@@ -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,