Dashboard › opencode › Distillation
13dcb8bc-455a-4720-a3d6-851c330bd38c["lore_tm_v1_L672d8mXNmuhqm1UKGlzPPUd0WNTBzgVmRH81NnbJ3I"]
/home/byk/Code/opencode-v2-pilot/packages/core/src/session/model-request.ts lines 207-215: sessionHeaders(...) sets "x-session-affinity" and "X-Session-Id" to session.id, conditionally sets "x-parent-session-id" from session.parentID, sets "User-Agent" via App.useragent(app), and includes "x-opencode-project", "x-opencode-session", and "x-opencode-client"./home/byk/Code/opencode-v2-pilot/packages/core/src/session/model-request.ts lines 217-218: promptCacheKey(sessionID) strips the ses_ prefix only when the ID matches /^ses_[0-9a-f]{64}$/; otherwise it returns the original ID.applyModelHooks(...) in /home/byk/Code/opencode-v2-pilot/packages/core/src/session/model-request.ts lines 220-240: it triggers session.model.request with the hook scope, current string baseURL, and copied HTTP headers; a changed event.baseURL updates the model route endpoint; returned headers replace request headers; and the existing HTTP body and query are preserved through a new HttpOptions.httpMiddleware(...) in /home/byk/Code/opencode-v2-pilot/packages/core/src/session/model-request.ts lines 243-270: it exposes outbound exchanges to session.http.request and session.http.response hooks using web-standard Request/Response; converts the request via HttpClientRequest.toWeb(...); reconstructs a hook-modified request with HttpClientRequest.fromWeb(...); clones and restores a request body as Uint8Array with its content-type; passes the request to handler; represents statuses 204, 205, and 304 with a null response body; converts the hook-modified response using HttpClientResponse.fromWeb(sent, after.response); and normalizes non-Error failures to new Error(String(cause))./home/byk/Code/opencode-v2-pilot/packages/core/src/session/model-request.ts lines 272-283: Interface.prepare(input: PrepareInput) returns Effect.Effect<Prepared> and is documented as building, but not executing, an outbound model request together with the matching tool-call capability; Service is a location-scoped Context.Service named "@opencode/SessionModelRequest".SessionModelRequest.layer initialization in /home/byk/Code/opencode-v2-pilot/packages/core/src/session/model-request.ts lines 285-294: it obtains PluginHooks.Service, SessionModelTransport.Service, and App.Metadata; prepare is instrumented as Effect.fn("SessionModelRequest.prepare"); and it derives session, resolved, and model from input.scope./home/byk/Code/opencode-v2-pilot/packages/core/src/session/model-request.ts lines 295-308: absent input.scope.tools, prepare uses no definitions and an executor that returns new Tool.Error({ message: "Tools are not available for this request" }); it creates a name-to-tool registry, an identity-based given map from mutable hook definitions to canonical tools, and a definitions record that hooks may edit, rename, or remove in place./home/byk/Code/opencode-v2-pilot/packages/core/src/session/model-request.ts lines 309-319: the session.context hook receives sessionID, agent chosen as contextAgentID ?? agentID, model: resolved.ref, transcript system and messages, mutable tool definitions, and initially empty generation and providerOptions; the hook is skipped only when input.contextHooks === false./home/byk/Code/opencode-v2-pilot/packages/core/src/session/model-request.ts lines 320-330: after context hooks, surviving tool entries are matched first by definition-object identity and then by key; identity takes precedence when a definition is moved onto another tool’s name; hook-invented definitions matching neither source are dropped; descriptions and input schemas come from the hook-mutated definitions while tool.name remains canonical for translating renamed tool calls during execution./home/byk/Code/opencode-v2-pilot/packages/core/src/session/model-request.ts lines 331-348: prepare constructs LLM.request(...) and passes it through applyModelHooks; hook scope includes sessionID, agentID, resolved.ref, and input.kind; request headers come from sessionHeaders(session, app); promptCacheKey uses session.fork?.sessionID ?? session.id; messages pass through unsupportedParts(...) and then boundImages(...); tools use hook-visible names; toolChoice is forwarded; and empty generation or providerOptions records become undefined./home/byk/Code/opencode-v2-pilot/packages/core/src/session/model-request.ts line 339: persist cache lineage so nested forks reuse the root session’s cache key./home/byk/Code/opencode-v2-pilot/packages/core/src/session/model-request.ts lines 349-363: history selects native windows against the catalog route before model hooks run; if a routing hook changes to a provenance-incompatible deployment and any message contains a compaction part, prepare dies with new Error("Provider context is incompatible with the route selected by model request hooks"); the comment notes that prepare has no error channel, so this surfaces as a defect like hook failures./home/byk/Code/opencode-v2-pilot/packages/core/src/session/model-request.ts lines 364-381: hasHttpHooks is true when the resolved provider has either a session.http.request or session.http.response hook; webSocket is enabled only when resolved.capabilities.responsesWebsockets === true and the provider-specific responsesWebSocketFlag(...) config resolves true, with a default of false and configuration failures converted via Effect.orDie; HTTP middleware receives sessionID, agentID, resolved.ref, and request kind./home/byk/Code/opencode-v2-pilot/packages/core/src/session/model-request.ts lines 382-387: StreamOptions includes HTTP middleware when HTTP hooks exist; session-bound WebSocket transport is used only when input.webSocket === "session", provider WebSockets are enabled, and no HTTP request/response hooks exist, via transport.bind(session.id).