@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,22 @@
1
+ import { SupervisorCancelledError } from "../errors/supervisor-cancelled-error.mjs";
2
+ import "../errors/index.mjs";
3
+
4
+ //#region ../../@warlock.js/ai/src/supervisor/cancellation.ts
5
+ /**
6
+ * Build a `SupervisorCancelledError` from an `AbortSignal`. Extracts a
7
+ * human-readable reason from `signal.reason` whether it was a string,
8
+ * an `Error`, or some other value. Used at between-iteration boundaries
9
+ * and on any mid-iteration cancellation path.
10
+ */
11
+ function createCancelledError(signal) {
12
+ const reason = signal?.reason;
13
+ const reasonText = typeof reason === "string" ? reason : reason instanceof Error ? reason.message : reason === void 0 ? "" : String(reason);
14
+ return new SupervisorCancelledError(`supervisor cancelled${reasonText ? `: ${reasonText}` : ""}`, {
15
+ cancelledAt: (/* @__PURE__ */ new Date()).toISOString(),
16
+ reason: reasonText
17
+ });
18
+ }
19
+
20
+ //#endregion
21
+ export { createCancelledError };
22
+ //# sourceMappingURL=cancellation.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cancellation.mjs","names":[],"sources":["../../../../../../@warlock.js/ai/src/supervisor/cancellation.ts"],"sourcesContent":["import { SupervisorCancelledError } from \"../errors\";\n\n/**\n * Build a `SupervisorCancelledError` from an `AbortSignal`. Extracts a\n * human-readable reason from `signal.reason` whether it was a string,\n * an `Error`, or some other value. Used at between-iteration boundaries\n * and on any mid-iteration cancellation path.\n */\nexport function createCancelledError(\n signal: AbortSignal | undefined,\n): SupervisorCancelledError {\n const reason = signal?.reason;\n const reasonText =\n typeof reason === \"string\"\n ? reason\n : reason instanceof Error\n ? reason.message\n : reason === undefined\n ? \"\"\n : String(reason);\n\n return new SupervisorCancelledError(\n `supervisor cancelled${reasonText ? `: ${reasonText}` : \"\"}`,\n { cancelledAt: new Date().toISOString(), reason: reasonText },\n );\n}\n"],"mappings":";;;;;;;;;;AAQA,SAAgB,qBACd,QAC0B;CAC1B,MAAM,SAAS,QAAQ;CACvB,MAAM,aACJ,OAAO,WAAW,WACd,SACA,kBAAkB,QAChB,OAAO,UACP,WAAW,SACT,KACA,OAAO,MAAM;CAEvB,OAAO,IAAI,yBACT,uBAAuB,aAAa,KAAK,eAAe,MACxD;EAAE,8BAAa,IAAI,KAAK,GAAE,YAAY;EAAG,QAAQ;CAAW,CAC9D;AACF"}
@@ -0,0 +1,272 @@
1
+ import { AIError } from "../errors/ai-error.mjs";
2
+ import { SupervisorFailedError } from "../errors/supervisor-failed-error.mjs";
3
+ import { SupervisorRoutingError } from "../errors/supervisor-routing-error.mjs";
4
+ import "../errors/index.mjs";
5
+ import { END } from "../contracts/end.type.mjs";
6
+ import { buildRouterContextMessage } from "./router-prompt.mjs";
7
+
8
+ //#region ../../@warlock.js/ai/src/supervisor/decide.ts
9
+ /**
10
+ * Unified dispatch decision entry — calls either the `route` callback
11
+ * or the `router` agent based on the supervisor's configured mode and
12
+ * normalizes the result into a `DispatchDecision`. Runtime validates
13
+ * every routing value against the configured agent keys; unknown keys
14
+ * surface as `SupervisorRoutingError`.
15
+ */
16
+ async function decide(params) {
17
+ if (params.useInitialAgent && params.config.initialAgent) {
18
+ const intent = params.config.initialAgent;
19
+ validateKey(intent, params.entries);
20
+ return {
21
+ kind: "dispatch",
22
+ intents: [intent],
23
+ source: "initialAgent",
24
+ raw: intent,
25
+ durationMs: 0
26
+ };
27
+ }
28
+ if (params.config.route) return decideViaCallback(params);
29
+ if (params.config.router) return decideViaRouter(params);
30
+ throw new SupervisorFailedError(`ai.supervisor("${params.config.name}"): neither \`route\` nor \`router\` is configured — factory validation should have prevented this`, { context: { authoring: true } });
31
+ }
32
+ async function decideViaCallback(params) {
33
+ const started = performance.now();
34
+ const ctx = {
35
+ iteration: params.iteration,
36
+ input: params.input,
37
+ state: params.state,
38
+ iterations: params.iterations,
39
+ feedback: typeof params.evaluateFeedback?.feedback === "string" ? params.evaluateFeedback.feedback : void 0,
40
+ evaluateFeedback: params.evaluateFeedback,
41
+ context: params.context,
42
+ history: params.history,
43
+ goal: params.goal,
44
+ classifier: params.classifier
45
+ };
46
+ let raw;
47
+ try {
48
+ raw = await params.config.route(ctx);
49
+ } catch (thrown) {
50
+ throw wrapRouteError(params.config.name, thrown);
51
+ }
52
+ const durationMs = performance.now() - started;
53
+ return normalize(raw, params.entries, "route", durationMs);
54
+ }
55
+ async function decideViaRouter(params) {
56
+ const { agent, placeholders, inputOverride, historySlicer } = resolveRouterEntry(params.config.router);
57
+ const started = performance.now();
58
+ const routeCtx = {
59
+ iteration: params.iteration,
60
+ input: params.input,
61
+ state: params.state,
62
+ iterations: params.iterations,
63
+ feedback: typeof params.evaluateFeedback?.feedback === "string" ? params.evaluateFeedback.feedback : void 0,
64
+ evaluateFeedback: params.evaluateFeedback,
65
+ context: params.context,
66
+ history: params.history,
67
+ goal: params.goal
68
+ };
69
+ const userMessage = inputOverride?.(routeCtx) ?? buildRouterContextMessage({
70
+ entries: params.entries,
71
+ iteration: params.iteration,
72
+ maxIterations: params.maxIterations,
73
+ iterations: params.iterations,
74
+ input: params.input,
75
+ state: params.state,
76
+ feedback: routeCtx.feedback,
77
+ supervisorPrompt: resolveSupervisorPromptText(params.config),
78
+ goal: params.goal
79
+ });
80
+ const resolvedPlaceholders = placeholders?.(routeCtx);
81
+ const routerHistory = resolveRouterHistory(historySlicer, routeCtx, params.history, params.config.historyWindow?.router);
82
+ const routerResult = await agent.execute(userMessage, {
83
+ signal: params.signal,
84
+ output: ROUTER_OUTPUT_SCHEMA,
85
+ ...resolvedPlaceholders ? { placeholders: resolvedPlaceholders } : {},
86
+ ...routerHistory.length > 0 ? { history: routerHistory } : {}
87
+ });
88
+ const durationMs = performance.now() - started;
89
+ if (routerResult.error) throw routerResult.error instanceof AIError ? routerResult.error : new SupervisorFailedError(`router agent failed`, { cause: routerResult.error });
90
+ const data = routerResult.data;
91
+ if (!data || typeof data !== "object") throw new SupervisorRoutingError(`router agent returned no structured \`next\` — did its output schema include { next, reasoning? }?`, {
92
+ returned: data,
93
+ availableKeys: [...params.entries.keys()]
94
+ });
95
+ const rawNext = data.next;
96
+ const reasoning = data.reasoning;
97
+ if (rawNext === void 0) throw new SupervisorRoutingError(`router agent output missing \`next\` field`, {
98
+ returned: data,
99
+ availableKeys: [...params.entries.keys()]
100
+ });
101
+ return {
102
+ ...normalize(rawNext, params.entries, "router", durationMs),
103
+ reasoning: typeof reasoning === "string" ? reasoning : void 0,
104
+ usage: routerResult.usage,
105
+ routerReport: routerResult.report
106
+ };
107
+ }
108
+ /**
109
+ * Normalize the `router` config field — accepts either a bare
110
+ * `AgentContract` (shorthand) or a full `RouterEntry` — into a
111
+ * uniform `{ agent, placeholders?, inputOverride? }` triple. Centralized
112
+ * so the dispatch path doesn't branch on shape.
113
+ */
114
+ function resolveRouterEntry(router) {
115
+ if (typeof router.execute === "function") return { agent: router };
116
+ const entry = router;
117
+ return {
118
+ agent: entry.agent,
119
+ placeholders: entry.placeholders,
120
+ inputOverride: entry.input,
121
+ historySlicer: entry.history
122
+ };
123
+ }
124
+ /**
125
+ * Resolve the supervisor's own `systemPrompt` (string or contract)
126
+ * into plain text. Returns `undefined` when the supervisor didn't
127
+ * configure one. The resolved text is surfaced in the per-turn
128
+ * router user message so the router sees team/domain context without
129
+ * disturbing the router agent's own factory-level system prompt —
130
+ * functionally equivalent to prepending, without requiring an API
131
+ * expansion on `AgentContract` to read the router's system prompt.
132
+ */
133
+ function resolveSupervisorPromptText(config) {
134
+ if (!config.systemPrompt) return;
135
+ return typeof config.systemPrompt === "string" ? config.systemPrompt : config.systemPrompt.resolve();
136
+ }
137
+ /**
138
+ * Convert the raw routing value (callback return OR router agent
139
+ * `next` field) into a canonical `DispatchDecision`, validating every
140
+ * named intent against the supervisor's `intents` map.
141
+ */
142
+ function normalize(raw, entries, source, durationMs) {
143
+ if (isEnd(raw)) return {
144
+ kind: "end",
145
+ source,
146
+ raw,
147
+ durationMs
148
+ };
149
+ if (typeof raw === "string") {
150
+ validateKey(raw, entries);
151
+ return {
152
+ kind: "dispatch",
153
+ intents: [raw],
154
+ source,
155
+ raw,
156
+ durationMs
157
+ };
158
+ }
159
+ if (Array.isArray(raw)) {
160
+ if (raw.length === 0) throw new SupervisorRoutingError(`router returned an empty array — must be a non-empty list of agent intents`, {
161
+ returned: raw,
162
+ availableKeys: [...entries.keys()]
163
+ });
164
+ for (const intent of raw) {
165
+ if (typeof intent !== "string") throw new SupervisorRoutingError(`router returned a non-string inside its fan-out array`, {
166
+ returned: raw,
167
+ availableKeys: [...entries.keys()]
168
+ });
169
+ validateKey(intent, entries);
170
+ }
171
+ return {
172
+ kind: "dispatch",
173
+ intents: raw,
174
+ source,
175
+ raw,
176
+ durationMs
177
+ };
178
+ }
179
+ throw new SupervisorRoutingError(`router returned an unsupported value — expected a string, string[], or END`, {
180
+ returned: raw,
181
+ availableKeys: [...entries.keys()]
182
+ });
183
+ }
184
+ function validateKey(intent, entries) {
185
+ if (!entries.has(intent)) throw new SupervisorRoutingError(`router returned unknown agent key "${intent}"`, {
186
+ returned: intent,
187
+ availableKeys: [...entries.keys()]
188
+ });
189
+ }
190
+ function isEnd(value) {
191
+ return value === END;
192
+ }
193
+ /**
194
+ * Resolve the history slice forwarded to the router agent. Mirrors
195
+ * `SupervisorExecution.resolveHistoryFor("router", ...)` — duplicated
196
+ * here so the standalone `decide()` function stays callable without
197
+ * threading the execution instance through. Precedence is identical:
198
+ * entry slicer > `historyWindow.router` > full history.
199
+ */
200
+ function resolveRouterHistory(slicer, routeCtx, full, window) {
201
+ if (slicer) {
202
+ const sliced = slicer(routeCtx);
203
+ return sliced ? [...sliced] : [];
204
+ }
205
+ if (window === void 0 || window < 0) return [...full];
206
+ if (window === 0) return [];
207
+ return full.slice(-window);
208
+ }
209
+ /**
210
+ * JSON Schema form of the canonical router output shape. Surfaced via
211
+ * the Standard JSON Schema V1 extension path (`["~standard"].jsonSchema.input`)
212
+ * so `extractJsonSchema()` can pull it for native structured-output
213
+ * enforcement on capable providers (OpenAI strict json_schema mode,
214
+ * Anthropic tool-use shape, etc.). Without this, the model is told to
215
+ * emit JSON only via soft system-prompt instruction — fragile, and
216
+ * skipped entirely when the model advertises `structuredOutput: true`.
217
+ *
218
+ * `next` is intentionally `string` (not a union with arrays) because
219
+ * OpenAI strict mode rejects polymorphic root types — fan-out via
220
+ * `string[]` is still validated at the framework layer; the model
221
+ * just emits a single intent name (or the END sentinel) and the
222
+ * supervisor's own normalizer handles the rest.
223
+ */
224
+ const ROUTER_OUTPUT_JSON_SCHEMA = {
225
+ type: "object",
226
+ properties: {
227
+ next: {
228
+ type: "string",
229
+ description: "Name of the agent to dispatch next, or the END sentinel to terminate the run."
230
+ },
231
+ reasoning: {
232
+ type: "string",
233
+ description: "One-sentence justification for the routing choice."
234
+ }
235
+ },
236
+ required: ["next", "reasoning"],
237
+ additionalProperties: false
238
+ };
239
+ /**
240
+ * Canonical Standard Schema the supervisor injects when calling the
241
+ * router agent. Pragmatic — accepts any `next` shape the router can
242
+ * plausibly emit (`string`, `string[]`, or the `END` literal) plus an
243
+ * optional `reasoning` field. Rejects anything else so a broken
244
+ * router output surfaces cleanly via the agent's own validation path.
245
+ *
246
+ * Exposes `["~standard"].jsonSchema.input()` (Standard JSON Schema V1)
247
+ * so capable providers enforce the shape natively rather than relying
248
+ * on prompt-side coaching.
249
+ */
250
+ const ROUTER_OUTPUT_SCHEMA = { "~standard": {
251
+ version: 1,
252
+ vendor: "warlock-supervisor",
253
+ jsonSchema: { input: () => ROUTER_OUTPUT_JSON_SCHEMA },
254
+ validate(value) {
255
+ if (!value || typeof value !== "object") return { issues: [{ message: "router output must be an object" }] };
256
+ const record = value;
257
+ const rawNext = record.next;
258
+ if (!(typeof rawNext === "string" || Array.isArray(rawNext) && rawNext.every((element) => typeof element === "string"))) return { issues: [{ message: "router output `next` must be a string, string[], or the END sentinel" }] };
259
+ return { value: {
260
+ next: rawNext,
261
+ reasoning: typeof record.reasoning === "string" ? record.reasoning : void 0
262
+ } };
263
+ }
264
+ } };
265
+ function wrapRouteError(supervisorName, thrown) {
266
+ if (thrown instanceof AIError) return thrown;
267
+ return new SupervisorFailedError(`\`route\` callback threw in supervisor "${supervisorName}": ${thrown instanceof Error ? thrown.message : String(thrown)}`, { cause: thrown });
268
+ }
269
+
270
+ //#endregion
271
+ export { decide };
272
+ //# sourceMappingURL=decide.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decide.mjs","names":[],"sources":["../../../../../../@warlock.js/ai/src/supervisor/decide.ts"],"sourcesContent":["import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { AgentContract } from \"../contracts/agent/agent.contract\";\nimport type { Message } from \"../contracts/conversation-message.type\";\nimport { END, type EndSentinel } from \"../contracts/end.type\";\nimport type { BaseReport } from \"../contracts/result/base-report.type\";\nimport type { IterationSnapshot } from \"../contracts/supervisor/iteration-snapshot.type\";\nimport type { Next } from \"../contracts/supervisor/next.type\";\nimport type { RouteContext } from \"../contracts/supervisor/route-context.type\";\nimport type { RouterEntry } from \"../contracts/supervisor/router-entry.type\";\nimport type { SupervisorConfig } from \"../contracts/supervisor/supervisor-config.type\";\nimport type { SupervisorInput } from \"../contracts/supervisor/supervisor-input.type\";\nimport { AIError, SupervisorFailedError, SupervisorRoutingError } from \"../errors\";\nimport type { ResolvedIntentEntry } from \"./entries\";\nimport { buildRouterContextMessage } from \"./router-prompt\";\n\n/**\n * Outcome of one dispatch decision — what the iteration loop needs to\n * act on. `kind: \"end\"` signals termination; `kind: \"dispatch\"` carries\n * the resolved intents (always an array; single-agent dispatch has\n * length 1). `source` records which path made the call so the\n * iteration snapshot can surface it to debuggers.\n */\nexport type DispatchDecision =\n | {\n kind: \"end\";\n source: \"route\" | \"router\" | \"initialAgent\" | \"classifier\";\n raw: Next;\n reasoning?: string;\n durationMs: number;\n usage?: { input: number; output: number; total: number };\n /** Full router-agent report when this decision came from a router. */\n routerReport?: BaseReport;\n }\n | {\n kind: \"dispatch\";\n intents: string[];\n source: \"route\" | \"router\" | \"initialAgent\" | \"classifier\";\n raw: Next;\n reasoning?: string;\n durationMs: number;\n usage?: { input: number; output: number; total: number };\n /** Full router-agent report when this decision came from a router. */\n routerReport?: BaseReport;\n };\n\nexport type DecideParams = {\n config: SupervisorConfig<unknown>;\n entries: Map<string, ResolvedIntentEntry>;\n iteration: number;\n maxIterations: number;\n iterations: IterationSnapshot[];\n input: SupervisorInput;\n /**\n * Per-execute state accumulator at the start of this iteration.\n * Threaded into `RouteContext` for the route callback and\n * rendered into the router prompt so routing decisions can be\n * state-aware (Q14).\n */\n state: Record<string, unknown>;\n /**\n * Frozen request-scoped bag from the `execute({ context })` call —\n * surfaced on `RouteContext.context` for both `route` callbacks\n * and `RouterEntry.placeholders` / `RouterEntry.input` resolvers.\n */\n context: Readonly<Record<string, unknown>>;\n /**\n * Frozen prior-conversation history from `execute({ history })` —\n * surfaced on `RouteContext.history` and forwarded to the router\n * agent as `agent.execute(input, { history })` so router decisions\n * are conversation-aware.\n */\n history: ReadonlyArray<Message>;\n /**\n * Resolved natural-language objective from `SupervisorConfig.goal`\n * (materialized to plain text at supervisor construction). Surfaced\n * on `RouteContext.goal` for `route` / `RouterEntry` resolvers, and\n * injected into the router agent's per-turn user message via\n * `buildRouterContextMessage`. `undefined` when no goal was set.\n */\n goal: string | undefined;\n evaluateFeedback?: RouteContext[\"evaluateFeedback\"];\n /**\n * Forensic record of the iter-0 classifier (Phase 7). Threaded into\n * `RouteContext.classifier` so route callbacks and router-agent\n * input composers can read the classification trail without\n * re-parsing state.\n */\n classifier?: RouteContext[\"classifier\"];\n signal?: AbortSignal;\n /**\n * Override for the very first iteration — when `initialAgent` is\n * set, the first turn skips `route`/`router` and dispatches the\n * named intent directly. `runIteration` passes `true` only on turn\n * 0 when the config has `initialAgent`.\n */\n useInitialAgent?: boolean;\n};\n\n/**\n * Unified dispatch decision entry — calls either the `route` callback\n * or the `router` agent based on the supervisor's configured mode and\n * normalizes the result into a `DispatchDecision`. Runtime validates\n * every routing value against the configured agent keys; unknown keys\n * surface as `SupervisorRoutingError`.\n */\nexport async function decide(params: DecideParams): Promise<DispatchDecision> {\n if (params.useInitialAgent && params.config.initialAgent) {\n const intent = params.config.initialAgent;\n validateKey(intent, params.entries);\n\n return {\n kind: \"dispatch\",\n intents: [intent],\n source: \"initialAgent\",\n raw: intent,\n durationMs: 0,\n };\n }\n\n if (params.config.route) {\n return decideViaCallback(params);\n }\n\n if (params.config.router) {\n return decideViaRouter(params);\n }\n\n throw new SupervisorFailedError(\n `ai.supervisor(\"${params.config.name}\"): neither \\`route\\` nor \\`router\\` is configured — factory validation should have prevented this`,\n { context: { authoring: true } },\n );\n}\n\nasync function decideViaCallback(params: DecideParams): Promise<DispatchDecision> {\n const started = performance.now();\n const ctx: RouteContext = {\n iteration: params.iteration,\n input: params.input,\n state: params.state,\n iterations: params.iterations,\n feedback:\n typeof params.evaluateFeedback?.feedback === \"string\"\n ? params.evaluateFeedback.feedback\n : undefined,\n evaluateFeedback: params.evaluateFeedback,\n context: params.context,\n history: params.history,\n goal: params.goal,\n classifier: params.classifier,\n };\n\n let raw: Next;\n\n try {\n raw = await params.config.route!(ctx);\n } catch (thrown) {\n throw wrapRouteError(params.config.name, thrown);\n }\n\n const durationMs = performance.now() - started;\n\n return normalize(raw, params.entries, \"route\", durationMs);\n}\n\nasync function decideViaRouter(params: DecideParams): Promise<DispatchDecision> {\n const { agent, placeholders, inputOverride, historySlicer } = resolveRouterEntry(\n params.config.router!,\n );\n const started = performance.now();\n\n const routeCtx: RouteContext = {\n iteration: params.iteration,\n input: params.input,\n state: params.state,\n iterations: params.iterations,\n feedback:\n typeof params.evaluateFeedback?.feedback === \"string\"\n ? params.evaluateFeedback.feedback\n : undefined,\n evaluateFeedback: params.evaluateFeedback,\n context: params.context,\n history: params.history,\n goal: params.goal,\n };\n\n const userMessage =\n inputOverride?.(routeCtx) ??\n buildRouterContextMessage({\n entries: params.entries,\n iteration: params.iteration,\n maxIterations: params.maxIterations,\n iterations: params.iterations,\n input: params.input,\n state: params.state,\n feedback: routeCtx.feedback,\n supervisorPrompt: resolveSupervisorPromptText(params.config),\n goal: params.goal,\n });\n\n const resolvedPlaceholders = placeholders?.(routeCtx);\n\n // Inject the canonical router output schema so the supervisor gets\n // a predictable `{ next, reasoning? }` shape regardless of what the\n // user scripted on the router agent. Lets the router stay a plain\n // agent — no supervisor-specific config needed at construction.\n const routerHistory = resolveRouterHistory(\n historySlicer,\n routeCtx,\n params.history,\n params.config.historyWindow?.router,\n );\n\n const routerResult = await agent.execute(userMessage, {\n signal: params.signal,\n output: ROUTER_OUTPUT_SCHEMA as unknown as StandardSchemaV1<{\n next: Next;\n reasoning?: string;\n }>,\n ...(resolvedPlaceholders ? { placeholders: resolvedPlaceholders } : {}),\n ...(routerHistory.length > 0 ? { history: routerHistory } : {}),\n });\n\n const durationMs = performance.now() - started;\n\n if (routerResult.error) {\n throw routerResult.error instanceof AIError\n ? routerResult.error\n : new SupervisorFailedError(`router agent failed`, {\n cause: routerResult.error,\n });\n }\n\n const data = routerResult.data;\n\n if (!data || typeof data !== \"object\") {\n throw new SupervisorRoutingError(\n `router agent returned no structured \\`next\\` — did its output schema include { next, reasoning? }?`,\n { returned: data, availableKeys: [...params.entries.keys()] },\n );\n }\n\n const rawNext = (data as { next?: unknown }).next;\n const reasoning = (data as { reasoning?: unknown }).reasoning;\n\n if (rawNext === undefined) {\n throw new SupervisorRoutingError(`router agent output missing \\`next\\` field`, {\n returned: data,\n availableKeys: [...params.entries.keys()],\n });\n }\n\n const decision = normalize(rawNext as Next, params.entries, \"router\", durationMs);\n\n return {\n ...decision,\n reasoning: typeof reasoning === \"string\" ? reasoning : undefined,\n usage: routerResult.usage,\n routerReport: routerResult.report,\n };\n}\n\n/**\n * Normalize the `router` config field — accepts either a bare\n * `AgentContract` (shorthand) or a full `RouterEntry` — into a\n * uniform `{ agent, placeholders?, inputOverride? }` triple. Centralized\n * so the dispatch path doesn't branch on shape.\n */\nfunction resolveRouterEntry(router: AgentContract<unknown> | RouterEntry): {\n agent: AgentContract<unknown>;\n placeholders?: RouterEntry[\"placeholders\"];\n inputOverride?: RouterEntry[\"input\"];\n historySlicer?: RouterEntry[\"history\"];\n} {\n if (typeof (router as { execute?: unknown }).execute === \"function\") {\n return { agent: router as AgentContract<unknown> };\n }\n\n const entry = router as RouterEntry;\n\n return {\n agent: entry.agent,\n placeholders: entry.placeholders,\n inputOverride: entry.input,\n historySlicer: entry.history,\n };\n}\n\n/**\n * Resolve the supervisor's own `systemPrompt` (string or contract)\n * into plain text. Returns `undefined` when the supervisor didn't\n * configure one. The resolved text is surfaced in the per-turn\n * router user message so the router sees team/domain context without\n * disturbing the router agent's own factory-level system prompt —\n * functionally equivalent to prepending, without requiring an API\n * expansion on `AgentContract` to read the router's system prompt.\n */\nfunction resolveSupervisorPromptText(config: SupervisorConfig<unknown>): string | undefined {\n if (!config.systemPrompt) {\n return undefined;\n }\n\n return typeof config.systemPrompt === \"string\"\n ? config.systemPrompt\n : config.systemPrompt.resolve();\n}\n\n/**\n * Convert the raw routing value (callback return OR router agent\n * `next` field) into a canonical `DispatchDecision`, validating every\n * named intent against the supervisor's `intents` map.\n */\nfunction normalize(\n raw: Next,\n entries: Map<string, ResolvedIntentEntry>,\n source: \"route\" | \"router\",\n durationMs: number,\n): DispatchDecision {\n if (isEnd(raw)) {\n return { kind: \"end\", source, raw, durationMs };\n }\n\n if (typeof raw === \"string\") {\n validateKey(raw, entries);\n\n return {\n kind: \"dispatch\",\n intents: [raw],\n source,\n raw,\n durationMs,\n };\n }\n\n if (Array.isArray(raw)) {\n if (raw.length === 0) {\n throw new SupervisorRoutingError(\n `router returned an empty array — must be a non-empty list of agent intents`,\n { returned: raw, availableKeys: [...entries.keys()] },\n );\n }\n\n for (const intent of raw) {\n if (typeof intent !== \"string\") {\n throw new SupervisorRoutingError(`router returned a non-string inside its fan-out array`, {\n returned: raw,\n availableKeys: [...entries.keys()],\n });\n }\n\n validateKey(intent, entries);\n }\n\n return {\n kind: \"dispatch\",\n intents: raw,\n source,\n raw,\n durationMs,\n };\n }\n\n throw new SupervisorRoutingError(\n `router returned an unsupported value — expected a string, string[], or END`,\n { returned: raw, availableKeys: [...entries.keys()] },\n );\n}\n\nfunction validateKey(intent: string, entries: Map<string, ResolvedIntentEntry>): void {\n if (!entries.has(intent)) {\n throw new SupervisorRoutingError(`router returned unknown agent key \"${intent}\"`, {\n returned: intent,\n availableKeys: [...entries.keys()],\n });\n }\n}\n\nfunction isEnd(value: unknown): value is EndSentinel {\n return value === END;\n}\n\n/**\n * Resolve the history slice forwarded to the router agent. Mirrors\n * `SupervisorExecution.resolveHistoryFor(\"router\", ...)` — duplicated\n * here so the standalone `decide()` function stays callable without\n * threading the execution instance through. Precedence is identical:\n * entry slicer > `historyWindow.router` > full history.\n */\nfunction resolveRouterHistory(\n slicer: RouterEntry[\"history\"] | undefined,\n routeCtx: RouteContext,\n full: ReadonlyArray<Message>,\n window: number | undefined,\n): Message[] {\n if (slicer) {\n const sliced = slicer(routeCtx);\n return sliced ? [...sliced] : [];\n }\n\n if (window === undefined || window < 0) {\n return [...full];\n }\n\n if (window === 0) {\n return [];\n }\n\n return full.slice(-window);\n}\n\n/**\n * JSON Schema form of the canonical router output shape. Surfaced via\n * the Standard JSON Schema V1 extension path (`[\"~standard\"].jsonSchema.input`)\n * so `extractJsonSchema()` can pull it for native structured-output\n * enforcement on capable providers (OpenAI strict json_schema mode,\n * Anthropic tool-use shape, etc.). Without this, the model is told to\n * emit JSON only via soft system-prompt instruction — fragile, and\n * skipped entirely when the model advertises `structuredOutput: true`.\n *\n * `next` is intentionally `string` (not a union with arrays) because\n * OpenAI strict mode rejects polymorphic root types — fan-out via\n * `string[]` is still validated at the framework layer; the model\n * just emits a single intent name (or the END sentinel) and the\n * supervisor's own normalizer handles the rest.\n */\nconst ROUTER_OUTPUT_JSON_SCHEMA = {\n type: \"object\",\n properties: {\n next: {\n type: \"string\",\n description: \"Name of the agent to dispatch next, or the END sentinel to terminate the run.\",\n },\n reasoning: {\n type: \"string\",\n description: \"One-sentence justification for the routing choice.\",\n },\n },\n required: [\"next\", \"reasoning\"],\n additionalProperties: false,\n};\n\n/**\n * Canonical Standard Schema the supervisor injects when calling the\n * router agent. Pragmatic — accepts any `next` shape the router can\n * plausibly emit (`string`, `string[]`, or the `END` literal) plus an\n * optional `reasoning` field. Rejects anything else so a broken\n * router output surfaces cleanly via the agent's own validation path.\n *\n * Exposes `[\"~standard\"].jsonSchema.input()` (Standard JSON Schema V1)\n * so capable providers enforce the shape natively rather than relying\n * on prompt-side coaching.\n */\nconst ROUTER_OUTPUT_SCHEMA: StandardSchemaV1<{\n next: Next;\n reasoning?: string;\n}> = {\n \"~standard\": {\n version: 1,\n vendor: \"warlock-supervisor\",\n jsonSchema: {\n input: () => ROUTER_OUTPUT_JSON_SCHEMA,\n },\n validate(value: unknown): StandardSchemaV1.Result<{ next: Next; reasoning?: string }> {\n if (!value || typeof value !== \"object\") {\n return { issues: [{ message: \"router output must be an object\" }] };\n }\n\n const record = value as { next?: unknown; reasoning?: unknown };\n const rawNext = record.next;\n\n const nextIsValid =\n typeof rawNext === \"string\" ||\n (Array.isArray(rawNext) && rawNext.every((element) => typeof element === \"string\"));\n\n if (!nextIsValid) {\n return {\n issues: [\n {\n message: \"router output `next` must be a string, string[], or the END sentinel\",\n },\n ],\n };\n }\n\n const reasoning = typeof record.reasoning === \"string\" ? record.reasoning : undefined;\n\n return {\n value: { next: rawNext as Next, reasoning },\n };\n },\n } as StandardSchemaV1<{ next: Next; reasoning?: string }>[\"~standard\"] & {\n jsonSchema: { input: () => Record<string, unknown> };\n },\n};\n\nfunction wrapRouteError(supervisorName: string, thrown: unknown): AIError {\n if (thrown instanceof AIError) {\n return thrown;\n }\n\n const message = thrown instanceof Error ? thrown.message : String(thrown);\n\n return new SupervisorFailedError(\n `\\`route\\` callback threw in supervisor \"${supervisorName}\": ${message}`,\n { cause: thrown },\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;AAyGA,eAAsB,OAAO,QAAiD;CAC5E,IAAI,OAAO,mBAAmB,OAAO,OAAO,cAAc;EACxD,MAAM,SAAS,OAAO,OAAO;EAC7B,YAAY,QAAQ,OAAO,OAAO;EAElC,OAAO;GACL,MAAM;GACN,SAAS,CAAC,MAAM;GAChB,QAAQ;GACR,KAAK;GACL,YAAY;EACd;CACF;CAEA,IAAI,OAAO,OAAO,OAChB,OAAO,kBAAkB,MAAM;CAGjC,IAAI,OAAO,OAAO,QAChB,OAAO,gBAAgB,MAAM;CAG/B,MAAM,IAAI,sBACR,kBAAkB,OAAO,OAAO,KAAK,qGACrC,EAAE,SAAS,EAAE,WAAW,KAAK,EAAE,CACjC;AACF;AAEA,eAAe,kBAAkB,QAAiD;CAChF,MAAM,UAAU,YAAY,IAAI;CAChC,MAAM,MAAoB;EACxB,WAAW,OAAO;EAClB,OAAO,OAAO;EACd,OAAO,OAAO;EACd,YAAY,OAAO;EACnB,UACE,OAAO,OAAO,kBAAkB,aAAa,WACzC,OAAO,iBAAiB,WACxB;EACN,kBAAkB,OAAO;EACzB,SAAS,OAAO;EAChB,SAAS,OAAO;EAChB,MAAM,OAAO;EACb,YAAY,OAAO;CACrB;CAEA,IAAI;CAEJ,IAAI;EACF,MAAM,MAAM,OAAO,OAAO,MAAO,GAAG;CACtC,SAAS,QAAQ;EACf,MAAM,eAAe,OAAO,OAAO,MAAM,MAAM;CACjD;CAEA,MAAM,aAAa,YAAY,IAAI,IAAI;CAEvC,OAAO,UAAU,KAAK,OAAO,SAAS,SAAS,UAAU;AAC3D;AAEA,eAAe,gBAAgB,QAAiD;CAC9E,MAAM,EAAE,OAAO,cAAc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,CACN,EACE,SAAS,uEACX,CACF,EACF;EAKF,OAAO,EACL,OAAO;GAAE,MAAM;GAAiB,WAHhB,OAAO,OAAO,cAAc,WAAW,OAAO,YAAY;EAGhC,EAC5C;CACF;AACF,EAGF;AAEA,SAAS,eAAe,gBAAwB,QAA0B;CACxE,IAAI,kBAAkB,SACpB,OAAO;CAKT,OAAO,IAAI,sBACT,2CAA2C,eAAe,KAH5C,kBAAkB,QAAQ,OAAO,UAAU,OAAO,MAAM,KAItE,EAAE,OAAO,OAAO,CAClB;AACF"}
@@ -0,0 +1,27 @@
1
+ import { SupervisorEventHandler, SupervisorEventHandlers } from "../contracts/supervisor/supervisor-config.type.mjs";
2
+ import { SupervisorEventMap } from "../contracts/events/event-map.type.mjs";
3
+
4
+ //#region ../../@warlock.js/ai/src/supervisor/emitter.d.ts
5
+ /**
6
+ * Three-tier supervisor event emitter — factory (definition) → instance
7
+ * → per-execution. Mirrors `WorkflowEmitter` structurally; the only
8
+ * difference is the event map. All matching handlers fire in layer
9
+ * order. Handler errors are swallowed so a listener bug can never
10
+ * derail the run.
11
+ *
12
+ * @example
13
+ * const emitter = new SupervisorEmitter(definition.on);
14
+ * const unsubscribe = emitter.on("supervisor.completed", (payload) => ...);
15
+ * emitter.emit("supervisor.starting", { runId, rootRunId, supervisorName, input }, perCallHandlers);
16
+ */
17
+ declare class SupervisorEmitter {
18
+ private readonly factoryHandlers?;
19
+ private readonly instanceHandlers;
20
+ constructor(factoryHandlers?: SupervisorEventHandlers);
21
+ on<K extends keyof SupervisorEventMap>(event: K, handler: SupervisorEventHandler<K>): () => void;
22
+ off<K extends keyof SupervisorEventMap>(event: K, handler: SupervisorEventHandler<K>): void;
23
+ emit<K extends keyof SupervisorEventMap>(event: K, payload: SupervisorEventMap[K], executionHandlers?: SupervisorEventHandlers): void;
24
+ }
25
+ //#endregion
26
+ export { SupervisorEmitter };
27
+ //# sourceMappingURL=emitter.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emitter.d.mts","names":[],"sources":["../../../../../../@warlock.js/ai/src/supervisor/emitter.ts"],"mappings":";;;;;;AAoBA;;;;;;;;;;cAAa,iBAAA;EAAA,iBACM,eAAA;EAAA,iBACA,gBAAA;cAKE,eAAA,GAAkB,uBAAA;EAI9B,EAAA,iBAAmB,kBAAA,CAAA,CACxB,KAAA,EAAO,CAAA,EACP,OAAA,EAAS,sBAAA,CAAuB,CAAA;EAc3B,GAAA,iBAAoB,kBAAA,CAAA,CACzB,KAAA,EAAO,CAAA,EACP,OAAA,EAAS,sBAAA,CAAuB,CAAA;EAK3B,IAAA,iBAAqB,kBAAA,CAAA,CAC1B,KAAA,EAAO,CAAA,EACP,OAAA,EAAS,kBAAA,CAAmB,CAAA,GAC5B,iBAAA,GAAoB,uBAAA;AAAA"}
@@ -0,0 +1,47 @@
1
+ //#region ../../@warlock.js/ai/src/supervisor/emitter.ts
2
+ /**
3
+ * Three-tier supervisor event emitter — factory (definition) → instance
4
+ * → per-execution. Mirrors `WorkflowEmitter` structurally; the only
5
+ * difference is the event map. All matching handlers fire in layer
6
+ * order. Handler errors are swallowed so a listener bug can never
7
+ * derail the run.
8
+ *
9
+ * @example
10
+ * const emitter = new SupervisorEmitter(definition.on);
11
+ * const unsubscribe = emitter.on("supervisor.completed", (payload) => ...);
12
+ * emitter.emit("supervisor.starting", { runId, rootRunId, supervisorName, input }, perCallHandlers);
13
+ */
14
+ var SupervisorEmitter = class {
15
+ constructor(factoryHandlers) {
16
+ this.instanceHandlers = /* @__PURE__ */ new Map();
17
+ this.factoryHandlers = factoryHandlers;
18
+ }
19
+ on(event, handler) {
20
+ let bucket = this.instanceHandlers.get(event);
21
+ if (!bucket) {
22
+ bucket = /* @__PURE__ */ new Set();
23
+ this.instanceHandlers.set(event, bucket);
24
+ }
25
+ bucket.add(handler);
26
+ return () => this.off(event, handler);
27
+ }
28
+ off(event, handler) {
29
+ this.instanceHandlers.get(event)?.delete(handler);
30
+ }
31
+ emit(event, payload, executionHandlers) {
32
+ invoke(this.factoryHandlers?.[event], payload);
33
+ const bucket = this.instanceHandlers.get(event);
34
+ if (bucket) for (const handler of bucket) invoke(handler, payload);
35
+ invoke(executionHandlers?.[event], payload);
36
+ }
37
+ };
38
+ function invoke(handler, payload) {
39
+ if (typeof handler !== "function") return;
40
+ try {
41
+ handler(payload);
42
+ } catch {}
43
+ }
44
+
45
+ //#endregion
46
+ export { SupervisorEmitter };
47
+ //# sourceMappingURL=emitter.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emitter.mjs","names":[],"sources":["../../../../../../@warlock.js/ai/src/supervisor/emitter.ts"],"sourcesContent":["import type { SupervisorEventMap } from \"../contracts/events/event-map.type\";\nimport type {\n SupervisorEventHandler,\n SupervisorEventHandlers,\n} from \"../contracts/supervisor/supervisor-config.type\";\n\ntype AnyHandler = SupervisorEventHandler<keyof SupervisorEventMap>;\n\n/**\n * Three-tier supervisor event emitter — factory (definition) → instance\n * → per-execution. Mirrors `WorkflowEmitter` structurally; the only\n * difference is the event map. All matching handlers fire in layer\n * order. Handler errors are swallowed so a listener bug can never\n * derail the run.\n *\n * @example\n * const emitter = new SupervisorEmitter(definition.on);\n * const unsubscribe = emitter.on(\"supervisor.completed\", (payload) => ...);\n * emitter.emit(\"supervisor.starting\", { runId, rootRunId, supervisorName, input }, perCallHandlers);\n */\nexport class SupervisorEmitter {\n private readonly factoryHandlers?: SupervisorEventHandlers;\n private readonly instanceHandlers = new Map<\n keyof SupervisorEventMap,\n Set<AnyHandler>\n >();\n\n public constructor(factoryHandlers?: SupervisorEventHandlers) {\n this.factoryHandlers = factoryHandlers;\n }\n\n public on<K extends keyof SupervisorEventMap>(\n event: K,\n handler: SupervisorEventHandler<K>,\n ): () => void {\n let bucket = this.instanceHandlers.get(event);\n\n if (!bucket) {\n bucket = new Set();\n this.instanceHandlers.set(event, bucket);\n }\n\n bucket.add(handler as AnyHandler);\n\n return () => this.off(event, handler);\n }\n\n public off<K extends keyof SupervisorEventMap>(\n event: K,\n handler: SupervisorEventHandler<K>,\n ): void {\n this.instanceHandlers.get(event)?.delete(handler as AnyHandler);\n }\n\n public emit<K extends keyof SupervisorEventMap>(\n event: K,\n payload: SupervisorEventMap[K],\n executionHandlers?: SupervisorEventHandlers,\n ): void {\n invoke(this.factoryHandlers?.[event], payload);\n\n const bucket = this.instanceHandlers.get(event);\n\n if (bucket) {\n for (const handler of bucket) {\n invoke(handler, payload);\n }\n }\n\n invoke(executionHandlers?.[event], payload);\n }\n}\n\nfunction invoke<K extends keyof SupervisorEventMap>(\n handler: ((payload: SupervisorEventMap[K]) => void) | undefined,\n payload: SupervisorEventMap[K],\n): void {\n if (typeof handler !== \"function\") {\n return;\n }\n\n try {\n handler(payload);\n } catch {\n // Listener bugs must not derail the supervisor.\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAoBA,IAAa,oBAAb,MAA+B;CAO7B,AAAO,YAAY,iBAA2C;0CAL1B,IAAI,IAGtC;EAGA,KAAK,kBAAkB;CACzB;CAEA,AAAO,GACL,OACA,SACY;EACZ,IAAI,SAAS,KAAK,iBAAiB,IAAI,KAAK;EAE5C,IAAI,CAAC,QAAQ;GACX,yBAAS,IAAI,IAAI;GACjB,KAAK,iBAAiB,IAAI,OAAO,MAAM;EACzC;EAEA,OAAO,IAAI,OAAqB;EAEhC,aAAa,KAAK,IAAI,OAAO,OAAO;CACtC;CAEA,AAAO,IACL,OACA,SACM;EACN,KAAK,iBAAiB,IAAI,KAAK,GAAG,OAAO,OAAqB;CAChE;CAEA,AAAO,KACL,OACA,SACA,mBACM;EACN,OAAO,KAAK,kBAAkB,QAAQ,OAAO;EAE7C,MAAM,SAAS,KAAK,iBAAiB,IAAI,KAAK;EAE9C,IAAI,QACF,KAAK,MAAM,WAAW,QACpB,OAAO,SAAS,OAAO;EAI3B,OAAO,oBAAoB,QAAQ,OAAO;CAC5C;AACF;AAEA,SAAS,OACP,SACA,SACM;CACN,IAAI,OAAO,YAAY,YACrB;CAGF,IAAI;EACF,QAAQ,OAAO;CACjB,QAAQ,CAER;AACF"}
@@ -0,0 +1,141 @@
1
+ import { Message } from "../contracts/conversation-message.type.mjs";
2
+ import { AgentContract } from "../contracts/agent/agent.contract.mjs";
3
+ import { EndSentinel } from "../contracts/end.type.mjs";
4
+ import { WorkflowInstance } from "../contracts/workflow/workflow.contract.mjs";
5
+ import { RouteContext } from "../contracts/supervisor/route-context.type.mjs";
6
+ import { IntentCallback, SupervisorIntentValue } from "../contracts/supervisor/intent-entry.type.mjs";
7
+ import { DispatchContext } from "../contracts/supervisor/dispatch-context.type.mjs";
8
+ import { StandardSchemaV1 } from "@standard-schema/spec";
9
+
10
+ //#region ../../@warlock.js/ai/src/supervisor/entries.d.ts
11
+ /**
12
+ * Normalized internal representation of one entry in a supervisor's
13
+ * `intents` map — resolved at factory time from one of the accepted
14
+ * value forms (bare agent / workflow / callback / object entry).
15
+ *
16
+ * Carrying the explicit `type` discriminator keeps downstream code
17
+ * (execution, signature, router-prompt) from having to re-detect
18
+ * shape on every dispatch. The discriminated union below replaces
19
+ * the flat-shape used in Phase 3 so callbacks can carry their own
20
+ * function reference + dispatch-context-shaped resolvers.
21
+ *
22
+ * Discriminator renamed `kind` → `type` (Q12) for codebase-wide
23
+ * consistency — every other discriminated result/report shape uses
24
+ * `type`.
25
+ */
26
+ type ResolvedIntentEntry = ResolvedAgentEntry | ResolvedWorkflowEntry | ResolvedCallbackEntry;
27
+ /**
28
+ * Successor directive function type — the resolver-time projection of
29
+ * `IntentEntry.next` / `IntentRunEntry.next`. Single source of truth
30
+ * across the three resolved variants.
31
+ */
32
+ type IntentNext = (ctx: DispatchContext) => string | string[] | EndSentinel | undefined;
33
+ /**
34
+ * Resolver-time projection of `IntentEntry.history` /
35
+ * `RouterEntry.history` / `AckEntry.history`. Custom slicer that
36
+ * REPLACES the default `historyWindow.<role>` slice.
37
+ */
38
+ type EntryHistorySlicer = (ctx: RouteContext) => Message[] | ReadonlyArray<Message>;
39
+ type ResolvedAgentEntry = {
40
+ intent: string;
41
+ type: "agent";
42
+ unit: AgentContract<unknown>;
43
+ description: string;
44
+ input?: (ctx: RouteContext) => string;
45
+ /**
46
+ * Per-dispatch placeholder values for the agent's systemPrompt
47
+ * template. Forwarded as `agent.execute(input, { placeholders })`.
48
+ * Phase 3.4 (Stage 4b) — replaces the dropped `composeAgentInput`
49
+ * mechanism for threading state into agents.
50
+ */
51
+ placeholders?: (ctx: DispatchContext) => Record<string, unknown>;
52
+ /**
53
+ * Schema declaring this intent's slice of supervisor state. Agent
54
+ * output is strip-merged against it; only validated keys appear on
55
+ * `IterationSnapshot.result[intent].output` AND merge into
56
+ * supervisor `state`.
57
+ */
58
+ output?: StandardSchemaV1<unknown>;
59
+ /**
60
+ * Successor directive (Stage 4d / Q24). When present, runs after
61
+ * this branch's slice merges into state to choose the next dispatch
62
+ * (or terminate) without invoking the router.
63
+ */
64
+ next?: IntentNext;
65
+ /**
66
+ * Custom history slicer — replaces the default
67
+ * `historyWindow.agents` slice when supplied. See `IntentEntry.history`.
68
+ */
69
+ history?: EntryHistorySlicer;
70
+ /**
71
+ * Phase 5 / decisions §34. `"stream"` runs the agent without
72
+ * structured-output coercion and writes the assembled prose into
73
+ * `state[streamTo]`; `"structured"` is the default. Resolved at
74
+ * factory time — `undefined` here is treated as `"structured"`.
75
+ */
76
+ mode?: "structured" | "stream"; /** State key the assembled stream-mode prose writes into. Set iff `mode === "stream"`. */
77
+ streamTo?: string;
78
+ };
79
+ type ResolvedWorkflowEntry = {
80
+ intent: string;
81
+ type: "workflow";
82
+ unit: WorkflowInstance<unknown, unknown>;
83
+ description: string;
84
+ input?: (ctx: RouteContext) => string;
85
+ placeholders?: (ctx: DispatchContext) => Record<string, unknown>;
86
+ output?: StandardSchemaV1<unknown>;
87
+ next?: IntentNext;
88
+ history?: EntryHistorySlicer;
89
+ };
90
+ type ResolvedCallbackEntry = {
91
+ intent: string;
92
+ type: "callback";
93
+ /**
94
+ * The callback that actually runs at dispatch time. Always present
95
+ * regardless of whether the user passed bare-function shorthand or
96
+ * the `{ run, ... }` entry form.
97
+ */
98
+ callback: IntentCallback;
99
+ /**
100
+ * Description is required only when the supervisor uses a router.
101
+ * Callback intents under a router are validated separately
102
+ * (see {@link assertRouterDescriptions}); under deterministic
103
+ * `route` mode this field is `undefined`.
104
+ */
105
+ description?: string;
106
+ /**
107
+ * Per-intent input resolver. Receives the upcoming
108
+ * `DispatchContext` and returns the value forwarded as
109
+ * `ctx.input` to the callback.
110
+ */
111
+ input?: (ctx: DispatchContext) => unknown;
112
+ placeholders?: (ctx: DispatchContext) => Record<string, unknown>;
113
+ /**
114
+ * Schema declaring this callback's slice of state. Without it, the
115
+ * full return value shallow-merges; with it, return is strip-merged
116
+ * to declared keys before merging.
117
+ */
118
+ output?: StandardSchemaV1<unknown>;
119
+ next?: IntentNext;
120
+ };
121
+ /**
122
+ * Validate and normalize the `intents` map into resolved entries.
123
+ * Runs at factory time — throws `SupervisorFailedError` on the first
124
+ * malformed entry so author-time bugs surface immediately rather
125
+ * than mid-run.
126
+ *
127
+ * Validation rules:
128
+ * - Every value must be an agent, a workflow, a callback function,
129
+ * or an object entry with `agent` / `workflow` / `run`.
130
+ * - Object entries with more than one of `{ agent, workflow, run }`
131
+ * throw with code `SUPERVISOR_INTENT_MIXED_DISPATCH`.
132
+ * - Agent / workflow / agent-shaped entries must resolve to a
133
+ * non-empty description from the underlying unit or the entry's
134
+ * `description` override. Bare callback shorthand has no
135
+ * description source — that's enforced separately by
136
+ * {@link assertRouterDescriptions} when a router is configured.
137
+ */
138
+ declare function resolveIntentEntries(rawIntents: Record<string, SupervisorIntentValue>, supervisorName: string): Map<string, ResolvedIntentEntry>;
139
+ //#endregion
140
+ export { ResolvedIntentEntry, resolveIntentEntries };
141
+ //# sourceMappingURL=entries.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entries.d.mts","names":[],"sources":["../../../../../../@warlock.js/ai/src/supervisor/entries.ts"],"mappings":";;;;;;;;;;AAkCA;;;;;;;;;;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