xonecas.io
64875
Mc

mini-coder / commit 4c65a83

fix(llm-api): display GPT reasoning summaries in stream

xonecas2026-03-11 4c65a83077d68f70182f3604629fe8aa401f1bd5 parent 2055827

4 files changed

src/llm-api/providers.test.ts+19−1
@@ -1,6 +1,9 @@
11 import { describe, expect, test } from "bun:test";
22
3-import { shouldDisableGeminiThinkingForTools } from "./providers.ts";
3+import {
4+ getThinkingProviderOptions,
5+ shouldDisableGeminiThinkingForTools,
6+} from "./providers.ts";
47
58 describe("shouldDisableGeminiThinkingForTools", () => {
69 test("enables workaround for affected Gemini versions", () => {
@@ -31,3 +34,18 @@ describe("shouldDisableGeminiThinkingForTools", () => {
3134 );
3235 });
3336 });
37+
38+describe("getThinkingProviderOptions", () => {
39+ test("requests OpenAI reasoning summary for GPT reasoning models", () => {
40+ expect(
41+ getThinkingProviderOptions("openai/gpt-5.3-codex", "medium", false),
42+ ).toEqual({
43+ openai: { reasoningEffort: "medium", reasoningSummary: "auto" },
44+ });
45+ expect(
46+ getThinkingProviderOptions("zen/gpt-5.3-codex", "high", false),
47+ ).toEqual({
48+ openai: { reasoningEffort: "high", reasoningSummary: "auto" },
49+ });
50+ });
51+});
src/llm-api/providers.ts+1−1
@@ -260,7 +260,7 @@ export function getThinkingProviderOptions(
260260 // xhigh only valid on gpt-5.2+, o4+; clamp for others.
261261 const supportsXhigh = /^gpt-5\.[2-9]/.test(modelId) || /^o4/.test(modelId);
262262 const clamped = supportsXhigh ? effort : clampEffort(effort, "high");
263- return { openai: { reasoningEffort: clamped } };
263+ return { openai: { reasoningEffort: clamped, reasoningSummary: "auto" } };
264264 }
265265
266266 // Google Gemini (direct or via Zen routing through @ai-sdk/google)
src/llm-api/turn.test.ts+31−1
@@ -1,6 +1,10 @@
11 import { describe, expect, test } from "bun:test";
22 import type { CoreMessage } from "./turn.ts";
3-import { isOpenAIGPT, sanitizeGeminiToolMessages } from "./turn.ts";
3+import {
4+ getReasoningDeltaFromStreamChunk,
5+ isOpenAIGPT,
6+ sanitizeGeminiToolMessages,
7+} from "./turn.ts";
48
59 describe("isOpenAIGPT", () => {
610 test("matches openai/gpt-* models", () => {
@@ -26,6 +30,32 @@ describe("isOpenAIGPT", () => {
2630 });
2731 });
2832
33+describe("getReasoningDeltaFromStreamChunk", () => {
34+ test("reads SDK reasoning-delta text field", () => {
35+ expect(
36+ getReasoningDeltaFromStreamChunk({
37+ type: "reasoning-delta",
38+ text: "step by step",
39+ }),
40+ ).toBe("step by step");
41+ });
42+
43+ test("keeps compatibility with legacy reasoning textDelta field", () => {
44+ expect(
45+ getReasoningDeltaFromStreamChunk({
46+ type: "reasoning",
47+ textDelta: "legacy reasoning",
48+ }),
49+ ).toBe("legacy reasoning");
50+ });
51+
52+ test("returns null for non-reasoning chunks", () => {
53+ expect(
54+ getReasoningDeltaFromStreamChunk({ type: "text-delta", text: "hi" }),
55+ ).toBe(null);
56+ });
57+});
58+
2959 describe("sanitizeGeminiToolMessages", () => {
3060 test("truncates the current Gemini tool turn when any tool call lacks a thought signature", () => {
3161 const messages = [
src/llm-api/turn.ts+32−7
@@ -16,6 +16,17 @@ type ToolSet = NonNullable<StreamTextOptions["tools"]>;
1616 type ToolEntry = ToolSet extends Record<string, infer T> ? T : never;
1717 type StreamChunk = { type?: string; [key: string]: unknown };
1818
19+export function getReasoningDeltaFromStreamChunk(
20+ chunk: StreamChunk,
21+): string | null {
22+ if (chunk.type !== "reasoning-delta" && chunk.type !== "reasoning") {
23+ return null;
24+ }
25+ if (typeof chunk.text === "string") return chunk.text;
26+ if (typeof chunk.textDelta === "string") return chunk.textDelta;
27+ return "";
28+}
29+
1930 type StreamTextResult = ReturnType<typeof streamText>;
2031 type StreamTextResultFull = StreamTextResult & {
2132 fullStream: AsyncIterable<StreamChunk>;
@@ -210,9 +221,20 @@ export async function* runTurn(options: {
210221 const useInstructions =
211222 systemPrompt !== undefined && isOpenAIGPT(modelString);
212223
213- logApiEvent("turn start", { modelString, messageCount: messages.length });
214-
215224 const toolCount = Object.keys(toolSet).length;
225+ const thinkingOpts = thinkingEffort
226+ ? getThinkingProviderOptions(modelString, thinkingEffort, toolCount > 0)
227+ : null;
228+ const reasoningSummaryRequested =
229+ isRecord(thinkingOpts) &&
230+ isRecord(thinkingOpts.openai) &&
231+ typeof thinkingOpts.openai.reasoningSummary === "string";
232+ logApiEvent("turn start", {
233+ modelString,
234+ messageCount: messages.length,
235+ reasoningSummaryRequested,
236+ });
237+
216238 const turnMessages = sanitizeGeminiToolMessages(
217239 messages,
218240 modelString,
@@ -225,9 +247,6 @@ export async function* runTurn(options: {
225247 sanitizedMessages: turnMessages.length,
226248 });
227249 }
228- const thinkingOpts = thinkingEffort
229- ? getThinkingProviderOptions(modelString, thinkingEffort, toolCount > 0)
230- : null;
231250
232251 const mergedProviderOptions = {
233252 ...(useInstructions
@@ -306,7 +325,11 @@ export async function* runTurn(options: {
306325 for await (const chunk of result.fullStream) {
307326 const c = chunk as StreamChunk;
308327
309- if (c.type !== "text-delta" && c.type !== "reasoning") {
328+ if (
329+ c.type !== "text-delta" &&
330+ c.type !== "reasoning" &&
331+ c.type !== "reasoning-delta"
332+ ) {
310333 logApiEvent("stream chunk", {
311334 type: c.type,
312335 toolCallId: c.toolCallId,
@@ -333,8 +356,10 @@ export async function* runTurn(options: {
333356 };
334357 break;
335358 }
359+ case "reasoning-delta":
336360 case "reasoning": {
337- const delta = typeof c.textDelta === "string" ? c.textDelta : "";
361+ const delta = getReasoningDeltaFromStreamChunk(c);
362+ if (delta === null) break;
338363 yield {
339364 type: "reasoning-delta",
340365 delta,