ai 7.0.168 → 7.0.170

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.js CHANGED
@@ -2,7 +2,8 @@ import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.js";
2
2
  import { GatewayAuthenticationError, GatewayError, createGateway, gateway, gateway as gateway$1 } from "@ai-sdk/gateway";
3
3
  import { DEFAULT_MAX_DOWNLOAD_SIZE, DelayedPromise, DownloadError, DownloadError as DownloadError$1, EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL, EXPERIMENTAL_EMBEDDING_MODEL_PROVIDER_OPTIONS_TRANSFORMER, asArray, asSchema, asSchema as asSchema$1, cancelResponseBody, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertUint8ArrayToBase64, createIdGenerator, createIdGenerator as createIdGenerator$1, delay, detectMediaType, dynamicTool, executeTool, experimental_getToolCaller, experimental_toolCaller, fetchUntrustedUrl, filterNullable, generateId, generateId as generateId$1, getErrorMessage, getRuntimeEnvironmentUserAgent, getTopLevelMediaType, getWebSocketConstructor, isAbortError, isArrayBuffer, isBuffer, isExecutableTool, isFullMediaType, isNonNullable, isProviderReference, isProviderStreamError, isUint8Array, isUrlSupported, jsonSchema, jsonSchema as jsonSchema$1, lazySchema, normalizeHeaders, parseJsonEventStream, parseJsonEventStream as parseJsonEventStream$1, readResponseWithSizeLimit, readWebSocketMessageText, redactTelemetryValue, resolve, retryWithExponentialBackoff, safeParseJSON, safeValidateTypes, toWebSocketUrl, tool, tool as tool$1, validateTypes, waitForWebSocketBufferDrain, withUserAgentSuffix, zodSchema, zodSchema as zodSchema$1 } from "@ai-sdk/provider-utils";
4
4
  import { AISDKError, AISDKError as AISDKError$1, APICallError, APICallError as APICallError$1, EmptyResponseBodyError, EmptyResponseBodyError as EmptyResponseBodyError$1, Experimental_DecisionRefusalError, Experimental_DecisionRefusalError as Experimental_DecisionRefusalError$1, Experimental_DecisionUnsupportedQuestionTypeError, Experimental_DecisionUnsupportedQuestionTypeError as Experimental_DecisionUnsupportedQuestionTypeError$1, InvalidPromptError, InvalidPromptError as InvalidPromptError$1, InvalidResponseDataError, InvalidResponseDataError as InvalidResponseDataError$1, JSONParseError, JSONParseError as JSONParseError$1, LoadAPIKeyError, LoadSettingError, NoContentGeneratedError, NoSuchModelError, NoSuchModelError as NoSuchModelError$1, NoSuchProviderReferenceError, TooManyEmbeddingValuesForCallError, TypeValidationError, TypeValidationError as TypeValidationError$1, UnsupportedFunctionalityError, UnsupportedFunctionalityError as UnsupportedFunctionalityError$1, getErrorMessage as getErrorMessage$1, isJSONArray, isJSONObject } from "@ai-sdk/provider";
5
- import { array, boolean, custom, discriminatedUnion, enum as enum$1, instanceof as instanceof$1, lazy, literal, looseObject, never, null as null$1, number, object, record, string, union, unknown } from "zod/v4";
5
+ import { array, boolean, custom, discriminatedUnion, enum as enum$1, extend, int, literal, looseObject, maximum, minLength, never, nonnegative, number, object, optional, pipe, positive, record, refine, startsWith, string, transform, union, unknown } from "zod/v4/mini";
6
+ import { array as array$1, boolean as boolean$1, custom as custom$1, discriminatedUnion as discriminatedUnion$1, instanceof as instanceof$1, lazy, literal as literal$1, null as null$1, number as number$1, object as object$1, record as record$1, string as string$1, union as union$1, unknown as unknown$1 } from "zod/v4";
6
7
  //#region src/telemetry/get-request-origin.ts
7
8
  /** Remove credentials, paths, queries, and fragments before emitting telemetry. */
8
9
  function getRequestOrigin(url) {
@@ -1241,7 +1242,7 @@ function cloneValue(value, seen) {
1241
1242
  }
1242
1243
  //#endregion
1243
1244
  //#region src/version.ts
1244
- const VERSION = "7.0.168";
1245
+ const VERSION = "7.0.170";
1245
1246
  //#endregion
1246
1247
  //#region src/util/download/download.ts
1247
1248
  /**
@@ -3194,6 +3195,96 @@ function isToolExecutionAllowedFinishReason(finishReason) {
3194
3195
  return finishReason === "stop" || finishReason === "tool-calls";
3195
3196
  }
3196
3197
  //#endregion
3198
+ //#region src/util/array-output-stream.ts
3199
+ const arrayStreamParserFactories = /* @__PURE__ */ new WeakMap();
3200
+ function createArrayStreamParser(output) {
3201
+ return arrayStreamParserFactories.get(output)?.();
3202
+ }
3203
+ /**
3204
+ * Scan only new text and parse/validate each delimited element once. Keep the
3205
+ * last element pending until another starts or the enclosing object closes,
3206
+ * matching the partial JSON parser's treatment of an incomplete response.
3207
+ * Nonstandard envelopes and malformed JSON use the existing partial parser.
3208
+ */
3209
+ function createArrayOutputStreamParser(schema, skipInvalidElements) {
3210
+ let phase = 0;
3211
+ let prefix = "";
3212
+ let elementText = "";
3213
+ let depth = 0;
3214
+ let inString = false;
3215
+ let escaped = false;
3216
+ let afterComma = false;
3217
+ let pending = [];
3218
+ const elements = [];
3219
+ let publishedCount;
3220
+ async function finishElement() {
3221
+ const parsed = await safeParseJSON({ text: elementText });
3222
+ if (!parsed.success) return false;
3223
+ const validated = await safeValidateTypes({
3224
+ value: parsed.value,
3225
+ schema
3226
+ });
3227
+ if (validated.success) pending = [validated.value];
3228
+ else if (!skipInvalidElements) return false;
3229
+ elementText = "";
3230
+ return true;
3231
+ }
3232
+ function publishPending() {
3233
+ elements.push(...pending);
3234
+ pending = [];
3235
+ }
3236
+ return async (textDelta) => {
3237
+ for (const char of textDelta) {
3238
+ if (phase === 0) {
3239
+ prefix += char;
3240
+ if (char === "[") {
3241
+ if (!/^\s*\{\s*"elements"\s*:\s*\[$/.test(prefix)) return "fallback";
3242
+ phase = 1;
3243
+ } else if (prefix.length > 256) return "fallback";
3244
+ continue;
3245
+ }
3246
+ if (phase === 2 || phase === 3) {
3247
+ if (/\s/.test(char)) continue;
3248
+ if (phase === 2 && char === "}") {
3249
+ publishPending();
3250
+ phase = 3;
3251
+ continue;
3252
+ }
3253
+ return "fallback";
3254
+ }
3255
+ if (!inString && depth === 0 && (char === "," || char === "]")) {
3256
+ if (elementText.length > 0) {
3257
+ if (!await finishElement()) return "fallback";
3258
+ } else if (char === "," || afterComma) return "fallback";
3259
+ afterComma = char === ",";
3260
+ if (char === "]") phase = 2;
3261
+ continue;
3262
+ }
3263
+ if (elementText.length === 0) {
3264
+ if (/\s/.test(char)) continue;
3265
+ publishPending();
3266
+ afterComma = false;
3267
+ }
3268
+ elementText += char;
3269
+ if (inString) {
3270
+ if (escaped) escaped = false;
3271
+ else if (char === "\\") escaped = true;
3272
+ else if (char === "\"") inString = false;
3273
+ } else if (char === "\"") inString = true;
3274
+ else if (char === "{" || char === "[") depth++;
3275
+ else if (char === "}" || char === "]") depth--;
3276
+ }
3277
+ if (phase === 0 || publishedCount === elements.length) return;
3278
+ const previousCount = publishedCount ?? 0;
3279
+ const delta = (publishedCount == null ? "[" : "") + (previousCount > 0 && elements.length > previousCount ? "," : "") + elements.slice(previousCount).map((value) => JSON.stringify(value)).join(",") + (phase === 3 ? "]" : "");
3280
+ publishedCount = elements.length;
3281
+ return {
3282
+ partial: elements.slice(),
3283
+ textDelta: delta
3284
+ };
3285
+ };
3286
+ }
3287
+ //#endregion
3197
3288
  //#region src/util/fix-json.ts
3198
3289
  function fixJson(input) {
3199
3290
  const stack = ["ROOT"];
@@ -3469,10 +3560,10 @@ async function parsePartialJson(jsonText) {
3469
3560
  //#endregion
3470
3561
  //#region src/generate-text/output.ts
3471
3562
  var output_exports = /* @__PURE__ */ __exportAll({
3472
- array: () => array$1,
3563
+ array: () => array$2,
3473
3564
  choice: () => choice,
3474
3565
  json: () => json,
3475
- object: () => object$1,
3566
+ object: () => object$2,
3476
3567
  text: () => text
3477
3568
  });
3478
3569
  /**
@@ -3492,7 +3583,7 @@ const text = () => ({
3492
3583
  },
3493
3584
  createElementStreamTransform() {}
3494
3585
  });
3495
- function object$1({ schema: inputSchema, name, description }) {
3586
+ function object$2({ schema: inputSchema, name, description }) {
3496
3587
  const schema = asSchema$1(inputSchema);
3497
3588
  return {
3498
3589
  name: "object",
@@ -3505,24 +3596,20 @@ function object$1({ schema: inputSchema, name, description }) {
3505
3596
  async parseCompleteOutput({ text }, context) {
3506
3597
  const parseResult = await safeParseJSON({ text });
3507
3598
  if (!parseResult.success) throw new NoObjectGeneratedError({
3599
+ ...context,
3508
3600
  message: "No object generated: could not parse the response.",
3509
3601
  cause: parseResult.error,
3510
- text,
3511
- response: context.response,
3512
- usage: context.usage,
3513
- finishReason: context.finishReason
3602
+ text
3514
3603
  });
3515
3604
  const validationResult = await safeValidateTypes({
3516
3605
  value: parseResult.value,
3517
3606
  schema
3518
3607
  });
3519
3608
  if (!validationResult.success) throw new NoObjectGeneratedError({
3609
+ ...context,
3520
3610
  message: "No object generated: response did not match schema.",
3521
3611
  cause: validationResult.error,
3522
- text,
3523
- response: context.response,
3524
- usage: context.usage,
3525
- finishReason: context.finishReason
3612
+ text
3526
3613
  });
3527
3614
  return validationResult.value;
3528
3615
  },
@@ -3538,7 +3625,7 @@ function object$1({ schema: inputSchema, name, description }) {
3538
3625
  createElementStreamTransform() {}
3539
3626
  };
3540
3627
  }
3541
- function array$1({ element: inputElementSchema, minItems, maxItems, name, description }) {
3628
+ function array$2({ element: inputElementSchema, minItems, maxItems, name, description }) {
3542
3629
  validateArrayBound({
3543
3630
  name: "minItems",
3544
3631
  value: minItems
@@ -3553,7 +3640,7 @@ function array$1({ element: inputElementSchema, minItems, maxItems, name, descri
3553
3640
  message: "minItems must be less than or equal to maxItems"
3554
3641
  });
3555
3642
  const elementSchema = asSchema$1(inputElementSchema);
3556
- return {
3643
+ const output = {
3557
3644
  name: "array",
3558
3645
  responseFormat: resolve(elementSchema.jsonSchema).then((jsonSchema) => {
3559
3646
  const { $schema: _$schema, definitions, $defs, ...itemSchema } = jsonSchema;
@@ -3580,24 +3667,20 @@ function array$1({ element: inputElementSchema, minItems, maxItems, name, descri
3580
3667
  async parseCompleteOutput({ text }, context) {
3581
3668
  const parseResult = await safeParseJSON({ text });
3582
3669
  if (!parseResult.success) throw new NoObjectGeneratedError({
3670
+ ...context,
3583
3671
  message: "No object generated: could not parse the response.",
3584
3672
  cause: parseResult.error,
3585
- text,
3586
- response: context.response,
3587
- usage: context.usage,
3588
- finishReason: context.finishReason
3673
+ text
3589
3674
  });
3590
3675
  const outerValue = parseResult.value;
3591
3676
  if (outerValue == null || typeof outerValue !== "object" || !("elements" in outerValue) || !Array.isArray(outerValue.elements)) throw new NoObjectGeneratedError({
3677
+ ...context,
3592
3678
  message: "No object generated: response did not match schema.",
3593
3679
  cause: new TypeValidationError$1({
3594
3680
  value: outerValue,
3595
3681
  cause: "response must be an object with an elements array"
3596
3682
  }),
3597
- text,
3598
- response: context.response,
3599
- usage: context.usage,
3600
- finishReason: context.finishReason
3683
+ text
3601
3684
  });
3602
3685
  const lengthValidationError = getArrayLengthValidationError({
3603
3686
  value: outerValue.elements,
@@ -3605,12 +3688,10 @@ function array$1({ element: inputElementSchema, minItems, maxItems, name, descri
3605
3688
  maxItems
3606
3689
  });
3607
3690
  if (lengthValidationError != null) throw new NoObjectGeneratedError({
3691
+ ...context,
3608
3692
  message: "No object generated: response did not match schema.",
3609
3693
  cause: lengthValidationError,
3610
- text,
3611
- response: context.response,
3612
- usage: context.usage,
3613
- finishReason: context.finishReason
3694
+ text
3614
3695
  });
3615
3696
  const validatedElements = [];
3616
3697
  for (const element of outerValue.elements) {
@@ -3619,12 +3700,10 @@ function array$1({ element: inputElementSchema, minItems, maxItems, name, descri
3619
3700
  schema: elementSchema
3620
3701
  });
3621
3702
  if (!validationResult.success) throw new NoObjectGeneratedError({
3703
+ ...context,
3622
3704
  message: "No object generated: response did not match schema.",
3623
3705
  cause: validationResult.error,
3624
- text,
3625
- response: context.response,
3626
- usage: context.usage,
3627
- finishReason: context.finishReason
3706
+ text
3628
3707
  });
3629
3708
  validatedElements.push(validationResult.value);
3630
3709
  }
@@ -3668,6 +3747,9 @@ function array$1({ element: inputElementSchema, minItems, maxItems, name, descri
3668
3747
  } });
3669
3748
  }
3670
3749
  };
3750
+ const parsePartialOutput = output.parsePartialOutput;
3751
+ arrayStreamParserFactories.set(output, () => output.parsePartialOutput === parsePartialOutput ? createArrayOutputStreamParser(elementSchema, true) : void 0);
3752
+ return output;
3671
3753
  }
3672
3754
  function validateArrayBound({ name, value }) {
3673
3755
  if (value == null) return;
@@ -3723,24 +3805,20 @@ const choice = ({ options: choiceOptions, name, description }) => {
3723
3805
  async parseCompleteOutput({ text }, context) {
3724
3806
  const parseResult = await safeParseJSON({ text });
3725
3807
  if (!parseResult.success) throw new NoObjectGeneratedError({
3808
+ ...context,
3726
3809
  message: "No object generated: could not parse the response.",
3727
3810
  cause: parseResult.error,
3728
- text,
3729
- response: context.response,
3730
- usage: context.usage,
3731
- finishReason: context.finishReason
3811
+ text
3732
3812
  });
3733
3813
  const outerValue = parseResult.value;
3734
3814
  if (outerValue == null || typeof outerValue !== "object" || !("result" in outerValue) || typeof outerValue.result !== "string" || !choiceOptions.includes(outerValue.result)) throw new NoObjectGeneratedError({
3815
+ ...context,
3735
3816
  message: "No object generated: response did not match schema.",
3736
3817
  cause: new TypeValidationError$1({
3737
3818
  value: outerValue,
3738
3819
  cause: "response must be an object that contains a choice value."
3739
3820
  }),
3740
- text,
3741
- response: context.response,
3742
- usage: context.usage,
3743
- finishReason: context.finishReason
3821
+ text
3744
3822
  });
3745
3823
  return outerValue.result;
3746
3824
  },
@@ -3782,12 +3860,10 @@ const json = ({ name, description } = {}) => {
3782
3860
  async parseCompleteOutput({ text }, context) {
3783
3861
  const parseResult = await safeParseJSON({ text });
3784
3862
  if (!parseResult.success) throw new NoObjectGeneratedError({
3863
+ ...context,
3785
3864
  message: "No object generated: could not parse the response.",
3786
3865
  cause: parseResult.error,
3787
- text,
3788
- response: context.response,
3789
- usage: context.usage,
3790
- finishReason: context.finishReason
3866
+ text
3791
3867
  });
3792
3868
  return parseResult.value;
3793
3869
  },
@@ -6501,26 +6577,52 @@ function getResponseUIMessageId({ originalMessages, responseMessageId }) {
6501
6577
  }
6502
6578
  //#endregion
6503
6579
  //#region src/util/zod.ts
6504
- const z = {
6580
+ const z$1 = {
6505
6581
  array,
6506
6582
  boolean,
6507
6583
  custom,
6508
6584
  discriminatedUnion,
6509
6585
  enum: enum$1,
6510
- instanceof: instanceof$1,
6511
- lazy,
6586
+ extend,
6587
+ int,
6512
6588
  literal,
6513
6589
  looseObject,
6590
+ maximum,
6591
+ minLength,
6514
6592
  never,
6515
- null: null$1,
6593
+ nonnegative,
6516
6594
  number,
6517
6595
  object,
6596
+ optional,
6597
+ pipe,
6598
+ positive,
6518
6599
  record,
6600
+ refine,
6601
+ startsWith,
6519
6602
  string,
6603
+ transform,
6520
6604
  union,
6521
6605
  unknown
6522
6606
  };
6523
6607
  //#endregion
6608
+ //#region src/util/classic-zod.ts
6609
+ const z = {
6610
+ array: array$1,
6611
+ boolean: boolean$1,
6612
+ custom: custom$1,
6613
+ discriminatedUnion: discriminatedUnion$1,
6614
+ instanceof: instanceof$1,
6615
+ lazy,
6616
+ literal: literal$1,
6617
+ null: null$1,
6618
+ number: number$1,
6619
+ object: object$1,
6620
+ record: record$1,
6621
+ string: string$1,
6622
+ union: union$1,
6623
+ unknown: unknown$1
6624
+ };
6625
+ //#endregion
6524
6626
  //#region src/types/json-value.ts
6525
6627
  const jsonValueSchema = z.lazy(() => z.union([
6526
6628
  z.null(),
@@ -6535,213 +6637,213 @@ const jsonValueSchema = z.lazy(() => z.union([
6535
6637
  const providerMetadataSchema = z.record(z.string(), z.record(z.string(), jsonValueSchema.optional()));
6536
6638
  //#endregion
6537
6639
  //#region src/types/citation.ts
6538
- const citationSchema = z.object({
6539
- source: z.discriminatedUnion("sourceType", [z.object({
6540
- type: z.literal("source"),
6541
- sourceType: z.literal("url"),
6542
- id: z.string(),
6543
- url: z.string(),
6544
- title: z.string().optional(),
6545
- providerMetadata: providerMetadataSchema.optional()
6546
- }), z.object({
6547
- type: z.literal("source"),
6548
- sourceType: z.literal("document"),
6549
- id: z.string(),
6550
- mediaType: z.string(),
6551
- title: z.string(),
6552
- filename: z.string().optional(),
6553
- providerMetadata: providerMetadataSchema.optional()
6640
+ const citationSchema = z$1.object({
6641
+ source: z$1.discriminatedUnion("sourceType", [z$1.object({
6642
+ type: z$1.literal("source"),
6643
+ sourceType: z$1.literal("url"),
6644
+ id: z$1.string(),
6645
+ url: z$1.string(),
6646
+ title: z$1.optional(z$1.string()),
6647
+ providerMetadata: z$1.optional(providerMetadataSchema)
6648
+ }), z$1.object({
6649
+ type: z$1.literal("source"),
6650
+ sourceType: z$1.literal("document"),
6651
+ id: z$1.string(),
6652
+ mediaType: z$1.string(),
6653
+ title: z$1.string(),
6654
+ filename: z$1.optional(z$1.string()),
6655
+ providerMetadata: z$1.optional(providerMetadataSchema)
6554
6656
  })]),
6555
- startIndex: z.number().int().nonnegative().optional(),
6556
- endIndex: z.number().int().nonnegative().optional(),
6557
- citedText: z.string().optional()
6657
+ startIndex: z$1.optional(z$1.number().check(z$1.int()).check(z$1.nonnegative())),
6658
+ endIndex: z$1.optional(z$1.number().check(z$1.int()).check(z$1.nonnegative())),
6659
+ citedText: z$1.optional(z$1.string())
6558
6660
  });
6559
6661
  //#endregion
6560
6662
  //#region src/ui-message-stream/ui-message-chunks.ts
6561
- const toolMetadataSchema$1 = z.record(z.string(), jsonValueSchema.optional());
6562
- const uiMessageChunkSchema = lazySchema(() => zodSchema$1(z.union([
6563
- z.looseObject({
6564
- type: z.literal("text-start"),
6565
- id: z.string(),
6566
- providerMetadata: providerMetadataSchema.optional()
6663
+ const toolMetadataSchema$1 = z$1.record(z$1.string(), z$1.optional(jsonValueSchema));
6664
+ const uiMessageChunkSchema = lazySchema(() => zodSchema$1(z$1.union([
6665
+ z$1.looseObject({
6666
+ type: z$1.literal("text-start"),
6667
+ id: z$1.string(),
6668
+ providerMetadata: z$1.optional(providerMetadataSchema)
6567
6669
  }),
6568
- z.looseObject({
6569
- type: z.literal("text-delta"),
6570
- id: z.string(),
6571
- delta: z.string(),
6572
- providerMetadata: providerMetadataSchema.optional()
6670
+ z$1.looseObject({
6671
+ type: z$1.literal("text-delta"),
6672
+ id: z$1.string(),
6673
+ delta: z$1.string(),
6674
+ providerMetadata: z$1.optional(providerMetadataSchema)
6573
6675
  }),
6574
- z.looseObject({
6575
- type: z.literal("text-end"),
6576
- id: z.string(),
6577
- citations: z.array(citationSchema).optional(),
6578
- providerMetadata: providerMetadataSchema.optional()
6676
+ z$1.looseObject({
6677
+ type: z$1.literal("text-end"),
6678
+ id: z$1.string(),
6679
+ citations: z$1.optional(z$1.array(citationSchema)),
6680
+ providerMetadata: z$1.optional(providerMetadataSchema)
6579
6681
  }),
6580
- z.looseObject({
6581
- type: z.literal("error"),
6582
- errorText: z.string()
6682
+ z$1.looseObject({
6683
+ type: z$1.literal("error"),
6684
+ errorText: z$1.string()
6583
6685
  }),
6584
- z.looseObject({
6585
- type: z.literal("tool-input-start"),
6586
- toolCallId: z.string(),
6587
- toolName: z.string(),
6588
- inputEncoding: z.enum(["json", "text"]).optional(),
6589
- providerExecuted: z.boolean().optional(),
6590
- providerMetadata: providerMetadataSchema.optional(),
6591
- toolMetadata: toolMetadataSchema$1.optional(),
6592
- dynamic: z.boolean().optional(),
6593
- title: z.string().optional()
6686
+ z$1.looseObject({
6687
+ type: z$1.literal("tool-input-start"),
6688
+ toolCallId: z$1.string(),
6689
+ toolName: z$1.string(),
6690
+ inputEncoding: z$1.optional(z$1.enum(["json", "text"])),
6691
+ providerExecuted: z$1.optional(z$1.boolean()),
6692
+ providerMetadata: z$1.optional(providerMetadataSchema),
6693
+ toolMetadata: z$1.optional(toolMetadataSchema$1),
6694
+ dynamic: z$1.optional(z$1.boolean()),
6695
+ title: z$1.optional(z$1.string())
6594
6696
  }),
6595
- z.looseObject({
6596
- type: z.literal("tool-input-delta"),
6597
- toolCallId: z.string(),
6598
- inputTextDelta: z.string()
6697
+ z$1.looseObject({
6698
+ type: z$1.literal("tool-input-delta"),
6699
+ toolCallId: z$1.string(),
6700
+ inputTextDelta: z$1.string()
6599
6701
  }),
6600
- z.looseObject({
6601
- type: z.literal("tool-input-available"),
6602
- toolCallId: z.string(),
6603
- toolName: z.string(),
6604
- input: z.unknown(),
6605
- providerExecuted: z.boolean().optional(),
6606
- providerMetadata: providerMetadataSchema.optional(),
6607
- toolMetadata: toolMetadataSchema$1.optional(),
6608
- dynamic: z.boolean().optional(),
6609
- title: z.string().optional()
6702
+ z$1.looseObject({
6703
+ type: z$1.literal("tool-input-available"),
6704
+ toolCallId: z$1.string(),
6705
+ toolName: z$1.string(),
6706
+ input: z$1.unknown(),
6707
+ providerExecuted: z$1.optional(z$1.boolean()),
6708
+ providerMetadata: z$1.optional(providerMetadataSchema),
6709
+ toolMetadata: z$1.optional(toolMetadataSchema$1),
6710
+ dynamic: z$1.optional(z$1.boolean()),
6711
+ title: z$1.optional(z$1.string())
6610
6712
  }),
6611
- z.looseObject({
6612
- type: z.literal("tool-input-error"),
6613
- toolCallId: z.string(),
6614
- toolName: z.string(),
6615
- input: z.unknown(),
6616
- providerExecuted: z.boolean().optional(),
6617
- providerMetadata: providerMetadataSchema.optional(),
6618
- toolMetadata: toolMetadataSchema$1.optional(),
6619
- dynamic: z.boolean().optional(),
6620
- errorText: z.string(),
6621
- title: z.string().optional()
6713
+ z$1.looseObject({
6714
+ type: z$1.literal("tool-input-error"),
6715
+ toolCallId: z$1.string(),
6716
+ toolName: z$1.string(),
6717
+ input: z$1.unknown(),
6718
+ providerExecuted: z$1.optional(z$1.boolean()),
6719
+ providerMetadata: z$1.optional(providerMetadataSchema),
6720
+ toolMetadata: z$1.optional(toolMetadataSchema$1),
6721
+ dynamic: z$1.optional(z$1.boolean()),
6722
+ errorText: z$1.string(),
6723
+ title: z$1.optional(z$1.string())
6622
6724
  }),
6623
- z.looseObject({
6624
- type: z.literal("tool-approval-request"),
6625
- approvalId: z.string(),
6626
- toolCallId: z.string(),
6627
- approvalDescriptor: z.unknown().optional(),
6628
- inputSchemaInput: z.unknown().optional(),
6629
- reason: z.string().optional(),
6630
- isAutomatic: z.boolean().optional(),
6631
- signature: z.string().optional()
6725
+ z$1.looseObject({
6726
+ type: z$1.literal("tool-approval-request"),
6727
+ approvalId: z$1.string(),
6728
+ toolCallId: z$1.string(),
6729
+ approvalDescriptor: z$1.optional(z$1.unknown()),
6730
+ inputSchemaInput: z$1.optional(z$1.unknown()),
6731
+ reason: z$1.optional(z$1.string()),
6732
+ isAutomatic: z$1.optional(z$1.boolean()),
6733
+ signature: z$1.optional(z$1.string())
6632
6734
  }),
6633
- z.looseObject({
6634
- type: z.literal("tool-approval-response"),
6635
- approvalId: z.string(),
6636
- approved: z.boolean(),
6637
- reason: z.string().optional(),
6638
- providerExecuted: z.boolean().optional(),
6639
- providerMetadata: providerMetadataSchema.optional()
6735
+ z$1.looseObject({
6736
+ type: z$1.literal("tool-approval-response"),
6737
+ approvalId: z$1.string(),
6738
+ approved: z$1.boolean(),
6739
+ reason: z$1.optional(z$1.string()),
6740
+ providerExecuted: z$1.optional(z$1.boolean()),
6741
+ providerMetadata: z$1.optional(providerMetadataSchema)
6640
6742
  }),
6641
- z.looseObject({
6642
- type: z.literal("tool-output-available"),
6643
- toolCallId: z.string(),
6644
- output: z.unknown(),
6645
- providerExecuted: z.boolean().optional(),
6646
- providerMetadata: providerMetadataSchema.optional(),
6647
- toolMetadata: toolMetadataSchema$1.optional(),
6648
- dynamic: z.boolean().optional(),
6649
- preliminary: z.boolean().optional()
6743
+ z$1.looseObject({
6744
+ type: z$1.literal("tool-output-available"),
6745
+ toolCallId: z$1.string(),
6746
+ output: z$1.unknown(),
6747
+ providerExecuted: z$1.optional(z$1.boolean()),
6748
+ providerMetadata: z$1.optional(providerMetadataSchema),
6749
+ toolMetadata: z$1.optional(toolMetadataSchema$1),
6750
+ dynamic: z$1.optional(z$1.boolean()),
6751
+ preliminary: z$1.optional(z$1.boolean())
6650
6752
  }),
6651
- z.looseObject({
6652
- type: z.literal("tool-output-error"),
6653
- toolCallId: z.string(),
6654
- errorText: z.string(),
6655
- providerExecuted: z.boolean().optional(),
6656
- providerMetadata: providerMetadataSchema.optional(),
6657
- toolMetadata: toolMetadataSchema$1.optional(),
6658
- dynamic: z.boolean().optional()
6753
+ z$1.looseObject({
6754
+ type: z$1.literal("tool-output-error"),
6755
+ toolCallId: z$1.string(),
6756
+ errorText: z$1.string(),
6757
+ providerExecuted: z$1.optional(z$1.boolean()),
6758
+ providerMetadata: z$1.optional(providerMetadataSchema),
6759
+ toolMetadata: z$1.optional(toolMetadataSchema$1),
6760
+ dynamic: z$1.optional(z$1.boolean())
6659
6761
  }),
6660
- z.looseObject({
6661
- type: z.literal("tool-output-denied"),
6662
- toolCallId: z.string()
6762
+ z$1.looseObject({
6763
+ type: z$1.literal("tool-output-denied"),
6764
+ toolCallId: z$1.string()
6663
6765
  }),
6664
- z.looseObject({
6665
- type: z.literal("reasoning-start"),
6666
- id: z.string(),
6667
- providerMetadata: providerMetadataSchema.optional()
6766
+ z$1.looseObject({
6767
+ type: z$1.literal("reasoning-start"),
6768
+ id: z$1.string(),
6769
+ providerMetadata: z$1.optional(providerMetadataSchema)
6668
6770
  }),
6669
- z.looseObject({
6670
- type: z.literal("reasoning-delta"),
6671
- id: z.string(),
6672
- delta: z.string(),
6673
- providerMetadata: providerMetadataSchema.optional()
6771
+ z$1.looseObject({
6772
+ type: z$1.literal("reasoning-delta"),
6773
+ id: z$1.string(),
6774
+ delta: z$1.string(),
6775
+ providerMetadata: z$1.optional(providerMetadataSchema)
6674
6776
  }),
6675
- z.looseObject({
6676
- type: z.literal("reasoning-end"),
6677
- id: z.string(),
6678
- providerMetadata: providerMetadataSchema.optional()
6777
+ z$1.looseObject({
6778
+ type: z$1.literal("reasoning-end"),
6779
+ id: z$1.string(),
6780
+ providerMetadata: z$1.optional(providerMetadataSchema)
6679
6781
  }),
6680
- z.looseObject({
6681
- type: z.literal("custom"),
6682
- kind: z.string().transform((value) => value),
6683
- providerMetadata: providerMetadataSchema.optional()
6782
+ z$1.looseObject({
6783
+ type: z$1.literal("custom"),
6784
+ kind: z$1.pipe(z$1.string(), z$1.transform((value) => value)),
6785
+ providerMetadata: z$1.optional(providerMetadataSchema)
6684
6786
  }),
6685
- z.looseObject({
6686
- type: z.literal("source-url"),
6687
- sourceId: z.string(),
6688
- url: z.string(),
6689
- title: z.string().optional(),
6690
- providerMetadata: providerMetadataSchema.optional()
6787
+ z$1.looseObject({
6788
+ type: z$1.literal("source-url"),
6789
+ sourceId: z$1.string(),
6790
+ url: z$1.string(),
6791
+ title: z$1.optional(z$1.string()),
6792
+ providerMetadata: z$1.optional(providerMetadataSchema)
6691
6793
  }),
6692
- z.looseObject({
6693
- type: z.literal("source-document"),
6694
- sourceId: z.string(),
6695
- mediaType: z.string(),
6696
- title: z.string(),
6697
- filename: z.string().optional(),
6698
- providerMetadata: providerMetadataSchema.optional()
6794
+ z$1.looseObject({
6795
+ type: z$1.literal("source-document"),
6796
+ sourceId: z$1.string(),
6797
+ mediaType: z$1.string(),
6798
+ title: z$1.string(),
6799
+ filename: z$1.optional(z$1.string()),
6800
+ providerMetadata: z$1.optional(providerMetadataSchema)
6699
6801
  }),
6700
- z.looseObject({
6701
- type: z.literal("file"),
6702
- url: z.string(),
6703
- mediaType: z.string(),
6704
- providerMetadata: providerMetadataSchema.optional()
6802
+ z$1.looseObject({
6803
+ type: z$1.literal("file"),
6804
+ url: z$1.string(),
6805
+ mediaType: z$1.string(),
6806
+ providerMetadata: z$1.optional(providerMetadataSchema)
6705
6807
  }),
6706
- z.looseObject({
6707
- type: z.literal("reasoning-file"),
6708
- url: z.string(),
6709
- mediaType: z.string(),
6710
- providerMetadata: providerMetadataSchema.optional()
6808
+ z$1.looseObject({
6809
+ type: z$1.literal("reasoning-file"),
6810
+ url: z$1.string(),
6811
+ mediaType: z$1.string(),
6812
+ providerMetadata: z$1.optional(providerMetadataSchema)
6711
6813
  }),
6712
- z.looseObject({
6713
- type: z.literal("steering-message"),
6714
- id: z.string(),
6715
- parts: z.array(z.union([z.looseObject({
6716
- type: z.literal("text"),
6717
- text: z.string(),
6718
- providerMetadata: providerMetadataSchema.optional()
6719
- }), z.looseObject({
6720
- type: z.literal("file"),
6721
- mediaType: z.string(),
6722
- url: z.string(),
6723
- filename: z.string().optional(),
6724
- providerReference: z.record(z.string(), z.string()).optional(),
6725
- providerMetadata: providerMetadataSchema.optional()
6814
+ z$1.looseObject({
6815
+ type: z$1.literal("steering-message"),
6816
+ id: z$1.string(),
6817
+ parts: z$1.array(z$1.union([z$1.looseObject({
6818
+ type: z$1.literal("text"),
6819
+ text: z$1.string(),
6820
+ providerMetadata: z$1.optional(providerMetadataSchema)
6821
+ }), z$1.looseObject({
6822
+ type: z$1.literal("file"),
6823
+ mediaType: z$1.string(),
6824
+ url: z$1.string(),
6825
+ filename: z$1.optional(z$1.string()),
6826
+ providerReference: z$1.optional(z$1.record(z$1.string(), z$1.string())),
6827
+ providerMetadata: z$1.optional(providerMetadataSchema)
6726
6828
  })]))
6727
6829
  }),
6728
- z.looseObject({
6729
- type: z.custom((value) => typeof value === "string" && value.startsWith("data-"), { message: "Type must start with \"data-\"" }),
6730
- id: z.string().optional(),
6731
- data: z.unknown(),
6732
- transient: z.boolean().optional()
6830
+ z$1.looseObject({
6831
+ type: z$1.custom((value) => typeof value === "string" && value.startsWith("data-"), { message: "Type must start with \"data-\"" }),
6832
+ id: z$1.optional(z$1.string()),
6833
+ data: z$1.unknown(),
6834
+ transient: z$1.optional(z$1.boolean())
6733
6835
  }),
6734
- z.looseObject({ type: z.literal("start-step") }),
6735
- z.looseObject({ type: z.literal("finish-step") }),
6736
- z.looseObject({ type: z.literal("reset-step") }),
6737
- z.looseObject({
6738
- type: z.literal("start"),
6739
- messageId: z.string().optional(),
6740
- messageMetadata: z.unknown().optional()
6836
+ z$1.looseObject({ type: z$1.literal("start-step") }),
6837
+ z$1.looseObject({ type: z$1.literal("finish-step") }),
6838
+ z$1.looseObject({ type: z$1.literal("reset-step") }),
6839
+ z$1.looseObject({
6840
+ type: z$1.literal("start"),
6841
+ messageId: z$1.optional(z$1.string()),
6842
+ messageMetadata: z$1.optional(z$1.unknown())
6741
6843
  }),
6742
- z.looseObject({
6743
- type: z.literal("finish"),
6744
- finishReason: z.enum([
6844
+ z$1.looseObject({
6845
+ type: z$1.literal("finish"),
6846
+ finishReason: z$1.optional(z$1.enum([
6745
6847
  "stop",
6746
6848
  "length",
6747
6849
  "content-filter",
@@ -6749,16 +6851,16 @@ const uiMessageChunkSchema = lazySchema(() => zodSchema$1(z.union([
6749
6851
  "error",
6750
6852
  "interrupted",
6751
6853
  "other"
6752
- ]).optional(),
6753
- messageMetadata: z.unknown().optional()
6854
+ ])),
6855
+ messageMetadata: z$1.optional(z$1.unknown())
6754
6856
  }),
6755
- z.looseObject({
6756
- type: z.literal("abort"),
6757
- reason: z.string().optional()
6857
+ z$1.looseObject({
6858
+ type: z$1.literal("abort"),
6859
+ reason: z$1.optional(z$1.string())
6758
6860
  }),
6759
- z.looseObject({
6760
- type: z.literal("message-metadata"),
6761
- messageMetadata: z.unknown()
6861
+ z$1.looseObject({
6862
+ type: z$1.literal("message-metadata"),
6863
+ messageMetadata: z$1.unknown()
6762
6864
  })
6763
6865
  ])));
6764
6866
  function isDataUIMessageChunk(chunk) {
@@ -9277,9 +9379,13 @@ function createOutputTransformStream(output, collectOutput = true) {
9277
9379
  let text = "";
9278
9380
  let textChunk = "";
9279
9381
  let textProviderMetadata = void 0;
9382
+ let arrayStreamParser = createArrayStreamParser(output);
9383
+ let lastArrayPartial;
9280
9384
  let lastPublishedValue = void 0;
9281
9385
  let hasPublishedValue = false;
9282
9386
  function resetOutputState() {
9387
+ arrayStreamParser = createArrayStreamParser(output);
9388
+ lastArrayPartial = void 0;
9283
9389
  firstTextChunkId = void 0;
9284
9390
  text = "";
9285
9391
  textChunk = "";
@@ -9375,6 +9481,24 @@ function createOutputTransformStream(output, collectOutput = true) {
9375
9481
  });
9376
9482
  return;
9377
9483
  }
9484
+ if (arrayStreamParser != null) {
9485
+ const result = await arrayStreamParser(chunk.text);
9486
+ if (result !== "fallback") {
9487
+ if (result != null) {
9488
+ lastArrayPartial = result.partial;
9489
+ publishTextChunk({
9490
+ controller,
9491
+ partialOutput: lastArrayPartial
9492
+ });
9493
+ }
9494
+ return;
9495
+ }
9496
+ arrayStreamParser = void 0;
9497
+ if (lastArrayPartial != null) {
9498
+ lastPublishedValue = JSON.stringify(lastArrayPartial);
9499
+ hasPublishedValue = true;
9500
+ }
9501
+ }
9378
9502
  const result = await output.parsePartialOutput({ text });
9379
9503
  if (result !== void 0) {
9380
9504
  const currentValue = typeof result.partial === "string" ? result.partial : JSON.stringify(result.partial);
@@ -11611,8 +11735,8 @@ function convertUserContentUIPart(part) {
11611
11735
  }
11612
11736
  //#endregion
11613
11737
  //#region src/ui/validate-ui-messages.ts
11614
- const toolMetadataSchema = z.record(z.string(), jsonValueSchema.optional());
11615
- const providerReferenceSchema$1 = z.record(z.string(), z.string());
11738
+ const toolMetadataSchema = z$1.record(z$1.string(), z$1.optional(jsonValueSchema));
11739
+ const providerReferenceSchema$1 = z$1.record(z$1.string(), z$1.string());
11616
11740
  function isEmptyObject(value) {
11617
11741
  return value != null && typeof value === "object" && !Array.isArray(value) && Object.keys(value).length === 0;
11618
11742
  }
@@ -11628,312 +11752,314 @@ function getToolPartInputSchemaInput(toolPart) {
11628
11752
  return toolPart.approval != null && Object.prototype.hasOwnProperty.call(toolPart.approval, "inputSchemaInput") ? { value: toolPart.approval.inputSchemaInput } : void 0;
11629
11753
  }
11630
11754
  const uiMessagesSchema = lazySchema(() => {
11631
- const approvalRequestedSchema = z.object({
11632
- id: z.string(),
11633
- approved: z.never().optional(),
11634
- descriptor: z.unknown().optional(),
11635
- requestReason: z.string().optional(),
11636
- reason: z.never().optional(),
11637
- isAutomatic: z.boolean().optional(),
11638
- signature: z.string().optional(),
11639
- inputSchemaInput: z.unknown().optional()
11755
+ const approvalRequestedSchema = z$1.object({
11756
+ id: z$1.string(),
11757
+ approved: z$1.optional(z$1.never()),
11758
+ descriptor: z$1.optional(z$1.unknown()),
11759
+ requestReason: z$1.optional(z$1.string()),
11760
+ reason: z$1.optional(z$1.never()),
11761
+ isAutomatic: z$1.optional(z$1.boolean()),
11762
+ signature: z$1.optional(z$1.string()),
11763
+ inputSchemaInput: z$1.optional(z$1.unknown())
11640
11764
  });
11641
- const approvalRespondedSchema = approvalRequestedSchema.extend({
11642
- approved: z.boolean(),
11643
- reason: z.string().optional()
11765
+ const approvalRespondedSchema = z$1.extend(approvalRequestedSchema, {
11766
+ approved: z$1.boolean(),
11767
+ reason: z$1.optional(z$1.string())
11644
11768
  });
11645
- const approvalGrantedSchema = approvalRespondedSchema.extend({ approved: z.literal(true) });
11646
- const approvalDeniedSchema = approvalRespondedSchema.extend({ approved: z.literal(false) });
11647
- return zodSchema$1(z.array(z.object({
11648
- id: z.string(),
11649
- role: z.enum([
11769
+ const approvalGrantedSchema = z$1.extend(approvalRespondedSchema, { approved: z$1.literal(true) });
11770
+ const approvalDeniedSchema = z$1.extend(approvalRespondedSchema, { approved: z$1.literal(false) });
11771
+ return zodSchema$1(z$1.array(z$1.object({
11772
+ id: z$1.string(),
11773
+ role: z$1.enum([
11650
11774
  "system",
11651
11775
  "user",
11652
11776
  "assistant"
11653
11777
  ]),
11654
- metadata: z.unknown().optional(),
11655
- parts: z.array(z.union([
11656
- z.object({
11657
- type: z.literal("text"),
11658
- text: z.string(),
11659
- citations: z.array(citationSchema).optional(),
11660
- state: z.enum(["streaming", "done"]).optional(),
11661
- providerMetadata: providerMetadataSchema.optional()
11778
+ metadata: z$1.optional(z$1.unknown()),
11779
+ parts: z$1.array(z$1.union([
11780
+ z$1.object({
11781
+ type: z$1.literal("text"),
11782
+ text: z$1.string(),
11783
+ citations: z$1.optional(z$1.array(citationSchema)),
11784
+ state: z$1.optional(z$1.enum(["streaming", "done"])),
11785
+ providerMetadata: z$1.optional(providerMetadataSchema)
11662
11786
  }),
11663
- z.object({
11664
- type: z.literal("reasoning"),
11665
- id: z.string().optional(),
11666
- text: z.string(),
11667
- state: z.enum(["streaming", "done"]).optional(),
11668
- providerMetadata: providerMetadataSchema.optional()
11787
+ z$1.object({
11788
+ type: z$1.literal("reasoning"),
11789
+ id: z$1.optional(z$1.string()),
11790
+ text: z$1.string(),
11791
+ state: z$1.optional(z$1.enum(["streaming", "done"])),
11792
+ providerMetadata: z$1.optional(providerMetadataSchema)
11669
11793
  }),
11670
- z.object({
11671
- type: z.literal("custom"),
11672
- kind: z.string(),
11673
- providerMetadata: providerMetadataSchema.optional()
11794
+ z$1.object({
11795
+ type: z$1.literal("custom"),
11796
+ kind: z$1.string(),
11797
+ providerMetadata: z$1.optional(providerMetadataSchema)
11674
11798
  }),
11675
- z.object({
11676
- type: z.literal("source-url"),
11677
- sourceId: z.string(),
11678
- url: z.string(),
11679
- title: z.string().optional(),
11680
- providerMetadata: providerMetadataSchema.optional()
11799
+ z$1.object({
11800
+ type: z$1.literal("source-url"),
11801
+ sourceId: z$1.string(),
11802
+ url: z$1.string(),
11803
+ title: z$1.optional(z$1.string()),
11804
+ providerMetadata: z$1.optional(providerMetadataSchema)
11681
11805
  }),
11682
- z.object({
11683
- type: z.literal("source-document"),
11684
- sourceId: z.string(),
11685
- mediaType: z.string(),
11686
- title: z.string(),
11687
- filename: z.string().optional(),
11688
- providerMetadata: providerMetadataSchema.optional()
11806
+ z$1.object({
11807
+ type: z$1.literal("source-document"),
11808
+ sourceId: z$1.string(),
11809
+ mediaType: z$1.string(),
11810
+ title: z$1.string(),
11811
+ filename: z$1.optional(z$1.string()),
11812
+ providerMetadata: z$1.optional(providerMetadataSchema)
11689
11813
  }),
11690
- z.object({
11691
- type: z.literal("file"),
11692
- mediaType: z.string(),
11693
- filename: z.string().optional(),
11694
- url: z.string(),
11695
- providerReference: providerReferenceSchema$1.optional(),
11696
- providerMetadata: providerMetadataSchema.optional()
11814
+ z$1.object({
11815
+ type: z$1.literal("file"),
11816
+ mediaType: z$1.string(),
11817
+ filename: z$1.optional(z$1.string()),
11818
+ url: z$1.string(),
11819
+ providerReference: z$1.optional(providerReferenceSchema$1),
11820
+ providerMetadata: z$1.optional(providerMetadataSchema)
11697
11821
  }),
11698
- z.object({
11699
- type: z.literal("reasoning-file"),
11700
- mediaType: z.string(),
11701
- url: z.string(),
11702
- providerMetadata: providerMetadataSchema.optional()
11822
+ z$1.object({
11823
+ type: z$1.literal("reasoning-file"),
11824
+ mediaType: z$1.string(),
11825
+ url: z$1.string(),
11826
+ providerMetadata: z$1.optional(providerMetadataSchema)
11703
11827
  }),
11704
- z.object({
11705
- type: z.literal("steering-message"),
11706
- id: z.string(),
11707
- parts: z.array(z.union([z.object({
11708
- type: z.literal("text"),
11709
- text: z.string(),
11710
- providerMetadata: providerMetadataSchema.optional()
11711
- }), z.object({
11712
- type: z.literal("file"),
11713
- mediaType: z.string(),
11714
- filename: z.string().optional(),
11715
- url: z.string(),
11716
- providerReference: providerReferenceSchema$1.optional(),
11717
- providerMetadata: providerMetadataSchema.optional()
11828
+ z$1.object({
11829
+ type: z$1.literal("steering-message"),
11830
+ id: z$1.string(),
11831
+ parts: z$1.array(z$1.union([z$1.object({
11832
+ type: z$1.literal("text"),
11833
+ text: z$1.string(),
11834
+ providerMetadata: z$1.optional(providerMetadataSchema)
11835
+ }), z$1.object({
11836
+ type: z$1.literal("file"),
11837
+ mediaType: z$1.string(),
11838
+ filename: z$1.optional(z$1.string()),
11839
+ url: z$1.string(),
11840
+ providerReference: z$1.optional(providerReferenceSchema$1),
11841
+ providerMetadata: z$1.optional(providerMetadataSchema)
11718
11842
  })]))
11719
11843
  }),
11720
- z.object({ type: z.literal("step-start") }),
11721
- z.object({
11722
- type: z.string().startsWith("data-"),
11723
- id: z.string().optional(),
11724
- data: z.unknown()
11844
+ z$1.object({ type: z$1.literal("step-start") }),
11845
+ z$1.object({
11846
+ type: z$1.string().check(z$1.startsWith("data-")),
11847
+ id: z$1.optional(z$1.string()),
11848
+ data: z$1.unknown()
11725
11849
  }),
11726
- z.object({
11727
- type: z.literal("dynamic-tool"),
11728
- dynamic: z.literal(false).optional(),
11729
- toolName: z.string(),
11730
- toolCallId: z.string(),
11731
- title: z.string().optional(),
11732
- toolMetadata: toolMetadataSchema.optional(),
11733
- state: z.literal("input-streaming"),
11734
- input: z.unknown().optional(),
11735
- rawInput: z.string().optional(),
11736
- inputEncoding: z.enum(["json", "text"]).optional(),
11737
- providerExecuted: z.boolean().optional(),
11738
- callProviderMetadata: providerMetadataSchema.optional(),
11739
- output: z.never().optional(),
11740
- errorText: z.never().optional(),
11741
- approval: z.never().optional()
11850
+ z$1.object({
11851
+ type: z$1.literal("dynamic-tool"),
11852
+ dynamic: z$1.optional(z$1.literal(false)),
11853
+ toolName: z$1.string(),
11854
+ toolCallId: z$1.string(),
11855
+ title: z$1.optional(z$1.string()),
11856
+ toolMetadata: z$1.optional(toolMetadataSchema),
11857
+ state: z$1.literal("input-streaming"),
11858
+ input: z$1.optional(z$1.unknown()),
11859
+ rawInput: z$1.optional(z$1.string()),
11860
+ inputEncoding: z$1.optional(z$1.enum(["json", "text"])),
11861
+ providerExecuted: z$1.optional(z$1.boolean()),
11862
+ callProviderMetadata: z$1.optional(providerMetadataSchema),
11863
+ output: z$1.optional(z$1.never()),
11864
+ errorText: z$1.optional(z$1.never()),
11865
+ approval: z$1.optional(z$1.never())
11742
11866
  }),
11743
- z.object({
11744
- type: z.literal("dynamic-tool"),
11745
- dynamic: z.literal(false).optional(),
11746
- toolName: z.string(),
11747
- toolCallId: z.string(),
11748
- title: z.string().optional(),
11749
- toolMetadata: toolMetadataSchema.optional(),
11750
- state: z.literal("input-available"),
11751
- input: z.unknown(),
11752
- providerExecuted: z.boolean().optional(),
11753
- output: z.never().optional(),
11754
- errorText: z.never().optional(),
11755
- callProviderMetadata: providerMetadataSchema.optional(),
11756
- approval: z.never().optional()
11867
+ z$1.object({
11868
+ type: z$1.literal("dynamic-tool"),
11869
+ dynamic: z$1.optional(z$1.literal(false)),
11870
+ toolName: z$1.string(),
11871
+ toolCallId: z$1.string(),
11872
+ title: z$1.optional(z$1.string()),
11873
+ toolMetadata: z$1.optional(toolMetadataSchema),
11874
+ state: z$1.literal("input-available"),
11875
+ input: z$1.unknown(),
11876
+ providerExecuted: z$1.optional(z$1.boolean()),
11877
+ output: z$1.optional(z$1.never()),
11878
+ errorText: z$1.optional(z$1.never()),
11879
+ callProviderMetadata: z$1.optional(providerMetadataSchema),
11880
+ approval: z$1.optional(z$1.never())
11757
11881
  }),
11758
- z.object({
11759
- type: z.literal("dynamic-tool"),
11760
- dynamic: z.literal(false).optional(),
11761
- toolName: z.string(),
11762
- toolCallId: z.string(),
11763
- title: z.string().optional(),
11764
- toolMetadata: toolMetadataSchema.optional(),
11765
- state: z.literal("approval-requested"),
11766
- input: z.unknown(),
11767
- providerExecuted: z.boolean().optional(),
11768
- output: z.never().optional(),
11769
- errorText: z.never().optional(),
11770
- callProviderMetadata: providerMetadataSchema.optional(),
11882
+ z$1.object({
11883
+ type: z$1.literal("dynamic-tool"),
11884
+ dynamic: z$1.optional(z$1.literal(false)),
11885
+ toolName: z$1.string(),
11886
+ toolCallId: z$1.string(),
11887
+ title: z$1.optional(z$1.string()),
11888
+ toolMetadata: z$1.optional(toolMetadataSchema),
11889
+ state: z$1.literal("approval-requested"),
11890
+ input: z$1.unknown(),
11891
+ providerExecuted: z$1.optional(z$1.boolean()),
11892
+ output: z$1.optional(z$1.never()),
11893
+ errorText: z$1.optional(z$1.never()),
11894
+ callProviderMetadata: z$1.optional(providerMetadataSchema),
11771
11895
  approval: approvalRequestedSchema
11772
11896
  }),
11773
- z.object({
11774
- type: z.literal("dynamic-tool"),
11775
- dynamic: z.literal(false).optional(),
11776
- toolName: z.string(),
11777
- toolCallId: z.string(),
11778
- title: z.string().optional(),
11779
- toolMetadata: toolMetadataSchema.optional(),
11780
- state: z.literal("approval-responded"),
11781
- input: z.unknown(),
11782
- providerExecuted: z.boolean().optional(),
11783
- output: z.never().optional(),
11784
- errorText: z.never().optional(),
11785
- callProviderMetadata: providerMetadataSchema.optional(),
11897
+ z$1.object({
11898
+ type: z$1.literal("dynamic-tool"),
11899
+ dynamic: z$1.optional(z$1.literal(false)),
11900
+ toolName: z$1.string(),
11901
+ toolCallId: z$1.string(),
11902
+ title: z$1.optional(z$1.string()),
11903
+ toolMetadata: z$1.optional(toolMetadataSchema),
11904
+ state: z$1.literal("approval-responded"),
11905
+ input: z$1.unknown(),
11906
+ providerExecuted: z$1.optional(z$1.boolean()),
11907
+ output: z$1.optional(z$1.never()),
11908
+ errorText: z$1.optional(z$1.never()),
11909
+ callProviderMetadata: z$1.optional(providerMetadataSchema),
11786
11910
  approval: approvalRespondedSchema
11787
11911
  }),
11788
- z.object({
11789
- type: z.literal("dynamic-tool"),
11790
- dynamic: z.literal(false).optional(),
11791
- toolName: z.string(),
11792
- toolCallId: z.string(),
11793
- title: z.string().optional(),
11794
- toolMetadata: toolMetadataSchema.optional(),
11795
- state: z.literal("output-available"),
11796
- input: z.unknown(),
11797
- providerExecuted: z.boolean().optional(),
11798
- output: z.unknown(),
11799
- errorText: z.never().optional(),
11800
- callProviderMetadata: providerMetadataSchema.optional(),
11801
- resultProviderMetadata: providerMetadataSchema.optional(),
11802
- preliminary: z.boolean().optional(),
11803
- approval: approvalGrantedSchema.optional()
11912
+ z$1.object({
11913
+ type: z$1.literal("dynamic-tool"),
11914
+ dynamic: z$1.optional(z$1.literal(false)),
11915
+ toolName: z$1.string(),
11916
+ toolCallId: z$1.string(),
11917
+ title: z$1.optional(z$1.string()),
11918
+ toolMetadata: z$1.optional(toolMetadataSchema),
11919
+ state: z$1.literal("output-available"),
11920
+ input: z$1.unknown(),
11921
+ providerExecuted: z$1.optional(z$1.boolean()),
11922
+ output: z$1.unknown(),
11923
+ errorText: z$1.optional(z$1.never()),
11924
+ callProviderMetadata: z$1.optional(providerMetadataSchema),
11925
+ resultProviderMetadata: z$1.optional(providerMetadataSchema),
11926
+ preliminary: z$1.optional(z$1.boolean()),
11927
+ approval: z$1.optional(approvalGrantedSchema)
11804
11928
  }),
11805
- z.object({
11806
- type: z.literal("dynamic-tool"),
11807
- dynamic: z.literal(false).optional(),
11808
- toolName: z.string(),
11809
- toolCallId: z.string(),
11810
- title: z.string().optional(),
11811
- toolMetadata: toolMetadataSchema.optional(),
11812
- state: z.literal("output-error"),
11813
- input: z.unknown().optional(),
11814
- rawInput: z.unknown().optional(),
11815
- providerExecuted: z.boolean().optional(),
11816
- output: z.never().optional(),
11817
- errorText: z.string(),
11818
- callProviderMetadata: providerMetadataSchema.optional(),
11819
- resultProviderMetadata: providerMetadataSchema.optional(),
11820
- approval: approvalGrantedSchema.optional()
11929
+ z$1.object({
11930
+ type: z$1.literal("dynamic-tool"),
11931
+ dynamic: z$1.optional(z$1.literal(false)),
11932
+ toolName: z$1.string(),
11933
+ toolCallId: z$1.string(),
11934
+ title: z$1.optional(z$1.string()),
11935
+ toolMetadata: z$1.optional(toolMetadataSchema),
11936
+ state: z$1.literal("output-error"),
11937
+ input: z$1.optional(z$1.unknown()),
11938
+ rawInput: z$1.optional(z$1.unknown()),
11939
+ providerExecuted: z$1.optional(z$1.boolean()),
11940
+ output: z$1.optional(z$1.never()),
11941
+ errorText: z$1.string(),
11942
+ callProviderMetadata: z$1.optional(providerMetadataSchema),
11943
+ resultProviderMetadata: z$1.optional(providerMetadataSchema),
11944
+ approval: z$1.optional(approvalGrantedSchema)
11821
11945
  }),
11822
- z.object({
11823
- type: z.literal("dynamic-tool"),
11824
- dynamic: z.literal(false).optional(),
11825
- toolName: z.string(),
11826
- toolCallId: z.string(),
11827
- title: z.string().optional(),
11828
- toolMetadata: toolMetadataSchema.optional(),
11829
- state: z.literal("output-denied"),
11830
- input: z.unknown(),
11831
- providerExecuted: z.boolean().optional(),
11832
- output: z.never().optional(),
11833
- errorText: z.never().optional(),
11834
- callProviderMetadata: providerMetadataSchema.optional(),
11946
+ z$1.object({
11947
+ type: z$1.literal("dynamic-tool"),
11948
+ dynamic: z$1.optional(z$1.literal(false)),
11949
+ toolName: z$1.string(),
11950
+ toolCallId: z$1.string(),
11951
+ title: z$1.optional(z$1.string()),
11952
+ toolMetadata: z$1.optional(toolMetadataSchema),
11953
+ state: z$1.literal("output-denied"),
11954
+ input: z$1.unknown(),
11955
+ providerExecuted: z$1.optional(z$1.boolean()),
11956
+ output: z$1.optional(z$1.never()),
11957
+ errorText: z$1.optional(z$1.never()),
11958
+ callProviderMetadata: z$1.optional(providerMetadataSchema),
11835
11959
  approval: approvalDeniedSchema
11836
11960
  }),
11837
- z.object({
11838
- type: z.string().startsWith("tool-"),
11839
- toolCallId: z.string(),
11840
- title: z.string().optional(),
11841
- toolMetadata: toolMetadataSchema.optional(),
11842
- state: z.literal("input-streaming"),
11843
- providerExecuted: z.boolean().optional(),
11844
- callProviderMetadata: providerMetadataSchema.optional(),
11845
- input: z.unknown().optional(),
11846
- rawInput: z.string().optional(),
11847
- inputEncoding: z.enum(["json", "text"]).optional(),
11848
- output: z.never().optional(),
11849
- errorText: z.never().optional(),
11850
- approval: z.never().optional()
11961
+ z$1.object({
11962
+ type: z$1.string().check(z$1.startsWith("tool-")),
11963
+ toolCallId: z$1.string(),
11964
+ title: z$1.optional(z$1.string()),
11965
+ toolMetadata: z$1.optional(toolMetadataSchema),
11966
+ state: z$1.literal("input-streaming"),
11967
+ providerExecuted: z$1.optional(z$1.boolean()),
11968
+ callProviderMetadata: z$1.optional(providerMetadataSchema),
11969
+ input: z$1.optional(z$1.unknown()),
11970
+ rawInput: z$1.optional(z$1.string()),
11971
+ inputEncoding: z$1.optional(z$1.enum(["json", "text"])),
11972
+ output: z$1.optional(z$1.never()),
11973
+ errorText: z$1.optional(z$1.never()),
11974
+ approval: z$1.optional(z$1.never())
11851
11975
  }),
11852
- z.object({
11853
- type: z.string().startsWith("tool-"),
11854
- toolCallId: z.string(),
11855
- title: z.string().optional(),
11856
- toolMetadata: toolMetadataSchema.optional(),
11857
- state: z.literal("input-available"),
11858
- providerExecuted: z.boolean().optional(),
11859
- input: z.unknown(),
11860
- output: z.never().optional(),
11861
- errorText: z.never().optional(),
11862
- callProviderMetadata: providerMetadataSchema.optional(),
11863
- approval: z.never().optional()
11976
+ z$1.object({
11977
+ type: z$1.string().check(z$1.startsWith("tool-")),
11978
+ toolCallId: z$1.string(),
11979
+ title: z$1.optional(z$1.string()),
11980
+ toolMetadata: z$1.optional(toolMetadataSchema),
11981
+ state: z$1.literal("input-available"),
11982
+ providerExecuted: z$1.optional(z$1.boolean()),
11983
+ input: z$1.unknown(),
11984
+ output: z$1.optional(z$1.never()),
11985
+ errorText: z$1.optional(z$1.never()),
11986
+ callProviderMetadata: z$1.optional(providerMetadataSchema),
11987
+ approval: z$1.optional(z$1.never())
11864
11988
  }),
11865
- z.object({
11866
- type: z.string().startsWith("tool-"),
11867
- toolCallId: z.string(),
11868
- title: z.string().optional(),
11869
- toolMetadata: toolMetadataSchema.optional(),
11870
- state: z.literal("approval-requested"),
11871
- input: z.unknown(),
11872
- providerExecuted: z.boolean().optional(),
11873
- output: z.never().optional(),
11874
- errorText: z.never().optional(),
11875
- callProviderMetadata: providerMetadataSchema.optional(),
11989
+ z$1.object({
11990
+ type: z$1.string().check(z$1.startsWith("tool-")),
11991
+ toolCallId: z$1.string(),
11992
+ title: z$1.optional(z$1.string()),
11993
+ toolMetadata: z$1.optional(toolMetadataSchema),
11994
+ state: z$1.literal("approval-requested"),
11995
+ input: z$1.unknown(),
11996
+ providerExecuted: z$1.optional(z$1.boolean()),
11997
+ output: z$1.optional(z$1.never()),
11998
+ errorText: z$1.optional(z$1.never()),
11999
+ callProviderMetadata: z$1.optional(providerMetadataSchema),
11876
12000
  approval: approvalRequestedSchema
11877
12001
  }),
11878
- z.object({
11879
- type: z.string().startsWith("tool-"),
11880
- toolCallId: z.string(),
11881
- title: z.string().optional(),
11882
- toolMetadata: toolMetadataSchema.optional(),
11883
- state: z.literal("approval-responded"),
11884
- input: z.unknown(),
11885
- providerExecuted: z.boolean().optional(),
11886
- output: z.never().optional(),
11887
- errorText: z.never().optional(),
11888
- callProviderMetadata: providerMetadataSchema.optional(),
12002
+ z$1.object({
12003
+ type: z$1.string().check(z$1.startsWith("tool-")),
12004
+ toolCallId: z$1.string(),
12005
+ title: z$1.optional(z$1.string()),
12006
+ toolMetadata: z$1.optional(toolMetadataSchema),
12007
+ state: z$1.literal("approval-responded"),
12008
+ input: z$1.unknown(),
12009
+ providerExecuted: z$1.optional(z$1.boolean()),
12010
+ output: z$1.optional(z$1.never()),
12011
+ errorText: z$1.optional(z$1.never()),
12012
+ callProviderMetadata: z$1.optional(providerMetadataSchema),
11889
12013
  approval: approvalRespondedSchema
11890
12014
  }),
11891
- z.object({
11892
- type: z.string().startsWith("tool-"),
11893
- toolCallId: z.string(),
11894
- title: z.string().optional(),
11895
- toolMetadata: toolMetadataSchema.optional(),
11896
- state: z.literal("output-available"),
11897
- providerExecuted: z.boolean().optional(),
11898
- input: z.unknown(),
11899
- output: z.unknown(),
11900
- errorText: z.never().optional(),
11901
- callProviderMetadata: providerMetadataSchema.optional(),
11902
- resultProviderMetadata: providerMetadataSchema.optional(),
11903
- preliminary: z.boolean().optional(),
11904
- approval: approvalGrantedSchema.optional()
12015
+ z$1.object({
12016
+ type: z$1.string().check(z$1.startsWith("tool-")),
12017
+ toolCallId: z$1.string(),
12018
+ title: z$1.optional(z$1.string()),
12019
+ toolMetadata: z$1.optional(toolMetadataSchema),
12020
+ state: z$1.literal("output-available"),
12021
+ providerExecuted: z$1.optional(z$1.boolean()),
12022
+ input: z$1.unknown(),
12023
+ output: z$1.unknown(),
12024
+ errorText: z$1.optional(z$1.never()),
12025
+ callProviderMetadata: z$1.optional(providerMetadataSchema),
12026
+ resultProviderMetadata: z$1.optional(providerMetadataSchema),
12027
+ preliminary: z$1.optional(z$1.boolean()),
12028
+ approval: z$1.optional(approvalGrantedSchema)
11905
12029
  }),
11906
- z.object({
11907
- type: z.string().startsWith("tool-"),
11908
- toolCallId: z.string(),
11909
- title: z.string().optional(),
11910
- toolMetadata: toolMetadataSchema.optional(),
11911
- state: z.literal("output-error"),
11912
- providerExecuted: z.boolean().optional(),
11913
- input: z.unknown().optional(),
11914
- rawInput: z.unknown().optional(),
11915
- output: z.never().optional(),
11916
- errorText: z.string(),
11917
- callProviderMetadata: providerMetadataSchema.optional(),
11918
- resultProviderMetadata: providerMetadataSchema.optional(),
11919
- approval: approvalGrantedSchema.optional()
12030
+ z$1.object({
12031
+ type: z$1.string().check(z$1.startsWith("tool-")),
12032
+ toolCallId: z$1.string(),
12033
+ title: z$1.optional(z$1.string()),
12034
+ toolMetadata: z$1.optional(toolMetadataSchema),
12035
+ state: z$1.literal("output-error"),
12036
+ providerExecuted: z$1.optional(z$1.boolean()),
12037
+ input: z$1.optional(z$1.unknown()),
12038
+ rawInput: z$1.optional(z$1.unknown()),
12039
+ output: z$1.optional(z$1.never()),
12040
+ errorText: z$1.string(),
12041
+ callProviderMetadata: z$1.optional(providerMetadataSchema),
12042
+ resultProviderMetadata: z$1.optional(providerMetadataSchema),
12043
+ approval: z$1.optional(approvalGrantedSchema)
11920
12044
  }),
11921
- z.object({
11922
- type: z.string().startsWith("tool-"),
11923
- toolCallId: z.string(),
11924
- title: z.string().optional(),
11925
- toolMetadata: toolMetadataSchema.optional(),
11926
- state: z.literal("output-denied"),
11927
- providerExecuted: z.boolean().optional(),
11928
- input: z.unknown(),
11929
- output: z.never().optional(),
11930
- errorText: z.never().optional(),
11931
- callProviderMetadata: providerMetadataSchema.optional(),
12045
+ z$1.object({
12046
+ type: z$1.string().check(z$1.startsWith("tool-")),
12047
+ toolCallId: z$1.string(),
12048
+ title: z$1.optional(z$1.string()),
12049
+ toolMetadata: z$1.optional(toolMetadataSchema),
12050
+ state: z$1.literal("output-denied"),
12051
+ providerExecuted: z$1.optional(z$1.boolean()),
12052
+ input: z$1.unknown(),
12053
+ output: z$1.optional(z$1.never()),
12054
+ errorText: z$1.optional(z$1.never()),
12055
+ callProviderMetadata: z$1.optional(providerMetadataSchema),
11932
12056
  approval: approvalDeniedSchema
11933
12057
  })
11934
12058
  ]))
11935
- }).superRefine((message, context) => {
11936
- if (message.role !== "assistant" && message.parts.length === 0) context.addIssue({
12059
+ }).check((context) => {
12060
+ const message = context.value;
12061
+ if (message.role !== "assistant" && message.parts.length === 0) context.issues.push({
12062
+ continue: true,
11937
12063
  origin: "array",
11938
12064
  code: "too_small",
11939
12065
  minimum: 1,
@@ -11942,7 +12068,7 @@ const uiMessagesSchema = lazySchema(() => {
11942
12068
  path: ["parts"],
11943
12069
  message: "Message must contain at least one part"
11944
12070
  });
11945
- })).nonempty("Messages array must not be empty"));
12071
+ })).check(z$1.minLength(1, "Messages array must not be empty")));
11946
12072
  });
11947
12073
  async function safeValidateUIMessagesInternal({ messages, metadataSchema, dataSchemas, tools, experimental_refineToolInput }, { convertMissingTerminalToolsToDynamic }) {
11948
12074
  try {
@@ -13774,6 +13900,7 @@ const objectOutputStrategy = (schema) => ({
13774
13900
  const arrayOutputStrategy = (schema) => {
13775
13901
  return {
13776
13902
  type: "array",
13903
+ createArrayStreamParser: () => createArrayOutputStreamParser(schema, false),
13777
13904
  jsonSchema: async () => {
13778
13905
  const { $schema: _$schema, definitions, $defs, ...itemSchema } = await schema.jsonSchema;
13779
13906
  return {
@@ -14729,6 +14856,7 @@ var DefaultStreamObjectResult = class {
14729
14856
  let error;
14730
14857
  let terminalError;
14731
14858
  let msToFirstChunk = void 0;
14859
+ let arrayStreamParser = outputStrategy.createArrayStreamParser?.();
14732
14860
  let accumulatedText = "";
14733
14861
  let textDelta = "";
14734
14862
  let fullResponse = {
@@ -14753,6 +14881,26 @@ var DefaultStreamObjectResult = class {
14753
14881
  if (typeof chunk === "string") {
14754
14882
  accumulatedText += chunk;
14755
14883
  textDelta += chunk;
14884
+ if (arrayStreamParser != null) {
14885
+ const result = await arrayStreamParser(chunk);
14886
+ if (result !== "fallback") {
14887
+ if (result != null) {
14888
+ latestObject = result.partial;
14889
+ controller.enqueue({
14890
+ type: "object",
14891
+ object: latestObject
14892
+ });
14893
+ controller.enqueue({
14894
+ type: "text-delta",
14895
+ textDelta: result.textDelta
14896
+ });
14897
+ textDelta = "";
14898
+ isFirstDelta = false;
14899
+ }
14900
+ return;
14901
+ }
14902
+ arrayStreamParser = void 0;
14903
+ }
14756
14904
  const { value: currentObjectJson, state: parseState } = await parsePartialJson(accumulatedText);
14757
14905
  if (currentObjectJson !== void 0 && !isDeepEqualData(latestObjectJson, currentObjectJson)) {
14758
14906
  const validationResult = await outputStrategy.validatePartialResult({
@@ -18544,23 +18692,23 @@ var RealtimeCommandTracker = class {
18544
18692
  };
18545
18693
  //#endregion
18546
18694
  //#region src/realtime/validate-realtime-setup.ts
18547
- const setupSchema = z.object({
18548
- token: z.string().refine((value) => value.trim().length > 0),
18549
- url: z.string().refine((value) => {
18695
+ const setupSchema = z$1.object({
18696
+ token: z$1.string().check(z$1.refine((value) => value.trim().length > 0)),
18697
+ url: z$1.string().check(z$1.refine((value) => {
18550
18698
  try {
18551
18699
  const url = new URL(value);
18552
18700
  return (url.protocol === "ws:" || url.protocol === "wss:") && url.hostname !== "";
18553
18701
  } catch {
18554
18702
  return false;
18555
18703
  }
18556
- }),
18557
- expiresAt: z.number().positive().max(Number.MAX_SAFE_INTEGER).optional(),
18558
- tools: z.array(z.object({
18559
- type: z.literal("function"),
18560
- name: z.string().min(1),
18561
- description: z.string().optional(),
18562
- parameters: z.record(z.string(), z.unknown())
18563
- })).optional()
18704
+ })),
18705
+ expiresAt: z$1.optional(z$1.number().check(z$1.positive()).check(z$1.maximum(Number.MAX_SAFE_INTEGER))),
18706
+ tools: z$1.optional(z$1.array(z$1.object({
18707
+ type: z$1.literal("function"),
18708
+ name: z$1.string().check(z$1.minLength(1)),
18709
+ description: z$1.optional(z$1.string()),
18710
+ parameters: z$1.record(z$1.string(), z$1.unknown())
18711
+ })))
18564
18712
  });
18565
18713
  function validateRealtimeSetup(payload) {
18566
18714
  const result = setupSchema.safeParse(payload);
@@ -21101,6 +21249,7 @@ var AbstractChat = class {
21101
21249
  this.queuedMessagesFallback = [];
21102
21250
  this.queuedMessageOptions = /* @__PURE__ */ new Map();
21103
21251
  this.isQueuePaused = false;
21252
+ this.pendingAutomaticDecisions = [];
21104
21253
  this.pendingMessagePreparations = /* @__PURE__ */ new Set();
21105
21254
  this.interruptedMessageIds = /* @__PURE__ */ new Set();
21106
21255
  this.activeResponse = void 0;
@@ -21117,8 +21266,13 @@ var AbstractChat = class {
21117
21266
  const message = this.experimental_queuedMessages.find((message) => message.id === id);
21118
21267
  if (message == null) return;
21119
21268
  this.setQueuedMessages([message, ...this.experimental_queuedMessages.filter((queued) => queued.id !== id)]);
21269
+ const stopGeneration = this.stopGeneration + 1;
21120
21270
  await this.stop();
21121
- await this.resumeQueue({ skipWaitForUser: true });
21271
+ if (stopGeneration !== this.stopGeneration) return;
21272
+ await this.resumeQueue({
21273
+ skipWaitForUser: true,
21274
+ options: this.queuedMessageOptions.get(id)
21275
+ });
21122
21276
  };
21123
21277
  this.sendMessage = async (message, options) => {
21124
21278
  if (message == null) {
@@ -21166,7 +21320,10 @@ var AbstractChat = class {
21166
21320
  };
21167
21321
  if (options != null) this.queuedMessageOptions.set(queuedMessage.id, options);
21168
21322
  this.setQueuedMessages([...this.experimental_queuedMessages, queuedMessage]);
21169
- await this.resumeQueue({ skipWaitForUser: this.isQueuePaused });
21323
+ await this.resumeQueue({
21324
+ skipWaitForUser: this.isQueuePaused,
21325
+ options
21326
+ });
21170
21327
  return;
21171
21328
  }
21172
21329
  if (message.messageId != null) {
@@ -21328,6 +21485,7 @@ var AbstractChat = class {
21328
21485
  this.stop = async () => {
21329
21486
  this.activeStopCount++;
21330
21487
  this.stopGeneration++;
21488
+ this.deferredApprovalSend = void 0;
21331
21489
  try {
21332
21490
  const activeResumeRequest = this.activeResumeRequest;
21333
21491
  const activeResponse = this.activeResponse;
@@ -21397,11 +21555,14 @@ var AbstractChat = class {
21397
21555
  if ("experimental_queuedMessages" in this.state) this.state.experimental_queuedMessages = experimental_queuedMessages;
21398
21556
  else this.queuedMessagesFallback = experimental_queuedMessages;
21399
21557
  }
21400
- async resumeQueue({ skipWaitForUser }) {
21558
+ async resumeQueue({ skipWaitForUser, options }) {
21401
21559
  this.isQueuePaused = false;
21402
- if (!this.isRequestInProgress() && this.hasUnsentApprovalResponse()) {
21403
- await this.sendMessage();
21404
- return;
21560
+ if (this.hasUnsentApprovalResponse()) {
21561
+ if (!this.isRequestInProgress()) {
21562
+ await this.sendMessage(void 0, options);
21563
+ return;
21564
+ }
21565
+ this.deferredApprovalSend = { options };
21405
21566
  }
21406
21567
  await this.settleQueue({ skipWaitForUser });
21407
21568
  }
@@ -21409,10 +21570,11 @@ var AbstractChat = class {
21409
21570
  if (!this.queueEnabled) return;
21410
21571
  this.queuedMessageOptions.clear();
21411
21572
  this.setQueuedMessages([]);
21573
+ this.deferredApprovalSend = void 0;
21412
21574
  if (this.isRequestInProgress()) await this.stop();
21413
21575
  }
21414
21576
  isRequestInProgress() {
21415
- return this.activeResponse != null || this.status === "submitted" || this.status === "streaming";
21577
+ return this.pendingAutomaticDecisions.includes(this.stopGeneration) || this.activeResponse != null || this.status === "submitted" || this.status === "streaming";
21416
21578
  }
21417
21579
  isWaitingForUser() {
21418
21580
  const lastMessage = this.lastMessage;
@@ -21423,8 +21585,15 @@ var AbstractChat = class {
21423
21585
  return lastMessage?.role === "assistant" && lastMessage.parts.some((part) => isToolUIPart(part) && part.state === "approval-responded") && !lastMessage.parts.some((part) => isToolUIPart(part) && (part.state === "approval-requested" || !part.providerExecuted && (part.state === "input-streaming" || part.state === "input-available")));
21424
21586
  }
21425
21587
  async settleQueue({ stopGeneration = this.stopGeneration, skipWaitForUser = false } = {}) {
21588
+ if (this.isQueuePaused || this.isRequestInProgress() || this.activeStopCount > 0 || stopGeneration !== this.stopGeneration) return;
21589
+ const deferredApprovalSend = this.deferredApprovalSend;
21590
+ this.deferredApprovalSend = void 0;
21591
+ if (deferredApprovalSend != null && this.hasUnsentApprovalResponse()) {
21592
+ await this.sendMessage(void 0, deferredApprovalSend.options);
21593
+ return;
21594
+ }
21426
21595
  const [message, ...rest] = this.experimental_queuedMessages;
21427
- if (message == null || this.isQueuePaused || this.isRequestInProgress() || this.activeStopCount > 0 || stopGeneration !== this.stopGeneration || !skipWaitForUser && this.isWaitingForUser()) return;
21596
+ if (message == null || !skipWaitForUser && this.isWaitingForUser()) return;
21428
21597
  const options = this.queuedMessageOptions.get(message.id);
21429
21598
  this.queuedMessageOptions.delete(message.id);
21430
21599
  this.setQueuedMessages(rest);
@@ -21440,7 +21609,15 @@ var AbstractChat = class {
21440
21609
  async shouldSendAutomatically(messageId = this.lastMessage?.id) {
21441
21610
  const isInterrupted = (id) => id != null && this.interruptedMessageIds.has(id);
21442
21611
  if (!this.sendAutomaticallyWhen || isInterrupted(messageId) || isInterrupted(this.lastMessage?.id)) return false;
21443
- return await this.sendAutomaticallyWhen({ messages: this.state.messages }) && !isInterrupted(messageId) && !isInterrupted(this.lastMessage?.id);
21612
+ const stopGeneration = this.stopGeneration;
21613
+ this.pendingAutomaticDecisions.push(stopGeneration);
21614
+ let result;
21615
+ try {
21616
+ result = await this.sendAutomaticallyWhen({ messages: this.state.messages });
21617
+ } finally {
21618
+ this.pendingAutomaticDecisions.splice(this.pendingAutomaticDecisions.indexOf(stopGeneration), 1);
21619
+ }
21620
+ return result && !isInterrupted(messageId) && !isInterrupted(this.lastMessage?.id);
21444
21621
  }
21445
21622
  async runAutomaticRequest(request, shouldSend) {
21446
21623
  const stopGeneration = this.stopGeneration;
@@ -21451,6 +21628,7 @@ var AbstractChat = class {
21451
21628
  return true;
21452
21629
  }
21453
21630
  async makeRequestForToolApproval({ messageId, messageIndex, ...options }) {
21631
+ this.deferredApprovalSend = void 0;
21454
21632
  const consumesPendingApproval = messageId != null && messageId === this.pendingApprovalMessageId;
21455
21633
  if (consumesPendingApproval) this.pendingApprovalMessageId = void 0;
21456
21634
  await this.makeRequest({