diff --git a/packages/llm/src/protocols/openai-responses.ts b/packages/llm/src/protocols/openai-responses.ts index ad673a263..cc29f5019 100644 --- a/packages/llm/src/protocols/openai-responses.ts +++ b/packages/llm/src/protocols/openai-responses.ts @@ -320,7 +320,9 @@ const lowerToolResultOutput = Effect.fn("OpenAIResponses.lowerToolResultOutput") // Text/json/error results are encoded as a plain string for backward // compatibility with existing cassettes and provider expectations. if (part.result.type !== "content") return ProviderShared.toolResultText(part) - return yield* Effect.forEach(part.result.value, lowerToolResultContentItem) + // Preserve the narrowed array element type when compiled through a consumer package. + const content: ReadonlyArray = part.result.value + return yield* Effect.forEach(content, lowerToolResultContentItem) }) const lowerMessages = Effect.fn("OpenAIResponses.lowerMessages")(function* (request: LLMRequest) { @@ -427,6 +429,7 @@ const lowerOptions = Effect.fn("OpenAIResponses.lowerOptions")(function* (reques const fromRequest = Effect.fn("OpenAIResponses.fromRequest")(function* (request: LLMRequest) { const generation = request.generation + const options = yield* lowerOptions(request) return { model: request.model.id, input: yield* lowerMessages(request), @@ -436,7 +439,7 @@ const fromRequest = Effect.fn("OpenAIResponses.fromRequest")(function* (request: max_output_tokens: generation?.maxTokens, temperature: generation?.temperature, top_p: generation?.topP, - ...(yield* lowerOptions(request)), + ...options, } }) diff --git a/packages/opencode/src/session/session.ts b/packages/opencode/src/session/session.ts index 7c7d57be6..7da998593 100644 --- a/packages/opencode/src/session/session.ts +++ b/packages/opencode/src/session/session.ts @@ -522,6 +522,20 @@ export const layer: Layer.Layer< const storage = yield* Storage.Service const flags = yield* RuntimeFlags.Service + const locationForSession = Effect.fnUntraced(function* (sessionID: SessionID) { + const row = yield* db + .select({ directory: SessionTable.directory, workspaceID: SessionTable.workspace_id }) + .from(SessionTable) + .where(eq(SessionTable.id, sessionID)) + .get() + .pipe(Effect.orDie) + if (!row) return + return { + directory: AbsolutePath.make(row.directory), + workspaceID: row.workspaceID ?? undefined, + } + }) + const createNext = Effect.fn("Session.createNext")(function* (input: { id?: SessionID title?: string @@ -615,18 +629,18 @@ export const layer: Layer.Layer< const updateMessage = (msg: T): Effect.Effect => Effect.gen(function* () { - const session = yield* get(msg.sessionID) + const location = yield* locationForSession(msg.sessionID) yield* events.publish( SessionLegacy.Event.MessageUpdated, { sessionID: msg.sessionID, info: msg }, - { location: eventLocation(session) }, + { location }, ) return msg }).pipe(Effect.withSpan("Session.updateMessage")) const updatePart = (part: T): Effect.Effect => Effect.gen(function* () { - const session = yield* get(part.sessionID) + const location = yield* locationForSession(part.sessionID) yield* events.publish( SessionLegacy.Event.PartUpdated, { @@ -634,7 +648,7 @@ export const layer: Layer.Layer< part: structuredClone(part), time: Date.now(), }, - { location: eventLocation(session) }, + { location }, ) return part }).pipe(Effect.withSpan("Session.updatePart")) @@ -828,14 +842,14 @@ export const layer: Layer.Layer< sessionID: SessionID messageID: MessageID }) { - const session = yield* get(input.sessionID) + const location = yield* locationForSession(input.sessionID) yield* events.publish( SessionLegacy.Event.MessageRemoved, { sessionID: input.sessionID, messageID: input.messageID, }, - { location: eventLocation(session) }, + { location }, ) return input.messageID }) @@ -845,7 +859,7 @@ export const layer: Layer.Layer< messageID: MessageID partID: PartID }) { - const session = yield* get(input.sessionID) + const location = yield* locationForSession(input.sessionID) yield* events.publish( SessionLegacy.Event.PartRemoved, { @@ -853,7 +867,7 @@ export const layer: Layer.Layer< messageID: input.messageID, partID: input.partID, }, - { location: eventLocation(session) }, + { location }, ) return input.partID })