Dashboard › opencode › Distillation
9197eb46-a16d-4139-a514-8069dffd3f9a["lore_tm_v1_QM--Stet5go7NHVWtzDHj-XG7i-Ln_Z1e55WDk7c0Gs","lore_tm_v1_k6iw4KQmvRnS8U-VDTD490j9BjHpphhwyR8D1OY2qoE","lore_tm_v1_Fg0_HI7hoChbbMO7JS_9kmeE0D5tSvKYsLWVV_7ePX8","lore_tm_v1_e6afT5vcSstuFxiKfRZHuqMSWu5EQAt7lSGacrEyH0w"]
/home/byk/Code/opencode-lore-v2/packages/opencode/src/internal.ts:1-14 keeps internal helpers out of plugin entry module ./index.ts because OpenCode’s legacy getServerPlugin / getLegacyPlugins loader invokes every exported function as a plugin instance. Exporting applyLoreProviderConfig there previously inserted its undefined return into the hooks array and caused undefined is not an object (evaluating 'A.event') on first hook dispatch; the separate module lets tests import helpers while the entry module exports only the plugin function.isLoopbackUrl(value) in /home/byk/Code/opencode-lore-v2/packages/opencode/src/internal.ts:22-37 parses and normalizes the hostname by removing IPv6 brackets and lowercasing, accepts localhost, localhost., ::1, and IPv4 addresses matching ^127(?:\.\d{1,3}){3}$, and returns false on URL parsing failure.gatewayAccessHeadersForRemote(gatewayBase, env = process.env) in /home/byk/Code/opencode-lore-v2/packages/opencode/src/internal.ts:39-49 strips trailing slashes from LORE_REMOTE_URL and gatewayBase, and injects { [GATEWAY_AUTH_HEADER]: LORE_GATEWAY_AUTH_TOKEN } only when those bases match and the token exists.shouldForwardUpstreamExtraHeader(name) in /home/byk/Code/opencode-lore-v2/packages/opencode/src/internal.ts:51-60 prevents this hop from forwarding any x-lore-*, x-api-key, x-goog-api-key, or authorization header because provider and Lore credentials are applied by the gateway.parseUpstreamExtraHeaders(value) in /home/byk/Code/opencode-lore-v2/packages/opencode/src/internal.ts:62-73 splits newline-delimited headers at the first :, trims names and values, ignores lines with no nonempty name before the separator, and returns Array<[string, string]>.probeLoopback(url, signal) in /home/byk/Code/opencode-lore-v2/packages/opencode/src/internal.ts:75-90 uses node:http or node:https according to the parsed protocol, sends GET with an AbortSignal, drains the response via response.resume(), and resolves true only for status codes 200-299.applyLoreProviderConfig(cfg, gatewayBase) in /home/byk/Code/opencode-lore-v2/packages/opencode/src/internal.ts:92-148 pins every configured OpenCode provider’s options.baseURL to ${gatewayBase}/v1, while deep-merging each provider and preserving existing options such as custom headers and model overrides; iterating cfg.provider is the universal provider-routing lever.resolveSDK() always passes options.baseURL to the @ai-sdk factory; @ai-sdk’s loadOptionalSetting() consults an environment variable only when the factory receives an undefined baseURL. Consequently, OPENAI_BASE_URL / ANTHROPIC_BASE_URL are bypassed, and other providers including Google, Mistral, Groq, Cohere, xAI, Perplexity, Together AI, Vercel, Alibaba, DeepInfra, Gateway, OpenRouter, and Cerebras have no base-URL environment variable.options.baseURL pinning, OpenCode can derive Anthropic’s base URL from OPENAI_BASE_URL by stripping /v1, causing the SDK to call http://host/messages; Lore routes only /v1/messages, and its fetch interceptor skips 127.0.0.1 to avoid loops, so the bare /messages request returns 404.applyLoreProviderConfig(...) overrides headerTimeout to false for provider IDs "openai" and "openai-codex" because OpenCode installs its own Codex 10s header deadline before the hook runs, Lore may take longer while preparing context, and the gateway owns the foreground request deadline. If "openai" is absent, it creates pinned.openai = { options: { baseURL: baseUrl, headerTimeout: false } }.probeGateway(baseURL, timeoutMs = 1500) in /home/byk/Code/opencode-lore-v2/packages/opencode/src/internal.ts:150-169 probes ${baseURL}/health, uses probeLoopback(...) for loopback URLs and fetch(...).ok otherwise, returns false on every failure, aborts after 1500ms by default, and always clears its timer.surfaceGatewayUnavailable(client, message) in /home/byk/Code/opencode-lore-v2/packages/opencode/src/internal.ts:171-208 logs the fatal Lore-unavailable message through log.error(...), then fire-and-forgets client?.tui?.showToast({ body: { title: "Lore", message, variant: "error" } }).log.silenceStderr() makes the core logger invisible to a user because output goes only to the log file and Sentry sink. showToast is the user-visible, TUI-safe channel because it posts over HTTP and renders inside the TUI render loop; it never writes a raw byte to the terminal and therefore cannot corrupt the screen, unlike the replaced process.stderr.write.surfaceGatewayUnavailable(...) must never propagate a notification failure: it catches synchronous showToast exceptions and defensively attaches .catch(() => {}) to promise-like returns, even though the SDK defaults to throwOnError=false. Missing/headless TUIs and older servers without /tui/show-toast must not turn a degraded-but-running session into a crash.5 HTTP-hook-related matches in /home/byk/Code/opencode-v2-pilot/packages/core/src/session/model-request.ts: line 243 documents outbound HTTP exchanges exposed to session.http.request/response hooks; line 245 defines httpMiddleware; line 249 triggers "session", "http.request"; line 365 checks hooks.has("session", "http.request", resolved.ref.providerID); line 375 conditionally applies httpMiddleware(...).18 occurrences related to x-lore-upstream-url / x-lore-upstream-path: /home/byk/Code/opencode-lore-v2/packages/gateway/src/translate/types.ts lines 796-797; /home/byk/Code/opencode-lore-v2/packages/gateway/src/pipeline.ts lines 6207, 6249, 6589, 13377, 13383, 14220, and 14282; /home/byk/Code/opencode-lore-v2/packages/gateway/src/config.ts lines 567, 712, 1017, 1033, 1040, 1066, 1073, and 1076; and /home/byk/Code/opencode-lore-v2/packages/gateway/src/cache-warmer.ts line 1231.ResolvedRequestUpstreamRoute in /home/byk/Code/opencode-lore-v2/packages/gateway/src/pipeline.ts:6178-6192 records providerHeader, selected providerID including Copilot inference, headerUpstream, headerUpstreamPath, providerRoute, modelRoute, effectiveProtocol, effectiveUpstreamBase, and bedrockMantle.captureLegacyGlobalAuth(req, config, cred) in /home/byk/Code/opencode-lore-v2/packages/gateway/src/pipeline.ts:6194-6231 preserves the legacy process-global credential only for a local, unambiguous direct-provider request targeting the exact configured base. Remote/hosted gateways, explicit provider selection, and client-selected URLs never populate it.captureLegacyGlobalAuth(...) returns undefined when usesRemoteSessionBinding(config) is true, when x-lore-provider or x-lore-upstream-url is present, when the effective protocol is not Anthropic/OpenAI/OpenAI Responses, or when normalized routed and configured bases differ. On an eligible request it calls setLastSeenAuth(cred, providerID) and returns "anthropic" or "openai".resolveRequestUpstreamRoute(req, config) in /home/byk/Code/opencode-lore-v2/packages/gateway/src/pipeline.ts:6233-6294 is the synchronous single source of truth for foreground routing and its durable snapshot; dynamic models.dev lookup is cache-only so route intent can be captured before fetch/interception and retained even for failed requests.resolveRequestUpstreamRoute(...) rejects malformed explicit routing with "Unsupported or invalid X-Lore-Provider" or "Invalid X-Lore-Upstream-URL", rejects disallowed remote origins with "X-Lore-Upstream-URL origin is not allowed by this remote gateway", and performs unknown explicit provider lookup via lookupProviderRoute(providerID, false) so untrusted routing fails closed without side-channel network activity.resolveRequestUpstreamRoute(...) infers providerID = "github-copilot" and resolves that provider route. It treats Bedrock Mantle and Vertex provider routes as self-URL-building protocols.resolveRequestUpstreamRoute(...) requires client authentication for an explicit upstream URL, raising "An explicit upstream URL requires client authentication" if absent. It verifies an explicit upstream path remains within its upstream base and raises "Explicit upstream path escapes its upstream base" on escape; a provider ID with neither a route nor explicit upstream raises Unsupported provider "${providerID}".