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
5 changes: 5 additions & 0 deletions .changeset/fuzzy-responses-reason.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@ai-sdk/open-responses': patch
---

Stream Open Responses reasoning summary text deltas as reasoning output.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{"type":"response.output_item.added","sequence_number":0,"output_index":0,"item":{"id":"rs_1","type":"reasoning","summary":[]}}
{"type":"response.reasoning_summary_text.delta","sequence_number":1,"item_id":"rs_1","output_index":0,"summary_index":0,"delta":"Think"}
{"type":"response.reasoning_summary_text.delta","sequence_number":2,"item_id":"rs_1","output_index":0,"summary_index":0,"delta":"ing."}
{"type":"response.reasoning_summary_text.done","sequence_number":3,"item_id":"rs_1","output_index":0,"summary_index":0,"text":"Thinking."}
{"type":"response.output_item.done","sequence_number":4,"output_index":0,"item":{"id":"rs_1","type":"reasoning","summary":[{"type":"summary_text","text":"Thinking."}]}}
{"type":"response.completed","sequence_number":5,"response":{"id":"resp_1","status":"completed","incomplete_details":null,"usage":{"input_tokens":1,"output_tokens":1}}}
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,39 @@ describe('OpenResponsesLanguageModel', () => {
});
});

it('should stream reasoning summary text deltas', async () => {
prepareChunksFixtureResponse('openai-reasoning-summary-text.1');

const result = await createModel().doStream({
prompt: TEST_PROMPT,
});

const parts = await convertReadableStreamToArray(result.stream);

expect(
parts.filter(part => part.type.startsWith('reasoning')),
).toStrictEqual([
{
type: 'reasoning-start',
id: 'rs_1',
},
{
type: 'reasoning-delta',
id: 'rs_1',
delta: 'Think',
},
{
type: 'reasoning-delta',
id: 'rs_1',
delta: 'ing.',
},
{
type: 'reasoning-end',
id: 'rs_1',
},
]);
});

describe('reasoning with tool call', () => {
it('should stream reasoning and tool call content', async () => {
prepareChunksFixtureResponse('lmstudio-tool-call.2');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,9 @@ export class OpenResponsesLanguageModel implements LanguageModelV3 {
});
isActiveReasoning = true;
} else if (
chunk.type === 'response.reasoning_summary_text.delta' ||
(chunk as { type: string }).type ===
'response.reasoning_text.delta'
'response.reasoning_text.delta'
) {
const reasoningChunk = chunk as {
item_id: string;
Expand Down
3 changes: 2 additions & 1 deletion packages/zai/src/zai-provider.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { afterEach, describe, expect, it, vi } from 'vitest';
import { ZaiChatLanguageModel } from './zai-chat-language-model';
import { createZai } from './zai-provider';
import { VERSION } from './version';

const TEST_PROMPT = [
{
Expand Down Expand Up @@ -61,7 +62,7 @@ describe('createZai', () => {
);
const headers = new Headers(fetch.mock.calls[0][1].headers);
expect(headers.get('authorization')).toBe('Bearer test-key');
expect(headers.get('user-agent')).toContain('ai-sdk/zai/1.0.0');
expect(headers.get('user-agent')).toContain(`ai-sdk/zai/${VERSION}`);
});

it('reads the API key from ZAI_API_KEY by default', async () => {
Expand Down
Loading