@warlock.js/ai 4.4.0 → 4.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +52 -55
- package/cjs/index.cjs +221 -14147
- package/cjs/src-C02yzsLs.cjs +22991 -0
- package/cjs/src-C02yzsLs.cjs.map +1 -0
- package/cjs/src-DFibP2FQ.cjs +30 -0
- package/esm/agent/agent-config.type.d.mts +90 -1
- package/esm/agent/agent-config.type.d.mts.map +1 -1
- package/esm/agent/agent-input-builder.mjs +27 -6
- package/esm/agent/agent-input-builder.mjs.map +1 -1
- package/esm/agent/agent.d.mts +40 -1
- package/esm/agent/agent.d.mts.map +1 -1
- package/esm/agent/agent.mjs +203 -30
- package/esm/agent/agent.mjs.map +1 -1
- package/esm/agent/index.d.mts +2 -1
- package/esm/agent/index.mjs +1 -0
- package/esm/agent/judge-config.type.d.mts +33 -0
- package/esm/agent/judge-config.type.d.mts.map +1 -0
- package/esm/agent/judge-config.type.mjs +13 -0
- package/esm/agent/judge-config.type.mjs.map +1 -0
- package/esm/ai-openai/src/embedder.mjs +4 -0
- package/esm/ai-openai/src/index.mjs +4 -0
- package/esm/ai-openai/src/model.mjs +5 -0
- package/esm/ai-openai/src/sdk.mjs +6 -0
- package/esm/ai-openai/src/utils/index.mjs +4 -0
- package/esm/ai-openai/src/utils/to-openai-tools.mjs +3 -0
- package/esm/ai-openai/src/utils/wrap-openai-error.mjs +4 -0
- package/esm/ai.d.mts +119 -53
- package/esm/ai.d.mts.map +1 -1
- package/esm/ai.mjs +43 -8
- package/esm/ai.mjs.map +1 -1
- package/esm/batch/batch.d.mts.map +1 -1
- package/esm/batch/batch.mjs +21 -1
- package/esm/batch/batch.mjs.map +1 -1
- package/esm/batch/batch.type.d.mts +11 -4
- package/esm/batch/batch.type.d.mts.map +1 -1
- package/esm/config.d.mts +39 -3
- package/esm/config.d.mts.map +1 -1
- package/esm/config.mjs +26 -2
- package/esm/config.mjs.map +1 -1
- package/esm/contracts/agent/agent-options.type.d.mts +11 -3
- package/esm/contracts/agent/agent-options.type.d.mts.map +1 -1
- package/esm/contracts/agent/eval.type.d.mts +43 -2
- package/esm/contracts/agent/eval.type.d.mts.map +1 -1
- package/esm/contracts/attachment-policy.type.d.mts +51 -0
- package/esm/contracts/attachment-policy.type.d.mts.map +1 -0
- package/esm/contracts/attachment.type.d.mts +16 -7
- package/esm/contracts/attachment.type.d.mts.map +1 -1
- package/esm/contracts/content-part.type.d.mts +14 -5
- package/esm/contracts/content-part.type.d.mts.map +1 -1
- package/esm/contracts/events/supervisor-events.type.d.mts.map +1 -1
- package/esm/contracts/index.d.mts +6 -4
- package/esm/contracts/model.contract.d.mts +11 -8
- package/esm/contracts/model.contract.d.mts.map +1 -1
- package/esm/contracts/orchestrator/index.d.mts +1 -0
- package/esm/contracts/orchestrator/orchestrator-config.type.d.mts +31 -2
- package/esm/contracts/orchestrator/orchestrator-config.type.d.mts.map +1 -1
- package/esm/contracts/orchestrator/session-lock.contract.d.mts +47 -0
- package/esm/contracts/orchestrator/session-lock.contract.d.mts.map +1 -0
- package/esm/contracts/planner/index.d.mts +1 -1
- package/esm/contracts/planner/planner-config.type.d.mts +31 -0
- package/esm/contracts/planner/planner-config.type.d.mts.map +1 -1
- package/esm/contracts/planner/planner-execute-options.type.d.mts +48 -1
- package/esm/contracts/planner/planner-execute-options.type.d.mts.map +1 -1
- package/esm/contracts/planner/planner-result.type.d.mts +8 -0
- package/esm/contracts/planner/planner-result.type.d.mts.map +1 -1
- package/esm/contracts/planner/planner.contract.d.mts +1 -1
- package/esm/contracts/result/agent-result.type.d.mts +6 -4
- package/esm/contracts/result/agent-result.type.d.mts.map +1 -1
- package/esm/contracts/result/base-report.type.d.mts +21 -3
- package/esm/contracts/result/base-report.type.d.mts.map +1 -1
- package/esm/contracts/result/base-report.type.mjs.map +1 -1
- package/esm/contracts/result/execution-report.type.d.mts +53 -1
- package/esm/contracts/result/execution-report.type.d.mts.map +1 -1
- package/esm/contracts/result/supervisor-result.type.d.mts +14 -2
- package/esm/contracts/result/supervisor-result.type.d.mts.map +1 -1
- package/esm/contracts/result/workflow-result.type.d.mts +2 -1
- package/esm/contracts/result/workflow-result.type.d.mts.map +1 -1
- package/esm/contracts/supervisor/supervisor-config.type.d.mts +29 -0
- package/esm/contracts/supervisor/supervisor-config.type.d.mts.map +1 -1
- package/esm/contracts/system-prompt.contract.d.mts +103 -1
- package/esm/contracts/system-prompt.contract.d.mts.map +1 -1
- package/esm/contracts/team/index.d.mts +1 -0
- package/esm/contracts/team/team-config.type.d.mts +127 -0
- package/esm/contracts/team/team-config.type.d.mts.map +1 -0
- package/esm/contracts/tool.contract.d.mts +4 -2
- package/esm/contracts/tool.contract.d.mts.map +1 -1
- package/esm/contracts/workflow/step.contract.d.mts +30 -5
- package/esm/contracts/workflow/step.contract.d.mts.map +1 -1
- package/esm/contracts/workflow/workflow.contract.d.mts +16 -0
- package/esm/contracts/workflow/workflow.contract.d.mts.map +1 -1
- package/esm/errors/error-code.type.d.mts +1 -1
- package/esm/errors/index.d.mts +1 -0
- package/esm/errors/index.mjs +1 -0
- package/esm/errors/outbound-policy-error.d.mts +27 -0
- package/esm/errors/outbound-policy-error.d.mts.map +1 -0
- package/esm/errors/outbound-policy-error.mjs +32 -0
- package/esm/errors/outbound-policy-error.mjs.map +1 -0
- package/esm/eval/dataset.d.mts +28 -0
- package/esm/eval/dataset.d.mts.map +1 -0
- package/esm/eval/dataset.mjs +112 -0
- package/esm/eval/dataset.mjs.map +1 -0
- package/esm/eval/dataset.type.d.mts +53 -0
- package/esm/eval/dataset.type.d.mts.map +1 -0
- package/esm/eval/eval-runner.d.mts.map +1 -1
- package/esm/eval/eval-runner.mjs +16 -2
- package/esm/eval/eval-runner.mjs.map +1 -1
- package/esm/eval/index.d.mts +20 -1
- package/esm/eval/index.d.mts.map +1 -1
- package/esm/eval/index.mjs +20 -2
- package/esm/eval/index.mjs.map +1 -1
- package/esm/eval/regression.d.mts +30 -0
- package/esm/eval/regression.d.mts.map +1 -0
- package/esm/eval/regression.mjs +51 -0
- package/esm/eval/regression.mjs.map +1 -0
- package/esm/eval/report-json.d.mts +30 -0
- package/esm/eval/report-json.d.mts.map +1 -0
- package/esm/eval/report-json.mjs +33 -0
- package/esm/eval/report-json.mjs.map +1 -0
- package/esm/eval/report-junit.d.mts +22 -0
- package/esm/eval/report-junit.d.mts.map +1 -0
- package/esm/eval/report-junit.mjs +60 -0
- package/esm/eval/report-junit.mjs.map +1 -0
- package/esm/guard/contracts/guard-options.type.d.mts +165 -0
- package/esm/guard/contracts/guard-options.type.d.mts.map +1 -0
- package/esm/guard/contracts/guardrail.contract.d.mts +78 -0
- package/esm/guard/contracts/guardrail.contract.d.mts.map +1 -0
- package/esm/guard/contracts/index.d.mts +4 -0
- package/esm/guard/contracts/openai-client.contract.d.mts +51 -0
- package/esm/guard/contracts/openai-client.contract.d.mts.map +1 -0
- package/esm/guard/contracts/verdict.type.d.mts +76 -0
- package/esm/guard/contracts/verdict.type.d.mts.map +1 -0
- package/esm/guard/detectors/index.d.mts +4 -0
- package/esm/guard/detectors/index.mjs +6 -0
- package/esm/guard/detectors/injection.d.mts +34 -0
- package/esm/guard/detectors/injection.d.mts.map +1 -0
- package/esm/guard/detectors/injection.mjs +254 -0
- package/esm/guard/detectors/injection.mjs.map +1 -0
- package/esm/guard/detectors/moderation.d.mts +32 -0
- package/esm/guard/detectors/moderation.d.mts.map +1 -0
- package/esm/guard/detectors/moderation.mjs +134 -0
- package/esm/guard/detectors/moderation.mjs.map +1 -0
- package/esm/guard/detectors/pii.d.mts +41 -0
- package/esm/guard/detectors/pii.d.mts.map +1 -0
- package/esm/guard/detectors/pii.mjs +199 -0
- package/esm/guard/detectors/pii.mjs.map +1 -0
- package/esm/guard/detectors/topic.d.mts +29 -0
- package/esm/guard/detectors/topic.d.mts.map +1 -0
- package/esm/guard/detectors/topic.mjs +99 -0
- package/esm/guard/detectors/topic.mjs.map +1 -0
- package/esm/guard/errors.d.mts +12 -0
- package/esm/guard/errors.d.mts.map +1 -0
- package/esm/guard/errors.mjs +18 -0
- package/esm/guard/errors.mjs.map +1 -0
- package/esm/guard/guard.d.mts +67 -0
- package/esm/guard/guard.d.mts.map +1 -0
- package/esm/guard/guard.mjs +209 -0
- package/esm/guard/guard.mjs.map +1 -0
- package/esm/guard/guardrail.d.mts +39 -0
- package/esm/guard/guardrail.d.mts.map +1 -0
- package/esm/guard/guardrail.mjs +22 -0
- package/esm/guard/guardrail.mjs.map +1 -0
- package/esm/human/contracts/approval.type.d.mts +154 -0
- package/esm/human/contracts/approval.type.d.mts.map +1 -0
- package/esm/human/contracts/human-approval.type.d.mts +38 -0
- package/esm/human/contracts/human-approval.type.d.mts.map +1 -0
- package/esm/human/contracts/index.d.mts +4 -0
- package/esm/human/contracts/interrupt-store.contract.d.mts +112 -0
- package/esm/human/contracts/interrupt-store.contract.d.mts.map +1 -0
- package/esm/human/contracts/resume.type.d.mts +77 -0
- package/esm/human/contracts/resume.type.d.mts.map +1 -0
- package/esm/human/errors.d.mts +84 -0
- package/esm/human/errors.d.mts.map +1 -0
- package/esm/human/errors.mjs +60 -0
- package/esm/human/errors.mjs.map +1 -0
- package/esm/human/human-approval.d.mts +57 -0
- package/esm/human/human-approval.d.mts.map +1 -0
- package/esm/human/human-approval.mjs +170 -0
- package/esm/human/human-approval.mjs.map +1 -0
- package/esm/human/policy.d.mts +55 -0
- package/esm/human/policy.d.mts.map +1 -0
- package/esm/human/policy.mjs +67 -0
- package/esm/human/policy.mjs.map +1 -0
- package/esm/human/register.mjs +37 -0
- package/esm/human/register.mjs.map +1 -0
- package/esm/human/resume-seed.mjs +53 -0
- package/esm/human/resume-seed.mjs.map +1 -0
- package/esm/human/resume.d.mts +54 -0
- package/esm/human/resume.d.mts.map +1 -0
- package/esm/human/resume.mjs +121 -0
- package/esm/human/resume.mjs.map +1 -0
- package/esm/human/stores/index.mjs +5 -0
- package/esm/human/stores/memory.d.mts +30 -0
- package/esm/human/stores/memory.d.mts.map +1 -0
- package/esm/human/stores/memory.mjs +91 -0
- package/esm/human/stores/memory.mjs.map +1 -0
- package/esm/human/stores/pg.d.mts +59 -0
- package/esm/human/stores/pg.d.mts.map +1 -0
- package/esm/human/stores/pg.mjs +220 -0
- package/esm/human/stores/pg.mjs.map +1 -0
- package/esm/human/stores/redis.d.mts +56 -0
- package/esm/human/stores/redis.d.mts.map +1 -0
- package/esm/human/stores/redis.mjs +201 -0
- package/esm/human/stores/redis.mjs.map +1 -0
- package/esm/index.d.mts +113 -22
- package/esm/index.mjs +82 -11
- package/esm/middleware/builtins/budget.mjs +6 -2
- package/esm/middleware/builtins/budget.mjs.map +1 -1
- package/esm/middleware/utils/extract-user-text.d.mts +8 -1
- package/esm/middleware/utils/extract-user-text.d.mts.map +1 -1
- package/esm/middleware/utils/extract-user-text.mjs +8 -1
- package/esm/middleware/utils/extract-user-text.mjs.map +1 -1
- package/esm/object-stream/index.d.mts +2 -0
- package/esm/object-stream/index.mjs +4 -0
- package/esm/object-stream/parse-partial-json.d.mts +22 -0
- package/esm/object-stream/parse-partial-json.d.mts.map +1 -0
- package/esm/object-stream/parse-partial-json.mjs +78 -0
- package/esm/object-stream/parse-partial-json.mjs.map +1 -0
- package/esm/object-stream/stream-object.d.mts +68 -0
- package/esm/object-stream/stream-object.d.mts.map +1 -0
- package/esm/object-stream/stream-object.mjs +104 -0
- package/esm/object-stream/stream-object.mjs.map +1 -0
- package/esm/observe/index.mjs +4 -0
- package/esm/observe/observer-registry.d.mts +30 -0
- package/esm/observe/observer-registry.d.mts.map +1 -0
- package/esm/observe/observer-registry.mjs +51 -0
- package/esm/observe/observer-registry.mjs.map +1 -0
- package/esm/observe/observer.contract.d.mts +40 -0
- package/esm/observe/observer.contract.d.mts.map +1 -0
- package/esm/observe/resolve-observers.d.mts +40 -0
- package/esm/observe/resolve-observers.d.mts.map +1 -0
- package/esm/observe/resolve-observers.mjs +73 -0
- package/esm/observe/resolve-observers.mjs.map +1 -0
- package/esm/orchestrator/execution.d.mts.map +1 -1
- package/esm/orchestrator/execution.mjs +5 -2
- package/esm/orchestrator/execution.mjs.map +1 -1
- package/esm/orchestrator/index.d.mts +1 -0
- package/esm/orchestrator/index.mjs +1 -0
- package/esm/orchestrator/orchestrator.d.mts.map +1 -1
- package/esm/orchestrator/orchestrator.mjs +39 -6
- package/esm/orchestrator/orchestrator.mjs.map +1 -1
- package/esm/orchestrator/session-lock.d.mts +25 -0
- package/esm/orchestrator/session-lock.d.mts.map +1 -0
- package/esm/orchestrator/session-lock.mjs +83 -0
- package/esm/orchestrator/session-lock.mjs.map +1 -0
- package/esm/planner/dag-scheduler.mjs +97 -0
- package/esm/planner/dag-scheduler.mjs.map +1 -0
- package/esm/planner/plan-prompt.d.mts +1 -1
- package/esm/planner/plan-prompt.d.mts.map +1 -1
- package/esm/planner/plan-prompt.mjs +2 -1
- package/esm/planner/plan-prompt.mjs.map +1 -1
- package/esm/planner/planner-run.d.mts.map +1 -1
- package/esm/planner/planner-run.mjs +300 -29
- package/esm/planner/planner-run.mjs.map +1 -1
- package/esm/planner/planner.mjs +1 -1
- package/esm/planner/planner.mjs.map +1 -1
- package/esm/prompt/errors.d.mts +57 -0
- package/esm/prompt/errors.d.mts.map +1 -0
- package/esm/prompt/errors.mjs +73 -0
- package/esm/prompt/errors.mjs.map +1 -0
- package/esm/prompt/index.d.mts +3 -0
- package/esm/prompt/index.mjs +4 -0
- package/esm/prompt/prompt-langfuse-sync.mjs +104 -0
- package/esm/prompt/prompt-langfuse-sync.mjs.map +1 -0
- package/esm/prompt/prompt-langfuse-sync.type.d.mts +32 -0
- package/esm/prompt/prompt-langfuse-sync.type.d.mts.map +1 -0
- package/esm/prompt/prompt-validate.mjs +170 -0
- package/esm/prompt/prompt-validate.mjs.map +1 -0
- package/esm/prompt/prompt.d.mts +54 -0
- package/esm/prompt/prompt.d.mts.map +1 -0
- package/esm/prompt/prompt.mjs +218 -0
- package/esm/prompt/prompt.mjs.map +1 -0
- package/esm/prompt/prompt.type.d.mts +174 -0
- package/esm/prompt/prompt.type.d.mts.map +1 -0
- package/esm/prompts/index.d.mts +3 -0
- package/esm/prompts/index.mjs +3 -0
- package/esm/prompts/prompts-manager.contract.d.mts +154 -0
- package/esm/prompts/prompts-manager.contract.d.mts.map +1 -0
- package/esm/prompts/prompts-manager.d.mts +38 -0
- package/esm/prompts/prompts-manager.d.mts.map +1 -0
- package/esm/prompts/prompts-manager.mjs +410 -0
- package/esm/prompts/prompts-manager.mjs.map +1 -0
- package/esm/prompts/prompts-manager.type.d.mts +172 -0
- package/esm/prompts/prompts-manager.type.d.mts.map +1 -0
- package/esm/prompts/prompts-validate.mjs +200 -0
- package/esm/prompts/prompts-validate.mjs.map +1 -0
- package/esm/rag/as-tool.mjs +48 -0
- package/esm/rag/as-tool.mjs.map +1 -0
- package/esm/rag/chunk/chunk.d.mts +24 -0
- package/esm/rag/chunk/chunk.d.mts.map +1 -0
- package/esm/rag/chunk/chunk.mjs +44 -0
- package/esm/rag/chunk/chunk.mjs.map +1 -0
- package/esm/rag/chunk/fixed.mjs +32 -0
- package/esm/rag/chunk/fixed.mjs.map +1 -0
- package/esm/rag/chunk/markdown.mjs +75 -0
- package/esm/rag/chunk/markdown.mjs.map +1 -0
- package/esm/rag/chunk/recursive.mjs +132 -0
- package/esm/rag/chunk/recursive.mjs.map +1 -0
- package/esm/rag/chunk/sentence.mjs +73 -0
- package/esm/rag/chunk/sentence.mjs.map +1 -0
- package/esm/rag/contracts/chunk-options.type.d.mts +35 -0
- package/esm/rag/contracts/chunk-options.type.d.mts.map +1 -0
- package/esm/rag/contracts/citation.type.d.mts +35 -0
- package/esm/rag/contracts/citation.type.d.mts.map +1 -0
- package/esm/rag/contracts/index.d.mts +4 -0
- package/esm/rag/contracts/rag-config.type.d.mts +68 -0
- package/esm/rag/contracts/rag-config.type.d.mts.map +1 -0
- package/esm/rag/contracts/rag-document.type.d.mts +21 -0
- package/esm/rag/contracts/rag-document.type.d.mts.map +1 -0
- package/esm/rag/hybrid/bm25.d.mts +23 -0
- package/esm/rag/hybrid/bm25.d.mts.map +1 -0
- package/esm/rag/hybrid/bm25.mjs +51 -0
- package/esm/rag/hybrid/bm25.mjs.map +1 -0
- package/esm/rag/hybrid/hybrid-rank.d.mts +33 -0
- package/esm/rag/hybrid/hybrid-rank.d.mts.map +1 -0
- package/esm/rag/hybrid/hybrid-rank.mjs +29 -0
- package/esm/rag/hybrid/hybrid-rank.mjs.map +1 -0
- package/esm/rag/hybrid/rrf.d.mts +25 -0
- package/esm/rag/hybrid/rrf.d.mts.map +1 -0
- package/esm/rag/hybrid/rrf.mjs +30 -0
- package/esm/rag/hybrid/rrf.mjs.map +1 -0
- package/esm/rag/index.d.mts +15 -0
- package/esm/rag/index.mjs +11 -0
- package/esm/rag/rag.d.mts +38 -0
- package/esm/rag/rag.d.mts.map +1 -0
- package/esm/rag/rag.mjs +126 -0
- package/esm/rag/rag.mjs.map +1 -0
- package/esm/rag/rerank/keyword-reranker.d.mts +32 -0
- package/esm/rag/rerank/keyword-reranker.d.mts.map +1 -0
- package/esm/rag/rerank/keyword-reranker.mjs +58 -0
- package/esm/rag/rerank/keyword-reranker.mjs.map +1 -0
- package/esm/rag/rerank/llm-reranker.d.mts +36 -0
- package/esm/rag/rerank/llm-reranker.d.mts.map +1 -0
- package/esm/rag/rerank/llm-reranker.mjs +85 -0
- package/esm/rag/rerank/llm-reranker.mjs.map +1 -0
- package/esm/rag/rerank/reranker.contract.d.mts +28 -0
- package/esm/rag/rerank/reranker.contract.d.mts.map +1 -0
- package/esm/rag/retrieve.mjs +68 -0
- package/esm/rag/retrieve.mjs.map +1 -0
- package/esm/rag/store/cache-vector-store.d.mts +27 -0
- package/esm/rag/store/cache-vector-store.d.mts.map +1 -0
- package/esm/rag/store/cache-vector-store.mjs +48 -0
- package/esm/rag/store/cache-vector-store.mjs.map +1 -0
- package/esm/rag/store/vector-store.contract.d.mts +38 -0
- package/esm/rag/store/vector-store.contract.d.mts.map +1 -0
- package/esm/rag/transforms/multi-query.d.mts +27 -0
- package/esm/rag/transforms/multi-query.d.mts.map +1 -0
- package/esm/rag/transforms/multi-query.mjs +41 -0
- package/esm/rag/transforms/multi-query.mjs.map +1 -0
- package/esm/security/index.mjs +5 -0
- package/esm/security/outbound-policy.d.mts +46 -0
- package/esm/security/outbound-policy.d.mts.map +1 -0
- package/esm/security/outbound-policy.mjs +187 -0
- package/esm/security/outbound-policy.mjs.map +1 -0
- package/esm/security/outbound-policy.type.d.mts +74 -0
- package/esm/security/outbound-policy.type.d.mts.map +1 -0
- package/esm/security/private-ip.d.mts +15 -0
- package/esm/security/private-ip.d.mts.map +1 -0
- package/esm/security/private-ip.mjs +48 -0
- package/esm/security/private-ip.mjs.map +1 -0
- package/esm/security/redact.d.mts +59 -0
- package/esm/security/redact.d.mts.map +1 -0
- package/esm/security/redact.mjs +122 -0
- package/esm/security/redact.mjs.map +1 -0
- package/esm/serve/serve.d.mts +50 -0
- package/esm/serve/serve.d.mts.map +1 -0
- package/esm/serve/serve.mjs +90 -0
- package/esm/serve/serve.mjs.map +1 -0
- package/esm/serve/sse.d.mts +20 -0
- package/esm/serve/sse.d.mts.map +1 -0
- package/esm/serve/sse.mjs +25 -0
- package/esm/serve/sse.mjs.map +1 -0
- package/esm/serve/stream-to-sse.d.mts +29 -0
- package/esm/serve/stream-to-sse.d.mts.map +1 -0
- package/esm/serve/stream-to-sse.mjs +37 -0
- package/esm/serve/stream-to-sse.mjs.map +1 -0
- package/esm/skills/catalog.d.mts +49 -0
- package/esm/skills/catalog.d.mts.map +1 -0
- package/esm/skills/catalog.mjs +140 -0
- package/esm/skills/catalog.mjs.map +1 -0
- package/esm/skills/contracts/skill-record.type.d.mts +37 -0
- package/esm/skills/contracts/skill-record.type.d.mts.map +1 -0
- package/esm/skills/contracts/skills-config.type.d.mts +108 -0
- package/esm/skills/contracts/skills-config.type.d.mts.map +1 -0
- package/esm/skills/contracts/skills-store.contract.d.mts +28 -0
- package/esm/skills/contracts/skills-store.contract.d.mts.map +1 -0
- package/esm/skills/contracts/skills.contract.d.mts +43 -0
- package/esm/skills/contracts/skills.contract.d.mts.map +1 -0
- package/esm/skills/index.d.mts +16 -0
- package/esm/skills/index.mjs +14 -0
- package/esm/skills/load-skill-tool.d.mts +38 -0
- package/esm/skills/load-skill-tool.d.mts.map +1 -0
- package/esm/skills/load-skill-tool.mjs +65 -0
- package/esm/skills/load-skill-tool.mjs.map +1 -0
- package/esm/skills/review-gate.d.mts +33 -0
- package/esm/skills/review-gate.d.mts.map +1 -0
- package/esm/skills/review-gate.mjs +60 -0
- package/esm/skills/review-gate.mjs.map +1 -0
- package/esm/skills/save-skill-tool.d.mts +39 -0
- package/esm/skills/save-skill-tool.d.mts.map +1 -0
- package/esm/skills/save-skill-tool.mjs +65 -0
- package/esm/skills/save-skill-tool.mjs.map +1 -0
- package/esm/skills/skills.d.mts +33 -0
- package/esm/skills/skills.d.mts.map +1 -0
- package/esm/skills/skills.mjs +109 -0
- package/esm/skills/skills.mjs.map +1 -0
- package/esm/skills/sources/directory-source.d.mts +19 -0
- package/esm/skills/sources/directory-source.d.mts.map +1 -0
- package/esm/skills/sources/directory-source.mjs +108 -0
- package/esm/skills/sources/directory-source.mjs.map +1 -0
- package/esm/skills/sources/index.d.mts +18 -0
- package/esm/skills/sources/index.d.mts.map +1 -0
- package/esm/skills/sources/index.mjs +27 -0
- package/esm/skills/sources/index.mjs.map +1 -0
- package/esm/skills/sources/parse-frontmatter.d.mts +27 -0
- package/esm/skills/sources/parse-frontmatter.d.mts.map +1 -0
- package/esm/skills/sources/parse-frontmatter.mjs +46 -0
- package/esm/skills/sources/parse-frontmatter.mjs.map +1 -0
- package/esm/skills/sources/store-source.d.mts +14 -0
- package/esm/skills/sources/store-source.d.mts.map +1 -0
- package/esm/skills/sources/store-source.mjs +15 -0
- package/esm/skills/sources/store-source.mjs.map +1 -0
- package/esm/skills/sources/url-source.d.mts +29 -0
- package/esm/skills/sources/url-source.d.mts.map +1 -0
- package/esm/skills/sources/url-source.mjs +117 -0
- package/esm/skills/sources/url-source.mjs.map +1 -0
- package/esm/skills/store/mock-skills-store.d.mts +57 -0
- package/esm/skills/store/mock-skills-store.d.mts.map +1 -0
- package/esm/skills/store/mock-skills-store.mjs +100 -0
- package/esm/skills/store/mock-skills-store.mjs.map +1 -0
- package/esm/skills/store/procedural-skill-store.d.mts +30 -0
- package/esm/skills/store/procedural-skill-store.d.mts.map +1 -0
- package/esm/skills/store/procedural-skill-store.mjs +125 -0
- package/esm/skills/store/procedural-skill-store.mjs.map +1 -0
- package/esm/supervisor/as-tool.mjs +2 -2
- package/esm/supervisor/as-tool.mjs.map +1 -1
- package/esm/supervisor/execution.d.mts.map +1 -1
- package/esm/supervisor/execution.mjs +31 -28
- package/esm/supervisor/execution.mjs.map +1 -1
- package/esm/supervisor/supervisor.d.mts.map +1 -1
- package/esm/supervisor/supervisor.mjs +8 -3
- package/esm/supervisor/supervisor.mjs.map +1 -1
- package/esm/system-prompt/index.d.mts +4 -0
- package/esm/system-prompt/system-prompt.d.mts +68 -4
- package/esm/system-prompt/system-prompt.d.mts.map +1 -1
- package/esm/system-prompt/system-prompt.mjs +89 -5
- package/esm/system-prompt/system-prompt.mjs.map +1 -1
- package/esm/team/gates.mjs +48 -0
- package/esm/team/gates.mjs.map +1 -0
- package/esm/team/index.d.mts +1 -0
- package/esm/team/index.mjs +3 -0
- package/esm/team/team.d.mts +42 -0
- package/esm/team/team.d.mts.map +1 -0
- package/esm/team/team.mjs +94 -0
- package/esm/team/team.mjs.map +1 -0
- package/esm/tool/executable-as-tool.d.mts.map +1 -1
- package/esm/tool/executable-as-tool.mjs +2 -2
- package/esm/tool/executable-as-tool.mjs.map +1 -1
- package/esm/tool/tool.d.mts.map +1 -1
- package/esm/tool/tool.mjs +2 -2
- package/esm/tool/tool.mjs.map +1 -1
- package/esm/utils/compute-cost.d.mts +17 -1
- package/esm/utils/compute-cost.d.mts.map +1 -1
- package/esm/utils/compute-cost.mjs +26 -1
- package/esm/utils/compute-cost.mjs.map +1 -1
- package/esm/utils/extract-json-lenient.d.mts +42 -0
- package/esm/utils/extract-json-lenient.d.mts.map +1 -0
- package/esm/utils/extract-json-lenient.mjs +97 -0
- package/esm/utils/extract-json-lenient.mjs.map +1 -0
- package/esm/utils/index.d.mts +4 -2
- package/esm/utils/index.mjs +3 -1
- package/esm/utils/json-schema.d.mts +1 -1
- package/esm/utils/prepare-attachment-part.d.mts +10 -1
- package/esm/utils/prepare-attachment-part.d.mts.map +1 -1
- package/esm/utils/prepare-attachment-part.mjs +103 -11
- package/esm/utils/prepare-attachment-part.mjs.map +1 -1
- package/esm/utils/resolve-attachment.d.mts +4 -3
- package/esm/utils/resolve-attachment.d.mts.map +1 -1
- package/esm/utils/resolve-attachment.mjs +4 -3
- package/esm/utils/resolve-attachment.mjs.map +1 -1
- package/esm/utils/run-context.d.mts +94 -0
- package/esm/utils/run-context.d.mts.map +1 -0
- package/esm/utils/run-context.mjs +98 -0
- package/esm/utils/run-context.mjs.map +1 -0
- package/esm/vcr/cassette-io.mjs +57 -0
- package/esm/vcr/cassette-io.mjs.map +1 -0
- package/esm/vcr/errors.d.mts +42 -0
- package/esm/vcr/errors.d.mts.map +1 -0
- package/esm/vcr/errors.mjs +37 -0
- package/esm/vcr/errors.mjs.map +1 -0
- package/esm/vcr/hash-request.d.mts +28 -0
- package/esm/vcr/hash-request.d.mts.map +1 -0
- package/esm/vcr/hash-request.mjs +118 -0
- package/esm/vcr/hash-request.mjs.map +1 -0
- package/esm/vcr/index.d.mts +4 -0
- package/esm/vcr/index.mjs +5 -0
- package/esm/vcr/vcr.d.mts +32 -0
- package/esm/vcr/vcr.d.mts.map +1 -0
- package/esm/vcr/vcr.mjs +248 -0
- package/esm/vcr/vcr.mjs.map +1 -0
- package/esm/vcr/vcr.type.d.mts +118 -0
- package/esm/vcr/vcr.type.d.mts.map +1 -0
- package/esm/workflow/as-tool.mjs +2 -2
- package/esm/workflow/as-tool.mjs.map +1 -1
- package/esm/workflow/engine.mjs +1 -0
- package/esm/workflow/engine.mjs.map +1 -1
- package/esm/workflow/step-runner.mjs +19 -20
- package/esm/workflow/step-runner.mjs.map +1 -1
- package/esm/workflow/workflow.d.mts.map +1 -1
- package/esm/workflow/workflow.mjs +8 -3
- package/esm/workflow/workflow.mjs.map +1 -1
- package/llms-full.txt +1683 -68
- package/llms.txt +16 -4
- package/package.json +7 -3
- package/skills/README.md +40 -4
- package/skills/ai-dx-helpers/SKILL.md +2 -2
- package/skills/approve-tool-calls/SKILL.md +134 -0
- package/skills/attach-ai-middleware/SKILL.md +1 -1
- package/skills/detect-and-redact-pii/SKILL.md +104 -0
- package/skills/durable-resume/SKILL.md +128 -0
- package/skills/escalate-block-to-human/SKILL.md +85 -0
- package/skills/eval-datasets-and-ci/SKILL.md +117 -0
- package/skills/guard-input-output/SKILL.md +117 -0
- package/skills/manage-prompts/SKILL.md +186 -0
- package/skills/observe-ai-flows/SKILL.md +94 -0
- package/skills/record-replay-llm/SKILL.md +92 -0
- package/skills/run-ai-agent/SKILL.md +26 -1
- package/skills/run-ai-rag/SKILL.md +139 -0
- package/skills/run-ai-team/SKILL.md +107 -0
- package/skills/run-orchestrator/SKILL.md +2 -0
- package/skills/run-planner/SKILL.md +73 -8
- package/skills/run-supervisor/SKILL.md +20 -1
- package/skills/use-runtime-skills/SKILL.md +106 -0
- package/skills/write-system-prompt/SKILL.md +30 -1
- package/cjs/index.cjs.map +0 -1
- package/esm/contracts/result/index.d.mts +0 -15
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { PlannerPlanInvalidError } from "../errors/planner-plan-invalid-error.mjs";
|
|
2
|
+
|
|
3
|
+
//#region ../@warlock.js/ai/src/planner/dag-scheduler.ts
|
|
4
|
+
/**
|
|
5
|
+
* Build the execution DAG from a plan's steps.
|
|
6
|
+
*
|
|
7
|
+
* Each step's `id` (falling back to its array index) and its `dependsOn`
|
|
8
|
+
* become an adjacency list. A `dependsOn` that names a step not in the
|
|
9
|
+
* plan, or any dependency cycle, raises a typed
|
|
10
|
+
* {@link PlannerPlanInvalidError} BEFORE any step runs — the same error
|
|
11
|
+
* class `generatePlan` uses for an unusable plan, with forensic context.
|
|
12
|
+
*
|
|
13
|
+
* @throws PlannerPlanInvalidError on a duplicate id, an unknown
|
|
14
|
+
* `dependsOn` target, or a cycle.
|
|
15
|
+
*/
|
|
16
|
+
function buildDag(steps, plannerName = "planner") {
|
|
17
|
+
const nodes = [];
|
|
18
|
+
const byId = /* @__PURE__ */ new Map();
|
|
19
|
+
for (let index = 0; index < steps.length; index++) {
|
|
20
|
+
const step = steps[index];
|
|
21
|
+
const id = step.id ?? String(index);
|
|
22
|
+
if (byId.has(id)) throw new PlannerPlanInvalidError(`ai.planner("${plannerName}"): duplicate step id "${id}" in DAG plan`, { context: { id } });
|
|
23
|
+
const node = {
|
|
24
|
+
id,
|
|
25
|
+
index,
|
|
26
|
+
step,
|
|
27
|
+
dependencies: []
|
|
28
|
+
};
|
|
29
|
+
nodes.push(node);
|
|
30
|
+
byId.set(id, node);
|
|
31
|
+
}
|
|
32
|
+
const dependents = /* @__PURE__ */ new Map();
|
|
33
|
+
for (const node of nodes) {
|
|
34
|
+
const seen = /* @__PURE__ */ new Set();
|
|
35
|
+
for (const dependency of node.step.dependsOn ?? []) {
|
|
36
|
+
if (dependency === node.id) continue;
|
|
37
|
+
if (!byId.has(dependency)) throw new PlannerPlanInvalidError(`ai.planner("${plannerName}"): step "${node.id}" depends on unknown step "${dependency}"`, { context: {
|
|
38
|
+
id: node.id,
|
|
39
|
+
dependency
|
|
40
|
+
} });
|
|
41
|
+
if (seen.has(dependency)) continue;
|
|
42
|
+
seen.add(dependency);
|
|
43
|
+
node.dependencies.push(dependency);
|
|
44
|
+
const reverse = dependents.get(dependency) ?? [];
|
|
45
|
+
reverse.push(node.id);
|
|
46
|
+
dependents.set(dependency, reverse);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
assertAcyclic(nodes, byId, plannerName);
|
|
50
|
+
return {
|
|
51
|
+
nodes,
|
|
52
|
+
byId,
|
|
53
|
+
dependents
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Compute the next ready set: nodes not yet done whose every dependency
|
|
58
|
+
* is in `completed`. Preserves original plan order so a level dispatches
|
|
59
|
+
* deterministically. A node whose dependency is `unreachable` (a failed
|
|
60
|
+
* or skipped ancestor) is NOT ready — it never becomes ready and is
|
|
61
|
+
* recorded skipped by the caller.
|
|
62
|
+
*/
|
|
63
|
+
function readyNodes(dag, completed, done) {
|
|
64
|
+
return dag.nodes.filter((node) => !done.has(node.id) && node.dependencies.every((dependency) => completed.has(dependency)));
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* The topological sink(s) — nodes nothing depends on. Used to define the
|
|
68
|
+
* "final output" under parallelism: with an `output` schema set, a
|
|
69
|
+
* single sink is the unambiguous final step; multiple sinks are a
|
|
70
|
+
* convergence error the caller surfaces.
|
|
71
|
+
*/
|
|
72
|
+
function sinkNodes(dag) {
|
|
73
|
+
return dag.nodes.filter((node) => (dag.dependents.get(node.id) ?? []).length === 0);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Depth-first cycle detection over the dependency edges. A back-edge to
|
|
77
|
+
* a node on the current recursion stack means a cycle — raised as a
|
|
78
|
+
* typed {@link PlannerPlanInvalidError} naming the offending node.
|
|
79
|
+
*/
|
|
80
|
+
function assertAcyclic(nodes, byId, plannerName) {
|
|
81
|
+
const VISITING = 1;
|
|
82
|
+
const DONE = 2;
|
|
83
|
+
const state = /* @__PURE__ */ new Map();
|
|
84
|
+
const visit = (node) => {
|
|
85
|
+
const current = state.get(node.id);
|
|
86
|
+
if (current === DONE) return;
|
|
87
|
+
if (current === VISITING) throw new PlannerPlanInvalidError(`ai.planner("${plannerName}"): dependency cycle detected at step "${node.id}"`, { context: { id: node.id } });
|
|
88
|
+
state.set(node.id, VISITING);
|
|
89
|
+
for (const dependency of node.dependencies) visit(byId.get(dependency));
|
|
90
|
+
state.set(node.id, DONE);
|
|
91
|
+
};
|
|
92
|
+
for (const node of nodes) visit(node);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
//#endregion
|
|
96
|
+
export { buildDag, readyNodes, sinkNodes };
|
|
97
|
+
//# sourceMappingURL=dag-scheduler.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dag-scheduler.mjs","names":[],"sources":["../../../../../../../@warlock.js/ai/src/planner/dag-scheduler.ts"],"sourcesContent":["import type { PlannerStep } from \"../contracts/planner/planner-plan.type\";\nimport { PlannerPlanInvalidError } from \"../errors/planner-plan-invalid-error\";\n\n/**\n * One node in the planner's execution DAG — a plan step plus the\n * resolved structural metadata the scheduler needs to order it.\n *\n * `id` is the step's own `id` when present, falling back to the step's\n * array index stringified (exactly as {@link PlannerStep.id} documents).\n * `dependencies` is the resolved set of node ids this step waits on,\n * de-duplicated and self-references dropped.\n */\nexport type DagNode = {\n /** Stable id — the step's own `id`, or its array index as a string. */\n id: string;\n /** 0-based position of the step in the original plan array. */\n index: number;\n /** The plan step this node schedules. */\n step: PlannerStep;\n /** Resolved ids this step depends on (subset of the DAG's node ids). */\n dependencies: string[];\n};\n\n/**\n * The built execution DAG — the ordered node list plus the lookups the\n * scheduler walks. Ordering follows the original plan array so a\n * dependency-free plan executes in author order, level by level.\n */\nexport type PlannerDag = {\n /** Nodes in original plan order. */\n nodes: DagNode[];\n /** id → node, for dependency resolution and sink detection. */\n byId: Map<string, DagNode>;\n /** id → ids of the nodes that depend on it (reverse edges). */\n dependents: Map<string, string[]>;\n};\n\n/**\n * Build the execution DAG from a plan's steps.\n *\n * Each step's `id` (falling back to its array index) and its `dependsOn`\n * become an adjacency list. A `dependsOn` that names a step not in the\n * plan, or any dependency cycle, raises a typed\n * {@link PlannerPlanInvalidError} BEFORE any step runs — the same error\n * class `generatePlan` uses for an unusable plan, with forensic context.\n *\n * @throws PlannerPlanInvalidError on a duplicate id, an unknown\n * `dependsOn` target, or a cycle.\n */\nexport function buildDag(steps: PlannerStep[], plannerName = \"planner\"): PlannerDag {\n const nodes: DagNode[] = [];\n const byId = new Map<string, DagNode>();\n\n // Pass 1 — assign every step a stable id (own id or array index) and\n // index the nodes. Duplicate explicit ids are a malformed plan.\n for (let index = 0; index < steps.length; index++) {\n const step = steps[index] as PlannerStep;\n const id = step.id ?? String(index);\n\n if (byId.has(id)) {\n throw new PlannerPlanInvalidError(\n `ai.planner(\"${plannerName}\"): duplicate step id \"${id}\" in DAG plan`,\n { context: { id } },\n );\n }\n\n const node: DagNode = { id, index, step, dependencies: [] };\n nodes.push(node);\n byId.set(id, node);\n }\n\n // Pass 2 — resolve dependencies against the id set; reject unknowns,\n // dedupe, and drop self-references (a no-op edge, never a cycle).\n const dependents = new Map<string, string[]>();\n\n for (const node of nodes) {\n const seen = new Set<string>();\n\n for (const dependency of node.step.dependsOn ?? []) {\n if (dependency === node.id) {\n continue;\n }\n\n if (!byId.has(dependency)) {\n throw new PlannerPlanInvalidError(\n `ai.planner(\"${plannerName}\"): step \"${node.id}\" depends on unknown step \"${dependency}\"`,\n { context: { id: node.id, dependency } },\n );\n }\n\n if (seen.has(dependency)) {\n continue;\n }\n\n seen.add(dependency);\n node.dependencies.push(dependency);\n\n const reverse = dependents.get(dependency) ?? [];\n reverse.push(node.id);\n dependents.set(dependency, reverse);\n }\n }\n\n assertAcyclic(nodes, byId, plannerName);\n\n return { nodes, byId, dependents };\n}\n\n/**\n * Compute the next ready set: nodes not yet done whose every dependency\n * is in `completed`. Preserves original plan order so a level dispatches\n * deterministically. A node whose dependency is `unreachable` (a failed\n * or skipped ancestor) is NOT ready — it never becomes ready and is\n * recorded skipped by the caller.\n */\nexport function readyNodes(\n dag: PlannerDag,\n completed: ReadonlySet<string>,\n done: ReadonlySet<string>,\n): DagNode[] {\n return dag.nodes.filter(\n (node) =>\n !done.has(node.id) &&\n node.dependencies.every((dependency) => completed.has(dependency)),\n );\n}\n\n/**\n * The topological sink(s) — nodes nothing depends on. Used to define the\n * \"final output\" under parallelism: with an `output` schema set, a\n * single sink is the unambiguous final step; multiple sinks are a\n * convergence error the caller surfaces.\n */\nexport function sinkNodes(dag: PlannerDag): DagNode[] {\n return dag.nodes.filter((node) => (dag.dependents.get(node.id) ?? []).length === 0);\n}\n\n/**\n * Depth-first cycle detection over the dependency edges. A back-edge to\n * a node on the current recursion stack means a cycle — raised as a\n * typed {@link PlannerPlanInvalidError} naming the offending node.\n */\nfunction assertAcyclic(\n nodes: DagNode[],\n byId: Map<string, DagNode>,\n plannerName: string,\n): void {\n const VISITING = 1;\n const DONE = 2;\n const state = new Map<string, number>();\n\n const visit = (node: DagNode): void => {\n const current = state.get(node.id);\n\n if (current === DONE) {\n return;\n }\n\n if (current === VISITING) {\n throw new PlannerPlanInvalidError(\n `ai.planner(\"${plannerName}\"): dependency cycle detected at step \"${node.id}\"`,\n { context: { id: node.id } },\n );\n }\n\n state.set(node.id, VISITING);\n\n for (const dependency of node.dependencies) {\n visit(byId.get(dependency) as DagNode);\n }\n\n state.set(node.id, DONE);\n };\n\n for (const node of nodes) {\n visit(node);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAiDA,SAAgB,SAAS,OAAsB,cAAc,WAAuB;CAClF,MAAM,QAAmB,CAAC;CAC1B,MAAM,uBAAO,IAAI,IAAqB;CAItC,KAAK,IAAI,QAAQ,GAAG,QAAQ,MAAM,QAAQ,SAAS;EACjD,MAAM,OAAO,MAAM;EACnB,MAAM,KAAK,KAAK,MAAM,OAAO,KAAK;EAElC,IAAI,KAAK,IAAI,EAAE,GACb,MAAM,IAAI,wBACR,eAAe,YAAY,yBAAyB,GAAG,gBACvD,EAAE,SAAS,EAAE,GAAG,EAAE,CACpB;EAGF,MAAM,OAAgB;GAAE;GAAI;GAAO;GAAM,cAAc,CAAC;EAAE;EAC1D,MAAM,KAAK,IAAI;EACf,KAAK,IAAI,IAAI,IAAI;CACnB;CAIA,MAAM,6BAAa,IAAI,IAAsB;CAE7C,KAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,uBAAO,IAAI,IAAY;EAE7B,KAAK,MAAM,cAAc,KAAK,KAAK,aAAa,CAAC,GAAG;GAClD,IAAI,eAAe,KAAK,IACtB;GAGF,IAAI,CAAC,KAAK,IAAI,UAAU,GACtB,MAAM,IAAI,wBACR,eAAe,YAAY,YAAY,KAAK,GAAG,6BAA6B,WAAW,IACvF,EAAE,SAAS;IAAE,IAAI,KAAK;IAAI;GAAW,EAAE,CACzC;GAGF,IAAI,KAAK,IAAI,UAAU,GACrB;GAGF,KAAK,IAAI,UAAU;GACnB,KAAK,aAAa,KAAK,UAAU;GAEjC,MAAM,UAAU,WAAW,IAAI,UAAU,KAAK,CAAC;GAC/C,QAAQ,KAAK,KAAK,EAAE;GACpB,WAAW,IAAI,YAAY,OAAO;EACpC;CACF;CAEA,cAAc,OAAO,MAAM,WAAW;CAEtC,OAAO;EAAE;EAAO;EAAM;CAAW;AACnC;;;;;;;;AASA,SAAgB,WACd,KACA,WACA,MACW;CACX,OAAO,IAAI,MAAM,QACd,SACC,CAAC,KAAK,IAAI,KAAK,EAAE,KACjB,KAAK,aAAa,OAAO,eAAe,UAAU,IAAI,UAAU,CAAC,CACrE;AACF;;;;;;;AAQA,SAAgB,UAAU,KAA4B;CACpD,OAAO,IAAI,MAAM,QAAQ,UAAU,IAAI,WAAW,IAAI,KAAK,EAAE,KAAK,CAAC,EAAC,CAAE,WAAW,CAAC;AACpF;;;;;;AAOA,SAAS,cACP,OACA,MACA,aACM;CACN,MAAM,WAAW;CACjB,MAAM,OAAO;CACb,MAAM,wBAAQ,IAAI,IAAoB;CAEtC,MAAM,SAAS,SAAwB;EACrC,MAAM,UAAU,MAAM,IAAI,KAAK,EAAE;EAEjC,IAAI,YAAY,MACd;EAGF,IAAI,YAAY,UACd,MAAM,IAAI,wBACR,eAAe,YAAY,yCAAyC,KAAK,GAAG,IAC5E,EAAE,SAAS,EAAE,IAAI,KAAK,GAAG,EAAE,CAC7B;EAGF,MAAM,IAAI,KAAK,IAAI,QAAQ;EAE3B,KAAK,MAAM,cAAc,KAAK,cAC5B,MAAM,KAAK,IAAI,UAAU,CAAY;EAGvC,MAAM,IAAI,KAAK,IAAI,IAAI;CACzB;CAEA,KAAK,MAAM,QAAQ,OACjB,MAAM,IAAI;AAEd"}
|
|
@@ -11,7 +11,7 @@ import { PlannerCapability } from "../contracts/planner/planner-capability.type.
|
|
|
11
11
|
* planner's lifetime) — the produced string is baked onto the internal
|
|
12
12
|
* planning agent.
|
|
13
13
|
*/
|
|
14
|
-
declare function buildPlanSystemPrompt(capabilities: PlannerCapability[], maxSteps: number, prefix: SystemPromptContract | string | undefined): string;
|
|
14
|
+
declare function buildPlanSystemPrompt(capabilities: PlannerCapability[], maxSteps: number, prefix: SystemPromptContract | string | undefined, dag?: boolean): string;
|
|
15
15
|
//#endregion
|
|
16
16
|
export { buildPlanSystemPrompt };
|
|
17
17
|
//# sourceMappingURL=plan-prompt.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plan-prompt.d.mts","names":[],"sources":["../../../../../../../@warlock.js/ai/src/planner/plan-prompt.ts"],"mappings":";;;;;;AAYA;;;;;;;iBAAgB,qBAAA,CACd,YAAA,EAAc,iBAAA,IACd,QAAA,UACA,MAAA,EAAQ,oBAAoB"}
|
|
1
|
+
{"version":3,"file":"plan-prompt.d.mts","names":[],"sources":["../../../../../../../@warlock.js/ai/src/planner/plan-prompt.ts"],"mappings":";;;;;;AAYA;;;;;;;iBAAgB,qBAAA,CACd,YAAA,EAAc,iBAAA,IACd,QAAA,UACA,MAAA,EAAQ,oBAAoB,uBAC5B,GAAA"}
|
|
@@ -8,12 +8,13 @@
|
|
|
8
8
|
* planner's lifetime) — the produced string is baked onto the internal
|
|
9
9
|
* planning agent.
|
|
10
10
|
*/
|
|
11
|
-
function buildPlanSystemPrompt(capabilities, maxSteps, prefix) {
|
|
11
|
+
function buildPlanSystemPrompt(capabilities, maxSteps, prefix, dag = false) {
|
|
12
12
|
const capabilityLines = capabilities.map((capability) => `- ${capability.name}: ${capability.description}`);
|
|
13
13
|
const sections = [];
|
|
14
14
|
const resolvedPrefix = resolvePrefix(prefix);
|
|
15
15
|
if (resolvedPrefix && resolvedPrefix.trim().length > 0) sections.push(resolvedPrefix.trim(), "");
|
|
16
16
|
sections.push("You are a planner. Break the user's goal into an ordered sequence of steps,", "each one dispatching exactly one of the available capabilities below.", "", "Available capabilities:", ...capabilityLines, "", "Rules:", `- Produce at most ${maxSteps} steps.`, "- Each step's `capability` must be exactly one name from the list above.", "- Each step's `input` is the concrete instruction passed to that capability.", "- Order the steps so each builds on the outputs of the ones before it.", "- Never invent a capability name that is not listed.", "- Keep the plan minimal — only the steps actually needed to satisfy the goal.");
|
|
17
|
+
if (dag) sections.push("- Give each step a stable `id` and list the ids it builds on in `dependsOn`.", "- Steps with no `dependsOn` between them run in PARALLEL — only add a", " dependency when a step genuinely needs an earlier step's output.", "- The plan must converge: avoid dependency cycles.");
|
|
17
18
|
return sections.join("\n");
|
|
18
19
|
}
|
|
19
20
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plan-prompt.mjs","names":[],"sources":["../../../../../../../@warlock.js/ai/src/planner/plan-prompt.ts"],"sourcesContent":["import type { PlannerCapability } from \"../contracts/planner/planner-capability.type\";\nimport type { SystemPromptContract } from \"../contracts/system-prompt.contract\";\n\n/**\n * Assemble the plan-generation system prompt: optional caller framing on\n * top, then the mechanical block listing every capability + its\n * description and the rules for emitting an ordered plan.\n *\n * Runs once at factory time (the capability set is fixed for the\n * planner's lifetime) — the produced string is baked onto the internal\n * planning agent.\n */\nexport function buildPlanSystemPrompt(\n capabilities: PlannerCapability[],\n maxSteps: number,\n prefix: SystemPromptContract | string | undefined,\n): string {\n const capabilityLines = capabilities.map(\n (capability) => `- ${capability.name}: ${capability.description}`,\n );\n\n const sections: string[] = [];\n const resolvedPrefix = resolvePrefix(prefix);\n\n if (resolvedPrefix && resolvedPrefix.trim().length > 0) {\n sections.push(resolvedPrefix.trim(), \"\");\n }\n\n sections.push(\n \"You are a planner. Break the user's goal into an ordered sequence of steps,\",\n \"each one dispatching exactly one of the available capabilities below.\",\n \"\",\n \"Available capabilities:\",\n ...capabilityLines,\n \"\",\n \"Rules:\",\n `- Produce at most ${maxSteps} steps.`,\n \"- Each step's `capability` must be exactly one name from the list above.\",\n \"- Each step's `input` is the concrete instruction passed to that capability.\",\n \"- Order the steps so each builds on the outputs of the ones before it.\",\n \"- Never invent a capability name that is not listed.\",\n \"- Keep the plan minimal — only the steps actually needed to satisfy the goal.\",\n );\n\n return sections.join(\"\\n\");\n}\n\n/**\n * Resolve a caller-supplied `systemPrompt` (string or contract) to plain\n * text. Returns `undefined` when none was supplied.\n */\nfunction resolvePrefix(prompt: SystemPromptContract | string | undefined): string | undefined {\n if (!prompt) {\n return undefined;\n }\n\n return typeof prompt === \"string\" ? prompt : prompt.resolve();\n}\n"],"mappings":";;;;;;;;;;AAYA,SAAgB,sBACd,cACA,UACA,
|
|
1
|
+
{"version":3,"file":"plan-prompt.mjs","names":[],"sources":["../../../../../../../@warlock.js/ai/src/planner/plan-prompt.ts"],"sourcesContent":["import type { PlannerCapability } from \"../contracts/planner/planner-capability.type\";\nimport type { SystemPromptContract } from \"../contracts/system-prompt.contract\";\n\n/**\n * Assemble the plan-generation system prompt: optional caller framing on\n * top, then the mechanical block listing every capability + its\n * description and the rules for emitting an ordered plan.\n *\n * Runs once at factory time (the capability set is fixed for the\n * planner's lifetime) — the produced string is baked onto the internal\n * planning agent.\n */\nexport function buildPlanSystemPrompt(\n capabilities: PlannerCapability[],\n maxSteps: number,\n prefix: SystemPromptContract | string | undefined,\n dag = false,\n): string {\n const capabilityLines = capabilities.map(\n (capability) => `- ${capability.name}: ${capability.description}`,\n );\n\n const sections: string[] = [];\n const resolvedPrefix = resolvePrefix(prefix);\n\n if (resolvedPrefix && resolvedPrefix.trim().length > 0) {\n sections.push(resolvedPrefix.trim(), \"\");\n }\n\n sections.push(\n \"You are a planner. Break the user's goal into an ordered sequence of steps,\",\n \"each one dispatching exactly one of the available capabilities below.\",\n \"\",\n \"Available capabilities:\",\n ...capabilityLines,\n \"\",\n \"Rules:\",\n `- Produce at most ${maxSteps} steps.`,\n \"- Each step's `capability` must be exactly one name from the list above.\",\n \"- Each step's `input` is the concrete instruction passed to that capability.\",\n \"- Order the steps so each builds on the outputs of the ones before it.\",\n \"- Never invent a capability name that is not listed.\",\n \"- Keep the plan minimal — only the steps actually needed to satisfy the goal.\",\n );\n\n if (dag) {\n // DAG mode — the runtime schedules independent steps in parallel off\n // `dependsOn`, so the model should declare dependencies explicitly\n // rather than relying purely on array order.\n sections.push(\n \"- Give each step a stable `id` and list the ids it builds on in `dependsOn`.\",\n \"- Steps with no `dependsOn` between them run in PARALLEL — only add a\",\n \" dependency when a step genuinely needs an earlier step's output.\",\n \"- The plan must converge: avoid dependency cycles.\",\n );\n }\n\n return sections.join(\"\\n\");\n}\n\n/**\n * Resolve a caller-supplied `systemPrompt` (string or contract) to plain\n * text. Returns `undefined` when none was supplied.\n */\nfunction resolvePrefix(prompt: SystemPromptContract | string | undefined): string | undefined {\n if (!prompt) {\n return undefined;\n }\n\n return typeof prompt === \"string\" ? prompt : prompt.resolve();\n}\n"],"mappings":";;;;;;;;;;AAYA,SAAgB,sBACd,cACA,UACA,QACA,MAAM,OACE;CACR,MAAM,kBAAkB,aAAa,KAClC,eAAe,KAAK,WAAW,KAAK,IAAI,WAAW,aACtD;CAEA,MAAM,WAAqB,CAAC;CAC5B,MAAM,iBAAiB,cAAc,MAAM;CAE3C,IAAI,kBAAkB,eAAe,KAAK,CAAC,CAAC,SAAS,GACnD,SAAS,KAAK,eAAe,KAAK,GAAG,EAAE;CAGzC,SAAS,KACP,+EACA,yEACA,IACA,2BACA,GAAG,iBACH,IACA,UACA,qBAAqB,SAAS,UAC9B,4EACA,gFACA,0EACA,wDACA,+EACF;CAEA,IAAI,KAIF,SAAS,KACP,gFACA,yEACA,sEACA,oDACF;CAGF,OAAO,SAAS,KAAK,IAAI;AAC3B;;;;;AAMA,SAAS,cAAc,QAAuE;CAC5F,IAAI,CAAC,QACH;CAGF,OAAO,OAAO,WAAW,WAAW,SAAS,OAAO,QAAQ;AAC9D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"planner-run.d.mts","names":[],"sources":["../../../../../../../@warlock.js/ai/src/planner/planner-run.ts"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"planner-run.d.mts","names":[],"sources":["../../../../../../../@warlock.js/ai/src/planner/planner-run.ts"],"mappings":";;;;;;;AAqCA;;;;KAAY,cAAA;EACV,MAAA,EAAQ,aAAA,CAAc,OAAA;EACtB,YAAA,EAAc,GAAA,SAAY,iBAAA;EAC1B,QAAA;EACA,SAAA;EACA,aAAA,EAAe,aAAA;EACf,IAAA;EACA,OAAA,GAAU,qBAAA,CAAsB,OAAA;AAAA"}
|
|
@@ -5,8 +5,11 @@ 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";
|
|
11
14
|
|
|
12
15
|
//#region ../@warlock.js/ai/src/planner/planner-run.ts
|
|
@@ -40,6 +43,8 @@ var PlannerRun = class {
|
|
|
40
43
|
};
|
|
41
44
|
this.children = [];
|
|
42
45
|
this.executedSteps = [];
|
|
46
|
+
this.awaitingApproval = false;
|
|
47
|
+
this.replanCount = 0;
|
|
43
48
|
this.runId = args.options?.runId ?? generateRunId("planner");
|
|
44
49
|
}
|
|
45
50
|
/**
|
|
@@ -49,14 +54,31 @@ var PlannerRun = class {
|
|
|
49
54
|
* `report.status`.
|
|
50
55
|
*/
|
|
51
56
|
async run() {
|
|
57
|
+
const result = await this.runPlan();
|
|
58
|
+
await notifyObservers(this.args.config.observe, result.report);
|
|
59
|
+
captureChildReport(result.report);
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Drive the planner lifecycle and return the built result WITHOUT
|
|
64
|
+
* routing it — `run()` owns observer routing + auto-nesting so the
|
|
65
|
+
* unified tree is emitted exactly once.
|
|
66
|
+
*/
|
|
67
|
+
async runPlan() {
|
|
52
68
|
try {
|
|
53
69
|
if (this.isAborted()) {
|
|
54
70
|
this.markCancelled();
|
|
55
71
|
return this.buildResult();
|
|
56
72
|
}
|
|
57
|
-
const plan = await this.generatePlan();
|
|
73
|
+
const plan = this.args.options?.approvedPlan ?? await this.generatePlan();
|
|
58
74
|
if (this.error || !plan) return this.buildResult();
|
|
75
|
+
this.assertPlanValid(plan);
|
|
76
|
+
if (this.error) return this.buildResult();
|
|
59
77
|
this.plan = plan;
|
|
78
|
+
if (this.args.options?.mode === "plan-only" && !this.args.options?.approvedPlan) {
|
|
79
|
+
this.awaitingApproval = true;
|
|
80
|
+
return this.buildResult();
|
|
81
|
+
}
|
|
60
82
|
await this.executePlan(plan);
|
|
61
83
|
await this.finalizeOutput();
|
|
62
84
|
} catch (caught) {
|
|
@@ -70,15 +92,19 @@ var PlannerRun = class {
|
|
|
70
92
|
* agent's per-call `output`, so the model is steered to reference only
|
|
71
93
|
* real capabilities. The planning trip's usage + report roll into the
|
|
72
94
|
* planner's totals regardless of outcome.
|
|
95
|
+
*
|
|
96
|
+
* `feedback` is set only on a RE-plan: the regenerated request is
|
|
97
|
+
* seeded with the executed-step digest plus the caller's feedback so
|
|
98
|
+
* the planner revises the remaining work rather than starting cold.
|
|
73
99
|
*/
|
|
74
|
-
async generatePlan() {
|
|
100
|
+
async generatePlan(feedback) {
|
|
75
101
|
const schema = planSchema([...this.args.capabilities.keys()], this.args.maxSteps);
|
|
76
|
-
const result = await this.args.planningAgent.execute(this.buildPlanPrompt(), {
|
|
102
|
+
const result = await withoutRunFrame(() => this.args.planningAgent.execute(this.buildPlanPrompt(feedback), {
|
|
77
103
|
output: schema,
|
|
78
104
|
placeholders: this.args.options?.placeholders,
|
|
79
105
|
signal: this.args.options?.signal,
|
|
80
106
|
sessionId: this.args.options?.sessionId
|
|
81
|
-
});
|
|
107
|
+
}));
|
|
82
108
|
this.absorb(result.usage, result.report);
|
|
83
109
|
if (result.error) {
|
|
84
110
|
this.error = result.error instanceof SchemaValidationError ? new PlannerPlanInvalidError(`ai.planner("${this.args.config.name}"): the planner produced no usable plan`, {
|
|
@@ -92,43 +118,174 @@ var PlannerRun = class {
|
|
|
92
118
|
this.error = new PlannerPlanInvalidError(`ai.planner("${this.args.config.name}"): the planner produced no usable plan`, { context: { runId: this.runId } });
|
|
93
119
|
return;
|
|
94
120
|
}
|
|
95
|
-
|
|
96
|
-
if (
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
121
|
+
this.assertPlanValid(plan);
|
|
122
|
+
if (this.error) return;
|
|
123
|
+
return plan;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Shared plan-validity guard — used both for a freshly generated plan
|
|
127
|
+
* and for a caller-supplied `approvedPlan`. Sets `this.error` to a
|
|
128
|
+
* typed {@link PlannerPlanInvalidError} when the plan is empty or names
|
|
129
|
+
* an unknown capability; a stale `approvedPlan` thus fails the same way
|
|
130
|
+
* a hallucinated capability does, never silently mis-dispatching.
|
|
131
|
+
*/
|
|
132
|
+
assertPlanValid(plan) {
|
|
133
|
+
if (!Array.isArray(plan.steps) || plan.steps.length === 0) {
|
|
134
|
+
this.error = new PlannerPlanInvalidError(`ai.planner("${this.args.config.name}"): the planner produced no usable plan`, { context: { runId: this.runId } });
|
|
101
135
|
return;
|
|
102
136
|
}
|
|
103
|
-
|
|
137
|
+
const unknownStep = plan.steps.find((step) => !this.args.capabilities.has(step.capability));
|
|
138
|
+
if (unknownStep) this.error = new PlannerPlanInvalidError(`ai.planner("${this.args.config.name}"): plan references unknown capability "${unknownStep.capability}"`, { context: {
|
|
139
|
+
runId: this.runId,
|
|
140
|
+
capability: unknownStep.capability
|
|
141
|
+
} });
|
|
104
142
|
}
|
|
105
143
|
/**
|
|
106
|
-
* Phase 2 — execute the plan
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
* recorded as `skipped` without running.
|
|
144
|
+
* Phase 2 — execute the plan. Branches on `config.dag`: the default is
|
|
145
|
+
* the strict array-order sequential loop (byte-for-byte today's
|
|
146
|
+
* behavior when neither `onStep` nor `replan` is configured); `dag:
|
|
147
|
+
* true` schedules independent `dependsOn` branches in parallel.
|
|
111
148
|
*/
|
|
112
149
|
async executePlan(plan) {
|
|
150
|
+
if (this.args.config.dag) return this.executeDag(plan);
|
|
151
|
+
return this.executeSequential(plan);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Sequential executor — the original strict array-order loop, threading
|
|
155
|
+
* each completed step's output into the next step's input context.
|
|
156
|
+
* Stops at the first step failure or when the abort signal fires
|
|
157
|
+
* between steps; steps beyond `maxSteps` are recorded `skipped`.
|
|
158
|
+
*
|
|
159
|
+
* **Additive hooks (inert by default).** After each step settles it
|
|
160
|
+
* fires the `onStep` directive hook; an `abort` directive stops the run
|
|
161
|
+
* like a failure, and a `replan` directive (or, when `config.replan` is
|
|
162
|
+
* set, an unhandled failure) regenerates the REMAINING plan instead of
|
|
163
|
+
* aborting. With no `onStep` and no `replan`, the behavior is identical
|
|
164
|
+
* to before.
|
|
165
|
+
*/
|
|
166
|
+
async executeSequential(plan) {
|
|
113
167
|
const previousOutputs = [];
|
|
114
|
-
|
|
115
|
-
|
|
168
|
+
let steps = plan.steps;
|
|
169
|
+
let index = 0;
|
|
170
|
+
while (index < steps.length) {
|
|
171
|
+
const step = steps[index];
|
|
116
172
|
if (index >= this.args.maxSteps) {
|
|
117
173
|
this.recordSkipped(index, step);
|
|
174
|
+
index++;
|
|
118
175
|
continue;
|
|
119
176
|
}
|
|
120
177
|
if (this.isAborted()) {
|
|
121
178
|
this.markCancelled();
|
|
122
179
|
this.recordSkipped(index, step);
|
|
180
|
+
index++;
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
const completed = await this.executeStep(index, step, previousOutputs);
|
|
184
|
+
const snapshot = this.snapshotFor(index);
|
|
185
|
+
const directive = snapshot ? await this.resolveDirective(snapshot, plan, completed) : void 0;
|
|
186
|
+
if (directive?.type === "replan") {
|
|
187
|
+
const remaining = await this.regeneratePlan(directive.feedback);
|
|
188
|
+
if (this.error || !remaining) {
|
|
189
|
+
this.skipRest(steps, index + 1);
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
steps = remaining.steps;
|
|
193
|
+
index = 0;
|
|
194
|
+
previousOutputs.length = 0;
|
|
195
|
+
previousOutputs.push(...this.executedDigest());
|
|
123
196
|
continue;
|
|
124
197
|
}
|
|
125
|
-
if (
|
|
126
|
-
|
|
198
|
+
if (directive?.type === "abort") {
|
|
199
|
+
this.skipRest(steps, index + 1);
|
|
127
200
|
return;
|
|
128
201
|
}
|
|
202
|
+
index++;
|
|
129
203
|
}
|
|
130
204
|
}
|
|
131
205
|
/**
|
|
206
|
+
* DAG executor — schedule independent `dependsOn` branches in parallel.
|
|
207
|
+
*
|
|
208
|
+
* Builds the DAG (cycle / unknown-id → `PlannerPlanInvalidError`),
|
|
209
|
+
* then repeatedly computes the ready set (steps whose deps all
|
|
210
|
+
* completed), dispatches up to `maxConcurrency` of them with
|
|
211
|
+
* `Promise.all`, and feeds each step ONLY its dependencies' outputs. A
|
|
212
|
+
* failed step blocks just its descendants (recorded `skipped`);
|
|
213
|
+
* independent branches still settle. With an `output` schema set, the
|
|
214
|
+
* final `data` is the topological SINK's output (multiple sinks → a
|
|
215
|
+
* convergence error).
|
|
216
|
+
*/
|
|
217
|
+
async executeDag(plan) {
|
|
218
|
+
const dag = buildDag(plan.steps, this.args.config.name);
|
|
219
|
+
const maxConcurrency = Math.max(1, this.args.config.maxConcurrency ?? 4);
|
|
220
|
+
const completed = /* @__PURE__ */ new Set();
|
|
221
|
+
const done = /* @__PURE__ */ new Set();
|
|
222
|
+
const outputs = /* @__PURE__ */ new Map();
|
|
223
|
+
const rawOutputs = /* @__PURE__ */ new Map();
|
|
224
|
+
let executedCount = 0;
|
|
225
|
+
while (done.size < dag.nodes.length) {
|
|
226
|
+
if (this.isAborted()) {
|
|
227
|
+
this.markCancelled();
|
|
228
|
+
this.skipDagRest(dag, done);
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
const ready = readyNodes(dag, completed, done);
|
|
232
|
+
if (ready.length === 0) {
|
|
233
|
+
this.skipDagRest(dag, done);
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
const batch = ready.slice(0, maxConcurrency);
|
|
237
|
+
const settled = await Promise.all(batch.map(async (node) => {
|
|
238
|
+
if (executedCount >= this.args.maxSteps) {
|
|
239
|
+
this.recordSkipped(node.index, node.step);
|
|
240
|
+
return {
|
|
241
|
+
node,
|
|
242
|
+
ran: false,
|
|
243
|
+
completed: false
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
executedCount++;
|
|
247
|
+
const previousOutputs = node.dependencies.map((dependency) => outputs.get(dependency));
|
|
248
|
+
const stepCompleted = await this.executeStep(node.index, node.step, previousOutputs);
|
|
249
|
+
if (stepCompleted) {
|
|
250
|
+
const rawOutput = this.snapshotFor(node.index)?.output;
|
|
251
|
+
rawOutputs.set(node.id, rawOutput);
|
|
252
|
+
outputs.set(node.id, this.stringifyOutput(node.step.capability, rawOutput));
|
|
253
|
+
}
|
|
254
|
+
return {
|
|
255
|
+
node,
|
|
256
|
+
ran: true,
|
|
257
|
+
completed: stepCompleted
|
|
258
|
+
};
|
|
259
|
+
}));
|
|
260
|
+
for (const entry of settled) {
|
|
261
|
+
done.add(entry.node.id);
|
|
262
|
+
if (entry.completed) completed.add(entry.node.id);
|
|
263
|
+
}
|
|
264
|
+
let replanFeedback;
|
|
265
|
+
let shouldAbort = false;
|
|
266
|
+
for (const entry of settled) {
|
|
267
|
+
if (!entry.ran) continue;
|
|
268
|
+
const snapshot = this.snapshotFor(entry.node.index);
|
|
269
|
+
const directive = snapshot ? await this.resolveDirective(snapshot, plan, entry.completed) : void 0;
|
|
270
|
+
if (directive?.type === "replan") replanFeedback = directive.feedback;
|
|
271
|
+
else if (directive?.type === "abort") shouldAbort = true;
|
|
272
|
+
}
|
|
273
|
+
if (shouldAbort) {
|
|
274
|
+
this.skipDagRest(dag, done);
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
if (replanFeedback !== void 0) {
|
|
278
|
+
const remaining = await this.regeneratePlan(replanFeedback);
|
|
279
|
+
if (this.error || !remaining) {
|
|
280
|
+
this.skipDagRest(dag, done);
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
return this.executeDag(remaining);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
this.finalizeDagOutput(dag, completed, rawOutputs);
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
132
289
|
* Dispatch one plan step through its capability's `executable.execute()`
|
|
133
290
|
* and fold the outcome into the accumulators. Returns `true` when the
|
|
134
291
|
* step completed, `false` when it failed (setting the run error).
|
|
@@ -138,10 +295,10 @@ var PlannerRun = class {
|
|
|
138
295
|
const stepStart = performance.now();
|
|
139
296
|
const startedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
140
297
|
const input = this.composeStepInput(step, previousOutputs);
|
|
141
|
-
const result = await capability.executable.execute(input, {
|
|
298
|
+
const result = await withoutRunFrame(() => capability.executable.execute(input, {
|
|
142
299
|
signal: this.args.options?.signal,
|
|
143
300
|
sessionId: this.args.options?.sessionId
|
|
144
|
-
});
|
|
301
|
+
}));
|
|
145
302
|
const childReport = "report" in result ? result.report : void 0;
|
|
146
303
|
this.absorb(result.usage, childReport);
|
|
147
304
|
const output = this.extractOutput(result);
|
|
@@ -167,6 +324,104 @@ var PlannerRun = class {
|
|
|
167
324
|
return true;
|
|
168
325
|
}
|
|
169
326
|
/**
|
|
327
|
+
* Resolve the steering directive for a just-settled step, shared by the
|
|
328
|
+
* sequential and DAG executors. Fires the user's `onStep` hook, then
|
|
329
|
+
* normalizes the result against the `replan` budget:
|
|
330
|
+
*
|
|
331
|
+
* - explicit `replan` directive — honored only when `config.replan` is
|
|
332
|
+
* set and the budget remains; otherwise downgraded to `continue`.
|
|
333
|
+
* - explicit `abort` — honored.
|
|
334
|
+
* - failed step with no overriding directive — auto-`replan` when
|
|
335
|
+
* `config.replan` is set and the budget remains (feedback = the step
|
|
336
|
+
* error message), else `abort` (today's abort-on-first-failure).
|
|
337
|
+
*
|
|
338
|
+
* Returns `undefined` when the run should simply continue. A returned
|
|
339
|
+
* `replan` directive has ALREADY consumed one unit of the replan budget.
|
|
340
|
+
*/
|
|
341
|
+
async resolveDirective(snapshot, plan, completed) {
|
|
342
|
+
const hook = this.args.options?.onStep;
|
|
343
|
+
const userDirective = hook ? await hook(snapshot, plan) : void 0;
|
|
344
|
+
if (userDirective?.type === "replan") {
|
|
345
|
+
if (this.canReplan()) {
|
|
346
|
+
this.replanCount++;
|
|
347
|
+
return userDirective;
|
|
348
|
+
}
|
|
349
|
+
} else if (userDirective?.type === "abort") return { type: "abort" };
|
|
350
|
+
else if (userDirective?.type === "continue") return;
|
|
351
|
+
if (!completed) {
|
|
352
|
+
if (this.canReplan()) {
|
|
353
|
+
this.replanCount++;
|
|
354
|
+
return {
|
|
355
|
+
type: "replan",
|
|
356
|
+
feedback: snapshot.error?.message ?? "step failed"
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
return { type: "abort" };
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
/** Whether a re-plan is configured and the budget has room. */
|
|
363
|
+
canReplan() {
|
|
364
|
+
const replan = this.args.config.replan;
|
|
365
|
+
return replan !== void 0 && this.replanCount < replan.maxReplans;
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Re-ask the planning agent for a plan over the REMAINING work — a
|
|
369
|
+
* second `generatePlan()` seeded with the executed-step digest plus the
|
|
370
|
+
* caller's feedback. Reuses the exact `generatePlan` plumbing (same
|
|
371
|
+
* schema, same `PlannerPlanInvalidError` handling), so a regenerated
|
|
372
|
+
* plan that is empty or names an unknown capability fails identically.
|
|
373
|
+
* The failed step's error is cleared so the regenerated plan runs
|
|
374
|
+
* cleanly; a fresh failure (or exhausted budget) re-sets it.
|
|
375
|
+
*/
|
|
376
|
+
async regeneratePlan(feedback) {
|
|
377
|
+
this.error = void 0;
|
|
378
|
+
return this.generatePlan(feedback);
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* The executed-so-far digest — one context line per completed step, in
|
|
382
|
+
* execution order. Seeds the regenerated plan's first step so it builds
|
|
383
|
+
* on what already ran.
|
|
384
|
+
*/
|
|
385
|
+
executedDigest() {
|
|
386
|
+
return this.executedSteps.filter((snapshot) => snapshot.status === "completed").map((snapshot) => this.stringifyOutput(snapshot.step.capability, snapshot.output));
|
|
387
|
+
}
|
|
388
|
+
/** The last-pushed snapshot for a given step index, if any. */
|
|
389
|
+
snapshotFor(index) {
|
|
390
|
+
for (let position = this.executedSteps.length - 1; position >= 0; position--) {
|
|
391
|
+
const snapshot = this.executedSteps[position];
|
|
392
|
+
if (snapshot.index === index) return snapshot;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
/** Record every step from `from` onward (in a flat array plan) as skipped. */
|
|
396
|
+
skipRest(steps, from) {
|
|
397
|
+
for (let rest = from; rest < steps.length; rest++) this.recordSkipped(rest, steps[rest]);
|
|
398
|
+
}
|
|
399
|
+
/** Record every not-yet-`done` DAG node as skipped, in plan order. */
|
|
400
|
+
skipDagRest(dag, done) {
|
|
401
|
+
for (const node of dag.nodes) if (!done.has(node.id)) this.recordSkipped(node.index, node.step);
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Set `this.data` from the DAG's topological sink for a configured
|
|
405
|
+
* `output` schema. "Last completed step" is meaningless under
|
|
406
|
+
* parallelism, so the sink (the step nothing depends on) is the
|
|
407
|
+
* unambiguous final output. Multiple sinks while an `output` schema is
|
|
408
|
+
* set is a convergence error — a typed `PlannerPlanInvalidError`.
|
|
409
|
+
*/
|
|
410
|
+
finalizeDagOutput(dag, completed, rawOutputs) {
|
|
411
|
+
if (!(this.args.options?.output ?? this.args.config.output) || this.error) return;
|
|
412
|
+
const sinks = sinkNodes(dag).filter((node) => completed.has(node.id));
|
|
413
|
+
if (sinks.length > 1) {
|
|
414
|
+
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: {
|
|
415
|
+
runId: this.runId,
|
|
416
|
+
sinks: sinks.map((node) => node.id)
|
|
417
|
+
} });
|
|
418
|
+
this.data = void 0;
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
const sink = sinks[0];
|
|
422
|
+
this.data = sink ? rawOutputs.get(sink.id) : void 0;
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
170
425
|
* Phase 3 — when an `output` schema is configured (factory or per-call
|
|
171
426
|
* override), validate the final completed step's output into typed
|
|
172
427
|
* `result.data`. A validation failure replaces the run error and flips
|
|
@@ -205,6 +460,7 @@ var PlannerRun = class {
|
|
|
205
460
|
version: this.args.config.version,
|
|
206
461
|
type: "planner",
|
|
207
462
|
status,
|
|
463
|
+
...this.error ? { error: this.error } : {},
|
|
208
464
|
startedAt: this.startedAt,
|
|
209
465
|
endedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
210
466
|
duration: performance.now() - this.startPerf,
|
|
@@ -220,27 +476,42 @@ var PlannerRun = class {
|
|
|
220
476
|
rootRunId: this.runId,
|
|
221
477
|
sessionId: this.args.options?.sessionId
|
|
222
478
|
});
|
|
223
|
-
|
|
479
|
+
const result = {
|
|
224
480
|
type: "planner",
|
|
225
481
|
data: this.error ? void 0 : this.data,
|
|
226
482
|
error: this.error,
|
|
227
483
|
usage: this.usage,
|
|
228
484
|
report
|
|
229
485
|
};
|
|
486
|
+
if (this.awaitingApproval) result.plan = this.plan;
|
|
487
|
+
return result;
|
|
230
488
|
}
|
|
231
489
|
/**
|
|
232
|
-
* Resolve the terminal status from the accumulated outcome.
|
|
233
|
-
*
|
|
234
|
-
*
|
|
490
|
+
* Resolve the terminal status from the accumulated outcome.
|
|
491
|
+
* `awaiting-approval` (plan-only short-circuit) wins over everything —
|
|
492
|
+
* nothing executed, so neither cancellation nor error applies.
|
|
493
|
+
* Otherwise cancelled wins over failed (an abort that also produced a
|
|
494
|
+
* step error still reads as cancelled); failed wins over completed.
|
|
235
495
|
*/
|
|
236
496
|
resolveStatus() {
|
|
497
|
+
if (this.awaitingApproval) return "awaiting-approval";
|
|
237
498
|
if (this.cancelledAt !== void 0) return "cancelled";
|
|
238
499
|
if (this.error) return "failed";
|
|
239
500
|
return "completed";
|
|
240
501
|
}
|
|
241
|
-
/**
|
|
242
|
-
|
|
243
|
-
|
|
502
|
+
/**
|
|
503
|
+
* Build the prompt handed to the planning agent. On the first pass this
|
|
504
|
+
* is just the user's goal (byte-for-byte unchanged). On a RE-plan it
|
|
505
|
+
* prepends the executed-step digest and the steering feedback so the
|
|
506
|
+
* planner revises the remaining work.
|
|
507
|
+
*/
|
|
508
|
+
buildPlanPrompt(feedback) {
|
|
509
|
+
if (feedback === void 0) return this.args.goal;
|
|
510
|
+
const digest = this.executedDigest();
|
|
511
|
+
const sections = [`Goal: ${this.args.goal}`, ""];
|
|
512
|
+
if (digest.length > 0) sections.push("Steps already completed:", ...digest, "");
|
|
513
|
+
sections.push(`Feedback requiring a revised plan: ${feedback}`, "", "Produce a plan for the REMAINING work only.");
|
|
514
|
+
return sections.join("\n");
|
|
244
515
|
}
|
|
245
516
|
/**
|
|
246
517
|
* Compose a step's effective input: the step's own `input`, prefixed
|