@warlock.js/ai 4.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (490) hide show
  1. package/README.md +72 -0
  2. package/cjs/index.cjs +8625 -0
  3. package/cjs/index.cjs.map +1 -0
  4. package/esm/agent/agent-config.type.d.mts +160 -0
  5. package/esm/agent/agent-config.type.d.mts.map +1 -0
  6. package/esm/agent/agent-input-builder.mjs +111 -0
  7. package/esm/agent/agent-input-builder.mjs.map +1 -0
  8. package/esm/agent/agent-log-event.mjs +101 -0
  9. package/esm/agent/agent-log-event.mjs.map +1 -0
  10. package/esm/agent/agent-stream.d.mts +47 -0
  11. package/esm/agent/agent-stream.d.mts.map +1 -0
  12. package/esm/agent/agent-stream.mjs +82 -0
  13. package/esm/agent/agent-stream.mjs.map +1 -0
  14. package/esm/agent/agent-to-stream-event.mjs +86 -0
  15. package/esm/agent/agent-to-stream-event.mjs.map +1 -0
  16. package/esm/agent/agent.d.mts +38 -0
  17. package/esm/agent/agent.d.mts.map +1 -0
  18. package/esm/agent/agent.mjs +974 -0
  19. package/esm/agent/agent.mjs.map +1 -0
  20. package/esm/agent/index.d.mts +3 -0
  21. package/esm/agent/index.mjs +4 -0
  22. package/esm/agent/json-stream-guard.mjs +400 -0
  23. package/esm/agent/json-stream-guard.mjs.map +1 -0
  24. package/esm/ai.d.mts +64 -0
  25. package/esm/ai.d.mts.map +1 -0
  26. package/esm/ai.mjs +65 -0
  27. package/esm/ai.mjs.map +1 -0
  28. package/esm/config.d.mts +79 -0
  29. package/esm/config.d.mts.map +1 -0
  30. package/esm/config.mjs +43 -0
  31. package/esm/config.mjs.map +1 -0
  32. package/esm/contracts/agent/agent-options.type.d.mts +132 -0
  33. package/esm/contracts/agent/agent-options.type.d.mts.map +1 -0
  34. package/esm/contracts/agent/agent.contract.d.mts +92 -0
  35. package/esm/contracts/agent/agent.contract.d.mts.map +1 -0
  36. package/esm/contracts/agent/index.d.mts +2 -0
  37. package/esm/contracts/attachment.type.d.mts +100 -0
  38. package/esm/contracts/attachment.type.d.mts.map +1 -0
  39. package/esm/contracts/content-part.type.d.mts +55 -0
  40. package/esm/contracts/content-part.type.d.mts.map +1 -0
  41. package/esm/contracts/conversation-message.type.d.mts +51 -0
  42. package/esm/contracts/conversation-message.type.d.mts.map +1 -0
  43. package/esm/contracts/embedder.contract.d.mts +69 -0
  44. package/esm/contracts/embedder.contract.d.mts.map +1 -0
  45. package/esm/contracts/end.type.d.mts +53 -0
  46. package/esm/contracts/end.type.d.mts.map +1 -0
  47. package/esm/contracts/end.type.mjs +47 -0
  48. package/esm/contracts/end.type.mjs.map +1 -0
  49. package/esm/contracts/events/agent-events.type.d.mts +71 -0
  50. package/esm/contracts/events/agent-events.type.d.mts.map +1 -0
  51. package/esm/contracts/events/complete-event.type.d.mts +33 -0
  52. package/esm/contracts/events/complete-event.type.d.mts.map +1 -0
  53. package/esm/contracts/events/event-identity.type.d.mts +30 -0
  54. package/esm/contracts/events/event-identity.type.d.mts.map +1 -0
  55. package/esm/contracts/events/event-map.type.d.mts +80 -0
  56. package/esm/contracts/events/event-map.type.d.mts.map +1 -0
  57. package/esm/contracts/events/index.d.mts +7 -0
  58. package/esm/contracts/events/supervisor-events.type.d.mts +162 -0
  59. package/esm/contracts/events/supervisor-events.type.d.mts.map +1 -0
  60. package/esm/contracts/events/usage-event.type.d.mts +39 -0
  61. package/esm/contracts/events/usage-event.type.d.mts.map +1 -0
  62. package/esm/contracts/events/workflow-events.type.d.mts +51 -0
  63. package/esm/contracts/events/workflow-events.type.d.mts.map +1 -0
  64. package/esm/contracts/executable.contract.d.mts +25 -0
  65. package/esm/contracts/executable.contract.d.mts.map +1 -0
  66. package/esm/contracts/finish-reason.type.d.mts +17 -0
  67. package/esm/contracts/finish-reason.type.d.mts.map +1 -0
  68. package/esm/contracts/index.d.mts +63 -0
  69. package/esm/contracts/middleware/index.d.mts +3 -0
  70. package/esm/contracts/middleware/middleware-context.type.d.mts +99 -0
  71. package/esm/contracts/middleware/middleware-context.type.d.mts.map +1 -0
  72. package/esm/contracts/middleware/middleware-state.type.d.mts +34 -0
  73. package/esm/contracts/middleware/middleware-state.type.d.mts.map +1 -0
  74. package/esm/contracts/middleware/middleware.contract.d.mts +140 -0
  75. package/esm/contracts/middleware/middleware.contract.d.mts.map +1 -0
  76. package/esm/contracts/model-tool-call-request.type.d.mts +58 -0
  77. package/esm/contracts/model-tool-call-request.type.d.mts.map +1 -0
  78. package/esm/contracts/model.contract.d.mts +164 -0
  79. package/esm/contracts/model.contract.d.mts.map +1 -0
  80. package/esm/contracts/placeholders.type.d.mts +23 -0
  81. package/esm/contracts/placeholders.type.d.mts.map +1 -0
  82. package/esm/contracts/result/agent-result.type.d.mts +33 -0
  83. package/esm/contracts/result/agent-result.type.d.mts.map +1 -0
  84. package/esm/contracts/result/attempt-entry.type.d.mts +40 -0
  85. package/esm/contracts/result/attempt-entry.type.d.mts.map +1 -0
  86. package/esm/contracts/result/base-report.type.d.mts +137 -0
  87. package/esm/contracts/result/base-report.type.d.mts.map +1 -0
  88. package/esm/contracts/result/base-report.type.mjs +17 -0
  89. package/esm/contracts/result/base-report.type.mjs.map +1 -0
  90. package/esm/contracts/result/base-result.type.d.mts +26 -0
  91. package/esm/contracts/result/base-result.type.d.mts.map +1 -0
  92. package/esm/contracts/result/execute-result.type.d.mts +40 -0
  93. package/esm/contracts/result/execute-result.type.d.mts.map +1 -0
  94. package/esm/contracts/result/execution-report.type.d.mts +50 -0
  95. package/esm/contracts/result/execution-report.type.d.mts.map +1 -0
  96. package/esm/contracts/result/index.d.mts +14 -0
  97. package/esm/contracts/result/llm-trip.type.d.mts +36 -0
  98. package/esm/contracts/result/llm-trip.type.d.mts.map +1 -0
  99. package/esm/contracts/result/model-pricing.type.d.mts +51 -0
  100. package/esm/contracts/result/model-pricing.type.d.mts.map +1 -0
  101. package/esm/contracts/result/session-send-result.type.d.mts +29 -0
  102. package/esm/contracts/result/session-send-result.type.d.mts.map +1 -0
  103. package/esm/contracts/result/step-result.type.d.mts +43 -0
  104. package/esm/contracts/result/step-result.type.d.mts.map +1 -0
  105. package/esm/contracts/result/supervisor-result.type.d.mts +86 -0
  106. package/esm/contracts/result/supervisor-result.type.d.mts.map +1 -0
  107. package/esm/contracts/result/tool-call.type.d.mts +44 -0
  108. package/esm/contracts/result/tool-call.type.d.mts.map +1 -0
  109. package/esm/contracts/result/usage.type.d.mts +57 -0
  110. package/esm/contracts/result/usage.type.d.mts.map +1 -0
  111. package/esm/contracts/result/workflow-result.type.d.mts +45 -0
  112. package/esm/contracts/result/workflow-result.type.d.mts.map +1 -0
  113. package/esm/contracts/sdk-adapter.contract.d.mts +77 -0
  114. package/esm/contracts/sdk-adapter.contract.d.mts.map +1 -0
  115. package/esm/contracts/stream/stream-event.type.d.mts +68 -0
  116. package/esm/contracts/stream/stream-event.type.d.mts.map +1 -0
  117. package/esm/contracts/stream/stream.contract.d.mts +61 -0
  118. package/esm/contracts/stream/stream.contract.d.mts.map +1 -0
  119. package/esm/contracts/streaming-tool-guard-config.type.d.mts +78 -0
  120. package/esm/contracts/streaming-tool-guard-config.type.d.mts.map +1 -0
  121. package/esm/contracts/supervisor/ack-entry.type.d.mts +97 -0
  122. package/esm/contracts/supervisor/ack-entry.type.d.mts.map +1 -0
  123. package/esm/contracts/supervisor/classifier-context.type.d.mts +189 -0
  124. package/esm/contracts/supervisor/classifier-context.type.d.mts.map +1 -0
  125. package/esm/contracts/supervisor/dispatch-context.type.d.mts +235 -0
  126. package/esm/contracts/supervisor/dispatch-context.type.d.mts.map +1 -0
  127. package/esm/contracts/supervisor/evaluate-context.type.d.mts +124 -0
  128. package/esm/contracts/supervisor/evaluate-context.type.d.mts.map +1 -0
  129. package/esm/contracts/supervisor/index.d.mts +16 -0
  130. package/esm/contracts/supervisor/intent-entry.type.d.mts +254 -0
  131. package/esm/contracts/supervisor/intent-entry.type.d.mts.map +1 -0
  132. package/esm/contracts/supervisor/iteration-snapshot.type.d.mts +117 -0
  133. package/esm/contracts/supervisor/iteration-snapshot.type.d.mts.map +1 -0
  134. package/esm/contracts/supervisor/next.type.d.mts +25 -0
  135. package/esm/contracts/supervisor/next.type.d.mts.map +1 -0
  136. package/esm/contracts/supervisor/route-context.type.d.mts +91 -0
  137. package/esm/contracts/supervisor/route-context.type.d.mts.map +1 -0
  138. package/esm/contracts/supervisor/router-entry.type.d.mts +67 -0
  139. package/esm/contracts/supervisor/router-entry.type.d.mts.map +1 -0
  140. package/esm/contracts/supervisor/supervisor-config.type.d.mts +356 -0
  141. package/esm/contracts/supervisor/supervisor-config.type.d.mts.map +1 -0
  142. package/esm/contracts/supervisor/supervisor-execute-options.type.d.mts +90 -0
  143. package/esm/contracts/supervisor/supervisor-execute-options.type.d.mts.map +1 -0
  144. package/esm/contracts/supervisor/supervisor-input.type.d.mts +24 -0
  145. package/esm/contracts/supervisor/supervisor-input.type.d.mts.map +1 -0
  146. package/esm/contracts/supervisor/supervisor-snapshot.type.d.mts +49 -0
  147. package/esm/contracts/supervisor/supervisor-snapshot.type.d.mts.map +1 -0
  148. package/esm/contracts/supervisor/supervisor-stream-event.type.d.mts +16 -0
  149. package/esm/contracts/supervisor/supervisor-stream-event.type.d.mts.map +1 -0
  150. package/esm/contracts/supervisor/supervisor.contract.d.mts +126 -0
  151. package/esm/contracts/supervisor/supervisor.contract.d.mts.map +1 -0
  152. package/esm/contracts/system-prompt.contract.d.mts +118 -0
  153. package/esm/contracts/system-prompt.contract.d.mts.map +1 -0
  154. package/esm/contracts/tool.contract.d.mts +161 -0
  155. package/esm/contracts/tool.contract.d.mts.map +1 -0
  156. package/esm/contracts/workflow/index.d.mts +6 -0
  157. package/esm/contracts/workflow/next-step-result.type.d.mts +17 -0
  158. package/esm/contracts/workflow/next-step-result.type.d.mts.map +1 -0
  159. package/esm/contracts/workflow/retry-config.type.d.mts +19 -0
  160. package/esm/contracts/workflow/retry-config.type.d.mts.map +1 -0
  161. package/esm/contracts/workflow/step.contract.d.mts +189 -0
  162. package/esm/contracts/workflow/step.contract.d.mts.map +1 -0
  163. package/esm/contracts/workflow/workflow-context.type.d.mts +45 -0
  164. package/esm/contracts/workflow/workflow-context.type.d.mts.map +1 -0
  165. package/esm/contracts/workflow/workflow-snapshot.type.d.mts +24 -0
  166. package/esm/contracts/workflow/workflow-snapshot.type.d.mts.map +1 -0
  167. package/esm/contracts/workflow/workflow.contract.d.mts +142 -0
  168. package/esm/contracts/workflow/workflow.contract.d.mts.map +1 -0
  169. package/esm/errors/agent-cancelled-error.d.mts +49 -0
  170. package/esm/errors/agent-cancelled-error.d.mts.map +1 -0
  171. package/esm/errors/agent-cancelled-error.mjs +43 -0
  172. package/esm/errors/agent-cancelled-error.mjs.map +1 -0
  173. package/esm/errors/agent-execution-error.d.mts +32 -0
  174. package/esm/errors/agent-execution-error.d.mts.map +1 -0
  175. package/esm/errors/agent-execution-error.mjs +35 -0
  176. package/esm/errors/agent-execution-error.mjs.map +1 -0
  177. package/esm/errors/agent-max-trips-error.d.mts +45 -0
  178. package/esm/errors/agent-max-trips-error.d.mts.map +1 -0
  179. package/esm/errors/agent-max-trips-error.mjs +41 -0
  180. package/esm/errors/agent-max-trips-error.mjs.map +1 -0
  181. package/esm/errors/ai-error.d.mts +94 -0
  182. package/esm/errors/ai-error.d.mts.map +1 -0
  183. package/esm/errors/ai-error.mjs +68 -0
  184. package/esm/errors/ai-error.mjs.map +1 -0
  185. package/esm/errors/budget-exceeded-error.d.mts +41 -0
  186. package/esm/errors/budget-exceeded-error.d.mts.map +1 -0
  187. package/esm/errors/budget-exceeded-error.mjs +31 -0
  188. package/esm/errors/budget-exceeded-error.mjs.map +1 -0
  189. package/esm/errors/content-filter-error.d.mts +33 -0
  190. package/esm/errors/content-filter-error.d.mts.map +1 -0
  191. package/esm/errors/content-filter-error.mjs +28 -0
  192. package/esm/errors/content-filter-error.mjs.map +1 -0
  193. package/esm/errors/context-length-exceeded-error.d.mts +38 -0
  194. package/esm/errors/context-length-exceeded-error.d.mts.map +1 -0
  195. package/esm/errors/context-length-exceeded-error.mjs +31 -0
  196. package/esm/errors/context-length-exceeded-error.mjs.map +1 -0
  197. package/esm/errors/error-category.type.d.mts +30 -0
  198. package/esm/errors/error-category.type.d.mts.map +1 -0
  199. package/esm/errors/error-code.type.d.mts +19 -0
  200. package/esm/errors/error-code.type.d.mts.map +1 -0
  201. package/esm/errors/guardrail-violation-error.d.mts +55 -0
  202. package/esm/errors/guardrail-violation-error.d.mts.map +1 -0
  203. package/esm/errors/guardrail-violation-error.mjs +41 -0
  204. package/esm/errors/guardrail-violation-error.mjs.map +1 -0
  205. package/esm/errors/index.d.mts +29 -0
  206. package/esm/errors/index.mjs +29 -0
  207. package/esm/errors/invalid-request-error.d.mts +27 -0
  208. package/esm/errors/invalid-request-error.d.mts.map +1 -0
  209. package/esm/errors/invalid-request-error.mjs +31 -0
  210. package/esm/errors/invalid-request-error.mjs.map +1 -0
  211. package/esm/errors/max-iterations-error.d.mts +31 -0
  212. package/esm/errors/max-iterations-error.d.mts.map +1 -0
  213. package/esm/errors/max-iterations-error.mjs +32 -0
  214. package/esm/errors/max-iterations-error.mjs.map +1 -0
  215. package/esm/errors/max-steps-exceeded-error.d.mts +20 -0
  216. package/esm/errors/max-steps-exceeded-error.d.mts.map +1 -0
  217. package/esm/errors/max-steps-exceeded-error.mjs +21 -0
  218. package/esm/errors/max-steps-exceeded-error.mjs.map +1 -0
  219. package/esm/errors/provider-auth-error.d.mts +22 -0
  220. package/esm/errors/provider-auth-error.d.mts.map +1 -0
  221. package/esm/errors/provider-auth-error.mjs +26 -0
  222. package/esm/errors/provider-auth-error.mjs.map +1 -0
  223. package/esm/errors/provider-error.d.mts +38 -0
  224. package/esm/errors/provider-error.d.mts.map +1 -0
  225. package/esm/errors/provider-error.mjs +42 -0
  226. package/esm/errors/provider-error.mjs.map +1 -0
  227. package/esm/errors/provider-rate-limit-error.d.mts +34 -0
  228. package/esm/errors/provider-rate-limit-error.d.mts.map +1 -0
  229. package/esm/errors/provider-rate-limit-error.mjs +31 -0
  230. package/esm/errors/provider-rate-limit-error.mjs.map +1 -0
  231. package/esm/errors/provider-timeout-error.d.mts +22 -0
  232. package/esm/errors/provider-timeout-error.d.mts.map +1 -0
  233. package/esm/errors/provider-timeout-error.mjs +26 -0
  234. package/esm/errors/provider-timeout-error.mjs.map +1 -0
  235. package/esm/errors/quota-exceeded-error.d.mts +36 -0
  236. package/esm/errors/quota-exceeded-error.d.mts.map +1 -0
  237. package/esm/errors/quota-exceeded-error.mjs +40 -0
  238. package/esm/errors/quota-exceeded-error.mjs.map +1 -0
  239. package/esm/errors/routing-error.d.mts +23 -0
  240. package/esm/errors/routing-error.d.mts.map +1 -0
  241. package/esm/errors/routing-error.mjs +23 -0
  242. package/esm/errors/routing-error.mjs.map +1 -0
  243. package/esm/errors/schema-validation-error.d.mts +40 -0
  244. package/esm/errors/schema-validation-error.d.mts.map +1 -0
  245. package/esm/errors/schema-validation-error.mjs +37 -0
  246. package/esm/errors/schema-validation-error.mjs.map +1 -0
  247. package/esm/errors/step-failed-error.d.mts +20 -0
  248. package/esm/errors/step-failed-error.d.mts.map +1 -0
  249. package/esm/errors/step-failed-error.mjs +19 -0
  250. package/esm/errors/step-failed-error.mjs.map +1 -0
  251. package/esm/errors/supervisor-cancelled-error.d.mts +29 -0
  252. package/esm/errors/supervisor-cancelled-error.d.mts.map +1 -0
  253. package/esm/errors/supervisor-cancelled-error.mjs +29 -0
  254. package/esm/errors/supervisor-cancelled-error.mjs.map +1 -0
  255. package/esm/errors/supervisor-drift-error.d.mts +31 -0
  256. package/esm/errors/supervisor-drift-error.d.mts.map +1 -0
  257. package/esm/errors/supervisor-drift-error.mjs +30 -0
  258. package/esm/errors/supervisor-drift-error.mjs.map +1 -0
  259. package/esm/errors/supervisor-failed-error.d.mts +40 -0
  260. package/esm/errors/supervisor-failed-error.d.mts.map +1 -0
  261. package/esm/errors/supervisor-failed-error.mjs +43 -0
  262. package/esm/errors/supervisor-failed-error.mjs.map +1 -0
  263. package/esm/errors/supervisor-routing-error.d.mts +44 -0
  264. package/esm/errors/supervisor-routing-error.d.mts.map +1 -0
  265. package/esm/errors/supervisor-routing-error.mjs +39 -0
  266. package/esm/errors/supervisor-routing-error.mjs.map +1 -0
  267. package/esm/errors/tool-execution-error.d.mts +35 -0
  268. package/esm/errors/tool-execution-error.d.mts.map +1 -0
  269. package/esm/errors/tool-execution-error.mjs +32 -0
  270. package/esm/errors/tool-execution-error.mjs.map +1 -0
  271. package/esm/errors/workflow-cancelled-error.d.mts +23 -0
  272. package/esm/errors/workflow-cancelled-error.d.mts.map +1 -0
  273. package/esm/errors/workflow-cancelled-error.mjs +23 -0
  274. package/esm/errors/workflow-cancelled-error.mjs.map +1 -0
  275. package/esm/errors/workflow-drift-error.d.mts +25 -0
  276. package/esm/errors/workflow-drift-error.d.mts.map +1 -0
  277. package/esm/errors/workflow-drift-error.mjs +24 -0
  278. package/esm/errors/workflow-drift-error.mjs.map +1 -0
  279. package/esm/errors/workflow-error.d.mts +15 -0
  280. package/esm/errors/workflow-error.d.mts.map +1 -0
  281. package/esm/errors/workflow-error.mjs +18 -0
  282. package/esm/errors/workflow-error.mjs.map +1 -0
  283. package/esm/index.d.mts +137 -0
  284. package/esm/index.mjs +81 -0
  285. package/esm/middleware/builtins/budget.d.mts +103 -0
  286. package/esm/middleware/builtins/budget.d.mts.map +1 -0
  287. package/esm/middleware/builtins/budget.mjs +100 -0
  288. package/esm/middleware/builtins/budget.mjs.map +1 -0
  289. package/esm/middleware/builtins/guardrail.d.mts +92 -0
  290. package/esm/middleware/builtins/guardrail.d.mts.map +1 -0
  291. package/esm/middleware/builtins/guardrail.mjs +76 -0
  292. package/esm/middleware/builtins/guardrail.mjs.map +1 -0
  293. package/esm/middleware/builtins/semantic-cache.d.mts +106 -0
  294. package/esm/middleware/builtins/semantic-cache.d.mts.map +1 -0
  295. package/esm/middleware/builtins/semantic-cache.mjs +149 -0
  296. package/esm/middleware/builtins/semantic-cache.mjs.map +1 -0
  297. package/esm/middleware/helpers/compose.d.mts +42 -0
  298. package/esm/middleware/helpers/compose.d.mts.map +1 -0
  299. package/esm/middleware/helpers/compose.mjs +52 -0
  300. package/esm/middleware/helpers/compose.mjs.map +1 -0
  301. package/esm/middleware/helpers/for-tool.d.mts +55 -0
  302. package/esm/middleware/helpers/for-tool.d.mts.map +1 -0
  303. package/esm/middleware/helpers/for-tool.mjs +80 -0
  304. package/esm/middleware/helpers/for-tool.mjs.map +1 -0
  305. package/esm/middleware/helpers/index.d.mts +2 -0
  306. package/esm/middleware/index.d.mts +8 -0
  307. package/esm/middleware/index.mjs +10 -0
  308. package/esm/middleware/pipeline.d.mts +70 -0
  309. package/esm/middleware/pipeline.d.mts.map +1 -0
  310. package/esm/middleware/pipeline.mjs +100 -0
  311. package/esm/middleware/pipeline.mjs.map +1 -0
  312. package/esm/middleware/utils/extract-user-text.d.mts +33 -0
  313. package/esm/middleware/utils/extract-user-text.d.mts.map +1 -0
  314. package/esm/middleware/utils/extract-user-text.mjs +40 -0
  315. package/esm/middleware/utils/extract-user-text.mjs.map +1 -0
  316. package/esm/middleware/utils/index.d.mts +2 -0
  317. package/esm/middleware/utils/namespaced-state.d.mts +60 -0
  318. package/esm/middleware/utils/namespaced-state.d.mts.map +1 -0
  319. package/esm/middleware/utils/namespaced-state.mjs +60 -0
  320. package/esm/middleware/utils/namespaced-state.mjs.map +1 -0
  321. package/esm/mock/index.d.mts +4 -0
  322. package/esm/mock/index.mjs +5 -0
  323. package/esm/mock/mock-agent.d.mts +41 -0
  324. package/esm/mock/mock-agent.d.mts.map +1 -0
  325. package/esm/mock/mock-agent.mjs +39 -0
  326. package/esm/mock/mock-agent.mjs.map +1 -0
  327. package/esm/mock/mock-config.type.d.mts +31 -0
  328. package/esm/mock/mock-config.type.d.mts.map +1 -0
  329. package/esm/mock/mock-model.d.mts +94 -0
  330. package/esm/mock/mock-model.d.mts.map +1 -0
  331. package/esm/mock/mock-model.mjs +150 -0
  332. package/esm/mock/mock-model.mjs.map +1 -0
  333. package/esm/mock/mock-sdk.d.mts +25 -0
  334. package/esm/mock/mock-sdk.d.mts.map +1 -0
  335. package/esm/mock/mock-sdk.mjs +37 -0
  336. package/esm/mock/mock-sdk.mjs.map +1 -0
  337. package/esm/supervisor/as-tool.d.mts +45 -0
  338. package/esm/supervisor/as-tool.d.mts.map +1 -0
  339. package/esm/supervisor/as-tool.mjs +80 -0
  340. package/esm/supervisor/as-tool.mjs.map +1 -0
  341. package/esm/supervisor/cancellation.d.mts +12 -0
  342. package/esm/supervisor/cancellation.d.mts.map +1 -0
  343. package/esm/supervisor/cancellation.mjs +22 -0
  344. package/esm/supervisor/cancellation.mjs.map +1 -0
  345. package/esm/supervisor/decide.mjs +272 -0
  346. package/esm/supervisor/decide.mjs.map +1 -0
  347. package/esm/supervisor/emitter.d.mts +27 -0
  348. package/esm/supervisor/emitter.d.mts.map +1 -0
  349. package/esm/supervisor/emitter.mjs +47 -0
  350. package/esm/supervisor/emitter.mjs.map +1 -0
  351. package/esm/supervisor/entries.d.mts +141 -0
  352. package/esm/supervisor/entries.d.mts.map +1 -0
  353. package/esm/supervisor/entries.mjs +206 -0
  354. package/esm/supervisor/entries.mjs.map +1 -0
  355. package/esm/supervisor/execution.d.mts +637 -0
  356. package/esm/supervisor/execution.d.mts.map +1 -0
  357. package/esm/supervisor/execution.mjs +1868 -0
  358. package/esm/supervisor/execution.mjs.map +1 -0
  359. package/esm/supervisor/index.d.mts +11 -0
  360. package/esm/supervisor/index.mjs +12 -0
  361. package/esm/supervisor/router-prompt.d.mts +56 -0
  362. package/esm/supervisor/router-prompt.d.mts.map +1 -0
  363. package/esm/supervisor/router-prompt.mjs +52 -0
  364. package/esm/supervisor/router-prompt.mjs.map +1 -0
  365. package/esm/supervisor/signature.d.mts +28 -0
  366. package/esm/supervisor/signature.d.mts.map +1 -0
  367. package/esm/supervisor/signature.mjs +89 -0
  368. package/esm/supervisor/signature.mjs.map +1 -0
  369. package/esm/supervisor/snapshot.d.mts +54 -0
  370. package/esm/supervisor/snapshot.d.mts.map +1 -0
  371. package/esm/supervisor/snapshot.mjs +77 -0
  372. package/esm/supervisor/snapshot.mjs.map +1 -0
  373. package/esm/supervisor/supervisor-stream.d.mts +29 -0
  374. package/esm/supervisor/supervisor-stream.d.mts.map +1 -0
  375. package/esm/supervisor/supervisor-stream.mjs +89 -0
  376. package/esm/supervisor/supervisor-stream.mjs.map +1 -0
  377. package/esm/supervisor/supervisor.d.mts +27 -0
  378. package/esm/supervisor/supervisor.d.mts.map +1 -0
  379. package/esm/supervisor/supervisor.mjs +138 -0
  380. package/esm/supervisor/supervisor.mjs.map +1 -0
  381. package/esm/system-prompt/instruction.d.mts +52 -0
  382. package/esm/system-prompt/instruction.d.mts.map +1 -0
  383. package/esm/system-prompt/instruction.mjs +57 -0
  384. package/esm/system-prompt/instruction.mjs.map +1 -0
  385. package/esm/system-prompt/persona.d.mts +52 -0
  386. package/esm/system-prompt/persona.d.mts.map +1 -0
  387. package/esm/system-prompt/persona.mjs +57 -0
  388. package/esm/system-prompt/persona.mjs.map +1 -0
  389. package/esm/system-prompt/render-placeholders.d.mts +31 -0
  390. package/esm/system-prompt/render-placeholders.d.mts.map +1 -0
  391. package/esm/system-prompt/render-placeholders.mjs +58 -0
  392. package/esm/system-prompt/render-placeholders.mjs.map +1 -0
  393. package/esm/system-prompt/system-prompt.d.mts +117 -0
  394. package/esm/system-prompt/system-prompt.d.mts.map +1 -0
  395. package/esm/system-prompt/system-prompt.mjs +137 -0
  396. package/esm/system-prompt/system-prompt.mjs.map +1 -0
  397. package/esm/tool/index.d.mts +1 -0
  398. package/esm/tool/index.mjs +3 -0
  399. package/esm/tool/tool.d.mts +64 -0
  400. package/esm/tool/tool.d.mts.map +1 -0
  401. package/esm/tool/tool.mjs +184 -0
  402. package/esm/tool/tool.mjs.map +1 -0
  403. package/esm/utils/compute-cost.d.mts +58 -0
  404. package/esm/utils/compute-cost.d.mts.map +1 -0
  405. package/esm/utils/compute-cost.mjs +87 -0
  406. package/esm/utils/compute-cost.mjs.map +1 -0
  407. package/esm/utils/extract-json-payload.d.mts +33 -0
  408. package/esm/utils/extract-json-payload.d.mts.map +1 -0
  409. package/esm/utils/extract-json-payload.mjs +39 -0
  410. package/esm/utils/extract-json-payload.mjs.map +1 -0
  411. package/esm/utils/generate-run-id.d.mts +20 -0
  412. package/esm/utils/generate-run-id.d.mts.map +1 -0
  413. package/esm/utils/generate-run-id.mjs +23 -0
  414. package/esm/utils/generate-run-id.mjs.map +1 -0
  415. package/esm/utils/index.d.mts +9 -0
  416. package/esm/utils/index.mjs +11 -0
  417. package/esm/utils/json-schema.d.mts +57 -0
  418. package/esm/utils/json-schema.d.mts.map +1 -0
  419. package/esm/utils/json-schema.mjs +89 -0
  420. package/esm/utils/json-schema.mjs.map +1 -0
  421. package/esm/utils/prepare-attachment-part.d.mts +36 -0
  422. package/esm/utils/prepare-attachment-part.d.mts.map +1 -0
  423. package/esm/utils/prepare-attachment-part.mjs +140 -0
  424. package/esm/utils/prepare-attachment-part.mjs.map +1 -0
  425. package/esm/utils/resolve-attachment.d.mts +33 -0
  426. package/esm/utils/resolve-attachment.d.mts.map +1 -0
  427. package/esm/utils/resolve-attachment.mjs +73 -0
  428. package/esm/utils/resolve-attachment.mjs.map +1 -0
  429. package/esm/utils/safe-json-parse.d.mts +14 -0
  430. package/esm/utils/safe-json-parse.d.mts.map +1 -0
  431. package/esm/utils/safe-json-parse.mjs +22 -0
  432. package/esm/utils/safe-json-parse.mjs.map +1 -0
  433. package/esm/utils/stamp-report-lineage.d.mts +61 -0
  434. package/esm/utils/stamp-report-lineage.d.mts.map +1 -0
  435. package/esm/utils/stamp-report-lineage.mjs +47 -0
  436. package/esm/utils/stamp-report-lineage.mjs.map +1 -0
  437. package/esm/utils/token-count.d.mts +15 -0
  438. package/esm/utils/token-count.d.mts.map +1 -0
  439. package/esm/utils/token-count.mjs +18 -0
  440. package/esm/utils/token-count.mjs.map +1 -0
  441. package/esm/workflow/as-tool.mjs +55 -0
  442. package/esm/workflow/as-tool.mjs.map +1 -0
  443. package/esm/workflow/cancellation.mjs +44 -0
  444. package/esm/workflow/cancellation.mjs.map +1 -0
  445. package/esm/workflow/emitter.mjs +40 -0
  446. package/esm/workflow/emitter.mjs.map +1 -0
  447. package/esm/workflow/engine.mjs +362 -0
  448. package/esm/workflow/engine.mjs.map +1 -0
  449. package/esm/workflow/index.d.mts +3 -0
  450. package/esm/workflow/index.mjs +5 -0
  451. package/esm/workflow/retry.mjs +32 -0
  452. package/esm/workflow/retry.mjs.map +1 -0
  453. package/esm/workflow/router.mjs +56 -0
  454. package/esm/workflow/router.mjs.map +1 -0
  455. package/esm/workflow/run-scoped-emitter.mjs +32 -0
  456. package/esm/workflow/run-scoped-emitter.mjs.map +1 -0
  457. package/esm/workflow/signature.d.mts +7 -0
  458. package/esm/workflow/signature.d.mts.map +1 -0
  459. package/esm/workflow/signature.mjs +34 -0
  460. package/esm/workflow/signature.mjs.map +1 -0
  461. package/esm/workflow/snapshot.mjs +71 -0
  462. package/esm/workflow/snapshot.mjs.map +1 -0
  463. package/esm/workflow/state.mjs +37 -0
  464. package/esm/workflow/state.mjs.map +1 -0
  465. package/esm/workflow/step-runner.mjs +371 -0
  466. package/esm/workflow/step-runner.mjs.map +1 -0
  467. package/esm/workflow/step.d.mts +19 -0
  468. package/esm/workflow/step.d.mts.map +1 -0
  469. package/esm/workflow/step.mjs +37 -0
  470. package/esm/workflow/step.mjs.map +1 -0
  471. package/esm/workflow/workflow.d.mts +12 -0
  472. package/esm/workflow/workflow.d.mts.map +1 -0
  473. package/esm/workflow/workflow.mjs +116 -0
  474. package/esm/workflow/workflow.mjs.map +1 -0
  475. package/llms-full.txt +2293 -0
  476. package/llms.txt +20 -0
  477. package/package.json +37 -0
  478. package/skills/README.md +53 -0
  479. package/skills/ai-basics/SKILL.md +95 -0
  480. package/skills/attach-ai-middleware/SKILL.md +184 -0
  481. package/skills/define-ai-tool/SKILL.md +186 -0
  482. package/skills/embed-text/SKILL.md +105 -0
  483. package/skills/handle-ai-errors/SKILL.md +194 -0
  484. package/skills/log-ai-calls/SKILL.md +141 -0
  485. package/skills/persist-ai-data/SKILL.md +207 -0
  486. package/skills/pick-ai-provider/SKILL.md +164 -0
  487. package/skills/run-ai-agent/SKILL.md +267 -0
  488. package/skills/run-ai-workflow/SKILL.md +258 -0
  489. package/skills/run-supervisor/SKILL.md +309 -0
  490. package/skills/write-system-prompt/SKILL.md +129 -0
@@ -0,0 +1,89 @@
1
+ //#region ../../@warlock.js/ai/src/utils/json-schema.ts
2
+ /**
3
+ * Best-effort JSON Schema extraction from a Standard Schema instance.
4
+ *
5
+ * Different libraries expose their JSON representation through different
6
+ * paths:
7
+ * - **Seal / Standard JSON Schema V1**: `["~standard"].jsonSchema.input({ target })`
8
+ * — nested under the spec object, takes a target switch. Default target
9
+ * is `"openai-strict"` since the primary consumer is OpenAI's native
10
+ * structured-output mechanism; pass `options.target` to override.
11
+ * - **Zod / similar**: top-level `.jsonSchema` property. Zod v4 actually
12
+ * ships `toJSONSchema` as a module function, not a method, so it does
13
+ * NOT hit this probe — Zod users pass their converted schema via the
14
+ * `AgentExecuteOptions.responseSchema` escape hatch.
15
+ *
16
+ * Deliberately does NOT probe `toJSON` — that's a generic JavaScript
17
+ * serialization hook (Seal's schemas have one that dumps internal rule
18
+ * state) and matching it would return garbage disguised as a JSON Schema.
19
+ *
20
+ * Returns `undefined` when no path matches. The caller then either skips
21
+ * native structured-output wiring or falls back to a schema-less
22
+ * instruction.
23
+ *
24
+ * Shared across every SDK adapter package (OpenAI, Anthropic, Bedrock…)
25
+ * so each provider converts schemas identically.
26
+ *
27
+ * @example
28
+ * const schema = extractJsonSchema(mySealSchema);
29
+ * // { type: "object", properties: { ... }, required: [ ... ], additionalProperties: false }
30
+ *
31
+ * @example
32
+ * // Ask for a different target explicitly
33
+ * const draft = extractJsonSchema(mySealSchema, { target: "draft-2020-12" });
34
+ */
35
+ function extractJsonSchema(schema, options = {}) {
36
+ if (!schema) return void 0;
37
+ const sealJsonSchema = extractFromSealPath(schema, options.target ?? "openai-strict");
38
+ if (sealJsonSchema) return sealJsonSchema;
39
+ const topLevel = extractFromCandidateKeys(schema);
40
+ if (topLevel) return topLevel;
41
+ }
42
+ /**
43
+ * Probe the Standard JSON Schema V1 extension path on `schema["~standard"]`.
44
+ * The spec defines `jsonSchema.input({ target, libraryOptions? })` as a
45
+ * function returning a JSON Schema tailored to the requested target. We
46
+ * pass the caller's target (default `"openai-strict"`) so the library
47
+ * produces output ready for OpenAI's native structured-output mode
48
+ * without additional post-processing.
49
+ *
50
+ * Calling `.input()` without a target would throw (or return garbage) per
51
+ * the spec — a failure here returns `undefined` so the fallback probe
52
+ * runs.
53
+ */
54
+ function extractFromSealPath(schema, target) {
55
+ const standardSlot = schema["~standard"];
56
+ if (!standardSlot || typeof standardSlot !== "object") return;
57
+ const jsonSchemaSlot = standardSlot["jsonSchema"];
58
+ if (!jsonSchemaSlot || typeof jsonSchemaSlot !== "object") return;
59
+ const inputFn = jsonSchemaSlot["input"];
60
+ if (typeof inputFn !== "function") return;
61
+ try {
62
+ const result = inputFn.call(jsonSchemaSlot, { target });
63
+ if (result && typeof result === "object") return result;
64
+ } catch {}
65
+ }
66
+ /**
67
+ * Probe well-known top-level keys libraries use to expose their JSON
68
+ * Schema. Supports both method form (rare) and property form (common).
69
+ * Deliberately narrow — `toJSON` is NOT probed here because it's a
70
+ * generic serialization hook that returns library-internal state for
71
+ * many validators (Seal included), not a JSON Schema.
72
+ */
73
+ function extractFromCandidateKeys(schemaRecord) {
74
+ for (const key of ["jsonSchema", "_jsonSchema"]) {
75
+ const value = schemaRecord[key];
76
+ if (typeof value === "function") {
77
+ try {
78
+ const result = value.call(schemaRecord);
79
+ if (result && typeof result === "object") return result;
80
+ } catch {}
81
+ continue;
82
+ }
83
+ if (value && typeof value === "object") return value;
84
+ }
85
+ }
86
+
87
+ //#endregion
88
+ export { extractJsonSchema };
89
+ //# sourceMappingURL=json-schema.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-schema.mjs","names":[],"sources":["../../../../../../@warlock.js/ai/src/utils/json-schema.ts"],"sourcesContent":["import type { StandardSchemaV1 } from \"@standard-schema/spec\";\n\n/**\n * Supported JSON Schema output targets per the Standard JSON Schema V1\n * spec. `openai-strict` is the richest for OpenAI structured outputs —\n * every property listed in `required`, optionals expressed as\n * `[\"T\", \"null\"]`, `additionalProperties: false` everywhere. Other\n * targets produce standards-compliant but looser output.\n */\nexport type JsonSchemaTarget = \"draft-2020-12\" | \"draft-07\" | \"openapi-3.0\" | \"openai-strict\";\n\n/**\n * Options for `extractJsonSchema`. `target` is forwarded to libraries that\n * implement the Standard JSON Schema V1 spec (Seal, and any future lib\n * that follows the spec). Libraries using their own top-level `.jsonSchema`\n * / `._jsonSchema` property ignore the target.\n */\nexport type ExtractJsonSchemaOptions = {\n target?: JsonSchemaTarget | (string & {});\n};\n\n/**\n * Best-effort JSON Schema extraction from a Standard Schema instance.\n *\n * Different libraries expose their JSON representation through different\n * paths:\n * - **Seal / Standard JSON Schema V1**: `[\"~standard\"].jsonSchema.input({ target })`\n * — nested under the spec object, takes a target switch. Default target\n * is `\"openai-strict\"` since the primary consumer is OpenAI's native\n * structured-output mechanism; pass `options.target` to override.\n * - **Zod / similar**: top-level `.jsonSchema` property. Zod v4 actually\n * ships `toJSONSchema` as a module function, not a method, so it does\n * NOT hit this probe — Zod users pass their converted schema via the\n * `AgentExecuteOptions.responseSchema` escape hatch.\n *\n * Deliberately does NOT probe `toJSON` — that's a generic JavaScript\n * serialization hook (Seal's schemas have one that dumps internal rule\n * state) and matching it would return garbage disguised as a JSON Schema.\n *\n * Returns `undefined` when no path matches. The caller then either skips\n * native structured-output wiring or falls back to a schema-less\n * instruction.\n *\n * Shared across every SDK adapter package (OpenAI, Anthropic, Bedrock…)\n * so each provider converts schemas identically.\n *\n * @example\n * const schema = extractJsonSchema(mySealSchema);\n * // { type: \"object\", properties: { ... }, required: [ ... ], additionalProperties: false }\n *\n * @example\n * // Ask for a different target explicitly\n * const draft = extractJsonSchema(mySealSchema, { target: \"draft-2020-12\" });\n */\nexport function extractJsonSchema(\n schema: StandardSchemaV1<unknown> | undefined,\n options: ExtractJsonSchemaOptions = {},\n): Record<string, unknown> | undefined {\n if (!schema) return undefined;\n\n const target = options.target ?? \"openai-strict\";\n\n // 1. Seal / Standard JSON Schema V1 pattern: [\"~standard\"].jsonSchema.input({ target })\n const sealJsonSchema = extractFromSealPath(schema, target);\n\n if (sealJsonSchema) {\n return sealJsonSchema;\n }\n\n // 2. Top-level jsonSchema / _jsonSchema (Zod-like, property or method form)\n const topLevel = extractFromCandidateKeys(schema as unknown as Record<string, unknown>);\n\n if (topLevel) {\n return topLevel;\n }\n\n return undefined;\n}\n\n/**\n * Probe the Standard JSON Schema V1 extension path on `schema[\"~standard\"]`.\n * The spec defines `jsonSchema.input({ target, libraryOptions? })` as a\n * function returning a JSON Schema tailored to the requested target. We\n * pass the caller's target (default `\"openai-strict\"`) so the library\n * produces output ready for OpenAI's native structured-output mode\n * without additional post-processing.\n *\n * Calling `.input()` without a target would throw (or return garbage) per\n * the spec — a failure here returns `undefined` so the fallback probe\n * runs.\n */\nfunction extractFromSealPath(\n schema: StandardSchemaV1<unknown>,\n target: string,\n): Record<string, unknown> | undefined {\n const standardSlot = (schema as unknown as Record<string, unknown>)[\"~standard\"];\n\n if (!standardSlot || typeof standardSlot !== \"object\") {\n return undefined;\n }\n\n const jsonSchemaSlot = (standardSlot as Record<string, unknown>)[\"jsonSchema\"];\n\n if (!jsonSchemaSlot || typeof jsonSchemaSlot !== \"object\") {\n return undefined;\n }\n\n const inputFn = (jsonSchemaSlot as Record<string, unknown>)[\"input\"];\n\n if (typeof inputFn !== \"function\") {\n return undefined;\n }\n\n try {\n const result = (inputFn as (options: { target: string }) => unknown).call(jsonSchemaSlot, {\n target,\n });\n\n if (result && typeof result === \"object\") {\n return result as Record<string, unknown>;\n }\n } catch {\n // fall through — library didn't support the target or threw otherwise\n }\n\n return undefined;\n}\n\n/**\n * Probe well-known top-level keys libraries use to expose their JSON\n * Schema. Supports both method form (rare) and property form (common).\n * Deliberately narrow — `toJSON` is NOT probed here because it's a\n * generic serialization hook that returns library-internal state for\n * many validators (Seal included), not a JSON Schema.\n */\nfunction extractFromCandidateKeys(\n schemaRecord: Record<string, unknown>,\n): Record<string, unknown> | undefined {\n const candidateKeys = [\"jsonSchema\", \"_jsonSchema\"] as const;\n\n for (const key of candidateKeys) {\n const value = schemaRecord[key];\n\n if (typeof value === \"function\") {\n try {\n const result = (value as () => unknown).call(schemaRecord);\n\n if (result && typeof result === \"object\") {\n return result as Record<string, unknown>;\n }\n } catch {\n // try next candidate\n }\n\n continue;\n }\n\n if (value && typeof value === \"object\") {\n return value as Record<string, unknown>;\n }\n }\n\n return undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsDA,SAAgB,kBACd,QACA,UAAoC,CAAC,GACA;CACrC,IAAI,CAAC,QAAQ,OAAO;CAKpB,MAAM,iBAAiB,oBAAoB,QAH5B,QAAQ,UAAU,eAGwB;CAEzD,IAAI,gBACF,OAAO;CAIT,MAAM,WAAW,yBAAyB,MAA4C;CAEtF,IAAI,UACF,OAAO;AAIX;;;;;;;;;;;;;AAcA,SAAS,oBACP,QACA,QACqC;CACrC,MAAM,eAAgB,OAA8C;CAEpE,IAAI,CAAC,gBAAgB,OAAO,iBAAiB,UAC3C;CAGF,MAAM,iBAAkB,aAAyC;CAEjE,IAAI,CAAC,kBAAkB,OAAO,mBAAmB,UAC/C;CAGF,MAAM,UAAW,eAA2C;CAE5D,IAAI,OAAO,YAAY,YACrB;CAGF,IAAI;EACF,MAAM,SAAU,QAAqD,KAAK,gBAAgB,EACxF,OACF,CAAC;EAED,IAAI,UAAU,OAAO,WAAW,UAC9B,OAAO;CAEX,QAAQ,CAER;AAGF;;;;;;;;AASA,SAAS,yBACP,cACqC;CAGrC,KAAK,MAAM,OAAO,CAFK,cAAc,aAEP,GAAG;EAC/B,MAAM,QAAQ,aAAa;EAE3B,IAAI,OAAO,UAAU,YAAY;GAC/B,IAAI;IACF,MAAM,SAAU,MAAwB,KAAK,YAAY;IAEzD,IAAI,UAAU,OAAO,WAAW,UAC9B,OAAO;GAEX,QAAQ,CAER;GAEA;EACF;EAEA,IAAI,SAAS,OAAO,UAAU,UAC5B,OAAO;CAEX;AAGF"}
@@ -0,0 +1,36 @@
1
+ import { Attachment } from "../contracts/attachment.type.mjs";
2
+ import { ContentPart } from "../contracts/content-part.type.mjs";
3
+
4
+ //#region ../../@warlock.js/ai/src/utils/prepare-attachment-part.d.ts
5
+ /**
6
+ * Convert a user-supplied `Attachment` into a provider-ready
7
+ * `ContentPart` the model adapter can consume without doing any I/O of
8
+ * its own.
9
+ *
10
+ * Kind resolution:
11
+ * - Tagged `{ type: "image", source }` / `{ type: "text", source }`
12
+ * trusts the caller's intent.
13
+ * - Shorthand (raw string / `StorageFileShape`) infers from the file
14
+ * extension. Image extensions (`.png`/`.jpg`/`.jpeg`/`.webp`/`.gif`)
15
+ * map to `"image"`. `.txt` maps to `"text"`. Anything else throws
16
+ * `InvalidRequestError` — silent inference on ambiguous inputs
17
+ * causes silent bugs.
18
+ *
19
+ * Local paths are read from disk; images are base64-encoded inline,
20
+ * text files are read as UTF-8 strings and returned as a `text`
21
+ * `ContentPart`. Remote URLs for image attachments are passed through
22
+ * unchanged; remote URLs for text attachments are fetched so the
23
+ * adapter never needs network access.
24
+ *
25
+ * @example
26
+ * await prepareAttachmentPart("./photo.png");
27
+ * // → { type: "image", source: { base64: "...", mediaType: "image/png" } }
28
+ *
29
+ * @example
30
+ * await prepareAttachmentPart({ type: "text", source: "./notes.txt" });
31
+ * // → { type: "text", text: "<file contents>" }
32
+ */
33
+ declare function prepareAttachmentPart(attachment: Attachment): Promise<ContentPart>;
34
+ //#endregion
35
+ export { prepareAttachmentPart };
36
+ //# sourceMappingURL=prepare-attachment-part.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prepare-attachment-part.d.mts","names":[],"sources":["../../../../../../@warlock.js/ai/src/utils/prepare-attachment-part.ts"],"mappings":";;;;;;AA+CA;;;;;;;;;;;;;AAEsB;;;;;;;;;;;;;iBAFA,qBAAA,CACpB,UAAA,EAAY,UAAA,GACX,OAAA,CAAQ,WAAA"}
@@ -0,0 +1,140 @@
1
+ import { InvalidRequestError } from "../errors/invalid-request-error.mjs";
2
+ import "../errors/index.mjs";
3
+ import { resolveAttachment } from "./resolve-attachment.mjs";
4
+ import { readFile } from "node:fs/promises";
5
+ import { extname } from "node:path";
6
+
7
+ //#region ../../@warlock.js/ai/src/utils/prepare-attachment-part.ts
8
+ const IMAGE_EXTENSIONS_TO_MEDIA_TYPE = {
9
+ ".png": "image/png",
10
+ ".jpg": "image/jpeg",
11
+ ".jpeg": "image/jpeg",
12
+ ".webp": "image/webp",
13
+ ".gif": "image/gif"
14
+ };
15
+ const TEXT_EXTENSIONS = new Set([".txt"]);
16
+ /**
17
+ * Convert a user-supplied `Attachment` into a provider-ready
18
+ * `ContentPart` the model adapter can consume without doing any I/O of
19
+ * its own.
20
+ *
21
+ * Kind resolution:
22
+ * - Tagged `{ type: "image", source }` / `{ type: "text", source }`
23
+ * trusts the caller's intent.
24
+ * - Shorthand (raw string / `StorageFileShape`) infers from the file
25
+ * extension. Image extensions (`.png`/`.jpg`/`.jpeg`/`.webp`/`.gif`)
26
+ * map to `"image"`. `.txt` maps to `"text"`. Anything else throws
27
+ * `InvalidRequestError` — silent inference on ambiguous inputs
28
+ * causes silent bugs.
29
+ *
30
+ * Local paths are read from disk; images are base64-encoded inline,
31
+ * text files are read as UTF-8 strings and returned as a `text`
32
+ * `ContentPart`. Remote URLs for image attachments are passed through
33
+ * unchanged; remote URLs for text attachments are fetched so the
34
+ * adapter never needs network access.
35
+ *
36
+ * @example
37
+ * await prepareAttachmentPart("./photo.png");
38
+ * // → { type: "image", source: { base64: "...", mediaType: "image/png" } }
39
+ *
40
+ * @example
41
+ * await prepareAttachmentPart({ type: "text", source: "./notes.txt" });
42
+ * // → { type: "text", text: "<file contents>" }
43
+ */
44
+ async function prepareAttachmentPart(attachment) {
45
+ if (resolveKind(attachment) === "text") return prepareTextPart(attachment);
46
+ return prepareImagePart(attachment);
47
+ }
48
+ /**
49
+ * Decide whether the attachment is text or image. Tagged forms win
50
+ * immediately; for shorthand we inspect the extension. Throws if the
51
+ * shorthand doesn't look like anything we recognize.
52
+ */
53
+ function resolveKind(attachment) {
54
+ if (isTaggedAttachment(attachment)) return attachment.type;
55
+ const path = extractPath(attachment);
56
+ const extension = path ? extname(stripQuery(path)).toLowerCase() : "";
57
+ if (IMAGE_EXTENSIONS_TO_MEDIA_TYPE[extension]) return "image";
58
+ if (TEXT_EXTENSIONS.has(extension)) return "text";
59
+ throw new InvalidRequestError("Cannot infer attachment type from input — pass an explicit `{ type: 'image' | 'text', source: ... }` or use a recognized extension (.png, .jpg, .jpeg, .webp, .gif, .txt)");
60
+ }
61
+ /**
62
+ * Produce an `image` ContentPart. URLs pass through; paths are
63
+ * read from disk and base64-encoded with an inferred media type.
64
+ * Inline base64 attachments pass through unchanged.
65
+ */
66
+ async function prepareImagePart(attachment) {
67
+ const inferredMediaType = isTaggedAttachment(attachment) ? void 0 : inferImageMediaType(attachment);
68
+ const resolved = resolveAttachment(attachment);
69
+ if (resolved.type === "url") return {
70
+ type: "image",
71
+ source: { url: resolved.value }
72
+ };
73
+ if (resolved.type === "base64") return {
74
+ type: "image",
75
+ source: {
76
+ base64: resolved.value,
77
+ mediaType: resolved.mediaType
78
+ }
79
+ };
80
+ const mediaType = inferredMediaType ?? inferImageMediaType(resolved.value);
81
+ if (!mediaType) throw new InvalidRequestError(`Cannot infer media type for path "${resolved.value}" — use a recognized image extension or pass \`{ type: 'image', source: { base64, mediaType } }\``, { context: { path: resolved.value } });
82
+ return {
83
+ type: "image",
84
+ source: {
85
+ base64: (await readFile(resolved.value)).toString("base64"),
86
+ mediaType
87
+ }
88
+ };
89
+ }
90
+ /**
91
+ * Produce a `text` ContentPart. URLs are fetched as UTF-8, paths are
92
+ * read from disk as UTF-8, inline base64 is decoded to UTF-8. The
93
+ * result joins the conversation as an additional text part the model
94
+ * sees before responding.
95
+ */
96
+ async function prepareTextPart(attachment) {
97
+ const resolved = resolveAttachment(attachment);
98
+ if (resolved.type === "url") {
99
+ const response = await fetch(resolved.value);
100
+ if (!response.ok) throw new InvalidRequestError(`Failed to fetch text attachment "${resolved.value}" — status ${response.status}`, { context: {
101
+ url: resolved.value,
102
+ status: response.status
103
+ } });
104
+ return {
105
+ type: "text",
106
+ text: await response.text()
107
+ };
108
+ }
109
+ if (resolved.type === "base64") return {
110
+ type: "text",
111
+ text: Buffer.from(resolved.value, "base64").toString("utf8")
112
+ };
113
+ return {
114
+ type: "text",
115
+ text: await readFile(resolved.value, "utf8")
116
+ };
117
+ }
118
+ function isTaggedAttachment(attachment) {
119
+ return typeof attachment === "object" && attachment !== null && "type" in attachment;
120
+ }
121
+ function inferImageMediaType(input) {
122
+ const path = extractPath(input);
123
+ if (!path) return;
124
+ return IMAGE_EXTENSIONS_TO_MEDIA_TYPE[extname(stripQuery(path)).toLowerCase()];
125
+ }
126
+ function extractPath(input) {
127
+ if (typeof input === "string") return input;
128
+ if (typeof input === "object" && input !== null) {
129
+ const storage = input;
130
+ return storage.url ?? storage.absolutePath;
131
+ }
132
+ }
133
+ function stripQuery(path) {
134
+ const queryIndex = path.indexOf("?");
135
+ return queryIndex === -1 ? path : path.slice(0, queryIndex);
136
+ }
137
+
138
+ //#endregion
139
+ export { prepareAttachmentPart };
140
+ //# sourceMappingURL=prepare-attachment-part.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prepare-attachment-part.mjs","names":[],"sources":["../../../../../../@warlock.js/ai/src/utils/prepare-attachment-part.ts"],"sourcesContent":["import { readFile } from \"node:fs/promises\";\nimport { extname } from \"node:path\";\nimport type { Attachment } from \"../contracts/attachment.type\";\nimport type { ContentPart } from \"../contracts/content-part.type\";\nimport { InvalidRequestError } from \"../errors\";\nimport { resolveAttachment } from \"./resolve-attachment\";\n\nconst IMAGE_EXTENSIONS_TO_MEDIA_TYPE: Record<string, string> = {\n \".png\": \"image/png\",\n \".jpg\": \"image/jpeg\",\n \".jpeg\": \"image/jpeg\",\n \".webp\": \"image/webp\",\n \".gif\": \"image/gif\",\n};\n\nconst TEXT_EXTENSIONS = new Set([\".txt\"]);\n\ntype AttachmentKind = \"image\" | \"text\";\n\n/**\n * Convert a user-supplied `Attachment` into a provider-ready\n * `ContentPart` the model adapter can consume without doing any I/O of\n * its own.\n *\n * Kind resolution:\n * - Tagged `{ type: \"image\", source }` / `{ type: \"text\", source }`\n * trusts the caller's intent.\n * - Shorthand (raw string / `StorageFileShape`) infers from the file\n * extension. Image extensions (`.png`/`.jpg`/`.jpeg`/`.webp`/`.gif`)\n * map to `\"image\"`. `.txt` maps to `\"text\"`. Anything else throws\n * `InvalidRequestError` — silent inference on ambiguous inputs\n * causes silent bugs.\n *\n * Local paths are read from disk; images are base64-encoded inline,\n * text files are read as UTF-8 strings and returned as a `text`\n * `ContentPart`. Remote URLs for image attachments are passed through\n * unchanged; remote URLs for text attachments are fetched so the\n * adapter never needs network access.\n *\n * @example\n * await prepareAttachmentPart(\"./photo.png\");\n * // → { type: \"image\", source: { base64: \"...\", mediaType: \"image/png\" } }\n *\n * @example\n * await prepareAttachmentPart({ type: \"text\", source: \"./notes.txt\" });\n * // → { type: \"text\", text: \"<file contents>\" }\n */\nexport async function prepareAttachmentPart(\n attachment: Attachment,\n): Promise<ContentPart> {\n const kind = resolveKind(attachment);\n\n if (kind === \"text\") {\n return prepareTextPart(attachment);\n }\n\n return prepareImagePart(attachment);\n}\n\n/**\n * Decide whether the attachment is text or image. Tagged forms win\n * immediately; for shorthand we inspect the extension. Throws if the\n * shorthand doesn't look like anything we recognize.\n */\nfunction resolveKind(attachment: Attachment): AttachmentKind {\n if (isTaggedAttachment(attachment)) {\n return attachment.type;\n }\n\n const path = extractPath(attachment);\n const extension = path ? extname(stripQuery(path)).toLowerCase() : \"\";\n\n if (IMAGE_EXTENSIONS_TO_MEDIA_TYPE[extension]) {\n return \"image\";\n }\n\n if (TEXT_EXTENSIONS.has(extension)) {\n return \"text\";\n }\n\n throw new InvalidRequestError(\n \"Cannot infer attachment type from input — pass an explicit `{ type: 'image' | 'text', source: ... }` or use a recognized extension (.png, .jpg, .jpeg, .webp, .gif, .txt)\",\n );\n}\n\n/**\n * Produce an `image` ContentPart. URLs pass through; paths are\n * read from disk and base64-encoded with an inferred media type.\n * Inline base64 attachments pass through unchanged.\n */\nasync function prepareImagePart(attachment: Attachment): Promise<ContentPart> {\n const inferredMediaType = isTaggedAttachment(attachment)\n ? undefined\n : inferImageMediaType(attachment);\n\n const resolved = resolveAttachment(attachment);\n\n if (resolved.type === \"url\") {\n return { type: \"image\", source: { url: resolved.value } };\n }\n\n if (resolved.type === \"base64\") {\n return {\n type: \"image\",\n source: { base64: resolved.value, mediaType: resolved.mediaType },\n };\n }\n\n const mediaType = inferredMediaType ?? inferImageMediaType(resolved.value);\n\n if (!mediaType) {\n throw new InvalidRequestError(\n `Cannot infer media type for path \"${resolved.value}\" — use a recognized image extension or pass ` +\n \"`{ type: 'image', source: { base64, mediaType } }`\",\n { context: { path: resolved.value } },\n );\n }\n\n const bytes = await readFile(resolved.value);\n\n return {\n type: \"image\",\n source: { base64: bytes.toString(\"base64\"), mediaType },\n };\n}\n\n/**\n * Produce a `text` ContentPart. URLs are fetched as UTF-8, paths are\n * read from disk as UTF-8, inline base64 is decoded to UTF-8. The\n * result joins the conversation as an additional text part the model\n * sees before responding.\n */\nasync function prepareTextPart(attachment: Attachment): Promise<ContentPart> {\n const resolved = resolveAttachment(attachment);\n\n if (resolved.type === \"url\") {\n const response = await fetch(resolved.value);\n\n if (!response.ok) {\n throw new InvalidRequestError(\n `Failed to fetch text attachment \"${resolved.value}\" — status ${response.status}`,\n { context: { url: resolved.value, status: response.status } },\n );\n }\n\n return { type: \"text\", text: await response.text() };\n }\n\n if (resolved.type === \"base64\") {\n const decoded = Buffer.from(resolved.value, \"base64\").toString(\"utf8\");\n\n return { type: \"text\", text: decoded };\n }\n\n const bytes = await readFile(resolved.value, \"utf8\");\n\n return { type: \"text\", text: bytes };\n}\n\nfunction isTaggedAttachment(\n attachment: Attachment,\n): attachment is Extract<Attachment, { type: string }> {\n return (\n typeof attachment === \"object\" &&\n attachment !== null &&\n \"type\" in attachment\n );\n}\n\nfunction inferImageMediaType(input: unknown): string | undefined {\n const path = extractPath(input);\n\n if (!path) {\n return undefined;\n }\n\n const extension = extname(stripQuery(path)).toLowerCase();\n\n return IMAGE_EXTENSIONS_TO_MEDIA_TYPE[extension];\n}\n\nfunction extractPath(input: unknown): string | undefined {\n if (typeof input === \"string\") {\n return input;\n }\n\n if (typeof input === \"object\" && input !== null) {\n const storage = input as { url?: string; absolutePath?: string };\n return storage.url ?? storage.absolutePath;\n }\n\n return undefined;\n}\n\nfunction stripQuery(path: string): string {\n const queryIndex = path.indexOf(\"?\");\n\n return queryIndex === -1 ? path : path.slice(0, queryIndex);\n}\n"],"mappings":";;;;;;;AAOA,MAAM,iCAAyD;CAC7D,QAAQ;CACR,QAAQ;CACR,SAAS;CACT,SAAS;CACT,QAAQ;AACV;AAEA,MAAM,kBAAkB,IAAI,IAAI,CAAC,MAAM,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCxC,eAAsB,sBACpB,YACsB;CAGtB,IAFa,YAAY,UAElB,MAAM,QACX,OAAO,gBAAgB,UAAU;CAGnC,OAAO,iBAAiB,UAAU;AACpC;;;;;;AAOA,SAAS,YAAY,YAAwC;CAC3D,IAAI,mBAAmB,UAAU,GAC/B,OAAO,WAAW;CAGpB,MAAM,OAAO,YAAY,UAAU;CACnC,MAAM,YAAY,OAAO,QAAQ,WAAW,IAAI,CAAC,EAAE,YAAY,IAAI;CAEnE,IAAI,+BAA+B,YACjC,OAAO;CAGT,IAAI,gBAAgB,IAAI,SAAS,GAC/B,OAAO;CAGT,MAAM,IAAI,oBACR,2KACF;AACF;;;;;;AAOA,eAAe,iBAAiB,YAA8C;CAC5E,MAAM,oBAAoB,mBAAmB,UAAU,IACnD,SACA,oBAAoB,UAAU;CAElC,MAAM,WAAW,kBAAkB,UAAU;CAE7C,IAAI,SAAS,SAAS,OACpB,OAAO;EAAE,MAAM;EAAS,QAAQ,EAAE,KAAK,SAAS,MAAM;CAAE;CAG1D,IAAI,SAAS,SAAS,UACpB,OAAO;EACL,MAAM;EACN,QAAQ;GAAE,QAAQ,SAAS;GAAO,WAAW,SAAS;EAAU;CAClE;CAGF,MAAM,YAAY,qBAAqB,oBAAoB,SAAS,KAAK;CAEzE,IAAI,CAAC,WACH,MAAM,IAAI,oBACR,qCAAqC,SAAS,MAAM,oGAEpD,EAAE,SAAS,EAAE,MAAM,SAAS,MAAM,EAAE,CACtC;CAKF,OAAO;EACL,MAAM;EACN,QAAQ;GAAE,SAAQ,MAJA,SAAS,SAAS,KAAK,GAIjB,SAAS,QAAQ;GAAG;EAAU;CACxD;AACF;;;;;;;AAQA,eAAe,gBAAgB,YAA8C;CAC3E,MAAM,WAAW,kBAAkB,UAAU;CAE7C,IAAI,SAAS,SAAS,OAAO;EAC3B,MAAM,WAAW,MAAM,MAAM,SAAS,KAAK;EAE3C,IAAI,CAAC,SAAS,IACZ,MAAM,IAAI,oBACR,oCAAoC,SAAS,MAAM,aAAa,SAAS,UACzE,EAAE,SAAS;GAAE,KAAK,SAAS;GAAO,QAAQ,SAAS;EAAO,EAAE,CAC9D;EAGF,OAAO;GAAE,MAAM;GAAQ,MAAM,MAAM,SAAS,KAAK;EAAE;CACrD;CAEA,IAAI,SAAS,SAAS,UAGpB,OAAO;EAAE,MAAM;EAAQ,MAFP,OAAO,KAAK,SAAS,OAAO,QAAQ,EAAE,SAAS,MAE5B;CAAE;CAKvC,OAAO;EAAE,MAAM;EAAQ,MAAM,MAFT,SAAS,SAAS,OAAO,MAAM;CAEhB;AACrC;AAEA,SAAS,mBACP,YACqD;CACrD,OACE,OAAO,eAAe,YACtB,eAAe,QACf,UAAU;AAEd;AAEA,SAAS,oBAAoB,OAAoC;CAC/D,MAAM,OAAO,YAAY,KAAK;CAE9B,IAAI,CAAC,MACH;CAKF,OAAO,+BAFW,QAAQ,WAAW,IAAI,CAAC,EAAE,YAEE;AAChD;AAEA,SAAS,YAAY,OAAoC;CACvD,IAAI,OAAO,UAAU,UACnB,OAAO;CAGT,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM;EAC/C,MAAM,UAAU;EAChB,OAAO,QAAQ,OAAO,QAAQ;CAChC;AAGF;AAEA,SAAS,WAAW,MAAsB;CACxC,MAAM,aAAa,KAAK,QAAQ,GAAG;CAEnC,OAAO,eAAe,KAAK,OAAO,KAAK,MAAM,GAAG,UAAU;AAC5D"}
@@ -0,0 +1,33 @@
1
+ import { Attachment, ResolvedAttachment } from "../contracts/attachment.type.mjs";
2
+
3
+ //#region ../../@warlock.js/ai/src/utils/resolve-attachment.d.ts
4
+ /**
5
+ * Normalize a user-supplied `Attachment` (or bare `AttachmentSource`)
6
+ * into a `ResolvedAttachment` the agent can hand to file-reading code
7
+ * without re-discriminating the input variant.
8
+ *
9
+ * Resolution rules:
10
+ * - `{ base64, mediaType }` → `{ type: "base64", value, mediaType }`.
11
+ * - `StorageFileShape` (`{ url?, absolutePath? }`) → URL wins over
12
+ * absolute path. URL becomes `{ type: "url" }`; absolute path
13
+ * becomes `{ type: "path" }`.
14
+ * - String starting with `http://` / `https://` → `{ type: "url" }`.
15
+ * - Any other string → `{ type: "path" }`.
16
+ * - Tagged `{ type: "image" | "text", source }` → recurses into `source`.
17
+ *
18
+ * Throws `InvalidRequestError` on obviously invalid input (empty
19
+ * string, storage object with neither url nor absolutePath, missing
20
+ * source field).
21
+ *
22
+ * @example
23
+ * resolveAttachment("https://cdn.example.com/doc.pdf");
24
+ * // → { type: "url", value: "https://cdn.example.com/doc.pdf" }
25
+ *
26
+ * @example
27
+ * resolveAttachment({ type: "image", source: "/tmp/x.png" });
28
+ * // → { type: "path", value: "/tmp/x.png" }
29
+ */
30
+ declare function resolveAttachment(attachment: Attachment): ResolvedAttachment;
31
+ //#endregion
32
+ export { resolveAttachment };
33
+ //# sourceMappingURL=resolve-attachment.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve-attachment.d.mts","names":[],"sources":["../../../../../../@warlock.js/ai/src/utils/resolve-attachment.ts"],"mappings":";;;;;AAmCA;;;;;;;;AAA6E;;;;;;;;;;;;;;;;iBAA7D,iBAAA,CAAkB,UAAA,EAAY,UAAA,GAAa,kBAAkB"}
@@ -0,0 +1,73 @@
1
+ import { InvalidRequestError } from "../errors/invalid-request-error.mjs";
2
+ import "../errors/index.mjs";
3
+
4
+ //#region ../../@warlock.js/ai/src/utils/resolve-attachment.ts
5
+ const REMOTE_URL_PATTERN = /^https?:\/\//i;
6
+ /**
7
+ * Normalize a user-supplied `Attachment` (or bare `AttachmentSource`)
8
+ * into a `ResolvedAttachment` the agent can hand to file-reading code
9
+ * without re-discriminating the input variant.
10
+ *
11
+ * Resolution rules:
12
+ * - `{ base64, mediaType }` → `{ type: "base64", value, mediaType }`.
13
+ * - `StorageFileShape` (`{ url?, absolutePath? }`) → URL wins over
14
+ * absolute path. URL becomes `{ type: "url" }`; absolute path
15
+ * becomes `{ type: "path" }`.
16
+ * - String starting with `http://` / `https://` → `{ type: "url" }`.
17
+ * - Any other string → `{ type: "path" }`.
18
+ * - Tagged `{ type: "image" | "text", source }` → recurses into `source`.
19
+ *
20
+ * Throws `InvalidRequestError` on obviously invalid input (empty
21
+ * string, storage object with neither url nor absolutePath, missing
22
+ * source field).
23
+ *
24
+ * @example
25
+ * resolveAttachment("https://cdn.example.com/doc.pdf");
26
+ * // → { type: "url", value: "https://cdn.example.com/doc.pdf" }
27
+ *
28
+ * @example
29
+ * resolveAttachment({ type: "image", source: "/tmp/x.png" });
30
+ * // → { type: "path", value: "/tmp/x.png" }
31
+ */
32
+ function resolveAttachment(attachment) {
33
+ if (typeof attachment === "object" && attachment !== null && "type" in attachment) return resolveSource(attachment.source);
34
+ return resolveSource(attachment);
35
+ }
36
+ function resolveSource(source) {
37
+ if (typeof source === "string") {
38
+ if (!source) throw new InvalidRequestError("Cannot resolve empty attachment string");
39
+ if (REMOTE_URL_PATTERN.test(source)) return {
40
+ type: "url",
41
+ value: source
42
+ };
43
+ return {
44
+ type: "path",
45
+ value: source
46
+ };
47
+ }
48
+ if ("url" in source || "absolutePath" in source) {
49
+ const storage = source;
50
+ if (storage.absolutePath) return {
51
+ type: "path",
52
+ value: storage.absolutePath
53
+ };
54
+ if (storage.url) return {
55
+ type: "url",
56
+ value: storage.url
57
+ };
58
+ throw new InvalidRequestError("Storage attachment has neither url nor absolutePath");
59
+ }
60
+ if ("base64" in source) {
61
+ if (!source.base64 || !source.mediaType) throw new InvalidRequestError("Inline attachment requires both `base64` and `mediaType`");
62
+ return {
63
+ type: "base64",
64
+ value: source.base64,
65
+ mediaType: source.mediaType
66
+ };
67
+ }
68
+ throw new InvalidRequestError("Unrecognized attachment source — expected a string path/URL, a StorageFile, or `{ base64, mediaType }`");
69
+ }
70
+
71
+ //#endregion
72
+ export { resolveAttachment };
73
+ //# sourceMappingURL=resolve-attachment.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve-attachment.mjs","names":[],"sources":["../../../../../../@warlock.js/ai/src/utils/resolve-attachment.ts"],"sourcesContent":["import type {\n Attachment,\n AttachmentSource,\n ResolvedAttachment,\n} from \"../contracts/attachment.type\";\nimport { InvalidRequestError } from \"../errors\";\n\nconst REMOTE_URL_PATTERN = /^https?:\\/\\//i;\n\n/**\n * Normalize a user-supplied `Attachment` (or bare `AttachmentSource`)\n * into a `ResolvedAttachment` the agent can hand to file-reading code\n * without re-discriminating the input variant.\n *\n * Resolution rules:\n * - `{ base64, mediaType }` → `{ type: \"base64\", value, mediaType }`.\n * - `StorageFileShape` (`{ url?, absolutePath? }`) → URL wins over\n * absolute path. URL becomes `{ type: \"url\" }`; absolute path\n * becomes `{ type: \"path\" }`.\n * - String starting with `http://` / `https://` → `{ type: \"url\" }`.\n * - Any other string → `{ type: \"path\" }`.\n * - Tagged `{ type: \"image\" | \"text\", source }` → recurses into `source`.\n *\n * Throws `InvalidRequestError` on obviously invalid input (empty\n * string, storage object with neither url nor absolutePath, missing\n * source field).\n *\n * @example\n * resolveAttachment(\"https://cdn.example.com/doc.pdf\");\n * // → { type: \"url\", value: \"https://cdn.example.com/doc.pdf\" }\n *\n * @example\n * resolveAttachment({ type: \"image\", source: \"/tmp/x.png\" });\n * // → { type: \"path\", value: \"/tmp/x.png\" }\n */\nexport function resolveAttachment(attachment: Attachment): ResolvedAttachment {\n if (\n typeof attachment === \"object\" &&\n attachment !== null &&\n \"type\" in attachment\n ) {\n return resolveSource(attachment.source);\n }\n\n return resolveSource(attachment);\n}\n\nfunction resolveSource(source: AttachmentSource): ResolvedAttachment {\n if (typeof source === \"string\") {\n if (!source) {\n throw new InvalidRequestError(\"Cannot resolve empty attachment string\");\n }\n\n if (REMOTE_URL_PATTERN.test(source)) {\n return { type: \"url\", value: source };\n }\n\n return { type: \"path\", value: source };\n }\n\n // StorageFile objects (from @warlock.js/core) can expose a `base64`\n // property alongside `url` / `absolutePath`. Check storage shape\n // first so we don't treat a StorageFile as an inline-bytes payload.\n if (\"url\" in source || \"absolutePath\" in source) {\n const storage = source as { url?: string; absolutePath?: string };\n\n if (storage.absolutePath) {\n return { type: \"path\", value: storage.absolutePath };\n }\n\n if (storage.url) {\n return { type: \"url\", value: storage.url };\n }\n\n throw new InvalidRequestError(\n \"Storage attachment has neither url nor absolutePath\",\n );\n }\n\n if (\"base64\" in source) {\n if (!source.base64 || !source.mediaType) {\n throw new InvalidRequestError(\n \"Inline attachment requires both `base64` and `mediaType`\",\n );\n }\n\n return {\n type: \"base64\",\n value: source.base64,\n mediaType: source.mediaType,\n };\n }\n\n throw new InvalidRequestError(\n \"Unrecognized attachment source — expected a string path/URL, a StorageFile, or `{ base64, mediaType }`\",\n );\n}\n"],"mappings":";;;;AAOA,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4B3B,SAAgB,kBAAkB,YAA4C;CAC5E,IACE,OAAO,eAAe,YACtB,eAAe,QACf,UAAU,YAEV,OAAO,cAAc,WAAW,MAAM;CAGxC,OAAO,cAAc,UAAU;AACjC;AAEA,SAAS,cAAc,QAA8C;CACnE,IAAI,OAAO,WAAW,UAAU;EAC9B,IAAI,CAAC,QACH,MAAM,IAAI,oBAAoB,wCAAwC;EAGxE,IAAI,mBAAmB,KAAK,MAAM,GAChC,OAAO;GAAE,MAAM;GAAO,OAAO;EAAO;EAGtC,OAAO;GAAE,MAAM;GAAQ,OAAO;EAAO;CACvC;CAKA,IAAI,SAAS,UAAU,kBAAkB,QAAQ;EAC/C,MAAM,UAAU;EAEhB,IAAI,QAAQ,cACV,OAAO;GAAE,MAAM;GAAQ,OAAO,QAAQ;EAAa;EAGrD,IAAI,QAAQ,KACV,OAAO;GAAE,MAAM;GAAO,OAAO,QAAQ;EAAI;EAG3C,MAAM,IAAI,oBACR,qDACF;CACF;CAEA,IAAI,YAAY,QAAQ;EACtB,IAAI,CAAC,OAAO,UAAU,CAAC,OAAO,WAC5B,MAAM,IAAI,oBACR,0DACF;EAGF,OAAO;GACL,MAAM;GACN,OAAO,OAAO;GACd,WAAW,OAAO;EACpB;CACF;CAEA,MAAM,IAAI,oBACR,wGACF;AACF"}
@@ -0,0 +1,14 @@
1
+ //#region ../../@warlock.js/ai/src/utils/safe-json-parse.d.ts
2
+ /**
3
+ * Parse a JSON string, returning a caller-supplied fallback when the input
4
+ * is empty or malformed instead of throwing. Useful at provider boundaries
5
+ * where tool-call arguments may arrive as `null`, `""`, or partial JSON
6
+ * during streaming — callers want a safe default, not an exception.
7
+ *
8
+ * @example
9
+ * const args = safeJsonParse<Record<string, unknown>>(toolCall.function.arguments, {});
10
+ */
11
+ declare function safeJsonParse<TValue>(data: string | null | undefined, defaultValue: TValue): TValue;
12
+ //#endregion
13
+ export { safeJsonParse };
14
+ //# sourceMappingURL=safe-json-parse.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"safe-json-parse.d.mts","names":[],"sources":["../../../../../../@warlock.js/ai/src/utils/safe-json-parse.ts"],"mappings":";;AASA;;;;;;;;iBAAgB,aAAA,QAAA,CACd,IAAA,6BACA,YAAA,EAAc,MAAA,GACb,MAAM"}
@@ -0,0 +1,22 @@
1
+ //#region ../../@warlock.js/ai/src/utils/safe-json-parse.ts
2
+ /**
3
+ * Parse a JSON string, returning a caller-supplied fallback when the input
4
+ * is empty or malformed instead of throwing. Useful at provider boundaries
5
+ * where tool-call arguments may arrive as `null`, `""`, or partial JSON
6
+ * during streaming — callers want a safe default, not an exception.
7
+ *
8
+ * @example
9
+ * const args = safeJsonParse<Record<string, unknown>>(toolCall.function.arguments, {});
10
+ */
11
+ function safeJsonParse(data, defaultValue) {
12
+ if (!data) return defaultValue;
13
+ try {
14
+ return JSON.parse(data);
15
+ } catch {
16
+ return defaultValue;
17
+ }
18
+ }
19
+
20
+ //#endregion
21
+ export { safeJsonParse };
22
+ //# sourceMappingURL=safe-json-parse.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"safe-json-parse.mjs","names":[],"sources":["../../../../../../@warlock.js/ai/src/utils/safe-json-parse.ts"],"sourcesContent":["/**\n * Parse a JSON string, returning a caller-supplied fallback when the input\n * is empty or malformed instead of throwing. Useful at provider boundaries\n * where tool-call arguments may arrive as `null`, `\"\"`, or partial JSON\n * during streaming — callers want a safe default, not an exception.\n *\n * @example\n * const args = safeJsonParse<Record<string, unknown>>(toolCall.function.arguments, {});\n */\nexport function safeJsonParse<TValue>(\n data: string | null | undefined,\n defaultValue: TValue,\n): TValue {\n if (!data) {\n return defaultValue;\n }\n\n try {\n return JSON.parse(data) as TValue;\n } catch {\n return defaultValue;\n }\n}\n"],"mappings":";;;;;;;;;;AASA,SAAgB,cACd,MACA,cACQ;CACR,IAAI,CAAC,MACH,OAAO;CAGT,IAAI;EACF,OAAO,KAAK,MAAM,IAAI;CACxB,QAAQ;EACN,OAAO;CACT;AACF"}
@@ -0,0 +1,61 @@
1
+ import { BaseReport } from "../contracts/result/base-report.type.mjs";
2
+
3
+ //#region ../../@warlock.js/ai/src/utils/stamp-report-lineage.d.ts
4
+ /**
5
+ * Options for {@link stampReportLineage}. Every field is optional —
6
+ * the caller supplies whichever pieces it knows. Missing pieces are
7
+ * left untouched (existing values on the report survive).
8
+ */
9
+ type LineageStamp = {
10
+ /**
11
+ * The outermost run-id this subtree belongs to. When set, EVERY
12
+ * node in the subtree gets its `rootRunId` rewritten to this
13
+ * value — overrides any inner self-roots produced by nested
14
+ * `buildResult` calls.
15
+ */
16
+ rootRunId: string;
17
+ /**
18
+ * Run-id of the immediate parent of THIS subtree's top node. Each
19
+ * descendant's `parentRunId` is then derived from its own walk
20
+ * position (its parent's `runId`).
21
+ */
22
+ parentRunId?: string;
23
+ /**
24
+ * Caller-supplied session identifier — propagates to every node in
25
+ * the subtree. Skipped when undefined.
26
+ */
27
+ sessionId?: string;
28
+ };
29
+ /**
30
+ * Walk a freshly-built report tree and stamp lineage fields onto
31
+ * every node:
32
+ *
33
+ * - `rootRunId` — rewritten to `stamp.rootRunId` everywhere. Composite
34
+ * children built by inner primitives carry their own self-root; this
35
+ * walk overrides it so the outer root wins (single coherent run id
36
+ * across the whole tree).
37
+ * - `parentRunId` — root node gets `stamp.parentRunId`; descendants
38
+ * derive theirs from each parent's own `runId`.
39
+ * - `sessionId` — propagated when provided.
40
+ * - `reportSchemaVersion` — stamped only on the root (the value is the
41
+ * same for the whole tree; storing it on every node would waste
42
+ * space).
43
+ *
44
+ * Designed to run ONCE per top-level `buildResult` call. Each
45
+ * primitive's executor invokes this on the assembled root report just
46
+ * before returning; nested primitives produced their own subtree with
47
+ * a self-root, and this pass relinks everything to the outer caller's
48
+ * lineage.
49
+ *
50
+ * Mutates the report in place — internal use only, before the report
51
+ * is exposed via `result.report`.
52
+ *
53
+ * @example
54
+ * const root = this.buildBareReport();
55
+ * stampReportLineage(root, { rootRunId: this.runId, sessionId: this.options?.sessionId });
56
+ * return { ..., report: root };
57
+ */
58
+ declare function stampReportLineage(root: BaseReport, stamp: LineageStamp): void;
59
+ //#endregion
60
+ export { LineageStamp, stampReportLineage };
61
+ //# sourceMappingURL=stamp-report-lineage.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stamp-report-lineage.d.mts","names":[],"sources":["../../../../../../@warlock.js/ai/src/utils/stamp-report-lineage.ts"],"mappings":";;;;;AAQA;;;KAAY,YAAA;EAOV;;;;AAWS;AAgCX;EA3CE,SAAA;;;;;;EAMA,WAAA;EAqCsE;AAAA;;;EAhCtE,SAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAgCc,kBAAA,CAAmB,IAAA,EAAM,UAAA,EAAY,KAAA,EAAO,YAAY"}
@@ -0,0 +1,47 @@
1
+ import { REPORT_SCHEMA_VERSION } from "../contracts/result/base-report.type.mjs";
2
+
3
+ //#region ../../@warlock.js/ai/src/utils/stamp-report-lineage.ts
4
+ /**
5
+ * Walk a freshly-built report tree and stamp lineage fields onto
6
+ * every node:
7
+ *
8
+ * - `rootRunId` — rewritten to `stamp.rootRunId` everywhere. Composite
9
+ * children built by inner primitives carry their own self-root; this
10
+ * walk overrides it so the outer root wins (single coherent run id
11
+ * across the whole tree).
12
+ * - `parentRunId` — root node gets `stamp.parentRunId`; descendants
13
+ * derive theirs from each parent's own `runId`.
14
+ * - `sessionId` — propagated when provided.
15
+ * - `reportSchemaVersion` — stamped only on the root (the value is the
16
+ * same for the whole tree; storing it on every node would waste
17
+ * space).
18
+ *
19
+ * Designed to run ONCE per top-level `buildResult` call. Each
20
+ * primitive's executor invokes this on the assembled root report just
21
+ * before returning; nested primitives produced their own subtree with
22
+ * a self-root, and this pass relinks everything to the outer caller's
23
+ * lineage.
24
+ *
25
+ * Mutates the report in place — internal use only, before the report
26
+ * is exposed via `result.report`.
27
+ *
28
+ * @example
29
+ * const root = this.buildBareReport();
30
+ * stampReportLineage(root, { rootRunId: this.runId, sessionId: this.options?.sessionId });
31
+ * return { ..., report: root };
32
+ */
33
+ function stampReportLineage(root, stamp) {
34
+ root.reportSchemaVersion = 1;
35
+ walk(root, stamp.rootRunId, stamp.parentRunId, stamp.sessionId);
36
+ }
37
+ function walk(node, rootRunId, parentRunId, sessionId) {
38
+ node.rootRunId = rootRunId;
39
+ if (parentRunId !== void 0) node.parentRunId = parentRunId;
40
+ else delete node.parentRunId;
41
+ if (sessionId !== void 0) node.sessionId = sessionId;
42
+ for (const child of node.children) walk(child, rootRunId, node.runId, sessionId);
43
+ }
44
+
45
+ //#endregion
46
+ export { stampReportLineage };
47
+ //# sourceMappingURL=stamp-report-lineage.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stamp-report-lineage.mjs","names":[],"sources":["../../../../../../@warlock.js/ai/src/utils/stamp-report-lineage.ts"],"sourcesContent":["import type { BaseReport } from \"../contracts/result/base-report.type\";\nimport { REPORT_SCHEMA_VERSION } from \"../contracts/result/base-report.type\";\n\n/**\n * Options for {@link stampReportLineage}. Every field is optional —\n * the caller supplies whichever pieces it knows. Missing pieces are\n * left untouched (existing values on the report survive).\n */\nexport type LineageStamp = {\n /**\n * The outermost run-id this subtree belongs to. When set, EVERY\n * node in the subtree gets its `rootRunId` rewritten to this\n * value — overrides any inner self-roots produced by nested\n * `buildResult` calls.\n */\n rootRunId: string;\n /**\n * Run-id of the immediate parent of THIS subtree's top node. Each\n * descendant's `parentRunId` is then derived from its own walk\n * position (its parent's `runId`).\n */\n parentRunId?: string;\n /**\n * Caller-supplied session identifier — propagates to every node in\n * the subtree. Skipped when undefined.\n */\n sessionId?: string;\n};\n\n/**\n * Walk a freshly-built report tree and stamp lineage fields onto\n * every node:\n *\n * - `rootRunId` — rewritten to `stamp.rootRunId` everywhere. Composite\n * children built by inner primitives carry their own self-root; this\n * walk overrides it so the outer root wins (single coherent run id\n * across the whole tree).\n * - `parentRunId` — root node gets `stamp.parentRunId`; descendants\n * derive theirs from each parent's own `runId`.\n * - `sessionId` — propagated when provided.\n * - `reportSchemaVersion` — stamped only on the root (the value is the\n * same for the whole tree; storing it on every node would waste\n * space).\n *\n * Designed to run ONCE per top-level `buildResult` call. Each\n * primitive's executor invokes this on the assembled root report just\n * before returning; nested primitives produced their own subtree with\n * a self-root, and this pass relinks everything to the outer caller's\n * lineage.\n *\n * Mutates the report in place — internal use only, before the report\n * is exposed via `result.report`.\n *\n * @example\n * const root = this.buildBareReport();\n * stampReportLineage(root, { rootRunId: this.runId, sessionId: this.options?.sessionId });\n * return { ..., report: root };\n */\nexport function stampReportLineage(root: BaseReport, stamp: LineageStamp): void {\n root.reportSchemaVersion = REPORT_SCHEMA_VERSION;\n\n walk(root, stamp.rootRunId, stamp.parentRunId, stamp.sessionId);\n}\n\nfunction walk(node: BaseReport, rootRunId: string, parentRunId?: string, sessionId?: string): void {\n node.rootRunId = rootRunId;\n\n if (parentRunId !== undefined) {\n node.parentRunId = parentRunId;\n } else {\n delete node.parentRunId;\n }\n\n if (sessionId !== undefined) {\n node.sessionId = sessionId;\n }\n\n for (const child of node.children) {\n walk(child, rootRunId, node.runId, sessionId);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0DA,SAAgB,mBAAmB,MAAkB,OAA2B;CAC9E,KAAK;CAEL,KAAK,MAAM,MAAM,WAAW,MAAM,aAAa,MAAM,SAAS;AAChE;AAEA,SAAS,KAAK,MAAkB,WAAmB,aAAsB,WAA0B;CACjG,KAAK,YAAY;CAEjB,IAAI,gBAAgB,QAClB,KAAK,cAAc;MAEnB,OAAO,KAAK;CAGd,IAAI,cAAc,QAChB,KAAK,YAAY;CAGnB,KAAK,MAAM,SAAS,KAAK,UACvB,KAAK,OAAO,WAAW,KAAK,OAAO,SAAS;AAEhD"}
@@ -0,0 +1,15 @@
1
+ //#region ../../@warlock.js/ai/src/utils/token-count.d.ts
2
+ /**
3
+ * Approximate the number of tokens in a string.
4
+ *
5
+ * Uses the ~4-characters-per-token heuristic, which is accurate enough for
6
+ * GPT-4 family models and most English text. Use this when a real tokenizer
7
+ * (tiktoken, etc.) isn't available or would add native dependencies.
8
+ *
9
+ * @example
10
+ * const tokens = approximateTokenCount("Hello, world!"); // 4
11
+ */
12
+ declare function approximateTokenCount(text: string): number;
13
+ //#endregion
14
+ export { approximateTokenCount };
15
+ //# sourceMappingURL=token-count.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token-count.d.mts","names":[],"sources":["../../../../../../@warlock.js/ai/src/utils/token-count.ts"],"mappings":";;AAUA;;;;AAAkD;;;;;iBAAlC,qBAAA,CAAsB,IAAY"}
@@ -0,0 +1,18 @@
1
+ //#region ../../@warlock.js/ai/src/utils/token-count.ts
2
+ /**
3
+ * Approximate the number of tokens in a string.
4
+ *
5
+ * Uses the ~4-characters-per-token heuristic, which is accurate enough for
6
+ * GPT-4 family models and most English text. Use this when a real tokenizer
7
+ * (tiktoken, etc.) isn't available or would add native dependencies.
8
+ *
9
+ * @example
10
+ * const tokens = approximateTokenCount("Hello, world!"); // 4
11
+ */
12
+ function approximateTokenCount(text) {
13
+ return Math.ceil(text.length / 4);
14
+ }
15
+
16
+ //#endregion
17
+ export { approximateTokenCount };
18
+ //# sourceMappingURL=token-count.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token-count.mjs","names":[],"sources":["../../../../../../@warlock.js/ai/src/utils/token-count.ts"],"sourcesContent":["/**\n * Approximate the number of tokens in a string.\n *\n * Uses the ~4-characters-per-token heuristic, which is accurate enough for\n * GPT-4 family models and most English text. Use this when a real tokenizer\n * (tiktoken, etc.) isn't available or would add native dependencies.\n *\n * @example\n * const tokens = approximateTokenCount(\"Hello, world!\"); // 4\n */\nexport function approximateTokenCount(text: string): number {\n return Math.ceil(text.length / 4);\n}\n"],"mappings":";;;;;;;;;;;AAUA,SAAgB,sBAAsB,MAAsB;CAC1D,OAAO,KAAK,KAAK,KAAK,SAAS,CAAC;AAClC"}