fix: use shared formatStatsForPrompt from backstoryGenerator

Removes duplicated local version that had different format.
Also brings backstoryGenerator.ts into the worktree from main.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
root
2026-03-08 18:13:23 +00:00
parent 541b70b781
commit 78c8dbfb7f
2 changed files with 39 additions and 11 deletions
+38
View File
@@ -0,0 +1,38 @@
import type { Stats } from '@dflike/shared';
import type { World } from '../ecs/World.js';
import type { LlmService } from './llmService.js';
const STAT_KEYS: (keyof Stats)[] = [
'strength', 'dexterity', 'constitution', 'intelligence', 'perception',
'sociability', 'courage', 'curiosity', 'empathy', 'temperament',
];
const STAT_ABBREVS: Record<keyof Stats, string> = {
strength: 'STR', dexterity: 'DEX', constitution: 'CON',
intelligence: 'INT', perception: 'PER',
sociability: 'SOC', courage: 'COU', curiosity: 'CUR',
empathy: 'EMP', temperament: 'TMP',
};
export function formatStatsForPrompt(stats: Stats): string {
return STAT_KEYS.map(k => `${STAT_ABBREVS[k]}:${Math.floor(stats[k])}`).join(', ');
}
export async function generateBackstory(
world: World,
entityId: number,
llmService: LlmService,
): Promise<void> {
const name = world.getComponent<string>(entityId, 'name');
const stats = world.getComponent<Stats>(entityId, 'stats');
if (!name || !stats) return;
const result = await llmService.generate('backstory', {
npcName: name,
stats: formatStatsForPrompt(stats),
});
if (result) {
world.addComponent<string>(entityId, 'backstory', result);
}
}
+1 -11
View File
@@ -3,19 +3,9 @@ import type {
} from '@dflike/shared';
import type { World } from '../ecs/World.js';
import type { NarrationService } from '../llm/narrationService.js';
import { formatStatsForPrompt } from '../llm/backstoryGenerator.js';
import { classify } from './relationshipHelpers.js';
function formatStatsForPrompt(stats: Stats): string {
const personality = [
`sociability:${stats.sociability}`,
`courage:${stats.courage}`,
`curiosity:${stats.curiosity}`,
`empathy:${stats.empathy}`,
`temperament:${stats.temperament}`,
];
return personality.join(', ');
}
export function narrationEmitter(
world: World,
narrationService: NarrationService,