@warlock.js/core 4.4.0 → 4.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (846) hide show
  1. package/CHANGELOG.md +45 -5
  2. package/README.md +47 -11
  3. package/esm/ai/src/agent/agent-input-builder.mjs +132 -0
  4. package/esm/ai/src/agent/agent-input-builder.mjs.map +1 -0
  5. package/esm/ai/src/agent/agent-log-event.mjs +101 -0
  6. package/esm/ai/src/agent/agent-log-event.mjs.map +1 -0
  7. package/esm/ai/src/agent/agent-stream.mjs +82 -0
  8. package/esm/ai/src/agent/agent-stream.mjs.map +1 -0
  9. package/esm/ai/src/agent/agent-to-stream-event.mjs +86 -0
  10. package/esm/ai/src/agent/agent-to-stream-event.mjs.map +1 -0
  11. package/esm/ai/src/agent/agent.mjs +1157 -0
  12. package/esm/ai/src/agent/agent.mjs.map +1 -0
  13. package/esm/ai/src/agent/index.mjs +5 -0
  14. package/esm/ai/src/agent/json-stream-guard.mjs +400 -0
  15. package/esm/ai/src/agent/json-stream-guard.mjs.map +1 -0
  16. package/esm/ai/src/agent/spawn-sub-agent.mjs +68 -0
  17. package/esm/ai/src/agent/spawn-sub-agent.mjs.map +1 -0
  18. package/esm/ai/src/ai.mjs +155 -0
  19. package/esm/ai/src/ai.mjs.map +1 -0
  20. package/esm/ai/src/batch/batch.mjs +198 -0
  21. package/esm/ai/src/batch/batch.mjs.map +1 -0
  22. package/esm/ai/src/batch/index.mjs +3 -0
  23. package/esm/ai/src/batch/run-batch-item.mjs +100 -0
  24. package/esm/ai/src/batch/run-batch-item.mjs.map +1 -0
  25. package/esm/ai/src/batch/run-with-concurrency.mjs +39 -0
  26. package/esm/ai/src/batch/run-with-concurrency.mjs.map +1 -0
  27. package/esm/ai/src/checkpoint/memory.mjs +0 -0
  28. package/esm/ai/src/checkpoint/memory.mjs.map +1 -0
  29. package/esm/ai/src/checkpoint/pg.mjs +265 -0
  30. package/esm/ai/src/checkpoint/pg.mjs.map +1 -0
  31. package/esm/ai/src/checkpoint/redis.mjs +200 -0
  32. package/esm/ai/src/checkpoint/redis.mjs.map +1 -0
  33. package/esm/ai/src/config.mjs +59 -0
  34. package/esm/ai/src/config.mjs.map +1 -0
  35. package/esm/ai/src/contracts/end.type.mjs +47 -0
  36. package/esm/ai/src/contracts/end.type.mjs.map +1 -0
  37. package/esm/ai/src/errors/agent-cancelled-error.mjs +43 -0
  38. package/esm/ai/src/errors/agent-cancelled-error.mjs.map +1 -0
  39. package/esm/ai/src/errors/agent-execution-error.mjs +35 -0
  40. package/esm/ai/src/errors/agent-execution-error.mjs.map +1 -0
  41. package/esm/ai/src/errors/agent-max-trips-error.mjs +41 -0
  42. package/esm/ai/src/errors/agent-max-trips-error.mjs.map +1 -0
  43. package/esm/ai/src/errors/ai-error.mjs +68 -0
  44. package/esm/ai/src/errors/ai-error.mjs.map +1 -0
  45. package/esm/ai/src/errors/budget-exceeded-error.mjs +31 -0
  46. package/esm/ai/src/errors/budget-exceeded-error.mjs.map +1 -0
  47. package/esm/ai/src/errors/content-filter-error.mjs +28 -0
  48. package/esm/ai/src/errors/content-filter-error.mjs.map +1 -0
  49. package/esm/ai/src/errors/context-length-exceeded-error.mjs +31 -0
  50. package/esm/ai/src/errors/context-length-exceeded-error.mjs.map +1 -0
  51. package/esm/ai/src/errors/guardrail-violation-error.mjs +41 -0
  52. package/esm/ai/src/errors/guardrail-violation-error.mjs.map +1 -0
  53. package/esm/ai/src/errors/index.mjs +37 -0
  54. package/esm/ai/src/errors/invalid-request-error.mjs +31 -0
  55. package/esm/ai/src/errors/invalid-request-error.mjs.map +1 -0
  56. package/esm/ai/src/errors/max-iterations-error.mjs +32 -0
  57. package/esm/ai/src/errors/max-iterations-error.mjs.map +1 -0
  58. package/esm/ai/src/errors/max-steps-exceeded-error.mjs +21 -0
  59. package/esm/ai/src/errors/max-steps-exceeded-error.mjs.map +1 -0
  60. package/esm/ai/src/errors/orchestrator-cancelled-error.mjs +31 -0
  61. package/esm/ai/src/errors/orchestrator-cancelled-error.mjs.map +1 -0
  62. package/esm/ai/src/errors/orchestrator-config-error.mjs +30 -0
  63. package/esm/ai/src/errors/orchestrator-config-error.mjs.map +1 -0
  64. package/esm/ai/src/errors/orchestrator-drift-error.mjs +37 -0
  65. package/esm/ai/src/errors/orchestrator-drift-error.mjs.map +1 -0
  66. package/esm/ai/src/errors/orchestrator-failed-error.mjs +36 -0
  67. package/esm/ai/src/errors/orchestrator-failed-error.mjs.map +1 -0
  68. package/esm/ai/src/errors/outbound-policy-error.mjs +32 -0
  69. package/esm/ai/src/errors/outbound-policy-error.mjs.map +1 -0
  70. package/esm/ai/src/errors/planner-cancelled-error.mjs +29 -0
  71. package/esm/ai/src/errors/planner-cancelled-error.mjs.map +1 -0
  72. package/esm/ai/src/errors/planner-failed-error.mjs +37 -0
  73. package/esm/ai/src/errors/planner-failed-error.mjs.map +1 -0
  74. package/esm/ai/src/errors/planner-plan-invalid-error.mjs +25 -0
  75. package/esm/ai/src/errors/planner-plan-invalid-error.mjs.map +1 -0
  76. package/esm/ai/src/errors/provider-auth-error.mjs +26 -0
  77. package/esm/ai/src/errors/provider-auth-error.mjs.map +1 -0
  78. package/esm/ai/src/errors/provider-error.mjs +42 -0
  79. package/esm/ai/src/errors/provider-error.mjs.map +1 -0
  80. package/esm/ai/src/errors/provider-rate-limit-error.mjs +31 -0
  81. package/esm/ai/src/errors/provider-rate-limit-error.mjs.map +1 -0
  82. package/esm/ai/src/errors/provider-timeout-error.mjs +26 -0
  83. package/esm/ai/src/errors/provider-timeout-error.mjs.map +1 -0
  84. package/esm/ai/src/errors/quota-exceeded-error.mjs +40 -0
  85. package/esm/ai/src/errors/quota-exceeded-error.mjs.map +1 -0
  86. package/esm/ai/src/errors/routing-error.mjs +23 -0
  87. package/esm/ai/src/errors/routing-error.mjs.map +1 -0
  88. package/esm/ai/src/errors/schema-validation-error.mjs +37 -0
  89. package/esm/ai/src/errors/schema-validation-error.mjs.map +1 -0
  90. package/esm/ai/src/errors/step-failed-error.mjs +19 -0
  91. package/esm/ai/src/errors/step-failed-error.mjs.map +1 -0
  92. package/esm/ai/src/errors/supervisor-cancelled-error.mjs +29 -0
  93. package/esm/ai/src/errors/supervisor-cancelled-error.mjs.map +1 -0
  94. package/esm/ai/src/errors/supervisor-drift-error.mjs +30 -0
  95. package/esm/ai/src/errors/supervisor-drift-error.mjs.map +1 -0
  96. package/esm/ai/src/errors/supervisor-failed-error.mjs +43 -0
  97. package/esm/ai/src/errors/supervisor-failed-error.mjs.map +1 -0
  98. package/esm/ai/src/errors/supervisor-routing-error.mjs +39 -0
  99. package/esm/ai/src/errors/supervisor-routing-error.mjs.map +1 -0
  100. package/esm/ai/src/errors/tool-execution-error.mjs +32 -0
  101. package/esm/ai/src/errors/tool-execution-error.mjs.map +1 -0
  102. package/esm/ai/src/errors/workflow-cancelled-error.mjs +23 -0
  103. package/esm/ai/src/errors/workflow-cancelled-error.mjs.map +1 -0
  104. package/esm/ai/src/errors/workflow-drift-error.mjs +24 -0
  105. package/esm/ai/src/errors/workflow-drift-error.mjs.map +1 -0
  106. package/esm/ai/src/errors/workflow-error.mjs +18 -0
  107. package/esm/ai/src/errors/workflow-error.mjs.map +1 -0
  108. package/esm/ai/src/eval/dataset.mjs +112 -0
  109. package/esm/ai/src/eval/dataset.mjs.map +1 -0
  110. package/esm/ai/src/eval/eval-runner.mjs +135 -0
  111. package/esm/ai/src/eval/eval-runner.mjs.map +1 -0
  112. package/esm/ai/src/eval/index.mjs +48 -0
  113. package/esm/ai/src/eval/index.mjs.map +1 -0
  114. package/esm/ai/src/eval/judge-scorer.mjs +87 -0
  115. package/esm/ai/src/eval/judge-scorer.mjs.map +1 -0
  116. package/esm/ai/src/eval/regression.mjs +51 -0
  117. package/esm/ai/src/eval/regression.mjs.map +1 -0
  118. package/esm/ai/src/eval/report-json.mjs +33 -0
  119. package/esm/ai/src/eval/report-json.mjs.map +1 -0
  120. package/esm/ai/src/eval/report-junit.mjs +60 -0
  121. package/esm/ai/src/eval/report-junit.mjs.map +1 -0
  122. package/esm/ai/src/eval/scorers.mjs +101 -0
  123. package/esm/ai/src/eval/scorers.mjs.map +1 -0
  124. package/esm/ai/src/guard/detectors/index.mjs +6 -0
  125. package/esm/ai/src/guard/detectors/injection.mjs +254 -0
  126. package/esm/ai/src/guard/detectors/injection.mjs.map +1 -0
  127. package/esm/ai/src/guard/detectors/moderation.mjs +134 -0
  128. package/esm/ai/src/guard/detectors/moderation.mjs.map +1 -0
  129. package/esm/ai/src/guard/detectors/pii.mjs +199 -0
  130. package/esm/ai/src/guard/detectors/pii.mjs.map +1 -0
  131. package/esm/ai/src/guard/detectors/topic.mjs +99 -0
  132. package/esm/ai/src/guard/detectors/topic.mjs.map +1 -0
  133. package/esm/ai/src/guard/errors.mjs +18 -0
  134. package/esm/ai/src/guard/errors.mjs.map +1 -0
  135. package/esm/ai/src/guard/guard.mjs +209 -0
  136. package/esm/ai/src/guard/guard.mjs.map +1 -0
  137. package/esm/ai/src/guard/guardrail.mjs +22 -0
  138. package/esm/ai/src/guard/guardrail.mjs.map +1 -0
  139. package/esm/ai/src/human/errors.mjs +60 -0
  140. package/esm/ai/src/human/errors.mjs.map +1 -0
  141. package/esm/ai/src/human/human-approval.mjs +170 -0
  142. package/esm/ai/src/human/human-approval.mjs.map +1 -0
  143. package/esm/ai/src/human/policy.mjs +67 -0
  144. package/esm/ai/src/human/policy.mjs.map +1 -0
  145. package/esm/ai/src/human/register.mjs +37 -0
  146. package/esm/ai/src/human/register.mjs.map +1 -0
  147. package/esm/ai/src/human/resume-seed.mjs +53 -0
  148. package/esm/ai/src/human/resume-seed.mjs.map +1 -0
  149. package/esm/ai/src/human/resume.mjs +121 -0
  150. package/esm/ai/src/human/resume.mjs.map +1 -0
  151. package/esm/ai/src/human/stores/index.mjs +5 -0
  152. package/esm/ai/src/human/stores/memory.mjs +91 -0
  153. package/esm/ai/src/human/stores/memory.mjs.map +1 -0
  154. package/esm/ai/src/human/stores/pg.mjs +220 -0
  155. package/esm/ai/src/human/stores/pg.mjs.map +1 -0
  156. package/esm/ai/src/human/stores/redis.mjs +201 -0
  157. package/esm/ai/src/human/stores/redis.mjs.map +1 -0
  158. package/esm/ai/src/index.mjs +174 -0
  159. package/esm/ai/src/memory/derive-id.mjs +24 -0
  160. package/esm/ai/src/memory/derive-id.mjs.map +1 -0
  161. package/esm/ai/src/memory/episodic-memory.mjs +106 -0
  162. package/esm/ai/src/memory/episodic-memory.mjs.map +1 -0
  163. package/esm/ai/src/memory/memory.mjs +166 -0
  164. package/esm/ai/src/memory/memory.mjs.map +1 -0
  165. package/esm/ai/src/memory/procedural-memory.mjs +103 -0
  166. package/esm/ai/src/memory/procedural-memory.mjs.map +1 -0
  167. package/esm/ai/src/memory/semantic-memory.mjs +80 -0
  168. package/esm/ai/src/memory/semantic-memory.mjs.map +1 -0
  169. package/esm/ai/src/memory/working-memory.mjs +62 -0
  170. package/esm/ai/src/memory/working-memory.mjs.map +1 -0
  171. package/esm/ai/src/middleware/builtins/budget.mjs +219 -0
  172. package/esm/ai/src/middleware/builtins/budget.mjs.map +1 -0
  173. package/esm/ai/src/middleware/builtins/guardrail.mjs +76 -0
  174. package/esm/ai/src/middleware/builtins/guardrail.mjs.map +1 -0
  175. package/esm/ai/src/middleware/builtins/semantic-cache.mjs +149 -0
  176. package/esm/ai/src/middleware/builtins/semantic-cache.mjs.map +1 -0
  177. package/esm/ai/src/middleware/helpers/compose.mjs +52 -0
  178. package/esm/ai/src/middleware/helpers/compose.mjs.map +1 -0
  179. package/esm/ai/src/middleware/helpers/for-tool.mjs +80 -0
  180. package/esm/ai/src/middleware/helpers/for-tool.mjs.map +1 -0
  181. package/esm/ai/src/middleware/index.mjs +10 -0
  182. package/esm/ai/src/middleware/pipeline.mjs +100 -0
  183. package/esm/ai/src/middleware/pipeline.mjs.map +1 -0
  184. package/esm/ai/src/middleware/utils/extract-user-text.mjs +47 -0
  185. package/esm/ai/src/middleware/utils/extract-user-text.mjs.map +1 -0
  186. package/esm/ai/src/middleware/utils/namespaced-state.mjs +60 -0
  187. package/esm/ai/src/middleware/utils/namespaced-state.mjs.map +1 -0
  188. package/esm/ai/src/mock/index.mjs +4 -0
  189. package/esm/ai/src/mock/mock-agent.mjs +3 -0
  190. package/esm/ai/src/mock/mock-router.mjs +58 -0
  191. package/esm/ai/src/mock/mock-router.mjs.map +1 -0
  192. package/esm/ai/src/model/fallback-model.mjs +218 -0
  193. package/esm/ai/src/model/fallback-model.mjs.map +1 -0
  194. package/esm/ai/src/model/index.mjs +3 -0
  195. package/esm/ai/src/object-stream/index.mjs +4 -0
  196. package/esm/ai/src/object-stream/parse-partial-json.mjs +78 -0
  197. package/esm/ai/src/object-stream/parse-partial-json.mjs.map +1 -0
  198. package/esm/ai/src/object-stream/stream-object.mjs +97 -0
  199. package/esm/ai/src/object-stream/stream-object.mjs.map +1 -0
  200. package/esm/ai/src/observe/index.mjs +4 -0
  201. package/esm/ai/src/observe/observer-registry.mjs +35 -0
  202. package/esm/ai/src/observe/observer-registry.mjs.map +1 -0
  203. package/esm/ai/src/observe/resolve-observers.mjs +73 -0
  204. package/esm/ai/src/observe/resolve-observers.mjs.map +1 -0
  205. package/esm/ai/src/orchestrator/as-tool.mjs +98 -0
  206. package/esm/ai/src/orchestrator/as-tool.mjs.map +1 -0
  207. package/esm/ai/src/orchestrator/checkpoint.mjs +75 -0
  208. package/esm/ai/src/orchestrator/checkpoint.mjs.map +1 -0
  209. package/esm/ai/src/orchestrator/commands.mjs +34 -0
  210. package/esm/ai/src/orchestrator/commands.mjs.map +1 -0
  211. package/esm/ai/src/orchestrator/compaction.mjs +206 -0
  212. package/esm/ai/src/orchestrator/compaction.mjs.map +1 -0
  213. package/esm/ai/src/orchestrator/dispatch.mjs +171 -0
  214. package/esm/ai/src/orchestrator/dispatch.mjs.map +1 -0
  215. package/esm/ai/src/orchestrator/emitter.mjs +85 -0
  216. package/esm/ai/src/orchestrator/emitter.mjs.map +1 -0
  217. package/esm/ai/src/orchestrator/execution.mjs +395 -0
  218. package/esm/ai/src/orchestrator/execution.mjs.map +1 -0
  219. package/esm/ai/src/orchestrator/index.mjs +11 -0
  220. package/esm/ai/src/orchestrator/load.mjs +49 -0
  221. package/esm/ai/src/orchestrator/load.mjs.map +1 -0
  222. package/esm/ai/src/orchestrator/lock.mjs +75 -0
  223. package/esm/ai/src/orchestrator/lock.mjs.map +1 -0
  224. package/esm/ai/src/orchestrator/memory.mjs +141 -0
  225. package/esm/ai/src/orchestrator/memory.mjs.map +1 -0
  226. package/esm/ai/src/orchestrator/orchestrator-stream.mjs +98 -0
  227. package/esm/ai/src/orchestrator/orchestrator-stream.mjs.map +1 -0
  228. package/esm/ai/src/orchestrator/orchestrator.mjs +206 -0
  229. package/esm/ai/src/orchestrator/orchestrator.mjs.map +1 -0
  230. package/esm/ai/src/orchestrator/resume.mjs +74 -0
  231. package/esm/ai/src/orchestrator/resume.mjs.map +1 -0
  232. package/esm/ai/src/orchestrator/session-lock.mjs +83 -0
  233. package/esm/ai/src/orchestrator/session-lock.mjs.map +1 -0
  234. package/esm/ai/src/orchestrator/signature.mjs +120 -0
  235. package/esm/ai/src/orchestrator/signature.mjs.map +1 -0
  236. package/esm/ai/src/orchestrator/window.mjs +56 -0
  237. package/esm/ai/src/orchestrator/window.mjs.map +1 -0
  238. package/esm/ai/src/planner/dag-scheduler.mjs +97 -0
  239. package/esm/ai/src/planner/dag-scheduler.mjs.map +1 -0
  240. package/esm/ai/src/planner/index.mjs +6 -0
  241. package/esm/ai/src/planner/plan-prompt.mjs +31 -0
  242. package/esm/ai/src/planner/plan-prompt.mjs.map +1 -0
  243. package/esm/ai/src/planner/plan-schema.mjs +120 -0
  244. package/esm/ai/src/planner/plan-schema.mjs.map +1 -0
  245. package/esm/ai/src/planner/planner-run.mjs +614 -0
  246. package/esm/ai/src/planner/planner-run.mjs.map +1 -0
  247. package/esm/ai/src/planner/planner.mjs +120 -0
  248. package/esm/ai/src/planner/planner.mjs.map +1 -0
  249. package/esm/ai/src/planner/signature.mjs +27 -0
  250. package/esm/ai/src/planner/signature.mjs.map +1 -0
  251. package/esm/ai/src/prompt/errors.mjs +73 -0
  252. package/esm/ai/src/prompt/errors.mjs.map +1 -0
  253. package/esm/ai/src/prompt/index.mjs +4 -0
  254. package/esm/ai/src/prompt/prompt-langfuse-sync.mjs +104 -0
  255. package/esm/ai/src/prompt/prompt-langfuse-sync.mjs.map +1 -0
  256. package/esm/ai/src/prompt/prompt-validate.mjs +170 -0
  257. package/esm/ai/src/prompt/prompt-validate.mjs.map +1 -0
  258. package/esm/ai/src/prompt/prompt.mjs +218 -0
  259. package/esm/ai/src/prompt/prompt.mjs.map +1 -0
  260. package/esm/ai/src/prompts/index.mjs +3 -0
  261. package/esm/ai/src/prompts/prompts-manager.mjs +410 -0
  262. package/esm/ai/src/prompts/prompts-manager.mjs.map +1 -0
  263. package/esm/ai/src/prompts/prompts-validate.mjs +200 -0
  264. package/esm/ai/src/prompts/prompts-validate.mjs.map +1 -0
  265. package/esm/ai/src/rag/as-tool.mjs +48 -0
  266. package/esm/ai/src/rag/as-tool.mjs.map +1 -0
  267. package/esm/ai/src/rag/chunk/chunk.mjs +44 -0
  268. package/esm/ai/src/rag/chunk/chunk.mjs.map +1 -0
  269. package/esm/ai/src/rag/chunk/fixed.mjs +32 -0
  270. package/esm/ai/src/rag/chunk/fixed.mjs.map +1 -0
  271. package/esm/ai/src/rag/chunk/markdown.mjs +75 -0
  272. package/esm/ai/src/rag/chunk/markdown.mjs.map +1 -0
  273. package/esm/ai/src/rag/chunk/recursive.mjs +132 -0
  274. package/esm/ai/src/rag/chunk/recursive.mjs.map +1 -0
  275. package/esm/ai/src/rag/chunk/sentence.mjs +73 -0
  276. package/esm/ai/src/rag/chunk/sentence.mjs.map +1 -0
  277. package/esm/ai/src/rag/index.mjs +7 -0
  278. package/esm/ai/src/rag/rag.mjs +126 -0
  279. package/esm/ai/src/rag/rag.mjs.map +1 -0
  280. package/esm/ai/src/rag/rerank/keyword-reranker.mjs +58 -0
  281. package/esm/ai/src/rag/rerank/keyword-reranker.mjs.map +1 -0
  282. package/esm/ai/src/rag/rerank/llm-reranker.mjs +85 -0
  283. package/esm/ai/src/rag/rerank/llm-reranker.mjs.map +1 -0
  284. package/esm/ai/src/rag/retrieve.mjs +68 -0
  285. package/esm/ai/src/rag/retrieve.mjs.map +1 -0
  286. package/esm/ai/src/rag/store/cache-vector-store.mjs +48 -0
  287. package/esm/ai/src/rag/store/cache-vector-store.mjs.map +1 -0
  288. package/esm/ai/src/security/index.mjs +5 -0
  289. package/esm/ai/src/security/outbound-policy.mjs +187 -0
  290. package/esm/ai/src/security/outbound-policy.mjs.map +1 -0
  291. package/esm/ai/src/security/private-ip.mjs +48 -0
  292. package/esm/ai/src/security/private-ip.mjs.map +1 -0
  293. package/esm/ai/src/security/redact.mjs +60 -0
  294. package/esm/ai/src/security/redact.mjs.map +1 -0
  295. package/esm/ai/src/serve/serve.mjs +90 -0
  296. package/esm/ai/src/serve/serve.mjs.map +1 -0
  297. package/esm/ai/src/serve/sse.mjs +25 -0
  298. package/esm/ai/src/serve/sse.mjs.map +1 -0
  299. package/esm/ai/src/serve/stream-to-sse.mjs +37 -0
  300. package/esm/ai/src/serve/stream-to-sse.mjs.map +1 -0
  301. package/esm/ai/src/skills/catalog.mjs +140 -0
  302. package/esm/ai/src/skills/catalog.mjs.map +1 -0
  303. package/esm/ai/src/skills/index.mjs +11 -0
  304. package/esm/ai/src/skills/load-skill-tool.mjs +65 -0
  305. package/esm/ai/src/skills/load-skill-tool.mjs.map +1 -0
  306. package/esm/ai/src/skills/save-skill-tool.mjs +65 -0
  307. package/esm/ai/src/skills/save-skill-tool.mjs.map +1 -0
  308. package/esm/ai/src/skills/skills.mjs +109 -0
  309. package/esm/ai/src/skills/skills.mjs.map +1 -0
  310. package/esm/ai/src/skills/sources/directory-source.mjs +108 -0
  311. package/esm/ai/src/skills/sources/directory-source.mjs.map +1 -0
  312. package/esm/ai/src/skills/sources/index.mjs +27 -0
  313. package/esm/ai/src/skills/sources/index.mjs.map +1 -0
  314. package/esm/ai/src/skills/sources/parse-frontmatter.mjs +46 -0
  315. package/esm/ai/src/skills/sources/parse-frontmatter.mjs.map +1 -0
  316. package/esm/ai/src/skills/sources/store-source.mjs +15 -0
  317. package/esm/ai/src/skills/sources/store-source.mjs.map +1 -0
  318. package/esm/ai/src/skills/sources/url-source.mjs +117 -0
  319. package/esm/ai/src/skills/sources/url-source.mjs.map +1 -0
  320. package/esm/ai/src/snapshot/memory.mjs +81 -0
  321. package/esm/ai/src/snapshot/memory.mjs.map +1 -0
  322. package/esm/ai/src/snapshot/pg.mjs +146 -0
  323. package/esm/ai/src/snapshot/pg.mjs.map +1 -0
  324. package/esm/ai/src/snapshot/redis.mjs +101 -0
  325. package/esm/ai/src/snapshot/redis.mjs.map +1 -0
  326. package/esm/ai/src/supervisor/as-tool.mjs +74 -0
  327. package/esm/ai/src/supervisor/as-tool.mjs.map +1 -0
  328. package/esm/ai/src/supervisor/cancellation.mjs +22 -0
  329. package/esm/ai/src/supervisor/cancellation.mjs.map +1 -0
  330. package/esm/ai/src/supervisor/decide.mjs +272 -0
  331. package/esm/ai/src/supervisor/decide.mjs.map +1 -0
  332. package/esm/ai/src/supervisor/emitter.mjs +47 -0
  333. package/esm/ai/src/supervisor/emitter.mjs.map +1 -0
  334. package/esm/ai/src/supervisor/entries.mjs +206 -0
  335. package/esm/ai/src/supervisor/entries.mjs.map +1 -0
  336. package/esm/ai/src/supervisor/execution.mjs +1921 -0
  337. package/esm/ai/src/supervisor/execution.mjs.map +1 -0
  338. package/esm/ai/src/supervisor/fan-out.mjs +65 -0
  339. package/esm/ai/src/supervisor/fan-out.mjs.map +1 -0
  340. package/esm/ai/src/supervisor/index.mjs +14 -0
  341. package/esm/ai/src/supervisor/router-factory.mjs +141 -0
  342. package/esm/ai/src/supervisor/router-factory.mjs.map +1 -0
  343. package/esm/ai/src/supervisor/router-prompt.mjs +52 -0
  344. package/esm/ai/src/supervisor/router-prompt.mjs.map +1 -0
  345. package/esm/ai/src/supervisor/signature.mjs +89 -0
  346. package/esm/ai/src/supervisor/signature.mjs.map +1 -0
  347. package/esm/ai/src/supervisor/snapshot.mjs +69 -0
  348. package/esm/ai/src/supervisor/snapshot.mjs.map +1 -0
  349. package/esm/ai/src/supervisor/supervisor-stream.mjs +89 -0
  350. package/esm/ai/src/supervisor/supervisor-stream.mjs.map +1 -0
  351. package/esm/ai/src/supervisor/supervisor.mjs +144 -0
  352. package/esm/ai/src/supervisor/supervisor.mjs.map +1 -0
  353. package/esm/ai/src/system-prompt/index.mjs +6 -0
  354. package/esm/ai/src/system-prompt/instruction.mjs +57 -0
  355. package/esm/ai/src/system-prompt/instruction.mjs.map +1 -0
  356. package/esm/ai/src/system-prompt/persona.mjs +57 -0
  357. package/esm/ai/src/system-prompt/persona.mjs.map +1 -0
  358. package/esm/ai/src/system-prompt/render-placeholders.mjs +58 -0
  359. package/esm/ai/src/system-prompt/render-placeholders.mjs.map +1 -0
  360. package/esm/ai/src/system-prompt/system-prompt.mjs +267 -0
  361. package/esm/ai/src/system-prompt/system-prompt.mjs.map +1 -0
  362. package/esm/ai/src/team/gates.mjs +48 -0
  363. package/esm/ai/src/team/gates.mjs.map +1 -0
  364. package/esm/ai/src/team/index.mjs +3 -0
  365. package/esm/ai/src/team/team.mjs +94 -0
  366. package/esm/ai/src/team/team.mjs.map +1 -0
  367. package/esm/ai/src/tool/executable-as-tool.mjs +81 -0
  368. package/esm/ai/src/tool/executable-as-tool.mjs.map +1 -0
  369. package/esm/ai/src/tool/index.mjs +4 -0
  370. package/esm/ai/src/tool/tool.mjs +185 -0
  371. package/esm/ai/src/tool/tool.mjs.map +1 -0
  372. package/esm/ai/src/utils/compute-cost.mjs +112 -0
  373. package/esm/ai/src/utils/compute-cost.mjs.map +1 -0
  374. package/esm/ai/src/utils/extract-json-lenient.mjs +97 -0
  375. package/esm/ai/src/utils/extract-json-lenient.mjs.map +1 -0
  376. package/esm/ai/src/utils/extract-json-payload.mjs +39 -0
  377. package/esm/ai/src/utils/extract-json-payload.mjs.map +1 -0
  378. package/esm/ai/src/utils/generate-run-id.mjs +23 -0
  379. package/esm/ai/src/utils/generate-run-id.mjs.map +1 -0
  380. package/esm/ai/src/utils/index.mjs +12 -0
  381. package/esm/ai/src/utils/json-schema.mjs +89 -0
  382. package/esm/ai/src/utils/json-schema.mjs.map +1 -0
  383. package/esm/ai/src/utils/prepare-attachment-part.mjs +232 -0
  384. package/esm/ai/src/utils/prepare-attachment-part.mjs.map +1 -0
  385. package/esm/ai/src/utils/resolve-attachment.mjs +74 -0
  386. package/esm/ai/src/utils/resolve-attachment.mjs.map +1 -0
  387. package/esm/ai/src/utils/run-context.mjs +89 -0
  388. package/esm/ai/src/utils/run-context.mjs.map +1 -0
  389. package/esm/ai/src/utils/safe-json-parse.mjs +22 -0
  390. package/esm/ai/src/utils/safe-json-parse.mjs.map +1 -0
  391. package/esm/ai/src/utils/stamp-report-lineage.mjs +45 -0
  392. package/esm/ai/src/utils/stamp-report-lineage.mjs.map +1 -0
  393. package/esm/ai/src/vcr/cassette-io.mjs +57 -0
  394. package/esm/ai/src/vcr/cassette-io.mjs.map +1 -0
  395. package/esm/ai/src/vcr/errors.mjs +37 -0
  396. package/esm/ai/src/vcr/errors.mjs.map +1 -0
  397. package/esm/ai/src/vcr/hash-request.mjs +118 -0
  398. package/esm/ai/src/vcr/hash-request.mjs.map +1 -0
  399. package/esm/ai/src/vcr/index.mjs +5 -0
  400. package/esm/ai/src/vcr/vcr.mjs +248 -0
  401. package/esm/ai/src/vcr/vcr.mjs.map +1 -0
  402. package/esm/ai/src/workflow/as-tool.mjs +49 -0
  403. package/esm/ai/src/workflow/as-tool.mjs.map +1 -0
  404. package/esm/ai/src/workflow/cancellation.mjs +44 -0
  405. package/esm/ai/src/workflow/cancellation.mjs.map +1 -0
  406. package/esm/ai/src/workflow/emitter.mjs +40 -0
  407. package/esm/ai/src/workflow/emitter.mjs.map +1 -0
  408. package/esm/ai/src/workflow/engine.mjs +363 -0
  409. package/esm/ai/src/workflow/engine.mjs.map +1 -0
  410. package/esm/ai/src/workflow/index.mjs +5 -0
  411. package/esm/ai/src/workflow/retry.mjs +32 -0
  412. package/esm/ai/src/workflow/retry.mjs.map +1 -0
  413. package/esm/ai/src/workflow/router.mjs +56 -0
  414. package/esm/ai/src/workflow/router.mjs.map +1 -0
  415. package/esm/ai/src/workflow/run-scoped-emitter.mjs +32 -0
  416. package/esm/ai/src/workflow/run-scoped-emitter.mjs.map +1 -0
  417. package/esm/ai/src/workflow/signature.mjs +34 -0
  418. package/esm/ai/src/workflow/signature.mjs.map +1 -0
  419. package/esm/ai/src/workflow/snapshot.mjs +77 -0
  420. package/esm/ai/src/workflow/snapshot.mjs.map +1 -0
  421. package/esm/ai/src/workflow/state.mjs +37 -0
  422. package/esm/ai/src/workflow/state.mjs.map +1 -0
  423. package/esm/ai/src/workflow/step-runner.mjs +370 -0
  424. package/esm/ai/src/workflow/step-runner.mjs.map +1 -0
  425. package/esm/ai/src/workflow/step.mjs +37 -0
  426. package/esm/ai/src/workflow/step.mjs.map +1 -0
  427. package/esm/ai/src/workflow/workflow.mjs +122 -0
  428. package/esm/ai/src/workflow/workflow.mjs.map +1 -0
  429. package/esm/ai-openai/src/embedder.mjs +4 -0
  430. package/esm/ai-openai/src/index.mjs +4 -0
  431. package/esm/ai-openai/src/model.mjs +5 -0
  432. package/esm/ai-openai/src/sdk.mjs +6 -0
  433. package/esm/ai-openai/src/utils/index.mjs +4 -0
  434. package/esm/ai-openai/src/utils/to-openai-tools.mjs +3 -0
  435. package/esm/ai-openai/src/utils/wrap-openai-error.mjs +4 -0
  436. package/esm/cli/commands/dev-server.command.mjs +1 -1
  437. package/esm/cli/commands/dev-server.command.mjs.map +1 -1
  438. package/esm/cli/commands/generate/templates/stubs.mjs +3 -4
  439. package/esm/cli/commands/generate/templates/stubs.mjs.map +1 -1
  440. package/esm/connectors/ai-connector.d.mts +43 -0
  441. package/esm/connectors/ai-connector.d.mts.map +1 -0
  442. package/esm/connectors/ai-connector.mjs +56 -0
  443. package/esm/connectors/ai-connector.mjs.map +1 -0
  444. package/esm/connectors/cache-connector.d.mts +5 -0
  445. package/esm/connectors/cache-connector.d.mts.map +1 -1
  446. package/esm/connectors/cache-connector.mjs +7 -0
  447. package/esm/connectors/cache-connector.mjs.map +1 -1
  448. package/esm/connectors/connectors-manager.d.mts +6 -2
  449. package/esm/connectors/connectors-manager.d.mts.map +1 -1
  450. package/esm/connectors/connectors-manager.mjs +8 -2
  451. package/esm/connectors/connectors-manager.mjs.map +1 -1
  452. package/esm/connectors/http-connector.mjs.map +1 -1
  453. package/esm/connectors/index.d.mts +1 -0
  454. package/esm/connectors/index.mjs +1 -0
  455. package/esm/connectors/socket-connector.d.mts +16 -1
  456. package/esm/connectors/socket-connector.d.mts.map +1 -1
  457. package/esm/connectors/socket-connector.mjs +28 -5
  458. package/esm/connectors/socket-connector.mjs.map +1 -1
  459. package/esm/connectors/storage.connector.d.mts +7 -0
  460. package/esm/connectors/storage.connector.d.mts.map +1 -1
  461. package/esm/connectors/storage.connector.mjs +7 -0
  462. package/esm/connectors/storage.connector.mjs.map +1 -1
  463. package/esm/connectors/types.d.mts +3 -2
  464. package/esm/connectors/types.d.mts.map +1 -1
  465. package/esm/connectors/types.mjs +1 -0
  466. package/esm/connectors/types.mjs.map +1 -1
  467. package/esm/dev-server/development-server.mjs +2 -14
  468. package/esm/dev-server/development-server.mjs.map +1 -1
  469. package/esm/dev-server/file-event-handler.mjs +15 -3
  470. package/esm/dev-server/file-event-handler.mjs.map +1 -1
  471. package/esm/generations/add-command.action.mjs +61 -12
  472. package/esm/generations/add-command.action.mjs.map +1 -1
  473. package/esm/generations/stubs.mjs +31 -1
  474. package/esm/generations/stubs.mjs.map +1 -1
  475. package/esm/http/middleware/cache-response-middleware.d.mts +1 -1
  476. package/esm/http/middleware/cache-response-middleware.d.mts.map +1 -1
  477. package/esm/http/middleware/cache-response-middleware.mjs +15 -6
  478. package/esm/http/middleware/cache-response-middleware.mjs.map +1 -1
  479. package/esm/http/middleware/concurrency-limit.middleware.mjs +2 -0
  480. package/esm/http/middleware/concurrency-limit.middleware.mjs.map +1 -1
  481. package/esm/http/middleware/idempotency.middleware.d.mts.map +1 -1
  482. package/esm/http/middleware/idempotency.middleware.mjs +4 -1
  483. package/esm/http/middleware/idempotency.middleware.mjs.map +1 -1
  484. package/esm/http/middleware/maintenance.middleware.mjs +2 -1
  485. package/esm/http/middleware/maintenance.middleware.mjs.map +1 -1
  486. package/esm/http/request.d.mts +9 -2
  487. package/esm/http/request.d.mts.map +1 -1
  488. package/esm/http/request.mjs +15 -3
  489. package/esm/http/request.mjs.map +1 -1
  490. package/esm/http/response.d.mts +12 -0
  491. package/esm/http/response.d.mts.map +1 -1
  492. package/esm/http/response.mjs +19 -2
  493. package/esm/http/response.mjs.map +1 -1
  494. package/esm/http/server.d.mts.map +1 -1
  495. package/esm/http/server.mjs +1 -1
  496. package/esm/http/server.mjs.map +1 -1
  497. package/esm/index.d.mts +6 -2
  498. package/esm/index.mjs +5 -1
  499. package/esm/node_modules/langfuse/lib/index.mjs +1827 -0
  500. package/esm/node_modules/langfuse/lib/index.mjs.map +1 -0
  501. package/esm/node_modules/langfuse-core/lib/index.mjs +1770 -0
  502. package/esm/node_modules/langfuse-core/lib/index.mjs.map +1 -0
  503. package/esm/node_modules/mustache/mustache.mjs +587 -0
  504. package/esm/node_modules/mustache/mustache.mjs.map +1 -0
  505. package/esm/node_modules/openai/_vendor/partial-json-parser/parser.mjs +180 -0
  506. package/esm/node_modules/openai/_vendor/partial-json-parser/parser.mjs.map +1 -0
  507. package/esm/node_modules/openai/auth/workload-identity-auth.mjs +80 -0
  508. package/esm/node_modules/openai/auth/workload-identity-auth.mjs.map +1 -0
  509. package/esm/node_modules/openai/azure.mjs +82 -0
  510. package/esm/node_modules/openai/azure.mjs.map +1 -0
  511. package/esm/node_modules/openai/client.mjs +638 -0
  512. package/esm/node_modules/openai/client.mjs.map +1 -0
  513. package/esm/node_modules/openai/core/api-promise.mjs +75 -0
  514. package/esm/node_modules/openai/core/api-promise.mjs.map +1 -0
  515. package/esm/node_modules/openai/core/error.mjs +110 -0
  516. package/esm/node_modules/openai/core/error.mjs.map +1 -0
  517. package/esm/node_modules/openai/core/pagination.mjs +160 -0
  518. package/esm/node_modules/openai/core/pagination.mjs.map +1 -0
  519. package/esm/node_modules/openai/core/resource.mjs +10 -0
  520. package/esm/node_modules/openai/core/resource.mjs.map +1 -0
  521. package/esm/node_modules/openai/core/streaming.mjs +238 -0
  522. package/esm/node_modules/openai/core/streaming.mjs.map +1 -0
  523. package/esm/node_modules/openai/index.mjs +8 -0
  524. package/esm/node_modules/openai/internal/decoders/line.mjs +91 -0
  525. package/esm/node_modules/openai/internal/decoders/line.mjs.map +1 -0
  526. package/esm/node_modules/openai/internal/detect-platform.mjs +123 -0
  527. package/esm/node_modules/openai/internal/detect-platform.mjs.map +1 -0
  528. package/esm/node_modules/openai/internal/errors.mjs +26 -0
  529. package/esm/node_modules/openai/internal/errors.mjs.map +1 -0
  530. package/esm/node_modules/openai/internal/headers.mjs +65 -0
  531. package/esm/node_modules/openai/internal/headers.mjs.map +1 -0
  532. package/esm/node_modules/openai/internal/parse.mjs +41 -0
  533. package/esm/node_modules/openai/internal/parse.mjs.map +1 -0
  534. package/esm/node_modules/openai/internal/qs/formats.mjs +12 -0
  535. package/esm/node_modules/openai/internal/qs/formats.mjs.map +1 -0
  536. package/esm/node_modules/openai/internal/qs/stringify.mjs +179 -0
  537. package/esm/node_modules/openai/internal/qs/stringify.mjs.map +1 -0
  538. package/esm/node_modules/openai/internal/qs/utils.mjs +65 -0
  539. package/esm/node_modules/openai/internal/qs/utils.mjs.map +1 -0
  540. package/esm/node_modules/openai/internal/request-options.mjs +11 -0
  541. package/esm/node_modules/openai/internal/request-options.mjs.map +1 -0
  542. package/esm/node_modules/openai/internal/shims.mjs +77 -0
  543. package/esm/node_modules/openai/internal/shims.mjs.map +1 -0
  544. package/esm/node_modules/openai/internal/to-file.mjs +63 -0
  545. package/esm/node_modules/openai/internal/to-file.mjs.map +1 -0
  546. package/esm/node_modules/openai/internal/tslib.mjs +16 -0
  547. package/esm/node_modules/openai/internal/tslib.mjs.map +1 -0
  548. package/esm/node_modules/openai/internal/uploads.mjs +94 -0
  549. package/esm/node_modules/openai/internal/uploads.mjs.map +1 -0
  550. package/esm/node_modules/openai/internal/utils/base64.mjs +22 -0
  551. package/esm/node_modules/openai/internal/utils/base64.mjs.map +1 -0
  552. package/esm/node_modules/openai/internal/utils/bytes.mjs +26 -0
  553. package/esm/node_modules/openai/internal/utils/bytes.mjs.map +1 -0
  554. package/esm/node_modules/openai/internal/utils/env.mjs +16 -0
  555. package/esm/node_modules/openai/internal/utils/env.mjs.map +1 -0
  556. package/esm/node_modules/openai/internal/utils/log.mjs +58 -0
  557. package/esm/node_modules/openai/internal/utils/log.mjs.map +1 -0
  558. package/esm/node_modules/openai/internal/utils/path.mjs +62 -0
  559. package/esm/node_modules/openai/internal/utils/path.mjs.map +1 -0
  560. package/esm/node_modules/openai/internal/utils/query.mjs +10 -0
  561. package/esm/node_modules/openai/internal/utils/query.mjs.map +1 -0
  562. package/esm/node_modules/openai/internal/utils/sleep.mjs +6 -0
  563. package/esm/node_modules/openai/internal/utils/sleep.mjs.map +1 -0
  564. package/esm/node_modules/openai/internal/utils/uuid.mjs +18 -0
  565. package/esm/node_modules/openai/internal/utils/uuid.mjs.map +1 -0
  566. package/esm/node_modules/openai/internal/utils/values.mjs +41 -0
  567. package/esm/node_modules/openai/internal/utils/values.mjs.map +1 -0
  568. package/esm/node_modules/openai/lib/AbstractChatCompletionRunner.mjs +247 -0
  569. package/esm/node_modules/openai/lib/AbstractChatCompletionRunner.mjs.map +1 -0
  570. package/esm/node_modules/openai/lib/AssistantStream.mjs +472 -0
  571. package/esm/node_modules/openai/lib/AssistantStream.mjs.map +1 -0
  572. package/esm/node_modules/openai/lib/ChatCompletionRunner.mjs +26 -0
  573. package/esm/node_modules/openai/lib/ChatCompletionRunner.mjs.map +1 -0
  574. package/esm/node_modules/openai/lib/ChatCompletionStream.mjs +423 -0
  575. package/esm/node_modules/openai/lib/ChatCompletionStream.mjs.map +1 -0
  576. package/esm/node_modules/openai/lib/ChatCompletionStreamingRunner.mjs +26 -0
  577. package/esm/node_modules/openai/lib/ChatCompletionStreamingRunner.mjs.map +1 -0
  578. package/esm/node_modules/openai/lib/EventStream.mjs +163 -0
  579. package/esm/node_modules/openai/lib/EventStream.mjs.map +1 -0
  580. package/esm/node_modules/openai/lib/ResponsesParser.mjs +94 -0
  581. package/esm/node_modules/openai/lib/ResponsesParser.mjs.map +1 -0
  582. package/esm/node_modules/openai/lib/RunnableFunction.mjs +8 -0
  583. package/esm/node_modules/openai/lib/RunnableFunction.mjs.map +1 -0
  584. package/esm/node_modules/openai/lib/Util.mjs +19 -0
  585. package/esm/node_modules/openai/lib/Util.mjs.map +1 -0
  586. package/esm/node_modules/openai/lib/chatCompletionUtils.mjs +11 -0
  587. package/esm/node_modules/openai/lib/chatCompletionUtils.mjs.map +1 -0
  588. package/esm/node_modules/openai/lib/parser.mjs +88 -0
  589. package/esm/node_modules/openai/lib/parser.mjs.map +1 -0
  590. package/esm/node_modules/openai/lib/responses/ResponseStream.mjs +231 -0
  591. package/esm/node_modules/openai/lib/responses/ResponseStream.mjs.map +1 -0
  592. package/esm/node_modules/openai/resources/admin/admin.mjs +15 -0
  593. package/esm/node_modules/openai/resources/admin/admin.mjs.map +1 -0
  594. package/esm/node_modules/openai/resources/admin/organization/admin-api-keys.mjs +81 -0
  595. package/esm/node_modules/openai/resources/admin/organization/admin-api-keys.mjs.map +1 -0
  596. package/esm/node_modules/openai/resources/admin/organization/audit-logs.mjs +31 -0
  597. package/esm/node_modules/openai/resources/admin/organization/audit-logs.mjs.map +1 -0
  598. package/esm/node_modules/openai/resources/admin/organization/certificates.mjs +153 -0
  599. package/esm/node_modules/openai/resources/admin/organization/certificates.mjs.map +1 -0
  600. package/esm/node_modules/openai/resources/admin/organization/data-retention.mjs +42 -0
  601. package/esm/node_modules/openai/resources/admin/organization/data-retention.mjs.map +1 -0
  602. package/esm/node_modules/openai/resources/admin/organization/groups/groups.mjs +106 -0
  603. package/esm/node_modules/openai/resources/admin/organization/groups/groups.mjs.map +1 -0
  604. package/esm/node_modules/openai/resources/admin/organization/groups/roles.mjs +88 -0
  605. package/esm/node_modules/openai/resources/admin/organization/groups/roles.mjs.map +1 -0
  606. package/esm/node_modules/openai/resources/admin/organization/groups/users.mjs +88 -0
  607. package/esm/node_modules/openai/resources/admin/organization/groups/users.mjs.map +1 -0
  608. package/esm/node_modules/openai/resources/admin/organization/invites.mjs +83 -0
  609. package/esm/node_modules/openai/resources/admin/organization/invites.mjs.map +1 -0
  610. package/esm/node_modules/openai/resources/admin/organization/organization.mjs +45 -0
  611. package/esm/node_modules/openai/resources/admin/organization/organization.mjs.map +1 -0
  612. package/esm/node_modules/openai/resources/admin/organization/projects/api-keys.mjs +72 -0
  613. package/esm/node_modules/openai/resources/admin/organization/projects/api-keys.mjs.map +1 -0
  614. package/esm/node_modules/openai/resources/admin/organization/projects/certificates.mjs +78 -0
  615. package/esm/node_modules/openai/resources/admin/organization/projects/certificates.mjs.map +1 -0
  616. package/esm/node_modules/openai/resources/admin/organization/projects/data-retention.mjs +46 -0
  617. package/esm/node_modules/openai/resources/admin/organization/projects/data-retention.mjs.map +1 -0
  618. package/esm/node_modules/openai/resources/admin/organization/projects/groups/groups.mjs +95 -0
  619. package/esm/node_modules/openai/resources/admin/organization/projects/groups/groups.mjs.map +1 -0
  620. package/esm/node_modules/openai/resources/admin/organization/projects/groups/roles.mjs +91 -0
  621. package/esm/node_modules/openai/resources/admin/organization/projects/groups/roles.mjs.map +1 -0
  622. package/esm/node_modules/openai/resources/admin/organization/projects/hosted-tool-permissions.mjs +45 -0
  623. package/esm/node_modules/openai/resources/admin/organization/projects/hosted-tool-permissions.mjs.map +1 -0
  624. package/esm/node_modules/openai/resources/admin/organization/projects/model-permissions.mjs +63 -0
  625. package/esm/node_modules/openai/resources/admin/organization/projects/model-permissions.mjs.map +1 -0
  626. package/esm/node_modules/openai/resources/admin/organization/projects/projects.mjs +137 -0
  627. package/esm/node_modules/openai/resources/admin/organization/projects/projects.mjs.map +1 -0
  628. package/esm/node_modules/openai/resources/admin/organization/projects/rate-limits.mjs +51 -0
  629. package/esm/node_modules/openai/resources/admin/organization/projects/rate-limits.mjs.map +1 -0
  630. package/esm/node_modules/openai/resources/admin/organization/projects/roles.mjs +108 -0
  631. package/esm/node_modules/openai/resources/admin/organization/projects/roles.mjs.map +1 -0
  632. package/esm/node_modules/openai/resources/admin/organization/projects/service-accounts.mjs +112 -0
  633. package/esm/node_modules/openai/resources/admin/organization/projects/service-accounts.mjs.map +1 -0
  634. package/esm/node_modules/openai/resources/admin/organization/projects/spend-alerts.mjs +106 -0
  635. package/esm/node_modules/openai/resources/admin/organization/projects/spend-alerts.mjs.map +1 -0
  636. package/esm/node_modules/openai/resources/admin/organization/projects/users/roles.mjs +91 -0
  637. package/esm/node_modules/openai/resources/admin/organization/projects/users/roles.mjs.map +1 -0
  638. package/esm/node_modules/openai/resources/admin/organization/projects/users/users.mjs +118 -0
  639. package/esm/node_modules/openai/resources/admin/organization/projects/users/users.mjs.map +1 -0
  640. package/esm/node_modules/openai/resources/admin/organization/roles.mjs +96 -0
  641. package/esm/node_modules/openai/resources/admin/organization/roles.mjs.map +1 -0
  642. package/esm/node_modules/openai/resources/admin/organization/spend-alerts.mjs +97 -0
  643. package/esm/node_modules/openai/resources/admin/organization/spend-alerts.mjs.map +1 -0
  644. package/esm/node_modules/openai/resources/admin/organization/usage.mjs +207 -0
  645. package/esm/node_modules/openai/resources/admin/organization/usage.mjs.map +1 -0
  646. package/esm/node_modules/openai/resources/admin/organization/users/roles.mjs +88 -0
  647. package/esm/node_modules/openai/resources/admin/organization/users/roles.mjs.map +1 -0
  648. package/esm/node_modules/openai/resources/admin/organization/users/users.mjs +82 -0
  649. package/esm/node_modules/openai/resources/admin/organization/users/users.mjs.map +1 -0
  650. package/esm/node_modules/openai/resources/audio/audio.mjs +21 -0
  651. package/esm/node_modules/openai/resources/audio/audio.mjs.map +1 -0
  652. package/esm/node_modules/openai/resources/audio/speech.mjs +39 -0
  653. package/esm/node_modules/openai/resources/audio/speech.mjs.map +1 -0
  654. package/esm/node_modules/openai/resources/audio/transcriptions.mjs +22 -0
  655. package/esm/node_modules/openai/resources/audio/transcriptions.mjs.map +1 -0
  656. package/esm/node_modules/openai/resources/audio/translations.mjs +21 -0
  657. package/esm/node_modules/openai/resources/audio/translations.mjs.map +1 -0
  658. package/esm/node_modules/openai/resources/batches.mjs +54 -0
  659. package/esm/node_modules/openai/resources/batches.mjs.map +1 -0
  660. package/esm/node_modules/openai/resources/beta/assistants.mjs +78 -0
  661. package/esm/node_modules/openai/resources/beta/assistants.mjs.map +1 -0
  662. package/esm/node_modules/openai/resources/beta/beta.mjs +24 -0
  663. package/esm/node_modules/openai/resources/beta/beta.mjs.map +1 -0
  664. package/esm/node_modules/openai/resources/beta/chatkit/chatkit.mjs +18 -0
  665. package/esm/node_modules/openai/resources/beta/chatkit/chatkit.mjs.map +1 -0
  666. package/esm/node_modules/openai/resources/beta/chatkit/sessions.mjs +49 -0
  667. package/esm/node_modules/openai/resources/beta/chatkit/sessions.mjs.map +1 -0
  668. package/esm/node_modules/openai/resources/beta/chatkit/threads.mjs +85 -0
  669. package/esm/node_modules/openai/resources/beta/chatkit/threads.mjs.map +1 -0
  670. package/esm/node_modules/openai/resources/beta/realtime/realtime.mjs +21 -0
  671. package/esm/node_modules/openai/resources/beta/realtime/realtime.mjs.map +1 -0
  672. package/esm/node_modules/openai/resources/beta/realtime/sessions.mjs +33 -0
  673. package/esm/node_modules/openai/resources/beta/realtime/sessions.mjs.map +1 -0
  674. package/esm/node_modules/openai/resources/beta/realtime/transcription-sessions.mjs +33 -0
  675. package/esm/node_modules/openai/resources/beta/realtime/transcription-sessions.mjs.map +1 -0
  676. package/esm/node_modules/openai/resources/beta/threads/messages.mjs +83 -0
  677. package/esm/node_modules/openai/resources/beta/threads/messages.mjs.map +1 -0
  678. package/esm/node_modules/openai/resources/beta/threads/runs/runs.mjs +183 -0
  679. package/esm/node_modules/openai/resources/beta/threads/runs/runs.mjs.map +1 -0
  680. package/esm/node_modules/openai/resources/beta/threads/runs/steps.mjs +45 -0
  681. package/esm/node_modules/openai/resources/beta/threads/runs/steps.mjs.map +1 -0
  682. package/esm/node_modules/openai/resources/beta/threads/threads.mjs +101 -0
  683. package/esm/node_modules/openai/resources/beta/threads/threads.mjs.map +1 -0
  684. package/esm/node_modules/openai/resources/chat/chat.mjs +15 -0
  685. package/esm/node_modules/openai/resources/chat/chat.mjs.map +1 -0
  686. package/esm/node_modules/openai/resources/chat/completions/completions.mjs +123 -0
  687. package/esm/node_modules/openai/resources/chat/completions/completions.mjs.map +1 -0
  688. package/esm/node_modules/openai/resources/chat/completions/index.mjs +7 -0
  689. package/esm/node_modules/openai/resources/chat/completions/messages.mjs +35 -0
  690. package/esm/node_modules/openai/resources/chat/completions/messages.mjs.map +1 -0
  691. package/esm/node_modules/openai/resources/chat/index.mjs +5 -0
  692. package/esm/node_modules/openai/resources/completions.mjs +20 -0
  693. package/esm/node_modules/openai/resources/completions.mjs.map +1 -0
  694. package/esm/node_modules/openai/resources/containers/containers.mjs +57 -0
  695. package/esm/node_modules/openai/resources/containers/containers.mjs.map +1 -0
  696. package/esm/node_modules/openai/resources/containers/files/content.mjs +23 -0
  697. package/esm/node_modules/openai/resources/containers/files/content.mjs.map +1 -0
  698. package/esm/node_modules/openai/resources/containers/files/files.mjs +63 -0
  699. package/esm/node_modules/openai/resources/containers/files/files.mjs.map +1 -0
  700. package/esm/node_modules/openai/resources/conversations/conversations.mjs +57 -0
  701. package/esm/node_modules/openai/resources/conversations/conversations.mjs.map +1 -0
  702. package/esm/node_modules/openai/resources/conversations/items.mjs +57 -0
  703. package/esm/node_modules/openai/resources/conversations/items.mjs.map +1 -0
  704. package/esm/node_modules/openai/resources/embeddings.mjs +48 -0
  705. package/esm/node_modules/openai/resources/embeddings.mjs.map +1 -0
  706. package/esm/node_modules/openai/resources/evals/evals.mjs +73 -0
  707. package/esm/node_modules/openai/resources/evals/evals.mjs.map +1 -0
  708. package/esm/node_modules/openai/resources/evals/runs/output-items.mjs +35 -0
  709. package/esm/node_modules/openai/resources/evals/runs/output-items.mjs.map +1 -0
  710. package/esm/node_modules/openai/resources/evals/runs/runs.mjs +72 -0
  711. package/esm/node_modules/openai/resources/evals/runs/runs.mjs.map +1 -0
  712. package/esm/node_modules/openai/resources/files.mjs +111 -0
  713. package/esm/node_modules/openai/resources/files.mjs.map +1 -0
  714. package/esm/node_modules/openai/resources/fine-tuning/alpha/alpha.mjs +15 -0
  715. package/esm/node_modules/openai/resources/fine-tuning/alpha/alpha.mjs.map +1 -0
  716. package/esm/node_modules/openai/resources/fine-tuning/alpha/graders.mjs +60 -0
  717. package/esm/node_modules/openai/resources/fine-tuning/alpha/graders.mjs.map +1 -0
  718. package/esm/node_modules/openai/resources/fine-tuning/checkpoints/checkpoints.mjs +15 -0
  719. package/esm/node_modules/openai/resources/fine-tuning/checkpoints/checkpoints.mjs.map +1 -0
  720. package/esm/node_modules/openai/resources/fine-tuning/checkpoints/permissions.mjs +102 -0
  721. package/esm/node_modules/openai/resources/fine-tuning/checkpoints/permissions.mjs.map +1 -0
  722. package/esm/node_modules/openai/resources/fine-tuning/fine-tuning.mjs +24 -0
  723. package/esm/node_modules/openai/resources/fine-tuning/fine-tuning.mjs.map +1 -0
  724. package/esm/node_modules/openai/resources/fine-tuning/jobs/checkpoints.mjs +34 -0
  725. package/esm/node_modules/openai/resources/fine-tuning/jobs/checkpoints.mjs.map +1 -0
  726. package/esm/node_modules/openai/resources/fine-tuning/jobs/jobs.mjs +148 -0
  727. package/esm/node_modules/openai/resources/fine-tuning/jobs/jobs.mjs.map +1 -0
  728. package/esm/node_modules/openai/resources/fine-tuning/methods.mjs +8 -0
  729. package/esm/node_modules/openai/resources/fine-tuning/methods.mjs.map +1 -0
  730. package/esm/node_modules/openai/resources/graders/grader-models.mjs +8 -0
  731. package/esm/node_modules/openai/resources/graders/grader-models.mjs.map +1 -0
  732. package/esm/node_modules/openai/resources/graders/graders.mjs +15 -0
  733. package/esm/node_modules/openai/resources/graders/graders.mjs.map +1 -0
  734. package/esm/node_modules/openai/resources/images.mjs +46 -0
  735. package/esm/node_modules/openai/resources/images.mjs.map +1 -0
  736. package/esm/node_modules/openai/resources/index.mjs +27 -0
  737. package/esm/node_modules/openai/resources/models.mjs +44 -0
  738. package/esm/node_modules/openai/resources/models.mjs.map +1 -0
  739. package/esm/node_modules/openai/resources/moderations.mjs +23 -0
  740. package/esm/node_modules/openai/resources/moderations.mjs.map +1 -0
  741. package/esm/node_modules/openai/resources/realtime/calls.mjs +79 -0
  742. package/esm/node_modules/openai/resources/realtime/calls.mjs.map +1 -0
  743. package/esm/node_modules/openai/resources/realtime/client-secrets.mjs +39 -0
  744. package/esm/node_modules/openai/resources/realtime/client-secrets.mjs.map +1 -0
  745. package/esm/node_modules/openai/resources/realtime/realtime.mjs +18 -0
  746. package/esm/node_modules/openai/resources/realtime/realtime.mjs.map +1 -0
  747. package/esm/node_modules/openai/resources/responses/input-items.mjs +31 -0
  748. package/esm/node_modules/openai/resources/responses/input-items.mjs.map +1 -0
  749. package/esm/node_modules/openai/resources/responses/input-tokens.mjs +27 -0
  750. package/esm/node_modules/openai/resources/responses/input-tokens.mjs.map +1 -0
  751. package/esm/node_modules/openai/resources/responses/responses.mjs +110 -0
  752. package/esm/node_modules/openai/resources/responses/responses.mjs.map +1 -0
  753. package/esm/node_modules/openai/resources/skills/content.mjs +22 -0
  754. package/esm/node_modules/openai/resources/skills/content.mjs.map +1 -0
  755. package/esm/node_modules/openai/resources/skills/skills.mjs +69 -0
  756. package/esm/node_modules/openai/resources/skills/skills.mjs.map +1 -0
  757. package/esm/node_modules/openai/resources/skills/versions/content.mjs +23 -0
  758. package/esm/node_modules/openai/resources/skills/versions/content.mjs.map +1 -0
  759. package/esm/node_modules/openai/resources/skills/versions/versions.mjs +58 -0
  760. package/esm/node_modules/openai/resources/skills/versions/versions.mjs.map +1 -0
  761. package/esm/node_modules/openai/resources/uploads/parts.mjs +34 -0
  762. package/esm/node_modules/openai/resources/uploads/parts.mjs.map +1 -0
  763. package/esm/node_modules/openai/resources/uploads/uploads.mjs +84 -0
  764. package/esm/node_modules/openai/resources/uploads/uploads.mjs.map +1 -0
  765. package/esm/node_modules/openai/resources/vector-stores/file-batches.mjs +126 -0
  766. package/esm/node_modules/openai/resources/vector-stores/file-batches.mjs.map +1 -0
  767. package/esm/node_modules/openai/resources/vector-stores/files.mjs +147 -0
  768. package/esm/node_modules/openai/resources/vector-stores/files.mjs.map +1 -0
  769. package/esm/node_modules/openai/resources/vector-stores/vector-stores.mjs +87 -0
  770. package/esm/node_modules/openai/resources/vector-stores/vector-stores.mjs.map +1 -0
  771. package/esm/node_modules/openai/resources/videos.mjs +115 -0
  772. package/esm/node_modules/openai/resources/videos.mjs.map +1 -0
  773. package/esm/node_modules/openai/resources/webhooks/index.mjs +3 -0
  774. package/esm/node_modules/openai/resources/webhooks/webhooks.mjs +69 -0
  775. package/esm/node_modules/openai/resources/webhooks/webhooks.mjs.map +1 -0
  776. package/esm/node_modules/openai/resources/webhooks.mjs +4 -0
  777. package/esm/node_modules/openai/streaming.mjs +3 -0
  778. package/esm/node_modules/openai/version.mjs +6 -0
  779. package/esm/node_modules/openai/version.mjs.map +1 -0
  780. package/esm/repositories/adapters/cascade/cascade-query-builder.d.mts +9 -0
  781. package/esm/repositories/adapters/cascade/cascade-query-builder.d.mts.map +1 -1
  782. package/esm/repositories/adapters/cascade/cascade-query-builder.mjs +32 -5
  783. package/esm/repositories/adapters/cascade/cascade-query-builder.mjs.map +1 -1
  784. package/esm/repositories/adapters/cascade/filter-applicator.mjs +17 -3
  785. package/esm/repositories/adapters/cascade/filter-applicator.mjs.map +1 -1
  786. package/esm/repositories/repository.manager.d.mts +11 -1
  787. package/esm/repositories/repository.manager.d.mts.map +1 -1
  788. package/esm/repositories/repository.manager.mjs +79 -25
  789. package/esm/repositories/repository.manager.mjs.map +1 -1
  790. package/esm/router/route-registry.mjs +19 -10
  791. package/esm/router/route-registry.mjs.map +1 -1
  792. package/esm/router/router.d.mts.map +1 -1
  793. package/esm/router/router.mjs +7 -4
  794. package/esm/router/router.mjs.map +1 -1
  795. package/esm/storage/drivers/cloud-driver.d.mts.map +1 -1
  796. package/esm/storage/drivers/cloud-driver.mjs +48 -12
  797. package/esm/storage/drivers/cloud-driver.mjs.map +1 -1
  798. package/esm/storage/drivers/do-spaces-driver.mjs +1 -1
  799. package/esm/storage/drivers/do-spaces-driver.mjs.map +1 -1
  800. package/esm/storage/drivers/local-driver.d.mts +8 -0
  801. package/esm/storage/drivers/local-driver.d.mts.map +1 -1
  802. package/esm/storage/drivers/local-driver.mjs +19 -4
  803. package/esm/storage/drivers/local-driver.mjs.map +1 -1
  804. package/esm/storage/drivers/r2-driver.mjs +1 -1
  805. package/esm/storage/drivers/r2-driver.mjs.map +1 -1
  806. package/esm/storage/drivers/s3-driver.mjs +1 -1
  807. package/esm/storage/drivers/s3-driver.mjs.map +1 -1
  808. package/esm/storage/index.d.mts +4 -1
  809. package/esm/storage/index.mjs +3 -0
  810. package/esm/storage/scoped-storage.d.mts +8 -4
  811. package/esm/storage/scoped-storage.d.mts.map +1 -1
  812. package/esm/storage/scoped-storage.mjs +21 -6
  813. package/esm/storage/scoped-storage.mjs.map +1 -1
  814. package/esm/storage/storage.d.mts +12 -4
  815. package/esm/storage/storage.d.mts.map +1 -1
  816. package/esm/storage/storage.mjs +23 -9
  817. package/esm/storage/storage.mjs.map +1 -1
  818. package/esm/storage/types.d.mts +33 -5
  819. package/esm/storage/types.d.mts.map +1 -1
  820. package/esm/storage/utils/contain-path.d.mts +23 -0
  821. package/esm/storage/utils/contain-path.d.mts.map +1 -0
  822. package/esm/storage/utils/contain-path.mjs +35 -0
  823. package/esm/storage/utils/contain-path.mjs.map +1 -0
  824. package/esm/storage/utils/safe-fetch.d.mts +68 -0
  825. package/esm/storage/utils/safe-fetch.d.mts.map +1 -0
  826. package/esm/storage/utils/safe-fetch.mjs +205 -0
  827. package/esm/storage/utils/safe-fetch.mjs.map +1 -0
  828. package/esm/storage/utils/storage-error.d.mts +35 -0
  829. package/esm/storage/utils/storage-error.d.mts.map +1 -0
  830. package/esm/storage/utils/storage-error.mjs +17 -0
  831. package/esm/storage/utils/storage-error.mjs.map +1 -0
  832. package/esm/use-cases/use-case-pipeline.mjs +4 -1
  833. package/esm/use-cases/use-case-pipeline.mjs.map +1 -1
  834. package/esm/use-cases/use-case.mjs +12 -4
  835. package/esm/use-cases/use-case.mjs.map +1 -1
  836. package/esm/use-cases/use-cases-registry.d.mts +12 -4
  837. package/esm/use-cases/use-cases-registry.d.mts.map +1 -1
  838. package/esm/use-cases/use-cases-registry.mjs +13 -3
  839. package/esm/use-cases/use-cases-registry.mjs.map +1 -1
  840. package/esm/utils/npm-registry.d.mts +1 -1
  841. package/esm/utils/npm-registry.mjs +2 -2
  842. package/esm/utils/npm-registry.mjs.map +1 -1
  843. package/llms-full.txt +29 -1
  844. package/package.json +9 -9
  845. package/skills/add-connector/SKILL.md +6 -1
  846. package/skills/configure-app/SKILL.md +23 -0
@@ -0,0 +1,81 @@
1
+ import { AgentExecutionError } from "../errors/agent-execution-error.mjs";
2
+ import "../errors/index.mjs";
3
+ import { compositeAsTool } from "./tool.mjs";
4
+
5
+ //#region ../@warlock.js/ai/src/tool/executable-as-tool.ts
6
+ /**
7
+ * Identity passthrough schema used when an executable is registered as
8
+ * a tool without declaring an `inputSchema`. The model's raw arguments
9
+ * flow straight to `execute()` unchanged — the executable validates
10
+ * internally (workflows via their steps, supervisors/agents via their
11
+ * own input handling).
12
+ */
13
+ function passthroughSchema() {
14
+ return { "~standard": {
15
+ version: 1,
16
+ vendor: "warlock-ai",
17
+ validate: (value) => ({ value })
18
+ } };
19
+ }
20
+ /**
21
+ * Type guard distinguishing a raw executable primitive from a built
22
+ * `ToolContract`. An executable exposes `execute()` and no `invoke()`;
23
+ * a `ToolContract` exposes `invoke()`. The `invoke` check is the
24
+ * load-bearing discriminator — `.asTool()`-wrapped composites keep
25
+ * their own `execute` too, so checking `execute` alone is insufficient.
26
+ */
27
+ function isExecutableTool(entry) {
28
+ if (!entry || typeof entry !== "object") return false;
29
+ const candidate = entry;
30
+ return typeof candidate.execute === "function" && typeof candidate.invoke !== "function";
31
+ }
32
+ /**
33
+ * Adapt a raw executable primitive (agent / workflow / supervisor) into
34
+ * a `ToolContract` so an agent can dispatch it inside its tool-call
35
+ * loop WITHOUT the caller writing `.asTool()`. Derives the LLM tool
36
+ * manifest from the executable's own `name` + `description` +
37
+ * (optional) `inputSchema`, then dispatches through the executable's
38
+ * `execute()` — the inner report nests under the outer tool-call node
39
+ * exactly like an explicit `.asTool()` wrapper.
40
+ *
41
+ * Throws `AgentExecutionError` at author time when the executable lacks
42
+ * a usable `name` — the agent's tool surface needs a stable id, the
43
+ * same constraint `.asTool()` enforces.
44
+ */
45
+ function executableToTool(executable) {
46
+ if (!executable.name || typeof executable.name !== "string") throw new AgentExecutionError("tools[]: an executable (agent/workflow/supervisor) used as a tool must have a `name`", { context: { authoring: true } });
47
+ return compositeAsTool({
48
+ name: executable.name,
49
+ description: executable.description ?? `Invoke "${executable.name}" as a tool.`,
50
+ input: executable.inputSchema ?? passthroughSchema(),
51
+ execute: async (input, ctx) => {
52
+ const result = await executable.execute(input, ctx?.signal ? { signal: ctx.signal } : void 0);
53
+ if (result.error) throw result.error;
54
+ return {
55
+ data: result.data,
56
+ usage: result.usage,
57
+ report: result.report
58
+ };
59
+ }
60
+ });
61
+ }
62
+ /**
63
+ * Normalize an agent's `tools: []` array into a uniform
64
+ * `ToolContract[]` for the runtime. Already-built `ToolContract`s
65
+ * (`.asTool()` / `ai.tool()`) pass through untouched; raw executable
66
+ * primitives are auto-adapted via {@link executableToTool}.
67
+ *
68
+ * Returns `undefined` when no tools were supplied so the agent's
69
+ * existing `config.tools ?? []` fallbacks stay byte-identical.
70
+ */
71
+ function normalizeAgentTools(tools) {
72
+ if (!tools) return;
73
+ return tools.map((entry) => {
74
+ if (isExecutableTool(entry)) return executableToTool(entry);
75
+ return entry;
76
+ });
77
+ }
78
+
79
+ //#endregion
80
+ export { executableToTool, isExecutableTool, normalizeAgentTools };
81
+ //# sourceMappingURL=executable-as-tool.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executable-as-tool.mjs","names":[],"sources":["../../../../../../../../../@warlock.js/ai/src/tool/executable-as-tool.ts"],"sourcesContent":["import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { BaseReport } from \"../contracts/result/base-report.type\";\nimport type { BaseResult } from \"../contracts/result/base-result.type\";\nimport type { Usage } from \"../contracts/result/usage.type\";\nimport { AgentExecutionError, type AIError } from \"../errors\";\nimport { compositeAsTool, type ToolContract } from \"./tool\";\n\n/**\n * Envelope every executable's `execute()` resolves to. Agent, workflow,\n * and supervisor results all satisfy this shape — `data` / `error`\n * carry the outcome while `usage` and `report` are always present —\n * which is exactly what {@link compositeAsTool} needs to nest the inner\n * run under the outer tool-call node.\n */\ntype ExecutableEnvelope<TOutput> = BaseResult & {\n data?: TOutput;\n error?: AIError;\n report: BaseReport;\n};\n\n/**\n * Structural view of an executable primitive (agent / workflow /\n * supervisor) when it is dropped straight into an agent's `tools: []`\n * array WITHOUT being wrapped via `.asTool()` first.\n *\n * Only the fields the auto-adapt path reads are declared:\n * - `name` — becomes the LLM tool name (required; anonymous executables\n * are rejected at author time, mirroring `.asTool()`).\n * - `description` — the \"when would the model pick this?\" line.\n * - `inputSchema` — opt-in Standard Schema typing the tool's arguments.\n * Surfaced on `WorkflowInstance` / `SupervisorContract` from the new\n * optional `inputSchema` config field. Absent for agents (which take\n * a plain string prompt).\n * - `execute` — the dispatch entry every `ExecutableContract` exposes.\n *\n * `invoke` is declared `never` so a `ToolContract` (which HAS `invoke`)\n * can never be mistaken for an executable by the {@link isExecutableTool}\n * guard.\n */\nexport type ExecutableTool<TInput = unknown, TOutput = unknown> = {\n readonly name: string;\n readonly description?: string;\n readonly inputSchema?: StandardSchemaV1<TInput>;\n execute(input: TInput, options?: unknown): Promise<ExecutableEnvelope<TOutput>>;\n invoke?: never;\n};\n\n/**\n * Entry accepted in an agent's `tools: []` array — either an already-\n * built `ToolContract` (the `.asTool()` / `ai.tool()` path) or a raw\n * executable primitive the framework auto-adapts on the caller's\n * behalf.\n */\nexport type AgentToolEntry<TInput = unknown, TOutput = unknown> =\n | ToolContract<TInput, TOutput>\n | ExecutableTool<TInput, TOutput>;\n\n/**\n * Identity passthrough schema used when an executable is registered as\n * a tool without declaring an `inputSchema`. The model's raw arguments\n * flow straight to `execute()` unchanged — the executable validates\n * internally (workflows via their steps, supervisors/agents via their\n * own input handling).\n */\nfunction passthroughSchema<TInput>(): StandardSchemaV1<TInput> {\n return {\n \"~standard\": {\n version: 1,\n vendor: \"warlock-ai\",\n validate: (value: unknown) => ({ value: value as TInput }),\n },\n };\n}\n\n/**\n * Type guard distinguishing a raw executable primitive from a built\n * `ToolContract`. An executable exposes `execute()` and no `invoke()`;\n * a `ToolContract` exposes `invoke()`. The `invoke` check is the\n * load-bearing discriminator — `.asTool()`-wrapped composites keep\n * their own `execute` too, so checking `execute` alone is insufficient.\n */\nexport function isExecutableTool(entry: unknown): entry is ExecutableTool {\n if (!entry || typeof entry !== \"object\") {\n return false;\n }\n\n const candidate = entry as { execute?: unknown; invoke?: unknown };\n\n return typeof candidate.execute === \"function\" && typeof candidate.invoke !== \"function\";\n}\n\n/**\n * Adapt a raw executable primitive (agent / workflow / supervisor) into\n * a `ToolContract` so an agent can dispatch it inside its tool-call\n * loop WITHOUT the caller writing `.asTool()`. Derives the LLM tool\n * manifest from the executable's own `name` + `description` +\n * (optional) `inputSchema`, then dispatches through the executable's\n * `execute()` — the inner report nests under the outer tool-call node\n * exactly like an explicit `.asTool()` wrapper.\n *\n * Throws `AgentExecutionError` at author time when the executable lacks\n * a usable `name` — the agent's tool surface needs a stable id, the\n * same constraint `.asTool()` enforces.\n */\nexport function executableToTool<TInput, TOutput>(\n executable: ExecutableTool<TInput, TOutput>,\n): ToolContract<TInput, TOutput> {\n if (!executable.name || typeof executable.name !== \"string\") {\n throw new AgentExecutionError(\n \"tools[]: an executable (agent/workflow/supervisor) used as a tool must have a `name`\",\n { context: { authoring: true } },\n );\n }\n\n return compositeAsTool<TInput, TOutput>({\n name: executable.name,\n description: executable.description ?? `Invoke \"${executable.name}\" as a tool.`,\n input: executable.inputSchema ?? passthroughSchema<TInput>(),\n execute: async (input, ctx) => {\n // Relay the outer run's cancellation signal so a cancelled parent\n // aborts this nested agent/workflow/supervisor (C2). Omit the\n // options object entirely when there's no signal so primitives that\n // treat any second arg as meaningful stay byte-identical.\n const result = await executable.execute(\n input,\n ctx?.signal ? { signal: ctx.signal } : undefined,\n );\n\n if (result.error) {\n // Surface the inner typed error so the surrounding\n // `compositeAsTool` wrapper produces a `ToolExecutionError`\n // with `cause` pointing back at the original subclass — the\n // agent's tool-call loop sees one uniform error class\n // regardless of which primitive failed.\n throw result.error;\n }\n\n return {\n data: result.data as TOutput,\n usage: result.usage as Usage,\n report: result.report,\n };\n },\n });\n}\n\n/**\n * Normalize an agent's `tools: []` array into a uniform\n * `ToolContract[]` for the runtime. Already-built `ToolContract`s\n * (`.asTool()` / `ai.tool()`) pass through untouched; raw executable\n * primitives are auto-adapted via {@link executableToTool}.\n *\n * Returns `undefined` when no tools were supplied so the agent's\n * existing `config.tools ?? []` fallbacks stay byte-identical.\n */\nexport function normalizeAgentTools(\n tools: ReadonlyArray<AgentToolEntry> | undefined,\n): ToolContract<unknown, unknown>[] | undefined {\n if (!tools) {\n return undefined;\n }\n\n return tools.map((entry) => {\n if (isExecutableTool(entry)) {\n return executableToTool(entry) as ToolContract<unknown, unknown>;\n }\n\n return entry as ToolContract<unknown, unknown>;\n });\n}\n"],"mappings":";;;;;;;;;;;;AAgEA,SAAS,oBAAsD;CAC7D,OAAO,EACL,aAAa;EACX,SAAS;EACT,QAAQ;EACR,WAAW,WAAoB,EAAS,MAAgB;CAC1D,EACF;AACF;;;;;;;;AASA,SAAgB,iBAAiB,OAAyC;CACxE,IAAI,CAAC,SAAS,OAAO,UAAU,UAC7B,OAAO;CAGT,MAAM,YAAY;CAElB,OAAO,OAAO,UAAU,YAAY,cAAc,OAAO,UAAU,WAAW;AAChF;;;;;;;;;;;;;;AAeA,SAAgB,iBACd,YAC+B;CAC/B,IAAI,CAAC,WAAW,QAAQ,OAAO,WAAW,SAAS,UACjD,MAAM,IAAI,oBACR,wFACA,EAAE,SAAS,EAAE,WAAW,KAAK,EAAE,CACjC;CAGF,OAAO,gBAAiC;EACtC,MAAM,WAAW;EACjB,aAAa,WAAW,eAAe,WAAW,WAAW,KAAK;EAClE,OAAO,WAAW,eAAe,kBAA0B;EAC3D,SAAS,OAAO,OAAO,QAAQ;GAK7B,MAAM,SAAS,MAAM,WAAW,QAC9B,OACA,KAAK,SAAS,EAAE,QAAQ,IAAI,OAAO,IAAI,MACzC;GAEA,IAAI,OAAO,OAMT,MAAM,OAAO;GAGf,OAAO;IACL,MAAM,OAAO;IACb,OAAO,OAAO;IACd,QAAQ,OAAO;GACjB;EACF;CACF,CAAC;AACH;;;;;;;;;;AAWA,SAAgB,oBACd,OAC8C;CAC9C,IAAI,CAAC,OACH;CAGF,OAAO,MAAM,KAAK,UAAU;EAC1B,IAAI,iBAAiB,KAAK,GACxB,OAAO,iBAAiB,KAAK;EAG/B,OAAO;CACT,CAAC;AACH"}
@@ -0,0 +1,4 @@
1
+ import { tool } from "./tool.mjs";
2
+ import { executableToTool, isExecutableTool, normalizeAgentTools } from "./executable-as-tool.mjs";
3
+
4
+ export { };
@@ -0,0 +1,185 @@
1
+ import { SchemaValidationError } from "../errors/schema-validation-error.mjs";
2
+ import { ToolExecutionError } from "../errors/tool-execution-error.mjs";
3
+ import "../errors/index.mjs";
4
+ import { generateRunId } from "../utils/generate-run-id.mjs";
5
+
6
+ //#region ../@warlock.js/ai/src/tool/tool.ts
7
+ /**
8
+ * Degraded `ToolContext` supplied when no caller threads one through
9
+ * (`tool.invoke(input)` standalone, batch scripts, tests). Per
10
+ * decisions §35 — mutations on the empty bag are harmless no-ops;
11
+ * production paths under a supervisor receive a real ctx with the
12
+ * iteration's shared bag.
13
+ */
14
+ function defaultToolContext() {
15
+ return { artifacts: {} };
16
+ }
17
+ const EMPTY_USAGE = Object.freeze({
18
+ input: 0,
19
+ output: 0,
20
+ total: 0
21
+ });
22
+ /**
23
+ * Wraps a raw `ToolConfig` and adds a safe `invoke()` method for the agent runtime.
24
+ * The returned object preserves all original contract fields unchanged.
25
+ *
26
+ * Error categorization:
27
+ * - Input schema rejects model args → `SchemaValidationError` (issues preserved).
28
+ * - Schema's `validate()` itself throws → `SchemaValidationError` wrapping the cause.
29
+ * - `execute()` throws → `ToolExecutionError` wrapping the cause.
30
+ *
31
+ * @example
32
+ * const weatherTool = tool({
33
+ * name: "getWeather",
34
+ * description: "Fetch current weather for a city",
35
+ * input: z.object({ city: z.string() }),
36
+ * execute: async ({ city }) => ({ temp: 72 }),
37
+ * });
38
+ *
39
+ * const result = await weatherTool.invoke({ city: "Cairo" });
40
+ */
41
+ /**
42
+ * Internal factory for `asTool()` wrappers on composite primitives
43
+ * (agent / workflow / supervisor). Unlike the public `tool()` factory
44
+ * (which synthesizes a leaf `BaseReport` every time), this variant
45
+ * lets the composite's own `ExecuteResult` flow through: the inner
46
+ * primitive's `report` becomes the sole child of the outer tool-call
47
+ * node, and the inner `usage` is surfaced so parents can roll it up.
48
+ *
49
+ * The caller supplies `execute()` returning `{ data, usage, report }`
50
+ * from the composite's own `execute()` method. Validation failures
51
+ * and thrown errors still produce a synthesized failed leaf report —
52
+ * the inner-report propagation is strictly a success-path concern.
53
+ *
54
+ * Not exported from the package barrel — used by `agent.asTool()`,
55
+ * `workflow.asTool()`, `supervisor.asTool()` only.
56
+ */
57
+ function compositeAsTool(contract) {
58
+ const publicExecute = async (input) => {
59
+ const envelope = await contract.execute(input);
60
+ if (envelope.error) throw envelope.error;
61
+ return envelope.data;
62
+ };
63
+ return {
64
+ name: contract.name,
65
+ description: contract.description ?? `Composite tool "${contract.name}".`,
66
+ meta: contract.meta,
67
+ input: contract.input,
68
+ execute: publicExecute,
69
+ async invoke(rawInput, ctx) {
70
+ const startedAtDate = /* @__PURE__ */ new Date();
71
+ const start = performance.now();
72
+ const runId = generateRunId("tool");
73
+ const failLeaf = (error) => {
74
+ const endedAt = (/* @__PURE__ */ new Date()).toISOString();
75
+ const duration = performance.now() - start;
76
+ return {
77
+ error,
78
+ usage: EMPTY_USAGE,
79
+ report: {
80
+ runId,
81
+ rootRunId: runId,
82
+ name: contract.name,
83
+ version: contract.version,
84
+ type: "tool",
85
+ status: "failed",
86
+ startedAt: startedAtDate.toISOString(),
87
+ endedAt,
88
+ duration,
89
+ usage: EMPTY_USAGE,
90
+ children: []
91
+ }
92
+ };
93
+ };
94
+ let validationResult;
95
+ try {
96
+ validationResult = await contract.input["~standard"].validate(rawInput);
97
+ } catch (thrown) {
98
+ const message = thrown instanceof Error ? thrown.message : String(thrown);
99
+ return failLeaf(new SchemaValidationError(`Schema validation threw for tool "${contract.name}": ${message}`, {
100
+ cause: thrown,
101
+ context: { toolName: contract.name }
102
+ }));
103
+ }
104
+ if (validationResult.issues) return failLeaf(new SchemaValidationError(`Validation failed: ${validationResult.issues.map((issue) => issue.message).join("; ")}`, {
105
+ issues: validationResult.issues,
106
+ context: { toolName: contract.name }
107
+ }));
108
+ try {
109
+ const composite = await contract.execute(validationResult.value, ctx);
110
+ return {
111
+ data: composite.data,
112
+ error: composite.error,
113
+ usage: composite.usage,
114
+ report: composite.report
115
+ };
116
+ } catch (thrown) {
117
+ return failLeaf(new ToolExecutionError(thrown instanceof Error ? thrown.message : String(thrown), {
118
+ cause: thrown,
119
+ toolName: contract.name
120
+ }));
121
+ }
122
+ }
123
+ };
124
+ }
125
+ function tool(contract) {
126
+ return {
127
+ ...contract,
128
+ async invoke(rawInput, ctx) {
129
+ const startedAtDate = /* @__PURE__ */ new Date();
130
+ const start = performance.now();
131
+ const runId = generateRunId("tool");
132
+ const handlerCtx = ctx ?? defaultToolContext();
133
+ const finish = (partial) => {
134
+ const endedAt = (/* @__PURE__ */ new Date()).toISOString();
135
+ const duration = performance.now() - start;
136
+ const status = partial.error ? "failed" : "completed";
137
+ const report = {
138
+ runId,
139
+ rootRunId: runId,
140
+ name: contract.name,
141
+ version: contract.version,
142
+ type: "tool",
143
+ status,
144
+ startedAt: startedAtDate.toISOString(),
145
+ endedAt,
146
+ duration,
147
+ usage: EMPTY_USAGE,
148
+ children: []
149
+ };
150
+ return {
151
+ ...partial,
152
+ usage: EMPTY_USAGE,
153
+ report
154
+ };
155
+ };
156
+ let validationResult;
157
+ if (contract.input) try {
158
+ validationResult = await contract.input["~standard"].validate(rawInput);
159
+ } catch (thrown) {
160
+ const message = thrown instanceof Error ? thrown.message : String(thrown);
161
+ return finish({ error: new SchemaValidationError(`Schema validation threw for tool "${contract.name}": ${message}`, {
162
+ cause: thrown,
163
+ context: { toolName: contract.name }
164
+ }) });
165
+ }
166
+ else validationResult = { value: rawInput };
167
+ if (validationResult.issues) return finish({ error: new SchemaValidationError(`Validation failed: ${validationResult.issues.map((issue) => issue.message).join("; ")}`, {
168
+ issues: validationResult.issues,
169
+ context: { toolName: contract.name }
170
+ }) });
171
+ try {
172
+ return finish({ data: await contract.execute(validationResult.value, handlerCtx) });
173
+ } catch (thrown) {
174
+ return finish({ error: new ToolExecutionError(thrown instanceof Error ? thrown.message : String(thrown), {
175
+ cause: thrown,
176
+ toolName: contract.name
177
+ }) });
178
+ }
179
+ }
180
+ };
181
+ }
182
+
183
+ //#endregion
184
+ export { compositeAsTool, tool };
185
+ //# sourceMappingURL=tool.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool.mjs","names":[],"sources":["../../../../../../../../../@warlock.js/ai/src/tool/tool.ts"],"sourcesContent":["import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { BaseReport } from \"../contracts/result/base-report.type\";\nimport type { Usage } from \"../contracts/result/usage.type\";\nimport type { ToolConfig, ToolContext } from \"../contracts/tool.contract\";\nimport { AIError, SchemaValidationError, ToolExecutionError } from \"../errors\";\nimport { generateRunId } from \"../utils/generate-run-id\";\n\n/**\n * Degraded `ToolContext` supplied when no caller threads one through\n * (`tool.invoke(input)` standalone, batch scripts, tests). Per\n * decisions §35 — mutations on the empty bag are harmless no-ops;\n * production paths under a supervisor receive a real ctx with the\n * iteration's shared bag.\n */\nfunction defaultToolContext(): ToolContext {\n return { artifacts: {} };\n}\n\nconst EMPTY_USAGE: Usage = Object.freeze({ input: 0, output: 0, total: 0 });\n\n/**\n * Result returned by `ToolContract.invoke()`.\n *\n * **Canonical destructure:** `const { data, usage, report, error }` —\n * matches every other executable (`AgentResult`, `WorkflowResult`,\n * `SupervisorResult`) so parent agents can treat every tool dispatch\n * uniformly.\n *\n * **Shape.** `data` / `error` carry the outcome; `usage` and `report`\n * are always present. For leaf tools, `usage` is zero and `report`\n * is a framework-synthesized {@link BaseReport} (`type: \"tool\"`,\n * `children: []`, real timing) so parents never have to nil-check.\n * For composites wrapped via `asTool()`, `usage` and `report` mirror\n * the inner primitive's — the nested tree lives in `report.children`.\n *\n * @example\n * const result = await myTool.invoke({ city: \"Cairo\" });\n * if (result.error) console.error(result.error.message);\n * else console.log(result.data, result.report.duration);\n */\nexport type ToolInvokeResult<TOutput> = {\n /** Successfully-returned output. Undefined if execution or validation failed. */\n data?: TOutput;\n /** Typed AI error produced by validation or execute(), if any. */\n error?: AIError;\n /** Rolled-up usage (zero for leaf tools, populated for composites). */\n usage: Usage;\n /** Recursive execution report — `report.children` carries nested executables. */\n report: BaseReport;\n};\n\n/**\n * A `ToolConfig` augmented with a safe `invoke()` entry point for the agent runtime.\n *\n * @example\n * const wrapped: ToolContract<{ city: string }, { temp: number }> = tool(contract);\n * const result = await wrapped.invoke({ city: \"Cairo\" });\n */\nexport interface ToolContract<TInput = unknown, TOutput = unknown> extends ToolConfig<\n TInput,\n TOutput\n> {\n /**\n * Agent-runtime entry point. Validates raw input against the tool's schema,\n * calls execute(), catches errors, and reports duration.\n * Never throws — errors surface in the returned `error` field as\n * typed `AIError` subclasses.\n *\n * The optional second argument is a `ToolContext` (Phase 5 /\n * decisions §35) — when supplied, threaded into `execute(input, ctx)`\n * so tools can write system-only side data into `ctx.artifacts`.\n * Standalone callers may omit it; the framework supplies a\n * degraded `{ artifacts: {} }` so single-arg legacy handlers keep\n * working unchanged.\n *\n * @example\n * const result = await myTool.invoke(rawLLMArgs);\n * if (result.error) handleError(result.error);\n */\n invoke(rawInput: unknown, ctx?: ToolContext): Promise<ToolInvokeResult<TOutput>>;\n}\n\n/**\n * Wraps a raw `ToolConfig` and adds a safe `invoke()` method for the agent runtime.\n * The returned object preserves all original contract fields unchanged.\n *\n * Error categorization:\n * - Input schema rejects model args → `SchemaValidationError` (issues preserved).\n * - Schema's `validate()` itself throws → `SchemaValidationError` wrapping the cause.\n * - `execute()` throws → `ToolExecutionError` wrapping the cause.\n *\n * @example\n * const weatherTool = tool({\n * name: \"getWeather\",\n * description: \"Fetch current weather for a city\",\n * input: z.object({ city: z.string() }),\n * execute: async ({ city }) => ({ temp: 72 }),\n * });\n *\n * const result = await weatherTool.invoke({ city: \"Cairo\" });\n */\n/**\n * Internal factory for `asTool()` wrappers on composite primitives\n * (agent / workflow / supervisor). Unlike the public `tool()` factory\n * (which synthesizes a leaf `BaseReport` every time), this variant\n * lets the composite's own `ExecuteResult` flow through: the inner\n * primitive's `report` becomes the sole child of the outer tool-call\n * node, and the inner `usage` is surfaced so parents can roll it up.\n *\n * The caller supplies `execute()` returning `{ data, usage, report }`\n * from the composite's own `execute()` method. Validation failures\n * and thrown errors still produce a synthesized failed leaf report —\n * the inner-report propagation is strictly a success-path concern.\n *\n * Not exported from the package barrel — used by `agent.asTool()`,\n * `workflow.asTool()`, `supervisor.asTool()` only.\n */\nexport function compositeAsTool<TInput, TOutput>(contract: {\n name: string;\n description?: string;\n version?: string;\n meta?: ToolConfig[\"meta\"];\n input: StandardSchemaV1<TInput>;\n /**\n * Runs the underlying composite and returns its full envelope. The\n * optional `ctx` relays the outer run's cancellation `signal` so a\n * cancelled parent aborts the nested primitive instead of letting it\n * outlive the cancellation (C2).\n */\n execute: (input: TInput, ctx?: ToolContext) => Promise<{\n data?: TOutput;\n error?: AIError;\n usage: Usage;\n report: BaseReport;\n }>;\n}): ToolContract<TInput, TOutput> {\n // The underlying `ToolConfig<TInput, TOutput>.execute` is typed as\n // `(input) => Promise<TOutput>`, but composite wrappers return an\n // envelope object instead. Surface a contract-shaped view that\n // extracts `.data` on demand for any code that still treats this\n // like a plain tool.\n const publicExecute = async (input: TInput): Promise<TOutput> => {\n const envelope = await contract.execute(input);\n if (envelope.error) throw envelope.error;\n return envelope.data as TOutput;\n };\n\n return {\n name: contract.name,\n description: contract.description ?? `Composite tool \"${contract.name}\".`,\n meta: contract.meta,\n input: contract.input,\n execute: publicExecute,\n\n async invoke(rawInput: unknown, ctx?: ToolContext): Promise<ToolInvokeResult<TOutput>> {\n // Composite tools (asTool-wrapped agent/workflow/supervisor) run in\n // their own state/scope — the ctx's `artifacts` bag is NOT shared\n // into the inner primitive (an inner supervisor gets a fresh bag).\n // The cancellation `signal`, however, IS relayed (below, into\n // `contract.execute`) so a cancelled outer run aborts the nested\n // primitive instead of letting it outlive the cancellation (C2).\n const startedAtDate = new Date();\n const start = performance.now();\n const runId = generateRunId(\"tool\");\n\n const failLeaf = (error: AIError): ToolInvokeResult<TOutput> => {\n const endedAt = new Date().toISOString();\n const duration = performance.now() - start;\n return {\n error,\n usage: EMPTY_USAGE,\n report: {\n runId,\n rootRunId: runId,\n name: contract.name,\n version: contract.version,\n type: \"tool\",\n status: \"failed\",\n startedAt: startedAtDate.toISOString(),\n endedAt,\n duration,\n usage: EMPTY_USAGE,\n children: [],\n },\n };\n };\n\n let validationResult: StandardSchemaV1.Result<TInput>;\n try {\n const schema = contract.input as StandardSchemaV1<TInput>;\n validationResult = await schema[\"~standard\"].validate(rawInput);\n } catch (thrown) {\n const message = thrown instanceof Error ? thrown.message : String(thrown);\n return failLeaf(\n new SchemaValidationError(\n `Schema validation threw for tool \"${contract.name}\": ${message}`,\n { cause: thrown, context: { toolName: contract.name } },\n ),\n );\n }\n\n if (validationResult.issues) {\n const summary = validationResult.issues.map((issue) => issue.message).join(\"; \");\n return failLeaf(\n new SchemaValidationError(`Validation failed: ${summary}`, {\n issues: validationResult.issues,\n context: { toolName: contract.name },\n }),\n );\n }\n\n try {\n const composite = await contract.execute(validationResult.value, ctx);\n // Surface the inner primitive's full envelope. The outer\n // ToolInvokeResult carries the composite's usage and report\n // verbatim; the agent runtime nests the report as a child of\n // the tool-dispatch node it records.\n return {\n data: composite.data,\n error: composite.error,\n usage: composite.usage,\n report: composite.report,\n };\n } catch (thrown) {\n const message = thrown instanceof Error ? thrown.message : String(thrown);\n return failLeaf(\n new ToolExecutionError(message, {\n cause: thrown,\n toolName: contract.name,\n }),\n );\n }\n },\n };\n}\n\nexport function tool<TInput, TOutput>(\n contract: ToolConfig<TInput, TOutput>,\n): ToolContract<TInput, TOutput> {\n return {\n ...contract,\n\n async invoke(rawInput: unknown, ctx?: ToolContext): Promise<ToolInvokeResult<TOutput>> {\n const startedAtDate = new Date();\n const start = performance.now();\n const runId = generateRunId(\"tool\");\n const handlerCtx = ctx ?? defaultToolContext();\n\n const finish = (partial: { data?: TOutput; error?: AIError }): ToolInvokeResult<TOutput> => {\n const endedAt = new Date().toISOString();\n const duration = performance.now() - start;\n const status: BaseReport[\"status\"] = partial.error ? \"failed\" : \"completed\";\n const report: BaseReport = {\n runId,\n rootRunId: runId,\n name: contract.name,\n version: contract.version,\n type: \"tool\",\n status,\n startedAt: startedAtDate.toISOString(),\n endedAt,\n duration,\n usage: EMPTY_USAGE,\n children: [],\n };\n\n return {\n ...partial,\n usage: EMPTY_USAGE,\n report,\n };\n };\n\n let validationResult: StandardSchemaV1.Result<TInput>;\n if (contract.input) {\n try {\n validationResult = await contract.input[\"~standard\"].validate(rawInput);\n } catch (thrown) {\n const message = thrown instanceof Error ? thrown.message : String(thrown);\n\n return finish({\n error: new SchemaValidationError(\n `Schema validation threw for tool \"${contract.name}\": ${message}`,\n { cause: thrown, context: { toolName: contract.name } },\n ),\n });\n }\n } else {\n // `input` is optional on ToolConfig — this is a no-argument tool\n // (e.g. view_cart, checkout). With no schema there is nothing to\n // validate, so pass the raw model args straight to execute()\n // instead of dereferencing a missing schema's `~standard`.\n validationResult = { value: rawInput as TInput };\n }\n\n if (validationResult.issues) {\n const summary = validationResult.issues.map((issue) => issue.message).join(\"; \");\n\n return finish({\n error: new SchemaValidationError(`Validation failed: ${summary}`, {\n issues: validationResult.issues,\n context: { toolName: contract.name },\n }),\n });\n }\n\n try {\n const output = await contract.execute(validationResult.value, handlerCtx);\n return finish({ data: output });\n } catch (thrown) {\n const message = thrown instanceof Error ? thrown.message : String(thrown);\n\n return finish({\n error: new ToolExecutionError(message, {\n cause: thrown,\n toolName: contract.name,\n }),\n });\n }\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;AAcA,SAAS,qBAAkC;CACzC,OAAO,EAAE,WAAW,CAAC,EAAE;AACzB;AAEA,MAAM,cAAqB,OAAO,OAAO;CAAE,OAAO;CAAG,QAAQ;CAAG,OAAO;AAAE,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmG1E,SAAgB,gBAAiC,UAkBf;CAMhC,MAAM,gBAAgB,OAAO,UAAoC;EAC/D,MAAM,WAAW,MAAM,SAAS,QAAQ,KAAK;EAC7C,IAAI,SAAS,OAAO,MAAM,SAAS;EACnC,OAAO,SAAS;CAClB;CAEA,OAAO;EACL,MAAM,SAAS;EACf,aAAa,SAAS,eAAe,mBAAmB,SAAS,KAAK;EACtE,MAAM,SAAS;EACf,OAAO,SAAS;EAChB,SAAS;EAET,MAAM,OAAO,UAAmB,KAAuD;GAOrF,MAAM,gCAAgB,IAAI,KAAK;GAC/B,MAAM,QAAQ,YAAY,IAAI;GAC9B,MAAM,QAAQ,cAAc,MAAM;GAElC,MAAM,YAAY,UAA8C;IAC9D,MAAM,2BAAU,IAAI,KAAK,EAAC,CAAC,YAAY;IACvC,MAAM,WAAW,YAAY,IAAI,IAAI;IACrC,OAAO;KACL;KACA,OAAO;KACP,QAAQ;MACN;MACA,WAAW;MACX,MAAM,SAAS;MACf,SAAS,SAAS;MAClB,MAAM;MACN,QAAQ;MACR,WAAW,cAAc,YAAY;MACrC;MACA;MACA,OAAO;MACP,UAAU,CAAC;KACb;IACF;GACF;GAEA,IAAI;GACJ,IAAI;IAEF,mBAAmB,MADJ,SAAS,MACQ,YAAY,CAAC,SAAS,QAAQ;GAChE,SAAS,QAAQ;IACf,MAAM,UAAU,kBAAkB,QAAQ,OAAO,UAAU,OAAO,MAAM;IACxE,OAAO,SACL,IAAI,sBACF,qCAAqC,SAAS,KAAK,KAAK,WACxD;KAAE,OAAO;KAAQ,SAAS,EAAE,UAAU,SAAS,KAAK;IAAE,CACxD,CACF;GACF;GAEA,IAAI,iBAAiB,QAEnB,OAAO,SACL,IAAI,sBAAsB,sBAFZ,iBAAiB,OAAO,KAAK,UAAU,MAAM,OAAO,CAAC,CAAC,KAAK,IAEnB,KAAK;IACzD,QAAQ,iBAAiB;IACzB,SAAS,EAAE,UAAU,SAAS,KAAK;GACrC,CAAC,CACH;GAGF,IAAI;IACF,MAAM,YAAY,MAAM,SAAS,QAAQ,iBAAiB,OAAO,GAAG;IAKpE,OAAO;KACL,MAAM,UAAU;KAChB,OAAO,UAAU;KACjB,OAAO,UAAU;KACjB,QAAQ,UAAU;IACpB;GACF,SAAS,QAAQ;IAEf,OAAO,SACL,IAAI,mBAFU,kBAAkB,QAAQ,OAAO,UAAU,OAAO,MAAM,GAEtC;KAC9B,OAAO;KACP,UAAU,SAAS;IACrB,CAAC,CACH;GACF;EACF;CACF;AACF;AAEA,SAAgB,KACd,UAC+B;CAC/B,OAAO;EACL,GAAG;EAEH,MAAM,OAAO,UAAmB,KAAuD;GACrF,MAAM,gCAAgB,IAAI,KAAK;GAC/B,MAAM,QAAQ,YAAY,IAAI;GAC9B,MAAM,QAAQ,cAAc,MAAM;GAClC,MAAM,aAAa,OAAO,mBAAmB;GAE7C,MAAM,UAAU,YAA4E;IAC1F,MAAM,2BAAU,IAAI,KAAK,EAAC,CAAC,YAAY;IACvC,MAAM,WAAW,YAAY,IAAI,IAAI;IACrC,MAAM,SAA+B,QAAQ,QAAQ,WAAW;IAChE,MAAM,SAAqB;KACzB;KACA,WAAW;KACX,MAAM,SAAS;KACf,SAAS,SAAS;KAClB,MAAM;KACN;KACA,WAAW,cAAc,YAAY;KACrC;KACA;KACA,OAAO;KACP,UAAU,CAAC;IACb;IAEA,OAAO;KACL,GAAG;KACH,OAAO;KACP;IACF;GACF;GAEA,IAAI;GACJ,IAAI,SAAS,OACX,IAAI;IACF,mBAAmB,MAAM,SAAS,MAAM,YAAY,CAAC,SAAS,QAAQ;GACxE,SAAS,QAAQ;IACf,MAAM,UAAU,kBAAkB,QAAQ,OAAO,UAAU,OAAO,MAAM;IAExE,OAAO,OAAO,EACZ,OAAO,IAAI,sBACT,qCAAqC,SAAS,KAAK,KAAK,WACxD;KAAE,OAAO;KAAQ,SAAS,EAAE,UAAU,SAAS,KAAK;IAAE,CACxD,EACF,CAAC;GACH;QAMA,mBAAmB,EAAE,OAAO,SAAmB;GAGjD,IAAI,iBAAiB,QAGnB,OAAO,OAAO,EACZ,OAAO,IAAI,sBAAsB,sBAHnB,iBAAiB,OAAO,KAAK,UAAU,MAAM,OAAO,CAAC,CAAC,KAAK,IAGZ,KAAK;IAChE,QAAQ,iBAAiB;IACzB,SAAS,EAAE,UAAU,SAAS,KAAK;GACrC,CAAC,EACH,CAAC;GAGH,IAAI;IAEF,OAAO,OAAO,EAAE,MAAM,MADD,SAAS,QAAQ,iBAAiB,OAAO,UAAU,EAC3C,CAAC;GAChC,SAAS,QAAQ;IAGf,OAAO,OAAO,EACZ,OAAO,IAAI,mBAHG,kBAAkB,QAAQ,OAAO,UAAU,OAAO,MAAM,GAG/B;KACrC,OAAO;KACP,UAAU,SAAS;IACrB,CAAC,EACH,CAAC;GACH;EACF;CACF;AACF"}
@@ -0,0 +1,112 @@
1
+ //#region ../@warlock.js/ai/src/utils/compute-cost.ts
2
+ /**
3
+ * Compute a per-channel USD cost breakdown for a single `Usage` against
4
+ * a model's pricing table. Returns `undefined` when no pricing is
5
+ * configured — the framework treats unpriced runs as "cost unknown,"
6
+ * not "cost zero," so dashboards can distinguish free-tier from
7
+ * un-instrumented.
8
+ *
9
+ * **Shape mirrors `ModelPricing`** — `input`, `output`, optional
10
+ * `cachedInput` / `cachedOutput`. Consumers needing a scalar total
11
+ * sum the populated fields. The breakdown is the value-add: it tells
12
+ * downstream tooling HOW the total was reached (input-vs-output
13
+ * share, cache savings) without re-deriving against pricing tables
14
+ * that may have shifted since the report was written.
15
+ *
16
+ * **Cache-aware.** `usage.cachedTokens` is the subset of `usage.input`
17
+ * served from the provider's prompt cache and bills at
18
+ * `pricing.cachedInput` (falls back to full `pricing.input` when the
19
+ * provider doesn't publish a cache rate). The remaining `input -
20
+ * cachedTokens` bills at full rate and shows up in `cost.input`. The
21
+ * `cachedOutput` channel is reserved for Anthropic-style cache writes;
22
+ * until an adapter populates `usage.cacheWriteTokens`, the framework
23
+ * leaves it undefined.
24
+ *
25
+ * Pricing values are USD-per-million-tokens. The function divides
26
+ * once at the end to avoid floating-point accumulation error on
27
+ * per-token math.
28
+ *
29
+ * @example
30
+ * const usage: Usage = { input: 150_000, output: 30_000, total: 180_000, cachedTokens: 90_000 };
31
+ * const cost = computeCost(usage, { input: 0.15, output: 0.6, cachedInput: 0.075 });
32
+ * // cost = {
33
+ * // input: (60_000 * 0.15) / 1e6 = 0.009,
34
+ * // output: (30_000 * 0.6) / 1e6 = 0.018,
35
+ * // cachedInput: (90_000 * 0.075) / 1e6 = 0.00675,
36
+ * // }
37
+ */
38
+ function computeCost(usage, pricing) {
39
+ if (!pricing) return;
40
+ const cachedInput = usage.cachedTokens ?? 0;
41
+ const cost = {
42
+ input: Math.max(0, usage.input - cachedInput) * pricing.input / 1e6,
43
+ output: usage.output * pricing.output / 1e6
44
+ };
45
+ if (cachedInput > 0) cost.cachedInput = cachedInput * (pricing.cachedInput ?? pricing.input) / 1e6;
46
+ return cost;
47
+ }
48
+ /**
49
+ * Merge a child's cost breakdown into a running parent total. Each
50
+ * channel (`input`, `output`, `cachedInput`, `cachedOutput`) sums
51
+ * independently — an undefined channel on either side is treated as
52
+ * zero contribution rather than dropping the other side's value. A
53
+ * single unpriced child should never erase the cost of its priced
54
+ * siblings.
55
+ *
56
+ * Returns the new parent breakdown, or `undefined` when neither parent
57
+ * nor child carried any cost data (preserves the "no priced
58
+ * contributor has appeared yet" signal that distinguishes "missing
59
+ * pricing" from "genuinely zero").
60
+ */
61
+ function accumulateCost(parent, child) {
62
+ if (!child) return parent;
63
+ if (!parent) return { ...child };
64
+ const merged = {
65
+ input: parent.input + child.input,
66
+ output: parent.output + child.output
67
+ };
68
+ const cachedInput = sumOptional(parent.cachedInput, child.cachedInput);
69
+ if (cachedInput !== void 0) merged.cachedInput = cachedInput;
70
+ const cachedOutput = sumOptional(parent.cachedOutput, child.cachedOutput);
71
+ if (cachedOutput !== void 0) merged.cachedOutput = cachedOutput;
72
+ return merged;
73
+ }
74
+ /**
75
+ * Add two optional numbers, treating either side's `undefined` as
76
+ * zero — but return `undefined` when both are absent. Keeps "this
77
+ * channel was never reported anywhere" distinguishable from "this
78
+ * channel was reported as 0."
79
+ */
80
+ function sumOptional(parent, child) {
81
+ if (parent === void 0 && child === void 0) return;
82
+ return (parent ?? 0) + (child ?? 0);
83
+ }
84
+ /**
85
+ * Accumulate a child {@link Usage} into a running parent total, mutating
86
+ * `target` in place. Scalar token channels (`input` / `output` / `total`)
87
+ * sum directly; the optional sub-channels (`cachedTokens`,
88
+ * `reasoningTokens`, `cacheWriteTokens`) accumulate only when some
89
+ * contributor reported them (preserving the "never reported anywhere"
90
+ * signal); and the cost breakdown merges via {@link accumulateCost} so a
91
+ * single unpriced child can never erase a priced sibling's cost.
92
+ *
93
+ * This is the ONE canonical usage rollup — every aggregator (agent,
94
+ * workflow, supervisor, team, planner, batch) routes through it so cost +
95
+ * cache/reasoning telemetry propagates identically to the top-level
96
+ * `result.usage`. Re-implementing a bare `input/output/total` sum at a
97
+ * call site silently drops those optional channels.
98
+ */
99
+ function mergeUsage(target, child) {
100
+ target.input += child.input;
101
+ target.output += child.output;
102
+ target.total += child.total;
103
+ if (child.cachedTokens !== void 0) target.cachedTokens = (target.cachedTokens ?? 0) + child.cachedTokens;
104
+ if (child.reasoningTokens !== void 0) target.reasoningTokens = (target.reasoningTokens ?? 0) + child.reasoningTokens;
105
+ if (child.cacheWriteTokens !== void 0) target.cacheWriteTokens = (target.cacheWriteTokens ?? 0) + child.cacheWriteTokens;
106
+ const mergedCost = accumulateCost(target.cost, child.cost);
107
+ if (mergedCost !== void 0) target.cost = mergedCost;
108
+ }
109
+
110
+ //#endregion
111
+ export { accumulateCost, computeCost, mergeUsage };
112
+ //# sourceMappingURL=compute-cost.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compute-cost.mjs","names":[],"sources":["../../../../../../../../../@warlock.js/ai/src/utils/compute-cost.ts"],"sourcesContent":["import type { ModelPricing } from \"../contracts/result/model-pricing.type\";\nimport type { Usage } from \"../contracts/result/usage.type\";\n\n/**\n * Compute a per-channel USD cost breakdown for a single `Usage` against\n * a model's pricing table. Returns `undefined` when no pricing is\n * configured — the framework treats unpriced runs as \"cost unknown,\"\n * not \"cost zero,\" so dashboards can distinguish free-tier from\n * un-instrumented.\n *\n * **Shape mirrors `ModelPricing`** — `input`, `output`, optional\n * `cachedInput` / `cachedOutput`. Consumers needing a scalar total\n * sum the populated fields. The breakdown is the value-add: it tells\n * downstream tooling HOW the total was reached (input-vs-output\n * share, cache savings) without re-deriving against pricing tables\n * that may have shifted since the report was written.\n *\n * **Cache-aware.** `usage.cachedTokens` is the subset of `usage.input`\n * served from the provider's prompt cache and bills at\n * `pricing.cachedInput` (falls back to full `pricing.input` when the\n * provider doesn't publish a cache rate). The remaining `input -\n * cachedTokens` bills at full rate and shows up in `cost.input`. The\n * `cachedOutput` channel is reserved for Anthropic-style cache writes;\n * until an adapter populates `usage.cacheWriteTokens`, the framework\n * leaves it undefined.\n *\n * Pricing values are USD-per-million-tokens. The function divides\n * once at the end to avoid floating-point accumulation error on\n * per-token math.\n *\n * @example\n * const usage: Usage = { input: 150_000, output: 30_000, total: 180_000, cachedTokens: 90_000 };\n * const cost = computeCost(usage, { input: 0.15, output: 0.6, cachedInput: 0.075 });\n * // cost = {\n * // input: (60_000 * 0.15) / 1e6 = 0.009,\n * // output: (30_000 * 0.6) / 1e6 = 0.018,\n * // cachedInput: (90_000 * 0.075) / 1e6 = 0.00675,\n * // }\n */\nexport function computeCost(usage: Usage, pricing: ModelPricing | undefined): ModelPricing | undefined {\n if (!pricing) {\n return undefined;\n }\n\n const cachedInput = usage.cachedTokens ?? 0;\n const uncachedInput = Math.max(0, usage.input - cachedInput);\n\n const cost: ModelPricing = {\n input: (uncachedInput * pricing.input) / 1_000_000,\n output: (usage.output * pricing.output) / 1_000_000,\n };\n\n if (cachedInput > 0) {\n const cachedInputRate = pricing.cachedInput ?? pricing.input;\n cost.cachedInput = (cachedInput * cachedInputRate) / 1_000_000;\n }\n\n return cost;\n}\n\n/**\n * Merge a child's cost breakdown into a running parent total. Each\n * channel (`input`, `output`, `cachedInput`, `cachedOutput`) sums\n * independently — an undefined channel on either side is treated as\n * zero contribution rather than dropping the other side's value. A\n * single unpriced child should never erase the cost of its priced\n * siblings.\n *\n * Returns the new parent breakdown, or `undefined` when neither parent\n * nor child carried any cost data (preserves the \"no priced\n * contributor has appeared yet\" signal that distinguishes \"missing\n * pricing\" from \"genuinely zero\").\n */\nexport function accumulateCost(\n parent: ModelPricing | undefined,\n child: ModelPricing | undefined,\n): ModelPricing | undefined {\n if (!child) {\n return parent;\n }\n\n if (!parent) {\n return { ...child };\n }\n\n const merged: ModelPricing = {\n input: parent.input + child.input,\n output: parent.output + child.output,\n };\n\n const cachedInput = sumOptional(parent.cachedInput, child.cachedInput);\n if (cachedInput !== undefined) {\n merged.cachedInput = cachedInput;\n }\n\n const cachedOutput = sumOptional(parent.cachedOutput, child.cachedOutput);\n if (cachedOutput !== undefined) {\n merged.cachedOutput = cachedOutput;\n }\n\n return merged;\n}\n\n/**\n * Add two optional numbers, treating either side's `undefined` as\n * zero — but return `undefined` when both are absent. Keeps \"this\n * channel was never reported anywhere\" distinguishable from \"this\n * channel was reported as 0.\"\n */\nfunction sumOptional(parent: number | undefined, child: number | undefined): number | undefined {\n if (parent === undefined && child === undefined) {\n return undefined;\n }\n\n return (parent ?? 0) + (child ?? 0);\n}\n\n/**\n * Accumulate a child {@link Usage} into a running parent total, mutating\n * `target` in place. Scalar token channels (`input` / `output` / `total`)\n * sum directly; the optional sub-channels (`cachedTokens`,\n * `reasoningTokens`, `cacheWriteTokens`) accumulate only when some\n * contributor reported them (preserving the \"never reported anywhere\"\n * signal); and the cost breakdown merges via {@link accumulateCost} so a\n * single unpriced child can never erase a priced sibling's cost.\n *\n * This is the ONE canonical usage rollup — every aggregator (agent,\n * workflow, supervisor, team, planner, batch) routes through it so cost +\n * cache/reasoning telemetry propagates identically to the top-level\n * `result.usage`. Re-implementing a bare `input/output/total` sum at a\n * call site silently drops those optional channels.\n */\nexport function mergeUsage(target: Usage, child: Usage): void {\n target.input += child.input;\n target.output += child.output;\n target.total += child.total;\n\n if (child.cachedTokens !== undefined) {\n target.cachedTokens = (target.cachedTokens ?? 0) + child.cachedTokens;\n }\n\n if (child.reasoningTokens !== undefined) {\n target.reasoningTokens = (target.reasoningTokens ?? 0) + child.reasoningTokens;\n }\n\n if (child.cacheWriteTokens !== undefined) {\n target.cacheWriteTokens = (target.cacheWriteTokens ?? 0) + child.cacheWriteTokens;\n }\n\n const mergedCost = accumulateCost(target.cost, child.cost);\n if (mergedCost !== undefined) {\n target.cost = mergedCost;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,SAAgB,YAAY,OAAc,SAA6D;CACrG,IAAI,CAAC,SACH;CAGF,MAAM,cAAc,MAAM,gBAAgB;CAG1C,MAAM,OAAqB;EACzB,OAHoB,KAAK,IAAI,GAAG,MAAM,QAAQ,WAG1B,IAAI,QAAQ,QAAS;EACzC,QAAS,MAAM,SAAS,QAAQ,SAAU;CAC5C;CAEA,IAAI,cAAc,GAEhB,KAAK,cAAe,eADI,QAAQ,eAAe,QAAQ,SACF;CAGvD,OAAO;AACT;;;;;;;;;;;;;;AAeA,SAAgB,eACd,QACA,OAC0B;CAC1B,IAAI,CAAC,OACH,OAAO;CAGT,IAAI,CAAC,QACH,OAAO,EAAE,GAAG,MAAM;CAGpB,MAAM,SAAuB;EAC3B,OAAO,OAAO,QAAQ,MAAM;EAC5B,QAAQ,OAAO,SAAS,MAAM;CAChC;CAEA,MAAM,cAAc,YAAY,OAAO,aAAa,MAAM,WAAW;CACrE,IAAI,gBAAgB,QAClB,OAAO,cAAc;CAGvB,MAAM,eAAe,YAAY,OAAO,cAAc,MAAM,YAAY;CACxE,IAAI,iBAAiB,QACnB,OAAO,eAAe;CAGxB,OAAO;AACT;;;;;;;AAQA,SAAS,YAAY,QAA4B,OAA+C;CAC9F,IAAI,WAAW,UAAa,UAAU,QACpC;CAGF,QAAQ,UAAU,MAAM,SAAS;AACnC;;;;;;;;;;;;;;;;AAiBA,SAAgB,WAAW,QAAe,OAAoB;CAC5D,OAAO,SAAS,MAAM;CACtB,OAAO,UAAU,MAAM;CACvB,OAAO,SAAS,MAAM;CAEtB,IAAI,MAAM,iBAAiB,QACzB,OAAO,gBAAgB,OAAO,gBAAgB,KAAK,MAAM;CAG3D,IAAI,MAAM,oBAAoB,QAC5B,OAAO,mBAAmB,OAAO,mBAAmB,KAAK,MAAM;CAGjE,IAAI,MAAM,qBAAqB,QAC7B,OAAO,oBAAoB,OAAO,oBAAoB,KAAK,MAAM;CAGnE,MAAM,aAAa,eAAe,OAAO,MAAM,MAAM,IAAI;CACzD,IAAI,eAAe,QACjB,OAAO,OAAO;AAElB"}
@@ -0,0 +1,97 @@
1
+ import { extractJsonPayload } from "./extract-json-payload.mjs";
2
+
3
+ //#region ../@warlock.js/ai/src/utils/extract-json-lenient.ts
4
+ /**
5
+ * Lenient counterpart to {@link extractJsonPayload}, tuned for the
6
+ * structured-output judges that emit *corrupted* JSON — notably the
7
+ * Amazon Nova family, which routinely wraps its verdict in fenced
8
+ * ` ```json ` blocks, prepends an explanation paragraph, or trails the
9
+ * object with commentary.
10
+ *
11
+ * Where `extractJsonPayload` deliberately refuses the "first `{` … last
12
+ * `}`" heuristic (it would corrupt strict callers when prose contains
13
+ * stray braces), this helper *opts into* that resilience: after fence
14
+ * stripping it scans for the first balanced JSON object (`{…}`) or array
15
+ * (`[…]`) and returns just that slice. Brace/bracket counting is
16
+ * string-aware (it ignores braces inside JSON string literals and honors
17
+ * `\"` escapes), so prose-embedded braces inside the JSON's own strings
18
+ * don't throw off the balance.
19
+ *
20
+ * Returns the fence-stripped, trimmed text unchanged when no balanced
21
+ * structure is found, so the caller's `JSON.parse` still fails loudly on
22
+ * genuine garbage rather than this helper inventing a value.
23
+ *
24
+ * **Trade-off:** resilience over strictness. Use it only where a tolerant
25
+ * parse is wanted (the judge preset) — for normal structured output keep
26
+ * `extractJsonPayload`, which fails fast on malformed responses so real
27
+ * prompt/model defects surface instead of being silently papered over.
28
+ *
29
+ * @example
30
+ * extractJsonLenient('Here is my verdict:\n```json\n{"score":0.9}\n``` — done.');
31
+ * // => '{"score":0.9}'
32
+ *
33
+ * @example
34
+ * extractJsonLenient('The answer is {"verdict":"pass"} for sure.');
35
+ * // => '{"verdict":"pass"}'
36
+ *
37
+ * @example
38
+ * extractJsonLenient('{"valid":true}');
39
+ * // => '{"valid":true}' (clean JSON passes through)
40
+ */
41
+ function extractJsonLenient(text) {
42
+ const stripped = extractJsonPayload(text);
43
+ return sliceFirstBalanced(stripped) ?? stripped;
44
+ }
45
+ /**
46
+ * Scan for the first balanced JSON object or array and return its raw
47
+ * slice. Returns `undefined` when no opening `{`/`[` is found or the
48
+ * structure never closes (truncated / partial output) — the caller then
49
+ * falls back to the fence-stripped text so the failure stays visible.
50
+ *
51
+ * String-literal aware: braces and brackets appearing *inside* a JSON
52
+ * string are not counted toward the balance, and a backslash escapes the
53
+ * next character so an escaped quote (`\"`) doesn't prematurely end the
54
+ * string scan.
55
+ */
56
+ function sliceFirstBalanced(text) {
57
+ const start = firstOpenerIndex(text);
58
+ if (start === -1) return;
59
+ const opener = text[start];
60
+ const closer = opener === "{" ? "}" : "]";
61
+ let depth = 0;
62
+ let inString = false;
63
+ let escaped = false;
64
+ for (let index = start; index < text.length; index++) {
65
+ const char = text[index];
66
+ if (inString) {
67
+ if (escaped) escaped = false;
68
+ else if (char === "\\") escaped = true;
69
+ else if (char === "\"") inString = false;
70
+ continue;
71
+ }
72
+ if (char === "\"") {
73
+ inString = true;
74
+ continue;
75
+ }
76
+ if (char === opener) depth++;
77
+ else if (char === closer) {
78
+ depth--;
79
+ if (depth === 0) return text.slice(start, index + 1);
80
+ }
81
+ }
82
+ }
83
+ /**
84
+ * Index of the first JSON structure opener (`{` or `[`), whichever
85
+ * appears earliest, or `-1` when neither is present.
86
+ */
87
+ function firstOpenerIndex(text) {
88
+ const brace = text.indexOf("{");
89
+ const bracket = text.indexOf("[");
90
+ if (brace === -1) return bracket;
91
+ if (bracket === -1) return brace;
92
+ return Math.min(brace, bracket);
93
+ }
94
+
95
+ //#endregion
96
+ export { extractJsonLenient };
97
+ //# sourceMappingURL=extract-json-lenient.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extract-json-lenient.mjs","names":[],"sources":["../../../../../../../../../@warlock.js/ai/src/utils/extract-json-lenient.ts"],"sourcesContent":["import { extractJsonPayload } from \"./extract-json-payload\";\n\n/**\n * Lenient counterpart to {@link extractJsonPayload}, tuned for the\n * structured-output judges that emit *corrupted* JSON — notably the\n * Amazon Nova family, which routinely wraps its verdict in fenced\n * ` ```json ` blocks, prepends an explanation paragraph, or trails the\n * object with commentary.\n *\n * Where `extractJsonPayload` deliberately refuses the \"first `{` … last\n * `}`\" heuristic (it would corrupt strict callers when prose contains\n * stray braces), this helper *opts into* that resilience: after fence\n * stripping it scans for the first balanced JSON object (`{…}`) or array\n * (`[…]`) and returns just that slice. Brace/bracket counting is\n * string-aware (it ignores braces inside JSON string literals and honors\n * `\\\"` escapes), so prose-embedded braces inside the JSON's own strings\n * don't throw off the balance.\n *\n * Returns the fence-stripped, trimmed text unchanged when no balanced\n * structure is found, so the caller's `JSON.parse` still fails loudly on\n * genuine garbage rather than this helper inventing a value.\n *\n * **Trade-off:** resilience over strictness. Use it only where a tolerant\n * parse is wanted (the judge preset) — for normal structured output keep\n * `extractJsonPayload`, which fails fast on malformed responses so real\n * prompt/model defects surface instead of being silently papered over.\n *\n * @example\n * extractJsonLenient('Here is my verdict:\\n```json\\n{\"score\":0.9}\\n``` — done.');\n * // => '{\"score\":0.9}'\n *\n * @example\n * extractJsonLenient('The answer is {\"verdict\":\"pass\"} for sure.');\n * // => '{\"verdict\":\"pass\"}'\n *\n * @example\n * extractJsonLenient('{\"valid\":true}');\n * // => '{\"valid\":true}' (clean JSON passes through)\n */\nexport function extractJsonLenient(text: string): string {\n // First reuse the strict fence stripper. When the model produced a\n // clean fenced block this already yields the exact payload, so the\n // balanced scan below becomes a no-op pass-through.\n const stripped = extractJsonPayload(text);\n\n const sliced = sliceFirstBalanced(stripped);\n\n return sliced ?? stripped;\n}\n\n/**\n * Scan for the first balanced JSON object or array and return its raw\n * slice. Returns `undefined` when no opening `{`/`[` is found or the\n * structure never closes (truncated / partial output) — the caller then\n * falls back to the fence-stripped text so the failure stays visible.\n *\n * String-literal aware: braces and brackets appearing *inside* a JSON\n * string are not counted toward the balance, and a backslash escapes the\n * next character so an escaped quote (`\\\"`) doesn't prematurely end the\n * string scan.\n */\nfunction sliceFirstBalanced(text: string): string | undefined {\n const start = firstOpenerIndex(text);\n\n if (start === -1) {\n return undefined;\n }\n\n const opener = text[start];\n const closer = opener === \"{\" ? \"}\" : \"]\";\n\n let depth = 0;\n let inString = false;\n let escaped = false;\n\n for (let index = start; index < text.length; index++) {\n const char = text[index];\n\n if (inString) {\n if (escaped) {\n escaped = false;\n } else if (char === \"\\\\\") {\n escaped = true;\n } else if (char === '\"') {\n inString = false;\n }\n\n continue;\n }\n\n if (char === '\"') {\n inString = true;\n continue;\n }\n\n if (char === opener) {\n depth++;\n } else if (char === closer) {\n depth--;\n\n if (depth === 0) {\n return text.slice(start, index + 1);\n }\n }\n }\n\n // Opener with no matching close — truncated / partial output. Leave it\n // to the caller's fallback (and its loud parse failure).\n return undefined;\n}\n\n/**\n * Index of the first JSON structure opener (`{` or `[`), whichever\n * appears earliest, or `-1` when neither is present.\n */\nfunction firstOpenerIndex(text: string): number {\n const brace = text.indexOf(\"{\");\n const bracket = text.indexOf(\"[\");\n\n if (brace === -1) {\n return bracket;\n }\n\n if (bracket === -1) {\n return brace;\n }\n\n return Math.min(brace, bracket);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,SAAgB,mBAAmB,MAAsB;CAIvD,MAAM,WAAW,mBAAmB,IAAI;CAIxC,OAFe,mBAAmB,QAEtB,KAAK;AACnB;;;;;;;;;;;;AAaA,SAAS,mBAAmB,MAAkC;CAC5D,MAAM,QAAQ,iBAAiB,IAAI;CAEnC,IAAI,UAAU,IACZ;CAGF,MAAM,SAAS,KAAK;CACpB,MAAM,SAAS,WAAW,MAAM,MAAM;CAEtC,IAAI,QAAQ;CACZ,IAAI,WAAW;CACf,IAAI,UAAU;CAEd,KAAK,IAAI,QAAQ,OAAO,QAAQ,KAAK,QAAQ,SAAS;EACpD,MAAM,OAAO,KAAK;EAElB,IAAI,UAAU;GACZ,IAAI,SACF,UAAU;QACL,IAAI,SAAS,MAClB,UAAU;QACL,IAAI,SAAS,MAClB,WAAW;GAGb;EACF;EAEA,IAAI,SAAS,MAAK;GAChB,WAAW;GACX;EACF;EAEA,IAAI,SAAS,QACX;OACK,IAAI,SAAS,QAAQ;GAC1B;GAEA,IAAI,UAAU,GACZ,OAAO,KAAK,MAAM,OAAO,QAAQ,CAAC;EAEtC;CACF;AAKF;;;;;AAMA,SAAS,iBAAiB,MAAsB;CAC9C,MAAM,QAAQ,KAAK,QAAQ,GAAG;CAC9B,MAAM,UAAU,KAAK,QAAQ,GAAG;CAEhC,IAAI,UAAU,IACZ,OAAO;CAGT,IAAI,YAAY,IACd,OAAO;CAGT,OAAO,KAAK,IAAI,OAAO,OAAO;AAChC"}
@@ -0,0 +1,39 @@
1
+ //#region ../@warlock.js/ai/src/utils/extract-json-payload.ts
2
+ /**
3
+ * Strip markdown code fences from an LLM response before JSON parsing.
4
+ *
5
+ * Models — especially Claude, smaller models, and local models — routinely
6
+ * wrap JSON output in fenced code blocks (` ```json\n{...}\n``` `) even when
7
+ * instructed otherwise. Sometimes they also precede the fence with prose
8
+ * ("Here you go:\n```json\n...\n```"). This helper finds the first fenced
9
+ * block regardless of language tag and returns its trimmed contents.
10
+ *
11
+ * Returns the trimmed original text unchanged when no fence is present, so
12
+ * clean JSON passes through as a no-op.
13
+ *
14
+ * Deliberately does NOT fall back to "find first `{` and last `}` and slice
15
+ * between them" — that heuristic silently corrupts data when prose contains
16
+ * stray braces. Failing loudly at `JSON.parse` is safer.
17
+ *
18
+ * @example
19
+ * extractJsonPayload('```json\n{"a":1}\n```');
20
+ * // => '{"a":1}'
21
+ *
22
+ * @example
23
+ * extractJsonPayload('Here you go:\n```\n{"a":1}\n```\nHope this helps.');
24
+ * // => '{"a":1}'
25
+ *
26
+ * @example
27
+ * extractJsonPayload('{"a":1}');
28
+ * // => '{"a":1}' (no fence → unchanged)
29
+ */
30
+ function extractJsonPayload(text) {
31
+ const trimmed = text.trim();
32
+ const fenceMatch = trimmed.match(/```(?:json)?\s*\n?([\s\S]*?)\n?```/);
33
+ if (fenceMatch) return fenceMatch[1].trim();
34
+ return trimmed;
35
+ }
36
+
37
+ //#endregion
38
+ export { extractJsonPayload };
39
+ //# sourceMappingURL=extract-json-payload.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extract-json-payload.mjs","names":[],"sources":["../../../../../../../../../@warlock.js/ai/src/utils/extract-json-payload.ts"],"sourcesContent":["/**\n * Strip markdown code fences from an LLM response before JSON parsing.\n *\n * Models — especially Claude, smaller models, and local models — routinely\n * wrap JSON output in fenced code blocks (` ```json\\n{...}\\n``` `) even when\n * instructed otherwise. Sometimes they also precede the fence with prose\n * (\"Here you go:\\n```json\\n...\\n```\"). This helper finds the first fenced\n * block regardless of language tag and returns its trimmed contents.\n *\n * Returns the trimmed original text unchanged when no fence is present, so\n * clean JSON passes through as a no-op.\n *\n * Deliberately does NOT fall back to \"find first `{` and last `}` and slice\n * between them\" — that heuristic silently corrupts data when prose contains\n * stray braces. Failing loudly at `JSON.parse` is safer.\n *\n * @example\n * extractJsonPayload('```json\\n{\"a\":1}\\n```');\n * // => '{\"a\":1}'\n *\n * @example\n * extractJsonPayload('Here you go:\\n```\\n{\"a\":1}\\n```\\nHope this helps.');\n * // => '{\"a\":1}'\n *\n * @example\n * extractJsonPayload('{\"a\":1}');\n * // => '{\"a\":1}' (no fence → unchanged)\n */\nexport function extractJsonPayload(text: string): string {\n const trimmed = text.trim();\n\n const fenceMatch = trimmed.match(/```(?:json)?\\s*\\n?([\\s\\S]*?)\\n?```/);\n\n if (fenceMatch) {\n return fenceMatch[1].trim();\n }\n\n return trimmed;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,SAAgB,mBAAmB,MAAsB;CACvD,MAAM,UAAU,KAAK,KAAK;CAE1B,MAAM,aAAa,QAAQ,MAAM,oCAAoC;CAErE,IAAI,YACF,OAAO,WAAW,EAAE,CAAC,KAAK;CAG5B,OAAO;AACT"}
@@ -0,0 +1,23 @@
1
+ //#region ../@warlock.js/ai/src/utils/generate-run-id.ts
2
+ /**
3
+ * Generates a stable, human-readable run id for any execution node
4
+ * (tool invocation, agent run, workflow run, supervisor run). Format:
5
+ * `${prefix}_${timestamp36}_${random36}` — compact, sortable by
6
+ * prefix, collision-resistant within a run.
7
+ *
8
+ * Shared helper so every primitive emits the same id shape. The
9
+ * prefix is conventionally the primitive kind (`"tool"`, `"agent"`,
10
+ * `"workflow"`, `"sup"`) but callers can pass anything; the id is
11
+ * purely for correlation, never parsed.
12
+ *
13
+ * @example
14
+ * const runId = generateRunId("tool");
15
+ * // → "tool_ld8x3m_7fq2j1kp"
16
+ */
17
+ function generateRunId(prefix) {
18
+ return `${prefix}_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 10)}`;
19
+ }
20
+
21
+ //#endregion
22
+ export { generateRunId };
23
+ //# sourceMappingURL=generate-run-id.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-run-id.mjs","names":[],"sources":["../../../../../../../../../@warlock.js/ai/src/utils/generate-run-id.ts"],"sourcesContent":["/**\n * Generates a stable, human-readable run id for any execution node\n * (tool invocation, agent run, workflow run, supervisor run). Format:\n * `${prefix}_${timestamp36}_${random36}` — compact, sortable by\n * prefix, collision-resistant within a run.\n *\n * Shared helper so every primitive emits the same id shape. The\n * prefix is conventionally the primitive kind (`\"tool\"`, `\"agent\"`,\n * `\"workflow\"`, `\"sup\"`) but callers can pass anything; the id is\n * purely for correlation, never parsed.\n *\n * @example\n * const runId = generateRunId(\"tool\");\n * // → \"tool_ld8x3m_7fq2j1kp\"\n */\nexport function generateRunId(prefix: string): string {\n return `${prefix}_${Date.now().toString(36)}_${Math.random()\n .toString(36)\n .slice(2, 10)}`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAeA,SAAgB,cAAc,QAAwB;CACpD,OAAO,GAAG,OAAO,GAAG,KAAK,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,GAAG,KAAK,OAAO,CAAC,CACzD,SAAS,EAAE,CAAC,CACZ,MAAM,GAAG,EAAE;AAChB"}