Dashboard › opencode › Distillation
778d3041-a319-4a2b-99cd-cf793f1fc97b["lore_tm_v1_MWMNMiY36NiOtb-ph708Wki41wTkt5kzBUR4GeS5_tE"]
/home/byk/Code/opencode-v2-pilot/packages/core/src/session/title.ts lines 1–92 of 158. The module re-exports SessionTitle from "./title.js" and imports isDeepStrictEqual from "node:util"; LLMClient, LLMEvent, Message, and SystemPart from "@opencode/ai"; type Agent from "@opencode/schema/agent"; Context, DateTime, Effect, Layer, and Stream from "effect"; Database, Bus, makeLocationNode, isExactRootFallback, llmClient, SessionContext, SessionEvent, SessionHistory, type SessionRunnerModel, SessionSchema, SessionUsage, and SessionStore./home/byk/Code/opencode-v2-pilot/packages/core/src/session/title.ts: MAX_LENGTH = 100, MAX_CONTEXT_LENGTH = 8_000, MAX_FIRST_MESSAGE_LENGTH = 2_000, and titleChanged = Symbol("Session title changed").Interface in /home/byk/Code/opencode-v2-pilot/packages/core/src/session/title.ts: generate(sessionID: SessionSchema.ID): Effect.Effect<void> generates an initial title or regenerates one from bounded conversation history. Service extends Context.Service<Service, Interface>()("@opencode/SessionTitle")./home/byk/Code/opencode-v2-pilot/packages/core/src/session/title.ts: truncate(value) returns the unchanged string when value.length <= MAX_LENGTH, otherwise ${value.slice(0, MAX_LENGTH - 3)}...; isUntitled(session) calls isExactRootFallback({ title: session.title, time: { created: DateTime.toEpochMillis(session.time.created) } }).layer = Layer.effect(Service, Effect.gen(...)) in /home/byk/Code/opencode-v2-pilot/packages/core/src/session/title.ts. It obtains Bus.Service, LLMClient.Service, SessionContext.Service, SessionStore.Service, and (yield* Database.Service).db.attempt = Effect.fn("SessionTitle.attempt") in /home/byk/Code/opencode-v2-pilot/packages/core/src/session/title.ts. Its input contains readonly session: SessionSchema.Info, agent: Agent.Info, text: string, and model: SessionRunnerModel.Resolved; it initializes chunks: string[] = [], failed = false, and usage: SessionUsage.Recorded | undefined.recordUsage inside SessionTitle.attempt: Effect.suspend publishes SessionEvent.UsageRecorded through bus.publish when usage exists, with { sessionID: input.session.id, source: "title", ...usage }; otherwise it returns Effect.void.SessionTitle.attempt: context.prepare receives kind: "title", scope { session: input.session, agentID: input.agent.id, model: input.model }, transcript system parts set to [SystemPart.make(input.agent.system)] when the agent has a system prompt or [] otherwise, messages [Message.user(input.text)], and contextHooks: false.SessionTitle.attempt: llm.stream(prepared.request, prepared.options) is consumed with Stream.runForEach; LLMEvent.is.providerError(event) sets failed = true, LLMEvent.is.textDelta(event) appends event.text to chunks, and LLMEvent.is.stepFinish(event) records usage via SessionUsage.record(event.usage, input.model.cost) and accumulates multiple steps via SessionUsage.add(usage, step).SessionTitle.attempt: tagged "AI.Error" failures are caught and set failed = true; interruption invokes recordUsage.pipe(Effect.asVoid) via Effect.onInterrupt; after streaming, yield* recordUsage runs. The remainder of the function after line 92 was not shown.