@warlock.js/ai 4.2.11 → 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,84 @@
|
|
|
1
|
+
import { SupervisorInput } from "../contracts/supervisor/supervisor-input.type.mjs";
|
|
2
|
+
import { TurnSnapshot } from "../contracts/result/orchestrator-result.type.mjs";
|
|
3
|
+
import { RecalledMemory } from "../contracts/memory/memory-item.type.mjs";
|
|
4
|
+
import { MemoryContract } from "../contracts/memory/memory.contract.mjs";
|
|
5
|
+
import { OrchestratorMemoryConfig } from "../contracts/orchestrator/orchestrator-config.type.mjs";
|
|
6
|
+
|
|
7
|
+
//#region ../@warlock.js/ai/src/orchestrator/memory.d.ts
|
|
8
|
+
/**
|
|
9
|
+
* Memory wiring resolved once per turn from `OrchestratorConfig.memory`
|
|
10
|
+
* (memory core M2). Normalizes the two accepted config shapes — a bare
|
|
11
|
+
* {@link MemoryContract} or the richer {@link OrchestratorMemoryConfig} —
|
|
12
|
+
* into a single flat record the lifecycle phase reads, so `runTurn` never
|
|
13
|
+
* branches on which form the dev supplied.
|
|
14
|
+
*/
|
|
15
|
+
type ResolvedOrchestratorMemory = {
|
|
16
|
+
/** The store recalled-from before dispatch and remembered-into after. */store: MemoryContract; /** Recall count cap; `0` disables recall (write-only memory). */
|
|
17
|
+
k?: number; /** Semantic-similarity floor for recall. */
|
|
18
|
+
threshold?: number; /** Single-tier recall restriction. */
|
|
19
|
+
tier?: ResolvedTier; /** Whether a clean turn writes its outcome back. Default `true`. */
|
|
20
|
+
remember: boolean; /** Tier the remembered outcome lands in. Omit for the memory's `defaultTier`. */
|
|
21
|
+
rememberTier?: ResolvedTier; /** Context-bag key the recalled memories are injected under. */
|
|
22
|
+
injectKey: string;
|
|
23
|
+
};
|
|
24
|
+
type ResolvedTier = NonNullable<OrchestratorMemoryConfig["recall"]>["tier"];
|
|
25
|
+
/**
|
|
26
|
+
* Normalize `OrchestratorConfig.memory` into {@link ResolvedOrchestratorMemory},
|
|
27
|
+
* or `undefined` when no memory is configured. Centralizes the
|
|
28
|
+
* bare-store-vs-config distinction so the engine context carries one
|
|
29
|
+
* shape and the lifecycle phase stays branch-free.
|
|
30
|
+
*/
|
|
31
|
+
declare function resolveOrchestratorMemory(memory: MemoryContract | OrchestratorMemoryConfig | undefined): ResolvedOrchestratorMemory | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* Coerce a turn's {@link SupervisorInput} (string or structured object)
|
|
34
|
+
* into the natural-language query the memory store recalls / embeds
|
|
35
|
+
* against. Strings pass through; objects are JSON-serialized — the same
|
|
36
|
+
* coercion the supervisor applies when forwarding an object input to a
|
|
37
|
+
* child agent without an explicit `input(ctx)` override.
|
|
38
|
+
*/
|
|
39
|
+
declare function memoryQueryFromInput(input: SupervisorInput): string;
|
|
40
|
+
/**
|
|
41
|
+
* Recall the memories relevant to a turn's input (memory core M2 — the
|
|
42
|
+
* pre-dispatch half). Returns the scored {@link RecalledMemory}[] the
|
|
43
|
+
* lifecycle injects into the turn's `context` bag under
|
|
44
|
+
* `memory.injectKey`. Returns an empty array — never throws on "no hits"
|
|
45
|
+
* — and short-circuits when `k === 0` (recall disabled / write-only
|
|
46
|
+
* memory) so a write-only config never round-trips the embedder.
|
|
47
|
+
*/
|
|
48
|
+
declare function recallForTurn(memory: ResolvedOrchestratorMemory, input: SupervisorInput): Promise<RecalledMemory[]>;
|
|
49
|
+
/**
|
|
50
|
+
* Merge the recalled memories into a fresh per-turn context bag under
|
|
51
|
+
* `memory.injectKey` (memory core M2 — the injection half). Never
|
|
52
|
+
* mutates the caller's `context` object — returns a new bag (or the
|
|
53
|
+
* original when there is nothing to inject) so the request-scoped input
|
|
54
|
+
* stays immutable, and the supervisor's intake (which freezes a
|
|
55
|
+
* shallow copy) sees the recalled set on every `ctx.context[injectKey]`.
|
|
56
|
+
*
|
|
57
|
+
* A pre-existing value at `injectKey` is preserved when recall produced
|
|
58
|
+
* nothing, and overwritten with the recalled set otherwise — the
|
|
59
|
+
* orchestrator owns that key once memory is configured.
|
|
60
|
+
*/
|
|
61
|
+
declare function injectMemories(context: Record<string, unknown> | undefined, memory: ResolvedOrchestratorMemory, recalled: RecalledMemory[]): Record<string, unknown> | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* Remember a settled turn's outcome (memory core M2 — the post-dispatch
|
|
64
|
+
* half). Called only after a clean turn (cancelled / failed turns revert
|
|
65
|
+
* and never remember — §17). No-ops when `remember` is `false`
|
|
66
|
+
* (read-only memory) or when the produced text is empty.
|
|
67
|
+
*
|
|
68
|
+
* The remembered text is the turn input followed by the model's textual
|
|
69
|
+
* outcome when one is available, so a later `recall` keyed on a similar
|
|
70
|
+
* input surfaces both the prior question and its answer.
|
|
71
|
+
*/
|
|
72
|
+
declare function rememberTurnOutcome(memory: ResolvedOrchestratorMemory, input: SupervisorInput, outcomeText: string | undefined): Promise<void>;
|
|
73
|
+
/**
|
|
74
|
+
* Derive a turn's textual outcome for remembering (memory core M2).
|
|
75
|
+
* Prefers the validated `result.data` (an `output` schema reshaped it);
|
|
76
|
+
* otherwise stringifies the dispatched intents' branch outputs from the
|
|
77
|
+
* turn snapshot, joined newline-wise so a multi-branch fan-out
|
|
78
|
+
* contributes every output. Returns `undefined` when the turn produced
|
|
79
|
+
* no usable text — the caller then remembers the input alone.
|
|
80
|
+
*/
|
|
81
|
+
declare function outcomeTextFromTurn(data: unknown, turnSnapshot: TurnSnapshot): string | undefined;
|
|
82
|
+
//#endregion
|
|
83
|
+
export { ResolvedOrchestratorMemory, injectMemories, memoryQueryFromInput, outcomeTextFromTurn, recallForTurn, rememberTurnOutcome, resolveOrchestratorMemory };
|
|
84
|
+
//# sourceMappingURL=memory.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.d.mts","names":[],"sources":["../../../../../../../@warlock.js/ai/src/orchestrator/memory.ts"],"mappings":";;;;;;;;;AAmBA;;;;;KAAY,0BAAA;EAYiB,yEAV3B,KAAA,EAAO,cAAA,EAAP;EAEA,CAAA;EAEA,SAAA,WAEA;EAAA,IAAA,GAAO,YAAA,EAEP;EAAA,QAAA,WAEe;EAAf,YAAA,GAAe,YAAA,EAEN;EAAT,SAAA;AAAA;AAAA,KAGG,YAAA,GAAe,WAAW,CAAC,wBAAA;;;AAAwB;AAoBxD;;;iBAAgB,yBAAA,CACd,MAAA,EAAQ,cAAA,GAAiB,wBAAA,eACxB,0BAAA;;;;;;;;iBA+Ba,oBAAA,CAAqB,KAAsB,EAAf,eAAe;;AA/B9B;AA+B7B;;;;AAA2D;AAY3D;iBAAsB,aAAA,CACpB,MAAA,EAAQ,0BAAA,EACR,KAAA,EAAO,eAAA,GACN,OAAA,CAAQ,cAAA;;;;;;;;;;;;;iBAwBK,cAAA,CACd,OAAA,EAAS,MAAA,+BACT,MAAA,EAAQ,0BAAA,EACR,QAAA,EAAU,cAAA,KACT,MAAA;;AA5BsB;AAwBzB;;;;;;;;iBAsBsB,mBAAA,CACpB,MAAA,EAAQ,0BAAA,EACR,KAAA,EAAO,eAAA,EACP,WAAA,uBACC,OAAA;;;;;;;;;iBA4Ca,mBAAA,CACd,IAAA,WACA,YAAA,EAAc,YAAY"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
//#region ../@warlock.js/ai/src/orchestrator/memory.ts
|
|
2
|
+
/** Default key the recalled memories are injected under in the context bag. */
|
|
3
|
+
const DEFAULT_INJECT_KEY = "memories";
|
|
4
|
+
/**
|
|
5
|
+
* A `MemoryContract` is the bare-store form; anything carrying a `store`
|
|
6
|
+
* is the {@link OrchestratorMemoryConfig} wrapper. Distinguished by the
|
|
7
|
+
* presence of `recall` — a method on the contract, absent on the config
|
|
8
|
+
* (whose own `recall` is a plain options object, never a function).
|
|
9
|
+
*/
|
|
10
|
+
function isBareMemory(value) {
|
|
11
|
+
return typeof value.recall === "function";
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Normalize `OrchestratorConfig.memory` into {@link ResolvedOrchestratorMemory},
|
|
15
|
+
* or `undefined` when no memory is configured. Centralizes the
|
|
16
|
+
* bare-store-vs-config distinction so the engine context carries one
|
|
17
|
+
* shape and the lifecycle phase stays branch-free.
|
|
18
|
+
*/
|
|
19
|
+
function resolveOrchestratorMemory(memory) {
|
|
20
|
+
if (!memory) return;
|
|
21
|
+
if (isBareMemory(memory)) return {
|
|
22
|
+
store: memory,
|
|
23
|
+
remember: true,
|
|
24
|
+
injectKey: DEFAULT_INJECT_KEY
|
|
25
|
+
};
|
|
26
|
+
return {
|
|
27
|
+
store: memory.store,
|
|
28
|
+
k: memory.recall?.k,
|
|
29
|
+
threshold: memory.recall?.threshold,
|
|
30
|
+
tier: memory.recall?.tier,
|
|
31
|
+
remember: memory.remember ?? true,
|
|
32
|
+
rememberTier: memory.rememberTier,
|
|
33
|
+
injectKey: memory.injectKey ?? DEFAULT_INJECT_KEY
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Coerce a turn's {@link SupervisorInput} (string or structured object)
|
|
38
|
+
* into the natural-language query the memory store recalls / embeds
|
|
39
|
+
* against. Strings pass through; objects are JSON-serialized — the same
|
|
40
|
+
* coercion the supervisor applies when forwarding an object input to a
|
|
41
|
+
* child agent without an explicit `input(ctx)` override.
|
|
42
|
+
*/
|
|
43
|
+
function memoryQueryFromInput(input) {
|
|
44
|
+
return typeof input === "string" ? input : JSON.stringify(input);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Recall the memories relevant to a turn's input (memory core M2 — the
|
|
48
|
+
* pre-dispatch half). Returns the scored {@link RecalledMemory}[] the
|
|
49
|
+
* lifecycle injects into the turn's `context` bag under
|
|
50
|
+
* `memory.injectKey`. Returns an empty array — never throws on "no hits"
|
|
51
|
+
* — and short-circuits when `k === 0` (recall disabled / write-only
|
|
52
|
+
* memory) so a write-only config never round-trips the embedder.
|
|
53
|
+
*/
|
|
54
|
+
async function recallForTurn(memory, input) {
|
|
55
|
+
if (memory.k === 0) return [];
|
|
56
|
+
return memory.store.recall(memoryQueryFromInput(input), {
|
|
57
|
+
k: memory.k,
|
|
58
|
+
threshold: memory.threshold,
|
|
59
|
+
tier: memory.tier
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Merge the recalled memories into a fresh per-turn context bag under
|
|
64
|
+
* `memory.injectKey` (memory core M2 — the injection half). Never
|
|
65
|
+
* mutates the caller's `context` object — returns a new bag (or the
|
|
66
|
+
* original when there is nothing to inject) so the request-scoped input
|
|
67
|
+
* stays immutable, and the supervisor's intake (which freezes a
|
|
68
|
+
* shallow copy) sees the recalled set on every `ctx.context[injectKey]`.
|
|
69
|
+
*
|
|
70
|
+
* A pre-existing value at `injectKey` is preserved when recall produced
|
|
71
|
+
* nothing, and overwritten with the recalled set otherwise — the
|
|
72
|
+
* orchestrator owns that key once memory is configured.
|
|
73
|
+
*/
|
|
74
|
+
function injectMemories(context, memory, recalled) {
|
|
75
|
+
if (recalled.length === 0) return context;
|
|
76
|
+
return {
|
|
77
|
+
...context ?? {},
|
|
78
|
+
[memory.injectKey]: recalled
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Remember a settled turn's outcome (memory core M2 — the post-dispatch
|
|
83
|
+
* half). Called only after a clean turn (cancelled / failed turns revert
|
|
84
|
+
* and never remember — §17). No-ops when `remember` is `false`
|
|
85
|
+
* (read-only memory) or when the produced text is empty.
|
|
86
|
+
*
|
|
87
|
+
* The remembered text is the turn input followed by the model's textual
|
|
88
|
+
* outcome when one is available, so a later `recall` keyed on a similar
|
|
89
|
+
* input surfaces both the prior question and its answer.
|
|
90
|
+
*/
|
|
91
|
+
async function rememberTurnOutcome(memory, input, outcomeText) {
|
|
92
|
+
if (!memory.remember) return;
|
|
93
|
+
const text = buildOutcomeText(input, outcomeText);
|
|
94
|
+
if (!text) return;
|
|
95
|
+
const item = {
|
|
96
|
+
text,
|
|
97
|
+
tier: memory.rememberTier
|
|
98
|
+
};
|
|
99
|
+
await memory.store.remember(item);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Compose the text written to memory for a turn: the input query, plus
|
|
103
|
+
* the outcome text on a following line when the dispatch produced one.
|
|
104
|
+
* Returns `undefined` when neither side carries content so an empty turn
|
|
105
|
+
* never pollutes the store.
|
|
106
|
+
*/
|
|
107
|
+
function buildOutcomeText(input, outcomeText) {
|
|
108
|
+
const query = memoryQueryFromInput(input).trim();
|
|
109
|
+
const outcome = outcomeText?.trim();
|
|
110
|
+
if (query && outcome) return `${query}\n${outcome}`;
|
|
111
|
+
return query || outcome || void 0;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Derive a turn's textual outcome for remembering (memory core M2).
|
|
115
|
+
* Prefers the validated `result.data` (an `output` schema reshaped it);
|
|
116
|
+
* otherwise stringifies the dispatched intents' branch outputs from the
|
|
117
|
+
* turn snapshot, joined newline-wise so a multi-branch fan-out
|
|
118
|
+
* contributes every output. Returns `undefined` when the turn produced
|
|
119
|
+
* no usable text — the caller then remembers the input alone.
|
|
120
|
+
*/
|
|
121
|
+
function outcomeTextFromTurn(data, turnSnapshot) {
|
|
122
|
+
const fromData = stringifyOutcome(data);
|
|
123
|
+
if (fromData) return fromData;
|
|
124
|
+
const outputs = Object.values(turnSnapshot.result).map((branch) => stringifyOutcome(branch.output)).filter((text) => Boolean(text));
|
|
125
|
+
return outputs.length > 0 ? outputs.join("\n") : void 0;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Coerce one outcome value to text: strings pass through; everything
|
|
129
|
+
* else (objects, numbers) is JSON-serialized. `undefined` / `null` and
|
|
130
|
+
* empty strings collapse to `undefined` so they don't masquerade as
|
|
131
|
+
* content.
|
|
132
|
+
*/
|
|
133
|
+
function stringifyOutcome(value) {
|
|
134
|
+
if (value === void 0 || value === null) return;
|
|
135
|
+
const text = typeof value === "string" ? value : JSON.stringify(value);
|
|
136
|
+
return text.trim() ? text : void 0;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
//#endregion
|
|
140
|
+
export { injectMemories, memoryQueryFromInput, outcomeTextFromTurn, recallForTurn, rememberTurnOutcome, resolveOrchestratorMemory };
|
|
141
|
+
//# sourceMappingURL=memory.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.mjs","names":[],"sources":["../../../../../../../@warlock.js/ai/src/orchestrator/memory.ts"],"sourcesContent":["import type { MemoryContract } from \"../contracts/memory/memory.contract\";\nimport type {\n MemoryItem,\n RecalledMemory,\n} from \"../contracts/memory/memory-item.type\";\nimport type { OrchestratorMemoryConfig } from \"../contracts/orchestrator/orchestrator-config.type\";\nimport type { TurnSnapshot } from \"../contracts/result/orchestrator-result.type\";\nimport type { SupervisorInput } from \"../contracts/supervisor/supervisor-input.type\";\n\n/** Default key the recalled memories are injected under in the context bag. */\nconst DEFAULT_INJECT_KEY = \"memories\";\n\n/**\n * Memory wiring resolved once per turn from `OrchestratorConfig.memory`\n * (memory core M2). Normalizes the two accepted config shapes — a bare\n * {@link MemoryContract} or the richer {@link OrchestratorMemoryConfig} —\n * into a single flat record the lifecycle phase reads, so `runTurn` never\n * branches on which form the dev supplied.\n */\nexport type ResolvedOrchestratorMemory = {\n /** The store recalled-from before dispatch and remembered-into after. */\n store: MemoryContract;\n /** Recall count cap; `0` disables recall (write-only memory). */\n k?: number;\n /** Semantic-similarity floor for recall. */\n threshold?: number;\n /** Single-tier recall restriction. */\n tier?: ResolvedTier;\n /** Whether a clean turn writes its outcome back. Default `true`. */\n remember: boolean;\n /** Tier the remembered outcome lands in. Omit for the memory's `defaultTier`. */\n rememberTier?: ResolvedTier;\n /** Context-bag key the recalled memories are injected under. */\n injectKey: string;\n};\n\ntype ResolvedTier = NonNullable<OrchestratorMemoryConfig[\"recall\"]>[\"tier\"];\n\n/**\n * A `MemoryContract` is the bare-store form; anything carrying a `store`\n * is the {@link OrchestratorMemoryConfig} wrapper. Distinguished by the\n * presence of `recall` — a method on the contract, absent on the config\n * (whose own `recall` is a plain options object, never a function).\n */\nfunction isBareMemory(\n value: MemoryContract | OrchestratorMemoryConfig,\n): value is MemoryContract {\n return typeof (value as MemoryContract).recall === \"function\";\n}\n\n/**\n * Normalize `OrchestratorConfig.memory` into {@link ResolvedOrchestratorMemory},\n * or `undefined` when no memory is configured. Centralizes the\n * bare-store-vs-config distinction so the engine context carries one\n * shape and the lifecycle phase stays branch-free.\n */\nexport function resolveOrchestratorMemory(\n memory: MemoryContract | OrchestratorMemoryConfig | undefined,\n): ResolvedOrchestratorMemory | undefined {\n if (!memory) {\n return undefined;\n }\n\n if (isBareMemory(memory)) {\n return {\n store: memory,\n remember: true,\n injectKey: DEFAULT_INJECT_KEY,\n };\n }\n\n return {\n store: memory.store,\n k: memory.recall?.k,\n threshold: memory.recall?.threshold,\n tier: memory.recall?.tier,\n remember: memory.remember ?? true,\n rememberTier: memory.rememberTier,\n injectKey: memory.injectKey ?? DEFAULT_INJECT_KEY,\n };\n}\n\n/**\n * Coerce a turn's {@link SupervisorInput} (string or structured object)\n * into the natural-language query the memory store recalls / embeds\n * against. Strings pass through; objects are JSON-serialized — the same\n * coercion the supervisor applies when forwarding an object input to a\n * child agent without an explicit `input(ctx)` override.\n */\nexport function memoryQueryFromInput(input: SupervisorInput): string {\n return typeof input === \"string\" ? input : JSON.stringify(input);\n}\n\n/**\n * Recall the memories relevant to a turn's input (memory core M2 — the\n * pre-dispatch half). Returns the scored {@link RecalledMemory}[] the\n * lifecycle injects into the turn's `context` bag under\n * `memory.injectKey`. Returns an empty array — never throws on \"no hits\"\n * — and short-circuits when `k === 0` (recall disabled / write-only\n * memory) so a write-only config never round-trips the embedder.\n */\nexport async function recallForTurn(\n memory: ResolvedOrchestratorMemory,\n input: SupervisorInput,\n): Promise<RecalledMemory[]> {\n if (memory.k === 0) {\n return [];\n }\n\n return memory.store.recall(memoryQueryFromInput(input), {\n k: memory.k,\n threshold: memory.threshold,\n tier: memory.tier,\n });\n}\n\n/**\n * Merge the recalled memories into a fresh per-turn context bag under\n * `memory.injectKey` (memory core M2 — the injection half). Never\n * mutates the caller's `context` object — returns a new bag (or the\n * original when there is nothing to inject) so the request-scoped input\n * stays immutable, and the supervisor's intake (which freezes a\n * shallow copy) sees the recalled set on every `ctx.context[injectKey]`.\n *\n * A pre-existing value at `injectKey` is preserved when recall produced\n * nothing, and overwritten with the recalled set otherwise — the\n * orchestrator owns that key once memory is configured.\n */\nexport function injectMemories(\n context: Record<string, unknown> | undefined,\n memory: ResolvedOrchestratorMemory,\n recalled: RecalledMemory[],\n): Record<string, unknown> | undefined {\n if (recalled.length === 0) {\n return context;\n }\n\n return { ...(context ?? {}), [memory.injectKey]: recalled };\n}\n\n/**\n * Remember a settled turn's outcome (memory core M2 — the post-dispatch\n * half). Called only after a clean turn (cancelled / failed turns revert\n * and never remember — §17). No-ops when `remember` is `false`\n * (read-only memory) or when the produced text is empty.\n *\n * The remembered text is the turn input followed by the model's textual\n * outcome when one is available, so a later `recall` keyed on a similar\n * input surfaces both the prior question and its answer.\n */\nexport async function rememberTurnOutcome(\n memory: ResolvedOrchestratorMemory,\n input: SupervisorInput,\n outcomeText: string | undefined,\n): Promise<void> {\n if (!memory.remember) {\n return;\n }\n\n const text = buildOutcomeText(input, outcomeText);\n\n if (!text) {\n return;\n }\n\n const item: MemoryItem = { text, tier: memory.rememberTier };\n\n await memory.store.remember(item);\n}\n\n/**\n * Compose the text written to memory for a turn: the input query, plus\n * the outcome text on a following line when the dispatch produced one.\n * Returns `undefined` when neither side carries content so an empty turn\n * never pollutes the store.\n */\nfunction buildOutcomeText(\n input: SupervisorInput,\n outcomeText: string | undefined,\n): string | undefined {\n const query = memoryQueryFromInput(input).trim();\n const outcome = outcomeText?.trim();\n\n if (query && outcome) {\n return `${query}\\n${outcome}`;\n }\n\n return query || outcome || undefined;\n}\n\n/**\n * Derive a turn's textual outcome for remembering (memory core M2).\n * Prefers the validated `result.data` (an `output` schema reshaped it);\n * otherwise stringifies the dispatched intents' branch outputs from the\n * turn snapshot, joined newline-wise so a multi-branch fan-out\n * contributes every output. Returns `undefined` when the turn produced\n * no usable text — the caller then remembers the input alone.\n */\nexport function outcomeTextFromTurn(\n data: unknown,\n turnSnapshot: TurnSnapshot,\n): string | undefined {\n const fromData = stringifyOutcome(data);\n\n if (fromData) {\n return fromData;\n }\n\n const outputs = Object.values(turnSnapshot.result)\n .map((branch) => stringifyOutcome(branch.output))\n .filter((text): text is string => Boolean(text));\n\n return outputs.length > 0 ? outputs.join(\"\\n\") : undefined;\n}\n\n/**\n * Coerce one outcome value to text: strings pass through; everything\n * else (objects, numbers) is JSON-serialized. `undefined` / `null` and\n * empty strings collapse to `undefined` so they don't masquerade as\n * content.\n */\nfunction stringifyOutcome(value: unknown): string | undefined {\n if (value === undefined || value === null) {\n return undefined;\n }\n\n const text = typeof value === \"string\" ? value : JSON.stringify(value);\n\n return text.trim() ? text : undefined;\n}\n"],"mappings":";;AAUA,MAAM,qBAAqB;;;;;;;AAkC3B,SAAS,aACP,OACyB;CACzB,OAAO,OAAQ,MAAyB,WAAW;AACrD;;;;;;;AAQA,SAAgB,0BACd,QACwC;CACxC,IAAI,CAAC,QACH;CAGF,IAAI,aAAa,MAAM,GACrB,OAAO;EACL,OAAO;EACP,UAAU;EACV,WAAW;CACb;CAGF,OAAO;EACL,OAAO,OAAO;EACd,GAAG,OAAO,QAAQ;EAClB,WAAW,OAAO,QAAQ;EAC1B,MAAM,OAAO,QAAQ;EACrB,UAAU,OAAO,YAAY;EAC7B,cAAc,OAAO;EACrB,WAAW,OAAO,aAAa;CACjC;AACF;;;;;;;;AASA,SAAgB,qBAAqB,OAAgC;CACnE,OAAO,OAAO,UAAU,WAAW,QAAQ,KAAK,UAAU,KAAK;AACjE;;;;;;;;;AAUA,eAAsB,cACpB,QACA,OAC2B;CAC3B,IAAI,OAAO,MAAM,GACf,OAAO,CAAC;CAGV,OAAO,OAAO,MAAM,OAAO,qBAAqB,KAAK,GAAG;EACtD,GAAG,OAAO;EACV,WAAW,OAAO;EAClB,MAAM,OAAO;CACf,CAAC;AACH;;;;;;;;;;;;;AAcA,SAAgB,eACd,SACA,QACA,UACqC;CACrC,IAAI,SAAS,WAAW,GACtB,OAAO;CAGT,OAAO;EAAE,GAAI,WAAW,CAAC;GAAK,OAAO,YAAY;CAAS;AAC5D;;;;;;;;;;;AAYA,eAAsB,oBACpB,QACA,OACA,aACe;CACf,IAAI,CAAC,OAAO,UACV;CAGF,MAAM,OAAO,iBAAiB,OAAO,WAAW;CAEhD,IAAI,CAAC,MACH;CAGF,MAAM,OAAmB;EAAE;EAAM,MAAM,OAAO;CAAa;CAE3D,MAAM,OAAO,MAAM,SAAS,IAAI;AAClC;;;;;;;AAQA,SAAS,iBACP,OACA,aACoB;CACpB,MAAM,QAAQ,qBAAqB,KAAK,CAAC,CAAC,KAAK;CAC/C,MAAM,UAAU,aAAa,KAAK;CAElC,IAAI,SAAS,SACX,OAAO,GAAG,MAAM,IAAI;CAGtB,OAAO,SAAS,WAAW;AAC7B;;;;;;;;;AAUA,SAAgB,oBACd,MACA,cACoB;CACpB,MAAM,WAAW,iBAAiB,IAAI;CAEtC,IAAI,UACF,OAAO;CAGT,MAAM,UAAU,OAAO,OAAO,aAAa,MAAM,CAAC,CAC/C,KAAK,WAAW,iBAAiB,OAAO,MAAM,CAAC,CAAC,CAChD,QAAQ,SAAyB,QAAQ,IAAI,CAAC;CAEjD,OAAO,QAAQ,SAAS,IAAI,QAAQ,KAAK,IAAI,IAAI;AACnD;;;;;;;AAQA,SAAS,iBAAiB,OAAoC;CAC5D,IAAI,UAAU,UAAa,UAAU,MACnC;CAGF,MAAM,OAAO,OAAO,UAAU,WAAW,QAAQ,KAAK,UAAU,KAAK;CAErE,OAAO,KAAK,KAAK,IAAI,OAAO;AAC9B"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { StreamContract } from "../contracts/stream/stream.contract.mjs";
|
|
2
|
+
import { OrchestratorEvent } from "../contracts/orchestrator/orchestrator-event.type.mjs";
|
|
3
|
+
|
|
4
|
+
//#region ../@warlock.js/ai/src/orchestrator/orchestrator-stream.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Internal async-queue controller driving `orchestrator.stream()`.
|
|
7
|
+
* Mirrors {@link import("../supervisor/supervisor-stream").createSupervisorStream}'s
|
|
8
|
+
* controller — same producer/consumer pipe, parameterized by the
|
|
9
|
+
* orchestrator event union and the terminal result type.
|
|
10
|
+
*
|
|
11
|
+
* The turn pushes events as it advances through the lifecycle phases,
|
|
12
|
+
* then settles with `end(result)` (the same `OrchestratorResult` that
|
|
13
|
+
* `execute()` resolves) or `fail(error)` on an authoring/drift throw.
|
|
14
|
+
*/
|
|
15
|
+
type OrchestratorStreamController<TResult> = {
|
|
16
|
+
push(event: OrchestratorEvent): void;
|
|
17
|
+
end(result: TResult): void;
|
|
18
|
+
fail(error: Error): void;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Factory mirroring `createSupervisorStream`. Returns a paired
|
|
22
|
+
* `{ controller, stream }` — the turn pushes events into the controller
|
|
23
|
+
* while the caller iterates (or awaits `.result`) on the stream side.
|
|
24
|
+
*
|
|
25
|
+
* The `result` promise resolves to the same `OrchestratorResult` value
|
|
26
|
+
* `execute()` produces; it rejects only when the turn throws before
|
|
27
|
+
* producing a result (drift / config misuse) — runtime failures ride on
|
|
28
|
+
* `result.error` and still settle via `end()`.
|
|
29
|
+
*
|
|
30
|
+
* Child `supervisor.*` / `agent.*` events bubble through this same pipe
|
|
31
|
+
* unmodified (the turn forwards them as it observes them on the
|
|
32
|
+
* delegated run); they share the `{ type, ...payload }` shape with the
|
|
33
|
+
* orchestrator's own events so iteration narrows uniformly on
|
|
34
|
+
* `event.type`.
|
|
35
|
+
*/
|
|
36
|
+
declare function createOrchestratorStream<TResult>(): {
|
|
37
|
+
controller: OrchestratorStreamController<TResult>;
|
|
38
|
+
stream: StreamContract<TResult, OrchestratorEvent>;
|
|
39
|
+
};
|
|
40
|
+
//#endregion
|
|
41
|
+
export { OrchestratorStreamController, createOrchestratorStream };
|
|
42
|
+
//# sourceMappingURL=orchestrator-stream.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orchestrator-stream.d.mts","names":[],"sources":["../../../../../../../@warlock.js/ai/src/orchestrator/orchestrator-stream.ts"],"mappings":";;;;;;AAaA;;;;;;;;KAAY,4BAAA;EACV,IAAA,CAAK,KAAA,EAAO,iBAAA;EACZ,GAAA,CAAI,MAAA,EAAQ,OAAA;EACZ,IAAA,CAAK,KAAA,EAAO,KAAA;AAAA;;;;;;;AAAK;AAwBnB;;;;;;;;;iBAAgB,wBAAA;EACd,UAAA,EAAY,4BAAA,CAA6B,OAAA;EACzC,MAAA,EAAQ,cAAA,CAAe,OAAA,EAAS,iBAAA;AAAA"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
//#region ../@warlock.js/ai/src/orchestrator/orchestrator-stream.ts
|
|
2
|
+
/**
|
|
3
|
+
* Factory mirroring `createSupervisorStream`. Returns a paired
|
|
4
|
+
* `{ controller, stream }` — the turn pushes events into the controller
|
|
5
|
+
* while the caller iterates (or awaits `.result`) on the stream side.
|
|
6
|
+
*
|
|
7
|
+
* The `result` promise resolves to the same `OrchestratorResult` value
|
|
8
|
+
* `execute()` produces; it rejects only when the turn throws before
|
|
9
|
+
* producing a result (drift / config misuse) — runtime failures ride on
|
|
10
|
+
* `result.error` and still settle via `end()`.
|
|
11
|
+
*
|
|
12
|
+
* Child `supervisor.*` / `agent.*` events bubble through this same pipe
|
|
13
|
+
* unmodified (the turn forwards them as it observes them on the
|
|
14
|
+
* delegated run); they share the `{ type, ...payload }` shape with the
|
|
15
|
+
* orchestrator's own events so iteration narrows uniformly on
|
|
16
|
+
* `event.type`.
|
|
17
|
+
*/
|
|
18
|
+
function createOrchestratorStream() {
|
|
19
|
+
const queue = [];
|
|
20
|
+
const pending = [];
|
|
21
|
+
const handlers = /* @__PURE__ */ new Map();
|
|
22
|
+
let closed = false;
|
|
23
|
+
let failure;
|
|
24
|
+
let resolveResult;
|
|
25
|
+
let rejectResult;
|
|
26
|
+
const result = new Promise((resolve, reject) => {
|
|
27
|
+
resolveResult = resolve;
|
|
28
|
+
rejectResult = reject;
|
|
29
|
+
});
|
|
30
|
+
const controller = {
|
|
31
|
+
push(event) {
|
|
32
|
+
const handler = handlers.get(event.type);
|
|
33
|
+
if (handler) try {
|
|
34
|
+
handler(event);
|
|
35
|
+
} catch {}
|
|
36
|
+
const reader = pending.shift();
|
|
37
|
+
if (reader) {
|
|
38
|
+
reader.resolve({
|
|
39
|
+
value: event,
|
|
40
|
+
done: false
|
|
41
|
+
});
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
queue.push(event);
|
|
45
|
+
},
|
|
46
|
+
end(finalResult) {
|
|
47
|
+
closed = true;
|
|
48
|
+
resolveResult(finalResult);
|
|
49
|
+
while (pending.length > 0) pending.shift()?.resolve({
|
|
50
|
+
value: void 0,
|
|
51
|
+
done: true
|
|
52
|
+
});
|
|
53
|
+
},
|
|
54
|
+
fail(error) {
|
|
55
|
+
closed = true;
|
|
56
|
+
failure = error;
|
|
57
|
+
rejectResult(error);
|
|
58
|
+
while (pending.length > 0) pending.shift()?.reject(error);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
const iterator = { next() {
|
|
62
|
+
if (queue.length > 0) return Promise.resolve({
|
|
63
|
+
value: queue.shift(),
|
|
64
|
+
done: false
|
|
65
|
+
});
|
|
66
|
+
if (closed) {
|
|
67
|
+
if (failure) return Promise.reject(failure);
|
|
68
|
+
return Promise.resolve({
|
|
69
|
+
value: void 0,
|
|
70
|
+
done: true
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
return new Promise((resolve, reject) => {
|
|
74
|
+
pending.push({
|
|
75
|
+
resolve,
|
|
76
|
+
reject
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
} };
|
|
80
|
+
const stream = {
|
|
81
|
+
result,
|
|
82
|
+
on(handlerMap) {
|
|
83
|
+
for (const [key, handler] of Object.entries(handlerMap)) if (handler) handlers.set(key, handler);
|
|
84
|
+
return stream;
|
|
85
|
+
},
|
|
86
|
+
[Symbol.asyncIterator]() {
|
|
87
|
+
return iterator;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
return {
|
|
91
|
+
controller,
|
|
92
|
+
stream
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
//#endregion
|
|
97
|
+
export { createOrchestratorStream };
|
|
98
|
+
//# sourceMappingURL=orchestrator-stream.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orchestrator-stream.mjs","names":[],"sources":["../../../../../../../@warlock.js/ai/src/orchestrator/orchestrator-stream.ts"],"sourcesContent":["import type { OrchestratorEvent } from \"../contracts/orchestrator/orchestrator-event.type\";\nimport type { StreamContract } from \"../contracts/stream/stream.contract\";\n\n/**\n * Internal async-queue controller driving `orchestrator.stream()`.\n * Mirrors {@link import(\"../supervisor/supervisor-stream\").createSupervisorStream}'s\n * controller — same producer/consumer pipe, parameterized by the\n * orchestrator event union and the terminal result type.\n *\n * The turn pushes events as it advances through the lifecycle phases,\n * then settles with `end(result)` (the same `OrchestratorResult` that\n * `execute()` resolves) or `fail(error)` on an authoring/drift throw.\n */\nexport type OrchestratorStreamController<TResult> = {\n push(event: OrchestratorEvent): void;\n end(result: TResult): void;\n fail(error: Error): void;\n};\n\ntype PendingRead = {\n resolve(value: IteratorResult<OrchestratorEvent>): void;\n reject(error: Error): void;\n};\n\n/**\n * Factory mirroring `createSupervisorStream`. Returns a paired\n * `{ controller, stream }` — the turn pushes events into the controller\n * while the caller iterates (or awaits `.result`) on the stream side.\n *\n * The `result` promise resolves to the same `OrchestratorResult` value\n * `execute()` produces; it rejects only when the turn throws before\n * producing a result (drift / config misuse) — runtime failures ride on\n * `result.error` and still settle via `end()`.\n *\n * Child `supervisor.*` / `agent.*` events bubble through this same pipe\n * unmodified (the turn forwards them as it observes them on the\n * delegated run); they share the `{ type, ...payload }` shape with the\n * orchestrator's own events so iteration narrows uniformly on\n * `event.type`.\n */\nexport function createOrchestratorStream<TResult>(): {\n controller: OrchestratorStreamController<TResult>;\n stream: StreamContract<TResult, OrchestratorEvent>;\n} {\n const queue: OrchestratorEvent[] = [];\n const pending: PendingRead[] = [];\n const handlers = new Map<string, (event: OrchestratorEvent) => void>();\n\n let closed = false;\n let failure: Error | undefined;\n let resolveResult!: (value: TResult) => void;\n let rejectResult!: (error: Error) => void;\n\n const result = new Promise<TResult>((resolve, reject) => {\n resolveResult = resolve;\n rejectResult = reject;\n });\n\n const controller: OrchestratorStreamController<TResult> = {\n push(event) {\n const handler = handlers.get(event.type);\n\n if (handler) {\n try {\n handler(event);\n } catch {\n // Stream handlers must never crash the orchestrator.\n }\n }\n\n const reader = pending.shift();\n\n if (reader) {\n reader.resolve({ value: event, done: false });\n return;\n }\n\n queue.push(event);\n },\n\n end(finalResult) {\n closed = true;\n resolveResult(finalResult);\n\n while (pending.length > 0) {\n pending.shift()?.resolve({ value: undefined, done: true });\n }\n },\n\n fail(error) {\n closed = true;\n failure = error;\n rejectResult(error);\n\n while (pending.length > 0) {\n pending.shift()?.reject(error);\n }\n },\n };\n\n const iterator: AsyncIterator<OrchestratorEvent> = {\n next() {\n if (queue.length > 0) {\n return Promise.resolve({ value: queue.shift()!, done: false });\n }\n\n if (closed) {\n if (failure) {\n return Promise.reject(failure);\n }\n\n return Promise.resolve({ value: undefined, done: true });\n }\n\n return new Promise<IteratorResult<OrchestratorEvent>>(\n (resolve, reject) => {\n pending.push({ resolve, reject });\n },\n );\n },\n };\n\n const stream = {\n result,\n on(handlerMap) {\n for (const [key, handler] of Object.entries(handlerMap)) {\n if (handler) {\n handlers.set(key, handler as (event: OrchestratorEvent) => void);\n }\n }\n\n return stream;\n },\n [Symbol.asyncIterator]() {\n return iterator;\n },\n } as StreamContract<TResult, OrchestratorEvent>;\n\n return { controller, stream };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAwCA,SAAgB,2BAGd;CACA,MAAM,QAA6B,CAAC;CACpC,MAAM,UAAyB,CAAC;CAChC,MAAM,2BAAW,IAAI,IAAgD;CAErE,IAAI,SAAS;CACb,IAAI;CACJ,IAAI;CACJ,IAAI;CAEJ,MAAM,SAAS,IAAI,SAAkB,SAAS,WAAW;EACvD,gBAAgB;EAChB,eAAe;CACjB,CAAC;CAED,MAAM,aAAoD;EACxD,KAAK,OAAO;GACV,MAAM,UAAU,SAAS,IAAI,MAAM,IAAI;GAEvC,IAAI,SACF,IAAI;IACF,QAAQ,KAAK;GACf,QAAQ,CAER;GAGF,MAAM,SAAS,QAAQ,MAAM;GAE7B,IAAI,QAAQ;IACV,OAAO,QAAQ;KAAE,OAAO;KAAO,MAAM;IAAM,CAAC;IAC5C;GACF;GAEA,MAAM,KAAK,KAAK;EAClB;EAEA,IAAI,aAAa;GACf,SAAS;GACT,cAAc,WAAW;GAEzB,OAAO,QAAQ,SAAS,GACtB,QAAQ,MAAM,CAAC,EAAE,QAAQ;IAAE,OAAO;IAAW,MAAM;GAAK,CAAC;EAE7D;EAEA,KAAK,OAAO;GACV,SAAS;GACT,UAAU;GACV,aAAa,KAAK;GAElB,OAAO,QAAQ,SAAS,GACtB,QAAQ,MAAM,CAAC,EAAE,OAAO,KAAK;EAEjC;CACF;CAEA,MAAM,WAA6C,EACjD,OAAO;EACL,IAAI,MAAM,SAAS,GACjB,OAAO,QAAQ,QAAQ;GAAE,OAAO,MAAM,MAAM;GAAI,MAAM;EAAM,CAAC;EAG/D,IAAI,QAAQ;GACV,IAAI,SACF,OAAO,QAAQ,OAAO,OAAO;GAG/B,OAAO,QAAQ,QAAQ;IAAE,OAAO;IAAW,MAAM;GAAK,CAAC;EACzD;EAEA,OAAO,IAAI,SACR,SAAS,WAAW;GACnB,QAAQ,KAAK;IAAE;IAAS;GAAO,CAAC;EAClC,CACF;CACF,EACF;CAEA,MAAM,SAAS;EACb;EACA,GAAG,YAAY;GACb,KAAK,MAAM,CAAC,KAAK,YAAY,OAAO,QAAQ,UAAU,GACpD,IAAI,SACF,SAAS,IAAI,KAAK,OAA6C;GAInE,OAAO;EACT;EACA,CAAC,OAAO,iBAAiB;GACvB,OAAO;EACT;CACF;CAEA,OAAO;EAAE;EAAY;CAAO;AAC9B"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { SupervisorIntentValue } from "../contracts/supervisor/intent-entry.type.mjs";
|
|
2
|
+
import { OrchestratorContract } from "../contracts/orchestrator/orchestrator.contract.mjs";
|
|
3
|
+
import { OrchestratorConfig } from "../contracts/orchestrator/orchestrator-config.type.mjs";
|
|
4
|
+
|
|
5
|
+
//#region ../@warlock.js/ai/src/orchestrator/orchestrator.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* `ai.orchestrator(config)` — construct an {@link OrchestratorContract}:
|
|
8
|
+
* a session-state manager wrapped around a supervisor (orchestrator.md
|
|
9
|
+
* §1, §15). Validates the config at author time (throws
|
|
10
|
+
* {@link OrchestratorConfigError} on bad shape), resolves the intent
|
|
11
|
+
* entries, computes a stable structural signature for drift detection
|
|
12
|
+
* (§10.1), wires the three-tier event emitter, and returns a handle that
|
|
13
|
+
* runs one durable session turn per `execute` / `stream` call, resumes
|
|
14
|
+
* an interrupted `iterate: true` turn via `resume`, and exposes typed
|
|
15
|
+
* built-in commands plus an `asTool` wrapper.
|
|
16
|
+
*
|
|
17
|
+
* The "what runs" fields (`intents`, `route` / `router`, `evaluate`,
|
|
18
|
+
* `state`, `output`, `initialAgent`, `maxIterations`) are the
|
|
19
|
+
* supervisor's surface spread directly — the lifecycle builds the
|
|
20
|
+
* supervisor lazily per turn and delegates to it (§3 Phase 5). Users
|
|
21
|
+
* never see the supervisor object.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* const supportBot = ai.orchestrator<SessionState>({
|
|
25
|
+
* name: "refund-support",
|
|
26
|
+
* intents: { classify, lookup, process, compose },
|
|
27
|
+
* route: (ctx) => (ctx.iteration === 0 ? "classify" : END),
|
|
28
|
+
* iterate: true,
|
|
29
|
+
* checkpointStore: ai.checkpoint.pg({ client: pg }),
|
|
30
|
+
* snapshotStore: ai.snapshot.pg({ client: pg }),
|
|
31
|
+
* });
|
|
32
|
+
*
|
|
33
|
+
* const result = await supportBot.execute(message, { sessionId, history });
|
|
34
|
+
*/
|
|
35
|
+
declare function orchestrator<TOutput = unknown, TState = TOutput, TIntents extends Record<string, SupervisorIntentValue> = Record<string, SupervisorIntentValue>>(config: OrchestratorConfig<TOutput, TState, TIntents>): OrchestratorContract<TOutput, TState>;
|
|
36
|
+
//#endregion
|
|
37
|
+
export { orchestrator };
|
|
38
|
+
//# sourceMappingURL=orchestrator.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orchestrator.d.mts","names":[],"sources":["../../../../../../../@warlock.js/ai/src/orchestrator/orchestrator.ts"],"mappings":";;;;;;;AA4DA;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAgB,YAAA,6BAEL,OAAA,mBACQ,MAAA,SAAe,qBAAA,IAAyB,MAAA,SAEvD,qBAAA,GAGF,MAAA,EAAQ,kBAAA,CAAmB,OAAA,EAAS,MAAA,EAAQ,QAAA,IAC3C,oBAAA,CAAqB,OAAA,EAAS,MAAA"}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { SupervisorFailedError } from "../errors/supervisor-failed-error.mjs";
|
|
2
|
+
import { OrchestratorConfigError } from "../errors/orchestrator-config-error.mjs";
|
|
3
|
+
import "../errors/index.mjs";
|
|
4
|
+
import { resolveDefaultSnapshotStore } from "../config.mjs";
|
|
5
|
+
import { asTool } from "./as-tool.mjs";
|
|
6
|
+
import { createCommandDispatcher } from "./commands.mjs";
|
|
7
|
+
import { OrchestratorEmitter } from "./emitter.mjs";
|
|
8
|
+
import { resolveIntentEntries } from "../supervisor/entries.mjs";
|
|
9
|
+
import { OrchestratorExecution } from "./execution.mjs";
|
|
10
|
+
import { createOrchestratorStream } from "./orchestrator-stream.mjs";
|
|
11
|
+
import { computeOrchestratorSignature } from "./signature.mjs";
|
|
12
|
+
|
|
13
|
+
//#region ../@warlock.js/ai/src/orchestrator/orchestrator.ts
|
|
14
|
+
/**
|
|
15
|
+
* `ai.orchestrator(config)` — construct an {@link OrchestratorContract}:
|
|
16
|
+
* a session-state manager wrapped around a supervisor (orchestrator.md
|
|
17
|
+
* §1, §15). Validates the config at author time (throws
|
|
18
|
+
* {@link OrchestratorConfigError} on bad shape), resolves the intent
|
|
19
|
+
* entries, computes a stable structural signature for drift detection
|
|
20
|
+
* (§10.1), wires the three-tier event emitter, and returns a handle that
|
|
21
|
+
* runs one durable session turn per `execute` / `stream` call, resumes
|
|
22
|
+
* an interrupted `iterate: true` turn via `resume`, and exposes typed
|
|
23
|
+
* built-in commands plus an `asTool` wrapper.
|
|
24
|
+
*
|
|
25
|
+
* The "what runs" fields (`intents`, `route` / `router`, `evaluate`,
|
|
26
|
+
* `state`, `output`, `initialAgent`, `maxIterations`) are the
|
|
27
|
+
* supervisor's surface spread directly — the lifecycle builds the
|
|
28
|
+
* supervisor lazily per turn and delegates to it (§3 Phase 5). Users
|
|
29
|
+
* never see the supervisor object.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* const supportBot = ai.orchestrator<SessionState>({
|
|
33
|
+
* name: "refund-support",
|
|
34
|
+
* intents: { classify, lookup, process, compose },
|
|
35
|
+
* route: (ctx) => (ctx.iteration === 0 ? "classify" : END),
|
|
36
|
+
* iterate: true,
|
|
37
|
+
* checkpointStore: ai.checkpoint.pg({ client: pg }),
|
|
38
|
+
* snapshotStore: ai.snapshot.pg({ client: pg }),
|
|
39
|
+
* });
|
|
40
|
+
*
|
|
41
|
+
* const result = await supportBot.execute(message, { sessionId, history });
|
|
42
|
+
*/
|
|
43
|
+
function orchestrator(config) {
|
|
44
|
+
validateFactoryConfig(config);
|
|
45
|
+
const entries = resolveEntries(config);
|
|
46
|
+
assertInitialAgent(config, entries);
|
|
47
|
+
const signature = computeOrchestratorSignature(config, entries);
|
|
48
|
+
const emitter = new OrchestratorEmitter(config.on);
|
|
49
|
+
async function execute(input, options) {
|
|
50
|
+
return new OrchestratorExecution({
|
|
51
|
+
config,
|
|
52
|
+
entries,
|
|
53
|
+
signature,
|
|
54
|
+
emitter,
|
|
55
|
+
input,
|
|
56
|
+
options
|
|
57
|
+
}).run();
|
|
58
|
+
}
|
|
59
|
+
function stream(input, options) {
|
|
60
|
+
const { controller, stream: contract } = createOrchestratorStream();
|
|
61
|
+
new OrchestratorExecution({
|
|
62
|
+
config,
|
|
63
|
+
entries,
|
|
64
|
+
signature,
|
|
65
|
+
emitter,
|
|
66
|
+
input,
|
|
67
|
+
options,
|
|
68
|
+
streamController: controller
|
|
69
|
+
}).run();
|
|
70
|
+
return contract;
|
|
71
|
+
}
|
|
72
|
+
async function resume(sessionId, options) {
|
|
73
|
+
return new OrchestratorExecution({
|
|
74
|
+
config,
|
|
75
|
+
entries,
|
|
76
|
+
signature,
|
|
77
|
+
emitter,
|
|
78
|
+
resumeSessionId: sessionId,
|
|
79
|
+
resumeOptions: options
|
|
80
|
+
}).resume();
|
|
81
|
+
}
|
|
82
|
+
const command = createCommandDispatcher({ compact: (args) => {
|
|
83
|
+
return new OrchestratorExecution({
|
|
84
|
+
config,
|
|
85
|
+
entries,
|
|
86
|
+
signature,
|
|
87
|
+
emitter
|
|
88
|
+
}).compact(args);
|
|
89
|
+
} });
|
|
90
|
+
const instance = {
|
|
91
|
+
name: config.name,
|
|
92
|
+
signature,
|
|
93
|
+
version: config.version,
|
|
94
|
+
execute,
|
|
95
|
+
stream,
|
|
96
|
+
resume,
|
|
97
|
+
command,
|
|
98
|
+
asTool(options) {
|
|
99
|
+
return asTool(instance, options);
|
|
100
|
+
},
|
|
101
|
+
on(event, handler) {
|
|
102
|
+
return emitter.on(event, handler);
|
|
103
|
+
},
|
|
104
|
+
off(event, handler) {
|
|
105
|
+
emitter.off(event, handler);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
return instance;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Author-time validation (orchestrator.md §17). Enforces the rules that
|
|
112
|
+
* must fail at construction rather than on the first turn:
|
|
113
|
+
*
|
|
114
|
+
* - `name` present and a string.
|
|
115
|
+
* - `intents` present.
|
|
116
|
+
* - `route` XOR `router` (mutually exclusive; at least one required) —
|
|
117
|
+
* the supervisor's dispatch-source rule, surfaced as an orchestrator
|
|
118
|
+
* config error.
|
|
119
|
+
* - `router` is a valid agent contract or `{ agent, ... }` entry.
|
|
120
|
+
* - `maxIterations >= 1` when set.
|
|
121
|
+
* - `snapshotStore` resolvable when `iterate: true` — explicit field or
|
|
122
|
+
* the global `ai.config({ defaultSnapshotStore })` fallback.
|
|
123
|
+
*
|
|
124
|
+
* `initialAgent` membership is checked separately once the intent
|
|
125
|
+
* entries are resolved.
|
|
126
|
+
*/
|
|
127
|
+
function validateFactoryConfig(config) {
|
|
128
|
+
if (!config.name || typeof config.name !== "string") throw new OrchestratorConfigError("ai.orchestrator: `name` is required and must be a string", { context: { authoring: true } });
|
|
129
|
+
if (!config.intents || typeof config.intents !== "object") throw new OrchestratorConfigError(`ai.orchestrator("${config.name}"): \`intents\` is required`, { context: { authoring: true } });
|
|
130
|
+
const hasRoute = typeof config.route === "function";
|
|
131
|
+
const hasRouter = Boolean(config.router);
|
|
132
|
+
if (hasRouter) {
|
|
133
|
+
const router = config.router;
|
|
134
|
+
const isBareAgent = typeof router.execute === "function";
|
|
135
|
+
const isEntryForm = !isBareAgent && typeof router.agent === "object" && typeof router.agent?.execute === "function";
|
|
136
|
+
if (!isBareAgent && !isEntryForm) throw new OrchestratorConfigError(`ai.orchestrator("${config.name}"): \`router\` must be an agent contract or a \`{ agent, placeholders?, input? }\` entry`, { context: { authoring: true } });
|
|
137
|
+
}
|
|
138
|
+
if (hasRoute && hasRouter) throw new OrchestratorConfigError(`ai.orchestrator("${config.name}"): \`route\` and \`router\` are mutually exclusive — configure exactly one`, { context: { authoring: true } });
|
|
139
|
+
if (!hasRoute && !hasRouter) throw new OrchestratorConfigError(`ai.orchestrator("${config.name}"): one of \`route\` or \`router\` is required`, { context: { authoring: true } });
|
|
140
|
+
if (config.maxIterations !== void 0 && config.maxIterations < 1) throw new OrchestratorConfigError(`ai.orchestrator("${config.name}"): \`maxIterations\` must be >= 1`, { context: {
|
|
141
|
+
authoring: true,
|
|
142
|
+
maxIterations: config.maxIterations
|
|
143
|
+
} });
|
|
144
|
+
if (config.iterate && !config.snapshotStore && !resolveDefaultSnapshotStore()) throw new OrchestratorConfigError(`ai.orchestrator("${config.name}"): \`iterate: true\` requires a \`snapshotStore\` (or \`ai.config({ defaultSnapshotStore })\`) for mid-turn resume`, { context: { authoring: true } });
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Resolve the `intents` map into the supervisor's internal entry shape,
|
|
148
|
+
* re-wrapping the supervisor's authoring failure as an
|
|
149
|
+
* {@link OrchestratorConfigError} so misuse surfaces under the
|
|
150
|
+
* orchestrator's error family rather than the supervisor's.
|
|
151
|
+
*/
|
|
152
|
+
function resolveEntries(config) {
|
|
153
|
+
try {
|
|
154
|
+
return resolveIntentEntries(config.intents, config.name);
|
|
155
|
+
} catch (error) {
|
|
156
|
+
if (error instanceof SupervisorFailedError) throw new OrchestratorConfigError(error.message, {
|
|
157
|
+
context: { authoring: true },
|
|
158
|
+
cause: error
|
|
159
|
+
});
|
|
160
|
+
throw error;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Enforce the `initialAgent` membership rule (§17) once entries are
|
|
165
|
+
* resolved — `initialAgent`, when set, must name a key in `intents`.
|
|
166
|
+
*/
|
|
167
|
+
function assertInitialAgent(config, entries) {
|
|
168
|
+
if (config.initialAgent && !entries.has(config.initialAgent)) throw new OrchestratorConfigError(`ai.orchestrator("${config.name}"): \`initialAgent\` "${config.initialAgent}" is not a key in \`intents\``, { context: { authoring: true } });
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
//#endregion
|
|
172
|
+
export { orchestrator };
|
|
173
|
+
//# sourceMappingURL=orchestrator.mjs.map
|