@convex-dev/agent 0.1.18-alpha.0 → 0.5.0-alpha.1

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.
Files changed (71) hide show
  1. package/dist/client/createTool.d.ts +30 -9
  2. package/dist/client/createTool.d.ts.map +1 -1
  3. package/dist/client/createTool.js +24 -9
  4. package/dist/client/createTool.js.map +1 -1
  5. package/dist/client/definePlaygroundAPI.d.ts +176 -201
  6. package/dist/client/definePlaygroundAPI.d.ts.map +1 -1
  7. package/dist/client/definePlaygroundAPI.js +12 -19
  8. package/dist/client/definePlaygroundAPI.js.map +1 -1
  9. package/dist/client/files.js +4 -4
  10. package/dist/client/files.js.map +1 -1
  11. package/dist/client/index.d.ts +166 -63
  12. package/dist/client/index.d.ts.map +1 -1
  13. package/dist/client/index.js +75 -45
  14. package/dist/client/index.js.map +1 -1
  15. package/dist/client/search.d.ts +27 -6
  16. package/dist/client/search.d.ts.map +1 -1
  17. package/dist/client/search.js.map +1 -1
  18. package/dist/client/streaming.d.ts +3 -2
  19. package/dist/client/streaming.d.ts.map +1 -1
  20. package/dist/client/streaming.js.map +1 -1
  21. package/dist/client/types.d.ts +27 -41
  22. package/dist/client/types.d.ts.map +1 -1
  23. package/dist/component/_generated/api.d.ts +436 -73
  24. package/dist/component/messages.d.ts +246 -43
  25. package/dist/component/messages.d.ts.map +1 -1
  26. package/dist/component/messages.js +2 -2
  27. package/dist/component/messages.js.map +1 -1
  28. package/dist/component/schema.d.ts +1453 -152
  29. package/dist/component/schema.d.ts.map +1 -1
  30. package/dist/component/schema.js +2 -2
  31. package/dist/component/schema.js.map +1 -1
  32. package/dist/component/streams.d.ts +180 -6
  33. package/dist/component/streams.d.ts.map +1 -1
  34. package/dist/mapping.d.ts +12 -14
  35. package/dist/mapping.d.ts.map +1 -1
  36. package/dist/mapping.js +187 -47
  37. package/dist/mapping.js.map +1 -1
  38. package/dist/react/deltas.d.ts +0 -3
  39. package/dist/react/deltas.d.ts.map +1 -1
  40. package/dist/react/deltas.js +140 -44
  41. package/dist/react/deltas.js.map +1 -1
  42. package/dist/react/optimisticallySendMessage.d.ts.map +1 -1
  43. package/dist/react/optimisticallySendMessage.js +2 -1
  44. package/dist/react/optimisticallySendMessage.js.map +1 -1
  45. package/dist/react/toUIMessages.d.ts +5 -4
  46. package/dist/react/toUIMessages.d.ts.map +1 -1
  47. package/dist/react/toUIMessages.js +103 -40
  48. package/dist/react/toUIMessages.js.map +1 -1
  49. package/dist/validators.d.ts +1798 -259
  50. package/dist/validators.d.ts.map +1 -1
  51. package/dist/validators.js +79 -15
  52. package/dist/validators.js.map +1 -1
  53. package/package.json +2 -2
  54. package/src/client/createTool.ts +68 -37
  55. package/src/client/definePlaygroundAPI.ts +25 -27
  56. package/src/client/files.ts +4 -4
  57. package/src/client/index.test.ts +14 -12
  58. package/src/client/index.ts +134 -94
  59. package/src/client/search.ts +3 -2
  60. package/src/client/streaming.ts +4 -3
  61. package/src/client/types.ts +34 -70
  62. package/src/component/_generated/api.d.ts +436 -73
  63. package/src/component/messages.ts +2 -2
  64. package/src/component/schema.ts +2 -2
  65. package/src/mapping.ts +228 -75
  66. package/src/react/deltas.ts +165 -52
  67. package/src/react/optimisticallySendMessage.ts +4 -1
  68. package/src/react/toUIMessages.test.ts +154 -36
  69. package/src/react/toUIMessages.ts +136 -57
  70. package/src/validators.test.ts +2 -99
  71. package/src/validators.ts +95 -17
@@ -1,22 +1,41 @@
1
- import type { ToolInvocationUIPart } from "@ai-sdk/ui-utils";
2
- import type { UIMessage as AIUIMessage } from "ai";
1
+ import type {
2
+ UIMessage as AIUIMessage,
3
+ DeepPartial,
4
+ ReasoningUIPart,
5
+ SourceDocumentUIPart,
6
+ SourceUrlUIPart,
7
+ StepStartUIPart,
8
+ TextUIPart,
9
+ ToolUIPart,
10
+ UIDataTypes,
11
+ UITools,
12
+ } from "ai";
3
13
  import type { MessageDoc } from "../client/index.js";
4
14
  import { deserializeMessage, toUIFilePart } from "../mapping.js";
5
15
  import type { MessageStatus } from "../validators.js";
6
16
 
7
- export type UIMessage = AIUIMessage & {
17
+ export type UIMessage<
18
+ METADATA = unknown,
19
+ DATA_PARTS extends UIDataTypes = UIDataTypes,
20
+ TOOLS extends UITools = UITools,
21
+ > = AIUIMessage<METADATA, DATA_PARTS, TOOLS> & {
8
22
  key: string;
9
23
  order: number;
10
24
  stepOrder: number;
11
25
  status: "streaming" | MessageStatus;
12
26
  agentName?: string;
27
+ text: string;
13
28
  };
14
29
 
15
- export function toUIMessages(
30
+ export function toUIMessages<
31
+ METADATA = unknown,
32
+ DATA_PARTS extends UIDataTypes = UIDataTypes,
33
+ TOOLS extends UITools = UITools,
34
+ >(
16
35
  messages: (MessageDoc & { streaming?: boolean })[],
17
- ): UIMessage[] {
18
- const uiMessages: UIMessage[] = [];
19
- let assistantMessage: UIMessage | undefined;
36
+ ): UIMessage<METADATA, DATA_PARTS, TOOLS>[] {
37
+ const uiMessages: UIMessage<METADATA, DATA_PARTS, TOOLS>[] = [];
38
+ let assistantMessage: UIMessage<METADATA, DATA_PARTS, TOOLS> | undefined;
20
39
  for (const message of messages) {
21
40
  const coreMessage = message.message && deserializeMessage(message.message);
22
41
  const text = message.text ?? "";
@@ -31,17 +50,23 @@ export function toUIMessages(
31
50
  stepOrder: message.stepOrder,
32
51
  status: message.streaming ? ("streaming" as const) : message.status,
33
52
  key: `${message.threadId}-${message.order}-${message.stepOrder}`,
53
+ text,
54
+ };
55
+ const partCommon = {
56
+ state: message.streaming ? ("streaming" as const) : ("done" as const),
57
+ ...(message.providerMetadata
58
+ ? { providerMetadata: message.providerMetadata }
59
+ : {}),
34
60
  };
35
61
  if (coreMessage.role === "system") {
36
62
  uiMessages.push({
37
63
  ...common,
38
64
  role: "system",
39
- content: text,
40
65
  agentName: message.agentName,
41
- parts: [{ type: "text", text }],
66
+ parts: [{ type: "text", text, ...partCommon } satisfies TextUIPart],
42
67
  });
43
68
  } else if (coreMessage.role === "user") {
44
- const parts: UIMessage["parts"] = [];
69
+ const parts: UIMessage<METADATA, DATA_PARTS, TOOLS>["parts"] = [];
45
70
  if (text) {
46
71
  parts.push({ type: "text", text });
47
72
  }
@@ -56,7 +81,6 @@ export function toUIMessages(
56
81
  uiMessages.push({
57
82
  ...common,
58
83
  role: "user",
59
- content: message.text ?? "",
60
84
  parts,
61
85
  });
62
86
  } else {
@@ -72,7 +96,6 @@ export function toUIMessages(
72
96
  ...common,
73
97
  role: "assistant",
74
98
  agentName: message.agentName,
75
- content: "",
76
99
  parts: [],
77
100
  };
78
101
  uiMessages.push(assistantMessage);
@@ -83,78 +106,134 @@ export function toUIMessages(
83
106
  }
84
107
  // update it to the last message's id
85
108
  assistantMessage.id = message._id;
86
- if (message.reasoning) {
109
+ if (
110
+ message.reasoning &&
111
+ !nonStringContent.some((c) => c.type === "reasoning")
112
+ ) {
87
113
  assistantMessage.parts.push({
88
114
  type: "reasoning",
89
- reasoning: message.reasoning,
90
- details: message.reasoningDetails ?? [],
91
- });
115
+ text: message.reasoning,
116
+ ...partCommon,
117
+ } satisfies ReasoningUIPart);
92
118
  }
93
- if (message.text) {
119
+ if (message.text && !nonStringContent.length) {
94
120
  assistantMessage.parts.push({
95
121
  type: "text",
96
122
  text: message.text,
97
- });
98
- assistantMessage.content += message.text;
123
+ ...partCommon,
124
+ } satisfies TextUIPart);
99
125
  }
100
126
  for (const source of message.sources ?? []) {
101
- assistantMessage.parts.push({
102
- type: "source",
103
- source,
104
- });
127
+ if (source.sourceType === "url") {
128
+ assistantMessage.parts.push({
129
+ type: "source-url",
130
+ url: source.url!,
131
+ sourceId: source.id,
132
+ providerMetadata: message.providerMetadata,
133
+ title: source.title,
134
+ } satisfies SourceUrlUIPart);
135
+ } else {
136
+ assistantMessage.parts.push({
137
+ type: "source-document",
138
+ mediaType: source.mediaType,
139
+ sourceId: source.id,
140
+ title: source.title,
141
+ filename: source.filename,
142
+ providerMetadata: message.providerMetadata,
143
+ } satisfies SourceDocumentUIPart);
144
+ }
105
145
  }
106
146
  for (const contentPart of nonStringContent) {
107
147
  switch (contentPart.type) {
148
+ case "text":
149
+ assistantMessage.parts.push({
150
+ ...partCommon,
151
+ ...contentPart,
152
+ } satisfies TextUIPart);
153
+ break;
154
+ case "reasoning":
155
+ assistantMessage.parts.push({
156
+ ...partCommon,
157
+ ...contentPart,
158
+ } satisfies ReasoningUIPart);
159
+ break;
108
160
  case "file":
109
161
  case "image":
110
162
  assistantMessage.parts.push(toUIFilePart(contentPart));
111
163
  break;
112
- case "tool-call":
164
+ case "tool-call": {
113
165
  assistantMessage.parts.push({
114
166
  type: "step-start",
115
- });
116
- assistantMessage.parts.push({
117
- type: "tool-invocation",
118
- toolInvocation: {
119
- state: "call",
120
- step: assistantMessage.parts.filter(
121
- (part) => part.type === "tool-invocation",
122
- ).length,
123
- toolCallId: contentPart.toolCallId,
124
- toolName: contentPart.toolName,
125
- args: contentPart.args,
126
- },
127
- });
167
+ } satisfies StepStartUIPart);
168
+ const toolPart: ToolUIPart<TOOLS> = {
169
+ type: `tool-${contentPart.toolName as keyof TOOLS & string}`,
170
+ toolCallId: contentPart.toolCallId,
171
+ input: contentPart.input as DeepPartial<
172
+ TOOLS[keyof TOOLS & string]["input"]
173
+ >,
174
+ providerExecuted: contentPart.providerExecuted,
175
+ ...(message.streaming
176
+ ? { state: "input-streaming" }
177
+ : {
178
+ state: "input-available",
179
+ callProviderMetadata: message.providerMetadata,
180
+ }),
181
+ };
182
+ assistantMessage.parts.push(toolPart);
128
183
  break;
184
+ }
129
185
  case "tool-result": {
130
186
  const call = assistantMessage.parts.find(
131
187
  (part) =>
132
- part.type === "tool-invocation" &&
133
- part.toolInvocation.toolCallId === contentPart.toolCallId,
134
- ) as ToolInvocationUIPart | undefined;
135
- const toolInvocation: ToolInvocationUIPart["toolInvocation"] = {
136
- state: "result",
137
- toolCallId: contentPart.toolCallId,
138
- toolName: contentPart.toolName,
139
- args: call?.toolInvocation.args,
140
- result: contentPart.result,
141
- step:
142
- call?.toolInvocation.step ??
143
- assistantMessage.parts.filter(
144
- (part) => part.type === "tool-invocation",
145
- ).length,
146
- };
188
+ part.type === `tool-${contentPart.toolName}` &&
189
+ "toolCallId" in part &&
190
+ part.toolCallId === contentPart.toolCallId,
191
+ ) as ToolUIPart | undefined;
147
192
  if (call) {
148
- (call as ToolInvocationUIPart).toolInvocation = toolInvocation;
193
+ if (message.error) {
194
+ call.state = "output-error";
195
+ call.errorText = message.error;
196
+ call.output = contentPart.output;
197
+ } else {
198
+ call.state = "output-available";
199
+ call.output =
200
+ contentPart.output?.type === "json"
201
+ ? contentPart.output.value
202
+ : contentPart.output;
203
+ // Technically we could pull this from the doc.message
204
+ // but the ModelMessage doesn't have it
205
+ // call.providerExecuted = contentPart.providerExecuted;
206
+ }
149
207
  } else {
150
208
  console.warn(
151
209
  "Tool result without preceding tool call.. adding anyways",
152
210
  contentPart,
153
211
  );
154
- assistantMessage.parts.push({
155
- type: "tool-invocation",
156
- toolInvocation,
157
- });
212
+ if (message.error) {
213
+ assistantMessage.parts.push({
214
+ type: `tool-${contentPart.toolName}`,
215
+ toolCallId: contentPart.toolCallId,
216
+ state: "output-error",
217
+ input: undefined,
218
+ errorText: message.error,
219
+ // Technically we could pull this from the doc.message
220
+ // but the ModelMessage doesn't have it
221
+ // providerExecuted: contentPart.providerExecuted,
222
+ callProviderMetadata: message.providerMetadata,
223
+ } satisfies ToolUIPart<TOOLS>);
224
+ } else {
225
+ assistantMessage.parts.push({
226
+ type: `tool-${contentPart.toolName}`,
227
+ toolCallId: contentPart.toolCallId,
228
+ state: "output-available",
229
+ input: undefined,
230
+ output:
231
+ contentPart.output?.type === "json"
232
+ ? contentPart.output.value
233
+ : contentPart.output,
234
+ callProviderMetadata: message.providerMetadata,
235
+ } satisfies ToolUIPart<TOOLS>);
236
+ }
158
237
  }
159
238
  break;
160
239
  }
@@ -1,108 +1,11 @@
1
- import type {
2
- TextStreamPart as AITextStreamPart,
3
- AssistantContent,
4
- CoreAssistantMessage,
5
- CoreMessage,
6
- CoreSystemMessage,
7
- CoreToolMessage,
8
- CoreUserMessage,
9
- FilePart,
10
- ImagePart,
11
- TextPart,
12
- ToolCallPart,
13
- ToolContent,
14
- ToolSet,
15
- UserContent,
16
- } from "ai";
1
+ import type { TextStreamPart as AITextStreamPart, ToolSet } from "ai";
17
2
  import type { Infer } from "convex/values";
18
3
  import { expectTypeOf, test } from "vitest";
19
4
  import type { ContextOptions, StorageOptions } from "./client/types.js";
20
- import type { SerializeUrlsAndUint8Arrays } from "./mapping.js";
21
5
  import type { TextStreamPart } from "./validators.js";
22
- import {
23
- vAssistantContent,
24
- vAssistantMessage,
25
- vContextOptions,
26
- vFilePart,
27
- vImagePart,
28
- vMessage,
29
- vReasoningPart,
30
- vRedactedReasoningPart,
31
- vStorageOptions,
32
- vSystemMessage,
33
- vTextPart,
34
- vToolCallPart,
35
- vToolContent,
36
- vToolMessage,
37
- vUserContent,
38
- vUserMessage,
39
- } from "./validators.js";
6
+ import { vContextOptions, vStorageOptions } from "./validators.js";
40
7
 
41
- // type assertion
42
- type OurUserContent = SerializeUrlsAndUint8Arrays<UserContent>;
43
- expectTypeOf<OurUserContent>().toExtend<Infer<typeof vUserContent>>();
44
- expectTypeOf<Infer<typeof vUserContent>>().toExtend<OurUserContent>();
45
8
 
46
- type OurAssistantContent = SerializeUrlsAndUint8Arrays<AssistantContent>;
47
- expectTypeOf<OurAssistantContent>().toExtend<Infer<typeof vAssistantContent>>();
48
- expectTypeOf<Infer<typeof vAssistantContent>>().toExtend<OurAssistantContent>();
49
-
50
- type OurToolContent = SerializeUrlsAndUint8Arrays<ToolContent>;
51
- expectTypeOf<OurToolContent>().toExtend<Infer<typeof vToolContent>>();
52
- expectTypeOf<Infer<typeof vToolContent>>().toExtend<OurToolContent>();
53
-
54
- expectTypeOf<Infer<typeof vToolCallPart>>().toExtend<ToolCallPart>();
55
- expectTypeOf<ToolCallPart>().toExtend<Infer<typeof vToolCallPart>>();
56
-
57
- type OurTextPart = SerializeUrlsAndUint8Arrays<TextPart>;
58
- expectTypeOf<OurTextPart>().toExtend<Infer<typeof vTextPart>>();
59
- expectTypeOf<Infer<typeof vTextPart>>().toExtend<OurTextPart>();
60
-
61
- type OurImagePart = SerializeUrlsAndUint8Arrays<ImagePart>;
62
- expectTypeOf<OurImagePart>().toExtend<Infer<typeof vImagePart>>();
63
- expectTypeOf<Infer<typeof vImagePart>>().toExtend<OurImagePart>();
64
-
65
- type OurFilePart = SerializeUrlsAndUint8Arrays<FilePart>;
66
- expectTypeOf<OurFilePart>().toExtend<Infer<typeof vFilePart>>();
67
- expectTypeOf<Infer<typeof vFilePart>>().toExtend<OurFilePart>();
68
-
69
- // narrow to the type
70
- type ReasoningPart = AssistantContent[number] & { type: "reasoning" } & object;
71
- type OurReasoningPart = SerializeUrlsAndUint8Arrays<ReasoningPart>;
72
- expectTypeOf<OurReasoningPart>().toExtend<Infer<typeof vReasoningPart>>();
73
- expectTypeOf<Infer<typeof vReasoningPart>>().toExtend<OurReasoningPart>();
74
-
75
- // narrow to the type
76
- type RedactedReasoningPart = AssistantContent[number] & {
77
- type: "redacted-reasoning";
78
- } & object;
79
- type OurRedactedReasoningPart =
80
- SerializeUrlsAndUint8Arrays<RedactedReasoningPart>;
81
- expectTypeOf<OurRedactedReasoningPart>().toExtend<
82
- Infer<typeof vRedactedReasoningPart>
83
- >();
84
- expectTypeOf<
85
- Infer<typeof vRedactedReasoningPart>
86
- >().toExtend<OurRedactedReasoningPart>();
87
-
88
- // test("noop", () => {
89
- type OurUserMessage = SerializeUrlsAndUint8Arrays<CoreUserMessage>;
90
- expectTypeOf<OurUserMessage>().toExtend<Infer<typeof vUserMessage>>();
91
- expectTypeOf<Infer<typeof vUserMessage>>().toExtend<OurUserMessage>();
92
-
93
- type OurAssistantMessage = SerializeUrlsAndUint8Arrays<CoreAssistantMessage>;
94
- expectTypeOf<OurAssistantMessage>().toExtend<Infer<typeof vAssistantMessage>>();
95
- expectTypeOf<Infer<typeof vAssistantMessage>>().toExtend<OurAssistantMessage>();
96
-
97
- expectTypeOf<Infer<typeof vToolMessage>>().toExtend<CoreToolMessage>();
98
- expectTypeOf<CoreToolMessage>().toExtend<Infer<typeof vToolMessage>>();
99
-
100
- expectTypeOf<Infer<typeof vSystemMessage>>().toExtend<CoreSystemMessage>();
101
- expectTypeOf<CoreSystemMessage>().toExtend<Infer<typeof vSystemMessage>>();
102
-
103
- type OurMessage = SerializeUrlsAndUint8Arrays<CoreMessage>;
104
- expectTypeOf<OurMessage>().toExtend<Infer<typeof vMessage>>();
105
- expectTypeOf<Infer<typeof vMessage>>().toExtend<OurMessage>();
106
9
 
107
10
  expectTypeOf<Infer<typeof vContextOptions>>().toExtend<ContextOptions>();
108
11
  expectTypeOf<ContextOptions>().toExtend<Infer<typeof vContextOptions>>();
package/src/validators.ts CHANGED
@@ -69,6 +69,7 @@ export const vReasoningPart = v.object({
69
69
  text: v.string(),
70
70
  signature: v.optional(v.string()),
71
71
  providerOptions,
72
+ state: v.optional(v.union(v.literal("streaming"), v.literal("done"))),
72
73
  });
73
74
 
74
75
  export const vRedactedReasoningPart = v.object({
@@ -79,6 +80,7 @@ export const vRedactedReasoningPart = v.object({
79
80
 
80
81
  export const vReasoningDetails = v.array(
81
82
  v.union(
83
+ vReasoningPart,
82
84
  v.object({
83
85
  type: v.literal("text"),
84
86
  text: v.string(),
@@ -97,6 +99,7 @@ export const vToolCallPart = v.object({
97
99
  toolName: v.string(),
98
100
  args: v.any(),
99
101
  providerOptions,
102
+ providerExecuted: v.optional(v.boolean()),
100
103
  });
101
104
 
102
105
  export const vAssistantContent = v.union(
@@ -126,17 +129,20 @@ const vToolResultContent = v.array(
126
129
  ),
127
130
  );
128
131
 
129
- const vToolResultPart = v.object({
132
+ export const vToolResultPart = v.object({
130
133
  type: v.literal("tool-result"),
131
134
  toolCallId: v.string(),
132
135
  toolName: v.string(),
133
136
  result: v.any(),
137
+ providerOptions,
138
+ providerExecuted: v.optional(v.boolean()),
139
+
140
+ // Deprecated in ai v5
141
+ isError: v.optional(v.boolean()),
134
142
  // This is only here b/c steps include it in toolResults
135
- // Normal CoreMessage doesn't have this
143
+ // Normal ModelMessage doesn't have this
136
144
  args: v.optional(v.any()),
137
145
  experimental_content: v.optional(vToolResultContent),
138
- isError: v.optional(v.boolean()),
139
- providerOptions,
140
146
  });
141
147
  export const vToolContent = v.array(vToolResultPart);
142
148
 
@@ -175,13 +181,25 @@ export const vMessage = v.union(
175
181
  );
176
182
  export type Message = Infer<typeof vMessage>;
177
183
 
178
- export const vSource = v.object({
179
- sourceType: v.literal("url"),
180
- id: v.string(),
181
- url: v.string(),
182
- title: v.optional(v.string()),
183
- providerOptions,
184
- });
184
+ export const vSource = v.union(
185
+ v.object({
186
+ type: v.optional(v.literal("source")),
187
+ sourceType: v.literal("url"),
188
+ id: v.string(),
189
+ url: v.optional(v.string()),
190
+ title: v.optional(v.string()),
191
+ providerOptions,
192
+ }),
193
+ v.object({
194
+ type: v.literal("source"),
195
+ sourceType: v.literal("document"),
196
+ id: v.string(),
197
+ mediaType: v.string(),
198
+ title: v.string(),
199
+ filename: v.optional(v.string()),
200
+ providerMetadata,
201
+ }),
202
+ );
185
203
 
186
204
  export const vRequest = v.object({
187
205
  body: v.optional(v.any()),
@@ -228,10 +246,12 @@ export const vUsage = v.object({
228
246
  promptTokens: v.number(),
229
247
  completionTokens: v.number(),
230
248
  totalTokens: v.number(),
249
+ reasoningTokens: v.optional(v.number()),
250
+ cachedInputTokens: v.optional(v.number()),
231
251
  });
232
252
  export type Usage = Infer<typeof vUsage>;
233
253
 
234
- export const vLanguageModelV1CallWarning = v.union(
254
+ export const vLanguageModelCallWarning = v.union(
235
255
  v.object({
236
256
  type: v.literal("unsupported-setting"),
237
257
  setting: v.string(),
@@ -262,7 +282,7 @@ export const vMessageWithMetadataInternal = v.object({
262
282
  reasoning: v.optional(v.string()),
263
283
  reasoningDetails: v.optional(vReasoningDetails),
264
284
  usage: v.optional(vUsage),
265
- warnings: v.optional(v.array(vLanguageModelV1CallWarning)),
285
+ warnings: v.optional(v.array(vLanguageModelCallWarning)),
266
286
  error: v.optional(v.string()),
267
287
  });
268
288
  export const vMessageWithMetadata = v.object({
@@ -285,7 +305,7 @@ export const vObjectResult = v.object({
285
305
  usage: v.optional(v.any()),
286
306
  object: v.any(),
287
307
  error: v.optional(v.string()),
288
- warnings: v.optional(v.array(vLanguageModelV1CallWarning)),
308
+ warnings: v.optional(v.array(vLanguageModelCallWarning)),
289
309
  providerMetadata,
290
310
  });
291
311
  export type ObjectResult = Infer<typeof vObjectResult>;
@@ -388,7 +408,7 @@ export function vPaginationResult<
388
408
  });
389
409
  }
390
410
 
391
- export const vTextStreamPart = v.union(
411
+ export const vTextStreamPartV4 = v.union(
392
412
  v.object({
393
413
  type: v.literal("text-delta"),
394
414
  textDelta: v.string(),
@@ -399,9 +419,16 @@ export const vTextStreamPart = v.union(
399
419
  }),
400
420
  v.object({
401
421
  type: v.literal("source"),
402
- source: vSource,
422
+ source: v.object({
423
+ sourceType: v.literal("url"),
424
+ id: v.string(),
425
+ url: v.optional(v.string()),
426
+ title: v.optional(v.string()),
427
+ providerOptions,
428
+ }),
403
429
  }),
404
430
  vToolCallPart,
431
+ vToolResultPart,
405
432
  v.object({
406
433
  type: v.literal("tool-call-streaming-start"),
407
434
  toolCallId: v.string(),
@@ -413,8 +440,59 @@ export const vTextStreamPart = v.union(
413
440
  toolName: v.string(),
414
441
  argsTextDelta: v.string(),
415
442
  }),
416
- vToolResultPart,
417
443
  );
444
+ export const vTextStreamPartV5 = v.union(
445
+ v.object({
446
+ type: v.literal("text-delta"),
447
+ id: v.string(),
448
+ text: v.string(),
449
+ providerMetadata,
450
+ }),
451
+ v.object({
452
+ type: v.literal("reasoning-delta"),
453
+ id: v.string(),
454
+ text: v.string(),
455
+ providerMetadata,
456
+ }),
457
+ vSource,
458
+ v.object({
459
+ type: v.literal("tool-call"),
460
+ toolCallId: v.string(),
461
+ toolName: v.string(),
462
+ input: v.any(),
463
+ providerExecuted: v.optional(v.boolean()),
464
+ dynamic: v.optional(v.boolean()),
465
+ providerMetadata,
466
+ }),
467
+ v.object({
468
+ type: v.literal("tool-input-start"),
469
+ id: v.string(),
470
+ toolName: v.string(),
471
+ providerMetadata,
472
+ providerExecuted: v.optional(v.boolean()),
473
+ dynamic: v.optional(v.boolean()),
474
+ }),
475
+ v.object({
476
+ type: v.literal("tool-input-delta"),
477
+ id: v.string(),
478
+ delta: v.string(),
479
+ providerMetadata,
480
+ }),
481
+ v.object({
482
+ type: v.literal("tool-result"),
483
+ toolCallId: v.string(),
484
+ toolName: v.string(),
485
+ input: v.optional(v.any()),
486
+ output: v.optional(v.any()),
487
+ providerExecuted: v.optional(v.boolean()),
488
+ dynamic: v.optional(v.boolean()),
489
+ }),
490
+ v.object({
491
+ type: v.literal("raw"),
492
+ rawValue: v.any(),
493
+ }),
494
+ );
495
+ export const vTextStreamPart = v.union(vTextStreamPartV4, vTextStreamPartV5);
418
496
  export type TextStreamPart = Infer<typeof vTextStreamPart>;
419
497
 
420
498
  export const vStreamCursor = v.object({