@warlock.js/ai 4.2.10 → 4.3.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 +61 -1
- package/cjs/index.cjs +10151 -4625
- package/cjs/index.cjs.map +1 -1
- package/cjs/magic-string.es-BtxW4VqG.cjs +1015 -0
- package/cjs/magic-string.es-BtxW4VqG.cjs.map +1 -0
- package/cjs/matcher-logic-SBnzYohQ.cjs +217 -0
- package/cjs/matcher-logic-SBnzYohQ.cjs.map +1 -0
- package/cjs/matchers-BBh3gyB-.cjs +13739 -0
- package/cjs/matchers-BBh3gyB-.cjs.map +1 -0
- package/esm/agent/agent-config.type.d.mts +19 -6
- package/esm/agent/agent-config.type.d.mts.map +1 -1
- package/esm/agent/agent.d.mts.map +1 -1
- package/esm/agent/agent.mjs +17 -6
- 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/spawn-sub-agent.d.mts +87 -0
- package/esm/agent/spawn-sub-agent.d.mts.map +1 -0
- package/esm/agent/spawn-sub-agent.mjs +68 -0
- package/esm/agent/spawn-sub-agent.mjs.map +1 -0
- package/esm/ai.d.mts +58 -3
- package/esm/ai.d.mts.map +1 -1
- package/esm/ai.mjs +58 -3
- package/esm/ai.mjs.map +1 -1
- package/esm/batch/batch.d.mts +43 -0
- package/esm/batch/batch.d.mts.map +1 -0
- package/esm/batch/batch.mjs +179 -0
- package/esm/batch/batch.mjs.map +1 -0
- package/esm/batch/batch.type.d.mts +144 -0
- package/esm/batch/batch.type.d.mts.map +1 -0
- package/esm/batch/index.mjs +3 -0
- package/esm/batch/run-batch-item.mjs +100 -0
- package/esm/batch/run-batch-item.mjs.map +1 -0
- package/esm/batch/run-with-concurrency.mjs +39 -0
- package/esm/batch/run-with-concurrency.mjs.map +1 -0
- package/esm/checkpoint/index.d.mts +3 -0
- package/esm/checkpoint/memory.d.mts +21 -0
- package/esm/checkpoint/memory.d.mts.map +1 -0
- package/esm/checkpoint/memory.mjs +0 -0
- package/esm/checkpoint/memory.mjs.map +1 -0
- package/esm/checkpoint/pg.d.mts +37 -0
- package/esm/checkpoint/pg.d.mts.map +1 -0
- package/esm/checkpoint/pg.mjs +265 -0
- package/esm/checkpoint/pg.mjs.map +1 -0
- package/esm/checkpoint/redis.d.mts +39 -0
- package/esm/checkpoint/redis.d.mts.map +1 -0
- package/esm/checkpoint/redis.mjs +200 -0
- package/esm/checkpoint/redis.mjs.map +1 -0
- package/esm/config.d.mts +61 -14
- package/esm/config.d.mts.map +1 -1
- package/esm/config.mjs +25 -6
- package/esm/config.mjs.map +1 -1
- package/esm/contracts/agent/agent.contract.d.mts +43 -0
- package/esm/contracts/agent/agent.contract.d.mts.map +1 -1
- package/esm/contracts/agent/eval.type.d.mts +143 -0
- package/esm/contracts/agent/eval.type.d.mts.map +1 -0
- package/esm/contracts/agent/index.d.mts +1 -0
- package/esm/contracts/events/supervisor-events.type.d.mts +3 -3
- package/esm/contracts/fallback-model.contract.d.mts +65 -0
- package/esm/contracts/fallback-model.contract.d.mts.map +1 -0
- package/esm/contracts/index.d.mts +32 -12
- package/esm/contracts/memory/index.d.mts +4 -0
- package/esm/contracts/memory/memory-config.type.d.mts +150 -0
- package/esm/contracts/memory/memory-config.type.d.mts.map +1 -0
- package/esm/contracts/memory/memory-item.type.d.mts +64 -0
- package/esm/contracts/memory/memory-item.type.d.mts.map +1 -0
- package/esm/contracts/memory/memory.contract.d.mts +87 -0
- package/esm/contracts/memory/memory.contract.d.mts.map +1 -0
- package/esm/contracts/memory/recall-options.type.d.mts +33 -0
- package/esm/contracts/memory/recall-options.type.d.mts.map +1 -0
- package/esm/contracts/middleware/index.d.mts +2 -2
- package/esm/contracts/middleware/middleware-context.type.d.mts +42 -2
- package/esm/contracts/middleware/middleware-context.type.d.mts.map +1 -1
- package/esm/contracts/middleware/middleware.contract.d.mts +46 -2
- package/esm/contracts/middleware/middleware.contract.d.mts.map +1 -1
- package/esm/contracts/model.contract.d.mts +63 -2
- package/esm/contracts/model.contract.d.mts.map +1 -1
- package/esm/contracts/orchestrator/checkpoint-store.contract.d.mts +91 -0
- package/esm/contracts/orchestrator/checkpoint-store.contract.d.mts.map +1 -0
- package/esm/contracts/orchestrator/index.d.mts +8 -0
- package/esm/contracts/orchestrator/orchestrator-commands.type.d.mts +43 -0
- package/esm/contracts/orchestrator/orchestrator-commands.type.d.mts.map +1 -0
- package/esm/contracts/orchestrator/orchestrator-config.type.d.mts +170 -0
- package/esm/contracts/orchestrator/orchestrator-config.type.d.mts.map +1 -0
- package/esm/contracts/orchestrator/orchestrator-event.type.d.mts +118 -0
- package/esm/contracts/orchestrator/orchestrator-event.type.d.mts.map +1 -0
- package/esm/contracts/orchestrator/orchestrator-execute-options.type.d.mts +44 -0
- package/esm/contracts/orchestrator/orchestrator-execute-options.type.d.mts.map +1 -0
- package/esm/contracts/orchestrator/orchestrator.contract.d.mts +129 -0
- package/esm/contracts/orchestrator/orchestrator.contract.d.mts.map +1 -0
- package/esm/contracts/orchestrator/session.contract.d.mts +26 -0
- package/esm/contracts/orchestrator/session.contract.d.mts.map +1 -0
- package/esm/contracts/orchestrator/snapshot-store.contract.d.mts +89 -0
- package/esm/contracts/orchestrator/snapshot-store.contract.d.mts.map +1 -0
- package/esm/contracts/planner/index.d.mts +6 -0
- package/esm/contracts/planner/planner-capability.type.d.mts +39 -0
- package/esm/contracts/planner/planner-capability.type.d.mts.map +1 -0
- package/esm/contracts/planner/planner-config.type.d.mts +78 -0
- package/esm/contracts/planner/planner-config.type.d.mts.map +1 -0
- package/esm/contracts/planner/planner-execute-options.type.d.mts +43 -0
- package/esm/contracts/planner/planner-execute-options.type.d.mts.map +1 -0
- package/esm/contracts/planner/planner-plan.type.d.mts +48 -0
- package/esm/contracts/planner/planner-plan.type.d.mts.map +1 -0
- package/esm/contracts/planner/planner-result.type.d.mts +82 -0
- package/esm/contracts/planner/planner-result.type.d.mts.map +1 -0
- package/esm/contracts/planner/planner.contract.d.mts +60 -0
- package/esm/contracts/planner/planner.contract.d.mts.map +1 -0
- package/esm/contracts/result/base-report.type.d.mts +7 -2
- 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/index.d.mts +2 -1
- package/esm/contracts/result/model-pricing.type.d.mts +10 -0
- package/esm/contracts/result/model-pricing.type.d.mts.map +1 -1
- package/esm/contracts/result/orchestrator-result.type.d.mts +139 -0
- package/esm/contracts/result/orchestrator-result.type.d.mts.map +1 -0
- package/esm/contracts/result/session-send-result.type.d.mts +12 -3
- package/esm/contracts/result/session-send-result.type.d.mts.map +1 -1
- package/esm/contracts/result/supervisor-result.type.d.mts +1 -1
- package/esm/contracts/result/usage.type.d.mts +24 -0
- package/esm/contracts/result/usage.type.d.mts.map +1 -1
- package/esm/contracts/sdk-adapter.contract.d.mts +1 -1
- package/esm/contracts/supervisor/dispatch-context.type.d.mts +3 -3
- package/esm/contracts/supervisor/evaluate-context.type.d.mts +1 -1
- package/esm/contracts/supervisor/index.d.mts +5 -5
- package/esm/contracts/supervisor/route-context.type.d.mts +2 -2
- package/esm/contracts/supervisor/supervisor-config.type.d.mts +55 -13
- package/esm/contracts/supervisor/supervisor-config.type.d.mts.map +1 -1
- package/esm/contracts/supervisor/supervisor-snapshot.type.d.mts +1 -1
- package/esm/contracts/supervisor/supervisor.contract.d.mts +9 -2
- package/esm/contracts/supervisor/supervisor.contract.d.mts.map +1 -1
- package/esm/contracts/workflow/index.d.mts +2 -2
- package/esm/contracts/workflow/workflow.contract.d.mts +28 -7
- 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 +7 -0
- package/esm/errors/index.mjs +7 -0
- package/esm/errors/orchestrator-cancelled-error.d.mts +32 -0
- package/esm/errors/orchestrator-cancelled-error.d.mts.map +1 -0
- package/esm/errors/orchestrator-cancelled-error.mjs +31 -0
- package/esm/errors/orchestrator-cancelled-error.mjs.map +1 -0
- package/esm/errors/orchestrator-config-error.d.mts +26 -0
- package/esm/errors/orchestrator-config-error.d.mts.map +1 -0
- package/esm/errors/orchestrator-config-error.mjs +30 -0
- package/esm/errors/orchestrator-config-error.mjs.map +1 -0
- package/esm/errors/orchestrator-drift-error.d.mts +38 -0
- package/esm/errors/orchestrator-drift-error.d.mts.map +1 -0
- package/esm/errors/orchestrator-drift-error.mjs +37 -0
- package/esm/errors/orchestrator-drift-error.mjs.map +1 -0
- package/esm/errors/orchestrator-failed-error.d.mts +33 -0
- package/esm/errors/orchestrator-failed-error.d.mts.map +1 -0
- package/esm/errors/orchestrator-failed-error.mjs +36 -0
- package/esm/errors/orchestrator-failed-error.mjs.map +1 -0
- package/esm/errors/planner-cancelled-error.d.mts +33 -0
- package/esm/errors/planner-cancelled-error.d.mts.map +1 -0
- package/esm/errors/planner-cancelled-error.mjs +29 -0
- package/esm/errors/planner-cancelled-error.mjs.map +1 -0
- package/esm/errors/planner-failed-error.d.mts +40 -0
- package/esm/errors/planner-failed-error.d.mts.map +1 -0
- package/esm/errors/planner-failed-error.mjs +37 -0
- package/esm/errors/planner-failed-error.mjs.map +1 -0
- package/esm/errors/planner-plan-invalid-error.d.mts +21 -0
- package/esm/errors/planner-plan-invalid-error.d.mts.map +1 -0
- package/esm/errors/planner-plan-invalid-error.mjs +25 -0
- package/esm/errors/planner-plan-invalid-error.mjs.map +1 -0
- package/esm/eval/eval-runner.d.mts +17 -0
- package/esm/eval/eval-runner.d.mts.map +1 -0
- package/esm/eval/eval-runner.mjs +121 -0
- package/esm/eval/eval-runner.mjs.map +1 -0
- package/esm/eval/index.d.mts +29 -0
- package/esm/eval/index.d.mts.map +1 -0
- package/esm/eval/index.mjs +30 -0
- package/esm/eval/index.mjs.map +1 -0
- package/esm/eval/judge-scorer.d.mts +21 -0
- package/esm/eval/judge-scorer.d.mts.map +1 -0
- package/esm/eval/judge-scorer.mjs +87 -0
- package/esm/eval/judge-scorer.mjs.map +1 -0
- package/esm/eval/scorers.d.mts +50 -0
- package/esm/eval/scorers.d.mts.map +1 -0
- package/esm/eval/scorers.mjs +101 -0
- package/esm/eval/scorers.mjs.map +1 -0
- package/esm/index.d.mts +95 -30
- package/esm/index.mjs +66 -22
- package/esm/memory/derive-id.mjs +24 -0
- package/esm/memory/derive-id.mjs.map +1 -0
- package/esm/memory/episodic-memory.mjs +106 -0
- package/esm/memory/episodic-memory.mjs.map +1 -0
- package/esm/memory/index.d.mts +5 -0
- package/esm/memory/memory.d.mts +42 -0
- package/esm/memory/memory.d.mts.map +1 -0
- package/esm/memory/memory.mjs +166 -0
- package/esm/memory/memory.mjs.map +1 -0
- package/esm/memory/procedural-memory.mjs +103 -0
- package/esm/memory/procedural-memory.mjs.map +1 -0
- package/esm/memory/semantic-memory.mjs +80 -0
- package/esm/memory/semantic-memory.mjs.map +1 -0
- package/esm/memory/working-memory.mjs +62 -0
- package/esm/memory/working-memory.mjs.map +1 -0
- package/esm/middleware/builtins/budget-contract.type.d.mts +126 -0
- package/esm/middleware/builtins/budget-contract.type.d.mts.map +1 -0
- package/esm/middleware/builtins/budget.d.mts +71 -1
- package/esm/middleware/builtins/budget.d.mts.map +1 -1
- package/esm/middleware/builtins/budget.mjs +119 -4
- package/esm/middleware/builtins/budget.mjs.map +1 -1
- package/esm/middleware/builtins/semantic-cache.d.mts +1 -1
- package/esm/middleware/index.d.mts +2 -1
- package/esm/middleware/index.mjs +1 -1
- package/esm/middleware/pipeline.d.mts +9 -6
- package/esm/middleware/pipeline.d.mts.map +1 -1
- package/esm/middleware/pipeline.mjs.map +1 -1
- package/esm/mock/index.d.mts +1 -0
- package/esm/mock/index.mjs +1 -0
- package/esm/mock/mock-router.d.mts +63 -0
- package/esm/mock/mock-router.d.mts.map +1 -0
- package/esm/mock/mock-router.mjs +58 -0
- package/esm/mock/mock-router.mjs.map +1 -0
- package/esm/model/fallback-model.d.mts +45 -0
- package/esm/model/fallback-model.d.mts.map +1 -0
- package/esm/model/fallback-model.mjs +218 -0
- package/esm/model/fallback-model.mjs.map +1 -0
- package/esm/model/index.d.mts +2 -0
- package/esm/model/index.mjs +3 -0
- package/esm/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs +78 -0
- package/esm/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs.map +1 -0
- package/esm/node_modules/@vitest/expect/dist/index.mjs +1473 -0
- package/esm/node_modules/@vitest/expect/dist/index.mjs.map +1 -0
- package/esm/node_modules/@vitest/pretty-format/dist/index.mjs +888 -0
- package/esm/node_modules/@vitest/pretty-format/dist/index.mjs.map +1 -0
- package/esm/node_modules/@vitest/runner/dist/chunk-artifact.mjs +1533 -0
- package/esm/node_modules/@vitest/runner/dist/chunk-artifact.mjs.map +1 -0
- package/esm/node_modules/@vitest/runner/dist/index.mjs +3 -0
- package/esm/node_modules/@vitest/runner/dist/utils.mjs +3 -0
- package/esm/node_modules/@vitest/snapshot/dist/index.mjs +922 -0
- package/esm/node_modules/@vitest/snapshot/dist/index.mjs.map +1 -0
- package/esm/node_modules/@vitest/spy/dist/index.mjs +386 -0
- package/esm/node_modules/@vitest/spy/dist/index.mjs.map +1 -0
- package/esm/node_modules/@vitest/utils/dist/chunk-pathe.M-eThtNZ.mjs +82 -0
- package/esm/node_modules/@vitest/utils/dist/chunk-pathe.M-eThtNZ.mjs.map +1 -0
- package/esm/node_modules/@vitest/utils/dist/diff.mjs +1357 -0
- package/esm/node_modules/@vitest/utils/dist/diff.mjs.map +1 -0
- package/esm/node_modules/@vitest/utils/dist/display.mjs +559 -0
- package/esm/node_modules/@vitest/utils/dist/display.mjs.map +1 -0
- package/esm/node_modules/@vitest/utils/dist/error.mjs +38 -0
- package/esm/node_modules/@vitest/utils/dist/error.mjs.map +1 -0
- package/esm/node_modules/@vitest/utils/dist/helpers.mjs +181 -0
- package/esm/node_modules/@vitest/utils/dist/helpers.mjs.map +1 -0
- package/esm/node_modules/@vitest/utils/dist/offset.mjs +27 -0
- package/esm/node_modules/@vitest/utils/dist/offset.mjs.map +1 -0
- package/esm/node_modules/@vitest/utils/dist/serialize.mjs +77 -0
- package/esm/node_modules/@vitest/utils/dist/serialize.mjs.map +1 -0
- package/esm/node_modules/@vitest/utils/dist/source-map.mjs +374 -0
- package/esm/node_modules/@vitest/utils/dist/source-map.mjs.map +1 -0
- package/esm/node_modules/@vitest/utils/dist/timers.mjs +37 -0
- package/esm/node_modules/@vitest/utils/dist/timers.mjs.map +1 -0
- package/esm/node_modules/chai/index.mjs +2973 -0
- package/esm/node_modules/chai/index.mjs.map +1 -0
- package/esm/node_modules/magic-string/dist/magic-string.es.mjs +940 -0
- package/esm/node_modules/magic-string/dist/magic-string.es.mjs.map +1 -0
- package/esm/node_modules/tinyrainbow/dist/index.mjs +87 -0
- package/esm/node_modules/tinyrainbow/dist/index.mjs.map +1 -0
- package/esm/node_modules/vitest/dist/chunks/_commonjsHelpers.D26ty3Ew.mjs +6 -0
- package/esm/node_modules/vitest/dist/chunks/_commonjsHelpers.D26ty3Ew.mjs.map +1 -0
- package/esm/node_modules/vitest/dist/chunks/rpc.MzXet3jl.mjs +52 -0
- package/esm/node_modules/vitest/dist/chunks/rpc.MzXet3jl.mjs.map +1 -0
- package/esm/node_modules/vitest/dist/chunks/test.DNmyFkvJ.mjs +2697 -0
- package/esm/node_modules/vitest/dist/chunks/test.DNmyFkvJ.mjs.map +1 -0
- package/esm/node_modules/vitest/dist/chunks/utils.BX5Fg8C4.mjs +45 -0
- package/esm/node_modules/vitest/dist/chunks/utils.BX5Fg8C4.mjs.map +1 -0
- package/esm/orchestrator/as-tool.d.mts +42 -0
- package/esm/orchestrator/as-tool.d.mts.map +1 -0
- package/esm/orchestrator/as-tool.mjs +98 -0
- package/esm/orchestrator/as-tool.mjs.map +1 -0
- package/esm/orchestrator/checkpoint.mjs +75 -0
- package/esm/orchestrator/checkpoint.mjs.map +1 -0
- package/esm/orchestrator/commands.d.mts +38 -0
- package/esm/orchestrator/commands.d.mts.map +1 -0
- package/esm/orchestrator/commands.mjs +34 -0
- package/esm/orchestrator/commands.mjs.map +1 -0
- package/esm/orchestrator/compaction.mjs +206 -0
- package/esm/orchestrator/compaction.mjs.map +1 -0
- package/esm/orchestrator/dispatch.mjs +171 -0
- package/esm/orchestrator/dispatch.mjs.map +1 -0
- package/esm/orchestrator/emitter-port.type.d.mts +31 -0
- package/esm/orchestrator/emitter-port.type.d.mts.map +1 -0
- package/esm/orchestrator/emitter.d.mts +56 -0
- package/esm/orchestrator/emitter.d.mts.map +1 -0
- package/esm/orchestrator/emitter.mjs +85 -0
- package/esm/orchestrator/emitter.mjs.map +1 -0
- package/esm/orchestrator/engine-context.type.d.mts +56 -0
- package/esm/orchestrator/engine-context.type.d.mts.map +1 -0
- package/esm/orchestrator/execution.d.mts +116 -0
- package/esm/orchestrator/execution.d.mts.map +1 -0
- package/esm/orchestrator/execution.mjs +406 -0
- package/esm/orchestrator/execution.mjs.map +1 -0
- package/esm/orchestrator/index.d.mts +8 -0
- package/esm/orchestrator/index.mjs +10 -0
- package/esm/orchestrator/load.mjs +49 -0
- package/esm/orchestrator/load.mjs.map +1 -0
- package/esm/orchestrator/lock.mjs +75 -0
- package/esm/orchestrator/lock.mjs.map +1 -0
- package/esm/orchestrator/memory.d.mts +84 -0
- package/esm/orchestrator/memory.d.mts.map +1 -0
- package/esm/orchestrator/memory.mjs +141 -0
- package/esm/orchestrator/memory.mjs.map +1 -0
- package/esm/orchestrator/orchestrator-stream.d.mts +42 -0
- package/esm/orchestrator/orchestrator-stream.d.mts.map +1 -0
- package/esm/orchestrator/orchestrator-stream.mjs +98 -0
- package/esm/orchestrator/orchestrator-stream.mjs.map +1 -0
- package/esm/orchestrator/orchestrator.d.mts +38 -0
- package/esm/orchestrator/orchestrator.d.mts.map +1 -0
- package/esm/orchestrator/orchestrator.mjs +173 -0
- package/esm/orchestrator/orchestrator.mjs.map +1 -0
- package/esm/orchestrator/resume.mjs +74 -0
- package/esm/orchestrator/resume.mjs.map +1 -0
- package/esm/orchestrator/signature.d.mts +40 -0
- package/esm/orchestrator/signature.d.mts.map +1 -0
- package/esm/orchestrator/signature.mjs +120 -0
- package/esm/orchestrator/signature.mjs.map +1 -0
- package/esm/orchestrator/window.mjs +56 -0
- package/esm/orchestrator/window.mjs.map +1 -0
- package/esm/planner/index.d.mts +5 -0
- package/esm/planner/index.mjs +6 -0
- package/esm/planner/plan-prompt.d.mts +17 -0
- package/esm/planner/plan-prompt.d.mts.map +1 -0
- package/esm/planner/plan-prompt.mjs +30 -0
- package/esm/planner/plan-prompt.mjs.map +1 -0
- package/esm/planner/plan-schema.d.mts +27 -0
- package/esm/planner/plan-schema.d.mts.map +1 -0
- package/esm/planner/plan-schema.mjs +117 -0
- package/esm/planner/plan-schema.mjs.map +1 -0
- package/esm/planner/planner-run.d.mts +23 -0
- package/esm/planner/planner-run.d.mts.map +1 -0
- package/esm/planner/planner-run.mjs +344 -0
- package/esm/planner/planner-run.mjs.map +1 -0
- package/esm/planner/planner.d.mts +37 -0
- package/esm/planner/planner.d.mts.map +1 -0
- package/esm/planner/planner.mjs +120 -0
- package/esm/planner/planner.mjs.map +1 -0
- package/esm/planner/signature.d.mts +18 -0
- package/esm/planner/signature.d.mts.map +1 -0
- package/esm/planner/signature.mjs +27 -0
- package/esm/planner/signature.mjs.map +1 -0
- package/esm/snapshot/index.d.mts +3 -0
- package/esm/snapshot/memory.d.mts +26 -0
- package/esm/snapshot/memory.d.mts.map +1 -0
- package/esm/snapshot/memory.mjs +81 -0
- package/esm/snapshot/memory.mjs.map +1 -0
- package/esm/snapshot/pg.d.mts +41 -0
- package/esm/snapshot/pg.d.mts.map +1 -0
- package/esm/snapshot/pg.mjs +146 -0
- package/esm/snapshot/pg.mjs.map +1 -0
- package/esm/snapshot/redis.d.mts +42 -0
- package/esm/snapshot/redis.d.mts.map +1 -0
- package/esm/snapshot/redis.mjs +101 -0
- package/esm/snapshot/redis.mjs.map +1 -0
- package/esm/supervisor/as-tool.d.mts +0 -6
- package/esm/supervisor/as-tool.d.mts.map +1 -1
- package/esm/supervisor/as-tool.mjs +0 -6
- package/esm/supervisor/as-tool.mjs.map +1 -1
- package/esm/supervisor/execution.d.mts +43 -8
- package/esm/supervisor/execution.d.mts.map +1 -1
- package/esm/supervisor/execution.mjs +66 -16
- package/esm/supervisor/execution.mjs.map +1 -1
- package/esm/supervisor/fan-out.d.mts +65 -0
- package/esm/supervisor/fan-out.d.mts.map +1 -0
- package/esm/supervisor/fan-out.mjs +65 -0
- package/esm/supervisor/fan-out.mjs.map +1 -0
- package/esm/supervisor/index.d.mts +5 -3
- package/esm/supervisor/index.mjs +3 -1
- package/esm/supervisor/router-factory.d.mts +110 -0
- package/esm/supervisor/router-factory.d.mts.map +1 -0
- package/esm/supervisor/router-factory.mjs +141 -0
- package/esm/supervisor/router-factory.mjs.map +1 -0
- package/esm/supervisor/router-prompt.d.mts +1 -1
- package/esm/supervisor/snapshot.d.mts +4 -10
- package/esm/supervisor/snapshot.d.mts.map +1 -1
- package/esm/supervisor/snapshot.mjs +8 -16
- package/esm/supervisor/snapshot.mjs.map +1 -1
- package/esm/supervisor/supervisor.mjs +1 -0
- package/esm/supervisor/supervisor.mjs.map +1 -1
- package/esm/system-prompt/index.mjs +6 -0
- package/esm/system-prompt/system-prompt.d.mts +51 -3
- package/esm/system-prompt/system-prompt.d.mts.map +1 -1
- package/esm/system-prompt/system-prompt.mjs +52 -6
- package/esm/system-prompt/system-prompt.mjs.map +1 -1
- package/esm/testing/matcher-logic.d.mts +76 -0
- package/esm/testing/matcher-logic.d.mts.map +1 -0
- package/esm/testing/matcher-logic.mjs +144 -0
- package/esm/testing/matcher-logic.mjs.map +1 -0
- package/esm/testing/matchers.d.mts +48 -0
- package/esm/testing/matchers.d.mts.map +1 -0
- package/esm/testing/matchers.mjs +37 -0
- package/esm/testing/matchers.mjs.map +1 -0
- package/esm/testing/register-lazy.d.mts +20 -0
- package/esm/testing/register-lazy.d.mts.map +1 -0
- package/esm/testing/register-lazy.mjs +24 -0
- package/esm/testing/register-lazy.mjs.map +1 -0
- package/esm/tool/executable-as-tool.d.mts +87 -0
- package/esm/tool/executable-as-tool.d.mts.map +1 -0
- package/esm/tool/executable-as-tool.mjs +81 -0
- package/esm/tool/executable-as-tool.mjs.map +1 -0
- package/esm/tool/index.d.mts +2 -1
- package/esm/tool/index.mjs +1 -0
- package/esm/workflow/as-tool.mjs +0 -6
- package/esm/workflow/as-tool.mjs.map +1 -1
- package/esm/workflow/engine.mjs +2 -2
- package/esm/workflow/snapshot.mjs +13 -7
- package/esm/workflow/snapshot.mjs.map +1 -1
- package/esm/workflow/step-runner.mjs +1 -1
- package/esm/workflow/workflow.mjs +1 -0
- package/esm/workflow/workflow.mjs.map +1 -1
- package/llms-full.txt +947 -42
- package/llms.txt +13 -8
- package/package.json +3 -3
- package/skills/README.md +25 -5
- package/skills/ai-basics/SKILL.md +18 -7
- package/skills/ai-dx-helpers/SKILL.md +180 -0
- package/skills/attach-ai-middleware/SKILL.md +32 -3
- package/skills/handle-ai-errors/SKILL.md +20 -6
- package/skills/manage-ai-stores/SKILL.md +127 -0
- package/skills/persist-ai-data/SKILL.md +21 -10
- package/skills/pick-ai-provider/SKILL.md +46 -12
- package/skills/run-ai-agent/SKILL.md +51 -2
- package/skills/run-orchestrator/SKILL.md +198 -0
- package/skills/run-planner/SKILL.md +68 -0
- package/skills/run-supervisor/SKILL.md +47 -2
- package/skills/use-ai-memory/SKILL.md +124 -0
- package/skills/write-system-prompt/SKILL.md +14 -1
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { AgentContract } from "../contracts/agent/agent.contract.mjs";
|
|
2
|
+
import { WorkflowInstance } from "../contracts/workflow/workflow.contract.mjs";
|
|
3
|
+
import { IntentEntry } from "../contracts/supervisor/intent-entry.type.mjs";
|
|
4
|
+
|
|
5
|
+
//#region ../@warlock.js/ai/src/supervisor/fan-out.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* A dispatchable unit that can be fanned out — an agent or a workflow.
|
|
8
|
+
* The same union the supervisor's `intents` map accepts for its
|
|
9
|
+
* agent/workflow object entries.
|
|
10
|
+
*/
|
|
11
|
+
type FanOutUnit = AgentContract<unknown> | WorkflowInstance<unknown, unknown>;
|
|
12
|
+
/**
|
|
13
|
+
* Options for {@link fanOut}.
|
|
14
|
+
*/
|
|
15
|
+
type FanOutOptions = {
|
|
16
|
+
/**
|
|
17
|
+
* Base name for the generated intent keys. Defaults to the unit's own
|
|
18
|
+
* `name`. The keys are `<keyPrefix>1`, `<keyPrefix>2`, … `<keyPrefix>n`.
|
|
19
|
+
*/
|
|
20
|
+
keyPrefix?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Description applied to every generated entry. Defaults to the
|
|
23
|
+
* unit's own `description`. A description is required when the
|
|
24
|
+
* supervisor uses a `router` (the LLM needs a signal per intent); the
|
|
25
|
+
* factory enforces that downstream, so supply one here when the
|
|
26
|
+
* underlying unit has none.
|
|
27
|
+
*/
|
|
28
|
+
description?: string;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Spread one agent/workflow into `n` distinctly-keyed intent entries
|
|
32
|
+
* for voting / self-consistency under a supervisor.
|
|
33
|
+
*
|
|
34
|
+
* A supervisor dispatches a fan-out array (`["writer1", "writer2",
|
|
35
|
+
* "writer3"]`) in parallel; each branch runs the SAME unit independently
|
|
36
|
+
* so a downstream evaluate/aggregate intent can pick the majority answer
|
|
37
|
+
* or the best of `n` samples. Because every branch needs its own intent
|
|
38
|
+
* KEY, this helper clones the unit across distinct keys rather than
|
|
39
|
+
* cloning the unit itself — the underlying agent/workflow is referenced
|
|
40
|
+
* by all entries, but each entry is a separate dispatch slot.
|
|
41
|
+
*
|
|
42
|
+
* Returns a `Record<string, IntentEntry>` you spread directly into the
|
|
43
|
+
* supervisor's `intents` map. The keys are `<keyPrefix>1..<keyPrefix>n`.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* const writer = ai.agent({ name: "writer", description: "Drafts an answer.", model });
|
|
47
|
+
*
|
|
48
|
+
* const support = ai.supervisor({
|
|
49
|
+
* name: "self-consistency",
|
|
50
|
+
* intents: {
|
|
51
|
+
* ...ai.fanOut(writer, 3), // writer1, writer2, writer3
|
|
52
|
+
* vote: { run: pickMajority, description: "Choose the majority answer." },
|
|
53
|
+
* },
|
|
54
|
+
* route: (ctx) =>
|
|
55
|
+
* ctx.iteration === 0 ? ["writer1", "writer2", "writer3"] : "vote",
|
|
56
|
+
* });
|
|
57
|
+
*
|
|
58
|
+
* @param unit The agent or workflow to fan out.
|
|
59
|
+
* @param count Number of parallel copies. Must be an integer >= 1.
|
|
60
|
+
* @param options Optional key-prefix / description overrides.
|
|
61
|
+
*/
|
|
62
|
+
declare function fanOut(unit: FanOutUnit, count: number, options?: FanOutOptions): Record<string, IntentEntry>;
|
|
63
|
+
//#endregion
|
|
64
|
+
export { FanOutOptions, FanOutUnit, fanOut };
|
|
65
|
+
//# sourceMappingURL=fan-out.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fan-out.d.mts","names":[],"sources":["../../../../../../../@warlock.js/ai/src/supervisor/fan-out.ts"],"mappings":";;;;;;;AASA;;;KAAY,UAAA,GAAa,aAAA,YAAyB,gBAAgB;AAAA;AAKlE;;AALkE,KAKtD,aAAA;EAKV;AAQW;AAmCb;;EA3CE,SAAA;EA4CM;;;;;;;EApCN,WAAW;AAAA;;;;;;AAuCgB;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAJb,MAAA,CACd,IAAA,EAAM,UAAA,EACN,KAAA,UACA,OAAA,GAAS,aAAA,GACR,MAAA,SAAe,WAAA"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
//#region ../@warlock.js/ai/src/supervisor/fan-out.ts
|
|
2
|
+
/**
|
|
3
|
+
* Spread one agent/workflow into `n` distinctly-keyed intent entries
|
|
4
|
+
* for voting / self-consistency under a supervisor.
|
|
5
|
+
*
|
|
6
|
+
* A supervisor dispatches a fan-out array (`["writer1", "writer2",
|
|
7
|
+
* "writer3"]`) in parallel; each branch runs the SAME unit independently
|
|
8
|
+
* so a downstream evaluate/aggregate intent can pick the majority answer
|
|
9
|
+
* or the best of `n` samples. Because every branch needs its own intent
|
|
10
|
+
* KEY, this helper clones the unit across distinct keys rather than
|
|
11
|
+
* cloning the unit itself — the underlying agent/workflow is referenced
|
|
12
|
+
* by all entries, but each entry is a separate dispatch slot.
|
|
13
|
+
*
|
|
14
|
+
* Returns a `Record<string, IntentEntry>` you spread directly into the
|
|
15
|
+
* supervisor's `intents` map. The keys are `<keyPrefix>1..<keyPrefix>n`.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* const writer = ai.agent({ name: "writer", description: "Drafts an answer.", model });
|
|
19
|
+
*
|
|
20
|
+
* const support = ai.supervisor({
|
|
21
|
+
* name: "self-consistency",
|
|
22
|
+
* intents: {
|
|
23
|
+
* ...ai.fanOut(writer, 3), // writer1, writer2, writer3
|
|
24
|
+
* vote: { run: pickMajority, description: "Choose the majority answer." },
|
|
25
|
+
* },
|
|
26
|
+
* route: (ctx) =>
|
|
27
|
+
* ctx.iteration === 0 ? ["writer1", "writer2", "writer3"] : "vote",
|
|
28
|
+
* });
|
|
29
|
+
*
|
|
30
|
+
* @param unit The agent or workflow to fan out.
|
|
31
|
+
* @param count Number of parallel copies. Must be an integer >= 1.
|
|
32
|
+
* @param options Optional key-prefix / description overrides.
|
|
33
|
+
*/
|
|
34
|
+
function fanOut(unit, count, options = {}) {
|
|
35
|
+
if (!unit || typeof unit.execute !== "function") throw new TypeError("ai.fanOut: first argument must be an agent or workflow");
|
|
36
|
+
if (!Number.isInteger(count) || count < 1) throw new TypeError(`ai.fanOut: \`count\` must be an integer >= 1 (received ${String(count)})`);
|
|
37
|
+
const keyPrefix = resolveKeyPrefix(unit, options.keyPrefix);
|
|
38
|
+
const description = options.description ?? readDescription(unit);
|
|
39
|
+
const entries = {};
|
|
40
|
+
for (let index = 1; index <= count; index++) {
|
|
41
|
+
const entry = { agent: unit };
|
|
42
|
+
if (description) entry.description = description;
|
|
43
|
+
entries[`${keyPrefix}${index}`] = entry;
|
|
44
|
+
}
|
|
45
|
+
return entries;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Resolve the base key prefix: explicit override wins, then the unit's
|
|
49
|
+
* own name. A unit with no usable name forces an explicit `keyPrefix`
|
|
50
|
+
* so the generated keys stay meaningful and collision-free.
|
|
51
|
+
*/
|
|
52
|
+
function resolveKeyPrefix(unit, override) {
|
|
53
|
+
if (override && override.trim().length > 0) return override.trim();
|
|
54
|
+
const name = unit.name;
|
|
55
|
+
if (typeof name === "string" && name.trim().length > 0) return name.trim();
|
|
56
|
+
throw new TypeError("ai.fanOut: the unit has no usable `name` — pass `options.keyPrefix` to name the generated intent keys");
|
|
57
|
+
}
|
|
58
|
+
function readDescription(unit) {
|
|
59
|
+
const description = unit.description;
|
|
60
|
+
return typeof description === "string" && description.trim().length > 0 ? description : void 0;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
//#endregion
|
|
64
|
+
export { fanOut };
|
|
65
|
+
//# sourceMappingURL=fan-out.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fan-out.mjs","names":[],"sources":["../../../../../../../@warlock.js/ai/src/supervisor/fan-out.ts"],"sourcesContent":["import type { AgentContract } from \"../contracts/agent/agent.contract\";\nimport type { IntentEntry } from \"../contracts/supervisor/intent-entry.type\";\nimport type { WorkflowInstance } from \"../contracts/workflow/workflow.contract\";\n\n/**\n * A dispatchable unit that can be fanned out — an agent or a workflow.\n * The same union the supervisor's `intents` map accepts for its\n * agent/workflow object entries.\n */\nexport type FanOutUnit = AgentContract<unknown> | WorkflowInstance<unknown, unknown>;\n\n/**\n * Options for {@link fanOut}.\n */\nexport type FanOutOptions = {\n /**\n * Base name for the generated intent keys. Defaults to the unit's own\n * `name`. The keys are `<keyPrefix>1`, `<keyPrefix>2`, … `<keyPrefix>n`.\n */\n keyPrefix?: string;\n /**\n * Description applied to every generated entry. Defaults to the\n * unit's own `description`. A description is required when the\n * supervisor uses a `router` (the LLM needs a signal per intent); the\n * factory enforces that downstream, so supply one here when the\n * underlying unit has none.\n */\n description?: string;\n};\n\n/**\n * Spread one agent/workflow into `n` distinctly-keyed intent entries\n * for voting / self-consistency under a supervisor.\n *\n * A supervisor dispatches a fan-out array (`[\"writer1\", \"writer2\",\n * \"writer3\"]`) in parallel; each branch runs the SAME unit independently\n * so a downstream evaluate/aggregate intent can pick the majority answer\n * or the best of `n` samples. Because every branch needs its own intent\n * KEY, this helper clones the unit across distinct keys rather than\n * cloning the unit itself — the underlying agent/workflow is referenced\n * by all entries, but each entry is a separate dispatch slot.\n *\n * Returns a `Record<string, IntentEntry>` you spread directly into the\n * supervisor's `intents` map. The keys are `<keyPrefix>1..<keyPrefix>n`.\n *\n * @example\n * const writer = ai.agent({ name: \"writer\", description: \"Drafts an answer.\", model });\n *\n * const support = ai.supervisor({\n * name: \"self-consistency\",\n * intents: {\n * ...ai.fanOut(writer, 3), // writer1, writer2, writer3\n * vote: { run: pickMajority, description: \"Choose the majority answer.\" },\n * },\n * route: (ctx) =>\n * ctx.iteration === 0 ? [\"writer1\", \"writer2\", \"writer3\"] : \"vote\",\n * });\n *\n * @param unit The agent or workflow to fan out.\n * @param count Number of parallel copies. Must be an integer >= 1.\n * @param options Optional key-prefix / description overrides.\n */\nexport function fanOut(\n unit: FanOutUnit,\n count: number,\n options: FanOutOptions = {},\n): Record<string, IntentEntry> {\n if (!unit || typeof (unit as { execute?: unknown }).execute !== \"function\") {\n throw new TypeError(\"ai.fanOut: first argument must be an agent or workflow\");\n }\n\n if (!Number.isInteger(count) || count < 1) {\n throw new TypeError(`ai.fanOut: \\`count\\` must be an integer >= 1 (received ${String(count)})`);\n }\n\n const keyPrefix = resolveKeyPrefix(unit, options.keyPrefix);\n const description = options.description ?? readDescription(unit);\n\n const entries: Record<string, IntentEntry> = {};\n\n for (let index = 1; index <= count; index++) {\n const entry: IntentEntry = { agent: unit };\n\n if (description) {\n entry.description = description;\n }\n\n entries[`${keyPrefix}${index}`] = entry;\n }\n\n return entries;\n}\n\n/**\n * Resolve the base key prefix: explicit override wins, then the unit's\n * own name. A unit with no usable name forces an explicit `keyPrefix`\n * so the generated keys stay meaningful and collision-free.\n */\nfunction resolveKeyPrefix(unit: FanOutUnit, override: string | undefined): string {\n if (override && override.trim().length > 0) {\n return override.trim();\n }\n\n const name = (unit as { name?: unknown }).name;\n\n if (typeof name === \"string\" && name.trim().length > 0) {\n return name.trim();\n }\n\n throw new TypeError(\n \"ai.fanOut: the unit has no usable `name` — pass `options.keyPrefix` to name the generated intent keys\",\n );\n}\n\nfunction readDescription(unit: FanOutUnit): string | undefined {\n const description = (unit as { description?: unknown }).description;\n\n return typeof description === \"string\" && description.trim().length > 0 ? description : undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8DA,SAAgB,OACd,MACA,OACA,UAAyB,CAAC,GACG;CAC7B,IAAI,CAAC,QAAQ,OAAQ,KAA+B,YAAY,YAC9D,MAAM,IAAI,UAAU,wDAAwD;CAG9E,IAAI,CAAC,OAAO,UAAU,KAAK,KAAK,QAAQ,GACtC,MAAM,IAAI,UAAU,0DAA0D,OAAO,KAAK,EAAE,EAAE;CAGhG,MAAM,YAAY,iBAAiB,MAAM,QAAQ,SAAS;CAC1D,MAAM,cAAc,QAAQ,eAAe,gBAAgB,IAAI;CAE/D,MAAM,UAAuC,CAAC;CAE9C,KAAK,IAAI,QAAQ,GAAG,SAAS,OAAO,SAAS;EAC3C,MAAM,QAAqB,EAAE,OAAO,KAAK;EAEzC,IAAI,aACF,MAAM,cAAc;EAGtB,QAAQ,GAAG,YAAY,WAAW;CACpC;CAEA,OAAO;AACT;;;;;;AAOA,SAAS,iBAAiB,MAAkB,UAAsC;CAChF,IAAI,YAAY,SAAS,KAAK,CAAC,CAAC,SAAS,GACvC,OAAO,SAAS,KAAK;CAGvB,MAAM,OAAQ,KAA4B;CAE1C,IAAI,OAAO,SAAS,YAAY,KAAK,KAAK,CAAC,CAAC,SAAS,GACnD,OAAO,KAAK,KAAK;CAGnB,MAAM,IAAI,UACR,uGACF;AACF;AAEA,SAAS,gBAAgB,MAAsC;CAC7D,MAAM,cAAe,KAAmC;CAExD,OAAO,OAAO,gBAAgB,YAAY,YAAY,KAAK,CAAC,CAAC,SAAS,IAAI,cAAc;AAC1F"}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { SupervisorStreamEvent } from "../contracts/supervisor/supervisor-stream-event.type.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { ResolvedIntentEntry, resolveIntentEntries } from "./entries.mjs";
|
|
3
3
|
import { asTool } from "./as-tool.mjs";
|
|
4
4
|
import { createCancelledError } from "./cancellation.mjs";
|
|
5
5
|
import { SupervisorEmitter } from "./emitter.mjs";
|
|
6
|
-
import { ResolvedIntentEntry, resolveIntentEntries } from "./entries.mjs";
|
|
7
6
|
import { SupervisorStreamController, createSupervisorStream } from "./supervisor-stream.mjs";
|
|
8
7
|
import { SupervisorExecution } from "./execution.mjs";
|
|
8
|
+
import { FanOutOptions, FanOutUnit, fanOut } from "./fan-out.mjs";
|
|
9
|
+
import { RouterConfig, RouterIntents, RouterOutput, router } from "./router-factory.mjs";
|
|
9
10
|
import { buildRouterContextMessage } from "./router-prompt.mjs";
|
|
10
11
|
import { computeSignature } from "./signature.mjs";
|
|
11
|
-
import { loadSnapshotForResume, persistSupervisorSnapshot
|
|
12
|
+
import { loadSnapshotForResume, persistSupervisorSnapshot } from "./snapshot.mjs";
|
|
13
|
+
import { supervisor } from "./supervisor.mjs";
|
package/esm/supervisor/index.mjs
CHANGED
|
@@ -3,10 +3,12 @@ import { SupervisorEmitter } from "./emitter.mjs";
|
|
|
3
3
|
import { resolveIntentEntries } from "./entries.mjs";
|
|
4
4
|
import { createCancelledError } from "./cancellation.mjs";
|
|
5
5
|
import { buildRouterContextMessage } from "./router-prompt.mjs";
|
|
6
|
-
import { loadSnapshotForResume, persistSupervisorSnapshot
|
|
6
|
+
import { loadSnapshotForResume, persistSupervisorSnapshot } from "./snapshot.mjs";
|
|
7
7
|
import { SupervisorExecution } from "./execution.mjs";
|
|
8
8
|
import { computeSignature } from "./signature.mjs";
|
|
9
9
|
import { createSupervisorStream } from "./supervisor-stream.mjs";
|
|
10
10
|
import { supervisor } from "./supervisor.mjs";
|
|
11
|
+
import { fanOut } from "./fan-out.mjs";
|
|
12
|
+
import { router } from "./router-factory.mjs";
|
|
11
13
|
|
|
12
14
|
export { };
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { AgentContract } from "../contracts/agent/agent.contract.mjs";
|
|
2
|
+
import { ModelCallOptions, ModelContract } from "../contracts/model.contract.mjs";
|
|
3
|
+
import { Placeholders } from "../contracts/placeholders.type.mjs";
|
|
4
|
+
import { SystemPromptContract } from "../contracts/system-prompt.contract.mjs";
|
|
5
|
+
import { SupervisorIntentValue } from "../contracts/supervisor/intent-entry.type.mjs";
|
|
6
|
+
import { Next } from "../contracts/supervisor/next.type.mjs";
|
|
7
|
+
import { AgentEventHandlers } from "../agent/agent-config.type.mjs";
|
|
8
|
+
|
|
9
|
+
//#region ../@warlock.js/ai/src/supervisor/router-factory.d.ts
|
|
10
|
+
/**
|
|
11
|
+
* Output shape every router agent produced by {@link router} emits —
|
|
12
|
+
* the canonical `{ next, reasoning }` contract the supervisor's
|
|
13
|
+
* dispatch loop reads. Exposed so callers can type a router result
|
|
14
|
+
* they handle directly.
|
|
15
|
+
*/
|
|
16
|
+
type RouterOutput = {
|
|
17
|
+
/** Chosen intent name, a fan-out array, or the `END` sentinel. */next: Next; /** One-sentence justification for the routing choice. */
|
|
18
|
+
reasoning: string;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Description source for one intent the router can pick from. Accepts
|
|
22
|
+
* the same value-shapes the supervisor's `intents` map does (bare
|
|
23
|
+
* agent / workflow / callback / object entry) so a caller can pass the
|
|
24
|
+
* very same `intents` object to both `router()` and `ai.supervisor()`.
|
|
25
|
+
*
|
|
26
|
+
* The router only needs each intent's NAME (the map key) and a
|
|
27
|
+
* human-readable DESCRIPTION — it never dispatches anything itself, so
|
|
28
|
+
* the underlying unit is read for its `description` only.
|
|
29
|
+
*/
|
|
30
|
+
type RouterIntents = Record<string, SupervisorIntentValue>;
|
|
31
|
+
/**
|
|
32
|
+
* Config for {@link router}. Mirrors the relevant slice of `AgentConfig`
|
|
33
|
+
* — the router IS an agent — plus the `intents` map it routes over.
|
|
34
|
+
*
|
|
35
|
+
* Everything except `model` and `intents` is optional; the helper
|
|
36
|
+
* generates the output schema and the routing system prompt for you.
|
|
37
|
+
*/
|
|
38
|
+
type RouterConfig = {
|
|
39
|
+
/**
|
|
40
|
+
* Stable identifier for the router agent. Defaults to
|
|
41
|
+
* `"<supervisor-ish>-router"` is NOT assumed — when omitted the helper
|
|
42
|
+
* uses `"router"` so the agent carries a meaningful (non-anonymous)
|
|
43
|
+
* name, which `ai.supervisor({ router })` is happy to accept.
|
|
44
|
+
*/
|
|
45
|
+
name?: string; /** The routing LLM. Required — a router with no model can't decide. */
|
|
46
|
+
model: ModelContract;
|
|
47
|
+
/**
|
|
48
|
+
* The intents the router chooses among. Same object you pass to
|
|
49
|
+
* `ai.supervisor({ intents })`. Their descriptions are rendered into
|
|
50
|
+
* the generated routing system prompt so the LLM knows what each
|
|
51
|
+
* option does.
|
|
52
|
+
*/
|
|
53
|
+
intents: RouterIntents;
|
|
54
|
+
/**
|
|
55
|
+
* Extra guidance prepended to the framework-generated routing system
|
|
56
|
+
* prompt. Use it for domain framing ("You coordinate a support
|
|
57
|
+
* team."); the mechanical "here are your options, emit `next`"
|
|
58
|
+
* scaffolding is appended automatically.
|
|
59
|
+
*/
|
|
60
|
+
systemPrompt?: SystemPromptContract | string; /** Placeholder values merged into the router's system prompt template. */
|
|
61
|
+
placeholders?: Placeholders; /** Base model call options forwarded to the underlying agent. */
|
|
62
|
+
modelOptions?: ModelCallOptions;
|
|
63
|
+
/**
|
|
64
|
+
* Hard cap on LLM trips for the router agent. A router is a
|
|
65
|
+
* single-shot decision maker, so this defaults to `1` — override
|
|
66
|
+
* only if the router itself calls tools mid-decision.
|
|
67
|
+
*/
|
|
68
|
+
maxTrips?: number; /** Factory-level event handlers forwarded to the underlying agent. */
|
|
69
|
+
on?: AgentEventHandlers;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Build a routing agent for `ai.supervisor({ router })` without
|
|
73
|
+
* hand-writing the output schema or the "pick one of these intents"
|
|
74
|
+
* system prompt.
|
|
75
|
+
*
|
|
76
|
+
* **What it does for you.**
|
|
77
|
+
* - Generates the canonical `{ next, reasoning }` output schema
|
|
78
|
+
* (baked onto the agent so it's a valid router standalone, and
|
|
79
|
+
* identical to what the supervisor injects per-turn) — the model is
|
|
80
|
+
* steered to emit a single intent name or the `END` sentinel.
|
|
81
|
+
* - Auto-builds a system prompt that lists every intent + its
|
|
82
|
+
* description + the reserved `END` value + terse routing rules, with
|
|
83
|
+
* any caller-supplied `systemPrompt` framing kept on top.
|
|
84
|
+
*
|
|
85
|
+
* The result is a plain {@link AgentContract}; pass it straight to
|
|
86
|
+
* `ai.supervisor({ router: ... })`. Because the supervisor also injects
|
|
87
|
+
* the same schema per-turn and prepends its own per-turn context
|
|
88
|
+
* message, the baked schema/prompt are belt-and-suspenders — they make
|
|
89
|
+
* the agent a correct router even when invoked directly.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* const intents = { triage, orderLookup, billingLookup, resolver };
|
|
93
|
+
*
|
|
94
|
+
* const supportRouter = ai.router({
|
|
95
|
+
* model,
|
|
96
|
+
* intents,
|
|
97
|
+
* systemPrompt: "You coordinate a customer-support team.",
|
|
98
|
+
* });
|
|
99
|
+
*
|
|
100
|
+
* const support = ai.supervisor({
|
|
101
|
+
* name: "customer-support",
|
|
102
|
+
* router: supportRouter,
|
|
103
|
+
* intents,
|
|
104
|
+
* maxIterations: 6,
|
|
105
|
+
* });
|
|
106
|
+
*/
|
|
107
|
+
declare function router(config: RouterConfig): AgentContract<RouterOutput>;
|
|
108
|
+
//#endregion
|
|
109
|
+
export { RouterConfig, RouterIntents, RouterOutput, router };
|
|
110
|
+
//# sourceMappingURL=router-factory.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router-factory.d.mts","names":[],"sources":["../../../../../../../@warlock.js/ai/src/supervisor/router-factory.ts"],"mappings":";;;;;;;;;;;AAiBA;;;;KAAY,YAAA;EAEJ,kEAAN,IAAA,EAAM,IAAI,EAED;EAAT,SAAA;AAAA;;;;AAa8D;AAShE;;;;;;KATY,aAAA,GAAgB,MAAM,SAAS,qBAAA;;;;;;;;KAS/B,YAAA;EAgBD;;;;;;EATT,IAAA,WA0BA;EAxBA,KAAA,EAAO,aAAA;EA0BF;;AAAkB;AAuCzB;;;EA1DE,OAAA,EAAS,aAAA;EA0DiD;;;;;;EAnD1D,YAAA,GAAe,oBAAA,WAmD2C;EAjD1D,YAAA,GAAe,YAAA,EAiDuD;EA/CtE,YAAA,GAAe,gBAAA;;;;;;EAMf,QAAA;EAEA,EAAA,GAAK,kBAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAuCS,MAAA,CAAO,MAAA,EAAQ,YAAA,GAAe,aAAA,CAAc,YAAA"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { agent } from "../agent/agent.mjs";
|
|
2
|
+
import { END } from "../contracts/end.type.mjs";
|
|
3
|
+
|
|
4
|
+
//#region ../@warlock.js/ai/src/supervisor/router-factory.ts
|
|
5
|
+
/**
|
|
6
|
+
* Build a routing agent for `ai.supervisor({ router })` without
|
|
7
|
+
* hand-writing the output schema or the "pick one of these intents"
|
|
8
|
+
* system prompt.
|
|
9
|
+
*
|
|
10
|
+
* **What it does for you.**
|
|
11
|
+
* - Generates the canonical `{ next, reasoning }` output schema
|
|
12
|
+
* (baked onto the agent so it's a valid router standalone, and
|
|
13
|
+
* identical to what the supervisor injects per-turn) — the model is
|
|
14
|
+
* steered to emit a single intent name or the `END` sentinel.
|
|
15
|
+
* - Auto-builds a system prompt that lists every intent + its
|
|
16
|
+
* description + the reserved `END` value + terse routing rules, with
|
|
17
|
+
* any caller-supplied `systemPrompt` framing kept on top.
|
|
18
|
+
*
|
|
19
|
+
* The result is a plain {@link AgentContract}; pass it straight to
|
|
20
|
+
* `ai.supervisor({ router: ... })`. Because the supervisor also injects
|
|
21
|
+
* the same schema per-turn and prepends its own per-turn context
|
|
22
|
+
* message, the baked schema/prompt are belt-and-suspenders — they make
|
|
23
|
+
* the agent a correct router even when invoked directly.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* const intents = { triage, orderLookup, billingLookup, resolver };
|
|
27
|
+
*
|
|
28
|
+
* const supportRouter = ai.router({
|
|
29
|
+
* model,
|
|
30
|
+
* intents,
|
|
31
|
+
* systemPrompt: "You coordinate a customer-support team.",
|
|
32
|
+
* });
|
|
33
|
+
*
|
|
34
|
+
* const support = ai.supervisor({
|
|
35
|
+
* name: "customer-support",
|
|
36
|
+
* router: supportRouter,
|
|
37
|
+
* intents,
|
|
38
|
+
* maxIterations: 6,
|
|
39
|
+
* });
|
|
40
|
+
*/
|
|
41
|
+
function router(config) {
|
|
42
|
+
if (!config.model) throw new TypeError("ai.router: `model` is required");
|
|
43
|
+
if (!config.intents || typeof config.intents !== "object") throw new TypeError("ai.router: `intents` is required and must be an object");
|
|
44
|
+
const intentNames = Object.keys(config.intents);
|
|
45
|
+
if (intentNames.length === 0) throw new TypeError("ai.router: `intents` must contain at least one entry");
|
|
46
|
+
const routingPrompt = buildRoutingSystemPrompt(config.intents, resolvePrefix(config.systemPrompt));
|
|
47
|
+
return agent({
|
|
48
|
+
name: config.name ?? "router",
|
|
49
|
+
description: "Routes a supervisor run to the next intent (or terminates it).",
|
|
50
|
+
model: config.model,
|
|
51
|
+
systemPrompt: routingPrompt,
|
|
52
|
+
output: routerOutputSchema(intentNames),
|
|
53
|
+
placeholders: config.placeholders,
|
|
54
|
+
modelOptions: config.modelOptions,
|
|
55
|
+
maxTrips: config.maxTrips ?? 1,
|
|
56
|
+
on: config.on
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Resolve a caller-supplied `systemPrompt` (string or contract) to
|
|
61
|
+
* plain text for prepending to the generated routing block. Returns
|
|
62
|
+
* `undefined` when none was supplied.
|
|
63
|
+
*/
|
|
64
|
+
function resolvePrefix(prompt) {
|
|
65
|
+
if (!prompt) return;
|
|
66
|
+
return typeof prompt === "string" ? prompt : prompt.resolve();
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Assemble the routing system prompt: optional caller framing on top,
|
|
70
|
+
* then the mechanical block listing every intent + description, the
|
|
71
|
+
* reserved `END` sentinel, and the rules for emitting `next`.
|
|
72
|
+
*/
|
|
73
|
+
function buildRoutingSystemPrompt(intents, prefix) {
|
|
74
|
+
const intentLines = Object.entries(intents).map(([name, value]) => {
|
|
75
|
+
const description = resolveIntentDescription(value);
|
|
76
|
+
return description ? `- ${name}: ${description}` : `- ${name}`;
|
|
77
|
+
});
|
|
78
|
+
const sections = [];
|
|
79
|
+
if (prefix && prefix.trim().length > 0) sections.push(prefix.trim(), "");
|
|
80
|
+
sections.push("You are a router. Pick the single best intent to handle the next step, or terminate the run.", "", "Available intents:", ...intentLines, "", "Reserved values:", `- ${END} = terminate the run when no further intent is needed`, "", "Rules:", "- Respond with the `next` field set to exactly one intent name from the list above, or the END sentinel.", "- Put a one-sentence justification in the `reasoning` field.", "- Never invent an intent name that is not listed.");
|
|
81
|
+
return sections.join("\n");
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Read the human-readable description off a supervisor-intent value,
|
|
85
|
+
* regardless of which accepted shape it is (bare agent / workflow,
|
|
86
|
+
* object entry with a `description` override, callback entry). Bare
|
|
87
|
+
* callbacks have no description source — returns `undefined`, and the
|
|
88
|
+
* prompt simply lists the intent by name.
|
|
89
|
+
*/
|
|
90
|
+
function resolveIntentDescription(value) {
|
|
91
|
+
if (!value || typeof value === "function") return;
|
|
92
|
+
const entry = value;
|
|
93
|
+
if (typeof entry.description === "string" && entry.description.trim().length > 0) return entry.description.trim();
|
|
94
|
+
const agentDescription = entry.agent?.description;
|
|
95
|
+
if (typeof agentDescription === "string" && agentDescription.trim().length > 0) return agentDescription.trim();
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Build the canonical router output Standard Schema. The same shape the
|
|
99
|
+
* supervisor injects per-turn — `{ next: string, reasoning: string }` —
|
|
100
|
+
* with the JSON Schema extension carrying the intent names as an `enum`
|
|
101
|
+
* (plus the `END` sentinel) so capable providers enforce the choice
|
|
102
|
+
* natively rather than via soft prompt coaching. Validation still
|
|
103
|
+
* accepts `string` / `string[]` for framework-level fan-out.
|
|
104
|
+
*/
|
|
105
|
+
function routerOutputSchema(intentNames) {
|
|
106
|
+
const jsonSchema = {
|
|
107
|
+
type: "object",
|
|
108
|
+
properties: {
|
|
109
|
+
next: {
|
|
110
|
+
type: "string",
|
|
111
|
+
enum: [...intentNames, END],
|
|
112
|
+
description: "Name of the intent to dispatch next, or the END sentinel to terminate."
|
|
113
|
+
},
|
|
114
|
+
reasoning: {
|
|
115
|
+
type: "string",
|
|
116
|
+
description: "One-sentence justification for the routing choice."
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
required: ["next", "reasoning"],
|
|
120
|
+
additionalProperties: false
|
|
121
|
+
};
|
|
122
|
+
return { "~standard": {
|
|
123
|
+
version: 1,
|
|
124
|
+
vendor: "warlock-router",
|
|
125
|
+
jsonSchema: { input: () => jsonSchema },
|
|
126
|
+
validate(value) {
|
|
127
|
+
if (!value || typeof value !== "object") return { issues: [{ message: "router output must be an object" }] };
|
|
128
|
+
const record = value;
|
|
129
|
+
const rawNext = record.next;
|
|
130
|
+
if (!(typeof rawNext === "string" || Array.isArray(rawNext) && rawNext.every((element) => typeof element === "string"))) return { issues: [{ message: "router output `next` must be a string, string[], or the END sentinel" }] };
|
|
131
|
+
return { value: {
|
|
132
|
+
next: rawNext,
|
|
133
|
+
reasoning: typeof record.reasoning === "string" ? record.reasoning : ""
|
|
134
|
+
} };
|
|
135
|
+
}
|
|
136
|
+
} };
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
//#endregion
|
|
140
|
+
export { router };
|
|
141
|
+
//# sourceMappingURL=router-factory.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router-factory.mjs","names":[],"sources":["../../../../../../../@warlock.js/ai/src/supervisor/router-factory.ts"],"sourcesContent":["import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport { agent } from \"../agent/agent\";\nimport type { AgentEventHandlers } from \"../agent/agent-config.type\";\nimport type { AgentContract } from \"../contracts/agent/agent.contract\";\nimport { END } from \"../contracts/end.type\";\nimport type { ModelCallOptions, ModelContract } from \"../contracts/model.contract\";\nimport type { Placeholders } from \"../contracts/placeholders.type\";\nimport type { SupervisorIntentValue } from \"../contracts/supervisor/intent-entry.type\";\nimport type { Next } from \"../contracts/supervisor/next.type\";\nimport type { SystemPromptContract } from \"../contracts/system-prompt.contract\";\n\n/**\n * Output shape every router agent produced by {@link router} emits —\n * the canonical `{ next, reasoning }` contract the supervisor's\n * dispatch loop reads. Exposed so callers can type a router result\n * they handle directly.\n */\nexport type RouterOutput = {\n /** Chosen intent name, a fan-out array, or the `END` sentinel. */\n next: Next;\n /** One-sentence justification for the routing choice. */\n reasoning: string;\n};\n\n/**\n * Description source for one intent the router can pick from. Accepts\n * the same value-shapes the supervisor's `intents` map does (bare\n * agent / workflow / callback / object entry) so a caller can pass the\n * very same `intents` object to both `router()` and `ai.supervisor()`.\n *\n * The router only needs each intent's NAME (the map key) and a\n * human-readable DESCRIPTION — it never dispatches anything itself, so\n * the underlying unit is read for its `description` only.\n */\nexport type RouterIntents = Record<string, SupervisorIntentValue>;\n\n/**\n * Config for {@link router}. Mirrors the relevant slice of `AgentConfig`\n * — the router IS an agent — plus the `intents` map it routes over.\n *\n * Everything except `model` and `intents` is optional; the helper\n * generates the output schema and the routing system prompt for you.\n */\nexport type RouterConfig = {\n /**\n * Stable identifier for the router agent. Defaults to\n * `\"<supervisor-ish>-router\"` is NOT assumed — when omitted the helper\n * uses `\"router\"` so the agent carries a meaningful (non-anonymous)\n * name, which `ai.supervisor({ router })` is happy to accept.\n */\n name?: string;\n /** The routing LLM. Required — a router with no model can't decide. */\n model: ModelContract;\n /**\n * The intents the router chooses among. Same object you pass to\n * `ai.supervisor({ intents })`. Their descriptions are rendered into\n * the generated routing system prompt so the LLM knows what each\n * option does.\n */\n intents: RouterIntents;\n /**\n * Extra guidance prepended to the framework-generated routing system\n * prompt. Use it for domain framing (\"You coordinate a support\n * team.\"); the mechanical \"here are your options, emit `next`\"\n * scaffolding is appended automatically.\n */\n systemPrompt?: SystemPromptContract | string;\n /** Placeholder values merged into the router's system prompt template. */\n placeholders?: Placeholders;\n /** Base model call options forwarded to the underlying agent. */\n modelOptions?: ModelCallOptions;\n /**\n * Hard cap on LLM trips for the router agent. A router is a\n * single-shot decision maker, so this defaults to `1` — override\n * only if the router itself calls tools mid-decision.\n */\n maxTrips?: number;\n /** Factory-level event handlers forwarded to the underlying agent. */\n on?: AgentEventHandlers;\n};\n\n/**\n * Build a routing agent for `ai.supervisor({ router })` without\n * hand-writing the output schema or the \"pick one of these intents\"\n * system prompt.\n *\n * **What it does for you.**\n * - Generates the canonical `{ next, reasoning }` output schema\n * (baked onto the agent so it's a valid router standalone, and\n * identical to what the supervisor injects per-turn) — the model is\n * steered to emit a single intent name or the `END` sentinel.\n * - Auto-builds a system prompt that lists every intent + its\n * description + the reserved `END` value + terse routing rules, with\n * any caller-supplied `systemPrompt` framing kept on top.\n *\n * The result is a plain {@link AgentContract}; pass it straight to\n * `ai.supervisor({ router: ... })`. Because the supervisor also injects\n * the same schema per-turn and prepends its own per-turn context\n * message, the baked schema/prompt are belt-and-suspenders — they make\n * the agent a correct router even when invoked directly.\n *\n * @example\n * const intents = { triage, orderLookup, billingLookup, resolver };\n *\n * const supportRouter = ai.router({\n * model,\n * intents,\n * systemPrompt: \"You coordinate a customer-support team.\",\n * });\n *\n * const support = ai.supervisor({\n * name: \"customer-support\",\n * router: supportRouter,\n * intents,\n * maxIterations: 6,\n * });\n */\nexport function router(config: RouterConfig): AgentContract<RouterOutput> {\n if (!config.model) {\n throw new TypeError(\"ai.router: `model` is required\");\n }\n\n if (!config.intents || typeof config.intents !== \"object\") {\n throw new TypeError(\"ai.router: `intents` is required and must be an object\");\n }\n\n const intentNames = Object.keys(config.intents);\n\n if (intentNames.length === 0) {\n throw new TypeError(\"ai.router: `intents` must contain at least one entry\");\n }\n\n const routingPrompt = buildRoutingSystemPrompt(config.intents, resolvePrefix(config.systemPrompt));\n\n return agent<RouterOutput>({\n name: config.name ?? \"router\",\n description: \"Routes a supervisor run to the next intent (or terminates it).\",\n model: config.model,\n systemPrompt: routingPrompt,\n output: routerOutputSchema(intentNames),\n placeholders: config.placeholders,\n modelOptions: config.modelOptions,\n maxTrips: config.maxTrips ?? 1,\n on: config.on,\n });\n}\n\n/**\n * Resolve a caller-supplied `systemPrompt` (string or contract) to\n * plain text for prepending to the generated routing block. Returns\n * `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\n/**\n * Assemble the routing system prompt: optional caller framing on top,\n * then the mechanical block listing every intent + description, the\n * reserved `END` sentinel, and the rules for emitting `next`.\n */\nfunction buildRoutingSystemPrompt(intents: RouterIntents, prefix: string | undefined): string {\n const intentLines = Object.entries(intents).map(([name, value]) => {\n const description = resolveIntentDescription(value);\n\n return description ? `- ${name}: ${description}` : `- ${name}`;\n });\n\n const sections: string[] = [];\n\n if (prefix && prefix.trim().length > 0) {\n sections.push(prefix.trim(), \"\");\n }\n\n sections.push(\n \"You are a router. Pick the single best intent to handle the next step, or terminate the run.\",\n \"\",\n \"Available intents:\",\n ...intentLines,\n \"\",\n \"Reserved values:\",\n `- ${END} = terminate the run when no further intent is needed`,\n \"\",\n \"Rules:\",\n \"- Respond with the `next` field set to exactly one intent name from the list above, or the END sentinel.\",\n \"- Put a one-sentence justification in the `reasoning` field.\",\n \"- Never invent an intent name that is not listed.\",\n );\n\n return sections.join(\"\\n\");\n}\n\n/**\n * Read the human-readable description off a supervisor-intent value,\n * regardless of which accepted shape it is (bare agent / workflow,\n * object entry with a `description` override, callback entry). Bare\n * callbacks have no description source — returns `undefined`, and the\n * prompt simply lists the intent by name.\n */\nfunction resolveIntentDescription(value: SupervisorIntentValue): string | undefined {\n if (!value || typeof value === \"function\") {\n return undefined;\n }\n\n const entry = value as {\n description?: unknown;\n agent?: { description?: unknown };\n };\n\n if (typeof entry.description === \"string\" && entry.description.trim().length > 0) {\n return entry.description.trim();\n }\n\n const agentDescription = entry.agent?.description;\n\n if (typeof agentDescription === \"string\" && agentDescription.trim().length > 0) {\n return agentDescription.trim();\n }\n\n return undefined;\n}\n\n/**\n * Build the canonical router output Standard Schema. The same shape the\n * supervisor injects per-turn — `{ next: string, reasoning: string }` —\n * with the JSON Schema extension carrying the intent names as an `enum`\n * (plus the `END` sentinel) so capable providers enforce the choice\n * natively rather than via soft prompt coaching. Validation still\n * accepts `string` / `string[]` for framework-level fan-out.\n */\nfunction routerOutputSchema(intentNames: string[]): StandardSchemaV1<RouterOutput> {\n const nextEnum = [...intentNames, END];\n\n const jsonSchema = {\n type: \"object\",\n properties: {\n next: {\n type: \"string\",\n enum: nextEnum,\n description: \"Name of the intent to dispatch next, or the END sentinel to terminate.\",\n },\n reasoning: {\n type: \"string\",\n description: \"One-sentence justification for the routing choice.\",\n },\n },\n required: [\"next\", \"reasoning\"],\n additionalProperties: false,\n };\n\n return {\n \"~standard\": {\n version: 1,\n vendor: \"warlock-router\",\n jsonSchema: {\n input: () => jsonSchema,\n },\n validate(value: unknown): StandardSchemaV1.Result<RouterOutput> {\n if (!value || typeof value !== \"object\") {\n return { issues: [{ message: \"router output must be an object\" }] };\n }\n\n const record = value as { next?: unknown; reasoning?: unknown };\n const rawNext = record.next;\n\n const nextIsValid =\n typeof rawNext === \"string\" ||\n (Array.isArray(rawNext) && rawNext.every((element) => typeof element === \"string\"));\n\n if (!nextIsValid) {\n return {\n issues: [\n { message: \"router output `next` must be a string, string[], or the END sentinel\" },\n ],\n };\n }\n\n const reasoning = typeof record.reasoning === \"string\" ? record.reasoning : \"\";\n\n return {\n value: { next: rawNext as Next, reasoning },\n };\n },\n } as StandardSchemaV1<RouterOutput>[\"~standard\"] & {\n jsonSchema: { input: () => Record<string, unknown> };\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqHA,SAAgB,OAAO,QAAmD;CACxE,IAAI,CAAC,OAAO,OACV,MAAM,IAAI,UAAU,gCAAgC;CAGtD,IAAI,CAAC,OAAO,WAAW,OAAO,OAAO,YAAY,UAC/C,MAAM,IAAI,UAAU,wDAAwD;CAG9E,MAAM,cAAc,OAAO,KAAK,OAAO,OAAO;CAE9C,IAAI,YAAY,WAAW,GACzB,MAAM,IAAI,UAAU,sDAAsD;CAG5E,MAAM,gBAAgB,yBAAyB,OAAO,SAAS,cAAc,OAAO,YAAY,CAAC;CAEjG,OAAO,MAAoB;EACzB,MAAM,OAAO,QAAQ;EACrB,aAAa;EACb,OAAO,OAAO;EACd,cAAc;EACd,QAAQ,mBAAmB,WAAW;EACtC,cAAc,OAAO;EACrB,cAAc,OAAO;EACrB,UAAU,OAAO,YAAY;EAC7B,IAAI,OAAO;CACb,CAAC;AACH;;;;;;AAOA,SAAS,cAAc,QAAuE;CAC5F,IAAI,CAAC,QACH;CAGF,OAAO,OAAO,WAAW,WAAW,SAAS,OAAO,QAAQ;AAC9D;;;;;;AAOA,SAAS,yBAAyB,SAAwB,QAAoC;CAC5F,MAAM,cAAc,OAAO,QAAQ,OAAO,CAAC,CAAC,KAAK,CAAC,MAAM,WAAW;EACjE,MAAM,cAAc,yBAAyB,KAAK;EAElD,OAAO,cAAc,KAAK,KAAK,IAAI,gBAAgB,KAAK;CAC1D,CAAC;CAED,MAAM,WAAqB,CAAC;CAE5B,IAAI,UAAU,OAAO,KAAK,CAAC,CAAC,SAAS,GACnC,SAAS,KAAK,OAAO,KAAK,GAAG,EAAE;CAGjC,SAAS,KACP,gGACA,IACA,sBACA,GAAG,aACH,IACA,oBACA,KAAK,IAAI,wDACT,IACA,UACA,4GACA,gEACA,mDACF;CAEA,OAAO,SAAS,KAAK,IAAI;AAC3B;;;;;;;;AASA,SAAS,yBAAyB,OAAkD;CAClF,IAAI,CAAC,SAAS,OAAO,UAAU,YAC7B;CAGF,MAAM,QAAQ;CAKd,IAAI,OAAO,MAAM,gBAAgB,YAAY,MAAM,YAAY,KAAK,CAAC,CAAC,SAAS,GAC7E,OAAO,MAAM,YAAY,KAAK;CAGhC,MAAM,mBAAmB,MAAM,OAAO;CAEtC,IAAI,OAAO,qBAAqB,YAAY,iBAAiB,KAAK,CAAC,CAAC,SAAS,GAC3E,OAAO,iBAAiB,KAAK;AAIjC;;;;;;;;;AAUA,SAAS,mBAAmB,aAAuD;CAGjF,MAAM,aAAa;EACjB,MAAM;EACN,YAAY;GACV,MAAM;IACJ,MAAM;IACN,MAAM,CAPM,GAAG,aAAa,GAOf;IACb,aAAa;GACf;GACA,WAAW;IACT,MAAM;IACN,aAAa;GACf;EACF;EACA,UAAU,CAAC,QAAQ,WAAW;EAC9B,sBAAsB;CACxB;CAEA,OAAO,EACL,aAAa;EACX,SAAS;EACT,QAAQ;EACR,YAAY,EACV,aAAa,WACf;EACA,SAAS,OAAuD;GAC9D,IAAI,CAAC,SAAS,OAAO,UAAU,UAC7B,OAAO,EAAE,QAAQ,CAAC,EAAE,SAAS,kCAAkC,CAAC,EAAE;GAGpE,MAAM,SAAS;GACf,MAAM,UAAU,OAAO;GAMvB,IAAI,EAHF,OAAO,YAAY,YAClB,MAAM,QAAQ,OAAO,KAAK,QAAQ,OAAO,YAAY,OAAO,YAAY,QAAQ,IAGjF,OAAO,EACL,QAAQ,CACN,EAAE,SAAS,uEAAuE,CACpF,EACF;GAKF,OAAO,EACL,OAAO;IAAE,MAAM;IAAiB,WAHhB,OAAO,OAAO,cAAc,WAAW,OAAO,YAAY;GAGhC,EAC5C;EACF;CACF,EAGF;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { IterationSnapshot } from "../contracts/supervisor/iteration-snapshot.type.mjs";
|
|
2
1
|
import { SupervisorInput } from "../contracts/supervisor/supervisor-input.type.mjs";
|
|
2
|
+
import { IterationSnapshot } from "../contracts/supervisor/iteration-snapshot.type.mjs";
|
|
3
3
|
import { ResolvedIntentEntry } from "./entries.mjs";
|
|
4
4
|
|
|
5
5
|
//#region ../@warlock.js/ai/src/supervisor/router-prompt.d.ts
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { IterationSnapshot } from "../contracts/supervisor/iteration-snapshot.type.mjs";
|
|
2
1
|
import { SupervisorInput } from "../contracts/supervisor/supervisor-input.type.mjs";
|
|
3
|
-
import { SupervisorConfig } from "../contracts/supervisor/supervisor-config.type.mjs";
|
|
4
|
-
import { SupervisorResumeOptions } from "../contracts/supervisor/supervisor-execute-options.type.mjs";
|
|
5
2
|
import { SupervisorSnapshot, SupervisorSnapshotStatus } from "../contracts/supervisor/supervisor-snapshot.type.mjs";
|
|
3
|
+
import { SupervisorResumeOptions } from "../contracts/supervisor/supervisor-execute-options.type.mjs";
|
|
4
|
+
import { SupervisorConfig } from "../contracts/supervisor/supervisor-config.type.mjs";
|
|
5
|
+
import { IterationSnapshot } from "../contracts/supervisor/iteration-snapshot.type.mjs";
|
|
6
6
|
|
|
7
7
|
//#region ../@warlock.js/ai/src/supervisor/snapshot.d.ts
|
|
8
8
|
type PersistParams = {
|
|
@@ -43,12 +43,6 @@ declare function loadSnapshotForResume(params: {
|
|
|
43
43
|
runId: string;
|
|
44
44
|
options?: SupervisorResumeOptions;
|
|
45
45
|
}): Promise<SupervisorSnapshot>;
|
|
46
|
-
/**
|
|
47
|
-
* Canonical key shape used in the KVStore. Prefixed so supervisor
|
|
48
|
-
* snapshots don't collide with workflow / session snapshots in a
|
|
49
|
-
* shared store.
|
|
50
|
-
*/
|
|
51
|
-
declare function snapshotKey(runId: string): string;
|
|
52
46
|
//#endregion
|
|
53
|
-
export { loadSnapshotForResume, persistSupervisorSnapshot
|
|
47
|
+
export { loadSnapshotForResume, persistSupervisorSnapshot };
|
|
54
48
|
//# sourceMappingURL=snapshot.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snapshot.d.mts","names":[],"sources":["../../../../../../../@warlock.js/ai/src/supervisor/snapshot.ts"],"mappings":";;;;;;;KAoBY,aAAA;EACV,MAAA,EAAQ,gBAAA;EACR,SAAA;EACA,KAAA;EACA,KAAA,EAAO,eAAA;EACP,SAAA;EACA,SAAA;EACA,SAAA,EAAW,iBAAA;EACX,MAAA,EAAQ,wBAAA;AAAA;AAAA,KAGE,cAAA;EAAmB,EAAA;AAAA;EAAe,EAAA;EAAW,KAAA;AAAA;;;;;;;;;iBAUnC,yBAAA,CACpB,MAAA,EAAQ,aAAA,GACP,OAAA,CAAQ,cAAA;AAZX;;;;;;;AAAA,iBA+CsB,qBAAA,CAAsB,MAAA;EAC1C,MAAA,EAAQ,gBAAA;EACR,SAAA;EACA,KAAA;EACA,OAAA,GAAU,uBAAA;AAAA,IACR,OAAA,CAAQ,kBAAA
|
|
1
|
+
{"version":3,"file":"snapshot.d.mts","names":[],"sources":["../../../../../../../@warlock.js/ai/src/supervisor/snapshot.ts"],"mappings":";;;;;;;KAoBY,aAAA;EACV,MAAA,EAAQ,gBAAA;EACR,SAAA;EACA,KAAA;EACA,KAAA,EAAO,eAAA;EACP,SAAA;EACA,SAAA;EACA,SAAA,EAAW,iBAAA;EACX,MAAA,EAAQ,wBAAA;AAAA;AAAA,KAGE,cAAA;EAAmB,EAAA;AAAA;EAAe,EAAA;EAAW,KAAA;AAAA;;;;;;;;;iBAUnC,yBAAA,CACpB,MAAA,EAAQ,aAAA,GACP,OAAA,CAAQ,cAAA;AAZX;;;;;;;AAAA,iBA+CsB,qBAAA,CAAsB,MAAA;EAC1C,MAAA,EAAQ,gBAAA;EACR,SAAA;EACA,KAAA;EACA,OAAA,GAAU,uBAAA;AAAA,IACR,OAAA,CAAQ,kBAAA"}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { SupervisorFailedError } from "../errors/supervisor-failed-error.mjs";
|
|
2
2
|
import { SupervisorDriftError } from "../errors/supervisor-drift-error.mjs";
|
|
3
3
|
import "../errors/index.mjs";
|
|
4
|
-
import {
|
|
4
|
+
import { resolveDefaultSnapshotStore } from "../config.mjs";
|
|
5
5
|
|
|
6
6
|
//#region ../@warlock.js/ai/src/supervisor/snapshot.ts
|
|
7
7
|
/**
|
|
8
|
-
* Resolve the effective
|
|
8
|
+
* Resolve the effective {@link SnapshotStore}: the supervisor's own
|
|
9
9
|
* `snapshotStore` field wins; absent that, fall back to the global
|
|
10
|
-
* default set via `ai.config({
|
|
10
|
+
* default set via `ai.config({ defaultSnapshotStore })`.
|
|
11
11
|
*/
|
|
12
12
|
function resolveSnapshotStore(config) {
|
|
13
|
-
return config.snapshotStore ??
|
|
13
|
+
return config.snapshotStore ?? resolveDefaultSnapshotStore();
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
16
|
* Write the current run state to the resolved snapshot store. No-op
|
|
@@ -35,7 +35,7 @@ async function persistSupervisorSnapshot(params) {
|
|
|
35
35
|
savedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
36
36
|
};
|
|
37
37
|
try {
|
|
38
|
-
await store.
|
|
38
|
+
await store.save(snapshot);
|
|
39
39
|
return { ok: true };
|
|
40
40
|
} catch (error) {
|
|
41
41
|
return {
|
|
@@ -53,8 +53,8 @@ async function persistSupervisorSnapshot(params) {
|
|
|
53
53
|
*/
|
|
54
54
|
async function loadSnapshotForResume(params) {
|
|
55
55
|
const store = resolveSnapshotStore(params.config);
|
|
56
|
-
if (!store) throw new SupervisorFailedError(`supervisor "${params.config.name}" has no store configured — set \`snapshotStore\` on the config or call \`ai.config({
|
|
57
|
-
const snapshot = await store.
|
|
56
|
+
if (!store) throw new SupervisorFailedError(`supervisor "${params.config.name}" has no store configured — set \`snapshotStore\` on the config or call \`ai.config({ defaultSnapshotStore })\` at boot before calling resume()`, { context: { runId: params.runId } });
|
|
57
|
+
const snapshot = await store.load(params.runId) ?? null;
|
|
58
58
|
if (!snapshot) throw new SupervisorFailedError(`supervisor "${params.config.name}": no snapshot for runId "${params.runId}"`, { context: { runId: params.runId } });
|
|
59
59
|
if (!params.options?.force && snapshot.signature !== params.signature) throw new SupervisorDriftError(`supervisor "${params.config.name}" signature drift on resume`, {
|
|
60
60
|
savedSignature: snapshot.signature,
|
|
@@ -63,15 +63,7 @@ async function loadSnapshotForResume(params) {
|
|
|
63
63
|
});
|
|
64
64
|
return snapshot;
|
|
65
65
|
}
|
|
66
|
-
/**
|
|
67
|
-
* Canonical key shape used in the KVStore. Prefixed so supervisor
|
|
68
|
-
* snapshots don't collide with workflow / session snapshots in a
|
|
69
|
-
* shared store.
|
|
70
|
-
*/
|
|
71
|
-
function snapshotKey(runId) {
|
|
72
|
-
return `supervisor:${runId}`;
|
|
73
|
-
}
|
|
74
66
|
|
|
75
67
|
//#endregion
|
|
76
|
-
export { loadSnapshotForResume, persistSupervisorSnapshot
|
|
68
|
+
export { loadSnapshotForResume, persistSupervisorSnapshot };
|
|
77
69
|
//# sourceMappingURL=snapshot.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snapshot.mjs","names":[],"sources":["../../../../../../../@warlock.js/ai/src/supervisor/snapshot.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"snapshot.mjs","names":[],"sources":["../../../../../../../@warlock.js/ai/src/supervisor/snapshot.ts"],"sourcesContent":["import { resolveDefaultSnapshotStore } from \"../config\";\nimport type { IterationSnapshot } from \"../contracts/supervisor/iteration-snapshot.type\";\nimport type { SupervisorConfig } from \"../contracts/supervisor/supervisor-config.type\";\nimport type { SupervisorResumeOptions } from \"../contracts/supervisor/supervisor-execute-options.type\";\nimport type { SupervisorInput } from \"../contracts/supervisor/supervisor-input.type\";\nimport type {\n SupervisorSnapshot,\n SupervisorSnapshotStatus,\n} from \"../contracts/supervisor/supervisor-snapshot.type\";\nimport { SupervisorDriftError, SupervisorFailedError } from \"../errors\";\n\n/**\n * Resolve the effective {@link SnapshotStore}: the supervisor's own\n * `snapshotStore` field wins; absent that, fall back to the global\n * default set via `ai.config({ defaultSnapshotStore })`.\n */\nfunction resolveSnapshotStore(config: SupervisorConfig<unknown>) {\n return config.snapshotStore ?? resolveDefaultSnapshotStore();\n}\n\nexport type PersistParams = {\n config: SupervisorConfig<unknown>;\n signature: string;\n runId: string;\n input: SupervisorInput;\n startedAt: string;\n iteration: number;\n snapshots: IterationSnapshot[];\n status: SupervisorSnapshotStatus;\n};\n\nexport type PersistOutcome = { ok: true } | { ok: false; error: unknown };\n\n/**\n * Write the current run state to the resolved snapshot store. No-op\n * (ok) when neither the supervisor's `snapshotStore` nor the global\n * `defaultStore` is configured. Failures are returned as\n * `{ ok: false }` rather than thrown so the engine can surface them\n * via events/logs without aborting the run — callers decide whether\n * a failed checkpoint is fatal.\n */\nexport async function persistSupervisorSnapshot(\n params: PersistParams,\n): Promise<PersistOutcome> {\n const store = resolveSnapshotStore(params.config);\n\n if (!store) {\n return { ok: true };\n }\n\n const snapshot: SupervisorSnapshot = {\n runId: params.runId,\n supervisorName: params.config.name,\n signature: params.signature,\n input: params.input,\n iteration: params.iteration,\n snapshots: params.snapshots,\n status: params.status,\n startedAt: params.startedAt,\n savedAt: new Date().toISOString(),\n };\n\n try {\n await store.save(snapshot);\n\n return { ok: true };\n } catch (error) {\n return { ok: false, error };\n }\n}\n\n/**\n * Load a persisted snapshot for `resume()` and run the drift check.\n * Throws `SupervisorFailedError` when no store is configured or when\n * the run is missing; throws `SupervisorDriftError` when the stored\n * signature doesn't match the current definition (unless `force` is\n * set).\n */\nexport async function loadSnapshotForResume(params: {\n config: SupervisorConfig<unknown>;\n signature: string;\n runId: string;\n options?: SupervisorResumeOptions;\n}): Promise<SupervisorSnapshot> {\n const store = resolveSnapshotStore(params.config);\n\n if (!store) {\n throw new SupervisorFailedError(\n `supervisor \"${params.config.name}\" has no store configured — set \\`snapshotStore\\` on the config or call \\`ai.config({ defaultSnapshotStore })\\` at boot before calling resume()`,\n { context: { runId: params.runId } },\n );\n }\n\n const snapshot = (await store.load(params.runId)) ?? null;\n\n if (!snapshot) {\n throw new SupervisorFailedError(\n `supervisor \"${params.config.name}\": no snapshot for runId \"${params.runId}\"`,\n { context: { runId: params.runId } },\n );\n }\n\n if (!params.options?.force && snapshot.signature !== params.signature) {\n throw new SupervisorDriftError(\n `supervisor \"${params.config.name}\" signature drift on resume`,\n {\n savedSignature: snapshot.signature,\n currentSignature: params.signature,\n runId: params.runId,\n },\n );\n }\n\n return snapshot;\n}\n"],"mappings":";;;;;;;;;;;AAgBA,SAAS,qBAAqB,QAAmC;CAC/D,OAAO,OAAO,iBAAiB,4BAA4B;AAC7D;;;;;;;;;AAuBA,eAAsB,0BACpB,QACyB;CACzB,MAAM,QAAQ,qBAAqB,OAAO,MAAM;CAEhD,IAAI,CAAC,OACH,OAAO,EAAE,IAAI,KAAK;CAGpB,MAAM,WAA+B;EACnC,OAAO,OAAO;EACd,gBAAgB,OAAO,OAAO;EAC9B,WAAW,OAAO;EAClB,OAAO,OAAO;EACd,WAAW,OAAO;EAClB,WAAW,OAAO;EAClB,QAAQ,OAAO;EACf,WAAW,OAAO;EAClB,0BAAS,IAAI,KAAK,EAAC,CAAC,YAAY;CAClC;CAEA,IAAI;EACF,MAAM,MAAM,KAAK,QAAQ;EAEzB,OAAO,EAAE,IAAI,KAAK;CACpB,SAAS,OAAO;EACd,OAAO;GAAE,IAAI;GAAO;EAAM;CAC5B;AACF;;;;;;;;AASA,eAAsB,sBAAsB,QAKZ;CAC9B,MAAM,QAAQ,qBAAqB,OAAO,MAAM;CAEhD,IAAI,CAAC,OACH,MAAM,IAAI,sBACR,eAAe,OAAO,OAAO,KAAK,kJAClC,EAAE,SAAS,EAAE,OAAO,OAAO,MAAM,EAAE,CACrC;CAGF,MAAM,WAAY,MAAM,MAAM,KAAK,OAAO,KAAK,KAAM;CAErD,IAAI,CAAC,UACH,MAAM,IAAI,sBACR,eAAe,OAAO,OAAO,KAAK,4BAA4B,OAAO,MAAM,IAC3E,EAAE,SAAS,EAAE,OAAO,OAAO,MAAM,EAAE,CACrC;CAGF,IAAI,CAAC,OAAO,SAAS,SAAS,SAAS,cAAc,OAAO,WAC1D,MAAM,IAAI,qBACR,eAAe,OAAO,OAAO,KAAK,8BAClC;EACE,gBAAgB,SAAS;EACzB,kBAAkB,OAAO;EACzB,OAAO,OAAO;CAChB,CACF;CAGF,OAAO;AACT"}
|