@qlairoslabs/acp-client 0.12.1 → 0.13.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG-consumer-fixes.md +17 -10
- package/CHANGELOG-controller-interface.md +258 -0
- package/CHANGELOG-metering.md +29 -0
- package/CHANGELOG-operation-lifecycle.md +15 -1
- package/CONSUMER_GUIDE.md +845 -6
- package/MIGRATION-0.10-to-0.12.md +4 -1
- package/MIGRATION-0.12-to-0.13.md +275 -0
- package/README.md +17 -16
- package/package.json +4 -2
- package/src/acp-client-handlers.ts +48 -0
- package/src/activity.ts +3 -0
- package/src/adapters.ts +25 -0
- package/src/agent/adoption/provider-attachment.ts +33 -0
- package/src/agent/adoption/provider-session-delete.ts +1 -1
- package/src/agent/adoption/provider-sessions.ts +3 -2
- package/src/agent/append-assistant-message.ts +91 -0
- package/src/agent/config.ts +54 -6
- package/src/agent/conversation-manager.ts +94 -158
- package/src/agent/manager-settings.ts +1 -0
- package/src/agent/native-channel-lifecycle.ts +111 -0
- package/src/agent/persisted-lifecycle.ts +44 -4
- package/src/agent/persistence-policy/context.ts +13 -0
- package/src/agent/persistence-policy/resolver.ts +7 -0
- package/src/agent/persistence-policy/types.ts +1 -0
- package/src/agent/record-capture.ts +1 -0
- package/src/agent-adapter-registry.ts +33 -7
- package/src/agent-conversation-contracts.ts +14 -1
- package/src/agent-conversation-errors.ts +8 -0
- package/src/agent-conversation-owner.ts +9 -4
- package/src/agent-session-config.ts +135 -0
- package/src/agent-session.ts +439 -934
- package/src/agent.ts +73 -0
- package/src/capabilities.ts +2 -0
- package/src/checkpointing/recovery.ts +3 -0
- package/src/cli/index.ts +3 -3
- package/src/cli/managed.ts +2 -2
- package/src/client.ts +52 -94
- package/src/connection-attempt.ts +95 -0
- package/src/controller-connection.ts +114 -0
- package/src/controller.ts +156 -148
- package/src/conversation-controller/capabilities.ts +88 -0
- package/src/conversation-controller/contracts.ts +208 -0
- package/src/conversation-controller/factory.ts +39 -0
- package/src/conversation-controller/guards.ts +98 -0
- package/src/conversation-controller/index.ts +20 -0
- package/src/conversation-startup.ts +35 -0
- package/src/conversation-turns/backend-turns.ts +373 -0
- package/src/conversation-turns/clear-operations.ts +37 -0
- package/src/conversation-turns/context.ts +135 -0
- package/src/conversation-turns/index.ts +4 -0
- package/src/conversation-turns/record-helpers.ts +75 -0
- package/src/conversation-turns/recording.ts +235 -0
- package/src/conversation-turns/run-turn.ts +367 -0
- package/src/conversation-turns/turn-run.ts +57 -0
- package/src/errors.ts +41 -0
- package/src/handoff-options.ts +81 -0
- package/src/identity/checkpoint-backed.ts +1 -1
- package/src/index.ts +58 -3
- package/src/internal-inference/coordination/manager.ts +11 -0
- package/src/internal-inference/runtime/harness-runtime.ts +4 -4
- package/src/launcher.ts +35 -2
- package/src/media/parts.ts +5 -0
- package/src/message-status.ts +83 -0
- package/src/metering/engine.ts +39 -64
- package/src/metering/measurement-provenance.ts +36 -0
- package/src/metering/native/durability.ts +115 -0
- package/src/metering/native/ledger.ts +104 -0
- package/src/metering/native/operation.ts +85 -0
- package/src/metering/native/projection.ts +114 -0
- package/src/metering/native/proof.ts +51 -0
- package/src/metering/native/requirements.ts +10 -0
- package/src/metering/native/retirement.ts +92 -0
- package/src/metering/native/source.ts +90 -0
- package/src/metering/record.ts +38 -1
- package/src/metering/state.ts +13 -3
- package/src/native/approvals.ts +169 -0
- package/src/native/capabilities.ts +17 -0
- package/src/native/channel-changes.ts +211 -0
- package/src/native/connection.ts +56 -0
- package/src/native/controller.ts +591 -0
- package/src/native/delegation-sender.ts +26 -0
- package/src/native/errors.ts +35 -0
- package/src/native/functions.ts +156 -0
- package/src/native/host-config.ts +59 -0
- package/src/native/host.ts +909 -0
- package/src/native/item-receipts.ts +15 -0
- package/src/native/metering.ts +12 -0
- package/src/native/records.ts +166 -0
- package/src/native/recovery.ts +186 -0
- package/src/native/reminders/fixtures/schema21.sqlite.gz +0 -0
- package/src/native/reminders/idle.ts +70 -0
- package/src/native/reminders/limits.ts +19 -0
- package/src/native/reminders/notifications.ts +29 -0
- package/src/native/reminders/reminders.test.ts +553 -0
- package/src/native/reminders/routine-config.typecheck.ts +13 -0
- package/src/native/reminders/routine-guard.ts +66 -0
- package/src/native/reminders/routine-schedule.ts +25 -0
- package/src/native/reminders/routine-wire.ts +21 -0
- package/src/native/reminders/schedule.ts +97 -0
- package/src/native/reminders/service.ts +280 -0
- package/src/native/reminders/supervisor.ts +91 -0
- package/src/native/reminders/sync.ts +301 -0
- package/src/native/reminders/wire.ts +197 -0
- package/src/native/reminders/wire.typecheck.ts +13 -0
- package/src/native/submission-withdrawal.ts +65 -0
- package/src/native/usage.ts +15 -0
- package/src/native/worker-delivery.ts +61 -0
- package/src/native-harness/.res/README.md +1 -0
- package/src/native-harness/.res/architecture/README.md +21 -0
- package/src/native-harness/.res/architecture/context-and-data.md +31 -0
- package/src/native-harness/.res/architecture/execution.md +42 -0
- package/src/native-harness/.res/architecture/overview.md +44 -0
- package/src/native-harness/.res/architecture/persistence.md +56 -0
- package/src/native-harness/.res/architecture/suspend-and-resume.md +45 -0
- package/src/native-harness/.res/architecture/technical-architecture.md +50 -0
- package/src/native-harness/.res/decisions/0001-basic-loop.md +11 -0
- package/src/native-harness/.res/decisions/0002-channel-input.md +17 -0
- package/src/native-harness/.res/decisions/0003-inference-inspection.md +14 -0
- package/src/native-harness/.res/decisions/0004-shared-context.md +21 -0
- package/src/native-harness/.res/decisions/0005-notice-inbox.md +20 -0
- package/src/native-harness/.res/decisions/0006-explicit-notices.md +12 -0
- package/src/native-harness/.res/decisions/0007-channel-output.md +12 -0
- package/src/native-harness/.res/decisions/0008-browser-client.md +16 -0
- package/src/native-harness/.res/decisions/0009-scripted-model.md +18 -0
- package/src/native-harness/.res/decisions/0010-inprocess-protocol.md +19 -0
- package/src/native-harness/.res/decisions/0011-stdio-transport.md +21 -0
- package/src/native-harness/.res/decisions/0012-session-storage-contract.md +37 -0
- package/src/native-harness/.res/decisions/0013-durable-delivery-contract.md +64 -0
- package/src/native-harness/.res/decisions/0014-channel-controls-contract.md +73 -0
- package/src/native-harness/.res/decisions/0015-session-file-contract.md +72 -0
- package/src/native-harness/.res/decisions/0016-configuration-permissions.md +159 -0
- package/src/native-harness/.res/decisions/0017-openrouter-managed-config.md +69 -0
- package/src/native-harness/.res/decisions/0018-tool-dispatch-evidence.md +78 -0
- package/src/native-harness/.res/decisions/0019-model-execution.md +188 -0
- package/src/native-harness/.res/decisions/0020-startup-channel-changes.md +71 -0
- package/src/native-harness/.res/decisions/0021-tools-and-host-callbacks.md +100 -0
- package/src/native-harness/.res/decisions/0022-operator-controls.md +115 -0
- package/src/native-harness/.res/decisions/0023-long-running-mock.md +82 -0
- package/src/native-harness/.res/decisions/0024-callback-policy-names.md +46 -0
- package/src/native-harness/.res/decisions/0025-external-notices.md +364 -0
- package/src/native-harness/.res/decisions/0026-bounded-context.md +81 -0
- package/src/native-harness/.res/decisions/0027-development-instructions.md +22 -0
- package/src/native-harness/.res/decisions/0028-debug-tools.md +16 -0
- package/src/native-harness/.res/decisions/0029-bounded-model-call-pages.md +37 -0
- package/src/native-harness/.res/decisions/0030-timeline-retrieval.md +145 -0
- package/src/native-harness/.res/decisions/0031-one-off-reminders.md +173 -0
- package/src/native-harness/.res/docs/11-15.md +148 -0
- package/src/native-harness/.res/docs/BUSINESS_RULES.md +111 -0
- package/src/native-harness/.res/docs/WORK.md +65 -0
- package/src/native-harness/.res/docs/_/11-16-persistence/LOG.md +312 -0
- package/src/native-harness/.res/docs/_/11-16-persistence/PLAN.md +77 -0
- package/src/native-harness/.res/docs/_/11-16-persistence/SPEC.md +313 -0
- package/src/native-harness/.res/docs/_/11-19-channel-controls/LOG.md +160 -0
- package/src/native-harness/.res/docs/_/11-19-channel-controls/PLAN.md +89 -0
- package/src/native-harness/.res/docs/_/11-19-channel-controls/SPEC.md +135 -0
- package/src/native-harness/.res/docs/_/11-19-config-permissions/LOG.md +143 -0
- package/src/native-harness/.res/docs/_/11-19-config-permissions/PLAN.md +93 -0
- package/src/native-harness/.res/docs/_/11-19-config-permissions/SPEC.md +181 -0
- package/src/native-harness/.res/docs/acp-client-integration/0001-DESIGN/11-20-LOG.md +433 -0
- package/src/native-harness/.res/docs/acp-client-integration/0001-DESIGN/PLAN.md +60 -0
- package/src/native-harness/.res/docs/acp-client-integration/0001-DESIGN/PROTOCOL.md +141 -0
- package/src/native-harness/.res/docs/acp-client-integration/0001-DESIGN/SPEC.md +168 -0
- package/src/native-harness/.res/docs/attachments/0001-DESIGN/SPEC.md +111 -0
- package/src/native-harness/.res/docs/bounded-context/0001-DESIGN/PLAN.md +129 -0
- package/src/native-harness/.res/docs/bounded-context/0001-DESIGN/SPEC.md +135 -0
- package/src/native-harness/.res/docs/channel-messaging/0001-DESIGN-external-notices/LOG.md +437 -0
- package/src/native-harness/.res/docs/channel-messaging/0001-DESIGN-external-notices/PLAN.md +127 -0
- package/src/native-harness/.res/docs/channel-messaging/0001-DESIGN-external-notices/SPEC.md +203 -0
- package/src/native-harness/.res/docs/long-running-mock/0001-DESIGN/LOG.md +292 -0
- package/src/native-harness/.res/docs/long-running-mock/0001-DESIGN/PLAN.md +91 -0
- package/src/native-harness/.res/docs/long-running-mock/0001-DESIGN/SPEC.md +187 -0
- package/src/native-harness/.res/docs/model-execution/0001-DESIGN/LOG.md +148 -0
- package/src/native-harness/.res/docs/model-execution/0001-DESIGN/PLAN.md +95 -0
- package/src/native-harness/.res/docs/model-execution/0001-DESIGN/SPEC.md +200 -0
- package/src/native-harness/.res/docs/model-execution/0002-AMENDMENT-accounting/SPEC.md +80 -0
- package/src/native-harness/.res/docs/operator-controls/0001-DESIGN/LOG.md +206 -0
- package/src/native-harness/.res/docs/operator-controls/0001-DESIGN/PLAN.md +106 -0
- package/src/native-harness/.res/docs/operator-controls/0001-DESIGN/SPEC.md +297 -0
- package/src/native-harness/.res/docs/persistence/0002-AMENDMENT-session-file/LOG.md +41 -0
- package/src/native-harness/.res/docs/persistence/0002-AMENDMENT-session-file/PLAN.md +36 -0
- package/src/native-harness/.res/docs/persistence/0002-AMENDMENT-session-file/SPEC.md +84 -0
- package/src/native-harness/.res/docs/shell-execution/0001-DESIGN/SPEC.md +147 -0
- package/src/native-harness/.res/docs/timeline-retrieval/0001-DESIGN/LOG.md +15 -0
- package/src/native-harness/.res/docs/timeline-retrieval/0001-DESIGN/PLAN.md +107 -0
- package/src/native-harness/.res/docs/timeline-retrieval/0001-DESIGN/SPEC.md +114 -0
- package/src/native-harness/.res/docs/todos/11-19-TODO-auto_review-approve.md +24 -0
- package/src/native-harness/.res/docs/todos/11-20-TODO-user-entered-tool-code.md +23 -0
- package/src/native-harness/.res/docs/todos/11-21-TODO-node-resource-coordination.md +103 -0
- package/src/native-harness/.res/docs/todos/11-22-TODO-harness-m1-sequence.md +50 -0
- package/src/native-harness/.res/docs/tools-and-callbacks/0001-DESIGN/LOG.md +337 -0
- package/src/native-harness/.res/docs/tools-and-callbacks/0001-DESIGN/PLAN.md +76 -0
- package/src/native-harness/.res/docs/tools-and-callbacks/0001-DESIGN/SPEC.md +204 -0
- package/src/native-harness/.res/docs/tools-and-callbacks/0002-AMENDMENT-callback-policy/LOG.md +73 -0
- package/src/native-harness/.res/docs/tools-and-callbacks/0002-AMENDMENT-callback-policy/SPEC.md +64 -0
- package/src/native-harness/.res/docs/tools-and-callbacks/0003-DESIGN-attachment-tools/SPEC.md +58 -0
- package/src/native-harness/.res/docs/tools-and-callbacks/0004-DESIGN-reminder-tools/LOG.md +45 -0
- package/src/native-harness/.res/docs/tools-and-callbacks/0004-DESIGN-reminder-tools/PLAN.md +108 -0
- package/src/native-harness/.res/docs/tools-and-callbacks/0004-DESIGN-reminder-tools/SPEC.md +169 -0
- package/src/native-harness/.res/docs/web-tools/0001-DESIGN/SPEC.md +128 -0
- package/src/native-harness/.res/marketing-draft.md +22 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/README.md +285 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-1.md +19 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-10.md +138 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-11.md +148 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-12.md +172 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-13.md +194 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-14.md +233 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-15.md +249 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-16.md +265 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-17.md +279 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-18.md +293 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-19.md +307 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-2.md +29 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-20.md +317 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-21.md +327 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-3.md +40 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-4.md +59 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-5.md +69 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-6.md +79 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-7.md +89 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-8.md +102 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-9.md +116 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation.jsonl +49 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/doc.md +87 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/harness.py +289 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/local/harness copy 2.py +221 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/local/harness copy 3.py +287 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/local/harness copy.py +165 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/state.json +22 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/system-prompt.md +2 -0
- package/src/native-harness/AGENTS.md +70 -0
- package/src/native-harness/ARCHITECTURE.md +249 -0
- package/src/native-harness/README.md +726 -0
- package/src/native-harness/bun.lock +26 -0
- package/src/native-harness/package.json +24 -0
- package/src/native-harness/src/capabilities/context/build.ts +59 -0
- package/src/native-harness/src/capabilities/context/instructions/agent-demo.md +11 -0
- package/src/native-harness/src/capabilities/context/instructions/agent.md +5 -0
- package/src/native-harness/src/capabilities/context/instructions/harness.md +7 -0
- package/src/native-harness/src/capabilities/context/load-instructions.ts +22 -0
- package/src/native-harness/src/capabilities/context/session.ts +92 -0
- package/src/native-harness/src/capabilities/model/attempt.ts +27 -0
- package/src/native-harness/src/capabilities/model/openrouter-stream.ts +72 -0
- package/src/native-harness/src/capabilities/model/openrouter.ts +62 -0
- package/src/native-harness/src/capabilities/model/runner.ts +116 -0
- package/src/native-harness/src/capabilities/model/scenario-attempt.ts +50 -0
- package/src/native-harness/src/capabilities/model/scenario-file.ts +125 -0
- package/src/native-harness/src/capabilities/model/scripted-error.ts +6 -0
- package/src/native-harness/src/capabilities/model/scripted.ts +81 -0
- package/src/native-harness/src/capabilities/model/usage.ts +15 -0
- package/src/native-harness/src/capabilities/tools/builtin/current-time.ts +28 -0
- package/src/native-harness/src/capabilities/tools/builtin/notify-channel.ts +17 -0
- package/src/native-harness/src/capabilities/tools/debug/index.ts +13 -0
- package/src/native-harness/src/capabilities/tools/debug/result.ts +12 -0
- package/src/native-harness/src/capabilities/tools/debug/test-echo.ts +16 -0
- package/src/native-harness/src/capabilities/tools/debug/test-fail.ts +14 -0
- package/src/native-harness/src/capabilities/tools/debug/test-wait.ts +19 -0
- package/src/native-harness/src/capabilities/tools/reminders/index.ts +75 -0
- package/src/native-harness/src/capabilities/tools/runtime/catalog.ts +103 -0
- package/src/native-harness/src/capabilities/tools/runtime/functions.ts +130 -0
- package/src/native-harness/src/capabilities/tools/runtime/invocations.ts +48 -0
- package/src/native-harness/src/capabilities/tools/testing/echo.ts +18 -0
- package/src/native-harness/src/capabilities/tools/testing/record.ts +47 -0
- package/src/native-harness/src/capabilities/tools/timeline/index.ts +41 -0
- package/src/native-harness/src/client.ts +18 -0
- package/src/native-harness/src/contracts/agent.ts +105 -0
- package/src/native-harness/src/contracts/config-permissions.ts +47 -0
- package/src/native-harness/src/contracts/context.ts +112 -0
- package/src/native-harness/src/contracts/events.ts +47 -0
- package/src/native-harness/src/contracts/input-limits.ts +7 -0
- package/src/native-harness/src/contracts/inspection.ts +22 -0
- package/src/native-harness/src/contracts/loop.ts +31 -0
- package/src/native-harness/src/contracts/model-execution.ts +83 -0
- package/src/native-harness/src/contracts/operator-controls.ts +106 -0
- package/src/native-harness/src/contracts/output.ts +13 -0
- package/src/native-harness/src/contracts/protocol.ts +320 -0
- package/src/native-harness/src/contracts/reminders.ts +132 -0
- package/src/native-harness/src/contracts/scenario.ts +42 -0
- package/src/native-harness/src/contracts/session-file.ts +19 -0
- package/src/native-harness/src/contracts/session.ts +184 -0
- package/src/native-harness/src/contracts/storage.ts +596 -0
- package/src/native-harness/src/contracts/timeline-retrieval.ts +40 -0
- package/src/native-harness/src/contracts/tools.ts +133 -0
- package/src/native-harness/src/governance/permissions/gate.ts +129 -0
- package/src/native-harness/src/governance/policy/resolve.ts +32 -0
- package/src/native-harness/src/index.ts +318 -0
- package/src/native-harness/src/interfaces/cli/chat.ts +83 -0
- package/src/native-harness/src/interfaces/cli/development.ts +145 -0
- package/src/native-harness/src/interfaces/cli/format-reply.ts +27 -0
- package/src/native-harness/src/interfaces/cli/listeners.ts +74 -0
- package/src/native-harness/src/interfaces/cli/main.ts +47 -0
- package/src/native-harness/src/interfaces/cli/scenario.ts +37 -0
- package/src/native-harness/src/interfaces/cli/serve.ts +21 -0
- package/src/native-harness/src/interfaces/cli/start.ts +106 -0
- package/src/native-harness/src/interfaces/client.ts +225 -0
- package/src/native-harness/src/interfaces/inspector/index.html +283 -0
- package/src/native-harness/src/interfaces/inspector/observe.ts +35 -0
- package/src/native-harness/src/interfaces/inspector/server.ts +56 -0
- package/src/native-harness/src/interfaces/inspector/state.ts +92 -0
- package/src/native-harness/src/interfaces/protocol/channel-changes.ts +153 -0
- package/src/native-harness/src/interfaces/protocol/framing.ts +47 -0
- package/src/native-harness/src/interfaces/protocol/functions.ts +87 -0
- package/src/native-harness/src/interfaces/protocol/in-process.ts +67 -0
- package/src/native-harness/src/interfaces/protocol/live-queue.ts +55 -0
- package/src/native-harness/src/interfaces/protocol/load.ts +60 -0
- package/src/native-harness/src/interfaces/protocol/local.ts +120 -0
- package/src/native-harness/src/interfaces/protocol/operator.ts +120 -0
- package/src/native-harness/src/interfaces/protocol/output.ts +59 -0
- package/src/native-harness/src/interfaces/protocol/server.ts +517 -0
- package/src/native-harness/src/interfaces/protocol/stdio-client.ts +119 -0
- package/src/native-harness/src/interfaces/protocol/stdio-server.ts +82 -0
- package/src/native-harness/src/interfaces/protocol/subscribe.ts +41 -0
- package/src/native-harness/src/interfaces/protocol/transfers.ts +146 -0
- package/src/native-harness/src/interfaces/web-chat/index.html +94 -0
- package/src/native-harness/src/interfaces/web-chat/server.ts +34 -0
- package/src/native-harness/src/kernel/channels.ts +405 -0
- package/src/native-harness/src/kernel/loop.ts +45 -0
- package/src/native-harness/src/runtime/config/development.ts +23 -0
- package/src/native-harness/src/runtime/config/managed.ts +2 -0
- package/src/native-harness/src/runtime/config/paths.ts +27 -0
- package/src/native-harness/src/runtime/reminder-timer.ts +42 -0
- package/src/native-harness/src/runtime/reminder-validation.ts +104 -0
- package/src/native-harness/src/runtime/reminders.ts +66 -0
- package/src/native-harness/src/state/storage/archive.ts +239 -0
- package/src/native-harness/src/state/storage/engine.ts +1013 -0
- package/src/native-harness/src/state/storage/inference.ts +124 -0
- package/src/native-harness/src/state/storage/memory-reminders.ts +78 -0
- package/src/native-harness/src/state/storage/memory.ts +341 -0
- package/src/native-harness/src/state/storage/policy-metadata.ts +32 -0
- package/src/native-harness/src/state/storage/reminder-archive.ts +63 -0
- package/src/native-harness/src/state/storage/reminder-change.ts +92 -0
- package/src/native-harness/src/state/storage/reminder-tables.ts +27 -0
- package/src/native-harness/src/state/storage/retrieval.ts +122 -0
- package/src/native-harness/src/state/storage/script-identity.ts +7 -0
- package/src/native-harness/src/state/storage/session-file.ts +85 -0
- package/src/native-harness/src/state/storage/sqlite-reminders.ts +134 -0
- package/src/native-harness/src/state/storage/sqlite.ts +625 -0
- package/src/native-harness/src/testing.ts +190 -0
- package/src/native-harness/src/util/config.ts +58 -0
- package/src/native-harness/src/util/json.ts +41 -0
- package/src/native-harness/src/util/message-position.ts +3 -0
- package/src/native-harness/src/util/reminder-schedule.ts +44 -0
- package/src/native-harness/src/util/schema.ts +40 -0
- package/src/native-harness/src/util/timeline-text.ts +72 -0
- package/src/native-harness/src/util/timeline-tool-names.ts +3 -0
- package/src/native-harness/test/agent.test.ts +130 -0
- package/src/native-harness/test/approval-gate.test.ts +255 -0
- package/src/native-harness/test/approval-protocol.test.ts +94 -0
- package/src/native-harness/test/boundaries.test.ts +18 -0
- package/src/native-harness/test/channel-controls.test.ts +322 -0
- package/src/native-harness/test/client-abort.test.ts +136 -0
- package/src/native-harness/test/config-policy.test.ts +301 -0
- package/src/native-harness/test/conformance/storage.ts +1141 -0
- package/src/native-harness/test/context.test.ts +177 -0
- package/src/native-harness/test/crash.test.ts +187 -0
- package/src/native-harness/test/debug-tools.test.ts +67 -0
- package/src/native-harness/test/development-cli.test.ts +67 -0
- package/src/native-harness/test/development.test.ts +171 -0
- package/src/native-harness/test/dispatch-evidence.test.ts +58 -0
- package/src/native-harness/test/e2e.test.ts +186 -0
- package/src/native-harness/test/external-notices.test.ts +101 -0
- package/src/native-harness/test/fixtures/approval-e2e.jsonl +4 -0
- package/src/native-harness/test/fixtures/crash-scenario.jsonl +5 -0
- package/src/native-harness/test/fixtures/development-lifecycle.jsonl +10 -0
- package/src/native-harness/test/fixtures/echo-scenario.jsonl +3 -0
- package/src/native-harness/test/fixtures/format2-schema.ts +27 -0
- package/src/native-harness/test/fixtures/format3-schema.ts +16 -0
- package/src/native-harness/test/fixtures/hold-scenario.jsonl +4 -0
- package/src/native-harness/test/fixtures/model-e2e.jsonl +3 -0
- package/src/native-harness/test/fixtures/storage-owner.ts +20 -0
- package/src/native-harness/test/format-reply.test.ts +10 -0
- package/src/native-harness/test/helpers/operator-view.ts +41 -0
- package/src/native-harness/test/helpers/scenario.ts +9 -0
- package/src/native-harness/test/helpers/session.ts +38 -0
- package/src/native-harness/test/helpers/stdio.ts +46 -0
- package/src/native-harness/test/inspector.test.ts +77 -0
- package/src/native-harness/test/listeners.test.ts +49 -0
- package/src/native-harness/test/loop.test.ts +88 -0
- package/src/native-harness/test/model-channel-double.test.ts +87 -0
- package/src/native-harness/test/model-crash.test.ts +62 -0
- package/src/native-harness/test/model-delivery-regressions.test.ts +55 -0
- package/src/native-harness/test/model-e2e.test.ts +71 -0
- package/src/native-harness/test/model-final-filter.test.ts +30 -0
- package/src/native-harness/test/model-large-reply.test.ts +28 -0
- package/src/native-harness/test/model-live-queue.test.ts +33 -0
- package/src/native-harness/test/model-runner.test.ts +117 -0
- package/src/native-harness/test/model-storage.test.ts +99 -0
- package/src/native-harness/test/model-stream-adapter.test.ts +26 -0
- package/src/native-harness/test/model-stream-public.test.ts +77 -0
- package/src/native-harness/test/notices.test.ts +64 -0
- package/src/native-harness/test/openrouter-config.test.ts +218 -0
- package/src/native-harness/test/operator-controls.test.ts +132 -0
- package/src/native-harness/test/output.test.ts +44 -0
- package/src/native-harness/test/owner-config.test.ts +64 -0
- package/src/native-harness/test/permissions-e2e.test.ts +68 -0
- package/src/native-harness/test/persistence.test.ts +236 -0
- package/src/native-harness/test/portability.test.ts +337 -0
- package/src/native-harness/test/protocol.test.ts +160 -0
- package/src/native-harness/test/reminder-clock.test.ts +61 -0
- package/src/native-harness/test/reminder-stdio.test.ts +140 -0
- package/src/native-harness/test/reminder-storage.test.ts +124 -0
- package/src/native-harness/test/scenario-jsonl.test.ts +112 -0
- package/src/native-harness/test/scripted.test.ts +92 -0
- package/src/native-harness/test/session-file.test.ts +51 -0
- package/src/native-harness/test/startup-channel-changes.test.ts +256 -0
- package/src/native-harness/test/stdio.test.ts +132 -0
- package/src/native-harness/test/storage-memory.test.ts +4 -0
- package/src/native-harness/test/storage-sqlite.test.ts +420 -0
- package/src/native-harness/test/suspension.test.ts +430 -0
- package/src/native-harness/test/timeline-retrieval.test.ts +211 -0
- package/src/native-harness/test/tools-catalog.test.ts +468 -0
- package/src/native-harness/test/tools-protocol.test.ts +418 -0
- package/src/native-harness/test/transfers.test.ts +94 -0
- package/src/native-harness/test/web-chat.test.ts +35 -0
- package/src/native-harness/tsconfig.json +20 -0
- package/src/observation/agent-event-bus.ts +44 -18
- package/src/observation/index.ts +1 -0
- package/src/operations/contracts.ts +11 -3
- package/src/operations/errors.ts +5 -0
- package/src/operations/stale-policy.ts +1 -1
- package/src/operations/supervisor.ts +34 -10
- package/src/orchestrator/acp-delivery.ts +68 -0
- package/src/orchestrator/assignments.ts +27 -0
- package/src/orchestrator/busy.ts +15 -0
- package/src/orchestrator/config.ts +41 -0
- package/src/orchestrator/consumer-api.ts +24 -0
- package/src/orchestrator/contracts.ts +71 -0
- package/src/orchestrator/durable-assignments.ts +111 -0
- package/src/orchestrator/native-delegation.ts +103 -0
- package/src/orchestrator/orchestrator.ts +318 -0
- package/src/orchestrator/permissions.ts +25 -0
- package/src/orchestrator/policy.ts +44 -0
- package/src/orchestrator/pool.ts +123 -0
- package/src/orchestrator/tool-descriptions.ts +11 -0
- package/src/permissions/acp.ts +18 -0
- package/src/permissions/arrival.ts +13 -0
- package/src/permissions/consumer-config.ts +19 -0
- package/src/permissions/conversation.ts +280 -0
- package/src/permissions/matcher.ts +85 -0
- package/src/permissions/outcome.ts +15 -0
- package/src/permissions/policy.ts +81 -0
- package/src/permissions/request.ts +26 -0
- package/src/persistence/activity-projection.ts +1 -0
- package/src/persistence/backend.ts +34 -1
- package/src/persistence/channels.ts +23 -0
- package/src/persistence/index.ts +4 -0
- package/src/persistence/protocol-method.ts +5 -0
- package/src/persistence/reminder-wake.ts +49 -0
- package/src/persistence/reminders.ts +385 -0
- package/src/persistence/sqlite-backend.ts +84 -6
- package/src/persistence/sqlite-channels.ts +65 -0
- package/src/persistence/sqlite-reminders.ts +85 -0
- package/src/persistence/sqlite-schema.ts +108 -3
- package/src/persistence/sqlite-worker-delivery.ts +374 -0
- package/src/persistence/sqlite-workers.ts +59 -0
- package/src/persistence/worker-delivery-contract.ts +104 -0
- package/src/persistence/worker-terminal-reason.ts +29 -0
- package/src/persistence/workers.ts +19 -0
- package/src/provider-notices.ts +137 -0
- package/src/repl/commands.ts +2 -2
- package/src/steering/combine.ts +3 -1
- package/src/steering/contracts.ts +11 -2
- package/src/steering/controller.ts +3 -2
- package/src/transport/acp-transport.ts +24 -14
- package/src/types.ts +15 -12
- package/src/updates.ts +14 -2
- package/src/wire-log.ts +1 -1
|
@@ -0,0 +1,468 @@
|
|
|
1
|
+
import { expect, test } from "bun:test";
|
|
2
|
+
import { createSession } from "../src/index.ts";
|
|
3
|
+
import { createMemoryStorageAdapter } from "../src/state/storage/memory.ts";
|
|
4
|
+
import { CatalogError, parseCatalog, sameCatalog } from "../src/capabilities/tools/runtime/catalog.ts";
|
|
5
|
+
import { CallbackFailure, CallbackLost } from "../src/capabilities/tools/runtime/functions.ts";
|
|
6
|
+
import { bindModelAttempt } from "../src/capabilities/model/attempt.ts";
|
|
7
|
+
import { schemaProblem } from "../src/util/schema.ts";
|
|
8
|
+
import type { ManagedConfig } from "../src/contracts/config-permissions.ts";
|
|
9
|
+
import type { ChannelEvent } from "../src/contracts/events.ts";
|
|
10
|
+
import type { Message, Model, ToolDefinition } from "../src/contracts/loop.ts";
|
|
11
|
+
import type { FunctionCall, FunctionResult, ResultRead, ToolCatalogInput, ToolRegistration } from "../src/contracts/tools.ts";
|
|
12
|
+
import { lastInput } from "./helpers/session.ts";
|
|
13
|
+
|
|
14
|
+
// Decision 0021 at the session: the catalog, the offered list, the dispatch
|
|
15
|
+
// gate and invocation records, with a controllable executor in place of the
|
|
16
|
+
// callback transport.
|
|
17
|
+
function deferred<T = void>() { let resolve!: (value: T) => void, reject!: (error: unknown) => void; const promise = new Promise<T>((res, rej) => { resolve = res; reject = rej; }); return { promise, resolve, reject }; }
|
|
18
|
+
async function until(check: () => boolean, label: string) { for (let i = 0; i < 400; i++) { if (check()) return; await new Promise(r => setTimeout(r, 5)); } throw new Error(`Timed out: ${label}`); }
|
|
19
|
+
const tool = (name: string, group: ToolRegistration["group"], extra: Partial<ToolRegistration> = {}): ToolRegistration => ({ name, group, handler: `${name}_handler`,
|
|
20
|
+
description: `Test tool ${name}`, parameters: { type: "object", properties: { q: { type: "string" } }, required: ["q"], additionalProperties: false }, ...extra });
|
|
21
|
+
const builtin: ToolDefinition = { name: "echo", description: "Built-in echo", parameters: { type: "object" } };
|
|
22
|
+
|
|
23
|
+
/** The scripted model calls the tool named by the newest input (`call <tool> <json>`),
|
|
24
|
+
* and answers `done` after a tool result or for any other input. */
|
|
25
|
+
function rig(options: { catalog?: ToolCatalogInput; policies?: ManagedConfig["policies"]; defaultPolicy?: string; beforeDispatch?: () => Promise<void>; limits?: { inlineBytes?: number } } = {}) {
|
|
26
|
+
const config: ManagedConfig = { version: 1, system: "test", model: { protocol: "scripted", script: "fixture" }, defaultPolicy: options.defaultPolicy ?? "open",
|
|
27
|
+
policies: options.policies ?? { open: { fallback: "allow", tools: {} } } };
|
|
28
|
+
const catalog = options.catalog ?? { catalog: [tool("lookup", "fixed"), tool("send", "revocable"), tool("extra", "runtime")] };
|
|
29
|
+
const adapter = createMemoryStorageAdapter();
|
|
30
|
+
let created = false;
|
|
31
|
+
const open = () => {
|
|
32
|
+
const opened = adapter.open({ mode: created ? "open" : "create", identity: { sessionId: "s", compatibilityKey: "k" }, config });
|
|
33
|
+
if (!opened.ok) throw new Error(opened.error.message);
|
|
34
|
+
created = true;
|
|
35
|
+
const storage = opened.value, events: ChannelEvent[] = [];
|
|
36
|
+
/** Every inference request: the tools offered and the messages sent. */
|
|
37
|
+
const requests: { channel: string; tools: string[]; messages: Message[] }[] = [];
|
|
38
|
+
/** Callbacks the executor received, each waiting for the test to answer. */
|
|
39
|
+
const calls: { request: FunctionCall; signal: AbortSignal; answer: ReturnType<typeof deferred<FunctionResult>> }[] = [];
|
|
40
|
+
const reads: ResultRead[] = [];
|
|
41
|
+
const stored = new Map<string, string>();
|
|
42
|
+
const session = createSession({ systemPrompt: "test", storage, config, catalog, beforeToolDispatch: options.beforeDispatch, toolLimits: options.limits,
|
|
43
|
+
configureTurn(turn) {
|
|
44
|
+
let n = 0;
|
|
45
|
+
const model: Model = async (messages, tools) => {
|
|
46
|
+
requests.push({ channel: turn.channelId, tools: tools.map(value => value.name), messages: [...messages] });
|
|
47
|
+
const last = messages.at(-1)!, text = lastInput(messages);
|
|
48
|
+
if (last.role === "tool" && !text.startsWith("then ")) return { role: "assistant", content: "done", calls: [] };
|
|
49
|
+
const match = /^(?:then )?call (\S+) (.*)$/.exec(text);
|
|
50
|
+
// "then call X": a second call after the first result, to show what the next inference sees.
|
|
51
|
+
if (last.role === "tool" && messages.filter(message => message.role === "tool").length > 1) return { role: "assistant", content: "done", calls: [] };
|
|
52
|
+
if (!match) return { role: "assistant", content: `said ${text}`, calls: [] };
|
|
53
|
+
return { role: "assistant", content: null, calls: [{ id: `c${turn.turnId}-${++n}`, name: match[1]!, arguments: match[2]! }] };
|
|
54
|
+
};
|
|
55
|
+
return { tools: [builtin], model, executeTool: async () => JSON.stringify({ echoed: true }) };
|
|
56
|
+
} });
|
|
57
|
+
session.subscribe(event => events.push(event));
|
|
58
|
+
session.approvals.setConsumer(true);
|
|
59
|
+
const executor = {
|
|
60
|
+
call(request: FunctionCall, signal: AbortSignal) { const answer = deferred<FunctionResult>(); calls.push({ request, signal, answer }); return answer.promise; },
|
|
61
|
+
async read(request: ResultRead) {
|
|
62
|
+
reads.push(request);
|
|
63
|
+
const text = stored.get(request.resultId);
|
|
64
|
+
if (text === undefined) throw new CallbackFailure("result_expired", "gone");
|
|
65
|
+
const part = text.slice(request.offset, request.offset + request.length);
|
|
66
|
+
return { text: part, eof: request.offset + part.length >= text.length, totalBytes: text.length };
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
session.tools!.serve(catalog.catalog.map(entry => entry.handler), executor);
|
|
70
|
+
session.start();
|
|
71
|
+
const send = (channel: string, text: string, policy?: string) => session.agent.send({ channelId: channel, participantId: "u", text, ...(policy ? { policy } : {}) });
|
|
72
|
+
const ended = (channel: string, count = 1) => events.filter(e => e.channel === channel && e.event.type === "turn_ended").length >= count;
|
|
73
|
+
const results = () => session.snapshot().timeline.flatMap(e => e.message.role === "tool" ? [{ ...JSON.parse(e.message.content), outcome: e.message.outcome }] : []);
|
|
74
|
+
const toolEvents = () => events.flatMap(e => e.event.type === "tool_call" ? [`${e.event.status}:${e.event.invocationId}`] : []);
|
|
75
|
+
return { session, storage, events, requests, calls, reads, stored, executor, send, ended, results, toolEvents,
|
|
76
|
+
approval: () => events.findLast(e => e.event.type === "approval_requested")?.event as Extract<ChannelEvent["event"], { type: "approval_requested" }> | undefined,
|
|
77
|
+
close() { session.stop("test"); storage.close(); } };
|
|
78
|
+
};
|
|
79
|
+
return { open, adapter };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
test("catalog validation rejects the whole input: duplicates, built-in conflicts, bad groups, deadlines and enabled names", () => {
|
|
83
|
+
const good = { catalog: [tool("a", "fixed"), tool("b", "runtime", { deadlineMs: 50 })], enabled: ["b"], defaultDeadlineMs: 1000 };
|
|
84
|
+
expect(parseCatalog(good, ["echo"])).toEqual(good);
|
|
85
|
+
const bad: unknown[] = [
|
|
86
|
+
{ catalog: [tool("a", "fixed"), tool("a", "runtime")] },
|
|
87
|
+
{ catalog: [tool("echo", "fixed")] },
|
|
88
|
+
{ catalog: [tool("read_tool_result", "fixed")] },
|
|
89
|
+
{ catalog: [{ ...tool("a", "fixed"), group: "sometimes" }] },
|
|
90
|
+
{ catalog: [{ ...tool("a", "fixed"), handler: " " }] },
|
|
91
|
+
{ catalog: [{ ...tool("a", "fixed"), parameters: [] }] },
|
|
92
|
+
{ catalog: [{ ...tool("a", "fixed"), extra: 1 }] },
|
|
93
|
+
{ catalog: [tool("a", "fixed", { deadlineMs: 0 })] },
|
|
94
|
+
{ catalog: [tool("a", "fixed")], enabled: ["a"] },
|
|
95
|
+
{ catalog: [tool("a", "runtime")], enabled: ["a", "a"] },
|
|
96
|
+
{ catalog: [tool("a", "fixed")], defaultDeadlineMs: -1 },
|
|
97
|
+
{ catalog: "a" }, [], { catalog: [], other: true },
|
|
98
|
+
];
|
|
99
|
+
for (const input of bad) expect(() => parseCatalog(input, ["echo"])).toThrow(CatalogError);
|
|
100
|
+
expect(sameCatalog(good, structuredClone(good))).toBe(true);
|
|
101
|
+
expect(sameCatalog(good, { ...good, enabled: [] })).toBe(false);
|
|
102
|
+
expect(sameCatalog(good, { ...good, catalog: [good.catalog[0]!, { ...good.catalog[1]!, description: "changed" }] })).toBe(false);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test("argument schemas: required fields, types, unknown fields, enums, nested items and bounds", () => {
|
|
106
|
+
const schema = { type: "object", required: ["q"], additionalProperties: false, properties: { q: { type: "string", minLength: 2 },
|
|
107
|
+
n: { type: "integer", minimum: 1, maximum: 5 }, mode: { enum: ["a", "b"] }, tags: { type: "array", items: { type: "string" } } } };
|
|
108
|
+
expect(schemaProblem(schema, { q: "ok", n: 3, mode: "a", tags: ["x"] })).toBeUndefined();
|
|
109
|
+
expect(schemaProblem(schema, {})).toBe("arguments.q is required");
|
|
110
|
+
expect(schemaProblem(schema, { q: 1 })).toBe("arguments.q must be string");
|
|
111
|
+
expect(schemaProblem(schema, { q: "ok", extra: 1 })).toBe("arguments.extra is not an accepted field");
|
|
112
|
+
expect(schemaProblem(schema, { q: "ok", n: 9 })).toBe("arguments.n must be at most 5");
|
|
113
|
+
expect(schemaProblem(schema, { q: "ok", n: 1.5 })).toBe("arguments.n must be integer");
|
|
114
|
+
expect(schemaProblem(schema, { q: "ok", mode: "c" })).toContain("must be one of");
|
|
115
|
+
expect(schemaProblem(schema, { q: "ok", tags: ["x", 2] })).toBe("arguments.tags[1] must be string");
|
|
116
|
+
expect(schemaProblem(schema, { q: "o" })).toContain("at least 2 characters");
|
|
117
|
+
expect(schemaProblem({ unknownKeyword: true }, { anything: 1 })).toBeUndefined();
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
test("fixed entries cannot be removed or revoked; revocations are durable; runtime entries are enabled and removed in memory", async () => {
|
|
121
|
+
const r = rig({ catalog: { catalog: [tool("lookup", "fixed"), tool("send", "revocable"), tool("extra", "runtime"), tool("spare", "runtime")], enabled: ["extra"] } });
|
|
122
|
+
const first = r.open(), tools = first.session.tools!;
|
|
123
|
+
const names = (session: typeof first.session) => Object.fromEntries(session.tools!.list().map(entry => [entry.name, entry.available ? "available" : entry.reason]));
|
|
124
|
+
expect(names(first.session)).toEqual({ lookup: "available", send: "available", extra: "available", spare: "not_enabled", read_tool_result: "available" });
|
|
125
|
+
for (const act of [tools.revoke, tools.restore, tools.enable, tools.remove]) expect(act("lookup")).toMatchObject({ ok: false, error: { code: "invalid_state" } });
|
|
126
|
+
expect(tools.revoke("nope")).toMatchObject({ ok: false, error: { code: "not_found" } });
|
|
127
|
+
expect(tools.enable("send")).toMatchObject({ ok: false, error: { code: "invalid_state" } });
|
|
128
|
+
expect(tools.revoke("extra")).toMatchObject({ ok: false, error: { code: "invalid_state" } });
|
|
129
|
+
expect(names(first.session)).toMatchObject({ lookup: "available" });
|
|
130
|
+
|
|
131
|
+
expect(tools.revoke("send")).toMatchObject({ ok: true, value: { name: "send", group: "revocable", available: false, reason: "revoked" } });
|
|
132
|
+
expect(tools.remove("extra")).toMatchObject({ ok: true, value: { available: false, reason: "not_enabled" } });
|
|
133
|
+
expect(tools.enable("spare")).toMatchObject({ ok: true, value: { available: true } });
|
|
134
|
+
expect(first.session.snapshot().revokedTools).toEqual(["send"]);
|
|
135
|
+
first.close();
|
|
136
|
+
|
|
137
|
+
// Reopen: the revocation is stored with the session; the runtime selection is supplied again by the consumer.
|
|
138
|
+
const second = r.open();
|
|
139
|
+
expect(names(second.session)).toEqual({ lookup: "available", send: "revoked", extra: "available", spare: "not_enabled", read_tool_result: "available" });
|
|
140
|
+
expect(second.session.tools!.restore("send")).toMatchObject({ ok: true, value: { available: true } });
|
|
141
|
+
expect(second.session.snapshot().revokedTools).toEqual([]);
|
|
142
|
+
// A handler the connection does not serve makes its tool unavailable, whatever its group.
|
|
143
|
+
second.session.tools!.serve(["send_handler"], second.executor);
|
|
144
|
+
expect(names(second.session)).toMatchObject({ lookup: "handler_missing", send: "available", extra: "handler_missing" });
|
|
145
|
+
second.close();
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
test("each inference offers built-ins, then fixed entries, then changeable ones, omitting denied and unavailable tools; changes apply to the next inference", async () => {
|
|
149
|
+
const r = rig({ catalog: { catalog: [tool("zeta", "fixed"), tool("alpha", "fixed"), tool("send", "revocable"), tool("extra", "runtime"), tool("banned", "fixed")], enabled: ["extra"] },
|
|
150
|
+
policies: { open: { fallback: "allow", tools: { banned: "deny" } }, strict: { fallback: "deny", tools: { alpha: "allow" } } } });
|
|
151
|
+
const s = r.open();
|
|
152
|
+
try {
|
|
153
|
+
s.send("a", "hello"); await until(() => s.ended("a"), "first turn");
|
|
154
|
+
expect(s.requests[0]!.tools).toEqual(["echo", "notify_channel", "schedule_reminder", "list_reminders", "cancel_reminder", "alpha", "zeta", "read_tool_result", "extra", "send"]);
|
|
155
|
+
s.session.tools!.revoke("send"); s.session.tools!.remove("extra");
|
|
156
|
+
s.send("a", "again"); await until(() => s.ended("a", 2), "second turn");
|
|
157
|
+
expect(s.requests[1]!.tools).toEqual(["echo", "notify_channel", "schedule_reminder", "list_reminders", "cancel_reminder", "alpha", "zeta", "read_tool_result"]);
|
|
158
|
+
// A turn whose input carries a stricter policy sees only what that policy does not deny.
|
|
159
|
+
s.send("b", "hello", "strict"); await until(() => s.ended("b"), "strict turn");
|
|
160
|
+
expect(s.requests[2]!.tools).toEqual(["alpha"]);
|
|
161
|
+
} finally { s.close(); }
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
test("a retry of one model call offers the list frozen for that call, even if a tool was revoked in between", async () => {
|
|
165
|
+
const catalog = { catalog: [tool("send", "revocable")] };
|
|
166
|
+
const config: ManagedConfig = { version: 1, system: "test", model: { protocol: "scripted", script: "fixture" }, defaultPolicy: "open", policies: { open: { fallback: "allow", tools: {} } } };
|
|
167
|
+
const opened = createMemoryStorageAdapter().open({ mode: "create", identity: { sessionId: "s", compatibilityKey: "k" }, config });
|
|
168
|
+
if (!opened.ok) throw new Error(opened.error.message);
|
|
169
|
+
const offered: string[][] = [], events: ChannelEvent[] = [];
|
|
170
|
+
let attempts = 0, revoke = () => {};
|
|
171
|
+
const model: Model = async () => ({ role: "assistant", content: "unused", calls: [] });
|
|
172
|
+
bindModelAttempt(model, { scripted: false, settings: { retryDelayMs: 5 }, create: () => async function* (request) {
|
|
173
|
+
offered.push(request.tools.map(value => value.name));
|
|
174
|
+
if (++attempts === 1) { revoke(); yield { type: "failure", kind: "transient", message: "try again" }; return; }
|
|
175
|
+
yield { type: "response", response: { role: "assistant", content: "ok", calls: [], stopReason: "complete" } };
|
|
176
|
+
} });
|
|
177
|
+
const session = createSession({ systemPrompt: "test", storage: opened.value, config, catalog, configureTurn: () => ({ tools: [], model, executeTool: async () => "" }) });
|
|
178
|
+
session.subscribe(event => events.push(event));
|
|
179
|
+
session.tools!.serve(["send_handler"]);
|
|
180
|
+
revoke = () => { session.tools!.revoke("send"); };
|
|
181
|
+
session.start();
|
|
182
|
+
try {
|
|
183
|
+
session.agent.send({ channelId: "a", participantId: "u", text: "one" });
|
|
184
|
+
await until(() => events.some(e => e.event.type === "turn_ended"), "turn");
|
|
185
|
+
expect(offered).toEqual([["notify_channel", "schedule_reminder", "list_reminders", "cancel_reminder", "read_tool_result", "send"], ["notify_channel", "schedule_reminder", "list_reminders", "cancel_reminder", "read_tool_result", "send"]]);
|
|
186
|
+
session.agent.send({ channelId: "a", participantId: "u", text: "two" });
|
|
187
|
+
await until(() => events.filter(e => e.event.type === "turn_ended").length === 2, "second turn");
|
|
188
|
+
expect(offered[2]).toEqual(["notify_channel", "schedule_reminder", "list_reminders", "cancel_reminder", "read_tool_result"]);
|
|
189
|
+
} finally { session.stop("test"); opened.value.close(); }
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
test("a consumer call runs once through the gate: validated arguments, invocation identity, a committed result that reaches the next inference", async () => {
|
|
193
|
+
const r = rig(); const s = r.open();
|
|
194
|
+
try {
|
|
195
|
+
s.send("a", 'call lookup {"q":"weather"}');
|
|
196
|
+
await until(() => s.calls.length === 1, "the callback");
|
|
197
|
+
const { request } = s.calls[0]!;
|
|
198
|
+
expect(request).toEqual({ invocationId: "1:c1-1", sessionId: "s", channel: "a", turnId: "1", tool: "lookup", handler: "lookup_handler", policyNames: ["open"], arguments: { q: "weather" } });
|
|
199
|
+
expect(s.session.tools!.invocation("1:c1-1")).toMatchObject({ state: "started", tool: "lookup", toolCallId: "c1-1", channel: "a", arguments: '{"q":"weather"}' });
|
|
200
|
+
// The status shows what the turn is doing and which call it concerns.
|
|
201
|
+
expect(s.session.status().channels[0]!.activeTurn).toMatchObject({ turnId: 1, status: "running", phase: { kind: "tool", id: "1:c1-1" } });
|
|
202
|
+
// Another channel completes while this callback is outstanding.
|
|
203
|
+
s.send("b", "hello"); await until(() => s.ended("b"), "bob");
|
|
204
|
+
expect(s.ended("a")).toBe(false);
|
|
205
|
+
s.calls[0]!.answer.resolve({ output: { temperature: 21 } });
|
|
206
|
+
await until(() => s.ended("a"), "alice");
|
|
207
|
+
expect(s.calls).toHaveLength(1);
|
|
208
|
+
expect(s.results()).toEqual([{ ok: true, output: { temperature: 21 }, outcome: { status: "succeeded" } }]);
|
|
209
|
+
expect(s.session.tools!.invocation("1:c1-1")).toMatchObject({ state: "succeeded" });
|
|
210
|
+
expect(s.session.tools!.invocations(1).map(record => record.invocationId)).toEqual(["1:c1-1"]);
|
|
211
|
+
expect(s.toolEvents()).toEqual(["started:1:c1-1", "completed:1:c1-1"]);
|
|
212
|
+
const next = s.requests.filter(request => request.channel === "a")[1]!.messages.at(-1)!;
|
|
213
|
+
expect(next).toMatchObject({ role: "tool", callId: "c1-1" });
|
|
214
|
+
expect(JSON.parse((next as { content: string }).content)).toEqual({ ok: true, output: { temperature: 21 } });
|
|
215
|
+
expect(s.session.status().channels.find(channel => channel.channelId === "a")!.activeTurn).toBeUndefined();
|
|
216
|
+
expect(s.session.tools!.invocation("9:nope")).toBeUndefined();
|
|
217
|
+
expect(s.session.tools!.invocation("not-an-id")).toBeUndefined();
|
|
218
|
+
} finally { s.close(); }
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
test("invalid arguments, an unoffered tool and an unavailable tool are skipped with a reason and no callback; a built-in keeps its own path", async () => {
|
|
222
|
+
const r = rig({ catalog: { catalog: [tool("lookup", "fixed"), tool("extra", "runtime")] } }); const s = r.open();
|
|
223
|
+
try {
|
|
224
|
+
s.send("a", 'call lookup {"q":1}'); await until(() => s.ended("a"), "invalid arguments");
|
|
225
|
+
s.send("a", 'call lookup {"q":"ok","other":true}'); await until(() => s.ended("a", 2), "unknown field");
|
|
226
|
+
s.send("a", 'call extra {"q":"x"}'); await until(() => s.ended("a", 3), "not enabled, so not offered");
|
|
227
|
+
s.send("a", 'call echo {"anything":1}'); await until(() => s.ended("a", 4), "built-in");
|
|
228
|
+
expect(s.calls).toEqual([]);
|
|
229
|
+
const results = s.results();
|
|
230
|
+
expect(results.slice(0, 3).map(result => [result.code, result.outcome])).toEqual([
|
|
231
|
+
["invalid_arguments", { status: "skipped", code: "invalid_arguments" }], ["invalid_arguments", { status: "skipped", code: "invalid_arguments" }],
|
|
232
|
+
["tool_unavailable", { status: "skipped", code: "tool_unavailable" }]]);
|
|
233
|
+
expect(results[0]!.message).toContain("arguments.q must be string");
|
|
234
|
+
expect(results[2]!.message).toContain("not offered");
|
|
235
|
+
expect(s.session.tools!.invocations(1)).toMatchObject([{ state: "skipped", code: "invalid_arguments", effect: "none" }]);
|
|
236
|
+
expect(s.toolEvents().filter(event => event.startsWith("skipped"))).toEqual(["skipped:1:c1-1", "skipped:2:c2-1", "skipped:3:c3-1"]);
|
|
237
|
+
expect(s.toolEvents().filter(event => event.startsWith("started"))).toEqual(["started:4:c4-1"]);
|
|
238
|
+
// The model is told the reason in the paired result of the same turn.
|
|
239
|
+
expect(s.requests.filter(request => request.channel === "a")[1]!.messages.at(-1)).toMatchObject({ role: "tool", callId: "c1-1" });
|
|
240
|
+
} finally { s.close(); }
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
test("a tool revoked after it was offered is skipped at dispatch: before approval, while approval is pending, and after an approval was given", async () => {
|
|
244
|
+
// Before dispatch, no approval involved: the barrier holds the call at the boundary.
|
|
245
|
+
const barrier = deferred(), entered = deferred();
|
|
246
|
+
const r = rig({ beforeDispatch: async () => { entered.resolve(); await barrier.promise; } }); const s = r.open();
|
|
247
|
+
try {
|
|
248
|
+
s.send("a", 'call send {"q":"x"}'); await entered.promise;
|
|
249
|
+
expect(s.session.tools!.invocation("1:c1-1")).toMatchObject({ state: "requested" });
|
|
250
|
+
s.session.tools!.revoke("send"); barrier.resolve();
|
|
251
|
+
await until(() => s.ended("a"), "skipped turn");
|
|
252
|
+
expect(s.calls).toEqual([]);
|
|
253
|
+
expect(s.results()[0]).toMatchObject({ code: "tool_unavailable", outcome: { status: "skipped", code: "tool_unavailable" } });
|
|
254
|
+
expect(s.session.tools!.invocation("1:c1-1")).toMatchObject({ state: "skipped", effect: "none" });
|
|
255
|
+
// The next inference no longer offers it.
|
|
256
|
+
expect(s.requests.at(-1)!.tools).not.toContain("send");
|
|
257
|
+
} finally { s.close(); }
|
|
258
|
+
|
|
259
|
+
// While its approval is pending: the request is closed and can no longer authorize anything.
|
|
260
|
+
const asking = rig({ policies: { open: { fallback: "ask", tools: {} } } }); const p = asking.open();
|
|
261
|
+
try {
|
|
262
|
+
p.send("a", 'call send {"q":"x"}'); await until(() => !!p.approval(), "approval request");
|
|
263
|
+
const requestId = p.approval()!.requestId;
|
|
264
|
+
expect(p.session.tools!.invocation("1:c1-1")).toMatchObject({ state: "waiting_for_approval" });
|
|
265
|
+
expect(p.session.status().channels[0]!.activeTurn).toMatchObject({ phase: { kind: "approval", id: requestId } });
|
|
266
|
+
p.session.tools!.revoke("send");
|
|
267
|
+
await until(() => p.ended("a"), "skipped turn");
|
|
268
|
+
expect(p.session.approvals.respond(requestId, "allow_once")).toBe(false);
|
|
269
|
+
expect(p.calls).toEqual([]);
|
|
270
|
+
expect(p.results()[0]).toMatchObject({ code: "tool_unavailable", outcome: { status: "skipped", code: "tool_unavailable" } });
|
|
271
|
+
expect(p.events.filter(e => e.event.type === "tool_call" && e.event.status === "started")).toEqual([]);
|
|
272
|
+
} finally { p.close(); }
|
|
273
|
+
|
|
274
|
+
// After the approval was given but before dispatch: the grant is discarded.
|
|
275
|
+
const hold = deferred(), reached = deferred();
|
|
276
|
+
const granted = rig({ policies: { open: { fallback: "ask", tools: {} } }, beforeDispatch: async () => { reached.resolve(); await hold.promise; } }); const g = granted.open();
|
|
277
|
+
try {
|
|
278
|
+
g.send("a", 'call send {"q":"x"}'); await until(() => !!g.approval(), "approval request");
|
|
279
|
+
expect(g.session.approvals.respond(g.approval()!.requestId, "allow_once")).toBe(true);
|
|
280
|
+
await reached.promise;
|
|
281
|
+
g.session.tools!.revoke("send"); hold.resolve();
|
|
282
|
+
await until(() => g.ended("a"), "skipped turn");
|
|
283
|
+
expect(g.calls).toEqual([]);
|
|
284
|
+
expect(g.results()).toHaveLength(1);
|
|
285
|
+
expect(g.results()[0]).toMatchObject({ code: "tool_unavailable", outcome: { status: "skipped" } });
|
|
286
|
+
} finally { g.close(); }
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
test("deadlines: a tool's own overrides the session default, none means no deadline; a timeout commits one paired result and a late reply changes nothing", async () => {
|
|
290
|
+
const r = rig({ catalog: { catalog: [tool("quick", "fixed", { deadlineMs: 30 }), tool("patient", "fixed", { deadlineMs: 400 }), tool("plain", "fixed")], defaultDeadlineMs: 60 } });
|
|
291
|
+
const s = r.open();
|
|
292
|
+
try {
|
|
293
|
+
// The longer per-tool deadline outlasts both the short one and the session default.
|
|
294
|
+
s.send("p", 'call patient {"q":"x"}'); await until(() => s.calls.length === 1, "patient");
|
|
295
|
+
s.send("a", 'call quick {"q":"x"}'); await until(() => s.calls.length === 2, "quick");
|
|
296
|
+
s.send("d", 'call plain {"q":"x"}'); await until(() => s.calls.length === 3, "plain");
|
|
297
|
+
await until(() => s.ended("a") && s.ended("d"), "the two short deadlines");
|
|
298
|
+
expect(s.ended("p")).toBe(false);
|
|
299
|
+
const quick = s.calls.find(call => call.request.tool === "quick")!, plain = s.calls.find(call => call.request.tool === "plain")!, patient = s.calls.find(call => call.request.tool === "patient")!;
|
|
300
|
+
expect(quick.signal.aborted).toBe(true); // the host was asked to stop
|
|
301
|
+
expect(plain.signal.aborted).toBe(true);
|
|
302
|
+
expect(patient.signal.aborted).toBe(false);
|
|
303
|
+
const timedOut = s.results().filter(result => result.code === "tool_timeout");
|
|
304
|
+
expect(timedOut).toHaveLength(2);
|
|
305
|
+
expect(timedOut[0]).toMatchObject({ ok: false, effect: "unknown", outcome: { status: "interrupted", code: "tool_timeout" } });
|
|
306
|
+
expect(s.session.tools!.invocation(quick.request.invocationId)).toMatchObject({ state: "interrupted", code: "tool_timeout", effect: "unknown" });
|
|
307
|
+
expect(s.toolEvents()).toContain(`interrupted:${quick.request.invocationId}`);
|
|
308
|
+
// The turn stayed live: its next inference received exactly that one paired result, and then it completed.
|
|
309
|
+
const inferences = s.requests.filter(request => request.channel === "a");
|
|
310
|
+
expect(inferences).toHaveLength(2);
|
|
311
|
+
expect(inferences[1]!.messages.filter(message => message.role === "tool")).toHaveLength(1);
|
|
312
|
+
expect(s.events.findLast(e => e.channel === "a" && e.event.type === "turn_ended")!.event).toMatchObject({ outcome: "completed" });
|
|
313
|
+
// A late reply is ignored: no new result, no further inference.
|
|
314
|
+
const before = { results: s.results().length, requests: s.requests.length };
|
|
315
|
+
quick.answer.resolve({ output: "too late" });
|
|
316
|
+
await new Promise(resolve => setTimeout(resolve, 30));
|
|
317
|
+
expect({ results: s.results().length, requests: s.requests.length }).toEqual(before);
|
|
318
|
+
patient.answer.resolve({ output: "in time" });
|
|
319
|
+
await until(() => s.ended("p"), "patient turn");
|
|
320
|
+
expect(s.results().at(-1)).toMatchObject({ ok: true, output: "in time" });
|
|
321
|
+
} finally { s.close(); }
|
|
322
|
+
|
|
323
|
+
// No deadline at all: the call simply waits.
|
|
324
|
+
const untimed = rig({ catalog: { catalog: [tool("slow", "fixed")] } }); const u = untimed.open();
|
|
325
|
+
try {
|
|
326
|
+
u.send("a", 'call slow {"q":"x"}'); await until(() => u.calls.length === 1, "slow");
|
|
327
|
+
await new Promise(resolve => setTimeout(resolve, 120));
|
|
328
|
+
expect(u.ended("a")).toBe(false);
|
|
329
|
+
expect(u.calls[0]!.signal.aborted).toBe(false);
|
|
330
|
+
u.calls[0]!.answer.resolve({ output: 1 });
|
|
331
|
+
await until(() => u.ended("a"), "slow turn");
|
|
332
|
+
} finally { u.close(); }
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
test("an executor that rejects its wait when asked to stop still yields the paired timeout result", async () => {
|
|
336
|
+
const r = rig({ catalog: { catalog: [tool("quick", "fixed", { deadlineMs: 30 })] } }); const s = r.open();
|
|
337
|
+
try {
|
|
338
|
+
s.executor.call = (_request, signal) => new Promise((_, reject) => signal.addEventListener("abort", () => reject(signal.reason), { once: true }));
|
|
339
|
+
s.send("a", 'call quick {"q":"x"}'); await until(() => s.ended("a"), "turn");
|
|
340
|
+
expect(s.results()).toMatchObject([{ code: "tool_timeout", outcome: { status: "interrupted", code: "tool_timeout" } }]);
|
|
341
|
+
expect(s.events.findLast(e => e.event.type === "turn_ended")!.event).toMatchObject({ outcome: "completed" });
|
|
342
|
+
} finally { s.close(); }
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
test("a typed handler error is a paired failure and the turn goes on; a lost connection leaves the call uncertain and it is never repeated", async () => {
|
|
346
|
+
const r = rig(); const s = r.open();
|
|
347
|
+
s.send("a", 'call lookup {"q":"x"}'); await until(() => s.calls.length === 1, "callback");
|
|
348
|
+
s.calls[0]!.answer.reject(new CallbackFailure("quota_exceeded", "No quota left"));
|
|
349
|
+
await until(() => s.ended("a"), "failed call");
|
|
350
|
+
expect(s.results()[0]).toMatchObject({ ok: false, code: "quota_exceeded", message: "No quota left", outcome: { status: "failed", code: "quota_exceeded" } });
|
|
351
|
+
expect(s.events.findLast(e => e.event.type === "turn_ended")!.event).toMatchObject({ outcome: "completed" });
|
|
352
|
+
expect(s.toolEvents()).toEqual(["started:1:c1-1", "failed:1:c1-1"]);
|
|
353
|
+
|
|
354
|
+
s.send("a", 'call lookup {"q":"y"}'); await until(() => s.calls.length === 2, "second callback");
|
|
355
|
+
s.calls[1]!.answer.reject(new CallbackLost("connection closed"));
|
|
356
|
+
await until(() => s.ended("a", 2), "lost callback");
|
|
357
|
+
expect(s.events.findLast(e => e.event.type === "turn_ended")!.event).toMatchObject({ outcome: "failed", uncertainCalls: ["c2-1"] });
|
|
358
|
+
expect(s.results()).toHaveLength(1);
|
|
359
|
+
expect(s.session.tools!.invocation("2:c2-1")).toMatchObject({ state: "interrupted", effect: "unknown" });
|
|
360
|
+
s.close();
|
|
361
|
+
// Reopen: still uncertain, and nothing calls the handler again.
|
|
362
|
+
const again = r.open();
|
|
363
|
+
try {
|
|
364
|
+
expect(again.session.tools!.invocation("2:c2-1")).toMatchObject({ state: "interrupted", effect: "unknown" });
|
|
365
|
+
again.send("a", "hello"); await until(() => again.ended("a"), "fresh turn");
|
|
366
|
+
expect(again.calls).toEqual([]);
|
|
367
|
+
} finally { again.close(); }
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
test("recovery tells a call that never reached dispatch from one that did", async () => {
|
|
371
|
+
const hold = deferred(), reached = deferred();
|
|
372
|
+
let held = false;
|
|
373
|
+
const r = rig({ beforeDispatch: async () => { if (held) return; held = true; reached.resolve(); await hold.promise; } }); const s = r.open();
|
|
374
|
+
s.send("a", 'call lookup {"q":"x"}'); await reached.promise;
|
|
375
|
+
// The process ends with the call requested and no dispatch evidence.
|
|
376
|
+
s.storage.close();
|
|
377
|
+
const second = r.open();
|
|
378
|
+
expect(second.session.tools!.invocation("1:c1-1")).toMatchObject({ state: "skipped", code: "turn_ended", effect: "none" });
|
|
379
|
+
expect(second.session.snapshot().turns[0]!.state).toMatchObject({ status: "interrupted", uncertainCallIds: [] });
|
|
380
|
+
// Now one that was dispatched: evidence is committed, the callback is outstanding.
|
|
381
|
+
second.send("a", 'call lookup {"q":"y"}'); await until(() => second.calls.length === 1, "callback");
|
|
382
|
+
second.storage.close();
|
|
383
|
+
const third = r.open();
|
|
384
|
+
try {
|
|
385
|
+
expect(third.session.tools!.invocation("2:c2-1")).toMatchObject({ state: "interrupted", effect: "unknown" });
|
|
386
|
+
expect(third.session.snapshot().turns[1]!.state).toMatchObject({ status: "interrupted", uncertainCallIds: ["c2-1"] });
|
|
387
|
+
expect(third.calls).toEqual([]);
|
|
388
|
+
} finally { third.close(); hold.resolve(); }
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
test("suspension waits for an untimed call and says which; interrupting the turn resolves the wait without replaying the call", async () => {
|
|
392
|
+
const r = rig(); const s = r.open();
|
|
393
|
+
try {
|
|
394
|
+
s.send("a", 'call lookup {"q":"x"}'); await until(() => s.calls.length === 1, "callback");
|
|
395
|
+
let suspended = false;
|
|
396
|
+
const suspending = s.session.suspend().then(result => { suspended = true; return result; });
|
|
397
|
+
await new Promise(resolve => setTimeout(resolve, 40));
|
|
398
|
+
expect(suspended).toBe(false);
|
|
399
|
+
const status = s.session.status();
|
|
400
|
+
expect(status.lifecycle).toBe("suspending");
|
|
401
|
+
expect(status.channels[0]!.activeTurn).toMatchObject({ status: "running", phase: { kind: "tool", id: "1:c1-1" } });
|
|
402
|
+
expect(s.session.tools!.invocation("1:c1-1")).toMatchObject({ state: "started", tool: "lookup" });
|
|
403
|
+
expect(s.session.channels.interrupt("a", 1)).toMatchObject({ ok: true, value: { interrupted: true } });
|
|
404
|
+
expect((await suspending).ok).toBe(true);
|
|
405
|
+
expect(s.calls[0]!.signal.aborted).toBe(true);
|
|
406
|
+
expect(s.session.tools!.invocation("1:c1-1")).toMatchObject({ state: "interrupted", effect: "unknown" });
|
|
407
|
+
// A late answer starts nothing, and resuming does not run the call again.
|
|
408
|
+
s.calls[0]!.answer.resolve({ output: "late" });
|
|
409
|
+
expect(s.session.resume().ok).toBe(true);
|
|
410
|
+
await new Promise(resolve => setTimeout(resolve, 30));
|
|
411
|
+
expect(s.calls).toHaveLength(1);
|
|
412
|
+
expect(s.results()).toEqual([]);
|
|
413
|
+
expect(s.requests).toHaveLength(1);
|
|
414
|
+
} finally { s.close(); }
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
test("a large result is stored by its producer; only the channel that produced it can read it, by ID, until it expires", async () => {
|
|
418
|
+
const r = rig(); const s = r.open();
|
|
419
|
+
try {
|
|
420
|
+
const full = "0123456789".repeat(5000);
|
|
421
|
+
s.send("a", 'call lookup {"q":"big"}'); await until(() => s.calls.length === 1, "callback");
|
|
422
|
+
s.stored.set("res-1", full);
|
|
423
|
+
s.calls[0]!.answer.resolve({ preview: full.slice(0, 40), reference: { resultId: "res-1", bytes: full.length, retention: "temporary", expiresAt: new Date(Date.now() + 60_000).toISOString() } });
|
|
424
|
+
await until(() => s.ended("a"), "large result turn");
|
|
425
|
+
const stored = s.results()[0]!;
|
|
426
|
+
expect(stored).toMatchObject({ ok: true, preview: full.slice(0, 40), result_id: "res-1", bytes: 50000, outcome: { status: "succeeded", reference: { resultId: "res-1", bytes: 50000, retention: "temporary" } } });
|
|
427
|
+
expect(JSON.stringify(stored).length).toBeLessThan(1000); // the model saw a preview, not the bytes
|
|
428
|
+
expect(s.session.tools!.invocation("1:c1-1")).toMatchObject({ state: "succeeded", reference: { resultId: "res-1" } });
|
|
429
|
+
|
|
430
|
+
// The producing channel reads a bounded part through the scoped reader.
|
|
431
|
+
s.send("a", 'call read_tool_result {"result_id":"res-1","offset":10,"length":20}'); await until(() => s.ended("a", 2), "read");
|
|
432
|
+
expect(s.results().at(-1)).toMatchObject({ ok: true, text: full.slice(10, 30), total_bytes: 50000, eof: false, next_offset: 30 });
|
|
433
|
+
expect(s.reads).toEqual([{ resultId: "res-1", invocationId: "1:c1-1", channel: "a", offset: 10, length: 20 }]);
|
|
434
|
+
// Another channel that saw the ID in shared history cannot use it; a path is not an ID; an unknown ID finds nothing.
|
|
435
|
+
s.send("b", 'call read_tool_result {"result_id":"res-1"}'); await until(() => s.ended("b"), "other channel");
|
|
436
|
+
expect(s.results().at(-1)).toMatchObject({ ok: false, code: "result_forbidden", outcome: { status: "failed", code: "result_forbidden" } });
|
|
437
|
+
s.send("a", 'call read_tool_result {"result_id":"/etc/passwd"}'); await until(() => s.ended("a", 3), "path");
|
|
438
|
+
expect(s.results().at(-1)).toMatchObject({ ok: false, code: "result_not_found" });
|
|
439
|
+
s.send("a", 'call read_tool_result {"result_id":"res-2"}'); await until(() => s.ended("a", 4), "unknown");
|
|
440
|
+
expect(s.results().at(-1)).toMatchObject({ ok: false, code: "result_not_found" });
|
|
441
|
+
expect(s.reads).toHaveLength(1); // none of the refused reads reached the host
|
|
442
|
+
// The producer dropped it: the host says so and the original call keeps its outcome.
|
|
443
|
+
s.stored.delete("res-1");
|
|
444
|
+
s.send("a", 'call read_tool_result {"result_id":"res-1"}'); await until(() => s.ended("a", 5), "expired at the host");
|
|
445
|
+
expect(s.results().at(-1)).toMatchObject({ ok: false, code: "result_expired" });
|
|
446
|
+
expect(s.session.tools!.invocation("1:c1-1")).toMatchObject({ state: "succeeded" });
|
|
447
|
+
} finally { s.close(); }
|
|
448
|
+
|
|
449
|
+
// A reference past its declared lifetime is refused by the harness itself; inline bytes over the limit are a typed failure.
|
|
450
|
+
const short = rig({ limits: { inlineBytes: 200 } }); const e = short.open();
|
|
451
|
+
try {
|
|
452
|
+
e.send("a", 'call lookup {"q":"x"}'); await until(() => e.calls.length === 1, "callback");
|
|
453
|
+
e.stored.set("old", "bytes");
|
|
454
|
+
e.calls[0]!.answer.resolve({ preview: "by", reference: { resultId: "old", bytes: 5, retention: "temporary", expiresAt: new Date(Date.now() - 1000).toISOString() } });
|
|
455
|
+
await until(() => e.ended("a"), "turn");
|
|
456
|
+
e.send("a", 'call read_tool_result {"result_id":"old"}'); await until(() => e.ended("a", 2), "expired");
|
|
457
|
+
expect(e.results().at(-1)).toMatchObject({ ok: false, code: "result_expired" });
|
|
458
|
+
expect(e.reads).toEqual([]);
|
|
459
|
+
e.send("a", 'call lookup {"q":"y"}'); await until(() => e.calls.length === 2, "second callback");
|
|
460
|
+
e.calls[1]!.answer.resolve({ output: "x".repeat(500) });
|
|
461
|
+
await until(() => e.ended("a", 3), "oversized inline");
|
|
462
|
+
expect(e.results().at(-1)).toMatchObject({ ok: false, code: "result_too_large", outcome: { status: "failed" } });
|
|
463
|
+
} finally { e.close(); }
|
|
464
|
+
});
|
|
465
|
+
|
|
466
|
+
test("catalog registrations cannot shadow notify_channel", () => {
|
|
467
|
+
expect(() => parseCatalog({ catalog: [tool("notify_channel", "fixed")] }, [])).toThrow(CatalogError);
|
|
468
|
+
});
|