@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
|
@@ -5,9 +5,14 @@ import { PlannerPlanInvalidError } from "../errors/planner-plan-invalid-error.mj
|
|
|
5
5
|
import { SchemaValidationError } from "../errors/schema-validation-error.mjs";
|
|
6
6
|
import { accumulateCost } from "../utils/compute-cost.mjs";
|
|
7
7
|
import { generateRunId } from "../utils/generate-run-id.mjs";
|
|
8
|
+
import { captureChildReport, withoutRunFrame } from "../utils/run-context.mjs";
|
|
8
9
|
import { REPORT_SCHEMA_VERSION } from "../contracts/result/base-report.type.mjs";
|
|
9
10
|
import { stampReportLineage } from "../utils/stamp-report-lineage.mjs";
|
|
11
|
+
import { notifyObservers } from "../observe/resolve-observers.mjs";
|
|
12
|
+
import { buildDag, readyNodes, sinkNodes } from "./dag-scheduler.mjs";
|
|
10
13
|
import { planSchema } from "./plan-schema.mjs";
|
|
14
|
+
import { deletePlannerSnapshot, persistPlannerSnapshot } from "./snapshot.mjs";
|
|
15
|
+
import { log } from "@warlock.js/logger";
|
|
11
16
|
|
|
12
17
|
//#region ../@warlock.js/ai/src/planner/planner-run.ts
|
|
13
18
|
/**
|
|
@@ -40,7 +45,18 @@ var PlannerRun = class {
|
|
|
40
45
|
};
|
|
41
46
|
this.children = [];
|
|
42
47
|
this.executedSteps = [];
|
|
43
|
-
this.
|
|
48
|
+
this.awaitingApproval = false;
|
|
49
|
+
this.replanCount = 0;
|
|
50
|
+
this.dagResumeConsumed = false;
|
|
51
|
+
this.runId = args.resumeFrom?.runId ?? args.options?.runId ?? generateRunId("planner");
|
|
52
|
+
if (args.resumeFrom) {
|
|
53
|
+
this.plan = args.resumeFrom.plan;
|
|
54
|
+
this.executedSteps.push(...args.resumeFrom.executedSteps);
|
|
55
|
+
this.children.push(...args.resumeFrom.children);
|
|
56
|
+
this.mergeUsage(this.usage, args.resumeFrom.usage);
|
|
57
|
+
this.replanCount = args.resumeFrom.replanCount;
|
|
58
|
+
this.startedAt = args.resumeFrom.startedAt;
|
|
59
|
+
}
|
|
44
60
|
}
|
|
45
61
|
/**
|
|
46
62
|
* Run the planner end-to-end. Never throws on runtime failure —
|
|
@@ -49,19 +65,57 @@ var PlannerRun = class {
|
|
|
49
65
|
* `report.status`.
|
|
50
66
|
*/
|
|
51
67
|
async run() {
|
|
68
|
+
const result = await this.runPlan();
|
|
69
|
+
await notifyObservers(this.args.config.observe, result.report);
|
|
70
|
+
captureChildReport(result.report);
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Drive the planner lifecycle and return the built result WITHOUT
|
|
75
|
+
* routing it — `run()` owns observer routing + auto-nesting so the
|
|
76
|
+
* unified tree is emitted exactly once.
|
|
77
|
+
*/
|
|
78
|
+
async runPlan() {
|
|
79
|
+
if (this.args.resumeFrom && this.args.resumeFrom.status === "completed") {
|
|
80
|
+
this.rebuildResumedTerminal("completed");
|
|
81
|
+
return this.buildResult();
|
|
82
|
+
}
|
|
52
83
|
try {
|
|
53
84
|
if (this.isAborted()) {
|
|
54
85
|
this.markCancelled();
|
|
86
|
+
await this.checkpoint(this.resolveSnapshotStatus());
|
|
87
|
+
return this.buildResult();
|
|
88
|
+
}
|
|
89
|
+
const plan = this.args.resumeFrom ? this.plan : this.args.options?.approvedPlan ?? await this.generatePlan();
|
|
90
|
+
if (this.error || !plan) {
|
|
91
|
+
await this.checkpoint(this.resolveSnapshotStatus());
|
|
55
92
|
return this.buildResult();
|
|
56
93
|
}
|
|
57
|
-
|
|
58
|
-
|
|
94
|
+
if (!this.args.resumeFrom) {
|
|
95
|
+
this.assertPlanValid(plan);
|
|
96
|
+
if (this.error) {
|
|
97
|
+
await this.checkpoint(this.resolveSnapshotStatus());
|
|
98
|
+
return this.buildResult();
|
|
99
|
+
}
|
|
100
|
+
}
|
|
59
101
|
this.plan = plan;
|
|
102
|
+
if (!this.args.resumeFrom && this.args.options?.mode === "plan-only" && !this.args.options?.approvedPlan) {
|
|
103
|
+
this.awaitingApproval = true;
|
|
104
|
+
return this.buildResult();
|
|
105
|
+
}
|
|
60
106
|
await this.executePlan(plan);
|
|
61
107
|
await this.finalizeOutput();
|
|
62
108
|
} catch (caught) {
|
|
63
109
|
this.error = this.toAIError(caught);
|
|
64
110
|
}
|
|
111
|
+
await this.checkpoint(this.resolveSnapshotStatus());
|
|
112
|
+
if (!this.error && this.args.config.durable?.deleteOnComplete) {
|
|
113
|
+
const outcome = await deletePlannerSnapshot({
|
|
114
|
+
durable: this.args.config.durable,
|
|
115
|
+
runId: this.runId
|
|
116
|
+
});
|
|
117
|
+
if (!outcome.ok) this.logDurableFailure("snapshot.delete.failed", outcome.error);
|
|
118
|
+
}
|
|
65
119
|
return this.buildResult();
|
|
66
120
|
}
|
|
67
121
|
/**
|
|
@@ -70,15 +124,19 @@ var PlannerRun = class {
|
|
|
70
124
|
* agent's per-call `output`, so the model is steered to reference only
|
|
71
125
|
* real capabilities. The planning trip's usage + report roll into the
|
|
72
126
|
* planner's totals regardless of outcome.
|
|
127
|
+
*
|
|
128
|
+
* `feedback` is set only on a RE-plan: the regenerated request is
|
|
129
|
+
* seeded with the executed-step digest plus the caller's feedback so
|
|
130
|
+
* the planner revises the remaining work rather than starting cold.
|
|
73
131
|
*/
|
|
74
|
-
async generatePlan() {
|
|
132
|
+
async generatePlan(feedback) {
|
|
75
133
|
const schema = planSchema([...this.args.capabilities.keys()], this.args.maxSteps);
|
|
76
|
-
const result = await this.args.planningAgent.execute(this.buildPlanPrompt(), {
|
|
134
|
+
const result = await withoutRunFrame(() => this.args.planningAgent.execute(this.buildPlanPrompt(feedback), {
|
|
77
135
|
output: schema,
|
|
78
136
|
placeholders: this.args.options?.placeholders,
|
|
79
137
|
signal: this.args.options?.signal,
|
|
80
138
|
sessionId: this.args.options?.sessionId
|
|
81
|
-
});
|
|
139
|
+
}));
|
|
82
140
|
this.absorb(result.usage, result.report);
|
|
83
141
|
if (result.error) {
|
|
84
142
|
this.error = result.error instanceof SchemaValidationError ? new PlannerPlanInvalidError(`ai.planner("${this.args.config.name}"): the planner produced no usable plan`, {
|
|
@@ -92,43 +150,179 @@ var PlannerRun = class {
|
|
|
92
150
|
this.error = new PlannerPlanInvalidError(`ai.planner("${this.args.config.name}"): the planner produced no usable plan`, { context: { runId: this.runId } });
|
|
93
151
|
return;
|
|
94
152
|
}
|
|
95
|
-
|
|
96
|
-
if (
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
153
|
+
this.assertPlanValid(plan);
|
|
154
|
+
if (this.error) return;
|
|
155
|
+
return plan;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Shared plan-validity guard — used both for a freshly generated plan
|
|
159
|
+
* and for a caller-supplied `approvedPlan`. Sets `this.error` to a
|
|
160
|
+
* typed {@link PlannerPlanInvalidError} when the plan is empty or names
|
|
161
|
+
* an unknown capability; a stale `approvedPlan` thus fails the same way
|
|
162
|
+
* a hallucinated capability does, never silently mis-dispatching.
|
|
163
|
+
*/
|
|
164
|
+
assertPlanValid(plan) {
|
|
165
|
+
if (!Array.isArray(plan.steps) || plan.steps.length === 0) {
|
|
166
|
+
this.error = new PlannerPlanInvalidError(`ai.planner("${this.args.config.name}"): the planner produced no usable plan`, { context: { runId: this.runId } });
|
|
101
167
|
return;
|
|
102
168
|
}
|
|
103
|
-
|
|
169
|
+
const unknownStep = plan.steps.find((step) => !this.args.capabilities.has(step.capability));
|
|
170
|
+
if (unknownStep) this.error = new PlannerPlanInvalidError(`ai.planner("${this.args.config.name}"): plan references unknown capability "${unknownStep.capability}"`, { context: {
|
|
171
|
+
runId: this.runId,
|
|
172
|
+
capability: unknownStep.capability
|
|
173
|
+
} });
|
|
104
174
|
}
|
|
105
175
|
/**
|
|
106
|
-
* Phase 2 — execute the plan
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
* recorded as `skipped` without running.
|
|
176
|
+
* Phase 2 — execute the plan. Branches on `config.dag`: the default is
|
|
177
|
+
* the strict array-order sequential loop (byte-for-byte today's
|
|
178
|
+
* behavior when neither `onStep` nor `replan` is configured); `dag:
|
|
179
|
+
* true` schedules independent `dependsOn` branches in parallel.
|
|
111
180
|
*/
|
|
112
181
|
async executePlan(plan) {
|
|
182
|
+
if (this.args.config.dag) return this.executeDag(plan);
|
|
183
|
+
return this.executeSequential(plan);
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Sequential executor — the original strict array-order loop, threading
|
|
187
|
+
* each completed step's output into the next step's input context.
|
|
188
|
+
* Stops at the first step failure or when the abort signal fires
|
|
189
|
+
* between steps; steps beyond `maxSteps` are recorded `skipped`.
|
|
190
|
+
*
|
|
191
|
+
* **Additive hooks (inert by default).** After each step settles it
|
|
192
|
+
* fires the `onStep` directive hook; an `abort` directive stops the run
|
|
193
|
+
* like a failure, and a `replan` directive (or, when `config.replan` is
|
|
194
|
+
* set, an unhandled failure) regenerates the REMAINING plan instead of
|
|
195
|
+
* aborting. With no `onStep` and no `replan`, the behavior is identical
|
|
196
|
+
* to before.
|
|
197
|
+
*/
|
|
198
|
+
async executeSequential(plan) {
|
|
113
199
|
const previousOutputs = [];
|
|
114
|
-
|
|
115
|
-
|
|
200
|
+
let steps = plan.steps;
|
|
201
|
+
let index = 0;
|
|
202
|
+
if (this.args.resumeFrom) index = this.rehydrateSequentialState(steps, previousOutputs);
|
|
203
|
+
while (index < steps.length) {
|
|
204
|
+
const step = steps[index];
|
|
116
205
|
if (index >= this.args.maxSteps) {
|
|
117
206
|
this.recordSkipped(index, step);
|
|
207
|
+
index++;
|
|
118
208
|
continue;
|
|
119
209
|
}
|
|
120
210
|
if (this.isAborted()) {
|
|
121
211
|
this.markCancelled();
|
|
122
212
|
this.recordSkipped(index, step);
|
|
213
|
+
index++;
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
const completed = await this.executeStep(index, step, previousOutputs);
|
|
217
|
+
const snapshot = this.snapshotFor(index);
|
|
218
|
+
const directive = snapshot ? await this.resolveDirective(snapshot, plan, completed) : void 0;
|
|
219
|
+
if (directive?.type === "replan") {
|
|
220
|
+
const remaining = await this.regeneratePlan(directive.feedback);
|
|
221
|
+
if (this.error || !remaining) {
|
|
222
|
+
this.skipRest(steps, index + 1);
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
steps = remaining.steps;
|
|
226
|
+
index = 0;
|
|
227
|
+
previousOutputs.length = 0;
|
|
228
|
+
previousOutputs.push(...this.executedDigest());
|
|
123
229
|
continue;
|
|
124
230
|
}
|
|
125
|
-
if (
|
|
126
|
-
|
|
231
|
+
if (directive?.type === "abort") {
|
|
232
|
+
this.skipRest(steps, index + 1);
|
|
127
233
|
return;
|
|
128
234
|
}
|
|
235
|
+
index++;
|
|
129
236
|
}
|
|
130
237
|
}
|
|
131
238
|
/**
|
|
239
|
+
* DAG executor — schedule independent `dependsOn` branches in parallel.
|
|
240
|
+
*
|
|
241
|
+
* Builds the DAG (cycle / unknown-id → `PlannerPlanInvalidError`),
|
|
242
|
+
* then repeatedly computes the ready set (steps whose deps all
|
|
243
|
+
* completed), dispatches up to `maxConcurrency` of them with
|
|
244
|
+
* `Promise.all`, and feeds each step ONLY its dependencies' outputs. A
|
|
245
|
+
* failed step blocks just its descendants (recorded `skipped`);
|
|
246
|
+
* independent branches still settle. With an `output` schema set, the
|
|
247
|
+
* final `data` is the topological SINK's output (multiple sinks → a
|
|
248
|
+
* convergence error).
|
|
249
|
+
*/
|
|
250
|
+
async executeDag(plan) {
|
|
251
|
+
const dag = buildDag(plan.steps, this.args.config.name);
|
|
252
|
+
const maxConcurrency = Math.max(1, this.args.config.maxConcurrency ?? 4);
|
|
253
|
+
const completed = /* @__PURE__ */ new Set();
|
|
254
|
+
const done = /* @__PURE__ */ new Set();
|
|
255
|
+
const outputs = /* @__PURE__ */ new Map();
|
|
256
|
+
const rawOutputs = /* @__PURE__ */ new Map();
|
|
257
|
+
let executedCount = 0;
|
|
258
|
+
if (this.args.resumeFrom && !this.dagResumeConsumed) {
|
|
259
|
+
this.dagResumeConsumed = true;
|
|
260
|
+
executedCount = this.rehydrateDagState(dag, completed, done, outputs, rawOutputs);
|
|
261
|
+
}
|
|
262
|
+
while (done.size < dag.nodes.length) {
|
|
263
|
+
if (this.isAborted()) {
|
|
264
|
+
this.markCancelled();
|
|
265
|
+
this.skipDagRest(dag, done);
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
const ready = readyNodes(dag, completed, done);
|
|
269
|
+
if (ready.length === 0) {
|
|
270
|
+
this.skipDagRest(dag, done);
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
const batch = ready.slice(0, maxConcurrency);
|
|
274
|
+
const settled = await Promise.all(batch.map(async (node) => {
|
|
275
|
+
if (executedCount >= this.args.maxSteps) {
|
|
276
|
+
this.recordSkipped(node.index, node.step);
|
|
277
|
+
return {
|
|
278
|
+
node,
|
|
279
|
+
ran: false,
|
|
280
|
+
completed: false
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
executedCount++;
|
|
284
|
+
const previousOutputs = node.dependencies.map((dependency) => outputs.get(dependency));
|
|
285
|
+
const stepCompleted = await this.executeStep(node.index, node.step, previousOutputs);
|
|
286
|
+
if (stepCompleted) {
|
|
287
|
+
const rawOutput = this.snapshotFor(node.index)?.output;
|
|
288
|
+
rawOutputs.set(node.id, rawOutput);
|
|
289
|
+
outputs.set(node.id, this.stringifyOutput(node.step.capability, rawOutput));
|
|
290
|
+
}
|
|
291
|
+
return {
|
|
292
|
+
node,
|
|
293
|
+
ran: true,
|
|
294
|
+
completed: stepCompleted
|
|
295
|
+
};
|
|
296
|
+
}));
|
|
297
|
+
for (const entry of settled) {
|
|
298
|
+
done.add(entry.node.id);
|
|
299
|
+
if (entry.completed) completed.add(entry.node.id);
|
|
300
|
+
}
|
|
301
|
+
let replanFeedback;
|
|
302
|
+
let shouldAbort = false;
|
|
303
|
+
for (const entry of settled) {
|
|
304
|
+
if (!entry.ran) continue;
|
|
305
|
+
const snapshot = this.snapshotFor(entry.node.index);
|
|
306
|
+
const directive = snapshot ? await this.resolveDirective(snapshot, plan, entry.completed) : void 0;
|
|
307
|
+
if (directive?.type === "replan") replanFeedback = directive.feedback;
|
|
308
|
+
else if (directive?.type === "abort") shouldAbort = true;
|
|
309
|
+
}
|
|
310
|
+
if (shouldAbort) {
|
|
311
|
+
this.skipDagRest(dag, done);
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
if (replanFeedback !== void 0) {
|
|
315
|
+
const remaining = await this.regeneratePlan(replanFeedback);
|
|
316
|
+
if (this.error || !remaining) {
|
|
317
|
+
this.skipDagRest(dag, done);
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
return this.executeDag(remaining);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
this.finalizeDagOutput(dag, completed, rawOutputs);
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
132
326
|
* Dispatch one plan step through its capability's `executable.execute()`
|
|
133
327
|
* and fold the outcome into the accumulators. Returns `true` when the
|
|
134
328
|
* step completed, `false` when it failed (setting the run error).
|
|
@@ -138,10 +332,10 @@ var PlannerRun = class {
|
|
|
138
332
|
const stepStart = performance.now();
|
|
139
333
|
const startedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
140
334
|
const input = this.composeStepInput(step, previousOutputs);
|
|
141
|
-
const result = await capability.executable.execute(input, {
|
|
335
|
+
const result = await withoutRunFrame(() => capability.executable.execute(input, {
|
|
142
336
|
signal: this.args.options?.signal,
|
|
143
337
|
sessionId: this.args.options?.sessionId
|
|
144
|
-
});
|
|
338
|
+
}));
|
|
145
339
|
const childReport = "report" in result ? result.report : void 0;
|
|
146
340
|
this.absorb(result.usage, childReport);
|
|
147
341
|
const output = this.extractOutput(result);
|
|
@@ -158,6 +352,7 @@ var PlannerRun = class {
|
|
|
158
352
|
usage: result.usage,
|
|
159
353
|
childReport
|
|
160
354
|
});
|
|
355
|
+
await this.checkpoint("running");
|
|
161
356
|
if (failed) {
|
|
162
357
|
this.error = result.error;
|
|
163
358
|
return false;
|
|
@@ -167,6 +362,104 @@ var PlannerRun = class {
|
|
|
167
362
|
return true;
|
|
168
363
|
}
|
|
169
364
|
/**
|
|
365
|
+
* Resolve the steering directive for a just-settled step, shared by the
|
|
366
|
+
* sequential and DAG executors. Fires the user's `onStep` hook, then
|
|
367
|
+
* normalizes the result against the `replan` budget:
|
|
368
|
+
*
|
|
369
|
+
* - explicit `replan` directive — honored only when `config.replan` is
|
|
370
|
+
* set and the budget remains; otherwise downgraded to `continue`.
|
|
371
|
+
* - explicit `abort` — honored.
|
|
372
|
+
* - failed step with no overriding directive — auto-`replan` when
|
|
373
|
+
* `config.replan` is set and the budget remains (feedback = the step
|
|
374
|
+
* error message), else `abort` (today's abort-on-first-failure).
|
|
375
|
+
*
|
|
376
|
+
* Returns `undefined` when the run should simply continue. A returned
|
|
377
|
+
* `replan` directive has ALREADY consumed one unit of the replan budget.
|
|
378
|
+
*/
|
|
379
|
+
async resolveDirective(snapshot, plan, completed) {
|
|
380
|
+
const hook = this.args.options?.onStep;
|
|
381
|
+
const userDirective = hook ? await hook(snapshot, plan) : void 0;
|
|
382
|
+
if (userDirective?.type === "replan") {
|
|
383
|
+
if (this.canReplan()) {
|
|
384
|
+
this.replanCount++;
|
|
385
|
+
return userDirective;
|
|
386
|
+
}
|
|
387
|
+
} else if (userDirective?.type === "abort") return { type: "abort" };
|
|
388
|
+
else if (userDirective?.type === "continue") return;
|
|
389
|
+
if (!completed) {
|
|
390
|
+
if (this.canReplan()) {
|
|
391
|
+
this.replanCount++;
|
|
392
|
+
return {
|
|
393
|
+
type: "replan",
|
|
394
|
+
feedback: snapshot.error?.message ?? "step failed"
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
return { type: "abort" };
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
/** Whether a re-plan is configured and the budget has room. */
|
|
401
|
+
canReplan() {
|
|
402
|
+
const replan = this.args.config.replan;
|
|
403
|
+
return replan !== void 0 && this.replanCount < replan.maxReplans;
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Re-ask the planning agent for a plan over the REMAINING work — a
|
|
407
|
+
* second `generatePlan()` seeded with the executed-step digest plus the
|
|
408
|
+
* caller's feedback. Reuses the exact `generatePlan` plumbing (same
|
|
409
|
+
* schema, same `PlannerPlanInvalidError` handling), so a regenerated
|
|
410
|
+
* plan that is empty or names an unknown capability fails identically.
|
|
411
|
+
* The failed step's error is cleared so the regenerated plan runs
|
|
412
|
+
* cleanly; a fresh failure (or exhausted budget) re-sets it.
|
|
413
|
+
*/
|
|
414
|
+
async regeneratePlan(feedback) {
|
|
415
|
+
this.error = void 0;
|
|
416
|
+
return this.generatePlan(feedback);
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* The executed-so-far digest — one context line per completed step, in
|
|
420
|
+
* execution order. Seeds the regenerated plan's first step so it builds
|
|
421
|
+
* on what already ran.
|
|
422
|
+
*/
|
|
423
|
+
executedDigest() {
|
|
424
|
+
return this.executedSteps.filter((snapshot) => snapshot.status === "completed").map((snapshot) => this.stringifyOutput(snapshot.step.capability, snapshot.output));
|
|
425
|
+
}
|
|
426
|
+
/** The last-pushed snapshot for a given step index, if any. */
|
|
427
|
+
snapshotFor(index) {
|
|
428
|
+
for (let position = this.executedSteps.length - 1; position >= 0; position--) {
|
|
429
|
+
const snapshot = this.executedSteps[position];
|
|
430
|
+
if (snapshot.index === index) return snapshot;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
/** Record every step from `from` onward (in a flat array plan) as skipped. */
|
|
434
|
+
skipRest(steps, from) {
|
|
435
|
+
for (let rest = from; rest < steps.length; rest++) this.recordSkipped(rest, steps[rest]);
|
|
436
|
+
}
|
|
437
|
+
/** Record every not-yet-`done` DAG node as skipped, in plan order. */
|
|
438
|
+
skipDagRest(dag, done) {
|
|
439
|
+
for (const node of dag.nodes) if (!done.has(node.id)) this.recordSkipped(node.index, node.step);
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Set `this.data` from the DAG's topological sink for a configured
|
|
443
|
+
* `output` schema. "Last completed step" is meaningless under
|
|
444
|
+
* parallelism, so the sink (the step nothing depends on) is the
|
|
445
|
+
* unambiguous final output. Multiple sinks while an `output` schema is
|
|
446
|
+
* set is a convergence error — a typed `PlannerPlanInvalidError`.
|
|
447
|
+
*/
|
|
448
|
+
finalizeDagOutput(dag, completed, rawOutputs) {
|
|
449
|
+
if (!(this.args.options?.output ?? this.args.config.output) || this.error) return;
|
|
450
|
+
const sinks = sinkNodes(dag).filter((node) => completed.has(node.id));
|
|
451
|
+
if (sinks.length > 1) {
|
|
452
|
+
this.error = new PlannerPlanInvalidError(`ai.planner("${this.args.config.name}"): DAG has multiple sinks but an \`output\` schema is set — the plan must converge to a single final step`, { context: {
|
|
453
|
+
runId: this.runId,
|
|
454
|
+
sinks: sinks.map((node) => node.id)
|
|
455
|
+
} });
|
|
456
|
+
this.data = void 0;
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
const sink = sinks[0];
|
|
460
|
+
this.data = sink ? rawOutputs.get(sink.id) : void 0;
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
170
463
|
* Phase 3 — when an `output` schema is configured (factory or per-call
|
|
171
464
|
* override), validate the final completed step's output into typed
|
|
172
465
|
* `result.data`. A validation failure replaces the run error and flips
|
|
@@ -205,6 +498,7 @@ var PlannerRun = class {
|
|
|
205
498
|
version: this.args.config.version,
|
|
206
499
|
type: "planner",
|
|
207
500
|
status,
|
|
501
|
+
...this.error ? { error: this.error } : {},
|
|
208
502
|
startedAt: this.startedAt,
|
|
209
503
|
endedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
210
504
|
duration: performance.now() - this.startPerf,
|
|
@@ -220,27 +514,42 @@ var PlannerRun = class {
|
|
|
220
514
|
rootRunId: this.runId,
|
|
221
515
|
sessionId: this.args.options?.sessionId
|
|
222
516
|
});
|
|
223
|
-
|
|
517
|
+
const result = {
|
|
224
518
|
type: "planner",
|
|
225
519
|
data: this.error ? void 0 : this.data,
|
|
226
520
|
error: this.error,
|
|
227
521
|
usage: this.usage,
|
|
228
522
|
report
|
|
229
523
|
};
|
|
524
|
+
if (this.awaitingApproval) result.plan = this.plan;
|
|
525
|
+
return result;
|
|
230
526
|
}
|
|
231
527
|
/**
|
|
232
|
-
* Resolve the terminal status from the accumulated outcome.
|
|
233
|
-
*
|
|
234
|
-
*
|
|
528
|
+
* Resolve the terminal status from the accumulated outcome.
|
|
529
|
+
* `awaiting-approval` (plan-only short-circuit) wins over everything —
|
|
530
|
+
* nothing executed, so neither cancellation nor error applies.
|
|
531
|
+
* Otherwise cancelled wins over failed (an abort that also produced a
|
|
532
|
+
* step error still reads as cancelled); failed wins over completed.
|
|
235
533
|
*/
|
|
236
534
|
resolveStatus() {
|
|
535
|
+
if (this.awaitingApproval) return "awaiting-approval";
|
|
237
536
|
if (this.cancelledAt !== void 0) return "cancelled";
|
|
238
537
|
if (this.error) return "failed";
|
|
239
538
|
return "completed";
|
|
240
539
|
}
|
|
241
|
-
/**
|
|
242
|
-
|
|
243
|
-
|
|
540
|
+
/**
|
|
541
|
+
* Build the prompt handed to the planning agent. On the first pass this
|
|
542
|
+
* is just the user's goal (byte-for-byte unchanged). On a RE-plan it
|
|
543
|
+
* prepends the executed-step digest and the steering feedback so the
|
|
544
|
+
* planner revises the remaining work.
|
|
545
|
+
*/
|
|
546
|
+
buildPlanPrompt(feedback) {
|
|
547
|
+
if (feedback === void 0) return this.args.goal;
|
|
548
|
+
const digest = this.executedDigest();
|
|
549
|
+
const sections = [`Goal: ${this.args.goal}`, ""];
|
|
550
|
+
if (digest.length > 0) sections.push("Steps already completed:", ...digest, "");
|
|
551
|
+
sections.push(`Feedback requiring a revised plan: ${feedback}`, "", "Produce a plan for the REMAINING work only.");
|
|
552
|
+
return sections.join("\n");
|
|
244
553
|
}
|
|
245
554
|
/**
|
|
246
555
|
* Compose a step's effective input: the step's own `input`, prefixed
|
|
@@ -313,6 +622,123 @@ var PlannerRun = class {
|
|
|
313
622
|
const mergedCost = accumulateCost(target.cost, child.cost);
|
|
314
623
|
if (mergedCost !== void 0) target.cost = mergedCost;
|
|
315
624
|
}
|
|
625
|
+
/**
|
|
626
|
+
* Re-derive the sequential cursor + prior-output context from the
|
|
627
|
+
* persisted ledger on resume. Threads every already-`completed` node's
|
|
628
|
+
* output into `previousOutputs`, returns the first index NOT completed
|
|
629
|
+
* as the resume cursor, and prunes stale non-completed ledger entries
|
|
630
|
+
* (the failed node + any skipped tail) at-or-after that cursor so the
|
|
631
|
+
* re-run repopulates them without duplicating.
|
|
632
|
+
*/
|
|
633
|
+
rehydrateSequentialState(steps, previousOutputs) {
|
|
634
|
+
let cursor = 0;
|
|
635
|
+
for (let index = 0; index < steps.length; index++) {
|
|
636
|
+
const snapshot = this.snapshotFor(index);
|
|
637
|
+
if (snapshot?.status === "completed") {
|
|
638
|
+
const step = steps[index];
|
|
639
|
+
previousOutputs.push(this.stringifyOutput(step.capability, snapshot.output));
|
|
640
|
+
cursor = index + 1;
|
|
641
|
+
continue;
|
|
642
|
+
}
|
|
643
|
+
break;
|
|
644
|
+
}
|
|
645
|
+
this.pruneLedgerFrom(cursor);
|
|
646
|
+
return cursor;
|
|
647
|
+
}
|
|
648
|
+
/**
|
|
649
|
+
* Re-derive the DAG scheduler's working sets from the persisted ledger
|
|
650
|
+
* on resume. Completed nodes go into `completed` + `done` with their
|
|
651
|
+
* string + raw outputs restored (so dependents read the right context);
|
|
652
|
+
* stale non-completed entries are pruned so the re-run repopulates them.
|
|
653
|
+
* Returns the count of nodes already dispatched (for the `maxSteps`
|
|
654
|
+
* truncation budget).
|
|
655
|
+
*/
|
|
656
|
+
rehydrateDagState(dag, completed, done, outputs, rawOutputs) {
|
|
657
|
+
const completedIndices = /* @__PURE__ */ new Set();
|
|
658
|
+
for (const node of dag.nodes) {
|
|
659
|
+
const snapshot = this.snapshotFor(node.index);
|
|
660
|
+
if (snapshot?.status !== "completed") continue;
|
|
661
|
+
completed.add(node.id);
|
|
662
|
+
done.add(node.id);
|
|
663
|
+
completedIndices.add(node.index);
|
|
664
|
+
rawOutputs.set(node.id, snapshot.output);
|
|
665
|
+
outputs.set(node.id, this.stringifyOutput(node.step.capability, snapshot.output));
|
|
666
|
+
}
|
|
667
|
+
const retained = this.executedSteps.filter((snapshot) => completedIndices.has(snapshot.index));
|
|
668
|
+
this.executedSteps.length = 0;
|
|
669
|
+
this.executedSteps.push(...retained);
|
|
670
|
+
return completedIndices.size;
|
|
671
|
+
}
|
|
672
|
+
/**
|
|
673
|
+
* Drop every ledger entry whose index is at or after `from`. Used by
|
|
674
|
+
* the sequential resume re-seed to clear the crashed run's failed /
|
|
675
|
+
* skipped frontier before the re-run repopulates it.
|
|
676
|
+
*/
|
|
677
|
+
pruneLedgerFrom(from) {
|
|
678
|
+
const retained = this.executedSteps.filter((snapshot) => snapshot.index < from);
|
|
679
|
+
this.executedSteps.length = 0;
|
|
680
|
+
this.executedSteps.push(...retained);
|
|
681
|
+
}
|
|
682
|
+
/**
|
|
683
|
+
* Map the run's terminal outcome to the persisted snapshot status.
|
|
684
|
+
* `awaiting-approval` (plan-only) never persists a durable snapshot
|
|
685
|
+
* (resume is always an execution), so it folds to `running` here —
|
|
686
|
+
* but the durable + plan-only combination is disallowed at the call
|
|
687
|
+
* site, so this path is effectively unreachable.
|
|
688
|
+
*/
|
|
689
|
+
resolveSnapshotStatus() {
|
|
690
|
+
if (this.cancelledAt !== void 0) return "cancelled";
|
|
691
|
+
if (this.error) return "failed";
|
|
692
|
+
if (this.awaitingApproval) return "running";
|
|
693
|
+
return "completed";
|
|
694
|
+
}
|
|
695
|
+
/**
|
|
696
|
+
* Build and persist a {@link PlannerSnapshot} from the current
|
|
697
|
+
* accumulators. The per-node and terminal checkpoints both route
|
|
698
|
+
* through here. No-op when `durable` is absent. A failed persist is
|
|
699
|
+
* logged and swallowed (never aborts the run), matching the supervisor
|
|
700
|
+
* / workflow checkpoint policy.
|
|
701
|
+
*/
|
|
702
|
+
async checkpoint(status) {
|
|
703
|
+
if (!this.args.config.durable || !this.plan) return;
|
|
704
|
+
const outcome = await persistPlannerSnapshot({
|
|
705
|
+
durable: this.args.config.durable,
|
|
706
|
+
runId: this.runId,
|
|
707
|
+
plannerName: this.args.config.name,
|
|
708
|
+
signature: this.args.signature,
|
|
709
|
+
version: this.args.config.version,
|
|
710
|
+
goal: this.args.goal,
|
|
711
|
+
plan: this.plan,
|
|
712
|
+
executedSteps: this.executedSteps,
|
|
713
|
+
usage: this.usage,
|
|
714
|
+
children: this.children,
|
|
715
|
+
replanCount: this.replanCount,
|
|
716
|
+
status,
|
|
717
|
+
startedAt: this.startedAt
|
|
718
|
+
});
|
|
719
|
+
if (!outcome.ok) this.logDurableFailure("snapshot.persist.failed", outcome.error);
|
|
720
|
+
}
|
|
721
|
+
/**
|
|
722
|
+
* Re-derive the terminal state when a resume short-circuits a snapshot
|
|
723
|
+
* whose run already COMPLETED. The persisted ledger is the
|
|
724
|
+
* authoritative outcome — `this.data` is restored from the last
|
|
725
|
+
* completed node so the rebuilt result carries the final output.
|
|
726
|
+
*
|
|
727
|
+
* Only reached for a `completed` snapshot — `failed` / `cancelled`
|
|
728
|
+
* snapshots re-enter execution to retry the unfinished frontier instead.
|
|
729
|
+
*/
|
|
730
|
+
rebuildResumedTerminal(_status) {
|
|
731
|
+
const lastCompleted = [...this.executedSteps].reverse().find((snapshot) => snapshot.status === "completed");
|
|
732
|
+
if (lastCompleted) this.data = lastCompleted.output;
|
|
733
|
+
}
|
|
734
|
+
/** Structured-log a durable persist/delete failure. */
|
|
735
|
+
logDurableFailure(action, error) {
|
|
736
|
+
log.warn("ai.planner", action, "durable snapshot operation failed", {
|
|
737
|
+
runId: this.runId,
|
|
738
|
+
planner: this.args.config.name,
|
|
739
|
+
error: error instanceof Error ? error.message : String(error)
|
|
740
|
+
});
|
|
741
|
+
}
|
|
316
742
|
/** Whether the caller's abort signal has fired. */
|
|
317
743
|
isAborted() {
|
|
318
744
|
return this.args.options?.signal?.aborted === true;
|