@openllmsh/sdk 2.10.12-alpha.1 → 2.10.12
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/README.md +27 -7
- package/dist/client/chat.d.ts +38 -0
- package/dist/client/chat.js +77 -0
- package/dist/client/devices.d.ts +70 -0
- package/dist/client/devices.js +172 -0
- package/dist/client/http.d.ts +24 -0
- package/dist/client/http.js +34 -0
- package/dist/client/index.d.ts +43 -0
- package/dist/client/index.js +57 -0
- package/dist/client/relay-mux.d.ts +71 -0
- package/dist/client/relay-mux.js +394 -0
- package/dist/client/types.d.ts +47 -0
- package/dist/client/types.js +5 -0
- package/dist/client/vault.d.ts +68 -0
- package/dist/client/vault.js +113 -0
- package/dist/connect/chat.d.ts +24 -0
- package/dist/connect/chat.js +25 -0
- package/dist/connect/client.d.ts +50 -0
- package/dist/connect/client.js +141 -0
- package/dist/connect/config.d.ts +22 -0
- package/dist/connect/config.js +22 -0
- package/dist/connect/errors.d.ts +32 -0
- package/dist/connect/errors.js +85 -0
- package/{connect/index.ts → dist/connect/index.d.ts} +7 -7
- package/dist/connect/index.js +23 -0
- package/dist/connect/oauth.d.ts +51 -0
- package/dist/connect/oauth.js +150 -0
- package/dist/connect/routes.d.ts +38 -0
- package/dist/connect/routes.js +175 -0
- package/dist/connect/store.d.ts +26 -0
- package/dist/connect/store.js +65 -0
- package/dist/mcp/handle.d.ts +6 -0
- package/dist/mcp/handle.js +6 -0
- package/dist/mcp/index.d.ts +15 -0
- package/dist/mcp/index.js +10 -0
- package/dist/mcp/server.d.ts +84 -0
- package/dist/mcp/server.js +168 -0
- package/dist/mcp/tools/marketplace.d.ts +94 -0
- package/dist/mcp/tools/marketplace.js +303 -0
- package/dist/mcp/tools/memory-client.d.ts +109 -0
- package/dist/mcp/tools/memory-client.js +200 -0
- package/dist/mcp/tools/memory-config.d.ts +29 -0
- package/dist/mcp/tools/memory-config.js +12 -0
- package/dist/mcp/tools/memory.d.ts +92 -0
- package/dist/mcp/tools/memory.js +312 -0
- package/dist/mcp/tools/model-priority.d.ts +16 -0
- package/dist/mcp/tools/model-priority.js +87 -0
- package/dist/mcp/tools/openllm.d.ts +75 -0
- package/dist/mcp/tools/openllm.js +715 -0
- package/dist/mcp/types.d.ts +25 -0
- package/dist/mcp/types.js +7 -0
- package/dist/openapi/call.d.ts +26 -0
- package/dist/openapi/call.js +56 -0
- package/dist/openapi/index.d.ts +2 -0
- package/dist/openapi/index.js +2 -0
- package/dist/openapi/openapi.json +80213 -0
- package/dist/openapi/operations.d.ts +14 -0
- package/dist/openapi/operations.js +2060 -0
- package/dist/protocol/access.d.ts +81 -0
- package/dist/protocol/access.js +125 -0
- package/dist/protocol/agent-prompt-text.d.ts +15 -0
- package/{protocol/agent-prompt-text.ts → dist/protocol/agent-prompt-text.js} +9 -14
- package/dist/protocol/agent.d.ts +1487 -0
- package/dist/protocol/agent.js +787 -0
- package/dist/protocol/api-key-syntax.d.ts +58 -0
- package/dist/protocol/api-key-syntax.js +73 -0
- package/dist/protocol/audio.d.ts +18 -0
- package/dist/protocol/audio.js +21 -0
- package/dist/protocol/auth.d.ts +126 -0
- package/dist/protocol/auth.js +119 -0
- package/dist/protocol/changelog.d.ts +69 -0
- package/dist/protocol/changelog.js +107 -0
- package/dist/protocol/chat.d.ts +789 -0
- package/dist/protocol/chat.js +394 -0
- package/dist/protocol/client-registry.d.ts +151 -0
- package/dist/protocol/client-registry.js +238 -0
- package/dist/protocol/config.d.ts +508 -0
- package/dist/protocol/config.js +289 -0
- package/dist/protocol/control-channel.d.ts +102 -0
- package/{protocol/control-channel.ts → dist/protocol/control-channel.js} +33 -61
- package/dist/protocol/cooldown-reason.d.ts +30 -0
- package/dist/protocol/cooldown-reason.js +44 -0
- package/dist/protocol/cost.d.ts +9 -0
- package/dist/protocol/cost.js +8 -0
- package/dist/protocol/daemon-port.d.ts +2 -0
- package/dist/protocol/daemon-port.js +28 -0
- package/dist/protocol/daemon.d.ts +2034 -0
- package/dist/protocol/daemon.js +1286 -0
- package/dist/protocol/default-chains.d.ts +15 -0
- package/dist/protocol/default-chains.js +21 -0
- package/dist/protocol/device-state.d.ts +223 -0
- package/dist/protocol/device-state.js +52 -0
- package/dist/protocol/doctor-report-local.d.ts +105 -0
- package/{protocol/doctor-report-local.ts → dist/protocol/doctor-report-local.js} +92 -196
- package/dist/protocol/doctor-report-policy.d.ts +62 -0
- package/{protocol/doctor-report-policy.ts → dist/protocol/doctor-report-policy.js} +23 -76
- package/dist/protocol/doctor-report.d.ts +406 -0
- package/dist/protocol/doctor-report.js +645 -0
- package/dist/protocol/errors.d.ts +17 -0
- package/dist/protocol/errors.js +10 -0
- package/dist/protocol/execution-selection.d.ts +92 -0
- package/{protocol/execution-selection.ts → dist/protocol/execution-selection.js} +38 -63
- package/dist/protocol/hop-grant.d.ts +28 -0
- package/{protocol/hop-grant.ts → dist/protocol/hop-grant.js} +7 -13
- package/dist/protocol/image-edit-parse.d.ts +25 -0
- package/dist/protocol/image-edit-parse.js +196 -0
- package/dist/protocol/images.d.ts +288 -0
- package/dist/protocol/images.js +229 -0
- package/dist/protocol/index.d.ts +69 -0
- package/dist/protocol/index.js +74 -0
- package/dist/protocol/inference-headers.d.ts +3 -0
- package/dist/protocol/keepalive.d.ts +36 -0
- package/dist/protocol/keepalive.js +51 -0
- package/dist/protocol/local-auth.d.ts +125 -0
- package/dist/protocol/local-auth.js +227 -0
- package/dist/protocol/local-device-control.d.ts +108 -0
- package/{protocol/local-device-control.ts → dist/protocol/local-device-control.js} +40 -70
- package/dist/protocol/local-provider.d.ts +105 -0
- package/dist/protocol/local-provider.js +213 -0
- package/dist/protocol/local-session.d.ts +70 -0
- package/dist/protocol/local-session.js +87 -0
- package/dist/protocol/marketplace.d.ts +190 -0
- package/dist/protocol/marketplace.js +140 -0
- package/{protocol/media-attempt.ts → dist/protocol/media-attempt.d.ts} +11 -50
- package/dist/protocol/media-attempt.js +50 -0
- package/dist/protocol/media-bytes.d.ts +8 -0
- package/dist/protocol/media-bytes.js +21 -0
- package/dist/protocol/media-default.d.ts +56 -0
- package/dist/protocol/media-default.js +302 -0
- package/{protocol/media-dimensions.ts → dist/protocol/media-dimensions.d.ts} +11 -78
- package/dist/protocol/media-dimensions.js +90 -0
- package/dist/protocol/media-input.d.ts +20 -0
- package/dist/protocol/media-input.js +29 -0
- package/dist/protocol/media-model.d.ts +77 -0
- package/dist/protocol/media-model.js +89 -0
- package/{protocol/media-option-issue.ts → dist/protocol/media-option-issue.d.ts} +25 -53
- package/dist/protocol/media-option-issue.js +50 -0
- package/dist/protocol/media-types.d.ts +14 -0
- package/dist/protocol/media-types.js +61 -0
- package/dist/protocol/model-match.d.ts +254 -0
- package/dist/protocol/model-match.js +760 -0
- package/dist/protocol/model-settings.d.ts +153 -0
- package/dist/protocol/model-settings.js +246 -0
- package/dist/protocol/models.d.ts +1065 -0
- package/dist/protocol/models.js +638 -0
- package/dist/protocol/mux.d.ts +350 -0
- package/dist/protocol/mux.js +595 -0
- package/{protocol/plan-surface.ts → dist/protocol/plan-surface.d.ts} +12 -26
- package/dist/protocol/plan-surface.js +39 -0
- package/dist/protocol/provider-models.d.ts +8 -0
- package/{protocol/provider-models.ts → dist/protocol/provider-models.js} +7 -9
- package/dist/protocol/provider-status.d.ts +59 -0
- package/dist/protocol/provider-status.js +142 -0
- package/dist/protocol/provider-tier.d.ts +34 -0
- package/{protocol/provider-tier.ts → dist/protocol/provider-tier.js} +9 -34
- package/dist/protocol/provider-usage.d.ts +230 -0
- package/dist/protocol/provider-usage.js +214 -0
- package/dist/protocol/providers.d.ts +2496 -0
- package/dist/protocol/providers.js +723 -0
- package/dist/protocol/public-usage-index.d.ts +449 -0
- package/dist/protocol/public-usage-index.js +279 -0
- package/dist/protocol/realtime-generated.d.ts +29 -0
- package/{protocol/realtime-generated.ts → dist/protocol/realtime-generated.js} +3 -5
- package/dist/protocol/realtime.d.ts +241 -0
- package/{protocol/realtime.ts → dist/protocol/realtime.js} +88 -155
- package/dist/protocol/registry-pointer.d.ts +24 -0
- package/dist/protocol/registry-pointer.js +78 -0
- package/dist/protocol/relay.d.ts +1152 -0
- package/{protocol/relay.ts → dist/protocol/relay.js} +237 -370
- package/dist/protocol/replay-session.d.ts +4 -0
- package/{protocol/replay-session.ts → dist/protocol/replay-session.js} +1 -8
- package/dist/protocol/responses.d.ts +303 -0
- package/dist/protocol/responses.js +240 -0
- package/dist/protocol/semver.d.ts +59 -0
- package/dist/protocol/semver.js +171 -0
- package/{protocol/setup-mode.ts → dist/protocol/setup-mode.d.ts} +4 -12
- package/dist/protocol/setup-mode.js +18 -0
- package/dist/protocol/sha256-hex.d.ts +2 -0
- package/dist/protocol/sha256-hex.js +93 -0
- package/dist/protocol/stats.d.ts +711 -0
- package/dist/protocol/stats.js +353 -0
- package/dist/protocol/streaming.d.ts +16 -0
- package/dist/protocol/streaming.js +15 -0
- package/{protocol/subscription-daemon-floors.ts → dist/protocol/subscription-daemon-floors.d.ts} +8 -14
- package/dist/protocol/subscription-daemon-floors.js +4 -0
- package/dist/protocol/subscription-provider-compat.d.ts +44 -0
- package/dist/protocol/subscription-provider-compat.js +67 -0
- package/dist/protocol/subscription-provider.d.ts +15 -0
- package/dist/protocol/subscription-provider.js +17 -0
- package/dist/protocol/team-grant.d.ts +14 -0
- package/{protocol/team-grant.ts → dist/protocol/team-grant.js} +0 -3
- package/dist/protocol/team-shareable.d.ts +6 -0
- package/{protocol/team-shareable.ts → dist/protocol/team-shareable.js} +29 -33
- package/dist/protocol/transcription-encoding.d.ts +25 -0
- package/dist/protocol/transcription-encoding.js +47 -0
- package/{protocol/url-locality-dns.ts → dist/protocol/url-locality-dns.d.ts} +1 -23
- package/dist/protocol/url-locality-dns.js +33 -0
- package/dist/protocol/url-locality.d.ts +45 -0
- package/dist/protocol/url-locality.js +288 -0
- package/dist/protocol/usage-snapshots.d.ts +8 -0
- package/{protocol/usage-snapshots.ts → dist/protocol/usage-snapshots.js} +1 -2
- package/dist/protocol/vendor-cli-install.d.ts +20 -0
- package/{protocol/vendor-cli-install.ts → dist/protocol/vendor-cli-install.js} +10 -15
- package/dist/protocol/video-job-plan.d.ts +18 -0
- package/dist/protocol/video-job-plan.js +44 -0
- package/dist/protocol/videos.d.ts +107 -0
- package/dist/protocol/videos.js +154 -0
- package/dist/tunnel/channel-envelope.d.ts +53 -0
- package/dist/tunnel/channel-envelope.js +100 -0
- package/dist/tunnel/codec.d.ts +71 -0
- package/dist/tunnel/codec.js +151 -0
- package/dist/tunnel/device-anchor.d.ts +62 -0
- package/dist/tunnel/device-anchor.js +168 -0
- package/dist/tunnel/device-control.d.ts +50 -0
- package/dist/tunnel/device-control.js +88 -0
- package/dist/tunnel/device-grant.d.ts +91 -0
- package/dist/tunnel/device-grant.js +105 -0
- package/dist/tunnel/fleet.d.ts +28 -0
- package/dist/tunnel/fleet.js +41 -0
- package/dist/tunnel/index.d.ts +22 -0
- package/dist/tunnel/index.js +22 -0
- package/dist/tunnel/mux.d.ts +64 -0
- package/dist/tunnel/mux.js +449 -0
- package/dist/tunnel/peer-link.d.ts +88 -0
- package/dist/tunnel/peer-link.js +271 -0
- package/dist/tunnel/rtc-auth.d.ts +159 -0
- package/dist/tunnel/rtc-auth.js +340 -0
- package/dist/tunnel/rtc-duplex.d.ts +52 -0
- package/dist/tunnel/rtc-duplex.js +148 -0
- package/dist/tunnel/rtc-ice.d.ts +55 -0
- package/dist/tunnel/rtc-ice.js +100 -0
- package/dist/tunnel/secure.d.ts +179 -0
- package/dist/tunnel/secure.js +936 -0
- package/dist/tunnel/stream-reset-error.d.ts +6 -0
- package/dist/tunnel/stream-reset-error.js +9 -0
- package/dist/tunnel/streams.d.ts +244 -0
- package/dist/tunnel/streams.js +1071 -0
- package/dist/tunnel/team-grant.d.ts +90 -0
- package/dist/tunnel/team-grant.js +226 -0
- package/dist/tunnel/wire-bytes.d.ts +32 -0
- package/dist/tunnel/wire-bytes.js +90 -0
- package/dist/vault/api-key.d.ts +71 -0
- package/dist/vault/api-key.js +130 -0
- package/{vault/argon2.ts → dist/vault/argon2.d.ts} +18 -53
- package/dist/vault/argon2.js +82 -0
- package/dist/vault/cli-auth-seal.d.ts +35 -0
- package/dist/vault/cli-auth-seal.js +78 -0
- package/dist/vault/cred-seal.d.ts +18 -0
- package/dist/vault/cred-seal.js +86 -0
- package/dist/vault/credential.d.ts +21 -0
- package/dist/vault/credential.js +26 -0
- package/dist/vault/crypto.d.ts +51 -0
- package/dist/vault/crypto.js +156 -0
- package/dist/vault/daemon-attest.d.ts +68 -0
- package/dist/vault/daemon-attest.js +147 -0
- package/dist/vault/derive.d.ts +34 -0
- package/dist/vault/derive.js +84 -0
- package/dist/vault/device-access.d.ts +17 -0
- package/dist/vault/device-access.js +77 -0
- package/dist/vault/device-anchor.d.ts +42 -0
- package/dist/vault/device-anchor.js +90 -0
- package/dist/vault/device-control.d.ts +80 -0
- package/{vault/device-control.ts → dist/vault/device-control.js} +46 -104
- package/dist/vault/handoff.d.ts +102 -0
- package/dist/vault/handoff.js +236 -0
- package/dist/vault/index.d.ts +21 -0
- package/dist/vault/index.js +21 -0
- package/dist/vault/passkey.d.ts +82 -0
- package/{vault/passkey.ts → dist/vault/passkey.js} +63 -153
- package/dist/vault/phrase.d.ts +40 -0
- package/{vault/phrase.ts → dist/vault/phrase.js} +17 -23
- package/dist/vault/pin.d.ts +46 -0
- package/dist/vault/pin.js +92 -0
- package/dist/vault/public-key-seal.d.ts +17 -0
- package/dist/vault/public-key-seal.js +59 -0
- package/dist/vault/seed.d.ts +96 -0
- package/dist/vault/seed.js +179 -0
- package/dist/vault/team.d.ts +134 -0
- package/dist/vault/team.js +217 -0
- package/dist/vault/vault-item.d.ts +45 -0
- package/dist/vault/vault-item.js +62 -0
- package/dist/vault/vault-migrate-digest.d.ts +10 -0
- package/dist/vault/vault-migrate-digest.js +22 -0
- package/dist/vault/wrapped.d.ts +19 -0
- package/dist/vault/wrapped.js +52 -0
- package/dist/wire/adapters/messages/anthropic-map.d.ts +8 -0
- package/dist/wire/adapters/messages/anthropic-map.js +32 -0
- package/dist/wire/adapters/messages/index.d.ts +7 -0
- package/dist/wire/adapters/messages/index.js +7 -0
- package/dist/wire/adapters/messages/reasoning-from-items.d.ts +14 -0
- package/dist/wire/adapters/messages/reasoning-from-items.js +39 -0
- package/dist/wire/adapters/messages/reasoning-signature.d.ts +81 -0
- package/dist/wire/adapters/messages/reasoning-signature.js +180 -0
- package/dist/wire/adapters/messages/request.d.ts +28 -0
- package/dist/wire/adapters/messages/request.js +490 -0
- package/dist/wire/adapters/messages/response.d.ts +10 -0
- package/dist/wire/adapters/messages/response.js +177 -0
- package/dist/wire/adapters/messages/streaming.d.ts +134 -0
- package/dist/wire/adapters/messages/streaming.js +791 -0
- package/dist/wire/adapters/messages/usage.d.ts +20 -0
- package/dist/wire/adapters/messages/usage.js +10 -0
- package/dist/wire/adapters/responses/index.d.ts +3 -0
- package/dist/wire/adapters/responses/index.js +3 -0
- package/dist/wire/adapters/responses/request.d.ts +2 -0
- package/dist/wire/adapters/responses/request.js +287 -0
- package/dist/wire/adapters/responses/response.d.ts +11 -0
- package/dist/wire/adapters/responses/response.js +69 -0
- package/dist/wire/adapters/responses/streaming.d.ts +2 -0
- package/dist/wire/adapters/responses/streaming.js +267 -0
- package/dist/wire/features/account-rank.d.ts +61 -0
- package/dist/wire/features/account-rank.js +109 -0
- package/dist/wire/features/compaction/compact-request.d.ts +69 -0
- package/dist/wire/features/compaction/compact-request.js +667 -0
- package/dist/wire/features/compaction/compaction-text.d.ts +17 -0
- package/dist/wire/features/compaction/compaction-text.js +29 -0
- package/dist/wire/features/context-demote.d.ts +15 -0
- package/dist/wire/features/context-demote.js +45 -0
- package/dist/wire/features/context-overflow-strategy.d.ts +12 -0
- package/dist/wire/features/context-overflow-strategy.js +8 -0
- package/dist/wire/features/context-skip.d.ts +120 -0
- package/{wire/features/context-skip.ts → dist/wire/features/context-skip.js} +23 -57
- package/dist/wire/features/conversation-affinity.d.ts +49 -0
- package/dist/wire/features/conversation-affinity.js +121 -0
- package/dist/wire/features/max-tokens-backfill.d.ts +50 -0
- package/dist/wire/features/max-tokens-backfill.js +118 -0
- package/dist/wire/features/model-caps.d.ts +7 -0
- package/dist/wire/features/model-caps.js +40 -0
- package/dist/wire/features/model-settings.d.ts +3 -0
- package/dist/wire/features/model-settings.js +13 -0
- package/dist/wire/features/output-limit-clamp.d.ts +14 -0
- package/dist/wire/features/output-limit-clamp.js +36 -0
- package/dist/wire/features/quota-gate.d.ts +16 -0
- package/dist/wire/features/quota-gate.js +48 -0
- package/dist/wire/index.d.ts +44 -0
- package/dist/wire/index.js +44 -0
- package/dist/wire/lib/attempt-outcome.d.ts +19 -0
- package/dist/wire/lib/attempt-outcome.js +18 -0
- package/{wire/lib/canonical/content-part.ts → dist/wire/lib/canonical/content-part.d.ts} +12 -18
- package/dist/wire/lib/canonical/content-part.js +11 -0
- package/dist/wire/lib/canonical/count-tokens-capability.d.ts +52 -0
- package/dist/wire/lib/canonical/count-tokens-capability.js +109 -0
- package/{wire/lib/canonical/encoding-select.ts → dist/wire/lib/canonical/encoding-select.d.ts} +7 -24
- package/dist/wire/lib/canonical/encoding-select.js +26 -0
- package/dist/wire/lib/canonical/image-signature.d.ts +20 -0
- package/dist/wire/lib/canonical/image-signature.js +184 -0
- package/dist/wire/lib/canonical/image-sse.d.ts +88 -0
- package/dist/wire/lib/canonical/image-sse.js +173 -0
- package/{wire/lib/canonical/message.ts → dist/wire/lib/canonical/message.d.ts} +2 -20
- package/dist/wire/lib/canonical/message.js +31 -0
- package/dist/wire/lib/canonical/token-estimate.d.ts +98 -0
- package/dist/wire/lib/canonical/token-estimate.js +230 -0
- package/dist/wire/lib/encrypted-content.d.ts +22 -0
- package/dist/wire/lib/encrypted-content.js +55 -0
- package/dist/wire/lib/error-class.d.ts +57 -0
- package/dist/wire/lib/error-class.js +97 -0
- package/dist/wire/lib/error-envelope.d.ts +20 -0
- package/dist/wire/lib/error-envelope.js +53 -0
- package/dist/wire/lib/forwarded-headers.d.ts +16 -0
- package/{wire/lib/forwarded-headers.ts → dist/wire/lib/forwarded-headers.js} +62 -72
- package/dist/wire/lib/provider-error-rules.d.ts +21 -0
- package/dist/wire/lib/provider-error-rules.js +20 -0
- package/{wire/lib/refusal.ts → dist/wire/lib/refusal.d.ts} +3 -13
- package/dist/wire/lib/refusal.js +27 -0
- package/dist/wire/lib/responses-apply-patch.d.ts +57 -0
- package/dist/wire/lib/responses-apply-patch.js +81 -0
- package/dist/wire/lib/responses-namespace.d.ts +27 -0
- package/{wire/lib/responses-namespace.ts → dist/wire/lib/responses-namespace.js} +16 -32
- package/dist/wire/lib/secret-scrub.d.ts +23 -0
- package/dist/wire/lib/secret-scrub.js +72 -0
- package/dist/wire/lib/streaming/accumulate.d.ts +12 -0
- package/dist/wire/lib/streaming/accumulate.js +187 -0
- package/dist/wire/lib/streaming/finish-reason.d.ts +20 -0
- package/dist/wire/lib/streaming/finish-reason.js +15 -0
- package/{wire/lib/streaming/peek.ts → dist/wire/lib/streaming/peek.d.ts} +13 -82
- package/dist/wire/lib/streaming/peek.js +100 -0
- package/dist/wire/lib/streaming/provider-decode.d.ts +57 -0
- package/dist/wire/lib/streaming/provider-decode.js +210 -0
- package/dist/wire/lib/streaming/response-stream.d.ts +16 -0
- package/dist/wire/lib/streaming/response-stream.js +64 -0
- package/dist/wire/lib/streaming/sse.d.ts +130 -0
- package/dist/wire/lib/streaming/sse.js +600 -0
- package/dist/wire/lib/streaming/strip-tool-calls.d.ts +14 -0
- package/dist/wire/lib/streaming/strip-tool-calls.js +75 -0
- package/dist/wire/lib/streaming/upstream-error.d.ts +32 -0
- package/dist/wire/lib/streaming/upstream-error.js +45 -0
- package/dist/wire/lib/strip-subagent-isolation.d.ts +16 -0
- package/dist/wire/lib/strip-subagent-isolation.js +240 -0
- package/dist/wire/lib/thinking-signature.d.ts +56 -0
- package/{wire/lib/thinking-signature.ts → dist/wire/lib/thinking-signature.js} +77 -84
- package/dist/wire/lib/token-ruler/bpe-core.d.ts +105 -0
- package/dist/wire/lib/token-ruler/bpe-core.js +398 -0
- package/dist/wire/lib/token-ruler/index.d.ts +2 -0
- package/dist/wire/lib/token-ruler/index.js +2 -0
- package/dist/wire/lib/token-ruler/ruler.d.ts +36 -0
- package/dist/wire/lib/token-ruler/ruler.js +50 -0
- package/dist/wire/lib/token-ruler/vocab/claude-ranks.d.ts +14 -0
- package/dist/wire/lib/token-ruler/vocab/claude-ranks.js +16 -0
- package/{wire/lib/token-ruler/vocab/claude.ts → dist/wire/lib/token-ruler/vocab/claude.d.ts} +2 -12
- package/dist/wire/lib/token-ruler/vocab/claude.js +8 -0
- package/dist/wire/lib/token-ruler/vocab/o200k-ranks.d.ts +3 -0
- package/dist/wire/lib/token-ruler/vocab/o200k-ranks.js +18 -0
- package/dist/wire/lib/token-ruler/vocab/o200k.d.ts +11 -0
- package/dist/wire/lib/token-ruler/vocab/o200k.js +6 -0
- package/dist/wire/lib/tool-name-map.d.ts +44 -0
- package/dist/wire/lib/tool-name-map.js +186 -0
- package/dist/wire/lib/tool-schema.d.ts +15 -0
- package/dist/wire/lib/tool-schema.js +307 -0
- package/dist/wire/lib/usage-observer.d.ts +9 -0
- package/dist/wire/lib/usage-observer.js +108 -0
- package/dist/wire/providers/anthropic/adaptive-thinking.d.ts +125 -0
- package/dist/wire/providers/anthropic/adaptive-thinking.js +221 -0
- package/dist/wire/providers/anthropic/beta-headers.d.ts +44 -0
- package/{wire/providers/anthropic/beta-headers.ts → dist/wire/providers/anthropic/beta-headers.js} +57 -79
- package/dist/wire/providers/anthropic/index.d.ts +6 -0
- package/{wire/providers/anthropic/index.ts → dist/wire/providers/anthropic/index.js} +6 -6
- package/dist/wire/providers/anthropic/request.d.ts +12 -0
- package/dist/wire/providers/anthropic/request.js +456 -0
- package/dist/wire/providers/anthropic/response.d.ts +3 -0
- package/dist/wire/providers/anthropic/response.js +126 -0
- package/dist/wire/providers/anthropic/streaming.d.ts +28 -0
- package/dist/wire/providers/anthropic/streaming.js +268 -0
- package/dist/wire/providers/anthropic/web-search-domains.d.ts +7 -0
- package/dist/wire/providers/anthropic/web-search-domains.js +36 -0
- package/dist/wire/providers/chatgpt/common.d.ts +27 -0
- package/{wire/providers/chatgpt/common.ts → dist/wire/providers/chatgpt/common.js} +69 -89
- package/dist/wire/providers/chatgpt/index.d.ts +4 -0
- package/{wire/providers/chatgpt/index.ts → dist/wire/providers/chatgpt/index.js} +4 -4
- package/dist/wire/providers/chatgpt/request.d.ts +132 -0
- package/dist/wire/providers/chatgpt/request.js +696 -0
- package/dist/wire/providers/chatgpt/streaming.d.ts +69 -0
- package/dist/wire/providers/chatgpt/streaming.js +761 -0
- package/dist/wire/providers/chatgpt/web-search.d.ts +19 -0
- package/dist/wire/providers/chatgpt/web-search.js +55 -0
- package/dist/wire/providers/grok/web-search.d.ts +23 -0
- package/dist/wire/providers/grok/web-search.js +74 -0
- package/dist/wire/providers/kimi/web-search.d.ts +48 -0
- package/dist/wire/providers/kimi/web-search.js +106 -0
- package/dist/wire/providers/upstream-deny.d.ts +61 -0
- package/dist/wire/providers/upstream-deny.js +293 -0
- package/dist/wire/providers/upstream-request.d.ts +104 -0
- package/dist/wire/providers/upstream-request.js +411 -0
- package/package.json +105 -23
- package/ARCHITECTURE.md +0 -43
- package/client/chat.ts +0 -140
- package/client/devices.ts +0 -269
- package/client/http.ts +0 -72
- package/client/index.ts +0 -129
- package/client/relay-mux.ts +0 -547
- package/client/types.ts +0 -51
- package/client/vault.ts +0 -239
- package/connect/chat.ts +0 -58
- package/connect/client.ts +0 -240
- package/connect/config.ts +0 -47
- package/connect/errors.ts +0 -121
- package/connect/oauth.ts +0 -265
- package/connect/routes.ts +0 -234
- package/connect/store.ts +0 -107
- package/mcp/handle.ts +0 -24
- package/mcp/index.ts +0 -76
- package/mcp/server.ts +0 -319
- package/mcp/tools/marketplace.ts +0 -439
- package/mcp/tools/memory-client.ts +0 -297
- package/mcp/tools/memory-config.ts +0 -32
- package/mcp/tools/memory.ts +0 -369
- package/mcp/tools/model-priority.ts +0 -88
- package/mcp/tools/openllm.ts +0 -883
- package/mcp/types.ts +0 -28
- package/openapi/call.ts +0 -90
- package/openapi/index.ts +0 -8
- package/openapi/openapi.json +0 -80213
- package/openapi/operations.ts +0 -2075
- package/protocol/CONTRIBUTING.md +0 -21
- package/protocol/README.md +0 -134
- package/protocol/access.ts +0 -186
- package/protocol/agent.ts +0 -991
- package/protocol/api-key-syntax.ts +0 -105
- package/protocol/assets/openllm-light.svg +0 -18
- package/protocol/assets/openllm.svg +0 -18
- package/protocol/audio.ts +0 -29
- package/protocol/auth.ts +0 -142
- package/protocol/changelog.ts +0 -155
- package/protocol/chat.ts +0 -458
- package/protocol/client-registry.ts +0 -356
- package/protocol/config.ts +0 -345
- package/protocol/cooldown-reason.ts +0 -78
- package/protocol/cost.ts +0 -10
- package/protocol/daemon-port.ts +0 -31
- package/protocol/daemon.ts +0 -1524
- package/protocol/default-chains.ts +0 -66
- package/protocol/device-state.ts +0 -85
- package/protocol/doctor-report.ts +0 -947
- package/protocol/errors.ts +0 -14
- package/protocol/image-edit-parse.ts +0 -263
- package/protocol/images.ts +0 -298
- package/protocol/index.ts +0 -74
- package/protocol/keepalive.ts +0 -69
- package/protocol/local-auth.ts +0 -300
- package/protocol/local-provider.ts +0 -288
- package/protocol/local-session.ts +0 -118
- package/protocol/marketplace.ts +0 -187
- package/protocol/media-bytes.ts +0 -28
- package/protocol/media-default.ts +0 -357
- package/protocol/media-input.ts +0 -61
- package/protocol/media-model.ts +0 -142
- package/protocol/media-types.ts +0 -70
- package/protocol/model-match.ts +0 -1051
- package/protocol/model-settings.ts +0 -327
- package/protocol/models.ts +0 -767
- package/protocol/mux.ts +0 -722
- package/protocol/provider-status.ts +0 -206
- package/protocol/provider-usage.ts +0 -263
- package/protocol/providers.ts +0 -901
- package/protocol/public-usage-index.ts +0 -354
- package/protocol/registry-pointer.ts +0 -118
- package/protocol/responses.ts +0 -280
- package/protocol/semver.ts +0 -182
- package/protocol/sha256-hex.ts +0 -98
- package/protocol/stats.ts +0 -406
- package/protocol/streaming.ts +0 -19
- package/protocol/subscription-provider-compat.ts +0 -104
- package/protocol/subscription-provider.ts +0 -32
- package/protocol/transcription-encoding.ts +0 -76
- package/protocol/url-locality.ts +0 -288
- package/protocol/video-job-plan.ts +0 -50
- package/protocol/videos.ts +0 -227
- package/tsconfig.json +0 -14
- package/tunnel/ARCHITECTURE.md +0 -111
- package/tunnel/assets/openllm-light.svg +0 -18
- package/tunnel/assets/openllm.svg +0 -18
- package/tunnel/channel-envelope.ts +0 -139
- package/tunnel/codec.ts +0 -191
- package/tunnel/device-anchor.ts +0 -229
- package/tunnel/device-control.ts +0 -118
- package/tunnel/device-grant.ts +0 -173
- package/tunnel/fleet.ts +0 -77
- package/tunnel/index.ts +0 -22
- package/tunnel/mux.ts +0 -580
- package/tunnel/peer-link.ts +0 -390
- package/tunnel/rtc-auth.ts +0 -415
- package/tunnel/rtc-duplex.ts +0 -187
- package/tunnel/rtc-ice.ts +0 -136
- package/tunnel/secure.ts +0 -1298
- package/tunnel/stream-reset-error.ts +0 -14
- package/tunnel/streams.ts +0 -1430
- package/tunnel/team-grant.ts +0 -302
- package/tunnel/wire-bytes.ts +0 -102
- package/vault/ARCHITECTURE.md +0 -470
- package/vault/api-key.ts +0 -190
- package/vault/cli-auth-seal.ts +0 -157
- package/vault/cred-seal.ts +0 -146
- package/vault/credential.ts +0 -55
- package/vault/crypto.ts +0 -210
- package/vault/daemon-attest.ts +0 -229
- package/vault/derive.ts +0 -113
- package/vault/device-access.ts +0 -87
- package/vault/device-anchor.ts +0 -185
- package/vault/handoff.ts +0 -396
- package/vault/index.ts +0 -21
- package/vault/pin.ts +0 -153
- package/vault/public-key-seal.ts +0 -131
- package/vault/seed.ts +0 -272
- package/vault/team.ts +0 -355
- package/vault/vault-item.ts +0 -131
- package/vault/vault-migrate-digest.ts +0 -29
- package/vault/wrapped.ts +0 -77
- package/wire/ARCHITECTURE.md +0 -90
- package/wire/CONTRIBUTING.md +0 -19
- package/wire/adapters/messages/anthropic-map.ts +0 -37
- package/wire/adapters/messages/index.ts +0 -7
- package/wire/adapters/messages/reasoning-from-items.ts +0 -38
- package/wire/adapters/messages/reasoning-signature.ts +0 -243
- package/wire/adapters/messages/request.ts +0 -574
- package/wire/adapters/messages/response.ts +0 -215
- package/wire/adapters/messages/streaming.ts +0 -1027
- package/wire/adapters/messages/usage.ts +0 -43
- package/wire/adapters/responses/index.ts +0 -3
- package/wire/adapters/responses/request.ts +0 -395
- package/wire/adapters/responses/response.ts +0 -88
- package/wire/adapters/responses/streaming.ts +0 -344
- package/wire/assets/openllm-light.svg +0 -18
- package/wire/assets/openllm.svg +0 -18
- package/wire/features/account-rank.ts +0 -166
- package/wire/features/compaction/compact-request.ts +0 -862
- package/wire/features/compaction/compaction-text.ts +0 -43
- package/wire/features/context-demote.ts +0 -47
- package/wire/features/context-overflow-strategy.ts +0 -26
- package/wire/features/conversation-affinity.ts +0 -144
- package/wire/features/max-tokens-backfill.ts +0 -141
- package/wire/features/model-caps.ts +0 -53
- package/wire/features/model-settings.ts +0 -24
- package/wire/features/output-limit-clamp.ts +0 -64
- package/wire/features/quota-gate.ts +0 -85
- package/wire/index.ts +0 -44
- package/wire/lib/attempt-outcome.ts +0 -43
- package/wire/lib/canonical/count-tokens-capability.ts +0 -138
- package/wire/lib/canonical/image-signature.ts +0 -202
- package/wire/lib/canonical/image-sse.ts +0 -216
- package/wire/lib/canonical/token-estimate.ts +0 -266
- package/wire/lib/encrypted-content.ts +0 -66
- package/wire/lib/error-class.ts +0 -154
- package/wire/lib/error-envelope.ts +0 -56
- package/wire/lib/provider-error-rules.ts +0 -48
- package/wire/lib/responses-apply-patch.ts +0 -104
- package/wire/lib/secret-scrub.ts +0 -101
- package/wire/lib/streaming/accumulate.ts +0 -221
- package/wire/lib/streaming/finish-reason.ts +0 -33
- package/wire/lib/streaming/provider-decode.ts +0 -259
- package/wire/lib/streaming/response-stream.ts +0 -71
- package/wire/lib/streaming/sse.ts +0 -699
- package/wire/lib/streaming/strip-tool-calls.ts +0 -95
- package/wire/lib/streaming/upstream-error.ts +0 -58
- package/wire/lib/strip-subagent-isolation.ts +0 -284
- package/wire/lib/token-ruler/bpe-core.ts +0 -426
- package/wire/lib/token-ruler/index.ts +0 -2
- package/wire/lib/token-ruler/ruler.ts +0 -79
- package/wire/lib/token-ruler/vocab/claude-ranks.ts +0 -16
- package/wire/lib/token-ruler/vocab/o200k-ranks.ts +0 -18
- package/wire/lib/token-ruler/vocab/o200k.ts +0 -19
- package/wire/lib/tool-name-map.ts +0 -271
- package/wire/lib/tool-schema.ts +0 -353
- package/wire/lib/usage-observer.ts +0 -125
- package/wire/providers/anthropic/adaptive-thinking.ts +0 -291
- package/wire/providers/anthropic/request.ts +0 -607
- package/wire/providers/anthropic/response.ts +0 -155
- package/wire/providers/anthropic/streaming.ts +0 -315
- package/wire/providers/anthropic/web-search-domains.ts +0 -49
- package/wire/providers/chatgpt/request.ts +0 -959
- package/wire/providers/chatgpt/streaming.ts +0 -1007
- package/wire/providers/chatgpt/web-search.ts +0 -63
- package/wire/providers/grok/web-search.ts +0 -87
- package/wire/providers/kimi/web-search.ts +0 -145
- package/wire/providers/upstream-deny.ts +0 -355
- package/wire/providers/upstream-request.ts +0 -619
- /package/{protocol/inference-headers.ts → dist/protocol/inference-headers.js} +0 -0
|
@@ -0,0 +1,787 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent session protocol — the structured replacement for remote PTY
|
|
3
|
+
* mirroring (docs/plan/2026-10-23-agent-sessions-replace-remote-pty.md).
|
|
4
|
+
*
|
|
5
|
+
* A consumer opens a mux stream with {@link AgentStreamOpenPayload}
|
|
6
|
+
* (`kind:"agent"`, seed-gated on the daemon) or reaches the daemon's loopback
|
|
7
|
+
* agent endpoint, then exchanges NDJSON lines over the flow-controlled DATA
|
|
8
|
+
* channel:
|
|
9
|
+
*
|
|
10
|
+
* consumer → daemon : {@link AgentCommand} (start / attach / send /
|
|
11
|
+
* interrupt / respond / close / attachment_get /
|
|
12
|
+
* set_model / delete_session / history_get)
|
|
13
|
+
* daemon → consumer : {@link AgentEvent} (session / turn / item / content /
|
|
14
|
+
* request / user-input / token-usage / runtime /
|
|
15
|
+
* attachment.data / history.page)
|
|
16
|
+
*
|
|
17
|
+
* History is paged (after t3code's windowed thread detail): an attach replays
|
|
18
|
+
* only the LATEST window of the session, ending on a turn boundary, then a
|
|
19
|
+
* {@link AgentHistoryPageEvent} names the opaque cursor before that window.
|
|
20
|
+
* `history_get{before}` returns the adjacent, strictly older page.
|
|
21
|
+
*
|
|
22
|
+
* The event families are a trimmed subset of t3code's `ProviderRuntimeEvent`:
|
|
23
|
+
* no multi-CLI orchestration, no event-sourcing / checkpoint / git tooling, no
|
|
24
|
+
* terminal drawer, no realtime-audio, account or MCP-OAuth events. Every
|
|
25
|
+
* engine adapter on the daemon emits this one stream, so the UI renders one
|
|
26
|
+
* vocabulary whichever engine runs the session.
|
|
27
|
+
*
|
|
28
|
+
* Forward compatibility: an event whose `type` this build does not know
|
|
29
|
+
* decodes to `null` and is dropped by consumers. Commands are validated
|
|
30
|
+
* strictly by the serving daemon.
|
|
31
|
+
*/
|
|
32
|
+
import { Schema as S } from "effect";
|
|
33
|
+
import * as Result from "effect/Result";
|
|
34
|
+
import { SESSION_ID_PATTERN } from "./local-session.js";
|
|
35
|
+
/**
|
|
36
|
+
* Capability advertising `kind:"agent"` stream support. Consumers MUST check
|
|
37
|
+
* {@link hasAgentCap} before OPEN; a peer without it gets "update your device".
|
|
38
|
+
*/
|
|
39
|
+
export const AGENT_CAP = "agent1";
|
|
40
|
+
/** Returns whether an open-vocabulary capability list advertises agent sessions. */
|
|
41
|
+
export const hasAgentCap = (caps) => caps?.includes(AGENT_CAP) ?? false;
|
|
42
|
+
/**
|
|
43
|
+
* Bound on ONE NDJSON agent line (JSON-encoded UTF-8 bytes, including the
|
|
44
|
+
* trailing `\n`). Larger than the realtime bound because a `send` command may
|
|
45
|
+
* carry inline attachments; a line (or unterminated remainder) over the bound
|
|
46
|
+
* is an overflow, never a growing buffer.
|
|
47
|
+
*/
|
|
48
|
+
export const AGENT_MAX_LINE_BYTES = 8 * 1024 * 1024;
|
|
49
|
+
const lineEncoder = new TextEncoder();
|
|
50
|
+
/** Max characters of one prompt. */
|
|
51
|
+
export const AGENT_MAX_PROMPT_LENGTH = 1024 * 1024;
|
|
52
|
+
/**
|
|
53
|
+
* Daemon loopback route Claude's hooks post to (`openllm exec agent hook`):
|
|
54
|
+
* busy/idle and PermissionRequest for agent sessions. Admitted like the other
|
|
55
|
+
* `/local/*` routes (loopback peer + Host, local control capability).
|
|
56
|
+
* Body: `{session_id, event, payload}`; reply: `{output}` (the hook's stdout
|
|
57
|
+
* JSON) or `{}` for no output.
|
|
58
|
+
*/
|
|
59
|
+
export const AGENT_HOOK_LOCAL_PATH = "/local/agent-hook";
|
|
60
|
+
/**
|
|
61
|
+
* Claude hook events `openllm exec agent hook` forwards. `SessionStart` is the
|
|
62
|
+
* engine's readiness signal: Claude runs it once the TUI is up (after any
|
|
63
|
+
* folder-trust dialog), so a queued web prompt is pasted only then.
|
|
64
|
+
*/
|
|
65
|
+
export const AGENT_HOOK_EVENTS = [
|
|
66
|
+
"PermissionRequest",
|
|
67
|
+
"PreToolUse",
|
|
68
|
+
"Stop",
|
|
69
|
+
"SessionStart",
|
|
70
|
+
];
|
|
71
|
+
/** Max inline attachments on one `send`. */
|
|
72
|
+
export const AGENT_MAX_ATTACHMENTS = 8;
|
|
73
|
+
/** Max base64 characters of one inline attachment. */
|
|
74
|
+
export const AGENT_MAX_ATTACHMENT_BASE64_LENGTH = 6 * 1024 * 1024;
|
|
75
|
+
/**
|
|
76
|
+
* Engines an agent session can run. Each id is the `openllm <client>` the
|
|
77
|
+
* daemon launches the engine through (same overlay, gateway URL, key, model
|
|
78
|
+
* mapping), so a session's inference is routed through openllm whatever
|
|
79
|
+
* model the user picked.
|
|
80
|
+
*/
|
|
81
|
+
export const AgentEngine = S.Literals(["claude", "codex"]);
|
|
82
|
+
/**
|
|
83
|
+
* Agent session id: daemon-minted (a UUID), the consumer's own record id, or
|
|
84
|
+
* a vendor session id for attach/resume (Claude / Codex ids are UUIDs). The
|
|
85
|
+
* id names the session host's registry dir and its attachments dir, so it is
|
|
86
|
+
* the local session id itself: url-safe, no `.`, so never `.` / `..`.
|
|
87
|
+
*/
|
|
88
|
+
export const AGENT_SESSION_ID_PATTERN = SESSION_ID_PATTERN;
|
|
89
|
+
export const AgentSessionId = S.String.check(S.isPattern(AGENT_SESSION_ID_PATTERN));
|
|
90
|
+
/** Opaque daemon-minted id for turns, items, and requests. */
|
|
91
|
+
const AgentRefId = S.String.check(S.isMinLength(1), S.isMaxLength(128));
|
|
92
|
+
/** Optional consumer-minted command id, echoed on correlated events. */
|
|
93
|
+
const AgentCommandId = S.String.check(S.isMinLength(1), S.isMaxLength(64));
|
|
94
|
+
const AgentModel = S.String.check(S.isMinLength(1), S.isMaxLength(256));
|
|
95
|
+
/** Absolute directory; the daemon validates it exists before starting. */
|
|
96
|
+
const AgentCwd = S.String.check(S.isMinLength(1), S.isMaxLength(1024));
|
|
97
|
+
/**
|
|
98
|
+
* Length caps (UTF-16 code units, as `String.length`) of an event's short
|
|
99
|
+
* label fields (titles, messages, option labels), its detail text, and a tool
|
|
100
|
+
* call's `tool_name`. An event over one fails to decode and consumers drop it,
|
|
101
|
+
* so builders clip to these.
|
|
102
|
+
*/
|
|
103
|
+
export const AGENT_SHORT_TEXT_MAX_LENGTH = 256;
|
|
104
|
+
export const AGENT_DETAIL_TEXT_MAX_LENGTH = 16 * 1024;
|
|
105
|
+
export const AGENT_TOOL_NAME_MAX_LENGTH = 128;
|
|
106
|
+
const ShortText = S.String.check(S.isMaxLength(AGENT_SHORT_TEXT_MAX_LENGTH));
|
|
107
|
+
const DetailText = S.String.check(S.isMaxLength(AGENT_DETAIL_TEXT_MAX_LENGTH));
|
|
108
|
+
// ---------------------------------------------------------------------------
|
|
109
|
+
// Stream OPEN
|
|
110
|
+
// ---------------------------------------------------------------------------
|
|
111
|
+
/**
|
|
112
|
+
* Mux `kind:"agent"` OPEN payload — folded into `StreamOpenPayload` in
|
|
113
|
+
* `./mux`. Carries nothing but the kind: the session itself is driven by
|
|
114
|
+
* {@link AgentCommand} lines on the stream, so one OPEN shape serves start,
|
|
115
|
+
* attach and resume.
|
|
116
|
+
*/
|
|
117
|
+
export const AgentStreamOpenPayload = S.Struct({
|
|
118
|
+
kind: S.Literal("agent"),
|
|
119
|
+
});
|
|
120
|
+
// ---------------------------------------------------------------------------
|
|
121
|
+
// Commands (consumer → daemon)
|
|
122
|
+
// ---------------------------------------------------------------------------
|
|
123
|
+
export const AgentAttachment = S.Struct({
|
|
124
|
+
kind: S.Literals(["image", "file"]),
|
|
125
|
+
name: S.optional(S.String.check(S.isMinLength(1), S.isMaxLength(256))),
|
|
126
|
+
media_type: S.String.check(S.isMinLength(1), S.isMaxLength(128)),
|
|
127
|
+
/** Base64 bytes. */
|
|
128
|
+
data: S.String.check(S.isMaxLength(AGENT_MAX_ATTACHMENT_BASE64_LENGTH)),
|
|
129
|
+
});
|
|
130
|
+
/**
|
|
131
|
+
* Metadata for an attachment that was saved on the device for a turn. The
|
|
132
|
+
* `name` is the on-disk basename under the session's attachments dir (what
|
|
133
|
+
* {@link AgentAttachmentGetCommand} looks up) — not the original upload name
|
|
134
|
+
* when they differ. Optional on `turn.started` so terminal prompts and older
|
|
135
|
+
* daemons stay compatible.
|
|
136
|
+
*/
|
|
137
|
+
export const AgentAttachmentMeta = S.Struct({
|
|
138
|
+
name: S.String.check(S.isMinLength(1), S.isMaxLength(256)),
|
|
139
|
+
mime: S.String.check(S.isMinLength(1), S.isMaxLength(128)),
|
|
140
|
+
size: S.Number.check(S.isInt(), S.isGreaterThanOrEqualTo(0)),
|
|
141
|
+
});
|
|
142
|
+
/** Decoded-byte cap mirroring {@link AGENT_MAX_ATTACHMENT_BASE64_LENGTH}. */
|
|
143
|
+
export const AGENT_MAX_ATTACHMENT_BYTES = Math.floor((AGENT_MAX_ATTACHMENT_BASE64_LENGTH * 3) / 4);
|
|
144
|
+
/** Decision on an approval request (`request.opened`). */
|
|
145
|
+
export const AgentRequestDecision = S.Literals([
|
|
146
|
+
"accept",
|
|
147
|
+
"accept_for_session",
|
|
148
|
+
"decline",
|
|
149
|
+
"cancel",
|
|
150
|
+
]);
|
|
151
|
+
/** Answers to a `user-input.requested`, keyed by question id. */
|
|
152
|
+
export const AgentUserInputAnswers = S.Record(S.String.check(S.isMinLength(1), S.isMaxLength(128)), S.Union([
|
|
153
|
+
S.String.check(S.isMaxLength(16 * 1024)),
|
|
154
|
+
S.Array(S.String.check(S.isMaxLength(1024))).check(S.isMaxLength(64)),
|
|
155
|
+
]));
|
|
156
|
+
export const AgentStartCommand = S.Struct({
|
|
157
|
+
type: S.Literal("start"),
|
|
158
|
+
id: S.optional(AgentCommandId),
|
|
159
|
+
engine: AgentEngine,
|
|
160
|
+
/** Gateway model id; omitted → the engine's openllm default. */
|
|
161
|
+
model: S.optional(AgentModel),
|
|
162
|
+
/** Omitted → the daemon user's home directory. */
|
|
163
|
+
cwd: S.optional(AgentCwd),
|
|
164
|
+
/**
|
|
165
|
+
* Per-session opt-in to the engine's skip-permissions mode
|
|
166
|
+
* (`--dangerously-skip-permissions` or the vendor equivalent). Default off:
|
|
167
|
+
* approvals surface as `request.opened` events.
|
|
168
|
+
*/
|
|
169
|
+
skip_permissions: S.optional(S.Boolean),
|
|
170
|
+
title: S.optional(S.String.check(S.isMaxLength(80))),
|
|
171
|
+
/**
|
|
172
|
+
* The id the new session takes (the consumer's own record id, e.g. the web's
|
|
173
|
+
* cloud session row). Omitted → the daemon mints one. One id end to end (the
|
|
174
|
+
* cloud row, the session host, Claude's transcript) is what lets a reload
|
|
175
|
+
* re-attach and a running row match the daemon's status.
|
|
176
|
+
*/
|
|
177
|
+
session_id: S.optional(AgentSessionId),
|
|
178
|
+
});
|
|
179
|
+
export const AgentAttachCommand = S.Struct({
|
|
180
|
+
type: S.Literal("attach"),
|
|
181
|
+
id: S.optional(AgentCommandId),
|
|
182
|
+
session_id: AgentSessionId,
|
|
183
|
+
/** Engine of the target session when the consumer knows it (local index). */
|
|
184
|
+
engine: S.optional(AgentEngine),
|
|
185
|
+
/**
|
|
186
|
+
* The session was started with skip-permissions: a resume (the session is
|
|
187
|
+
* not running) relaunches the engine the same way. Ignored when joining a
|
|
188
|
+
* live session, which keeps the mode it runs in.
|
|
189
|
+
*/
|
|
190
|
+
skip_permissions: S.optional(S.Boolean),
|
|
191
|
+
});
|
|
192
|
+
export const AgentSendCommand = S.Struct({
|
|
193
|
+
type: S.Literal("send"),
|
|
194
|
+
id: S.optional(AgentCommandId),
|
|
195
|
+
prompt: S.String.check(S.isMaxLength(AGENT_MAX_PROMPT_LENGTH)),
|
|
196
|
+
attachments: S.optional(S.Array(AgentAttachment).check(S.isMaxLength(AGENT_MAX_ATTACHMENTS))),
|
|
197
|
+
}).check(S.makeFilter((command) => lineEncoder.encode(`${JSON.stringify(command)}\n`).byteLength <=
|
|
198
|
+
AGENT_MAX_LINE_BYTES, { message: "send command exceeds the agent line size bound" }));
|
|
199
|
+
/**
|
|
200
|
+
* Deliver the queued prompts NOW instead of after the running turn. Plain,
|
|
201
|
+
* they join the running turn at its next tool boundary and running tools
|
|
202
|
+
* finish. With `interrupt`, the engine's own send-now (Claude Code's
|
|
203
|
+
* ctrl+enter) runs: running shells move to the background and tools that
|
|
204
|
+
* can't (an MCP call) are stopped — consumers ask the user before setting it.
|
|
205
|
+
* A daemon that predates it rejects the line; consumers offer it only after
|
|
206
|
+
* a `queue.updated` showed the daemon queues.
|
|
207
|
+
*/
|
|
208
|
+
export const AgentSendNowCommand = S.Struct({
|
|
209
|
+
type: S.Literal("send_now"),
|
|
210
|
+
id: S.optional(AgentCommandId),
|
|
211
|
+
interrupt: S.optional(S.Boolean),
|
|
212
|
+
});
|
|
213
|
+
/** Resume a queue that an interrupt deliberately paused. */
|
|
214
|
+
export const AgentResumeQueueCommand = S.Struct({
|
|
215
|
+
type: S.Literal("resume_queue"),
|
|
216
|
+
id: S.optional(AgentCommandId),
|
|
217
|
+
});
|
|
218
|
+
/** Remove one queued prompt without affecting the active turn. */
|
|
219
|
+
export const AgentCancelQueuedCommand = S.Struct({
|
|
220
|
+
type: S.Literal("cancel_queued"),
|
|
221
|
+
id: S.optional(AgentCommandId),
|
|
222
|
+
queue_id: AgentRefId,
|
|
223
|
+
});
|
|
224
|
+
export const AgentInterruptCommand = S.Struct({
|
|
225
|
+
type: S.Literal("interrupt"),
|
|
226
|
+
id: S.optional(AgentCommandId),
|
|
227
|
+
/** Omitted → the active turn. */
|
|
228
|
+
turn_id: S.optional(AgentRefId),
|
|
229
|
+
});
|
|
230
|
+
/**
|
|
231
|
+
* Answer a pending approval (`decision`) or user-input request (`answers`).
|
|
232
|
+
* Exactly one of the two is present.
|
|
233
|
+
*/
|
|
234
|
+
export const AgentRespondCommand = S.Struct({
|
|
235
|
+
type: S.Literal("respond"),
|
|
236
|
+
id: S.optional(AgentCommandId),
|
|
237
|
+
request_id: AgentRefId,
|
|
238
|
+
decision: S.optional(AgentRequestDecision),
|
|
239
|
+
answers: S.optional(AgentUserInputAnswers),
|
|
240
|
+
}).check(S.makeFilter((command) => (command.decision === undefined) !== (command.answers === undefined), {
|
|
241
|
+
message: "respond carries exactly one of decision / answers",
|
|
242
|
+
}));
|
|
243
|
+
export const AgentCloseCommand = S.Struct({
|
|
244
|
+
type: S.Literal("close"),
|
|
245
|
+
id: S.optional(AgentCommandId),
|
|
246
|
+
});
|
|
247
|
+
/**
|
|
248
|
+
* Fetch one attachment from the current session's on-device attachments dir.
|
|
249
|
+
* `name` is the basename recorded on `turn.started.attachments` (no path
|
|
250
|
+
* separators). The daemon refuses traversal / absolute / symlink-escape names
|
|
251
|
+
* and streams the bytes back as one or more {@link AgentAttachmentDataEvent}
|
|
252
|
+
* lines under the same `command_id`.
|
|
253
|
+
*/
|
|
254
|
+
export const AgentAttachmentGetCommand = S.Struct({
|
|
255
|
+
type: S.Literal("attachment_get"),
|
|
256
|
+
id: S.optional(AgentCommandId),
|
|
257
|
+
name: S.String.check(S.isMinLength(1), S.isMaxLength(256)),
|
|
258
|
+
});
|
|
259
|
+
/**
|
|
260
|
+
* A model id a running session can switch to: gateway ids and Claude aliases
|
|
261
|
+
* (`ultra`, `sonnet`, `openai/gpt-5`, `claude-opus-4-5[1m]`). No whitespace or
|
|
262
|
+
* control characters: it is typed into the engine's own `/model` command.
|
|
263
|
+
*/
|
|
264
|
+
export const AGENT_SWITCH_MODEL_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._:/@[\]-]{0,255}$/;
|
|
265
|
+
/**
|
|
266
|
+
* Switch the running session's model (Claude: its own `/model <id>`, applied
|
|
267
|
+
* when the session is idle, queued while a turn runs). Confirmed by a
|
|
268
|
+
* `session.configured` event once the engine reports the change.
|
|
269
|
+
*/
|
|
270
|
+
export const AgentSetModelCommand = S.Struct({
|
|
271
|
+
type: S.Literal("set_model"),
|
|
272
|
+
id: S.optional(AgentCommandId),
|
|
273
|
+
model: S.String.check(S.isPattern(AGENT_SWITCH_MODEL_PATTERN)),
|
|
274
|
+
});
|
|
275
|
+
/**
|
|
276
|
+
* Delete one session from this device: stop its process if it runs (here or
|
|
277
|
+
* in a terminal), then remove its attachments, Claude's transcript
|
|
278
|
+
* (`~/.claude/projects/<slug of its cwd>/<id>.jsonl`) and its lines in
|
|
279
|
+
* `~/.claude/history.jsonl`. Stream-level (needs no bound session). Answered
|
|
280
|
+
* by `session.deleted`, or a `runtime.error`. `close` is the non-destructive
|
|
281
|
+
* Stop: it kills the process and keeps the history.
|
|
282
|
+
*/
|
|
283
|
+
export const AgentDeleteSessionCommand = S.Struct({
|
|
284
|
+
type: S.Literal("delete_session"),
|
|
285
|
+
id: S.optional(AgentCommandId),
|
|
286
|
+
session_id: AgentSessionId,
|
|
287
|
+
});
|
|
288
|
+
/** Turns one `history_get` page holds at most. */
|
|
289
|
+
export const AGENT_HISTORY_MAX_PAGE_TURNS = 100;
|
|
290
|
+
/** Events one `history.page` carries at most. */
|
|
291
|
+
export const AGENT_HISTORY_MAX_PAGE_EVENTS = 4_000;
|
|
292
|
+
/** Opaque daemon-minted history cursor (consumers never parse it). */
|
|
293
|
+
const AgentHistoryCursor = S.String.check(S.isMinLength(1), S.isMaxLength(128));
|
|
294
|
+
/**
|
|
295
|
+
* Older history of the bound session: the turns strictly before `before`
|
|
296
|
+
* (a cursor from an earlier `history.page`), newest `limit` of them. Answered
|
|
297
|
+
* by one `history.page` carrying the events, under the same `command_id`.
|
|
298
|
+
*/
|
|
299
|
+
export const AgentHistoryGetCommand = S.Struct({
|
|
300
|
+
type: S.Literal("history_get"),
|
|
301
|
+
id: S.optional(AgentCommandId),
|
|
302
|
+
before: AgentHistoryCursor,
|
|
303
|
+
limit: S.optional(S.Number.check(S.isInt(), S.isGreaterThan(0), S.isLessThanOrEqualTo(AGENT_HISTORY_MAX_PAGE_TURNS))),
|
|
304
|
+
});
|
|
305
|
+
/** One consumer → daemon command line. */
|
|
306
|
+
export const AgentCommand = S.Union([
|
|
307
|
+
AgentStartCommand,
|
|
308
|
+
AgentAttachCommand,
|
|
309
|
+
AgentSendCommand,
|
|
310
|
+
AgentSendNowCommand,
|
|
311
|
+
AgentResumeQueueCommand,
|
|
312
|
+
AgentCancelQueuedCommand,
|
|
313
|
+
AgentInterruptCommand,
|
|
314
|
+
AgentRespondCommand,
|
|
315
|
+
AgentCloseCommand,
|
|
316
|
+
AgentAttachmentGetCommand,
|
|
317
|
+
AgentSetModelCommand,
|
|
318
|
+
AgentDeleteSessionCommand,
|
|
319
|
+
AgentHistoryGetCommand,
|
|
320
|
+
]);
|
|
321
|
+
// ---------------------------------------------------------------------------
|
|
322
|
+
// Events (daemon → consumer)
|
|
323
|
+
// ---------------------------------------------------------------------------
|
|
324
|
+
/** Fields every event may carry. */
|
|
325
|
+
const eventBase = {
|
|
326
|
+
/** The session this event belongs to (absent only before one exists). */
|
|
327
|
+
session_id: S.optional(AgentSessionId),
|
|
328
|
+
/** Daemon-assigned ordinal, monotonically increasing per session. */
|
|
329
|
+
seq: S.optional(S.Number.check(S.isInt(), S.isGreaterThanOrEqualTo(0))),
|
|
330
|
+
/** Epoch milliseconds on the daemon. */
|
|
331
|
+
at: S.optional(S.Number.check(S.isGreaterThanOrEqualTo(0))),
|
|
332
|
+
/** Echo of the {@link AgentCommand} `id` this event answers, if any. */
|
|
333
|
+
command_id: S.optional(AgentCommandId),
|
|
334
|
+
};
|
|
335
|
+
const TokenCount = S.Number.check(S.isInt(), S.isGreaterThanOrEqualTo(0));
|
|
336
|
+
export const AgentTokenUsage = S.Struct({
|
|
337
|
+
input_tokens: TokenCount,
|
|
338
|
+
output_tokens: TokenCount,
|
|
339
|
+
cached_input_tokens: S.optional(TokenCount),
|
|
340
|
+
reasoning_tokens: S.optional(TokenCount),
|
|
341
|
+
total_tokens: S.optional(TokenCount),
|
|
342
|
+
/** The model's context window, when known, for a fill gauge. */
|
|
343
|
+
context_window: S.optional(TokenCount),
|
|
344
|
+
});
|
|
345
|
+
export const AgentSessionExitReason = S.Literals([
|
|
346
|
+
"closed",
|
|
347
|
+
"completed",
|
|
348
|
+
"killed",
|
|
349
|
+
"error",
|
|
350
|
+
]);
|
|
351
|
+
export const AgentSessionStartedEvent = S.Struct({
|
|
352
|
+
...eventBase,
|
|
353
|
+
type: S.Literal("session.started"),
|
|
354
|
+
session_id: AgentSessionId,
|
|
355
|
+
engine: AgentEngine,
|
|
356
|
+
model: S.optional(AgentModel),
|
|
357
|
+
cwd: S.optional(AgentCwd),
|
|
358
|
+
/** True when this is an attach/resume of an existing engine session. */
|
|
359
|
+
resumed: S.optional(S.Boolean),
|
|
360
|
+
skip_permissions: S.optional(S.Boolean),
|
|
361
|
+
});
|
|
362
|
+
/**
|
|
363
|
+
* The engine began a new conversation in the same live TUI (for example,
|
|
364
|
+
* Claude Code's `/new`). The consumer must discard the prior transcript; the
|
|
365
|
+
* daemon also starts its replay buffer over so a later attach stays clean.
|
|
366
|
+
*/
|
|
367
|
+
export const AgentSessionResetEvent = S.Struct({
|
|
368
|
+
...eventBase,
|
|
369
|
+
type: S.Literal("session.reset"),
|
|
370
|
+
});
|
|
371
|
+
/**
|
|
372
|
+
* The session's configuration changed (today: its model), from whichever side
|
|
373
|
+
* changed it (a web `set_model`, or `/model` typed in the terminal). Read from
|
|
374
|
+
* the engine's own record, so every viewer converges on the same value.
|
|
375
|
+
*/
|
|
376
|
+
export const AgentSessionConfiguredEvent = S.Struct({
|
|
377
|
+
...eventBase,
|
|
378
|
+
type: S.Literal("session.configured"),
|
|
379
|
+
model: S.optional(AgentModel),
|
|
380
|
+
/**
|
|
381
|
+
* The conversation's title, from the engine's own record (Claude's
|
|
382
|
+
* `ai-title`). Optional: older daemons omit it, older consumers ignore it.
|
|
383
|
+
*/
|
|
384
|
+
title: S.optional(ShortText),
|
|
385
|
+
});
|
|
386
|
+
export const AgentSessionExitedEvent = S.Struct({
|
|
387
|
+
...eventBase,
|
|
388
|
+
type: S.Literal("session.exited"),
|
|
389
|
+
session_id: AgentSessionId,
|
|
390
|
+
reason: AgentSessionExitReason,
|
|
391
|
+
message: S.optional(ShortText),
|
|
392
|
+
});
|
|
393
|
+
export const AgentTurnStartedEvent = S.Struct({
|
|
394
|
+
...eventBase,
|
|
395
|
+
type: S.Literal("turn.started"),
|
|
396
|
+
turn_id: AgentRefId,
|
|
397
|
+
model: S.optional(AgentModel),
|
|
398
|
+
/**
|
|
399
|
+
* The prompt text that opened the turn. Lets a consumer that attaches later
|
|
400
|
+
* (replay) render the user's side of the transcript. Optional: older daemons
|
|
401
|
+
* omit it and older consumers ignore it.
|
|
402
|
+
*/
|
|
403
|
+
prompt: S.optional(S.String.check(S.isMaxLength(AGENT_MAX_PROMPT_LENGTH))),
|
|
404
|
+
/**
|
|
405
|
+
* Attachments saved for this turn (on-disk basename + mime + size). Optional:
|
|
406
|
+
* terminal prompts and older daemons omit it; older consumers ignore it.
|
|
407
|
+
*/
|
|
408
|
+
attachments: S.optional(S.Array(AgentAttachmentMeta).check(S.isMaxLength(AGENT_MAX_ATTACHMENTS))),
|
|
409
|
+
});
|
|
410
|
+
/** Most prompts a session holds behind its running turn. */
|
|
411
|
+
export const AGENT_MAX_QUEUED_PROMPTS = 16;
|
|
412
|
+
/**
|
|
413
|
+
* The prompts waiting behind the running turn, oldest first — the whole
|
|
414
|
+
* queue, so the latest event is the state. A `send` that lands mid-turn is
|
|
415
|
+
* queued on the daemon and goes out as the turn ends (or on `send_now`).
|
|
416
|
+
* Older consumers ignore it.
|
|
417
|
+
*/
|
|
418
|
+
export const AgentQueuedPrompt = S.Struct({
|
|
419
|
+
/** Stable while the prompt is queued; used for a targeted cancel. */
|
|
420
|
+
id: AgentRefId,
|
|
421
|
+
/** Clipped preview, never the complete prompt. */
|
|
422
|
+
prompt: ShortText,
|
|
423
|
+
attachment_count: S.Number.check(S.isInt(), S.isGreaterThanOrEqualTo(0), S.isLessThanOrEqualTo(AGENT_MAX_ATTACHMENTS)),
|
|
424
|
+
});
|
|
425
|
+
export const AgentQueueUpdatedEvent = S.Struct({
|
|
426
|
+
...eventBase,
|
|
427
|
+
type: S.Literal("queue.updated"),
|
|
428
|
+
/**
|
|
429
|
+
* Identified entries, oldest first. `string[]` remains valid on the browser
|
|
430
|
+
* boundary for daemons predating this protocol shape.
|
|
431
|
+
*/
|
|
432
|
+
prompts: S.Array(S.Union([AgentQueuedPrompt, ShortText])).check(S.isMaxLength(AGENT_MAX_QUEUED_PROMPTS)),
|
|
433
|
+
/** An interrupt pauses automatic draining until `resume_queue`. */
|
|
434
|
+
held: S.optional(S.Boolean),
|
|
435
|
+
});
|
|
436
|
+
export const AgentTurnCompletedEvent = S.Struct({
|
|
437
|
+
...eventBase,
|
|
438
|
+
type: S.Literal("turn.completed"),
|
|
439
|
+
turn_id: AgentRefId,
|
|
440
|
+
stop_reason: S.optional(S.String.check(S.isMaxLength(64))),
|
|
441
|
+
/**
|
|
442
|
+
* What the turn cost, from the engine's own record: `input_tokens` is the
|
|
443
|
+
* context the turn's last request carried, `output_tokens` the sum the turn
|
|
444
|
+
* generated. Optional: older daemons omit it, older consumers ignore it.
|
|
445
|
+
*/
|
|
446
|
+
usage: S.optional(AgentTokenUsage),
|
|
447
|
+
});
|
|
448
|
+
export const AgentTurnAbortedEvent = S.Struct({
|
|
449
|
+
...eventBase,
|
|
450
|
+
type: S.Literal("turn.aborted"),
|
|
451
|
+
turn_id: AgentRefId,
|
|
452
|
+
reason: S.Literals(["interrupted", "failed", "cancelled"]),
|
|
453
|
+
message: S.optional(ShortText),
|
|
454
|
+
});
|
|
455
|
+
export const AgentToolStatus = S.Literals([
|
|
456
|
+
"in_progress",
|
|
457
|
+
"completed",
|
|
458
|
+
"failed",
|
|
459
|
+
]);
|
|
460
|
+
export const AgentNoticeKind = S.Literals([
|
|
461
|
+
"compacted",
|
|
462
|
+
"interrupted",
|
|
463
|
+
"model_changed",
|
|
464
|
+
"error",
|
|
465
|
+
/** A background subagent reported completion (`ref_item_id` is its call). */
|
|
466
|
+
"subagent_finished",
|
|
467
|
+
]);
|
|
468
|
+
/** The renderable unit of a turn. */
|
|
469
|
+
export const AgentItem = S.Union([
|
|
470
|
+
S.Struct({
|
|
471
|
+
kind: S.Literal("assistant_message"),
|
|
472
|
+
text: S.String,
|
|
473
|
+
}),
|
|
474
|
+
S.Struct({
|
|
475
|
+
kind: S.Literal("reasoning"),
|
|
476
|
+
text: S.String,
|
|
477
|
+
}),
|
|
478
|
+
S.Struct({
|
|
479
|
+
kind: S.Literal("tool_call"),
|
|
480
|
+
tool_name: S.String.check(S.isMinLength(1), S.isMaxLength(AGENT_TOOL_NAME_MAX_LENGTH)),
|
|
481
|
+
title: S.optional(ShortText),
|
|
482
|
+
/** The tool's input as the engine reported it (JSON). */
|
|
483
|
+
input: S.optional(S.Unknown),
|
|
484
|
+
status: AgentToolStatus,
|
|
485
|
+
/** Result text, truncated by the daemon to fit one line. */
|
|
486
|
+
output: S.optional(S.String),
|
|
487
|
+
is_error: S.optional(S.Boolean),
|
|
488
|
+
/** The user (or a policy) refused the call; optional, additive. */
|
|
489
|
+
denied: S.optional(S.Boolean),
|
|
490
|
+
/** Wall time from call to result, when the engine recorded both. */
|
|
491
|
+
duration_ms: S.optional(S.Number.check(S.isInt(), S.isGreaterThanOrEqualTo(0))),
|
|
492
|
+
/** A shell command's exit status, when the engine reported it. */
|
|
493
|
+
exit_code: S.optional(S.Number.check(S.isInt())),
|
|
494
|
+
/**
|
|
495
|
+
* A subagent launched in the background: the call's own result is only
|
|
496
|
+
* the launch ack, so it stays in progress past its turn until the
|
|
497
|
+
* subagent finishes. Optional, additive.
|
|
498
|
+
*/
|
|
499
|
+
background: S.optional(S.Boolean),
|
|
500
|
+
}),
|
|
501
|
+
/**
|
|
502
|
+
* A marker in the conversation that is neither speech nor a tool: context
|
|
503
|
+
* compacted, a turn interrupted, the model switched, an engine error. Older
|
|
504
|
+
* consumers drop the whole event (unknown kind), which loses only the line.
|
|
505
|
+
*/
|
|
506
|
+
S.Struct({
|
|
507
|
+
kind: S.Literal("notice"),
|
|
508
|
+
notice: AgentNoticeKind,
|
|
509
|
+
text: S.optional(DetailText),
|
|
510
|
+
/** The item the notice is about (a subagent's call). Optional, additive. */
|
|
511
|
+
ref_item_id: S.optional(AgentRefId),
|
|
512
|
+
}),
|
|
513
|
+
]);
|
|
514
|
+
/** `item.updated` carries the item's full current state, not a diff. */
|
|
515
|
+
const itemEventFields = {
|
|
516
|
+
...eventBase,
|
|
517
|
+
turn_id: S.optional(AgentRefId),
|
|
518
|
+
item_id: AgentRefId,
|
|
519
|
+
item: AgentItem,
|
|
520
|
+
/**
|
|
521
|
+
* The tool call (a Task / Agent subagent) this item belongs to: a
|
|
522
|
+
* subagent's own text and tool calls nest under the call that spawned it.
|
|
523
|
+
* Absent → a top-level item of the turn. Older consumers ignore it.
|
|
524
|
+
*/
|
|
525
|
+
parent_item_id: S.optional(AgentRefId),
|
|
526
|
+
};
|
|
527
|
+
export const AgentItemStartedEvent = S.Struct({
|
|
528
|
+
...itemEventFields,
|
|
529
|
+
type: S.Literal("item.started"),
|
|
530
|
+
});
|
|
531
|
+
export const AgentItemUpdatedEvent = S.Struct({
|
|
532
|
+
...itemEventFields,
|
|
533
|
+
type: S.Literal("item.updated"),
|
|
534
|
+
});
|
|
535
|
+
export const AgentItemCompletedEvent = S.Struct({
|
|
536
|
+
...itemEventFields,
|
|
537
|
+
type: S.Literal("item.completed"),
|
|
538
|
+
});
|
|
539
|
+
export const AgentContentStream = S.Literals([
|
|
540
|
+
"assistant_text",
|
|
541
|
+
"reasoning_text",
|
|
542
|
+
"tool_output",
|
|
543
|
+
]);
|
|
544
|
+
export const AgentContentDeltaEvent = S.Struct({
|
|
545
|
+
...eventBase,
|
|
546
|
+
type: S.Literal("content.delta"),
|
|
547
|
+
turn_id: S.optional(AgentRefId),
|
|
548
|
+
item_id: AgentRefId,
|
|
549
|
+
stream: AgentContentStream,
|
|
550
|
+
delta: S.String,
|
|
551
|
+
});
|
|
552
|
+
/** What an approval request asks permission for. */
|
|
553
|
+
export const AgentRequestKind = S.Literals([
|
|
554
|
+
"command",
|
|
555
|
+
"file_change",
|
|
556
|
+
"tool",
|
|
557
|
+
"other",
|
|
558
|
+
]);
|
|
559
|
+
export const AgentRequestOpenedEvent = S.Struct({
|
|
560
|
+
...eventBase,
|
|
561
|
+
type: S.Literal("request.opened"),
|
|
562
|
+
request_id: AgentRefId,
|
|
563
|
+
turn_id: S.optional(AgentRefId),
|
|
564
|
+
item_id: S.optional(AgentRefId),
|
|
565
|
+
request_kind: AgentRequestKind,
|
|
566
|
+
title: S.optional(ShortText),
|
|
567
|
+
detail: S.optional(DetailText),
|
|
568
|
+
input: S.optional(S.Unknown),
|
|
569
|
+
});
|
|
570
|
+
export const AgentRequestResolvedEvent = S.Struct({
|
|
571
|
+
...eventBase,
|
|
572
|
+
type: S.Literal("request.resolved"),
|
|
573
|
+
request_id: AgentRefId,
|
|
574
|
+
decision: AgentRequestDecision,
|
|
575
|
+
});
|
|
576
|
+
export const AgentUserInputQuestion = S.Struct({
|
|
577
|
+
id: S.String.check(S.isMinLength(1), S.isMaxLength(128)),
|
|
578
|
+
header: S.optional(ShortText),
|
|
579
|
+
question: DetailText,
|
|
580
|
+
options: S.optional(S.Array(S.Struct({
|
|
581
|
+
label: ShortText,
|
|
582
|
+
description: S.optional(S.String.check(S.isMaxLength(1024))),
|
|
583
|
+
})).check(S.isMaxLength(64))),
|
|
584
|
+
multi_select: S.optional(S.Boolean),
|
|
585
|
+
});
|
|
586
|
+
export const AgentUserInputRequestedEvent = S.Struct({
|
|
587
|
+
...eventBase,
|
|
588
|
+
type: S.Literal("user-input.requested"),
|
|
589
|
+
request_id: AgentRefId,
|
|
590
|
+
turn_id: S.optional(AgentRefId),
|
|
591
|
+
questions: S.Array(AgentUserInputQuestion).check(S.isMinLength(1), S.isMaxLength(16)),
|
|
592
|
+
});
|
|
593
|
+
export const AgentUserInputResolvedEvent = S.Struct({
|
|
594
|
+
...eventBase,
|
|
595
|
+
type: S.Literal("user-input.resolved"),
|
|
596
|
+
request_id: AgentRefId,
|
|
597
|
+
answers: AgentUserInputAnswers,
|
|
598
|
+
});
|
|
599
|
+
export const AgentTokenUsageUpdatedEvent = S.Struct({
|
|
600
|
+
...eventBase,
|
|
601
|
+
type: S.Literal("thread.token-usage.updated"),
|
|
602
|
+
usage: AgentTokenUsage,
|
|
603
|
+
});
|
|
604
|
+
export const AgentRuntimeWarningEvent = S.Struct({
|
|
605
|
+
...eventBase,
|
|
606
|
+
type: S.Literal("runtime.warning"),
|
|
607
|
+
code: S.optional(S.String.check(S.isMaxLength(64))),
|
|
608
|
+
message: DetailText,
|
|
609
|
+
});
|
|
610
|
+
/**
|
|
611
|
+
* `runtime.error` code of a `set_model` the engine accepted but could not
|
|
612
|
+
* apply (the CLI refused the model, or never confirmed the switch).
|
|
613
|
+
*/
|
|
614
|
+
export const AGENT_MODEL_SWITCH_FAILED_CODE = "model_switch_failed";
|
|
615
|
+
/** `runtime.warning` code of a model switch the user declined. */
|
|
616
|
+
export const AGENT_MODEL_SWITCH_DECLINED_CODE = "model_switch_declined";
|
|
617
|
+
export const AgentRuntimeErrorEvent = S.Struct({
|
|
618
|
+
...eventBase,
|
|
619
|
+
type: S.Literal("runtime.error"),
|
|
620
|
+
code: S.optional(S.String.check(S.isMaxLength(64))),
|
|
621
|
+
message: DetailText,
|
|
622
|
+
/** True when the session cannot continue (a `session.exited` follows). */
|
|
623
|
+
fatal: S.optional(S.Boolean),
|
|
624
|
+
});
|
|
625
|
+
/**
|
|
626
|
+
* One chunk of an `attachment_get` response. Chunked so a single NDJSON line
|
|
627
|
+
* stays under {@link AGENT_MAX_LINE_BYTES}: `data` is base64 of
|
|
628
|
+
* `file[offset .. offset+decodedLen)`, and `done` is true on the last chunk.
|
|
629
|
+
*/
|
|
630
|
+
export const AgentAttachmentDataEvent = S.Struct({
|
|
631
|
+
...eventBase,
|
|
632
|
+
type: S.Literal("attachment.data"),
|
|
633
|
+
name: S.String.check(S.isMinLength(1), S.isMaxLength(256)),
|
|
634
|
+
mime: S.String.check(S.isMinLength(1), S.isMaxLength(128)),
|
|
635
|
+
/** Total decoded byte length of the file. */
|
|
636
|
+
size: S.Number.check(S.isInt(), S.isGreaterThanOrEqualTo(0)),
|
|
637
|
+
/** Decoded-byte offset of this chunk within the file. */
|
|
638
|
+
offset: S.Number.check(S.isInt(), S.isGreaterThanOrEqualTo(0)),
|
|
639
|
+
/** Base64 of this chunk. */
|
|
640
|
+
data: S.String.check(S.isMaxLength(AGENT_MAX_ATTACHMENT_BASE64_LENGTH)),
|
|
641
|
+
/** True when this is the last chunk. */
|
|
642
|
+
done: S.Boolean,
|
|
643
|
+
});
|
|
644
|
+
/** Answer to `delete_session`: the session is gone from the device. */
|
|
645
|
+
export const AgentSessionDeletedEvent = S.Struct({
|
|
646
|
+
...eventBase,
|
|
647
|
+
type: S.Literal("session.deleted"),
|
|
648
|
+
session_id: AgentSessionId,
|
|
649
|
+
});
|
|
650
|
+
/**
|
|
651
|
+
* A page of session history. On attach (no `events`): the cursor before the
|
|
652
|
+
* replayed window. Answering `history_get` (same `command_id`): the older
|
|
653
|
+
* events themselves, oldest first, each one {@link AgentEvent} line's value
|
|
654
|
+
* (decode with {@link parseAgentEvent}; unknown types are dropped). Paging is
|
|
655
|
+
* by whole turns, so a page never splits one. `has_more` false → the page
|
|
656
|
+
* reaches the start of the session.
|
|
657
|
+
*/
|
|
658
|
+
export const AgentHistoryPageEvent = S.Struct({
|
|
659
|
+
...eventBase,
|
|
660
|
+
type: S.Literal("history.page"),
|
|
661
|
+
before_cursor: S.optional(AgentHistoryCursor),
|
|
662
|
+
has_more: S.Boolean,
|
|
663
|
+
events: S.optional(S.Array(S.Unknown).check(S.isMaxLength(AGENT_HISTORY_MAX_PAGE_EVENTS))),
|
|
664
|
+
});
|
|
665
|
+
/** One daemon → consumer event line. */
|
|
666
|
+
export const AgentEvent = S.Union([
|
|
667
|
+
AgentSessionStartedEvent,
|
|
668
|
+
AgentSessionResetEvent,
|
|
669
|
+
AgentSessionConfiguredEvent,
|
|
670
|
+
AgentSessionExitedEvent,
|
|
671
|
+
AgentTurnStartedEvent,
|
|
672
|
+
AgentQueueUpdatedEvent,
|
|
673
|
+
AgentTurnCompletedEvent,
|
|
674
|
+
AgentTurnAbortedEvent,
|
|
675
|
+
AgentItemStartedEvent,
|
|
676
|
+
AgentItemUpdatedEvent,
|
|
677
|
+
AgentItemCompletedEvent,
|
|
678
|
+
AgentContentDeltaEvent,
|
|
679
|
+
AgentRequestOpenedEvent,
|
|
680
|
+
AgentRequestResolvedEvent,
|
|
681
|
+
AgentUserInputRequestedEvent,
|
|
682
|
+
AgentUserInputResolvedEvent,
|
|
683
|
+
AgentTokenUsageUpdatedEvent,
|
|
684
|
+
AgentRuntimeWarningEvent,
|
|
685
|
+
AgentRuntimeErrorEvent,
|
|
686
|
+
AgentAttachmentDataEvent,
|
|
687
|
+
AgentSessionDeletedEvent,
|
|
688
|
+
AgentHistoryPageEvent,
|
|
689
|
+
]);
|
|
690
|
+
// ---------------------------------------------------------------------------
|
|
691
|
+
// Parsing + NDJSON framing
|
|
692
|
+
// ---------------------------------------------------------------------------
|
|
693
|
+
const decodeCommand = S.decodeUnknownResult(S.revealCodec(AgentCommand));
|
|
694
|
+
const decodeEvent = S.decodeUnknownResult(S.revealCodec(AgentEvent));
|
|
695
|
+
/** Decode an already-parsed JSON value as a command, or null. */
|
|
696
|
+
export const parseAgentCommand = (value) => {
|
|
697
|
+
const result = decodeCommand(value);
|
|
698
|
+
return Result.isSuccess(result) ? result.success : null;
|
|
699
|
+
};
|
|
700
|
+
/** Decode an already-parsed JSON value as an event, or null (unknown types too). */
|
|
701
|
+
export const parseAgentEvent = (value) => {
|
|
702
|
+
const result = decodeEvent(value);
|
|
703
|
+
return Result.isSuccess(result) ? result.success : null;
|
|
704
|
+
};
|
|
705
|
+
const lineDecoder = new TextDecoder("utf-8", { fatal: true });
|
|
706
|
+
const NEWLINE = 0x0a;
|
|
707
|
+
/**
|
|
708
|
+
* JSON-encode one value as a newline-terminated line. Null when it does not
|
|
709
|
+
* serialize or exceeds {@link AGENT_MAX_LINE_BYTES} — the caller decides
|
|
710
|
+
* (truncate, or emit a `runtime.warning`); a truncated line would desync the
|
|
711
|
+
* framing.
|
|
712
|
+
*/
|
|
713
|
+
export const encodeAgentLine = (value) => {
|
|
714
|
+
let text;
|
|
715
|
+
try {
|
|
716
|
+
text = JSON.stringify(value);
|
|
717
|
+
}
|
|
718
|
+
catch {
|
|
719
|
+
return null;
|
|
720
|
+
}
|
|
721
|
+
if (text === undefined)
|
|
722
|
+
return null;
|
|
723
|
+
const encoded = lineEncoder.encode(`${text}\n`);
|
|
724
|
+
return encoded.byteLength > AGENT_MAX_LINE_BYTES ? null : encoded;
|
|
725
|
+
};
|
|
726
|
+
/** Decode one line's bytes (without `\n`) into JSON, or `undefined`. */
|
|
727
|
+
export const decodeAgentLine = (line) => {
|
|
728
|
+
try {
|
|
729
|
+
return JSON.parse(lineDecoder.decode(line));
|
|
730
|
+
}
|
|
731
|
+
catch {
|
|
732
|
+
return undefined;
|
|
733
|
+
}
|
|
734
|
+
};
|
|
735
|
+
/**
|
|
736
|
+
* Stateful NDJSON splitter. Partial lines are kept as a chunk list and joined
|
|
737
|
+
* once, when their newline arrives, so a multi-megabyte line costs one copy
|
|
738
|
+
* rather than one per DATA frame.
|
|
739
|
+
*/
|
|
740
|
+
export const createAgentLineSplitter = (maxLineBytes = AGENT_MAX_LINE_BYTES) => {
|
|
741
|
+
let pending = [];
|
|
742
|
+
let pendingBytes = 0;
|
|
743
|
+
let failed = false;
|
|
744
|
+
const join = (tail) => {
|
|
745
|
+
if (pending.length === 0)
|
|
746
|
+
return tail;
|
|
747
|
+
const out = new Uint8Array(pendingBytes + tail.byteLength);
|
|
748
|
+
let offset = 0;
|
|
749
|
+
for (const part of pending) {
|
|
750
|
+
out.set(part, offset);
|
|
751
|
+
offset += part.byteLength;
|
|
752
|
+
}
|
|
753
|
+
out.set(tail, offset);
|
|
754
|
+
pending = [];
|
|
755
|
+
pendingBytes = 0;
|
|
756
|
+
return out;
|
|
757
|
+
};
|
|
758
|
+
return {
|
|
759
|
+
push: (chunk) => {
|
|
760
|
+
if (failed)
|
|
761
|
+
return null;
|
|
762
|
+
const lines = [];
|
|
763
|
+
let start = 0;
|
|
764
|
+
for (let i = 0; i < chunk.byteLength; i += 1) {
|
|
765
|
+
if (chunk[i] !== NEWLINE)
|
|
766
|
+
continue;
|
|
767
|
+
if (pendingBytes + (i - start) > maxLineBytes) {
|
|
768
|
+
failed = true;
|
|
769
|
+
return null;
|
|
770
|
+
}
|
|
771
|
+
lines.push(join(chunk.subarray(start, i)));
|
|
772
|
+
start = i + 1;
|
|
773
|
+
}
|
|
774
|
+
if (start < chunk.byteLength) {
|
|
775
|
+
const rest = chunk.subarray(start);
|
|
776
|
+
if (pendingBytes + rest.byteLength > maxLineBytes) {
|
|
777
|
+
failed = true;
|
|
778
|
+
return null;
|
|
779
|
+
}
|
|
780
|
+
// Copy: the transport may reuse the chunk's buffer.
|
|
781
|
+
pending.push(rest.slice());
|
|
782
|
+
pendingBytes += rest.byteLength;
|
|
783
|
+
}
|
|
784
|
+
return lines;
|
|
785
|
+
},
|
|
786
|
+
};
|
|
787
|
+
};
|