openai 4.0.0-beta.0 → 4.0.0-beta.10

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 (467) hide show
  1. package/README.md +107 -52
  2. package/_shims/ReadableStream.d.ts +38 -0
  3. package/_shims/ReadableStream.js +5 -0
  4. package/_shims/ReadableStream.mjs +7 -0
  5. package/_shims/ReadableStream.node.d.ts +6 -0
  6. package/_shims/ReadableStream.node.d.ts.map +1 -0
  7. package/_shims/ReadableStream.node.js +14 -0
  8. package/_shims/ReadableStream.node.js.map +1 -0
  9. package/_shims/ReadableStream.node.mjs +3 -0
  10. package/_shims/ReadableStream.node.mjs.map +1 -0
  11. package/_shims/agent.d.ts +9 -0
  12. package/_shims/agent.d.ts.map +1 -0
  13. package/_shims/agent.js +14 -0
  14. package/_shims/agent.js.map +1 -0
  15. package/_shims/agent.mjs +10 -0
  16. package/_shims/agent.mjs.map +1 -0
  17. package/_shims/agent.node.d.ts +7 -0
  18. package/_shims/agent.node.d.ts.map +1 -0
  19. package/_shims/agent.node.js +28 -0
  20. package/_shims/agent.node.js.map +1 -0
  21. package/_shims/agent.node.mjs +16 -0
  22. package/_shims/agent.node.mjs.map +1 -0
  23. package/_shims/fetch.d.ts +59 -0
  24. package/_shims/fetch.js +13 -0
  25. package/_shims/fetch.mjs +15 -0
  26. package/_shims/fetch.node.d.ts +63 -0
  27. package/_shims/fetch.node.js +12 -0
  28. package/_shims/fetch.node.mjs +14 -0
  29. package/_shims/fileFromPath.d.ts +22 -0
  30. package/_shims/fileFromPath.d.ts.map +1 -0
  31. package/_shims/fileFromPath.js +16 -0
  32. package/_shims/fileFromPath.js.map +1 -0
  33. package/_shims/fileFromPath.mjs +12 -0
  34. package/_shims/fileFromPath.mjs.map +1 -0
  35. package/_shims/fileFromPath.node.d.ts +17 -0
  36. package/_shims/fileFromPath.node.d.ts.map +1 -0
  37. package/_shims/fileFromPath.node.js +17 -0
  38. package/_shims/fileFromPath.node.js.map +1 -0
  39. package/_shims/fileFromPath.node.mjs +13 -0
  40. package/_shims/fileFromPath.node.mjs.map +1 -0
  41. package/_shims/formdata.d.ts +43 -0
  42. package/_shims/formdata.js +9 -0
  43. package/_shims/formdata.mjs +11 -0
  44. package/_shims/formdata.node.d.ts +45 -0
  45. package/_shims/formdata.node.js +11 -0
  46. package/_shims/formdata.node.mjs +9 -0
  47. package/_shims/getMultipartRequestOptions.d.ts +10 -0
  48. package/_shims/getMultipartRequestOptions.d.ts.map +1 -0
  49. package/_shims/getMultipartRequestOptions.js +12 -0
  50. package/_shims/getMultipartRequestOptions.js.map +1 -0
  51. package/_shims/getMultipartRequestOptions.mjs +8 -0
  52. package/_shims/getMultipartRequestOptions.mjs.map +1 -0
  53. package/_shims/getMultipartRequestOptions.node.d.ts +10 -0
  54. package/_shims/getMultipartRequestOptions.node.d.ts.map +1 -0
  55. package/_shims/getMultipartRequestOptions.node.js +22 -0
  56. package/_shims/getMultipartRequestOptions.node.js.map +1 -0
  57. package/_shims/getMultipartRequestOptions.node.mjs +18 -0
  58. package/_shims/getMultipartRequestOptions.node.mjs.map +1 -0
  59. package/_shims/node-readable.d.ts +23 -0
  60. package/_shims/node-readable.d.ts.map +1 -0
  61. package/_shims/node-readable.js +11 -0
  62. package/_shims/node-readable.js.map +1 -0
  63. package/_shims/node-readable.mjs +7 -0
  64. package/_shims/node-readable.mjs.map +1 -0
  65. package/_shims/node-readable.node.d.ts +8 -0
  66. package/_shims/node-readable.node.d.ts.map +1 -0
  67. package/_shims/node-readable.node.js +9 -0
  68. package/_shims/node-readable.node.js.map +1 -0
  69. package/_shims/node-readable.node.mjs +5 -0
  70. package/_shims/node-readable.node.mjs.map +1 -0
  71. package/bin/cli +21 -0
  72. package/{dist/cjs/core.d.ts → core.d.ts} +108 -57
  73. package/core.d.ts.map +1 -0
  74. package/core.js +858 -0
  75. package/core.js.map +1 -0
  76. package/core.mjs +786 -0
  77. package/core.mjs.map +1 -0
  78. package/{dist/cjs/error.d.ts → error.d.ts} +6 -1
  79. package/error.d.ts.map +1 -0
  80. package/{dist/cjs/error.js → error.js} +23 -7
  81. package/error.js.map +1 -0
  82. package/error.mjs +120 -0
  83. package/error.mjs.map +1 -0
  84. package/index.d.mts +163 -0
  85. package/index.d.ts +163 -0
  86. package/index.d.ts.map +1 -0
  87. package/{dist/cjs/index.js → index.js} +62 -21
  88. package/index.js.map +1 -0
  89. package/index.mjs +118 -0
  90. package/index.mjs.map +1 -0
  91. package/package.json +60 -24
  92. package/pagination.d.ts +21 -0
  93. package/pagination.d.ts.map +1 -0
  94. package/pagination.js +31 -0
  95. package/pagination.js.map +1 -0
  96. package/pagination.mjs +27 -0
  97. package/pagination.mjs.map +1 -0
  98. package/{dist/cjs/resource.d.ts → resource.d.ts} +1 -1
  99. package/resource.d.ts.map +1 -0
  100. package/resource.js.map +1 -0
  101. package/resource.mjs +13 -0
  102. package/resource.mjs.map +1 -0
  103. package/resources/audio/audio.d.ts +17 -0
  104. package/resources/audio/audio.d.ts.map +1 -0
  105. package/resources/audio/audio.js +61 -0
  106. package/resources/audio/audio.js.map +1 -0
  107. package/resources/audio/audio.mjs +17 -0
  108. package/resources/audio/audio.mjs.map +1 -0
  109. package/resources/audio/index.d.ts +4 -0
  110. package/resources/audio/index.d.ts.map +1 -0
  111. package/resources/audio/index.js +26 -0
  112. package/resources/audio/index.js.map +1 -0
  113. package/resources/audio/index.mjs +5 -0
  114. package/resources/audio/index.mjs.map +1 -0
  115. package/{dist/cjs/resources → resources}/audio/transcriptions.d.ts +12 -10
  116. package/resources/audio/transcriptions.d.ts.map +1 -0
  117. package/{dist/cjs/resources → resources}/audio/transcriptions.js +4 -6
  118. package/resources/audio/transcriptions.js.map +1 -0
  119. package/resources/audio/transcriptions.mjs +13 -0
  120. package/resources/audio/transcriptions.mjs.map +1 -0
  121. package/{dist/cjs/resources → resources}/audio/translations.d.ts +12 -10
  122. package/resources/audio/translations.d.ts.map +1 -0
  123. package/{dist/cjs/resources → resources}/audio/translations.js +5 -7
  124. package/resources/audio/translations.js.map +1 -0
  125. package/resources/audio/translations.mjs +13 -0
  126. package/resources/audio/translations.mjs.map +1 -0
  127. package/resources/chat/chat.d.ts +17 -0
  128. package/resources/chat/chat.d.ts.map +1 -0
  129. package/resources/chat/chat.js +58 -0
  130. package/resources/chat/chat.js.map +1 -0
  131. package/resources/chat/chat.mjs +14 -0
  132. package/resources/chat/chat.mjs.map +1 -0
  133. package/resources/chat/completions.d.ts +338 -0
  134. package/resources/chat/completions.d.ts.map +1 -0
  135. package/{dist/cjs/resources → resources/chat}/completions.js +7 -7
  136. package/resources/chat/completions.js.map +1 -0
  137. package/resources/chat/completions.mjs +14 -0
  138. package/resources/chat/completions.mjs.map +1 -0
  139. package/resources/chat/index.d.ts +12 -0
  140. package/resources/chat/index.d.ts.map +1 -0
  141. package/resources/chat/index.js +19 -0
  142. package/resources/chat/index.js.map +1 -0
  143. package/resources/chat/index.mjs +4 -0
  144. package/resources/chat/index.mjs.map +1 -0
  145. package/resources/completions.d.ts +217 -0
  146. package/resources/completions.d.ts.map +1 -0
  147. package/{dist/cjs/resources/chat → resources}/completions.js +7 -7
  148. package/resources/completions.js.map +1 -0
  149. package/resources/completions.mjs +14 -0
  150. package/resources/completions.mjs.map +1 -0
  151. package/{dist/cjs/resources → resources}/edits.d.ts +18 -18
  152. package/resources/edits.d.ts.map +1 -0
  153. package/{dist/cjs/resources → resources}/edits.js +7 -2
  154. package/resources/edits.js.map +1 -0
  155. package/resources/edits.mjs +16 -0
  156. package/resources/edits.mjs.map +1 -0
  157. package/{dist/cjs/resources → resources}/embeddings.d.ts +9 -4
  158. package/resources/embeddings.d.ts.map +1 -0
  159. package/{dist/cjs/resources → resources}/embeddings.js +3 -2
  160. package/resources/embeddings.js.map +1 -0
  161. package/resources/embeddings.mjs +12 -0
  162. package/resources/embeddings.mjs.map +1 -0
  163. package/{dist/cjs/resources → resources}/files.d.ts +33 -24
  164. package/resources/files.d.ts.map +1 -0
  165. package/{dist/cjs/resources → resources}/files.js +19 -14
  166. package/resources/files.js.map +1 -0
  167. package/resources/files.mjs +51 -0
  168. package/resources/files.mjs.map +1 -0
  169. package/{dist/cjs/resources → resources}/fine-tunes.d.ts +87 -50
  170. package/resources/fine-tunes.d.ts.map +1 -0
  171. package/{dist/cjs/resources → resources}/fine-tunes.js +20 -13
  172. package/resources/fine-tunes.js.map +1 -0
  173. package/resources/fine-tunes.mjs +54 -0
  174. package/resources/fine-tunes.mjs.map +1 -0
  175. package/{dist/cjs/resources → resources}/images.d.ts +17 -12
  176. package/resources/images.d.ts.map +1 -0
  177. package/{dist/cjs/resources → resources}/images.js +6 -11
  178. package/resources/images.js.map +1 -0
  179. package/resources/images.mjs +25 -0
  180. package/resources/images.mjs.map +1 -0
  181. package/resources/index.d.ts +35 -0
  182. package/resources/index.d.ts.map +1 -0
  183. package/{dist/cjs/resources → resources}/index.js +38 -33
  184. package/resources/index.js.map +1 -0
  185. package/resources/index.mjs +12 -0
  186. package/resources/index.mjs.map +1 -0
  187. package/resources/models.d.ts +43 -0
  188. package/resources/models.d.ts.map +1 -0
  189. package/{dist/cjs/resources → resources}/models.js +10 -3
  190. package/resources/models.js.map +1 -0
  191. package/resources/models.mjs +31 -0
  192. package/resources/models.mjs.map +1 -0
  193. package/{dist/cjs/resources → resources}/moderations.d.ts +10 -4
  194. package/resources/moderations.d.ts.map +1 -0
  195. package/{dist/cjs/resources → resources}/moderations.js +3 -2
  196. package/resources/moderations.js.map +1 -0
  197. package/resources/moderations.mjs +12 -0
  198. package/resources/moderations.mjs.map +1 -0
  199. package/src/_shims/ReadableStream.d.ts +38 -0
  200. package/src/_shims/ReadableStream.js +5 -0
  201. package/src/_shims/ReadableStream.mjs +7 -0
  202. package/src/_shims/ReadableStream.node.ts +6 -0
  203. package/src/_shims/agent.node.ts +22 -0
  204. package/src/_shims/agent.ts +12 -0
  205. package/src/_shims/fetch.d.ts +59 -0
  206. package/src/_shims/fetch.deno.ts +23 -0
  207. package/src/_shims/fetch.js +13 -0
  208. package/src/_shims/fetch.mjs +15 -0
  209. package/src/_shims/fetch.node.d.ts +63 -0
  210. package/src/_shims/fetch.node.js +12 -0
  211. package/src/_shims/fetch.node.mjs +14 -0
  212. package/src/_shims/fileFromPath.node.ts +29 -0
  213. package/src/_shims/fileFromPath.ts +29 -0
  214. package/src/_shims/formdata.d.ts +43 -0
  215. package/src/_shims/formdata.deno.ts +16 -0
  216. package/src/_shims/formdata.js +9 -0
  217. package/src/_shims/formdata.mjs +11 -0
  218. package/src/_shims/formdata.node.d.ts +45 -0
  219. package/src/_shims/formdata.node.js +11 -0
  220. package/src/_shims/formdata.node.mjs +9 -0
  221. package/src/_shims/getMultipartRequestOptions.node.ts +25 -0
  222. package/src/_shims/getMultipartRequestOptions.ts +14 -0
  223. package/src/_shims/node-readable.node.ts +10 -0
  224. package/src/_shims/node-readable.ts +30 -0
  225. package/{core.ts → src/core.ts} +420 -193
  226. package/{error.ts → src/error.ts} +22 -5
  227. package/src/index.ts +246 -0
  228. package/src/pagination.ts +42 -0
  229. package/src/resources/audio/audio.ts +21 -0
  230. package/src/resources/audio/index.ts +5 -0
  231. package/{resources → src/resources}/audio/transcriptions.ts +13 -11
  232. package/{resources → src/resources}/audio/translations.ts +13 -11
  233. package/src/resources/chat/chat.ts +20 -0
  234. package/src/resources/chat/completions.ts +406 -0
  235. package/src/resources/chat/index.ts +13 -0
  236. package/src/resources/completions.ts +264 -0
  237. package/{resources → src/resources}/edits.ts +19 -23
  238. package/{resources → src/resources}/embeddings.ts +10 -4
  239. package/{resources → src/resources}/files.ts +40 -31
  240. package/{resources → src/resources}/fine-tunes.ts +102 -56
  241. package/{resources → src/resources}/images.ts +18 -13
  242. package/{resources → src/resources}/index.ts +14 -14
  243. package/src/resources/models.ts +62 -0
  244. package/{resources → src/resources}/moderations.ts +11 -4
  245. package/{streaming.ts → src/streaming.ts} +146 -79
  246. package/src/uploads.ts +250 -0
  247. package/src/version.ts +1 -0
  248. package/{dist/cjs/streaming.d.ts → streaming.d.ts} +4 -7
  249. package/streaming.d.ts.map +1 -0
  250. package/streaming.js +218 -0
  251. package/streaming.js.map +1 -0
  252. package/streaming.mjs +214 -0
  253. package/streaming.mjs.map +1 -0
  254. package/uploads.d.ts +91 -0
  255. package/uploads.d.ts.map +1 -0
  256. package/uploads.js +208 -0
  257. package/uploads.js.map +1 -0
  258. package/uploads.mjs +175 -0
  259. package/uploads.mjs.map +1 -0
  260. package/version.d.ts +2 -0
  261. package/version.d.ts.map +1 -0
  262. package/{dist/cjs/version.js → version.js} +1 -1
  263. package/version.js.map +1 -0
  264. package/version.mjs +2 -0
  265. package/version.mjs.map +1 -0
  266. package/.eslintrc.js +0 -10
  267. package/.github/ISSUE_TEMPLATE/bug_report.yml +0 -56
  268. package/.github/ISSUE_TEMPLATE/config.yml +0 -7
  269. package/.github/ISSUE_TEMPLATE/feature_request.yml +0 -20
  270. package/.github/workflows/test.yml +0 -24
  271. package/.prettierignore +0 -1
  272. package/.prettierrc +0 -6
  273. package/.stats.yml +0 -1
  274. package/api.md +0 -157
  275. package/bin/check-test-server +0 -50
  276. package/build +0 -12
  277. package/check-version.ts +0 -18
  278. package/dist/cjs/check-version.d.ts +0 -2
  279. package/dist/cjs/check-version.d.ts.map +0 -1
  280. package/dist/cjs/check-version.js +0 -23
  281. package/dist/cjs/check-version.js.map +0 -1
  282. package/dist/cjs/core.d.ts.map +0 -1
  283. package/dist/cjs/core.js +0 -854
  284. package/dist/cjs/core.js.map +0 -1
  285. package/dist/cjs/error.d.ts.map +0 -1
  286. package/dist/cjs/error.js.map +0 -1
  287. package/dist/cjs/examples/demo.d.ts +0 -3
  288. package/dist/cjs/examples/demo.d.ts.map +0 -1
  289. package/dist/cjs/examples/demo.js +0 -119
  290. package/dist/cjs/examples/demo.js.map +0 -1
  291. package/dist/cjs/examples/errors.d.ts +0 -3
  292. package/dist/cjs/examples/errors.d.ts.map +0 -1
  293. package/dist/cjs/examples/errors.js +0 -100
  294. package/dist/cjs/examples/errors.js.map +0 -1
  295. package/dist/cjs/examples/fine-tunes.d.ts +0 -10
  296. package/dist/cjs/examples/fine-tunes.d.ts.map +0 -1
  297. package/dist/cjs/examples/fine-tunes.js +0 -160
  298. package/dist/cjs/examples/fine-tunes.js.map +0 -1
  299. package/dist/cjs/fetch-polyfill.d.ts +0 -6
  300. package/dist/cjs/fetch-polyfill.d.ts.map +0 -1
  301. package/dist/cjs/fetch-polyfill.js +0 -57
  302. package/dist/cjs/fetch-polyfill.js.map +0 -1
  303. package/dist/cjs/index.d.ts +0 -100
  304. package/dist/cjs/index.d.ts.map +0 -1
  305. package/dist/cjs/index.js.map +0 -1
  306. package/dist/cjs/resource.d.ts.map +0 -1
  307. package/dist/cjs/resource.js.map +0 -1
  308. package/dist/cjs/resources/answers.d.ts +0 -150
  309. package/dist/cjs/resources/answers.d.ts.map +0 -1
  310. package/dist/cjs/resources/answers.js +0 -20
  311. package/dist/cjs/resources/answers.js.map +0 -1
  312. package/dist/cjs/resources/audio/audio.d.ts +0 -8
  313. package/dist/cjs/resources/audio/audio.d.ts.map +0 -1
  314. package/dist/cjs/resources/audio/audio.js +0 -16
  315. package/dist/cjs/resources/audio/audio.js.map +0 -1
  316. package/dist/cjs/resources/audio/index.d.ts +0 -3
  317. package/dist/cjs/resources/audio/index.d.ts.map +0 -1
  318. package/dist/cjs/resources/audio/index.js +0 -4
  319. package/dist/cjs/resources/audio/index.js.map +0 -1
  320. package/dist/cjs/resources/audio/transcriptions.d.ts.map +0 -1
  321. package/dist/cjs/resources/audio/transcriptions.js.map +0 -1
  322. package/dist/cjs/resources/audio/translations.d.ts.map +0 -1
  323. package/dist/cjs/resources/audio/translations.js.map +0 -1
  324. package/dist/cjs/resources/chat/chat.d.ts +0 -6
  325. package/dist/cjs/resources/chat/chat.d.ts.map +0 -1
  326. package/dist/cjs/resources/chat/chat.js +0 -14
  327. package/dist/cjs/resources/chat/chat.js.map +0 -1
  328. package/dist/cjs/resources/chat/completions.d.ts +0 -472
  329. package/dist/cjs/resources/chat/completions.d.ts.map +0 -1
  330. package/dist/cjs/resources/chat/completions.js.map +0 -1
  331. package/dist/cjs/resources/chat/index.d.ts +0 -2
  332. package/dist/cjs/resources/chat/index.d.ts.map +0 -1
  333. package/dist/cjs/resources/chat/index.js +0 -4
  334. package/dist/cjs/resources/chat/index.js.map +0 -1
  335. package/dist/cjs/resources/classifications.d.ts +0 -142
  336. package/dist/cjs/resources/classifications.d.ts.map +0 -1
  337. package/dist/cjs/resources/classifications.js +0 -24
  338. package/dist/cjs/resources/classifications.js.map +0 -1
  339. package/dist/cjs/resources/completions.d.ts +0 -313
  340. package/dist/cjs/resources/completions.d.ts.map +0 -1
  341. package/dist/cjs/resources/completions.js.map +0 -1
  342. package/dist/cjs/resources/edits.d.ts.map +0 -1
  343. package/dist/cjs/resources/edits.js.map +0 -1
  344. package/dist/cjs/resources/embeddings.d.ts.map +0 -1
  345. package/dist/cjs/resources/embeddings.js.map +0 -1
  346. package/dist/cjs/resources/files.d.ts.map +0 -1
  347. package/dist/cjs/resources/files.js.map +0 -1
  348. package/dist/cjs/resources/fine-tunes.d.ts.map +0 -1
  349. package/dist/cjs/resources/fine-tunes.js.map +0 -1
  350. package/dist/cjs/resources/images.d.ts.map +0 -1
  351. package/dist/cjs/resources/images.js.map +0 -1
  352. package/dist/cjs/resources/index.d.ts +0 -35
  353. package/dist/cjs/resources/index.d.ts.map +0 -1
  354. package/dist/cjs/resources/index.js.map +0 -1
  355. package/dist/cjs/resources/models.d.ts +0 -34
  356. package/dist/cjs/resources/models.d.ts.map +0 -1
  357. package/dist/cjs/resources/models.js.map +0 -1
  358. package/dist/cjs/resources/moderations.d.ts.map +0 -1
  359. package/dist/cjs/resources/moderations.js.map +0 -1
  360. package/dist/cjs/streaming.d.ts.map +0 -1
  361. package/dist/cjs/streaming.js +0 -287
  362. package/dist/cjs/streaming.js.map +0 -1
  363. package/dist/cjs/tests/api-resources/answers.test.d.ts +0 -2
  364. package/dist/cjs/tests/api-resources/answers.test.d.ts.map +0 -1
  365. package/dist/cjs/tests/api-resources/answers.test.js +0 -279
  366. package/dist/cjs/tests/api-resources/answers.test.js.map +0 -1
  367. package/dist/cjs/tests/api-resources/audio/transcriptions.test.d.ts +0 -2
  368. package/dist/cjs/tests/api-resources/audio/transcriptions.test.d.ts.map +0 -1
  369. package/dist/cjs/tests/api-resources/audio/transcriptions.test.js +0 -65
  370. package/dist/cjs/tests/api-resources/audio/transcriptions.test.js.map +0 -1
  371. package/dist/cjs/tests/api-resources/audio/translations.test.d.ts +0 -2
  372. package/dist/cjs/tests/api-resources/audio/translations.test.d.ts.map +0 -1
  373. package/dist/cjs/tests/api-resources/audio/translations.test.js +0 -64
  374. package/dist/cjs/tests/api-resources/audio/translations.test.js.map +0 -1
  375. package/dist/cjs/tests/api-resources/chat/completions.test.d.ts +0 -2
  376. package/dist/cjs/tests/api-resources/chat/completions.test.d.ts.map +0 -1
  377. package/dist/cjs/tests/api-resources/chat/completions.test.js +0 -77
  378. package/dist/cjs/tests/api-resources/chat/completions.test.js.map +0 -1
  379. package/dist/cjs/tests/api-resources/classifications.test.d.ts +0 -2
  380. package/dist/cjs/tests/api-resources/classifications.test.d.ts.map +0 -1
  381. package/dist/cjs/tests/api-resources/classifications.test.js +0 -73
  382. package/dist/cjs/tests/api-resources/classifications.test.js.map +0 -1
  383. package/dist/cjs/tests/api-resources/completions.test.d.ts +0 -2
  384. package/dist/cjs/tests/api-resources/completions.test.d.ts.map +0 -1
  385. package/dist/cjs/tests/api-resources/completions.test.js +0 -69
  386. package/dist/cjs/tests/api-resources/completions.test.js.map +0 -1
  387. package/dist/cjs/tests/api-resources/edits.test.d.ts +0 -2
  388. package/dist/cjs/tests/api-resources/edits.test.d.ts.map +0 -1
  389. package/dist/cjs/tests/api-resources/edits.test.js +0 -62
  390. package/dist/cjs/tests/api-resources/edits.test.js.map +0 -1
  391. package/dist/cjs/tests/api-resources/embeddings.test.d.ts +0 -2
  392. package/dist/cjs/tests/api-resources/embeddings.test.d.ts.map +0 -1
  393. package/dist/cjs/tests/api-resources/embeddings.test.js +0 -59
  394. package/dist/cjs/tests/api-resources/embeddings.test.js.map +0 -1
  395. package/dist/cjs/tests/api-resources/files.test.d.ts +0 -2
  396. package/dist/cjs/tests/api-resources/files.test.d.ts.map +0 -1
  397. package/dist/cjs/tests/api-resources/files.test.js +0 -107
  398. package/dist/cjs/tests/api-resources/files.test.js.map +0 -1
  399. package/dist/cjs/tests/api-resources/fine-tunes.test.d.ts +0 -2
  400. package/dist/cjs/tests/api-resources/fine-tunes.test.d.ts.map +0 -1
  401. package/dist/cjs/tests/api-resources/fine-tunes.test.js +0 -115
  402. package/dist/cjs/tests/api-resources/fine-tunes.test.js.map +0 -1
  403. package/dist/cjs/tests/api-resources/images.test.d.ts +0 -2
  404. package/dist/cjs/tests/api-resources/images.test.d.ts.map +0 -1
  405. package/dist/cjs/tests/api-resources/images.test.js +0 -100
  406. package/dist/cjs/tests/api-resources/images.test.js.map +0 -1
  407. package/dist/cjs/tests/api-resources/models.test.d.ts +0 -2
  408. package/dist/cjs/tests/api-resources/models.test.d.ts.map +0 -1
  409. package/dist/cjs/tests/api-resources/models.test.js +0 -77
  410. package/dist/cjs/tests/api-resources/models.test.js.map +0 -1
  411. package/dist/cjs/tests/api-resources/moderations.test.d.ts +0 -2
  412. package/dist/cjs/tests/api-resources/moderations.test.d.ts.map +0 -1
  413. package/dist/cjs/tests/api-resources/moderations.test.js +0 -55
  414. package/dist/cjs/tests/api-resources/moderations.test.js.map +0 -1
  415. package/dist/cjs/tests/form.test.d.ts +0 -2
  416. package/dist/cjs/tests/form.test.d.ts.map +0 -1
  417. package/dist/cjs/tests/form.test.js +0 -61
  418. package/dist/cjs/tests/form.test.js.map +0 -1
  419. package/dist/cjs/tests/index.test.d.ts +0 -2
  420. package/dist/cjs/tests/index.test.d.ts.map +0 -1
  421. package/dist/cjs/tests/index.test.js +0 -75
  422. package/dist/cjs/tests/index.test.js.map +0 -1
  423. package/dist/cjs/tests/responses.test.d.ts +0 -2
  424. package/dist/cjs/tests/responses.test.d.ts.map +0 -1
  425. package/dist/cjs/tests/responses.test.js +0 -60
  426. package/dist/cjs/tests/responses.test.js.map +0 -1
  427. package/dist/cjs/version.d.ts +0 -2
  428. package/dist/cjs/version.d.ts.map +0 -1
  429. package/dist/cjs/version.js.map +0 -1
  430. package/examples/demo.ts +0 -28
  431. package/examples/errors.ts +0 -28
  432. package/examples/fine-tune-data.jsonl +0 -3
  433. package/examples/fine-tunes.ts +0 -37
  434. package/fetch-polyfill.ts +0 -69
  435. package/index.ts +0 -157
  436. package/jest.config.js +0 -8
  437. package/resources/answers.ts +0 -180
  438. package/resources/audio/audio.ts +0 -10
  439. package/resources/audio/index.ts +0 -4
  440. package/resources/chat/chat.ts +0 -8
  441. package/resources/chat/completions.ts +0 -559
  442. package/resources/chat/index.ts +0 -3
  443. package/resources/classifications.ts +0 -169
  444. package/resources/completions.ts +0 -371
  445. package/resources/models.ts +0 -53
  446. package/tests/api-resources/answers.test.ts +0 -242
  447. package/tests/api-resources/audio/transcriptions.test.ts +0 -28
  448. package/tests/api-resources/audio/translations.test.ts +0 -27
  449. package/tests/api-resources/chat/completions.test.ts +0 -40
  450. package/tests/api-resources/classifications.test.ts +0 -36
  451. package/tests/api-resources/completions.test.ts +0 -32
  452. package/tests/api-resources/edits.test.ts +0 -25
  453. package/tests/api-resources/embeddings.test.ts +0 -22
  454. package/tests/api-resources/files.test.ts +0 -64
  455. package/tests/api-resources/fine-tunes.test.ts +0 -78
  456. package/tests/api-resources/images.test.ts +0 -61
  457. package/tests/api-resources/models.test.ts +0 -40
  458. package/tests/api-resources/moderations.test.ts +0 -18
  459. package/tests/form.test.ts +0 -27
  460. package/tests/index.test.ts +0 -76
  461. package/tests/responses.test.ts +0 -25
  462. package/tsconfig.cjs.json +0 -8
  463. package/tsconfig.json +0 -39
  464. package/typings/digest-fetch/index.d.ts +0 -33
  465. package/version.ts +0 -1
  466. /package/{dist/cjs/resource.js → resource.js} +0 -0
  467. /package/{resource.ts → src/resource.ts} +0 -0
package/README.md CHANGED
@@ -2,12 +2,9 @@
2
2
 
3
3
  [![NPM version](https://img.shields.io/npm/v/openai.svg)](https://npmjs.org/package/openai)
4
4
 
5
- The OpenAI Node library provides convenient access to the OpenAI REST API from applications written in server-side JavaScript.
6
- It includes TypeScript definitions for all request params and response fields.
5
+ This library provides convenient access to the OpenAI REST API from TypeScript or JavaScript.
7
6
 
8
- > ⚠️ **Important note: this library is meant for server-side usage only, as using it in client-side browser code will expose your secret API key. [See here](https://platform.openai.com/docs/api-reference/authentication) for more details.**
9
-
10
- ## Documentation
7
+ It is generated from our [OpenAPI specification](https://github.com/openai/openai-openapi) with [Stainless](https://stainlessapi.com/).
11
8
 
12
9
  To learn how to use the OpenAI API, check out our [API Reference](https://platform.openai.com/docs/api-reference) and [Documentation](https://platform.openai.com/docs).
13
10
 
@@ -21,24 +18,26 @@ yarn add openai
21
18
 
22
19
  ## Usage
23
20
 
21
+ > [!IMPORTANT]
22
+ > Previous versions of this SDK used a `Configuration` class. See the [v3 to v4 migration guide](https://github.com/openai/openai-node/discussions/217).
23
+
24
24
  ```js
25
25
  import OpenAI from 'openai';
26
26
 
27
- const openAI = new OpenAI({
27
+ const openai = new OpenAI({
28
28
  apiKey: 'my api key', // defaults to process.env["OPENAI_API_KEY"]
29
29
  });
30
30
 
31
31
  async function main() {
32
- const completion = await openAI.completions.create({
33
- model: 'text-davinci-002',
34
- prompt: 'Say this is a test',
35
- max_tokens: 6,
36
- temperature: 0,
32
+ const completion = await openai.chat.completions.create({
33
+ messages: [{ role: 'user', content: 'Say this is a test' }],
34
+ model: 'gpt-3.5-turbo',
37
35
  });
38
36
 
39
37
  console.log(completion.choices);
40
38
  }
41
- main().catch(console.error);
39
+
40
+ main();
42
41
  ```
43
42
 
44
43
  ## Streaming Responses
@@ -48,60 +47,83 @@ We provide support for streaming responses using Server Side Events (SSE).
48
47
  ```ts
49
48
  import OpenAI from 'openai';
50
49
 
51
- const client = new OpenAI();
50
+ const openai = new OpenAI();
52
51
 
53
- const stream = await client.completions.create({
54
- prompt: 'Say this is a test',
55
- model: 'text-davinci-003',
56
- stream: true,
57
- });
58
- for await (const part of stream) {
59
- process.stdout.write(part.choices[0]?.text || '');
52
+ async function main() {
53
+ const stream = await openai.chat.completions.create({
54
+ model: 'gpt-4',
55
+ messages: [{ role: 'user', content: 'Say this is a test' }],
56
+ stream: true,
57
+ });
58
+ for await (const part of stream) {
59
+ process.stdout.write(part.choices[0]?.delta?.content || '');
60
+ }
60
61
  }
62
+
63
+ main();
61
64
  ```
62
65
 
63
66
  If you need to cancel a stream, you can `break` from the loop
64
67
  or call `stream.controller.abort()`.
65
68
 
66
- ### Usage with TypeScript
69
+ ### Request & Response types
67
70
 
68
- Importing, instantiating, and interacting with the library are the same as above.
69
- If you like, you may reference our types directly:
71
+ This library includes TypeScript definitions for all request params and response fields. You may import and use them like so:
70
72
 
71
73
  ```ts
72
74
  import OpenAI from 'openai';
73
75
 
74
- const openAI = new OpenAI({
76
+ const openai = new OpenAI({
75
77
  apiKey: 'my api key', // defaults to process.env["OPENAI_API_KEY"]
76
78
  });
77
79
 
78
80
  async function main() {
79
- const params: OpenAI.CompletionCreateParams = {
80
- model: 'text-davinci-002',
81
- prompt: 'Say this is a test',
82
- max_tokens: 6,
83
- temperature: 0,
81
+ const params: OpenAI.Chat.CompletionCreateParams = {
82
+ messages: [{ role: 'user', content: 'Say this is a test' }],
83
+ model: 'gpt-3.5-turbo',
84
84
  };
85
- const completion: OpenAI.Completion = await openAI.completions.create(params);
85
+ const completion: OpenAI.Chat.ChatCompletion = await openai.chat.completions.create(params);
86
86
  }
87
- main().catch(console.error);
87
+
88
+ main();
88
89
  ```
89
90
 
90
91
  Documentation for each method, request param, and response field are available in docstrings and will appear on hover in most modern editors.
91
92
 
92
93
  ## File Uploads
93
94
 
94
- Request parameters that correspond to file uploads can be passed as either a `FormData.Blob` or a `FormData.File` instance.
95
+ Request parameters that correspond to file uploads can be passed in many different forms:
95
96
 
96
- We provide a `fileFromPath` helper function to easily create `FormData.File` instances from a given class.
97
+ - `File` (or an object with the same structure)
98
+ - a `fetch` `Response` (or an object with the same structure)
99
+ - an `fs.ReadStream`
100
+ - the return value of our `toFile` helper
97
101
 
98
102
  ```ts
99
- import OpenAI, { fileFromPath } from 'openai';
103
+ import fs from 'fs';
104
+ import fetch from 'node-fetch';
105
+ import OpenAI, { toFile } from 'openai';
106
+
107
+ const openai = new OpenAI();
100
108
 
101
- const openAI = new OpenAI();
109
+ // If you have access to Node `fs` we recommend using `fs.createReadStream()`:
110
+ await openai.files.create({ file: fs.createReadStream('input.jsonl'), purpose: 'fine-tune' });
102
111
 
103
- const file = await fileFromPath('input.jsonl');
104
- await openAI.files.create({ file: file, purpose: 'fine-tune' });
112
+ // Or if you have the web `File` API you can pass a `File` instance:
113
+ await openai.files.create({ file: new File(['my bytes'], 'input.jsonl'), purpose: 'fine-tune' });
114
+
115
+ // You can also pass a `fetch` `Response`:
116
+ await openai.files.create({ file: await fetch('https://somesite/input.jsonl'), purpose: 'fine-tune' });
117
+
118
+ // Finally, if none of the above are convenient, you can use our `toFile` helper:
119
+ await openai.files.create({
120
+ file: await toFile(Buffer.from('my bytes'), 'input.jsonl'),
121
+ purpose: 'fine-tune',
122
+ });
123
+ await openai.files.create({
124
+ file: await toFile(new Uint8Array([0, 1, 2]), 'input.jsonl'),
125
+ purpose: 'fine-tune',
126
+ });
105
127
  ```
106
128
 
107
129
  ## Handling errors
@@ -112,7 +134,7 @@ a subclass of `APIError` will be thrown:
112
134
 
113
135
  ```ts
114
136
  async function main() {
115
- const fineTune = await openAI.fineTunes
137
+ const fineTune = await openai.fineTunes
116
138
  .create({ training_file: 'file-XGinujblHPwGLSztz8cPS8XY' })
117
139
  .catch((err) => {
118
140
  if (err instanceof OpenAI.APIError) {
@@ -120,10 +142,13 @@ async function main() {
120
142
  console.log(err.name); // BadRequestError
121
143
 
122
144
  console.log(err.headers); // {server: 'nginx', ...}
145
+ } else {
146
+ throw err;
123
147
  }
124
148
  });
125
149
  }
126
- main().catch(console.error);
150
+
151
+ main();
127
152
  ```
128
153
 
129
154
  Error codes are as followed:
@@ -150,12 +175,12 @@ You can use the `maxRetries` option to configure or disable this:
150
175
  <!-- prettier-ignore -->
151
176
  ```js
152
177
  // Configure the default for all requests:
153
- const openAI = new OpenAI({
178
+ const openai = new OpenAI({
154
179
  maxRetries: 0, // default is 2
155
180
  });
156
181
 
157
182
  // Or, configure per-request:
158
- openAI.embeddings.create({ model: 'text-similarity-babbage-001',input: 'The food was delicious and the waiter...' }, {
183
+ await openai.chat.completions.create({ messages: [{ role: 'user', content: 'How can I get the name of the current day in Node.js?' }], model: 'gpt-3.5-turbo' }, {
159
184
  maxRetries: 5,
160
185
  });
161
186
  ```
@@ -167,12 +192,12 @@ Requests time out after 60 seconds by default. You can configure this with a `ti
167
192
  <!-- prettier-ignore -->
168
193
  ```ts
169
194
  // Configure the default for all requests:
170
- const openAI = new OpenAI({
195
+ const openai = new OpenAI({
171
196
  timeout: 20 * 1000, // 20 seconds (default is 60s)
172
197
  });
173
198
 
174
199
  // Override per-request:
175
- openAI.edits.create({ model: 'text-davinci-edit-001',input: 'What day of the wek is it?',instruction: 'Fix the spelling mistakes' }, {
200
+ await openai.chat.completions.create({ messages: [{ role: 'user', content: 'How can I list all files in a directory using Python?' }], model: 'gpt-3.5-turbo' }, {
176
201
  timeout: 5 * 1000,
177
202
  });
178
203
  ```
@@ -181,6 +206,30 @@ On timeout, an `APIConnectionTimeoutError` is thrown.
181
206
 
182
207
  Note that requests which time out will be [retried twice by default](#retries).
183
208
 
209
+ ## Advanced Usage
210
+
211
+ ### Accessing raw Response data (e.g., headers)
212
+
213
+ The "raw" `Response` returned by `fetch()` can be accessed through the `.asResponse()` method on the `APIPromise` type that all methods return.
214
+
215
+ You can also use the `.withResponse()` method to get the raw `Response` along with the parsed data.
216
+
217
+ ```ts
218
+ const openai = new OpenAI();
219
+
220
+ const response = await openai.chat.completions
221
+ .create({ messages: [{ role: 'user', content: 'Say this is a test' }], model: 'gpt-3.5-turbo' })
222
+ .asResponse();
223
+ console.log(response.headers.get('X-My-Header'));
224
+ console.log(response.statusText); // access the underlying Response object
225
+
226
+ const { data: completions, response: raw } = await openai.chat.completions
227
+ .create({ messages: [{ role: 'user', content: 'Say this is a test' }], model: 'gpt-3.5-turbo' })
228
+ .withResponse();
229
+ console.log(raw.headers.get('X-My-Header'));
230
+ console.log(completions.choices);
231
+ ```
232
+
184
233
  ## Configuring an HTTP(S) Agent (e.g., for proxies)
185
234
 
186
235
  By default, this library uses a stable agent for all http/https requests to reuse TCP connections, eliminating many TCP & TLS handshakes and shaving around 100ms off most requests.
@@ -193,22 +242,26 @@ import http from 'http';
193
242
  import HttpsProxyAgent from 'https-proxy-agent';
194
243
 
195
244
  // Configure the default for all requests:
196
- const openAI = new OpenAI({
245
+ const openai = new OpenAI({
197
246
  httpAgent: new HttpsProxyAgent(process.env.PROXY_URL),
198
247
  });
199
248
 
200
249
  // Override per-request:
201
- openAI.models.list({
250
+ await openai.models.list({
202
251
  baseURL: 'http://localhost:8080/test-api',
203
252
  httpAgent: new http.Agent({ keepAlive: false }),
204
253
  })
205
254
  ```
206
255
 
207
- ## Status
256
+ ## Semantic Versioning
257
+
258
+ This package generally attempts to follow [SemVer](https://semver.org/spec/v2.0.0.html) conventions, though certain backwards-incompatible changes may be released as minor versions:
259
+
260
+ 1. Changes that only affect static types, without breaking runtime behavior.
261
+ 2. Changes to library internals which are technically public but not intended or documented for external use. _(Please open a GitHub issue to let us know if you are relying on such internals)_.
262
+ 3. Changes that we do not expect to impact the vast majority of users in practice.
208
263
 
209
- This package is in beta. Its internals and interfaces are not stable
210
- and subject to change without a major semver bump;
211
- please reach out if you rely on any undocumented behavior.
264
+ We take backwards-compatibility seriously and work hard to ensure you can rely on a smooth upgrade experience.
212
265
 
213
266
  We are keen for your feedback; please open an [issue](https://www.github.com/openai/openai-node/issues) with questions, bugs, or suggestions.
214
267
 
@@ -216,8 +269,10 @@ We are keen for your feedback; please open an [issue](https://www.github.com/ope
216
269
 
217
270
  The following runtimes are supported:
218
271
 
219
- - Node.js version 12 or higher.
220
- - Deno v1.28.0 or higher (experimental).
221
- Use `import OpenAI from "npm:openai"`.
272
+ - Node.js 16 LTS or later ([non-EOL](https://endoflife.date/nodejs)) versions.
273
+ - Deno v1.28.0 or higher, using `import OpenAI from "npm:openai"`.
274
+ Deno Deploy is not yet supported.
275
+ - Cloudflare Workers.
276
+ - Vercel Edge Runtime.
222
277
 
223
278
  If you are interested in other runtime environments, please open or upvote an issue on GitHub.
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
3
+ */
4
+
5
+ /**
6
+ * >>> Confused? <<<
7
+ *
8
+ * If you're getting errors from these types, try adding "lib": ["DOM"]
9
+ * to your tsconfig.json, or otherwise configure the appropriate builtin
10
+ * `ReadableStream` type for your environment.
11
+ */
12
+
13
+ // @ts-ignore
14
+ type _ReadableStream<R = any> = unknown extends ReadableStream ? never : ReadableStream<R>;
15
+ declare const _ReadableStream: {
16
+ prototype: _ReadableStream;
17
+ new (
18
+ underlyingSource: _UnderlyingByteSource,
19
+ strategy?: { highWaterMark?: number },
20
+ ): _ReadableStream<Uint8Array>;
21
+ new <R = any>(
22
+ underlyingSource: _UnderlyingDefaultSource<R>,
23
+ strategy?: _QueuingStrategy<R>,
24
+ ): _ReadableStream<R>;
25
+ new <R = any>(underlyingSource?: _UnderlyingSource<R>, strategy?: _QueuingStrategy<R>): _ReadableStream<R>;
26
+ };
27
+
28
+ // @ts-ignore
29
+ type _UnderlyingSource<R = any> = unknown extends UnderlyingSource ? never : UnderlyingSource<R>;
30
+ // @ts-ignore
31
+ type _UnderlyingByteSource = unknown extends UnderlyingByteSource ? never : UnderlyingByteSource;
32
+ type _UnderlyingDefaultSource<R = any> =
33
+ // @ts-ignore
34
+ unknown extends UnderlyingDefaultSource ? never : UnderlyingDefaultSource<R>;
35
+ // @ts-ignore
36
+ type _QueuingStrategy<R = any> = unknown extends QueuingStrategy ? never : QueuingStrategy<R>;
37
+
38
+ export { _ReadableStream as ReadableStream };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
3
+ */
4
+
5
+ exports.ReadableStream = ReadableStream;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
3
+ */
4
+
5
+ const _ReadableStream = ReadableStream;
6
+
7
+ export { _ReadableStream as ReadableStream };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
3
+ */
4
+ import { ReadableStream } from 'web-streams-polyfill';
5
+ export { ReadableStream };
6
+ //# sourceMappingURL=ReadableStream.node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReadableStream.node.d.ts","sourceRoot":"","sources":["../src/_shims/ReadableStream.node.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,OAAO,EAAE,cAAc,EAAE,CAAC"}
@@ -0,0 +1,14 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, '__esModule', { value: true });
3
+ exports.ReadableStream = void 0;
4
+ /**
5
+ * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
6
+ */
7
+ const web_streams_polyfill_1 = require('web-streams-polyfill');
8
+ Object.defineProperty(exports, 'ReadableStream', {
9
+ enumerable: true,
10
+ get: function () {
11
+ return web_streams_polyfill_1.ReadableStream;
12
+ },
13
+ });
14
+ //# sourceMappingURL=ReadableStream.node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReadableStream.node.js","sourceRoot":"","sources":["../src/_shims/ReadableStream.node.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,+DAAsD;AAE7C,+FAFA,qCAAc,OAEA"}
@@ -0,0 +1,3 @@
1
+ import { ReadableStream } from 'web-streams-polyfill';
2
+ export { ReadableStream };
3
+ //# sourceMappingURL=ReadableStream.node.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReadableStream.node.mjs","sourceRoot":"","sources":["../src/_shims/ReadableStream.node.ts"],"names":[],"mappings":"OAGO,EAAE,cAAc,EAAE,MAAM,sBAAsB;AAErD,OAAO,EAAE,cAAc,EAAE,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
3
+ *
4
+ * This is a stub for non-node environments.
5
+ * In node environments, it gets replaced agent.node.ts by the package export map
6
+ */
7
+ export type Agent = any;
8
+ export declare const getDefaultAgent: (url: string) => any;
9
+ //# sourceMappingURL=agent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/_shims/agent.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,MAAM,KAAK,GAAG,GAAG,CAAC;AAExB,eAAO,MAAM,eAAe,QAAS,MAAM,KAAG,GAE7C,CAAC"}
@@ -0,0 +1,14 @@
1
+ 'use strict';
2
+ /**
3
+ * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
4
+ *
5
+ * This is a stub for non-node environments.
6
+ * In node environments, it gets replaced agent.node.ts by the package export map
7
+ */
8
+ Object.defineProperty(exports, '__esModule', { value: true });
9
+ exports.getDefaultAgent = void 0;
10
+ const getDefaultAgent = (url) => {
11
+ return undefined;
12
+ };
13
+ exports.getDefaultAgent = getDefaultAgent;
14
+ //# sourceMappingURL=agent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent.js","sourceRoot":"","sources":["../src/_shims/agent.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAII,MAAM,eAAe,GAAG,CAAC,GAAW,EAAO,EAAE;IAClD,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAFW,QAAA,eAAe,mBAE1B"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
3
+ *
4
+ * This is a stub for non-node environments.
5
+ * In node environments, it gets replaced agent.node.ts by the package export map
6
+ */
7
+ export const getDefaultAgent = (url) => {
8
+ return undefined;
9
+ };
10
+ //# sourceMappingURL=agent.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent.mjs","sourceRoot":"","sources":["../src/_shims/agent.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,GAAW,EAAO,EAAE;IAClD,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
3
+ */
4
+ import type { Agent } from 'node:http';
5
+ export type { Agent };
6
+ export declare const getDefaultAgent: (url: string) => Agent | undefined;
7
+ //# sourceMappingURL=agent.node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent.node.d.ts","sourceRoot":"","sources":["../src/_shims/agent.node.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAGvC,YAAY,EAAE,KAAK,EAAE,CAAC;AAUtB,eAAO,MAAM,eAAe,QAAS,MAAM,KAAG,KAAK,GAAG,SAGrD,CAAC"}
@@ -0,0 +1,28 @@
1
+ 'use strict';
2
+ /**
3
+ * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
4
+ */
5
+ var __importDefault =
6
+ (this && this.__importDefault) ||
7
+ function (mod) {
8
+ return mod && mod.__esModule ? mod : { default: mod };
9
+ };
10
+ Object.defineProperty(exports, '__esModule', { value: true });
11
+ exports.getDefaultAgent = void 0;
12
+ const agentkeepalive_1 = __importDefault(require('agentkeepalive'));
13
+ const abort_controller_1 = require('abort-controller');
14
+ const defaultHttpAgent = new agentkeepalive_1.default({ keepAlive: true, timeout: 5 * 60 * 1000 });
15
+ const defaultHttpsAgent = new agentkeepalive_1.default.HttpsAgent({
16
+ keepAlive: true,
17
+ timeout: 5 * 60 * 1000,
18
+ });
19
+ // Polyfill global object if needed.
20
+ if (typeof AbortController === 'undefined') {
21
+ AbortController = abort_controller_1.AbortController;
22
+ }
23
+ const getDefaultAgent = (url) => {
24
+ if (defaultHttpsAgent && url.startsWith('https')) return defaultHttpsAgent;
25
+ return defaultHttpAgent;
26
+ };
27
+ exports.getDefaultAgent = getDefaultAgent;
28
+ //# sourceMappingURL=agent.node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent.node.js","sourceRoot":"","sources":["../src/_shims/agent.node.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;AAEH,oEAA4C;AAE5C,uDAA8E;AAI9E,MAAM,gBAAgB,GAAU,IAAI,wBAAc,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC;AAChG,MAAM,iBAAiB,GAAU,IAAI,wBAAc,CAAC,UAAU,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC;AAE5G,oCAAoC;AACpC,IAAI,OAAO,eAAe,KAAK,WAAW,EAAE;IAC1C,eAAe,GAAG,kCAAwD,CAAC;CAC5E;AAEM,MAAM,eAAe,GAAG,CAAC,GAAW,EAAqB,EAAE;IAChE,IAAI,iBAAiB,IAAI,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC;QAAE,OAAO,iBAAiB,CAAC;IAC3E,OAAO,gBAAgB,CAAC;AAC1B,CAAC,CAAC;AAHW,QAAA,eAAe,mBAG1B"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
3
+ */
4
+ import KeepAliveAgent from 'agentkeepalive';
5
+ import { AbortController as AbortControllerPolyfill } from 'abort-controller';
6
+ const defaultHttpAgent = new KeepAliveAgent({ keepAlive: true, timeout: 5 * 60 * 1000 });
7
+ const defaultHttpsAgent = new KeepAliveAgent.HttpsAgent({ keepAlive: true, timeout: 5 * 60 * 1000 });
8
+ // Polyfill global object if needed.
9
+ if (typeof AbortController === 'undefined') {
10
+ AbortController = AbortControllerPolyfill;
11
+ }
12
+ export const getDefaultAgent = (url) => {
13
+ if (defaultHttpsAgent && url.startsWith('https')) return defaultHttpsAgent;
14
+ return defaultHttpAgent;
15
+ };
16
+ //# sourceMappingURL=agent.node.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent.node.mjs","sourceRoot":"","sources":["../src/_shims/agent.node.ts"],"names":[],"mappings":"AAAA;;GAEG;OAEI,cAAc,MAAM,gBAAgB;OAEpC,EAAE,eAAe,IAAI,uBAAuB,EAAE,MAAM,kBAAkB;AAI7E,MAAM,gBAAgB,GAAU,IAAI,cAAc,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC;AAChG,MAAM,iBAAiB,GAAU,IAAI,cAAc,CAAC,UAAU,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC;AAE5G,oCAAoC;AACpC,IAAI,OAAO,eAAe,KAAK,WAAW,EAAE;IAC1C,eAAe,GAAG,uBAAwD,CAAC;CAC5E;AAED,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,GAAW,EAAqB,EAAE;IAChE,IAAI,iBAAiB,IAAI,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC;QAAE,OAAO,iBAAiB,CAAC;IAC3E,OAAO,gBAAgB,CAAC;AAC1B,CAAC,CAAC"}
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
3
+ */
4
+
5
+ // Use builtin web types if present; else never (user should
6
+ // add appropriate lib or types to tsconfig)
7
+
8
+ /**
9
+ * >>> Confused? <<<
10
+ *
11
+ * If you're getting errors from these types, try adding "lib": ["DOM"]
12
+ * to your tsconfig.json, or otherwise configure the appropriate builtin
13
+ * `fetch` types for your environment.
14
+ */
15
+
16
+ // @ts-ignore
17
+ type _fetch = unknown extends typeof fetch ? never : typeof fetch;
18
+ // @ts-ignore
19
+ type _Request = unknown extends Request ? never : Request;
20
+ // @ts-ignore
21
+ type _RequestInfo = unknown extends RequestInfo ? never : RequestInfo;
22
+ // @ts-ignore
23
+ type _RequestInit = unknown extends RequestInit ? never : RequestInit;
24
+ // @ts-ignore
25
+ type _Response = unknown extends Response ? never : Response;
26
+ // @ts-ignore
27
+ type _ResponseInit = unknown extends ResponseInit ? never : ResponseInit;
28
+ // @ts-ignore
29
+ type _ResponseType = unknown extends ResponseType ? never : ResponseType;
30
+ // @ts-ignore
31
+ type _BodyInit = unknown extends BodyInit ? never : BodyInit;
32
+ // @ts-ignore
33
+ type _Headers = unknown extends Headers ? never : Headers;
34
+ // @ts-ignore
35
+ type _HeadersInit = unknown extends HeadersInit ? never : HeadersInit;
36
+
37
+ declare const _fetch: _fetch;
38
+ declare const _Request: {
39
+ prototype: _Request;
40
+ new (input: _RequestInfo | URL, init?: _RequestInit): _Request;
41
+ };
42
+ declare const _Response: {
43
+ prototype: _Response;
44
+ new (body?: _BodyInit | null, init?: _ResponseInit): _Response;
45
+ };
46
+ declare const _Headers: {
47
+ prototype: _Headers;
48
+ new (init?: _HeadersInit): _Headers;
49
+ };
50
+
51
+ export const isPolyfilled = false;
52
+
53
+ export { _fetch as fetch, _Request as Request, _Response as Response, _Headers as Headers };
54
+ export type {
55
+ _RequestInit as RequestInit,
56
+ _RequestInfo as RequestInfo,
57
+ _ResponseType as ResponseType,
58
+ _BodyInit as BodyInit,
59
+ };
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
3
+ */
4
+
5
+ // If we accidentally call fetch with the wrong this binding,
6
+ // in the browser it would throw:
7
+ // TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
8
+ exports.fetch = fetch.bind(undefined);
9
+ exports.Request = Request;
10
+ exports.Response = Response;
11
+ exports.Headers = Headers;
12
+
13
+ exports.isPolyfilled = false;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
3
+ */
4
+
5
+ // If we accidentally call fetch with the wrong this binding,
6
+ // in the browser it would throw:
7
+ // TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
8
+ const _fetch = fetch.bind(undefined);
9
+ const _Request = Request;
10
+ const _Response = Response;
11
+ const _Headers = Headers;
12
+
13
+ export const isPolyfilled = false;
14
+
15
+ export { _fetch as fetch, _Request as Request, _Response as Response, _Headers as Headers };
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
3
+ */
4
+
5
+ import * as nf from 'node-fetch';
6
+
7
+ // Use builtin web types if present; else node-fetch types
8
+
9
+ /**
10
+ * >>> Confused? <<<
11
+ *
12
+ * If you're getting errors from these types, try adding "lib": ["DOM"]
13
+ * to your tsconfig.json, or otherwise configure the appropriate builtin
14
+ * `fetch` types for your environment.
15
+ */
16
+
17
+ // @ts-ignore
18
+ type _fetch = unknown extends typeof fetch ? typeof nf.default : typeof fetch;
19
+ // @ts-ignore
20
+ type _Request = unknown extends Request ? nf.Request : Request;
21
+ // @ts-ignore
22
+ type _RequestInfo = unknown extends RequestInfo ? nf.RequestInfo : RequestInfo;
23
+ // @ts-ignore
24
+ type _RequestInit = unknown extends RequestInit ? nf.RequestInit : RequestInit;
25
+ // @ts-ignore
26
+ type _Response = unknown extends Response ? nf.Response : Response;
27
+ // @ts-ignore
28
+ type _ResponseInit = unknown extends ResponseInit ? nf.ResponseInit : ResponseInit;
29
+ type _ResponseType =
30
+ // @ts-ignore
31
+ unknown extends ResponseType ? 'basic' | 'cors' | 'default' | 'error' | 'opaque' | 'opaqueredirect'
32
+ : // @ts-ignore
33
+ ResponseType;
34
+ // @ts-ignore
35
+ type _BodyInit = unknown extends BodyInit ? nf.BodyInit : BodyInit;
36
+ // @ts-ignore
37
+ type _Headers = unknown extends Headers ? nf.Headers : Headers;
38
+ // @ts-ignore
39
+ type _HeadersInit = unknown extends HeadersInit ? nf.HeadersInit : HeadersInit;
40
+
41
+ declare const _fetch: _fetch;
42
+ declare const _Request: {
43
+ prototype: _Request;
44
+ new (input: _RequestInfo | URL, init?: _RequestInit): _Request;
45
+ };
46
+ declare const _Response: {
47
+ prototype: _Response;
48
+ new (body?: _BodyInit | null, init?: _ResponseInit): _Response;
49
+ };
50
+ declare const _Headers: {
51
+ prototype: _Headers;
52
+ new (init?: _HeadersInit): _Headers;
53
+ };
54
+
55
+ export const isPolyfilled = false;
56
+
57
+ export { _fetch as fetch, _Request as Request, _Response as Response, _Headers as Headers };
58
+ export type {
59
+ _RequestInit as RequestInit,
60
+ _RequestInfo as RequestInfo,
61
+ _ResponseType as ResponseType,
62
+ _BodyInit as BodyInit,
63
+ };