@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,140 @@
1
+ import { AIError } from "../../errors/ai-error.mjs";
2
+ import { AgentResult } from "../result/agent-result.type.mjs";
3
+ import { ToolInvokeResult } from "../../tool/tool.mjs";
4
+ import { MiddlewareExecuteContext, MiddlewareToolContext, MiddlewareTripContext } from "./middleware-context.type.mjs";
5
+ import { ModelResponse } from "../model.contract.mjs";
6
+
7
+ //#region ../../@warlock.js/ai/src/contracts/middleware/middleware.contract.d.ts
8
+ /**
9
+ * `execute`-level hook map. Wraps the entire `agent.execute()` call.
10
+ *
11
+ * - `before` — fires once at the start of the run. Throw to abort the
12
+ * whole execution before any model call is made (e.g. budget pre-check,
13
+ * hard deny based on a ctx flag).
14
+ * - `after` — fires once at the end of a successful run with the final
15
+ * `AgentResult`. Optional return value replaces the result. Does not
16
+ * fire when the run errored — use `onError` for that path.
17
+ * - `onError`— fires once when the run aborted with an error. Optional
18
+ * return value recovers: the engine treats the returned `AgentResult`
19
+ * as the real outcome and clears the error. `void` / omitted rethrow.
20
+ */
21
+ type AgentMiddlewareExecuteHooks = {
22
+ before?(ctx: MiddlewareExecuteContext): void | Promise<void>;
23
+ after?(ctx: MiddlewareExecuteContext, result: AgentResult<unknown>): void | AgentResult<unknown> | Promise<void | AgentResult<unknown>>;
24
+ onError?(ctx: MiddlewareExecuteContext, error: AIError): void | AgentResult<unknown> | Promise<void | AgentResult<unknown>>;
25
+ };
26
+ /**
27
+ * `trip`-level hook map. Wraps each model round-trip individually.
28
+ *
29
+ * - `before` — fires just before `model.complete()` / `model.stream()`.
30
+ * Return a `ModelResponse` to short-circuit the call entirely
31
+ * (semantic cache hit, offline fixture replay). Throw to abort the
32
+ * trip with a typed error (guardrail input rejection).
33
+ * - `after` — fires immediately after a successful model response.
34
+ * Optional `ModelResponse` return replaces the response before the
35
+ * engine builds its `LLMTrip` record or dispatches tool calls.
36
+ * - `onError`— fires when the model call threw. Return a `ModelResponse`
37
+ * to recover (fallback chain), or `void` to propagate the error up.
38
+ */
39
+ type AgentMiddlewareTripHooks = {
40
+ before?(ctx: MiddlewareTripContext): void | ModelResponse | Promise<void | ModelResponse>;
41
+ after?(ctx: MiddlewareTripContext, response: ModelResponse): void | ModelResponse | Promise<void | ModelResponse>;
42
+ onError?(ctx: MiddlewareTripContext, error: AIError): void | ModelResponse | Promise<void | ModelResponse>;
43
+ };
44
+ /**
45
+ * `tool`-level hook map. Wraps each tool dispatch individually.
46
+ *
47
+ * - `before` — fires just before the wrapped `tool.invoke()`. Return a
48
+ * `ToolInvokeResult` to short-circuit (cached tool response, hard
49
+ * rate-limit rejection). Throw to abort the agent with a typed error.
50
+ * - `after` — fires after a successful tool invocation. Optional
51
+ * `ToolInvokeResult` return replaces the result before the engine
52
+ * records it into `toolCalls` / the next trip's messages.
53
+ * - `onError`— fires when the tool threw synchronously (rare — `invoke`
54
+ * itself never throws; this covers catastrophic runtime crashes in
55
+ * the pipeline wrap). Return a `ToolInvokeResult` to recover.
56
+ */
57
+ type AgentMiddlewareToolHooks = {
58
+ before?(ctx: MiddlewareToolContext): void | ToolInvokeResult<unknown> | Promise<void | ToolInvokeResult<unknown>>;
59
+ after?(ctx: MiddlewareToolContext, result: ToolInvokeResult<unknown>): void | ToolInvokeResult<unknown> | Promise<void | ToolInvokeResult<unknown>>;
60
+ onError?(ctx: MiddlewareToolContext, error: AIError): void | ToolInvokeResult<unknown> | Promise<void | ToolInvokeResult<unknown>>;
61
+ };
62
+ /**
63
+ * Agent-level middleware — a composable interceptor that wraps agent
64
+ * execution at one or more of three granularities: the whole
65
+ * `agent.execute()` call (`execute`), each LLM round-trip (`trip`),
66
+ * and each tool dispatch (`tool`).
67
+ *
68
+ * **Role.** The single authoring surface for cross-cutting concerns
69
+ * around an agent: budgets, guardrails, semantic cache, observability
70
+ * exports, fallback chains. One middleware = one config object.
71
+ * Middleware declares **any subset** of the three level hook maps; the
72
+ * pipeline skips levels a given middleware doesn't care about.
73
+ *
74
+ * **Ordering.** Registration order defines execution order: for every
75
+ * level, `before` hooks run top-down through the array, `after` and
76
+ * `onError` hooks run bottom-up (onion model — same mental picture as
77
+ * Koa / Express middleware). No priority numbers. The canonical
78
+ * install order documented in the subskill is:
79
+ * `[cache, budget, guardrail, observability]`.
80
+ *
81
+ * **Abort vs. synthetic-return.** Middleware has two ways to change
82
+ * behavior. Throwing an `AIError` aborts the wrapped operation (the
83
+ * error surfaces on `result.error` — `execute()` still never throws).
84
+ * Returning a value from a `before` hook short-circuits the wrapped
85
+ * operation with that value as its result, skipping the real work
86
+ * and running `after` hooks in reverse as if the wrapped operation
87
+ * had produced the value itself. Cache hits use the short-circuit
88
+ * path; budgets and guardrails use the throw path.
89
+ *
90
+ * **State.** Middleware never holds mutable state in closure — a
91
+ * single middleware object may be registered on multiple agents, or
92
+ * invoked by concurrent `execute()` calls on the same agent. Use
93
+ * `ctx.state` (fresh per execution) for any cross-hook bookkeeping.
94
+ *
95
+ * **Type independence.** Middleware is never generic over the agent's
96
+ * `TOutput`. A budget or guardrail must be reusable across every
97
+ * agent in the app, so all level hooks see `AgentResult<unknown>` and
98
+ * `AgentExecuteOptions<unknown>`. Output-specific logic belongs in
99
+ * the caller or in a purpose-built middleware for that agent.
100
+ *
101
+ * @example
102
+ * const budget: AgentMiddleware = {
103
+ * name: "budget",
104
+ * execute: {
105
+ * before(ctx) { ctx.state.set("budget.used", 0); },
106
+ * },
107
+ * trip: {
108
+ * after(ctx, response) {
109
+ * const used = (ctx.state.get("budget.used") as number) + response.usage.total;
110
+ * ctx.state.set("budget.used", used);
111
+ * if (used > 1_000) throw new BudgetExceededError("token cap", { limit: 1_000, actual: used, unit: "tokens" });
112
+ * },
113
+ * },
114
+ * };
115
+ *
116
+ * const myAgent = agent({
117
+ * model,
118
+ * middleware: [budget],
119
+ * });
120
+ */
121
+ type AgentMiddleware = {
122
+ /**
123
+ * Stable identifier for this middleware — used in logs, as the
124
+ * state-bag namespace prefix, and in the canonical install-order
125
+ * documentation. Should be kebab-case.
126
+ */
127
+ name: string;
128
+ /**
129
+ * Optional per-middleware log kill-switch. `false` silences the
130
+ * pipeline's `debug`-level trace for this middleware only; other
131
+ * middlewares in the same pipeline continue logging. Default `true`.
132
+ */
133
+ log?: boolean;
134
+ execute?: AgentMiddlewareExecuteHooks;
135
+ trip?: AgentMiddlewareTripHooks;
136
+ tool?: AgentMiddlewareToolHooks;
137
+ };
138
+ //#endregion
139
+ export { AgentMiddleware, AgentMiddlewareExecuteHooks, AgentMiddlewareToolHooks, AgentMiddlewareTripHooks };
140
+ //# sourceMappingURL=middleware.contract.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"middleware.contract.d.mts","names":[],"sources":["../../../../../../../@warlock.js/ai/src/contracts/middleware/middleware.contract.ts"],"mappings":";;;;;;;;;;AAuBA;;;;;;;;;;KAAY,2BAAA;EACV,MAAA,EAAQ,GAAA,EAAK,wBAAA,UAAkC,OAAA;EAC/C,KAAA,EACE,GAAA,EAAK,wBAAA,EACL,MAAA,EAAQ,WAAA,mBACA,WAAA,YAAuB,OAAA,QAAe,WAAA;EAChD,OAAA,EACE,GAAA,EAAK,wBAAA,EACL,KAAA,EAAO,OAAA,UACC,WAAA,YAAuB,OAAA,QAAe,WAAA;AAAA;;;;;;;;;;;;;;KAgBtC,wBAAA;EACV,MAAA,EACE,GAAA,EAAK,qBAAA,UACG,aAAA,GAAgB,OAAA,QAAe,aAAA;EACzC,KAAA,EACE,GAAA,EAAK,qBAAA,EACL,QAAA,EAAU,aAAA,UACF,aAAA,GAAgB,OAAA,QAAe,aAAA;EACzC,OAAA,EACE,GAAA,EAAK,qBAAA,EACL,KAAA,EAAO,OAAA,UACC,aAAA,GAAgB,OAAA,QAAe,aAAA;AAAA;;;;;;AA3BkB;AAgB7D;;;;;;;KA2BY,wBAAA;EACV,MAAA,EACE,GAAA,EAAK,qBAAA,UAGH,gBAAA,YACA,OAAA,QAAe,gBAAA;EACnB,KAAA,EACE,GAAA,EAAK,qBAAA,EACL,MAAA,EAAQ,gBAAA,mBAGN,gBAAA,YACA,OAAA,QAAe,gBAAA;EACnB,OAAA,EACE,GAAA,EAAK,qBAAA,EACL,KAAA,EAAO,OAAA,UAGL,gBAAA,YACA,OAAA,QAAe,gBAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AApCmC;AAgBxD;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAkFY,eAAA;EAzER;;;;;EA+EF,IAAA;EAzEE;;;;;EA+EF,GAAA;EACA,OAAA,GAAU,2BAAA;EACV,IAAA,GAAO,wBAAA;EACP,IAAA,GAAO,wBAAA;AAAA"}
@@ -0,0 +1,58 @@
1
+ //#region ../../@warlock.js/ai/src/contracts/model-tool-call-request.type.d.ts
2
+ /**
3
+ * A raw tool call request returned by the model during a complete() call or
4
+ * emitted as a chunk during stream(). Agents look up the tool by `name` and
5
+ * correlate the eventual tool-result message back to the model using `id`.
6
+ *
7
+ * @example
8
+ * const req: ModelToolCallRequest = {
9
+ * id: "call_abc123",
10
+ * name: "searchWeb",
11
+ * input: { query: "warlock.js docs" },
12
+ * };
13
+ */
14
+ type ModelToolCallRequest = {
15
+ /** Provider-generated id; agent echoes it on the matching tool-result message */id: string; /** Registered tool name the model wants to invoke */
16
+ name: string; /** Arguments the model produced for the tool */
17
+ input: unknown;
18
+ /**
19
+ * Provenance marker stamped by the framework, NOT the provider.
20
+ * Present only when the agent's stream-time tool-call guard
21
+ * synthesized this request from a JSON envelope the model emitted as
22
+ * literal text in the content channel. Absent means the provider
23
+ * emitted a structured tool call (the normal path).
24
+ *
25
+ * Consumers branch on this for:
26
+ * - **Telemetry**: dashboards measure per-model leak rate as
27
+ * `recovered / total`. High rates are a strong signal to drop the
28
+ * model from the rotation.
29
+ * - **Cost auditing**: recovered calls cost the same as real ones
30
+ * in terms of tool execution, but the *prompt tokens* that produced
31
+ * them were wasted on text the user couldn't see. Worth tracking.
32
+ *
33
+ * The framework treats it as informational only — recovered calls
34
+ * dispatch through the same path as real ones with no behavioral
35
+ * difference.
36
+ */
37
+ recoveredFrom?: "stream-text";
38
+ /**
39
+ * Opaque, provider-specific data the adapter must round-trip back to
40
+ * the provider on the *next* request for this tool call to remain
41
+ * valid. The framework treats it as a black box: it never reads or
42
+ * mutates the contents — it only guarantees the object survives from
43
+ * the model response, through the assistant history message, back
44
+ * into the adapter's next request.
45
+ *
46
+ * Concrete need: Gemini "thinking" models attach a `thoughtSignature`
47
+ * to every `functionCall` part and **reject the follow-up request
48
+ * with a 400** if it is missing. Anthropic extended-thinking
49
+ * signatures are the same shape of problem. Vendor-neutral by
50
+ * design — only the owning adapter knows the keys.
51
+ *
52
+ * Absent for providers (OpenAI, Bedrock, Ollama) that need no echo.
53
+ */
54
+ providerMetadata?: Record<string, unknown>;
55
+ };
56
+ //#endregion
57
+ export { ModelToolCallRequest };
58
+ //# sourceMappingURL=model-tool-call-request.type.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model-tool-call-request.type.d.mts","names":[],"sources":["../../../../../../@warlock.js/ai/src/contracts/model-tool-call-request.type.ts"],"mappings":";;AAYA;;;;;;;;;;;KAAY,oBAAA;mFAEV,EAAA;EAEA,IAAA;EAEA,KAAA;;;;;;;;;;;;;;;;;;;;EAoBA,aAAA;;;;;;;;;;;;;;;;;EAiBA,gBAAA,GAAmB,MAAM;AAAA"}
@@ -0,0 +1,164 @@
1
+ import { ModelToolCallRequest } from "./model-tool-call-request.type.mjs";
2
+ import { Message } from "./conversation-message.type.mjs";
3
+ import { ModelPricing } from "./result/model-pricing.type.mjs";
4
+ import { Usage } from "./result/usage.type.mjs";
5
+ import { FinishReason } from "./finish-reason.type.mjs";
6
+ import { ToolConfig } from "./tool.contract.mjs";
7
+
8
+ //#region ../../@warlock.js/ai/src/contracts/model.contract.d.ts
9
+ /**
10
+ * Options passed to model.complete() or model.stream().
11
+ *
12
+ * `tools` is first-class so every model implementation is responsible for
13
+ * converting the vendor-neutral ToolConfig into its own provider format
14
+ * (OpenAI functions, Anthropic tools, etc.).
15
+ *
16
+ * @example
17
+ * await model.complete(messages, {
18
+ * temperature: 0.2,
19
+ * maxTokens: 1000,
20
+ * tools: [weatherTool, searchTool],
21
+ * });
22
+ */
23
+ type ModelCallOptions = {
24
+ temperature?: number;
25
+ maxTokens?: number; /** Tools to expose to the LLM on this call. Each model converts to its provider format. */
26
+ tools?: ToolConfig<unknown, unknown>[];
27
+ /**
28
+ * JSON Schema the response must match. Adapters that declare
29
+ * `capabilities.structuredOutput` forward this to the provider's native
30
+ * structured-output mechanism (OpenAI `response_format: json_schema`,
31
+ * Anthropic tool-use trick, etc.). Adapters without native support may
32
+ * ignore this field — the agent still injects a soft JSON instruction
33
+ * into the system prompt as a fallback.
34
+ */
35
+ responseSchema?: Record<string, unknown>;
36
+ /**
37
+ * Cancellation handle. Adapters that wire it into their HTTP client
38
+ * (OpenAI SDK, fetch) will abort the in-flight request when
39
+ * `signal.aborted` flips. Adapters without support may ignore it;
40
+ * the agent still honors the signal at trip boundaries regardless.
41
+ */
42
+ signal?: AbortSignal; /** Additional provider-specific options */
43
+ [key: string]: unknown;
44
+ };
45
+ /**
46
+ * Declarative feature flags a `ModelContract` may expose so the agent can
47
+ * short-circuit redundant work when the provider already enforces a
48
+ * behavior natively.
49
+ *
50
+ * @example
51
+ * class OpenAIModel implements ModelContract {
52
+ * public readonly capabilities: ModelCapabilities = { structuredOutput: true };
53
+ * }
54
+ */
55
+ type ModelCapabilities = {
56
+ /**
57
+ * True when the adapter forwards `ModelCallOptions.responseSchema` to
58
+ * the provider's native structured-output mechanism and the provider
59
+ * guarantees a matching response at the token level. When true, the
60
+ * agent skips the soft "respond in JSON" system-prompt injection.
61
+ */
62
+ structuredOutput?: boolean;
63
+ /**
64
+ * True when the adapter accepts `ContentPart` entries of type
65
+ * `"image"` in user messages and the provider can interpret them
66
+ * (vision models). When false/absent and the caller passes image
67
+ * attachments, the agent throws upfront rather than silently
68
+ * dropping them at the wire layer.
69
+ */
70
+ vision?: boolean;
71
+ };
72
+ /**
73
+ * Full response from a non-streaming model call.
74
+ *
75
+ * @example
76
+ * const response: ModelResponse = {
77
+ * content: "Here is the answer...",
78
+ * finishReason: "stop",
79
+ * usage: { input: 120, output: 80, total: 200 },
80
+ * };
81
+ */
82
+ type ModelResponse = {
83
+ content: string;
84
+ finishReason: FinishReason;
85
+ usage: Usage; /** Tool calls requested by the model, present when finishReason is "tool_calls" */
86
+ toolCalls?: ModelToolCallRequest[];
87
+ };
88
+ /**
89
+ * A single chunk emitted during a streaming model call.
90
+ *
91
+ * @example
92
+ * for await (const chunk of model.stream(messages)) {
93
+ * if (chunk.type === "delta") process.stdout.write(chunk.content);
94
+ * else if (chunk.type === "done") console.log(chunk.usage.total, "tokens");
95
+ * }
96
+ */
97
+ type ModelStreamChunk = {
98
+ type: "delta";
99
+ content: string;
100
+ } | {
101
+ type: "tool-call";
102
+ id: string;
103
+ name: string;
104
+ input: unknown;
105
+ /**
106
+ * Opaque provider round-trip data for this call — see
107
+ * `ModelToolCallRequest.providerMetadata`. The agent copies it
108
+ * verbatim onto the assembled `ModelToolCallRequest` so streamed
109
+ * tool calls round-trip identically to non-streamed ones.
110
+ */
111
+ providerMetadata?: Record<string, unknown>;
112
+ } | {
113
+ type: "done";
114
+ finishReason: FinishReason;
115
+ usage: Usage;
116
+ };
117
+ /**
118
+ * Contract every SDK model instance must implement.
119
+ * Created by SDKAdapterContract.model() — internally holds the SDK client
120
+ * so agents only need to pass the model, not the SDK.
121
+ *
122
+ * @example
123
+ * const model = ai.openai.model({ name: "gpt-4o", temperature: 0.7 });
124
+ * const response = await model.complete(messages);
125
+ *
126
+ * @example
127
+ * for await (const chunk of model.stream(messages)) {
128
+ * if (chunk.type === "delta") process.stdout.write(chunk.content);
129
+ * }
130
+ */
131
+ interface ModelContract {
132
+ /** Model identifier (e.g. "gpt-4o", "claude-3-5-sonnet-20241022") */
133
+ readonly name: string;
134
+ /** Provider this model belongs to (e.g. "openai", "anthropic") */
135
+ readonly provider: string;
136
+ /**
137
+ * Optional feature flags so callers (notably the agent) can skip work
138
+ * the provider already handles natively. Absent = treat every flag as
139
+ * `false`.
140
+ */
141
+ readonly capabilities?: ModelCapabilities;
142
+ /**
143
+ * Per-million-token USD pricing. When set, the framework computes
144
+ * `Usage.costUSD` at emit time for every trip / tool / report node
145
+ * touching this model. Resolution: per-model `pricing` (here) >
146
+ * SDK-level `pricing[name]` registry > undefined (no cost computed).
147
+ *
148
+ * Critical for multi-tenant projects where pricing is contract-
149
+ * specific or runtime-resolved — pass per-model when you need to
150
+ * override the SDK registry for a single agent.
151
+ */
152
+ readonly pricing?: ModelPricing;
153
+ /**
154
+ * Send messages and receive a full response once generation is complete.
155
+ */
156
+ complete(messages: Message[], options?: ModelCallOptions): Promise<ModelResponse>;
157
+ /**
158
+ * Send messages and stream the response chunk by chunk.
159
+ */
160
+ stream(messages: Message[], options?: ModelCallOptions): AsyncIterable<ModelStreamChunk>;
161
+ }
162
+ //#endregion
163
+ export { ModelCallOptions, ModelCapabilities, ModelContract, ModelResponse, ModelStreamChunk };
164
+ //# sourceMappingURL=model.contract.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model.contract.d.mts","names":[],"sources":["../../../../../../@warlock.js/ai/src/contracts/model.contract.ts"],"mappings":";;;;;;;;;;AAqBA;;;;;;;;;;;;KAAY,gBAAA;EACV,WAAA;EACA,SAAA,WAkBS;EAhBT,KAAA,GAAQ,UAAA;EAkBI;AAAA;AAad;;;;AAeQ;AAaR;EAlDE,cAAA,GAAiB,MAAA;;;;;;;EAOjB,MAAA,GAAS,WAAA,EA6CT;EAAA,CA3CC,GAAA;AAAA;;;;;AA8C+B;AAYlC;;;;;KA7CY,iBAAA;EA4DgD;;;;;;EArD1D,gBAAA;EA4CI;;;;;;;EApCJ,MAAM;AAAA;AA6CoD;AAgB5D;;;;;;;;;AAhB4D,KAhChD,aAAA;EACV,OAAA;EACA,YAAA,EAAc,YAAA;EACd,KAAA,EAAO,KAAA,EA6E+D;EA3EtE,SAAA,GAAY,oBAAA;AAAA;;;;;;;;;;KAYF,gBAAA;EACN,IAAA;EAAe,OAAA;AAAA;EAEf,IAAA;EACA,EAAA;EACA,IAAA;EACA,KAAA;EAyDqD;;;AAA8B;;;EAlDnF,gBAAA,GAAmB,MAAA;AAAA;EAEnB,IAAA;EAAc,YAAA,EAAc,YAAA;EAAc,KAAA,EAAO,KAAA;AAAA;;;;;;;;;;;;;;;UAgBtC,aAAA;;WAEN,IAAA;;WAEA,QAAA;;;;;;WAMA,YAAA,GAAe,iBAAA;;;;;;;;;;;WAYf,OAAA,GAAU,YAAA;;;;EAKnB,QAAA,CAAS,QAAA,EAAU,OAAA,IAAW,OAAA,GAAU,gBAAA,GAAmB,OAAA,CAAQ,aAAA;;;;EAKnE,MAAA,CAAO,QAAA,EAAU,OAAA,IAAW,OAAA,GAAU,gBAAA,GAAmB,aAAA,CAAc,gBAAA;AAAA"}
@@ -0,0 +1,23 @@
1
+ //#region ../../@warlock.js/ai/src/contracts/placeholders.type.d.ts
2
+ /**
3
+ * A map of placeholder keys to their replacement values.
4
+ * Supports nested access via dot notation in {{mustache}} templates.
5
+ *
6
+ * Syntax:
7
+ * - `{{key}}` — simple replacement
8
+ * - `{{ctx.city}}` — nested access
9
+ * - `{{lang|English}}` — with default value
10
+ *
11
+ * @example
12
+ * const placeholders: Placeholders = {
13
+ * name: "Hasan",
14
+ * ctx: { city: "Cairo", country: "Egypt" },
15
+ * lang: "Arabic",
16
+ * };
17
+ * // Template: "Hello {{name}}, welcome from {{ctx.city}}. Language: {{lang|English}}"
18
+ * // Resolved: "Hello Hasan, welcome from Cairo. Language: Arabic"
19
+ */
20
+ type Placeholders = Record<string, unknown>;
21
+ //#endregion
22
+ export { Placeholders };
23
+ //# sourceMappingURL=placeholders.type.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"placeholders.type.d.mts","names":[],"sources":["../../../../../../@warlock.js/ai/src/contracts/placeholders.type.ts"],"mappings":";;AAkBA;;;;AAAiC;;;;;;;;;;;;;KAArB,YAAA,GAAe,MAAM"}
@@ -0,0 +1,33 @@
1
+ import { BaseResult } from "./base-result.type.mjs";
2
+ import { AgentReport } from "./execution-report.type.mjs";
3
+
4
+ //#region ../../@warlock.js/ai/src/contracts/result/agent-result.type.d.ts
5
+ /**
6
+ * Result returned by `agent.execute()` and resolved by `stream.result`.
7
+ *
8
+ * **Canonical destructuring:** `const { data, text, report, usage, error }`.
9
+ *
10
+ * `report.trips` / `report.toolCalls` / `report.duration` hold
11
+ * everything the old top-level fields did — moving them under
12
+ * `report` leaves the root clean for the four things callers reach
13
+ * for constantly (`data`, `text`, `usage`, `error`).
14
+ *
15
+ * @example
16
+ * const { data, error, report, usage } = await agent.execute(input);
17
+ *
18
+ * if (error) {
19
+ * logger.error(error.code, { duration: report.duration });
20
+ * return;
21
+ * }
22
+ *
23
+ * return { answer: data, cost: usage.total, latency: report.duration };
24
+ */
25
+ type AgentResult<TOutput = unknown> = BaseResult & {
26
+ /** Discriminant for narrowing `SessionSendResult.executionResult`. */type: "agent"; /** Typed structured output when the caller passed an `output` schema. */
27
+ data?: TOutput; /** Raw text from the final LLM trip. */
28
+ text?: string; /** Trips, tool calls, status, and timing for this execution. */
29
+ report: AgentReport;
30
+ };
31
+ //#endregion
32
+ export { AgentResult };
33
+ //# sourceMappingURL=agent-result.type.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-result.type.d.mts","names":[],"sources":["../../../../../../../@warlock.js/ai/src/contracts/result/agent-result.type.ts"],"mappings":";;;;;;AAuBA;;;;;;;;;;;;;;;;;AAQqB;KART,WAAA,sBAAiC,UAAA;wEAE3C,IAAA;EAEA,IAAA,GAAO,OAAA;EAEP,IAAA;EAEA,MAAA,EAAQ,WAAA;AAAA"}
@@ -0,0 +1,40 @@
1
+ import { AIError } from "../../errors/ai-error.mjs";
2
+
3
+ //#region ../../@warlock.js/ai/src/contracts/result/attempt-entry.type.d.ts
4
+ /**
5
+ * One row in an executable's retry history. Captures a single
6
+ * attempt's timing + outcome — populated wherever retry happens:
7
+ *
8
+ * - **Workflow** — per-step retry loop (native, see `step-runner.ts`),
9
+ * surfaced at `StepSnapshot.attemptHistory`.
10
+ * - **Agent / Tool / Supervisor** — middleware-driven retries write
11
+ * here via `MiddlewareState`; the executable surfaces them at
12
+ * `BaseReport.attempts` so Panoptic / cost dashboards see the
13
+ * real call count, not just the surviving success.
14
+ *
15
+ * The shape is intentionally minimal — start-end-duration + status +
16
+ * error. Richer per-attempt forensics (input snapshot, partial output)
17
+ * stay out of the universal contract; consumers that need them attach
18
+ * via `error.context` or middleware-specific extensions.
19
+ *
20
+ * @example
21
+ * const entry: AttemptEntry = {
22
+ * index: 1,
23
+ * startedAt: "2026-05-12T09:00:00.000Z",
24
+ * endedAt: "2026-05-12T09:00:00.450Z",
25
+ * duration: 450,
26
+ * status: "failed",
27
+ * error: new ProviderRateLimitError("429"),
28
+ * };
29
+ */
30
+ type AttemptEntry = {
31
+ /** 1-based attempt index. */index: number;
32
+ startedAt: string;
33
+ endedAt: string;
34
+ duration: number;
35
+ status: "success" | "failed";
36
+ error?: AIError;
37
+ };
38
+ //#endregion
39
+ export { AttemptEntry };
40
+ //# sourceMappingURL=attempt-entry.type.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attempt-entry.type.d.mts","names":[],"sources":["../../../../../../../@warlock.js/ai/src/contracts/result/attempt-entry.type.ts"],"mappings":";;;;;AA4BA;;;;;;;;;;;;AAOiB;;;;;;;;;;;;KAPL,YAAA;+BAEV,KAAA;EACA,SAAA;EACA,OAAA;EACA,QAAA;EACA,MAAA;EACA,KAAA,GAAQ,OAAO;AAAA"}
@@ -0,0 +1,137 @@
1
+ import { Usage } from "./usage.type.mjs";
2
+ import { AttemptEntry } from "./attempt-entry.type.mjs";
3
+
4
+ //#region ../../@warlock.js/ai/src/contracts/result/base-report.type.d.ts
5
+ /**
6
+ * Wire-format version stamped on every root `BaseReport`. Bumped only
7
+ * when we make a BREAKING change to the report shape (field removed,
8
+ * required-ness flipped, semantics changed). Additive changes (new
9
+ * optional fields) do not bump.
10
+ *
11
+ * Panoptic and other downstream consumers branch on this to parse
12
+ * old stored reports with their original-shape rules.
13
+ *
14
+ * Current: **1** — initial Panoptic-readiness shape.
15
+ */
16
+ declare const REPORT_SCHEMA_VERSION = 1;
17
+ /**
18
+ * Discriminator for the kind of executable that produced a given
19
+ * {@link BaseReport}. Forms a closed union so consumers can narrow on
20
+ * the tree without string-matching on `name`.
21
+ */
22
+ type ReportType = "tool" | "callback" | "agent" | "workflow" | "supervisor";
23
+ /**
24
+ * Terminal status every executable primitive reports. Unified across
25
+ * tools, agents, workflows, and supervisors so dashboards and
26
+ * generic traversal helpers don't special-case per primitive.
27
+ *
28
+ * - `"completed"` — ran to natural end with a usable result.
29
+ * - `"failed"` — aborted mid-run or finished without a usable result
30
+ * (crash, schema failure, max-trips, etc.). The
31
+ * accompanying `error` on the envelope carries the typed cause.
32
+ * - `"cancelled"` — caller aborted before completion via `AbortSignal`.
33
+ * - `"max-iterations"` — supervisor-specific termination when the
34
+ * iteration cap was hit without an explicit `END` / `satisfied`.
35
+ * Harmless on non-supervisor reports; keeping it on the shared
36
+ * union lets consumers write one `switch` for every status.
37
+ */
38
+ type ReportStatus = "completed" | "failed" | "cancelled" | "max-iterations";
39
+ /**
40
+ * Universal execution report shared by every primitive. Per-primitive
41
+ * report types extend this with their own domain-specific fields
42
+ * (agent trips, workflow steps, supervisor iteration snapshots) while
43
+ * keeping the root fields identical. Recursion happens through
44
+ * {@link BaseReport.children} — any executable this node invoked
45
+ * contributes its own full report here, producing a walkable tree of
46
+ * the entire run.
47
+ *
48
+ * **Usage rollup.** `usage` at every node equals this node's own cost
49
+ * plus the sum of each child's `usage`. Leaves (tools) contribute
50
+ * zero own-cost; composites contribute their direct LLM spend only,
51
+ * with children covering everything delegated.
52
+ *
53
+ * @example
54
+ * function totalCost(report: BaseReport): number {
55
+ * return report.usage.total;
56
+ * }
57
+ *
58
+ * function walk(report: BaseReport, depth = 0): void {
59
+ * console.log(`${" ".repeat(depth)}${report.type} "${report.name}" — ${report.status}`);
60
+ * for (const child of report.children) walk(child, depth + 1);
61
+ * }
62
+ */
63
+ type BaseReport = {
64
+ /** Stable id for this execution node. Generated per `execute()`/`invoke()` call. */runId: string;
65
+ /**
66
+ * Run-id of the immediate parent execution node, when this node was
67
+ * invoked as part of a larger run (e.g. a tool dispatched by an
68
+ * agent; an agent dispatched by a supervisor; an inner primitive
69
+ * wrapped via `asTool()`). Absent on root nodes.
70
+ *
71
+ * Lets Panoptic and other flat-row consumers reconstruct the tree
72
+ * without traversing `children[]` in memory.
73
+ */
74
+ parentRunId?: string;
75
+ /**
76
+ * Run-id of the top-level execution this node belongs to. Equals
77
+ * `runId` on the root node, and is propagated downward to every
78
+ * descendant. Used to slice flat report tables back into per-run
79
+ * groupings.
80
+ */
81
+ rootRunId: string; /** Executable identity — the tool/agent/workflow/supervisor name. */
82
+ name: string;
83
+ /**
84
+ * Dev-curated version string mirrored from the primitive's config
85
+ * (`AgentConfig.version`, `ToolConfig.version`, etc.). Free-form —
86
+ * the framework neither parses nor compares it. Stored verbatim on
87
+ * every report so trip-archive queries can distinguish runs of
88
+ * "agent X v2.1" from "agent X v2.2" even when name + signature
89
+ * are identical.
90
+ *
91
+ * Stays `undefined` when the dev didn't declare one — never
92
+ * auto-defaulted.
93
+ */
94
+ version?: string;
95
+ /**
96
+ * Caller-supplied identifier that groups multiple `.execute()` calls
97
+ * into one conceptual user session / request. Propagated to every
98
+ * descendant report node so flat queries ("total spend for session
99
+ * X today") work without joining the tree.
100
+ *
101
+ * Threaded from `execute()` options on every primitive. Optional —
102
+ * absent when the caller didn't supply one.
103
+ */
104
+ sessionId?: string; /** Discriminator for the kind of executable that produced this report. */
105
+ type: ReportType; /** Terminal status of this execution. */
106
+ status: ReportStatus; /** ISO-8601 wall-clock timestamp when execution began. */
107
+ startedAt: string; /** ISO-8601 wall-clock timestamp when execution finished. */
108
+ endedAt: string; /** Monotonic duration in milliseconds — `performance.now()` delta. */
109
+ duration: number; /** Rolled-up usage: own cost + sum of `children[].usage`. */
110
+ usage: Usage;
111
+ /**
112
+ * Reports of every executable invoked by this node, in invocation
113
+ * order. Empty for leaves (pure tools) and for executables that
114
+ * didn't delegate work.
115
+ */
116
+ children: BaseReport[];
117
+ /**
118
+ * Retry history when middleware (or, for workflow steps, the engine
119
+ * itself) retried this node before it either succeeded or gave up.
120
+ * Absent when zero retries happened — keeps the common-case payload
121
+ * lean. The surviving (final) attempt is NOT duplicated here; its
122
+ * outcome is the report's own `status` / timing.
123
+ */
124
+ attempts?: AttemptEntry[];
125
+ /**
126
+ * Wire-format version of this report shape. Only present on root
127
+ * report nodes — implies the same version for the whole tree.
128
+ * Panoptic / archive consumers branch on this to parse old reports
129
+ * with their original-shape rules.
130
+ *
131
+ * Always equals {@link REPORT_SCHEMA_VERSION} at write time.
132
+ */
133
+ reportSchemaVersion?: number;
134
+ };
135
+ //#endregion
136
+ export { BaseReport, REPORT_SCHEMA_VERSION, ReportStatus, ReportType };
137
+ //# sourceMappingURL=base-report.type.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base-report.type.d.mts","names":[],"sources":["../../../../../../../@warlock.js/ai/src/contracts/result/base-report.type.ts"],"mappings":";;;;;;AAcA;;;;AAAkC;AAOlC;;;;cAPa,qBAAA;AA6Bb;;;;AAAwB;AAAxB,KAtBY,UAAA;;;;;;;;;;;;;;;;KAsBA,YAAA;;;;;;;;;;;;;;;AA4GS;;;;;;;;;;KA9ET,UAAA;sFAEV,KAAA;;;;;;;;;;EAUA,WAAA;;;;;;;EAOA,SAAA;EAEA,IAAA;;;;;;;;;;;;EAYA,OAAA;;;;;;;;;;EAUA,SAAA;EAEA,IAAA,EAAM,UAAA;EAEN,MAAA,EAAQ,YAAA;EAER,SAAA;EAEA,OAAA;EAEA,QAAA;EAEA,KAAA,EAAO,KAAA;;;;;;EAMP,QAAA,EAAU,UAAA;;;;;;;;EAQV,QAAA,GAAW,YAAA;;;;;;;;;EASX,mBAAA;AAAA"}
@@ -0,0 +1,17 @@
1
+ //#region ../../@warlock.js/ai/src/contracts/result/base-report.type.ts
2
+ /**
3
+ * Wire-format version stamped on every root `BaseReport`. Bumped only
4
+ * when we make a BREAKING change to the report shape (field removed,
5
+ * required-ness flipped, semantics changed). Additive changes (new
6
+ * optional fields) do not bump.
7
+ *
8
+ * Panoptic and other downstream consumers branch on this to parse
9
+ * old stored reports with their original-shape rules.
10
+ *
11
+ * Current: **1** — initial Panoptic-readiness shape.
12
+ */
13
+ const REPORT_SCHEMA_VERSION = 1;
14
+
15
+ //#endregion
16
+ export { REPORT_SCHEMA_VERSION };
17
+ //# sourceMappingURL=base-report.type.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base-report.type.mjs","names":[],"sources":["../../../../../../../@warlock.js/ai/src/contracts/result/base-report.type.ts"],"sourcesContent":["import type { AttemptEntry } from \"./attempt-entry.type\";\nimport type { Usage } from \"./usage.type\";\n\n/**\n * Wire-format version stamped on every root `BaseReport`. Bumped only\n * when we make a BREAKING change to the report shape (field removed,\n * required-ness flipped, semantics changed). Additive changes (new\n * optional fields) do not bump.\n *\n * Panoptic and other downstream consumers branch on this to parse\n * old stored reports with their original-shape rules.\n *\n * Current: **1** — initial Panoptic-readiness shape.\n */\nexport const REPORT_SCHEMA_VERSION = 1;\n\n/**\n * Discriminator for the kind of executable that produced a given\n * {@link BaseReport}. Forms a closed union so consumers can narrow on\n * the tree without string-matching on `name`.\n */\nexport type ReportType =\n | \"tool\"\n | \"callback\"\n | \"agent\"\n | \"workflow\"\n | \"supervisor\";\n\n/**\n * Terminal status every executable primitive reports. Unified across\n * tools, agents, workflows, and supervisors so dashboards and\n * generic traversal helpers don't special-case per primitive.\n *\n * - `\"completed\"` — ran to natural end with a usable result.\n * - `\"failed\"` — aborted mid-run or finished without a usable result\n * (crash, schema failure, max-trips, etc.). The\n * accompanying `error` on the envelope carries the typed cause.\n * - `\"cancelled\"` — caller aborted before completion via `AbortSignal`.\n * - `\"max-iterations\"` — supervisor-specific termination when the\n * iteration cap was hit without an explicit `END` / `satisfied`.\n * Harmless on non-supervisor reports; keeping it on the shared\n * union lets consumers write one `switch` for every status.\n */\nexport type ReportStatus =\n | \"completed\"\n | \"failed\"\n | \"cancelled\"\n | \"max-iterations\";\n\n/**\n * Universal execution report shared by every primitive. Per-primitive\n * report types extend this with their own domain-specific fields\n * (agent trips, workflow steps, supervisor iteration snapshots) while\n * keeping the root fields identical. Recursion happens through\n * {@link BaseReport.children} — any executable this node invoked\n * contributes its own full report here, producing a walkable tree of\n * the entire run.\n *\n * **Usage rollup.** `usage` at every node equals this node's own cost\n * plus the sum of each child's `usage`. Leaves (tools) contribute\n * zero own-cost; composites contribute their direct LLM spend only,\n * with children covering everything delegated.\n *\n * @example\n * function totalCost(report: BaseReport): number {\n * return report.usage.total;\n * }\n *\n * function walk(report: BaseReport, depth = 0): void {\n * console.log(`${\" \".repeat(depth)}${report.type} \"${report.name}\" — ${report.status}`);\n * for (const child of report.children) walk(child, depth + 1);\n * }\n */\nexport type BaseReport = {\n /** Stable id for this execution node. Generated per `execute()`/`invoke()` call. */\n runId: string;\n /**\n * Run-id of the immediate parent execution node, when this node was\n * invoked as part of a larger run (e.g. a tool dispatched by an\n * agent; an agent dispatched by a supervisor; an inner primitive\n * wrapped via `asTool()`). Absent on root nodes.\n *\n * Lets Panoptic and other flat-row consumers reconstruct the tree\n * without traversing `children[]` in memory.\n */\n parentRunId?: string;\n /**\n * Run-id of the top-level execution this node belongs to. Equals\n * `runId` on the root node, and is propagated downward to every\n * descendant. Used to slice flat report tables back into per-run\n * groupings.\n */\n rootRunId: string;\n /** Executable identity — the tool/agent/workflow/supervisor name. */\n name: string;\n /**\n * Dev-curated version string mirrored from the primitive's config\n * (`AgentConfig.version`, `ToolConfig.version`, etc.). Free-form —\n * the framework neither parses nor compares it. Stored verbatim on\n * every report so trip-archive queries can distinguish runs of\n * \"agent X v2.1\" from \"agent X v2.2\" even when name + signature\n * are identical.\n *\n * Stays `undefined` when the dev didn't declare one — never\n * auto-defaulted.\n */\n version?: string;\n /**\n * Caller-supplied identifier that groups multiple `.execute()` calls\n * into one conceptual user session / request. Propagated to every\n * descendant report node so flat queries (\"total spend for session\n * X today\") work without joining the tree.\n *\n * Threaded from `execute()` options on every primitive. Optional —\n * absent when the caller didn't supply one.\n */\n sessionId?: string;\n /** Discriminator for the kind of executable that produced this report. */\n type: ReportType;\n /** Terminal status of this execution. */\n status: ReportStatus;\n /** ISO-8601 wall-clock timestamp when execution began. */\n startedAt: string;\n /** ISO-8601 wall-clock timestamp when execution finished. */\n endedAt: string;\n /** Monotonic duration in milliseconds — `performance.now()` delta. */\n duration: number;\n /** Rolled-up usage: own cost + sum of `children[].usage`. */\n usage: Usage;\n /**\n * Reports of every executable invoked by this node, in invocation\n * order. Empty for leaves (pure tools) and for executables that\n * didn't delegate work.\n */\n children: BaseReport[];\n /**\n * Retry history when middleware (or, for workflow steps, the engine\n * itself) retried this node before it either succeeded or gave up.\n * Absent when zero retries happened — keeps the common-case payload\n * lean. The surviving (final) attempt is NOT duplicated here; its\n * outcome is the report's own `status` / timing.\n */\n attempts?: AttemptEntry[];\n /**\n * Wire-format version of this report shape. Only present on root\n * report nodes — implies the same version for the whole tree.\n * Panoptic / archive consumers branch on this to parse old reports\n * with their original-shape rules.\n *\n * Always equals {@link REPORT_SCHEMA_VERSION} at write time.\n */\n reportSchemaVersion?: number;\n};\n"],"mappings":";;;;;;;;;;;;AAcA,MAAa,wBAAwB"}