@warlock.js/ai 4.2.11 → 4.4.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 +68 -1
- package/cjs/index.cjs +10155 -4626
- 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 +88 -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 +143 -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 +2 -2
- package/esm/contracts/result/supervisor-result.type.d.mts.map +1 -1
- package/esm/contracts/result/tool-call.type.d.mts +2 -2
- package/esm/contracts/result/tool-call.type.d.mts.map +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/result/workflow-result.type.d.mts +1 -1
- package/esm/contracts/result/workflow-result.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 +120 -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,63 @@
|
|
|
1
|
+
import { RouteContext } from "../contracts/supervisor/route-context.type.mjs";
|
|
2
|
+
import { Next } from "../contracts/supervisor/next.type.mjs";
|
|
3
|
+
|
|
4
|
+
//#region ../@warlock.js/ai/src/mock/mock-router.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* A canned routing decision for {@link mockRouter}. Either a literal
|
|
7
|
+
* {@link Next} value (intent key, fan-out array, or the `END`
|
|
8
|
+
* sentinel) or a predicate that derives the decision from the live
|
|
9
|
+
* {@link RouteContext} — the latter lets a test branch on accumulated
|
|
10
|
+
* state without scripting an exact per-iteration sequence.
|
|
11
|
+
*/
|
|
12
|
+
type MockRouterDecision<TState = Record<string, unknown>> = Next | ((context: RouteContext<TState>) => Next);
|
|
13
|
+
/**
|
|
14
|
+
* Behavior when the canned decision queue is exhausted before the
|
|
15
|
+
* supervisor terminates on its own.
|
|
16
|
+
*
|
|
17
|
+
* - `"end"` (default) — return `END`, terminating the run cleanly. The
|
|
18
|
+
* common case: script the interesting turns, let the run stop.
|
|
19
|
+
* - `"throw"` — throw, surfacing the over-run as a test failure. Use
|
|
20
|
+
* when every iteration must be accounted for.
|
|
21
|
+
* - `"repeat"` — replay the last decision for every further iteration.
|
|
22
|
+
* Useful for "keep routing to the same intent until evaluate is
|
|
23
|
+
* satisfied" scenarios.
|
|
24
|
+
*/
|
|
25
|
+
type MockRouterExhaustion = "end" | "throw" | "repeat";
|
|
26
|
+
/**
|
|
27
|
+
* Options for {@link mockRouter}.
|
|
28
|
+
*/
|
|
29
|
+
type MockRouterOptions = {
|
|
30
|
+
/** What to do once the decision queue is exhausted. Default `"end"`. */onExhausted?: MockRouterExhaustion;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Build a deterministic `route` callback that replays a canned
|
|
34
|
+
* sequence of routing decisions — one per supervisor iteration — for
|
|
35
|
+
* testing supervisors without an LLM router.
|
|
36
|
+
*
|
|
37
|
+
* Drop the returned callback into `ai.supervisor({ route: mockRouter([...]) })`
|
|
38
|
+
* in place of an LLM `router`. The Nth iteration consumes the Nth
|
|
39
|
+
* decision; a function decision is evaluated against the live
|
|
40
|
+
* `RouteContext`. When the queue runs out, behavior follows
|
|
41
|
+
* `options.onExhausted` (default: terminate with `END`).
|
|
42
|
+
*
|
|
43
|
+
* Pairs with the `toRouteTo` / `toConverge` matchers to assert the
|
|
44
|
+
* resulting report tree.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* const supervisor = ai.supervisor({
|
|
48
|
+
* name: "draft-then-review",
|
|
49
|
+
* intents: { writer, critic },
|
|
50
|
+
* route: mockRouter(["writer", "critic", END]),
|
|
51
|
+
* });
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* // Branch on accumulated state, repeat the last decision until done.
|
|
55
|
+
* route: mockRouter(
|
|
56
|
+
* ["research", (ctx) => (ctx.state.summary ? END : "research")],
|
|
57
|
+
* { onExhausted: "repeat" },
|
|
58
|
+
* );
|
|
59
|
+
*/
|
|
60
|
+
declare function mockRouter<TState = Record<string, unknown>>(decisions: MockRouterDecision<TState>[], options?: MockRouterOptions): (context: RouteContext<TState>) => Next;
|
|
61
|
+
//#endregion
|
|
62
|
+
export { MockRouterDecision, MockRouterExhaustion, MockRouterOptions, mockRouter };
|
|
63
|
+
//# sourceMappingURL=mock-router.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mock-router.d.mts","names":[],"sources":["../../../../../../../@warlock.js/ai/src/mock/mock-router.ts"],"mappings":";;;;;;AAWA;;;;;KAAY,kBAAA,UAA4B,MAAA,qBACpC,IAAA,KACE,OAAA,EAAS,YAAA,CAAa,MAAA,MAAY,IAAA;;;;;;;;;;;;;KAc5B,oBAAA;AAAZ;;;AAAA,KAKY,iBAAA;EALoB,wEAO9B,WAAA,GAAc,oBAAoB;AAAA;;;AAAA;AA+BpC;;;;;;;;;;;;;;;;;;;;;;;;AAG0C;iBAH1B,UAAA,UAAoB,MAAA,mBAClC,SAAA,EAAW,kBAAA,CAAmB,MAAA,KAC9B,OAAA,GAAS,iBAAA,IACP,OAAA,EAAS,YAAA,CAAa,MAAA,MAAY,IAAA"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { END } from "../contracts/end.type.mjs";
|
|
2
|
+
|
|
3
|
+
//#region ../@warlock.js/ai/src/mock/mock-router.ts
|
|
4
|
+
/**
|
|
5
|
+
* Build a deterministic `route` callback that replays a canned
|
|
6
|
+
* sequence of routing decisions — one per supervisor iteration — for
|
|
7
|
+
* testing supervisors without an LLM router.
|
|
8
|
+
*
|
|
9
|
+
* Drop the returned callback into `ai.supervisor({ route: mockRouter([...]) })`
|
|
10
|
+
* in place of an LLM `router`. The Nth iteration consumes the Nth
|
|
11
|
+
* decision; a function decision is evaluated against the live
|
|
12
|
+
* `RouteContext`. When the queue runs out, behavior follows
|
|
13
|
+
* `options.onExhausted` (default: terminate with `END`).
|
|
14
|
+
*
|
|
15
|
+
* Pairs with the `toRouteTo` / `toConverge` matchers to assert the
|
|
16
|
+
* resulting report tree.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* const supervisor = ai.supervisor({
|
|
20
|
+
* name: "draft-then-review",
|
|
21
|
+
* intents: { writer, critic },
|
|
22
|
+
* route: mockRouter(["writer", "critic", END]),
|
|
23
|
+
* });
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* // Branch on accumulated state, repeat the last decision until done.
|
|
27
|
+
* route: mockRouter(
|
|
28
|
+
* ["research", (ctx) => (ctx.state.summary ? END : "research")],
|
|
29
|
+
* { onExhausted: "repeat" },
|
|
30
|
+
* );
|
|
31
|
+
*/
|
|
32
|
+
function mockRouter(decisions, options = {}) {
|
|
33
|
+
const onExhausted = options.onExhausted ?? "end";
|
|
34
|
+
let cursor = 0;
|
|
35
|
+
return (context) => {
|
|
36
|
+
if (cursor < decisions.length) {
|
|
37
|
+
const decision = decisions[cursor];
|
|
38
|
+
cursor++;
|
|
39
|
+
return resolveDecision(decision, context);
|
|
40
|
+
}
|
|
41
|
+
if (onExhausted === "throw") throw new Error(`mockRouter exhausted after ${decisions.length} decision(s) at iteration ${context.iteration}`);
|
|
42
|
+
if (onExhausted === "repeat" && decisions.length > 0) return resolveDecision(decisions[decisions.length - 1], context);
|
|
43
|
+
return END;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Resolve a single decision entry into a concrete {@link Next} —
|
|
48
|
+
* invoking the predicate form against the live context, or returning
|
|
49
|
+
* the literal form verbatim.
|
|
50
|
+
*/
|
|
51
|
+
function resolveDecision(decision, context) {
|
|
52
|
+
if (typeof decision === "function") return decision(context);
|
|
53
|
+
return decision;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
//#endregion
|
|
57
|
+
export { mockRouter };
|
|
58
|
+
//# sourceMappingURL=mock-router.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mock-router.mjs","names":[],"sources":["../../../../../../../@warlock.js/ai/src/mock/mock-router.ts"],"sourcesContent":["import { END } from \"../contracts/end.type\";\nimport type { Next } from \"../contracts/supervisor/next.type\";\nimport type { RouteContext } from \"../contracts/supervisor/route-context.type\";\n\n/**\n * A canned routing decision for {@link mockRouter}. Either a literal\n * {@link Next} value (intent key, fan-out array, or the `END`\n * sentinel) or a predicate that derives the decision from the live\n * {@link RouteContext} — the latter lets a test branch on accumulated\n * state without scripting an exact per-iteration sequence.\n */\nexport type MockRouterDecision<TState = Record<string, unknown>> =\n | Next\n | ((context: RouteContext<TState>) => Next);\n\n/**\n * Behavior when the canned decision queue is exhausted before the\n * supervisor terminates on its own.\n *\n * - `\"end\"` (default) — return `END`, terminating the run cleanly. The\n * common case: script the interesting turns, let the run stop.\n * - `\"throw\"` — throw, surfacing the over-run as a test failure. Use\n * when every iteration must be accounted for.\n * - `\"repeat\"` — replay the last decision for every further iteration.\n * Useful for \"keep routing to the same intent until evaluate is\n * satisfied\" scenarios.\n */\nexport type MockRouterExhaustion = \"end\" | \"throw\" | \"repeat\";\n\n/**\n * Options for {@link mockRouter}.\n */\nexport type MockRouterOptions = {\n /** What to do once the decision queue is exhausted. Default `\"end\"`. */\n onExhausted?: MockRouterExhaustion;\n};\n\n/**\n * Build a deterministic `route` callback that replays a canned\n * sequence of routing decisions — one per supervisor iteration — for\n * testing supervisors without an LLM router.\n *\n * Drop the returned callback into `ai.supervisor({ route: mockRouter([...]) })`\n * in place of an LLM `router`. The Nth iteration consumes the Nth\n * decision; a function decision is evaluated against the live\n * `RouteContext`. When the queue runs out, behavior follows\n * `options.onExhausted` (default: terminate with `END`).\n *\n * Pairs with the `toRouteTo` / `toConverge` matchers to assert the\n * resulting report tree.\n *\n * @example\n * const supervisor = ai.supervisor({\n * name: \"draft-then-review\",\n * intents: { writer, critic },\n * route: mockRouter([\"writer\", \"critic\", END]),\n * });\n *\n * @example\n * // Branch on accumulated state, repeat the last decision until done.\n * route: mockRouter(\n * [\"research\", (ctx) => (ctx.state.summary ? END : \"research\")],\n * { onExhausted: \"repeat\" },\n * );\n */\nexport function mockRouter<TState = Record<string, unknown>>(\n decisions: MockRouterDecision<TState>[],\n options: MockRouterOptions = {},\n): (context: RouteContext<TState>) => Next {\n const onExhausted = options.onExhausted ?? \"end\";\n let cursor = 0;\n\n return (context: RouteContext<TState>): Next => {\n if (cursor < decisions.length) {\n const decision = decisions[cursor];\n cursor++;\n\n return resolveDecision(decision, context);\n }\n\n if (onExhausted === \"throw\") {\n throw new Error(\n `mockRouter exhausted after ${decisions.length} decision(s) at iteration ${context.iteration}`,\n );\n }\n\n if (onExhausted === \"repeat\" && decisions.length > 0) {\n return resolveDecision(decisions[decisions.length - 1], context);\n }\n\n return END;\n };\n}\n\n/**\n * Resolve a single decision entry into a concrete {@link Next} —\n * invoking the predicate form against the live context, or returning\n * the literal form verbatim.\n */\nfunction resolveDecision<TState>(\n decision: MockRouterDecision<TState>,\n context: RouteContext<TState>,\n): Next {\n if (typeof decision === \"function\") {\n return decision(context);\n }\n\n return decision;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiEA,SAAgB,WACd,WACA,UAA6B,CAAC,GACW;CACzC,MAAM,cAAc,QAAQ,eAAe;CAC3C,IAAI,SAAS;CAEb,QAAQ,YAAwC;EAC9C,IAAI,SAAS,UAAU,QAAQ;GAC7B,MAAM,WAAW,UAAU;GAC3B;GAEA,OAAO,gBAAgB,UAAU,OAAO;EAC1C;EAEA,IAAI,gBAAgB,SAClB,MAAM,IAAI,MACR,8BAA8B,UAAU,OAAO,4BAA4B,QAAQ,WACrF;EAGF,IAAI,gBAAgB,YAAY,UAAU,SAAS,GACjD,OAAO,gBAAgB,UAAU,UAAU,SAAS,IAAI,OAAO;EAGjE,OAAO;CACT;AACF;;;;;;AAOA,SAAS,gBACP,UACA,SACM;CACN,IAAI,OAAO,aAAa,YACtB,OAAO,SAAS,OAAO;CAGzB,OAAO;AACT"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { ModelContract } from "../contracts/model.contract.mjs";
|
|
2
|
+
import { FallbackModelContract, FallbackModelOptions } from "../contracts/fallback-model.contract.mjs";
|
|
3
|
+
|
|
4
|
+
//#region ../@warlock.js/ai/src/model/fallback-model.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* A `ModelContract` that wraps an ordered list of models and tries each
|
|
7
|
+
* in turn, advancing to the next only when the current one fails with a
|
|
8
|
+
* matching (transient) provider error.
|
|
9
|
+
*
|
|
10
|
+
* **Role.** A drop-in `ModelContract` for resilience: hand it to any
|
|
11
|
+
* agent / workflow / supervisor in place of a single model and provider
|
|
12
|
+
* outages, rate-limits, and timeouts transparently fail over to a
|
|
13
|
+
* backup. Non-transient failures (bad key, oversized prompt, blocked
|
|
14
|
+
* content) re-throw immediately rather than wastefully retrying.
|
|
15
|
+
*
|
|
16
|
+
* **What it owns / doesn't own.** Owns the ordered model list, the
|
|
17
|
+
* retry decision, and per-call usage aggregation across attempted
|
|
18
|
+
* models. Does NOT own retry/backoff timing (it advances instantly to
|
|
19
|
+
* the next model — pair it with a backoff middleware if you want delay)
|
|
20
|
+
* nor any provider I/O of its own; every call is delegated to a wrapped
|
|
21
|
+
* model.
|
|
22
|
+
*
|
|
23
|
+
* **Streaming fall-over caveat.** `stream()` can only fail over while no
|
|
24
|
+
* chunk has been emitted yet. Once the first `delta` / `tool-call`
|
|
25
|
+
* reaches the consumer, the partial output cannot be un-sent, so a
|
|
26
|
+
* mid-stream failure propagates instead of restarting on the next
|
|
27
|
+
* model.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* const model = fallbackModel([
|
|
31
|
+
* ai.openai.model({ name: "gpt-4o" }),
|
|
32
|
+
* ai.anthropic.model({ name: "claude-3-5-sonnet" }),
|
|
33
|
+
* ]);
|
|
34
|
+
* const agent = ai.agent({ model });
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* // custom retry predicate
|
|
38
|
+
* const model = fallbackModel([primary, backup], {
|
|
39
|
+
* retryOn: (error) => error instanceof ProviderError,
|
|
40
|
+
* });
|
|
41
|
+
*/
|
|
42
|
+
declare function fallbackModel(models: ModelContract[], options?: FallbackModelOptions): FallbackModelContract;
|
|
43
|
+
//#endregion
|
|
44
|
+
export { fallbackModel };
|
|
45
|
+
//# sourceMappingURL=fallback-model.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fallback-model.d.mts","names":[],"sources":["../../../../../../../@warlock.js/ai/src/model/fallback-model.ts"],"mappings":";;;;;;AAuEA;;;;;;;;;;;;;;AAGwB;;;;;;;;;;;;;;;;;;;;;iBAHR,aAAA,CACd,MAAA,EAAQ,aAAA,IACR,OAAA,GAAU,oBAAA,GACT,qBAAA"}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { AIError } from "../errors/ai-error.mjs";
|
|
2
|
+
import { accumulateCost } from "../utils/compute-cost.mjs";
|
|
3
|
+
|
|
4
|
+
//#region ../@warlock.js/ai/src/model/fallback-model.ts
|
|
5
|
+
/**
|
|
6
|
+
* Error codes treated as transient — and therefore worth falling over
|
|
7
|
+
* to the next model — when the caller does not supply an explicit
|
|
8
|
+
* `retryOn`. Covers provider rate-limits, timeouts, and the generic
|
|
9
|
+
* `PROVIDER_ERROR` catch-all that adapters throw for 5xx / unknown
|
|
10
|
+
* network failures. Deliberately omits auth, invalid-request,
|
|
11
|
+
* context-length, and content-filter: those fail identically on every
|
|
12
|
+
* downstream model, so retrying only burns budget.
|
|
13
|
+
*/
|
|
14
|
+
const DEFAULT_RETRYABLE_CODES = [
|
|
15
|
+
"PROVIDER_RATE_LIMIT",
|
|
16
|
+
"PROVIDER_TIMEOUT",
|
|
17
|
+
"PROVIDER_ERROR"
|
|
18
|
+
];
|
|
19
|
+
/**
|
|
20
|
+
* A `ModelContract` that wraps an ordered list of models and tries each
|
|
21
|
+
* in turn, advancing to the next only when the current one fails with a
|
|
22
|
+
* matching (transient) provider error.
|
|
23
|
+
*
|
|
24
|
+
* **Role.** A drop-in `ModelContract` for resilience: hand it to any
|
|
25
|
+
* agent / workflow / supervisor in place of a single model and provider
|
|
26
|
+
* outages, rate-limits, and timeouts transparently fail over to a
|
|
27
|
+
* backup. Non-transient failures (bad key, oversized prompt, blocked
|
|
28
|
+
* content) re-throw immediately rather than wastefully retrying.
|
|
29
|
+
*
|
|
30
|
+
* **What it owns / doesn't own.** Owns the ordered model list, the
|
|
31
|
+
* retry decision, and per-call usage aggregation across attempted
|
|
32
|
+
* models. Does NOT own retry/backoff timing (it advances instantly to
|
|
33
|
+
* the next model — pair it with a backoff middleware if you want delay)
|
|
34
|
+
* nor any provider I/O of its own; every call is delegated to a wrapped
|
|
35
|
+
* model.
|
|
36
|
+
*
|
|
37
|
+
* **Streaming fall-over caveat.** `stream()` can only fail over while no
|
|
38
|
+
* chunk has been emitted yet. Once the first `delta` / `tool-call`
|
|
39
|
+
* reaches the consumer, the partial output cannot be un-sent, so a
|
|
40
|
+
* mid-stream failure propagates instead of restarting on the next
|
|
41
|
+
* model.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* const model = fallbackModel([
|
|
45
|
+
* ai.openai.model({ name: "gpt-4o" }),
|
|
46
|
+
* ai.anthropic.model({ name: "claude-3-5-sonnet" }),
|
|
47
|
+
* ]);
|
|
48
|
+
* const agent = ai.agent({ model });
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* // custom retry predicate
|
|
52
|
+
* const model = fallbackModel([primary, backup], {
|
|
53
|
+
* retryOn: (error) => error instanceof ProviderError,
|
|
54
|
+
* });
|
|
55
|
+
*/
|
|
56
|
+
function fallbackModel(models, options) {
|
|
57
|
+
if (models.length === 0) throw new AIError("PROVIDER_INVALID_REQUEST", "fallbackModel() requires at least one model in the chain.", void 0, "validation");
|
|
58
|
+
return new FallbackModel(models, resolveShouldRetry(options?.retryOn));
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Build the chain-advancement predicate from the caller's `retryOn`.
|
|
62
|
+
* An array becomes a code membership test against an `AIError.code`; a
|
|
63
|
+
* function is used verbatim; absence falls back to the transient
|
|
64
|
+
* default set.
|
|
65
|
+
*/
|
|
66
|
+
function resolveShouldRetry(retryOn) {
|
|
67
|
+
if (typeof retryOn === "function") return retryOn;
|
|
68
|
+
const codes = retryOn ?? DEFAULT_RETRYABLE_CODES;
|
|
69
|
+
return (error) => {
|
|
70
|
+
return error instanceof AIError && codes.includes(error.code);
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Add a successful call's usage into a running aggregate, mirroring the
|
|
75
|
+
* agent's trip accumulation: scalar token counts sum, optional channels
|
|
76
|
+
* sum only when present, and cost merges via `accumulateCost` so an
|
|
77
|
+
* unpriced model never erases a priced sibling's cost.
|
|
78
|
+
*/
|
|
79
|
+
function aggregateUsage(total, next) {
|
|
80
|
+
total.input += next.input;
|
|
81
|
+
total.output += next.output;
|
|
82
|
+
total.total += next.total;
|
|
83
|
+
if (next.cachedTokens !== void 0) total.cachedTokens = (total.cachedTokens ?? 0) + next.cachedTokens;
|
|
84
|
+
if (next.reasoningTokens !== void 0) total.reasoningTokens = (total.reasoningTokens ?? 0) + next.reasoningTokens;
|
|
85
|
+
if (next.cacheWriteTokens !== void 0) total.cacheWriteTokens = (total.cacheWriteTokens ?? 0) + next.cacheWriteTokens;
|
|
86
|
+
total.cost = accumulateCost(total.cost, next.cost);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Internal `ModelContract` implementation backing {@link fallbackModel}.
|
|
90
|
+
*
|
|
91
|
+
* Long-lived (its identity, capabilities, and pricing front the primary
|
|
92
|
+
* model for the wrapper's whole lifetime) so it is a class rather than a
|
|
93
|
+
* closure. Per-call mutable state (the usage aggregate, the attempt log)
|
|
94
|
+
* lives in {@link FallbackRun}, instantiated fresh on every
|
|
95
|
+
* `complete()` / `stream()` so concurrent calls never share bookkeeping.
|
|
96
|
+
*/
|
|
97
|
+
var FallbackModel = class {
|
|
98
|
+
constructor(models, shouldRetry) {
|
|
99
|
+
this.models = models;
|
|
100
|
+
this.shouldRetry = shouldRetry;
|
|
101
|
+
this.latestAttempts = [];
|
|
102
|
+
const primary = models[0];
|
|
103
|
+
this.name = primary.name;
|
|
104
|
+
this.provider = primary.provider;
|
|
105
|
+
this.capabilities = primary.capabilities;
|
|
106
|
+
this.pricing = primary.pricing;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Models that failed with a chain-advancing error during the most
|
|
110
|
+
* recent `complete()` / `stream()` call, in attempt order. Empty when
|
|
111
|
+
* the primary model succeeded outright. Overwritten on each call.
|
|
112
|
+
*/
|
|
113
|
+
get lastAttempts() {
|
|
114
|
+
return this.latestAttempts;
|
|
115
|
+
}
|
|
116
|
+
async complete(messages, options) {
|
|
117
|
+
const run = new FallbackRun(this.models, this.shouldRetry);
|
|
118
|
+
const response = await run.complete(messages, options);
|
|
119
|
+
this.latestAttempts = run.attempts;
|
|
120
|
+
return response;
|
|
121
|
+
}
|
|
122
|
+
stream(messages, options) {
|
|
123
|
+
return new FallbackRun(this.models, this.shouldRetry).stream(messages, options, (attempts) => {
|
|
124
|
+
this.latestAttempts = attempts;
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* Per-call execution of the fallback chain. Holds the usage aggregate
|
|
130
|
+
* and the attempt log for a single `complete()` / `stream()` invocation
|
|
131
|
+
* so the long-lived {@link FallbackModel} stays free of shared mutable
|
|
132
|
+
* state across concurrent calls.
|
|
133
|
+
*/
|
|
134
|
+
var FallbackRun = class {
|
|
135
|
+
constructor(models, shouldRetry) {
|
|
136
|
+
this.models = models;
|
|
137
|
+
this.shouldRetry = shouldRetry;
|
|
138
|
+
this.attempts = [];
|
|
139
|
+
this.usage = {
|
|
140
|
+
input: 0,
|
|
141
|
+
output: 0,
|
|
142
|
+
total: 0
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Try each model's `complete()` in order. On a chain-advancing error,
|
|
147
|
+
* record the attempt and move to the next; on the last model (or a
|
|
148
|
+
* non-retryable error) re-throw the underlying error verbatim so the
|
|
149
|
+
* caller still sees a typed `AIError` with its original code.
|
|
150
|
+
*/
|
|
151
|
+
async complete(messages, options) {
|
|
152
|
+
for (let index = 0; index < this.models.length; index++) {
|
|
153
|
+
const model = this.models[index];
|
|
154
|
+
const isLast = index === this.models.length - 1;
|
|
155
|
+
try {
|
|
156
|
+
const response = await model.complete(messages, options);
|
|
157
|
+
aggregateUsage(this.usage, response.usage);
|
|
158
|
+
return {
|
|
159
|
+
...response,
|
|
160
|
+
usage: this.usage
|
|
161
|
+
};
|
|
162
|
+
} catch (error) {
|
|
163
|
+
if (isLast || !this.shouldRetry(error)) throw error;
|
|
164
|
+
this.recordAttempt(model, error);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
throw new AIError("PROVIDER_ERROR", "fallbackModel() exhausted its chain without producing a response.", void 0, "provider");
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Try each model's `stream()` in order. Fall-over is only attempted
|
|
171
|
+
* while no chunk has been emitted yet for the current model — once the
|
|
172
|
+
* consumer has seen a `delta` / `tool-call`, a mid-stream failure
|
|
173
|
+
* propagates instead of restarting (partial output cannot be un-sent).
|
|
174
|
+
* The aggregated usage replaces the `done` chunk's usage so the caller
|
|
175
|
+
* sees the chain total.
|
|
176
|
+
*/
|
|
177
|
+
async *stream(messages, options, onSettle) {
|
|
178
|
+
try {
|
|
179
|
+
for (let index = 0; index < this.models.length; index++) {
|
|
180
|
+
const model = this.models[index];
|
|
181
|
+
const isLast = index === this.models.length - 1;
|
|
182
|
+
let emitted = false;
|
|
183
|
+
try {
|
|
184
|
+
for await (const chunk of model.stream(messages, options)) {
|
|
185
|
+
if (chunk.type === "done") {
|
|
186
|
+
aggregateUsage(this.usage, chunk.usage);
|
|
187
|
+
yield {
|
|
188
|
+
...chunk,
|
|
189
|
+
usage: this.usage
|
|
190
|
+
};
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
emitted = true;
|
|
194
|
+
yield chunk;
|
|
195
|
+
}
|
|
196
|
+
return;
|
|
197
|
+
} catch (error) {
|
|
198
|
+
if (emitted || isLast || !this.shouldRetry(error)) throw error;
|
|
199
|
+
this.recordAttempt(model, error);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
throw new AIError("PROVIDER_ERROR", "fallbackModel() exhausted its chain without producing a response.", void 0, "provider");
|
|
203
|
+
} finally {
|
|
204
|
+
onSettle(this.attempts);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
recordAttempt(model, error) {
|
|
208
|
+
this.attempts.push({
|
|
209
|
+
modelName: model.name,
|
|
210
|
+
provider: model.provider,
|
|
211
|
+
error
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
//#endregion
|
|
217
|
+
export { fallbackModel };
|
|
218
|
+
//# sourceMappingURL=fallback-model.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fallback-model.mjs","names":[],"sources":["../../../../../../../@warlock.js/ai/src/model/fallback-model.ts"],"sourcesContent":["import type {\n FallbackAttempt,\n FallbackModelContract,\n FallbackModelOptions,\n FallbackRetryPredicate,\n} from \"../contracts/fallback-model.contract\";\nimport type { Message } from \"../contracts/conversation-message.type\";\nimport type {\n ModelCallOptions,\n ModelCapabilities,\n ModelContract,\n ModelResponse,\n ModelStreamChunk,\n} from \"../contracts/model.contract\";\nimport type { Usage } from \"../contracts/result/usage.type\";\nimport { AIError } from \"../errors/ai-error\";\nimport type { AIErrorCode } from \"../errors/error-code.type\";\nimport { accumulateCost } from \"../utils/compute-cost\";\n\n/**\n * Error codes treated as transient — and therefore worth falling over\n * to the next model — when the caller does not supply an explicit\n * `retryOn`. Covers provider rate-limits, timeouts, and the generic\n * `PROVIDER_ERROR` catch-all that adapters throw for 5xx / unknown\n * network failures. Deliberately omits auth, invalid-request,\n * context-length, and content-filter: those fail identically on every\n * downstream model, so retrying only burns budget.\n */\nconst DEFAULT_RETRYABLE_CODES: readonly AIErrorCode[] = [\n \"PROVIDER_RATE_LIMIT\",\n \"PROVIDER_TIMEOUT\",\n \"PROVIDER_ERROR\",\n];\n\n/**\n * A `ModelContract` that wraps an ordered list of models and tries each\n * in turn, advancing to the next only when the current one fails with a\n * matching (transient) provider error.\n *\n * **Role.** A drop-in `ModelContract` for resilience: hand it to any\n * agent / workflow / supervisor in place of a single model and provider\n * outages, rate-limits, and timeouts transparently fail over to a\n * backup. Non-transient failures (bad key, oversized prompt, blocked\n * content) re-throw immediately rather than wastefully retrying.\n *\n * **What it owns / doesn't own.** Owns the ordered model list, the\n * retry decision, and per-call usage aggregation across attempted\n * models. Does NOT own retry/backoff timing (it advances instantly to\n * the next model — pair it with a backoff middleware if you want delay)\n * nor any provider I/O of its own; every call is delegated to a wrapped\n * model.\n *\n * **Streaming fall-over caveat.** `stream()` can only fail over while no\n * chunk has been emitted yet. Once the first `delta` / `tool-call`\n * reaches the consumer, the partial output cannot be un-sent, so a\n * mid-stream failure propagates instead of restarting on the next\n * model.\n *\n * @example\n * const model = fallbackModel([\n * ai.openai.model({ name: \"gpt-4o\" }),\n * ai.anthropic.model({ name: \"claude-3-5-sonnet\" }),\n * ]);\n * const agent = ai.agent({ model });\n *\n * @example\n * // custom retry predicate\n * const model = fallbackModel([primary, backup], {\n * retryOn: (error) => error instanceof ProviderError,\n * });\n */\nexport function fallbackModel(\n models: ModelContract[],\n options?: FallbackModelOptions,\n): FallbackModelContract {\n if (models.length === 0) {\n throw new AIError(\n \"PROVIDER_INVALID_REQUEST\",\n \"fallbackModel() requires at least one model in the chain.\",\n undefined,\n \"validation\",\n );\n }\n\n return new FallbackModel(models, resolveShouldRetry(options?.retryOn));\n}\n\n/**\n * Build the chain-advancement predicate from the caller's `retryOn`.\n * An array becomes a code membership test against an `AIError.code`; a\n * function is used verbatim; absence falls back to the transient\n * default set.\n */\nfunction resolveShouldRetry(\n retryOn: FallbackModelOptions[\"retryOn\"],\n): FallbackRetryPredicate {\n if (typeof retryOn === \"function\") {\n return retryOn;\n }\n\n const codes: readonly AIErrorCode[] = retryOn ?? DEFAULT_RETRYABLE_CODES;\n\n return (error: unknown): boolean => {\n return error instanceof AIError && codes.includes(error.code);\n };\n}\n\n/**\n * Add a successful call's usage into a running aggregate, mirroring the\n * agent's trip accumulation: scalar token counts sum, optional channels\n * sum only when present, and cost merges via `accumulateCost` so an\n * unpriced model never erases a priced sibling's cost.\n */\nfunction aggregateUsage(total: Usage, next: Usage): void {\n total.input += next.input;\n total.output += next.output;\n total.total += next.total;\n\n if (next.cachedTokens !== undefined) {\n total.cachedTokens = (total.cachedTokens ?? 0) + next.cachedTokens;\n }\n\n if (next.reasoningTokens !== undefined) {\n total.reasoningTokens = (total.reasoningTokens ?? 0) + next.reasoningTokens;\n }\n\n if (next.cacheWriteTokens !== undefined) {\n total.cacheWriteTokens = (total.cacheWriteTokens ?? 0) + next.cacheWriteTokens;\n }\n\n total.cost = accumulateCost(total.cost, next.cost);\n}\n\n/**\n * Internal `ModelContract` implementation backing {@link fallbackModel}.\n *\n * Long-lived (its identity, capabilities, and pricing front the primary\n * model for the wrapper's whole lifetime) so it is a class rather than a\n * closure. Per-call mutable state (the usage aggregate, the attempt log)\n * lives in {@link FallbackRun}, instantiated fresh on every\n * `complete()` / `stream()` so concurrent calls never share bookkeeping.\n */\nclass FallbackModel implements FallbackModelContract {\n public readonly name: string;\n public readonly provider: string;\n public readonly capabilities?: ModelCapabilities;\n public readonly pricing?: ModelContract[\"pricing\"];\n\n private latestAttempts: FallbackAttempt[] = [];\n\n public constructor(\n private readonly models: ModelContract[],\n private readonly shouldRetry: FallbackRetryPredicate,\n ) {\n const primary = models[0]!;\n\n this.name = primary.name;\n this.provider = primary.provider;\n this.capabilities = primary.capabilities;\n this.pricing = primary.pricing;\n }\n\n /**\n * Models that failed with a chain-advancing error during the most\n * recent `complete()` / `stream()` call, in attempt order. Empty when\n * the primary model succeeded outright. Overwritten on each call.\n */\n public get lastAttempts(): FallbackAttempt[] {\n return this.latestAttempts;\n }\n\n public async complete(\n messages: Message[],\n options?: ModelCallOptions,\n ): Promise<ModelResponse> {\n const run = new FallbackRun(this.models, this.shouldRetry);\n const response = await run.complete(messages, options);\n\n this.latestAttempts = run.attempts;\n\n return response;\n }\n\n public stream(\n messages: Message[],\n options?: ModelCallOptions,\n ): AsyncIterable<ModelStreamChunk> {\n const run = new FallbackRun(this.models, this.shouldRetry);\n\n return run.stream(messages, options, (attempts) => {\n this.latestAttempts = attempts;\n });\n }\n}\n\n/**\n * Per-call execution of the fallback chain. Holds the usage aggregate\n * and the attempt log for a single `complete()` / `stream()` invocation\n * so the long-lived {@link FallbackModel} stays free of shared mutable\n * state across concurrent calls.\n */\nclass FallbackRun {\n public readonly attempts: FallbackAttempt[] = [];\n\n private readonly usage: Usage = { input: 0, output: 0, total: 0 };\n\n public constructor(\n private readonly models: ModelContract[],\n private readonly shouldRetry: FallbackRetryPredicate,\n ) {}\n\n /**\n * Try each model's `complete()` in order. On a chain-advancing error,\n * record the attempt and move to the next; on the last model (or a\n * non-retryable error) re-throw the underlying error verbatim so the\n * caller still sees a typed `AIError` with its original code.\n */\n public async complete(\n messages: Message[],\n options?: ModelCallOptions,\n ): Promise<ModelResponse> {\n for (let index = 0; index < this.models.length; index++) {\n const model = this.models[index]!;\n const isLast = index === this.models.length - 1;\n\n try {\n const response = await model.complete(messages, options);\n\n aggregateUsage(this.usage, response.usage);\n\n return { ...response, usage: this.usage };\n } catch (error) {\n if (isLast || !this.shouldRetry(error)) {\n throw error;\n }\n\n this.recordAttempt(model, error);\n }\n }\n\n throw new AIError(\n \"PROVIDER_ERROR\",\n \"fallbackModel() exhausted its chain without producing a response.\",\n undefined,\n \"provider\",\n );\n }\n\n /**\n * Try each model's `stream()` in order. Fall-over is only attempted\n * while no chunk has been emitted yet for the current model — once the\n * consumer has seen a `delta` / `tool-call`, a mid-stream failure\n * propagates instead of restarting (partial output cannot be un-sent).\n * The aggregated usage replaces the `done` chunk's usage so the caller\n * sees the chain total.\n */\n public async *stream(\n messages: Message[],\n options: ModelCallOptions | undefined,\n onSettle: (attempts: FallbackAttempt[]) => void,\n ): AsyncIterable<ModelStreamChunk> {\n try {\n for (let index = 0; index < this.models.length; index++) {\n const model = this.models[index]!;\n const isLast = index === this.models.length - 1;\n let emitted = false;\n\n try {\n for await (const chunk of model.stream(messages, options)) {\n if (chunk.type === \"done\") {\n aggregateUsage(this.usage, chunk.usage);\n\n yield { ...chunk, usage: this.usage };\n return;\n }\n\n emitted = true;\n\n yield chunk;\n }\n\n return;\n } catch (error) {\n if (emitted || isLast || !this.shouldRetry(error)) {\n throw error;\n }\n\n this.recordAttempt(model, error);\n }\n }\n\n throw new AIError(\n \"PROVIDER_ERROR\",\n \"fallbackModel() exhausted its chain without producing a response.\",\n undefined,\n \"provider\",\n );\n } finally {\n onSettle(this.attempts);\n }\n }\n\n private recordAttempt(model: ModelContract, error: unknown): void {\n this.attempts.push({\n modelName: model.name,\n provider: model.provider,\n error,\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;AA4BA,MAAM,0BAAkD;CACtD;CACA;CACA;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,SAAgB,cACd,QACA,SACuB;CACvB,IAAI,OAAO,WAAW,GACpB,MAAM,IAAI,QACR,4BACA,6DACA,QACA,YACF;CAGF,OAAO,IAAI,cAAc,QAAQ,mBAAmB,SAAS,OAAO,CAAC;AACvE;;;;;;;AAQA,SAAS,mBACP,SACwB;CACxB,IAAI,OAAO,YAAY,YACrB,OAAO;CAGT,MAAM,QAAgC,WAAW;CAEjD,QAAQ,UAA4B;EAClC,OAAO,iBAAiB,WAAW,MAAM,SAAS,MAAM,IAAI;CAC9D;AACF;;;;;;;AAQA,SAAS,eAAe,OAAc,MAAmB;CACvD,MAAM,SAAS,KAAK;CACpB,MAAM,UAAU,KAAK;CACrB,MAAM,SAAS,KAAK;CAEpB,IAAI,KAAK,iBAAiB,QACxB,MAAM,gBAAgB,MAAM,gBAAgB,KAAK,KAAK;CAGxD,IAAI,KAAK,oBAAoB,QAC3B,MAAM,mBAAmB,MAAM,mBAAmB,KAAK,KAAK;CAG9D,IAAI,KAAK,qBAAqB,QAC5B,MAAM,oBAAoB,MAAM,oBAAoB,KAAK,KAAK;CAGhE,MAAM,OAAO,eAAe,MAAM,MAAM,KAAK,IAAI;AACnD;;;;;;;;;;AAWA,IAAM,gBAAN,MAAqD;CAQnD,AAAO,YACL,AAAiB,QACjB,AAAiB,aACjB;EAFiB;EACA;wBAJyB,CAAC;EAM3C,MAAM,UAAU,OAAO;EAEvB,KAAK,OAAO,QAAQ;EACpB,KAAK,WAAW,QAAQ;EACxB,KAAK,eAAe,QAAQ;EAC5B,KAAK,UAAU,QAAQ;CACzB;;;;;;CAOA,IAAW,eAAkC;EAC3C,OAAO,KAAK;CACd;CAEA,MAAa,SACX,UACA,SACwB;EACxB,MAAM,MAAM,IAAI,YAAY,KAAK,QAAQ,KAAK,WAAW;EACzD,MAAM,WAAW,MAAM,IAAI,SAAS,UAAU,OAAO;EAErD,KAAK,iBAAiB,IAAI;EAE1B,OAAO;CACT;CAEA,AAAO,OACL,UACA,SACiC;EAGjC,OAAO,IAFS,YAAY,KAAK,QAAQ,KAAK,WAErC,CAAC,CAAC,OAAO,UAAU,UAAU,aAAa;GACjD,KAAK,iBAAiB;EACxB,CAAC;CACH;AACF;;;;;;;AAQA,IAAM,cAAN,MAAkB;CAKhB,AAAO,YACL,AAAiB,QACjB,AAAiB,aACjB;EAFiB;EACA;kBAN2B,CAAC;eAEf;GAAE,OAAO;GAAG,QAAQ;GAAG,OAAO;EAAE;CAK7D;;;;;;;CAQH,MAAa,SACX,UACA,SACwB;EACxB,KAAK,IAAI,QAAQ,GAAG,QAAQ,KAAK,OAAO,QAAQ,SAAS;GACvD,MAAM,QAAQ,KAAK,OAAO;GAC1B,MAAM,SAAS,UAAU,KAAK,OAAO,SAAS;GAE9C,IAAI;IACF,MAAM,WAAW,MAAM,MAAM,SAAS,UAAU,OAAO;IAEvD,eAAe,KAAK,OAAO,SAAS,KAAK;IAEzC,OAAO;KAAE,GAAG;KAAU,OAAO,KAAK;IAAM;GAC1C,SAAS,OAAO;IACd,IAAI,UAAU,CAAC,KAAK,YAAY,KAAK,GACnC,MAAM;IAGR,KAAK,cAAc,OAAO,KAAK;GACjC;EACF;EAEA,MAAM,IAAI,QACR,kBACA,qEACA,QACA,UACF;CACF;;;;;;;;;CAUA,OAAc,OACZ,UACA,SACA,UACiC;EACjC,IAAI;GACF,KAAK,IAAI,QAAQ,GAAG,QAAQ,KAAK,OAAO,QAAQ,SAAS;IACvD,MAAM,QAAQ,KAAK,OAAO;IAC1B,MAAM,SAAS,UAAU,KAAK,OAAO,SAAS;IAC9C,IAAI,UAAU;IAEd,IAAI;KACF,WAAW,MAAM,SAAS,MAAM,OAAO,UAAU,OAAO,GAAG;MACzD,IAAI,MAAM,SAAS,QAAQ;OACzB,eAAe,KAAK,OAAO,MAAM,KAAK;OAEtC,MAAM;QAAE,GAAG;QAAO,OAAO,KAAK;OAAM;OACpC;MACF;MAEA,UAAU;MAEV,MAAM;KACR;KAEA;IACF,SAAS,OAAO;KACd,IAAI,WAAW,UAAU,CAAC,KAAK,YAAY,KAAK,GAC9C,MAAM;KAGR,KAAK,cAAc,OAAO,KAAK;IACjC;GACF;GAEA,MAAM,IAAI,QACR,kBACA,qEACA,QACA,UACF;EACF,UAAU;GACR,SAAS,KAAK,QAAQ;EACxB;CACF;CAEA,AAAQ,cAAc,OAAsB,OAAsB;EAChE,KAAK,SAAS,KAAK;GACjB,WAAW,MAAM;GACjB,UAAU,MAAM;GAChB;EACF,CAAC;CACH;AACF"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
//#region ../@warlock.js/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs
|
|
2
|
+
var comma = ",".charCodeAt(0);
|
|
3
|
+
var semicolon = ";".charCodeAt(0);
|
|
4
|
+
var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
5
|
+
var intToChar = new Uint8Array(64);
|
|
6
|
+
var charToInt = new Uint8Array(128);
|
|
7
|
+
for (let i = 0; i < chars.length; i++) {
|
|
8
|
+
const c = chars.charCodeAt(i);
|
|
9
|
+
intToChar[i] = c;
|
|
10
|
+
charToInt[c] = i;
|
|
11
|
+
}
|
|
12
|
+
function encodeInteger(builder, num, relative) {
|
|
13
|
+
let delta = num - relative;
|
|
14
|
+
delta = delta < 0 ? -delta << 1 | 1 : delta << 1;
|
|
15
|
+
do {
|
|
16
|
+
let clamped = delta & 31;
|
|
17
|
+
delta >>>= 5;
|
|
18
|
+
if (delta > 0) clamped |= 32;
|
|
19
|
+
builder.write(intToChar[clamped]);
|
|
20
|
+
} while (delta > 0);
|
|
21
|
+
return num;
|
|
22
|
+
}
|
|
23
|
+
var bufLength = 1024 * 16;
|
|
24
|
+
var td = typeof TextDecoder !== "undefined" ? /* @__PURE__ */ new TextDecoder() : typeof Buffer !== "undefined" ? { decode(buf) {
|
|
25
|
+
return Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength).toString();
|
|
26
|
+
} } : { decode(buf) {
|
|
27
|
+
let out = "";
|
|
28
|
+
for (let i = 0; i < buf.length; i++) out += String.fromCharCode(buf[i]);
|
|
29
|
+
return out;
|
|
30
|
+
} };
|
|
31
|
+
var StringWriter = class {
|
|
32
|
+
constructor() {
|
|
33
|
+
this.pos = 0;
|
|
34
|
+
this.out = "";
|
|
35
|
+
this.buffer = new Uint8Array(bufLength);
|
|
36
|
+
}
|
|
37
|
+
write(v) {
|
|
38
|
+
const { buffer } = this;
|
|
39
|
+
buffer[this.pos++] = v;
|
|
40
|
+
if (this.pos === bufLength) {
|
|
41
|
+
this.out += td.decode(buffer);
|
|
42
|
+
this.pos = 0;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
flush() {
|
|
46
|
+
const { buffer, out, pos } = this;
|
|
47
|
+
return pos > 0 ? out + td.decode(buffer.subarray(0, pos)) : out;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
function encode(decoded) {
|
|
51
|
+
const writer = new StringWriter();
|
|
52
|
+
let sourcesIndex = 0;
|
|
53
|
+
let sourceLine = 0;
|
|
54
|
+
let sourceColumn = 0;
|
|
55
|
+
let namesIndex = 0;
|
|
56
|
+
for (let i = 0; i < decoded.length; i++) {
|
|
57
|
+
const line = decoded[i];
|
|
58
|
+
if (i > 0) writer.write(semicolon);
|
|
59
|
+
if (line.length === 0) continue;
|
|
60
|
+
let genColumn = 0;
|
|
61
|
+
for (let j = 0; j < line.length; j++) {
|
|
62
|
+
const segment = line[j];
|
|
63
|
+
if (j > 0) writer.write(comma);
|
|
64
|
+
genColumn = encodeInteger(writer, segment[0], genColumn);
|
|
65
|
+
if (segment.length === 1) continue;
|
|
66
|
+
sourcesIndex = encodeInteger(writer, segment[1], sourcesIndex);
|
|
67
|
+
sourceLine = encodeInteger(writer, segment[2], sourceLine);
|
|
68
|
+
sourceColumn = encodeInteger(writer, segment[3], sourceColumn);
|
|
69
|
+
if (segment.length === 4) continue;
|
|
70
|
+
namesIndex = encodeInteger(writer, segment[4], namesIndex);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return writer.flush();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
//#endregion
|
|
77
|
+
export { encode };
|
|
78
|
+
//# sourceMappingURL=sourcemap-codec.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sourcemap-codec.mjs","names":[],"sources":["../../../../../../../../../../@warlock.js/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs"],"sourcesContent":["// src/vlq.ts\nvar comma = \",\".charCodeAt(0);\nvar semicolon = \";\".charCodeAt(0);\nvar chars = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\";\nvar intToChar = new Uint8Array(64);\nvar charToInt = new Uint8Array(128);\nfor (let i = 0; i < chars.length; i++) {\n const c = chars.charCodeAt(i);\n intToChar[i] = c;\n charToInt[c] = i;\n}\nfunction decodeInteger(reader, relative) {\n let value = 0;\n let shift = 0;\n let integer = 0;\n do {\n const c = reader.next();\n integer = charToInt[c];\n value |= (integer & 31) << shift;\n shift += 5;\n } while (integer & 32);\n const shouldNegate = value & 1;\n value >>>= 1;\n if (shouldNegate) {\n value = -2147483648 | -value;\n }\n return relative + value;\n}\nfunction encodeInteger(builder, num, relative) {\n let delta = num - relative;\n delta = delta < 0 ? -delta << 1 | 1 : delta << 1;\n do {\n let clamped = delta & 31;\n delta >>>= 5;\n if (delta > 0) clamped |= 32;\n builder.write(intToChar[clamped]);\n } while (delta > 0);\n return num;\n}\nfunction hasMoreVlq(reader, max) {\n if (reader.pos >= max) return false;\n return reader.peek() !== comma;\n}\n\n// src/strings.ts\nvar bufLength = 1024 * 16;\nvar td = typeof TextDecoder !== \"undefined\" ? /* @__PURE__ */ new TextDecoder() : typeof Buffer !== \"undefined\" ? {\n decode(buf) {\n const out = Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength);\n return out.toString();\n }\n} : {\n decode(buf) {\n let out = \"\";\n for (let i = 0; i < buf.length; i++) {\n out += String.fromCharCode(buf[i]);\n }\n return out;\n }\n};\nvar StringWriter = class {\n constructor() {\n this.pos = 0;\n this.out = \"\";\n this.buffer = new Uint8Array(bufLength);\n }\n write(v) {\n const { buffer } = this;\n buffer[this.pos++] = v;\n if (this.pos === bufLength) {\n this.out += td.decode(buffer);\n this.pos = 0;\n }\n }\n flush() {\n const { buffer, out, pos } = this;\n return pos > 0 ? out + td.decode(buffer.subarray(0, pos)) : out;\n }\n};\nvar StringReader = class {\n constructor(buffer) {\n this.pos = 0;\n this.buffer = buffer;\n }\n next() {\n return this.buffer.charCodeAt(this.pos++);\n }\n peek() {\n return this.buffer.charCodeAt(this.pos);\n }\n indexOf(char) {\n const { buffer, pos } = this;\n const idx = buffer.indexOf(char, pos);\n return idx === -1 ? buffer.length : idx;\n }\n};\n\n// src/scopes.ts\nvar EMPTY = [];\nfunction decodeOriginalScopes(input) {\n const { length } = input;\n const reader = new StringReader(input);\n const scopes = [];\n const stack = [];\n let line = 0;\n for (; reader.pos < length; reader.pos++) {\n line = decodeInteger(reader, line);\n const column = decodeInteger(reader, 0);\n if (!hasMoreVlq(reader, length)) {\n const last = stack.pop();\n last[2] = line;\n last[3] = column;\n continue;\n }\n const kind = decodeInteger(reader, 0);\n const fields = decodeInteger(reader, 0);\n const hasName = fields & 1;\n const scope = hasName ? [line, column, 0, 0, kind, decodeInteger(reader, 0)] : [line, column, 0, 0, kind];\n let vars = EMPTY;\n if (hasMoreVlq(reader, length)) {\n vars = [];\n do {\n const varsIndex = decodeInteger(reader, 0);\n vars.push(varsIndex);\n } while (hasMoreVlq(reader, length));\n }\n scope.vars = vars;\n scopes.push(scope);\n stack.push(scope);\n }\n return scopes;\n}\nfunction encodeOriginalScopes(scopes) {\n const writer = new StringWriter();\n for (let i = 0; i < scopes.length; ) {\n i = _encodeOriginalScopes(scopes, i, writer, [0]);\n }\n return writer.flush();\n}\nfunction _encodeOriginalScopes(scopes, index, writer, state) {\n const scope = scopes[index];\n const { 0: startLine, 1: startColumn, 2: endLine, 3: endColumn, 4: kind, vars } = scope;\n if (index > 0) writer.write(comma);\n state[0] = encodeInteger(writer, startLine, state[0]);\n encodeInteger(writer, startColumn, 0);\n encodeInteger(writer, kind, 0);\n const fields = scope.length === 6 ? 1 : 0;\n encodeInteger(writer, fields, 0);\n if (scope.length === 6) encodeInteger(writer, scope[5], 0);\n for (const v of vars) {\n encodeInteger(writer, v, 0);\n }\n for (index++; index < scopes.length; ) {\n const next = scopes[index];\n const { 0: l, 1: c } = next;\n if (l > endLine || l === endLine && c >= endColumn) {\n break;\n }\n index = _encodeOriginalScopes(scopes, index, writer, state);\n }\n writer.write(comma);\n state[0] = encodeInteger(writer, endLine, state[0]);\n encodeInteger(writer, endColumn, 0);\n return index;\n}\nfunction decodeGeneratedRanges(input) {\n const { length } = input;\n const reader = new StringReader(input);\n const ranges = [];\n const stack = [];\n let genLine = 0;\n let definitionSourcesIndex = 0;\n let definitionScopeIndex = 0;\n let callsiteSourcesIndex = 0;\n let callsiteLine = 0;\n let callsiteColumn = 0;\n let bindingLine = 0;\n let bindingColumn = 0;\n do {\n const semi = reader.indexOf(\";\");\n let genColumn = 0;\n for (; reader.pos < semi; reader.pos++) {\n genColumn = decodeInteger(reader, genColumn);\n if (!hasMoreVlq(reader, semi)) {\n const last = stack.pop();\n last[2] = genLine;\n last[3] = genColumn;\n continue;\n }\n const fields = decodeInteger(reader, 0);\n const hasDefinition = fields & 1;\n const hasCallsite = fields & 2;\n const hasScope = fields & 4;\n let callsite = null;\n let bindings = EMPTY;\n let range;\n if (hasDefinition) {\n const defSourcesIndex = decodeInteger(reader, definitionSourcesIndex);\n definitionScopeIndex = decodeInteger(\n reader,\n definitionSourcesIndex === defSourcesIndex ? definitionScopeIndex : 0\n );\n definitionSourcesIndex = defSourcesIndex;\n range = [genLine, genColumn, 0, 0, defSourcesIndex, definitionScopeIndex];\n } else {\n range = [genLine, genColumn, 0, 0];\n }\n range.isScope = !!hasScope;\n if (hasCallsite) {\n const prevCsi = callsiteSourcesIndex;\n const prevLine = callsiteLine;\n callsiteSourcesIndex = decodeInteger(reader, callsiteSourcesIndex);\n const sameSource = prevCsi === callsiteSourcesIndex;\n callsiteLine = decodeInteger(reader, sameSource ? callsiteLine : 0);\n callsiteColumn = decodeInteger(\n reader,\n sameSource && prevLine === callsiteLine ? callsiteColumn : 0\n );\n callsite = [callsiteSourcesIndex, callsiteLine, callsiteColumn];\n }\n range.callsite = callsite;\n if (hasMoreVlq(reader, semi)) {\n bindings = [];\n do {\n bindingLine = genLine;\n bindingColumn = genColumn;\n const expressionsCount = decodeInteger(reader, 0);\n let expressionRanges;\n if (expressionsCount < -1) {\n expressionRanges = [[decodeInteger(reader, 0)]];\n for (let i = -1; i > expressionsCount; i--) {\n const prevBl = bindingLine;\n bindingLine = decodeInteger(reader, bindingLine);\n bindingColumn = decodeInteger(reader, bindingLine === prevBl ? bindingColumn : 0);\n const expression = decodeInteger(reader, 0);\n expressionRanges.push([expression, bindingLine, bindingColumn]);\n }\n } else {\n expressionRanges = [[expressionsCount]];\n }\n bindings.push(expressionRanges);\n } while (hasMoreVlq(reader, semi));\n }\n range.bindings = bindings;\n ranges.push(range);\n stack.push(range);\n }\n genLine++;\n reader.pos = semi + 1;\n } while (reader.pos < length);\n return ranges;\n}\nfunction encodeGeneratedRanges(ranges) {\n if (ranges.length === 0) return \"\";\n const writer = new StringWriter();\n for (let i = 0; i < ranges.length; ) {\n i = _encodeGeneratedRanges(ranges, i, writer, [0, 0, 0, 0, 0, 0, 0]);\n }\n return writer.flush();\n}\nfunction _encodeGeneratedRanges(ranges, index, writer, state) {\n const range = ranges[index];\n const {\n 0: startLine,\n 1: startColumn,\n 2: endLine,\n 3: endColumn,\n isScope,\n callsite,\n bindings\n } = range;\n if (state[0] < startLine) {\n catchupLine(writer, state[0], startLine);\n state[0] = startLine;\n state[1] = 0;\n } else if (index > 0) {\n writer.write(comma);\n }\n state[1] = encodeInteger(writer, range[1], state[1]);\n const fields = (range.length === 6 ? 1 : 0) | (callsite ? 2 : 0) | (isScope ? 4 : 0);\n encodeInteger(writer, fields, 0);\n if (range.length === 6) {\n const { 4: sourcesIndex, 5: scopesIndex } = range;\n if (sourcesIndex !== state[2]) {\n state[3] = 0;\n }\n state[2] = encodeInteger(writer, sourcesIndex, state[2]);\n state[3] = encodeInteger(writer, scopesIndex, state[3]);\n }\n if (callsite) {\n const { 0: sourcesIndex, 1: callLine, 2: callColumn } = range.callsite;\n if (sourcesIndex !== state[4]) {\n state[5] = 0;\n state[6] = 0;\n } else if (callLine !== state[5]) {\n state[6] = 0;\n }\n state[4] = encodeInteger(writer, sourcesIndex, state[4]);\n state[5] = encodeInteger(writer, callLine, state[5]);\n state[6] = encodeInteger(writer, callColumn, state[6]);\n }\n if (bindings) {\n for (const binding of bindings) {\n if (binding.length > 1) encodeInteger(writer, -binding.length, 0);\n const expression = binding[0][0];\n encodeInteger(writer, expression, 0);\n let bindingStartLine = startLine;\n let bindingStartColumn = startColumn;\n for (let i = 1; i < binding.length; i++) {\n const expRange = binding[i];\n bindingStartLine = encodeInteger(writer, expRange[1], bindingStartLine);\n bindingStartColumn = encodeInteger(writer, expRange[2], bindingStartColumn);\n encodeInteger(writer, expRange[0], 0);\n }\n }\n }\n for (index++; index < ranges.length; ) {\n const next = ranges[index];\n const { 0: l, 1: c } = next;\n if (l > endLine || l === endLine && c >= endColumn) {\n break;\n }\n index = _encodeGeneratedRanges(ranges, index, writer, state);\n }\n if (state[0] < endLine) {\n catchupLine(writer, state[0], endLine);\n state[0] = endLine;\n state[1] = 0;\n } else {\n writer.write(comma);\n }\n state[1] = encodeInteger(writer, endColumn, state[1]);\n return index;\n}\nfunction catchupLine(writer, lastLine, line) {\n do {\n writer.write(semicolon);\n } while (++lastLine < line);\n}\n\n// src/sourcemap-codec.ts\nfunction decode(mappings) {\n const { length } = mappings;\n const reader = new StringReader(mappings);\n const decoded = [];\n let genColumn = 0;\n let sourcesIndex = 0;\n let sourceLine = 0;\n let sourceColumn = 0;\n let namesIndex = 0;\n do {\n const semi = reader.indexOf(\";\");\n const line = [];\n let sorted = true;\n let lastCol = 0;\n genColumn = 0;\n while (reader.pos < semi) {\n let seg;\n genColumn = decodeInteger(reader, genColumn);\n if (genColumn < lastCol) sorted = false;\n lastCol = genColumn;\n if (hasMoreVlq(reader, semi)) {\n sourcesIndex = decodeInteger(reader, sourcesIndex);\n sourceLine = decodeInteger(reader, sourceLine);\n sourceColumn = decodeInteger(reader, sourceColumn);\n if (hasMoreVlq(reader, semi)) {\n namesIndex = decodeInteger(reader, namesIndex);\n seg = [genColumn, sourcesIndex, sourceLine, sourceColumn, namesIndex];\n } else {\n seg = [genColumn, sourcesIndex, sourceLine, sourceColumn];\n }\n } else {\n seg = [genColumn];\n }\n line.push(seg);\n reader.pos++;\n }\n if (!sorted) sort(line);\n decoded.push(line);\n reader.pos = semi + 1;\n } while (reader.pos <= length);\n return decoded;\n}\nfunction sort(line) {\n line.sort(sortComparator);\n}\nfunction sortComparator(a, b) {\n return a[0] - b[0];\n}\nfunction encode(decoded) {\n const writer = new StringWriter();\n let sourcesIndex = 0;\n let sourceLine = 0;\n let sourceColumn = 0;\n let namesIndex = 0;\n for (let i = 0; i < decoded.length; i++) {\n const line = decoded[i];\n if (i > 0) writer.write(semicolon);\n if (line.length === 0) continue;\n let genColumn = 0;\n for (let j = 0; j < line.length; j++) {\n const segment = line[j];\n if (j > 0) writer.write(comma);\n genColumn = encodeInteger(writer, segment[0], genColumn);\n if (segment.length === 1) continue;\n sourcesIndex = encodeInteger(writer, segment[1], sourcesIndex);\n sourceLine = encodeInteger(writer, segment[2], sourceLine);\n sourceColumn = encodeInteger(writer, segment[3], sourceColumn);\n if (segment.length === 4) continue;\n namesIndex = encodeInteger(writer, segment[4], namesIndex);\n }\n }\n return writer.flush();\n}\nexport {\n decode,\n decodeGeneratedRanges,\n decodeOriginalScopes,\n encode,\n encodeGeneratedRanges,\n encodeOriginalScopes\n};\n//# sourceMappingURL=sourcemap-codec.mjs.map\n"],"x_google_ignoreList":[0],"mappings":";AACA,IAAI,QAAQ,IAAI,WAAW,CAAC;AAC5B,IAAI,YAAY,IAAI,WAAW,CAAC;AAChC,IAAI,QAAQ;AACZ,IAAI,YAAY,IAAI,WAAW,EAAE;AACjC,IAAI,YAAY,IAAI,WAAW,GAAG;AAClC,KAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;CACrC,MAAM,IAAI,MAAM,WAAW,CAAC;CAC5B,UAAU,KAAK;CACf,UAAU,KAAK;AACjB;AAkBA,SAAS,cAAc,SAAS,KAAK,UAAU;CAC7C,IAAI,QAAQ,MAAM;CAClB,QAAQ,QAAQ,IAAI,CAAC,SAAS,IAAI,IAAI,SAAS;CAC/C,GAAG;EACD,IAAI,UAAU,QAAQ;EACtB,WAAW;EACX,IAAI,QAAQ,GAAG,WAAW;EAC1B,QAAQ,MAAM,UAAU,QAAQ;CAClC,SAAS,QAAQ;CACjB,OAAO;AACT;AAOA,IAAI,YAAY,OAAO;AACvB,IAAI,KAAK,OAAO,gBAAgB,8BAA8B,IAAI,YAAY,IAAI,OAAO,WAAW,cAAc,EAChH,OAAO,KAAK;CAEV,OADY,OAAO,KAAK,IAAI,QAAQ,IAAI,YAAY,IAAI,UAC/C,CAAC,CAAC,SAAS;AACtB,EACF,IAAI,EACF,OAAO,KAAK;CACV,IAAI,MAAM;CACV,KAAK,IAAI,IAAI,GAAG,IAAI,IAAI,QAAQ,KAC9B,OAAO,OAAO,aAAa,IAAI,EAAE;CAEnC,OAAO;AACT,EACF;AACA,IAAI,eAAe,MAAM;CACvB,cAAc;EACZ,KAAK,MAAM;EACX,KAAK,MAAM;EACX,KAAK,SAAS,IAAI,WAAW,SAAS;CACxC;CACA,MAAM,GAAG;EACP,MAAM,EAAE,WAAW;EACnB,OAAO,KAAK,SAAS;EACrB,IAAI,KAAK,QAAQ,WAAW;GAC1B,KAAK,OAAO,GAAG,OAAO,MAAM;GAC5B,KAAK,MAAM;EACb;CACF;CACA,QAAQ;EACN,MAAM,EAAE,QAAQ,KAAK,QAAQ;EAC7B,OAAO,MAAM,IAAI,MAAM,GAAG,OAAO,OAAO,SAAS,GAAG,GAAG,CAAC,IAAI;CAC9D;AACF;AAuTA,SAAS,OAAO,SAAS;CACvB,MAAM,SAAS,IAAI,aAAa;CAChC,IAAI,eAAe;CACnB,IAAI,aAAa;CACjB,IAAI,eAAe;CACnB,IAAI,aAAa;CACjB,KAAK,IAAI,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAAK;EACvC,MAAM,OAAO,QAAQ;EACrB,IAAI,IAAI,GAAG,OAAO,MAAM,SAAS;EACjC,IAAI,KAAK,WAAW,GAAG;EACvB,IAAI,YAAY;EAChB,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;GACpC,MAAM,UAAU,KAAK;GACrB,IAAI,IAAI,GAAG,OAAO,MAAM,KAAK;GAC7B,YAAY,cAAc,QAAQ,QAAQ,IAAI,SAAS;GACvD,IAAI,QAAQ,WAAW,GAAG;GAC1B,eAAe,cAAc,QAAQ,QAAQ,IAAI,YAAY;GAC7D,aAAa,cAAc,QAAQ,QAAQ,IAAI,UAAU;GACzD,eAAe,cAAc,QAAQ,QAAQ,IAAI,YAAY;GAC7D,IAAI,QAAQ,WAAW,GAAG;GAC1B,aAAa,cAAc,QAAQ,QAAQ,IAAI,UAAU;EAC3D;CACF;CACA,OAAO,OAAO,MAAM;AACtB"}
|