@warlock.js/ai 4.3.0 → 4.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (541) hide show
  1. package/CHANGELOG.md +52 -48
  2. package/cjs/index.cjs +221 -14144
  3. package/cjs/src-C02yzsLs.cjs +22991 -0
  4. package/cjs/src-C02yzsLs.cjs.map +1 -0
  5. package/cjs/src-DFibP2FQ.cjs +30 -0
  6. package/esm/agent/agent-config.type.d.mts +90 -1
  7. package/esm/agent/agent-config.type.d.mts.map +1 -1
  8. package/esm/agent/agent-input-builder.mjs +27 -6
  9. package/esm/agent/agent-input-builder.mjs.map +1 -1
  10. package/esm/agent/agent.d.mts +40 -1
  11. package/esm/agent/agent.d.mts.map +1 -1
  12. package/esm/agent/agent.mjs +203 -30
  13. package/esm/agent/agent.mjs.map +1 -1
  14. package/esm/agent/index.d.mts +2 -1
  15. package/esm/agent/index.mjs +1 -0
  16. package/esm/agent/judge-config.type.d.mts +33 -0
  17. package/esm/agent/judge-config.type.d.mts.map +1 -0
  18. package/esm/agent/judge-config.type.mjs +13 -0
  19. package/esm/agent/judge-config.type.mjs.map +1 -0
  20. package/esm/ai-openai/src/embedder.mjs +4 -0
  21. package/esm/ai-openai/src/index.mjs +4 -0
  22. package/esm/ai-openai/src/model.mjs +5 -0
  23. package/esm/ai-openai/src/sdk.mjs +6 -0
  24. package/esm/ai-openai/src/utils/index.mjs +4 -0
  25. package/esm/ai-openai/src/utils/to-openai-tools.mjs +3 -0
  26. package/esm/ai-openai/src/utils/wrap-openai-error.mjs +4 -0
  27. package/esm/ai.d.mts +119 -53
  28. package/esm/ai.d.mts.map +1 -1
  29. package/esm/ai.mjs +43 -8
  30. package/esm/ai.mjs.map +1 -1
  31. package/esm/batch/batch.d.mts.map +1 -1
  32. package/esm/batch/batch.mjs +21 -1
  33. package/esm/batch/batch.mjs.map +1 -1
  34. package/esm/batch/batch.type.d.mts +11 -4
  35. package/esm/batch/batch.type.d.mts.map +1 -1
  36. package/esm/config.d.mts +39 -3
  37. package/esm/config.d.mts.map +1 -1
  38. package/esm/config.mjs +26 -2
  39. package/esm/config.mjs.map +1 -1
  40. package/esm/contracts/agent/agent-options.type.d.mts +11 -3
  41. package/esm/contracts/agent/agent-options.type.d.mts.map +1 -1
  42. package/esm/contracts/agent/eval.type.d.mts +43 -2
  43. package/esm/contracts/agent/eval.type.d.mts.map +1 -1
  44. package/esm/contracts/attachment-policy.type.d.mts +51 -0
  45. package/esm/contracts/attachment-policy.type.d.mts.map +1 -0
  46. package/esm/contracts/attachment.type.d.mts +16 -7
  47. package/esm/contracts/attachment.type.d.mts.map +1 -1
  48. package/esm/contracts/content-part.type.d.mts +14 -5
  49. package/esm/contracts/content-part.type.d.mts.map +1 -1
  50. package/esm/contracts/events/supervisor-events.type.d.mts.map +1 -1
  51. package/esm/contracts/index.d.mts +6 -4
  52. package/esm/contracts/model.contract.d.mts +11 -8
  53. package/esm/contracts/model.contract.d.mts.map +1 -1
  54. package/esm/contracts/orchestrator/index.d.mts +1 -0
  55. package/esm/contracts/orchestrator/orchestrator-config.type.d.mts +31 -2
  56. package/esm/contracts/orchestrator/orchestrator-config.type.d.mts.map +1 -1
  57. package/esm/contracts/orchestrator/session-lock.contract.d.mts +47 -0
  58. package/esm/contracts/orchestrator/session-lock.contract.d.mts.map +1 -0
  59. package/esm/contracts/planner/index.d.mts +1 -1
  60. package/esm/contracts/planner/planner-config.type.d.mts +31 -0
  61. package/esm/contracts/planner/planner-config.type.d.mts.map +1 -1
  62. package/esm/contracts/planner/planner-execute-options.type.d.mts +48 -1
  63. package/esm/contracts/planner/planner-execute-options.type.d.mts.map +1 -1
  64. package/esm/contracts/planner/planner-result.type.d.mts +19 -5
  65. package/esm/contracts/planner/planner-result.type.d.mts.map +1 -1
  66. package/esm/contracts/planner/planner.contract.d.mts +1 -1
  67. package/esm/contracts/result/agent-result.type.d.mts +6 -4
  68. package/esm/contracts/result/agent-result.type.d.mts.map +1 -1
  69. package/esm/contracts/result/base-report.type.d.mts +21 -3
  70. package/esm/contracts/result/base-report.type.d.mts.map +1 -1
  71. package/esm/contracts/result/base-report.type.mjs.map +1 -1
  72. package/esm/contracts/result/execution-report.type.d.mts +53 -1
  73. package/esm/contracts/result/execution-report.type.d.mts.map +1 -1
  74. package/esm/contracts/result/orchestrator-result.type.d.mts +15 -11
  75. package/esm/contracts/result/orchestrator-result.type.d.mts.map +1 -1
  76. package/esm/contracts/result/supervisor-result.type.d.mts +13 -1
  77. package/esm/contracts/result/supervisor-result.type.d.mts.map +1 -1
  78. package/esm/contracts/result/tool-call.type.d.mts +2 -2
  79. package/esm/contracts/result/tool-call.type.d.mts.map +1 -1
  80. package/esm/contracts/result/workflow-result.type.d.mts +1 -0
  81. package/esm/contracts/result/workflow-result.type.d.mts.map +1 -1
  82. package/esm/contracts/supervisor/supervisor-config.type.d.mts +29 -0
  83. package/esm/contracts/supervisor/supervisor-config.type.d.mts.map +1 -1
  84. package/esm/contracts/system-prompt.contract.d.mts +103 -1
  85. package/esm/contracts/system-prompt.contract.d.mts.map +1 -1
  86. package/esm/contracts/team/index.d.mts +1 -0
  87. package/esm/contracts/team/team-config.type.d.mts +127 -0
  88. package/esm/contracts/team/team-config.type.d.mts.map +1 -0
  89. package/esm/contracts/tool.contract.d.mts +4 -2
  90. package/esm/contracts/tool.contract.d.mts.map +1 -1
  91. package/esm/contracts/workflow/step.contract.d.mts +30 -5
  92. package/esm/contracts/workflow/step.contract.d.mts.map +1 -1
  93. package/esm/contracts/workflow/workflow.contract.d.mts +16 -0
  94. package/esm/contracts/workflow/workflow.contract.d.mts.map +1 -1
  95. package/esm/errors/error-code.type.d.mts +1 -1
  96. package/esm/errors/index.d.mts +1 -0
  97. package/esm/errors/index.mjs +1 -0
  98. package/esm/errors/outbound-policy-error.d.mts +27 -0
  99. package/esm/errors/outbound-policy-error.d.mts.map +1 -0
  100. package/esm/errors/outbound-policy-error.mjs +32 -0
  101. package/esm/errors/outbound-policy-error.mjs.map +1 -0
  102. package/esm/eval/dataset.d.mts +28 -0
  103. package/esm/eval/dataset.d.mts.map +1 -0
  104. package/esm/eval/dataset.mjs +112 -0
  105. package/esm/eval/dataset.mjs.map +1 -0
  106. package/esm/eval/dataset.type.d.mts +53 -0
  107. package/esm/eval/dataset.type.d.mts.map +1 -0
  108. package/esm/eval/eval-runner.d.mts.map +1 -1
  109. package/esm/eval/eval-runner.mjs +16 -2
  110. package/esm/eval/eval-runner.mjs.map +1 -1
  111. package/esm/eval/index.d.mts +20 -1
  112. package/esm/eval/index.d.mts.map +1 -1
  113. package/esm/eval/index.mjs +20 -2
  114. package/esm/eval/index.mjs.map +1 -1
  115. package/esm/eval/regression.d.mts +30 -0
  116. package/esm/eval/regression.d.mts.map +1 -0
  117. package/esm/eval/regression.mjs +51 -0
  118. package/esm/eval/regression.mjs.map +1 -0
  119. package/esm/eval/report-json.d.mts +30 -0
  120. package/esm/eval/report-json.d.mts.map +1 -0
  121. package/esm/eval/report-json.mjs +33 -0
  122. package/esm/eval/report-json.mjs.map +1 -0
  123. package/esm/eval/report-junit.d.mts +22 -0
  124. package/esm/eval/report-junit.d.mts.map +1 -0
  125. package/esm/eval/report-junit.mjs +60 -0
  126. package/esm/eval/report-junit.mjs.map +1 -0
  127. package/esm/guard/contracts/guard-options.type.d.mts +165 -0
  128. package/esm/guard/contracts/guard-options.type.d.mts.map +1 -0
  129. package/esm/guard/contracts/guardrail.contract.d.mts +78 -0
  130. package/esm/guard/contracts/guardrail.contract.d.mts.map +1 -0
  131. package/esm/guard/contracts/index.d.mts +4 -0
  132. package/esm/guard/contracts/openai-client.contract.d.mts +51 -0
  133. package/esm/guard/contracts/openai-client.contract.d.mts.map +1 -0
  134. package/esm/guard/contracts/verdict.type.d.mts +76 -0
  135. package/esm/guard/contracts/verdict.type.d.mts.map +1 -0
  136. package/esm/guard/detectors/index.d.mts +4 -0
  137. package/esm/guard/detectors/index.mjs +6 -0
  138. package/esm/guard/detectors/injection.d.mts +34 -0
  139. package/esm/guard/detectors/injection.d.mts.map +1 -0
  140. package/esm/guard/detectors/injection.mjs +254 -0
  141. package/esm/guard/detectors/injection.mjs.map +1 -0
  142. package/esm/guard/detectors/moderation.d.mts +32 -0
  143. package/esm/guard/detectors/moderation.d.mts.map +1 -0
  144. package/esm/guard/detectors/moderation.mjs +134 -0
  145. package/esm/guard/detectors/moderation.mjs.map +1 -0
  146. package/esm/guard/detectors/pii.d.mts +41 -0
  147. package/esm/guard/detectors/pii.d.mts.map +1 -0
  148. package/esm/guard/detectors/pii.mjs +199 -0
  149. package/esm/guard/detectors/pii.mjs.map +1 -0
  150. package/esm/guard/detectors/topic.d.mts +29 -0
  151. package/esm/guard/detectors/topic.d.mts.map +1 -0
  152. package/esm/guard/detectors/topic.mjs +99 -0
  153. package/esm/guard/detectors/topic.mjs.map +1 -0
  154. package/esm/guard/errors.d.mts +12 -0
  155. package/esm/guard/errors.d.mts.map +1 -0
  156. package/esm/guard/errors.mjs +18 -0
  157. package/esm/guard/errors.mjs.map +1 -0
  158. package/esm/guard/guard.d.mts +67 -0
  159. package/esm/guard/guard.d.mts.map +1 -0
  160. package/esm/guard/guard.mjs +209 -0
  161. package/esm/guard/guard.mjs.map +1 -0
  162. package/esm/guard/guardrail.d.mts +39 -0
  163. package/esm/guard/guardrail.d.mts.map +1 -0
  164. package/esm/guard/guardrail.mjs +22 -0
  165. package/esm/guard/guardrail.mjs.map +1 -0
  166. package/esm/human/contracts/approval.type.d.mts +154 -0
  167. package/esm/human/contracts/approval.type.d.mts.map +1 -0
  168. package/esm/human/contracts/human-approval.type.d.mts +38 -0
  169. package/esm/human/contracts/human-approval.type.d.mts.map +1 -0
  170. package/esm/human/contracts/index.d.mts +4 -0
  171. package/esm/human/contracts/interrupt-store.contract.d.mts +112 -0
  172. package/esm/human/contracts/interrupt-store.contract.d.mts.map +1 -0
  173. package/esm/human/contracts/resume.type.d.mts +77 -0
  174. package/esm/human/contracts/resume.type.d.mts.map +1 -0
  175. package/esm/human/errors.d.mts +84 -0
  176. package/esm/human/errors.d.mts.map +1 -0
  177. package/esm/human/errors.mjs +60 -0
  178. package/esm/human/errors.mjs.map +1 -0
  179. package/esm/human/human-approval.d.mts +57 -0
  180. package/esm/human/human-approval.d.mts.map +1 -0
  181. package/esm/human/human-approval.mjs +170 -0
  182. package/esm/human/human-approval.mjs.map +1 -0
  183. package/esm/human/policy.d.mts +55 -0
  184. package/esm/human/policy.d.mts.map +1 -0
  185. package/esm/human/policy.mjs +67 -0
  186. package/esm/human/policy.mjs.map +1 -0
  187. package/esm/human/register.mjs +37 -0
  188. package/esm/human/register.mjs.map +1 -0
  189. package/esm/human/resume-seed.mjs +53 -0
  190. package/esm/human/resume-seed.mjs.map +1 -0
  191. package/esm/human/resume.d.mts +54 -0
  192. package/esm/human/resume.d.mts.map +1 -0
  193. package/esm/human/resume.mjs +121 -0
  194. package/esm/human/resume.mjs.map +1 -0
  195. package/esm/human/stores/index.mjs +5 -0
  196. package/esm/human/stores/memory.d.mts +30 -0
  197. package/esm/human/stores/memory.d.mts.map +1 -0
  198. package/esm/human/stores/memory.mjs +91 -0
  199. package/esm/human/stores/memory.mjs.map +1 -0
  200. package/esm/human/stores/pg.d.mts +59 -0
  201. package/esm/human/stores/pg.d.mts.map +1 -0
  202. package/esm/human/stores/pg.mjs +220 -0
  203. package/esm/human/stores/pg.mjs.map +1 -0
  204. package/esm/human/stores/redis.d.mts +56 -0
  205. package/esm/human/stores/redis.d.mts.map +1 -0
  206. package/esm/human/stores/redis.mjs +201 -0
  207. package/esm/human/stores/redis.mjs.map +1 -0
  208. package/esm/index.d.mts +113 -22
  209. package/esm/index.mjs +82 -11
  210. package/esm/middleware/builtins/budget.mjs +6 -2
  211. package/esm/middleware/builtins/budget.mjs.map +1 -1
  212. package/esm/middleware/utils/extract-user-text.d.mts +8 -1
  213. package/esm/middleware/utils/extract-user-text.d.mts.map +1 -1
  214. package/esm/middleware/utils/extract-user-text.mjs +8 -1
  215. package/esm/middleware/utils/extract-user-text.mjs.map +1 -1
  216. package/esm/object-stream/index.d.mts +2 -0
  217. package/esm/object-stream/index.mjs +4 -0
  218. package/esm/object-stream/parse-partial-json.d.mts +22 -0
  219. package/esm/object-stream/parse-partial-json.d.mts.map +1 -0
  220. package/esm/object-stream/parse-partial-json.mjs +78 -0
  221. package/esm/object-stream/parse-partial-json.mjs.map +1 -0
  222. package/esm/object-stream/stream-object.d.mts +68 -0
  223. package/esm/object-stream/stream-object.d.mts.map +1 -0
  224. package/esm/object-stream/stream-object.mjs +104 -0
  225. package/esm/object-stream/stream-object.mjs.map +1 -0
  226. package/esm/observe/index.mjs +4 -0
  227. package/esm/observe/observer-registry.d.mts +30 -0
  228. package/esm/observe/observer-registry.d.mts.map +1 -0
  229. package/esm/observe/observer-registry.mjs +51 -0
  230. package/esm/observe/observer-registry.mjs.map +1 -0
  231. package/esm/observe/observer.contract.d.mts +40 -0
  232. package/esm/observe/observer.contract.d.mts.map +1 -0
  233. package/esm/observe/resolve-observers.d.mts +40 -0
  234. package/esm/observe/resolve-observers.d.mts.map +1 -0
  235. package/esm/observe/resolve-observers.mjs +73 -0
  236. package/esm/observe/resolve-observers.mjs.map +1 -0
  237. package/esm/orchestrator/execution.d.mts.map +1 -1
  238. package/esm/orchestrator/execution.mjs +5 -2
  239. package/esm/orchestrator/execution.mjs.map +1 -1
  240. package/esm/orchestrator/index.d.mts +1 -0
  241. package/esm/orchestrator/index.mjs +1 -0
  242. package/esm/orchestrator/orchestrator.d.mts.map +1 -1
  243. package/esm/orchestrator/orchestrator.mjs +39 -6
  244. package/esm/orchestrator/orchestrator.mjs.map +1 -1
  245. package/esm/orchestrator/session-lock.d.mts +25 -0
  246. package/esm/orchestrator/session-lock.d.mts.map +1 -0
  247. package/esm/orchestrator/session-lock.mjs +83 -0
  248. package/esm/orchestrator/session-lock.mjs.map +1 -0
  249. package/esm/planner/dag-scheduler.mjs +97 -0
  250. package/esm/planner/dag-scheduler.mjs.map +1 -0
  251. package/esm/planner/plan-prompt.d.mts +1 -1
  252. package/esm/planner/plan-prompt.d.mts.map +1 -1
  253. package/esm/planner/plan-prompt.mjs +2 -1
  254. package/esm/planner/plan-prompt.mjs.map +1 -1
  255. package/esm/planner/plan-schema.mjs +17 -14
  256. package/esm/planner/plan-schema.mjs.map +1 -1
  257. package/esm/planner/planner-run.d.mts.map +1 -1
  258. package/esm/planner/planner-run.mjs +300 -29
  259. package/esm/planner/planner-run.mjs.map +1 -1
  260. package/esm/planner/planner.mjs +1 -1
  261. package/esm/planner/planner.mjs.map +1 -1
  262. package/esm/prompt/errors.d.mts +57 -0
  263. package/esm/prompt/errors.d.mts.map +1 -0
  264. package/esm/prompt/errors.mjs +73 -0
  265. package/esm/prompt/errors.mjs.map +1 -0
  266. package/esm/prompt/index.d.mts +3 -0
  267. package/esm/prompt/index.mjs +4 -0
  268. package/esm/prompt/prompt-langfuse-sync.mjs +104 -0
  269. package/esm/prompt/prompt-langfuse-sync.mjs.map +1 -0
  270. package/esm/prompt/prompt-langfuse-sync.type.d.mts +32 -0
  271. package/esm/prompt/prompt-langfuse-sync.type.d.mts.map +1 -0
  272. package/esm/prompt/prompt-validate.mjs +170 -0
  273. package/esm/prompt/prompt-validate.mjs.map +1 -0
  274. package/esm/prompt/prompt.d.mts +54 -0
  275. package/esm/prompt/prompt.d.mts.map +1 -0
  276. package/esm/prompt/prompt.mjs +218 -0
  277. package/esm/prompt/prompt.mjs.map +1 -0
  278. package/esm/prompt/prompt.type.d.mts +174 -0
  279. package/esm/prompt/prompt.type.d.mts.map +1 -0
  280. package/esm/prompts/index.d.mts +3 -0
  281. package/esm/prompts/index.mjs +3 -0
  282. package/esm/prompts/prompts-manager.contract.d.mts +154 -0
  283. package/esm/prompts/prompts-manager.contract.d.mts.map +1 -0
  284. package/esm/prompts/prompts-manager.d.mts +38 -0
  285. package/esm/prompts/prompts-manager.d.mts.map +1 -0
  286. package/esm/prompts/prompts-manager.mjs +410 -0
  287. package/esm/prompts/prompts-manager.mjs.map +1 -0
  288. package/esm/prompts/prompts-manager.type.d.mts +172 -0
  289. package/esm/prompts/prompts-manager.type.d.mts.map +1 -0
  290. package/esm/prompts/prompts-validate.mjs +200 -0
  291. package/esm/prompts/prompts-validate.mjs.map +1 -0
  292. package/esm/rag/as-tool.mjs +48 -0
  293. package/esm/rag/as-tool.mjs.map +1 -0
  294. package/esm/rag/chunk/chunk.d.mts +24 -0
  295. package/esm/rag/chunk/chunk.d.mts.map +1 -0
  296. package/esm/rag/chunk/chunk.mjs +44 -0
  297. package/esm/rag/chunk/chunk.mjs.map +1 -0
  298. package/esm/rag/chunk/fixed.mjs +32 -0
  299. package/esm/rag/chunk/fixed.mjs.map +1 -0
  300. package/esm/rag/chunk/markdown.mjs +75 -0
  301. package/esm/rag/chunk/markdown.mjs.map +1 -0
  302. package/esm/rag/chunk/recursive.mjs +132 -0
  303. package/esm/rag/chunk/recursive.mjs.map +1 -0
  304. package/esm/rag/chunk/sentence.mjs +73 -0
  305. package/esm/rag/chunk/sentence.mjs.map +1 -0
  306. package/esm/rag/contracts/chunk-options.type.d.mts +35 -0
  307. package/esm/rag/contracts/chunk-options.type.d.mts.map +1 -0
  308. package/esm/rag/contracts/citation.type.d.mts +35 -0
  309. package/esm/rag/contracts/citation.type.d.mts.map +1 -0
  310. package/esm/rag/contracts/index.d.mts +4 -0
  311. package/esm/rag/contracts/rag-config.type.d.mts +68 -0
  312. package/esm/rag/contracts/rag-config.type.d.mts.map +1 -0
  313. package/esm/rag/contracts/rag-document.type.d.mts +21 -0
  314. package/esm/rag/contracts/rag-document.type.d.mts.map +1 -0
  315. package/esm/rag/hybrid/bm25.d.mts +23 -0
  316. package/esm/rag/hybrid/bm25.d.mts.map +1 -0
  317. package/esm/rag/hybrid/bm25.mjs +51 -0
  318. package/esm/rag/hybrid/bm25.mjs.map +1 -0
  319. package/esm/rag/hybrid/hybrid-rank.d.mts +33 -0
  320. package/esm/rag/hybrid/hybrid-rank.d.mts.map +1 -0
  321. package/esm/rag/hybrid/hybrid-rank.mjs +29 -0
  322. package/esm/rag/hybrid/hybrid-rank.mjs.map +1 -0
  323. package/esm/rag/hybrid/rrf.d.mts +25 -0
  324. package/esm/rag/hybrid/rrf.d.mts.map +1 -0
  325. package/esm/rag/hybrid/rrf.mjs +30 -0
  326. package/esm/rag/hybrid/rrf.mjs.map +1 -0
  327. package/esm/rag/index.d.mts +15 -0
  328. package/esm/rag/index.mjs +11 -0
  329. package/esm/rag/rag.d.mts +38 -0
  330. package/esm/rag/rag.d.mts.map +1 -0
  331. package/esm/rag/rag.mjs +126 -0
  332. package/esm/rag/rag.mjs.map +1 -0
  333. package/esm/rag/rerank/keyword-reranker.d.mts +32 -0
  334. package/esm/rag/rerank/keyword-reranker.d.mts.map +1 -0
  335. package/esm/rag/rerank/keyword-reranker.mjs +58 -0
  336. package/esm/rag/rerank/keyword-reranker.mjs.map +1 -0
  337. package/esm/rag/rerank/llm-reranker.d.mts +36 -0
  338. package/esm/rag/rerank/llm-reranker.d.mts.map +1 -0
  339. package/esm/rag/rerank/llm-reranker.mjs +85 -0
  340. package/esm/rag/rerank/llm-reranker.mjs.map +1 -0
  341. package/esm/rag/rerank/reranker.contract.d.mts +28 -0
  342. package/esm/rag/rerank/reranker.contract.d.mts.map +1 -0
  343. package/esm/rag/retrieve.mjs +68 -0
  344. package/esm/rag/retrieve.mjs.map +1 -0
  345. package/esm/rag/store/cache-vector-store.d.mts +27 -0
  346. package/esm/rag/store/cache-vector-store.d.mts.map +1 -0
  347. package/esm/rag/store/cache-vector-store.mjs +48 -0
  348. package/esm/rag/store/cache-vector-store.mjs.map +1 -0
  349. package/esm/rag/store/vector-store.contract.d.mts +38 -0
  350. package/esm/rag/store/vector-store.contract.d.mts.map +1 -0
  351. package/esm/rag/transforms/multi-query.d.mts +27 -0
  352. package/esm/rag/transforms/multi-query.d.mts.map +1 -0
  353. package/esm/rag/transforms/multi-query.mjs +41 -0
  354. package/esm/rag/transforms/multi-query.mjs.map +1 -0
  355. package/esm/security/index.mjs +5 -0
  356. package/esm/security/outbound-policy.d.mts +46 -0
  357. package/esm/security/outbound-policy.d.mts.map +1 -0
  358. package/esm/security/outbound-policy.mjs +187 -0
  359. package/esm/security/outbound-policy.mjs.map +1 -0
  360. package/esm/security/outbound-policy.type.d.mts +74 -0
  361. package/esm/security/outbound-policy.type.d.mts.map +1 -0
  362. package/esm/security/private-ip.d.mts +15 -0
  363. package/esm/security/private-ip.d.mts.map +1 -0
  364. package/esm/security/private-ip.mjs +48 -0
  365. package/esm/security/private-ip.mjs.map +1 -0
  366. package/esm/security/redact.d.mts +59 -0
  367. package/esm/security/redact.d.mts.map +1 -0
  368. package/esm/security/redact.mjs +122 -0
  369. package/esm/security/redact.mjs.map +1 -0
  370. package/esm/serve/serve.d.mts +50 -0
  371. package/esm/serve/serve.d.mts.map +1 -0
  372. package/esm/serve/serve.mjs +90 -0
  373. package/esm/serve/serve.mjs.map +1 -0
  374. package/esm/serve/sse.d.mts +20 -0
  375. package/esm/serve/sse.d.mts.map +1 -0
  376. package/esm/serve/sse.mjs +25 -0
  377. package/esm/serve/sse.mjs.map +1 -0
  378. package/esm/serve/stream-to-sse.d.mts +29 -0
  379. package/esm/serve/stream-to-sse.d.mts.map +1 -0
  380. package/esm/serve/stream-to-sse.mjs +37 -0
  381. package/esm/serve/stream-to-sse.mjs.map +1 -0
  382. package/esm/skills/catalog.d.mts +49 -0
  383. package/esm/skills/catalog.d.mts.map +1 -0
  384. package/esm/skills/catalog.mjs +140 -0
  385. package/esm/skills/catalog.mjs.map +1 -0
  386. package/esm/skills/contracts/skill-record.type.d.mts +37 -0
  387. package/esm/skills/contracts/skill-record.type.d.mts.map +1 -0
  388. package/esm/skills/contracts/skills-config.type.d.mts +108 -0
  389. package/esm/skills/contracts/skills-config.type.d.mts.map +1 -0
  390. package/esm/skills/contracts/skills-store.contract.d.mts +28 -0
  391. package/esm/skills/contracts/skills-store.contract.d.mts.map +1 -0
  392. package/esm/skills/contracts/skills.contract.d.mts +43 -0
  393. package/esm/skills/contracts/skills.contract.d.mts.map +1 -0
  394. package/esm/skills/index.d.mts +16 -0
  395. package/esm/skills/index.mjs +14 -0
  396. package/esm/skills/load-skill-tool.d.mts +38 -0
  397. package/esm/skills/load-skill-tool.d.mts.map +1 -0
  398. package/esm/skills/load-skill-tool.mjs +65 -0
  399. package/esm/skills/load-skill-tool.mjs.map +1 -0
  400. package/esm/skills/review-gate.d.mts +33 -0
  401. package/esm/skills/review-gate.d.mts.map +1 -0
  402. package/esm/skills/review-gate.mjs +60 -0
  403. package/esm/skills/review-gate.mjs.map +1 -0
  404. package/esm/skills/save-skill-tool.d.mts +39 -0
  405. package/esm/skills/save-skill-tool.d.mts.map +1 -0
  406. package/esm/skills/save-skill-tool.mjs +65 -0
  407. package/esm/skills/save-skill-tool.mjs.map +1 -0
  408. package/esm/skills/skills.d.mts +33 -0
  409. package/esm/skills/skills.d.mts.map +1 -0
  410. package/esm/skills/skills.mjs +109 -0
  411. package/esm/skills/skills.mjs.map +1 -0
  412. package/esm/skills/sources/directory-source.d.mts +19 -0
  413. package/esm/skills/sources/directory-source.d.mts.map +1 -0
  414. package/esm/skills/sources/directory-source.mjs +108 -0
  415. package/esm/skills/sources/directory-source.mjs.map +1 -0
  416. package/esm/skills/sources/index.d.mts +18 -0
  417. package/esm/skills/sources/index.d.mts.map +1 -0
  418. package/esm/skills/sources/index.mjs +27 -0
  419. package/esm/skills/sources/index.mjs.map +1 -0
  420. package/esm/skills/sources/parse-frontmatter.d.mts +27 -0
  421. package/esm/skills/sources/parse-frontmatter.d.mts.map +1 -0
  422. package/esm/skills/sources/parse-frontmatter.mjs +46 -0
  423. package/esm/skills/sources/parse-frontmatter.mjs.map +1 -0
  424. package/esm/skills/sources/store-source.d.mts +14 -0
  425. package/esm/skills/sources/store-source.d.mts.map +1 -0
  426. package/esm/skills/sources/store-source.mjs +15 -0
  427. package/esm/skills/sources/store-source.mjs.map +1 -0
  428. package/esm/skills/sources/url-source.d.mts +29 -0
  429. package/esm/skills/sources/url-source.d.mts.map +1 -0
  430. package/esm/skills/sources/url-source.mjs +117 -0
  431. package/esm/skills/sources/url-source.mjs.map +1 -0
  432. package/esm/skills/store/mock-skills-store.d.mts +57 -0
  433. package/esm/skills/store/mock-skills-store.d.mts.map +1 -0
  434. package/esm/skills/store/mock-skills-store.mjs +100 -0
  435. package/esm/skills/store/mock-skills-store.mjs.map +1 -0
  436. package/esm/skills/store/procedural-skill-store.d.mts +30 -0
  437. package/esm/skills/store/procedural-skill-store.d.mts.map +1 -0
  438. package/esm/skills/store/procedural-skill-store.mjs +125 -0
  439. package/esm/skills/store/procedural-skill-store.mjs.map +1 -0
  440. package/esm/supervisor/as-tool.mjs +2 -2
  441. package/esm/supervisor/as-tool.mjs.map +1 -1
  442. package/esm/supervisor/execution.d.mts.map +1 -1
  443. package/esm/supervisor/execution.mjs +31 -28
  444. package/esm/supervisor/execution.mjs.map +1 -1
  445. package/esm/supervisor/supervisor.d.mts.map +1 -1
  446. package/esm/supervisor/supervisor.mjs +8 -3
  447. package/esm/supervisor/supervisor.mjs.map +1 -1
  448. package/esm/system-prompt/index.d.mts +4 -0
  449. package/esm/system-prompt/system-prompt.d.mts +68 -4
  450. package/esm/system-prompt/system-prompt.d.mts.map +1 -1
  451. package/esm/system-prompt/system-prompt.mjs +89 -5
  452. package/esm/system-prompt/system-prompt.mjs.map +1 -1
  453. package/esm/team/gates.mjs +48 -0
  454. package/esm/team/gates.mjs.map +1 -0
  455. package/esm/team/index.d.mts +1 -0
  456. package/esm/team/index.mjs +3 -0
  457. package/esm/team/team.d.mts +42 -0
  458. package/esm/team/team.d.mts.map +1 -0
  459. package/esm/team/team.mjs +94 -0
  460. package/esm/team/team.mjs.map +1 -0
  461. package/esm/tool/executable-as-tool.d.mts.map +1 -1
  462. package/esm/tool/executable-as-tool.mjs +2 -2
  463. package/esm/tool/executable-as-tool.mjs.map +1 -1
  464. package/esm/tool/tool.d.mts.map +1 -1
  465. package/esm/tool/tool.mjs +2 -2
  466. package/esm/tool/tool.mjs.map +1 -1
  467. package/esm/utils/compute-cost.d.mts +17 -1
  468. package/esm/utils/compute-cost.d.mts.map +1 -1
  469. package/esm/utils/compute-cost.mjs +26 -1
  470. package/esm/utils/compute-cost.mjs.map +1 -1
  471. package/esm/utils/extract-json-lenient.d.mts +42 -0
  472. package/esm/utils/extract-json-lenient.d.mts.map +1 -0
  473. package/esm/utils/extract-json-lenient.mjs +97 -0
  474. package/esm/utils/extract-json-lenient.mjs.map +1 -0
  475. package/esm/utils/index.d.mts +4 -2
  476. package/esm/utils/index.mjs +3 -1
  477. package/esm/utils/json-schema.d.mts +1 -1
  478. package/esm/utils/prepare-attachment-part.d.mts +10 -1
  479. package/esm/utils/prepare-attachment-part.d.mts.map +1 -1
  480. package/esm/utils/prepare-attachment-part.mjs +103 -11
  481. package/esm/utils/prepare-attachment-part.mjs.map +1 -1
  482. package/esm/utils/resolve-attachment.d.mts +4 -3
  483. package/esm/utils/resolve-attachment.d.mts.map +1 -1
  484. package/esm/utils/resolve-attachment.mjs +4 -3
  485. package/esm/utils/resolve-attachment.mjs.map +1 -1
  486. package/esm/utils/run-context.d.mts +94 -0
  487. package/esm/utils/run-context.d.mts.map +1 -0
  488. package/esm/utils/run-context.mjs +98 -0
  489. package/esm/utils/run-context.mjs.map +1 -0
  490. package/esm/vcr/cassette-io.mjs +57 -0
  491. package/esm/vcr/cassette-io.mjs.map +1 -0
  492. package/esm/vcr/errors.d.mts +42 -0
  493. package/esm/vcr/errors.d.mts.map +1 -0
  494. package/esm/vcr/errors.mjs +37 -0
  495. package/esm/vcr/errors.mjs.map +1 -0
  496. package/esm/vcr/hash-request.d.mts +28 -0
  497. package/esm/vcr/hash-request.d.mts.map +1 -0
  498. package/esm/vcr/hash-request.mjs +118 -0
  499. package/esm/vcr/hash-request.mjs.map +1 -0
  500. package/esm/vcr/index.d.mts +4 -0
  501. package/esm/vcr/index.mjs +5 -0
  502. package/esm/vcr/vcr.d.mts +32 -0
  503. package/esm/vcr/vcr.d.mts.map +1 -0
  504. package/esm/vcr/vcr.mjs +248 -0
  505. package/esm/vcr/vcr.mjs.map +1 -0
  506. package/esm/vcr/vcr.type.d.mts +118 -0
  507. package/esm/vcr/vcr.type.d.mts.map +1 -0
  508. package/esm/workflow/as-tool.mjs +2 -2
  509. package/esm/workflow/as-tool.mjs.map +1 -1
  510. package/esm/workflow/engine.mjs +1 -0
  511. package/esm/workflow/engine.mjs.map +1 -1
  512. package/esm/workflow/step-runner.mjs +19 -20
  513. package/esm/workflow/step-runner.mjs.map +1 -1
  514. package/esm/workflow/workflow.d.mts.map +1 -1
  515. package/esm/workflow/workflow.mjs +8 -3
  516. package/esm/workflow/workflow.mjs.map +1 -1
  517. package/llms-full.txt +1683 -68
  518. package/llms.txt +16 -4
  519. package/package.json +7 -3
  520. package/skills/README.md +40 -4
  521. package/skills/ai-dx-helpers/SKILL.md +2 -2
  522. package/skills/approve-tool-calls/SKILL.md +134 -0
  523. package/skills/attach-ai-middleware/SKILL.md +1 -1
  524. package/skills/detect-and-redact-pii/SKILL.md +104 -0
  525. package/skills/durable-resume/SKILL.md +128 -0
  526. package/skills/escalate-block-to-human/SKILL.md +85 -0
  527. package/skills/eval-datasets-and-ci/SKILL.md +117 -0
  528. package/skills/guard-input-output/SKILL.md +117 -0
  529. package/skills/manage-prompts/SKILL.md +186 -0
  530. package/skills/observe-ai-flows/SKILL.md +94 -0
  531. package/skills/record-replay-llm/SKILL.md +92 -0
  532. package/skills/run-ai-agent/SKILL.md +26 -1
  533. package/skills/run-ai-rag/SKILL.md +139 -0
  534. package/skills/run-ai-team/SKILL.md +107 -0
  535. package/skills/run-orchestrator/SKILL.md +2 -0
  536. package/skills/run-planner/SKILL.md +73 -8
  537. package/skills/run-supervisor/SKILL.md +20 -1
  538. package/skills/use-runtime-skills/SKILL.md +106 -0
  539. package/skills/write-system-prompt/SKILL.md +30 -1
  540. package/cjs/index.cjs.map +0 -1
  541. package/esm/contracts/result/index.d.mts +0 -15
@@ -0,0 +1,218 @@
1
+ import { agent } from "../agent/agent.mjs";
2
+ import { renderPlaceholders } from "../system-prompt/render-placeholders.mjs";
3
+ import { Instruction } from "../system-prompt/instruction.mjs";
4
+ import { SystemPrompt } from "../system-prompt/system-prompt.mjs";
5
+ import { buildValidationReport, judgePrompt, staticLint } from "./prompt-validate.mjs";
6
+ import { defaultPromptsManager, prompts } from "../prompts/prompts-manager.mjs";
7
+ import { PromptNotFoundError, PromptValidationError } from "./errors.mjs";
8
+ import { syncLangfusePrompts, warmLangfuse } from "./prompt-langfuse-sync.mjs";
9
+
10
+ //#region ../@warlock.js/ai/src/prompt/prompt.ts
11
+ /**
12
+ * Build the one-shot judge agent the `validate()` LLM-as-judge pass runs.
13
+ * Name-bearing (the eval `judge` scorer requires a usable agent) and seeded
14
+ * with a strict-JSON instruction so its verdict parses even without an output
15
+ * schema. Kept module-private so the registry's only model dependency is the
16
+ * `agent()` factory.
17
+ */
18
+ function buildJudgeAgent(model) {
19
+ return agent({
20
+ name: "prompt-quality-judge",
21
+ model,
22
+ systemPrompt: "You are a strict prompt-quality grader. Respond with JSON only: { \"score\": <0..1>, \"passed\": <true|false>, \"reason\": \"<short explanation>\" }."
23
+ });
24
+ }
25
+ /**
26
+ * Build the `SystemPromptContract` a single {@link PromptVersion} maps to: its
27
+ * `template` becomes one instruction block, and its `required` keys ride along
28
+ * as `meta.required` so the unified manager (and `validate`) can see them.
29
+ *
30
+ * Deliberately ANONYMOUS (no `meta.name`) so the `SystemPrompt` constructor
31
+ * never auto-registers this version into the process-wide `ai.prompts` default
32
+ * manager — each `prompt()` registry owns its OWN isolated
33
+ * {@link PromptsManagerContract}, the single storage shape behind this facade.
34
+ */
35
+ function versionToContract(version) {
36
+ return new SystemPrompt([new Instruction(version.template)], { ...version.required ? { required: version.required } : {} });
37
+ }
38
+ /**
39
+ * Legacy `PromptRegistryContract` — now a THIN FACADE over the unified
40
+ * {@link PromptsManagerContract} (`ai.prompts`).
41
+ *
42
+ * **Role.** The store behind `ai.prompt(...)`. Historically it held a private
43
+ * `Map<string, PromptVersion[]>`; it now delegates ALL storage to a private,
44
+ * per-instance {@link PromptsManagerContract}, so there is exactly ONE storage
45
+ * shape across the whole prompt surface: a `SystemPromptContract` keyed by
46
+ * `name@version`. A version's raw `template` string maps to a single
47
+ * instruction block and its `required` keys to `meta.required`.
48
+ *
49
+ * **Responsibility.**
50
+ * - Owns: the legacy method surface (`register` / `add` / `versions` /
51
+ * `resolve` / `validate` / `sync`) and the back-compat behaviors — duplicate
52
+ * version rejection, required-key assertion on `resolve()`, the
53
+ * `{ score, notes }` validation report shape, and the optional Langfuse sync.
54
+ * - Does NOT own: the actual storage (delegated to the internal manager),
55
+ * placeholder rendering (delegated to `renderPlaceholders`), or the unified
56
+ * validation primitives (delegated to `prompt-validate`).
57
+ *
58
+ * Each `prompt(options)` call builds its own isolated manager — so parallel
59
+ * test suites and multi-tenant apps never share mutable global prompt state,
60
+ * exactly as before the unification.
61
+ *
62
+ * Users construct via the `prompt()` factory — `new PromptRegistry()` is not
63
+ * the public API.
64
+ */
65
+ var PromptRegistry = class {
66
+ constructor(options = {}) {
67
+ this.options = options;
68
+ this.versionMeta = /* @__PURE__ */ new Map();
69
+ this.manager = prompts();
70
+ for (const entry of options.prompts ?? []) this.register(entry);
71
+ if (options.langfuse) warmLangfuse(options.langfuse);
72
+ }
73
+ /**
74
+ * Register a whole entry. Merges onto an existing name's history; a
75
+ * duplicate version label throws {@link PromptValidationError}.
76
+ */
77
+ register(entry) {
78
+ for (const version of entry.versions) this.add(entry.name, version);
79
+ if (!this.versionMeta.has(entry.name)) this.versionMeta.set(entry.name, []);
80
+ return this;
81
+ }
82
+ /**
83
+ * Add a new version to a name (creating it when absent). A duplicate
84
+ * version label throws {@link PromptValidationError} — never a silent
85
+ * overwrite.
86
+ */
87
+ add(name, version) {
88
+ const mirror = this.versionMeta.get(name) ?? [];
89
+ if (mirror.some((existing) => existing.version === version.version)) throw new PromptValidationError(`Prompt "${name}" already has a version labeled "${version.version}".`, { context: {
90
+ name,
91
+ version: version.version
92
+ } });
93
+ this.manager.register(versionToContract(version), {
94
+ name,
95
+ version: version.version
96
+ });
97
+ this.versionMeta.set(name, [...mirror, version]);
98
+ return this;
99
+ }
100
+ /** Whether a name is registered. */
101
+ has(name) {
102
+ return this.versionMeta.has(name);
103
+ }
104
+ /** Every registered prompt name, in registration order. */
105
+ list() {
106
+ return [...this.versionMeta.keys()];
107
+ }
108
+ /** Versions registered for a name, latest last. Throws on an unknown name. */
109
+ versions(name) {
110
+ const mirror = this.versionMeta.get(name);
111
+ if (!mirror) throw new PromptNotFoundError(name);
112
+ return [...mirror];
113
+ }
114
+ /**
115
+ * Resolve + render. Picks the requested or latest version, validates the
116
+ * version's `required` keys against the merged placeholders, then renders by
117
+ * delegating to the shared `renderPlaceholders` over the contract's text.
118
+ */
119
+ resolve(name, options = {}) {
120
+ const picked = this.pickVersion(name, options.version);
121
+ const placeholders = options.placeholders ?? {};
122
+ this.assertRequired(name, picked, placeholders);
123
+ const text = renderPlaceholders(this.manager.get(name, picked.version).blocks[0]?.text ?? picked.template, placeholders);
124
+ return {
125
+ name,
126
+ version: picked.version,
127
+ text,
128
+ toSystemPrompt: () => new SystemPrompt([new Instruction(text)])
129
+ };
130
+ }
131
+ /**
132
+ * Quality-check a raw prompt body or a registered prompt (by name). Backed by
133
+ * the unified deterministic validate primitives plus the LLM-as-judge pass,
134
+ * but returns the legacy `{ score, notes }` report shape so existing callers
135
+ * keep working.
136
+ *
137
+ * Always runs the static lint; runs the LLM-as-judge pass too when a model is
138
+ * resolvable. Never throws when no judge model is available.
139
+ */
140
+ async validate(textOrName, options = {}) {
141
+ const text = this.resolveValidationText(textOrName, options.version);
142
+ const staticNotes = staticLint(text);
143
+ const model = options.model ?? this.options.judgeModel;
144
+ if (!model) return buildValidationReport(staticNotes);
145
+ return buildValidationReport(staticNotes, await judgePrompt(text, model, buildJudgeAgent));
146
+ }
147
+ /**
148
+ * Synchronize named prompts with Langfuse-prompts. No-op (resolves) when no
149
+ * `langfuse` option was configured. The resolved (rendered) body + the
150
+ * `name@version` label are what is pushed/pulled.
151
+ */
152
+ async sync() {
153
+ if (!this.options.langfuse) return;
154
+ await syncLangfusePrompts(this.options.langfuse, this.list(), this.snapshotEntries(), (entry) => this.register(entry));
155
+ }
156
+ /**
157
+ * Pick the requested (or latest) {@link PromptVersion} for a name from the
158
+ * mirror, throwing {@link PromptNotFoundError} on an unknown name or version.
159
+ */
160
+ pickVersion(name, version) {
161
+ const mirror = this.versionMeta.get(name);
162
+ if (!mirror || mirror.length === 0) throw new PromptNotFoundError(name);
163
+ const picked = version ? mirror.find((candidate) => candidate.version === version) : mirror[mirror.length - 1];
164
+ if (!picked) throw new PromptNotFoundError(name, { context: {
165
+ name,
166
+ version
167
+ } });
168
+ return picked;
169
+ }
170
+ /**
171
+ * Resolve the text `validate()` should grade: a registered name yields its
172
+ * picked version's raw `template`; anything else is treated as the raw body.
173
+ */
174
+ resolveValidationText(textOrName, version) {
175
+ const mirror = this.versionMeta.get(textOrName);
176
+ if (!mirror || mirror.length === 0) return textOrName;
177
+ const picked = version ? mirror.find((candidate) => candidate.version === version) : mirror[mirror.length - 1];
178
+ return picked ? picked.template : textOrName;
179
+ }
180
+ /**
181
+ * Throw {@link PromptValidationError} listing every `required` key absent
182
+ * from the merged placeholders. A no-op when the version declares none.
183
+ */
184
+ assertRequired(name, version, placeholders) {
185
+ if (!version.required || version.required.length === 0) return;
186
+ const missing = version.required.filter((key) => placeholders[key] === void 0 || placeholders[key] === null || placeholders[key] === "");
187
+ if (missing.length > 0) throw new PromptValidationError(`Prompt "${name}" version "${version.version}" is missing required placeholder${missing.length > 1 ? "s" : ""}: ${missing.join(", ")}.`, { context: {
188
+ name,
189
+ version: version.version,
190
+ missing
191
+ } });
192
+ }
193
+ /** Snapshot the catalog as `PromptEntry[]` (for the Langfuse push path). */
194
+ snapshotEntries() {
195
+ return [...this.versionMeta.entries()].map(([name, versions]) => ({
196
+ name,
197
+ versions: [...versions]
198
+ }));
199
+ }
200
+ };
201
+ function promptFactory(first, versionOrTag) {
202
+ if (typeof first === "string") return defaultPromptsManager().get(first, versionOrTag);
203
+ return new PromptRegistry(first);
204
+ }
205
+ /**
206
+ * Create a versioned prompt registry, OR resolve a globally-registered prompt
207
+ * by name from `ai.prompts`.
208
+ *
209
+ * - `prompt(options?)` → a fresh, isolated {@link PromptRegistryContract}.
210
+ * - `prompt(name, versionOrTag?)` → the `SystemPromptContract` registered under
211
+ * `name` in the process-wide `ai.prompts` manager (latest version by default,
212
+ * or a specific version / pinned tag).
213
+ */
214
+ const prompt = promptFactory;
215
+
216
+ //#endregion
217
+ export { prompt };
218
+ //# sourceMappingURL=prompt.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt.mjs","names":["createPromptsManager"],"sources":["../../../../../../../@warlock.js/ai/src/prompt/prompt.ts"],"sourcesContent":["import type { SystemPromptContract } from \"../contracts/system-prompt.contract\";\nimport {\n defaultPromptsManager,\n prompts as createPromptsManager,\n} from \"../prompts/prompts-manager\";\nimport type { PromptsManagerContract } from \"../prompts/prompts-manager.contract\";\nimport { Instruction } from \"../system-prompt/instruction\";\nimport { renderPlaceholders } from \"../system-prompt/render-placeholders\";\nimport { SystemPrompt } from \"../system-prompt/system-prompt\";\nimport { PromptNotFoundError, PromptValidationError } from \"./errors\";\nimport {\n syncLangfusePrompts,\n warmLangfuse,\n} from \"./prompt-langfuse-sync\";\nimport {\n buildValidationReport,\n judgePrompt,\n staticLint,\n} from \"./prompt-validate\";\nimport { agent } from \"../agent/agent\";\nimport type { AgentContract } from \"../contracts/agent/agent.contract\";\nimport type { ModelContract } from \"../contracts/model.contract\";\nimport type {\n PromptEntry,\n PromptRegistryContract,\n PromptRegistryOptions,\n PromptResolveOptions,\n PromptValidateOptions,\n PromptValidationReport,\n PromptVersion,\n ResolvedPrompt,\n} from \"./prompt.type\";\n\n/**\n * Build the one-shot judge agent the `validate()` LLM-as-judge pass runs.\n * Name-bearing (the eval `judge` scorer requires a usable agent) and seeded\n * with a strict-JSON instruction so its verdict parses even without an output\n * schema. Kept module-private so the registry's only model dependency is the\n * `agent()` factory.\n */\nfunction buildJudgeAgent(model: ModelContract): AgentContract<unknown> {\n return agent({\n name: \"prompt-quality-judge\",\n model,\n systemPrompt:\n \"You are a strict prompt-quality grader. Respond with JSON only: \" +\n '{ \"score\": <0..1>, \"passed\": <true|false>, \"reason\": \"<short explanation>\" }.',\n });\n}\n\n/**\n * Build the `SystemPromptContract` a single {@link PromptVersion} maps to: its\n * `template` becomes one instruction block, and its `required` keys ride along\n * as `meta.required` so the unified manager (and `validate`) can see them.\n *\n * Deliberately ANONYMOUS (no `meta.name`) so the `SystemPrompt` constructor\n * never auto-registers this version into the process-wide `ai.prompts` default\n * manager — each `prompt()` registry owns its OWN isolated\n * {@link PromptsManagerContract}, the single storage shape behind this facade.\n */\nfunction versionToContract(version: PromptVersion): SystemPromptContract {\n return new SystemPrompt([new Instruction(version.template)], {\n ...(version.required ? { required: version.required } : {}),\n });\n}\n\n/**\n * Legacy `PromptRegistryContract` — now a THIN FACADE over the unified\n * {@link PromptsManagerContract} (`ai.prompts`).\n *\n * **Role.** The store behind `ai.prompt(...)`. Historically it held a private\n * `Map<string, PromptVersion[]>`; it now delegates ALL storage to a private,\n * per-instance {@link PromptsManagerContract}, so there is exactly ONE storage\n * shape across the whole prompt surface: a `SystemPromptContract` keyed by\n * `name@version`. A version's raw `template` string maps to a single\n * instruction block and its `required` keys to `meta.required`.\n *\n * **Responsibility.**\n * - Owns: the legacy method surface (`register` / `add` / `versions` /\n * `resolve` / `validate` / `sync`) and the back-compat behaviors — duplicate\n * version rejection, required-key assertion on `resolve()`, the\n * `{ score, notes }` validation report shape, and the optional Langfuse sync.\n * - Does NOT own: the actual storage (delegated to the internal manager),\n * placeholder rendering (delegated to `renderPlaceholders`), or the unified\n * validation primitives (delegated to `prompt-validate`).\n *\n * Each `prompt(options)` call builds its own isolated manager — so parallel\n * test suites and multi-tenant apps never share mutable global prompt state,\n * exactly as before the unification.\n *\n * Users construct via the `prompt()` factory — `new PromptRegistry()` is not\n * the public API.\n */\nclass PromptRegistry implements PromptRegistryContract {\n /** The single backing store — one isolated unified manager per registry. */\n private readonly manager: PromptsManagerContract;\n\n /** Per-name version metadata mirror, kept so `versions()` returns the rich\n * {@link PromptVersion} shape (template + required + meta) the legacy API\n * promised — the manager itself only stores the flattened contract. */\n private readonly versionMeta = new Map<string, PromptVersion[]>();\n\n public constructor(private readonly options: PromptRegistryOptions = {}) {\n this.manager = createPromptsManager();\n\n for (const entry of options.prompts ?? []) {\n this.register(entry);\n }\n\n if (options.langfuse) {\n warmLangfuse(options.langfuse);\n }\n }\n\n /**\n * Register a whole entry. Merges onto an existing name's history; a\n * duplicate version label throws {@link PromptValidationError}.\n */\n public register(entry: PromptEntry): PromptRegistryContract {\n for (const version of entry.versions) {\n this.add(entry.name, version);\n }\n\n // An entry with an empty version list still creates the name so `has`\n // / `list` reflect it.\n if (!this.versionMeta.has(entry.name)) {\n this.versionMeta.set(entry.name, []);\n }\n\n return this;\n }\n\n /**\n * Add a new version to a name (creating it when absent). A duplicate\n * version label throws {@link PromptValidationError} — never a silent\n * overwrite.\n */\n public add(name: string, version: PromptVersion): PromptRegistryContract {\n const mirror = this.versionMeta.get(name) ?? [];\n\n if (mirror.some(existing => existing.version === version.version)) {\n throw new PromptValidationError(\n `Prompt \"${name}\" already has a version labeled \"${version.version}\".`,\n { context: { name, version: version.version } },\n );\n }\n\n this.manager.register(versionToContract(version), {\n name,\n version: version.version,\n });\n\n this.versionMeta.set(name, [...mirror, version]);\n\n return this;\n }\n\n /** Whether a name is registered. */\n public has(name: string): boolean {\n return this.versionMeta.has(name);\n }\n\n /** Every registered prompt name, in registration order. */\n public list(): string[] {\n return [...this.versionMeta.keys()];\n }\n\n /** Versions registered for a name, latest last. Throws on an unknown name. */\n public versions(name: string): PromptVersion[] {\n const mirror = this.versionMeta.get(name);\n\n if (!mirror) {\n throw new PromptNotFoundError(name);\n }\n\n return [...mirror];\n }\n\n /**\n * Resolve + render. Picks the requested or latest version, validates the\n * version's `required` keys against the merged placeholders, then renders by\n * delegating to the shared `renderPlaceholders` over the contract's text.\n */\n public resolve(name: string, options: PromptResolveOptions = {}): ResolvedPrompt {\n const picked = this.pickVersion(name, options.version);\n const placeholders = options.placeholders ?? {};\n\n this.assertRequired(name, picked, placeholders);\n\n // Render the RAW template (placeholders intact) against the merged values —\n // resolving the contract first would bake inline `{{key|default}}` defaults\n // in and shadow an explicitly-supplied value. The stored block text is the\n // single source of the un-rendered template.\n const contract = this.manager.get(name, picked.version);\n const template = contract.blocks[0]?.text ?? picked.template;\n const text = renderPlaceholders(template, placeholders);\n\n return {\n name,\n version: picked.version,\n text,\n toSystemPrompt: () => new SystemPrompt([new Instruction(text)]),\n };\n }\n\n /**\n * Quality-check a raw prompt body or a registered prompt (by name). Backed by\n * the unified deterministic validate primitives plus the LLM-as-judge pass,\n * but returns the legacy `{ score, notes }` report shape so existing callers\n * keep working.\n *\n * Always runs the static lint; runs the LLM-as-judge pass too when a model is\n * resolvable. Never throws when no judge model is available.\n */\n public async validate(\n textOrName: string,\n options: PromptValidateOptions = {},\n ): Promise<PromptValidationReport> {\n const text = this.resolveValidationText(textOrName, options.version);\n const staticNotes = staticLint(text);\n\n const model = options.model ?? this.options.judgeModel;\n\n if (!model) {\n return buildValidationReport(staticNotes);\n }\n\n const judgeResult = await judgePrompt(text, model, buildJudgeAgent);\n\n return buildValidationReport(staticNotes, judgeResult);\n }\n\n /**\n * Synchronize named prompts with Langfuse-prompts. No-op (resolves) when no\n * `langfuse` option was configured. The resolved (rendered) body + the\n * `name@version` label are what is pushed/pulled.\n */\n public async sync(): Promise<void> {\n if (!this.options.langfuse) {\n return;\n }\n\n await syncLangfusePrompts(\n this.options.langfuse,\n this.list(),\n this.snapshotEntries(),\n entry => this.register(entry),\n );\n }\n\n /**\n * Pick the requested (or latest) {@link PromptVersion} for a name from the\n * mirror, throwing {@link PromptNotFoundError} on an unknown name or version.\n */\n private pickVersion(name: string, version?: string): PromptVersion {\n const mirror = this.versionMeta.get(name);\n\n if (!mirror || mirror.length === 0) {\n throw new PromptNotFoundError(name);\n }\n\n const picked = version\n ? mirror.find(candidate => candidate.version === version)\n : mirror[mirror.length - 1];\n\n if (!picked) {\n throw new PromptNotFoundError(name, {\n context: { name, version },\n });\n }\n\n return picked;\n }\n\n /**\n * Resolve the text `validate()` should grade: a registered name yields its\n * picked version's raw `template`; anything else is treated as the raw body.\n */\n private resolveValidationText(textOrName: string, version?: string): string {\n const mirror = this.versionMeta.get(textOrName);\n\n if (!mirror || mirror.length === 0) {\n return textOrName;\n }\n\n const picked = version\n ? mirror.find(candidate => candidate.version === version)\n : mirror[mirror.length - 1];\n\n return picked ? picked.template : textOrName;\n }\n\n /**\n * Throw {@link PromptValidationError} listing every `required` key absent\n * from the merged placeholders. A no-op when the version declares none.\n */\n private assertRequired(\n name: string,\n version: PromptVersion,\n placeholders: Record<string, unknown>,\n ): void {\n if (!version.required || version.required.length === 0) {\n return;\n }\n\n const missing = version.required.filter(\n key => placeholders[key] === undefined || placeholders[key] === null || placeholders[key] === \"\",\n );\n\n if (missing.length > 0) {\n throw new PromptValidationError(\n `Prompt \"${name}\" version \"${version.version}\" is missing required placeholder${\n missing.length > 1 ? \"s\" : \"\"\n }: ${missing.join(\", \")}.`,\n { context: { name, version: version.version, missing } },\n );\n }\n }\n\n /** Snapshot the catalog as `PromptEntry[]` (for the Langfuse push path). */\n private snapshotEntries(): PromptEntry[] {\n return [...this.versionMeta.entries()].map(([name, versions]) => ({\n name,\n versions: [...versions],\n }));\n }\n}\n\n/**\n * Create a versioned, typed prompt registry — a thin facade over the unified\n * `ai.prompts` manager.\n *\n * **Role.** Public factory for {@link PromptRegistryContract}. Keeps\n * user-facing code free of `new` and consistent with `ai.memory`,\n * `ai.orchestrator`, `ai.batch` (all return instances). Each call returns a\n * fresh, isolated registry backed by its own unified manager, so parallel test\n * suites and multi-tenant apps never share mutable global prompt state.\n *\n * @param options - Seed entries, an optional default judge model, and an\n * optional Langfuse sync.\n *\n * @example\n * const prompts = prompt({\n * prompts: [\n * {\n * name: \"support-agent\",\n * versions: [\n * { version: \"1\", template: \"You are support for {{product}}. Reply in {{language|English}}.\" },\n * { version: \"2\", template: \"You are senior support for {{product}}.\", required: [\"product\"] },\n * ],\n * },\n * ],\n * });\n *\n * const resolved = prompts.resolve(\"support-agent\", { placeholders: { product: \"Warlock\" } });\n * const agent = ai.agent({ model, systemPrompt: resolved.toSystemPrompt() });\n * // resolved.version === \"2\"; a missing `product` would throw PromptValidationError.\n *\n * @example\n * // Resolve a globally-registered prompt by name from `ai.prompts`.\n * ai.systemPrompt(\"You are support.\", { name: \"support\" });\n * const sp = ai.prompt(\"support\"); // → the registered SystemPromptContract\n */\nfunction promptFactory(\n name: string,\n versionOrTag?: string,\n): SystemPromptContract;\nfunction promptFactory(options?: PromptRegistryOptions): PromptRegistryContract;\nfunction promptFactory(\n first?: string | PromptRegistryOptions,\n versionOrTag?: string,\n): SystemPromptContract | PromptRegistryContract {\n // String form: resolve a globally-registered prompt from the process-wide\n // `ai.prompts` manager (the single unified registry). This is the thin\n // facade's read path onto the shared store.\n if (typeof first === \"string\") {\n return defaultPromptsManager().get(first, versionOrTag);\n }\n\n // Options form: build an isolated registry backed by its own unified manager.\n return new PromptRegistry(first);\n}\n\n/**\n * Create a versioned prompt registry, OR resolve a globally-registered prompt\n * by name from `ai.prompts`.\n *\n * - `prompt(options?)` → a fresh, isolated {@link PromptRegistryContract}.\n * - `prompt(name, versionOrTag?)` → the `SystemPromptContract` registered under\n * `name` in the process-wide `ai.prompts` manager (latest version by default,\n * or a specific version / pinned tag).\n */\nexport const prompt: typeof promptFactory = promptFactory;\n"],"mappings":";;;;;;;;;;;;;;;;;AAwCA,SAAS,gBAAgB,OAA8C;CACrE,OAAO,MAAM;EACX,MAAM;EACN;EACA,cACE;CAEJ,CAAC;AACH;;;;;;;;;;;AAYA,SAAS,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import { Placeholders } from "../contracts/placeholders.type.mjs";
3
+ import { SystemPrompt } from "../system-prompt/system-prompt.mjs";
4
+ import { LangfuseClientLike } from "./prompt-langfuse-sync.type.mjs";
5
+
6
+ //#region ../@warlock.js/ai/src/prompt/prompt.type.d.ts
7
+ /**
8
+ * One immutable version of a named prompt.
9
+ *
10
+ * **Role.** A single addressable snapshot of a prompt body, tagged with a
11
+ * free-form `version` label and (optionally) the placeholder keys it
12
+ * requires. Many versions accumulate under one {@link PromptEntry} so a
13
+ * registered prompt can evolve while older versions stay resolvable.
14
+ *
15
+ * The `template` uses the exact same `{{placeholder}}` syntax the shared
16
+ * `renderPlaceholders` helper supports — `{{key}}`, `{{a.b.c}}`,
17
+ * `{{key|default}}` — so a version's body renders identically to a
18
+ * `systemPrompt(string)` seed.
19
+ */
20
+ type PromptVersion = {
21
+ /** Monotonic version label, e.g. `"1"`, `"2"`, `"2025-06-draft"`. Free-form string. */version: string; /** The prompt body — same `{{placeholder}}` syntax `renderPlaceholders` supports. */
22
+ template: string;
23
+ /**
24
+ * Placeholder keys this version requires. When set, `.resolve()` throws a
25
+ * {@link PromptValidationError} if any are missing from the merged
26
+ * placeholders — closing the silent-passthrough gap `renderPlaceholders`
27
+ * leaves for an unsupplied `{{key}}`. Absent = no required-key validation.
28
+ */
29
+ required?: string[]; /** Optional free-form metadata (author note, model hint, etc.). */
30
+ meta?: Record<string, unknown>;
31
+ };
32
+ /**
33
+ * A named prompt and its ordered version history.
34
+ *
35
+ * **Role.** The unit `register()` ingests and `versions()` returns. The
36
+ * `versions` array is ordered oldest-first; the **last** entry is the
37
+ * default resolved when no explicit `version` is requested.
38
+ */
39
+ type PromptEntry = {
40
+ /** Unique name used for lookup, e.g. `"support-agent"`. */name: string; /** Ordered version history; the last entry is the default. */
41
+ versions: PromptVersion[];
42
+ };
43
+ /**
44
+ * Options for {@link PromptRegistryContract.resolve}.
45
+ */
46
+ type PromptResolveOptions = {
47
+ /** Pick a specific version by its label. Default: the latest registered version. */version?: string; /** Values for the template's `{{placeholders}}`. */
48
+ placeholders?: Placeholders;
49
+ };
50
+ /**
51
+ * Outcome of {@link PromptRegistryContract.resolve} — the picked version, its
52
+ * rendered text, and a one-call bridge to a `SystemPrompt`.
53
+ */
54
+ type ResolvedPrompt = {
55
+ /** The prompt name that was resolved. */name: string; /** The version label that was picked. */
56
+ version: string; /** The rendered string (placeholders substituted). */
57
+ text: string;
58
+ /**
59
+ * A `SystemPrompt` seeded with the rendered text — the exact same seed
60
+ * `systemPrompt(string)` produces (`new SystemPrompt([new Instruction(text)])`),
61
+ * so it is a drop-in for `ai.agent({ systemPrompt })`.
62
+ */
63
+ toSystemPrompt(): SystemPrompt;
64
+ };
65
+ /** Severity of a single {@link PromptValidationReport} finding. */
66
+ type PromptValidationSeverity = "info" | "warn" | "error";
67
+ /** One finding in a {@link PromptValidationReport}. */
68
+ type PromptValidationNote = {
69
+ /** How serious this finding is — drives the most-severe-first ordering. */severity: PromptValidationSeverity; /** Human-readable description of the finding. */
70
+ message: string; /** Optional concrete rewrite/fix for this finding. */
71
+ suggestion?: string;
72
+ };
73
+ /**
74
+ * Result of {@link PromptRegistryContract.validate} — an overall quality
75
+ * score plus individual findings, most severe first.
76
+ */
77
+ type PromptValidationReport = {
78
+ /** Overall quality score, `0`–`1`, from the LLM-as-judge rubric + static lint. */score: number; /** Individual findings, most severe first. */
79
+ notes: PromptValidationNote[];
80
+ };
81
+ /** Options for {@link PromptRegistryContract.validate}. */
82
+ type PromptValidateOptions = {
83
+ /**
84
+ * Model that powers the LLM-as-judge pass. When omitted (and no registry
85
+ * default `judgeModel` is set), `validate()` returns the static-lint
86
+ * findings only — never throwing.
87
+ */
88
+ model?: ModelContract;
89
+ /**
90
+ * Validate a registered prompt's specific version (only meaningful when the
91
+ * first argument is a registered name). Default: the latest version.
92
+ */
93
+ version?: string;
94
+ };
95
+ /**
96
+ * Public surface of the prompt registry returned by `prompt(options?)`.
97
+ *
98
+ * **Role.** A named, versioned, typed catalog wrapping `systemPrompt` /
99
+ * `SystemPrompt.fromFile` with `{{placeholder}}` validation, a `validate()`
100
+ * quality check (static lint + LLM-as-judge), and an optional Langfuse sync.
101
+ *
102
+ * Mutating methods (`register` / `add`) return the same registry for chaining.
103
+ */
104
+ type PromptRegistryContract = {
105
+ /**
106
+ * Register a whole entry (name + its version history). Returns the registry
107
+ * for chaining. A name registered twice merges the new versions onto the
108
+ * existing history (duplicate version labels throw a
109
+ * {@link PromptValidationError}).
110
+ */
111
+ register(entry: PromptEntry): PromptRegistryContract;
112
+ /**
113
+ * Add a new version to an existing name (creating the name when absent).
114
+ * A duplicate `version` label throws a {@link PromptValidationError} —
115
+ * never a silent overwrite.
116
+ */
117
+ add(name: string, version: PromptVersion): PromptRegistryContract; /** Whether a name is registered. */
118
+ has(name: string): boolean; /** Every registered prompt name. */
119
+ list(): string[];
120
+ /**
121
+ * Resolve + render. Throws {@link PromptNotFoundError} on an unknown name
122
+ * and {@link PromptValidationError} when the picked version's `required`
123
+ * keys are missing from the merged placeholders.
124
+ */
125
+ resolve(name: string, options?: PromptResolveOptions): ResolvedPrompt; /** Versions registered for a name, latest last. Throws {@link PromptNotFoundError} on miss. */
126
+ versions(name: string): PromptVersion[];
127
+ /**
128
+ * Quality-check a prompt body (raw text) or a registered prompt (by name).
129
+ * Runs a cheap static lint (length, undeclared/unresolved `{{placeholders}}`,
130
+ * missing role line) PLUS, when a model is resolvable, an LLM-as-judge pass
131
+ * over a clarity / role / output-format / conflict rubric — reusing the eval
132
+ * `judge` scorer. With no judge model, returns the static-lint findings only
133
+ * and never throws.
134
+ */
135
+ validate(textOrName: string, options?: PromptValidateOptions): Promise<PromptValidationReport>;
136
+ /**
137
+ * Synchronize named prompts with Langfuse-prompts. Lazily imports the
138
+ * optional `langfuse` peer; pulls named prompts into the catalog and/or
139
+ * pushes local versions per the configured `direction`. Throws a curated
140
+ * install error when `langfuse` is not installed.
141
+ */
142
+ sync(): Promise<void>;
143
+ };
144
+ /**
145
+ * Optional Langfuse-prompts sync configuration (see {@link PromptRegistryOptions}).
146
+ */
147
+ type PromptLangfuseSyncOptions = {
148
+ /** A pre-built Langfuse client. When supplied, the SDK is never imported. */client?: LangfuseClientLike; /** Langfuse public key — used to construct a client when `client` is omitted. */
149
+ publicKey?: string; /** Langfuse secret key — used to construct a client when `client` is omitted. */
150
+ secretKey?: string; /** Langfuse host base URL. Optional; defaults to the SDK's own default. */
151
+ baseUrl?: string; /** Sync direction. `"pull"` (default) pulls remote prompts; `"push"` pushes local; `"both"` does both. */
152
+ direction?: "pull" | "push" | "both";
153
+ };
154
+ /**
155
+ * Options for the `prompt(options?)` factory.
156
+ */
157
+ type PromptRegistryOptions = {
158
+ /** Seed entries at construction. */prompts?: PromptEntry[];
159
+ /**
160
+ * Default model for the `validate()` LLM-as-judge pass when a call does not
161
+ * pass its own `model`. Absent = `validate()` is static-lint-only unless a
162
+ * per-call model is supplied.
163
+ */
164
+ judgeModel?: ModelContract;
165
+ /**
166
+ * Optional Langfuse-prompts sync. Lazily imports `langfuse`; pulls named
167
+ * prompts on `.sync()` and (optionally) pushes local versions. Absent =
168
+ * fully local, no network.
169
+ */
170
+ langfuse?: PromptLangfuseSyncOptions;
171
+ };
172
+ //#endregion
173
+ export { PromptEntry, PromptLangfuseSyncOptions, PromptRegistryContract, PromptRegistryOptions, PromptResolveOptions, PromptValidateOptions, PromptValidationNote, PromptValidationReport, PromptValidationSeverity, PromptVersion, ResolvedPrompt };
174
+ //# sourceMappingURL=prompt.type.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt.type.d.mts","names":[],"sources":["../../../../../../../@warlock.js/ai/src/prompt/prompt.type.ts"],"mappings":";;;;;;;;AAkBA;;;;;;;;;;AAae;KAbH,aAAA;EAuBW,uFArBrB,OAAA,UAyBuB;EAvBvB,QAAA;EAuBA;;;AAAuB;AAMzB;;EAtBE,QAAA,aA0B2B;EAxB3B,IAAA,GAAO,MAAM;AAAA;;;AAwBc;AAO7B;;;;KArBY,W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a,aAAA;;;;;;EAMb,QAAA,GAAW,yBAAA;AAAA"}
@@ -0,0 +1,3 @@
1
+ import { ExportedPrompt, ExportedPromptVersion, ExportedRegistry, PromptDiff, PromptDiffBlock, PromptJudgeCacheLike, PromptTemplateVersion, PromptValidateTarget, PromptValidationResult, PromptsManagerOptions, PromptsValidateOptions } from "./prompts-manager.type.mjs";
2
+ import { PromptsManagerContract, PromptsManagerEntry, PromptsManagerRegisterOptions } from "./prompts-manager.contract.mjs";
3
+ import { defaultPromptsManager, promptKey, prompts } from "./prompts-manager.mjs";
@@ -0,0 +1,3 @@
1
+ import { defaultPromptsManager, promptKey, prompts } from "./prompts-manager.mjs";
2
+
3
+ export { };
@@ -0,0 +1,154 @@
1
+ import { Placeholders } from "../contracts/placeholders.type.mjs";
2
+ import { ExportedRegistry, PromptDiff, PromptTemplateVersion, PromptValidateTarget, PromptValidationResult, PromptsValidateOptions } from "./prompts-manager.type.mjs";
3
+ import { SystemPromptBlockContract, SystemPromptContract, SystemPromptMeta } from "../contracts/system-prompt.contract.mjs";
4
+
5
+ //#region ../@warlock.js/ai/src/prompts/prompts-manager.contract.d.ts
6
+ /**
7
+ * One registered prompt in the {@link PromptsManagerContract} — a named,
8
+ * versioned `SystemPromptContract` plus the bookkeeping the manager needs to
9
+ * resolve "latest" deterministically.
10
+ *
11
+ * **Role.** The unit `register()` produces and `list()` / `get()` return. The
12
+ * registry is keyed by `name@version`, so the same `name` can hold many
13
+ * versions side by side, each its own entry.
14
+ */
15
+ interface PromptsManagerEntry {
16
+ /** Registry name (from the contract's `meta.name`). */
17
+ readonly name: string;
18
+ /** Version label. Defaults to the next integer when registration omits it. */
19
+ readonly version: string;
20
+ /**
21
+ * Monotonic insertion order, sourced from an internal counter (never
22
+ * `Date.now()`), so "latest" is the highest `addedAt` for a name —
23
+ * deterministic and stable across same-tick registrations.
24
+ */
25
+ readonly addedAt: number;
26
+ /** The registered prompt builder. */
27
+ readonly contract: SystemPromptContract;
28
+ /** Optional free-form tags for grouping / filtering. */
29
+ readonly tags?: readonly string[];
30
+ }
31
+ /** Options for {@link PromptsManagerContract.register}. */
32
+ interface PromptsManagerRegisterOptions {
33
+ /** Optional tags stored alongside the entry. */
34
+ readonly tags?: readonly string[];
35
+ /**
36
+ * Explicit name override. When set, it (not `contract.meta().name`) is the
37
+ * registry name — used by `define()` / `import()` to register an anonymous
38
+ * contract under a name without triggering the `SystemPrompt` constructor's
39
+ * auto-registration into the process-wide default manager.
40
+ */
41
+ readonly name?: string;
42
+ /** Explicit version override, paired with {@link name}. */
43
+ readonly version?: string;
44
+ }
45
+ /**
46
+ * Public surface of the prompts manager returned by `prompts()` and exposed as
47
+ * `ai.prompts`.
48
+ *
49
+ * **Role.** A single registry of named, versioned `SystemPromptContract`
50
+ * builders keyed by `name@version`. It owns registration (deriving the version
51
+ * when omitted, rejecting non-idempotent duplicates), version resolution
52
+ * (latest by insertion order), and one-call `resolve()` to the final string.
53
+ *
54
+ * **Responsibility.**
55
+ * - Owns: the `name@version` registry, the monotonic `addedAt` counter, the
56
+ * duplicate / idempotency rule, and latest-version selection.
57
+ * - Does NOT own: how a prompt renders (delegated to the contract's
58
+ * `resolve()`), the `{{placeholder}}` syntax, or block composition.
59
+ */
60
+ interface PromptsManagerContract {
61
+ /**
62
+ * Register a prompt builder. The contract must carry `meta.name`; the
63
+ * version defaults to the next integer for that name when `meta.version` is
64
+ * omitted. Throws `InvalidRequestError` on a duplicate `name@version` unless
65
+ * the registered content is byte-identical (idempotent re-registration).
66
+ * Returns the manager for chaining.
67
+ */
68
+ register(contract: SystemPromptContract, options?: PromptsManagerRegisterOptions): PromptsManagerContract;
69
+ /**
70
+ * Build a new `SystemPromptContract` — a documented alias of `ai.systemPrompt`.
71
+ * Identical input forms: no argument → empty builder; a single string → one
72
+ * instruction-seeded prompt; an array of blocks → used verbatim. Pass a `meta`
73
+ * with a `name` to auto-register the result in the process-wide `ai.prompts`
74
+ * default manager (same semantics as `ai.systemPrompt(input, { name })`).
75
+ *
76
+ * Provided so prompt authoring and the prompt registry share one entry point:
77
+ * `ai.prompts.create(...)` reads identically to `ai.prompts.get(...)` /
78
+ * `ai.prompts.resolve(...)` right beside it.
79
+ */
80
+ create(input?: string | ReadonlyArray<SystemPromptBlockContract>, meta?: SystemPromptMeta): SystemPromptContract;
81
+ /**
82
+ * Resolve a registered builder. The optional second argument selects the
83
+ * version by its label, by a pinned tag (`get(name, "production")`), or via
84
+ * the inline `name@selector` form folded into the first argument
85
+ * (`get("agent@production")`, `get("agent@2")`). With no selector, returns
86
+ * the latest by insertion order. Throws `InvalidRequestError` on an unknown
87
+ * name, version, or tag.
88
+ */
89
+ get(name: string, versionOrTag?: string): SystemPromptContract;
90
+ /** Whether any version of `name` is registered (optionally a specific version/tag). */
91
+ has(name: string, versionOrTag?: string): boolean;
92
+ /** Every registered name, in first-seen order. */
93
+ list(): string[];
94
+ /** Version labels registered for a name, oldest first. Empty when unknown. */
95
+ versions(name: string): string[];
96
+ /**
97
+ * Resolve a registered prompt to its final string in one call — picks the
98
+ * version (latest when omitted; a version label, a pinned tag, or the inline
99
+ * `name@selector` form is accepted) and renders it against `placeholders`.
100
+ * Throws `InvalidRequestError` on an unknown name / version / tag.
101
+ */
102
+ resolve(name: string, versionOrTag?: string, placeholders?: Placeholders): string;
103
+ /**
104
+ * Bulk-register many versions of one name in a single call. Each entry's
105
+ * `template` is a raw string (wrapped into one instruction block) or an
106
+ * explicit ordered block list (used verbatim). Versions register oldest-first
107
+ * in array order; the same duplicate / idempotency rule as `register` applies
108
+ * per `name@version`. Returns the manager for chaining.
109
+ */
110
+ define(name: string, versions: readonly PromptTemplateVersion[]): PromptsManagerContract;
111
+ /**
112
+ * Pin a tag to a specific registered version of a name (e.g.
113
+ * `tag("agent", "production", "2")`). The tag then resolves through
114
+ * `get(name, tag)` / `resolve(name, tag)` / the `name@tag` inline form.
115
+ * Re-pinning an existing tag moves it. Throws `InvalidRequestError` when the
116
+ * name or version is unknown. Returns the manager for chaining.
117
+ */
118
+ tag(name: string, tag: string, version: string): PromptsManagerContract;
119
+ /**
120
+ * Unified prompt validation. ALWAYS runs the deterministic check — every
121
+ * `{{key}}` placeholder with no inline default that is neither supplied
122
+ * (`options.placeholders`) nor declared (`options.declare` + the prompt's
123
+ * `meta.required`) is reported in `missing`, and `ok` is `true` iff `missing`
124
+ * is empty. When `options.judge` is a model, ALSO runs a Nova-safe
125
+ * LLM-as-judge quality pass — it never throws and degrades to an `issues`
126
+ * note (leaving `score` undefined) on failure, so it never flips `ok`.
127
+ *
128
+ * `target` is a registered name (or `name@selector`), a `SystemPromptContract`
129
+ * instance, or a raw prompt string.
130
+ */
131
+ validate(target: PromptValidateTarget, options?: PromptsValidateOptions): Promise<PromptValidationResult>;
132
+ /**
133
+ * Block-level diff between two registered versions of a name. Blocks are
134
+ * matched positionally; the result lists added / removed / changed blocks and
135
+ * an `identical` flag. Throws `InvalidRequestError` on an unknown name or
136
+ * version.
137
+ */
138
+ diff(name: string, from: string, to: string): PromptDiff;
139
+ /**
140
+ * Serialize the whole registry to a portable JSON snapshot — every name, its
141
+ * versions (flattened to `{ type, text }` blocks), pinned tags, and carried
142
+ * `description` / `required` metadata. Round-trips through `import`.
143
+ */
144
+ export(): ExportedRegistry;
145
+ /**
146
+ * Rehydrate a registry from an `export()` snapshot. Each version re-registers
147
+ * under its `name@version` (subject to the same duplicate / idempotency rule)
148
+ * and pinned tags are restored. Returns the manager for chaining.
149
+ */
150
+ import(snapshot: ExportedRegistry): PromptsManagerContract;
151
+ }
152
+ //#endregion
153
+ export { PromptsManagerContract, PromptsManagerEntry, PromptsManagerRegisterOptions };
154
+ //# sourceMappingURL=prompts-manager.contract.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompts-manager.contract.d.mts","names":[],"sources":["../../../../../../../@warlock.js/ai/src/prompts/prompts-manager.contract.ts"],"mappings":";;;;;;;AAwBA;;;;;;;UAAiB,mBAAA;EAeI;EAAA,SAbV,IAAA;EAgBI;EAAA,SAbJ,OAAA;EAiBM;;;;;EAAA,SAVN,OAAA;EAuBA;EAAA,SApBA,QAAA,EAAU,oBAAoB;EAoBvB;EAAA,SAjBP,IAAA;AAAA;;UAIM,6BAAA;EAyCH;EAAA,SAvCH,IAAA;EAsDwB;;;;;;EAAA,SA9CxB,IAAA;EA2FN;EAAA,SAxFM,OAAA;AAAA;;;;;;;;;;;;;;;;UAkBM,sBAAA;EAyBI;;;;;;;EAjBnB,QAAA,CACE,QAAA,EAAU,oBAAA,EACV,OAAA,GAAU,6BAAA,GACT,sBAAA;EA0Be;;;;;;;;;;;EAblB,MAAA,CACE,KAAA,YAAiB,aAAA,CAAc,yBAAA,GAC/B,IAAA,GAAO,gBAAA,GACN,oBAAA;EA8BD;;;;;;;;EApBF,GAAA,CAAI,IAAA,UAAc,YAAA,YAAwB,oBAAA;EA0CX;EAvC/B,GAAA,CAAI,IAAA,UAAc,YAAA;EAqDlB;EAlDA,IAAA;EAmDE;EAhDF,QAAA,CAAS,IAAA;EAiDP;;;;;;EAzCF,OAAA,CACE,IAAA,UACA,YAAA,WACA,YAAA,GAAe,YAAA;EA+C6B;;;;;;;EArC9C,MAAA,CACE,IAAA,UACA,QAAA,WAAmB,qBAAA,KAClB,sBAAA;EAgDuD;;;;;;;EAvC1D,GAAA,CAAI,IAAA,UAAc,GAAA,UAAa,OAAA,WAAkB,sBAAA;;;;;;;;;;;;;EAcjD,QAAA,CACE,MAAA,EAAQ,oBAAA,EACR,OAAA,GAAU,sBAAA,GACT,OAAA,CAAQ,sBAAA;;;;;;;EAQX,IAAA,CAAK,IAAA,UAAc,IAAA,UAAc,EAAA,WAAa,UAAA;;;;;;EAO9C,MAAA,IAAU,gBAAA;;;;;;EAOV,MAAA,CAAO,QAAA,EAAU,gBAAA,GAAmB,sBAAA;AAAA"}
@@ -0,0 +1,38 @@
1
+ import { PromptsManagerOptions } from "./prompts-manager.type.mjs";
2
+ import { PromptsManagerContract } from "./prompts-manager.contract.mjs";
3
+
4
+ //#region ../@warlock.js/ai/src/prompts/prompts-manager.d.ts
5
+ /**
6
+ * Build the `name@version` registry key. Centralized so the duplicate check,
7
+ * `get`, and `composedFrom` provenance all agree on one label shape.
8
+ */
9
+ declare function promptKey(name: string, version: string): string;
10
+ /**
11
+ * Create a new, isolated prompts manager.
12
+ *
13
+ * **Role.** Public factory for {@link PromptsManagerContract} — keeps
14
+ * user-facing code free of `new` and consistent with the other `ai.*`
15
+ * factories. Each call returns a fresh registry, so parallel test suites and
16
+ * multi-tenant apps never share mutable global prompt state.
17
+ *
18
+ * The process-wide instance that named `systemPrompt(...)` builders
19
+ * auto-register into is `ai.prompts` (see {@link defaultPromptsManager}).
20
+ *
21
+ * @param options - Optional wiring, notably a `judgeCache` that memoizes
22
+ * LLM-judge verdicts (absent ⇒ every judge pass runs live).
23
+ *
24
+ * @example
25
+ * const registry = prompts();
26
+ * registry.register(systemPrompt("You are support.", { name: "support" }));
27
+ * registry.resolve("support"); // "You are support."
28
+ *
29
+ * @example
30
+ * // Memoize judge verdicts across validations.
31
+ * const registry = prompts({ judgeCache: new MemoryCacheDriver() });
32
+ */
33
+ declare function prompts(options?: PromptsManagerOptions): PromptsManagerContract;
34
+ /** Accessor for the process-wide default {@link PromptsManagerContract}. */
35
+ declare function defaultPromptsManager(): PromptsManagerContract;
36
+ //#endregion
37
+ export { defaultPromptsManager, promptKey, prompts };
38
+ //# sourceMappingURL=prompts-manager.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompts-manager.d.mts","names":[],"sources":["../../../../../../../@warlock.js/ai/src/prompts/prompts-manager.ts"],"mappings":";;;;;;AAsCA;;iBAAgB,SAAA,CAAU,IAAA,UAAc,OAAe;;AAAA;AAqnBvD;;;;;;;;AAAgF;AAehF;;;;AAA+D;;;;;;;;iBAf/C,OAAA,CAAQ,OAAA,GAAU,qBAAA,GAAwB,sBAAsB;;iBAehE,qBAAA,IAAyB,sBAAsB"}