ai 6.0.0-beta.67 → 6.0.0-beta.69

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
@@ -775,7 +775,7 @@ import {
775
775
  } from "@ai-sdk/provider-utils";
776
776
 
777
777
  // src/version.ts
778
- var VERSION = true ? "6.0.0-beta.67" : "0.0.0-test";
778
+ var VERSION = true ? "6.0.0-beta.69" : "0.0.0-test";
779
779
 
780
780
  // src/util/download/download.ts
781
781
  var download = async ({ url }) => {
@@ -3829,6 +3829,15 @@ async function parsePartialJson(jsonText) {
3829
3829
  function isDataUIPart(part) {
3830
3830
  return part.type.startsWith("data-");
3831
3831
  }
3832
+ function isTextUIPart(part) {
3833
+ return part.type === "text";
3834
+ }
3835
+ function isFileUIPart(part) {
3836
+ return part.type === "file";
3837
+ }
3838
+ function isReasoningUIPart(part) {
3839
+ return part.type === "reasoning";
3840
+ }
3832
3841
  function isToolUIPart(part) {
3833
3842
  return part.type.startsWith("tool-");
3834
3843
  }
@@ -6430,6 +6439,9 @@ function readUIMessageStream({
6430
6439
  }
6431
6440
 
6432
6441
  // src/ui/convert-to-model-messages.ts
6442
+ import {
6443
+ isNonNullable
6444
+ } from "@ai-sdk/provider-utils";
6433
6445
  function convertToModelMessages(messages, options) {
6434
6446
  const modelMessages = [];
6435
6447
  if (options == null ? void 0 : options.ignoreIncompleteToolCalls) {
@@ -6443,7 +6455,9 @@ function convertToModelMessages(messages, options) {
6443
6455
  for (const message of messages) {
6444
6456
  switch (message.role) {
6445
6457
  case "system": {
6446
- const textParts = message.parts.filter((part) => part.type === "text");
6458
+ const textParts = message.parts.filter(
6459
+ (part) => part.type === "text"
6460
+ );
6447
6461
  const providerMetadata = textParts.reduce((acc, part) => {
6448
6462
  if (part.providerMetadata != null) {
6449
6463
  return { ...acc, ...part.providerMetadata };
@@ -6460,54 +6474,57 @@ function convertToModelMessages(messages, options) {
6460
6474
  case "user": {
6461
6475
  modelMessages.push({
6462
6476
  role: "user",
6463
- content: message.parts.filter(
6464
- (part) => part.type === "text" || part.type === "file"
6465
- ).map((part) => {
6466
- switch (part.type) {
6467
- case "text":
6468
- return {
6469
- type: "text",
6470
- text: part.text,
6471
- ...part.providerMetadata != null ? { providerOptions: part.providerMetadata } : {}
6472
- };
6473
- case "file":
6474
- return {
6475
- type: "file",
6476
- mediaType: part.mediaType,
6477
- filename: part.filename,
6478
- data: part.url,
6479
- ...part.providerMetadata != null ? { providerOptions: part.providerMetadata } : {}
6480
- };
6481
- default:
6482
- return part;
6477
+ content: message.parts.map((part) => {
6478
+ var _a17;
6479
+ if (isTextUIPart(part)) {
6480
+ return {
6481
+ type: "text",
6482
+ text: part.text,
6483
+ ...part.providerMetadata != null ? { providerOptions: part.providerMetadata } : {}
6484
+ };
6483
6485
  }
6484
- })
6486
+ if (isFileUIPart(part)) {
6487
+ return {
6488
+ type: "file",
6489
+ mediaType: part.mediaType,
6490
+ filename: part.filename,
6491
+ data: part.url,
6492
+ ...part.providerMetadata != null ? { providerOptions: part.providerMetadata } : {}
6493
+ };
6494
+ }
6495
+ if (isDataUIPart(part)) {
6496
+ return (_a17 = options == null ? void 0 : options.convertDataPart) == null ? void 0 : _a17.call(
6497
+ options,
6498
+ part
6499
+ );
6500
+ }
6501
+ }).filter(isNonNullable)
6485
6502
  });
6486
6503
  break;
6487
6504
  }
6488
6505
  case "assistant": {
6489
6506
  if (message.parts != null) {
6490
6507
  let processBlock2 = function() {
6491
- var _a17, _b;
6508
+ var _a17, _b, _c;
6492
6509
  if (block.length === 0) {
6493
6510
  return;
6494
6511
  }
6495
6512
  const content = [];
6496
6513
  for (const part of block) {
6497
- if (part.type === "text") {
6514
+ if (isTextUIPart(part)) {
6498
6515
  content.push({
6499
6516
  type: "text",
6500
6517
  text: part.text,
6501
6518
  ...part.providerMetadata != null ? { providerOptions: part.providerMetadata } : {}
6502
6519
  });
6503
- } else if (part.type === "file") {
6520
+ } else if (isFileUIPart(part)) {
6504
6521
  content.push({
6505
6522
  type: "file",
6506
6523
  mediaType: part.mediaType,
6507
6524
  filename: part.filename,
6508
6525
  data: part.url
6509
6526
  });
6510
- } else if (part.type === "reasoning") {
6527
+ } else if (isReasoningUIPart(part)) {
6511
6528
  content.push({
6512
6529
  type: "reasoning",
6513
6530
  text: part.text,
@@ -6544,6 +6561,14 @@ function convertToModelMessages(messages, options) {
6544
6561
  });
6545
6562
  }
6546
6563
  }
6564
+ } else if (isDataUIPart(part)) {
6565
+ const dataPart = (_c = options == null ? void 0 : options.convertDataPart) == null ? void 0 : _c.call(
6566
+ options,
6567
+ part
6568
+ );
6569
+ if (dataPart != null) {
6570
+ content.push(dataPart);
6571
+ }
6547
6572
  } else {
6548
6573
  const _exhaustiveCheck = part;
6549
6574
  throw new Error(`Unsupported part: ${_exhaustiveCheck}`);
@@ -6561,7 +6586,7 @@ function convertToModelMessages(messages, options) {
6561
6586
  role: "tool",
6562
6587
  content: toolParts.flatMap(
6563
6588
  (toolPart) => {
6564
- var _a18, _b2, _c;
6589
+ var _a18, _b2, _c2;
6565
6590
  const outputs = [];
6566
6591
  if (((_a18 = toolPart.approval) == null ? void 0 : _a18.approved) != null) {
6567
6592
  outputs.push({
@@ -6593,7 +6618,7 @@ function convertToModelMessages(messages, options) {
6593
6618
  toolName,
6594
6619
  output: createToolModelOutput({
6595
6620
  output: toolPart.state === "output-error" ? toolPart.errorText : toolPart.output,
6596
- tool: (_c = options == null ? void 0 : options.tools) == null ? void 0 : _c[toolName],
6621
+ tool: (_c2 = options == null ? void 0 : options.tools) == null ? void 0 : _c2[toolName],
6597
6622
  errorMode: toolPart.state === "output-error" ? "text" : "none"
6598
6623
  })
6599
6624
  });
@@ -6610,7 +6635,7 @@ function convertToModelMessages(messages, options) {
6610
6635
  var processBlock = processBlock2;
6611
6636
  let block = [];
6612
6637
  for (const part of message.parts) {
6613
- if (part.type === "text" || part.type === "reasoning" || part.type === "file" || isToolOrDynamicToolUIPart(part)) {
6638
+ if (isTextUIPart(part) || isReasoningUIPart(part) || isFileUIPart(part) || isToolOrDynamicToolUIPart(part) || isDataUIPart(part)) {
6614
6639
  block.push(part);
6615
6640
  } else if (part.type === "step-start") {
6616
6641
  processBlock2();
@@ -7194,13 +7219,13 @@ var DefaultEmbedResult = class {
7194
7219
  import { withUserAgentSuffix as withUserAgentSuffix4 } from "@ai-sdk/provider-utils";
7195
7220
 
7196
7221
  // src/util/split-array.ts
7197
- function splitArray(array, chunkSize) {
7222
+ function splitArray(array2, chunkSize) {
7198
7223
  if (chunkSize <= 0) {
7199
7224
  throw new Error("chunkSize must be greater than 0");
7200
7225
  }
7201
7226
  const result = [];
7202
- for (let i = 0; i < array.length; i += chunkSize) {
7203
- result.push(array.slice(i, i + chunkSize));
7227
+ for (let i = 0; i < array2.length; i += chunkSize) {
7228
+ result.push(array2.slice(i, i + chunkSize));
7204
7229
  }
7205
7230
  return result;
7206
7231
  }
@@ -7722,9 +7747,9 @@ var arrayOutputStrategy = (schema) => {
7722
7747
  transform(chunk, controller) {
7723
7748
  switch (chunk.type) {
7724
7749
  case "object": {
7725
- const array = chunk.object;
7726
- for (; publishedElements < array.length; publishedElements++) {
7727
- controller.enqueue(array[publishedElements]);
7750
+ const array2 = chunk.object;
7751
+ for (; publishedElements < array2.length; publishedElements++) {
7752
+ controller.enqueue(array2[publishedElements]);
7728
7753
  }
7729
7754
  break;
7730
7755
  }
@@ -9035,9 +9060,13 @@ var DefaultSpeechResult = class {
9035
9060
  // src/generate-text/output.ts
9036
9061
  var output_exports = {};
9037
9062
  __export(output_exports, {
9063
+ array: () => array,
9038
9064
  object: () => object,
9039
9065
  text: () => text
9040
9066
  });
9067
+ import {
9068
+ TypeValidationError as TypeValidationError5
9069
+ } from "@ai-sdk/provider";
9041
9070
  import {
9042
9071
  asSchema as asSchema4,
9043
9072
  resolve,
@@ -9047,11 +9076,11 @@ import {
9047
9076
  var text = () => ({
9048
9077
  type: "text",
9049
9078
  responseFormat: Promise.resolve({ type: "text" }),
9050
- async parsePartial({ text: text2 }) {
9051
- return { partial: text2 };
9052
- },
9053
9079
  async parseOutput({ text: text2 }) {
9054
9080
  return text2;
9081
+ },
9082
+ async parsePartial({ text: text2 }) {
9083
+ return { partial: text2 };
9055
9084
  }
9056
9085
  });
9057
9086
  var object = ({
@@ -9064,24 +9093,78 @@ var object = ({
9064
9093
  type: "json",
9065
9094
  schema: jsonSchema3
9066
9095
  })),
9096
+ async parseOutput({ text: text2 }, context) {
9097
+ const parseResult = await safeParseJSON4({ text: text2 });
9098
+ if (!parseResult.success) {
9099
+ throw new NoObjectGeneratedError({
9100
+ message: "No object generated: could not parse the response.",
9101
+ cause: parseResult.error,
9102
+ text: text2,
9103
+ response: context.response,
9104
+ usage: context.usage,
9105
+ finishReason: context.finishReason
9106
+ });
9107
+ }
9108
+ const validationResult = await safeValidateTypes4({
9109
+ value: parseResult.value,
9110
+ schema
9111
+ });
9112
+ if (!validationResult.success) {
9113
+ throw new NoObjectGeneratedError({
9114
+ message: "No object generated: response did not match schema.",
9115
+ cause: validationResult.error,
9116
+ text: text2,
9117
+ response: context.response,
9118
+ usage: context.usage,
9119
+ finishReason: context.finishReason
9120
+ });
9121
+ }
9122
+ return validationResult.value;
9123
+ },
9067
9124
  async parsePartial({ text: text2 }) {
9068
9125
  const result = await parsePartialJson(text2);
9069
9126
  switch (result.state) {
9070
9127
  case "failed-parse":
9071
- case "undefined-input":
9128
+ case "undefined-input": {
9072
9129
  return void 0;
9130
+ }
9073
9131
  case "repaired-parse":
9074
- case "successful-parse":
9132
+ case "successful-parse": {
9075
9133
  return {
9076
9134
  // Note: currently no validation of partial results:
9077
9135
  partial: result.value
9078
9136
  };
9137
+ }
9079
9138
  default: {
9080
9139
  const _exhaustiveCheck = result.state;
9081
9140
  throw new Error(`Unsupported parse state: ${_exhaustiveCheck}`);
9082
9141
  }
9083
9142
  }
9084
- },
9143
+ }
9144
+ };
9145
+ };
9146
+ var array = ({
9147
+ element: inputElementSchema
9148
+ }) => {
9149
+ const elementSchema = asSchema4(inputElementSchema);
9150
+ return {
9151
+ type: "object",
9152
+ // returns a JSON schema that describes an array of elements:
9153
+ responseFormat: resolve(elementSchema.jsonSchema).then((jsonSchema3) => {
9154
+ const { $schema, ...itemSchema } = jsonSchema3;
9155
+ return {
9156
+ type: "json",
9157
+ schema: {
9158
+ $schema: "http://json-schema.org/draft-07/schema#",
9159
+ type: "object",
9160
+ properties: {
9161
+ elements: { type: "array", items: itemSchema }
9162
+ },
9163
+ required: ["elements"],
9164
+ additionalProperties: false
9165
+ }
9166
+ };
9167
+ }),
9085
9168
  async parseOutput({ text: text2 }, context) {
9086
9169
  const parseResult = await safeParseJSON4({ text: text2 });
9087
9170
  if (!parseResult.success) {
@@ -9094,21 +9177,69 @@ var object = ({
9094
9177
  finishReason: context.finishReason
9095
9178
  });
9096
9179
  }
9097
- const validationResult = await safeValidateTypes4({
9098
- value: parseResult.value,
9099
- schema
9100
- });
9101
- if (!validationResult.success) {
9180
+ const outerValue = parseResult.value;
9181
+ if (outerValue == null || typeof outerValue !== "object" || !("elements" in outerValue) || !Array.isArray(outerValue.elements)) {
9102
9182
  throw new NoObjectGeneratedError({
9103
9183
  message: "No object generated: response did not match schema.",
9104
- cause: validationResult.error,
9184
+ cause: new TypeValidationError5({
9185
+ value: outerValue,
9186
+ cause: "response must be an object with an elements array"
9187
+ }),
9105
9188
  text: text2,
9106
9189
  response: context.response,
9107
9190
  usage: context.usage,
9108
9191
  finishReason: context.finishReason
9109
9192
  });
9110
9193
  }
9111
- return validationResult.value;
9194
+ for (const element of outerValue.elements) {
9195
+ const validationResult = await safeValidateTypes4({
9196
+ value: element,
9197
+ schema: elementSchema
9198
+ });
9199
+ if (!validationResult.success) {
9200
+ throw new NoObjectGeneratedError({
9201
+ message: "No object generated: response did not match schema.",
9202
+ cause: validationResult.error,
9203
+ text: text2,
9204
+ response: context.response,
9205
+ usage: context.usage,
9206
+ finishReason: context.finishReason
9207
+ });
9208
+ }
9209
+ }
9210
+ return outerValue.elements;
9211
+ },
9212
+ async parsePartial({ text: text2 }) {
9213
+ const result = await parsePartialJson(text2);
9214
+ switch (result.state) {
9215
+ case "failed-parse":
9216
+ case "undefined-input": {
9217
+ return void 0;
9218
+ }
9219
+ case "repaired-parse":
9220
+ case "successful-parse": {
9221
+ const outerValue = result.value;
9222
+ if (outerValue == null || typeof outerValue !== "object" || !("elements" in outerValue) || !Array.isArray(outerValue.elements)) {
9223
+ return void 0;
9224
+ }
9225
+ const rawElements = result.state === "repaired-parse" && outerValue.elements.length > 0 ? outerValue.elements.slice(0, -1) : outerValue.elements;
9226
+ const parsedElements = [];
9227
+ for (const rawElement of rawElements) {
9228
+ const validationResult = await safeValidateTypes4({
9229
+ value: rawElement,
9230
+ schema: elementSchema
9231
+ });
9232
+ if (validationResult.success) {
9233
+ parsedElements.push(validationResult.value);
9234
+ }
9235
+ }
9236
+ return { partial: parsedElements };
9237
+ }
9238
+ default: {
9239
+ const _exhaustiveCheck = result.state;
9240
+ throw new Error(`Unsupported parse state: ${_exhaustiveCheck}`);
9241
+ }
9242
+ }
9112
9243
  }
9113
9244
  };
9114
9245
  };
@@ -11300,6 +11431,9 @@ export {
11300
11431
  hasToolCall,
11301
11432
  isDataUIPart,
11302
11433
  isDeepEqualData,
11434
+ isFileUIPart,
11435
+ isReasoningUIPart,
11436
+ isTextUIPart,
11303
11437
  isToolOrDynamicToolUIPart,
11304
11438
  isToolUIPart,
11305
11439
  jsonSchema2 as jsonSchema,