ai 5.0.56 → 5.1.0-beta.0

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.
package/dist/index.mjs CHANGED
@@ -12,7 +12,6 @@ import {
12
12
  dynamicTool as dynamicTool2,
13
13
  generateId as generateId2,
14
14
  jsonSchema as jsonSchema2,
15
- parseJsonEventStream as parseJsonEventStream3,
16
15
  tool as tool2,
17
16
  zodSchema
18
17
  } from "@ai-sdk/provider-utils";
@@ -679,7 +678,7 @@ import {
679
678
  } from "@ai-sdk/provider-utils";
680
679
 
681
680
  // src/version.ts
682
- var VERSION = true ? "5.0.56" : "0.0.0-test";
681
+ var VERSION = true ? "5.1.0-beta.0" : "0.0.0-test";
683
682
 
684
683
  // src/util/download/download.ts
685
684
  var download = async ({ url }) => {
@@ -972,12 +971,12 @@ async function downloadAssets(messages, download2, supportedUrls) {
972
971
  }));
973
972
  const downloadedFiles = await download2(plannedDownloads);
974
973
  return Object.fromEntries(
975
- downloadedFiles.map(
976
- (file, index) => file == null ? null : [
977
- plannedDownloads[index].url.toString(),
978
- { data: file.data, mediaType: file.mediaType }
979
- ]
980
- ).filter((file) => file != null)
974
+ downloadedFiles.filter(
975
+ (downloadedFile) => (downloadedFile == null ? void 0 : downloadedFile.data) != null
976
+ ).map(({ data, mediaType }, index) => [
977
+ plannedDownloads[index].url.toString(),
978
+ { data, mediaType }
979
+ ])
981
980
  );
982
981
  }
983
982
  function convertPartToLanguageModelPart(part, downloadedAssets) {
@@ -2923,6 +2922,11 @@ var uiMessageChunkSchema = z7.union([
2923
2922
  providerExecuted: z7.boolean().optional(),
2924
2923
  dynamic: z7.boolean().optional()
2925
2924
  }),
2925
+ z7.strictObject({
2926
+ type: z7.literal("reasoning"),
2927
+ text: z7.string(),
2928
+ providerMetadata: providerMetadataSchema.optional()
2929
+ }),
2926
2930
  z7.strictObject({
2927
2931
  type: z7.literal("reasoning-start"),
2928
2932
  id: z7.string(),
@@ -2939,6 +2943,9 @@ var uiMessageChunkSchema = z7.union([
2939
2943
  id: z7.string(),
2940
2944
  providerMetadata: providerMetadataSchema.optional()
2941
2945
  }),
2946
+ z7.strictObject({
2947
+ type: z7.literal("reasoning-part-finish")
2948
+ }),
2942
2949
  z7.strictObject({
2943
2950
  type: z7.literal("source-url"),
2944
2951
  sourceId: z7.string(),
@@ -2961,10 +2968,7 @@ var uiMessageChunkSchema = z7.union([
2961
2968
  providerMetadata: providerMetadataSchema.optional()
2962
2969
  }),
2963
2970
  z7.strictObject({
2964
- type: z7.custom(
2965
- (value) => typeof value === "string" && value.startsWith("data-"),
2966
- { message: 'Type must start with "data-"' }
2967
- ),
2971
+ type: z7.string().startsWith("data-"),
2968
2972
  id: z7.string().optional(),
2969
2973
  data: z7.unknown(),
2970
2974
  transient: z7.boolean().optional()
@@ -4593,7 +4597,7 @@ var DefaultStreamTextResult = class {
4593
4597
  let activeReasoningContent = {};
4594
4598
  const eventProcessor = new TransformStream({
4595
4599
  async transform(chunk, controller) {
4596
- var _a17, _b, _c, _d;
4600
+ var _a17, _b, _c;
4597
4601
  controller.enqueue(chunk);
4598
4602
  const { part } = chunk;
4599
4603
  if (part.type === "text-delta" || part.type === "reasoning-delta" || part.type === "source" || part.type === "tool-call" || part.type === "tool-result" || part.type === "tool-input-start" || part.type === "tool-input-delta" || part.type === "raw") {
@@ -4626,18 +4630,6 @@ var DefaultStreamTextResult = class {
4626
4630
  activeText.providerMetadata = (_a17 = part.providerMetadata) != null ? _a17 : activeText.providerMetadata;
4627
4631
  }
4628
4632
  if (part.type === "text-end") {
4629
- const activeText = activeTextContent[part.id];
4630
- if (activeText == null) {
4631
- controller.enqueue({
4632
- part: {
4633
- type: "error",
4634
- error: `text part ${part.id} not found`
4635
- },
4636
- partialOutput: void 0
4637
- });
4638
- return;
4639
- }
4640
- activeText.providerMetadata = (_b = part.providerMetadata) != null ? _b : activeText.providerMetadata;
4641
4633
  delete activeTextContent[part.id];
4642
4634
  }
4643
4635
  if (part.type === "reasoning-start") {
@@ -4661,7 +4653,7 @@ var DefaultStreamTextResult = class {
4661
4653
  return;
4662
4654
  }
4663
4655
  activeReasoning.text += part.text;
4664
- activeReasoning.providerMetadata = (_c = part.providerMetadata) != null ? _c : activeReasoning.providerMetadata;
4656
+ activeReasoning.providerMetadata = (_b = part.providerMetadata) != null ? _b : activeReasoning.providerMetadata;
4665
4657
  }
4666
4658
  if (part.type === "reasoning-end") {
4667
4659
  const activeReasoning = activeReasoningContent[part.id];
@@ -4675,7 +4667,7 @@ var DefaultStreamTextResult = class {
4675
4667
  });
4676
4668
  return;
4677
4669
  }
4678
- activeReasoning.providerMetadata = (_d = part.providerMetadata) != null ? _d : activeReasoning.providerMetadata;
4670
+ activeReasoning.providerMetadata = (_c = part.providerMetadata) != null ? _c : activeReasoning.providerMetadata;
4679
4671
  delete activeReasoningContent[part.id];
4680
4672
  }
4681
4673
  if (part.type === "file") {
@@ -9709,11 +9701,9 @@ var AbstractChat = class {
9709
9701
  }
9710
9702
  };
9711
9703
  this.addToolResult = async ({
9712
- state = "output-available",
9713
9704
  tool: tool3,
9714
9705
  toolCallId,
9715
- output,
9716
- errorText
9706
+ output
9717
9707
  }) => this.jobExecutor.run(async () => {
9718
9708
  var _a17, _b;
9719
9709
  const messages = this.state.messages;
@@ -9721,16 +9711,16 @@ var AbstractChat = class {
9721
9711
  this.state.replaceMessage(messages.length - 1, {
9722
9712
  ...lastMessage,
9723
9713
  parts: lastMessage.parts.map(
9724
- (part) => isToolOrDynamicToolUIPart(part) && part.toolCallId === toolCallId ? { ...part, state, output, errorText } : part
9714
+ (part) => isToolOrDynamicToolUIPart(part) && part.toolCallId === toolCallId ? { ...part, state: "output-available", output } : part
9725
9715
  )
9726
9716
  });
9727
9717
  if (this.activeResponse) {
9728
9718
  this.activeResponse.state.message.parts = this.activeResponse.state.message.parts.map(
9729
9719
  (part) => isToolOrDynamicToolUIPart(part) && part.toolCallId === toolCallId ? {
9730
9720
  ...part,
9731
- state,
9721
+ state: "output-available",
9732
9722
  output,
9733
- errorText
9723
+ errorText: void 0
9734
9724
  } : part
9735
9725
  );
9736
9726
  }
@@ -9939,9 +9929,7 @@ function lastAssistantMessageIsCompleteWithToolCalls({
9939
9929
  return part.type === "step-start" ? index : lastIndex;
9940
9930
  }, -1);
9941
9931
  const lastStepToolInvocations = message.parts.slice(lastStepStartIndex + 1).filter(isToolOrDynamicToolUIPart);
9942
- return lastStepToolInvocations.length > 0 && lastStepToolInvocations.every(
9943
- (part) => part.state === "output-available" || part.state === "output-error"
9944
- );
9932
+ return lastStepToolInvocations.length > 0 && lastStepToolInvocations.every((part) => part.state === "output-available");
9945
9933
  }
9946
9934
 
9947
9935
  // src/ui/transform-text-to-ui-message-stream.ts
@@ -10129,118 +10117,82 @@ var uiMessageSchema = z10.object({
10129
10117
  ])
10130
10118
  )
10131
10119
  });
10132
- async function safeValidateUIMessages({
10120
+ async function validateUIMessages({
10133
10121
  messages,
10134
10122
  metadataSchema,
10135
10123
  dataSchemas,
10136
10124
  tools
10137
10125
  }) {
10138
- try {
10139
- if (messages == null) {
10140
- return {
10141
- success: false,
10142
- error: new InvalidArgumentError({
10143
- parameter: "messages",
10144
- value: messages,
10145
- message: "messages parameter must be provided"
10146
- })
10147
- };
10148
- }
10149
- const validatedMessages = await validateTypes2({
10126
+ if (messages == null) {
10127
+ throw new InvalidArgumentError({
10128
+ parameter: "messages",
10150
10129
  value: messages,
10151
- schema: z10.array(uiMessageSchema)
10130
+ message: "messages parameter must be provided"
10152
10131
  });
10153
- if (metadataSchema) {
10154
- for (const message of validatedMessages) {
10132
+ }
10133
+ const validatedMessages = await validateTypes2({
10134
+ value: messages,
10135
+ schema: z10.array(uiMessageSchema)
10136
+ });
10137
+ if (metadataSchema) {
10138
+ for (const message of validatedMessages) {
10139
+ await validateTypes2({
10140
+ value: message.metadata,
10141
+ schema: metadataSchema
10142
+ });
10143
+ }
10144
+ }
10145
+ if (dataSchemas) {
10146
+ for (const message of validatedMessages) {
10147
+ const dataParts = message.parts.filter(
10148
+ (part) => part.type.startsWith("data-")
10149
+ );
10150
+ for (const dataPart of dataParts) {
10151
+ const dataName = dataPart.type.slice(5);
10152
+ const dataSchema = dataSchemas[dataName];
10153
+ if (!dataSchema) {
10154
+ throw new TypeValidationError4({
10155
+ value: dataPart.data,
10156
+ cause: `No data schema found for data part ${dataName}`
10157
+ });
10158
+ }
10155
10159
  await validateTypes2({
10156
- value: message.metadata,
10157
- schema: metadataSchema
10160
+ value: dataPart.data,
10161
+ schema: dataSchema
10158
10162
  });
10159
10163
  }
10160
10164
  }
10161
- if (dataSchemas) {
10162
- for (const message of validatedMessages) {
10163
- const dataParts = message.parts.filter(
10164
- (part) => part.type.startsWith("data-")
10165
- );
10166
- for (const dataPart of dataParts) {
10167
- const dataName = dataPart.type.slice(5);
10168
- const dataSchema = dataSchemas[dataName];
10169
- if (!dataSchema) {
10170
- return {
10171
- success: false,
10172
- error: new TypeValidationError4({
10173
- value: dataPart.data,
10174
- cause: `No data schema found for data part ${dataName}`
10175
- })
10176
- };
10177
- }
10165
+ }
10166
+ if (tools) {
10167
+ for (const message of validatedMessages) {
10168
+ const toolParts = message.parts.filter(
10169
+ (part) => part.type.startsWith("tool-")
10170
+ );
10171
+ for (const toolPart of toolParts) {
10172
+ const toolName = toolPart.type.slice(5);
10173
+ const tool3 = tools[toolName];
10174
+ if (!tool3) {
10175
+ throw new TypeValidationError4({
10176
+ value: toolPart.input,
10177
+ cause: `No tool schema found for tool part ${toolName}`
10178
+ });
10179
+ }
10180
+ if (toolPart.state === "input-available" || toolPart.state === "output-available" || toolPart.state === "output-error") {
10178
10181
  await validateTypes2({
10179
- value: dataPart.data,
10180
- schema: dataSchema
10182
+ value: toolPart.input,
10183
+ schema: tool3.inputSchema
10181
10184
  });
10182
10185
  }
10183
- }
10184
- }
10185
- if (tools) {
10186
- for (const message of validatedMessages) {
10187
- const toolParts = message.parts.filter(
10188
- (part) => part.type.startsWith("tool-")
10189
- );
10190
- for (const toolPart of toolParts) {
10191
- const toolName = toolPart.type.slice(5);
10192
- const tool3 = tools[toolName];
10193
- if (!tool3) {
10194
- return {
10195
- success: false,
10196
- error: new TypeValidationError4({
10197
- value: toolPart.input,
10198
- cause: `No tool schema found for tool part ${toolName}`
10199
- })
10200
- };
10201
- }
10202
- if (toolPart.state === "input-available" || toolPart.state === "output-available" || toolPart.state === "output-error") {
10203
- await validateTypes2({
10204
- value: toolPart.input,
10205
- schema: tool3.inputSchema
10206
- });
10207
- }
10208
- if (toolPart.state === "output-available" && tool3.outputSchema) {
10209
- await validateTypes2({
10210
- value: toolPart.output,
10211
- schema: tool3.outputSchema
10212
- });
10213
- }
10186
+ if (toolPart.state === "output-available" && tool3.outputSchema) {
10187
+ await validateTypes2({
10188
+ value: toolPart.output,
10189
+ schema: tool3.outputSchema
10190
+ });
10214
10191
  }
10215
10192
  }
10216
10193
  }
10217
- return {
10218
- success: true,
10219
- data: validatedMessages
10220
- };
10221
- } catch (error) {
10222
- const err = error;
10223
- return {
10224
- success: false,
10225
- error: err
10226
- };
10227
10194
  }
10228
- }
10229
- async function validateUIMessages({
10230
- messages,
10231
- metadataSchema,
10232
- dataSchemas,
10233
- tools
10234
- }) {
10235
- const response = await safeValidateUIMessages({
10236
- messages,
10237
- metadataSchema,
10238
- dataSchemas,
10239
- tools
10240
- });
10241
- if (!response.success)
10242
- throw response.error;
10243
- return response.data;
10195
+ return validatedMessages;
10244
10196
  }
10245
10197
 
10246
10198
  // src/ui-message-stream/create-ui-message-stream.ts
@@ -10463,12 +10415,10 @@ export {
10463
10415
  jsonSchema2 as jsonSchema,
10464
10416
  lastAssistantMessageIsCompleteWithToolCalls,
10465
10417
  modelMessageSchema,
10466
- parseJsonEventStream3 as parseJsonEventStream,
10467
10418
  parsePartialJson,
10468
10419
  pipeTextStreamToResponse,
10469
10420
  pipeUIMessageStreamToResponse,
10470
10421
  readUIMessageStream,
10471
- safeValidateUIMessages,
10472
10422
  simulateReadableStream,
10473
10423
  simulateStreamingMiddleware,
10474
10424
  smoothStream,
@@ -10478,7 +10428,6 @@ export {
10478
10428
  systemModelMessageSchema,
10479
10429
  tool2 as tool,
10480
10430
  toolModelMessageSchema,
10481
- uiMessageChunkSchema,
10482
10431
  userModelMessageSchema,
10483
10432
  validateUIMessages,
10484
10433
  wrapLanguageModel,