This commit is contained in:
2026-04-18 13:05:29 +08:00
parent 09d4c0c31b
commit 5032701c38
77 changed files with 8538 additions and 2413 deletions

View File

@@ -5,6 +5,7 @@ import type {
CustomWorldFoundationDraftLandmark,
CustomWorldFoundationDraftProfile,
CustomWorldFoundationDraftThread,
EightAnchorContent,
} from '../../../packages/shared/src/contracts/customWorldAgent.js';
import { parseJsonResponseText } from '../../../packages/shared/src/llm/parsers.js';
import {
@@ -36,6 +37,13 @@ import {
type CustomWorldCreatorIntentRecord,
normalizeCreatorIntentRecord,
} from './customWorldAgentIntentExtractionService.js';
import {
buildCreatorIntentFromEightAnchorContent,
buildDraftSummaryFromEightAnchorContent,
buildDraftTitleFromEightAnchorContent,
buildEightAnchorFoundationText,
normalizeEightAnchorContent,
} from './eightAnchorCompatibilityService.js';
import type { UpstreamLlmClient } from './llmClient.js';
function toText(value: unknown) {
@@ -923,7 +931,15 @@ function sanitizeJsonLikeText(text: string) {
function buildFoundationGenerationSeedText(params: {
intent: CustomWorldCreatorIntentRecord;
anchorPack: unknown;
anchorContent?: EightAnchorContent | null;
}) {
const anchorText = params.anchorContent
? buildEightAnchorFoundationText(params.anchorContent)
: '';
if (anchorText) {
return anchorText;
}
const anchorRecord = toRecord(params.anchorPack);
const anchorSummary = toText(anchorRecord?.creatorIntentSummary);
if (anchorSummary) {
@@ -1574,12 +1590,14 @@ async function buildFoundationDraftProfileWithLlm(params: {
llmClient: UpstreamLlmClient;
creatorIntent: CustomWorldCreatorIntentRecord;
anchorPack: unknown;
anchorContent?: EightAnchorContent | null;
signal?: AbortSignal;
onProgress?: DraftProgressCallback;
}) {
const settingText = buildFoundationGenerationSeedText({
intent: params.creatorIntent,
anchorPack: params.anchorPack,
anchorContent: params.anchorContent,
});
await emitDraftProgress(params.onProgress, {
@@ -1720,22 +1738,14 @@ export class CustomWorldAgentFoundationDraftService {
private generateFallbackDraft(params: {
creatorIntent: unknown;
anchorPack: unknown;
anchorContent?: EightAnchorContent | null;
}): CustomWorldFoundationDraftProfile {
const intent = normalizeCreatorIntentRecord(params.creatorIntent) ?? {
sourceMode: 'freeform' as const,
rawSettingText: '',
worldHook: '',
themeKeywords: [],
toneDirectives: [],
playerPremise: '',
openingSituation: '',
coreConflicts: [],
keyFactions: [],
keyCharacters: [],
keyLandmarks: [],
iconicElements: [],
forbiddenDirectives: [],
};
const normalizedAnchorContent = normalizeEightAnchorContent(
params.anchorContent,
);
const intent =
normalizeCreatorIntentRecord(params.creatorIntent) ??
buildCreatorIntentFromEightAnchorContent(normalizedAnchorContent);
const anchorPack = toRecord(params.anchorPack);
const worldHook =
clampText(intent.worldHook || intent.rawSettingText, 72) ||
@@ -1757,6 +1767,8 @@ export class CustomWorldAgentFoundationDraftService {
openingSituation,
coreConflict: coreConflicts[0] || '',
});
const anchorDraftTitle =
buildDraftTitleFromEightAnchorContent(normalizedAnchorContent);
const factions = buildFactions({
intent,
coreConflicts,
@@ -1815,7 +1827,10 @@ export class CustomWorldAgentFoundationDraftService {
);
return {
name: worldName,
name:
anchorDraftTitle && anchorDraftTitle !== '未命名草稿'
? anchorDraftTitle
: worldName,
subtitle:
clampText(
[
@@ -1845,6 +1860,7 @@ export class CustomWorldAgentFoundationDraftService {
openingSituation,
iconicElements,
sourceAnchorSummary:
buildDraftSummaryFromEightAnchorContent(normalizedAnchorContent) ||
toText(anchorPack?.creatorIntentSummary) ||
buildDraftSummaryFromIntent(intent) ||
summary,
@@ -1854,10 +1870,15 @@ export class CustomWorldAgentFoundationDraftService {
async generate(params: {
creatorIntent: unknown;
anchorPack: unknown;
anchorContent?: EightAnchorContent | null;
signal?: AbortSignal;
onProgress?: DraftProgressCallback;
}): Promise<CustomWorldFoundationDraftProfile> {
const intent = normalizeCreatorIntentRecord(params.creatorIntent);
const intent =
normalizeCreatorIntentRecord(params.creatorIntent) ??
buildCreatorIntentFromEightAnchorContent(
normalizeEightAnchorContent(params.anchorContent),
);
if (!this.llmClient || !intent) {
return this.generateFallbackDraft(params);
@@ -1867,6 +1888,7 @@ export class CustomWorldAgentFoundationDraftService {
llmClient: this.llmClient,
creatorIntent: intent,
anchorPack: params.anchorPack,
anchorContent: params.anchorContent,
signal: params.signal,
onProgress: params.onProgress,
});