@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.
Files changed (326) hide show
  1. package/README.md +323 -0
  2. package/dist/api/handlers/index.d.ts +3 -0
  3. package/dist/api/handlers/index.js +4 -0
  4. package/dist/api/handlers/invoke.handler.d.ts +77 -0
  5. package/dist/api/handlers/invoke.handler.js +411 -0
  6. package/dist/api/handlers/messages.handler.d.ts +53 -0
  7. package/dist/api/handlers/messages.handler.js +80 -0
  8. package/dist/api/handlers/stream.handler.d.ts +92 -0
  9. package/dist/api/handlers/stream.handler.js +432 -0
  10. package/dist/api/index.d.ts +3 -0
  11. package/dist/api/index.js +4 -0
  12. package/dist/api/middleware/auth.middleware.d.ts +96 -0
  13. package/dist/api/middleware/auth.middleware.js +158 -0
  14. package/dist/api/middleware/index.d.ts +1 -0
  15. package/dist/api/middleware/index.js +2 -0
  16. package/dist/api/routes/agent.routes.d.ts +44 -0
  17. package/dist/api/routes/agent.routes.js +204 -0
  18. package/dist/api/routes/index.d.ts +3 -0
  19. package/dist/api/routes/index.js +4 -0
  20. package/dist/api/routes/session.routes.d.ts +82 -0
  21. package/dist/api/routes/session.routes.js +169 -0
  22. package/dist/api/routes/task.routes.d.ts +75 -0
  23. package/dist/api/routes/task.routes.js +108 -0
  24. package/dist/checkpoint/checkpoint-serializer.d.ts +58 -0
  25. package/dist/checkpoint/checkpoint-serializer.js +81 -0
  26. package/dist/checkpoint/composite-checkpoint-saver.d.ts +42 -0
  27. package/dist/checkpoint/composite-checkpoint-saver.js +118 -0
  28. package/dist/checkpoint/contracts/checkpoint-saver.contract.d.ts +65 -0
  29. package/dist/checkpoint/contracts/checkpoint-saver.contract.js +12 -0
  30. package/dist/checkpoint/contracts/index.d.ts +1 -0
  31. package/dist/checkpoint/contracts/index.js +1 -0
  32. package/dist/checkpoint/file-checkpoint-saver.d.ts +19 -0
  33. package/dist/checkpoint/file-checkpoint-saver.js +98 -0
  34. package/dist/checkpoint/hybrid-checkpoint-saver.d.ts +130 -0
  35. package/dist/checkpoint/hybrid-checkpoint-saver.js +211 -0
  36. package/dist/checkpoint/in-memory-checkpoint-saver.d.ts +14 -0
  37. package/dist/checkpoint/in-memory-checkpoint-saver.js +46 -0
  38. package/dist/checkpoint/index.d.ts +16 -0
  39. package/dist/checkpoint/index.js +13 -0
  40. package/dist/checkpoint/mongo-checkpoint-saver.d.ts +38 -0
  41. package/dist/checkpoint/mongo-checkpoint-saver.js +56 -0
  42. package/dist/checkpoint/pg-checkpoint-saver.d.ts +59 -0
  43. package/dist/checkpoint/pg-checkpoint-saver.js +140 -0
  44. package/dist/checkpoint/redis-checkpoint-saver.d.ts +68 -0
  45. package/dist/checkpoint/redis-checkpoint-saver.js +173 -0
  46. package/dist/checkpoint/restore-checkpoint.d.ts +33 -0
  47. package/dist/checkpoint/restore-checkpoint.js +33 -0
  48. package/dist/common/agent-code.d.ts +10 -0
  49. package/dist/common/agent-code.js +12 -0
  50. package/dist/common/concurrency.d.ts +79 -0
  51. package/dist/common/concurrency.js +121 -0
  52. package/dist/common/health.d.ts +40 -0
  53. package/dist/common/health.js +37 -0
  54. package/dist/common/index.d.ts +5 -0
  55. package/dist/common/index.js +5 -0
  56. package/dist/common/logger.d.ts +34 -0
  57. package/dist/common/logger.js +38 -0
  58. package/dist/common/queue-consumer.d.ts +125 -0
  59. package/dist/common/queue-consumer.js +159 -0
  60. package/dist/common/trace-id.d.ts +2 -0
  61. package/dist/common/trace-id.js +8 -0
  62. package/dist/common/types.d.ts +104 -0
  63. package/dist/common/types.js +14 -0
  64. package/dist/contracts/index.d.ts +11 -0
  65. package/dist/contracts/index.js +10 -0
  66. package/dist/contracts/permission-checker.d.ts +10 -0
  67. package/dist/contracts/permission-checker.js +4 -0
  68. package/dist/contracts/trace-collector.d.ts +211 -0
  69. package/dist/contracts/trace-collector.js +13 -0
  70. package/dist/governance/governance-client.d.ts +38 -0
  71. package/dist/governance/governance-client.js +95 -0
  72. package/dist/governance/index.d.ts +7 -0
  73. package/dist/governance/index.js +5 -0
  74. package/dist/governance/permission-guard.d.ts +19 -0
  75. package/dist/governance/permission-guard.js +59 -0
  76. package/dist/graph/adapters/index.d.ts +3 -0
  77. package/dist/graph/adapters/index.js +3 -0
  78. package/dist/graph/adapters/langgraph-checkpointer.d.ts +40 -0
  79. package/dist/graph/adapters/langgraph-checkpointer.js +211 -0
  80. package/dist/graph/adapters/langgraph.adapter.d.ts +190 -0
  81. package/dist/graph/adapters/langgraph.adapter.js +1303 -0
  82. package/dist/graph/adapters/subgraph-compiler.d.ts +39 -0
  83. package/dist/graph/adapters/subgraph-compiler.js +248 -0
  84. package/dist/graph/condition-evaluator.d.ts +57 -0
  85. package/dist/graph/condition-evaluator.js +162 -0
  86. package/dist/graph/contracts/executable-graph.d.ts +340 -0
  87. package/dist/graph/contracts/executable-graph.js +10 -0
  88. package/dist/graph/contracts/index.d.ts +2 -0
  89. package/dist/graph/contracts/index.js +2 -0
  90. package/dist/graph/contracts/state-graph.contract.d.ts +76 -0
  91. package/dist/graph/contracts/state-graph.contract.js +11 -0
  92. package/dist/graph/hitl/hitl-handler.d.ts +199 -0
  93. package/dist/graph/hitl/hitl-handler.js +480 -0
  94. package/dist/graph/hitl/index.d.ts +1 -0
  95. package/dist/graph/hitl/index.js +1 -0
  96. package/dist/graph/index.d.ts +7 -0
  97. package/dist/graph/index.js +7 -0
  98. package/dist/graph/nodes/index.d.ts +2 -0
  99. package/dist/graph/nodes/index.js +2 -0
  100. package/dist/graph/nodes/llm-node.d.ts +182 -0
  101. package/dist/graph/nodes/llm-node.js +281 -0
  102. package/dist/graph/nodes/skill-bind-node.d.ts +32 -0
  103. package/dist/graph/nodes/skill-bind-node.js +116 -0
  104. package/dist/graph/nodes/tool-node.d.ts +75 -0
  105. package/dist/graph/nodes/tool-node.js +324 -0
  106. package/dist/graph/resolve-graph-prompt.d.ts +5 -0
  107. package/dist/graph/resolve-graph-prompt.js +75 -0
  108. package/dist/graph/retry/budget-aware-retry.d.ts +91 -0
  109. package/dist/graph/retry/budget-aware-retry.js +126 -0
  110. package/dist/graph/retry/index.d.ts +9 -0
  111. package/dist/graph/retry/index.js +8 -0
  112. package/dist/graph/retry/node-retry.d.ts +123 -0
  113. package/dist/graph/retry/node-retry.js +235 -0
  114. package/dist/graph/skill-audit-recorder.d.ts +126 -0
  115. package/dist/graph/skill-audit-recorder.js +114 -0
  116. package/dist/index.d.ts +21 -0
  117. package/dist/index.js +32 -0
  118. package/dist/memory/compression/compression-stats.d.ts +109 -0
  119. package/dist/memory/compression/compression-stats.js +144 -0
  120. package/dist/memory/compression/compression.repository.d.ts +62 -0
  121. package/dist/memory/compression/compression.repository.js +71 -0
  122. package/dist/memory/compression/index.d.ts +10 -0
  123. package/dist/memory/compression/index.js +15 -0
  124. package/dist/memory/compression/llm-summarize.d.ts +58 -0
  125. package/dist/memory/compression/llm-summarize.js +192 -0
  126. package/dist/memory/compression/sliding-window.compression.d.ts +60 -0
  127. package/dist/memory/compression/sliding-window.compression.js +175 -0
  128. package/dist/memory/index.d.ts +4 -0
  129. package/dist/memory/index.js +7 -0
  130. package/dist/memory/long-term-memory.service.d.ts +94 -0
  131. package/dist/memory/long-term-memory.service.js +120 -0
  132. package/dist/memory/message-compression.service.d.ts +128 -0
  133. package/dist/memory/message-compression.service.js +69 -0
  134. package/dist/memory/pg-memory.repository.d.ts +44 -0
  135. package/dist/memory/pg-memory.repository.js +108 -0
  136. package/dist/memory/semantic-retrieval.service.d.ts +148 -0
  137. package/dist/memory/semantic-retrieval.service.js +238 -0
  138. package/dist/providers/echo-llm-provider.d.ts +10 -0
  139. package/dist/providers/echo-llm-provider.js +87 -0
  140. package/dist/providers/http-llm-provider.d.ts +35 -0
  141. package/dist/providers/http-llm-provider.js +404 -0
  142. package/dist/providers/index.d.ts +7 -0
  143. package/dist/providers/index.js +5 -0
  144. package/dist/providers/local-llm-provider.d.ts +27 -0
  145. package/dist/providers/local-llm-provider.js +105 -0
  146. package/dist/providers/resolve-llm-model.d.ts +13 -0
  147. package/dist/providers/resolve-llm-model.js +30 -0
  148. package/dist/providers/routing-llm-provider.d.ts +28 -0
  149. package/dist/providers/routing-llm-provider.js +79 -0
  150. package/dist/registry/agent-models.d.ts +1 -0
  151. package/dist/registry/agent-models.js +1 -0
  152. package/dist/registry/agent-registry-client.d.ts +56 -0
  153. package/dist/registry/agent-registry-client.js +36 -0
  154. package/dist/registry/definition-cache.d.ts +37 -0
  155. package/dist/registry/definition-cache.js +82 -0
  156. package/dist/registry/deployment-snapshot.d.ts +99 -0
  157. package/dist/registry/deployment-snapshot.js +542 -0
  158. package/dist/registry/graph-loader.d.ts +134 -0
  159. package/dist/registry/graph-loader.js +985 -0
  160. package/dist/registry/index.d.ts +9 -0
  161. package/dist/registry/index.js +9 -0
  162. package/dist/registry/preload-errors.d.ts +13 -0
  163. package/dist/registry/preload-errors.js +35 -0
  164. package/dist/registry/preload-flags.d.ts +22 -0
  165. package/dist/registry/preload-flags.js +44 -0
  166. package/dist/registry/skill-io-guard.d.ts +25 -0
  167. package/dist/registry/skill-io-guard.js +98 -0
  168. package/dist/registry/skill-tree.d.ts +27 -0
  169. package/dist/registry/skill-tree.js +183 -0
  170. package/dist/runtime/agent-runtime.d.ts +106 -0
  171. package/dist/runtime/agent-runtime.js +777 -0
  172. package/dist/runtime/dev-runtime.d.ts +69 -0
  173. package/dist/runtime/dev-runtime.js +199 -0
  174. package/dist/runtime/index.d.ts +4 -0
  175. package/dist/runtime/index.js +3 -0
  176. package/dist/runtime/storage-profile.d.ts +50 -0
  177. package/dist/runtime/storage-profile.js +138 -0
  178. package/dist/runtime/types.d.ts +120 -0
  179. package/dist/runtime/types.js +9 -0
  180. package/dist/server.d.ts +12 -0
  181. package/dist/server.js +161 -0
  182. package/dist/session/compression-middleware.d.ts +126 -0
  183. package/dist/session/compression-middleware.js +230 -0
  184. package/dist/session/file-message.repository.d.ts +25 -0
  185. package/dist/session/file-message.repository.js +78 -0
  186. package/dist/session/file-session.repository.d.ts +72 -0
  187. package/dist/session/file-session.repository.js +212 -0
  188. package/dist/session/index.d.ts +13 -0
  189. package/dist/session/index.js +12 -0
  190. package/dist/session/message.service.d.ts +80 -0
  191. package/dist/session/message.service.js +128 -0
  192. package/dist/session/persist-turn-messages.d.ts +145 -0
  193. package/dist/session/persist-turn-messages.js +325 -0
  194. package/dist/session/pg-message.repository.d.ts +49 -0
  195. package/dist/session/pg-message.repository.js +149 -0
  196. package/dist/session/pg-session.repository.d.ts +46 -0
  197. package/dist/session/pg-session.repository.js +117 -0
  198. package/dist/session/session-context.service.d.ts +49 -0
  199. package/dist/session/session-context.service.js +66 -0
  200. package/dist/session/session.service.d.ts +194 -0
  201. package/dist/session/session.service.js +166 -0
  202. package/dist/sse/connection-event-logger.d.ts +21 -0
  203. package/dist/sse/connection-event-logger.js +33 -0
  204. package/dist/sse/contracts/index.d.ts +1 -0
  205. package/dist/sse/contracts/index.js +1 -0
  206. package/dist/sse/contracts/sse-emitter.contract.d.ts +74 -0
  207. package/dist/sse/contracts/sse-emitter.contract.js +11 -0
  208. package/dist/sse/event-buffer.d.ts +20 -0
  209. package/dist/sse/event-buffer.js +45 -0
  210. package/dist/sse/events/code-events.d.ts +19 -0
  211. package/dist/sse/events/code-events.js +9 -0
  212. package/dist/sse/events/collaboration-events.d.ts +37 -0
  213. package/dist/sse/events/collaboration-events.js +11 -0
  214. package/dist/sse/events/connection-events.d.ts +13 -0
  215. package/dist/sse/events/connection-events.js +9 -0
  216. package/dist/sse/events/file-events.d.ts +29 -0
  217. package/dist/sse/events/file-events.js +10 -0
  218. package/dist/sse/events/hitl-events.d.ts +33 -0
  219. package/dist/sse/events/hitl-events.js +10 -0
  220. package/dist/sse/events/index.d.ts +107 -0
  221. package/dist/sse/events/index.js +96 -0
  222. package/dist/sse/events/plan-events.d.ts +38 -0
  223. package/dist/sse/events/plan-events.js +11 -0
  224. package/dist/sse/events/reasoning-events.d.ts +35 -0
  225. package/dist/sse/events/reasoning-events.js +13 -0
  226. package/dist/sse/events/response-events.d.ts +25 -0
  227. package/dist/sse/events/response-events.js +12 -0
  228. package/dist/sse/events/session-events.d.ts +43 -0
  229. package/dist/sse/events/session-events.js +12 -0
  230. package/dist/sse/events/skill-events.d.ts +48 -0
  231. package/dist/sse/events/skill-events.js +11 -0
  232. package/dist/sse/events/stats-events.d.ts +44 -0
  233. package/dist/sse/events/stats-events.js +12 -0
  234. package/dist/sse/events/tool-events.d.ts +68 -0
  235. package/dist/sse/events/tool-events.js +14 -0
  236. package/dist/sse/index.d.ts +8 -0
  237. package/dist/sse/index.js +8 -0
  238. package/dist/sse/sse-connection-manager.d.ts +116 -0
  239. package/dist/sse/sse-connection-manager.js +185 -0
  240. package/dist/sse/sse-emitter.d.ts +108 -0
  241. package/dist/sse/sse-emitter.js +210 -0
  242. package/dist/sse/sse-heartbeat.d.ts +58 -0
  243. package/dist/sse/sse-heartbeat.js +76 -0
  244. package/dist/sse/trace-collector.d.ts +60 -0
  245. package/dist/sse/trace-collector.js +107 -0
  246. package/dist/task/contracts/index.d.ts +2 -0
  247. package/dist/task/contracts/index.js +1 -0
  248. package/dist/task/contracts/task-manager.contract.d.ts +160 -0
  249. package/dist/task/contracts/task-manager.contract.js +10 -0
  250. package/dist/task/index.d.ts +7 -0
  251. package/dist/task/index.js +5 -0
  252. package/dist/task/pg-task.repository.d.ts +47 -0
  253. package/dist/task/pg-task.repository.js +131 -0
  254. package/dist/task/task-progress-tracker.d.ts +67 -0
  255. package/dist/task/task-progress-tracker.js +80 -0
  256. package/dist/task/task-timeout.d.ts +70 -0
  257. package/dist/task/task-timeout.js +116 -0
  258. package/dist/task/task.service.d.ts +84 -0
  259. package/dist/task/task.service.js +233 -0
  260. package/dist/token/compression-budget-integration.d.ts +145 -0
  261. package/dist/token/compression-budget-integration.js +185 -0
  262. package/dist/token/context-window-budget.d.ts +113 -0
  263. package/dist/token/context-window-budget.js +134 -0
  264. package/dist/token/contracts/index.d.ts +1 -0
  265. package/dist/token/contracts/index.js +1 -0
  266. package/dist/token/contracts/token-budget.contract.d.ts +77 -0
  267. package/dist/token/contracts/token-budget.contract.js +11 -0
  268. package/dist/token/index.d.ts +12 -0
  269. package/dist/token/index.js +10 -0
  270. package/dist/token/pg-token-budget.repository.d.ts +39 -0
  271. package/dist/token/pg-token-budget.repository.js +116 -0
  272. package/dist/token/session-budget-checker.d.ts +54 -0
  273. package/dist/token/session-budget-checker.js +72 -0
  274. package/dist/token/token-budget-guard.d.ts +66 -0
  275. package/dist/token/token-budget-guard.js +97 -0
  276. package/dist/token/token-budget.service.d.ts +86 -0
  277. package/dist/token/token-budget.service.js +130 -0
  278. package/dist/token/token-detail-mode.d.ts +73 -0
  279. package/dist/token/token-detail-mode.js +107 -0
  280. package/dist/token/token-estimator.d.ts +80 -0
  281. package/dist/token/token-estimator.js +134 -0
  282. package/dist/token/token-stats.service.d.ts +88 -0
  283. package/dist/token/token-stats.service.js +94 -0
  284. package/dist/tool/create-tool-executor.d.ts +33 -0
  285. package/dist/tool/create-tool-executor.js +60 -0
  286. package/dist/tool/dev-http-executor.d.ts +18 -0
  287. package/dist/tool/dev-http-executor.js +96 -0
  288. package/dist/tool/dev-mcp-executor.d.ts +29 -0
  289. package/dist/tool/dev-mcp-executor.js +84 -0
  290. package/dist/tool/dev-tool-executor.d.ts +23 -0
  291. package/dist/tool/dev-tool-executor.js +55 -0
  292. package/dist/tool/file-artifact.d.ts +11 -0
  293. package/dist/tool/file-artifact.js +90 -0
  294. package/dist/tool/http-tool-executor.d.ts +17 -0
  295. package/dist/tool/http-tool-executor.js +158 -0
  296. package/dist/tool/index.d.ts +18 -0
  297. package/dist/tool/index.js +17 -0
  298. package/dist/tool/loaded-tool-definition.d.ts +35 -0
  299. package/dist/tool/loaded-tool-definition.js +9 -0
  300. package/dist/tool/local-mcp-client.d.ts +23 -0
  301. package/dist/tool/local-mcp-client.js +225 -0
  302. package/dist/tool/local-tool-executor.d.ts +37 -0
  303. package/dist/tool/local-tool-executor.js +249 -0
  304. package/dist/tool/mcp-tool-executor.d.ts +23 -0
  305. package/dist/tool/mcp-tool-executor.js +160 -0
  306. package/dist/tool/mock-tool-executor.d.ts +28 -0
  307. package/dist/tool/mock-tool-executor.js +65 -0
  308. package/dist/tool/system-prompt-builder.d.ts +114 -0
  309. package/dist/tool/system-prompt-builder.js +213 -0
  310. package/dist/tool/tool-confirmation.d.ts +29 -0
  311. package/dist/tool/tool-confirmation.js +81 -0
  312. package/dist/tool/tool-event-emitter.d.ts +58 -0
  313. package/dist/tool/tool-event-emitter.js +154 -0
  314. package/dist/tool/tool-execution-router.d.ts +25 -0
  315. package/dist/tool/tool-execution-router.js +50 -0
  316. package/dist/tool/tool-executor.interface.d.ts +85 -0
  317. package/dist/tool/tool-executor.interface.js +7 -0
  318. package/dist/tool/tool-orchestrator.d.ts +22 -0
  319. package/dist/tool/tool-orchestrator.js +104 -0
  320. package/dist/tool/tool-result-injector.d.ts +64 -0
  321. package/dist/tool/tool-result-injector.js +65 -0
  322. package/dist/utils/format-error.d.ts +4 -0
  323. package/dist/utils/format-error.js +4 -0
  324. package/dist/utils/http-error.d.ts +11 -0
  325. package/dist/utils/http-error.js +24 -0
  326. package/package.json +56 -0
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Task API — Route Handlers(dev-only HTTP 适配层)
3
+ *
4
+ * 生产环境 Task 状态 / HITL 由 Hosting 提供;本模块供 `EAP_DEV_HTTP=1` 本地调试。
5
+ */
6
+ import type { TaskStatus } from '../../common/types.js';
7
+ import type { ITaskManager } from '../../task/task.service.js';
8
+ /**
9
+ * 任务状态查询请求 — GET /api/v1/tasks/:taskId/status
10
+ */
11
+ export interface GetTaskStatusRequest {
12
+ /** Task ID(从路径参数获取) */
13
+ taskId: string;
14
+ }
15
+ /**
16
+ * 任务状态查询响应数据
17
+ */
18
+ export interface GetTaskStatusResponseData {
19
+ /** 当前状态 */
20
+ status: TaskStatus;
21
+ /** 执行进度(0-100) */
22
+ progress: number;
23
+ /** 开始执行时间 (ISO 8601) */
24
+ startedAt: string | null;
25
+ /** 已运行时长(毫秒) */
26
+ duration: number;
27
+ /** 错误信息(如果失败) */
28
+ error?: string;
29
+ }
30
+ /**
31
+ * 任务状态查询完整响应
32
+ */
33
+ export interface GetTaskStatusResponse {
34
+ /** 业务状态码,0 表示成功 */
35
+ code: string;
36
+ /** 响应数据 */
37
+ data: GetTaskStatusResponseData;
38
+ }
39
+ /**
40
+ * HITL 人工介入确认请求 — POST /api/v1/tasks/:taskId/hitl
41
+ */
42
+ export interface PostHitlRequest {
43
+ /** Task ID(从路径参数获取) */
44
+ taskId: string;
45
+ /** 用户选择(确认/拒绝/其他选项) */
46
+ choice: string;
47
+ /** 操作用户 ID */
48
+ userId: string;
49
+ }
50
+ /**
51
+ * HITL 人工介入确认响应数据
52
+ */
53
+ export interface PostHitlResponseData {
54
+ /** 是否已确认接收 */
55
+ acknowledged: boolean;
56
+ }
57
+ /**
58
+ * HITL 人工介入确认完整响应
59
+ */
60
+ export interface PostHitlResponse {
61
+ /** 业务状态码,0 表示成功 */
62
+ code: string;
63
+ /** 响应数据 */
64
+ data: PostHitlResponseData;
65
+ }
66
+ /**
67
+ * 创建 Task 路由处理器
68
+ *
69
+ * @param taskManager - Task 管理器实例
70
+ * @returns 路由处理器函数
71
+ */
72
+ export declare function createTaskRouteHandlers(taskManager: ITaskManager): {
73
+ getTaskStatusHandler: (req: GetTaskStatusRequest) => Promise<GetTaskStatusResponse>;
74
+ postHitlHandler: (req: PostHitlRequest) => Promise<PostHitlResponse>;
75
+ };
@@ -0,0 +1,108 @@
1
+ /**
2
+ * Task API — Route Handlers(dev-only HTTP 适配层)
3
+ *
4
+ * 生产环境 Task 状态 / HITL 由 Hosting 提供;本模块供 `EAP_DEV_HTTP=1` 本地调试。
5
+ */
6
+ // ─────────────────────────────────────────────
7
+ // Route Handlers
8
+ // ─────────────────────────────────────────────
9
+ /**
10
+ * 创建 Task 路由处理器
11
+ *
12
+ * @param taskManager - Task 管理器实例
13
+ * @returns 路由处理器函数
14
+ */
15
+ export function createTaskRouteHandlers(taskManager) {
16
+ /**
17
+ * 查询任务状态(轮询长任务进度)
18
+ *
19
+ * 客户端通过此接口轮询分钟级/小时级长任务的执行进度。
20
+ * SSE 断连后可降级为轮询模式。
21
+ */
22
+ async function getTaskStatusHandler(req) {
23
+ const { taskId } = req;
24
+ try {
25
+ // 获取任务状态
26
+ const task = await taskManager.getStatus(taskId);
27
+ if (!task) {
28
+ return {
29
+ code: 'runtime.task.not_found',
30
+ data: {
31
+ status: 'failed',
32
+ progress: 0,
33
+ startedAt: null,
34
+ duration: 0,
35
+ error: `Task not found: ${taskId}`,
36
+ },
37
+ };
38
+ }
39
+ // 计算已运行时长
40
+ const now = Date.now();
41
+ const startTime = task.startedAt ? new Date(task.startedAt).getTime() : now;
42
+ const duration = task.status === 'running' ? now - startTime : (task.duration ?? 0);
43
+ return {
44
+ code: 'ok',
45
+ data: {
46
+ status: task.status,
47
+ progress: task.progress ?? 0,
48
+ startedAt: task.startedAt ?? null,
49
+ duration,
50
+ error: task.status,
51
+ },
52
+ };
53
+ }
54
+ catch (error) {
55
+ return {
56
+ code: 'runtime.graph.execution_error',
57
+ data: {
58
+ status: 'failed',
59
+ progress: 0,
60
+ startedAt: null,
61
+ duration: 0,
62
+ error: error instanceof Error ? error.message : 'Unknown error',
63
+ },
64
+ };
65
+ }
66
+ }
67
+ /**
68
+ * 提交人工介入确认(HITL)
69
+ *
70
+ * 当 Agent 执行遇到需要人工确认的节点时(如危险操作、require_confirmation Tool),
71
+ * Graph 暂停并推送 hitl.waiting 事件,客户端通过此接口提交用户的确认/拒绝决定。
72
+ */
73
+ async function postHitlHandler(req) {
74
+ const { taskId, choice, userId } = req;
75
+ try {
76
+ // 验证任务存在且处于 HITL 等待状态
77
+ const task = await taskManager.getStatus(taskId);
78
+ if (!task) {
79
+ return {
80
+ code: 'runtime.task.not_found',
81
+ data: { acknowledged: false },
82
+ };
83
+ }
84
+ if (task.status !== 'waiting_hitl' && task.status !== 'running') {
85
+ return {
86
+ code: 'runtime.task.hitl_invalid_state',
87
+ data: { acknowledged: false },
88
+ };
89
+ }
90
+ // 恢复 HITL 执行:waiting_hitl → running
91
+ await taskManager.updateStatus(taskId, 'running');
92
+ return {
93
+ code: 'ok',
94
+ data: { acknowledged: true },
95
+ };
96
+ }
97
+ catch (error) {
98
+ return {
99
+ code: 'runtime.graph.execution_error',
100
+ data: { acknowledged: false },
101
+ };
102
+ }
103
+ }
104
+ return {
105
+ getTaskStatusHandler,
106
+ postHitlHandler,
107
+ };
108
+ }
@@ -0,0 +1,58 @@
1
+ /**
2
+ * CheckpointSerializer — Checkpoint 序列化/反序列化与工厂函数
3
+ *
4
+ * 提供:
5
+ * 1. createCheckpointData 工厂函数 — 自动生成 checkpointId + createdAt 时间戳
6
+ * 2. serializeCheckpoint / deserializeCheckpoint — 处理序列化边界情况
7
+ * (Date 对象 → ISO 字符串、undefined 清除、循环引用检测)
8
+ *
9
+ * @see design.md §1.3 Checkpoint 数据模型
10
+ * @see requirements.md Requirement 2 AC3
11
+ */
12
+ import type { CheckpointData, GraphState } from '../graph/contracts/executable-graph.js';
13
+ /**
14
+ * createCheckpointData 参数 — checkpointId 和 createdAt 可选(自动生成)
15
+ */
16
+ export interface CreateCheckpointParams {
17
+ /** Checkpoint ID(可选,默认自动生成 UUID) */
18
+ checkpointId?: string;
19
+ /** 线程 ID */
20
+ threadId: string;
21
+ /** 当前执行节点 ID */
22
+ currentNodeId: string;
23
+ /** 已执行的节点历史路径 */
24
+ historyPath: string[];
25
+ /** 完整 Graph State 快照 */
26
+ state: GraphState;
27
+ /** 创建人(可选,默认 'system') */
28
+ createdBy?: string;
29
+ /** 创建时间(可选,默认当前时间 ISO 字符串) */
30
+ createdAt?: string;
31
+ /** 最后更新人(可选,默认 'system') */
32
+ updatedBy?: string;
33
+ /** 最后更新时间(可选,默认当前时间 ISO 字符串) */
34
+ updatedAt?: string;
35
+ }
36
+ /**
37
+ * 创建 CheckpointData 实例
38
+ *
39
+ * 自动生成 checkpointId(UUID v4)和 createdAt(ISO 8601)。
40
+ * 确保所有必要字段的一致性。
41
+ */
42
+ export declare function createCheckpointData(params: CreateCheckpointParams): CheckpointData;
43
+ /**
44
+ * 序列化 CheckpointData 为 JSON 字符串
45
+ *
46
+ * 处理边界情况:
47
+ * - Date 对象 → ISO 字符串
48
+ * - undefined 值自动剔除(JSON.stringify 默认行为)
49
+ * - 循环引用检测(抛出明确错误而非默认 TypeError)
50
+ */
51
+ export declare function serializeCheckpoint(data: CheckpointData): string;
52
+ /**
53
+ * 反序列化 JSON 字符串为 CheckpointData
54
+ *
55
+ * 基本 JSON.parse,附加类型断言和基础字段校验。
56
+ * @throws Error 如果 JSON 无效或缺少必填字段
57
+ */
58
+ export declare function deserializeCheckpoint(json: string): CheckpointData;
@@ -0,0 +1,81 @@
1
+ /**
2
+ * CheckpointSerializer — Checkpoint 序列化/反序列化与工厂函数
3
+ *
4
+ * 提供:
5
+ * 1. createCheckpointData 工厂函数 — 自动生成 checkpointId + createdAt 时间戳
6
+ * 2. serializeCheckpoint / deserializeCheckpoint — 处理序列化边界情况
7
+ * (Date 对象 → ISO 字符串、undefined 清除、循环引用检测)
8
+ *
9
+ * @see design.md §1.3 Checkpoint 数据模型
10
+ * @see requirements.md Requirement 2 AC3
11
+ */
12
+ import { randomUUID } from 'node:crypto';
13
+ // ─────────────────────────────────────────────
14
+ // 工厂函数
15
+ // ─────────────────────────────────────────────
16
+ /**
17
+ * 创建 CheckpointData 实例
18
+ *
19
+ * 自动生成 checkpointId(UUID v4)和 createdAt(ISO 8601)。
20
+ * 确保所有必要字段的一致性。
21
+ */
22
+ export function createCheckpointData(params) {
23
+ const now = new Date().toISOString();
24
+ return {
25
+ checkpointId: params.checkpointId ?? randomUUID(),
26
+ threadId: params.threadId,
27
+ currentNodeId: params.currentNodeId,
28
+ historyPath: [...params.historyPath],
29
+ state: params.state,
30
+ createdBy: params.createdBy ?? 'system',
31
+ createdAt: params.createdAt ?? now,
32
+ updatedBy: params.updatedBy ?? 'system',
33
+ updatedAt: params.updatedAt ?? now,
34
+ isDeleted: false,
35
+ };
36
+ }
37
+ // ─────────────────────────────────────────────
38
+ // 序列化 / 反序列化
39
+ // ─────────────────────────────────────────────
40
+ /**
41
+ * 序列化 CheckpointData 为 JSON 字符串
42
+ *
43
+ * 处理边界情况:
44
+ * - Date 对象 → ISO 字符串
45
+ * - undefined 值自动剔除(JSON.stringify 默认行为)
46
+ * - 循环引用检测(抛出明确错误而非默认 TypeError)
47
+ */
48
+ export function serializeCheckpoint(data) {
49
+ const seen = new WeakSet();
50
+ return JSON.stringify(data, (_key, value) => {
51
+ // Date → ISO 字符串
52
+ if (value instanceof Date) {
53
+ return value.toISOString();
54
+ }
55
+ // 循环引用检测
56
+ if (typeof value === 'object' && value !== null) {
57
+ if (seen.has(value)) {
58
+ throw new Error(`[CheckpointSerializer] Circular reference detected during serialization`);
59
+ }
60
+ seen.add(value);
61
+ }
62
+ return value;
63
+ });
64
+ }
65
+ /**
66
+ * 反序列化 JSON 字符串为 CheckpointData
67
+ *
68
+ * 基本 JSON.parse,附加类型断言和基础字段校验。
69
+ * @throws Error 如果 JSON 无效或缺少必填字段
70
+ */
71
+ export function deserializeCheckpoint(json) {
72
+ const parsed = JSON.parse(json);
73
+ // 基础字段校验
74
+ const requiredFields = ['checkpointId', 'threadId', 'currentNodeId', 'historyPath', 'state', 'createdAt'];
75
+ for (const field of requiredFields) {
76
+ if (!(field in parsed) || parsed[field] === undefined || parsed[field] === null) {
77
+ throw new Error(`[CheckpointSerializer] Missing required field: ${field}`);
78
+ }
79
+ }
80
+ return parsed;
81
+ }
@@ -0,0 +1,42 @@
1
+ /**
2
+ * CompositeCheckpointSaver — 组合式 Checkpoint 持久化实现
3
+ *
4
+ * 写入策略:同步写 DB(主存储),异步写 Redis 缓存(可选)
5
+ * 读取策略:优先 Redis 缓存(如存在),失败或 null 时 fallback 到 DB
6
+ *
7
+ * @see design.md §1.3 checkpoints 数据模型
8
+ * @see checkpoint-saver.contract.ts ICheckpointSaver 接口定义
9
+ */
10
+ import type { ICheckpointSaver } from './contracts/checkpoint-saver.contract.js';
11
+ import type { CheckpointData } from '../graph/contracts/executable-graph.js';
12
+ /**
13
+ * CompositeCheckpointSaver — DB 主存储 + Redis 可选缓存
14
+ *
15
+ * - save: await DB → fire-and-forget Redis 缓存(错误静默记录)
16
+ * - load / loadByCheckpointId / list: try Redis 缓存 → fallback DB
17
+ */
18
+ export declare class CompositeCheckpointSaver implements ICheckpointSaver {
19
+ private readonly db;
20
+ private readonly cache?;
21
+ constructor(db: ICheckpointSaver, cache?: ICheckpointSaver | undefined);
22
+ /**
23
+ * 写入 Checkpoint:同步写 DB,异步写 Redis 缓存(不 await,错误静默)
24
+ */
25
+ save(threadId: string, data: CheckpointData): Promise<void>;
26
+ /**
27
+ * 加载最新 Checkpoint:优先 Redis 缓存,失败或 null 时 fallback DB
28
+ */
29
+ load(threadId: string): Promise<CheckpointData | null>;
30
+ /**
31
+ * 按 checkpointId 加载:优先 Redis 缓存,失败或 null 时 fallback DB
32
+ */
33
+ loadByCheckpointId(checkpointId: string): Promise<CheckpointData | null>;
34
+ /**
35
+ * 列出 thread 所有 Checkpoint:优先 Redis 缓存,失败时 fallback DB
36
+ */
37
+ list(threadId: string): Promise<CheckpointData[]>;
38
+ /**
39
+ * Fork: 从指定 Checkpoint 创建新的执行线程
40
+ */
41
+ fork(sourceCheckpointId: string, newThreadId: string, overrides?: Record<string, unknown>): Promise<import('../graph/contracts/executable-graph.js').CheckpointData>;
42
+ }
@@ -0,0 +1,118 @@
1
+ /**
2
+ * CompositeCheckpointSaver — 组合式 Checkpoint 持久化实现
3
+ *
4
+ * 写入策略:同步写 DB(主存储),异步写 Redis 缓存(可选)
5
+ * 读取策略:优先 Redis 缓存(如存在),失败或 null 时 fallback 到 DB
6
+ *
7
+ * @see design.md §1.3 checkpoints 数据模型
8
+ * @see checkpoint-saver.contract.ts ICheckpointSaver 接口定义
9
+ */
10
+ /**
11
+ * CompositeCheckpointSaver — DB 主存储 + Redis 可选缓存
12
+ *
13
+ * - save: await DB → fire-and-forget Redis 缓存(错误静默记录)
14
+ * - load / loadByCheckpointId / list: try Redis 缓存 → fallback DB
15
+ */
16
+ export class CompositeCheckpointSaver {
17
+ db;
18
+ cache;
19
+ constructor(db, cache) {
20
+ this.db = db;
21
+ this.cache = cache;
22
+ }
23
+ /**
24
+ * 写入 Checkpoint:同步写 DB,异步写 Redis 缓存(不 await,错误静默)
25
+ */
26
+ async save(threadId, data) {
27
+ // 主存储:DB
28
+ await this.db.save(threadId, data);
29
+ // 可选缓存:Redis(fire-and-forget)
30
+ if (this.cache) {
31
+ this.cache.save(threadId, data).catch((err) => {
32
+ console.error('[CompositeCheckpointSaver] Cache save failed:', err);
33
+ });
34
+ }
35
+ }
36
+ /**
37
+ * 加载最新 Checkpoint:优先 Redis 缓存,失败或 null 时 fallback DB
38
+ */
39
+ async load(threadId) {
40
+ // 尝试从缓存加载
41
+ if (this.cache) {
42
+ try {
43
+ const result = await this.cache.load(threadId);
44
+ if (result !== null) {
45
+ return result;
46
+ }
47
+ }
48
+ catch (err) {
49
+ console.error('[CompositeCheckpointSaver] Cache load failed, falling back to DB:', err);
50
+ }
51
+ }
52
+ // Fallback: 从 DB 加载
53
+ return this.db.load(threadId);
54
+ }
55
+ /**
56
+ * 按 checkpointId 加载:优先 Redis 缓存,失败或 null 时 fallback DB
57
+ */
58
+ async loadByCheckpointId(checkpointId) {
59
+ // 尝试从缓存加载
60
+ if (this.cache) {
61
+ try {
62
+ const result = await this.cache.loadByCheckpointId(checkpointId);
63
+ if (result !== null) {
64
+ return result;
65
+ }
66
+ }
67
+ catch (err) {
68
+ console.error('[CompositeCheckpointSaver] Cache loadByCheckpointId failed, falling back to DB:', err);
69
+ }
70
+ }
71
+ // Fallback: 从 DB 加载
72
+ return this.db.loadByCheckpointId(checkpointId);
73
+ }
74
+ /**
75
+ * 列出 thread 所有 Checkpoint:优先 Redis 缓存,失败时 fallback DB
76
+ */
77
+ async list(threadId) {
78
+ // 尝试从缓存加载
79
+ if (this.cache) {
80
+ try {
81
+ const results = await this.cache.list(threadId);
82
+ if (results.length > 0) {
83
+ return results;
84
+ }
85
+ }
86
+ catch (err) {
87
+ console.error('[CompositeCheckpointSaver] Cache list failed, falling back to DB:', err);
88
+ }
89
+ }
90
+ // Fallback: 从 DB 加载
91
+ return this.db.list(threadId);
92
+ }
93
+ /**
94
+ * Fork: 从指定 Checkpoint 创建新的执行线程
95
+ */
96
+ async fork(sourceCheckpointId, newThreadId, overrides) {
97
+ const source = await this.loadByCheckpointId(sourceCheckpointId);
98
+ if (!source) {
99
+ throw new Error(`Source checkpoint not found: ${sourceCheckpointId}`);
100
+ }
101
+ const now = new Date().toISOString();
102
+ const { randomUUID } = await import('node:crypto');
103
+ const newData = {
104
+ checkpointId: randomUUID(),
105
+ threadId: newThreadId,
106
+ currentNodeId: source.currentNodeId,
107
+ historyPath: source.historyPath,
108
+ state: overrides ? { ...source.state, ...overrides } : source.state,
109
+ createdBy: 'fork',
110
+ createdAt: now,
111
+ updatedBy: 'fork',
112
+ updatedAt: now,
113
+ isDeleted: false,
114
+ };
115
+ await this.save(newThreadId, newData);
116
+ return newData;
117
+ }
118
+ }
@@ -0,0 +1,65 @@
1
+ /**
2
+ * ICheckpointSaver — Checkpoint 持久化服务接口
3
+ *
4
+ * 定义 Checkpoint 的存储/加载/列表操作。
5
+ * 实现架构:DB 为主存储,Redis 为可选缓存。
6
+ *
7
+ * 支持 Fork 功能:从指定 Checkpoint 恢复执行。
8
+ *
9
+ * @see design.md §1.3 checkpoints 数据模型
10
+ * @see requirements.md Requirement 2 AC1-AC4
11
+ */
12
+ import type { CheckpointData } from '../../graph/contracts/executable-graph.js';
13
+ /**
14
+ * ICheckpointSaver — Checkpoint 持久化接口
15
+ *
16
+ * 由 PostgreSQL/MySQL/Redis/Composite 实现,提供 Graph 状态快照的 CRUD 能力。
17
+ * - save: 持久化 Checkpoint(DB 主写 + Redis 可选缓存)
18
+ * - load: 加载指定 thread 最新的 Checkpoint(用于断点恢复)
19
+ * - loadByCheckpointId: 按 checkpointId 加载特定快照(供 05-Trace/Replay 模块使用)
20
+ * - list: 列出指定 thread 的所有 Checkpoint 历史
21
+ * - fork: 从指定 Checkpoint 创建新的执行线程
22
+ */
23
+ export interface ICheckpointSaver {
24
+ /**
25
+ * 持久化一个 Checkpoint
26
+ *
27
+ * @param threadId - 线程 ID(一个 Task 对应一个 thread)
28
+ * @param data - 完整的 Checkpoint 数据(含 state 快照)
29
+ */
30
+ save(threadId: string, data: CheckpointData): Promise<void>;
31
+ /**
32
+ * 加载指定 thread 的最新 Checkpoint
33
+ *
34
+ * @param threadId - 线程 ID
35
+ * @returns 最新的 CheckpointData,不存在时返回 null
36
+ */
37
+ load(threadId: string): Promise<CheckpointData | null>;
38
+ /**
39
+ * 按 checkpointId 加载特定 Checkpoint
40
+ *
41
+ * 供 05-Trace/Replay 模块调用,实现 Replay/Fork 功能。
42
+ *
43
+ * @param checkpointId - Checkpoint 唯一 ID
44
+ * @returns 对应的 CheckpointData,不存在时返回 null
45
+ */
46
+ loadByCheckpointId(checkpointId: string): Promise<CheckpointData | null>;
47
+ /**
48
+ * 列出指定 thread 的所有 Checkpoint
49
+ *
50
+ * @param threadId - 线程 ID
51
+ * @returns 按时间排序的 CheckpointData 数组
52
+ */
53
+ list(threadId: string): Promise<CheckpointData[]>;
54
+ /**
55
+ * Fork:从指定 Checkpoint 创建新的执行线程
56
+ *
57
+ * 用于用户调试场景,从某个 Checkpoint 恢复执行,支持修改参数后重新执行。
58
+ *
59
+ * @param sourceCheckpointId - 源 Checkpoint ID
60
+ * @param newThreadId - 新线程 ID
61
+ * @param overrides - 覆盖的参数(可选)
62
+ * @returns 新的 CheckpointData
63
+ */
64
+ fork(sourceCheckpointId: string, newThreadId: string, overrides?: Record<string, unknown>): Promise<CheckpointData>;
65
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * ICheckpointSaver — Checkpoint 持久化服务接口
3
+ *
4
+ * 定义 Checkpoint 的存储/加载/列表操作。
5
+ * 实现架构:DB 为主存储,Redis 为可选缓存。
6
+ *
7
+ * 支持 Fork 功能:从指定 Checkpoint 恢复执行。
8
+ *
9
+ * @see design.md §1.3 checkpoints 数据模型
10
+ * @see requirements.md Requirement 2 AC1-AC4
11
+ */
12
+ export {};
@@ -0,0 +1 @@
1
+ export type { ICheckpointSaver } from './checkpoint-saver.contract.js';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,19 @@
1
+ /**
2
+ * FileCheckpointSaver — 本地 JSON 文件存储
3
+ * 适用场景:本地开发、单机部署
4
+ */
5
+ import type { ICheckpointSaver } from './contracts/checkpoint-saver.contract.js';
6
+ import type { CheckpointData } from '../graph/contracts/executable-graph.js';
7
+ export declare class FileCheckpointSaver implements ICheckpointSaver {
8
+ private readonly baseDir;
9
+ constructor(baseDir: string);
10
+ save(threadId: string, data: CheckpointData): Promise<void>;
11
+ load(threadId: string): Promise<CheckpointData | null>;
12
+ loadByCheckpointId(checkpointId: string, threadId?: string): Promise<CheckpointData | null>;
13
+ list(threadId: string): Promise<CheckpointData[]>;
14
+ private readCheckpoint;
15
+ /**
16
+ * Fork: 从指定 Checkpoint 创建新的执行线程
17
+ */
18
+ fork(sourceCheckpointId: string, newThreadId: string, overrides?: Record<string, unknown>): Promise<import('../graph/contracts/executable-graph.js').CheckpointData>;
19
+ }
@@ -0,0 +1,98 @@
1
+ /**
2
+ * FileCheckpointSaver — 本地 JSON 文件存储
3
+ * 适用场景:本地开发、单机部署
4
+ */
5
+ import { readdir, readFile, writeFile, mkdir } from 'node:fs/promises';
6
+ import { join } from 'node:path';
7
+ export class FileCheckpointSaver {
8
+ baseDir;
9
+ constructor(baseDir) {
10
+ this.baseDir = baseDir;
11
+ }
12
+ async save(threadId, data) {
13
+ const dir = join(this.baseDir, threadId);
14
+ await mkdir(dir, { recursive: true });
15
+ await writeFile(join(dir, `${data.checkpointId}.json`), JSON.stringify(data));
16
+ // 更新 latest 指针
17
+ await writeFile(join(dir, 'latest.json'), JSON.stringify({ checkpointId: data.checkpointId }));
18
+ }
19
+ async load(threadId) {
20
+ try {
21
+ const latestRaw = await readFile(join(this.baseDir, threadId, 'latest.json'), 'utf-8');
22
+ const { checkpointId } = JSON.parse(latestRaw);
23
+ return this.loadByCheckpointId(checkpointId, threadId);
24
+ }
25
+ catch {
26
+ return null;
27
+ }
28
+ }
29
+ async loadByCheckpointId(checkpointId, threadId) {
30
+ // If threadId provided, look directly; otherwise scan all thread dirs
31
+ if (threadId) {
32
+ return this.readCheckpoint(join(this.baseDir, threadId, `${checkpointId}.json`));
33
+ }
34
+ // ponytail: brute scan — upgrade to index file if perf matters
35
+ try {
36
+ const threads = await readdir(this.baseDir);
37
+ for (const t of threads) {
38
+ const result = await this.readCheckpoint(join(this.baseDir, t, `${checkpointId}.json`));
39
+ if (result)
40
+ return result;
41
+ }
42
+ }
43
+ catch { /* dir doesn't exist */ }
44
+ return null;
45
+ }
46
+ async list(threadId) {
47
+ const dir = join(this.baseDir, threadId);
48
+ try {
49
+ const files = await readdir(dir);
50
+ const results = [];
51
+ for (const f of files) {
52
+ if (f === 'latest.json' || !f.endsWith('.json'))
53
+ continue;
54
+ const data = await this.readCheckpoint(join(dir, f));
55
+ if (data)
56
+ results.push(data);
57
+ }
58
+ return results.sort((a, b) => a.createdAt.localeCompare(b.createdAt));
59
+ }
60
+ catch {
61
+ return [];
62
+ }
63
+ }
64
+ async readCheckpoint(filePath) {
65
+ try {
66
+ const raw = await readFile(filePath, 'utf-8');
67
+ return JSON.parse(raw);
68
+ }
69
+ catch {
70
+ return null;
71
+ }
72
+ }
73
+ /**
74
+ * Fork: 从指定 Checkpoint 创建新的执行线程
75
+ */
76
+ async fork(sourceCheckpointId, newThreadId, overrides) {
77
+ const source = await this.loadByCheckpointId(sourceCheckpointId);
78
+ if (!source) {
79
+ throw new Error(`Source checkpoint not found: ${sourceCheckpointId}`);
80
+ }
81
+ const now = new Date().toISOString();
82
+ const { randomUUID } = await import('node:crypto');
83
+ const newData = {
84
+ checkpointId: randomUUID(),
85
+ threadId: newThreadId,
86
+ currentNodeId: source.currentNodeId,
87
+ historyPath: source.historyPath,
88
+ state: overrides ? { ...source.state, ...overrides } : source.state,
89
+ createdBy: 'fork',
90
+ createdAt: now,
91
+ updatedBy: 'fork',
92
+ updatedAt: now,
93
+ isDeleted: false,
94
+ };
95
+ await this.save(newThreadId, newData);
96
+ return newData;
97
+ }
98
+ }