@mastra/core 1.0.0-beta.3 → 1.0.0-beta.4

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.
Files changed (146) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/dist/agent/index.cjs +9 -9
  3. package/dist/agent/index.js +2 -2
  4. package/dist/agent/message-list/index.cjs +3 -3
  5. package/dist/agent/message-list/index.d.ts +5 -0
  6. package/dist/agent/message-list/index.d.ts.map +1 -1
  7. package/dist/agent/message-list/index.js +1 -1
  8. package/dist/{chunk-OWX2PUFH.cjs → chunk-2NVBZKZI.cjs} +161 -129
  9. package/dist/chunk-2NVBZKZI.cjs.map +1 -0
  10. package/dist/{chunk-OQF4H5Y2.js → chunk-2OTDXX73.js} +4 -4
  11. package/dist/{chunk-OQF4H5Y2.js.map → chunk-2OTDXX73.js.map} +1 -1
  12. package/dist/{chunk-4DWZ4Z6H.js → chunk-3RW5EMSB.js} +3 -4
  13. package/dist/chunk-3RW5EMSB.js.map +1 -0
  14. package/dist/{chunk-N4SJ4YX7.cjs → chunk-3W5RQCCY.cjs} +40 -24
  15. package/dist/chunk-3W5RQCCY.cjs.map +1 -0
  16. package/dist/{chunk-XRIVPHXV.cjs → chunk-4RXG622P.cjs} +5 -5
  17. package/dist/{chunk-XRIVPHXV.cjs.map → chunk-4RXG622P.cjs.map} +1 -1
  18. package/dist/{chunk-VZGBVYXA.cjs → chunk-5WXEYDFI.cjs} +22 -23
  19. package/dist/chunk-5WXEYDFI.cjs.map +1 -0
  20. package/dist/{chunk-EZVRSZMK.cjs → chunk-CYVNOIXS.cjs} +11 -11
  21. package/dist/{chunk-EZVRSZMK.cjs.map → chunk-CYVNOIXS.cjs.map} +1 -1
  22. package/dist/{chunk-MCUX2D5Q.js → chunk-FVNT7VTO.js} +29 -13
  23. package/dist/chunk-FVNT7VTO.js.map +1 -0
  24. package/dist/{chunk-T3WZCEC4.js → chunk-IHJDOC3A.js} +34 -587
  25. package/dist/chunk-IHJDOC3A.js.map +1 -0
  26. package/dist/{chunk-QUKUN6NR.cjs → chunk-ISMGVGUM.cjs} +105 -5
  27. package/dist/chunk-ISMGVGUM.cjs.map +1 -0
  28. package/dist/{chunk-4RSHBKDJ.cjs → chunk-IWB65P37.cjs} +5 -5
  29. package/dist/{chunk-4RSHBKDJ.cjs.map → chunk-IWB65P37.cjs.map} +1 -1
  30. package/dist/{chunk-5CWWU22H.js → chunk-IWQDBVJK.js} +3 -3
  31. package/dist/{chunk-5CWWU22H.js.map → chunk-IWQDBVJK.js.map} +1 -1
  32. package/dist/{chunk-KOSW5PP5.js → chunk-MDKPL2R2.js} +464 -124
  33. package/dist/chunk-MDKPL2R2.js.map +1 -0
  34. package/dist/{chunk-UIZSWUKP.js → chunk-NZAXAFI3.js} +104 -6
  35. package/dist/chunk-NZAXAFI3.js.map +1 -0
  36. package/dist/{chunk-GRGPQ32U.js → chunk-RXDJL5QT.js} +3 -3
  37. package/dist/{chunk-GRGPQ32U.js.map → chunk-RXDJL5QT.js.map} +1 -1
  38. package/dist/{chunk-YQ7NLZZ3.cjs → chunk-S6OEQHEI.cjs} +61 -614
  39. package/dist/chunk-S6OEQHEI.cjs.map +1 -0
  40. package/dist/{chunk-G3OOCXAI.js → chunk-U7VECK2G.js} +4 -4
  41. package/dist/{chunk-G3OOCXAI.js.map → chunk-U7VECK2G.js.map} +1 -1
  42. package/dist/{chunk-G36A2JRR.cjs → chunk-VSM3NLUX.cjs} +296 -199
  43. package/dist/chunk-VSM3NLUX.cjs.map +1 -0
  44. package/dist/{chunk-3VOUB4ZU.cjs → chunk-VZC4BWWH.cjs} +8 -8
  45. package/dist/{chunk-3VOUB4ZU.cjs.map → chunk-VZC4BWWH.cjs.map} +1 -1
  46. package/dist/{chunk-BAMR7HKO.js → chunk-W3DD3XP5.js} +296 -199
  47. package/dist/chunk-W3DD3XP5.js.map +1 -0
  48. package/dist/{chunk-JTXVR2RA.cjs → chunk-WQSGX6XA.cjs} +5 -5
  49. package/dist/{chunk-JTXVR2RA.cjs.map → chunk-WQSGX6XA.cjs.map} +1 -1
  50. package/dist/{chunk-VU6DVS7J.js → chunk-WTYNK7Q4.js} +4 -4
  51. package/dist/{chunk-VU6DVS7J.js.map → chunk-WTYNK7Q4.js.map} +1 -1
  52. package/dist/{chunk-CKGIPST2.js → chunk-XXBWX7DT.js} +138 -106
  53. package/dist/chunk-XXBWX7DT.js.map +1 -0
  54. package/dist/{chunk-ZPMFINU2.cjs → chunk-ZCVTH3CH.cjs} +464 -130
  55. package/dist/chunk-ZCVTH3CH.cjs.map +1 -0
  56. package/dist/evals/index.cjs +4 -4
  57. package/dist/evals/index.js +1 -1
  58. package/dist/evals/scoreTraces/index.cjs +3 -3
  59. package/dist/evals/scoreTraces/index.js +1 -1
  60. package/dist/index.cjs +2 -2
  61. package/dist/index.js +1 -1
  62. package/dist/llm/index.cjs +14 -14
  63. package/dist/llm/index.js +5 -5
  64. package/dist/llm/model/aisdk/v5/model.d.ts.map +1 -1
  65. package/dist/loop/index.cjs +2 -2
  66. package/dist/loop/index.js +1 -1
  67. package/dist/loop/test-utils/generateText.d.ts.map +1 -1
  68. package/dist/loop/test-utils/resultObject.d.ts.map +1 -1
  69. package/dist/loop/test-utils/toUIMessageStream.d.ts.map +1 -1
  70. package/dist/loop/test-utils/utils.d.ts.map +1 -1
  71. package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts.map +1 -1
  72. package/dist/loop/workflows/agentic-execution/llm-mapping-step.d.ts.map +1 -1
  73. package/dist/mastra/index.cjs +2 -2
  74. package/dist/mastra/index.js +1 -1
  75. package/dist/memory/index.cjs +6 -6
  76. package/dist/memory/index.js +3 -3
  77. package/dist/models-dev-6PRLJKVZ.js +3 -0
  78. package/dist/{models-dev-GCVENVWA.js.map → models-dev-6PRLJKVZ.js.map} +1 -1
  79. package/dist/models-dev-WHMI5G6Y.cjs +12 -0
  80. package/dist/{models-dev-TIBJR6IG.cjs.map → models-dev-WHMI5G6Y.cjs.map} +1 -1
  81. package/dist/netlify-46I3SNNV.cjs +12 -0
  82. package/dist/{netlify-NTSNNT6F.cjs.map → netlify-46I3SNNV.cjs.map} +1 -1
  83. package/dist/netlify-EBQ6YUC6.js +3 -0
  84. package/dist/{netlify-O5NJW7CF.js.map → netlify-EBQ6YUC6.js.map} +1 -1
  85. package/dist/processors/index.cjs +11 -11
  86. package/dist/processors/index.js +1 -1
  87. package/dist/provider-registry-HDG6UMUC.js +3 -0
  88. package/dist/{provider-registry-74GMFZKT.js.map → provider-registry-HDG6UMUC.js.map} +1 -1
  89. package/dist/provider-registry-RP2W4B24.cjs +40 -0
  90. package/dist/{provider-registry-BZP3DIIV.cjs.map → provider-registry-RP2W4B24.cjs.map} +1 -1
  91. package/dist/relevance/index.cjs +2 -2
  92. package/dist/relevance/index.js +1 -1
  93. package/dist/server/auth.d.ts +11 -0
  94. package/dist/server/auth.d.ts.map +1 -1
  95. package/dist/server/index.cjs +10 -0
  96. package/dist/server/index.cjs.map +1 -1
  97. package/dist/server/index.js +10 -0
  98. package/dist/server/index.js.map +1 -1
  99. package/dist/storage/index.cjs +29 -29
  100. package/dist/storage/index.js +1 -1
  101. package/dist/stream/aisdk/v5/compat/prepare-tools.d.ts.map +1 -1
  102. package/dist/stream/index.cjs +11 -11
  103. package/dist/stream/index.js +2 -2
  104. package/dist/test-utils/llm-mock.cjs +66 -29
  105. package/dist/test-utils/llm-mock.cjs.map +1 -1
  106. package/dist/test-utils/llm-mock.d.ts +4 -2
  107. package/dist/test-utils/llm-mock.d.ts.map +1 -1
  108. package/dist/test-utils/llm-mock.js +66 -29
  109. package/dist/test-utils/llm-mock.js.map +1 -1
  110. package/dist/voice/aisdk/index.d.ts +3 -0
  111. package/dist/voice/aisdk/index.d.ts.map +1 -0
  112. package/dist/voice/aisdk/speech.d.ts +23 -0
  113. package/dist/voice/aisdk/speech.d.ts.map +1 -0
  114. package/dist/voice/aisdk/transcription.d.ts +22 -0
  115. package/dist/voice/aisdk/transcription.d.ts.map +1 -0
  116. package/dist/voice/composite-voice.d.ts +4 -3
  117. package/dist/voice/composite-voice.d.ts.map +1 -1
  118. package/dist/voice/index.cjs +12 -4
  119. package/dist/voice/index.d.ts +1 -0
  120. package/dist/voice/index.d.ts.map +1 -1
  121. package/dist/voice/index.js +1 -1
  122. package/dist/workflows/evented/index.cjs +10 -10
  123. package/dist/workflows/evented/index.js +1 -1
  124. package/dist/workflows/index.cjs +19 -19
  125. package/dist/workflows/index.js +1 -1
  126. package/package.json +10 -10
  127. package/dist/chunk-4DWZ4Z6H.js.map +0 -1
  128. package/dist/chunk-BAMR7HKO.js.map +0 -1
  129. package/dist/chunk-CKGIPST2.js.map +0 -1
  130. package/dist/chunk-G36A2JRR.cjs.map +0 -1
  131. package/dist/chunk-KOSW5PP5.js.map +0 -1
  132. package/dist/chunk-MCUX2D5Q.js.map +0 -1
  133. package/dist/chunk-N4SJ4YX7.cjs.map +0 -1
  134. package/dist/chunk-OWX2PUFH.cjs.map +0 -1
  135. package/dist/chunk-QUKUN6NR.cjs.map +0 -1
  136. package/dist/chunk-T3WZCEC4.js.map +0 -1
  137. package/dist/chunk-UIZSWUKP.js.map +0 -1
  138. package/dist/chunk-VZGBVYXA.cjs.map +0 -1
  139. package/dist/chunk-YQ7NLZZ3.cjs.map +0 -1
  140. package/dist/chunk-ZPMFINU2.cjs.map +0 -1
  141. package/dist/models-dev-GCVENVWA.js +0 -3
  142. package/dist/models-dev-TIBJR6IG.cjs +0 -12
  143. package/dist/netlify-NTSNNT6F.cjs +0 -12
  144. package/dist/netlify-O5NJW7CF.js +0 -3
  145. package/dist/provider-registry-74GMFZKT.js +0 -3
  146. package/dist/provider-registry-BZP3DIIV.cjs +0 -40
@@ -499,24 +499,74 @@ function getRuntimeEnvironmentUserAgent(globalThisAny = globalThis) {
499
499
  }
500
500
  return "runtime/unknown";
501
501
  }
502
- function removeUndefinedEntries(record) {
503
- return Object.fromEntries(
504
- Object.entries(record).filter(([_key, value]) => value != null)
505
- );
502
+ function normalizeHeaders(headers) {
503
+ if (headers == null) {
504
+ return {};
505
+ }
506
+ const normalized = {};
507
+ if (headers instanceof Headers) {
508
+ headers.forEach((value, key) => {
509
+ normalized[key.toLowerCase()] = value;
510
+ });
511
+ } else {
512
+ if (!Array.isArray(headers)) {
513
+ headers = Object.entries(headers);
514
+ }
515
+ for (const [key, value] of headers) {
516
+ if (value != null) {
517
+ normalized[key.toLowerCase()] = value;
518
+ }
519
+ }
520
+ }
521
+ return normalized;
506
522
  }
507
523
  function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
508
- const cleanedHeaders = removeUndefinedEntries(
509
- headers != null ? headers : {}
510
- );
511
- const normalizedHeaders = new Headers(cleanedHeaders);
524
+ const normalizedHeaders = new Headers(normalizeHeaders(headers));
512
525
  const currentUserAgentHeader = normalizedHeaders.get("user-agent") || "";
513
526
  normalizedHeaders.set(
514
527
  "user-agent",
515
528
  [currentUserAgentHeader, ...userAgentSuffixParts].filter(Boolean).join(" ")
516
529
  );
517
- return Object.fromEntries(normalizedHeaders);
530
+ return Object.fromEntries(normalizedHeaders.entries());
531
+ }
532
+ var VERSION = "3.0.17" ;
533
+ var DEFAULT_SCHEMA_PREFIX = "JSON schema:";
534
+ var DEFAULT_SCHEMA_SUFFIX = "You MUST answer with a JSON object that matches the JSON schema above.";
535
+ var DEFAULT_GENERIC_SUFFIX = "You MUST answer with JSON.";
536
+ function injectJsonInstruction({
537
+ prompt,
538
+ schema,
539
+ schemaPrefix = schema != null ? DEFAULT_SCHEMA_PREFIX : void 0,
540
+ schemaSuffix = schema != null ? DEFAULT_SCHEMA_SUFFIX : DEFAULT_GENERIC_SUFFIX
541
+ }) {
542
+ return [
543
+ prompt != null && prompt.length > 0 ? prompt : void 0,
544
+ prompt != null && prompt.length > 0 ? "" : void 0,
545
+ // add a newline if prompt is not null
546
+ schemaPrefix,
547
+ schema != null ? JSON.stringify(schema) : void 0,
548
+ schemaSuffix
549
+ ].filter((line) => line != null).join("\n");
550
+ }
551
+ function injectJsonInstructionIntoMessages({
552
+ messages,
553
+ schema,
554
+ schemaPrefix,
555
+ schemaSuffix
556
+ }) {
557
+ var _a15, _b;
558
+ const systemMessage = ((_a15 = messages[0]) == null ? void 0 : _a15.role) === "system" ? { ...messages[0] } : { role: "system", content: "" };
559
+ systemMessage.content = injectJsonInstruction({
560
+ prompt: systemMessage.content,
561
+ schema,
562
+ schemaPrefix,
563
+ schemaSuffix
564
+ });
565
+ return [
566
+ systemMessage,
567
+ ...((_b = messages[0]) == null ? void 0 : _b.role) === "system" ? messages.slice(1) : messages
568
+ ];
518
569
  }
519
- var VERSION = "3.0.12" ;
520
570
  function loadApiKey({
521
571
  apiKey,
522
572
  environmentVariableName,
@@ -612,7 +662,11 @@ function filter(obj) {
612
662
  }
613
663
  function secureJsonParse(text) {
614
664
  const { stackTraceLimit } = Error;
615
- Error.stackTraceLimit = 0;
665
+ try {
666
+ Error.stackTraceLimit = 0;
667
+ } catch (e) {
668
+ return _parse(text);
669
+ }
616
670
  try {
617
671
  return _parse(text);
618
672
  } finally {
@@ -3537,7 +3591,7 @@ var OpenAICompatibleImageModel = class {
3537
3591
  var openaiCompatibleImageResponseSchema = z.object({
3538
3592
  data: z.array(z.object({ b64_json: z.string() }))
3539
3593
  });
3540
- var VERSION2 = "1.0.22" ;
3594
+ var VERSION2 = "1.0.27" ;
3541
3595
  function createOpenAICompatible(options) {
3542
3596
  const baseURL = withoutTrailingSlash(options.baseURL);
3543
3597
  const providerName = options.name;
@@ -3590,7 +3644,7 @@ var MastraModelGateway = class {
3590
3644
  return this.id;
3591
3645
  }
3592
3646
  };
3593
- var VERSION3 = "2.0.33" ;
3647
+ var VERSION3 = "2.0.45" ;
3594
3648
  var anthropicErrorDataSchema = lazySchema(
3595
3649
  () => zodSchema(
3596
3650
  z.object({
@@ -3792,7 +3846,18 @@ var anthropicMessagesResponseSchema = lazySchema(
3792
3846
  output_tokens: z.number(),
3793
3847
  cache_creation_input_tokens: z.number().nullish(),
3794
3848
  cache_read_input_tokens: z.number().nullish()
3795
- })
3849
+ }),
3850
+ container: z.object({
3851
+ expires_at: z.string(),
3852
+ id: z.string(),
3853
+ skills: z.array(
3854
+ z.object({
3855
+ type: z.union([z.literal("anthropic"), z.literal("custom")]),
3856
+ skill_id: z.string(),
3857
+ version: z.string()
3858
+ })
3859
+ ).nullish()
3860
+ }).nullish()
3796
3861
  })
3797
3862
  )
3798
3863
  );
@@ -4022,7 +4087,21 @@ var anthropicMessagesChunkSchema = lazySchema(
4022
4087
  type: z.literal("message_delta"),
4023
4088
  delta: z.object({
4024
4089
  stop_reason: z.string().nullish(),
4025
- stop_sequence: z.string().nullish()
4090
+ stop_sequence: z.string().nullish(),
4091
+ container: z.object({
4092
+ expires_at: z.string(),
4093
+ id: z.string(),
4094
+ skills: z.array(
4095
+ z.object({
4096
+ type: z.union([
4097
+ z.literal("anthropic"),
4098
+ z.literal("custom")
4099
+ ]),
4100
+ skill_id: z.string(),
4101
+ version: z.string()
4102
+ })
4103
+ ).nullish()
4104
+ }).nullish()
4026
4105
  }),
4027
4106
  usage: z.looseObject({
4028
4107
  output_tokens: z.number(),
@@ -5265,6 +5344,21 @@ var AnthropicMessagesLanguageModel = class {
5265
5344
  setting: "seed"
5266
5345
  });
5267
5346
  }
5347
+ if (temperature != null && temperature > 1) {
5348
+ warnings.push({
5349
+ type: "unsupported-setting",
5350
+ setting: "temperature",
5351
+ details: `${temperature} exceeds anthropic maximum of 1.0. clamped to 1.0`
5352
+ });
5353
+ temperature = 1;
5354
+ } else if (temperature != null && temperature < 0) {
5355
+ warnings.push({
5356
+ type: "unsupported-setting",
5357
+ setting: "temperature",
5358
+ details: `${temperature} is below anthropic minimum of 0. clamped to 0`
5359
+ });
5360
+ temperature = 0;
5361
+ }
5268
5362
  if ((responseFormat == null ? void 0 : responseFormat.type) === "json") {
5269
5363
  if (responseFormat.schema == null) {
5270
5364
  warnings.push({
@@ -5300,7 +5394,7 @@ var AnthropicMessagesLanguageModel = class {
5300
5394
  });
5301
5395
  const isThinking = ((_b = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _b.type) === "enabled";
5302
5396
  const thinkingBudget = (_c = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _c.budgetTokens;
5303
- const maxOutputTokensForModel = getMaxOutputTokensForModel(this.modelId);
5397
+ const { maxOutputTokens: maxOutputTokensForModel, knownModel } = getMaxOutputTokensForModel(this.modelId);
5304
5398
  const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
5305
5399
  const baseArgs = {
5306
5400
  // model id:
@@ -5362,7 +5456,7 @@ var AnthropicMessagesLanguageModel = class {
5362
5456
  }
5363
5457
  baseArgs.max_tokens = maxTokens + thinkingBudget;
5364
5458
  }
5365
- if (baseArgs.max_tokens > maxOutputTokensForModel) {
5459
+ if (knownModel && baseArgs.max_tokens > maxOutputTokensForModel) {
5366
5460
  if (maxOutputTokens != null) {
5367
5461
  warnings.push({
5368
5462
  type: "unsupported-setting",
@@ -5457,7 +5551,7 @@ var AnthropicMessagesLanguageModel = class {
5457
5551
  });
5458
5552
  }
5459
5553
  async doGenerate(options) {
5460
- var _a15, _b, _c, _d, _e, _f;
5554
+ var _a15, _b, _c, _d, _e, _f, _g, _h;
5461
5555
  const { args, warnings, betas, usesJsonResponseTool } = await this.getArgs(options);
5462
5556
  const citationDocuments = this.extractCitationDocuments(options.prompt);
5463
5557
  const {
@@ -5708,7 +5802,16 @@ var AnthropicMessagesLanguageModel = class {
5708
5802
  anthropic: {
5709
5803
  usage: response.usage,
5710
5804
  cacheCreationInputTokens: (_e = response.usage.cache_creation_input_tokens) != null ? _e : null,
5711
- stopSequence: (_f = response.stop_sequence) != null ? _f : null
5805
+ stopSequence: (_f = response.stop_sequence) != null ? _f : null,
5806
+ container: response.container ? {
5807
+ expiresAt: response.container.expires_at,
5808
+ id: response.container.id,
5809
+ skills: (_h = (_g = response.container.skills) == null ? void 0 : _g.map((skill) => ({
5810
+ type: skill.type,
5811
+ skillId: skill.skill_id,
5812
+ version: skill.version
5813
+ }))) != null ? _h : null
5814
+ } : null
5712
5815
  }
5713
5816
  }
5714
5817
  };
@@ -5738,6 +5841,7 @@ var AnthropicMessagesLanguageModel = class {
5738
5841
  let rawUsage = void 0;
5739
5842
  let cacheCreationInputTokens = null;
5740
5843
  let stopSequence = null;
5844
+ let container = null;
5741
5845
  let blockType = void 0;
5742
5846
  const generateId3 = this.generateId;
5743
5847
  return {
@@ -5747,7 +5851,7 @@ var AnthropicMessagesLanguageModel = class {
5747
5851
  controller.enqueue({ type: "stream-start", warnings });
5748
5852
  },
5749
5853
  transform(chunk, controller) {
5750
- var _a15, _b, _c, _d, _e, _f, _g, _h;
5854
+ var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j;
5751
5855
  if (options.includeRawChunks) {
5752
5856
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
5753
5857
  }
@@ -5860,7 +5964,8 @@ var AnthropicMessagesLanguageModel = class {
5860
5964
  data: part.content.content.source.data
5861
5965
  }
5862
5966
  }
5863
- }
5967
+ },
5968
+ providerExecuted: true
5864
5969
  });
5865
5970
  } else if (part.content.type === "web_fetch_tool_result_error") {
5866
5971
  controller.enqueue({
@@ -6128,6 +6233,15 @@ var AnthropicMessagesLanguageModel = class {
6128
6233
  isJsonResponseFromTool: usesJsonResponseTool
6129
6234
  });
6130
6235
  stopSequence = (_h = value.delta.stop_sequence) != null ? _h : null;
6236
+ container = value.delta.container != null ? {
6237
+ expiresAt: value.delta.container.expires_at,
6238
+ id: value.delta.container.id,
6239
+ skills: (_j = (_i = value.delta.container.skills) == null ? void 0 : _i.map((skill) => ({
6240
+ type: skill.type,
6241
+ skillId: skill.skill_id,
6242
+ version: skill.version
6243
+ }))) != null ? _j : null
6244
+ } : null;
6131
6245
  rawUsage = {
6132
6246
  ...rawUsage,
6133
6247
  ...value.usage
@@ -6143,7 +6257,8 @@ var AnthropicMessagesLanguageModel = class {
6143
6257
  anthropic: {
6144
6258
  usage: rawUsage != null ? rawUsage : null,
6145
6259
  cacheCreationInputTokens,
6146
- stopSequence
6260
+ stopSequence,
6261
+ container
6147
6262
  }
6148
6263
  }
6149
6264
  });
@@ -6168,13 +6283,15 @@ var AnthropicMessagesLanguageModel = class {
6168
6283
  };
6169
6284
  function getMaxOutputTokensForModel(modelId) {
6170
6285
  if (modelId.includes("claude-sonnet-4-") || modelId.includes("claude-3-7-sonnet") || modelId.includes("claude-haiku-4-5")) {
6171
- return 64e3;
6286
+ return { maxOutputTokens: 64e3, knownModel: true };
6172
6287
  } else if (modelId.includes("claude-opus-4-")) {
6173
- return 32e3;
6288
+ return { maxOutputTokens: 32e3, knownModel: true };
6174
6289
  } else if (modelId.includes("claude-3-5-haiku")) {
6175
- return 8192;
6290
+ return { maxOutputTokens: 8192, knownModel: true };
6291
+ } else if (modelId.includes("claude-3-haiku")) {
6292
+ return { maxOutputTokens: 4096, knownModel: true };
6176
6293
  } else {
6177
- return 4096;
6294
+ return { maxOutputTokens: 4096, knownModel: false };
6178
6295
  }
6179
6296
  }
6180
6297
  var bash_20241022InputSchema = lazySchema(
@@ -6510,8 +6627,14 @@ var anthropicTools = {
6510
6627
  webSearch_20250305
6511
6628
  };
6512
6629
  function createAnthropic(options = {}) {
6513
- var _a15;
6514
- const baseURL = (_a15 = withoutTrailingSlash(options.baseURL)) != null ? _a15 : "https://api.anthropic.com/v1";
6630
+ var _a15, _b;
6631
+ const baseURL = (_a15 = withoutTrailingSlash(
6632
+ loadOptionalSetting({
6633
+ settingValue: options.baseURL,
6634
+ environmentVariableName: "ANTHROPIC_BASE_URL"
6635
+ })
6636
+ )) != null ? _a15 : "https://api.anthropic.com/v1";
6637
+ const providerName = (_b = options.name) != null ? _b : "anthropic.messages";
6515
6638
  const getHeaders = () => withUserAgentSuffix(
6516
6639
  {
6517
6640
  "anthropic-version": "2023-06-01",
@@ -6527,7 +6650,7 @@ function createAnthropic(options = {}) {
6527
6650
  const createChatModel = (modelId) => {
6528
6651
  var _a22;
6529
6652
  return new AnthropicMessagesLanguageModel(modelId, {
6530
- provider: "anthropic.messages",
6653
+ provider: providerName,
6531
6654
  baseURL,
6532
6655
  headers: getHeaders,
6533
6656
  fetch: options.fetch,
@@ -6558,7 +6681,7 @@ function createAnthropic(options = {}) {
6558
6681
  return provider;
6559
6682
  }
6560
6683
  createAnthropic();
6561
- var VERSION4 = "2.0.23" ;
6684
+ var VERSION4 = "2.0.39" ;
6562
6685
  var googleErrorDataSchema = lazySchema(
6563
6686
  () => zodSchema(
6564
6687
  z.object({
@@ -6858,19 +6981,20 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
6858
6981
  contents.push({
6859
6982
  role: "model",
6860
6983
  parts: content.map((part) => {
6861
- var _a22, _b, _c, _d, _e, _f;
6984
+ var _a22, _b, _c;
6985
+ const thoughtSignature = ((_b = (_a22 = part.providerOptions) == null ? void 0 : _a22.google) == null ? void 0 : _b.thoughtSignature) != null ? String((_c = part.providerOptions.google) == null ? void 0 : _c.thoughtSignature) : void 0;
6862
6986
  switch (part.type) {
6863
6987
  case "text": {
6864
6988
  return part.text.length === 0 ? void 0 : {
6865
6989
  text: part.text,
6866
- thoughtSignature: (_b = (_a22 = part.providerOptions) == null ? void 0 : _a22.google) == null ? void 0 : _b.thoughtSignature
6990
+ thoughtSignature
6867
6991
  };
6868
6992
  }
6869
6993
  case "reasoning": {
6870
6994
  return part.text.length === 0 ? void 0 : {
6871
6995
  text: part.text,
6872
6996
  thought: true,
6873
- thoughtSignature: (_d = (_c = part.providerOptions) == null ? void 0 : _c.google) == null ? void 0 : _d.thoughtSignature
6997
+ thoughtSignature
6874
6998
  };
6875
6999
  }
6876
7000
  case "file": {
@@ -6897,7 +7021,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
6897
7021
  name: part.toolName,
6898
7022
  args: part.input
6899
7023
  },
6900
- thoughtSignature: (_f = (_e = part.providerOptions) == null ? void 0 : _e.google) == null ? void 0 : _f.thoughtSignature
7024
+ thoughtSignature
6901
7025
  };
6902
7026
  }
6903
7027
  }
@@ -6980,7 +7104,9 @@ var googleGenerativeAIProviderOptions = lazySchema(
6980
7104
  responseModalities: z.array(z.enum(["TEXT", "IMAGE"])).optional(),
6981
7105
  thinkingConfig: z.object({
6982
7106
  thinkingBudget: z.number().optional(),
6983
- includeThoughts: z.boolean().optional()
7107
+ includeThoughts: z.boolean().optional(),
7108
+ // https://ai.google.dev/gemini-api/docs/gemini-3?thinking=high#thinking_level
7109
+ thinkingLevel: z.enum(["low", "medium", "high"]).optional()
6984
7110
  }).optional(),
6985
7111
  /**
6986
7112
  * Optional.
@@ -7081,8 +7207,14 @@ function prepareTools3({
7081
7207
  var _a15;
7082
7208
  tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
7083
7209
  const toolWarnings = [];
7084
- const isGemini2 = modelId.includes("gemini-2");
7210
+ const isLatest = [
7211
+ "gemini-flash-latest",
7212
+ "gemini-flash-lite-latest",
7213
+ "gemini-pro-latest"
7214
+ ].some((id) => id === modelId);
7215
+ const isGemini2orNewer = modelId.includes("gemini-2") || modelId.includes("gemini-3") || isLatest;
7085
7216
  const supportsDynamicRetrieval = modelId.includes("gemini-1.5-flash") && !modelId.includes("-8b");
7217
+ const supportsFileSearch = modelId.includes("gemini-2.5");
7086
7218
  if (tools == null) {
7087
7219
  return { tools: void 0, toolConfig: void 0, toolWarnings };
7088
7220
  }
@@ -7091,10 +7223,11 @@ function prepareTools3({
7091
7223
  (tool2) => tool2.type === "provider-defined"
7092
7224
  );
7093
7225
  if (hasFunctionTools && hasProviderDefinedTools) {
7226
+ const functionTools = tools.filter((tool2) => tool2.type === "function");
7094
7227
  toolWarnings.push({
7095
7228
  type: "unsupported-tool",
7096
7229
  tool: tools.find((tool2) => tool2.type === "function"),
7097
- details: "Cannot mix function tools with provider-defined tools in the same request. Please use either function tools or provider-defined tools, but not both."
7230
+ details: `Cannot mix function tools with provider-defined tools in the same request. Falling back to provider-defined tools only. The following function tools will be ignored: ${functionTools.map((t) => t.name).join(", ")}. Please use either function tools or provider-defined tools, but not both.`
7098
7231
  });
7099
7232
  }
7100
7233
  if (hasProviderDefinedTools) {
@@ -7105,7 +7238,7 @@ function prepareTools3({
7105
7238
  providerDefinedTools.forEach((tool2) => {
7106
7239
  switch (tool2.id) {
7107
7240
  case "google.google_search":
7108
- if (isGemini2) {
7241
+ if (isGemini2orNewer) {
7109
7242
  googleTools2.push({ googleSearch: {} });
7110
7243
  } else if (supportsDynamicRetrieval) {
7111
7244
  googleTools2.push({
@@ -7121,7 +7254,7 @@ function prepareTools3({
7121
7254
  }
7122
7255
  break;
7123
7256
  case "google.url_context":
7124
- if (isGemini2) {
7257
+ if (isGemini2orNewer) {
7125
7258
  googleTools2.push({ urlContext: {} });
7126
7259
  } else {
7127
7260
  toolWarnings.push({
@@ -7132,7 +7265,7 @@ function prepareTools3({
7132
7265
  }
7133
7266
  break;
7134
7267
  case "google.code_execution":
7135
- if (isGemini2) {
7268
+ if (isGemini2orNewer) {
7136
7269
  googleTools2.push({ codeExecution: {} });
7137
7270
  } else {
7138
7271
  toolWarnings.push({
@@ -7142,6 +7275,37 @@ function prepareTools3({
7142
7275
  });
7143
7276
  }
7144
7277
  break;
7278
+ case "google.file_search":
7279
+ if (supportsFileSearch) {
7280
+ googleTools2.push({ fileSearch: { ...tool2.args } });
7281
+ } else {
7282
+ toolWarnings.push({
7283
+ type: "unsupported-tool",
7284
+ tool: tool2,
7285
+ details: "The file search tool is only supported with Gemini 2.5 models."
7286
+ });
7287
+ }
7288
+ break;
7289
+ case "google.vertex_rag_store":
7290
+ if (isGemini2orNewer) {
7291
+ googleTools2.push({
7292
+ retrieval: {
7293
+ vertex_rag_store: {
7294
+ rag_resources: {
7295
+ rag_corpus: tool2.args.ragCorpus
7296
+ },
7297
+ similarity_top_k: tool2.args.topK
7298
+ }
7299
+ }
7300
+ });
7301
+ } else {
7302
+ toolWarnings.push({
7303
+ type: "unsupported-tool",
7304
+ tool: tool2,
7305
+ details: "The RAG store tool is not supported with other Gemini models than Gemini 2."
7306
+ });
7307
+ }
7308
+ break;
7145
7309
  default:
7146
7310
  toolWarnings.push({ type: "unsupported-tool", tool: tool2 });
7147
7311
  break;
@@ -7269,17 +7433,19 @@ var GoogleGenerativeAILanguageModel = class {
7269
7433
  toolChoice,
7270
7434
  providerOptions
7271
7435
  }) {
7272
- var _a15, _b;
7436
+ var _a15;
7273
7437
  const warnings = [];
7274
7438
  const googleOptions = await parseProviderOptions({
7275
7439
  provider: "google",
7276
7440
  providerOptions,
7277
7441
  schema: googleGenerativeAIProviderOptions
7278
7442
  });
7279
- if (((_a15 = googleOptions == null ? void 0 : googleOptions.thinkingConfig) == null ? void 0 : _a15.includeThoughts) === true && !this.config.provider.startsWith("google.vertex.")) {
7443
+ if ((tools == null ? void 0 : tools.some(
7444
+ (tool2) => tool2.type === "provider-defined" && tool2.id === "google.vertex_rag_store"
7445
+ )) && !this.config.provider.startsWith("google.vertex.")) {
7280
7446
  warnings.push({
7281
7447
  type: "other",
7282
- message: `The 'includeThoughts' option is only supported with the Google Vertex provider and might not be supported or could behave unexpectedly with the current Google provider (${this.config.provider}).`
7448
+ message: `The 'vertex_rag_store' tool is only supported with the Google Vertex provider and might not be supported or could behave unexpectedly with the current Google provider (${this.config.provider}).`
7283
7449
  });
7284
7450
  }
7285
7451
  const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
@@ -7313,7 +7479,7 @@ var GoogleGenerativeAILanguageModel = class {
7313
7479
  responseSchema: (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && // Google GenAI does not support all OpenAPI Schema features,
7314
7480
  // so this is needed as an escape hatch:
7315
7481
  // TODO convert into provider option
7316
- ((_b = googleOptions == null ? void 0 : googleOptions.structuredOutputs) != null ? _b : true) ? convertJSONSchemaToOpenAPISchema(responseFormat.schema) : void 0,
7482
+ ((_a15 = googleOptions == null ? void 0 : googleOptions.structuredOutputs) != null ? _a15 : true) ? convertJSONSchemaToOpenAPISchema(responseFormat.schema) : void 0,
7317
7483
  ...(googleOptions == null ? void 0 : googleOptions.audioTimestamp) && {
7318
7484
  audioTimestamp: googleOptions.audioTimestamp
7319
7485
  },
@@ -7725,16 +7891,64 @@ function extractSources({
7725
7891
  groundingMetadata,
7726
7892
  generateId: generateId3
7727
7893
  }) {
7728
- var _a15;
7729
- return (_a15 = groundingMetadata == null ? void 0 : groundingMetadata.groundingChunks) == null ? void 0 : _a15.filter(
7730
- (chunk) => chunk.web != null
7731
- ).map((chunk) => ({
7732
- type: "source",
7733
- sourceType: "url",
7734
- id: generateId3(),
7735
- url: chunk.web.uri,
7736
- title: chunk.web.title
7737
- }));
7894
+ var _a15, _b, _c;
7895
+ if (!(groundingMetadata == null ? void 0 : groundingMetadata.groundingChunks)) {
7896
+ return void 0;
7897
+ }
7898
+ const sources = [];
7899
+ for (const chunk of groundingMetadata.groundingChunks) {
7900
+ if (chunk.web != null) {
7901
+ sources.push({
7902
+ type: "source",
7903
+ sourceType: "url",
7904
+ id: generateId3(),
7905
+ url: chunk.web.uri,
7906
+ title: (_a15 = chunk.web.title) != null ? _a15 : void 0
7907
+ });
7908
+ } else if (chunk.retrievedContext != null) {
7909
+ const uri = chunk.retrievedContext.uri;
7910
+ if (uri.startsWith("http://") || uri.startsWith("https://")) {
7911
+ sources.push({
7912
+ type: "source",
7913
+ sourceType: "url",
7914
+ id: generateId3(),
7915
+ url: uri,
7916
+ title: (_b = chunk.retrievedContext.title) != null ? _b : void 0
7917
+ });
7918
+ } else {
7919
+ const title = (_c = chunk.retrievedContext.title) != null ? _c : "Unknown Document";
7920
+ let mediaType = "application/octet-stream";
7921
+ let filename = void 0;
7922
+ if (uri.endsWith(".pdf")) {
7923
+ mediaType = "application/pdf";
7924
+ filename = uri.split("/").pop();
7925
+ } else if (uri.endsWith(".txt")) {
7926
+ mediaType = "text/plain";
7927
+ filename = uri.split("/").pop();
7928
+ } else if (uri.endsWith(".docx")) {
7929
+ mediaType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
7930
+ filename = uri.split("/").pop();
7931
+ } else if (uri.endsWith(".doc")) {
7932
+ mediaType = "application/msword";
7933
+ filename = uri.split("/").pop();
7934
+ } else if (uri.match(/\.(md|markdown)$/)) {
7935
+ mediaType = "text/markdown";
7936
+ filename = uri.split("/").pop();
7937
+ } else {
7938
+ filename = uri.split("/").pop();
7939
+ }
7940
+ sources.push({
7941
+ type: "source",
7942
+ sourceType: "document",
7943
+ id: generateId3(),
7944
+ mediaType,
7945
+ title,
7946
+ filename
7947
+ });
7948
+ }
7949
+ }
7950
+ }
7951
+ return sources.length > 0 ? sources : void 0;
7738
7952
  }
7739
7953
  var getGroundingMetadataSchema = () => z.object({
7740
7954
  webSearchQueries: z.array(z.string()).nullish(),
@@ -7742,8 +7956,12 @@ var getGroundingMetadataSchema = () => z.object({
7742
7956
  searchEntryPoint: z.object({ renderedContent: z.string() }).nullish(),
7743
7957
  groundingChunks: z.array(
7744
7958
  z.object({
7745
- web: z.object({ uri: z.string(), title: z.string() }).nullish(),
7746
- retrievedContext: z.object({ uri: z.string(), title: z.string() }).nullish()
7959
+ web: z.object({ uri: z.string(), title: z.string().nullish() }).nullish(),
7960
+ retrievedContext: z.object({
7961
+ uri: z.string(),
7962
+ title: z.string().nullish(),
7963
+ text: z.string().nullish()
7964
+ }).nullish()
7747
7965
  })
7748
7966
  ).nullish(),
7749
7967
  groundingSupports: z.array(
@@ -7813,7 +8031,9 @@ var usageSchema2 = z.object({
7813
8031
  thoughtsTokenCount: z.number().nullish(),
7814
8032
  promptTokenCount: z.number().nullish(),
7815
8033
  candidatesTokenCount: z.number().nullish(),
7816
- totalTokenCount: z.number().nullish()
8034
+ totalTokenCount: z.number().nullish(),
8035
+ // https://cloud.google.com/vertex-ai/generative-ai/docs/reference/rest/v1/GenerateContentResponse#TrafficType
8036
+ trafficType: z.string().nullish()
7817
8037
  });
7818
8038
  var getUrlContextMetadataSchema = () => z.object({
7819
8039
  urlMetadata: z.array(
@@ -7875,6 +8095,30 @@ var codeExecution = createProviderDefinedToolFactoryWithOutputSchema({
7875
8095
  output: z.string().describe("The output from the code execution.")
7876
8096
  })
7877
8097
  });
8098
+ var fileSearchArgsBaseSchema = z.object({
8099
+ /** The names of the file_search_stores to retrieve from.
8100
+ * Example: `fileSearchStores/my-file-search-store-123`
8101
+ */
8102
+ fileSearchStoreNames: z.array(z.string()).describe(
8103
+ "The names of the file_search_stores to retrieve from. Example: `fileSearchStores/my-file-search-store-123`"
8104
+ ),
8105
+ /** The number of file search retrieval chunks to retrieve. */
8106
+ topK: z.number().int().positive().describe("The number of file search retrieval chunks to retrieve.").optional(),
8107
+ /** Metadata filter to apply to the file search retrieval documents.
8108
+ * See https://google.aip.dev/160 for the syntax of the filter expression.
8109
+ */
8110
+ metadataFilter: z.string().describe(
8111
+ "Metadata filter to apply to the file search retrieval documents. See https://google.aip.dev/160 for the syntax of the filter expression."
8112
+ ).optional()
8113
+ }).passthrough();
8114
+ var fileSearchArgsSchema = lazySchema(
8115
+ () => zodSchema(fileSearchArgsBaseSchema)
8116
+ );
8117
+ var fileSearch = createProviderDefinedToolFactory({
8118
+ id: "google.file_search",
8119
+ name: "file_search",
8120
+ inputSchema: fileSearchArgsSchema
8121
+ });
7878
8122
  var googleSearch = createProviderDefinedToolFactory({
7879
8123
  id: "google.google_search",
7880
8124
  name: "google_search",
@@ -7892,6 +8136,14 @@ var urlContext = createProviderDefinedToolFactory({
7892
8136
  name: "url_context",
7893
8137
  inputSchema: lazySchema(() => zodSchema(z.object({})))
7894
8138
  });
8139
+ var vertexRagStore = createProviderDefinedToolFactory({
8140
+ id: "google.vertex_rag_store",
8141
+ name: "vertex_rag_store",
8142
+ inputSchema: z.object({
8143
+ ragCorpus: z.string(),
8144
+ topK: z.number().optional()
8145
+ })
8146
+ });
7895
8147
  var googleTools = {
7896
8148
  /**
7897
8149
  * Creates a Google search tool that gives Google direct access to real-time web content.
@@ -7903,6 +8155,17 @@ var googleTools = {
7903
8155
  * Must have name "url_context".
7904
8156
  */
7905
8157
  urlContext,
8158
+ /**
8159
+ * Enables Retrieval Augmented Generation (RAG) via the Gemini File Search tool.
8160
+ * Must have name "file_search".
8161
+ *
8162
+ * @param fileSearchStoreNames - Fully-qualified File Search store resource names.
8163
+ * @param metadataFilter - Optional filter expression to restrict the files that can be retrieved.
8164
+ * @param topK - Optional result limit for the number of chunks returned from File Search.
8165
+ *
8166
+ * @see https://ai.google.dev/gemini-api/docs/file-search
8167
+ */
8168
+ fileSearch,
7906
8169
  /**
7907
8170
  * A tool that enables the model to generate and run Python code.
7908
8171
  * Must have name "code_execution".
@@ -7913,7 +8176,12 @@ var googleTools = {
7913
8176
  * @see https://ai.google.dev/gemini-api/docs/code-execution (Google AI)
7914
8177
  * @see https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/code-execution-api (Vertex AI)
7915
8178
  */
7916
- codeExecution
8179
+ codeExecution,
8180
+ /**
8181
+ * Creates a Vertex RAG Store tool that enables the model to perform RAG searches against a Vertex RAG Store.
8182
+ * Must have name "vertex_rag_store".
8183
+ */
8184
+ vertexRagStore
7917
8185
  };
7918
8186
  var GoogleGenerativeAIImageModel = class {
7919
8187
  constructor(modelId, settings, config) {
@@ -8022,8 +8290,9 @@ var googleImageProviderOptionsSchema = lazySchema(
8022
8290
  )
8023
8291
  );
8024
8292
  function createGoogleGenerativeAI(options = {}) {
8025
- var _a15;
8293
+ var _a15, _b;
8026
8294
  const baseURL = (_a15 = withoutTrailingSlash(options.baseURL)) != null ? _a15 : "https://generativelanguage.googleapis.com/v1beta";
8295
+ const providerName = (_b = options.name) != null ? _b : "google.generative-ai";
8027
8296
  const getHeaders = () => withUserAgentSuffix(
8028
8297
  {
8029
8298
  "x-goog-api-key": loadApiKey({
@@ -8038,7 +8307,7 @@ function createGoogleGenerativeAI(options = {}) {
8038
8307
  const createChatModel = (modelId) => {
8039
8308
  var _a22;
8040
8309
  return new GoogleGenerativeAILanguageModel(modelId, {
8041
- provider: "google.generative-ai",
8310
+ provider: providerName,
8042
8311
  baseURL,
8043
8312
  headers: getHeaders,
8044
8313
  generateId: (_a22 = options.generateId) != null ? _a22 : generateId,
@@ -8058,13 +8327,13 @@ function createGoogleGenerativeAI(options = {}) {
8058
8327
  });
8059
8328
  };
8060
8329
  const createEmbeddingModel = (modelId) => new GoogleGenerativeAIEmbeddingModel(modelId, {
8061
- provider: "google.generative-ai",
8330
+ provider: providerName,
8062
8331
  baseURL,
8063
8332
  headers: getHeaders,
8064
8333
  fetch: options.fetch
8065
8334
  });
8066
8335
  const createImageModel = (modelId, settings = {}) => new GoogleGenerativeAIImageModel(modelId, settings, {
8067
- provider: "google.generative-ai",
8336
+ provider: providerName,
8068
8337
  baseURL,
8069
8338
  headers: getHeaders,
8070
8339
  fetch: options.fetch
@@ -8286,7 +8555,7 @@ function getResponseMetadata3({
8286
8555
  return {
8287
8556
  id: id != null ? id : void 0,
8288
8557
  modelId: model != null ? model : void 0,
8289
- timestamp: created != null ? new Date(created * 1e3) : void 0
8558
+ timestamp: created ? new Date(created * 1e3) : void 0
8290
8559
  };
8291
8560
  }
8292
8561
  function mapOpenAIFinishReason(finishReason) {
@@ -8470,7 +8739,7 @@ var openaiChatLanguageModelOptions = lazyValidator(
8470
8739
  /**
8471
8740
  * Reasoning effort for reasoning models. Defaults to `medium`.
8472
8741
  */
8473
- reasoningEffort: z.enum(["minimal", "low", "medium", "high"]).optional(),
8742
+ reasoningEffort: z.enum(["none", "minimal", "low", "medium", "high"]).optional(),
8474
8743
  /**
8475
8744
  * Maximum number of completion tokens to generate. Useful for reasoning models.
8476
8745
  */
@@ -8520,6 +8789,15 @@ var openaiChatLanguageModelOptions = lazyValidator(
8520
8789
  * Useful for improving cache hit rates and working around automatic caching issues.
8521
8790
  */
8522
8791
  promptCacheKey: z.string().optional(),
8792
+ /**
8793
+ * The retention policy for the prompt cache.
8794
+ * - 'in_memory': Default. Standard prompt caching behavior.
8795
+ * - '24h': Extended prompt caching that keeps cached prefixes active for up to 24 hours.
8796
+ * Currently only available for 5.1 series models.
8797
+ *
8798
+ * @default 'in_memory'
8799
+ */
8800
+ promptCacheRetention: z.enum(["in_memory", "24h"]).optional(),
8523
8801
  /**
8524
8802
  * A stable identifier used to help detect users of your application
8525
8803
  * that may be violating OpenAI's usage policies. The IDs should be a
@@ -8681,6 +8959,7 @@ var OpenAIChatLanguageModel = class {
8681
8959
  reasoning_effort: openaiOptions.reasoningEffort,
8682
8960
  service_tier: openaiOptions.serviceTier,
8683
8961
  prompt_cache_key: openaiOptions.promptCacheKey,
8962
+ prompt_cache_retention: openaiOptions.promptCacheRetention,
8684
8963
  safety_identifier: openaiOptions.safetyIdentifier,
8685
8964
  // messages:
8686
8965
  messages
@@ -8896,7 +9175,7 @@ var OpenAIChatLanguageModel = class {
8896
9175
  outputTokens: void 0,
8897
9176
  totalTokens: void 0
8898
9177
  };
8899
- let isFirstChunk = true;
9178
+ let metadataExtracted = false;
8900
9179
  let isActiveText = false;
8901
9180
  const providerMetadata = { openai: {} };
8902
9181
  return {
@@ -8921,12 +9200,15 @@ var OpenAIChatLanguageModel = class {
8921
9200
  controller.enqueue({ type: "error", error: value.error });
8922
9201
  return;
8923
9202
  }
8924
- if (isFirstChunk) {
8925
- isFirstChunk = false;
8926
- controller.enqueue({
8927
- type: "response-metadata",
8928
- ...getResponseMetadata3(value)
8929
- });
9203
+ if (!metadataExtracted) {
9204
+ const metadata = getResponseMetadata3(value);
9205
+ if (Object.values(metadata).some(Boolean)) {
9206
+ metadataExtracted = true;
9207
+ controller.enqueue({
9208
+ type: "response-metadata",
9209
+ ...getResponseMetadata3(value)
9210
+ });
9211
+ }
8930
9212
  }
8931
9213
  if (value.usage != null) {
8932
9214
  usage.inputTokens = (_a15 = value.usage.prompt_tokens) != null ? _a15 : void 0;
@@ -9098,18 +9380,6 @@ function getSystemMessageMode(modelId) {
9098
9380
  return (_b = (_a15 = reasoningModels[modelId]) == null ? void 0 : _a15.systemMessageMode) != null ? _b : "developer";
9099
9381
  }
9100
9382
  var reasoningModels = {
9101
- "o1-mini": {
9102
- systemMessageMode: "remove"
9103
- },
9104
- "o1-mini-2024-09-12": {
9105
- systemMessageMode: "remove"
9106
- },
9107
- "o1-preview": {
9108
- systemMessageMode: "remove"
9109
- },
9110
- "o1-preview-2024-09-12": {
9111
- systemMessageMode: "remove"
9112
- },
9113
9383
  o3: {
9114
9384
  systemMessageMode: "developer"
9115
9385
  },
@@ -9645,7 +9915,7 @@ var openaiImageResponseSchema = lazyValidator(
9645
9915
  data: z.array(
9646
9916
  z.object({
9647
9917
  b64_json: z.string(),
9648
- revised_prompt: z.string().optional()
9918
+ revised_prompt: z.string().nullish()
9649
9919
  })
9650
9920
  )
9651
9921
  })
@@ -9790,7 +10060,7 @@ var compoundFilterSchema = z.object({
9790
10060
  z.union([comparisonFilterSchema, z.lazy(() => compoundFilterSchema)])
9791
10061
  )
9792
10062
  });
9793
- var fileSearchArgsSchema = lazySchema(
10063
+ var fileSearchArgsSchema2 = lazySchema(
9794
10064
  () => zodSchema(
9795
10065
  z.object({
9796
10066
  vectorStoreIds: z.array(z.string()),
@@ -9819,7 +10089,7 @@ var fileSearchOutputSchema = lazySchema(
9819
10089
  })
9820
10090
  )
9821
10091
  );
9822
- var fileSearch = createProviderDefinedToolFactoryWithOutputSchema({
10092
+ var fileSearch2 = createProviderDefinedToolFactoryWithOutputSchema({
9823
10093
  id: "openai.file_search",
9824
10094
  name: "file_search",
9825
10095
  inputSchema: z.object({}),
@@ -9913,7 +10183,13 @@ var webSearchOutputSchema = lazySchema(
9913
10183
  url: z.string(),
9914
10184
  pattern: z.string()
9915
10185
  })
9916
- ])
10186
+ ]),
10187
+ sources: z.array(
10188
+ z.discriminatedUnion("type", [
10189
+ z.object({ type: z.literal("url"), url: z.string() }),
10190
+ z.object({ type: z.literal("api"), name: z.string() })
10191
+ ])
10192
+ ).optional()
9917
10193
  })
9918
10194
  )
9919
10195
  );
@@ -9991,7 +10267,7 @@ var openaiTools = {
9991
10267
  * @param ranking - The ranking options to use for the file search.
9992
10268
  * @param filters - The filters to use for the file search.
9993
10269
  */
9994
- fileSearch,
10270
+ fileSearch: fileSearch2,
9995
10271
  /**
9996
10272
  * The image generation tool allows you to generate images using a text prompt,
9997
10273
  * and optionally image inputs. It leverages the GPT Image model,
@@ -10471,7 +10747,13 @@ var openaiResponsesChunkSchema = lazyValidator(
10471
10747
  action: z.discriminatedUnion("type", [
10472
10748
  z.object({
10473
10749
  type: z.literal("search"),
10474
- query: z.string().nullish()
10750
+ query: z.string().nullish(),
10751
+ sources: z.array(
10752
+ z.discriminatedUnion("type", [
10753
+ z.object({ type: z.literal("url"), url: z.string() }),
10754
+ z.object({ type: z.literal("api"), name: z.string() })
10755
+ ])
10756
+ ).nullish()
10475
10757
  }),
10476
10758
  z.object({
10477
10759
  type: z.literal("open_page"),
@@ -10579,10 +10861,13 @@ var openaiResponsesChunkSchema = lazyValidator(
10579
10861
  }),
10580
10862
  z.object({
10581
10863
  type: z.literal("error"),
10582
- code: z.string(),
10583
- message: z.string(),
10584
- param: z.string().nullish(),
10585
- sequence_number: z.number()
10864
+ sequence_number: z.number(),
10865
+ error: z.object({
10866
+ type: z.string(),
10867
+ code: z.string(),
10868
+ message: z.string(),
10869
+ param: z.string().nullish()
10870
+ })
10586
10871
  }),
10587
10872
  z.object({ type: z.string() }).loose().transform((value) => ({
10588
10873
  type: "unknown_chunk",
@@ -10595,13 +10880,15 @@ var openaiResponsesChunkSchema = lazyValidator(
10595
10880
  var openaiResponsesResponseSchema = lazyValidator(
10596
10881
  () => zodSchema(
10597
10882
  z.object({
10598
- id: z.string(),
10599
- created_at: z.number(),
10883
+ id: z.string().optional(),
10884
+ created_at: z.number().optional(),
10600
10885
  error: z.object({
10601
- code: z.string(),
10602
- message: z.string()
10886
+ message: z.string(),
10887
+ type: z.string(),
10888
+ param: z.string().nullish(),
10889
+ code: z.string()
10603
10890
  }).nullish(),
10604
- model: z.string(),
10891
+ model: z.string().optional(),
10605
10892
  output: z.array(
10606
10893
  z.discriminatedUnion("type", [
10607
10894
  z.object({
@@ -10643,7 +10930,18 @@ var openaiResponsesResponseSchema = lazyValidator(
10643
10930
  quote: z.string().nullish()
10644
10931
  }),
10645
10932
  z.object({
10646
- type: z.literal("container_file_citation")
10933
+ type: z.literal("container_file_citation"),
10934
+ container_id: z.string(),
10935
+ file_id: z.string(),
10936
+ filename: z.string().nullish(),
10937
+ start_index: z.number().nullish(),
10938
+ end_index: z.number().nullish(),
10939
+ index: z.number().nullish()
10940
+ }),
10941
+ z.object({
10942
+ type: z.literal("file_path"),
10943
+ file_id: z.string(),
10944
+ index: z.number().nullish()
10647
10945
  })
10648
10946
  ])
10649
10947
  )
@@ -10657,7 +10955,13 @@ var openaiResponsesResponseSchema = lazyValidator(
10657
10955
  action: z.discriminatedUnion("type", [
10658
10956
  z.object({
10659
10957
  type: z.literal("search"),
10660
- query: z.string().nullish()
10958
+ query: z.string().nullish(),
10959
+ sources: z.array(
10960
+ z.discriminatedUnion("type", [
10961
+ z.object({ type: z.literal("url"), url: z.string() }),
10962
+ z.object({ type: z.literal("api"), name: z.string() })
10963
+ ])
10964
+ ).nullish()
10661
10965
  }),
10662
10966
  z.object({
10663
10967
  type: z.literal("open_page"),
@@ -10676,7 +10980,10 @@ var openaiResponsesResponseSchema = lazyValidator(
10676
10980
  queries: z.array(z.string()),
10677
10981
  results: z.array(
10678
10982
  z.object({
10679
- attributes: z.record(z.string(), z.unknown()),
10983
+ attributes: z.record(
10984
+ z.string(),
10985
+ z.union([z.string(), z.number(), z.boolean()])
10986
+ ),
10680
10987
  file_id: z.string(),
10681
10988
  filename: z.string(),
10682
10989
  score: z.number(),
@@ -10738,7 +11045,7 @@ var openaiResponsesResponseSchema = lazyValidator(
10738
11045
  )
10739
11046
  })
10740
11047
  ])
10741
- ),
11048
+ ).optional(),
10742
11049
  service_tier: z.string().nullish(),
10743
11050
  incomplete_details: z.object({ reason: z.string() }).nullish(),
10744
11051
  usage: z.object({
@@ -10746,7 +11053,7 @@ var openaiResponsesResponseSchema = lazyValidator(
10746
11053
  input_tokens_details: z.object({ cached_tokens: z.number().nullish() }).nullish(),
10747
11054
  output_tokens: z.number(),
10748
11055
  output_tokens_details: z.object({ reasoning_tokens: z.number().nullish() }).nullish()
10749
- })
11056
+ }).optional()
10750
11057
  })
10751
11058
  )
10752
11059
  );
@@ -10754,6 +11061,7 @@ var TOP_LOGPROBS_MAX = 20;
10754
11061
  var openaiResponsesProviderOptionsSchema = lazyValidator(
10755
11062
  () => zodSchema(
10756
11063
  z.object({
11064
+ conversation: z.string().nullish(),
10757
11065
  include: z.array(
10758
11066
  z.enum([
10759
11067
  "reasoning.encrypted_content",
@@ -10786,6 +11094,15 @@ var openaiResponsesProviderOptionsSchema = lazyValidator(
10786
11094
  parallelToolCalls: z.boolean().nullish(),
10787
11095
  previousResponseId: z.string().nullish(),
10788
11096
  promptCacheKey: z.string().nullish(),
11097
+ /**
11098
+ * The retention policy for the prompt cache.
11099
+ * - 'in_memory': Default. Standard prompt caching behavior.
11100
+ * - '24h': Extended prompt caching that keeps cached prefixes active for up to 24 hours.
11101
+ * Currently only available for 5.1 series models.
11102
+ *
11103
+ * @default 'in_memory'
11104
+ */
11105
+ promptCacheRetention: z.enum(["in_memory", "24h"]).nullish(),
10789
11106
  reasoningEffort: z.string().nullish(),
10790
11107
  reasoningSummary: z.string().nullish(),
10791
11108
  safetyIdentifier: z.string().nullish(),
@@ -10825,7 +11142,7 @@ async function prepareResponsesTools({
10825
11142
  case "openai.file_search": {
10826
11143
  const args = await validateTypes({
10827
11144
  value: tool2.args,
10828
- schema: fileSearchArgsSchema
11145
+ schema: fileSearchArgsSchema2
10829
11146
  });
10830
11147
  openaiTools2.push({
10831
11148
  type: "file_search",
@@ -10991,6 +11308,13 @@ var OpenAIResponsesLanguageModel = class {
10991
11308
  providerOptions,
10992
11309
  schema: openaiResponsesProviderOptionsSchema
10993
11310
  });
11311
+ if ((openaiOptions == null ? void 0 : openaiOptions.conversation) && (openaiOptions == null ? void 0 : openaiOptions.previousResponseId)) {
11312
+ warnings.push({
11313
+ type: "unsupported-setting",
11314
+ setting: "conversation",
11315
+ details: "conversation and previousResponseId cannot be used together"
11316
+ });
11317
+ }
10994
11318
  const { input, warnings: inputWarnings } = await convertToOpenAIResponsesInput({
10995
11319
  prompt,
10996
11320
  systemMessageMode: modelConfig.systemMessageMode,
@@ -11053,6 +11377,7 @@ var OpenAIResponsesLanguageModel = class {
11053
11377
  }
11054
11378
  },
11055
11379
  // provider options:
11380
+ conversation: openaiOptions == null ? void 0 : openaiOptions.conversation,
11056
11381
  max_tool_calls: openaiOptions == null ? void 0 : openaiOptions.maxToolCalls,
11057
11382
  metadata: openaiOptions == null ? void 0 : openaiOptions.metadata,
11058
11383
  parallel_tool_calls: openaiOptions == null ? void 0 : openaiOptions.parallelToolCalls,
@@ -11063,6 +11388,7 @@ var OpenAIResponsesLanguageModel = class {
11063
11388
  service_tier: openaiOptions == null ? void 0 : openaiOptions.serviceTier,
11064
11389
  include,
11065
11390
  prompt_cache_key: openaiOptions == null ? void 0 : openaiOptions.promptCacheKey,
11391
+ prompt_cache_retention: openaiOptions == null ? void 0 : openaiOptions.promptCacheRetention,
11066
11392
  safety_identifier: openaiOptions == null ? void 0 : openaiOptions.safetyIdentifier,
11067
11393
  top_logprobs: topLogprobs,
11068
11394
  truncation: openaiOptions == null ? void 0 : openaiOptions.truncation,
@@ -11272,7 +11598,14 @@ var OpenAIResponsesLanguageModel = class {
11272
11598
  id: (_i = (_h = (_g = this.config).generateId) == null ? void 0 : _h.call(_g)) != null ? _i : generateId(),
11273
11599
  mediaType: "text/plain",
11274
11600
  title: (_k = (_j = annotation.quote) != null ? _j : annotation.filename) != null ? _k : "Document",
11275
- filename: (_l = annotation.filename) != null ? _l : annotation.file_id
11601
+ filename: (_l = annotation.filename) != null ? _l : annotation.file_id,
11602
+ ...annotation.file_id ? {
11603
+ providerMetadata: {
11604
+ openai: {
11605
+ fileId: annotation.file_id
11606
+ }
11607
+ }
11608
+ } : {}
11276
11609
  });
11277
11610
  }
11278
11611
  }
@@ -11382,7 +11715,9 @@ var OpenAIResponsesLanguageModel = class {
11382
11715
  }
11383
11716
  }
11384
11717
  const providerMetadata = {
11385
- openai: { responseId: response.id }
11718
+ openai: {
11719
+ ...response.id != null ? { responseId: response.id } : {}
11720
+ }
11386
11721
  };
11387
11722
  if (logprobs.length > 0) {
11388
11723
  providerMetadata.openai.logprobs = logprobs;
@@ -11390,6 +11725,7 @@ var OpenAIResponsesLanguageModel = class {
11390
11725
  if (typeof response.service_tier === "string") {
11391
11726
  providerMetadata.openai.serviceTier = response.service_tier;
11392
11727
  }
11728
+ const usage = response.usage;
11393
11729
  return {
11394
11730
  content,
11395
11731
  finishReason: mapOpenAIResponseFinishReason({
@@ -11397,11 +11733,11 @@ var OpenAIResponsesLanguageModel = class {
11397
11733
  hasFunctionCall
11398
11734
  }),
11399
11735
  usage: {
11400
- inputTokens: response.usage.input_tokens,
11401
- outputTokens: response.usage.output_tokens,
11402
- totalTokens: response.usage.input_tokens + response.usage.output_tokens,
11403
- reasoningTokens: (_q = (_p = response.usage.output_tokens_details) == null ? void 0 : _p.reasoning_tokens) != null ? _q : void 0,
11404
- cachedInputTokens: (_s = (_r = response.usage.input_tokens_details) == null ? void 0 : _r.cached_tokens) != null ? _s : void 0
11736
+ inputTokens: usage.input_tokens,
11737
+ outputTokens: usage.output_tokens,
11738
+ totalTokens: usage.input_tokens + usage.output_tokens,
11739
+ reasoningTokens: (_q = (_p = usage.output_tokens_details) == null ? void 0 : _p.reasoning_tokens) != null ? _q : void 0,
11740
+ cachedInputTokens: (_s = (_r = usage.input_tokens_details) == null ? void 0 : _r.cached_tokens) != null ? _s : void 0
11405
11741
  },
11406
11742
  request: { body },
11407
11743
  response: {
@@ -11850,7 +12186,14 @@ var OpenAIResponsesLanguageModel = class {
11850
12186
  id: (_s = (_r = (_q = self.config).generateId) == null ? void 0 : _r.call(_q)) != null ? _s : generateId(),
11851
12187
  mediaType: "text/plain",
11852
12188
  title: (_u = (_t = value.annotation.quote) != null ? _t : value.annotation.filename) != null ? _u : "Document",
11853
- filename: (_v = value.annotation.filename) != null ? _v : value.annotation.file_id
12189
+ filename: (_v = value.annotation.filename) != null ? _v : value.annotation.file_id,
12190
+ ...value.annotation.file_id ? {
12191
+ providerMetadata: {
12192
+ openai: {
12193
+ fileId: value.annotation.file_id
12194
+ }
12195
+ }
12196
+ } : {}
11854
12197
  });
11855
12198
  }
11856
12199
  } else if (isErrorChunk(value)) {
@@ -11928,13 +12271,6 @@ function getResponsesModelConfig(modelId) {
11928
12271
  };
11929
12272
  }
11930
12273
  if (modelId.startsWith("o") || modelId.startsWith("gpt-5") || modelId.startsWith("codex-") || modelId.startsWith("computer-use")) {
11931
- if (modelId.startsWith("o1-mini") || modelId.startsWith("o1-preview")) {
11932
- return {
11933
- ...defaults,
11934
- isReasoningModel: true,
11935
- systemMessageMode: "remove"
11936
- };
11937
- }
11938
12274
  return {
11939
12275
  ...defaults,
11940
12276
  isReasoningModel: true,
@@ -11950,7 +12286,11 @@ function mapWebSearchOutput(action) {
11950
12286
  var _a15;
11951
12287
  switch (action.type) {
11952
12288
  case "search":
11953
- return { action: { type: "search", query: (_a15 = action.query) != null ? _a15 : void 0 } };
12289
+ return {
12290
+ action: { type: "search", query: (_a15 = action.query) != null ? _a15 : void 0 },
12291
+ // include sources when provided by the Responses API (behind include flag)
12292
+ ...action.sources != null && { sources: action.sources }
12293
+ };
11954
12294
  case "open_page":
11955
12295
  return { action: { type: "openPage", url: action.url } };
11956
12296
  case "find":
@@ -12289,7 +12629,7 @@ var OpenAITranscriptionModel = class {
12289
12629
  };
12290
12630
  }
12291
12631
  };
12292
- var VERSION5 = "2.0.53" ;
12632
+ var VERSION5 = "2.0.69" ;
12293
12633
  function createOpenAI(options = {}) {
12294
12634
  var _a15, _b;
12295
12635
  const baseURL = (_a15 = withoutTrailingSlash(
@@ -12386,6 +12726,6 @@ function createOpenAI(options = {}) {
12386
12726
  }
12387
12727
  createOpenAI();
12388
12728
 
12389
- export { APICallError, EmptyResponseBodyError, EventSourceParserStream, InvalidArgumentError, JSONParseError, LoadAPIKeyError, MastraModelGateway, NoSuchModelError, OpenAICompatibleImageModel, TooManyEmbeddingValuesForCallError, TypeValidationError, UnsupportedFunctionalityError, combineHeaders, convertToBase64, createAnthropic, createEventSourceResponseHandler, createGoogleGenerativeAI, createJsonErrorResponseHandler, createJsonResponseHandler, createOpenAI, createOpenAICompatible, generateId, loadApiKey, parseProviderOptions, postJsonToApi, withUserAgentSuffix, withoutTrailingSlash };
12390
- //# sourceMappingURL=chunk-KOSW5PP5.js.map
12391
- //# sourceMappingURL=chunk-KOSW5PP5.js.map
12729
+ export { MastraModelGateway, NoSuchModelError, OpenAICompatibleImageModel, TooManyEmbeddingValuesForCallError, UnsupportedFunctionalityError, combineHeaders, convertToBase64, createAnthropic, createEventSourceResponseHandler, createGoogleGenerativeAI, createJsonErrorResponseHandler, createJsonResponseHandler, createOpenAI, createOpenAICompatible, generateId, injectJsonInstructionIntoMessages, loadApiKey, parseProviderOptions, postJsonToApi, withUserAgentSuffix, withoutTrailingSlash };
12730
+ //# sourceMappingURL=chunk-MDKPL2R2.js.map
12731
+ //# sourceMappingURL=chunk-MDKPL2R2.js.map