@mastra/server 0.0.0-remove-cloud-span-transform-20250425214156 → 0.0.0-remove-unused-model-providers-api-20251030210744

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 (268) hide show
  1. package/CHANGELOG.md +4230 -0
  2. package/LICENSE.md +11 -42
  3. package/README.md +45 -137
  4. package/dist/chunk-2PLXW4ZX.cjs +2777 -0
  5. package/dist/chunk-2PLXW4ZX.cjs.map +1 -0
  6. package/dist/chunk-2S4IMB6E.cjs +130 -0
  7. package/dist/chunk-2S4IMB6E.cjs.map +1 -0
  8. package/dist/{chunk-5JNVY6DU.js → chunk-2XD2KQEK.js} +57 -17
  9. package/dist/chunk-2XD2KQEK.js.map +1 -0
  10. package/dist/chunk-36CWLQQT.js +192 -0
  11. package/dist/chunk-36CWLQQT.js.map +1 -0
  12. package/dist/chunk-4BKR6543.cjs +19504 -0
  13. package/dist/chunk-4BKR6543.cjs.map +1 -0
  14. package/dist/{chunk-L7XE5QTW.js → chunk-4QCXUEAT.js} +11 -2
  15. package/dist/chunk-4QCXUEAT.js.map +1 -0
  16. package/dist/chunk-4YFT3JFJ.js +19463 -0
  17. package/dist/chunk-4YFT3JFJ.js.map +1 -0
  18. package/dist/chunk-6562SOHJ.js +130 -0
  19. package/dist/chunk-6562SOHJ.js.map +1 -0
  20. package/dist/chunk-6IGZKIRM.cjs +200 -0
  21. package/dist/chunk-6IGZKIRM.cjs.map +1 -0
  22. package/dist/{chunk-Q6SHQECN.js → chunk-74ZF4DII.js} +47 -13
  23. package/dist/chunk-74ZF4DII.js.map +1 -0
  24. package/dist/chunk-7KNKINQE.js +83 -0
  25. package/dist/chunk-7KNKINQE.js.map +1 -0
  26. package/dist/chunk-7MCHFMDF.js +665 -0
  27. package/dist/chunk-7MCHFMDF.js.map +1 -0
  28. package/dist/{chunk-FV45V6WC.cjs → chunk-7NADHFD2.cjs} +3 -7
  29. package/dist/chunk-7NADHFD2.cjs.map +1 -0
  30. package/dist/chunk-7YHMDEQ6.cjs +128 -0
  31. package/dist/chunk-7YHMDEQ6.cjs.map +1 -0
  32. package/dist/chunk-BATEJLED.js +124 -0
  33. package/dist/chunk-BATEJLED.js.map +1 -0
  34. package/dist/chunk-BMOVKZO7.cjs +167 -0
  35. package/dist/chunk-BMOVKZO7.cjs.map +1 -0
  36. package/dist/chunk-CXVOX4WB.js +508 -0
  37. package/dist/chunk-CXVOX4WB.js.map +1 -0
  38. package/dist/chunk-CY4TP3FK.js +16 -0
  39. package/dist/chunk-CY4TP3FK.js.map +1 -0
  40. package/dist/{chunk-M56ECCHK.cjs → chunk-EP3JQDPD.cjs} +22 -19
  41. package/dist/chunk-EP3JQDPD.cjs.map +1 -0
  42. package/dist/chunk-G4PUALCE.cjs +28 -0
  43. package/dist/chunk-G4PUALCE.cjs.map +1 -0
  44. package/dist/chunk-GQRJOUV7.js +797 -0
  45. package/dist/chunk-GQRJOUV7.js.map +1 -0
  46. package/dist/chunk-HLIRV42R.cjs +685 -0
  47. package/dist/chunk-HLIRV42R.cjs.map +1 -0
  48. package/dist/chunk-LPM6BBAX.cjs +1043 -0
  49. package/dist/chunk-LPM6BBAX.cjs.map +1 -0
  50. package/dist/chunk-LROVQBIB.cjs +524 -0
  51. package/dist/chunk-LROVQBIB.cjs.map +1 -0
  52. package/dist/chunk-LZKJT7QP.cjs +799 -0
  53. package/dist/chunk-LZKJT7QP.cjs.map +1 -0
  54. package/dist/{chunk-TRDNDNGQ.js → chunk-MMROOK5J.js} +4 -7
  55. package/dist/chunk-MMROOK5J.js.map +1 -0
  56. package/dist/{chunk-4JINXASC.js → chunk-MYR4PVGN.js} +7 -4
  57. package/dist/chunk-MYR4PVGN.js.map +1 -0
  58. package/dist/chunk-O7I5CWRX.cjs +44 -0
  59. package/dist/chunk-O7I5CWRX.cjs.map +1 -0
  60. package/dist/chunk-OEW3R7V4.js +477 -0
  61. package/dist/chunk-OEW3R7V4.js.map +1 -0
  62. package/dist/chunk-PR4QN5HX.js +39 -0
  63. package/dist/chunk-PR4QN5HX.js.map +1 -0
  64. package/dist/chunk-PUYDRTPG.cjs +720 -0
  65. package/dist/chunk-PUYDRTPG.cjs.map +1 -0
  66. package/dist/chunk-QU6N55W6.cjs +256 -0
  67. package/dist/chunk-QU6N55W6.cjs.map +1 -0
  68. package/dist/chunk-RE4RPXT2.cjs +18 -0
  69. package/dist/chunk-RE4RPXT2.cjs.map +1 -0
  70. package/dist/chunk-RQK4FQUD.js +1012 -0
  71. package/dist/chunk-RQK4FQUD.js.map +1 -0
  72. package/dist/chunk-S4IOWSI3.js +698 -0
  73. package/dist/chunk-S4IOWSI3.js.map +1 -0
  74. package/dist/chunk-SED4H2GJ.cjs +485 -0
  75. package/dist/chunk-SED4H2GJ.cjs.map +1 -0
  76. package/dist/chunk-SHWNNZBL.js +254 -0
  77. package/dist/chunk-SHWNNZBL.js.map +1 -0
  78. package/dist/chunk-TOCYBDP2.js +46 -0
  79. package/dist/chunk-TOCYBDP2.js.map +1 -0
  80. package/dist/chunk-WH5RPLO4.cjs +88 -0
  81. package/dist/chunk-WH5RPLO4.cjs.map +1 -0
  82. package/dist/chunk-X6C7BUWN.cjs +48 -0
  83. package/dist/chunk-X6C7BUWN.cjs.map +1 -0
  84. package/dist/chunk-YNGDJJOH.cjs +134 -0
  85. package/dist/chunk-YNGDJJOH.cjs.map +1 -0
  86. package/dist/chunk-ZULZ2752.js +2774 -0
  87. package/dist/chunk-ZULZ2752.js.map +1 -0
  88. package/dist/dist-4MVGNSRL.cjs +1150 -0
  89. package/dist/dist-4MVGNSRL.cjs.map +1 -0
  90. package/dist/dist-FZYCV3VB.cjs +940 -0
  91. package/dist/dist-FZYCV3VB.cjs.map +1 -0
  92. package/dist/dist-G2BYZJOC.cjs +928 -0
  93. package/dist/dist-G2BYZJOC.cjs.map +1 -0
  94. package/dist/dist-P4MXBQ3U.cjs +16 -0
  95. package/dist/dist-P4MXBQ3U.cjs.map +1 -0
  96. package/dist/dist-PQZUVLPC.js +937 -0
  97. package/dist/dist-PQZUVLPC.js.map +1 -0
  98. package/dist/dist-R7WYX6LC.js +925 -0
  99. package/dist/dist-R7WYX6LC.js.map +1 -0
  100. package/dist/dist-RFMYFILX.cjs +764 -0
  101. package/dist/dist-RFMYFILX.cjs.map +1 -0
  102. package/dist/dist-X7XR3M3Z.js +1147 -0
  103. package/dist/dist-X7XR3M3Z.js.map +1 -0
  104. package/dist/dist-XVBSOGFK.js +761 -0
  105. package/dist/dist-XVBSOGFK.js.map +1 -0
  106. package/dist/dist-YREX2TJT.js +3 -0
  107. package/dist/dist-YREX2TJT.js.map +1 -0
  108. package/dist/index.cjs +6 -0
  109. package/dist/index.cjs.map +1 -0
  110. package/dist/index.d.ts +1 -0
  111. package/dist/index.d.ts.map +1 -0
  112. package/dist/index.js +5 -0
  113. package/dist/index.js.map +1 -0
  114. package/dist/server/a2a/protocol.d.ts +8 -0
  115. package/dist/server/a2a/protocol.d.ts.map +1 -0
  116. package/dist/server/a2a/store.cjs +25 -0
  117. package/dist/server/a2a/store.cjs.map +1 -0
  118. package/dist/server/a2a/store.d.ts +14 -0
  119. package/dist/server/a2a/store.d.ts.map +1 -0
  120. package/dist/server/a2a/store.js +23 -0
  121. package/dist/server/a2a/store.js.map +1 -0
  122. package/dist/server/a2a/tasks.d.ts +20 -0
  123. package/dist/server/a2a/tasks.d.ts.map +1 -0
  124. package/dist/server/handlers/a2a.cjs +32 -0
  125. package/dist/server/handlers/a2a.cjs.map +1 -0
  126. package/dist/server/handlers/a2a.d.ts +68 -0
  127. package/dist/server/handlers/a2a.d.ts.map +1 -0
  128. package/dist/server/handlers/a2a.js +3 -0
  129. package/dist/server/handlers/a2a.js.map +1 -0
  130. package/dist/server/handlers/agent-builder.cjs +88 -0
  131. package/dist/server/handlers/agent-builder.cjs.map +1 -0
  132. package/dist/server/handlers/agent-builder.d.ts +110 -0
  133. package/dist/server/handlers/agent-builder.d.ts.map +1 -0
  134. package/dist/server/handlers/agent-builder.js +3 -0
  135. package/dist/server/handlers/agent-builder.js.map +1 -0
  136. package/dist/server/handlers/agents.cjs +60 -10
  137. package/dist/server/handlers/agents.cjs.map +1 -0
  138. package/dist/server/handlers/agents.d.ts +195 -6
  139. package/dist/server/handlers/agents.d.ts.map +1 -0
  140. package/dist/server/handlers/agents.js +3 -1
  141. package/dist/server/handlers/agents.js.map +1 -0
  142. package/dist/server/handlers/error.cjs +4 -2
  143. package/dist/server/handlers/error.cjs.map +1 -0
  144. package/dist/server/handlers/error.d.ts +2 -1
  145. package/dist/server/handlers/error.d.ts.map +1 -0
  146. package/dist/server/handlers/error.js +3 -1
  147. package/dist/server/handlers/error.js.map +1 -0
  148. package/dist/server/handlers/logs.cjs +9 -7
  149. package/dist/server/handlers/logs.cjs.map +1 -0
  150. package/dist/server/handlers/logs.d.ts +34 -3
  151. package/dist/server/handlers/logs.d.ts.map +1 -0
  152. package/dist/server/handlers/logs.js +3 -1
  153. package/dist/server/handlers/logs.js.map +1 -0
  154. package/dist/server/handlers/memory.cjs +36 -10
  155. package/dist/server/handlers/memory.cjs.map +1 -0
  156. package/dist/server/handlers/memory.d.ts +115 -8
  157. package/dist/server/handlers/memory.d.ts.map +1 -0
  158. package/dist/server/handlers/memory.js +3 -1
  159. package/dist/server/handlers/memory.js.map +1 -0
  160. package/dist/server/handlers/observability.cjs +24 -0
  161. package/dist/server/handlers/observability.cjs.map +1 -0
  162. package/dist/server/handlers/observability.d.ts +49 -0
  163. package/dist/server/handlers/observability.d.ts.map +1 -0
  164. package/dist/server/handlers/observability.js +3 -0
  165. package/dist/server/handlers/observability.js.map +1 -0
  166. package/dist/server/handlers/scores.cjs +32 -0
  167. package/dist/server/handlers/scores.cjs.map +1 -0
  168. package/dist/server/handlers/scores.d.ts +152 -0
  169. package/dist/server/handlers/scores.d.ts.map +1 -0
  170. package/dist/server/handlers/scores.js +3 -0
  171. package/dist/server/handlers/scores.js.map +1 -0
  172. package/dist/server/handlers/tools.cjs +12 -6
  173. package/dist/server/handlers/tools.cjs.map +1 -0
  174. package/dist/server/handlers/tools.d.ts +25 -4
  175. package/dist/server/handlers/tools.d.ts.map +1 -0
  176. package/dist/server/handlers/tools.js +3 -1
  177. package/dist/server/handlers/tools.js.map +1 -0
  178. package/dist/server/handlers/utils.cjs +8 -2
  179. package/dist/server/handlers/utils.cjs.map +1 -0
  180. package/dist/server/handlers/utils.d.ts +8 -1
  181. package/dist/server/handlers/utils.d.ts.map +1 -0
  182. package/dist/server/handlers/utils.js +3 -1
  183. package/dist/server/handlers/utils.js.map +1 -0
  184. package/dist/server/handlers/vector.cjs +9 -7
  185. package/dist/server/handlers/vector.cjs.map +1 -0
  186. package/dist/server/handlers/vector.d.ts +51 -6
  187. package/dist/server/handlers/vector.d.ts.map +1 -0
  188. package/dist/server/handlers/vector.js +3 -1
  189. package/dist/server/handlers/vector.js.map +1 -0
  190. package/dist/server/handlers/voice.cjs +10 -4
  191. package/dist/server/handlers/voice.cjs.map +1 -0
  192. package/dist/server/handlers/voice.d.ts +41 -3
  193. package/dist/server/handlers/voice.d.ts.map +1 -0
  194. package/dist/server/handlers/voice.js +3 -1
  195. package/dist/server/handlers/voice.js.map +1 -0
  196. package/dist/server/handlers/workflows.cjs +57 -15
  197. package/dist/server/handlers/workflows.cjs.map +1 -0
  198. package/dist/server/handlers/workflows.d.ts +97 -10
  199. package/dist/server/handlers/workflows.d.ts.map +1 -0
  200. package/dist/server/handlers/workflows.js +3 -1
  201. package/dist/server/handlers/workflows.js.map +1 -0
  202. package/dist/server/handlers.cjs +37 -30
  203. package/dist/server/handlers.cjs.map +1 -0
  204. package/dist/server/handlers.d.ts +12 -10
  205. package/dist/server/handlers.d.ts.map +1 -0
  206. package/dist/server/handlers.js +13 -10
  207. package/dist/server/handlers.js.map +1 -0
  208. package/dist/server/http-exception.d.ts +87 -0
  209. package/dist/server/http-exception.d.ts.map +1 -0
  210. package/dist/server/types.d.ts +10 -0
  211. package/dist/server/types.d.ts.map +1 -0
  212. package/dist/server/utils.d.ts +44 -0
  213. package/dist/server/utils.d.ts.map +1 -0
  214. package/dist/token-375W3LEI.cjs +64 -0
  215. package/dist/token-375W3LEI.cjs.map +1 -0
  216. package/dist/token-C3IMNCC4.js +62 -0
  217. package/dist/token-C3IMNCC4.js.map +1 -0
  218. package/dist/token-util-CV3RRG6K.cjs +9 -0
  219. package/dist/token-util-CV3RRG6K.cjs.map +1 -0
  220. package/dist/token-util-E5QO2RCL.js +7 -0
  221. package/dist/token-util-E5QO2RCL.js.map +1 -0
  222. package/package.json +43 -19
  223. package/dist/_tsup-dts-rollup.d.cts +0 -648
  224. package/dist/_tsup-dts-rollup.d.ts +0 -648
  225. package/dist/chunk-2FJURXCL.cjs +0 -213
  226. package/dist/chunk-3AHQ5RGN.js +0 -11
  227. package/dist/chunk-3EJZQ6TQ.js +0 -49
  228. package/dist/chunk-55HTWX4C.cjs +0 -93
  229. package/dist/chunk-5SWCVTNL.cjs +0 -5579
  230. package/dist/chunk-7IWQE76Z.cjs +0 -139
  231. package/dist/chunk-B66WVPGJ.js +0 -297
  232. package/dist/chunk-D3G23FP3.cjs +0 -126
  233. package/dist/chunk-FPIWDH5Y.cjs +0 -126
  234. package/dist/chunk-HCOPJZ4A.cjs +0 -164
  235. package/dist/chunk-LFOBHRFO.js +0 -305
  236. package/dist/chunk-OMN3UI6X.js +0 -5576
  237. package/dist/chunk-QN4KF3BH.cjs +0 -18
  238. package/dist/chunk-R4J7XQYU.js +0 -156
  239. package/dist/chunk-RBQASTUP.js +0 -203
  240. package/dist/chunk-RE6YL32K.js +0 -120
  241. package/dist/chunk-SKBVVI24.cjs +0 -54
  242. package/dist/chunk-TZK63M5N.cjs +0 -317
  243. package/dist/chunk-WTHDCRMY.js +0 -135
  244. package/dist/chunk-ZHNKYTNS.cjs +0 -309
  245. package/dist/chunk-ZLBRQFDD.cjs +0 -13
  246. package/dist/index.d.cts +0 -1
  247. package/dist/server/handlers/agents.d.cts +0 -6
  248. package/dist/server/handlers/error.d.cts +0 -1
  249. package/dist/server/handlers/logs.d.cts +0 -3
  250. package/dist/server/handlers/memory.d.cts +0 -8
  251. package/dist/server/handlers/network.cjs +0 -22
  252. package/dist/server/handlers/network.d.cts +0 -4
  253. package/dist/server/handlers/network.d.ts +0 -4
  254. package/dist/server/handlers/network.js +0 -1
  255. package/dist/server/handlers/telemetry.cjs +0 -14
  256. package/dist/server/handlers/telemetry.d.cts +0 -2
  257. package/dist/server/handlers/telemetry.d.ts +0 -2
  258. package/dist/server/handlers/telemetry.js +0 -1
  259. package/dist/server/handlers/tools.d.cts +0 -4
  260. package/dist/server/handlers/utils.d.cts +0 -1
  261. package/dist/server/handlers/vNextWorkflows.cjs +0 -46
  262. package/dist/server/handlers/vNextWorkflows.d.cts +0 -10
  263. package/dist/server/handlers/vNextWorkflows.d.ts +0 -10
  264. package/dist/server/handlers/vNextWorkflows.js +0 -1
  265. package/dist/server/handlers/vector.d.cts +0 -6
  266. package/dist/server/handlers/voice.d.cts +0 -3
  267. package/dist/server/handlers/workflows.d.cts +0 -10
  268. package/dist/server/handlers.d.cts +0 -10
@@ -0,0 +1,940 @@
1
+ 'use strict';
2
+
3
+ var chunkLPM6BBAX_cjs = require('./chunk-LPM6BBAX.cjs');
4
+ var zod = require('zod');
5
+
6
+ function convertJSONSchemaToOpenAPISchema(jsonSchema) {
7
+ if (isEmptyObjectSchema(jsonSchema)) {
8
+ return void 0;
9
+ }
10
+ if (typeof jsonSchema === "boolean") {
11
+ return { type: "boolean", properties: {} };
12
+ }
13
+ const {
14
+ type,
15
+ description,
16
+ required,
17
+ properties,
18
+ items,
19
+ allOf,
20
+ anyOf,
21
+ oneOf,
22
+ format,
23
+ const: constValue,
24
+ minLength,
25
+ enum: enumValues
26
+ } = jsonSchema;
27
+ const result = {};
28
+ if (description)
29
+ result.description = description;
30
+ if (required)
31
+ result.required = required;
32
+ if (format)
33
+ result.format = format;
34
+ if (constValue !== void 0) {
35
+ result.enum = [constValue];
36
+ }
37
+ if (type) {
38
+ if (Array.isArray(type)) {
39
+ if (type.includes("null")) {
40
+ result.type = type.filter((t) => t !== "null")[0];
41
+ result.nullable = true;
42
+ } else {
43
+ result.type = type;
44
+ }
45
+ } else if (type === "null") {
46
+ result.type = "null";
47
+ } else {
48
+ result.type = type;
49
+ }
50
+ }
51
+ if (enumValues !== void 0) {
52
+ result.enum = enumValues;
53
+ }
54
+ if (properties != null) {
55
+ result.properties = Object.entries(properties).reduce(
56
+ (acc, [key, value]) => {
57
+ acc[key] = convertJSONSchemaToOpenAPISchema(value);
58
+ return acc;
59
+ },
60
+ {}
61
+ );
62
+ }
63
+ if (items) {
64
+ result.items = Array.isArray(items) ? items.map(convertJSONSchemaToOpenAPISchema) : convertJSONSchemaToOpenAPISchema(items);
65
+ }
66
+ if (allOf) {
67
+ result.allOf = allOf.map(convertJSONSchemaToOpenAPISchema);
68
+ }
69
+ if (anyOf) {
70
+ if (anyOf.some(
71
+ (schema) => typeof schema === "object" && (schema == null ? void 0 : schema.type) === "null"
72
+ )) {
73
+ const nonNullSchemas = anyOf.filter(
74
+ (schema) => !(typeof schema === "object" && (schema == null ? void 0 : schema.type) === "null")
75
+ );
76
+ if (nonNullSchemas.length === 1) {
77
+ const converted = convertJSONSchemaToOpenAPISchema(nonNullSchemas[0]);
78
+ if (typeof converted === "object") {
79
+ result.nullable = true;
80
+ Object.assign(result, converted);
81
+ }
82
+ } else {
83
+ result.anyOf = nonNullSchemas.map(convertJSONSchemaToOpenAPISchema);
84
+ result.nullable = true;
85
+ }
86
+ } else {
87
+ result.anyOf = anyOf.map(convertJSONSchemaToOpenAPISchema);
88
+ }
89
+ }
90
+ if (oneOf) {
91
+ result.oneOf = oneOf.map(convertJSONSchemaToOpenAPISchema);
92
+ }
93
+ if (minLength !== void 0) {
94
+ result.minLength = minLength;
95
+ }
96
+ return result;
97
+ }
98
+ function isEmptyObjectSchema(jsonSchema) {
99
+ return jsonSchema != null && typeof jsonSchema === "object" && jsonSchema.type === "object" && (jsonSchema.properties == null || Object.keys(jsonSchema.properties).length === 0) && !jsonSchema.additionalProperties;
100
+ }
101
+ function convertToGoogleGenerativeAIMessages(prompt) {
102
+ var _a, _b;
103
+ const systemInstructionParts = [];
104
+ const contents = [];
105
+ let systemMessagesAllowed = true;
106
+ for (const { role, content } of prompt) {
107
+ switch (role) {
108
+ case "system": {
109
+ if (!systemMessagesAllowed) {
110
+ throw new chunkLPM6BBAX_cjs.UnsupportedFunctionalityError({
111
+ functionality: "system messages are only supported at the beginning of the conversation"
112
+ });
113
+ }
114
+ systemInstructionParts.push({ text: content });
115
+ break;
116
+ }
117
+ case "user": {
118
+ systemMessagesAllowed = false;
119
+ const parts = [];
120
+ for (const part of content) {
121
+ switch (part.type) {
122
+ case "text": {
123
+ parts.push({ text: part.text });
124
+ break;
125
+ }
126
+ case "image": {
127
+ parts.push(
128
+ part.image instanceof URL ? {
129
+ fileData: {
130
+ mimeType: (_a = part.mimeType) != null ? _a : "image/jpeg",
131
+ fileUri: part.image.toString()
132
+ }
133
+ } : {
134
+ inlineData: {
135
+ mimeType: (_b = part.mimeType) != null ? _b : "image/jpeg",
136
+ data: chunkLPM6BBAX_cjs.convertUint8ArrayToBase64(part.image)
137
+ }
138
+ }
139
+ );
140
+ break;
141
+ }
142
+ case "file": {
143
+ parts.push(
144
+ part.data instanceof URL ? {
145
+ fileData: {
146
+ mimeType: part.mimeType,
147
+ fileUri: part.data.toString()
148
+ }
149
+ } : {
150
+ inlineData: {
151
+ mimeType: part.mimeType,
152
+ data: part.data
153
+ }
154
+ }
155
+ );
156
+ break;
157
+ }
158
+ }
159
+ }
160
+ contents.push({ role: "user", parts });
161
+ break;
162
+ }
163
+ case "assistant": {
164
+ systemMessagesAllowed = false;
165
+ contents.push({
166
+ role: "model",
167
+ parts: content.map((part) => {
168
+ switch (part.type) {
169
+ case "text": {
170
+ return part.text.length === 0 ? void 0 : { text: part.text };
171
+ }
172
+ case "file": {
173
+ if (part.mimeType !== "image/png") {
174
+ throw new chunkLPM6BBAX_cjs.UnsupportedFunctionalityError({
175
+ functionality: "Only PNG images are supported in assistant messages"
176
+ });
177
+ }
178
+ if (part.data instanceof URL) {
179
+ throw new chunkLPM6BBAX_cjs.UnsupportedFunctionalityError({
180
+ functionality: "File data URLs in assistant messages are not supported"
181
+ });
182
+ }
183
+ return {
184
+ inlineData: {
185
+ mimeType: part.mimeType,
186
+ data: part.data
187
+ }
188
+ };
189
+ }
190
+ case "tool-call": {
191
+ return {
192
+ functionCall: {
193
+ name: part.toolName,
194
+ args: part.args
195
+ }
196
+ };
197
+ }
198
+ }
199
+ }).filter((part) => part !== void 0)
200
+ });
201
+ break;
202
+ }
203
+ case "tool": {
204
+ systemMessagesAllowed = false;
205
+ contents.push({
206
+ role: "user",
207
+ parts: content.map((part) => ({
208
+ functionResponse: {
209
+ name: part.toolName,
210
+ response: {
211
+ name: part.toolName,
212
+ content: part.result
213
+ }
214
+ }
215
+ }))
216
+ });
217
+ break;
218
+ }
219
+ }
220
+ }
221
+ return {
222
+ systemInstruction: systemInstructionParts.length > 0 ? { parts: systemInstructionParts } : void 0,
223
+ contents
224
+ };
225
+ }
226
+ function getModelPath(modelId) {
227
+ return modelId.includes("/") ? modelId : `models/${modelId}`;
228
+ }
229
+ var googleErrorDataSchema = zod.z.object({
230
+ error: zod.z.object({
231
+ code: zod.z.number().nullable(),
232
+ message: zod.z.string(),
233
+ status: zod.z.string()
234
+ })
235
+ });
236
+ var googleFailedResponseHandler = chunkLPM6BBAX_cjs.createJsonErrorResponseHandler({
237
+ errorSchema: googleErrorDataSchema,
238
+ errorToMessage: (data) => data.error.message
239
+ });
240
+ function prepareTools(mode, useSearchGrounding, dynamicRetrievalConfig, modelId) {
241
+ var _a, _b;
242
+ const tools = ((_a = mode.tools) == null ? void 0 : _a.length) ? mode.tools : void 0;
243
+ const toolWarnings = [];
244
+ const isGemini2 = modelId.includes("gemini-2");
245
+ const supportsDynamicRetrieval = modelId.includes("gemini-1.5-flash") && !modelId.includes("-8b");
246
+ if (useSearchGrounding) {
247
+ return {
248
+ tools: isGemini2 ? { googleSearch: {} } : {
249
+ googleSearchRetrieval: !supportsDynamicRetrieval || !dynamicRetrievalConfig ? {} : { dynamicRetrievalConfig }
250
+ },
251
+ toolConfig: void 0,
252
+ toolWarnings
253
+ };
254
+ }
255
+ if (tools == null) {
256
+ return { tools: void 0, toolConfig: void 0, toolWarnings };
257
+ }
258
+ const functionDeclarations = [];
259
+ for (const tool of tools) {
260
+ if (tool.type === "provider-defined") {
261
+ toolWarnings.push({ type: "unsupported-tool", tool });
262
+ } else {
263
+ functionDeclarations.push({
264
+ name: tool.name,
265
+ description: (_b = tool.description) != null ? _b : "",
266
+ parameters: convertJSONSchemaToOpenAPISchema(tool.parameters)
267
+ });
268
+ }
269
+ }
270
+ const toolChoice = mode.toolChoice;
271
+ if (toolChoice == null) {
272
+ return {
273
+ tools: { functionDeclarations },
274
+ toolConfig: void 0,
275
+ toolWarnings
276
+ };
277
+ }
278
+ const type = toolChoice.type;
279
+ switch (type) {
280
+ case "auto":
281
+ return {
282
+ tools: { functionDeclarations },
283
+ toolConfig: { functionCallingConfig: { mode: "AUTO" } },
284
+ toolWarnings
285
+ };
286
+ case "none":
287
+ return {
288
+ tools: { functionDeclarations },
289
+ toolConfig: { functionCallingConfig: { mode: "NONE" } },
290
+ toolWarnings
291
+ };
292
+ case "required":
293
+ return {
294
+ tools: { functionDeclarations },
295
+ toolConfig: { functionCallingConfig: { mode: "ANY" } },
296
+ toolWarnings
297
+ };
298
+ case "tool":
299
+ return {
300
+ tools: { functionDeclarations },
301
+ toolConfig: {
302
+ functionCallingConfig: {
303
+ mode: "ANY",
304
+ allowedFunctionNames: [toolChoice.toolName]
305
+ }
306
+ },
307
+ toolWarnings
308
+ };
309
+ default: {
310
+ const _exhaustiveCheck = type;
311
+ throw new chunkLPM6BBAX_cjs.UnsupportedFunctionalityError({
312
+ functionality: `Unsupported tool choice type: ${_exhaustiveCheck}`
313
+ });
314
+ }
315
+ }
316
+ }
317
+ function mapGoogleGenerativeAIFinishReason({
318
+ finishReason,
319
+ hasToolCalls
320
+ }) {
321
+ switch (finishReason) {
322
+ case "STOP":
323
+ return hasToolCalls ? "tool-calls" : "stop";
324
+ case "MAX_TOKENS":
325
+ return "length";
326
+ case "IMAGE_SAFETY":
327
+ case "RECITATION":
328
+ case "SAFETY":
329
+ case "BLOCKLIST":
330
+ case "PROHIBITED_CONTENT":
331
+ case "SPII":
332
+ return "content-filter";
333
+ case "FINISH_REASON_UNSPECIFIED":
334
+ case "OTHER":
335
+ return "other";
336
+ case "MALFORMED_FUNCTION_CALL":
337
+ return "error";
338
+ default:
339
+ return "unknown";
340
+ }
341
+ }
342
+ var GoogleGenerativeAILanguageModel = class {
343
+ constructor(modelId, settings, config) {
344
+ this.specificationVersion = "v1";
345
+ this.defaultObjectGenerationMode = "json";
346
+ this.supportsImageUrls = false;
347
+ this.modelId = modelId;
348
+ this.settings = settings;
349
+ this.config = config;
350
+ }
351
+ get supportsStructuredOutputs() {
352
+ var _a;
353
+ return (_a = this.settings.structuredOutputs) != null ? _a : true;
354
+ }
355
+ get provider() {
356
+ return this.config.provider;
357
+ }
358
+ async getArgs({
359
+ mode,
360
+ prompt,
361
+ maxTokens,
362
+ temperature,
363
+ topP,
364
+ topK,
365
+ frequencyPenalty,
366
+ presencePenalty,
367
+ stopSequences,
368
+ responseFormat,
369
+ seed,
370
+ providerMetadata
371
+ }) {
372
+ var _a, _b, _c;
373
+ const type = mode.type;
374
+ const warnings = [];
375
+ const googleOptions = chunkLPM6BBAX_cjs.parseProviderOptions({
376
+ provider: "google",
377
+ providerOptions: providerMetadata,
378
+ schema: googleGenerativeAIProviderOptionsSchema
379
+ });
380
+ if (((_a = googleOptions == null ? void 0 : googleOptions.thinkingConfig) == null ? void 0 : _a.includeThoughts) === true && !this.config.provider.startsWith("google.vertex.")) {
381
+ warnings.push({
382
+ type: "other",
383
+ 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}).`
384
+ });
385
+ }
386
+ const generationConfig = {
387
+ // standardized settings:
388
+ maxOutputTokens: maxTokens,
389
+ temperature,
390
+ topK,
391
+ topP,
392
+ frequencyPenalty,
393
+ presencePenalty,
394
+ stopSequences,
395
+ seed,
396
+ // response format:
397
+ responseMimeType: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? "application/json" : void 0,
398
+ responseSchema: (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && // Google GenAI does not support all OpenAPI Schema features,
399
+ // so this is needed as an escape hatch:
400
+ this.supportsStructuredOutputs ? convertJSONSchemaToOpenAPISchema(responseFormat.schema) : void 0,
401
+ ...this.settings.audioTimestamp && {
402
+ audioTimestamp: this.settings.audioTimestamp
403
+ },
404
+ // provider options:
405
+ responseModalities: googleOptions == null ? void 0 : googleOptions.responseModalities,
406
+ thinkingConfig: googleOptions == null ? void 0 : googleOptions.thinkingConfig
407
+ };
408
+ const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(prompt);
409
+ switch (type) {
410
+ case "regular": {
411
+ const { tools, toolConfig, toolWarnings } = prepareTools(
412
+ mode,
413
+ (_b = this.settings.useSearchGrounding) != null ? _b : false,
414
+ this.settings.dynamicRetrievalConfig,
415
+ this.modelId
416
+ );
417
+ return {
418
+ args: {
419
+ generationConfig,
420
+ contents,
421
+ systemInstruction,
422
+ safetySettings: this.settings.safetySettings,
423
+ tools,
424
+ toolConfig,
425
+ cachedContent: this.settings.cachedContent
426
+ },
427
+ warnings: [...warnings, ...toolWarnings]
428
+ };
429
+ }
430
+ case "object-json": {
431
+ return {
432
+ args: {
433
+ generationConfig: {
434
+ ...generationConfig,
435
+ responseMimeType: "application/json",
436
+ responseSchema: mode.schema != null && // Google GenAI does not support all OpenAPI Schema features,
437
+ // so this is needed as an escape hatch:
438
+ this.supportsStructuredOutputs ? convertJSONSchemaToOpenAPISchema(mode.schema) : void 0
439
+ },
440
+ contents,
441
+ systemInstruction,
442
+ safetySettings: this.settings.safetySettings,
443
+ cachedContent: this.settings.cachedContent
444
+ },
445
+ warnings
446
+ };
447
+ }
448
+ case "object-tool": {
449
+ return {
450
+ args: {
451
+ generationConfig,
452
+ contents,
453
+ systemInstruction,
454
+ tools: {
455
+ functionDeclarations: [
456
+ {
457
+ name: mode.tool.name,
458
+ description: (_c = mode.tool.description) != null ? _c : "",
459
+ parameters: convertJSONSchemaToOpenAPISchema(
460
+ mode.tool.parameters
461
+ )
462
+ }
463
+ ]
464
+ },
465
+ toolConfig: { functionCallingConfig: { mode: "ANY" } },
466
+ safetySettings: this.settings.safetySettings,
467
+ cachedContent: this.settings.cachedContent
468
+ },
469
+ warnings
470
+ };
471
+ }
472
+ default: {
473
+ const _exhaustiveCheck = type;
474
+ throw new Error(`Unsupported type: ${_exhaustiveCheck}`);
475
+ }
476
+ }
477
+ }
478
+ supportsUrl(url) {
479
+ return this.config.isSupportedUrl(url);
480
+ }
481
+ async doGenerate(options) {
482
+ var _a, _b, _c, _d, _e;
483
+ const { args, warnings } = await this.getArgs(options);
484
+ const body = JSON.stringify(args);
485
+ const mergedHeaders = chunkLPM6BBAX_cjs.combineHeaders(
486
+ await chunkLPM6BBAX_cjs.resolve(this.config.headers),
487
+ options.headers
488
+ );
489
+ const {
490
+ responseHeaders,
491
+ value: response,
492
+ rawValue: rawResponse
493
+ } = await chunkLPM6BBAX_cjs.postJsonToApi({
494
+ url: `${this.config.baseURL}/${getModelPath(
495
+ this.modelId
496
+ )}:generateContent`,
497
+ headers: mergedHeaders,
498
+ body: args,
499
+ failedResponseHandler: googleFailedResponseHandler,
500
+ successfulResponseHandler: chunkLPM6BBAX_cjs.createJsonResponseHandler(responseSchema),
501
+ abortSignal: options.abortSignal,
502
+ fetch: this.config.fetch
503
+ });
504
+ const { contents: rawPrompt, ...rawSettings } = args;
505
+ const candidate = response.candidates[0];
506
+ const parts = candidate.content == null || typeof candidate.content !== "object" || !("parts" in candidate.content) ? [] : candidate.content.parts;
507
+ const toolCalls = getToolCallsFromParts({
508
+ parts,
509
+ // Use candidateParts
510
+ generateId: this.config.generateId
511
+ });
512
+ const usageMetadata = response.usageMetadata;
513
+ return {
514
+ text: getTextFromParts(parts),
515
+ reasoning: getReasoningDetailsFromParts(parts),
516
+ files: (_a = getInlineDataParts(parts)) == null ? void 0 : _a.map((part) => ({
517
+ data: part.inlineData.data,
518
+ mimeType: part.inlineData.mimeType
519
+ })),
520
+ toolCalls,
521
+ finishReason: mapGoogleGenerativeAIFinishReason({
522
+ finishReason: candidate.finishReason,
523
+ hasToolCalls: toolCalls != null && toolCalls.length > 0
524
+ }),
525
+ usage: {
526
+ promptTokens: (_b = usageMetadata == null ? void 0 : usageMetadata.promptTokenCount) != null ? _b : NaN,
527
+ completionTokens: (_c = usageMetadata == null ? void 0 : usageMetadata.candidatesTokenCount) != null ? _c : NaN
528
+ },
529
+ rawCall: { rawPrompt, rawSettings },
530
+ rawResponse: { headers: responseHeaders, body: rawResponse },
531
+ warnings,
532
+ providerMetadata: {
533
+ google: {
534
+ groundingMetadata: (_d = candidate.groundingMetadata) != null ? _d : null,
535
+ safetyRatings: (_e = candidate.safetyRatings) != null ? _e : null
536
+ }
537
+ },
538
+ sources: extractSources({
539
+ groundingMetadata: candidate.groundingMetadata,
540
+ generateId: this.config.generateId
541
+ }),
542
+ request: { body }
543
+ };
544
+ }
545
+ async doStream(options) {
546
+ const { args, warnings } = await this.getArgs(options);
547
+ const body = JSON.stringify(args);
548
+ const headers = chunkLPM6BBAX_cjs.combineHeaders(
549
+ await chunkLPM6BBAX_cjs.resolve(this.config.headers),
550
+ options.headers
551
+ );
552
+ const { responseHeaders, value: response } = await chunkLPM6BBAX_cjs.postJsonToApi({
553
+ url: `${this.config.baseURL}/${getModelPath(
554
+ this.modelId
555
+ )}:streamGenerateContent?alt=sse`,
556
+ headers,
557
+ body: args,
558
+ failedResponseHandler: googleFailedResponseHandler,
559
+ successfulResponseHandler: chunkLPM6BBAX_cjs.createEventSourceResponseHandler(chunkSchema),
560
+ abortSignal: options.abortSignal,
561
+ fetch: this.config.fetch
562
+ });
563
+ const { contents: rawPrompt, ...rawSettings } = args;
564
+ let finishReason = "unknown";
565
+ let usage = {
566
+ promptTokens: Number.NaN,
567
+ completionTokens: Number.NaN
568
+ };
569
+ let providerMetadata = void 0;
570
+ const generateId2 = this.config.generateId;
571
+ let hasToolCalls = false;
572
+ return {
573
+ stream: response.pipeThrough(
574
+ new TransformStream({
575
+ transform(chunk, controller) {
576
+ var _a, _b, _c, _d, _e, _f;
577
+ if (!chunk.success) {
578
+ controller.enqueue({ type: "error", error: chunk.error });
579
+ return;
580
+ }
581
+ const value = chunk.value;
582
+ const usageMetadata = value.usageMetadata;
583
+ if (usageMetadata != null) {
584
+ usage = {
585
+ promptTokens: (_a = usageMetadata.promptTokenCount) != null ? _a : NaN,
586
+ completionTokens: (_b = usageMetadata.candidatesTokenCount) != null ? _b : NaN
587
+ };
588
+ }
589
+ const candidate = (_c = value.candidates) == null ? void 0 : _c[0];
590
+ if (candidate == null) {
591
+ return;
592
+ }
593
+ const content = candidate.content;
594
+ if (content != null) {
595
+ const deltaText = getTextFromParts(content.parts);
596
+ if (deltaText != null) {
597
+ controller.enqueue({
598
+ type: "text-delta",
599
+ textDelta: deltaText
600
+ });
601
+ }
602
+ const reasoningDeltaText = getReasoningDetailsFromParts(
603
+ content.parts
604
+ );
605
+ if (reasoningDeltaText != null) {
606
+ for (const part of reasoningDeltaText) {
607
+ controller.enqueue({
608
+ type: "reasoning",
609
+ textDelta: part.text
610
+ });
611
+ }
612
+ }
613
+ const inlineDataParts = getInlineDataParts(content.parts);
614
+ if (inlineDataParts != null) {
615
+ for (const part of inlineDataParts) {
616
+ controller.enqueue({
617
+ type: "file",
618
+ mimeType: part.inlineData.mimeType,
619
+ data: part.inlineData.data
620
+ });
621
+ }
622
+ }
623
+ const toolCallDeltas = getToolCallsFromParts({
624
+ parts: content.parts,
625
+ generateId: generateId2
626
+ });
627
+ if (toolCallDeltas != null) {
628
+ for (const toolCall of toolCallDeltas) {
629
+ controller.enqueue({
630
+ type: "tool-call-delta",
631
+ toolCallType: "function",
632
+ toolCallId: toolCall.toolCallId,
633
+ toolName: toolCall.toolName,
634
+ argsTextDelta: toolCall.args
635
+ });
636
+ controller.enqueue({
637
+ type: "tool-call",
638
+ toolCallType: "function",
639
+ toolCallId: toolCall.toolCallId,
640
+ toolName: toolCall.toolName,
641
+ args: toolCall.args
642
+ });
643
+ hasToolCalls = true;
644
+ }
645
+ }
646
+ }
647
+ if (candidate.finishReason != null) {
648
+ finishReason = mapGoogleGenerativeAIFinishReason({
649
+ finishReason: candidate.finishReason,
650
+ hasToolCalls
651
+ });
652
+ const sources = (_d = extractSources({
653
+ groundingMetadata: candidate.groundingMetadata,
654
+ generateId: generateId2
655
+ })) != null ? _d : [];
656
+ for (const source of sources) {
657
+ controller.enqueue({ type: "source", source });
658
+ }
659
+ providerMetadata = {
660
+ google: {
661
+ groundingMetadata: (_e = candidate.groundingMetadata) != null ? _e : null,
662
+ safetyRatings: (_f = candidate.safetyRatings) != null ? _f : null
663
+ }
664
+ };
665
+ }
666
+ },
667
+ flush(controller) {
668
+ controller.enqueue({
669
+ type: "finish",
670
+ finishReason,
671
+ usage,
672
+ providerMetadata
673
+ });
674
+ }
675
+ })
676
+ ),
677
+ rawCall: { rawPrompt, rawSettings },
678
+ rawResponse: { headers: responseHeaders },
679
+ warnings,
680
+ request: { body }
681
+ };
682
+ }
683
+ };
684
+ function getToolCallsFromParts({
685
+ parts,
686
+ generateId: generateId2
687
+ }) {
688
+ const functionCallParts = parts == null ? void 0 : parts.filter(
689
+ (part) => "functionCall" in part
690
+ );
691
+ return functionCallParts == null || functionCallParts.length === 0 ? void 0 : functionCallParts.map((part) => ({
692
+ toolCallType: "function",
693
+ toolCallId: generateId2(),
694
+ toolName: part.functionCall.name,
695
+ args: JSON.stringify(part.functionCall.args)
696
+ }));
697
+ }
698
+ function getTextFromParts(parts) {
699
+ const textParts = parts == null ? void 0 : parts.filter(
700
+ (part) => "text" in part && part.thought !== true
701
+ );
702
+ return textParts == null || textParts.length === 0 ? void 0 : textParts.map((part) => part.text).join("");
703
+ }
704
+ function getReasoningDetailsFromParts(parts) {
705
+ const reasoningParts = parts == null ? void 0 : parts.filter(
706
+ (part) => "text" in part && part.thought === true && part.text != null
707
+ );
708
+ return reasoningParts == null || reasoningParts.length === 0 ? void 0 : reasoningParts.map((part) => ({ type: "text", text: part.text }));
709
+ }
710
+ function getInlineDataParts(parts) {
711
+ return parts == null ? void 0 : parts.filter(
712
+ (part) => "inlineData" in part
713
+ );
714
+ }
715
+ function extractSources({
716
+ groundingMetadata,
717
+ generateId: generateId2
718
+ }) {
719
+ var _a;
720
+ return (_a = groundingMetadata == null ? void 0 : groundingMetadata.groundingChunks) == null ? void 0 : _a.filter(
721
+ (chunk) => chunk.web != null
722
+ ).map((chunk) => ({
723
+ sourceType: "url",
724
+ id: generateId2(),
725
+ url: chunk.web.uri,
726
+ title: chunk.web.title
727
+ }));
728
+ }
729
+ var contentSchema = zod.z.object({
730
+ parts: zod.z.array(
731
+ zod.z.union([
732
+ // note: order matters since text can be fully empty
733
+ zod.z.object({
734
+ functionCall: zod.z.object({
735
+ name: zod.z.string(),
736
+ args: zod.z.unknown()
737
+ })
738
+ }),
739
+ zod.z.object({
740
+ inlineData: zod.z.object({
741
+ mimeType: zod.z.string(),
742
+ data: zod.z.string()
743
+ })
744
+ }),
745
+ zod.z.object({
746
+ text: zod.z.string().nullish(),
747
+ thought: zod.z.boolean().nullish()
748
+ })
749
+ ])
750
+ ).nullish()
751
+ });
752
+ var groundingChunkSchema = zod.z.object({
753
+ web: zod.z.object({ uri: zod.z.string(), title: zod.z.string() }).nullish(),
754
+ retrievedContext: zod.z.object({ uri: zod.z.string(), title: zod.z.string() }).nullish()
755
+ });
756
+ var groundingMetadataSchema = zod.z.object({
757
+ webSearchQueries: zod.z.array(zod.z.string()).nullish(),
758
+ retrievalQueries: zod.z.array(zod.z.string()).nullish(),
759
+ searchEntryPoint: zod.z.object({ renderedContent: zod.z.string() }).nullish(),
760
+ groundingChunks: zod.z.array(groundingChunkSchema).nullish(),
761
+ groundingSupports: zod.z.array(
762
+ zod.z.object({
763
+ segment: zod.z.object({
764
+ startIndex: zod.z.number().nullish(),
765
+ endIndex: zod.z.number().nullish(),
766
+ text: zod.z.string().nullish()
767
+ }),
768
+ segment_text: zod.z.string().nullish(),
769
+ groundingChunkIndices: zod.z.array(zod.z.number()).nullish(),
770
+ supportChunkIndices: zod.z.array(zod.z.number()).nullish(),
771
+ confidenceScores: zod.z.array(zod.z.number()).nullish(),
772
+ confidenceScore: zod.z.array(zod.z.number()).nullish()
773
+ })
774
+ ).nullish(),
775
+ retrievalMetadata: zod.z.union([
776
+ zod.z.object({
777
+ webDynamicRetrievalScore: zod.z.number()
778
+ }),
779
+ zod.z.object({})
780
+ ]).nullish()
781
+ });
782
+ var safetyRatingSchema = zod.z.object({
783
+ category: zod.z.string().nullish(),
784
+ probability: zod.z.string().nullish(),
785
+ probabilityScore: zod.z.number().nullish(),
786
+ severity: zod.z.string().nullish(),
787
+ severityScore: zod.z.number().nullish(),
788
+ blocked: zod.z.boolean().nullish()
789
+ });
790
+ var responseSchema = zod.z.object({
791
+ candidates: zod.z.array(
792
+ zod.z.object({
793
+ content: contentSchema.nullish().or(zod.z.object({}).strict()),
794
+ finishReason: zod.z.string().nullish(),
795
+ safetyRatings: zod.z.array(safetyRatingSchema).nullish(),
796
+ groundingMetadata: groundingMetadataSchema.nullish()
797
+ })
798
+ ),
799
+ usageMetadata: zod.z.object({
800
+ promptTokenCount: zod.z.number().nullish(),
801
+ candidatesTokenCount: zod.z.number().nullish(),
802
+ totalTokenCount: zod.z.number().nullish()
803
+ }).nullish()
804
+ });
805
+ var chunkSchema = zod.z.object({
806
+ candidates: zod.z.array(
807
+ zod.z.object({
808
+ content: contentSchema.nullish(),
809
+ finishReason: zod.z.string().nullish(),
810
+ safetyRatings: zod.z.array(safetyRatingSchema).nullish(),
811
+ groundingMetadata: groundingMetadataSchema.nullish()
812
+ })
813
+ ).nullish(),
814
+ usageMetadata: zod.z.object({
815
+ promptTokenCount: zod.z.number().nullish(),
816
+ candidatesTokenCount: zod.z.number().nullish(),
817
+ totalTokenCount: zod.z.number().nullish()
818
+ }).nullish()
819
+ });
820
+ var googleGenerativeAIProviderOptionsSchema = zod.z.object({
821
+ responseModalities: zod.z.array(zod.z.enum(["TEXT", "IMAGE"])).nullish(),
822
+ thinkingConfig: zod.z.object({
823
+ thinkingBudget: zod.z.number().nullish(),
824
+ includeThoughts: zod.z.boolean().nullish()
825
+ }).nullish()
826
+ });
827
+ var GoogleGenerativeAIEmbeddingModel = class {
828
+ constructor(modelId, settings, config) {
829
+ this.specificationVersion = "v1";
830
+ this.modelId = modelId;
831
+ this.settings = settings;
832
+ this.config = config;
833
+ }
834
+ get provider() {
835
+ return this.config.provider;
836
+ }
837
+ get maxEmbeddingsPerCall() {
838
+ return 2048;
839
+ }
840
+ get supportsParallelCalls() {
841
+ return true;
842
+ }
843
+ async doEmbed({
844
+ values,
845
+ headers,
846
+ abortSignal
847
+ }) {
848
+ if (values.length > this.maxEmbeddingsPerCall) {
849
+ throw new chunkLPM6BBAX_cjs.TooManyEmbeddingValuesForCallError({
850
+ provider: this.provider,
851
+ modelId: this.modelId,
852
+ maxEmbeddingsPerCall: this.maxEmbeddingsPerCall,
853
+ values
854
+ });
855
+ }
856
+ const mergedHeaders = chunkLPM6BBAX_cjs.combineHeaders(
857
+ await chunkLPM6BBAX_cjs.resolve(this.config.headers),
858
+ headers
859
+ );
860
+ const { responseHeaders, value: response } = await chunkLPM6BBAX_cjs.postJsonToApi({
861
+ url: `${this.config.baseURL}/models/${this.modelId}:batchEmbedContents`,
862
+ headers: mergedHeaders,
863
+ body: {
864
+ requests: values.map((value) => ({
865
+ model: `models/${this.modelId}`,
866
+ content: { role: "user", parts: [{ text: value }] },
867
+ outputDimensionality: this.settings.outputDimensionality,
868
+ taskType: this.settings.taskType
869
+ }))
870
+ },
871
+ failedResponseHandler: googleFailedResponseHandler,
872
+ successfulResponseHandler: chunkLPM6BBAX_cjs.createJsonResponseHandler(
873
+ googleGenerativeAITextEmbeddingResponseSchema
874
+ ),
875
+ abortSignal,
876
+ fetch: this.config.fetch
877
+ });
878
+ return {
879
+ embeddings: response.embeddings.map((item) => item.values),
880
+ usage: void 0,
881
+ rawResponse: { headers: responseHeaders }
882
+ };
883
+ }
884
+ };
885
+ var googleGenerativeAITextEmbeddingResponseSchema = zod.z.object({
886
+ embeddings: zod.z.array(zod.z.object({ values: zod.z.array(zod.z.number()) }))
887
+ });
888
+ function isSupportedFileUrl(url) {
889
+ return url.toString().startsWith("https://generativelanguage.googleapis.com/v1beta/files/");
890
+ }
891
+ function createGoogleGenerativeAI(options = {}) {
892
+ var _a;
893
+ const baseURL = (_a = chunkLPM6BBAX_cjs.withoutTrailingSlash(options.baseURL)) != null ? _a : "https://generativelanguage.googleapis.com/v1beta";
894
+ const getHeaders = () => ({
895
+ "x-goog-api-key": chunkLPM6BBAX_cjs.loadApiKey({
896
+ apiKey: options.apiKey,
897
+ environmentVariableName: "GOOGLE_GENERATIVE_AI_API_KEY",
898
+ description: "Google Generative AI"
899
+ }),
900
+ ...options.headers
901
+ });
902
+ const createChatModel = (modelId, settings = {}) => {
903
+ var _a2;
904
+ return new GoogleGenerativeAILanguageModel(modelId, settings, {
905
+ provider: "google.generative-ai",
906
+ baseURL,
907
+ headers: getHeaders,
908
+ generateId: (_a2 = options.generateId) != null ? _a2 : chunkLPM6BBAX_cjs.generateId,
909
+ isSupportedUrl: isSupportedFileUrl,
910
+ fetch: options.fetch
911
+ });
912
+ };
913
+ const createEmbeddingModel = (modelId, settings = {}) => new GoogleGenerativeAIEmbeddingModel(modelId, settings, {
914
+ provider: "google.generative-ai",
915
+ baseURL,
916
+ headers: getHeaders,
917
+ fetch: options.fetch
918
+ });
919
+ const provider = function(modelId, settings) {
920
+ if (new.target) {
921
+ throw new Error(
922
+ "The Google Generative AI model function cannot be called with the new keyword."
923
+ );
924
+ }
925
+ return createChatModel(modelId, settings);
926
+ };
927
+ provider.languageModel = createChatModel;
928
+ provider.chat = createChatModel;
929
+ provider.generativeAI = createChatModel;
930
+ provider.embedding = createEmbeddingModel;
931
+ provider.textEmbedding = createEmbeddingModel;
932
+ provider.textEmbeddingModel = createEmbeddingModel;
933
+ return provider;
934
+ }
935
+ var google = createGoogleGenerativeAI();
936
+
937
+ exports.createGoogleGenerativeAI = createGoogleGenerativeAI;
938
+ exports.google = google;
939
+ //# sourceMappingURL=dist-FZYCV3VB.cjs.map
940
+ //# sourceMappingURL=dist-FZYCV3VB.cjs.map