Dashboard › opencode › Distillation
3ff2bbe9-e4ad-419c-926b-ef8424ee3913["lore_tm_v1_XLhHz8qzZ9AnTI1SOqZGVaJrg0Sr_mkWrFj0B1ju7l8","lore_tm_v1_mIc8PDhSBj7T-azqJRg3MjXutVapt1c-0FkarSXP5E8","lore_tm_v1_yWqnELVAOddUi1ZTaA5ueRX-n1kJXpJPUzYyu1ucBDQ"]
/home/byk/Code/opencode-v2-pilot/packages/core/src/session/model-request.ts defines HookScope with sessionID: SessionSchema.ID, agent: Agent.ID, model: Model.Ref, and kind: SessionRequestKind.sessionHeaders() in /home/byk/Code/opencode-v2-pilot/packages/core/src/session/model-request.ts emits "x-session-affinity" and "X-Session-Id" from session.id, conditionally emits "x-parent-session-id" from session.parentID, sets "User-Agent" via App.useragent(app), and emits "x-opencode-project", "x-opencode-session", and "x-opencode-client".promptCacheKey() strips the ses_ prefix only from session IDs matching /^ses_[0-9a-f]{64}$/; request preparation uses promptCacheKey(session.fork?.sessionID ?? session.id). A TODO says cache lineage should be persisted so nested forks reuse the root session’s cache key.applyModelHooks() triggers hooks.trigger("session", "model.request", ...) with scope, optional current baseURL, and copied HTTP headers. Hooks may rewrite the route endpoint’s baseURL and headers; request body and query are retained in a new HttpOptions.httpMiddleware() in /home/byk/Code/opencode-v2-pilot/packages/core/src/session/model-request.ts exposes outbound exchanges through web-standard Request/Response: it triggers "session", "http.request", converts the possibly rewritten request with HttpClientRequest.fromWeb(), clones and restores a present body as Uint8Array with its content-type, invokes the handler, then triggers "session", "http.response".httpMiddleware() creates a null response body for HTTP statuses 204, 205, and 304; otherwise it uses Stream.toReadableStreamEffect(response.stream). It converts the hook’s resulting response through HttpClientResponse.fromWeb(sent, after.response) and maps non-Error causes to new Error(String(cause))./home/byk/Code/opencode-v2-pilot/packages/core/src/session/model-request.ts exports Interface.prepare(input: PrepareInput): Effect.Effect<Prepared> and Location-scoped Service with context tag "@opencode/SessionModelRequest". Preparation builds a request and matching tool-call capability without executing the request or mutating Session state.SessionModelRequest layer depends on PluginHooks.Service, SessionModelTransport.Service, and App.Metadata; prepare is instrumented as Effect.fn("SessionModelRequest.prepare").prepare() defaults to definitions: [] and an executor that returns new Tool.Error({ message: "Tools are not available for this request" }).prepare() builds registry by canonical tool name and given by the exact hook-facing definition object { description, input: { ...tool.inputSchema } }. The mutable definitions record lets "session", "context" hooks edit descriptions and schemas, rename tools, or remove tools."session", "context" hook receives sessionID, agent selected as input.scope.contextAgentID ?? input.scope.agentID, resolved model ref, transcript system and messages, mutable tool definitions, and initially empty generation and providerOptions; the hook is skipped only when input.contextHooks === false.tool.name is retained so renamed calls can be translated for execution.prepare() constructs LLM.request() with session headers, fork-aware prompt cache key, hook-modified system text, messages processed through unsupportedParts() and boundImages(), surviving renamed tool definitions, input.toolChoice, and nonempty context.generation/context.providerOptions.part.type === "compaction", prepare() dies with Error("Provider context is incompatible with the route selected by model request hooks").hooks.has("session", "http.request", resolved.ref.providerID) or hooks.has("session", "http.response", resolved.ref.providerID) succeeds. Responses WebSocket support additionally requires resolved.capabilities.responsesWebsockets === true and provider flag responsesWebSocketFlag(resolved.ref.providerID), defaulting to false.{ webSocket: transport.bind(session.id) } only when input.webSocket === "session", the provider WebSocket flag is enabled, and no HTTP request/response hooks are installed.executeTool calls tools.execute({ ...input, definitions: hooked }) and converts defects matching declineDefect into failures. The prepared retry triggers "session", "retry" and discards its result with Effect.asVoid. prepare() returns { request, options, retry, executeTool }.parentID-related declarations in /home/byk/Code/opencode-v2-pilot/packages/schema/src/session.ts at lines 31 and 34, where Info extends Schema.Schema.Type<typeof Info> and parentID is ID.pipe(optional).parentID declarations in /home/byk/Code/opencode-v2-pilot/packages/schema/src/v1/session.ts: line 461 uses parentID: MessageID, and line 550 uses parentID: optional(SessionID)./home/byk/Code/opencode-v2-pilot/packages/plugin/package.json identifies @opencode/plugin version 1.18.15, with "type": "module" and "license": "MIT".@opencode/plugin scripts are "test": "bun test --only-failures", "typecheck": "tsgo --noEmit", and "build": "tsc -p tsconfig.build.json".@opencode/plugin exports "." as ./src/promise/index.ts, "./effect" as ./src/effect/index.ts, "./host" as ./src/host.ts, "./tui" as ./src/tui/index.ts, and "./*" as ./src/*.ts; its published "files" list contains only "dist".#plugin-source package import resolves to ./src/source.bun.ts under "bun" and to ./src/source.node.ts under both "node" and "default".@opencode/plugin dependencies are @ai-sdk/provider@3.0.8, workspace packages @opencode/ai, @opencode/client, @opencode/protocol, @opencode/schema, and @opencode/util, plus catalog dependencies @standard-schema/spec, effect, and zod.@opencode/plugin peer dependencies are @opencode/theme@workspace:*, @opentui/core@>=0.5.10, @opentui/solid@>=0.5.10, and solid-js@>=1.9.0; all four are marked optional in peerDependenciesMeta.@opencode/plugin dev dependencies are @opencode/theme@workspace:* and catalog entries for @opentui/core, @opentui/solid, @tsconfig/bun, @tsconfig/node22, @types/bun, @types/node, solid-js, typescript, and @typescript/native-preview.