ai 6.0.252 → 6.0.255

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -164,7 +164,7 @@ function detectMediaType({
164
164
  var import_provider_utils2 = require("@ai-sdk/provider-utils");
165
165
 
166
166
  // src/version.ts
167
- var VERSION = true ? "6.0.252" : "0.0.0-test";
167
+ var VERSION = true ? "6.0.255" : "0.0.0-test";
168
168
 
169
169
  // src/util/download/download.ts
170
170
  var download = async ({
@@ -144,7 +144,7 @@ import {
144
144
  } from "@ai-sdk/provider-utils";
145
145
 
146
146
  // src/version.ts
147
- var VERSION = true ? "6.0.252" : "0.0.0-test";
147
+ var VERSION = true ? "6.0.255" : "0.0.0-test";
148
148
 
149
149
  // src/util/download/download.ts
150
150
  var download = async ({
@@ -452,5 +452,6 @@ try {
452
452
  | [Kling AI](/providers/ai-sdk-providers/klingai#video-models) | `kling-v2.6-motion-control` | Motion control |
453
453
  | [Replicate](/providers/ai-sdk-providers/replicate#video-models) | `minimax/video-01` | Text-to-video |
454
454
  | [xAI](/providers/ai-sdk-providers/xai#video-models) | `grok-imagine-video` | Text-to-video, image-to-video, editing, extension, R2V |
455
+ | [xAI](/providers/ai-sdk-providers/xai#video-models) | `grok-imagine-video-1.5` | Text-to-video, image-to-video, editing, extension, R2V |
455
456
 
456
457
  Above are a small subset of the video models supported by the AI SDK providers. For more, see the respective provider documentation.
@@ -102,6 +102,10 @@ A reasoning part of a message.
102
102
  ```typescript
103
103
  type ReasoningUIPart = {
104
104
  type: 'reasoning';
105
+ /**
106
+ * The reasoning part ID.
107
+ */
108
+ id?: string;
105
109
  /**
106
110
  * The reasoning text.
107
111
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai",
3
- "version": "6.0.252",
3
+ "version": "6.0.255",
4
4
  "description": "AI SDK by Vercel - build apps like ChatGPT, Claude, Gemini, and more with a single interface for any model using the Vercel AI Gateway or go direct to OpenAI, Anthropic, Google, or any other model provider.",
5
5
  "license": "Apache-2.0",
6
6
  "sideEffects": false,
@@ -45,7 +45,7 @@
45
45
  },
46
46
  "dependencies": {
47
47
  "@opentelemetry/api": "^1.9.0",
48
- "@ai-sdk/gateway": "3.0.171",
48
+ "@ai-sdk/gateway": "3.0.173",
49
49
  "@ai-sdk/provider": "3.0.15",
50
50
  "@ai-sdk/provider-utils": "4.0.45"
51
51
  },
@@ -15,6 +15,7 @@ export {
15
15
  type GeneratedFile,
16
16
  } from './generated-file';
17
17
  export * as Output from './output';
18
+ export type { Output as OutputInterface } from './output';
18
19
  export type {
19
20
  InferCompleteOutput as InferGenerateOutput,
20
21
  InferPartialOutput as InferStreamOutput,
package/src/ui/chat.ts CHANGED
@@ -15,6 +15,7 @@ import {
15
15
  createStreamingUIMessageState,
16
16
  processUIMessageStream,
17
17
  type StreamingUIMessageState,
18
+ type UIMessageStreamWriteOptions,
18
19
  } from './process-ui-message-stream';
19
20
  import {
20
21
  isToolUIPart,
@@ -742,7 +743,7 @@ export abstract class AbstractChat<UI_MESSAGE extends UIMessage> {
742
743
  const runUpdateMessageJob = (
743
744
  job: (options: {
744
745
  state: StreamingUIMessageState<UI_MESSAGE>;
745
- write: () => void;
746
+ write: (options?: UIMessageStreamWriteOptions) => void;
746
747
  }) => Promise<void>,
747
748
  ) =>
748
749
  // serialize the job execution to avoid race conditions:
@@ -753,13 +754,14 @@ export abstract class AbstractChat<UI_MESSAGE extends UIMessage> {
753
754
 
754
755
  return job({
755
756
  state: response.state,
756
- write: () => {
757
+ write: ({ updateStatus = true } = {}) => {
757
758
  if (response.abortController.signal.aborted) {
758
759
  return;
759
760
  }
760
761
 
761
- // streaming is set on first write (before it should be "submitted")
762
- this.setStatus({ status: 'streaming' });
762
+ if (updateStatus) {
763
+ this.setStatus({ status: 'streaming' });
764
+ }
763
765
 
764
766
  const replaceLastMessage =
765
767
  response.state.message.id === this.lastMessage?.id;
@@ -49,6 +49,10 @@ export type StreamingUIMessageState<UI_MESSAGE extends UIMessage> = {
49
49
  finishReason?: FinishReason;
50
50
  };
51
51
 
52
+ export type UIMessageStreamWriteOptions = {
53
+ updateStatus?: boolean;
54
+ };
55
+
52
56
  export function createStreamingUIMessageState<UI_MESSAGE extends UIMessage>({
53
57
  lastMessage,
54
58
  messageId,
@@ -95,7 +99,7 @@ export function processUIMessageStream<UI_MESSAGE extends UIMessage>({
95
99
  runUpdateMessageJob: (
96
100
  job: (options: {
97
101
  state: StreamingUIMessageState<UI_MESSAGE>;
98
- write: () => void;
102
+ write: (options?: UIMessageStreamWriteOptions) => void;
99
103
  }) => Promise<void>,
100
104
  ) => Promise<void>;
101
105
  onError: ErrorHandler;
@@ -455,6 +459,7 @@ export function processUIMessageStream<UI_MESSAGE extends UIMessage>({
455
459
  case 'reasoning-start': {
456
460
  const reasoningPart: ReasoningUIPart = {
457
461
  type: 'reasoning',
462
+ id: chunk.id,
458
463
  text: '',
459
464
  providerMetadata: chunk.providerMetadata,
460
465
  state: 'streaming',
@@ -830,7 +835,7 @@ export function processUIMessageStream<UI_MESSAGE extends UIMessage>({
830
835
  await updateMessageMetadata(chunk.messageMetadata);
831
836
 
832
837
  if (chunk.messageId != null || chunk.messageMetadata != null) {
833
- write();
838
+ write({ updateStatus: false });
834
839
  }
835
840
  break;
836
841
  }
@@ -115,6 +115,11 @@ export type TextUIPart = {
115
115
  export type ReasoningUIPart = {
116
116
  type: 'reasoning';
117
117
 
118
+ /**
119
+ * The reasoning part ID.
120
+ */
121
+ id?: string;
122
+
118
123
  /**
119
124
  * The reasoning text.
120
125
  */
@@ -47,6 +47,7 @@ const uiMessagesSchema = lazySchema(() =>
47
47
  }),
48
48
  z.object({
49
49
  type: z.literal('reasoning'),
50
+ id: z.string().optional(),
50
51
  text: z.string(),
51
52
  state: z.enum(['streaming', 'done']).optional(),
52
53
  providerMetadata: providerMetadataSchema.optional(),
@@ -2,6 +2,7 @@ import {
2
2
  createStreamingUIMessageState,
3
3
  processUIMessageStream,
4
4
  type StreamingUIMessageState,
5
+ type UIMessageStreamWriteOptions,
5
6
  } from '../ui/process-ui-message-stream';
6
7
  import type { UIMessage } from '../ui/ui-messages';
7
8
  import type { ErrorHandler } from '../util/error-handler';
@@ -91,7 +92,7 @@ export function handleUIMessageStreamFinish<UI_MESSAGE extends UIMessage>({
91
92
  const runUpdateMessageJob = async (
92
93
  job: (options: {
93
94
  state: StreamingUIMessageState<UI_MESSAGE>;
94
- write: () => void;
95
+ write: (options?: UIMessageStreamWriteOptions) => void;
95
96
  }) => Promise<void>,
96
97
  ) => {
97
98
  await job({ state, write: () => {} });
@@ -4,6 +4,7 @@ import {
4
4
  createStreamingUIMessageState,
5
5
  processUIMessageStream,
6
6
  type StreamingUIMessageState,
7
+ type UIMessageStreamWriteOptions,
7
8
  } from '../ui/process-ui-message-stream';
8
9
  import {
9
10
  createAsyncIterableStream,
@@ -11,6 +12,35 @@ import {
11
12
  } from '../util/async-iterable-stream';
12
13
  import { consumeStream } from '../util/consume-stream';
13
14
 
15
+ function createUIMessageSnapshot<UI_MESSAGE extends UIMessage>(
16
+ message: UI_MESSAGE,
17
+ ): UI_MESSAGE {
18
+ const textByPartIndex = new Map<number, string>();
19
+ const messageWithoutText = {
20
+ ...message,
21
+ parts: message.parts.map((part, index) => {
22
+ if (part.type === 'text' || part.type === 'reasoning') {
23
+ textByPartIndex.set(index, part.text);
24
+ return { ...part, text: '' };
25
+ }
26
+
27
+ return part;
28
+ }),
29
+ };
30
+
31
+ const snapshot = structuredClone(messageWithoutText) as UI_MESSAGE;
32
+
33
+ for (const [index, text] of textByPartIndex) {
34
+ const part = snapshot.parts[index];
35
+
36
+ if (part.type === 'text' || part.type === 'reasoning') {
37
+ part.text = text;
38
+ }
39
+ }
40
+
41
+ return snapshot;
42
+ }
43
+
14
44
  /**
15
45
  * Transforms a stream of `UIMessageChunk`s into an `AsyncIterableStream` of `UIMessage`s.
16
46
  *
@@ -62,13 +92,13 @@ export function readUIMessageStream<UI_MESSAGE extends UIMessage>({
62
92
  runUpdateMessageJob(
63
93
  job: (options: {
64
94
  state: StreamingUIMessageState<UI_MESSAGE>;
65
- write: () => void;
95
+ write: (options?: UIMessageStreamWriteOptions) => void;
66
96
  }) => Promise<void>,
67
97
  ) {
68
98
  return job({
69
99
  state,
70
100
  write: () => {
71
- controller?.enqueue(structuredClone(state.message));
101
+ controller?.enqueue(createUIMessageSnapshot(state.message));
72
102
  },
73
103
  });
74
104
  },