Skip to content

Commit c3743b2

Browse files
committed
fix(opencode): preserve session event routing types
1 parent b97d254 commit c3743b2

2 files changed

Lines changed: 27 additions & 10 deletions

File tree

packages/llm/src/protocols/openai-responses.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,9 @@ const lowerToolResultOutput = Effect.fn("OpenAIResponses.lowerToolResultOutput")
320320
// Text/json/error results are encoded as a plain string for backward
321321
// compatibility with existing cassettes and provider expectations.
322322
if (part.result.type !== "content") return ProviderShared.toolResultText(part)
323-
return yield* Effect.forEach(part.result.value, lowerToolResultContentItem)
323+
// Preserve the narrowed array element type when compiled through a consumer package.
324+
const content: ReadonlyArray<ToolResultContentPart> = part.result.value
325+
return yield* Effect.forEach(content, lowerToolResultContentItem)
324326
})
325327

326328
const lowerMessages = Effect.fn("OpenAIResponses.lowerMessages")(function* (request: LLMRequest) {
@@ -427,6 +429,7 @@ const lowerOptions = Effect.fn("OpenAIResponses.lowerOptions")(function* (reques
427429

428430
const fromRequest = Effect.fn("OpenAIResponses.fromRequest")(function* (request: LLMRequest) {
429431
const generation = request.generation
432+
const options = yield* lowerOptions(request)
430433
return {
431434
model: request.model.id,
432435
input: yield* lowerMessages(request),
@@ -436,7 +439,7 @@ const fromRequest = Effect.fn("OpenAIResponses.fromRequest")(function* (request:
436439
max_output_tokens: generation?.maxTokens,
437440
temperature: generation?.temperature,
438441
top_p: generation?.topP,
439-
...(yield* lowerOptions(request)),
442+
...options,
440443
}
441444
})
442445

packages/opencode/src/session/session.ts

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,20 @@ export const layer: Layer.Layer<
522522
const storage = yield* Storage.Service
523523
const flags = yield* RuntimeFlags.Service
524524

525+
const locationForSession = Effect.fnUntraced(function* (sessionID: SessionID) {
526+
const row = yield* db
527+
.select({ directory: SessionTable.directory, workspaceID: SessionTable.workspace_id })
528+
.from(SessionTable)
529+
.where(eq(SessionTable.id, sessionID))
530+
.get()
531+
.pipe(Effect.orDie)
532+
if (!row) return
533+
return {
534+
directory: AbsolutePath.make(row.directory),
535+
workspaceID: row.workspaceID ?? undefined,
536+
}
537+
})
538+
525539
const createNext = Effect.fn("Session.createNext")(function* (input: {
526540
id?: SessionID
527541
title?: string
@@ -615,26 +629,26 @@ export const layer: Layer.Layer<
615629

616630
const updateMessage = <T extends SessionLegacy.Info>(msg: T): Effect.Effect<T> =>
617631
Effect.gen(function* () {
618-
const session = yield* get(msg.sessionID)
632+
const location = yield* locationForSession(msg.sessionID)
619633
yield* events.publish(
620634
SessionLegacy.Event.MessageUpdated,
621635
{ sessionID: msg.sessionID, info: msg },
622-
{ location: eventLocation(session) },
636+
{ location },
623637
)
624638
return msg
625639
}).pipe(Effect.withSpan("Session.updateMessage"))
626640

627641
const updatePart = <T extends SessionLegacy.Part>(part: T): Effect.Effect<T> =>
628642
Effect.gen(function* () {
629-
const session = yield* get(part.sessionID)
643+
const location = yield* locationForSession(part.sessionID)
630644
yield* events.publish(
631645
SessionLegacy.Event.PartUpdated,
632646
{
633647
sessionID: part.sessionID,
634648
part: structuredClone(part),
635649
time: Date.now(),
636650
},
637-
{ location: eventLocation(session) },
651+
{ location },
638652
)
639653
return part
640654
}).pipe(Effect.withSpan("Session.updatePart"))
@@ -828,14 +842,14 @@ export const layer: Layer.Layer<
828842
sessionID: SessionID
829843
messageID: MessageID
830844
}) {
831-
const session = yield* get(input.sessionID)
845+
const location = yield* locationForSession(input.sessionID)
832846
yield* events.publish(
833847
SessionLegacy.Event.MessageRemoved,
834848
{
835849
sessionID: input.sessionID,
836850
messageID: input.messageID,
837851
},
838-
{ location: eventLocation(session) },
852+
{ location },
839853
)
840854
return input.messageID
841855
})
@@ -845,15 +859,15 @@ export const layer: Layer.Layer<
845859
messageID: MessageID
846860
partID: PartID
847861
}) {
848-
const session = yield* get(input.sessionID)
862+
const location = yield* locationForSession(input.sessionID)
849863
yield* events.publish(
850864
SessionLegacy.Event.PartRemoved,
851865
{
852866
sessionID: input.sessionID,
853867
messageID: input.messageID,
854868
partID: input.partID,
855869
},
856-
{ location: eventLocation(session) },
870+
{ location },
857871
)
858872
return input.partID
859873
})

0 commit comments

Comments
 (0)