@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/agent/agent.mjs
CHANGED
|
@@ -4,26 +4,42 @@ import { AgentCancelledError } from "../errors/agent-cancelled-error.mjs";
|
|
|
4
4
|
import { AgentMaxTripsError } from "../errors/agent-max-trips-error.mjs";
|
|
5
5
|
import { SchemaValidationError } from "../errors/schema-validation-error.mjs";
|
|
6
6
|
import "../errors/index.mjs";
|
|
7
|
-
import {
|
|
7
|
+
import { computeCost, mergeUsage } from "../utils/compute-cost.mjs";
|
|
8
8
|
import { extractJsonPayload } from "../utils/extract-json-payload.mjs";
|
|
9
|
+
import { extractJsonLenient } from "../utils/extract-json-lenient.mjs";
|
|
9
10
|
import { generateRunId } from "../utils/generate-run-id.mjs";
|
|
11
|
+
import { captureChildReport } from "../utils/run-context.mjs";
|
|
10
12
|
import { safeJsonParse } from "../utils/safe-json-parse.mjs";
|
|
11
13
|
import { stampReportLineage } from "../utils/stamp-report-lineage.mjs";
|
|
12
14
|
import "../utils/index.mjs";
|
|
13
15
|
import { runEval } from "../eval/eval-runner.mjs";
|
|
14
16
|
import { runPipeline } from "../middleware/pipeline.mjs";
|
|
15
17
|
import "../middleware/index.mjs";
|
|
18
|
+
import { notifyObservers } from "../observe/resolve-observers.mjs";
|
|
19
|
+
import { skills } from "../skills/skills.mjs";
|
|
20
|
+
import "../skills/index.mjs";
|
|
16
21
|
import { normalizeAgentTools } from "../tool/executable-as-tool.mjs";
|
|
22
|
+
import { JUDGE_DEFAULT_REPAIR_ATTEMPTS } from "./judge-config.type.mjs";
|
|
17
23
|
import { buildAgentInputMessages } from "./agent-input-builder.mjs";
|
|
18
24
|
import { logAgentEvent } from "./agent-log-event.mjs";
|
|
19
25
|
import { createAgentStream } from "./agent-stream.mjs";
|
|
20
26
|
import { agentEventToStreamEvent } from "./agent-to-stream-event.mjs";
|
|
21
27
|
import { JsonStreamGuard } from "./json-stream-guard.mjs";
|
|
28
|
+
import { computeAgentSignature } from "./signature.mjs";
|
|
29
|
+
import { deleteAgentSnapshot, loadAgentSnapshotForResume, persistAgentSnapshot } from "./snapshot.mjs";
|
|
22
30
|
import { log } from "@warlock.js/logger";
|
|
23
31
|
|
|
24
32
|
//#region ../@warlock.js/ai/src/agent/agent.ts
|
|
25
33
|
const LOG_MODULE = "ai.agent";
|
|
26
34
|
/**
|
|
35
|
+
* Duck-type a value as a {@link SkillsContract} (vs a raw `SkillsConfig`).
|
|
36
|
+
* A contract exposes the agent-facing methods; a config is a plain spec.
|
|
37
|
+
* Checking `catalogPrompt` is sufficient to discriminate the two shapes.
|
|
38
|
+
*/
|
|
39
|
+
function isSkillsContract(value) {
|
|
40
|
+
return typeof value === "object" && value !== null && typeof value.catalogPrompt === "function";
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
27
43
|
* Detect abort-flavored errors surfaced by SDK HTTP layers — the
|
|
28
44
|
* DOM `AbortError`, axios `ERR_CANCELED`, node-fetch's own
|
|
29
45
|
* `AbortError`. Used to classify them as cancellation rather than
|
|
@@ -93,6 +109,16 @@ function validateMiddleware(middleware) {
|
|
|
93
109
|
}
|
|
94
110
|
}
|
|
95
111
|
/**
|
|
112
|
+
* Normalize the public `judge` flag (`boolean | JudgeConfig | undefined`)
|
|
113
|
+
* into a resolved {@link JudgeConfig} or `undefined` when the preset is
|
|
114
|
+
* off. `true` ⇒ all defaults (`{}`); a partial config fills missing fields
|
|
115
|
+
* from the defaults; `false` / absent ⇒ `undefined` (judge mode off).
|
|
116
|
+
*/
|
|
117
|
+
function resolveJudgeConfig(judge) {
|
|
118
|
+
if (!judge) return;
|
|
119
|
+
return { repairAttempts: (judge === true ? {} : judge).repairAttempts ?? 2 };
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
96
122
|
* Creates an executable AI agent from the given configuration.
|
|
97
123
|
*
|
|
98
124
|
* The agent runs a bounded trip loop: each trip calls the model, dispatches
|
|
@@ -130,10 +156,24 @@ function agent(config) {
|
|
|
130
156
|
...config,
|
|
131
157
|
tools
|
|
132
158
|
}) : config.name;
|
|
159
|
+
const skillsLib = config.skills ? isSkillsContract(config.skills) ? config.skills : skills(config.skills) : void 0;
|
|
160
|
+
const signature = computeAgentSignature({
|
|
161
|
+
name: isAnonymous ? void 0 : name,
|
|
162
|
+
version: config.version,
|
|
163
|
+
model: {
|
|
164
|
+
name: config.model?.name,
|
|
165
|
+
provider: config.model?.provider
|
|
166
|
+
},
|
|
167
|
+
tools,
|
|
168
|
+
maxTrips: config.maxTrips,
|
|
169
|
+
output: config.output
|
|
170
|
+
});
|
|
133
171
|
const resolvedConfig = {
|
|
134
172
|
...config,
|
|
135
173
|
name,
|
|
136
|
-
tools
|
|
174
|
+
tools,
|
|
175
|
+
skillsLib,
|
|
176
|
+
signature
|
|
137
177
|
};
|
|
138
178
|
const instanceHandlers = /* @__PURE__ */ new Map();
|
|
139
179
|
function on(event, handler) {
|
|
@@ -153,6 +193,7 @@ function agent(config) {
|
|
|
153
193
|
name,
|
|
154
194
|
isAnonymous,
|
|
155
195
|
description: config.description,
|
|
196
|
+
signature,
|
|
156
197
|
async execute(input, options) {
|
|
157
198
|
return new Execution(resolvedConfig, input, options, void 0, instanceHandlers).run();
|
|
158
199
|
},
|
|
@@ -161,6 +202,19 @@ function agent(config) {
|
|
|
161
202
|
new Execution(resolvedConfig, input, options, controller, instanceHandlers).run();
|
|
162
203
|
return stream;
|
|
163
204
|
},
|
|
205
|
+
async resume(runId, options) {
|
|
206
|
+
const snapshot = await loadAgentSnapshotForResume({
|
|
207
|
+
durable: resolvedConfig.durable,
|
|
208
|
+
agentName: name,
|
|
209
|
+
signature,
|
|
210
|
+
runId,
|
|
211
|
+
options
|
|
212
|
+
});
|
|
213
|
+
return new Execution(resolvedConfig, snapshot.input, {
|
|
214
|
+
...options,
|
|
215
|
+
runId
|
|
216
|
+
}, void 0, instanceHandlers, snapshot).run();
|
|
217
|
+
},
|
|
164
218
|
on,
|
|
165
219
|
off,
|
|
166
220
|
eval(options) {
|
|
@@ -170,6 +224,41 @@ function agent(config) {
|
|
|
170
224
|
return agentContract;
|
|
171
225
|
}
|
|
172
226
|
/**
|
|
227
|
+
* Build a judge-safe agent — sugar for `agent({ ...config, judge })`.
|
|
228
|
+
*
|
|
229
|
+
* Use this for LLM-as-judge graders and verdict classifiers running on
|
|
230
|
+
* models that may emit corrupted structured output (e.g. the Amazon Nova
|
|
231
|
+
* family). The returned agent parses verdicts leniently (tolerates fenced
|
|
232
|
+
* ` ```json ` blocks + surrounding prose), auto-enables a couple of repair
|
|
233
|
+
* re-asks, and never throws on a parse miss — surfacing `result.error` with
|
|
234
|
+
* `result.data` left undefined so a flaky judge degrades gracefully.
|
|
235
|
+
*
|
|
236
|
+
* See {@link AgentConfig.judge} for the full behavior + the resilience-over-
|
|
237
|
+
* strictness trade-off.
|
|
238
|
+
*
|
|
239
|
+
* @param config - Any agent config (model, system prompt, output schema, …).
|
|
240
|
+
* @param judge - Optional fine-tuning ({@link JudgeConfig}); defaults to `true`.
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* const grader = ai.agent.judge({
|
|
244
|
+
* model: nova.model({ name: "amazon.nova-pro-v1:0" }),
|
|
245
|
+
* systemPrompt: "Grade the answer. Respond with JSON only.",
|
|
246
|
+
* output: verdictSchema,
|
|
247
|
+
* });
|
|
248
|
+
*
|
|
249
|
+
* const result = await grader.execute(prompt);
|
|
250
|
+
* if (result.error) {
|
|
251
|
+
* // graceful default — the judge couldn't produce a clean verdict
|
|
252
|
+
* }
|
|
253
|
+
*/
|
|
254
|
+
function judgeAgent(config, judge = true) {
|
|
255
|
+
return agent({
|
|
256
|
+
...config,
|
|
257
|
+
judge
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
agent.judge = judgeAgent;
|
|
261
|
+
/**
|
|
173
262
|
* Per-call driver that owns the full lifecycle of a single
|
|
174
263
|
* `agent.execute()` or `agent.stream()` invocation.
|
|
175
264
|
*
|
|
@@ -212,12 +301,13 @@ function agent(config) {
|
|
|
212
301
|
* return stream;
|
|
213
302
|
*/
|
|
214
303
|
var Execution = class {
|
|
215
|
-
constructor(config, input, options, streamController, instanceHandlers) {
|
|
304
|
+
constructor(config, input, options, streamController, instanceHandlers, resumeFrom) {
|
|
216
305
|
this.config = config;
|
|
217
306
|
this.input = input;
|
|
218
307
|
this.options = options;
|
|
219
308
|
this.streamController = streamController;
|
|
220
309
|
this.instanceHandlers = instanceHandlers;
|
|
310
|
+
this.resumeFrom = resumeFrom;
|
|
221
311
|
this.trips = [];
|
|
222
312
|
this.toolCalls = [];
|
|
223
313
|
this.usage = {
|
|
@@ -226,13 +316,27 @@ var Execution = class {
|
|
|
226
316
|
total: 0
|
|
227
317
|
};
|
|
228
318
|
this.messages = [];
|
|
229
|
-
this.startedAt = /* @__PURE__ */ new Date();
|
|
230
319
|
this.start = performance.now();
|
|
231
|
-
this.runId = generateRunId("agent");
|
|
232
320
|
this.logger = log;
|
|
321
|
+
this.warnedHandlerEvents = /* @__PURE__ */ new Set();
|
|
233
322
|
this.middlewareState = /* @__PURE__ */ new Map();
|
|
234
323
|
this.maxTrips = config.maxTrips ?? 10;
|
|
235
324
|
this.middleware = config.middleware ?? [];
|
|
325
|
+
this.judgeConfig = resolveJudgeConfig(config.judge);
|
|
326
|
+
this.runId = resumeFrom?.runId ?? options?.runId ?? generateRunId("agent");
|
|
327
|
+
this.startedAt = resumeFrom ? new Date(resumeFrom.startedAt) : /* @__PURE__ */ new Date();
|
|
328
|
+
if (resumeFrom) {
|
|
329
|
+
this.messages.push(...resumeFrom.messages);
|
|
330
|
+
this.trips.push(...resumeFrom.trips);
|
|
331
|
+
this.toolCalls.push(...resumeFrom.toolCalls);
|
|
332
|
+
mergeUsage(this.usage, resumeFrom.usage);
|
|
333
|
+
this.systemPrompt = resumeFrom.systemPrompt;
|
|
334
|
+
this.responseSchema = resumeFrom.responseSchema;
|
|
335
|
+
this.promptName = resumeFrom.promptName;
|
|
336
|
+
this.promptVersion = resumeFrom.promptVersion;
|
|
337
|
+
}
|
|
338
|
+
const skillTools = config.skillsLib ? normalizeAgentTools(config.skillsLib.tools(this.runId)) ?? [] : [];
|
|
339
|
+
this.effectiveTools = [...config.tools ?? [], ...skillTools];
|
|
236
340
|
}
|
|
237
341
|
/**
|
|
238
342
|
* Base middleware context shared by every level. `state` is the
|
|
@@ -280,6 +384,8 @@ var Execution = class {
|
|
|
280
384
|
if (result.error) this.emit("agent.error", { error: result.error });
|
|
281
385
|
this.emit("agent.completed", { result });
|
|
282
386
|
await this.fireCompleteHook(result);
|
|
387
|
+
await notifyObservers(this.config.observe, result.report);
|
|
388
|
+
captureChildReport(result.report);
|
|
283
389
|
this.streamController?.end(result);
|
|
284
390
|
return result;
|
|
285
391
|
}
|
|
@@ -292,14 +398,28 @@ var Execution = class {
|
|
|
292
398
|
* with `error` populated when things went wrong.
|
|
293
399
|
*/
|
|
294
400
|
async runCore() {
|
|
401
|
+
if (this.resumeFrom && this.resumeFrom.status === "completed") return this.rebuildResumedResult(this.resumeFrom);
|
|
295
402
|
try {
|
|
296
|
-
|
|
297
|
-
|
|
403
|
+
if (!this.resumeFrom) {
|
|
404
|
+
await this.buildInitialMessages();
|
|
405
|
+
this.emit("agent.starting", { input: this.input });
|
|
406
|
+
}
|
|
298
407
|
await this.runTripLoop();
|
|
299
|
-
if (await this.parseOutput() === "failed" && this.
|
|
408
|
+
if (await this.parseOutput() === "failed" && this.resolveRepairAttempts() > 0) await this.runRepairLoop();
|
|
300
409
|
} catch (thrown) {
|
|
301
410
|
this.error = this.toAIError(thrown);
|
|
302
411
|
}
|
|
412
|
+
await this.checkpoint(this.resolveSnapshotStatus());
|
|
413
|
+
if (!this.error && this.config.durable?.deleteOnComplete) {
|
|
414
|
+
const outcome = await deleteAgentSnapshot({
|
|
415
|
+
durable: this.config.durable,
|
|
416
|
+
runId: this.runId
|
|
417
|
+
});
|
|
418
|
+
if (!outcome.ok) this.logger.warn(LOG_MODULE, "snapshot.delete.failed", "durable snapshot delete failed", {
|
|
419
|
+
runId: this.runId,
|
|
420
|
+
error: outcome.error instanceof Error ? outcome.error.message : String(outcome.error)
|
|
421
|
+
});
|
|
422
|
+
}
|
|
303
423
|
return this.buildResult();
|
|
304
424
|
}
|
|
305
425
|
/**
|
|
@@ -311,13 +431,50 @@ var Execution = class {
|
|
|
311
431
|
* to the model. Runs exactly once per execution.
|
|
312
432
|
*/
|
|
313
433
|
async buildInitialMessages() {
|
|
314
|
-
const { messages, responseSchema } = await buildAgentInputMessages({
|
|
434
|
+
const { messages, responseSchema, systemPrompt, promptName, promptVersion } = await buildAgentInputMessages({
|
|
315
435
|
config: this.config,
|
|
316
436
|
input: this.input,
|
|
317
437
|
options: this.options
|
|
318
438
|
});
|
|
319
439
|
this.messages.push(...messages);
|
|
320
440
|
this.responseSchema = responseSchema;
|
|
441
|
+
this.systemPrompt = systemPrompt;
|
|
442
|
+
this.promptName = promptName;
|
|
443
|
+
this.promptVersion = promptVersion;
|
|
444
|
+
await this.injectSkills();
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* Prepend the skills library's contribution to the system prompt — the
|
|
448
|
+
* always-injected metadata catalog first, then (only under `inject`) the
|
|
449
|
+
* preloaded skill bodies, then the developer's resolved system prompt.
|
|
450
|
+
* Never replaces the developer prompt.
|
|
451
|
+
*
|
|
452
|
+
* No-op when no skills library is attached. `catalogPrompt` returns `""`
|
|
453
|
+
* when nothing is in scope and `preload` returns `[]` when `inject` is
|
|
454
|
+
* omitted (the default), so the prepend is a no-op in those cases too.
|
|
455
|
+
*
|
|
456
|
+
* Awaited inside `buildInitialMessages`, which runs inside `runCore`'s
|
|
457
|
+
* try/catch — a source/embedder failure funnels into `this.error` like
|
|
458
|
+
* any other build failure, no new error handling needed.
|
|
459
|
+
*/
|
|
460
|
+
async injectSkills() {
|
|
461
|
+
const lib = this.config.skillsLib;
|
|
462
|
+
if (!lib) return;
|
|
463
|
+
const catalogBlock = await lib.catalogPrompt(this.input);
|
|
464
|
+
const preloaded = await lib.preload(this.input);
|
|
465
|
+
const blocks = [];
|
|
466
|
+
if (catalogBlock) blocks.push(catalogBlock);
|
|
467
|
+
for (const record of preloaded) if (record.body) blocks.push(record.body);
|
|
468
|
+
if (blocks.length === 0) return;
|
|
469
|
+
const prefix = blocks.join("\n\n");
|
|
470
|
+
const merged = this.systemPrompt ? `${prefix}\n\n${this.systemPrompt}` : prefix;
|
|
471
|
+
this.systemPrompt = merged;
|
|
472
|
+
const firstMessage = this.messages[0];
|
|
473
|
+
if (firstMessage?.role === "system") firstMessage.content = merged;
|
|
474
|
+
else this.messages.unshift({
|
|
475
|
+
role: "system",
|
|
476
|
+
content: merged
|
|
477
|
+
});
|
|
321
478
|
}
|
|
322
479
|
/**
|
|
323
480
|
* Drive sequential trips up to `maxTrips`. Each trip may stop the loop
|
|
@@ -327,7 +484,7 @@ var Execution = class {
|
|
|
327
484
|
* error so the caller can distinguish runaway tool loops from a real result.
|
|
328
485
|
*/
|
|
329
486
|
async runTripLoop() {
|
|
330
|
-
for (let tripIndex =
|
|
487
|
+
for (let tripIndex = this.trips.length; tripIndex < this.maxTrips; tripIndex++) {
|
|
331
488
|
if (this.options?.signal?.aborted) {
|
|
332
489
|
this.error = this.makeCancelledError();
|
|
333
490
|
return;
|
|
@@ -375,14 +532,11 @@ var Execution = class {
|
|
|
375
532
|
this.trips.push(failedTrip);
|
|
376
533
|
this.emit("agent.trip.completed", { trip: failedTrip });
|
|
377
534
|
this.emit("agent.error", { error: this.error });
|
|
535
|
+
await this.checkpoint("failed");
|
|
378
536
|
return "error";
|
|
379
537
|
}
|
|
380
538
|
if (response.usage.cost === void 0) response.usage.cost = computeCost(response.usage, this.config.model.pricing);
|
|
381
|
-
this.usage
|
|
382
|
-
this.usage.output += response.usage.output;
|
|
383
|
-
this.usage.total += response.usage.total;
|
|
384
|
-
if (response.usage.cachedTokens !== void 0) this.usage.cachedTokens = (this.usage.cachedTokens ?? 0) + response.usage.cachedTokens;
|
|
385
|
-
this.usage.cost = accumulateCost(this.usage.cost, response.usage.cost);
|
|
539
|
+
mergeUsage(this.usage, response.usage);
|
|
386
540
|
await this.fireUsageHook(tripIndex, response.usage);
|
|
387
541
|
const isToolCallTrip = response.finishReason === "tool_calls" && response.toolCalls !== void 0 && response.toolCalls.length > 0;
|
|
388
542
|
const tripToolCalls = [];
|
|
@@ -410,9 +564,10 @@ var Execution = class {
|
|
|
410
564
|
};
|
|
411
565
|
this.trips.push(trip);
|
|
412
566
|
this.emit("agent.trip.completed", { trip });
|
|
567
|
+
await this.checkpoint("running");
|
|
413
568
|
if (!isToolCallTrip) return "stop";
|
|
414
569
|
return response.toolCalls.every((request) => {
|
|
415
|
-
return
|
|
570
|
+
return this.effectiveTools.find((tool) => tool.name === request.name)?.mode === "silent";
|
|
416
571
|
}) ? "stop" : "continue";
|
|
417
572
|
}
|
|
418
573
|
/**
|
|
@@ -442,7 +597,7 @@ var Execution = class {
|
|
|
442
597
|
async getModelResponse(tripIndex) {
|
|
443
598
|
const callOptions = {
|
|
444
599
|
...this.config.modelOptions,
|
|
445
|
-
tools: this.
|
|
600
|
+
tools: this.effectiveTools,
|
|
446
601
|
...this.responseSchema ? { responseSchema: this.responseSchema } : {},
|
|
447
602
|
...this.options?.signal ? { signal: this.options.signal } : {}
|
|
448
603
|
};
|
|
@@ -458,7 +613,7 @@ var Execution = class {
|
|
|
458
613
|
const recoveredCalls = [];
|
|
459
614
|
const guardConfig = this.resolveStreamingToolGuard();
|
|
460
615
|
const guard = guardConfig ? new JsonStreamGuard({
|
|
461
|
-
tools: this.
|
|
616
|
+
tools: this.effectiveTools,
|
|
462
617
|
maxBufferBytes: guardConfig.maxBufferBytes,
|
|
463
618
|
onSafeDelta: (delta) => {
|
|
464
619
|
content += delta;
|
|
@@ -527,7 +682,7 @@ var Execution = class {
|
|
|
527
682
|
* an error). Never throws — always returns a `ToolCall` record.
|
|
528
683
|
*/
|
|
529
684
|
async dispatchToolCall(toolCallRequest, tripIndex) {
|
|
530
|
-
const registeredTool = this.
|
|
685
|
+
const registeredTool = this.effectiveTools.find((tool) => tool.name === toolCallRequest.name);
|
|
531
686
|
if (!registeredTool) {
|
|
532
687
|
const error = new AgentExecutionError(`Tool not registered: ${toolCallRequest.name}`, { context: {
|
|
533
688
|
toolName: toolCallRequest.name,
|
|
@@ -592,9 +747,15 @@ var Execution = class {
|
|
|
592
747
|
},
|
|
593
748
|
request: toolCallRequest
|
|
594
749
|
};
|
|
750
|
+
const runSignal = this.options?.signal;
|
|
751
|
+
const dispatchToolCtx = runSignal ? {
|
|
752
|
+
artifacts: this.options?.toolCtx?.artifacts ?? {},
|
|
753
|
+
...this.options?.toolCtx,
|
|
754
|
+
signal: runSignal
|
|
755
|
+
} : this.options?.toolCtx;
|
|
595
756
|
let invokeResult;
|
|
596
757
|
try {
|
|
597
|
-
invokeResult = await runPipeline(this.middleware, "tool", toolContext, () => registeredTool.invoke(toolCallRequest.input,
|
|
758
|
+
invokeResult = await runPipeline(this.middleware, "tool", toolContext, () => registeredTool.invoke(toolCallRequest.input, dispatchToolCtx), this.logger);
|
|
598
759
|
} catch (thrown) {
|
|
599
760
|
const error = this.toAIError(thrown);
|
|
600
761
|
const nowIso = (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -643,10 +804,7 @@ var Execution = class {
|
|
|
643
804
|
...toolCallRequest.recoveredFrom ? { recoveredFrom: toolCallRequest.recoveredFrom } : {}
|
|
644
805
|
};
|
|
645
806
|
this.toolCalls.push(record);
|
|
646
|
-
this.usage
|
|
647
|
-
this.usage.output += invokeResult.usage.output;
|
|
648
|
-
this.usage.total += invokeResult.usage.total;
|
|
649
|
-
this.usage.cost = accumulateCost(this.usage.cost, invokeResult.usage.cost);
|
|
807
|
+
mergeUsage(this.usage, invokeResult.usage);
|
|
650
808
|
this.messages.push({
|
|
651
809
|
role: "tool",
|
|
652
810
|
toolCallId: toolCallRequest.id,
|
|
@@ -675,13 +833,20 @@ var Execution = class {
|
|
|
675
833
|
* - `"failed"` — schema present, output text either failed JSON.parse
|
|
676
834
|
* or failed `~standard.validate`. Repairable via `runRepairLoop`.
|
|
677
835
|
* - `"success"` — parsed and validated; `this.data` populated.
|
|
836
|
+
*
|
|
837
|
+
* Under the judge-safe preset (`judge: true`) the JSON extraction is
|
|
838
|
+
* lenient — it tolerates fenced ` ```json ` blocks plus leading /
|
|
839
|
+
* trailing prose by slicing the first balanced object / array out of the
|
|
840
|
+
* response. Never throws regardless of preset: a parse / validation miss
|
|
841
|
+
* sets `this.error` and returns `"failed"`, leaving `this.data`
|
|
842
|
+
* undefined for the graceful-default path.
|
|
678
843
|
*/
|
|
679
844
|
async parseOutput() {
|
|
680
845
|
const schema = this.options?.output ?? this.config.output;
|
|
681
846
|
if (!schema || this.error) return "skipped";
|
|
682
847
|
const text = this.trips[this.trips.length - 1]?.output ?? "";
|
|
683
848
|
if (!text) return "skipped";
|
|
684
|
-
const payload = extractJsonPayload(text);
|
|
849
|
+
const payload = this.judgeConfig ? extractJsonLenient(text) : extractJsonPayload(text);
|
|
685
850
|
const sentinel = Symbol("parse-failed");
|
|
686
851
|
const parsed = safeJsonParse(payload, sentinel);
|
|
687
852
|
if (parsed === sentinel) {
|
|
@@ -698,8 +863,22 @@ var Execution = class {
|
|
|
698
863
|
return "success";
|
|
699
864
|
}
|
|
700
865
|
/**
|
|
866
|
+
* Resolve how many repair re-asks this run should perform after a parse
|
|
867
|
+
* failure. Per-call `options.repair` wins when explicitly set (preserving
|
|
868
|
+
* the existing surface). Otherwise the judge-safe preset supplies its
|
|
869
|
+
* default attempt count — so `judge: true` enables repair without the
|
|
870
|
+
* caller also having to pass `repair`. Returns `0` when neither applies,
|
|
871
|
+
* which leaves the historical "no repair unless asked" behavior intact.
|
|
872
|
+
*/
|
|
873
|
+
resolveRepairAttempts() {
|
|
874
|
+
if (this.options?.repair) return this.options.repair.maxAttempts ?? 1;
|
|
875
|
+
if (this.judgeConfig) return this.judgeConfig.repairAttempts ?? 2;
|
|
876
|
+
return 0;
|
|
877
|
+
}
|
|
878
|
+
/**
|
|
701
879
|
* Opt-in self-repair loop for `output` schema failures. Triggered only
|
|
702
|
-
* when
|
|
880
|
+
* when repair attempts remain (`resolveRepairAttempts() > 0`) and
|
|
881
|
+
* `parseOutput()` returned `"failed"`.
|
|
703
882
|
*
|
|
704
883
|
* Each attempt:
|
|
705
884
|
* 1. Pushes the bad assistant response into `this.messages` (so the
|
|
@@ -714,7 +893,7 @@ var Execution = class {
|
|
|
714
893
|
* outcome (success or last failure) is what surfaces to the caller.
|
|
715
894
|
*/
|
|
716
895
|
async runRepairLoop() {
|
|
717
|
-
const maxAttempts = this.
|
|
896
|
+
const maxAttempts = this.resolveRepairAttempts();
|
|
718
897
|
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
719
898
|
if (this.trips.length >= this.maxTrips) return;
|
|
720
899
|
const badResponse = this.trips[this.trips.length - 1]?.output ?? "";
|
|
@@ -764,6 +943,7 @@ var Execution = class {
|
|
|
764
943
|
version: this.config.version,
|
|
765
944
|
type: "agent",
|
|
766
945
|
status,
|
|
946
|
+
...this.error ? { error: this.error } : {},
|
|
767
947
|
startedAt: this.startedAt.toISOString(),
|
|
768
948
|
endedAt: endedAt.toISOString(),
|
|
769
949
|
duration: performance.now() - this.start,
|
|
@@ -773,7 +953,13 @@ var Execution = class {
|
|
|
773
953
|
name: this.config.model.name,
|
|
774
954
|
provider: this.config.model.provider
|
|
775
955
|
},
|
|
776
|
-
trips: this.trips
|
|
956
|
+
trips: this.trips,
|
|
957
|
+
systemPrompt: this.systemPrompt,
|
|
958
|
+
...this.promptName ? {
|
|
959
|
+
promptName: this.promptName,
|
|
960
|
+
promptVersion: this.promptVersion
|
|
961
|
+
} : {},
|
|
962
|
+
...this.config.captureMessages ? { messages: this.captureMessages() } : {}
|
|
777
963
|
};
|
|
778
964
|
stampReportLineage(report, {
|
|
779
965
|
rootRunId: this.runId,
|
|
@@ -789,6 +975,89 @@ var Execution = class {
|
|
|
789
975
|
};
|
|
790
976
|
}
|
|
791
977
|
/**
|
|
978
|
+
* Map the run's terminal outcome to the persisted snapshot status.
|
|
979
|
+
* A cancelled error reads as `"cancelled"`, any other error as
|
|
980
|
+
* `"failed"`, otherwise `"completed"`. Mirrors the report-status
|
|
981
|
+
* mapping in {@link buildResult}.
|
|
982
|
+
*/
|
|
983
|
+
resolveSnapshotStatus() {
|
|
984
|
+
if (!this.error) return "completed";
|
|
985
|
+
return this.error instanceof AgentCancelledError ? "cancelled" : "failed";
|
|
986
|
+
}
|
|
987
|
+
/**
|
|
988
|
+
* Build and persist an {@link AgentSnapshot} from the current
|
|
989
|
+
* accumulators. The per-trip and terminal checkpoints both route
|
|
990
|
+
* through here. Reuses {@link captureMessages} to normalize the live
|
|
991
|
+
* `Message[]` into JSON-safe form so the snapshot round-trips through
|
|
992
|
+
* any store backend.
|
|
993
|
+
*
|
|
994
|
+
* No-op (returns immediately) when `durable` is absent — the common
|
|
995
|
+
* non-durable path stays free. A failed persist is logged and
|
|
996
|
+
* swallowed (never aborts the run), matching the supervisor / workflow
|
|
997
|
+
* checkpoint policy.
|
|
998
|
+
*/
|
|
999
|
+
async checkpoint(status) {
|
|
1000
|
+
if (!this.config.durable) return;
|
|
1001
|
+
const outcome = await persistAgentSnapshot({
|
|
1002
|
+
durable: this.config.durable,
|
|
1003
|
+
runId: this.runId,
|
|
1004
|
+
agentName: this.config.name ?? this.config.model.name,
|
|
1005
|
+
signature: this.config.signature,
|
|
1006
|
+
version: this.config.version,
|
|
1007
|
+
input: this.input,
|
|
1008
|
+
systemPrompt: this.systemPrompt,
|
|
1009
|
+
responseSchema: this.responseSchema,
|
|
1010
|
+
promptName: this.promptName,
|
|
1011
|
+
promptVersion: this.promptVersion,
|
|
1012
|
+
messages: this.captureMessages(),
|
|
1013
|
+
trips: this.trips,
|
|
1014
|
+
toolCalls: this.toolCalls,
|
|
1015
|
+
usage: this.usage,
|
|
1016
|
+
status,
|
|
1017
|
+
startedAt: this.startedAt.toISOString()
|
|
1018
|
+
});
|
|
1019
|
+
if (!outcome.ok) this.logger.warn(LOG_MODULE, "snapshot.persist.failed", "durable snapshot persist failed", {
|
|
1020
|
+
runId: this.runId,
|
|
1021
|
+
status,
|
|
1022
|
+
error: outcome.error instanceof Error ? outcome.error.message : String(outcome.error)
|
|
1023
|
+
});
|
|
1024
|
+
}
|
|
1025
|
+
/**
|
|
1026
|
+
* Rebuild the final {@link AgentResult} from a COMPLETED snapshot
|
|
1027
|
+
* WITHOUT re-running anything. Used by the completed-run resume
|
|
1028
|
+
* short-circuit: the persisted trips / tool calls / usage are the
|
|
1029
|
+
* authoritative outcome, so a resume of a settled run re-returns that
|
|
1030
|
+
* outcome idempotently. Re-derives `this.data` from the final trip
|
|
1031
|
+
* output against the schema (cheap, no model call) so the rebuilt
|
|
1032
|
+
* result carries the same structured payload the original produced.
|
|
1033
|
+
*
|
|
1034
|
+
* Only reached for a `completed` snapshot — `failed` / `cancelled`
|
|
1035
|
+
* snapshots re-enter the trip loop to retry the remaining work instead.
|
|
1036
|
+
*/
|
|
1037
|
+
async rebuildResumedResult(_snapshot) {
|
|
1038
|
+
await this.parseOutput();
|
|
1039
|
+
return this.buildResult();
|
|
1040
|
+
}
|
|
1041
|
+
/**
|
|
1042
|
+
* Normalize the accumulated runtime `Message[]` into the JSON-safe
|
|
1043
|
+
* {@link CapturedMessage}[] persisted on `AgentReport.messages` (F2).
|
|
1044
|
+
* Flattens `ContentPart[]` content to a string, and forwards
|
|
1045
|
+
* `toolCalls` (assistant turns) / `toolCallId` (tool-result turns)
|
|
1046
|
+
* only when present so the captured shape stays lean. Called only when
|
|
1047
|
+
* `captureMessages` is enabled.
|
|
1048
|
+
*/
|
|
1049
|
+
captureMessages() {
|
|
1050
|
+
return this.messages.map((message) => {
|
|
1051
|
+
const captured = {
|
|
1052
|
+
role: message.role,
|
|
1053
|
+
content: typeof message.content === "string" ? message.content : JSON.stringify(message.content)
|
|
1054
|
+
};
|
|
1055
|
+
if (message.toolCalls !== void 0) captured.toolCalls = message.toolCalls;
|
|
1056
|
+
if (message.toolCallId !== void 0) captured.toolCallId = message.toolCallId;
|
|
1057
|
+
return captured;
|
|
1058
|
+
});
|
|
1059
|
+
}
|
|
1060
|
+
/**
|
|
792
1061
|
* Normalize any thrown value into an `AIError`. `AIError` instances
|
|
793
1062
|
* pass through untouched; provider-adapter SDK errors are caught by
|
|
794
1063
|
* the adapter and already arrive typed, so this branch mainly
|
|
@@ -832,12 +1101,13 @@ var Execution = class {
|
|
|
832
1101
|
rootRunId: this.runId
|
|
833
1102
|
};
|
|
834
1103
|
this.logEvent(event, fullPayload);
|
|
1104
|
+
const onError = (error) => this.surfaceHandlerError(event, error);
|
|
835
1105
|
const factoryHandler = this.config.on?.[event];
|
|
836
|
-
if (factoryHandler) safeCall(factoryHandler, fullPayload);
|
|
1106
|
+
if (factoryHandler) safeCall(factoryHandler, fullPayload, onError);
|
|
837
1107
|
const bucket = this.instanceHandlers?.get(event);
|
|
838
|
-
if (bucket) for (const handler of bucket) safeCall(handler, fullPayload);
|
|
1108
|
+
if (bucket) for (const handler of bucket) safeCall(handler, fullPayload, onError);
|
|
839
1109
|
const perCallHandler = this.options?.on?.[event];
|
|
840
|
-
if (perCallHandler) safeCall(perCallHandler, fullPayload);
|
|
1110
|
+
if (perCallHandler) safeCall(perCallHandler, fullPayload, onError);
|
|
841
1111
|
if (this.streamController) {
|
|
842
1112
|
const body = this.toStreamEvent(event, fullPayload);
|
|
843
1113
|
if (body) this.streamController.push({
|
|
@@ -848,6 +1118,23 @@ var Execution = class {
|
|
|
848
1118
|
}
|
|
849
1119
|
}
|
|
850
1120
|
/**
|
|
1121
|
+
* Surface an isolated event-handler failure (C5). A throwing user
|
|
1122
|
+
* handler never crashes the agent — that isolation is preserved — but
|
|
1123
|
+
* total silence is the wrong default: a broken `on` handler would
|
|
1124
|
+
* otherwise disappear from production with no signal. Routed to the
|
|
1125
|
+
* structured logger (matching the `onUsage` / `onComplete` policy) and
|
|
1126
|
+
* warned at most once per event type so a hot event can't spam the log.
|
|
1127
|
+
*/
|
|
1128
|
+
surfaceHandlerError(event, error) {
|
|
1129
|
+
if (this.warnedHandlerEvents.has(event)) return;
|
|
1130
|
+
this.warnedHandlerEvents.add(event);
|
|
1131
|
+
this.logger.warn(LOG_MODULE, "event.handler.error", "an event handler threw and was isolated", {
|
|
1132
|
+
runId: this.runId,
|
|
1133
|
+
event,
|
|
1134
|
+
error: error instanceof Error ? error.message : String(error)
|
|
1135
|
+
});
|
|
1136
|
+
}
|
|
1137
|
+
/**
|
|
851
1138
|
* Emit a structured log line for a lifecycle event. The action
|
|
852
1139
|
* string mirrors the event name with the `agent.` prefix stripped
|
|
853
1140
|
* (`agent.trip.started` → `trip.started`) so log grep filters and
|
|
@@ -953,18 +1240,23 @@ function stableStringify(value) {
|
|
|
953
1240
|
}
|
|
954
1241
|
/**
|
|
955
1242
|
* Invoke a user-supplied event handler without letting exceptions
|
|
956
|
-
* escape the agent.
|
|
957
|
-
*
|
|
1243
|
+
* escape the agent. A throw is isolated (it never crashes the agent)
|
|
1244
|
+
* but no longer silent: the optional `onError` surfaces it — the agent
|
|
1245
|
+
* routes it to its structured logger, matching the swallow-and-log
|
|
1246
|
+
* policy of the `onUsage` / `onComplete` hooks (C5).
|
|
958
1247
|
*/
|
|
959
|
-
function safeCall(handler, payload) {
|
|
1248
|
+
function safeCall(handler, payload, onError) {
|
|
960
1249
|
try {
|
|
961
1250
|
handler(payload);
|
|
962
|
-
} catch {
|
|
1251
|
+
} catch (error) {
|
|
1252
|
+
onError?.(error);
|
|
1253
|
+
}
|
|
963
1254
|
}
|
|
964
1255
|
/**
|
|
965
1256
|
* Resolve a tool's `action` declaration into a plain string for
|
|
966
1257
|
* inclusion in `ToolEventMeta`. Static strings pass through;
|
|
967
|
-
* function-shaped actions are invoked with the
|
|
1258
|
+
* function-shaped actions are invoked with the model's raw,
|
|
1259
|
+
* pre-validation input (before `execute`'s schema validation runs).
|
|
968
1260
|
*
|
|
969
1261
|
* Defensive: if the user's callback throws, swallow and return
|
|
970
1262
|
* `undefined` rather than crashing the agent — UI strings are not
|