openai 4.8.0 → 4.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (319) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +4 -0
  3. package/_shims/MultipartBody.d.ts +9 -0
  4. package/_shims/MultipartBody.d.ts.map +1 -0
  5. package/_shims/MultipartBody.js +16 -0
  6. package/_shims/MultipartBody.js.map +1 -0
  7. package/_shims/MultipartBody.mjs +12 -0
  8. package/_shims/MultipartBody.mjs.map +1 -0
  9. package/_shims/README.md +46 -0
  10. package/{src/_shims/ReadableStream-node.ts → _shims/auto/runtime-bun.d.ts} +2 -3
  11. package/_shims/auto/runtime-bun.d.ts.map +1 -0
  12. package/_shims/auto/runtime-bun.js +21 -0
  13. package/_shims/auto/runtime-bun.js.map +1 -0
  14. package/_shims/auto/runtime-bun.mjs +2 -0
  15. package/_shims/auto/runtime-bun.mjs.map +1 -0
  16. package/_shims/auto/runtime-node.d.ts +5 -0
  17. package/_shims/auto/runtime-node.d.ts.map +1 -0
  18. package/_shims/auto/runtime-node.js +21 -0
  19. package/_shims/auto/runtime-node.js.map +1 -0
  20. package/_shims/auto/runtime-node.mjs +2 -0
  21. package/_shims/auto/runtime-node.mjs.map +1 -0
  22. package/_shims/auto/runtime.d.ts +5 -0
  23. package/_shims/auto/runtime.d.ts.map +1 -0
  24. package/_shims/auto/runtime.js +21 -0
  25. package/_shims/auto/runtime.js.map +1 -0
  26. package/_shims/auto/runtime.mjs +2 -0
  27. package/_shims/auto/runtime.mjs.map +1 -0
  28. package/_shims/auto/types-node.d.ts +5 -0
  29. package/_shims/auto/types-node.d.ts.map +1 -0
  30. package/_shims/auto/types-node.js +21 -0
  31. package/_shims/auto/types-node.js.map +1 -0
  32. package/_shims/auto/types-node.mjs +2 -0
  33. package/_shims/auto/types-node.mjs.map +1 -0
  34. package/_shims/auto/types.d.ts +99 -0
  35. package/_shims/{ReadableStream.js → auto/types.js} +0 -2
  36. package/{src/_shims/ReadableStream.js → _shims/auto/types.mjs} +0 -2
  37. package/_shims/bun-runtime.d.ts +6 -0
  38. package/_shims/bun-runtime.d.ts.map +1 -0
  39. package/_shims/bun-runtime.js +14 -0
  40. package/_shims/bun-runtime.js.map +1 -0
  41. package/_shims/bun-runtime.mjs +10 -0
  42. package/_shims/bun-runtime.mjs.map +1 -0
  43. package/_shims/index.d.ts +79 -0
  44. package/_shims/index.js +13 -0
  45. package/_shims/index.mjs +7 -0
  46. package/_shims/manual-types.d.ts +12 -0
  47. package/_shims/manual-types.js +3 -0
  48. package/_shims/manual-types.mjs +3 -0
  49. package/_shims/node-runtime.d.ts +3 -0
  50. package/_shims/node-runtime.d.ts.map +1 -0
  51. package/_shims/node-runtime.js +87 -0
  52. package/_shims/node-runtime.js.map +1 -0
  53. package/_shims/node-runtime.mjs +54 -0
  54. package/_shims/node-runtime.mjs.map +1 -0
  55. package/_shims/node-types.d.ts +42 -0
  56. package/_shims/node-types.js +3 -0
  57. package/_shims/node-types.mjs +3 -0
  58. package/_shims/registry.d.ts +35 -0
  59. package/_shims/registry.d.ts.map +1 -0
  60. package/_shims/registry.js +39 -0
  61. package/_shims/registry.js.map +1 -0
  62. package/_shims/registry.mjs +35 -0
  63. package/_shims/registry.mjs.map +1 -0
  64. package/_shims/web-runtime.d.ts +5 -0
  65. package/_shims/web-runtime.d.ts.map +1 -0
  66. package/_shims/web-runtime.js +70 -0
  67. package/_shims/web-runtime.js.map +1 -0
  68. package/_shims/web-runtime.mjs +63 -0
  69. package/_shims/web-runtime.mjs.map +1 -0
  70. package/_shims/web-types.d.ts +82 -0
  71. package/_shims/web-types.js +3 -0
  72. package/_shims/web-types.mjs +3 -0
  73. package/core.d.ts +170 -218
  74. package/core.d.ts.map +1 -1
  75. package/core.js +679 -737
  76. package/core.js.map +1 -1
  77. package/core.mjs +673 -688
  78. package/core.mjs.map +1 -1
  79. package/error.d.ts +32 -34
  80. package/error.js +95 -109
  81. package/error.mjs +92 -94
  82. package/index.d.mts +164 -175
  83. package/index.d.ts +164 -175
  84. package/index.d.ts.map +1 -1
  85. package/index.js +110 -161
  86. package/index.mjs +88 -109
  87. package/package.json +31 -58
  88. package/pagination.d.ts +31 -41
  89. package/pagination.js +52 -48
  90. package/pagination.mjs +50 -46
  91. package/resource.d.ts +10 -10
  92. package/resource.js +12 -12
  93. package/resource.mjs +10 -10
  94. package/resources/audio/audio.d.ts +12 -12
  95. package/resources/audio/audio.js +33 -50
  96. package/resources/audio/audio.mjs +11 -11
  97. package/resources/audio/index.d.ts +4 -4
  98. package/resources/audio/index.js +9 -24
  99. package/resources/audio/index.mjs +4 -4
  100. package/resources/audio/transcriptions.d.ts +44 -44
  101. package/resources/audio/transcriptions.js +13 -12
  102. package/resources/audio/transcriptions.mjs +9 -8
  103. package/resources/audio/translations.d.ts +38 -38
  104. package/resources/audio/translations.js +13 -12
  105. package/resources/audio/translations.mjs +9 -8
  106. package/resources/chat/chat.d.ts +17 -17
  107. package/resources/chat/chat.js +30 -47
  108. package/resources/chat/chat.mjs +8 -8
  109. package/resources/chat/completions.d.ts +330 -353
  110. package/resources/chat/completions.js +10 -13
  111. package/resources/chat/completions.mjs +7 -10
  112. package/resources/chat/index.d.ts +3 -17
  113. package/resources/chat/index.js +7 -17
  114. package/resources/chat/index.mjs +3 -3
  115. package/resources/completions.d.ts +216 -232
  116. package/resources/completions.js +10 -13
  117. package/resources/completions.mjs +7 -10
  118. package/resources/edits.d.ts +73 -73
  119. package/resources/edits.js +16 -15
  120. package/resources/edits.mjs +13 -12
  121. package/resources/embeddings.d.ts +73 -76
  122. package/resources/embeddings.js +12 -11
  123. package/resources/embeddings.mjs +9 -8
  124. package/resources/files.d.ts +91 -96
  125. package/resources/files.js +64 -65
  126. package/resources/files.mjs +57 -58
  127. package/resources/fine-tunes.d.ts +277 -290
  128. package/resources/fine-tunes.js +49 -50
  129. package/resources/fine-tunes.mjs +45 -46
  130. package/resources/fine-tuning/fine-tuning.d.ts +12 -12
  131. package/resources/fine-tuning/fine-tuning.js +32 -49
  132. package/resources/fine-tuning/fine-tuning.mjs +10 -10
  133. package/resources/fine-tuning/index.d.ts +3 -12
  134. package/resources/fine-tuning/index.js +9 -29
  135. package/resources/fine-tuning/index.mjs +3 -3
  136. package/resources/fine-tuning/jobs.d.ts +173 -179
  137. package/resources/fine-tuning/jobs.js +50 -47
  138. package/resources/fine-tuning/jobs.mjs +45 -42
  139. package/resources/images.d.ts +116 -119
  140. package/resources/images.js +25 -24
  141. package/resources/images.mjs +21 -20
  142. package/resources/index.d.ts +12 -37
  143. package/resources/index.js +29 -113
  144. package/resources/index.mjs +12 -12
  145. package/resources/models.d.ts +41 -40
  146. package/resources/models.js +30 -28
  147. package/resources/models.mjs +26 -24
  148. package/resources/moderations.d.ts +153 -156
  149. package/resources/moderations.js +12 -11
  150. package/resources/moderations.mjs +9 -8
  151. package/shims/node.d.ts +29 -0
  152. package/shims/node.d.ts.map +1 -0
  153. package/shims/node.js +31 -0
  154. package/shims/node.js.map +1 -0
  155. package/shims/node.mjs +5 -0
  156. package/shims/node.mjs.map +1 -0
  157. package/shims/web.d.ts +26 -0
  158. package/shims/web.d.ts.map +1 -0
  159. package/shims/web.js +31 -0
  160. package/shims/web.js.map +1 -0
  161. package/shims/web.mjs +5 -0
  162. package/shims/web.mjs.map +1 -0
  163. package/src/_shims/MultipartBody.ts +9 -0
  164. package/src/_shims/README.md +46 -0
  165. package/src/_shims/auto/runtime-bun.ts +4 -0
  166. package/src/_shims/auto/runtime-node.ts +4 -0
  167. package/src/_shims/auto/runtime.ts +4 -0
  168. package/src/_shims/auto/types-node.ts +4 -0
  169. package/src/_shims/auto/types.d.ts +99 -0
  170. package/src/_shims/auto/types.js +3 -0
  171. package/src/_shims/auto/types.mjs +3 -0
  172. package/src/_shims/bun-runtime.ts +14 -0
  173. package/src/_shims/index.d.ts +79 -0
  174. package/src/_shims/index.js +13 -0
  175. package/src/_shims/index.mjs +7 -0
  176. package/src/_shims/manual-types.d.ts +12 -0
  177. package/src/_shims/manual-types.js +3 -0
  178. package/src/_shims/manual-types.mjs +3 -0
  179. package/src/_shims/node-runtime.ts +79 -0
  180. package/src/_shims/node-types.d.ts +42 -0
  181. package/src/_shims/node-types.js +3 -0
  182. package/src/_shims/node-types.mjs +3 -0
  183. package/src/_shims/registry.ts +62 -0
  184. package/src/_shims/web-runtime.ts +91 -0
  185. package/src/_shims/web-types.d.ts +82 -0
  186. package/src/_shims/web-types.js +3 -0
  187. package/src/_shims/web-types.mjs +3 -0
  188. package/src/core.ts +34 -17
  189. package/src/error.ts +1 -1
  190. package/src/index.ts +6 -6
  191. package/src/pagination.ts +1 -1
  192. package/src/resource.ts +1 -1
  193. package/src/resources/audio/audio.ts +4 -4
  194. package/src/resources/audio/index.ts +3 -3
  195. package/src/resources/audio/transcriptions.ts +4 -4
  196. package/src/resources/audio/translations.ts +4 -4
  197. package/src/resources/chat/chat.ts +3 -3
  198. package/src/resources/chat/completions.ts +6 -6
  199. package/src/resources/chat/index.ts +2 -2
  200. package/src/resources/completions.ts +5 -5
  201. package/src/resources/edits.ts +4 -4
  202. package/src/resources/embeddings.ts +3 -3
  203. package/src/resources/files.ts +7 -7
  204. package/src/resources/fine-tunes.ts +7 -7
  205. package/src/resources/fine-tuning/fine-tuning.ts +3 -3
  206. package/src/resources/fine-tuning/index.ts +2 -2
  207. package/src/resources/fine-tuning/jobs.ts +6 -6
  208. package/src/resources/images.ts +4 -4
  209. package/src/resources/index.ts +11 -11
  210. package/src/resources/models.ts +4 -4
  211. package/src/resources/moderations.ts +3 -3
  212. package/src/shims/node.ts +50 -0
  213. package/src/shims/web.ts +50 -0
  214. package/src/streaming.ts +1 -1
  215. package/src/uploads.ts +12 -16
  216. package/src/version.ts +1 -1
  217. package/streaming.d.ts +9 -8
  218. package/streaming.d.ts.map +1 -1
  219. package/streaming.js +194 -185
  220. package/streaming.mjs +192 -183
  221. package/uploads.d.ts +23 -39
  222. package/uploads.d.ts.map +1 -1
  223. package/uploads.js +115 -157
  224. package/uploads.js.map +1 -1
  225. package/uploads.mjs +111 -133
  226. package/uploads.mjs.map +1 -1
  227. package/version.d.ts +2 -2
  228. package/version.js +4 -4
  229. package/version.mjs +2 -2
  230. package/_shims/ReadableStream-node.d.ts +0 -6
  231. package/_shims/ReadableStream-node.d.ts.map +0 -1
  232. package/_shims/ReadableStream-node.js +0 -14
  233. package/_shims/ReadableStream-node.js.map +0 -1
  234. package/_shims/ReadableStream-node.mjs +0 -3
  235. package/_shims/ReadableStream-node.mjs.map +0 -1
  236. package/_shims/ReadableStream.d.ts +0 -38
  237. package/_shims/ReadableStream.mjs +0 -7
  238. package/_shims/agent-node.d.ts +0 -7
  239. package/_shims/agent-node.d.ts.map +0 -1
  240. package/_shims/agent-node.js +0 -28
  241. package/_shims/agent-node.js.map +0 -1
  242. package/_shims/agent-node.mjs +0 -16
  243. package/_shims/agent-node.mjs.map +0 -1
  244. package/_shims/agent.d.ts +0 -9
  245. package/_shims/agent.d.ts.map +0 -1
  246. package/_shims/agent.js +0 -14
  247. package/_shims/agent.js.map +0 -1
  248. package/_shims/agent.mjs +0 -10
  249. package/_shims/agent.mjs.map +0 -1
  250. package/_shims/fetch-node.d.ts +0 -64
  251. package/_shims/fetch-node.js +0 -12
  252. package/_shims/fetch-node.mjs +0 -14
  253. package/_shims/fetch.d.ts +0 -60
  254. package/_shims/fetch.js +0 -13
  255. package/_shims/fetch.mjs +0 -15
  256. package/_shims/fileFromPath-node.d.ts +0 -17
  257. package/_shims/fileFromPath-node.d.ts.map +0 -1
  258. package/_shims/fileFromPath-node.js +0 -17
  259. package/_shims/fileFromPath-node.js.map +0 -1
  260. package/_shims/fileFromPath-node.mjs +0 -13
  261. package/_shims/fileFromPath-node.mjs.map +0 -1
  262. package/_shims/fileFromPath.d.ts +0 -22
  263. package/_shims/fileFromPath.d.ts.map +0 -1
  264. package/_shims/fileFromPath.js +0 -16
  265. package/_shims/fileFromPath.js.map +0 -1
  266. package/_shims/fileFromPath.mjs +0 -12
  267. package/_shims/fileFromPath.mjs.map +0 -1
  268. package/_shims/form-data-node.d.ts +0 -45
  269. package/_shims/form-data-node.js +0 -11
  270. package/_shims/form-data-node.mjs +0 -9
  271. package/_shims/form-data.d.ts +0 -43
  272. package/_shims/form-data.js +0 -17
  273. package/_shims/form-data.mjs +0 -20
  274. package/_shims/getMultipartRequestOptions-node.d.ts +0 -10
  275. package/_shims/getMultipartRequestOptions-node.d.ts.map +0 -1
  276. package/_shims/getMultipartRequestOptions-node.js +0 -22
  277. package/_shims/getMultipartRequestOptions-node.js.map +0 -1
  278. package/_shims/getMultipartRequestOptions-node.mjs +0 -18
  279. package/_shims/getMultipartRequestOptions-node.mjs.map +0 -1
  280. package/_shims/getMultipartRequestOptions.d.ts +0 -10
  281. package/_shims/getMultipartRequestOptions.d.ts.map +0 -1
  282. package/_shims/getMultipartRequestOptions.js +0 -12
  283. package/_shims/getMultipartRequestOptions.js.map +0 -1
  284. package/_shims/getMultipartRequestOptions.mjs +0 -8
  285. package/_shims/getMultipartRequestOptions.mjs.map +0 -1
  286. package/_shims/node-readable-node.d.ts +0 -8
  287. package/_shims/node-readable-node.d.ts.map +0 -1
  288. package/_shims/node-readable-node.js +0 -9
  289. package/_shims/node-readable-node.js.map +0 -1
  290. package/_shims/node-readable-node.mjs +0 -5
  291. package/_shims/node-readable-node.mjs.map +0 -1
  292. package/_shims/node-readable.d.ts +0 -23
  293. package/_shims/node-readable.d.ts.map +0 -1
  294. package/_shims/node-readable.js +0 -11
  295. package/_shims/node-readable.js.map +0 -1
  296. package/_shims/node-readable.mjs +0 -7
  297. package/_shims/node-readable.mjs.map +0 -1
  298. package/src/_shims/ReadableStream.d.ts +0 -38
  299. package/src/_shims/ReadableStream.mjs +0 -7
  300. package/src/_shims/agent-node.ts +0 -22
  301. package/src/_shims/agent.ts +0 -12
  302. package/src/_shims/fetch-node.d.ts +0 -64
  303. package/src/_shims/fetch-node.js +0 -12
  304. package/src/_shims/fetch-node.mjs +0 -14
  305. package/src/_shims/fetch.d.ts +0 -60
  306. package/src/_shims/fetch.js +0 -13
  307. package/src/_shims/fetch.mjs +0 -15
  308. package/src/_shims/fileFromPath-node.ts +0 -29
  309. package/src/_shims/fileFromPath.ts +0 -29
  310. package/src/_shims/form-data-node.d.ts +0 -45
  311. package/src/_shims/form-data-node.js +0 -11
  312. package/src/_shims/form-data-node.mjs +0 -9
  313. package/src/_shims/form-data.d.ts +0 -43
  314. package/src/_shims/form-data.js +0 -17
  315. package/src/_shims/form-data.mjs +0 -20
  316. package/src/_shims/getMultipartRequestOptions-node.ts +0 -25
  317. package/src/_shims/getMultipartRequestOptions.ts +0 -14
  318. package/src/_shims/node-readable-node.ts +0 -10
  319. package/src/_shims/node-readable.ts +0 -30
@@ -1,8 +1,8 @@
1
1
  // File generated from our OpenAPI spec by Stainless.
2
2
 
3
- import * as Core from '../core.js';
4
- import { APIResource } from '../resource.js';
5
- import * as API from './index.js';
3
+ import * as Core from "../core";
4
+ import { APIResource } from "../resource";
5
+ import * as API from './index';
6
6
 
7
7
  export class Moderations extends APIResource {
8
8
  /**
@@ -0,0 +1,50 @@
1
+ // @ts-ignore
2
+ import * as types from '../_shims/node-types';
3
+ import { setShims } from '../_shims/registry';
4
+ import { getRuntime } from '../_shims/node-runtime';
5
+ setShims(getRuntime());
6
+
7
+ declare module '../_shims/manual-types' {
8
+ export namespace manual {
9
+ // @ts-ignore
10
+ export type Agent = types.Agent;
11
+ // @ts-ignore
12
+ export import fetch = types.fetch;
13
+ // @ts-ignore
14
+ export type Request = types.Request;
15
+ // @ts-ignore
16
+ export type RequestInfo = types.RequestInfo;
17
+ // @ts-ignore
18
+ export type RequestInit = types.RequestInit;
19
+ // @ts-ignore
20
+ export type Response = types.Response;
21
+ // @ts-ignore
22
+ export type ResponseInit = types.ResponseInit;
23
+ // @ts-ignore
24
+ export type ResponseType = types.ResponseType;
25
+ // @ts-ignore
26
+ export type BodyInit = types.BodyInit;
27
+ // @ts-ignore
28
+ export type Headers = types.Headers;
29
+ // @ts-ignore
30
+ export type HeadersInit = types.HeadersInit;
31
+ // @ts-ignore
32
+ export type BlobPropertyBag = types.BlobPropertyBag;
33
+ // @ts-ignore
34
+ export type FilePropertyBag = types.FilePropertyBag;
35
+ // @ts-ignore
36
+ export type FileFromPathOptions = types.FileFromPathOptions;
37
+ // @ts-ignore
38
+ export import FormData = types.FormData;
39
+ // @ts-ignore
40
+ export import File = types.File;
41
+ // @ts-ignore
42
+ export import Blob = types.Blob;
43
+ // @ts-ignore
44
+ export type Readable = types.Readable;
45
+ // @ts-ignore
46
+ export type FsReadStream = types.FsReadStream;
47
+ // @ts-ignore
48
+ export type ReadableStream = types.ReadableStream;
49
+ }
50
+ }
@@ -0,0 +1,50 @@
1
+ // @ts-ignore
2
+ import * as types from '../_shims/web-types';
3
+ import { setShims } from '../_shims/registry';
4
+ import { getRuntime } from '../_shims/web-runtime';
5
+ setShims(getRuntime({ manuallyImported: true }));
6
+
7
+ declare module '../_shims/manual-types' {
8
+ export namespace manual {
9
+ // @ts-ignore
10
+ export type Agent = types.Agent;
11
+ // @ts-ignore
12
+ export import fetch = types.fetch;
13
+ // @ts-ignore
14
+ export type Request = types.Request;
15
+ // @ts-ignore
16
+ export type RequestInfo = types.RequestInfo;
17
+ // @ts-ignore
18
+ export type RequestInit = types.RequestInit;
19
+ // @ts-ignore
20
+ export type Response = types.Response;
21
+ // @ts-ignore
22
+ export type ResponseInit = types.ResponseInit;
23
+ // @ts-ignore
24
+ export type ResponseType = types.ResponseType;
25
+ // @ts-ignore
26
+ export type BodyInit = types.BodyInit;
27
+ // @ts-ignore
28
+ export type Headers = types.Headers;
29
+ // @ts-ignore
30
+ export type HeadersInit = types.HeadersInit;
31
+ // @ts-ignore
32
+ export type BlobPropertyBag = types.BlobPropertyBag;
33
+ // @ts-ignore
34
+ export type FilePropertyBag = types.FilePropertyBag;
35
+ // @ts-ignore
36
+ export type FileFromPathOptions = types.FileFromPathOptions;
37
+ // @ts-ignore
38
+ export import FormData = types.FormData;
39
+ // @ts-ignore
40
+ export import File = types.File;
41
+ // @ts-ignore
42
+ export import Blob = types.Blob;
43
+ // @ts-ignore
44
+ export type Readable = types.Readable;
45
+ // @ts-ignore
46
+ export type FsReadStream = types.FsReadStream;
47
+ // @ts-ignore
48
+ export type ReadableStream = types.ReadableStream;
49
+ }
50
+ }
package/src/streaming.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Response } from './_shims/fetch.js';
1
+ import { type Response } from './_shims/index';
2
2
 
3
3
  type Bytes = string | ArrayBuffer | Uint8Array | Buffer | null | undefined;
4
4
 
package/src/uploads.ts CHANGED
@@ -1,12 +1,15 @@
1
- import { type RequestOptions } from './core.js';
2
- import { type Readable } from './_shims/node-readable.js';
3
- import { type BodyInit } from './_shims/fetch.js';
4
- import { FormData, File, type Blob, type FilePropertyBag } from './_shims/form-data.js';
5
- import { getMultipartRequestOptions } from './_shims/getMultipartRequestOptions.js';
6
- import { fileFromPath } from './_shims/fileFromPath.js';
7
- import { type FsReadStream, isFsReadStream } from './_shims/node-readable.js';
8
-
9
- export { fileFromPath };
1
+ import { type RequestOptions } from './core';
2
+ import {
3
+ FormData,
4
+ File,
5
+ type Blob,
6
+ type FilePropertyBag,
7
+ getMultipartRequestOptions,
8
+ type FsReadStream,
9
+ isFsReadStream,
10
+ } from './_shims/index';
11
+ import { MultipartBody } from './_shims/MultipartBody';
12
+ export { fileFromPath } from './_shims/index';
10
13
 
11
14
  type BlobLikePart = string | ArrayBuffer | ArrayBufferView | BlobLike | Uint8Array | DataView;
12
15
  export type BlobPart = string | ArrayBuffer | ArrayBufferView | Blob | Uint8Array | DataView;
@@ -175,13 +178,6 @@ const getStringFromMaybeBuffer = (x: string | Buffer | unknown): string | undefi
175
178
  const isAsyncIterableIterator = (value: any): value is AsyncIterableIterator<unknown> =>
176
179
  value != null && typeof value === 'object' && typeof value[Symbol.asyncIterator] === 'function';
177
180
 
178
- export class MultipartBody {
179
- constructor(public body: Readable | BodyInit) {}
180
- get [Symbol.toStringTag](): string {
181
- return 'MultipartBody';
182
- }
183
- }
184
-
185
181
  export const isMultipartBody = (body: any): body is MultipartBody =>
186
182
  body && typeof body === 'object' && body.body && body[Symbol.toStringTag] === 'MultipartBody';
187
183
 
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const VERSION = '4.8.0'; // x-release-please-version
1
+ export const VERSION = '4.9.0'; // x-release-please-version
package/streaming.d.ts CHANGED
@@ -1,10 +1,11 @@
1
- import type { Response } from 'openai/_shims/fetch';
1
+
2
+ import { type Response } from "./_shims/index.js";
2
3
  export declare class Stream<Item> implements AsyncIterable<Item> {
3
- controller: AbortController;
4
- private response;
5
- private decoder;
6
- constructor(response: Response, controller: AbortController);
7
- private iterMessages;
8
- [Symbol.asyncIterator](): AsyncIterator<Item, any, undefined>;
4
+ controller: AbortController;
5
+ private response;
6
+ private decoder;
7
+ constructor(response: Response, controller: AbortController);
8
+ private iterMessages;
9
+ [Symbol.asyncIterator](): AsyncIterator<Item, any, undefined>;
9
10
  }
10
- //# sourceMappingURL=streaming.d.ts.map
11
+ //# sourceMappingURL=streaming.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"streaming.d.ts","sourceRoot":"","sources":["src/streaming.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAUpD,qBAAa,MAAM,CAAC,IAAI,CAAE,YAAW,aAAa,CAAC,IAAI,CAAC;IACtD,UAAU,EAAE,eAAe,CAAC;IAE5B,OAAO,CAAC,QAAQ,CAAW;IAC3B,OAAO,CAAC,OAAO,CAAa;gBAEhB,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,eAAe;YAM5C,YAAY;IAqBpB,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,aAAa,CAAC,IAAI,EAAE,GAAG,EAAE,SAAS,CAAC;CA+BrE"}
1
+ {"version":3,"file":"streaming.d.ts","sourceRoot":"","sources":["src/streaming.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAU/C,qBAAa,MAAM,CAAC,IAAI,CAAE,YAAW,aAAa,CAAC,IAAI,CAAC;IACtD,UAAU,EAAE,eAAe,CAAC;IAE5B,OAAO,CAAC,QAAQ,CAAW;IAC3B,OAAO,CAAC,OAAO,CAAa;gBAEhB,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,eAAe;YAM5C,YAAY;IAqBpB,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,aAAa,CAAC,IAAI,EAAE,GAAG,EAAE,SAAS,CAAC;CA+BrE"}
package/streaming.js CHANGED
@@ -1,99 +1,109 @@
1
- 'use strict';
2
- Object.defineProperty(exports, '__esModule', { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Stream = void 0;
4
4
  class Stream {
5
- constructor(response, controller) {
6
- this.response = response;
7
- this.controller = controller;
8
- this.decoder = new SSEDecoder();
9
- }
10
- async *iterMessages() {
11
- if (!this.response.body) {
12
- this.controller.abort();
13
- throw new Error(`Attempted to iterate over a response with no body`);
14
- }
15
- const lineDecoder = new LineDecoder();
16
- const iter = readableStreamAsyncIterable(this.response.body);
17
- for await (const chunk of iter) {
18
- for (const line of lineDecoder.decode(chunk)) {
19
- const sse = this.decoder.decode(line);
20
- if (sse) yield sse;
21
- }
22
- }
23
- for (const line of lineDecoder.flush()) {
24
- const sse = this.decoder.decode(line);
25
- if (sse) yield sse;
5
+ constructor(response, controller) {
6
+ this.response = response;
7
+ this.controller = controller;
8
+ this.decoder = new SSEDecoder();
9
+ }
10
+ async *iterMessages() {
11
+ if (!this.response.body) {
12
+ this.controller.abort();
13
+ throw new Error(`Attempted to iterate over a response with no body`);
14
+ }
15
+ const lineDecoder = new LineDecoder();
16
+ const iter = readableStreamAsyncIterable(this.response.body);
17
+ for await (const chunk of iter) {
18
+ for (const line of lineDecoder.decode(chunk)) {
19
+ const sse = this.decoder.decode(line);
20
+ if (sse)
21
+ yield sse;
22
+ }
23
+ }
24
+ for (const line of lineDecoder.flush()) {
25
+ const sse = this.decoder.decode(line);
26
+ if (sse)
27
+ yield sse;
28
+ }
26
29
  }
27
- }
28
- async *[Symbol.asyncIterator]() {
29
- let done = false;
30
- try {
31
- for await (const sse of this.iterMessages()) {
32
- if (done) continue;
33
- if (sse.data.startsWith('[DONE]')) {
34
- done = true;
35
- continue;
36
- }
37
- if (sse.event === null) {
38
- try {
39
- yield JSON.parse(sse.data);
40
- } catch (e) {
41
- console.error(`Could not parse message into JSON:`, sse.data);
42
- console.error(`From chunk:`, sse.raw);
30
+ async *[Symbol.asyncIterator]() {
31
+ let done = false;
32
+ try {
33
+ for await (const sse of this.iterMessages()) {
34
+ if (done)
35
+ continue;
36
+ if (sse.data.startsWith('[DONE]')) {
37
+ done = true;
38
+ continue;
39
+ }
40
+ if (sse.event === null) {
41
+ try {
42
+ yield JSON.parse(sse.data);
43
+ }
44
+ catch (e) {
45
+ console.error(`Could not parse message into JSON:`, sse.data);
46
+ console.error(`From chunk:`, sse.raw);
47
+ throw e;
48
+ }
49
+ }
50
+ }
51
+ done = true;
52
+ }
53
+ catch (e) {
54
+ // If the user calls `stream.controller.abort()`, we should exit without throwing.
55
+ if (e instanceof Error && e.name === 'AbortError')
56
+ return;
43
57
  throw e;
44
- }
45
- }
46
- }
47
- done = true;
48
- } catch (e) {
49
- // If the user calls `stream.controller.abort()`, we should exit without throwing.
50
- if (e instanceof Error && e.name === 'AbortError') return;
51
- throw e;
52
- } finally {
53
- // If the user `break`s, abort the ongoing request.
54
- if (!done) this.controller.abort();
58
+ }
59
+ finally {
60
+ // If the user `break`s, abort the ongoing request.
61
+ if (!done)
62
+ this.controller.abort();
63
+ }
55
64
  }
56
- }
57
65
  }
58
66
  exports.Stream = Stream;
59
67
  class SSEDecoder {
60
- constructor() {
61
- this.event = null;
62
- this.data = [];
63
- this.chunks = [];
64
- }
65
- decode(line) {
66
- if (line.endsWith('\r')) {
67
- line = line.substring(0, line.length - 1);
68
- }
69
- if (!line) {
70
- // empty line and we didn't previously encounter any messages
71
- if (!this.event && !this.data.length) return null;
72
- const sse = {
73
- event: this.event,
74
- data: this.data.join('\n'),
75
- raw: this.chunks,
76
- };
77
- this.event = null;
78
- this.data = [];
79
- this.chunks = [];
80
- return sse;
81
- }
82
- this.chunks.push(line);
83
- if (line.startsWith(':')) {
84
- return null;
85
- }
86
- let [fieldname, _, value] = partition(line, ':');
87
- if (value.startsWith(' ')) {
88
- value = value.substring(1);
89
- }
90
- if (fieldname === 'event') {
91
- this.event = value;
92
- } else if (fieldname === 'data') {
93
- this.data.push(value);
68
+ constructor() {
69
+ this.event = null;
70
+ this.data = [];
71
+ this.chunks = [];
72
+ }
73
+ decode(line) {
74
+ if (line.endsWith('\r')) {
75
+ line = line.substring(0, line.length - 1);
76
+ }
77
+ if (!line) {
78
+ // empty line and we didn't previously encounter any messages
79
+ if (!this.event && !this.data.length)
80
+ return null;
81
+ const sse = {
82
+ event: this.event,
83
+ data: this.data.join('\n'),
84
+ raw: this.chunks,
85
+ };
86
+ this.event = null;
87
+ this.data = [];
88
+ this.chunks = [];
89
+ return sse;
90
+ }
91
+ this.chunks.push(line);
92
+ if (line.startsWith(':')) {
93
+ return null;
94
+ }
95
+ let [fieldname, _, value] = partition(line, ':');
96
+ if (value.startsWith(' ')) {
97
+ value = value.substring(1);
98
+ }
99
+ if (fieldname === 'event') {
100
+ this.event = value;
101
+ }
102
+ else if (fieldname === 'data') {
103
+ this.data.push(value);
104
+ }
105
+ return null;
94
106
  }
95
- return null;
96
- }
97
107
  }
98
108
  /**
99
109
  * A re-implementation of httpx's `LineDecoder` in Python that handles incrementally
@@ -102,87 +112,83 @@ class SSEDecoder {
102
112
  * https://github.com/encode/httpx/blob/920333ea98118e9cf617f246905d7b202510941c/httpx/_decoders.py#L258
103
113
  */
104
114
  class LineDecoder {
105
- constructor() {
106
- this.buffer = [];
107
- this.trailingCR = false;
108
- }
109
- decode(chunk) {
110
- let text = this.decodeText(chunk);
111
- if (this.trailingCR) {
112
- text = '\r' + text;
113
- this.trailingCR = false;
114
- }
115
- if (text.endsWith('\r')) {
116
- this.trailingCR = true;
117
- text = text.slice(0, -1);
118
- }
119
- if (!text) {
120
- return [];
121
- }
122
- const trailingNewline = LineDecoder.NEWLINE_CHARS.has(text[text.length - 1] || '');
123
- let lines = text.split(LineDecoder.NEWLINE_REGEXP);
124
- if (lines.length === 1 && !trailingNewline) {
125
- this.buffer.push(lines[0]);
126
- return [];
127
- }
128
- if (this.buffer.length > 0) {
129
- lines = [this.buffer.join('') + lines[0], ...lines.slice(1)];
130
- this.buffer = [];
131
- }
132
- if (!trailingNewline) {
133
- this.buffer = [lines.pop() || ''];
134
- }
135
- return lines;
136
- }
137
- decodeText(bytes) {
138
- var _a;
139
- if (bytes == null) return '';
140
- if (typeof bytes === 'string') return bytes;
141
- // Node:
142
- if (typeof Buffer !== 'undefined') {
143
- if (bytes instanceof Buffer) {
144
- return bytes.toString();
145
- }
146
- if (bytes instanceof Uint8Array) {
147
- return Buffer.from(bytes).toString();
148
- }
149
- throw new Error(
150
- `Unexpected: received non-Uint8Array (${bytes.constructor.name}) stream chunk in an environment with a global "Buffer" defined, which this library assumes to be Node. Please report this error.`,
151
- );
152
- }
153
- // Browser
154
- if (typeof TextDecoder !== 'undefined') {
155
- if (bytes instanceof Uint8Array || bytes instanceof ArrayBuffer) {
156
- (_a = this.textDecoder) !== null && _a !== void 0 ? _a : (this.textDecoder = new TextDecoder('utf8'));
157
- return this.textDecoder.decode(bytes);
158
- }
159
- throw new Error(
160
- `Unexpected: received non-Uint8Array/ArrayBuffer (${bytes.constructor.name}) in a web platform. Please report this error.`,
161
- );
115
+ constructor() {
116
+ this.buffer = [];
117
+ this.trailingCR = false;
118
+ }
119
+ decode(chunk) {
120
+ let text = this.decodeText(chunk);
121
+ if (this.trailingCR) {
122
+ text = '\r' + text;
123
+ this.trailingCR = false;
124
+ }
125
+ if (text.endsWith('\r')) {
126
+ this.trailingCR = true;
127
+ text = text.slice(0, -1);
128
+ }
129
+ if (!text) {
130
+ return [];
131
+ }
132
+ const trailingNewline = LineDecoder.NEWLINE_CHARS.has(text[text.length - 1] || '');
133
+ let lines = text.split(LineDecoder.NEWLINE_REGEXP);
134
+ if (lines.length === 1 && !trailingNewline) {
135
+ this.buffer.push(lines[0]);
136
+ return [];
137
+ }
138
+ if (this.buffer.length > 0) {
139
+ lines = [this.buffer.join('') + lines[0], ...lines.slice(1)];
140
+ this.buffer = [];
141
+ }
142
+ if (!trailingNewline) {
143
+ this.buffer = [lines.pop() || ''];
144
+ }
145
+ return lines;
146
+ }
147
+ decodeText(bytes) {
148
+ var _a;
149
+ if (bytes == null)
150
+ return '';
151
+ if (typeof bytes === 'string')
152
+ return bytes;
153
+ // Node:
154
+ if (typeof Buffer !== 'undefined') {
155
+ if (bytes instanceof Buffer) {
156
+ return bytes.toString();
157
+ }
158
+ if (bytes instanceof Uint8Array) {
159
+ return Buffer.from(bytes).toString();
160
+ }
161
+ throw new Error(`Unexpected: received non-Uint8Array (${bytes.constructor.name}) stream chunk in an environment with a global "Buffer" defined, which this library assumes to be Node. Please report this error.`);
162
+ }
163
+ // Browser
164
+ if (typeof TextDecoder !== 'undefined') {
165
+ if (bytes instanceof Uint8Array || bytes instanceof ArrayBuffer) {
166
+ (_a = this.textDecoder) !== null && _a !== void 0 ? _a : (this.textDecoder = new TextDecoder('utf8'));
167
+ return this.textDecoder.decode(bytes);
168
+ }
169
+ throw new Error(`Unexpected: received non-Uint8Array/ArrayBuffer (${bytes.constructor.name}) in a web platform. Please report this error.`);
170
+ }
171
+ throw new Error(`Unexpected: neither Buffer nor TextDecoder are available as globals. Please report this error.`);
162
172
  }
163
- throw new Error(
164
- `Unexpected: neither Buffer nor TextDecoder are available as globals. Please report this error.`,
165
- );
166
- }
167
- flush() {
168
- if (!this.buffer.length && !this.trailingCR) {
169
- return [];
173
+ flush() {
174
+ if (!this.buffer.length && !this.trailingCR) {
175
+ return [];
176
+ }
177
+ const lines = [this.buffer.join('')];
178
+ this.buffer = [];
179
+ this.trailingCR = false;
180
+ return lines;
170
181
  }
171
- const lines = [this.buffer.join('')];
172
- this.buffer = [];
173
- this.trailingCR = false;
174
- return lines;
175
- }
176
182
  }
177
183
  // prettier-ignore
178
184
  LineDecoder.NEWLINE_CHARS = new Set(['\n', '\r', '\x0b', '\x0c', '\x1c', '\x1d', '\x1e', '\x85', '\u2028', '\u2029']);
179
185
  LineDecoder.NEWLINE_REGEXP = /\r\n|[\n\r\x0b\x0c\x1c\x1d\x1e\x85\u2028\u2029]/g;
180
186
  function partition(str, delimiter) {
181
- const index = str.indexOf(delimiter);
182
- if (index !== -1) {
183
- return [str.substring(0, index), delimiter, str.substring(index + delimiter.length)];
184
- }
185
- return [str, '', ''];
187
+ const index = str.indexOf(delimiter);
188
+ if (index !== -1) {
189
+ return [str.substring(0, index), delimiter, str.substring(index + delimiter.length)];
190
+ }
191
+ return [str, '', ''];
186
192
  }
187
193
  /**
188
194
  * Most browsers don't yet have async iterable support for ReadableStream,
@@ -191,28 +197,31 @@ function partition(str, delimiter) {
191
197
  * This polyfill was pulled from https://github.com/MattiasBuelens/web-streams-polyfill/pull/122#issuecomment-1627354490
192
198
  */
193
199
  function readableStreamAsyncIterable(stream) {
194
- if (stream[Symbol.asyncIterator]) return stream;
195
- const reader = stream.getReader();
196
- return {
197
- async next() {
198
- try {
199
- const result = await reader.read();
200
- if (result === null || result === void 0 ? void 0 : result.done) reader.releaseLock(); // release lock when stream becomes closed
201
- return result;
202
- } catch (e) {
203
- reader.releaseLock(); // release lock when stream becomes errored
204
- throw e;
205
- }
206
- },
207
- async return() {
208
- const cancelPromise = reader.cancel();
209
- reader.releaseLock();
210
- await cancelPromise;
211
- return { done: true, value: undefined };
212
- },
213
- [Symbol.asyncIterator]() {
214
- return this;
215
- },
216
- };
200
+ if (stream[Symbol.asyncIterator])
201
+ return stream;
202
+ const reader = stream.getReader();
203
+ return {
204
+ async next() {
205
+ try {
206
+ const result = await reader.read();
207
+ if (result === null || result === void 0 ? void 0 : result.done)
208
+ reader.releaseLock(); // release lock when stream becomes closed
209
+ return result;
210
+ }
211
+ catch (e) {
212
+ reader.releaseLock(); // release lock when stream becomes errored
213
+ throw e;
214
+ }
215
+ },
216
+ async return() {
217
+ const cancelPromise = reader.cancel();
218
+ reader.releaseLock();
219
+ await cancelPromise;
220
+ return { done: true, value: undefined };
221
+ },
222
+ [Symbol.asyncIterator]() {
223
+ return this;
224
+ },
225
+ };
217
226
  }
218
- //# sourceMappingURL=streaming.js.map
227
+ //# sourceMappingURL=streaming.js.map