From 164ead068194e3bcd45e143a1be9da5b9d097dfa Mon Sep 17 00:00:00 2001 From: kdletters Date: Mon, 20 Apr 2026 12:10:42 +0000 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E9=BD=90story=E4=B8=8Eworld=E8=83=BD?= =?UTF-8?q?=E5=8A=9B=E6=B3=A8=E5=85=A5=E9=93=BE=E8=B7=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...O_STDB_CAPABILITY_FIRST_PLAN_2026-04-20.md | 4 +++- server-node/src/context.ts | 8 +++++++ .../src/modules/story/storyActionRoutes.ts | 4 ++-- server-node/src/routes/runtimeRoutes.ts | 2 +- server-node/src/server.ts | 21 +++++++++++++++++-- 5 files changed, 33 insertions(+), 6 deletions(-) diff --git a/docs/technical/STORY_WORLD_TO_STDB_CAPABILITY_FIRST_PLAN_2026-04-20.md b/docs/technical/STORY_WORLD_TO_STDB_CAPABILITY_FIRST_PLAN_2026-04-20.md index dd03d3d5..261f58e6 100644 --- a/docs/technical/STORY_WORLD_TO_STDB_CAPABILITY_FIRST_PLAN_2026-04-20.md +++ b/docs/technical/STORY_WORLD_TO_STDB_CAPABILITY_FIRST_PLAN_2026-04-20.md @@ -89,6 +89,7 @@ 本轮只做一件事: 1. 把 `story/custom world` 的 service 依赖从大仓储接口改成最小 capability +2. 把 `AppContext -> route -> service` 的注入链路同步改成 capability wiring 本轮不做: @@ -100,4 +101,5 @@ 1. `server-node` 编译通过 2. 相关测试 stub 不再依赖完整 `RuntimeRepositoryPort` -3. 文档明确固定“能力先迁、逻辑后搬”的顺序 +3. `storyActionRoutes` / `runtimeRoutes` 不再默认把整块 `runtimeRepository` 传进对应 service +4. 文档明确固定“能力先迁、逻辑后搬”的顺序 diff --git a/server-node/src/context.ts b/server-node/src/context.ts index 8f195f8e..dbde9565 100644 --- a/server-node/src/context.ts +++ b/server-node/src/context.ts @@ -14,6 +14,11 @@ import { CustomWorldAgentOrchestrator } from './services/customWorldAgentOrchest import { CustomWorldAgentSessionStore } from './services/customWorldAgentSessionStore.js'; import { CustomWorldSessionStore } from './services/customWorldSessionStore.js'; import { UpstreamLlmClient } from './services/llmClient.js'; +import type { + CustomWorldProfileCapability, + CustomWorldSessionCapability, + RuntimeStoryCapability, +} from './services/runtimeCapabilities.js'; import type { SmsVerificationService } from './services/smsVerificationService.js'; import type { WechatAuthService } from './services/wechatAuthService.js'; import { WechatAuthStateStore } from './services/wechatAuthStateStore.js'; @@ -29,6 +34,9 @@ export type AppContext = { smsAuthEventRepository: SmsAuthEventRepository; userSessionRepository: UserSessionRepository; runtimeRepository: RuntimeRepository; + runtimeStoryCapability: RuntimeStoryCapability; + customWorldSessionCapability: CustomWorldSessionCapability; + customWorldProfileCapability: CustomWorldProfileCapability; llmClient: UpstreamLlmClient; customWorldSessions: CustomWorldSessionStore; customWorldAgentSessions: CustomWorldAgentSessionStore; diff --git a/server-node/src/modules/story/storyActionRoutes.ts b/server-node/src/modules/story/storyActionRoutes.ts index ca4d958d..5971e700 100644 --- a/server-node/src/modules/story/storyActionRoutes.ts +++ b/server-node/src/modules/story/storyActionRoutes.ts @@ -58,7 +58,7 @@ export function createStoryActionRoutes(context: AppContext) { await resolveRuntimeStoryAction({ runtimeRepository: createRuntimeStorySnapshotRepository({ request, - runtimeRepository: context.runtimeRepository, + runtimeRepository: context.runtimeStoryCapability, config: context.config, }), llmClient: context.llmClient, @@ -83,7 +83,7 @@ export function createStoryActionRoutes(context: AppContext) { await getRuntimeStoryState({ runtimeRepository: createRuntimeStorySnapshotRepository({ request, - runtimeRepository: context.runtimeRepository, + runtimeRepository: context.runtimeStoryCapability, config: context.config, }), userId: request.userId!, diff --git a/server-node/src/routes/runtimeRoutes.ts b/server-node/src/routes/runtimeRoutes.ts index 75b8dc27..96b7f900 100644 --- a/server-node/src/routes/runtimeRoutes.ts +++ b/server-node/src/routes/runtimeRoutes.ts @@ -555,7 +555,7 @@ export function createRuntimeRoutes(context: AppContext) { asyncHandler(async (request, response) => { sendApiResponse(response, { items: await listCustomWorldWorkSummaries(request.userId!, { - runtimeRepository: context.runtimeRepository, + runtimeRepository: context.customWorldProfileCapability, customWorldAgentSessions: context.customWorldAgentSessions, }), }); diff --git a/server-node/src/server.ts b/server-node/src/server.ts index e23d87f7..9e41addc 100644 --- a/server-node/src/server.ts +++ b/server-node/src/server.ts @@ -17,6 +17,11 @@ import { CustomWorldAgentOrchestrator } from './services/customWorldAgentOrchest import { CustomWorldAgentSessionStore } from './services/customWorldAgentSessionStore.js'; import { CustomWorldSessionStore } from './services/customWorldSessionStore.js'; import { UpstreamLlmClient } from './services/llmClient.js'; +import { + createCustomWorldProfileCapability, + createCustomWorldSessionCapability, + createRuntimeSnapshotCapability, +} from './services/runtimeCapabilities.js'; import { createSmsVerificationService } from './services/smsVerificationService.js'; import { createWechatAuthService } from './services/wechatAuthService.js'; import { WechatAuthStateStore } from './services/wechatAuthStateStore.js'; @@ -80,9 +85,18 @@ export async function createAppContext(config: AppConfig = loadConfig()) { const logger = createLogger(config); const db = await createDatabase(config); const runtimeRepository = new RuntimeRepository(db); - const customWorldAgentSessions = new CustomWorldAgentSessionStore( + const runtimeStoryCapability = createRuntimeSnapshotCapability( runtimeRepository, ); + const customWorldSessionCapability = createCustomWorldSessionCapability( + runtimeRepository, + ); + const customWorldProfileCapability = createCustomWorldProfileCapability( + runtimeRepository, + ); + const customWorldAgentSessions = new CustomWorldAgentSessionStore( + customWorldSessionCapability, + ); const context: AppContext = { config, logger, @@ -94,8 +108,11 @@ export async function createAppContext(config: AppConfig = loadConfig()) { smsAuthEventRepository: new SmsAuthEventRepository(db), userSessionRepository: new UserSessionRepository(db), runtimeRepository, + runtimeStoryCapability, + customWorldSessionCapability, + customWorldProfileCapability, llmClient: new UpstreamLlmClient(config, logger), - customWorldSessions: new CustomWorldSessionStore(runtimeRepository), + customWorldSessions: new CustomWorldSessionStore(customWorldSessionCapability), customWorldAgentSessions, customWorldAgentOrchestrator: new CustomWorldAgentOrchestrator( customWorldAgentSessions,