@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,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RoutingLLMProvider — 基于 Foundation Service 模型路由的 LLM Provider
|
|
3
|
+
*
|
|
4
|
+
* 工作流程:
|
|
5
|
+
* 1. 请求 Foundation `/models/select` 选择最佳模型
|
|
6
|
+
* 2. Foundation 返回模型名称 + Provider 连接配置(baseUrl/apiKey/headers)
|
|
7
|
+
* 3. 用返回的连接配置创建 HttpLLMProvider,发送请求
|
|
8
|
+
*
|
|
9
|
+
* 设计原则:
|
|
10
|
+
* - Runtime 不存任何 LLM 凭证,全部从 Foundation 获取
|
|
11
|
+
* - 支持任意 OpenAI 兼容 API(OpenAI / DeepSeek / 本地 Ollama 等)
|
|
12
|
+
* - 连接配置由 Foundation 统一管理,Runtime 无感知
|
|
13
|
+
*/
|
|
14
|
+
import { EchoLLMProvider } from './echo-llm-provider.js';
|
|
15
|
+
import { HttpLLMProvider } from './http-llm-provider.js';
|
|
16
|
+
export class RoutingLLMProvider {
|
|
17
|
+
foundationUrl;
|
|
18
|
+
fallback;
|
|
19
|
+
constructor(config) {
|
|
20
|
+
this.foundationUrl = config.foundationUrl.replace(/\/$/, '');
|
|
21
|
+
this.fallback = config.fallbackProvider ?? new EchoLLMProvider();
|
|
22
|
+
}
|
|
23
|
+
async invoke(messages, config) {
|
|
24
|
+
const selected = await this.selectModel(config);
|
|
25
|
+
const provider = this.createProviderForModel(selected);
|
|
26
|
+
return provider.invoke(messages, { ...config, model: selected.name });
|
|
27
|
+
}
|
|
28
|
+
async *stream(messages, config) {
|
|
29
|
+
const selected = await this.selectModel(config);
|
|
30
|
+
const provider = this.createProviderForModel(selected);
|
|
31
|
+
yield* provider.stream(messages, { ...config, model: selected.name });
|
|
32
|
+
}
|
|
33
|
+
async selectModel(config) {
|
|
34
|
+
try {
|
|
35
|
+
const res = await fetch(`${this.foundationUrl}/api/v1/models/select`, {
|
|
36
|
+
method: 'POST',
|
|
37
|
+
headers: { 'Content-Type': 'application/json' },
|
|
38
|
+
body: JSON.stringify({
|
|
39
|
+
preferredModel: config.model,
|
|
40
|
+
capabilities: { chat: true, functionCalling: true },
|
|
41
|
+
}),
|
|
42
|
+
});
|
|
43
|
+
if (res.ok) {
|
|
44
|
+
const body = await res.json();
|
|
45
|
+
if (body.data?.name) {
|
|
46
|
+
return {
|
|
47
|
+
name: body.data.name,
|
|
48
|
+
provider: body.data.provider,
|
|
49
|
+
connection: body.data.connection ?? null,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
// fallback to local
|
|
56
|
+
}
|
|
57
|
+
return { name: config.model ?? 'echo', provider: 'local', connection: null };
|
|
58
|
+
}
|
|
59
|
+
createProviderForModel(selected) {
|
|
60
|
+
// 优先使用 Foundation 返回的连接配置
|
|
61
|
+
if (selected.connection) {
|
|
62
|
+
return new HttpLLMProvider({
|
|
63
|
+
apiKey: selected.connection.apiKey ?? '',
|
|
64
|
+
baseUrl: selected.connection.baseUrl,
|
|
65
|
+
defaultModel: selected.name,
|
|
66
|
+
timeoutMs: selected.connection.timeoutMs,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
// Fallback: 兼容旧逻辑(直接读 env)—— 开发环境快速启动用
|
|
70
|
+
if (process.env.OPENAI_API_KEY && selected.provider === 'openai') {
|
|
71
|
+
return new HttpLLMProvider({
|
|
72
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
73
|
+
baseUrl: process.env.OPENAI_BASE_URL,
|
|
74
|
+
defaultModel: selected.name,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
return this.fallback;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { resolveDeclaredModels, resolveAgentPrimaryModel, resolveAgentModelAllowlist, } from '@gt-fe/eap-contracts';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { resolveDeclaredModels, resolveAgentPrimaryModel, resolveAgentModelAllowlist, } from '@gt-fe/eap-contracts';
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Registry 客户端 — 从 foundation-service 拉取 Agent 定义
|
|
3
|
+
*/
|
|
4
|
+
/** Agent 清单(与 @gt-fe/eap-contracts AgentManifest 对齐) */
|
|
5
|
+
export interface AgentManifest {
|
|
6
|
+
id: string;
|
|
7
|
+
name: string;
|
|
8
|
+
version: string;
|
|
9
|
+
description: string;
|
|
10
|
+
mode: string;
|
|
11
|
+
tools: string[];
|
|
12
|
+
skills: string[];
|
|
13
|
+
prompts: Record<string, string>;
|
|
14
|
+
models?: {
|
|
15
|
+
primary: string;
|
|
16
|
+
alternatives?: string[];
|
|
17
|
+
};
|
|
18
|
+
config?: {
|
|
19
|
+
timeout?: number;
|
|
20
|
+
retryCount?: number;
|
|
21
|
+
};
|
|
22
|
+
metadata: {
|
|
23
|
+
owner: string;
|
|
24
|
+
tags?: string[];
|
|
25
|
+
category?: string;
|
|
26
|
+
graph?: Record<string, unknown>;
|
|
27
|
+
};
|
|
28
|
+
graph?: Record<string, unknown>;
|
|
29
|
+
}
|
|
30
|
+
export interface AgentRegistryClientConfig {
|
|
31
|
+
baseUrl: string;
|
|
32
|
+
timeout?: number;
|
|
33
|
+
}
|
|
34
|
+
export interface AgentRegistryRecord {
|
|
35
|
+
id: string;
|
|
36
|
+
name: string;
|
|
37
|
+
version: string;
|
|
38
|
+
status: string;
|
|
39
|
+
mode: string;
|
|
40
|
+
manifest: AgentManifest & {
|
|
41
|
+
graph?: unknown;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export declare function createAgentRegistryClient(config: AgentRegistryClientConfig): {
|
|
45
|
+
getAgent(agentCode: string): Promise<AgentRegistryRecord | null>;
|
|
46
|
+
getToolByName(toolName: string): Promise<ToolRegistryRecord | null>;
|
|
47
|
+
};
|
|
48
|
+
export type AgentRegistryClient = ReturnType<typeof createAgentRegistryClient>;
|
|
49
|
+
/** Registry Tool 记录(运行期拉取,manifest 保留扩展字段如 http) */
|
|
50
|
+
export interface ToolRegistryRecord {
|
|
51
|
+
id: string;
|
|
52
|
+
name: string;
|
|
53
|
+
version: string;
|
|
54
|
+
status: string;
|
|
55
|
+
manifest: Record<string, unknown>;
|
|
56
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Registry 客户端 — 从 foundation-service 拉取 Agent 定义
|
|
3
|
+
*/
|
|
4
|
+
export function createAgentRegistryClient(config) {
|
|
5
|
+
const { baseUrl, timeout = 5000 } = config;
|
|
6
|
+
async function request(path) {
|
|
7
|
+
const controller = new AbortController();
|
|
8
|
+
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
9
|
+
try {
|
|
10
|
+
const response = await fetch(`${baseUrl}${path}`, {
|
|
11
|
+
signal: controller.signal,
|
|
12
|
+
headers: { Accept: 'application/json' },
|
|
13
|
+
});
|
|
14
|
+
if (!response.ok) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
const data = await response.json();
|
|
18
|
+
return data.data ?? data;
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
finally {
|
|
24
|
+
clearTimeout(timeoutId);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
async getAgent(agentCode) {
|
|
29
|
+
return request(`/api/v1/agents/${agentCode}`);
|
|
30
|
+
},
|
|
31
|
+
async getToolByName(toolName) {
|
|
32
|
+
const result = await request(`/api/v1/tools?search=${encodeURIComponent(toolName)}&pageSize=50`);
|
|
33
|
+
return result?.items?.find((t) => t.name === toolName) ?? null;
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 预装可执行定义进程内缓存(会议目标态:上线 load 后请求命中内存)
|
|
3
|
+
*
|
|
4
|
+
* 缓存 Graph DSL / Tool / Skill 定义;不缓存已编译 StateGraph 实例
|
|
5
|
+
*(每次请求仍 buildGraph,避免可变状态串扰)。
|
|
6
|
+
*/
|
|
7
|
+
import type { GraphDSL } from '../graph/contracts/executable-graph.js';
|
|
8
|
+
import type { LoadedToolDefinition } from '../tool/loaded-tool-definition.js';
|
|
9
|
+
import type { LoadedSkillInfo } from '../tool/system-prompt-builder.js';
|
|
10
|
+
export interface CachedAgentDefinitions {
|
|
11
|
+
/** undefined = 尚未缓存 graph */
|
|
12
|
+
graph?: GraphDSL;
|
|
13
|
+
/** undefined = 尚未缓存 tools;空数组表示已缓存且无 tool */
|
|
14
|
+
tools?: LoadedToolDefinition[];
|
|
15
|
+
/** userId → skills;无用户层时键为 '';缺键表示该 user 视角未缓存 */
|
|
16
|
+
skillsByUser: Map<string, {
|
|
17
|
+
skills: LoadedSkillInfo[];
|
|
18
|
+
stamp: string;
|
|
19
|
+
}>;
|
|
20
|
+
warmedAt: number;
|
|
21
|
+
}
|
|
22
|
+
export declare function cacheKey(agentCode: string, agentVersion?: string): string;
|
|
23
|
+
export declare function skillUserKey(userId?: string): string;
|
|
24
|
+
export declare class PreinstallDefinitionCache {
|
|
25
|
+
private readonly store;
|
|
26
|
+
private ensure;
|
|
27
|
+
get(agentCode: string, agentVersion?: string): CachedAgentDefinitions | undefined;
|
|
28
|
+
setGraph(agentCode: string, agentVersion: string | undefined, graph: GraphDSL): void;
|
|
29
|
+
setTools(agentCode: string, agentVersion: string | undefined, tools: LoadedToolDefinition[]): void;
|
|
30
|
+
setSkills(agentCode: string, agentVersion: string | undefined, userId: string | undefined, skills: LoadedSkillInfo[], stamp?: string): void;
|
|
31
|
+
getSkills(agentCode: string, agentVersion: string | undefined, userId?: string, expectedStamp?: string): LoadedSkillInfo[] | undefined;
|
|
32
|
+
invalidate(agentCode: string, agentVersion?: string): void;
|
|
33
|
+
invalidateAll(): void;
|
|
34
|
+
size(): number;
|
|
35
|
+
}
|
|
36
|
+
/** 解析定义缓存开关:有预装时默认开;EAP_PRELOAD_DEFINITION_CACHE=0 关闭 */
|
|
37
|
+
export declare function resolveDefinitionCacheEnabled(hasPreinstall: boolean, explicit?: boolean): boolean;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 预装可执行定义进程内缓存(会议目标态:上线 load 后请求命中内存)
|
|
3
|
+
*
|
|
4
|
+
* 缓存 Graph DSL / Tool / Skill 定义;不缓存已编译 StateGraph 实例
|
|
5
|
+
*(每次请求仍 buildGraph,避免可变状态串扰)。
|
|
6
|
+
*/
|
|
7
|
+
export function cacheKey(agentCode, agentVersion) {
|
|
8
|
+
return `${agentCode}@${agentVersion ?? 'auto'}`;
|
|
9
|
+
}
|
|
10
|
+
export function skillUserKey(userId) {
|
|
11
|
+
return userId?.trim() ? userId.trim() : '';
|
|
12
|
+
}
|
|
13
|
+
export class PreinstallDefinitionCache {
|
|
14
|
+
store = new Map();
|
|
15
|
+
ensure(agentCode, agentVersion) {
|
|
16
|
+
const key = cacheKey(agentCode, agentVersion);
|
|
17
|
+
let existing = this.store.get(key);
|
|
18
|
+
if (!existing) {
|
|
19
|
+
existing = { skillsByUser: new Map(), warmedAt: Date.now() };
|
|
20
|
+
this.store.set(key, existing);
|
|
21
|
+
}
|
|
22
|
+
return existing;
|
|
23
|
+
}
|
|
24
|
+
get(agentCode, agentVersion) {
|
|
25
|
+
return this.store.get(cacheKey(agentCode, agentVersion));
|
|
26
|
+
}
|
|
27
|
+
setGraph(agentCode, agentVersion, graph) {
|
|
28
|
+
const entry = this.ensure(agentCode, agentVersion);
|
|
29
|
+
entry.graph = graph;
|
|
30
|
+
entry.warmedAt = Date.now();
|
|
31
|
+
}
|
|
32
|
+
setTools(agentCode, agentVersion, tools) {
|
|
33
|
+
const entry = this.ensure(agentCode, agentVersion);
|
|
34
|
+
entry.tools = tools;
|
|
35
|
+
entry.warmedAt = Date.now();
|
|
36
|
+
}
|
|
37
|
+
setSkills(agentCode, agentVersion, userId, skills, stamp = '') {
|
|
38
|
+
const entry = this.ensure(agentCode, agentVersion);
|
|
39
|
+
entry.skillsByUser.set(skillUserKey(userId), { skills, stamp });
|
|
40
|
+
entry.warmedAt = Date.now();
|
|
41
|
+
}
|
|
42
|
+
getSkills(agentCode, agentVersion, userId, expectedStamp) {
|
|
43
|
+
const entry = this.store.get(cacheKey(agentCode, agentVersion));
|
|
44
|
+
if (!entry)
|
|
45
|
+
return undefined;
|
|
46
|
+
const cached = entry.skillsByUser.get(skillUserKey(userId));
|
|
47
|
+
if (!cached)
|
|
48
|
+
return undefined;
|
|
49
|
+
if (expectedStamp !== undefined && cached.stamp !== expectedStamp)
|
|
50
|
+
return undefined;
|
|
51
|
+
return cached.skills;
|
|
52
|
+
}
|
|
53
|
+
invalidate(agentCode, agentVersion) {
|
|
54
|
+
if (agentVersion !== undefined) {
|
|
55
|
+
this.store.delete(cacheKey(agentCode, agentVersion));
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const prefix = `${agentCode}@`;
|
|
59
|
+
for (const key of [...this.store.keys()]) {
|
|
60
|
+
if (key.startsWith(prefix)) {
|
|
61
|
+
this.store.delete(key);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
invalidateAll() {
|
|
66
|
+
this.store.clear();
|
|
67
|
+
}
|
|
68
|
+
size() {
|
|
69
|
+
return this.store.size;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/** 解析定义缓存开关:有预装时默认开;EAP_PRELOAD_DEFINITION_CACHE=0 关闭 */
|
|
73
|
+
export function resolveDefinitionCacheEnabled(hasPreinstall, explicit) {
|
|
74
|
+
if (explicit !== undefined)
|
|
75
|
+
return explicit;
|
|
76
|
+
const v = process.env.EAP_PRELOAD_DEFINITION_CACHE;
|
|
77
|
+
if (v === '0' || v === 'false' || v === 'no')
|
|
78
|
+
return false;
|
|
79
|
+
if (v === '1' || v === 'true' || v === 'yes')
|
|
80
|
+
return true;
|
|
81
|
+
return hasPreinstall;
|
|
82
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deployment 预装快照读取(RT-4 / 04 Req 8.1 / 联调契约)
|
|
3
|
+
*
|
|
4
|
+
* 目录(Agent 自包含,无全局共享层):
|
|
5
|
+
* {root}/agents/<agentCode>/<version>/preinstall/tools/<toolsetCode>/
|
|
6
|
+
* {root}/agents/<agentCode>/<version>/preinstall/skills/<skillCode>/
|
|
7
|
+
* {root}/agents/<agentCode>/<version>/users/<userId>/skills/<skillCode>/
|
|
8
|
+
*
|
|
9
|
+
* 命名:agentCode / toolsetCode / skillCode / toolName 均为语义化小写标识;
|
|
10
|
+
* Skill 目录无版本层(维护形态为 ZIP 上传整包替换,包内必含 skill.md)。
|
|
11
|
+
*/
|
|
12
|
+
export interface SnapshotToolRef {
|
|
13
|
+
toolId?: string;
|
|
14
|
+
name: string;
|
|
15
|
+
version?: string;
|
|
16
|
+
/** 可选:对应 tool.manifest.json 内容 sha256(小写 hex,可带 sha256: 前缀) */
|
|
17
|
+
sha256?: string;
|
|
18
|
+
/**
|
|
19
|
+
* 可选白名单:列出则仅启用所列子工具;省略 = 启用该 toolset 下全部子工具。
|
|
20
|
+
* @see agent.manifest toolRefs[].enabledTools
|
|
21
|
+
*/
|
|
22
|
+
enabledTools?: string[];
|
|
23
|
+
/** 免 HITL 确认的子工具名(覆盖子工具 requireConfirmation) */
|
|
24
|
+
autoApprove?: string[];
|
|
25
|
+
}
|
|
26
|
+
export interface SnapshotSkillRef {
|
|
27
|
+
skillId: string;
|
|
28
|
+
name?: string;
|
|
29
|
+
version?: string;
|
|
30
|
+
description?: string;
|
|
31
|
+
/** 可选:对应 skill 清单文件内容 sha256 */
|
|
32
|
+
sha256?: string;
|
|
33
|
+
}
|
|
34
|
+
export interface AgentSnapshotMeta {
|
|
35
|
+
agentCode: string;
|
|
36
|
+
version: string;
|
|
37
|
+
tools?: SnapshotToolRef[];
|
|
38
|
+
skills?: SnapshotSkillRef[];
|
|
39
|
+
graph?: Record<string, unknown>;
|
|
40
|
+
agentDir: string;
|
|
41
|
+
manifest?: Record<string, unknown>;
|
|
42
|
+
}
|
|
43
|
+
export interface PreinstallToolManifest {
|
|
44
|
+
toolId: string;
|
|
45
|
+
name: string;
|
|
46
|
+
version: string;
|
|
47
|
+
manifest: Record<string, unknown>;
|
|
48
|
+
bundlePath: string;
|
|
49
|
+
}
|
|
50
|
+
export interface PreinstallSkillManifest {
|
|
51
|
+
skillId: string;
|
|
52
|
+
name: string;
|
|
53
|
+
version: string;
|
|
54
|
+
description?: string;
|
|
55
|
+
manifest: Record<string, unknown>;
|
|
56
|
+
bundlePath: string;
|
|
57
|
+
}
|
|
58
|
+
export interface DeploymentSnapshotOptions {
|
|
59
|
+
/** 强制校验 .ready;默认读 EAP_PRELOAD_REQUIRE_READY */
|
|
60
|
+
requireReady?: boolean;
|
|
61
|
+
/** snapshot 必须含 sha256 或 artifacts;默认 EAP_PRELOAD_REQUIRE_CHECKSUM */
|
|
62
|
+
requireChecksum?: boolean;
|
|
63
|
+
}
|
|
64
|
+
export interface IDeploymentSnapshot {
|
|
65
|
+
resolveAgentDir(agentCode: string, version?: string): Promise<string | null>;
|
|
66
|
+
loadAgentSnapshot(agentCode: string, version?: string): Promise<AgentSnapshotMeta | null>;
|
|
67
|
+
loadAgentManifest(agentDir: string): Promise<Record<string, unknown> | null>;
|
|
68
|
+
loadGraphDocument(agentDir: string, manifest?: Record<string, unknown> | null): Promise<Record<string, unknown> | null>;
|
|
69
|
+
loadToolManifest(ref: SnapshotToolRef, agentDir?: string | null): Promise<PreinstallToolManifest | null>;
|
|
70
|
+
loadSkillManifest(ref: SnapshotSkillRef, agentDir?: string | null, userId?: string, extraRoots?: string[]): Promise<PreinstallSkillManifest | null>;
|
|
71
|
+
assertReadyIfRequired(bundlePath: string, label: string): Promise<void>;
|
|
72
|
+
verifySnapshotIntegrity(agentDir: string, snap: Record<string, unknown>): Promise<void>;
|
|
73
|
+
}
|
|
74
|
+
/** 规范化摘要:去 sha256: 前缀、空白,转小写 hex */
|
|
75
|
+
export declare function normalizeDigest(value: unknown): string | null;
|
|
76
|
+
/**
|
|
77
|
+
* 装配引用(toolRefs / 简写 tools[])vs 内联完整 ToolManifest。
|
|
78
|
+
* 含 type/execution 的视为内联定义;仅 toolset/name/version/enabledTools 等视为引用。
|
|
79
|
+
*/
|
|
80
|
+
export declare function isInlineToolDeclaration(item: unknown): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* 将 agent.manifest.toolRefs 上的 enabledTools/autoApprove 叠到 snapshot.tools[](snapshot 未带时)。
|
|
83
|
+
*/
|
|
84
|
+
export declare function overlayToolRefPolicies(snapTools: SnapshotToolRef[], manifest?: Record<string, unknown>): SnapshotToolRef[];
|
|
85
|
+
export declare class FileSystemDeploymentSnapshot implements IDeploymentSnapshot {
|
|
86
|
+
private readonly root;
|
|
87
|
+
private readonly flags;
|
|
88
|
+
constructor(root: string, options?: DeploymentSnapshotOptions);
|
|
89
|
+
private get requireReady();
|
|
90
|
+
assertReadyIfRequired(bundlePath: string, label: string): Promise<void>;
|
|
91
|
+
verifySnapshotIntegrity(agentDir: string, snap: Record<string, unknown>): Promise<void>;
|
|
92
|
+
resolveAgentDir(agentCode: string, version?: string): Promise<string | null>;
|
|
93
|
+
loadAgentManifest(agentDir: string): Promise<Record<string, unknown> | null>;
|
|
94
|
+
loadGraphDocument(agentDir: string, manifest?: Record<string, unknown> | null): Promise<Record<string, unknown> | null>;
|
|
95
|
+
loadAgentSnapshot(agentCode: string, version?: string): Promise<AgentSnapshotMeta | null>;
|
|
96
|
+
loadToolManifest(ref: SnapshotToolRef, agentDir?: string | null): Promise<PreinstallToolManifest | null>;
|
|
97
|
+
loadSkillManifest(ref: SnapshotSkillRef, agentDir?: string | null, userId?: string, extraRoots?: string[]): Promise<PreinstallSkillManifest | null>;
|
|
98
|
+
}
|
|
99
|
+
export declare function createDeploymentSnapshotFromEnv(explicitRoot?: string, options?: DeploymentSnapshotOptions): FileSystemDeploymentSnapshot | undefined;
|