ai 6.0.0-beta.82 → 6.0.0-beta.83

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.82" : "0.0.0-test";
778
+ var VERSION = true ? "6.0.0-beta.83" : "0.0.0-test";
779
779
 
780
780
  // src/util/download/download.ts
781
781
  var download = async ({ url }) => {
@@ -2969,7 +2969,7 @@ async function generateText({
2969
2969
  }));
2970
2970
  let resolvedOutput;
2971
2971
  if (lastStep.finishReason === "stop") {
2972
- resolvedOutput = await (output == null ? void 0 : output.parseOutput(
2972
+ resolvedOutput = await (output == null ? void 0 : output.parseCompleteOutput(
2973
2973
  { text: lastStep.text },
2974
2974
  {
2975
2975
  response: lastStep.response,
@@ -5003,7 +5003,7 @@ function createOutputTransformStream(output) {
5003
5003
  }
5004
5004
  text2 += chunk.text;
5005
5005
  textChunk += chunk.text;
5006
- const result = await output.parsePartial({ text: text2 });
5006
+ const result = await output.parsePartialOutput({ text: text2 });
5007
5007
  if (result != null) {
5008
5008
  const currentJson = JSON.stringify(result.partial);
5009
5009
  if (currentJson !== lastPublishedJson) {
@@ -9121,6 +9121,7 @@ var output_exports = {};
9121
9121
  __export(output_exports, {
9122
9122
  array: () => array,
9123
9123
  choice: () => choice,
9124
+ json: () => json,
9124
9125
  object: () => object,
9125
9126
  text: () => text
9126
9127
  });
@@ -9134,12 +9135,11 @@ import {
9134
9135
  safeValidateTypes as safeValidateTypes4
9135
9136
  } from "@ai-sdk/provider-utils";
9136
9137
  var text = () => ({
9137
- type: "text",
9138
9138
  responseFormat: Promise.resolve({ type: "text" }),
9139
- async parseOutput({ text: text2 }) {
9139
+ async parseCompleteOutput({ text: text2 }) {
9140
9140
  return text2;
9141
9141
  },
9142
- async parsePartial({ text: text2 }) {
9142
+ async parsePartialOutput({ text: text2 }) {
9143
9143
  return { partial: text2 };
9144
9144
  }
9145
9145
  });
@@ -9148,12 +9148,11 @@ var object = ({
9148
9148
  }) => {
9149
9149
  const schema = asSchema4(inputSchema);
9150
9150
  return {
9151
- type: "object",
9152
9151
  responseFormat: resolve(schema.jsonSchema).then((jsonSchema2) => ({
9153
9152
  type: "json",
9154
9153
  schema: jsonSchema2
9155
9154
  })),
9156
- async parseOutput({ text: text2 }, context) {
9155
+ async parseCompleteOutput({ text: text2 }, context) {
9157
9156
  const parseResult = await safeParseJSON4({ text: text2 });
9158
9157
  if (!parseResult.success) {
9159
9158
  throw new NoObjectGeneratedError({
@@ -9181,7 +9180,7 @@ var object = ({
9181
9180
  }
9182
9181
  return validationResult.value;
9183
9182
  },
9184
- async parsePartial({ text: text2 }) {
9183
+ async parsePartialOutput({ text: text2 }) {
9185
9184
  const result = await parsePartialJson(text2);
9186
9185
  switch (result.state) {
9187
9186
  case "failed-parse":
@@ -9195,10 +9194,6 @@ var object = ({
9195
9194
  partial: result.value
9196
9195
  };
9197
9196
  }
9198
- default: {
9199
- const _exhaustiveCheck = result.state;
9200
- throw new Error(`Unsupported parse state: ${_exhaustiveCheck}`);
9201
- }
9202
9197
  }
9203
9198
  }
9204
9199
  };
@@ -9208,7 +9203,6 @@ var array = ({
9208
9203
  }) => {
9209
9204
  const elementSchema = asSchema4(inputElementSchema);
9210
9205
  return {
9211
- type: "object",
9212
9206
  // JSON schema that describes an array of elements:
9213
9207
  responseFormat: resolve(elementSchema.jsonSchema).then((jsonSchema2) => {
9214
9208
  const { $schema, ...itemSchema } = jsonSchema2;
@@ -9225,7 +9219,7 @@ var array = ({
9225
9219
  }
9226
9220
  };
9227
9221
  }),
9228
- async parseOutput({ text: text2 }, context) {
9222
+ async parseCompleteOutput({ text: text2 }, context) {
9229
9223
  const parseResult = await safeParseJSON4({ text: text2 });
9230
9224
  if (!parseResult.success) {
9231
9225
  throw new NoObjectGeneratedError({
@@ -9269,7 +9263,7 @@ var array = ({
9269
9263
  }
9270
9264
  return outerValue.elements;
9271
9265
  },
9272
- async parsePartial({ text: text2 }) {
9266
+ async parsePartialOutput({ text: text2 }) {
9273
9267
  const result = await parsePartialJson(text2);
9274
9268
  switch (result.state) {
9275
9269
  case "failed-parse":
@@ -9295,10 +9289,6 @@ var array = ({
9295
9289
  }
9296
9290
  return { partial: parsedElements };
9297
9291
  }
9298
- default: {
9299
- const _exhaustiveCheck = result.state;
9300
- throw new Error(`Unsupported parse state: ${_exhaustiveCheck}`);
9301
- }
9302
9292
  }
9303
9293
  }
9304
9294
  };
@@ -9307,7 +9297,6 @@ var choice = ({
9307
9297
  options: choiceOptions
9308
9298
  }) => {
9309
9299
  return {
9310
- type: "object",
9311
9300
  // JSON schema that describes an enumeration:
9312
9301
  responseFormat: Promise.resolve({
9313
9302
  type: "json",
@@ -9321,7 +9310,7 @@ var choice = ({
9321
9310
  additionalProperties: false
9322
9311
  }
9323
9312
  }),
9324
- async parseOutput({ text: text2 }, context) {
9313
+ async parseCompleteOutput({ text: text2 }, context) {
9325
9314
  const parseResult = await safeParseJSON4({ text: text2 });
9326
9315
  if (!parseResult.success) {
9327
9316
  throw new NoObjectGeneratedError({
@@ -9349,7 +9338,7 @@ var choice = ({
9349
9338
  }
9350
9339
  return outerValue.result;
9351
9340
  },
9352
- async parsePartial({ text: text2 }) {
9341
+ async parsePartialOutput({ text: text2 }) {
9353
9342
  const result = await parsePartialJson(text2);
9354
9343
  switch (result.state) {
9355
9344
  case "failed-parse":
@@ -9371,9 +9360,39 @@ var choice = ({
9371
9360
  return potentialMatches.length === 1 ? { partial: potentialMatches[0] } : void 0;
9372
9361
  }
9373
9362
  }
9374
- default: {
9375
- const _exhaustiveCheck = result.state;
9376
- throw new Error(`Unsupported parse state: ${_exhaustiveCheck}`);
9363
+ }
9364
+ }
9365
+ };
9366
+ };
9367
+ var json = () => {
9368
+ return {
9369
+ responseFormat: Promise.resolve({
9370
+ type: "json"
9371
+ }),
9372
+ async parseCompleteOutput({ text: text2 }, context) {
9373
+ const parseResult = await safeParseJSON4({ text: text2 });
9374
+ if (!parseResult.success) {
9375
+ throw new NoObjectGeneratedError({
9376
+ message: "No object generated: could not parse the response.",
9377
+ cause: parseResult.error,
9378
+ text: text2,
9379
+ response: context.response,
9380
+ usage: context.usage,
9381
+ finishReason: context.finishReason
9382
+ });
9383
+ }
9384
+ return parseResult.value;
9385
+ },
9386
+ async parsePartialOutput({ text: text2 }) {
9387
+ const result = await parsePartialJson(text2);
9388
+ switch (result.state) {
9389
+ case "failed-parse":
9390
+ case "undefined-input": {
9391
+ return void 0;
9392
+ }
9393
+ case "repaired-parse":
9394
+ case "successful-parse": {
9395
+ return result.value === void 0 ? void 0 : { partial: result.value };
9377
9396
  }
9378
9397
  }
9379
9398
  }