Dashboard › opencode › Distillation
0a195087-6ccf-4b93-838a-83ca3843cedc["lore_tm_v1_k9GtSqdbxkQUOTjsxuoF9jMk_y3YJphol72-JC5l7Xw","lore_tm_v1_NtNkAvrHWdNXSKpHhlvuXIuPxMsiaN9ZuuvWpZXyKZk","lore_tm_v1_5HYS_FMwEBxhUC3IhqtXOb7CkEO1ERSQbAcEQwkRqfs"]
/home/byk/Code/opencode-v2-pilot/packages/core/src/session/model-request.ts:33-48 that user declines tunneled as defects by Permission.assert and the question tool must “never become model-facing tool output.” ExecuteError is exactly Tool.Error | Permission.DeclinedError | QuestionTool.CancelledError; declineDefect() inspects Cause.isDieReason() entries and resurfaces the first Permission.DeclinedError or QuestionTool.CancelledError as a typed failure exactly once at the runner execution seam./home/byk/Code/opencode-v2-pilot/packages/core/src/session/model-request.ts:25-28,150-197 sets image-request limits to IMAGE_BYTES_TRIGGER = 25 * 1024 * 1024 (25 MiB) and IMAGE_BYTES_TARGET = 15 * 1024 * 1024 (15 MiB). boundImages() leaves requests at or below the trigger unchanged; above it, image media and image files inside content tool results are replaced in traversal order until the estimated image payload is at or below the target./home/byk/Code/opencode-v2-pilot/packages/core/src/session/model-request.ts are replaced with the exact warning: [This image was removed to reduce the request size and is no longer visible. Do not make claims about its contents from memory. If needed, retrieve it again with an available tool or ask the user to attach it again.]/home/byk/Code/opencode-v2-pilot/packages/core/src/session/model-request.ts:111-148 maps MIME types to modalities image, audio, video, and pdf; unsupportedParts() replaces unsupported top-level media and unsupported file items nested in content tool results with ERROR: Cannot read ... (this model does not support ... input). Inform the user., while preserving supported or unrecognized media.baseTranscript() in /home/byk/Code/opencode-v2-pilot/packages/core/src/session/model-request.ts:89-109 derives providerMetadataKey from input.model.model.route.providerMetadataKey ?? input.model.model.provider, uses input.agent.system or SessionSystemPrompt.make() over tool names, appends the initial prompt, removes empty system parts, converts them with SystemPart.make, and converts history through toLLMMessages(input.messages, input.model.ref, providerMetadataKey).Prepared in /home/byk/Code/opencode-v2-pilot/packages/core/src/session/model-request.ts:50-61 pairs an LLMRequest with StreamOptions, a retry() hook operation, and request-scoped executeTool(). Unknown and hook-removed calls fail individually through this same execution seam.PrepareInput in /home/byk/Code/opencode-v2-pilot/packages/core/src/session/model-request.ts:63-87 carries SessionRequestKind, session, agentID, optional contextAgentID, resolved model, optional tool snapshot, system/messages transcript, optional toolChoice, optional contextHooks?: false, and optional webSocket?: "session". contextAgentID lets an auxiliary request reuse another agent’s context without changing request-hook identity; title-like standalone requests can opt out of context hooks; stateful Session WebSockets require explicit durable-runner opt-in.responsesWebSocketFlag(providerID) in /home/byk/Code/opencode-v2-pilot/packages/core/src/session/model-request.ts:30-31 constructs OPENCODE_EXPERIMENTAL_${providerID.replace(/[^a-zA-Z0-9]+/g, "_").toUpperCase()}_RESPONSES_WEBSOCKET.sessionHeaders() in /home/byk/Code/opencode-v2-pilot/packages/core/src/session/model-request.ts:207-215 emits x-session-affinity, X-Session-Id, optional x-parent-session-id, User-Agent, x-opencode-project, x-opencode-session, and x-opencode-client.promptCacheKey() in /home/byk/Code/opencode-v2-pilot/packages/core/src/session/model-request.ts:217-218 strips the ses_ prefix only from session IDs matching /^ses_[0-9a-f]{64}$/; other IDs remain unchanged.applyModelHooks() in /home/byk/Code/opencode-v2-pilot/packages/core/src/session/model-request.ts:220-241 triggers session.model.request with request identity, current string baseURL when available, and a copied header record. Hook changes can replace the model route’s endpoint baseURL and headers while preserving the original HTTP body and query.httpMiddleware() in /home/byk/Code/opencode-v2-pilot/packages/core/src/session/model-request.ts:243-270 exposes each exchange to session.http.request and session.http.response hooks as web-standard Request/Response objects. A hook-replaced request is converted back with HttpClientRequest.fromWeb(); when it has a body, a clone is buffered to Uint8Array with its content-type; statuses 204, 205, and 304 produce a null response body; other response streams are converted with Stream.toReadableStreamEffect(). Non-Error failures are normalized to new Error(String(cause)).SessionModelRequest.Service in /home/byk/Code/opencode-v2-pilot/packages/core/src/session/model-request.ts:277-409 is a location-scoped service identified as @opencode/SessionModelRequest; its node depends on PluginHooks.node, SessionModelTransport.node, and App.node.SessionModelRequest.prepare() supplies an empty tool snapshot when tools are omitted: definitions: [] and an executor returning new Tool.Error({ message: "Tools are not available for this request" })./home/byk/Code/opencode-v2-pilot/packages/core/src/session/model-request.ts:299-330 maps hook-visible definition objects back to canonical tools. Hooks may edit descriptions/schemas, rename tools by moving definition objects to new keys, or remove tools; object identity takes precedence over key lookup, so a definition moved onto another tool’s name still executes the tool it describes. Hook-invented definitions matching neither identity nor a canonical key are dropped, and tool.name remains canonical for translating renamed calls during execution.session.context hook payload in /home/byk/Code/opencode-v2-pilot/packages/core/src/session/model-request.ts:309-319 includes sessionID, agent selected as contextAgentID ?? agentID, resolved model ref, mutable system/messages/tools, and initially empty generation and providerOptions; the hook is skipped only when contextHooks === false.SessionModelRequest.prepare() builds the LLM.request() with session headers, prompt-cache key from session.fork?.sessionID ?? session.id, hook-mutated system/messages/tools, optional toolChoice, and nonempty generation/providerOptions. Before dispatch, messages pass through unsupportedParts() and then boundImages()./home/byk/Code/opencode-v2-pilot/packages/core/src/session/model-request.ts:349-363 rejects an existing compaction window when session.model.request hooks reroute it to provider context incompatible with the catalog-selected native window. Because prepare() has no error channel, it dies with Error("Provider context is incompatible with the route selected by model request hooks").session.http.request or session.http.response hooks exist for resolved.ref.providerID. Session WebSocket transport is enabled only when all conditions hold: model capability responsesWebsockets === true, the provider-specific experimental environment flag resolves true, input.webSocket === "session", and no HTTP hooks are installed; the transport is then transport.bind(session.id).executeTool() calls tools.execute({ ...input, definitions: hooked }) and applies Effect.catchCauseFilter(declineDefect, ...) so recognized permission declines and question cancellations become typed failures rather than tool results. The prepared retry() triggers session.retry and discards its return value with Effect.asVoid.