@qlairoslabs/acp-client 0.12.0 → 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 -3
- package/CHANGELOG-controller-interface.md +258 -0
- package/CHANGELOG-metering.md +29 -0
- package/CHANGELOG-operation-lifecycle.md +15 -1
- package/CONSUMER_GUIDE.md +847 -7
- 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 +30 -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 +10 -0
- package/src/cli/index.ts +3 -3
- package/src/cli/managed.ts +2 -2
- package/src/client.ts +68 -98
- 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
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { isAgentConversationId } from "../agent-ids.ts";
|
|
2
|
+
import type { AgentConversationManager } from "../agent/config.ts";
|
|
3
|
+
import { WorkerPolicyError } from "../errors.ts";
|
|
4
|
+
import type { OrchestratorConfig } from "./config.ts";
|
|
5
|
+
import type { SendWorkerInput, WorkerActor } from "./contracts.ts";
|
|
6
|
+
import type { Orchestrator } from "./orchestrator.ts";
|
|
7
|
+
import { composeDelegationPolicy } from "./policy.ts";
|
|
8
|
+
import { WORKER_SEND_DESCRIPTION } from "./tool-descriptions.ts";
|
|
9
|
+
import { ownPermissions } from "../permissions/policy.ts";
|
|
10
|
+
import { FunctionError, type NativeFunction, type NativeFunctionContext, type NativeFunctionsConfig } from "../native/functions.ts";
|
|
11
|
+
|
|
12
|
+
const names = ["delegate", "check", "list", "stop"] as const;
|
|
13
|
+
const string = { type: "string" } as const;
|
|
14
|
+
const handleOnly = { type: "object", properties: { worker: string }, required: ["worker"], additionalProperties: false };
|
|
15
|
+
const denyDelegation = { use: false, scope: "none", redirect: false } as const;
|
|
16
|
+
const askWorker = { default: "ask" } as const;
|
|
17
|
+
|
|
18
|
+
export function withDelegationTools(
|
|
19
|
+
functions: NativeFunctionsConfig | undefined,
|
|
20
|
+
config: OrchestratorConfig,
|
|
21
|
+
orchestrator: () => Orchestrator,
|
|
22
|
+
conversations: () => Pick<AgentConversationManager, "get">,
|
|
23
|
+
): NativeFunctionsConfig {
|
|
24
|
+
for (const name of names) {
|
|
25
|
+
if (functions && Object.hasOwn(functions.tools, name)) throw new Error(`native delegation tool name is already registered: ${name}`);
|
|
26
|
+
}
|
|
27
|
+
const policies = new Map(Object.entries(config.policies ?? {}).map(([name, policy]) => [name, {
|
|
28
|
+
delegation: Object.freeze({ ...policy.delegation }),
|
|
29
|
+
permissions: ownPermissions(policy.workerPermissions) ?? askWorker,
|
|
30
|
+
}]));
|
|
31
|
+
const defaults = {
|
|
32
|
+
delegation: Object.freeze({ ...(config.defaults?.delegation ?? denyDelegation) }),
|
|
33
|
+
permissions: ownPermissions(config.defaults?.workerPermissions) ?? askWorker,
|
|
34
|
+
};
|
|
35
|
+
const ownerPolicies = new Set(config.ownerPolicies ?? ["owner"]);
|
|
36
|
+
|
|
37
|
+
async function actor(context: NativeFunctionContext): Promise<WorkerActor> {
|
|
38
|
+
const { channel, invocationId, policyNames, signal } = context;
|
|
39
|
+
if (!Array.isArray(policyNames)) throw new FunctionError("delegation_policy_unknown", "Missing delegation policy names");
|
|
40
|
+
const applicable = policyNames.length ? policyNames.map(name => {
|
|
41
|
+
const policy = policies.get(name);
|
|
42
|
+
if (!policy) throw new FunctionError("delegation_policy_unknown", "A contributing policy has no delegation rules");
|
|
43
|
+
return policy;
|
|
44
|
+
}) : [defaults];
|
|
45
|
+
signal.throwIfAborted();
|
|
46
|
+
if (!isAgentConversationId(channel)) throw new FunctionError("delegation_conversation_unavailable", "Unknown giving conversation");
|
|
47
|
+
const summary = await conversations().get(channel);
|
|
48
|
+
if (!summary || summary.deletedAt || summary.controllerKind === "acp") {
|
|
49
|
+
throw new FunctionError("delegation_conversation_unavailable", "Unknown giving conversation");
|
|
50
|
+
}
|
|
51
|
+
if (!context.takenSender) throw new FunctionError("delegation_sender_unavailable", "No taken-input lookup is available");
|
|
52
|
+
const sender = await context.takenSender();
|
|
53
|
+
signal.throwIfAborted();
|
|
54
|
+
return {
|
|
55
|
+
kind: "conversation", conversationId: channel, destinationKind: "native", sender, invocationId, policyNames: [...policyNames],
|
|
56
|
+
policy: composeDelegationPolicy(applicable.map(policy => policy.delegation)),
|
|
57
|
+
workerPermissions: applicable.map(policy => policy.permissions),
|
|
58
|
+
isOwner: policyNames.length > 0 && policyNames.every(name => ownerPolicies.has(name)),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function tool(description: string, parameters: Record<string, unknown>, call: (
|
|
63
|
+
args: Record<string, unknown>, actor: WorkerActor,
|
|
64
|
+
) => Promise<unknown>): NativeFunction {
|
|
65
|
+
return {
|
|
66
|
+
description, parameters, group: "fixed",
|
|
67
|
+
async handler(args, context) {
|
|
68
|
+
try {
|
|
69
|
+
return await call(args, await actor(context));
|
|
70
|
+
} catch (error) {
|
|
71
|
+
if (error instanceof WorkerPolicyError) throw new FunctionError("delegation_policy_denied", error.message);
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return {
|
|
79
|
+
...functions,
|
|
80
|
+
tools: {
|
|
81
|
+
...functions?.tools,
|
|
82
|
+
delegate: tool(`Omit worker to open a worker. ${WORKER_SEND_DESCRIPTION}`, {
|
|
83
|
+
type: "object",
|
|
84
|
+
properties: { worker: string, text: string, about: string, redirect: { type: "boolean" },
|
|
85
|
+
assignment: { type: "string", enum: ["new"] } },
|
|
86
|
+
required: ["text"], additionalProperties: false,
|
|
87
|
+
}, async (args, actor) => {
|
|
88
|
+
const input = args as unknown as SendWorkerInput & { worker?: string };
|
|
89
|
+
if (input.worker !== undefined) return orchestrator().send(actor, input.worker, input);
|
|
90
|
+
if (input.assignment !== undefined || input.redirect !== undefined) {
|
|
91
|
+
throw new FunctionError("invalid_arguments", "assignment and redirect require an existing worker handle");
|
|
92
|
+
}
|
|
93
|
+
return orchestrator().open(actor, input);
|
|
94
|
+
}),
|
|
95
|
+
check: tool("Check a worker by handle, including its latest staged result and delivery state. Results for native destinations may be absent until the harness opens.", handleOnly,
|
|
96
|
+
(args, actor) => orchestrator().check(actor, args.worker as string)),
|
|
97
|
+
list: tool("List visible workers with their latest staged results and delivery states. Results for native destinations may be absent until the harness opens.", { type: "object", properties: {}, additionalProperties: false },
|
|
98
|
+
(_args, actor) => orchestrator().list(actor)),
|
|
99
|
+
stop: tool('Interrupt running work and clear pending prompts. Returns "stopped" after an interruption or "idle" if there was no work to stop.', handleOnly,
|
|
100
|
+
async (args, actor) => ({ status: await orchestrator().stop(actor, args.worker as string) })),
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
}
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
import { ownPermissions } from "../permissions/policy.ts";
|
|
2
|
+
import type { PermissionSettings } from "../permissions/matcher.ts";
|
|
3
|
+
import { workerPermissionHandler, type FindGivingConversation } from "./permissions.ts";
|
|
4
|
+
import { WorkerPolicyError } from "../errors.ts";
|
|
5
|
+
import { canSeeWorker, checkWorkerOpenLimit, requireWorkerRedirect, requireWorkerUse } from "./policy.ts";
|
|
6
|
+
import type { AssignmentPlan, WorkerAssignmentPort } from "./assignments.ts";
|
|
7
|
+
import { planAssignment } from "./busy.ts";
|
|
8
|
+
import type { AgentConversationManager, DeleteConversationResult } from "../agent/config.ts";
|
|
9
|
+
import { workerTerminalFailure } from "../persistence/worker-terminal-reason.ts";
|
|
10
|
+
import type { Logger } from "../logger.ts";
|
|
11
|
+
import type { WorkerPersistence, WorkerRow } from "../persistence/workers.ts";
|
|
12
|
+
import type { OrchestratorConfig } from "./config.ts";
|
|
13
|
+
import type { OpenWorkerResult, SendWorkerInput, SendWorkerResult, WorkerActor, WorkerEvent, WorkerInput, WorkerSummary } from "./contracts.ts";
|
|
14
|
+
import { WorkerPool } from "./pool.ts";
|
|
15
|
+
import { WorkerAssignmentConflict } from "./durable-assignments.ts";
|
|
16
|
+
|
|
17
|
+
export class Orchestrator {
|
|
18
|
+
private readonly pool: WorkerPool;
|
|
19
|
+
private readonly completions = new Set<Promise<void>>();
|
|
20
|
+
private closed = false;
|
|
21
|
+
private readonly defaultWorkerPermissions: readonly PermissionSettings[];
|
|
22
|
+
private readonly evicted = (row: WorkerRow) => this.emit({ ...this.identity(row), kind: "worker_stopped", reason: "eviction" });
|
|
23
|
+
|
|
24
|
+
constructor(
|
|
25
|
+
private readonly workers: WorkerPersistence,
|
|
26
|
+
private readonly conversations: AgentConversationManager,
|
|
27
|
+
private readonly options: OrchestratorConfig["workers"] & { readonly defaultPermissions?: PermissionSettings },
|
|
28
|
+
private readonly log: Logger,
|
|
29
|
+
private readonly emit: (event: WorkerEvent) => void,
|
|
30
|
+
private readonly assignments?: WorkerAssignmentPort,
|
|
31
|
+
private readonly findGivingConversation?: FindGivingConversation,
|
|
32
|
+
) {
|
|
33
|
+
this.pool = new WorkerPool(options.limit, options.idleStopMs ?? 600_000);
|
|
34
|
+
const defaults = ownPermissions(options.defaultPermissions);
|
|
35
|
+
this.defaultWorkerPermissions = defaults ? [defaults] : [];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
open(actor: WorkerActor, input: WorkerInput): Promise<OpenWorkerResult> {
|
|
39
|
+
return this.run(async () => {
|
|
40
|
+
requireWorkerUse(actor);
|
|
41
|
+
this.assertInput(input);
|
|
42
|
+
const rows = await this.workers.list();
|
|
43
|
+
checkWorkerOpenLimit(actor, await this.activeRows(rows));
|
|
44
|
+
if (!await this.pool.makeRoom(this.evicted)) return { status: "no_worker_free", workers: await this.summaries(actor) };
|
|
45
|
+
const ordinal = rows.reduce((highest, row) => /^w[1-9][0-9]*$/.test(row.handle)
|
|
46
|
+
? Math.max(highest, Number(row.handle.slice(1))) : highest, 0) + 1;
|
|
47
|
+
if (!Number.isSafeInteger(ordinal)) throw new RangeError("worker handle space exhausted");
|
|
48
|
+
const handle = `w${ordinal}`;
|
|
49
|
+
const conversation = await this.conversations.create({ role: "worker", ...this.startOptions() });
|
|
50
|
+
const row: WorkerRow = {
|
|
51
|
+
handle, conversationId: conversation.id, createdAt: new Date().toISOString(),
|
|
52
|
+
openedBy: actor.kind === "consumer" ? "consumer" : actor.conversationId,
|
|
53
|
+
...(actor.kind === "conversation" ? { lastConversation: actor.conversationId } : {}),
|
|
54
|
+
...(input.about === undefined ? {} : { about: input.about }),
|
|
55
|
+
};
|
|
56
|
+
try {
|
|
57
|
+
await this.workers.create(row);
|
|
58
|
+
} catch (error) {
|
|
59
|
+
try {
|
|
60
|
+
await this.conversations.delete(conversation.id);
|
|
61
|
+
} catch (cleanup) {
|
|
62
|
+
throw new AggregateError([error, cleanup], "worker registration and conversation cleanup failed");
|
|
63
|
+
}
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
66
|
+
const slot = this.pool.attach(row, conversation);
|
|
67
|
+
this.emit({ ...this.identity(row), kind: "worker_opened" });
|
|
68
|
+
this.dispatch(slot, actor, input.text, planAssignment(actor, input)!);
|
|
69
|
+
return { status: "sent", handle };
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
send(actor: WorkerActor, handle: string, input: SendWorkerInput): Promise<SendWorkerResult> {
|
|
74
|
+
return this.run(async () => {
|
|
75
|
+
requireWorkerUse(actor);
|
|
76
|
+
this.assertInput(input);
|
|
77
|
+
const row = await this.requireWorker(actor, handle);
|
|
78
|
+
let slot = this.pool.get(handle);
|
|
79
|
+
const running = slot?.work?.assignment;
|
|
80
|
+
const plan = planAssignment(actor, input, running);
|
|
81
|
+
if (!plan || (slot && this.pool.busy(slot) && !running)) return { status: "busy", worker: await this.summary(row) };
|
|
82
|
+
if (running && running.destination !== plan.assignment.destination) requireWorkerRedirect(actor);
|
|
83
|
+
if (!slot) {
|
|
84
|
+
if (!await this.pool.makeRoom(this.evicted)) return { status: "no_worker_free", workers: await this.summaries(actor) };
|
|
85
|
+
const { conversation } = await this.conversations.open(row.conversationId, this.startOptions());
|
|
86
|
+
slot = this.pool.attach(row, conversation);
|
|
87
|
+
this.emit({ ...this.identity(row), kind: "worker_reloaded" });
|
|
88
|
+
}
|
|
89
|
+
const change = {
|
|
90
|
+
...(input.about === undefined ? {} : { about: input.about }),
|
|
91
|
+
...(actor.kind === "conversation" ? { lastConversation: actor.conversationId } : {}),
|
|
92
|
+
};
|
|
93
|
+
const workerSlot = slot;
|
|
94
|
+
const update = async () => {
|
|
95
|
+
if (!await this.workers.update(handle, change)) throw new Error(`worker is unavailable: ${handle}`);
|
|
96
|
+
workerSlot.row = { ...workerSlot.row, ...change };
|
|
97
|
+
};
|
|
98
|
+
const redirected = running && running.destination !== plan.assignment.destination;
|
|
99
|
+
if (!redirected) await update();
|
|
100
|
+
this.dispatch(slot, actor, input.text, plan, redirected ? async () => {
|
|
101
|
+
await update();
|
|
102
|
+
const event = { ...this.identity(workerSlot.row), kind: "worker_redirected" as const,
|
|
103
|
+
...(running.destination ? { previousConversation: running.destination } : {}) };
|
|
104
|
+
return () => this.emit(event);
|
|
105
|
+
} : undefined);
|
|
106
|
+
return { status: running ? "steered" : "sent" };
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
check(actor: WorkerActor, handle: string): Promise<WorkerSummary> {
|
|
111
|
+
return this.run(async () => {
|
|
112
|
+
return this.summary(await this.requireWorker(actor, handle));
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
list(actor: WorkerActor): Promise<readonly WorkerSummary[]> {
|
|
117
|
+
return this.run(async () => {
|
|
118
|
+
return this.summaries(actor);
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
retryDelivery(handle: string): Promise<void> {
|
|
123
|
+
return this.run(async () => {
|
|
124
|
+
const row = await this.requireWorker({ kind: "consumer" }, handle);
|
|
125
|
+
if (!this.assignments?.retryDelivery) throw new Error(`worker ${handle} has no policy-blocked delivery to retry`);
|
|
126
|
+
await this.assignments.retryDelivery(row);
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
stop(actor: WorkerActor, handle: string): Promise<"stopped" | "idle"> {
|
|
131
|
+
return this.run(async () => {
|
|
132
|
+
const row = await this.requireWorker(actor, handle);
|
|
133
|
+
const running = this.pool.get(handle)?.work;
|
|
134
|
+
if (actor.kind === "conversation" && running && running.assignment.destination !== actor.conversationId) {
|
|
135
|
+
requireWorkerRedirect(actor);
|
|
136
|
+
}
|
|
137
|
+
if (!await this.interrupt(handle)) return "idle";
|
|
138
|
+
this.emit({ ...this.identity(row), kind: "worker_stopped", reason: "requested" });
|
|
139
|
+
return "stopped";
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
drop(actor: WorkerActor, handle: string): Promise<DeleteConversationResult> {
|
|
144
|
+
return this.run(async () => {
|
|
145
|
+
requireWorkerRedirect(actor);
|
|
146
|
+
const row = await this.requireWorker(actor, handle, true);
|
|
147
|
+
if (!await this.reconcileWorker(row)) return { providerDeleted: false, checkpointsDeleted: 0 };
|
|
148
|
+
await this.interrupt(handle);
|
|
149
|
+
let result: DeleteConversationResult;
|
|
150
|
+
try {
|
|
151
|
+
result = await this.conversations.delete(row.conversationId, { providerSession: "best-effort" });
|
|
152
|
+
} catch (error) {
|
|
153
|
+
if ((await this.conversations.get(row.conversationId))?.deletedAt) await this.markDropped(row);
|
|
154
|
+
throw error;
|
|
155
|
+
}
|
|
156
|
+
await this.markDropped(row);
|
|
157
|
+
return result;
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
close(): Promise<void> {
|
|
162
|
+
this.closed = true;
|
|
163
|
+
this.pool.closeIdleTimers();
|
|
164
|
+
return this.pool.run(async () => {});
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
async waitForCompletions(): Promise<void> { await Promise.allSettled(this.completions); }
|
|
168
|
+
|
|
169
|
+
private run<T>(work: () => Promise<T>): Promise<T> {
|
|
170
|
+
if (this.closed) return Promise.reject(new Error("orchestrator is closed"));
|
|
171
|
+
return this.pool.run(work);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
private async markDropped(row: WorkerRow): Promise<void> {
|
|
175
|
+
const dropped = await this.workers.drop(row.handle, new Date().toISOString());
|
|
176
|
+
try {
|
|
177
|
+
await this.pool.release(row.handle);
|
|
178
|
+
} finally {
|
|
179
|
+
if (dropped) this.emit({ ...this.identity(row), kind: "worker_dropped" });
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
private async interrupt(handle: string): Promise<boolean> {
|
|
184
|
+
const slot = this.pool.get(handle);
|
|
185
|
+
if (!slot || !this.pool.busy(slot)) return false;
|
|
186
|
+
slot.conversation.interrupt({ clearQueue: true });
|
|
187
|
+
await Promise.allSettled(slot.completions);
|
|
188
|
+
return true;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
private identity({ handle, conversationId, openedBy, lastConversation }: WorkerRow) {
|
|
192
|
+
return { handle, conversationId, openedBy, ...(lastConversation ? { lastConversation } : {}) };
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
private startOptions() {
|
|
196
|
+
const { adapterId, cwd } = this.options;
|
|
197
|
+
return {
|
|
198
|
+
adapterId,
|
|
199
|
+
runtime: {
|
|
200
|
+
...(cwd === undefined ? {} : { cwd }),
|
|
201
|
+
permissions: { default: "ask" as const },
|
|
202
|
+
// The delegated actor owns the worker's decision. Always enter its prompt handler.
|
|
203
|
+
permissionRule: () => "ask" as const,
|
|
204
|
+
},
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
private assertInput(input: WorkerInput): void {
|
|
209
|
+
if (!input.text.trim()) throw new Error("worker prompt cannot be blank");
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
private async requireWorker(actor: WorkerActor, handle: string, allowMissingConversation = false): Promise<WorkerRow> {
|
|
213
|
+
const row = await this.workers.get(handle);
|
|
214
|
+
if (actor.kind === "conversation" && actor.policy.scope === "none" &&
|
|
215
|
+
(!row || !canSeeWorker(actor, row, this.pool.get(handle)?.work?.assignment))) throw new WorkerPolicyError("scope");
|
|
216
|
+
if (!row || row.droppedAt) throw new Error(`unknown active worker: ${handle}`);
|
|
217
|
+
if (!allowMissingConversation && !await this.reconcileWorker(row)) throw new Error(`worker conversation is unavailable: ${handle}`);
|
|
218
|
+
return row;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
private async summaries(actor: WorkerActor): Promise<readonly WorkerSummary[]> {
|
|
222
|
+
const visible = (await this.activeRows(await this.workers.list()))
|
|
223
|
+
.filter(row => canSeeWorker(actor, row, this.pool.get(row.handle)?.work?.assignment));
|
|
224
|
+
return Promise.all(visible.map(row => this.summary(row)));
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
private async summary(row: WorkerRow): Promise<WorkerSummary> {
|
|
228
|
+
const latest = await this.assignments?.latestOutcome?.(row);
|
|
229
|
+
const result = latest?.assignmentId.startsWith("refused-steer:")
|
|
230
|
+
? (await this.assignments?.latestResult?.(row))?.outcome : undefined;
|
|
231
|
+
return { ...this.pool.summary(row), ...(latest ? { latestOutcome: latest.outcome, deliveryState: latest.delivery.state } : {}),
|
|
232
|
+
...(result?.kind === "result" ? { latestResult: result } : {}) };
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
private async activeRows(rows: readonly WorkerRow[]): Promise<WorkerRow[]> {
|
|
236
|
+
const active: WorkerRow[] = [];
|
|
237
|
+
for (const row of rows) {
|
|
238
|
+
if (!row.droppedAt && await this.reconcileWorker(row)) active.push(row);
|
|
239
|
+
}
|
|
240
|
+
return active;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
private async reconcileWorker(row: WorkerRow): Promise<boolean> {
|
|
244
|
+
const summary = await this.conversations.get(row.conversationId);
|
|
245
|
+
if (summary && !summary.deletedAt) return true;
|
|
246
|
+
await this.markDropped(row);
|
|
247
|
+
return false;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
private dispatch(
|
|
251
|
+
slot: ReturnType<WorkerPool["attach"]>, actor: WorkerActor, text: string, plan: AssignmentPlan,
|
|
252
|
+
accepted?: () => Promise<() => void>,
|
|
253
|
+
): void {
|
|
254
|
+
const sender = actor.kind === "conversation" ? actor.sender : undefined;
|
|
255
|
+
const active = this.pool.start(slot, plan.assignment, sender);
|
|
256
|
+
const row = slot.row;
|
|
257
|
+
const identity = this.identity(row);
|
|
258
|
+
if (plan.kind === "start") this.emit({ ...identity, kind: "worker_busy" });
|
|
259
|
+
const policyNames = actor.kind === "conversation" ? [...actor.policyNames] : [];
|
|
260
|
+
let crossedDispatch = false;
|
|
261
|
+
let announceRedirect: (() => void) | undefined;
|
|
262
|
+
const confirmDispatch = () => {
|
|
263
|
+
const announce = announceRedirect;
|
|
264
|
+
announceRedirect = undefined;
|
|
265
|
+
announce?.();
|
|
266
|
+
};
|
|
267
|
+
const input = {
|
|
268
|
+
text,
|
|
269
|
+
handlers: {
|
|
270
|
+
onPermissionRequest: workerPermissionHandler(actor, row, this.findGivingConversation, this.defaultWorkerPermissions),
|
|
271
|
+
...(accepted ? { onUpdate: confirmDispatch } : {}),
|
|
272
|
+
},
|
|
273
|
+
delivery: plan.kind === "start" ? "queue" as const : "steer" as const,
|
|
274
|
+
...(actor.kind === "conversation" || accepted ? { beforeDispatch: async (messageId: string) => {
|
|
275
|
+
const assignment = await this.assignments?.beforeDispatch(row, plan, messageId, policyNames, actor.kind === "conversation" ? actor : undefined);
|
|
276
|
+
if (assignment) active.assignment = assignment;
|
|
277
|
+
crossedDispatch = true;
|
|
278
|
+
// Reservation and retarget have committed. Bookkeeping errors must not refuse that accepted dispatch.
|
|
279
|
+
try { announceRedirect = await accepted?.(); }
|
|
280
|
+
catch (error) { this.log.warn("worker_dispatch_bookkeeping_failed", { handle: row.handle, error: String(error) }); }
|
|
281
|
+
} } : {}),
|
|
282
|
+
};
|
|
283
|
+
const work = sender === undefined ? slot.conversation.prompt(input) : slot.conversation.promptFrom({ ...input, participantId: sender });
|
|
284
|
+
const completion = work.then(result => {
|
|
285
|
+
if (result.status === "completed") {
|
|
286
|
+
confirmDispatch();
|
|
287
|
+
this.emit({ ...identity, kind: "worker_replied" });
|
|
288
|
+
} else if (result.status === "error") this.emit({ ...identity, kind: "worker_failed", reason: workerTerminalFailure(false).reason });
|
|
289
|
+
}, async (error: unknown) => {
|
|
290
|
+
this.log.warn("worker_prompt_failed", { conversationId: slot.conversation.id, error: String(error) });
|
|
291
|
+
if (!crossedDispatch && actor.kind === "conversation") {
|
|
292
|
+
const cause = error instanceof WorkerAssignmentConflict ? "conflict" : "hook_error";
|
|
293
|
+
this.emit({ ...identity, kind: "worker_failed", reason: "refused", cause, destination: actor.conversationId });
|
|
294
|
+
try { await this.assignments?.refuse?.(row, plan, { actor, cause }); }
|
|
295
|
+
catch (failure) { this.log.warn("worker_refusal_persistence_failed", { handle: row.handle, error: String(failure) }); }
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
this.emit({ ...identity, kind: "worker_failed", reason: workerTerminalFailure(false, error).reason });
|
|
299
|
+
}).finally(() => {
|
|
300
|
+
slot.completions.delete(completion);
|
|
301
|
+
this.pool.finish(slot, active);
|
|
302
|
+
const touched = slot.touched;
|
|
303
|
+
const idle = () => {
|
|
304
|
+
if (slot.touched !== touched || this.pool.get(row.handle) !== slot || this.pool.busy(slot)) return;
|
|
305
|
+
this.emit({ ...this.identity(slot.row), kind: "worker_idle" });
|
|
306
|
+
this.pool.armIdle(slot, row => this.emit({ ...this.identity(row), kind: "worker_stopped", reason: "idle" }),
|
|
307
|
+
error => this.log.warn("worker_idle_stop_failed", { handle: slot.row.handle, error: String(error) }));
|
|
308
|
+
};
|
|
309
|
+
const flush = actor.kind === "conversation" && this.assignments?.settled?.();
|
|
310
|
+
if (flush) return flush.finally(idle);
|
|
311
|
+
idle();
|
|
312
|
+
});
|
|
313
|
+
slot.completions.add(completion);
|
|
314
|
+
this.completions.add(completion);
|
|
315
|
+
const forget = () => { this.completions.delete(completion); };
|
|
316
|
+
void completion.then(forget, forget);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { PermissionSettings } from "../permissions/matcher.ts";
|
|
2
|
+
import type { AgentConversationId } from "../agent-ids.ts";
|
|
3
|
+
import { forwardPermission } from "../permissions/conversation.ts";
|
|
4
|
+
import { selectPermissionOutcome } from "../permissions/outcome.ts";
|
|
5
|
+
import type { WorkerRow } from "../persistence/workers.ts";
|
|
6
|
+
import type { PromptHandlers } from "../types.ts";
|
|
7
|
+
import type { WorkerActor } from "./contracts.ts";
|
|
8
|
+
import { matchWorkerPermissionLevel } from "./policy.ts";
|
|
9
|
+
|
|
10
|
+
export type FindGivingConversation = (id: AgentConversationId) => object | undefined;
|
|
11
|
+
|
|
12
|
+
export function workerPermissionHandler(
|
|
13
|
+
actor: WorkerActor, worker: WorkerRow, findGivingConversation?: FindGivingConversation, defaults: readonly PermissionSettings[] = [],
|
|
14
|
+
): NonNullable<PromptHandlers["onPermissionRequest"]> {
|
|
15
|
+
return (request, signal) => {
|
|
16
|
+
const level = matchWorkerPermissionLevel(request, actor.kind === "consumer" ? defaults : actor.workerPermissions);
|
|
17
|
+
if (level !== "ask") return selectPermissionOutcome(level, request.options)!;
|
|
18
|
+
if (actor.kind === "consumer") return selectPermissionOutcome("deny", request.options)!;
|
|
19
|
+
return forwardPermission(findGivingConversation?.(actor.conversationId), request, {
|
|
20
|
+
source: { kind: "worker", handle: worker.handle, conversationId: worker.conversationId },
|
|
21
|
+
includeAllowAlways: actor.isOwner === true,
|
|
22
|
+
signal,
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { RunningAssignment } from "./assignments.ts";
|
|
2
|
+
import { matchPermissionLevel, mostRestrictivePermissionLevel, type PermissionLevel, type PermissionSettings } from "../permissions/matcher.ts";
|
|
3
|
+
import type { NeutralPermissionRequest } from "../permissions/request.ts";
|
|
4
|
+
import { WorkerPolicyError } from "../errors.ts";
|
|
5
|
+
import type { WorkerRow } from "../persistence/workers.ts";
|
|
6
|
+
import type { DelegationPolicy, WorkerActor } from "./contracts.ts";
|
|
7
|
+
|
|
8
|
+
export function canSeeWorker(actor: WorkerActor, row: WorkerRow, running?: RunningAssignment): boolean {
|
|
9
|
+
return actor.kind === "consumer" || actor.policy.scope === "all"
|
|
10
|
+
|| row.openedBy === actor.conversationId || running?.destination === actor.conversationId;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function requireWorkerUse(actor: WorkerActor): void {
|
|
14
|
+
if (actor.kind === "conversation" && !actor.policy.use) throw new WorkerPolicyError("use");
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function composeDelegationPolicy(policies: readonly DelegationPolicy[]): DelegationPolicy {
|
|
18
|
+
if (!policies.length) throw new Error("at least one delegation policy is required");
|
|
19
|
+
const cap = Math.min(...policies.map(policy => policy.maxOpen ?? Infinity));
|
|
20
|
+
return {
|
|
21
|
+
use: policies.every(policy => policy.use),
|
|
22
|
+
scope: policies.every(policy => policy.scope === "all") ? "all" : "none",
|
|
23
|
+
redirect: policies.every(policy => policy.redirect),
|
|
24
|
+
...(cap === Infinity ? {} : { maxOpen: cap }),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Match within each policy before reducing so each policy uses its own fallback. */
|
|
29
|
+
export function matchWorkerPermissionLevel(
|
|
30
|
+
request: Partial<Pick<NeutralPermissionRequest, "tool">>, policies: readonly PermissionSettings[],
|
|
31
|
+
): PermissionLevel {
|
|
32
|
+
if (!policies.length) return "ask";
|
|
33
|
+
return policies.map(policy => matchPermissionLevel(request, policy)).reduce(mostRestrictivePermissionLevel);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function requireWorkerRedirect(actor: WorkerActor): void {
|
|
37
|
+
if (actor.kind === "conversation" && !actor.policy.redirect) throw new WorkerPolicyError("redirect");
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function checkWorkerOpenLimit(actor: WorkerActor, rows: readonly WorkerRow[]): void {
|
|
41
|
+
if (actor.kind === "consumer" || actor.policy.maxOpen === undefined) return;
|
|
42
|
+
const count = rows.filter(row => row.openedBy === actor.conversationId && row.droppedAt === undefined).length;
|
|
43
|
+
if (count >= actor.policy.maxOpen) throw new WorkerPolicyError("maxOpen");
|
|
44
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import type { RunningAssignment } from "./assignments.ts";
|
|
2
|
+
import type { AgentConversation } from "../agent-session.ts";
|
|
3
|
+
import type { WorkerRow } from "../persistence/workers.ts";
|
|
4
|
+
import type { WorkerSummary } from "./contracts.ts";
|
|
5
|
+
|
|
6
|
+
interface Slot {
|
|
7
|
+
readonly conversation: AgentConversation;
|
|
8
|
+
row: WorkerRow;
|
|
9
|
+
readonly completions: Set<Promise<void>>;
|
|
10
|
+
touched: number;
|
|
11
|
+
idleTimer?: ReturnType<typeof setTimeout>;
|
|
12
|
+
work?: { readonly started: number; readonly sender?: string; assignment: RunningAssignment };
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export class WorkerPool {
|
|
16
|
+
private readonly slots = new Map<string, Slot>();
|
|
17
|
+
private tail = Promise.resolve();
|
|
18
|
+
private access = 0;
|
|
19
|
+
private idleTimersClosed = false;
|
|
20
|
+
|
|
21
|
+
constructor(private readonly limit: number, private readonly idleStopMs: number | false) {}
|
|
22
|
+
|
|
23
|
+
run<T>(work: () => Promise<T>): Promise<T> {
|
|
24
|
+
const result = this.tail.then(work);
|
|
25
|
+
this.tail = result.then(() => undefined, () => undefined);
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
attach(row: WorkerRow, conversation: AgentConversation): Slot {
|
|
30
|
+
const slot: Slot = { row, conversation, touched: ++this.access, completions: new Set() };
|
|
31
|
+
this.slots.set(row.handle, slot);
|
|
32
|
+
return slot;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
get(handle: string): Slot | undefined {
|
|
36
|
+
const slot = this.slots.get(handle);
|
|
37
|
+
return slot?.conversation.state.phase === "stopped" ? undefined : slot;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async release(handle: string): Promise<void> {
|
|
41
|
+
const slot = this.slots.get(handle);
|
|
42
|
+
if (!slot) return;
|
|
43
|
+
this.cancelIdle(slot);
|
|
44
|
+
try {
|
|
45
|
+
await slot.conversation.stop();
|
|
46
|
+
} finally {
|
|
47
|
+
if (this.slots.get(handle) === slot) this.slots.delete(handle);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async makeRoom(onEvicted: (row: WorkerRow) => void): Promise<boolean> {
|
|
52
|
+
for (const [handle, slot] of this.slots) {
|
|
53
|
+
if (slot.conversation.state.phase !== "stopped") continue;
|
|
54
|
+
await this.release(handle);
|
|
55
|
+
}
|
|
56
|
+
if (this.slots.size < this.limit) return true;
|
|
57
|
+
const oldest = [...this.slots.entries()].filter(([, slot]) => !this.busy(slot))
|
|
58
|
+
.sort(([, left], [, right]) => left.touched - right.touched)[0];
|
|
59
|
+
if (!oldest) return false;
|
|
60
|
+
const [handle, slot] = oldest;
|
|
61
|
+
await this.release(handle);
|
|
62
|
+
onEvicted(slot.row);
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
busy(slot: Slot): boolean {
|
|
67
|
+
return Boolean(slot.work || slot.completions.size || slot.conversation.isBusy);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
start(slot: Slot, assignment: RunningAssignment, sender?: string): NonNullable<Slot["work"]> {
|
|
71
|
+
this.cancelIdle(slot);
|
|
72
|
+
slot.touched = ++this.access;
|
|
73
|
+
const started = slot.work?.started ?? performance.now();
|
|
74
|
+
return slot.work = { started, sender, assignment };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
finish(slot: Slot, work: Slot["work"]): void {
|
|
78
|
+
if (slot.work !== work) return;
|
|
79
|
+
slot.work = undefined;
|
|
80
|
+
slot.touched = ++this.access;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
armIdle(slot: Slot, onStopped: (row: WorkerRow) => void, onError: (error: unknown) => void): void {
|
|
84
|
+
if (this.idleTimersClosed || this.idleStopMs === false) return;
|
|
85
|
+
this.cancelIdle(slot);
|
|
86
|
+
const handle = slot.row.handle;
|
|
87
|
+
const timer = setTimeout(() => {
|
|
88
|
+
void this.run(async () => {
|
|
89
|
+
// The callback may have entered the queue before a send or teardown cancelled it.
|
|
90
|
+
if (slot.idleTimer !== timer) return;
|
|
91
|
+
slot.idleTimer = undefined;
|
|
92
|
+
if (this.idleTimersClosed || this.get(handle) !== slot || this.busy(slot)) return;
|
|
93
|
+
await this.release(handle);
|
|
94
|
+
onStopped(slot.row);
|
|
95
|
+
}).catch(onError);
|
|
96
|
+
}, this.idleStopMs);
|
|
97
|
+
timer.unref?.();
|
|
98
|
+
slot.idleTimer = timer;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
closeIdleTimers(): void {
|
|
102
|
+
this.idleTimersClosed = true;
|
|
103
|
+
for (const slot of this.slots.values()) this.cancelIdle(slot);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
private cancelIdle(slot: Slot): void {
|
|
107
|
+
clearTimeout(slot.idleTimer);
|
|
108
|
+
slot.idleTimer = undefined;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
summary(row: WorkerRow): WorkerSummary {
|
|
112
|
+
const slot = this.get(row.handle);
|
|
113
|
+
if (!slot) return { ...row, state: "offline" };
|
|
114
|
+
const operation = slot.conversation.state.operation;
|
|
115
|
+
return {
|
|
116
|
+
...row,
|
|
117
|
+
state: this.busy(slot) ? "busy" : "idle",
|
|
118
|
+
...(operation ? { operation } : {}),
|
|
119
|
+
...(slot.work?.sender === undefined ? {} : { sender: slot.work.sender }),
|
|
120
|
+
...(slot.work ? { busyMs: Math.max(0, performance.now() - slot.work.started) } : {}),
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Used when the delegation route installs the worker send operation. */
|
|
2
|
+
export const WORKER_SEND_DESCRIPTION = [
|
|
3
|
+
"Send work to a worker. Use about to give the worker a short label for check and list.",
|
|
4
|
+
'A busy send continues its running assignment by default. Set assignment to "new" to interrupt that assignment and start a separate one.',
|
|
5
|
+
"Set redirect to true to take over work from another conversation when policy permits.",
|
|
6
|
+
"Returns immediately without waiting for the worker's reply.",
|
|
7
|
+
'"sent" means work was accepted for a new run (with a handle when opening).',
|
|
8
|
+
'"steered" means a busy worker accepted the input.',
|
|
9
|
+
'"busy" means nothing was sent or queued.',
|
|
10
|
+
'"no_worker_free" means no slot is available and nothing was sent or queued.',
|
|
11
|
+
].join(" ");
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { RequestPermissionRequest } from "@agentclientprotocol/sdk";
|
|
2
|
+
import type { PermissionRequest } from "../types.ts";
|
|
3
|
+
|
|
4
|
+
/** Project the ACP packet while keeping the existing prompt callback fields and raw packet. */
|
|
5
|
+
export function toPermissionRequest(params: RequestPermissionRequest): PermissionRequest {
|
|
6
|
+
const call = params.toolCall;
|
|
7
|
+
const tool = {
|
|
8
|
+
...(call?.kind == null ? {} : { kind: call.kind }),
|
|
9
|
+
...(call?.rawInput === undefined ? {} : { rawInput: call.rawInput }),
|
|
10
|
+
};
|
|
11
|
+
return {
|
|
12
|
+
toolCallId: call?.toolCallId ?? "",
|
|
13
|
+
title: call?.title ?? undefined,
|
|
14
|
+
options: (params.options ?? []).map(({ optionId, name, kind }) => ({ optionId, name, kind })),
|
|
15
|
+
...(call?.kind != null || call?.rawInput !== undefined ? { tool } : {}),
|
|
16
|
+
raw: params,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { PermissionRequest } from "../types.ts";
|
|
2
|
+
|
|
3
|
+
export function permissionArrival() {
|
|
4
|
+
return { wallTime: Date.now(), monotonicTime: performance.now() };
|
|
5
|
+
}
|
|
6
|
+
export type PermissionArrival = ReturnType<typeof permissionArrival>;
|
|
7
|
+
|
|
8
|
+
export const acpPermissionArrivals = new WeakMap<PermissionRequest, PermissionArrival>();
|
|
9
|
+
|
|
10
|
+
export function stampAcpPermission(request: PermissionRequest): PermissionRequest {
|
|
11
|
+
acpPermissionArrivals.set(request, permissionArrival());
|
|
12
|
+
return request;
|
|
13
|
+
}
|