@llumiverse/drivers 1.3.0 → 1.4.0

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 (409) hide show
  1. package/lib/{types/adobe → adobe}/firefly.d.ts +2 -1
  2. package/lib/adobe/firefly.d.ts.map +1 -0
  3. package/lib/adobe/firefly.js +120 -0
  4. package/lib/adobe/firefly.js.map +1 -0
  5. package/lib/{types/anthropic → anthropic}/index.d.ts +4 -2
  6. package/lib/anthropic/index.d.ts.map +1 -0
  7. package/lib/{esm/anthropic → anthropic}/index.js +19 -8
  8. package/lib/anthropic/index.js.map +1 -0
  9. package/lib/{types/azure → azure}/azure_foundry.d.ts +9 -7
  10. package/lib/azure/azure_foundry.d.ts.map +1 -0
  11. package/lib/{esm/azure → azure}/azure_foundry.js +138 -124
  12. package/lib/azure/azure_foundry.js.map +1 -0
  13. package/lib/{types/bedrock → bedrock}/converse.d.ts +2 -2
  14. package/lib/bedrock/converse.d.ts.map +1 -0
  15. package/lib/{esm/bedrock → bedrock}/converse.js +86 -79
  16. package/lib/bedrock/converse.js.map +1 -0
  17. package/lib/bedrock/embeddings.d.ts +4 -0
  18. package/lib/bedrock/embeddings.d.ts.map +1 -0
  19. package/lib/bedrock/embeddings.js +359 -0
  20. package/lib/bedrock/embeddings.js.map +1 -0
  21. package/lib/{types/bedrock → bedrock}/index.d.ts +33 -9
  22. package/lib/bedrock/index.d.ts.map +1 -0
  23. package/lib/{esm/bedrock → bedrock}/index.js +599 -324
  24. package/lib/bedrock/index.js.map +1 -0
  25. package/lib/{types/bedrock → bedrock}/nova-image-payload.d.ts +5 -5
  26. package/lib/bedrock/nova-image-payload.d.ts.map +1 -0
  27. package/lib/{esm/bedrock → bedrock}/nova-image-payload.js +31 -36
  28. package/lib/bedrock/nova-image-payload.js.map +1 -0
  29. package/lib/{types/bedrock → bedrock}/payloads.d.ts +1 -1
  30. package/lib/bedrock/payloads.d.ts.map +1 -0
  31. package/lib/{cjs/bedrock → bedrock}/payloads.js.map +1 -1
  32. package/lib/{types/bedrock → bedrock}/s3.d.ts +3 -2
  33. package/lib/bedrock/s3.d.ts.map +1 -0
  34. package/lib/{esm/bedrock → bedrock}/s3.js +27 -23
  35. package/lib/bedrock/s3.js.map +1 -0
  36. package/lib/{types/bedrock → bedrock}/twelvelabs.d.ts +8 -9
  37. package/lib/bedrock/twelvelabs.d.ts.map +1 -0
  38. package/lib/{esm/bedrock → bedrock}/twelvelabs.js +17 -21
  39. package/lib/bedrock/twelvelabs.js.map +1 -0
  40. package/lib/{types/groq → groq}/index.d.ts +6 -4
  41. package/lib/groq/index.d.ts.map +1 -0
  42. package/lib/{esm/groq → groq}/index.js +72 -39
  43. package/lib/groq/index.js.map +1 -0
  44. package/lib/{types/huggingface_ie.d.ts → huggingface_ie.d.ts} +4 -3
  45. package/lib/huggingface_ie.d.ts.map +1 -0
  46. package/lib/{esm/huggingface_ie.js → huggingface_ie.js} +32 -31
  47. package/lib/huggingface_ie.js.map +1 -0
  48. package/lib/index.d.ts +16 -0
  49. package/lib/index.d.ts.map +1 -0
  50. package/lib/index.js +16 -0
  51. package/lib/index.js.map +1 -0
  52. package/lib/{types/mistral → mistral}/index.d.ts +6 -5
  53. package/lib/mistral/index.d.ts.map +1 -0
  54. package/lib/{esm/mistral → mistral}/index.js +66 -38
  55. package/lib/mistral/index.js.map +1 -0
  56. package/lib/{types/mistral → mistral}/types.d.ts +1 -0
  57. package/lib/mistral/types.d.ts.map +1 -0
  58. package/lib/mistral/types.js.map +1 -0
  59. package/lib/{types/openai → openai}/azure_openai.d.ts +5 -4
  60. package/lib/openai/azure_openai.d.ts.map +1 -0
  61. package/lib/{esm/openai → openai}/azure_openai.js +17 -14
  62. package/lib/openai/azure_openai.js.map +1 -0
  63. package/lib/openai/drivers.d.ts +4 -0
  64. package/lib/openai/drivers.d.ts.map +1 -0
  65. package/lib/openai/drivers.js +9 -0
  66. package/lib/openai/drivers.js.map +1 -0
  67. package/lib/{types/openai → openai}/index.d.ts +16 -5
  68. package/lib/openai/index.d.ts.map +1 -0
  69. package/lib/{esm/openai → openai}/index.js +242 -141
  70. package/lib/openai/index.js.map +1 -0
  71. package/lib/{types/openai → openai}/openai.d.ts +3 -3
  72. package/lib/openai/openai.d.ts.map +1 -0
  73. package/lib/openai/openai.js +15 -0
  74. package/lib/openai/openai.js.map +1 -0
  75. package/lib/{types/openai → openai}/openai_compatible.d.ts +3 -3
  76. package/lib/openai/openai_compatible.d.ts.map +1 -0
  77. package/lib/{esm/openai → openai}/openai_compatible.js +14 -11
  78. package/lib/openai/openai_compatible.js.map +1 -0
  79. package/lib/{types/openai → openai}/openai_format.d.ts +3 -2
  80. package/lib/openai/openai_format.d.ts.map +1 -0
  81. package/lib/{esm/openai → openai}/openai_format.js +66 -24
  82. package/lib/openai/openai_format.js.map +1 -0
  83. package/lib/{types/replicate.d.ts → replicate.d.ts} +3 -2
  84. package/lib/replicate.d.ts.map +1 -0
  85. package/lib/{esm/replicate.js → replicate.js} +59 -49
  86. package/lib/replicate.js.map +1 -0
  87. package/lib/{types/shared → shared}/claude-messages.d.ts +25 -1
  88. package/lib/shared/claude-messages.d.ts.map +1 -0
  89. package/lib/{esm/shared → shared}/claude-messages.js +212 -59
  90. package/lib/shared/claude-messages.js.map +1 -0
  91. package/lib/{types/shared → shared}/claude-thinking.d.ts +1 -1
  92. package/lib/shared/claude-thinking.d.ts.map +1 -0
  93. package/lib/{esm/shared → shared}/claude-thinking.js +5 -7
  94. package/lib/shared/claude-thinking.js.map +1 -0
  95. package/lib/shared/debug-prompt.d.ts +5 -0
  96. package/lib/shared/debug-prompt.d.ts.map +1 -0
  97. package/lib/shared/debug-prompt.js +25 -0
  98. package/lib/shared/debug-prompt.js.map +1 -0
  99. package/lib/{types/test-driver → test-driver}/TestErrorCompletionStream.d.ts +1 -1
  100. package/lib/test-driver/TestErrorCompletionStream.d.ts.map +1 -0
  101. package/lib/test-driver/TestErrorCompletionStream.js +16 -0
  102. package/lib/test-driver/TestErrorCompletionStream.js.map +1 -0
  103. package/lib/{types/test-driver → test-driver}/TestValidationErrorCompletionStream.d.ts +1 -1
  104. package/lib/test-driver/TestValidationErrorCompletionStream.d.ts.map +1 -0
  105. package/lib/{esm/test-driver → test-driver}/TestValidationErrorCompletionStream.js +4 -4
  106. package/lib/test-driver/TestValidationErrorCompletionStream.js.map +1 -0
  107. package/lib/{types/test-driver → test-driver}/index.d.ts +3 -3
  108. package/lib/test-driver/index.d.ts.map +1 -0
  109. package/lib/{esm/test-driver → test-driver}/index.js +20 -20
  110. package/lib/test-driver/index.js.map +1 -0
  111. package/lib/{types/test-driver → test-driver}/utils.d.ts +1 -1
  112. package/lib/test-driver/utils.d.ts.map +1 -0
  113. package/lib/{esm/test-driver → test-driver}/utils.js +4 -4
  114. package/lib/test-driver/utils.js.map +1 -0
  115. package/lib/togetherai/index.d.ts +15 -0
  116. package/lib/togetherai/index.d.ts.map +1 -0
  117. package/lib/togetherai/index.js +54 -0
  118. package/lib/togetherai/index.js.map +1 -0
  119. package/lib/{types/togetherai → togetherai}/interfaces.d.ts +1 -1
  120. package/lib/togetherai/interfaces.d.ts.map +1 -0
  121. package/lib/{cjs/watsonx → togetherai}/interfaces.js.map +1 -1
  122. package/lib/vertexai/debug.d.ts +2 -0
  123. package/lib/vertexai/debug.d.ts.map +1 -0
  124. package/lib/{esm/vertexai → vertexai}/debug.js +1 -1
  125. package/lib/vertexai/debug.js.map +1 -0
  126. package/lib/vertexai/embeddings/embed-legacy-multimodal.d.ts +9 -0
  127. package/lib/vertexai/embeddings/embed-legacy-multimodal.d.ts.map +1 -0
  128. package/lib/vertexai/embeddings/embed-legacy-multimodal.js +141 -0
  129. package/lib/vertexai/embeddings/embed-legacy-multimodal.js.map +1 -0
  130. package/lib/vertexai/embeddings/embed.d.ts +13 -0
  131. package/lib/vertexai/embeddings/embed.d.ts.map +1 -0
  132. package/lib/vertexai/embeddings/embed.js +162 -0
  133. package/lib/vertexai/embeddings/embed.js.map +1 -0
  134. package/lib/vertexai/embeddings/source-utils.d.ts +9 -0
  135. package/lib/vertexai/embeddings/source-utils.d.ts.map +1 -0
  136. package/lib/vertexai/embeddings/source-utils.js +18 -0
  137. package/lib/vertexai/embeddings/source-utils.js.map +1 -0
  138. package/lib/{types/vertexai → vertexai}/index.d.ts +31 -19
  139. package/lib/vertexai/index.d.ts.map +1 -0
  140. package/lib/{esm/vertexai → vertexai}/index.js +221 -159
  141. package/lib/vertexai/index.js.map +1 -0
  142. package/lib/{types/vertexai → vertexai}/models/claude.d.ts +4 -4
  143. package/lib/vertexai/models/claude.d.ts.map +1 -0
  144. package/lib/{esm/vertexai → vertexai}/models/claude.js +17 -20
  145. package/lib/vertexai/models/claude.js.map +1 -0
  146. package/lib/{types/vertexai → vertexai}/models/gemini.d.ts +28 -4
  147. package/lib/vertexai/models/gemini.d.ts.map +1 -0
  148. package/lib/{esm/vertexai → vertexai}/models/gemini.js +238 -116
  149. package/lib/vertexai/models/gemini.js.map +1 -0
  150. package/lib/{types/vertexai → vertexai}/models/imagen.d.ts +12 -11
  151. package/lib/vertexai/models/imagen.d.ts.map +1 -0
  152. package/lib/{esm/vertexai → vertexai}/models/imagen.js +74 -47
  153. package/lib/vertexai/models/imagen.js.map +1 -0
  154. package/lib/{types/vertexai → vertexai}/models/llama.d.ts +4 -4
  155. package/lib/vertexai/models/llama.d.ts.map +1 -0
  156. package/lib/{esm/vertexai → vertexai}/models/llama.js +37 -33
  157. package/lib/vertexai/models/llama.js.map +1 -0
  158. package/lib/vertexai/models.d.ts +21 -0
  159. package/lib/vertexai/models.d.ts.map +1 -0
  160. package/lib/{esm/vertexai → vertexai}/models.js +12 -9
  161. package/lib/vertexai/models.js.map +1 -0
  162. package/lib/{types/watsonx → watsonx}/index.d.ts +4 -3
  163. package/lib/watsonx/index.d.ts.map +1 -0
  164. package/lib/{esm/watsonx → watsonx}/index.js +69 -41
  165. package/lib/watsonx/index.js.map +1 -0
  166. package/lib/watsonx/interfaces.d.ts.map +1 -0
  167. package/lib/{esm/watsonx → watsonx}/interfaces.js.map +1 -1
  168. package/lib/{types/xai → xai}/index.d.ts +4 -4
  169. package/lib/xai/index.d.ts.map +1 -0
  170. package/lib/{esm/xai → xai}/index.js +22 -18
  171. package/lib/xai/index.js.map +1 -0
  172. package/package.json +87 -36
  173. package/src/adobe/firefly.ts +60 -43
  174. package/src/anthropic/index.ts +37 -20
  175. package/src/azure/azure_foundry.ts +210 -165
  176. package/src/bedrock/converse.ts +124 -101
  177. package/src/bedrock/embeddings.test.ts +508 -0
  178. package/src/bedrock/embeddings.ts +517 -0
  179. package/src/bedrock/error-handling.test.ts +62 -14
  180. package/src/bedrock/index.ts +832 -466
  181. package/src/bedrock/nova-image-payload.ts +98 -91
  182. package/src/bedrock/payloads.ts +9 -9
  183. package/src/bedrock/s3.test.ts +39 -0
  184. package/src/bedrock/s3.ts +57 -38
  185. package/src/bedrock/streaming-tool-use.test.ts +86 -69
  186. package/src/bedrock/twelvelabs.ts +35 -32
  187. package/src/groq/index.ts +143 -60
  188. package/src/http-timeout-wiring.test.ts +263 -0
  189. package/src/huggingface_ie.ts +45 -61
  190. package/src/index.ts +15 -16
  191. package/src/mistral/index.ts +97 -48
  192. package/src/mistral/types.ts +13 -12
  193. package/src/openai/azure_openai.ts +35 -27
  194. package/src/openai/drivers.ts +9 -0
  195. package/src/openai/error-handling.test.ts +308 -113
  196. package/src/openai/index.ts +378 -248
  197. package/src/openai/openai.ts +6 -13
  198. package/src/openai/openai_compatible.ts +35 -25
  199. package/src/openai/openai_format.ts +90 -40
  200. package/src/replicate.ts +108 -86
  201. package/src/shared/claude-messages.test.ts +37 -0
  202. package/src/shared/claude-messages.ts +303 -97
  203. package/src/shared/claude-thinking.ts +6 -12
  204. package/src/shared/debug-prompt.ts +28 -0
  205. package/src/test-driver/TestErrorCompletionStream.ts +9 -10
  206. package/src/test-driver/TestValidationErrorCompletionStream.ts +9 -10
  207. package/src/test-driver/index.ts +43 -27
  208. package/src/test-driver/utils.ts +8 -8
  209. package/src/togetherai/index.test.ts +32 -0
  210. package/src/togetherai/index.ts +64 -128
  211. package/src/togetherai/interfaces.ts +5 -5
  212. package/src/vertexai/debug.ts +3 -3
  213. package/src/vertexai/embeddings/embed-legacy-multimodal.ts +211 -0
  214. package/src/vertexai/embeddings/embed.ts +206 -0
  215. package/src/vertexai/embeddings/embeddings.test.ts +497 -0
  216. package/src/vertexai/embeddings/source-utils.test.ts +54 -0
  217. package/src/vertexai/embeddings/source-utils.ts +29 -0
  218. package/src/vertexai/index.ts +331 -244
  219. package/src/vertexai/models/claude-error-handling.test.ts +83 -36
  220. package/src/vertexai/models/claude-streaming-spacing.test.ts +82 -75
  221. package/src/vertexai/models/claude.ts +55 -40
  222. package/src/vertexai/models/gemini-conversation-mutation.test.ts +65 -23
  223. package/src/vertexai/models/gemini-error-handling.test.ts +126 -10
  224. package/src/vertexai/models/gemini-orphaned-tool-result.test.ts +118 -0
  225. package/src/vertexai/models/gemini.ts +349 -172
  226. package/src/vertexai/models/imagen.ts +164 -100
  227. package/src/vertexai/models/llama.ts +70 -48
  228. package/src/vertexai/models.ts +36 -16
  229. package/src/watsonx/index.ts +101 -65
  230. package/src/watsonx/interfaces.ts +10 -15
  231. package/src/xai/index.ts +30 -30
  232. package/lib/cjs/adobe/firefly.js +0 -120
  233. package/lib/cjs/adobe/firefly.js.map +0 -1
  234. package/lib/cjs/anthropic/index.js +0 -64
  235. package/lib/cjs/anthropic/index.js.map +0 -1
  236. package/lib/cjs/azure/azure_foundry.js +0 -432
  237. package/lib/cjs/azure/azure_foundry.js.map +0 -1
  238. package/lib/cjs/bedrock/converse.js +0 -359
  239. package/lib/cjs/bedrock/converse.js.map +0 -1
  240. package/lib/cjs/bedrock/index.js +0 -1508
  241. package/lib/cjs/bedrock/index.js.map +0 -1
  242. package/lib/cjs/bedrock/nova-image-payload.js +0 -207
  243. package/lib/cjs/bedrock/nova-image-payload.js.map +0 -1
  244. package/lib/cjs/bedrock/payloads.js +0 -3
  245. package/lib/cjs/bedrock/s3.js +0 -107
  246. package/lib/cjs/bedrock/s3.js.map +0 -1
  247. package/lib/cjs/bedrock/twelvelabs.js +0 -87
  248. package/lib/cjs/bedrock/twelvelabs.js.map +0 -1
  249. package/lib/cjs/groq/index.js +0 -328
  250. package/lib/cjs/groq/index.js.map +0 -1
  251. package/lib/cjs/huggingface_ie.js +0 -201
  252. package/lib/cjs/huggingface_ie.js.map +0 -1
  253. package/lib/cjs/index.js +0 -32
  254. package/lib/cjs/index.js.map +0 -1
  255. package/lib/cjs/mistral/index.js +0 -176
  256. package/lib/cjs/mistral/index.js.map +0 -1
  257. package/lib/cjs/mistral/types.js +0 -83
  258. package/lib/cjs/mistral/types.js.map +0 -1
  259. package/lib/cjs/openai/azure_openai.js +0 -72
  260. package/lib/cjs/openai/azure_openai.js.map +0 -1
  261. package/lib/cjs/openai/index.js +0 -1135
  262. package/lib/cjs/openai/index.js.map +0 -1
  263. package/lib/cjs/openai/openai.js +0 -21
  264. package/lib/cjs/openai/openai.js.map +0 -1
  265. package/lib/cjs/openai/openai_compatible.js +0 -63
  266. package/lib/cjs/openai/openai_compatible.js.map +0 -1
  267. package/lib/cjs/openai/openai_format.js +0 -131
  268. package/lib/cjs/openai/openai_format.js.map +0 -1
  269. package/lib/cjs/package.json +0 -3
  270. package/lib/cjs/replicate.js +0 -275
  271. package/lib/cjs/replicate.js.map +0 -1
  272. package/lib/cjs/shared/claude-messages.js +0 -737
  273. package/lib/cjs/shared/claude-messages.js.map +0 -1
  274. package/lib/cjs/shared/claude-thinking.js +0 -60
  275. package/lib/cjs/shared/claude-thinking.js.map +0 -1
  276. package/lib/cjs/test-driver/TestErrorCompletionStream.js +0 -20
  277. package/lib/cjs/test-driver/TestErrorCompletionStream.js.map +0 -1
  278. package/lib/cjs/test-driver/TestValidationErrorCompletionStream.js +0 -24
  279. package/lib/cjs/test-driver/TestValidationErrorCompletionStream.js.map +0 -1
  280. package/lib/cjs/test-driver/index.js +0 -109
  281. package/lib/cjs/test-driver/index.js.map +0 -1
  282. package/lib/cjs/test-driver/utils.js +0 -30
  283. package/lib/cjs/test-driver/utils.js.map +0 -1
  284. package/lib/cjs/togetherai/index.js +0 -126
  285. package/lib/cjs/togetherai/index.js.map +0 -1
  286. package/lib/cjs/togetherai/interfaces.js +0 -3
  287. package/lib/cjs/togetherai/interfaces.js.map +0 -1
  288. package/lib/cjs/vertexai/debug.js +0 -12
  289. package/lib/cjs/vertexai/debug.js.map +0 -1
  290. package/lib/cjs/vertexai/embeddings/embeddings-image.js +0 -27
  291. package/lib/cjs/vertexai/embeddings/embeddings-image.js.map +0 -1
  292. package/lib/cjs/vertexai/embeddings/embeddings-text.js +0 -23
  293. package/lib/cjs/vertexai/embeddings/embeddings-text.js.map +0 -1
  294. package/lib/cjs/vertexai/index.js +0 -644
  295. package/lib/cjs/vertexai/index.js.map +0 -1
  296. package/lib/cjs/vertexai/models/claude.js +0 -72
  297. package/lib/cjs/vertexai/models/claude.js.map +0 -1
  298. package/lib/cjs/vertexai/models/gemini.js +0 -864
  299. package/lib/cjs/vertexai/models/gemini.js.map +0 -1
  300. package/lib/cjs/vertexai/models/imagen.js +0 -303
  301. package/lib/cjs/vertexai/models/imagen.js.map +0 -1
  302. package/lib/cjs/vertexai/models/llama.js +0 -183
  303. package/lib/cjs/vertexai/models/llama.js.map +0 -1
  304. package/lib/cjs/vertexai/models.js +0 -35
  305. package/lib/cjs/vertexai/models.js.map +0 -1
  306. package/lib/cjs/watsonx/index.js +0 -161
  307. package/lib/cjs/watsonx/index.js.map +0 -1
  308. package/lib/cjs/watsonx/interfaces.js +0 -3
  309. package/lib/cjs/xai/index.js +0 -65
  310. package/lib/cjs/xai/index.js.map +0 -1
  311. package/lib/esm/adobe/firefly.js +0 -116
  312. package/lib/esm/adobe/firefly.js.map +0 -1
  313. package/lib/esm/anthropic/index.js.map +0 -1
  314. package/lib/esm/azure/azure_foundry.js.map +0 -1
  315. package/lib/esm/bedrock/converse.js.map +0 -1
  316. package/lib/esm/bedrock/index.js.map +0 -1
  317. package/lib/esm/bedrock/nova-image-payload.js.map +0 -1
  318. package/lib/esm/bedrock/payloads.js.map +0 -1
  319. package/lib/esm/bedrock/s3.js.map +0 -1
  320. package/lib/esm/bedrock/twelvelabs.js.map +0 -1
  321. package/lib/esm/groq/index.js.map +0 -1
  322. package/lib/esm/huggingface_ie.js.map +0 -1
  323. package/lib/esm/index.js +0 -16
  324. package/lib/esm/index.js.map +0 -1
  325. package/lib/esm/mistral/index.js.map +0 -1
  326. package/lib/esm/mistral/types.js.map +0 -1
  327. package/lib/esm/openai/azure_openai.js.map +0 -1
  328. package/lib/esm/openai/index.js.map +0 -1
  329. package/lib/esm/openai/openai.js +0 -14
  330. package/lib/esm/openai/openai.js.map +0 -1
  331. package/lib/esm/openai/openai_compatible.js.map +0 -1
  332. package/lib/esm/openai/openai_format.js.map +0 -1
  333. package/lib/esm/replicate.js.map +0 -1
  334. package/lib/esm/shared/claude-messages.js.map +0 -1
  335. package/lib/esm/shared/claude-thinking.js.map +0 -1
  336. package/lib/esm/test-driver/TestErrorCompletionStream.js +0 -16
  337. package/lib/esm/test-driver/TestErrorCompletionStream.js.map +0 -1
  338. package/lib/esm/test-driver/TestValidationErrorCompletionStream.js.map +0 -1
  339. package/lib/esm/test-driver/index.js.map +0 -1
  340. package/lib/esm/test-driver/utils.js.map +0 -1
  341. package/lib/esm/togetherai/index.js +0 -122
  342. package/lib/esm/togetherai/index.js.map +0 -1
  343. package/lib/esm/togetherai/interfaces.js.map +0 -1
  344. package/lib/esm/vertexai/debug.js.map +0 -1
  345. package/lib/esm/vertexai/embeddings/embeddings-image.js +0 -24
  346. package/lib/esm/vertexai/embeddings/embeddings-image.js.map +0 -1
  347. package/lib/esm/vertexai/embeddings/embeddings-text.js +0 -20
  348. package/lib/esm/vertexai/embeddings/embeddings-text.js.map +0 -1
  349. package/lib/esm/vertexai/index.js.map +0 -1
  350. package/lib/esm/vertexai/models/claude.js.map +0 -1
  351. package/lib/esm/vertexai/models/gemini.js.map +0 -1
  352. package/lib/esm/vertexai/models/imagen.js.map +0 -1
  353. package/lib/esm/vertexai/models/llama.js.map +0 -1
  354. package/lib/esm/vertexai/models.js.map +0 -1
  355. package/lib/esm/watsonx/index.js.map +0 -1
  356. package/lib/esm/xai/index.js.map +0 -1
  357. package/lib/types/adobe/firefly.d.ts.map +0 -1
  358. package/lib/types/anthropic/index.d.ts.map +0 -1
  359. package/lib/types/azure/azure_foundry.d.ts.map +0 -1
  360. package/lib/types/bedrock/converse.d.ts.map +0 -1
  361. package/lib/types/bedrock/index.d.ts.map +0 -1
  362. package/lib/types/bedrock/nova-image-payload.d.ts.map +0 -1
  363. package/lib/types/bedrock/payloads.d.ts.map +0 -1
  364. package/lib/types/bedrock/s3.d.ts.map +0 -1
  365. package/lib/types/bedrock/twelvelabs.d.ts.map +0 -1
  366. package/lib/types/groq/index.d.ts.map +0 -1
  367. package/lib/types/huggingface_ie.d.ts.map +0 -1
  368. package/lib/types/index.d.ts +0 -16
  369. package/lib/types/index.d.ts.map +0 -1
  370. package/lib/types/mistral/index.d.ts.map +0 -1
  371. package/lib/types/mistral/types.d.ts.map +0 -1
  372. package/lib/types/openai/azure_openai.d.ts.map +0 -1
  373. package/lib/types/openai/index.d.ts.map +0 -1
  374. package/lib/types/openai/openai.d.ts.map +0 -1
  375. package/lib/types/openai/openai_compatible.d.ts.map +0 -1
  376. package/lib/types/openai/openai_format.d.ts.map +0 -1
  377. package/lib/types/replicate.d.ts.map +0 -1
  378. package/lib/types/shared/claude-messages.d.ts.map +0 -1
  379. package/lib/types/shared/claude-thinking.d.ts.map +0 -1
  380. package/lib/types/test-driver/TestErrorCompletionStream.d.ts.map +0 -1
  381. package/lib/types/test-driver/TestValidationErrorCompletionStream.d.ts.map +0 -1
  382. package/lib/types/test-driver/index.d.ts.map +0 -1
  383. package/lib/types/test-driver/utils.d.ts.map +0 -1
  384. package/lib/types/togetherai/index.d.ts +0 -23
  385. package/lib/types/togetherai/index.d.ts.map +0 -1
  386. package/lib/types/togetherai/interfaces.d.ts.map +0 -1
  387. package/lib/types/vertexai/debug.d.ts +0 -2
  388. package/lib/types/vertexai/debug.d.ts.map +0 -1
  389. package/lib/types/vertexai/embeddings/embeddings-image.d.ts +0 -11
  390. package/lib/types/vertexai/embeddings/embeddings-image.d.ts.map +0 -1
  391. package/lib/types/vertexai/embeddings/embeddings-text.d.ts +0 -10
  392. package/lib/types/vertexai/embeddings/embeddings-text.d.ts.map +0 -1
  393. package/lib/types/vertexai/index.d.ts.map +0 -1
  394. package/lib/types/vertexai/models/claude.d.ts.map +0 -1
  395. package/lib/types/vertexai/models/gemini.d.ts.map +0 -1
  396. package/lib/types/vertexai/models/imagen.d.ts.map +0 -1
  397. package/lib/types/vertexai/models/llama.d.ts.map +0 -1
  398. package/lib/types/vertexai/models.d.ts +0 -20
  399. package/lib/types/vertexai/models.d.ts.map +0 -1
  400. package/lib/types/watsonx/index.d.ts.map +0 -1
  401. package/lib/types/watsonx/interfaces.d.ts.map +0 -1
  402. package/lib/types/xai/index.d.ts.map +0 -1
  403. package/src/vertexai/embeddings/embeddings-image.ts +0 -52
  404. package/src/vertexai/embeddings/embeddings-text.ts +0 -54
  405. /package/lib/{esm/bedrock → bedrock}/payloads.js +0 -0
  406. /package/lib/{esm/mistral → mistral}/types.js +0 -0
  407. /package/lib/{esm/togetherai → togetherai}/interfaces.js +0 -0
  408. /package/lib/{types/watsonx → watsonx}/interfaces.d.ts +0 -0
  409. /package/lib/{esm/watsonx → watsonx}/interfaces.js +0 -0
@@ -1,864 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GeminiModelDefinition = void 0;
4
- exports.mergeConsecutiveRole = mergeConsecutiveRole;
5
- exports.convertGeminiFunctionPartsToText = convertGeminiFunctionPartsToText;
6
- const genai_1 = require("@google/genai");
7
- const core_1 = require("@llumiverse/core");
8
- const async_1 = require("@llumiverse/core/async");
9
- function supportsStructuredOutput(options) {
10
- // Gemini 1.0 Ultra does not support JSON output, 1.0 Pro does.
11
- return !!options.result_schema && !options.model.includes("ultra");
12
- }
13
- const geminiSafetySettings = [
14
- {
15
- category: genai_1.HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT,
16
- threshold: genai_1.HarmBlockThreshold.BLOCK_ONLY_HIGH
17
- },
18
- {
19
- category: genai_1.HarmCategory.HARM_CATEGORY_HARASSMENT,
20
- threshold: genai_1.HarmBlockThreshold.BLOCK_ONLY_HIGH
21
- },
22
- {
23
- category: genai_1.HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT,
24
- threshold: genai_1.HarmBlockThreshold.BLOCK_ONLY_HIGH
25
- },
26
- {
27
- category: genai_1.HarmCategory.HARM_CATEGORY_HATE_SPEECH,
28
- threshold: genai_1.HarmBlockThreshold.BLOCK_ONLY_HIGH
29
- },
30
- {
31
- category: genai_1.HarmCategory.HARM_CATEGORY_UNSPECIFIED,
32
- threshold: genai_1.HarmBlockThreshold.BLOCK_ONLY_HIGH
33
- },
34
- {
35
- category: genai_1.HarmCategory.HARM_CATEGORY_CIVIC_INTEGRITY,
36
- threshold: genai_1.HarmBlockThreshold.BLOCK_ONLY_HIGH
37
- }
38
- ];
39
- // We do the mapping here rather than in common to avoid bringing the SDK into the common package.
40
- function getProminentPeopleOption(prominentPeople) {
41
- switch (prominentPeople) {
42
- case "ALLOW_PROMINENT_PEOPLE":
43
- return genai_1.ProminentPeople.ALLOW_PROMINENT_PEOPLE;
44
- case "BLOCK_PROMINENT_PEOPLE":
45
- return genai_1.ProminentPeople.BLOCK_PROMINENT_PEOPLE;
46
- case "PROMINENT_PEOPLE_UNSPECIFIED":
47
- return genai_1.ProminentPeople.PROMINENT_PEOPLE_UNSPECIFIED;
48
- default:
49
- return undefined;
50
- }
51
- }
52
- function getGeminiPayload(options, prompt) {
53
- const model_options = options.model_options;
54
- const tools = getToolDefinitions(options.tools);
55
- // When no tools are provided but conversation contains functionCall/functionResponse parts
56
- // (e.g. checkpoint summary calls), convert them to text to avoid API errors.
57
- // Use a local variable to avoid mutating the caller's conversation object.
58
- let payloadContents = prompt.contents;
59
- if (!tools && payloadContents) {
60
- const hasToolParts = payloadContents.some(c => c.parts?.some(p => p.functionCall || p.functionResponse));
61
- if (hasToolParts) {
62
- payloadContents = convertGeminiFunctionPartsToText(payloadContents);
63
- }
64
- }
65
- const useStructuredOutput = supportsStructuredOutput(options) && !tools;
66
- const configNanoBanana = {
67
- systemInstruction: prompt.system,
68
- safetySettings: geminiSafetySettings,
69
- responseModalities: [genai_1.Modality.TEXT, genai_1.Modality.IMAGE], // This is an error if only Text, and Only Image just gets blank responses.
70
- candidateCount: 1,
71
- //Model options
72
- temperature: model_options?.temperature,
73
- topP: model_options?.top_p,
74
- maxOutputTokens: model_options?.max_tokens,
75
- stopSequences: model_options?.stop_sequence,
76
- thinkingConfig: geminiThinkingConfig(options),
77
- labels: options.labels,
78
- imageConfig: {
79
- imageSize: model_options?.image_size,
80
- aspectRatio: model_options?.image_aspect_ratio,
81
- personGeneration: model_options?.person_generation,
82
- prominentPeople: getProminentPeopleOption(model_options?.prominent_people),
83
- outputMimeType: model_options?.output_mime_type,
84
- outputCompressionQuality: model_options?.output_compression_quality,
85
- }
86
- };
87
- const config = {
88
- systemInstruction: prompt.system,
89
- safetySettings: geminiSafetySettings,
90
- tools: tools ? [tools] : undefined,
91
- toolConfig: tools ? {
92
- functionCallingConfig: {
93
- mode: genai_1.FunctionCallingConfigMode.AUTO,
94
- }
95
- } : undefined,
96
- candidateCount: 1,
97
- //JSON/Structured output
98
- responseMimeType: useStructuredOutput ? "application/json" : undefined,
99
- responseJsonSchema: useStructuredOutput ? options.result_schema : undefined,
100
- //Model options
101
- temperature: model_options?.temperature,
102
- topP: model_options?.top_p,
103
- topK: model_options?.top_k,
104
- maxOutputTokens: model_options?.max_tokens,
105
- stopSequences: model_options?.stop_sequence,
106
- presencePenalty: model_options?.presence_penalty,
107
- frequencyPenalty: model_options?.frequency_penalty,
108
- seed: model_options?.seed,
109
- thinkingConfig: geminiThinkingConfig(options),
110
- labels: options.labels,
111
- };
112
- return {
113
- model: options.model,
114
- contents: payloadContents,
115
- config: options.model.toLowerCase().includes("image") ? configNanoBanana : config,
116
- };
117
- }
118
- /**
119
- * Collect all parts (text and images) from content in order.
120
- * This preserves the original ordering of text and image parts.
121
- */
122
- function extractCompletionResults(content) {
123
- const results = [];
124
- const parts = content.parts;
125
- if (parts) {
126
- for (const part of parts) {
127
- if (part.text) {
128
- results.push({
129
- type: "text",
130
- value: part.text
131
- });
132
- }
133
- else if (part.inlineData) {
134
- const base64ImageBytes = part.inlineData.data ?? "";
135
- const mimeType = part.inlineData.mimeType ?? "image/png";
136
- const imageUrl = `data:${mimeType};base64,${base64ImageBytes}`;
137
- results.push({
138
- type: "image",
139
- value: imageUrl
140
- });
141
- }
142
- }
143
- }
144
- return results;
145
- }
146
- function collectToolUseParts(content) {
147
- const out = [];
148
- const parts = content.parts ?? [];
149
- for (const part of parts) {
150
- if (part.functionCall) {
151
- const toolUse = {
152
- id: part.functionCall.name ?? '',
153
- tool_name: part.functionCall.name ?? '',
154
- tool_input: part.functionCall.args,
155
- };
156
- // Capture thought_signature for Gemini thinking models (2.5+/3.0+)
157
- // This must be passed back with the function response
158
- if (part.thoughtSignature) {
159
- toolUse.thought_signature = part.thoughtSignature;
160
- }
161
- out.push(toolUse);
162
- }
163
- }
164
- return out.length > 0 ? out : undefined;
165
- }
166
- function mergeConsecutiveRole(contents) {
167
- if (!contents || contents.length === 0)
168
- return [];
169
- const needsMerging = contents.some((content, i) => i < contents.length - 1 && content.role === contents[i + 1].role);
170
- // If no merging needed, return original array
171
- if (!needsMerging) {
172
- return contents;
173
- }
174
- const result = [];
175
- let currentContent = { ...contents[0], parts: [...(contents[0].parts || [])] };
176
- for (let i = 1; i < contents.length; i++) {
177
- if (currentContent.role === contents[i].role) {
178
- // Same role - concatenate parts (without merging individual parts)
179
- currentContent.parts = (currentContent.parts || []).concat(...(contents[i].parts || []));
180
- }
181
- else {
182
- // Different role - push current and start new
183
- result.push(currentContent);
184
- currentContent = { ...contents[i], parts: [...(contents[i].parts || [])] };
185
- }
186
- }
187
- result.push(currentContent);
188
- return result;
189
- }
190
- const supportedFinishReasons = [
191
- genai_1.FinishReason.MAX_TOKENS,
192
- genai_1.FinishReason.STOP,
193
- genai_1.FinishReason.FINISH_REASON_UNSPECIFIED,
194
- ];
195
- // Finish reasons that indicate tool call issues but should be recovered gracefully
196
- // instead of throwing an error. The tool_use is still extracted and returned
197
- // so the workflow can generate a proper toolError response.
198
- const recoverableToolCallReasons = [
199
- 'UNEXPECTED_TOOL_CALL', // Model called an undeclared tool
200
- ];
201
- function geminiThinkingBudget(option) {
202
- const model_options = option.model_options;
203
- // If thinking_budget_tokens is explicitly set in model options, use it directly
204
- if (model_options?.thinking_budget_tokens !== undefined) {
205
- return model_options.thinking_budget_tokens;
206
- }
207
- if (model_options?.effort) {
208
- return geminiBudgetForEffort(option.model, model_options.effort);
209
- }
210
- // Set minimum thinking level by default.
211
- // Docs: https://ai.google.dev/gemini-api/docs/thinking#set-budget
212
- if ((0, core_1.getGeminiModelVersion)(option.model) === '2.5') {
213
- if (option.model.includes("pro")) {
214
- return 128;
215
- }
216
- return 0;
217
- }
218
- return undefined;
219
- }
220
- function geminiThinkingLevelForEffort(model, effort) {
221
- if (model.includes("gemini-3-pro-image")) {
222
- return genai_1.ThinkingLevel.HIGH;
223
- }
224
- if (model.includes("gemini-3.1-flash-image")) {
225
- return effort === "low" ? genai_1.ThinkingLevel.MINIMAL : genai_1.ThinkingLevel.HIGH;
226
- }
227
- switch (effort) {
228
- case "low":
229
- return genai_1.ThinkingLevel.LOW;
230
- case "medium":
231
- return genai_1.ThinkingLevel.MEDIUM;
232
- case "high":
233
- return genai_1.ThinkingLevel.HIGH;
234
- default:
235
- return undefined;
236
- }
237
- }
238
- function geminiBudgetForEffort(model, effort) {
239
- const isFlashLite = model.includes("flash-lite");
240
- const isFlash = model.includes("flash") && !isFlashLite;
241
- const isPro = model.includes("pro");
242
- if (effort === "low") {
243
- if (isPro)
244
- return 128;
245
- if (isFlashLite)
246
- return 512;
247
- if (isFlash)
248
- return 1;
249
- return 1024;
250
- }
251
- if (effort === "medium") {
252
- return 8192;
253
- }
254
- if (isPro)
255
- return 32768;
256
- if (isFlash || isFlashLite)
257
- return 24576;
258
- return 8192;
259
- }
260
- function geminiThinkingConfig(option) {
261
- const model_options = option.model_options;
262
- // If thinking options are explicitly set in model options, use them directly
263
- const include_thoughts = model_options?.include_thoughts ?? false;
264
- if (model_options?.thinking_budget_tokens !== undefined || model_options?.thinking_level) {
265
- return {
266
- includeThoughts: include_thoughts,
267
- thinkingBudget: model_options.thinking_budget_tokens,
268
- thinkingLevel: model_options.thinking_level,
269
- };
270
- }
271
- if (model_options?.effort) {
272
- if ((0, core_1.isGeminiModelVersionGte)(option.model, '3.0')) {
273
- return {
274
- includeThoughts: include_thoughts,
275
- thinkingLevel: geminiThinkingLevelForEffort(option.model, model_options.effort),
276
- };
277
- }
278
- return {
279
- includeThoughts: include_thoughts,
280
- thinkingBudget: geminiBudgetForEffort(option.model, model_options.effort),
281
- };
282
- }
283
- // Set a low thinking level by default.
284
- // Docs: https://ai.google.dev/gemini-api/docs/thinking#set-budget
285
- // https://docs.cloud.google.com/vertex-ai/generative-ai/docs/thinking
286
- if ((0, core_1.isGeminiModelVersionGte)(option.model, '3.0')) {
287
- return {
288
- includeThoughts: include_thoughts,
289
- thinkingLevel: option.model.includes("gemini-3-pro-image") ? genai_1.ThinkingLevel.HIGH : genai_1.ThinkingLevel.LOW
290
- };
291
- }
292
- if ((0, core_1.isGeminiModelVersionGte)(option.model, '2.5')) {
293
- const thinking_budget_tokens = geminiThinkingBudget(option) ?? 0;
294
- return {
295
- includeThoughts: include_thoughts,
296
- thinkingBudget: thinking_budget_tokens
297
- };
298
- }
299
- }
300
- class GeminiModelDefinition {
301
- model;
302
- constructor(modelId) {
303
- this.model = {
304
- id: modelId,
305
- name: modelId,
306
- provider: 'vertexai',
307
- type: core_1.ModelType.Text,
308
- can_stream: true
309
- };
310
- }
311
- async createPrompt(_driver, segments, options) {
312
- const splits = options.model.split("/");
313
- const modelName = splits[splits.length - 1];
314
- options = { ...options, model: modelName };
315
- const schema = options.result_schema;
316
- let contents = [];
317
- let system = { role: "user", parts: [] }; // Single content block for system messages
318
- const safety = [];
319
- for (const msg of segments) {
320
- // Role specific handling
321
- if (msg.role === core_1.PromptRole.system) {
322
- // Text only for system messages
323
- if (msg.files && msg.files.length > 0) {
324
- throw new Error("Gemini does not support files/images etc. in system messages. Only text content is allowed.");
325
- }
326
- if (msg.content) {
327
- system.parts?.push({
328
- text: msg.content
329
- });
330
- }
331
- }
332
- else if (msg.role === core_1.PromptRole.tool) {
333
- if (!msg.tool_use_id) {
334
- throw new Error("Tool response missing tool_use_id");
335
- }
336
- // Build functionResponse part with optional thought_signature for Gemini thinking models
337
- const functionResponsePart = {
338
- functionResponse: {
339
- name: msg.tool_use_id,
340
- response: formatFunctionResponse(msg.content || ''),
341
- },
342
- // Include thought_signature if provided (required for Gemini 2.5+/3.0+ thinking models)
343
- thoughtSignature: msg.thought_signature,
344
- };
345
- contents.push({
346
- role: 'user',
347
- parts: [functionResponsePart]
348
- });
349
- }
350
- else { // PromptRole.user, PromptRole.assistant, PromptRole.safety
351
- const parts = [];
352
- // Text content handling
353
- if (msg.content) {
354
- parts.push({
355
- text: msg.content,
356
- });
357
- }
358
- // File content handling
359
- if (msg.files) {
360
- for (const f of msg.files) {
361
- const fileUrl = await f.getURL();
362
- const isGsUrl = fileUrl.startsWith('gs://') || fileUrl.startsWith('https://storage.googleapis.com/');
363
- if (isGsUrl) {
364
- parts.push({
365
- fileData: {
366
- fileUri: fileUrl,
367
- mimeType: f.mime_type
368
- }
369
- });
370
- }
371
- else {
372
- // Inline data handling
373
- const stream = await f.getStream();
374
- const data = await (0, core_1.readStreamAsBase64)(stream);
375
- parts.push({
376
- inlineData: {
377
- data,
378
- mimeType: f.mime_type
379
- }
380
- });
381
- }
382
- }
383
- }
384
- if (parts.length > 0) {
385
- if (msg.role === core_1.PromptRole.safety) {
386
- safety.push({
387
- role: 'user',
388
- parts,
389
- });
390
- }
391
- else {
392
- contents.push({
393
- role: msg.role === core_1.PromptRole.assistant ? 'model' : 'user',
394
- parts,
395
- });
396
- }
397
- }
398
- }
399
- }
400
- // Adding JSON Schema to system message
401
- if (schema) {
402
- if (supportsStructuredOutput(options) && !options.tools) {
403
- // Gemini structured output is unnecessarily sparse. Adding encouragement to fill the fields.
404
- // Putting JSON in prompt is not recommended by Google, when using structured output.
405
- system.parts?.push({ text: "Fill all appropriate fields in the JSON output." });
406
- }
407
- else {
408
- // Fallback to putting the schema in the system instructions, if not using structured output.
409
- if (options.tools) {
410
- system.parts?.push({
411
- text: "When not calling tools, the output must be a JSON object using the following JSON Schema:\n" + JSON.stringify(schema)
412
- });
413
- }
414
- else {
415
- system.parts?.push({ text: "The output must be a JSON object using the following JSON Schema:\n" + JSON.stringify(schema) });
416
- }
417
- }
418
- }
419
- // If no system messages, set system to undefined.
420
- if (!system.parts || system.parts.length === 0) {
421
- system = undefined;
422
- }
423
- // Add safety messages to the end of contents. They are in effect user messages that come at the end.
424
- if (safety.length > 0) {
425
- contents = contents.concat(safety);
426
- }
427
- // Merge consecutive messages with the same role. Note: this may not be necessary, works without it, keeping to match previous behavior.
428
- contents = mergeConsecutiveRole(contents);
429
- return { contents, system };
430
- }
431
- usageMetadataToTokenUsage(driver, usageMetadata) {
432
- if (!usageMetadata || !usageMetadata.totalTokenCount) {
433
- return {};
434
- }
435
- const tokenUsage = {
436
- total: usageMetadata.totalTokenCount,
437
- prompt: usageMetadata.promptTokenCount,
438
- prompt_cached: usageMetadata.cachedContentTokenCount ?? undefined,
439
- prompt_new: (usageMetadata.promptTokenCount ?? 0) - (usageMetadata.cachedContentTokenCount ?? 0),
440
- };
441
- //Output/Response side
442
- tokenUsage.result = (usageMetadata.candidatesTokenCount ?? 0)
443
- + (usageMetadata.thoughtsTokenCount ?? 0)
444
- + (usageMetadata.toolUsePromptTokenCount ?? 0);
445
- if ((tokenUsage.total ?? 0) !== (tokenUsage.prompt ?? 0) + tokenUsage.result) {
446
- // Token-accounting mismatch: warn-level diagnostic (the call still
447
- // returns the best-effort tokenUsage). Use the driver's structured
448
- // logger so we don't promote stderr writes to ERROR in serverless
449
- // log aggregators — see the recoverable-tool-call sites below.
450
- driver.logger.warn({ total: tokenUsage.total, prompt: tokenUsage.prompt, result: tokenUsage.result }, "[VertexAI] Gemini token usage mismatch: total does not equal prompt + result");
451
- }
452
- if (!tokenUsage.result) {
453
- tokenUsage.result = undefined; // If no result, mark as undefined
454
- }
455
- return tokenUsage;
456
- }
457
- async requestTextCompletion(driver, prompt, options) {
458
- const splits = options.model.split("/");
459
- let region = undefined;
460
- if (splits[0] === "locations" && splits.length >= 2) {
461
- region = splits[1];
462
- }
463
- const modelName = splits[splits.length - 1];
464
- options = { ...options, model: modelName };
465
- // Restore system instruction from stored conversation on resume.
466
- // The stored _llumiverse_system contains the complete system (interaction prompt + schema)
467
- // from the initial call. Always prefer it over the prompt's system, which on resume only
468
- // contains the schema instruction (no interaction system segments are present on resume).
469
- const existingSystem = extractSystemFromConversation(options.conversation);
470
- if (existingSystem) {
471
- prompt.system = existingSystem;
472
- }
473
- let conversation = updateConversation(options.conversation, prompt.contents);
474
- prompt.contents = conversation;
475
- // TODO: Remove hack, use global endpoint manually if needed.
476
- if (options.model.includes("gemini-2.5-flash-image")) {
477
- region = "global"; // Gemini Flash Image only available in global region, this is for nano-banana model
478
- }
479
- const model_options = options.model_options;
480
- const client = driver.getGoogleGenAIClient(region, model_options?.flex ?? false);
481
- const payload = getGeminiPayload(options, prompt);
482
- const response = await client.models.generateContent(payload);
483
- const token_usage = this.usageMetadataToTokenUsage(driver, response.usageMetadata);
484
- let tool_use;
485
- let finish_reason, result;
486
- const candidate = response.candidates && response.candidates[0];
487
- if (candidate) {
488
- switch (candidate.finishReason) {
489
- case genai_1.FinishReason.MAX_TOKENS:
490
- finish_reason = "length";
491
- break;
492
- case genai_1.FinishReason.STOP:
493
- finish_reason = "stop";
494
- break;
495
- default: finish_reason = candidate.finishReason;
496
- }
497
- const content = candidate.content;
498
- // Check for unsupported finish reasons, but allow recoverable tool call issues
499
- const isRecoverableToolCall = recoverableToolCallReasons.includes(candidate.finishReason);
500
- if (candidate.finishReason && !supportedFinishReasons.includes(candidate.finishReason) && !isRecoverableToolCall) {
501
- throw new Error(`Unsupported finish reason: ${candidate.finishReason}, `
502
- + `finish message: ${candidate.finishMessage}, `
503
- + `content: ${JSON.stringify(content, null, 2)}, safety: ${JSON.stringify(candidate.safetyRatings, null, 2)}`);
504
- }
505
- if (content) {
506
- tool_use = collectToolUseParts(content);
507
- // For recoverable tool call issues, log warning but continue processing
508
- // The workflow will handle the invalid tool call gracefully.
509
- // Route through the driver's structured logger instead of `console.warn`
510
- // so downstream runtimes (e.g. Cloud Run) don't promote stderr writes
511
- // to ERROR severity for what is, by definition, a recoverable event.
512
- if (isRecoverableToolCall && tool_use && tool_use.length > 0) {
513
- driver.logger.warn(`[Gemini] Recoverable tool call issue (${candidate.finishReason}): ` +
514
- `Model tried to call undeclared tool(s): ${tool_use.map(t => t.tool_name).join(', ')}`);
515
- }
516
- result = extractCompletionResults(content);
517
- conversation = updateConversation(conversation, [content]);
518
- }
519
- }
520
- if (tool_use) {
521
- finish_reason = "tool_use";
522
- }
523
- // Increment turn counter for deferred stripping
524
- conversation = (0, core_1.incrementConversationTurn)(conversation);
525
- // Strip large base64 image data based on options.stripImagesAfterTurns
526
- const currentTurn = (0, core_1.getConversationMeta)(conversation).turnNumber;
527
- const stripOptions = {
528
- keepForTurns: options.stripImagesAfterTurns ?? Infinity,
529
- currentTurn,
530
- textMaxTokens: options.stripTextMaxTokens
531
- };
532
- let processedConversation = (0, core_1.stripBase64ImagesFromConversation)(conversation, stripOptions);
533
- // Truncate large text content if configured
534
- processedConversation = (0, core_1.truncateLargeTextInConversation)(processedConversation, stripOptions);
535
- // Strip old heartbeat status messages
536
- processedConversation = (0, core_1.stripHeartbeatsFromConversation)(processedConversation, {
537
- keepForTurns: options.stripHeartbeatsAfterTurns ?? 1,
538
- currentTurn,
539
- });
540
- // Preserve system instruction in conversation for multi-turn support
541
- const finalConversation = storeSystemInConversation(processedConversation, prompt.system);
542
- return {
543
- result: result && result.length > 0 ? result : [{ type: "text", value: '' }],
544
- token_usage: token_usage,
545
- finish_reason: finish_reason,
546
- original_response: options.include_original_response ? response : undefined,
547
- conversation: finalConversation,
548
- tool_use
549
- };
550
- }
551
- async requestTextCompletionStream(driver, prompt, options) {
552
- const splits = options.model.split("/");
553
- let region = undefined;
554
- if (splits[0] === "locations" && splits.length >= 2) {
555
- region = splits[1];
556
- }
557
- const modelName = splits[splits.length - 1];
558
- options = { ...options, model: modelName };
559
- // Restore system instruction from stored conversation on resume.
560
- // The stored _llumiverse_system contains the complete system (interaction prompt + schema)
561
- // from the initial call. Always prefer it over the prompt's system, which on resume only
562
- // contains the schema instruction (no interaction system segments are present on resume).
563
- const existingSystem = extractSystemFromConversation(options.conversation);
564
- if (existingSystem) {
565
- prompt.system = existingSystem;
566
- }
567
- // Include conversation history in prompt contents (same as non-streaming)
568
- const conversation = updateConversation(options.conversation, prompt.contents);
569
- prompt.contents = conversation;
570
- if (options.model.includes("gemini-2.5-flash-image")) {
571
- region = "global"; // Gemini Flash Image only available in global region, this is for nano-banana model
572
- }
573
- const model_options = options.model_options;
574
- const client = driver.getGoogleGenAIClient(region, model_options?.flex ?? false);
575
- const payload = getGeminiPayload(options, prompt);
576
- const response = await client.models.generateContentStream(payload);
577
- const stream = (0, async_1.asyncMap)(response, async (item) => {
578
- const token_usage = this.usageMetadataToTokenUsage(driver, item.usageMetadata);
579
- if (item.candidates && item.candidates.length > 0) {
580
- for (const candidate of item.candidates) {
581
- let tool_use;
582
- let finish_reason;
583
- switch (candidate.finishReason) {
584
- case genai_1.FinishReason.MAX_TOKENS:
585
- finish_reason = "length";
586
- break;
587
- case genai_1.FinishReason.STOP:
588
- finish_reason = "stop";
589
- break;
590
- default: finish_reason = candidate.finishReason;
591
- }
592
- // Check for unsupported finish reasons, but allow recoverable tool call issues
593
- const isRecoverableToolCall = recoverableToolCallReasons.includes(candidate.finishReason);
594
- if (candidate.finishReason && !supportedFinishReasons.includes(candidate.finishReason) && !isRecoverableToolCall) {
595
- throw new Error(`Unsupported finish reason: ${candidate.finishReason}, `
596
- + `finish message: ${candidate.finishMessage}, `
597
- + `content: ${JSON.stringify(candidate.content, null, 2)}, safety: ${JSON.stringify(candidate.safetyRatings, null, 2)}`);
598
- }
599
- if (candidate.content?.role === 'model') {
600
- // Collect all parts in order (text and images)
601
- const combinedResults = extractCompletionResults(candidate.content);
602
- tool_use = collectToolUseParts(candidate.content);
603
- if (tool_use) {
604
- finish_reason = "tool_use";
605
- // Log warning for recoverable tool call issues — see the
606
- // matching site in `requestTextCompletion` above for why
607
- // we route through the driver's logger instead of
608
- // `console.warn`.
609
- if (isRecoverableToolCall) {
610
- driver.logger.warn(`[Gemini] Recoverable tool call issue (${candidate.finishReason}): ` +
611
- `Model tried to call undeclared tool(s): ${tool_use.map(t => t.tool_name).join(', ')}`);
612
- }
613
- }
614
- return {
615
- result: combinedResults.length > 0 ? combinedResults : [],
616
- token_usage: token_usage,
617
- finish_reason: finish_reason,
618
- tool_use,
619
- };
620
- }
621
- }
622
- }
623
- //No normal output, returning block reason if it exists.
624
- return {
625
- result: item.promptFeedback?.blockReasonMessage ? [{ type: "text", value: item.promptFeedback.blockReasonMessage }] : [],
626
- finish_reason: item.promptFeedback?.blockReason ?? "",
627
- token_usage: token_usage,
628
- };
629
- });
630
- return stream;
631
- }
632
- /**
633
- * Format Google API errors into LlumiverseError with proper status codes and retryability.
634
- *
635
- * Google API errors follow AIP-193 standard:
636
- * - ApiError.status: HTTP status code
637
- * - ApiError.message: Error message
638
- *
639
- * Common error codes:
640
- * - 400 (INVALID_ARGUMENT): Invalid request parameters
641
- * - 401 (UNAUTHENTICATED): Authentication required
642
- * - 403 (PERMISSION_DENIED): Insufficient permissions
643
- * - 404 (NOT_FOUND): Resource not found
644
- * - 429 (RESOURCE_EXHAUSTED): Rate limit/quota exceeded
645
- * - 500 (INTERNAL): Internal server error
646
- * - 503 (UNAVAILABLE): Service temporarily unavailable
647
- * - 504 (DEADLINE_EXCEEDED): Request timeout
648
- *
649
- * @see https://google.aip.dev/193
650
- * @see https://docs.cloud.google.com/vertex-ai/generative-ai/docs/model-reference/api-errors
651
- */
652
- formatLlumiverseError(_driver, error, context) {
653
- // Check if it's a Google API error with status code
654
- const isApiError = this.isGoogleApiError(error);
655
- if (!isApiError) {
656
- // Not a Google API error, use default handling
657
- // This will be called by the driver's default formatLlumiverseError
658
- throw error;
659
- }
660
- const apiError = error;
661
- const httpStatusCode = apiError.status;
662
- // Extract error message
663
- const message = apiError.message || String(error);
664
- // Build user-facing message with status code
665
- let userMessage = message;
666
- // Include status code in message (for end-user visibility)
667
- if (httpStatusCode) {
668
- userMessage = `[${httpStatusCode}] ${userMessage}`;
669
- }
670
- // Determine retryability based on Google error codes
671
- const retryable = this.isGeminiErrorRetryable(httpStatusCode);
672
- // Extract error name/type from message if present
673
- const errorName = this.extractErrorName(message);
674
- return new core_1.LlumiverseError(`[${context.provider}] ${userMessage}`, retryable, context, error, httpStatusCode, errorName);
675
- }
676
- /**
677
- * Type guard to check if error is a Google API error.
678
- */
679
- isGoogleApiError(error) {
680
- return (error !== null &&
681
- typeof error === 'object' &&
682
- 'status' in error &&
683
- typeof error.status === 'number' &&
684
- 'message' in error);
685
- }
686
- /**
687
- * Determine if a Google API error is retryable based on HTTP status code.
688
- *
689
- * Retryable errors (per Google AIP-194):
690
- * - 408 (REQUEST_TIMEOUT): Request timeout
691
- * - 429 (RESOURCE_EXHAUSTED): Rate limit exceeded, quota exhausted
692
- * - 500 (INTERNAL): Internal server error
693
- * - 502 (BAD_GATEWAY): Bad gateway
694
- * - 503 (UNAVAILABLE): Service temporarily unavailable
695
- * - 504 (DEADLINE_EXCEEDED): Gateway timeout
696
- *
697
- * Non-retryable errors:
698
- * - 400 (INVALID_ARGUMENT): Invalid request parameters
699
- * - 401 (UNAUTHENTICATED): Authentication required
700
- * - 403 (PERMISSION_DENIED): Insufficient permissions
701
- * - 404 (NOT_FOUND): Resource not found
702
- * - 409 (CONFLICT): Resource conflict
703
- * - Other 4xx client errors
704
- *
705
- * @param httpStatusCode - The HTTP status code from the API error
706
- * @returns True if retryable, false if not retryable, undefined if unknown
707
- */
708
- isGeminiErrorRetryable(httpStatusCode) {
709
- // Retryable status codes
710
- if (httpStatusCode === 408)
711
- return true; // Request timeout
712
- if (httpStatusCode === 429)
713
- return true; // Rate limit/quota
714
- if (httpStatusCode === 502)
715
- return true; // Bad gateway
716
- if (httpStatusCode === 503)
717
- return true; // Service unavailable
718
- if (httpStatusCode === 504)
719
- return true; // Gateway timeout
720
- if (httpStatusCode >= 500 && httpStatusCode < 600)
721
- return true; // Other 5xx server errors
722
- // Non-retryable 4xx client errors
723
- if (httpStatusCode >= 400 && httpStatusCode < 500)
724
- return false;
725
- // Unknown status codes - let consumer decide retry strategy
726
- return undefined;
727
- }
728
- /**
729
- * Extract error type name from error message.
730
- * Google errors often include the error type in the message.
731
- * Examples: "INVALID_ARGUMENT", "RESOURCE_EXHAUSTED", "PERMISSION_DENIED"
732
- */
733
- extractErrorName(message) {
734
- // Common Google error patterns
735
- const patterns = [
736
- /^([A-Z_]+):/, // "ERROR_NAME: message"
737
- /\[([A-Z_]+)\]/, // "[ERROR_NAME] message"
738
- /^(\w+Error):/, // "ErrorTypeError: message"
739
- ];
740
- for (const pattern of patterns) {
741
- const match = message.match(pattern);
742
- if (match) {
743
- return match[1];
744
- }
745
- }
746
- return undefined;
747
- }
748
- }
749
- exports.GeminiModelDefinition = GeminiModelDefinition;
750
- /**
751
- * Converts functionCall and functionResponse parts to text parts in Gemini Content[].
752
- * Preserves tool call information while removing structured parts that require
753
- * tools/toolConfig to be defined in the API request.
754
- */
755
- function convertGeminiFunctionPartsToText(contents) {
756
- return contents.map(content => {
757
- if (!content.parts)
758
- return content;
759
- const hasFunctionParts = content.parts.some(p => p.functionCall || p.functionResponse);
760
- if (!hasFunctionParts)
761
- return content;
762
- const newParts = content.parts.map(part => {
763
- if (part.functionCall) {
764
- const argsStr = part.functionCall.args ? JSON.stringify(part.functionCall.args) : '';
765
- const truncated = argsStr.length > 500 ? argsStr.substring(0, 500) + '...' : argsStr;
766
- return { text: `[Tool call: ${part.functionCall.name}(${truncated})]` };
767
- }
768
- if (part.functionResponse) {
769
- const respStr = part.functionResponse.response
770
- ? JSON.stringify(part.functionResponse.response) : 'No response';
771
- const truncated = respStr.length > 500 ? respStr.substring(0, 500) + '...' : respStr;
772
- return { text: `[Tool result for ${part.functionResponse.name}: ${truncated}]` };
773
- }
774
- return part;
775
- });
776
- return { ...content, parts: newParts };
777
- });
778
- }
779
- function getToolDefinitions(tools) {
780
- if (!tools || tools.length === 0) {
781
- return undefined;
782
- }
783
- // VertexAI Gemini only supports one tool at a time.
784
- // For multiple tools, we have multiple functions in one tool.
785
- return {
786
- functionDeclarations: tools.map(getToolFunction),
787
- };
788
- }
789
- function getToolFunction(tool) {
790
- return {
791
- name: tool.name,
792
- description: tool.description,
793
- // Pass the input_schema directly as a JSON Schema object.
794
- // parametersJsonSchema accepts standard JSON Schema and is mutually exclusive
795
- // with the legacy parameters field (which required a proprietary Gemini Schema type).
796
- parametersJsonSchema: tool.input_schema,
797
- };
798
- }
799
- /**
800
- * Update the conversation messages
801
- * @param prompt
802
- * @param response
803
- * @returns
804
- */
805
- function updateConversation(conversation, prompt) {
806
- // Unwrap array if wrapped, otherwise treat as array
807
- const unwrapped = (0, core_1.unwrapConversationArray)(conversation);
808
- const convArray = unwrapped ?? (conversation || []);
809
- return convArray.concat(prompt);
810
- }
811
- const SYSTEM_KEY = '_llumiverse_system';
812
- /**
813
- * Extract the stored system instruction from a Gemini conversation object.
814
- * Returns undefined if no system was stored.
815
- */
816
- function extractSystemFromConversation(conversation) {
817
- if (typeof conversation === 'object' && conversation !== null) {
818
- const c = conversation;
819
- if (c[SYSTEM_KEY] && typeof c[SYSTEM_KEY] === 'object') {
820
- return c[SYSTEM_KEY];
821
- }
822
- }
823
- return undefined;
824
- }
825
- /**
826
- * Store the system instruction in the Gemini conversation wrapper object.
827
- * The conversation is already wrapped by incrementConversationTurn into
828
- * { _arrayConversation: Content[], _llumiverse_meta: {...} }.
829
- * We add _llumiverse_system alongside these fields.
830
- */
831
- function storeSystemInConversation(conversation, system) {
832
- if (!system)
833
- return conversation;
834
- if (typeof conversation === 'object' && conversation !== null) {
835
- return { ...conversation, [SYSTEM_KEY]: system };
836
- }
837
- return conversation;
838
- }
839
- /**
840
- *
841
- * Gemini supports JSON output in the response. so we test if the response is a valid JSON object. otherwise we treat the response as a string.
842
- *
843
- * This is an excerpt from googleapis.github.io/python-genai:
844
- *
845
- * The function response in JSON object format.
846
- * Use “output” key to specify function output and “error” key to specify error details (if any).
847
- * If “output” and “error” keys are not specified, then whole “response” is treated as function output.
848
- * @see https://googleapis.github.io/python-genai/genai.html#genai.types.FunctionResponse
849
- */
850
- function formatFunctionResponse(response) {
851
- response = response.trim();
852
- if (response.startsWith("{") && response.endsWith("}")) {
853
- try {
854
- return JSON.parse(response);
855
- }
856
- catch (e) {
857
- return { output: response };
858
- }
859
- }
860
- else {
861
- return { output: response };
862
- }
863
- }
864
- //# sourceMappingURL=gemini.js.map