@qlairoslabs/acp-client 0.12.1 → 0.13.0-alpha.1
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-consumer-fixes.md +17 -10
- package/CHANGELOG-controller-interface.md +258 -0
- package/CHANGELOG-metering.md +29 -0
- package/CHANGELOG-operation-lifecycle.md +15 -1
- package/CONSUMER_GUIDE.md +845 -6
- package/MIGRATION-0.10-to-0.12.md +4 -1
- package/MIGRATION-0.12-to-0.13.md +275 -0
- package/README.md +17 -16
- package/package.json +4 -2
- package/src/acp-client-handlers.ts +48 -0
- package/src/activity.ts +3 -0
- package/src/adapters.ts +25 -0
- package/src/agent/adoption/provider-attachment.ts +33 -0
- package/src/agent/adoption/provider-session-delete.ts +1 -1
- package/src/agent/adoption/provider-sessions.ts +3 -2
- package/src/agent/append-assistant-message.ts +91 -0
- package/src/agent/config.ts +54 -6
- package/src/agent/conversation-manager.ts +94 -158
- package/src/agent/manager-settings.ts +1 -0
- package/src/agent/native-channel-lifecycle.ts +111 -0
- package/src/agent/persisted-lifecycle.ts +44 -4
- package/src/agent/persistence-policy/context.ts +13 -0
- package/src/agent/persistence-policy/resolver.ts +7 -0
- package/src/agent/persistence-policy/types.ts +1 -0
- package/src/agent/record-capture.ts +1 -0
- package/src/agent-adapter-registry.ts +33 -7
- package/src/agent-conversation-contracts.ts +14 -1
- package/src/agent-conversation-errors.ts +8 -0
- package/src/agent-conversation-owner.ts +9 -4
- package/src/agent-session-config.ts +135 -0
- package/src/agent-session.ts +439 -934
- package/src/agent.ts +73 -0
- package/src/capabilities.ts +2 -0
- package/src/checkpointing/recovery.ts +3 -0
- package/src/cli/index.ts +3 -3
- package/src/cli/managed.ts +2 -2
- package/src/client.ts +52 -94
- package/src/connection-attempt.ts +95 -0
- package/src/controller-connection.ts +114 -0
- package/src/controller.ts +156 -148
- package/src/conversation-controller/capabilities.ts +88 -0
- package/src/conversation-controller/contracts.ts +208 -0
- package/src/conversation-controller/factory.ts +39 -0
- package/src/conversation-controller/guards.ts +98 -0
- package/src/conversation-controller/index.ts +20 -0
- package/src/conversation-startup.ts +35 -0
- package/src/conversation-turns/backend-turns.ts +373 -0
- package/src/conversation-turns/clear-operations.ts +37 -0
- package/src/conversation-turns/context.ts +135 -0
- package/src/conversation-turns/index.ts +4 -0
- package/src/conversation-turns/record-helpers.ts +75 -0
- package/src/conversation-turns/recording.ts +235 -0
- package/src/conversation-turns/run-turn.ts +367 -0
- package/src/conversation-turns/turn-run.ts +57 -0
- package/src/errors.ts +41 -0
- package/src/handoff-options.ts +81 -0
- package/src/identity/checkpoint-backed.ts +1 -1
- package/src/index.ts +58 -3
- package/src/internal-inference/coordination/manager.ts +11 -0
- package/src/internal-inference/runtime/harness-runtime.ts +4 -4
- package/src/launcher.ts +35 -2
- package/src/media/parts.ts +5 -0
- package/src/message-status.ts +83 -0
- package/src/metering/engine.ts +39 -64
- package/src/metering/measurement-provenance.ts +36 -0
- package/src/metering/native/durability.ts +115 -0
- package/src/metering/native/ledger.ts +104 -0
- package/src/metering/native/operation.ts +85 -0
- package/src/metering/native/projection.ts +114 -0
- package/src/metering/native/proof.ts +51 -0
- package/src/metering/native/requirements.ts +10 -0
- package/src/metering/native/retirement.ts +92 -0
- package/src/metering/native/source.ts +90 -0
- package/src/metering/record.ts +38 -1
- package/src/metering/state.ts +13 -3
- package/src/native/approvals.ts +169 -0
- package/src/native/capabilities.ts +17 -0
- package/src/native/channel-changes.ts +211 -0
- package/src/native/connection.ts +56 -0
- package/src/native/controller.ts +591 -0
- package/src/native/delegation-sender.ts +26 -0
- package/src/native/errors.ts +35 -0
- package/src/native/functions.ts +156 -0
- package/src/native/host-config.ts +59 -0
- package/src/native/host.ts +909 -0
- package/src/native/item-receipts.ts +15 -0
- package/src/native/metering.ts +12 -0
- package/src/native/records.ts +166 -0
- package/src/native/recovery.ts +186 -0
- package/src/native/reminders/fixtures/schema21.sqlite.gz +0 -0
- package/src/native/reminders/idle.ts +70 -0
- package/src/native/reminders/limits.ts +19 -0
- package/src/native/reminders/notifications.ts +29 -0
- package/src/native/reminders/reminders.test.ts +553 -0
- package/src/native/reminders/routine-config.typecheck.ts +13 -0
- package/src/native/reminders/routine-guard.ts +66 -0
- package/src/native/reminders/routine-schedule.ts +25 -0
- package/src/native/reminders/routine-wire.ts +21 -0
- package/src/native/reminders/schedule.ts +97 -0
- package/src/native/reminders/service.ts +280 -0
- package/src/native/reminders/supervisor.ts +91 -0
- package/src/native/reminders/sync.ts +301 -0
- package/src/native/reminders/wire.ts +197 -0
- package/src/native/reminders/wire.typecheck.ts +13 -0
- package/src/native/submission-withdrawal.ts +65 -0
- package/src/native/usage.ts +15 -0
- package/src/native/worker-delivery.ts +61 -0
- package/src/native-harness/.res/README.md +1 -0
- package/src/native-harness/.res/architecture/README.md +21 -0
- package/src/native-harness/.res/architecture/context-and-data.md +31 -0
- package/src/native-harness/.res/architecture/execution.md +42 -0
- package/src/native-harness/.res/architecture/overview.md +44 -0
- package/src/native-harness/.res/architecture/persistence.md +56 -0
- package/src/native-harness/.res/architecture/suspend-and-resume.md +45 -0
- package/src/native-harness/.res/architecture/technical-architecture.md +50 -0
- package/src/native-harness/.res/decisions/0001-basic-loop.md +11 -0
- package/src/native-harness/.res/decisions/0002-channel-input.md +17 -0
- package/src/native-harness/.res/decisions/0003-inference-inspection.md +14 -0
- package/src/native-harness/.res/decisions/0004-shared-context.md +21 -0
- package/src/native-harness/.res/decisions/0005-notice-inbox.md +20 -0
- package/src/native-harness/.res/decisions/0006-explicit-notices.md +12 -0
- package/src/native-harness/.res/decisions/0007-channel-output.md +12 -0
- package/src/native-harness/.res/decisions/0008-browser-client.md +16 -0
- package/src/native-harness/.res/decisions/0009-scripted-model.md +18 -0
- package/src/native-harness/.res/decisions/0010-inprocess-protocol.md +19 -0
- package/src/native-harness/.res/decisions/0011-stdio-transport.md +21 -0
- package/src/native-harness/.res/decisions/0012-session-storage-contract.md +37 -0
- package/src/native-harness/.res/decisions/0013-durable-delivery-contract.md +64 -0
- package/src/native-harness/.res/decisions/0014-channel-controls-contract.md +73 -0
- package/src/native-harness/.res/decisions/0015-session-file-contract.md +72 -0
- package/src/native-harness/.res/decisions/0016-configuration-permissions.md +159 -0
- package/src/native-harness/.res/decisions/0017-openrouter-managed-config.md +69 -0
- package/src/native-harness/.res/decisions/0018-tool-dispatch-evidence.md +78 -0
- package/src/native-harness/.res/decisions/0019-model-execution.md +188 -0
- package/src/native-harness/.res/decisions/0020-startup-channel-changes.md +71 -0
- package/src/native-harness/.res/decisions/0021-tools-and-host-callbacks.md +100 -0
- package/src/native-harness/.res/decisions/0022-operator-controls.md +115 -0
- package/src/native-harness/.res/decisions/0023-long-running-mock.md +82 -0
- package/src/native-harness/.res/decisions/0024-callback-policy-names.md +46 -0
- package/src/native-harness/.res/decisions/0025-external-notices.md +364 -0
- package/src/native-harness/.res/decisions/0026-bounded-context.md +81 -0
- package/src/native-harness/.res/decisions/0027-development-instructions.md +22 -0
- package/src/native-harness/.res/decisions/0028-debug-tools.md +16 -0
- package/src/native-harness/.res/decisions/0029-bounded-model-call-pages.md +37 -0
- package/src/native-harness/.res/decisions/0030-timeline-retrieval.md +145 -0
- package/src/native-harness/.res/decisions/0031-one-off-reminders.md +173 -0
- package/src/native-harness/.res/docs/11-15.md +148 -0
- package/src/native-harness/.res/docs/BUSINESS_RULES.md +111 -0
- package/src/native-harness/.res/docs/WORK.md +65 -0
- package/src/native-harness/.res/docs/_/11-16-persistence/LOG.md +312 -0
- package/src/native-harness/.res/docs/_/11-16-persistence/PLAN.md +77 -0
- package/src/native-harness/.res/docs/_/11-16-persistence/SPEC.md +313 -0
- package/src/native-harness/.res/docs/_/11-19-channel-controls/LOG.md +160 -0
- package/src/native-harness/.res/docs/_/11-19-channel-controls/PLAN.md +89 -0
- package/src/native-harness/.res/docs/_/11-19-channel-controls/SPEC.md +135 -0
- package/src/native-harness/.res/docs/_/11-19-config-permissions/LOG.md +143 -0
- package/src/native-harness/.res/docs/_/11-19-config-permissions/PLAN.md +93 -0
- package/src/native-harness/.res/docs/_/11-19-config-permissions/SPEC.md +181 -0
- package/src/native-harness/.res/docs/acp-client-integration/0001-DESIGN/11-20-LOG.md +433 -0
- package/src/native-harness/.res/docs/acp-client-integration/0001-DESIGN/PLAN.md +60 -0
- package/src/native-harness/.res/docs/acp-client-integration/0001-DESIGN/PROTOCOL.md +141 -0
- package/src/native-harness/.res/docs/acp-client-integration/0001-DESIGN/SPEC.md +168 -0
- package/src/native-harness/.res/docs/attachments/0001-DESIGN/SPEC.md +111 -0
- package/src/native-harness/.res/docs/bounded-context/0001-DESIGN/PLAN.md +129 -0
- package/src/native-harness/.res/docs/bounded-context/0001-DESIGN/SPEC.md +135 -0
- package/src/native-harness/.res/docs/channel-messaging/0001-DESIGN-external-notices/LOG.md +437 -0
- package/src/native-harness/.res/docs/channel-messaging/0001-DESIGN-external-notices/PLAN.md +127 -0
- package/src/native-harness/.res/docs/channel-messaging/0001-DESIGN-external-notices/SPEC.md +203 -0
- package/src/native-harness/.res/docs/long-running-mock/0001-DESIGN/LOG.md +292 -0
- package/src/native-harness/.res/docs/long-running-mock/0001-DESIGN/PLAN.md +91 -0
- package/src/native-harness/.res/docs/long-running-mock/0001-DESIGN/SPEC.md +187 -0
- package/src/native-harness/.res/docs/model-execution/0001-DESIGN/LOG.md +148 -0
- package/src/native-harness/.res/docs/model-execution/0001-DESIGN/PLAN.md +95 -0
- package/src/native-harness/.res/docs/model-execution/0001-DESIGN/SPEC.md +200 -0
- package/src/native-harness/.res/docs/model-execution/0002-AMENDMENT-accounting/SPEC.md +80 -0
- package/src/native-harness/.res/docs/operator-controls/0001-DESIGN/LOG.md +206 -0
- package/src/native-harness/.res/docs/operator-controls/0001-DESIGN/PLAN.md +106 -0
- package/src/native-harness/.res/docs/operator-controls/0001-DESIGN/SPEC.md +297 -0
- package/src/native-harness/.res/docs/persistence/0002-AMENDMENT-session-file/LOG.md +41 -0
- package/src/native-harness/.res/docs/persistence/0002-AMENDMENT-session-file/PLAN.md +36 -0
- package/src/native-harness/.res/docs/persistence/0002-AMENDMENT-session-file/SPEC.md +84 -0
- package/src/native-harness/.res/docs/shell-execution/0001-DESIGN/SPEC.md +147 -0
- package/src/native-harness/.res/docs/timeline-retrieval/0001-DESIGN/LOG.md +15 -0
- package/src/native-harness/.res/docs/timeline-retrieval/0001-DESIGN/PLAN.md +107 -0
- package/src/native-harness/.res/docs/timeline-retrieval/0001-DESIGN/SPEC.md +114 -0
- package/src/native-harness/.res/docs/todos/11-19-TODO-auto_review-approve.md +24 -0
- package/src/native-harness/.res/docs/todos/11-20-TODO-user-entered-tool-code.md +23 -0
- package/src/native-harness/.res/docs/todos/11-21-TODO-node-resource-coordination.md +103 -0
- package/src/native-harness/.res/docs/todos/11-22-TODO-harness-m1-sequence.md +50 -0
- package/src/native-harness/.res/docs/tools-and-callbacks/0001-DESIGN/LOG.md +337 -0
- package/src/native-harness/.res/docs/tools-and-callbacks/0001-DESIGN/PLAN.md +76 -0
- package/src/native-harness/.res/docs/tools-and-callbacks/0001-DESIGN/SPEC.md +204 -0
- package/src/native-harness/.res/docs/tools-and-callbacks/0002-AMENDMENT-callback-policy/LOG.md +73 -0
- package/src/native-harness/.res/docs/tools-and-callbacks/0002-AMENDMENT-callback-policy/SPEC.md +64 -0
- package/src/native-harness/.res/docs/tools-and-callbacks/0003-DESIGN-attachment-tools/SPEC.md +58 -0
- package/src/native-harness/.res/docs/tools-and-callbacks/0004-DESIGN-reminder-tools/LOG.md +45 -0
- package/src/native-harness/.res/docs/tools-and-callbacks/0004-DESIGN-reminder-tools/PLAN.md +108 -0
- package/src/native-harness/.res/docs/tools-and-callbacks/0004-DESIGN-reminder-tools/SPEC.md +169 -0
- package/src/native-harness/.res/docs/web-tools/0001-DESIGN/SPEC.md +128 -0
- package/src/native-harness/.res/marketing-draft.md +22 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/README.md +285 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-1.md +19 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-10.md +138 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-11.md +148 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-12.md +172 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-13.md +194 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-14.md +233 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-15.md +249 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-16.md +265 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-17.md +279 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-18.md +293 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-19.md +307 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-2.md +29 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-20.md +317 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-21.md +327 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-3.md +40 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-4.md +59 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-5.md +69 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-6.md +79 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-7.md +89 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-8.md +102 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-9.md +116 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation.jsonl +49 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/doc.md +87 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/harness.py +289 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/local/harness copy 2.py +221 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/local/harness copy 3.py +287 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/local/harness copy.py +165 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/state.json +22 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/system-prompt.md +2 -0
- package/src/native-harness/AGENTS.md +70 -0
- package/src/native-harness/ARCHITECTURE.md +249 -0
- package/src/native-harness/README.md +726 -0
- package/src/native-harness/bun.lock +26 -0
- package/src/native-harness/package.json +24 -0
- package/src/native-harness/src/capabilities/context/build.ts +59 -0
- package/src/native-harness/src/capabilities/context/instructions/agent-demo.md +11 -0
- package/src/native-harness/src/capabilities/context/instructions/agent.md +5 -0
- package/src/native-harness/src/capabilities/context/instructions/harness.md +7 -0
- package/src/native-harness/src/capabilities/context/load-instructions.ts +22 -0
- package/src/native-harness/src/capabilities/context/session.ts +92 -0
- package/src/native-harness/src/capabilities/model/attempt.ts +27 -0
- package/src/native-harness/src/capabilities/model/openrouter-stream.ts +72 -0
- package/src/native-harness/src/capabilities/model/openrouter.ts +62 -0
- package/src/native-harness/src/capabilities/model/runner.ts +116 -0
- package/src/native-harness/src/capabilities/model/scenario-attempt.ts +50 -0
- package/src/native-harness/src/capabilities/model/scenario-file.ts +125 -0
- package/src/native-harness/src/capabilities/model/scripted-error.ts +6 -0
- package/src/native-harness/src/capabilities/model/scripted.ts +81 -0
- package/src/native-harness/src/capabilities/model/usage.ts +15 -0
- package/src/native-harness/src/capabilities/tools/builtin/current-time.ts +28 -0
- package/src/native-harness/src/capabilities/tools/builtin/notify-channel.ts +17 -0
- package/src/native-harness/src/capabilities/tools/debug/index.ts +13 -0
- package/src/native-harness/src/capabilities/tools/debug/result.ts +12 -0
- package/src/native-harness/src/capabilities/tools/debug/test-echo.ts +16 -0
- package/src/native-harness/src/capabilities/tools/debug/test-fail.ts +14 -0
- package/src/native-harness/src/capabilities/tools/debug/test-wait.ts +19 -0
- package/src/native-harness/src/capabilities/tools/reminders/index.ts +75 -0
- package/src/native-harness/src/capabilities/tools/runtime/catalog.ts +103 -0
- package/src/native-harness/src/capabilities/tools/runtime/functions.ts +130 -0
- package/src/native-harness/src/capabilities/tools/runtime/invocations.ts +48 -0
- package/src/native-harness/src/capabilities/tools/testing/echo.ts +18 -0
- package/src/native-harness/src/capabilities/tools/testing/record.ts +47 -0
- package/src/native-harness/src/capabilities/tools/timeline/index.ts +41 -0
- package/src/native-harness/src/client.ts +18 -0
- package/src/native-harness/src/contracts/agent.ts +105 -0
- package/src/native-harness/src/contracts/config-permissions.ts +47 -0
- package/src/native-harness/src/contracts/context.ts +112 -0
- package/src/native-harness/src/contracts/events.ts +47 -0
- package/src/native-harness/src/contracts/input-limits.ts +7 -0
- package/src/native-harness/src/contracts/inspection.ts +22 -0
- package/src/native-harness/src/contracts/loop.ts +31 -0
- package/src/native-harness/src/contracts/model-execution.ts +83 -0
- package/src/native-harness/src/contracts/operator-controls.ts +106 -0
- package/src/native-harness/src/contracts/output.ts +13 -0
- package/src/native-harness/src/contracts/protocol.ts +320 -0
- package/src/native-harness/src/contracts/reminders.ts +132 -0
- package/src/native-harness/src/contracts/scenario.ts +42 -0
- package/src/native-harness/src/contracts/session-file.ts +19 -0
- package/src/native-harness/src/contracts/session.ts +184 -0
- package/src/native-harness/src/contracts/storage.ts +596 -0
- package/src/native-harness/src/contracts/timeline-retrieval.ts +40 -0
- package/src/native-harness/src/contracts/tools.ts +133 -0
- package/src/native-harness/src/governance/permissions/gate.ts +129 -0
- package/src/native-harness/src/governance/policy/resolve.ts +32 -0
- package/src/native-harness/src/index.ts +318 -0
- package/src/native-harness/src/interfaces/cli/chat.ts +83 -0
- package/src/native-harness/src/interfaces/cli/development.ts +145 -0
- package/src/native-harness/src/interfaces/cli/format-reply.ts +27 -0
- package/src/native-harness/src/interfaces/cli/listeners.ts +74 -0
- package/src/native-harness/src/interfaces/cli/main.ts +47 -0
- package/src/native-harness/src/interfaces/cli/scenario.ts +37 -0
- package/src/native-harness/src/interfaces/cli/serve.ts +21 -0
- package/src/native-harness/src/interfaces/cli/start.ts +106 -0
- package/src/native-harness/src/interfaces/client.ts +225 -0
- package/src/native-harness/src/interfaces/inspector/index.html +283 -0
- package/src/native-harness/src/interfaces/inspector/observe.ts +35 -0
- package/src/native-harness/src/interfaces/inspector/server.ts +56 -0
- package/src/native-harness/src/interfaces/inspector/state.ts +92 -0
- package/src/native-harness/src/interfaces/protocol/channel-changes.ts +153 -0
- package/src/native-harness/src/interfaces/protocol/framing.ts +47 -0
- package/src/native-harness/src/interfaces/protocol/functions.ts +87 -0
- package/src/native-harness/src/interfaces/protocol/in-process.ts +67 -0
- package/src/native-harness/src/interfaces/protocol/live-queue.ts +55 -0
- package/src/native-harness/src/interfaces/protocol/load.ts +60 -0
- package/src/native-harness/src/interfaces/protocol/local.ts +120 -0
- package/src/native-harness/src/interfaces/protocol/operator.ts +120 -0
- package/src/native-harness/src/interfaces/protocol/output.ts +59 -0
- package/src/native-harness/src/interfaces/protocol/server.ts +517 -0
- package/src/native-harness/src/interfaces/protocol/stdio-client.ts +119 -0
- package/src/native-harness/src/interfaces/protocol/stdio-server.ts +82 -0
- package/src/native-harness/src/interfaces/protocol/subscribe.ts +41 -0
- package/src/native-harness/src/interfaces/protocol/transfers.ts +146 -0
- package/src/native-harness/src/interfaces/web-chat/index.html +94 -0
- package/src/native-harness/src/interfaces/web-chat/server.ts +34 -0
- package/src/native-harness/src/kernel/channels.ts +405 -0
- package/src/native-harness/src/kernel/loop.ts +45 -0
- package/src/native-harness/src/runtime/config/development.ts +23 -0
- package/src/native-harness/src/runtime/config/managed.ts +2 -0
- package/src/native-harness/src/runtime/config/paths.ts +27 -0
- package/src/native-harness/src/runtime/reminder-timer.ts +42 -0
- package/src/native-harness/src/runtime/reminder-validation.ts +104 -0
- package/src/native-harness/src/runtime/reminders.ts +66 -0
- package/src/native-harness/src/state/storage/archive.ts +239 -0
- package/src/native-harness/src/state/storage/engine.ts +1013 -0
- package/src/native-harness/src/state/storage/inference.ts +124 -0
- package/src/native-harness/src/state/storage/memory-reminders.ts +78 -0
- package/src/native-harness/src/state/storage/memory.ts +341 -0
- package/src/native-harness/src/state/storage/policy-metadata.ts +32 -0
- package/src/native-harness/src/state/storage/reminder-archive.ts +63 -0
- package/src/native-harness/src/state/storage/reminder-change.ts +92 -0
- package/src/native-harness/src/state/storage/reminder-tables.ts +27 -0
- package/src/native-harness/src/state/storage/retrieval.ts +122 -0
- package/src/native-harness/src/state/storage/script-identity.ts +7 -0
- package/src/native-harness/src/state/storage/session-file.ts +85 -0
- package/src/native-harness/src/state/storage/sqlite-reminders.ts +134 -0
- package/src/native-harness/src/state/storage/sqlite.ts +625 -0
- package/src/native-harness/src/testing.ts +190 -0
- package/src/native-harness/src/util/config.ts +58 -0
- package/src/native-harness/src/util/json.ts +41 -0
- package/src/native-harness/src/util/message-position.ts +3 -0
- package/src/native-harness/src/util/reminder-schedule.ts +44 -0
- package/src/native-harness/src/util/schema.ts +40 -0
- package/src/native-harness/src/util/timeline-text.ts +72 -0
- package/src/native-harness/src/util/timeline-tool-names.ts +3 -0
- package/src/native-harness/test/agent.test.ts +130 -0
- package/src/native-harness/test/approval-gate.test.ts +255 -0
- package/src/native-harness/test/approval-protocol.test.ts +94 -0
- package/src/native-harness/test/boundaries.test.ts +18 -0
- package/src/native-harness/test/channel-controls.test.ts +322 -0
- package/src/native-harness/test/client-abort.test.ts +136 -0
- package/src/native-harness/test/config-policy.test.ts +301 -0
- package/src/native-harness/test/conformance/storage.ts +1141 -0
- package/src/native-harness/test/context.test.ts +177 -0
- package/src/native-harness/test/crash.test.ts +187 -0
- package/src/native-harness/test/debug-tools.test.ts +67 -0
- package/src/native-harness/test/development-cli.test.ts +67 -0
- package/src/native-harness/test/development.test.ts +171 -0
- package/src/native-harness/test/dispatch-evidence.test.ts +58 -0
- package/src/native-harness/test/e2e.test.ts +186 -0
- package/src/native-harness/test/external-notices.test.ts +101 -0
- package/src/native-harness/test/fixtures/approval-e2e.jsonl +4 -0
- package/src/native-harness/test/fixtures/crash-scenario.jsonl +5 -0
- package/src/native-harness/test/fixtures/development-lifecycle.jsonl +10 -0
- package/src/native-harness/test/fixtures/echo-scenario.jsonl +3 -0
- package/src/native-harness/test/fixtures/format2-schema.ts +27 -0
- package/src/native-harness/test/fixtures/format3-schema.ts +16 -0
- package/src/native-harness/test/fixtures/hold-scenario.jsonl +4 -0
- package/src/native-harness/test/fixtures/model-e2e.jsonl +3 -0
- package/src/native-harness/test/fixtures/storage-owner.ts +20 -0
- package/src/native-harness/test/format-reply.test.ts +10 -0
- package/src/native-harness/test/helpers/operator-view.ts +41 -0
- package/src/native-harness/test/helpers/scenario.ts +9 -0
- package/src/native-harness/test/helpers/session.ts +38 -0
- package/src/native-harness/test/helpers/stdio.ts +46 -0
- package/src/native-harness/test/inspector.test.ts +77 -0
- package/src/native-harness/test/listeners.test.ts +49 -0
- package/src/native-harness/test/loop.test.ts +88 -0
- package/src/native-harness/test/model-channel-double.test.ts +87 -0
- package/src/native-harness/test/model-crash.test.ts +62 -0
- package/src/native-harness/test/model-delivery-regressions.test.ts +55 -0
- package/src/native-harness/test/model-e2e.test.ts +71 -0
- package/src/native-harness/test/model-final-filter.test.ts +30 -0
- package/src/native-harness/test/model-large-reply.test.ts +28 -0
- package/src/native-harness/test/model-live-queue.test.ts +33 -0
- package/src/native-harness/test/model-runner.test.ts +117 -0
- package/src/native-harness/test/model-storage.test.ts +99 -0
- package/src/native-harness/test/model-stream-adapter.test.ts +26 -0
- package/src/native-harness/test/model-stream-public.test.ts +77 -0
- package/src/native-harness/test/notices.test.ts +64 -0
- package/src/native-harness/test/openrouter-config.test.ts +218 -0
- package/src/native-harness/test/operator-controls.test.ts +132 -0
- package/src/native-harness/test/output.test.ts +44 -0
- package/src/native-harness/test/owner-config.test.ts +64 -0
- package/src/native-harness/test/permissions-e2e.test.ts +68 -0
- package/src/native-harness/test/persistence.test.ts +236 -0
- package/src/native-harness/test/portability.test.ts +337 -0
- package/src/native-harness/test/protocol.test.ts +160 -0
- package/src/native-harness/test/reminder-clock.test.ts +61 -0
- package/src/native-harness/test/reminder-stdio.test.ts +140 -0
- package/src/native-harness/test/reminder-storage.test.ts +124 -0
- package/src/native-harness/test/scenario-jsonl.test.ts +112 -0
- package/src/native-harness/test/scripted.test.ts +92 -0
- package/src/native-harness/test/session-file.test.ts +51 -0
- package/src/native-harness/test/startup-channel-changes.test.ts +256 -0
- package/src/native-harness/test/stdio.test.ts +132 -0
- package/src/native-harness/test/storage-memory.test.ts +4 -0
- package/src/native-harness/test/storage-sqlite.test.ts +420 -0
- package/src/native-harness/test/suspension.test.ts +430 -0
- package/src/native-harness/test/timeline-retrieval.test.ts +211 -0
- package/src/native-harness/test/tools-catalog.test.ts +468 -0
- package/src/native-harness/test/tools-protocol.test.ts +418 -0
- package/src/native-harness/test/transfers.test.ts +94 -0
- package/src/native-harness/test/web-chat.test.ts +35 -0
- package/src/native-harness/tsconfig.json +20 -0
- package/src/observation/agent-event-bus.ts +44 -18
- package/src/observation/index.ts +1 -0
- package/src/operations/contracts.ts +11 -3
- package/src/operations/errors.ts +5 -0
- package/src/operations/stale-policy.ts +1 -1
- package/src/operations/supervisor.ts +34 -10
- package/src/orchestrator/acp-delivery.ts +68 -0
- package/src/orchestrator/assignments.ts +27 -0
- package/src/orchestrator/busy.ts +15 -0
- package/src/orchestrator/config.ts +41 -0
- package/src/orchestrator/consumer-api.ts +24 -0
- package/src/orchestrator/contracts.ts +71 -0
- package/src/orchestrator/durable-assignments.ts +111 -0
- package/src/orchestrator/native-delegation.ts +103 -0
- package/src/orchestrator/orchestrator.ts +318 -0
- package/src/orchestrator/permissions.ts +25 -0
- package/src/orchestrator/policy.ts +44 -0
- package/src/orchestrator/pool.ts +123 -0
- package/src/orchestrator/tool-descriptions.ts +11 -0
- package/src/permissions/acp.ts +18 -0
- package/src/permissions/arrival.ts +13 -0
- package/src/permissions/consumer-config.ts +19 -0
- package/src/permissions/conversation.ts +280 -0
- package/src/permissions/matcher.ts +85 -0
- package/src/permissions/outcome.ts +15 -0
- package/src/permissions/policy.ts +81 -0
- package/src/permissions/request.ts +26 -0
- package/src/persistence/activity-projection.ts +1 -0
- package/src/persistence/backend.ts +34 -1
- package/src/persistence/channels.ts +23 -0
- package/src/persistence/index.ts +4 -0
- package/src/persistence/protocol-method.ts +5 -0
- package/src/persistence/reminder-wake.ts +49 -0
- package/src/persistence/reminders.ts +385 -0
- package/src/persistence/sqlite-backend.ts +84 -6
- package/src/persistence/sqlite-channels.ts +65 -0
- package/src/persistence/sqlite-reminders.ts +85 -0
- package/src/persistence/sqlite-schema.ts +108 -3
- package/src/persistence/sqlite-worker-delivery.ts +374 -0
- package/src/persistence/sqlite-workers.ts +59 -0
- package/src/persistence/worker-delivery-contract.ts +104 -0
- package/src/persistence/worker-terminal-reason.ts +29 -0
- package/src/persistence/workers.ts +19 -0
- package/src/provider-notices.ts +137 -0
- package/src/repl/commands.ts +2 -2
- package/src/steering/combine.ts +3 -1
- package/src/steering/contracts.ts +11 -2
- package/src/steering/controller.ts +3 -2
- package/src/transport/acp-transport.ts +24 -14
- package/src/types.ts +15 -12
- package/src/updates.ts +14 -2
- package/src/wire-log.ts +1 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { WorkerEvent } from "../orchestrator/contracts.ts";
|
|
1
2
|
import type { AgentConversationId, AgentSessionId } from "../agent-ids.ts";
|
|
2
3
|
import {
|
|
3
4
|
isConversationRecordKind,
|
|
@@ -20,26 +21,30 @@ export interface ConversationRecordCommittedEvent {
|
|
|
20
21
|
readonly record: ConversationRecord;
|
|
21
22
|
}
|
|
22
23
|
|
|
23
|
-
export type AgentEvent = ConversationRecordCommittedEvent;
|
|
24
|
+
export type AgentEvent = ConversationRecordCommittedEvent | WorkerEvent;
|
|
24
25
|
|
|
25
|
-
export interface AgentEventNotification {
|
|
26
|
+
export interface AgentEventNotification<Event extends AgentEvent = ConversationRecordCommittedEvent> {
|
|
26
27
|
/** Process-local order assigned before subscriber filtering. Not a durable cursor. */
|
|
27
28
|
readonly deliverySequence: number;
|
|
28
|
-
/** Time at which the
|
|
29
|
+
/** Time at which the event was offered to listeners. */
|
|
29
30
|
readonly emittedAt: string;
|
|
30
31
|
readonly agentSessionId: AgentSessionId;
|
|
31
|
-
readonly event:
|
|
32
|
+
readonly event: Event;
|
|
32
33
|
}
|
|
33
34
|
|
|
35
|
+
export type WorkerEventNotification = AgentEventNotification<WorkerEvent>;
|
|
36
|
+
|
|
34
37
|
export type AgentEventListener = (notification: AgentEventNotification) => void;
|
|
35
38
|
|
|
36
39
|
export interface AgentEventBus extends Subscribable<AgentEventNotification> {
|
|
37
40
|
subscribe(listener: AgentEventListener, options?: AgentEventSubscriptionOptions): Unsubscribe;
|
|
41
|
+
/** Observe process-local worker facts independently of committed-record filters. */
|
|
42
|
+
subscribeWorkers(listener: (notification: WorkerEventNotification) => void): Unsubscribe;
|
|
38
43
|
}
|
|
39
44
|
|
|
40
45
|
export interface AgentEventBusOptions {
|
|
41
46
|
readonly agentSessionId: AgentSessionId;
|
|
42
|
-
readonly onListenerError?: (failure: SubscriptionListenerError<AgentEventNotification
|
|
47
|
+
readonly onListenerError?: (failure: SubscriptionListenerError<AgentEventNotification<AgentEvent>>) => void;
|
|
43
48
|
}
|
|
44
49
|
|
|
45
50
|
type RecordFilter = (record: ConversationRecord) => boolean;
|
|
@@ -96,12 +101,15 @@ function compileRecordKinds(
|
|
|
96
101
|
*/
|
|
97
102
|
export class CommittedRecordEventBus implements AgentEventBus {
|
|
98
103
|
private readonly hub: SubscriptionHub<AgentEventNotification>;
|
|
104
|
+
private readonly workerHub: SubscriptionHub<WorkerEventNotification>;
|
|
105
|
+
private workerSubscriptions = 0;
|
|
99
106
|
private deliverySequence = 0;
|
|
100
107
|
private subscriptionCount = 0;
|
|
101
108
|
private closed = false;
|
|
102
109
|
|
|
103
110
|
constructor(private readonly options: AgentEventBusOptions) {
|
|
104
|
-
this.hub = new SubscriptionHub(options.onListenerError);
|
|
111
|
+
this.hub = new SubscriptionHub<AgentEventNotification>(options.onListenerError);
|
|
112
|
+
this.workerHub = new SubscriptionHub<WorkerEventNotification>(options.onListenerError);
|
|
105
113
|
}
|
|
106
114
|
|
|
107
115
|
subscribe(listener: AgentEventListener, options: AgentEventSubscriptionOptions = {}): Unsubscribe {
|
|
@@ -123,6 +131,34 @@ export class CommittedRecordEventBus implements AgentEventBus {
|
|
|
123
131
|
};
|
|
124
132
|
}
|
|
125
133
|
|
|
134
|
+
subscribeWorkers(listener: (notification: WorkerEventNotification) => void): Unsubscribe {
|
|
135
|
+
if (typeof listener !== "function") throw new TypeError("worker event subscription listener must be a function");
|
|
136
|
+
this.workerSubscriptions++;
|
|
137
|
+
const unsubscribe = this.workerHub.subscribe(notification => listener(notification));
|
|
138
|
+
let subscribed = true;
|
|
139
|
+
return () => {
|
|
140
|
+
if (!subscribed) return;
|
|
141
|
+
subscribed = false;
|
|
142
|
+
this.workerSubscriptions--;
|
|
143
|
+
unsubscribe();
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** @internal Publish a worker fact after the corresponding state change. */
|
|
148
|
+
publishWorker(event: WorkerEvent): void {
|
|
149
|
+
if (this.closed || this.workerSubscriptions === 0) return;
|
|
150
|
+
this.workerHub.emit(this.envelope(event));
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
private envelope<Event extends AgentEvent>(event: Event): AgentEventNotification<Event> {
|
|
154
|
+
return Object.freeze({
|
|
155
|
+
deliverySequence: ++this.deliverySequence,
|
|
156
|
+
emittedAt: new Date().toISOString(),
|
|
157
|
+
agentSessionId: this.options.agentSessionId,
|
|
158
|
+
event: Object.freeze(event),
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
|
|
126
162
|
/** @internal Publish records whose persistence transaction has already committed. */
|
|
127
163
|
publish(records: readonly ConversationRecord[]): void {
|
|
128
164
|
// No subscribers means no notification to allocate; the delivery sequence is
|
|
@@ -131,18 +167,7 @@ export class CommittedRecordEventBus implements AgentEventBus {
|
|
|
131
167
|
const ordered = records.length > 1
|
|
132
168
|
? [...records].sort((left, right) => left.sequence - right.sequence)
|
|
133
169
|
: records;
|
|
134
|
-
for (const record of ordered) {
|
|
135
|
-
const notification: AgentEventNotification = Object.freeze({
|
|
136
|
-
deliverySequence: (this.deliverySequence += 1),
|
|
137
|
-
emittedAt: new Date().toISOString(),
|
|
138
|
-
agentSessionId: this.options.agentSessionId,
|
|
139
|
-
event: Object.freeze({
|
|
140
|
-
kind: "conversation_record_committed" as const,
|
|
141
|
-
record,
|
|
142
|
-
}),
|
|
143
|
-
});
|
|
144
|
-
this.hub.emit(notification);
|
|
145
|
-
}
|
|
170
|
+
for (const record of ordered) this.hub.emit(this.envelope({ kind: "conversation_record_committed", record }));
|
|
146
171
|
}
|
|
147
172
|
|
|
148
173
|
/** @internal Prevent further publication and drop every subscription. */
|
|
@@ -150,5 +175,6 @@ export class CommittedRecordEventBus implements AgentEventBus {
|
|
|
150
175
|
this.closed = true;
|
|
151
176
|
this.subscriptionCount = 0;
|
|
152
177
|
this.hub.clear();
|
|
178
|
+
this.workerHub.clear();
|
|
153
179
|
}
|
|
154
180
|
}
|
package/src/observation/index.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// outside (its stage and timestamps) and what the provider is observed to send while it runs.
|
|
3
3
|
// Spec: .res/somelogs.md/9-22+/10-17-SPEC-operation-lifecycle.md.
|
|
4
4
|
|
|
5
|
-
import type { ActivityEvent } from "../types.ts";
|
|
5
|
+
import type { ActivityEvent, PromptResult } from "../types.ts";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Anything the provider sent for a session: a `session/update`, or a request from the agent to the
|
|
@@ -14,6 +14,14 @@ export type ProviderOutput =
|
|
|
14
14
|
|
|
15
15
|
export type OutputListener = (output: ProviderOutput) => void;
|
|
16
16
|
|
|
17
|
+
/** The narrow view of a provider the supervisor needs: one request, started by `prompt()`. */
|
|
18
|
+
export interface SupervisedProvider {
|
|
19
|
+
prompt(): Promise<PromptResult>;
|
|
20
|
+
subscribeOutput(listener: OutputListener): () => void;
|
|
21
|
+
cancel(): void;
|
|
22
|
+
forceStop(): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
|
|
17
25
|
/** What a running operation is waiting on. */
|
|
18
26
|
export type OperationStage = "waiting" | "streaming" | "tool_running" | "awaiting_permission" | "cancelling";
|
|
19
27
|
|
|
@@ -47,9 +55,9 @@ export interface OperationActivity {
|
|
|
47
55
|
|
|
48
56
|
/** When an operation counts as stale. `false` disables a condition. */
|
|
49
57
|
export interface StaleLimits {
|
|
50
|
-
/** No output at all since the request was sent. Default
|
|
58
|
+
/** No output at all since the request was sent. Default 600 000 (10 minutes). */
|
|
51
59
|
readonly firstOutputMs?: number | false;
|
|
52
|
-
/** No output since the last one, with no tool or permission explaining it. Default
|
|
60
|
+
/** No output since the last one, with no tool or permission explaining it. Default 900 000 (15 minutes). */
|
|
53
61
|
readonly nextOutputMs?: number | false;
|
|
54
62
|
/** One tool running longer than this. Off by default. */
|
|
55
63
|
readonly toolMs?: number | false;
|
package/src/operations/errors.ts
CHANGED
|
@@ -14,6 +14,11 @@ export class OperationStalledError extends Error {
|
|
|
14
14
|
followedBy?: readonly string[];
|
|
15
15
|
metering?: OperationMeteringRecord;
|
|
16
16
|
cancel?: "acknowledged" | "forced";
|
|
17
|
+
/**
|
|
18
|
+
* The provider's last notice before the stall, when it was retrying or warning (a 429, say): the
|
|
19
|
+
* likely cause, which the recorded error names instead of a bare "stopped producing output".
|
|
20
|
+
*/
|
|
21
|
+
notice?: { readonly title: string; readonly category: string; readonly code?: string };
|
|
17
22
|
|
|
18
23
|
constructor(readonly operationId: string, readonly phase: StallPhase) {
|
|
19
24
|
super(`Provider operation stalled (${phase}).`);
|
|
@@ -3,7 +3,7 @@ import type { OperationActivity, StaleLimits } from "./contracts.ts";
|
|
|
3
3
|
/** Whether anything had arrived when the operation went stale. */
|
|
4
4
|
export type StallPhase = "no_response" | "incomplete_response";
|
|
5
5
|
|
|
6
|
-
export const DEFAULT_STALE_LIMITS = Object.freeze({ firstOutputMs:
|
|
6
|
+
export const DEFAULT_STALE_LIMITS = Object.freeze({ firstOutputMs: 600_000, nextOutputMs: 900_000 });
|
|
7
7
|
|
|
8
8
|
export interface StaleDecision {
|
|
9
9
|
readonly deadline: number;
|
|
@@ -10,21 +10,15 @@ import type {
|
|
|
10
10
|
CancelOutcome,
|
|
11
11
|
CancelReason,
|
|
12
12
|
OperationActivity,
|
|
13
|
-
OutputListener,
|
|
14
13
|
ProviderOutput,
|
|
15
14
|
StaleLimits,
|
|
16
15
|
SupervisedOperationKind,
|
|
16
|
+
SupervisedProvider,
|
|
17
17
|
} from "./contracts.ts";
|
|
18
18
|
import { ToolTracker } from "./activity-tracker.ts";
|
|
19
19
|
import { realTimers, type Timers } from "./timers.ts";
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
export interface SupervisedProvider {
|
|
23
|
-
prompt(): Promise<PromptResult>;
|
|
24
|
-
subscribeOutput(listener: OutputListener): () => void;
|
|
25
|
-
cancel(): void;
|
|
26
|
-
forceStop(): Promise<void>;
|
|
27
|
-
}
|
|
21
|
+
export type { SupervisedProvider } from "./contracts.ts";
|
|
28
22
|
|
|
29
23
|
export interface SupervisorOptions {
|
|
30
24
|
readonly operationId: string;
|
|
@@ -35,6 +29,12 @@ export interface SupervisorOptions {
|
|
|
35
29
|
readonly cancelGraceMs?: number;
|
|
36
30
|
readonly timers?: Timers;
|
|
37
31
|
readonly limits?: StaleLimits;
|
|
32
|
+
/**
|
|
33
|
+
* Whether the provider is replaying output the backend already produced (a held turn that is not `live`). Read each
|
|
34
|
+
* time a stall deadline is reached, not once: a replaying turn is never stalled, and one that has become live since
|
|
35
|
+
* gets its stall deadline back (a controller-interface turn is not live while its held output replays).
|
|
36
|
+
*/
|
|
37
|
+
readonly isReplaying?: () => boolean;
|
|
38
38
|
readonly onStageChanged?: (activity: OperationActivity) => void;
|
|
39
39
|
/** The last running tool settled. */
|
|
40
40
|
readonly onToolBoundary?: () => void;
|
|
@@ -58,6 +58,7 @@ export class OperationSupervisor {
|
|
|
58
58
|
private readonly timers: Timers;
|
|
59
59
|
private readonly startedAt: number;
|
|
60
60
|
private lastOutputAt: number | null = null;
|
|
61
|
+
private lastNotice?: { title: string; category: string; code?: string };
|
|
61
62
|
private permissions = 0;
|
|
62
63
|
private cancellation?: { reason: CancelReason; requestedAt: number };
|
|
63
64
|
private stage: OperationActivity["stage"] = "waiting";
|
|
@@ -67,6 +68,8 @@ export class OperationSupervisor {
|
|
|
67
68
|
private finished = false;
|
|
68
69
|
private started = false;
|
|
69
70
|
private forced = false;
|
|
71
|
+
/** The last time a stall deadline was skipped because the provider was replaying: silence counts from then. */
|
|
72
|
+
private replayCheckedAt: number | null = null;
|
|
70
73
|
private finishForced?: (result: PromptResult) => void;
|
|
71
74
|
|
|
72
75
|
constructor(private readonly provider: SupervisedProvider, private readonly options: SupervisorOptions) {
|
|
@@ -155,7 +158,9 @@ export class OperationSupervisor {
|
|
|
155
158
|
}
|
|
156
159
|
|
|
157
160
|
private stalled(): OperationStalledError {
|
|
158
|
-
|
|
161
|
+
const error = new OperationStalledError(this.options.operationId, this.stallPhase!);
|
|
162
|
+
if (this.lastNotice) error.notice = this.lastNotice;
|
|
163
|
+
return this.markCancel(error);
|
|
159
164
|
}
|
|
160
165
|
|
|
161
166
|
private markCancel(error: OperationStalledError): OperationStalledError {
|
|
@@ -180,6 +185,14 @@ export class OperationSupervisor {
|
|
|
180
185
|
this.lastOutputAt = this.timers.now();
|
|
181
186
|
if (output.kind === "permission_started") this.permissions++;
|
|
182
187
|
if (output.kind === "permission_ended") this.permissions = Math.max(0, this.permissions - 1);
|
|
188
|
+
// A retry or warning in progress is remembered until real output follows, to name a stall's cause.
|
|
189
|
+
if (output.kind === "update" && output.activity?.kind === "provider_notice") {
|
|
190
|
+
const notice = output.activity;
|
|
191
|
+
this.lastNotice = notice.severity === "error" ? undefined
|
|
192
|
+
: { title: notice.title, category: notice.category, ...(notice.code ? { code: notice.code } : {}) };
|
|
193
|
+
} else if (output.kind === "update") {
|
|
194
|
+
this.lastNotice = undefined;
|
|
195
|
+
}
|
|
183
196
|
if (output.kind === "update" && output.activity) {
|
|
184
197
|
const settled = this.tools.observe(output.activity, this.lastOutputAt);
|
|
185
198
|
if (settled && !this.tools.inFlight) this.options.onToolBoundary?.();
|
|
@@ -191,9 +204,20 @@ export class OperationSupervisor {
|
|
|
191
204
|
private armStaleTimer(): void {
|
|
192
205
|
this.timers.clearTimeout(this.staleHandle);
|
|
193
206
|
const limits = this.options.limits ?? {};
|
|
194
|
-
|
|
207
|
+
// Silence is counted from the last skipped deadline too, so a turn that stopped replaying gets a full interval.
|
|
208
|
+
const floor = this.replayCheckedAt ?? 0;
|
|
209
|
+
const activity = this.activity;
|
|
210
|
+
const counted = this.replayCheckedAt === null ? activity : { ...activity, startedAt: Math.max(activity.startedAt, floor), lastOutputAt: activity.lastOutputAt === null ? null : Math.max(activity.lastOutputAt, floor) };
|
|
211
|
+
const oldestTool = this.tools.oldestStartedAt;
|
|
212
|
+
const decision = stalePolicy(counted, this.permissions, oldestTool === null ? null : Math.max(oldestTool, floor), limits, this.timers.now());
|
|
195
213
|
if (!decision || this.finished) return;
|
|
196
214
|
this.staleHandle = this.timers.setTimeout(() => {
|
|
215
|
+
if (this.options.isReplaying?.()) {
|
|
216
|
+
// Still replaying held output: no stall now; look again after another interval.
|
|
217
|
+
this.replayCheckedAt = this.timers.now();
|
|
218
|
+
this.armStaleTimer();
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
197
221
|
this.stallPhase = decision.phase;
|
|
198
222
|
this.cancel("stalled");
|
|
199
223
|
}, Math.max(0, decision.deadline - this.timers.now()));
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { isAgentConversationId, type AgentConversationId } from "../agent-ids.ts";
|
|
2
|
+
import { AppendDestinationUnavailableError } from "../agent/append-assistant-message.ts";
|
|
3
|
+
import type { Logger } from "../logger.ts";
|
|
4
|
+
import type { AppendAssistantMessageInput } from "../out-of-band-messages.ts";
|
|
5
|
+
import type { StagedWorkerAssignment, WorkerDeliveryRepository } from "../persistence/worker-delivery-contract.ts";
|
|
6
|
+
import { REFUSED_STEER_REASONS } from "../persistence/worker-terminal-reason.ts";
|
|
7
|
+
|
|
8
|
+
export class AcpWorkerDelivery {
|
|
9
|
+
private tail = Promise.resolve();
|
|
10
|
+
|
|
11
|
+
constructor(
|
|
12
|
+
private readonly repository: WorkerDeliveryRepository,
|
|
13
|
+
private readonly append: (id: AgentConversationId, input: AppendAssistantMessageInput, stableId: string) => Promise<unknown>,
|
|
14
|
+
private readonly log: Logger,
|
|
15
|
+
) {}
|
|
16
|
+
|
|
17
|
+
flush(): Promise<void> {
|
|
18
|
+
this.tail = this.tail.then(() => this.drain()).catch(error => {
|
|
19
|
+
this.log.warn("acp_worker_delivery_failed", { error: String(error) });
|
|
20
|
+
});
|
|
21
|
+
return this.tail;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
private async drain(): Promise<void> {
|
|
25
|
+
for (const state of ["unstaged", "pending"] as const) {
|
|
26
|
+
let after: string | undefined;
|
|
27
|
+
do {
|
|
28
|
+
const page = await this.repository.discoverAssignments({ destinationKind: "acp", state, after });
|
|
29
|
+
for (const entry of page.assignments) {
|
|
30
|
+
if (entry.state === "pending") await this.deliver(entry.staged);
|
|
31
|
+
else await this.repository.stage(entry.binding.assignmentId);
|
|
32
|
+
}
|
|
33
|
+
after = page.next;
|
|
34
|
+
} while (after !== undefined);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
private async deliver({ delivery, outcome }: StagedWorkerAssignment): Promise<void> {
|
|
39
|
+
if (delivery.destination.kind !== "acp") return;
|
|
40
|
+
const target = delivery.destination.id;
|
|
41
|
+
const reason = "reason" in outcome ? outcome.reason : undefined;
|
|
42
|
+
const cause = reason === REFUSED_STEER_REASONS.conflict ? "conflict"
|
|
43
|
+
: reason === REFUSED_STEER_REASONS.hook_error ? "hook_error" : undefined;
|
|
44
|
+
let state: "delivered" | "failed_destination";
|
|
45
|
+
try {
|
|
46
|
+
if (!isAgentConversationId(target)) throw new AppendDestinationUnavailableError("invalid ACP destination");
|
|
47
|
+
await this.append(target, {
|
|
48
|
+
text: delivery.text,
|
|
49
|
+
consumerMetadata: {
|
|
50
|
+
kind: outcome.kind === "result" ? "worker_reply" : "worker_failed",
|
|
51
|
+
sender: delivery.source,
|
|
52
|
+
...(outcome.kind === "result" ? {} : {
|
|
53
|
+
errorKind: outcome.kind,
|
|
54
|
+
...(cause ? { reason: "refused", cause } : reason ? { reason } : {}),
|
|
55
|
+
}),
|
|
56
|
+
},
|
|
57
|
+
}, delivery.id);
|
|
58
|
+
state = "delivered";
|
|
59
|
+
} catch (error) {
|
|
60
|
+
if (!(error instanceof AppendDestinationUnavailableError)) {
|
|
61
|
+
this.log.warn("acp_worker_append_unconfirmed", { deliveryId: delivery.id, error: String(error) });
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
state = "failed_destination";
|
|
65
|
+
}
|
|
66
|
+
await this.repository.transitionDelivery(delivery.id, { from: "pending", to: state });
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { AgentConversationId } from "../agent-ids.ts";
|
|
2
|
+
import type { WorkerRow } from "../persistence/workers.ts";
|
|
3
|
+
import type { StagedWorkerAssignment } from "../persistence/worker-delivery-contract.ts";
|
|
4
|
+
import type { WorkerConversationActor } from "./contracts.ts";
|
|
5
|
+
|
|
6
|
+
export interface RunningAssignment {
|
|
7
|
+
readonly id: string;
|
|
8
|
+
readonly destination?: AgentConversationId;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type AssignmentPlan =
|
|
12
|
+
| { readonly kind: "start"; readonly assignment: RunningAssignment }
|
|
13
|
+
| { readonly kind: "continue"; readonly previous: RunningAssignment; readonly assignment: RunningAssignment }
|
|
14
|
+
| { readonly kind: "replace"; readonly previous: RunningAssignment; readonly assignment: RunningAssignment };
|
|
15
|
+
|
|
16
|
+
export type RefusedSteerCause = "conflict" | "hook_error";
|
|
17
|
+
export type RefusedSteer = { readonly actor: WorkerConversationActor; readonly cause: RefusedSteerCause };
|
|
18
|
+
|
|
19
|
+
/** The assignment implementation is supplied separately. The pool only knows the dispatch boundary. */
|
|
20
|
+
export interface WorkerAssignmentPort {
|
|
21
|
+
beforeDispatch(row: WorkerRow, plan: AssignmentPlan, messageId: string, policyNames: readonly string[], actor?: WorkerConversationActor): Promise<RunningAssignment | void>;
|
|
22
|
+
refuse?(row: WorkerRow, plan: AssignmentPlan, refusal: RefusedSteer): Promise<void>;
|
|
23
|
+
settled?(): Promise<void>;
|
|
24
|
+
latestOutcome?(row: WorkerRow): Promise<StagedWorkerAssignment | undefined>;
|
|
25
|
+
latestResult?(row: WorkerRow): Promise<StagedWorkerAssignment | undefined>;
|
|
26
|
+
retryDelivery?(row: WorkerRow): Promise<void>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AssignmentPlan, RunningAssignment } from "./assignments.ts";
|
|
2
|
+
import type { SendWorkerInput, WorkerActor } from "./contracts.ts";
|
|
3
|
+
|
|
4
|
+
export function planAssignment(
|
|
5
|
+
actor: WorkerActor, input: SendWorkerInput, running?: RunningAssignment,
|
|
6
|
+
): AssignmentPlan | undefined {
|
|
7
|
+
const destination = actor.kind === "conversation" ? actor.conversationId : undefined;
|
|
8
|
+
const fresh = () => ({ id: actor.kind === "conversation" ? actor.invocationId : crypto.randomUUID(), destination });
|
|
9
|
+
if (!running) return { kind: "start", assignment: fresh() };
|
|
10
|
+
if (destination !== running.destination && !input.redirect) return;
|
|
11
|
+
if (input.assignment === "new" || (!running.destination && destination)) {
|
|
12
|
+
return { kind: "replace", previous: running, assignment: fresh() };
|
|
13
|
+
}
|
|
14
|
+
return { kind: "continue", previous: running, assignment: { ...running, destination } };
|
|
15
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { DelegationPolicy } from "./contracts.ts";
|
|
2
|
+
import type { PermissionSettings } from "../permissions/matcher.ts";
|
|
3
|
+
import { PersistenceCapabilityError } from "../persistence/backend.ts";
|
|
4
|
+
import type { PersistenceBackend, RecordCaptureLevel } from "../persistence/backend.ts";
|
|
5
|
+
|
|
6
|
+
export interface OrchestratorConfig {
|
|
7
|
+
/** Each entry corresponds to a configured native harness policy name. */
|
|
8
|
+
readonly policies?: Readonly<Record<string, {
|
|
9
|
+
readonly delegation: DelegationPolicy;
|
|
10
|
+
readonly workerPermissions?: PermissionSettings;
|
|
11
|
+
}>>;
|
|
12
|
+
/** Forwarded requests retain owner options only when every contributing name is listed here. */
|
|
13
|
+
readonly ownerPolicies?: readonly string[];
|
|
14
|
+
readonly defaults?: {
|
|
15
|
+
readonly delegation?: DelegationPolicy;
|
|
16
|
+
/** Worker policy for consumer work and callbacks with no contributing policies. */
|
|
17
|
+
readonly workerPermissions?: PermissionSettings;
|
|
18
|
+
};
|
|
19
|
+
readonly workers: {
|
|
20
|
+
readonly adapterId?: string;
|
|
21
|
+
readonly cwd?: string;
|
|
22
|
+
readonly limit: number;
|
|
23
|
+
/** Time idle before stopping the provider process. Defaults to ten minutes. */
|
|
24
|
+
readonly idleStopMs?: number | false;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function validateOrchestrator(
|
|
29
|
+
config: OrchestratorConfig, persistence: PersistenceBackend, messageCapture: RecordCaptureLevel,
|
|
30
|
+
): void {
|
|
31
|
+
if (!persistence.capabilities.workers || !persistence.workers) throw new PersistenceCapabilityError("workers");
|
|
32
|
+
if (!persistence.capabilities.workerDelivery || !persistence.workerDelivery) throw new PersistenceCapabilityError("workerDelivery");
|
|
33
|
+
if (messageCapture !== "content") throw new Error('orchestrator requires message capture "content"');
|
|
34
|
+
if (!Number.isSafeInteger(config.workers.limit) || config.workers.limit < 1) {
|
|
35
|
+
throw new RangeError("orchestrator worker limit must be a positive integer");
|
|
36
|
+
}
|
|
37
|
+
const idle = config.workers.idleStopMs;
|
|
38
|
+
if (idle !== undefined && idle !== false && (!Number.isInteger(idle) || idle < 0 || idle > 2_147_483_647)) {
|
|
39
|
+
throw new RangeError("orchestrator worker idleStopMs must be a non-negative timer delay or false");
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { DeleteConversationResult } from "../agent/config.ts";
|
|
2
|
+
import type { WorkerSummary } from "./contracts.ts";
|
|
3
|
+
import type { Orchestrator } from "./orchestrator.ts";
|
|
4
|
+
|
|
5
|
+
export interface WorkerConsumerApi {
|
|
6
|
+
list(): Promise<readonly WorkerSummary[]>;
|
|
7
|
+
check(handle: string): Promise<WorkerSummary>;
|
|
8
|
+
/** Explicitly retry the worker's newest policy-blocked delivery. */
|
|
9
|
+
retryDelivery(handle: string): Promise<void>;
|
|
10
|
+
stop(handle: string): Promise<void>;
|
|
11
|
+
/** Removes the worker locally and reports the provider cleanup outcome. */
|
|
12
|
+
delete(handle: string): Promise<DeleteConversationResult>;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function workerConsumerApi(orchestrator: Orchestrator): WorkerConsumerApi {
|
|
16
|
+
const consumer = { kind: "consumer" } as const;
|
|
17
|
+
return Object.freeze({
|
|
18
|
+
list: () => orchestrator.list(consumer),
|
|
19
|
+
check: (handle: string) => orchestrator.check(consumer, handle),
|
|
20
|
+
retryDelivery: (handle: string) => orchestrator.retryDelivery(handle),
|
|
21
|
+
async stop(handle: string) { await orchestrator.stop(consumer, handle); },
|
|
22
|
+
delete: (handle: string) => orchestrator.drop(consumer, handle),
|
|
23
|
+
});
|
|
24
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { PermissionSettings } from "../permissions/matcher.ts";
|
|
2
|
+
import type { AgentConversationId } from "../agent-ids.ts";
|
|
3
|
+
import type { OperationActivity } from "../operations/contracts.ts";
|
|
4
|
+
import type { WorkerRow } from "../persistence/workers.ts";
|
|
5
|
+
import type { WorkerAssignmentOutcome, WorkerDeliveryState } from "../persistence/worker-delivery-contract.ts";
|
|
6
|
+
|
|
7
|
+
export interface DelegationPolicy {
|
|
8
|
+
readonly use: boolean;
|
|
9
|
+
readonly scope: "none" | "all";
|
|
10
|
+
readonly redirect: boolean;
|
|
11
|
+
readonly maxOpen?: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type WorkerActor = { readonly kind: "consumer" } | WorkerConversationActor;
|
|
15
|
+
|
|
16
|
+
export interface WorkerConversationActor {
|
|
17
|
+
readonly kind: "conversation";
|
|
18
|
+
readonly conversationId: AgentConversationId;
|
|
19
|
+
readonly sender: string;
|
|
20
|
+
readonly invocationId: string;
|
|
21
|
+
/** Native callbacks identify their destination even for rows created before controller kinds. */
|
|
22
|
+
readonly destinationKind?: "native" | "acp";
|
|
23
|
+
readonly policyNames: readonly string[];
|
|
24
|
+
readonly policy: DelegationPolicy;
|
|
25
|
+
readonly workerPermissions: readonly PermissionSettings[];
|
|
26
|
+
/** A trusted caller can attest owner authority independently of policy names. */
|
|
27
|
+
readonly isOwner?: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface WorkerInput {
|
|
31
|
+
readonly text: string;
|
|
32
|
+
readonly about?: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface SendWorkerInput extends WorkerInput {
|
|
36
|
+
readonly redirect?: boolean;
|
|
37
|
+
readonly assignment?: "new";
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface WorkerSummary extends WorkerRow {
|
|
41
|
+
readonly state: "offline" | "idle" | "busy";
|
|
42
|
+
readonly operation?: OperationActivity;
|
|
43
|
+
readonly sender?: string;
|
|
44
|
+
readonly busyMs?: number;
|
|
45
|
+
readonly latestOutcome?: WorkerAssignmentOutcome;
|
|
46
|
+
/** Delivery state of the latest staged assignment. */
|
|
47
|
+
readonly deliveryState?: WorkerDeliveryState;
|
|
48
|
+
/** The last successful result, when the most recent outcome is a dispatch refusal. */
|
|
49
|
+
readonly latestResult?: Extract<WorkerAssignmentOutcome, { kind: "result" }>;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export type OpenWorkerResult = { readonly status: "sent"; readonly handle: string } |
|
|
53
|
+
{ readonly status: "no_worker_free"; readonly workers: readonly WorkerSummary[] };
|
|
54
|
+
|
|
55
|
+
export type SendWorkerResult = { readonly status: "sent" | "steered" } |
|
|
56
|
+
{ readonly status: "busy"; readonly worker: WorkerSummary } |
|
|
57
|
+
{ readonly status: "no_worker_free"; readonly workers: readonly WorkerSummary[] };
|
|
58
|
+
|
|
59
|
+
interface WorkerEventIdentity {
|
|
60
|
+
readonly handle: string;
|
|
61
|
+
readonly conversationId: AgentConversationId;
|
|
62
|
+
readonly openedBy: WorkerRow["openedBy"];
|
|
63
|
+
readonly lastConversation?: AgentConversationId;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export type WorkerEvent = WorkerEventIdentity & (
|
|
67
|
+
| { readonly kind: "worker_opened" | "worker_busy" | "worker_idle" | "worker_replied" | "worker_reloaded" | "worker_dropped" }
|
|
68
|
+
| { readonly kind: "worker_redirected"; readonly previousConversation?: AgentConversationId }
|
|
69
|
+
| { readonly kind: "worker_failed"; readonly reason: string; readonly cause?: "conflict" | "hook_error"; readonly destination?: AgentConversationId }
|
|
70
|
+
| { readonly kind: "worker_stopped"; readonly reason: "eviction" | "requested" | "idle" }
|
|
71
|
+
);
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import type { PersistenceBackend, PersistenceScope } from "../persistence/backend.ts";
|
|
2
|
+
import type { AgentConversationId } from "../agent-ids.ts";
|
|
3
|
+
import type { WorkerAssignmentReservation, WorkerDestination } from "../persistence/worker-delivery-contract.ts";
|
|
4
|
+
import type { WorkerRow } from "../persistence/workers.ts";
|
|
5
|
+
import type { AssignmentPlan, RefusedSteer, RunningAssignment, WorkerAssignmentPort } from "./assignments.ts";
|
|
6
|
+
import { REFUSED_STEER_REASONS } from "../persistence/worker-terminal-reason.ts";
|
|
7
|
+
import type { WorkerConversationActor } from "./contracts.ts";
|
|
8
|
+
|
|
9
|
+
export class WorkerAssignmentConflict extends Error {
|
|
10
|
+
constructor() { super("worker assignment conflict"); }
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export class DurableWorkerAssignments implements WorkerAssignmentPort {
|
|
14
|
+
constructor(
|
|
15
|
+
private readonly persistence: PersistenceBackend,
|
|
16
|
+
private readonly flushAcp: () => Promise<void>,
|
|
17
|
+
private readonly flushNative: () => Promise<void> | undefined,
|
|
18
|
+
) {}
|
|
19
|
+
|
|
20
|
+
async beforeDispatch(
|
|
21
|
+
row: WorkerRow, plan: AssignmentPlan, messageId: string, policyNames: readonly string[], actor?: WorkerConversationActor,
|
|
22
|
+
): Promise<RunningAssignment | void> {
|
|
23
|
+
const target = plan.assignment.destination;
|
|
24
|
+
if (!target) return;
|
|
25
|
+
const accepted = await this.persistence.transaction(async scope => {
|
|
26
|
+
const repository = scope.workerDelivery!;
|
|
27
|
+
const destination = await this.destination(scope, target, actor?.destinationKind);
|
|
28
|
+
const binding = this.binding(row, plan.assignment.id, messageId, destination, policyNames);
|
|
29
|
+
// A local consumer's work has no delivery destination and therefore no predecessor binding.
|
|
30
|
+
if (plan.kind === "start" || !plan.previous.destination) {
|
|
31
|
+
if (await repository.reserve(binding) !== "reserved") throw new WorkerAssignmentConflict();
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
const old = await repository.readBinding(plan.previous.id);
|
|
35
|
+
if (!old || old.workerConversationId !== row.conversationId) throw new WorkerAssignmentConflict();
|
|
36
|
+
if (plan.kind === "continue" && old.finalRecordId && actor) {
|
|
37
|
+
const result = await repository.replaceAssignment(old.assignmentId, old.messageId, { ...binding, assignmentId: actor.invocationId });
|
|
38
|
+
if (result.kind !== "old_settled" || result.reservation !== "reserved") throw new WorkerAssignmentConflict();
|
|
39
|
+
return { id: actor.invocationId, destination: target };
|
|
40
|
+
}
|
|
41
|
+
if (plan.kind === "replace") {
|
|
42
|
+
const result = await repository.replaceAssignment(old.assignmentId, old.messageId, binding);
|
|
43
|
+
if (result.kind === "conflict" || result.reservation !== "reserved") throw new WorkerAssignmentConflict();
|
|
44
|
+
return result.kind === "replaced";
|
|
45
|
+
}
|
|
46
|
+
if (await repository.continueAssignment(old.assignmentId, old.messageId, messageId) !== "continued"
|
|
47
|
+
|| !await repository.addContributingPolicies(old.assignmentId, policyNames)
|
|
48
|
+
|| (old.destination.id !== destination.id && !await repository.redirect(old.assignmentId, destination))) {
|
|
49
|
+
throw new WorkerAssignmentConflict();
|
|
50
|
+
}
|
|
51
|
+
return false;
|
|
52
|
+
});
|
|
53
|
+
if (accepted === true) void this.flushNative();
|
|
54
|
+
if (plan.kind === "replace") void this.flushAcp();
|
|
55
|
+
if (typeof accepted === "object") return accepted;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async refuse(row: WorkerRow, plan: AssignmentPlan, { actor, cause }: RefusedSteer): Promise<void> {
|
|
59
|
+
await this.persistence.transaction(async scope => {
|
|
60
|
+
const repository = scope.workerDelivery!;
|
|
61
|
+
const old = plan.kind === "start" ? undefined : await repository.readBinding(plan.previous.id);
|
|
62
|
+
if (old?.workerConversationId === row.conversationId) {
|
|
63
|
+
await repository.closeContinuation(old.assignmentId, old.messageId, {
|
|
64
|
+
kind: "interrupted", reason: "worker interrupted by steering", possiblePartialEffects: true,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
const destination = await this.destination(scope, actor.conversationId, actor.destinationKind);
|
|
68
|
+
// The refusal is a separate notice. Its synthetic cause never reaches the worker and cannot
|
|
69
|
+
// take over the predecessor's binding or reuse a conflicting replacement invocation ID.
|
|
70
|
+
const id = `refused-steer:${actor.invocationId}`;
|
|
71
|
+
const reserved = await repository.reserve(this.binding(row, id, id, destination, actor.policyNames));
|
|
72
|
+
if (reserved === "conflict") throw new WorkerAssignmentConflict();
|
|
73
|
+
if (reserved === "reserved") await repository.recordFailure(row.conversationId, id, [id], {
|
|
74
|
+
kind: "failed",
|
|
75
|
+
reason: REFUSED_STEER_REASONS[cause],
|
|
76
|
+
possiblePartialEffects: false,
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
void this.flushNative();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async settled(): Promise<void> {
|
|
83
|
+
await Promise.all([this.flushAcp(), this.flushNative()]);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
latestOutcome(row: WorkerRow) { return this.persistence.workerDelivery!.latestOutcome(row.conversationId); }
|
|
87
|
+
latestResult(row: WorkerRow) { return this.persistence.workerDelivery!.latestOutcome(row.conversationId, "result"); }
|
|
88
|
+
|
|
89
|
+
async retryDelivery(row: WorkerRow): Promise<void> {
|
|
90
|
+
const repository = this.persistence.workerDelivery!;
|
|
91
|
+
const blocked = await repository.latestOutcome(row.conversationId, "blocked_policy");
|
|
92
|
+
if (blocked?.delivery.state !== "blocked_policy" || !await repository.transitionDelivery(blocked.delivery.id,
|
|
93
|
+
{ from: "blocked_policy", to: "pending", explicitRetry: true })) {
|
|
94
|
+
throw new Error(`worker ${row.handle} has no policy-blocked delivery to retry`);
|
|
95
|
+
}
|
|
96
|
+
await (blocked.delivery.destination.kind === "native" ? this.flushNative() : this.flushAcp());
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
private async destination(scope: PersistenceScope, id: AgentConversationId, kind?: WorkerDestination["kind"]): Promise<WorkerDestination> {
|
|
100
|
+
return { id, kind: (await scope.conversations.get(id))?.controllerKind ?? kind ?? "acp" };
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
private binding(
|
|
104
|
+
row: WorkerRow, assignmentId: string, messageId: string, destination: WorkerDestination, policyNames: readonly string[],
|
|
105
|
+
): WorkerAssignmentReservation {
|
|
106
|
+
return {
|
|
107
|
+
assignmentId, messageId, destination, workerConversationId: row.conversationId, workerHandle: row.handle,
|
|
108
|
+
originatingPolicyNames: policyNames, contributingPolicyNames: policyNames,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
}
|