@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,4 @@
1
+ import { MockModelResponse, MockSDKConfig } from "./mock-config.type.mjs";
2
+ import { mockAgent } from "./mock-agent.mjs";
3
+ import { MockModel } from "./mock-model.mjs";
4
+ import { MockSDK } from "./mock-sdk.mjs";
@@ -0,0 +1,5 @@
1
+ import { MockModel } from "./mock-model.mjs";
2
+ import { MockSDK } from "./mock-sdk.mjs";
3
+ import { mockAgent } from "./mock-agent.mjs";
4
+
5
+ export { };
@@ -0,0 +1,41 @@
1
+ import { AgentContract } from "../contracts/agent/agent.contract.mjs";
2
+ import { ToolContract } from "../tool/tool.mjs";
3
+ import { MockModelResponse } from "./mock-config.type.mjs";
4
+
5
+ //#region ../../@warlock.js/ai/src/mock/mock-agent.d.ts
6
+ /**
7
+ * Test helper that wires `MockSDK` → mock model → `agent()` in one call.
8
+ *
9
+ * Replaces the 4-line ritual specs typically write:
10
+ * ```ts
11
+ * const mock = MockSDK({ responses: [...] });
12
+ * const myAgent = agent({ name: "x", model: mock.model({ name: "m" }) });
13
+ * ```
14
+ *
15
+ * Defaults to a single empty `"stop"` response — enough to exercise an
16
+ * agent that doesn't need a scripted reply (composition wiring,
17
+ * anonymous-name tests, etc.). Pass `responses` to script outputs.
18
+ *
19
+ * `name` is optional — when omitted the resulting agent runs through
20
+ * the normal anonymous-name fingerprint
21
+ * (`anon_<provider>_<model>[_<tool1>+<tool2>...]`), which is the
22
+ * default for `agent({ model })`.
23
+ *
24
+ * @example
25
+ * const a = mockAgent({ name: "writer", responses: [{ content: "hi", finishReason: "stop" }] });
26
+ * const result = await a.execute("anything");
27
+ */
28
+ declare function mockAgent<TOutput = unknown>(options?: {
29
+ name?: string;
30
+ responses?: MockModelResponse[];
31
+ tools?: ToolContract<unknown, unknown>[];
32
+ /**
33
+ * Override the model name reported by the mock model. Defaults to
34
+ * `"mock-model"` (the MockSDK default). Useful when a test needs
35
+ * deterministic provider/model fingerprinting.
36
+ */
37
+ modelName?: string;
38
+ }): AgentContract<TOutput>;
39
+ //#endregion
40
+ export { mockAgent };
41
+ //# sourceMappingURL=mock-agent.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mock-agent.d.mts","names":[],"sources":["../../../../../../@warlock.js/ai/src/mock/mock-agent.ts"],"mappings":";;;;;;;AA6BA;;;;;;;;;;;;;;;;;;;;iBAAgB,SAAA,mBAAA,CACd,OAAA;EACE,IAAA;EACA,SAAA,GAAY,iBAAA;EACZ,KAAA,GAAQ,YAAA;;;;;;EAMR,SAAA;AAAA,IAED,aAAA,CAAc,OAAA"}
@@ -0,0 +1,39 @@
1
+ import { agent } from "../agent/agent.mjs";
2
+ import { MockSDK } from "./mock-sdk.mjs";
3
+
4
+ //#region ../../@warlock.js/ai/src/mock/mock-agent.ts
5
+ /**
6
+ * Test helper that wires `MockSDK` → mock model → `agent()` in one call.
7
+ *
8
+ * Replaces the 4-line ritual specs typically write:
9
+ * ```ts
10
+ * const mock = MockSDK({ responses: [...] });
11
+ * const myAgent = agent({ name: "x", model: mock.model({ name: "m" }) });
12
+ * ```
13
+ *
14
+ * Defaults to a single empty `"stop"` response — enough to exercise an
15
+ * agent that doesn't need a scripted reply (composition wiring,
16
+ * anonymous-name tests, etc.). Pass `responses` to script outputs.
17
+ *
18
+ * `name` is optional — when omitted the resulting agent runs through
19
+ * the normal anonymous-name fingerprint
20
+ * (`anon_<provider>_<model>[_<tool1>+<tool2>...]`), which is the
21
+ * default for `agent({ model })`.
22
+ *
23
+ * @example
24
+ * const a = mockAgent({ name: "writer", responses: [{ content: "hi", finishReason: "stop" }] });
25
+ * const result = await a.execute("anything");
26
+ */
27
+ function mockAgent(options = {}) {
28
+ const config = { model: MockSDK({ responses: options.responses ?? [{
29
+ content: "",
30
+ finishReason: "stop"
31
+ }] }).model({ name: options.modelName ?? "mock-model" }) };
32
+ if (options.name !== void 0) config.name = options.name;
33
+ if (options.tools !== void 0) config.tools = options.tools;
34
+ return agent(config);
35
+ }
36
+
37
+ //#endregion
38
+ export { mockAgent };
39
+ //# sourceMappingURL=mock-agent.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mock-agent.mjs","names":[],"sources":["../../../../../../@warlock.js/ai/src/mock/mock-agent.ts"],"sourcesContent":["import { agent } from \"../agent/agent\";\nimport type { AgentConfig } from \"../agent/agent-config.type\";\nimport type { AgentContract } from \"../contracts/agent/agent.contract\";\nimport type { ToolContract } from \"../tool/tool\";\nimport type { MockModelResponse } from \"./mock-config.type\";\nimport { MockSDK } from \"./mock-sdk\";\n\n/**\n * Test helper that wires `MockSDK` → mock model → `agent()` in one call.\n *\n * Replaces the 4-line ritual specs typically write:\n * ```ts\n * const mock = MockSDK({ responses: [...] });\n * const myAgent = agent({ name: \"x\", model: mock.model({ name: \"m\" }) });\n * ```\n *\n * Defaults to a single empty `\"stop\"` response — enough to exercise an\n * agent that doesn't need a scripted reply (composition wiring,\n * anonymous-name tests, etc.). Pass `responses` to script outputs.\n *\n * `name` is optional — when omitted the resulting agent runs through\n * the normal anonymous-name fingerprint\n * (`anon_<provider>_<model>[_<tool1>+<tool2>...]`), which is the\n * default for `agent({ model })`.\n *\n * @example\n * const a = mockAgent({ name: \"writer\", responses: [{ content: \"hi\", finishReason: \"stop\" }] });\n * const result = await a.execute(\"anything\");\n */\nexport function mockAgent<TOutput = unknown>(\n options: {\n name?: string;\n responses?: MockModelResponse[];\n tools?: ToolContract<unknown, unknown>[];\n /**\n * Override the model name reported by the mock model. Defaults to\n * `\"mock-model\"` (the MockSDK default). Useful when a test needs\n * deterministic provider/model fingerprinting.\n */\n modelName?: string;\n } = {},\n): AgentContract<TOutput> {\n const responses = options.responses ?? [{ content: \"\", finishReason: \"stop\" as const }];\n const sdk = MockSDK({ responses });\n const model = sdk.model({ name: options.modelName ?? \"mock-model\" });\n\n const config: AgentConfig<TOutput> = { model };\n\n if (options.name !== undefined) {\n config.name = options.name;\n }\n\n if (options.tools !== undefined) {\n config.tools = options.tools;\n }\n\n return agent<TOutput>(config);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,SAAgB,UACd,UAUI,CAAC,GACmB;CAKxB,MAAM,SAA+B,EAAE,OAH3B,QAAQ,EAAE,WADJ,QAAQ,aAAa,CAAC;EAAE,SAAS;EAAI,cAAc;CAAgB,CAAC,EACtD,CAChB,EAAE,MAAM,EAAE,MAAM,QAAQ,aAAa,aAAa,CAEvB,EAAE;CAE7C,IAAI,QAAQ,SAAS,QACnB,OAAO,OAAO,QAAQ;CAGxB,IAAI,QAAQ,UAAU,QACpB,OAAO,QAAQ,QAAQ;CAGzB,OAAO,MAAe,MAAM;AAC9B"}
@@ -0,0 +1,31 @@
1
+ import { ModelToolCallRequest } from "../contracts/model-tool-call-request.type.mjs";
2
+ import { Usage } from "../contracts/result/usage.type.mjs";
3
+ import { FinishReason } from "../contracts/finish-reason.type.mjs";
4
+ import { ModelCapabilities } from "../contracts/model.contract.mjs";
5
+ //#region ../../@warlock.js/ai/src/mock/mock-config.type.d.ts
6
+ /**
7
+ * Configuration for a single mock model response.
8
+ * Responses are consumed in order — last one repeats if list is exhausted.
9
+ */
10
+ type MockModelResponse = {
11
+ content: string;
12
+ finishReason?: FinishReason;
13
+ usage?: Usage;
14
+ toolCalls?: ModelToolCallRequest[]; /** Simulate a delay in ms before resolving */
15
+ delay?: number; /** Throw this error instead of returning a response */
16
+ error?: Error;
17
+ };
18
+ type MockSDKConfig = {
19
+ /** Responses to return in sequence. Last one repeats when exhausted. */responses?: MockModelResponse[]; /** Default model name reported by mock models */
20
+ defaultModelName?: string;
21
+ /**
22
+ * Capability flags reported by every model this mock SDK creates.
23
+ * Tests use this to exercise capability-gated agent behavior (e.g.
24
+ * vision attachments, native structured output) without standing up
25
+ * a real provider.
26
+ */
27
+ capabilities?: ModelCapabilities;
28
+ };
29
+ //#endregion
30
+ export { MockModelResponse, MockSDKConfig };
31
+ //# sourceMappingURL=mock-config.type.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mock-config.type.d.mts","names":[],"sources":["../../../../../../@warlock.js/ai/src/mock/mock-config.type.ts"],"mappings":";;;;;;;;AASA;KAAY,iBAAA;EACV,OAAA;EACA,YAAA,GAAe,YAAA;EACf,KAAA,GAAQ,KAAA;EACR,SAAA,GAAY,oBAAA,IAIJ;EAFR,KAAA,WAEa;EAAb,KAAA,GAAQ,KAAA;AAAA;AAAA,KAGE,aAAA;EARV,wEAUA,SAAA,GAAY,iBAAA,IATZ;EAWA,gBAAA;EATA;;;;AAEa;AAGf;EAWE,YAAA,GAAe,iBAAiB;AAAA"}
@@ -0,0 +1,94 @@
1
+ import { Message } from "../contracts/conversation-message.type.mjs";
2
+ import { ModelCallOptions, ModelCapabilities, ModelContract, ModelResponse, ModelStreamChunk } from "../contracts/model.contract.mjs";
3
+ import { MockModelResponse } from "./mock-config.type.mjs";
4
+
5
+ //#region ../../@warlock.js/ai/src/mock/mock-model.d.ts
6
+ type RecordedCall = {
7
+ messages: Message[];
8
+ options?: ModelCallOptions;
9
+ };
10
+ /**
11
+ * Deterministic in-memory `ModelContract` implementation for tests.
12
+ *
13
+ * **Role.** Stands in for a real provider model so agent/workflow/supervisor
14
+ * tests can assert behavior without hitting the network, spending tokens, or
15
+ * depending on non-deterministic LLM output.
16
+ *
17
+ * **Responsibility.**
18
+ * - Owns: a scripted queue of `MockModelResponse` entries, a call-history
19
+ * log for assertions, and the index pointer that advances through the
20
+ * queue on each `complete()` / `stream()` call.
21
+ * - Does NOT own: any real inference, tokenization, or network I/O — when
22
+ * the queue is exhausted, the final entry is reused so tests never crash
23
+ * on accidental over-consumption.
24
+ *
25
+ * Every AI-related test in this repo uses `MockSDK` / `MockModel` — real
26
+ * provider APIs are never hit from the test suite (see §6 of code-style.md).
27
+ *
28
+ * @example
29
+ * const model = new MockModel("mock-gpt", [
30
+ * { content: "Hello!", finishReason: "stop" },
31
+ * { content: "Second turn.", finishReason: "stop" },
32
+ * ]);
33
+ *
34
+ * const first = await model.complete([{ role: "user", content: "hi" }]);
35
+ * expect(first.content).toBe("Hello!");
36
+ * expect(model.callCount).toBe(1);
37
+ */
38
+ declare class MockModel implements ModelContract {
39
+ readonly name: string;
40
+ private readonly responses;
41
+ readonly provider = "mock";
42
+ readonly capabilities?: ModelCapabilities;
43
+ private responseIndex;
44
+ private calls;
45
+ constructor(name: string, responses: MockModelResponse[], capabilities?: ModelCapabilities);
46
+ /**
47
+ * Full history of calls made to this model. Each entry is the exact
48
+ * `{ messages, options }` pair that was passed — useful for asserting
49
+ * that an agent built the right prompt or forwarded the right tool list.
50
+ */
51
+ get callHistory(): RecordedCall[];
52
+ /**
53
+ * Number of times `complete()` or `stream()` has been invoked. Convenient
54
+ * shorthand for `callHistory.length` in assertions.
55
+ */
56
+ get callCount(): number;
57
+ /**
58
+ * Advance the scripted response queue by one and return the entry at the
59
+ * current pointer. If the queue is exhausted, the final scripted entry is
60
+ * returned repeatedly so over-consumption in tests produces predictable
61
+ * output instead of `undefined`.
62
+ */
63
+ private nextResponse;
64
+ /**
65
+ * Convert a scripted `MockModelResponse` into a full `ModelResponse` with
66
+ * synthesized usage numbers when the script didn't supply them. Input
67
+ * usage is a fixed estimate; output usage is derived from content length.
68
+ */
69
+ private buildResponse;
70
+ /**
71
+ * Record the call, optionally delay (to simulate latency), and either
72
+ * throw the scripted error or return the scripted response. Mirrors the
73
+ * real provider's `complete()` contract so agents cannot tell the
74
+ * difference at runtime.
75
+ */
76
+ complete(messages: Message[], options?: ModelCallOptions): Promise<ModelResponse>;
77
+ /**
78
+ * Record the call, optionally delay, then emit the scripted response as a
79
+ * sequence of stream chunks: content split word-by-word as `delta`
80
+ * chunks, each scripted tool call as a `tool-call` chunk, and finally a
81
+ * `done` chunk with finish reason + usage. Throws eagerly if the scripted
82
+ * entry carries an `error`.
83
+ */
84
+ stream(messages: Message[], options?: ModelCallOptions): AsyncIterable<ModelStreamChunk>;
85
+ /**
86
+ * Reset call history and response pointer back to their initial state.
87
+ * Intended for test-suite `beforeEach` hooks so a single `MockModel`
88
+ * instance can be reused across cases without cross-test leakage.
89
+ */
90
+ reset(): void;
91
+ }
92
+ //#endregion
93
+ export { MockModel };
94
+ //# sourceMappingURL=mock-model.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mock-model.d.mts","names":[],"sources":["../../../../../../@warlock.js/ai/src/mock/mock-model.ts"],"mappings":";;;;;KAUK,YAAA;EACH,QAAA,EAAU,OAAA;EACV,OAAA,GAAU,gBAAgB;AAAA;;;;;;;;AAAA;AA+B5B;;;;;;;;;;;;;;;;;;;;cAAa,SAAA,YAAqB,aAAA;EAAA,SAQd,IAAA;EAAA,iBACC,SAAA;EAAA,SARH,QAAA;EAAA,SACA,YAAA,GAAe,iBAAA;EAAA,QAEvB,aAAA;EAAA,QACA,KAAA;cAGU,IAAA,UACC,SAAA,EAAW,iBAAA,IAC5B,YAAA,GAAe,iBAAA;EADa;;;;;EAAA,IAWnB,WAAA,CAAA,GAAe,YAAA;EAQf;;;;EAAA,IAAA,SAAA,CAAA;EA8CW;;;;;;EAAA,QApCd,YAAA;EA4DN;;;;;EAAA,QA/CM,aAAA;EA6FI;AAAA;;;;;EAtEC,QAAA,CAAS,QAAA,EAAU,OAAA,IAAW,OAAA,GAAU,gBAAA,GAAmB,OAAA,CAAQ,aAAA;;;;;;;;EAuBlE,MAAA,CACZ,QAAA,EAAU,OAAA,IACV,OAAA,GAAU,gBAAA,GACT,aAAA,CAAc,gBAAA;;;;;;EA4CV,KAAA,CAAA;AAAA"}
@@ -0,0 +1,150 @@
1
+ //#region ../../@warlock.js/ai/src/mock/mock-model.ts
2
+ /**
3
+ * Deterministic in-memory `ModelContract` implementation for tests.
4
+ *
5
+ * **Role.** Stands in for a real provider model so agent/workflow/supervisor
6
+ * tests can assert behavior without hitting the network, spending tokens, or
7
+ * depending on non-deterministic LLM output.
8
+ *
9
+ * **Responsibility.**
10
+ * - Owns: a scripted queue of `MockModelResponse` entries, a call-history
11
+ * log for assertions, and the index pointer that advances through the
12
+ * queue on each `complete()` / `stream()` call.
13
+ * - Does NOT own: any real inference, tokenization, or network I/O — when
14
+ * the queue is exhausted, the final entry is reused so tests never crash
15
+ * on accidental over-consumption.
16
+ *
17
+ * Every AI-related test in this repo uses `MockSDK` / `MockModel` — real
18
+ * provider APIs are never hit from the test suite (see §6 of code-style.md).
19
+ *
20
+ * @example
21
+ * const model = new MockModel("mock-gpt", [
22
+ * { content: "Hello!", finishReason: "stop" },
23
+ * { content: "Second turn.", finishReason: "stop" },
24
+ * ]);
25
+ *
26
+ * const first = await model.complete([{ role: "user", content: "hi" }]);
27
+ * expect(first.content).toBe("Hello!");
28
+ * expect(model.callCount).toBe(1);
29
+ */
30
+ var MockModel = class {
31
+ constructor(name, responses, capabilities) {
32
+ this.name = name;
33
+ this.responses = responses;
34
+ this.provider = "mock";
35
+ this.responseIndex = 0;
36
+ this.calls = [];
37
+ this.capabilities = capabilities;
38
+ }
39
+ /**
40
+ * Full history of calls made to this model. Each entry is the exact
41
+ * `{ messages, options }` pair that was passed — useful for asserting
42
+ * that an agent built the right prompt or forwarded the right tool list.
43
+ */
44
+ get callHistory() {
45
+ return this.calls;
46
+ }
47
+ /**
48
+ * Number of times `complete()` or `stream()` has been invoked. Convenient
49
+ * shorthand for `callHistory.length` in assertions.
50
+ */
51
+ get callCount() {
52
+ return this.calls.length;
53
+ }
54
+ /**
55
+ * Advance the scripted response queue by one and return the entry at the
56
+ * current pointer. If the queue is exhausted, the final scripted entry is
57
+ * returned repeatedly so over-consumption in tests produces predictable
58
+ * output instead of `undefined`.
59
+ */
60
+ nextResponse() {
61
+ const response = this.responses[Math.min(this.responseIndex, this.responses.length - 1)];
62
+ this.responseIndex++;
63
+ return response ?? {
64
+ content: "Mock response",
65
+ finishReason: "stop"
66
+ };
67
+ }
68
+ /**
69
+ * Convert a scripted `MockModelResponse` into a full `ModelResponse` with
70
+ * synthesized usage numbers when the script didn't supply them. Input
71
+ * usage is a fixed estimate; output usage is derived from content length.
72
+ */
73
+ buildResponse(mock) {
74
+ const estimatedInput = 10;
75
+ const estimatedOutput = Math.ceil(mock.content.length / 4);
76
+ return {
77
+ content: mock.content,
78
+ finishReason: mock.finishReason ?? "stop",
79
+ usage: {
80
+ input: mock.usage?.input ?? estimatedInput,
81
+ output: mock.usage?.output ?? estimatedOutput,
82
+ total: (mock.usage?.input ?? estimatedInput) + (mock.usage?.output ?? estimatedOutput),
83
+ ...mock.usage?.cachedTokens !== void 0 ? { cachedTokens: mock.usage.cachedTokens } : {}
84
+ },
85
+ toolCalls: mock.toolCalls
86
+ };
87
+ }
88
+ /**
89
+ * Record the call, optionally delay (to simulate latency), and either
90
+ * throw the scripted error or return the scripted response. Mirrors the
91
+ * real provider's `complete()` contract so agents cannot tell the
92
+ * difference at runtime.
93
+ */
94
+ async complete(messages, options) {
95
+ this.calls.push({
96
+ messages,
97
+ options
98
+ });
99
+ const mock = this.nextResponse();
100
+ if (mock.delay) await new Promise((resolve) => setTimeout(resolve, mock.delay));
101
+ if (mock.error) throw mock.error;
102
+ return this.buildResponse(mock);
103
+ }
104
+ /**
105
+ * Record the call, optionally delay, then emit the scripted response as a
106
+ * sequence of stream chunks: content split word-by-word as `delta`
107
+ * chunks, each scripted tool call as a `tool-call` chunk, and finally a
108
+ * `done` chunk with finish reason + usage. Throws eagerly if the scripted
109
+ * entry carries an `error`.
110
+ */
111
+ async *stream(messages, options) {
112
+ this.calls.push({
113
+ messages,
114
+ options
115
+ });
116
+ const mock = this.nextResponse();
117
+ if (mock.delay) await new Promise((resolve) => setTimeout(resolve, mock.delay));
118
+ if (mock.error) throw mock.error;
119
+ const words = mock.content.split(" ");
120
+ for (const word of words) yield {
121
+ type: "delta",
122
+ content: word + " "
123
+ };
124
+ if (mock.toolCalls) for (const toolCall of mock.toolCalls) yield {
125
+ type: "tool-call",
126
+ id: toolCall.id,
127
+ name: toolCall.name,
128
+ input: toolCall.input
129
+ };
130
+ const response = this.buildResponse(mock);
131
+ yield {
132
+ type: "done",
133
+ finishReason: response.finishReason,
134
+ usage: response.usage
135
+ };
136
+ }
137
+ /**
138
+ * Reset call history and response pointer back to their initial state.
139
+ * Intended for test-suite `beforeEach` hooks so a single `MockModel`
140
+ * instance can be reused across cases without cross-test leakage.
141
+ */
142
+ reset() {
143
+ this.calls = [];
144
+ this.responseIndex = 0;
145
+ }
146
+ };
147
+
148
+ //#endregion
149
+ export { MockModel };
150
+ //# sourceMappingURL=mock-model.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mock-model.mjs","names":[],"sources":["../../../../../../@warlock.js/ai/src/mock/mock-model.ts"],"sourcesContent":["import type { Message } from \"../contracts/conversation-message.type\";\nimport type {\n ModelCallOptions,\n ModelCapabilities,\n ModelContract,\n ModelResponse,\n ModelStreamChunk,\n} from \"../contracts/model.contract\";\nimport type { MockModelResponse } from \"./mock-config.type\";\n\ntype RecordedCall = {\n messages: Message[];\n options?: ModelCallOptions;\n};\n\n/**\n * Deterministic in-memory `ModelContract` implementation for tests.\n *\n * **Role.** Stands in for a real provider model so agent/workflow/supervisor\n * tests can assert behavior without hitting the network, spending tokens, or\n * depending on non-deterministic LLM output.\n *\n * **Responsibility.**\n * - Owns: a scripted queue of `MockModelResponse` entries, a call-history\n * log for assertions, and the index pointer that advances through the\n * queue on each `complete()` / `stream()` call.\n * - Does NOT own: any real inference, tokenization, or network I/O — when\n * the queue is exhausted, the final entry is reused so tests never crash\n * on accidental over-consumption.\n *\n * Every AI-related test in this repo uses `MockSDK` / `MockModel` — real\n * provider APIs are never hit from the test suite (see §6 of code-style.md).\n *\n * @example\n * const model = new MockModel(\"mock-gpt\", [\n * { content: \"Hello!\", finishReason: \"stop\" },\n * { content: \"Second turn.\", finishReason: \"stop\" },\n * ]);\n *\n * const first = await model.complete([{ role: \"user\", content: \"hi\" }]);\n * expect(first.content).toBe(\"Hello!\");\n * expect(model.callCount).toBe(1);\n */\nexport class MockModel implements ModelContract {\n public readonly provider = \"mock\";\n public readonly capabilities?: ModelCapabilities;\n\n private responseIndex = 0;\n private calls: RecordedCall[] = [];\n\n public constructor(\n public readonly name: string,\n private readonly responses: MockModelResponse[],\n capabilities?: ModelCapabilities,\n ) {\n this.capabilities = capabilities;\n }\n\n /**\n * Full history of calls made to this model. Each entry is the exact\n * `{ messages, options }` pair that was passed — useful for asserting\n * that an agent built the right prompt or forwarded the right tool list.\n */\n public get callHistory(): RecordedCall[] {\n return this.calls;\n }\n\n /**\n * Number of times `complete()` or `stream()` has been invoked. Convenient\n * shorthand for `callHistory.length` in assertions.\n */\n public get callCount(): number {\n return this.calls.length;\n }\n\n /**\n * Advance the scripted response queue by one and return the entry at the\n * current pointer. If the queue is exhausted, the final scripted entry is\n * returned repeatedly so over-consumption in tests produces predictable\n * output instead of `undefined`.\n */\n private nextResponse(): MockModelResponse {\n const response = this.responses[Math.min(this.responseIndex, this.responses.length - 1)];\n\n this.responseIndex++;\n\n return response ?? { content: \"Mock response\", finishReason: \"stop\" };\n }\n\n /**\n * Convert a scripted `MockModelResponse` into a full `ModelResponse` with\n * synthesized usage numbers when the script didn't supply them. Input\n * usage is a fixed estimate; output usage is derived from content length.\n */\n private buildResponse(mock: MockModelResponse): ModelResponse {\n const estimatedInput = 10;\n const estimatedOutput = Math.ceil(mock.content.length / 4);\n\n return {\n content: mock.content,\n finishReason: mock.finishReason ?? \"stop\",\n usage: {\n input: mock.usage?.input ?? estimatedInput,\n output: mock.usage?.output ?? estimatedOutput,\n total: (mock.usage?.input ?? estimatedInput) + (mock.usage?.output ?? estimatedOutput),\n ...(mock.usage?.cachedTokens !== undefined ? { cachedTokens: mock.usage.cachedTokens } : {}),\n },\n toolCalls: mock.toolCalls,\n };\n }\n\n /**\n * Record the call, optionally delay (to simulate latency), and either\n * throw the scripted error or return the scripted response. Mirrors the\n * real provider's `complete()` contract so agents cannot tell the\n * difference at runtime.\n */\n public async complete(messages: Message[], options?: ModelCallOptions): Promise<ModelResponse> {\n this.calls.push({ messages, options });\n\n const mock = this.nextResponse();\n\n if (mock.delay) {\n await new Promise((resolve) => setTimeout(resolve, mock.delay));\n }\n\n if (mock.error) {\n throw mock.error;\n }\n\n return this.buildResponse(mock);\n }\n\n /**\n * Record the call, optionally delay, then emit the scripted response as a\n * sequence of stream chunks: content split word-by-word as `delta`\n * chunks, each scripted tool call as a `tool-call` chunk, and finally a\n * `done` chunk with finish reason + usage. Throws eagerly if the scripted\n * entry carries an `error`.\n */\n public async *stream(\n messages: Message[],\n options?: ModelCallOptions,\n ): AsyncIterable<ModelStreamChunk> {\n this.calls.push({ messages, options });\n\n const mock = this.nextResponse();\n\n if (mock.delay) {\n await new Promise((resolve) => setTimeout(resolve, mock.delay));\n }\n\n if (mock.error) {\n throw mock.error;\n }\n\n const words = mock.content.split(\" \");\n\n for (const word of words) {\n yield { type: \"delta\", content: word + \" \" };\n }\n\n if (mock.toolCalls) {\n for (const toolCall of mock.toolCalls) {\n yield {\n type: \"tool-call\",\n id: toolCall.id,\n name: toolCall.name,\n input: toolCall.input,\n };\n }\n }\n\n const response = this.buildResponse(mock);\n\n yield {\n type: \"done\",\n finishReason: response.finishReason,\n usage: response.usage,\n };\n }\n\n /**\n * Reset call history and response pointer back to their initial state.\n * Intended for test-suite `beforeEach` hooks so a single `MockModel`\n * instance can be reused across cases without cross-test leakage.\n */\n public reset(): void {\n this.calls = [];\n this.responseIndex = 0;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,IAAa,YAAb,MAAgD;CAO9C,AAAO,YACL,AAAgB,MAChB,AAAiB,WACjB,cACA;EAHgB;EACC;kBARQ;uBAGH;eACQ,CAAC;EAO/B,KAAK,eAAe;CACtB;;;;;;CAOA,IAAW,cAA8B;EACvC,OAAO,KAAK;CACd;;;;;CAMA,IAAW,YAAoB;EAC7B,OAAO,KAAK,MAAM;CACpB;;;;;;;CAQA,AAAQ,eAAkC;EACxC,MAAM,WAAW,KAAK,UAAU,KAAK,IAAI,KAAK,eAAe,KAAK,UAAU,SAAS,CAAC;EAEtF,KAAK;EAEL,OAAO,YAAY;GAAE,SAAS;GAAiB,cAAc;EAAO;CACtE;;;;;;CAOA,AAAQ,cAAc,MAAwC;EAC5D,MAAM,iBAAiB;EACvB,MAAM,kBAAkB,KAAK,KAAK,KAAK,QAAQ,SAAS,CAAC;EAEzD,OAAO;GACL,SAAS,KAAK;GACd,cAAc,KAAK,gBAAgB;GACnC,OAAO;IACL,OAAO,KAAK,OAAO,SAAS;IAC5B,QAAQ,KAAK,OAAO,UAAU;IAC9B,QAAQ,KAAK,OAAO,SAAS,mBAAmB,KAAK,OAAO,UAAU;IACtE,GAAI,KAAK,OAAO,iBAAiB,SAAY,EAAE,cAAc,KAAK,MAAM,aAAa,IAAI,CAAC;GAC5F;GACA,WAAW,KAAK;EAClB;CACF;;;;;;;CAQA,MAAa,SAAS,UAAqB,SAAoD;EAC7F,KAAK,MAAM,KAAK;GAAE;GAAU;EAAQ,CAAC;EAErC,MAAM,OAAO,KAAK,aAAa;EAE/B,IAAI,KAAK,OACP,MAAM,IAAI,SAAS,YAAY,WAAW,SAAS,KAAK,KAAK,CAAC;EAGhE,IAAI,KAAK,OACP,MAAM,KAAK;EAGb,OAAO,KAAK,cAAc,IAAI;CAChC;;;;;;;;CASA,OAAc,OACZ,UACA,SACiC;EACjC,KAAK,MAAM,KAAK;GAAE;GAAU;EAAQ,CAAC;EAErC,MAAM,OAAO,KAAK,aAAa;EAE/B,IAAI,KAAK,OACP,MAAM,IAAI,SAAS,YAAY,WAAW,SAAS,KAAK,KAAK,CAAC;EAGhE,IAAI,KAAK,OACP,MAAM,KAAK;EAGb,MAAM,QAAQ,KAAK,QAAQ,MAAM,GAAG;EAEpC,KAAK,MAAM,QAAQ,OACjB,MAAM;GAAE,MAAM;GAAS,SAAS,OAAO;EAAI;EAG7C,IAAI,KAAK,WACP,KAAK,MAAM,YAAY,KAAK,WAC1B,MAAM;GACJ,MAAM;GACN,IAAI,SAAS;GACb,MAAM,SAAS;GACf,OAAO,SAAS;EAClB;EAIJ,MAAM,WAAW,KAAK,cAAc,IAAI;EAExC,MAAM;GACJ,MAAM;GACN,cAAc,SAAS;GACvB,OAAO,SAAS;EAClB;CACF;;;;;;CAOA,AAAO,QAAc;EACnB,KAAK,QAAQ,CAAC;EACd,KAAK,gBAAgB;CACvB;AACF"}
@@ -0,0 +1,25 @@
1
+ import { SDKAdapterContract } from "../contracts/sdk-adapter.contract.mjs";
2
+ import { MockSDKConfig } from "./mock-config.type.mjs";
3
+ import { MockModel } from "./mock-model.mjs";
4
+
5
+ //#region ../../@warlock.js/ai/src/mock/mock-sdk.d.ts
6
+ /**
7
+ * Creates a mock SDK adapter for testing — no HTTP calls, fully configurable.
8
+ *
9
+ * @example
10
+ * const mock = MockSDK({
11
+ * responses: [
12
+ * { content: "Hello from mock!" },
13
+ * { content: "Second response" },
14
+ * ],
15
+ * });
16
+ * const model = mock.model({ name: "gpt-4o" });
17
+ * const result = await model.complete([{ role: "user", content: "Hi" }]);
18
+ * console.log(result.content); // "Hello from mock!"
19
+ */
20
+ declare function MockSDK(config?: MockSDKConfig): SDKAdapterContract & {
21
+ /** All model instances created by this SDK — for inspecting calls in tests */models: MockModel[];
22
+ };
23
+ //#endregion
24
+ export { MockSDK };
25
+ //# sourceMappingURL=mock-sdk.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mock-sdk.d.mts","names":[],"sources":["../../../../../../@warlock.js/ai/src/mock/mock-sdk.ts"],"mappings":";;;;;;;AAsBA;;;;;;;;;;;;iBAAgB,OAAA,CAAQ,MAAA,GAAQ,aAAA,GAAqB,kBAAA;EAElC,8EAAjB,MAAA,EAAQ,SAAA;AAAA"}
@@ -0,0 +1,37 @@
1
+ import { approximateTokenCount } from "../utils/token-count.mjs";
2
+ import { MockModel } from "./mock-model.mjs";
3
+
4
+ //#region ../../@warlock.js/ai/src/mock/mock-sdk.ts
5
+ /**
6
+ * Creates a mock SDK adapter for testing — no HTTP calls, fully configurable.
7
+ *
8
+ * @example
9
+ * const mock = MockSDK({
10
+ * responses: [
11
+ * { content: "Hello from mock!" },
12
+ * { content: "Second response" },
13
+ * ],
14
+ * });
15
+ * const model = mock.model({ name: "gpt-4o" });
16
+ * const result = await model.complete([{ role: "user", content: "Hi" }]);
17
+ * console.log(result.content); // "Hello from mock!"
18
+ */
19
+ function MockSDK(config = {}) {
20
+ const models = [];
21
+ const responses = config.responses ?? [{ content: "Mock response" }];
22
+ return {
23
+ models,
24
+ model(modelConfig) {
25
+ const model = new MockModel(modelConfig.name ?? config.defaultModelName ?? "mock-model", responses, config.capabilities);
26
+ models.push(model);
27
+ return model;
28
+ },
29
+ async count(text, _model) {
30
+ return approximateTokenCount(text);
31
+ }
32
+ };
33
+ }
34
+
35
+ //#endregion
36
+ export { MockSDK };
37
+ //# sourceMappingURL=mock-sdk.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mock-sdk.mjs","names":[],"sources":["../../../../../../@warlock.js/ai/src/mock/mock-sdk.ts"],"sourcesContent":["import type {\n ModelConfig,\n SDKAdapterContract,\n} from \"../contracts/sdk-adapter.contract\";\nimport { approximateTokenCount } from \"../utils/token-count\";\nimport type { MockSDKConfig } from \"./mock-config.type\";\nimport { MockModel } from \"./mock-model\";\n\n/**\n * Creates a mock SDK adapter for testing — no HTTP calls, fully configurable.\n *\n * @example\n * const mock = MockSDK({\n * responses: [\n * { content: \"Hello from mock!\" },\n * { content: \"Second response\" },\n * ],\n * });\n * const model = mock.model({ name: \"gpt-4o\" });\n * const result = await model.complete([{ role: \"user\", content: \"Hi\" }]);\n * console.log(result.content); // \"Hello from mock!\"\n */\nexport function MockSDK(config: MockSDKConfig = {}): SDKAdapterContract & {\n /** All model instances created by this SDK — for inspecting calls in tests */\n models: MockModel[];\n} {\n const models: MockModel[] = [];\n const responses = config.responses ?? [{ content: \"Mock response\" }];\n\n return {\n models,\n model(modelConfig: ModelConfig) {\n const model = new MockModel(\n modelConfig.name ?? config.defaultModelName ?? \"mock-model\",\n responses,\n config.capabilities,\n );\n models.push(model);\n return model;\n },\n async count(text: string, _model?: string): Promise<number> {\n return approximateTokenCount(text);\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAsBA,SAAgB,QAAQ,SAAwB,CAAC,GAG/C;CACA,MAAM,SAAsB,CAAC;CAC7B,MAAM,YAAY,OAAO,aAAa,CAAC,EAAE,SAAS,gBAAgB,CAAC;CAEnE,OAAO;EACL;EACA,MAAM,aAA0B;GAC9B,MAAM,QAAQ,IAAI,UAChB,YAAY,QAAQ,OAAO,oBAAoB,cAC/C,WACA,OAAO,YACT;GACA,OAAO,KAAK,KAAK;GACjB,OAAO;EACT;EACA,MAAM,MAAM,MAAc,QAAkC;GAC1D,OAAO,sBAAsB,IAAI;EACnC;CACF;AACF"}
@@ -0,0 +1,45 @@
1
+ import { ToolContract } from "../tool/tool.mjs";
2
+ import { SupervisorAsToolOptions, SupervisorContract } from "../contracts/supervisor/supervisor.contract.mjs";
3
+
4
+ //#region ../../@warlock.js/ai/src/supervisor/as-tool.d.ts
5
+ /**
6
+ * Wrap a `SupervisorContract` as a `ToolContract` so an outer agent
7
+ * can invoke it from its tool-call loop. Mirrors
8
+ * `workflow.asTool()` / `agent.asTool()` — same composition pattern,
9
+ * same error-normalization behavior.
10
+ *
11
+ * Behavior:
12
+ * - The tool's `name` mirrors the supervisor's `name` unless the
13
+ * caller overrides via `options.name`. Supervisors without a
14
+ * meaningful name throw `SupervisorFailedError` — an outer agent
15
+ * can't route to an anonymous tool.
16
+ * - Tool `input` is the supplied schema; the validated value is
17
+ * coerced to a string (via `String()` for non-string values, or
18
+ * `JSON.stringify()` for objects) before being forwarded to
19
+ * `supervisor.execute(input)`. Consumers whose inputs need
20
+ * richer shaping should pre-format the string themselves.
21
+ * - On `result.error`, the supervisor error is thrown so the tool
22
+ * wrapper catches it and produces a `ToolExecutionError` with
23
+ * `cause` set to the original typed supervisor error — the outer
24
+ * agent sees one uniform error class regardless of which
25
+ * primitive failed.
26
+ *
27
+ * **Usage caveat** (mirrors workflow-as-tool): nested usage is not
28
+ * rolled into the outer agent's `result.usage` today — the
29
+ * supervisor's tokens stay on the supervisor result. Sum manually
30
+ * if you need a combined cost number until nested-usage
31
+ * standardization lands.
32
+ *
33
+ * @example
34
+ * const support = ai.supervisor({ ... });
35
+ * const supportTool = support.asTool({
36
+ * name: "handle_support_ticket",
37
+ * description: "Process a customer support ticket end-to-end.",
38
+ * inputSchema: z.object({ ticket: z.string() }),
39
+ * });
40
+ * const concierge = ai.agent({ model, tools: [supportTool] });
41
+ */
42
+ declare function asTool<TOutput, TToolInput>(supervisorInstance: SupervisorContract<TOutput>, options: SupervisorAsToolOptions<TToolInput>): ToolContract<TToolInput, TOutput>;
43
+ //#endregion
44
+ export { asTool };
45
+ //# sourceMappingURL=as-tool.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"as-tool.d.mts","names":[],"sources":["../../../../../../@warlock.js/ai/src/supervisor/as-tool.ts"],"mappings":";;;;;;AA4CA;;;;;;;;;;;;;;;;;;;;;;;;AAGmC;;;;;;;;;;;iBAHnB,MAAA,qBAAA,CACd,kBAAA,EAAoB,kBAAA,CAAmB,OAAA,GACvC,OAAA,EAAS,uBAAA,CAAwB,UAAA,IAChC,YAAA,CAAa,UAAA,EAAY,OAAA"}
@@ -0,0 +1,80 @@
1
+ import { SupervisorFailedError } from "../errors/supervisor-failed-error.mjs";
2
+ import "../errors/index.mjs";
3
+ import { compositeAsTool } from "../tool/tool.mjs";
4
+
5
+ //#region ../../@warlock.js/ai/src/supervisor/as-tool.ts
6
+ /**
7
+ * Wrap a `SupervisorContract` as a `ToolContract` so an outer agent
8
+ * can invoke it from its tool-call loop. Mirrors
9
+ * `workflow.asTool()` / `agent.asTool()` — same composition pattern,
10
+ * same error-normalization behavior.
11
+ *
12
+ * Behavior:
13
+ * - The tool's `name` mirrors the supervisor's `name` unless the
14
+ * caller overrides via `options.name`. Supervisors without a
15
+ * meaningful name throw `SupervisorFailedError` — an outer agent
16
+ * can't route to an anonymous tool.
17
+ * - Tool `input` is the supplied schema; the validated value is
18
+ * coerced to a string (via `String()` for non-string values, or
19
+ * `JSON.stringify()` for objects) before being forwarded to
20
+ * `supervisor.execute(input)`. Consumers whose inputs need
21
+ * richer shaping should pre-format the string themselves.
22
+ * - On `result.error`, the supervisor error is thrown so the tool
23
+ * wrapper catches it and produces a `ToolExecutionError` with
24
+ * `cause` set to the original typed supervisor error — the outer
25
+ * agent sees one uniform error class regardless of which
26
+ * primitive failed.
27
+ *
28
+ * **Usage caveat** (mirrors workflow-as-tool): nested usage is not
29
+ * rolled into the outer agent's `result.usage` today — the
30
+ * supervisor's tokens stay on the supervisor result. Sum manually
31
+ * if you need a combined cost number until nested-usage
32
+ * standardization lands.
33
+ *
34
+ * @example
35
+ * const support = ai.supervisor({ ... });
36
+ * const supportTool = support.asTool({
37
+ * name: "handle_support_ticket",
38
+ * description: "Process a customer support ticket end-to-end.",
39
+ * inputSchema: z.object({ ticket: z.string() }),
40
+ * });
41
+ * const concierge = ai.agent({ model, tools: [supportTool] });
42
+ */
43
+ function asTool(supervisorInstance, options) {
44
+ if (!supervisorInstance.name || typeof supervisorInstance.name !== "string") throw new SupervisorFailedError("supervisor.asTool(): supervisor must have a `name` to be wrapped as a tool");
45
+ return compositeAsTool({
46
+ name: options.name ?? supervisorInstance.name,
47
+ description: options.description ?? `Invoke supervisor "${supervisorInstance.name}" as a tool.`,
48
+ input: options.inputSchema,
49
+ execute: async (input) => {
50
+ const coerced = coerceInput(input);
51
+ const result = await supervisorInstance.execute(coerced);
52
+ if (result.error) throw result.error;
53
+ return {
54
+ data: result.data,
55
+ usage: result.usage,
56
+ report: result.report
57
+ };
58
+ }
59
+ });
60
+ }
61
+ /**
62
+ * Coerce a tool-input value into the `string` shape supervisor
63
+ * `execute()` expects. Strings pass through; everything else gets
64
+ * JSON-stringified so supervisors invoked via tool wrappers receive a
65
+ * predictable textual input regardless of how the outer agent shaped
66
+ * its call.
67
+ */
68
+ function coerceInput(value) {
69
+ if (typeof value === "string") return value;
70
+ if (value === void 0 || value === null) return "";
71
+ try {
72
+ return JSON.stringify(value);
73
+ } catch {
74
+ return String(value);
75
+ }
76
+ }
77
+
78
+ //#endregion
79
+ export { asTool };
80
+ //# sourceMappingURL=as-tool.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"as-tool.mjs","names":[],"sources":["../../../../../../@warlock.js/ai/src/supervisor/as-tool.ts"],"sourcesContent":["import type {\n SupervisorAsToolOptions,\n SupervisorContract,\n} from \"../contracts/supervisor/supervisor.contract\";\nimport { SupervisorFailedError } from \"../errors\";\nimport { compositeAsTool, type ToolContract } from \"../tool/tool\";\n\n/**\n * Wrap a `SupervisorContract` as a `ToolContract` so an outer agent\n * can invoke it from its tool-call loop. Mirrors\n * `workflow.asTool()` / `agent.asTool()` — same composition pattern,\n * same error-normalization behavior.\n *\n * Behavior:\n * - The tool's `name` mirrors the supervisor's `name` unless the\n * caller overrides via `options.name`. Supervisors without a\n * meaningful name throw `SupervisorFailedError` — an outer agent\n * can't route to an anonymous tool.\n * - Tool `input` is the supplied schema; the validated value is\n * coerced to a string (via `String()` for non-string values, or\n * `JSON.stringify()` for objects) before being forwarded to\n * `supervisor.execute(input)`. Consumers whose inputs need\n * richer shaping should pre-format the string themselves.\n * - On `result.error`, the supervisor error is thrown so the tool\n * wrapper catches it and produces a `ToolExecutionError` with\n * `cause` set to the original typed supervisor error — the outer\n * agent sees one uniform error class regardless of which\n * primitive failed.\n *\n * **Usage caveat** (mirrors workflow-as-tool): nested usage is not\n * rolled into the outer agent's `result.usage` today — the\n * supervisor's tokens stay on the supervisor result. Sum manually\n * if you need a combined cost number until nested-usage\n * standardization lands.\n *\n * @example\n * const support = ai.supervisor({ ... });\n * const supportTool = support.asTool({\n * name: \"handle_support_ticket\",\n * description: \"Process a customer support ticket end-to-end.\",\n * inputSchema: z.object({ ticket: z.string() }),\n * });\n * const concierge = ai.agent({ model, tools: [supportTool] });\n */\nexport function asTool<TOutput, TToolInput>(\n supervisorInstance: SupervisorContract<TOutput>,\n options: SupervisorAsToolOptions<TToolInput>,\n): ToolContract<TToolInput, TOutput> {\n if (!supervisorInstance.name || typeof supervisorInstance.name !== \"string\") {\n throw new SupervisorFailedError(\n \"supervisor.asTool(): supervisor must have a `name` to be wrapped as a tool\",\n );\n }\n\n return compositeAsTool<TToolInput, TOutput>({\n name: options.name ?? supervisorInstance.name,\n description: options.description ?? `Invoke supervisor \"${supervisorInstance.name}\" as a tool.`,\n input: options.inputSchema,\n execute: async (input) => {\n const coerced = coerceInput(input);\n const result = await supervisorInstance.execute(coerced);\n\n if (result.error) {\n // Surface the typed supervisor error — the outer ToolContract\n // wraps it as a ToolExecutionError with `cause` preserved.\n throw result.error;\n }\n\n return {\n data: result.data as TOutput,\n usage: result.usage,\n report: result.report,\n };\n },\n });\n}\n\n/**\n * Coerce a tool-input value into the `string` shape supervisor\n * `execute()` expects. Strings pass through; everything else gets\n * JSON-stringified so supervisors invoked via tool wrappers receive a\n * predictable textual input regardless of how the outer agent shaped\n * its call.\n */\nfunction coerceInput(value: unknown): string {\n if (typeof value === \"string\") {\n return value;\n }\n\n if (value === undefined || value === null) {\n return \"\";\n }\n\n try {\n return JSON.stringify(value);\n } catch {\n return String(value);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CA,SAAgB,OACd,oBACA,SACmC;CACnC,IAAI,CAAC,mBAAmB,QAAQ,OAAO,mBAAmB,SAAS,UACjE,MAAM,IAAI,sBACR,4EACF;CAGF,OAAO,gBAAqC;EAC1C,MAAM,QAAQ,QAAQ,mBAAmB;EACzC,aAAa,QAAQ,eAAe,sBAAsB,mBAAmB,KAAK;EAClF,OAAO,QAAQ;EACf,SAAS,OAAO,UAAU;GACxB,MAAM,UAAU,YAAY,KAAK;GACjC,MAAM,SAAS,MAAM,mBAAmB,QAAQ,OAAO;GAEvD,IAAI,OAAO,OAGT,MAAM,OAAO;GAGf,OAAO;IACL,MAAM,OAAO;IACb,OAAO,OAAO;IACd,QAAQ,OAAO;GACjB;EACF;CACF,CAAC;AACH;;;;;;;;AASA,SAAS,YAAY,OAAwB;CAC3C,IAAI,OAAO,UAAU,UACnB,OAAO;CAGT,IAAI,UAAU,UAAa,UAAU,MACnC,OAAO;CAGT,IAAI;EACF,OAAO,KAAK,UAAU,KAAK;CAC7B,QAAQ;EACN,OAAO,OAAO,KAAK;CACrB;AACF"}
@@ -0,0 +1,12 @@
1
+ import { SupervisorCancelledError } from "../errors/supervisor-cancelled-error.mjs";
2
+ //#region ../../@warlock.js/ai/src/supervisor/cancellation.d.ts
3
+ /**
4
+ * Build a `SupervisorCancelledError` from an `AbortSignal`. Extracts a
5
+ * human-readable reason from `signal.reason` whether it was a string,
6
+ * an `Error`, or some other value. Used at between-iteration boundaries
7
+ * and on any mid-iteration cancellation path.
8
+ */
9
+ declare function createCancelledError(signal: AbortSignal | undefined): SupervisorCancelledError;
10
+ //#endregion
11
+ export { createCancelledError };
12
+ //# sourceMappingURL=cancellation.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cancellation.d.mts","names":[],"sources":["../../../../../../@warlock.js/ai/src/supervisor/cancellation.ts"],"mappings":";;;;;AAQA;;;iBAAgB,oBAAA,CACd,MAAA,EAAQ,WAAA,eACP,wBAAwB"}