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:
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user