@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,130 @@
|
|
|
1
|
+
import type { StorageSnapshot } from "../../../contracts/storage.ts";
|
|
2
|
+
import type { FunctionCall, FunctionExecutor, ResultReference, ToolLimits, ToolOutcome, ToolRegistration } from "../../../contracts/tools.ts";
|
|
3
|
+
|
|
4
|
+
/** Adjustable defaults (BUSINESS_RULES.md, tools and callbacks). */
|
|
5
|
+
export const TOOL_LIMITS: Readonly<ToolLimits> = { inlineBytes: 16_384, previewBytes: 1_024, readBytes: 16_384 };
|
|
6
|
+
|
|
7
|
+
/** The wait for a callback ended for a reason that says nothing about its
|
|
8
|
+
* effect on the host: the connection is gone. The call stays dispatched with
|
|
9
|
+
* no result, so recovery reports it uncertain and nothing repeats it. */
|
|
10
|
+
export class CallbackLost extends Error {
|
|
11
|
+
constructor(message: string) { super(message); this.name = "CallbackLost"; }
|
|
12
|
+
}
|
|
13
|
+
/** A typed failure from the handler or the host: `{ code, message }`. */
|
|
14
|
+
export class CallbackFailure extends Error {
|
|
15
|
+
constructor(readonly code: string, message: string) { super(message); this.name = "CallbackFailure"; }
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
type Settled = { content: string; outcome: ToolOutcome };
|
|
19
|
+
const bytes = (text: string) => new TextEncoder().encode(text).length;
|
|
20
|
+
const failure = (status: "failed" | "interrupted", code: string, message: string, extra: Record<string, unknown> = {}): Settled =>
|
|
21
|
+
({ content: JSON.stringify({ ok: false, code, message, ...extra }), outcome: { status, code } });
|
|
22
|
+
const validReference = (value: unknown): value is ResultReference => {
|
|
23
|
+
const reference = value as ResultReference;
|
|
24
|
+
return !!reference && typeof reference === "object" && typeof reference.resultId === "string" && reference.resultId.trim().length > 0
|
|
25
|
+
&& Number.isSafeInteger(reference.bytes) && reference.bytes >= 0 && (reference.retention === "temporary" || reference.retention === "durable")
|
|
26
|
+
&& (reference.expiresAt === undefined || typeof reference.expiresAt === "string");
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/** Run one authorized catalog call through the executor (decision 0021). The
|
|
30
|
+
* caller has already recorded dispatch evidence. Resolves with the paired
|
|
31
|
+
* result and its outcome whenever the turn can go on: success, a typed
|
|
32
|
+
* failure, or the tool's deadline. Rejects when the turn cannot: it was
|
|
33
|
+
* interrupted, or the connection carrying the callback is gone. */
|
|
34
|
+
export async function runFunction(options: {
|
|
35
|
+
executor: FunctionExecutor; request: FunctionCall; registration: ToolRegistration;
|
|
36
|
+
defaultDeadlineMs?: number; limits: ToolLimits; signal: AbortSignal;
|
|
37
|
+
}): Promise<Settled> {
|
|
38
|
+
const { executor, request, registration, limits, signal } = options;
|
|
39
|
+
const deadline = registration.deadlineMs ?? options.defaultDeadlineMs;
|
|
40
|
+
// The executor's own signal: aborted by the turn's interruption or by the
|
|
41
|
+
// deadline. Either way the host is asked to stop and a late answer is ignored.
|
|
42
|
+
const wait = new AbortController();
|
|
43
|
+
// The wait itself ends on interruption, whether or not the executor reacts.
|
|
44
|
+
let stop!: (reason: unknown) => void;
|
|
45
|
+
const stopped = new Promise<never>((_, reject) => { stop = reject; });
|
|
46
|
+
stopped.catch(() => undefined);
|
|
47
|
+
const interrupted = () => { wait.abort(signal.reason); stop(signal.reason); };
|
|
48
|
+
signal.addEventListener("abort", interrupted, { once: true });
|
|
49
|
+
let timer: ReturnType<typeof setTimeout> | undefined, expired = false;
|
|
50
|
+
const timedOut = deadline === undefined ? undefined : new Promise<"deadline">(resolve => {
|
|
51
|
+
// An executor that honours the abort rejects its wait at once; `expired`
|
|
52
|
+
// tells that rejection apart from a failure of the call.
|
|
53
|
+
timer = setTimeout(() => { expired = true; wait.abort(new Error("tool deadline")); resolve("deadline"); }, deadline);
|
|
54
|
+
});
|
|
55
|
+
const timeout = () => failure("interrupted", "tool_timeout", `The tool did not answer within ${deadline} ms and was asked to stop. Whether it took effect is unknown; it was not retried.`, { effect: "unknown" });
|
|
56
|
+
try {
|
|
57
|
+
signal.throwIfAborted();
|
|
58
|
+
const answering = executor.call(request, wait.signal);
|
|
59
|
+
// Observed here so a rejection after the deadline is never unhandled.
|
|
60
|
+
answering.catch(() => undefined);
|
|
61
|
+
const answer = await Promise.race(timedOut ? [answering, timedOut, stopped] : [answering, stopped]);
|
|
62
|
+
signal.throwIfAborted();
|
|
63
|
+
if (answer === "deadline") return timeout();
|
|
64
|
+
if (answer && typeof answer === "object" && "reference" in answer && answer.reference !== undefined) {
|
|
65
|
+
if (!validReference(answer.reference) || typeof answer.preview !== "string")
|
|
66
|
+
return failure("failed", "invalid_result", "The tool returned a malformed result reference.");
|
|
67
|
+
const preview = bytes(answer.preview) > limits.previewBytes ? new TextDecoder().decode(new TextEncoder().encode(answer.preview).subarray(0, limits.previewBytes)) : answer.preview;
|
|
68
|
+
return { content: JSON.stringify({ ok: true, preview, result_id: answer.reference.resultId, bytes: answer.reference.bytes,
|
|
69
|
+
...(answer.reference.expiresAt ? { expires_at: answer.reference.expiresAt } : {}),
|
|
70
|
+
note: "The full result is stored. Read it in parts with read_tool_result and this result_id." }),
|
|
71
|
+
outcome: { status: "succeeded", reference: structuredClone(answer.reference) } };
|
|
72
|
+
}
|
|
73
|
+
const content = JSON.stringify({ ok: true, output: (answer as { output?: unknown })?.output ?? null });
|
|
74
|
+
// A producer stores what does not fit and sends a reference. Bytes that
|
|
75
|
+
// arrive inline anyway cannot be kept or shown in full.
|
|
76
|
+
if (bytes(content) > limits.inlineBytes) return failure("failed", "result_too_large", `The tool's result exceeds ${limits.inlineBytes} bytes and was not stored by its producer.`);
|
|
77
|
+
return { content, outcome: { status: "succeeded" } };
|
|
78
|
+
} catch (error) {
|
|
79
|
+
if (signal.aborted) throw signal.reason instanceof Error ? signal.reason : new Error("Turn interrupted");
|
|
80
|
+
if (expired) return timeout();
|
|
81
|
+
if (error instanceof CallbackFailure) return failure("failed", error.code, error.message);
|
|
82
|
+
throw error;
|
|
83
|
+
} finally {
|
|
84
|
+
clearTimeout(timer);
|
|
85
|
+
signal.removeEventListener("abort", interrupted);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Where a result ID was produced, from the references recorded with tool
|
|
90
|
+
* results. Only IDs the harness itself recorded resolve: a path or a made-up
|
|
91
|
+
* ID finds nothing. */
|
|
92
|
+
export function locateResult(view: StorageSnapshot, resultId: string): { channel: string; turnId: number; callId: string; reference: ResultReference } | undefined {
|
|
93
|
+
for (const entry of view.timeline) {
|
|
94
|
+
if (entry.message.role !== "tool" || entry.message.outcome?.reference?.resultId !== resultId) continue;
|
|
95
|
+
return { channel: entry.channelId, turnId: entry.turnId, callId: entry.message.callId, reference: entry.message.outcome.reference };
|
|
96
|
+
}
|
|
97
|
+
return undefined;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** The scoped reader (decision 0021). The requesting channel comes from the
|
|
101
|
+
* harness, never from the arguments: only the channel that produced a result
|
|
102
|
+
* can read it, whatever it has seen in shared history. */
|
|
103
|
+
export async function readResult(options: {
|
|
104
|
+
executor: FunctionExecutor | undefined; view: StorageSnapshot; channel: string; arguments: string; limits: ToolLimits; signal: AbortSignal; now?: () => number;
|
|
105
|
+
}): Promise<Settled> {
|
|
106
|
+
let args: { result_id?: unknown; offset?: unknown; length?: unknown };
|
|
107
|
+
try { args = JSON.parse(options.arguments); } catch { return failure("failed", "invalid_arguments", "read_tool_result needs a JSON object."); }
|
|
108
|
+
if (typeof args?.result_id !== "string" || !args.result_id) return failure("failed", "invalid_arguments", "read_tool_result needs result_id.");
|
|
109
|
+
const offset = args.offset === undefined ? 0 : args.offset, length = args.length === undefined ? options.limits.readBytes : args.length;
|
|
110
|
+
if (!Number.isSafeInteger(offset) || (offset as number) < 0 || !Number.isSafeInteger(length) || (length as number) < 1)
|
|
111
|
+
return failure("failed", "invalid_arguments", "offset must be a nonnegative integer and length a positive integer.");
|
|
112
|
+
const found = locateResult(options.view, args.result_id);
|
|
113
|
+
if (!found) return failure("failed", "result_not_found", "No stored result has this result_id. Use an ID returned by a tool in this conversation.");
|
|
114
|
+
if (found.channel !== options.channel) return failure("failed", "result_forbidden", "That result belongs to another conversation and cannot be read here.");
|
|
115
|
+
if (found.reference.expiresAt !== undefined && Date.parse(found.reference.expiresAt) <= (options.now ?? Date.now)())
|
|
116
|
+
return failure("failed", "result_expired", "That result was temporary and has expired. The original tool call keeps its recorded outcome.");
|
|
117
|
+
if (!options.executor) return failure("failed", "result_unavailable", "The process that holds that result is not connected.");
|
|
118
|
+
try {
|
|
119
|
+
const page = await options.executor.read({ resultId: args.result_id, invocationId: `${found.turnId}:${found.callId}`, channel: options.channel,
|
|
120
|
+
offset: offset as number, length: Math.min(length as number, options.limits.readBytes) }, options.signal);
|
|
121
|
+
options.signal.throwIfAborted();
|
|
122
|
+
const text = String(page.text ?? "");
|
|
123
|
+
return { content: JSON.stringify({ ok: true, text, total_bytes: page.totalBytes, eof: page.eof === true,
|
|
124
|
+
...(page.eof === true ? {} : { next_offset: (offset as number) + bytes(text) }) }), outcome: { status: "succeeded" } };
|
|
125
|
+
} catch (error) {
|
|
126
|
+
if (options.signal.aborted) throw options.signal.reason instanceof Error ? options.signal.reason : new Error("Turn interrupted");
|
|
127
|
+
if (error instanceof CallbackFailure) return failure("failed", error.code, error.message);
|
|
128
|
+
throw error;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { StorageSnapshot } from "../../../contracts/storage.ts";
|
|
2
|
+
import type { ToolInvocation } from "../../../contracts/tools.ts";
|
|
3
|
+
|
|
4
|
+
export const invocationId = (turnId: number | string, toolCallId: string) => `${turnId}:${toolCallId}`;
|
|
5
|
+
|
|
6
|
+
/** Invocation records for one turn, in request order, derived from what storage
|
|
7
|
+
* already commits (decision 0021): the assistant's calls, the dispatch
|
|
8
|
+
* evidence of decision 0018, the paired results and the turn's end. `waiting`
|
|
9
|
+
* holds the invocation IDs with a live approval request in this process. */
|
|
10
|
+
export function turnInvocations(view: StorageSnapshot, turnId: number, waiting: ReadonlySet<string> = new Set()): ToolInvocation[] {
|
|
11
|
+
const turn = view.turns.find(value => value.turnId === turnId);
|
|
12
|
+
if (!turn) return [];
|
|
13
|
+
const results = new Map<string, Extract<StorageSnapshot["timeline"][number]["message"], { role: "tool" }>>();
|
|
14
|
+
for (const entry of view.timeline) if (entry.turnId === turnId && entry.message.role === "tool") results.set(entry.message.callId, entry.message);
|
|
15
|
+
const state = turn.state;
|
|
16
|
+
const dispatched = state.status === "running" || state.status === "suspended" ? state.dispatchedCallIds : undefined;
|
|
17
|
+
const ended = state.status === "failed" || state.status === "interrupted";
|
|
18
|
+
const uncertain = ended ? new Set(state.uncertainCallIds) : undefined;
|
|
19
|
+
const records: ToolInvocation[] = [];
|
|
20
|
+
for (const entry of view.timeline) {
|
|
21
|
+
if (entry.turnId !== turnId || entry.message.role !== "assistant") continue;
|
|
22
|
+
for (const call of entry.message.calls) {
|
|
23
|
+
const id = invocationId(turnId, call.id), result = results.get(call.id);
|
|
24
|
+
const base = { invocationId: id, channel: turn.channelId, turnId: String(turnId), toolCallId: call.id, tool: call.name, arguments: call.arguments };
|
|
25
|
+
if (result) {
|
|
26
|
+
// A result written before decision 0021, or by a built-in, is a success.
|
|
27
|
+
const outcome = result.outcome ?? { status: "succeeded" as const };
|
|
28
|
+
records.push({ ...base, state: outcome.status, ...(outcome.code === undefined ? {} : { code: outcome.code }),
|
|
29
|
+
...(outcome.status === "skipped" ? { effect: "none" as const } : outcome.status === "interrupted" ? { effect: "unknown" as const } : {}),
|
|
30
|
+
...(outcome.reference ? { reference: outcome.reference } : {}) });
|
|
31
|
+
} else if (uncertain) {
|
|
32
|
+
// The turn ended. With dispatch evidence and no result the effect is
|
|
33
|
+
// unknown, and stays so: the harness never repeats the call. Without
|
|
34
|
+
// evidence the call never left the harness.
|
|
35
|
+
records.push(uncertain.has(call.id) ? { ...base, state: "interrupted", effect: "unknown" } : { ...base, state: "skipped", code: "turn_ended", effect: "none" });
|
|
36
|
+
} else if (dispatched?.includes(call.id)) records.push({ ...base, state: "started" });
|
|
37
|
+
else records.push({ ...base, state: waiting.has(id) ? "waiting_for_approval" : "requested" });
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return records;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** One record by its ID, or undefined. */
|
|
44
|
+
export function findInvocation(view: StorageSnapshot, id: string, waiting?: ReadonlySet<string>): ToolInvocation | undefined {
|
|
45
|
+
const at = id.indexOf(":"), turnId = Number(id.slice(0, at));
|
|
46
|
+
if (at < 1 || !Number.isSafeInteger(turnId) || String(turnId) !== id.slice(0, at)) return undefined;
|
|
47
|
+
return turnInvocations(view, turnId, waiting).find(record => record.invocationId === id);
|
|
48
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ExecuteTool, ToolDefinition } from "../../../contracts/loop.ts";
|
|
2
|
+
|
|
3
|
+
/** Test setup registers this explicitly; normal agent startup never does. */
|
|
4
|
+
export const echoDefinition: ToolDefinition = {
|
|
5
|
+
name: "echo",
|
|
6
|
+
description: "Return the supplied text unchanged. Available only in offline test scenarios.",
|
|
7
|
+
parameters: { type: "object", properties: { text: { type: "string" } }, required: ["text"], additionalProperties: false },
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const executeEcho: ExecuteTool = async call => {
|
|
11
|
+
try {
|
|
12
|
+
if (call.name !== "echo") throw new Error(`Tool not allowed in this test: ${call.name}`);
|
|
13
|
+
const args = JSON.parse(call.arguments);
|
|
14
|
+
if (!args || typeof args !== "object" || Array.isArray(args)
|
|
15
|
+
|| Object.keys(args).length !== 1 || typeof args.text !== "string") throw new Error("echo requires exactly one string argument: text");
|
|
16
|
+
return JSON.stringify({ ok: true, text: args.text });
|
|
17
|
+
} catch (error) { return JSON.stringify({ ok: false, error: String(error) }); }
|
|
18
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { appendFileSync, existsSync } from "node:fs";
|
|
2
|
+
import type { ExecuteTool, ToolDefinition } from "../../../contracts/loop.ts";
|
|
3
|
+
|
|
4
|
+
/** Offline scenarios only: a tool with an effect outside the session, so a test
|
|
5
|
+
* can count how many times a call really ran across process restarts. */
|
|
6
|
+
export const recordDefinition: ToolDefinition = {
|
|
7
|
+
name: "record",
|
|
8
|
+
description: "Append the supplied text as one line to the scenario's effect log. Available only in offline test scenarios.",
|
|
9
|
+
parameters: { type: "object", properties: { text: { type: "string" } }, required: ["text"], additionalProperties: false },
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export function createRecordTool(path: string | undefined): ExecuteTool {
|
|
13
|
+
return async call => {
|
|
14
|
+
try {
|
|
15
|
+
const args = JSON.parse(call.arguments);
|
|
16
|
+
if (!args || typeof args !== "object" || typeof args.text !== "string" || Object.keys(args).length !== 1) throw new Error("record requires exactly one string argument: text");
|
|
17
|
+
if (!path) throw new Error("No effect log is configured for this scenario");
|
|
18
|
+
appendFileSync(path, `${args.text}\n`);
|
|
19
|
+
return JSON.stringify({ ok: true });
|
|
20
|
+
} catch (error) { return JSON.stringify({ ok: false, error: String(error) }); }
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Offline scenarios only: a tool a test can keep running. It logs `start:<key>`,
|
|
25
|
+
* waits until the file `<log>.release-<key>` exists, then logs `done:<key>`.
|
|
26
|
+
* Cancellation rejects without logging `done`. */
|
|
27
|
+
export const holdDefinition: ToolDefinition = {
|
|
28
|
+
name: "hold",
|
|
29
|
+
description: "Wait until the scenario releases the named key. Available only in offline test scenarios.",
|
|
30
|
+
parameters: { type: "object", properties: { key: { type: "string" } }, required: ["key"], additionalProperties: false },
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export function createHoldTool(path: string | undefined): ExecuteTool {
|
|
34
|
+
return async (call, signal) => {
|
|
35
|
+
const args = JSON.parse(call.arguments);
|
|
36
|
+
if (!path || typeof args?.key !== "string" || !/^[a-z0-9-]+$/.test(args.key)) return JSON.stringify({ ok: false, error: "hold requires a key and a configured effect log" });
|
|
37
|
+
appendFileSync(path, `start:${args.key}\n`);
|
|
38
|
+
while (!existsSync(`${path}.release-${args.key}`)) {
|
|
39
|
+
signal?.throwIfAborted();
|
|
40
|
+
await new Promise(resolve => setTimeout(resolve, 5));
|
|
41
|
+
}
|
|
42
|
+
// Released and cancelled in the same instant still counts as cancelled.
|
|
43
|
+
signal?.throwIfAborted();
|
|
44
|
+
appendFileSync(path, `done:${args.key}\n`);
|
|
45
|
+
return JSON.stringify({ ok: true });
|
|
46
|
+
};
|
|
47
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { SESSION_INPUT_MAX_BYTES } from "../../../contracts/input-limits.ts";
|
|
2
|
+
import type { TimelineRetrievalReads } from "../../../contracts/storage.ts";
|
|
3
|
+
import type { TimelineSearch, TimelineWindow } from "../../../contracts/timeline-retrieval.ts";
|
|
4
|
+
import type { ToolDefinition } from "../../../contracts/loop.ts";
|
|
5
|
+
import { timelineQuery } from "../../../util/timeline-text.ts";
|
|
6
|
+
import { timelineToolNames } from "../../../util/timeline-tool-names.ts";
|
|
7
|
+
import { schemaProblem } from "../../../util/schema.ts";
|
|
8
|
+
|
|
9
|
+
const [search, read] = timelineToolNames;
|
|
10
|
+
const text = { type: "string", minLength: 1 };
|
|
11
|
+
const count = { type: "integer", minimum: 0, maximum: 20 };
|
|
12
|
+
export const timelineDefinitions: readonly ToolDefinition[] = [
|
|
13
|
+
{ name: search, description: "Find earlier attributed text in the shared session timeline.", parameters: {
|
|
14
|
+
type: "object", required: ["query"], additionalProperties: false, properties: {
|
|
15
|
+
query: text, channel: text, match: { enum: ["keywords", "phrase"] }, case_sensitive: { type: "boolean" },
|
|
16
|
+
},
|
|
17
|
+
} },
|
|
18
|
+
{ name: read, description: "Read an attributed timeline message and optional same-channel neighbors.", parameters: {
|
|
19
|
+
type: "object", required: ["message_id"], additionalProperties: false, properties: {
|
|
20
|
+
message_id: text, before: count, after: count, cursor: text,
|
|
21
|
+
},
|
|
22
|
+
} },
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
export function timelineArgumentsProblem(name: string, args: unknown): string | undefined {
|
|
26
|
+
const definition = timelineDefinitions.find(tool => tool.name === name)!;
|
|
27
|
+
const problem = schemaProblem(definition.parameters, args);
|
|
28
|
+
if (problem) return problem;
|
|
29
|
+
const value = args as Record<string, unknown>;
|
|
30
|
+
for (const [key, field] of Object.entries(value)) {
|
|
31
|
+
if (typeof field === "string" && (!field.trim() || Buffer.byteLength(field) > (key === "cursor" ? 32768 : key === "query" ? 1024 : SESSION_INPUT_MAX_BYTES))) return `Invalid ${key}`;
|
|
32
|
+
}
|
|
33
|
+
if (name === search && !timelineQuery(args as TimelineSearch)) return "Query requires searchable words within timeline limits";
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function runTimelineTool(store: TimelineRetrievalReads, name: string, args: unknown, signal?: AbortSignal): string {
|
|
38
|
+
signal?.throwIfAborted();
|
|
39
|
+
const result = name === search ? store.searchTimeline(args as TimelineSearch, 8192) : store.readMessage(args as TimelineWindow, 8192);
|
|
40
|
+
return JSON.stringify(result.ok ? result.value : { ok: false, ...result.error });
|
|
41
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export { HarnessClient, HarnessClientError, FunctionError } from "./interfaces/client.ts";
|
|
2
|
+
export type { FunctionHandler, ResultReader } from "./interfaces/client.ts";
|
|
3
|
+
export type { ToolRegistration, ToolCatalogInput, ToolAvailability, ToolInvocation, ToolInvocationState, ToolOutcome, ResultReference, TurnPhase, FunctionCall, FunctionResult, ResultRead, ResultPage } from "./contracts/tools.ts";
|
|
4
|
+
export { createInProcessTransport } from "./interfaces/protocol/in-process.ts";
|
|
5
|
+
export { createStdioTransport } from "./interfaces/protocol/stdio-client.ts";
|
|
6
|
+
export type { StdioConnection } from "./contracts/protocol.ts";
|
|
7
|
+
export type { ChannelEvent } from "./contracts/events.ts";
|
|
8
|
+
export type { InitializeParams, CreateParams, PushParams, NotifyParams, ProtocolConfig, ClientTransport, PendingChannelChange, ChannelChangeResult, LoadResult, StatusResult, ChannelStatusResult, ItemStatus, TurnStatus, StoredMessage } from "./contracts/protocol.ts";
|
|
9
|
+
export type { ManagedConfig, ManagedModel, ToolPolicy, ToolDecision, ItemPolicy, ApprovalRequest, ApprovalAnswer, ApprovalCloseReason } from "./contracts/config-permissions.ts";
|
|
10
|
+
|
|
11
|
+
export type { ModelCallSummary, ModelAttemptSummary, ModelUsage, ModelTextEvent, ModelTextPage } from "./contracts/model-execution.ts";
|
|
12
|
+
export { aggregateUsage } from "./capabilities/model/usage.ts";
|
|
13
|
+
|
|
14
|
+
export type { Reminder, ReminderChange, ReminderChangeResult, ReminderList, ReminderListParams, ReminderWake, ReminderSessionEvent, ConditionalStopParams, ConditionalStopResult } from "./contracts/reminders.ts";
|
|
15
|
+
|
|
16
|
+
export type { InitializeResult } from "./contracts/protocol.ts";
|
|
17
|
+
export type { OpenResult } from "./contracts/operator-controls.ts";
|
|
18
|
+
export type { ReminderBlockReason, OneOffSchedule, ReminderSchedule, RoutineSchedule, IntervalRoutineSchedule, CalendarRoutineSchedule, RoutineEnd, RoutineDeliveryOptions, RoutineTimezoneMigration, ReminderLimits, ReminderChannelEvent } from "./contracts/reminders.ts";
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
|
|
2
|
+
/** Caller-provided routing and sender identity; not authentication. */
|
|
3
|
+
export interface ChannelInput {
|
|
4
|
+
channelId: string;
|
|
5
|
+
participantId: string;
|
|
6
|
+
text: string;
|
|
7
|
+
itemId?: string;
|
|
8
|
+
policy?: string | null;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface ChannelNotice {
|
|
12
|
+
channelId: string;
|
|
13
|
+
fromChannelId: string;
|
|
14
|
+
text: string;
|
|
15
|
+
/** Set by session assembly from the executing turn, never by model input. */
|
|
16
|
+
sourceTurnId?: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// ---- Durable delivery, decision 0013.
|
|
20
|
+
|
|
21
|
+
/** An owning host's external inbox input, with no harness source turn. */
|
|
22
|
+
export interface ExternalNotice {
|
|
23
|
+
channelId: string;
|
|
24
|
+
itemId: string;
|
|
25
|
+
text: string;
|
|
26
|
+
source?: string;
|
|
27
|
+
/** Configured user-facing names. Reserved internal names are invalid. */
|
|
28
|
+
policyNames: readonly string[];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export type ItemKind = "participant_message" | "channel_notice" | "external_notice";
|
|
32
|
+
|
|
33
|
+
/** Last confirmed evidence for an accepted input. `received`: committed to the
|
|
34
|
+
* durable inbox. `taken`: committed to the timeline and linked to its turn.
|
|
35
|
+
* `delivered`/`seen`: provider evidence from a request in that turn.
|
|
36
|
+
* `withdrawn`: removed from pending delivery before any take. */
|
|
37
|
+
export type ItemMilestone = "received" | "taken" | "delivered" | "seen" | "withdrawn";
|
|
38
|
+
// `withdrawn` (decision 0014) is the other terminal state of a `received` item:
|
|
39
|
+
// never taken, never in the timeline, never pending again.
|
|
40
|
+
|
|
41
|
+
/** Acknowledgment of durable acceptance only. It is returned after the inbox
|
|
42
|
+
* commit and says nothing about a reply. A retry with the same ID and payload
|
|
43
|
+
* returns the original item's current state with `duplicate: true`. Completion,
|
|
44
|
+
* replies and failure are observed separately as channel events: the
|
|
45
|
+
* `turn_started`/`turn_took` event listing `itemId` names the turn, and that
|
|
46
|
+
* turn's `message_completed`/`turn_ended` events carry the outcome. */
|
|
47
|
+
export type SendResult =
|
|
48
|
+
| { accepted: true; itemId: string; duplicate: boolean; milestone: ItemMilestone; turnId?: number }
|
|
49
|
+
| { accepted: false; error: string;
|
|
50
|
+
code: "invalid_input" | "invalid_policy" | "incompatible" | "item_conflict" | "not_running" | "stopped" | "not_found" | "storage_failure"
|
|
51
|
+
/** Decision 0014: the target channel is suspending or suspended. A retry of
|
|
52
|
+
* an already accepted input never gets this; it returns its recorded outcome. */
|
|
53
|
+
| "channel_suspended"
|
|
54
|
+
/** Decision 0014: the channel ID was deleted and is reserved. */
|
|
55
|
+
| "channel_retired" };
|
|
56
|
+
|
|
57
|
+
/** Shared entity with one delivery behavior for messages and notices: accept
|
|
58
|
+
* durably, then the channel takes the item as soon as it can. An active turn
|
|
59
|
+
* takes it at its next inference boundary; otherwise it starts the channel's
|
|
60
|
+
* next turn. Turns are sequential per channel and concurrent across channels.
|
|
61
|
+
* A failed or interrupted turn ends; its channel keeps accepting and running
|
|
62
|
+
* new work. There is deliberately no wait-for-reply operation here. */
|
|
63
|
+
export interface SessionAgent {
|
|
64
|
+
/** No running turn and no pending item that this process may start. */
|
|
65
|
+
idle(): boolean;
|
|
66
|
+
/** Synchronous: returns once the item is committed (Received) or refused. */
|
|
67
|
+
send(input: ChannelInput): SendResult;
|
|
68
|
+
/** Same acceptance for an internal notice; never waits for the target turn. */
|
|
69
|
+
notify(notice: ChannelNotice): SendResult;
|
|
70
|
+
/** Accepts or returns a recorded receipt without waiting for a reply. */
|
|
71
|
+
notifyExternal(notice: ExternalNotice): SendResult;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Identity of a live turn handed to composition. `resumed` marks continuation
|
|
75
|
+
* from a suspension checkpoint, where recorded work must not be repeated. */
|
|
76
|
+
export interface ActiveTurn { channelId: string; turnId: number; resumed: boolean }
|
|
77
|
+
|
|
78
|
+
/** The scheduler's durable boundary operations for one running turn. */
|
|
79
|
+
export interface TurnPort {
|
|
80
|
+
/** Aborts on session suspension or this turn's channel suspension only. It is
|
|
81
|
+
* never passed to ExecuteTool; already-dispatched calls keep running. */
|
|
82
|
+
suspensionSignal: AbortSignal;
|
|
83
|
+
/** Take pending items into this turn before building the next inference. */
|
|
84
|
+
take(): void;
|
|
85
|
+
/** Record provider evidence after a valid model response for this turn. */
|
|
86
|
+
confirm(milestone: "delivered" | "seen"): void;
|
|
87
|
+
/** Atomic finish decision after a tool-free response: true ends the turn as
|
|
88
|
+
* completed; false means items arrived first and the turn stays open. The
|
|
89
|
+
* loop then returns to the iteration boundary: checkpoint() first, and only
|
|
90
|
+
* if that is false, take() and another inference. */
|
|
91
|
+
finish(): boolean;
|
|
92
|
+
/** At every iteration boundary, before take(): false while neither the
|
|
93
|
+
* session nor this turn's channel is suspending. While either is suspending,
|
|
94
|
+
* checkpoints the turn and returns true; the loop must return "suspended"
|
|
95
|
+
* without taking or inferring. A naturally finished
|
|
96
|
+
* turn never reaches this call, because finish() returned true. */
|
|
97
|
+
checkpoint(): boolean;
|
|
98
|
+
/** Aborted on stop or when this turn is interrupted (decision 0014). Passed to
|
|
99
|
+
* the model and tools; after abort the turn is already interrupted and nothing
|
|
100
|
+
* further may be recorded for it. Interrupting another turn never aborts it. */
|
|
101
|
+
signal: AbortSignal;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Runs one live turn to its next durable resting point. Rejection fails the turn. */
|
|
105
|
+
export type TurnExecutor = (turn: ActiveTurn, port: TurnPort) => Promise<"completed" | "suspended">;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/** Decisions 0016 and 0017: a validated portable session configuration.
|
|
2
|
+
* Script files and credential environment variables are destination resources. */
|
|
3
|
+
export type ToolDecision = "allow" | "ask" | "deny";
|
|
4
|
+
export interface ToolPolicy { fallback: ToolDecision; tools: Record<string, ToolDecision> }
|
|
5
|
+
export type ManagedModel = { protocol: "scripted"; script: string }
|
|
6
|
+
| { protocol: "openrouter"; model: string; apiKeyEnv: string };
|
|
7
|
+
export interface ManagedConfig {
|
|
8
|
+
version: 1;
|
|
9
|
+
system: string;
|
|
10
|
+
model: ManagedModel;
|
|
11
|
+
defaultPolicy: string;
|
|
12
|
+
timelineTools?: boolean;
|
|
13
|
+
policies: Record<string, ToolPolicy>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Immutable acceptance metadata. `explicit` records absence distinctly from
|
|
17
|
+
* a named override. `inherited` is the deduplicated source-turn restriction
|
|
18
|
+
* set for a notice; callers cannot supply it for a participant message. */
|
|
19
|
+
export interface ItemPolicy {
|
|
20
|
+
explicit?: string;
|
|
21
|
+
resolved: string;
|
|
22
|
+
inherited: string[];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** One request names one exact call; arguments are the original JSON text.
|
|
26
|
+
* IDs are unique within the lifetime of a server and cannot authorize a
|
|
27
|
+
* different request. Requests never survive restart as grants. */
|
|
28
|
+
export interface ApprovalRequest {
|
|
29
|
+
requestId: string;
|
|
30
|
+
channel: string;
|
|
31
|
+
turnId: string;
|
|
32
|
+
toolCallId: string;
|
|
33
|
+
tool: string;
|
|
34
|
+
arguments: string;
|
|
35
|
+
}
|
|
36
|
+
export type ApprovalAnswer = "allow_once" | "deny";
|
|
37
|
+
/** Optional initialize field. Only true declares this connection as the
|
|
38
|
+
* approval consumer; callbacks must remain empty. */
|
|
39
|
+
export interface ApprovalInitialization { approval?: boolean }
|
|
40
|
+
export type ApprovalCloseReason = "approval_denied" | "approval_timeout" | "approval_unhandled"
|
|
41
|
+
| "approval_disconnected" | "approval_cancelled_by_suspension"
|
|
42
|
+
| "approval_cancelled_by_interrupt" | "approval_cancelled_by_stop"
|
|
43
|
+
/** Decision 0021: the tool was revoked or removed, or its handler left, while the request was open. */
|
|
44
|
+
| "tool_unavailable";
|
|
45
|
+
|
|
46
|
+
/** A skipped call records a paired tool result with this stable reason. */
|
|
47
|
+
export interface SkippedToolResult { ok: false; code: ApprovalCloseReason | "policy_denied"; message: string }
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type { Message, ToolCall, ExecuteTurnTool, ToolDefinition } from "./loop.ts";
|
|
2
|
+
import type { LoopEvent } from "./events.ts";
|
|
3
|
+
import type { StorageResult, StoredTurn, TimelineEntry } from "./storage.ts";
|
|
4
|
+
|
|
5
|
+
/** Effective limits for one session. Bytes refer to UTF-8 text or serialized
|
|
6
|
+
* records as documented by the relevant operation. */
|
|
7
|
+
export interface ContextLimits {
|
|
8
|
+
readonly maxInputBytes: number;
|
|
9
|
+
readonly maxTakenTextBytes: number;
|
|
10
|
+
readonly maxTakenItems: number;
|
|
11
|
+
readonly maxReadBytes: number;
|
|
12
|
+
readonly maxReadRecords: number;
|
|
13
|
+
readonly maxSharedCandidates: number;
|
|
14
|
+
readonly contextTokens: number;
|
|
15
|
+
readonly outputReserveTokens: number;
|
|
16
|
+
readonly estimationMarginTokens: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Historical failure evidence associated with selected history. */
|
|
20
|
+
export type ContextTurnOutcome = Pick<StoredTurn, "channelId" | "turnId" | "state">;
|
|
21
|
+
|
|
22
|
+
/** Detached inputs for one build, all read at the StorageResult revision.
|
|
23
|
+
* Each record list is ordered by timeline sequence. Merge required and optional
|
|
24
|
+
* turn records by sequence before rendering them. Required records and complete
|
|
25
|
+
* policy evidence fit in full or the read reports context_limit. */
|
|
26
|
+
export interface InferenceRead {
|
|
27
|
+
readonly required: readonly TimelineEntry[];
|
|
28
|
+
readonly optionalTurn: readonly TimelineEntry[];
|
|
29
|
+
readonly localHistory: readonly TimelineEntry[];
|
|
30
|
+
readonly sharedHistory: readonly TimelineEntry[];
|
|
31
|
+
readonly unfinished: readonly ContextTurnOutcome[];
|
|
32
|
+
/** Newly taken items in boundary order, including those taken before resume. */
|
|
33
|
+
readonly takenItemIds: readonly string[];
|
|
34
|
+
/** Complete policy provenance of the turn, independent of prompt trimming. */
|
|
35
|
+
readonly policyNames: readonly string[];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** The session storage adapter supplies the coherent bounded read. */
|
|
39
|
+
export interface InferenceStorageReads {
|
|
40
|
+
readInferencePolicies(turnId: number, limits: ContextLimits): StorageResult<readonly string[] | { readonly code: "context_limit" }>;
|
|
41
|
+
readInferenceContext(input: { channelId: string; turnId: number; limits: ContextLimits }):
|
|
42
|
+
StorageResult<InferenceRead | { readonly code: "context_limit" }>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Optional diagnostics for an assembled request. */
|
|
46
|
+
export interface ContextCapture {
|
|
47
|
+
context: InferenceContext;
|
|
48
|
+
estimatedInputBytes: number;
|
|
49
|
+
/** Sequence numbers of selected and trimmed candidates from the bounded read. */
|
|
50
|
+
records: { included: number[]; trimmed: number[] };
|
|
51
|
+
omitted: { active: number; local: number; shared: number };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** One provider-neutral request. A retry reuses this capture. */
|
|
55
|
+
export interface InferenceContext {
|
|
56
|
+
readonly sessionId: string;
|
|
57
|
+
readonly channelId: string;
|
|
58
|
+
readonly turnId: number;
|
|
59
|
+
readonly timelineRevision: number;
|
|
60
|
+
readonly messages: readonly Message[];
|
|
61
|
+
readonly tools: readonly ToolDefinition[];
|
|
62
|
+
readonly fixedToolCount?: number;
|
|
63
|
+
/** Only original input items represented in this request may get receipts. */
|
|
64
|
+
readonly representedItemIds: readonly string[];
|
|
65
|
+
readonly takenItemIds: readonly string[];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Size failures happen before reserving a model call or attempt. */
|
|
69
|
+
export type ContextBuildResult = { readonly ok: true; readonly value: InferenceContext }
|
|
70
|
+
| { readonly ok: false; readonly code: "context_limit"; readonly message: string };
|
|
71
|
+
|
|
72
|
+
/** Attributed agent experience; system instructions are configuration, not events. */
|
|
73
|
+
export interface ContextEntry {
|
|
74
|
+
seq: number;
|
|
75
|
+
at: string;
|
|
76
|
+
channelId: string;
|
|
77
|
+
turnId: number;
|
|
78
|
+
from: string;
|
|
79
|
+
kind?: "participant_message" | "channel_notice" | "external_notice";
|
|
80
|
+
/** Optional host-supplied external attribution. */
|
|
81
|
+
externalSource?: string;
|
|
82
|
+
sourceChannelId?: string;
|
|
83
|
+
message: Message;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Read-only projection of the storage timeline. Values never alias stored
|
|
87
|
+
* records. Listeners run after a commit that changed the timeline. */
|
|
88
|
+
export interface SharedContextStore {
|
|
89
|
+
snapshot(): ContextEntry[];
|
|
90
|
+
subscribe(listener: () => void): () => void;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Turn-scoped operations available to the execution loop. */
|
|
94
|
+
export interface TurnContext {
|
|
95
|
+
append(message: Message): void;
|
|
96
|
+
/** The sole dispatch boundary. It records dispatch before invoking the tool,
|
|
97
|
+
* invokes before publishing started to prevent reentrant cancellation, and
|
|
98
|
+
* returns a paired skipped result for denial or closed approval. A test
|
|
99
|
+
* barrier resolves before the last cancellation check. */
|
|
100
|
+
dispatchTool(call: ToolCall, execute: ExecuteTurnTool): Promise<{ content: string; dispatched: boolean;
|
|
101
|
+
/** Decision 0021: recorded with the paired result of a dispatched call. */
|
|
102
|
+
outcome?: import("./tools.ts").ToolOutcome }>;
|
|
103
|
+
/** Take pending inbox items (messages and notices) into this turn. */
|
|
104
|
+
drainNotices?(): void;
|
|
105
|
+
finish?(): boolean;
|
|
106
|
+
emit?(event: LoopEvent): void;
|
|
107
|
+
/** Decision 0013. Throwing from append means the turn was fenced (stopped or
|
|
108
|
+
* ended); the loop must not continue. The members below mirror TurnPort. */
|
|
109
|
+
confirm?(milestone: "delivered" | "seen"): void;
|
|
110
|
+
checkpoint?(): boolean;
|
|
111
|
+
signal?: AbortSignal;
|
|
112
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/** Loop facts; composition supplies channel/turn IDs and message IDs. */
|
|
2
|
+
export type LoopEvent =
|
|
3
|
+
| ({ type: "message_completed"; position?: import("./operator-controls.ts").MessagePosition } & ({ parts: { type: "text"; text: string }[]; reference?: never } | { parts?: never; reference: true }))
|
|
4
|
+
/** Decision 0021 adds `invocationId` and, for catalog tools, `skipped` (never
|
|
5
|
+
* dispatched) and `interrupted` (the wait ended after dispatch: effect unknown). */
|
|
6
|
+
| { type: "tool_call"; id: string; name: string; status: "started" | "completed" | "failed" | "skipped" | "interrupted"; input?: string; output?: string; invocationId?: string };
|
|
7
|
+
|
|
8
|
+
/** Ordered within a channel; no order is promised across channels.
|
|
9
|
+
* With storage (decision 0013) every event except tool_call started/failed
|
|
10
|
+
* reports a committed record and is published only after that commit:
|
|
11
|
+
* - `revision` is the storage revision containing it. Event revisions never
|
|
12
|
+
* decrease on one subscription.
|
|
13
|
+
* - `turn_started`/`turn_took` list the item IDs that commit took into `turnId`.
|
|
14
|
+
* This is how an accepted input is correlated to its turn; several IDs,
|
|
15
|
+
* across one or more of these events, may name the same turn.
|
|
16
|
+
* - `items_receipt` reports Delivered/Seen for items of that turn, and is
|
|
17
|
+
* published only after a commit that advanced at least one milestone.
|
|
18
|
+
* - `message_completed.messageId` is the stable timeline ID of the message.
|
|
19
|
+
* - `turn_suspended` is a checkpoint, not an end (session or channel suspension);
|
|
20
|
+
* `turn_resumed` continues it under the same turn ID.
|
|
21
|
+
* - `channel_state` reports a committed change of the channel record: create,
|
|
22
|
+
* edit, suspension begun or completed, resume, retirement. It carries the
|
|
23
|
+
* resulting lifecycle and name, and no turn ID.
|
|
24
|
+
* - `item_withdrawn` reports a committed withdrawal of a pending item.
|
|
25
|
+
* - `turn_ended` is terminal for the turn only. `interrupted` and `failed` may
|
|
26
|
+
* list `uncertainCalls`, which are never replayed. The channel stays usable.
|
|
27
|
+
* Events are live notifications, not a durable replay log. */
|
|
28
|
+
export interface ChannelEvent {
|
|
29
|
+
channel: string;
|
|
30
|
+
revision?: number;
|
|
31
|
+
event: (LoopEvent & { turnId: string; messageId?: string })
|
|
32
|
+
| import("./model-execution.ts").ModelTextEvent
|
|
33
|
+
| { type: "turn_started" | "turn_took"; turnId: string; items: string[]; messages?: { itemId: string; messageId: string; position: import("./operator-controls.ts").MessagePosition }[] }
|
|
34
|
+
| { type: "items_receipt"; turnId: string; items: string[]; milestone: "delivered" | "seen" }
|
|
35
|
+
| { type: "turn_suspended" | "turn_resumed"; turnId: string }
|
|
36
|
+
| { type: "channel_state"; lifecycle: "open" | "suspending" | "suspended" | "retired"; displayName?: string; policy?: string }
|
|
37
|
+
| { type: "item_withdrawn"; item: string }
|
|
38
|
+
| (import("./reminders.ts").ReminderChannelEvent & { turnId?: never })
|
|
39
|
+
| import("./operator-controls.ts").ApprovalClosedEvent
|
|
40
|
+
| ({ type: "approval_requested" } & import("./config-permissions.ts").ApprovalRequest)
|
|
41
|
+
| { type: "turn_ended"; turnId: string; outcome: "completed" | "failed" | "interrupted"; error?: string; uncertainCalls?: string[] };
|
|
42
|
+
}
|
|
43
|
+
export type EventSink = (event: ChannelEvent) => void;
|
|
44
|
+
|
|
45
|
+
/** Published after the lifecycle transition commits. */
|
|
46
|
+
export interface SessionEvent { type: "lifecycle"; lifecycle: "running" | "suspending" | "suspended"; revision: number }
|
|
47
|
+
export type SessionEventSink = (event: SessionEvent) => void;
|