@warlock.js/core 4.7.0 → 4.8.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 (812) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/esm/config/config-getter.mjs +5 -5
  3. package/esm/config/config-getter.mjs.map +1 -1
  4. package/esm/config/config-loader.mjs +2 -2
  5. package/esm/config/config-loader.mjs.map +1 -1
  6. package/esm/connectors/access-connector.mjs +2 -2
  7. package/esm/connectors/access-connector.mjs.map +1 -1
  8. package/esm/connectors/ai-connector.mjs +3 -3
  9. package/esm/connectors/ai-connector.mjs.map +1 -1
  10. package/esm/connectors/cache-connector.mjs +2 -2
  11. package/esm/connectors/cache-connector.mjs.map +1 -1
  12. package/esm/connectors/database-connector.mjs +2 -2
  13. package/esm/connectors/database-connector.mjs.map +1 -1
  14. package/esm/connectors/herald-connector.mjs +2 -2
  15. package/esm/connectors/herald-connector.mjs.map +1 -1
  16. package/esm/connectors/http-connector.mjs +7 -7
  17. package/esm/connectors/http-connector.mjs.map +1 -1
  18. package/esm/connectors/logger-connector.mjs +2 -2
  19. package/esm/connectors/logger-connector.mjs.map +1 -1
  20. package/esm/connectors/mail-connector.mjs +2 -2
  21. package/esm/connectors/mail-connector.mjs.map +1 -1
  22. package/esm/connectors/notifications-connector.mjs +2 -2
  23. package/esm/connectors/notifications-connector.mjs.map +1 -1
  24. package/esm/connectors/socket-connector.mjs +3 -3
  25. package/esm/connectors/socket-connector.mjs.map +1 -1
  26. package/esm/http/config.mjs +2 -2
  27. package/esm/http/config.mjs.map +1 -1
  28. package/esm/http/createHttpApplication.mjs +2 -2
  29. package/esm/http/createHttpApplication.mjs.map +1 -1
  30. package/esm/http/middleware/idempotency.middleware.mjs +5 -5
  31. package/esm/http/middleware/idempotency.middleware.mjs.map +1 -1
  32. package/esm/http/middleware/inject-request-context.mjs +2 -2
  33. package/esm/http/middleware/inject-request-context.mjs.map +1 -1
  34. package/esm/http/middleware/maintenance.middleware.mjs +4 -4
  35. package/esm/http/middleware/maintenance.middleware.mjs.map +1 -1
  36. package/esm/http/plugins.mjs +9 -9
  37. package/esm/http/plugins.mjs.map +1 -1
  38. package/esm/http/response.mjs +5 -5
  39. package/esm/http/response.mjs.map +1 -1
  40. package/esm/http/server.mjs +4 -4
  41. package/esm/http/server.mjs.map +1 -1
  42. package/esm/utils/paths.mjs +2 -2
  43. package/esm/utils/paths.mjs.map +1 -1
  44. package/esm/validation/validateAll.mjs +2 -2
  45. package/esm/validation/validateAll.mjs.map +1 -1
  46. package/package.json +12 -9
  47. package/esm/ai/src/agent/agent-input-builder.mjs +0 -133
  48. package/esm/ai/src/agent/agent-input-builder.mjs.map +0 -1
  49. package/esm/ai/src/agent/agent-log-event.mjs +0 -101
  50. package/esm/ai/src/agent/agent-log-event.mjs.map +0 -1
  51. package/esm/ai/src/agent/agent-stream.mjs +0 -82
  52. package/esm/ai/src/agent/agent-stream.mjs.map +0 -1
  53. package/esm/ai/src/agent/agent-to-stream-event.mjs +0 -86
  54. package/esm/ai/src/agent/agent-to-stream-event.mjs.map +0 -1
  55. package/esm/ai/src/agent/agent.mjs +0 -1276
  56. package/esm/ai/src/agent/agent.mjs.map +0 -1
  57. package/esm/ai/src/agent/index.mjs +0 -5
  58. package/esm/ai/src/agent/json-stream-guard.mjs +0 -400
  59. package/esm/ai/src/agent/json-stream-guard.mjs.map +0 -1
  60. package/esm/ai/src/agent/signature.mjs +0 -57
  61. package/esm/ai/src/agent/signature.mjs.map +0 -1
  62. package/esm/ai/src/agent/snapshot.mjs +0 -101
  63. package/esm/ai/src/agent/snapshot.mjs.map +0 -1
  64. package/esm/ai/src/agent/spawn-sub-agent.mjs +0 -68
  65. package/esm/ai/src/agent/spawn-sub-agent.mjs.map +0 -1
  66. package/esm/ai/src/ai.mjs +0 -191
  67. package/esm/ai/src/ai.mjs.map +0 -1
  68. package/esm/ai/src/batch/batch.mjs +0 -198
  69. package/esm/ai/src/batch/batch.mjs.map +0 -1
  70. package/esm/ai/src/batch/index.mjs +0 -3
  71. package/esm/ai/src/batch/run-batch-item.mjs +0 -100
  72. package/esm/ai/src/batch/run-batch-item.mjs.map +0 -1
  73. package/esm/ai/src/batch/run-with-concurrency.mjs +0 -39
  74. package/esm/ai/src/batch/run-with-concurrency.mjs.map +0 -1
  75. package/esm/ai/src/checkpoint/memory.mjs +0 -0
  76. package/esm/ai/src/checkpoint/memory.mjs.map +0 -1
  77. package/esm/ai/src/checkpoint/pg.mjs +0 -265
  78. package/esm/ai/src/checkpoint/pg.mjs.map +0 -1
  79. package/esm/ai/src/checkpoint/redis.mjs +0 -200
  80. package/esm/ai/src/checkpoint/redis.mjs.map +0 -1
  81. package/esm/ai/src/config.mjs +0 -59
  82. package/esm/ai/src/config.mjs.map +0 -1
  83. package/esm/ai/src/contracts/end.type.mjs +0 -47
  84. package/esm/ai/src/contracts/end.type.mjs.map +0 -1
  85. package/esm/ai/src/errors/agent-cancelled-error.mjs +0 -43
  86. package/esm/ai/src/errors/agent-cancelled-error.mjs.map +0 -1
  87. package/esm/ai/src/errors/agent-drift-error.mjs +0 -31
  88. package/esm/ai/src/errors/agent-drift-error.mjs.map +0 -1
  89. package/esm/ai/src/errors/agent-execution-error.mjs +0 -35
  90. package/esm/ai/src/errors/agent-execution-error.mjs.map +0 -1
  91. package/esm/ai/src/errors/agent-max-trips-error.mjs +0 -41
  92. package/esm/ai/src/errors/agent-max-trips-error.mjs.map +0 -1
  93. package/esm/ai/src/errors/ai-error.mjs +0 -68
  94. package/esm/ai/src/errors/ai-error.mjs.map +0 -1
  95. package/esm/ai/src/errors/budget-exceeded-error.mjs +0 -31
  96. package/esm/ai/src/errors/budget-exceeded-error.mjs.map +0 -1
  97. package/esm/ai/src/errors/content-filter-error.mjs +0 -28
  98. package/esm/ai/src/errors/content-filter-error.mjs.map +0 -1
  99. package/esm/ai/src/errors/context-length-exceeded-error.mjs +0 -31
  100. package/esm/ai/src/errors/context-length-exceeded-error.mjs.map +0 -1
  101. package/esm/ai/src/errors/guardrail-violation-error.mjs +0 -41
  102. package/esm/ai/src/errors/guardrail-violation-error.mjs.map +0 -1
  103. package/esm/ai/src/errors/index.mjs +0 -40
  104. package/esm/ai/src/errors/invalid-request-error.mjs +0 -31
  105. package/esm/ai/src/errors/invalid-request-error.mjs.map +0 -1
  106. package/esm/ai/src/errors/max-iterations-error.mjs +0 -32
  107. package/esm/ai/src/errors/max-iterations-error.mjs.map +0 -1
  108. package/esm/ai/src/errors/max-steps-exceeded-error.mjs +0 -21
  109. package/esm/ai/src/errors/max-steps-exceeded-error.mjs.map +0 -1
  110. package/esm/ai/src/errors/orchestrator-cancelled-error.mjs +0 -31
  111. package/esm/ai/src/errors/orchestrator-cancelled-error.mjs.map +0 -1
  112. package/esm/ai/src/errors/orchestrator-config-error.mjs +0 -30
  113. package/esm/ai/src/errors/orchestrator-config-error.mjs.map +0 -1
  114. package/esm/ai/src/errors/orchestrator-drift-error.mjs +0 -37
  115. package/esm/ai/src/errors/orchestrator-drift-error.mjs.map +0 -1
  116. package/esm/ai/src/errors/orchestrator-failed-error.mjs +0 -36
  117. package/esm/ai/src/errors/orchestrator-failed-error.mjs.map +0 -1
  118. package/esm/ai/src/errors/outbound-policy-error.mjs +0 -32
  119. package/esm/ai/src/errors/outbound-policy-error.mjs.map +0 -1
  120. package/esm/ai/src/errors/planner-cancelled-error.mjs +0 -29
  121. package/esm/ai/src/errors/planner-cancelled-error.mjs.map +0 -1
  122. package/esm/ai/src/errors/planner-drift-error.mjs +0 -33
  123. package/esm/ai/src/errors/planner-drift-error.mjs.map +0 -1
  124. package/esm/ai/src/errors/planner-failed-error.mjs +0 -37
  125. package/esm/ai/src/errors/planner-failed-error.mjs.map +0 -1
  126. package/esm/ai/src/errors/planner-plan-invalid-error.mjs +0 -25
  127. package/esm/ai/src/errors/planner-plan-invalid-error.mjs.map +0 -1
  128. package/esm/ai/src/errors/prompt-refinement-error.mjs +0 -27
  129. package/esm/ai/src/errors/prompt-refinement-error.mjs.map +0 -1
  130. package/esm/ai/src/errors/provider-auth-error.mjs +0 -26
  131. package/esm/ai/src/errors/provider-auth-error.mjs.map +0 -1
  132. package/esm/ai/src/errors/provider-error.mjs +0 -42
  133. package/esm/ai/src/errors/provider-error.mjs.map +0 -1
  134. package/esm/ai/src/errors/provider-rate-limit-error.mjs +0 -31
  135. package/esm/ai/src/errors/provider-rate-limit-error.mjs.map +0 -1
  136. package/esm/ai/src/errors/provider-timeout-error.mjs +0 -26
  137. package/esm/ai/src/errors/provider-timeout-error.mjs.map +0 -1
  138. package/esm/ai/src/errors/quota-exceeded-error.mjs +0 -40
  139. package/esm/ai/src/errors/quota-exceeded-error.mjs.map +0 -1
  140. package/esm/ai/src/errors/routing-error.mjs +0 -23
  141. package/esm/ai/src/errors/routing-error.mjs.map +0 -1
  142. package/esm/ai/src/errors/schema-validation-error.mjs +0 -37
  143. package/esm/ai/src/errors/schema-validation-error.mjs.map +0 -1
  144. package/esm/ai/src/errors/step-failed-error.mjs +0 -19
  145. package/esm/ai/src/errors/step-failed-error.mjs.map +0 -1
  146. package/esm/ai/src/errors/supervisor-cancelled-error.mjs +0 -29
  147. package/esm/ai/src/errors/supervisor-cancelled-error.mjs.map +0 -1
  148. package/esm/ai/src/errors/supervisor-drift-error.mjs +0 -30
  149. package/esm/ai/src/errors/supervisor-drift-error.mjs.map +0 -1
  150. package/esm/ai/src/errors/supervisor-failed-error.mjs +0 -43
  151. package/esm/ai/src/errors/supervisor-failed-error.mjs.map +0 -1
  152. package/esm/ai/src/errors/supervisor-routing-error.mjs +0 -39
  153. package/esm/ai/src/errors/supervisor-routing-error.mjs.map +0 -1
  154. package/esm/ai/src/errors/tool-execution-error.mjs +0 -32
  155. package/esm/ai/src/errors/tool-execution-error.mjs.map +0 -1
  156. package/esm/ai/src/errors/workflow-cancelled-error.mjs +0 -23
  157. package/esm/ai/src/errors/workflow-cancelled-error.mjs.map +0 -1
  158. package/esm/ai/src/errors/workflow-drift-error.mjs +0 -24
  159. package/esm/ai/src/errors/workflow-drift-error.mjs.map +0 -1
  160. package/esm/ai/src/errors/workflow-error.mjs +0 -18
  161. package/esm/ai/src/errors/workflow-error.mjs.map +0 -1
  162. package/esm/ai/src/eval/dataset.mjs +0 -112
  163. package/esm/ai/src/eval/dataset.mjs.map +0 -1
  164. package/esm/ai/src/eval/eval-runner.mjs +0 -135
  165. package/esm/ai/src/eval/eval-runner.mjs.map +0 -1
  166. package/esm/ai/src/eval/index.mjs +0 -48
  167. package/esm/ai/src/eval/index.mjs.map +0 -1
  168. package/esm/ai/src/eval/judge-scorer.mjs +0 -87
  169. package/esm/ai/src/eval/judge-scorer.mjs.map +0 -1
  170. package/esm/ai/src/eval/regression.mjs +0 -51
  171. package/esm/ai/src/eval/regression.mjs.map +0 -1
  172. package/esm/ai/src/eval/report-json.mjs +0 -33
  173. package/esm/ai/src/eval/report-json.mjs.map +0 -1
  174. package/esm/ai/src/eval/report-junit.mjs +0 -60
  175. package/esm/ai/src/eval/report-junit.mjs.map +0 -1
  176. package/esm/ai/src/eval/scorers.mjs +0 -101
  177. package/esm/ai/src/eval/scorers.mjs.map +0 -1
  178. package/esm/ai/src/guard/detectors/index.mjs +0 -6
  179. package/esm/ai/src/guard/detectors/injection.mjs +0 -254
  180. package/esm/ai/src/guard/detectors/injection.mjs.map +0 -1
  181. package/esm/ai/src/guard/detectors/moderation.mjs +0 -134
  182. package/esm/ai/src/guard/detectors/moderation.mjs.map +0 -1
  183. package/esm/ai/src/guard/detectors/pii.mjs +0 -199
  184. package/esm/ai/src/guard/detectors/pii.mjs.map +0 -1
  185. package/esm/ai/src/guard/detectors/topic.mjs +0 -99
  186. package/esm/ai/src/guard/detectors/topic.mjs.map +0 -1
  187. package/esm/ai/src/guard/errors.mjs +0 -18
  188. package/esm/ai/src/guard/errors.mjs.map +0 -1
  189. package/esm/ai/src/guard/guard.mjs +0 -209
  190. package/esm/ai/src/guard/guard.mjs.map +0 -1
  191. package/esm/ai/src/guard/guardrail.mjs +0 -22
  192. package/esm/ai/src/guard/guardrail.mjs.map +0 -1
  193. package/esm/ai/src/human/errors.mjs +0 -60
  194. package/esm/ai/src/human/errors.mjs.map +0 -1
  195. package/esm/ai/src/human/human-approval.mjs +0 -170
  196. package/esm/ai/src/human/human-approval.mjs.map +0 -1
  197. package/esm/ai/src/human/policy.mjs +0 -67
  198. package/esm/ai/src/human/policy.mjs.map +0 -1
  199. package/esm/ai/src/human/register.mjs +0 -37
  200. package/esm/ai/src/human/register.mjs.map +0 -1
  201. package/esm/ai/src/human/resume-seed.mjs +0 -53
  202. package/esm/ai/src/human/resume-seed.mjs.map +0 -1
  203. package/esm/ai/src/human/resume.mjs +0 -121
  204. package/esm/ai/src/human/resume.mjs.map +0 -1
  205. package/esm/ai/src/human/stores/index.mjs +0 -5
  206. package/esm/ai/src/human/stores/memory.mjs +0 -91
  207. package/esm/ai/src/human/stores/memory.mjs.map +0 -1
  208. package/esm/ai/src/human/stores/pg.mjs +0 -220
  209. package/esm/ai/src/human/stores/pg.mjs.map +0 -1
  210. package/esm/ai/src/human/stores/redis.mjs +0 -201
  211. package/esm/ai/src/human/stores/redis.mjs.map +0 -1
  212. package/esm/ai/src/image/image-cost.mjs +0 -55
  213. package/esm/ai/src/image/image-cost.mjs.map +0 -1
  214. package/esm/ai/src/image/image.mjs +0 -112
  215. package/esm/ai/src/image/image.mjs.map +0 -1
  216. package/esm/ai/src/image/index.mjs +0 -4
  217. package/esm/ai/src/index.mjs +0 -196
  218. package/esm/ai/src/memory/derive-id.mjs +0 -24
  219. package/esm/ai/src/memory/derive-id.mjs.map +0 -1
  220. package/esm/ai/src/memory/episodic-memory.mjs +0 -106
  221. package/esm/ai/src/memory/episodic-memory.mjs.map +0 -1
  222. package/esm/ai/src/memory/memory.mjs +0 -166
  223. package/esm/ai/src/memory/memory.mjs.map +0 -1
  224. package/esm/ai/src/memory/procedural-memory.mjs +0 -103
  225. package/esm/ai/src/memory/procedural-memory.mjs.map +0 -1
  226. package/esm/ai/src/memory/semantic-memory.mjs +0 -80
  227. package/esm/ai/src/memory/semantic-memory.mjs.map +0 -1
  228. package/esm/ai/src/memory/working-memory.mjs +0 -62
  229. package/esm/ai/src/memory/working-memory.mjs.map +0 -1
  230. package/esm/ai/src/middleware/builtins/budget.mjs +0 -219
  231. package/esm/ai/src/middleware/builtins/budget.mjs.map +0 -1
  232. package/esm/ai/src/middleware/builtins/guardrail.mjs +0 -76
  233. package/esm/ai/src/middleware/builtins/guardrail.mjs.map +0 -1
  234. package/esm/ai/src/middleware/builtins/semantic-cache.mjs +0 -149
  235. package/esm/ai/src/middleware/builtins/semantic-cache.mjs.map +0 -1
  236. package/esm/ai/src/middleware/helpers/compose.mjs +0 -52
  237. package/esm/ai/src/middleware/helpers/compose.mjs.map +0 -1
  238. package/esm/ai/src/middleware/helpers/for-tool.mjs +0 -80
  239. package/esm/ai/src/middleware/helpers/for-tool.mjs.map +0 -1
  240. package/esm/ai/src/middleware/index.mjs +0 -10
  241. package/esm/ai/src/middleware/pipeline.mjs +0 -100
  242. package/esm/ai/src/middleware/pipeline.mjs.map +0 -1
  243. package/esm/ai/src/middleware/utils/extract-user-text.mjs +0 -47
  244. package/esm/ai/src/middleware/utils/extract-user-text.mjs.map +0 -1
  245. package/esm/ai/src/middleware/utils/namespaced-state.mjs +0 -60
  246. package/esm/ai/src/middleware/utils/namespaced-state.mjs.map +0 -1
  247. package/esm/ai/src/mock/index.mjs +0 -4
  248. package/esm/ai/src/mock/mock-agent.mjs +0 -3
  249. package/esm/ai/src/mock/mock-router.mjs +0 -58
  250. package/esm/ai/src/mock/mock-router.mjs.map +0 -1
  251. package/esm/ai/src/model/fallback-model.mjs +0 -218
  252. package/esm/ai/src/model/fallback-model.mjs.map +0 -1
  253. package/esm/ai/src/model/index.mjs +0 -3
  254. package/esm/ai/src/object-stream/index.mjs +0 -4
  255. package/esm/ai/src/object-stream/parse-partial-json.mjs +0 -78
  256. package/esm/ai/src/object-stream/parse-partial-json.mjs.map +0 -1
  257. package/esm/ai/src/object-stream/stream-object.mjs +0 -97
  258. package/esm/ai/src/object-stream/stream-object.mjs.map +0 -1
  259. package/esm/ai/src/observe/index.mjs +0 -4
  260. package/esm/ai/src/observe/observer-registry.mjs +0 -35
  261. package/esm/ai/src/observe/observer-registry.mjs.map +0 -1
  262. package/esm/ai/src/observe/resolve-observers.mjs +0 -73
  263. package/esm/ai/src/observe/resolve-observers.mjs.map +0 -1
  264. package/esm/ai/src/orchestrator/as-tool.mjs +0 -98
  265. package/esm/ai/src/orchestrator/as-tool.mjs.map +0 -1
  266. package/esm/ai/src/orchestrator/checkpoint.mjs +0 -75
  267. package/esm/ai/src/orchestrator/checkpoint.mjs.map +0 -1
  268. package/esm/ai/src/orchestrator/commands.mjs +0 -34
  269. package/esm/ai/src/orchestrator/commands.mjs.map +0 -1
  270. package/esm/ai/src/orchestrator/compaction.mjs +0 -206
  271. package/esm/ai/src/orchestrator/compaction.mjs.map +0 -1
  272. package/esm/ai/src/orchestrator/dispatch.mjs +0 -171
  273. package/esm/ai/src/orchestrator/dispatch.mjs.map +0 -1
  274. package/esm/ai/src/orchestrator/emitter.mjs +0 -85
  275. package/esm/ai/src/orchestrator/emitter.mjs.map +0 -1
  276. package/esm/ai/src/orchestrator/execution.mjs +0 -395
  277. package/esm/ai/src/orchestrator/execution.mjs.map +0 -1
  278. package/esm/ai/src/orchestrator/index.mjs +0 -11
  279. package/esm/ai/src/orchestrator/load.mjs +0 -49
  280. package/esm/ai/src/orchestrator/load.mjs.map +0 -1
  281. package/esm/ai/src/orchestrator/lock.mjs +0 -75
  282. package/esm/ai/src/orchestrator/lock.mjs.map +0 -1
  283. package/esm/ai/src/orchestrator/memory.mjs +0 -141
  284. package/esm/ai/src/orchestrator/memory.mjs.map +0 -1
  285. package/esm/ai/src/orchestrator/orchestrator-stream.mjs +0 -98
  286. package/esm/ai/src/orchestrator/orchestrator-stream.mjs.map +0 -1
  287. package/esm/ai/src/orchestrator/orchestrator.mjs +0 -206
  288. package/esm/ai/src/orchestrator/orchestrator.mjs.map +0 -1
  289. package/esm/ai/src/orchestrator/resume.mjs +0 -74
  290. package/esm/ai/src/orchestrator/resume.mjs.map +0 -1
  291. package/esm/ai/src/orchestrator/session-lock.mjs +0 -83
  292. package/esm/ai/src/orchestrator/session-lock.mjs.map +0 -1
  293. package/esm/ai/src/orchestrator/signature.mjs +0 -120
  294. package/esm/ai/src/orchestrator/signature.mjs.map +0 -1
  295. package/esm/ai/src/orchestrator/window.mjs +0 -56
  296. package/esm/ai/src/orchestrator/window.mjs.map +0 -1
  297. package/esm/ai/src/planner/dag-scheduler.mjs +0 -97
  298. package/esm/ai/src/planner/dag-scheduler.mjs.map +0 -1
  299. package/esm/ai/src/planner/index.mjs +0 -6
  300. package/esm/ai/src/planner/plan-prompt.mjs +0 -31
  301. package/esm/ai/src/planner/plan-prompt.mjs.map +0 -1
  302. package/esm/ai/src/planner/plan-schema.mjs +0 -120
  303. package/esm/ai/src/planner/plan-schema.mjs.map +0 -1
  304. package/esm/ai/src/planner/planner-run.mjs +0 -769
  305. package/esm/ai/src/planner/planner-run.mjs.map +0 -1
  306. package/esm/ai/src/planner/planner.mjs +0 -144
  307. package/esm/ai/src/planner/planner.mjs.map +0 -1
  308. package/esm/ai/src/planner/signature.mjs +0 -27
  309. package/esm/ai/src/planner/signature.mjs.map +0 -1
  310. package/esm/ai/src/planner/snapshot.mjs +0 -95
  311. package/esm/ai/src/planner/snapshot.mjs.map +0 -1
  312. package/esm/ai/src/prompt/errors.mjs +0 -73
  313. package/esm/ai/src/prompt/errors.mjs.map +0 -1
  314. package/esm/ai/src/prompt/index.mjs +0 -4
  315. package/esm/ai/src/prompt/prompt-langfuse-sync.mjs +0 -104
  316. package/esm/ai/src/prompt/prompt-langfuse-sync.mjs.map +0 -1
  317. package/esm/ai/src/prompt/prompt-validate.mjs +0 -170
  318. package/esm/ai/src/prompt/prompt-validate.mjs.map +0 -1
  319. package/esm/ai/src/prompt/prompt.mjs +0 -218
  320. package/esm/ai/src/prompt/prompt.mjs.map +0 -1
  321. package/esm/ai/src/prompts/index.mjs +0 -3
  322. package/esm/ai/src/prompts/prompts-manager.mjs +0 -410
  323. package/esm/ai/src/prompts/prompts-manager.mjs.map +0 -1
  324. package/esm/ai/src/prompts/prompts-validate.mjs +0 -0
  325. package/esm/ai/src/prompts/prompts-validate.mjs.map +0 -1
  326. package/esm/ai/src/rag/as-tool.mjs +0 -48
  327. package/esm/ai/src/rag/as-tool.mjs.map +0 -1
  328. package/esm/ai/src/rag/chunk/chunk.mjs +0 -44
  329. package/esm/ai/src/rag/chunk/chunk.mjs.map +0 -1
  330. package/esm/ai/src/rag/chunk/fixed.mjs +0 -32
  331. package/esm/ai/src/rag/chunk/fixed.mjs.map +0 -1
  332. package/esm/ai/src/rag/chunk/markdown.mjs +0 -75
  333. package/esm/ai/src/rag/chunk/markdown.mjs.map +0 -1
  334. package/esm/ai/src/rag/chunk/recursive.mjs +0 -132
  335. package/esm/ai/src/rag/chunk/recursive.mjs.map +0 -1
  336. package/esm/ai/src/rag/chunk/sentence.mjs +0 -73
  337. package/esm/ai/src/rag/chunk/sentence.mjs.map +0 -1
  338. package/esm/ai/src/rag/hybrid/bm25.mjs +0 -51
  339. package/esm/ai/src/rag/hybrid/bm25.mjs.map +0 -1
  340. package/esm/ai/src/rag/hybrid/hybrid-rank.mjs +0 -29
  341. package/esm/ai/src/rag/hybrid/hybrid-rank.mjs.map +0 -1
  342. package/esm/ai/src/rag/hybrid/rrf.mjs +0 -30
  343. package/esm/ai/src/rag/hybrid/rrf.mjs.map +0 -1
  344. package/esm/ai/src/rag/index.mjs +0 -18
  345. package/esm/ai/src/rag/loaders/errors.mjs +0 -25
  346. package/esm/ai/src/rag/loaders/errors.mjs.map +0 -1
  347. package/esm/ai/src/rag/loaders/index.mjs +0 -7
  348. package/esm/ai/src/rag/loaders/load-html.mjs +0 -138
  349. package/esm/ai/src/rag/loaders/load-html.mjs.map +0 -1
  350. package/esm/ai/src/rag/loaders/load-pdf.mjs +0 -150
  351. package/esm/ai/src/rag/loaders/load-pdf.mjs.map +0 -1
  352. package/esm/ai/src/rag/loaders/load-text.mjs +0 -60
  353. package/esm/ai/src/rag/loaders/load-text.mjs.map +0 -1
  354. package/esm/ai/src/rag/loaders/load-web.mjs +0 -89
  355. package/esm/ai/src/rag/loaders/load-web.mjs.map +0 -1
  356. package/esm/ai/src/rag/rag.mjs +0 -126
  357. package/esm/ai/src/rag/rag.mjs.map +0 -1
  358. package/esm/ai/src/rag/rerank/keyword-reranker.mjs +0 -58
  359. package/esm/ai/src/rag/rerank/keyword-reranker.mjs.map +0 -1
  360. package/esm/ai/src/rag/rerank/llm-reranker.mjs +0 -85
  361. package/esm/ai/src/rag/rerank/llm-reranker.mjs.map +0 -1
  362. package/esm/ai/src/rag/retrieve.mjs +0 -68
  363. package/esm/ai/src/rag/retrieve.mjs.map +0 -1
  364. package/esm/ai/src/rag/store/cache-vector-store.mjs +0 -48
  365. package/esm/ai/src/rag/store/cache-vector-store.mjs.map +0 -1
  366. package/esm/ai/src/rag/store/pg-vector-store.mjs +0 -328
  367. package/esm/ai/src/rag/store/pg-vector-store.mjs.map +0 -1
  368. package/esm/ai/src/rag/transforms/multi-query.mjs +0 -41
  369. package/esm/ai/src/rag/transforms/multi-query.mjs.map +0 -1
  370. package/esm/ai/src/security/index.mjs +0 -5
  371. package/esm/ai/src/security/outbound-policy.mjs +0 -187
  372. package/esm/ai/src/security/outbound-policy.mjs.map +0 -1
  373. package/esm/ai/src/security/private-ip.mjs +0 -48
  374. package/esm/ai/src/security/private-ip.mjs.map +0 -1
  375. package/esm/ai/src/security/redact.mjs +0 -60
  376. package/esm/ai/src/security/redact.mjs.map +0 -1
  377. package/esm/ai/src/serve/serve.mjs +0 -90
  378. package/esm/ai/src/serve/serve.mjs.map +0 -1
  379. package/esm/ai/src/serve/sse.mjs +0 -25
  380. package/esm/ai/src/serve/sse.mjs.map +0 -1
  381. package/esm/ai/src/serve/stream-to-sse.mjs +0 -37
  382. package/esm/ai/src/serve/stream-to-sse.mjs.map +0 -1
  383. package/esm/ai/src/skills/catalog.mjs +0 -140
  384. package/esm/ai/src/skills/catalog.mjs.map +0 -1
  385. package/esm/ai/src/skills/index.mjs +0 -11
  386. package/esm/ai/src/skills/load-skill-tool.mjs +0 -65
  387. package/esm/ai/src/skills/load-skill-tool.mjs.map +0 -1
  388. package/esm/ai/src/skills/save-skill-tool.mjs +0 -65
  389. package/esm/ai/src/skills/save-skill-tool.mjs.map +0 -1
  390. package/esm/ai/src/skills/skills.mjs +0 -109
  391. package/esm/ai/src/skills/skills.mjs.map +0 -1
  392. package/esm/ai/src/skills/sources/directory-source.mjs +0 -108
  393. package/esm/ai/src/skills/sources/directory-source.mjs.map +0 -1
  394. package/esm/ai/src/skills/sources/index.mjs +0 -27
  395. package/esm/ai/src/skills/sources/index.mjs.map +0 -1
  396. package/esm/ai/src/skills/sources/parse-frontmatter.mjs +0 -46
  397. package/esm/ai/src/skills/sources/parse-frontmatter.mjs.map +0 -1
  398. package/esm/ai/src/skills/sources/store-source.mjs +0 -15
  399. package/esm/ai/src/skills/sources/store-source.mjs.map +0 -1
  400. package/esm/ai/src/skills/sources/url-source.mjs +0 -117
  401. package/esm/ai/src/skills/sources/url-source.mjs.map +0 -1
  402. package/esm/ai/src/snapshot/memory.mjs +0 -81
  403. package/esm/ai/src/snapshot/memory.mjs.map +0 -1
  404. package/esm/ai/src/snapshot/pg.mjs +0 -146
  405. package/esm/ai/src/snapshot/pg.mjs.map +0 -1
  406. package/esm/ai/src/snapshot/redis.mjs +0 -101
  407. package/esm/ai/src/snapshot/redis.mjs.map +0 -1
  408. package/esm/ai/src/speech/index.mjs +0 -3
  409. package/esm/ai/src/speech/speech.mjs +0 -122
  410. package/esm/ai/src/speech/speech.mjs.map +0 -1
  411. package/esm/ai/src/supervisor/as-tool.mjs +0 -74
  412. package/esm/ai/src/supervisor/as-tool.mjs.map +0 -1
  413. package/esm/ai/src/supervisor/cancellation.mjs +0 -22
  414. package/esm/ai/src/supervisor/cancellation.mjs.map +0 -1
  415. package/esm/ai/src/supervisor/decide.mjs +0 -272
  416. package/esm/ai/src/supervisor/decide.mjs.map +0 -1
  417. package/esm/ai/src/supervisor/emitter.mjs +0 -47
  418. package/esm/ai/src/supervisor/emitter.mjs.map +0 -1
  419. package/esm/ai/src/supervisor/entries.mjs +0 -206
  420. package/esm/ai/src/supervisor/entries.mjs.map +0 -1
  421. package/esm/ai/src/supervisor/execution.mjs +0 -1921
  422. package/esm/ai/src/supervisor/execution.mjs.map +0 -1
  423. package/esm/ai/src/supervisor/fan-out.mjs +0 -65
  424. package/esm/ai/src/supervisor/fan-out.mjs.map +0 -1
  425. package/esm/ai/src/supervisor/index.mjs +0 -14
  426. package/esm/ai/src/supervisor/router-factory.mjs +0 -141
  427. package/esm/ai/src/supervisor/router-factory.mjs.map +0 -1
  428. package/esm/ai/src/supervisor/router-prompt.mjs +0 -52
  429. package/esm/ai/src/supervisor/router-prompt.mjs.map +0 -1
  430. package/esm/ai/src/supervisor/signature.mjs +0 -89
  431. package/esm/ai/src/supervisor/signature.mjs.map +0 -1
  432. package/esm/ai/src/supervisor/snapshot.mjs +0 -69
  433. package/esm/ai/src/supervisor/snapshot.mjs.map +0 -1
  434. package/esm/ai/src/supervisor/supervisor-stream.mjs +0 -89
  435. package/esm/ai/src/supervisor/supervisor-stream.mjs.map +0 -1
  436. package/esm/ai/src/supervisor/supervisor.mjs +0 -144
  437. package/esm/ai/src/supervisor/supervisor.mjs.map +0 -1
  438. package/esm/ai/src/system-prompt/index.mjs +0 -7
  439. package/esm/ai/src/system-prompt/instruction.mjs +0 -57
  440. package/esm/ai/src/system-prompt/instruction.mjs.map +0 -1
  441. package/esm/ai/src/system-prompt/persona.mjs +0 -57
  442. package/esm/ai/src/system-prompt/persona.mjs.map +0 -1
  443. package/esm/ai/src/system-prompt/refined-system-prompt.mjs +0 -461
  444. package/esm/ai/src/system-prompt/refined-system-prompt.mjs.map +0 -1
  445. package/esm/ai/src/system-prompt/render-placeholders.mjs +0 -58
  446. package/esm/ai/src/system-prompt/render-placeholders.mjs.map +0 -1
  447. package/esm/ai/src/system-prompt/system-prompt.mjs +0 -286
  448. package/esm/ai/src/system-prompt/system-prompt.mjs.map +0 -1
  449. package/esm/ai/src/team/gates.mjs +0 -48
  450. package/esm/ai/src/team/gates.mjs.map +0 -1
  451. package/esm/ai/src/team/index.mjs +0 -3
  452. package/esm/ai/src/team/team.mjs +0 -94
  453. package/esm/ai/src/team/team.mjs.map +0 -1
  454. package/esm/ai/src/tool/executable-as-tool.mjs +0 -81
  455. package/esm/ai/src/tool/executable-as-tool.mjs.map +0 -1
  456. package/esm/ai/src/tool/index.mjs +0 -4
  457. package/esm/ai/src/tool/tool.mjs +0 -185
  458. package/esm/ai/src/tool/tool.mjs.map +0 -1
  459. package/esm/ai/src/transcribe/audio-input.mjs +0 -84
  460. package/esm/ai/src/transcribe/audio-input.mjs.map +0 -1
  461. package/esm/ai/src/transcribe/index.mjs +0 -4
  462. package/esm/ai/src/transcribe/transcribe.mjs +0 -127
  463. package/esm/ai/src/transcribe/transcribe.mjs.map +0 -1
  464. package/esm/ai/src/utils/compute-cost.mjs +0 -112
  465. package/esm/ai/src/utils/compute-cost.mjs.map +0 -1
  466. package/esm/ai/src/utils/extract-json-lenient.mjs +0 -97
  467. package/esm/ai/src/utils/extract-json-lenient.mjs.map +0 -1
  468. package/esm/ai/src/utils/extract-json-payload.mjs +0 -39
  469. package/esm/ai/src/utils/extract-json-payload.mjs.map +0 -1
  470. package/esm/ai/src/utils/generate-run-id.mjs +0 -23
  471. package/esm/ai/src/utils/generate-run-id.mjs.map +0 -1
  472. package/esm/ai/src/utils/index.mjs +0 -12
  473. package/esm/ai/src/utils/json-schema.mjs +0 -89
  474. package/esm/ai/src/utils/json-schema.mjs.map +0 -1
  475. package/esm/ai/src/utils/prepare-attachment-part.mjs +0 -232
  476. package/esm/ai/src/utils/prepare-attachment-part.mjs.map +0 -1
  477. package/esm/ai/src/utils/resolve-attachment.mjs +0 -74
  478. package/esm/ai/src/utils/resolve-attachment.mjs.map +0 -1
  479. package/esm/ai/src/utils/run-context.mjs +0 -89
  480. package/esm/ai/src/utils/run-context.mjs.map +0 -1
  481. package/esm/ai/src/utils/safe-json-parse.mjs +0 -22
  482. package/esm/ai/src/utils/safe-json-parse.mjs.map +0 -1
  483. package/esm/ai/src/utils/stamp-report-lineage.mjs +0 -45
  484. package/esm/ai/src/utils/stamp-report-lineage.mjs.map +0 -1
  485. package/esm/ai/src/vcr/cassette-io.mjs +0 -57
  486. package/esm/ai/src/vcr/cassette-io.mjs.map +0 -1
  487. package/esm/ai/src/vcr/errors.mjs +0 -37
  488. package/esm/ai/src/vcr/errors.mjs.map +0 -1
  489. package/esm/ai/src/vcr/hash-request.mjs +0 -118
  490. package/esm/ai/src/vcr/hash-request.mjs.map +0 -1
  491. package/esm/ai/src/vcr/index.mjs +0 -5
  492. package/esm/ai/src/vcr/vcr.mjs +0 -248
  493. package/esm/ai/src/vcr/vcr.mjs.map +0 -1
  494. package/esm/ai/src/workflow/as-tool.mjs +0 -49
  495. package/esm/ai/src/workflow/as-tool.mjs.map +0 -1
  496. package/esm/ai/src/workflow/cancellation.mjs +0 -44
  497. package/esm/ai/src/workflow/cancellation.mjs.map +0 -1
  498. package/esm/ai/src/workflow/emitter.mjs +0 -40
  499. package/esm/ai/src/workflow/emitter.mjs.map +0 -1
  500. package/esm/ai/src/workflow/engine.mjs +0 -363
  501. package/esm/ai/src/workflow/engine.mjs.map +0 -1
  502. package/esm/ai/src/workflow/index.mjs +0 -5
  503. package/esm/ai/src/workflow/retry.mjs +0 -32
  504. package/esm/ai/src/workflow/retry.mjs.map +0 -1
  505. package/esm/ai/src/workflow/router.mjs +0 -56
  506. package/esm/ai/src/workflow/router.mjs.map +0 -1
  507. package/esm/ai/src/workflow/run-scoped-emitter.mjs +0 -32
  508. package/esm/ai/src/workflow/run-scoped-emitter.mjs.map +0 -1
  509. package/esm/ai/src/workflow/signature.mjs +0 -34
  510. package/esm/ai/src/workflow/signature.mjs.map +0 -1
  511. package/esm/ai/src/workflow/snapshot.mjs +0 -77
  512. package/esm/ai/src/workflow/snapshot.mjs.map +0 -1
  513. package/esm/ai/src/workflow/state.mjs +0 -37
  514. package/esm/ai/src/workflow/state.mjs.map +0 -1
  515. package/esm/ai/src/workflow/step-runner.mjs +0 -370
  516. package/esm/ai/src/workflow/step-runner.mjs.map +0 -1
  517. package/esm/ai/src/workflow/step.mjs +0 -37
  518. package/esm/ai/src/workflow/step.mjs.map +0 -1
  519. package/esm/ai/src/workflow/workflow.mjs +0 -122
  520. package/esm/ai/src/workflow/workflow.mjs.map +0 -1
  521. package/esm/ai-openai/src/embedder.mjs +0 -4
  522. package/esm/ai-openai/src/image.mjs +0 -5
  523. package/esm/ai-openai/src/index.mjs +0 -7
  524. package/esm/ai-openai/src/model.mjs +0 -5
  525. package/esm/ai-openai/src/sdk.mjs +0 -9
  526. package/esm/ai-openai/src/speech.mjs +0 -5
  527. package/esm/ai-openai/src/transcription.mjs +0 -6
  528. package/esm/ai-openai/src/utils/index.mjs +0 -5
  529. package/esm/ai-openai/src/utils/to-openai-messages.mjs +0 -3
  530. package/esm/ai-openai/src/utils/to-openai-tools.mjs +0 -3
  531. package/esm/ai-openai/src/utils/wrap-openai-error.mjs +0 -4
  532. package/esm/node_modules/langfuse/lib/index.mjs +0 -1827
  533. package/esm/node_modules/langfuse/lib/index.mjs.map +0 -1
  534. package/esm/node_modules/langfuse-core/lib/index.mjs +0 -1770
  535. package/esm/node_modules/langfuse-core/lib/index.mjs.map +0 -1
  536. package/esm/node_modules/mustache/mustache.mjs +0 -587
  537. package/esm/node_modules/mustache/mustache.mjs.map +0 -1
  538. package/esm/node_modules/openai/_vendor/partial-json-parser/parser.mjs +0 -180
  539. package/esm/node_modules/openai/_vendor/partial-json-parser/parser.mjs.map +0 -1
  540. package/esm/node_modules/openai/auth/workload-identity-auth.mjs +0 -80
  541. package/esm/node_modules/openai/auth/workload-identity-auth.mjs.map +0 -1
  542. package/esm/node_modules/openai/azure.mjs +0 -82
  543. package/esm/node_modules/openai/azure.mjs.map +0 -1
  544. package/esm/node_modules/openai/client.mjs +0 -638
  545. package/esm/node_modules/openai/client.mjs.map +0 -1
  546. package/esm/node_modules/openai/core/api-promise.mjs +0 -75
  547. package/esm/node_modules/openai/core/api-promise.mjs.map +0 -1
  548. package/esm/node_modules/openai/core/error.mjs +0 -110
  549. package/esm/node_modules/openai/core/error.mjs.map +0 -1
  550. package/esm/node_modules/openai/core/pagination.mjs +0 -160
  551. package/esm/node_modules/openai/core/pagination.mjs.map +0 -1
  552. package/esm/node_modules/openai/core/resource.mjs +0 -10
  553. package/esm/node_modules/openai/core/resource.mjs.map +0 -1
  554. package/esm/node_modules/openai/core/streaming.mjs +0 -238
  555. package/esm/node_modules/openai/core/streaming.mjs.map +0 -1
  556. package/esm/node_modules/openai/index.mjs +0 -8
  557. package/esm/node_modules/openai/internal/decoders/line.mjs +0 -91
  558. package/esm/node_modules/openai/internal/decoders/line.mjs.map +0 -1
  559. package/esm/node_modules/openai/internal/detect-platform.mjs +0 -123
  560. package/esm/node_modules/openai/internal/detect-platform.mjs.map +0 -1
  561. package/esm/node_modules/openai/internal/errors.mjs +0 -26
  562. package/esm/node_modules/openai/internal/errors.mjs.map +0 -1
  563. package/esm/node_modules/openai/internal/headers.mjs +0 -65
  564. package/esm/node_modules/openai/internal/headers.mjs.map +0 -1
  565. package/esm/node_modules/openai/internal/parse.mjs +0 -41
  566. package/esm/node_modules/openai/internal/parse.mjs.map +0 -1
  567. package/esm/node_modules/openai/internal/qs/formats.mjs +0 -12
  568. package/esm/node_modules/openai/internal/qs/formats.mjs.map +0 -1
  569. package/esm/node_modules/openai/internal/qs/stringify.mjs +0 -179
  570. package/esm/node_modules/openai/internal/qs/stringify.mjs.map +0 -1
  571. package/esm/node_modules/openai/internal/qs/utils.mjs +0 -65
  572. package/esm/node_modules/openai/internal/qs/utils.mjs.map +0 -1
  573. package/esm/node_modules/openai/internal/request-options.mjs +0 -11
  574. package/esm/node_modules/openai/internal/request-options.mjs.map +0 -1
  575. package/esm/node_modules/openai/internal/shims.mjs +0 -77
  576. package/esm/node_modules/openai/internal/shims.mjs.map +0 -1
  577. package/esm/node_modules/openai/internal/to-file.mjs +0 -63
  578. package/esm/node_modules/openai/internal/to-file.mjs.map +0 -1
  579. package/esm/node_modules/openai/internal/tslib.mjs +0 -16
  580. package/esm/node_modules/openai/internal/tslib.mjs.map +0 -1
  581. package/esm/node_modules/openai/internal/uploads.mjs +0 -94
  582. package/esm/node_modules/openai/internal/uploads.mjs.map +0 -1
  583. package/esm/node_modules/openai/internal/utils/base64.mjs +0 -22
  584. package/esm/node_modules/openai/internal/utils/base64.mjs.map +0 -1
  585. package/esm/node_modules/openai/internal/utils/bytes.mjs +0 -26
  586. package/esm/node_modules/openai/internal/utils/bytes.mjs.map +0 -1
  587. package/esm/node_modules/openai/internal/utils/env.mjs +0 -16
  588. package/esm/node_modules/openai/internal/utils/env.mjs.map +0 -1
  589. package/esm/node_modules/openai/internal/utils/log.mjs +0 -58
  590. package/esm/node_modules/openai/internal/utils/log.mjs.map +0 -1
  591. package/esm/node_modules/openai/internal/utils/path.mjs +0 -62
  592. package/esm/node_modules/openai/internal/utils/path.mjs.map +0 -1
  593. package/esm/node_modules/openai/internal/utils/query.mjs +0 -10
  594. package/esm/node_modules/openai/internal/utils/query.mjs.map +0 -1
  595. package/esm/node_modules/openai/internal/utils/sleep.mjs +0 -6
  596. package/esm/node_modules/openai/internal/utils/sleep.mjs.map +0 -1
  597. package/esm/node_modules/openai/internal/utils/uuid.mjs +0 -18
  598. package/esm/node_modules/openai/internal/utils/uuid.mjs.map +0 -1
  599. package/esm/node_modules/openai/internal/utils/values.mjs +0 -41
  600. package/esm/node_modules/openai/internal/utils/values.mjs.map +0 -1
  601. package/esm/node_modules/openai/lib/AbstractChatCompletionRunner.mjs +0 -247
  602. package/esm/node_modules/openai/lib/AbstractChatCompletionRunner.mjs.map +0 -1
  603. package/esm/node_modules/openai/lib/AssistantStream.mjs +0 -472
  604. package/esm/node_modules/openai/lib/AssistantStream.mjs.map +0 -1
  605. package/esm/node_modules/openai/lib/ChatCompletionRunner.mjs +0 -26
  606. package/esm/node_modules/openai/lib/ChatCompletionRunner.mjs.map +0 -1
  607. package/esm/node_modules/openai/lib/ChatCompletionStream.mjs +0 -423
  608. package/esm/node_modules/openai/lib/ChatCompletionStream.mjs.map +0 -1
  609. package/esm/node_modules/openai/lib/ChatCompletionStreamingRunner.mjs +0 -26
  610. package/esm/node_modules/openai/lib/ChatCompletionStreamingRunner.mjs.map +0 -1
  611. package/esm/node_modules/openai/lib/EventStream.mjs +0 -163
  612. package/esm/node_modules/openai/lib/EventStream.mjs.map +0 -1
  613. package/esm/node_modules/openai/lib/ResponsesParser.mjs +0 -94
  614. package/esm/node_modules/openai/lib/ResponsesParser.mjs.map +0 -1
  615. package/esm/node_modules/openai/lib/RunnableFunction.mjs +0 -8
  616. package/esm/node_modules/openai/lib/RunnableFunction.mjs.map +0 -1
  617. package/esm/node_modules/openai/lib/Util.mjs +0 -19
  618. package/esm/node_modules/openai/lib/Util.mjs.map +0 -1
  619. package/esm/node_modules/openai/lib/chatCompletionUtils.mjs +0 -11
  620. package/esm/node_modules/openai/lib/chatCompletionUtils.mjs.map +0 -1
  621. package/esm/node_modules/openai/lib/parser.mjs +0 -88
  622. package/esm/node_modules/openai/lib/parser.mjs.map +0 -1
  623. package/esm/node_modules/openai/lib/responses/ResponseStream.mjs +0 -231
  624. package/esm/node_modules/openai/lib/responses/ResponseStream.mjs.map +0 -1
  625. package/esm/node_modules/openai/resources/admin/admin.mjs +0 -15
  626. package/esm/node_modules/openai/resources/admin/admin.mjs.map +0 -1
  627. package/esm/node_modules/openai/resources/admin/organization/admin-api-keys.mjs +0 -81
  628. package/esm/node_modules/openai/resources/admin/organization/admin-api-keys.mjs.map +0 -1
  629. package/esm/node_modules/openai/resources/admin/organization/audit-logs.mjs +0 -31
  630. package/esm/node_modules/openai/resources/admin/organization/audit-logs.mjs.map +0 -1
  631. package/esm/node_modules/openai/resources/admin/organization/certificates.mjs +0 -153
  632. package/esm/node_modules/openai/resources/admin/organization/certificates.mjs.map +0 -1
  633. package/esm/node_modules/openai/resources/admin/organization/data-retention.mjs +0 -42
  634. package/esm/node_modules/openai/resources/admin/organization/data-retention.mjs.map +0 -1
  635. package/esm/node_modules/openai/resources/admin/organization/groups/groups.mjs +0 -106
  636. package/esm/node_modules/openai/resources/admin/organization/groups/groups.mjs.map +0 -1
  637. package/esm/node_modules/openai/resources/admin/organization/groups/roles.mjs +0 -88
  638. package/esm/node_modules/openai/resources/admin/organization/groups/roles.mjs.map +0 -1
  639. package/esm/node_modules/openai/resources/admin/organization/groups/users.mjs +0 -88
  640. package/esm/node_modules/openai/resources/admin/organization/groups/users.mjs.map +0 -1
  641. package/esm/node_modules/openai/resources/admin/organization/invites.mjs +0 -83
  642. package/esm/node_modules/openai/resources/admin/organization/invites.mjs.map +0 -1
  643. package/esm/node_modules/openai/resources/admin/organization/organization.mjs +0 -45
  644. package/esm/node_modules/openai/resources/admin/organization/organization.mjs.map +0 -1
  645. package/esm/node_modules/openai/resources/admin/organization/projects/api-keys.mjs +0 -72
  646. package/esm/node_modules/openai/resources/admin/organization/projects/api-keys.mjs.map +0 -1
  647. package/esm/node_modules/openai/resources/admin/organization/projects/certificates.mjs +0 -78
  648. package/esm/node_modules/openai/resources/admin/organization/projects/certificates.mjs.map +0 -1
  649. package/esm/node_modules/openai/resources/admin/organization/projects/data-retention.mjs +0 -46
  650. package/esm/node_modules/openai/resources/admin/organization/projects/data-retention.mjs.map +0 -1
  651. package/esm/node_modules/openai/resources/admin/organization/projects/groups/groups.mjs +0 -95
  652. package/esm/node_modules/openai/resources/admin/organization/projects/groups/groups.mjs.map +0 -1
  653. package/esm/node_modules/openai/resources/admin/organization/projects/groups/roles.mjs +0 -91
  654. package/esm/node_modules/openai/resources/admin/organization/projects/groups/roles.mjs.map +0 -1
  655. package/esm/node_modules/openai/resources/admin/organization/projects/hosted-tool-permissions.mjs +0 -45
  656. package/esm/node_modules/openai/resources/admin/organization/projects/hosted-tool-permissions.mjs.map +0 -1
  657. package/esm/node_modules/openai/resources/admin/organization/projects/model-permissions.mjs +0 -63
  658. package/esm/node_modules/openai/resources/admin/organization/projects/model-permissions.mjs.map +0 -1
  659. package/esm/node_modules/openai/resources/admin/organization/projects/projects.mjs +0 -137
  660. package/esm/node_modules/openai/resources/admin/organization/projects/projects.mjs.map +0 -1
  661. package/esm/node_modules/openai/resources/admin/organization/projects/rate-limits.mjs +0 -51
  662. package/esm/node_modules/openai/resources/admin/organization/projects/rate-limits.mjs.map +0 -1
  663. package/esm/node_modules/openai/resources/admin/organization/projects/roles.mjs +0 -108
  664. package/esm/node_modules/openai/resources/admin/organization/projects/roles.mjs.map +0 -1
  665. package/esm/node_modules/openai/resources/admin/organization/projects/service-accounts.mjs +0 -112
  666. package/esm/node_modules/openai/resources/admin/organization/projects/service-accounts.mjs.map +0 -1
  667. package/esm/node_modules/openai/resources/admin/organization/projects/spend-alerts.mjs +0 -106
  668. package/esm/node_modules/openai/resources/admin/organization/projects/spend-alerts.mjs.map +0 -1
  669. package/esm/node_modules/openai/resources/admin/organization/projects/users/roles.mjs +0 -91
  670. package/esm/node_modules/openai/resources/admin/organization/projects/users/roles.mjs.map +0 -1
  671. package/esm/node_modules/openai/resources/admin/organization/projects/users/users.mjs +0 -118
  672. package/esm/node_modules/openai/resources/admin/organization/projects/users/users.mjs.map +0 -1
  673. package/esm/node_modules/openai/resources/admin/organization/roles.mjs +0 -96
  674. package/esm/node_modules/openai/resources/admin/organization/roles.mjs.map +0 -1
  675. package/esm/node_modules/openai/resources/admin/organization/spend-alerts.mjs +0 -97
  676. package/esm/node_modules/openai/resources/admin/organization/spend-alerts.mjs.map +0 -1
  677. package/esm/node_modules/openai/resources/admin/organization/usage.mjs +0 -207
  678. package/esm/node_modules/openai/resources/admin/organization/usage.mjs.map +0 -1
  679. package/esm/node_modules/openai/resources/admin/organization/users/roles.mjs +0 -88
  680. package/esm/node_modules/openai/resources/admin/organization/users/roles.mjs.map +0 -1
  681. package/esm/node_modules/openai/resources/admin/organization/users/users.mjs +0 -82
  682. package/esm/node_modules/openai/resources/admin/organization/users/users.mjs.map +0 -1
  683. package/esm/node_modules/openai/resources/audio/audio.mjs +0 -21
  684. package/esm/node_modules/openai/resources/audio/audio.mjs.map +0 -1
  685. package/esm/node_modules/openai/resources/audio/speech.mjs +0 -39
  686. package/esm/node_modules/openai/resources/audio/speech.mjs.map +0 -1
  687. package/esm/node_modules/openai/resources/audio/transcriptions.mjs +0 -22
  688. package/esm/node_modules/openai/resources/audio/transcriptions.mjs.map +0 -1
  689. package/esm/node_modules/openai/resources/audio/translations.mjs +0 -21
  690. package/esm/node_modules/openai/resources/audio/translations.mjs.map +0 -1
  691. package/esm/node_modules/openai/resources/batches.mjs +0 -54
  692. package/esm/node_modules/openai/resources/batches.mjs.map +0 -1
  693. package/esm/node_modules/openai/resources/beta/assistants.mjs +0 -78
  694. package/esm/node_modules/openai/resources/beta/assistants.mjs.map +0 -1
  695. package/esm/node_modules/openai/resources/beta/beta.mjs +0 -24
  696. package/esm/node_modules/openai/resources/beta/beta.mjs.map +0 -1
  697. package/esm/node_modules/openai/resources/beta/chatkit/chatkit.mjs +0 -18
  698. package/esm/node_modules/openai/resources/beta/chatkit/chatkit.mjs.map +0 -1
  699. package/esm/node_modules/openai/resources/beta/chatkit/sessions.mjs +0 -49
  700. package/esm/node_modules/openai/resources/beta/chatkit/sessions.mjs.map +0 -1
  701. package/esm/node_modules/openai/resources/beta/chatkit/threads.mjs +0 -85
  702. package/esm/node_modules/openai/resources/beta/chatkit/threads.mjs.map +0 -1
  703. package/esm/node_modules/openai/resources/beta/realtime/realtime.mjs +0 -21
  704. package/esm/node_modules/openai/resources/beta/realtime/realtime.mjs.map +0 -1
  705. package/esm/node_modules/openai/resources/beta/realtime/sessions.mjs +0 -33
  706. package/esm/node_modules/openai/resources/beta/realtime/sessions.mjs.map +0 -1
  707. package/esm/node_modules/openai/resources/beta/realtime/transcription-sessions.mjs +0 -33
  708. package/esm/node_modules/openai/resources/beta/realtime/transcription-sessions.mjs.map +0 -1
  709. package/esm/node_modules/openai/resources/beta/threads/messages.mjs +0 -83
  710. package/esm/node_modules/openai/resources/beta/threads/messages.mjs.map +0 -1
  711. package/esm/node_modules/openai/resources/beta/threads/runs/runs.mjs +0 -183
  712. package/esm/node_modules/openai/resources/beta/threads/runs/runs.mjs.map +0 -1
  713. package/esm/node_modules/openai/resources/beta/threads/runs/steps.mjs +0 -45
  714. package/esm/node_modules/openai/resources/beta/threads/runs/steps.mjs.map +0 -1
  715. package/esm/node_modules/openai/resources/beta/threads/threads.mjs +0 -101
  716. package/esm/node_modules/openai/resources/beta/threads/threads.mjs.map +0 -1
  717. package/esm/node_modules/openai/resources/chat/chat.mjs +0 -15
  718. package/esm/node_modules/openai/resources/chat/chat.mjs.map +0 -1
  719. package/esm/node_modules/openai/resources/chat/completions/completions.mjs +0 -123
  720. package/esm/node_modules/openai/resources/chat/completions/completions.mjs.map +0 -1
  721. package/esm/node_modules/openai/resources/chat/completions/index.mjs +0 -7
  722. package/esm/node_modules/openai/resources/chat/completions/messages.mjs +0 -35
  723. package/esm/node_modules/openai/resources/chat/completions/messages.mjs.map +0 -1
  724. package/esm/node_modules/openai/resources/chat/index.mjs +0 -5
  725. package/esm/node_modules/openai/resources/completions.mjs +0 -20
  726. package/esm/node_modules/openai/resources/completions.mjs.map +0 -1
  727. package/esm/node_modules/openai/resources/containers/containers.mjs +0 -57
  728. package/esm/node_modules/openai/resources/containers/containers.mjs.map +0 -1
  729. package/esm/node_modules/openai/resources/containers/files/content.mjs +0 -23
  730. package/esm/node_modules/openai/resources/containers/files/content.mjs.map +0 -1
  731. package/esm/node_modules/openai/resources/containers/files/files.mjs +0 -63
  732. package/esm/node_modules/openai/resources/containers/files/files.mjs.map +0 -1
  733. package/esm/node_modules/openai/resources/conversations/conversations.mjs +0 -57
  734. package/esm/node_modules/openai/resources/conversations/conversations.mjs.map +0 -1
  735. package/esm/node_modules/openai/resources/conversations/items.mjs +0 -57
  736. package/esm/node_modules/openai/resources/conversations/items.mjs.map +0 -1
  737. package/esm/node_modules/openai/resources/embeddings.mjs +0 -48
  738. package/esm/node_modules/openai/resources/embeddings.mjs.map +0 -1
  739. package/esm/node_modules/openai/resources/evals/evals.mjs +0 -73
  740. package/esm/node_modules/openai/resources/evals/evals.mjs.map +0 -1
  741. package/esm/node_modules/openai/resources/evals/runs/output-items.mjs +0 -35
  742. package/esm/node_modules/openai/resources/evals/runs/output-items.mjs.map +0 -1
  743. package/esm/node_modules/openai/resources/evals/runs/runs.mjs +0 -72
  744. package/esm/node_modules/openai/resources/evals/runs/runs.mjs.map +0 -1
  745. package/esm/node_modules/openai/resources/files.mjs +0 -111
  746. package/esm/node_modules/openai/resources/files.mjs.map +0 -1
  747. package/esm/node_modules/openai/resources/fine-tuning/alpha/alpha.mjs +0 -15
  748. package/esm/node_modules/openai/resources/fine-tuning/alpha/alpha.mjs.map +0 -1
  749. package/esm/node_modules/openai/resources/fine-tuning/alpha/graders.mjs +0 -60
  750. package/esm/node_modules/openai/resources/fine-tuning/alpha/graders.mjs.map +0 -1
  751. package/esm/node_modules/openai/resources/fine-tuning/checkpoints/checkpoints.mjs +0 -15
  752. package/esm/node_modules/openai/resources/fine-tuning/checkpoints/checkpoints.mjs.map +0 -1
  753. package/esm/node_modules/openai/resources/fine-tuning/checkpoints/permissions.mjs +0 -102
  754. package/esm/node_modules/openai/resources/fine-tuning/checkpoints/permissions.mjs.map +0 -1
  755. package/esm/node_modules/openai/resources/fine-tuning/fine-tuning.mjs +0 -24
  756. package/esm/node_modules/openai/resources/fine-tuning/fine-tuning.mjs.map +0 -1
  757. package/esm/node_modules/openai/resources/fine-tuning/jobs/checkpoints.mjs +0 -34
  758. package/esm/node_modules/openai/resources/fine-tuning/jobs/checkpoints.mjs.map +0 -1
  759. package/esm/node_modules/openai/resources/fine-tuning/jobs/jobs.mjs +0 -148
  760. package/esm/node_modules/openai/resources/fine-tuning/jobs/jobs.mjs.map +0 -1
  761. package/esm/node_modules/openai/resources/fine-tuning/methods.mjs +0 -8
  762. package/esm/node_modules/openai/resources/fine-tuning/methods.mjs.map +0 -1
  763. package/esm/node_modules/openai/resources/graders/grader-models.mjs +0 -8
  764. package/esm/node_modules/openai/resources/graders/grader-models.mjs.map +0 -1
  765. package/esm/node_modules/openai/resources/graders/graders.mjs +0 -15
  766. package/esm/node_modules/openai/resources/graders/graders.mjs.map +0 -1
  767. package/esm/node_modules/openai/resources/images.mjs +0 -46
  768. package/esm/node_modules/openai/resources/images.mjs.map +0 -1
  769. package/esm/node_modules/openai/resources/index.mjs +0 -27
  770. package/esm/node_modules/openai/resources/models.mjs +0 -44
  771. package/esm/node_modules/openai/resources/models.mjs.map +0 -1
  772. package/esm/node_modules/openai/resources/moderations.mjs +0 -23
  773. package/esm/node_modules/openai/resources/moderations.mjs.map +0 -1
  774. package/esm/node_modules/openai/resources/realtime/calls.mjs +0 -79
  775. package/esm/node_modules/openai/resources/realtime/calls.mjs.map +0 -1
  776. package/esm/node_modules/openai/resources/realtime/client-secrets.mjs +0 -39
  777. package/esm/node_modules/openai/resources/realtime/client-secrets.mjs.map +0 -1
  778. package/esm/node_modules/openai/resources/realtime/realtime.mjs +0 -18
  779. package/esm/node_modules/openai/resources/realtime/realtime.mjs.map +0 -1
  780. package/esm/node_modules/openai/resources/responses/input-items.mjs +0 -31
  781. package/esm/node_modules/openai/resources/responses/input-items.mjs.map +0 -1
  782. package/esm/node_modules/openai/resources/responses/input-tokens.mjs +0 -27
  783. package/esm/node_modules/openai/resources/responses/input-tokens.mjs.map +0 -1
  784. package/esm/node_modules/openai/resources/responses/responses.mjs +0 -110
  785. package/esm/node_modules/openai/resources/responses/responses.mjs.map +0 -1
  786. package/esm/node_modules/openai/resources/skills/content.mjs +0 -22
  787. package/esm/node_modules/openai/resources/skills/content.mjs.map +0 -1
  788. package/esm/node_modules/openai/resources/skills/skills.mjs +0 -69
  789. package/esm/node_modules/openai/resources/skills/skills.mjs.map +0 -1
  790. package/esm/node_modules/openai/resources/skills/versions/content.mjs +0 -23
  791. package/esm/node_modules/openai/resources/skills/versions/content.mjs.map +0 -1
  792. package/esm/node_modules/openai/resources/skills/versions/versions.mjs +0 -58
  793. package/esm/node_modules/openai/resources/skills/versions/versions.mjs.map +0 -1
  794. package/esm/node_modules/openai/resources/uploads/parts.mjs +0 -34
  795. package/esm/node_modules/openai/resources/uploads/parts.mjs.map +0 -1
  796. package/esm/node_modules/openai/resources/uploads/uploads.mjs +0 -84
  797. package/esm/node_modules/openai/resources/uploads/uploads.mjs.map +0 -1
  798. package/esm/node_modules/openai/resources/vector-stores/file-batches.mjs +0 -126
  799. package/esm/node_modules/openai/resources/vector-stores/file-batches.mjs.map +0 -1
  800. package/esm/node_modules/openai/resources/vector-stores/files.mjs +0 -147
  801. package/esm/node_modules/openai/resources/vector-stores/files.mjs.map +0 -1
  802. package/esm/node_modules/openai/resources/vector-stores/vector-stores.mjs +0 -87
  803. package/esm/node_modules/openai/resources/vector-stores/vector-stores.mjs.map +0 -1
  804. package/esm/node_modules/openai/resources/videos.mjs +0 -115
  805. package/esm/node_modules/openai/resources/videos.mjs.map +0 -1
  806. package/esm/node_modules/openai/resources/webhooks/index.mjs +0 -3
  807. package/esm/node_modules/openai/resources/webhooks/webhooks.mjs +0 -69
  808. package/esm/node_modules/openai/resources/webhooks/webhooks.mjs.map +0 -1
  809. package/esm/node_modules/openai/resources/webhooks.mjs +0 -4
  810. package/esm/node_modules/openai/streaming.mjs +0 -3
  811. package/esm/node_modules/openai/version.mjs +0 -6
  812. package/esm/node_modules/openai/version.mjs.map +0 -1
@@ -1,99 +0,0 @@
1
- //#region ../@warlock.js/ai/src/guard/detectors/topic.ts
2
- /** Detector name, used as the namespace prefix on every {@link GuardrailMatch.rule}. */
3
- const DETECTOR_NAME = "topic";
4
- /**
5
- * Locate the first occurrence of `term` in `text`. A `string` matches
6
- * case-insensitively as a substring; a `RegExp` is tested as-is (its own
7
- * flags decide case-sensitivity). Returns the inclusive `[start, end]`
8
- * span on a hit, or `undefined` when the term is absent.
9
- */
10
- function locate(text, term) {
11
- if (typeof term === "string") {
12
- if (term.length === 0) return;
13
- const index = text.toLowerCase().indexOf(term.toLowerCase());
14
- if (index === -1) return;
15
- return [index, index + term.length - 1];
16
- }
17
- const match = new RegExp(term.source, term.flags.replace(/[gy]/g, "")).exec(text);
18
- if (match === null) return;
19
- return [match.index, match.index + match[0].length - 1];
20
- }
21
- /** A human-readable label for a deny/allow term, used in the match rule + reason. */
22
- function describeTerm(term) {
23
- return typeof term === "string" ? term : term.source;
24
- }
25
- /**
26
- * Build the built-in **topic filter** (`ai.guardrail.topic`) — a
27
- * zero-runtime-dependency {@link GuardrailDetector} that gates text against a
28
- * deny list, an allow list, or both.
29
- *
30
- * - **`deny`** — any term that appears triggers `onMatch`. A `string`
31
- * matches case-insensitively as a substring; a `RegExp` is tested as-is.
32
- * The deny list is checked first; the first hit decides the verdict.
33
- * - **`allow`** — when set, text matching **none** of the allow terms
34
- * triggers `onMatch` (an allow-list miss). Text matching at least one
35
- * allow term passes the allow gate.
36
- *
37
- * `onMatch` is `"block"` (default) or `"flag"`. With neither list supplied
38
- * the detector is a no-op that always allows.
39
- *
40
- * @example
41
- * ai.guardrail.topic({ deny: ["medical advice", /diagnos\w+/i] });
42
- *
43
- * @example
44
- * // Stay on-topic: anything not about billing is flagged.
45
- * ai.guardrail.topic({ allow: ["billing", "invoice", "refund"], onMatch: "flag" });
46
- */
47
- function topic(options) {
48
- const deny = options.deny ?? [];
49
- const allow = options.allow ?? [];
50
- const onMatch = options.onMatch ?? "block";
51
- return {
52
- name: DETECTOR_NAME,
53
- check(text) {
54
- for (const term of deny) {
55
- const span = locate(text, term);
56
- if (span !== void 0) {
57
- const label = describeTerm(term);
58
- const match = {
59
- rule: `${DETECTOR_NAME}.deny.${label}`,
60
- span,
61
- label
62
- };
63
- return verdict(onMatch, options.reason ?? `Denied topic matched: ${label}.`, [match]);
64
- }
65
- }
66
- if (allow.length > 0) {
67
- if (!allow.some((term) => locate(text, term) !== void 0)) {
68
- const match = {
69
- rule: `${DETECTOR_NAME}.allow.miss`,
70
- label: "allow-miss"
71
- };
72
- return verdict(onMatch, options.reason ?? "Text matched none of the allowed topics.", [match]);
73
- }
74
- }
75
- return { type: "allow" };
76
- }
77
- };
78
- }
79
- /**
80
- * Fold the resolved action into a `block` or `flag` verdict. Topic never
81
- * redacts — it cannot meaningfully rewrite a whole-text policy miss — so the
82
- * action is constrained to `"block" | "flag"` at the type level.
83
- */
84
- function verdict(action, reason, matches) {
85
- if (action === "block") return {
86
- type: "block",
87
- reason,
88
- matches
89
- };
90
- return {
91
- type: "flag",
92
- reason,
93
- matches
94
- };
95
- }
96
-
97
- //#endregion
98
- export { topic };
99
- //# sourceMappingURL=topic.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"topic.mjs","names":[],"sources":["../../../../../../../../../../@warlock.js/ai/src/guard/detectors/topic.ts"],"sourcesContent":["import type {\n GuardrailMatch,\n GuardrailVerdict,\n SyncGuardrailDetector,\n TopicFilterOptions,\n} from \"../contracts\";\n\n/** Detector name, used as the namespace prefix on every {@link GuardrailMatch.rule}. */\nconst DETECTOR_NAME = \"topic\";\n\n/**\n * Locate the first occurrence of `term` in `text`. A `string` matches\n * case-insensitively as a substring; a `RegExp` is tested as-is (its own\n * flags decide case-sensitivity). Returns the inclusive `[start, end]`\n * span on a hit, or `undefined` when the term is absent.\n */\nfunction locate(text: string, term: string | RegExp): readonly [number, number] | undefined {\n if (typeof term === \"string\") {\n if (term.length === 0) {\n return undefined;\n }\n\n const index = text.toLowerCase().indexOf(term.toLowerCase());\n\n if (index === -1) {\n return undefined;\n }\n\n return [index, index + term.length - 1];\n }\n\n // RegExp: run a non-global copy so a caller-supplied `/g` term cannot leak\n // `lastIndex` between calls and so `.exec` reports a deterministic first hit.\n const probe = new RegExp(term.source, term.flags.replace(/[gy]/g, \"\"));\n const match = probe.exec(text);\n\n if (match === null) {\n return undefined;\n }\n\n return [match.index, match.index + match[0].length - 1];\n}\n\n/** A human-readable label for a deny/allow term, used in the match rule + reason. */\nfunction describeTerm(term: string | RegExp): string {\n return typeof term === \"string\" ? term : term.source;\n}\n\n/**\n * Build the built-in **topic filter** (`ai.guardrail.topic`) — a\n * zero-runtime-dependency {@link GuardrailDetector} that gates text against a\n * deny list, an allow list, or both.\n *\n * - **`deny`** — any term that appears triggers `onMatch`. A `string`\n * matches case-insensitively as a substring; a `RegExp` is tested as-is.\n * The deny list is checked first; the first hit decides the verdict.\n * - **`allow`** — when set, text matching **none** of the allow terms\n * triggers `onMatch` (an allow-list miss). Text matching at least one\n * allow term passes the allow gate.\n *\n * `onMatch` is `\"block\"` (default) or `\"flag\"`. With neither list supplied\n * the detector is a no-op that always allows.\n *\n * @example\n * ai.guardrail.topic({ deny: [\"medical advice\", /diagnos\\w+/i] });\n *\n * @example\n * // Stay on-topic: anything not about billing is flagged.\n * ai.guardrail.topic({ allow: [\"billing\", \"invoice\", \"refund\"], onMatch: \"flag\" });\n */\nexport function topic(options: TopicFilterOptions): SyncGuardrailDetector {\n const deny = options.deny ?? [];\n const allow = options.allow ?? [];\n const onMatch = options.onMatch ?? \"block\";\n\n return {\n name: DETECTOR_NAME,\n check(text: string): GuardrailVerdict {\n // Deny list: the first present term decides the verdict.\n for (const term of deny) {\n const span = locate(text, term);\n\n if (span !== undefined) {\n const label = describeTerm(term);\n const match: GuardrailMatch = {\n rule: `${DETECTOR_NAME}.deny.${label}`,\n span,\n label,\n };\n const reason = options.reason ?? `Denied topic matched: ${label}.`;\n\n return verdict(onMatch, reason, [match]);\n }\n }\n\n // Allow list: matching NONE of the terms is a miss → trigger onMatch.\n if (allow.length > 0) {\n const matchedAny = allow.some(term => locate(text, term) !== undefined);\n\n if (!matchedAny) {\n const match: GuardrailMatch = {\n rule: `${DETECTOR_NAME}.allow.miss`,\n label: \"allow-miss\",\n };\n const reason =\n options.reason ?? \"Text matched none of the allowed topics.\";\n\n return verdict(onMatch, reason, [match]);\n }\n }\n\n return { type: \"allow\" };\n },\n };\n}\n\n/**\n * Fold the resolved action into a `block` or `flag` verdict. Topic never\n * redacts — it cannot meaningfully rewrite a whole-text policy miss — so the\n * action is constrained to `\"block\" | \"flag\"` at the type level.\n */\nfunction verdict(\n action: \"block\" | \"flag\",\n reason: string,\n matches: readonly GuardrailMatch[],\n): GuardrailVerdict {\n if (action === \"block\") {\n return { type: \"block\", reason, matches };\n }\n\n return { type: \"flag\", reason, matches };\n}\n"],"mappings":";;AAQA,MAAM,gBAAgB;;;;;;;AAQtB,SAAS,OAAO,MAAc,MAA8D;CAC1F,IAAI,OAAO,SAAS,UAAU;EAC5B,IAAI,KAAK,WAAW,GAClB;EAGF,MAAM,QAAQ,KAAK,YAAY,CAAC,CAAC,QAAQ,KAAK,YAAY,CAAC;EAE3D,IAAI,UAAU,IACZ;EAGF,OAAO,CAAC,OAAO,QAAQ,KAAK,SAAS,CAAC;CACxC;CAKA,MAAM,QAAQ,IADI,OAAO,KAAK,QAAQ,KAAK,MAAM,QAAQ,SAAS,EAAE,CAClD,CAAC,CAAC,KAAK,IAAI;CAE7B,IAAI,UAAU,MACZ;CAGF,OAAO,CAAC,MAAM,OAAO,MAAM,QAAQ,MAAM,EAAE,CAAC,SAAS,CAAC;AACxD;;AAGA,SAAS,aAAa,MAA+B;CACnD,OAAO,OAAO,SAAS,WAAW,OAAO,KAAK;AAChD;;;;;;;;;;;;;;;;;;;;;;;AAwBA,SAAgB,MAAM,SAAoD;CACxE,MAAM,OAAO,QAAQ,QAAQ,CAAC;CAC9B,MAAM,QAAQ,QAAQ,SAAS,CAAC;CAChC,MAAM,UAAU,QAAQ,WAAW;CAEnC,OAAO;EACL,MAAM;EACN,MAAM,MAAgC;GAEpC,KAAK,MAAM,QAAQ,MAAM;IACvB,MAAM,OAAO,OAAO,MAAM,IAAI;IAE9B,IAAI,SAAS,QAAW;KACtB,MAAM,QAAQ,aAAa,IAAI;KAC/B,MAAM,QAAwB;MAC5B,MAAM,GAAG,cAAc,QAAQ;MAC/B;MACA;KACF;KAGA,OAAO,QAAQ,SAFA,QAAQ,UAAU,yBAAyB,MAAM,IAEhC,CAAC,KAAK,CAAC;IACzC;GACF;GAGA,IAAI,MAAM,SAAS,GAGjB;QAAI,CAFe,MAAM,MAAK,SAAQ,OAAO,MAAM,IAAI,MAAM,MAE/C,GAAG;KACf,MAAM,QAAwB;MAC5B,MAAM,GAAG,cAAc;MACvB,OAAO;KACT;KAIA,OAAO,QAAQ,SAFb,QAAQ,UAAU,4CAEY,CAAC,KAAK,CAAC;IACzC;;GAGF,OAAO,EAAE,MAAM,QAAQ;EACzB;CACF;AACF;;;;;;AAOA,SAAS,QACP,QACA,QACA,SACkB;CAClB,IAAI,WAAW,SACb,OAAO;EAAE,MAAM;EAAS;EAAQ;CAAQ;CAG1C,OAAO;EAAE,MAAM;EAAQ;EAAQ;CAAQ;AACzC"}
@@ -1,18 +0,0 @@
1
- import { GuardrailViolationError } from "../errors/guardrail-violation-error.mjs";
2
-
3
- //#region ../@warlock.js/ai/src/guard/errors.ts
4
- /**
5
- * Curated install string thrown by the optional `moderation` detector on
6
- * first `check()` when the `openai` peer is absent. Mirrors ai-panoptic's
7
- * `LANGFUSE_INSTALL_INSTRUCTIONS`.
8
- */
9
- const OPENAI_INSTALL_INSTRUCTIONS = `
10
- The @warlock.js/ai moderation detector requires the optional "openai" peer.
11
- Install it with:
12
-
13
- npm install openai
14
- `.trim();
15
-
16
- //#endregion
17
- export { OPENAI_INSTALL_INSTRUCTIONS };
18
- //# sourceMappingURL=errors.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"errors.mjs","names":[],"sources":["../../../../../../../../../@warlock.js/ai/src/guard/errors.ts"],"sourcesContent":["/**\n * Error surface for `@warlock.js/ai`.\n *\n * **No new error class.** A `block` verdict reuses the existing\n * `@warlock.js/ai` {@link GuardrailViolationError} verbatim — its category\n * (`\"guardrail\"`) and `phase` field already model exactly what a guard\n * needs, and `phase` is widened by this package to include `\"tool\"` (a\n * source-compatible third value). Re-exported here so the future `guard()`\n * factory has one import site for the typed abort it throws.\n *\n * The optional `moderation` detector's missing-peer failure is an\n * *infrastructure* fault, not a content violation, so it throws a plain\n * `Error` carrying {@link OPENAI_INSTALL_INSTRUCTIONS} (the langfuse-style\n * lazy-import pattern) rather than an `AIError`.\n */\nexport { GuardrailViolationError } from \"../errors/guardrail-violation-error\";\nexport type { GuardrailViolationErrorOptions } from \"../errors/guardrail-violation-error\";\n\n/**\n * Curated install string thrown by the optional `moderation` detector on\n * first `check()` when the `openai` peer is absent. Mirrors ai-panoptic's\n * `LANGFUSE_INSTALL_INSTRUCTIONS`.\n */\nexport const OPENAI_INSTALL_INSTRUCTIONS = `\nThe @warlock.js/ai moderation detector requires the optional \"openai\" peer.\nInstall it with:\n\n npm install openai\n`.trim();\n"],"mappings":";;;;;;;;AAuBA,MAAa,8BAA8B;;;;;EAKzC,KAAK"}
@@ -1,209 +0,0 @@
1
- import { GuardrailViolationError } from "../errors/guardrail-violation-error.mjs";
2
- import { extractUserText } from "../middleware/utils/extract-user-text.mjs";
3
- import { forTool } from "../middleware/helpers/for-tool.mjs";
4
- import "./errors.mjs";
5
-
6
- //#region ../@warlock.js/ai/src/guard/guard.ts
7
- /** Default middleware name when the caller supplies none. */
8
- const DEFAULT_NAME = "guardrail";
9
- /**
10
- * The `ctx.state` key under which a guard records its `flag` verdicts. The
11
- * value is an append-only array of {@link FlagRecord}, namespaced by the
12
- * middleware name so two guards on the same agent never collide and a
13
- * downstream observer (panoptic, the caller) can read the annotations
14
- * post-run.
15
- */
16
- function flagsKey(name) {
17
- return `${name}.flags`;
18
- }
19
- /**
20
- * Append a `flag` record onto the namespaced `ctx.state` array, creating it
21
- * on first write. Never throws — recording is best-effort annotation.
22
- */
23
- function recordFlag(ctx, name, record) {
24
- const key = flagsKey(name);
25
- const existing = ctx.state.get(key);
26
- const flags = Array.isArray(existing) ? existing : [];
27
- flags.push(record);
28
- ctx.state.set(key, flags);
29
- }
30
- /**
31
- * Run a phase's detector array over `text`, in registration order, and fold
32
- * the verdicts into a single {@link PhaseOutcome}.
33
- *
34
- * **Short-circuit.** The first non-`allow`/non-`flag` verdict (a `redact` or
35
- * `block`) decides the outcome and stops the fold — outer detectors never run
36
- * after one objects, matching the install-array ordering. `flag` verdicts are
37
- * recorded into `ctx.state` and the fold continues (allow-but-annotate).
38
- *
39
- * **Phase-aware redact downgrade.** A `redact` verdict is only honoured where
40
- * the seam supports rewrite-and-continue:
41
- * - `"output"` — `trip.after` may return a replacement `ModelResponse`, so the
42
- * rewritten text is threaded out.
43
- * - `"input"` — the core `trip.before` hook can only short-circuit (return a
44
- * response) or throw; it has **no** rewrite-and-continue seam, so an input
45
- * `redact` is downgraded to a `block` rather than silently passing the
46
- * un-redacted prompt through. (Documented on {@link GuardOptions.input}.)
47
- * - `"tool"` — silently rewriting tool arguments changes the call's
48
- * side-effects unpredictably, so a tool `redact` is downgraded to a `block`
49
- * (`tool-arg-redaction-unsupported`) rather than mutating what the tool runs.
50
- *
51
- * **Fail-open on detector fault.** A detector's `check()` rejecting is an
52
- * infrastructure fault, not a content violation — it is recorded as a `flag`
53
- * (`<detector>.error`) and the fold continues, so a moderation-API outage does
54
- * not abort every agent run.
55
- */
56
- async function runDetectors(detectors, text, phase, ctx, name) {
57
- for (const detector of detectors) {
58
- let verdict;
59
- try {
60
- verdict = await detector.check(text, {
61
- phase,
62
- ctx
63
- });
64
- } catch (error) {
65
- recordFlag(ctx, name, {
66
- detector: detector.name,
67
- phase,
68
- reason: `detector "${detector.name}" threw: ${error instanceof Error ? error.message : String(error)}`,
69
- matches: []
70
- });
71
- continue;
72
- }
73
- if (verdict.type === "allow") continue;
74
- if (verdict.type === "flag") {
75
- recordFlag(ctx, name, {
76
- detector: detector.name,
77
- phase,
78
- reason: verdict.reason,
79
- matches: verdict.matches
80
- });
81
- continue;
82
- }
83
- if (verdict.type === "redact") {
84
- if (phase === "output") return {
85
- type: "redact",
86
- text: verdict.text
87
- };
88
- return {
89
- type: "block",
90
- reason: phase === "tool" ? "tool-arg-redaction-unsupported" : verdict.reason,
91
- matches: verdict.matches,
92
- escalate: false
93
- };
94
- }
95
- return {
96
- type: "block",
97
- reason: verdict.reason,
98
- matches: verdict.matches,
99
- escalate: verdict.escalate ?? false
100
- };
101
- }
102
- return { type: "allow" };
103
- }
104
- /**
105
- * Realize a `block` outcome: fire the escalation seam (when the verdict asked
106
- * for it) and throw the typed {@link GuardrailViolationError} on `result.error`.
107
- * Never returns — always throws.
108
- *
109
- * The core `GuardrailViolationError.phase` is typed `"input" | "output"`; this
110
- * package widens the surfaced `phase` with `"tool"` (a source-compatible third
111
- * value), so the construction site asserts the wider value through the options
112
- * shape the error already accepts at runtime.
113
- */
114
- async function block(outcome, phase, ctx, name, escalation) {
115
- if (outcome.escalate) await escalation?.onBlock?.({
116
- phase,
117
- reason: outcome.reason,
118
- matches: outcome.matches,
119
- ctx
120
- });
121
- throw new GuardrailViolationError(`guardrail "${name}" rejected ${phase} — ${outcome.reason}`, {
122
- phase,
123
- reason: outcome.reason,
124
- guardrail: name
125
- });
126
- }
127
- /**
128
- * Build the composed **guardrail middleware** (surfaced as
129
- * `ai.guardrail(options)`) — one {@link AgentMiddleware} that runs the
130
- * configured detectors at three hook points and maps each
131
- * {@link GuardrailVerdict} onto the pipeline's throw / return / record
132
- * mechanics:
133
- *
134
- * - **`input`** detectors run at `trip.before` over the outbound prompt
135
- * (`extractUserText(ctx.messages)`). `block` / `flag` only — the core
136
- * `trip.before` seam cannot rewrite-and-continue, so a `redact` verdict here
137
- * is downgraded to a `block`.
138
- * - **`output`** detectors run at `trip.after` over `response.content`. Full
139
- * `allow` / `redact` / `block` / `flag` support — a `redact` returns a
140
- * replacement `ModelResponse` with the rewritten `content`.
141
- * - **`tool`** detectors run at `tool.before` over `JSON.stringify(toolArgs)`.
142
- * `block` / `flag`; a `redact` is downgraded to a `block`
143
- * (`tool-arg-redaction-unsupported`). Scoped to `toolNames` via the core
144
- * `forTool(toolNames, mw)` helper when set.
145
- *
146
- * **Verdict → action.** Detectors run in registration order; the first
147
- * `redact` / `block` short-circuits the phase. `block` throws a
148
- * {@link GuardrailViolationError} on `result.error` (never out of the
149
- * pipeline); `flag` records the match into `ctx.state` under `<name>.flags`
150
- * and continues; a `{ type: "block", escalate: true }` verdict awaits
151
- * `escalation.onBlock` before throwing. A detector that *throws* is treated as
152
- * an infra fault and fails open (recorded as a flag, run continues).
153
- *
154
- * @param options - The {@link GuardOptions}: per-phase detector arrays,
155
- * optional `toolNames` scope, `escalation` seam, and `name` override.
156
- * @returns One {@link AgentMiddleware} to pass into `ai.agent({ middleware: [...] })`.
157
- *
158
- * @example
159
- * const policy = ai.guardrail({
160
- * name: "compliance",
161
- * input: [ai.guardrail.injection({ onMatch: "block" })],
162
- * output: [ai.guardrail.pii({ onMatch: "redact", mask: "[REDACTED:{label}]" })],
163
- * tool: [ai.guardrail.pii({ onMatch: "block" })],
164
- * toolNames: ["send_email"],
165
- * escalation: { async onBlock(e) { await reviewQueue.enqueue(e); } },
166
- * });
167
- *
168
- * const agent = ai.agent({ model, tools: [sendEmail], middleware: [policy] });
169
- */
170
- function guard(options) {
171
- const name = options.name ?? DEFAULT_NAME;
172
- const input = options.input ?? [];
173
- const output = options.output ?? [];
174
- const tool = options.tool ?? [];
175
- const escalation = options.escalation;
176
- const middleware = {
177
- name,
178
- trip: {
179
- async before(ctx) {
180
- if (input.length === 0) return;
181
- const prompt = extractUserText(ctx.messages);
182
- if (!prompt) return;
183
- const outcome = await runDetectors(input, prompt, "input", ctx, name);
184
- if (outcome.type === "block") await block(outcome, "input", ctx, name, escalation);
185
- },
186
- async after(ctx, response) {
187
- if (output.length === 0 || !response.content) return;
188
- const outcome = await runDetectors(output, response.content, "output", ctx, name);
189
- if (outcome.type === "block") await block(outcome, "output", ctx, name, escalation);
190
- if (outcome.type === "redact") return {
191
- ...response,
192
- content: outcome.text
193
- };
194
- }
195
- }
196
- };
197
- if (tool.length > 0) middleware.tool = { async before(ctx) {
198
- const args = JSON.stringify(ctx.request.input);
199
- if (!args) return;
200
- const outcome = await runDetectors(tool, args, "tool", ctx, name);
201
- if (outcome.type === "block") await block(outcome, "tool", ctx, name, escalation);
202
- } };
203
- if (options.toolNames !== void 0 && middleware.tool) return forTool(options.toolNames, middleware);
204
- return middleware;
205
- }
206
-
207
- //#endregion
208
- export { guard };
209
- //# sourceMappingURL=guard.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"guard.mjs","names":[],"sources":["../../../../../../../../../@warlock.js/ai/src/guard/guard.ts"],"sourcesContent":["import { extractUserText } from \"../middleware/utils/extract-user-text\";\nimport { forTool } from \"../middleware/helpers/for-tool\";\nimport type { AgentMiddleware } from \"../contracts/middleware/middleware.contract\";\nimport type {\n MiddlewareToolContext,\n MiddlewareTripContext,\n} from \"../contracts/middleware/middleware-context.type\";\nimport type { ModelResponse } from \"../contracts/model.contract\";\nimport type {\n GuardOptions,\n GuardrailDetector,\n GuardrailEscalation,\n GuardrailMatch,\n GuardrailPhase,\n GuardrailVerdict,\n} from \"./contracts\";\nimport { GuardrailViolationError } from \"./errors\";\n\n/** Default middleware name when the caller supplies none. */\nconst DEFAULT_NAME = \"guardrail\";\n\n/**\n * The `ctx.state` key under which a guard records its `flag` verdicts. The\n * value is an append-only array of {@link FlagRecord}, namespaced by the\n * middleware name so two guards on the same agent never collide and a\n * downstream observer (panoptic, the caller) can read the annotations\n * post-run.\n */\nfunction flagsKey(name: string): string {\n return `${name}.flags`;\n}\n\n/**\n * One flagged match recorded into `ctx.state`. Mirrors the\n * {@link GuardrailVerdict} `flag` shape plus the phase it fired at, so an\n * observer can reconstruct *what* tripped *where* without re-running the\n * detector.\n */\nexport interface FlagRecord {\n /** The detector that produced the flag. */\n readonly detector: string;\n /** Where the detector was running. */\n readonly phase: GuardrailPhase;\n /** The detector's human-readable reason. */\n readonly reason: string;\n /** The matches the detector recorded. */\n readonly matches: readonly GuardrailMatch[];\n}\n\n/**\n * Append a `flag` record onto the namespaced `ctx.state` array, creating it\n * on first write. Never throws — recording is best-effort annotation.\n */\nfunction recordFlag(\n ctx: MiddlewareTripContext,\n name: string,\n record: FlagRecord,\n): void {\n const key = flagsKey(name);\n const existing = ctx.state.get(key);\n const flags = Array.isArray(existing) ? (existing as FlagRecord[]) : [];\n\n flags.push(record);\n ctx.state.set(key, flags);\n}\n\n/**\n * The outcome of folding a phase's detector array — what the hook should do\n * with the inspected text once every detector has had its say.\n *\n * - `allow` — no detector objected; the hook continues untouched.\n * - `redact` — a detector returned rewritten `text`; the hook substitutes it\n * (output / tool phases only — see {@link runDetectors}).\n * - `block` — a detector rejected; the hook throws a\n * {@link GuardrailViolationError} carrying `reason` / `matches` / `escalate`.\n *\n * `flag` verdicts never reach this type — they are recorded into `ctx.state`\n * as a side effect inside {@link runDetectors} and do not short-circuit the\n * fold, so a flagged-but-otherwise-clean run resolves to `allow`.\n */\ntype PhaseOutcome =\n | { readonly type: \"allow\" }\n | { readonly type: \"redact\"; readonly text: string }\n | {\n readonly type: \"block\";\n readonly reason: string;\n readonly matches?: readonly GuardrailMatch[];\n readonly escalate: boolean;\n };\n\n/**\n * Run a phase's detector array over `text`, in registration order, and fold\n * the verdicts into a single {@link PhaseOutcome}.\n *\n * **Short-circuit.** The first non-`allow`/non-`flag` verdict (a `redact` or\n * `block`) decides the outcome and stops the fold — outer detectors never run\n * after one objects, matching the install-array ordering. `flag` verdicts are\n * recorded into `ctx.state` and the fold continues (allow-but-annotate).\n *\n * **Phase-aware redact downgrade.** A `redact` verdict is only honoured where\n * the seam supports rewrite-and-continue:\n * - `\"output\"` — `trip.after` may return a replacement `ModelResponse`, so the\n * rewritten text is threaded out.\n * - `\"input\"` — the core `trip.before` hook can only short-circuit (return a\n * response) or throw; it has **no** rewrite-and-continue seam, so an input\n * `redact` is downgraded to a `block` rather than silently passing the\n * un-redacted prompt through. (Documented on {@link GuardOptions.input}.)\n * - `\"tool\"` — silently rewriting tool arguments changes the call's\n * side-effects unpredictably, so a tool `redact` is downgraded to a `block`\n * (`tool-arg-redaction-unsupported`) rather than mutating what the tool runs.\n *\n * **Fail-open on detector fault.** A detector's `check()` rejecting is an\n * infrastructure fault, not a content violation — it is recorded as a `flag`\n * (`<detector>.error`) and the fold continues, so a moderation-API outage does\n * not abort every agent run.\n */\nasync function runDetectors(\n detectors: readonly GuardrailDetector[],\n text: string,\n phase: GuardrailPhase,\n ctx: MiddlewareTripContext,\n name: string,\n): Promise<PhaseOutcome> {\n for (const detector of detectors) {\n let verdict: GuardrailVerdict;\n\n try {\n verdict = await detector.check(text, { phase, ctx });\n } catch (error) {\n // Infra fault — fail open: record and continue, never abort the run.\n recordFlag(ctx, name, {\n detector: detector.name,\n phase,\n reason: `detector \"${detector.name}\" threw: ${\n error instanceof Error ? error.message : String(error)\n }`,\n matches: [],\n });\n\n continue;\n }\n\n if (verdict.type === \"allow\") {\n continue;\n }\n\n if (verdict.type === \"flag\") {\n recordFlag(ctx, name, {\n detector: detector.name,\n phase,\n reason: verdict.reason,\n matches: verdict.matches,\n });\n\n continue;\n }\n\n if (verdict.type === \"redact\") {\n if (phase === \"output\") {\n return { type: \"redact\", text: verdict.text };\n }\n\n // Input / tool phases have no safe rewrite-and-continue seam — downgrade\n // to a block so the un-redacted text is never threaded through.\n const reason =\n phase === \"tool\"\n ? \"tool-arg-redaction-unsupported\"\n : verdict.reason;\n\n return {\n type: \"block\",\n reason,\n matches: verdict.matches,\n escalate: false,\n };\n }\n\n // verdict.type === \"block\"\n return {\n type: \"block\",\n reason: verdict.reason,\n matches: verdict.matches,\n escalate: verdict.escalate ?? false,\n };\n }\n\n return { type: \"allow\" };\n}\n\n/**\n * Realize a `block` outcome: fire the escalation seam (when the verdict asked\n * for it) and throw the typed {@link GuardrailViolationError} on `result.error`.\n * Never returns — always throws.\n *\n * The core `GuardrailViolationError.phase` is typed `\"input\" | \"output\"`; this\n * package widens the surfaced `phase` with `\"tool\"` (a source-compatible third\n * value), so the construction site asserts the wider value through the options\n * shape the error already accepts at runtime.\n */\nasync function block(\n outcome: Extract<PhaseOutcome, { type: \"block\" }>,\n phase: GuardrailPhase,\n ctx: MiddlewareTripContext,\n name: string,\n escalation: GuardrailEscalation | undefined,\n): Promise<never> {\n if (outcome.escalate) {\n await escalation?.onBlock?.({\n phase,\n reason: outcome.reason,\n matches: outcome.matches,\n ctx,\n });\n }\n\n throw new GuardrailViolationError(\n `guardrail \"${name}\" rejected ${phase} — ${outcome.reason}`,\n {\n // `phase` is widened to include \"tool\"; the error carries it verbatim.\n phase: phase as \"input\" | \"output\",\n reason: outcome.reason,\n guardrail: name,\n },\n );\n}\n\n/**\n * Build the composed **guardrail middleware** (surfaced as\n * `ai.guardrail(options)`) — one {@link AgentMiddleware} that runs the\n * configured detectors at three hook points and maps each\n * {@link GuardrailVerdict} onto the pipeline's throw / return / record\n * mechanics:\n *\n * - **`input`** detectors run at `trip.before` over the outbound prompt\n * (`extractUserText(ctx.messages)`). `block` / `flag` only — the core\n * `trip.before` seam cannot rewrite-and-continue, so a `redact` verdict here\n * is downgraded to a `block`.\n * - **`output`** detectors run at `trip.after` over `response.content`. Full\n * `allow` / `redact` / `block` / `flag` support — a `redact` returns a\n * replacement `ModelResponse` with the rewritten `content`.\n * - **`tool`** detectors run at `tool.before` over `JSON.stringify(toolArgs)`.\n * `block` / `flag`; a `redact` is downgraded to a `block`\n * (`tool-arg-redaction-unsupported`). Scoped to `toolNames` via the core\n * `forTool(toolNames, mw)` helper when set.\n *\n * **Verdict → action.** Detectors run in registration order; the first\n * `redact` / `block` short-circuits the phase. `block` throws a\n * {@link GuardrailViolationError} on `result.error` (never out of the\n * pipeline); `flag` records the match into `ctx.state` under `<name>.flags`\n * and continues; a `{ type: \"block\", escalate: true }` verdict awaits\n * `escalation.onBlock` before throwing. A detector that *throws* is treated as\n * an infra fault and fails open (recorded as a flag, run continues).\n *\n * @param options - The {@link GuardOptions}: per-phase detector arrays,\n * optional `toolNames` scope, `escalation` seam, and `name` override.\n * @returns One {@link AgentMiddleware} to pass into `ai.agent({ middleware: [...] })`.\n *\n * @example\n * const policy = ai.guardrail({\n * name: \"compliance\",\n * input: [ai.guardrail.injection({ onMatch: \"block\" })],\n * output: [ai.guardrail.pii({ onMatch: \"redact\", mask: \"[REDACTED:{label}]\" })],\n * tool: [ai.guardrail.pii({ onMatch: \"block\" })],\n * toolNames: [\"send_email\"],\n * escalation: { async onBlock(e) { await reviewQueue.enqueue(e); } },\n * });\n *\n * const agent = ai.agent({ model, tools: [sendEmail], middleware: [policy] });\n */\nexport function guard(options: GuardOptions): AgentMiddleware {\n const name = options.name ?? DEFAULT_NAME;\n const input = options.input ?? [];\n const output = options.output ?? [];\n const tool = options.tool ?? [];\n const escalation = options.escalation;\n\n const middleware: AgentMiddleware = {\n name,\n trip: {\n async before(ctx: MiddlewareTripContext): Promise<void> {\n if (input.length === 0) {\n return;\n }\n\n const prompt = extractUserText(ctx.messages);\n\n if (!prompt) {\n return;\n }\n\n const outcome = await runDetectors(input, prompt, \"input\", ctx, name);\n\n if (outcome.type === \"block\") {\n await block(outcome, \"input\", ctx, name, escalation);\n }\n\n // `allow` (incl. any recorded flags) and a downgraded-but-impossible\n // input `redact` (already mapped to block above) fall through — the\n // real model call proceeds with the un-mutated prompt.\n },\n async after(\n ctx: MiddlewareTripContext,\n response: ModelResponse,\n ): Promise<void | ModelResponse> {\n if (output.length === 0 || !response.content) {\n return;\n }\n\n const outcome = await runDetectors(\n output,\n response.content,\n \"output\",\n ctx,\n name,\n );\n\n if (outcome.type === \"block\") {\n await block(outcome, \"output\", ctx, name, escalation);\n }\n\n if (outcome.type === \"redact\") {\n // `trip.after` may return a replacement response — thread the\n // rewritten content back so the caller never sees the original.\n return { ...response, content: outcome.text };\n }\n\n return;\n },\n },\n };\n\n // Only declare the `tool` hook map when there are tool detectors — an empty\n // `tool` array would otherwise make `forTool` scoping a no-op cost.\n if (tool.length > 0) {\n middleware.tool = {\n async before(ctx: MiddlewareToolContext): Promise<void> {\n const args = JSON.stringify(ctx.request.input);\n\n if (!args) {\n return;\n }\n\n const outcome = await runDetectors(tool, args, \"tool\", ctx, name);\n\n if (outcome.type === \"block\") {\n await block(outcome, \"tool\", ctx, name, escalation);\n }\n\n // A tool `redact` is downgraded to `block` inside `runDetectors`, so\n // `redact` is unreachable here; `allow`/`flag` fall through and the\n // real tool dispatch proceeds.\n },\n };\n }\n\n // Scope the `tool` hooks to the named tools when requested — `forTool`\n // leaves `trip` hooks untouched, so input/output detectors still fire for\n // every trip regardless of which tool is being dispatched.\n if (options.toolNames !== undefined && middleware.tool) {\n return forTool(options.toolNames, middleware);\n }\n\n return middleware;\n}\n"],"mappings":";;;;;;;AAmBA,MAAM,eAAe;;;;;;;;AASrB,SAAS,SAAS,MAAsB;CACtC,OAAO,GAAG,KAAK;AACjB;;;;;AAuBA,SAAS,WACP,KACA,MACA,QACM;CACN,MAAM,MAAM,SAAS,IAAI;CACzB,MAAM,WAAW,IAAI,MAAM,IAAI,GAAG;CAClC,MAAM,QAAQ,MAAM,QAAQ,QAAQ,IAAK,WAA4B,CAAC;CAEtE,MAAM,KAAK,MAAM;CACjB,IAAI,MAAM,IAAI,KAAK,KAAK;AAC1B;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoDA,eAAe,aACb,WACA,MACA,OACA,KACA,MACuB;CACvB,KAAK,MAAM,YAAY,WAAW;EAChC,IAAI;EAEJ,IAAI;GACF,UAAU,MAAM,SAAS,MAAM,MAAM;IAAE;IAAO;GAAI,CAAC;EACrD,SAAS,OAAO;GAEd,WAAW,KAAK,MAAM;IACpB,UAAU,SAAS;IACnB;IACA,QAAQ,aAAa,SAAS,KAAK,WACjC,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;IAEvD,SAAS,CAAC;GACZ,CAAC;GAED;EACF;EAEA,IAAI,QAAQ,SAAS,SACnB;EAGF,IAAI,QAAQ,SAAS,QAAQ;GAC3B,WAAW,KAAK,MAAM;IACpB,UAAU,SAAS;IACnB;IACA,QAAQ,QAAQ;IAChB,SAAS,QAAQ;GACnB,CAAC;GAED;EACF;EAEA,IAAI,QAAQ,SAAS,UAAU;GAC7B,IAAI,UAAU,UACZ,OAAO;IAAE,MAAM;IAAU,MAAM,QAAQ;GAAK;GAU9C,OAAO;IACL,MAAM;IACN,QANA,UAAU,SACN,mCACA,QAAQ;IAKZ,SAAS,QAAQ;IACjB,UAAU;GACZ;EACF;EAGA,OAAO;GACL,MAAM;GACN,QAAQ,QAAQ;GAChB,SAAS,QAAQ;GACjB,UAAU,QAAQ,YAAY;EAChC;CACF;CAEA,OAAO,EAAE,MAAM,QAAQ;AACzB;;;;;;;;;;;AAYA,eAAe,MACb,SACA,OACA,KACA,MACA,YACgB;CAChB,IAAI,QAAQ,UACV,MAAM,YAAY,UAAU;EAC1B;EACA,QAAQ,QAAQ;EAChB,SAAS,QAAQ;EACjB;CACF,CAAC;CAGH,MAAM,IAAI,wBACR,cAAc,KAAK,aAAa,MAAM,KAAK,QAAQ,UACnD;EAES;EACP,QAAQ,QAAQ;EAChB,WAAW;CACb,CACF;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,SAAgB,MAAM,SAAwC;CAC5D,MAAM,OAAO,QAAQ,QAAQ;CAC7B,MAAM,QAAQ,QAAQ,SAAS,CAAC;CAChC,MAAM,SAAS,QAAQ,UAAU,CAAC;CAClC,MAAM,OAAO,QAAQ,QAAQ,CAAC;CAC9B,MAAM,aAAa,QAAQ;CAE3B,MAAM,aAA8B;EAClC;EACA,MAAM;GACJ,MAAM,OAAO,KAA2C;IACtD,IAAI,MAAM,WAAW,GACnB;IAGF,MAAM,SAAS,gBAAgB,IAAI,QAAQ;IAE3C,IAAI,CAAC,QACH;IAGF,MAAM,UAAU,MAAM,aAAa,OAAO,QAAQ,SAAS,KAAK,IAAI;IAEpE,IAAI,QAAQ,SAAS,SACnB,MAAM,MAAM,SAAS,SAAS,KAAK,MAAM,UAAU;GAMvD;GACA,MAAM,MACJ,KACA,UAC+B;IAC/B,IAAI,OAAO,WAAW,KAAK,CAAC,SAAS,SACnC;IAGF,MAAM,UAAU,MAAM,aACpB,QACA,SAAS,SACT,UACA,KACA,IACF;IAEA,IAAI,QAAQ,SAAS,SACnB,MAAM,MAAM,SAAS,UAAU,KAAK,MAAM,UAAU;IAGtD,IAAI,QAAQ,SAAS,UAGnB,OAAO;KAAE,GAAG;KAAU,SAAS,QAAQ;IAAK;GAIhD;EACF;CACF;CAIA,IAAI,KAAK,SAAS,GAChB,WAAW,OAAO,EAChB,MAAM,OAAO,KAA2C;EACtD,MAAM,OAAO,KAAK,UAAU,IAAI,QAAQ,KAAK;EAE7C,IAAI,CAAC,MACH;EAGF,MAAM,UAAU,MAAM,aAAa,MAAM,MAAM,QAAQ,KAAK,IAAI;EAEhE,IAAI,QAAQ,SAAS,SACnB,MAAM,MAAM,SAAS,QAAQ,KAAK,MAAM,UAAU;CAMtD,EACF;CAMF,IAAI,QAAQ,cAAc,UAAa,WAAW,MAChD,OAAO,QAAQ,QAAQ,WAAW,UAAU;CAG9C,OAAO;AACT"}
@@ -1,22 +0,0 @@
1
- import { injection } from "./detectors/injection.mjs";
2
- import { pii } from "./detectors/pii.mjs";
3
- import { topic } from "./detectors/topic.mjs";
4
- import { moderation } from "./detectors/moderation.mjs";
5
- import "./detectors/index.mjs";
6
- import { guard } from "./guard.mjs";
7
-
8
- //#region ../@warlock.js/ai/src/guard/guardrail.ts
9
- /**
10
- * The `ai.guardrail` value: the {@link guard} factory with the detector
11
- * factories assigned onto it. Built once and shared.
12
- */
13
- const guardrail = Object.assign(guard, {
14
- pii,
15
- topic,
16
- injection,
17
- moderation
18
- });
19
-
20
- //#endregion
21
- export { guardrail };
22
- //# sourceMappingURL=guardrail.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"guardrail.mjs","names":[],"sources":["../../../../../../../../../@warlock.js/ai/src/guard/guardrail.ts"],"sourcesContent":["import type { AgentMiddleware } from \"../contracts/middleware/middleware.contract\";\nimport type {\n GuardOptions,\n GuardrailDetector,\n InjectionDetectorOptions,\n OpenAiModerationOptions,\n PiiDetectorOptions,\n TopicFilterOptions,\n} from \"./contracts\";\nimport { injection, moderation, pii, topic } from \"./detectors\";\nimport { guard } from \"./guard\";\n\n/**\n * The callable `ai.guardrail` surface — the {@link guard} factory with the\n * built-in detector factories attached as methods, so the whole guardrail\n * vocabulary lives under one name:\n *\n * - `ai.guardrail(options)` — build the composed middleware.\n * - `ai.guardrail.pii(o?)` / `.topic(o)` / `.injection(o?)` / `.moderation(o?)`\n * — build a detector to pass into the factory's `input` / `output` / `tool`\n * arrays.\n *\n * @example\n * const policy = ai.guardrail({\n * output: [ai.guardrail.pii({ onMatch: \"redact\" })],\n * });\n */\nexport interface GuardrailFactory {\n /** Build the composed guardrail {@link AgentMiddleware}. */\n (options: GuardOptions): AgentMiddleware;\n /** Built-in PII detector (regex + dictionary, zero runtime dep). */\n pii(options?: PiiDetectorOptions): GuardrailDetector;\n /** Built-in topic filter (allow / deny string | RegExp lists). */\n topic(options: TopicFilterOptions): GuardrailDetector;\n /** Built-in jailbreak / prompt-injection marker detector. */\n injection(options?: InjectionDetectorOptions): GuardrailDetector;\n /** Optional OpenAI-backed moderation detector (lazy `openai` peer). */\n moderation(options?: OpenAiModerationOptions): GuardrailDetector;\n}\n\n/**\n * The `ai.guardrail` value: the {@link guard} factory with the detector\n * factories assigned onto it. Built once and shared.\n */\nexport const guardrail: GuardrailFactory = Object.assign(guard, {\n pii,\n topic,\n injection,\n moderation,\n});\n\n// `ai.guardrail` is registered natively on the core `ai` object (in `../ai`),\n// now that the guardrail suite ships inside `@warlock.js/ai`.\n"],"mappings":";;;;;;;;;;;;AA4CA,MAAa,YAA8B,OAAO,OAAO,OAAO;CAC9D;CACA;CACA;CACA;AACF,CAAC"}
@@ -1,60 +0,0 @@
1
- import { AIError } from "../errors/ai-error.mjs";
2
-
3
- //#region ../@warlock.js/ai/src/human/errors.ts
4
- /**
5
- * A durable approval handler suspended the run rather than denying the
6
- * call.
7
- *
8
- * **Role.** The sentinel a durable {@link import("./contracts").ApprovalHandler}
9
- * throws after persisting a
10
- * {@link import("./contracts").PendingInterrupt}. The approval
11
- * middleware recognizes its own sentinel (an `instanceof` check) and
12
- * re-throws so the agent run unwinds; the dispatch records it as a failed
13
- * tool call carrying this typed error. The caller reads
14
- * `error.interruptId` off the surfaced `result.error`, surfaces it to the
15
- * reviewer, and later calls `ai.human.resume(...)`.
16
- *
17
- * Surfaced via `result.error` like every other `AIError` — the middleware
18
- * never lets it escape `execute()`.
19
- *
20
- * @example
21
- * if (result.error instanceof InterruptSuspendedError) {
22
- * await notifyReviewer(result.error.interruptId);
23
- * return { status: "awaiting-approval", interruptId: result.error.interruptId };
24
- * }
25
- */
26
- var InterruptSuspendedError = class extends AIError {
27
- constructor(message, options) {
28
- super("INTERRUPT_SUSPENDED", message, options);
29
- this.name = "InterruptSuspendedError";
30
- this.interruptId = options.interruptId;
31
- }
32
- };
33
- /**
34
- * A human rejected a gated tool call.
35
- *
36
- * **Role.** The typed result of an `{ type: "reject", reason }` decision.
37
- * The approval middleware throws it from `tool.before`; the agent
38
- * dispatch records a failed tool call and writes a `role: "tool"`
39
- * message carrying `reason`, so the **next trip lets the model
40
- * self-correct** — exactly the existing tool-error feedback path.
41
- *
42
- * Surfaced via `result.error` like every other `AIError`.
43
- *
44
- * @example
45
- * if (result.error instanceof ApprovalRejectedError) {
46
- * logAudit(`${result.error.toolName} rejected: ${result.error.reason}`);
47
- * }
48
- */
49
- var ApprovalRejectedError = class extends AIError {
50
- constructor(message, options) {
51
- super("APPROVAL_REJECTED", message, options);
52
- this.name = "ApprovalRejectedError";
53
- this.reason = options.reason;
54
- this.toolName = options.toolName;
55
- }
56
- };
57
-
58
- //#endregion
59
- export { ApprovalRejectedError, InterruptSuspendedError };
60
- //# sourceMappingURL=errors.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"errors.mjs","names":[],"sources":["../../../../../../../../../@warlock.js/ai/src/human/errors.ts"],"sourcesContent":["import { AIError, type AIErrorOptions } from \"../errors/ai-error\";\nimport type { AIErrorCode } from \"../errors/error-code.type\";\n\n/**\n * Stable, machine-readable codes this package raises.\n *\n * `@warlock.js/ai`'s `AIErrorCode` is a closed union that (by design)\n * does not enumerate satellite-package codes, and this package must not\n * modify the core union. These codes are therefore declared locally and\n * narrowed into the base `AIError` `code` slot at the single `super(...)`\n * call — the runtime string is exactly what a consumer branches on via\n * `error.code`, identical to every other `AIError`.\n */\nexport type HumanErrorCode = \"INTERRUPT_SUSPENDED\" | \"APPROVAL_REJECTED\";\n\n/**\n * Payload for {@link InterruptSuspendedError}. `interruptId` is the key a\n * later `ai.human.resume(interruptId, decision)` call uses to replay the\n * decision against the persisted interrupt.\n */\nexport type InterruptSuspendedErrorOptions = AIErrorOptions & {\n /** Id of the persisted interrupt awaiting a decision. */\n interruptId: string;\n};\n\n/**\n * A durable approval handler suspended the run rather than denying the\n * call.\n *\n * **Role.** The sentinel a durable {@link import(\"./contracts\").ApprovalHandler}\n * throws after persisting a\n * {@link import(\"./contracts\").PendingInterrupt}. The approval\n * middleware recognizes its own sentinel (an `instanceof` check) and\n * re-throws so the agent run unwinds; the dispatch records it as a failed\n * tool call carrying this typed error. The caller reads\n * `error.interruptId` off the surfaced `result.error`, surfaces it to the\n * reviewer, and later calls `ai.human.resume(...)`.\n *\n * Surfaced via `result.error` like every other `AIError` — the middleware\n * never lets it escape `execute()`.\n *\n * @example\n * if (result.error instanceof InterruptSuspendedError) {\n * await notifyReviewer(result.error.interruptId);\n * return { status: \"awaiting-approval\", interruptId: result.error.interruptId };\n * }\n */\nexport class InterruptSuspendedError extends AIError {\n /** Id of the persisted interrupt awaiting a human decision. */\n public readonly interruptId: string;\n\n public constructor(message: string, options: InterruptSuspendedErrorOptions) {\n super(\"INTERRUPT_SUSPENDED\" as AIErrorCode, message, options);\n\n this.name = \"InterruptSuspendedError\";\n this.interruptId = options.interruptId;\n }\n}\n\n/**\n * Payload for {@link ApprovalRejectedError}. `reason` is the reviewer's\n * explanation, surfaced to the model on the next trip so it can\n * self-correct; `toolName` names the call that was rejected.\n */\nexport type ApprovalRejectedErrorOptions = AIErrorOptions & {\n /** The reviewer's explanation for rejecting the call. */\n reason: string;\n /** Name of the tool whose call was rejected. */\n toolName: string;\n};\n\n/**\n * A human rejected a gated tool call.\n *\n * **Role.** The typed result of an `{ type: \"reject\", reason }` decision.\n * The approval middleware throws it from `tool.before`; the agent\n * dispatch records a failed tool call and writes a `role: \"tool\"`\n * message carrying `reason`, so the **next trip lets the model\n * self-correct** — exactly the existing tool-error feedback path.\n *\n * Surfaced via `result.error` like every other `AIError`.\n *\n * @example\n * if (result.error instanceof ApprovalRejectedError) {\n * logAudit(`${result.error.toolName} rejected: ${result.error.reason}`);\n * }\n */\nexport class ApprovalRejectedError extends AIError {\n /** The reviewer's explanation for rejecting the call. */\n public readonly reason: string;\n\n /** Name of the tool whose call was rejected. */\n public readonly toolName: string;\n\n public constructor(message: string, options: ApprovalRejectedErrorOptions) {\n super(\"APPROVAL_REJECTED\" as AIErrorCode, message, options);\n\n this.name = \"ApprovalRejectedError\";\n this.reason = options.reason;\n this.toolName = options.toolName;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA+CA,IAAa,0BAAb,cAA6C,QAAQ;CAInD,AAAO,YAAY,SAAiB,SAAyC;EAC3E,MAAM,uBAAsC,SAAS,OAAO;EAE5D,KAAK,OAAO;EACZ,KAAK,cAAc,QAAQ;CAC7B;AACF;;;;;;;;;;;;;;;;;AA8BA,IAAa,wBAAb,cAA2C,QAAQ;CAOjD,AAAO,YAAY,SAAiB,SAAuC;EACzE,MAAM,qBAAoC,SAAS,OAAO;EAE1D,KAAK,OAAO;EACZ,KAAK,SAAS,QAAQ;EACtB,KAAK,WAAW,QAAQ;CAC1B;AACF"}
@@ -1,170 +0,0 @@
1
- import { generateRunId } from "../utils/generate-run-id.mjs";
2
- import { ApprovalRejectedError, InterruptSuspendedError } from "./errors.mjs";
3
- import { evaluatePolicy } from "./policy.mjs";
4
- import { takeSeededDecision } from "./resume-seed.mjs";
5
-
6
- //#region ../@warlock.js/ai/src/human/human-approval.ts
7
- /** Default middleware name when {@link HumanApprovalOptions.name} is omitted. */
8
- const DEFAULT_NAME = "human-approval";
9
- /** Zero usage for a synthetic, no-LLM-spend short-circuit result. */
10
- const ZERO_USAGE = Object.freeze({
11
- input: 0,
12
- output: 0,
13
- total: 0
14
- });
15
- /**
16
- * Derive the read-only {@link PolicyContext} the policy + request are
17
- * built from out of the wrapping {@link MiddlewareToolContext}.
18
- */
19
- function toPolicyContext(ctx) {
20
- return {
21
- toolName: ctx.tool.name,
22
- toolDescription: ctx.tool.description,
23
- args: ctx.request.input,
24
- agentName: ctx.agent.name,
25
- tripIndex: ctx.tripIndex,
26
- sessionId: ctx.options?.sessionId
27
- };
28
- }
29
- /**
30
- * Generate a stable, unique id for a pending interrupt. Shaped
31
- * `${agentName}.${sessionId ?? "nosession"}.${tripIndex}.${random}` so a
32
- * reviewer can eyeball the originating run, while the trailing random
33
- * segment guarantees per-call uniqueness even within one trip.
34
- */
35
- function makeInterruptId(ctx) {
36
- const session = ctx.options?.sessionId ?? "nosession";
37
- const random = generateRunId("interrupt");
38
- return `${ctx.agent.name}.${session}.${ctx.tripIndex}.${random}`;
39
- }
40
- /**
41
- * Build the {@link ApprovalRequest} a human rules on, from the tool
42
- * context and the policy-derived tags.
43
- */
44
- function buildRequest(ctx, interruptId, tags) {
45
- return {
46
- interruptId,
47
- toolName: ctx.tool.name,
48
- toolDescription: ctx.tool.description,
49
- args: ctx.request.input,
50
- context: {
51
- agentName: ctx.agent.name,
52
- tripIndex: ctx.tripIndex,
53
- sessionId: ctx.options?.sessionId,
54
- originalInput: ctx.input,
55
- ...tags ? { tags } : {}
56
- },
57
- requestedAt: (/* @__PURE__ */ new Date()).toISOString()
58
- };
59
- }
60
- /**
61
- * Synthesize a failed {@link ToolInvokeResult} carrying a typed error.
62
- *
63
- * The approval middleware returns this from `tool.before` to
64
- * **short-circuit** the real tool without throwing: the pipeline treats a
65
- * defined return as the tool's result, the agent records a failed
66
- * `ToolCall`, and the model sees `{ error }` on the next trip — exactly
67
- * the existing tool-error feedback path. Used for both `reject`
68
- * (`ApprovalRejectedError`) and durable suspend (`InterruptSuspendedError`).
69
- */
70
- function failedResult(error, toolName) {
71
- const runId = generateRunId("tool");
72
- const nowIso = (/* @__PURE__ */ new Date()).toISOString();
73
- return {
74
- error,
75
- usage: ZERO_USAGE,
76
- report: {
77
- runId,
78
- rootRunId: runId,
79
- name: toolName,
80
- type: "tool",
81
- status: "failed",
82
- startedAt: nowIso,
83
- endedAt: nowIso,
84
- duration: 0,
85
- usage: ZERO_USAGE,
86
- children: []
87
- }
88
- };
89
- }
90
- /**
91
- * Human-in-the-loop approval gate for an agent's tool calls — the
92
- * middleware behind `ai.human.approval(options)`.
93
- *
94
- * **Role.** Pauses *before a specific tool call* and routes it to a human
95
- * who can **approve** (run the real tool unchanged), **reject** (the model
96
- * sees a typed error and self-corrects), or **edit** (run the tool with
97
- * reviewer-replaced args). The dangerous subset is chosen by an
98
- * {@link import("./contracts").InterruptPolicy} (allowlist / denylist /
99
- * predicate); every other call passes through untouched.
100
- *
101
- * **One hook.** Declares only `tool.before`. On each tool dispatch it:
102
- * 1. evaluates the policy — not gated → returns `void`, the real tool runs;
103
- * 2. for a gated call, builds an {@link ApprovalRequest} and calls the
104
- * {@link import("./contracts").ApprovalHandler};
105
- * 3. applies the returned {@link ApprovalDecision}:
106
- * - `approve` → returns `void`, the real tool runs;
107
- * - `reject` → short-circuits a failed `ToolInvokeResult` carrying an
108
- * {@link ApprovalRejectedError} (the reviewer's `reason` reaches the
109
- * model);
110
- * - `edit` → rewrites `ctx.request.input` to the reviewer's args and
111
- * returns `void`, so the real tool runs with the edited args (schema
112
- * validation still applies — bad edits surface as a tool error).
113
- *
114
- * **Durable mode.** When a `store` is configured and the handler throws
115
- * {@link InterruptSuspendedError} (after persisting the interrupt
116
- * out-of-band), the middleware catches its **own** sentinel and
117
- * short-circuits a failed result carrying it — so the caller reads
118
- * `result.error.interruptId` and later calls
119
- * `ai.human.resume(interruptId, decision)`. The middleware **never throws
120
- * out of the pipeline**: every outcome (skip, approve, reject, edit,
121
- * suspend) returns normally; only a *handler bug* (a non-sentinel throw)
122
- * propagates, and even then the agent dispatch funnels it onto
123
- * `result.error` — `execute()` still never throws.
124
- *
125
- * @param options - Policy, handler, optional durable store, optional name.
126
- * @returns An {@link AgentMiddleware} declaring a single `tool.before` hook.
127
- *
128
- * @example
129
- * const support = ai.agent({
130
- * model,
131
- * tools: [refundCustomer],
132
- * middleware: [
133
- * humanApproval({
134
- * policy: { type: "allowlist", tools: ["refundCustomer"], tags: () => ["money"] },
135
- * handler: async (req) => ui.prompt(req), // { type: "edit", args: { amount: 5 } }
136
- * }),
137
- * ],
138
- * });
139
- */
140
- function humanApproval(options) {
141
- const name = options.name ?? DEFAULT_NAME;
142
- const { policy, handler } = options;
143
- return {
144
- name,
145
- tool: { async before(ctx) {
146
- const verdict = evaluatePolicy(policy, toPolicyContext(ctx));
147
- if (!verdict.requiresApproval) return;
148
- const request = buildRequest(ctx, makeInterruptId(ctx), verdict.tags);
149
- const seeded = takeSeededDecision(ctx.agent.name);
150
- let decision;
151
- if (seeded !== void 0) decision = seeded;
152
- else try {
153
- decision = await handler(request);
154
- } catch (thrown) {
155
- if (thrown instanceof InterruptSuspendedError) return failedResult(thrown, ctx.tool.name);
156
- throw thrown;
157
- }
158
- if (decision.type === "approve") return;
159
- if (decision.type === "reject") return failedResult(new ApprovalRejectedError(`Tool call "${ctx.tool.name}" rejected by reviewer — ${decision.reason}`, {
160
- reason: decision.reason,
161
- toolName: ctx.tool.name
162
- }), ctx.tool.name);
163
- ctx.request.input = decision.args;
164
- } }
165
- };
166
- }
167
-
168
- //#endregion
169
- export { humanApproval };
170
- //# sourceMappingURL=human-approval.mjs.map