Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/fixtures.html
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ <h2>Response Types</h2>
<tbody>
<tr>
<td>Text</td>
<td>content, role?, finishReason?</td>
<td>content, role?, finishReason?, reasoning?, webSearches?</td>
<td>Plain text response</td>
</tr>
<tr>
Expand Down
16 changes: 8 additions & 8 deletions src/__tests__/reasoning-web-search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,10 @@ describe("POST /v1/responses (web search streaming)", () => {
(e) =>
e.type === "response.output_item.done" &&
(e.item as { type: string })?.type === "web_search_call",
) as (SSEEvent & { item: { query: string } })[];
) as (SSEEvent & { item: { action: { query: string } } })[];

expect(searchDone[0].item.query).toBe("latest news");
expect(searchDone[1].item.query).toBe("weather forecast");
expect(searchDone[0].item.action.query).toBe("latest news");
expect(searchDone[1].item.action.query).toBe("weather forecast");
});

it("response.completed includes web search output items", async () => {
Expand All @@ -251,14 +251,14 @@ describe("POST /v1/responses (web search streaming)", () => {

const events = parseResponsesSSEEvents(res.body);
const completed = events.find((e) => e.type === "response.completed") as SSEEvent & {
response: { output: { type: string; query?: string }[] };
response: { output: { type: string; action: { query: string } }[] };
};
expect(completed).toBeDefined();

const searchOutputs = completed.response.output.filter((o) => o.type === "web_search_call");
expect(searchOutputs).toHaveLength(2);
expect(searchOutputs[0].query).toBe("latest news");
expect(searchOutputs[1].query).toBe("weather forecast");
expect(searchOutputs[0].action.query).toBe("latest news");
expect(searchOutputs[1].action.query).toBe("weather forecast");
});
});

Expand Down Expand Up @@ -355,8 +355,8 @@ describe("POST /v1/responses (non-streaming with reasoning)", () => {

const searchOutputs = body.output.filter((o: { type: string }) => o.type === "web_search_call");
expect(searchOutputs).toHaveLength(2);
expect(searchOutputs[0].query).toBe("latest news");
expect(searchOutputs[1].query).toBe("weather forecast");
expect(searchOutputs[0].action.query).toBe("latest news");
expect(searchOutputs[1].action.query).toBe("weather forecast");
});

it("combined non-streaming response has correct output order", async () => {
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/stream-collapse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1715,12 +1715,12 @@ describe("collapseOpenAISSE with reasoning", () => {
"",
`data: ${JSON.stringify({
type: "response.output_item.done",
item: { type: "web_search_call", status: "completed", query: "test query" },
item: { type: "web_search_call", status: "completed", action: { query: "test query" } },
})}`,
"",
`data: ${JSON.stringify({
type: "response.output_item.done",
item: { type: "web_search_call", status: "completed", query: "another query" },
item: { type: "web_search_call", status: "completed", action: { query: "another query" } },
})}`,
"",
`data: ${JSON.stringify({ type: "response.output_text.delta", delta: "Result" })}`,
Expand Down
6 changes: 3 additions & 3 deletions src/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ function buildWebSearchStreamEvents(
type: "web_search_call",
id: searchId,
status: "in_progress",
query: queries[i],
action: { query: queries[i] },
},
});

Expand All @@ -516,7 +516,7 @@ function buildWebSearchStreamEvents(
type: "web_search_call",
id: searchId,
status: "completed",
query: queries[i],
action: { query: queries[i] },
},
});
}
Expand Down Expand Up @@ -550,7 +550,7 @@ function buildTextResponse(
type: "web_search_call",
id: generateId("ws"),
status: "completed",
query,
action: { query },
});
}
}
Expand Down
9 changes: 6 additions & 3 deletions src/stream-collapse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,12 @@ export function collapseOpenAISSE(body: string): CollapseResult {
// Responses API web search events
if (parsed.type === "response.output_item.done") {
const item = parsed.item as Record<string, unknown> | undefined;
if (item?.type === "web_search_call" && typeof item.query === "string") {
webSearchQueries.push(item.query);
continue;
if (item?.type === "web_search_call") {
const action = item.action as Record<string, unknown> | undefined;
if (action && typeof action.query === "string") {
webSearchQueries.push(action.query);
continue;
}
}
}

Expand Down
Loading