@gt-fe/eap-runtime 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +323 -0
- package/dist/api/handlers/index.d.ts +3 -0
- package/dist/api/handlers/index.js +4 -0
- package/dist/api/handlers/invoke.handler.d.ts +77 -0
- package/dist/api/handlers/invoke.handler.js +411 -0
- package/dist/api/handlers/messages.handler.d.ts +53 -0
- package/dist/api/handlers/messages.handler.js +80 -0
- package/dist/api/handlers/stream.handler.d.ts +92 -0
- package/dist/api/handlers/stream.handler.js +432 -0
- package/dist/api/index.d.ts +3 -0
- package/dist/api/index.js +4 -0
- package/dist/api/middleware/auth.middleware.d.ts +96 -0
- package/dist/api/middleware/auth.middleware.js +158 -0
- package/dist/api/middleware/index.d.ts +1 -0
- package/dist/api/middleware/index.js +2 -0
- package/dist/api/routes/agent.routes.d.ts +44 -0
- package/dist/api/routes/agent.routes.js +204 -0
- package/dist/api/routes/index.d.ts +3 -0
- package/dist/api/routes/index.js +4 -0
- package/dist/api/routes/session.routes.d.ts +82 -0
- package/dist/api/routes/session.routes.js +169 -0
- package/dist/api/routes/task.routes.d.ts +75 -0
- package/dist/api/routes/task.routes.js +108 -0
- package/dist/checkpoint/checkpoint-serializer.d.ts +58 -0
- package/dist/checkpoint/checkpoint-serializer.js +81 -0
- package/dist/checkpoint/composite-checkpoint-saver.d.ts +42 -0
- package/dist/checkpoint/composite-checkpoint-saver.js +118 -0
- package/dist/checkpoint/contracts/checkpoint-saver.contract.d.ts +65 -0
- package/dist/checkpoint/contracts/checkpoint-saver.contract.js +12 -0
- package/dist/checkpoint/contracts/index.d.ts +1 -0
- package/dist/checkpoint/contracts/index.js +1 -0
- package/dist/checkpoint/file-checkpoint-saver.d.ts +19 -0
- package/dist/checkpoint/file-checkpoint-saver.js +98 -0
- package/dist/checkpoint/hybrid-checkpoint-saver.d.ts +130 -0
- package/dist/checkpoint/hybrid-checkpoint-saver.js +211 -0
- package/dist/checkpoint/in-memory-checkpoint-saver.d.ts +14 -0
- package/dist/checkpoint/in-memory-checkpoint-saver.js +46 -0
- package/dist/checkpoint/index.d.ts +16 -0
- package/dist/checkpoint/index.js +13 -0
- package/dist/checkpoint/mongo-checkpoint-saver.d.ts +38 -0
- package/dist/checkpoint/mongo-checkpoint-saver.js +56 -0
- package/dist/checkpoint/pg-checkpoint-saver.d.ts +59 -0
- package/dist/checkpoint/pg-checkpoint-saver.js +140 -0
- package/dist/checkpoint/redis-checkpoint-saver.d.ts +68 -0
- package/dist/checkpoint/redis-checkpoint-saver.js +173 -0
- package/dist/checkpoint/restore-checkpoint.d.ts +33 -0
- package/dist/checkpoint/restore-checkpoint.js +33 -0
- package/dist/common/agent-code.d.ts +10 -0
- package/dist/common/agent-code.js +12 -0
- package/dist/common/concurrency.d.ts +79 -0
- package/dist/common/concurrency.js +121 -0
- package/dist/common/health.d.ts +40 -0
- package/dist/common/health.js +37 -0
- package/dist/common/index.d.ts +5 -0
- package/dist/common/index.js +5 -0
- package/dist/common/logger.d.ts +34 -0
- package/dist/common/logger.js +38 -0
- package/dist/common/queue-consumer.d.ts +125 -0
- package/dist/common/queue-consumer.js +159 -0
- package/dist/common/trace-id.d.ts +2 -0
- package/dist/common/trace-id.js +8 -0
- package/dist/common/types.d.ts +104 -0
- package/dist/common/types.js +14 -0
- package/dist/contracts/index.d.ts +11 -0
- package/dist/contracts/index.js +10 -0
- package/dist/contracts/permission-checker.d.ts +10 -0
- package/dist/contracts/permission-checker.js +4 -0
- package/dist/contracts/trace-collector.d.ts +211 -0
- package/dist/contracts/trace-collector.js +13 -0
- package/dist/governance/governance-client.d.ts +38 -0
- package/dist/governance/governance-client.js +95 -0
- package/dist/governance/index.d.ts +7 -0
- package/dist/governance/index.js +5 -0
- package/dist/governance/permission-guard.d.ts +19 -0
- package/dist/governance/permission-guard.js +59 -0
- package/dist/graph/adapters/index.d.ts +3 -0
- package/dist/graph/adapters/index.js +3 -0
- package/dist/graph/adapters/langgraph-checkpointer.d.ts +40 -0
- package/dist/graph/adapters/langgraph-checkpointer.js +211 -0
- package/dist/graph/adapters/langgraph.adapter.d.ts +190 -0
- package/dist/graph/adapters/langgraph.adapter.js +1303 -0
- package/dist/graph/adapters/subgraph-compiler.d.ts +39 -0
- package/dist/graph/adapters/subgraph-compiler.js +248 -0
- package/dist/graph/condition-evaluator.d.ts +57 -0
- package/dist/graph/condition-evaluator.js +162 -0
- package/dist/graph/contracts/executable-graph.d.ts +340 -0
- package/dist/graph/contracts/executable-graph.js +10 -0
- package/dist/graph/contracts/index.d.ts +2 -0
- package/dist/graph/contracts/index.js +2 -0
- package/dist/graph/contracts/state-graph.contract.d.ts +76 -0
- package/dist/graph/contracts/state-graph.contract.js +11 -0
- package/dist/graph/hitl/hitl-handler.d.ts +199 -0
- package/dist/graph/hitl/hitl-handler.js +480 -0
- package/dist/graph/hitl/index.d.ts +1 -0
- package/dist/graph/hitl/index.js +1 -0
- package/dist/graph/index.d.ts +7 -0
- package/dist/graph/index.js +7 -0
- package/dist/graph/nodes/index.d.ts +2 -0
- package/dist/graph/nodes/index.js +2 -0
- package/dist/graph/nodes/llm-node.d.ts +182 -0
- package/dist/graph/nodes/llm-node.js +281 -0
- package/dist/graph/nodes/skill-bind-node.d.ts +32 -0
- package/dist/graph/nodes/skill-bind-node.js +116 -0
- package/dist/graph/nodes/tool-node.d.ts +75 -0
- package/dist/graph/nodes/tool-node.js +324 -0
- package/dist/graph/resolve-graph-prompt.d.ts +5 -0
- package/dist/graph/resolve-graph-prompt.js +75 -0
- package/dist/graph/retry/budget-aware-retry.d.ts +91 -0
- package/dist/graph/retry/budget-aware-retry.js +126 -0
- package/dist/graph/retry/index.d.ts +9 -0
- package/dist/graph/retry/index.js +8 -0
- package/dist/graph/retry/node-retry.d.ts +123 -0
- package/dist/graph/retry/node-retry.js +235 -0
- package/dist/graph/skill-audit-recorder.d.ts +126 -0
- package/dist/graph/skill-audit-recorder.js +114 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +32 -0
- package/dist/memory/compression/compression-stats.d.ts +109 -0
- package/dist/memory/compression/compression-stats.js +144 -0
- package/dist/memory/compression/compression.repository.d.ts +62 -0
- package/dist/memory/compression/compression.repository.js +71 -0
- package/dist/memory/compression/index.d.ts +10 -0
- package/dist/memory/compression/index.js +15 -0
- package/dist/memory/compression/llm-summarize.d.ts +58 -0
- package/dist/memory/compression/llm-summarize.js +192 -0
- package/dist/memory/compression/sliding-window.compression.d.ts +60 -0
- package/dist/memory/compression/sliding-window.compression.js +175 -0
- package/dist/memory/index.d.ts +4 -0
- package/dist/memory/index.js +7 -0
- package/dist/memory/long-term-memory.service.d.ts +94 -0
- package/dist/memory/long-term-memory.service.js +120 -0
- package/dist/memory/message-compression.service.d.ts +128 -0
- package/dist/memory/message-compression.service.js +69 -0
- package/dist/memory/pg-memory.repository.d.ts +44 -0
- package/dist/memory/pg-memory.repository.js +108 -0
- package/dist/memory/semantic-retrieval.service.d.ts +148 -0
- package/dist/memory/semantic-retrieval.service.js +238 -0
- package/dist/providers/echo-llm-provider.d.ts +10 -0
- package/dist/providers/echo-llm-provider.js +87 -0
- package/dist/providers/http-llm-provider.d.ts +35 -0
- package/dist/providers/http-llm-provider.js +404 -0
- package/dist/providers/index.d.ts +7 -0
- package/dist/providers/index.js +5 -0
- package/dist/providers/local-llm-provider.d.ts +27 -0
- package/dist/providers/local-llm-provider.js +105 -0
- package/dist/providers/resolve-llm-model.d.ts +13 -0
- package/dist/providers/resolve-llm-model.js +30 -0
- package/dist/providers/routing-llm-provider.d.ts +28 -0
- package/dist/providers/routing-llm-provider.js +79 -0
- package/dist/registry/agent-models.d.ts +1 -0
- package/dist/registry/agent-models.js +1 -0
- package/dist/registry/agent-registry-client.d.ts +56 -0
- package/dist/registry/agent-registry-client.js +36 -0
- package/dist/registry/definition-cache.d.ts +37 -0
- package/dist/registry/definition-cache.js +82 -0
- package/dist/registry/deployment-snapshot.d.ts +99 -0
- package/dist/registry/deployment-snapshot.js +542 -0
- package/dist/registry/graph-loader.d.ts +134 -0
- package/dist/registry/graph-loader.js +985 -0
- package/dist/registry/index.d.ts +9 -0
- package/dist/registry/index.js +9 -0
- package/dist/registry/preload-errors.d.ts +13 -0
- package/dist/registry/preload-errors.js +35 -0
- package/dist/registry/preload-flags.d.ts +22 -0
- package/dist/registry/preload-flags.js +44 -0
- package/dist/registry/skill-io-guard.d.ts +25 -0
- package/dist/registry/skill-io-guard.js +98 -0
- package/dist/registry/skill-tree.d.ts +27 -0
- package/dist/registry/skill-tree.js +183 -0
- package/dist/runtime/agent-runtime.d.ts +106 -0
- package/dist/runtime/agent-runtime.js +777 -0
- package/dist/runtime/dev-runtime.d.ts +69 -0
- package/dist/runtime/dev-runtime.js +199 -0
- package/dist/runtime/index.d.ts +4 -0
- package/dist/runtime/index.js +3 -0
- package/dist/runtime/storage-profile.d.ts +50 -0
- package/dist/runtime/storage-profile.js +138 -0
- package/dist/runtime/types.d.ts +120 -0
- package/dist/runtime/types.js +9 -0
- package/dist/server.d.ts +12 -0
- package/dist/server.js +161 -0
- package/dist/session/compression-middleware.d.ts +126 -0
- package/dist/session/compression-middleware.js +230 -0
- package/dist/session/file-message.repository.d.ts +25 -0
- package/dist/session/file-message.repository.js +78 -0
- package/dist/session/file-session.repository.d.ts +72 -0
- package/dist/session/file-session.repository.js +212 -0
- package/dist/session/index.d.ts +13 -0
- package/dist/session/index.js +12 -0
- package/dist/session/message.service.d.ts +80 -0
- package/dist/session/message.service.js +128 -0
- package/dist/session/persist-turn-messages.d.ts +145 -0
- package/dist/session/persist-turn-messages.js +325 -0
- package/dist/session/pg-message.repository.d.ts +49 -0
- package/dist/session/pg-message.repository.js +149 -0
- package/dist/session/pg-session.repository.d.ts +46 -0
- package/dist/session/pg-session.repository.js +117 -0
- package/dist/session/session-context.service.d.ts +49 -0
- package/dist/session/session-context.service.js +66 -0
- package/dist/session/session.service.d.ts +194 -0
- package/dist/session/session.service.js +166 -0
- package/dist/sse/connection-event-logger.d.ts +21 -0
- package/dist/sse/connection-event-logger.js +33 -0
- package/dist/sse/contracts/index.d.ts +1 -0
- package/dist/sse/contracts/index.js +1 -0
- package/dist/sse/contracts/sse-emitter.contract.d.ts +74 -0
- package/dist/sse/contracts/sse-emitter.contract.js +11 -0
- package/dist/sse/event-buffer.d.ts +20 -0
- package/dist/sse/event-buffer.js +45 -0
- package/dist/sse/events/code-events.d.ts +19 -0
- package/dist/sse/events/code-events.js +9 -0
- package/dist/sse/events/collaboration-events.d.ts +37 -0
- package/dist/sse/events/collaboration-events.js +11 -0
- package/dist/sse/events/connection-events.d.ts +13 -0
- package/dist/sse/events/connection-events.js +9 -0
- package/dist/sse/events/file-events.d.ts +29 -0
- package/dist/sse/events/file-events.js +10 -0
- package/dist/sse/events/hitl-events.d.ts +33 -0
- package/dist/sse/events/hitl-events.js +10 -0
- package/dist/sse/events/index.d.ts +107 -0
- package/dist/sse/events/index.js +96 -0
- package/dist/sse/events/plan-events.d.ts +38 -0
- package/dist/sse/events/plan-events.js +11 -0
- package/dist/sse/events/reasoning-events.d.ts +35 -0
- package/dist/sse/events/reasoning-events.js +13 -0
- package/dist/sse/events/response-events.d.ts +25 -0
- package/dist/sse/events/response-events.js +12 -0
- package/dist/sse/events/session-events.d.ts +43 -0
- package/dist/sse/events/session-events.js +12 -0
- package/dist/sse/events/skill-events.d.ts +48 -0
- package/dist/sse/events/skill-events.js +11 -0
- package/dist/sse/events/stats-events.d.ts +44 -0
- package/dist/sse/events/stats-events.js +12 -0
- package/dist/sse/events/tool-events.d.ts +68 -0
- package/dist/sse/events/tool-events.js +14 -0
- package/dist/sse/index.d.ts +8 -0
- package/dist/sse/index.js +8 -0
- package/dist/sse/sse-connection-manager.d.ts +116 -0
- package/dist/sse/sse-connection-manager.js +185 -0
- package/dist/sse/sse-emitter.d.ts +108 -0
- package/dist/sse/sse-emitter.js +210 -0
- package/dist/sse/sse-heartbeat.d.ts +58 -0
- package/dist/sse/sse-heartbeat.js +76 -0
- package/dist/sse/trace-collector.d.ts +60 -0
- package/dist/sse/trace-collector.js +107 -0
- package/dist/task/contracts/index.d.ts +2 -0
- package/dist/task/contracts/index.js +1 -0
- package/dist/task/contracts/task-manager.contract.d.ts +160 -0
- package/dist/task/contracts/task-manager.contract.js +10 -0
- package/dist/task/index.d.ts +7 -0
- package/dist/task/index.js +5 -0
- package/dist/task/pg-task.repository.d.ts +47 -0
- package/dist/task/pg-task.repository.js +131 -0
- package/dist/task/task-progress-tracker.d.ts +67 -0
- package/dist/task/task-progress-tracker.js +80 -0
- package/dist/task/task-timeout.d.ts +70 -0
- package/dist/task/task-timeout.js +116 -0
- package/dist/task/task.service.d.ts +84 -0
- package/dist/task/task.service.js +233 -0
- package/dist/token/compression-budget-integration.d.ts +145 -0
- package/dist/token/compression-budget-integration.js +185 -0
- package/dist/token/context-window-budget.d.ts +113 -0
- package/dist/token/context-window-budget.js +134 -0
- package/dist/token/contracts/index.d.ts +1 -0
- package/dist/token/contracts/index.js +1 -0
- package/dist/token/contracts/token-budget.contract.d.ts +77 -0
- package/dist/token/contracts/token-budget.contract.js +11 -0
- package/dist/token/index.d.ts +12 -0
- package/dist/token/index.js +10 -0
- package/dist/token/pg-token-budget.repository.d.ts +39 -0
- package/dist/token/pg-token-budget.repository.js +116 -0
- package/dist/token/session-budget-checker.d.ts +54 -0
- package/dist/token/session-budget-checker.js +72 -0
- package/dist/token/token-budget-guard.d.ts +66 -0
- package/dist/token/token-budget-guard.js +97 -0
- package/dist/token/token-budget.service.d.ts +86 -0
- package/dist/token/token-budget.service.js +130 -0
- package/dist/token/token-detail-mode.d.ts +73 -0
- package/dist/token/token-detail-mode.js +107 -0
- package/dist/token/token-estimator.d.ts +80 -0
- package/dist/token/token-estimator.js +134 -0
- package/dist/token/token-stats.service.d.ts +88 -0
- package/dist/token/token-stats.service.js +94 -0
- package/dist/tool/create-tool-executor.d.ts +33 -0
- package/dist/tool/create-tool-executor.js +60 -0
- package/dist/tool/dev-http-executor.d.ts +18 -0
- package/dist/tool/dev-http-executor.js +96 -0
- package/dist/tool/dev-mcp-executor.d.ts +29 -0
- package/dist/tool/dev-mcp-executor.js +84 -0
- package/dist/tool/dev-tool-executor.d.ts +23 -0
- package/dist/tool/dev-tool-executor.js +55 -0
- package/dist/tool/file-artifact.d.ts +11 -0
- package/dist/tool/file-artifact.js +90 -0
- package/dist/tool/http-tool-executor.d.ts +17 -0
- package/dist/tool/http-tool-executor.js +158 -0
- package/dist/tool/index.d.ts +18 -0
- package/dist/tool/index.js +17 -0
- package/dist/tool/loaded-tool-definition.d.ts +35 -0
- package/dist/tool/loaded-tool-definition.js +9 -0
- package/dist/tool/local-mcp-client.d.ts +23 -0
- package/dist/tool/local-mcp-client.js +225 -0
- package/dist/tool/local-tool-executor.d.ts +37 -0
- package/dist/tool/local-tool-executor.js +249 -0
- package/dist/tool/mcp-tool-executor.d.ts +23 -0
- package/dist/tool/mcp-tool-executor.js +160 -0
- package/dist/tool/mock-tool-executor.d.ts +28 -0
- package/dist/tool/mock-tool-executor.js +65 -0
- package/dist/tool/system-prompt-builder.d.ts +114 -0
- package/dist/tool/system-prompt-builder.js +213 -0
- package/dist/tool/tool-confirmation.d.ts +29 -0
- package/dist/tool/tool-confirmation.js +81 -0
- package/dist/tool/tool-event-emitter.d.ts +58 -0
- package/dist/tool/tool-event-emitter.js +154 -0
- package/dist/tool/tool-execution-router.d.ts +25 -0
- package/dist/tool/tool-execution-router.js +50 -0
- package/dist/tool/tool-executor.interface.d.ts +85 -0
- package/dist/tool/tool-executor.interface.js +7 -0
- package/dist/tool/tool-orchestrator.d.ts +22 -0
- package/dist/tool/tool-orchestrator.js +104 -0
- package/dist/tool/tool-result-injector.d.ts +64 -0
- package/dist/tool/tool-result-injector.js +65 -0
- package/dist/utils/format-error.d.ts +4 -0
- package/dist/utils/format-error.js +4 -0
- package/dist/utils/http-error.d.ts +11 -0
- package/dist/utils/http-error.js +24 -0
- package/package.json +56 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* createDevRuntime — 本地 dev 模式 Runtime SDK 装配工厂
|
|
3
|
+
*
|
|
4
|
+
* 将 server.ts 里的依赖注入装配逻辑抽成纯函数,让 CLI / 测试 / 宿主服务
|
|
5
|
+
* 可以**进程内嵌**调用 AgentRuntime.execute / stream,无需起 HTTP。
|
|
6
|
+
*
|
|
7
|
+
* 典型用法(dev-tools/packages/cli/src/commands/chat.ts --sdk 模式):
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { createDevRuntime } from '@eap/runtime';
|
|
11
|
+
*
|
|
12
|
+
* const rt = createDevRuntime();
|
|
13
|
+
* const result = await rt.invokeOrchestrator.execute(
|
|
14
|
+
* { agentCode, input, sessionId, userId },
|
|
15
|
+
* userId,
|
|
16
|
+
* );
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* 装配策略(与 server.ts 一致):
|
|
20
|
+
* - LLM Provider: Routing > HttpLLMProvider(OpenAI) > Echo 兜底
|
|
21
|
+
* - Tool Executor: mock(显式)/ DevToolExecutor(dev+mcp,缺配置失败)/ 通用路由
|
|
22
|
+
* - Governance: AllowAll(本地闭环默认) / HttpGovernance(显式 GOVERNANCE_DISABLED=0)
|
|
23
|
+
* - 存储: EAP_RUNTIME_STORAGE_PROFILE(默认 dev = File Session/Message/Checkpoint)
|
|
24
|
+
* - Registry: 本地闭环不装配,由 GraphLoader.deploymentSnapshot 兜底
|
|
25
|
+
*/
|
|
26
|
+
import { InvokeOrchestrator, StreamOrchestrator, SessionService, MessageService, SessionContextService, TaskService, TokenStatsService, GraphLoader } from '../index.js';
|
|
27
|
+
import { type AgentRuntime } from './agent-runtime.js';
|
|
28
|
+
import type { RuntimeStorageProfile } from './storage-profile.js';
|
|
29
|
+
import type { HitlResponse, ResumeHitlResult, SSEEvent } from './types.js';
|
|
30
|
+
/** createDevRuntime 返回值(CLI 嵌入用,可选字段后续扩展) */
|
|
31
|
+
export interface DevRuntime {
|
|
32
|
+
invokeOrchestrator: InvokeOrchestrator;
|
|
33
|
+
streamOrchestrator: StreamOrchestrator;
|
|
34
|
+
/** SDK 门面:execute / stream / resumeHitl / fork */
|
|
35
|
+
agentRuntime: AgentRuntime;
|
|
36
|
+
/** 与 Graph 共用同一 HitlHandler 实例(等待态可 resume) */
|
|
37
|
+
resumeHitl: (taskId: string, response: HitlResponse) => Promise<ResumeHitlResult>;
|
|
38
|
+
/** HITL 恢复流式入口:新开一条 SSE(第一条 stream 已在 hitl.waited 结束) */
|
|
39
|
+
streamResumeHitl: (taskId: string, response: HitlResponse) => AsyncIterable<SSEEvent>;
|
|
40
|
+
sessionService: SessionService;
|
|
41
|
+
messageService: MessageService;
|
|
42
|
+
sessionContextService: SessionContextService;
|
|
43
|
+
taskService: TaskService;
|
|
44
|
+
tokenStatsService: TokenStatsService;
|
|
45
|
+
graphLoader: GraphLoader;
|
|
46
|
+
/** 停止 Skill 目录 watch;未开启热加载时为 no-op */
|
|
47
|
+
dispose: () => void;
|
|
48
|
+
/** 装配期诊断摘要(CLI 启动时打印,便于排查环境问题) */
|
|
49
|
+
diagnostics: {
|
|
50
|
+
deploymentContext: string;
|
|
51
|
+
toolExecutionMode: string;
|
|
52
|
+
llmProviderKind: 'routing' | 'openai-http' | 'echo';
|
|
53
|
+
llmDefaultModel: string;
|
|
54
|
+
governanceKind: 'AllowAll' | 'Http';
|
|
55
|
+
storageProfile: RuntimeStorageProfile;
|
|
56
|
+
sessionStoreKind: 'file' | 'in-memory';
|
|
57
|
+
messageStoreKind: 'memory' | 'file' | 'postgres';
|
|
58
|
+
checkpointKind: 'memory' | 'file' | 'redis+pg' | 'pg';
|
|
59
|
+
foundationConfigured: boolean;
|
|
60
|
+
skillHotReload: boolean;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* 装配本地 dev 模式所需的全部 Runtime 依赖
|
|
65
|
+
*
|
|
66
|
+
* @returns DevRuntime(含 invokeOrchestrator / streamOrchestrator / 诊断摘要)
|
|
67
|
+
* @throws EAP_LLM_MODE=local 但解不出任何密钥时抛错,避免静默 Echo
|
|
68
|
+
*/
|
|
69
|
+
export declare function createDevRuntime(): DevRuntime;
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* createDevRuntime — 本地 dev 模式 Runtime SDK 装配工厂
|
|
3
|
+
*
|
|
4
|
+
* 将 server.ts 里的依赖注入装配逻辑抽成纯函数,让 CLI / 测试 / 宿主服务
|
|
5
|
+
* 可以**进程内嵌**调用 AgentRuntime.execute / stream,无需起 HTTP。
|
|
6
|
+
*
|
|
7
|
+
* 典型用法(dev-tools/packages/cli/src/commands/chat.ts --sdk 模式):
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { createDevRuntime } from '@eap/runtime';
|
|
11
|
+
*
|
|
12
|
+
* const rt = createDevRuntime();
|
|
13
|
+
* const result = await rt.invokeOrchestrator.execute(
|
|
14
|
+
* { agentCode, input, sessionId, userId },
|
|
15
|
+
* userId,
|
|
16
|
+
* );
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* 装配策略(与 server.ts 一致):
|
|
20
|
+
* - LLM Provider: Routing > HttpLLMProvider(OpenAI) > Echo 兜底
|
|
21
|
+
* - Tool Executor: mock(显式)/ DevToolExecutor(dev+mcp,缺配置失败)/ 通用路由
|
|
22
|
+
* - Governance: AllowAll(本地闭环默认) / HttpGovernance(显式 GOVERNANCE_DISABLED=0)
|
|
23
|
+
* - 存储: EAP_RUNTIME_STORAGE_PROFILE(默认 dev = File Session/Message/Checkpoint)
|
|
24
|
+
* - Registry: 本地闭环不装配,由 GraphLoader.deploymentSnapshot 兜底
|
|
25
|
+
*/
|
|
26
|
+
import { createDefaultLLMProvider } from '../providers/echo-llm-provider.js';
|
|
27
|
+
import { HttpLLMProvider } from '../providers/http-llm-provider.js';
|
|
28
|
+
import { createLocalLlmProvider, requireLocalLlmConnections } from '../providers/local-llm-provider.js';
|
|
29
|
+
import { RoutingLLMProvider } from '../providers/routing-llm-provider.js';
|
|
30
|
+
import { createToolExecutor } from '../tool/create-tool-executor.js';
|
|
31
|
+
import { MockToolExecutor } from '../tool/mock-tool-executor.js';
|
|
32
|
+
import { DevToolExecutor } from '../tool/dev-tool-executor.js';
|
|
33
|
+
import { AllowAllGovernanceClient, HttpGovernanceClient, } from '../governance/index.js';
|
|
34
|
+
import { InvokeOrchestrator, StreamOrchestrator, SessionService, MessageService, SessionContextService, TaskService, LangGraphAdapter, HitlHandler, TokenBudgetService, InMemoryTokenBudgetRepository, TokenStatsService, TokenBudgetGuard, SessionBudgetChecker, createAgentRegistryClient, GraphLoader, } from '../index.js';
|
|
35
|
+
import { createAgentRuntime } from './agent-runtime.js';
|
|
36
|
+
import { assembleRuntimeStorage } from './storage-profile.js';
|
|
37
|
+
import { resolveSkillHotReload, watchPreinstallSkillRoot, watchSkillRoots } from '../registry/skill-tree.js';
|
|
38
|
+
/**
|
|
39
|
+
* 装配本地 dev 模式所需的全部 Runtime 依赖
|
|
40
|
+
*
|
|
41
|
+
* @returns DevRuntime(含 invokeOrchestrator / streamOrchestrator / 诊断摘要)
|
|
42
|
+
* @throws EAP_LLM_MODE=local 但解不出任何密钥时抛错,避免静默 Echo
|
|
43
|
+
*/
|
|
44
|
+
export function createDevRuntime() {
|
|
45
|
+
const foundationUrl = process.env.FOUNDATION_SERVICE_URL ?? 'http://localhost:3100';
|
|
46
|
+
const foundationConfigured = Boolean(process.env.FOUNDATION_SERVICE_URL && process.env.FOUNDATION_SERVICE_URL.trim().length > 0);
|
|
47
|
+
const toolExecutionMode = (process.env.EAP_TOOL_EXECUTION_MODE ?? 'mcp').toLowerCase();
|
|
48
|
+
const deploymentContext = process.env.EAP_DEPLOYMENT_CONTEXT ?? 'server';
|
|
49
|
+
// ── 存储 profile(默认 dev:File Session/Message/Checkpoint)──
|
|
50
|
+
// 兼容旧变量:EAP_SESSION_STORE=memory → 强制 test(全内存)
|
|
51
|
+
const legacySessionStore = process.env.EAP_SESSION_STORE?.toLowerCase();
|
|
52
|
+
const storage = assembleRuntimeStorage({
|
|
53
|
+
defaultProfile: legacySessionStore === 'memory' || legacySessionStore === 'in-memory' ? 'test' : 'dev',
|
|
54
|
+
profile: legacySessionStore === 'memory' || legacySessionStore === 'in-memory'
|
|
55
|
+
? 'test'
|
|
56
|
+
: undefined,
|
|
57
|
+
});
|
|
58
|
+
// ── LLM Provider(本地 eap.config runtime.llm 优先,再 Foundation 路由,再环境直连)──
|
|
59
|
+
let llmProviderKind;
|
|
60
|
+
let llmProvider;
|
|
61
|
+
const localLlm = process.env.EAP_LLM_MODE === 'local';
|
|
62
|
+
if (localLlm || (!foundationConfigured && process.env.OPENAI_API_KEY)) {
|
|
63
|
+
llmProvider = localLlm
|
|
64
|
+
? createLocalLlmProvider(requireLocalLlmConnections())
|
|
65
|
+
: new HttpLLMProvider({
|
|
66
|
+
apiKey: process.env.OPENAI_API_KEY ?? '',
|
|
67
|
+
baseUrl: process.env.OPENAI_BASE_URL,
|
|
68
|
+
defaultModel: process.env.EAP_DEFAULT_MODEL,
|
|
69
|
+
});
|
|
70
|
+
llmProviderKind = 'openai-http';
|
|
71
|
+
}
|
|
72
|
+
else if (foundationConfigured) {
|
|
73
|
+
llmProvider = new RoutingLLMProvider({ foundationUrl });
|
|
74
|
+
llmProviderKind = 'routing';
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
llmProvider = createDefaultLLMProvider();
|
|
78
|
+
llmProviderKind = 'echo';
|
|
79
|
+
}
|
|
80
|
+
// ── Tool Executor(显式 mock → dev+mcp 直连,缺配置失败 → 通用路由)──
|
|
81
|
+
const toolExecutor = toolExecutionMode === 'mock'
|
|
82
|
+
? new MockToolExecutor({ toolsDir: process.env.EAP_LOCAL_TOOLS_DIR })
|
|
83
|
+
: toolExecutionMode === 'mcp' && deploymentContext === 'dev'
|
|
84
|
+
? new DevToolExecutor()
|
|
85
|
+
: createToolExecutor({ foundationUrl, deploymentContext });
|
|
86
|
+
// ── Governance ──
|
|
87
|
+
const governanceClient = process.env.GOVERNANCE_DISABLED === '1' || !foundationConfigured
|
|
88
|
+
? new AllowAllGovernanceClient()
|
|
89
|
+
: new HttpGovernanceClient({ baseUrl: foundationUrl });
|
|
90
|
+
const hitlHandler = new HitlHandler(storage.checkpointSaver, {
|
|
91
|
+
emit: () => { },
|
|
92
|
+
close: () => { },
|
|
93
|
+
heartbeat: () => { },
|
|
94
|
+
});
|
|
95
|
+
const graphEngine = new LangGraphAdapter(storage.checkpointSaver, llmProvider, toolExecutor, governanceClient, hitlHandler);
|
|
96
|
+
// ── Session / Messages ──
|
|
97
|
+
const sessionService = new SessionService(storage.sessionRepository);
|
|
98
|
+
const messageService = new MessageService(storage.messageRepository);
|
|
99
|
+
const sessionContextService = new SessionContextService(sessionService, messageService);
|
|
100
|
+
// ── Task / Token ──
|
|
101
|
+
const taskService = new TaskService();
|
|
102
|
+
const budgetService = new TokenBudgetService(new InMemoryTokenBudgetRepository());
|
|
103
|
+
const tokenStatsService = new TokenStatsService();
|
|
104
|
+
const tokenBudgetGuard = new TokenBudgetGuard(budgetService);
|
|
105
|
+
const sessionBudgetChecker = new SessionBudgetChecker(budgetService);
|
|
106
|
+
// ── Registry / GraphLoader ──
|
|
107
|
+
const registryClient = foundationConfigured
|
|
108
|
+
? createAgentRegistryClient({ baseUrl: foundationUrl })
|
|
109
|
+
: undefined;
|
|
110
|
+
const skillHotReload = resolveSkillHotReload(deploymentContext);
|
|
111
|
+
const preinstallRoot = process.env.EAP_PREINSTALL_ROOT;
|
|
112
|
+
const localSkillsDir = process.env.EAP_LOCAL_SKILLS_DIR;
|
|
113
|
+
const graphLoader = new GraphLoader({
|
|
114
|
+
registryClient,
|
|
115
|
+
deploymentContext,
|
|
116
|
+
localToolsDir: process.env.EAP_LOCAL_TOOLS_DIR,
|
|
117
|
+
localSkillsDir,
|
|
118
|
+
preinstallRoot,
|
|
119
|
+
skillHotReload,
|
|
120
|
+
});
|
|
121
|
+
const stopSkillWatch = skillHotReload
|
|
122
|
+
? (() => {
|
|
123
|
+
const stopPreinstall = preinstallRoot
|
|
124
|
+
? watchPreinstallSkillRoot(preinstallRoot, () => {
|
|
125
|
+
graphLoader.invalidateAllDefinitions();
|
|
126
|
+
})
|
|
127
|
+
: () => { };
|
|
128
|
+
const stopAuthor = localSkillsDir
|
|
129
|
+
? watchSkillRoots([localSkillsDir], () => {
|
|
130
|
+
graphLoader.invalidateAllDefinitions();
|
|
131
|
+
})
|
|
132
|
+
: () => { };
|
|
133
|
+
return () => {
|
|
134
|
+
stopPreinstall();
|
|
135
|
+
stopAuthor();
|
|
136
|
+
};
|
|
137
|
+
})()
|
|
138
|
+
: () => { };
|
|
139
|
+
// ── Orchestrators ──
|
|
140
|
+
const invokeOrchestrator = new InvokeOrchestrator({
|
|
141
|
+
sessionContextService,
|
|
142
|
+
taskService,
|
|
143
|
+
graphEngine,
|
|
144
|
+
tokenStatsService,
|
|
145
|
+
tokenBudgetGuard,
|
|
146
|
+
sessionBudgetChecker,
|
|
147
|
+
messageService,
|
|
148
|
+
graphLoader,
|
|
149
|
+
checkpointSaver: storage.checkpointSaver,
|
|
150
|
+
});
|
|
151
|
+
const streamOrchestrator = new StreamOrchestrator({
|
|
152
|
+
sessionContextService,
|
|
153
|
+
taskService,
|
|
154
|
+
graphEngine,
|
|
155
|
+
tokenStatsService,
|
|
156
|
+
tokenBudgetGuard,
|
|
157
|
+
sessionBudgetChecker,
|
|
158
|
+
messageService,
|
|
159
|
+
graphLoader,
|
|
160
|
+
checkpointSaver: storage.checkpointSaver,
|
|
161
|
+
});
|
|
162
|
+
const agentRuntime = createAgentRuntime({
|
|
163
|
+
invokeOrchestrator,
|
|
164
|
+
sessionContextService,
|
|
165
|
+
taskService,
|
|
166
|
+
graphEngine,
|
|
167
|
+
checkpointSaver: storage.checkpointSaver,
|
|
168
|
+
hitlHandler,
|
|
169
|
+
graphLoader,
|
|
170
|
+
messageService,
|
|
171
|
+
});
|
|
172
|
+
return {
|
|
173
|
+
invokeOrchestrator,
|
|
174
|
+
streamOrchestrator,
|
|
175
|
+
agentRuntime,
|
|
176
|
+
resumeHitl: (taskId, response) => agentRuntime.resumeHitl(taskId, response),
|
|
177
|
+
streamResumeHitl: (taskId, response) => agentRuntime.streamResumeHitl(taskId, response),
|
|
178
|
+
sessionService,
|
|
179
|
+
messageService,
|
|
180
|
+
sessionContextService,
|
|
181
|
+
taskService,
|
|
182
|
+
tokenStatsService,
|
|
183
|
+
graphLoader,
|
|
184
|
+
dispose: stopSkillWatch,
|
|
185
|
+
diagnostics: {
|
|
186
|
+
deploymentContext,
|
|
187
|
+
toolExecutionMode,
|
|
188
|
+
llmProviderKind,
|
|
189
|
+
llmDefaultModel: process.env.EAP_DEFAULT_MODEL ?? 'DeepSeek-V4-Pro',
|
|
190
|
+
governanceKind: governanceClient instanceof AllowAllGovernanceClient ? 'AllowAll' : 'Http',
|
|
191
|
+
storageProfile: storage.profile,
|
|
192
|
+
sessionStoreKind: storage.diagnostics.sessionKind === 'file' ? 'file' : 'in-memory',
|
|
193
|
+
messageStoreKind: storage.diagnostics.messageKind,
|
|
194
|
+
checkpointKind: storage.diagnostics.checkpointKind,
|
|
195
|
+
foundationConfigured,
|
|
196
|
+
skillHotReload,
|
|
197
|
+
},
|
|
198
|
+
};
|
|
199
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { AgentRuntime, createAgentRuntime, type AgentRuntimeDeps, type ForkRelationRecord, type RecordForkRelation, } from './agent-runtime.js';
|
|
2
|
+
export type { ExecuteParams, ExecuteResult, ForkOverrides, ForkResult, HitlResponse, ResumeHitlResult, SSEEvent, } from './types.js';
|
|
3
|
+
export { createDevRuntime, type DevRuntime, } from './dev-runtime.js';
|
|
4
|
+
export { assembleRuntimeStorage, resolveRuntimeStorageProfile, type RuntimeStorageProfile, type AssembleRuntimeStorageOptions, type AssembledRuntimeStorage, } from './storage-profile.js';
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime 存储装配(EAP_RUNTIME_STORAGE_PROFILE)
|
|
3
|
+
*
|
|
4
|
+
* @see docs/governance/governance-env-config.md §9
|
|
5
|
+
* @see docs/architecture/storage-decisions.md — messages.session_id → hosting.sessions.id;不单独建 Runtime sessions 表
|
|
6
|
+
*/
|
|
7
|
+
import { Redis } from 'ioredis';
|
|
8
|
+
import type { ICheckpointSaver } from '../checkpoint/contracts/checkpoint-saver.contract.js';
|
|
9
|
+
import { type IPgPool } from '../checkpoint/pg-checkpoint-saver.js';
|
|
10
|
+
import type { ISessionRepository } from '../session/session.service.js';
|
|
11
|
+
import type { IFullMessageRepository } from '../session/message.service.js';
|
|
12
|
+
export type RuntimeStorageProfile = 'test' | 'dev' | 'integration' | 'production';
|
|
13
|
+
export interface AssembleRuntimeStorageOptions {
|
|
14
|
+
/** 显式 profile;缺省读 EAP_RUNTIME_STORAGE_PROFILE */
|
|
15
|
+
profile?: RuntimeStorageProfile;
|
|
16
|
+
/** 未指定 profile 时的默认值(dev-runtime → dev;embedded → integration) */
|
|
17
|
+
defaultProfile: RuntimeStorageProfile;
|
|
18
|
+
/** File Checkpoint / Session / Message 根目录 */
|
|
19
|
+
checkpointDir?: string;
|
|
20
|
+
sessionDir?: string;
|
|
21
|
+
messageDir?: string;
|
|
22
|
+
/** 注入已有连接(Hosting 复用);未注入时 integration/production 自建 */
|
|
23
|
+
pgPool?: IPgPool;
|
|
24
|
+
redis?: Redis;
|
|
25
|
+
/** Redis key 前缀 */
|
|
26
|
+
redisKeyPrefix?: string;
|
|
27
|
+
}
|
|
28
|
+
export interface AssembledRuntimeStorage {
|
|
29
|
+
profile: RuntimeStorageProfile;
|
|
30
|
+
checkpointSaver: ICheckpointSaver;
|
|
31
|
+
/** undefined = SessionService 默认 InMemory */
|
|
32
|
+
sessionRepository?: ISessionRepository;
|
|
33
|
+
messageRepository: IFullMessageRepository;
|
|
34
|
+
diagnostics: {
|
|
35
|
+
profile: RuntimeStorageProfile;
|
|
36
|
+
checkpointKind: 'memory' | 'file' | 'redis+pg' | 'pg';
|
|
37
|
+
sessionKind: 'memory' | 'file';
|
|
38
|
+
messageKind: 'memory' | 'file' | 'postgres';
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
export declare function resolveRuntimeStorageProfile(explicit: RuntimeStorageProfile | undefined, defaultProfile: RuntimeStorageProfile, env?: NodeJS.ProcessEnv): RuntimeStorageProfile;
|
|
42
|
+
/**
|
|
43
|
+
* 按 profile 装配 Checkpoint / Session / Message 存储
|
|
44
|
+
*
|
|
45
|
+
* - test: 全内存
|
|
46
|
+
* - dev: File Checkpoint + File Session + File Message
|
|
47
|
+
* - integration/production: Message=PG;Checkpoint=Redis 热 + PG 备;
|
|
48
|
+
* Session 仓储不落 PG(sessionId 权威在 Hosting.sessions,Runtime 内存采纳)
|
|
49
|
+
*/
|
|
50
|
+
export declare function assembleRuntimeStorage(options: AssembleRuntimeStorageOptions, env?: NodeJS.ProcessEnv): AssembledRuntimeStorage;
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime 存储装配(EAP_RUNTIME_STORAGE_PROFILE)
|
|
3
|
+
*
|
|
4
|
+
* @see docs/governance/governance-env-config.md §9
|
|
5
|
+
* @see docs/architecture/storage-decisions.md — messages.session_id → hosting.sessions.id;不单独建 Runtime sessions 表
|
|
6
|
+
*/
|
|
7
|
+
// @ts-expect-error pg 无内置类型;Hosting 侧同样按 any 使用
|
|
8
|
+
import pg from 'pg';
|
|
9
|
+
import { Redis } from 'ioredis';
|
|
10
|
+
import { FileCheckpointSaver } from '../checkpoint/file-checkpoint-saver.js';
|
|
11
|
+
import { PostgresCheckpointSaver } from '../checkpoint/pg-checkpoint-saver.js';
|
|
12
|
+
import { RedisCheckpointSaver } from '../checkpoint/redis-checkpoint-saver.js';
|
|
13
|
+
import { CompositeCheckpointSaver } from '../checkpoint/composite-checkpoint-saver.js';
|
|
14
|
+
import { InMemoryCheckpointSaver } from '../checkpoint/in-memory-checkpoint-saver.js';
|
|
15
|
+
import { FileSessionRepository } from '../session/file-session.repository.js';
|
|
16
|
+
import { InMemoryFullMessageRepository } from '../session/message.service.js';
|
|
17
|
+
import { FileMessageRepository } from '../session/file-message.repository.js';
|
|
18
|
+
import { PostgresMessageRepository } from '../session/pg-message.repository.js';
|
|
19
|
+
const { Pool } = pg;
|
|
20
|
+
const VALID_PROFILES = new Set([
|
|
21
|
+
'test',
|
|
22
|
+
'dev',
|
|
23
|
+
'integration',
|
|
24
|
+
'production',
|
|
25
|
+
]);
|
|
26
|
+
export function resolveRuntimeStorageProfile(explicit, defaultProfile, env = process.env) {
|
|
27
|
+
const raw = explicit ?? env.EAP_RUNTIME_STORAGE_PROFILE;
|
|
28
|
+
if (raw && VALID_PROFILES.has(raw)) {
|
|
29
|
+
return raw;
|
|
30
|
+
}
|
|
31
|
+
return defaultProfile;
|
|
32
|
+
}
|
|
33
|
+
function requireDbEnv(env) {
|
|
34
|
+
const missing = [];
|
|
35
|
+
if (!env.DB_HOST && !env.DATABASE_URL)
|
|
36
|
+
missing.push('DB_HOST 或 DATABASE_URL');
|
|
37
|
+
if (!env.DB_NAME && !env.DATABASE_URL)
|
|
38
|
+
missing.push('DB_NAME 或 DATABASE_URL');
|
|
39
|
+
if (!env.DB_USER && !env.DATABASE_URL)
|
|
40
|
+
missing.push('DB_USER 或 DATABASE_URL');
|
|
41
|
+
if (missing.length > 0) {
|
|
42
|
+
throw new Error(`[EAP_RUNTIME_STORAGE_PROFILE] integration/production 缺少数据库配置: ${missing.join(', ')}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function requireRedisEnv(env) {
|
|
46
|
+
if (!env.REDIS_HOST && !env.REDIS_URL) {
|
|
47
|
+
throw new Error('[EAP_RUNTIME_STORAGE_PROFILE] integration/production 缺少 REDIS_HOST 或 REDIS_URL(禁止回退 File Checkpoint)');
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function createPgPoolFromEnv(env) {
|
|
51
|
+
if (env.DATABASE_URL) {
|
|
52
|
+
return new Pool({ connectionString: env.DATABASE_URL });
|
|
53
|
+
}
|
|
54
|
+
return new Pool({
|
|
55
|
+
host: env.DB_HOST ?? 'localhost',
|
|
56
|
+
port: parseInt(env.DB_PORT ?? '5432', 10),
|
|
57
|
+
database: env.DB_NAME ?? 'eap_hosting',
|
|
58
|
+
user: env.DB_USER ?? 'postgres',
|
|
59
|
+
password: env.DB_PASSWORD ?? '',
|
|
60
|
+
max: 10,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
function createRedisFromEnv(env) {
|
|
64
|
+
if (env.REDIS_URL) {
|
|
65
|
+
return new Redis(env.REDIS_URL);
|
|
66
|
+
}
|
|
67
|
+
const password = env.REDIS_PASSWORD || undefined;
|
|
68
|
+
return new Redis({
|
|
69
|
+
host: env.REDIS_HOST ?? 'localhost',
|
|
70
|
+
port: parseInt(env.REDIS_PORT ?? '6379', 10),
|
|
71
|
+
password,
|
|
72
|
+
db: parseInt(env.REDIS_DB ?? '0', 10),
|
|
73
|
+
maxRetriesPerRequest: 1,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* 按 profile 装配 Checkpoint / Session / Message 存储
|
|
78
|
+
*
|
|
79
|
+
* - test: 全内存
|
|
80
|
+
* - dev: File Checkpoint + File Session + File Message
|
|
81
|
+
* - integration/production: Message=PG;Checkpoint=Redis 热 + PG 备;
|
|
82
|
+
* Session 仓储不落 PG(sessionId 权威在 Hosting.sessions,Runtime 内存采纳)
|
|
83
|
+
*/
|
|
84
|
+
export function assembleRuntimeStorage(options, env = process.env) {
|
|
85
|
+
const profile = resolveRuntimeStorageProfile(options.profile, options.defaultProfile, env);
|
|
86
|
+
const checkpointDir = options.checkpointDir ?? env.EAP_CHECKPOINT_DIR ?? '/tmp/eap-checkpoints';
|
|
87
|
+
const sessionDir = options.sessionDir ?? env.EAP_SESSION_DIR ?? '/tmp/eap-sessions';
|
|
88
|
+
const messageDir = options.messageDir ?? env.EAP_MESSAGE_DIR ?? `${sessionDir.replace(/\/$/, '')}/messages`;
|
|
89
|
+
if (profile === 'test') {
|
|
90
|
+
return {
|
|
91
|
+
profile,
|
|
92
|
+
checkpointSaver: new InMemoryCheckpointSaver(),
|
|
93
|
+
sessionRepository: undefined,
|
|
94
|
+
messageRepository: new InMemoryFullMessageRepository(),
|
|
95
|
+
diagnostics: {
|
|
96
|
+
profile,
|
|
97
|
+
checkpointKind: 'memory',
|
|
98
|
+
sessionKind: 'memory',
|
|
99
|
+
messageKind: 'memory',
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
if (profile === 'dev') {
|
|
104
|
+
return {
|
|
105
|
+
profile,
|
|
106
|
+
checkpointSaver: new FileCheckpointSaver(checkpointDir),
|
|
107
|
+
sessionRepository: new FileSessionRepository({ baseDir: sessionDir }),
|
|
108
|
+
messageRepository: new FileMessageRepository({ baseDir: messageDir }),
|
|
109
|
+
diagnostics: {
|
|
110
|
+
profile,
|
|
111
|
+
checkpointKind: 'file',
|
|
112
|
+
sessionKind: 'file',
|
|
113
|
+
messageKind: 'file',
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
requireDbEnv(env);
|
|
118
|
+
requireRedisEnv(env);
|
|
119
|
+
const pool = options.pgPool ?? createPgPoolFromEnv(env);
|
|
120
|
+
const redis = options.redis ?? createRedisFromEnv(env);
|
|
121
|
+
const pgSaver = new PostgresCheckpointSaver(pool);
|
|
122
|
+
const redisSaver = new RedisCheckpointSaver(redis, {
|
|
123
|
+
keyPrefix: options.redisKeyPrefix ?? env.REDIS_KEY_PREFIX ?? 'eap:rt:',
|
|
124
|
+
});
|
|
125
|
+
const checkpointSaver = new CompositeCheckpointSaver(pgSaver, redisSaver);
|
|
126
|
+
return {
|
|
127
|
+
profile,
|
|
128
|
+
checkpointSaver,
|
|
129
|
+
sessionRepository: undefined,
|
|
130
|
+
messageRepository: new PostgresMessageRepository(pool),
|
|
131
|
+
diagnostics: {
|
|
132
|
+
profile,
|
|
133
|
+
checkpointKind: 'redis+pg',
|
|
134
|
+
sessionKind: 'memory',
|
|
135
|
+
messageKind: 'postgres',
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AgentRuntime SDK 类型 — 供 Hosting 内嵌与 eap dev 调用
|
|
3
|
+
*
|
|
4
|
+
* HITL:`stream()` 在 `hitl.waited` 后结束;续跑走 `streamResumeHitl()`(新 SSE)。
|
|
5
|
+
* `resumeHitl()` 消费该流并返回 `ResumeHitlResult`。
|
|
6
|
+
*
|
|
7
|
+
* @see 04-runtime-core/design.md §1.5
|
|
8
|
+
*/
|
|
9
|
+
import type { ExecutionContext, InvokeConfig, ResumeHitlResult } from '@gt-fe/eap-contracts';
|
|
10
|
+
import type { InvokeResponseData } from '../api/routes/agent.routes.js';
|
|
11
|
+
import type { GraphMessage } from '../graph/contracts/executable-graph.js';
|
|
12
|
+
import type { SSEEvent } from '../sse/contracts/sse-emitter.contract.js';
|
|
13
|
+
/** 同步/流式执行参数 */
|
|
14
|
+
export interface ExecuteParams {
|
|
15
|
+
/**
|
|
16
|
+
* @deprecated 使用 agentCode;保留仅为迁移双读
|
|
17
|
+
*/
|
|
18
|
+
agentId?: string;
|
|
19
|
+
/** 对外主键(优先) */
|
|
20
|
+
agentCode?: string;
|
|
21
|
+
input: string;
|
|
22
|
+
/** 平台执行上下文(Hosting / eap dev 注入,对齐 04 R15) */
|
|
23
|
+
executionContext?: ExecutionContext;
|
|
24
|
+
sessionId?: string;
|
|
25
|
+
/** Hosting 发号的 Task ID;有则 Runtime 复用 */
|
|
26
|
+
taskId?: string;
|
|
27
|
+
/** Hosting 路由选定的预装版本目录(AR-3b) */
|
|
28
|
+
agentVersion?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Hosting 已创建的 Trace id(Foundation `POST /traces` / TraceLinker.createTrace 的返回值)。
|
|
31
|
+
* 写入 GraphState 供 Skill/Tool span。
|
|
32
|
+
*/
|
|
33
|
+
traceId?: string;
|
|
34
|
+
config?: InvokeConfig;
|
|
35
|
+
}
|
|
36
|
+
/** 同步执行结果 */
|
|
37
|
+
export type ExecuteResult = InvokeResponseData;
|
|
38
|
+
/** HITL 恢复结果(与 @gt-fe/eap-contracts ResumeHitlResult 对齐) */
|
|
39
|
+
export type { ResumeHitlResult };
|
|
40
|
+
/** HITL 用户响应 */
|
|
41
|
+
export interface HitlResponse {
|
|
42
|
+
choice: string;
|
|
43
|
+
userId: string;
|
|
44
|
+
executionContext?: ExecutionContext;
|
|
45
|
+
/**
|
|
46
|
+
* Checkpoint thread_id 提示(冷恢复)。
|
|
47
|
+
* Hosting 可从 tasks.output.hitlThreadId 注入;优先于 sessionId。
|
|
48
|
+
*/
|
|
49
|
+
threadId?: string;
|
|
50
|
+
}
|
|
51
|
+
/** Fork 参数覆盖 */
|
|
52
|
+
export interface ForkOverrides {
|
|
53
|
+
model?: string;
|
|
54
|
+
toolInputs?: Record<string, unknown>;
|
|
55
|
+
skipNodes?: string[];
|
|
56
|
+
state?: Record<string, unknown>;
|
|
57
|
+
/** 源 Trace ID(未提供时从 checkpoint 元数据读取) */
|
|
58
|
+
originalTraceId?: string;
|
|
59
|
+
/**
|
|
60
|
+
* @deprecated 使用 agentCode
|
|
61
|
+
*/
|
|
62
|
+
agentId?: string;
|
|
63
|
+
/** 执行所用 Agent(未提供时从 checkpoint state 读取) */
|
|
64
|
+
agentCode?: string;
|
|
65
|
+
/** 预装版本(未提供时从 checkpoint state.agentVersion 读取) */
|
|
66
|
+
agentVersion?: string;
|
|
67
|
+
userId?: string;
|
|
68
|
+
sessionId?: string;
|
|
69
|
+
/** 续操作时的执行上下文(Hosting 注入) */
|
|
70
|
+
executionContext?: ExecutionContext;
|
|
71
|
+
}
|
|
72
|
+
/** Fork 执行结果 */
|
|
73
|
+
export interface ForkResult {
|
|
74
|
+
newTraceId: string;
|
|
75
|
+
originalTraceId: string;
|
|
76
|
+
newTaskId: string;
|
|
77
|
+
checkpointId: string;
|
|
78
|
+
status: 'completed' | 'failed';
|
|
79
|
+
output: unknown;
|
|
80
|
+
tokenUsage: {
|
|
81
|
+
input_tokens: number;
|
|
82
|
+
output_tokens: number;
|
|
83
|
+
total_tokens: number;
|
|
84
|
+
};
|
|
85
|
+
compareUrl?: string;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* 会话种子消息入参 —— 首条真实用户输入之前,向 Runtime session 一次性预置
|
|
89
|
+
* 开发者提供的对话上下文(开场白 / few-shot)。
|
|
90
|
+
*
|
|
91
|
+
* 约束(AgentRuntime.seedSessionMessages 强制校验):
|
|
92
|
+
* - `role` 白名单为 `user` / `assistant`,`system` 走 graph.json 的
|
|
93
|
+
* `config.systemPrompt`(由 SystemPromptBuilder 拼平台规则),`tool` 必须与
|
|
94
|
+
* 前置 assistant.toolCalls 严格配对,两者禁止作为种子;
|
|
95
|
+
* - 该 session 已有历史时,视作已种入,跳过写入(exactly-once 幂等)。
|
|
96
|
+
*/
|
|
97
|
+
export interface SeedSessionMessagesParams {
|
|
98
|
+
/**
|
|
99
|
+
* @deprecated 使用 agentCode;保留仅为迁移双读
|
|
100
|
+
*/
|
|
101
|
+
agentId?: string;
|
|
102
|
+
/** 对外主键(优先) */
|
|
103
|
+
agentCode?: string;
|
|
104
|
+
/** 预装版本(写入 session.metadata.agentVersion,续聊回退) */
|
|
105
|
+
agentVersion?: string;
|
|
106
|
+
/** 会话 ID;未提供时新建 session */
|
|
107
|
+
sessionId?: string;
|
|
108
|
+
/** 平台执行上下文(Hosting / eap dev 注入) */
|
|
109
|
+
executionContext?: ExecutionContext;
|
|
110
|
+
/** 种子消息列表(role ∈ user | assistant,content 非空) */
|
|
111
|
+
messages: GraphMessage[];
|
|
112
|
+
}
|
|
113
|
+
/** 种子消息执行结果 */
|
|
114
|
+
export interface SeedSessionMessagesResult {
|
|
115
|
+
/** 复用或新建的 session ID */
|
|
116
|
+
sessionId: string;
|
|
117
|
+
/** true=本次写入了种子;false=既有历史已存在,跳过写入 */
|
|
118
|
+
seeded: boolean;
|
|
119
|
+
}
|
|
120
|
+
export type { SSEEvent };
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @eap/runtime HTTP 服务入口
|
|
3
|
+
*
|
|
4
|
+
* Phase 1 独立部署模式:包装 InvokeOrchestrator / StreamOrchestrator 为 REST API。
|
|
5
|
+
* Phase 2+ 推荐由 hosting-service 内嵌 SDK,本服务可选。
|
|
6
|
+
*
|
|
7
|
+
* TODO: Phase 2 将本文件迁移至 dev-tools/cli(作为 `eap dev` 命令实现),
|
|
8
|
+
* runtime 包不再包含 HTTP 服务代码,仅作为纯库导出。
|
|
9
|
+
*/
|
|
10
|
+
import { type IncomingMessage, type ServerResponse } from 'node:http';
|
|
11
|
+
declare const server: import("http").Server<typeof IncomingMessage, typeof ServerResponse>;
|
|
12
|
+
export { server };
|