@warlock.js/ai 4.2.11 → 4.3.0

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 (427) hide show
  1. package/CHANGELOG.md +61 -1
  2. package/cjs/index.cjs +10151 -4625
  3. package/cjs/index.cjs.map +1 -1
  4. package/cjs/magic-string.es-BtxW4VqG.cjs +1015 -0
  5. package/cjs/magic-string.es-BtxW4VqG.cjs.map +1 -0
  6. package/cjs/matcher-logic-SBnzYohQ.cjs +217 -0
  7. package/cjs/matcher-logic-SBnzYohQ.cjs.map +1 -0
  8. package/cjs/matchers-BBh3gyB-.cjs +13739 -0
  9. package/cjs/matchers-BBh3gyB-.cjs.map +1 -0
  10. package/esm/agent/agent-config.type.d.mts +19 -6
  11. package/esm/agent/agent-config.type.d.mts.map +1 -1
  12. package/esm/agent/agent.d.mts.map +1 -1
  13. package/esm/agent/agent.mjs +17 -6
  14. package/esm/agent/agent.mjs.map +1 -1
  15. package/esm/agent/index.d.mts +2 -1
  16. package/esm/agent/index.mjs +1 -0
  17. package/esm/agent/spawn-sub-agent.d.mts +87 -0
  18. package/esm/agent/spawn-sub-agent.d.mts.map +1 -0
  19. package/esm/agent/spawn-sub-agent.mjs +68 -0
  20. package/esm/agent/spawn-sub-agent.mjs.map +1 -0
  21. package/esm/ai.d.mts +58 -3
  22. package/esm/ai.d.mts.map +1 -1
  23. package/esm/ai.mjs +58 -3
  24. package/esm/ai.mjs.map +1 -1
  25. package/esm/batch/batch.d.mts +43 -0
  26. package/esm/batch/batch.d.mts.map +1 -0
  27. package/esm/batch/batch.mjs +179 -0
  28. package/esm/batch/batch.mjs.map +1 -0
  29. package/esm/batch/batch.type.d.mts +144 -0
  30. package/esm/batch/batch.type.d.mts.map +1 -0
  31. package/esm/batch/index.mjs +3 -0
  32. package/esm/batch/run-batch-item.mjs +100 -0
  33. package/esm/batch/run-batch-item.mjs.map +1 -0
  34. package/esm/batch/run-with-concurrency.mjs +39 -0
  35. package/esm/batch/run-with-concurrency.mjs.map +1 -0
  36. package/esm/checkpoint/index.d.mts +3 -0
  37. package/esm/checkpoint/memory.d.mts +21 -0
  38. package/esm/checkpoint/memory.d.mts.map +1 -0
  39. package/esm/checkpoint/memory.mjs +0 -0
  40. package/esm/checkpoint/memory.mjs.map +1 -0
  41. package/esm/checkpoint/pg.d.mts +37 -0
  42. package/esm/checkpoint/pg.d.mts.map +1 -0
  43. package/esm/checkpoint/pg.mjs +265 -0
  44. package/esm/checkpoint/pg.mjs.map +1 -0
  45. package/esm/checkpoint/redis.d.mts +39 -0
  46. package/esm/checkpoint/redis.d.mts.map +1 -0
  47. package/esm/checkpoint/redis.mjs +200 -0
  48. package/esm/checkpoint/redis.mjs.map +1 -0
  49. package/esm/config.d.mts +61 -14
  50. package/esm/config.d.mts.map +1 -1
  51. package/esm/config.mjs +25 -6
  52. package/esm/config.mjs.map +1 -1
  53. package/esm/contracts/agent/agent.contract.d.mts +43 -0
  54. package/esm/contracts/agent/agent.contract.d.mts.map +1 -1
  55. package/esm/contracts/agent/eval.type.d.mts +143 -0
  56. package/esm/contracts/agent/eval.type.d.mts.map +1 -0
  57. package/esm/contracts/agent/index.d.mts +1 -0
  58. package/esm/contracts/events/supervisor-events.type.d.mts +3 -3
  59. package/esm/contracts/fallback-model.contract.d.mts +65 -0
  60. package/esm/contracts/fallback-model.contract.d.mts.map +1 -0
  61. package/esm/contracts/index.d.mts +32 -12
  62. package/esm/contracts/memory/index.d.mts +4 -0
  63. package/esm/contracts/memory/memory-config.type.d.mts +150 -0
  64. package/esm/contracts/memory/memory-config.type.d.mts.map +1 -0
  65. package/esm/contracts/memory/memory-item.type.d.mts +64 -0
  66. package/esm/contracts/memory/memory-item.type.d.mts.map +1 -0
  67. package/esm/contracts/memory/memory.contract.d.mts +87 -0
  68. package/esm/contracts/memory/memory.contract.d.mts.map +1 -0
  69. package/esm/contracts/memory/recall-options.type.d.mts +33 -0
  70. package/esm/contracts/memory/recall-options.type.d.mts.map +1 -0
  71. package/esm/contracts/middleware/index.d.mts +2 -2
  72. package/esm/contracts/middleware/middleware-context.type.d.mts +42 -2
  73. package/esm/contracts/middleware/middleware-context.type.d.mts.map +1 -1
  74. package/esm/contracts/middleware/middleware.contract.d.mts +46 -2
  75. package/esm/contracts/middleware/middleware.contract.d.mts.map +1 -1
  76. package/esm/contracts/model.contract.d.mts +63 -2
  77. package/esm/contracts/model.contract.d.mts.map +1 -1
  78. package/esm/contracts/orchestrator/checkpoint-store.contract.d.mts +91 -0
  79. package/esm/contracts/orchestrator/checkpoint-store.contract.d.mts.map +1 -0
  80. package/esm/contracts/orchestrator/index.d.mts +8 -0
  81. package/esm/contracts/orchestrator/orchestrator-commands.type.d.mts +43 -0
  82. package/esm/contracts/orchestrator/orchestrator-commands.type.d.mts.map +1 -0
  83. package/esm/contracts/orchestrator/orchestrator-config.type.d.mts +170 -0
  84. package/esm/contracts/orchestrator/orchestrator-config.type.d.mts.map +1 -0
  85. package/esm/contracts/orchestrator/orchestrator-event.type.d.mts +118 -0
  86. package/esm/contracts/orchestrator/orchestrator-event.type.d.mts.map +1 -0
  87. package/esm/contracts/orchestrator/orchestrator-execute-options.type.d.mts +44 -0
  88. package/esm/contracts/orchestrator/orchestrator-execute-options.type.d.mts.map +1 -0
  89. package/esm/contracts/orchestrator/orchestrator.contract.d.mts +129 -0
  90. package/esm/contracts/orchestrator/orchestrator.contract.d.mts.map +1 -0
  91. package/esm/contracts/orchestrator/session.contract.d.mts +26 -0
  92. package/esm/contracts/orchestrator/session.contract.d.mts.map +1 -0
  93. package/esm/contracts/orchestrator/snapshot-store.contract.d.mts +89 -0
  94. package/esm/contracts/orchestrator/snapshot-store.contract.d.mts.map +1 -0
  95. package/esm/contracts/planner/index.d.mts +6 -0
  96. package/esm/contracts/planner/planner-capability.type.d.mts +39 -0
  97. package/esm/contracts/planner/planner-capability.type.d.mts.map +1 -0
  98. package/esm/contracts/planner/planner-config.type.d.mts +78 -0
  99. package/esm/contracts/planner/planner-config.type.d.mts.map +1 -0
  100. package/esm/contracts/planner/planner-execute-options.type.d.mts +43 -0
  101. package/esm/contracts/planner/planner-execute-options.type.d.mts.map +1 -0
  102. package/esm/contracts/planner/planner-plan.type.d.mts +48 -0
  103. package/esm/contracts/planner/planner-plan.type.d.mts.map +1 -0
  104. package/esm/contracts/planner/planner-result.type.d.mts +82 -0
  105. package/esm/contracts/planner/planner-result.type.d.mts.map +1 -0
  106. package/esm/contracts/planner/planner.contract.d.mts +60 -0
  107. package/esm/contracts/planner/planner.contract.d.mts.map +1 -0
  108. package/esm/contracts/result/base-report.type.d.mts +7 -2
  109. package/esm/contracts/result/base-report.type.d.mts.map +1 -1
  110. package/esm/contracts/result/base-report.type.mjs.map +1 -1
  111. package/esm/contracts/result/index.d.mts +2 -1
  112. package/esm/contracts/result/model-pricing.type.d.mts +10 -0
  113. package/esm/contracts/result/model-pricing.type.d.mts.map +1 -1
  114. package/esm/contracts/result/orchestrator-result.type.d.mts +139 -0
  115. package/esm/contracts/result/orchestrator-result.type.d.mts.map +1 -0
  116. package/esm/contracts/result/session-send-result.type.d.mts +12 -3
  117. package/esm/contracts/result/session-send-result.type.d.mts.map +1 -1
  118. package/esm/contracts/result/supervisor-result.type.d.mts +1 -1
  119. package/esm/contracts/result/usage.type.d.mts +24 -0
  120. package/esm/contracts/result/usage.type.d.mts.map +1 -1
  121. package/esm/contracts/sdk-adapter.contract.d.mts +1 -1
  122. package/esm/contracts/supervisor/dispatch-context.type.d.mts +3 -3
  123. package/esm/contracts/supervisor/evaluate-context.type.d.mts +1 -1
  124. package/esm/contracts/supervisor/index.d.mts +5 -5
  125. package/esm/contracts/supervisor/route-context.type.d.mts +2 -2
  126. package/esm/contracts/supervisor/supervisor-config.type.d.mts +55 -13
  127. package/esm/contracts/supervisor/supervisor-config.type.d.mts.map +1 -1
  128. package/esm/contracts/supervisor/supervisor-snapshot.type.d.mts +1 -1
  129. package/esm/contracts/supervisor/supervisor.contract.d.mts +9 -2
  130. package/esm/contracts/supervisor/supervisor.contract.d.mts.map +1 -1
  131. package/esm/contracts/workflow/index.d.mts +2 -2
  132. package/esm/contracts/workflow/workflow.contract.d.mts +28 -7
  133. package/esm/contracts/workflow/workflow.contract.d.mts.map +1 -1
  134. package/esm/errors/error-code.type.d.mts +1 -1
  135. package/esm/errors/index.d.mts +7 -0
  136. package/esm/errors/index.mjs +7 -0
  137. package/esm/errors/orchestrator-cancelled-error.d.mts +32 -0
  138. package/esm/errors/orchestrator-cancelled-error.d.mts.map +1 -0
  139. package/esm/errors/orchestrator-cancelled-error.mjs +31 -0
  140. package/esm/errors/orchestrator-cancelled-error.mjs.map +1 -0
  141. package/esm/errors/orchestrator-config-error.d.mts +26 -0
  142. package/esm/errors/orchestrator-config-error.d.mts.map +1 -0
  143. package/esm/errors/orchestrator-config-error.mjs +30 -0
  144. package/esm/errors/orchestrator-config-error.mjs.map +1 -0
  145. package/esm/errors/orchestrator-drift-error.d.mts +38 -0
  146. package/esm/errors/orchestrator-drift-error.d.mts.map +1 -0
  147. package/esm/errors/orchestrator-drift-error.mjs +37 -0
  148. package/esm/errors/orchestrator-drift-error.mjs.map +1 -0
  149. package/esm/errors/orchestrator-failed-error.d.mts +33 -0
  150. package/esm/errors/orchestrator-failed-error.d.mts.map +1 -0
  151. package/esm/errors/orchestrator-failed-error.mjs +36 -0
  152. package/esm/errors/orchestrator-failed-error.mjs.map +1 -0
  153. package/esm/errors/planner-cancelled-error.d.mts +33 -0
  154. package/esm/errors/planner-cancelled-error.d.mts.map +1 -0
  155. package/esm/errors/planner-cancelled-error.mjs +29 -0
  156. package/esm/errors/planner-cancelled-error.mjs.map +1 -0
  157. package/esm/errors/planner-failed-error.d.mts +40 -0
  158. package/esm/errors/planner-failed-error.d.mts.map +1 -0
  159. package/esm/errors/planner-failed-error.mjs +37 -0
  160. package/esm/errors/planner-failed-error.mjs.map +1 -0
  161. package/esm/errors/planner-plan-invalid-error.d.mts +21 -0
  162. package/esm/errors/planner-plan-invalid-error.d.mts.map +1 -0
  163. package/esm/errors/planner-plan-invalid-error.mjs +25 -0
  164. package/esm/errors/planner-plan-invalid-error.mjs.map +1 -0
  165. package/esm/eval/eval-runner.d.mts +17 -0
  166. package/esm/eval/eval-runner.d.mts.map +1 -0
  167. package/esm/eval/eval-runner.mjs +121 -0
  168. package/esm/eval/eval-runner.mjs.map +1 -0
  169. package/esm/eval/index.d.mts +29 -0
  170. package/esm/eval/index.d.mts.map +1 -0
  171. package/esm/eval/index.mjs +30 -0
  172. package/esm/eval/index.mjs.map +1 -0
  173. package/esm/eval/judge-scorer.d.mts +21 -0
  174. package/esm/eval/judge-scorer.d.mts.map +1 -0
  175. package/esm/eval/judge-scorer.mjs +87 -0
  176. package/esm/eval/judge-scorer.mjs.map +1 -0
  177. package/esm/eval/scorers.d.mts +50 -0
  178. package/esm/eval/scorers.d.mts.map +1 -0
  179. package/esm/eval/scorers.mjs +101 -0
  180. package/esm/eval/scorers.mjs.map +1 -0
  181. package/esm/index.d.mts +95 -30
  182. package/esm/index.mjs +66 -22
  183. package/esm/memory/derive-id.mjs +24 -0
  184. package/esm/memory/derive-id.mjs.map +1 -0
  185. package/esm/memory/episodic-memory.mjs +106 -0
  186. package/esm/memory/episodic-memory.mjs.map +1 -0
  187. package/esm/memory/index.d.mts +5 -0
  188. package/esm/memory/memory.d.mts +42 -0
  189. package/esm/memory/memory.d.mts.map +1 -0
  190. package/esm/memory/memory.mjs +166 -0
  191. package/esm/memory/memory.mjs.map +1 -0
  192. package/esm/memory/procedural-memory.mjs +103 -0
  193. package/esm/memory/procedural-memory.mjs.map +1 -0
  194. package/esm/memory/semantic-memory.mjs +80 -0
  195. package/esm/memory/semantic-memory.mjs.map +1 -0
  196. package/esm/memory/working-memory.mjs +62 -0
  197. package/esm/memory/working-memory.mjs.map +1 -0
  198. package/esm/middleware/builtins/budget-contract.type.d.mts +126 -0
  199. package/esm/middleware/builtins/budget-contract.type.d.mts.map +1 -0
  200. package/esm/middleware/builtins/budget.d.mts +71 -1
  201. package/esm/middleware/builtins/budget.d.mts.map +1 -1
  202. package/esm/middleware/builtins/budget.mjs +119 -4
  203. package/esm/middleware/builtins/budget.mjs.map +1 -1
  204. package/esm/middleware/builtins/semantic-cache.d.mts +1 -1
  205. package/esm/middleware/index.d.mts +2 -1
  206. package/esm/middleware/index.mjs +1 -1
  207. package/esm/middleware/pipeline.d.mts +9 -6
  208. package/esm/middleware/pipeline.d.mts.map +1 -1
  209. package/esm/middleware/pipeline.mjs.map +1 -1
  210. package/esm/mock/index.d.mts +1 -0
  211. package/esm/mock/index.mjs +1 -0
  212. package/esm/mock/mock-router.d.mts +63 -0
  213. package/esm/mock/mock-router.d.mts.map +1 -0
  214. package/esm/mock/mock-router.mjs +58 -0
  215. package/esm/mock/mock-router.mjs.map +1 -0
  216. package/esm/model/fallback-model.d.mts +45 -0
  217. package/esm/model/fallback-model.d.mts.map +1 -0
  218. package/esm/model/fallback-model.mjs +218 -0
  219. package/esm/model/fallback-model.mjs.map +1 -0
  220. package/esm/model/index.d.mts +2 -0
  221. package/esm/model/index.mjs +3 -0
  222. package/esm/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs +78 -0
  223. package/esm/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs.map +1 -0
  224. package/esm/node_modules/@vitest/expect/dist/index.mjs +1473 -0
  225. package/esm/node_modules/@vitest/expect/dist/index.mjs.map +1 -0
  226. package/esm/node_modules/@vitest/pretty-format/dist/index.mjs +888 -0
  227. package/esm/node_modules/@vitest/pretty-format/dist/index.mjs.map +1 -0
  228. package/esm/node_modules/@vitest/runner/dist/chunk-artifact.mjs +1533 -0
  229. package/esm/node_modules/@vitest/runner/dist/chunk-artifact.mjs.map +1 -0
  230. package/esm/node_modules/@vitest/runner/dist/index.mjs +3 -0
  231. package/esm/node_modules/@vitest/runner/dist/utils.mjs +3 -0
  232. package/esm/node_modules/@vitest/snapshot/dist/index.mjs +922 -0
  233. package/esm/node_modules/@vitest/snapshot/dist/index.mjs.map +1 -0
  234. package/esm/node_modules/@vitest/spy/dist/index.mjs +386 -0
  235. package/esm/node_modules/@vitest/spy/dist/index.mjs.map +1 -0
  236. package/esm/node_modules/@vitest/utils/dist/chunk-pathe.M-eThtNZ.mjs +82 -0
  237. package/esm/node_modules/@vitest/utils/dist/chunk-pathe.M-eThtNZ.mjs.map +1 -0
  238. package/esm/node_modules/@vitest/utils/dist/diff.mjs +1357 -0
  239. package/esm/node_modules/@vitest/utils/dist/diff.mjs.map +1 -0
  240. package/esm/node_modules/@vitest/utils/dist/display.mjs +559 -0
  241. package/esm/node_modules/@vitest/utils/dist/display.mjs.map +1 -0
  242. package/esm/node_modules/@vitest/utils/dist/error.mjs +38 -0
  243. package/esm/node_modules/@vitest/utils/dist/error.mjs.map +1 -0
  244. package/esm/node_modules/@vitest/utils/dist/helpers.mjs +181 -0
  245. package/esm/node_modules/@vitest/utils/dist/helpers.mjs.map +1 -0
  246. package/esm/node_modules/@vitest/utils/dist/offset.mjs +27 -0
  247. package/esm/node_modules/@vitest/utils/dist/offset.mjs.map +1 -0
  248. package/esm/node_modules/@vitest/utils/dist/serialize.mjs +77 -0
  249. package/esm/node_modules/@vitest/utils/dist/serialize.mjs.map +1 -0
  250. package/esm/node_modules/@vitest/utils/dist/source-map.mjs +374 -0
  251. package/esm/node_modules/@vitest/utils/dist/source-map.mjs.map +1 -0
  252. package/esm/node_modules/@vitest/utils/dist/timers.mjs +37 -0
  253. package/esm/node_modules/@vitest/utils/dist/timers.mjs.map +1 -0
  254. package/esm/node_modules/chai/index.mjs +2973 -0
  255. package/esm/node_modules/chai/index.mjs.map +1 -0
  256. package/esm/node_modules/magic-string/dist/magic-string.es.mjs +940 -0
  257. package/esm/node_modules/magic-string/dist/magic-string.es.mjs.map +1 -0
  258. package/esm/node_modules/tinyrainbow/dist/index.mjs +87 -0
  259. package/esm/node_modules/tinyrainbow/dist/index.mjs.map +1 -0
  260. package/esm/node_modules/vitest/dist/chunks/_commonjsHelpers.D26ty3Ew.mjs +6 -0
  261. package/esm/node_modules/vitest/dist/chunks/_commonjsHelpers.D26ty3Ew.mjs.map +1 -0
  262. package/esm/node_modules/vitest/dist/chunks/rpc.MzXet3jl.mjs +52 -0
  263. package/esm/node_modules/vitest/dist/chunks/rpc.MzXet3jl.mjs.map +1 -0
  264. package/esm/node_modules/vitest/dist/chunks/test.DNmyFkvJ.mjs +2697 -0
  265. package/esm/node_modules/vitest/dist/chunks/test.DNmyFkvJ.mjs.map +1 -0
  266. package/esm/node_modules/vitest/dist/chunks/utils.BX5Fg8C4.mjs +45 -0
  267. package/esm/node_modules/vitest/dist/chunks/utils.BX5Fg8C4.mjs.map +1 -0
  268. package/esm/orchestrator/as-tool.d.mts +42 -0
  269. package/esm/orchestrator/as-tool.d.mts.map +1 -0
  270. package/esm/orchestrator/as-tool.mjs +98 -0
  271. package/esm/orchestrator/as-tool.mjs.map +1 -0
  272. package/esm/orchestrator/checkpoint.mjs +75 -0
  273. package/esm/orchestrator/checkpoint.mjs.map +1 -0
  274. package/esm/orchestrator/commands.d.mts +38 -0
  275. package/esm/orchestrator/commands.d.mts.map +1 -0
  276. package/esm/orchestrator/commands.mjs +34 -0
  277. package/esm/orchestrator/commands.mjs.map +1 -0
  278. package/esm/orchestrator/compaction.mjs +206 -0
  279. package/esm/orchestrator/compaction.mjs.map +1 -0
  280. package/esm/orchestrator/dispatch.mjs +171 -0
  281. package/esm/orchestrator/dispatch.mjs.map +1 -0
  282. package/esm/orchestrator/emitter-port.type.d.mts +31 -0
  283. package/esm/orchestrator/emitter-port.type.d.mts.map +1 -0
  284. package/esm/orchestrator/emitter.d.mts +56 -0
  285. package/esm/orchestrator/emitter.d.mts.map +1 -0
  286. package/esm/orchestrator/emitter.mjs +85 -0
  287. package/esm/orchestrator/emitter.mjs.map +1 -0
  288. package/esm/orchestrator/engine-context.type.d.mts +56 -0
  289. package/esm/orchestrator/engine-context.type.d.mts.map +1 -0
  290. package/esm/orchestrator/execution.d.mts +116 -0
  291. package/esm/orchestrator/execution.d.mts.map +1 -0
  292. package/esm/orchestrator/execution.mjs +406 -0
  293. package/esm/orchestrator/execution.mjs.map +1 -0
  294. package/esm/orchestrator/index.d.mts +8 -0
  295. package/esm/orchestrator/index.mjs +10 -0
  296. package/esm/orchestrator/load.mjs +49 -0
  297. package/esm/orchestrator/load.mjs.map +1 -0
  298. package/esm/orchestrator/lock.mjs +75 -0
  299. package/esm/orchestrator/lock.mjs.map +1 -0
  300. package/esm/orchestrator/memory.d.mts +84 -0
  301. package/esm/orchestrator/memory.d.mts.map +1 -0
  302. package/esm/orchestrator/memory.mjs +141 -0
  303. package/esm/orchestrator/memory.mjs.map +1 -0
  304. package/esm/orchestrator/orchestrator-stream.d.mts +42 -0
  305. package/esm/orchestrator/orchestrator-stream.d.mts.map +1 -0
  306. package/esm/orchestrator/orchestrator-stream.mjs +98 -0
  307. package/esm/orchestrator/orchestrator-stream.mjs.map +1 -0
  308. package/esm/orchestrator/orchestrator.d.mts +38 -0
  309. package/esm/orchestrator/orchestrator.d.mts.map +1 -0
  310. package/esm/orchestrator/orchestrator.mjs +173 -0
  311. package/esm/orchestrator/orchestrator.mjs.map +1 -0
  312. package/esm/orchestrator/resume.mjs +74 -0
  313. package/esm/orchestrator/resume.mjs.map +1 -0
  314. package/esm/orchestrator/signature.d.mts +40 -0
  315. package/esm/orchestrator/signature.d.mts.map +1 -0
  316. package/esm/orchestrator/signature.mjs +120 -0
  317. package/esm/orchestrator/signature.mjs.map +1 -0
  318. package/esm/orchestrator/window.mjs +56 -0
  319. package/esm/orchestrator/window.mjs.map +1 -0
  320. package/esm/planner/index.d.mts +5 -0
  321. package/esm/planner/index.mjs +6 -0
  322. package/esm/planner/plan-prompt.d.mts +17 -0
  323. package/esm/planner/plan-prompt.d.mts.map +1 -0
  324. package/esm/planner/plan-prompt.mjs +30 -0
  325. package/esm/planner/plan-prompt.mjs.map +1 -0
  326. package/esm/planner/plan-schema.d.mts +27 -0
  327. package/esm/planner/plan-schema.d.mts.map +1 -0
  328. package/esm/planner/plan-schema.mjs +117 -0
  329. package/esm/planner/plan-schema.mjs.map +1 -0
  330. package/esm/planner/planner-run.d.mts +23 -0
  331. package/esm/planner/planner-run.d.mts.map +1 -0
  332. package/esm/planner/planner-run.mjs +344 -0
  333. package/esm/planner/planner-run.mjs.map +1 -0
  334. package/esm/planner/planner.d.mts +37 -0
  335. package/esm/planner/planner.d.mts.map +1 -0
  336. package/esm/planner/planner.mjs +120 -0
  337. package/esm/planner/planner.mjs.map +1 -0
  338. package/esm/planner/signature.d.mts +18 -0
  339. package/esm/planner/signature.d.mts.map +1 -0
  340. package/esm/planner/signature.mjs +27 -0
  341. package/esm/planner/signature.mjs.map +1 -0
  342. package/esm/snapshot/index.d.mts +3 -0
  343. package/esm/snapshot/memory.d.mts +26 -0
  344. package/esm/snapshot/memory.d.mts.map +1 -0
  345. package/esm/snapshot/memory.mjs +81 -0
  346. package/esm/snapshot/memory.mjs.map +1 -0
  347. package/esm/snapshot/pg.d.mts +41 -0
  348. package/esm/snapshot/pg.d.mts.map +1 -0
  349. package/esm/snapshot/pg.mjs +146 -0
  350. package/esm/snapshot/pg.mjs.map +1 -0
  351. package/esm/snapshot/redis.d.mts +42 -0
  352. package/esm/snapshot/redis.d.mts.map +1 -0
  353. package/esm/snapshot/redis.mjs +101 -0
  354. package/esm/snapshot/redis.mjs.map +1 -0
  355. package/esm/supervisor/as-tool.d.mts +0 -6
  356. package/esm/supervisor/as-tool.d.mts.map +1 -1
  357. package/esm/supervisor/as-tool.mjs +0 -6
  358. package/esm/supervisor/as-tool.mjs.map +1 -1
  359. package/esm/supervisor/execution.d.mts +43 -8
  360. package/esm/supervisor/execution.d.mts.map +1 -1
  361. package/esm/supervisor/execution.mjs +66 -16
  362. package/esm/supervisor/execution.mjs.map +1 -1
  363. package/esm/supervisor/fan-out.d.mts +65 -0
  364. package/esm/supervisor/fan-out.d.mts.map +1 -0
  365. package/esm/supervisor/fan-out.mjs +65 -0
  366. package/esm/supervisor/fan-out.mjs.map +1 -0
  367. package/esm/supervisor/index.d.mts +5 -3
  368. package/esm/supervisor/index.mjs +3 -1
  369. package/esm/supervisor/router-factory.d.mts +110 -0
  370. package/esm/supervisor/router-factory.d.mts.map +1 -0
  371. package/esm/supervisor/router-factory.mjs +141 -0
  372. package/esm/supervisor/router-factory.mjs.map +1 -0
  373. package/esm/supervisor/router-prompt.d.mts +1 -1
  374. package/esm/supervisor/snapshot.d.mts +4 -10
  375. package/esm/supervisor/snapshot.d.mts.map +1 -1
  376. package/esm/supervisor/snapshot.mjs +8 -16
  377. package/esm/supervisor/snapshot.mjs.map +1 -1
  378. package/esm/supervisor/supervisor.mjs +1 -0
  379. package/esm/supervisor/supervisor.mjs.map +1 -1
  380. package/esm/system-prompt/index.mjs +6 -0
  381. package/esm/system-prompt/system-prompt.d.mts +51 -3
  382. package/esm/system-prompt/system-prompt.d.mts.map +1 -1
  383. package/esm/system-prompt/system-prompt.mjs +52 -6
  384. package/esm/system-prompt/system-prompt.mjs.map +1 -1
  385. package/esm/testing/matcher-logic.d.mts +76 -0
  386. package/esm/testing/matcher-logic.d.mts.map +1 -0
  387. package/esm/testing/matcher-logic.mjs +144 -0
  388. package/esm/testing/matcher-logic.mjs.map +1 -0
  389. package/esm/testing/matchers.d.mts +48 -0
  390. package/esm/testing/matchers.d.mts.map +1 -0
  391. package/esm/testing/matchers.mjs +37 -0
  392. package/esm/testing/matchers.mjs.map +1 -0
  393. package/esm/testing/register-lazy.d.mts +20 -0
  394. package/esm/testing/register-lazy.d.mts.map +1 -0
  395. package/esm/testing/register-lazy.mjs +24 -0
  396. package/esm/testing/register-lazy.mjs.map +1 -0
  397. package/esm/tool/executable-as-tool.d.mts +87 -0
  398. package/esm/tool/executable-as-tool.d.mts.map +1 -0
  399. package/esm/tool/executable-as-tool.mjs +81 -0
  400. package/esm/tool/executable-as-tool.mjs.map +1 -0
  401. package/esm/tool/index.d.mts +2 -1
  402. package/esm/tool/index.mjs +1 -0
  403. package/esm/workflow/as-tool.mjs +0 -6
  404. package/esm/workflow/as-tool.mjs.map +1 -1
  405. package/esm/workflow/engine.mjs +2 -2
  406. package/esm/workflow/snapshot.mjs +13 -7
  407. package/esm/workflow/snapshot.mjs.map +1 -1
  408. package/esm/workflow/step-runner.mjs +1 -1
  409. package/esm/workflow/workflow.mjs +1 -0
  410. package/esm/workflow/workflow.mjs.map +1 -1
  411. package/llms-full.txt +947 -42
  412. package/llms.txt +13 -8
  413. package/package.json +3 -3
  414. package/skills/README.md +25 -5
  415. package/skills/ai-basics/SKILL.md +18 -7
  416. package/skills/ai-dx-helpers/SKILL.md +180 -0
  417. package/skills/attach-ai-middleware/SKILL.md +32 -3
  418. package/skills/handle-ai-errors/SKILL.md +20 -6
  419. package/skills/manage-ai-stores/SKILL.md +127 -0
  420. package/skills/persist-ai-data/SKILL.md +21 -10
  421. package/skills/pick-ai-provider/SKILL.md +46 -12
  422. package/skills/run-ai-agent/SKILL.md +51 -2
  423. package/skills/run-orchestrator/SKILL.md +198 -0
  424. package/skills/run-planner/SKILL.md +68 -0
  425. package/skills/run-supervisor/SKILL.md +47 -2
  426. package/skills/use-ai-memory/SKILL.md +124 -0
  427. package/skills/write-system-prompt/SKILL.md +14 -1
@@ -0,0 +1,37 @@
1
+ import { matchConverge, matchOutputShape, matchPassStep, matchRouteTo } from "./matcher-logic.mjs";
2
+ import { globalExpect } from "../node_modules/vitest/dist/chunks/test.DNmyFkvJ.mjs";
3
+
4
+ //#region ../@warlock.js/ai/src/testing/matchers.ts
5
+ let registered = false;
6
+ /**
7
+ * Register the `@warlock.js/ai` custom matchers on Vitest's global
8
+ * `expect`. Call once per test file (or in a shared import) before
9
+ * using `toRouteTo` / `toConverge` / `toPassStep` / `toOutputShape`.
10
+ * Idempotent — repeated calls are a no-op.
11
+ *
12
+ * @example
13
+ * import { registerAiMatchers } from "@warlock.js/ai";
14
+ * registerAiMatchers();
15
+ */
16
+ function registerAiMatchers() {
17
+ if (registered) return;
18
+ registered = true;
19
+ globalExpect.extend({
20
+ toRouteTo(received, intent) {
21
+ return matchRouteTo(received, intent);
22
+ },
23
+ toConverge(received) {
24
+ return matchConverge(received);
25
+ },
26
+ toPassStep(received, stepName) {
27
+ return matchPassStep(received, stepName);
28
+ },
29
+ toOutputShape(received, schema) {
30
+ return matchOutputShape(received, schema);
31
+ }
32
+ });
33
+ }
34
+
35
+ //#endregion
36
+ export { registerAiMatchers };
37
+ //# sourceMappingURL=matchers.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"matchers.mjs","names":[],"sources":["../../../../../../../@warlock.js/ai/src/testing/matchers.ts"],"sourcesContent":["import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport { expect } from \"vitest\";\nimport {\n matchConverge,\n matchOutputShape,\n matchPassStep,\n matchRouteTo,\n} from \"./matcher-logic\";\n\n/**\n * Custom Vitest matchers over the unified `@warlock.js/ai` report tree.\n *\n * - `toRouteTo(intent)` — a supervisor dispatched the named intent.\n * - `toConverge()` — a supervisor terminated cleanly on its own\n * decision (not max-iterations / cancelled / error).\n * - `toPassStep(name)` — a workflow step completed successfully.\n * - `toOutputShape(schema)` — a result's `data` validates against a\n * Standard Schema.\n *\n * @example\n * import { registerAiMatchers } from \"@warlock.js/ai\";\n * registerAiMatchers();\n *\n * expect(await supervisor.execute(input)).toRouteTo(\"critic\");\n * expect(await supervisor.execute(input)).toConverge();\n * expect(await workflow.execute(input)).toPassStep(\"draft\");\n * expect(await agent.execute(input, { output: schema })).toOutputShape(schema);\n */\nexport interface AiMatchers<R = unknown> {\n /** Assert a supervisor dispatched the named intent across its run. */\n toRouteTo(intent: string): R;\n /** Assert a supervisor terminated cleanly on its own decision. */\n toConverge(): R;\n /** Assert a named workflow step completed successfully. */\n toPassStep(stepName: string): R;\n /** Assert a result's `data` validates against a Standard Schema. */\n toOutputShape(schema: StandardSchemaV1): R;\n}\n\ndeclare module \"vitest\" {\n // Vitest 4's augmentable `Matchers` interface is `Matchers<T = any>`\n // — the type parameter must match exactly (TS2428) or the\n // declaration is rejected. `T` is the assertion-chain return type.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n interface Matchers<T = any> extends AiMatchers<T> {}\n}\n\nlet registered = false;\n\n/**\n * Register the `@warlock.js/ai` custom matchers on Vitest's global\n * `expect`. Call once per test file (or in a shared import) before\n * using `toRouteTo` / `toConverge` / `toPassStep` / `toOutputShape`.\n * Idempotent — repeated calls are a no-op.\n *\n * @example\n * import { registerAiMatchers } from \"@warlock.js/ai\";\n * registerAiMatchers();\n */\nexport function registerAiMatchers(): void {\n if (registered) {\n return;\n }\n\n registered = true;\n\n expect.extend({\n toRouteTo(received: unknown, intent: string) {\n return matchRouteTo(received as never, intent);\n },\n toConverge(received: unknown) {\n return matchConverge(received as never);\n },\n toPassStep(received: unknown, stepName: string) {\n return matchPassStep(received as never, stepName);\n },\n toOutputShape(received: unknown, schema: StandardSchemaV1) {\n return matchOutputShape(received as never, schema);\n },\n });\n}\n"],"mappings":";;;;AA+CA,IAAI,aAAa;;;;;;;;;;;AAYjB,SAAgB,qBAA2B;CACzC,IAAI,YACF;CAGF,aAAa;CAEb,aAAO,OAAO;EACZ,UAAU,UAAmB,QAAgB;GAC3C,OAAO,aAAa,UAAmB,MAAM;EAC/C;EACA,WAAW,UAAmB;GAC5B,OAAO,cAAc,QAAiB;EACxC;EACA,WAAW,UAAmB,UAAkB;GAC9C,OAAO,cAAc,UAAmB,QAAQ;EAClD;EACA,cAAc,UAAmB,QAA0B;GACzD,OAAO,iBAAiB,UAAmB,MAAM;EACnD;CACF,CAAC;AACH"}
@@ -0,0 +1,20 @@
1
+ //#region ../@warlock.js/ai/src/testing/register-lazy.d.ts
2
+ /**
3
+ * Register the `@warlock.js/ai` custom Vitest matchers
4
+ * (`toRouteTo` / `toConverge` / `toPassStep` / `toOutputShape`) on the
5
+ * global `expect`. Call once from test code before using them. The
6
+ * underlying `vitest`-coupled implementation is imported lazily on the
7
+ * first call, so importing `@warlock.js/ai` in production never pulls in
8
+ * `vitest`. Idempotent — the underlying registration is itself a no-op on
9
+ * repeat calls.
10
+ *
11
+ * @example
12
+ * import { registerAiMatchers } from "@warlock.js/ai";
13
+ * await registerAiMatchers();
14
+ *
15
+ * expect(await supervisor.execute(input)).toRouteTo("critic");
16
+ */
17
+ declare function registerAiMatchers(): Promise<void>;
18
+ //#endregion
19
+ export { registerAiMatchers };
20
+ //# sourceMappingURL=register-lazy.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register-lazy.d.mts","names":[],"sources":["../../../../../../../@warlock.js/ai/src/testing/register-lazy.ts"],"mappings":";;AA2BA;;;;AAAmD;;;;;;;;;;iBAA7B,kBAAA,IAAsB,OAAO"}
@@ -0,0 +1,24 @@
1
+ //#region ../@warlock.js/ai/src/testing/register-lazy.ts
2
+ /**
3
+ * Register the `@warlock.js/ai` custom Vitest matchers
4
+ * (`toRouteTo` / `toConverge` / `toPassStep` / `toOutputShape`) on the
5
+ * global `expect`. Call once from test code before using them. The
6
+ * underlying `vitest`-coupled implementation is imported lazily on the
7
+ * first call, so importing `@warlock.js/ai` in production never pulls in
8
+ * `vitest`. Idempotent — the underlying registration is itself a no-op on
9
+ * repeat calls.
10
+ *
11
+ * @example
12
+ * import { registerAiMatchers } from "@warlock.js/ai";
13
+ * await registerAiMatchers();
14
+ *
15
+ * expect(await supervisor.execute(input)).toRouteTo("critic");
16
+ */
17
+ async function registerAiMatchers() {
18
+ const { registerAiMatchers: register } = await import("./matchers.mjs");
19
+ register();
20
+ }
21
+
22
+ //#endregion
23
+ export { registerAiMatchers };
24
+ //# sourceMappingURL=register-lazy.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register-lazy.mjs","names":[],"sources":["../../../../../../../@warlock.js/ai/src/testing/register-lazy.ts"],"sourcesContent":["// Lazy bridge for the vitest-coupled matcher registration.\n//\n// WHY: `@warlock.js/ai`'s root barrel (`src/index.ts`) is the package's\n// only public entry, and it is loaded by every production consumer.\n// `./matchers` statically imports `vitest` (a devDependency) at module\n// top to call `expect.extend`, so pulling it into the eager barrel would\n// force `vitest` to resolve in production — where it is not installed —\n// and crash the import. This wrapper defers that import to call time via\n// a dynamic `import()`, mirroring the package's optional-peer discipline,\n// so `registerAiMatchers` can ship on the root barrel while staying inert\n// (and `vitest`-free) until a test actually invokes it.\n\n/**\n * Register the `@warlock.js/ai` custom Vitest matchers\n * (`toRouteTo` / `toConverge` / `toPassStep` / `toOutputShape`) on the\n * global `expect`. Call once from test code before using them. The\n * underlying `vitest`-coupled implementation is imported lazily on the\n * first call, so importing `@warlock.js/ai` in production never pulls in\n * `vitest`. Idempotent — the underlying registration is itself a no-op on\n * repeat calls.\n *\n * @example\n * import { registerAiMatchers } from \"@warlock.js/ai\";\n * await registerAiMatchers();\n *\n * expect(await supervisor.execute(input)).toRouteTo(\"critic\");\n */\nexport async function registerAiMatchers(): Promise<void> {\n const { registerAiMatchers: register } = await import(\"./matchers\");\n\n register();\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA2BA,eAAsB,qBAAoC;CACxD,MAAM,EAAE,oBAAoB,aAAa,MAAM,OAAO;CAEtD,SAAS;AACX"}
@@ -0,0 +1,87 @@
1
+ import { AIError } from "../errors/ai-error.mjs";
2
+ import { BaseResult } from "../contracts/result/base-result.type.mjs";
3
+ import { BaseReport } from "../contracts/result/base-report.type.mjs";
4
+ import { ToolContract } from "./tool.mjs";
5
+ import { StandardSchemaV1 } from "@standard-schema/spec";
6
+
7
+ //#region ../@warlock.js/ai/src/tool/executable-as-tool.d.ts
8
+ /**
9
+ * Envelope every executable's `execute()` resolves to. Agent, workflow,
10
+ * and supervisor results all satisfy this shape — `data` / `error`
11
+ * carry the outcome while `usage` and `report` are always present —
12
+ * which is exactly what {@link compositeAsTool} needs to nest the inner
13
+ * run under the outer tool-call node.
14
+ */
15
+ type ExecutableEnvelope<TOutput> = BaseResult & {
16
+ data?: TOutput;
17
+ error?: AIError;
18
+ report: BaseReport;
19
+ };
20
+ /**
21
+ * Structural view of an executable primitive (agent / workflow /
22
+ * supervisor) when it is dropped straight into an agent's `tools: []`
23
+ * array WITHOUT being wrapped via `.asTool()` first.
24
+ *
25
+ * Only the fields the auto-adapt path reads are declared:
26
+ * - `name` — becomes the LLM tool name (required; anonymous executables
27
+ * are rejected at author time, mirroring `.asTool()`).
28
+ * - `description` — the "when would the model pick this?" line.
29
+ * - `inputSchema` — opt-in Standard Schema typing the tool's arguments.
30
+ * Surfaced on `WorkflowInstance` / `SupervisorContract` from the new
31
+ * optional `inputSchema` config field. Absent for agents (which take
32
+ * a plain string prompt).
33
+ * - `execute` — the dispatch entry every `ExecutableContract` exposes.
34
+ *
35
+ * `invoke` is declared `never` so a `ToolContract` (which HAS `invoke`)
36
+ * can never be mistaken for an executable by the {@link isExecutableTool}
37
+ * guard.
38
+ */
39
+ type ExecutableTool<TInput = unknown, TOutput = unknown> = {
40
+ readonly name: string;
41
+ readonly description?: string;
42
+ readonly inputSchema?: StandardSchemaV1<TInput>;
43
+ execute(input: TInput, options?: unknown): Promise<ExecutableEnvelope<TOutput>>;
44
+ invoke?: never;
45
+ };
46
+ /**
47
+ * Entry accepted in an agent's `tools: []` array — either an already-
48
+ * built `ToolContract` (the `.asTool()` / `ai.tool()` path) or a raw
49
+ * executable primitive the framework auto-adapts on the caller's
50
+ * behalf.
51
+ */
52
+ type AgentToolEntry<TInput = unknown, TOutput = unknown> = ToolContract<TInput, TOutput> | ExecutableTool<TInput, TOutput>;
53
+ /**
54
+ * Type guard distinguishing a raw executable primitive from a built
55
+ * `ToolContract`. An executable exposes `execute()` and no `invoke()`;
56
+ * a `ToolContract` exposes `invoke()`. The `invoke` check is the
57
+ * load-bearing discriminator — `.asTool()`-wrapped composites keep
58
+ * their own `execute` too, so checking `execute` alone is insufficient.
59
+ */
60
+ declare function isExecutableTool(entry: unknown): entry is ExecutableTool;
61
+ /**
62
+ * Adapt a raw executable primitive (agent / workflow / supervisor) into
63
+ * a `ToolContract` so an agent can dispatch it inside its tool-call
64
+ * loop WITHOUT the caller writing `.asTool()`. Derives the LLM tool
65
+ * manifest from the executable's own `name` + `description` +
66
+ * (optional) `inputSchema`, then dispatches through the executable's
67
+ * `execute()` — the inner report nests under the outer tool-call node
68
+ * exactly like an explicit `.asTool()` wrapper.
69
+ *
70
+ * Throws `AgentExecutionError` at author time when the executable lacks
71
+ * a usable `name` — the agent's tool surface needs a stable id, the
72
+ * same constraint `.asTool()` enforces.
73
+ */
74
+ declare function executableToTool<TInput, TOutput>(executable: ExecutableTool<TInput, TOutput>): ToolContract<TInput, TOutput>;
75
+ /**
76
+ * Normalize an agent's `tools: []` array into a uniform
77
+ * `ToolContract[]` for the runtime. Already-built `ToolContract`s
78
+ * (`.asTool()` / `ai.tool()`) pass through untouched; raw executable
79
+ * primitives are auto-adapted via {@link executableToTool}.
80
+ *
81
+ * Returns `undefined` when no tools were supplied so the agent's
82
+ * existing `config.tools ?? []` fallbacks stay byte-identical.
83
+ */
84
+ declare function normalizeAgentTools(tools: ReadonlyArray<AgentToolEntry> | undefined): ToolContract<unknown, unknown>[] | undefined;
85
+ //#endregion
86
+ export { AgentToolEntry, ExecutableTool, executableToTool, isExecutableTool, normalizeAgentTools };
87
+ //# sourceMappingURL=executable-as-tool.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executable-as-tool.d.mts","names":[],"sources":["../../../../../../../@warlock.js/ai/src/tool/executable-as-tool.ts"],"mappings":";;;;;;;;;;AAK4D;;;;KASvD,kBAAA,YAA8B,UAAA;EACjC,IAAA,GAAO,OAAA;EACP,KAAA,GAAQ,OAAA;EACR,MAAA,EAAQ,UAAA;AAAA;;;;;;;;;;AAAU;AAsBpB;;;;;;;;;KAAY,cAAA;EAAA,SACD,IAAA;EAAA,SACA,WAAA;EAAA,SACA,WAAA,GAAc,gBAAA,CAAiB,MAAA;EACxC,OAAA,CAAQ,KAAA,EAAO,MAAA,EAAQ,OAAA,aAAoB,OAAA,CAAQ,kBAAA,CAAmB,OAAA;EACtE,MAAA;AAAA;;;;;;;KASU,cAAA,wCACR,YAAA,CAAa,MAAA,EAAQ,OAAA,IACrB,cAAA,CAAe,MAAA,EAAQ,OAAA;;;;;AAXnB;AASR;;iBA4BgB,gBAAA,CAAiB,KAAA,YAAiB,KAAA,IAAS,cAAc;;;;;;;;;;;;;;iBAuBzD,gBAAA,kBACd,UAAA,EAAY,cAAA,CAAe,MAAA,EAAQ,OAAA,IAClC,YAAA,CAAa,MAAA,EAAQ,OAAA;;;;AAnDU;AA0BlC;;;;;iBAmEgB,mBAAA,CACd,KAAA,EAAO,aAAA,CAAc,cAAA,gBACpB,YAAA"}
@@ -0,0 +1,81 @@
1
+ import { AgentExecutionError } from "../errors/agent-execution-error.mjs";
2
+ import "../errors/index.mjs";
3
+ import { compositeAsTool } from "./tool.mjs";
4
+
5
+ //#region ../@warlock.js/ai/src/tool/executable-as-tool.ts
6
+ /**
7
+ * Identity passthrough schema used when an executable is registered as
8
+ * a tool without declaring an `inputSchema`. The model's raw arguments
9
+ * flow straight to `execute()` unchanged — the executable validates
10
+ * internally (workflows via their steps, supervisors/agents via their
11
+ * own input handling).
12
+ */
13
+ function passthroughSchema() {
14
+ return { "~standard": {
15
+ version: 1,
16
+ vendor: "warlock-ai",
17
+ validate: (value) => ({ value })
18
+ } };
19
+ }
20
+ /**
21
+ * Type guard distinguishing a raw executable primitive from a built
22
+ * `ToolContract`. An executable exposes `execute()` and no `invoke()`;
23
+ * a `ToolContract` exposes `invoke()`. The `invoke` check is the
24
+ * load-bearing discriminator — `.asTool()`-wrapped composites keep
25
+ * their own `execute` too, so checking `execute` alone is insufficient.
26
+ */
27
+ function isExecutableTool(entry) {
28
+ if (!entry || typeof entry !== "object") return false;
29
+ const candidate = entry;
30
+ return typeof candidate.execute === "function" && typeof candidate.invoke !== "function";
31
+ }
32
+ /**
33
+ * Adapt a raw executable primitive (agent / workflow / supervisor) into
34
+ * a `ToolContract` so an agent can dispatch it inside its tool-call
35
+ * loop WITHOUT the caller writing `.asTool()`. Derives the LLM tool
36
+ * manifest from the executable's own `name` + `description` +
37
+ * (optional) `inputSchema`, then dispatches through the executable's
38
+ * `execute()` — the inner report nests under the outer tool-call node
39
+ * exactly like an explicit `.asTool()` wrapper.
40
+ *
41
+ * Throws `AgentExecutionError` at author time when the executable lacks
42
+ * a usable `name` — the agent's tool surface needs a stable id, the
43
+ * same constraint `.asTool()` enforces.
44
+ */
45
+ function executableToTool(executable) {
46
+ if (!executable.name || typeof executable.name !== "string") throw new AgentExecutionError("tools[]: an executable (agent/workflow/supervisor) used as a tool must have a `name`", { context: { authoring: true } });
47
+ return compositeAsTool({
48
+ name: executable.name,
49
+ description: executable.description ?? `Invoke "${executable.name}" as a tool.`,
50
+ input: executable.inputSchema ?? passthroughSchema(),
51
+ execute: async (input) => {
52
+ const result = await executable.execute(input);
53
+ if (result.error) throw result.error;
54
+ return {
55
+ data: result.data,
56
+ usage: result.usage,
57
+ report: result.report
58
+ };
59
+ }
60
+ });
61
+ }
62
+ /**
63
+ * Normalize an agent's `tools: []` array into a uniform
64
+ * `ToolContract[]` for the runtime. Already-built `ToolContract`s
65
+ * (`.asTool()` / `ai.tool()`) pass through untouched; raw executable
66
+ * primitives are auto-adapted via {@link executableToTool}.
67
+ *
68
+ * Returns `undefined` when no tools were supplied so the agent's
69
+ * existing `config.tools ?? []` fallbacks stay byte-identical.
70
+ */
71
+ function normalizeAgentTools(tools) {
72
+ if (!tools) return;
73
+ return tools.map((entry) => {
74
+ if (isExecutableTool(entry)) return executableToTool(entry);
75
+ return entry;
76
+ });
77
+ }
78
+
79
+ //#endregion
80
+ export { executableToTool, isExecutableTool, normalizeAgentTools };
81
+ //# sourceMappingURL=executable-as-tool.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executable-as-tool.mjs","names":[],"sources":["../../../../../../../@warlock.js/ai/src/tool/executable-as-tool.ts"],"sourcesContent":["import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { BaseReport } from \"../contracts/result/base-report.type\";\nimport type { BaseResult } from \"../contracts/result/base-result.type\";\nimport type { Usage } from \"../contracts/result/usage.type\";\nimport { AgentExecutionError, type AIError } from \"../errors\";\nimport { compositeAsTool, type ToolContract } from \"./tool\";\n\n/**\n * Envelope every executable's `execute()` resolves to. Agent, workflow,\n * and supervisor results all satisfy this shape — `data` / `error`\n * carry the outcome while `usage` and `report` are always present —\n * which is exactly what {@link compositeAsTool} needs to nest the inner\n * run under the outer tool-call node.\n */\ntype ExecutableEnvelope<TOutput> = BaseResult & {\n data?: TOutput;\n error?: AIError;\n report: BaseReport;\n};\n\n/**\n * Structural view of an executable primitive (agent / workflow /\n * supervisor) when it is dropped straight into an agent's `tools: []`\n * array WITHOUT being wrapped via `.asTool()` first.\n *\n * Only the fields the auto-adapt path reads are declared:\n * - `name` — becomes the LLM tool name (required; anonymous executables\n * are rejected at author time, mirroring `.asTool()`).\n * - `description` — the \"when would the model pick this?\" line.\n * - `inputSchema` — opt-in Standard Schema typing the tool's arguments.\n * Surfaced on `WorkflowInstance` / `SupervisorContract` from the new\n * optional `inputSchema` config field. Absent for agents (which take\n * a plain string prompt).\n * - `execute` — the dispatch entry every `ExecutableContract` exposes.\n *\n * `invoke` is declared `never` so a `ToolContract` (which HAS `invoke`)\n * can never be mistaken for an executable by the {@link isExecutableTool}\n * guard.\n */\nexport type ExecutableTool<TInput = unknown, TOutput = unknown> = {\n readonly name: string;\n readonly description?: string;\n readonly inputSchema?: StandardSchemaV1<TInput>;\n execute(input: TInput, options?: unknown): Promise<ExecutableEnvelope<TOutput>>;\n invoke?: never;\n};\n\n/**\n * Entry accepted in an agent's `tools: []` array — either an already-\n * built `ToolContract` (the `.asTool()` / `ai.tool()` path) or a raw\n * executable primitive the framework auto-adapts on the caller's\n * behalf.\n */\nexport type AgentToolEntry<TInput = unknown, TOutput = unknown> =\n | ToolContract<TInput, TOutput>\n | ExecutableTool<TInput, TOutput>;\n\n/**\n * Identity passthrough schema used when an executable is registered as\n * a tool without declaring an `inputSchema`. The model's raw arguments\n * flow straight to `execute()` unchanged — the executable validates\n * internally (workflows via their steps, supervisors/agents via their\n * own input handling).\n */\nfunction passthroughSchema<TInput>(): StandardSchemaV1<TInput> {\n return {\n \"~standard\": {\n version: 1,\n vendor: \"warlock-ai\",\n validate: (value: unknown) => ({ value: value as TInput }),\n },\n };\n}\n\n/**\n * Type guard distinguishing a raw executable primitive from a built\n * `ToolContract`. An executable exposes `execute()` and no `invoke()`;\n * a `ToolContract` exposes `invoke()`. The `invoke` check is the\n * load-bearing discriminator — `.asTool()`-wrapped composites keep\n * their own `execute` too, so checking `execute` alone is insufficient.\n */\nexport function isExecutableTool(entry: unknown): entry is ExecutableTool {\n if (!entry || typeof entry !== \"object\") {\n return false;\n }\n\n const candidate = entry as { execute?: unknown; invoke?: unknown };\n\n return typeof candidate.execute === \"function\" && typeof candidate.invoke !== \"function\";\n}\n\n/**\n * Adapt a raw executable primitive (agent / workflow / supervisor) into\n * a `ToolContract` so an agent can dispatch it inside its tool-call\n * loop WITHOUT the caller writing `.asTool()`. Derives the LLM tool\n * manifest from the executable's own `name` + `description` +\n * (optional) `inputSchema`, then dispatches through the executable's\n * `execute()` — the inner report nests under the outer tool-call node\n * exactly like an explicit `.asTool()` wrapper.\n *\n * Throws `AgentExecutionError` at author time when the executable lacks\n * a usable `name` — the agent's tool surface needs a stable id, the\n * same constraint `.asTool()` enforces.\n */\nexport function executableToTool<TInput, TOutput>(\n executable: ExecutableTool<TInput, TOutput>,\n): ToolContract<TInput, TOutput> {\n if (!executable.name || typeof executable.name !== \"string\") {\n throw new AgentExecutionError(\n \"tools[]: an executable (agent/workflow/supervisor) used as a tool must have a `name`\",\n { context: { authoring: true } },\n );\n }\n\n return compositeAsTool<TInput, TOutput>({\n name: executable.name,\n description: executable.description ?? `Invoke \"${executable.name}\" as a tool.`,\n input: executable.inputSchema ?? passthroughSchema<TInput>(),\n execute: async (input) => {\n const result = await executable.execute(input);\n\n if (result.error) {\n // Surface the inner typed error so the surrounding\n // `compositeAsTool` wrapper produces a `ToolExecutionError`\n // with `cause` pointing back at the original subclass — the\n // agent's tool-call loop sees one uniform error class\n // regardless of which primitive failed.\n throw result.error;\n }\n\n return {\n data: result.data as TOutput,\n usage: result.usage as Usage,\n report: result.report,\n };\n },\n });\n}\n\n/**\n * Normalize an agent's `tools: []` array into a uniform\n * `ToolContract[]` for the runtime. Already-built `ToolContract`s\n * (`.asTool()` / `ai.tool()`) pass through untouched; raw executable\n * primitives are auto-adapted via {@link executableToTool}.\n *\n * Returns `undefined` when no tools were supplied so the agent's\n * existing `config.tools ?? []` fallbacks stay byte-identical.\n */\nexport function normalizeAgentTools(\n tools: ReadonlyArray<AgentToolEntry> | undefined,\n): ToolContract<unknown, unknown>[] | undefined {\n if (!tools) {\n return undefined;\n }\n\n return tools.map((entry) => {\n if (isExecutableTool(entry)) {\n return executableToTool(entry) as ToolContract<unknown, unknown>;\n }\n\n return entry as ToolContract<unknown, unknown>;\n });\n}\n"],"mappings":";;;;;;;;;;;;AAgEA,SAAS,oBAAsD;CAC7D,OAAO,EACL,aAAa;EACX,SAAS;EACT,QAAQ;EACR,WAAW,WAAoB,EAAS,MAAgB;CAC1D,EACF;AACF;;;;;;;;AASA,SAAgB,iBAAiB,OAAyC;CACxE,IAAI,CAAC,SAAS,OAAO,UAAU,UAC7B,OAAO;CAGT,MAAM,YAAY;CAElB,OAAO,OAAO,UAAU,YAAY,cAAc,OAAO,UAAU,WAAW;AAChF;;;;;;;;;;;;;;AAeA,SAAgB,iBACd,YAC+B;CAC/B,IAAI,CAAC,WAAW,QAAQ,OAAO,WAAW,SAAS,UACjD,MAAM,IAAI,oBACR,wFACA,EAAE,SAAS,EAAE,WAAW,KAAK,EAAE,CACjC;CAGF,OAAO,gBAAiC;EACtC,MAAM,WAAW;EACjB,aAAa,WAAW,eAAe,WAAW,WAAW,KAAK;EAClE,OAAO,WAAW,eAAe,kBAA0B;EAC3D,SAAS,OAAO,UAAU;GACxB,MAAM,SAAS,MAAM,WAAW,QAAQ,KAAK;GAE7C,IAAI,OAAO,OAMT,MAAM,OAAO;GAGf,OAAO;IACL,MAAM,OAAO;IACb,OAAO,OAAO;IACd,QAAQ,OAAO;GACjB;EACF;CACF,CAAC;AACH;;;;;;;;;;AAWA,SAAgB,oBACd,OAC8C;CAC9C,IAAI,CAAC,OACH;CAGF,OAAO,MAAM,KAAK,UAAU;EAC1B,IAAI,iBAAiB,KAAK,GACxB,OAAO,iBAAiB,KAAK;EAG/B,OAAO;CACT,CAAC;AACH"}
@@ -1 +1,2 @@
1
- import { ToolContract, ToolInvokeResult, tool } from "./tool.mjs";
1
+ import { ToolContract, ToolInvokeResult, tool } from "./tool.mjs";
2
+ import { AgentToolEntry, ExecutableTool, executableToTool, isExecutableTool, normalizeAgentTools } from "./executable-as-tool.mjs";
@@ -1,3 +1,4 @@
1
1
  import { tool } from "./tool.mjs";
2
+ import { executableToTool, isExecutableTool, normalizeAgentTools } from "./executable-as-tool.mjs";
2
3
 
3
4
  export { };
@@ -18,12 +18,6 @@ import { compositeAsTool } from "../tool/tool.mjs";
18
18
  * `WorkflowError` subclass — the agent's tool-call loop sees a
19
19
  * uniform error class regardless of which primitive failed.
20
20
  *
21
- * **Usage caveat (deferred to Phase 2):** the parent agent's
22
- * `result.usage` does NOT roll up tokens consumed inside the wrapped
23
- * workflow today. Nested-usage standardization lands with the
24
- * supervisor work; until then, sum workflow + agent usage manually if
25
- * you need a combined cost figure.
26
- *
27
21
  * @example
28
22
  * const wf = workflow({ name: "triage", steps: [...] });
29
23
  * const triageTool = asTool(wf, {
@@ -1 +1 @@
1
- {"version":3,"file":"as-tool.mjs","names":[],"sources":["../../../../../../../@warlock.js/ai/src/workflow/as-tool.ts"],"sourcesContent":["import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { WorkflowInstance } from \"../contracts/workflow/workflow.contract\";\nimport { WorkflowError } from \"../errors\";\nimport { compositeAsTool, type ToolContract } from \"../tool/tool\";\n\n/**\n * Wrap a `WorkflowInstance` as a `ToolContract` so an agent can invoke\n * it inside its tool-call loop. Closes the agent-calls-workflow\n * composition gap.\n *\n * Behavior:\n * - Tool `name` mirrors `workflow.name` — workflows without a name throw\n * `WorkflowError` at wrap time (the agent surface needs a stable id).\n * - Tool `input` is the supplied `inputSchema`; the validated value is\n * forwarded straight to `workflow.execute(input)`.\n * - On `result.error`, the workflow error is wrapped in\n * `ToolExecutionError` with `cause` set to the original\n * `WorkflowError` subclass — the agent's tool-call loop sees a\n * uniform error class regardless of which primitive failed.\n *\n * **Usage caveat (deferred to Phase 2):** the parent agent's\n * `result.usage` does NOT roll up tokens consumed inside the wrapped\n * workflow today. Nested-usage standardization lands with the\n * supervisor work; until then, sum workflow + agent usage manually if\n * you need a combined cost figure.\n *\n * @example\n * const wf = workflow({ name: \"triage\", steps: [...] });\n * const triageTool = asTool(wf, {\n * description: \"Run the support-ticket triage flow\",\n * inputSchema: ticketSchema,\n * });\n * const a = ai.agent({ model, tools: [triageTool] });\n */\nexport function asTool<TInput, TOutput, TToolInput = TInput>(\n workflowInstance: WorkflowInstance<TInput, TOutput>,\n options: {\n description?: string;\n inputSchema: StandardSchemaV1<TToolInput>;\n },\n): ToolContract<TToolInput, TOutput> {\n if (!workflowInstance.name || typeof workflowInstance.name !== \"string\") {\n throw new WorkflowError(\n \"workflow.asTool(): workflow must have a `name` to be wrapped as a tool\",\n );\n }\n\n return compositeAsTool<TToolInput, TOutput>({\n name: workflowInstance.name,\n description: options.description ?? `Invoke workflow \"${workflowInstance.name}\" as a tool.`,\n input: options.inputSchema,\n execute: async (input) => {\n const result = await workflowInstance.execute(input as unknown as TInput);\n\n if (result.error) {\n // Throw the workflow error so the surrounding wrapper catches\n // it and produces a `ToolExecutionError` with `cause` pointing\n // back at the original `WorkflowError` subclass — keeps the\n // agent's tool-call loop seeing one uniform error class\n // regardless of which primitive failed.\n throw result.error;\n }\n\n return {\n data: result.data as TOutput,\n usage: result.usage,\n report: result.report,\n };\n },\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,SAAgB,OACd,kBACA,SAImC;CACnC,IAAI,CAAC,iBAAiB,QAAQ,OAAO,iBAAiB,SAAS,UAC7D,MAAM,IAAI,cACR,wEACF;CAGF,OAAO,gBAAqC;EAC1C,MAAM,iBAAiB;EACvB,aAAa,QAAQ,eAAe,oBAAoB,iBAAiB,KAAK;EAC9E,OAAO,QAAQ;EACf,SAAS,OAAO,UAAU;GACxB,MAAM,SAAS,MAAM,iBAAiB,QAAQ,KAA0B;GAExE,IAAI,OAAO,OAMT,MAAM,OAAO;GAGf,OAAO;IACL,MAAM,OAAO;IACb,OAAO,OAAO;IACd,QAAQ,OAAO;GACjB;EACF;CACF,CAAC;AACH"}
1
+ {"version":3,"file":"as-tool.mjs","names":[],"sources":["../../../../../../../@warlock.js/ai/src/workflow/as-tool.ts"],"sourcesContent":["import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { WorkflowInstance } from \"../contracts/workflow/workflow.contract\";\nimport { WorkflowError } from \"../errors\";\nimport { compositeAsTool, type ToolContract } from \"../tool/tool\";\n\n/**\n * Wrap a `WorkflowInstance` as a `ToolContract` so an agent can invoke\n * it inside its tool-call loop. Closes the agent-calls-workflow\n * composition gap.\n *\n * Behavior:\n * - Tool `name` mirrors `workflow.name` — workflows without a name throw\n * `WorkflowError` at wrap time (the agent surface needs a stable id).\n * - Tool `input` is the supplied `inputSchema`; the validated value is\n * forwarded straight to `workflow.execute(input)`.\n * - On `result.error`, the workflow error is wrapped in\n * `ToolExecutionError` with `cause` set to the original\n * `WorkflowError` subclass — the agent's tool-call loop sees a\n * uniform error class regardless of which primitive failed.\n *\n * @example\n * const wf = workflow({ name: \"triage\", steps: [...] });\n * const triageTool = asTool(wf, {\n * description: \"Run the support-ticket triage flow\",\n * inputSchema: ticketSchema,\n * });\n * const a = ai.agent({ model, tools: [triageTool] });\n */\nexport function asTool<TInput, TOutput, TToolInput = TInput>(\n workflowInstance: WorkflowInstance<TInput, TOutput>,\n options: {\n description?: string;\n inputSchema: StandardSchemaV1<TToolInput>;\n },\n): ToolContract<TToolInput, TOutput> {\n if (!workflowInstance.name || typeof workflowInstance.name !== \"string\") {\n throw new WorkflowError(\n \"workflow.asTool(): workflow must have a `name` to be wrapped as a tool\",\n );\n }\n\n return compositeAsTool<TToolInput, TOutput>({\n name: workflowInstance.name,\n description: options.description ?? `Invoke workflow \"${workflowInstance.name}\" as a tool.`,\n input: options.inputSchema,\n execute: async (input) => {\n const result = await workflowInstance.execute(input as unknown as TInput);\n\n if (result.error) {\n // Throw the workflow error so the surrounding wrapper catches\n // it and produces a `ToolExecutionError` with `cause` pointing\n // back at the original `WorkflowError` subclass — keeps the\n // agent's tool-call loop seeing one uniform error class\n // regardless of which primitive failed.\n throw result.error;\n }\n\n return {\n data: result.data as TOutput,\n usage: result.usage,\n report: result.report,\n };\n },\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,SAAgB,OACd,kBACA,SAImC;CACnC,IAAI,CAAC,iBAAiB,QAAQ,OAAO,iBAAiB,SAAS,UAC7D,MAAM,IAAI,cACR,wEACF;CAGF,OAAO,gBAAqC;EAC1C,MAAM,iBAAiB;EACvB,aAAa,QAAQ,eAAe,oBAAoB,iBAAiB,KAAK;EAC9E,OAAO,QAAQ;EACf,SAAS,OAAO,UAAU;GACxB,MAAM,SAAS,MAAM,iBAAiB,QAAQ,KAA0B;GAExE,IAAI,OAAO,OAMT,MAAM,OAAO;GAGf,OAAO;IACL,MAAM,OAAO;IACb,OAAO,OAAO;IACd,QAAQ,OAAO;GACjB;EACF;CACF,CAAC;AACH"}
@@ -8,11 +8,11 @@ import "../errors/index.mjs";
8
8
  import { stampReportLineage } from "../utils/stamp-report-lineage.mjs";
9
9
  import "../utils/index.mjs";
10
10
  import { createCancelledError } from "./cancellation.mjs";
11
+ import { cloneState, deepFreeze } from "./state.mjs";
12
+ import { executeStep, finalizeSnapshot, toAIError } from "./step-runner.mjs";
11
13
  import { mapNextStep, nextDeclaredStep, resolveNextStep } from "./router.mjs";
12
14
  import { runScopedEmitter } from "./run-scoped-emitter.mjs";
13
15
  import { loadSnapshotForResume, persistSnapshot } from "./snapshot.mjs";
14
- import { cloneState, deepFreeze } from "./state.mjs";
15
- import { executeStep, finalizeSnapshot, toAIError } from "./step-runner.mjs";
16
16
  import { log } from "@warlock.js/logger";
17
17
 
18
18
  //#region ../@warlock.js/ai/src/workflow/engine.ts
@@ -1,16 +1,22 @@
1
1
  import { WorkflowError } from "../errors/workflow-error.mjs";
2
2
  import { WorkflowDriftError } from "../errors/workflow-drift-error.mjs";
3
3
  import "../errors/index.mjs";
4
- import { resolveDefaultStore } from "../config.mjs";
4
+ import { resolveDefaultSnapshotStore } from "../config.mjs";
5
5
 
6
6
  //#region ../@warlock.js/ai/src/workflow/snapshot.ts
7
7
  /**
8
- * Resolve the effective snapshot store: the workflow's own
8
+ * Resolve the effective {@link SnapshotStore}: the workflow's own
9
9
  * `snapshotStore` field wins; absent that, fall back to the global
10
- * default set via `ai.config({ defaultStore })`.
10
+ * default set via `ai.config({ defaultSnapshotStore })`.
11
+ *
12
+ * The global default is typed for the supervisor snapshot shape, but
13
+ * every store impl keys purely by `runId` and round-trips whatever
14
+ * envelope it is handed — so it serves a `WorkflowSnapshot` just as
15
+ * well. The cast re-tags the shape at this single boundary; the
16
+ * workflow only ever hands it a `WorkflowSnapshot`.
11
17
  */
12
18
  function resolveSnapshotStore(definition) {
13
- return definition.snapshotStore ?? resolveDefaultStore();
19
+ return definition.snapshotStore ?? resolveDefaultSnapshotStore();
14
20
  }
15
21
  /**
16
22
  * Write the current run's state to the configured `KVStore`. Returns
@@ -38,7 +44,7 @@ async function persistSnapshot(params) {
38
44
  savedAt: (/* @__PURE__ */ new Date()).toISOString()
39
45
  };
40
46
  try {
41
- await store.set(params.runId, snapshot);
47
+ await store.save(snapshot);
42
48
  return { ok: true };
43
49
  } catch (err) {
44
50
  return {
@@ -55,8 +61,8 @@ async function persistSnapshot(params) {
55
61
  */
56
62
  async function loadSnapshotForResume(params) {
57
63
  const store = resolveSnapshotStore(params.definition);
58
- if (!store) throw new WorkflowError(`workflow "${params.definition.name}" has no store configured — set \`snapshotStore\` on the definition or call \`ai.config({ defaultStore })\` at boot before calling resume()`);
59
- const snap = await store.get(params.runId) ?? null;
64
+ if (!store) throw new WorkflowError(`workflow "${params.definition.name}" has no store configured — set \`snapshotStore\` on the definition or call \`ai.config({ defaultSnapshotStore })\` at boot before calling resume()`);
65
+ const snap = await store.load(params.runId) ?? null;
60
66
  if (!snap) throw new WorkflowError(`workflow "${params.definition.name}": no snapshot for runId "${params.runId}"`);
61
67
  if (!params.options?.force && snap.signature !== params.signature) throw new WorkflowDriftError(`workflow "${params.definition.name}" signature drift on resume`, {
62
68
  savedSignature: snap.signature,
@@ -1 +1 @@
1
- {"version":3,"file":"snapshot.mjs","names":[],"sources":["../../../../../../../@warlock.js/ai/src/workflow/snapshot.ts"],"sourcesContent":["import { resolveDefaultStore } from \"../config\";\nimport type { StepSnapshot } from \"../contracts/result/step-result.type\";\nimport type { WorkflowSnapshot } from \"../contracts/workflow/workflow-snapshot.type\";\nimport type {\n WorkflowDefinition,\n WorkflowResumeOptions,\n} from \"../contracts/workflow/workflow.contract\";\nimport { WorkflowDriftError, WorkflowError } from \"../errors\";\n\n/**\n * Resolve the effective snapshot store: the workflow's own\n * `snapshotStore` field wins; absent that, fall back to the global\n * default set via `ai.config({ defaultStore })`.\n */\nfunction resolveSnapshotStore<T>(definition: WorkflowDefinition<any, T, any, any>) {\n return definition.snapshotStore ?? resolveDefaultStore();\n}\n\nexport type PersistParams<T> = {\n definition: WorkflowDefinition<any, T, any, any>;\n signature: string;\n runId: string;\n startedAt: string;\n input: unknown;\n state: Record<string, unknown>;\n steps: Record<string, StepSnapshot>;\n next: string | null;\n status: WorkflowSnapshot[\"status\"];\n};\n\nexport type PersistOutcome = { ok: true } | { ok: false; error: unknown };\n\n/**\n * Write the current run's state to the configured `KVStore`. Returns\n * an outcome object instead of throwing so the engine can surface\n * persistence failures via events + logs without aborting the run.\n * Callers decide whether a failed checkpoint is fatal.\n *\n * No-op (returns `{ ok: true }`) when the workflow has no store\n * configured — the common in-memory test case.\n */\nexport async function persistSnapshot<T>(\n params: PersistParams<T>,\n): Promise<PersistOutcome> {\n const store = resolveSnapshotStore(params.definition);\n\n if (!store) return { ok: true };\n\n const snapshot: WorkflowSnapshot = {\n runId: params.runId,\n workflowName: params.definition.name,\n signature: params.signature,\n version: params.definition.version,\n input: params.input,\n state: { ...params.state },\n steps: { ...params.steps },\n next: params.next,\n status: params.status,\n startedAt: params.startedAt,\n savedAt: new Date().toISOString(),\n };\n\n try {\n await store.set(params.runId, snapshot);\n return { ok: true };\n } catch (err) {\n return { ok: false, error: err };\n }\n}\n\n/**\n * Load a prior run's snapshot from the store and run the drift\n * check. Throws `WorkflowError` when no snapshot exists, and\n * `WorkflowDriftError` when the stored signature doesn't match the\n * current definition (unless `force` is set).\n */\nexport async function loadSnapshotForResume<T>(params: {\n definition: WorkflowDefinition<any, T, any, any>;\n signature: string;\n runId: string;\n options?: WorkflowResumeOptions;\n}): Promise<WorkflowSnapshot> {\n const store = resolveSnapshotStore(params.definition);\n\n if (!store) {\n throw new WorkflowError(\n `workflow \"${params.definition.name}\" has no store configured — set \\`snapshotStore\\` on the definition or call \\`ai.config({ defaultStore })\\` at boot before calling resume()`,\n );\n }\n\n const snap = (await store.get<WorkflowSnapshot>(params.runId)) ?? null;\n\n if (!snap) {\n throw new WorkflowError(\n `workflow \"${params.definition.name}\": no snapshot for runId \"${params.runId}\"`,\n );\n }\n\n if (!params.options?.force && snap.signature !== params.signature) {\n throw new WorkflowDriftError(\n `workflow \"${params.definition.name}\" signature drift on resume`,\n {\n savedSignature: snap.signature,\n currentSignature: params.signature,\n runId: params.runId,\n },\n );\n }\n\n return snap;\n}\n"],"mappings":";;;;;;;;;;;AAcA,SAAS,qBAAwB,YAAkD;CACjF,OAAO,WAAW,iBAAiB,oBAAoB;AACzD;;;;;;;;;;AAyBA,eAAsB,gBACpB,QACyB;CACzB,MAAM,QAAQ,qBAAqB,OAAO,UAAU;CAEpD,IAAI,CAAC,OAAO,OAAO,EAAE,IAAI,KAAK;CAE9B,MAAM,WAA6B;EACjC,OAAO,OAAO;EACd,cAAc,OAAO,WAAW;EAChC,WAAW,OAAO;EAClB,SAAS,OAAO,WAAW;EAC3B,OAAO,OAAO;EACd,OAAO,EAAE,GAAG,OAAO,MAAM;EACzB,OAAO,EAAE,GAAG,OAAO,MAAM;EACzB,MAAM,OAAO;EACb,QAAQ,OAAO;EACf,WAAW,OAAO;EAClB,0BAAS,IAAI,KAAK,EAAC,CAAC,YAAY;CAClC;CAEA,IAAI;EACF,MAAM,MAAM,IAAI,OAAO,OAAO,QAAQ;EACtC,OAAO,EAAE,IAAI,KAAK;CACpB,SAAS,KAAK;EACZ,OAAO;GAAE,IAAI;GAAO,OAAO;EAAI;CACjC;AACF;;;;;;;AAQA,eAAsB,sBAAyB,QAKjB;CAC5B,MAAM,QAAQ,qBAAqB,OAAO,UAAU;CAEpD,IAAI,CAAC,OACH,MAAM,IAAI,cACR,aAAa,OAAO,WAAW,KAAK,4IACtC;CAGF,MAAM,OAAQ,MAAM,MAAM,IAAsB,OAAO,KAAK,KAAM;CAElE,IAAI,CAAC,MACH,MAAM,IAAI,cACR,aAAa,OAAO,WAAW,KAAK,4BAA4B,OAAO,MAAM,EAC/E;CAGF,IAAI,CAAC,OAAO,SAAS,SAAS,KAAK,cAAc,OAAO,WACtD,MAAM,IAAI,mBACR,aAAa,OAAO,WAAW,KAAK,8BACpC;EACE,gBAAgB,KAAK;EACrB,kBAAkB,OAAO;EACzB,OAAO,OAAO;CAChB,CACF;CAGF,OAAO;AACT"}
1
+ {"version":3,"file":"snapshot.mjs","names":[],"sources":["../../../../../../../@warlock.js/ai/src/workflow/snapshot.ts"],"sourcesContent":["import { resolveDefaultSnapshotStore } from \"../config\";\nimport type { SnapshotStore } from \"../contracts/orchestrator/snapshot-store.contract\";\nimport type { StepSnapshot } from \"../contracts/result/step-result.type\";\nimport type { WorkflowSnapshot } from \"../contracts/workflow/workflow-snapshot.type\";\nimport type {\n WorkflowDefinition,\n WorkflowResumeOptions,\n} from \"../contracts/workflow/workflow.contract\";\nimport { WorkflowDriftError, WorkflowError } from \"../errors\";\n\n/**\n * Resolve the effective {@link SnapshotStore}: the workflow's own\n * `snapshotStore` field wins; absent that, fall back to the global\n * default set via `ai.config({ defaultSnapshotStore })`.\n *\n * The global default is typed for the supervisor snapshot shape, but\n * every store impl keys purely by `runId` and round-trips whatever\n * envelope it is handed — so it serves a `WorkflowSnapshot` just as\n * well. The cast re-tags the shape at this single boundary; the\n * workflow only ever hands it a `WorkflowSnapshot`.\n */\nfunction resolveSnapshotStore<T>(\n definition: WorkflowDefinition<any, T, any, any>,\n): SnapshotStore<WorkflowSnapshot> | undefined {\n return (\n definition.snapshotStore ??\n (resolveDefaultSnapshotStore() as SnapshotStore<WorkflowSnapshot> | undefined)\n );\n}\n\nexport type PersistParams<T> = {\n definition: WorkflowDefinition<any, T, any, any>;\n signature: string;\n runId: string;\n startedAt: string;\n input: unknown;\n state: Record<string, unknown>;\n steps: Record<string, StepSnapshot>;\n next: string | null;\n status: WorkflowSnapshot[\"status\"];\n};\n\nexport type PersistOutcome = { ok: true } | { ok: false; error: unknown };\n\n/**\n * Write the current run's state to the configured `KVStore`. Returns\n * an outcome object instead of throwing so the engine can surface\n * persistence failures via events + logs without aborting the run.\n * Callers decide whether a failed checkpoint is fatal.\n *\n * No-op (returns `{ ok: true }`) when the workflow has no store\n * configured — the common in-memory test case.\n */\nexport async function persistSnapshot<T>(\n params: PersistParams<T>,\n): Promise<PersistOutcome> {\n const store = resolveSnapshotStore(params.definition);\n\n if (!store) return { ok: true };\n\n const snapshot: WorkflowSnapshot = {\n runId: params.runId,\n workflowName: params.definition.name,\n signature: params.signature,\n version: params.definition.version,\n input: params.input,\n state: { ...params.state },\n steps: { ...params.steps },\n next: params.next,\n status: params.status,\n startedAt: params.startedAt,\n savedAt: new Date().toISOString(),\n };\n\n try {\n await store.save(snapshot);\n return { ok: true };\n } catch (err) {\n return { ok: false, error: err };\n }\n}\n\n/**\n * Load a prior run's snapshot from the store and run the drift\n * check. Throws `WorkflowError` when no snapshot exists, and\n * `WorkflowDriftError` when the stored signature doesn't match the\n * current definition (unless `force` is set).\n */\nexport async function loadSnapshotForResume<T>(params: {\n definition: WorkflowDefinition<any, T, any, any>;\n signature: string;\n runId: string;\n options?: WorkflowResumeOptions;\n}): Promise<WorkflowSnapshot> {\n const store = resolveSnapshotStore(params.definition);\n\n if (!store) {\n throw new WorkflowError(\n `workflow \"${params.definition.name}\" has no store configured — set \\`snapshotStore\\` on the definition or call \\`ai.config({ defaultSnapshotStore })\\` at boot before calling resume()`,\n );\n }\n\n const snap = (await store.load(params.runId)) ?? null;\n\n if (!snap) {\n throw new WorkflowError(\n `workflow \"${params.definition.name}\": no snapshot for runId \"${params.runId}\"`,\n );\n }\n\n if (!params.options?.force && snap.signature !== params.signature) {\n throw new WorkflowDriftError(\n `workflow \"${params.definition.name}\" signature drift on resume`,\n {\n savedSignature: snap.signature,\n currentSignature: params.signature,\n runId: params.runId,\n },\n );\n }\n\n return snap;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAqBA,SAAS,qBACP,YAC6C;CAC7C,OACE,WAAW,iBACV,4BAA4B;AAEjC;;;;;;;;;;AAyBA,eAAsB,gBACpB,QACyB;CACzB,MAAM,QAAQ,qBAAqB,OAAO,UAAU;CAEpD,IAAI,CAAC,OAAO,OAAO,EAAE,IAAI,KAAK;CAE9B,MAAM,WAA6B;EACjC,OAAO,OAAO;EACd,cAAc,OAAO,WAAW;EAChC,WAAW,OAAO;EAClB,SAAS,OAAO,WAAW;EAC3B,OAAO,OAAO;EACd,OAAO,EAAE,GAAG,OAAO,MAAM;EACzB,OAAO,EAAE,GAAG,OAAO,MAAM;EACzB,MAAM,OAAO;EACb,QAAQ,OAAO;EACf,WAAW,OAAO;EAClB,0BAAS,IAAI,KAAK,EAAC,CAAC,YAAY;CAClC;CAEA,IAAI;EACF,MAAM,MAAM,KAAK,QAAQ;EACzB,OAAO,EAAE,IAAI,KAAK;CACpB,SAAS,KAAK;EACZ,OAAO;GAAE,IAAI;GAAO,OAAO;EAAI;CACjC;AACF;;;;;;;AAQA,eAAsB,sBAAyB,QAKjB;CAC5B,MAAM,QAAQ,qBAAqB,OAAO,UAAU;CAEpD,IAAI,CAAC,OACH,MAAM,IAAI,cACR,aAAa,OAAO,WAAW,KAAK,oJACtC;CAGF,MAAM,OAAQ,MAAM,MAAM,KAAK,OAAO,KAAK,KAAM;CAEjD,IAAI,CAAC,MACH,MAAM,IAAI,cACR,aAAa,OAAO,WAAW,KAAK,4BAA4B,OAAO,MAAM,EAC/E;CAGF,IAAI,CAAC,OAAO,SAAS,SAAS,KAAK,cAAc,OAAO,WACtD,MAAM,IAAI,mBACR,aAAa,OAAO,WAAW,KAAK,8BACpC;EACE,gBAAgB,KAAK;EACrB,kBAAkB,OAAO;EACzB,OAAO,OAAO;CAChB,CACF;CAGF,OAAO;AACT"}
@@ -4,9 +4,9 @@ import { SchemaValidationError } from "../errors/schema-validation-error.mjs";
4
4
  import { StepFailedError } from "../errors/step-failed-error.mjs";
5
5
  import { WorkflowCancelledError } from "../errors/workflow-cancelled-error.mjs";
6
6
  import "../errors/index.mjs";
7
+ import { isAbortError, resolveBackoff, resolveRetryConfig } from "./retry.mjs";
7
8
  import { createCancelledError, sleep } from "./cancellation.mjs";
8
9
  import { cloneState, deepFreeze } from "./state.mjs";
9
- import { isAbortError, resolveBackoff, resolveRetryConfig } from "./retry.mjs";
10
10
 
11
11
  //#region ../@warlock.js/ai/src/workflow/step-runner.ts
12
12
  /**
@@ -54,6 +54,7 @@ function workflow(definition) {
54
54
  const instance = {
55
55
  name: definition.name,
56
56
  description: definition.description,
57
+ inputSchema: definition.inputSchema,
57
58
  signature,
58
59
  version: definition.version,
59
60
  execute,
@@ -1 +1 @@
1
- {"version":3,"file":"workflow.mjs","names":["combined"],"sources":["../../../../../../../@warlock.js/ai/src/workflow/workflow.ts"],"sourcesContent":["import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { WorkflowEventMap } from \"../contracts/events/event-map.type\";\nimport type { WorkflowResult } from \"../contracts/result/workflow-result.type\";\nimport type {\n WorkflowDefinition,\n WorkflowEventHandler,\n WorkflowExecuteOptions,\n WorkflowInstance,\n WorkflowResumeOptions,\n WorkflowRunOptions,\n} from \"../contracts/workflow/workflow.contract\";\nimport { WorkflowError } from \"../errors\";\nimport type { ToolContract } from \"../tool/tool\";\nimport { asTool } from \"./as-tool\";\nimport { WorkflowEmitter } from \"./emitter\";\nimport { loadSnapshotForResume, runWorkflow } from \"./engine\";\nimport { computeSignature } from \"./signature\";\n\n/**\n * `ai.workflow(def)` — construct a `WorkflowInstance`. Validates the\n * definition, computes a stable structural signature, and wires up the\n * three-tier event subscription model.\n */\nexport function workflow<\n TInput = unknown,\n TOutput = unknown,\n TState = Record<string, unknown>,\n TContext = unknown,\n>(\n definition: WorkflowDefinition<TInput, TOutput, TState, TContext>,\n): WorkflowInstance<TInput, TOutput, TState, TContext> {\n validate(definition);\n const signature = computeSignature(definition);\n const emitter = new WorkflowEmitter(definition.on);\n\n function execute(\n inputOrOptions: TInput | WorkflowExecuteOptions<TInput, TContext>,\n maybeOptions?: WorkflowRunOptions<TContext>,\n ): Promise<WorkflowResult<TOutput>> {\n const { input, options } = normalizeExecuteArgs<TInput, TContext>(\n inputOrOptions,\n maybeOptions,\n );\n const runId = options?.runId ?? generateRunId();\n return runWorkflow<TOutput>({\n definition,\n signature,\n emitter,\n input,\n context: options?.context,\n runId,\n signal: options?.signal,\n executionHandlers: options?.on,\n sessionId: options?.sessionId,\n });\n }\n\n async function resume(\n runId: string,\n options?: WorkflowResumeOptions<TContext>,\n ): Promise<WorkflowResult<TOutput>> {\n const snapshot = await loadSnapshotForResume({\n definition,\n signature,\n runId,\n options,\n });\n\n return runWorkflow<TOutput>({\n definition,\n signature,\n emitter,\n input: snapshot.input,\n context: options?.context,\n runId,\n signal: options?.signal,\n executionHandlers: options?.on,\n sessionId: options?.sessionId,\n resumeFrom: snapshot,\n });\n }\n\n const instance: WorkflowInstance<TInput, TOutput, TState, TContext> = {\n name: definition.name,\n description: definition.description,\n signature,\n version: definition.version,\n execute,\n resume,\n on<K extends keyof WorkflowEventMap>(event: K, handler: WorkflowEventHandler<K>) {\n return emitter.on(event, handler);\n },\n off<K extends keyof WorkflowEventMap>(event: K, handler: WorkflowEventHandler<K>) {\n emitter.off(event, handler);\n },\n asTool<TToolInput = TInput>(options: {\n description?: string;\n inputSchema: StandardSchemaV1<TToolInput>;\n }): ToolContract<TToolInput, TOutput> {\n return asTool<TInput, TOutput, TToolInput>(instance, options);\n },\n };\n\n return instance;\n}\n\n/**\n * Resolve the overloaded `execute()` call shape. If the caller passed\n * a single plain object with an `input` field, treat it as the\n * combined `WorkflowExecuteOptions`. Otherwise the first arg is the\n * raw workflow input and the second is the run options.\n *\n * Ambiguity note: if your real workflow `input` is itself an object\n * with a top-level `input` key, prefer `execute(rawInput, options)`\n * explicitly — the single-arg detection heuristic would mis-classify\n * it.\n */\nfunction normalizeExecuteArgs<TInput, TContext>(\n inputOrOptions: TInput | WorkflowExecuteOptions<TInput, TContext>,\n maybeOptions: WorkflowRunOptions<TContext> | undefined,\n): { input: TInput; options?: WorkflowRunOptions<TContext> } {\n if (\n maybeOptions === undefined &&\n inputOrOptions !== null &&\n typeof inputOrOptions === \"object\" &&\n \"input\" in (inputOrOptions as object)\n ) {\n const combined = inputOrOptions as WorkflowExecuteOptions<TInput, TContext>;\n const { input, ...options } = combined;\n return { input, options };\n }\n\n return { input: inputOrOptions as TInput, options: maybeOptions };\n}\n\nfunction validate<TInput, TOutput, TState, TContext>(\n definition: WorkflowDefinition<TInput, TOutput, TState, TContext>,\n): void {\n if (!definition.name || typeof definition.name !== \"string\") {\n throw new WorkflowError(\"ai.workflow: `name` is required\");\n }\n\n if (!Array.isArray(definition.steps) || definition.steps.length === 0) {\n throw new WorkflowError(`ai.workflow(\"${definition.name}\"): at least one step is required`);\n }\n\n const seen = new Set<string>();\n const walk = (name: string) => {\n if (seen.has(name)) {\n throw new WorkflowError(`ai.workflow(\"${definition.name}\"): duplicate step name \"${name}\"`);\n }\n seen.add(name);\n };\n\n for (const step of definition.steps) {\n walk(step.name);\n\n if (step.parallel) {\n for (const child of step.parallel) {\n walk(child.name);\n }\n }\n }\n}\n\nfunction generateRunId(): string {\n // Non-crypto random — adequate for ephemeral workflow runs.\n return `wf_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 10)}`;\n}\n"],"mappings":";;;;;;;;;;;;;;AAuBA,SAAgB,SAMd,YACqD;CACrD,SAAS,UAAU;CACnB,MAAM,YAAY,iBAAiB,UAAU;CAC7C,MAAM,UAAU,IAAI,gBAAgB,WAAW,EAAE;CAEjD,SAAS,QACP,gBACA,cACkC;EAClC,MAAM,EAAE,OAAO,YAAY,qBACzB,gBACA,YACF;EACA,MAAM,QAAQ,SAAS,SAAS,cAAc;EAC9C,OAAO,YAAqB;GAC1B;GACA;GACA;GACA;GACA,SAAS,SAAS;GAClB;GACA,QAAQ,SAAS;GACjB,mBAAmB,SAAS;GAC5B,WAAW,SAAS;EACtB,CAAC;CACH;CAEA,eAAe,OACb,OACA,SACkC;EAClC,MAAM,WAAW,MAAM,sBAAsB;GAC3C;GACA;GACA;GACA;EACF,CAAC;EAED,OAAO,YAAqB;GAC1B;GACA;GACA;GACA,OAAO,SAAS;GAChB,SAAS,SAAS;GAClB;GACA,QAAQ,SAAS;GACjB,mBAAmB,SAAS;GAC5B,WAAW,SAAS;GACpB,YAAY;EACd,CAAC;CACH;CAEA,MAAM,WAAgE;EACpE,MAAM,WAAW;EACjB,aAAa,WAAW;EACxB;EACA,SAAS,WAAW;EACpB;EACA;EACA,GAAqC,OAAU,SAAkC;GAC/E,OAAO,QAAQ,GAAG,OAAO,OAAO;EAClC;EACA,IAAsC,OAAU,SAAkC;GAChF,QAAQ,IAAI,OAAO,OAAO;EAC5B;EACA,OAA4B,SAGU;GACpC,OAAO,OAAoC,UAAU,OAAO;EAC9D;CACF;CAEA,OAAO;AACT;;;;;;;;;;;;AAaA,SAAS,qBACP,gBACA,cAC2D;CAC3D,IACE,iBAAiB,UACjB,mBAAmB,QACnB,OAAO,mBAAmB,YAC1B,WAAY,gBACZ;EAEA,MAAM,EAAE,OAAO,GAAG,YAAYA;EAC9B,OAAO;GAAE;GAAO;EAAQ;CAC1B;CAEA,OAAO;EAAE,OAAO;EAA0B,SAAS;CAAa;AAClE;AAEA,SAAS,SACP,YACM;CACN,IAAI,CAAC,WAAW,QAAQ,OAAO,WAAW,SAAS,UACjD,MAAM,IAAI,cAAc,iCAAiC;CAG3D,IAAI,CAAC,MAAM,QAAQ,WAAW,KAAK,KAAK,WAAW,MAAM,WAAW,GAClE,MAAM,IAAI,cAAc,gBAAgB,WAAW,KAAK,kCAAkC;CAG5F,MAAM,uBAAO,IAAI,IAAY;CAC7B,MAAM,QAAQ,SAAiB;EAC7B,IAAI,KAAK,IAAI,IAAI,GACf,MAAM,IAAI,cAAc,gBAAgB,WAAW,KAAK,2BAA2B,KAAK,EAAE;EAE5F,KAAK,IAAI,IAAI;CACf;CAEA,KAAK,MAAM,QAAQ,WAAW,OAAO;EACnC,KAAK,KAAK,IAAI;EAEd,IAAI,KAAK,UACP,KAAK,MAAM,SAAS,KAAK,UACvB,KAAK,MAAM,IAAI;CAGrB;AACF;AAEA,SAAS,gBAAwB;CAE/B,OAAO,MAAM,KAAK,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,GAAG,KAAK,OAAO,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,MAAM,GAAG,EAAE;AAChF"}
1
+ {"version":3,"file":"workflow.mjs","names":["combined"],"sources":["../../../../../../../@warlock.js/ai/src/workflow/workflow.ts"],"sourcesContent":["import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { WorkflowEventMap } from \"../contracts/events/event-map.type\";\nimport type { WorkflowResult } from \"../contracts/result/workflow-result.type\";\nimport type {\n WorkflowDefinition,\n WorkflowEventHandler,\n WorkflowExecuteOptions,\n WorkflowInstance,\n WorkflowResumeOptions,\n WorkflowRunOptions,\n} from \"../contracts/workflow/workflow.contract\";\nimport { WorkflowError } from \"../errors\";\nimport type { ToolContract } from \"../tool/tool\";\nimport { asTool } from \"./as-tool\";\nimport { WorkflowEmitter } from \"./emitter\";\nimport { loadSnapshotForResume, runWorkflow } from \"./engine\";\nimport { computeSignature } from \"./signature\";\n\n/**\n * `ai.workflow(def)` — construct a `WorkflowInstance`. Validates the\n * definition, computes a stable structural signature, and wires up the\n * three-tier event subscription model.\n */\nexport function workflow<\n TInput = unknown,\n TOutput = unknown,\n TState = Record<string, unknown>,\n TContext = unknown,\n>(\n definition: WorkflowDefinition<TInput, TOutput, TState, TContext>,\n): WorkflowInstance<TInput, TOutput, TState, TContext> {\n validate(definition);\n const signature = computeSignature(definition);\n const emitter = new WorkflowEmitter(definition.on);\n\n function execute(\n inputOrOptions: TInput | WorkflowExecuteOptions<TInput, TContext>,\n maybeOptions?: WorkflowRunOptions<TContext>,\n ): Promise<WorkflowResult<TOutput>> {\n const { input, options } = normalizeExecuteArgs<TInput, TContext>(\n inputOrOptions,\n maybeOptions,\n );\n const runId = options?.runId ?? generateRunId();\n return runWorkflow<TOutput>({\n definition,\n signature,\n emitter,\n input,\n context: options?.context,\n runId,\n signal: options?.signal,\n executionHandlers: options?.on,\n sessionId: options?.sessionId,\n });\n }\n\n async function resume(\n runId: string,\n options?: WorkflowResumeOptions<TContext>,\n ): Promise<WorkflowResult<TOutput>> {\n const snapshot = await loadSnapshotForResume({\n definition,\n signature,\n runId,\n options,\n });\n\n return runWorkflow<TOutput>({\n definition,\n signature,\n emitter,\n input: snapshot.input,\n context: options?.context,\n runId,\n signal: options?.signal,\n executionHandlers: options?.on,\n sessionId: options?.sessionId,\n resumeFrom: snapshot,\n });\n }\n\n const instance: WorkflowInstance<TInput, TOutput, TState, TContext> = {\n name: definition.name,\n description: definition.description,\n inputSchema: definition.inputSchema,\n signature,\n version: definition.version,\n execute,\n resume,\n on<K extends keyof WorkflowEventMap>(event: K, handler: WorkflowEventHandler<K>) {\n return emitter.on(event, handler);\n },\n off<K extends keyof WorkflowEventMap>(event: K, handler: WorkflowEventHandler<K>) {\n emitter.off(event, handler);\n },\n asTool<TToolInput = TInput>(options: {\n description?: string;\n inputSchema: StandardSchemaV1<TToolInput>;\n }): ToolContract<TToolInput, TOutput> {\n return asTool<TInput, TOutput, TToolInput>(instance, options);\n },\n };\n\n return instance;\n}\n\n/**\n * Resolve the overloaded `execute()` call shape. If the caller passed\n * a single plain object with an `input` field, treat it as the\n * combined `WorkflowExecuteOptions`. Otherwise the first arg is the\n * raw workflow input and the second is the run options.\n *\n * Ambiguity note: if your real workflow `input` is itself an object\n * with a top-level `input` key, prefer `execute(rawInput, options)`\n * explicitly — the single-arg detection heuristic would mis-classify\n * it.\n */\nfunction normalizeExecuteArgs<TInput, TContext>(\n inputOrOptions: TInput | WorkflowExecuteOptions<TInput, TContext>,\n maybeOptions: WorkflowRunOptions<TContext> | undefined,\n): { input: TInput; options?: WorkflowRunOptions<TContext> } {\n if (\n maybeOptions === undefined &&\n inputOrOptions !== null &&\n typeof inputOrOptions === \"object\" &&\n \"input\" in (inputOrOptions as object)\n ) {\n const combined = inputOrOptions as WorkflowExecuteOptions<TInput, TContext>;\n const { input, ...options } = combined;\n return { input, options };\n }\n\n return { input: inputOrOptions as TInput, options: maybeOptions };\n}\n\nfunction validate<TInput, TOutput, TState, TContext>(\n definition: WorkflowDefinition<TInput, TOutput, TState, TContext>,\n): void {\n if (!definition.name || typeof definition.name !== \"string\") {\n throw new WorkflowError(\"ai.workflow: `name` is required\");\n }\n\n if (!Array.isArray(definition.steps) || definition.steps.length === 0) {\n throw new WorkflowError(`ai.workflow(\"${definition.name}\"): at least one step is required`);\n }\n\n const seen = new Set<string>();\n const walk = (name: string) => {\n if (seen.has(name)) {\n throw new WorkflowError(`ai.workflow(\"${definition.name}\"): duplicate step name \"${name}\"`);\n }\n seen.add(name);\n };\n\n for (const step of definition.steps) {\n walk(step.name);\n\n if (step.parallel) {\n for (const child of step.parallel) {\n walk(child.name);\n }\n }\n }\n}\n\nfunction generateRunId(): string {\n // Non-crypto random — adequate for ephemeral workflow runs.\n return `wf_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 10)}`;\n}\n"],"mappings":";;;;;;;;;;;;;;AAuBA,SAAgB,SAMd,YACqD;CACrD,SAAS,UAAU;CACnB,MAAM,YAAY,iBAAiB,UAAU;CAC7C,MAAM,UAAU,IAAI,gBAAgB,WAAW,EAAE;CAEjD,SAAS,QACP,gBACA,cACkC;EAClC,MAAM,EAAE,OAAO,YAAY,qBACzB,gBACA,YACF;EACA,MAAM,QAAQ,SAAS,SAAS,cAAc;EAC9C,OAAO,YAAqB;GAC1B;GACA;GACA;GACA;GACA,SAAS,SAAS;GAClB;GACA,QAAQ,SAAS;GACjB,mBAAmB,SAAS;GAC5B,WAAW,SAAS;EACtB,CAAC;CACH;CAEA,eAAe,OACb,OACA,SACkC;EAClC,MAAM,WAAW,MAAM,sBAAsB;GAC3C;GACA;GACA;GACA;EACF,CAAC;EAED,OAAO,YAAqB;GAC1B;GACA;GACA;GACA,OAAO,SAAS;GAChB,SAAS,SAAS;GAClB;GACA,QAAQ,SAAS;GACjB,mBAAmB,SAAS;GAC5B,WAAW,SAAS;GACpB,YAAY;EACd,CAAC;CACH;CAEA,MAAM,WAAgE;EACpE,MAAM,WAAW;EACjB,aAAa,WAAW;EACxB,aAAa,WAAW;EACxB;EACA,SAAS,WAAW;EACpB;EACA;EACA,GAAqC,OAAU,SAAkC;GAC/E,OAAO,QAAQ,GAAG,OAAO,OAAO;EAClC;EACA,IAAsC,OAAU,SAAkC;GAChF,QAAQ,IAAI,OAAO,OAAO;EAC5B;EACA,OAA4B,SAGU;GACpC,OAAO,OAAoC,UAAU,OAAO;EAC9D;CACF;CAEA,OAAO;AACT;;;;;;;;;;;;AAaA,SAAS,qBACP,gBACA,cAC2D;CAC3D,IACE,iBAAiB,UACjB,mBAAmB,QACnB,OAAO,mBAAmB,YAC1B,WAAY,gBACZ;EAEA,MAAM,EAAE,OAAO,GAAG,YAAYA;EAC9B,OAAO;GAAE;GAAO;EAAQ;CAC1B;CAEA,OAAO;EAAE,OAAO;EAA0B,SAAS;CAAa;AAClE;AAEA,SAAS,SACP,YACM;CACN,IAAI,CAAC,WAAW,QAAQ,OAAO,WAAW,SAAS,UACjD,MAAM,IAAI,cAAc,iCAAiC;CAG3D,IAAI,CAAC,MAAM,QAAQ,WAAW,KAAK,KAAK,WAAW,MAAM,WAAW,GAClE,MAAM,IAAI,cAAc,gBAAgB,WAAW,KAAK,kCAAkC;CAG5F,MAAM,uBAAO,IAAI,IAAY;CAC7B,MAAM,QAAQ,SAAiB;EAC7B,IAAI,KAAK,IAAI,IAAI,GACf,MAAM,IAAI,cAAc,gBAAgB,WAAW,KAAK,2BAA2B,KAAK,EAAE;EAE5F,KAAK,IAAI,IAAI;CACf;CAEA,KAAK,MAAM,QAAQ,WAAW,OAAO;EACnC,KAAK,KAAK,IAAI;EAEd,IAAI,KAAK,UACP,KAAK,MAAM,SAAS,KAAK,UACvB,KAAK,MAAM,IAAI;CAGrB;AACF;AAEA,SAAS,gBAAwB;CAE/B,OAAO,MAAM,KAAK,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,GAAG,KAAK,OAAO,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,MAAM,GAAG,EAAE;AAChF"}