ai 6.0.0-beta.57 → 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.57" : "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,91 +6629,440 @@ 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.settings = settings;
6457
- }
6458
- /**
6459
- * The id of the agent.
6460
- */
6461
- get id() {
6462
- return this.settings.id;
6463
- }
6464
- /**
6465
- * The tools that the agent can use.
6466
- */
6467
- get tools() {
6468
- return this.settings.tools;
6469
- }
6470
- /**
6471
- * Generates an output from the agent (non-streaming).
6472
- */
6473
- async generate(options) {
6474
- var _a17;
6475
- return generateText({
6476
- ...this.settings,
6477
- stopWhen: (_a17 = this.settings.stopWhen) != null ? _a17 : stepCountIs(20),
6478
- ...options
6479
- });
6480
- }
6481
- /**
6482
- * Streams an output from the agent (streaming).
6483
- */
6484
- stream(options) {
6485
- var _a17;
6486
- return streamText({
6487
- ...this.settings,
6488
- stopWhen: (_a17 = this.settings.stopWhen) != null ? _a17 : stepCountIs(20),
6489
- ...options
6490
- });
6491
- }
6492
- /**
6493
- * Creates a response object that streams UI messages to the client.
6494
- */
6495
- respond(options) {
6496
- return this.stream({
6497
- prompt: convertToModelMessages(options.messages, { tools: this.tools })
6498
- }).toUIMessageStreamResponse();
6499
- }
6500
- };
6501
-
6502
- // src/embed/embed.ts
6503
- import { withUserAgentSuffix as withUserAgentSuffix3 } from "@ai-sdk/provider-utils";
6504
- async function embed({
6505
- model: modelArg,
6506
- value,
6507
- providerOptions,
6508
- maxRetries: maxRetriesArg,
6509
- abortSignal,
6510
- headers,
6511
- experimental_telemetry: telemetry
6512
- }) {
6513
- const model = resolveEmbeddingModel(modelArg);
6514
- const { maxRetries, retry } = prepareRetries({
6515
- maxRetries: maxRetriesArg,
6516
- abortSignal
6517
- });
6518
- const headersWithUserAgent = withUserAgentSuffix3(
6519
- headers != null ? headers : {},
6520
- `ai/${VERSION}`
6521
- );
6522
- const baseTelemetryAttributes = getBaseTelemetryAttributes({
6523
- model,
6524
- telemetry,
6525
- headers: headersWithUserAgent,
6526
- settings: { maxRetries }
6527
- });
6528
- const tracer = getTracer(telemetry);
6529
- return recordSpan({
6530
- name: "ai.embed",
6531
- attributes: selectTelemetryAttributes({
6532
- telemetry,
6533
- attributes: {
6534
- ...assembleOperationName({ operationId: "ai.embed", telemetry }),
6535
- ...baseTelemetryAttributes,
6536
- "ai.value": { input: () => JSON.stringify(value) }
6537
- }
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,
7064
+ "ai.value": { input: () => JSON.stringify(value) }
7065
+ }
6538
7066
  }),
6539
7067
  tracer,
6540
7068
  fn: async (span) => {
@@ -7003,7 +7531,7 @@ function extractReasoningContent(content) {
7003
7531
  import {
7004
7532
  isJSONArray,
7005
7533
  isJSONObject,
7006
- TypeValidationError as TypeValidationError2,
7534
+ TypeValidationError as TypeValidationError3,
7007
7535
  UnsupportedFunctionalityError as UnsupportedFunctionalityError2
7008
7536
  } from "@ai-sdk/provider";
7009
7537
  import {
@@ -7084,7 +7612,7 @@ var arrayOutputStrategy = (schema) => {
7084
7612
  if (!isJSONObject(value) || !isJSONArray(value.elements)) {
7085
7613
  return {
7086
7614
  success: false,
7087
- error: new TypeValidationError2({
7615
+ error: new TypeValidationError3({
7088
7616
  value,
7089
7617
  cause: "value must be an object that contains an array of elements"
7090
7618
  })
@@ -7127,7 +7655,7 @@ var arrayOutputStrategy = (schema) => {
7127
7655
  if (!isJSONObject(value) || !isJSONArray(value.elements)) {
7128
7656
  return {
7129
7657
  success: false,
7130
- error: new TypeValidationError2({
7658
+ error: new TypeValidationError3({
7131
7659
  value,
7132
7660
  cause: "value must be an object that contains an array of elements"
7133
7661
  })
@@ -7193,7 +7721,7 @@ var enumOutputStrategy = (enumValues) => {
7193
7721
  if (!isJSONObject(value) || typeof value.result !== "string") {
7194
7722
  return {
7195
7723
  success: false,
7196
- error: new TypeValidationError2({
7724
+ error: new TypeValidationError3({
7197
7725
  value,
7198
7726
  cause: 'value must be an object that contains a string in the "result" property.'
7199
7727
  })
@@ -7202,7 +7730,7 @@ var enumOutputStrategy = (enumValues) => {
7202
7730
  const result = value.result;
7203
7731
  return enumValues.includes(result) ? { success: true, value: result } : {
7204
7732
  success: false,
7205
- error: new TypeValidationError2({
7733
+ error: new TypeValidationError3({
7206
7734
  value,
7207
7735
  cause: "value must be a string in the enum"
7208
7736
  })
@@ -7212,7 +7740,7 @@ var enumOutputStrategy = (enumValues) => {
7212
7740
  if (!isJSONObject(value) || typeof value.result !== "string") {
7213
7741
  return {
7214
7742
  success: false,
7215
- error: new TypeValidationError2({
7743
+ error: new TypeValidationError3({
7216
7744
  value,
7217
7745
  cause: 'value must be an object that contains a string in the "result" property.'
7218
7746
  })
@@ -7225,7 +7753,7 @@ var enumOutputStrategy = (enumValues) => {
7225
7753
  if (value.result.length === 0 || possibleEnumValues.length === 0) {
7226
7754
  return {
7227
7755
  success: false,
7228
- error: new TypeValidationError2({
7756
+ error: new TypeValidationError3({
7229
7757
  value,
7230
7758
  cause: "value must be a string in the enum"
7231
7759
  })
@@ -7268,7 +7796,7 @@ function getOutputStrategy({
7268
7796
  }
7269
7797
 
7270
7798
  // src/generate-object/parse-and-validate-object-result.ts
7271
- import { JSONParseError as JSONParseError2, TypeValidationError as TypeValidationError3 } from "@ai-sdk/provider";
7799
+ import { JSONParseError as JSONParseError2, TypeValidationError as TypeValidationError4 } from "@ai-sdk/provider";
7272
7800
  import { safeParseJSON as safeParseJSON3 } from "@ai-sdk/provider-utils";
7273
7801
  async function parseAndValidateObjectResult(result, outputStrategy, context) {
7274
7802
  const parseResult = await safeParseJSON3({ text: result });
@@ -7306,7 +7834,7 @@ async function parseAndValidateObjectResultWithRepair(result, outputStrategy, re
7306
7834
  try {
7307
7835
  return await parseAndValidateObjectResult(result, outputStrategy, context);
7308
7836
  } catch (error) {
7309
- 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))) {
7310
7838
  const repairedText = await repairText({
7311
7839
  text: result,
7312
7840
  error: error.cause
@@ -9247,137 +9775,137 @@ import {
9247
9775
  } from "@ai-sdk/provider-utils";
9248
9776
 
9249
9777
  // src/tool/mcp/json-rpc-message.ts
9250
- import { z as z9 } from "zod/v4";
9778
+ import { z as z10 } from "zod/v4";
9251
9779
 
9252
9780
  // src/tool/mcp/types.ts
9253
- import { z as z8 } from "zod/v4";
9781
+ import { z as z9 } from "zod/v4";
9254
9782
  var LATEST_PROTOCOL_VERSION = "2025-06-18";
9255
9783
  var SUPPORTED_PROTOCOL_VERSIONS = [
9256
9784
  LATEST_PROTOCOL_VERSION,
9257
9785
  "2025-03-26",
9258
9786
  "2024-11-05"
9259
9787
  ];
9260
- var ClientOrServerImplementationSchema = z8.looseObject({
9261
- name: z8.string(),
9262
- version: z8.string()
9788
+ var ClientOrServerImplementationSchema = z9.looseObject({
9789
+ name: z9.string(),
9790
+ version: z9.string()
9263
9791
  });
9264
- var BaseParamsSchema = z8.looseObject({
9265
- _meta: z8.optional(z8.object({}).loose())
9792
+ var BaseParamsSchema = z9.looseObject({
9793
+ _meta: z9.optional(z9.object({}).loose())
9266
9794
  });
9267
9795
  var ResultSchema = BaseParamsSchema;
9268
- var RequestSchema = z8.object({
9269
- method: z8.string(),
9270
- params: z8.optional(BaseParamsSchema)
9796
+ var RequestSchema = z9.object({
9797
+ method: z9.string(),
9798
+ params: z9.optional(BaseParamsSchema)
9271
9799
  });
9272
- var ServerCapabilitiesSchema = z8.looseObject({
9273
- experimental: z8.optional(z8.object({}).loose()),
9274
- logging: z8.optional(z8.object({}).loose()),
9275
- prompts: z8.optional(
9276
- z8.looseObject({
9277
- 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())
9278
9806
  })
9279
9807
  ),
9280
- resources: z8.optional(
9281
- z8.looseObject({
9282
- subscribe: z8.optional(z8.boolean()),
9283
- listChanged: z8.optional(z8.boolean())
9808
+ resources: z9.optional(
9809
+ z9.looseObject({
9810
+ subscribe: z9.optional(z9.boolean()),
9811
+ listChanged: z9.optional(z9.boolean())
9284
9812
  })
9285
9813
  ),
9286
- tools: z8.optional(
9287
- z8.looseObject({
9288
- listChanged: z8.optional(z8.boolean())
9814
+ tools: z9.optional(
9815
+ z9.looseObject({
9816
+ listChanged: z9.optional(z9.boolean())
9289
9817
  })
9290
9818
  )
9291
9819
  });
9292
9820
  var InitializeResultSchema = ResultSchema.extend({
9293
- protocolVersion: z8.string(),
9821
+ protocolVersion: z9.string(),
9294
9822
  capabilities: ServerCapabilitiesSchema,
9295
9823
  serverInfo: ClientOrServerImplementationSchema,
9296
- instructions: z8.optional(z8.string())
9824
+ instructions: z9.optional(z9.string())
9297
9825
  });
9298
9826
  var PaginatedResultSchema = ResultSchema.extend({
9299
- nextCursor: z8.optional(z8.string())
9827
+ nextCursor: z9.optional(z9.string())
9300
9828
  });
9301
- var ToolSchema = z8.object({
9302
- name: z8.string(),
9303
- description: z8.optional(z8.string()),
9304
- inputSchema: z8.object({
9305
- type: z8.literal("object"),
9306
- 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())
9307
9835
  }).loose()
9308
9836
  }).loose();
9309
9837
  var ListToolsResultSchema = PaginatedResultSchema.extend({
9310
- tools: z8.array(ToolSchema)
9838
+ tools: z9.array(ToolSchema)
9311
9839
  });
9312
- var TextContentSchema = z8.object({
9313
- type: z8.literal("text"),
9314
- text: z8.string()
9840
+ var TextContentSchema = z9.object({
9841
+ type: z9.literal("text"),
9842
+ text: z9.string()
9315
9843
  }).loose();
9316
- var ImageContentSchema = z8.object({
9317
- type: z8.literal("image"),
9318
- data: z8.base64(),
9319
- mimeType: z8.string()
9844
+ var ImageContentSchema = z9.object({
9845
+ type: z9.literal("image"),
9846
+ data: z9.base64(),
9847
+ mimeType: z9.string()
9320
9848
  }).loose();
9321
- var ResourceContentsSchema = z8.object({
9849
+ var ResourceContentsSchema = z9.object({
9322
9850
  /**
9323
9851
  * The URI of this resource.
9324
9852
  */
9325
- uri: z8.string(),
9853
+ uri: z9.string(),
9326
9854
  /**
9327
9855
  * The MIME type of this resource, if known.
9328
9856
  */
9329
- mimeType: z8.optional(z8.string())
9857
+ mimeType: z9.optional(z9.string())
9330
9858
  }).loose();
9331
9859
  var TextResourceContentsSchema = ResourceContentsSchema.extend({
9332
- text: z8.string()
9860
+ text: z9.string()
9333
9861
  });
9334
9862
  var BlobResourceContentsSchema = ResourceContentsSchema.extend({
9335
- blob: z8.base64()
9863
+ blob: z9.base64()
9336
9864
  });
9337
- var EmbeddedResourceSchema = z8.object({
9338
- type: z8.literal("resource"),
9339
- resource: z8.union([TextResourceContentsSchema, BlobResourceContentsSchema])
9865
+ var EmbeddedResourceSchema = z9.object({
9866
+ type: z9.literal("resource"),
9867
+ resource: z9.union([TextResourceContentsSchema, BlobResourceContentsSchema])
9340
9868
  }).loose();
9341
9869
  var CallToolResultSchema = ResultSchema.extend({
9342
- content: z8.array(
9343
- z8.union([TextContentSchema, ImageContentSchema, EmbeddedResourceSchema])
9870
+ content: z9.array(
9871
+ z9.union([TextContentSchema, ImageContentSchema, EmbeddedResourceSchema])
9344
9872
  ),
9345
- isError: z8.boolean().default(false).optional()
9873
+ isError: z9.boolean().default(false).optional()
9346
9874
  }).or(
9347
9875
  ResultSchema.extend({
9348
- toolResult: z8.unknown()
9876
+ toolResult: z9.unknown()
9349
9877
  })
9350
9878
  );
9351
9879
 
9352
9880
  // src/tool/mcp/json-rpc-message.ts
9353
9881
  var JSONRPC_VERSION = "2.0";
9354
- var JSONRPCRequestSchema = z9.object({
9355
- jsonrpc: z9.literal(JSONRPC_VERSION),
9356
- 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()])
9357
9885
  }).merge(RequestSchema).strict();
9358
- var JSONRPCResponseSchema = z9.object({
9359
- jsonrpc: z9.literal(JSONRPC_VERSION),
9360
- 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()]),
9361
9889
  result: ResultSchema
9362
9890
  }).strict();
9363
- var JSONRPCErrorSchema = z9.object({
9364
- jsonrpc: z9.literal(JSONRPC_VERSION),
9365
- id: z9.union([z9.string(), z9.number().int()]),
9366
- error: z9.object({
9367
- code: z9.number().int(),
9368
- message: z9.string(),
9369
- 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())
9370
9898
  })
9371
9899
  }).strict();
9372
- var JSONRPCNotificationSchema = z9.object({
9373
- jsonrpc: z9.literal(JSONRPC_VERSION)
9900
+ var JSONRPCNotificationSchema = z10.object({
9901
+ jsonrpc: z10.literal(JSONRPC_VERSION)
9374
9902
  }).merge(
9375
- z9.object({
9376
- method: z9.string(),
9377
- params: z9.optional(BaseParamsSchema)
9903
+ z10.object({
9904
+ method: z10.string(),
9905
+ params: z10.optional(BaseParamsSchema)
9378
9906
  })
9379
9907
  ).strict();
9380
- var JSONRPCMessageSchema = z9.union([
9908
+ var JSONRPCMessageSchema = z10.union([
9381
9909
  JSONRPCRequestSchema,
9382
9910
  JSONRPCNotificationSchema,
9383
9911
  JSONRPCResponseSchema,
@@ -10036,7 +10564,7 @@ async function callCompletionApi({
10036
10564
 
10037
10565
  // src/ui/chat.ts
10038
10566
  import {
10039
- generateId as generateIdFunc
10567
+ generateId as generateIdFunc2
10040
10568
  } from "@ai-sdk/provider-utils";
10041
10569
 
10042
10570
  // src/ui/convert-file-list-to-file-ui-parts.ts
@@ -10217,7 +10745,7 @@ var DefaultChatTransport = class extends HttpChatTransport {
10217
10745
  // src/ui/chat.ts
10218
10746
  var AbstractChat = class {
10219
10747
  constructor({
10220
- generateId: generateId2 = generateIdFunc,
10748
+ generateId: generateId2 = generateIdFunc2,
10221
10749
  id = generateId2(),
10222
10750
  transport = new DefaultChatTransport(),
10223
10751
  messageMetadataSchema,
@@ -10643,523 +11171,6 @@ var TextStreamChatTransport = class extends HttpChatTransport {
10643
11171
  });
10644
11172
  }
10645
11173
  };
10646
-
10647
- // src/ui/validate-ui-messages.ts
10648
- import { TypeValidationError as TypeValidationError4 } from "@ai-sdk/provider";
10649
- import {
10650
- lazySchema as lazySchema2,
10651
- validateTypes as validateTypes2,
10652
- zodSchema as zodSchema2
10653
- } from "@ai-sdk/provider-utils";
10654
- import { z as z10 } from "zod/v4";
10655
- var uiMessagesSchema = lazySchema2(
10656
- () => zodSchema2(
10657
- z10.array(
10658
- z10.object({
10659
- id: z10.string(),
10660
- role: z10.enum(["system", "user", "assistant"]),
10661
- metadata: z10.unknown().optional(),
10662
- parts: z10.array(
10663
- z10.union([
10664
- z10.object({
10665
- type: z10.literal("text"),
10666
- text: z10.string(),
10667
- state: z10.enum(["streaming", "done"]).optional(),
10668
- providerMetadata: providerMetadataSchema.optional()
10669
- }),
10670
- z10.object({
10671
- type: z10.literal("reasoning"),
10672
- text: z10.string(),
10673
- state: z10.enum(["streaming", "done"]).optional(),
10674
- providerMetadata: providerMetadataSchema.optional()
10675
- }),
10676
- z10.object({
10677
- type: z10.literal("source-url"),
10678
- sourceId: z10.string(),
10679
- url: z10.string(),
10680
- title: z10.string().optional(),
10681
- providerMetadata: providerMetadataSchema.optional()
10682
- }),
10683
- z10.object({
10684
- type: z10.literal("source-document"),
10685
- sourceId: z10.string(),
10686
- mediaType: z10.string(),
10687
- title: z10.string(),
10688
- filename: z10.string().optional(),
10689
- providerMetadata: providerMetadataSchema.optional()
10690
- }),
10691
- z10.object({
10692
- type: z10.literal("file"),
10693
- mediaType: z10.string(),
10694
- filename: z10.string().optional(),
10695
- url: z10.string(),
10696
- providerMetadata: providerMetadataSchema.optional()
10697
- }),
10698
- z10.object({
10699
- type: z10.literal("step-start")
10700
- }),
10701
- z10.object({
10702
- type: z10.string().startsWith("data-"),
10703
- id: z10.string().optional(),
10704
- data: z10.unknown()
10705
- }),
10706
- z10.object({
10707
- type: z10.literal("dynamic-tool"),
10708
- toolName: z10.string(),
10709
- toolCallId: z10.string(),
10710
- state: z10.literal("input-streaming"),
10711
- input: z10.unknown().optional(),
10712
- providerExecuted: z10.boolean().optional(),
10713
- output: z10.never().optional(),
10714
- errorText: z10.never().optional(),
10715
- approval: z10.never().optional()
10716
- }),
10717
- z10.object({
10718
- type: z10.literal("dynamic-tool"),
10719
- toolName: z10.string(),
10720
- toolCallId: z10.string(),
10721
- state: z10.literal("input-available"),
10722
- input: z10.unknown(),
10723
- providerExecuted: z10.boolean().optional(),
10724
- output: z10.never().optional(),
10725
- errorText: z10.never().optional(),
10726
- callProviderMetadata: providerMetadataSchema.optional(),
10727
- approval: z10.never().optional()
10728
- }),
10729
- z10.object({
10730
- type: z10.literal("dynamic-tool"),
10731
- toolName: z10.string(),
10732
- toolCallId: z10.string(),
10733
- state: z10.literal("approval-requested"),
10734
- input: z10.unknown(),
10735
- providerExecuted: z10.boolean().optional(),
10736
- output: z10.never().optional(),
10737
- errorText: z10.never().optional(),
10738
- callProviderMetadata: providerMetadataSchema.optional(),
10739
- approval: z10.object({
10740
- id: z10.string(),
10741
- approved: z10.never().optional(),
10742
- reason: z10.never().optional()
10743
- })
10744
- }),
10745
- z10.object({
10746
- type: z10.literal("dynamic-tool"),
10747
- toolName: z10.string(),
10748
- toolCallId: z10.string(),
10749
- state: z10.literal("approval-responded"),
10750
- input: z10.unknown(),
10751
- providerExecuted: z10.boolean().optional(),
10752
- output: z10.never().optional(),
10753
- errorText: z10.never().optional(),
10754
- callProviderMetadata: providerMetadataSchema.optional(),
10755
- approval: z10.object({
10756
- id: z10.string(),
10757
- approved: z10.boolean(),
10758
- reason: z10.string().optional()
10759
- })
10760
- }),
10761
- z10.object({
10762
- type: z10.literal("dynamic-tool"),
10763
- toolName: z10.string(),
10764
- toolCallId: z10.string(),
10765
- state: z10.literal("output-available"),
10766
- input: z10.unknown(),
10767
- providerExecuted: z10.boolean().optional(),
10768
- output: z10.unknown(),
10769
- errorText: z10.never().optional(),
10770
- callProviderMetadata: providerMetadataSchema.optional(),
10771
- preliminary: z10.boolean().optional(),
10772
- approval: z10.object({
10773
- id: z10.string(),
10774
- approved: z10.literal(true),
10775
- reason: z10.string().optional()
10776
- }).optional()
10777
- }),
10778
- z10.object({
10779
- type: z10.literal("dynamic-tool"),
10780
- toolName: z10.string(),
10781
- toolCallId: z10.string(),
10782
- state: z10.literal("output-error"),
10783
- input: z10.unknown(),
10784
- providerExecuted: z10.boolean().optional(),
10785
- output: z10.never().optional(),
10786
- errorText: z10.string(),
10787
- callProviderMetadata: providerMetadataSchema.optional(),
10788
- approval: z10.object({
10789
- id: z10.string(),
10790
- approved: z10.literal(true),
10791
- reason: z10.string().optional()
10792
- }).optional()
10793
- }),
10794
- z10.object({
10795
- type: z10.literal("dynamic-tool"),
10796
- toolName: z10.string(),
10797
- toolCallId: z10.string(),
10798
- state: z10.literal("output-denied"),
10799
- input: z10.unknown(),
10800
- providerExecuted: z10.boolean().optional(),
10801
- output: z10.never().optional(),
10802
- errorText: z10.never().optional(),
10803
- callProviderMetadata: providerMetadataSchema.optional(),
10804
- approval: z10.object({
10805
- id: z10.string(),
10806
- approved: z10.literal(false),
10807
- reason: z10.string().optional()
10808
- })
10809
- }),
10810
- z10.object({
10811
- type: z10.string().startsWith("tool-"),
10812
- toolCallId: z10.string(),
10813
- state: z10.literal("input-streaming"),
10814
- providerExecuted: z10.boolean().optional(),
10815
- input: z10.unknown().optional(),
10816
- output: z10.never().optional(),
10817
- errorText: z10.never().optional(),
10818
- approval: z10.never().optional()
10819
- }),
10820
- z10.object({
10821
- type: z10.string().startsWith("tool-"),
10822
- toolCallId: z10.string(),
10823
- state: z10.literal("input-available"),
10824
- providerExecuted: z10.boolean().optional(),
10825
- input: z10.unknown(),
10826
- output: z10.never().optional(),
10827
- errorText: z10.never().optional(),
10828
- callProviderMetadata: providerMetadataSchema.optional(),
10829
- approval: z10.never().optional()
10830
- }),
10831
- z10.object({
10832
- type: z10.string().startsWith("tool-"),
10833
- toolCallId: z10.string(),
10834
- state: z10.literal("approval-requested"),
10835
- input: z10.unknown(),
10836
- providerExecuted: z10.boolean().optional(),
10837
- output: z10.never().optional(),
10838
- errorText: z10.never().optional(),
10839
- callProviderMetadata: providerMetadataSchema.optional(),
10840
- approval: z10.object({
10841
- id: z10.string(),
10842
- approved: z10.never().optional(),
10843
- reason: z10.never().optional()
10844
- })
10845
- }),
10846
- z10.object({
10847
- type: z10.string().startsWith("tool-"),
10848
- toolCallId: z10.string(),
10849
- state: z10.literal("approval-responded"),
10850
- input: z10.unknown(),
10851
- providerExecuted: z10.boolean().optional(),
10852
- output: z10.never().optional(),
10853
- errorText: z10.never().optional(),
10854
- callProviderMetadata: providerMetadataSchema.optional(),
10855
- approval: z10.object({
10856
- id: z10.string(),
10857
- approved: z10.boolean(),
10858
- reason: z10.string().optional()
10859
- })
10860
- }),
10861
- z10.object({
10862
- type: z10.string().startsWith("tool-"),
10863
- toolCallId: z10.string(),
10864
- state: z10.literal("output-available"),
10865
- providerExecuted: z10.boolean().optional(),
10866
- input: z10.unknown(),
10867
- output: z10.unknown(),
10868
- errorText: z10.never().optional(),
10869
- callProviderMetadata: providerMetadataSchema.optional(),
10870
- preliminary: z10.boolean().optional(),
10871
- approval: z10.object({
10872
- id: z10.string(),
10873
- approved: z10.literal(true),
10874
- reason: z10.string().optional()
10875
- }).optional()
10876
- }),
10877
- z10.object({
10878
- type: z10.string().startsWith("tool-"),
10879
- toolCallId: z10.string(),
10880
- state: z10.literal("output-error"),
10881
- providerExecuted: z10.boolean().optional(),
10882
- input: z10.unknown(),
10883
- output: z10.never().optional(),
10884
- errorText: z10.string(),
10885
- callProviderMetadata: providerMetadataSchema.optional(),
10886
- approval: z10.object({
10887
- id: z10.string(),
10888
- approved: z10.literal(true),
10889
- reason: z10.string().optional()
10890
- }).optional()
10891
- }),
10892
- z10.object({
10893
- type: z10.string().startsWith("tool-"),
10894
- toolCallId: z10.string(),
10895
- state: z10.literal("output-denied"),
10896
- providerExecuted: z10.boolean().optional(),
10897
- input: z10.unknown(),
10898
- output: z10.never().optional(),
10899
- errorText: z10.never().optional(),
10900
- callProviderMetadata: providerMetadataSchema.optional(),
10901
- approval: z10.object({
10902
- id: z10.string(),
10903
- approved: z10.literal(false),
10904
- reason: z10.string().optional()
10905
- })
10906
- })
10907
- ])
10908
- )
10909
- })
10910
- )
10911
- )
10912
- );
10913
- async function safeValidateUIMessages({
10914
- messages,
10915
- metadataSchema,
10916
- dataSchemas,
10917
- tools
10918
- }) {
10919
- try {
10920
- if (messages == null) {
10921
- return {
10922
- success: false,
10923
- error: new InvalidArgumentError({
10924
- parameter: "messages",
10925
- value: messages,
10926
- message: "messages parameter must be provided"
10927
- })
10928
- };
10929
- }
10930
- const validatedMessages = await validateTypes2({
10931
- value: messages,
10932
- schema: uiMessagesSchema
10933
- });
10934
- if (metadataSchema) {
10935
- for (const message of validatedMessages) {
10936
- await validateTypes2({
10937
- value: message.metadata,
10938
- schema: metadataSchema
10939
- });
10940
- }
10941
- }
10942
- if (dataSchemas) {
10943
- for (const message of validatedMessages) {
10944
- const dataParts = message.parts.filter(
10945
- (part) => part.type.startsWith("data-")
10946
- );
10947
- for (const dataPart of dataParts) {
10948
- const dataName = dataPart.type.slice(5);
10949
- const dataSchema = dataSchemas[dataName];
10950
- if (!dataSchema) {
10951
- return {
10952
- success: false,
10953
- error: new TypeValidationError4({
10954
- value: dataPart.data,
10955
- cause: `No data schema found for data part ${dataName}`
10956
- })
10957
- };
10958
- }
10959
- await validateTypes2({
10960
- value: dataPart.data,
10961
- schema: dataSchema
10962
- });
10963
- }
10964
- }
10965
- }
10966
- if (tools) {
10967
- for (const message of validatedMessages) {
10968
- const toolParts = message.parts.filter(
10969
- (part) => part.type.startsWith("tool-")
10970
- );
10971
- for (const toolPart of toolParts) {
10972
- const toolName = toolPart.type.slice(5);
10973
- const tool3 = tools[toolName];
10974
- if (!tool3) {
10975
- return {
10976
- success: false,
10977
- error: new TypeValidationError4({
10978
- value: toolPart.input,
10979
- cause: `No tool schema found for tool part ${toolName}`
10980
- })
10981
- };
10982
- }
10983
- if (toolPart.state === "input-available" || toolPart.state === "output-available" || toolPart.state === "output-error") {
10984
- await validateTypes2({
10985
- value: toolPart.input,
10986
- schema: tool3.inputSchema
10987
- });
10988
- }
10989
- if (toolPart.state === "output-available" && tool3.outputSchema) {
10990
- await validateTypes2({
10991
- value: toolPart.output,
10992
- schema: tool3.outputSchema
10993
- });
10994
- }
10995
- }
10996
- }
10997
- }
10998
- return {
10999
- success: true,
11000
- data: validatedMessages
11001
- };
11002
- } catch (error) {
11003
- const err = error;
11004
- return {
11005
- success: false,
11006
- error: err
11007
- };
11008
- }
11009
- }
11010
- async function validateUIMessages({
11011
- messages,
11012
- metadataSchema,
11013
- dataSchemas,
11014
- tools
11015
- }) {
11016
- const response = await safeValidateUIMessages({
11017
- messages,
11018
- metadataSchema,
11019
- dataSchemas,
11020
- tools
11021
- });
11022
- if (!response.success)
11023
- throw response.error;
11024
- return response.data;
11025
- }
11026
-
11027
- // src/ui-message-stream/create-ui-message-stream.ts
11028
- import {
11029
- generateId as generateIdFunc2,
11030
- getErrorMessage as getErrorMessage8
11031
- } from "@ai-sdk/provider-utils";
11032
- function createUIMessageStream({
11033
- execute,
11034
- onError = getErrorMessage8,
11035
- originalMessages,
11036
- onFinish,
11037
- generateId: generateId2 = generateIdFunc2
11038
- }) {
11039
- let controller;
11040
- const ongoingStreamPromises = [];
11041
- const stream = new ReadableStream({
11042
- start(controllerArg) {
11043
- controller = controllerArg;
11044
- }
11045
- });
11046
- function safeEnqueue(data) {
11047
- try {
11048
- controller.enqueue(data);
11049
- } catch (error) {
11050
- }
11051
- }
11052
- try {
11053
- const result = execute({
11054
- writer: {
11055
- write(part) {
11056
- safeEnqueue(part);
11057
- },
11058
- merge(streamArg) {
11059
- ongoingStreamPromises.push(
11060
- (async () => {
11061
- const reader = streamArg.getReader();
11062
- while (true) {
11063
- const { done, value } = await reader.read();
11064
- if (done)
11065
- break;
11066
- safeEnqueue(value);
11067
- }
11068
- })().catch((error) => {
11069
- safeEnqueue({
11070
- type: "error",
11071
- errorText: onError(error)
11072
- });
11073
- })
11074
- );
11075
- },
11076
- onError
11077
- }
11078
- });
11079
- if (result) {
11080
- ongoingStreamPromises.push(
11081
- result.catch((error) => {
11082
- safeEnqueue({
11083
- type: "error",
11084
- errorText: onError(error)
11085
- });
11086
- })
11087
- );
11088
- }
11089
- } catch (error) {
11090
- safeEnqueue({
11091
- type: "error",
11092
- errorText: onError(error)
11093
- });
11094
- }
11095
- const waitForStreams = new Promise(async (resolve3) => {
11096
- while (ongoingStreamPromises.length > 0) {
11097
- await ongoingStreamPromises.shift();
11098
- }
11099
- resolve3();
11100
- });
11101
- waitForStreams.finally(() => {
11102
- try {
11103
- controller.close();
11104
- } catch (error) {
11105
- }
11106
- });
11107
- return handleUIMessageStreamFinish({
11108
- stream,
11109
- messageId: generateId2(),
11110
- originalMessages,
11111
- onFinish,
11112
- onError
11113
- });
11114
- }
11115
-
11116
- // src/ui-message-stream/read-ui-message-stream.ts
11117
- function readUIMessageStream({
11118
- message,
11119
- stream,
11120
- onError,
11121
- terminateOnError = false
11122
- }) {
11123
- var _a17;
11124
- let controller;
11125
- let hasErrored = false;
11126
- const outputStream = new ReadableStream({
11127
- start(controllerParam) {
11128
- controller = controllerParam;
11129
- }
11130
- });
11131
- const state = createStreamingUIMessageState({
11132
- messageId: (_a17 = message == null ? void 0 : message.id) != null ? _a17 : "",
11133
- lastMessage: message
11134
- });
11135
- const handleError = (error) => {
11136
- onError == null ? void 0 : onError(error);
11137
- if (!hasErrored && terminateOnError) {
11138
- hasErrored = true;
11139
- controller == null ? void 0 : controller.error(error);
11140
- }
11141
- };
11142
- consumeStream({
11143
- stream: processUIMessageStream({
11144
- stream,
11145
- runUpdateMessageJob(job) {
11146
- return job({
11147
- state,
11148
- write: () => {
11149
- controller == null ? void 0 : controller.enqueue(structuredClone(state.message));
11150
- }
11151
- });
11152
- },
11153
- onError: handleError
11154
- }),
11155
- onError: handleError
11156
- }).finally(() => {
11157
- if (!hasErrored) {
11158
- controller == null ? void 0 : controller.close();
11159
- }
11160
- });
11161
- return createAsyncIterableStream(outputStream);
11162
- }
11163
11174
  export {
11164
11175
  AISDKError18 as AISDKError,
11165
11176
  APICallError,
@@ -11215,6 +11226,7 @@ export {
11215
11226
  coreToolMessageSchema,
11216
11227
  coreUserMessageSchema,
11217
11228
  cosineSimilarity,
11229
+ createAgentStreamResponse,
11218
11230
  createGateway,
11219
11231
  createIdGenerator5 as createIdGenerator,
11220
11232
  createProviderRegistry,