ai 6.0.0-beta.68 → 6.0.0-beta.70

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.68" : "0.0.0-test";
778
+ var VERSION = true ? "6.0.0-beta.70" : "0.0.0-test";
779
779
 
780
780
  // src/util/download/download.ts
781
781
  var download = async ({ url }) => {
@@ -7219,13 +7219,13 @@ var DefaultEmbedResult = class {
7219
7219
  import { withUserAgentSuffix as withUserAgentSuffix4 } from "@ai-sdk/provider-utils";
7220
7220
 
7221
7221
  // src/util/split-array.ts
7222
- function splitArray(array, chunkSize) {
7222
+ function splitArray(array2, chunkSize) {
7223
7223
  if (chunkSize <= 0) {
7224
7224
  throw new Error("chunkSize must be greater than 0");
7225
7225
  }
7226
7226
  const result = [];
7227
- for (let i = 0; i < array.length; i += chunkSize) {
7228
- 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));
7229
7229
  }
7230
7230
  return result;
7231
7231
  }
@@ -7747,9 +7747,9 @@ var arrayOutputStrategy = (schema) => {
7747
7747
  transform(chunk, controller) {
7748
7748
  switch (chunk.type) {
7749
7749
  case "object": {
7750
- const array = chunk.object;
7751
- for (; publishedElements < array.length; publishedElements++) {
7752
- controller.enqueue(array[publishedElements]);
7750
+ const array2 = chunk.object;
7751
+ for (; publishedElements < array2.length; publishedElements++) {
7752
+ controller.enqueue(array2[publishedElements]);
7753
7753
  }
7754
7754
  break;
7755
7755
  }
@@ -9060,9 +9060,14 @@ var DefaultSpeechResult = class {
9060
9060
  // src/generate-text/output.ts
9061
9061
  var output_exports = {};
9062
9062
  __export(output_exports, {
9063
+ array: () => array,
9064
+ choice: () => choice,
9063
9065
  object: () => object,
9064
9066
  text: () => text
9065
9067
  });
9068
+ import {
9069
+ TypeValidationError as TypeValidationError5
9070
+ } from "@ai-sdk/provider";
9066
9071
  import {
9067
9072
  asSchema as asSchema4,
9068
9073
  resolve,
@@ -9072,11 +9077,11 @@ import {
9072
9077
  var text = () => ({
9073
9078
  type: "text",
9074
9079
  responseFormat: Promise.resolve({ type: "text" }),
9075
- async parsePartial({ text: text2 }) {
9076
- return { partial: text2 };
9077
- },
9078
9080
  async parseOutput({ text: text2 }) {
9079
9081
  return text2;
9082
+ },
9083
+ async parsePartial({ text: text2 }) {
9084
+ return { partial: text2 };
9080
9085
  }
9081
9086
  });
9082
9087
  var object = ({
@@ -9089,24 +9094,174 @@ var object = ({
9089
9094
  type: "json",
9090
9095
  schema: jsonSchema3
9091
9096
  })),
9097
+ async parseOutput({ text: text2 }, context) {
9098
+ const parseResult = await safeParseJSON4({ text: text2 });
9099
+ if (!parseResult.success) {
9100
+ throw new NoObjectGeneratedError({
9101
+ message: "No object generated: could not parse the response.",
9102
+ cause: parseResult.error,
9103
+ text: text2,
9104
+ response: context.response,
9105
+ usage: context.usage,
9106
+ finishReason: context.finishReason
9107
+ });
9108
+ }
9109
+ const validationResult = await safeValidateTypes4({
9110
+ value: parseResult.value,
9111
+ schema
9112
+ });
9113
+ if (!validationResult.success) {
9114
+ throw new NoObjectGeneratedError({
9115
+ message: "No object generated: response did not match schema.",
9116
+ cause: validationResult.error,
9117
+ text: text2,
9118
+ response: context.response,
9119
+ usage: context.usage,
9120
+ finishReason: context.finishReason
9121
+ });
9122
+ }
9123
+ return validationResult.value;
9124
+ },
9092
9125
  async parsePartial({ text: text2 }) {
9093
9126
  const result = await parsePartialJson(text2);
9094
9127
  switch (result.state) {
9095
9128
  case "failed-parse":
9096
- case "undefined-input":
9129
+ case "undefined-input": {
9097
9130
  return void 0;
9131
+ }
9098
9132
  case "repaired-parse":
9099
- case "successful-parse":
9133
+ case "successful-parse": {
9100
9134
  return {
9101
9135
  // Note: currently no validation of partial results:
9102
9136
  partial: result.value
9103
9137
  };
9138
+ }
9104
9139
  default: {
9105
9140
  const _exhaustiveCheck = result.state;
9106
9141
  throw new Error(`Unsupported parse state: ${_exhaustiveCheck}`);
9107
9142
  }
9108
9143
  }
9144
+ }
9145
+ };
9146
+ };
9147
+ var array = ({
9148
+ element: inputElementSchema
9149
+ }) => {
9150
+ const elementSchema = asSchema4(inputElementSchema);
9151
+ return {
9152
+ type: "object",
9153
+ // JSON schema that describes an array of elements:
9154
+ responseFormat: resolve(elementSchema.jsonSchema).then((jsonSchema3) => {
9155
+ const { $schema, ...itemSchema } = jsonSchema3;
9156
+ return {
9157
+ type: "json",
9158
+ schema: {
9159
+ $schema: "http://json-schema.org/draft-07/schema#",
9160
+ type: "object",
9161
+ properties: {
9162
+ elements: { type: "array", items: itemSchema }
9163
+ },
9164
+ required: ["elements"],
9165
+ additionalProperties: false
9166
+ }
9167
+ };
9168
+ }),
9169
+ async parseOutput({ text: text2 }, context) {
9170
+ const parseResult = await safeParseJSON4({ text: text2 });
9171
+ if (!parseResult.success) {
9172
+ throw new NoObjectGeneratedError({
9173
+ message: "No object generated: could not parse the response.",
9174
+ cause: parseResult.error,
9175
+ text: text2,
9176
+ response: context.response,
9177
+ usage: context.usage,
9178
+ finishReason: context.finishReason
9179
+ });
9180
+ }
9181
+ const outerValue = parseResult.value;
9182
+ if (outerValue == null || typeof outerValue !== "object" || !("elements" in outerValue) || !Array.isArray(outerValue.elements)) {
9183
+ throw new NoObjectGeneratedError({
9184
+ message: "No object generated: response did not match schema.",
9185
+ cause: new TypeValidationError5({
9186
+ value: outerValue,
9187
+ cause: "response must be an object with an elements array"
9188
+ }),
9189
+ text: text2,
9190
+ response: context.response,
9191
+ usage: context.usage,
9192
+ finishReason: context.finishReason
9193
+ });
9194
+ }
9195
+ for (const element of outerValue.elements) {
9196
+ const validationResult = await safeValidateTypes4({
9197
+ value: element,
9198
+ schema: elementSchema
9199
+ });
9200
+ if (!validationResult.success) {
9201
+ throw new NoObjectGeneratedError({
9202
+ message: "No object generated: response did not match schema.",
9203
+ cause: validationResult.error,
9204
+ text: text2,
9205
+ response: context.response,
9206
+ usage: context.usage,
9207
+ finishReason: context.finishReason
9208
+ });
9209
+ }
9210
+ }
9211
+ return outerValue.elements;
9109
9212
  },
9213
+ async parsePartial({ text: text2 }) {
9214
+ const result = await parsePartialJson(text2);
9215
+ switch (result.state) {
9216
+ case "failed-parse":
9217
+ case "undefined-input": {
9218
+ return void 0;
9219
+ }
9220
+ case "repaired-parse":
9221
+ case "successful-parse": {
9222
+ const outerValue = result.value;
9223
+ if (outerValue == null || typeof outerValue !== "object" || !("elements" in outerValue) || !Array.isArray(outerValue.elements)) {
9224
+ return void 0;
9225
+ }
9226
+ const rawElements = result.state === "repaired-parse" && outerValue.elements.length > 0 ? outerValue.elements.slice(0, -1) : outerValue.elements;
9227
+ const parsedElements = [];
9228
+ for (const rawElement of rawElements) {
9229
+ const validationResult = await safeValidateTypes4({
9230
+ value: rawElement,
9231
+ schema: elementSchema
9232
+ });
9233
+ if (validationResult.success) {
9234
+ parsedElements.push(validationResult.value);
9235
+ }
9236
+ }
9237
+ return { partial: parsedElements };
9238
+ }
9239
+ default: {
9240
+ const _exhaustiveCheck = result.state;
9241
+ throw new Error(`Unsupported parse state: ${_exhaustiveCheck}`);
9242
+ }
9243
+ }
9244
+ }
9245
+ };
9246
+ };
9247
+ var choice = ({
9248
+ options: choiceOptions
9249
+ }) => {
9250
+ return {
9251
+ type: "object",
9252
+ // JSON schema that describes an enumeration:
9253
+ responseFormat: Promise.resolve({
9254
+ type: "json",
9255
+ schema: {
9256
+ $schema: "http://json-schema.org/draft-07/schema#",
9257
+ type: "object",
9258
+ properties: {
9259
+ result: { type: "string", enum: choiceOptions }
9260
+ },
9261
+ required: ["result"],
9262
+ additionalProperties: false
9263
+ }
9264
+ }),
9110
9265
  async parseOutput({ text: text2 }, context) {
9111
9266
  const parseResult = await safeParseJSON4({ text: text2 });
9112
9267
  if (!parseResult.success) {
@@ -9119,21 +9274,49 @@ var object = ({
9119
9274
  finishReason: context.finishReason
9120
9275
  });
9121
9276
  }
9122
- const validationResult = await safeValidateTypes4({
9123
- value: parseResult.value,
9124
- schema
9125
- });
9126
- if (!validationResult.success) {
9277
+ const outerValue = parseResult.value;
9278
+ if (outerValue == null || typeof outerValue !== "object" || !("result" in outerValue) || typeof outerValue.result !== "string" || !choiceOptions.includes(outerValue.result)) {
9127
9279
  throw new NoObjectGeneratedError({
9128
9280
  message: "No object generated: response did not match schema.",
9129
- cause: validationResult.error,
9281
+ cause: new TypeValidationError5({
9282
+ value: outerValue,
9283
+ cause: "response must be an object that contains a choice value."
9284
+ }),
9130
9285
  text: text2,
9131
9286
  response: context.response,
9132
9287
  usage: context.usage,
9133
9288
  finishReason: context.finishReason
9134
9289
  });
9135
9290
  }
9136
- return validationResult.value;
9291
+ return outerValue.result;
9292
+ },
9293
+ async parsePartial({ text: text2 }) {
9294
+ const result = await parsePartialJson(text2);
9295
+ switch (result.state) {
9296
+ case "failed-parse":
9297
+ case "undefined-input": {
9298
+ return void 0;
9299
+ }
9300
+ case "repaired-parse":
9301
+ case "successful-parse": {
9302
+ const outerValue = result.value;
9303
+ if (outerValue == null || typeof outerValue !== "object" || !("result" in outerValue) || typeof outerValue.result !== "string") {
9304
+ return void 0;
9305
+ }
9306
+ const potentialMatches = choiceOptions.filter(
9307
+ (choiceOption) => choiceOption.startsWith(outerValue.result)
9308
+ );
9309
+ if (result.state === "successful-parse") {
9310
+ return potentialMatches.includes(outerValue.result) ? { partial: outerValue.result } : void 0;
9311
+ } else {
9312
+ return potentialMatches.length === 1 ? { partial: potentialMatches[0] } : void 0;
9313
+ }
9314
+ }
9315
+ default: {
9316
+ const _exhaustiveCheck = result.state;
9317
+ throw new Error(`Unsupported parse state: ${_exhaustiveCheck}`);
9318
+ }
9319
+ }
9137
9320
  }
9138
9321
  };
9139
9322
  };