This commit is contained in:
2026-04-10 15:37:02 +08:00
parent 161cd32277
commit f19e482c8f
233 changed files with 43987 additions and 5127 deletions

View File

@@ -1,16 +1,22 @@
import { buildRuntimeItemAiIntent } from '../../../src/data/runtimeItemNarrative.js';
import { parseJsonResponseText } from '../../../src/services/llmParsers.js';
import {
RUNTIME_ITEM_FUNCTIONAL_BIAS_VALUES,
RUNTIME_ITEM_TONE_VALUES,
} from '../../../packages/shared/src/contracts/story.js';
import type {
RuntimeItemIntentRequest,
} from '../../../packages/shared/src/contracts/story.js';
import { parseJsonResponseText } from '../../../packages/shared/src/llm/parsers.js';
import {
buildRuntimeItemAiIntent,
buildRuntimeItemIntentPrompt,
RUNTIME_ITEM_INTENT_SYSTEM_PROMPT,
} from '../../../src/services/runtimeItemAiPrompt.js';
import type {
RuntimeItemAiIntent,
RuntimeItemGenerationContext,
RuntimeItemPlan,
} from '../../../src/types/runtimeItem.js';
} from '../bridges/legacyRuntimeItemBridge.js';
import type { UpstreamLlmClient } from './llmClient.js';
type RuntimeItemGenerationContext = Parameters<typeof buildRuntimeItemAiIntent>[0];
type RuntimeItemPlan = Parameters<typeof buildRuntimeItemAiIntent>[1];
type RuntimeItemAiIntent = ReturnType<typeof buildRuntimeItemAiIntent>;
function coerceString(value: unknown, fallback: string) {
return typeof value === 'string' && value.trim() ? value.trim() : fallback;
}
@@ -45,7 +51,7 @@ function sanitizeRuntimeItemAiIntent(
(
item,
): item is RuntimeItemAiIntent['desiredFunctionalBias'][number] =>
['heal', 'mana', 'cooldown', 'guard', 'damage'].includes(item),
RUNTIME_ITEM_FUNCTIONAL_BIAS_VALUES.includes(item),
);
const tone = coerceString(intent.tone, fallback.tone);
@@ -59,7 +65,7 @@ function sanitizeRuntimeItemAiIntent(
desiredFunctionalBias.length > 0
? desiredFunctionalBias
: fallback.desiredFunctionalBias,
tone: ['grim', 'mysterious', 'martial', 'ritual', 'survival'].includes(tone)
tone: RUNTIME_ITEM_TONE_VALUES.includes(tone)
? (tone as RuntimeItemAiIntent['tone'])
: fallback.tone,
visibleClue: coerceString(intent.visibleClue, fallback.visibleClue ?? ''),
@@ -80,10 +86,7 @@ function sanitizeRuntimeItemAiIntent(
export async function generateRuntimeItemIntents(
llmClient: UpstreamLlmClient,
params: {
context: RuntimeItemGenerationContext;
plans: RuntimeItemPlan[];
},
params: RuntimeItemIntentRequest<RuntimeItemGenerationContext, RuntimeItemPlan>,
) {
const fallbackIntents = params.plans.map((plan) =>
buildRuntimeItemAiIntent(params.context, plan),