Skip to content

Commit 6aa21f7

Browse files
committed
fix(session): align OpenAI response stream fixtures
1 parent d80f5d8 commit 6aa21f7

2 files changed

Lines changed: 31 additions & 2 deletions

File tree

packages/llm/src/schema/events.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ const llmEventTagged = Schema.Union([
167167
]).pipe(Schema.toTaggedUnion("type"))
168168

169169
type WithID<Event extends { readonly id: unknown }, ID> = Omit<Event, "type" | "id"> & { readonly id: ID | string }
170+
type WithUsage<Event extends { readonly usage?: Usage }> = Omit<Event, "type" | "usage"> & {
171+
readonly usage?: Usage | ConstructorParameters<typeof Usage>[0]
172+
}
170173

171174
const responseID = (value: ResponseID | string) => ResponseID.make(value)
172175
const contentBlockID = (value: ContentBlockID | string) => ContentBlockID.make(value)
@@ -197,8 +200,10 @@ export const LLMEvent = Object.assign(llmEventTagged, {
197200
toolCall: (input: WithID<ToolCall, ToolCallID>) => ToolCall.make({ ...input, id: toolCallID(input.id) }),
198201
toolResult: (input: WithID<ToolResult, ToolCallID>) => ToolResult.make({ ...input, id: toolCallID(input.id) }),
199202
toolError: (input: WithID<ToolError, ToolCallID>) => ToolError.make({ ...input, id: toolCallID(input.id) }),
200-
stepFinish: StepFinish.make,
201-
requestFinish: RequestFinish.make,
203+
stepFinish: (input: WithUsage<StepFinish>) =>
204+
StepFinish.make({ ...input, usage: input.usage instanceof Usage ? input.usage : new Usage(input.usage ?? {}) }),
205+
requestFinish: (input: WithUsage<RequestFinish>) =>
206+
RequestFinish.make({ ...input, usage: input.usage instanceof Usage ? input.usage : new Usage(input.usage ?? {}) }),
202207
providerError: ProviderErrorEvent.make,
203208
is: {
204209
requestStart: llmEventTagged.guards["request-start"],

packages/opencode/test/session/llm.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,18 @@ describe("session.llm.stream", () => {
581581
service_tier: null,
582582
},
583583
},
584+
{
585+
type: "response.output_item.added",
586+
output_index: 0,
587+
item: { type: "message", id: "item-1", status: "in_progress", role: "assistant", content: [] },
588+
},
589+
{
590+
type: "response.content_part.added",
591+
item_id: "item-1",
592+
output_index: 0,
593+
content_index: 0,
594+
part: { type: "output_text", text: "", annotations: [] },
595+
},
584596
{
585597
type: "response.output_text.delta",
586598
item_id: "item-1",
@@ -694,6 +706,18 @@ describe("session.llm.stream", () => {
694706
service_tier: null,
695707
},
696708
},
709+
{
710+
type: "response.output_item.added",
711+
output_index: 0,
712+
item: { type: "message", id: "item-data-url", status: "in_progress", role: "assistant", content: [] },
713+
},
714+
{
715+
type: "response.content_part.added",
716+
item_id: "item-data-url",
717+
output_index: 0,
718+
content_index: 0,
719+
part: { type: "output_text", text: "", annotations: [] },
720+
},
697721
{
698722
type: "response.output_text.delta",
699723
item_id: "item-data-url",

0 commit comments

Comments
 (0)