@warlock.js/ai 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 (535) hide show
  1. package/CHANGELOG.md +52 -55
  2. package/cjs/index.cjs +221 -14147
  3. package/cjs/src-C02yzsLs.cjs +22991 -0
  4. package/cjs/src-C02yzsLs.cjs.map +1 -0
  5. package/cjs/src-DFibP2FQ.cjs +30 -0
  6. package/esm/agent/agent-config.type.d.mts +90 -1
  7. package/esm/agent/agent-config.type.d.mts.map +1 -1
  8. package/esm/agent/agent-input-builder.mjs +27 -6
  9. package/esm/agent/agent-input-builder.mjs.map +1 -1
  10. package/esm/agent/agent.d.mts +40 -1
  11. package/esm/agent/agent.d.mts.map +1 -1
  12. package/esm/agent/agent.mjs +203 -30
  13. package/esm/agent/agent.mjs.map +1 -1
  14. package/esm/agent/index.d.mts +2 -1
  15. package/esm/agent/index.mjs +1 -0
  16. package/esm/agent/judge-config.type.d.mts +33 -0
  17. package/esm/agent/judge-config.type.d.mts.map +1 -0
  18. package/esm/agent/judge-config.type.mjs +13 -0
  19. package/esm/agent/judge-config.type.mjs.map +1 -0
  20. package/esm/ai-openai/src/embedder.mjs +4 -0
  21. package/esm/ai-openai/src/index.mjs +4 -0
  22. package/esm/ai-openai/src/model.mjs +5 -0
  23. package/esm/ai-openai/src/sdk.mjs +6 -0
  24. package/esm/ai-openai/src/utils/index.mjs +4 -0
  25. package/esm/ai-openai/src/utils/to-openai-tools.mjs +3 -0
  26. package/esm/ai-openai/src/utils/wrap-openai-error.mjs +4 -0
  27. package/esm/ai.d.mts +119 -53
  28. package/esm/ai.d.mts.map +1 -1
  29. package/esm/ai.mjs +43 -8
  30. package/esm/ai.mjs.map +1 -1
  31. package/esm/batch/batch.d.mts.map +1 -1
  32. package/esm/batch/batch.mjs +21 -1
  33. package/esm/batch/batch.mjs.map +1 -1
  34. package/esm/batch/batch.type.d.mts +11 -4
  35. package/esm/batch/batch.type.d.mts.map +1 -1
  36. package/esm/config.d.mts +39 -3
  37. package/esm/config.d.mts.map +1 -1
  38. package/esm/config.mjs +26 -2
  39. package/esm/config.mjs.map +1 -1
  40. package/esm/contracts/agent/agent-options.type.d.mts +11 -3
  41. package/esm/contracts/agent/agent-options.type.d.mts.map +1 -1
  42. package/esm/contracts/agent/eval.type.d.mts +43 -2
  43. package/esm/contracts/agent/eval.type.d.mts.map +1 -1
  44. package/esm/contracts/attachment-policy.type.d.mts +51 -0
  45. package/esm/contracts/attachment-policy.type.d.mts.map +1 -0
  46. package/esm/contracts/attachment.type.d.mts +16 -7
  47. package/esm/contracts/attachment.type.d.mts.map +1 -1
  48. package/esm/contracts/content-part.type.d.mts +14 -5
  49. package/esm/contracts/content-part.type.d.mts.map +1 -1
  50. package/esm/contracts/events/supervisor-events.type.d.mts.map +1 -1
  51. package/esm/contracts/index.d.mts +6 -4
  52. package/esm/contracts/model.contract.d.mts +11 -8
  53. package/esm/contracts/model.contract.d.mts.map +1 -1
  54. package/esm/contracts/orchestrator/index.d.mts +1 -0
  55. package/esm/contracts/orchestrator/orchestrator-config.type.d.mts +31 -2
  56. package/esm/contracts/orchestrator/orchestrator-config.type.d.mts.map +1 -1
  57. package/esm/contracts/orchestrator/session-lock.contract.d.mts +47 -0
  58. package/esm/contracts/orchestrator/session-lock.contract.d.mts.map +1 -0
  59. package/esm/contracts/planner/index.d.mts +1 -1
  60. package/esm/contracts/planner/planner-config.type.d.mts +31 -0
  61. package/esm/contracts/planner/planner-config.type.d.mts.map +1 -1
  62. package/esm/contracts/planner/planner-execute-options.type.d.mts +48 -1
  63. package/esm/contracts/planner/planner-execute-options.type.d.mts.map +1 -1
  64. package/esm/contracts/planner/planner-result.type.d.mts +8 -0
  65. package/esm/contracts/planner/planner-result.type.d.mts.map +1 -1
  66. package/esm/contracts/planner/planner.contract.d.mts +1 -1
  67. package/esm/contracts/result/agent-result.type.d.mts +6 -4
  68. package/esm/contracts/result/agent-result.type.d.mts.map +1 -1
  69. package/esm/contracts/result/base-report.type.d.mts +21 -3
  70. package/esm/contracts/result/base-report.type.d.mts.map +1 -1
  71. package/esm/contracts/result/base-report.type.mjs.map +1 -1
  72. package/esm/contracts/result/execution-report.type.d.mts +53 -1
  73. package/esm/contracts/result/execution-report.type.d.mts.map +1 -1
  74. package/esm/contracts/result/supervisor-result.type.d.mts +14 -2
  75. package/esm/contracts/result/supervisor-result.type.d.mts.map +1 -1
  76. package/esm/contracts/result/workflow-result.type.d.mts +2 -1
  77. package/esm/contracts/result/workflow-result.type.d.mts.map +1 -1
  78. package/esm/contracts/supervisor/supervisor-config.type.d.mts +29 -0
  79. package/esm/contracts/supervisor/supervisor-config.type.d.mts.map +1 -1
  80. package/esm/contracts/system-prompt.contract.d.mts +103 -1
  81. package/esm/contracts/system-prompt.contract.d.mts.map +1 -1
  82. package/esm/contracts/team/index.d.mts +1 -0
  83. package/esm/contracts/team/team-config.type.d.mts +127 -0
  84. package/esm/contracts/team/team-config.type.d.mts.map +1 -0
  85. package/esm/contracts/tool.contract.d.mts +4 -2
  86. package/esm/contracts/tool.contract.d.mts.map +1 -1
  87. package/esm/contracts/workflow/step.contract.d.mts +30 -5
  88. package/esm/contracts/workflow/step.contract.d.mts.map +1 -1
  89. package/esm/contracts/workflow/workflow.contract.d.mts +16 -0
  90. package/esm/contracts/workflow/workflow.contract.d.mts.map +1 -1
  91. package/esm/errors/error-code.type.d.mts +1 -1
  92. package/esm/errors/index.d.mts +1 -0
  93. package/esm/errors/index.mjs +1 -0
  94. package/esm/errors/outbound-policy-error.d.mts +27 -0
  95. package/esm/errors/outbound-policy-error.d.mts.map +1 -0
  96. package/esm/errors/outbound-policy-error.mjs +32 -0
  97. package/esm/errors/outbound-policy-error.mjs.map +1 -0
  98. package/esm/eval/dataset.d.mts +28 -0
  99. package/esm/eval/dataset.d.mts.map +1 -0
  100. package/esm/eval/dataset.mjs +112 -0
  101. package/esm/eval/dataset.mjs.map +1 -0
  102. package/esm/eval/dataset.type.d.mts +53 -0
  103. package/esm/eval/dataset.type.d.mts.map +1 -0
  104. package/esm/eval/eval-runner.d.mts.map +1 -1
  105. package/esm/eval/eval-runner.mjs +16 -2
  106. package/esm/eval/eval-runner.mjs.map +1 -1
  107. package/esm/eval/index.d.mts +20 -1
  108. package/esm/eval/index.d.mts.map +1 -1
  109. package/esm/eval/index.mjs +20 -2
  110. package/esm/eval/index.mjs.map +1 -1
  111. package/esm/eval/regression.d.mts +30 -0
  112. package/esm/eval/regression.d.mts.map +1 -0
  113. package/esm/eval/regression.mjs +51 -0
  114. package/esm/eval/regression.mjs.map +1 -0
  115. package/esm/eval/report-json.d.mts +30 -0
  116. package/esm/eval/report-json.d.mts.map +1 -0
  117. package/esm/eval/report-json.mjs +33 -0
  118. package/esm/eval/report-json.mjs.map +1 -0
  119. package/esm/eval/report-junit.d.mts +22 -0
  120. package/esm/eval/report-junit.d.mts.map +1 -0
  121. package/esm/eval/report-junit.mjs +60 -0
  122. package/esm/eval/report-junit.mjs.map +1 -0
  123. package/esm/guard/contracts/guard-options.type.d.mts +165 -0
  124. package/esm/guard/contracts/guard-options.type.d.mts.map +1 -0
  125. package/esm/guard/contracts/guardrail.contract.d.mts +78 -0
  126. package/esm/guard/contracts/guardrail.contract.d.mts.map +1 -0
  127. package/esm/guard/contracts/index.d.mts +4 -0
  128. package/esm/guard/contracts/openai-client.contract.d.mts +51 -0
  129. package/esm/guard/contracts/openai-client.contract.d.mts.map +1 -0
  130. package/esm/guard/contracts/verdict.type.d.mts +76 -0
  131. package/esm/guard/contracts/verdict.type.d.mts.map +1 -0
  132. package/esm/guard/detectors/index.d.mts +4 -0
  133. package/esm/guard/detectors/index.mjs +6 -0
  134. package/esm/guard/detectors/injection.d.mts +34 -0
  135. package/esm/guard/detectors/injection.d.mts.map +1 -0
  136. package/esm/guard/detectors/injection.mjs +254 -0
  137. package/esm/guard/detectors/injection.mjs.map +1 -0
  138. package/esm/guard/detectors/moderation.d.mts +32 -0
  139. package/esm/guard/detectors/moderation.d.mts.map +1 -0
  140. package/esm/guard/detectors/moderation.mjs +134 -0
  141. package/esm/guard/detectors/moderation.mjs.map +1 -0
  142. package/esm/guard/detectors/pii.d.mts +41 -0
  143. package/esm/guard/detectors/pii.d.mts.map +1 -0
  144. package/esm/guard/detectors/pii.mjs +199 -0
  145. package/esm/guard/detectors/pii.mjs.map +1 -0
  146. package/esm/guard/detectors/topic.d.mts +29 -0
  147. package/esm/guard/detectors/topic.d.mts.map +1 -0
  148. package/esm/guard/detectors/topic.mjs +99 -0
  149. package/esm/guard/detectors/topic.mjs.map +1 -0
  150. package/esm/guard/errors.d.mts +12 -0
  151. package/esm/guard/errors.d.mts.map +1 -0
  152. package/esm/guard/errors.mjs +18 -0
  153. package/esm/guard/errors.mjs.map +1 -0
  154. package/esm/guard/guard.d.mts +67 -0
  155. package/esm/guard/guard.d.mts.map +1 -0
  156. package/esm/guard/guard.mjs +209 -0
  157. package/esm/guard/guard.mjs.map +1 -0
  158. package/esm/guard/guardrail.d.mts +39 -0
  159. package/esm/guard/guardrail.d.mts.map +1 -0
  160. package/esm/guard/guardrail.mjs +22 -0
  161. package/esm/guard/guardrail.mjs.map +1 -0
  162. package/esm/human/contracts/approval.type.d.mts +154 -0
  163. package/esm/human/contracts/approval.type.d.mts.map +1 -0
  164. package/esm/human/contracts/human-approval.type.d.mts +38 -0
  165. package/esm/human/contracts/human-approval.type.d.mts.map +1 -0
  166. package/esm/human/contracts/index.d.mts +4 -0
  167. package/esm/human/contracts/interrupt-store.contract.d.mts +112 -0
  168. package/esm/human/contracts/interrupt-store.contract.d.mts.map +1 -0
  169. package/esm/human/contracts/resume.type.d.mts +77 -0
  170. package/esm/human/contracts/resume.type.d.mts.map +1 -0
  171. package/esm/human/errors.d.mts +84 -0
  172. package/esm/human/errors.d.mts.map +1 -0
  173. package/esm/human/errors.mjs +60 -0
  174. package/esm/human/errors.mjs.map +1 -0
  175. package/esm/human/human-approval.d.mts +57 -0
  176. package/esm/human/human-approval.d.mts.map +1 -0
  177. package/esm/human/human-approval.mjs +170 -0
  178. package/esm/human/human-approval.mjs.map +1 -0
  179. package/esm/human/policy.d.mts +55 -0
  180. package/esm/human/policy.d.mts.map +1 -0
  181. package/esm/human/policy.mjs +67 -0
  182. package/esm/human/policy.mjs.map +1 -0
  183. package/esm/human/register.mjs +37 -0
  184. package/esm/human/register.mjs.map +1 -0
  185. package/esm/human/resume-seed.mjs +53 -0
  186. package/esm/human/resume-seed.mjs.map +1 -0
  187. package/esm/human/resume.d.mts +54 -0
  188. package/esm/human/resume.d.mts.map +1 -0
  189. package/esm/human/resume.mjs +121 -0
  190. package/esm/human/resume.mjs.map +1 -0
  191. package/esm/human/stores/index.mjs +5 -0
  192. package/esm/human/stores/memory.d.mts +30 -0
  193. package/esm/human/stores/memory.d.mts.map +1 -0
  194. package/esm/human/stores/memory.mjs +91 -0
  195. package/esm/human/stores/memory.mjs.map +1 -0
  196. package/esm/human/stores/pg.d.mts +59 -0
  197. package/esm/human/stores/pg.d.mts.map +1 -0
  198. package/esm/human/stores/pg.mjs +220 -0
  199. package/esm/human/stores/pg.mjs.map +1 -0
  200. package/esm/human/stores/redis.d.mts +56 -0
  201. package/esm/human/stores/redis.d.mts.map +1 -0
  202. package/esm/human/stores/redis.mjs +201 -0
  203. package/esm/human/stores/redis.mjs.map +1 -0
  204. package/esm/index.d.mts +113 -22
  205. package/esm/index.mjs +82 -11
  206. package/esm/middleware/builtins/budget.mjs +6 -2
  207. package/esm/middleware/builtins/budget.mjs.map +1 -1
  208. package/esm/middleware/utils/extract-user-text.d.mts +8 -1
  209. package/esm/middleware/utils/extract-user-text.d.mts.map +1 -1
  210. package/esm/middleware/utils/extract-user-text.mjs +8 -1
  211. package/esm/middleware/utils/extract-user-text.mjs.map +1 -1
  212. package/esm/object-stream/index.d.mts +2 -0
  213. package/esm/object-stream/index.mjs +4 -0
  214. package/esm/object-stream/parse-partial-json.d.mts +22 -0
  215. package/esm/object-stream/parse-partial-json.d.mts.map +1 -0
  216. package/esm/object-stream/parse-partial-json.mjs +78 -0
  217. package/esm/object-stream/parse-partial-json.mjs.map +1 -0
  218. package/esm/object-stream/stream-object.d.mts +68 -0
  219. package/esm/object-stream/stream-object.d.mts.map +1 -0
  220. package/esm/object-stream/stream-object.mjs +104 -0
  221. package/esm/object-stream/stream-object.mjs.map +1 -0
  222. package/esm/observe/index.mjs +4 -0
  223. package/esm/observe/observer-registry.d.mts +30 -0
  224. package/esm/observe/observer-registry.d.mts.map +1 -0
  225. package/esm/observe/observer-registry.mjs +51 -0
  226. package/esm/observe/observer-registry.mjs.map +1 -0
  227. package/esm/observe/observer.contract.d.mts +40 -0
  228. package/esm/observe/observer.contract.d.mts.map +1 -0
  229. package/esm/observe/resolve-observers.d.mts +40 -0
  230. package/esm/observe/resolve-observers.d.mts.map +1 -0
  231. package/esm/observe/resolve-observers.mjs +73 -0
  232. package/esm/observe/resolve-observers.mjs.map +1 -0
  233. package/esm/orchestrator/execution.d.mts.map +1 -1
  234. package/esm/orchestrator/execution.mjs +5 -2
  235. package/esm/orchestrator/execution.mjs.map +1 -1
  236. package/esm/orchestrator/index.d.mts +1 -0
  237. package/esm/orchestrator/index.mjs +1 -0
  238. package/esm/orchestrator/orchestrator.d.mts.map +1 -1
  239. package/esm/orchestrator/orchestrator.mjs +39 -6
  240. package/esm/orchestrator/orchestrator.mjs.map +1 -1
  241. package/esm/orchestrator/session-lock.d.mts +25 -0
  242. package/esm/orchestrator/session-lock.d.mts.map +1 -0
  243. package/esm/orchestrator/session-lock.mjs +83 -0
  244. package/esm/orchestrator/session-lock.mjs.map +1 -0
  245. package/esm/planner/dag-scheduler.mjs +97 -0
  246. package/esm/planner/dag-scheduler.mjs.map +1 -0
  247. package/esm/planner/plan-prompt.d.mts +1 -1
  248. package/esm/planner/plan-prompt.d.mts.map +1 -1
  249. package/esm/planner/plan-prompt.mjs +2 -1
  250. package/esm/planner/plan-prompt.mjs.map +1 -1
  251. package/esm/planner/planner-run.d.mts.map +1 -1
  252. package/esm/planner/planner-run.mjs +300 -29
  253. package/esm/planner/planner-run.mjs.map +1 -1
  254. package/esm/planner/planner.mjs +1 -1
  255. package/esm/planner/planner.mjs.map +1 -1
  256. package/esm/prompt/errors.d.mts +57 -0
  257. package/esm/prompt/errors.d.mts.map +1 -0
  258. package/esm/prompt/errors.mjs +73 -0
  259. package/esm/prompt/errors.mjs.map +1 -0
  260. package/esm/prompt/index.d.mts +3 -0
  261. package/esm/prompt/index.mjs +4 -0
  262. package/esm/prompt/prompt-langfuse-sync.mjs +104 -0
  263. package/esm/prompt/prompt-langfuse-sync.mjs.map +1 -0
  264. package/esm/prompt/prompt-langfuse-sync.type.d.mts +32 -0
  265. package/esm/prompt/prompt-langfuse-sync.type.d.mts.map +1 -0
  266. package/esm/prompt/prompt-validate.mjs +170 -0
  267. package/esm/prompt/prompt-validate.mjs.map +1 -0
  268. package/esm/prompt/prompt.d.mts +54 -0
  269. package/esm/prompt/prompt.d.mts.map +1 -0
  270. package/esm/prompt/prompt.mjs +218 -0
  271. package/esm/prompt/prompt.mjs.map +1 -0
  272. package/esm/prompt/prompt.type.d.mts +174 -0
  273. package/esm/prompt/prompt.type.d.mts.map +1 -0
  274. package/esm/prompts/index.d.mts +3 -0
  275. package/esm/prompts/index.mjs +3 -0
  276. package/esm/prompts/prompts-manager.contract.d.mts +154 -0
  277. package/esm/prompts/prompts-manager.contract.d.mts.map +1 -0
  278. package/esm/prompts/prompts-manager.d.mts +38 -0
  279. package/esm/prompts/prompts-manager.d.mts.map +1 -0
  280. package/esm/prompts/prompts-manager.mjs +410 -0
  281. package/esm/prompts/prompts-manager.mjs.map +1 -0
  282. package/esm/prompts/prompts-manager.type.d.mts +172 -0
  283. package/esm/prompts/prompts-manager.type.d.mts.map +1 -0
  284. package/esm/prompts/prompts-validate.mjs +200 -0
  285. package/esm/prompts/prompts-validate.mjs.map +1 -0
  286. package/esm/rag/as-tool.mjs +48 -0
  287. package/esm/rag/as-tool.mjs.map +1 -0
  288. package/esm/rag/chunk/chunk.d.mts +24 -0
  289. package/esm/rag/chunk/chunk.d.mts.map +1 -0
  290. package/esm/rag/chunk/chunk.mjs +44 -0
  291. package/esm/rag/chunk/chunk.mjs.map +1 -0
  292. package/esm/rag/chunk/fixed.mjs +32 -0
  293. package/esm/rag/chunk/fixed.mjs.map +1 -0
  294. package/esm/rag/chunk/markdown.mjs +75 -0
  295. package/esm/rag/chunk/markdown.mjs.map +1 -0
  296. package/esm/rag/chunk/recursive.mjs +132 -0
  297. package/esm/rag/chunk/recursive.mjs.map +1 -0
  298. package/esm/rag/chunk/sentence.mjs +73 -0
  299. package/esm/rag/chunk/sentence.mjs.map +1 -0
  300. package/esm/rag/contracts/chunk-options.type.d.mts +35 -0
  301. package/esm/rag/contracts/chunk-options.type.d.mts.map +1 -0
  302. package/esm/rag/contracts/citation.type.d.mts +35 -0
  303. package/esm/rag/contracts/citation.type.d.mts.map +1 -0
  304. package/esm/rag/contracts/index.d.mts +4 -0
  305. package/esm/rag/contracts/rag-config.type.d.mts +68 -0
  306. package/esm/rag/contracts/rag-config.type.d.mts.map +1 -0
  307. package/esm/rag/contracts/rag-document.type.d.mts +21 -0
  308. package/esm/rag/contracts/rag-document.type.d.mts.map +1 -0
  309. package/esm/rag/hybrid/bm25.d.mts +23 -0
  310. package/esm/rag/hybrid/bm25.d.mts.map +1 -0
  311. package/esm/rag/hybrid/bm25.mjs +51 -0
  312. package/esm/rag/hybrid/bm25.mjs.map +1 -0
  313. package/esm/rag/hybrid/hybrid-rank.d.mts +33 -0
  314. package/esm/rag/hybrid/hybrid-rank.d.mts.map +1 -0
  315. package/esm/rag/hybrid/hybrid-rank.mjs +29 -0
  316. package/esm/rag/hybrid/hybrid-rank.mjs.map +1 -0
  317. package/esm/rag/hybrid/rrf.d.mts +25 -0
  318. package/esm/rag/hybrid/rrf.d.mts.map +1 -0
  319. package/esm/rag/hybrid/rrf.mjs +30 -0
  320. package/esm/rag/hybrid/rrf.mjs.map +1 -0
  321. package/esm/rag/index.d.mts +15 -0
  322. package/esm/rag/index.mjs +11 -0
  323. package/esm/rag/rag.d.mts +38 -0
  324. package/esm/rag/rag.d.mts.map +1 -0
  325. package/esm/rag/rag.mjs +126 -0
  326. package/esm/rag/rag.mjs.map +1 -0
  327. package/esm/rag/rerank/keyword-reranker.d.mts +32 -0
  328. package/esm/rag/rerank/keyword-reranker.d.mts.map +1 -0
  329. package/esm/rag/rerank/keyword-reranker.mjs +58 -0
  330. package/esm/rag/rerank/keyword-reranker.mjs.map +1 -0
  331. package/esm/rag/rerank/llm-reranker.d.mts +36 -0
  332. package/esm/rag/rerank/llm-reranker.d.mts.map +1 -0
  333. package/esm/rag/rerank/llm-reranker.mjs +85 -0
  334. package/esm/rag/rerank/llm-reranker.mjs.map +1 -0
  335. package/esm/rag/rerank/reranker.contract.d.mts +28 -0
  336. package/esm/rag/rerank/reranker.contract.d.mts.map +1 -0
  337. package/esm/rag/retrieve.mjs +68 -0
  338. package/esm/rag/retrieve.mjs.map +1 -0
  339. package/esm/rag/store/cache-vector-store.d.mts +27 -0
  340. package/esm/rag/store/cache-vector-store.d.mts.map +1 -0
  341. package/esm/rag/store/cache-vector-store.mjs +48 -0
  342. package/esm/rag/store/cache-vector-store.mjs.map +1 -0
  343. package/esm/rag/store/vector-store.contract.d.mts +38 -0
  344. package/esm/rag/store/vector-store.contract.d.mts.map +1 -0
  345. package/esm/rag/transforms/multi-query.d.mts +27 -0
  346. package/esm/rag/transforms/multi-query.d.mts.map +1 -0
  347. package/esm/rag/transforms/multi-query.mjs +41 -0
  348. package/esm/rag/transforms/multi-query.mjs.map +1 -0
  349. package/esm/security/index.mjs +5 -0
  350. package/esm/security/outbound-policy.d.mts +46 -0
  351. package/esm/security/outbound-policy.d.mts.map +1 -0
  352. package/esm/security/outbound-policy.mjs +187 -0
  353. package/esm/security/outbound-policy.mjs.map +1 -0
  354. package/esm/security/outbound-policy.type.d.mts +74 -0
  355. package/esm/security/outbound-policy.type.d.mts.map +1 -0
  356. package/esm/security/private-ip.d.mts +15 -0
  357. package/esm/security/private-ip.d.mts.map +1 -0
  358. package/esm/security/private-ip.mjs +48 -0
  359. package/esm/security/private-ip.mjs.map +1 -0
  360. package/esm/security/redact.d.mts +59 -0
  361. package/esm/security/redact.d.mts.map +1 -0
  362. package/esm/security/redact.mjs +122 -0
  363. package/esm/security/redact.mjs.map +1 -0
  364. package/esm/serve/serve.d.mts +50 -0
  365. package/esm/serve/serve.d.mts.map +1 -0
  366. package/esm/serve/serve.mjs +90 -0
  367. package/esm/serve/serve.mjs.map +1 -0
  368. package/esm/serve/sse.d.mts +20 -0
  369. package/esm/serve/sse.d.mts.map +1 -0
  370. package/esm/serve/sse.mjs +25 -0
  371. package/esm/serve/sse.mjs.map +1 -0
  372. package/esm/serve/stream-to-sse.d.mts +29 -0
  373. package/esm/serve/stream-to-sse.d.mts.map +1 -0
  374. package/esm/serve/stream-to-sse.mjs +37 -0
  375. package/esm/serve/stream-to-sse.mjs.map +1 -0
  376. package/esm/skills/catalog.d.mts +49 -0
  377. package/esm/skills/catalog.d.mts.map +1 -0
  378. package/esm/skills/catalog.mjs +140 -0
  379. package/esm/skills/catalog.mjs.map +1 -0
  380. package/esm/skills/contracts/skill-record.type.d.mts +37 -0
  381. package/esm/skills/contracts/skill-record.type.d.mts.map +1 -0
  382. package/esm/skills/contracts/skills-config.type.d.mts +108 -0
  383. package/esm/skills/contracts/skills-config.type.d.mts.map +1 -0
  384. package/esm/skills/contracts/skills-store.contract.d.mts +28 -0
  385. package/esm/skills/contracts/skills-store.contract.d.mts.map +1 -0
  386. package/esm/skills/contracts/skills.contract.d.mts +43 -0
  387. package/esm/skills/contracts/skills.contract.d.mts.map +1 -0
  388. package/esm/skills/index.d.mts +16 -0
  389. package/esm/skills/index.mjs +14 -0
  390. package/esm/skills/load-skill-tool.d.mts +38 -0
  391. package/esm/skills/load-skill-tool.d.mts.map +1 -0
  392. package/esm/skills/load-skill-tool.mjs +65 -0
  393. package/esm/skills/load-skill-tool.mjs.map +1 -0
  394. package/esm/skills/review-gate.d.mts +33 -0
  395. package/esm/skills/review-gate.d.mts.map +1 -0
  396. package/esm/skills/review-gate.mjs +60 -0
  397. package/esm/skills/review-gate.mjs.map +1 -0
  398. package/esm/skills/save-skill-tool.d.mts +39 -0
  399. package/esm/skills/save-skill-tool.d.mts.map +1 -0
  400. package/esm/skills/save-skill-tool.mjs +65 -0
  401. package/esm/skills/save-skill-tool.mjs.map +1 -0
  402. package/esm/skills/skills.d.mts +33 -0
  403. package/esm/skills/skills.d.mts.map +1 -0
  404. package/esm/skills/skills.mjs +109 -0
  405. package/esm/skills/skills.mjs.map +1 -0
  406. package/esm/skills/sources/directory-source.d.mts +19 -0
  407. package/esm/skills/sources/directory-source.d.mts.map +1 -0
  408. package/esm/skills/sources/directory-source.mjs +108 -0
  409. package/esm/skills/sources/directory-source.mjs.map +1 -0
  410. package/esm/skills/sources/index.d.mts +18 -0
  411. package/esm/skills/sources/index.d.mts.map +1 -0
  412. package/esm/skills/sources/index.mjs +27 -0
  413. package/esm/skills/sources/index.mjs.map +1 -0
  414. package/esm/skills/sources/parse-frontmatter.d.mts +27 -0
  415. package/esm/skills/sources/parse-frontmatter.d.mts.map +1 -0
  416. package/esm/skills/sources/parse-frontmatter.mjs +46 -0
  417. package/esm/skills/sources/parse-frontmatter.mjs.map +1 -0
  418. package/esm/skills/sources/store-source.d.mts +14 -0
  419. package/esm/skills/sources/store-source.d.mts.map +1 -0
  420. package/esm/skills/sources/store-source.mjs +15 -0
  421. package/esm/skills/sources/store-source.mjs.map +1 -0
  422. package/esm/skills/sources/url-source.d.mts +29 -0
  423. package/esm/skills/sources/url-source.d.mts.map +1 -0
  424. package/esm/skills/sources/url-source.mjs +117 -0
  425. package/esm/skills/sources/url-source.mjs.map +1 -0
  426. package/esm/skills/store/mock-skills-store.d.mts +57 -0
  427. package/esm/skills/store/mock-skills-store.d.mts.map +1 -0
  428. package/esm/skills/store/mock-skills-store.mjs +100 -0
  429. package/esm/skills/store/mock-skills-store.mjs.map +1 -0
  430. package/esm/skills/store/procedural-skill-store.d.mts +30 -0
  431. package/esm/skills/store/procedural-skill-store.d.mts.map +1 -0
  432. package/esm/skills/store/procedural-skill-store.mjs +125 -0
  433. package/esm/skills/store/procedural-skill-store.mjs.map +1 -0
  434. package/esm/supervisor/as-tool.mjs +2 -2
  435. package/esm/supervisor/as-tool.mjs.map +1 -1
  436. package/esm/supervisor/execution.d.mts.map +1 -1
  437. package/esm/supervisor/execution.mjs +31 -28
  438. package/esm/supervisor/execution.mjs.map +1 -1
  439. package/esm/supervisor/supervisor.d.mts.map +1 -1
  440. package/esm/supervisor/supervisor.mjs +8 -3
  441. package/esm/supervisor/supervisor.mjs.map +1 -1
  442. package/esm/system-prompt/index.d.mts +4 -0
  443. package/esm/system-prompt/system-prompt.d.mts +68 -4
  444. package/esm/system-prompt/system-prompt.d.mts.map +1 -1
  445. package/esm/system-prompt/system-prompt.mjs +89 -5
  446. package/esm/system-prompt/system-prompt.mjs.map +1 -1
  447. package/esm/team/gates.mjs +48 -0
  448. package/esm/team/gates.mjs.map +1 -0
  449. package/esm/team/index.d.mts +1 -0
  450. package/esm/team/index.mjs +3 -0
  451. package/esm/team/team.d.mts +42 -0
  452. package/esm/team/team.d.mts.map +1 -0
  453. package/esm/team/team.mjs +94 -0
  454. package/esm/team/team.mjs.map +1 -0
  455. package/esm/tool/executable-as-tool.d.mts.map +1 -1
  456. package/esm/tool/executable-as-tool.mjs +2 -2
  457. package/esm/tool/executable-as-tool.mjs.map +1 -1
  458. package/esm/tool/tool.d.mts.map +1 -1
  459. package/esm/tool/tool.mjs +2 -2
  460. package/esm/tool/tool.mjs.map +1 -1
  461. package/esm/utils/compute-cost.d.mts +17 -1
  462. package/esm/utils/compute-cost.d.mts.map +1 -1
  463. package/esm/utils/compute-cost.mjs +26 -1
  464. package/esm/utils/compute-cost.mjs.map +1 -1
  465. package/esm/utils/extract-json-lenient.d.mts +42 -0
  466. package/esm/utils/extract-json-lenient.d.mts.map +1 -0
  467. package/esm/utils/extract-json-lenient.mjs +97 -0
  468. package/esm/utils/extract-json-lenient.mjs.map +1 -0
  469. package/esm/utils/index.d.mts +4 -2
  470. package/esm/utils/index.mjs +3 -1
  471. package/esm/utils/json-schema.d.mts +1 -1
  472. package/esm/utils/prepare-attachment-part.d.mts +10 -1
  473. package/esm/utils/prepare-attachment-part.d.mts.map +1 -1
  474. package/esm/utils/prepare-attachment-part.mjs +103 -11
  475. package/esm/utils/prepare-attachment-part.mjs.map +1 -1
  476. package/esm/utils/resolve-attachment.d.mts +4 -3
  477. package/esm/utils/resolve-attachment.d.mts.map +1 -1
  478. package/esm/utils/resolve-attachment.mjs +4 -3
  479. package/esm/utils/resolve-attachment.mjs.map +1 -1
  480. package/esm/utils/run-context.d.mts +94 -0
  481. package/esm/utils/run-context.d.mts.map +1 -0
  482. package/esm/utils/run-context.mjs +98 -0
  483. package/esm/utils/run-context.mjs.map +1 -0
  484. package/esm/vcr/cassette-io.mjs +57 -0
  485. package/esm/vcr/cassette-io.mjs.map +1 -0
  486. package/esm/vcr/errors.d.mts +42 -0
  487. package/esm/vcr/errors.d.mts.map +1 -0
  488. package/esm/vcr/errors.mjs +37 -0
  489. package/esm/vcr/errors.mjs.map +1 -0
  490. package/esm/vcr/hash-request.d.mts +28 -0
  491. package/esm/vcr/hash-request.d.mts.map +1 -0
  492. package/esm/vcr/hash-request.mjs +118 -0
  493. package/esm/vcr/hash-request.mjs.map +1 -0
  494. package/esm/vcr/index.d.mts +4 -0
  495. package/esm/vcr/index.mjs +5 -0
  496. package/esm/vcr/vcr.d.mts +32 -0
  497. package/esm/vcr/vcr.d.mts.map +1 -0
  498. package/esm/vcr/vcr.mjs +248 -0
  499. package/esm/vcr/vcr.mjs.map +1 -0
  500. package/esm/vcr/vcr.type.d.mts +118 -0
  501. package/esm/vcr/vcr.type.d.mts.map +1 -0
  502. package/esm/workflow/as-tool.mjs +2 -2
  503. package/esm/workflow/as-tool.mjs.map +1 -1
  504. package/esm/workflow/engine.mjs +1 -0
  505. package/esm/workflow/engine.mjs.map +1 -1
  506. package/esm/workflow/step-runner.mjs +19 -20
  507. package/esm/workflow/step-runner.mjs.map +1 -1
  508. package/esm/workflow/workflow.d.mts.map +1 -1
  509. package/esm/workflow/workflow.mjs +8 -3
  510. package/esm/workflow/workflow.mjs.map +1 -1
  511. package/llms-full.txt +1683 -68
  512. package/llms.txt +16 -4
  513. package/package.json +7 -3
  514. package/skills/README.md +40 -4
  515. package/skills/ai-dx-helpers/SKILL.md +2 -2
  516. package/skills/approve-tool-calls/SKILL.md +134 -0
  517. package/skills/attach-ai-middleware/SKILL.md +1 -1
  518. package/skills/detect-and-redact-pii/SKILL.md +104 -0
  519. package/skills/durable-resume/SKILL.md +128 -0
  520. package/skills/escalate-block-to-human/SKILL.md +85 -0
  521. package/skills/eval-datasets-and-ci/SKILL.md +117 -0
  522. package/skills/guard-input-output/SKILL.md +117 -0
  523. package/skills/manage-prompts/SKILL.md +186 -0
  524. package/skills/observe-ai-flows/SKILL.md +94 -0
  525. package/skills/record-replay-llm/SKILL.md +92 -0
  526. package/skills/run-ai-agent/SKILL.md +26 -1
  527. package/skills/run-ai-rag/SKILL.md +139 -0
  528. package/skills/run-ai-team/SKILL.md +107 -0
  529. package/skills/run-orchestrator/SKILL.md +2 -0
  530. package/skills/run-planner/SKILL.md +73 -8
  531. package/skills/run-supervisor/SKILL.md +20 -1
  532. package/skills/use-runtime-skills/SKILL.md +106 -0
  533. package/skills/write-system-prompt/SKILL.md +30 -1
  534. package/cjs/index.cjs.map +0 -1
  535. package/esm/contracts/result/index.d.mts +0 -15
package/esm/ai.d.mts CHANGED
@@ -2,16 +2,23 @@ import { tool } from "./tool/tool.mjs";
2
2
  import { agent } from "./agent/agent.mjs";
3
3
  import { budget, readBudgetFallbackSignal } from "./middleware/builtins/budget.mjs";
4
4
  import { spawnSubAgent } from "./agent/spawn-sub-agent.mjs";
5
- import { SystemPromptFactory } from "./system-prompt/system-prompt.mjs";
6
- import { judge } from "./eval/judge-scorer.mjs";
7
- import { contains, exact, predicate } from "./eval/scorers.mjs";
8
5
  import { batch } from "./batch/batch.mjs";
6
+ import { streamObject } from "./object-stream/stream-object.mjs";
7
+ import { serve } from "./serve/serve.mjs";
9
8
  import { memory } from "./checkpoint/memory.mjs";
10
9
  import { pg } from "./checkpoint/pg.mjs";
11
10
  import { redis } from "./checkpoint/redis.mjs";
12
11
  import { setAIConfig } from "./config.mjs";
13
- import { memory as memory$1 } from "./memory/memory.mjs";
14
- import { guardrail } from "./middleware/builtins/guardrail.mjs";
12
+ import { dataset } from "./eval/dataset.mjs";
13
+ import { evalScorers } from "./eval/index.mjs";
14
+ import { humanApproval } from "./human/human-approval.mjs";
15
+ import { resume } from "./human/resume.mjs";
16
+ import { memory as memory$1 } from "./human/stores/memory.mjs";
17
+ import { pg as pg$1 } from "./human/stores/pg.mjs";
18
+ import { redis as redis$1 } from "./human/stores/redis.mjs";
19
+ import { guardrail } from "./guard/guardrail.mjs";
20
+ import { memory as memory$2 } from "./memory/memory.mjs";
21
+ import { guardrail as guardrail$1 } from "./middleware/builtins/guardrail.mjs";
15
22
  import { semanticCache } from "./middleware/builtins/semantic-cache.mjs";
16
23
  import { composeMiddleware } from "./middleware/helpers/compose.mjs";
17
24
  import { forTool } from "./middleware/helpers/for-tool.mjs";
@@ -19,18 +26,117 @@ import { mockRouter } from "./mock/mock-router.mjs";
19
26
  import { fallbackModel } from "./model/fallback-model.mjs";
20
27
  import { orchestrator } from "./orchestrator/orchestrator.mjs";
21
28
  import { planner } from "./planner/planner.mjs";
22
- import { memory as memory$2 } from "./snapshot/memory.mjs";
23
- import { pg as pg$1 } from "./snapshot/pg.mjs";
24
- import { redis as redis$1 } from "./snapshot/redis.mjs";
29
+ import { defaultPromptsManager } from "./prompts/prompts-manager.mjs";
30
+ import { rag } from "./rag/rag.mjs";
31
+ import { keywordReranker } from "./rag/rerank/keyword-reranker.mjs";
32
+ import { llmReranker } from "./rag/rerank/llm-reranker.mjs";
33
+ import { skills } from "./skills/skills.mjs";
34
+ import { systemPrompt } from "./system-prompt/system-prompt.mjs";
35
+ import { prompt } from "./prompt/prompt.mjs";
36
+ import { vcr } from "./vcr/vcr.mjs";
37
+ import { memory as memory$3 } from "./snapshot/memory.mjs";
38
+ import { pg as pg$2 } from "./snapshot/pg.mjs";
39
+ import { redis as redis$2 } from "./snapshot/redis.mjs";
25
40
  import { fanOut } from "./supervisor/fan-out.mjs";
26
41
  import { router } from "./supervisor/router-factory.mjs";
27
42
  import { supervisor } from "./supervisor/supervisor.mjs";
43
+ import { team } from "./team/team.mjs";
28
44
  import { instruction } from "./system-prompt/instruction.mjs";
29
45
  import { persona } from "./system-prompt/persona.mjs";
30
46
  import { step } from "./workflow/step.mjs";
31
47
  import { workflow } from "./workflow/workflow.mjs";
32
48
 
33
49
  //#region ../@warlock.js/ai/src/ai.d.ts
50
+ /**
51
+ * The shape of the top-level `ai` namespace. Declared as an `interface` (not an
52
+ * inferred `const` type) so satellite packages can attach their verb via
53
+ * `declare module "@warlock.js/ai" { interface Ai { … } }` — e.g. `ai.workspace`,
54
+ * `ai.tools`, `ai.mcp`, `ai.human`. The runtime object below is asserted to this
55
+ * type; a satellite assigns its member on import.
56
+ */
57
+ interface Ai {
58
+ config: typeof setAIConfig;
59
+ tool: typeof tool;
60
+ agent: typeof agent;
61
+ systemPrompt: typeof systemPrompt;
62
+ persona: typeof persona;
63
+ instruction: typeof instruction;
64
+ workflow: typeof workflow;
65
+ step: typeof step;
66
+ supervisor: typeof supervisor;
67
+ team: typeof team;
68
+ orchestrator: typeof orchestrator;
69
+ memory: typeof memory$2;
70
+ skills: typeof skills;
71
+ planner: typeof planner;
72
+ rag: typeof rag & {
73
+ keywordReranker: typeof keywordReranker;
74
+ llmReranker: typeof llmReranker;
75
+ };
76
+ spawnSubAgent: typeof spawnSubAgent;
77
+ router: typeof router;
78
+ fanOut: typeof fanOut;
79
+ batch: typeof batch;
80
+ /** Structured-output streaming — partial-object snapshots + a strict final parse (A1). */
81
+ streamObject: typeof streamObject;
82
+ /** Serve an executable as an SSE HTTP endpoint — production serving primitive (A3). */
83
+ serve: typeof serve;
84
+ fallbackModel: typeof fallbackModel;
85
+ eval: typeof evalScorers;
86
+ dataset: typeof dataset;
87
+ prompt: typeof prompt;
88
+ /**
89
+ * Process-wide registry of named, versioned `systemPrompt(...)` builders,
90
+ * keyed by `name@version`. A `systemPrompt(input, { name })` (or any
91
+ * `.meta({ name })` rename) auto-registers here; `ai.prompts.get(name)` /
92
+ * `.resolve(name)` reads them back, and `systemPrompt().merge(name)` folds a
93
+ * registered prompt into a new one.
94
+ */
95
+ prompts: ReturnType<typeof defaultPromptsManager>;
96
+ vcr: typeof vcr;
97
+ mockRouter: typeof mockRouter;
98
+ middleware: {
99
+ budget: typeof budget;
100
+ guardrail: typeof guardrail$1;
101
+ semanticCache: typeof semanticCache;
102
+ compose: typeof composeMiddleware;
103
+ forTool: typeof forTool;
104
+ readBudgetFallbackSignal: typeof readBudgetFallbackSignal;
105
+ };
106
+ checkpoint: {
107
+ memory: typeof memory;
108
+ pg: typeof pg;
109
+ redis: typeof redis;
110
+ };
111
+ snapshot: {
112
+ memory: typeof memory$3;
113
+ pg: typeof pg$2;
114
+ redis: typeof redis$2;
115
+ };
116
+ /**
117
+ * Human-in-the-loop tool approval (interrupt / resume).
118
+ *
119
+ * - `human.approval(options)` — the `tool.before` approval-gate middleware.
120
+ * - `human.resume(id, decision, options)` — out-of-process durable resume.
121
+ * - `human.interrupt.{memory,pg,redis}()` — durable {@link InterruptStore}
122
+ * factories (memory ships real; pg/redis are lazy optional peers).
123
+ */
124
+ human: {
125
+ approval: typeof humanApproval;
126
+ resume: typeof resume;
127
+ interrupt: {
128
+ memory: typeof memory$1;
129
+ pg: typeof pg$1;
130
+ redis: typeof redis$1;
131
+ };
132
+ };
133
+ /**
134
+ * Content-intelligence guardrail. `ai.guardrail(options)` builds a composed
135
+ * input / output / tool middleware; `ai.guardrail.{pii,topic,injection,moderation}`
136
+ * are the built-in detector factories.
137
+ */
138
+ guardrail: typeof guardrail;
139
+ }
34
140
  /**
35
141
  * Top-level `ai` namespace — holds built-in factories and user-registered SDK adapters.
36
142
  *
@@ -42,6 +148,7 @@ import { workflow } from "./workflow/workflow.mjs";
42
148
  * - `ai.instruction(text)` — reusable instruction block (can be passed to `systemPrompt`).
43
149
  * - `ai.orchestrator(...)` — session-state manager wrapped around a supervisor (durable session, drift detection, resume, commands).
44
150
  * - `ai.memory(...)` — build an agent-memory store with WORKING (in-run scratch) and SEMANTIC (cache-driver `.similar()` recall) tiers.
151
+ * - `ai.skills(...)` — build a runtime skills library (always-injected metadata catalog + on-demand loadSkill tool).
45
152
  * - `ai.planner(...)` — build an executable that generates an ordered plan over registered capabilities, then runs it step-by-step.
46
153
  * - `ai.spawnSubAgent(spec)` — thin wrapper that builds a fresh one-shot `agent()` with an optional per-task `budget` and runs the task once. A general primitive (not planner-specific).
47
154
  * - `ai.router(...)` — build a supervisor-compatible routing agent from named intents.
@@ -52,6 +159,8 @@ import { workflow } from "./workflow/workflow.mjs";
52
159
  * - `ai.mockRouter(decisions, opts?)` — deterministic supervisor `route` callback for tests.
53
160
  * - `ai.checkpoint.{memory,pg,redis}()` — durable orchestrator session checkpoint stores.
54
161
  * - `ai.snapshot.{memory,pg,redis}()` — supervisor-run snapshot stores for `iterate: true` resume.
162
+ * - `ai.human.approval(...)` / `ai.human.resume(...)` / `ai.human.interrupt.{memory,pg,redis}()` — human-in-the-loop tool approval (interrupt / resume).
163
+ * - `ai.guardrail(options)` + `ai.guardrail.{pii,topic,injection,moderation}(...)` — content-intelligence guardrails (moderation / PII / injection / topic).
55
164
  * - `ai.openai.model(...)` / `ai.anthropic.model(...)` / ... once the adapter SDK is registered.
56
165
  *
57
166
  * @example
@@ -70,50 +179,7 @@ import { workflow } from "./workflow/workflow.mjs";
70
179
  * placeholders: { language: "Arabic" },
71
180
  * });
72
181
  */
73
- declare const ai: {
74
- config: typeof setAIConfig;
75
- tool: typeof tool;
76
- agent: typeof agent;
77
- systemPrompt: SystemPromptFactory;
78
- persona: typeof persona;
79
- instruction: typeof instruction;
80
- workflow: typeof workflow;
81
- step: typeof step;
82
- supervisor: typeof supervisor;
83
- orchestrator: typeof orchestrator;
84
- memory: typeof memory$1;
85
- planner: typeof planner;
86
- spawnSubAgent: typeof spawnSubAgent;
87
- router: typeof router;
88
- fanOut: typeof fanOut;
89
- batch: typeof batch;
90
- fallbackModel: typeof fallbackModel;
91
- eval: {
92
- exact: typeof exact;
93
- contains: typeof contains;
94
- predicate: typeof predicate;
95
- judge: typeof judge;
96
- };
97
- mockRouter: typeof mockRouter;
98
- middleware: {
99
- budget: typeof budget;
100
- guardrail: typeof guardrail;
101
- semanticCache: typeof semanticCache;
102
- compose: typeof composeMiddleware;
103
- forTool: typeof forTool;
104
- readBudgetFallbackSignal: typeof readBudgetFallbackSignal;
105
- };
106
- checkpoint: {
107
- memory: typeof memory;
108
- pg: typeof pg;
109
- redis: typeof redis;
110
- };
111
- snapshot: {
112
- memory: typeof memory$2;
113
- pg: typeof pg$1;
114
- redis: typeof redis$1;
115
- };
116
- };
182
+ declare const ai: Ai;
117
183
  //#endregion
118
- export { ai };
184
+ export { Ai, ai };
119
185
  //# sourceMappingURL=ai.d.mts.map
package/esm/ai.d.mts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"ai.d.mts","names":[],"sources":["../../../../../../@warlock.js/ai/src/ai.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoEA;;;;;;;;;;;;;;;;;;cAAa,EAAA"}
1
+ {"version":3,"file":"ai.d.mts","names":[],"sources":["../../../../../../@warlock.js/ai/src/ai.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAuDiB,EAAA;EACf,MAAA,SAAe,WAAA;EACf,IAAA,SAAa,IAAA;EACb,KAAA,SAAc,KAAA;EACd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EA8EA,SAAA,SAAkB,SAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA6CP,EAAA,EAmDR,EAAE"}
package/esm/ai.mjs CHANGED
@@ -5,15 +5,23 @@ import { semanticCache } from "./middleware/builtins/semantic-cache.mjs";
5
5
  import { composeMiddleware } from "./middleware/helpers/compose.mjs";
6
6
  import { forTool } from "./middleware/helpers/for-tool.mjs";
7
7
  import { tool } from "./tool/tool.mjs";
8
+ import { skills } from "./skills/skills.mjs";
9
+ import { memory } from "./memory/memory.mjs";
10
+ import "./skills/index.mjs";
8
11
  import { agent } from "./agent/agent.mjs";
9
12
  import { spawnSubAgent } from "./agent/spawn-sub-agent.mjs";
10
13
  import { batch } from "./batch/batch.mjs";
11
14
  import "./batch/index.mjs";
12
- import { memory } from "./checkpoint/memory.mjs";
15
+ import { streamObject } from "./object-stream/stream-object.mjs";
16
+ import "./object-stream/index.mjs";
17
+ import { serve } from "./serve/serve.mjs";
18
+ import { memory as memory$1 } from "./checkpoint/memory.mjs";
13
19
  import { pg } from "./checkpoint/pg.mjs";
14
20
  import { redis } from "./checkpoint/redis.mjs";
21
+ import { dataset } from "./eval/dataset.mjs";
15
22
  import { evalScorers } from "./eval/index.mjs";
16
- import { memory as memory$1 } from "./memory/memory.mjs";
23
+ import { human } from "./human/register.mjs";
24
+ import { guardrail as guardrail$1 } from "./guard/guardrail.mjs";
17
25
  import { mockRouter } from "./mock/mock-router.mjs";
18
26
  import "./mock/index.mjs";
19
27
  import { fallbackModel } from "./model/fallback-model.mjs";
@@ -23,15 +31,25 @@ import { orchestrator } from "./orchestrator/orchestrator.mjs";
23
31
  import "./orchestrator/index.mjs";
24
32
  import { planner } from "./planner/planner.mjs";
25
33
  import "./planner/index.mjs";
34
+ import { instruction } from "./system-prompt/instruction.mjs";
35
+ import { persona } from "./system-prompt/persona.mjs";
36
+ import { systemPrompt } from "./system-prompt/system-prompt.mjs";
37
+ import { defaultPromptsManager } from "./prompts/prompts-manager.mjs";
38
+ import { rag } from "./rag/rag.mjs";
39
+ import { keywordReranker } from "./rag/rerank/keyword-reranker.mjs";
40
+ import { llmReranker } from "./rag/rerank/llm-reranker.mjs";
41
+ import "./rag/index.mjs";
42
+ import { prompt } from "./prompt/prompt.mjs";
43
+ import "./prompt/index.mjs";
44
+ import { vcr } from "./vcr/vcr.mjs";
45
+ import "./vcr/index.mjs";
26
46
  import { memory as memory$2 } from "./snapshot/memory.mjs";
27
47
  import { pg as pg$1 } from "./snapshot/pg.mjs";
28
48
  import { redis as redis$1 } from "./snapshot/redis.mjs";
29
49
  import { fanOut } from "./supervisor/fan-out.mjs";
30
50
  import { router } from "./supervisor/router-factory.mjs";
31
51
  import "./supervisor/index.mjs";
32
- import { instruction } from "./system-prompt/instruction.mjs";
33
- import { persona } from "./system-prompt/persona.mjs";
34
- import { systemPrompt } from "./system-prompt/system-prompt.mjs";
52
+ import { team } from "./team/team.mjs";
35
53
  import { step } from "./workflow/step.mjs";
36
54
  import { workflow } from "./workflow/workflow.mjs";
37
55
 
@@ -47,6 +65,7 @@ import { workflow } from "./workflow/workflow.mjs";
47
65
  * - `ai.instruction(text)` — reusable instruction block (can be passed to `systemPrompt`).
48
66
  * - `ai.orchestrator(...)` — session-state manager wrapped around a supervisor (durable session, drift detection, resume, commands).
49
67
  * - `ai.memory(...)` — build an agent-memory store with WORKING (in-run scratch) and SEMANTIC (cache-driver `.similar()` recall) tiers.
68
+ * - `ai.skills(...)` — build a runtime skills library (always-injected metadata catalog + on-demand loadSkill tool).
50
69
  * - `ai.planner(...)` — build an executable that generates an ordered plan over registered capabilities, then runs it step-by-step.
51
70
  * - `ai.spawnSubAgent(spec)` — thin wrapper that builds a fresh one-shot `agent()` with an optional per-task `budget` and runs the task once. A general primitive (not planner-specific).
52
71
  * - `ai.router(...)` — build a supervisor-compatible routing agent from named intents.
@@ -57,6 +76,8 @@ import { workflow } from "./workflow/workflow.mjs";
57
76
  * - `ai.mockRouter(decisions, opts?)` — deterministic supervisor `route` callback for tests.
58
77
  * - `ai.checkpoint.{memory,pg,redis}()` — durable orchestrator session checkpoint stores.
59
78
  * - `ai.snapshot.{memory,pg,redis}()` — supervisor-run snapshot stores for `iterate: true` resume.
79
+ * - `ai.human.approval(...)` / `ai.human.resume(...)` / `ai.human.interrupt.{memory,pg,redis}()` — human-in-the-loop tool approval (interrupt / resume).
80
+ * - `ai.guardrail(options)` + `ai.guardrail.{pii,topic,injection,moderation}(...)` — content-intelligence guardrails (moderation / PII / injection / topic).
60
81
  * - `ai.openai.model(...)` / `ai.anthropic.model(...)` / ... once the adapter SDK is registered.
61
82
  *
62
83
  * @example
@@ -85,15 +106,27 @@ const ai = {
85
106
  workflow,
86
107
  step,
87
108
  supervisor,
109
+ team,
88
110
  orchestrator,
89
- memory: memory$1,
111
+ memory,
112
+ skills,
90
113
  planner,
114
+ rag: Object.assign(rag, {
115
+ keywordReranker,
116
+ llmReranker
117
+ }),
91
118
  spawnSubAgent,
92
119
  router,
93
120
  fanOut,
94
121
  batch,
122
+ streamObject,
123
+ serve,
95
124
  fallbackModel,
96
125
  eval: evalScorers,
126
+ dataset,
127
+ prompt,
128
+ prompts: defaultPromptsManager(),
129
+ vcr,
97
130
  mockRouter,
98
131
  middleware: {
99
132
  budget,
@@ -104,7 +137,7 @@ const ai = {
104
137
  readBudgetFallbackSignal
105
138
  },
106
139
  checkpoint: {
107
- memory,
140
+ memory: memory$1,
108
141
  pg,
109
142
  redis
110
143
  },
@@ -112,7 +145,9 @@ const ai = {
112
145
  memory: memory$2,
113
146
  pg: pg$1,
114
147
  redis: redis$1
115
- }
148
+ },
149
+ human,
150
+ guardrail: guardrail$1
116
151
  };
117
152
 
118
153
  //#endregion
package/esm/ai.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"ai.mjs","names":["checkpointMemory","checkpointPg","checkpointRedis","snapshotMemory","snapshotPg","snapshotRedis"],"sources":["../../../../../../@warlock.js/ai/src/ai.ts"],"sourcesContent":["import { agent } from \"./agent/agent\";\nimport { batch } from \"./batch\";\nimport {\n checkpointMemory,\n checkpointPg,\n checkpointRedis,\n} from \"./checkpoint\";\nimport { setAIConfig } from \"./config\";\nimport { evalScorers } from \"./eval\";\nimport { budget, readBudgetFallbackSignal } from \"./middleware/builtins/budget\";\nimport { memory } from \"./memory\";\nimport { guardrail } from \"./middleware/builtins/guardrail\";\nimport { semanticCache } from \"./middleware/builtins/semantic-cache\";\nimport { composeMiddleware, forTool } from \"./middleware/helpers\";\nimport { mockRouter } from \"./mock\";\nimport { fallbackModel } from \"./model\";\nimport { orchestrator } from \"./orchestrator\";\nimport { planner } from \"./planner\";\nimport { spawnSubAgent } from \"./agent/spawn-sub-agent\";\nimport { snapshotMemory, snapshotPg, snapshotRedis } from \"./snapshot\";\nimport { fanOut, router } from \"./supervisor\";\nimport { supervisor } from \"./supervisor/supervisor\";\nimport { instruction } from \"./system-prompt/instruction\";\nimport { persona } from \"./system-prompt/persona\";\nimport { systemPrompt } from \"./system-prompt/system-prompt\";\nimport { tool } from \"./tool/tool\";\nimport { step } from \"./workflow/step\";\nimport { workflow } from \"./workflow/workflow\";\n\n/**\n * Top-level `ai` namespace — holds built-in factories and user-registered SDK adapters.\n *\n * Factories:\n * - `ai.tool(...)` — wrap an async function with a schema-validated input.\n * - `ai.agent(...)` — build an executable agent from model + tools + prompt.\n * - `ai.systemPrompt(...)` — compose a layered persona + instructions prompt.\n * - `ai.persona(text)` — reusable persona block (can be passed to `systemPrompt`).\n * - `ai.instruction(text)` — reusable instruction block (can be passed to `systemPrompt`).\n * - `ai.orchestrator(...)` — session-state manager wrapped around a supervisor (durable session, drift detection, resume, commands).\n * - `ai.memory(...)` — build an agent-memory store with WORKING (in-run scratch) and SEMANTIC (cache-driver `.similar()` recall) tiers.\n * - `ai.planner(...)` — build an executable that generates an ordered plan over registered capabilities, then runs it step-by-step.\n * - `ai.spawnSubAgent(spec)` — thin wrapper that builds a fresh one-shot `agent()` with an optional per-task `budget` and runs the task once. A general primitive (not planner-specific).\n * - `ai.router(...)` — build a supervisor-compatible routing agent from named intents.\n * - `ai.fanOut(unit, count)` — spread one agent/workflow into N intent entries for voting / self-consistency.\n * - `ai.batch(executable, items, opts?)` — run any executable over a dataset with bounded concurrency + per-item retry.\n * - `ai.fallbackModel(models, opts?)` — wrap an ordered model list that fails over to the next on transient provider errors.\n * - `ai.eval.{exact,contains,predicate,judge}(...)` — built-in scorer factories for `agent.eval(...)`.\n * - `ai.mockRouter(decisions, opts?)` — deterministic supervisor `route` callback for tests.\n * - `ai.checkpoint.{memory,pg,redis}()` — durable orchestrator session checkpoint stores.\n * - `ai.snapshot.{memory,pg,redis}()` — supervisor-run snapshot stores for `iterate: true` resume.\n * - `ai.openai.model(...)` / `ai.anthropic.model(...)` / ... once the adapter SDK is registered.\n *\n * @example\n * const alex = ai.persona(\"You are Alex, a TypeScript expert.\");\n * const replyIn = ai.instruction(\"Respond in {{language|English}}.\");\n *\n * const prompt = ai.systemPrompt().persona(alex).instruction(replyIn);\n *\n * const myAgent = ai.agent({\n * model: ai.openai.model({ name: \"gpt-4o\" }),\n * systemPrompt: prompt,\n * tools: [myTool],\n * });\n *\n * const result = await myAgent.execute(\"What is the weather in Cairo?\", {\n * placeholders: { language: \"Arabic\" },\n * });\n */\nexport const ai = {\n config: setAIConfig,\n tool,\n agent,\n systemPrompt,\n persona,\n instruction,\n workflow,\n step,\n supervisor,\n orchestrator,\n memory,\n planner,\n spawnSubAgent,\n router,\n fanOut,\n batch,\n fallbackModel,\n eval: evalScorers,\n mockRouter,\n middleware: {\n budget,\n guardrail,\n semanticCache,\n compose: composeMiddleware,\n forTool,\n readBudgetFallbackSignal,\n },\n checkpoint: {\n memory: checkpointMemory,\n pg: checkpointPg,\n redis: checkpointRedis,\n },\n snapshot: {\n memory: snapshotMemory,\n pg: snapshotPg,\n redis: snapshotRedis,\n },\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoEA,MAAa,KAAK;CAChB,QAAQ;CACR;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA,MAAM;CACN;CACA,YAAY;EACV;EACA;EACA;EACA,SAAS;EACT;EACA;CACF;CACA,YAAY;EACFA;EACJC;EACGC;CACT;CACA,UAAU;EACR,QAAQC;EACR,IAAIC;EACJ,OAAOC;CACT;AACF"}
1
+ {"version":3,"file":"ai.mjs","names":["checkpointMemory","checkpointPg","checkpointRedis","snapshotMemory","snapshotPg","snapshotRedis","guardrailSuite"],"sources":["../../../../../../@warlock.js/ai/src/ai.ts"],"sourcesContent":["import { agent } from \"./agent/agent\";\nimport { batch } from \"./batch\";\nimport { streamObject } from \"./object-stream\";\nimport { serve } from \"./serve\";\nimport {\n checkpointMemory,\n checkpointPg,\n checkpointRedis,\n} from \"./checkpoint\";\nimport { setAIConfig } from \"./config\";\nimport { dataset, evalScorers } from \"./eval\";\nimport { humanApproval } from \"./human/human-approval\";\nimport { human } from \"./human/register\";\nimport { resume } from \"./human/resume\";\nimport {\n interruptMemory,\n interruptPg,\n interruptRedis,\n} from \"./human/stores\";\nimport { guardrail as guardrailSuite } from \"./guard/guardrail\";\nimport { budget, readBudgetFallbackSignal } from \"./middleware/builtins/budget\";\nimport { memory } from \"./memory\";\nimport { guardrail } from \"./middleware/builtins/guardrail\";\nimport { semanticCache } from \"./middleware/builtins/semantic-cache\";\nimport { composeMiddleware, forTool } from \"./middleware/helpers\";\nimport { mockRouter } from \"./mock\";\nimport { fallbackModel } from \"./model\";\nimport { orchestrator } from \"./orchestrator\";\nimport { planner } from \"./planner\";\nimport { defaultPromptsManager } from \"./prompts/prompts-manager\";\nimport { rag } from \"./rag\";\nimport { keywordReranker } from \"./rag/rerank/keyword-reranker\";\nimport { llmReranker } from \"./rag/rerank/llm-reranker\";\nimport { spawnSubAgent } from \"./agent/spawn-sub-agent\";\nimport { skills } from \"./skills\";\nimport { prompt } from \"./prompt\";\nimport { vcr } from \"./vcr\";\nimport { snapshotMemory, snapshotPg, snapshotRedis } from \"./snapshot\";\nimport { fanOut, router } from \"./supervisor\";\nimport { supervisor } from \"./supervisor/supervisor\";\nimport { team } from \"./team/team\";\nimport { instruction } from \"./system-prompt/instruction\";\nimport { persona } from \"./system-prompt/persona\";\nimport { systemPrompt } from \"./system-prompt/system-prompt\";\nimport { tool } from \"./tool/tool\";\nimport { step } from \"./workflow/step\";\nimport { workflow } from \"./workflow/workflow\";\n\n/**\n * The shape of the top-level `ai` namespace. Declared as an `interface` (not an\n * inferred `const` type) so satellite packages can attach their verb via\n * `declare module \"@warlock.js/ai\" { interface Ai { … } }` — e.g. `ai.workspace`,\n * `ai.tools`, `ai.mcp`, `ai.human`. The runtime object below is asserted to this\n * type; a satellite assigns its member on import.\n */\nexport interface Ai {\n config: typeof setAIConfig;\n tool: typeof tool;\n agent: typeof agent;\n systemPrompt: typeof systemPrompt;\n persona: typeof persona;\n instruction: typeof instruction;\n workflow: typeof workflow;\n step: typeof step;\n supervisor: typeof supervisor;\n team: typeof team;\n orchestrator: typeof orchestrator;\n memory: typeof memory;\n skills: typeof skills;\n planner: typeof planner;\n rag: typeof rag & {\n keywordReranker: typeof keywordReranker;\n llmReranker: typeof llmReranker;\n };\n spawnSubAgent: typeof spawnSubAgent;\n router: typeof router;\n fanOut: typeof fanOut;\n batch: typeof batch;\n /** Structured-output streaming — partial-object snapshots + a strict final parse (A1). */\n streamObject: typeof streamObject;\n /** Serve an executable as an SSE HTTP endpoint — production serving primitive (A3). */\n serve: typeof serve;\n fallbackModel: typeof fallbackModel;\n eval: typeof evalScorers;\n dataset: typeof dataset;\n prompt: typeof prompt;\n /**\n * Process-wide registry of named, versioned `systemPrompt(...)` builders,\n * keyed by `name@version`. A `systemPrompt(input, { name })` (or any\n * `.meta({ name })` rename) auto-registers here; `ai.prompts.get(name)` /\n * `.resolve(name)` reads them back, and `systemPrompt().merge(name)` folds a\n * registered prompt into a new one.\n */\n prompts: ReturnType<typeof defaultPromptsManager>;\n vcr: typeof vcr;\n mockRouter: typeof mockRouter;\n middleware: {\n budget: typeof budget;\n guardrail: typeof guardrail;\n semanticCache: typeof semanticCache;\n compose: typeof composeMiddleware;\n forTool: typeof forTool;\n readBudgetFallbackSignal: typeof readBudgetFallbackSignal;\n };\n checkpoint: {\n memory: typeof checkpointMemory;\n pg: typeof checkpointPg;\n redis: typeof checkpointRedis;\n };\n snapshot: {\n memory: typeof snapshotMemory;\n pg: typeof snapshotPg;\n redis: typeof snapshotRedis;\n };\n /**\n * Human-in-the-loop tool approval (interrupt / resume).\n *\n * - `human.approval(options)` — the `tool.before` approval-gate middleware.\n * - `human.resume(id, decision, options)` — out-of-process durable resume.\n * - `human.interrupt.{memory,pg,redis}()` — durable {@link InterruptStore}\n * factories (memory ships real; pg/redis are lazy optional peers).\n */\n human: {\n approval: typeof humanApproval;\n resume: typeof resume;\n interrupt: {\n memory: typeof interruptMemory;\n pg: typeof interruptPg;\n redis: typeof interruptRedis;\n };\n };\n /**\n * Content-intelligence guardrail. `ai.guardrail(options)` builds a composed\n * input / output / tool middleware; `ai.guardrail.{pii,topic,injection,moderation}`\n * are the built-in detector factories.\n */\n guardrail: typeof guardrailSuite;\n}\n\n/**\n * Top-level `ai` namespace — holds built-in factories and user-registered SDK adapters.\n *\n * Factories:\n * - `ai.tool(...)` — wrap an async function with a schema-validated input.\n * - `ai.agent(...)` — build an executable agent from model + tools + prompt.\n * - `ai.systemPrompt(...)` — compose a layered persona + instructions prompt.\n * - `ai.persona(text)` — reusable persona block (can be passed to `systemPrompt`).\n * - `ai.instruction(text)` — reusable instruction block (can be passed to `systemPrompt`).\n * - `ai.orchestrator(...)` — session-state manager wrapped around a supervisor (durable session, drift detection, resume, commands).\n * - `ai.memory(...)` — build an agent-memory store with WORKING (in-run scratch) and SEMANTIC (cache-driver `.similar()` recall) tiers.\n * - `ai.skills(...)` — build a runtime skills library (always-injected metadata catalog + on-demand loadSkill tool).\n * - `ai.planner(...)` — build an executable that generates an ordered plan over registered capabilities, then runs it step-by-step.\n * - `ai.spawnSubAgent(spec)` — thin wrapper that builds a fresh one-shot `agent()` with an optional per-task `budget` and runs the task once. A general primitive (not planner-specific).\n * - `ai.router(...)` — build a supervisor-compatible routing agent from named intents.\n * - `ai.fanOut(unit, count)` — spread one agent/workflow into N intent entries for voting / self-consistency.\n * - `ai.batch(executable, items, opts?)` — run any executable over a dataset with bounded concurrency + per-item retry.\n * - `ai.fallbackModel(models, opts?)` — wrap an ordered model list that fails over to the next on transient provider errors.\n * - `ai.eval.{exact,contains,predicate,judge}(...)` — built-in scorer factories for `agent.eval(...)`.\n * - `ai.mockRouter(decisions, opts?)` — deterministic supervisor `route` callback for tests.\n * - `ai.checkpoint.{memory,pg,redis}()` — durable orchestrator session checkpoint stores.\n * - `ai.snapshot.{memory,pg,redis}()` — supervisor-run snapshot stores for `iterate: true` resume.\n * - `ai.human.approval(...)` / `ai.human.resume(...)` / `ai.human.interrupt.{memory,pg,redis}()` — human-in-the-loop tool approval (interrupt / resume).\n * - `ai.guardrail(options)` + `ai.guardrail.{pii,topic,injection,moderation}(...)` — content-intelligence guardrails (moderation / PII / injection / topic).\n * - `ai.openai.model(...)` / `ai.anthropic.model(...)` / ... once the adapter SDK is registered.\n *\n * @example\n * const alex = ai.persona(\"You are Alex, a TypeScript expert.\");\n * const replyIn = ai.instruction(\"Respond in {{language|English}}.\");\n *\n * const prompt = ai.systemPrompt().persona(alex).instruction(replyIn);\n *\n * const myAgent = ai.agent({\n * model: ai.openai.model({ name: \"gpt-4o\" }),\n * systemPrompt: prompt,\n * tools: [myTool],\n * });\n *\n * const result = await myAgent.execute(\"What is the weather in Cairo?\", {\n * placeholders: { language: \"Arabic\" },\n * });\n */\nexport const ai = {\n config: setAIConfig,\n tool,\n agent,\n systemPrompt,\n persona,\n instruction,\n workflow,\n step,\n supervisor,\n team,\n orchestrator,\n memory,\n skills,\n planner,\n rag: Object.assign(rag, { keywordReranker, llmReranker }),\n spawnSubAgent,\n router,\n fanOut,\n batch,\n streamObject,\n serve,\n fallbackModel,\n eval: evalScorers,\n dataset,\n prompt,\n prompts: defaultPromptsManager(),\n vcr,\n mockRouter,\n middleware: {\n budget,\n guardrail,\n semanticCache,\n compose: composeMiddleware,\n forTool,\n readBudgetFallbackSignal,\n },\n checkpoint: {\n memory: checkpointMemory,\n pg: checkpointPg,\n redis: checkpointRedis,\n },\n snapshot: {\n memory: snapshotMemory,\n pg: snapshotPg,\n redis: snapshotRedis,\n },\n human,\n guardrail: guardrailSuite,\n // Asserted (not `: Ai`) so a consumer build that augments `Ai` with a\n // satellite verb (e.g. `workspace`) doesn't flag this literal as missing it.\n} as Ai;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqLA,MAAa,KAAK;CAChB,QAAQ;CACR;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA,KAAK,OAAO,OAAO,KAAK;EAAE;EAAiB;CAAY,CAAC;CACxD;CACA;CACA;CACA;CACA;CACA;CACA;CACA,MAAM;CACN;CACA;CACA,SAAS,sBAAsB;CAC/B;CACA;CACA,YAAY;EACV;EACA;EACA;EACA,SAAS;EACT;EACA;CACF;CACA,YAAY;EACV,QAAQA;EACJC;EACGC;CACT;CACA,UAAU;EACR,QAAQC;EACR,IAAIC;EACJ,OAAOC;CACT;CACA;CACA,WAAWC;AAGb"}
@@ -1 +1 @@
1
- {"version":3,"file":"batch.d.mts","names":[],"sources":["../../../../../../../@warlock.js/ai/src/batch/batch.ts"],"mappings":";;;;;;;;AAmDA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAsB,KAAA,mCAAwC,UAAA,GAAa,aAAA,EACzE,UAAA,EAAY,kBAAA,CAAmB,MAAA,EAAQ,QAAA,EAAU,OAAA,GACjD,KAAA,WAAgB,MAAA,IAChB,OAAA,GAAS,YAAA,CAAa,OAAA,IACrB,OAAA,CAAQ,WAAA,CAAY,OAAA"}
1
+ {"version":3,"file":"batch.d.mts","names":[],"sources":["../../../../../../../@warlock.js/ai/src/batch/batch.ts"],"mappings":";;;;;;;;AAyDA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAsB,KAAA,mCAAwC,UAAA,GAAa,aAAA,EACzE,UAAA,EAAY,kBAAA,CAAmB,MAAA,EAAQ,QAAA,EAAU,OAAA,GACjD,KAAA,WAAgB,MAAA,IAChB,OAAA,GAAS,YAAA,CAAa,OAAA,IACrB,OAAA,CAAQ,WAAA,CAAY,OAAA"}
@@ -6,6 +6,10 @@ import { runBatchItem } from "./run-batch-item.mjs";
6
6
  import { runWithConcurrency } from "./run-with-concurrency.mjs";
7
7
 
8
8
  //#region ../@warlock.js/ai/src/batch/batch.ts
9
+ /** Batch size above which an unset (unbounded) concurrency warns once (D5). */
10
+ const BATCH_UNBOUNDED_WARN_THRESHOLD = 50;
11
+ /** Process-lifetime flag so the unbounded-batch warning fires at most once. */
12
+ let warnedUnboundedBatch = false;
9
13
  /**
10
14
  * Run an executable AI primitive (agent, workflow, supervisor, tool,
11
15
  * or anything satisfying {@link ExecutableContract}) over a dataset
@@ -63,11 +67,27 @@ var BatchRun = class {
63
67
  * the rolled-up {@link BatchResult}. Runs once per `batch()` call.
64
68
  */
65
69
  async run() {
66
- const concurrency = this.options.concurrency ?? this.items.length;
70
+ const concurrency = this.resolveConcurrency();
67
71
  await runWithConcurrency(this.items.length, concurrency, (index) => this.processItem(index));
68
72
  return this.buildResult();
69
73
  }
70
74
  /**
75
+ * Resolve the effective concurrency from {@link BatchOptions.concurrency}
76
+ * (D5). An explicit number or `"unbounded"` is honored as-is; an omitted
77
+ * value runs unbounded for back-compat but warns once (outside tests)
78
+ * for a large batch so an accidental all-at-once run is visible.
79
+ */
80
+ resolveConcurrency() {
81
+ const configured = this.options.concurrency;
82
+ if (configured === "unbounded") return this.items.length;
83
+ if (typeof configured === "number") return configured;
84
+ if (this.items.length > BATCH_UNBOUNDED_WARN_THRESHOLD && !warnedUnboundedBatch && !process.env.VITEST && process.env.NODE_ENV !== "test") {
85
+ warnedUnboundedBatch = true;
86
+ console.warn(`[warlock-ai] ai.batch() is running ${this.items.length} items with unbounded concurrency (no \`concurrency\` set). Each concurrent item consumes tokens/quota/memory — pass an explicit \`concurrency\` cap, or \`concurrency: "unbounded"\` to silence this.`);
87
+ }
88
+ return this.items.length;
89
+ }
90
+ /**
71
91
  * Run a single item with retry, record it positionally, then fire
72
92
  * the `onItem` hook. A throw from the hook is swallowed — a progress
73
93
  * callback must never break the batch.
@@ -1 +1 @@
1
- {"version":3,"file":"batch.mjs","names":[],"sources":["../../../../../../../@warlock.js/ai/src/batch/batch.ts"],"sourcesContent":["import type { BaseReport } from \"../contracts/result/base-report.type\";\nimport { REPORT_SCHEMA_VERSION } from \"../contracts/result/base-report.type\";\nimport type { BaseResult } from \"../contracts/result/base-result.type\";\nimport type { ExecutableContract } from \"../contracts/executable.contract\";\nimport type { ExecuteResult } from \"../contracts/result/execute-result.type\";\nimport type { Usage } from \"../contracts/result/usage.type\";\nimport { accumulateCost } from \"../utils/compute-cost\";\nimport { generateRunId } from \"../utils/generate-run-id\";\nimport { stampReportLineage } from \"../utils/stamp-report-lineage\";\nimport type {\n BatchItemResult,\n BatchOptions,\n BatchReport,\n BatchResult,\n} from \"./batch.type\";\nimport { runBatchItem } from \"./run-batch-item\";\nimport { runWithConcurrency } from \"./run-with-concurrency\";\n\n/**\n * Run an executable AI primitive (agent, workflow, supervisor, tool,\n * or anything satisfying {@link ExecutableContract}) over a dataset\n * with bounded concurrency and per-item retry, returning per-item\n * outcomes plus rolled-up usage and a walkable report tree.\n *\n * **Role.** The fan-out primitive of `@warlock.js/ai`. Where an agent\n * runs once, `batch` runs the SAME executable N times — once per item\n * — and aggregates the results into the unified {@link ExecuteResult}\n * envelope, so a batch slots into cost dashboards and trace tooling\n * exactly like a single run does.\n *\n * **Isolation.** Items are independent: one item's failure (after its\n * retries are exhausted) never cancels a sibling, and the batch as a\n * whole never rejects — failures live on each {@link BatchItemResult}.\n * Reach for `result.report.failed` / `item.status` to inspect them.\n *\n * **Usage rollup.** `result.usage` and `result.report.usage` sum every\n * item's usage, satisfying the universal rollup invariant (\"own cost\n * + sum of children\"; a batch has zero own cost). Each item's own\n * report is attached under `report.children[]`, in original item\n * order, so a trace walker sees every run.\n *\n * @example\n * const result = await batch(summarizer, articles, {\n * concurrency: 4,\n * retry: { attempts: 3, backoff: \"exponential\" },\n * onItem: (item) => log.info(\"batch\", \"item\", \"settled\", { index: item.index }),\n * });\n *\n * console.log(`${result.report.succeeded}/${result.report.total} ok`);\n * console.log(`${result.usage.total} tokens total`);\n */\nexport async function batch<TInput, TOptions, TResult extends BaseResult = ExecuteResult>(\n executable: ExecutableContract<TInput, TOptions, TResult>,\n items: readonly TInput[],\n options: BatchOptions<TResult> = {},\n): Promise<BatchResult<TResult>> {\n return new BatchRun(executable, items, options).run();\n}\n\n/**\n * Per-call orchestration state for one {@link batch} invocation.\n * Instantiated fresh inside the factory so the mutable accumulators\n * (`results`, `usage`) are never shared across batches. Unexported —\n * callers only ever see the plain {@link BatchResult}.\n */\nclass BatchRun<TInput, TOptions, TResult extends BaseResult> {\n private readonly runId: string;\n private readonly results: BatchItemResult<TResult>[];\n private readonly startedAt = new Date().toISOString();\n private readonly startPerf = performance.now();\n\n public constructor(\n private readonly executable: ExecutableContract<TInput, TOptions, TResult>,\n private readonly items: readonly TInput[],\n private readonly options: BatchOptions<TResult>,\n ) {\n this.runId = generateRunId(\"batch\");\n this.results = new Array<BatchItemResult<TResult>>(items.length);\n }\n\n /**\n * Dispatch every item through the concurrency pool, then assemble\n * the rolled-up {@link BatchResult}. Runs once per `batch()` call.\n */\n public async run(): Promise<BatchResult<TResult>> {\n const concurrency = this.options.concurrency ?? this.items.length;\n\n await runWithConcurrency(this.items.length, concurrency, (index) =>\n this.processItem(index),\n );\n\n return this.buildResult();\n }\n\n /**\n * Run a single item with retry, record it positionally, then fire\n * the `onItem` hook. A throw from the hook is swallowed — a progress\n * callback must never break the batch.\n */\n private async processItem(index: number): Promise<void> {\n const item = await runBatchItem({\n index,\n input: this.items[index] as TInput,\n executable: this.executable,\n retry: this.options.retry,\n signal: this.options.signal,\n });\n\n this.results[index] = item;\n\n if (this.options.onItem) {\n try {\n await this.options.onItem(item);\n } catch {\n // A progress hook must never break the batch — swallow its throw.\n }\n }\n }\n\n /**\n * Fold the per-item outcomes into rolled-up usage, the child report\n * list, and the final {@link BatchResult}, then stamp lineage across\n * the whole subtree so every child shares this batch's root run id.\n */\n private buildResult(): BatchResult<TResult> {\n const usage: Usage = { input: 0, output: 0, total: 0 };\n const children: BaseReport[] = [];\n const data: (unknown | undefined)[] = new Array(this.items.length).fill(undefined);\n\n let succeeded = 0;\n let failed = 0;\n let cancelled = 0;\n\n for (const item of this.results) {\n if (item.status === \"completed\") {\n succeeded += 1;\n } else if (item.status === \"failed\") {\n failed += 1;\n } else {\n cancelled += 1;\n }\n\n const itemResult = item.result;\n if (itemResult) {\n this.mergeUsage(usage, itemResult.usage);\n\n if (\"report\" in itemResult && itemResult.report) {\n children.push(itemResult.report as BaseReport);\n }\n\n if (item.status === \"completed\" && \"data\" in itemResult) {\n data[item.index] = (itemResult as { data?: unknown }).data;\n }\n }\n }\n\n const report = this.buildReport(usage, children, { succeeded, failed, cancelled });\n\n stampReportLineage(report, {\n rootRunId: this.runId,\n sessionId: this.options.sessionId,\n });\n\n return {\n type: \"batch\",\n data,\n usage,\n report,\n items: this.results,\n };\n }\n\n /**\n * Add a child's usage into the running batch total. Scalar token\n * channels sum directly; the optional cost breakdown merges via\n * {@link accumulateCost} so a single unpriced child can't erase the\n * cost of priced siblings. Optional token sub-channels\n * (`cachedTokens`, etc.) accumulate only when some child reports\n * them, preserving the \"never reported anywhere\" signal.\n */\n private 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\n /**\n * Build the batch's own {@link BatchReport} node. `parentRunId` /\n * `rootRunId` are placeholders here — {@link stampReportLineage}\n * rewrites them across the whole subtree right after.\n */\n private buildReport(\n usage: Usage,\n children: BaseReport[],\n counts: { succeeded: number; failed: number; cancelled: number },\n ): BatchReport {\n const status = counts.failed > 0 || counts.cancelled > 0 ? \"failed\" : \"completed\";\n\n return {\n runId: this.runId,\n rootRunId: this.runId,\n name: this.options.name ?? \"batch\",\n type: \"batch\",\n status,\n startedAt: this.startedAt,\n endedAt: new Date().toISOString(),\n duration: performance.now() - this.startPerf,\n usage,\n children,\n total: this.items.length,\n succeeded: counts.succeeded,\n failed: counts.failed,\n cancelled: counts.cancelled,\n reportSchemaVersion: REPORT_SCHEMA_VERSION,\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmDA,eAAsB,MACpB,YACA,OACA,UAAiC,CAAC,GACH;CAC/B,OAAO,IAAI,SAAS,YAAY,OAAO,OAAO,CAAC,CAAC,IAAI;AACtD;;;;;;;AAQA,IAAM,WAAN,MAA6D;CAM3D,AAAO,YACL,AAAiB,YACjB,AAAiB,OACjB,AAAiB,SACjB;EAHiB;EACA;EACA;oCANU,IAAI,KAAK,EAAC,CAAC,YAAY;mBACvB,YAAY,IAAI;EAO3C,KAAK,QAAQ,cAAc,OAAO;EAClC,KAAK,UAAU,IAAI,MAAgC,MA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EAED,OAAO;GACL,MAAM;GACN;GACA;GACA;GACA,OAAO,KAAK;EACd;CACF;;;;;;;;;CAUA,AAAQ,WAAW,QAAe,OAAoB;EACpD,OAAO,SAAS,MAAM;EACtB,OAAO,UAAU,MAAM;EACvB,OAAO,SAAS,MAAM;EAEtB,IAAI,MAAM,iBAAiB,QACzB,OAAO,gBAAgB,OAAO,gBAAgB,KAAK,MAAM;EAG3D,IAAI,MAAM,oBAAoB,QAC5B,OAAO,mBAAmB,OAAO,mBAAmB,KAAK,MAAM;EAGjE,IAAI,MAAM,qBAAqB,QAC7B,OAAO,oBAAoB,OAAO,oBAAoB,KAAK,MAAM;EAGnE,MAAM,aAAa,eAAe,OAAO,MAAM,MAAM,IAAI;EACzD,IAAI,eAAe,QACjB,OAAO,OAAO;CAElB;;;;;;CAOA,AAAQ,YACN,OACA,UACA,QACa;EACb,MAAM,SAAS,OAAO,SAAS,KAAK,OAAO,YAAY,IAAI,WAAW;EAEtE,OAAO;GACL,OAAO,KAAK;GACZ,WAAW,KAAK;GAChB,MAAM,KAAK,QAAQ,QAAQ;GAC3B,MAAM;GACN;GACA,WAAW,KAAK;GAChB,0BAAS,IAAI,KAAK,EAAC,CAAC,YAAY;GAChC,UAAU,YAAY,IAAI,IAAI,KAAK;GACnC;GACA;GACA,OAAO,KAAK,MAAM;GAClB,WAAW,OAAO;GAClB,QAAQ,OAAO;GACf,WAAW,OAAO;GAClB;EACF;CACF;AACF"}
1
+ {"version":3,"file":"batch.mjs","names":[],"sources":["../../../../../../../@warlock.js/ai/src/batch/batch.ts"],"sourcesContent":["import type { BaseReport } from \"../contracts/result/base-report.type\";\nimport { REPORT_SCHEMA_VERSION } from \"../contracts/result/base-report.type\";\nimport type { BaseResult } from \"../contracts/result/base-result.type\";\nimport type { ExecutableContract } from \"../contracts/executable.contract\";\nimport type { ExecuteResult } from \"../contracts/result/execute-result.type\";\nimport type { Usage } from \"../contracts/result/usage.type\";\nimport { accumulateCost } from \"../utils/compute-cost\";\nimport { generateRunId } from \"../utils/generate-run-id\";\nimport { stampReportLineage } from \"../utils/stamp-report-lineage\";\nimport type {\n BatchItemResult,\n BatchOptions,\n BatchReport,\n BatchResult,\n} from \"./batch.type\";\nimport { runBatchItem } from \"./run-batch-item\";\nimport { runWithConcurrency } from \"./run-with-concurrency\";\n\n/** Batch size above which an unset (unbounded) concurrency warns once (D5). */\nconst BATCH_UNBOUNDED_WARN_THRESHOLD = 50;\n\n/** Process-lifetime flag so the unbounded-batch warning fires at most once. */\nlet warnedUnboundedBatch = false;\n\n/**\n * Run an executable AI primitive (agent, workflow, supervisor, tool,\n * or anything satisfying {@link ExecutableContract}) over a dataset\n * with bounded concurrency and per-item retry, returning per-item\n * outcomes plus rolled-up usage and a walkable report tree.\n *\n * **Role.** The fan-out primitive of `@warlock.js/ai`. Where an agent\n * runs once, `batch` runs the SAME executable N times — once per item\n * — and aggregates the results into the unified {@link ExecuteResult}\n * envelope, so a batch slots into cost dashboards and trace tooling\n * exactly like a single run does.\n *\n * **Isolation.** Items are independent: one item's failure (after its\n * retries are exhausted) never cancels a sibling, and the batch as a\n * whole never rejects — failures live on each {@link BatchItemResult}.\n * Reach for `result.report.failed` / `item.status` to inspect them.\n *\n * **Usage rollup.** `result.usage` and `result.report.usage` sum every\n * item's usage, satisfying the universal rollup invariant (\"own cost\n * + sum of children\"; a batch has zero own cost). Each item's own\n * report is attached under `report.children[]`, in original item\n * order, so a trace walker sees every run.\n *\n * @example\n * const result = await batch(summarizer, articles, {\n * concurrency: 4,\n * retry: { attempts: 3, backoff: \"exponential\" },\n * onItem: (item) => log.info(\"batch\", \"item\", \"settled\", { index: item.index }),\n * });\n *\n * console.log(`${result.report.succeeded}/${result.report.total} ok`);\n * console.log(`${result.usage.total} tokens total`);\n */\nexport async function batch<TInput, TOptions, TResult extends BaseResult = ExecuteResult>(\n executable: ExecutableContract<TInput, TOptions, TResult>,\n items: readonly TInput[],\n options: BatchOptions<TResult> = {},\n): Promise<BatchResult<TResult>> {\n return new BatchRun(executable, items, options).run();\n}\n\n/**\n * Per-call orchestration state for one {@link batch} invocation.\n * Instantiated fresh inside the factory so the mutable accumulators\n * (`results`, `usage`) are never shared across batches. Unexported —\n * callers only ever see the plain {@link BatchResult}.\n */\nclass BatchRun<TInput, TOptions, TResult extends BaseResult> {\n private readonly runId: string;\n private readonly results: BatchItemResult<TResult>[];\n private readonly startedAt = new Date().toISOString();\n private readonly startPerf = performance.now();\n\n public constructor(\n private readonly executable: ExecutableContract<TInput, TOptions, TResult>,\n private readonly items: readonly TInput[],\n private readonly options: BatchOptions<TResult>,\n ) {\n this.runId = generateRunId(\"batch\");\n this.results = new Array<BatchItemResult<TResult>>(items.length);\n }\n\n /**\n * Dispatch every item through the concurrency pool, then assemble\n * the rolled-up {@link BatchResult}. Runs once per `batch()` call.\n */\n public async run(): Promise<BatchResult<TResult>> {\n const concurrency = this.resolveConcurrency();\n\n await runWithConcurrency(this.items.length, concurrency, (index) =>\n this.processItem(index),\n );\n\n return this.buildResult();\n }\n\n /**\n * Resolve the effective concurrency from {@link BatchOptions.concurrency}\n * (D5). An explicit number or `\"unbounded\"` is honored as-is; an omitted\n * value runs unbounded for back-compat but warns once (outside tests)\n * for a large batch so an accidental all-at-once run is visible.\n */\n private resolveConcurrency(): number {\n const configured = this.options.concurrency;\n\n if (configured === \"unbounded\") {\n return this.items.length;\n }\n if (typeof configured === \"number\") {\n return configured;\n }\n\n if (\n this.items.length > BATCH_UNBOUNDED_WARN_THRESHOLD &&\n !warnedUnboundedBatch &&\n !process.env.VITEST &&\n process.env.NODE_ENV !== \"test\"\n ) {\n warnedUnboundedBatch = true;\n console.warn(\n `[warlock-ai] ai.batch() is running ${this.items.length} items with unbounded concurrency (no \\`concurrency\\` set). ` +\n 'Each concurrent item consumes tokens/quota/memory — pass an explicit `concurrency` cap, or `concurrency: \"unbounded\"` to silence this.',\n );\n }\n\n return this.items.length;\n }\n\n /**\n * Run a single item with retry, record it positionally, then fire\n * the `onItem` hook. A throw from the hook is swallowed — a progress\n * callback must never break the batch.\n */\n private async processItem(index: number): Promise<void> {\n const item = await runBatchItem({\n index,\n input: this.items[index] as TInput,\n executable: this.executable,\n retry: this.options.retry,\n signal: this.options.signal,\n });\n\n this.results[index] = item;\n\n if (this.options.onItem) {\n try {\n await this.options.onItem(item);\n } catch {\n // A progress hook must never break the batch — swallow its throw.\n }\n }\n }\n\n /**\n * Fold the per-item outcomes into rolled-up usage, the child report\n * list, and the final {@link BatchResult}, then stamp lineage across\n * the whole subtree so every child shares this batch's root run id.\n */\n private buildResult(): BatchResult<TResult> {\n const usage: Usage = { input: 0, output: 0, total: 0 };\n const children: BaseReport[] = [];\n const data: (unknown | undefined)[] = new Array(this.items.length).fill(undefined);\n\n let succeeded = 0;\n let failed = 0;\n let cancelled = 0;\n\n for (const item of this.results) {\n if (item.status === \"completed\") {\n succeeded += 1;\n } else if (item.status === \"failed\") {\n failed += 1;\n } else {\n cancelled += 1;\n }\n\n const itemResult = item.result;\n if (itemResult) {\n this.mergeUsage(usage, itemResult.usage);\n\n if (\"report\" in itemResult && itemResult.report) {\n children.push(itemResult.report as BaseReport);\n }\n\n if (item.status === \"completed\" && \"data\" in itemResult) {\n data[item.index] = (itemResult as { data?: unknown }).data;\n }\n }\n }\n\n const report = this.buildReport(usage, children, { succeeded, failed, cancelled });\n\n stampReportLineage(report, {\n rootRunId: this.runId,\n sessionId: this.options.sessionId,\n });\n\n return {\n type: \"batch\",\n data,\n usage,\n report,\n items: this.results,\n };\n }\n\n /**\n * Add a child's usage into the running batch total. Scalar token\n * channels sum directly; the optional cost breakdown merges via\n * {@link accumulateCost} so a single unpriced child can't erase the\n * cost of priced siblings. Optional token sub-channels\n * (`cachedTokens`, etc.) accumulate only when some child reports\n * them, preserving the \"never reported anywhere\" signal.\n */\n private 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\n /**\n * Build the batch's own {@link BatchReport} node. `parentRunId` /\n * `rootRunId` are placeholders here — {@link stampReportLineage}\n * rewrites them across the whole subtree right after.\n */\n private buildReport(\n usage: Usage,\n children: BaseReport[],\n counts: { succeeded: number; failed: number; cancelled: number },\n ): BatchReport {\n const status = counts.failed > 0 || counts.cancelled > 0 ? \"failed\" : \"completed\";\n\n return {\n runId: this.runId,\n rootRunId: this.runId,\n name: this.options.name ?? \"batch\",\n type: \"batch\",\n status,\n startedAt: this.startedAt,\n endedAt: new Date().toISOString(),\n duration: performance.now() - this.startPerf,\n usage,\n children,\n total: this.items.length,\n succeeded: counts.succeeded,\n failed: counts.failed,\n cancelled: counts.cancelled,\n reportSchemaVersion: REPORT_SCHEMA_VERSION,\n };\n }\n}\n"],"mappings":";;;;;;;;;AAmBA,MAAM,iCAAiC;;AAGvC,IAAI,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmC3B,eAAsB,MACpB,YACA,OACA,UAAiC,CAAC,GACH;CAC/B,OAAO,IAAI,SAAS,YAAY,OAAO,OAAO,CAAC,CAAC,IAAI;AACtD;;;;;;;AAQA,IAAM,WAAN,MAA6D;CAM3D,AAAO,YACL,AAAiB,YACjB,AAAiB,OACjB,AAAiB,SACjB;EAHiB;EACA;EACA;oCANU,IAAI,KAAK,EAAC,CAAC,YAAY;mBACvB,YAAY,IAAI;EAO3C,KAAK,QAAQ,cAAc,OAAO;EAClC,KAAK,UAAU,IAAI,MAAgC,MAAM,MAAM;CACjE;;;;;CAMA,MAAa,MAAqC;EAChD,MAAM,cAA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
  */
112
112
  type BatchOptions<TResult extends BaseResult = ExecuteResult> = {
113
113
  /**
114
- * Maximum number of items running at once. A positive integer.
115
- * Defaults to `items.length` (all at once). Values `<= 0` are
116
- * treated as `1` (fully serial).
114
+ * Maximum number of items running at once. A positive integer, or the
115
+ * literal `"unbounded"` to run the whole dataset at once (every item
116
+ * concurrent). Values `<= 0` are treated as `1` (fully serial).
117
+ *
118
+ * Omitting it still runs unbounded (back-compat), but for a large batch
119
+ * (> 50 items) that emits a one-time warning (outside tests) — each
120
+ * concurrent item can consume tokens, provider quota, and memory, so an
121
+ * accidental unbounded run is a cost/DoS foot-gun. Pass an explicit
122
+ * number to cap it, or `"unbounded"` to acknowledge the all-at-once
123
+ * behavior and silence the warning. (D5)
117
124
  */
118
- concurrency?: number;
125
+ concurrency?: number | "unbounded";
119
126
  /**
120
127
  * Per-item retry policy, reusing the workflow {@link RetryConfig}
121
128
  * semantics (attempts, backoff, `retryOn`, `onRetry`). Applied
@@ -1 +1 @@
1
- {"version":3,"file":"batch.type.d.mts","names":[],"sources":["../../../../../../../@warlock.js/ai/src/batch/batch.type.ts"],"mappings":";;;;;;;;;AAaA;;;;AAA2B;KAAf,eAAA;;;;;;;;;;;;;;;;;;;;;;AAuCF;AAUV;;KAvBY,eAAA,iBAAgC,UAAA,GAAa,aAAA;EAuBrB,mEArBlC,KAAA,UAsBA;EApBA,MAAA,EAAQ,eAAA;EAwBR;;;;EAnBA,MAAA,GAAS,OAAA,EA8CC;EA5CV,KAAA,GAAQ,OAAA,EA4Ca;EA1CrB,QAAA;AAAA;;;;;;;;KAUU,WAAA,GAAc,UAAU;EAClC,IAAA,WA+BmD;EA7BnD,KAAA,UA8BA;EA5BA,SAAA,UAqCA;EAnCA,MAAA,UAqCO;EAnCP,SAAA;AAAA;;;AAqCmB;AAYrB;;;;;;;;;;;;;;;;;KA1BY,WAAA,iBAA4B,UAAA,GAAa,aAAA,IAAiB,IAAA,CACpE,aAAA;EAGA,IAAA;EAgCU;;;;;E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A;;;;;AA6CN;;KArCM,YAAA,iBAA6B,UAAA,GAAa,aAAA;;;;;;;;;;;;;EAapD,WAAA;;;;;;;EAOA,KAAA,GAAQ,WAAA;EAER,MAAA,GAAS,gBAAA,CAAiB,OAAA;;;;;;;EAO1B,MAAA,GAAS,WAAA;;;;;;EAMT,SAAA;EAEA,IAAA;AAAA"}
package/esm/config.d.mts CHANGED
@@ -23,8 +23,25 @@ import { CacheDriver } from "@warlock.js/cache";
23
23
  * Phase 3.2 deliberately removed the previous `configureAI()` bag
24
24
  * because it was growing unbounded. Treat new fields here with the
25
25
  * same suspicion.
26
+ *
27
+ * **Augmentable.** Declared as an `interface` (not a `type` alias) so
28
+ * observability/tooling packages can attach their own opaque config slot
29
+ * via declaration merging WITHOUT core importing them — keeping core
30
+ * dependency-free. For example `@warlock.js/ai-panoptic` adds a
31
+ * `panoptic?` field:
32
+ *
33
+ * ```ts
34
+ * declare module "@warlock.js/ai" {
35
+ * interface AIConfig {
36
+ * panoptic?: PanopticConfig;
37
+ * }
38
+ * }
39
+ * ```
40
+ *
41
+ * `setAIConfig` stores the whole object via `Object.assign`, so any
42
+ * augmented field is preserved even though core never reads it.
26
43
  */
27
- type AIConfig = {
44
+ interface AIConfig {
28
45
  /**
29
46
  * Default `@warlock.js/cache` driver for cache-backed consumers that
30
47
  * didn't supply their own `store` — currently the `semanticCache`
@@ -75,7 +92,26 @@ type AIConfig = {
75
92
  * ai.config({ defaultSnapshotStore: ai.snapshot.memory() });
76
93
  */
77
94
  defaultSnapshotStore?: SnapshotStore;
78
- };
95
+ }
96
+ /** A listener notified after every `setAIConfig` merge. */
97
+ type ConfigListener = (config: AIConfig) => void;
98
+ /**
99
+ * Subscribe to config changes. The listener fires after every
100
+ * {@link setAIConfig} merge with a fresh snapshot of the full config —
101
+ * the seam observability/tooling packages use to react when their
102
+ * augmented slot (e.g. `panoptic`) is set, WITHOUT core importing them.
103
+ *
104
+ * Mirrors the dependency-inversion of the `Observer` registry: core
105
+ * exposes the structural hook; the tool subscribes on its side-effect
106
+ * import. To also catch config that was applied *before* the subscription,
107
+ * read {@link getAIConfig} once right after subscribing.
108
+ *
109
+ * @example
110
+ * import { onConfigApplied, getAIConfig } from "@warlock.js/ai";
111
+ * onConfigApplied((config) => applyPanopticConfig(config.panoptic));
112
+ * applyPanopticConfig(getAIConfig().panoptic); // catch pre-set config
113
+ */
114
+ declare function onConfigApplied(listener: ConfigListener): void;
79
115
  /**
80
116
  * Set or extend process-wide AI configuration. Merges over existing
81
117
  * values — fields not present in `partial` keep whatever was set
@@ -122,5 +158,5 @@ declare function resolveDefaultCheckpointStore(): CheckpointStore | undefined;
122
158
  */
123
159
  declare function resolveDefaultSnapshotStore(): SnapshotStore | undefined;
124
160
  //#endregion
125
- export { AIConfig, getAIConfig, resolveDefaultCheckpointStore, resolveDefaultSnapshotStore, resolveDefaultStore, setAIConfig };
161
+ export { AIConfig, getAIConfig, onConfigApplied, resolveDefaultCheckpointStore, resolveDefaultSnapshotStore, resolveDefaultStore, setAIConfig };
126
162
  //# sourceMappingURL=config.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.mts","names":[],"sources":["../../../../../../@warlock.js/ai/src/config.ts"],"mappings":";;;;;;;AAyBA;;;;;;;;;;;;;;;AAoDsC;AAoBtC;;;KAxEY,QAAA;EAwEyB;;;;;;;;;AAA4B;AAUjE;;;;AAAuC;AAYvC;;;;AAAkD;AAUlD;;;EAhFE,YAAA,GAAe,WAAA;EAgF+C;AAUhE;;;;AAA4D;;;;;;;EA5E1D,sBAAA,GAAyB,eAAA;;;;;;;;;;;;;EAczB,oBAAA,GAAuB,aAAA;AAAA;;;;;;;;;;;;;;;;iBAoBT,WAAA,CAAY,OAAA,EAAS,OAAA,CAAQ,QAAA,IAAY,QAAA;;;;;;iBAUzC,WAAA,IAAe,QAAQ;;;;;;;;;iBAYvB,mBAAA,IAAuB,WAAW;;;;;;;iBAUlC,6BAAA,IAAiC,eAAe;;;;;;;iBAUhD,2BAAA,IAA+B,aAAa"}
1
+ {"version":3,"file":"config.d.mts","names":[],"sources":["../../../../../../@warlock.js/ai/src/config.ts"],"mappings":";;;;;;;AA0CA;;;;;;;;;;;;;;;AAoDsC;AACrC;;;;AAKsC;AAoBvC;;;;AAAwD;AAmBxD;;;;;;;;;;UAjGiB,QAAA;EAiGwC;;AAAQ;AAuBjE;;;;AAAuC;AAYvC;;;;AAAkD;AAUlD;;;;AAAgE;AAUhE;;;;AAA4D;EAhI1D,YAAA,GAAe,WAAA;;;;;;;;;;;;;EAcf,sBAAA,GAAyB,eAAA;;;;;;;;;;;;;EAczB,oBAAA,GAAuB,aAAA;AAAA;;KAMpB,cAAA,IAAkB,MAAgB,EAAR,QAAQ;;;;;;;;;;;;;;;;;iBAoBvB,eAAA,CAAgB,QAAwB,EAAd,cAAc;;;;;;;;;;;;;;;;iBAmBxC,WAAA,CAAY,OAAA,EAAS,OAAA,CAAQ,QAAA,IAAY,QAAA;;;;;;iBAuBzC,WAAA,IAAe,QAAQ;;;;;;;;;iBAYvB,mBAAA,IAAuB,WAAW;;;;;;;iBAUlC,6BAAA,IAAiC,eAAe;;;;;;;iBAUhD,2BAAA,IAA+B,aAAa"}
package/esm/config.mjs CHANGED
@@ -1,5 +1,25 @@
1
1
  //#region ../@warlock.js/ai/src/config.ts
2
2
  const aiConfig = {};
3
+ const configListeners = [];
4
+ /**
5
+ * Subscribe to config changes. The listener fires after every
6
+ * {@link setAIConfig} merge with a fresh snapshot of the full config —
7
+ * the seam observability/tooling packages use to react when their
8
+ * augmented slot (e.g. `panoptic`) is set, WITHOUT core importing them.
9
+ *
10
+ * Mirrors the dependency-inversion of the `Observer` registry: core
11
+ * exposes the structural hook; the tool subscribes on its side-effect
12
+ * import. To also catch config that was applied *before* the subscription,
13
+ * read {@link getAIConfig} once right after subscribing.
14
+ *
15
+ * @example
16
+ * import { onConfigApplied, getAIConfig } from "@warlock.js/ai";
17
+ * onConfigApplied((config) => applyPanopticConfig(config.panoptic));
18
+ * applyPanopticConfig(getAIConfig().panoptic); // catch pre-set config
19
+ */
20
+ function onConfigApplied(listener) {
21
+ configListeners.push(listener);
22
+ }
3
23
  /**
4
24
  * Set or extend process-wide AI configuration. Merges over existing
5
25
  * values — fields not present in `partial` keep whatever was set
@@ -17,7 +37,11 @@ const aiConfig = {};
17
37
  */
18
38
  function setAIConfig(partial) {
19
39
  Object.assign(aiConfig, partial);
20
- return { ...aiConfig };
40
+ const snapshot = { ...aiConfig };
41
+ for (const listener of configListeners) try {
42
+ listener(snapshot);
43
+ } catch {}
44
+ return snapshot;
21
45
  }
22
46
  /**
23
47
  * Read the current AI config snapshot. Returns a shallow copy so
@@ -58,5 +82,5 @@ function resolveDefaultSnapshotStore() {
58
82
  }
59
83
 
60
84
  //#endregion
61
- export { getAIConfig, resolveDefaultCheckpointStore, resolveDefaultSnapshotStore, resolveDefaultStore, setAIConfig };
85
+ export { getAIConfig, onConfigApplied, resolveDefaultCheckpointStore, resolveDefaultSnapshotStore, resolveDefaultStore, setAIConfig };
62
86
  //# sourceMappingURL=config.mjs.map