@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,715 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* openllm native-API tool group — derived from `@openllmsh/sdk/openapi`
|
|
3
|
+
* operations, so it tracks the spec automatically.
|
|
4
|
+
* Two surfaces are exported:
|
|
5
|
+
* - `openllmToolDefsAll` — every operation (browser chat + execution).
|
|
6
|
+
* - `openllmToolDefs` — the MCP-listed subset (`isMcpExposed`), trimmed
|
|
7
|
+
* to cut agent context bloat.
|
|
8
|
+
* Execution (`byToolName` / `handleOpenllmTool`) always covers the FULL set,
|
|
9
|
+
* so trimming ListTools never makes an operation uncallable. Mutating
|
|
10
|
+
* operations (post/put/patch/delete) carry explicit consent copy in their
|
|
11
|
+
* descriptions.
|
|
12
|
+
*/
|
|
13
|
+
import { createClient } from "@openllmsh/sdk/client";
|
|
14
|
+
import { API_OPERATIONS, resolveUrl } from "@openllmsh/sdk/openapi";
|
|
15
|
+
import generatedSpec from "@openllmsh/sdk/openapi/spec.json" with { type: "json" };
|
|
16
|
+
import { KEEPALIVE_REQUEST_HEADER, OAUTH_PROVIDER_SLUGS, OPENLLM_CHAIN_HEADER, OPENLLM_RESOLVED_MODEL_HEADER, unwrapKeepaliveResponse, } from "@openllmsh/sdk/protocol";
|
|
17
|
+
import { MODELS_TOOL_NAME } from "./model-priority.js";
|
|
18
|
+
const schemaObject = (value) => value !== null && typeof value === "object" && !Array.isArray(value)
|
|
19
|
+
? value
|
|
20
|
+
: undefined;
|
|
21
|
+
/** Resolve only local generated references; media body schemas have no recursive branches. */
|
|
22
|
+
const resolveGeneratedSchema = (value, seen = new Set()) => {
|
|
23
|
+
if (Array.isArray(value))
|
|
24
|
+
return value.map((item) => resolveGeneratedSchema(item, seen));
|
|
25
|
+
const object = schemaObject(value);
|
|
26
|
+
if (object === undefined)
|
|
27
|
+
return value;
|
|
28
|
+
if (typeof object.$ref === "string" &&
|
|
29
|
+
object.$ref.startsWith("#/") &&
|
|
30
|
+
!seen.has(object.$ref)) {
|
|
31
|
+
let target = generatedSpec;
|
|
32
|
+
for (const segment of object.$ref.slice(2).split("/"))
|
|
33
|
+
target =
|
|
34
|
+
schemaObject(target)?.[segment.replace(/~1/g, "/").replace(/~0/g, "~")];
|
|
35
|
+
if (target !== undefined)
|
|
36
|
+
return resolveGeneratedSchema(target, new Set([...seen, object.$ref]));
|
|
37
|
+
}
|
|
38
|
+
return Object.fromEntries(Object.entries(object).map(([key, child]) => [
|
|
39
|
+
key,
|
|
40
|
+
resolveGeneratedSchema(child, seen),
|
|
41
|
+
]));
|
|
42
|
+
};
|
|
43
|
+
const generatedBodySchema = (op) => {
|
|
44
|
+
const paths = schemaObject(generatedSpec.paths);
|
|
45
|
+
const operation = schemaObject(schemaObject(paths?.[op.path])?.[op.method]);
|
|
46
|
+
const content = schemaObject(schemaObject(operation?.requestBody)?.content);
|
|
47
|
+
const schema = schemaObject(content?.["application/json"])?.schema;
|
|
48
|
+
return schemaObject(resolveGeneratedSchema(schema));
|
|
49
|
+
};
|
|
50
|
+
/** MCP tool names must match `[a-zA-Z0-9_-]+` — sanitize the operation id.
|
|
51
|
+
* Exported: the browser chat's tool bridge maps operations back to tool
|
|
52
|
+
* names with the SAME convention (no second naming scheme). */
|
|
53
|
+
export const toolNameFor = (op) => `api_${op.id.replace(/[^a-zA-Z0-9_-]+/g, "_")}`;
|
|
54
|
+
const MUTATING = new Set(["post", "put", "patch", "delete"]);
|
|
55
|
+
const REQUEST_TIMEOUT_MS = 120_000;
|
|
56
|
+
/** The media tools whose `model` is OPTIONAL — the one table. Consumers ask
|
|
57
|
+
* through {@link isMediaOptionalModelTool} rather than re-listing it. */
|
|
58
|
+
const MEDIA_OPTIONAL_MODEL_TOOLS = new Set([
|
|
59
|
+
"api_v1Images_imagesGenerations",
|
|
60
|
+
"api_v1Images_imagesEdits",
|
|
61
|
+
"api_v1Audio_transcriptions",
|
|
62
|
+
"api_v1Audio_speech",
|
|
63
|
+
"api_v1Videos_videosCreate",
|
|
64
|
+
]);
|
|
65
|
+
/** Also read by the browser chat, which marks exactly these `strict: false` —
|
|
66
|
+
* Responses normalizes an omitted `strict` toward strict, which would promote
|
|
67
|
+
* their optional fields to required. */
|
|
68
|
+
export const isMediaOptionalModelTool = (name) => MEDIA_OPTIONAL_MODEL_TOOLS.has(name);
|
|
69
|
+
/** Answers the loop this fixes: an agent filled every optional field, then on
|
|
70
|
+
* a rejection kept the body and swapped the model. So — smallest request,
|
|
71
|
+
* omit `model` rather than invent one (`"auto"` is named because agents reach
|
|
72
|
+
* for it, and it resolves as a literal id), and on a rejection change the FIELD
|
|
73
|
+
* (only what the agent added; a user's own constraint is reported, not
|
|
74
|
+
* silently overridden). */
|
|
75
|
+
const MEDIA_OPTIONAL_MODEL_GUIDANCE = ' Send the smallest request that expresses the user\'s intent — the optional fields are not a checklist, so send an optional key only when the user asked for that specific thing. Model is optional. Omit model entirely for automatic selection: omitting it is the default-selection mechanism (it uses the catalog-ranked media default chain — subscription candidates first, then a compatible API-key tail — and may fall through at runtime after a failed, unaccepted attempt), so never send a placeholder in its place — `model: "auto"` and `model: ""` are both invalid ways to request automatic selection, and `"auto"` in particular is taken as a literal model id. An explicit model is used as requested. If a field is rejected, fix that field and do not retry the same rejected fields under a different model: drop the unsupported options you added on your own, keep every constraint the user gave (voice, format, size, quality and the like), and if one of THOSE is what the provider refuses, report the conflict and the supported alternatives instead of silently changing or dropping it.';
|
|
76
|
+
/** Gravity Index tools: sponsored recommendations, FREE TIER ONLY. Both
|
|
77
|
+
* surfaces drop them for anyone not confirmed free — the MCP server off
|
|
78
|
+
* `fetchTier`, the browser chat off `useProductAccess` — and the gateway
|
|
79
|
+
* refuses paid callers regardless. Keyed by tool name; the value is the
|
|
80
|
+
* whole description (it replaces the generic one, consent copy included —
|
|
81
|
+
* a search changes nothing on the user's account). */
|
|
82
|
+
const GRAVITY_INDEX_TOOLS = new Map([
|
|
83
|
+
[
|
|
84
|
+
"api_gravity_indexSearch",
|
|
85
|
+
"Gravity Index: recommend the best developer service for a need the user has (a database, auth, email/SMS API, payments, hosting, an AI API, …). Returns one recommendation with reasoning, optional install steps and a tracked `click_url`. Call it only when the user actually needs a third-party service. Results are SPONSORED: when you present one, say it is a sponsored recommendation via Gravity, give the `click_url` (never the raw website), and do not present it as your own independent pick. Pass `search_id` back to ask a follow-up.",
|
|
86
|
+
],
|
|
87
|
+
[
|
|
88
|
+
"api_gravity_indexShopSearch",
|
|
89
|
+
"Gravity Index: find physical products the user wants to buy (shoes, electronics, kitchen, …). Returns a ranked list of in-stock products with price, image, merchant and a tracked `click_url`. Only pass filters the user stated. Results are SPONSORED: say so when you present them, link ONLY each product's `click_url`, and never buy anything on the user's behalf.",
|
|
90
|
+
],
|
|
91
|
+
]);
|
|
92
|
+
/** True for a tool listed only to free-tier users. */
|
|
93
|
+
export const isFreeTierOnlyTool = (name) => GRAVITY_INDEX_TOOLS.has(name);
|
|
94
|
+
/** Ops whose body schema is resolved from the spec rather than left opaque. */
|
|
95
|
+
const typedBodyTool = (name) => MEDIA_OPTIONAL_MODEL_TOOLS.has(name) || GRAVITY_INDEX_TOOLS.has(name);
|
|
96
|
+
const descriptionFor = (op) => {
|
|
97
|
+
const gravity = GRAVITY_INDEX_TOOLS.get(toolNameFor(op));
|
|
98
|
+
if (gravity !== undefined)
|
|
99
|
+
return gravity;
|
|
100
|
+
const base = op.summary.length > 0
|
|
101
|
+
? op.summary
|
|
102
|
+
: `${op.method.toUpperCase()} ${op.path}`;
|
|
103
|
+
const wire = ` [${op.method.toUpperCase()} ${op.path}]`;
|
|
104
|
+
const consent = MUTATING.has(op.method)
|
|
105
|
+
? " MUTATING operation — call only when the user explicitly asked for this change; confirm first when destructive."
|
|
106
|
+
: "";
|
|
107
|
+
const name = toolNameFor(op);
|
|
108
|
+
const media = MEDIA_OPTIONAL_MODEL_TOOLS.has(name)
|
|
109
|
+
? MEDIA_OPTIONAL_MODEL_GUIDANCE
|
|
110
|
+
: "";
|
|
111
|
+
return `${base}${wire}${consent}${media}`;
|
|
112
|
+
};
|
|
113
|
+
const inputSchemaFor = (op) => {
|
|
114
|
+
const properties = {};
|
|
115
|
+
const required = [];
|
|
116
|
+
for (const p of op.pathParams) {
|
|
117
|
+
properties[p] = { type: "string", description: `Path parameter \`${p}\`` };
|
|
118
|
+
required.push(p);
|
|
119
|
+
}
|
|
120
|
+
for (const q of op.queryParams) {
|
|
121
|
+
properties[q.name] = {
|
|
122
|
+
type: "string",
|
|
123
|
+
description: `Query parameter \`${q.name}\``,
|
|
124
|
+
};
|
|
125
|
+
if (q.required)
|
|
126
|
+
required.push(q.name);
|
|
127
|
+
}
|
|
128
|
+
if (op.hasBody) {
|
|
129
|
+
properties.body = (typedBodyTool(toolNameFor(op))
|
|
130
|
+
? generatedBodySchema(op)
|
|
131
|
+
: undefined) ?? {
|
|
132
|
+
type: "object",
|
|
133
|
+
description: "JSON request body — see the operation's schema in the OpenAPI spec (`openllm api --spec`).",
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
type: "object",
|
|
138
|
+
properties,
|
|
139
|
+
...(MEDIA_OPTIONAL_MODEL_TOOLS.has(toolNameFor(op))
|
|
140
|
+
? { additionalProperties: false }
|
|
141
|
+
: {}),
|
|
142
|
+
...(required.length > 0 ? { required } : {}),
|
|
143
|
+
};
|
|
144
|
+
};
|
|
145
|
+
/** Paths no agent may reach — not listed, not executable, not in web chat.
|
|
146
|
+
* `/marketplace/launch` returns the user's DECRYPTED integration secrets
|
|
147
|
+
* for the launcher to write into a 0600 run dir; as a tool it would put a
|
|
148
|
+
* vendor key straight into model context. `/vault/passkey*` manages the
|
|
149
|
+
* passkey wraps that unlock the vault: browser-session only (an `sk-llm`
|
|
150
|
+
* caller gets 403), and an agent revoking a user's unlock method is not a
|
|
151
|
+
* delegation anyone asked for. `/vault/handoff*` hands the vault to a new
|
|
152
|
+
* device: an agent must neither ask for it (every request prompts the user's
|
|
153
|
+
* devices) nor see or answer one — browser-session only, like the passkeys.
|
|
154
|
+
* `/vault/device-control` and `/daemon/attestations` hold the device-control
|
|
155
|
+
* trust root for agent sessions — same reasoning.
|
|
156
|
+
* Web chat runs the full tool list with the session cookie, so the handlers'
|
|
157
|
+
* own `sk-llm` refusal is not enough on its own. */
|
|
158
|
+
const AGENT_FORBIDDEN_PATHS = new Set([
|
|
159
|
+
// Browser ad plumbing (the /chat ad slot and the pixel's retention event),
|
|
160
|
+
// not agent capabilities.
|
|
161
|
+
"/gravity/app-open",
|
|
162
|
+
"/gravity/chat-ad",
|
|
163
|
+
"/marketplace/launch",
|
|
164
|
+
// Signing browsers out is the account owner's act, from Settings →
|
|
165
|
+
// Sessions; the gateway refuses keys there anyway.
|
|
166
|
+
"/user/sessions/revoke",
|
|
167
|
+
"/user/sessions/revoke-others",
|
|
168
|
+
"/vault/passkey",
|
|
169
|
+
"/vault/passkey/{id}",
|
|
170
|
+
"/vault/handoff",
|
|
171
|
+
"/vault/handoff/pending",
|
|
172
|
+
"/vault/handoff/{id}",
|
|
173
|
+
"/vault/handoff/{id}/approve",
|
|
174
|
+
"/vault/handoff/{id}/cancel",
|
|
175
|
+
"/vault/handoff/{id}/claim",
|
|
176
|
+
"/vault/handoff/{id}/deny",
|
|
177
|
+
// Device-control trust material (the phrase-derived key that gates agent
|
|
178
|
+
// sessions on the user's machines, and the attestations of which daemon
|
|
179
|
+
// keys it trusts). Session-only; an agent writing either would let it
|
|
180
|
+
// authorise itself onto the user's devices.
|
|
181
|
+
"/vault/device-control",
|
|
182
|
+
"/daemon/attestations",
|
|
183
|
+
// OAuth connections: what a business may do with the user's account is the
|
|
184
|
+
// user's consent, never an agent's (an agent widening or revoking one is
|
|
185
|
+
// not a delegation). Pickup and revoke are the business's own calls.
|
|
186
|
+
"/connect/grants",
|
|
187
|
+
"/connect/grants/{id}",
|
|
188
|
+
"/connect/grants/reconsent",
|
|
189
|
+
"/connect/grants/pickup",
|
|
190
|
+
"/connect/grants/revoke",
|
|
191
|
+
// Connections → Your apps: making an app or a new secret returns the
|
|
192
|
+
// client secret, and deleting one cuts off every person connected to it.
|
|
193
|
+
// The developer's own act, in the browser.
|
|
194
|
+
"/developer/apps",
|
|
195
|
+
"/developer/apps/{client_id}",
|
|
196
|
+
"/developer/apps/{client_id}/secret",
|
|
197
|
+
"/developer/apps/{client_id}/sealed",
|
|
198
|
+
// Asking OpenLLM to review an app (and reading those applications) speaks
|
|
199
|
+
// for the developer to OpenLLM's team; also the developer's own act.
|
|
200
|
+
"/developer/apps/{client_id}/review",
|
|
201
|
+
"/developer/applications",
|
|
202
|
+
// CLI OpenLLM OAuth approval (`/cli/authorize/[id]`): viewing, approving or
|
|
203
|
+
// denying a waiting CLI login hands an account key to a terminal (or refuses
|
|
204
|
+
// it). That is the signed-in user's act in the browser; as a web-chat tool it
|
|
205
|
+
// would run under the session cookie and let an agent let a CLI in.
|
|
206
|
+
"/cli/auth/{id}/approve",
|
|
207
|
+
"/cli/auth/{id}/deny",
|
|
208
|
+
"/cli/auth/{id}/view",
|
|
209
|
+
]);
|
|
210
|
+
const AGENT_OPERATIONS = API_OPERATIONS.filter((op) => !AGENT_FORBIDDEN_PATHS.has(op.path));
|
|
211
|
+
const byToolName = new Map(AGENT_OPERATIONS.map((op) => [toolNameFor(op), op]));
|
|
212
|
+
/** Endpoints that require a browser SESSION, not an `sk-llm-…` key, and so
|
|
213
|
+
* always 401 from the CLI. `/user/auth-methods` reads the auth service's
|
|
214
|
+
* `list-accounts` with the caller's cookies (see `authMethodsHandler`) and
|
|
215
|
+
* refuses the key path outright; `/user/sessions` does the same with
|
|
216
|
+
* `list-sessions` (`listAuthSessionsHandler`). The vault device-handoff reads
|
|
217
|
+
* (`vaultHandoffPendingHandler` / `vaultHandoffStatusHandler`) refuse any
|
|
218
|
+
* request presenting a key with a 403. Execution stays possible via
|
|
219
|
+
* `byToolName`; this only keeps them out of ListTools. */
|
|
220
|
+
const SESSION_ONLY_PATHS = new Set([
|
|
221
|
+
"/connect/apps",
|
|
222
|
+
"/connect/clients/{client_id}",
|
|
223
|
+
"/connect/history",
|
|
224
|
+
"/keys",
|
|
225
|
+
"/user/auth-methods",
|
|
226
|
+
"/user/sessions",
|
|
227
|
+
"/vault/handoff/pending",
|
|
228
|
+
"/vault/handoff/{id}",
|
|
229
|
+
"/vault/migrate/rows",
|
|
230
|
+
]);
|
|
231
|
+
/** Gateway-admin dashboards (`requireAdmin`): cross-user aggregates no agent
|
|
232
|
+
* acting for one user should be offered. */
|
|
233
|
+
const ADMIN_ONLY_PATHS = new Set([
|
|
234
|
+
"/stats/admin",
|
|
235
|
+
"/stats/admin/value",
|
|
236
|
+
]);
|
|
237
|
+
/** Browser/ops plumbing with no use to an agent: listing them only spends
|
|
238
|
+
* its context. */
|
|
239
|
+
const NOT_FOR_AGENTS_PATHS = new Set([
|
|
240
|
+
"/cookie-consent/region",
|
|
241
|
+
"/health",
|
|
242
|
+
"/public/usage-index",
|
|
243
|
+
"/version",
|
|
244
|
+
]);
|
|
245
|
+
/**
|
|
246
|
+
* The permission each listed non-`/v1` operation needs, by path prefix —
|
|
247
|
+
* the same gate its handler declares (`requireUser({ permission })`).
|
|
248
|
+
* Longest prefix wins. `/v1/*` needs `inference.use`; anything else NOT
|
|
249
|
+
* listed needs `account.manage`, so a new endpoint stays off a run-AI key's
|
|
250
|
+
* list until it is mapped here.
|
|
251
|
+
*/
|
|
252
|
+
const PERMISSION_BY_PREFIX = [
|
|
253
|
+
["/user/tier", "inference.use"],
|
|
254
|
+
["/marketplace/catalog", "mcp.use"],
|
|
255
|
+
["/marketplace/installations", "mcp.use"],
|
|
256
|
+
["/media", "media.read"],
|
|
257
|
+
["/sessions", "sessions.read"],
|
|
258
|
+
["/billing", "billing.manage"],
|
|
259
|
+
["/config", "config.manage"],
|
|
260
|
+
["/credentials", "credentials.manage"],
|
|
261
|
+
["/providers", "credentials.manage"],
|
|
262
|
+
["/stats", "stats.read"],
|
|
263
|
+
["/keys", "keys.manage"],
|
|
264
|
+
];
|
|
265
|
+
/** What calling `op` needs from the key (see {@link PERMISSION_BY_PREFIX}). */
|
|
266
|
+
export const permissionForOperation = (op) => {
|
|
267
|
+
if (op.path.startsWith("/v1/"))
|
|
268
|
+
return "inference.use";
|
|
269
|
+
let best;
|
|
270
|
+
for (const entry of PERMISSION_BY_PREFIX) {
|
|
271
|
+
const [prefix] = entry;
|
|
272
|
+
const matches = op.path === prefix || op.path.startsWith(`${prefix}/`);
|
|
273
|
+
if (matches && (best === undefined || prefix.length > best[0].length))
|
|
274
|
+
best = entry;
|
|
275
|
+
}
|
|
276
|
+
return best?.[1] ?? "account.manage";
|
|
277
|
+
};
|
|
278
|
+
/** Which operations surface as MCP tools an agent SEES (ListTools). This
|
|
279
|
+
* trims context bloat; it does NOT gate execution — `byToolName` above
|
|
280
|
+
* keeps every operation callable, and the browser chat imports the full
|
|
281
|
+
* `openllmToolDefsAll` below. Denylist:
|
|
282
|
+
* 1. `/integrations/memory/*` — the OpenLLM Memory marketplace entry's
|
|
283
|
+
* MCP group already exposes these; the raw HTTP mirrors are dupes.
|
|
284
|
+
* 2. Non-`/v1/*` mutations (post/put/patch/delete) — account/config/
|
|
285
|
+
* vault/keys/sessions/credentials writes an agent shouldn't drive
|
|
286
|
+
* through MCP. Inference (`/v1/*`) and all read-only GETs stay.
|
|
287
|
+
* 3. {@link SESSION_ONLY_PATHS} — read-only GETs the gateway serves ONLY to
|
|
288
|
+
* a browser session. The CLI authenticates with an API key and has no
|
|
289
|
+
* session cookie, so listing them spends an agent's context on a call
|
|
290
|
+
* that can only ever come back 401. */
|
|
291
|
+
const isMcpExposed = (op) => {
|
|
292
|
+
if (op.path.startsWith("/integrations/memory"))
|
|
293
|
+
return false;
|
|
294
|
+
// POST, but a read: a search, not an account write (tier-gated by caller).
|
|
295
|
+
if (GRAVITY_INDEX_TOOLS.has(toolNameFor(op)))
|
|
296
|
+
return true;
|
|
297
|
+
if (MUTATING.has(op.method) && !op.path.startsWith("/v1/"))
|
|
298
|
+
return false;
|
|
299
|
+
if (SESSION_ONLY_PATHS.has(op.path))
|
|
300
|
+
return false;
|
|
301
|
+
if (ADMIN_ONLY_PATHS.has(op.path))
|
|
302
|
+
return false;
|
|
303
|
+
if (NOT_FOR_AGENTS_PATHS.has(op.path))
|
|
304
|
+
return false;
|
|
305
|
+
return true;
|
|
306
|
+
};
|
|
307
|
+
const toolDef = (op) => ({
|
|
308
|
+
name: toolNameFor(op),
|
|
309
|
+
description: descriptionFor(op),
|
|
310
|
+
inputSchema: inputSchemaFor(op),
|
|
311
|
+
permission: permissionForOperation(op),
|
|
312
|
+
});
|
|
313
|
+
/** The FULL native-API tool surface — every operation. Consumed by the
|
|
314
|
+
* browser chat tool bridge (`lib/chat/tools.ts`), which intentionally
|
|
315
|
+
* exposes inference + account ops for in-chat delegation. */
|
|
316
|
+
export const openllmToolDefsAll = AGENT_OPERATIONS.map(toolDef);
|
|
317
|
+
/** Browser-safe identification/limit shared with the CLI-only local adapter. */
|
|
318
|
+
export const TRANSCRIPTION_TOOL_NAME = "api_v1Audio_transcriptions";
|
|
319
|
+
export const MAX_TRANSCRIPTION_BYTES = 25 * 1024 * 1024;
|
|
320
|
+
/** MCP-listed subset, with local input contracts where the CLI owns the IO. */
|
|
321
|
+
export const openllmToolDefs = AGENT_OPERATIONS.filter(isMcpExposed).map((op) => {
|
|
322
|
+
const def = toolDef(op);
|
|
323
|
+
if (def.name === MODELS_TOOL_NAME) {
|
|
324
|
+
return {
|
|
325
|
+
...def,
|
|
326
|
+
description: `${def.description} Subscription providers: ${OAUTH_PROVIDER_SLUGS.join(", ")}. Direct subscription provider/model IDs are listed first. Use exact returned IDs and check capabilities, audio formats, limits, and provider_type. Media inference may omit model (catalog-ranked chain; runtime fallback after a failed unaccepted attempt). Aliases are configurable fallback chains and may invoke API-key providers; they are not subscription guarantees. This is configured availability, not live readiness or remaining quota.`,
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
if (def.name !== TRANSCRIPTION_TOOL_NAME)
|
|
330
|
+
return def;
|
|
331
|
+
return {
|
|
332
|
+
...def,
|
|
333
|
+
description: `${def.description} Transcribe a local audio file by path; never send audio bytes or base64. Relative paths resolve from the MCP server working directory. Input and converted audio are limited to 25 MiB. Accepts any common audio or video file as it is (WAV, MP3, M4A/MP4/MOV, AAC, CAF, AIFF, FLAC, Ogg/Opus, WebM/MKV, WMA, AMR and more); never convert it yourself. With model omitted, models are tried in catalog order and the audio is converted (system ffmpeg on PATH) to whatever each model accepts, so the format never changes which model is used.`,
|
|
334
|
+
inputSchema: {
|
|
335
|
+
type: "object",
|
|
336
|
+
properties: {
|
|
337
|
+
path: {
|
|
338
|
+
type: "string",
|
|
339
|
+
minLength: 1,
|
|
340
|
+
description: "Local audio file path (absolute or relative to the MCP server working directory).",
|
|
341
|
+
},
|
|
342
|
+
model: {
|
|
343
|
+
type: "string",
|
|
344
|
+
minLength: 1,
|
|
345
|
+
description: "Optional model; omit to walk the catalog-ranked transcription chain, falling through to the next model on failure.",
|
|
346
|
+
},
|
|
347
|
+
language: {
|
|
348
|
+
type: "string",
|
|
349
|
+
minLength: 1,
|
|
350
|
+
description: "Optional language code, for example en.",
|
|
351
|
+
},
|
|
352
|
+
},
|
|
353
|
+
required: ["path"],
|
|
354
|
+
additionalProperties: false,
|
|
355
|
+
},
|
|
356
|
+
};
|
|
357
|
+
});
|
|
358
|
+
/** Names in the MCP-exposed subset. The `openllm mcp` server gates CallTool
|
|
359
|
+
* on THIS — not `isOpenllmTool` — so a client cannot invoke a hidden
|
|
360
|
+
* (generated-but-untrimmed) operation it was never offered. */
|
|
361
|
+
const mcpListedNames = new Set(openllmToolDefs.map((t) => t.name));
|
|
362
|
+
/** True when `name` is a native-API tool the CLI can EXECUTE. The full set
|
|
363
|
+
* (every generated operation) — used by the browser chat bridge, which
|
|
364
|
+
* exposes the whole surface. NOT an authorization gate for the MCP server;
|
|
365
|
+
* that uses `isMcpListedTool`. */
|
|
366
|
+
export const isOpenllmTool = (name) => byToolName.has(name);
|
|
367
|
+
/** True when `name` is in the MCP-LISTED subset (`openllmToolDefs`). The
|
|
368
|
+
* `openllm mcp` CallTool handler uses this to reject tools it never
|
|
369
|
+
* advertised, so trimming ListTools also trims what can be invoked. */
|
|
370
|
+
export const isMcpListedTool = (name) => mcpListedNames.has(name);
|
|
371
|
+
const textResult = (text, isError = false) => ({
|
|
372
|
+
content: [{ type: "text", text }],
|
|
373
|
+
...(isError ? { isError: true } : {}),
|
|
374
|
+
});
|
|
375
|
+
/** Which model served — or refused — this request, from the headers the
|
|
376
|
+
* gateway attaches on BOTH outcomes. Empty when nothing was resolved. */
|
|
377
|
+
const attributionFromHeaders = (headers) => {
|
|
378
|
+
const resolved = headers.get(OPENLLM_RESOLVED_MODEL_HEADER)?.trim() ?? "";
|
|
379
|
+
if (resolved === "")
|
|
380
|
+
return "";
|
|
381
|
+
const chain = (headers.get(OPENLLM_CHAIN_HEADER) ?? "")
|
|
382
|
+
.split(",")
|
|
383
|
+
.map((hop) => hop.trim())
|
|
384
|
+
.filter((hop) => hop !== "");
|
|
385
|
+
return chain.length > 1
|
|
386
|
+
? `Served by ${resolved} (chain: ${chain.join(" → ")}).`
|
|
387
|
+
: `Served by ${resolved}.`;
|
|
388
|
+
};
|
|
389
|
+
const withAttribution = (text, headers) => {
|
|
390
|
+
const attribution = attributionFromHeaders(headers);
|
|
391
|
+
return attribution === "" ? text : `${text} ${attribution}`;
|
|
392
|
+
};
|
|
393
|
+
/** Status line and provider body (message, `param`, `code`) verbatim;
|
|
394
|
+
* attribution is APPENDED, and absent when no model was ever selected. */
|
|
395
|
+
const responseErrorResult = async (res) => {
|
|
396
|
+
const text = await res.text().catch(() => "");
|
|
397
|
+
return textResult(withAttribution(`HTTP ${res.status}: ${text}`, res.headers), true);
|
|
398
|
+
};
|
|
399
|
+
const isImageGenerationBody = (body) => typeof body === "object" &&
|
|
400
|
+
body !== null &&
|
|
401
|
+
"data" in body &&
|
|
402
|
+
Array.isArray(body.data);
|
|
403
|
+
/**
|
|
404
|
+
* Split an SSE body into frames.
|
|
405
|
+
*
|
|
406
|
+
* Follows the event-stream framing rules the gateway emits against: lines end
|
|
407
|
+
* with LF, CRLF or CR; a blank line dispatches the frame; a line starting
|
|
408
|
+
* with `:` is a COMMENT and carries no data (the gateway uses comments for
|
|
409
|
+
* keepalives and for the "partials unavailable" note, precisely so no client
|
|
410
|
+
* can mistake them for progress); repeated `data:` lines within one frame are
|
|
411
|
+
* joined with a newline.
|
|
412
|
+
*/
|
|
413
|
+
const parseSseFrames = (raw) => {
|
|
414
|
+
const frames = [];
|
|
415
|
+
let event = null;
|
|
416
|
+
let data = [];
|
|
417
|
+
const flush = () => {
|
|
418
|
+
if (data.length > 0)
|
|
419
|
+
frames.push({ event, data: data.join("\n") });
|
|
420
|
+
event = null;
|
|
421
|
+
data = [];
|
|
422
|
+
};
|
|
423
|
+
for (const line of raw.split(/\r\n|\r|\n/)) {
|
|
424
|
+
if (line === "") {
|
|
425
|
+
flush();
|
|
426
|
+
continue;
|
|
427
|
+
}
|
|
428
|
+
if (line.startsWith(":"))
|
|
429
|
+
continue;
|
|
430
|
+
const colon = line.indexOf(":");
|
|
431
|
+
const field = colon === -1 ? line : line.slice(0, colon);
|
|
432
|
+
const rawValue = colon === -1 ? "" : line.slice(colon + 1);
|
|
433
|
+
const value = rawValue.startsWith(" ") ? rawValue.slice(1) : rawValue;
|
|
434
|
+
if (field === "event")
|
|
435
|
+
event = value;
|
|
436
|
+
else if (field === "data")
|
|
437
|
+
data.push(value);
|
|
438
|
+
}
|
|
439
|
+
// A stream cut off mid-frame never dispatched its last frame; the spec
|
|
440
|
+
// discards it, and so do we — a truncated frame is not a result.
|
|
441
|
+
return frames;
|
|
442
|
+
};
|
|
443
|
+
const sseFrameError = (event, parsed) => {
|
|
444
|
+
const error = typeof parsed === "object" && parsed !== null && "error" in parsed
|
|
445
|
+
? parsed.error
|
|
446
|
+
: null;
|
|
447
|
+
const message = typeof error === "object" &&
|
|
448
|
+
error !== null &&
|
|
449
|
+
"message" in error &&
|
|
450
|
+
typeof error.message === "string"
|
|
451
|
+
? error.message
|
|
452
|
+
: null;
|
|
453
|
+
if (message !== null)
|
|
454
|
+
return message;
|
|
455
|
+
return event === "error" ? "The image stream reported an error." : null;
|
|
456
|
+
};
|
|
457
|
+
const aggregateImageSseText = (raw) => {
|
|
458
|
+
const data = [];
|
|
459
|
+
let created = null;
|
|
460
|
+
let errorMessage = null;
|
|
461
|
+
for (const frame of parseSseFrames(raw)) {
|
|
462
|
+
let parsed;
|
|
463
|
+
try {
|
|
464
|
+
parsed = JSON.parse(frame.data);
|
|
465
|
+
}
|
|
466
|
+
catch {
|
|
467
|
+
// An unparseable frame is not a result. Skipping it keeps a provider's
|
|
468
|
+
// unknown extension from failing a generation that otherwise succeeded.
|
|
469
|
+
continue;
|
|
470
|
+
}
|
|
471
|
+
const failure = sseFrameError(frame.event, parsed);
|
|
472
|
+
if (failure !== null) {
|
|
473
|
+
errorMessage = failure;
|
|
474
|
+
continue;
|
|
475
|
+
}
|
|
476
|
+
if (typeof parsed !== "object" || parsed === null)
|
|
477
|
+
continue;
|
|
478
|
+
const event = parsed;
|
|
479
|
+
// Partials are successive PREVIEWS of one image, not fragments of it, so
|
|
480
|
+
// they are discarded rather than concatenated.
|
|
481
|
+
if (event.type !== "image_generation.completed")
|
|
482
|
+
continue;
|
|
483
|
+
if (created === null && typeof event.created_at === "number")
|
|
484
|
+
created = event.created_at;
|
|
485
|
+
data.push({
|
|
486
|
+
...(typeof event.b64_json === "string"
|
|
487
|
+
? { b64_json: event.b64_json }
|
|
488
|
+
: {}),
|
|
489
|
+
...(typeof event.url === "string" ? { url: event.url } : {}),
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
if (errorMessage !== null) {
|
|
493
|
+
// Terminal, but never silent about what DID land: a per-image persistence
|
|
494
|
+
// failure can follow completions, and those urls stay useful.
|
|
495
|
+
const urls = data
|
|
496
|
+
.map((item) => (typeof item.url === "string" ? item.url : null))
|
|
497
|
+
.filter((url) => url !== null);
|
|
498
|
+
return {
|
|
499
|
+
kind: "error",
|
|
500
|
+
message: urls.length === 0
|
|
501
|
+
? errorMessage
|
|
502
|
+
: `${errorMessage} Images that were saved: ${urls.join(" ")}`,
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
if (data.length === 0) {
|
|
506
|
+
return {
|
|
507
|
+
kind: "error",
|
|
508
|
+
message: "The image stream ended without a completed image. Nothing was generated.",
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
return { kind: "body", body: { created: created ?? 0, data } };
|
|
512
|
+
};
|
|
513
|
+
const isEventStream = (headers) => (headers.get("content-type") ?? "")
|
|
514
|
+
.toLowerCase()
|
|
515
|
+
.includes("text/event-stream");
|
|
516
|
+
const imageResult = async (body, config, label, headers) => {
|
|
517
|
+
if (!isImageGenerationBody(body)) {
|
|
518
|
+
return textResult(JSON.stringify(body, null, 2));
|
|
519
|
+
}
|
|
520
|
+
// URLs only — never the bytes. A tool result lives in the client's session
|
|
521
|
+
// history and is resent on every later turn, so an embedded multi-MB base64
|
|
522
|
+
// image floods the context and eventually trips request-size limits (a
|
|
523
|
+
// Vercel 413 on /v1/responses). The durable URL is the deliverable; a
|
|
524
|
+
// client that wants to display the image downloads it itself.
|
|
525
|
+
const urls = [];
|
|
526
|
+
const revisedPrompts = [];
|
|
527
|
+
let unsaved = 0;
|
|
528
|
+
for (const item of body.data) {
|
|
529
|
+
if (typeof item.url === "string" && item.url.length > 0) {
|
|
530
|
+
urls.push(new URL(item.url, config.baseUrl).toString());
|
|
531
|
+
}
|
|
532
|
+
else {
|
|
533
|
+
unsaved += 1;
|
|
534
|
+
}
|
|
535
|
+
if (typeof item.revised_prompt === "string") {
|
|
536
|
+
revisedPrompts.push(item.revised_prompt);
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
const notes = [
|
|
540
|
+
withAttribution(label, headers),
|
|
541
|
+
...urls,
|
|
542
|
+
...(unsaved > 0
|
|
543
|
+
? [
|
|
544
|
+
`${unsaved} image(s) could not be saved to the media library, so no URL is available for them.`,
|
|
545
|
+
]
|
|
546
|
+
: []),
|
|
547
|
+
...revisedPrompts.map((prompt) => `Revised prompt: ${prompt}`),
|
|
548
|
+
];
|
|
549
|
+
return textResult(notes.join(" "), urls.length === 0);
|
|
550
|
+
};
|
|
551
|
+
const mediaRedirectKindFor = (op) => {
|
|
552
|
+
if (op.path === "/v1/audio/speech")
|
|
553
|
+
return "audio";
|
|
554
|
+
if (op.path === "/v1/videos/{video_id}/content")
|
|
555
|
+
return "video";
|
|
556
|
+
return null;
|
|
557
|
+
};
|
|
558
|
+
const mediaRedirectResult = async (config, op, args, kind) => {
|
|
559
|
+
const url = resolveUrl(config, op, args);
|
|
560
|
+
const body = op.hasBody && args.body !== undefined
|
|
561
|
+
? JSON.stringify(args.body)
|
|
562
|
+
: undefined;
|
|
563
|
+
const client = createClient({
|
|
564
|
+
origin: config.baseUrl,
|
|
565
|
+
apiKey: config.apiKey,
|
|
566
|
+
transport: {
|
|
567
|
+
fetch: globalThis.fetch.bind(globalThis),
|
|
568
|
+
websocket: WebSocket,
|
|
569
|
+
},
|
|
570
|
+
});
|
|
571
|
+
let res;
|
|
572
|
+
try {
|
|
573
|
+
res = await client.http.request(url, {
|
|
574
|
+
method: op.method.toUpperCase(),
|
|
575
|
+
headers: {
|
|
576
|
+
...(body === undefined ? {} : { "content-type": "application/json" }),
|
|
577
|
+
},
|
|
578
|
+
...(body === undefined ? {} : { body }),
|
|
579
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
|
|
580
|
+
});
|
|
581
|
+
}
|
|
582
|
+
finally {
|
|
583
|
+
client.close();
|
|
584
|
+
}
|
|
585
|
+
if (!res.ok)
|
|
586
|
+
return responseErrorResult(res);
|
|
587
|
+
await res.body?.cancel();
|
|
588
|
+
const mediaUrl = res.headers.get("x-openllm-media-url");
|
|
589
|
+
if (mediaUrl === null || mediaUrl.length === 0) {
|
|
590
|
+
return textResult(withAttribution(`HTTP ${res.status}: missing media url header`, res.headers), true);
|
|
591
|
+
}
|
|
592
|
+
const durableUrl = new URL(mediaUrl, config.baseUrl).toString();
|
|
593
|
+
return textResult(withAttribution(`${kind === "video" ? "Video" : "Audio"} generated — ${durableUrl}`, res.headers));
|
|
594
|
+
};
|
|
595
|
+
export const handleOpenllmTool = async (name, args, config) => {
|
|
596
|
+
const op = byToolName.get(name);
|
|
597
|
+
if (op === undefined) {
|
|
598
|
+
return textResult(`Unknown tool: ${name}`, true);
|
|
599
|
+
}
|
|
600
|
+
if (op.path === "/v1/videos" && op.method === "post") {
|
|
601
|
+
const properties = schemaObject(inputSchemaFor(op).properties) ?? {};
|
|
602
|
+
if (Object.keys(args).some((key) => !Object.hasOwn(properties, key)))
|
|
603
|
+
return textResult("Invalid video tool envelope. Put canonical fields inside body; use input_image for a starting frame or reference_images for subject guidance, not input_reference.", true);
|
|
604
|
+
}
|
|
605
|
+
try {
|
|
606
|
+
const mediaRedirectKind = mediaRedirectKindFor(op);
|
|
607
|
+
if (mediaRedirectKind !== null) {
|
|
608
|
+
return await mediaRedirectResult(config, op, args, mediaRedirectKind);
|
|
609
|
+
}
|
|
610
|
+
const client = createClient({
|
|
611
|
+
origin: config.baseUrl,
|
|
612
|
+
apiKey: config.apiKey,
|
|
613
|
+
transport: {
|
|
614
|
+
fetch: globalThis.fetch.bind(globalThis),
|
|
615
|
+
websocket: WebSocket,
|
|
616
|
+
},
|
|
617
|
+
});
|
|
618
|
+
let res;
|
|
619
|
+
try {
|
|
620
|
+
res = await client.http.call(op, args);
|
|
621
|
+
}
|
|
622
|
+
finally {
|
|
623
|
+
client.close();
|
|
624
|
+
}
|
|
625
|
+
const text = typeof res.body === "string"
|
|
626
|
+
? res.body
|
|
627
|
+
: JSON.stringify(res.body, null, 2);
|
|
628
|
+
// Name the model that refused, so a retry fixes the FIELD, not the model.
|
|
629
|
+
if (!res.ok)
|
|
630
|
+
return textResult(withAttribution(`HTTP ${res.status}: ${text}`, res.headers), true);
|
|
631
|
+
if (op.path === "/v1/images/generations" ||
|
|
632
|
+
op.path === "/v1/images/edits") {
|
|
633
|
+
const label = op.path === "/v1/images/edits" ? "Image edited." : "Image generated.";
|
|
634
|
+
// The RESPONSE decides how it is read — the declared content type, not
|
|
635
|
+
// a guess at the body's shape. An ordinary JSON answer takes the
|
|
636
|
+
// unchanged path below; only a real event stream is aggregated.
|
|
637
|
+
if (!isEventStream(res.headers)) {
|
|
638
|
+
return imageResult(res.body, config, label, res.headers);
|
|
639
|
+
}
|
|
640
|
+
const aggregated = aggregateImageSseText(text);
|
|
641
|
+
if (aggregated.kind === "error") {
|
|
642
|
+
// An HTTP 200 carrying a terminal `error` frame was still served by
|
|
643
|
+
// some model; don't let it be the one failure shape that hides it.
|
|
644
|
+
return textResult(withAttribution(aggregated.message, res.headers), true);
|
|
645
|
+
}
|
|
646
|
+
return imageResult(aggregated.body, config, label, res.headers);
|
|
647
|
+
}
|
|
648
|
+
if (op.path === "/v1/audio/transcriptions" || op.path === "/v1/videos") {
|
|
649
|
+
return textResult(withAttribution(text, res.headers));
|
|
650
|
+
}
|
|
651
|
+
return textResult(text);
|
|
652
|
+
}
|
|
653
|
+
catch (err) {
|
|
654
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
655
|
+
return textResult(`Error: ${msg}`, true);
|
|
656
|
+
}
|
|
657
|
+
};
|
|
658
|
+
/** A transcription answers with one whole body, after the provider has
|
|
659
|
+
* processed every second of audio (whisper-1 took ~16 s per minute) and
|
|
660
|
+
* the upload has crossed the caller's uplink. Wait as long as the gateway
|
|
661
|
+
* function may run (`maxDuration = 300`), not the generic tool ceiling. */
|
|
662
|
+
export const TRANSCRIPTION_TIMEOUT_MS = 300_000;
|
|
663
|
+
/** The local daemon has no function time limit, and a subscription STT
|
|
664
|
+
* (Grok) takes longer than real time: 5 minutes of audio took ~380 s. */
|
|
665
|
+
export const LOCAL_TRANSCRIPTION_TIMEOUT_MS = 900_000;
|
|
666
|
+
/**
|
|
667
|
+
* Uploads audio to `/v1/audio/transcriptions` as multipart — the raw bytes,
|
|
668
|
+
* not a base64 data URL in JSON (a third larger, fully buffered on both
|
|
669
|
+
* ends). The result reads like {@link handleOpenllmTool}'s: the body plus
|
|
670
|
+
* the attribution of the model that served (or refused) it.
|
|
671
|
+
*/
|
|
672
|
+
export const uploadTranscription = async (form, config, timeoutMs = TRANSCRIPTION_TIMEOUT_MS) => {
|
|
673
|
+
const client = createClient({
|
|
674
|
+
origin: config.baseUrl,
|
|
675
|
+
apiKey: config.apiKey,
|
|
676
|
+
transport: {
|
|
677
|
+
// Bun's fetch gives up after ~360 s without response headers, and a
|
|
678
|
+
// local daemon answers only once the provider is done (Grok took
|
|
679
|
+
// ~380 s for 5 minutes of audio). `timeout: false` lifts that; the
|
|
680
|
+
// signal below still bounds the call. Other runtimes ignore the key.
|
|
681
|
+
fetch: (input, init) => globalThis.fetch(input, { ...init, timeout: false }),
|
|
682
|
+
websocket: WebSocket,
|
|
683
|
+
},
|
|
684
|
+
});
|
|
685
|
+
try {
|
|
686
|
+
// Opt in to heartbeat bytes so a long recording survives the edge
|
|
687
|
+
// proxy's ~100 s silence limit; the envelope unwraps to the real answer.
|
|
688
|
+
const res = await unwrapKeepaliveResponse(await client.http.request("/v1/audio/transcriptions", {
|
|
689
|
+
method: "POST",
|
|
690
|
+
headers: { [KEEPALIVE_REQUEST_HEADER]: "1" },
|
|
691
|
+
body: form,
|
|
692
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
693
|
+
}));
|
|
694
|
+
if (!res.ok)
|
|
695
|
+
return await responseErrorResult(res);
|
|
696
|
+
const raw = await res.text();
|
|
697
|
+
let text = raw;
|
|
698
|
+
if ((res.headers.get("content-type") ?? "").includes("application/json")) {
|
|
699
|
+
try {
|
|
700
|
+
text = JSON.stringify(JSON.parse(raw), null, 2);
|
|
701
|
+
}
|
|
702
|
+
catch {
|
|
703
|
+
text = raw;
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
return textResult(withAttribution(text, res.headers));
|
|
707
|
+
}
|
|
708
|
+
catch (err) {
|
|
709
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
710
|
+
return textResult(`Error: ${msg}`, true);
|
|
711
|
+
}
|
|
712
|
+
finally {
|
|
713
|
+
client.close();
|
|
714
|
+
}
|
|
715
|
+
};
|