@warlock.js/ai 4.1.1

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 (490) hide show
  1. package/README.md +72 -0
  2. package/cjs/index.cjs +8625 -0
  3. package/cjs/index.cjs.map +1 -0
  4. package/esm/agent/agent-config.type.d.mts +160 -0
  5. package/esm/agent/agent-config.type.d.mts.map +1 -0
  6. package/esm/agent/agent-input-builder.mjs +111 -0
  7. package/esm/agent/agent-input-builder.mjs.map +1 -0
  8. package/esm/agent/agent-log-event.mjs +101 -0
  9. package/esm/agent/agent-log-event.mjs.map +1 -0
  10. package/esm/agent/agent-stream.d.mts +47 -0
  11. package/esm/agent/agent-stream.d.mts.map +1 -0
  12. package/esm/agent/agent-stream.mjs +82 -0
  13. package/esm/agent/agent-stream.mjs.map +1 -0
  14. package/esm/agent/agent-to-stream-event.mjs +86 -0
  15. package/esm/agent/agent-to-stream-event.mjs.map +1 -0
  16. package/esm/agent/agent.d.mts +38 -0
  17. package/esm/agent/agent.d.mts.map +1 -0
  18. package/esm/agent/agent.mjs +974 -0
  19. package/esm/agent/agent.mjs.map +1 -0
  20. package/esm/agent/index.d.mts +3 -0
  21. package/esm/agent/index.mjs +4 -0
  22. package/esm/agent/json-stream-guard.mjs +400 -0
  23. package/esm/agent/json-stream-guard.mjs.map +1 -0
  24. package/esm/ai.d.mts +64 -0
  25. package/esm/ai.d.mts.map +1 -0
  26. package/esm/ai.mjs +65 -0
  27. package/esm/ai.mjs.map +1 -0
  28. package/esm/config.d.mts +79 -0
  29. package/esm/config.d.mts.map +1 -0
  30. package/esm/config.mjs +43 -0
  31. package/esm/config.mjs.map +1 -0
  32. package/esm/contracts/agent/agent-options.type.d.mts +132 -0
  33. package/esm/contracts/agent/agent-options.type.d.mts.map +1 -0
  34. package/esm/contracts/agent/agent.contract.d.mts +92 -0
  35. package/esm/contracts/agent/agent.contract.d.mts.map +1 -0
  36. package/esm/contracts/agent/index.d.mts +2 -0
  37. package/esm/contracts/attachment.type.d.mts +100 -0
  38. package/esm/contracts/attachment.type.d.mts.map +1 -0
  39. package/esm/contracts/content-part.type.d.mts +55 -0
  40. package/esm/contracts/content-part.type.d.mts.map +1 -0
  41. package/esm/contracts/conversation-message.type.d.mts +51 -0
  42. package/esm/contracts/conversation-message.type.d.mts.map +1 -0
  43. package/esm/contracts/embedder.contract.d.mts +69 -0
  44. package/esm/contracts/embedder.contract.d.mts.map +1 -0
  45. package/esm/contracts/end.type.d.mts +53 -0
  46. package/esm/contracts/end.type.d.mts.map +1 -0
  47. package/esm/contracts/end.type.mjs +47 -0
  48. package/esm/contracts/end.type.mjs.map +1 -0
  49. package/esm/contracts/events/agent-events.type.d.mts +71 -0
  50. package/esm/contracts/events/agent-events.type.d.mts.map +1 -0
  51. package/esm/contracts/events/complete-event.type.d.mts +33 -0
  52. package/esm/contracts/events/complete-event.type.d.mts.map +1 -0
  53. package/esm/contracts/events/event-identity.type.d.mts +30 -0
  54. package/esm/contracts/events/event-identity.type.d.mts.map +1 -0
  55. package/esm/contracts/events/event-map.type.d.mts +80 -0
  56. package/esm/contracts/events/event-map.type.d.mts.map +1 -0
  57. package/esm/contracts/events/index.d.mts +7 -0
  58. package/esm/contracts/events/supervisor-events.type.d.mts +162 -0
  59. package/esm/contracts/events/supervisor-events.type.d.mts.map +1 -0
  60. package/esm/contracts/events/usage-event.type.d.mts +39 -0
  61. package/esm/contracts/events/usage-event.type.d.mts.map +1 -0
  62. package/esm/contracts/events/workflow-events.type.d.mts +51 -0
  63. package/esm/contracts/events/workflow-events.type.d.mts.map +1 -0
  64. package/esm/contracts/executable.contract.d.mts +25 -0
  65. package/esm/contracts/executable.contract.d.mts.map +1 -0
  66. package/esm/contracts/finish-reason.type.d.mts +17 -0
  67. package/esm/contracts/finish-reason.type.d.mts.map +1 -0
  68. package/esm/contracts/index.d.mts +63 -0
  69. package/esm/contracts/middleware/index.d.mts +3 -0
  70. package/esm/contracts/middleware/middleware-context.type.d.mts +99 -0
  71. package/esm/contracts/middleware/middleware-context.type.d.mts.map +1 -0
  72. package/esm/contracts/middleware/middleware-state.type.d.mts +34 -0
  73. package/esm/contracts/middleware/middleware-state.type.d.mts.map +1 -0
  74. package/esm/contracts/middleware/middleware.contract.d.mts +140 -0
  75. package/esm/contracts/middleware/middleware.contract.d.mts.map +1 -0
  76. package/esm/contracts/model-tool-call-request.type.d.mts +58 -0
  77. package/esm/contracts/model-tool-call-request.type.d.mts.map +1 -0
  78. package/esm/contracts/model.contract.d.mts +164 -0
  79. package/esm/contracts/model.contract.d.mts.map +1 -0
  80. package/esm/contracts/placeholders.type.d.mts +23 -0
  81. package/esm/contracts/placeholders.type.d.mts.map +1 -0
  82. package/esm/contracts/result/agent-result.type.d.mts +33 -0
  83. package/esm/contracts/result/agent-result.type.d.mts.map +1 -0
  84. package/esm/contracts/result/attempt-entry.type.d.mts +40 -0
  85. package/esm/contracts/result/attempt-entry.type.d.mts.map +1 -0
  86. package/esm/contracts/result/base-report.type.d.mts +137 -0
  87. package/esm/contracts/result/base-report.type.d.mts.map +1 -0
  88. package/esm/contracts/result/base-report.type.mjs +17 -0
  89. package/esm/contracts/result/base-report.type.mjs.map +1 -0
  90. package/esm/contracts/result/base-result.type.d.mts +26 -0
  91. package/esm/contracts/result/base-result.type.d.mts.map +1 -0
  92. package/esm/contracts/result/execute-result.type.d.mts +40 -0
  93. package/esm/contracts/result/execute-result.type.d.mts.map +1 -0
  94. package/esm/contracts/result/execution-report.type.d.mts +50 -0
  95. package/esm/contracts/result/execution-report.type.d.mts.map +1 -0
  96. package/esm/contracts/result/index.d.mts +14 -0
  97. package/esm/contracts/result/llm-trip.type.d.mts +36 -0
  98. package/esm/contracts/result/llm-trip.type.d.mts.map +1 -0
  99. package/esm/contracts/result/model-pricing.type.d.mts +51 -0
  100. package/esm/contracts/result/model-pricing.type.d.mts.map +1 -0
  101. package/esm/contracts/result/session-send-result.type.d.mts +29 -0
  102. package/esm/contracts/result/session-send-result.type.d.mts.map +1 -0
  103. package/esm/contracts/result/step-result.type.d.mts +43 -0
  104. package/esm/contracts/result/step-result.type.d.mts.map +1 -0
  105. package/esm/contracts/result/supervisor-result.type.d.mts +86 -0
  106. package/esm/contracts/result/supervisor-result.type.d.mts.map +1 -0
  107. package/esm/contracts/result/tool-call.type.d.mts +44 -0
  108. package/esm/contracts/result/tool-call.type.d.mts.map +1 -0
  109. package/esm/contracts/result/usage.type.d.mts +57 -0
  110. package/esm/contracts/result/usage.type.d.mts.map +1 -0
  111. package/esm/contracts/result/workflow-result.type.d.mts +45 -0
  112. package/esm/contracts/result/workflow-result.type.d.mts.map +1 -0
  113. package/esm/contracts/sdk-adapter.contract.d.mts +77 -0
  114. package/esm/contracts/sdk-adapter.contract.d.mts.map +1 -0
  115. package/esm/contracts/stream/stream-event.type.d.mts +68 -0
  116. package/esm/contracts/stream/stream-event.type.d.mts.map +1 -0
  117. package/esm/contracts/stream/stream.contract.d.mts +61 -0
  118. package/esm/contracts/stream/stream.contract.d.mts.map +1 -0
  119. package/esm/contracts/streaming-tool-guard-config.type.d.mts +78 -0
  120. package/esm/contracts/streaming-tool-guard-config.type.d.mts.map +1 -0
  121. package/esm/contracts/supervisor/ack-entry.type.d.mts +97 -0
  122. package/esm/contracts/supervisor/ack-entry.type.d.mts.map +1 -0
  123. package/esm/contracts/supervisor/classifier-context.type.d.mts +189 -0
  124. package/esm/contracts/supervisor/classifier-context.type.d.mts.map +1 -0
  125. package/esm/contracts/supervisor/dispatch-context.type.d.mts +235 -0
  126. package/esm/contracts/supervisor/dispatch-context.type.d.mts.map +1 -0
  127. package/esm/contracts/supervisor/evaluate-context.type.d.mts +124 -0
  128. package/esm/contracts/supervisor/evaluate-context.type.d.mts.map +1 -0
  129. package/esm/contracts/supervisor/index.d.mts +16 -0
  130. package/esm/contracts/supervisor/intent-entry.type.d.mts +254 -0
  131. package/esm/contracts/supervisor/intent-entry.type.d.mts.map +1 -0
  132. package/esm/contracts/supervisor/iteration-snapshot.type.d.mts +117 -0
  133. package/esm/contracts/supervisor/iteration-snapshot.type.d.mts.map +1 -0
  134. package/esm/contracts/supervisor/next.type.d.mts +25 -0
  135. package/esm/contracts/supervisor/next.type.d.mts.map +1 -0
  136. package/esm/contracts/supervisor/route-context.type.d.mts +91 -0
  137. package/esm/contracts/supervisor/route-context.type.d.mts.map +1 -0
  138. package/esm/contracts/supervisor/router-entry.type.d.mts +67 -0
  139. package/esm/contracts/supervisor/router-entry.type.d.mts.map +1 -0
  140. package/esm/contracts/supervisor/supervisor-config.type.d.mts +356 -0
  141. package/esm/contracts/supervisor/supervisor-config.type.d.mts.map +1 -0
  142. package/esm/contracts/supervisor/supervisor-execute-options.type.d.mts +90 -0
  143. package/esm/contracts/supervisor/supervisor-execute-options.type.d.mts.map +1 -0
  144. package/esm/contracts/supervisor/supervisor-input.type.d.mts +24 -0
  145. package/esm/contracts/supervisor/supervisor-input.type.d.mts.map +1 -0
  146. package/esm/contracts/supervisor/supervisor-snapshot.type.d.mts +49 -0
  147. package/esm/contracts/supervisor/supervisor-snapshot.type.d.mts.map +1 -0
  148. package/esm/contracts/supervisor/supervisor-stream-event.type.d.mts +16 -0
  149. package/esm/contracts/supervisor/supervisor-stream-event.type.d.mts.map +1 -0
  150. package/esm/contracts/supervisor/supervisor.contract.d.mts +126 -0
  151. package/esm/contracts/supervisor/supervisor.contract.d.mts.map +1 -0
  152. package/esm/contracts/system-prompt.contract.d.mts +118 -0
  153. package/esm/contracts/system-prompt.contract.d.mts.map +1 -0
  154. package/esm/contracts/tool.contract.d.mts +161 -0
  155. package/esm/contracts/tool.contract.d.mts.map +1 -0
  156. package/esm/contracts/workflow/index.d.mts +6 -0
  157. package/esm/contracts/workflow/next-step-result.type.d.mts +17 -0
  158. package/esm/contracts/workflow/next-step-result.type.d.mts.map +1 -0
  159. package/esm/contracts/workflow/retry-config.type.d.mts +19 -0
  160. package/esm/contracts/workflow/retry-config.type.d.mts.map +1 -0
  161. package/esm/contracts/workflow/step.contract.d.mts +189 -0
  162. package/esm/contracts/workflow/step.contract.d.mts.map +1 -0
  163. package/esm/contracts/workflow/workflow-context.type.d.mts +45 -0
  164. package/esm/contracts/workflow/workflow-context.type.d.mts.map +1 -0
  165. package/esm/contracts/workflow/workflow-snapshot.type.d.mts +24 -0
  166. package/esm/contracts/workflow/workflow-snapshot.type.d.mts.map +1 -0
  167. package/esm/contracts/workflow/workflow.contract.d.mts +142 -0
  168. package/esm/contracts/workflow/workflow.contract.d.mts.map +1 -0
  169. package/esm/errors/agent-cancelled-error.d.mts +49 -0
  170. package/esm/errors/agent-cancelled-error.d.mts.map +1 -0
  171. package/esm/errors/agent-cancelled-error.mjs +43 -0
  172. package/esm/errors/agent-cancelled-error.mjs.map +1 -0
  173. package/esm/errors/agent-execution-error.d.mts +32 -0
  174. package/esm/errors/agent-execution-error.d.mts.map +1 -0
  175. package/esm/errors/agent-execution-error.mjs +35 -0
  176. package/esm/errors/agent-execution-error.mjs.map +1 -0
  177. package/esm/errors/agent-max-trips-error.d.mts +45 -0
  178. package/esm/errors/agent-max-trips-error.d.mts.map +1 -0
  179. package/esm/errors/agent-max-trips-error.mjs +41 -0
  180. package/esm/errors/agent-max-trips-error.mjs.map +1 -0
  181. package/esm/errors/ai-error.d.mts +94 -0
  182. package/esm/errors/ai-error.d.mts.map +1 -0
  183. package/esm/errors/ai-error.mjs +68 -0
  184. package/esm/errors/ai-error.mjs.map +1 -0
  185. package/esm/errors/budget-exceeded-error.d.mts +41 -0
  186. package/esm/errors/budget-exceeded-error.d.mts.map +1 -0
  187. package/esm/errors/budget-exceeded-error.mjs +31 -0
  188. package/esm/errors/budget-exceeded-error.mjs.map +1 -0
  189. package/esm/errors/content-filter-error.d.mts +33 -0
  190. package/esm/errors/content-filter-error.d.mts.map +1 -0
  191. package/esm/errors/content-filter-error.mjs +28 -0
  192. package/esm/errors/content-filter-error.mjs.map +1 -0
  193. package/esm/errors/context-length-exceeded-error.d.mts +38 -0
  194. package/esm/errors/context-length-exceeded-error.d.mts.map +1 -0
  195. package/esm/errors/context-length-exceeded-error.mjs +31 -0
  196. package/esm/errors/context-length-exceeded-error.mjs.map +1 -0
  197. package/esm/errors/error-category.type.d.mts +30 -0
  198. package/esm/errors/error-category.type.d.mts.map +1 -0
  199. package/esm/errors/error-code.type.d.mts +19 -0
  200. package/esm/errors/error-code.type.d.mts.map +1 -0
  201. package/esm/errors/guardrail-violation-error.d.mts +55 -0
  202. package/esm/errors/guardrail-violation-error.d.mts.map +1 -0
  203. package/esm/errors/guardrail-violation-error.mjs +41 -0
  204. package/esm/errors/guardrail-violation-error.mjs.map +1 -0
  205. package/esm/errors/index.d.mts +29 -0
  206. package/esm/errors/index.mjs +29 -0
  207. package/esm/errors/invalid-request-error.d.mts +27 -0
  208. package/esm/errors/invalid-request-error.d.mts.map +1 -0
  209. package/esm/errors/invalid-request-error.mjs +31 -0
  210. package/esm/errors/invalid-request-error.mjs.map +1 -0
  211. package/esm/errors/max-iterations-error.d.mts +31 -0
  212. package/esm/errors/max-iterations-error.d.mts.map +1 -0
  213. package/esm/errors/max-iterations-error.mjs +32 -0
  214. package/esm/errors/max-iterations-error.mjs.map +1 -0
  215. package/esm/errors/max-steps-exceeded-error.d.mts +20 -0
  216. package/esm/errors/max-steps-exceeded-error.d.mts.map +1 -0
  217. package/esm/errors/max-steps-exceeded-error.mjs +21 -0
  218. package/esm/errors/max-steps-exceeded-error.mjs.map +1 -0
  219. package/esm/errors/provider-auth-error.d.mts +22 -0
  220. package/esm/errors/provider-auth-error.d.mts.map +1 -0
  221. package/esm/errors/provider-auth-error.mjs +26 -0
  222. package/esm/errors/provider-auth-error.mjs.map +1 -0
  223. package/esm/errors/provider-error.d.mts +38 -0
  224. package/esm/errors/provider-error.d.mts.map +1 -0
  225. package/esm/errors/provider-error.mjs +42 -0
  226. package/esm/errors/provider-error.mjs.map +1 -0
  227. package/esm/errors/provider-rate-limit-error.d.mts +34 -0
  228. package/esm/errors/provider-rate-limit-error.d.mts.map +1 -0
  229. package/esm/errors/provider-rate-limit-error.mjs +31 -0
  230. package/esm/errors/provider-rate-limit-error.mjs.map +1 -0
  231. package/esm/errors/provider-timeout-error.d.mts +22 -0
  232. package/esm/errors/provider-timeout-error.d.mts.map +1 -0
  233. package/esm/errors/provider-timeout-error.mjs +26 -0
  234. package/esm/errors/provider-timeout-error.mjs.map +1 -0
  235. package/esm/errors/quota-exceeded-error.d.mts +36 -0
  236. package/esm/errors/quota-exceeded-error.d.mts.map +1 -0
  237. package/esm/errors/quota-exceeded-error.mjs +40 -0
  238. package/esm/errors/quota-exceeded-error.mjs.map +1 -0
  239. package/esm/errors/routing-error.d.mts +23 -0
  240. package/esm/errors/routing-error.d.mts.map +1 -0
  241. package/esm/errors/routing-error.mjs +23 -0
  242. package/esm/errors/routing-error.mjs.map +1 -0
  243. package/esm/errors/schema-validation-error.d.mts +40 -0
  244. package/esm/errors/schema-validation-error.d.mts.map +1 -0
  245. package/esm/errors/schema-validation-error.mjs +37 -0
  246. package/esm/errors/schema-validation-error.mjs.map +1 -0
  247. package/esm/errors/step-failed-error.d.mts +20 -0
  248. package/esm/errors/step-failed-error.d.mts.map +1 -0
  249. package/esm/errors/step-failed-error.mjs +19 -0
  250. package/esm/errors/step-failed-error.mjs.map +1 -0
  251. package/esm/errors/supervisor-cancelled-error.d.mts +29 -0
  252. package/esm/errors/supervisor-cancelled-error.d.mts.map +1 -0
  253. package/esm/errors/supervisor-cancelled-error.mjs +29 -0
  254. package/esm/errors/supervisor-cancelled-error.mjs.map +1 -0
  255. package/esm/errors/supervisor-drift-error.d.mts +31 -0
  256. package/esm/errors/supervisor-drift-error.d.mts.map +1 -0
  257. package/esm/errors/supervisor-drift-error.mjs +30 -0
  258. package/esm/errors/supervisor-drift-error.mjs.map +1 -0
  259. package/esm/errors/supervisor-failed-error.d.mts +40 -0
  260. package/esm/errors/supervisor-failed-error.d.mts.map +1 -0
  261. package/esm/errors/supervisor-failed-error.mjs +43 -0
  262. package/esm/errors/supervisor-failed-error.mjs.map +1 -0
  263. package/esm/errors/supervisor-routing-error.d.mts +44 -0
  264. package/esm/errors/supervisor-routing-error.d.mts.map +1 -0
  265. package/esm/errors/supervisor-routing-error.mjs +39 -0
  266. package/esm/errors/supervisor-routing-error.mjs.map +1 -0
  267. package/esm/errors/tool-execution-error.d.mts +35 -0
  268. package/esm/errors/tool-execution-error.d.mts.map +1 -0
  269. package/esm/errors/tool-execution-error.mjs +32 -0
  270. package/esm/errors/tool-execution-error.mjs.map +1 -0
  271. package/esm/errors/workflow-cancelled-error.d.mts +23 -0
  272. package/esm/errors/workflow-cancelled-error.d.mts.map +1 -0
  273. package/esm/errors/workflow-cancelled-error.mjs +23 -0
  274. package/esm/errors/workflow-cancelled-error.mjs.map +1 -0
  275. package/esm/errors/workflow-drift-error.d.mts +25 -0
  276. package/esm/errors/workflow-drift-error.d.mts.map +1 -0
  277. package/esm/errors/workflow-drift-error.mjs +24 -0
  278. package/esm/errors/workflow-drift-error.mjs.map +1 -0
  279. package/esm/errors/workflow-error.d.mts +15 -0
  280. package/esm/errors/workflow-error.d.mts.map +1 -0
  281. package/esm/errors/workflow-error.mjs +18 -0
  282. package/esm/errors/workflow-error.mjs.map +1 -0
  283. package/esm/index.d.mts +137 -0
  284. package/esm/index.mjs +81 -0
  285. package/esm/middleware/builtins/budget.d.mts +103 -0
  286. package/esm/middleware/builtins/budget.d.mts.map +1 -0
  287. package/esm/middleware/builtins/budget.mjs +100 -0
  288. package/esm/middleware/builtins/budget.mjs.map +1 -0
  289. package/esm/middleware/builtins/guardrail.d.mts +92 -0
  290. package/esm/middleware/builtins/guardrail.d.mts.map +1 -0
  291. package/esm/middleware/builtins/guardrail.mjs +76 -0
  292. package/esm/middleware/builtins/guardrail.mjs.map +1 -0
  293. package/esm/middleware/builtins/semantic-cache.d.mts +106 -0
  294. package/esm/middleware/builtins/semantic-cache.d.mts.map +1 -0
  295. package/esm/middleware/builtins/semantic-cache.mjs +149 -0
  296. package/esm/middleware/builtins/semantic-cache.mjs.map +1 -0
  297. package/esm/middleware/helpers/compose.d.mts +42 -0
  298. package/esm/middleware/helpers/compose.d.mts.map +1 -0
  299. package/esm/middleware/helpers/compose.mjs +52 -0
  300. package/esm/middleware/helpers/compose.mjs.map +1 -0
  301. package/esm/middleware/helpers/for-tool.d.mts +55 -0
  302. package/esm/middleware/helpers/for-tool.d.mts.map +1 -0
  303. package/esm/middleware/helpers/for-tool.mjs +80 -0
  304. package/esm/middleware/helpers/for-tool.mjs.map +1 -0
  305. package/esm/middleware/helpers/index.d.mts +2 -0
  306. package/esm/middleware/index.d.mts +8 -0
  307. package/esm/middleware/index.mjs +10 -0
  308. package/esm/middleware/pipeline.d.mts +70 -0
  309. package/esm/middleware/pipeline.d.mts.map +1 -0
  310. package/esm/middleware/pipeline.mjs +100 -0
  311. package/esm/middleware/pipeline.mjs.map +1 -0
  312. package/esm/middleware/utils/extract-user-text.d.mts +33 -0
  313. package/esm/middleware/utils/extract-user-text.d.mts.map +1 -0
  314. package/esm/middleware/utils/extract-user-text.mjs +40 -0
  315. package/esm/middleware/utils/extract-user-text.mjs.map +1 -0
  316. package/esm/middleware/utils/index.d.mts +2 -0
  317. package/esm/middleware/utils/namespaced-state.d.mts +60 -0
  318. package/esm/middleware/utils/namespaced-state.d.mts.map +1 -0
  319. package/esm/middleware/utils/namespaced-state.mjs +60 -0
  320. package/esm/middleware/utils/namespaced-state.mjs.map +1 -0
  321. package/esm/mock/index.d.mts +4 -0
  322. package/esm/mock/index.mjs +5 -0
  323. package/esm/mock/mock-agent.d.mts +41 -0
  324. package/esm/mock/mock-agent.d.mts.map +1 -0
  325. package/esm/mock/mock-agent.mjs +39 -0
  326. package/esm/mock/mock-agent.mjs.map +1 -0
  327. package/esm/mock/mock-config.type.d.mts +31 -0
  328. package/esm/mock/mock-config.type.d.mts.map +1 -0
  329. package/esm/mock/mock-model.d.mts +94 -0
  330. package/esm/mock/mock-model.d.mts.map +1 -0
  331. package/esm/mock/mock-model.mjs +150 -0
  332. package/esm/mock/mock-model.mjs.map +1 -0
  333. package/esm/mock/mock-sdk.d.mts +25 -0
  334. package/esm/mock/mock-sdk.d.mts.map +1 -0
  335. package/esm/mock/mock-sdk.mjs +37 -0
  336. package/esm/mock/mock-sdk.mjs.map +1 -0
  337. package/esm/supervisor/as-tool.d.mts +45 -0
  338. package/esm/supervisor/as-tool.d.mts.map +1 -0
  339. package/esm/supervisor/as-tool.mjs +80 -0
  340. package/esm/supervisor/as-tool.mjs.map +1 -0
  341. package/esm/supervisor/cancellation.d.mts +12 -0
  342. package/esm/supervisor/cancellation.d.mts.map +1 -0
  343. package/esm/supervisor/cancellation.mjs +22 -0
  344. package/esm/supervisor/cancellation.mjs.map +1 -0
  345. package/esm/supervisor/decide.mjs +272 -0
  346. package/esm/supervisor/decide.mjs.map +1 -0
  347. package/esm/supervisor/emitter.d.mts +27 -0
  348. package/esm/supervisor/emitter.d.mts.map +1 -0
  349. package/esm/supervisor/emitter.mjs +47 -0
  350. package/esm/supervisor/emitter.mjs.map +1 -0
  351. package/esm/supervisor/entries.d.mts +141 -0
  352. package/esm/supervisor/entries.d.mts.map +1 -0
  353. package/esm/supervisor/entries.mjs +206 -0
  354. package/esm/supervisor/entries.mjs.map +1 -0
  355. package/esm/supervisor/execution.d.mts +637 -0
  356. package/esm/supervisor/execution.d.mts.map +1 -0
  357. package/esm/supervisor/execution.mjs +1868 -0
  358. package/esm/supervisor/execution.mjs.map +1 -0
  359. package/esm/supervisor/index.d.mts +11 -0
  360. package/esm/supervisor/index.mjs +12 -0
  361. package/esm/supervisor/router-prompt.d.mts +56 -0
  362. package/esm/supervisor/router-prompt.d.mts.map +1 -0
  363. package/esm/supervisor/router-prompt.mjs +52 -0
  364. package/esm/supervisor/router-prompt.mjs.map +1 -0
  365. package/esm/supervisor/signature.d.mts +28 -0
  366. package/esm/supervisor/signature.d.mts.map +1 -0
  367. package/esm/supervisor/signature.mjs +89 -0
  368. package/esm/supervisor/signature.mjs.map +1 -0
  369. package/esm/supervisor/snapshot.d.mts +54 -0
  370. package/esm/supervisor/snapshot.d.mts.map +1 -0
  371. package/esm/supervisor/snapshot.mjs +77 -0
  372. package/esm/supervisor/snapshot.mjs.map +1 -0
  373. package/esm/supervisor/supervisor-stream.d.mts +29 -0
  374. package/esm/supervisor/supervisor-stream.d.mts.map +1 -0
  375. package/esm/supervisor/supervisor-stream.mjs +89 -0
  376. package/esm/supervisor/supervisor-stream.mjs.map +1 -0
  377. package/esm/supervisor/supervisor.d.mts +27 -0
  378. package/esm/supervisor/supervisor.d.mts.map +1 -0
  379. package/esm/supervisor/supervisor.mjs +138 -0
  380. package/esm/supervisor/supervisor.mjs.map +1 -0
  381. package/esm/system-prompt/instruction.d.mts +52 -0
  382. package/esm/system-prompt/instruction.d.mts.map +1 -0
  383. package/esm/system-prompt/instruction.mjs +57 -0
  384. package/esm/system-prompt/instruction.mjs.map +1 -0
  385. package/esm/system-prompt/persona.d.mts +52 -0
  386. package/esm/system-prompt/persona.d.mts.map +1 -0
  387. package/esm/system-prompt/persona.mjs +57 -0
  388. package/esm/system-prompt/persona.mjs.map +1 -0
  389. package/esm/system-prompt/render-placeholders.d.mts +31 -0
  390. package/esm/system-prompt/render-placeholders.d.mts.map +1 -0
  391. package/esm/system-prompt/render-placeholders.mjs +58 -0
  392. package/esm/system-prompt/render-placeholders.mjs.map +1 -0
  393. package/esm/system-prompt/system-prompt.d.mts +117 -0
  394. package/esm/system-prompt/system-prompt.d.mts.map +1 -0
  395. package/esm/system-prompt/system-prompt.mjs +137 -0
  396. package/esm/system-prompt/system-prompt.mjs.map +1 -0
  397. package/esm/tool/index.d.mts +1 -0
  398. package/esm/tool/index.mjs +3 -0
  399. package/esm/tool/tool.d.mts +64 -0
  400. package/esm/tool/tool.d.mts.map +1 -0
  401. package/esm/tool/tool.mjs +184 -0
  402. package/esm/tool/tool.mjs.map +1 -0
  403. package/esm/utils/compute-cost.d.mts +58 -0
  404. package/esm/utils/compute-cost.d.mts.map +1 -0
  405. package/esm/utils/compute-cost.mjs +87 -0
  406. package/esm/utils/compute-cost.mjs.map +1 -0
  407. package/esm/utils/extract-json-payload.d.mts +33 -0
  408. package/esm/utils/extract-json-payload.d.mts.map +1 -0
  409. package/esm/utils/extract-json-payload.mjs +39 -0
  410. package/esm/utils/extract-json-payload.mjs.map +1 -0
  411. package/esm/utils/generate-run-id.d.mts +20 -0
  412. package/esm/utils/generate-run-id.d.mts.map +1 -0
  413. package/esm/utils/generate-run-id.mjs +23 -0
  414. package/esm/utils/generate-run-id.mjs.map +1 -0
  415. package/esm/utils/index.d.mts +9 -0
  416. package/esm/utils/index.mjs +11 -0
  417. package/esm/utils/json-schema.d.mts +57 -0
  418. package/esm/utils/json-schema.d.mts.map +1 -0
  419. package/esm/utils/json-schema.mjs +89 -0
  420. package/esm/utils/json-schema.mjs.map +1 -0
  421. package/esm/utils/prepare-attachment-part.d.mts +36 -0
  422. package/esm/utils/prepare-attachment-part.d.mts.map +1 -0
  423. package/esm/utils/prepare-attachment-part.mjs +140 -0
  424. package/esm/utils/prepare-attachment-part.mjs.map +1 -0
  425. package/esm/utils/resolve-attachment.d.mts +33 -0
  426. package/esm/utils/resolve-attachment.d.mts.map +1 -0
  427. package/esm/utils/resolve-attachment.mjs +73 -0
  428. package/esm/utils/resolve-attachment.mjs.map +1 -0
  429. package/esm/utils/safe-json-parse.d.mts +14 -0
  430. package/esm/utils/safe-json-parse.d.mts.map +1 -0
  431. package/esm/utils/safe-json-parse.mjs +22 -0
  432. package/esm/utils/safe-json-parse.mjs.map +1 -0
  433. package/esm/utils/stamp-report-lineage.d.mts +61 -0
  434. package/esm/utils/stamp-report-lineage.d.mts.map +1 -0
  435. package/esm/utils/stamp-report-lineage.mjs +47 -0
  436. package/esm/utils/stamp-report-lineage.mjs.map +1 -0
  437. package/esm/utils/token-count.d.mts +15 -0
  438. package/esm/utils/token-count.d.mts.map +1 -0
  439. package/esm/utils/token-count.mjs +18 -0
  440. package/esm/utils/token-count.mjs.map +1 -0
  441. package/esm/workflow/as-tool.mjs +55 -0
  442. package/esm/workflow/as-tool.mjs.map +1 -0
  443. package/esm/workflow/cancellation.mjs +44 -0
  444. package/esm/workflow/cancellation.mjs.map +1 -0
  445. package/esm/workflow/emitter.mjs +40 -0
  446. package/esm/workflow/emitter.mjs.map +1 -0
  447. package/esm/workflow/engine.mjs +362 -0
  448. package/esm/workflow/engine.mjs.map +1 -0
  449. package/esm/workflow/index.d.mts +3 -0
  450. package/esm/workflow/index.mjs +5 -0
  451. package/esm/workflow/retry.mjs +32 -0
  452. package/esm/workflow/retry.mjs.map +1 -0
  453. package/esm/workflow/router.mjs +56 -0
  454. package/esm/workflow/router.mjs.map +1 -0
  455. package/esm/workflow/run-scoped-emitter.mjs +32 -0
  456. package/esm/workflow/run-scoped-emitter.mjs.map +1 -0
  457. package/esm/workflow/signature.d.mts +7 -0
  458. package/esm/workflow/signature.d.mts.map +1 -0
  459. package/esm/workflow/signature.mjs +34 -0
  460. package/esm/workflow/signature.mjs.map +1 -0
  461. package/esm/workflow/snapshot.mjs +71 -0
  462. package/esm/workflow/snapshot.mjs.map +1 -0
  463. package/esm/workflow/state.mjs +37 -0
  464. package/esm/workflow/state.mjs.map +1 -0
  465. package/esm/workflow/step-runner.mjs +371 -0
  466. package/esm/workflow/step-runner.mjs.map +1 -0
  467. package/esm/workflow/step.d.mts +19 -0
  468. package/esm/workflow/step.d.mts.map +1 -0
  469. package/esm/workflow/step.mjs +37 -0
  470. package/esm/workflow/step.mjs.map +1 -0
  471. package/esm/workflow/workflow.d.mts +12 -0
  472. package/esm/workflow/workflow.d.mts.map +1 -0
  473. package/esm/workflow/workflow.mjs +116 -0
  474. package/esm/workflow/workflow.mjs.map +1 -0
  475. package/llms-full.txt +2293 -0
  476. package/llms.txt +20 -0
  477. package/package.json +37 -0
  478. package/skills/README.md +53 -0
  479. package/skills/ai-basics/SKILL.md +95 -0
  480. package/skills/attach-ai-middleware/SKILL.md +184 -0
  481. package/skills/define-ai-tool/SKILL.md +186 -0
  482. package/skills/embed-text/SKILL.md +105 -0
  483. package/skills/handle-ai-errors/SKILL.md +194 -0
  484. package/skills/log-ai-calls/SKILL.md +141 -0
  485. package/skills/persist-ai-data/SKILL.md +207 -0
  486. package/skills/pick-ai-provider/SKILL.md +164 -0
  487. package/skills/run-ai-agent/SKILL.md +267 -0
  488. package/skills/run-ai-workflow/SKILL.md +258 -0
  489. package/skills/run-supervisor/SKILL.md +309 -0
  490. package/skills/write-system-prompt/SKILL.md +129 -0
@@ -0,0 +1,637 @@
1
+ import { SupervisorInput } from "../contracts/supervisor/supervisor-input.type.mjs";
2
+ import { SupervisorConfig } from "../contracts/supervisor/supervisor-config.type.mjs";
3
+ import { SupervisorExecuteOptions } from "../contracts/supervisor/supervisor-execute-options.type.mjs";
4
+ import { SupervisorResult } from "../contracts/result/supervisor-result.type.mjs";
5
+ import { SupervisorSnapshot } from "../contracts/supervisor/supervisor-snapshot.type.mjs";
6
+ import { SupervisorEmitter } from "./emitter.mjs";
7
+ import { ResolvedIntentEntry } from "./entries.mjs";
8
+ import { SupervisorStreamController } from "./supervisor-stream.mjs";
9
+
10
+ //#region ../../@warlock.js/ai/src/supervisor/execution.d.ts
11
+ type SupervisorExecutionParams<TOutput> = {
12
+ config: SupervisorConfig<TOutput>;
13
+ entries: Map<string, ResolvedIntentEntry>;
14
+ signature: string;
15
+ emitter: SupervisorEmitter;
16
+ input: SupervisorInput;
17
+ runId: string;
18
+ options?: SupervisorExecuteOptions;
19
+ streamController?: SupervisorStreamController<SupervisorResult<TOutput>>;
20
+ resumeFrom?: SupervisorSnapshot;
21
+ };
22
+ /**
23
+ * Per-call driver that owns the full lifecycle of one supervisor run.
24
+ *
25
+ * **Role.** Short-lived state container and phase orchestrator —
26
+ * mirrors `agent/Execution` and `workflow/runWorkflow`, one level up.
27
+ *
28
+ * **Responsibility.**
29
+ * - Owns: the iteration loop, per-iteration dispatch (single or
30
+ * fan-out), evaluate scheduling, usage aggregation across router +
31
+ * every branch + evaluate, snapshot collection, event emission
32
+ * through all three tiers, KV-store checkpointing, final result
33
+ * assembly (state validation against the output schema → typed data).
34
+ * - Does NOT own: how child agents produce responses (delegated via
35
+ * `agent.execute` / `workflow.execute`), the routing decision
36
+ * itself (delegated to `decide.ts`), snapshot persistence mechanics
37
+ * (delegated to `snapshot.ts`), the stream queue plumbing
38
+ * (delegated to `supervisor-stream.ts`).
39
+ *
40
+ * `execute()` never throws — every unexpected failure funnels into
41
+ * `this.error` and is returned on `result.error` with an appropriate
42
+ * `SupervisorFailedError` / `MaxIterationsError` / `SupervisorRoutingError`
43
+ * / `SupervisorCancelledError`.
44
+ *
45
+ * @example
46
+ * // Inside supervisor.execute() — never constructed by user code directly:
47
+ * return new SupervisorExecution(params).run();
48
+ */
49
+ declare class SupervisorExecution<TOutput> {
50
+ private readonly config;
51
+ private readonly entries;
52
+ private readonly signature;
53
+ private readonly emitter;
54
+ private readonly input;
55
+ private readonly runId;
56
+ private readonly options?;
57
+ private readonly streamController?;
58
+ private readonly resumeFrom?;
59
+ private readonly maxIterations;
60
+ private readonly logger;
61
+ private readonly logModule;
62
+ private readonly snapshots;
63
+ private readonly childReports;
64
+ private readonly usage;
65
+ private readonly startedAtIso;
66
+ private readonly startPerf;
67
+ private iteration;
68
+ private carriedFeedback?;
69
+ /**
70
+ * Per-intent `next` directive (Q24 / Stage 4d) collected at the
71
+ * end of an iteration after evaluate hasn't already steered. When
72
+ * set, `decideDispatch` consumes it on the next iteration's start —
73
+ * skipping the router entirely. Cleared after consumption.
74
+ *
75
+ * Only the dispatch variant is stored; an `END` collection
76
+ * terminates the iteration loop directly inside `runIteration`.
77
+ */
78
+ private carriedNextDispatch?;
79
+ private terminatedBy;
80
+ private status;
81
+ private cancelledAtIso?;
82
+ private error?;
83
+ private data?;
84
+ private lastDispatchIntents;
85
+ /**
86
+ * Per-execute typed accumulator. Initialized from `config.state`
87
+ * (default `{}`) at construction; rehydrated from the last
88
+ * snapshot's `state` on resume; mutated in-place as each iteration's
89
+ * intents strip-merge their outputs into it.
90
+ */
91
+ private state;
92
+ /**
93
+ * Per-iteration artifacts bag (Phase 5 / decisions §35). Tools
94
+ * dispatched within an iteration mutate `ctx.artifacts` — which
95
+ * points at this object. After the iteration's branches settle and
96
+ * their slices merge into state, this bag validates against
97
+ * `config.artifactsSchema` (if set) and merges via
98
+ * `config.finalizeArtifacts` or auto-spread, then resets to `{}`
99
+ * for the next iteration. The reset is crucial — long runs and
100
+ * orchestrator sessions never accumulate raw artifacts here.
101
+ */
102
+ private currentArtifacts;
103
+ /**
104
+ * Frozen copy of the iteration's `currentArtifacts` bag captured at
105
+ * merge time — BEFORE `finalizeArtifacts` (or auto-spread) reshaped
106
+ * it into state (Phase 8 / decisions §38). Surfaced on the iteration
107
+ * snapshot's `artifacts` field for forensic / telemetry consumers
108
+ * that want the raw tool contributions.
109
+ *
110
+ * Reset to `{}` at the start of every iteration so a snapshot built
111
+ * for an iteration whose tools wrote nothing carries an empty bag,
112
+ * not a stale carry-over.
113
+ */
114
+ private capturedIterationArtifacts;
115
+ /**
116
+ * Classifier (Phase 7 / decisions §37) forensic record. Set on iter
117
+ * 0 when `SupervisorConfig.classifier` is configured AND the run
118
+ * started fresh (resumes don't re-fire classifier — same as ack).
119
+ * Surfaced on `SupervisorReport.classifier` and threaded into
120
+ * `ctx.classifier` on RouteContext / DispatchContext /
121
+ * EvaluateContext from iter 0 onward.
122
+ */
123
+ private classifierSnapshot?;
124
+ /**
125
+ * Iter-0 dispatch decision pre-computed by the classifier (Phase 7).
126
+ * When set, `decideDispatch` short-circuits and uses this directly
127
+ * with `source: "classifier"`. Cleared after consumption.
128
+ */
129
+ private carriedClassifierDispatch?;
130
+ /** Set true by classifier refine returning END to halt before any dispatch. */
131
+ private classifierHalted;
132
+ /**
133
+ * Receptionist forensic record. Set when an `ackAgent` was
134
+ * configured AND the run started fresh (resumes don't re-fire ack).
135
+ * Surfaced on `SupervisorReport.ack`.
136
+ */
137
+ private ackSnapshot?;
138
+ /**
139
+ * Read-only request-scoped context surfaced on every `ctx.context`.
140
+ * Shallow-copied + frozen at construction so callbacks see a stable
141
+ * snapshot of the caller's bag and can't mutate the original.
142
+ * Always present — defaults to a frozen `{}` when no context was
143
+ * passed. NOT persisted in snapshots.
144
+ */
145
+ private readonly context;
146
+ /**
147
+ * Prior conversation messages threaded through every callback context
148
+ * (`ctx.history`) and forwarded verbatim to dispatched agents (and the
149
+ * receptionist `ack` agent) as `agent.execute(input, { history })`.
150
+ * Frozen reference so callbacks see a stable view; not deep-cloned —
151
+ * conversation messages are treated as immutable by convention. NOT
152
+ * persisted in snapshots (re-supply on `resume()`).
153
+ */
154
+ private readonly history;
155
+ /**
156
+ * Resolved natural-language objective from `SupervisorConfig.goal`.
157
+ * Materialized to plain text at construction (string passes through;
158
+ * `SystemPromptContract` is `.resolve()`-d). `undefined` when the
159
+ * supervisor was configured without a goal.
160
+ */
161
+ private readonly goal;
162
+ constructor(params: SupervisorExecutionParams<TOutput>);
163
+ /**
164
+ * Resolve the history slice forwarded to a child execution (router /
165
+ * dispatched agent / ack). Precedence:
166
+ *
167
+ * 1. Per-entry `history` callback — full override; whatever it
168
+ * returns goes through (after defensive copy).
169
+ * 2. `SupervisorConfig.historyWindow.<role>` — last-N slice of the
170
+ * caller-supplied history.
171
+ * 3. Default — full history for `router`/`agents`, empty for `ack`
172
+ * (receptionists rarely benefit from scroll-back).
173
+ *
174
+ * Always returns a fresh `Message[]` (the agent layer
175
+ * mutates by reference internally, e.g. via `messages.push(...)`).
176
+ */
177
+ private resolveHistoryFor;
178
+ /**
179
+ * Apply only the global `historyWindow.agents` slice — used by the
180
+ * recursive `ctx.intents.X.execute()` re-entry path where no
181
+ * `RouteContext` is available to feed the per-entry slicer.
182
+ */
183
+ private applyAgentsWindow;
184
+ /**
185
+ * Entry point. Drives the iteration loop, finalizes the result, and
186
+ * emits terminal events. Returns the uniform
187
+ * `{ data, report, usage, error }` shape and closes the stream if
188
+ * one was attached. Never throws.
189
+ */
190
+ run(): Promise<SupervisorResult<TOutput>>;
191
+ /**
192
+ * Drive the iteration loop until a terminal condition fires:
193
+ * `END` / `satisfied:true` / `maxIterations` / signal abort /
194
+ * routing error. Between-iteration cancellation is guaranteed —
195
+ * the signal is checked before every iteration starts.
196
+ */
197
+ private runIterationLoop;
198
+ /**
199
+ * Run one iteration end-to-end: decide → dispatch → evaluate →
200
+ * snapshot. Returns `true` when the loop should continue to the
201
+ * next iteration, `false` when this iteration terminated the run
202
+ * (success or satisfied-verdict). Failures throw — the loop's
203
+ * outer catch converts them into typed errors on the result.
204
+ */
205
+ private runIteration;
206
+ /**
207
+ * Resolve the dispatch decision for this iteration — defers to
208
+ * `decide.ts`. When `carriedFeedback.reassignTo` is set the
209
+ * supervisor overrides the router/route decision with an
210
+ * evaluator-forced dispatch (design §2 — "Evaluate can override
211
+ * router").
212
+ */
213
+ private decideDispatch;
214
+ /**
215
+ * Dispatch every intent named by the decision in parallel. Per-
216
+ * branch errors don't abort siblings — they're recorded on the
217
+ * branch snapshot and let evaluate (or default termination logic)
218
+ * decide the response.
219
+ */
220
+ private dispatchBranches;
221
+ /**
222
+ * Execute a single branch — resolve the input, invoke the
223
+ * agent / workflow / callback, apply the per-intent `output`
224
+ * transformer, and produce an immutable `AgentBranchSnapshot`.
225
+ */
226
+ private dispatchOne;
227
+ /**
228
+ * Dispatch a callback intent as a top-level branch — produces an
229
+ * `AgentBranchSnapshot` and pushes the synthesized callback report
230
+ * onto the supervisor's recursive children. Delegates the actual
231
+ * callback invocation to {@link runCallback} so nested
232
+ * `ctx.intents.X.execute()` calls can reuse the same machinery.
233
+ *
234
+ * Each branch dispatch starts with a fresh per-branch call stack —
235
+ * sibling fan-out branches don't share cycle-detection state, so
236
+ * branch A and branch B both invoking the same intent isn't a
237
+ * cycle. The branch's own intent name is seeded onto the stack so
238
+ * a callback that re-enters itself via `ctx.intents.X.execute()` trips
239
+ * cycle detection on the first recursion.
240
+ */
241
+ private dispatchCallback;
242
+ /**
243
+ * Run a callback intent and produce its leaf report + final
244
+ * output. Used both for top-level branch dispatch (via
245
+ * {@link dispatchCallback}) and for nested `dispatch.byName`
246
+ * recursion. The synthesized report is appended to `reportSink`,
247
+ * which is either `this.childReports` (top-level) or the calling
248
+ * callback's own `children[]` (nested) — that's what gives the
249
+ * unified report tree its compositional shape.
250
+ *
251
+ * Usage on the report rolls up children's usage; the callback
252
+ * itself contributes zero (it's dev code, no token spend).
253
+ */
254
+ private runCallback;
255
+ /**
256
+ * Build a {@link DispatchContext} with a typed `intents` map of
257
+ * `IntentRunner` closures, each closing over the supplied call
258
+ * stack and report sink. Cycle detection uses the call stack —
259
+ * re-entering an intent already on it throws
260
+ * `SupervisorFailedError` with code `SUPERVISOR_DISPATCH_CYCLE`
261
+ * and the offending chain in the message.
262
+ *
263
+ * Replaces the Phase-3.3 `ctx.dispatch.byName` plumbing with
264
+ * property-access on a typed map (Q5/Q6) — autocomplete, no typo
265
+ * crashes, `.execute()` matches every other primitive's verb.
266
+ */
267
+ private seedDispatchContext;
268
+ /**
269
+ * Backing implementation for `ctx.intents.X.execute(input?)`.
270
+ * Looks up the named intent in the supervisor's registry, asserts
271
+ * the call wouldn't close a cycle, and runs the dispatchable
272
+ * through the same machinery a top-level branch would — except
273
+ * the resulting report nests under the calling callback's
274
+ * `children[]` rather than the supervisor's top-level child list,
275
+ * and only the final output is returned (no snapshot).
276
+ */
277
+ private runIntent;
278
+ /**
279
+ * Backing implementation for `ctx.intents.X.stream(input?)` (Phase 6
280
+ * / decisions §36). Streaming sibling of {@link runIntent} — same
281
+ * cycle protection, same auto-merge of supervisor-level concerns,
282
+ * but routes through the unit's `.stream()` method when available
283
+ * and bubbles deltas as `supervisor.agent.streaming` under the
284
+ * **calling callback's** intent name (not the dispatched intent's).
285
+ */
286
+ private streamIntent;
287
+ /**
288
+ * Backing implementation for `ctx.run(executable, input, options?)`
289
+ * (Phase 6 / decisions §36). Runs an inline / un-registered
290
+ * executable under supervision: auto-merges `signal`, `toolCtx`,
291
+ * `history` defaults; nests the resulting report under the
292
+ * calling callback's `children[]`. Per-call options REPLACE auto-
293
+ * defaults — standard Warlock convention.
294
+ *
295
+ * Cycle protection by executable `name` matches the registered-
296
+ * intent path so a callback that recurses on the same agent trips
297
+ * the same error, regardless of whether the agent was looked up
298
+ * via `ctx.intents.X.execute()` or passed inline.
299
+ */
300
+ private runInline;
301
+ /**
302
+ * Backing implementation for `ctx.stream(executable, input, options?)`
303
+ * (Phase 6 / decisions §36). Streaming sibling of {@link runInline}.
304
+ * Routes through the executable's native `.stream()` method,
305
+ * subscribes to delta events, and bubbles them as
306
+ * `supervisor.agent.streaming` under the calling callback's intent
307
+ * name. The returned `StreamContract` is the executable's own —
308
+ * iteration and `.result` work identically.
309
+ *
310
+ * Cycle protection on entry mirrors {@link runInline}; release runs
311
+ * after `.result` settles so a same-callback recursion is caught
312
+ * regardless of which path closed the cycle.
313
+ */
314
+ private streamInline;
315
+ /**
316
+ * Shared wiring for both `ctx.intents.X.stream()` and
317
+ * `ctx.stream(...)`. Subscribes to the executable's stream, re-
318
+ * emits deltas as `supervisor.agent.streaming` under the calling
319
+ * callback's intent name, and pushes the inner report onto the
320
+ * reportSink once `.result` settles. The returned StreamContract
321
+ * is the executable's own — the framework attaches handlers
322
+ * transparently via `.on(...)`.
323
+ */
324
+ private streamSupervisedExecutable;
325
+ /**
326
+ * Build the options object passed into an inline `.execute()` /
327
+ * `.stream()` call. Auto-merges supervisor-level defaults
328
+ * (`signal`, `toolCtx`, `history` window) under the caller's
329
+ * options. Per-call values REPLACE the auto-defaults — when the
330
+ * dev passes `signal: undefined` they explicitly opt out.
331
+ */
332
+ private mergeInlineOptions;
333
+ /**
334
+ * Coerce an arbitrary inline input into the shape the underlying
335
+ * executable expects. Agents take `string`; workflows + supervisors
336
+ * take whatever they declared. We safe-stringify objects only when
337
+ * passing to an agent — workflow / supervisor calls hand the value
338
+ * through unchanged so structured inputs work.
339
+ */
340
+ private coerceInlineInput;
341
+ /**
342
+ * Heuristic detection of `SupervisorContract` — the contract carries
343
+ * a `signature` getter same as workflows, but supervisors expose
344
+ * `resume()` while workflows expose `resume(runId, options)` too.
345
+ * Cleanest distinguisher in the public surface: supervisors carry
346
+ * the `asTool` method name `as` … unfortunately so do workflows.
347
+ * Use the `streamableType` brand if we add one in v2; for now lean
348
+ * on a duck-typed check that's good enough for the ctx.run path
349
+ * (incorrect routing for workflows would still produce a runnable
350
+ * call — workflow.execute accepts the same args either way).
351
+ */
352
+ private isSupervisor;
353
+ /**
354
+ * Invoke the underlying dispatchable unit. Agents and workflows
355
+ * both satisfy `ExecutableContract<string, …>` so the call shape
356
+ * is uniform; the `type` discriminator picks which options get
357
+ * threaded through (e.g. per-call stream event bubbling for
358
+ * agents, which we wire inline so child agent tokens surface as
359
+ * `supervisor.agent.streaming`).
360
+ */
361
+ private invokeUnit;
362
+ /**
363
+ * Build the input string passed to a branch's child execution.
364
+ * Default: pass the supervisor's original `ctx.input` through
365
+ * unchanged. The per-intent `entry.input` override is the escape
366
+ * hatch for the rare case where the agent's user message itself
367
+ * must vary per intent.
368
+ *
369
+ * Q17 lock: dropped `composeAgentInput` + `defaultComposeAgentInput`.
370
+ * Their three jobs (carry original / prior outputs / feedback) all
371
+ * have cleaner homes in the new model — original is the input
372
+ * itself, prior outputs are state (Stage 4b), feedback is a
373
+ * router-only signal (Q18).
374
+ */
375
+ private resolveBranchInput;
376
+ /**
377
+ * Strip-merge the agent/workflow's raw output against the per-intent
378
+ * `output` schema (Q11/Q13). Returns the validated slice that:
379
+ *
380
+ * 1. Lands on `IterationSnapshot.result[intent].output` (so
381
+ * consumers see the same shape that hit state).
382
+ * 2. Shallow-merges into `this.state` (handled by the caller).
383
+ *
384
+ * When `entry.output` is omitted the agent's full `data` (or `text`
385
+ * fallback for unstructured agents) flows through unvalidated — but
386
+ * is NOT auto-merged into state. State contribution is opt-in via
387
+ * declaring the slice schema.
388
+ *
389
+ * Validation failure surfaces as a per-branch error on the
390
+ * snapshot; sibling branches still run.
391
+ */
392
+ private applyOutputSchema;
393
+ /**
394
+ * Fire the receptionist (`ack`) — runs in parallel with phase A on
395
+ * iteration 0 only. Accepts three shapes:
396
+ *
397
+ * - `AckEntry` — `{ agent, placeholders?, input?, output? }`. LLM
398
+ * form. Streams tokens via `supervisor.ack.streaming`; report
399
+ * node pushes onto `childReports[]`.
400
+ * - `AckRunEntry` — `{ run, output? }`. Pure-code callback. Settles
401
+ * without an LLM call. No streaming events; just `.completed`.
402
+ * - `AckCallback` — bare `(ctx) => slice` shorthand for the
403
+ * pure-code form when no schema is declared.
404
+ *
405
+ * Failures are recorded but never abort the run — the receptionist
406
+ * tripping doesn't stop the specialist from doing the actual job.
407
+ * The returned outcome is what `mergeAckIntoState` consumes.
408
+ */
409
+ private runAck;
410
+ /**
411
+ * Pure-code receptionist path — invokes the callback, strip-validates
412
+ * the return value (when an `output` schema is declared), records the
413
+ * snapshot, emits `supervisor.ack.completed`, returns the outcome.
414
+ * No streaming events fire (callbacks settle synchronously from the
415
+ * supervisor's POV).
416
+ */
417
+ private runAckCallback;
418
+ /**
419
+ * Agent-driven receptionist path — invokes the agent, streams tokens
420
+ * via `supervisor.ack.streaming`, captures the report node, strip-
421
+ * validates against `output` (when declared), records the snapshot,
422
+ * emits `supervisor.ack.completed`.
423
+ */
424
+ private runAckAgent;
425
+ /**
426
+ * Probe the ack promise non-blockingly. Yields one macrotask cycle
427
+ * (`setImmediate`) so an already-resolved ack wins via microtask
428
+ * priority; if the probe returns first, the slice is abandoned —
429
+ * warning logged, error captured on `report.ack`, run completes
430
+ * regardless. Specialists own the actual answer; the receptionist
431
+ * was just a reassuring preview.
432
+ */
433
+ private settleAck;
434
+ /**
435
+ * Merge the receptionist's strip-validated slice into state. Called
436
+ * from `settleAck` BEFORE branch merges so specialists override the
437
+ * receptionist on key collision — the receptionist hedges, the
438
+ * specialist commits.
439
+ */
440
+ private mergeAckIntoState;
441
+ /**
442
+ * Run the iter-0 classifier prelude (Phase 7 / decisions §37).
443
+ * Resolves the configured classifier (agent / callback / entry
444
+ * form), invokes it, runs the optional `refine` post-process hook,
445
+ * and either:
446
+ *
447
+ * - sets `carriedClassifierDispatch` so the upcoming
448
+ * `decideDispatch` short-circuits to the chosen intent, OR
449
+ * - sets `classifierHalted = true` so `runIteration` terminates
450
+ * before any dispatch (refine returned `END`).
451
+ *
452
+ * Captures the full forensic record on `classifierSnapshot` —
453
+ * surfaced on `SupervisorReport.classifier` and threaded into
454
+ * `ctx.classifier` on every downstream context.
455
+ *
456
+ * Errors in the classifier OR the refine hook abort the run with
457
+ * a `SupervisorFailedError` so issues surface loudly instead of
458
+ * silently falling through to router/route.
459
+ */
460
+ private runClassifier;
461
+ /**
462
+ * Resolve the configured classifier into a callable that returns
463
+ * `{ output, usage }`. Handles the four accepted shapes — bare
464
+ * agent / bare callback / agent-entry / run-entry. Pure shape
465
+ * normalization; no side effects.
466
+ */
467
+ private invokeClassifier;
468
+ /**
469
+ * Invoke a classifier agent with the supervisor's standard wiring
470
+ * — placeholders, input override, history slicing, signal,
471
+ * streaming bubble. Output schema validation belongs to the agent
472
+ * itself; we just pull the typed `data` (or fall back to parsing
473
+ * `text`) and assert the locked `intent` field.
474
+ */
475
+ private invokeClassifierAgent;
476
+ /**
477
+ * Coerce an agent's output into the locked classifier shape.
478
+ * Accepts a typed object with `intent` (the canonical case) or a
479
+ * plain string (interpreted as the intent name with no reasoning).
480
+ * Throws `SupervisorFailedError` if neither shape matches.
481
+ */
482
+ private coerceClassifierOutput;
483
+ /**
484
+ * Build the read-only context passed to a classifier callback / agent
485
+ * resolvers. No dispatch helpers — registered intents haven't fired
486
+ * yet; pre-running them from the classifier would be confusing.
487
+ */
488
+ private buildClassifierContext;
489
+ /**
490
+ * Build the refine context — extends ClassifierContext with the
491
+ * classifier's just-resolved output plus `run` / `stream` so the
492
+ * refine hook can spin up secondary classifiers / validators
493
+ * inline (Phase 6 features).
494
+ */
495
+ private buildClassifierRefineContext;
496
+ /**
497
+ * Pull the optional `refine` hook off whichever classifier-config
498
+ * shape was supplied. Bare-callback and bare-agent forms have no
499
+ * refine; only entry forms do.
500
+ */
501
+ private resolveRefineHook;
502
+ /**
503
+ * Interpret a refine return value into actionable bits — final
504
+ * classifier output to dispatch, slice-to-merge, halted/refined
505
+ * flags, or an error. See {@link ClassifierRefineResult} for the
506
+ * accepted shapes.
507
+ */
508
+ private interpretRefineResult;
509
+ /**
510
+ * Run the `evaluate` callback (when configured) after the
511
+ * iteration's branches settle and outputs have merged into state.
512
+ * Errors in the callback surface as `SupervisorFailedError` so a
513
+ * buggy evaluate doesn't silently swallow the whole run.
514
+ *
515
+ * Phase 3.4 (Stage 4b) — `EvaluateContext.state` carries the
516
+ * post-merge accumulator so verdicts can be state-aware. Q9
517
+ * lifted the router-only restriction; evaluate now runs in both
518
+ * router and route modes.
519
+ */
520
+ private runEvaluate;
521
+ /**
522
+ * Merge each branch's output into supervisor `state` in
523
+ * `decision.intents` order — Q15 conflict rule: last intent in
524
+ * the array wins on key collisions. Errored branches don't
525
+ * contribute. Non-object outputs (primitives, null) are skipped
526
+ * with a warning log; they can't shallow-merge into an object.
527
+ *
528
+ * For agent/workflow intents: merging is opt-in via declaring an
529
+ * `output` schema (the strip-merge gate). Without a schema, the
530
+ * raw output stays on the branch snapshot but doesn't pollute
531
+ * state. For callback intents: their return is already strip-merged
532
+ * (or pass-through) inside `runCallback` — we just merge what's on
533
+ * the branch snapshot.
534
+ */
535
+ private mergeBranchesIntoState;
536
+ /**
537
+ * Merge the iteration's accumulated `currentArtifacts` bag into
538
+ * supervisor state (Phase 5 / decisions §35). Runs once per
539
+ * iteration after branch slices land and before evaluate.
540
+ *
541
+ * Order of operations:
542
+ *
543
+ * 1. **Empty-bag fast path** — if no tool wrote anything, skip
544
+ * validation and merge entirely; reset the bag for the next
545
+ * iteration is also a no-op (already empty).
546
+ * 2. **Schema validation** — when `config.artifactsSchema` is set,
547
+ * validate the bag against it. Failure aborts the iteration via
548
+ * a thrown `SchemaValidationError`; the iteration loop's outer
549
+ * catch surfaces it on `result.error`. Validation is opt-in
550
+ * (no schema → no validation cost).
551
+ * 3. **Merge** — `config.finalizeArtifacts` when supplied, else
552
+ * auto-spread `state = { ...state, ...artifacts }`. Replace
553
+ * semantics under auto-spread; `finalizeArtifacts` carries
554
+ * full responsibility for concat / dedupe / cross-iteration
555
+ * accumulation when configured.
556
+ * 4. **Reset** — `currentArtifacts = {}`. The next iteration's
557
+ * tool calls start with a fresh empty bag; long runs never
558
+ * accumulate raw artifacts here.
559
+ */
560
+ private mergeArtifactsIntoState;
561
+ /**
562
+ * Collect each branch's `intent.next(ctx)` directive after state
563
+ * merge (Stage 4d / Q24). Iterates `decision.intents` order so
564
+ * union resolution is deterministic.
565
+ *
566
+ * Rules:
567
+ * - Errored branch → silent (treated as if no `next` defined).
568
+ * - Branch with no `next` → silent; abstains (does NOT drag the
569
+ * iteration to the router).
570
+ * - Branch returns `END` → supreme; terminates immediately and
571
+ * discards other branches' opinions.
572
+ * - Branch returns `string` or `string[]` → contributes to the
573
+ * union of unique intent names. Validated against the
574
+ * supervisor's registry; unknown keys throw `SupervisorFailedError`.
575
+ * - All branches silent → returns `undefined`; caller falls back
576
+ * to router/route.
577
+ */
578
+ private collectIntentNext;
579
+ /**
580
+ * Finalize the supervisor result: validate accumulated state
581
+ * against the output schema and build the public `SupervisorResult`.
582
+ * Assemble-only — event emission and stream close happen in
583
+ * `run()` around this call.
584
+ */
585
+ private finalize;
586
+ /**
587
+ * Build the typed `data` at finalize. Stage 4c — single mode:
588
+ *
589
+ * - When `config.output` is declared, validate the accumulated
590
+ * `state` against it and return the validated value (Q8).
591
+ * `result.data` always matches the schema, or `result.error`
592
+ * carries the validation issues.
593
+ * - When `config.output` is omitted, return the raw state object.
594
+ *
595
+ * Validation failure surfaces as `SchemaValidationError` on
596
+ * `result.error`; the run is still considered semantically
597
+ * "completed" (intents ran, evaluate said done) but the typed
598
+ * data slot is empty.
599
+ */
600
+ private buildTypedData;
601
+ /**
602
+ * Record a snapshot for an iteration whose first decision was
603
+ * `END` — no dispatch, no evaluate, just the decision record. Keeps
604
+ * the snapshot log uniform so a late-route-to-END still appears in
605
+ * the forensic history rather than vanishing.
606
+ */
607
+ private recordTerminalDecisionSnapshot;
608
+ /**
609
+ * Write the current run state to the configured KV store (if any).
610
+ * Persistence failures surface as `supervisor.error` events and
611
+ * logged warnings but never abort the run — checkpoint best-effort
612
+ * by design, matching `workflow` semantics.
613
+ */
614
+ private checkpoint;
615
+ /**
616
+ * Between-iteration cancellation check. Called at the top of
617
+ * every iteration; signal abort here means the loop exits before
618
+ * any routing happens.
619
+ */
620
+ private throwIfCancelled;
621
+ /**
622
+ * Aggregate one usage record (typically a branch or a router call)
623
+ * into both the run-wide total and the iteration-local total.
624
+ */
625
+ private aggregateUsage;
626
+ /**
627
+ * Fan an event out through the three-tier emitter AND mirror it
628
+ * into the stream controller when streaming. Event names map 1:1
629
+ * to stream event types so consumers iterating the stream see the
630
+ * exact same surface as `.on()` / `options.on` handlers.
631
+ */
632
+ private emit;
633
+ private logEvent;
634
+ }
635
+ //#endregion
636
+ export { SupervisorExecution };
637
+ //# sourceMappingURL=execution.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execution.d.mts","names":[],"sources":["../../../../../../@warlock.js/ai/src/supervisor/execution.ts"],"mappings":";;;;;;;;;;KAsEY,yBAAA;EACV,MAAA,EAAQ,gBAAA,CAAiB,OAAA;EACzB,OAAA,EAAS,GAAA,SAAY,mBAAA;EACrB,SAAA;EACA,OAAA,EAAS,iBAAA;EACT,KAAA,EAAO,eAAA;EACP,KAAA;EACA,OAAA,GAAU,wBAAA;EACV,gBAAA,GAAmB,0BAAA,CAA2B,gBAAA,CAAiB,OAAA;EAC/D,UAAA,GAAa,kBAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA8BF,mBAAA;EAAA,iBACM,MAAA;EAAA,iBACA,OAAA;EAAA,iBACA,SAAA;EAAA,iBACA,OAAA;EAAA,iBACA,KAAA;EAAA,iBACA,KAAA;EAAA,iBACA,OAAA;EAAA,iBACA,gBAAA;EAAA,iBACA,UAAA;EAAA,iBAEA,aAAA;EAAA,iBACA,MAAA;EAAA,iBACA,SAAA;EAAA,iBAEA,SAAA;EAAA,iBACA,YAAA;EAAA,iBACA,KAAA;EAAA,iBAEA,YAAA;EAAA,iBACA,SAAA;EAAA,QAET,SAAA;EAAA,QACA,eAAA;EAhBS;;;;;;;;;EAAA,QA0BT,mBAAA;EAAA,QACA,YAAA;EAAA,QACA,MAAA;EAAA,QACA,cAAA;EAAA,QACA,KAAA;EAAA,QACA,IAAA;EAAA,QACA,mBAAA;EAHA;;;;;;EAAA,QAUA,KAAA;EAgCA;;;;;;;;;;EAAA,QArBA,gBAAA;EAuIA;;;;;;;;;;;EAAA,QA3HA,0BAAA;EA0xBM;;;;;;;;EAAA,QAjxBN,kBAAA;EAgxCA;;;;;EAAA,QA1wCA,yBAAA;EAkmDM;EAAA,QAhmDN,gBAAA;EAqwDA;;;;;EAAA,QA/vDA,WAAA;EA8pEA;;;;;;;EAAA,iBAtpES,OAAA;EA+nFH;;;;;;;;EAAA,iBAtnFG,OAAA;;;;;;;mBAOA,IAAA;cAEE,MAAA,EAAQ,yBAAA,CAA0B,OAAA;;;;;;;;;;;;;;;UA0E7C,iBAAA;;;;;;UAsCA,iBAAA;;;;;;;EAoBK,GAAA,CAAA,GAAO,OAAA,CAAQ,gBAAA,CAAiB,OAAA;;;;;;;UA6D/B,gBAAA;;;;;;;;UA0BA,YAAA;;;;;;;;UAkNA,cAAA;;;;;;;UA8HA,gBAAA;;;;;;UAaA,WAAA;;;;;;;;;;;;;;;UAsHA,gBAAA;;;;;;;;;;;;;UA2DA,WAAA;;;;;;;;;;;;;UAqFN,mBAAA;;;;;;;;;;UAwDM,SAAA;;;;;;;;;UA+FN,YAAA;;;;;;;;;;;;;;UA2DM,SAAA;;;;;;;;;;;;;;UAoDN,YAAA;;;;;;;;;;UAwCA,0BAAA;;;;;;;;UA+DA,kBAAA;;;;;;;;UAmCA,iBAAA;;;;;;;;;;;;UA0BA,YAAA;;;;;;;;;UAgBM,UAAA;;;;;;;;;;;;;;UA4FN,kBAAA;;;;;;;;;;;;;;;;;UAiCM,iBAAA;;;;;;;;;;;;;;;;;UA+DA,MAAA;;;;;;;;UAyEA,cAAA;;;;;;;UAmEA,WAAA;;;;;;;;;UAoHA,SAAA;;;;;;;UAiDN,iBAAA;;;;;;;;;;;;;;;;;;;;UA+BM,aAAA;;;;;;;UA4NA,gBAAA;;;;;;;;UA2DA,qBAAA;;;;;;;UAwDN,sBAAA;;;;;;UA+BA,sBAAA;;;;;;;UAkBA,4BAAA;;;;;;UAsBA,iBAAA;;;;;;;UAwBA,qBAAA;;;;;;;;;;;;UAoEM,WAAA;;;;;;;;;;;;;;;UA4CN,sBAAA;;;;;;;;;;;;;;;;;;;;;;;;;UAiFM,uBAAA;;;;;;;;;;;;;;;;;;UA+EN,iBAAA;;;;;;;UAmGM,QAAA;;;;;;;;;;;;;;;UAwEA,cAAA;;;;;;;UAcA,8BAAA;;;;;;;UAuCA,UAAA;;;;;;UAwBN,gBAAA;;;;;UAUA,cAAA;;;;;;;UAoBA,IAAA;EAAA,QAyBA,QAAA;AAAA"}