@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.
- package/CHANGELOG.md +52 -48
- package/cjs/index.cjs +221 -14144
- 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 +19 -5
- 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/orchestrator-result.type.d.mts +15 -11
- package/esm/contracts/result/orchestrator-result.type.d.mts.map +1 -1
- package/esm/contracts/result/supervisor-result.type.d.mts +13 -1
- package/esm/contracts/result/supervisor-result.type.d.mts.map +1 -1
- package/esm/contracts/result/tool-call.type.d.mts +2 -2
- package/esm/contracts/result/tool-call.type.d.mts.map +1 -1
- package/esm/contracts/result/workflow-result.type.d.mts +1 -0
- 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/plan-schema.mjs +17 -14
- package/esm/planner/plan-schema.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,60 @@
|
|
|
1
|
+
//#region ../@warlock.js/ai/src/eval/report-junit.ts
|
|
2
|
+
/**
|
|
3
|
+
* Escape the five XML predefined entities so arbitrary text (case names,
|
|
4
|
+
* failure reasons, agent names) is safe inside an attribute value or
|
|
5
|
+
* element body. Covers `&`, `<`, `>`, `"`, and `'`.
|
|
6
|
+
*/
|
|
7
|
+
function escapeXml(value) {
|
|
8
|
+
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Build the `<failure>` body for a failed case: the joined reasons of
|
|
12
|
+
* every non-passing scorer, falling back to a generic message when a
|
|
13
|
+
* scorer offered no reason (or the failure was an agent error).
|
|
14
|
+
*/
|
|
15
|
+
function failureMessage(entry) {
|
|
16
|
+
if (entry.result.error) return `agent error: ${entry.result.error.message}`;
|
|
17
|
+
const reasons = entry.scores.filter((score) => score.passed === false).map((score) => score.reason).filter((reason) => typeof reason === "string" && reason !== "");
|
|
18
|
+
if (reasons.length > 0) return reasons.join("; ");
|
|
19
|
+
return "case did not pass";
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Serialize an {@link EvalReport} to a JUnit-XML string for CI ingestion.
|
|
23
|
+
*
|
|
24
|
+
* **Role.** A pure, runner-decoupled reporter: one `<testsuite>` whose
|
|
25
|
+
* name is the agent, one `<testcase>` per eval case, a `<failure>` child
|
|
26
|
+
* on each case that did not pass (with the joined scorer reasons), and a
|
|
27
|
+
* `time` attribute carrying the case / suite duration in **seconds**
|
|
28
|
+
* (JUnit's unit; the report stores milliseconds).
|
|
29
|
+
*
|
|
30
|
+
* XML is hand-emitted (no `xml` dependency) and every dynamic value is
|
|
31
|
+
* entity-escaped via {@link escapeXml}.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* await writeFile("./report.junit.xml", toJUnit(report));
|
|
35
|
+
*/
|
|
36
|
+
function toJUnit(report) {
|
|
37
|
+
const suiteName = escapeXml(report.agentName);
|
|
38
|
+
const suiteTime = (report.duration / 1e3).toFixed(3);
|
|
39
|
+
const lines = [];
|
|
40
|
+
lines.push("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
|
|
41
|
+
lines.push(`<testsuite name="${suiteName}" tests="${report.total}" failures="${report.failedCount}" time="${suiteTime}">`);
|
|
42
|
+
for (const entry of report.cases) {
|
|
43
|
+
const caseName = escapeXml(entry.case.name);
|
|
44
|
+
const caseTime = (entry.duration / 1e3).toFixed(3);
|
|
45
|
+
if (entry.passed) {
|
|
46
|
+
lines.push(` <testcase name="${caseName}" classname="${suiteName}" time="${caseTime}"/>`);
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
const message = failureMessage(entry);
|
|
50
|
+
lines.push(` <testcase name="${caseName}" classname="${suiteName}" time="${caseTime}">`);
|
|
51
|
+
lines.push(` <failure message="${escapeXml(message)}">${escapeXml(message)}</failure>`);
|
|
52
|
+
lines.push(" </testcase>");
|
|
53
|
+
}
|
|
54
|
+
lines.push("</testsuite>");
|
|
55
|
+
return lines.join("\n");
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
//#endregion
|
|
59
|
+
export { toJUnit };
|
|
60
|
+
//# sourceMappingURL=report-junit.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"report-junit.mjs","names":[],"sources":["../../../../../../../@warlock.js/ai/src/eval/report-junit.ts"],"sourcesContent":["import type { EvalCaseResult, EvalReport } from \"../contracts/agent/eval.type\";\n\n/**\n * Escape the five XML predefined entities so arbitrary text (case names,\n * failure reasons, agent names) is safe inside an attribute value or\n * element body. Covers `&`, `<`, `>`, `\"`, and `'`.\n */\nfunction escapeXml(value: string): string {\n return value\n .replace(/&/g, \"&\")\n .replace(/</g, \"<\")\n .replace(/>/g, \">\")\n .replace(/\"/g, \""\")\n .replace(/'/g, \"'\");\n}\n\n/**\n * Build the `<failure>` body for a failed case: the joined reasons of\n * every non-passing scorer, falling back to a generic message when a\n * scorer offered no reason (or the failure was an agent error).\n */\nfunction failureMessage(entry: EvalCaseResult): string {\n if (entry.result.error) {\n return `agent error: ${entry.result.error.message}`;\n }\n\n const reasons = entry.scores\n .filter((score) => score.passed === false)\n .map((score) => score.reason)\n .filter((reason): reason is string => typeof reason === \"string\" && reason !== \"\");\n\n if (reasons.length > 0) {\n return reasons.join(\"; \");\n }\n\n return \"case did not pass\";\n}\n\n/**\n * Serialize an {@link EvalReport} to a JUnit-XML string for CI ingestion.\n *\n * **Role.** A pure, runner-decoupled reporter: one `<testsuite>` whose\n * name is the agent, one `<testcase>` per eval case, a `<failure>` child\n * on each case that did not pass (with the joined scorer reasons), and a\n * `time` attribute carrying the case / suite duration in **seconds**\n * (JUnit's unit; the report stores milliseconds).\n *\n * XML is hand-emitted (no `xml` dependency) and every dynamic value is\n * entity-escaped via {@link escapeXml}.\n *\n * @example\n * await writeFile(\"./report.junit.xml\", toJUnit(report));\n */\nexport function toJUnit(report: EvalReport): string {\n const suiteName = escapeXml(report.agentName);\n const suiteTime = (report.duration / 1000).toFixed(3);\n\n const lines: string[] = [];\n\n lines.push('<?xml version=\"1.0\" encoding=\"UTF-8\"?>');\n lines.push(\n `<testsuite name=\"${suiteName}\" tests=\"${report.total}\" failures=\"${report.failedCount}\" time=\"${suiteTime}\">`,\n );\n\n for (const entry of report.cases) {\n const caseName = escapeXml(entry.case.name);\n const caseTime = (entry.duration / 1000).toFixed(3);\n\n if (entry.passed) {\n lines.push(\n ` <testcase name=\"${caseName}\" classname=\"${suiteName}\" time=\"${caseTime}\"/>`,\n );\n\n continue;\n }\n\n const message = failureMessage(entry);\n lines.push(\n ` <testcase name=\"${caseName}\" classname=\"${suiteName}\" time=\"${caseTime}\">`,\n );\n lines.push(\n ` <failure message=\"${escapeXml(message)}\">${escapeXml(message)}</failure>`,\n );\n lines.push(\" </testcase>\");\n }\n\n lines.push(\"</testsuite>\");\n\n return lines.join(\"\\n\");\n}\n"],"mappings":";;;;;;AAOA,SAAS,UAAU,OAAuB;CACxC,OAAO,MACJ,QAAQ,MAAM,OAAO,CAAC,CACtB,QAAQ,MAAM,MAAM,CAAC,CACrB,QAAQ,MAAM,MAAM,CAAC,CACrB,QAAQ,MAAM,QAAQ,CAAC,CACvB,QAAQ,MAAM,QAAQ;AAC3B;;;;;;AAOA,SAAS,eAAe,OAA+B;CACrD,IAAI,MAAM,OAAO,OACf,OAAO,gBAAgB,MAAM,OAAO,MAAM;CAG5C,MAAM,UAAU,MAAM,OACnB,QAAQ,UAAU,MAAM,WAAW,KAAK,CAAC,CACzC,KAAK,UAAU,MAAM,MAAM,CAAC,CAC5B,QAAQ,WAA6B,OAAO,WAAW,YAAY,WAAW,EAAE;CAEnF,IAAI,QAAQ,SAAS,GACnB,OAAO,QAAQ,KAAK,IAAI;CAG1B,OAAO;AACT;;;;;;;;;;;;;;;;AAiBA,SAAgB,QAAQ,QAA4B;CAClD,MAAM,YAAY,UAAU,OAAO,SAAS;CAC5C,MAAM,aAAa,OAAO,WAAW,IAAI,CAAE,QAAQ,CAAC;CAEpD,MAAM,QAAkB,CAAC;CAEzB,MAAM,KAAK,4CAAwC;CACnD,MAAM,KACJ,oBAAoB,UAAU,WAAW,OAAO,MAAM,cAAc,OAAO,YAAY,UAAU,UAAU,GAC7G;CAEA,KAAK,MAAM,SAAS,OAAO,OAAO;EAChC,MAAM,WAAW,UAAU,MAAM,KAAK,IAAI;EAC1C,MAAM,YAAY,MAAM,WAAW,IAAI,CAAE,QAAQ,CAAC;EAElD,IAAI,MAAM,QAAQ;GAChB,MAAM,KACJ,qBAAqB,SAAS,eAAe,UAAU,UAAU,SAAS,IAC5E;GAEA;EACF;EAEA,MAAM,UAAU,eAAe,KAAK;EACpC,MAAM,KACJ,qBAAqB,SAAS,eAAe,UAAU,UAAU,SAAS,GAC5E;EACA,MAAM,KACJ,yBAAyB,UAAU,OAAO,EAAE,IAAI,UAAU,OAAO,EAAE,WACrE;EACA,MAAM,KAAK,eAAe;CAC5B;CAEA,MAAM,KAAK,cAAc;CAEzB,OAAO,MAAM,KAAK,IAAI;AACxB"}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { MiddlewareTripContext } from "../../contracts/middleware/middleware-context.type.mjs";
|
|
2
|
+
import { GuardrailAction, GuardrailMatch, GuardrailPhase } from "./verdict.type.mjs";
|
|
3
|
+
import { GuardrailDetector } from "./guardrail.contract.mjs";
|
|
4
|
+
import { OpenAiClientLike } from "./openai-client.contract.mjs";
|
|
5
|
+
|
|
6
|
+
//#region ../@warlock.js/ai/src/guard/contracts/guard-options.type.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* The payload handed to {@link GuardrailEscalation.onBlock} when a detector
|
|
9
|
+
* returns `{ type: "block", escalate: true }`. The factory builds it just
|
|
10
|
+
* before throwing the `GuardrailViolationError`, so a host can route the
|
|
11
|
+
* hard block to a human-review surface.
|
|
12
|
+
*/
|
|
13
|
+
interface GuardrailBlockEvent {
|
|
14
|
+
/** Where the block fired: input prompt, output, or tool args. */
|
|
15
|
+
readonly phase: GuardrailPhase;
|
|
16
|
+
/** The detector's human-readable reason. */
|
|
17
|
+
readonly reason: string;
|
|
18
|
+
/** The matches that triggered the block, when the detector reported them. */
|
|
19
|
+
readonly matches?: readonly GuardrailMatch[];
|
|
20
|
+
/** The live middleware trip context (state, messages, agent, model, signal). */
|
|
21
|
+
readonly ctx: MiddlewareTripContext;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Escalation seam for composing a hard block with a human-review surface.
|
|
25
|
+
*
|
|
26
|
+
* The callback fires **only** for a verdict of `{ type: "block", escalate:
|
|
27
|
+
* true }`, awaited *before* the `GuardrailViolationError` is thrown. It is a
|
|
28
|
+
* plain callback by design — `ai-guard` takes no dependency on the deferred
|
|
29
|
+
* human-step machinery; the host wires its own review queue / resume loop
|
|
30
|
+
* inside `onBlock`.
|
|
31
|
+
*/
|
|
32
|
+
interface GuardrailEscalation {
|
|
33
|
+
/** Route a `{ type: "block", escalate: true }` verdict to a human. */
|
|
34
|
+
onBlock?(event: GuardrailBlockEvent): void | Promise<void>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Configuration for the {@link guard} factory (surfaced as
|
|
38
|
+
* `ai.guardrail(options)`). Each phase array runs in registration order;
|
|
39
|
+
* the first non-`allow` verdict decides the action for that phase.
|
|
40
|
+
*
|
|
41
|
+
* At least one of `input` / `output` / `tool` should be supplied — a guard
|
|
42
|
+
* with no detectors is a no-op middleware.
|
|
43
|
+
*/
|
|
44
|
+
interface GuardOptions {
|
|
45
|
+
/**
|
|
46
|
+
* Override the middleware name — surfaces on
|
|
47
|
+
* `GuardrailViolationError.guardrail` and as the `ctx.state` namespace so
|
|
48
|
+
* operators can tell two guards apart. Default `"guardrail"`.
|
|
49
|
+
*/
|
|
50
|
+
name?: string;
|
|
51
|
+
/**
|
|
52
|
+
* Detectors run on the outbound prompt at `trip.before`.
|
|
53
|
+
*
|
|
54
|
+
* **Input redaction is not supported in v1:** the core `trip.before` hook
|
|
55
|
+
* can only short-circuit, not rewrite-and-continue, so a `redact` verdict
|
|
56
|
+
* here is treated as a `block`. Input detectors are effectively
|
|
57
|
+
* `block` / `flag` only.
|
|
58
|
+
*/
|
|
59
|
+
input?: readonly GuardrailDetector[];
|
|
60
|
+
/** Detectors run on `response.content` at `trip.after`. Support `redact`. */
|
|
61
|
+
output?: readonly GuardrailDetector[];
|
|
62
|
+
/**
|
|
63
|
+
* Detectors run on `JSON.stringify(toolArgs)` at `tool.before`. A
|
|
64
|
+
* `redact` verdict here is treated as a `block` (silently rewriting tool
|
|
65
|
+
* arguments changes side-effects unpredictably).
|
|
66
|
+
*/
|
|
67
|
+
tool?: readonly GuardrailDetector[];
|
|
68
|
+
/**
|
|
69
|
+
* The tool names the `tool` detectors apply to. Omit to apply to every
|
|
70
|
+
* tool. When set, the middleware's `tool` hooks are scoped via the core
|
|
71
|
+
* `forTool(toolNames, mw)` helper; `trip` hooks are unaffected.
|
|
72
|
+
*/
|
|
73
|
+
toolNames?: string | readonly string[];
|
|
74
|
+
/** Compose a `{ type: "block", escalate: true }` verdict with a human. */
|
|
75
|
+
escalation?: GuardrailEscalation;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* The PII categories the built-in `pii` detector can scan for. Each is a
|
|
79
|
+
* linear (anchored, no nested quantifiers) regex — safe against catastrophic
|
|
80
|
+
* backtracking.
|
|
81
|
+
*/
|
|
82
|
+
type PiiCategory = "ssn" | "email" | "phone" | "credit-card" | "ipv4";
|
|
83
|
+
/**
|
|
84
|
+
* Options for the built-in `pii` detector (`ai.guardrail.pii`). All built-in
|
|
85
|
+
* PII matching is regex / exact-string only — zero runtime dependency.
|
|
86
|
+
*/
|
|
87
|
+
interface PiiDetectorOptions {
|
|
88
|
+
/** Which categories to scan for. Default: every {@link PiiCategory}. */
|
|
89
|
+
detect?: readonly PiiCategory[];
|
|
90
|
+
/** What to do on a match. Default `"redact"`. */
|
|
91
|
+
onMatch?: Extract<GuardrailAction, "redact" | "block" | "flag">;
|
|
92
|
+
/**
|
|
93
|
+
* Replacement template used on `redact`. Supports the `{label}` token,
|
|
94
|
+
* substituted with the matched category — e.g. `"[REDACTED:{label}]"`.
|
|
95
|
+
* Default masks the matched span with a fixed placeholder.
|
|
96
|
+
*/
|
|
97
|
+
mask?: string;
|
|
98
|
+
/** Extra exact-string terms to treat as PII alongside the built-in regexes. */
|
|
99
|
+
dictionary?: readonly string[];
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Options for the built-in `topic` filter (`ai.guardrail.topic`). Matches a
|
|
103
|
+
* case-insensitive substring or a `RegExp` against the inspected text.
|
|
104
|
+
*/
|
|
105
|
+
interface TopicFilterOptions {
|
|
106
|
+
/**
|
|
107
|
+
* Deny-list terms / phrases. A `string` matches case-insensitively as a
|
|
108
|
+
* substring; a `RegExp` is tested as-is. Any hit triggers `onMatch`.
|
|
109
|
+
*/
|
|
110
|
+
deny?: readonly (string | RegExp)[];
|
|
111
|
+
/**
|
|
112
|
+
* Allow-list terms / phrases. When set, text matching **none** of these
|
|
113
|
+
* triggers `onMatch` (an allow-list miss).
|
|
114
|
+
*/
|
|
115
|
+
allow?: readonly (string | RegExp)[];
|
|
116
|
+
/** Action on a deny hit (or an allow-list miss). Default `"block"`. */
|
|
117
|
+
onMatch?: Extract<GuardrailAction, "block" | "flag">;
|
|
118
|
+
/** Override the verdict's human-readable reason. */
|
|
119
|
+
reason?: string;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Options for the built-in `injection` detector (`ai.guardrail.injection`).
|
|
123
|
+
* Matches a built-in set of jailbreak / prompt-injection marker phrases,
|
|
124
|
+
* extensible with caller-supplied markers.
|
|
125
|
+
*/
|
|
126
|
+
interface InjectionDetectorOptions {
|
|
127
|
+
/**
|
|
128
|
+
* Extra marker phrases beyond the built-in jailbreak / prompt-injection
|
|
129
|
+
* set. A `string` matches case-insensitively as a substring; a `RegExp`
|
|
130
|
+
* is tested as-is.
|
|
131
|
+
*/
|
|
132
|
+
markers?: readonly (string | RegExp)[];
|
|
133
|
+
/**
|
|
134
|
+
* Action on a match. Default `"flag"` — callers commonly escalate to
|
|
135
|
+
* `"block"` on the input phase.
|
|
136
|
+
*/
|
|
137
|
+
onMatch?: Extract<GuardrailAction, "block" | "flag">;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Options for the optional `moderation` detector (`ai.guardrail.moderation`),
|
|
141
|
+
* backed by a lazily-imported `openai` peer. Importing `@warlock.js/ai`
|
|
142
|
+
* never forces `openai` to resolve; the detector throws a curated install
|
|
143
|
+
* string on first `check()` when the SDK is absent.
|
|
144
|
+
*/
|
|
145
|
+
interface OpenAiModerationOptions {
|
|
146
|
+
/**
|
|
147
|
+
* A pre-built OpenAI-compatible client (any object matching
|
|
148
|
+
* {@link OpenAiClientLike}, including a real `OpenAI` instance). When
|
|
149
|
+
* supplied, the detector calls it directly and never imports the SDK —
|
|
150
|
+
* the bring-your-own-client / test escape hatch.
|
|
151
|
+
*/
|
|
152
|
+
client?: OpenAiClientLike;
|
|
153
|
+
/** OpenAI API key. Reads `OPENAI_API_KEY` from the environment when omitted. */
|
|
154
|
+
apiKey?: string;
|
|
155
|
+
/** Moderation model to call. Default `"omni-moderation-latest"`. */
|
|
156
|
+
model?: string;
|
|
157
|
+
/**
|
|
158
|
+
* Categories that escalate to `block`; every other flagged category
|
|
159
|
+
* produces a `flag` verdict instead. Omit to `flag` on any category.
|
|
160
|
+
*/
|
|
161
|
+
blockOn?: readonly string[];
|
|
162
|
+
}
|
|
163
|
+
//#endregion
|
|
164
|
+
export { GuardOptions, GuardrailBlockEvent, GuardrailEscalation, InjectionDetectorOptions, OpenAiModerationOptions, PiiCategory, PiiDetectorOptions, TopicFilterOptions };
|
|
165
|
+
//# sourceMappingURL=guard-options.type.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guard-options.type.d.mts","names":[],"sources":["../../../../../../../../@warlock.js/ai/src/guard/contracts/guard-options.type.ts"],"mappings":";;;;;;;;AAeA;;;;UAAiB,mBAAA;EAQD;EAAA,SANL,KAAA,EAAO,cAAA;EAMmB;EAAA,SAJ1B,MAAA;EAFO;EAAA,SAIP,OAAA,YAAmB,cAAA;EAAnB;EAAA,SAEA,GAAA,EAAK,qBAAA;AAAA;;;AAAqB;AAYrC;;;;;;UAAiB,mBAAA;EAE8B;EAA7C,OAAA,EAAS,KAAA,EAAO,mBAAA,UAA6B,OAAO;AAAA;AAWtD;;;;;;;;AAAA,UAAiB,YAAA;EAMf;;;;;EAAA,IAAA;EAiBgB;;;;;AAQgB;AAQlC;;EAxBE,KAAA,YAAiB,iBAAA;EAwBI;EAtBrB,MAAA,YAAkB,iBAAA;EA4BH;;;;;EAtBf,IAAA,YAAgB,iBAAA;EA0BC;;;;;EApBjB,SAAA;EAoBkB;EAlBlB,UAAA,GAAa,mBAAA;AAAA;;AA0BH;AAOZ;;;KAzBY,WAAA;;;;;UAMK,kBAAA;EAwBf;EAtBA,MAAA,YAAkB,WAAA;EA2BlB;EAzBA,OAAA,GAAU,OAAA,CAAQ,eAAA;EA2BlB;;;;;EArBA,IAAA;EA+Be;EA7Bf,UAAA;AAAA;;;;;UAOe,kBAAA;EA4Bf;;;;EAvBA,IAAA,sBAA0B,MAAA;EA4BO;AAAA;AASnC;;EAhCE,KAAA,sBAA2B,MAAA;EAuCF;EArCzB,OAAA,GAAU,OAAA,CAAQ,eAAA;EAqCT;EAnCT,MAAA;AAAA;;;AA4CO;;;UApCQ,wBAAA;;;;;;EAMf,OAAA,sBAA6B,MAAA;;;;;EAK7B,OAAA,GAAU,OAAA,CAAQ,eAAA;AAAA;;;;;;;UASH,uBAAA;;;;;;;EAOf,MAAA,GAAS,gBAAgB;;EAEzB,MAAA;;EAEA,KAAA;;;;;EAKA,OAAA;AAAA"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { MiddlewareTripContext } from "../../contracts/middleware/middleware-context.type.mjs";
|
|
2
|
+
import { GuardrailPhase, GuardrailVerdict } from "./verdict.type.mjs";
|
|
3
|
+
|
|
4
|
+
//#region ../@warlock.js/ai/src/guard/contracts/guardrail.contract.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* The stable context every detector receives on each `check()` — the phase
|
|
7
|
+
* it is running at plus the live middleware trip context.
|
|
8
|
+
*
|
|
9
|
+
* A detector reads `phase` to branch on *where* it is running (e.g. an
|
|
10
|
+
* injection detector escalating to `block` on `"input"` but only `flag` on
|
|
11
|
+
* `"output"`), and `ctx` for the surrounding run identity (`state`,
|
|
12
|
+
* `messages`, `agent`, `model`, `signal`). A detector must never mutate
|
|
13
|
+
* `ctx` — it is a read-only view; the factory owns all pipeline effects.
|
|
14
|
+
*/
|
|
15
|
+
interface GuardrailDetectorContext {
|
|
16
|
+
/** Where this detector is running: input prompt, output, or tool args. */
|
|
17
|
+
readonly phase: GuardrailPhase;
|
|
18
|
+
/** The live middleware trip context (state, messages, agent, model, signal). */
|
|
19
|
+
readonly ctx: MiddlewareTripContext;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* A guardrail detector — the unit of content intelligence. Inspects a piece
|
|
23
|
+
* of text and returns a {@link GuardrailVerdict}. Sync or async (an async
|
|
24
|
+
* `check` routes to an external moderation API).
|
|
25
|
+
*
|
|
26
|
+
* A detector has **no** knowledge of hooks, ordering, or `ctx.state`
|
|
27
|
+
* mutation — the {@link guard} factory is the thin adapter that runs
|
|
28
|
+
* detectors at the right hook points and translates verdicts into the
|
|
29
|
+
* pipeline's throw / return / record mechanics.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* const noShouting: GuardrailDetector = {
|
|
33
|
+
* name: "no-shouting",
|
|
34
|
+
* check(text) {
|
|
35
|
+
* return text === text.toUpperCase() && text.length > 0
|
|
36
|
+
* ? { type: "flag", reason: "all caps", matches: [{ rule: "no-shouting" }] }
|
|
37
|
+
* : { type: "allow" };
|
|
38
|
+
* },
|
|
39
|
+
* };
|
|
40
|
+
*/
|
|
41
|
+
interface GuardrailDetector {
|
|
42
|
+
/**
|
|
43
|
+
* Kebab-case identifier, used as the rule prefix in {@link GuardrailMatch}
|
|
44
|
+
* and surfaced in logs / events — e.g. `"pii"`, `"topic"`, `"injection"`,
|
|
45
|
+
* `"moderation.openai"`.
|
|
46
|
+
*/
|
|
47
|
+
readonly name: string;
|
|
48
|
+
/**
|
|
49
|
+
* Inspect `text` and return a verdict. Receives the
|
|
50
|
+
* {@link GuardrailDetectorContext} so it can branch on the phase or read
|
|
51
|
+
* the surrounding run state.
|
|
52
|
+
*/
|
|
53
|
+
check(text: string, detectorCtx: GuardrailDetectorContext): GuardrailVerdict | Promise<GuardrailVerdict>;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* A {@link GuardrailDetector} whose `check()` is **synchronous** — it returns a
|
|
57
|
+
* {@link GuardrailVerdict} directly, never a `Promise`. Used by the built-in
|
|
58
|
+
* zero-dependency detectors (`pii`, `topic`, `injection`) that inspect text
|
|
59
|
+
* with pure string / regex matching and have no async work to do.
|
|
60
|
+
*
|
|
61
|
+
* Because the return type is covariant, a `SyncGuardrailDetector` is
|
|
62
|
+
* structurally assignable to {@link GuardrailDetector}: anything that accepts a
|
|
63
|
+
* `GuardrailDetector` (the guard factory's `input` / `output` / `tool` arrays)
|
|
64
|
+
* accepts a `SyncGuardrailDetector` unchanged. Callers that hold the concrete
|
|
65
|
+
* sync type additionally get to read `verdict.type` / `.matches` / `.text`
|
|
66
|
+
* without awaiting.
|
|
67
|
+
*/
|
|
68
|
+
interface SyncGuardrailDetector extends GuardrailDetector {
|
|
69
|
+
/**
|
|
70
|
+
* Inspect `text` and return a verdict synchronously. Receives the
|
|
71
|
+
* {@link GuardrailDetectorContext} so it can branch on the phase or read
|
|
72
|
+
* the surrounding run state.
|
|
73
|
+
*/
|
|
74
|
+
check(text: string, detectorCtx: GuardrailDetectorContext): GuardrailVerdict;
|
|
75
|
+
}
|
|
76
|
+
//#endregion
|
|
77
|
+
export { GuardrailDetector, GuardrailDetectorContext, SyncGuardrailDetector };
|
|
78
|
+
//# sourceMappingURL=guardrail.contract.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guardrail.contract.d.mts","names":[],"sources":["../../../../../../../../@warlock.js/ai/src/guard/contracts/guardrail.contract.ts"],"mappings":";;;;;;AAaA;;;;;;;;UAAiB,wBAAA;EAIoB;EAAA,SAF1B,KAAA,EAAO,cAAA;EAyBgB;EAAA,SAvBvB,GAAA,EAAK,qBAAqB;AAAA;;;;;;;;;;;;;;;AAsCW;AAgBhD;;;;;UA/BiB,iBAAA;EA+B+C;;;;;EAAA,SAzBrD,IAAA;EA+BW;;;AAAwD;;EAzB5E,KAAA,CACE,IAAA,UACA,WAAA,EAAa,wBAAA,GACZ,gBAAA,GAAmB,OAAA,CAAQ,gBAAA;AAAA;;;;;;;;;;;;;;UAgBf,qBAAA,SAA8B,iBAAA;;;;;;EAM7C,KAAA,CAAM,IAAA,UAAc,WAAA,EAAa,wBAAA,GAA2B,gBAAA;AAAA"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { GuardrailAction, GuardrailMatch, GuardrailPhase, GuardrailVerdict } from "./verdict.type.mjs";
|
|
2
|
+
import { GuardrailDetector, GuardrailDetectorContext, SyncGuardrailDetector } from "./guardrail.contract.mjs";
|
|
3
|
+
import { OpenAiClientLike, OpenAiModerationCreateBody, OpenAiModerationResponse, OpenAiModerationResult } from "./openai-client.contract.mjs";
|
|
4
|
+
import { GuardOptions, GuardrailBlockEvent, GuardrailEscalation, InjectionDetectorOptions, OpenAiModerationOptions, PiiCategory, PiiDetectorOptions, TopicFilterOptions } from "./guard-options.type.mjs";
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
//#region ../@warlock.js/ai/src/guard/contracts/openai-client.contract.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Minimal structural view of the part of the `openai` SDK the
|
|
4
|
+
* `moderation` detector actually calls. Declared locally (rather than
|
|
5
|
+
* importing the SDK's own types) so `@warlock.js/ai` type-checks even
|
|
6
|
+
* when `openai` is **not** installed — it is an OPTIONAL peer, lazily
|
|
7
|
+
* imported at runtime. The shape tracks the OpenAI Node SDK v4:
|
|
8
|
+
* `client.moderations.create({ model, input })` resolves to a response whose
|
|
9
|
+
* `results[]` each carry a `flagged` boolean and per-category `categories` /
|
|
10
|
+
* `category_scores` maps.
|
|
11
|
+
*
|
|
12
|
+
* Surfacing it as a contract lets a caller pass a ready
|
|
13
|
+
* {@link OpenAiClientLike} (real `OpenAI` instance, mock, or proxy) on
|
|
14
|
+
* `OpenAiModerationOptions.client` to bypass the lazy import entirely.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* A pre-built OpenAI-compatible client — any object exposing
|
|
18
|
+
* `moderations.create`. Passing one on `OpenAiModerationOptions.client` lets
|
|
19
|
+
* the detector skip the lazy `import("openai")` entirely (so bring-your-own-
|
|
20
|
+
* client callers and hermetic tests never need the SDK on disk).
|
|
21
|
+
*/
|
|
22
|
+
interface OpenAiClientLike {
|
|
23
|
+
readonly moderations: {
|
|
24
|
+
create(body: OpenAiModerationCreateBody): Promise<OpenAiModerationResponse>;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/** Subset of the moderation-create body the detector populates. */
|
|
28
|
+
interface OpenAiModerationCreateBody {
|
|
29
|
+
/** Moderation model id (e.g. `"omni-moderation-latest"`). */
|
|
30
|
+
readonly model: string;
|
|
31
|
+
/** The text to moderate. */
|
|
32
|
+
readonly input: string;
|
|
33
|
+
}
|
|
34
|
+
/** Subset of the moderation response the detector reads. */
|
|
35
|
+
interface OpenAiModerationResponse {
|
|
36
|
+
readonly results: readonly OpenAiModerationResult[];
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* One moderation result. `flagged` is the SDK's overall verdict; `categories`
|
|
40
|
+
* maps each policy category to whether it tripped; `category_scores` carries
|
|
41
|
+
* the per-category confidence, surfaced on each {@link GuardrailMatch.label}'s
|
|
42
|
+
* companion data when present.
|
|
43
|
+
*/
|
|
44
|
+
interface OpenAiModerationResult {
|
|
45
|
+
readonly flagged: boolean;
|
|
46
|
+
readonly categories: Record<string, boolean>;
|
|
47
|
+
readonly category_scores?: Record<string, number>;
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
export { OpenAiClientLike, OpenAiModerationCreateBody, OpenAiModerationResponse, OpenAiModerationResult };
|
|
51
|
+
//# sourceMappingURL=openai-client.contract.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openai-client.contract.d.mts","names":[],"sources":["../../../../../../../../@warlock.js/ai/src/guard/contracts/openai-client.contract.ts"],"mappings":";;AAqBA;;;;;;;;;;;;;;;AAE8E;AAK9E;;;UAPiB,gBAAA;EAAA,SACN,WAAA;IACP,MAAA,CAAO,IAAA,EAAM,0BAAA,GAA6B,OAAA,CAAQ,wBAAA;EAAA;AAAA;;UAKrC,0BAAA;EAkBA;EAAA,SAhBN,KAAA;;WAEA,KAAK;AAAA;;UAIC,wBAAA;EAAA,SACN,OAAA,WAAkB,sBAAsB;AAAA;;AAYhB;;;;;UAHlB,sBAAA;EAAA,SACN,OAAA;EAAA,SACA,UAAA,EAAY,MAAA;EAAA,SACZ,eAAA,GAAkB,MAAM;AAAA"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
//#region ../@warlock.js/ai/src/guard/contracts/verdict.type.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Where a detector is running. Widens the core guardrail phase
|
|
4
|
+
* (`"input" | "output"`) with a third value, `"tool"`, for detectors that
|
|
5
|
+
* inspect the arguments the model produced for a tool call. Reused on the
|
|
6
|
+
* `GuardrailViolationError.phase` surfaced to callers and on any emitted
|
|
7
|
+
* escalation event.
|
|
8
|
+
*/
|
|
9
|
+
type GuardrailPhase = "input" | "output" | "tool";
|
|
10
|
+
/**
|
|
11
|
+
* The four actions a detector can return, the discriminator of
|
|
12
|
+
* {@link GuardrailVerdict}.
|
|
13
|
+
*
|
|
14
|
+
* - `allow` — content is clean; continue to the next detector.
|
|
15
|
+
* - `redact` — rewrite the inspected text and continue.
|
|
16
|
+
* - `block` — reject the trip / tool call with a `GuardrailViolationError`.
|
|
17
|
+
* - `flag` — allow the content but record the match for a downstream observer.
|
|
18
|
+
*
|
|
19
|
+
* `type` is always the discriminator — never `kind`.
|
|
20
|
+
*/
|
|
21
|
+
type GuardrailAction = "allow" | "redact" | "block" | "flag";
|
|
22
|
+
/**
|
|
23
|
+
* A single thing a detector matched inside the inspected text. Surfaced in
|
|
24
|
+
* logs, events, and on `redact` / `flag` verdicts so an operator can see
|
|
25
|
+
* *what* tripped a rule without re-running the detector.
|
|
26
|
+
*/
|
|
27
|
+
interface GuardrailMatch {
|
|
28
|
+
/**
|
|
29
|
+
* The detector rule that produced the match, namespaced under the
|
|
30
|
+
* detector — e.g. `"pii.ssn"`, `"topic.deny.medical"`,
|
|
31
|
+
* `"injection.jailbreak"`.
|
|
32
|
+
*/
|
|
33
|
+
readonly rule: string;
|
|
34
|
+
/**
|
|
35
|
+
* Inclusive `[start, end]` character offsets into the inspected text,
|
|
36
|
+
* when the detector can locate the match. Omitted for whole-text
|
|
37
|
+
* verdicts (e.g. an allow-list miss or a moderation-model category).
|
|
38
|
+
*/
|
|
39
|
+
readonly span?: readonly [start: number, end: number];
|
|
40
|
+
/**
|
|
41
|
+
* Free-form category surfaced in logs and events and substituted into a
|
|
42
|
+
* redaction `mask` template — e.g. `"ssn"`, `"email"`, `"violence"`.
|
|
43
|
+
*/
|
|
44
|
+
readonly label?: string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The verdict a {@link GuardrailDetector} returns from `check()` — a
|
|
48
|
+
* discriminated union with exactly one {@link GuardrailAction} per shape.
|
|
49
|
+
* The factory folds a detector array and acts on the first non-`allow`
|
|
50
|
+
* verdict (short-circuit, in registration order).
|
|
51
|
+
*/
|
|
52
|
+
type GuardrailVerdict = {
|
|
53
|
+
/** Content is clean; continue to the next detector. */readonly type: "allow";
|
|
54
|
+
} | {
|
|
55
|
+
/** Rewrite the inspected text and continue. */readonly type: "redact"; /** The inspected text with every match replaced (detector-produced). */
|
|
56
|
+
readonly text: string; /** Human-readable explanation of what was redacted and why. */
|
|
57
|
+
readonly reason: string; /** The matches the detector replaced. */
|
|
58
|
+
readonly matches: readonly GuardrailMatch[];
|
|
59
|
+
} | {
|
|
60
|
+
/** Reject the trip / tool call. */readonly type: "block"; /** Human-readable reason surfaced on `GuardrailViolationError.reason`. */
|
|
61
|
+
readonly reason: string; /** The matches that triggered the block, when known. */
|
|
62
|
+
readonly matches?: readonly GuardrailMatch[];
|
|
63
|
+
/**
|
|
64
|
+
* Ask the host to route this block to a human-review surface. When
|
|
65
|
+
* `true`, the factory awaits `escalation.onBlock` before throwing.
|
|
66
|
+
* Default `false`.
|
|
67
|
+
*/
|
|
68
|
+
readonly escalate?: boolean;
|
|
69
|
+
} | {
|
|
70
|
+
/** Allow the content but record the match for a downstream observer. */readonly type: "flag"; /** Human-readable explanation of what was flagged. */
|
|
71
|
+
readonly reason: string; /** The matches the detector recorded. */
|
|
72
|
+
readonly matches: readonly GuardrailMatch[];
|
|
73
|
+
};
|
|
74
|
+
//#endregion
|
|
75
|
+
export { GuardrailAction, GuardrailMatch, GuardrailPhase, GuardrailVerdict };
|
|
76
|
+
//# sourceMappingURL=verdict.type.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verdict.type.d.mts","names":[],"sources":["../../../../../../../../@warlock.js/ai/src/guard/contracts/verdict.type.ts"],"mappings":";;AAOA;;;;AAA0B;AAa1B;KAbY,cAAA;;;AAae;AAO3B;;;;;;;;KAPY,eAAA;;AAwBI;AAShB;;;UA1BiB,cAAA;EA+CiB;;;;;EAAA,SAzCvB,IAAA;EA6BI;;;;;EAAA,SAvBJ,IAAA,aAAiB,KAAA,UAAe,GAAA;EAmC5B;;;;EAAA,SA9BJ,KAAA;AAAA;;;AA4CoC;;;;KAnCnC,gBAAA;kEAGG,IAAA;AAAA;0DAIA,IAAA;WAEA,IAAA;WAEA,MAAA;WAEA,OAAA,WAAkB,cAAA;AAAA;8CAIlB,IAAA;WAEA,MAAA;WAEA,OAAA,YAAmB,cAAA;;;;;;WAMnB,QAAA;AAAA;mFAIA,IAAA;WAEA,MAAA;WAEA,OAAA,WAAkB,cAAA;AAAA"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { SyncGuardrailDetector } from "../contracts/guardrail.contract.mjs";
|
|
2
|
+
import { InjectionDetectorOptions } from "../contracts/guard-options.type.mjs";
|
|
3
|
+
//#region ../@warlock.js/ai/src/guard/detectors/injection.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Build the built-in `injection` detector (surfaced as
|
|
6
|
+
* `ai.guardrail.injection(options?)`). Matches a curated set of jailbreak /
|
|
7
|
+
* prompt-injection marker phrases — override (`"ignore previous
|
|
8
|
+
* instructions"`), role-reset (`"you are now"`), jailbreak (`"developer
|
|
9
|
+
* mode"`, `"do anything now"`), and exfiltration (`"reveal your system
|
|
10
|
+
* prompt"`) — extensible with caller `markers` (case-insensitive substrings
|
|
11
|
+
* or `RegExp`s).
|
|
12
|
+
*
|
|
13
|
+
* Zero runtime dependency: matching is pure string / regex. On a hit the
|
|
14
|
+
* verdict is `flag` by default (record but allow); pass `onMatch: "block"`
|
|
15
|
+
* to reject instead — commonly used on the `input` phase, where the core
|
|
16
|
+
* `trip.before` seam supports `block` / `flag` only.
|
|
17
|
+
*
|
|
18
|
+
* @param options - Extra `markers` and the `onMatch` action (`"flag"` | `"block"`).
|
|
19
|
+
* @returns A {@link SyncGuardrailDetector} for the guard's `input` / `output` / `tool` arrays.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* const guard = ai.guardrail({
|
|
23
|
+
* input: [ai.guardrail.injection({ onMatch: "block" })],
|
|
24
|
+
* output: [ai.guardrail.injection()], // flag-only on the model's reply
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* // Extend the built-in set with a house rule.
|
|
29
|
+
* ai.guardrail.injection({ markers: [/system\s*:\s*override/i, "sudo mode"] });
|
|
30
|
+
*/
|
|
31
|
+
declare function injection(options?: InjectionDetectorOptions): SyncGuardrailDetector;
|
|
32
|
+
//#endregion
|
|
33
|
+
export { injection };
|
|
34
|
+
//# sourceMappingURL=injection.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"injection.d.mts","names":[],"sources":["../../../../../../../../@warlock.js/ai/src/guard/detectors/injection.ts"],"mappings":";;;;;;;AAiNA;;;;;;;;AAEwB;;;;;;;;;;;;;;;iBAFR,SAAA,CACd,OAAA,GAAU,wBAAA,GACT,qBAAqB"}
|