Close DDD refactor and remove generated asset proxy
This commit is contained in:
@@ -9,7 +9,6 @@ import type {
|
||||
NpcRecruitDialogueRequest,
|
||||
PlainTextResponse,
|
||||
} from '../../packages/shared/src/contracts/rpgRuntimeChat';
|
||||
import type { RuntimeStoryAiRequest } from '../../packages/shared/src/contracts/rpgRuntimeStoryState';
|
||||
import type {
|
||||
CustomWorldGenerationProgress,
|
||||
GenerateCustomWorldProfileInput,
|
||||
@@ -35,6 +34,11 @@ import type {
|
||||
import { fetchWithApiAuth, requestJson } from './apiClient';
|
||||
import { type CharacterChatTargetStatus } from './rpgRuntimeChatTypes';
|
||||
import { parseLineListContent } from './llmParsers';
|
||||
import {
|
||||
buildStoryMomentFromRuntimeProjection,
|
||||
getStoryRuntimeProjection,
|
||||
resolveRuntimeStoryAction,
|
||||
} from './rpg-runtime/rpgRuntimeStoryClient';
|
||||
|
||||
const RUNTIME_API_BASE = '/api/runtime';
|
||||
|
||||
@@ -42,6 +46,20 @@ function getRuntimeSessionIdFromContext(context: StoryGenerationContext) {
|
||||
return context.runtimeSessionId?.trim() || undefined;
|
||||
}
|
||||
|
||||
function getStorySessionIdFromContext(context: StoryGenerationContext) {
|
||||
return context.storySessionId?.trim() || undefined;
|
||||
}
|
||||
|
||||
function runtimeStoryMomentToAiResponse(
|
||||
story: StoryMoment | null | undefined,
|
||||
fallbackText: string,
|
||||
): AIResponse {
|
||||
return {
|
||||
storyText: story?.text?.trim() || fallbackText,
|
||||
options: story?.options ?? [],
|
||||
};
|
||||
}
|
||||
|
||||
async function requestPlainText(
|
||||
url: string,
|
||||
payload: unknown,
|
||||
@@ -162,30 +180,22 @@ export async function generateInitialStory(
|
||||
context: StoryGenerationContext,
|
||||
requestOptions: StoryRequestOptions = {},
|
||||
): Promise<AIResponse> {
|
||||
const sessionId = getRuntimeSessionIdFromContext(context);
|
||||
const payload: RuntimeStoryAiRequest | Record<string, unknown> = sessionId
|
||||
? {
|
||||
sessionId,
|
||||
clientVersion: context.runtimeActionVersion,
|
||||
requestOptions,
|
||||
}
|
||||
: {
|
||||
worldType: world,
|
||||
character,
|
||||
monsters,
|
||||
context,
|
||||
requestOptions,
|
||||
};
|
||||
void world;
|
||||
void character;
|
||||
void monsters;
|
||||
void requestOptions;
|
||||
|
||||
return requestJson<AIResponse>(
|
||||
`${RUNTIME_API_BASE}/story/initial`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(payload),
|
||||
},
|
||||
'剧情开局生成失败',
|
||||
);
|
||||
const storySessionId = getStorySessionIdFromContext(context);
|
||||
if (!storySessionId) {
|
||||
throw new Error('运行时故事会话不存在,无法生成开局剧情');
|
||||
}
|
||||
|
||||
const projection = await getStoryRuntimeProjection({
|
||||
storySessionId,
|
||||
clientVersion: context.runtimeActionVersion,
|
||||
});
|
||||
const story = buildStoryMomentFromRuntimeProjection({ projection });
|
||||
return runtimeStoryMomentToAiResponse(story, '开局剧情已同步。');
|
||||
}
|
||||
|
||||
export async function generateNextStep(
|
||||
@@ -197,35 +207,36 @@ export async function generateNextStep(
|
||||
context: StoryGenerationContext,
|
||||
requestOptions: StoryRequestOptions = {},
|
||||
): Promise<AIResponse> {
|
||||
const sessionId = getRuntimeSessionIdFromContext(context);
|
||||
const payload: RuntimeStoryAiRequest | Record<string, unknown> = sessionId
|
||||
? {
|
||||
sessionId,
|
||||
clientVersion: context.runtimeActionVersion,
|
||||
choice,
|
||||
lastFunctionId: context.lastFunctionId,
|
||||
observeSignsRequested: context.observeSignsRequested,
|
||||
recentActionResult: context.recentActionResult,
|
||||
requestOptions,
|
||||
}
|
||||
: {
|
||||
worldType: world,
|
||||
character,
|
||||
monsters,
|
||||
history,
|
||||
choice,
|
||||
context,
|
||||
requestOptions,
|
||||
};
|
||||
void world;
|
||||
void character;
|
||||
void monsters;
|
||||
void history;
|
||||
void requestOptions;
|
||||
|
||||
return requestJson<AIResponse>(
|
||||
`${RUNTIME_API_BASE}/story/continue`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(payload),
|
||||
const storySessionId = getStorySessionIdFromContext(context);
|
||||
if (!storySessionId) {
|
||||
throw new Error('运行时故事会话不存在,无法续写剧情');
|
||||
}
|
||||
const functionId = context.lastFunctionId?.trim();
|
||||
if (!functionId) {
|
||||
throw new Error('运行时动作缺少 functionId,无法续写剧情');
|
||||
}
|
||||
|
||||
const response = await resolveRuntimeStoryAction({
|
||||
storySessionId,
|
||||
clientVersion: context.runtimeActionVersion,
|
||||
option: {
|
||||
functionId,
|
||||
actionText: choice,
|
||||
},
|
||||
'剧情续写失败',
|
||||
payload: {
|
||||
observeSignsRequested: context.observeSignsRequested,
|
||||
recentActionResult: context.recentActionResult,
|
||||
},
|
||||
});
|
||||
return runtimeStoryMomentToAiResponse(
|
||||
response.snapshot.currentStory,
|
||||
choice,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user