@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,1135 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BaseOpenAIDriver = void 0;
4
- exports.mapResponseStream = mapResponseStream;
5
- exports.convertOpenAIFunctionItemsToText = convertOpenAIFunctionItemsToText;
6
- exports.collectTools = collectTools;
7
- exports.fixOrphanedToolUse = fixOrphanedToolUse;
8
- const core_1 = require("@llumiverse/core");
9
- const error_1 = require("openai/error");
10
- const openai_format_js_1 = require("./openai_format.js");
11
- // Helper function to convert string to CompletionResult[]
12
- function textToCompletionResult(text) {
13
- return text ? [{ type: "text", value: text }] : [];
14
- }
15
- function isOpenAIReasoningModel(model) {
16
- const normalized = model.toLowerCase();
17
- return normalized.includes("o1")
18
- || normalized.includes("o3")
19
- || normalized.includes("o4")
20
- || normalized.includes("gpt-5");
21
- }
22
- function isGpt5ProModel(model) {
23
- const modelName = model.toLowerCase().split('/').pop() ?? model.toLowerCase();
24
- return /^gpt-5(?:\.\d+)?-pro/.test(modelName);
25
- }
26
- function openAIReasoningEffort(model, effort) {
27
- if (!effort || !isOpenAIReasoningModel(model)) {
28
- return undefined;
29
- }
30
- if (isGpt5ProModel(model)) {
31
- return "high";
32
- }
33
- return effort === "low" || effort === "medium" || effort === "high" ? effort : undefined;
34
- }
35
- //TODO: Do we need a list?, replace with if statements and modernize?
36
- const supportFineTunning = new Set([
37
- "gpt-3.5-turbo-1106",
38
- "gpt-3.5-turbo-0613",
39
- "babbage-002",
40
- "davinci-002",
41
- "gpt-4-0613"
42
- ]);
43
- class BaseOpenAIDriver extends core_1.AbstractDriver {
44
- constructor(opts) {
45
- super(opts);
46
- this.formatPrompt = openai_format_js_1.formatOpenAILikeMultimodalPrompt;
47
- }
48
- extractDataFromResponse(_options, result) {
49
- const tokenInfo = mapUsage(result.usage);
50
- const tools = collectTools(result.output);
51
- // Collect all parts in order (text and images)
52
- const allResults = extractCompletionResults(result.output);
53
- if (allResults.length === 0 && !tools) {
54
- this.logger.error({ result }, "[OpenAI] Response is not valid");
55
- throw new Error("Response is not valid: no data");
56
- }
57
- return {
58
- result: allResults,
59
- token_usage: tokenInfo,
60
- finish_reason: responseFinishReason(result, tools),
61
- tool_use: tools,
62
- };
63
- }
64
- async requestTextCompletionStream(prompt, options) {
65
- if (options.model_options?._option_id !== undefined &&
66
- options.model_options?._option_id !== "openai-text" &&
67
- options.model_options?._option_id !== "openai-thinking" &&
68
- options.model_options?._option_id !== "text-fallback") {
69
- this.logger.debug({ options: options.model_options }, "Unexpected option id");
70
- }
71
- // Include conversation history (same as non-streaming)
72
- // Fix orphaned function_call items (can occur when agent is stopped mid-tool-execution)
73
- let conversation = fixOrphanedToolUse(updateConversation(options.conversation, prompt));
74
- const toolDefs = getToolDefinitions(options.tools);
75
- const useTools = toolDefs ? (0, core_1.supportsToolUse)(options.model, this.provider, true) : false;
76
- // When no tools are provided but conversation contains function_call/function_call_output
77
- // items (e.g. checkpoint summary calls), convert them to text to avoid API errors
78
- if (!useTools) {
79
- conversation = convertOpenAIFunctionItemsToText(conversation);
80
- }
81
- convertRoles(prompt, options.model);
82
- const model_options = options.model_options;
83
- insert_image_detail(prompt, model_options?.image_detail ?? "auto");
84
- let parsedSchema = undefined;
85
- let strictMode = false;
86
- if (options.result_schema && supportsSchema(options.model)) {
87
- try {
88
- parsedSchema = openAISchemaFormat(options.result_schema);
89
- strictMode = true;
90
- }
91
- catch (e) {
92
- parsedSchema = limitedSchemaFormat(options.result_schema);
93
- strictMode = false;
94
- }
95
- }
96
- const isReasoningModel = isOpenAIReasoningModel(options.model);
97
- const effort = openAIReasoningEffort(options.model, model_options?.effort ?? model_options?.reasoning_effort);
98
- const reasoning = effort ? { effort } : undefined;
99
- const stream = await this.service.responses.create({
100
- stream: true,
101
- model: options.model,
102
- input: conversation,
103
- reasoning,
104
- temperature: isReasoningModel ? undefined : model_options?.temperature,
105
- top_p: isReasoningModel ? undefined : model_options?.top_p,
106
- max_output_tokens: model_options?.max_tokens,
107
- tools: useTools ? toolDefs : undefined,
108
- text: parsedSchema ? {
109
- format: {
110
- type: "json_schema",
111
- name: "format_output",
112
- schema: parsedSchema,
113
- strict: strictMode,
114
- }
115
- } : undefined,
116
- });
117
- return mapResponseStream(stream);
118
- }
119
- async requestTextCompletion(prompt, options) {
120
- if (options.model_options?._option_id !== undefined &&
121
- options.model_options?._option_id !== "openai-text" &&
122
- options.model_options?._option_id !== "openai-thinking") {
123
- this.logger.debug({ options: options.model_options }, "Unexpected option id");
124
- }
125
- convertRoles(prompt, options.model);
126
- const model_options = options.model_options;
127
- insert_image_detail(prompt, model_options?.image_detail ?? "auto");
128
- const toolDefs = getToolDefinitions(options.tools);
129
- const useTools = toolDefs ? (0, core_1.supportsToolUse)(options.model, this.provider) : false;
130
- // Fix orphaned function_call items (can occur when agent is stopped mid-tool-execution)
131
- let conversation = fixOrphanedToolUse(updateConversation(options.conversation, prompt));
132
- // When no tools are provided but conversation contains function_call/function_call_output
133
- // items (e.g. checkpoint summary calls), convert them to text to avoid API errors
134
- if (!useTools) {
135
- conversation = convertOpenAIFunctionItemsToText(conversation);
136
- }
137
- let parsedSchema = undefined;
138
- let strictMode = false;
139
- if (options.result_schema && supportsSchema(options.model)) {
140
- try {
141
- parsedSchema = openAISchemaFormat(options.result_schema);
142
- strictMode = true;
143
- }
144
- catch (e) {
145
- parsedSchema = limitedSchemaFormat(options.result_schema);
146
- strictMode = false;
147
- }
148
- }
149
- const isReasoningModel = isOpenAIReasoningModel(options.model);
150
- const effort = openAIReasoningEffort(options.model, model_options?.effort ?? model_options?.reasoning_effort);
151
- const reasoning = effort ? { effort } : undefined;
152
- const res = await this.service.responses.create({
153
- stream: false,
154
- model: options.model,
155
- input: conversation,
156
- reasoning,
157
- temperature: isReasoningModel ? undefined : model_options?.temperature,
158
- top_p: isReasoningModel ? undefined : model_options?.top_p,
159
- max_output_tokens: model_options?.max_tokens, //TODO: use max_tokens for older models, currently relying on OpenAI to handle it
160
- tools: useTools ? toolDefs : undefined,
161
- text: parsedSchema ? {
162
- format: {
163
- type: "json_schema",
164
- name: "format_output",
165
- schema: parsedSchema,
166
- strict: strictMode,
167
- }
168
- } : undefined,
169
- });
170
- const completion = this.extractDataFromResponse(options, res);
171
- if (options.include_original_response) {
172
- completion.original_response = res;
173
- }
174
- conversation = updateConversation(conversation, createAssistantMessageFromCompletion(completion));
175
- // Increment turn counter for deferred stripping
176
- conversation = (0, core_1.incrementConversationTurn)(conversation);
177
- // Strip large base64 image data based on options.stripImagesAfterTurns
178
- const currentTurn = (0, core_1.getConversationMeta)(conversation).turnNumber;
179
- const stripOptions = {
180
- keepForTurns: options.stripImagesAfterTurns ?? Infinity,
181
- currentTurn,
182
- textMaxTokens: options.stripTextMaxTokens
183
- };
184
- let processedConversation = (0, core_1.stripBase64ImagesFromConversation)(conversation, stripOptions);
185
- // Truncate large text content if configured
186
- processedConversation = (0, core_1.truncateLargeTextInConversation)(processedConversation, stripOptions);
187
- // Strip old heartbeat status messages
188
- processedConversation = (0, core_1.stripHeartbeatsFromConversation)(processedConversation, {
189
- keepForTurns: options.stripHeartbeatsAfterTurns ?? 1,
190
- currentTurn,
191
- });
192
- completion.conversation = processedConversation;
193
- return completion;
194
- }
195
- canStream(_options) {
196
- // Image generation models don't support streaming
197
- if (_options.model.includes("dall-e")
198
- || _options.model.includes("gpt-image")
199
- || _options.model.includes("chatgpt-image")) {
200
- return Promise.resolve(false);
201
- }
202
- if (_options.model.includes("o1")
203
- && !(_options.model.includes("mini") || _options.model.includes("preview"))) {
204
- //o1 full does not support streaming
205
- //TODO: Update when OpenAI adds support for streaming, last check 16/02/2025
206
- return Promise.resolve(false);
207
- }
208
- return Promise.resolve(true);
209
- }
210
- /**
211
- * Build conversation context after streaming completion.
212
- * Reconstructs the assistant message from accumulated results and applies stripping.
213
- */
214
- buildStreamingConversation(prompt, result, toolUse, options) {
215
- // Build assistant message from accumulated CompletionResult[]
216
- const completionResults = result;
217
- const textContent = completionResultsToText(completionResults);
218
- // Start with the conversation from options or the prompt
219
- let conversation = updateConversation(options.conversation, prompt);
220
- // Add assistant message as EasyInputMessage
221
- if (textContent) {
222
- const assistantMessage = {
223
- role: 'assistant',
224
- content: textContent,
225
- };
226
- conversation = updateConversation(conversation, [assistantMessage]);
227
- }
228
- // Add function calls as separate items (Response API format)
229
- if (toolUse && toolUse.length > 0) {
230
- const functionCalls = toolUse.map(t => ({
231
- type: 'function_call',
232
- call_id: t.id,
233
- name: t.tool_name,
234
- arguments: typeof t.tool_input === 'string' ? t.tool_input : JSON.stringify(t.tool_input ?? {}),
235
- }));
236
- conversation = updateConversation(conversation, functionCalls);
237
- }
238
- // Increment turn counter
239
- conversation = (0, core_1.incrementConversationTurn)(conversation);
240
- // Apply stripping based on options
241
- const currentTurn = (0, core_1.getConversationMeta)(conversation).turnNumber;
242
- const stripOptions = {
243
- keepForTurns: options.stripImagesAfterTurns ?? Infinity,
244
- currentTurn,
245
- textMaxTokens: options.stripTextMaxTokens
246
- };
247
- let processedConversation = (0, core_1.stripBase64ImagesFromConversation)(conversation, stripOptions);
248
- processedConversation = (0, core_1.truncateLargeTextInConversation)(processedConversation, stripOptions);
249
- processedConversation = (0, core_1.stripHeartbeatsFromConversation)(processedConversation, {
250
- keepForTurns: options.stripHeartbeatsAfterTurns ?? 1,
251
- currentTurn,
252
- });
253
- return processedConversation;
254
- }
255
- createTrainingPrompt(options) {
256
- if (options.model.includes("gpt")) {
257
- return super.createTrainingPrompt(options);
258
- }
259
- else {
260
- // babbage, davinci not yet implemented
261
- throw new Error("Unsupported model for training: " + options.model);
262
- }
263
- }
264
- async startTraining(dataset, options) {
265
- const url = await dataset.getURL();
266
- const file = await this.service.files.create({
267
- file: await fetch(url),
268
- purpose: "fine-tune",
269
- });
270
- const job = await this.service.fineTuning.jobs.create({
271
- training_file: file.id,
272
- model: options.model,
273
- hyperparameters: options.params
274
- });
275
- return jobInfo(job);
276
- }
277
- async cancelTraining(jobId) {
278
- const job = await this.service.fineTuning.jobs.cancel(jobId);
279
- return jobInfo(job);
280
- }
281
- async getTrainingJob(jobId) {
282
- const job = await this.service.fineTuning.jobs.retrieve(jobId);
283
- return jobInfo(job);
284
- }
285
- // ========= management API =============
286
- async validateConnection() {
287
- try {
288
- await this.service.models.list();
289
- return true;
290
- }
291
- catch (error) {
292
- return false;
293
- }
294
- }
295
- listTrainableModels() {
296
- return this._listModels((m) => supportFineTunning.has(m.id));
297
- }
298
- async listModels() {
299
- return this._listModels();
300
- }
301
- async _listModels(filter) {
302
- let result = (await this.service.models.list()).data;
303
- //Some of these use the completions API instead of the chat completions API.
304
- //Others are for non-text input modalities. Therefore common to both.
305
- const wordBlacklist = ["embed", "whisper", "transcribe", "audio", "moderation", "tts",
306
- "realtime", "babbage", "davinci", "codex", "o1-pro", "computer-use", "sora"];
307
- //OpenAI has very little information, filtering based on name.
308
- result = result.filter((m) => {
309
- return !wordBlacklist.some((word) => m.id.includes(word));
310
- });
311
- const models = filter ? result.filter(filter) : result;
312
- const aiModels = models.map((m) => {
313
- const modelCapability = (0, core_1.getModelCapabilities)(m.id, "openai");
314
- let owner = m.owned_by;
315
- if (owner == "system") {
316
- owner = "openai";
317
- }
318
- // Determine model type based on capabilities
319
- let modelType = core_1.ModelType.Text;
320
- if (m.id.includes("dall-e") || m.id.includes("gpt-image")) {
321
- modelType = core_1.ModelType.Image;
322
- }
323
- return {
324
- id: m.id,
325
- name: m.id,
326
- provider: this.provider,
327
- owner: owner,
328
- type: modelType,
329
- input_modalities: (0, core_1.modelModalitiesToArray)(modelCapability.input),
330
- output_modalities: (0, core_1.modelModalitiesToArray)(modelCapability.output),
331
- tool_support: modelCapability.tool_support,
332
- };
333
- }).sort((a, b) => a.id.localeCompare(b.id));
334
- return aiModels;
335
- }
336
- async generateEmbeddings({ text, image, model = "text-embedding-3-small" }) {
337
- if (image) {
338
- throw new Error("Image embeddings not supported by OpenAI");
339
- }
340
- if (!text) {
341
- throw new Error("No text provided");
342
- }
343
- const res = await this.service.embeddings.create({
344
- input: text,
345
- model: model,
346
- });
347
- const embeddings = res.data[0].embedding;
348
- if (!embeddings || embeddings.length === 0) {
349
- throw new Error("No embedding found");
350
- }
351
- return { values: embeddings, model };
352
- }
353
- imageModels = ["dall-e", "gpt-image", "chatgpt-image"];
354
- /**
355
- * Determine if a model is specifically an image generation model (not conversational image model)
356
- */
357
- isImageModel(model) {
358
- // DALL-E models are standalone image generation
359
- // gpt-image models can generate images in conversations, not standalone
360
- return this.imageModels.some(imageModel => model.includes(imageModel));
361
- }
362
- /**
363
- * Request image generation from standalone Images API
364
- * Supports: DALL-E 2, DALL-E 3, GPT-image models (for edit/variation)
365
- */
366
- async requestImageGeneration(prompt, options) {
367
- this.logger.debug(`[${this.provider}] Generating image with model ${options.model}`);
368
- const model_options = options.model_options;
369
- // Extract prompt text from ResponseInputItem[]
370
- let promptText = "";
371
- for (const item of prompt) {
372
- if ('content' in item && typeof item.content === 'string') {
373
- promptText += item.content + "\\n";
374
- }
375
- else if ('content' in item && Array.isArray(item.content)) {
376
- // Extract text from content array
377
- for (const part of item.content) {
378
- if ('type' in part && part.type === 'input_text' && 'text' in part) {
379
- promptText += part.text + "\\n";
380
- }
381
- }
382
- }
383
- }
384
- promptText = promptText.trim();
385
- try {
386
- const generateParams = {
387
- model: options.model,
388
- prompt: promptText,
389
- size: model_options?.size || "1024x1024",
390
- };
391
- // Add DALL-E specific options
392
- if (options.model.includes("dall-e") || model_options?._option_id === "openai-dalle") {
393
- const dalleOptions = model_options;
394
- generateParams.n = dalleOptions?.n || 1;
395
- generateParams.response_format = dalleOptions?.response_format || "b64_json";
396
- if (options.model.includes("dall-e-3")) {
397
- generateParams.quality = dalleOptions?.image_quality || "standard";
398
- if (dalleOptions?.style) {
399
- generateParams.style = dalleOptions.style;
400
- }
401
- }
402
- }
403
- else {
404
- // Default for other models
405
- generateParams.n = 1;
406
- }
407
- const response = await this.service.images.generate(generateParams);
408
- // Convert response to CompletionResults
409
- const results = [];
410
- if (response.data) {
411
- for (const image of response.data) {
412
- let imageValue;
413
- if (image.b64_json) {
414
- // Base64 format
415
- imageValue = `data:image/png;base64,${image.b64_json}`;
416
- }
417
- else if (image.url) {
418
- // URL format
419
- imageValue = image.url;
420
- }
421
- else {
422
- continue;
423
- }
424
- results.push({
425
- type: "image",
426
- value: imageValue
427
- });
428
- }
429
- }
430
- return {
431
- result: results
432
- };
433
- }
434
- catch (error) {
435
- this.logger.error({ error }, `[${this.provider}] Image generation failed`);
436
- return {
437
- result: [],
438
- error: {
439
- message: error.message,
440
- code: error.code || 'GENERATION_FAILED'
441
- }
442
- };
443
- }
444
- }
445
- /**
446
- * Format OpenAI API errors into LlumiverseError with proper status codes and retryability.
447
- *
448
- * OpenAI API errors have a specific structure:
449
- * - APIError.status: HTTP status code (400, 401, 403, 404, 409, 422, 429, 500+)
450
- * - APIError.error: Error object with type, message, param, code
451
- * - APIError.requestID: Request ID for support
452
- * - APIError.code: Error code (e.g., 'invalid_api_key', 'rate_limit_exceeded')
453
- * - APIError.param: Parameter that caused the error (optional)
454
- * - APIError.type: Error type (optional)
455
- *
456
- * Common error types:
457
- * - BadRequestError (400): Invalid request parameters
458
- * - AuthenticationError (401): Invalid API key
459
- * - PermissionDeniedError (403): Insufficient permissions
460
- * - NotFoundError (404): Resource not found
461
- * - ConflictError (409): Resource conflict
462
- * - UnprocessableEntityError (422): Validation error
463
- * - RateLimitError (429): Rate limit exceeded
464
- * - InternalServerError (500+): Server-side errors
465
- * - APIConnectionError: Connection issues (no status code)
466
- * - APIConnectionTimeoutError: Request timeout (no status code)
467
- * - LengthFinishReasonError: Response truncated due to length
468
- * - ContentFilterFinishReasonError: Content filtered
469
- *
470
- * This implementation works for:
471
- * - OpenAI API
472
- * - Azure OpenAI
473
- * - xAI (uses OpenAI-compatible API)
474
- * - Azure Foundry (OpenAI-compatible)
475
- * - Other OpenAI-compatible APIs
476
- *
477
- * @see https://platform.openai.com/docs/guides/error-codes
478
- */
479
- formatLlumiverseError(error, context) {
480
- // Check if it's an OpenAI API error
481
- const isOpenAIError = this.isOpenAIApiError(error);
482
- if (!isOpenAIError) {
483
- // Not an OpenAI API error, use default handling
484
- throw error;
485
- }
486
- const apiError = error;
487
- const httpStatusCode = apiError.status;
488
- // Extract error message
489
- const message = apiError.message || String(error);
490
- // Extract additional error details (only available on APIError)
491
- const errorCode = apiError.code;
492
- const errorParam = apiError.param;
493
- const errorType = apiError.type;
494
- // Build user-facing message with status code
495
- let userMessage = message;
496
- // Include status code in message (for end-user visibility)
497
- if (httpStatusCode) {
498
- userMessage = `[${httpStatusCode}] ${userMessage}`;
499
- }
500
- // Add error code if available and not already in message
501
- if (errorCode && !userMessage.includes(errorCode)) {
502
- userMessage += ` (code: ${errorCode})`;
503
- }
504
- // Add parameter info if available and helpful
505
- if (errorParam && !userMessage.toLowerCase().includes(errorParam.toLowerCase())) {
506
- userMessage += ` [param: ${errorParam}]`;
507
- }
508
- // Add request ID if available (useful for OpenAI support)
509
- if (apiError.requestID) {
510
- userMessage += ` (Request ID: ${apiError.requestID})`;
511
- }
512
- // Determine retryability based on OpenAI error types
513
- const retryable = this.isOpenAIErrorRetryable(error, httpStatusCode, errorCode, errorType);
514
- // Use the error constructor name as the error name
515
- const errorName = error.constructor?.name || 'OpenAIError';
516
- return new core_1.LlumiverseError(`[${context.provider}] ${userMessage}`, retryable, context, error, httpStatusCode, errorName);
517
- }
518
- /**
519
- * Type guard to check if error is an OpenAI API error or OpenAI-specific error.
520
- */
521
- isOpenAIApiError(error) {
522
- return (error !== null &&
523
- typeof error === 'object' &&
524
- (error instanceof error_1.APIError || error instanceof error_1.OpenAIError));
525
- }
526
- /**
527
- * Determine if an OpenAI API error is retryable.
528
- *
529
- * Retryable errors:
530
- * - RateLimitError (429): Rate limit exceeded, retry with backoff
531
- * - InternalServerError (500+): Server-side errors
532
- * - APIConnectionTimeoutError: Request timeout
533
- * - Error codes: 'timeout', 'server_error', 'service_unavailable'
534
- * - Status codes: 408, 429, 502, 503, 504, 529, 5xx
535
- *
536
- * Non-retryable errors:
537
- * - BadRequestError (400): Invalid request parameters
538
- * - AuthenticationError (401): Invalid API key
539
- * - PermissionDeniedError (403): Insufficient permissions
540
- * - NotFoundError (404): Resource not found
541
- * - ConflictError (409): Resource conflict
542
- * - UnprocessableEntityError (422): Validation error
543
- * - LengthFinishReasonError: Length limit reached
544
- * - ContentFilterFinishReasonError: Content filtered
545
- * - Error codes: 'invalid_api_key', 'invalid_request_error', 'model_not_found'
546
- * - Other 4xx client errors
547
- *
548
- * @param error - The error object
549
- * @param httpStatusCode - The HTTP status code if available
550
- * @param errorCode - The error code if available
551
- * @param errorType - The error type if available
552
- * @returns True if retryable, false if not retryable, undefined if unknown
553
- */
554
- isOpenAIErrorRetryable(error, httpStatusCode, errorCode, errorType) {
555
- // Check specific OpenAI error types by class
556
- if (error instanceof error_1.RateLimitError)
557
- return true;
558
- if (error instanceof error_1.InternalServerError)
559
- return true;
560
- if (error instanceof error_1.APIConnectionTimeoutError)
561
- return true;
562
- // Non-retryable by error type
563
- if (error instanceof error_1.BadRequestError)
564
- return false;
565
- if (error instanceof error_1.AuthenticationError)
566
- return false;
567
- if (error instanceof error_1.PermissionDeniedError)
568
- return false;
569
- if (error instanceof error_1.NotFoundError)
570
- return false;
571
- if (error instanceof error_1.ConflictError)
572
- return false;
573
- if (error instanceof error_1.UnprocessableEntityError)
574
- return false;
575
- if (error instanceof error_1.LengthFinishReasonError)
576
- return false;
577
- if (error instanceof error_1.ContentFilterFinishReasonError)
578
- return false;
579
- // Check error codes (OpenAI specific)
580
- if (errorCode) {
581
- // Retryable error codes
582
- if (errorCode === 'timeout')
583
- return true;
584
- if (errorCode === 'server_error')
585
- return true;
586
- if (errorCode === 'service_unavailable')
587
- return true;
588
- if (errorCode === 'rate_limit_exceeded')
589
- return true;
590
- // Non-retryable error codes
591
- if (errorCode === 'invalid_api_key')
592
- return false;
593
- if (errorCode === 'invalid_request_error')
594
- return false;
595
- if (errorCode === 'model_not_found')
596
- return false;
597
- if (errorCode === 'insufficient_quota')
598
- return false;
599
- if (errorCode === 'invalid_model')
600
- return false;
601
- if (errorCode.includes('invalid_'))
602
- return false;
603
- }
604
- // Check error type
605
- if (errorType === 'invalid_request_error')
606
- return false;
607
- if (errorType === 'authentication_error')
608
- return false;
609
- // Use HTTP status code
610
- if (httpStatusCode !== undefined) {
611
- if (httpStatusCode === 429)
612
- return true; // Rate limit
613
- if (httpStatusCode === 408)
614
- return true; // Request timeout
615
- if (httpStatusCode === 502)
616
- return true; // Bad gateway
617
- if (httpStatusCode === 503)
618
- return true; // Service unavailable
619
- if (httpStatusCode === 504)
620
- return true; // Gateway timeout
621
- if (httpStatusCode === 529)
622
- return true; // Overloaded
623
- if (httpStatusCode >= 500 && httpStatusCode < 600)
624
- return true; // Server errors
625
- if (httpStatusCode >= 400 && httpStatusCode < 500)
626
- return false; // Client errors
627
- }
628
- // Connection errors without status codes
629
- if (error instanceof error_1.APIConnectionError && !(error instanceof error_1.APIConnectionTimeoutError)) {
630
- // Generic connection errors might be retryable (network issues)
631
- return true;
632
- }
633
- // Unknown error type - let consumer decide retry strategy
634
- return undefined;
635
- }
636
- }
637
- exports.BaseOpenAIDriver = BaseOpenAIDriver;
638
- function jobInfo(job) {
639
- //validating_files`, `queued`, `running`, `succeeded`, `failed`, or `cancelled`.
640
- const jobStatus = job.status;
641
- let status = core_1.TrainingJobStatus.running;
642
- let details;
643
- if (jobStatus === 'succeeded') {
644
- status = core_1.TrainingJobStatus.succeeded;
645
- }
646
- else if (jobStatus === 'failed') {
647
- status = core_1.TrainingJobStatus.failed;
648
- details = job.error ? `${job.error.code} - ${job.error.message} ${job.error.param ? " [" + job.error.param + "]" : ""}` : "error";
649
- }
650
- else if (jobStatus === 'cancelled') {
651
- status = core_1.TrainingJobStatus.cancelled;
652
- }
653
- else {
654
- status = core_1.TrainingJobStatus.running;
655
- details = jobStatus;
656
- }
657
- return {
658
- id: job.id,
659
- model: job.fine_tuned_model || undefined,
660
- status,
661
- details
662
- };
663
- }
664
- function mapUsage(usage) {
665
- if (!usage) {
666
- return undefined;
667
- }
668
- return {
669
- prompt: usage.input_tokens,
670
- result: usage.output_tokens,
671
- total: usage.total_tokens,
672
- prompt_cached: usage.input_tokens_details?.cached_tokens ?? undefined,
673
- prompt_new: usage.input_tokens - (usage.input_tokens_details?.cached_tokens ?? 0),
674
- };
675
- }
676
- function completionResultsToText(completionResults) {
677
- if (!completionResults) {
678
- return '';
679
- }
680
- return completionResults
681
- .map(r => {
682
- switch (r.type) {
683
- case 'text':
684
- return r.value;
685
- case 'json':
686
- return typeof r.value === 'string' ? r.value : JSON.stringify(r.value);
687
- case 'image':
688
- // Skip images in conversation - they're in the result
689
- return '';
690
- default:
691
- return String(r.value || '');
692
- }
693
- })
694
- .join('');
695
- }
696
- function createAssistantMessageFromCompletion(completion) {
697
- const textContent = completionResultsToText(completion.result);
698
- const result = [];
699
- // Add assistant text message if present
700
- if (textContent) {
701
- const assistantMessage = {
702
- role: 'assistant',
703
- content: textContent,
704
- };
705
- result.push(assistantMessage);
706
- }
707
- // Add function calls as separate items (Response API format)
708
- if (completion.tool_use && completion.tool_use.length > 0) {
709
- for (const t of completion.tool_use) {
710
- const functionCall = {
711
- type: 'function_call',
712
- call_id: t.id,
713
- name: t.tool_name,
714
- arguments: typeof t.tool_input === 'string'
715
- ? t.tool_input
716
- : JSON.stringify(t.tool_input ?? {}),
717
- };
718
- result.push(functionCall);
719
- }
720
- }
721
- return result;
722
- }
723
- function mapResponseStream(stream) {
724
- const toolCallMetadata = new Map();
725
- return {
726
- async *[Symbol.asyncIterator]() {
727
- for await (const event of stream) {
728
- if (event.type === 'response.output_item.added' && event.item.type === 'function_call') {
729
- const syntheticId = `tool_${event.output_index}`;
730
- const callId = event.item.call_id ?? event.item.id;
731
- const metadata = { syntheticId, callId, name: event.item.name };
732
- if (event.item.id) {
733
- toolCallMetadata.set(event.item.id, metadata);
734
- }
735
- if (event.item.call_id) {
736
- toolCallMetadata.set(event.item.call_id, metadata);
737
- }
738
- const toolUse = {
739
- id: syntheticId,
740
- _actual_id: callId,
741
- tool_name: event.item.name,
742
- tool_input: '',
743
- };
744
- yield {
745
- result: [],
746
- tool_use: [toolUse],
747
- };
748
- }
749
- else if (event.type === 'response.function_call_arguments.delta') {
750
- const metadata = toolCallMetadata.get(event.item_id);
751
- const syntheticId = metadata?.syntheticId ?? `tool_${event.output_index}`;
752
- const callId = metadata?.callId ?? event.item_id;
753
- const toolUse = {
754
- id: syntheticId,
755
- _actual_id: callId,
756
- tool_name: metadata?.name ?? '',
757
- tool_input: event.delta,
758
- };
759
- yield {
760
- result: [],
761
- tool_use: [toolUse],
762
- };
763
- }
764
- // Note: We don't emit response.function_call_arguments.done because the arguments were already
765
- // streamed via delta events. Emitting it again would duplicate the tool_input content.
766
- // We only update the metadata to ensure the tool name is captured.
767
- else if (event.type === 'response.function_call_arguments.done') {
768
- // Just update metadata, don't yield (arguments already accumulated from delta events)
769
- const metadata = toolCallMetadata.get(event.item_id);
770
- const syntheticId = metadata?.syntheticId ?? `tool_${event.output_index}`;
771
- const tool_name = metadata?.name ?? event.name ?? '';
772
- if (event.item_id) {
773
- toolCallMetadata.set(event.item_id, { syntheticId, callId: metadata?.callId, name: tool_name });
774
- }
775
- }
776
- else if (event.type === 'response.output_text.delta') {
777
- yield {
778
- result: textToCompletionResult(event.delta),
779
- };
780
- }
781
- // Note: We don't emit response.output_text.done because the text was already
782
- // streamed via delta events. Emitting it again would duplicate the content.
783
- else if (event.type === 'response.completed' || event.type === 'response.incomplete' || event.type === 'response.failed') {
784
- const finalTools = collectTools(event.response.output);
785
- yield {
786
- result: [],
787
- finish_reason: responseFinishReason(event.response, finalTools),
788
- token_usage: mapUsage(event.response.usage),
789
- };
790
- }
791
- }
792
- }
793
- };
794
- }
795
- function insert_image_detail(items, detail_level) {
796
- if (detail_level === "auto" || detail_level === "low" || detail_level === "high") {
797
- for (const item of items) {
798
- // Check if it's an EasyInputMessage or Message with content array
799
- if ('role' in item && 'content' in item && item.role !== 'assistant') {
800
- const content = item.content;
801
- if (Array.isArray(content)) {
802
- for (const part of content) {
803
- if (typeof part === 'object' && part.type === 'input_image') {
804
- part.detail = detail_level;
805
- }
806
- }
807
- }
808
- }
809
- }
810
- }
811
- return items;
812
- }
813
- function convertRoles(items, model) {
814
- //New openai models use developer role instead of system
815
- if (model.includes("o1") || model.includes("o3")) {
816
- if (model.includes("o1-mini") || model.includes("o1-preview")) {
817
- //o1-mini and o1-preview support neither system nor developer
818
- for (const item of items) {
819
- if ('role' in item && item.role === 'system') {
820
- item.role = 'user';
821
- }
822
- }
823
- }
824
- else {
825
- //Models newer than o1 use developer role
826
- for (const item of items) {
827
- if ('role' in item && item.role === 'system') {
828
- item.role = 'developer';
829
- }
830
- }
831
- }
832
- }
833
- return items;
834
- }
835
- //Structured output support is typically aligned with tool use support
836
- //Not true for realtime models, which do not support structured output, but do support tool use.
837
- function supportsSchema(model) {
838
- const realtimeModel = model.includes("realtime");
839
- if (realtimeModel) {
840
- return false;
841
- }
842
- return (0, core_1.supportsToolUse)(model, "openai");
843
- }
844
- /**
845
- * Converts function_call and function_call_output items to text messages in OpenAI conversation.
846
- * Preserves tool call information while removing structured items that require
847
- * tools to be defined in the API request.
848
- */
849
- function convertOpenAIFunctionItemsToText(items) {
850
- const hasFunctionItems = items.some(item => {
851
- const type = item.type;
852
- return type === 'function_call' || type === 'function_call_output';
853
- });
854
- if (!hasFunctionItems)
855
- return items;
856
- return items.map(item => {
857
- const typed = item;
858
- if (typed.type === 'function_call') {
859
- const argsStr = typed.arguments || '';
860
- const truncated = argsStr.length > 500 ? argsStr.substring(0, 500) + '...' : argsStr;
861
- return {
862
- role: 'assistant',
863
- content: `[Tool call: ${typed.name}(${truncated})]`,
864
- };
865
- }
866
- if (typed.type === 'function_call_output') {
867
- const output = typed.output || 'No output';
868
- const truncated = output.length > 500 ? output.substring(0, 500) + '...' : output;
869
- return {
870
- role: 'user',
871
- content: `[Tool result: ${truncated}]`,
872
- };
873
- }
874
- return item;
875
- });
876
- }
877
- function getToolDefinitions(tools) {
878
- return tools ? tools.map(getToolDefinition) : undefined;
879
- }
880
- function getToolDefinition(toolDef) {
881
- let parsedSchema = undefined;
882
- let strictMode = false;
883
- if (toolDef.input_schema) {
884
- try {
885
- //TODO: type assertion here is not safe, does not work with satisfies
886
- parsedSchema = openAISchemaFormat(toolDef.input_schema);
887
- strictMode = true;
888
- }
889
- catch (e) {
890
- //TODO: type assertion here is not safe, does not work with satisfies
891
- parsedSchema = limitedSchemaFormat(toolDef.input_schema);
892
- strictMode = false;
893
- }
894
- }
895
- return {
896
- type: "function",
897
- name: toolDef.name,
898
- description: toolDef.description,
899
- parameters: parsedSchema ?? null,
900
- strict: strictMode,
901
- };
902
- }
903
- function updateConversation(conversation, items) {
904
- if (!items) {
905
- // Unwrap array if wrapped, otherwise treat as array
906
- const unwrapped = (0, core_1.unwrapConversationArray)(conversation);
907
- return unwrapped ?? (conversation || []);
908
- }
909
- if (!conversation) {
910
- return items;
911
- }
912
- // Unwrap array if wrapped, otherwise treat as array
913
- const unwrapped = (0, core_1.unwrapConversationArray)(conversation);
914
- const convArray = unwrapped ?? conversation;
915
- return [...convArray, ...items];
916
- }
917
- function collectTools(output) {
918
- if (!output) {
919
- return undefined;
920
- }
921
- const tools = [];
922
- for (const item of output) {
923
- if (item.type === 'function_call') {
924
- const id = item.call_id || item.id;
925
- if (!id) {
926
- continue;
927
- }
928
- tools.push({
929
- id,
930
- tool_name: item.name ?? '',
931
- tool_input: safeJsonParse(item.arguments),
932
- });
933
- }
934
- }
935
- return tools.length > 0 ? tools : undefined;
936
- }
937
- /**
938
- * Collect all parts (text and images) from response output in order.
939
- * This preserves the original ordering of text and image parts.
940
- */
941
- function extractCompletionResults(output) {
942
- if (!output) {
943
- return [];
944
- }
945
- const results = [];
946
- for (const item of output) {
947
- if (item.type === 'message') {
948
- // Extract text from message content
949
- for (const part of item.content) {
950
- if (part.type === 'output_text' && part.text) {
951
- results.push({
952
- type: "text",
953
- value: part.text
954
- });
955
- }
956
- }
957
- }
958
- else if (item.type === 'image_generation_call' && 'result' in item && item.result) {
959
- // GPT-image models return base64 encoded images in result field
960
- const base64Data = item.result;
961
- // Format as data URL for consistency with other image outputs
962
- const imageUrl = base64Data.startsWith('data:')
963
- ? base64Data
964
- : `data:image/png;base64,${base64Data}`;
965
- results.push({
966
- type: "image",
967
- value: imageUrl
968
- });
969
- }
970
- }
971
- return results;
972
- }
973
- //For strict mode false
974
- function limitedSchemaFormat(schema) {
975
- const formattedSchema = { ...schema };
976
- // Defaults not supported
977
- delete formattedSchema.default;
978
- // OpenAI requires type field even in non-strict mode
979
- // If no type is specified, default to 'object' for properties with format/editor hints,
980
- // otherwise 'string' as a safe fallback
981
- if (!formattedSchema.type && formattedSchema.description) {
982
- // Properties with format: "document" or editor hints are typically objects
983
- if (formattedSchema.format === 'document' || formattedSchema.editor) {
984
- formattedSchema.type = 'object';
985
- }
986
- else {
987
- formattedSchema.type = 'string';
988
- }
989
- }
990
- if (formattedSchema?.properties) {
991
- // Process each property recursively
992
- for (const propName of Object.keys(formattedSchema.properties)) {
993
- const property = formattedSchema.properties[propName];
994
- // Recursively process properties
995
- formattedSchema.properties[propName] = limitedSchemaFormat(property);
996
- // Process arrays with items of type object
997
- if (property?.type === 'array' && property.items && property.items?.type === 'object') {
998
- formattedSchema.properties[propName] = {
999
- ...property,
1000
- items: limitedSchemaFormat(property.items),
1001
- };
1002
- }
1003
- }
1004
- }
1005
- return formattedSchema;
1006
- }
1007
- //For strict mode true
1008
- function openAISchemaFormat(schema, nesting = 0) {
1009
- if (nesting > 5) {
1010
- throw new Error("OpenAI schema nesting too deep");
1011
- }
1012
- const formattedSchema = { ...schema };
1013
- // Defaults not supported
1014
- delete formattedSchema.default;
1015
- // Additional properties not supported, required to be set.
1016
- if (formattedSchema?.type === "object") {
1017
- formattedSchema.additionalProperties = false;
1018
- }
1019
- if (formattedSchema?.properties) {
1020
- // Set all properties as required
1021
- formattedSchema.required = Object.keys(formattedSchema.properties);
1022
- // Process each property recursively
1023
- for (const propName of Object.keys(formattedSchema.properties)) {
1024
- const property = formattedSchema.properties[propName];
1025
- // OpenAI strict mode requires all properties to have a type
1026
- if (!property?.type) {
1027
- throw new Error(`Property '${propName}' is missing required 'type' field for OpenAI strict mode`);
1028
- }
1029
- // Recursively process properties
1030
- formattedSchema.properties[propName] = openAISchemaFormat(property, nesting + 1);
1031
- // Process arrays with items of type object
1032
- if (property?.type === 'array' && property.items && property.items?.type === 'object') {
1033
- formattedSchema.properties[propName] = {
1034
- ...property,
1035
- items: openAISchemaFormat(property.items, nesting + 1),
1036
- };
1037
- }
1038
- }
1039
- }
1040
- if (formattedSchema?.type === 'object' && (!formattedSchema?.properties || Object.keys(formattedSchema?.properties ?? {}).length == 0)) {
1041
- //If no properties are defined, then additionalProperties: true was set or the object would be empty.
1042
- //OpenAI does not support this on structured output/ strict mode.
1043
- throw new Error("OpenAI does not support empty objects or objects with additionalProperties set to true");
1044
- }
1045
- return formattedSchema;
1046
- }
1047
- function responseFinishReason(response, tools) {
1048
- if (tools && tools.length > 0) {
1049
- return "tool_use";
1050
- }
1051
- if (response.status === 'incomplete') {
1052
- if (response.incomplete_details?.reason === 'max_output_tokens') {
1053
- return 'length';
1054
- }
1055
- return response.incomplete_details?.reason ?? 'incomplete';
1056
- }
1057
- if (response.status && response.status !== 'completed') {
1058
- return response.status;
1059
- }
1060
- return 'stop';
1061
- }
1062
- /**
1063
- * Fix orphaned function_call items in the OpenAI Responses API conversation.
1064
- *
1065
- * When an agent is stopped mid-tool-execution, the conversation may contain
1066
- * function_call items without matching function_call_output items. The OpenAI
1067
- * Responses API requires every function_call to have a matching function_call_output.
1068
- *
1069
- * This function detects such cases and injects synthetic function_call_output items
1070
- * indicating the tools were interrupted, allowing the conversation to continue.
1071
- */
1072
- function fixOrphanedToolUse(items) {
1073
- if (items.length < 2)
1074
- return items;
1075
- // First pass: collect all function_call_output call_ids
1076
- const outputCallIds = new Set();
1077
- for (const item of items) {
1078
- if ('type' in item && item.type === 'function_call_output') {
1079
- outputCallIds.add(item.call_id);
1080
- }
1081
- }
1082
- // Second pass: build result, injecting synthetic outputs for orphaned function_calls
1083
- const result = [];
1084
- const pendingCalls = new Map(); // call_id -> tool name
1085
- for (const item of items) {
1086
- if ('type' in item && item.type === 'function_call') {
1087
- const fc = item;
1088
- // Only track if there's no matching output anywhere in the conversation
1089
- if (!outputCallIds.has(fc.call_id)) {
1090
- pendingCalls.set(fc.call_id, fc.name ?? 'unknown');
1091
- }
1092
- result.push(item);
1093
- }
1094
- else if ('type' in item && item.type === 'function_call_output') {
1095
- result.push(item);
1096
- }
1097
- else {
1098
- // Before any non-function item, flush pending orphaned calls
1099
- if (pendingCalls.size > 0) {
1100
- for (const [callId, toolName] of pendingCalls) {
1101
- result.push({
1102
- type: 'function_call_output',
1103
- call_id: callId,
1104
- output: `[Tool interrupted: The user stopped the operation before "${toolName}" could execute.]`,
1105
- });
1106
- }
1107
- pendingCalls.clear();
1108
- }
1109
- result.push(item);
1110
- }
1111
- }
1112
- // Handle trailing orphans at the end of the conversation
1113
- if (pendingCalls.size > 0) {
1114
- for (const [callId, toolName] of pendingCalls) {
1115
- result.push({
1116
- type: 'function_call_output',
1117
- call_id: callId,
1118
- output: `[Tool interrupted: The user stopped the operation before "${toolName}" could execute.]`,
1119
- });
1120
- }
1121
- }
1122
- return result;
1123
- }
1124
- function safeJsonParse(value) {
1125
- if (typeof value !== 'string') {
1126
- return value;
1127
- }
1128
- try {
1129
- return JSON.parse(value);
1130
- }
1131
- catch {
1132
- return value;
1133
- }
1134
- }
1135
- //# sourceMappingURL=index.js.map