@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,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node Retry — 通用节点级重试执行器
|
|
3
|
+
*
|
|
4
|
+
* 为 StateGraph 中任意节点提供可配置的重试逻辑:
|
|
5
|
+
* - 支持 exponential / linear / fixed 退避策略 + jitter
|
|
6
|
+
* - 支持 AbortSignal(Graph级 timeout 时停止重试)
|
|
7
|
+
* - 跟踪重试次数供 observability 使用
|
|
8
|
+
* - 提供 withRetry 高阶函数包装节点函数
|
|
9
|
+
*
|
|
10
|
+
* @see design.md Issue#1: 两级重试(节点级 + Graph级 timeout)
|
|
11
|
+
* @see requirements.md Requirement 1 AC6
|
|
12
|
+
*/
|
|
13
|
+
import type { NodeRetryConfig } from '../contracts/executable-graph.js';
|
|
14
|
+
/**
|
|
15
|
+
* NodeFunction — StateGraph 节点函数签名
|
|
16
|
+
*
|
|
17
|
+
* 接受当前 state 返回更新后的 state(partial 或完整)。
|
|
18
|
+
*/
|
|
19
|
+
export type NodeFunction = (state: Record<string, unknown>) => Promise<Record<string, unknown>>;
|
|
20
|
+
/**
|
|
21
|
+
* RetryAttemptInfo — 单次重试的观测信息
|
|
22
|
+
*/
|
|
23
|
+
export interface RetryAttemptInfo {
|
|
24
|
+
/** 第几次尝试(从 1 开始,首次执行=1) */
|
|
25
|
+
attempt: number;
|
|
26
|
+
/** 本次等待的退避延迟(毫秒) */
|
|
27
|
+
delayMs: number;
|
|
28
|
+
/** 本次失败的错误 */
|
|
29
|
+
error: Error;
|
|
30
|
+
/** 时间戳 (ISO 8601) */
|
|
31
|
+
timestamp: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* RetryResult — 重试执行结果(含观测数据)
|
|
35
|
+
*/
|
|
36
|
+
export interface RetryResult<T> {
|
|
37
|
+
/** 最终执行结果 */
|
|
38
|
+
result: T;
|
|
39
|
+
/** 总尝试次数(含首次) */
|
|
40
|
+
totalAttempts: number;
|
|
41
|
+
/** 各次重试的详细信息(不含最终成功的那次) */
|
|
42
|
+
retryAttempts: RetryAttemptInfo[];
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* RetryExhaustedError — 重试耗尽错误
|
|
46
|
+
*
|
|
47
|
+
* 当所有重试次数用完仍未成功时抛出。
|
|
48
|
+
*/
|
|
49
|
+
export declare class RetryExhaustedError extends Error {
|
|
50
|
+
/** 总尝试次数(含首次) */
|
|
51
|
+
readonly attempts: number;
|
|
52
|
+
/** 最后一次失败的原始错误 */
|
|
53
|
+
readonly lastError: Error;
|
|
54
|
+
/** 关联的节点 ID */
|
|
55
|
+
readonly nodeId: string;
|
|
56
|
+
/** 各次重试的详细记录 */
|
|
57
|
+
readonly retryAttempts: RetryAttemptInfo[];
|
|
58
|
+
constructor(opts: {
|
|
59
|
+
attempts: number;
|
|
60
|
+
lastError: Error;
|
|
61
|
+
nodeId: string;
|
|
62
|
+
retryAttempts: RetryAttemptInfo[];
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/** LLM 节点默认重试配置:3 次 + 指数退避 */
|
|
66
|
+
export declare const DEFAULT_LLM_RETRY_CONFIG: Required<NodeRetryConfig>;
|
|
67
|
+
/** 通用节点默认重试配置:1 次 + fixed */
|
|
68
|
+
export declare const DEFAULT_NODE_RETRY_CONFIG: Required<NodeRetryConfig>;
|
|
69
|
+
/**
|
|
70
|
+
* NodeRetryExecutor — 通用节点重试执行器
|
|
71
|
+
*
|
|
72
|
+
* 可包装任意异步函数,提供重试 + 退避 + AbortSignal 支持。
|
|
73
|
+
*/
|
|
74
|
+
export declare class NodeRetryExecutor {
|
|
75
|
+
private readonly nodeId;
|
|
76
|
+
private readonly config;
|
|
77
|
+
constructor(nodeId: string, config?: NodeRetryConfig);
|
|
78
|
+
/**
|
|
79
|
+
* executeWithRetry — 带重试的通用异步函数执行
|
|
80
|
+
*
|
|
81
|
+
* @param fn - 要执行的异步函数
|
|
82
|
+
* @param config - 可选覆盖重试配置(不传则使用构造时配置)
|
|
83
|
+
* @param abortSignal - 可选 AbortSignal,用于 Graph 级 timeout 中断重试
|
|
84
|
+
* @returns RetryResult 包含结果和观测数据
|
|
85
|
+
* @throws RetryExhaustedError 当所有重试用尽
|
|
86
|
+
* @throws Error 当 AbortSignal 中断时抛出原始 abort reason 或 AbortError
|
|
87
|
+
*/
|
|
88
|
+
executeWithRetry<T>(fn: () => Promise<T>, config?: NodeRetryConfig, abortSignal?: AbortSignal): Promise<RetryResult<T>>;
|
|
89
|
+
/**
|
|
90
|
+
* 获取节点 ID
|
|
91
|
+
*/
|
|
92
|
+
getNodeId(): string;
|
|
93
|
+
/**
|
|
94
|
+
* 获取当前配置
|
|
95
|
+
*/
|
|
96
|
+
getConfig(): Required<NodeRetryConfig>;
|
|
97
|
+
/**
|
|
98
|
+
* 计算退避延迟(支持 exponential / linear / fixed + jitter)
|
|
99
|
+
*/
|
|
100
|
+
private calculateDelay;
|
|
101
|
+
/**
|
|
102
|
+
* 可中断的 sleep
|
|
103
|
+
*
|
|
104
|
+
* 支持 AbortSignal 提前中断等待。
|
|
105
|
+
*/
|
|
106
|
+
private sleepWithAbort;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* withRetry — 将节点函数包装为带重试逻辑的版本
|
|
110
|
+
*
|
|
111
|
+
* @param nodeId - 节点标识(用于错误报告和 observability)
|
|
112
|
+
* @param nodeFn - 原始节点函数
|
|
113
|
+
* @param config - 重试配置
|
|
114
|
+
* @param abortSignal - 可选 AbortSignal,用于 Graph 级 timeout 中断
|
|
115
|
+
* @returns 包装后的节点函数,行为与原函数一致但带重试
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```ts
|
|
119
|
+
* const retryableLLM = withRetry('llm-node', llmNodeFn, { maxRetries: 3, backoff: { type: 'exponential', baseDelay: 1000, maxDelay: 30000 } });
|
|
120
|
+
* const result = await retryableLLM(state);
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
export declare function withRetry(nodeId: string, nodeFn: NodeFunction, config: NodeRetryConfig, abortSignal?: AbortSignal): NodeFunction;
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node Retry — 通用节点级重试执行器
|
|
3
|
+
*
|
|
4
|
+
* 为 StateGraph 中任意节点提供可配置的重试逻辑:
|
|
5
|
+
* - 支持 exponential / linear / fixed 退避策略 + jitter
|
|
6
|
+
* - 支持 AbortSignal(Graph级 timeout 时停止重试)
|
|
7
|
+
* - 跟踪重试次数供 observability 使用
|
|
8
|
+
* - 提供 withRetry 高阶函数包装节点函数
|
|
9
|
+
*
|
|
10
|
+
* @see design.md Issue#1: 两级重试(节点级 + Graph级 timeout)
|
|
11
|
+
* @see requirements.md Requirement 1 AC6
|
|
12
|
+
*/
|
|
13
|
+
// ─────────────────────────────────────────────
|
|
14
|
+
// Custom Error
|
|
15
|
+
// ─────────────────────────────────────────────
|
|
16
|
+
/**
|
|
17
|
+
* RetryExhaustedError — 重试耗尽错误
|
|
18
|
+
*
|
|
19
|
+
* 当所有重试次数用完仍未成功时抛出。
|
|
20
|
+
*/
|
|
21
|
+
export class RetryExhaustedError extends Error {
|
|
22
|
+
/** 总尝试次数(含首次) */
|
|
23
|
+
attempts;
|
|
24
|
+
/** 最后一次失败的原始错误 */
|
|
25
|
+
lastError;
|
|
26
|
+
/** 关联的节点 ID */
|
|
27
|
+
nodeId;
|
|
28
|
+
/** 各次重试的详细记录 */
|
|
29
|
+
retryAttempts;
|
|
30
|
+
constructor(opts) {
|
|
31
|
+
super(`Node "${opts.nodeId}" failed after ${opts.attempts} attempts: ${opts.lastError.message}`);
|
|
32
|
+
this.name = 'RetryExhaustedError';
|
|
33
|
+
this.attempts = opts.attempts;
|
|
34
|
+
this.lastError = opts.lastError;
|
|
35
|
+
this.nodeId = opts.nodeId;
|
|
36
|
+
this.retryAttempts = opts.retryAttempts;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
// ─────────────────────────────────────────────
|
|
40
|
+
// Default Config
|
|
41
|
+
// ─────────────────────────────────────────────
|
|
42
|
+
/** LLM 节点默认重试配置:3 次 + 指数退避 */
|
|
43
|
+
export const DEFAULT_LLM_RETRY_CONFIG = {
|
|
44
|
+
maxRetries: 3,
|
|
45
|
+
backoff: {
|
|
46
|
+
type: 'exponential',
|
|
47
|
+
baseDelay: 1000,
|
|
48
|
+
maxDelay: 30000,
|
|
49
|
+
jitter: 0.1,
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
/** 通用节点默认重试配置:1 次 + fixed */
|
|
53
|
+
export const DEFAULT_NODE_RETRY_CONFIG = {
|
|
54
|
+
maxRetries: 1,
|
|
55
|
+
backoff: {
|
|
56
|
+
type: 'fixed',
|
|
57
|
+
baseDelay: 500,
|
|
58
|
+
maxDelay: 5000,
|
|
59
|
+
jitter: 0,
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
// ─────────────────────────────────────────────
|
|
63
|
+
// NodeRetryExecutor
|
|
64
|
+
// ─────────────────────────────────────────────
|
|
65
|
+
/**
|
|
66
|
+
* NodeRetryExecutor — 通用节点重试执行器
|
|
67
|
+
*
|
|
68
|
+
* 可包装任意异步函数,提供重试 + 退避 + AbortSignal 支持。
|
|
69
|
+
*/
|
|
70
|
+
export class NodeRetryExecutor {
|
|
71
|
+
nodeId;
|
|
72
|
+
config;
|
|
73
|
+
constructor(nodeId, config) {
|
|
74
|
+
this.nodeId = nodeId;
|
|
75
|
+
this.config = {
|
|
76
|
+
maxRetries: config?.maxRetries ?? DEFAULT_NODE_RETRY_CONFIG.maxRetries,
|
|
77
|
+
backoff: config?.backoff ?? DEFAULT_NODE_RETRY_CONFIG.backoff,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* executeWithRetry — 带重试的通用异步函数执行
|
|
82
|
+
*
|
|
83
|
+
* @param fn - 要执行的异步函数
|
|
84
|
+
* @param config - 可选覆盖重试配置(不传则使用构造时配置)
|
|
85
|
+
* @param abortSignal - 可选 AbortSignal,用于 Graph 级 timeout 中断重试
|
|
86
|
+
* @returns RetryResult 包含结果和观测数据
|
|
87
|
+
* @throws RetryExhaustedError 当所有重试用尽
|
|
88
|
+
* @throws Error 当 AbortSignal 中断时抛出原始 abort reason 或 AbortError
|
|
89
|
+
*/
|
|
90
|
+
async executeWithRetry(fn, config, abortSignal) {
|
|
91
|
+
const effectiveConfig = {
|
|
92
|
+
maxRetries: config?.maxRetries ?? this.config.maxRetries,
|
|
93
|
+
backoff: config?.backoff ?? this.config.backoff,
|
|
94
|
+
};
|
|
95
|
+
const retryAttempts = [];
|
|
96
|
+
let lastError;
|
|
97
|
+
const totalTries = effectiveConfig.maxRetries + 1; // 首次 + 重试次数
|
|
98
|
+
for (let attempt = 1; attempt <= totalTries; attempt++) {
|
|
99
|
+
// 检查 AbortSignal
|
|
100
|
+
if (abortSignal?.aborted) {
|
|
101
|
+
throw abortSignal.reason instanceof Error
|
|
102
|
+
? abortSignal.reason
|
|
103
|
+
: new Error(abortSignal.reason?.toString() ?? 'Aborted');
|
|
104
|
+
}
|
|
105
|
+
try {
|
|
106
|
+
const result = await fn();
|
|
107
|
+
return {
|
|
108
|
+
result,
|
|
109
|
+
totalAttempts: attempt,
|
|
110
|
+
retryAttempts,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
lastError = error instanceof Error ? error : new Error(String(error));
|
|
115
|
+
// 最后一次尝试不再退避
|
|
116
|
+
if (attempt < totalTries) {
|
|
117
|
+
const delayMs = this.calculateDelay(attempt - 1, effectiveConfig.backoff);
|
|
118
|
+
retryAttempts.push({
|
|
119
|
+
attempt,
|
|
120
|
+
delayMs,
|
|
121
|
+
error: lastError,
|
|
122
|
+
timestamp: new Date().toISOString(),
|
|
123
|
+
});
|
|
124
|
+
// 带 AbortSignal 的 sleep
|
|
125
|
+
await this.sleepWithAbort(delayMs, abortSignal);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
// 所有重试耗尽
|
|
130
|
+
throw new RetryExhaustedError({
|
|
131
|
+
attempts: totalTries,
|
|
132
|
+
lastError: lastError,
|
|
133
|
+
nodeId: this.nodeId,
|
|
134
|
+
retryAttempts,
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* 获取节点 ID
|
|
139
|
+
*/
|
|
140
|
+
getNodeId() {
|
|
141
|
+
return this.nodeId;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* 获取当前配置
|
|
145
|
+
*/
|
|
146
|
+
getConfig() {
|
|
147
|
+
return { ...this.config };
|
|
148
|
+
}
|
|
149
|
+
// ─────────────────────────────────────────────
|
|
150
|
+
// Private
|
|
151
|
+
// ─────────────────────────────────────────────
|
|
152
|
+
/**
|
|
153
|
+
* 计算退避延迟(支持 exponential / linear / fixed + jitter)
|
|
154
|
+
*/
|
|
155
|
+
calculateDelay(retryIndex, backoff) {
|
|
156
|
+
let delay;
|
|
157
|
+
switch (backoff.type) {
|
|
158
|
+
case 'exponential':
|
|
159
|
+
delay = backoff.baseDelay * Math.pow(2, retryIndex);
|
|
160
|
+
break;
|
|
161
|
+
case 'linear':
|
|
162
|
+
delay = backoff.baseDelay * (retryIndex + 1);
|
|
163
|
+
break;
|
|
164
|
+
case 'fixed':
|
|
165
|
+
delay = backoff.baseDelay;
|
|
166
|
+
break;
|
|
167
|
+
default:
|
|
168
|
+
delay = backoff.baseDelay;
|
|
169
|
+
}
|
|
170
|
+
// 限制最大延迟
|
|
171
|
+
delay = Math.min(delay, backoff.maxDelay);
|
|
172
|
+
// 应用 jitter
|
|
173
|
+
if (backoff.jitter && backoff.jitter > 0) {
|
|
174
|
+
const jitterRange = delay * backoff.jitter;
|
|
175
|
+
delay += Math.random() * jitterRange * 2 - jitterRange;
|
|
176
|
+
delay = Math.max(0, delay);
|
|
177
|
+
}
|
|
178
|
+
return Math.round(delay);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* 可中断的 sleep
|
|
182
|
+
*
|
|
183
|
+
* 支持 AbortSignal 提前中断等待。
|
|
184
|
+
*/
|
|
185
|
+
sleepWithAbort(ms, abortSignal) {
|
|
186
|
+
if (!abortSignal) {
|
|
187
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
188
|
+
}
|
|
189
|
+
return new Promise((resolve, reject) => {
|
|
190
|
+
if (abortSignal.aborted) {
|
|
191
|
+
reject(abortSignal.reason instanceof Error
|
|
192
|
+
? abortSignal.reason
|
|
193
|
+
: new Error(abortSignal.reason?.toString() ?? 'Aborted'));
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
const timer = setTimeout(() => {
|
|
197
|
+
abortSignal.removeEventListener('abort', onAbort);
|
|
198
|
+
resolve();
|
|
199
|
+
}, ms);
|
|
200
|
+
function onAbort() {
|
|
201
|
+
clearTimeout(timer);
|
|
202
|
+
reject(abortSignal.reason instanceof Error
|
|
203
|
+
? abortSignal.reason
|
|
204
|
+
: new Error(abortSignal.reason?.toString() ?? 'Aborted'));
|
|
205
|
+
}
|
|
206
|
+
abortSignal.addEventListener('abort', onAbort, { once: true });
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
// ─────────────────────────────────────────────
|
|
211
|
+
// withRetry — 高阶包装函数
|
|
212
|
+
// ─────────────────────────────────────────────
|
|
213
|
+
/**
|
|
214
|
+
* withRetry — 将节点函数包装为带重试逻辑的版本
|
|
215
|
+
*
|
|
216
|
+
* @param nodeId - 节点标识(用于错误报告和 observability)
|
|
217
|
+
* @param nodeFn - 原始节点函数
|
|
218
|
+
* @param config - 重试配置
|
|
219
|
+
* @param abortSignal - 可选 AbortSignal,用于 Graph 级 timeout 中断
|
|
220
|
+
* @returns 包装后的节点函数,行为与原函数一致但带重试
|
|
221
|
+
*
|
|
222
|
+
* @example
|
|
223
|
+
* ```ts
|
|
224
|
+
* const retryableLLM = withRetry('llm-node', llmNodeFn, { maxRetries: 3, backoff: { type: 'exponential', baseDelay: 1000, maxDelay: 30000 } });
|
|
225
|
+
* const result = await retryableLLM(state);
|
|
226
|
+
* ```
|
|
227
|
+
*/
|
|
228
|
+
export function withRetry(nodeId, nodeFn, config, abortSignal) {
|
|
229
|
+
const executor = new NodeRetryExecutor(nodeId, config);
|
|
230
|
+
return async (state) => {
|
|
231
|
+
const { result } = await executor.executeWithRetry(() => nodeFn(state), undefined, // 使用 executor 自身的配置
|
|
232
|
+
abortSignal);
|
|
233
|
+
return result;
|
|
234
|
+
};
|
|
235
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SkillAuditRecorder — Skill 调用台账(RT-6)
|
|
3
|
+
*
|
|
4
|
+
* 记录每次 Skill(子图)激活的审计明细,供后续分析与看板使用。
|
|
5
|
+
* Runtime 负责写入;Gateway 看不到 Skill 调用。
|
|
6
|
+
*
|
|
7
|
+
* @see docs/status/module-status-and-backlog.md RT-6
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Skill 调用审计记录
|
|
11
|
+
*/
|
|
12
|
+
export interface SkillInvocationRecord {
|
|
13
|
+
/** 记录唯一 ID */
|
|
14
|
+
id: string;
|
|
15
|
+
/** Skill ID(子图标识) */
|
|
16
|
+
skillId: string;
|
|
17
|
+
/** Skill 名称 */
|
|
18
|
+
skillName?: string;
|
|
19
|
+
/** @deprecated 使用 agentCode;仅作历史记录查询兜底 */
|
|
20
|
+
agentId?: string;
|
|
21
|
+
/** 调用方 Agent Code */
|
|
22
|
+
agentCode?: string;
|
|
23
|
+
/** 调用用户 ID */
|
|
24
|
+
userId: string;
|
|
25
|
+
/** 所属 Task ID */
|
|
26
|
+
taskId?: string;
|
|
27
|
+
/** 链路关联 ID */
|
|
28
|
+
correlationId?: string;
|
|
29
|
+
/** 调用开始时间 (ISO 8601) */
|
|
30
|
+
startedAt: string;
|
|
31
|
+
/** 调用结束时间 (ISO 8601) */
|
|
32
|
+
completedAt?: string;
|
|
33
|
+
/** 执行耗时(毫秒) */
|
|
34
|
+
durationMs?: number;
|
|
35
|
+
/** 调用结果 */
|
|
36
|
+
status: 'success' | 'failed' | 'denied' | 'timeout';
|
|
37
|
+
/** 失败原因 */
|
|
38
|
+
errorMessage?: string;
|
|
39
|
+
/** Token 消耗(子图级别汇总) */
|
|
40
|
+
tokenUsage?: {
|
|
41
|
+
input: number;
|
|
42
|
+
output: number;
|
|
43
|
+
total: number;
|
|
44
|
+
};
|
|
45
|
+
/** 额外元数据 */
|
|
46
|
+
metadata?: Record<string, unknown>;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* ISkillAuditStore — Skill 审计存储接口
|
|
50
|
+
*
|
|
51
|
+
* 默认实现为内存存储;生产环境应接入 PG 或外部审计服务。
|
|
52
|
+
*/
|
|
53
|
+
export interface ISkillAuditStore {
|
|
54
|
+
/** 写入审计记录 */
|
|
55
|
+
write(record: SkillInvocationRecord): Promise<void>;
|
|
56
|
+
/** 按 Skill ID 查询记录 */
|
|
57
|
+
queryBySkill(skillId: string, limit?: number): Promise<SkillInvocationRecord[]>;
|
|
58
|
+
/** 按 Agent Code 查询记录 */
|
|
59
|
+
queryByAgent(agentCode: string, limit?: number): Promise<SkillInvocationRecord[]>;
|
|
60
|
+
/** 查询最近 N 条记录 */
|
|
61
|
+
queryRecent(limit?: number): Promise<SkillInvocationRecord[]>;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* InMemorySkillAuditStore — 内存 Skill 审计存储(开发/测试用)
|
|
65
|
+
*/
|
|
66
|
+
export declare class InMemorySkillAuditStore implements ISkillAuditStore {
|
|
67
|
+
private readonly records;
|
|
68
|
+
private readonly maxRecords;
|
|
69
|
+
constructor(maxRecords?: number);
|
|
70
|
+
write(record: SkillInvocationRecord): Promise<void>;
|
|
71
|
+
queryBySkill(skillId: string, limit?: number): Promise<SkillInvocationRecord[]>;
|
|
72
|
+
queryByAgent(agentCode: string, limit?: number): Promise<SkillInvocationRecord[]>;
|
|
73
|
+
queryRecent(limit?: number): Promise<SkillInvocationRecord[]>;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* SkillAuditRecorder — Skill 调用审计记录器
|
|
77
|
+
*
|
|
78
|
+
* 在 SubGraphCompiler 执行 Skill 子图时调用,
|
|
79
|
+
* 记录每次激活的完整审计信息。
|
|
80
|
+
*/
|
|
81
|
+
export declare class SkillAuditRecorder {
|
|
82
|
+
private readonly store;
|
|
83
|
+
constructor(store?: ISkillAuditStore);
|
|
84
|
+
/**
|
|
85
|
+
* 开始记录一次 Skill 调用
|
|
86
|
+
*
|
|
87
|
+
* 返回一个 recorder context,调用方在 Skill 完成/失败后调用 finish()
|
|
88
|
+
*/
|
|
89
|
+
startInvocation(params: {
|
|
90
|
+
skillId: string;
|
|
91
|
+
skillName?: string;
|
|
92
|
+
agentCode?: string;
|
|
93
|
+
userId: string;
|
|
94
|
+
taskId?: string;
|
|
95
|
+
correlationId?: string;
|
|
96
|
+
metadata?: Record<string, unknown>;
|
|
97
|
+
}): SkillInvocationContext;
|
|
98
|
+
/**
|
|
99
|
+
* 获取底层存储(供查询使用)
|
|
100
|
+
*/
|
|
101
|
+
getStore(): ISkillAuditStore;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* SkillInvocationContext — 单次 Skill 调用的审计上下文
|
|
105
|
+
*/
|
|
106
|
+
export declare class SkillInvocationContext {
|
|
107
|
+
private readonly record;
|
|
108
|
+
private readonly store;
|
|
109
|
+
constructor(store: ISkillAuditStore, record: SkillInvocationRecord);
|
|
110
|
+
/**
|
|
111
|
+
* 完成调用并写入审计记录
|
|
112
|
+
*/
|
|
113
|
+
finish(result: {
|
|
114
|
+
status?: 'success' | 'failed' | 'denied' | 'timeout';
|
|
115
|
+
errorMessage?: string;
|
|
116
|
+
tokenUsage?: {
|
|
117
|
+
input: number;
|
|
118
|
+
output: number;
|
|
119
|
+
total: number;
|
|
120
|
+
};
|
|
121
|
+
}): Promise<SkillInvocationRecord>;
|
|
122
|
+
/**
|
|
123
|
+
* 获取记录 ID
|
|
124
|
+
*/
|
|
125
|
+
getId(): string;
|
|
126
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SkillAuditRecorder — Skill 调用台账(RT-6)
|
|
3
|
+
*
|
|
4
|
+
* 记录每次 Skill(子图)激活的审计明细,供后续分析与看板使用。
|
|
5
|
+
* Runtime 负责写入;Gateway 看不到 Skill 调用。
|
|
6
|
+
*
|
|
7
|
+
* @see docs/status/module-status-and-backlog.md RT-6
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* InMemorySkillAuditStore — 内存 Skill 审计存储(开发/测试用)
|
|
11
|
+
*/
|
|
12
|
+
export class InMemorySkillAuditStore {
|
|
13
|
+
records = [];
|
|
14
|
+
maxRecords;
|
|
15
|
+
constructor(maxRecords = 10000) {
|
|
16
|
+
this.maxRecords = maxRecords;
|
|
17
|
+
}
|
|
18
|
+
async write(record) {
|
|
19
|
+
this.records.push(record);
|
|
20
|
+
// 超过上限时移除最早的记录
|
|
21
|
+
if (this.records.length > this.maxRecords) {
|
|
22
|
+
this.records.splice(0, this.records.length - this.maxRecords);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
async queryBySkill(skillId, limit = 100) {
|
|
26
|
+
return this.records
|
|
27
|
+
.filter((r) => r.skillId === skillId)
|
|
28
|
+
.slice(-limit)
|
|
29
|
+
.reverse();
|
|
30
|
+
}
|
|
31
|
+
async queryByAgent(agentCode, limit = 100) {
|
|
32
|
+
return this.records
|
|
33
|
+
.filter((r) => r.agentCode === agentCode || r.agentId === agentCode)
|
|
34
|
+
.slice(-limit)
|
|
35
|
+
.reverse();
|
|
36
|
+
}
|
|
37
|
+
async queryRecent(limit = 50) {
|
|
38
|
+
return this.records.slice(-limit).reverse();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* SkillAuditRecorder — Skill 调用审计记录器
|
|
43
|
+
*
|
|
44
|
+
* 在 SubGraphCompiler 执行 Skill 子图时调用,
|
|
45
|
+
* 记录每次激活的完整审计信息。
|
|
46
|
+
*/
|
|
47
|
+
export class SkillAuditRecorder {
|
|
48
|
+
store;
|
|
49
|
+
constructor(store) {
|
|
50
|
+
this.store = store ?? new InMemorySkillAuditStore();
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* 开始记录一次 Skill 调用
|
|
54
|
+
*
|
|
55
|
+
* 返回一个 recorder context,调用方在 Skill 完成/失败后调用 finish()
|
|
56
|
+
*/
|
|
57
|
+
startInvocation(params) {
|
|
58
|
+
const id = `skill-inv-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
59
|
+
const startedAt = new Date().toISOString();
|
|
60
|
+
return new SkillInvocationContext(this.store, {
|
|
61
|
+
id,
|
|
62
|
+
skillId: params.skillId,
|
|
63
|
+
skillName: params.skillName,
|
|
64
|
+
agentCode: params.agentCode,
|
|
65
|
+
userId: params.userId,
|
|
66
|
+
taskId: params.taskId,
|
|
67
|
+
correlationId: params.correlationId,
|
|
68
|
+
startedAt,
|
|
69
|
+
status: 'success',
|
|
70
|
+
metadata: params.metadata,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* 获取底层存储(供查询使用)
|
|
75
|
+
*/
|
|
76
|
+
getStore() {
|
|
77
|
+
return this.store;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* SkillInvocationContext — 单次 Skill 调用的审计上下文
|
|
82
|
+
*/
|
|
83
|
+
export class SkillInvocationContext {
|
|
84
|
+
record;
|
|
85
|
+
store;
|
|
86
|
+
constructor(store, record) {
|
|
87
|
+
this.store = store;
|
|
88
|
+
this.record = record;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* 完成调用并写入审计记录
|
|
92
|
+
*/
|
|
93
|
+
async finish(result) {
|
|
94
|
+
const completedAt = new Date().toISOString();
|
|
95
|
+
const startedMs = new Date(this.record.startedAt).getTime();
|
|
96
|
+
const durationMs = Date.now() - startedMs;
|
|
97
|
+
const finalRecord = {
|
|
98
|
+
...this.record,
|
|
99
|
+
completedAt,
|
|
100
|
+
durationMs,
|
|
101
|
+
status: result.status ?? 'success',
|
|
102
|
+
errorMessage: result.errorMessage,
|
|
103
|
+
tokenUsage: result.tokenUsage,
|
|
104
|
+
};
|
|
105
|
+
await this.store.write(finalRecord);
|
|
106
|
+
return finalRecord;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* 获取记录 ID
|
|
110
|
+
*/
|
|
111
|
+
getId() {
|
|
112
|
+
return this.record.id;
|
|
113
|
+
}
|
|
114
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export * from './graph/index.js';
|
|
2
|
+
export * from './checkpoint/index.js';
|
|
3
|
+
export * from './task/index.js';
|
|
4
|
+
export * from './runtime/index.js';
|
|
5
|
+
export * from './session/index.js';
|
|
6
|
+
export * from './sse/index.js';
|
|
7
|
+
export * from './token/index.js';
|
|
8
|
+
export * from './tool/index.js';
|
|
9
|
+
/**
|
|
10
|
+
* dev-only HTTP 适配层(`EAP_DEV_HTTP=1`);生产请内嵌 AgentRuntime + Hosting HTTP
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
export * from './api/index.js';
|
|
14
|
+
export * from './memory/index.js';
|
|
15
|
+
export * from './common/index.js';
|
|
16
|
+
export * from './registry/index.js';
|
|
17
|
+
export * from './providers/index.js';
|
|
18
|
+
export type { ITraceCollector, TraceEvent, TraceSession, ExecutionFlowEvent, ExecutionNodeEvent, TraceLinkEvent, TraceLinkNodeEvent, } from './contracts/trace-collector.js';
|
|
19
|
+
export type { ExecutionContext, CallerType, GovernancePermissionCheckParams, GovernancePermissionCheckResult, PermissionDenyReason, } from '@gt-fe/eap-contracts';
|
|
20
|
+
export { HttpGovernanceClient, AllowAllGovernanceClient, resolveExecutionContext, assertToolPermission, assertSkillPermission, PermissionDeniedError, GovernanceUnavailableError, } from './governance/index.js';
|
|
21
|
+
export type { IGovernanceClient } from './governance/index.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// @eap/runtime — Enterprise Agent Platform 运行时核心引擎
|
|
2
|
+
// 所有子模块的统一入口
|
|
3
|
+
// Graph Engine
|
|
4
|
+
export * from './graph/index.js';
|
|
5
|
+
// Checkpoint & State
|
|
6
|
+
export * from './checkpoint/index.js';
|
|
7
|
+
// Task Management
|
|
8
|
+
export * from './task/index.js';
|
|
9
|
+
// AgentRuntime SDK facade(Hosting / eap dev 内嵌入口)
|
|
10
|
+
export * from './runtime/index.js';
|
|
11
|
+
// Session & Messages
|
|
12
|
+
export * from './session/index.js';
|
|
13
|
+
// SSE Streaming
|
|
14
|
+
export * from './sse/index.js';
|
|
15
|
+
// Token Budget & Stats
|
|
16
|
+
export * from './token/index.js';
|
|
17
|
+
// Tool Orchestration
|
|
18
|
+
export * from './tool/index.js';
|
|
19
|
+
/**
|
|
20
|
+
* dev-only HTTP 适配层(`EAP_DEV_HTTP=1`);生产请内嵌 AgentRuntime + Hosting HTTP
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
export * from './api/index.js';
|
|
24
|
+
// Memory (P2)
|
|
25
|
+
export * from './memory/index.js';
|
|
26
|
+
// Common Types(不含 @internal 并发/队列模块)
|
|
27
|
+
export * from './common/index.js';
|
|
28
|
+
// Registry integration
|
|
29
|
+
export * from './registry/index.js';
|
|
30
|
+
// LLM Providers
|
|
31
|
+
export * from './providers/index.js';
|
|
32
|
+
export { HttpGovernanceClient, AllowAllGovernanceClient, resolveExecutionContext, assertToolPermission, assertSkillPermission, PermissionDeniedError, GovernanceUnavailableError, } from './governance/index.js';
|