@llumiverse/drivers 1.2.0 → 1.4.0-dev.20260629.090753Z

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 (403) 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/anthropic/index.d.ts +23 -0
  6. package/lib/anthropic/index.d.ts.map +1 -0
  7. package/lib/anthropic/index.js +68 -0
  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 +17 -5
  68. package/lib/openai/index.d.ts.map +1 -0
  69. package/lib/{esm/openai → openai}/index.js +254 -148
  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/shared/claude-messages.d.ts +99 -0
  88. package/lib/shared/claude-messages.d.ts.map +1 -0
  89. package/lib/shared/claude-messages.js +869 -0
  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/vertexai/models/claude.d.ts +16 -0
  143. package/lib/vertexai/models/claude.d.ts.map +1 -0
  144. package/lib/vertexai/models/claude.js +65 -0
  145. package/lib/vertexai/models/claude.js.map +1 -0
  146. package/lib/{types/vertexai → vertexai}/models/gemini.d.ts +29 -5
  147. package/lib/vertexai/models/gemini.d.ts.map +1 -0
  148. package/lib/{esm/vertexai → vertexai}/models/gemini.js +255 -127
  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 +88 -36
  173. package/src/adobe/firefly.ts +60 -43
  174. package/src/anthropic/index.ts +121 -0
  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 -15
  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 +389 -254
  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 +1085 -0
  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 +339 -253
  219. package/src/vertexai/models/claude-error-handling.test.ts +86 -39
  220. package/src/vertexai/models/claude-streaming-spacing.test.ts +82 -75
  221. package/src/vertexai/models/claude.ts +84 -1041
  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 +372 -182
  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/azure/azure_foundry.js +0 -432
  235. package/lib/cjs/azure/azure_foundry.js.map +0 -1
  236. package/lib/cjs/bedrock/converse.js +0 -359
  237. package/lib/cjs/bedrock/converse.js.map +0 -1
  238. package/lib/cjs/bedrock/index.js +0 -1508
  239. package/lib/cjs/bedrock/index.js.map +0 -1
  240. package/lib/cjs/bedrock/nova-image-payload.js +0 -207
  241. package/lib/cjs/bedrock/nova-image-payload.js.map +0 -1
  242. package/lib/cjs/bedrock/payloads.js +0 -3
  243. package/lib/cjs/bedrock/s3.js +0 -107
  244. package/lib/cjs/bedrock/s3.js.map +0 -1
  245. package/lib/cjs/bedrock/twelvelabs.js +0 -87
  246. package/lib/cjs/bedrock/twelvelabs.js.map +0 -1
  247. package/lib/cjs/groq/index.js +0 -328
  248. package/lib/cjs/groq/index.js.map +0 -1
  249. package/lib/cjs/huggingface_ie.js +0 -201
  250. package/lib/cjs/huggingface_ie.js.map +0 -1
  251. package/lib/cjs/index.js +0 -31
  252. package/lib/cjs/index.js.map +0 -1
  253. package/lib/cjs/mistral/index.js +0 -176
  254. package/lib/cjs/mistral/index.js.map +0 -1
  255. package/lib/cjs/mistral/types.js +0 -83
  256. package/lib/cjs/mistral/types.js.map +0 -1
  257. package/lib/cjs/openai/azure_openai.js +0 -72
  258. package/lib/cjs/openai/azure_openai.js.map +0 -1
  259. package/lib/cjs/openai/index.js +0 -1129
  260. package/lib/cjs/openai/index.js.map +0 -1
  261. package/lib/cjs/openai/openai.js +0 -21
  262. package/lib/cjs/openai/openai.js.map +0 -1
  263. package/lib/cjs/openai/openai_compatible.js +0 -63
  264. package/lib/cjs/openai/openai_compatible.js.map +0 -1
  265. package/lib/cjs/openai/openai_format.js +0 -131
  266. package/lib/cjs/openai/openai_format.js.map +0 -1
  267. package/lib/cjs/package.json +0 -3
  268. package/lib/cjs/replicate.js +0 -275
  269. package/lib/cjs/replicate.js.map +0 -1
  270. package/lib/cjs/shared/claude-thinking.js +0 -60
  271. package/lib/cjs/shared/claude-thinking.js.map +0 -1
  272. package/lib/cjs/test-driver/TestErrorCompletionStream.js +0 -20
  273. package/lib/cjs/test-driver/TestErrorCompletionStream.js.map +0 -1
  274. package/lib/cjs/test-driver/TestValidationErrorCompletionStream.js +0 -24
  275. package/lib/cjs/test-driver/TestValidationErrorCompletionStream.js.map +0 -1
  276. package/lib/cjs/test-driver/index.js +0 -109
  277. package/lib/cjs/test-driver/index.js.map +0 -1
  278. package/lib/cjs/test-driver/utils.js +0 -30
  279. package/lib/cjs/test-driver/utils.js.map +0 -1
  280. package/lib/cjs/togetherai/index.js +0 -126
  281. package/lib/cjs/togetherai/index.js.map +0 -1
  282. package/lib/cjs/togetherai/interfaces.js +0 -3
  283. package/lib/cjs/togetherai/interfaces.js.map +0 -1
  284. package/lib/cjs/vertexai/debug.js +0 -12
  285. package/lib/cjs/vertexai/debug.js.map +0 -1
  286. package/lib/cjs/vertexai/embeddings/embeddings-image.js +0 -27
  287. package/lib/cjs/vertexai/embeddings/embeddings-image.js.map +0 -1
  288. package/lib/cjs/vertexai/embeddings/embeddings-text.js +0 -23
  289. package/lib/cjs/vertexai/embeddings/embeddings-text.js.map +0 -1
  290. package/lib/cjs/vertexai/index.js +0 -644
  291. package/lib/cjs/vertexai/index.js.map +0 -1
  292. package/lib/cjs/vertexai/models/claude.js +0 -917
  293. package/lib/cjs/vertexai/models/claude.js.map +0 -1
  294. package/lib/cjs/vertexai/models/gemini.js +0 -858
  295. package/lib/cjs/vertexai/models/gemini.js.map +0 -1
  296. package/lib/cjs/vertexai/models/imagen.js +0 -303
  297. package/lib/cjs/vertexai/models/imagen.js.map +0 -1
  298. package/lib/cjs/vertexai/models/llama.js +0 -183
  299. package/lib/cjs/vertexai/models/llama.js.map +0 -1
  300. package/lib/cjs/vertexai/models.js +0 -35
  301. package/lib/cjs/vertexai/models.js.map +0 -1
  302. package/lib/cjs/watsonx/index.js +0 -161
  303. package/lib/cjs/watsonx/index.js.map +0 -1
  304. package/lib/cjs/watsonx/interfaces.js +0 -3
  305. package/lib/cjs/xai/index.js +0 -65
  306. package/lib/cjs/xai/index.js.map +0 -1
  307. package/lib/esm/adobe/firefly.js +0 -116
  308. package/lib/esm/adobe/firefly.js.map +0 -1
  309. package/lib/esm/azure/azure_foundry.js.map +0 -1
  310. package/lib/esm/bedrock/converse.js.map +0 -1
  311. package/lib/esm/bedrock/index.js.map +0 -1
  312. package/lib/esm/bedrock/nova-image-payload.js.map +0 -1
  313. package/lib/esm/bedrock/payloads.js.map +0 -1
  314. package/lib/esm/bedrock/s3.js.map +0 -1
  315. package/lib/esm/bedrock/twelvelabs.js.map +0 -1
  316. package/lib/esm/groq/index.js.map +0 -1
  317. package/lib/esm/huggingface_ie.js.map +0 -1
  318. package/lib/esm/index.js +0 -15
  319. package/lib/esm/index.js.map +0 -1
  320. package/lib/esm/mistral/index.js.map +0 -1
  321. package/lib/esm/mistral/types.js.map +0 -1
  322. package/lib/esm/openai/azure_openai.js.map +0 -1
  323. package/lib/esm/openai/index.js.map +0 -1
  324. package/lib/esm/openai/openai.js +0 -14
  325. package/lib/esm/openai/openai.js.map +0 -1
  326. package/lib/esm/openai/openai_compatible.js.map +0 -1
  327. package/lib/esm/openai/openai_format.js.map +0 -1
  328. package/lib/esm/replicate.js.map +0 -1
  329. package/lib/esm/shared/claude-thinking.js.map +0 -1
  330. package/lib/esm/test-driver/TestErrorCompletionStream.js +0 -16
  331. package/lib/esm/test-driver/TestErrorCompletionStream.js.map +0 -1
  332. package/lib/esm/test-driver/TestValidationErrorCompletionStream.js.map +0 -1
  333. package/lib/esm/test-driver/index.js.map +0 -1
  334. package/lib/esm/test-driver/utils.js.map +0 -1
  335. package/lib/esm/togetherai/index.js +0 -122
  336. package/lib/esm/togetherai/index.js.map +0 -1
  337. package/lib/esm/togetherai/interfaces.js.map +0 -1
  338. package/lib/esm/vertexai/debug.js.map +0 -1
  339. package/lib/esm/vertexai/embeddings/embeddings-image.js +0 -24
  340. package/lib/esm/vertexai/embeddings/embeddings-image.js.map +0 -1
  341. package/lib/esm/vertexai/embeddings/embeddings-text.js +0 -20
  342. package/lib/esm/vertexai/embeddings/embeddings-text.js.map +0 -1
  343. package/lib/esm/vertexai/index.js.map +0 -1
  344. package/lib/esm/vertexai/models/claude.js +0 -906
  345. package/lib/esm/vertexai/models/claude.js.map +0 -1
  346. package/lib/esm/vertexai/models/gemini.js.map +0 -1
  347. package/lib/esm/vertexai/models/imagen.js.map +0 -1
  348. package/lib/esm/vertexai/models/llama.js.map +0 -1
  349. package/lib/esm/vertexai/models.js.map +0 -1
  350. package/lib/esm/watsonx/index.js.map +0 -1
  351. package/lib/esm/xai/index.js.map +0 -1
  352. package/lib/types/adobe/firefly.d.ts.map +0 -1
  353. package/lib/types/azure/azure_foundry.d.ts.map +0 -1
  354. package/lib/types/bedrock/converse.d.ts.map +0 -1
  355. package/lib/types/bedrock/index.d.ts.map +0 -1
  356. package/lib/types/bedrock/nova-image-payload.d.ts.map +0 -1
  357. package/lib/types/bedrock/payloads.d.ts.map +0 -1
  358. package/lib/types/bedrock/s3.d.ts.map +0 -1
  359. package/lib/types/bedrock/twelvelabs.d.ts.map +0 -1
  360. package/lib/types/groq/index.d.ts.map +0 -1
  361. package/lib/types/huggingface_ie.d.ts.map +0 -1
  362. package/lib/types/index.d.ts +0 -15
  363. package/lib/types/index.d.ts.map +0 -1
  364. package/lib/types/mistral/index.d.ts.map +0 -1
  365. package/lib/types/mistral/types.d.ts.map +0 -1
  366. package/lib/types/openai/azure_openai.d.ts.map +0 -1
  367. package/lib/types/openai/index.d.ts.map +0 -1
  368. package/lib/types/openai/openai.d.ts.map +0 -1
  369. package/lib/types/openai/openai_compatible.d.ts.map +0 -1
  370. package/lib/types/openai/openai_format.d.ts.map +0 -1
  371. package/lib/types/replicate.d.ts.map +0 -1
  372. package/lib/types/shared/claude-thinking.d.ts.map +0 -1
  373. package/lib/types/test-driver/TestErrorCompletionStream.d.ts.map +0 -1
  374. package/lib/types/test-driver/TestValidationErrorCompletionStream.d.ts.map +0 -1
  375. package/lib/types/test-driver/index.d.ts.map +0 -1
  376. package/lib/types/test-driver/utils.d.ts.map +0 -1
  377. package/lib/types/togetherai/index.d.ts +0 -23
  378. package/lib/types/togetherai/index.d.ts.map +0 -1
  379. package/lib/types/togetherai/interfaces.d.ts.map +0 -1
  380. package/lib/types/vertexai/debug.d.ts +0 -2
  381. package/lib/types/vertexai/debug.d.ts.map +0 -1
  382. package/lib/types/vertexai/embeddings/embeddings-image.d.ts +0 -11
  383. package/lib/types/vertexai/embeddings/embeddings-image.d.ts.map +0 -1
  384. package/lib/types/vertexai/embeddings/embeddings-text.d.ts +0 -10
  385. package/lib/types/vertexai/embeddings/embeddings-text.d.ts.map +0 -1
  386. package/lib/types/vertexai/index.d.ts.map +0 -1
  387. package/lib/types/vertexai/models/claude.d.ts +0 -119
  388. package/lib/types/vertexai/models/claude.d.ts.map +0 -1
  389. package/lib/types/vertexai/models/gemini.d.ts.map +0 -1
  390. package/lib/types/vertexai/models/imagen.d.ts.map +0 -1
  391. package/lib/types/vertexai/models/llama.d.ts.map +0 -1
  392. package/lib/types/vertexai/models.d.ts +0 -20
  393. package/lib/types/vertexai/models.d.ts.map +0 -1
  394. package/lib/types/watsonx/index.d.ts.map +0 -1
  395. package/lib/types/watsonx/interfaces.d.ts.map +0 -1
  396. package/lib/types/xai/index.d.ts.map +0 -1
  397. package/src/vertexai/embeddings/embeddings-image.ts +0 -52
  398. package/src/vertexai/embeddings/embeddings-text.ts +0 -54
  399. /package/lib/{esm/bedrock → bedrock}/payloads.js +0 -0
  400. /package/lib/{esm/mistral → mistral}/types.js +0 -0
  401. /package/lib/{esm/togetherai → togetherai}/interfaces.js +0 -0
  402. /package/lib/{types/watsonx → watsonx}/interfaces.d.ts +0 -0
  403. /package/lib/{esm/watsonx → watsonx}/interfaces.js +0 -0
@@ -1,858 +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(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
- console.warn("[VertexAI] Gemini token usage mismatch: total does not equal prompt + result", {
447
- total: tokenUsage.total,
448
- prompt: tokenUsage.prompt,
449
- result: tokenUsage.result
450
- });
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(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
- if (isRecoverableToolCall && tool_use && tool_use.length > 0) {
510
- console.warn(`[Gemini] Recoverable tool call issue (${candidate.finishReason}): ` +
511
- `Model tried to call undeclared tool(s): ${tool_use.map(t => t.tool_name).join(', ')}`);
512
- }
513
- result = extractCompletionResults(content);
514
- conversation = updateConversation(conversation, [content]);
515
- }
516
- }
517
- if (tool_use) {
518
- finish_reason = "tool_use";
519
- }
520
- // Increment turn counter for deferred stripping
521
- conversation = (0, core_1.incrementConversationTurn)(conversation);
522
- // Strip large base64 image data based on options.stripImagesAfterTurns
523
- const currentTurn = (0, core_1.getConversationMeta)(conversation).turnNumber;
524
- const stripOptions = {
525
- keepForTurns: options.stripImagesAfterTurns ?? Infinity,
526
- currentTurn,
527
- textMaxTokens: options.stripTextMaxTokens
528
- };
529
- let processedConversation = (0, core_1.stripBase64ImagesFromConversation)(conversation, stripOptions);
530
- // Truncate large text content if configured
531
- processedConversation = (0, core_1.truncateLargeTextInConversation)(processedConversation, stripOptions);
532
- // Strip old heartbeat status messages
533
- processedConversation = (0, core_1.stripHeartbeatsFromConversation)(processedConversation, {
534
- keepForTurns: options.stripHeartbeatsAfterTurns ?? 1,
535
- currentTurn,
536
- });
537
- // Preserve system instruction in conversation for multi-turn support
538
- const finalConversation = storeSystemInConversation(processedConversation, prompt.system);
539
- return {
540
- result: result && result.length > 0 ? result : [{ type: "text", value: '' }],
541
- token_usage: token_usage,
542
- finish_reason: finish_reason,
543
- original_response: options.include_original_response ? response : undefined,
544
- conversation: finalConversation,
545
- tool_use
546
- };
547
- }
548
- async requestTextCompletionStream(driver, prompt, options) {
549
- const splits = options.model.split("/");
550
- let region = undefined;
551
- if (splits[0] === "locations" && splits.length >= 2) {
552
- region = splits[1];
553
- }
554
- const modelName = splits[splits.length - 1];
555
- options = { ...options, model: modelName };
556
- // Restore system instruction from stored conversation on resume.
557
- // The stored _llumiverse_system contains the complete system (interaction prompt + schema)
558
- // from the initial call. Always prefer it over the prompt's system, which on resume only
559
- // contains the schema instruction (no interaction system segments are present on resume).
560
- const existingSystem = extractSystemFromConversation(options.conversation);
561
- if (existingSystem) {
562
- prompt.system = existingSystem;
563
- }
564
- // Include conversation history in prompt contents (same as non-streaming)
565
- const conversation = updateConversation(options.conversation, prompt.contents);
566
- prompt.contents = conversation;
567
- if (options.model.includes("gemini-2.5-flash-image")) {
568
- region = "global"; // Gemini Flash Image only available in global region, this is for nano-banana model
569
- }
570
- const model_options = options.model_options;
571
- const client = driver.getGoogleGenAIClient(region, model_options?.flex ?? false);
572
- const payload = getGeminiPayload(options, prompt);
573
- const response = await client.models.generateContentStream(payload);
574
- const stream = (0, async_1.asyncMap)(response, async (item) => {
575
- const token_usage = this.usageMetadataToTokenUsage(item.usageMetadata);
576
- if (item.candidates && item.candidates.length > 0) {
577
- for (const candidate of item.candidates) {
578
- let tool_use;
579
- let finish_reason;
580
- switch (candidate.finishReason) {
581
- case genai_1.FinishReason.MAX_TOKENS:
582
- finish_reason = "length";
583
- break;
584
- case genai_1.FinishReason.STOP:
585
- finish_reason = "stop";
586
- break;
587
- default: finish_reason = candidate.finishReason;
588
- }
589
- // Check for unsupported finish reasons, but allow recoverable tool call issues
590
- const isRecoverableToolCall = recoverableToolCallReasons.includes(candidate.finishReason);
591
- if (candidate.finishReason && !supportedFinishReasons.includes(candidate.finishReason) && !isRecoverableToolCall) {
592
- throw new Error(`Unsupported finish reason: ${candidate.finishReason}, `
593
- + `finish message: ${candidate.finishMessage}, `
594
- + `content: ${JSON.stringify(candidate.content, null, 2)}, safety: ${JSON.stringify(candidate.safetyRatings, null, 2)}`);
595
- }
596
- if (candidate.content?.role === 'model') {
597
- // Collect all parts in order (text and images)
598
- const combinedResults = extractCompletionResults(candidate.content);
599
- tool_use = collectToolUseParts(candidate.content);
600
- if (tool_use) {
601
- finish_reason = "tool_use";
602
- // Log warning for recoverable tool call issues
603
- if (isRecoverableToolCall) {
604
- console.warn(`[Gemini] Recoverable tool call issue (${candidate.finishReason}): ` +
605
- `Model tried to call undeclared tool(s): ${tool_use.map(t => t.tool_name).join(', ')}`);
606
- }
607
- }
608
- return {
609
- result: combinedResults.length > 0 ? combinedResults : [],
610
- token_usage: token_usage,
611
- finish_reason: finish_reason,
612
- tool_use,
613
- };
614
- }
615
- }
616
- }
617
- //No normal output, returning block reason if it exists.
618
- return {
619
- result: item.promptFeedback?.blockReasonMessage ? [{ type: "text", value: item.promptFeedback.blockReasonMessage }] : [],
620
- finish_reason: item.promptFeedback?.blockReason ?? "",
621
- token_usage: token_usage,
622
- };
623
- });
624
- return stream;
625
- }
626
- /**
627
- * Format Google API errors into LlumiverseError with proper status codes and retryability.
628
- *
629
- * Google API errors follow AIP-193 standard:
630
- * - ApiError.status: HTTP status code
631
- * - ApiError.message: Error message
632
- *
633
- * Common error codes:
634
- * - 400 (INVALID_ARGUMENT): Invalid request parameters
635
- * - 401 (UNAUTHENTICATED): Authentication required
636
- * - 403 (PERMISSION_DENIED): Insufficient permissions
637
- * - 404 (NOT_FOUND): Resource not found
638
- * - 429 (RESOURCE_EXHAUSTED): Rate limit/quota exceeded
639
- * - 500 (INTERNAL): Internal server error
640
- * - 503 (UNAVAILABLE): Service temporarily unavailable
641
- * - 504 (DEADLINE_EXCEEDED): Request timeout
642
- *
643
- * @see https://google.aip.dev/193
644
- * @see https://docs.cloud.google.com/vertex-ai/generative-ai/docs/model-reference/api-errors
645
- */
646
- formatLlumiverseError(_driver, error, context) {
647
- // Check if it's a Google API error with status code
648
- const isApiError = this.isGoogleApiError(error);
649
- if (!isApiError) {
650
- // Not a Google API error, use default handling
651
- // This will be called by the driver's default formatLlumiverseError
652
- throw error;
653
- }
654
- const apiError = error;
655
- const httpStatusCode = apiError.status;
656
- // Extract error message
657
- const message = apiError.message || String(error);
658
- // Build user-facing message with status code
659
- let userMessage = message;
660
- // Include status code in message (for end-user visibility)
661
- if (httpStatusCode) {
662
- userMessage = `[${httpStatusCode}] ${userMessage}`;
663
- }
664
- // Determine retryability based on Google error codes
665
- const retryable = this.isGeminiErrorRetryable(httpStatusCode);
666
- // Extract error name/type from message if present
667
- const errorName = this.extractErrorName(message);
668
- return new core_1.LlumiverseError(`[${context.provider}] ${userMessage}`, retryable, context, error, httpStatusCode, errorName);
669
- }
670
- /**
671
- * Type guard to check if error is a Google API error.
672
- */
673
- isGoogleApiError(error) {
674
- return (error !== null &&
675
- typeof error === 'object' &&
676
- 'status' in error &&
677
- typeof error.status === 'number' &&
678
- 'message' in error);
679
- }
680
- /**
681
- * Determine if a Google API error is retryable based on HTTP status code.
682
- *
683
- * Retryable errors (per Google AIP-194):
684
- * - 408 (REQUEST_TIMEOUT): Request timeout
685
- * - 429 (RESOURCE_EXHAUSTED): Rate limit exceeded, quota exhausted
686
- * - 500 (INTERNAL): Internal server error
687
- * - 502 (BAD_GATEWAY): Bad gateway
688
- * - 503 (UNAVAILABLE): Service temporarily unavailable
689
- * - 504 (DEADLINE_EXCEEDED): Gateway timeout
690
- *
691
- * Non-retryable errors:
692
- * - 400 (INVALID_ARGUMENT): Invalid request parameters
693
- * - 401 (UNAUTHENTICATED): Authentication required
694
- * - 403 (PERMISSION_DENIED): Insufficient permissions
695
- * - 404 (NOT_FOUND): Resource not found
696
- * - 409 (CONFLICT): Resource conflict
697
- * - Other 4xx client errors
698
- *
699
- * @param httpStatusCode - The HTTP status code from the API error
700
- * @returns True if retryable, false if not retryable, undefined if unknown
701
- */
702
- isGeminiErrorRetryable(httpStatusCode) {
703
- // Retryable status codes
704
- if (httpStatusCode === 408)
705
- return true; // Request timeout
706
- if (httpStatusCode === 429)
707
- return true; // Rate limit/quota
708
- if (httpStatusCode === 502)
709
- return true; // Bad gateway
710
- if (httpStatusCode === 503)
711
- return true; // Service unavailable
712
- if (httpStatusCode === 504)
713
- return true; // Gateway timeout
714
- if (httpStatusCode >= 500 && httpStatusCode < 600)
715
- return true; // Other 5xx server errors
716
- // Non-retryable 4xx client errors
717
- if (httpStatusCode >= 400 && httpStatusCode < 500)
718
- return false;
719
- // Unknown status codes - let consumer decide retry strategy
720
- return undefined;
721
- }
722
- /**
723
- * Extract error type name from error message.
724
- * Google errors often include the error type in the message.
725
- * Examples: "INVALID_ARGUMENT", "RESOURCE_EXHAUSTED", "PERMISSION_DENIED"
726
- */
727
- extractErrorName(message) {
728
- // Common Google error patterns
729
- const patterns = [
730
- /^([A-Z_]+):/, // "ERROR_NAME: message"
731
- /\[([A-Z_]+)\]/, // "[ERROR_NAME] message"
732
- /^(\w+Error):/, // "ErrorTypeError: message"
733
- ];
734
- for (const pattern of patterns) {
735
- const match = message.match(pattern);
736
- if (match) {
737
- return match[1];
738
- }
739
- }
740
- return undefined;
741
- }
742
- }
743
- exports.GeminiModelDefinition = GeminiModelDefinition;
744
- /**
745
- * Converts functionCall and functionResponse parts to text parts in Gemini Content[].
746
- * Preserves tool call information while removing structured parts that require
747
- * tools/toolConfig to be defined in the API request.
748
- */
749
- function convertGeminiFunctionPartsToText(contents) {
750
- return contents.map(content => {
751
- if (!content.parts)
752
- return content;
753
- const hasFunctionParts = content.parts.some(p => p.functionCall || p.functionResponse);
754
- if (!hasFunctionParts)
755
- return content;
756
- const newParts = content.parts.map(part => {
757
- if (part.functionCall) {
758
- const argsStr = part.functionCall.args ? JSON.stringify(part.functionCall.args) : '';
759
- const truncated = argsStr.length > 500 ? argsStr.substring(0, 500) + '...' : argsStr;
760
- return { text: `[Tool call: ${part.functionCall.name}(${truncated})]` };
761
- }
762
- if (part.functionResponse) {
763
- const respStr = part.functionResponse.response
764
- ? JSON.stringify(part.functionResponse.response) : 'No response';
765
- const truncated = respStr.length > 500 ? respStr.substring(0, 500) + '...' : respStr;
766
- return { text: `[Tool result for ${part.functionResponse.name}: ${truncated}]` };
767
- }
768
- return part;
769
- });
770
- return { ...content, parts: newParts };
771
- });
772
- }
773
- function getToolDefinitions(tools) {
774
- if (!tools || tools.length === 0) {
775
- return undefined;
776
- }
777
- // VertexAI Gemini only supports one tool at a time.
778
- // For multiple tools, we have multiple functions in one tool.
779
- return {
780
- functionDeclarations: tools.map(getToolFunction),
781
- };
782
- }
783
- function getToolFunction(tool) {
784
- return {
785
- name: tool.name,
786
- description: tool.description,
787
- // Pass the input_schema directly as a JSON Schema object.
788
- // parametersJsonSchema accepts standard JSON Schema and is mutually exclusive
789
- // with the legacy parameters field (which required a proprietary Gemini Schema type).
790
- parametersJsonSchema: tool.input_schema,
791
- };
792
- }
793
- /**
794
- * Update the conversation messages
795
- * @param prompt
796
- * @param response
797
- * @returns
798
- */
799
- function updateConversation(conversation, prompt) {
800
- // Unwrap array if wrapped, otherwise treat as array
801
- const unwrapped = (0, core_1.unwrapConversationArray)(conversation);
802
- const convArray = unwrapped ?? (conversation || []);
803
- return convArray.concat(prompt);
804
- }
805
- const SYSTEM_KEY = '_llumiverse_system';
806
- /**
807
- * Extract the stored system instruction from a Gemini conversation object.
808
- * Returns undefined if no system was stored.
809
- */
810
- function extractSystemFromConversation(conversation) {
811
- if (typeof conversation === 'object' && conversation !== null) {
812
- const c = conversation;
813
- if (c[SYSTEM_KEY] && typeof c[SYSTEM_KEY] === 'object') {
814
- return c[SYSTEM_KEY];
815
- }
816
- }
817
- return undefined;
818
- }
819
- /**
820
- * Store the system instruction in the Gemini conversation wrapper object.
821
- * The conversation is already wrapped by incrementConversationTurn into
822
- * { _arrayConversation: Content[], _llumiverse_meta: {...} }.
823
- * We add _llumiverse_system alongside these fields.
824
- */
825
- function storeSystemInConversation(conversation, system) {
826
- if (!system)
827
- return conversation;
828
- if (typeof conversation === 'object' && conversation !== null) {
829
- return { ...conversation, [SYSTEM_KEY]: system };
830
- }
831
- return conversation;
832
- }
833
- /**
834
- *
835
- * 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.
836
- *
837
- * This is an excerpt from googleapis.github.io/python-genai:
838
- *
839
- * The function response in JSON object format.
840
- * Use “output” key to specify function output and “error” key to specify error details (if any).
841
- * If “output” and “error” keys are not specified, then whole “response” is treated as function output.
842
- * @see https://googleapis.github.io/python-genai/genai.html#genai.types.FunctionResponse
843
- */
844
- function formatFunctionResponse(response) {
845
- response = response.trim();
846
- if (response.startsWith("{") && response.endsWith("}")) {
847
- try {
848
- return JSON.parse(response);
849
- }
850
- catch (e) {
851
- return { output: response };
852
- }
853
- }
854
- else {
855
- return { output: response };
856
- }
857
- }
858
- //# sourceMappingURL=gemini.js.map