ai 6.0.0-beta.58 → 6.0.0-beta.59

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.59" : "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,438 @@ 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
+ }) {
7017
+ const validatedMessages = await validateUIMessages({
7018
+ messages,
7019
+ tools: agent.tools
7020
+ });
7021
+ const modelMessages = convertToModelMessages(validatedMessages, {
7022
+ tools: agent.tools
7023
+ });
7024
+ const result = agent.stream({ prompt: modelMessages });
7025
+ return createUIMessageStreamResponse({
7026
+ stream: result.toUIMessageStream()
7027
+ });
7028
+ }
7029
+
7030
+ // src/embed/embed.ts
7031
+ import { withUserAgentSuffix as withUserAgentSuffix3 } from "@ai-sdk/provider-utils";
7032
+ async function embed({
7033
+ model: modelArg,
7034
+ value,
7035
+ providerOptions,
7036
+ maxRetries: maxRetriesArg,
7037
+ abortSignal,
7038
+ headers,
7039
+ experimental_telemetry: telemetry
7040
+ }) {
7041
+ const model = resolveEmbeddingModel(modelArg);
7042
+ const { maxRetries, retry } = prepareRetries({
7043
+ maxRetries: maxRetriesArg,
7044
+ abortSignal
7045
+ });
7046
+ const headersWithUserAgent = withUserAgentSuffix3(
7047
+ headers != null ? headers : {},
7048
+ `ai/${VERSION}`
7049
+ );
7050
+ const baseTelemetryAttributes = getBaseTelemetryAttributes({
7051
+ model,
7052
+ telemetry,
7053
+ headers: headersWithUserAgent,
7054
+ settings: { maxRetries }
7055
+ });
7056
+ const tracer = getTracer(telemetry);
7057
+ return recordSpan({
7058
+ name: "ai.embed",
7059
+ attributes: selectTelemetryAttributes({
7060
+ telemetry,
7061
+ attributes: {
7062
+ ...assembleOperationName({ operationId: "ai.embed", telemetry }),
7063
+ ...baseTelemetryAttributes,
6537
7064
  "ai.value": { input: () => JSON.stringify(value) }
6538
7065
  }
6539
7066
  }),
@@ -7004,7 +7531,7 @@ function extractReasoningContent(content) {
7004
7531
  import {
7005
7532
  isJSONArray,
7006
7533
  isJSONObject,
7007
- TypeValidationError as TypeValidationError2,
7534
+ TypeValidationError as TypeValidationError3,
7008
7535
  UnsupportedFunctionalityError as UnsupportedFunctionalityError2
7009
7536
  } from "@ai-sdk/provider";
7010
7537
  import {
@@ -7085,7 +7612,7 @@ var arrayOutputStrategy = (schema) => {
7085
7612
  if (!isJSONObject(value) || !isJSONArray(value.elements)) {
7086
7613
  return {
7087
7614
  success: false,
7088
- error: new TypeValidationError2({
7615
+ error: new TypeValidationError3({
7089
7616
  value,
7090
7617
  cause: "value must be an object that contains an array of elements"
7091
7618
  })
@@ -7128,7 +7655,7 @@ var arrayOutputStrategy = (schema) => {
7128
7655
  if (!isJSONObject(value) || !isJSONArray(value.elements)) {
7129
7656
  return {
7130
7657
  success: false,
7131
- error: new TypeValidationError2({
7658
+ error: new TypeValidationError3({
7132
7659
  value,
7133
7660
  cause: "value must be an object that contains an array of elements"
7134
7661
  })
@@ -7194,7 +7721,7 @@ var enumOutputStrategy = (enumValues) => {
7194
7721
  if (!isJSONObject(value) || typeof value.result !== "string") {
7195
7722
  return {
7196
7723
  success: false,
7197
- error: new TypeValidationError2({
7724
+ error: new TypeValidationError3({
7198
7725
  value,
7199
7726
  cause: 'value must be an object that contains a string in the "result" property.'
7200
7727
  })
@@ -7203,7 +7730,7 @@ var enumOutputStrategy = (enumValues) => {
7203
7730
  const result = value.result;
7204
7731
  return enumValues.includes(result) ? { success: true, value: result } : {
7205
7732
  success: false,
7206
- error: new TypeValidationError2({
7733
+ error: new TypeValidationError3({
7207
7734
  value,
7208
7735
  cause: "value must be a string in the enum"
7209
7736
  })
@@ -7213,7 +7740,7 @@ var enumOutputStrategy = (enumValues) => {
7213
7740
  if (!isJSONObject(value) || typeof value.result !== "string") {
7214
7741
  return {
7215
7742
  success: false,
7216
- error: new TypeValidationError2({
7743
+ error: new TypeValidationError3({
7217
7744
  value,
7218
7745
  cause: 'value must be an object that contains a string in the "result" property.'
7219
7746
  })
@@ -7226,7 +7753,7 @@ var enumOutputStrategy = (enumValues) => {
7226
7753
  if (value.result.length === 0 || possibleEnumValues.length === 0) {
7227
7754
  return {
7228
7755
  success: false,
7229
- error: new TypeValidationError2({
7756
+ error: new TypeValidationError3({
7230
7757
  value,
7231
7758
  cause: "value must be a string in the enum"
7232
7759
  })
@@ -7269,7 +7796,7 @@ function getOutputStrategy({
7269
7796
  }
7270
7797
 
7271
7798
  // src/generate-object/parse-and-validate-object-result.ts
7272
- import { JSONParseError as JSONParseError2, TypeValidationError as TypeValidationError3 } from "@ai-sdk/provider";
7799
+ import { JSONParseError as JSONParseError2, TypeValidationError as TypeValidationError4 } from "@ai-sdk/provider";
7273
7800
  import { safeParseJSON as safeParseJSON3 } from "@ai-sdk/provider-utils";
7274
7801
  async function parseAndValidateObjectResult(result, outputStrategy, context) {
7275
7802
  const parseResult = await safeParseJSON3({ text: result });
@@ -7307,7 +7834,7 @@ async function parseAndValidateObjectResultWithRepair(result, outputStrategy, re
7307
7834
  try {
7308
7835
  return await parseAndValidateObjectResult(result, outputStrategy, context);
7309
7836
  } catch (error) {
7310
- if (repairText != null && NoObjectGeneratedError.isInstance(error) && (JSONParseError2.isInstance(error.cause) || TypeValidationError3.isInstance(error.cause))) {
7837
+ if (repairText != null && NoObjectGeneratedError.isInstance(error) && (JSONParseError2.isInstance(error.cause) || TypeValidationError4.isInstance(error.cause))) {
7311
7838
  const repairedText = await repairText({
7312
7839
  text: result,
7313
7840
  error: error.cause
@@ -9248,137 +9775,137 @@ import {
9248
9775
  } from "@ai-sdk/provider-utils";
9249
9776
 
9250
9777
  // src/tool/mcp/json-rpc-message.ts
9251
- import { z as z9 } from "zod/v4";
9778
+ import { z as z10 } from "zod/v4";
9252
9779
 
9253
9780
  // src/tool/mcp/types.ts
9254
- import { z as z8 } from "zod/v4";
9781
+ import { z as z9 } from "zod/v4";
9255
9782
  var LATEST_PROTOCOL_VERSION = "2025-06-18";
9256
9783
  var SUPPORTED_PROTOCOL_VERSIONS = [
9257
9784
  LATEST_PROTOCOL_VERSION,
9258
9785
  "2025-03-26",
9259
9786
  "2024-11-05"
9260
9787
  ];
9261
- var ClientOrServerImplementationSchema = z8.looseObject({
9262
- name: z8.string(),
9263
- version: z8.string()
9788
+ var ClientOrServerImplementationSchema = z9.looseObject({
9789
+ name: z9.string(),
9790
+ version: z9.string()
9264
9791
  });
9265
- var BaseParamsSchema = z8.looseObject({
9266
- _meta: z8.optional(z8.object({}).loose())
9792
+ var BaseParamsSchema = z9.looseObject({
9793
+ _meta: z9.optional(z9.object({}).loose())
9267
9794
  });
9268
9795
  var ResultSchema = BaseParamsSchema;
9269
- var RequestSchema = z8.object({
9270
- method: z8.string(),
9271
- params: z8.optional(BaseParamsSchema)
9796
+ var RequestSchema = z9.object({
9797
+ method: z9.string(),
9798
+ params: z9.optional(BaseParamsSchema)
9272
9799
  });
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())
9800
+ var ServerCapabilitiesSchema = z9.looseObject({
9801
+ experimental: z9.optional(z9.object({}).loose()),
9802
+ logging: z9.optional(z9.object({}).loose()),
9803
+ prompts: z9.optional(
9804
+ z9.looseObject({
9805
+ listChanged: z9.optional(z9.boolean())
9279
9806
  })
9280
9807
  ),
9281
- resources: z8.optional(
9282
- z8.looseObject({
9283
- subscribe: z8.optional(z8.boolean()),
9284
- listChanged: z8.optional(z8.boolean())
9808
+ resources: z9.optional(
9809
+ z9.looseObject({
9810
+ subscribe: z9.optional(z9.boolean()),
9811
+ listChanged: z9.optional(z9.boolean())
9285
9812
  })
9286
9813
  ),
9287
- tools: z8.optional(
9288
- z8.looseObject({
9289
- listChanged: z8.optional(z8.boolean())
9814
+ tools: z9.optional(
9815
+ z9.looseObject({
9816
+ listChanged: z9.optional(z9.boolean())
9290
9817
  })
9291
9818
  )
9292
9819
  });
9293
9820
  var InitializeResultSchema = ResultSchema.extend({
9294
- protocolVersion: z8.string(),
9821
+ protocolVersion: z9.string(),
9295
9822
  capabilities: ServerCapabilitiesSchema,
9296
9823
  serverInfo: ClientOrServerImplementationSchema,
9297
- instructions: z8.optional(z8.string())
9824
+ instructions: z9.optional(z9.string())
9298
9825
  });
9299
9826
  var PaginatedResultSchema = ResultSchema.extend({
9300
- nextCursor: z8.optional(z8.string())
9827
+ nextCursor: z9.optional(z9.string())
9301
9828
  });
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())
9829
+ var ToolSchema = z9.object({
9830
+ name: z9.string(),
9831
+ description: z9.optional(z9.string()),
9832
+ inputSchema: z9.object({
9833
+ type: z9.literal("object"),
9834
+ properties: z9.optional(z9.object({}).loose())
9308
9835
  }).loose()
9309
9836
  }).loose();
9310
9837
  var ListToolsResultSchema = PaginatedResultSchema.extend({
9311
- tools: z8.array(ToolSchema)
9838
+ tools: z9.array(ToolSchema)
9312
9839
  });
9313
- var TextContentSchema = z8.object({
9314
- type: z8.literal("text"),
9315
- text: z8.string()
9840
+ var TextContentSchema = z9.object({
9841
+ type: z9.literal("text"),
9842
+ text: z9.string()
9316
9843
  }).loose();
9317
- var ImageContentSchema = z8.object({
9318
- type: z8.literal("image"),
9319
- data: z8.base64(),
9320
- mimeType: z8.string()
9844
+ var ImageContentSchema = z9.object({
9845
+ type: z9.literal("image"),
9846
+ data: z9.base64(),
9847
+ mimeType: z9.string()
9321
9848
  }).loose();
9322
- var ResourceContentsSchema = z8.object({
9849
+ var ResourceContentsSchema = z9.object({
9323
9850
  /**
9324
9851
  * The URI of this resource.
9325
9852
  */
9326
- uri: z8.string(),
9853
+ uri: z9.string(),
9327
9854
  /**
9328
9855
  * The MIME type of this resource, if known.
9329
9856
  */
9330
- mimeType: z8.optional(z8.string())
9857
+ mimeType: z9.optional(z9.string())
9331
9858
  }).loose();
9332
9859
  var TextResourceContentsSchema = ResourceContentsSchema.extend({
9333
- text: z8.string()
9860
+ text: z9.string()
9334
9861
  });
9335
9862
  var BlobResourceContentsSchema = ResourceContentsSchema.extend({
9336
- blob: z8.base64()
9863
+ blob: z9.base64()
9337
9864
  });
9338
- var EmbeddedResourceSchema = z8.object({
9339
- type: z8.literal("resource"),
9340
- resource: z8.union([TextResourceContentsSchema, BlobResourceContentsSchema])
9865
+ var EmbeddedResourceSchema = z9.object({
9866
+ type: z9.literal("resource"),
9867
+ resource: z9.union([TextResourceContentsSchema, BlobResourceContentsSchema])
9341
9868
  }).loose();
9342
9869
  var CallToolResultSchema = ResultSchema.extend({
9343
- content: z8.array(
9344
- z8.union([TextContentSchema, ImageContentSchema, EmbeddedResourceSchema])
9870
+ content: z9.array(
9871
+ z9.union([TextContentSchema, ImageContentSchema, EmbeddedResourceSchema])
9345
9872
  ),
9346
- isError: z8.boolean().default(false).optional()
9873
+ isError: z9.boolean().default(false).optional()
9347
9874
  }).or(
9348
9875
  ResultSchema.extend({
9349
- toolResult: z8.unknown()
9876
+ toolResult: z9.unknown()
9350
9877
  })
9351
9878
  );
9352
9879
 
9353
9880
  // src/tool/mcp/json-rpc-message.ts
9354
9881
  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()])
9882
+ var JSONRPCRequestSchema = z10.object({
9883
+ jsonrpc: z10.literal(JSONRPC_VERSION),
9884
+ id: z10.union([z10.string(), z10.number().int()])
9358
9885
  }).merge(RequestSchema).strict();
9359
- var JSONRPCResponseSchema = z9.object({
9360
- jsonrpc: z9.literal(JSONRPC_VERSION),
9361
- id: z9.union([z9.string(), z9.number().int()]),
9886
+ var JSONRPCResponseSchema = z10.object({
9887
+ jsonrpc: z10.literal(JSONRPC_VERSION),
9888
+ id: z10.union([z10.string(), z10.number().int()]),
9362
9889
  result: ResultSchema
9363
9890
  }).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())
9891
+ var JSONRPCErrorSchema = z10.object({
9892
+ jsonrpc: z10.literal(JSONRPC_VERSION),
9893
+ id: z10.union([z10.string(), z10.number().int()]),
9894
+ error: z10.object({
9895
+ code: z10.number().int(),
9896
+ message: z10.string(),
9897
+ data: z10.optional(z10.unknown())
9371
9898
  })
9372
9899
  }).strict();
9373
- var JSONRPCNotificationSchema = z9.object({
9374
- jsonrpc: z9.literal(JSONRPC_VERSION)
9900
+ var JSONRPCNotificationSchema = z10.object({
9901
+ jsonrpc: z10.literal(JSONRPC_VERSION)
9375
9902
  }).merge(
9376
- z9.object({
9377
- method: z9.string(),
9378
- params: z9.optional(BaseParamsSchema)
9903
+ z10.object({
9904
+ method: z10.string(),
9905
+ params: z10.optional(BaseParamsSchema)
9379
9906
  })
9380
9907
  ).strict();
9381
- var JSONRPCMessageSchema = z9.union([
9908
+ var JSONRPCMessageSchema = z10.union([
9382
9909
  JSONRPCRequestSchema,
9383
9910
  JSONRPCNotificationSchema,
9384
9911
  JSONRPCResponseSchema,
@@ -10037,7 +10564,7 @@ async function callCompletionApi({
10037
10564
 
10038
10565
  // src/ui/chat.ts
10039
10566
  import {
10040
- generateId as generateIdFunc
10567
+ generateId as generateIdFunc2
10041
10568
  } from "@ai-sdk/provider-utils";
10042
10569
 
10043
10570
  // src/ui/convert-file-list-to-file-ui-parts.ts
@@ -10218,7 +10745,7 @@ var DefaultChatTransport = class extends HttpChatTransport {
10218
10745
  // src/ui/chat.ts
10219
10746
  var AbstractChat = class {
10220
10747
  constructor({
10221
- generateId: generateId2 = generateIdFunc,
10748
+ generateId: generateId2 = generateIdFunc2,
10222
10749
  id = generateId2(),
10223
10750
  transport = new DefaultChatTransport(),
10224
10751
  messageMetadataSchema,
@@ -10644,523 +11171,6 @@ var TextStreamChatTransport = class extends HttpChatTransport {
10644
11171
  });
10645
11172
  }
10646
11173
  };
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
11174
  export {
11165
11175
  AISDKError18 as AISDKError,
11166
11176
  APICallError,
@@ -11216,6 +11226,7 @@ export {
11216
11226
  coreToolMessageSchema,
11217
11227
  coreUserMessageSchema,
11218
11228
  cosineSimilarity,
11229
+ createAgentStreamResponse,
11219
11230
  createGateway,
11220
11231
  createIdGenerator5 as createIdGenerator,
11221
11232
  createProviderRegistry,