@warlock.js/ai 4.4.0 → 4.6.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 +63 -52
- package/cjs/index.cjs +240 -14147
- package/cjs/src-Bmajk4Qg.cjs +30 -0
- package/cjs/src-OZyDYHxm.cjs +25089 -0
- package/cjs/src-OZyDYHxm.cjs.map +1 -0
- package/esm/agent/agent-config.type.d.mts +119 -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 +328 -36
- 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/agent/signature.mjs +57 -0
- package/esm/agent/signature.mjs.map +1 -0
- package/esm/agent/snapshot.mjs +101 -0
- package/esm/agent/snapshot.mjs.map +1 -0
- package/esm/ai-openai/src/embedder.mjs +4 -0
- package/esm/ai-openai/src/image.mjs +5 -0
- package/esm/ai-openai/src/index.mjs +7 -0
- package/esm/ai-openai/src/model.mjs +5 -0
- package/esm/ai-openai/src/sdk.mjs +9 -0
- package/esm/ai-openai/src/speech.mjs +5 -0
- package/esm/ai-openai/src/transcription.mjs +6 -0
- package/esm/ai-openai/src/utils/index.mjs +5 -0
- package/esm/ai-openai/src/utils/to-openai-messages.mjs +3 -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 +164 -53
- package/esm/ai.d.mts.map +1 -1
- package/esm/ai.mjs +79 -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 +33 -5
- package/esm/contracts/agent/agent-options.type.d.mts.map +1 -1
- package/esm/contracts/agent/agent-snapshot.type.d.mts +90 -0
- package/esm/contracts/agent/agent-snapshot.type.d.mts.map +1 -0
- package/esm/contracts/agent/agent.contract.d.mts +29 -1
- package/esm/contracts/agent/agent.contract.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/agent/index.d.mts +2 -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/image-model.contract.d.mts +156 -0
- package/esm/contracts/image-model.contract.d.mts.map +1 -0
- package/esm/contracts/index.d.mts +13 -6
- 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 +3 -2
- package/esm/contracts/planner/planner-config.type.d.mts +61 -0
- package/esm/contracts/planner/planner-config.type.d.mts.map +1 -1
- package/esm/contracts/planner/planner-execute-options.type.d.mts +60 -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-snapshot.type.d.mts +77 -0
- package/esm/contracts/planner/planner-snapshot.type.d.mts.map +1 -0
- package/esm/contracts/planner/planner.contract.d.mts +21 -1
- package/esm/contracts/planner/planner.contract.d.mts.map +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/sdk-adapter.contract.d.mts +37 -0
- package/esm/contracts/sdk-adapter.contract.d.mts.map +1 -1
- package/esm/contracts/speech-model.contract.d.mts +97 -0
- package/esm/contracts/speech-model.contract.d.mts.map +1 -0
- 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/transcription-model.contract.d.mts +101 -0
- package/esm/contracts/transcription-model.contract.d.mts.map +1 -0
- 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/agent-drift-error.d.mts +32 -0
- package/esm/errors/agent-drift-error.d.mts.map +1 -0
- package/esm/errors/agent-drift-error.mjs +31 -0
- package/esm/errors/agent-drift-error.mjs.map +1 -0
- package/esm/errors/error-code.type.d.mts +1 -1
- package/esm/errors/index.d.mts +3 -0
- package/esm/errors/index.mjs +3 -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/errors/planner-drift-error.d.mts +34 -0
- package/esm/errors/planner-drift-error.d.mts.map +1 -0
- package/esm/errors/planner-drift-error.mjs +33 -0
- package/esm/errors/planner-drift-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/image/image-cost.d.mts +32 -0
- package/esm/image/image-cost.d.mts.map +1 -0
- package/esm/image/image-cost.mjs +55 -0
- package/esm/image/image-cost.mjs.map +1 -0
- package/esm/image/image.d.mts +92 -0
- package/esm/image/image.d.mts.map +1 -0
- package/esm/image/image.mjs +113 -0
- package/esm/image/image.mjs.map +1 -0
- package/esm/image/index.mjs +4 -0
- package/esm/index.d.mts +137 -24
- package/esm/index.mjs +101 -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/mock/index.d.mts +3 -0
- package/esm/mock/index.mjs +3 -0
- package/esm/mock/mock-config.type.d.mts +22 -0
- package/esm/mock/mock-config.type.d.mts.map +1 -1
- package/esm/mock/mock-image-model.d.mts +41 -0
- package/esm/mock/mock-image-model.d.mts.map +1 -0
- package/esm/mock/mock-image-model.mjs +52 -0
- package/esm/mock/mock-image-model.mjs.map +1 -0
- package/esm/mock/mock-sdk.d.mts +7 -1
- package/esm/mock/mock-sdk.d.mts.map +1 -1
- package/esm/mock/mock-sdk.mjs +27 -0
- package/esm/mock/mock-sdk.mjs.map +1 -1
- package/esm/mock/mock-speech-model.d.mts +31 -0
- package/esm/mock/mock-speech-model.d.mts.map +1 -0
- package/esm/mock/mock-speech-model.mjs +39 -0
- package/esm/mock/mock-speech-model.mjs.map +1 -0
- package/esm/mock/mock-transcription-model.d.mts +32 -0
- package/esm/mock/mock-transcription-model.d.mts.map +1 -0
- package/esm/mock/mock-transcription-model.mjs +36 -0
- package/esm/mock/mock-transcription-model.mjs.map +1 -0
- 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 +8 -0
- package/esm/planner/planner-run.d.mts.map +1 -1
- package/esm/planner/planner-run.mjs +457 -31
- package/esm/planner/planner-run.mjs.map +1 -1
- package/esm/planner/planner.d.mts.map +1 -1
- package/esm/planner/planner.mjs +26 -2
- package/esm/planner/planner.mjs.map +1 -1
- package/esm/planner/snapshot.mjs +95 -0
- package/esm/planner/snapshot.mjs.map +1 -0
- 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 +22 -0
- package/esm/rag/index.mjs +18 -0
- package/esm/rag/loaders/errors.d.mts +19 -0
- package/esm/rag/loaders/errors.d.mts.map +1 -0
- package/esm/rag/loaders/errors.mjs +25 -0
- package/esm/rag/loaders/errors.mjs.map +1 -0
- package/esm/rag/loaders/index.mjs +7 -0
- package/esm/rag/loaders/load-html.d.mts +26 -0
- package/esm/rag/loaders/load-html.d.mts.map +1 -0
- package/esm/rag/loaders/load-html.mjs +138 -0
- package/esm/rag/loaders/load-html.mjs.map +1 -0
- package/esm/rag/loaders/load-pdf.d.mts +38 -0
- package/esm/rag/loaders/load-pdf.d.mts.map +1 -0
- package/esm/rag/loaders/load-pdf.mjs +150 -0
- package/esm/rag/loaders/load-pdf.mjs.map +1 -0
- package/esm/rag/loaders/load-text.d.mts +47 -0
- package/esm/rag/loaders/load-text.d.mts.map +1 -0
- package/esm/rag/loaders/load-text.mjs +60 -0
- package/esm/rag/loaders/load-text.mjs.map +1 -0
- package/esm/rag/loaders/load-web.d.mts +42 -0
- package/esm/rag/loaders/load-web.d.mts.map +1 -0
- package/esm/rag/loaders/load-web.mjs +89 -0
- package/esm/rag/loaders/load-web.mjs.map +1 -0
- package/esm/rag/loaders/loader.type.d.mts +89 -0
- package/esm/rag/loaders/loader.type.d.mts.map +1 -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/pg-vector-store.d.mts +139 -0
- package/esm/rag/store/pg-vector-store.d.mts.map +1 -0
- package/esm/rag/store/pg-vector-store.mjs +328 -0
- package/esm/rag/store/pg-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/speech/index.mjs +3 -0
- package/esm/speech/speech.d.mts +65 -0
- package/esm/speech/speech.d.mts.map +1 -0
- package/esm/speech/speech.mjs +123 -0
- package/esm/speech/speech.mjs.map +1 -0
- package/esm/supervisor/as-tool.mjs +2 -2
- package/esm/supervisor/as-tool.mjs.map +1 -1
- package/esm/supervisor/entries.mjs +2 -2
- package/esm/supervisor/entries.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/transcribe/audio-input.d.mts +47 -0
- package/esm/transcribe/audio-input.d.mts.map +1 -0
- package/esm/transcribe/audio-input.mjs +84 -0
- package/esm/transcribe/audio-input.mjs.map +1 -0
- package/esm/transcribe/index.mjs +4 -0
- package/esm/transcribe/transcribe.d.mts +64 -0
- package/esm/transcribe/transcribe.d.mts.map +1 -0
- package/esm/transcribe/transcribe.mjs +128 -0
- package/esm/transcribe/transcribe.mjs.map +1 -0
- 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 +2572 -204
- package/llms.txt +21 -4
- package/package.json +7 -3
- package/skills/README.md +44 -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-agent-runs/SKILL.md +135 -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/generate-images/SKILL.md +138 -0
- package/skills/generate-speech/SKILL.md +139 -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/rag-loaders-and-stores/SKILL.md +164 -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/transcribe-audio/SKILL.md +157 -0
- 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
package/esm/ai.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai.mjs","names":["checkpointMemory","checkpointPg","checkpointRedis","snapshotMemory","snapshotPg","snapshotRedis"],"sources":["../../../../../../@warlock.js/ai/src/ai.ts"],"sourcesContent":["import { agent } from \"./agent/agent\";\nimport { batch } from \"./batch\";\nimport {\n checkpointMemory,\n checkpointPg,\n checkpointRedis,\n} from \"./checkpoint\";\nimport { setAIConfig } from \"./config\";\nimport { evalScorers } from \"./eval\";\nimport { budget, readBudgetFallbackSignal } from \"./middleware/builtins/budget\";\nimport { memory } from \"./memory\";\nimport { guardrail } from \"./middleware/builtins/guardrail\";\nimport { semanticCache } from \"./middleware/builtins/semantic-cache\";\nimport { composeMiddleware, forTool } from \"./middleware/helpers\";\nimport { mockRouter } from \"./mock\";\nimport { fallbackModel } from \"./model\";\nimport { orchestrator } from \"./orchestrator\";\nimport { planner } from \"./planner\";\nimport { spawnSubAgent } from \"./agent/spawn-sub-agent\";\nimport { snapshotMemory, snapshotPg, snapshotRedis } from \"./snapshot\";\nimport { fanOut, router } from \"./supervisor\";\nimport { supervisor } from \"./supervisor/supervisor\";\nimport { instruction } from \"./system-prompt/instruction\";\nimport { persona } from \"./system-prompt/persona\";\nimport { systemPrompt } from \"./system-prompt/system-prompt\";\nimport { tool } from \"./tool/tool\";\nimport { step } from \"./workflow/step\";\nimport { workflow } from \"./workflow/workflow\";\n\n/**\n * Top-level `ai` namespace — holds built-in factories and user-registered SDK adapters.\n *\n * Factories:\n * - `ai.tool(...)` — wrap an async function with a schema-validated input.\n * - `ai.agent(...)` — build an executable agent from model + tools + prompt.\n * - `ai.systemPrompt(...)` — compose a layered persona + instructions prompt.\n * - `ai.persona(text)` — reusable persona block (can be passed to `systemPrompt`).\n * - `ai.instruction(text)` — reusable instruction block (can be passed to `systemPrompt`).\n * - `ai.orchestrator(...)` — session-state manager wrapped around a supervisor (durable session, drift detection, resume, commands).\n * - `ai.memory(...)` — build an agent-memory store with WORKING (in-run scratch) and SEMANTIC (cache-driver `.similar()` recall) tiers.\n * - `ai.planner(...)` — build an executable that generates an ordered plan over registered capabilities, then runs it step-by-step.\n * - `ai.spawnSubAgent(spec)` — thin wrapper that builds a fresh one-shot `agent()` with an optional per-task `budget` and runs the task once. A general primitive (not planner-specific).\n * - `ai.router(...)` — build a supervisor-compatible routing agent from named intents.\n * - `ai.fanOut(unit, count)` — spread one agent/workflow into N intent entries for voting / self-consistency.\n * - `ai.batch(executable, items, opts?)` — run any executable over a dataset with bounded concurrency + per-item retry.\n * - `ai.fallbackModel(models, opts?)` — wrap an ordered model list that fails over to the next on transient provider errors.\n * - `ai.eval.{exact,contains,predicate,judge}(...)` — built-in scorer factories for `agent.eval(...)`.\n * - `ai.mockRouter(decisions, opts?)` — deterministic supervisor `route` callback for tests.\n * - `ai.checkpoint.{memory,pg,redis}()` — durable orchestrator session checkpoint stores.\n * - `ai.snapshot.{memory,pg,redis}()` — supervisor-run snapshot stores for `iterate: true` resume.\n * - `ai.openai.model(...)` / `ai.anthropic.model(...)` / ... once the adapter SDK is registered.\n *\n * @example\n * const alex = ai.persona(\"You are Alex, a TypeScript expert.\");\n * const replyIn = ai.instruction(\"Respond in {{language|English}}.\");\n *\n * const prompt = ai.systemPrompt().persona(alex).instruction(replyIn);\n *\n * const myAgent = ai.agent({\n * model: ai.openai.model({ name: \"gpt-4o\" }),\n * systemPrompt: prompt,\n * tools: [myTool],\n * });\n *\n * const result = await myAgent.execute(\"What is the weather in Cairo?\", {\n * placeholders: { language: \"Arabic\" },\n * });\n */\nexport const ai = {\n config: setAIConfig,\n tool,\n agent,\n systemPrompt,\n persona,\n instruction,\n workflow,\n step,\n supervisor,\n orchestrator,\n memory,\n planner,\n spawnSubAgent,\n router,\n fanOut,\n batch,\n fallbackModel,\n eval: evalScorers,\n mockRouter,\n middleware: {\n budget,\n guardrail,\n semanticCache,\n compose: composeMiddleware,\n forTool,\n readBudgetFallbackSignal,\n },\n checkpoint: {\n memory: checkpointMemory,\n pg: checkpointPg,\n redis: checkpointRedis,\n },\n snapshot: {\n memory: snapshotMemory,\n pg: snapshotPg,\n redis: snapshotRedis,\n },\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoEA,MAAa,KAAK;CAChB,QAAQ;CACR;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA,MAAM;CACN;CACA,YAAY;EACV;EACA;EACA;EACA,SAAS;EACT;EACA;CACF;CACA,YAAY;EACFA;EACJC;EACGC;CACT;CACA,UAAU;EACR,QAAQC;EACR,IAAIC;EACJ,OAAOC;CACT;AACF"}
|
|
1
|
+
{"version":3,"file":"ai.mjs","names":["checkpointMemory","checkpointPg","checkpointRedis","snapshotMemory","snapshotPg","snapshotRedis","guardrailSuite"],"sources":["../../../../../../@warlock.js/ai/src/ai.ts"],"sourcesContent":["import { agent } from \"./agent/agent\";\nimport { batch } from \"./batch\";\nimport { streamObject } from \"./object-stream\";\nimport { serve } from \"./serve\";\nimport {\n checkpointMemory,\n checkpointPg,\n checkpointRedis,\n} from \"./checkpoint\";\nimport { setAIConfig } from \"./config\";\nimport { dataset, evalScorers } from \"./eval\";\nimport { humanApproval } from \"./human/human-approval\";\nimport { human } from \"./human/register\";\nimport { image } from \"./image\";\nimport { speech } from \"./speech\";\nimport {\n audioFromBuffer,\n audioFromFile,\n audioMediaTypeForFilename,\n transcribe,\n} from \"./transcribe\";\nimport { resume } from \"./human/resume\";\nimport {\n interruptMemory,\n interruptPg,\n interruptRedis,\n} from \"./human/stores\";\nimport { guardrail as guardrailSuite } from \"./guard/guardrail\";\nimport { budget, readBudgetFallbackSignal } from \"./middleware/builtins/budget\";\nimport { memory } from \"./memory\";\nimport { guardrail } from \"./middleware/builtins/guardrail\";\nimport { semanticCache } from \"./middleware/builtins/semantic-cache\";\nimport { composeMiddleware, forTool } from \"./middleware/helpers\";\nimport { mockRouter } from \"./mock\";\nimport { fallbackModel } from \"./model\";\nimport { orchestrator } from \"./orchestrator\";\nimport { planner } from \"./planner\";\nimport { defaultPromptsManager } from \"./prompts/prompts-manager\";\nimport {\n bm25Rank,\n cacheVectorStore,\n chunk,\n hybridRank,\n keywordReranker,\n llmReranker,\n loadHtml,\n loadPdf,\n loadText,\n loadWeb,\n multiQuery,\n pgVectorStore,\n rag,\n reciprocalRankFusion,\n vectorLiteral,\n} from \"./rag\";\nimport { spawnSubAgent } from \"./agent/spawn-sub-agent\";\nimport { skills } from \"./skills\";\nimport { prompt } from \"./prompt\";\nimport { vcr } from \"./vcr\";\nimport { snapshotMemory, snapshotPg, snapshotRedis } from \"./snapshot\";\nimport { fanOut, router } from \"./supervisor\";\nimport { supervisor } from \"./supervisor/supervisor\";\nimport { team } from \"./team/team\";\nimport { instruction } from \"./system-prompt/instruction\";\nimport { persona } from \"./system-prompt/persona\";\nimport { systemPrompt } from \"./system-prompt/system-prompt\";\nimport { tool } from \"./tool/tool\";\nimport { step } from \"./workflow/step\";\nimport { workflow } from \"./workflow/workflow\";\n\n/**\n * The shape of the top-level `ai` namespace. Declared as an `interface` (not an\n * inferred `const` type) so satellite packages can attach their verb via\n * `declare module \"@warlock.js/ai\" { interface Ai { … } }` — e.g. `ai.workspace`,\n * `ai.tools`, `ai.mcp`, `ai.human`. The runtime object below is asserted to this\n * type; a satellite assigns its member on import.\n */\nexport interface Ai {\n config: typeof setAIConfig;\n tool: typeof tool;\n agent: typeof agent;\n systemPrompt: typeof systemPrompt;\n persona: typeof persona;\n instruction: typeof instruction;\n workflow: typeof workflow;\n step: typeof step;\n supervisor: typeof supervisor;\n team: typeof team;\n orchestrator: typeof orchestrator;\n memory: typeof memory;\n skills: typeof skills;\n planner: typeof planner;\n rag: typeof rag & {\n keywordReranker: typeof keywordReranker;\n llmReranker: typeof llmReranker;\n chunk: typeof chunk;\n cacheVectorStore: typeof cacheVectorStore;\n pgVectorStore: typeof pgVectorStore;\n vectorLiteral: typeof vectorLiteral;\n loadText: typeof loadText;\n loadHtml: typeof loadHtml;\n loadWeb: typeof loadWeb;\n loadPdf: typeof loadPdf;\n bm25Rank: typeof bm25Rank;\n reciprocalRankFusion: typeof reciprocalRankFusion;\n hybridRank: typeof hybridRank;\n multiQuery: typeof multiQuery;\n };\n spawnSubAgent: typeof spawnSubAgent;\n router: typeof router;\n fanOut: typeof fanOut;\n batch: typeof batch;\n /** Structured-output streaming — partial-object snapshots + a strict final parse (A1). */\n streamObject: typeof streamObject;\n /** Serve an executable as an SSE HTTP endpoint — production serving primitive (A3). */\n serve: typeof serve;\n /**\n * Generate images from a text prompt — the image-output verb of the\n * output-modality track (Theme I). Wraps an `ImageModelContract` (from\n * `openai.image(...)` / `google.image(...)`) in the uniform\n * never-throws `{ data, error, usage, report }` envelope with cost-truth\n * and observability.\n */\n image: typeof image;\n /** Text-to-speech (TTS) — the audio-output verb of the modality track (Theme I). */\n speech: typeof speech;\n /** Speech-to-text (STT / transcription) — the audio-input verb of the modality track (Theme I). */\n transcribe: typeof transcribe;\n /** Read an audio file from disk → `AudioInput` for `ai.transcribe` (non-AI file plumbing). */\n audioFromFile: typeof audioFromFile;\n /** Package raw audio bytes → `AudioInput` for `ai.transcribe`. */\n audioFromBuffer: typeof audioFromBuffer;\n /** Resolve the audio media type from a filename's extension. */\n audioMediaTypeForFilename: typeof audioMediaTypeForFilename;\n fallbackModel: typeof fallbackModel;\n eval: typeof evalScorers;\n dataset: typeof dataset;\n prompt: typeof prompt;\n /**\n * Process-wide registry of named, versioned `systemPrompt(...)` builders,\n * keyed by `name@version`. A `systemPrompt(input, { name })` (or any\n * `.meta({ name })` rename) auto-registers here; `ai.prompts.get(name)` /\n * `.resolve(name)` reads them back, and `systemPrompt().merge(name)` folds a\n * registered prompt into a new one.\n */\n prompts: ReturnType<typeof defaultPromptsManager>;\n vcr: typeof vcr;\n mockRouter: typeof mockRouter;\n middleware: {\n budget: typeof budget;\n guardrail: typeof guardrail;\n semanticCache: typeof semanticCache;\n compose: typeof composeMiddleware;\n forTool: typeof forTool;\n readBudgetFallbackSignal: typeof readBudgetFallbackSignal;\n };\n checkpoint: {\n memory: typeof checkpointMemory;\n pg: typeof checkpointPg;\n redis: typeof checkpointRedis;\n };\n snapshot: {\n memory: typeof snapshotMemory;\n pg: typeof snapshotPg;\n redis: typeof snapshotRedis;\n };\n /**\n * Human-in-the-loop tool approval (interrupt / resume).\n *\n * - `human.approval(options)` — the `tool.before` approval-gate middleware.\n * - `human.resume(id, decision, options)` — out-of-process durable resume.\n * - `human.interrupt.{memory,pg,redis}()` — durable {@link InterruptStore}\n * factories (memory ships real; pg/redis are lazy optional peers).\n */\n human: {\n approval: typeof humanApproval;\n resume: typeof resume;\n interrupt: {\n memory: typeof interruptMemory;\n pg: typeof interruptPg;\n redis: typeof interruptRedis;\n };\n };\n /**\n * Content-intelligence guardrail. `ai.guardrail(options)` builds a composed\n * input / output / tool middleware; `ai.guardrail.{pii,topic,injection,moderation}`\n * are the built-in detector factories.\n */\n guardrail: typeof guardrailSuite;\n}\n\n/**\n * Top-level `ai` namespace — holds built-in factories and user-registered SDK adapters.\n *\n * Factories:\n * - `ai.tool(...)` — wrap an async function with a schema-validated input.\n * - `ai.agent(...)` — build an executable agent from model + tools + prompt.\n * - `ai.systemPrompt(...)` — compose a layered persona + instructions prompt.\n * - `ai.persona(text)` — reusable persona block (can be passed to `systemPrompt`).\n * - `ai.instruction(text)` — reusable instruction block (can be passed to `systemPrompt`).\n * - `ai.orchestrator(...)` — session-state manager wrapped around a supervisor (durable session, drift detection, resume, commands).\n * - `ai.memory(...)` — build an agent-memory store with WORKING (in-run scratch) and SEMANTIC (cache-driver `.similar()` recall) tiers.\n * - `ai.skills(...)` — build a runtime skills library (always-injected metadata catalog + on-demand loadSkill tool).\n * - `ai.planner(...)` — build an executable that generates an ordered plan over registered capabilities, then runs it step-by-step.\n * - `ai.spawnSubAgent(spec)` — thin wrapper that builds a fresh one-shot `agent()` with an optional per-task `budget` and runs the task once. A general primitive (not planner-specific).\n * - `ai.router(...)` — build a supervisor-compatible routing agent from named intents.\n * - `ai.fanOut(unit, count)` — spread one agent/workflow into N intent entries for voting / self-consistency.\n * - `ai.batch(executable, items, opts?)` — run any executable over a dataset with bounded concurrency + per-item retry.\n * - `ai.fallbackModel(models, opts?)` — wrap an ordered model list that fails over to the next on transient provider errors.\n * - `ai.eval.{exact,contains,predicate,judge}(...)` — built-in scorer factories for `agent.eval(...)`.\n * - `ai.mockRouter(decisions, opts?)` — deterministic supervisor `route` callback for tests.\n * - `ai.checkpoint.{memory,pg,redis}()` — durable orchestrator session checkpoint stores.\n * - `ai.snapshot.{memory,pg,redis}()` — supervisor-run snapshot stores for `iterate: true` resume.\n * - `ai.human.approval(...)` / `ai.human.resume(...)` / `ai.human.interrupt.{memory,pg,redis}()` — human-in-the-loop tool approval (interrupt / resume).\n * - `ai.guardrail(options)` + `ai.guardrail.{pii,topic,injection,moderation}(...)` — content-intelligence guardrails (moderation / PII / injection / topic).\n * - `ai.openai.model(...)` / `ai.anthropic.model(...)` / ... once the adapter SDK is registered.\n *\n * @example\n * const alex = ai.persona(\"You are Alex, a TypeScript expert.\");\n * const replyIn = ai.instruction(\"Respond in {{language|English}}.\");\n *\n * const prompt = ai.systemPrompt().persona(alex).instruction(replyIn);\n *\n * const myAgent = ai.agent({\n * model: ai.openai.model({ name: \"gpt-4o\" }),\n * systemPrompt: prompt,\n * tools: [myTool],\n * });\n *\n * const result = await myAgent.execute(\"What is the weather in Cairo?\", {\n * placeholders: { language: \"Arabic\" },\n * });\n */\nexport const ai = {\n config: setAIConfig,\n tool,\n agent,\n systemPrompt,\n persona,\n instruction,\n workflow,\n step,\n supervisor,\n team,\n orchestrator,\n memory,\n skills,\n planner,\n rag: Object.assign(rag, {\n keywordReranker,\n llmReranker,\n chunk,\n cacheVectorStore,\n pgVectorStore,\n vectorLiteral,\n loadText,\n loadHtml,\n loadWeb,\n loadPdf,\n bm25Rank,\n reciprocalRankFusion,\n hybridRank,\n multiQuery,\n }),\n spawnSubAgent,\n router,\n fanOut,\n batch,\n streamObject,\n serve,\n image,\n speech,\n transcribe,\n audioFromFile,\n audioFromBuffer,\n audioMediaTypeForFilename,\n fallbackModel,\n eval: evalScorers,\n dataset,\n prompt,\n prompts: defaultPromptsManager(),\n vcr,\n mockRouter,\n middleware: {\n budget,\n guardrail,\n semanticCache,\n compose: composeMiddleware,\n forTool,\n readBudgetFallbackSignal,\n },\n checkpoint: {\n memory: checkpointMemory,\n pg: checkpointPg,\n redis: checkpointRedis,\n },\n snapshot: {\n memory: snapshotMemory,\n pg: snapshotPg,\n redis: snapshotRedis,\n },\n human,\n guardrail: guardrailSuite,\n // Asserted (not `: Ai`) so a consumer build that augments `Ai` with a\n // satellite verb (e.g. `workspace`) doesn't flag this literal as missing it.\n} as Ai;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyOA,MAAa,KAAK;CAChB,QAAQ;CACR;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA,KAAK,OAAO,OAAO,KAAK;EACtB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;CACD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA,MAAM;CACN;CACA;CACA,SAAS,sBAAsB;CAC/B;CACA;CACA,YAAY;EACV;EACA;EACA;EACA,SAAS;EACT;EACA;CACF;CACA,YAAY;EACV,QAAQA;EACJC;EACGC;CACT;CACA,UAAU;EACR,QAAQC;EACR,IAAIC;EACJ,OAAOC;CACT;CACA;CACA,WAAWC;AAGb"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batch.d.mts","names":[],"sources":["../../../../../../../@warlock.js/ai/src/batch/batch.ts"],"mappings":";;;;;;;;
|
|
1
|
+
{"version":3,"file":"batch.d.mts","names":[],"sources":["../../../../../../../@warlock.js/ai/src/batch/batch.ts"],"mappings":";;;;;;;;AAyDA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAsB,KAAA,mCAAwC,UAAA,GAAa,aAAA,EACzE,UAAA,EAAY,kBAAA,CAAmB,MAAA,EAAQ,QAAA,EAAU,OAAA,GACjD,KAAA,WAAgB,MAAA,IAChB,OAAA,GAAS,YAAA,CAAa,OAAA,IACrB,OAAA,CAAQ,WAAA,CAAY,OAAA"}
|
package/esm/batch/batch.mjs
CHANGED
|
@@ -6,6 +6,10 @@ import { runBatchItem } from "./run-batch-item.mjs";
|
|
|
6
6
|
import { runWithConcurrency } from "./run-with-concurrency.mjs";
|
|
7
7
|
|
|
8
8
|
//#region ../@warlock.js/ai/src/batch/batch.ts
|
|
9
|
+
/** Batch size above which an unset (unbounded) concurrency warns once (D5). */
|
|
10
|
+
const BATCH_UNBOUNDED_WARN_THRESHOLD = 50;
|
|
11
|
+
/** Process-lifetime flag so the unbounded-batch warning fires at most once. */
|
|
12
|
+
let warnedUnboundedBatch = false;
|
|
9
13
|
/**
|
|
10
14
|
* Run an executable AI primitive (agent, workflow, supervisor, tool,
|
|
11
15
|
* or anything satisfying {@link ExecutableContract}) over a dataset
|
|
@@ -63,11 +67,27 @@ var BatchRun = class {
|
|
|
63
67
|
* the rolled-up {@link BatchResult}. Runs once per `batch()` call.
|
|
64
68
|
*/
|
|
65
69
|
async run() {
|
|
66
|
-
const concurrency = this.
|
|
70
|
+
const concurrency = this.resolveConcurrency();
|
|
67
71
|
await runWithConcurrency(this.items.length, concurrency, (index) => this.processItem(index));
|
|
68
72
|
return this.buildResult();
|
|
69
73
|
}
|
|
70
74
|
/**
|
|
75
|
+
* Resolve the effective concurrency from {@link BatchOptions.concurrency}
|
|
76
|
+
* (D5). An explicit number or `"unbounded"` is honored as-is; an omitted
|
|
77
|
+
* value runs unbounded for back-compat but warns once (outside tests)
|
|
78
|
+
* for a large batch so an accidental all-at-once run is visible.
|
|
79
|
+
*/
|
|
80
|
+
resolveConcurrency() {
|
|
81
|
+
const configured = this.options.concurrency;
|
|
82
|
+
if (configured === "unbounded") return this.items.length;
|
|
83
|
+
if (typeof configured === "number") return configured;
|
|
84
|
+
if (this.items.length > BATCH_UNBOUNDED_WARN_THRESHOLD && !warnedUnboundedBatch && !process.env.VITEST && process.env.NODE_ENV !== "test") {
|
|
85
|
+
warnedUnboundedBatch = true;
|
|
86
|
+
console.warn(`[warlock-ai] ai.batch() is running ${this.items.length} items with unbounded concurrency (no \`concurrency\` set). Each concurrent item consumes tokens/quota/memory — pass an explicit \`concurrency\` cap, or \`concurrency: "unbounded"\` to silence this.`);
|
|
87
|
+
}
|
|
88
|
+
return this.items.length;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
71
91
|
* Run a single item with retry, record it positionally, then fire
|
|
72
92
|
* the `onItem` hook. A throw from the hook is swallowed — a progress
|
|
73
93
|
* callback must never break the batch.
|
package/esm/batch/batch.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batch.mjs","names":[],"sources":["../../../../../../../@warlock.js/ai/src/batch/batch.ts"],"sourcesContent":["import type { BaseReport } from \"../contracts/result/base-report.type\";\nimport { REPORT_SCHEMA_VERSION } from \"../contracts/result/base-report.type\";\nimport type { BaseResult } from \"../contracts/result/base-result.type\";\nimport type { ExecutableContract } from \"../contracts/executable.contract\";\nimport type { ExecuteResult } from \"../contracts/result/execute-result.type\";\nimport type { Usage } from \"../contracts/result/usage.type\";\nimport { accumulateCost } from \"../utils/compute-cost\";\nimport { generateRunId } from \"../utils/generate-run-id\";\nimport { stampReportLineage } from \"../utils/stamp-report-lineage\";\nimport type {\n BatchItemResult,\n BatchOptions,\n BatchReport,\n BatchResult,\n} from \"./batch.type\";\nimport { runBatchItem } from \"./run-batch-item\";\nimport { runWithConcurrency } from \"./run-with-concurrency\";\n\n/**\n * Run an executable AI primitive (agent, workflow, supervisor, tool,\n * or anything satisfying {@link ExecutableContract}) over a dataset\n * with bounded concurrency and per-item retry, returning per-item\n * outcomes plus rolled-up usage and a walkable report tree.\n *\n * **Role.** The fan-out primitive of `@warlock.js/ai`. Where an agent\n * runs once, `batch` runs the SAME executable N times — once per item\n * — and aggregates the results into the unified {@link ExecuteResult}\n * envelope, so a batch slots into cost dashboards and trace tooling\n * exactly like a single run does.\n *\n * **Isolation.** Items are independent: one item's failure (after its\n * retries are exhausted) never cancels a sibling, and the batch as a\n * whole never rejects — failures live on each {@link BatchItemResult}.\n * Reach for `result.report.failed` / `item.status` to inspect them.\n *\n * **Usage rollup.** `result.usage` and `result.report.usage` sum every\n * item's usage, satisfying the universal rollup invariant (\"own cost\n * + sum of children\"; a batch has zero own cost). Each item's own\n * report is attached under `report.children[]`, in original item\n * order, so a trace walker sees every run.\n *\n * @example\n * const result = await batch(summarizer, articles, {\n * concurrency: 4,\n * retry: { attempts: 3, backoff: \"exponential\" },\n * onItem: (item) => log.info(\"batch\", \"item\", \"settled\", { index: item.index }),\n * });\n *\n * console.log(`${result.report.succeeded}/${result.report.total} ok`);\n * console.log(`${result.usage.total} tokens total`);\n */\nexport async function batch<TInput, TOptions, TResult extends BaseResult = ExecuteResult>(\n executable: ExecutableContract<TInput, TOptions, TResult>,\n items: readonly TInput[],\n options: BatchOptions<TResult> = {},\n): Promise<BatchResult<TResult>> {\n return new BatchRun(executable, items, options).run();\n}\n\n/**\n * Per-call orchestration state for one {@link batch} invocation.\n * Instantiated fresh inside the factory so the mutable accumulators\n * (`results`, `usage`) are never shared across batches. Unexported —\n * callers only ever see the plain {@link BatchResult}.\n */\nclass BatchRun<TInput, TOptions, TResult extends BaseResult> {\n private readonly runId: string;\n private readonly results: BatchItemResult<TResult>[];\n private readonly startedAt = new Date().toISOString();\n private readonly startPerf = performance.now();\n\n public constructor(\n private readonly executable: ExecutableContract<TInput, TOptions, TResult>,\n private readonly items: readonly TInput[],\n private readonly options: BatchOptions<TResult>,\n ) {\n this.runId = generateRunId(\"batch\");\n this.results = new Array<BatchItemResult<TResult>>(items.length);\n }\n\n /**\n * Dispatch every item through the concurrency pool, then assemble\n * the rolled-up {@link BatchResult}. Runs once per `batch()` call.\n */\n public async run(): Promise<BatchResult<TResult>> {\n const concurrency = this.options.concurrency ?? this.items.length;\n\n await runWithConcurrency(this.items.length, concurrency, (index) =>\n this.processItem(index),\n );\n\n return this.buildResult();\n }\n\n /**\n * Run a single item with retry, record it positionally, then fire\n * the `onItem` hook. A throw from the hook is swallowed — a progress\n * callback must never break the batch.\n */\n private async processItem(index: number): Promise<void> {\n const item = await runBatchItem({\n index,\n input: this.items[index] as TInput,\n executable: this.executable,\n retry: this.options.retry,\n signal: this.options.signal,\n });\n\n this.results[index] = item;\n\n if (this.options.onItem) {\n try {\n await this.options.onItem(item);\n } catch {\n // A progress hook must never break the batch — swallow its throw.\n }\n }\n }\n\n /**\n * Fold the per-item outcomes into rolled-up usage, the child report\n * list, and the final {@link BatchResult}, then stamp lineage across\n * the whole subtree so every child shares this batch's root run id.\n */\n private buildResult(): BatchResult<TResult> {\n const usage: Usage = { input: 0, output: 0, total: 0 };\n const children: BaseReport[] = [];\n const data: (unknown | undefined)[] = new Array(this.items.length).fill(undefined);\n\n let succeeded = 0;\n let failed = 0;\n let cancelled = 0;\n\n for (const item of this.results) {\n if (item.status === \"completed\") {\n succeeded += 1;\n } else if (item.status === \"failed\") {\n failed += 1;\n } else {\n cancelled += 1;\n }\n\n const itemResult = item.result;\n if (itemResult) {\n this.mergeUsage(usage, itemResult.usage);\n\n if (\"report\" in itemResult && itemResult.report) {\n children.push(itemResult.report as BaseReport);\n }\n\n if (item.status === \"completed\" && \"data\" in itemResult) {\n data[item.index] = (itemResult as { data?: unknown }).data;\n }\n }\n }\n\n const report = this.buildReport(usage, children, { succeeded, failed, cancelled });\n\n stampReportLineage(report, {\n rootRunId: this.runId,\n sessionId: this.options.sessionId,\n });\n\n return {\n type: \"batch\",\n data,\n usage,\n report,\n items: this.results,\n };\n }\n\n /**\n * Add a child's usage into the running batch total. Scalar token\n * channels sum directly; the optional cost breakdown merges via\n * {@link accumulateCost} so a single unpriced child can't erase the\n * cost of priced siblings. Optional token sub-channels\n * (`cachedTokens`, etc.) accumulate only when some child reports\n * them, preserving the \"never reported anywhere\" signal.\n */\n private mergeUsage(target: Usage, child: Usage): void {\n target.input += child.input;\n target.output += child.output;\n target.total += child.total;\n\n if (child.cachedTokens !== undefined) {\n target.cachedTokens = (target.cachedTokens ?? 0) + child.cachedTokens;\n }\n\n if (child.reasoningTokens !== undefined) {\n target.reasoningTokens = (target.reasoningTokens ?? 0) + child.reasoningTokens;\n }\n\n if (child.cacheWriteTokens !== undefined) {\n target.cacheWriteTokens = (target.cacheWriteTokens ?? 0) + child.cacheWriteTokens;\n }\n\n const mergedCost = accumulateCost(target.cost, child.cost);\n if (mergedCost !== undefined) {\n target.cost = mergedCost;\n }\n }\n\n /**\n * Build the batch's own {@link BatchReport} node. `parentRunId` /\n * `rootRunId` are placeholders here — {@link stampReportLineage}\n * rewrites them across the whole subtree right after.\n */\n private buildReport(\n usage: Usage,\n children: BaseReport[],\n counts: { succeeded: number; failed: number; cancelled: number },\n ): BatchReport {\n const status = counts.failed > 0 || counts.cancelled > 0 ? \"failed\" : \"completed\";\n\n return {\n runId: this.runId,\n rootRunId: this.runId,\n name: this.options.name ?? \"batch\",\n type: \"batch\",\n status,\n startedAt: this.startedAt,\n endedAt: new Date().toISOString(),\n duration: performance.now() - this.startPerf,\n usage,\n children,\n total: this.items.length,\n succeeded: counts.succeeded,\n failed: counts.failed,\n cancelled: counts.cancelled,\n reportSchemaVersion: REPORT_SCHEMA_VERSION,\n };\n }\n}\n"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"batch.mjs","names":[],"sources":["../../../../../../../@warlock.js/ai/src/batch/batch.ts"],"sourcesContent":["import type { BaseReport } from \"../contracts/result/base-report.type\";\nimport { REPORT_SCHEMA_VERSION } from \"../contracts/result/base-report.type\";\nimport type { BaseResult } from \"../contracts/result/base-result.type\";\nimport type { ExecutableContract } from \"../contracts/executable.contract\";\nimport type { ExecuteResult } from \"../contracts/result/execute-result.type\";\nimport type { Usage } from \"../contracts/result/usage.type\";\nimport { accumulateCost } from \"../utils/compute-cost\";\nimport { generateRunId } from \"../utils/generate-run-id\";\nimport { stampReportLineage } from \"../utils/stamp-report-lineage\";\nimport type {\n BatchItemResult,\n BatchOptions,\n BatchReport,\n BatchResult,\n} from \"./batch.type\";\nimport { runBatchItem } from \"./run-batch-item\";\nimport { runWithConcurrency } from \"./run-with-concurrency\";\n\n/** Batch size above which an unset (unbounded) concurrency warns once (D5). */\nconst BATCH_UNBOUNDED_WARN_THRESHOLD = 50;\n\n/** Process-lifetime flag so the unbounded-batch warning fires at most once. */\nlet warnedUnboundedBatch = false;\n\n/**\n * Run an executable AI primitive (agent, workflow, supervisor, tool,\n * or anything satisfying {@link ExecutableContract}) over a dataset\n * with bounded concurrency and per-item retry, returning per-item\n * outcomes plus rolled-up usage and a walkable report tree.\n *\n * **Role.** The fan-out primitive of `@warlock.js/ai`. Where an agent\n * runs once, `batch` runs the SAME executable N times — once per item\n * — and aggregates the results into the unified {@link ExecuteResult}\n * envelope, so a batch slots into cost dashboards and trace tooling\n * exactly like a single run does.\n *\n * **Isolation.** Items are independent: one item's failure (after its\n * retries are exhausted) never cancels a sibling, and the batch as a\n * whole never rejects — failures live on each {@link BatchItemResult}.\n * Reach for `result.report.failed` / `item.status` to inspect them.\n *\n * **Usage rollup.** `result.usage` and `result.report.usage` sum every\n * item's usage, satisfying the universal rollup invariant (\"own cost\n * + sum of children\"; a batch has zero own cost). Each item's own\n * report is attached under `report.children[]`, in original item\n * order, so a trace walker sees every run.\n *\n * @example\n * const result = await batch(summarizer, articles, {\n * concurrency: 4,\n * retry: { attempts: 3, backoff: \"exponential\" },\n * onItem: (item) => log.info(\"batch\", \"item\", \"settled\", { index: item.index }),\n * });\n *\n * console.log(`${result.report.succeeded}/${result.report.total} ok`);\n * console.log(`${result.usage.total} tokens total`);\n */\nexport async function batch<TInput, TOptions, TResult extends BaseResult = ExecuteResult>(\n executable: ExecutableContract<TInput, TOptions, TResult>,\n items: readonly TInput[],\n options: BatchOptions<TResult> = {},\n): Promise<BatchResult<TResult>> {\n return new BatchRun(executable, items, options).run();\n}\n\n/**\n * Per-call orchestration state for one {@link batch} invocation.\n * Instantiated fresh inside the factory so the mutable accumulators\n * (`results`, `usage`) are never shared across batches. Unexported —\n * callers only ever see the plain {@link BatchResult}.\n */\nclass BatchRun<TInput, TOptions, TResult extends BaseResult> {\n private readonly runId: string;\n private readonly results: BatchItemResult<TResult>[];\n private readonly startedAt = new Date().toISOString();\n private readonly startPerf = performance.now();\n\n public constructor(\n private readonly executable: ExecutableContract<TInput, TOptions, TResult>,\n private readonly items: readonly TInput[],\n private readonly options: BatchOptions<TResult>,\n ) {\n this.runId = generateRunId(\"batch\");\n this.results = new Array<BatchItemResult<TResult>>(items.length);\n }\n\n /**\n * Dispatch every item through the concurrency pool, then assemble\n * the rolled-up {@link BatchResult}. Runs once per `batch()` call.\n */\n public async run(): Promise<BatchResult<TResult>> {\n const concurrency = this.resolveConcurrency();\n\n await runWithConcurrency(this.items.length, concurrency, (index) =>\n this.processItem(index),\n );\n\n return this.buildResult();\n }\n\n /**\n * Resolve the effective concurrency from {@link BatchOptions.concurrency}\n * (D5). An explicit number or `\"unbounded\"` is honored as-is; an omitted\n * value runs unbounded for back-compat but warns once (outside tests)\n * for a large batch so an accidental all-at-once run is visible.\n */\n private resolveConcurrency(): number {\n const configured = this.options.concurrency;\n\n if (configured === \"unbounded\") {\n return this.items.length;\n }\n if (typeof configured === \"number\") {\n return configured;\n }\n\n if (\n this.items.length > BATCH_UNBOUNDED_WARN_THRESHOLD &&\n !warnedUnboundedBatch &&\n !process.env.VITEST &&\n process.env.NODE_ENV !== \"test\"\n ) {\n warnedUnboundedBatch = true;\n console.warn(\n `[warlock-ai] ai.batch() is running ${this.items.length} items with unbounded concurrency (no \\`concurrency\\` set). ` +\n 'Each concurrent item consumes tokens/quota/memory — pass an explicit `concurrency` cap, or `concurrency: \"unbounded\"` to silence this.',\n );\n }\n\n return this.items.length;\n }\n\n /**\n * Run a single item with retry, record it positionally, then fire\n * the `onItem` hook. A throw from the hook is swallowed — a progress\n * callback must never break the batch.\n */\n private async processItem(index: number): Promise<void> {\n const item = await runBatchItem({\n index,\n input: this.items[index] as TInput,\n executable: this.executable,\n retry: this.options.retry,\n signal: this.options.signal,\n });\n\n this.results[index] = item;\n\n if (this.options.onItem) {\n try {\n await this.options.onItem(item);\n } catch {\n // A progress hook must never break the batch — swallow its throw.\n }\n }\n }\n\n /**\n * Fold the per-item outcomes into rolled-up usage, the child report\n * list, and the final {@link BatchResult}, then stamp lineage across\n * the whole subtree so every child shares this batch's root run id.\n */\n private buildResult(): BatchResult<TResult> {\n const usage: Usage = { input: 0, output: 0, total: 0 };\n const children: BaseReport[] = [];\n const data: (unknown | undefined)[] = new Array(this.items.length).fill(undefined);\n\n let succeeded = 0;\n let failed = 0;\n let cancelled = 0;\n\n for (const item of this.results) {\n if (item.status === \"completed\") {\n succeeded += 1;\n } else if (item.status === \"failed\") {\n failed += 1;\n } else {\n cancelled += 1;\n }\n\n const itemResult = item.result;\n if (itemResult) {\n this.mergeUsage(usage, itemResult.usage);\n\n if (\"report\" in itemResult && itemResult.report) {\n children.push(itemResult.report as BaseReport);\n }\n\n if (item.status === \"completed\" && \"data\" in itemResult) {\n data[item.index] = (itemResult as { data?: unknown }).data;\n }\n }\n }\n\n const report = this.buildReport(usage, children, { succeeded, failed, cancelled });\n\n stampReportLineage(report, {\n rootRunId: this.runId,\n sessionId: this.options.sessionId,\n });\n\n return {\n type: \"batch\",\n data,\n usage,\n report,\n items: this.results,\n };\n }\n\n /**\n * Add a child's usage into the running batch total. Scalar token\n * channels sum directly; the optional cost breakdown merges via\n * {@link accumulateCost} so a single unpriced child can't erase the\n * cost of priced siblings. Optional token sub-channels\n * (`cachedTokens`, etc.) accumulate only when some child reports\n * them, preserving the \"never reported anywhere\" signal.\n */\n private mergeUsage(target: Usage, child: Usage): void {\n target.input += child.input;\n target.output += child.output;\n target.total += child.total;\n\n if (child.cachedTokens !== undefined) {\n target.cachedTokens = (target.cachedTokens ?? 0) + child.cachedTokens;\n }\n\n if (child.reasoningTokens !== undefined) {\n target.reasoningTokens = (target.reasoningTokens ?? 0) + child.reasoningTokens;\n }\n\n if (child.cacheWriteTokens !== undefined) {\n target.cacheWriteTokens = (target.cacheWriteTokens ?? 0) + child.cacheWriteTokens;\n }\n\n const mergedCost = accumulateCost(target.cost, child.cost);\n if (mergedCost !== undefined) {\n target.cost = mergedCost;\n }\n }\n\n /**\n * Build the batch's own {@link BatchReport} node. `parentRunId` /\n * `rootRunId` are placeholders here — {@link stampReportLineage}\n * rewrites them across the whole subtree right after.\n */\n private buildReport(\n usage: Usage,\n children: BaseReport[],\n counts: { succeeded: number; failed: number; cancelled: number },\n ): BatchReport {\n const status = counts.failed > 0 || counts.cancelled > 0 ? \"failed\" : \"completed\";\n\n return {\n runId: this.runId,\n rootRunId: this.runId,\n name: this.options.name ?? \"batch\",\n type: \"batch\",\n status,\n startedAt: this.startedAt,\n endedAt: new Date().toISOString(),\n duration: performance.now() - this.startPerf,\n usage,\n children,\n total: this.items.length,\n succeeded: counts.succeeded,\n failed: counts.failed,\n cancelled: counts.cancelled,\n reportSchemaVersion: REPORT_SCHEMA_VERSION,\n };\n }\n}\n"],"mappings":"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"}
|
|
@@ -111,11 +111,18 @@ type BatchItemHandler<TResult extends BaseResult = ExecuteResult> = (item: Batch
|
|
|
111
111
|
*/
|
|
112
112
|
type BatchOptions<TResult extends BaseResult = ExecuteResult> = {
|
|
113
113
|
/**
|
|
114
|
-
* Maximum number of items running at once. A positive integer
|
|
115
|
-
*
|
|
116
|
-
* treated as `1` (fully serial).
|
|
114
|
+
* Maximum number of items running at once. A positive integer, or the
|
|
115
|
+
* literal `"unbounded"` to run the whole dataset at once (every item
|
|
116
|
+
* concurrent). Values `<= 0` are treated as `1` (fully serial).
|
|
117
|
+
*
|
|
118
|
+
* Omitting it still runs unbounded (back-compat), but for a large batch
|
|
119
|
+
* (> 50 items) that emits a one-time warning (outside tests) — each
|
|
120
|
+
* concurrent item can consume tokens, provider quota, and memory, so an
|
|
121
|
+
* accidental unbounded run is a cost/DoS foot-gun. Pass an explicit
|
|
122
|
+
* number to cap it, or `"unbounded"` to acknowledge the all-at-once
|
|
123
|
+
* behavior and silence the warning. (D5)
|
|
117
124
|
*/
|
|
118
|
-
concurrency?: number;
|
|
125
|
+
concurrency?: number | "unbounded";
|
|
119
126
|
/**
|
|
120
127
|
* Per-item retry policy, reusing the workflow {@link RetryConfig}
|
|
121
128
|
* semantics (attempts, backoff, `retryOn`, `onRetry`). Applied
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batch.type.d.mts","names":[],"sources":["../../../../../../../@warlock.js/ai/src/batch/batch.type.ts"],"mappings":";;;;;;;;;AAaA;;;;AAA2B;KAAf,eAAA;;;;;;;;;;;;;;;;;;;;;;AAuCF;AAUV;;KAvBY,eAAA,iBAAgC,UAAA,GAAa,aAAA;EAuBrB,mEArBlC,KAAA,UAsBA;EApBA,MAAA,EAAQ,eAAA;EAwBR;;;;EAnBA,MAAA,GAAS,OAAA,EA8CC;EA5CV,KAAA,GAAQ,OAAA,EA4Ca;EA1CrB,QAAA;AAAA;;;;;;;;KAUU,WAAA,GAAc,UAAU;EAClC,IAAA,WA+BmD;EA7BnD,KAAA,UA8BA;EA5BA,SAAA,UAqCA;EAnCA,MAAA,UAqCO;EAnCP,SAAA;AAAA;;;AAqCmB;AAYrB;;;;;;;;;;;;;;;;;KA1BY,WAAA,iBAA4B,UAAA,GAAa,aAAA,IAAiB,IAAA,CACpE,aAAA;EAGA,IAAA;EAgCU;;;;;EA1BV,IAAA,
|
|
1
|
+
{"version":3,"file":"batch.type.d.mts","names":[],"sources":["../../../../../../../@warlock.js/ai/src/batch/batch.type.ts"],"mappings":";;;;;;;;;AAaA;;;;AAA2B;KAAf,eAAA;;;;;;;;;;;;;;;;;;;;;;AAuCF;AAUV;;KAvBY,eAAA,iBAAgC,UAAA,GAAa,aAAA;EAuBrB,mEArBlC,KAAA,UAsBA;EApBA,MAAA,EAAQ,eAAA;EAwBR;;;;EAnBA,MAAA,GAAS,OAAA,EA8CC;EA5CV,KAAA,GAAQ,OAAA,EA4Ca;EA1CrB,QAAA;AAAA;;;;;;;;KAUU,WAAA,GAAc,UAAU;EAClC,IAAA,WA+BmD;EA7BnD,KAAA,UA8BA;EA5BA,SAAA,UAqCA;EAnCA,MAAA,UAqCO;EAnCP,SAAA;AAAA;;;AAqCmB;AAYrB;;;;;;;;;;;;;;;;;KA1BY,WAAA,iBAA4B,UAAA,GAAa,aAAA,IAAiB,IAAA,CACpE,aAAA;EAGA,IAAA;EAgCU;;;;;EA1BV,IAAA,2BAgD0B;EA9C1B,KAAA,EAAO,eAAA,CAAgB,OAAA,KAqDd;EAnDT,MAAA,EAAQ,WAAA;AAAA;;;;;;;;;;KAYE,gBAAA,iBAAiC,UAAA,GAAa,aAAA,KACxD,IAAA,EAAM,eAAA,CAAgB,OAAA,aACZ,OAAA;;;;;AA6CN;;KArCM,YAAA,iBAA6B,UAAA,GAAa,aAAA;;;;;;;;;;;;;EAapD,WAAA;;;;;;;EAOA,KAAA,GAAQ,WAAA;EAER,MAAA,GAAS,gBAAA,CAAiB,OAAA;;;;;;;EAO1B,MAAA,GAAS,WAAA;;;;;;EAMT,SAAA;EAEA,IAAA;AAAA"}
|
package/esm/config.d.mts
CHANGED
|
@@ -23,8 +23,25 @@ import { CacheDriver } from "@warlock.js/cache";
|
|
|
23
23
|
* Phase 3.2 deliberately removed the previous `configureAI()` bag
|
|
24
24
|
* because it was growing unbounded. Treat new fields here with the
|
|
25
25
|
* same suspicion.
|
|
26
|
+
*
|
|
27
|
+
* **Augmentable.** Declared as an `interface` (not a `type` alias) so
|
|
28
|
+
* observability/tooling packages can attach their own opaque config slot
|
|
29
|
+
* via declaration merging WITHOUT core importing them — keeping core
|
|
30
|
+
* dependency-free. For example `@warlock.js/ai-panoptic` adds a
|
|
31
|
+
* `panoptic?` field:
|
|
32
|
+
*
|
|
33
|
+
* ```ts
|
|
34
|
+
* declare module "@warlock.js/ai" {
|
|
35
|
+
* interface AIConfig {
|
|
36
|
+
* panoptic?: PanopticConfig;
|
|
37
|
+
* }
|
|
38
|
+
* }
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* `setAIConfig` stores the whole object via `Object.assign`, so any
|
|
42
|
+
* augmented field is preserved even though core never reads it.
|
|
26
43
|
*/
|
|
27
|
-
|
|
44
|
+
interface AIConfig {
|
|
28
45
|
/**
|
|
29
46
|
* Default `@warlock.js/cache` driver for cache-backed consumers that
|
|
30
47
|
* didn't supply their own `store` — currently the `semanticCache`
|
|
@@ -75,7 +92,26 @@ type AIConfig = {
|
|
|
75
92
|
* ai.config({ defaultSnapshotStore: ai.snapshot.memory() });
|
|
76
93
|
*/
|
|
77
94
|
defaultSnapshotStore?: SnapshotStore;
|
|
78
|
-
}
|
|
95
|
+
}
|
|
96
|
+
/** A listener notified after every `setAIConfig` merge. */
|
|
97
|
+
type ConfigListener = (config: AIConfig) => void;
|
|
98
|
+
/**
|
|
99
|
+
* Subscribe to config changes. The listener fires after every
|
|
100
|
+
* {@link setAIConfig} merge with a fresh snapshot of the full config —
|
|
101
|
+
* the seam observability/tooling packages use to react when their
|
|
102
|
+
* augmented slot (e.g. `panoptic`) is set, WITHOUT core importing them.
|
|
103
|
+
*
|
|
104
|
+
* Mirrors the dependency-inversion of the `Observer` registry: core
|
|
105
|
+
* exposes the structural hook; the tool subscribes on its side-effect
|
|
106
|
+
* import. To also catch config that was applied *before* the subscription,
|
|
107
|
+
* read {@link getAIConfig} once right after subscribing.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* import { onConfigApplied, getAIConfig } from "@warlock.js/ai";
|
|
111
|
+
* onConfigApplied((config) => applyPanopticConfig(config.panoptic));
|
|
112
|
+
* applyPanopticConfig(getAIConfig().panoptic); // catch pre-set config
|
|
113
|
+
*/
|
|
114
|
+
declare function onConfigApplied(listener: ConfigListener): void;
|
|
79
115
|
/**
|
|
80
116
|
* Set or extend process-wide AI configuration. Merges over existing
|
|
81
117
|
* values — fields not present in `partial` keep whatever was set
|
|
@@ -122,5 +158,5 @@ declare function resolveDefaultCheckpointStore(): CheckpointStore | undefined;
|
|
|
122
158
|
*/
|
|
123
159
|
declare function resolveDefaultSnapshotStore(): SnapshotStore | undefined;
|
|
124
160
|
//#endregion
|
|
125
|
-
export { AIConfig, getAIConfig, resolveDefaultCheckpointStore, resolveDefaultSnapshotStore, resolveDefaultStore, setAIConfig };
|
|
161
|
+
export { AIConfig, getAIConfig, onConfigApplied, resolveDefaultCheckpointStore, resolveDefaultSnapshotStore, resolveDefaultStore, setAIConfig };
|
|
126
162
|
//# sourceMappingURL=config.d.mts.map
|
package/esm/config.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.mts","names":[],"sources":["../../../../../../@warlock.js/ai/src/config.ts"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"config.d.mts","names":[],"sources":["../../../../../../@warlock.js/ai/src/config.ts"],"mappings":";;;;;;;AA0CA;;;;;;;;;;;;;;;AAoDsC;AACrC;;;;AAKsC;AAoBvC;;;;AAAwD;AAmBxD;;;;;;;;;;UAjGiB,QAAA;EAiGwC;;AAAQ;AAuBjE;;;;AAAuC;AAYvC;;;;AAAkD;AAUlD;;;;AAAgE;AAUhE;;;;AAA4D;EAhI1D,YAAA,GAAe,WAAA;;;;;;;;;;;;;EAcf,sBAAA,GAAyB,eAAA;;;;;;;;;;;;;EAczB,oBAAA,GAAuB,aAAA;AAAA;;KAMpB,cAAA,IAAkB,MAAgB,EAAR,QAAQ;;;;;;;;;;;;;;;;;iBAoBvB,eAAA,CAAgB,QAAwB,EAAd,cAAc;;;;;;;;;;;;;;;;iBAmBxC,WAAA,CAAY,OAAA,EAAS,OAAA,CAAQ,QAAA,IAAY,QAAA;;;;;;iBAuBzC,WAAA,IAAe,QAAQ;;;;;;;;;iBAYvB,mBAAA,IAAuB,WAAW;;;;;;;iBAUlC,6BAAA,IAAiC,eAAe;;;;;;;iBAUhD,2BAAA,IAA+B,aAAa"}
|
package/esm/config.mjs
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
//#region ../@warlock.js/ai/src/config.ts
|
|
2
2
|
const aiConfig = {};
|
|
3
|
+
const configListeners = [];
|
|
4
|
+
/**
|
|
5
|
+
* Subscribe to config changes. The listener fires after every
|
|
6
|
+
* {@link setAIConfig} merge with a fresh snapshot of the full config —
|
|
7
|
+
* the seam observability/tooling packages use to react when their
|
|
8
|
+
* augmented slot (e.g. `panoptic`) is set, WITHOUT core importing them.
|
|
9
|
+
*
|
|
10
|
+
* Mirrors the dependency-inversion of the `Observer` registry: core
|
|
11
|
+
* exposes the structural hook; the tool subscribes on its side-effect
|
|
12
|
+
* import. To also catch config that was applied *before* the subscription,
|
|
13
|
+
* read {@link getAIConfig} once right after subscribing.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* import { onConfigApplied, getAIConfig } from "@warlock.js/ai";
|
|
17
|
+
* onConfigApplied((config) => applyPanopticConfig(config.panoptic));
|
|
18
|
+
* applyPanopticConfig(getAIConfig().panoptic); // catch pre-set config
|
|
19
|
+
*/
|
|
20
|
+
function onConfigApplied(listener) {
|
|
21
|
+
configListeners.push(listener);
|
|
22
|
+
}
|
|
3
23
|
/**
|
|
4
24
|
* Set or extend process-wide AI configuration. Merges over existing
|
|
5
25
|
* values — fields not present in `partial` keep whatever was set
|
|
@@ -17,7 +37,11 @@ const aiConfig = {};
|
|
|
17
37
|
*/
|
|
18
38
|
function setAIConfig(partial) {
|
|
19
39
|
Object.assign(aiConfig, partial);
|
|
20
|
-
|
|
40
|
+
const snapshot = { ...aiConfig };
|
|
41
|
+
for (const listener of configListeners) try {
|
|
42
|
+
listener(snapshot);
|
|
43
|
+
} catch {}
|
|
44
|
+
return snapshot;
|
|
21
45
|
}
|
|
22
46
|
/**
|
|
23
47
|
* Read the current AI config snapshot. Returns a shallow copy so
|
|
@@ -58,5 +82,5 @@ function resolveDefaultSnapshotStore() {
|
|
|
58
82
|
}
|
|
59
83
|
|
|
60
84
|
//#endregion
|
|
61
|
-
export { getAIConfig, resolveDefaultCheckpointStore, resolveDefaultSnapshotStore, resolveDefaultStore, setAIConfig };
|
|
85
|
+
export { getAIConfig, onConfigApplied, resolveDefaultCheckpointStore, resolveDefaultSnapshotStore, resolveDefaultStore, setAIConfig };
|
|
62
86
|
//# sourceMappingURL=config.mjs.map
|
package/esm/config.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.mjs","names":[],"sources":["../../../../../../@warlock.js/ai/src/config.ts"],"sourcesContent":["import type { CacheDriver } from \"@warlock.js/cache\";\nimport type { CheckpointStore } from \"./contracts/orchestrator/checkpoint-store.contract\";\nimport type { SnapshotStore } from \"./contracts/orchestrator/snapshot-store.contract\";\n\n/**\n * Process-wide `@warlock.js/ai` configuration. **Intentionally tiny.**\n * Lives here only for genuinely cross-cutting defaults that would\n * otherwise force users to wire the same value into every consumer.\n *\n * **What lives here.** A field earns a slot only when it satisfies\n * all three:\n * 1. Multiple unrelated consumers need the same value.\n * 2. The value is infrastructure (drivers, clients, pools), not\n * behavior (kill-switches, mode flags).\n * 3. Per-call override doesn't make sense for the use case.\n *\n * **What does NOT live here.** Logger config (use\n * `@warlock.js/logger` directly). Per-primitive feature flags\n * (live on the relevant config type). Anything that's really one\n * consumer's concern (lives on that consumer).\n *\n * Phase 3.2 deliberately removed the previous `configureAI()` bag\n * because it was growing unbounded. Treat new fields here with the\n * same suspicion.\n */\nexport
|
|
1
|
+
{"version":3,"file":"config.mjs","names":[],"sources":["../../../../../../@warlock.js/ai/src/config.ts"],"sourcesContent":["import type { CacheDriver } from \"@warlock.js/cache\";\nimport type { CheckpointStore } from \"./contracts/orchestrator/checkpoint-store.contract\";\nimport type { SnapshotStore } from \"./contracts/orchestrator/snapshot-store.contract\";\n\n/**\n * Process-wide `@warlock.js/ai` configuration. **Intentionally tiny.**\n * Lives here only for genuinely cross-cutting defaults that would\n * otherwise force users to wire the same value into every consumer.\n *\n * **What lives here.** A field earns a slot only when it satisfies\n * all three:\n * 1. Multiple unrelated consumers need the same value.\n * 2. The value is infrastructure (drivers, clients, pools), not\n * behavior (kill-switches, mode flags).\n * 3. Per-call override doesn't make sense for the use case.\n *\n * **What does NOT live here.** Logger config (use\n * `@warlock.js/logger` directly). Per-primitive feature flags\n * (live on the relevant config type). Anything that's really one\n * consumer's concern (lives on that consumer).\n *\n * Phase 3.2 deliberately removed the previous `configureAI()` bag\n * because it was growing unbounded. Treat new fields here with the\n * same suspicion.\n *\n * **Augmentable.** Declared as an `interface` (not a `type` alias) so\n * observability/tooling packages can attach their own opaque config slot\n * via declaration merging WITHOUT core importing them — keeping core\n * dependency-free. For example `@warlock.js/ai-panoptic` adds a\n * `panoptic?` field:\n *\n * ```ts\n * declare module \"@warlock.js/ai\" {\n * interface AIConfig {\n * panoptic?: PanopticConfig;\n * }\n * }\n * ```\n *\n * `setAIConfig` stores the whole object via `Object.assign`, so any\n * augmented field is preserved even though core never reads it.\n */\nexport interface AIConfig {\n /**\n * Default `@warlock.js/cache` driver for cache-backed consumers that\n * didn't supply their own `store` — currently the `semanticCache`\n * middleware's vector store. Declaring it once here removes the\n * repetition across middleware declarations.\n *\n * NOT the snapshot-persistence fallback anymore. Supervisor /\n * workflow / orchestrator resume snapshots resolve through\n * {@link AIConfig.defaultSnapshotStore} (a {@link SnapshotStore}),\n * never this driver.\n *\n * Per-declaration overrides (`semanticCache({ store })`) win when\n * supplied. Set this once at app boot, *after* you've constructed\n * your driver.\n *\n * @example\n * import { cache } from \"@warlock.js/cache\";\n * import { ai } from \"@warlock.js/ai\";\n *\n * ai.config({\n * defaultStore: cache.driver(\"redis\", { client: redisClient }),\n * });\n */\n defaultStore?: CacheDriver<any, any>;\n\n /**\n * Default {@link CheckpointStore} for every orchestrator that didn't\n * supply its own `checkpointStore` (orchestrator.md §15.2). Holds\n * durable session state — `state`, `turn_index`, drift `signature`,\n * compaction locks. Per-orchestrator `checkpointStore` wins when\n * supplied. Set once at app boot.\n *\n * @example\n * import { ai } from \"@warlock.js/ai\";\n *\n * ai.config({ defaultCheckpointStore: ai.checkpoint.memory() });\n */\n defaultCheckpointStore?: CheckpointStore;\n\n /**\n * Default {@link SnapshotStore} for every orchestrator that didn't\n * supply its own `snapshotStore` (orchestrator.md §15.2). Holds the\n * internal supervisor run state used to resume an interrupted\n * `iterate: true` turn. Per-orchestrator `snapshotStore` wins when\n * supplied. Set once at app boot.\n *\n * @example\n * import { ai } from \"@warlock.js/ai\";\n *\n * ai.config({ defaultSnapshotStore: ai.snapshot.memory() });\n */\n defaultSnapshotStore?: SnapshotStore;\n};\n\nconst aiConfig: AIConfig = {};\n\n/** A listener notified after every `setAIConfig` merge. */\ntype ConfigListener = (config: AIConfig) => void;\n\nconst configListeners: ConfigListener[] = [];\n\n/**\n * Subscribe to config changes. The listener fires after every\n * {@link setAIConfig} merge with a fresh snapshot of the full config —\n * the seam observability/tooling packages use to react when their\n * augmented slot (e.g. `panoptic`) is set, WITHOUT core importing them.\n *\n * Mirrors the dependency-inversion of the `Observer` registry: core\n * exposes the structural hook; the tool subscribes on its side-effect\n * import. To also catch config that was applied *before* the subscription,\n * read {@link getAIConfig} once right after subscribing.\n *\n * @example\n * import { onConfigApplied, getAIConfig } from \"@warlock.js/ai\";\n * onConfigApplied((config) => applyPanopticConfig(config.panoptic));\n * applyPanopticConfig(getAIConfig().panoptic); // catch pre-set config\n */\nexport function onConfigApplied(listener: ConfigListener): void {\n configListeners.push(listener);\n}\n\n/**\n * Set or extend process-wide AI configuration. Merges over existing\n * values — fields not present in `partial` keep whatever was set\n * before (or stay unset). Call once at app boot, before constructing\n * any agent / supervisor / middleware that should pick up the\n * defaults.\n *\n * Returns the merged config so callers can verify what landed.\n *\n * @example\n * import { cache } from \"@warlock.js/cache\";\n * import { ai } from \"@warlock.js/ai\";\n *\n * ai.config({ defaultStore: cache.driver(\"redis\", { client }) });\n */\nexport function setAIConfig(partial: Partial<AIConfig>): AIConfig {\n Object.assign(aiConfig, partial);\n const snapshot = { ...aiConfig };\n\n // Notify subscribers (e.g. panoptic) after the merge. Errors are\n // swallowed so a misbehaving listener never breaks config application,\n // mirroring the observer / onUsage swallow-on-throw discipline.\n for (const listener of configListeners) {\n try {\n listener(snapshot);\n } catch {\n // intentionally ignored\n }\n }\n\n return snapshot;\n}\n\n/**\n * Read the current AI config snapshot. Returns a shallow copy so\n * callers can't accidentally mutate the source of truth. Used\n * internally by consumers to resolve their `defaultStore` fallback.\n */\nexport function getAIConfig(): AIConfig {\n return { ...aiConfig };\n}\n\n/**\n * Resolve the effective `@warlock.js/cache` driver for a cache-backed\n * consumer that didn't receive an explicit one. Returns the global\n * `defaultStore` if set, otherwise `undefined`. The semantic-cache\n * middleware treats `undefined` as fatal and throws. Snapshot\n * persistence no longer consults this — it resolves through\n * {@link resolveDefaultSnapshotStore}.\n */\nexport function resolveDefaultStore(): CacheDriver<any, any> | undefined {\n return aiConfig.defaultStore;\n}\n\n/**\n * Resolve the global default {@link CheckpointStore} for an\n * orchestrator that didn't receive an explicit `checkpointStore`.\n * Returns `undefined` when none is configured — the orchestrator\n * factory decides whether that's fatal.\n */\nexport function resolveDefaultCheckpointStore(): CheckpointStore | undefined {\n return aiConfig.defaultCheckpointStore;\n}\n\n/**\n * Resolve the global default {@link SnapshotStore} for an orchestrator\n * that didn't receive an explicit `snapshotStore`. Returns `undefined`\n * when none is configured — the orchestrator factory decides whether\n * that's fatal (it is, when `iterate: true`).\n */\nexport function resolveDefaultSnapshotStore(): SnapshotStore | undefined {\n return aiConfig.defaultSnapshotStore;\n}\n"],"mappings":";AAiGA,MAAM,WAAqB,CAAC;AAK5B,MAAM,kBAAoC,CAAC;;;;;;;;;;;;;;;;;AAkB3C,SAAgB,gBAAgB,UAAgC;CAC9D,gBAAgB,KAAK,QAAQ;AAC/B;;;;;;;;;;;;;;;;AAiBA,SAAgB,YAAY,SAAsC;CAChE,OAAO,OAAO,UAAU,OAAO;CAC/B,MAAM,WAAW,EAAE,GAAG,SAAS;CAK/B,KAAK,MAAM,YAAY,iBACrB,IAAI;EACF,SAAS,QAAQ;CACnB,QAAQ,CAER;CAGF,OAAO;AACT;;;;;;AAOA,SAAgB,cAAwB;CACtC,OAAO,EAAE,GAAG,SAAS;AACvB;;;;;;;;;AAUA,SAAgB,sBAAyD;CACvE,OAAO,SAAS;AAClB;;;;;;;AAQA,SAAgB,gCAA6D;CAC3E,OAAO,SAAS;AAClB;;;;;;;AAQA,SAAgB,8BAAyD;CACvE,OAAO,SAAS;AAClB"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AttachmentPolicy } from "../attachment-policy.type.mjs";
|
|
1
2
|
import { Attachment } from "../attachment.type.mjs";
|
|
2
3
|
import { Message } from "../conversation-message.type.mjs";
|
|
3
4
|
import { ToolContext } from "../tool.contract.mjs";
|
|
@@ -12,9 +13,9 @@ import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
|
12
13
|
* Options passed to AgentContract.execute() to configure a single execution run.
|
|
13
14
|
*
|
|
14
15
|
* @example
|
|
15
|
-
* const result = await agent.execute("
|
|
16
|
+
* const result = await agent.execute("Describe this image", {
|
|
16
17
|
* history: previousMessages,
|
|
17
|
-
* attachments: ["/path/to/
|
|
18
|
+
* attachments: ["/path/to/screenshot.png"],
|
|
18
19
|
* placeholders: { language: "English" },
|
|
19
20
|
* output: z.object({ summary: z.string(), keyPoints: z.array(z.string()) }),
|
|
20
21
|
* on: {
|
|
@@ -24,8 +25,23 @@ import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
|
24
25
|
* });
|
|
25
26
|
*/
|
|
26
27
|
type AgentExecuteOptions<TOutput = unknown> = {
|
|
27
|
-
/**
|
|
28
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Caller-chosen stable run identifier. Auto-generated (`agent_<rand>`)
|
|
30
|
+
* when omitted. Load-bearing for durable resume: when `durable` is on,
|
|
31
|
+
* pass a stable `runId` here (or read the generated one off
|
|
32
|
+
* `result.report.runId`) so a later `agent.resume(runId)` can find the
|
|
33
|
+
* snapshot. Mirrors `SupervisorExecuteOptions.runId`.
|
|
34
|
+
*/
|
|
35
|
+
runId?: string; /** Prior conversation messages to prepend as context */
|
|
36
|
+
history?: Message[]; /** Files or URLs to attach to the message */
|
|
37
|
+
attachments?: Attachment[];
|
|
38
|
+
/**
|
|
39
|
+
* Trust-boundary policy for {@link attachments} (S1) — overrides
|
|
40
|
+
* `AgentConfig.attachmentPolicy` for this call. Governs remote-text
|
|
41
|
+
* fetch (default-deny), the outbound `OutboundPolicy`, and the local-
|
|
42
|
+
* file `allowedRoots` sandbox. Omit to inherit the factory policy.
|
|
43
|
+
*/
|
|
44
|
+
attachmentPolicy?: AttachmentPolicy; /** Values to inject into {{mustache}} placeholders in prompts */
|
|
29
45
|
placeholders?: Placeholders;
|
|
30
46
|
/**
|
|
31
47
|
* Standard Schema for structured output extraction.
|
|
@@ -127,6 +143,18 @@ type AgentExecuteOptions<TOutput = unknown> = {
|
|
|
127
143
|
*/
|
|
128
144
|
sessionId?: string;
|
|
129
145
|
};
|
|
146
|
+
/**
|
|
147
|
+
* Options accepted by `agent.resume(runId, options?)`.
|
|
148
|
+
*
|
|
149
|
+
* `force: true` bypasses the signature drift check — use only when you
|
|
150
|
+
* have verified the definition change is safe for the in-flight
|
|
151
|
+
* snapshot. `AgentDriftError` is otherwise thrown without executing
|
|
152
|
+
* anything. Everything else mirrors {@link AgentExecuteOptions} (e.g.
|
|
153
|
+
* re-supply a `signal` to keep the resumed run cancellable).
|
|
154
|
+
*/
|
|
155
|
+
type AgentResumeOptions<TOutput = unknown> = AgentExecuteOptions<TOutput> & {
|
|
156
|
+
/** Bypass the drift check and resume against the changed definition. */force?: boolean;
|
|
157
|
+
};
|
|
130
158
|
//#endregion
|
|
131
|
-
export { AgentExecuteOptions };
|
|
159
|
+
export { AgentExecuteOptions, AgentResumeOptions };
|
|
132
160
|
//# sourceMappingURL=agent-options.type.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-options.type.d.mts","names":[],"sources":["../../../../../../../../@warlock.js/ai/src/contracts/agent/agent-options.type.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"agent-options.type.d.mts","names":[],"sources":["../../../../../../../../@warlock.js/ai/src/contracts/agent/agent-options.type.ts"],"mappings":";;;;;;;;;;;;;AAyBA;;;;;;;;;;;;;KAAY,mBAAA;EA2F4C;;;;;;;EAnFtD,KAAA,WAEA;EAAA,OAAA,GAAU,OAAA,IAEV;EAAA,WAAA,GAAc,UAAA;EAOd;;;;;;EAAA,gBAAA,GAAmB,gBAAA,EAgCnB;EA9BA,YAAA,GAAe,YAAA;EAmDf;;;;EA9CA,MAAA,GAAS,gBAAA,CAAiB,OAAA;EA8DjB;;;;;;;;;;;;;;AAqCA;AAYX;;;;;;;;;EAtFE,cAAA,GAAiB,MAAA;;;;;;;;;;;;;;;;;;;;;EAqBjB,MAAA;8EAEE,WAAA;EAAA;EAGF,YAAA,GAAe,oBAAA;;;;;;;;;;;EAWf,MAAA,GAAS,WAAA;EAET,EAAA,GAAK,OAAA,eACS,aAAA,IAAiB,OAAA,EAAS,aAAA,CAAc,CAAA;;;;;;;;;;;;EAatD,OAAA,GAAU,WAAA;;;;;;;;EAQV,kBAAA,GAAqB,wBAAA;;;;;;;;;;;;;EAarB,SAAA;AAAA;;;;;;;;;;KAYU,kBAAA,sBAAwC,mBAAmB,CAAC,OAAA;0EAEtE,KAAA;AAAA"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { Message } from "../conversation-message.type.mjs";
|
|
2
|
+
import { Usage } from "../result/usage.type.mjs";
|
|
3
|
+
import { ToolCall } from "../result/tool-call.type.mjs";
|
|
4
|
+
import { LLMTrip } from "../result/llm-trip.type.mjs";
|
|
5
|
+
|
|
6
|
+
//#region ../@warlock.js/ai/src/contracts/agent/agent-snapshot.type.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* Lifecycle status of a durable agent run, recorded on the persisted
|
|
9
|
+
* snapshot so `resume()` can decide whether a run is still in flight.
|
|
10
|
+
*
|
|
11
|
+
* - `"running"` — the trip loop is active; a resume is legitimate if
|
|
12
|
+
* the process crashed between trip boundaries.
|
|
13
|
+
* - `"completed"` — the agent terminated successfully; resume is a
|
|
14
|
+
* no-op and re-returns the final result rebuilt from the snapshot.
|
|
15
|
+
* - `"cancelled"` — aborted via `AbortSignal`; resume is allowed (the
|
|
16
|
+
* caller decides whether to retry).
|
|
17
|
+
* - `"failed"` — terminated with an error; resume after the fix.
|
|
18
|
+
*/
|
|
19
|
+
type AgentSnapshotStatus = "running" | "completed" | "cancelled" | "failed";
|
|
20
|
+
/**
|
|
21
|
+
* Persisted shape written to the configured {@link
|
|
22
|
+
* import("../orchestrator/snapshot-store.contract").SnapshotStore} after
|
|
23
|
+
* every trip settles. Exists so `agent.resume(runId)` can re-hydrate the
|
|
24
|
+
* assembled conversation + completed trips + tool calls + running usage
|
|
25
|
+
* and continue the trip loop from the next `tripIndex`.
|
|
26
|
+
*
|
|
27
|
+
* **Checkpoint granularity is per-trip.** The snapshot is written at the
|
|
28
|
+
* end of `runTrip`, after every tool the trip requested has been
|
|
29
|
+
* dispatched and its result message appended — the only point in the
|
|
30
|
+
* loop where `messages`, `trips`, `toolCalls`, and `usage` are mutually
|
|
31
|
+
* consistent. A crash mid-trip loses only that in-flight trip (never
|
|
32
|
+
* checkpointed), which the resumed run re-issues cleanly.
|
|
33
|
+
*
|
|
34
|
+
* `signature` is a structural fingerprint covering model + provider +
|
|
35
|
+
* sorted tool names + maxTrips + output presence + version (see
|
|
36
|
+
* {@link import("../../agent/signature").computeAgentSignature}).
|
|
37
|
+
* `resume()` compares it against the current agent's signature; a
|
|
38
|
+
* mismatch throws `AgentDriftError` (bypassable with `{ force: true }`).
|
|
39
|
+
*
|
|
40
|
+
* Every field is JSON-serializable — `Message`, `LLMTrip`, `ToolCall`,
|
|
41
|
+
* and `Usage` are the same plain-data shapes already persisted on
|
|
42
|
+
* reports, so the snapshot round-trips through any `SnapshotStore`
|
|
43
|
+
* backend (`memory`, `pg`, `redis`) verbatim.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* const snapshot: AgentSnapshot | undefined = await store.load(runId);
|
|
47
|
+
* if (snapshot?.status === "running") {
|
|
48
|
+
* await agent.resume(runId);
|
|
49
|
+
* }
|
|
50
|
+
*/
|
|
51
|
+
type AgentSnapshot = {
|
|
52
|
+
/** The store key — stable across the whole run. */runId: string; /** Resolved agent name, for the resume error message + attribution. */
|
|
53
|
+
agentName: string; /** Structural drift fingerprint (see `computeAgentSignature`). */
|
|
54
|
+
signature: string; /** `AgentConfig.version` — metadata only, never compared. */
|
|
55
|
+
version?: string; /** The original `execute(input)` value — needed to rebuild context. */
|
|
56
|
+
input: string;
|
|
57
|
+
/**
|
|
58
|
+
* The resolved system-prompt text captured once on the first run, so
|
|
59
|
+
* a resume skips `buildInitialMessages` (the messages array already
|
|
60
|
+
* holds the system turn). Absent when the agent had no prompt.
|
|
61
|
+
*/
|
|
62
|
+
systemPrompt?: string;
|
|
63
|
+
/**
|
|
64
|
+
* The wire-level JSON Schema sent to the model for structured output,
|
|
65
|
+
* captured so resume re-issues continuation trips with the identical
|
|
66
|
+
* response contract. Absent when the agent produced untyped output.
|
|
67
|
+
*/
|
|
68
|
+
responseSchema?: Record<string, unknown>; /** Registry name of the resolved named prompt, when one was used. */
|
|
69
|
+
promptName?: string; /** Registry version label paired with {@link AgentSnapshot.promptName}. */
|
|
70
|
+
promptVersion?: string;
|
|
71
|
+
/**
|
|
72
|
+
* The live conversation array — assistant turns (with `toolCalls`)
|
|
73
|
+
* plus tool-result turns — assembled across the persisted trips.
|
|
74
|
+
* Re-hydrated verbatim so the next trip sees the full history.
|
|
75
|
+
*/
|
|
76
|
+
messages: Message[];
|
|
77
|
+
/**
|
|
78
|
+
* Every settled trip so far. `trips.length` is the next `tripIndex`
|
|
79
|
+
* the resumed loop starts at, so completed trips never re-run.
|
|
80
|
+
*/
|
|
81
|
+
trips: LLMTrip[]; /** Every settled tool dispatch (flat, each carrying its `tripIndex`). */
|
|
82
|
+
toolCalls: ToolCall[]; /** Running usage total across the persisted trips — never double-counted. */
|
|
83
|
+
usage: Usage;
|
|
84
|
+
status: AgentSnapshotStatus;
|
|
85
|
+
startedAt: string;
|
|
86
|
+
savedAt: string;
|
|
87
|
+
};
|
|
88
|
+
//#endregion
|
|
89
|
+
export { AgentSnapshot, AgentSnapshotStatus };
|
|
90
|
+
//# sourceMappingURL=agent-snapshot.type.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-snapshot.type.d.mts","names":[],"sources":["../../../../../../../../@warlock.js/ai/src/contracts/agent/agent-snapshot.type.ts"],"mappings":";;;;;;;;AAiBA;;;;AAA+B;AAqC/B;;;;;KArCY,mBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiFH;;;KA5CG,aAAA;qDAEV,KAAA;EAEA,SAAA;EAEA,SAAA;EAEA,OAAA;EAEA,KAAA;;;;;;EAMA,YAAA;;;;;;EAMA,cAAA,GAAiB,MAAA;EAEjB,UAAA;EAEA,aAAA;;;;;;EAMA,QAAA,EAAU,OAAA;;;;;EAKV,KAAA,EAAO,OAAA;EAEP,SAAA,EAAW,QAAA;EAEX,KAAA,EAAO,KAAA;EACP,MAAA,EAAQ,mBAAA;EACR,SAAA;EACA,OAAA;AAAA"}
|
|
@@ -3,7 +3,7 @@ import { ExecutableContract } from "../executable.contract.mjs";
|
|
|
3
3
|
import { StreamContract } from "../stream/stream.contract.mjs";
|
|
4
4
|
import { EvalOptions, EvalReport } from "./eval.type.mjs";
|
|
5
5
|
import { AgentEventMap } from "../events/event-map.type.mjs";
|
|
6
|
-
import { AgentExecuteOptions } from "./agent-options.type.mjs";
|
|
6
|
+
import { AgentExecuteOptions, AgentResumeOptions } from "./agent-options.type.mjs";
|
|
7
7
|
|
|
8
8
|
//#region ../@warlock.js/ai/src/contracts/agent/agent.contract.d.ts
|
|
9
9
|
/**
|
|
@@ -71,11 +71,39 @@ interface AgentContract<TOutput = unknown> extends ExecutableContract<string, Ag
|
|
|
71
71
|
* `AgentConfig.description` at factory time.
|
|
72
72
|
*/
|
|
73
73
|
readonly description?: string;
|
|
74
|
+
/**
|
|
75
|
+
* Structural drift fingerprint of the agent definition — model +
|
|
76
|
+
* provider + sorted tool names + maxTrips + output presence + version.
|
|
77
|
+
* Stamped on every durable snapshot and compared on `resume()`; a
|
|
78
|
+
* mismatch throws `AgentDriftError`. Always populated (computed at
|
|
79
|
+
* factory time), independent of whether `durable` is configured.
|
|
80
|
+
*/
|
|
81
|
+
readonly signature: string;
|
|
74
82
|
/**
|
|
75
83
|
* Stream execution events in real time.
|
|
76
84
|
* Yields typed StreamEvent values and resolves result when done.
|
|
77
85
|
*/
|
|
78
86
|
stream(input: string, options?: AgentExecuteOptions<TOutput>): StreamContract<AgentResult<TOutput>>;
|
|
87
|
+
/**
|
|
88
|
+
* Resume a durable run after a crash. Loads the snapshot persisted
|
|
89
|
+
* under `runId` (requires `durable` on the config, or a global
|
|
90
|
+
* `defaultSnapshotStore`), re-hydrates the completed trips + tool
|
|
91
|
+
* calls + usage, and continues the trip loop from the next trip —
|
|
92
|
+
* never re-issuing a completed trip's model call or re-invoking its
|
|
93
|
+
* tools. A resume of an already-settled run re-returns the stored
|
|
94
|
+
* result without running anything.
|
|
95
|
+
*
|
|
96
|
+
* Refuses to continue when the current definition has structurally
|
|
97
|
+
* drifted from the snapshot (`AgentDriftError`), unless
|
|
98
|
+
* `{ force: true }` is passed. Throws `AgentExecutionError` when no
|
|
99
|
+
* store is configured or no snapshot exists for `runId`.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* const result = await writer.execute("research X", { runId: "run-42" });
|
|
103
|
+
* // ...process crashes mid-run...
|
|
104
|
+
* const recovered = await writer.resume("run-42");
|
|
105
|
+
*/
|
|
106
|
+
resume(runId: string, options?: AgentResumeOptions<TOutput>): Promise<AgentResult<TOutput>>;
|
|
79
107
|
/**
|
|
80
108
|
* Subscribe a handler to a single event name for the lifetime of
|
|
81
109
|
* this agent instance. Returns an unsubscribe function; calling it
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.contract.d.mts","names":[],"sources":["../../../../../../../../@warlock.js/ai/src/contracts/agent/agent.contract.ts"],"mappings":";;;;;;;;;;AAWA;;KAAY,iBAAA,iBAAkC,aAAA,KAC5C,OAAA,EAAS,aAAA,CAAc,CAAA;;;;;;;;;;;;AAAE;AAyC3B;;;;;;;;;;;;;;;;;;;;;;;;;;UAAiB,aAAA,4BAAyC,kBAAA,SAExD,mBAAA,CAAoB,OAAA,GACpB,WAAA,CAAY,OAAA;
|
|
1
|
+
{"version":3,"file":"agent.contract.d.mts","names":[],"sources":["../../../../../../../../@warlock.js/ai/src/contracts/agent/agent.contract.ts"],"mappings":";;;;;;;;;;AAWA;;KAAY,iBAAA,iBAAkC,aAAA,KAC5C,OAAA,EAAS,aAAA,CAAc,CAAA;;;;;;;;;;;;AAAE;AAyC3B;;;;;;;;;;;;;;;;;;;;;;;;;;UAAiB,aAAA,4BAAyC,kBAAA,SAExD,mBAAA,CAAoB,OAAA,GACpB,WAAA,CAAY,OAAA;EA4HmB;;;;;;;;EAAA,SAlHtB,IAAA;EAXT;;;;;EAAA,SAiBS,WAAA;EAMA;;;;;EAAA,SAAA,WAAA;EAeP;;;;;;;EAAA,SAPO,SAAA;EA+BP;;;;EA1BF,MAAA,CACE,KAAA,UACA,OAAA,GAAU,mBAAA,CAAoB,OAAA,IAC7B,cAAA,CAAe,WAAA,CAAY,OAAA;EA+B3B;;;;;;;;;;;;;;;;;;;EAVH,MAAA,CACE,KAAA,UACA,OAAA,GAAU,kBAAA,CAAmB,OAAA,IAC5B,OAAA,CAAQ,WAAA,CAAY,OAAA;EA8DD;;;;;EAvDtB,EAAA,iBAAmB,aAAA,EACjB,KAAA,EAAO,CAAA,EACP,OAAA,EAAS,iBAAA,CAAkB,CAAA;;;;;EAO7B,GAAA,iBAAoB,aAAA,EAClB,KAAA,EAAO,CAAA,EACP,OAAA,EAAS,iBAAA,CAAkB,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA4C7B,IAAA,SAAa,OAAA,EAAS,OAAA,EAAS,WAAA,CAAY,KAAA,IAAS,OAAA,CAAQ,UAAA,CAAW,KAAA;AAAA"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AgentResult } from "../result/agent-result.type.mjs";
|
|
2
|
+
import { DatasetContract } from "../../eval/dataset.type.mjs";
|
|
2
3
|
import { AgentContract } from "./agent.contract.mjs";
|
|
3
4
|
import { AgentExecuteOptions } from "./agent-options.type.mjs";
|
|
4
5
|
|
|
@@ -92,7 +93,12 @@ type EvalJudge = {
|
|
|
92
93
|
* resolvable per case or the runner throws at author time.
|
|
93
94
|
*/
|
|
94
95
|
type EvalOptions<TOutput = unknown> = {
|
|
95
|
-
/**
|
|
96
|
+
/**
|
|
97
|
+
* The evaluation cases to run. Either a raw `EvalCase[]` or a
|
|
98
|
+
* {@link DatasetContract} (from `ai.dataset(...)`) — the runner reads
|
|
99
|
+
* `.cases` off a dataset.
|
|
100
|
+
*/
|
|
101
|
+
cases: EvalCase<TOutput>[] | DatasetContract<TOutput>; /** Default scorers applied to every case without its own `scorers`. */
|
|
96
102
|
scorers?: EvalScorer<TOutput>[]; /** LLM-as-judge fallback for cases with no scorers. */
|
|
97
103
|
judge?: EvalJudge;
|
|
98
104
|
/**
|
|
@@ -108,6 +114,36 @@ type EvalOptions<TOutput = unknown> = {
|
|
|
108
114
|
*/
|
|
109
115
|
onFailure?: (caseResult: EvalCaseResult<TOutput>) => void | Promise<void>; /** Execute-options applied to every case (merged under per-case `options`). */
|
|
110
116
|
executeOptions?: AgentExecuteOptions<TOutput>;
|
|
117
|
+
/**
|
|
118
|
+
* A prior {@link EvalReport} to diff against. When set, the new report
|
|
119
|
+
* carries a `regression` block flagging cases whose score dropped more
|
|
120
|
+
* than `tolerance` below the baseline.
|
|
121
|
+
*/
|
|
122
|
+
baseline?: EvalReport<TOutput>;
|
|
123
|
+
/**
|
|
124
|
+
* Maximum allowed per-case score drop vs baseline before it counts as a
|
|
125
|
+
* regression. Only consulted when `baseline` is set. Defaults to `0`
|
|
126
|
+
* (any drop is a regression).
|
|
127
|
+
*/
|
|
128
|
+
tolerance?: number;
|
|
129
|
+
};
|
|
130
|
+
/**
|
|
131
|
+
* Regression verdict attached to an {@link EvalReport} when `agent.eval`
|
|
132
|
+
* is called with a `baseline`. Cases are joined by `name`.
|
|
133
|
+
*/
|
|
134
|
+
type EvalRegression = {
|
|
135
|
+
/**
|
|
136
|
+
* Cases whose score fell more than `tolerance` below the baseline,
|
|
137
|
+
* carrying the before/after scores.
|
|
138
|
+
*/
|
|
139
|
+
regressed: Array<{
|
|
140
|
+
name: string;
|
|
141
|
+
before: number;
|
|
142
|
+
after: number;
|
|
143
|
+
}>; /** Case names present in the baseline but absent in the new report. */
|
|
144
|
+
removed: string[]; /** Case names present in the new report but absent in the baseline. */
|
|
145
|
+
added: string[]; /** `true` when `regressed` is empty — no case regressed beyond tolerance. */
|
|
146
|
+
passed: boolean;
|
|
111
147
|
};
|
|
112
148
|
/**
|
|
113
149
|
* Per-case outcome in an {@link EvalReport}. Bundles the case, the
|
|
@@ -137,7 +173,12 @@ type EvalReport<TOutput = unknown> = {
|
|
|
137
173
|
passed: boolean; /** Per-case results in suite order. */
|
|
138
174
|
cases: EvalCaseResult<TOutput>[]; /** Total wall-clock duration of the whole suite in milliseconds. */
|
|
139
175
|
duration: number;
|
|
176
|
+
/**
|
|
177
|
+
* Regression diff vs a baseline. Present only when `agent.eval` was
|
|
178
|
+
* called with a `baseline`.
|
|
179
|
+
*/
|
|
180
|
+
regression?: EvalRegression;
|
|
140
181
|
};
|
|
141
182
|
//#endregion
|
|
142
|
-
export { EvalCase, EvalCaseResult, EvalJudge, EvalOptions, EvalReport, EvalScore, EvalScorer, EvalScorerContext };
|
|
183
|
+
export { EvalCase, EvalCaseResult, EvalJudge, EvalOptions, EvalRegression, EvalReport, EvalScore, EvalScorer, EvalScorerContext };
|
|
143
184
|
//# sourceMappingURL=eval.type.d.mts.map
|