@octopi-agent/engine 0.70.7 → 0.86.38

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 (362) hide show
  1. package/LICENSE +201 -201
  2. package/NOTICE +7 -7
  3. package/README.md +64 -26
  4. package/dist/config-schema/agent.d.ts +89 -1
  5. package/dist/config-schema/agent.js +69 -0
  6. package/dist/config-schema/context.d.ts +23 -4
  7. package/dist/config-schema/context.js +28 -1
  8. package/dist/config-schema/engine.d.ts +201 -9
  9. package/dist/config-schema/engine.js +31 -2
  10. package/dist/config-schema/governance.d.ts +95 -0
  11. package/dist/config-schema/governance.js +91 -0
  12. package/dist/config-schema/models.d.ts +1 -1
  13. package/dist/config-schema/observability.d.ts +6 -0
  14. package/dist/config-schema/observability.js +16 -0
  15. package/dist/config-schema/run.d.ts +10 -0
  16. package/dist/config-schema/run.js +18 -0
  17. package/dist/config-schema/shared.d.ts +10 -0
  18. package/dist/config-schema/shared.js +10 -0
  19. package/dist/config-schema/substrate.d.ts +1 -1
  20. package/dist/config-schema/subsystems.d.ts +1 -1
  21. package/dist/config-schema/subsystems.js +2 -1
  22. package/dist/config.d.ts +178 -7
  23. package/dist/config.js +113 -3
  24. package/dist/harness/activation/compiler.js +3 -0
  25. package/dist/harness/activation/runtime.d.ts +7 -0
  26. package/dist/harness/activation/runtime.js +60 -2
  27. package/dist/harness/activation/sources/agent-signal.d.ts +11 -0
  28. package/dist/harness/activation/sources/agent-signal.js +33 -0
  29. package/dist/harness/activation/types.d.ts +6 -1
  30. package/dist/harness/agent/builder.d.ts +47 -3
  31. package/dist/harness/agent/builder.js +180 -54
  32. package/dist/harness/agent/config-bridge.d.ts +33 -25
  33. package/dist/harness/agent/config-bridge.js +81 -291
  34. package/dist/harness/agent/index.d.ts +3 -1
  35. package/dist/harness/agent/index.js +2 -1
  36. package/dist/harness/agent/tool-purpose.d.ts +38 -0
  37. package/dist/harness/agent/tool-purpose.js +118 -0
  38. package/dist/harness/agent/wire-agent-builder.d.ts +133 -0
  39. package/dist/harness/agent/wire-agent-builder.js +363 -0
  40. package/dist/harness/collaboration/autonomous-subsystem/runtime.d.ts +4 -1
  41. package/dist/harness/collaboration/autonomous-subsystem/runtime.js +14 -8
  42. package/dist/harness/collaboration/autonomous-subsystem/sense/metrics.d.ts +12 -0
  43. package/dist/harness/collaboration/autonomous-subsystem/sense/metrics.js +19 -0
  44. package/dist/harness/collaboration/autonomous-subsystem/sense/session-lifecycle-bridge.d.ts +6 -0
  45. package/dist/harness/collaboration/autonomous-subsystem/sense/session-lifecycle-bridge.js +24 -7
  46. package/dist/harness/collaboration/autonomous-subsystem/think/executor.d.ts +5 -2
  47. package/dist/harness/collaboration/autonomous-subsystem/think/executor.js +11 -3
  48. package/dist/harness/collaboration/autonomous-subsystem/think/index.d.ts +1 -1
  49. package/dist/harness/collaboration/autonomous-subsystem/think/index.js +1 -1
  50. package/dist/harness/collaboration/autonomous-subsystem/think/llm-port.d.ts +7 -4
  51. package/dist/harness/collaboration/autonomous-subsystem/think/llm-port.js +8 -9
  52. package/dist/harness/collaboration/autonomous-subsystem/think/model-resolver.d.ts +36 -10
  53. package/dist/harness/collaboration/autonomous-subsystem/think/model-resolver.js +60 -7
  54. package/dist/harness/collaboration/delegation/child-run.d.ts +144 -0
  55. package/dist/harness/collaboration/delegation/child-run.js +241 -0
  56. package/dist/harness/collaboration/delegation/index.d.ts +26 -0
  57. package/dist/harness/collaboration/delegation/index.js +25 -0
  58. package/dist/harness/collaboration/delegation/notifier.d.ts +46 -0
  59. package/dist/harness/collaboration/delegation/notifier.js +84 -0
  60. package/dist/harness/collaboration/delegation/registry-types.d.ts +200 -0
  61. package/dist/harness/collaboration/delegation/registry-types.js +61 -0
  62. package/dist/harness/collaboration/delegation/registry.d.ts +110 -0
  63. package/dist/harness/collaboration/delegation/registry.js +220 -0
  64. package/dist/harness/collaboration/delegation/service.d.ts +249 -0
  65. package/dist/harness/collaboration/delegation/service.js +499 -0
  66. package/dist/harness/collaboration/delegation/store.d.ts +155 -0
  67. package/dist/harness/collaboration/delegation/store.js +271 -0
  68. package/dist/harness/collaboration/delegation/transport.d.ts +73 -0
  69. package/dist/harness/collaboration/delegation/transport.js +61 -0
  70. package/dist/harness/collaboration/delegation/types.d.ts +231 -0
  71. package/dist/harness/collaboration/delegation/types.js +70 -0
  72. package/dist/harness/collaboration/delegation/wiring.d.ts +111 -0
  73. package/dist/harness/collaboration/delegation/wiring.js +145 -0
  74. package/dist/harness/collaboration/orchestration/index.d.ts +11 -13
  75. package/dist/harness/collaboration/orchestration/index.js +11 -11
  76. package/dist/harness/context/assembler.d.ts +2 -2
  77. package/dist/harness/context/assembler.js +12 -7
  78. package/dist/harness/context/capabilities/compact/engine.js +80 -38
  79. package/dist/harness/context/capabilities/compact/types.d.ts +12 -1
  80. package/dist/harness/context/capabilities/summary/registry.js +10 -0
  81. package/dist/harness/context/constitution/default-agents.md +230 -228
  82. package/dist/harness/context/default-context-engine.d.ts +101 -23
  83. package/dist/harness/context/default-context-engine.js +483 -172
  84. package/dist/harness/context/hybrid-compressor.d.ts +3 -3
  85. package/dist/harness/context/hybrid-compressor.js +18 -23
  86. package/dist/harness/context/index.d.ts +5 -1
  87. package/dist/harness/context/index.js +2 -0
  88. package/dist/harness/context/layer-snapshot.d.ts +4 -0
  89. package/dist/harness/context/layer-snapshot.js +30 -18
  90. package/dist/harness/context/layer-types.d.ts +49 -1
  91. package/dist/harness/context/layer-types.js +72 -4
  92. package/dist/harness/context/layers.d.ts +5 -2
  93. package/dist/harness/context/layers.js +11 -5
  94. package/dist/harness/context/llm-summarizer.d.ts +15 -1
  95. package/dist/harness/context/llm-summarizer.js +107 -56
  96. package/dist/harness/context/message-selector.js +6 -2
  97. package/dist/harness/context/root-instructions.d.ts +72 -0
  98. package/dist/harness/context/root-instructions.js +227 -0
  99. package/dist/harness/context/runtime-datetime.d.ts +34 -7
  100. package/dist/harness/context/runtime-datetime.js +66 -10
  101. package/dist/harness/context/smart-router.d.ts +1 -1
  102. package/dist/harness/context/smart-router.js +1 -1
  103. package/dist/harness/context/system-prompt-assembler.d.ts +30 -0
  104. package/dist/harness/context/system-prompt-assembler.js +67 -6
  105. package/dist/harness/context/token-constants.d.ts +2 -2
  106. package/dist/harness/context/token-constants.js +2 -2
  107. package/dist/harness/context/token-estimate-fns.d.ts +1 -3
  108. package/dist/harness/context/token-estimate-fns.js +2 -4
  109. package/dist/harness/context/token-estimator.d.ts +1 -1
  110. package/dist/harness/context/token-estimator.js +14 -6
  111. package/dist/harness/context/tool-result-aging.d.ts +140 -0
  112. package/dist/harness/context/tool-result-aging.js +331 -0
  113. package/dist/harness/context/tool-result-body.d.ts +10 -0
  114. package/dist/harness/context/tool-result-body.js +27 -0
  115. package/dist/harness/context/turn-envelope.d.ts +123 -0
  116. package/dist/harness/context/turn-envelope.js +188 -0
  117. package/dist/harness/context/types.d.ts +35 -47
  118. package/dist/harness/extension/execution-environment/effect-policy.d.ts +248 -0
  119. package/dist/harness/extension/execution-environment/effect-policy.js +334 -0
  120. package/dist/harness/extension/execution-environment/index.d.ts +18 -2
  121. package/dist/harness/extension/execution-environment/index.js +11 -2
  122. package/dist/harness/extension/execution-environment/memory-undo.d.ts +101 -0
  123. package/dist/harness/extension/execution-environment/memory-undo.js +192 -0
  124. package/dist/harness/extension/execution-environment/process-isolation.d.ts +84 -0
  125. package/dist/harness/extension/execution-environment/process-isolation.js +315 -0
  126. package/dist/harness/extension/execution-environment/resource-limits.d.ts +36 -0
  127. package/dist/harness/extension/execution-environment/resource-limits.js +84 -0
  128. package/dist/harness/extension/execution-environment/sandbox.d.ts +125 -4
  129. package/dist/harness/extension/execution-environment/sandbox.js +493 -51
  130. package/dist/harness/extension/execution-environment/shell-journal.d.ts +100 -0
  131. package/dist/harness/extension/execution-environment/shell-journal.js +299 -0
  132. package/dist/harness/extension/execution-environment/tool-capabilities.d.ts +45 -0
  133. package/dist/harness/extension/execution-environment/tool-capabilities.js +126 -0
  134. package/dist/harness/extension/execution-environment/types.d.ts +67 -39
  135. package/dist/harness/extension/execution-environment/types.js +2 -2
  136. package/dist/harness/extension/execution-environment/undo-log.d.ts +203 -0
  137. package/dist/harness/extension/execution-environment/undo-log.js +627 -0
  138. package/dist/harness/extension/execution-environment/undo-merge.d.ts +40 -0
  139. package/dist/harness/extension/execution-environment/undo-merge.js +167 -0
  140. package/dist/harness/extension/plugin-ecosystem/client-tools/index.d.ts +1 -1
  141. package/dist/harness/extension/plugin-ecosystem/client-tools/types.d.ts +9 -0
  142. package/dist/harness/extension/plugin-ecosystem/mcp/bridge.js +2 -0
  143. package/dist/harness/extension/plugin-ecosystem/plugins/api.d.ts +1 -6
  144. package/dist/harness/extension/plugin-ecosystem/plugins/api.js +3 -8
  145. package/dist/harness/extension/plugin-ecosystem/plugins/capability.d.ts +0 -3
  146. package/dist/harness/extension/plugin-ecosystem/plugins/capability.js +0 -3
  147. package/dist/harness/extension/plugin-ecosystem/plugins/entry.d.ts +2 -10
  148. package/dist/harness/extension/plugin-ecosystem/plugins/entry.js +2 -9
  149. package/dist/harness/extension/plugin-ecosystem/plugins/index.d.ts +1 -3
  150. package/dist/harness/extension/plugin-ecosystem/plugins/index.js +1 -3
  151. package/dist/harness/extension/plugin-ecosystem/plugins/loader.d.ts +2 -4
  152. package/dist/harness/extension/plugin-ecosystem/plugins/loader.js +4 -21
  153. package/dist/harness/extension/plugin-ecosystem/plugins/manager.d.ts +3 -9
  154. package/dist/harness/extension/plugin-ecosystem/plugins/manager.js +4 -8
  155. package/dist/harness/extension/plugin-ecosystem/plugins/manifest.d.ts +1 -4
  156. package/dist/harness/extension/plugin-ecosystem/plugins/manifest.js +1 -3
  157. package/dist/harness/extension/plugin-ecosystem/skills/manager.d.ts +1 -1
  158. package/dist/harness/extension/plugin-ecosystem/skills/manager.js +1 -1
  159. package/dist/harness/extension/plugin-ecosystem/tools/allowlisted-run.d.ts +45 -0
  160. package/dist/harness/extension/plugin-ecosystem/tools/allowlisted-run.js +136 -0
  161. package/dist/harness/extension/plugin-ecosystem/tools/ask-user.js +1 -0
  162. package/dist/harness/extension/plugin-ecosystem/tools/builtin.d.ts +18 -3
  163. package/dist/harness/extension/plugin-ecosystem/tools/builtin.js +277 -81
  164. package/dist/harness/extension/plugin-ecosystem/tools/delegation.d.ts +31 -0
  165. package/dist/harness/extension/plugin-ecosystem/tools/delegation.js +291 -0
  166. package/dist/harness/extension/plugin-ecosystem/tools/document-tools.js +10 -2
  167. package/dist/harness/extension/plugin-ecosystem/tools/env-info.js +1 -0
  168. package/dist/harness/extension/plugin-ecosystem/tools/eol.d.ts +35 -0
  169. package/dist/harness/extension/plugin-ecosystem/tools/eol.js +43 -0
  170. package/dist/harness/extension/plugin-ecosystem/tools/file-edit.js +40 -9
  171. package/dist/harness/extension/plugin-ecosystem/tools/file-ops.d.ts +33 -0
  172. package/dist/harness/extension/plugin-ecosystem/tools/file-ops.js +376 -0
  173. package/dist/harness/extension/plugin-ecosystem/tools/file-search.d.ts +12 -2
  174. package/dist/harness/extension/plugin-ecosystem/tools/file-search.js +239 -61
  175. package/dist/harness/extension/plugin-ecosystem/tools/git-tools.d.ts +27 -0
  176. package/dist/harness/extension/plugin-ecosystem/tools/git-tools.js +554 -0
  177. package/dist/harness/extension/plugin-ecosystem/tools/http.d.ts +10 -6
  178. package/dist/harness/extension/plugin-ecosystem/tools/http.js +41 -47
  179. package/dist/harness/extension/plugin-ecosystem/tools/index.d.ts +2 -0
  180. package/dist/harness/extension/plugin-ecosystem/tools/index.js +2 -0
  181. package/dist/harness/extension/plugin-ecosystem/tools/knowledge.js +4 -0
  182. package/dist/harness/extension/plugin-ecosystem/tools/memory.js +25 -1
  183. package/dist/harness/extension/plugin-ecosystem/tools/package-tools.d.ts +13 -0
  184. package/dist/harness/extension/plugin-ecosystem/tools/package-tools.js +391 -0
  185. package/dist/harness/extension/plugin-ecosystem/tools/platform.d.ts +51 -2
  186. package/dist/harness/extension/plugin-ecosystem/tools/platform.js +151 -12
  187. package/dist/harness/extension/plugin-ecosystem/tools/session-history.js +2 -0
  188. package/dist/harness/extension/plugin-ecosystem/tools/tool-bus.d.ts +10 -1
  189. package/dist/harness/extension/plugin-ecosystem/tools/tool-bus.js +35 -19
  190. package/dist/harness/extension/plugin-ecosystem/tools/tool-set.d.ts +8 -0
  191. package/dist/harness/extension/plugin-ecosystem/tools/tool-set.js +5 -0
  192. package/dist/harness/extension/plugin-ecosystem/tools/web-search.js +1 -0
  193. package/dist/harness/governance/credentials/index.d.ts +1 -1
  194. package/dist/harness/governance/credentials/store.d.ts +16 -4
  195. package/dist/harness/governance/credentials/store.js +33 -6
  196. package/dist/harness/governance/credentials/types.d.ts +11 -0
  197. package/dist/harness/governance/human-in-the-loop/decision-cache.d.ts +105 -0
  198. package/dist/harness/governance/human-in-the-loop/decision-cache.js +184 -0
  199. package/dist/harness/governance/human-in-the-loop/index.d.ts +5 -5
  200. package/dist/harness/governance/human-in-the-loop/index.js +3 -3
  201. package/dist/harness/governance/human-in-the-loop/types.d.ts +7 -62
  202. package/dist/harness/governance/human-in-the-loop/types.js +6 -2
  203. package/dist/harness/governance/security/capability-enforcer.d.ts +9 -1
  204. package/dist/harness/governance/security/capability-enforcer.js +31 -8
  205. package/dist/harness/governance/security/degradation.js +5 -7
  206. package/dist/harness/governance/security/risk-evaluator.d.ts +1 -1
  207. package/dist/harness/governance/security/risk-evaluator.js +4 -82
  208. package/dist/harness/governance/security/temp-path.d.ts +41 -0
  209. package/dist/harness/governance/security/temp-path.js +117 -0
  210. package/dist/harness/governance/session-acl/index.d.ts +1 -0
  211. package/dist/harness/governance/session-acl/index.js +1 -0
  212. package/dist/harness/governance/session-acl/rights.d.ts +12 -0
  213. package/dist/harness/governance/session-acl/rights.js +89 -7
  214. package/dist/harness/governance/session-acl/seed-roles.js +9 -1
  215. package/dist/harness/governance/session-acl/service.js +21 -29
  216. package/dist/harness/governance/session-acl/tool-rights.d.ts +81 -0
  217. package/dist/harness/governance/session-acl/tool-rights.js +238 -0
  218. package/dist/harness/governance/session-acl/types.d.ts +22 -0
  219. package/dist/harness/index.d.ts +14 -12
  220. package/dist/harness/index.js +9 -6
  221. package/dist/harness/knowledge/file-index-store.js +11 -11
  222. package/dist/harness/knowledge/grounding.d.ts +2 -1
  223. package/dist/harness/knowledge/grounding.js +6 -3
  224. package/dist/harness/knowledge/index.d.ts +2 -2
  225. package/dist/harness/knowledge/index.js +1 -1
  226. package/dist/harness/knowledge/ingest.js +4 -1
  227. package/dist/harness/knowledge/job-control-state.js +4 -4
  228. package/dist/harness/knowledge/job-control.js +11 -11
  229. package/dist/harness/knowledge/membership-store.js +11 -11
  230. package/dist/harness/knowledge/network-guard.d.ts +61 -4
  231. package/dist/harness/knowledge/network-guard.js +390 -113
  232. package/dist/harness/knowledge/query-service.js +3 -3
  233. package/dist/harness/knowledge/writer-service.d.ts +2 -0
  234. package/dist/harness/knowledge/writer-service.js +14 -13
  235. package/dist/harness/memory/backfill-trigger.d.ts +2 -2
  236. package/dist/harness/memory/backfill-trigger.js +4 -4
  237. package/dist/harness/memory/index.d.ts +1 -0
  238. package/dist/harness/memory/index.js +1 -0
  239. package/dist/harness/memory/sqlite/agent-db.js +2 -0
  240. package/dist/harness/memory/sqlite/memory-store.d.ts +1 -0
  241. package/dist/harness/memory/sqlite/memory-store.js +14 -4
  242. package/dist/harness/memory/sqlite/wisdom-store.js +9 -9
  243. package/dist/harness/memory/store.d.ts +1 -0
  244. package/dist/harness/memory/store.js +3 -0
  245. package/dist/harness/memory/time-format.d.ts +28 -0
  246. package/dist/harness/memory/time-format.js +52 -0
  247. package/dist/harness/memory/types.d.ts +12 -0
  248. package/dist/harness/observability/observer/hub.js +23 -1
  249. package/dist/harness/observability/observer/index.d.ts +2 -2
  250. package/dist/harness/observability/observer/index.js +1 -1
  251. package/dist/harness/observability/observer/types.d.ts +57 -0
  252. package/dist/harness/observability/observer/types.js +118 -9
  253. package/dist/harness/run/agent/agent.d.ts +18 -0
  254. package/dist/harness/run/agent/agent.js +26 -0
  255. package/dist/harness/run/concurrency/tool-loop-detection-core.d.ts +1 -1
  256. package/dist/harness/run/concurrency/tool-loop-detection-core.js +1 -1
  257. package/dist/harness/run/reliability/harness-events.d.ts +4 -0
  258. package/dist/harness/run/reliability/run-agent.js +110 -18
  259. package/dist/harness/run/reliability/run-metrics-collector.d.ts +28 -2
  260. package/dist/harness/run/reliability/run-metrics-collector.js +92 -2
  261. package/dist/harness/run/run-guard/default-run-guard.d.ts +0 -5
  262. package/dist/harness/run/run-guard/default-run-guard.js +104 -44
  263. package/dist/harness/run/run-scope.d.ts +52 -0
  264. package/dist/harness/run/runner.d.ts +101 -16
  265. package/dist/harness/run/runner.js +556 -158
  266. package/dist/harness/session/attachments/llm-intent.js +17 -17
  267. package/dist/harness/session/history/port.js +1 -0
  268. package/dist/harness/session/in-memory-store.d.ts +1 -0
  269. package/dist/harness/session/in-memory-store.js +22 -1
  270. package/dist/harness/session/schedules/index.d.ts +10 -0
  271. package/dist/harness/session/schedules/index.js +10 -0
  272. package/dist/harness/session/schedules/render.d.ts +13 -0
  273. package/dist/harness/session/schedules/render.js +63 -0
  274. package/dist/harness/session/schedules/service.d.ts +179 -0
  275. package/dist/harness/session/schedules/service.js +695 -0
  276. package/dist/harness/session/schedules/store.d.ts +119 -0
  277. package/dist/harness/session/schedules/store.js +323 -0
  278. package/dist/harness/session/schedules/tools.d.ts +39 -0
  279. package/dist/harness/session/schedules/tools.js +442 -0
  280. package/dist/harness/session/schedules/types.d.ts +104 -0
  281. package/dist/harness/session/schedules/types.js +97 -0
  282. package/dist/harness/session/tasks/tools.js +22 -0
  283. package/dist/harness/session/types.d.ts +35 -0
  284. package/dist/harness/shared/events/agent-event-map.d.ts +13 -0
  285. package/dist/harness/shared/types/agent-definition.d.ts +23 -0
  286. package/dist/index.d.ts +23 -9
  287. package/dist/index.js +10 -2
  288. package/dist/integration/providers/anthropic.d.ts +10 -0
  289. package/dist/integration/providers/anthropic.js +44 -1
  290. package/dist/integration/providers/openai.d.ts +10 -0
  291. package/dist/integration/providers/openai.js +58 -2
  292. package/dist/integration/providers/wire-dump-diff.d.ts +191 -0
  293. package/dist/integration/providers/wire-dump-diff.js +351 -0
  294. package/dist/integration/providers/wire-dump.d.ts +178 -0
  295. package/dist/integration/providers/wire-dump.js +396 -0
  296. package/dist/integration/storage/jsonl.d.ts +11 -0
  297. package/dist/integration/storage/jsonl.js +148 -39
  298. package/dist/integration/storage/session-index.js +63 -8
  299. package/dist/subsystems/cognition-steward/conceptualize/SUBSYSTEM.md +43 -43
  300. package/dist/subsystems/cognition-steward/conceptualize/config.yaml +50 -50
  301. package/dist/subsystems/cognition-steward/consolidate/SUBSYSTEM.md +6 -6
  302. package/dist/subsystems/cognition-steward/consolidate/config.yaml +54 -54
  303. package/dist/subsystems/memory-steward/backfill/handler.js +9 -0
  304. package/dist/subsystems/wisdom-steward/evaluate/config.yaml +50 -50
  305. package/dist/subsystems/wisdom-steward/formation/SUBSYSTEM.md +42 -42
  306. package/dist/subsystems/wisdom-steward/formation/config.yaml +54 -54
  307. package/dist/subsystems/wisdom-steward/govern/config.yaml +55 -55
  308. package/package.json +115 -115
  309. package/dist/harness/collaboration/multi-agent/agent-registry-types.d.ts +0 -144
  310. package/dist/harness/collaboration/multi-agent/agent-registry-types.js +0 -25
  311. package/dist/harness/collaboration/multi-agent/index.d.ts +0 -17
  312. package/dist/harness/collaboration/multi-agent/index.js +0 -15
  313. package/dist/harness/collaboration/multi-agent/process.d.ts +0 -167
  314. package/dist/harness/collaboration/multi-agent/process.js +0 -256
  315. package/dist/harness/collaboration/multi-agent/registry.d.ts +0 -36
  316. package/dist/harness/collaboration/multi-agent/registry.js +0 -137
  317. package/dist/harness/collaboration/multi-agent/swarm.d.ts +0 -135
  318. package/dist/harness/collaboration/multi-agent/swarm.js +0 -317
  319. package/dist/harness/collaboration/multi-agent/types.d.ts +0 -66
  320. package/dist/harness/collaboration/multi-agent/types.js +0 -15
  321. package/dist/harness/collaboration/orchestration/async-task-store.d.ts +0 -107
  322. package/dist/harness/collaboration/orchestration/async-task-store.js +0 -12
  323. package/dist/harness/collaboration/orchestration/async-task.d.ts +0 -156
  324. package/dist/harness/collaboration/orchestration/async-task.js +0 -359
  325. package/dist/harness/collaboration/orchestration/planner/hybrid-planner.d.ts +0 -47
  326. package/dist/harness/collaboration/orchestration/planner/hybrid-planner.js +0 -61
  327. package/dist/harness/collaboration/orchestration/planner/index.d.ts +0 -9
  328. package/dist/harness/collaboration/orchestration/planner/index.js +0 -6
  329. package/dist/harness/collaboration/orchestration/planner/llm-planner.d.ts +0 -54
  330. package/dist/harness/collaboration/orchestration/planner/llm-planner.js +0 -167
  331. package/dist/harness/collaboration/orchestration/planner/rule-planner.d.ts +0 -85
  332. package/dist/harness/collaboration/orchestration/planner/rule-planner.js +0 -175
  333. package/dist/harness/collaboration/orchestration/quality/classifier.d.ts +0 -21
  334. package/dist/harness/collaboration/orchestration/quality/classifier.js +0 -235
  335. package/dist/harness/collaboration/orchestration/quality/gate.d.ts +0 -29
  336. package/dist/harness/collaboration/orchestration/quality/gate.js +0 -409
  337. package/dist/harness/collaboration/orchestration/quality/index.d.ts +0 -9
  338. package/dist/harness/collaboration/orchestration/quality/index.js +0 -8
  339. package/dist/harness/collaboration/orchestration/quality/types.d.ts +0 -159
  340. package/dist/harness/collaboration/orchestration/quality/types.js +0 -33
  341. package/dist/harness/collaboration/orchestration/scheduler/index.d.ts +0 -5
  342. package/dist/harness/collaboration/orchestration/scheduler/index.js +0 -4
  343. package/dist/harness/collaboration/orchestration/scheduler/task-scheduler.d.ts +0 -143
  344. package/dist/harness/collaboration/orchestration/scheduler/task-scheduler.js +0 -297
  345. package/dist/harness/collaboration/orchestration/strategy/classifier.d.ts +0 -12
  346. package/dist/harness/collaboration/orchestration/strategy/classifier.js +0 -81
  347. package/dist/harness/collaboration/orchestration/strategy/index.d.ts +0 -3
  348. package/dist/harness/collaboration/orchestration/strategy/index.js +0 -2
  349. package/dist/harness/collaboration/orchestration/strategy/router.d.ts +0 -28
  350. package/dist/harness/collaboration/orchestration/strategy/router.js +0 -105
  351. package/dist/harness/collaboration/orchestration/strategy/types.d.ts +0 -49
  352. package/dist/harness/collaboration/orchestration/strategy/types.js +0 -4
  353. package/dist/harness/collaboration/orchestration/workflow/engine.d.ts +0 -86
  354. package/dist/harness/collaboration/orchestration/workflow/engine.js +0 -298
  355. package/dist/harness/collaboration/orchestration/workflow/index.d.ts +0 -9
  356. package/dist/harness/collaboration/orchestration/workflow/index.js +0 -7
  357. package/dist/harness/collaboration/orchestration/workflow/types.d.ts +0 -143
  358. package/dist/harness/collaboration/orchestration/workflow/types.js +0 -7
  359. package/dist/harness/governance/human-in-the-loop/approval-manager.d.ts +0 -32
  360. package/dist/harness/governance/human-in-the-loop/approval-manager.js +0 -93
  361. /package/dist/harness/collaboration/{multi-agent → delegation}/message-channel-types.d.ts +0 -0
  362. /package/dist/harness/collaboration/{multi-agent → delegation}/message-channel-types.js +0 -0
@@ -1,107 +0,0 @@
1
- /**
2
- * AsyncTaskStore — 异步任务持久化协议
3
- *
4
- * @layer harness/collaboration/orchestration — AsyncTask 的状态持久化和检索。
5
- * 实现方:内存(开发)、文件、Redis、数据库等。
6
- *
7
- * 设计要点:
8
- * - 支持任务查询和过滤(dashboard/监控)
9
- * - 状态机:pending → running → completed | failed | cancelled
10
- * - 禁止依赖 Session.tasks
11
- */
12
- /** AsyncTask 状态 */
13
- export type AsyncTaskStatus = 'pending' | 'running' | 'completed' | 'failed' | 'cancelled';
14
- /** AsyncTask 优先级 */
15
- export type AsyncTaskPriority = 'low' | 'normal' | 'high' | 'critical';
16
- /** AsyncTask 记录 */
17
- export interface AsyncTaskRecord {
18
- /** 任务唯一 ID */
19
- id: string;
20
- /** 所属 Agent ID */
21
- agentId: string;
22
- /** 所属 Session ID(可选) */
23
- sessionId?: string;
24
- /** 任务类型 */
25
- type: string;
26
- /** 任务状态 */
27
- status: AsyncTaskStatus;
28
- /** 任务优先级 */
29
- priority: AsyncTaskPriority;
30
- /** 任务输入 */
31
- input: unknown;
32
- /** 任务输出(完成后有值) */
33
- output?: unknown;
34
- /** 错误信息(失败时有值) */
35
- error?: string;
36
- /** 创建时间 */
37
- createdAt: number;
38
- /** 开始执行时间 */
39
- startedAt?: number;
40
- /** 完成时间 */
41
- completedAt?: number;
42
- /** 重试次数 */
43
- retryCount: number;
44
- /** 最大重试次数 */
45
- maxRetries: number;
46
- /** 超时时间(毫秒) */
47
- timeoutMs?: number;
48
- /** 父任务 ID(子任务场景) */
49
- parentId?: string;
50
- /** 扩展元数据 */
51
- metadata?: Record<string, unknown>;
52
- }
53
- /** AsyncTask 查询过滤器 */
54
- export interface AsyncTaskFilter {
55
- /** 按 Agent ID 过滤 */
56
- agentId?: string;
57
- /** 按 Session ID 过滤 */
58
- sessionId?: string;
59
- /** 按状态过滤 */
60
- status?: AsyncTaskStatus | AsyncTaskStatus[];
61
- /** 按类型过滤 */
62
- type?: string;
63
- /** 按父任务 ID 过滤 */
64
- parentId?: string;
65
- /** 创建时间范围 */
66
- createdAfter?: number;
67
- createdBefore?: number;
68
- /** 返回数量限制 */
69
- limit?: number;
70
- /** 偏移量 */
71
- offset?: number;
72
- }
73
- /**
74
- * AsyncTaskStore 接口
75
- *
76
- * orchestration 域内 AsyncTask 的持久化契约(非 Core)。
77
- * 默认实现为内存;持久化实现可放在 integration/storage。
78
- */
79
- export interface AsyncTaskStore {
80
- /**
81
- * 创建任务记录
82
- * @param task - 完整的任务记录(包含 id)
83
- * @returns 创建的任务 ID
84
- */
85
- create(task: AsyncTaskRecord): Promise<string>;
86
- /**
87
- * 更新任务记录(部分更新)
88
- */
89
- update(taskId: string, patch: Partial<AsyncTaskRecord>): Promise<void>;
90
- /**
91
- * 获取任务记录
92
- */
93
- get(taskId: string): Promise<AsyncTaskRecord | null>;
94
- /**
95
- * 查询任务
96
- */
97
- query(filter: AsyncTaskFilter): Promise<AsyncTaskRecord[]>;
98
- /**
99
- * 删除任务记录
100
- */
101
- delete(taskId: string): Promise<void>;
102
- /**
103
- * 清理过期任务
104
- * @param olderThanMs - 清理此时间之前完成的任务
105
- */
106
- cleanup(olderThanMs: number): Promise<number>;
107
- }
@@ -1,12 +0,0 @@
1
- /**
2
- * AsyncTaskStore — 异步任务持久化协议
3
- *
4
- * @layer harness/collaboration/orchestration — AsyncTask 的状态持久化和检索。
5
- * 实现方:内存(开发)、文件、Redis、数据库等。
6
- *
7
- * 设计要点:
8
- * - 支持任务查询和过滤(dashboard/监控)
9
- * - 状态机:pending → running → completed | failed | cancelled
10
- * - 禁止依赖 Session.tasks
11
- */
12
- export {};
@@ -1,156 +0,0 @@
1
- /**
2
- * AsyncTask — 异步任务单元(Harness / orchestration)
3
- *
4
- * 调度与后台工作单元:超时、取消、重试、可选持久化。
5
- * **不是 Kernel**:Loop 与裸 Agent.run 不依赖;主消费方 TaskScheduler。
6
- *
7
- * 边界说明:
8
- * - `priority` 仅元数据;调度策略在 TaskScheduler
9
- * - 重试无退避(退避是策略)
10
- * - 持久化失败不阻塞执行,但会串行化
11
- */
12
- import type { EventBus } from '@octopi-agent/core/primitives/event-bus.js';
13
- import type { AsyncTaskStore, AsyncTaskRecord, AsyncTaskStatus, AsyncTaskPriority } from './async-task-store.js';
14
- /** AsyncTask 事件 */
15
- export declare const TaskEvents: {
16
- readonly CREATED: "task.created";
17
- readonly STARTED: "task.started";
18
- readonly COMPLETED: "task.completed";
19
- readonly FAILED: "task.failed";
20
- readonly CANCELLED: "task.cancelled";
21
- readonly TIMEOUT: "task.timeout";
22
- readonly RETRYING: "task.retrying";
23
- readonly CHILD_SPAWNED: "task.child.spawned";
24
- };
25
- /** AsyncTask 创建选项 */
26
- export interface TaskOptions {
27
- /** 任务类型(用于路由和日志) */
28
- type: string;
29
- /** 任务输入 */
30
- input?: unknown;
31
- /**
32
- * 优先级(仅元数据,Core 不调度)
33
- *
34
- * 持久化到 AsyncTaskStore,供上层调度器/过滤使用。
35
- */
36
- priority?: AsyncTaskPriority;
37
- /** 超时时间(毫秒) */
38
- timeoutMs?: number;
39
- /** 最大重试次数 */
40
- maxRetries?: number;
41
- /** 父任务 ID */
42
- parentId?: string;
43
- /** 所属 Agent ID */
44
- agentId?: string;
45
- /** 所属 Session ID */
46
- sessionId?: string;
47
- /** 扩展元数据 */
48
- metadata?: Record<string, unknown>;
49
- }
50
- /** 任务执行函数类型 */
51
- export type TaskExecutor<T = unknown> = (input: unknown, signal: AbortSignal) => Promise<T>;
52
- /**
53
- * AsyncTask — 异步任务
54
- *
55
- * 封装一个异步执行单元,提供生命周期管理。
56
- */
57
- export declare class AsyncTask<T = unknown> {
58
- readonly id: string;
59
- readonly type: string;
60
- readonly priority: AsyncTaskPriority;
61
- readonly parentId?: string;
62
- readonly agentId?: string;
63
- readonly sessionId?: string;
64
- readonly createdAt: number;
65
- private _status;
66
- private _output?;
67
- private _error?;
68
- private _startedAt?;
69
- private _completedAt?;
70
- private _retryCount;
71
- private readonly _maxRetries;
72
- private readonly _timeoutMs?;
73
- private readonly _metadata?;
74
- private readonly _input;
75
- private _abortController;
76
- private _resolvePromise;
77
- private _rejectPromise;
78
- private _promise;
79
- private _timeoutHandle?;
80
- private readonly _events?;
81
- private readonly _store?;
82
- private _settled;
83
- /** 串行化持久化,避免 create/update 乱序 */
84
- private _persistChain;
85
- constructor(options: TaskOptions, events?: EventBus, store?: AsyncTaskStore);
86
- /** 当前状态 */
87
- get status(): AsyncTaskStatus;
88
- /** 任务输出(完成后有值) */
89
- get output(): T | undefined;
90
- /** 错误信息(失败时有值) */
91
- get error(): string | undefined;
92
- /** 重试次数 */
93
- get retryCount(): number;
94
- /** 是否已完成(成功、失败或取消) */
95
- get isDone(): boolean;
96
- /** AbortSignal,用于取消传递 */
97
- get signal(): AbortSignal;
98
- /** 等待结果的 Promise */
99
- get promise(): Promise<T>;
100
- /**
101
- * 启动任务执行
102
- *
103
- * @param executor - 任务执行函数
104
- * @returns 任务结果
105
- *
106
- * 内部方法,由 TaskRunner 或直接调用方触发。
107
- * 重试为迭代实现,避免深递归;无退避(策略在外层)。
108
- */
109
- run(executor: TaskExecutor<T>): Promise<T>;
110
- /**
111
- * 取消任务
112
- *
113
- * @param reason - 取消原因
114
- */
115
- cancel(reason?: string): void;
116
- /**
117
- * 等待任务完成(带超时)
118
- *
119
- * @param timeoutMs - 超时时间(毫秒),不传则无限等待
120
- * @returns 任务结果
121
- * @throws TaskTimeoutError | TaskCancelledError | Error
122
- *
123
- * 调用方超时不会改变任务本身状态;任务超时用 TaskOptions.timeoutMs。
124
- */
125
- wait(timeoutMs?: number): Promise<T>;
126
- /**
127
- * 等待所有已排队的持久化完成(测试/优雅退出用)
128
- */
129
- flushPersist(): Promise<void>;
130
- private _settledError;
131
- private _complete;
132
- private _fail;
133
- private _handleTimeout;
134
- private _persistAndEmit;
135
- /** 转换为 AsyncTaskRecord(用于快照/调试/持久化) */
136
- toRecord(): AsyncTaskRecord;
137
- }
138
- /** 任务超时错误 */
139
- export declare class TaskTimeoutError extends Error {
140
- readonly taskId: string;
141
- readonly timeoutMs: number;
142
- constructor(taskId: string, timeoutMs: number);
143
- }
144
- /** 任务取消错误 */
145
- export declare class TaskCancelledError extends Error {
146
- readonly taskId: string;
147
- readonly reason?: string | undefined;
148
- constructor(taskId: string, reason?: string | undefined);
149
- }
150
- /**
151
- * 创建并立即启动一个 AsyncTask
152
- *
153
- * 便捷方法,适用于"发射后不管"的场景。
154
- * 错误通过 task.promise 和 EventBus 传播,不会被静默吞掉。
155
- */
156
- export declare function spawnTask<T = unknown>(options: TaskOptions, executor: TaskExecutor<T>, events?: EventBus, store?: AsyncTaskStore): AsyncTask<T>;
@@ -1,359 +0,0 @@
1
- /**
2
- * AsyncTask — 异步任务单元(Harness / orchestration)
3
- *
4
- * 调度与后台工作单元:超时、取消、重试、可选持久化。
5
- * **不是 Kernel**:Loop 与裸 Agent.run 不依赖;主消费方 TaskScheduler。
6
- *
7
- * 边界说明:
8
- * - `priority` 仅元数据;调度策略在 TaskScheduler
9
- * - 重试无退避(退避是策略)
10
- * - 持久化失败不阻塞执行,但会串行化
11
- */
12
- import { randomUUID } from 'node:crypto';
13
- // ── 任务状态机 ──
14
- /** AsyncTask 事件 */
15
- export const TaskEvents = {
16
- CREATED: 'task.created',
17
- STARTED: 'task.started',
18
- COMPLETED: 'task.completed',
19
- FAILED: 'task.failed',
20
- CANCELLED: 'task.cancelled',
21
- TIMEOUT: 'task.timeout',
22
- RETRYING: 'task.retrying',
23
- CHILD_SPAWNED: 'task.child.spawned',
24
- };
25
- // ── AsyncTask ──
26
- /**
27
- * AsyncTask — 异步任务
28
- *
29
- * 封装一个异步执行单元,提供生命周期管理。
30
- */
31
- export class AsyncTask {
32
- id;
33
- type;
34
- priority;
35
- parentId;
36
- agentId;
37
- sessionId;
38
- createdAt;
39
- _status = 'pending';
40
- _output;
41
- _error;
42
- _startedAt;
43
- _completedAt;
44
- _retryCount = 0;
45
- _maxRetries;
46
- _timeoutMs;
47
- _metadata;
48
- _input;
49
- _abortController;
50
- _resolvePromise;
51
- _rejectPromise;
52
- _promise;
53
- _timeoutHandle;
54
- // 外部依赖
55
- _events;
56
- _store;
57
- _settled = false;
58
- /** 串行化持久化,避免 create/update 乱序 */
59
- _persistChain = Promise.resolve();
60
- constructor(options, events, store) {
61
- this.id = randomUUID();
62
- this.type = options.type;
63
- this.priority = options.priority ?? 'normal';
64
- this.parentId = options.parentId;
65
- this.agentId = options.agentId;
66
- this.sessionId = options.sessionId;
67
- this.createdAt = Date.now();
68
- this._input = options.input;
69
- this._maxRetries = options.maxRetries ?? 0;
70
- this._timeoutMs = options.timeoutMs;
71
- this._metadata = options.metadata;
72
- this._abortController = new AbortController();
73
- this._events = events;
74
- this._store = store;
75
- this._promise = new Promise((resolve, reject) => {
76
- this._resolvePromise = resolve;
77
- this._rejectPromise = reject;
78
- });
79
- // 不静默吞掉 unhandled rejection。
80
- // 调用方应通过 task.promise.catch()、task.wait() 或 spawnTask() 处理错误。
81
- // 持久化创建事件(fire-and-forget,经 _persistChain 串行)
82
- this._persistAndEmit(TaskEvents.CREATED);
83
- }
84
- // ── 状态访问器 ──
85
- /** 当前状态 */
86
- get status() { return this._status; }
87
- /** 任务输出(完成后有值) */
88
- get output() { return this._output; }
89
- /** 错误信息(失败时有值) */
90
- get error() { return this._error; }
91
- /** 重试次数 */
92
- get retryCount() { return this._retryCount; }
93
- /** 是否已完成(成功、失败或取消) */
94
- get isDone() {
95
- return this._status === 'completed'
96
- || this._status === 'failed'
97
- || this._status === 'cancelled';
98
- }
99
- /** AbortSignal,用于取消传递 */
100
- get signal() { return this._abortController.signal; }
101
- /** 等待结果的 Promise */
102
- get promise() { return this._promise; }
103
- // ── 生命周期方法 ──
104
- /**
105
- * 启动任务执行
106
- *
107
- * @param executor - 任务执行函数
108
- * @returns 任务结果
109
- *
110
- * 内部方法,由 TaskRunner 或直接调用方触发。
111
- * 重试为迭代实现,避免深递归;无退避(策略在外层)。
112
- */
113
- async run(executor) {
114
- if (this._status !== 'pending') {
115
- throw new Error(`Task ${this.id} is not pending (status: ${this._status})`);
116
- }
117
- // 迭代重试:首次 + maxRetries
118
- while (true) {
119
- this._status = 'running';
120
- this._startedAt = Date.now();
121
- this._persistAndEmit(TaskEvents.STARTED);
122
- if (this._timeoutMs && this._timeoutMs > 0) {
123
- this._timeoutHandle = setTimeout(() => {
124
- if (this._status === 'running') {
125
- this._handleTimeout();
126
- }
127
- }, this._timeoutMs);
128
- }
129
- try {
130
- const result = await executor(this._input, this._abortController.signal);
131
- // 已经被 timeout/cancel 处理过了,抛出原错误让调用方感知
132
- if (this._settled) {
133
- throw this._settledError();
134
- }
135
- this._complete(result);
136
- return result;
137
- }
138
- catch (err) {
139
- // 已经被 timeout/cancel 处理过了,直接抛出原错误
140
- if (this._settled)
141
- throw err;
142
- const error = err instanceof Error ? err : new Error(String(err));
143
- // cancel() 会 abort signal,此时不重试
144
- if (this._abortController.signal.aborted) {
145
- this._fail(error.message);
146
- throw error;
147
- }
148
- // 重试
149
- if (this._retryCount < this._maxRetries) {
150
- this._retryCount++;
151
- this._abortController = new AbortController();
152
- this._status = 'pending';
153
- this._persistAndEmit(TaskEvents.RETRYING, {
154
- retryCount: this._retryCount,
155
- maxRetries: this._maxRetries,
156
- lastError: error.message,
157
- });
158
- continue;
159
- }
160
- this._fail(error.message);
161
- throw error;
162
- }
163
- finally {
164
- if (this._timeoutHandle) {
165
- clearTimeout(this._timeoutHandle);
166
- this._timeoutHandle = undefined;
167
- }
168
- }
169
- }
170
- }
171
- /**
172
- * 取消任务
173
- *
174
- * @param reason - 取消原因
175
- */
176
- cancel(reason) {
177
- if (this.isDone || this._settled)
178
- return;
179
- this._settled = true;
180
- this._status = 'cancelled';
181
- this._completedAt = Date.now();
182
- this._error = reason ?? 'cancelled';
183
- this._abortController.abort();
184
- this._persistAndEmit(TaskEvents.CANCELLED);
185
- this._rejectPromise(new TaskCancelledError(this.id, reason));
186
- }
187
- /**
188
- * 等待任务完成(带超时)
189
- *
190
- * @param timeoutMs - 超时时间(毫秒),不传则无限等待
191
- * @returns 任务结果
192
- * @throws TaskTimeoutError | TaskCancelledError | Error
193
- *
194
- * 调用方超时不会改变任务本身状态;任务超时用 TaskOptions.timeoutMs。
195
- */
196
- async wait(timeoutMs) {
197
- if (this.isDone) {
198
- if (this._status === 'cancelled')
199
- throw new TaskCancelledError(this.id, this._error);
200
- if (this._status === 'failed')
201
- throw new Error(this._error ?? 'Task failed');
202
- return this._output;
203
- }
204
- if (timeoutMs === undefined)
205
- return this._promise;
206
- let timer;
207
- try {
208
- return await Promise.race([
209
- this._promise,
210
- new Promise((_, reject) => {
211
- timer = setTimeout(() => {
212
- reject(new TaskTimeoutError(this.id, timeoutMs));
213
- }, timeoutMs);
214
- }),
215
- ]);
216
- }
217
- finally {
218
- if (timer !== undefined)
219
- clearTimeout(timer);
220
- }
221
- }
222
- /**
223
- * 等待所有已排队的持久化完成(测试/优雅退出用)
224
- */
225
- async flushPersist() {
226
- await this._persistChain;
227
- }
228
- // ── 内部方法 ──
229
- _settledError() {
230
- const settledStatus = this._status;
231
- if (settledStatus === 'failed' && this._error?.includes('timed out')) {
232
- return new TaskTimeoutError(this.id, this._timeoutMs);
233
- }
234
- if (settledStatus === 'cancelled') {
235
- return new TaskCancelledError(this.id, this._error);
236
- }
237
- return new Error(this._error ?? 'Task was settled externally');
238
- }
239
- _complete(output) {
240
- this._status = 'completed';
241
- this._output = output;
242
- this._completedAt = Date.now();
243
- this._persistAndEmit(TaskEvents.COMPLETED);
244
- this._resolvePromise(output);
245
- }
246
- _fail(error) {
247
- this._status = 'failed';
248
- this._error = error;
249
- this._completedAt = Date.now();
250
- this._persistAndEmit(TaskEvents.FAILED);
251
- this._rejectPromise(new Error(error));
252
- }
253
- _handleTimeout() {
254
- if (this._settled)
255
- return;
256
- this._settled = true;
257
- this._status = 'failed';
258
- this._error = `Task timed out after ${this._timeoutMs}ms`;
259
- this._completedAt = Date.now();
260
- this._abortController.abort();
261
- this._persistAndEmit(TaskEvents.TIMEOUT);
262
- this._rejectPromise(new TaskTimeoutError(this.id, this._timeoutMs));
263
- }
264
- _persistAndEmit(eventType, extraData) {
265
- // 事件同步发射:订阅方在状态变更同帧收到,保持原语可观测时序
266
- if (this._events) {
267
- const event = {
268
- type: eventType,
269
- timestamp: Date.now(),
270
- agentId: this.agentId,
271
- sessionId: this.sessionId,
272
- data: {
273
- taskId: this.id,
274
- taskType: this.type,
275
- status: this._status,
276
- ...extraData,
277
- },
278
- };
279
- this._events.emit(event);
280
- }
281
- // 持久化串行化:后一次等前一次结束,保证 store 终态正确
282
- const record = this.toRecord();
283
- this._persistChain = this._persistChain.then(async () => {
284
- if (!this._store)
285
- return;
286
- try {
287
- if (eventType === TaskEvents.CREATED) {
288
- await this._store.create(record);
289
- }
290
- else {
291
- await this._store.update(this.id, record);
292
- }
293
- }
294
- catch {
295
- // 持久化失败不应阻塞任务执行
296
- }
297
- });
298
- }
299
- // ── 序列化 ──
300
- /** 转换为 AsyncTaskRecord(用于快照/调试/持久化) */
301
- toRecord() {
302
- return {
303
- id: this.id,
304
- agentId: this.agentId ?? 'unknown',
305
- sessionId: this.sessionId,
306
- type: this.type,
307
- status: this._status,
308
- priority: this.priority,
309
- input: this._input,
310
- output: this._output,
311
- error: this._error,
312
- createdAt: this.createdAt,
313
- startedAt: this._startedAt,
314
- completedAt: this._completedAt,
315
- retryCount: this._retryCount,
316
- maxRetries: this._maxRetries,
317
- timeoutMs: this._timeoutMs,
318
- parentId: this.parentId,
319
- metadata: this._metadata,
320
- };
321
- }
322
- }
323
- // ── 错误类型 ──
324
- /** 任务超时错误 */
325
- export class TaskTimeoutError extends Error {
326
- taskId;
327
- timeoutMs;
328
- constructor(taskId, timeoutMs) {
329
- super(`Task ${taskId} timed out after ${timeoutMs}ms`);
330
- this.taskId = taskId;
331
- this.timeoutMs = timeoutMs;
332
- this.name = 'TaskTimeoutError';
333
- }
334
- }
335
- /** 任务取消错误 */
336
- export class TaskCancelledError extends Error {
337
- taskId;
338
- reason;
339
- constructor(taskId, reason) {
340
- super(`Task ${taskId} was cancelled${reason ? `: ${reason}` : ''}`);
341
- this.taskId = taskId;
342
- this.reason = reason;
343
- this.name = 'TaskCancelledError';
344
- }
345
- }
346
- // ── 工具函数 ──
347
- /**
348
- * 创建并立即启动一个 AsyncTask
349
- *
350
- * 便捷方法,适用于"发射后不管"的场景。
351
- * 错误通过 task.promise 和 EventBus 传播,不会被静默吞掉。
352
- */
353
- export function spawnTask(options, executor, events, store) {
354
- const task = new AsyncTask(options, events, store);
355
- // fire-and-forget:错误在 task 内部处理(状态更新 + 事件发射)
356
- // 调用方应通过 task.wait() 或 task.promise 获取结果/错误
357
- task.run(executor).catch(() => { });
358
- return task;
359
- }
@@ -1,47 +0,0 @@
1
- /**
2
- * HybridPlanner — 混合规划器
3
- *
4
- * 规则优先,LLM fallback。
5
- * 常见事件用规则快速处理,复杂情况交给 LLM。
6
- *
7
- * 策略:
8
- * 1. 先用 RulePlanner 匹配
9
- * 2. 如果规则匹配且生成了步骤 → 直接使用
10
- * 3. 如果没有匹配的规则 → fallback 到 LLMPlanner
11
- */
12
- import type { Planner, Plan, AgentState } from '../cognitive-loop.js';
13
- import type { EventBusAgentEvent as AgentEvent } from '@octopi-agent/core/index.js';
14
- import type { LLMPlannerConfig } from './llm-planner.js';
15
- import type { Rule } from './rule-planner.js';
16
- export interface HybridPlannerConfig {
17
- /** LLM 配置(fallback 用) */
18
- llm: LLMPlannerConfig;
19
- /** 规则集(默认使用内置规则) */
20
- rules?: Rule[];
21
- /** 是否启用 LLM fallback(默认 true) */
22
- enableLLMFallback?: boolean;
23
- }
24
- /**
25
- * 混合规划器
26
- *
27
- * 规则优先,LLM 兜底。
28
- */
29
- export declare class HybridPlanner implements Planner {
30
- readonly name = "hybrid-planner";
31
- private _rulePlanner;
32
- private _llmPlanner;
33
- private _enableFallback;
34
- constructor(config: HybridPlannerConfig);
35
- /**
36
- * 添加规则
37
- */
38
- addRule(rule: Rule): void;
39
- /**
40
- * 分析事件:规则优先,LLM fallback
41
- */
42
- decide(events: AgentEvent[], state: AgentState): Promise<Plan>;
43
- /**
44
- * 目标分解:直接用 LLM(规则不擅长分解)
45
- */
46
- decompose(goal: string, state: AgentState): Promise<Plan>;
47
- }