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