ai 6.0.0-beta.69 → 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.69" : "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 }) => {
@@ -9061,6 +9061,7 @@ var DefaultSpeechResult = class {
9061
9061
  var output_exports = {};
9062
9062
  __export(output_exports, {
9063
9063
  array: () => array,
9064
+ choice: () => choice,
9064
9065
  object: () => object,
9065
9066
  text: () => text
9066
9067
  });
@@ -9149,7 +9150,7 @@ var array = ({
9149
9150
  const elementSchema = asSchema4(inputElementSchema);
9150
9151
  return {
9151
9152
  type: "object",
9152
- // returns a JSON schema that describes an array of elements:
9153
+ // JSON schema that describes an array of elements:
9153
9154
  responseFormat: resolve(elementSchema.jsonSchema).then((jsonSchema3) => {
9154
9155
  const { $schema, ...itemSchema } = jsonSchema3;
9155
9156
  return {
@@ -9243,6 +9244,82 @@ var array = ({
9243
9244
  }
9244
9245
  };
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
+ }),
9265
+ async parseOutput({ text: text2 }, context) {
9266
+ const parseResult = await safeParseJSON4({ text: text2 });
9267
+ if (!parseResult.success) {
9268
+ throw new NoObjectGeneratedError({
9269
+ message: "No object generated: could not parse the response.",
9270
+ cause: parseResult.error,
9271
+ text: text2,
9272
+ response: context.response,
9273
+ usage: context.usage,
9274
+ finishReason: context.finishReason
9275
+ });
9276
+ }
9277
+ const outerValue = parseResult.value;
9278
+ if (outerValue == null || typeof outerValue !== "object" || !("result" in outerValue) || typeof outerValue.result !== "string" || !choiceOptions.includes(outerValue.result)) {
9279
+ throw new NoObjectGeneratedError({
9280
+ message: "No object generated: response did not match schema.",
9281
+ cause: new TypeValidationError5({
9282
+ value: outerValue,
9283
+ cause: "response must be an object that contains a choice value."
9284
+ }),
9285
+ text: text2,
9286
+ response: context.response,
9287
+ usage: context.usage,
9288
+ finishReason: context.finishReason
9289
+ });
9290
+ }
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
+ }
9320
+ }
9321
+ };
9322
+ };
9246
9323
 
9247
9324
  // src/generate-text/prune-messages.ts
9248
9325
  function pruneMessages({