@qlairoslabs/acp-client 0.13.0-alpha.1 → 0.13.2-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/CONSUMER_GUIDE.md +181 -8
- package/MIGRATION-0.12-to-0.13.md +20 -7
- package/package.json +13 -2
- package/src/agent/config.ts +2 -0
- package/src/agent/conversation-manager.ts +1 -0
- package/src/agent/native-operations.ts +40 -0
- package/src/agent-session-config.ts +2 -0
- package/src/agent-session.ts +12 -2
- package/src/agent.ts +100 -2
- package/src/client.ts +5 -3
- package/src/controller-connection.ts +1 -0
- package/src/controller.ts +2 -0
- package/src/index.ts +3 -0
- package/src/launcher.ts +2 -0
- package/src/native/approvals.ts +20 -3
- package/src/native/capabilities.ts +2 -2
- package/src/native/connection.ts +1 -1
- package/src/native/controller.ts +5 -3
- package/src/native/host-config.ts +2 -0
- package/src/native/host.ts +83 -4
- package/src/native/mcp.ts +47 -0
- package/src/native/recovery.ts +8 -7
- package/src/native/reminders/routine-guard.ts +4 -3
- package/src/native/reminders/routine-wire.ts +1 -1
- package/src/native-harness/README.md +58 -1
- package/src/native-harness/package.json +4 -0
- package/src/native-harness/scripts/build-routine-zones.py +47 -0
- package/src/native-harness/src/capabilities/attachments/admission.ts +42 -0
- package/src/native-harness/src/capabilities/attachments/image-validation.ts +98 -0
- package/src/native-harness/src/capabilities/attachments/input.ts +1 -0
- package/src/native-harness/src/capabilities/attachments/read.ts +76 -0
- package/src/native-harness/src/capabilities/attachments/recovery.ts +26 -0
- package/src/native-harness/src/capabilities/attachments/selection.ts +37 -0
- package/src/native-harness/src/capabilities/attachments/service.ts +75 -0
- package/src/native-harness/src/capabilities/attachments/upload.ts +164 -0
- package/src/native-harness/src/capabilities/attachments/vision.ts +45 -0
- package/src/native-harness/src/capabilities/context/build.ts +5 -0
- package/src/native-harness/src/capabilities/context/session.ts +2 -1
- package/src/native-harness/src/capabilities/model/openrouter-stream.ts +80 -17
- package/src/native-harness/src/capabilities/model/runner.ts +6 -3
- package/src/native-harness/src/capabilities/reminders/cron-calendar.ts +50 -0
- package/src/native-harness/src/capabilities/reminders/cron-fields.ts +46 -0
- package/src/native-harness/src/capabilities/reminders/cron-proof.ts +32 -0
- package/src/native-harness/src/capabilities/reminders/cron-zone.ts +53 -0
- package/src/native-harness/src/capabilities/reminders/iana-zones.json.gz +0 -0
- package/src/native-harness/src/capabilities/reminders/iana-zones.ts +34 -0
- package/src/native-harness/src/capabilities/reminders/interval.ts +30 -0
- package/src/native-harness/src/capabilities/reminders/routine-advance.ts +47 -0
- package/src/native-harness/src/capabilities/reminders/routine-backlog.ts +47 -0
- package/src/native-harness/src/capabilities/reminders/routine-expiry.ts +15 -0
- package/src/native-harness/src/capabilities/reminders/routine-occurrence.ts +65 -0
- package/src/native-harness/src/capabilities/reminders/routine-schedule.ts +70 -0
- package/src/native-harness/src/capabilities/reminders/unattended.ts +8 -0
- package/src/native-harness/src/capabilities/tools/mcp/client.ts +97 -0
- package/src/native-harness/src/capabilities/tools/mcp/http.ts +183 -0
- package/src/native-harness/src/capabilities/tools/mcp/registry.ts +62 -0
- package/src/native-harness/src/capabilities/tools/mcp/result.ts +33 -0
- package/src/native-harness/src/capabilities/tools/mcp/schema.ts +77 -0
- package/src/native-harness/src/capabilities/tools/mcp/secrets.ts +28 -0
- package/src/native-harness/src/capabilities/tools/mcp/stdio.ts +105 -0
- package/src/native-harness/src/capabilities/tools/reminders/index.ts +27 -5
- package/src/native-harness/src/capabilities/tools/runtime/invocations.ts +4 -1
- package/src/native-harness/src/capabilities/tools/web/config.ts +1 -0
- package/src/native-harness/src/capabilities/tools/web/definitions.ts +18 -0
- package/src/native-harness/src/capabilities/tools/web/direct-address.ts +56 -0
- package/src/native-harness/src/capabilities/tools/web/direct-transport.ts +235 -0
- package/src/native-harness/src/capabilities/tools/web/direct.ts +149 -0
- package/src/native-harness/src/capabilities/tools/web/exa-transport.ts +41 -0
- package/src/native-harness/src/capabilities/tools/web/exa.ts +71 -0
- package/src/native-harness/src/capabilities/tools/web/preview.ts +44 -0
- package/src/native-harness/src/capabilities/tools/web/registry.ts +47 -0
- package/src/native-harness/src/capabilities/tools/web/usage.ts +1 -0
- package/src/native-harness/src/contracts/agent.ts +3 -1
- package/src/native-harness/src/contracts/attachments.ts +62 -0
- package/src/native-harness/src/contracts/config-permissions.ts +14 -3
- package/src/native-harness/src/contracts/context.ts +1 -1
- package/src/native-harness/src/contracts/events.ts +2 -2
- package/src/native-harness/src/contracts/loop.ts +3 -3
- package/src/native-harness/src/contracts/mcp.ts +22 -0
- package/src/native-harness/src/contracts/model-execution.ts +2 -1
- package/src/native-harness/src/contracts/operator-controls.ts +8 -1
- package/src/native-harness/src/contracts/protocol.ts +21 -5
- package/src/native-harness/src/contracts/reminders.ts +4 -2
- package/src/native-harness/src/contracts/routines.ts +20 -0
- package/src/native-harness/src/contracts/session-file.ts +2 -0
- package/src/native-harness/src/contracts/session.ts +8 -3
- package/src/native-harness/src/contracts/storage.ts +32 -13
- package/src/native-harness/src/contracts/tools.ts +2 -0
- package/src/native-harness/src/contracts/web.ts +16 -0
- package/src/native-harness/src/governance/permissions/gate.ts +9 -2
- package/src/native-harness/src/governance/policy/resolve.ts +6 -1
- package/src/native-harness/src/index.ts +48 -12
- package/src/native-harness/src/interfaces/cli/development.ts +108 -53
- package/src/native-harness/src/interfaces/cli/serve.ts +2 -2
- package/src/native-harness/src/interfaces/cli/start.ts +22 -13
- package/src/native-harness/src/interfaces/client.ts +8 -2
- package/src/native-harness/src/interfaces/inspector/index.html +7 -1
- package/src/native-harness/src/interfaces/inspector/state.ts +6 -2
- package/src/native-harness/src/interfaces/protocol/load.ts +3 -1
- package/src/native-harness/src/interfaces/protocol/local.ts +13 -4
- package/src/native-harness/src/interfaces/protocol/operator.ts +8 -2
- package/src/native-harness/src/interfaces/protocol/server.ts +102 -36
- package/src/native-harness/src/interfaces/protocol/stdio-client.ts +8 -0
- package/src/native-harness/src/interfaces/web-chat/index.html +65 -12
- package/src/native-harness/src/interfaces/web-chat/server.ts +30 -3
- package/src/native-harness/src/kernel/channels.ts +27 -15
- package/src/native-harness/src/kernel/loop.ts +1 -1
- package/src/native-harness/src/runtime/config/inference-key.ts +7 -0
- package/src/native-harness/src/runtime/config/managed.ts +1 -1
- package/src/native-harness/src/runtime/config/paths.ts +8 -1
- package/src/native-harness/src/runtime/execution/mcp-stdio.ts +31 -0
- package/src/native-harness/src/runtime/reminder-validation.ts +31 -10
- package/src/native-harness/src/runtime/reminders.ts +2 -2
- package/src/native-harness/src/state/storage/archive.ts +113 -12
- package/src/native-harness/src/state/storage/attachment-files.ts +58 -0
- package/src/native-harness/src/state/storage/attachment-import.ts +106 -0
- package/src/native-harness/src/state/storage/attachment-tables.ts +123 -0
- package/src/native-harness/src/state/storage/engine.ts +396 -45
- package/src/native-harness/src/state/storage/inference.ts +30 -2
- package/src/native-harness/src/state/storage/memory-attachments.ts +56 -0
- package/src/native-harness/src/state/storage/memory-reminders.ts +31 -6
- package/src/native-harness/src/state/storage/memory.ts +32 -4
- package/src/native-harness/src/state/storage/reminder-archive.ts +53 -12
- package/src/native-harness/src/state/storage/reminder-change.ts +60 -14
- package/src/native-harness/src/state/storage/reminder-tables.ts +11 -3
- package/src/native-harness/src/state/storage/routine-row.ts +25 -0
- package/src/native-harness/src/state/storage/session-file.ts +22 -9
- package/src/native-harness/src/state/storage/sqlite-reminders.ts +48 -8
- package/src/native-harness/src/state/storage/sqlite.ts +59 -11
- package/src/native-harness/src/state/storage/web-tables.ts +47 -0
- package/src/native-harness/src/testing.ts +151 -56
- package/src/native-harness/src/util/attachment-input.ts +42 -0
- package/src/native-harness/src/util/config.ts +64 -9
- package/src/native-harness/src/util/intake.ts +7 -0
- package/src/native-harness/src/util/mcp-config.ts +102 -0
- package/src/native-harness/src/util/web-config.ts +34 -0
- package/src/native-harness/src/util/web-usage.ts +33 -0
- package/src/orchestrator/permissions.ts +6 -3
- package/src/permissions/conversation.ts +13 -5
- package/src/permissions/matcher.ts +2 -0
- package/src/permissions/outcome.ts +12 -1
- package/src/permissions/policy.ts +13 -8
- package/src/steering/combine.ts +1 -0
- package/src/steering/contracts.ts +3 -0
- package/src/terminals.ts +9 -6
- package/src/native/reminders/reminders.test.ts +0 -553
- package/src/native/reminders/routine-config.typecheck.ts +0 -13
- package/src/native/reminders/wire.typecheck.ts +0 -13
- package/src/native-harness/.res/README.md +0 -1
- package/src/native-harness/.res/architecture/README.md +0 -21
- package/src/native-harness/.res/architecture/context-and-data.md +0 -31
- package/src/native-harness/.res/architecture/execution.md +0 -42
- package/src/native-harness/.res/architecture/overview.md +0 -44
- package/src/native-harness/.res/architecture/persistence.md +0 -56
- package/src/native-harness/.res/architecture/suspend-and-resume.md +0 -45
- package/src/native-harness/.res/architecture/technical-architecture.md +0 -50
- package/src/native-harness/.res/decisions/0001-basic-loop.md +0 -11
- package/src/native-harness/.res/decisions/0002-channel-input.md +0 -17
- package/src/native-harness/.res/decisions/0003-inference-inspection.md +0 -14
- package/src/native-harness/.res/decisions/0004-shared-context.md +0 -21
- package/src/native-harness/.res/decisions/0005-notice-inbox.md +0 -20
- package/src/native-harness/.res/decisions/0006-explicit-notices.md +0 -12
- package/src/native-harness/.res/decisions/0007-channel-output.md +0 -12
- package/src/native-harness/.res/decisions/0008-browser-client.md +0 -16
- package/src/native-harness/.res/decisions/0009-scripted-model.md +0 -18
- package/src/native-harness/.res/decisions/0010-inprocess-protocol.md +0 -19
- package/src/native-harness/.res/decisions/0011-stdio-transport.md +0 -21
- package/src/native-harness/.res/decisions/0012-session-storage-contract.md +0 -37
- package/src/native-harness/.res/decisions/0013-durable-delivery-contract.md +0 -64
- package/src/native-harness/.res/decisions/0014-channel-controls-contract.md +0 -73
- package/src/native-harness/.res/decisions/0015-session-file-contract.md +0 -72
- package/src/native-harness/.res/decisions/0016-configuration-permissions.md +0 -159
- package/src/native-harness/.res/decisions/0017-openrouter-managed-config.md +0 -69
- package/src/native-harness/.res/decisions/0018-tool-dispatch-evidence.md +0 -78
- package/src/native-harness/.res/decisions/0019-model-execution.md +0 -188
- package/src/native-harness/.res/decisions/0020-startup-channel-changes.md +0 -71
- package/src/native-harness/.res/decisions/0021-tools-and-host-callbacks.md +0 -100
- package/src/native-harness/.res/decisions/0022-operator-controls.md +0 -115
- package/src/native-harness/.res/decisions/0023-long-running-mock.md +0 -82
- package/src/native-harness/.res/decisions/0024-callback-policy-names.md +0 -46
- package/src/native-harness/.res/decisions/0025-external-notices.md +0 -364
- package/src/native-harness/.res/decisions/0026-bounded-context.md +0 -81
- package/src/native-harness/.res/decisions/0027-development-instructions.md +0 -22
- package/src/native-harness/.res/decisions/0028-debug-tools.md +0 -16
- package/src/native-harness/.res/decisions/0029-bounded-model-call-pages.md +0 -37
- package/src/native-harness/.res/decisions/0030-timeline-retrieval.md +0 -145
- package/src/native-harness/.res/decisions/0031-one-off-reminders.md +0 -173
- package/src/native-harness/.res/docs/11-15.md +0 -148
- package/src/native-harness/.res/docs/BUSINESS_RULES.md +0 -111
- package/src/native-harness/.res/docs/WORK.md +0 -65
- package/src/native-harness/.res/docs/_/11-16-persistence/LOG.md +0 -312
- package/src/native-harness/.res/docs/_/11-16-persistence/PLAN.md +0 -77
- package/src/native-harness/.res/docs/_/11-16-persistence/SPEC.md +0 -313
- package/src/native-harness/.res/docs/_/11-19-channel-controls/LOG.md +0 -160
- package/src/native-harness/.res/docs/_/11-19-channel-controls/PLAN.md +0 -89
- package/src/native-harness/.res/docs/_/11-19-channel-controls/SPEC.md +0 -135
- package/src/native-harness/.res/docs/_/11-19-config-permissions/LOG.md +0 -143
- package/src/native-harness/.res/docs/_/11-19-config-permissions/PLAN.md +0 -93
- package/src/native-harness/.res/docs/_/11-19-config-permissions/SPEC.md +0 -181
- package/src/native-harness/.res/docs/acp-client-integration/0001-DESIGN/11-20-LOG.md +0 -433
- package/src/native-harness/.res/docs/acp-client-integration/0001-DESIGN/PLAN.md +0 -60
- package/src/native-harness/.res/docs/acp-client-integration/0001-DESIGN/PROTOCOL.md +0 -141
- package/src/native-harness/.res/docs/acp-client-integration/0001-DESIGN/SPEC.md +0 -168
- package/src/native-harness/.res/docs/attachments/0001-DESIGN/SPEC.md +0 -111
- package/src/native-harness/.res/docs/bounded-context/0001-DESIGN/PLAN.md +0 -129
- package/src/native-harness/.res/docs/bounded-context/0001-DESIGN/SPEC.md +0 -135
- package/src/native-harness/.res/docs/channel-messaging/0001-DESIGN-external-notices/LOG.md +0 -437
- package/src/native-harness/.res/docs/channel-messaging/0001-DESIGN-external-notices/PLAN.md +0 -127
- package/src/native-harness/.res/docs/channel-messaging/0001-DESIGN-external-notices/SPEC.md +0 -203
- package/src/native-harness/.res/docs/long-running-mock/0001-DESIGN/LOG.md +0 -292
- package/src/native-harness/.res/docs/long-running-mock/0001-DESIGN/PLAN.md +0 -91
- package/src/native-harness/.res/docs/long-running-mock/0001-DESIGN/SPEC.md +0 -187
- package/src/native-harness/.res/docs/model-execution/0001-DESIGN/LOG.md +0 -148
- package/src/native-harness/.res/docs/model-execution/0001-DESIGN/PLAN.md +0 -95
- package/src/native-harness/.res/docs/model-execution/0001-DESIGN/SPEC.md +0 -200
- package/src/native-harness/.res/docs/model-execution/0002-AMENDMENT-accounting/SPEC.md +0 -80
- package/src/native-harness/.res/docs/operator-controls/0001-DESIGN/LOG.md +0 -206
- package/src/native-harness/.res/docs/operator-controls/0001-DESIGN/PLAN.md +0 -106
- package/src/native-harness/.res/docs/operator-controls/0001-DESIGN/SPEC.md +0 -297
- package/src/native-harness/.res/docs/persistence/0002-AMENDMENT-session-file/LOG.md +0 -41
- package/src/native-harness/.res/docs/persistence/0002-AMENDMENT-session-file/PLAN.md +0 -36
- package/src/native-harness/.res/docs/persistence/0002-AMENDMENT-session-file/SPEC.md +0 -84
- package/src/native-harness/.res/docs/shell-execution/0001-DESIGN/SPEC.md +0 -147
- package/src/native-harness/.res/docs/timeline-retrieval/0001-DESIGN/LOG.md +0 -15
- package/src/native-harness/.res/docs/timeline-retrieval/0001-DESIGN/PLAN.md +0 -107
- package/src/native-harness/.res/docs/timeline-retrieval/0001-DESIGN/SPEC.md +0 -114
- package/src/native-harness/.res/docs/todos/11-19-TODO-auto_review-approve.md +0 -24
- package/src/native-harness/.res/docs/todos/11-20-TODO-user-entered-tool-code.md +0 -23
- package/src/native-harness/.res/docs/todos/11-21-TODO-node-resource-coordination.md +0 -103
- package/src/native-harness/.res/docs/todos/11-22-TODO-harness-m1-sequence.md +0 -50
- package/src/native-harness/.res/docs/tools-and-callbacks/0001-DESIGN/LOG.md +0 -337
- package/src/native-harness/.res/docs/tools-and-callbacks/0001-DESIGN/PLAN.md +0 -76
- package/src/native-harness/.res/docs/tools-and-callbacks/0001-DESIGN/SPEC.md +0 -204
- package/src/native-harness/.res/docs/tools-and-callbacks/0002-AMENDMENT-callback-policy/LOG.md +0 -73
- package/src/native-harness/.res/docs/tools-and-callbacks/0002-AMENDMENT-callback-policy/SPEC.md +0 -64
- package/src/native-harness/.res/docs/tools-and-callbacks/0003-DESIGN-attachment-tools/SPEC.md +0 -58
- package/src/native-harness/.res/docs/tools-and-callbacks/0004-DESIGN-reminder-tools/LOG.md +0 -45
- package/src/native-harness/.res/docs/tools-and-callbacks/0004-DESIGN-reminder-tools/PLAN.md +0 -108
- package/src/native-harness/.res/docs/tools-and-callbacks/0004-DESIGN-reminder-tools/SPEC.md +0 -169
- package/src/native-harness/.res/docs/web-tools/0001-DESIGN/SPEC.md +0 -128
- package/src/native-harness/.res/marketing-draft.md +0 -22
- package/src/native-harness/.res/sandbox/1-simple-harness/README.md +0 -285
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-1.md +0 -19
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-10.md +0 -138
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-11.md +0 -148
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-12.md +0 -172
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-13.md +0 -194
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-14.md +0 -233
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-15.md +0 -249
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-16.md +0 -265
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-17.md +0 -279
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-18.md +0 -293
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-19.md +0 -307
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-2.md +0 -29
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-20.md +0 -317
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-21.md +0 -327
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-3.md +0 -40
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-4.md +0 -59
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-5.md +0 -69
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-6.md +0 -79
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-7.md +0 -89
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-8.md +0 -102
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-9.md +0 -116
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation.jsonl +0 -49
- package/src/native-harness/.res/sandbox/1-simple-harness/doc.md +0 -87
- package/src/native-harness/.res/sandbox/1-simple-harness/harness.py +0 -289
- package/src/native-harness/.res/sandbox/1-simple-harness/local/harness copy 2.py +0 -221
- package/src/native-harness/.res/sandbox/1-simple-harness/local/harness copy 3.py +0 -287
- package/src/native-harness/.res/sandbox/1-simple-harness/local/harness copy.py +0 -165
- package/src/native-harness/.res/sandbox/1-simple-harness/state.json +0 -22
- package/src/native-harness/.res/sandbox/1-simple-harness/system-prompt.md +0 -2
- package/src/native-harness/AGENTS.md +0 -70
- package/src/native-harness/ARCHITECTURE.md +0 -249
- package/src/native-harness/bun.lock +0 -26
- package/src/native-harness/test/agent.test.ts +0 -130
- package/src/native-harness/test/approval-gate.test.ts +0 -255
- package/src/native-harness/test/approval-protocol.test.ts +0 -94
- package/src/native-harness/test/boundaries.test.ts +0 -18
- package/src/native-harness/test/channel-controls.test.ts +0 -322
- package/src/native-harness/test/client-abort.test.ts +0 -136
- package/src/native-harness/test/config-policy.test.ts +0 -301
- package/src/native-harness/test/conformance/storage.ts +0 -1141
- package/src/native-harness/test/context.test.ts +0 -177
- package/src/native-harness/test/crash.test.ts +0 -187
- package/src/native-harness/test/debug-tools.test.ts +0 -67
- package/src/native-harness/test/development-cli.test.ts +0 -67
- package/src/native-harness/test/development.test.ts +0 -171
- package/src/native-harness/test/dispatch-evidence.test.ts +0 -58
- package/src/native-harness/test/e2e.test.ts +0 -186
- package/src/native-harness/test/external-notices.test.ts +0 -101
- package/src/native-harness/test/fixtures/approval-e2e.jsonl +0 -4
- package/src/native-harness/test/fixtures/crash-scenario.jsonl +0 -5
- package/src/native-harness/test/fixtures/development-lifecycle.jsonl +0 -10
- package/src/native-harness/test/fixtures/echo-scenario.jsonl +0 -3
- package/src/native-harness/test/fixtures/format2-schema.ts +0 -27
- package/src/native-harness/test/fixtures/format3-schema.ts +0 -16
- package/src/native-harness/test/fixtures/hold-scenario.jsonl +0 -4
- package/src/native-harness/test/fixtures/model-e2e.jsonl +0 -3
- package/src/native-harness/test/fixtures/storage-owner.ts +0 -20
- package/src/native-harness/test/format-reply.test.ts +0 -10
- package/src/native-harness/test/helpers/operator-view.ts +0 -41
- package/src/native-harness/test/helpers/scenario.ts +0 -9
- package/src/native-harness/test/helpers/session.ts +0 -38
- package/src/native-harness/test/helpers/stdio.ts +0 -46
- package/src/native-harness/test/inspector.test.ts +0 -77
- package/src/native-harness/test/listeners.test.ts +0 -49
- package/src/native-harness/test/loop.test.ts +0 -88
- package/src/native-harness/test/model-channel-double.test.ts +0 -87
- package/src/native-harness/test/model-crash.test.ts +0 -62
- package/src/native-harness/test/model-delivery-regressions.test.ts +0 -55
- package/src/native-harness/test/model-e2e.test.ts +0 -71
- package/src/native-harness/test/model-final-filter.test.ts +0 -30
- package/src/native-harness/test/model-large-reply.test.ts +0 -28
- package/src/native-harness/test/model-live-queue.test.ts +0 -33
- package/src/native-harness/test/model-runner.test.ts +0 -117
- package/src/native-harness/test/model-storage.test.ts +0 -99
- package/src/native-harness/test/model-stream-adapter.test.ts +0 -26
- package/src/native-harness/test/model-stream-public.test.ts +0 -77
- package/src/native-harness/test/notices.test.ts +0 -64
- package/src/native-harness/test/openrouter-config.test.ts +0 -218
- package/src/native-harness/test/operator-controls.test.ts +0 -132
- package/src/native-harness/test/output.test.ts +0 -44
- package/src/native-harness/test/owner-config.test.ts +0 -64
- package/src/native-harness/test/permissions-e2e.test.ts +0 -68
- package/src/native-harness/test/persistence.test.ts +0 -236
- package/src/native-harness/test/portability.test.ts +0 -337
- package/src/native-harness/test/protocol.test.ts +0 -160
- package/src/native-harness/test/reminder-clock.test.ts +0 -61
- package/src/native-harness/test/reminder-stdio.test.ts +0 -140
- package/src/native-harness/test/reminder-storage.test.ts +0 -124
- package/src/native-harness/test/scenario-jsonl.test.ts +0 -112
- package/src/native-harness/test/scripted.test.ts +0 -92
- package/src/native-harness/test/session-file.test.ts +0 -51
- package/src/native-harness/test/startup-channel-changes.test.ts +0 -256
- package/src/native-harness/test/stdio.test.ts +0 -132
- package/src/native-harness/test/storage-memory.test.ts +0 -4
- package/src/native-harness/test/storage-sqlite.test.ts +0 -420
- package/src/native-harness/test/suspension.test.ts +0 -430
- package/src/native-harness/test/timeline-retrieval.test.ts +0 -211
- package/src/native-harness/test/tools-catalog.test.ts +0 -468
- package/src/native-harness/test/tools-protocol.test.ts +0 -418
- package/src/native-harness/test/transfers.test.ts +0 -94
- package/src/native-harness/test/web-chat.test.ts +0 -35
|
@@ -48,7 +48,7 @@ export async function start(options: StartOptions = {}) {
|
|
|
48
48
|
inspectorPort: Number(process.env.HARNESS_INSPECTOR_PORT ?? 3000), webChatPort: Number(process.env.HARNESS_CHAT_PORT ?? 3001) } : agentConfiguration();
|
|
49
49
|
if (config.managedDirectory) await mkdir(config.managedDirectory, { recursive: true, mode: 0o700 });
|
|
50
50
|
if (managed && create) await mkdir(managed.directory, { recursive: true, mode: 0o700 });
|
|
51
|
-
const development = await openDevelopment({ systemPrompt, database, sessionId, create, script, managedConfig, instructions,
|
|
51
|
+
const development = await openDevelopment({ systemPrompt, database, ...(managed ? { mediaRoot: join(managed.directory, "media") } : {}), sessionId, create, script, managedConfig, instructions,
|
|
52
52
|
debugTools: options.debug || options.debugTools,
|
|
53
53
|
timelineTools: options.timelineTools,
|
|
54
54
|
debugInstructions: options.debug && instructions === undefined ? loadInstructions("agent-demo") : undefined,
|
|
@@ -70,14 +70,14 @@ export async function start(options: StartOptions = {}) {
|
|
|
70
70
|
inspector = bindWebPort(port, "HARNESS_INSPECTOR_PORT", chosen => serveInspector(inspection, chosen));
|
|
71
71
|
// Lifecycle control stays on the owner's Unix socket; the LAN chat gets messages only.
|
|
72
72
|
const handleChat = createChannelHandler(local, outputs);
|
|
73
|
-
webChat = bindWebPort(config.webChatPort, "HARNESS_CHAT_PORT", chosen => serveWebChat(handleChat, chosen
|
|
73
|
+
webChat = bindWebPort(config.webChatPort, "HARNESS_CHAT_PORT", chosen => serveWebChat(handleChat, chosen, undefined,
|
|
74
|
+
{ attachments: development.attachments, ensureChannel(id) { const result = session.channels.create({ channelId: id }); if (!result.ok) throw new Error(result.error.message); } }));
|
|
74
75
|
} catch (error) {
|
|
75
76
|
// Startup is all-or-nothing: do not leave an agent listening if the inspector
|
|
76
77
|
// could not bind its port and the command reports a startup failure.
|
|
77
|
-
stopOutput()
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
development.close();
|
|
78
|
+
for (const cleanup of [stopOutput, () => server?.stop(true), () => inspector?.stop(true), () => development.close()]) {
|
|
79
|
+
try { await cleanup(); } catch { /* Preserve the original startup failure. */ }
|
|
80
|
+
}
|
|
81
81
|
throw error;
|
|
82
82
|
}
|
|
83
83
|
const status = session.status();
|
|
@@ -95,12 +95,21 @@ export async function start(options: StartOptions = {}) {
|
|
|
95
95
|
session.start();
|
|
96
96
|
}
|
|
97
97
|
console.log("Ctrl+C stops the agent: running turns are recorded as interrupted. Run `bun run suspend` first to pause cleanly.");
|
|
98
|
-
|
|
98
|
+
let stopping: Promise<void> | undefined;
|
|
99
|
+
const stop = () => stopping ??= (async () => {
|
|
99
100
|
// Stop is immediate and is not suspension; a cleanly suspended session keeps its checkpoints.
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
101
|
+
try {
|
|
102
|
+
session.stop("Agent process stopped");
|
|
103
|
+
stopOutput();
|
|
104
|
+
await Promise.allSettled([server?.stop(true), inspector?.stop(true), webChat.server.stop(true)]);
|
|
105
|
+
} finally {
|
|
106
|
+
await development.close();
|
|
107
|
+
}
|
|
108
|
+
})();
|
|
109
|
+
const onSignal = () => { void stop().catch(() => {
|
|
110
|
+
console.error("Failed to close the development session.");
|
|
111
|
+
process.exitCode = 1;
|
|
112
|
+
}); };
|
|
113
|
+
process.once("SIGINT", onSignal);
|
|
114
|
+
process.once("SIGTERM", onSignal);
|
|
106
115
|
}
|
|
@@ -19,7 +19,7 @@ export type ResultReader = (read: ResultRead) => Promise<ResultPage> | ResultPag
|
|
|
19
19
|
type Calls = Methods & DurableMethods;
|
|
20
20
|
|
|
21
21
|
export class HarnessClientError extends Error {
|
|
22
|
-
constructor(public readonly code: string, message: string) { super(message); this.name = "HarnessClientError"; }
|
|
22
|
+
constructor(public readonly code: string, message: string, public readonly expectedOffset?: number) { super(message); this.name = "HarnessClientError"; }
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
/**
|
|
@@ -52,7 +52,7 @@ export class HarnessClient {
|
|
|
52
52
|
if (message.id === null) return;
|
|
53
53
|
const waiting = this.waiting.get(message.id);
|
|
54
54
|
if (!waiting) return;
|
|
55
|
-
if ("error" in message) waiting.reject(new HarnessClientError(message.error.data.code, message.error.message));
|
|
55
|
+
if ("error" in message) waiting.reject(new HarnessClientError(message.error.data.code, message.error.message, message.error.data.expectedOffset));
|
|
56
56
|
else waiting.resolve(message.result);
|
|
57
57
|
}
|
|
58
58
|
});
|
|
@@ -129,6 +129,12 @@ export class HarnessClient {
|
|
|
129
129
|
return this.request("initialize", params);
|
|
130
130
|
}
|
|
131
131
|
createSession(params: CreateParams) { return this.request("session/create", params); }
|
|
132
|
+
beginAttachment(params: Calls["attachment/begin"]["params"]) { return this.request("attachment/begin", params); }
|
|
133
|
+
attachmentStatus(params: Calls["attachment/status"]["params"]) { return this.request("attachment/status", params); }
|
|
134
|
+
writeAttachment(params: Calls["attachment/write"]["params"]) { return this.request("attachment/write", params); }
|
|
135
|
+
finalizeAttachment(params: Calls["attachment/finalize"]["params"]) { return this.request("attachment/finalize", params); }
|
|
136
|
+
abortAttachment(params: Calls["attachment/abort"]["params"]) { return this.request("attachment/abort", params); }
|
|
137
|
+
readAttachment(params: Calls["attachment/read"]["params"]) { return this.request("attachment/read", params); }
|
|
132
138
|
/** Decision 0021. Serve `functions/call` requests. Set before `initialize`
|
|
133
139
|
* advertises handler names. One handler routes by `call.handler`. */
|
|
134
140
|
serveFunctions(handler: FunctionHandler, reader?: ResultReader) { this.functionHandler = handler; this.resultReader = reader; }
|
|
@@ -187,7 +187,7 @@
|
|
|
187
187
|
loadCalls.disabled = true;
|
|
188
188
|
try {
|
|
189
189
|
const data = await endpoint('/calls?id=' + encodeURIComponent(id));
|
|
190
|
-
if (version === viewVersion) { callDetails = { id, modelCalls: data.modelCalls }; fetchError = ''; }
|
|
190
|
+
if (version === viewVersion) { callDetails = { id, modelCalls: data.modelCalls, webUsage: data.webUsage }; fetchError = ''; }
|
|
191
191
|
} catch (error) { if (version === viewVersion) fetchError = String(error); }
|
|
192
192
|
finally { if (version === viewVersion) render(); }
|
|
193
193
|
};
|
|
@@ -206,6 +206,12 @@
|
|
|
206
206
|
for (const [turnId, requests] of turns) {
|
|
207
207
|
main.append(node('h2', turnId === 'unknown' ? 'New turn' : 'Turn ' + turnId, 'turn-divider'));
|
|
208
208
|
const calls = modelCalls.filter(call => call.turnId === String(turnId));
|
|
209
|
+
const webUsage = callDetails?.id === selected ? (callDetails.webUsage ?? []).filter(value => value.turnId === String(turnId)) : [];
|
|
210
|
+
for (const usage of webUsage) {
|
|
211
|
+
const details = node('details'); details.dataset.key = channel.id + ':web-usage:' + usage.invocationId;
|
|
212
|
+
details.open = expanded.has(details.dataset.key);
|
|
213
|
+
details.append(node('summary', 'Web usage · ' + usage.tool), json(usage.webUsage)); main.append(details);
|
|
214
|
+
}
|
|
209
215
|
for (const call of calls) {
|
|
210
216
|
const details = node('details');
|
|
211
217
|
details.dataset.key = channel.id + ':model-call:' + call.callId;
|
|
@@ -24,7 +24,8 @@ function read<T>(result: StorageResult<T>) {
|
|
|
24
24
|
/** Capture state is process-local. A notification marks the requested view
|
|
25
25
|
* dirty. Only HTTP reads request data from storage. */
|
|
26
26
|
export function createInspection(systemPrompt: string, tools: readonly ToolDefinition[],
|
|
27
|
-
reads: InspectionStorageReads, storage: string
|
|
27
|
+
reads: InspectionStorageReads, storage: string,
|
|
28
|
+
webInvocations?: (turnId: number) => import("../../contracts/tools.ts").ToolInvocation[]) {
|
|
28
29
|
const instructions = composeSystemPrompt(systemPrompt);
|
|
29
30
|
const captures = new Map<string, { turnId: number; metadata: NonNullable<InspectedInference["context"]> }>();
|
|
30
31
|
const channels = new Map<string, InspectedInference[]>();
|
|
@@ -55,7 +56,10 @@ export function createInspection(systemPrompt: string, tools: readonly ToolDefin
|
|
|
55
56
|
modelCalls(id: string) {
|
|
56
57
|
const result = reads.readInspectionCalls(id);
|
|
57
58
|
if (!result.ok) throw new Error(result.error.message);
|
|
58
|
-
|
|
59
|
+
const turns = [...new Set(result.value.map(call => Number(call.turnId)))];
|
|
60
|
+
const webUsage = turns.flatMap(turnId => webInvocations?.(turnId) ?? []).filter(value => value.webUsage)
|
|
61
|
+
.map(({ invocationId, turnId, tool, webUsage }) => ({ invocationId, turnId, tool, webUsage }));
|
|
62
|
+
return { modelCalls: result.value, webUsage };
|
|
59
63
|
},
|
|
60
64
|
subscribe(listener: () => void) {
|
|
61
65
|
listeners.add(listener);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ItemStatus, LoadResult, StatusResult, StoredMessage, TurnStatus } from "../../contracts/protocol.ts";
|
|
2
2
|
import type { SessionStatus } from "../../contracts/session.ts";
|
|
3
3
|
import type { StorageSnapshot, StoredTurn } from "../../contracts/storage.ts";
|
|
4
|
+
import { parseAttachmentFailure } from "../../contracts/attachments.ts";
|
|
4
5
|
import { MAX_FRAME_BYTES } from "./framing.ts";
|
|
5
6
|
|
|
6
7
|
/** Room left in a frame for the JSON-RPC envelope around a result. */
|
|
@@ -11,7 +12,8 @@ export class FrameLimit extends Error {}
|
|
|
11
12
|
export function turnStatus(turn: StoredTurn): TurnStatus {
|
|
12
13
|
const state = turn.state;
|
|
13
14
|
return { turnId: String(turn.turnId), channel: turn.channelId, items: turn.itemIds, state: state.status,
|
|
14
|
-
...(state.status === "failed" || state.status === "interrupted" ? { reason: state.reason, uncertainCalls: state.uncertainCallIds
|
|
15
|
+
...(state.status === "failed" || state.status === "interrupted" ? { reason: state.reason, uncertainCalls: state.uncertainCallIds,
|
|
16
|
+
...(parseAttachmentFailure(state.reason) ? { attachmentFailure: parseAttachmentFailure(state.reason) } : {}) } : {}) };
|
|
15
17
|
}
|
|
16
18
|
|
|
17
19
|
export function wireStatus(status: SessionStatus, view: Pick<StorageSnapshot, "turns">): StatusResult {
|
|
@@ -2,6 +2,7 @@ import type { ChannelInput } from "../../contracts/agent.ts";
|
|
|
2
2
|
import type { ChannelOutputs } from "../../contracts/output.ts";
|
|
3
3
|
import type { PersistentSession } from "../../contracts/session.ts";
|
|
4
4
|
import { outputStream } from "./output.ts";
|
|
5
|
+
import { validateMixedParts } from "../../util/attachment-input.ts";
|
|
5
6
|
|
|
6
7
|
type LocalSession = Pick<PersistentSession, "agent" | "subscribe">;
|
|
7
8
|
/** Lifecycle operations for the process owner's local socket only. */
|
|
@@ -67,15 +68,23 @@ export function createChannelHandler(session: LocalSession, outputs?: ChannelOut
|
|
|
67
68
|
let input: ChannelInput;
|
|
68
69
|
try {
|
|
69
70
|
const body = await request.json() as ChannelInput | null;
|
|
70
|
-
if (!body || ![body.channelId, body.participantId
|
|
71
|
+
if (!body || ![body.channelId, body.participantId].every(
|
|
71
72
|
(value) => typeof value === "string" && value.trim().length > 0,
|
|
72
|
-
)) throw new Error("Expected channelId
|
|
73
|
-
|
|
73
|
+
)) throw new Error("Expected channelId and participantId as nonempty strings");
|
|
74
|
+
if (body.parts !== undefined) {
|
|
75
|
+
const parts = validateMixedParts(body.parts);
|
|
76
|
+
const text = parts.flatMap(part => part.type === "text" ? [part.text] : []).join("\n");
|
|
77
|
+
if (body.text !== undefined && body.text !== text) throw new Error("Text does not match ordered parts");
|
|
78
|
+
input = { channelId: body.channelId, participantId: body.participantId, text, parts };
|
|
79
|
+
} else {
|
|
80
|
+
if (typeof body.text !== "string" || !body.text.trim()) throw new Error("Expected nonempty text");
|
|
81
|
+
input = { channelId: body.channelId, participantId: body.participantId, text: body.text };
|
|
82
|
+
}
|
|
74
83
|
} catch (error) {
|
|
75
84
|
return Response.json({ error: String(error) }, { status: 400 });
|
|
76
85
|
}
|
|
77
86
|
const accepted = session.agent.send(input);
|
|
78
|
-
if (!accepted.accepted) return Response.json({ error: accepted.error }, { status: accepted.code === "invalid_input" ? 400 :
|
|
87
|
+
if (!accepted.accepted) return Response.json({ error: accepted.error, code: accepted.code }, { status: accepted.code === "invalid_input" ? 400 : 409 });
|
|
79
88
|
try { return Response.json({ answer: await reply(accepted.itemId) }); }
|
|
80
89
|
catch (error) { return Response.json({ error: String(error) }, { status: 500 }); }
|
|
81
90
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { attachmentView } from "../../contracts/attachments.ts";
|
|
1
2
|
import { timelineMessageId as messageId } from "../../util/timeline-text.ts";
|
|
2
3
|
import { messagePosition } from "../../util/message-position.ts";
|
|
3
4
|
import type { PersistentSession } from "../../contracts/session.ts";
|
|
@@ -66,7 +67,7 @@ export function operatorRead(session: PersistentSession, method: string, p: Reco
|
|
|
66
67
|
const page = readValue(storage.readTimeline({ kind: "replies", channel, turnIds: turns, direction: "newer", throughRevision: revision,
|
|
67
68
|
exclusiveSeq: cursor ? sequence(cursor[4]) : undefined, limit: 50 })).value;
|
|
68
69
|
const items = tracked?.items.map(item => ({ id: item.itemId, channel: item.channelId, kind: item.kind, sender: item.senderId, ...(item.externalSource === undefined ? {} : { externalSource: item.externalSource }),
|
|
69
|
-
milestone: item.milestone, ...(item.policy ? { policy: item.policy } : {}), ...(item.turnId !== undefined ? { turnId: String(item.turnId) } : {}) })) ?? [];
|
|
70
|
+
milestone: item.milestone, ...(item.parts ? { parts: attachmentView(item.parts, storage.readManagedAttachment, { ownerChannel: channel! }) } : {}), ...(item.policy ? { policy: item.policy } : {}), ...(item.turnId !== undefined ? { turnId: String(item.turnId) } : {}) })) ?? [];
|
|
70
71
|
const foundTurns = tracked?.turns.map(turnStatus) ?? [];
|
|
71
72
|
const result = { revision, items, turns: foundTurns, unknownItemIds: inputIds.filter(id => !items.some(item => item.id === id)),
|
|
72
73
|
unknownTurnIds: cursor ? [] : turns.map(String).filter(id => !foundTurns.some(turn => turn.turnId === id)),
|
|
@@ -96,11 +97,16 @@ export function operatorRead(session: PersistentSession, method: string, p: Reco
|
|
|
96
97
|
const base = { channel: entry.channelId, turnId: String(entry.turnId), actor, position: position(entry) };
|
|
97
98
|
const message = entry.message;
|
|
98
99
|
const content = participant && message.role === "user" ? message.content.slice(`Participant: ${JSON.stringify(entry.from)}\n\n`.length) : message.content;
|
|
100
|
+
const parts = participant && message.role === "user" && message.parts ? message.parts.map(part => {
|
|
101
|
+
if (part.type === "text") return part;
|
|
102
|
+
const found = storage.readManagedAttachment ? readValue(storage.readManagedAttachment(part.id)).value : undefined;
|
|
103
|
+
return found?.timelineVisible ? { ...part, metadata: found.metadata } : { ...part, unavailable: true as const };
|
|
104
|
+
}) : [{ type: "text" as const, text: content }];
|
|
99
105
|
const identity = { ...base, messageId: messageId(entry), ...(participant ? { itemId: entry.itemId } : {}) };
|
|
100
106
|
const activity = { ...base, ...(entry.kind === "external_notice" ? { itemId: entry.itemId, externalSource: entry.externalSource } : {}), ...(entry.sourceChannelId ? { sourceChannel: entry.sourceChannelId } : {}),
|
|
101
107
|
kind: entry.kind ?? (message.role === "tool" ? "tool_result" : message.role === "assistant" && !message.content ? "tool_call" : "assistant_message"),
|
|
102
108
|
...(message.role === "assistant" || participant ? { messageId: messageId(entry) } : {}) };
|
|
103
|
-
let record: object = channel ? { ...identity, parts:
|
|
109
|
+
let record: object = channel ? { ...identity, parts } : { ...activity, payload: message.role === "user" && participant && message.parts ? { ...message, parts } : message };
|
|
104
110
|
let bytes = Buffer.byteLength(JSON.stringify(record)) + 1;
|
|
105
111
|
if (bytes > budget) {
|
|
106
112
|
record = channel ? { ...identity, ...(participant ? { omitted: true } : { reference: true }) } : { ...activity, omitted: true,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { attachmentView } from "../../contracts/attachments.ts";
|
|
1
2
|
import { OperatorFault, operatorMethods, operatorRead, readValue } from "./operator.ts";
|
|
2
3
|
import type { ProtocolEndpoint, RpcRequest, RpcResponse, RpcNotification, RpcSessionNotification, ProtocolConfig, Description, Subscription, DurableErrorCode } from "../../contracts/protocol.ts";
|
|
3
4
|
import type { PersistentSession } from "../../contracts/session.ts";
|
|
@@ -17,16 +18,23 @@ import { ToolFault, createCallbackBridge, isToolMethod, toolMethods, toolRequest
|
|
|
17
18
|
|
|
18
19
|
import { parseReminderBatch, parseReminderChange, parseReminderList, ReminderShapeError } from "../../runtime/reminder-validation.ts";
|
|
19
20
|
import { REMINDER_LIMITS } from "../../util/reminder-schedule.ts";
|
|
20
|
-
import type {
|
|
21
|
+
import type { ReminderChange, ReminderChangeResult, ReminderSessionEvent } from "../../contracts/reminders.ts";
|
|
22
|
+
import type { createManagedAttachmentService } from "../../capabilities/attachments/service.ts";
|
|
23
|
+
import { AttachmentServiceError } from "../../capabilities/attachments/service.ts";
|
|
24
|
+
import { UploadError } from "../../capabilities/attachments/upload.ts";
|
|
25
|
+
import { AttachmentReadError } from "../../capabilities/attachments/read.ts";
|
|
26
|
+
import { AttachmentInputError, validateMixedParts } from "../../util/attachment-input.ts";
|
|
27
|
+
import type { InputPart } from "../../contracts/attachments.ts";
|
|
28
|
+
import { ATTACHMENT_LIMITS } from "../../contracts/attachments.ts";
|
|
21
29
|
|
|
22
30
|
class Fault extends Error {
|
|
23
|
-
constructor(readonly tag: string, message: string, readonly rpc = -32602) { super(message); }
|
|
31
|
+
constructor(readonly tag: string, message: string, readonly rpc = -32602, readonly expectedOffset?: number) { super(message); }
|
|
24
32
|
}
|
|
25
33
|
/** Thrown by a session factory to report a typed storage or lifecycle refusal. */
|
|
26
34
|
export class SessionOpenError extends Error {
|
|
27
35
|
constructor(readonly code: DurableErrorCode, message: string) { super(message); }
|
|
28
36
|
}
|
|
29
|
-
export interface SessionRequest { mode: "create" | "open"; sessionId: string; config?: ProtocolConfig;
|
|
37
|
+
export interface SessionRequest { mode: "create" | "open"; sessionId: string; config?: ProtocolConfig; mcpRuntimeHeaders?: unknown;
|
|
30
38
|
/** Decision 0021: a catalog whose shape is valid. The factory checks its names
|
|
31
39
|
* against its built-in tools and passes it to the session. */
|
|
32
40
|
tools?: ToolCatalogInput }
|
|
@@ -39,6 +47,10 @@ export interface OpenedSession {
|
|
|
39
47
|
commitConfig?(): void;
|
|
40
48
|
/** One consistent logical copy, or `busy`. */
|
|
41
49
|
exportArchive?(): StorageResult<SessionArchive>;
|
|
50
|
+
attachments?: ReturnType<typeof createManagedAttachmentService>;
|
|
51
|
+
imageInput?: boolean;
|
|
52
|
+
mcpStatus?(): Record<string, import("../../contracts/mcp.ts").McpServerStatus>;
|
|
53
|
+
stopMcp?(): Promise<void>;
|
|
42
54
|
}
|
|
43
55
|
export interface ProtocolServerOptions {
|
|
44
56
|
durable?: boolean;
|
|
@@ -50,6 +62,9 @@ export interface ProtocolServerOptions {
|
|
|
50
62
|
limits?: Partial<{ chunkBytes: number; maxBytes: number; idleMs: number }>;
|
|
51
63
|
/** Decision 0021: the session factory accepts tool catalogs. */
|
|
52
64
|
functions?: boolean;
|
|
65
|
+
attachments?: boolean;
|
|
66
|
+
mcpStdio?: boolean;
|
|
67
|
+
mcpHttps?: boolean;
|
|
53
68
|
}
|
|
54
69
|
|
|
55
70
|
const bad = (message: string): never => { throw new Fault("invalid_params", message); };
|
|
@@ -71,22 +86,24 @@ function count(value: unknown, fallback: number): number {
|
|
|
71
86
|
}
|
|
72
87
|
/** Capabilities describe this server instance: durable acceptance and load are
|
|
73
88
|
* advertised only when its sessions are opened from durable storage. */
|
|
74
|
-
export function describe(durable: boolean, archives = false, functions = false): Description {
|
|
89
|
+
export function describe(durable: boolean, archives = false, functions = false, attachments = false): Description {
|
|
75
90
|
return {
|
|
76
|
-
|
|
91
|
+
...(attachments ? { attachmentLimits: { fileBytes: ATTACHMENT_LIMITS.fileBytes, chunkBytes: ATTACHMENT_LIMITS.chunkBytes, openUploads: ATTACHMENT_LIMITS.openUploads, uploadIdleMs: ATTACHMENT_LIMITS.uploadIdleMs } } : {}),
|
|
92
|
+
reminderLimits: { ...REMINDER_LIMITS, maxActiveRoutinesPerChannel: 20, maxRoutineCatchUp: 10 },
|
|
77
93
|
configOptions: [], commands: [], policies: [],
|
|
78
|
-
capabilities: { experimental: true, acceptance: durable ? "durable" : "memory", persistence: durable, startupChannelChanges: true, reminders: true, ...(functions ? { functions: true as const } : {}),
|
|
94
|
+
capabilities: { experimental: true, acceptance: durable ? "durable" : "memory", persistence: durable, startupChannelChanges: true, reminders: true, routines: true, unattendedTurnGuard: true, ...(functions ? { functions: true as const } : {}), ...(attachments ? { managedAttachments: true as const, orderedParts: true as const } : {}),
|
|
79
95
|
methods: ["initialize", "config/validate", "session/create", ...(durable ? ["session/open"] : []), ...operatorMethods, "session/status", "reminder/change", "reminder/get", "reminder/list",
|
|
80
96
|
"session/model-calls", "session/message/read", "session/suspend", "session/resume", "session/stop", "channel/push", "channel/notify", "channel/create", "channel/edit", "channel/suspend", "channel/resume", "channel/delete", "channel/withdraw", "channel/interrupt", "approval/respond", "session/idle",
|
|
81
|
-
...(archives ? ["session/export", "session/import", "transfer/open", "transfer/write", "transfer/read", "transfer/close"] : []), ...(functions ? toolMethods() : [])],
|
|
82
|
-
events: ["turn_started", "turn_took", "items_receipt", "text_delta", "text_gap", "text_incomplete", "tool_call", "message_completed", "turn_suspended", "turn_resumed", "turn_ended", "channel_state", "item_withdrawn", "approval_requested", "approval_closed", "reminder_changed", "reminder_fired", "reminder_expired", "reminder_cancelled", "session/event"] },
|
|
97
|
+
...(archives ? ["session/export", "session/import", "transfer/open", "transfer/write", "transfer/read", "transfer/close"] : []), ...(functions ? toolMethods() : []), ...(attachments ? ["attachment/begin", "attachment/write", "attachment/status", "attachment/finalize", "attachment/abort", "attachment/read"] : [])],
|
|
98
|
+
events: ["turn_started", "turn_took", "items_receipt", "text_delta", "text_gap", "text_incomplete", "tool_call", "message_completed", "turn_suspended", "turn_resumed", "turn_ended", "channel_state", "item_withdrawn", "approval_requested", "approval_closed", "reminder_changed", "reminder_fired", "reminder_expired", "reminder_cancelled", "routine_disposition", "routine_migration_blocked", "session/event"] },
|
|
83
99
|
};
|
|
84
100
|
}
|
|
85
101
|
|
|
86
|
-
export function createProtocolServer(open: (request: SessionRequest) => Promise<OpenedSession>, options: ProtocolServerOptions = {}): ProtocolEndpoint & { dispose(): void } {
|
|
102
|
+
export function createProtocolServer(open: (request: SessionRequest) => Promise<OpenedSession>, options: ProtocolServerOptions = {}): ProtocolEndpoint & { dispose(): Promise<void> } {
|
|
87
103
|
const limits = { ...TRANSFER_LIMITS, ...options.limits } as TransferLimits;
|
|
88
104
|
const transfers = options.importArchive && options.transferDirectory ? createTransfers(options.transferDirectory, limits) : undefined;
|
|
89
|
-
const description = describe(!!options.durable, !!transfers, !!options.functions);
|
|
105
|
+
const description = describe(!!options.durable, !!transfers, !!options.functions, !!options.attachments);
|
|
106
|
+
if (options.mcpStdio) description.capabilities.mcpServers = { stdio: true, http: !!options.mcpHttps, sse: false };
|
|
90
107
|
let initialized = false;
|
|
91
108
|
let approvalConsumer = false;
|
|
92
109
|
let opening = false;
|
|
@@ -94,7 +111,7 @@ export function createProtocolServer(open: (request: SessionRequest) => Promise<
|
|
|
94
111
|
// Decision 0020: the batch this connection's open applied, kept so a repeated
|
|
95
112
|
// load reports the same results without applying anything again.
|
|
96
113
|
let startup: { batch: PendingChannelChange[]; results: ChannelChangeResult[] } | undefined;
|
|
97
|
-
let reminderStartup: { batch:
|
|
114
|
+
let reminderStartup: { batch: ReminderChange[]; results: ReminderChangeResult[] } | undefined;
|
|
98
115
|
let activeConfig: ProtocolConfig | undefined;
|
|
99
116
|
let subscription: Subscription = { text: "final", tools: "full" };
|
|
100
117
|
const listeners = new Set<(notification: RpcNotification) => void>();
|
|
@@ -109,7 +126,11 @@ export function createProtocolServer(open: (request: SessionRequest) => Promise<
|
|
|
109
126
|
const catalogOf = (raw: unknown) => {
|
|
110
127
|
if (raw === undefined) return undefined;
|
|
111
128
|
if (!options.functions) bad("This server does not accept tool catalogs");
|
|
112
|
-
try {
|
|
129
|
+
try {
|
|
130
|
+
const parsed = parseCatalog(raw, []);
|
|
131
|
+
if (parsed.catalog.some(tool => tool.name.startsWith("mcp__"))) bad("MCP tool names are reserved");
|
|
132
|
+
return parsed;
|
|
133
|
+
} catch (error) { throw error instanceof CatalogError ? new Fault(error.code, error.message) : error; }
|
|
113
134
|
};
|
|
114
135
|
|
|
115
136
|
async function attach(request: SessionRequest): Promise<OpenedSession> {
|
|
@@ -162,9 +183,9 @@ export function createProtocolServer(open: (request: SessionRequest) => Promise<
|
|
|
162
183
|
}
|
|
163
184
|
/** An open that fails after attaching releases the session. With a batch,
|
|
164
185
|
* stop first: a resume in it may already have handed a turn to an executor. */
|
|
165
|
-
function abandon(opened: OpenedSession, batch: boolean) {
|
|
186
|
+
async function abandon(opened: OpenedSession, batch: boolean) {
|
|
166
187
|
if (batch) { try { opened.session.stop("Open failed"); } catch { /* Storage may be the failure. */ } }
|
|
167
|
-
opened.close();
|
|
188
|
+
try { await opened.stopMcp?.(); } finally { opened.close(); }
|
|
168
189
|
}
|
|
169
190
|
|
|
170
191
|
/** Read one snapshot, then keep every later notification behind the response.
|
|
@@ -175,7 +196,10 @@ export function createProtocolServer(open: (request: SessionRequest) => Promise<
|
|
|
175
196
|
const reads = opened.session.operatorReads;
|
|
176
197
|
if (!reads) throw new Fault("invalid_state", "Focused reads are unavailable");
|
|
177
198
|
const { value, revision } = readValue(reads.readSession());
|
|
178
|
-
|
|
199
|
+
const image = opened.imageInput && (opened.session.reminders?.executable() ?? true)
|
|
200
|
+
? { imageInput: true as const, imageLimits: { formats: ["image/png", "image/jpeg", "image/webp"], fileBytes: ATTACHMENT_LIMITS.fileBytes,
|
|
201
|
+
turnBytes: ATTACHMENT_LIMITS.imageBytesPerTurn, maxImages: ATTACHMENT_LIMITS.references, maxSide: ATTACHMENT_LIMITS.imageSide, maxPixels: ATTACHMENT_LIMITS.imagePixels } } : {};
|
|
202
|
+
return { sessionId: value.sessionId, lifecycle: value.lifecycle, revision, ...image, ...(opened.mcpStatus ? { mcpServers: opened.mcpStatus() } : {}) };
|
|
179
203
|
}
|
|
180
204
|
|
|
181
205
|
function holdAfterResponse(start?: () => void) {
|
|
@@ -188,15 +212,17 @@ export function createProtocolServer(open: (request: SessionRequest) => Promise<
|
|
|
188
212
|
}, 0);
|
|
189
213
|
}
|
|
190
214
|
|
|
191
|
-
function reminderView(session: PersistentSession, results:
|
|
215
|
+
function reminderView(session: PersistentSession, results: ReminderChangeResult[] = []) {
|
|
192
216
|
const reminders = session.reminders;
|
|
193
217
|
if (!reminders) return {};
|
|
194
218
|
const page = readValue(reminders.listReminders({})).value;
|
|
219
|
+
const guard = reminders.executable() ? readValue(reminders.unattendedGuard()).value : undefined;
|
|
195
220
|
return { reminderChanges: results, reminders: page.reminders, ...(page.next ? { remindersNext: page.next } : {}),
|
|
196
|
-
...(reminders.executable() ? readValue(reminders.reminderWake()).value : {})
|
|
221
|
+
...(reminders.executable() ? readValue(reminders.reminderWake()).value : {}),
|
|
222
|
+
...(reminders.executable() ? { unattendedTurnGuard: guard === undefined ? null : { maxConsecutiveTurns: guard } } : {}) };
|
|
197
223
|
}
|
|
198
224
|
|
|
199
|
-
function prepareReminders(session: PersistentSession, batch:
|
|
225
|
+
function prepareReminders(session: PersistentSession, batch: ReminderChange[]) {
|
|
200
226
|
const reminders = session.reminders;
|
|
201
227
|
if (batch.length && !reminders?.executable()) throw new Fault("incompatible", "Reminders cannot change in an inspection-only session");
|
|
202
228
|
const results = batch.map(change => readValue(reminders!.change(change)).value);
|
|
@@ -234,7 +260,7 @@ export function createProtocolServer(open: (request: SessionRequest) => Promise<
|
|
|
234
260
|
return { valid: true };
|
|
235
261
|
}
|
|
236
262
|
if (method === "session/create") {
|
|
237
|
-
keys(p, ["sessionId", "config", "participants", "channels", "channelChanges", "tools", "reminderChanges"]);
|
|
263
|
+
keys(p, ["sessionId", "config", "participants", "channels", "channelChanges", "tools", "reminderChanges", "mcpRuntimeHeaders"]);
|
|
238
264
|
const reminderBatch = parseReminderBatch(p.reminderChanges);
|
|
239
265
|
const tools = catalogOf(p.tools);
|
|
240
266
|
const sessionId = text(p.sessionId);
|
|
@@ -253,7 +279,7 @@ export function createProtocolServer(open: (request: SessionRequest) => Promise<
|
|
|
253
279
|
// effective configuration is known.
|
|
254
280
|
const batch = p.channelChanges === undefined ? undefined : parseChannelChanges(p.channelChanges);
|
|
255
281
|
if (batch && p.config?.policies) checkPolicies(batch, Object.keys(p.config.policies));
|
|
256
|
-
const opened = await attach({ mode: "create", sessionId, config: p.config, ...(tools ? { tools } : {}) });
|
|
282
|
+
const opened = await attach({ mode: "create", sessionId, config: p.config, mcpRuntimeHeaders: p.mcpRuntimeHeaders, ...(tools ? { tools } : {}) });
|
|
257
283
|
let results: ChannelChangeResult[] | undefined;
|
|
258
284
|
let reminderResult: ReturnType<typeof reminderView>;
|
|
259
285
|
try {
|
|
@@ -264,14 +290,14 @@ export function createProtocolServer(open: (request: SessionRequest) => Promise<
|
|
|
264
290
|
reminderResult = prepareReminders(opened.session, reminderBatch);
|
|
265
291
|
current = opened;
|
|
266
292
|
if (batch) startup = { batch, results: results! };
|
|
267
|
-
} catch (error) { abandon(opened, !!batch); throw error; }
|
|
293
|
+
} catch (error) { try { await abandon(opened, !!batch); } catch { /* Preserve startup failure. */ } throw error; }
|
|
268
294
|
finally { opening = false; }
|
|
269
295
|
if (batch?.length || opened.session.reminders) holdAfterResponse(() => { if (current === opened) opened.session.start(); });
|
|
270
296
|
else opened.session.start();
|
|
271
297
|
return { ...(opened.session.operatorReads ? ready(opened) : { sessionId }), ...reminderResult, ...(results ? { channelChanges: results } : {}) };
|
|
272
298
|
}
|
|
273
299
|
if (method === "session/open") {
|
|
274
|
-
keys(p, ["sessionId", "config", "channelChanges", "tools", "reminderChanges"]);
|
|
300
|
+
keys(p, ["sessionId", "config", "channelChanges", "tools", "reminderChanges", "mcpRuntimeHeaders"]);
|
|
275
301
|
const reminderBatch = parseReminderBatch(p.reminderChanges);
|
|
276
302
|
const tools = catalogOf(p.tools);
|
|
277
303
|
const sessionId = text(p.sessionId);
|
|
@@ -280,13 +306,14 @@ export function createProtocolServer(open: (request: SessionRequest) => Promise<
|
|
|
280
306
|
// the batch was applied by the open and is only reported again. A new
|
|
281
307
|
// batch belongs to the live channel API.
|
|
282
308
|
if (current) {
|
|
309
|
+
if (p.mcpRuntimeHeaders !== undefined) bad("Runtime material requires a new executable open");
|
|
283
310
|
if (ready(current).sessionId !== sessionId) throw new Fault("already_exists", "One session per endpoint");
|
|
284
311
|
if (batch && !sameBatch(startup?.batch ?? [], batch)) throw new Fault("invalid_state", "The session is already open; send newer channel changes through the channel methods");
|
|
285
312
|
if (tools && !(startupTools && sameCatalog(startupTools, tools))) throw new Fault("invalid_state", "The session is already open with another tool catalog; use the tool methods");
|
|
286
313
|
if (p.reminderChanges !== undefined && JSON.stringify(reminderBatch) !== JSON.stringify(reminderStartup?.batch ?? [])) throw new Fault("invalid_state", "The session is already open; send changes through reminder/change");
|
|
287
314
|
return { ...ready(current), ...reminderView(current.session, reminderStartup?.results), ...(startup ? { channelChanges: startup.results } : {}) };
|
|
288
315
|
}
|
|
289
|
-
const opened = await attach({ mode: "open", sessionId, config: p.config, ...(tools ? { tools } : {}) });
|
|
316
|
+
const opened = await attach({ mode: "open", sessionId, config: p.config, mcpRuntimeHeaders: p.mcpRuntimeHeaders, ...(tools ? { tools } : {}) });
|
|
290
317
|
try {
|
|
291
318
|
const finish = batch && await prepare(opened, batch);
|
|
292
319
|
// From here to the end of the block nothing is awaited: the resumes, the
|
|
@@ -302,7 +329,7 @@ export function createProtocolServer(open: (request: SessionRequest) => Promise<
|
|
|
302
329
|
return { ...result, ...reminderResult, ...(results ? { channelChanges: results } : {}) };
|
|
303
330
|
}
|
|
304
331
|
// Work was not started; release the session so no partial load is observable.
|
|
305
|
-
catch (error) { abandon(opened, !!batch); throw error; }
|
|
332
|
+
catch (error) { try { await abandon(opened, !!batch); } catch { /* Preserve startup failure. */ } throw error; }
|
|
306
333
|
finally { opening = false; }
|
|
307
334
|
}
|
|
308
335
|
if (transfers && method.startsWith("transfer/")) {
|
|
@@ -321,7 +348,7 @@ export function createProtocolServer(open: (request: SessionRequest) => Promise<
|
|
|
321
348
|
else if (from.type === "transfer") { keys(from, ["type", "transferId"]); bytes = transfers.consume(from.transferId); }
|
|
322
349
|
else return bad("Import source must be a path or a transfer");
|
|
323
350
|
const payload = decodeArchive(bytes, limits.maxBytes) as SessionFilePayload<SessionArchive>;
|
|
324
|
-
if (!payload || typeof payload !== "object" || Array.isArray(payload) || Object.keys(payload).sort().join() !== "archive,config" || ![2, 3, 4, 5, 6].includes(payload.archive?.archiveVersion))
|
|
351
|
+
if (!payload || typeof payload !== "object" || Array.isArray(payload) || Object.keys(payload).sort().join() !== "archive,config" || ![2, 3, 4, 5, 6, 7, 8].includes(payload.archive?.archiveVersion))
|
|
325
352
|
throw new Fault("invalid_archive", "Invalid session file payload");
|
|
326
353
|
try { validateConfig(payload.config, (payload.archive as { archiveVersion: number }).archiveVersion === 2); } catch (error) { throw new Fault("invalid_archive", String(error)); }
|
|
327
354
|
const sessionId = p.sessionId ?? payload.archive?.snapshot?.session?.sessionId;
|
|
@@ -350,6 +377,21 @@ export function createProtocolServer(open: (request: SessionRequest) => Promise<
|
|
|
350
377
|
milestone: result.milestone, ...(result.turnId === undefined ? {} : { turnId: String(result.turnId) }) } };
|
|
351
378
|
}
|
|
352
379
|
if (!current) throw new Fault("not_ready", "Create or load a session first");
|
|
380
|
+
if (method.startsWith("attachment/")) {
|
|
381
|
+
const service = current.attachments;
|
|
382
|
+
if (!service) throw new Fault("incompatible", "Managed attachments are unavailable");
|
|
383
|
+
const channel = text(p.channel);
|
|
384
|
+
if (method === "attachment/begin") {
|
|
385
|
+
keys(p, ["channel", "filename", "mediaType", "bytes", "sha256"]);
|
|
386
|
+
return service.begin({ channel, filename: p.filename, mediaType: text(p.mediaType), bytes: p.bytes, sha256: text(p.sha256) });
|
|
387
|
+
}
|
|
388
|
+
if (method === "attachment/read") { keys(p, ["channel", "id", "offset"]); return service.read(channel, text(p.id), p.offset); }
|
|
389
|
+
const uploadId = text(p.uploadId);
|
|
390
|
+
if (method === "attachment/status") { keys(p, ["channel", "uploadId"]); return service.status(channel, uploadId); }
|
|
391
|
+
if (method === "attachment/write") { keys(p, ["channel", "uploadId", "offset", "data"]); return service.write(channel, uploadId, p.offset, text(p.data)); }
|
|
392
|
+
if (method === "attachment/finalize") { keys(p, ["channel", "uploadId"]); return service.finalize(channel, uploadId); }
|
|
393
|
+
if (method === "attachment/abort") { keys(p, ["channel", "uploadId"]); service.abort(channel, uploadId); return {}; }
|
|
394
|
+
}
|
|
353
395
|
if (transfers && method === "session/export") {
|
|
354
396
|
keys(p, ["to"]);
|
|
355
397
|
const to = obj(p.to);
|
|
@@ -414,7 +456,11 @@ export function createProtocolServer(open: (request: SessionRequest) => Promise<
|
|
|
414
456
|
return { channel: status, ...(method === "channel/create" ? { created: (result.value as { created: boolean }).created } : {}) };
|
|
415
457
|
}
|
|
416
458
|
if (method === "session/idle") { keys(p, []); return { idle: session.agent.idle() && session.status().execution !== "working" }; }
|
|
417
|
-
if (method === "session/status") {
|
|
459
|
+
if (method === "session/status") {
|
|
460
|
+
keys(p, []);
|
|
461
|
+
return { ...wireStatus(session.status(), session.operatorReads ? readValue(session.operatorReads.readExecution()).value : session.snapshot()),
|
|
462
|
+
...(current.mcpStatus ? { mcpServers: current.mcpStatus() } : {}) };
|
|
463
|
+
}
|
|
418
464
|
if (method === "session/suspend" || method === "session/resume") {
|
|
419
465
|
keys(p, []);
|
|
420
466
|
// Suspend answers only once `suspended` is committed, after in-flight
|
|
@@ -443,7 +489,12 @@ export function createProtocolServer(open: (request: SessionRequest) => Promise<
|
|
|
443
489
|
if (!session.reminders) throw new Fault("invalid_state", "Conditional stop is unavailable");
|
|
444
490
|
return session.reminders.conditionalStop(windowMs);
|
|
445
491
|
}
|
|
446
|
-
if (method === "session/stop") {
|
|
492
|
+
if (method === "session/stop") {
|
|
493
|
+
keys(p, []);
|
|
494
|
+
const status = session.stop("Stopped by the host");
|
|
495
|
+
await current.stopMcp?.();
|
|
496
|
+
return wireStatus(status, session.operatorReads ? readValue(session.operatorReads.readExecution()).value : session.snapshot());
|
|
497
|
+
}
|
|
447
498
|
if (method === "session/model-calls") {
|
|
448
499
|
keys(p, ["after", "limit"]);
|
|
449
500
|
const after = p.after === undefined ? undefined : text(p.after);
|
|
@@ -477,18 +528,21 @@ export function createProtocolServer(open: (request: SessionRequest) => Promise<
|
|
|
477
528
|
// One delivery behavior: the two legacy fields are checked, then ignored.
|
|
478
529
|
if (item.kind !== "user_message" || (item.delivery !== undefined && item.delivery !== "queue") || (item.wake !== undefined && item.wake !== true)) bad("Only waking, queued user messages are supported");
|
|
479
530
|
if (!Array.isArray(item.content) || !item.content.length) bad("Expected text parts");
|
|
480
|
-
const
|
|
481
|
-
|
|
531
|
+
const mixed = item.content.some((value: unknown) => !!value && typeof value === "object" && (value as { type?: unknown }).type === "attachment");
|
|
532
|
+
const parts: InputPart[] = mixed ? validateMixedParts(item.content) : item.content.map((value: unknown) => { const part = obj(value); keys(part, ["type", "text"]);
|
|
533
|
+
if (part.type !== "text") bad("Only text parts are supported"); return { type: "text" as const, text: text(part.text) }; });
|
|
482
534
|
// send returns once the item is committed to the inbox (Received) or
|
|
483
535
|
// refused. It never waits for inference; the outcome arrives as events.
|
|
484
536
|
const result = session.agent.send({ channelId: channel, participantId: sender, itemId: id, ...(item.policy == null ? {} : { policy: text(item.policy) }),
|
|
485
|
-
text: parts.
|
|
537
|
+
text: parts.flatMap(part => part.type === "text" ? [part.text] : []).join("\n"), ...(mixed ? { parts } : {}) });
|
|
486
538
|
if (!result.accepted) throw new Fault(result.code === "invalid_input" ? "invalid_params" : result.code, result.error);
|
|
487
|
-
const
|
|
488
|
-
? readValue(session.operatorReads.readTracked(channel, [id], [])).value.items[0]
|
|
489
|
-
: session.snapshot().items.find(value => value.itemId === id)
|
|
539
|
+
const saved = session.operatorReads
|
|
540
|
+
? readValue(session.operatorReads.readTracked(channel, [id], [])).value.items[0]
|
|
541
|
+
: session.snapshot().items.find(value => value.itemId === id);
|
|
542
|
+
const policy = saved?.policy;
|
|
490
543
|
return { accepted: true, duplicate: result.duplicate, item: { id, channel, kind: "participant_message", sender, milestone: result.milestone,
|
|
491
544
|
...(policy === undefined ? {} : { policy }),
|
|
545
|
+
...(saved?.parts ? { parts: attachmentView(saved.parts, session.operatorReads?.readManagedAttachment, { ownerChannel: channel }) } : {}),
|
|
492
546
|
...(result.turnId === undefined ? {} : { turnId: String(result.turnId) }) } };
|
|
493
547
|
}
|
|
494
548
|
return {
|
|
@@ -500,10 +554,12 @@ export function createProtocolServer(open: (request: SessionRequest) => Promise<
|
|
|
500
554
|
return { jsonrpc: "2.0", id: request.id, result };
|
|
501
555
|
} catch (error) {
|
|
502
556
|
const fault = error instanceof FrameLimit ? new Fault("transfer_limit", error.message)
|
|
503
|
-
: error instanceof ReminderShapeError ? new Fault("invalid_params", error.message)
|
|
557
|
+
: error instanceof ReminderShapeError || error instanceof AttachmentInputError ? new Fault(error instanceof AttachmentInputError ? error.code : "invalid_params", error.message)
|
|
558
|
+
: error instanceof UploadError ? new Fault(error.code, error.message, -32602, error.expectedOffset)
|
|
559
|
+
: error instanceof AttachmentReadError || error instanceof AttachmentServiceError ? new Fault(error.code, error.message)
|
|
504
560
|
: error instanceof TransferFault || error instanceof SessionFileError || error instanceof OperatorFault || error instanceof ChannelChangeFault || error instanceof ToolFault ? new Fault(error.code, error.message) : error;
|
|
505
561
|
return { jsonrpc: "2.0", id, error: { code: fault instanceof Fault ? fault.rpc : -32603,
|
|
506
|
-
message: String(fault), data: { code: fault instanceof Fault ? fault.tag : "internal_error" } } };
|
|
562
|
+
message: String(fault), data: { code: fault instanceof Fault ? fault.tag : "internal_error", ...(fault instanceof Fault && fault.expectedOffset !== undefined ? { expectedOffset: fault.expectedOffset } : {}) } } };
|
|
507
563
|
}
|
|
508
564
|
},
|
|
509
565
|
subscribe(listener) { listeners.add(listener); return () => { listeners.delete(listener); }; },
|
|
@@ -512,6 +568,16 @@ export function createProtocolServer(open: (request: SessionRequest) => Promise<
|
|
|
512
568
|
respond(response) { bridge.respond(response); },
|
|
513
569
|
// A connection that is gone serves no handler and answers no callback.
|
|
514
570
|
disconnect() { approvalConsumer = false; current?.session.approvals.disconnect(); current?.session.tools?.serve([]); bridge.disconnect(); },
|
|
515
|
-
dispose() {
|
|
571
|
+
async dispose() {
|
|
572
|
+
const opened = current;
|
|
573
|
+
current = undefined;
|
|
574
|
+
approvalConsumer = false;
|
|
575
|
+
opened?.session.approvals.disconnect();
|
|
576
|
+
bridge.disconnect();
|
|
577
|
+
transfers?.dispose();
|
|
578
|
+
opened?.session.reminders?.releaseTimer();
|
|
579
|
+
if (opened?.stopMcp) await opened.stopMcp();
|
|
580
|
+
opened?.close();
|
|
581
|
+
},
|
|
516
582
|
};
|
|
517
583
|
}
|
|
@@ -28,6 +28,13 @@ function message(value: any): value is RpcResponse | RpcNotification | RpcSessio
|
|
|
28
28
|
if (event.type === "item_withdrawn") return typeof event.item === "string";
|
|
29
29
|
if (event.type === "reminder_changed") return typeof event.reminder?.id === "string" && event.reminder.channel === value.params.channel;
|
|
30
30
|
if (event.type === "reminder_cancelled") return typeof event.reminderId === "string" && ["host", "agent", "channel_retired"].includes(event.by);
|
|
31
|
+
if (event.type === "routine_disposition") return typeof event.reminderId === "string"
|
|
32
|
+
&& typeof event.firstScheduledAt === "string" && typeof event.lastScheduledAt === "string"
|
|
33
|
+
&& Number.isSafeInteger(event.count) && event.count > 0
|
|
34
|
+
&& ["missed", "catch_up_limit", "overlap", "expired", "coalesced"].includes(event.reason);
|
|
35
|
+
if (event.type === "routine_migration_blocked") return typeof event.reminderId === "string"
|
|
36
|
+
&& typeof event.fromVersion === "string" && typeof event.targetVersion === "string"
|
|
37
|
+
&& ["invalid_schedule", "proof_budget"].includes(event.cause);
|
|
31
38
|
if (event.type === "reminder_fired" || event.type === "reminder_expired") {
|
|
32
39
|
return typeof event.reminderId === "string" && typeof event.occurrenceId === "string" && typeof event.scheduledAt === "string"
|
|
33
40
|
&& (event.type === "reminder_fired" ? typeof event.firedAt === "string" && typeof event.noticeId === "string" : typeof event.expiredAt === "string");
|
|
@@ -42,6 +49,7 @@ function message(value: any): value is RpcResponse | RpcNotification | RpcSessio
|
|
|
42
49
|
&& typeof event.toolCallId === "string" && typeof event.tool === "string" && typeof event.arguments === "string";
|
|
43
50
|
case "turn_ended": return ["completed", "failed", "interrupted"].includes(event.outcome)
|
|
44
51
|
&& (event.error === undefined || typeof event.error === "string")
|
|
52
|
+
&& (event.attachmentFailure === undefined || (["unsupported_image", "attachment_unavailable", "transfer_limit"].includes(event.attachmentFailure?.code) && strings(event.attachmentFailure?.attachmentIds)))
|
|
45
53
|
&& (event.uncertainCalls === undefined || strings(event.uncertainCalls));
|
|
46
54
|
case "text_delta": return typeof event.messageId === "string" && typeof event.text === "string";
|
|
47
55
|
case "text_gap": return typeof event.messageId === "string";
|