ai 6.0.0-beta.58 → 6.0.0-beta.60

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.58" : "0.0.0-test";
778
+ var VERSION = true ? "6.0.0-beta.60" : "0.0.0-test";
779
779
 
780
780
  // src/util/download/download.ts
781
781
  var download = async ({ url }) => {
@@ -6245,6 +6245,185 @@ var DefaultStreamTextResult = class {
6245
6245
  }
6246
6246
  };
6247
6247
 
6248
+ // src/agent/tool-loop-agent.ts
6249
+ var ToolLoopAgent = class {
6250
+ constructor(settings) {
6251
+ this.version = "agent-v1";
6252
+ this.settings = settings;
6253
+ }
6254
+ /**
6255
+ * The id of the agent.
6256
+ */
6257
+ get id() {
6258
+ return this.settings.id;
6259
+ }
6260
+ /**
6261
+ * The tools that the agent can use.
6262
+ */
6263
+ get tools() {
6264
+ return this.settings.tools;
6265
+ }
6266
+ /**
6267
+ * Generates an output from the agent (non-streaming).
6268
+ */
6269
+ async generate(options) {
6270
+ var _a17;
6271
+ return generateText({
6272
+ ...this.settings,
6273
+ stopWhen: (_a17 = this.settings.stopWhen) != null ? _a17 : stepCountIs(20),
6274
+ ...options
6275
+ });
6276
+ }
6277
+ /**
6278
+ * Streams an output from the agent (streaming).
6279
+ */
6280
+ stream(options) {
6281
+ var _a17;
6282
+ return streamText({
6283
+ ...this.settings,
6284
+ stopWhen: (_a17 = this.settings.stopWhen) != null ? _a17 : stepCountIs(20),
6285
+ ...options
6286
+ });
6287
+ }
6288
+ };
6289
+
6290
+ // src/ui-message-stream/create-ui-message-stream.ts
6291
+ import {
6292
+ generateId as generateIdFunc,
6293
+ getErrorMessage as getErrorMessage8
6294
+ } from "@ai-sdk/provider-utils";
6295
+ function createUIMessageStream({
6296
+ execute,
6297
+ onError = getErrorMessage8,
6298
+ originalMessages,
6299
+ onFinish,
6300
+ generateId: generateId2 = generateIdFunc
6301
+ }) {
6302
+ let controller;
6303
+ const ongoingStreamPromises = [];
6304
+ const stream = new ReadableStream({
6305
+ start(controllerArg) {
6306
+ controller = controllerArg;
6307
+ }
6308
+ });
6309
+ function safeEnqueue(data) {
6310
+ try {
6311
+ controller.enqueue(data);
6312
+ } catch (error) {
6313
+ }
6314
+ }
6315
+ try {
6316
+ const result = execute({
6317
+ writer: {
6318
+ write(part) {
6319
+ safeEnqueue(part);
6320
+ },
6321
+ merge(streamArg) {
6322
+ ongoingStreamPromises.push(
6323
+ (async () => {
6324
+ const reader = streamArg.getReader();
6325
+ while (true) {
6326
+ const { done, value } = await reader.read();
6327
+ if (done)
6328
+ break;
6329
+ safeEnqueue(value);
6330
+ }
6331
+ })().catch((error) => {
6332
+ safeEnqueue({
6333
+ type: "error",
6334
+ errorText: onError(error)
6335
+ });
6336
+ })
6337
+ );
6338
+ },
6339
+ onError
6340
+ }
6341
+ });
6342
+ if (result) {
6343
+ ongoingStreamPromises.push(
6344
+ result.catch((error) => {
6345
+ safeEnqueue({
6346
+ type: "error",
6347
+ errorText: onError(error)
6348
+ });
6349
+ })
6350
+ );
6351
+ }
6352
+ } catch (error) {
6353
+ safeEnqueue({
6354
+ type: "error",
6355
+ errorText: onError(error)
6356
+ });
6357
+ }
6358
+ const waitForStreams = new Promise(async (resolve3) => {
6359
+ while (ongoingStreamPromises.length > 0) {
6360
+ await ongoingStreamPromises.shift();
6361
+ }
6362
+ resolve3();
6363
+ });
6364
+ waitForStreams.finally(() => {
6365
+ try {
6366
+ controller.close();
6367
+ } catch (error) {
6368
+ }
6369
+ });
6370
+ return handleUIMessageStreamFinish({
6371
+ stream,
6372
+ messageId: generateId2(),
6373
+ originalMessages,
6374
+ onFinish,
6375
+ onError
6376
+ });
6377
+ }
6378
+
6379
+ // src/ui-message-stream/read-ui-message-stream.ts
6380
+ function readUIMessageStream({
6381
+ message,
6382
+ stream,
6383
+ onError,
6384
+ terminateOnError = false
6385
+ }) {
6386
+ var _a17;
6387
+ let controller;
6388
+ let hasErrored = false;
6389
+ const outputStream = new ReadableStream({
6390
+ start(controllerParam) {
6391
+ controller = controllerParam;
6392
+ }
6393
+ });
6394
+ const state = createStreamingUIMessageState({
6395
+ messageId: (_a17 = message == null ? void 0 : message.id) != null ? _a17 : "",
6396
+ lastMessage: message
6397
+ });
6398
+ const handleError = (error) => {
6399
+ onError == null ? void 0 : onError(error);
6400
+ if (!hasErrored && terminateOnError) {
6401
+ hasErrored = true;
6402
+ controller == null ? void 0 : controller.error(error);
6403
+ }
6404
+ };
6405
+ consumeStream({
6406
+ stream: processUIMessageStream({
6407
+ stream,
6408
+ runUpdateMessageJob(job) {
6409
+ return job({
6410
+ state,
6411
+ write: () => {
6412
+ controller == null ? void 0 : controller.enqueue(structuredClone(state.message));
6413
+ }
6414
+ });
6415
+ },
6416
+ onError: handleError
6417
+ }),
6418
+ onError: handleError
6419
+ }).finally(() => {
6420
+ if (!hasErrored) {
6421
+ controller == null ? void 0 : controller.close();
6422
+ }
6423
+ });
6424
+ return createAsyncIterableStream(outputStream);
6425
+ }
6426
+
6248
6427
  // src/ui/convert-to-model-messages.ts
6249
6428
  function convertToModelMessages(messages, options) {
6250
6429
  const modelMessages = [];
@@ -6450,90 +6629,439 @@ function convertToModelMessages(messages, options) {
6450
6629
  }
6451
6630
  var convertToCoreMessages = convertToModelMessages;
6452
6631
 
6453
- // src/agent/tool-loop-agent.ts
6454
- var ToolLoopAgent = class {
6455
- constructor(settings) {
6456
- this.version = "agent-v1";
6457
- this.settings = settings;
6458
- }
6459
- /**
6460
- * The id of the agent.
6461
- */
6462
- get id() {
6463
- return this.settings.id;
6464
- }
6465
- /**
6466
- * The tools that the agent can use.
6467
- */
6468
- get tools() {
6469
- return this.settings.tools;
6470
- }
6471
- /**
6472
- * Generates an output from the agent (non-streaming).
6473
- */
6474
- async generate(options) {
6475
- var _a17;
6476
- return generateText({
6477
- ...this.settings,
6478
- stopWhen: (_a17 = this.settings.stopWhen) != null ? _a17 : stepCountIs(20),
6479
- ...options
6480
- });
6481
- }
6482
- /**
6483
- * Streams an output from the agent (streaming).
6484
- */
6485
- stream(options) {
6486
- var _a17;
6487
- return streamText({
6488
- ...this.settings,
6489
- stopWhen: (_a17 = this.settings.stopWhen) != null ? _a17 : stepCountIs(20),
6490
- ...options
6491
- });
6492
- }
6493
- /**
6494
- * Creates a response object that streams UI messages to the client.
6495
- */
6496
- respond(options) {
6497
- return this.stream({
6498
- prompt: convertToModelMessages(options.messages, { tools: this.tools })
6499
- }).toUIMessageStreamResponse();
6500
- }
6501
- };
6502
-
6503
- // src/embed/embed.ts
6504
- import { withUserAgentSuffix as withUserAgentSuffix3 } from "@ai-sdk/provider-utils";
6505
- async function embed({
6506
- model: modelArg,
6507
- value,
6508
- providerOptions,
6509
- maxRetries: maxRetriesArg,
6510
- abortSignal,
6511
- headers,
6512
- experimental_telemetry: telemetry
6513
- }) {
6514
- const model = resolveEmbeddingModel(modelArg);
6515
- const { maxRetries, retry } = prepareRetries({
6516
- maxRetries: maxRetriesArg,
6517
- abortSignal
6518
- });
6519
- const headersWithUserAgent = withUserAgentSuffix3(
6520
- headers != null ? headers : {},
6521
- `ai/${VERSION}`
6522
- );
6523
- const baseTelemetryAttributes = getBaseTelemetryAttributes({
6524
- model,
6525
- telemetry,
6526
- headers: headersWithUserAgent,
6527
- settings: { maxRetries }
6528
- });
6529
- const tracer = getTracer(telemetry);
6530
- return recordSpan({
6531
- name: "ai.embed",
6532
- attributes: selectTelemetryAttributes({
6533
- telemetry,
6534
- attributes: {
6535
- ...assembleOperationName({ operationId: "ai.embed", telemetry }),
6536
- ...baseTelemetryAttributes,
6632
+ // src/ui/validate-ui-messages.ts
6633
+ import { TypeValidationError as TypeValidationError2 } from "@ai-sdk/provider";
6634
+ import {
6635
+ lazySchema as lazySchema2,
6636
+ validateTypes as validateTypes2,
6637
+ zodSchema as zodSchema2
6638
+ } from "@ai-sdk/provider-utils";
6639
+ import { z as z8 } from "zod/v4";
6640
+ var uiMessagesSchema = lazySchema2(
6641
+ () => zodSchema2(
6642
+ z8.array(
6643
+ z8.object({
6644
+ id: z8.string(),
6645
+ role: z8.enum(["system", "user", "assistant"]),
6646
+ metadata: z8.unknown().optional(),
6647
+ parts: z8.array(
6648
+ z8.union([
6649
+ z8.object({
6650
+ type: z8.literal("text"),
6651
+ text: z8.string(),
6652
+ state: z8.enum(["streaming", "done"]).optional(),
6653
+ providerMetadata: providerMetadataSchema.optional()
6654
+ }),
6655
+ z8.object({
6656
+ type: z8.literal("reasoning"),
6657
+ text: z8.string(),
6658
+ state: z8.enum(["streaming", "done"]).optional(),
6659
+ providerMetadata: providerMetadataSchema.optional()
6660
+ }),
6661
+ z8.object({
6662
+ type: z8.literal("source-url"),
6663
+ sourceId: z8.string(),
6664
+ url: z8.string(),
6665
+ title: z8.string().optional(),
6666
+ providerMetadata: providerMetadataSchema.optional()
6667
+ }),
6668
+ z8.object({
6669
+ type: z8.literal("source-document"),
6670
+ sourceId: z8.string(),
6671
+ mediaType: z8.string(),
6672
+ title: z8.string(),
6673
+ filename: z8.string().optional(),
6674
+ providerMetadata: providerMetadataSchema.optional()
6675
+ }),
6676
+ z8.object({
6677
+ type: z8.literal("file"),
6678
+ mediaType: z8.string(),
6679
+ filename: z8.string().optional(),
6680
+ url: z8.string(),
6681
+ providerMetadata: providerMetadataSchema.optional()
6682
+ }),
6683
+ z8.object({
6684
+ type: z8.literal("step-start")
6685
+ }),
6686
+ z8.object({
6687
+ type: z8.string().startsWith("data-"),
6688
+ id: z8.string().optional(),
6689
+ data: z8.unknown()
6690
+ }),
6691
+ z8.object({
6692
+ type: z8.literal("dynamic-tool"),
6693
+ toolName: z8.string(),
6694
+ toolCallId: z8.string(),
6695
+ state: z8.literal("input-streaming"),
6696
+ input: z8.unknown().optional(),
6697
+ providerExecuted: z8.boolean().optional(),
6698
+ output: z8.never().optional(),
6699
+ errorText: z8.never().optional(),
6700
+ approval: z8.never().optional()
6701
+ }),
6702
+ z8.object({
6703
+ type: z8.literal("dynamic-tool"),
6704
+ toolName: z8.string(),
6705
+ toolCallId: z8.string(),
6706
+ state: z8.literal("input-available"),
6707
+ input: z8.unknown(),
6708
+ providerExecuted: z8.boolean().optional(),
6709
+ output: z8.never().optional(),
6710
+ errorText: z8.never().optional(),
6711
+ callProviderMetadata: providerMetadataSchema.optional(),
6712
+ approval: z8.never().optional()
6713
+ }),
6714
+ z8.object({
6715
+ type: z8.literal("dynamic-tool"),
6716
+ toolName: z8.string(),
6717
+ toolCallId: z8.string(),
6718
+ state: z8.literal("approval-requested"),
6719
+ input: z8.unknown(),
6720
+ providerExecuted: z8.boolean().optional(),
6721
+ output: z8.never().optional(),
6722
+ errorText: z8.never().optional(),
6723
+ callProviderMetadata: providerMetadataSchema.optional(),
6724
+ approval: z8.object({
6725
+ id: z8.string(),
6726
+ approved: z8.never().optional(),
6727
+ reason: z8.never().optional()
6728
+ })
6729
+ }),
6730
+ z8.object({
6731
+ type: z8.literal("dynamic-tool"),
6732
+ toolName: z8.string(),
6733
+ toolCallId: z8.string(),
6734
+ state: z8.literal("approval-responded"),
6735
+ input: z8.unknown(),
6736
+ providerExecuted: z8.boolean().optional(),
6737
+ output: z8.never().optional(),
6738
+ errorText: z8.never().optional(),
6739
+ callProviderMetadata: providerMetadataSchema.optional(),
6740
+ approval: z8.object({
6741
+ id: z8.string(),
6742
+ approved: z8.boolean(),
6743
+ reason: z8.string().optional()
6744
+ })
6745
+ }),
6746
+ z8.object({
6747
+ type: z8.literal("dynamic-tool"),
6748
+ toolName: z8.string(),
6749
+ toolCallId: z8.string(),
6750
+ state: z8.literal("output-available"),
6751
+ input: z8.unknown(),
6752
+ providerExecuted: z8.boolean().optional(),
6753
+ output: z8.unknown(),
6754
+ errorText: z8.never().optional(),
6755
+ callProviderMetadata: providerMetadataSchema.optional(),
6756
+ preliminary: z8.boolean().optional(),
6757
+ approval: z8.object({
6758
+ id: z8.string(),
6759
+ approved: z8.literal(true),
6760
+ reason: z8.string().optional()
6761
+ }).optional()
6762
+ }),
6763
+ z8.object({
6764
+ type: z8.literal("dynamic-tool"),
6765
+ toolName: z8.string(),
6766
+ toolCallId: z8.string(),
6767
+ state: z8.literal("output-error"),
6768
+ input: z8.unknown(),
6769
+ providerExecuted: z8.boolean().optional(),
6770
+ output: z8.never().optional(),
6771
+ errorText: z8.string(),
6772
+ callProviderMetadata: providerMetadataSchema.optional(),
6773
+ approval: z8.object({
6774
+ id: z8.string(),
6775
+ approved: z8.literal(true),
6776
+ reason: z8.string().optional()
6777
+ }).optional()
6778
+ }),
6779
+ z8.object({
6780
+ type: z8.literal("dynamic-tool"),
6781
+ toolName: z8.string(),
6782
+ toolCallId: z8.string(),
6783
+ state: z8.literal("output-denied"),
6784
+ input: z8.unknown(),
6785
+ providerExecuted: z8.boolean().optional(),
6786
+ output: z8.never().optional(),
6787
+ errorText: z8.never().optional(),
6788
+ callProviderMetadata: providerMetadataSchema.optional(),
6789
+ approval: z8.object({
6790
+ id: z8.string(),
6791
+ approved: z8.literal(false),
6792
+ reason: z8.string().optional()
6793
+ })
6794
+ }),
6795
+ z8.object({
6796
+ type: z8.string().startsWith("tool-"),
6797
+ toolCallId: z8.string(),
6798
+ state: z8.literal("input-streaming"),
6799
+ providerExecuted: z8.boolean().optional(),
6800
+ input: z8.unknown().optional(),
6801
+ output: z8.never().optional(),
6802
+ errorText: z8.never().optional(),
6803
+ approval: z8.never().optional()
6804
+ }),
6805
+ z8.object({
6806
+ type: z8.string().startsWith("tool-"),
6807
+ toolCallId: z8.string(),
6808
+ state: z8.literal("input-available"),
6809
+ providerExecuted: z8.boolean().optional(),
6810
+ input: z8.unknown(),
6811
+ output: z8.never().optional(),
6812
+ errorText: z8.never().optional(),
6813
+ callProviderMetadata: providerMetadataSchema.optional(),
6814
+ approval: z8.never().optional()
6815
+ }),
6816
+ z8.object({
6817
+ type: z8.string().startsWith("tool-"),
6818
+ toolCallId: z8.string(),
6819
+ state: z8.literal("approval-requested"),
6820
+ input: z8.unknown(),
6821
+ providerExecuted: z8.boolean().optional(),
6822
+ output: z8.never().optional(),
6823
+ errorText: z8.never().optional(),
6824
+ callProviderMetadata: providerMetadataSchema.optional(),
6825
+ approval: z8.object({
6826
+ id: z8.string(),
6827
+ approved: z8.never().optional(),
6828
+ reason: z8.never().optional()
6829
+ })
6830
+ }),
6831
+ z8.object({
6832
+ type: z8.string().startsWith("tool-"),
6833
+ toolCallId: z8.string(),
6834
+ state: z8.literal("approval-responded"),
6835
+ input: z8.unknown(),
6836
+ providerExecuted: z8.boolean().optional(),
6837
+ output: z8.never().optional(),
6838
+ errorText: z8.never().optional(),
6839
+ callProviderMetadata: providerMetadataSchema.optional(),
6840
+ approval: z8.object({
6841
+ id: z8.string(),
6842
+ approved: z8.boolean(),
6843
+ reason: z8.string().optional()
6844
+ })
6845
+ }),
6846
+ z8.object({
6847
+ type: z8.string().startsWith("tool-"),
6848
+ toolCallId: z8.string(),
6849
+ state: z8.literal("output-available"),
6850
+ providerExecuted: z8.boolean().optional(),
6851
+ input: z8.unknown(),
6852
+ output: z8.unknown(),
6853
+ errorText: z8.never().optional(),
6854
+ callProviderMetadata: providerMetadataSchema.optional(),
6855
+ preliminary: z8.boolean().optional(),
6856
+ approval: z8.object({
6857
+ id: z8.string(),
6858
+ approved: z8.literal(true),
6859
+ reason: z8.string().optional()
6860
+ }).optional()
6861
+ }),
6862
+ z8.object({
6863
+ type: z8.string().startsWith("tool-"),
6864
+ toolCallId: z8.string(),
6865
+ state: z8.literal("output-error"),
6866
+ providerExecuted: z8.boolean().optional(),
6867
+ input: z8.unknown(),
6868
+ output: z8.never().optional(),
6869
+ errorText: z8.string(),
6870
+ callProviderMetadata: providerMetadataSchema.optional(),
6871
+ approval: z8.object({
6872
+ id: z8.string(),
6873
+ approved: z8.literal(true),
6874
+ reason: z8.string().optional()
6875
+ }).optional()
6876
+ }),
6877
+ z8.object({
6878
+ type: z8.string().startsWith("tool-"),
6879
+ toolCallId: z8.string(),
6880
+ state: z8.literal("output-denied"),
6881
+ providerExecuted: z8.boolean().optional(),
6882
+ input: z8.unknown(),
6883
+ output: z8.never().optional(),
6884
+ errorText: z8.never().optional(),
6885
+ callProviderMetadata: providerMetadataSchema.optional(),
6886
+ approval: z8.object({
6887
+ id: z8.string(),
6888
+ approved: z8.literal(false),
6889
+ reason: z8.string().optional()
6890
+ })
6891
+ })
6892
+ ])
6893
+ )
6894
+ })
6895
+ )
6896
+ )
6897
+ );
6898
+ async function safeValidateUIMessages({
6899
+ messages,
6900
+ metadataSchema,
6901
+ dataSchemas,
6902
+ tools
6903
+ }) {
6904
+ try {
6905
+ if (messages == null) {
6906
+ return {
6907
+ success: false,
6908
+ error: new InvalidArgumentError({
6909
+ parameter: "messages",
6910
+ value: messages,
6911
+ message: "messages parameter must be provided"
6912
+ })
6913
+ };
6914
+ }
6915
+ const validatedMessages = await validateTypes2({
6916
+ value: messages,
6917
+ schema: uiMessagesSchema
6918
+ });
6919
+ if (metadataSchema) {
6920
+ for (const message of validatedMessages) {
6921
+ await validateTypes2({
6922
+ value: message.metadata,
6923
+ schema: metadataSchema
6924
+ });
6925
+ }
6926
+ }
6927
+ if (dataSchemas) {
6928
+ for (const message of validatedMessages) {
6929
+ const dataParts = message.parts.filter(
6930
+ (part) => part.type.startsWith("data-")
6931
+ );
6932
+ for (const dataPart of dataParts) {
6933
+ const dataName = dataPart.type.slice(5);
6934
+ const dataSchema = dataSchemas[dataName];
6935
+ if (!dataSchema) {
6936
+ return {
6937
+ success: false,
6938
+ error: new TypeValidationError2({
6939
+ value: dataPart.data,
6940
+ cause: `No data schema found for data part ${dataName}`
6941
+ })
6942
+ };
6943
+ }
6944
+ await validateTypes2({
6945
+ value: dataPart.data,
6946
+ schema: dataSchema
6947
+ });
6948
+ }
6949
+ }
6950
+ }
6951
+ if (tools) {
6952
+ for (const message of validatedMessages) {
6953
+ const toolParts = message.parts.filter(
6954
+ (part) => part.type.startsWith("tool-")
6955
+ );
6956
+ for (const toolPart of toolParts) {
6957
+ const toolName = toolPart.type.slice(5);
6958
+ const tool3 = tools[toolName];
6959
+ if (!tool3) {
6960
+ return {
6961
+ success: false,
6962
+ error: new TypeValidationError2({
6963
+ value: toolPart.input,
6964
+ cause: `No tool schema found for tool part ${toolName}`
6965
+ })
6966
+ };
6967
+ }
6968
+ if (toolPart.state === "input-available" || toolPart.state === "output-available" || toolPart.state === "output-error") {
6969
+ await validateTypes2({
6970
+ value: toolPart.input,
6971
+ schema: tool3.inputSchema
6972
+ });
6973
+ }
6974
+ if (toolPart.state === "output-available" && tool3.outputSchema) {
6975
+ await validateTypes2({
6976
+ value: toolPart.output,
6977
+ schema: tool3.outputSchema
6978
+ });
6979
+ }
6980
+ }
6981
+ }
6982
+ }
6983
+ return {
6984
+ success: true,
6985
+ data: validatedMessages
6986
+ };
6987
+ } catch (error) {
6988
+ const err = error;
6989
+ return {
6990
+ success: false,
6991
+ error: err
6992
+ };
6993
+ }
6994
+ }
6995
+ async function validateUIMessages({
6996
+ messages,
6997
+ metadataSchema,
6998
+ dataSchemas,
6999
+ tools
7000
+ }) {
7001
+ const response = await safeValidateUIMessages({
7002
+ messages,
7003
+ metadataSchema,
7004
+ dataSchemas,
7005
+ tools
7006
+ });
7007
+ if (!response.success)
7008
+ throw response.error;
7009
+ return response.data;
7010
+ }
7011
+
7012
+ // src/agent/create-agent-stream-response.ts
7013
+ async function createAgentStreamResponse({
7014
+ agent,
7015
+ messages,
7016
+ ...options
7017
+ }) {
7018
+ const validatedMessages = await validateUIMessages({
7019
+ messages,
7020
+ tools: agent.tools
7021
+ });
7022
+ const modelMessages = convertToModelMessages(validatedMessages, {
7023
+ tools: agent.tools
7024
+ });
7025
+ const result = agent.stream({ prompt: modelMessages });
7026
+ return createUIMessageStreamResponse({
7027
+ stream: result.toUIMessageStream(options)
7028
+ });
7029
+ }
7030
+
7031
+ // src/embed/embed.ts
7032
+ import { withUserAgentSuffix as withUserAgentSuffix3 } from "@ai-sdk/provider-utils";
7033
+ async function embed({
7034
+ model: modelArg,
7035
+ value,
7036
+ providerOptions,
7037
+ maxRetries: maxRetriesArg,
7038
+ abortSignal,
7039
+ headers,
7040
+ experimental_telemetry: telemetry
7041
+ }) {
7042
+ const model = resolveEmbeddingModel(modelArg);
7043
+ const { maxRetries, retry } = prepareRetries({
7044
+ maxRetries: maxRetriesArg,
7045
+ abortSignal
7046
+ });
7047
+ const headersWithUserAgent = withUserAgentSuffix3(
7048
+ headers != null ? headers : {},
7049
+ `ai/${VERSION}`
7050
+ );
7051
+ const baseTelemetryAttributes = getBaseTelemetryAttributes({
7052
+ model,
7053
+ telemetry,
7054
+ headers: headersWithUserAgent,
7055
+ settings: { maxRetries }
7056
+ });
7057
+ const tracer = getTracer(telemetry);
7058
+ return recordSpan({
7059
+ name: "ai.embed",
7060
+ attributes: selectTelemetryAttributes({
7061
+ telemetry,
7062
+ attributes: {
7063
+ ...assembleOperationName({ operationId: "ai.embed", telemetry }),
7064
+ ...baseTelemetryAttributes,
6537
7065
  "ai.value": { input: () => JSON.stringify(value) }
6538
7066
  }
6539
7067
  }),
@@ -7004,7 +7532,7 @@ function extractReasoningContent(content) {
7004
7532
  import {
7005
7533
  isJSONArray,
7006
7534
  isJSONObject,
7007
- TypeValidationError as TypeValidationError2,
7535
+ TypeValidationError as TypeValidationError3,
7008
7536
  UnsupportedFunctionalityError as UnsupportedFunctionalityError2
7009
7537
  } from "@ai-sdk/provider";
7010
7538
  import {
@@ -7085,7 +7613,7 @@ var arrayOutputStrategy = (schema) => {
7085
7613
  if (!isJSONObject(value) || !isJSONArray(value.elements)) {
7086
7614
  return {
7087
7615
  success: false,
7088
- error: new TypeValidationError2({
7616
+ error: new TypeValidationError3({
7089
7617
  value,
7090
7618
  cause: "value must be an object that contains an array of elements"
7091
7619
  })
@@ -7128,7 +7656,7 @@ var arrayOutputStrategy = (schema) => {
7128
7656
  if (!isJSONObject(value) || !isJSONArray(value.elements)) {
7129
7657
  return {
7130
7658
  success: false,
7131
- error: new TypeValidationError2({
7659
+ error: new TypeValidationError3({
7132
7660
  value,
7133
7661
  cause: "value must be an object that contains an array of elements"
7134
7662
  })
@@ -7194,7 +7722,7 @@ var enumOutputStrategy = (enumValues) => {
7194
7722
  if (!isJSONObject(value) || typeof value.result !== "string") {
7195
7723
  return {
7196
7724
  success: false,
7197
- error: new TypeValidationError2({
7725
+ error: new TypeValidationError3({
7198
7726
  value,
7199
7727
  cause: 'value must be an object that contains a string in the "result" property.'
7200
7728
  })
@@ -7203,7 +7731,7 @@ var enumOutputStrategy = (enumValues) => {
7203
7731
  const result = value.result;
7204
7732
  return enumValues.includes(result) ? { success: true, value: result } : {
7205
7733
  success: false,
7206
- error: new TypeValidationError2({
7734
+ error: new TypeValidationError3({
7207
7735
  value,
7208
7736
  cause: "value must be a string in the enum"
7209
7737
  })
@@ -7213,7 +7741,7 @@ var enumOutputStrategy = (enumValues) => {
7213
7741
  if (!isJSONObject(value) || typeof value.result !== "string") {
7214
7742
  return {
7215
7743
  success: false,
7216
- error: new TypeValidationError2({
7744
+ error: new TypeValidationError3({
7217
7745
  value,
7218
7746
  cause: 'value must be an object that contains a string in the "result" property.'
7219
7747
  })
@@ -7226,7 +7754,7 @@ var enumOutputStrategy = (enumValues) => {
7226
7754
  if (value.result.length === 0 || possibleEnumValues.length === 0) {
7227
7755
  return {
7228
7756
  success: false,
7229
- error: new TypeValidationError2({
7757
+ error: new TypeValidationError3({
7230
7758
  value,
7231
7759
  cause: "value must be a string in the enum"
7232
7760
  })
@@ -7269,7 +7797,7 @@ function getOutputStrategy({
7269
7797
  }
7270
7798
 
7271
7799
  // src/generate-object/parse-and-validate-object-result.ts
7272
- import { JSONParseError as JSONParseError2, TypeValidationError as TypeValidationError3 } from "@ai-sdk/provider";
7800
+ import { JSONParseError as JSONParseError2, TypeValidationError as TypeValidationError4 } from "@ai-sdk/provider";
7273
7801
  import { safeParseJSON as safeParseJSON3 } from "@ai-sdk/provider-utils";
7274
7802
  async function parseAndValidateObjectResult(result, outputStrategy, context) {
7275
7803
  const parseResult = await safeParseJSON3({ text: result });
@@ -7307,7 +7835,7 @@ async function parseAndValidateObjectResultWithRepair(result, outputStrategy, re
7307
7835
  try {
7308
7836
  return await parseAndValidateObjectResult(result, outputStrategy, context);
7309
7837
  } catch (error) {
7310
- if (repairText != null && NoObjectGeneratedError.isInstance(error) && (JSONParseError2.isInstance(error.cause) || TypeValidationError3.isInstance(error.cause))) {
7838
+ if (repairText != null && NoObjectGeneratedError.isInstance(error) && (JSONParseError2.isInstance(error.cause) || TypeValidationError4.isInstance(error.cause))) {
7311
7839
  const repairedText = await repairText({
7312
7840
  text: result,
7313
7841
  error: error.cause
@@ -9248,137 +9776,137 @@ import {
9248
9776
  } from "@ai-sdk/provider-utils";
9249
9777
 
9250
9778
  // src/tool/mcp/json-rpc-message.ts
9251
- import { z as z9 } from "zod/v4";
9779
+ import { z as z10 } from "zod/v4";
9252
9780
 
9253
9781
  // src/tool/mcp/types.ts
9254
- import { z as z8 } from "zod/v4";
9782
+ import { z as z9 } from "zod/v4";
9255
9783
  var LATEST_PROTOCOL_VERSION = "2025-06-18";
9256
9784
  var SUPPORTED_PROTOCOL_VERSIONS = [
9257
9785
  LATEST_PROTOCOL_VERSION,
9258
9786
  "2025-03-26",
9259
9787
  "2024-11-05"
9260
9788
  ];
9261
- var ClientOrServerImplementationSchema = z8.looseObject({
9262
- name: z8.string(),
9263
- version: z8.string()
9789
+ var ClientOrServerImplementationSchema = z9.looseObject({
9790
+ name: z9.string(),
9791
+ version: z9.string()
9264
9792
  });
9265
- var BaseParamsSchema = z8.looseObject({
9266
- _meta: z8.optional(z8.object({}).loose())
9793
+ var BaseParamsSchema = z9.looseObject({
9794
+ _meta: z9.optional(z9.object({}).loose())
9267
9795
  });
9268
9796
  var ResultSchema = BaseParamsSchema;
9269
- var RequestSchema = z8.object({
9270
- method: z8.string(),
9271
- params: z8.optional(BaseParamsSchema)
9797
+ var RequestSchema = z9.object({
9798
+ method: z9.string(),
9799
+ params: z9.optional(BaseParamsSchema)
9272
9800
  });
9273
- var ServerCapabilitiesSchema = z8.looseObject({
9274
- experimental: z8.optional(z8.object({}).loose()),
9275
- logging: z8.optional(z8.object({}).loose()),
9276
- prompts: z8.optional(
9277
- z8.looseObject({
9278
- listChanged: z8.optional(z8.boolean())
9801
+ var ServerCapabilitiesSchema = z9.looseObject({
9802
+ experimental: z9.optional(z9.object({}).loose()),
9803
+ logging: z9.optional(z9.object({}).loose()),
9804
+ prompts: z9.optional(
9805
+ z9.looseObject({
9806
+ listChanged: z9.optional(z9.boolean())
9279
9807
  })
9280
9808
  ),
9281
- resources: z8.optional(
9282
- z8.looseObject({
9283
- subscribe: z8.optional(z8.boolean()),
9284
- listChanged: z8.optional(z8.boolean())
9809
+ resources: z9.optional(
9810
+ z9.looseObject({
9811
+ subscribe: z9.optional(z9.boolean()),
9812
+ listChanged: z9.optional(z9.boolean())
9285
9813
  })
9286
9814
  ),
9287
- tools: z8.optional(
9288
- z8.looseObject({
9289
- listChanged: z8.optional(z8.boolean())
9815
+ tools: z9.optional(
9816
+ z9.looseObject({
9817
+ listChanged: z9.optional(z9.boolean())
9290
9818
  })
9291
9819
  )
9292
9820
  });
9293
9821
  var InitializeResultSchema = ResultSchema.extend({
9294
- protocolVersion: z8.string(),
9822
+ protocolVersion: z9.string(),
9295
9823
  capabilities: ServerCapabilitiesSchema,
9296
9824
  serverInfo: ClientOrServerImplementationSchema,
9297
- instructions: z8.optional(z8.string())
9825
+ instructions: z9.optional(z9.string())
9298
9826
  });
9299
9827
  var PaginatedResultSchema = ResultSchema.extend({
9300
- nextCursor: z8.optional(z8.string())
9828
+ nextCursor: z9.optional(z9.string())
9301
9829
  });
9302
- var ToolSchema = z8.object({
9303
- name: z8.string(),
9304
- description: z8.optional(z8.string()),
9305
- inputSchema: z8.object({
9306
- type: z8.literal("object"),
9307
- properties: z8.optional(z8.object({}).loose())
9830
+ var ToolSchema = z9.object({
9831
+ name: z9.string(),
9832
+ description: z9.optional(z9.string()),
9833
+ inputSchema: z9.object({
9834
+ type: z9.literal("object"),
9835
+ properties: z9.optional(z9.object({}).loose())
9308
9836
  }).loose()
9309
9837
  }).loose();
9310
9838
  var ListToolsResultSchema = PaginatedResultSchema.extend({
9311
- tools: z8.array(ToolSchema)
9839
+ tools: z9.array(ToolSchema)
9312
9840
  });
9313
- var TextContentSchema = z8.object({
9314
- type: z8.literal("text"),
9315
- text: z8.string()
9841
+ var TextContentSchema = z9.object({
9842
+ type: z9.literal("text"),
9843
+ text: z9.string()
9316
9844
  }).loose();
9317
- var ImageContentSchema = z8.object({
9318
- type: z8.literal("image"),
9319
- data: z8.base64(),
9320
- mimeType: z8.string()
9845
+ var ImageContentSchema = z9.object({
9846
+ type: z9.literal("image"),
9847
+ data: z9.base64(),
9848
+ mimeType: z9.string()
9321
9849
  }).loose();
9322
- var ResourceContentsSchema = z8.object({
9850
+ var ResourceContentsSchema = z9.object({
9323
9851
  /**
9324
9852
  * The URI of this resource.
9325
9853
  */
9326
- uri: z8.string(),
9854
+ uri: z9.string(),
9327
9855
  /**
9328
9856
  * The MIME type of this resource, if known.
9329
9857
  */
9330
- mimeType: z8.optional(z8.string())
9858
+ mimeType: z9.optional(z9.string())
9331
9859
  }).loose();
9332
9860
  var TextResourceContentsSchema = ResourceContentsSchema.extend({
9333
- text: z8.string()
9861
+ text: z9.string()
9334
9862
  });
9335
9863
  var BlobResourceContentsSchema = ResourceContentsSchema.extend({
9336
- blob: z8.base64()
9864
+ blob: z9.base64()
9337
9865
  });
9338
- var EmbeddedResourceSchema = z8.object({
9339
- type: z8.literal("resource"),
9340
- resource: z8.union([TextResourceContentsSchema, BlobResourceContentsSchema])
9866
+ var EmbeddedResourceSchema = z9.object({
9867
+ type: z9.literal("resource"),
9868
+ resource: z9.union([TextResourceContentsSchema, BlobResourceContentsSchema])
9341
9869
  }).loose();
9342
9870
  var CallToolResultSchema = ResultSchema.extend({
9343
- content: z8.array(
9344
- z8.union([TextContentSchema, ImageContentSchema, EmbeddedResourceSchema])
9871
+ content: z9.array(
9872
+ z9.union([TextContentSchema, ImageContentSchema, EmbeddedResourceSchema])
9345
9873
  ),
9346
- isError: z8.boolean().default(false).optional()
9874
+ isError: z9.boolean().default(false).optional()
9347
9875
  }).or(
9348
9876
  ResultSchema.extend({
9349
- toolResult: z8.unknown()
9877
+ toolResult: z9.unknown()
9350
9878
  })
9351
9879
  );
9352
9880
 
9353
9881
  // src/tool/mcp/json-rpc-message.ts
9354
9882
  var JSONRPC_VERSION = "2.0";
9355
- var JSONRPCRequestSchema = z9.object({
9356
- jsonrpc: z9.literal(JSONRPC_VERSION),
9357
- id: z9.union([z9.string(), z9.number().int()])
9883
+ var JSONRPCRequestSchema = z10.object({
9884
+ jsonrpc: z10.literal(JSONRPC_VERSION),
9885
+ id: z10.union([z10.string(), z10.number().int()])
9358
9886
  }).merge(RequestSchema).strict();
9359
- var JSONRPCResponseSchema = z9.object({
9360
- jsonrpc: z9.literal(JSONRPC_VERSION),
9361
- id: z9.union([z9.string(), z9.number().int()]),
9887
+ var JSONRPCResponseSchema = z10.object({
9888
+ jsonrpc: z10.literal(JSONRPC_VERSION),
9889
+ id: z10.union([z10.string(), z10.number().int()]),
9362
9890
  result: ResultSchema
9363
9891
  }).strict();
9364
- var JSONRPCErrorSchema = z9.object({
9365
- jsonrpc: z9.literal(JSONRPC_VERSION),
9366
- id: z9.union([z9.string(), z9.number().int()]),
9367
- error: z9.object({
9368
- code: z9.number().int(),
9369
- message: z9.string(),
9370
- data: z9.optional(z9.unknown())
9892
+ var JSONRPCErrorSchema = z10.object({
9893
+ jsonrpc: z10.literal(JSONRPC_VERSION),
9894
+ id: z10.union([z10.string(), z10.number().int()]),
9895
+ error: z10.object({
9896
+ code: z10.number().int(),
9897
+ message: z10.string(),
9898
+ data: z10.optional(z10.unknown())
9371
9899
  })
9372
9900
  }).strict();
9373
- var JSONRPCNotificationSchema = z9.object({
9374
- jsonrpc: z9.literal(JSONRPC_VERSION)
9901
+ var JSONRPCNotificationSchema = z10.object({
9902
+ jsonrpc: z10.literal(JSONRPC_VERSION)
9375
9903
  }).merge(
9376
- z9.object({
9377
- method: z9.string(),
9378
- params: z9.optional(BaseParamsSchema)
9904
+ z10.object({
9905
+ method: z10.string(),
9906
+ params: z10.optional(BaseParamsSchema)
9379
9907
  })
9380
9908
  ).strict();
9381
- var JSONRPCMessageSchema = z9.union([
9909
+ var JSONRPCMessageSchema = z10.union([
9382
9910
  JSONRPCRequestSchema,
9383
9911
  JSONRPCNotificationSchema,
9384
9912
  JSONRPCResponseSchema,
@@ -10037,7 +10565,7 @@ async function callCompletionApi({
10037
10565
 
10038
10566
  // src/ui/chat.ts
10039
10567
  import {
10040
- generateId as generateIdFunc
10568
+ generateId as generateIdFunc2
10041
10569
  } from "@ai-sdk/provider-utils";
10042
10570
 
10043
10571
  // src/ui/convert-file-list-to-file-ui-parts.ts
@@ -10218,7 +10746,7 @@ var DefaultChatTransport = class extends HttpChatTransport {
10218
10746
  // src/ui/chat.ts
10219
10747
  var AbstractChat = class {
10220
10748
  constructor({
10221
- generateId: generateId2 = generateIdFunc,
10749
+ generateId: generateId2 = generateIdFunc2,
10222
10750
  id = generateId2(),
10223
10751
  transport = new DefaultChatTransport(),
10224
10752
  messageMetadataSchema,
@@ -10644,523 +11172,6 @@ var TextStreamChatTransport = class extends HttpChatTransport {
10644
11172
  });
10645
11173
  }
10646
11174
  };
10647
-
10648
- // src/ui/validate-ui-messages.ts
10649
- import { TypeValidationError as TypeValidationError4 } from "@ai-sdk/provider";
10650
- import {
10651
- lazySchema as lazySchema2,
10652
- validateTypes as validateTypes2,
10653
- zodSchema as zodSchema2
10654
- } from "@ai-sdk/provider-utils";
10655
- import { z as z10 } from "zod/v4";
10656
- var uiMessagesSchema = lazySchema2(
10657
- () => zodSchema2(
10658
- z10.array(
10659
- z10.object({
10660
- id: z10.string(),
10661
- role: z10.enum(["system", "user", "assistant"]),
10662
- metadata: z10.unknown().optional(),
10663
- parts: z10.array(
10664
- z10.union([
10665
- z10.object({
10666
- type: z10.literal("text"),
10667
- text: z10.string(),
10668
- state: z10.enum(["streaming", "done"]).optional(),
10669
- providerMetadata: providerMetadataSchema.optional()
10670
- }),
10671
- z10.object({
10672
- type: z10.literal("reasoning"),
10673
- text: z10.string(),
10674
- state: z10.enum(["streaming", "done"]).optional(),
10675
- providerMetadata: providerMetadataSchema.optional()
10676
- }),
10677
- z10.object({
10678
- type: z10.literal("source-url"),
10679
- sourceId: z10.string(),
10680
- url: z10.string(),
10681
- title: z10.string().optional(),
10682
- providerMetadata: providerMetadataSchema.optional()
10683
- }),
10684
- z10.object({
10685
- type: z10.literal("source-document"),
10686
- sourceId: z10.string(),
10687
- mediaType: z10.string(),
10688
- title: z10.string(),
10689
- filename: z10.string().optional(),
10690
- providerMetadata: providerMetadataSchema.optional()
10691
- }),
10692
- z10.object({
10693
- type: z10.literal("file"),
10694
- mediaType: z10.string(),
10695
- filename: z10.string().optional(),
10696
- url: z10.string(),
10697
- providerMetadata: providerMetadataSchema.optional()
10698
- }),
10699
- z10.object({
10700
- type: z10.literal("step-start")
10701
- }),
10702
- z10.object({
10703
- type: z10.string().startsWith("data-"),
10704
- id: z10.string().optional(),
10705
- data: z10.unknown()
10706
- }),
10707
- z10.object({
10708
- type: z10.literal("dynamic-tool"),
10709
- toolName: z10.string(),
10710
- toolCallId: z10.string(),
10711
- state: z10.literal("input-streaming"),
10712
- input: z10.unknown().optional(),
10713
- providerExecuted: z10.boolean().optional(),
10714
- output: z10.never().optional(),
10715
- errorText: z10.never().optional(),
10716
- approval: z10.never().optional()
10717
- }),
10718
- z10.object({
10719
- type: z10.literal("dynamic-tool"),
10720
- toolName: z10.string(),
10721
- toolCallId: z10.string(),
10722
- state: z10.literal("input-available"),
10723
- input: z10.unknown(),
10724
- providerExecuted: z10.boolean().optional(),
10725
- output: z10.never().optional(),
10726
- errorText: z10.never().optional(),
10727
- callProviderMetadata: providerMetadataSchema.optional(),
10728
- approval: z10.never().optional()
10729
- }),
10730
- z10.object({
10731
- type: z10.literal("dynamic-tool"),
10732
- toolName: z10.string(),
10733
- toolCallId: z10.string(),
10734
- state: z10.literal("approval-requested"),
10735
- input: z10.unknown(),
10736
- providerExecuted: z10.boolean().optional(),
10737
- output: z10.never().optional(),
10738
- errorText: z10.never().optional(),
10739
- callProviderMetadata: providerMetadataSchema.optional(),
10740
- approval: z10.object({
10741
- id: z10.string(),
10742
- approved: z10.never().optional(),
10743
- reason: z10.never().optional()
10744
- })
10745
- }),
10746
- z10.object({
10747
- type: z10.literal("dynamic-tool"),
10748
- toolName: z10.string(),
10749
- toolCallId: z10.string(),
10750
- state: z10.literal("approval-responded"),
10751
- input: z10.unknown(),
10752
- providerExecuted: z10.boolean().optional(),
10753
- output: z10.never().optional(),
10754
- errorText: z10.never().optional(),
10755
- callProviderMetadata: providerMetadataSchema.optional(),
10756
- approval: z10.object({
10757
- id: z10.string(),
10758
- approved: z10.boolean(),
10759
- reason: z10.string().optional()
10760
- })
10761
- }),
10762
- z10.object({
10763
- type: z10.literal("dynamic-tool"),
10764
- toolName: z10.string(),
10765
- toolCallId: z10.string(),
10766
- state: z10.literal("output-available"),
10767
- input: z10.unknown(),
10768
- providerExecuted: z10.boolean().optional(),
10769
- output: z10.unknown(),
10770
- errorText: z10.never().optional(),
10771
- callProviderMetadata: providerMetadataSchema.optional(),
10772
- preliminary: z10.boolean().optional(),
10773
- approval: z10.object({
10774
- id: z10.string(),
10775
- approved: z10.literal(true),
10776
- reason: z10.string().optional()
10777
- }).optional()
10778
- }),
10779
- z10.object({
10780
- type: z10.literal("dynamic-tool"),
10781
- toolName: z10.string(),
10782
- toolCallId: z10.string(),
10783
- state: z10.literal("output-error"),
10784
- input: z10.unknown(),
10785
- providerExecuted: z10.boolean().optional(),
10786
- output: z10.never().optional(),
10787
- errorText: z10.string(),
10788
- callProviderMetadata: providerMetadataSchema.optional(),
10789
- approval: z10.object({
10790
- id: z10.string(),
10791
- approved: z10.literal(true),
10792
- reason: z10.string().optional()
10793
- }).optional()
10794
- }),
10795
- z10.object({
10796
- type: z10.literal("dynamic-tool"),
10797
- toolName: z10.string(),
10798
- toolCallId: z10.string(),
10799
- state: z10.literal("output-denied"),
10800
- input: z10.unknown(),
10801
- providerExecuted: z10.boolean().optional(),
10802
- output: z10.never().optional(),
10803
- errorText: z10.never().optional(),
10804
- callProviderMetadata: providerMetadataSchema.optional(),
10805
- approval: z10.object({
10806
- id: z10.string(),
10807
- approved: z10.literal(false),
10808
- reason: z10.string().optional()
10809
- })
10810
- }),
10811
- z10.object({
10812
- type: z10.string().startsWith("tool-"),
10813
- toolCallId: z10.string(),
10814
- state: z10.literal("input-streaming"),
10815
- providerExecuted: z10.boolean().optional(),
10816
- input: z10.unknown().optional(),
10817
- output: z10.never().optional(),
10818
- errorText: z10.never().optional(),
10819
- approval: z10.never().optional()
10820
- }),
10821
- z10.object({
10822
- type: z10.string().startsWith("tool-"),
10823
- toolCallId: z10.string(),
10824
- state: z10.literal("input-available"),
10825
- providerExecuted: z10.boolean().optional(),
10826
- input: z10.unknown(),
10827
- output: z10.never().optional(),
10828
- errorText: z10.never().optional(),
10829
- callProviderMetadata: providerMetadataSchema.optional(),
10830
- approval: z10.never().optional()
10831
- }),
10832
- z10.object({
10833
- type: z10.string().startsWith("tool-"),
10834
- toolCallId: z10.string(),
10835
- state: z10.literal("approval-requested"),
10836
- input: z10.unknown(),
10837
- providerExecuted: z10.boolean().optional(),
10838
- output: z10.never().optional(),
10839
- errorText: z10.never().optional(),
10840
- callProviderMetadata: providerMetadataSchema.optional(),
10841
- approval: z10.object({
10842
- id: z10.string(),
10843
- approved: z10.never().optional(),
10844
- reason: z10.never().optional()
10845
- })
10846
- }),
10847
- z10.object({
10848
- type: z10.string().startsWith("tool-"),
10849
- toolCallId: z10.string(),
10850
- state: z10.literal("approval-responded"),
10851
- input: z10.unknown(),
10852
- providerExecuted: z10.boolean().optional(),
10853
- output: z10.never().optional(),
10854
- errorText: z10.never().optional(),
10855
- callProviderMetadata: providerMetadataSchema.optional(),
10856
- approval: z10.object({
10857
- id: z10.string(),
10858
- approved: z10.boolean(),
10859
- reason: z10.string().optional()
10860
- })
10861
- }),
10862
- z10.object({
10863
- type: z10.string().startsWith("tool-"),
10864
- toolCallId: z10.string(),
10865
- state: z10.literal("output-available"),
10866
- providerExecuted: z10.boolean().optional(),
10867
- input: z10.unknown(),
10868
- output: z10.unknown(),
10869
- errorText: z10.never().optional(),
10870
- callProviderMetadata: providerMetadataSchema.optional(),
10871
- preliminary: z10.boolean().optional(),
10872
- approval: z10.object({
10873
- id: z10.string(),
10874
- approved: z10.literal(true),
10875
- reason: z10.string().optional()
10876
- }).optional()
10877
- }),
10878
- z10.object({
10879
- type: z10.string().startsWith("tool-"),
10880
- toolCallId: z10.string(),
10881
- state: z10.literal("output-error"),
10882
- providerExecuted: z10.boolean().optional(),
10883
- input: z10.unknown(),
10884
- output: z10.never().optional(),
10885
- errorText: z10.string(),
10886
- callProviderMetadata: providerMetadataSchema.optional(),
10887
- approval: z10.object({
10888
- id: z10.string(),
10889
- approved: z10.literal(true),
10890
- reason: z10.string().optional()
10891
- }).optional()
10892
- }),
10893
- z10.object({
10894
- type: z10.string().startsWith("tool-"),
10895
- toolCallId: z10.string(),
10896
- state: z10.literal("output-denied"),
10897
- providerExecuted: z10.boolean().optional(),
10898
- input: z10.unknown(),
10899
- output: z10.never().optional(),
10900
- errorText: z10.never().optional(),
10901
- callProviderMetadata: providerMetadataSchema.optional(),
10902
- approval: z10.object({
10903
- id: z10.string(),
10904
- approved: z10.literal(false),
10905
- reason: z10.string().optional()
10906
- })
10907
- })
10908
- ])
10909
- )
10910
- })
10911
- )
10912
- )
10913
- );
10914
- async function safeValidateUIMessages({
10915
- messages,
10916
- metadataSchema,
10917
- dataSchemas,
10918
- tools
10919
- }) {
10920
- try {
10921
- if (messages == null) {
10922
- return {
10923
- success: false,
10924
- error: new InvalidArgumentError({
10925
- parameter: "messages",
10926
- value: messages,
10927
- message: "messages parameter must be provided"
10928
- })
10929
- };
10930
- }
10931
- const validatedMessages = await validateTypes2({
10932
- value: messages,
10933
- schema: uiMessagesSchema
10934
- });
10935
- if (metadataSchema) {
10936
- for (const message of validatedMessages) {
10937
- await validateTypes2({
10938
- value: message.metadata,
10939
- schema: metadataSchema
10940
- });
10941
- }
10942
- }
10943
- if (dataSchemas) {
10944
- for (const message of validatedMessages) {
10945
- const dataParts = message.parts.filter(
10946
- (part) => part.type.startsWith("data-")
10947
- );
10948
- for (const dataPart of dataParts) {
10949
- const dataName = dataPart.type.slice(5);
10950
- const dataSchema = dataSchemas[dataName];
10951
- if (!dataSchema) {
10952
- return {
10953
- success: false,
10954
- error: new TypeValidationError4({
10955
- value: dataPart.data,
10956
- cause: `No data schema found for data part ${dataName}`
10957
- })
10958
- };
10959
- }
10960
- await validateTypes2({
10961
- value: dataPart.data,
10962
- schema: dataSchema
10963
- });
10964
- }
10965
- }
10966
- }
10967
- if (tools) {
10968
- for (const message of validatedMessages) {
10969
- const toolParts = message.parts.filter(
10970
- (part) => part.type.startsWith("tool-")
10971
- );
10972
- for (const toolPart of toolParts) {
10973
- const toolName = toolPart.type.slice(5);
10974
- const tool3 = tools[toolName];
10975
- if (!tool3) {
10976
- return {
10977
- success: false,
10978
- error: new TypeValidationError4({
10979
- value: toolPart.input,
10980
- cause: `No tool schema found for tool part ${toolName}`
10981
- })
10982
- };
10983
- }
10984
- if (toolPart.state === "input-available" || toolPart.state === "output-available" || toolPart.state === "output-error") {
10985
- await validateTypes2({
10986
- value: toolPart.input,
10987
- schema: tool3.inputSchema
10988
- });
10989
- }
10990
- if (toolPart.state === "output-available" && tool3.outputSchema) {
10991
- await validateTypes2({
10992
- value: toolPart.output,
10993
- schema: tool3.outputSchema
10994
- });
10995
- }
10996
- }
10997
- }
10998
- }
10999
- return {
11000
- success: true,
11001
- data: validatedMessages
11002
- };
11003
- } catch (error) {
11004
- const err = error;
11005
- return {
11006
- success: false,
11007
- error: err
11008
- };
11009
- }
11010
- }
11011
- async function validateUIMessages({
11012
- messages,
11013
- metadataSchema,
11014
- dataSchemas,
11015
- tools
11016
- }) {
11017
- const response = await safeValidateUIMessages({
11018
- messages,
11019
- metadataSchema,
11020
- dataSchemas,
11021
- tools
11022
- });
11023
- if (!response.success)
11024
- throw response.error;
11025
- return response.data;
11026
- }
11027
-
11028
- // src/ui-message-stream/create-ui-message-stream.ts
11029
- import {
11030
- generateId as generateIdFunc2,
11031
- getErrorMessage as getErrorMessage8
11032
- } from "@ai-sdk/provider-utils";
11033
- function createUIMessageStream({
11034
- execute,
11035
- onError = getErrorMessage8,
11036
- originalMessages,
11037
- onFinish,
11038
- generateId: generateId2 = generateIdFunc2
11039
- }) {
11040
- let controller;
11041
- const ongoingStreamPromises = [];
11042
- const stream = new ReadableStream({
11043
- start(controllerArg) {
11044
- controller = controllerArg;
11045
- }
11046
- });
11047
- function safeEnqueue(data) {
11048
- try {
11049
- controller.enqueue(data);
11050
- } catch (error) {
11051
- }
11052
- }
11053
- try {
11054
- const result = execute({
11055
- writer: {
11056
- write(part) {
11057
- safeEnqueue(part);
11058
- },
11059
- merge(streamArg) {
11060
- ongoingStreamPromises.push(
11061
- (async () => {
11062
- const reader = streamArg.getReader();
11063
- while (true) {
11064
- const { done, value } = await reader.read();
11065
- if (done)
11066
- break;
11067
- safeEnqueue(value);
11068
- }
11069
- })().catch((error) => {
11070
- safeEnqueue({
11071
- type: "error",
11072
- errorText: onError(error)
11073
- });
11074
- })
11075
- );
11076
- },
11077
- onError
11078
- }
11079
- });
11080
- if (result) {
11081
- ongoingStreamPromises.push(
11082
- result.catch((error) => {
11083
- safeEnqueue({
11084
- type: "error",
11085
- errorText: onError(error)
11086
- });
11087
- })
11088
- );
11089
- }
11090
- } catch (error) {
11091
- safeEnqueue({
11092
- type: "error",
11093
- errorText: onError(error)
11094
- });
11095
- }
11096
- const waitForStreams = new Promise(async (resolve3) => {
11097
- while (ongoingStreamPromises.length > 0) {
11098
- await ongoingStreamPromises.shift();
11099
- }
11100
- resolve3();
11101
- });
11102
- waitForStreams.finally(() => {
11103
- try {
11104
- controller.close();
11105
- } catch (error) {
11106
- }
11107
- });
11108
- return handleUIMessageStreamFinish({
11109
- stream,
11110
- messageId: generateId2(),
11111
- originalMessages,
11112
- onFinish,
11113
- onError
11114
- });
11115
- }
11116
-
11117
- // src/ui-message-stream/read-ui-message-stream.ts
11118
- function readUIMessageStream({
11119
- message,
11120
- stream,
11121
- onError,
11122
- terminateOnError = false
11123
- }) {
11124
- var _a17;
11125
- let controller;
11126
- let hasErrored = false;
11127
- const outputStream = new ReadableStream({
11128
- start(controllerParam) {
11129
- controller = controllerParam;
11130
- }
11131
- });
11132
- const state = createStreamingUIMessageState({
11133
- messageId: (_a17 = message == null ? void 0 : message.id) != null ? _a17 : "",
11134
- lastMessage: message
11135
- });
11136
- const handleError = (error) => {
11137
- onError == null ? void 0 : onError(error);
11138
- if (!hasErrored && terminateOnError) {
11139
- hasErrored = true;
11140
- controller == null ? void 0 : controller.error(error);
11141
- }
11142
- };
11143
- consumeStream({
11144
- stream: processUIMessageStream({
11145
- stream,
11146
- runUpdateMessageJob(job) {
11147
- return job({
11148
- state,
11149
- write: () => {
11150
- controller == null ? void 0 : controller.enqueue(structuredClone(state.message));
11151
- }
11152
- });
11153
- },
11154
- onError: handleError
11155
- }),
11156
- onError: handleError
11157
- }).finally(() => {
11158
- if (!hasErrored) {
11159
- controller == null ? void 0 : controller.close();
11160
- }
11161
- });
11162
- return createAsyncIterableStream(outputStream);
11163
- }
11164
11175
  export {
11165
11176
  AISDKError18 as AISDKError,
11166
11177
  APICallError,
@@ -11216,6 +11227,7 @@ export {
11216
11227
  coreToolMessageSchema,
11217
11228
  coreUserMessageSchema,
11218
11229
  cosineSimilarity,
11230
+ createAgentStreamResponse,
11219
11231
  createGateway,
11220
11232
  createIdGenerator5 as createIdGenerator,
11221
11233
  createProviderRegistry,