@openllmsh/sdk 2.10.12-alpha.1 → 2.10.12-alpha.2
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,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Claude Code compaction (`Xm()` in bundled CLI) rejects summaries when the
|
|
3
|
+
* extracted visible text is empty or **shorter than 10 characters** after
|
|
4
|
+
* trim — see https://github.com/anthropics/claude-code/issues/11095
|
|
5
|
+
*/
|
|
6
|
+
export const COMPACTION_MIN_VISIBLE_TEXT_CHARS = 10;
|
|
7
|
+
export const anthropicAssistantVisibleTextTrimmed = (resp, opts = {}) => {
|
|
8
|
+
const betweenBlocks = opts.betweenBlocks ?? "";
|
|
9
|
+
const trimParts = betweenBlocks !== "";
|
|
10
|
+
const texts = resp.content
|
|
11
|
+
.filter((b) => b.type === "text")
|
|
12
|
+
.map((b) => (trimParts ? b.text.trim() : b.text));
|
|
13
|
+
return texts.join(betweenBlocks).trim();
|
|
14
|
+
};
|
|
15
|
+
const FALLBACK_NO_SUMMARY = "OpenLLM: no visible summary text was returned for this compaction; you may retry /compact or continue the session.";
|
|
16
|
+
/**
|
|
17
|
+
* Ensures assistant `text` blocks meet Claude Code’s minimum length so
|
|
18
|
+
* `/compact` does not fail at ~30–40% with “did not contain valid text content”.
|
|
19
|
+
*/
|
|
20
|
+
export const ensureCompactionSafeVisibleText = (text) => {
|
|
21
|
+
const t = text.trim();
|
|
22
|
+
if (t.length >= COMPACTION_MIN_VISIBLE_TEXT_CHARS) {
|
|
23
|
+
return t;
|
|
24
|
+
}
|
|
25
|
+
if (t.length === 0) {
|
|
26
|
+
return FALLBACK_NO_SUMMARY;
|
|
27
|
+
}
|
|
28
|
+
return `${t}${".".repeat(COMPACTION_MIN_VISIBLE_TEXT_CHARS - t.length)}`;
|
|
29
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Choose the next chain hop that can accommodate an input of the required
|
|
3
|
+
* size. Shared by the cloud dispatch chain and the coreless daemon walker so
|
|
4
|
+
* context-overflow demotion cannot drift between the two paths.
|
|
5
|
+
*/
|
|
6
|
+
export declare const nextLargerContextModel: (chainModels: ReadonlyArray<string>, currentModel: string, requiredTokens: number, windowOf: (modelId: string) => number | null) => string | null;
|
|
7
|
+
/**
|
|
8
|
+
* Extract the upstream tokenizer's authoritative request size from an overflow
|
|
9
|
+
* diagnostic. Recognises the three vendor shapes observed live:
|
|
10
|
+
* - vLLM-style: "maximum prompt length is N ... contains M tokens" → M
|
|
11
|
+
* - Anthropic: "prompt is too long: N tokens > M maximum" → N
|
|
12
|
+
* - Kimi/DeepSeek:"... token limit: X (requested: N)" → N
|
|
13
|
+
* Returns the REQUIRED size (how big the request actually is), not the window.
|
|
14
|
+
*/
|
|
15
|
+
export declare const contextOverflowRequiredTokens: (raw: string) => number | null;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Choose the next chain hop that can accommodate an input of the required
|
|
3
|
+
* size. Shared by the cloud dispatch chain and the coreless daemon walker so
|
|
4
|
+
* context-overflow demotion cannot drift between the two paths.
|
|
5
|
+
*/
|
|
6
|
+
export const nextLargerContextModel = (chainModels, currentModel, requiredTokens, windowOf) => {
|
|
7
|
+
const currentIndex = chainModels.indexOf(currentModel);
|
|
8
|
+
if (currentIndex === -1)
|
|
9
|
+
return null;
|
|
10
|
+
for (const modelId of chainModels.slice(currentIndex + 1)) {
|
|
11
|
+
const window = windowOf(modelId);
|
|
12
|
+
if (window !== null && window > requiredTokens)
|
|
13
|
+
return modelId;
|
|
14
|
+
}
|
|
15
|
+
return null;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Extract the upstream tokenizer's authoritative request size from an overflow
|
|
19
|
+
* diagnostic. Recognises the three vendor shapes observed live:
|
|
20
|
+
* - vLLM-style: "maximum prompt length is N ... contains M tokens" → M
|
|
21
|
+
* - Anthropic: "prompt is too long: N tokens > M maximum" → N
|
|
22
|
+
* - Kimi/DeepSeek:"... token limit: X (requested: N)" → N
|
|
23
|
+
* Returns the REQUIRED size (how big the request actually is), not the window.
|
|
24
|
+
*/
|
|
25
|
+
export const contextOverflowRequiredTokens = (raw) => {
|
|
26
|
+
const patterns = [
|
|
27
|
+
// vLLM-style: the "contains M tokens" count.
|
|
28
|
+
/maximum (?:prompt|context) length is\s+[\d,]+.*?contains\s+([\d,]+)\s+tokens/i,
|
|
29
|
+
// Anthropic: "prompt is too long: N tokens > M maximum".
|
|
30
|
+
/prompt is too long:\s*([\d,]+)\s*tokens/i,
|
|
31
|
+
// Kimi/DeepSeek: "token limit: X (requested: N)". The "token limit" prefix
|
|
32
|
+
// is required so an unrelated "(requested: N)" (e.g. a quota / validation
|
|
33
|
+
// error) is NOT misread as a context overflow.
|
|
34
|
+
/token limit:?\s*[\d,]+\s*\(requested:\s*([\d,]+)\)/i,
|
|
35
|
+
];
|
|
36
|
+
for (const pattern of patterns) {
|
|
37
|
+
const match = pattern.exec(raw);
|
|
38
|
+
if (match === null)
|
|
39
|
+
continue;
|
|
40
|
+
const required = Number((match[1] ?? "").replaceAll(",", ""));
|
|
41
|
+
if (Number.isSafeInteger(required) && required > 0)
|
|
42
|
+
return required;
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { TContextOverflowStrategy as TProtocolContextOverflowStrategy } from "@openllmsh/sdk/protocol";
|
|
2
|
+
/**
|
|
3
|
+
* Shared context-overflow routing strategy. The cloud and daemon resolve an
|
|
4
|
+
* absent or unrecognised persisted value to the historical hop behaviour.
|
|
5
|
+
*/
|
|
6
|
+
export type TContextOverflowStrategy = TProtocolContextOverflowStrategy;
|
|
7
|
+
export declare const DEFAULT_CONTEXT_OVERFLOW_STRATEGY: TContextOverflowStrategy;
|
|
8
|
+
export declare const resolveContextOverflowStrategy: (raw: string | undefined | null) => TContextOverflowStrategy;
|
|
9
|
+
/** Hop mode both demotes on overflow and pre-skips known-too-small hops. */
|
|
10
|
+
export declare const isHopToLargerContext: (strategy: TContextOverflowStrategy) => boolean;
|
|
11
|
+
export declare const shouldDemoteOnContextOverflow: typeof isHopToLargerContext;
|
|
12
|
+
export declare const shouldSkipHopForSize: typeof isHopToLargerContext;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const DEFAULT_CONTEXT_OVERFLOW_STRATEGY = "hop_to_larger_context";
|
|
2
|
+
export const resolveContextOverflowStrategy = (raw) => raw === "compact_in_place"
|
|
3
|
+
? "compact_in_place"
|
|
4
|
+
: DEFAULT_CONTEXT_OVERFLOW_STRATEGY;
|
|
5
|
+
/** Hop mode both demotes on overflow and pre-skips known-too-small hops. */
|
|
6
|
+
export const isHopToLargerContext = (strategy) => strategy === "hop_to_larger_context";
|
|
7
|
+
export const shouldDemoteOnContextOverflow = isHopToLargerContext;
|
|
8
|
+
export const shouldSkipHopForSize = isHopToLargerContext;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context-skip gate — the per-hop context decision, shared verbatim by
|
|
3
|
+
* the cloud dispatch chain (BYOK) and the daemon walker (device) so the
|
|
4
|
+
* two paths cannot drift.
|
|
5
|
+
*
|
|
6
|
+
* The context "ladder" is deliberately thin (reference-proxy parity —
|
|
7
|
+
* ref/CLIProxyAPI does no gateway-side rewriting either):
|
|
8
|
+
*
|
|
9
|
+
* Plan A — serve correct per-model context metadata (and pass through
|
|
10
|
+
* Codex's own `/responses/compact`) so the CLIENT compacts
|
|
11
|
+
* itself with a STABLE prefix — the only compaction that
|
|
12
|
+
* preserves prompt-cache affinity;
|
|
13
|
+
* gate — THIS module: skip a hop only when the estimate CLEARLY
|
|
14
|
+
* exceeds its window (saves the doomed round trip + prefill
|
|
15
|
+
* wait);
|
|
16
|
+
* walk — the pre-commit first-event peek
|
|
17
|
+
* (`lib/streaming/peek.ts`): the real upstream tokenizer gets
|
|
18
|
+
* the final word, and a pre-output rejection walks the chain
|
|
19
|
+
* with zero double-spend.
|
|
20
|
+
*
|
|
21
|
+
* Gateway-side tool-output rewriting (the former "Plan B") was removed
|
|
22
|
+
* on purpose: estimator-driven per-request rewrites destabilise the
|
|
23
|
+
* conversation prefix (prompt-cache misses → quota drain) and silently
|
|
24
|
+
* degrade requests the vendor would have accepted.
|
|
25
|
+
*/
|
|
26
|
+
/**
|
|
27
|
+
* Confidence multiplier before a hop is abandoned over context. The
|
|
28
|
+
* routing estimator is intentionally conservative (it counts every string
|
|
29
|
+
* value), so an estimate above the catalogued input budget is enough to skip
|
|
30
|
+
* a non-final hop: that model has already advertised it cannot accept the
|
|
31
|
+
* request. Final and unknown-limit hops still reach the real tokenizer.
|
|
32
|
+
*
|
|
33
|
+
* A factor above 1 let known-over-budget requests through to an inevitable
|
|
34
|
+
* upstream context rejection. Keep this at one unless the estimator contract
|
|
35
|
+
* itself changes.
|
|
36
|
+
*/
|
|
37
|
+
export declare const CONTEXT_SKIP_CONFIDENCE_FACTOR = 1;
|
|
38
|
+
/**
|
|
39
|
+
* Conservative ruler→vendor-token calibration for last-resort compaction. The
|
|
40
|
+
* local `estimateBodyTokens` ruler can count fewer tokens than a vendor's own
|
|
41
|
+
* tokenizer, so target every provider below its advertised window until the
|
|
42
|
+
* vendor-grounded overflow path corrects from a real rejection.
|
|
43
|
+
*/
|
|
44
|
+
export declare const TOKEN_ESTIMATE_FACTOR = 1.2;
|
|
45
|
+
/**
|
|
46
|
+
* The compaction target for a hop: its input window shrunk by the shared
|
|
47
|
+
* calibration factor (so a body compacted to this size fits the vendor's real
|
|
48
|
+
* tokenizer, not just our ruler) and by the shared context-gate safety factor.
|
|
49
|
+
* Single source for BOTH seams (cloud dispatch chain + daemon walker) so the
|
|
50
|
+
* target can't drift.
|
|
51
|
+
*/
|
|
52
|
+
export declare const compactionTargetFor: (_provider: string, window: number) => number;
|
|
53
|
+
/**
|
|
54
|
+
* Single safety margin applied to the vendor-grounded compaction target: aim
|
|
55
|
+
* the shrunk body at `window × SAFETY` implied vendor tokens, leaving a small
|
|
56
|
+
* headroom band so the retry clears the real tokenizer even if the ratio drifts
|
|
57
|
+
* slightly between passes. ONE knob for every provider — the calibration itself
|
|
58
|
+
* is self-derived from the vendor's own numbers, so there is no per-model
|
|
59
|
+
* branching here.
|
|
60
|
+
*/
|
|
61
|
+
export declare const COMPACTION_OVERFLOW_SAFETY = 0.92;
|
|
62
|
+
/**
|
|
63
|
+
* A sane lower bound for any computed compaction target. A pathological vendor
|
|
64
|
+
* ratio (or a tiny window) must never drive the target to zero / negative — the
|
|
65
|
+
* cut would then strip the live turn too. 512 tokens comfortably holds the
|
|
66
|
+
* system prompt + the final user turn the compactor always preserves.
|
|
67
|
+
*/
|
|
68
|
+
export declare const COMPACTION_TARGET_FLOOR = 512;
|
|
69
|
+
/**
|
|
70
|
+
* Vendor-grounded, self-calibrating compaction target. When the upstream
|
|
71
|
+
* rejected a body on size it reports two ground-truth numbers: `requiredTokens`
|
|
72
|
+
* (how many tokens ITS tokenizer counted for the body we sent) and, implicitly,
|
|
73
|
+
* the `window` it must fit. Our local ruler measured that same body at
|
|
74
|
+
* `localEstimate`, so the observed ratio `r = requiredTokens / localEstimate`
|
|
75
|
+
* is exact calibration for THIS conversation's content — no static per-provider
|
|
76
|
+
* factor needed.
|
|
77
|
+
*
|
|
78
|
+
* We return a target in LOCAL ruler space: shrinking the body to
|
|
79
|
+
* `floor(window / r × SAFETY)` local tokens implies a vendor count of
|
|
80
|
+
* `<= window × SAFETY`, i.e. inside the window with headroom. The result is
|
|
81
|
+
* clamped to be no looser than `compactionTargetFor(provider, window)` (the
|
|
82
|
+
* static target is an upper bound — vendor grounding may only tighten) and never
|
|
83
|
+
* below `COMPACTION_TARGET_FLOOR`. When the vendor gave no usable count we fall
|
|
84
|
+
* back to the static target. Generic across grok / chatgpt / anthropic / kimi —
|
|
85
|
+
* whatever numbers the vendor surfaces drive the cut.
|
|
86
|
+
*/
|
|
87
|
+
export declare const compactionTargetFromOverflow: (params: {
|
|
88
|
+
readonly requiredTokens: number | null;
|
|
89
|
+
readonly window: number;
|
|
90
|
+
readonly localEstimate: number;
|
|
91
|
+
readonly provider: string;
|
|
92
|
+
}) => number;
|
|
93
|
+
/**
|
|
94
|
+
* Hard cap on last-resort compaction rounds (daemon walker + cloud dispatch
|
|
95
|
+
* chain). The vendor-grounded ratio converges fast (usually one tighter round
|
|
96
|
+
* after a static undercorrect), so three rounds is ample headroom; the cap's
|
|
97
|
+
* real job is to make an infinite compaction loop structurally impossible when
|
|
98
|
+
* an upstream keeps rejecting. Single source of truth — both seams import this.
|
|
99
|
+
*/
|
|
100
|
+
export declare const MAX_LAST_RESORT_COMPACTION_ROUNDS = 3;
|
|
101
|
+
/**
|
|
102
|
+
* A confirmed overflow always forces a real shrink. If the calibrated target
|
|
103
|
+
* is already below the current local estimate, use it; otherwise tighten below
|
|
104
|
+
* the current body (`localEstimate × SAFETY`, floored) so the cut is never a
|
|
105
|
+
* no-op re-send of the same bytes. Shared by the daemon walker and the cloud
|
|
106
|
+
* dispatch chain so the force-shrink math cannot drift between them.
|
|
107
|
+
*/
|
|
108
|
+
export declare const forcedCompactionTarget: (calibrated: number, localEstimate: number) => number;
|
|
109
|
+
/**
|
|
110
|
+
* Should this hop be skipped for context? True only when a later hop
|
|
111
|
+
* remains (the FINAL hop always serves — the real tokenizer must get the
|
|
112
|
+
* last word, never the heuristic estimator), the model's input budget is
|
|
113
|
+
* known, and the conservative routing estimate exceeds it. An unknown
|
|
114
|
+
* limit always serves.
|
|
115
|
+
*/
|
|
116
|
+
export declare const shouldSkipHopForContext: (params: {
|
|
117
|
+
readonly estimatedTokens: number;
|
|
118
|
+
readonly inputTokenLimit: number | null;
|
|
119
|
+
readonly finalHop: boolean;
|
|
120
|
+
}) => boolean;
|
|
@@ -23,7 +23,6 @@
|
|
|
23
23
|
* conversation prefix (prompt-cache misses → quota drain) and silently
|
|
24
24
|
* degrade requests the vendor would have accepted.
|
|
25
25
|
*/
|
|
26
|
-
|
|
27
26
|
/**
|
|
28
27
|
* Confidence multiplier before a hop is abandoned over context. The
|
|
29
28
|
* routing estimator is intentionally conservative (it counts every string
|
|
@@ -36,7 +35,6 @@
|
|
|
36
35
|
* itself changes.
|
|
37
36
|
*/
|
|
38
37
|
export const CONTEXT_SKIP_CONFIDENCE_FACTOR = 1;
|
|
39
|
-
|
|
40
38
|
/**
|
|
41
39
|
* Conservative ruler→vendor-token calibration for last-resort compaction. The
|
|
42
40
|
* local `estimateBodyTokens` ruler can count fewer tokens than a vendor's own
|
|
@@ -48,7 +46,6 @@ export const CONTEXT_SKIP_CONFIDENCE_FACTOR = 1;
|
|
|
48
46
|
// (higher values shrink the target and dull long contexts), and the
|
|
49
47
|
// vendor-grounded overflow path corrects the rare Claude first-pass rejection.
|
|
50
48
|
export const TOKEN_ESTIMATE_FACTOR = 1.2;
|
|
51
|
-
|
|
52
49
|
/**
|
|
53
50
|
* The compaction target for a hop: its input window shrunk by the shared
|
|
54
51
|
* calibration factor (so a body compacted to this size fits the vendor's real
|
|
@@ -56,12 +53,7 @@ export const TOKEN_ESTIMATE_FACTOR = 1.2;
|
|
|
56
53
|
* Single source for BOTH seams (cloud dispatch chain + daemon walker) so the
|
|
57
54
|
* target can't drift.
|
|
58
55
|
*/
|
|
59
|
-
export const compactionTargetFor = (
|
|
60
|
-
_provider: string,
|
|
61
|
-
window: number,
|
|
62
|
-
): number =>
|
|
63
|
-
Math.floor((window / TOKEN_ESTIMATE_FACTOR) * CONTEXT_SKIP_CONFIDENCE_FACTOR);
|
|
64
|
-
|
|
56
|
+
export const compactionTargetFor = (_provider, window) => Math.floor((window / TOKEN_ESTIMATE_FACTOR) * CONTEXT_SKIP_CONFIDENCE_FACTOR);
|
|
65
57
|
/**
|
|
66
58
|
* Single safety margin applied to the vendor-grounded compaction target: aim
|
|
67
59
|
* the shrunk body at `window × SAFETY` implied vendor tokens, leaving a small
|
|
@@ -71,7 +63,6 @@ export const compactionTargetFor = (
|
|
|
71
63
|
* branching here.
|
|
72
64
|
*/
|
|
73
65
|
export const COMPACTION_OVERFLOW_SAFETY = 0.92;
|
|
74
|
-
|
|
75
66
|
/**
|
|
76
67
|
* A sane lower bound for any computed compaction target. A pathological vendor
|
|
77
68
|
* ratio (or a tiny window) must never drive the target to zero / negative — the
|
|
@@ -79,7 +70,6 @@ export const COMPACTION_OVERFLOW_SAFETY = 0.92;
|
|
|
79
70
|
* system prompt + the final user turn the compactor always preserves.
|
|
80
71
|
*/
|
|
81
72
|
export const COMPACTION_TARGET_FLOOR = 512;
|
|
82
|
-
|
|
83
73
|
/**
|
|
84
74
|
* Vendor-grounded, self-calibrating compaction target. When the upstream
|
|
85
75
|
* rejected a body on size it reports two ground-truth numbers: `requiredTokens`
|
|
@@ -98,33 +88,23 @@ export const COMPACTION_TARGET_FLOOR = 512;
|
|
|
98
88
|
* back to the static target. Generic across grok / chatgpt / anthropic / kimi —
|
|
99
89
|
* whatever numbers the vendor surfaces drive the cut.
|
|
100
90
|
*/
|
|
101
|
-
export const compactionTargetFromOverflow = (params
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
params.
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
return
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
(params.window / ratio) * COMPACTION_OVERFLOW_SAFETY,
|
|
118
|
-
);
|
|
119
|
-
// Vendor-grounded may only TIGHTEN the static target. The floor is normally
|
|
120
|
-
// COMPACTION_TARGET_FLOOR, but a small live `context_window` can make the
|
|
121
|
-
// static target itself dip below that floor — clamping up to 512 would then
|
|
122
|
-
// return a target LOOSER than the window allows. Cap the floor at the static
|
|
123
|
-
// target so the result is always `<= staticTarget`.
|
|
124
|
-
const floor = Math.min(COMPACTION_TARGET_FLOOR, staticTarget);
|
|
125
|
-
return Math.max(floor, Math.min(staticTarget, vendorGrounded));
|
|
91
|
+
export const compactionTargetFromOverflow = (params) => {
|
|
92
|
+
const staticTarget = compactionTargetFor(params.provider, params.window);
|
|
93
|
+
if (params.requiredTokens === null ||
|
|
94
|
+
params.requiredTokens <= 0 ||
|
|
95
|
+
params.localEstimate <= 0) {
|
|
96
|
+
return staticTarget;
|
|
97
|
+
}
|
|
98
|
+
const ratio = params.requiredTokens / params.localEstimate;
|
|
99
|
+
const vendorGrounded = Math.floor((params.window / ratio) * COMPACTION_OVERFLOW_SAFETY);
|
|
100
|
+
// Vendor-grounded may only TIGHTEN the static target. The floor is normally
|
|
101
|
+
// COMPACTION_TARGET_FLOOR, but a small live `context_window` can make the
|
|
102
|
+
// static target itself dip below that floor — clamping up to 512 would then
|
|
103
|
+
// return a target LOOSER than the window allows. Cap the floor at the static
|
|
104
|
+
// target so the result is always `<= staticTarget`.
|
|
105
|
+
const floor = Math.min(COMPACTION_TARGET_FLOOR, staticTarget);
|
|
106
|
+
return Math.max(floor, Math.min(staticTarget, vendorGrounded));
|
|
126
107
|
};
|
|
127
|
-
|
|
128
108
|
/**
|
|
129
109
|
* Hard cap on last-resort compaction rounds (daemon walker + cloud dispatch
|
|
130
110
|
* chain). The vendor-grounded ratio converges fast (usually one tighter round
|
|
@@ -133,7 +113,6 @@ export const compactionTargetFromOverflow = (params: {
|
|
|
133
113
|
* an upstream keeps rejecting. Single source of truth — both seams import this.
|
|
134
114
|
*/
|
|
135
115
|
export const MAX_LAST_RESORT_COMPACTION_ROUNDS = 3;
|
|
136
|
-
|
|
137
116
|
/**
|
|
138
117
|
* A confirmed overflow always forces a real shrink. If the calibrated target
|
|
139
118
|
* is already below the current local estimate, use it; otherwise tighten below
|
|
@@ -141,17 +120,9 @@ export const MAX_LAST_RESORT_COMPACTION_ROUNDS = 3;
|
|
|
141
120
|
* no-op re-send of the same bytes. Shared by the daemon walker and the cloud
|
|
142
121
|
* dispatch chain so the force-shrink math cannot drift between them.
|
|
143
122
|
*/
|
|
144
|
-
export const forcedCompactionTarget = (
|
|
145
|
-
calibrated: number,
|
|
146
|
-
localEstimate: number,
|
|
147
|
-
): number =>
|
|
148
|
-
calibrated < localEstimate
|
|
123
|
+
export const forcedCompactionTarget = (calibrated, localEstimate) => calibrated < localEstimate
|
|
149
124
|
? calibrated
|
|
150
|
-
: Math.max(
|
|
151
|
-
COMPACTION_TARGET_FLOOR,
|
|
152
|
-
Math.floor(localEstimate * COMPACTION_OVERFLOW_SAFETY),
|
|
153
|
-
);
|
|
154
|
-
|
|
125
|
+
: Math.max(COMPACTION_TARGET_FLOOR, Math.floor(localEstimate * COMPACTION_OVERFLOW_SAFETY));
|
|
155
126
|
/**
|
|
156
127
|
* Should this hop be skipped for context? True only when a later hop
|
|
157
128
|
* remains (the FINAL hop always serves — the real tokenizer must get the
|
|
@@ -159,12 +130,7 @@ export const forcedCompactionTarget = (
|
|
|
159
130
|
* known, and the conservative routing estimate exceeds it. An unknown
|
|
160
131
|
* limit always serves.
|
|
161
132
|
*/
|
|
162
|
-
export const shouldSkipHopForContext = (params
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
}): boolean =>
|
|
167
|
-
!params.finalHop &&
|
|
168
|
-
params.inputTokenLimit !== null &&
|
|
169
|
-
params.estimatedTokens >
|
|
170
|
-
params.inputTokenLimit * CONTEXT_SKIP_CONFIDENCE_FACTOR;
|
|
133
|
+
export const shouldSkipHopForContext = (params) => !params.finalHop &&
|
|
134
|
+
params.inputTokenLimit !== null &&
|
|
135
|
+
params.estimatedTokens >
|
|
136
|
+
params.inputTokenLimit * CONTEXT_SKIP_CONFIDENCE_FACTOR;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Conversation affinity — keep one conversation on the backend that last
|
|
3
|
+
* served it, because switching account, supplier or device cold-misses the
|
|
4
|
+
* provider's prompt cache.
|
|
5
|
+
*
|
|
6
|
+
* Every routing layer ranks its candidates (chain hops, personal accounts,
|
|
7
|
+
* team suppliers, supplier devices) from live data that drifts between turns.
|
|
8
|
+
* Affinity sits on top of that ranking: the remembered candidate moves to the
|
|
9
|
+
* front whenever it is still eligible, and the ranking only decides for a new
|
|
10
|
+
* conversation or after the remembered one is excluded (cooling, exhausted,
|
|
11
|
+
* offline, critical failure). Whatever serves next is remembered in its place.
|
|
12
|
+
*
|
|
13
|
+
* Pure: the key derivation, the reorder and an in-process TTL memory. Hosts
|
|
14
|
+
* that need a cross-instance store wrap their own behind the same get/set.
|
|
15
|
+
*/
|
|
16
|
+
/** Longer than any provider's prompt-cache lifetime. */
|
|
17
|
+
export declare const CONVERSATION_AFFINITY_TTL_MS: number;
|
|
18
|
+
/**
|
|
19
|
+
* A stable key for the conversation `body` belongs to, or null when the body
|
|
20
|
+
* carries nothing to key on. A client-supplied cache/session id wins (OpenAI
|
|
21
|
+
* `prompt_cache_key`, Anthropic `metadata.user_id`, which Claude Code scopes
|
|
22
|
+
* per session); otherwise the hash of the conversation's fixed prefix — the
|
|
23
|
+
* system prompt and the turns up to and including the first user turn, which
|
|
24
|
+
* never change as the conversation grows.
|
|
25
|
+
*/
|
|
26
|
+
export declare const conversationAffinityKey: (body: unknown) => string | null;
|
|
27
|
+
/** `items` with the remembered one first; unchanged when it isn't present. */
|
|
28
|
+
export declare const preferRemembered: <T>(items: ReadonlyArray<T>, isRemembered: (item: T) => boolean) => ReadonlyArray<T>;
|
|
29
|
+
export type TAffinityMemory = {
|
|
30
|
+
readonly get: (key: string) => string | undefined;
|
|
31
|
+
readonly set: (key: string, value: string) => void;
|
|
32
|
+
};
|
|
33
|
+
/** Bounded in-process memory; the oldest entry is evicted first. */
|
|
34
|
+
export declare const createAffinityMemory: (options?: {
|
|
35
|
+
readonly ttlMs?: number;
|
|
36
|
+
readonly maxEntries?: number;
|
|
37
|
+
readonly now?: () => number;
|
|
38
|
+
}) => TAffinityMemory;
|
|
39
|
+
/** Memory slots, one per routing decision a conversation pins. */
|
|
40
|
+
export declare const affinitySlot: {
|
|
41
|
+
/** The chain hop (model id) that served. */
|
|
42
|
+
readonly hop: (conversation: string) => string;
|
|
43
|
+
/** The personal account index that served `provider`. */
|
|
44
|
+
readonly account: (conversation: string, provider: string) => string;
|
|
45
|
+
/** The team share that served `teamModelId`. */
|
|
46
|
+
readonly share: (conversation: string, teamModelId: string) => string;
|
|
47
|
+
/** The supplier device that served `shareId`. */
|
|
48
|
+
readonly device: (conversation: string, shareId: string) => string;
|
|
49
|
+
};
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Conversation affinity — keep one conversation on the backend that last
|
|
3
|
+
* served it, because switching account, supplier or device cold-misses the
|
|
4
|
+
* provider's prompt cache.
|
|
5
|
+
*
|
|
6
|
+
* Every routing layer ranks its candidates (chain hops, personal accounts,
|
|
7
|
+
* team suppliers, supplier devices) from live data that drifts between turns.
|
|
8
|
+
* Affinity sits on top of that ranking: the remembered candidate moves to the
|
|
9
|
+
* front whenever it is still eligible, and the ranking only decides for a new
|
|
10
|
+
* conversation or after the remembered one is excluded (cooling, exhausted,
|
|
11
|
+
* offline, critical failure). Whatever serves next is remembered in its place.
|
|
12
|
+
*
|
|
13
|
+
* Pure: the key derivation, the reorder and an in-process TTL memory. Hosts
|
|
14
|
+
* that need a cross-instance store wrap their own behind the same get/set.
|
|
15
|
+
*/
|
|
16
|
+
/** Longer than any provider's prompt-cache lifetime. */
|
|
17
|
+
export const CONVERSATION_AFFINITY_TTL_MS = 60 * 60 * 1000;
|
|
18
|
+
const DEFAULT_MAX_ENTRIES = 10_000;
|
|
19
|
+
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
20
|
+
const nonEmpty = (value) => typeof value === "string" && value.trim() !== "" ? value : null;
|
|
21
|
+
/** 64-bit FNV-1a (two 32-bit lanes) — a routing key, not a secret. */
|
|
22
|
+
const hash64 = (text) => {
|
|
23
|
+
let a = 0x811c9dc5;
|
|
24
|
+
let b = 0x01000193 ^ 0x9e3779b9;
|
|
25
|
+
for (let i = 0; i < text.length; i += 1) {
|
|
26
|
+
const code = text.charCodeAt(i);
|
|
27
|
+
a = Math.imul(a ^ code, 0x01000193);
|
|
28
|
+
b = Math.imul(b ^ code, 0x01000193 ^ 0x5bd1e995);
|
|
29
|
+
}
|
|
30
|
+
return ((a >>> 0).toString(16).padStart(8, "0") +
|
|
31
|
+
(b >>> 0).toString(16).padStart(8, "0"));
|
|
32
|
+
};
|
|
33
|
+
/** The turns of an inbound body, whichever surface it arrived on. */
|
|
34
|
+
const turnsOf = (body) => {
|
|
35
|
+
if (Array.isArray(body.messages))
|
|
36
|
+
return body.messages;
|
|
37
|
+
if (Array.isArray(body.input))
|
|
38
|
+
return body.input;
|
|
39
|
+
return [];
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* A stable key for the conversation `body` belongs to, or null when the body
|
|
43
|
+
* carries nothing to key on. A client-supplied cache/session id wins (OpenAI
|
|
44
|
+
* `prompt_cache_key`, Anthropic `metadata.user_id`, which Claude Code scopes
|
|
45
|
+
* per session); otherwise the hash of the conversation's fixed prefix — the
|
|
46
|
+
* system prompt and the turns up to and including the first user turn, which
|
|
47
|
+
* never change as the conversation grows.
|
|
48
|
+
*/
|
|
49
|
+
export const conversationAffinityKey = (body) => {
|
|
50
|
+
if (!isRecord(body))
|
|
51
|
+
return null;
|
|
52
|
+
const cacheKey = nonEmpty(body.prompt_cache_key);
|
|
53
|
+
if (cacheKey !== null)
|
|
54
|
+
return `k:${hash64(cacheKey)}`;
|
|
55
|
+
const metadata = isRecord(body.metadata) ? body.metadata : null;
|
|
56
|
+
const sessionId = nonEmpty(metadata?.user_id);
|
|
57
|
+
if (sessionId !== null)
|
|
58
|
+
return `s:${hash64(sessionId)}`;
|
|
59
|
+
const turns = turnsOf(body);
|
|
60
|
+
const firstUser = turns.findIndex((turn) => isRecord(turn) && turn.role === "user");
|
|
61
|
+
// A bare string `input` (Responses) is a one-shot with no history to keep.
|
|
62
|
+
if (firstUser === -1)
|
|
63
|
+
return null;
|
|
64
|
+
const prefix = JSON.stringify([
|
|
65
|
+
body.system ?? null,
|
|
66
|
+
body.instructions ?? null,
|
|
67
|
+
turns.slice(0, firstUser + 1),
|
|
68
|
+
]);
|
|
69
|
+
return `p:${hash64(prefix)}`;
|
|
70
|
+
};
|
|
71
|
+
/** `items` with the remembered one first; unchanged when it isn't present. */
|
|
72
|
+
export const preferRemembered = (items, isRemembered) => {
|
|
73
|
+
const index = items.findIndex(isRemembered);
|
|
74
|
+
if (index <= 0)
|
|
75
|
+
return items;
|
|
76
|
+
return [
|
|
77
|
+
items[index],
|
|
78
|
+
...items.slice(0, index),
|
|
79
|
+
...items.slice(index + 1),
|
|
80
|
+
];
|
|
81
|
+
};
|
|
82
|
+
/** Bounded in-process memory; the oldest entry is evicted first. */
|
|
83
|
+
export const createAffinityMemory = (options) => {
|
|
84
|
+
const ttlMs = options?.ttlMs ?? CONVERSATION_AFFINITY_TTL_MS;
|
|
85
|
+
const maxEntries = options?.maxEntries ?? DEFAULT_MAX_ENTRIES;
|
|
86
|
+
const now = options?.now ?? Date.now;
|
|
87
|
+
const entries = new Map();
|
|
88
|
+
return {
|
|
89
|
+
get: (key) => {
|
|
90
|
+
const entry = entries.get(key);
|
|
91
|
+
if (entry === undefined)
|
|
92
|
+
return undefined;
|
|
93
|
+
if (entry.expiresAt <= now()) {
|
|
94
|
+
entries.delete(key);
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
return entry.value;
|
|
98
|
+
},
|
|
99
|
+
set: (key, value) => {
|
|
100
|
+
entries.delete(key);
|
|
101
|
+
entries.set(key, { value, expiresAt: now() + ttlMs });
|
|
102
|
+
while (entries.size > maxEntries) {
|
|
103
|
+
const oldest = entries.keys().next().value;
|
|
104
|
+
if (oldest === undefined)
|
|
105
|
+
break;
|
|
106
|
+
entries.delete(oldest);
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
/** Memory slots, one per routing decision a conversation pins. */
|
|
112
|
+
export const affinitySlot = {
|
|
113
|
+
/** The chain hop (model id) that served. */
|
|
114
|
+
hop: (conversation) => `${conversation}|hop`,
|
|
115
|
+
/** The personal account index that served `provider`. */
|
|
116
|
+
account: (conversation, provider) => `${conversation}|account|${provider}`,
|
|
117
|
+
/** The team share that served `teamModelId`. */
|
|
118
|
+
share: (conversation, teamModelId) => `${conversation}|share|${teamModelId}`,
|
|
119
|
+
/** The supplier device that served `shareId`. */
|
|
120
|
+
device: (conversation, shareId) => `${conversation}|device|${shareId}`,
|
|
121
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Raise-only output-token backfill — the shared rule the cloud dispatch
|
|
3
|
+
* chain and the coreless daemon walker both apply so an alias / binding
|
|
4
|
+
* / pin that resolves to a concrete model gets its live vendor-reported
|
|
5
|
+
* ceiling instead of the client's conservative default for the
|
|
6
|
+
* unrecognised alias id.
|
|
7
|
+
*
|
|
8
|
+
* Lives in `@openllmsh/sdk/wire` (not `@openllm/core`) so the daemon can
|
|
9
|
+
* import it. Same gating as the historical `dispatch-chain` helper:
|
|
10
|
+
* concrete-id requests, unknown ceilings, and already-generous client
|
|
11
|
+
* values all no-op.
|
|
12
|
+
*/
|
|
13
|
+
export type TMaxTokensBackfillArgs = {
|
|
14
|
+
readonly requestedModel: string;
|
|
15
|
+
readonly getOutputTokenLimit: (modelId: string) => number | null;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* When a hop's catalog id differs from the inbound requested id AND the
|
|
19
|
+
* resolved model's native output ceiling is known AND it exceeds the
|
|
20
|
+
* client's value, return that ceiling. Otherwise `null` (leave the
|
|
21
|
+
* client's cap untouched).
|
|
22
|
+
*/
|
|
23
|
+
export declare const backfilledMaxTokens: (modelId: string, clientMaxTokens: number | undefined, args: TMaxTokensBackfillArgs) => number | null;
|
|
24
|
+
/**
|
|
25
|
+
* Effective client output cap on an already-built upstream body.
|
|
26
|
+
* The smallest present sibling wins: a leftover 32k `max_tokens` must
|
|
27
|
+
* still trigger raise-only backfill even when `max_completion_tokens`
|
|
28
|
+
* is already at the ceiling (first-present would miss it and leave
|
|
29
|
+
* the smaller field to shadow upstream).
|
|
30
|
+
*/
|
|
31
|
+
export declare const clientOutputCapFromBody: (body: unknown) => number | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* Raise whichever output-cap fields the built body already carries so a
|
|
34
|
+
* leftover smaller sibling cannot shadow the backfill. Codex Responses
|
|
35
|
+
* bodies omit the field on purpose (`max_output_tokens` 400s) — do not
|
|
36
|
+
* invent it. When no cap field is present on an openai / anthropic /
|
|
37
|
+
* non-Codex Responses body, write the field that wire honors.
|
|
38
|
+
*/
|
|
39
|
+
export declare const raiseOutputCapFields: (body: unknown, raised: number, wire: "anthropic" | "chatgpt" | "openai", codexInstructions?: boolean) => unknown;
|
|
40
|
+
/**
|
|
41
|
+
* Apply raise-only backfill to a built upstream body. `null` get-limit
|
|
42
|
+
* or a no-op rule returns `body` unchanged.
|
|
43
|
+
*/
|
|
44
|
+
export declare const applyOutputTokenBackfill: (body: unknown, args: {
|
|
45
|
+
readonly hopModelId: string;
|
|
46
|
+
readonly rawBody: unknown;
|
|
47
|
+
readonly getOutputTokenLimit: (modelId: string) => number | null;
|
|
48
|
+
readonly wire: "anthropic" | "chatgpt" | "openai";
|
|
49
|
+
readonly codexInstructions?: boolean;
|
|
50
|
+
}) => unknown;
|