@warlock.js/ai 4.4.0 → 4.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +52 -55
- package/cjs/index.cjs +221 -14147
- package/cjs/src-C02yzsLs.cjs +22991 -0
- package/cjs/src-C02yzsLs.cjs.map +1 -0
- package/cjs/src-DFibP2FQ.cjs +30 -0
- package/esm/agent/agent-config.type.d.mts +90 -1
- package/esm/agent/agent-config.type.d.mts.map +1 -1
- package/esm/agent/agent-input-builder.mjs +27 -6
- package/esm/agent/agent-input-builder.mjs.map +1 -1
- package/esm/agent/agent.d.mts +40 -1
- package/esm/agent/agent.d.mts.map +1 -1
- package/esm/agent/agent.mjs +203 -30
- package/esm/agent/agent.mjs.map +1 -1
- package/esm/agent/index.d.mts +2 -1
- package/esm/agent/index.mjs +1 -0
- package/esm/agent/judge-config.type.d.mts +33 -0
- package/esm/agent/judge-config.type.d.mts.map +1 -0
- package/esm/agent/judge-config.type.mjs +13 -0
- package/esm/agent/judge-config.type.mjs.map +1 -0
- package/esm/ai-openai/src/embedder.mjs +4 -0
- package/esm/ai-openai/src/index.mjs +4 -0
- package/esm/ai-openai/src/model.mjs +5 -0
- package/esm/ai-openai/src/sdk.mjs +6 -0
- package/esm/ai-openai/src/utils/index.mjs +4 -0
- package/esm/ai-openai/src/utils/to-openai-tools.mjs +3 -0
- package/esm/ai-openai/src/utils/wrap-openai-error.mjs +4 -0
- package/esm/ai.d.mts +119 -53
- package/esm/ai.d.mts.map +1 -1
- package/esm/ai.mjs +43 -8
- package/esm/ai.mjs.map +1 -1
- package/esm/batch/batch.d.mts.map +1 -1
- package/esm/batch/batch.mjs +21 -1
- package/esm/batch/batch.mjs.map +1 -1
- package/esm/batch/batch.type.d.mts +11 -4
- package/esm/batch/batch.type.d.mts.map +1 -1
- package/esm/config.d.mts +39 -3
- package/esm/config.d.mts.map +1 -1
- package/esm/config.mjs +26 -2
- package/esm/config.mjs.map +1 -1
- package/esm/contracts/agent/agent-options.type.d.mts +11 -3
- package/esm/contracts/agent/agent-options.type.d.mts.map +1 -1
- package/esm/contracts/agent/eval.type.d.mts +43 -2
- package/esm/contracts/agent/eval.type.d.mts.map +1 -1
- package/esm/contracts/attachment-policy.type.d.mts +51 -0
- package/esm/contracts/attachment-policy.type.d.mts.map +1 -0
- package/esm/contracts/attachment.type.d.mts +16 -7
- package/esm/contracts/attachment.type.d.mts.map +1 -1
- package/esm/contracts/content-part.type.d.mts +14 -5
- package/esm/contracts/content-part.type.d.mts.map +1 -1
- package/esm/contracts/events/supervisor-events.type.d.mts.map +1 -1
- package/esm/contracts/index.d.mts +6 -4
- package/esm/contracts/model.contract.d.mts +11 -8
- package/esm/contracts/model.contract.d.mts.map +1 -1
- package/esm/contracts/orchestrator/index.d.mts +1 -0
- package/esm/contracts/orchestrator/orchestrator-config.type.d.mts +31 -2
- package/esm/contracts/orchestrator/orchestrator-config.type.d.mts.map +1 -1
- package/esm/contracts/orchestrator/session-lock.contract.d.mts +47 -0
- package/esm/contracts/orchestrator/session-lock.contract.d.mts.map +1 -0
- package/esm/contracts/planner/index.d.mts +1 -1
- package/esm/contracts/planner/planner-config.type.d.mts +31 -0
- package/esm/contracts/planner/planner-config.type.d.mts.map +1 -1
- package/esm/contracts/planner/planner-execute-options.type.d.mts +48 -1
- package/esm/contracts/planner/planner-execute-options.type.d.mts.map +1 -1
- package/esm/contracts/planner/planner-result.type.d.mts +8 -0
- package/esm/contracts/planner/planner-result.type.d.mts.map +1 -1
- package/esm/contracts/planner/planner.contract.d.mts +1 -1
- package/esm/contracts/result/agent-result.type.d.mts +6 -4
- package/esm/contracts/result/agent-result.type.d.mts.map +1 -1
- package/esm/contracts/result/base-report.type.d.mts +21 -3
- package/esm/contracts/result/base-report.type.d.mts.map +1 -1
- package/esm/contracts/result/base-report.type.mjs.map +1 -1
- package/esm/contracts/result/execution-report.type.d.mts +53 -1
- package/esm/contracts/result/execution-report.type.d.mts.map +1 -1
- package/esm/contracts/result/supervisor-result.type.d.mts +14 -2
- package/esm/contracts/result/supervisor-result.type.d.mts.map +1 -1
- package/esm/contracts/result/workflow-result.type.d.mts +2 -1
- package/esm/contracts/result/workflow-result.type.d.mts.map +1 -1
- package/esm/contracts/supervisor/supervisor-config.type.d.mts +29 -0
- package/esm/contracts/supervisor/supervisor-config.type.d.mts.map +1 -1
- package/esm/contracts/system-prompt.contract.d.mts +103 -1
- package/esm/contracts/system-prompt.contract.d.mts.map +1 -1
- package/esm/contracts/team/index.d.mts +1 -0
- package/esm/contracts/team/team-config.type.d.mts +127 -0
- package/esm/contracts/team/team-config.type.d.mts.map +1 -0
- package/esm/contracts/tool.contract.d.mts +4 -2
- package/esm/contracts/tool.contract.d.mts.map +1 -1
- package/esm/contracts/workflow/step.contract.d.mts +30 -5
- package/esm/contracts/workflow/step.contract.d.mts.map +1 -1
- package/esm/contracts/workflow/workflow.contract.d.mts +16 -0
- package/esm/contracts/workflow/workflow.contract.d.mts.map +1 -1
- package/esm/errors/error-code.type.d.mts +1 -1
- package/esm/errors/index.d.mts +1 -0
- package/esm/errors/index.mjs +1 -0
- package/esm/errors/outbound-policy-error.d.mts +27 -0
- package/esm/errors/outbound-policy-error.d.mts.map +1 -0
- package/esm/errors/outbound-policy-error.mjs +32 -0
- package/esm/errors/outbound-policy-error.mjs.map +1 -0
- package/esm/eval/dataset.d.mts +28 -0
- package/esm/eval/dataset.d.mts.map +1 -0
- package/esm/eval/dataset.mjs +112 -0
- package/esm/eval/dataset.mjs.map +1 -0
- package/esm/eval/dataset.type.d.mts +53 -0
- package/esm/eval/dataset.type.d.mts.map +1 -0
- package/esm/eval/eval-runner.d.mts.map +1 -1
- package/esm/eval/eval-runner.mjs +16 -2
- package/esm/eval/eval-runner.mjs.map +1 -1
- package/esm/eval/index.d.mts +20 -1
- package/esm/eval/index.d.mts.map +1 -1
- package/esm/eval/index.mjs +20 -2
- package/esm/eval/index.mjs.map +1 -1
- package/esm/eval/regression.d.mts +30 -0
- package/esm/eval/regression.d.mts.map +1 -0
- package/esm/eval/regression.mjs +51 -0
- package/esm/eval/regression.mjs.map +1 -0
- package/esm/eval/report-json.d.mts +30 -0
- package/esm/eval/report-json.d.mts.map +1 -0
- package/esm/eval/report-json.mjs +33 -0
- package/esm/eval/report-json.mjs.map +1 -0
- package/esm/eval/report-junit.d.mts +22 -0
- package/esm/eval/report-junit.d.mts.map +1 -0
- package/esm/eval/report-junit.mjs +60 -0
- package/esm/eval/report-junit.mjs.map +1 -0
- package/esm/guard/contracts/guard-options.type.d.mts +165 -0
- package/esm/guard/contracts/guard-options.type.d.mts.map +1 -0
- package/esm/guard/contracts/guardrail.contract.d.mts +78 -0
- package/esm/guard/contracts/guardrail.contract.d.mts.map +1 -0
- package/esm/guard/contracts/index.d.mts +4 -0
- package/esm/guard/contracts/openai-client.contract.d.mts +51 -0
- package/esm/guard/contracts/openai-client.contract.d.mts.map +1 -0
- package/esm/guard/contracts/verdict.type.d.mts +76 -0
- package/esm/guard/contracts/verdict.type.d.mts.map +1 -0
- package/esm/guard/detectors/index.d.mts +4 -0
- package/esm/guard/detectors/index.mjs +6 -0
- package/esm/guard/detectors/injection.d.mts +34 -0
- package/esm/guard/detectors/injection.d.mts.map +1 -0
- package/esm/guard/detectors/injection.mjs +254 -0
- package/esm/guard/detectors/injection.mjs.map +1 -0
- package/esm/guard/detectors/moderation.d.mts +32 -0
- package/esm/guard/detectors/moderation.d.mts.map +1 -0
- package/esm/guard/detectors/moderation.mjs +134 -0
- package/esm/guard/detectors/moderation.mjs.map +1 -0
- package/esm/guard/detectors/pii.d.mts +41 -0
- package/esm/guard/detectors/pii.d.mts.map +1 -0
- package/esm/guard/detectors/pii.mjs +199 -0
- package/esm/guard/detectors/pii.mjs.map +1 -0
- package/esm/guard/detectors/topic.d.mts +29 -0
- package/esm/guard/detectors/topic.d.mts.map +1 -0
- package/esm/guard/detectors/topic.mjs +99 -0
- package/esm/guard/detectors/topic.mjs.map +1 -0
- package/esm/guard/errors.d.mts +12 -0
- package/esm/guard/errors.d.mts.map +1 -0
- package/esm/guard/errors.mjs +18 -0
- package/esm/guard/errors.mjs.map +1 -0
- package/esm/guard/guard.d.mts +67 -0
- package/esm/guard/guard.d.mts.map +1 -0
- package/esm/guard/guard.mjs +209 -0
- package/esm/guard/guard.mjs.map +1 -0
- package/esm/guard/guardrail.d.mts +39 -0
- package/esm/guard/guardrail.d.mts.map +1 -0
- package/esm/guard/guardrail.mjs +22 -0
- package/esm/guard/guardrail.mjs.map +1 -0
- package/esm/human/contracts/approval.type.d.mts +154 -0
- package/esm/human/contracts/approval.type.d.mts.map +1 -0
- package/esm/human/contracts/human-approval.type.d.mts +38 -0
- package/esm/human/contracts/human-approval.type.d.mts.map +1 -0
- package/esm/human/contracts/index.d.mts +4 -0
- package/esm/human/contracts/interrupt-store.contract.d.mts +112 -0
- package/esm/human/contracts/interrupt-store.contract.d.mts.map +1 -0
- package/esm/human/contracts/resume.type.d.mts +77 -0
- package/esm/human/contracts/resume.type.d.mts.map +1 -0
- package/esm/human/errors.d.mts +84 -0
- package/esm/human/errors.d.mts.map +1 -0
- package/esm/human/errors.mjs +60 -0
- package/esm/human/errors.mjs.map +1 -0
- package/esm/human/human-approval.d.mts +57 -0
- package/esm/human/human-approval.d.mts.map +1 -0
- package/esm/human/human-approval.mjs +170 -0
- package/esm/human/human-approval.mjs.map +1 -0
- package/esm/human/policy.d.mts +55 -0
- package/esm/human/policy.d.mts.map +1 -0
- package/esm/human/policy.mjs +67 -0
- package/esm/human/policy.mjs.map +1 -0
- package/esm/human/register.mjs +37 -0
- package/esm/human/register.mjs.map +1 -0
- package/esm/human/resume-seed.mjs +53 -0
- package/esm/human/resume-seed.mjs.map +1 -0
- package/esm/human/resume.d.mts +54 -0
- package/esm/human/resume.d.mts.map +1 -0
- package/esm/human/resume.mjs +121 -0
- package/esm/human/resume.mjs.map +1 -0
- package/esm/human/stores/index.mjs +5 -0
- package/esm/human/stores/memory.d.mts +30 -0
- package/esm/human/stores/memory.d.mts.map +1 -0
- package/esm/human/stores/memory.mjs +91 -0
- package/esm/human/stores/memory.mjs.map +1 -0
- package/esm/human/stores/pg.d.mts +59 -0
- package/esm/human/stores/pg.d.mts.map +1 -0
- package/esm/human/stores/pg.mjs +220 -0
- package/esm/human/stores/pg.mjs.map +1 -0
- package/esm/human/stores/redis.d.mts +56 -0
- package/esm/human/stores/redis.d.mts.map +1 -0
- package/esm/human/stores/redis.mjs +201 -0
- package/esm/human/stores/redis.mjs.map +1 -0
- package/esm/index.d.mts +113 -22
- package/esm/index.mjs +82 -11
- package/esm/middleware/builtins/budget.mjs +6 -2
- package/esm/middleware/builtins/budget.mjs.map +1 -1
- package/esm/middleware/utils/extract-user-text.d.mts +8 -1
- package/esm/middleware/utils/extract-user-text.d.mts.map +1 -1
- package/esm/middleware/utils/extract-user-text.mjs +8 -1
- package/esm/middleware/utils/extract-user-text.mjs.map +1 -1
- package/esm/object-stream/index.d.mts +2 -0
- package/esm/object-stream/index.mjs +4 -0
- package/esm/object-stream/parse-partial-json.d.mts +22 -0
- package/esm/object-stream/parse-partial-json.d.mts.map +1 -0
- package/esm/object-stream/parse-partial-json.mjs +78 -0
- package/esm/object-stream/parse-partial-json.mjs.map +1 -0
- package/esm/object-stream/stream-object.d.mts +68 -0
- package/esm/object-stream/stream-object.d.mts.map +1 -0
- package/esm/object-stream/stream-object.mjs +104 -0
- package/esm/object-stream/stream-object.mjs.map +1 -0
- package/esm/observe/index.mjs +4 -0
- package/esm/observe/observer-registry.d.mts +30 -0
- package/esm/observe/observer-registry.d.mts.map +1 -0
- package/esm/observe/observer-registry.mjs +51 -0
- package/esm/observe/observer-registry.mjs.map +1 -0
- package/esm/observe/observer.contract.d.mts +40 -0
- package/esm/observe/observer.contract.d.mts.map +1 -0
- package/esm/observe/resolve-observers.d.mts +40 -0
- package/esm/observe/resolve-observers.d.mts.map +1 -0
- package/esm/observe/resolve-observers.mjs +73 -0
- package/esm/observe/resolve-observers.mjs.map +1 -0
- package/esm/orchestrator/execution.d.mts.map +1 -1
- package/esm/orchestrator/execution.mjs +5 -2
- package/esm/orchestrator/execution.mjs.map +1 -1
- package/esm/orchestrator/index.d.mts +1 -0
- package/esm/orchestrator/index.mjs +1 -0
- package/esm/orchestrator/orchestrator.d.mts.map +1 -1
- package/esm/orchestrator/orchestrator.mjs +39 -6
- package/esm/orchestrator/orchestrator.mjs.map +1 -1
- package/esm/orchestrator/session-lock.d.mts +25 -0
- package/esm/orchestrator/session-lock.d.mts.map +1 -0
- package/esm/orchestrator/session-lock.mjs +83 -0
- package/esm/orchestrator/session-lock.mjs.map +1 -0
- package/esm/planner/dag-scheduler.mjs +97 -0
- package/esm/planner/dag-scheduler.mjs.map +1 -0
- package/esm/planner/plan-prompt.d.mts +1 -1
- package/esm/planner/plan-prompt.d.mts.map +1 -1
- package/esm/planner/plan-prompt.mjs +2 -1
- package/esm/planner/plan-prompt.mjs.map +1 -1
- package/esm/planner/planner-run.d.mts.map +1 -1
- package/esm/planner/planner-run.mjs +300 -29
- package/esm/planner/planner-run.mjs.map +1 -1
- package/esm/planner/planner.mjs +1 -1
- package/esm/planner/planner.mjs.map +1 -1
- package/esm/prompt/errors.d.mts +57 -0
- package/esm/prompt/errors.d.mts.map +1 -0
- package/esm/prompt/errors.mjs +73 -0
- package/esm/prompt/errors.mjs.map +1 -0
- package/esm/prompt/index.d.mts +3 -0
- package/esm/prompt/index.mjs +4 -0
- package/esm/prompt/prompt-langfuse-sync.mjs +104 -0
- package/esm/prompt/prompt-langfuse-sync.mjs.map +1 -0
- package/esm/prompt/prompt-langfuse-sync.type.d.mts +32 -0
- package/esm/prompt/prompt-langfuse-sync.type.d.mts.map +1 -0
- package/esm/prompt/prompt-validate.mjs +170 -0
- package/esm/prompt/prompt-validate.mjs.map +1 -0
- package/esm/prompt/prompt.d.mts +54 -0
- package/esm/prompt/prompt.d.mts.map +1 -0
- package/esm/prompt/prompt.mjs +218 -0
- package/esm/prompt/prompt.mjs.map +1 -0
- package/esm/prompt/prompt.type.d.mts +174 -0
- package/esm/prompt/prompt.type.d.mts.map +1 -0
- package/esm/prompts/index.d.mts +3 -0
- package/esm/prompts/index.mjs +3 -0
- package/esm/prompts/prompts-manager.contract.d.mts +154 -0
- package/esm/prompts/prompts-manager.contract.d.mts.map +1 -0
- package/esm/prompts/prompts-manager.d.mts +38 -0
- package/esm/prompts/prompts-manager.d.mts.map +1 -0
- package/esm/prompts/prompts-manager.mjs +410 -0
- package/esm/prompts/prompts-manager.mjs.map +1 -0
- package/esm/prompts/prompts-manager.type.d.mts +172 -0
- package/esm/prompts/prompts-manager.type.d.mts.map +1 -0
- package/esm/prompts/prompts-validate.mjs +200 -0
- package/esm/prompts/prompts-validate.mjs.map +1 -0
- package/esm/rag/as-tool.mjs +48 -0
- package/esm/rag/as-tool.mjs.map +1 -0
- package/esm/rag/chunk/chunk.d.mts +24 -0
- package/esm/rag/chunk/chunk.d.mts.map +1 -0
- package/esm/rag/chunk/chunk.mjs +44 -0
- package/esm/rag/chunk/chunk.mjs.map +1 -0
- package/esm/rag/chunk/fixed.mjs +32 -0
- package/esm/rag/chunk/fixed.mjs.map +1 -0
- package/esm/rag/chunk/markdown.mjs +75 -0
- package/esm/rag/chunk/markdown.mjs.map +1 -0
- package/esm/rag/chunk/recursive.mjs +132 -0
- package/esm/rag/chunk/recursive.mjs.map +1 -0
- package/esm/rag/chunk/sentence.mjs +73 -0
- package/esm/rag/chunk/sentence.mjs.map +1 -0
- package/esm/rag/contracts/chunk-options.type.d.mts +35 -0
- package/esm/rag/contracts/chunk-options.type.d.mts.map +1 -0
- package/esm/rag/contracts/citation.type.d.mts +35 -0
- package/esm/rag/contracts/citation.type.d.mts.map +1 -0
- package/esm/rag/contracts/index.d.mts +4 -0
- package/esm/rag/contracts/rag-config.type.d.mts +68 -0
- package/esm/rag/contracts/rag-config.type.d.mts.map +1 -0
- package/esm/rag/contracts/rag-document.type.d.mts +21 -0
- package/esm/rag/contracts/rag-document.type.d.mts.map +1 -0
- package/esm/rag/hybrid/bm25.d.mts +23 -0
- package/esm/rag/hybrid/bm25.d.mts.map +1 -0
- package/esm/rag/hybrid/bm25.mjs +51 -0
- package/esm/rag/hybrid/bm25.mjs.map +1 -0
- package/esm/rag/hybrid/hybrid-rank.d.mts +33 -0
- package/esm/rag/hybrid/hybrid-rank.d.mts.map +1 -0
- package/esm/rag/hybrid/hybrid-rank.mjs +29 -0
- package/esm/rag/hybrid/hybrid-rank.mjs.map +1 -0
- package/esm/rag/hybrid/rrf.d.mts +25 -0
- package/esm/rag/hybrid/rrf.d.mts.map +1 -0
- package/esm/rag/hybrid/rrf.mjs +30 -0
- package/esm/rag/hybrid/rrf.mjs.map +1 -0
- package/esm/rag/index.d.mts +15 -0
- package/esm/rag/index.mjs +11 -0
- package/esm/rag/rag.d.mts +38 -0
- package/esm/rag/rag.d.mts.map +1 -0
- package/esm/rag/rag.mjs +126 -0
- package/esm/rag/rag.mjs.map +1 -0
- package/esm/rag/rerank/keyword-reranker.d.mts +32 -0
- package/esm/rag/rerank/keyword-reranker.d.mts.map +1 -0
- package/esm/rag/rerank/keyword-reranker.mjs +58 -0
- package/esm/rag/rerank/keyword-reranker.mjs.map +1 -0
- package/esm/rag/rerank/llm-reranker.d.mts +36 -0
- package/esm/rag/rerank/llm-reranker.d.mts.map +1 -0
- package/esm/rag/rerank/llm-reranker.mjs +85 -0
- package/esm/rag/rerank/llm-reranker.mjs.map +1 -0
- package/esm/rag/rerank/reranker.contract.d.mts +28 -0
- package/esm/rag/rerank/reranker.contract.d.mts.map +1 -0
- package/esm/rag/retrieve.mjs +68 -0
- package/esm/rag/retrieve.mjs.map +1 -0
- package/esm/rag/store/cache-vector-store.d.mts +27 -0
- package/esm/rag/store/cache-vector-store.d.mts.map +1 -0
- package/esm/rag/store/cache-vector-store.mjs +48 -0
- package/esm/rag/store/cache-vector-store.mjs.map +1 -0
- package/esm/rag/store/vector-store.contract.d.mts +38 -0
- package/esm/rag/store/vector-store.contract.d.mts.map +1 -0
- package/esm/rag/transforms/multi-query.d.mts +27 -0
- package/esm/rag/transforms/multi-query.d.mts.map +1 -0
- package/esm/rag/transforms/multi-query.mjs +41 -0
- package/esm/rag/transforms/multi-query.mjs.map +1 -0
- package/esm/security/index.mjs +5 -0
- package/esm/security/outbound-policy.d.mts +46 -0
- package/esm/security/outbound-policy.d.mts.map +1 -0
- package/esm/security/outbound-policy.mjs +187 -0
- package/esm/security/outbound-policy.mjs.map +1 -0
- package/esm/security/outbound-policy.type.d.mts +74 -0
- package/esm/security/outbound-policy.type.d.mts.map +1 -0
- package/esm/security/private-ip.d.mts +15 -0
- package/esm/security/private-ip.d.mts.map +1 -0
- package/esm/security/private-ip.mjs +48 -0
- package/esm/security/private-ip.mjs.map +1 -0
- package/esm/security/redact.d.mts +59 -0
- package/esm/security/redact.d.mts.map +1 -0
- package/esm/security/redact.mjs +122 -0
- package/esm/security/redact.mjs.map +1 -0
- package/esm/serve/serve.d.mts +50 -0
- package/esm/serve/serve.d.mts.map +1 -0
- package/esm/serve/serve.mjs +90 -0
- package/esm/serve/serve.mjs.map +1 -0
- package/esm/serve/sse.d.mts +20 -0
- package/esm/serve/sse.d.mts.map +1 -0
- package/esm/serve/sse.mjs +25 -0
- package/esm/serve/sse.mjs.map +1 -0
- package/esm/serve/stream-to-sse.d.mts +29 -0
- package/esm/serve/stream-to-sse.d.mts.map +1 -0
- package/esm/serve/stream-to-sse.mjs +37 -0
- package/esm/serve/stream-to-sse.mjs.map +1 -0
- package/esm/skills/catalog.d.mts +49 -0
- package/esm/skills/catalog.d.mts.map +1 -0
- package/esm/skills/catalog.mjs +140 -0
- package/esm/skills/catalog.mjs.map +1 -0
- package/esm/skills/contracts/skill-record.type.d.mts +37 -0
- package/esm/skills/contracts/skill-record.type.d.mts.map +1 -0
- package/esm/skills/contracts/skills-config.type.d.mts +108 -0
- package/esm/skills/contracts/skills-config.type.d.mts.map +1 -0
- package/esm/skills/contracts/skills-store.contract.d.mts +28 -0
- package/esm/skills/contracts/skills-store.contract.d.mts.map +1 -0
- package/esm/skills/contracts/skills.contract.d.mts +43 -0
- package/esm/skills/contracts/skills.contract.d.mts.map +1 -0
- package/esm/skills/index.d.mts +16 -0
- package/esm/skills/index.mjs +14 -0
- package/esm/skills/load-skill-tool.d.mts +38 -0
- package/esm/skills/load-skill-tool.d.mts.map +1 -0
- package/esm/skills/load-skill-tool.mjs +65 -0
- package/esm/skills/load-skill-tool.mjs.map +1 -0
- package/esm/skills/review-gate.d.mts +33 -0
- package/esm/skills/review-gate.d.mts.map +1 -0
- package/esm/skills/review-gate.mjs +60 -0
- package/esm/skills/review-gate.mjs.map +1 -0
- package/esm/skills/save-skill-tool.d.mts +39 -0
- package/esm/skills/save-skill-tool.d.mts.map +1 -0
- package/esm/skills/save-skill-tool.mjs +65 -0
- package/esm/skills/save-skill-tool.mjs.map +1 -0
- package/esm/skills/skills.d.mts +33 -0
- package/esm/skills/skills.d.mts.map +1 -0
- package/esm/skills/skills.mjs +109 -0
- package/esm/skills/skills.mjs.map +1 -0
- package/esm/skills/sources/directory-source.d.mts +19 -0
- package/esm/skills/sources/directory-source.d.mts.map +1 -0
- package/esm/skills/sources/directory-source.mjs +108 -0
- package/esm/skills/sources/directory-source.mjs.map +1 -0
- package/esm/skills/sources/index.d.mts +18 -0
- package/esm/skills/sources/index.d.mts.map +1 -0
- package/esm/skills/sources/index.mjs +27 -0
- package/esm/skills/sources/index.mjs.map +1 -0
- package/esm/skills/sources/parse-frontmatter.d.mts +27 -0
- package/esm/skills/sources/parse-frontmatter.d.mts.map +1 -0
- package/esm/skills/sources/parse-frontmatter.mjs +46 -0
- package/esm/skills/sources/parse-frontmatter.mjs.map +1 -0
- package/esm/skills/sources/store-source.d.mts +14 -0
- package/esm/skills/sources/store-source.d.mts.map +1 -0
- package/esm/skills/sources/store-source.mjs +15 -0
- package/esm/skills/sources/store-source.mjs.map +1 -0
- package/esm/skills/sources/url-source.d.mts +29 -0
- package/esm/skills/sources/url-source.d.mts.map +1 -0
- package/esm/skills/sources/url-source.mjs +117 -0
- package/esm/skills/sources/url-source.mjs.map +1 -0
- package/esm/skills/store/mock-skills-store.d.mts +57 -0
- package/esm/skills/store/mock-skills-store.d.mts.map +1 -0
- package/esm/skills/store/mock-skills-store.mjs +100 -0
- package/esm/skills/store/mock-skills-store.mjs.map +1 -0
- package/esm/skills/store/procedural-skill-store.d.mts +30 -0
- package/esm/skills/store/procedural-skill-store.d.mts.map +1 -0
- package/esm/skills/store/procedural-skill-store.mjs +125 -0
- package/esm/skills/store/procedural-skill-store.mjs.map +1 -0
- package/esm/supervisor/as-tool.mjs +2 -2
- package/esm/supervisor/as-tool.mjs.map +1 -1
- package/esm/supervisor/execution.d.mts.map +1 -1
- package/esm/supervisor/execution.mjs +31 -28
- package/esm/supervisor/execution.mjs.map +1 -1
- package/esm/supervisor/supervisor.d.mts.map +1 -1
- package/esm/supervisor/supervisor.mjs +8 -3
- package/esm/supervisor/supervisor.mjs.map +1 -1
- package/esm/system-prompt/index.d.mts +4 -0
- package/esm/system-prompt/system-prompt.d.mts +68 -4
- package/esm/system-prompt/system-prompt.d.mts.map +1 -1
- package/esm/system-prompt/system-prompt.mjs +89 -5
- package/esm/system-prompt/system-prompt.mjs.map +1 -1
- package/esm/team/gates.mjs +48 -0
- package/esm/team/gates.mjs.map +1 -0
- package/esm/team/index.d.mts +1 -0
- package/esm/team/index.mjs +3 -0
- package/esm/team/team.d.mts +42 -0
- package/esm/team/team.d.mts.map +1 -0
- package/esm/team/team.mjs +94 -0
- package/esm/team/team.mjs.map +1 -0
- package/esm/tool/executable-as-tool.d.mts.map +1 -1
- package/esm/tool/executable-as-tool.mjs +2 -2
- package/esm/tool/executable-as-tool.mjs.map +1 -1
- package/esm/tool/tool.d.mts.map +1 -1
- package/esm/tool/tool.mjs +2 -2
- package/esm/tool/tool.mjs.map +1 -1
- package/esm/utils/compute-cost.d.mts +17 -1
- package/esm/utils/compute-cost.d.mts.map +1 -1
- package/esm/utils/compute-cost.mjs +26 -1
- package/esm/utils/compute-cost.mjs.map +1 -1
- package/esm/utils/extract-json-lenient.d.mts +42 -0
- package/esm/utils/extract-json-lenient.d.mts.map +1 -0
- package/esm/utils/extract-json-lenient.mjs +97 -0
- package/esm/utils/extract-json-lenient.mjs.map +1 -0
- package/esm/utils/index.d.mts +4 -2
- package/esm/utils/index.mjs +3 -1
- package/esm/utils/json-schema.d.mts +1 -1
- package/esm/utils/prepare-attachment-part.d.mts +10 -1
- package/esm/utils/prepare-attachment-part.d.mts.map +1 -1
- package/esm/utils/prepare-attachment-part.mjs +103 -11
- package/esm/utils/prepare-attachment-part.mjs.map +1 -1
- package/esm/utils/resolve-attachment.d.mts +4 -3
- package/esm/utils/resolve-attachment.d.mts.map +1 -1
- package/esm/utils/resolve-attachment.mjs +4 -3
- package/esm/utils/resolve-attachment.mjs.map +1 -1
- package/esm/utils/run-context.d.mts +94 -0
- package/esm/utils/run-context.d.mts.map +1 -0
- package/esm/utils/run-context.mjs +98 -0
- package/esm/utils/run-context.mjs.map +1 -0
- package/esm/vcr/cassette-io.mjs +57 -0
- package/esm/vcr/cassette-io.mjs.map +1 -0
- package/esm/vcr/errors.d.mts +42 -0
- package/esm/vcr/errors.d.mts.map +1 -0
- package/esm/vcr/errors.mjs +37 -0
- package/esm/vcr/errors.mjs.map +1 -0
- package/esm/vcr/hash-request.d.mts +28 -0
- package/esm/vcr/hash-request.d.mts.map +1 -0
- package/esm/vcr/hash-request.mjs +118 -0
- package/esm/vcr/hash-request.mjs.map +1 -0
- package/esm/vcr/index.d.mts +4 -0
- package/esm/vcr/index.mjs +5 -0
- package/esm/vcr/vcr.d.mts +32 -0
- package/esm/vcr/vcr.d.mts.map +1 -0
- package/esm/vcr/vcr.mjs +248 -0
- package/esm/vcr/vcr.mjs.map +1 -0
- package/esm/vcr/vcr.type.d.mts +118 -0
- package/esm/vcr/vcr.type.d.mts.map +1 -0
- package/esm/workflow/as-tool.mjs +2 -2
- package/esm/workflow/as-tool.mjs.map +1 -1
- package/esm/workflow/engine.mjs +1 -0
- package/esm/workflow/engine.mjs.map +1 -1
- package/esm/workflow/step-runner.mjs +19 -20
- package/esm/workflow/step-runner.mjs.map +1 -1
- package/esm/workflow/workflow.d.mts.map +1 -1
- package/esm/workflow/workflow.mjs +8 -3
- package/esm/workflow/workflow.mjs.map +1 -1
- package/llms-full.txt +1683 -68
- package/llms.txt +16 -4
- package/package.json +7 -3
- package/skills/README.md +40 -4
- package/skills/ai-dx-helpers/SKILL.md +2 -2
- package/skills/approve-tool-calls/SKILL.md +134 -0
- package/skills/attach-ai-middleware/SKILL.md +1 -1
- package/skills/detect-and-redact-pii/SKILL.md +104 -0
- package/skills/durable-resume/SKILL.md +128 -0
- package/skills/escalate-block-to-human/SKILL.md +85 -0
- package/skills/eval-datasets-and-ci/SKILL.md +117 -0
- package/skills/guard-input-output/SKILL.md +117 -0
- package/skills/manage-prompts/SKILL.md +186 -0
- package/skills/observe-ai-flows/SKILL.md +94 -0
- package/skills/record-replay-llm/SKILL.md +92 -0
- package/skills/run-ai-agent/SKILL.md +26 -1
- package/skills/run-ai-rag/SKILL.md +139 -0
- package/skills/run-ai-team/SKILL.md +107 -0
- package/skills/run-orchestrator/SKILL.md +2 -0
- package/skills/run-planner/SKILL.md +73 -8
- package/skills/run-supervisor/SKILL.md +20 -1
- package/skills/use-runtime-skills/SKILL.md +106 -0
- package/skills/write-system-prompt/SKILL.md +30 -1
- package/cjs/index.cjs.map +0 -1
- package/esm/contracts/result/index.d.mts +0 -15
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
import { InvalidRequestError } from "../errors/invalid-request-error.mjs";
|
|
2
|
+
import "../errors/index.mjs";
|
|
3
|
+
import { Instruction } from "../system-prompt/instruction.mjs";
|
|
4
|
+
import { Persona } from "../system-prompt/persona.mjs";
|
|
5
|
+
import { SystemPrompt } from "../system-prompt/system-prompt.mjs";
|
|
6
|
+
import { describeContractTarget, findMissingPlaceholders, findUnreferencedRequired, judgePromptBodyCached } from "./prompts-validate.mjs";
|
|
7
|
+
|
|
8
|
+
//#region ../@warlock.js/ai/src/prompts/prompts-manager.ts
|
|
9
|
+
/**
|
|
10
|
+
* Build the `name@version` registry key. Centralized so the duplicate check,
|
|
11
|
+
* `get`, and `composedFrom` provenance all agree on one label shape.
|
|
12
|
+
*/
|
|
13
|
+
function promptKey(name, version) {
|
|
14
|
+
return `${name}@${version}`;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Serialize a prompt's observable content — its ordered blocks (discriminator
|
|
18
|
+
* + raw template text) — into a stable signature. Two prompts with the same
|
|
19
|
+
* blocks in the same order share a signature, which is how `register()` tells
|
|
20
|
+
* an idempotent re-registration from a genuine clash. Meta is intentionally
|
|
21
|
+
* excluded: provenance / description should not defeat idempotency.
|
|
22
|
+
*/
|
|
23
|
+
function contentSignature(contract) {
|
|
24
|
+
return JSON.stringify(contract.blocks.map((block) => [block.type, block.text]));
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Reconstruct a block from its `{ type, text }` snapshot — `persona` blocks
|
|
28
|
+
* become a `Persona`, everything else an `Instruction`. The inverse of the
|
|
29
|
+
* flattening `export()` performs, so an imported registry resolves identically.
|
|
30
|
+
*/
|
|
31
|
+
function blockFromSnapshot(block) {
|
|
32
|
+
return block.type === "persona" ? new Persona(block.text) : new Instruction(block.text);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Narrow a {@link PromptTemplateVersion} body to its ordered block list: a raw
|
|
36
|
+
* string becomes one instruction block; an explicit block list is used verbatim.
|
|
37
|
+
*/
|
|
38
|
+
function blocksFromTemplate(template) {
|
|
39
|
+
if (typeof template === "string") return [new Instruction(template)];
|
|
40
|
+
return [...template];
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Concrete `PromptsManagerContract` — a single registry of named, versioned
|
|
44
|
+
* `SystemPromptContract` builders keyed by `name@version`.
|
|
45
|
+
*
|
|
46
|
+
* **Role.** The store behind `ai.prompts`. It holds one flat
|
|
47
|
+
* `Map<string, PromptsManagerEntry>` keyed by `name@version`, plus a monotonic
|
|
48
|
+
* counter that stamps each entry's `addedAt` so "latest" is deterministic
|
|
49
|
+
* (highest `addedAt` for a name) without ever reading the wall clock.
|
|
50
|
+
*
|
|
51
|
+
* **Responsibility.**
|
|
52
|
+
* - Owns: the registry map, the `addedAt` counter, the duplicate /
|
|
53
|
+
* idempotency rule, default version derivation, latest selection, the
|
|
54
|
+
* per-version tag pins, and the validate / diff / export / import surface.
|
|
55
|
+
* - Does NOT own: prompt rendering (delegated to the contract's `resolve()`),
|
|
56
|
+
* block composition, or the LLM-judge mechanics (delegated to the eval
|
|
57
|
+
* `judge` scorer via `prompts-validate`).
|
|
58
|
+
*
|
|
59
|
+
* Users construct via the `prompts()` factory — `new PromptsManager()` is not
|
|
60
|
+
* the public API.
|
|
61
|
+
*/
|
|
62
|
+
var PromptsManager = class {
|
|
63
|
+
constructor(options = {}) {
|
|
64
|
+
this.entries = /* @__PURE__ */ new Map();
|
|
65
|
+
this.names = [];
|
|
66
|
+
this.pins = /* @__PURE__ */ new Map();
|
|
67
|
+
this.counter = 0;
|
|
68
|
+
this.judgeCache = options.judgeCache;
|
|
69
|
+
}
|
|
70
|
+
register(contract, options = {}) {
|
|
71
|
+
const meta = contract.meta();
|
|
72
|
+
const name = options.name ?? meta?.name;
|
|
73
|
+
if (!name) throw new InvalidRequestError("Cannot register a prompt without a name — set meta.name via systemPrompt(input, { name }) or .meta({ name }).", { context: { meta } });
|
|
74
|
+
const version = options.version ?? meta?.version ?? this.nextVersion(name);
|
|
75
|
+
const key = promptKey(name, version);
|
|
76
|
+
const existing = this.entries.get(key);
|
|
77
|
+
if (existing) {
|
|
78
|
+
if (contentSignature(existing.contract) === contentSignature(contract)) return this;
|
|
79
|
+
throw new InvalidRequestError(`A different prompt is already registered as "${key}".`, { context: {
|
|
80
|
+
name,
|
|
81
|
+
version
|
|
82
|
+
} });
|
|
83
|
+
}
|
|
84
|
+
if (!this.names.includes(name)) this.names.push(name);
|
|
85
|
+
this.entries.set(key, {
|
|
86
|
+
name,
|
|
87
|
+
version,
|
|
88
|
+
addedAt: this.counter++,
|
|
89
|
+
contract,
|
|
90
|
+
...options.tags ? { tags: options.tags } : {}
|
|
91
|
+
});
|
|
92
|
+
return this;
|
|
93
|
+
}
|
|
94
|
+
create(input, meta) {
|
|
95
|
+
if (input === void 0) return new SystemPrompt([], meta);
|
|
96
|
+
if (typeof input === "string") return new SystemPrompt([new Instruction(input)], meta);
|
|
97
|
+
return new SystemPrompt([...input], meta);
|
|
98
|
+
}
|
|
99
|
+
get(name, versionOrTag) {
|
|
100
|
+
return this.requireEntry(name, versionOrTag).contract;
|
|
101
|
+
}
|
|
102
|
+
has(name, versionOrTag) {
|
|
103
|
+
const { baseName, selector } = this.parseSelector(name, versionOrTag);
|
|
104
|
+
if (selector !== void 0) return this.resolveSelector(baseName, selector) !== void 0;
|
|
105
|
+
return this.latestEntry(baseName) !== void 0;
|
|
106
|
+
}
|
|
107
|
+
list() {
|
|
108
|
+
return [...this.names];
|
|
109
|
+
}
|
|
110
|
+
versions(name) {
|
|
111
|
+
return [...this.entries.values()].filter((entry) => entry.name === name).sort((a, b) => a.addedAt - b.addedAt).map((entry) => entry.version);
|
|
112
|
+
}
|
|
113
|
+
resolve(name, versionOrTag, placeholders) {
|
|
114
|
+
return this.requireEntry(name, versionOrTag).contract.resolve(placeholders);
|
|
115
|
+
}
|
|
116
|
+
define(name, versions) {
|
|
117
|
+
for (const entry of versions) {
|
|
118
|
+
const contract = new SystemPrompt(blocksFromTemplate(entry.template));
|
|
119
|
+
this.register(contract, {
|
|
120
|
+
name,
|
|
121
|
+
version: entry.version
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
return this;
|
|
125
|
+
}
|
|
126
|
+
tag(name, tag, version) {
|
|
127
|
+
if (!this.entries.has(promptKey(name, version))) throw new InvalidRequestError(`Cannot tag "${tag}" — no prompt registered as "${promptKey(name, version)}".`, { context: {
|
|
128
|
+
name,
|
|
129
|
+
tag,
|
|
130
|
+
version
|
|
131
|
+
} });
|
|
132
|
+
const nameTags = this.pins.get(name) ?? /* @__PURE__ */ new Map();
|
|
133
|
+
nameTags.set(tag, version);
|
|
134
|
+
this.pins.set(name, nameTags);
|
|
135
|
+
return this;
|
|
136
|
+
}
|
|
137
|
+
async validate(target, options = {}) {
|
|
138
|
+
const { text, required } = this.describeTarget(target);
|
|
139
|
+
const missing = findMissingPlaceholders(text, new Set(Object.keys(options.placeholders ?? {})), new Set([...required, ...options.declare ?? []]));
|
|
140
|
+
const unreferenced = findUnreferencedRequired(text, required);
|
|
141
|
+
const ok = missing.length === 0;
|
|
142
|
+
if (!options.judge) {
|
|
143
|
+
if (unreferenced.length === 0) return {
|
|
144
|
+
ok,
|
|
145
|
+
missing
|
|
146
|
+
};
|
|
147
|
+
return {
|
|
148
|
+
ok,
|
|
149
|
+
missing,
|
|
150
|
+
issues: unreferenced.map((key) => `Required key "${key}" is never referenced in the prompt.`)
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
const cache = options.judgeCache ?? this.judgeCache;
|
|
154
|
+
const judgeOutcome = await judgePromptBodyCached(text, options.judge, cache);
|
|
155
|
+
const issues = [...unreferenced.map((key) => `Required key "${key}" is never referenced in the prompt.`), ...judgeOutcome.issues];
|
|
156
|
+
return {
|
|
157
|
+
ok,
|
|
158
|
+
missing,
|
|
159
|
+
...judgeOutcome.score !== void 0 ? { score: judgeOutcome.score } : {},
|
|
160
|
+
issues
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
diff(name, from, to) {
|
|
164
|
+
const fromBlocks = this.snapshotBlocks(this.requireExact(name, from));
|
|
165
|
+
const toBlocks = this.snapshotBlocks(this.requireExact(name, to));
|
|
166
|
+
const added = [];
|
|
167
|
+
const removed = [];
|
|
168
|
+
const changed = [];
|
|
169
|
+
const max = Math.max(fromBlocks.length, toBlocks.length);
|
|
170
|
+
for (let index = 0; index < max; index++) {
|
|
171
|
+
const left = fromBlocks[index];
|
|
172
|
+
const right = toBlocks[index];
|
|
173
|
+
if (left && !right) {
|
|
174
|
+
removed.push(left);
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
if (!left && right) {
|
|
178
|
+
added.push(right);
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
if (left && right && (left.type !== right.type || left.text !== right.text)) changed.push({
|
|
182
|
+
from: left,
|
|
183
|
+
to: right
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
return {
|
|
187
|
+
name,
|
|
188
|
+
from,
|
|
189
|
+
to,
|
|
190
|
+
added,
|
|
191
|
+
removed,
|
|
192
|
+
changed,
|
|
193
|
+
identical: added.length === 0 && removed.length === 0 && changed.length === 0
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
export() {
|
|
197
|
+
return { prompts: this.names.map((name) => ({
|
|
198
|
+
name,
|
|
199
|
+
versions: this.versions(name).map((version) => this.exportVersion(name, version))
|
|
200
|
+
})) };
|
|
201
|
+
}
|
|
202
|
+
import(snapshot) {
|
|
203
|
+
for (const exported of snapshot.prompts) for (const version of exported.versions) {
|
|
204
|
+
const contract = new SystemPrompt(version.blocks.map(blockFromSnapshot), {
|
|
205
|
+
...version.description ? { description: version.description } : {},
|
|
206
|
+
...version.required ? { required: version.required } : {}
|
|
207
|
+
});
|
|
208
|
+
this.register(contract, {
|
|
209
|
+
name: exported.name,
|
|
210
|
+
version: version.version
|
|
211
|
+
});
|
|
212
|
+
for (const tag of version.tags ?? []) this.tag(exported.name, tag, version.version);
|
|
213
|
+
}
|
|
214
|
+
return this;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Flatten a registered version into its portable `{ version, blocks, tags?,
|
|
218
|
+
* description?, required? }` snapshot for `export()`.
|
|
219
|
+
*/
|
|
220
|
+
exportVersion(name, version) {
|
|
221
|
+
const entry = this.requireExact(name, version);
|
|
222
|
+
const meta = entry.contract.meta();
|
|
223
|
+
const tags = this.tagsForVersion(name, version);
|
|
224
|
+
return {
|
|
225
|
+
version,
|
|
226
|
+
blocks: this.snapshotBlocks(entry),
|
|
227
|
+
...tags.length > 0 ? { tags } : {},
|
|
228
|
+
...meta?.description ? { description: meta.description } : {},
|
|
229
|
+
...meta?.required ? { required: [...meta.required] } : {}
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
/** Every tag currently pinned to a specific `name@version`, in pin order. */
|
|
233
|
+
tagsForVersion(name, version) {
|
|
234
|
+
const nameTags = this.pins.get(name);
|
|
235
|
+
if (!nameTags) return [];
|
|
236
|
+
const tags = [];
|
|
237
|
+
for (const [tag, pinnedVersion] of nameTags) if (pinnedVersion === version) tags.push(tag);
|
|
238
|
+
return tags;
|
|
239
|
+
}
|
|
240
|
+
/** Flatten an entry's blocks to `{ type, text }` snapshots. */
|
|
241
|
+
snapshotBlocks(entry) {
|
|
242
|
+
return entry.contract.blocks.map((block) => ({
|
|
243
|
+
type: block.type,
|
|
244
|
+
text: block.text
|
|
245
|
+
}));
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Resolve the body + declared-required keys for any `validate` target: a
|
|
249
|
+
* registered name (or `name@selector`), a `SystemPromptContract` instance, or
|
|
250
|
+
* a raw string.
|
|
251
|
+
*/
|
|
252
|
+
describeTarget(target) {
|
|
253
|
+
if (typeof target === "string") {
|
|
254
|
+
const { baseName, selector } = this.parseSelector(target, void 0);
|
|
255
|
+
const entry = selector ? this.resolveSelector(baseName, selector) : this.latestEntry(baseName);
|
|
256
|
+
if (entry) return describeContractTarget(entry.contract);
|
|
257
|
+
return {
|
|
258
|
+
text: target,
|
|
259
|
+
required: []
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
if (isSystemPromptContract(target)) return describeContractTarget(target);
|
|
263
|
+
if (isBlock(target)) return {
|
|
264
|
+
text: target.text,
|
|
265
|
+
required: []
|
|
266
|
+
};
|
|
267
|
+
throw new InvalidRequestError("validate() target must be a registered name, a SystemPromptContract, a prompt block, or a raw string.", { context: { target } });
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* The next integer version label for a name — `"1"` for the first, then the
|
|
271
|
+
* count of existing versions plus one. String-typed to match the free-form
|
|
272
|
+
* `version` label shape.
|
|
273
|
+
*/
|
|
274
|
+
nextVersion(name) {
|
|
275
|
+
const count = [...this.entries.values()].filter((entry) => entry.name === name).length;
|
|
276
|
+
return String(count + 1);
|
|
277
|
+
}
|
|
278
|
+
/** Pick the highest-`addedAt` entry for a name, or `undefined` when absent. */
|
|
279
|
+
latestEntry(name) {
|
|
280
|
+
let latest;
|
|
281
|
+
for (const entry of this.entries.values()) {
|
|
282
|
+
if (entry.name !== name) continue;
|
|
283
|
+
if (!latest || entry.addedAt > latest.addedAt) latest = entry;
|
|
284
|
+
}
|
|
285
|
+
return latest;
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Split a name argument into its base name + optional selector. The selector
|
|
289
|
+
* comes from the explicit second argument when present, else from an inline
|
|
290
|
+
* `name@selector` in the first argument. A bare name yields no selector.
|
|
291
|
+
*/
|
|
292
|
+
parseSelector(name, versionOrTag) {
|
|
293
|
+
if (versionOrTag !== void 0) return {
|
|
294
|
+
baseName: name,
|
|
295
|
+
selector: versionOrTag
|
|
296
|
+
};
|
|
297
|
+
const at = name.indexOf("@");
|
|
298
|
+
if (at > 0) return {
|
|
299
|
+
baseName: name.slice(0, at),
|
|
300
|
+
selector: name.slice(at + 1)
|
|
301
|
+
};
|
|
302
|
+
return {
|
|
303
|
+
baseName: name,
|
|
304
|
+
selector: void 0
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Resolve a selector (a version label OR a pinned tag) to a concrete entry.
|
|
309
|
+
* Version labels win over tags when both could match — the explicit label is
|
|
310
|
+
* the more specific intent. Returns `undefined` when neither resolves.
|
|
311
|
+
*/
|
|
312
|
+
resolveSelector(name, selector) {
|
|
313
|
+
const byVersion = this.entries.get(promptKey(name, selector));
|
|
314
|
+
if (byVersion) return byVersion;
|
|
315
|
+
const pinnedVersion = this.pins.get(name)?.get(selector);
|
|
316
|
+
if (pinnedVersion !== void 0) return this.entries.get(promptKey(name, pinnedVersion));
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Resolve an entry by name (+ optional version / tag / inline selector),
|
|
320
|
+
* throwing {@link InvalidRequestError} when the name or the requested
|
|
321
|
+
* selector is unknown. The single lookup path `get` / `resolve` share.
|
|
322
|
+
*/
|
|
323
|
+
requireEntry(name, versionOrTag) {
|
|
324
|
+
const { baseName, selector } = this.parseSelector(name, versionOrTag);
|
|
325
|
+
if (selector !== void 0) {
|
|
326
|
+
const entry = this.resolveSelector(baseName, selector);
|
|
327
|
+
if (!entry) throw new InvalidRequestError(`No prompt registered as "${baseName}" with version/tag "${selector}".`, { context: {
|
|
328
|
+
name: baseName,
|
|
329
|
+
selector
|
|
330
|
+
} });
|
|
331
|
+
return entry;
|
|
332
|
+
}
|
|
333
|
+
const latest = this.latestEntry(baseName);
|
|
334
|
+
if (!latest) throw new InvalidRequestError(`No prompt registered under name "${baseName}".`, { context: { name: baseName } });
|
|
335
|
+
return latest;
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Resolve a name + EXACT version label to its entry (no tag fallback), for
|
|
339
|
+
* `diff` / `export` where a concrete version is always required. Throws
|
|
340
|
+
* {@link InvalidRequestError} on a miss.
|
|
341
|
+
*/
|
|
342
|
+
requireExact(name, version) {
|
|
343
|
+
const entry = this.entries.get(promptKey(name, version));
|
|
344
|
+
if (!entry) throw new InvalidRequestError(`No prompt registered as "${promptKey(name, version)}".`, { context: {
|
|
345
|
+
name,
|
|
346
|
+
version
|
|
347
|
+
} });
|
|
348
|
+
return entry;
|
|
349
|
+
}
|
|
350
|
+
};
|
|
351
|
+
/**
|
|
352
|
+
* Narrow an arbitrary value to a `SystemPromptContract` — true when it exposes
|
|
353
|
+
* the builder surface (`blocks` array + a callable `resolve`) AND a callable
|
|
354
|
+
* `meta`. Robust across duplicate package copies (no `instanceof`).
|
|
355
|
+
*/
|
|
356
|
+
function isSystemPromptContract(value) {
|
|
357
|
+
return typeof value === "object" && value !== null && Array.isArray(value.blocks) && typeof value.resolve === "function" && typeof value.meta === "function";
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Narrow an arbitrary value to a single `SystemPromptBlockContract` — true when
|
|
361
|
+
* it carries a string `type` + `text` and a callable `resolve` but is NOT a
|
|
362
|
+
* full prompt (no `blocks` array). Lets `validate` accept a lone block.
|
|
363
|
+
*/
|
|
364
|
+
function isBlock(value) {
|
|
365
|
+
return typeof value === "object" && value !== null && typeof value.type === "string" && typeof value.text === "string" && typeof value.resolve === "function";
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Create a new, isolated prompts manager.
|
|
369
|
+
*
|
|
370
|
+
* **Role.** Public factory for {@link PromptsManagerContract} — keeps
|
|
371
|
+
* user-facing code free of `new` and consistent with the other `ai.*`
|
|
372
|
+
* factories. Each call returns a fresh registry, so parallel test suites and
|
|
373
|
+
* multi-tenant apps never share mutable global prompt state.
|
|
374
|
+
*
|
|
375
|
+
* The process-wide instance that named `systemPrompt(...)` builders
|
|
376
|
+
* auto-register into is `ai.prompts` (see {@link defaultPromptsManager}).
|
|
377
|
+
*
|
|
378
|
+
* @param options - Optional wiring, notably a `judgeCache` that memoizes
|
|
379
|
+
* LLM-judge verdicts (absent ⇒ every judge pass runs live).
|
|
380
|
+
*
|
|
381
|
+
* @example
|
|
382
|
+
* const registry = prompts();
|
|
383
|
+
* registry.register(systemPrompt("You are support.", { name: "support" }));
|
|
384
|
+
* registry.resolve("support"); // "You are support."
|
|
385
|
+
*
|
|
386
|
+
* @example
|
|
387
|
+
* // Memoize judge verdicts across validations.
|
|
388
|
+
* const registry = prompts({ judgeCache: new MemoryCacheDriver() });
|
|
389
|
+
*/
|
|
390
|
+
function prompts(options) {
|
|
391
|
+
return new PromptsManager(options);
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* The process-wide default manager that named prompts auto-register into.
|
|
395
|
+
*
|
|
396
|
+
* Held as a module-level singleton (lazily created on first access) so
|
|
397
|
+
* `system-prompt.ts` can register a named builder without importing the
|
|
398
|
+
* `PromptsManager` class — keeping the auto-registration seam free of a
|
|
399
|
+
* runtime import cycle.
|
|
400
|
+
*/
|
|
401
|
+
let defaultManager;
|
|
402
|
+
/** Accessor for the process-wide default {@link PromptsManagerContract}. */
|
|
403
|
+
function defaultPromptsManager() {
|
|
404
|
+
if (!defaultManager) defaultManager = new PromptsManager();
|
|
405
|
+
return defaultManager;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
//#endregion
|
|
409
|
+
export { defaultPromptsManager, promptKey, prompts };
|
|
410
|
+
//# sourceMappingURL=prompts-manager.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompts-manager.mjs","names":[],"sources":["../../../../../../../@warlock.js/ai/src/prompts/prompts-manager.ts"],"sourcesContent":["import type { Placeholders } from \"../contracts/placeholders.type\";\nimport type {\n SystemPromptBlockContract,\n SystemPromptContract,\n SystemPromptMeta,\n} from \"../contracts/system-prompt.contract\";\nimport { InvalidRequestError } from \"../errors\";\nimport { Instruction } from \"../system-prompt/instruction\";\nimport { Persona } from \"../system-prompt/persona\";\nimport { SystemPrompt } from \"../system-prompt/system-prompt\";\nimport type {\n PromptsManagerContract,\n PromptsManagerEntry,\n PromptsManagerRegisterOptions,\n} from \"./prompts-manager.contract\";\nimport type {\n ExportedPromptVersion,\n ExportedRegistry,\n PromptDiff,\n PromptDiffBlock,\n PromptJudgeCacheLike,\n PromptsManagerOptions,\n PromptTemplateVersion,\n PromptValidateTarget,\n PromptValidationResult,\n PromptsValidateOptions,\n} from \"./prompts-manager.type\";\nimport {\n describeContractTarget,\n findMissingPlaceholders,\n findUnreferencedRequired,\n judgePromptBodyCached,\n} from \"./prompts-validate\";\n\n/**\n * Build the `name@version` registry key. Centralized so the duplicate check,\n * `get`, and `composedFrom` provenance all agree on one label shape.\n */\nexport function promptKey(name: string, version: string): string {\n return `${name}@${version}`;\n}\n\n/**\n * Serialize a prompt's observable content — its ordered blocks (discriminator\n * + raw template text) — into a stable signature. Two prompts with the same\n * blocks in the same order share a signature, which is how `register()` tells\n * an idempotent re-registration from a genuine clash. Meta is intentionally\n * excluded: provenance / description should not defeat idempotency.\n */\nfunction contentSignature(contract: SystemPromptContract): string {\n return JSON.stringify(\n contract.blocks.map(block => [block.type, block.text]),\n );\n}\n\n/**\n * Reconstruct a block from its `{ type, text }` snapshot — `persona` blocks\n * become a `Persona`, everything else an `Instruction`. The inverse of the\n * flattening `export()` performs, so an imported registry resolves identically.\n */\nfunction blockFromSnapshot(block: PromptDiffBlock): SystemPromptBlockContract {\n return block.type === \"persona\"\n ? new Persona(block.text)\n : new Instruction(block.text);\n}\n\n/**\n * Narrow a {@link PromptTemplateVersion} body to its ordered block list: a raw\n * string becomes one instruction block; an explicit block list is used verbatim.\n */\nfunction blocksFromTemplate(\n template: string | readonly SystemPromptBlockContract[],\n): SystemPromptBlockContract[] {\n if (typeof template === \"string\") {\n return [new Instruction(template)];\n }\n\n return [...template];\n}\n\n/**\n * Concrete `PromptsManagerContract` — a single registry of named, versioned\n * `SystemPromptContract` builders keyed by `name@version`.\n *\n * **Role.** The store behind `ai.prompts`. It holds one flat\n * `Map<string, PromptsManagerEntry>` keyed by `name@version`, plus a monotonic\n * counter that stamps each entry's `addedAt` so \"latest\" is deterministic\n * (highest `addedAt` for a name) without ever reading the wall clock.\n *\n * **Responsibility.**\n * - Owns: the registry map, the `addedAt` counter, the duplicate /\n * idempotency rule, default version derivation, latest selection, the\n * per-version tag pins, and the validate / diff / export / import surface.\n * - Does NOT own: prompt rendering (delegated to the contract's `resolve()`),\n * block composition, or the LLM-judge mechanics (delegated to the eval\n * `judge` scorer via `prompts-validate`).\n *\n * Users construct via the `prompts()` factory — `new PromptsManager()` is not\n * the public API.\n */\nclass PromptsManager implements PromptsManagerContract {\n /** Flat registry keyed by `name@version`. */\n private readonly entries = new Map<string, PromptsManagerEntry>();\n\n /** First-seen order of names, for a stable `list()`. */\n private readonly names: string[] = [];\n\n /** Per-name tag pins: `name` → (`tag` → `version`). */\n private readonly pins = new Map<string, Map<string, string>>();\n\n /** Optional process-level judge-verdict memo (absent ⇒ judge always runs live). */\n private readonly judgeCache?: PromptJudgeCacheLike;\n\n /** Monotonic insertion counter — the deterministic stand-in for a timestamp. */\n private counter = 0;\n\n public constructor(options: PromptsManagerOptions = {}) {\n this.judgeCache = options.judgeCache;\n }\n\n public register(\n contract: SystemPromptContract,\n options: PromptsManagerRegisterOptions = {},\n ): PromptsManagerContract {\n const meta = contract.meta();\n // An explicit override (from define() / import()) wins over the contract's\n // own meta — it lets those bulk paths register an anonymous contract under\n // a name without the SystemPrompt constructor's default-manager auto-reg.\n const name = options.name ?? meta?.name;\n\n if (!name) {\n throw new InvalidRequestError(\n \"Cannot register a prompt without a name — set meta.name via \" +\n \"systemPrompt(input, { name }) or .meta({ name }).\",\n { context: { meta } },\n );\n }\n\n const version =\n options.version ?? meta?.version ?? this.nextVersion(name);\n const key = promptKey(name, version);\n const existing = this.entries.get(key);\n\n if (existing) {\n // Idempotent re-registration: identical content under the same\n // name@version is a no-op, not an error. Anything else is a clash.\n if (contentSignature(existing.contract) === contentSignature(contract)) {\n return this;\n }\n\n throw new InvalidRequestError(\n `A different prompt is already registered as \"${key}\".`,\n { context: { name, version } },\n );\n }\n\n if (!this.names.includes(name)) {\n this.names.push(name);\n }\n\n this.entries.set(key, {\n name,\n version,\n addedAt: this.counter++,\n contract,\n ...(options.tags ? { tags: options.tags } : {}),\n });\n\n return this;\n }\n\n public create(\n input?: string | ReadonlyArray<SystemPromptBlockContract>,\n meta?: SystemPromptMeta,\n ): SystemPromptContract {\n // Mirror `systemPromptFactory` exactly (no import — `system-prompt.ts`\n // already depends on this module, so importing its factory back here would\n // close an import cycle). A name in `meta` auto-registers into the\n // process-wide default manager via the SystemPrompt constructor.\n if (input === undefined) {\n return new SystemPrompt([], meta);\n }\n\n if (typeof input === \"string\") {\n return new SystemPrompt([new Instruction(input)], meta);\n }\n\n return new SystemPrompt([...input], meta);\n }\n\n public get(name: string, versionOrTag?: string): SystemPromptContract {\n return this.requireEntry(name, versionOrTag).contract;\n }\n\n public has(name: string, versionOrTag?: string): boolean {\n const { baseName, selector } = this.parseSelector(name, versionOrTag);\n\n if (selector !== undefined) {\n return this.resolveSelector(baseName, selector) !== undefined;\n }\n\n return this.latestEntry(baseName) !== undefined;\n }\n\n public list(): string[] {\n return [...this.names];\n }\n\n public versions(name: string): string[] {\n return [...this.entries.values()]\n .filter(entry => entry.name === name)\n .sort((a, b) => a.addedAt - b.addedAt)\n .map(entry => entry.version);\n }\n\n public resolve(\n name: string,\n versionOrTag?: string,\n placeholders?: Placeholders,\n ): string {\n return this.requireEntry(name, versionOrTag).contract.resolve(placeholders);\n }\n\n public define(\n name: string,\n versions: readonly PromptTemplateVersion[],\n ): PromptsManagerContract {\n for (const entry of versions) {\n const blocks = blocksFromTemplate(entry.template);\n // Anonymous contract (no name in meta ⇒ no SystemPrompt constructor\n // auto-registration into the default manager); the name/version are\n // supplied explicitly so define() targets only THIS manager.\n const contract = new SystemPrompt(blocks);\n\n this.register(contract, { name, version: entry.version });\n }\n\n return this;\n }\n\n public tag(\n name: string,\n tag: string,\n version: string,\n ): PromptsManagerContract {\n // Validate the target exists before pinning — a tag to a missing version is\n // an authoring mistake, not a silent dangling pin.\n if (!this.entries.has(promptKey(name, version))) {\n throw new InvalidRequestError(\n `Cannot tag \"${tag}\" — no prompt registered as \"${promptKey(\n name,\n version,\n )}\".`,\n { context: { name, tag, version } },\n );\n }\n\n const nameTags = this.pins.get(name) ?? new Map<string, string>();\n nameTags.set(tag, version);\n this.pins.set(name, nameTags);\n\n return this;\n }\n\n public async validate(\n target: PromptValidateTarget,\n options: PromptsValidateOptions = {},\n ): Promise<PromptValidationResult> {\n const { text, required } = this.describeTarget(target);\n\n const provided = new Set(Object.keys(options.placeholders ?? {}));\n const declared = new Set<string>([\n ...required,\n ...(options.declare ?? []),\n ]);\n\n const missing = findMissingPlaceholders(text, provided, declared);\n\n // A declared-required key that the body never references is itself a\n // defect — surface it as an issue (it does not affect `missing` / `ok`,\n // which track unresolved placeholders).\n const unreferenced = findUnreferencedRequired(text, required);\n\n const ok = missing.length === 0;\n\n if (!options.judge) {\n if (unreferenced.length === 0) {\n return { ok, missing };\n }\n\n return {\n ok,\n missing,\n issues: unreferenced.map(\n key => `Required key \"${key}\" is never referenced in the prompt.`,\n ),\n };\n }\n\n // Per-call cache override wins over the manager-level memo.\n const cache = options.judgeCache ?? this.judgeCache;\n const judgeOutcome = await judgePromptBodyCached(text, options.judge, cache);\n\n const issues = [\n ...unreferenced.map(\n key => `Required key \"${key}\" is never referenced in the prompt.`,\n ),\n ...judgeOutcome.issues,\n ];\n\n return {\n ok,\n missing,\n ...(judgeOutcome.score !== undefined ? { score: judgeOutcome.score } : {}),\n issues,\n };\n }\n\n public diff(name: string, from: string, to: string): PromptDiff {\n const fromBlocks = this.snapshotBlocks(this.requireExact(name, from));\n const toBlocks = this.snapshotBlocks(this.requireExact(name, to));\n\n const added: PromptDiffBlock[] = [];\n const removed: PromptDiffBlock[] = [];\n const changed: { from: PromptDiffBlock; to: PromptDiffBlock }[] = [];\n\n const max = Math.max(fromBlocks.length, toBlocks.length);\n\n for (let index = 0; index < max; index++) {\n const left = fromBlocks[index];\n const right = toBlocks[index];\n\n if (left && !right) {\n removed.push(left);\n continue;\n }\n\n if (!left && right) {\n added.push(right);\n continue;\n }\n\n if (left && right && (left.type !== right.type || left.text !== right.text)) {\n changed.push({ from: left, to: right });\n }\n }\n\n return {\n name,\n from,\n to,\n added,\n removed,\n changed,\n identical:\n added.length === 0 && removed.length === 0 && changed.length === 0,\n };\n }\n\n public export(): ExportedRegistry {\n return {\n prompts: this.names.map(name => ({\n name,\n versions: this.versions(name).map(version =>\n this.exportVersion(name, version),\n ),\n })),\n };\n }\n\n public import(snapshot: ExportedRegistry): PromptsManagerContract {\n for (const exported of snapshot.prompts) {\n for (const version of exported.versions) {\n const blocks = version.blocks.map(blockFromSnapshot);\n // Anonymous (no `name` in meta) so the SystemPrompt constructor does\n // not auto-register into the default manager; description / required\n // ride along for round-trip fidelity. Name/version are explicit so the\n // import lands only on THIS manager.\n const contract = new SystemPrompt(blocks, {\n ...(version.description ? { description: version.description } : {}),\n ...(version.required ? { required: version.required } : {}),\n });\n\n this.register(contract, {\n name: exported.name,\n version: version.version,\n });\n\n for (const tag of version.tags ?? []) {\n this.tag(exported.name, tag, version.version);\n }\n }\n }\n\n return this;\n }\n\n /**\n * Flatten a registered version into its portable `{ version, blocks, tags?,\n * description?, required? }` snapshot for `export()`.\n */\n private exportVersion(name: string, version: string): ExportedPromptVersion {\n const entry = this.requireExact(name, version);\n const meta = entry.contract.meta();\n const tags = this.tagsForVersion(name, version);\n\n return {\n version,\n blocks: this.snapshotBlocks(entry),\n ...(tags.length > 0 ? { tags } : {}),\n ...(meta?.description ? { description: meta.description } : {}),\n ...(meta?.required ? { required: [...meta.required] } : {}),\n };\n }\n\n /** Every tag currently pinned to a specific `name@version`, in pin order. */\n private tagsForVersion(name: string, version: string): string[] {\n const nameTags = this.pins.get(name);\n\n if (!nameTags) {\n return [];\n }\n\n const tags: string[] = [];\n\n for (const [tag, pinnedVersion] of nameTags) {\n if (pinnedVersion === version) {\n tags.push(tag);\n }\n }\n\n return tags;\n }\n\n /** Flatten an entry's blocks to `{ type, text }` snapshots. */\n private snapshotBlocks(entry: PromptsManagerEntry): PromptDiffBlock[] {\n return entry.contract.blocks.map(block => ({\n type: block.type,\n text: block.text,\n }));\n }\n\n /**\n * Resolve the body + declared-required keys for any `validate` target: a\n * registered name (or `name@selector`), a `SystemPromptContract` instance, or\n * a raw string.\n */\n private describeTarget(target: PromptValidateTarget): {\n text: string;\n required: readonly string[];\n } {\n if (typeof target === \"string\") {\n // An inline `name@selector` (or a bare registered name) resolves through\n // the registry; anything else is a raw prompt body validated verbatim.\n const { baseName, selector } = this.parseSelector(target, undefined);\n const entry = selector\n ? this.resolveSelector(baseName, selector)\n : this.latestEntry(baseName);\n\n if (entry) {\n return describeContractTarget(entry.contract);\n }\n\n return { text: target, required: [] };\n }\n\n if (isSystemPromptContract(target)) {\n return describeContractTarget(target);\n }\n\n if (isBlock(target)) {\n return { text: target.text, required: [] };\n }\n\n throw new InvalidRequestError(\n \"validate() target must be a registered name, a SystemPromptContract, \" +\n \"a prompt block, or a raw string.\",\n { context: { target } },\n );\n }\n\n /**\n * The next integer version label for a name — `\"1\"` for the first, then the\n * count of existing versions plus one. String-typed to match the free-form\n * `version` label shape.\n */\n private nextVersion(name: string): string {\n const count = [...this.entries.values()].filter(\n entry => entry.name === name,\n ).length;\n\n return String(count + 1);\n }\n\n /** Pick the highest-`addedAt` entry for a name, or `undefined` when absent. */\n private latestEntry(name: string): PromptsManagerEntry | undefined {\n let latest: PromptsManagerEntry | undefined;\n\n for (const entry of this.entries.values()) {\n if (entry.name !== name) {\n continue;\n }\n\n if (!latest || entry.addedAt > latest.addedAt) {\n latest = entry;\n }\n }\n\n return latest;\n }\n\n /**\n * Split a name argument into its base name + optional selector. The selector\n * comes from the explicit second argument when present, else from an inline\n * `name@selector` in the first argument. A bare name yields no selector.\n */\n private parseSelector(\n name: string,\n versionOrTag: string | undefined,\n ): { baseName: string; selector: string | undefined } {\n if (versionOrTag !== undefined) {\n return { baseName: name, selector: versionOrTag };\n }\n\n const at = name.indexOf(\"@\");\n\n if (at > 0) {\n return { baseName: name.slice(0, at), selector: name.slice(at + 1) };\n }\n\n return { baseName: name, selector: undefined };\n }\n\n /**\n * Resolve a selector (a version label OR a pinned tag) to a concrete entry.\n * Version labels win over tags when both could match — the explicit label is\n * the more specific intent. Returns `undefined` when neither resolves.\n */\n private resolveSelector(\n name: string,\n selector: string,\n ): PromptsManagerEntry | undefined {\n const byVersion = this.entries.get(promptKey(name, selector));\n\n if (byVersion) {\n return byVersion;\n }\n\n const pinnedVersion = this.pins.get(name)?.get(selector);\n\n if (pinnedVersion !== undefined) {\n return this.entries.get(promptKey(name, pinnedVersion));\n }\n\n return undefined;\n }\n\n /**\n * Resolve an entry by name (+ optional version / tag / inline selector),\n * throwing {@link InvalidRequestError} when the name or the requested\n * selector is unknown. The single lookup path `get` / `resolve` share.\n */\n private requireEntry(\n name: string,\n versionOrTag?: string,\n ): PromptsManagerEntry {\n const { baseName, selector } = this.parseSelector(name, versionOrTag);\n\n if (selector !== undefined) {\n const entry = this.resolveSelector(baseName, selector);\n\n if (!entry) {\n throw new InvalidRequestError(\n `No prompt registered as \"${baseName}\" with version/tag \"${selector}\".`,\n { context: { name: baseName, selector } },\n );\n }\n\n return entry;\n }\n\n const latest = this.latestEntry(baseName);\n\n if (!latest) {\n throw new InvalidRequestError(\n `No prompt registered under name \"${baseName}\".`,\n { context: { name: baseName } },\n );\n }\n\n return latest;\n }\n\n /**\n * Resolve a name + EXACT version label to its entry (no tag fallback), for\n * `diff` / `export` where a concrete version is always required. Throws\n * {@link InvalidRequestError} on a miss.\n */\n private requireExact(name: string, version: string): PromptsManagerEntry {\n const entry = this.entries.get(promptKey(name, version));\n\n if (!entry) {\n throw new InvalidRequestError(\n `No prompt registered as \"${promptKey(name, version)}\".`,\n { context: { name, version } },\n );\n }\n\n return entry;\n }\n}\n\n/**\n * Narrow an arbitrary value to a `SystemPromptContract` — true when it exposes\n * the builder surface (`blocks` array + a callable `resolve`) AND a callable\n * `meta`. Robust across duplicate package copies (no `instanceof`).\n */\nfunction isSystemPromptContract(\n value: unknown,\n): value is SystemPromptContract {\n return (\n typeof value === \"object\" &&\n value !== null &&\n Array.isArray((value as { blocks?: unknown }).blocks) &&\n typeof (value as { resolve?: unknown }).resolve === \"function\" &&\n typeof (value as { meta?: unknown }).meta === \"function\"\n );\n}\n\n/**\n * Narrow an arbitrary value to a single `SystemPromptBlockContract` — true when\n * it carries a string `type` + `text` and a callable `resolve` but is NOT a\n * full prompt (no `blocks` array). Lets `validate` accept a lone block.\n */\nfunction isBlock(value: unknown): value is SystemPromptBlockContract {\n return (\n typeof value === \"object\" &&\n value !== null &&\n typeof (value as { type?: unknown }).type === \"string\" &&\n typeof (value as { text?: unknown }).text === \"string\" &&\n typeof (value as { resolve?: unknown }).resolve === \"function\"\n );\n}\n\n/**\n * Create a new, isolated prompts manager.\n *\n * **Role.** Public factory for {@link PromptsManagerContract} — keeps\n * user-facing code free of `new` and consistent with the other `ai.*`\n * factories. Each call returns a fresh registry, so parallel test suites and\n * multi-tenant apps never share mutable global prompt state.\n *\n * The process-wide instance that named `systemPrompt(...)` builders\n * auto-register into is `ai.prompts` (see {@link defaultPromptsManager}).\n *\n * @param options - Optional wiring, notably a `judgeCache` that memoizes\n * LLM-judge verdicts (absent ⇒ every judge pass runs live).\n *\n * @example\n * const registry = prompts();\n * registry.register(systemPrompt(\"You are support.\", { name: \"support\" }));\n * registry.resolve(\"support\"); // \"You are support.\"\n *\n * @example\n * // Memoize judge verdicts across validations.\n * const registry = prompts({ judgeCache: new MemoryCacheDriver() });\n */\nexport function prompts(options?: PromptsManagerOptions): PromptsManagerContract {\n return new PromptsManager(options);\n}\n\n/**\n * The process-wide default manager that named prompts auto-register into.\n *\n * Held as a module-level singleton (lazily created on first access) so\n * `system-prompt.ts` can register a named builder without importing the\n * `PromptsManager` class — keeping the auto-registration seam free of a\n * runtime import cycle.\n */\nlet defaultManager: PromptsManagerContract | undefined;\n\n/** Accessor for the process-wide default {@link PromptsManagerContract}. */\nexport function defaultPromptsManager(): PromptsManagerContract {\n if (!defaultManager) {\n defaultManager = new PromptsManager();\n }\n\n return defaultManager;\n}\n"],"mappings":";;;;;;;;;;;;AAsCA,SAAgB,UAAU,MAAc,SAAyB;CAC/D,OAAO,GAAG,KAAK,GAAG;AACpB;;;;;;;;AASA,SAAS,iBAAiB,UAAwC;CAChE,OAAO,KAAK,UACV,SAAS,OAAO,KAAI,UAAS,CAAC,MAAM,MAAM,MAA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,KACpE,EAAE,SAAS;IAAE,MAAM;IAAU;GAAS,EAAE,CAC1C;GAGF,OAAO;EACT;EAEA,MAAM,SAAS,KAAK,YAAY,QAAQ;EAExC,IAAI,CAAC,QACH,MAAM,IAAI,oBACR,oCAAoC,SAAS,KAC7C,EAAE,SAAS,EAAE,MAAM,SAAS,EAAE,CAChC;EAGF,OAAO;CACT;;;;;;CAOA,AAAQ,aAAa,MAAc,SAAsC;EACvE,MAAM,QAAQ,KAAK,QAAQ,IAAI,UAAU,MAAM,OAAO,CAAC;EAEvD,IAAI,CAAC,OACH,MAAM,IAAI,oBACR,4BAA4B,UAAU,MAAM,OAAO,EAAE,KACrD,EAAE,SAAS;GAAE;GAAM;EAAQ,EAAE,CAC/B;EAGF,OAAO;CACT;AACF;;;;;;AAOA,SAAS,uBACP,OAC+B;CAC/B,OACE,OAAO,UAAU,YACjB,UAAU,QACV,MAAM,QAAS,MAA+B,MAAM,KACpD,OAAQ,MAAgC,YAAY,cACpD,OAAQ,MAA6B,SAAS;AAElD;;;;;;AAOA,SAAS,QAAQ,OAAoD;CACnE,OACE,OAAO,UAAU,YACjB,UAAU,QACV,OAAQ,MAA6B,SAAS,YAC9C,OAAQ,MAA6B,SAAS,YAC9C,OAAQ,MAAgC,YAAY;AAExD;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,SAAgB,QAAQ,SAAyD;CAC/E,OAAO,IAAI,eAAe,OAAO;AACnC;;;;;;;;;AAUA,IAAI;;AAGJ,SAAgB,wBAAgD;CAC9D,IAAI,CAAC,gBACH,iBAAiB,IAAI,eAAe;CAGtC,OAAO;AACT"}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { ModelContract } from "../contracts/model.contract.mjs";
|
|
2
|
+
import { Placeholders } from "../contracts/placeholders.type.mjs";
|
|
3
|
+
import { SystemPromptBlockContract } from "../contracts/system-prompt.contract.mjs";
|
|
4
|
+
|
|
5
|
+
//#region ../@warlock.js/ai/src/prompts/prompts-manager.type.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* The minimal cache surface the judge-verdict memo needs — a structural subset
|
|
8
|
+
* of `@warlock.js/cache`'s `CacheDriver` (`get` / `set`). Typed structurally
|
|
9
|
+
* (not imported) so `@warlock.js/cache` stays a strictly OPTIONAL peer: a
|
|
10
|
+
* consumer that never validates with a judge never needs the cache package.
|
|
11
|
+
* Any `CacheDriver` instance satisfies this.
|
|
12
|
+
*/
|
|
13
|
+
interface PromptJudgeCacheLike {
|
|
14
|
+
/** Read a cached value, or `null` on a miss. */
|
|
15
|
+
get<T = unknown>(key: string): Promise<T | null>;
|
|
16
|
+
/** Write a value (TTL / options ignored by this memo path). */
|
|
17
|
+
set(key: string, value: unknown, ttlOrOptions?: unknown): Promise<unknown>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Options for the `prompts(options?)` factory.
|
|
21
|
+
*/
|
|
22
|
+
interface PromptsManagerOptions {
|
|
23
|
+
/**
|
|
24
|
+
* Optional cache that memoizes LLM-judge verdicts. Keyed by a content hash of
|
|
25
|
+
* the resolved prompt body + the judge model's id, so a re-validation of the
|
|
26
|
+
* same prompt with the same judge skips the model call. Absent ⇒ every judge
|
|
27
|
+
* pass runs live (a pure no-op seam — `@warlock.js/cache` stays optional).
|
|
28
|
+
*/
|
|
29
|
+
readonly judgeCache?: PromptJudgeCacheLike;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* What {@link PromptsManagerContract.validate} accepts as its target:
|
|
33
|
+
* - a registered prompt **name** (resolved to its latest version, or a tagged /
|
|
34
|
+
* `name@version` selector — same syntax `get` accepts);
|
|
35
|
+
* - a `SystemPromptContract` instance (named or anonymous);
|
|
36
|
+
* - a raw prompt **string** (validated verbatim, no registry lookup).
|
|
37
|
+
*/
|
|
38
|
+
type PromptValidateTarget = string | SystemPromptBlockContract | object;
|
|
39
|
+
/**
|
|
40
|
+
* Options for {@link PromptsManagerContract.validate}.
|
|
41
|
+
*/
|
|
42
|
+
interface PromptsValidateOptions {
|
|
43
|
+
/**
|
|
44
|
+
* Placeholder values the caller intends to supply at resolve time. Any
|
|
45
|
+
* `{{key}}` present in these (or carrying an inline default, or declared in
|
|
46
|
+
* `meta.required`) is NOT reported as missing.
|
|
47
|
+
*/
|
|
48
|
+
readonly placeholders?: Placeholders;
|
|
49
|
+
/**
|
|
50
|
+
* Extra placeholder keys to treat as known/declared (beyond the prompt's own
|
|
51
|
+
* `meta.required`). A key listed here is never reported missing.
|
|
52
|
+
*/
|
|
53
|
+
readonly declare?: readonly string[];
|
|
54
|
+
/**
|
|
55
|
+
* Optional model that powers the LLM-as-judge quality pass. When omitted,
|
|
56
|
+
* `validate` runs the deterministic placeholder check only and returns no
|
|
57
|
+
* `score`. The judge is Nova-safe — it never throws and degrades to an
|
|
58
|
+
* `issues` note (leaving `score` undefined) on any failure.
|
|
59
|
+
*/
|
|
60
|
+
readonly judge?: ModelContract;
|
|
61
|
+
/**
|
|
62
|
+
* Per-call judge-verdict cache override. When set, takes precedence over the
|
|
63
|
+
* manager's `judgeCache` for this call only. Same memo semantics: only used
|
|
64
|
+
* when `judge` is also supplied.
|
|
65
|
+
*/
|
|
66
|
+
readonly judgeCache?: PromptJudgeCacheLike;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Unified result of {@link PromptsManagerContract.validate}.
|
|
70
|
+
*
|
|
71
|
+
* `ok` is the deterministic verdict alone — `true` iff no required placeholder
|
|
72
|
+
* is missing. The optional LLM-judge `score` / `issues` are advisory and never
|
|
73
|
+
* flip `ok`, so a flaky judge can't fail an otherwise-valid prompt.
|
|
74
|
+
*/
|
|
75
|
+
interface PromptValidationResult {
|
|
76
|
+
/** `true` when no required placeholder is missing (deterministic verdict). */
|
|
77
|
+
readonly ok: boolean;
|
|
78
|
+
/** Placeholder keys referenced with no default, unsupplied and undeclared. */
|
|
79
|
+
readonly missing: string[];
|
|
80
|
+
/**
|
|
81
|
+
* LLM-judge quality score in `[0, 1]`. Present only when a `judge` model was
|
|
82
|
+
* supplied AND the judge produced a usable verdict; `undefined` when no judge
|
|
83
|
+
* ran or the judge degraded.
|
|
84
|
+
*/
|
|
85
|
+
readonly score?: number;
|
|
86
|
+
/**
|
|
87
|
+
* Advisory findings — the judge's reason(s) and/or a degrade note. Present
|
|
88
|
+
* (possibly empty) only when a `judge` model was supplied.
|
|
89
|
+
*/
|
|
90
|
+
readonly issues?: string[];
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* One version in a bulk {@link PromptsManagerContract.define} call (or a
|
|
94
|
+
* `.templates([...])` builder call): a version label plus its body, given
|
|
95
|
+
* either as a raw string (wrapped into a single instruction block) or as an
|
|
96
|
+
* explicit ordered list of blocks (used verbatim).
|
|
97
|
+
*/
|
|
98
|
+
interface PromptTemplateVersion {
|
|
99
|
+
/** Version label, e.g. `"1"`, `"2"`, `"2025-draft"`. */
|
|
100
|
+
readonly version: string;
|
|
101
|
+
/**
|
|
102
|
+
* The version body. A string becomes one instruction block; an array of
|
|
103
|
+
* blocks is registered verbatim, preserving order.
|
|
104
|
+
*/
|
|
105
|
+
readonly template: string | readonly SystemPromptBlockContract[];
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* One block in a {@link PromptDiff} — its discriminator and raw text, so a diff
|
|
109
|
+
* is comparable without resolving placeholders.
|
|
110
|
+
*/
|
|
111
|
+
interface PromptDiffBlock {
|
|
112
|
+
/** Block discriminator (`"persona"` / `"instruction"` / …). */
|
|
113
|
+
readonly type: string;
|
|
114
|
+
/** Raw template text. */
|
|
115
|
+
readonly text: string;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Block-level diff between two registered versions of a prompt, returned by
|
|
119
|
+
* {@link PromptsManagerContract.diff}. Blocks are matched positionally.
|
|
120
|
+
*/
|
|
121
|
+
interface PromptDiff {
|
|
122
|
+
/** The prompt name diffed. */
|
|
123
|
+
readonly name: string;
|
|
124
|
+
/** The left/from version label. */
|
|
125
|
+
readonly from: string;
|
|
126
|
+
/** The right/to version label. */
|
|
127
|
+
readonly to: string;
|
|
128
|
+
/** Blocks present in `to` but not at the same position in `from`. */
|
|
129
|
+
readonly added: PromptDiffBlock[];
|
|
130
|
+
/** Blocks present in `from` but not at the same position in `to`. */
|
|
131
|
+
readonly removed: PromptDiffBlock[];
|
|
132
|
+
/** Blocks at the same position whose `type` or `text` changed. */
|
|
133
|
+
readonly changed: {
|
|
134
|
+
from: PromptDiffBlock;
|
|
135
|
+
to: PromptDiffBlock;
|
|
136
|
+
}[];
|
|
137
|
+
/** `true` when the two versions have identical blocks in identical order. */
|
|
138
|
+
readonly identical: boolean;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* The portable JSON shape of a single registered version, used by
|
|
142
|
+
* {@link PromptsManagerContract.export} / `import`. Blocks are flattened to
|
|
143
|
+
* `{ type, text }` so the registry round-trips without live builder instances.
|
|
144
|
+
*/
|
|
145
|
+
interface ExportedPromptVersion {
|
|
146
|
+
readonly version: string;
|
|
147
|
+
readonly blocks: PromptDiffBlock[];
|
|
148
|
+
/** Tags pinned to this exact version (via `tag(name, tag, version)`). */
|
|
149
|
+
readonly tags?: string[];
|
|
150
|
+
/** Carried-through `meta.description`, when present. */
|
|
151
|
+
readonly description?: string;
|
|
152
|
+
/** Carried-through `meta.required`, when present. */
|
|
153
|
+
readonly required?: string[];
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* The portable JSON shape of one registered name and all its versions, used by
|
|
157
|
+
* {@link PromptsManagerContract.export} / `import`.
|
|
158
|
+
*/
|
|
159
|
+
interface ExportedPrompt {
|
|
160
|
+
readonly name: string;
|
|
161
|
+
readonly versions: ExportedPromptVersion[];
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* The full portable registry snapshot returned by
|
|
165
|
+
* {@link PromptsManagerContract.export} and accepted by `import`.
|
|
166
|
+
*/
|
|
167
|
+
interface ExportedRegistry {
|
|
168
|
+
readonly prompts: ExportedPrompt[];
|
|
169
|
+
}
|
|
170
|
+
//#endregion
|
|
171
|
+
export { ExportedPrompt, ExportedPromptVersion, ExportedRegistry, PromptDiff, PromptDiffBlock, PromptJudgeCacheLike, PromptTemplateVersion, PromptValidateTarget, PromptValidationResult, PromptsManagerOptions, PromptsValidateOptions };
|
|
172
|
+
//# sourceMappingURL=prompts-manager.type.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompts-manager.type.d.mts","names":[],"sources":["../../../../../../../@warlock.js/ai/src/prompts/prompts-manager.type.ts"],"mappings":";;;;;;;AAWA;;;;;UAAiB,oBAAA;EAIkD;EAFjE,GAAA,cAAiB,GAAA,WAAc,OAAA,CAAQ,CAAA;EAAvC;EAEA,GAAA,CAAI,GAAA,UAAa,KAAA,WAAgB,YAAA,aAAyB,OAAA;AAAA;;;;UAM3C,qBAAA;EANE;;;;AAAgD;AAMnE;EANmB,SAaR,UAAA,GAAa,oBAAoB;AAAA;;AAAA;AAU5C;;;;AAAqE;KAAzD,oBAAA,YAAgC,yBAAyB;;;;UAKpD,sBAAA;EA2BO;;;;;EAAA,SArBb,YAAA,GAAe,YAAA;EAcf;;;;EAAA,SARA,OAAA;EAeiC;AAU5C;;;;;EAV4C,SAPjC,KAAA,GAAQ,aAAA;EA6BR;;;AAMM;AASjB;EAfW,SAtBA,UAAA,GAAa,oBAAA;AAAA;;;;;;AA6CwC;AAOhE;UA1CiB,sBAAA;;WAEN,EAAA;EA4CI;EAAA,SAzCJ,OAAA;EAgDgB;;;;;EAAA,SAzChB,KAAA;EAqDqD;;;;EAAA,SA/CrD,MAAA;AAAA;;;;;;;UASM,qBAAA;EAsCgC;EAAA,SApCtC,OAAA;EAsCS;AAAA;AAQpB;;EARoB,SAhCT,QAAA,oBAA4B,yBAAyB;AAAA;;;;;UAO/C,eAAA;EAyCN;EAAA,SAvCA,IAAA;EAuCQ;EAAA,SArCR,IAAI;AAAA;;;;;UAOE,UAAA;EAuCyB;EAAA,SArC/B,IAAA;EA4CM;EA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