Skip to content

Commit fcc6869

Browse files
authored
refactor(ai/core): align language model call stream naming (#14238)
## Background As part of the streamText custom loop refactor work, we are converging terminology on "language model call" and reducing mixed naming in the low-level streaming primitives. ## Summary - renamed `streamModelCall` to `streamLanguageModelCall` via the new `stream-language-model-call` export path - renamed `ModelCallStreamPart` to `LanguageModelStreamPart` across `packages/ai` internals, tests, and the custom loop example - updated experimental exports to `experimental_streamLanguageModelCall` and `Experimental_LanguageModelStreamPart` ## Manual Verification tests and type checks pass ## Checklist - [x] Tests have been added / updated (for bug fixes / features) - [ ] n/a ~~Documentation has been added / updated (for bug fixes / features)~~ - [ ] A _patch_ changeset for relevant packages has been added (for bug fixes / features - run `pnpm changeset` in the project root) - [x] I have reviewed this pull request (self-review) ## Related Issues - Related: #14234 - Related: #13570
1 parent 1e5f83c commit fcc6869

File tree

11 files changed

+73
-57
lines changed

11 files changed

+73
-57
lines changed

.changeset/rare-maps-invent.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"ai": major
3+
---
4+
5+
refactor(ai/core): rename `ModelCallStreamPart` to `LanguageModelStreamPart` and align stream model call naming (`streamLanguageModelCall`, `experimental_streamLanguageModelCall`).
6+
7+
This updates experimental low-level stream primitives to use "language model call" terminology consistently.

examples/ai-functions/src/stream-text-custom-loop/openai.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { openai } from '@ai-sdk/openai';
22
import {
33
AsyncIterableStream,
4-
experimental_streamModelCall as streamModelCall,
5-
type Experimental_ModelCallStreamPart as ModelCallStreamPart,
4+
experimental_streamLanguageModelCall as streamLanguageModelCall,
5+
type Experimental_LanguageModelStreamPart as LanguageModelStreamPart,
66
} from 'ai';
77
import { run } from '../lib/run';
88

99
run(async () => {
10-
const { stream }: { stream: AsyncIterableStream<ModelCallStreamPart> } =
11-
await streamModelCall({
10+
const { stream }: { stream: AsyncIterableStream<LanguageModelStreamPart> } =
11+
await streamLanguageModelCall({
1212
model: openai('gpt-5.4'),
1313
prompt: 'How many people live in the capital of France?',
1414
});

packages/ai/src/error/invalid-stream-part-error.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { AISDKError } from '@ai-sdk/provider';
2-
import { ModelCallStreamPart } from '../generate-text/stream-model-call';
2+
import { LanguageModelStreamPart } from '../generate-text/stream-language-model-call';
33

44
const name = 'AI_InvalidStreamPartError';
55
const marker = `vercel.ai.error.${name}`;
@@ -8,13 +8,13 @@ const symbol = Symbol.for(marker);
88
export class InvalidStreamPartError extends AISDKError {
99
private readonly [symbol] = true; // used in isInstance
1010

11-
readonly chunk: ModelCallStreamPart<any>;
11+
readonly chunk: LanguageModelStreamPart<any>;
1212

1313
constructor({
1414
chunk,
1515
message,
1616
}: {
17-
chunk: ModelCallStreamPart<any>;
17+
chunk: LanguageModelStreamPart<any>;
1818
message: string;
1919
}) {
2020
super({ name, message });

packages/ai/src/generate-text/create-execute-tools-transformation.test.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { describe, expect, it } from 'vitest';
88
import { z } from 'zod/v4';
99
import { asLanguageModelUsage } from '../types/usage';
1010
import { createExecuteToolsTransformation } from './create-execute-tools-transformation';
11-
import { ModelCallStreamPart } from './stream-model-call';
11+
import { LanguageModelStreamPart } from './stream-language-model-call';
1212

1313
const finishChunk = {
1414
type: 'model-call-end' as const,
@@ -38,7 +38,7 @@ describe('createExecuteToolsTransformation', () => {
3838
}),
3939
};
4040

41-
const inputStream: ReadableStream<ModelCallStreamPart<typeof tools>> =
41+
const inputStream: ReadableStream<LanguageModelStreamPart<typeof tools>> =
4242
convertArrayToReadableStream([
4343
{
4444
type: 'tool-call',
@@ -117,7 +117,7 @@ describe('createExecuteToolsTransformation', () => {
117117
}),
118118
};
119119

120-
const inputStream: ReadableStream<ModelCallStreamPart<typeof tools>> =
120+
const inputStream: ReadableStream<LanguageModelStreamPart<typeof tools>> =
121121
convertArrayToReadableStream([
122122
{
123123
type: 'tool-call',
@@ -202,7 +202,7 @@ describe('createExecuteToolsTransformation', () => {
202202

203203
let toolExecuted = false;
204204

205-
const inputStream: ReadableStream<ModelCallStreamPart<typeof tools>> =
205+
const inputStream: ReadableStream<LanguageModelStreamPart<typeof tools>> =
206206
convertArrayToReadableStream([
207207
{
208208
type: 'tool-call',
@@ -254,7 +254,7 @@ describe('createExecuteToolsTransformation', () => {
254254

255255
const callOrder: string[] = [];
256256

257-
const inputStream: ReadableStream<ModelCallStreamPart<typeof tools>> =
257+
const inputStream: ReadableStream<LanguageModelStreamPart<typeof tools>> =
258258
convertArrayToReadableStream([
259259
{
260260
type: 'tool-call',
@@ -304,7 +304,7 @@ describe('createExecuteToolsTransformation', () => {
304304
const startEvents: unknown[] = [];
305305
const finishEvents: unknown[] = [];
306306

307-
const inputStream: ReadableStream<ModelCallStreamPart<typeof tools>> =
307+
const inputStream: ReadableStream<LanguageModelStreamPart<typeof tools>> =
308308
convertArrayToReadableStream([
309309
{
310310
type: 'tool-call',
@@ -377,7 +377,7 @@ describe('createExecuteToolsTransformation', () => {
377377

378378
const finishEvents: unknown[] = [];
379379

380-
const inputStream: ReadableStream<ModelCallStreamPart<typeof tools>> =
380+
const inputStream: ReadableStream<LanguageModelStreamPart<typeof tools>> =
381381
convertArrayToReadableStream([
382382
{
383383
type: 'tool-call',
@@ -434,7 +434,7 @@ describe('createExecuteToolsTransformation', () => {
434434
const finishEvents: unknown[] = [];
435435
const toolError = new Error('tool failed');
436436

437-
const inputStream: ReadableStream<ModelCallStreamPart<typeof tools>> =
437+
const inputStream: ReadableStream<LanguageModelStreamPart<typeof tools>> =
438438
convertArrayToReadableStream([
439439
{
440440
type: 'tool-call',
@@ -484,7 +484,7 @@ describe('createExecuteToolsTransformation', () => {
484484
const startEvents: unknown[] = [];
485485
const finishEvents: unknown[] = [];
486486

487-
const inputStream: ReadableStream<ModelCallStreamPart<typeof tools>> =
487+
const inputStream: ReadableStream<LanguageModelStreamPart<typeof tools>> =
488488
convertArrayToReadableStream([
489489
{
490490
type: 'tool-call',
@@ -531,7 +531,7 @@ describe('createExecuteToolsTransformation', () => {
531531
const startEvents: unknown[] = [];
532532
const finishEvents: unknown[] = [];
533533

534-
const inputStream: ReadableStream<ModelCallStreamPart<typeof tools>> =
534+
const inputStream: ReadableStream<LanguageModelStreamPart<typeof tools>> =
535535
convertArrayToReadableStream([
536536
{
537537
type: 'tool-call',
@@ -584,7 +584,7 @@ describe('createExecuteToolsTransformation', () => {
584584
const startEvents: unknown[] = [];
585585
const finishEvents: unknown[] = [];
586586

587-
const inputStream: ReadableStream<ModelCallStreamPart<typeof tools>> =
587+
const inputStream: ReadableStream<LanguageModelStreamPart<typeof tools>> =
588588
convertArrayToReadableStream([
589589
{
590590
type: 'tool-call',
@@ -645,7 +645,7 @@ describe('createExecuteToolsTransformation', () => {
645645
}),
646646
};
647647

648-
const inputStream: ReadableStream<ModelCallStreamPart<typeof tools>> =
648+
const inputStream: ReadableStream<LanguageModelStreamPart<typeof tools>> =
649649
convertArrayToReadableStream([
650650
{
651651
type: 'tool-call',
@@ -732,7 +732,7 @@ describe('createExecuteToolsTransformation', () => {
732732
}),
733733
};
734734

735-
const inputStream: ReadableStream<ModelCallStreamPart<typeof tools>> =
735+
const inputStream: ReadableStream<LanguageModelStreamPart<typeof tools>> =
736736
convertArrayToReadableStream([
737737
{
738738
type: 'tool-call',

packages/ai/src/generate-text/create-execute-tools-transformation.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
import { TypedToolCall } from './tool-call';
1212
import type { GenerationContext } from './generation-context';
1313
import type { ToolSet } from '@ai-sdk/provider-utils';
14-
import { ModelCallStreamPart } from './stream-model-call';
14+
import { LanguageModelStreamPart } from './stream-language-model-call';
1515

1616
export function createExecuteToolsTransformation<
1717
TOOLS extends ToolSet,
@@ -50,17 +50,22 @@ export function createExecuteToolsTransformation<
5050
| StreamTextOnToolCallFinishCallback<TOOLS>
5151
| Array<StreamTextOnToolCallFinishCallback<TOOLS> | undefined | null>;
5252
executeToolInTelemetryContext?: TelemetryIntegration['executeTool'];
53-
}): TransformStream<ModelCallStreamPart<TOOLS>, ModelCallStreamPart<TOOLS>> {
53+
}): TransformStream<
54+
LanguageModelStreamPart<TOOLS>,
55+
LanguageModelStreamPart<TOOLS>
56+
> {
5457
const toolCallsToExecute: Array<TypedToolCall<TOOLS>> = [];
5558

5659
// forward stream
5760
return new TransformStream<
58-
ModelCallStreamPart<TOOLS>,
59-
ModelCallStreamPart<TOOLS>
61+
LanguageModelStreamPart<TOOLS>,
62+
LanguageModelStreamPart<TOOLS>
6063
>({
6164
async transform(
62-
chunk: ModelCallStreamPart<TOOLS>,
63-
controller: TransformStreamDefaultController<ModelCallStreamPart<TOOLS>>,
65+
chunk: LanguageModelStreamPart<TOOLS>,
66+
controller: TransformStreamDefaultController<
67+
LanguageModelStreamPart<TOOLS>
68+
>,
6469
) {
6570
// immediately forward all chunks
6671
controller.enqueue(chunk);

packages/ai/src/generate-text/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ export {
4848
type StopCondition,
4949
} from './stop-condition';
5050
export {
51-
streamModelCall as experimental_streamModelCall,
52-
type ModelCallStreamPart as Experimental_ModelCallStreamPart,
53-
} from './stream-model-call';
51+
streamLanguageModelCall as experimental_streamLanguageModelCall,
52+
type LanguageModelStreamPart as Experimental_LanguageModelStreamPart,
53+
} from './stream-language-model-call';
5454
export {
5555
streamText,
5656
type StreamTextOnChunkCallback,

packages/ai/src/generate-text/invoke-tool-callbacks-from-stream.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
} from '@ai-sdk/provider-utils/test';
66
import { describe, expect, it } from 'vitest';
77
import { z } from 'zod/v4';
8-
import { ModelCallStreamPart } from './stream-model-call';
8+
import { LanguageModelStreamPart } from './stream-language-model-call';
99
import { invokeToolCallbacksFromStream } from './invoke-tool-callbacks-from-stream';
1010

1111
describe('invokeToolCallbacksFromStream', () => {
@@ -32,7 +32,7 @@ describe('invokeToolCallbacksFromStream', () => {
3232
}),
3333
};
3434

35-
const chunks: Array<ModelCallStreamPart<typeof tools>> = [
35+
const chunks: Array<LanguageModelStreamPart<typeof tools>> = [
3636
{ type: 'text-delta', id: 'text-1', text: 'hello' },
3737
{ type: 'tool-input-start', id: 'call-1', toolName: 'test-tool' },
3838
{ type: 'tool-input-delta', id: 'call-1', delta: '{"value":"' },

packages/ai/src/generate-text/invoke-tool-callbacks-from-stream.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { GenerationContext } from './generation-context';
2-
import { ModelCallStreamPart } from './stream-model-call';
2+
import { LanguageModelStreamPart } from './stream-language-model-call';
33
import type { ToolSet } from '@ai-sdk/provider-utils';
44
import { ModelMessage } from '@ai-sdk/provider-utils';
55

@@ -13,12 +13,12 @@ export function invokeToolCallbacksFromStream<
1313
abortSignal,
1414
context,
1515
}: {
16-
stream: ReadableStream<ModelCallStreamPart<TOOLS>>;
16+
stream: ReadableStream<LanguageModelStreamPart<TOOLS>>;
1717
tools: TOOLS | undefined;
1818
stepInputMessages: Array<ModelMessage>;
1919
abortSignal: AbortSignal | undefined;
2020
context: CONTEXT;
21-
}): ReadableStream<ModelCallStreamPart<TOOLS>> {
21+
}): ReadableStream<LanguageModelStreamPart<TOOLS>> {
2222
if (tools == null) return stream;
2323

2424
const ongoingToolCallToolNames: Record<string, string> = {};

packages/ai/src/generate-text/stream-model-call.test.ts renamed to packages/ai/src/generate-text/stream-language-model-call.test.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { describe, expect, it } from 'vitest';
1111
import z from 'zod';
1212
import { NoSuchToolError } from '../error/no-such-tool-error';
1313
import { MockLanguageModelV4 } from '../test/mock-language-model-v4';
14-
import { streamModelCall } from './stream-model-call';
14+
import { streamLanguageModelCall } from './stream-language-model-call';
1515
import { ToolCallRepairFunction } from './tool-call-repair-function';
1616
import type { ToolSet } from '@ai-sdk/provider-utils';
1717

@@ -29,7 +29,7 @@ const testUsage: LanguageModelV4Usage = {
2929
},
3030
};
3131

32-
async function streamModelCallResult<TOOLS extends ToolSet>({
32+
async function streamLanguageModelCallResult<TOOLS extends ToolSet>({
3333
streamParts,
3434
tools,
3535
repairToolCall,
@@ -44,7 +44,7 @@ async function streamModelCallResult<TOOLS extends ToolSet>({
4444
}),
4545
});
4646

47-
const { stream } = await streamModelCall({
47+
const { stream } = await streamLanguageModelCall({
4848
model,
4949
tools,
5050
prompt: 'test prompt',
@@ -55,7 +55,7 @@ async function streamModelCallResult<TOOLS extends ToolSet>({
5555
return convertReadableStreamToArray(stream);
5656
}
5757

58-
describe('streamModelCall', () => {
58+
describe('streamLanguageModelCall', () => {
5959
describe('stream-start parts', () => {
6060
it('should convert stream-start to init-model-call', async () => {
6161
const model = new MockLanguageModelV4({
@@ -84,7 +84,7 @@ describe('streamModelCall', () => {
8484
}),
8585
});
8686

87-
const { stream } = await streamModelCall({
87+
const { stream } = await streamLanguageModelCall({
8888
model,
8989
tools: undefined,
9090
prompt: 'test prompt',
@@ -138,7 +138,7 @@ describe('streamModelCall', () => {
138138

139139
describe('text parts', () => {
140140
it('should convert text to delta', async () => {
141-
const result = await streamModelCallResult({
141+
const result = await streamLanguageModelCallResult({
142142
streamParts: [
143143
{ type: 'text-start', id: '1' },
144144
{ type: 'text-delta', id: '1', delta: 'text' },
@@ -199,7 +199,7 @@ describe('streamModelCall', () => {
199199

200200
describe('reasoning parts', () => {
201201
it('should convert text to delta', async () => {
202-
const result = await streamModelCallResult({
202+
const result = await streamLanguageModelCallResult({
203203
streamParts: [
204204
{ type: 'reasoning-start', id: '1' },
205205
{ type: 'reasoning-delta', id: '1', delta: 'text' },
@@ -232,7 +232,7 @@ describe('streamModelCall', () => {
232232

233233
describe('file parts', () => {
234234
it('should use GeneratedFile', async () => {
235-
const result = await streamModelCallResult({
235+
const result = await streamLanguageModelCallResult({
236236
streamParts: [
237237
{
238238
type: 'file',
@@ -289,7 +289,7 @@ describe('streamModelCall', () => {
289289
});
290290

291291
it('should use GeneratedFile with providerMetadata', async () => {
292-
const result = await streamModelCallResult({
292+
const result = await streamLanguageModelCallResult({
293293
streamParts: [
294294
{
295295
type: 'file',
@@ -369,7 +369,7 @@ describe('streamModelCall', () => {
369369

370370
describe('custom parts', () => {
371371
it('should forward custom parts', async () => {
372-
const result = await streamModelCallResult({
372+
const result = await streamLanguageModelCallResult({
373373
streamParts: [
374374
{
375375
type: 'custom',
@@ -436,7 +436,7 @@ describe('streamModelCall', () => {
436436
}),
437437
};
438438

439-
const result = await streamModelCallResult({
439+
const result = await streamLanguageModelCallResult({
440440
streamParts: [
441441
{
442442
type: 'tool-call',
@@ -507,7 +507,7 @@ describe('streamModelCall', () => {
507507

508508
describe('tool-approval-request parts', () => {
509509
it('should emit error when tool call is not found for provider approval request', async () => {
510-
const result = await streamModelCallResult({
510+
const result = await streamLanguageModelCallResult({
511511
streamParts: [
512512
// No tool-call part before the approval request
513513
{
@@ -568,7 +568,7 @@ describe('streamModelCall', () => {
568568
}),
569569
};
570570

571-
const result = await streamModelCallResult({
571+
const result = await streamLanguageModelCallResult({
572572
streamParts: [
573573
{
574574
type: 'tool-call',
@@ -663,7 +663,7 @@ describe('streamModelCall', () => {
663663
}),
664664
};
665665

666-
const result = await streamModelCallResult({
666+
const result = await streamLanguageModelCallResult({
667667
streamParts: [
668668
{
669669
type: 'tool-call',

0 commit comments

Comments
 (0)