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.
- package/CHANGELOG.md +8 -0
- package/README.md +4 -0
- package/_shims/MultipartBody.d.ts +9 -0
- package/_shims/MultipartBody.d.ts.map +1 -0
- package/_shims/MultipartBody.js +16 -0
- package/_shims/MultipartBody.js.map +1 -0
- package/_shims/MultipartBody.mjs +12 -0
- package/_shims/MultipartBody.mjs.map +1 -0
- package/_shims/README.md +46 -0
- package/{src/_shims/ReadableStream-node.ts → _shims/auto/runtime-bun.d.ts} +2 -3
- package/_shims/auto/runtime-bun.d.ts.map +1 -0
- package/_shims/auto/runtime-bun.js +21 -0
- package/_shims/auto/runtime-bun.js.map +1 -0
- package/_shims/auto/runtime-bun.mjs +2 -0
- package/_shims/auto/runtime-bun.mjs.map +1 -0
- package/_shims/auto/runtime-node.d.ts +5 -0
- package/_shims/auto/runtime-node.d.ts.map +1 -0
- package/_shims/auto/runtime-node.js +21 -0
- package/_shims/auto/runtime-node.js.map +1 -0
- package/_shims/auto/runtime-node.mjs +2 -0
- package/_shims/auto/runtime-node.mjs.map +1 -0
- package/_shims/auto/runtime.d.ts +5 -0
- package/_shims/auto/runtime.d.ts.map +1 -0
- package/_shims/auto/runtime.js +21 -0
- package/_shims/auto/runtime.js.map +1 -0
- package/_shims/auto/runtime.mjs +2 -0
- package/_shims/auto/runtime.mjs.map +1 -0
- package/_shims/auto/types-node.d.ts +5 -0
- package/_shims/auto/types-node.d.ts.map +1 -0
- package/_shims/auto/types-node.js +21 -0
- package/_shims/auto/types-node.js.map +1 -0
- package/_shims/auto/types-node.mjs +2 -0
- package/_shims/auto/types-node.mjs.map +1 -0
- package/_shims/auto/types.d.ts +99 -0
- package/_shims/{ReadableStream.js → auto/types.js} +0 -2
- package/{src/_shims/ReadableStream.js → _shims/auto/types.mjs} +0 -2
- package/_shims/bun-runtime.d.ts +6 -0
- package/_shims/bun-runtime.d.ts.map +1 -0
- package/_shims/bun-runtime.js +14 -0
- package/_shims/bun-runtime.js.map +1 -0
- package/_shims/bun-runtime.mjs +10 -0
- package/_shims/bun-runtime.mjs.map +1 -0
- package/_shims/index.d.ts +79 -0
- package/_shims/index.js +13 -0
- package/_shims/index.mjs +7 -0
- package/_shims/manual-types.d.ts +12 -0
- package/_shims/manual-types.js +3 -0
- package/_shims/manual-types.mjs +3 -0
- package/_shims/node-runtime.d.ts +3 -0
- package/_shims/node-runtime.d.ts.map +1 -0
- package/_shims/node-runtime.js +87 -0
- package/_shims/node-runtime.js.map +1 -0
- package/_shims/node-runtime.mjs +54 -0
- package/_shims/node-runtime.mjs.map +1 -0
- package/_shims/node-types.d.ts +42 -0
- package/_shims/node-types.js +3 -0
- package/_shims/node-types.mjs +3 -0
- package/_shims/registry.d.ts +35 -0
- package/_shims/registry.d.ts.map +1 -0
- package/_shims/registry.js +39 -0
- package/_shims/registry.js.map +1 -0
- package/_shims/registry.mjs +35 -0
- package/_shims/registry.mjs.map +1 -0
- package/_shims/web-runtime.d.ts +5 -0
- package/_shims/web-runtime.d.ts.map +1 -0
- package/_shims/web-runtime.js +70 -0
- package/_shims/web-runtime.js.map +1 -0
- package/_shims/web-runtime.mjs +63 -0
- package/_shims/web-runtime.mjs.map +1 -0
- package/_shims/web-types.d.ts +82 -0
- package/_shims/web-types.js +3 -0
- package/_shims/web-types.mjs +3 -0
- package/core.d.ts +170 -218
- package/core.d.ts.map +1 -1
- package/core.js +679 -737
- package/core.js.map +1 -1
- package/core.mjs +673 -688
- package/core.mjs.map +1 -1
- package/error.d.ts +32 -34
- package/error.js +95 -109
- package/error.mjs +92 -94
- package/index.d.mts +164 -175
- package/index.d.ts +164 -175
- package/index.d.ts.map +1 -1
- package/index.js +110 -161
- package/index.mjs +88 -109
- package/package.json +31 -58
- package/pagination.d.ts +31 -41
- package/pagination.js +52 -48
- package/pagination.mjs +50 -46
- package/resource.d.ts +10 -10
- package/resource.js +12 -12
- package/resource.mjs +10 -10
- package/resources/audio/audio.d.ts +12 -12
- package/resources/audio/audio.js +33 -50
- package/resources/audio/audio.mjs +11 -11
- package/resources/audio/index.d.ts +4 -4
- package/resources/audio/index.js +9 -24
- package/resources/audio/index.mjs +4 -4
- package/resources/audio/transcriptions.d.ts +44 -44
- package/resources/audio/transcriptions.js +13 -12
- package/resources/audio/transcriptions.mjs +9 -8
- package/resources/audio/translations.d.ts +38 -38
- package/resources/audio/translations.js +13 -12
- package/resources/audio/translations.mjs +9 -8
- package/resources/chat/chat.d.ts +17 -17
- package/resources/chat/chat.js +30 -47
- package/resources/chat/chat.mjs +8 -8
- package/resources/chat/completions.d.ts +330 -353
- package/resources/chat/completions.js +10 -13
- package/resources/chat/completions.mjs +7 -10
- package/resources/chat/index.d.ts +3 -17
- package/resources/chat/index.js +7 -17
- package/resources/chat/index.mjs +3 -3
- package/resources/completions.d.ts +216 -232
- package/resources/completions.js +10 -13
- package/resources/completions.mjs +7 -10
- package/resources/edits.d.ts +73 -73
- package/resources/edits.js +16 -15
- package/resources/edits.mjs +13 -12
- package/resources/embeddings.d.ts +73 -76
- package/resources/embeddings.js +12 -11
- package/resources/embeddings.mjs +9 -8
- package/resources/files.d.ts +91 -96
- package/resources/files.js +64 -65
- package/resources/files.mjs +57 -58
- package/resources/fine-tunes.d.ts +277 -290
- package/resources/fine-tunes.js +49 -50
- package/resources/fine-tunes.mjs +45 -46
- package/resources/fine-tuning/fine-tuning.d.ts +12 -12
- package/resources/fine-tuning/fine-tuning.js +32 -49
- package/resources/fine-tuning/fine-tuning.mjs +10 -10
- package/resources/fine-tuning/index.d.ts +3 -12
- package/resources/fine-tuning/index.js +9 -29
- package/resources/fine-tuning/index.mjs +3 -3
- package/resources/fine-tuning/jobs.d.ts +173 -179
- package/resources/fine-tuning/jobs.js +50 -47
- package/resources/fine-tuning/jobs.mjs +45 -42
- package/resources/images.d.ts +116 -119
- package/resources/images.js +25 -24
- package/resources/images.mjs +21 -20
- package/resources/index.d.ts +12 -37
- package/resources/index.js +29 -113
- package/resources/index.mjs +12 -12
- package/resources/models.d.ts +41 -40
- package/resources/models.js +30 -28
- package/resources/models.mjs +26 -24
- package/resources/moderations.d.ts +153 -156
- package/resources/moderations.js +12 -11
- package/resources/moderations.mjs +9 -8
- package/shims/node.d.ts +29 -0
- package/shims/node.d.ts.map +1 -0
- package/shims/node.js +31 -0
- package/shims/node.js.map +1 -0
- package/shims/node.mjs +5 -0
- package/shims/node.mjs.map +1 -0
- package/shims/web.d.ts +26 -0
- package/shims/web.d.ts.map +1 -0
- package/shims/web.js +31 -0
- package/shims/web.js.map +1 -0
- package/shims/web.mjs +5 -0
- package/shims/web.mjs.map +1 -0
- package/src/_shims/MultipartBody.ts +9 -0
- package/src/_shims/README.md +46 -0
- package/src/_shims/auto/runtime-bun.ts +4 -0
- package/src/_shims/auto/runtime-node.ts +4 -0
- package/src/_shims/auto/runtime.ts +4 -0
- package/src/_shims/auto/types-node.ts +4 -0
- package/src/_shims/auto/types.d.ts +99 -0
- package/src/_shims/auto/types.js +3 -0
- package/src/_shims/auto/types.mjs +3 -0
- package/src/_shims/bun-runtime.ts +14 -0
- package/src/_shims/index.d.ts +79 -0
- package/src/_shims/index.js +13 -0
- package/src/_shims/index.mjs +7 -0
- package/src/_shims/manual-types.d.ts +12 -0
- package/src/_shims/manual-types.js +3 -0
- package/src/_shims/manual-types.mjs +3 -0
- package/src/_shims/node-runtime.ts +79 -0
- package/src/_shims/node-types.d.ts +42 -0
- package/src/_shims/node-types.js +3 -0
- package/src/_shims/node-types.mjs +3 -0
- package/src/_shims/registry.ts +62 -0
- package/src/_shims/web-runtime.ts +91 -0
- package/src/_shims/web-types.d.ts +82 -0
- package/src/_shims/web-types.js +3 -0
- package/src/_shims/web-types.mjs +3 -0
- package/src/core.ts +34 -17
- package/src/error.ts +1 -1
- package/src/index.ts +6 -6
- package/src/pagination.ts +1 -1
- package/src/resource.ts +1 -1
- package/src/resources/audio/audio.ts +4 -4
- package/src/resources/audio/index.ts +3 -3
- package/src/resources/audio/transcriptions.ts +4 -4
- package/src/resources/audio/translations.ts +4 -4
- package/src/resources/chat/chat.ts +3 -3
- package/src/resources/chat/completions.ts +6 -6
- package/src/resources/chat/index.ts +2 -2
- package/src/resources/completions.ts +5 -5
- package/src/resources/edits.ts +4 -4
- package/src/resources/embeddings.ts +3 -3
- package/src/resources/files.ts +7 -7
- package/src/resources/fine-tunes.ts +7 -7
- package/src/resources/fine-tuning/fine-tuning.ts +3 -3
- package/src/resources/fine-tuning/index.ts +2 -2
- package/src/resources/fine-tuning/jobs.ts +6 -6
- package/src/resources/images.ts +4 -4
- package/src/resources/index.ts +11 -11
- package/src/resources/models.ts +4 -4
- package/src/resources/moderations.ts +3 -3
- package/src/shims/node.ts +50 -0
- package/src/shims/web.ts +50 -0
- package/src/streaming.ts +1 -1
- package/src/uploads.ts +12 -16
- package/src/version.ts +1 -1
- package/streaming.d.ts +9 -8
- package/streaming.d.ts.map +1 -1
- package/streaming.js +194 -185
- package/streaming.mjs +192 -183
- package/uploads.d.ts +23 -39
- package/uploads.d.ts.map +1 -1
- package/uploads.js +115 -157
- package/uploads.js.map +1 -1
- package/uploads.mjs +111 -133
- package/uploads.mjs.map +1 -1
- package/version.d.ts +2 -2
- package/version.js +4 -4
- package/version.mjs +2 -2
- package/_shims/ReadableStream-node.d.ts +0 -6
- package/_shims/ReadableStream-node.d.ts.map +0 -1
- package/_shims/ReadableStream-node.js +0 -14
- package/_shims/ReadableStream-node.js.map +0 -1
- package/_shims/ReadableStream-node.mjs +0 -3
- package/_shims/ReadableStream-node.mjs.map +0 -1
- package/_shims/ReadableStream.d.ts +0 -38
- package/_shims/ReadableStream.mjs +0 -7
- package/_shims/agent-node.d.ts +0 -7
- package/_shims/agent-node.d.ts.map +0 -1
- package/_shims/agent-node.js +0 -28
- package/_shims/agent-node.js.map +0 -1
- package/_shims/agent-node.mjs +0 -16
- package/_shims/agent-node.mjs.map +0 -1
- package/_shims/agent.d.ts +0 -9
- package/_shims/agent.d.ts.map +0 -1
- package/_shims/agent.js +0 -14
- package/_shims/agent.js.map +0 -1
- package/_shims/agent.mjs +0 -10
- package/_shims/agent.mjs.map +0 -1
- package/_shims/fetch-node.d.ts +0 -64
- package/_shims/fetch-node.js +0 -12
- package/_shims/fetch-node.mjs +0 -14
- package/_shims/fetch.d.ts +0 -60
- package/_shims/fetch.js +0 -13
- package/_shims/fetch.mjs +0 -15
- package/_shims/fileFromPath-node.d.ts +0 -17
- package/_shims/fileFromPath-node.d.ts.map +0 -1
- package/_shims/fileFromPath-node.js +0 -17
- package/_shims/fileFromPath-node.js.map +0 -1
- package/_shims/fileFromPath-node.mjs +0 -13
- package/_shims/fileFromPath-node.mjs.map +0 -1
- package/_shims/fileFromPath.d.ts +0 -22
- package/_shims/fileFromPath.d.ts.map +0 -1
- package/_shims/fileFromPath.js +0 -16
- package/_shims/fileFromPath.js.map +0 -1
- package/_shims/fileFromPath.mjs +0 -12
- package/_shims/fileFromPath.mjs.map +0 -1
- package/_shims/form-data-node.d.ts +0 -45
- package/_shims/form-data-node.js +0 -11
- package/_shims/form-data-node.mjs +0 -9
- package/_shims/form-data.d.ts +0 -43
- package/_shims/form-data.js +0 -17
- package/_shims/form-data.mjs +0 -20
- package/_shims/getMultipartRequestOptions-node.d.ts +0 -10
- package/_shims/getMultipartRequestOptions-node.d.ts.map +0 -1
- package/_shims/getMultipartRequestOptions-node.js +0 -22
- package/_shims/getMultipartRequestOptions-node.js.map +0 -1
- package/_shims/getMultipartRequestOptions-node.mjs +0 -18
- package/_shims/getMultipartRequestOptions-node.mjs.map +0 -1
- package/_shims/getMultipartRequestOptions.d.ts +0 -10
- package/_shims/getMultipartRequestOptions.d.ts.map +0 -1
- package/_shims/getMultipartRequestOptions.js +0 -12
- package/_shims/getMultipartRequestOptions.js.map +0 -1
- package/_shims/getMultipartRequestOptions.mjs +0 -8
- package/_shims/getMultipartRequestOptions.mjs.map +0 -1
- package/_shims/node-readable-node.d.ts +0 -8
- package/_shims/node-readable-node.d.ts.map +0 -1
- package/_shims/node-readable-node.js +0 -9
- package/_shims/node-readable-node.js.map +0 -1
- package/_shims/node-readable-node.mjs +0 -5
- package/_shims/node-readable-node.mjs.map +0 -1
- package/_shims/node-readable.d.ts +0 -23
- package/_shims/node-readable.d.ts.map +0 -1
- package/_shims/node-readable.js +0 -11
- package/_shims/node-readable.js.map +0 -1
- package/_shims/node-readable.mjs +0 -7
- package/_shims/node-readable.mjs.map +0 -1
- package/src/_shims/ReadableStream.d.ts +0 -38
- package/src/_shims/ReadableStream.mjs +0 -7
- package/src/_shims/agent-node.ts +0 -22
- package/src/_shims/agent.ts +0 -12
- package/src/_shims/fetch-node.d.ts +0 -64
- package/src/_shims/fetch-node.js +0 -12
- package/src/_shims/fetch-node.mjs +0 -14
- package/src/_shims/fetch.d.ts +0 -60
- package/src/_shims/fetch.js +0 -13
- package/src/_shims/fetch.mjs +0 -15
- package/src/_shims/fileFromPath-node.ts +0 -29
- package/src/_shims/fileFromPath.ts +0 -29
- package/src/_shims/form-data-node.d.ts +0 -45
- package/src/_shims/form-data-node.js +0 -11
- package/src/_shims/form-data-node.mjs +0 -9
- package/src/_shims/form-data.d.ts +0 -43
- package/src/_shims/form-data.js +0 -17
- package/src/_shims/form-data.mjs +0 -20
- package/src/_shims/getMultipartRequestOptions-node.ts +0 -25
- package/src/_shims/getMultipartRequestOptions.ts +0 -14
- package/src/_shims/node-readable-node.ts +0 -10
- package/src/_shims/node-readable.ts +0 -30
package/streaming.mjs
CHANGED
|
@@ -1,95 +1,105 @@
|
|
|
1
1
|
export class Stream {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
2
|
+
constructor(response, controller) {
|
|
3
|
+
this.response = response;
|
|
4
|
+
this.controller = controller;
|
|
5
|
+
this.decoder = new SSEDecoder();
|
|
6
|
+
}
|
|
7
|
+
async *iterMessages() {
|
|
8
|
+
if (!this.response.body) {
|
|
9
|
+
this.controller.abort();
|
|
10
|
+
throw new Error(`Attempted to iterate over a response with no body`);
|
|
11
|
+
}
|
|
12
|
+
const lineDecoder = new LineDecoder();
|
|
13
|
+
const iter = readableStreamAsyncIterable(this.response.body);
|
|
14
|
+
for await (const chunk of iter) {
|
|
15
|
+
for (const line of lineDecoder.decode(chunk)) {
|
|
16
|
+
const sse = this.decoder.decode(line);
|
|
17
|
+
if (sse)
|
|
18
|
+
yield sse;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
for (const line of lineDecoder.flush()) {
|
|
22
|
+
const sse = this.decoder.decode(line);
|
|
23
|
+
if (sse)
|
|
24
|
+
yield sse;
|
|
25
|
+
}
|
|
23
26
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
27
|
+
async *[Symbol.asyncIterator]() {
|
|
28
|
+
let done = false;
|
|
29
|
+
try {
|
|
30
|
+
for await (const sse of this.iterMessages()) {
|
|
31
|
+
if (done)
|
|
32
|
+
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
|
+
}
|
|
41
|
+
catch (e) {
|
|
42
|
+
console.error(`Could not parse message into JSON:`, sse.data);
|
|
43
|
+
console.error(`From chunk:`, sse.raw);
|
|
44
|
+
throw e;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
done = true;
|
|
49
|
+
}
|
|
50
|
+
catch (e) {
|
|
51
|
+
// If the user calls `stream.controller.abort()`, we should exit without throwing.
|
|
52
|
+
if (e instanceof Error && e.name === 'AbortError')
|
|
53
|
+
return;
|
|
40
54
|
throw e;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
if (e instanceof Error && e.name === 'AbortError') return;
|
|
48
|
-
throw e;
|
|
49
|
-
} finally {
|
|
50
|
-
// If the user `break`s, abort the ongoing request.
|
|
51
|
-
if (!done) this.controller.abort();
|
|
55
|
+
}
|
|
56
|
+
finally {
|
|
57
|
+
// If the user `break`s, abort the ongoing request.
|
|
58
|
+
if (!done)
|
|
59
|
+
this.controller.abort();
|
|
60
|
+
}
|
|
52
61
|
}
|
|
53
|
-
}
|
|
54
62
|
}
|
|
55
63
|
class SSEDecoder {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
64
|
+
constructor() {
|
|
65
|
+
this.event = null;
|
|
66
|
+
this.data = [];
|
|
67
|
+
this.chunks = [];
|
|
68
|
+
}
|
|
69
|
+
decode(line) {
|
|
70
|
+
if (line.endsWith('\r')) {
|
|
71
|
+
line = line.substring(0, line.length - 1);
|
|
72
|
+
}
|
|
73
|
+
if (!line) {
|
|
74
|
+
// empty line and we didn't previously encounter any messages
|
|
75
|
+
if (!this.event && !this.data.length)
|
|
76
|
+
return null;
|
|
77
|
+
const sse = {
|
|
78
|
+
event: this.event,
|
|
79
|
+
data: this.data.join('\n'),
|
|
80
|
+
raw: this.chunks,
|
|
81
|
+
};
|
|
82
|
+
this.event = null;
|
|
83
|
+
this.data = [];
|
|
84
|
+
this.chunks = [];
|
|
85
|
+
return sse;
|
|
86
|
+
}
|
|
87
|
+
this.chunks.push(line);
|
|
88
|
+
if (line.startsWith(':')) {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
let [fieldname, _, value] = partition(line, ':');
|
|
92
|
+
if (value.startsWith(' ')) {
|
|
93
|
+
value = value.substring(1);
|
|
94
|
+
}
|
|
95
|
+
if (fieldname === 'event') {
|
|
96
|
+
this.event = value;
|
|
97
|
+
}
|
|
98
|
+
else if (fieldname === 'data') {
|
|
99
|
+
this.data.push(value);
|
|
100
|
+
}
|
|
101
|
+
return null;
|
|
90
102
|
}
|
|
91
|
-
return null;
|
|
92
|
-
}
|
|
93
103
|
}
|
|
94
104
|
/**
|
|
95
105
|
* A re-implementation of httpx's `LineDecoder` in Python that handles incrementally
|
|
@@ -98,87 +108,83 @@ class SSEDecoder {
|
|
|
98
108
|
* https://github.com/encode/httpx/blob/920333ea98118e9cf617f246905d7b202510941c/httpx/_decoders.py#L258
|
|
99
109
|
*/
|
|
100
110
|
class LineDecoder {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
111
|
+
constructor() {
|
|
112
|
+
this.buffer = [];
|
|
113
|
+
this.trailingCR = false;
|
|
114
|
+
}
|
|
115
|
+
decode(chunk) {
|
|
116
|
+
let text = this.decodeText(chunk);
|
|
117
|
+
if (this.trailingCR) {
|
|
118
|
+
text = '\r' + text;
|
|
119
|
+
this.trailingCR = false;
|
|
120
|
+
}
|
|
121
|
+
if (text.endsWith('\r')) {
|
|
122
|
+
this.trailingCR = true;
|
|
123
|
+
text = text.slice(0, -1);
|
|
124
|
+
}
|
|
125
|
+
if (!text) {
|
|
126
|
+
return [];
|
|
127
|
+
}
|
|
128
|
+
const trailingNewline = LineDecoder.NEWLINE_CHARS.has(text[text.length - 1] || '');
|
|
129
|
+
let lines = text.split(LineDecoder.NEWLINE_REGEXP);
|
|
130
|
+
if (lines.length === 1 && !trailingNewline) {
|
|
131
|
+
this.buffer.push(lines[0]);
|
|
132
|
+
return [];
|
|
133
|
+
}
|
|
134
|
+
if (this.buffer.length > 0) {
|
|
135
|
+
lines = [this.buffer.join('') + lines[0], ...lines.slice(1)];
|
|
136
|
+
this.buffer = [];
|
|
137
|
+
}
|
|
138
|
+
if (!trailingNewline) {
|
|
139
|
+
this.buffer = [lines.pop() || ''];
|
|
140
|
+
}
|
|
141
|
+
return lines;
|
|
142
|
+
}
|
|
143
|
+
decodeText(bytes) {
|
|
144
|
+
var _a;
|
|
145
|
+
if (bytes == null)
|
|
146
|
+
return '';
|
|
147
|
+
if (typeof bytes === 'string')
|
|
148
|
+
return bytes;
|
|
149
|
+
// Node:
|
|
150
|
+
if (typeof Buffer !== 'undefined') {
|
|
151
|
+
if (bytes instanceof Buffer) {
|
|
152
|
+
return bytes.toString();
|
|
153
|
+
}
|
|
154
|
+
if (bytes instanceof Uint8Array) {
|
|
155
|
+
return Buffer.from(bytes).toString();
|
|
156
|
+
}
|
|
157
|
+
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.`);
|
|
158
|
+
}
|
|
159
|
+
// Browser
|
|
160
|
+
if (typeof TextDecoder !== 'undefined') {
|
|
161
|
+
if (bytes instanceof Uint8Array || bytes instanceof ArrayBuffer) {
|
|
162
|
+
(_a = this.textDecoder) !== null && _a !== void 0 ? _a : (this.textDecoder = new TextDecoder('utf8'));
|
|
163
|
+
return this.textDecoder.decode(bytes);
|
|
164
|
+
}
|
|
165
|
+
throw new Error(`Unexpected: received non-Uint8Array/ArrayBuffer (${bytes.constructor.name}) in a web platform. Please report this error.`);
|
|
166
|
+
}
|
|
167
|
+
throw new Error(`Unexpected: neither Buffer nor TextDecoder are available as globals. Please report this error.`);
|
|
158
168
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
169
|
+
flush() {
|
|
170
|
+
if (!this.buffer.length && !this.trailingCR) {
|
|
171
|
+
return [];
|
|
172
|
+
}
|
|
173
|
+
const lines = [this.buffer.join('')];
|
|
174
|
+
this.buffer = [];
|
|
175
|
+
this.trailingCR = false;
|
|
176
|
+
return lines;
|
|
166
177
|
}
|
|
167
|
-
const lines = [this.buffer.join('')];
|
|
168
|
-
this.buffer = [];
|
|
169
|
-
this.trailingCR = false;
|
|
170
|
-
return lines;
|
|
171
|
-
}
|
|
172
178
|
}
|
|
173
179
|
// prettier-ignore
|
|
174
180
|
LineDecoder.NEWLINE_CHARS = new Set(['\n', '\r', '\x0b', '\x0c', '\x1c', '\x1d', '\x1e', '\x85', '\u2028', '\u2029']);
|
|
175
181
|
LineDecoder.NEWLINE_REGEXP = /\r\n|[\n\r\x0b\x0c\x1c\x1d\x1e\x85\u2028\u2029]/g;
|
|
176
182
|
function partition(str, delimiter) {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
183
|
+
const index = str.indexOf(delimiter);
|
|
184
|
+
if (index !== -1) {
|
|
185
|
+
return [str.substring(0, index), delimiter, str.substring(index + delimiter.length)];
|
|
186
|
+
}
|
|
187
|
+
return [str, '', ''];
|
|
182
188
|
}
|
|
183
189
|
/**
|
|
184
190
|
* Most browsers don't yet have async iterable support for ReadableStream,
|
|
@@ -187,28 +193,31 @@ function partition(str, delimiter) {
|
|
|
187
193
|
* This polyfill was pulled from https://github.com/MattiasBuelens/web-streams-polyfill/pull/122#issuecomment-1627354490
|
|
188
194
|
*/
|
|
189
195
|
function readableStreamAsyncIterable(stream) {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
196
|
+
if (stream[Symbol.asyncIterator])
|
|
197
|
+
return stream;
|
|
198
|
+
const reader = stream.getReader();
|
|
199
|
+
return {
|
|
200
|
+
async next() {
|
|
201
|
+
try {
|
|
202
|
+
const result = await reader.read();
|
|
203
|
+
if (result === null || result === void 0 ? void 0 : result.done)
|
|
204
|
+
reader.releaseLock(); // release lock when stream becomes closed
|
|
205
|
+
return result;
|
|
206
|
+
}
|
|
207
|
+
catch (e) {
|
|
208
|
+
reader.releaseLock(); // release lock when stream becomes errored
|
|
209
|
+
throw e;
|
|
210
|
+
}
|
|
211
|
+
},
|
|
212
|
+
async return() {
|
|
213
|
+
const cancelPromise = reader.cancel();
|
|
214
|
+
reader.releaseLock();
|
|
215
|
+
await cancelPromise;
|
|
216
|
+
return { done: true, value: undefined };
|
|
217
|
+
},
|
|
218
|
+
[Symbol.asyncIterator]() {
|
|
219
|
+
return this;
|
|
220
|
+
},
|
|
221
|
+
};
|
|
213
222
|
}
|
|
214
|
-
//# sourceMappingURL=streaming.mjs.map
|
|
223
|
+
//# sourceMappingURL=streaming.mjs.map
|
package/uploads.d.ts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import { type RequestOptions } from
|
|
2
|
-
import { type
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
import { fileFromPath } from 'openai/_shims/fileFromPath';
|
|
6
|
-
import { type FsReadStream } from 'openai/_shims/node-readable';
|
|
7
|
-
export { fileFromPath };
|
|
1
|
+
import { type RequestOptions } from "./core.js";
|
|
2
|
+
import { FormData, type Blob, type FilePropertyBag, type FsReadStream } from "./_shims/index.js";
|
|
3
|
+
import { MultipartBody } from "./_shims/MultipartBody.js";
|
|
4
|
+
export { fileFromPath } from "./_shims/index.js";
|
|
8
5
|
type BlobLikePart = string | ArrayBuffer | ArrayBufferView | BlobLike | Uint8Array | DataView;
|
|
9
6
|
export type BlobPart = string | ArrayBuffer | ArrayBufferView | Blob | Uint8Array | DataView;
|
|
10
7
|
/**
|
|
@@ -21,30 +18,30 @@ export type Uploadable = FileLike | ResponseLike | FsReadStream;
|
|
|
21
18
|
* Intended to match web.Blob, node.Blob, node-fetch.Blob, etc.
|
|
22
19
|
*/
|
|
23
20
|
export interface BlobLike {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
21
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/size) */
|
|
22
|
+
readonly size: number;
|
|
23
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/type) */
|
|
24
|
+
readonly type: string;
|
|
25
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/text) */
|
|
26
|
+
text(): Promise<string>;
|
|
27
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/slice) */
|
|
28
|
+
slice(start?: number, end?: number): BlobLike;
|
|
32
29
|
}
|
|
33
30
|
/**
|
|
34
31
|
* Intended to match web.File, node.File, node-fetch.File, etc.
|
|
35
32
|
*/
|
|
36
33
|
export interface FileLike extends BlobLike {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
34
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/File/lastModified) */
|
|
35
|
+
readonly lastModified: number;
|
|
36
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/File/name) */
|
|
37
|
+
readonly name: string;
|
|
41
38
|
}
|
|
42
39
|
/**
|
|
43
40
|
* Intended to match web.Response, node.Response, node-fetch.Response, etc.
|
|
44
41
|
*/
|
|
45
42
|
export interface ResponseLike {
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
url: string;
|
|
44
|
+
blob(): Promise<BlobLike>;
|
|
48
45
|
}
|
|
49
46
|
export declare const isResponseLike: (value: any) => value is ResponseLike;
|
|
50
47
|
export declare const isFileLike: (value: any) => value is FileLike;
|
|
@@ -53,7 +50,7 @@ export declare const isFileLike: (value: any) => value is FileLike;
|
|
|
53
50
|
* adds the arrayBuffer() method type because it is available and used at runtime
|
|
54
51
|
*/
|
|
55
52
|
export declare const isBlobLike: (value: any) => value is BlobLike & {
|
|
56
|
-
|
|
53
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
57
54
|
};
|
|
58
55
|
export declare const isUploadable: (value: any) => value is Uploadable;
|
|
59
56
|
export type ToFileInput = Uploadable | Exclude<BlobLikePart, string> | AsyncIterable<BlobLikePart>;
|
|
@@ -66,26 +63,13 @@ export type ToFileInput = Uploadable | Exclude<BlobLikePart, string> | AsyncIter
|
|
|
66
63
|
* @param {number=} options.lastModified the last modified timestamp
|
|
67
64
|
* @returns a {@link File} with the given properties
|
|
68
65
|
*/
|
|
69
|
-
export declare function toFile(
|
|
70
|
-
value: ToFileInput | PromiseLike<ToFileInput>,
|
|
71
|
-
name?: string | null | undefined,
|
|
72
|
-
options?: FilePropertyBag | undefined,
|
|
73
|
-
): Promise<FileLike>;
|
|
74
|
-
export declare class MultipartBody {
|
|
75
|
-
body: Readable | BodyInit;
|
|
76
|
-
constructor(body: Readable | BodyInit);
|
|
77
|
-
get [Symbol.toStringTag](): string;
|
|
78
|
-
}
|
|
66
|
+
export declare function toFile(value: ToFileInput | PromiseLike<ToFileInput>, name?: string | null | undefined, options?: FilePropertyBag | undefined): Promise<FileLike>;
|
|
79
67
|
export declare const isMultipartBody: (body: any) => body is MultipartBody;
|
|
80
68
|
/**
|
|
81
69
|
* Returns a multipart/form-data request if any part of the given request body contains a File / Blob value.
|
|
82
70
|
* Otherwise returns the request as is.
|
|
83
71
|
*/
|
|
84
|
-
export declare const maybeMultipartFormRequestOptions: <T extends {} = Record<string, unknown>>(
|
|
85
|
-
|
|
86
|
-
) => Promise<RequestOptions<MultipartBody | T>>;
|
|
87
|
-
export declare const multipartFormRequestOptions: <T extends {} = Record<string, unknown>>(
|
|
88
|
-
opts: RequestOptions<T>,
|
|
89
|
-
) => Promise<RequestOptions<MultipartBody | T>>;
|
|
72
|
+
export declare const maybeMultipartFormRequestOptions: <T extends {} = Record<string, unknown>>(opts: RequestOptions<T>) => Promise<RequestOptions<MultipartBody | T>>;
|
|
73
|
+
export declare const multipartFormRequestOptions: <T extends {} = Record<string, unknown>>(opts: RequestOptions<T>) => Promise<RequestOptions<MultipartBody | T>>;
|
|
90
74
|
export declare const createForm: <T = Record<string, unknown>>(body: T | undefined) => Promise<FormData>;
|
|
91
|
-
//# sourceMappingURL=uploads.d.ts.map
|
|
75
|
+
//# sourceMappingURL=uploads.d.ts.map
|
package/uploads.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uploads.d.ts","sourceRoot":"","sources":["src/uploads.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"uploads.d.ts","sourceRoot":"","sources":["src/uploads.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,QAAQ,CAAC;AAC7C,OAAO,EACL,QAAQ,EAER,KAAK,IAAI,EACT,KAAK,eAAe,EAEpB,KAAK,YAAY,EAElB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,KAAK,YAAY,GAAG,MAAM,GAAG,WAAW,GAAG,eAAe,GAAG,QAAQ,GAAG,UAAU,GAAG,QAAQ,CAAC;AAC9F,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,WAAW,GAAG,eAAe,GAAG,IAAI,GAAG,UAAU,GAAG,QAAQ,CAAC;AAE7F;;;;;;;;GAQG;AACH,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,YAAY,GAAG,YAAY,CAAC;AAEhE;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,4EAA4E;IAC5E,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,4EAA4E;IAC5E,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,4EAA4E;IAC5E,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IACxB,6EAA6E;IAC7E,KAAK,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,QAAQ,CAAC;CAE/C;AAED;;GAEG;AACH,MAAM,WAAW,QAAS,SAAQ,QAAQ;IACxC,oFAAoF;IACpF,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,4EAA4E;IAC5E,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,IAAI,OAAO,CAAC,QAAQ,CAAC,CAAC;CAC3B;AAED,eAAO,MAAM,cAAc,UAAW,GAAG,0BAIP,CAAC;AAEnC,eAAO,MAAM,UAAU,UAAW,GAAG,sBAKlB,CAAC;AAEpB;;;GAGG;AACH,eAAO,MAAM,UAAU,UAAW,GAAG;mBAAwC,QAAQ,WAAW,CAAC;CAOxD,CAAC;AAE1C,eAAO,MAAM,YAAY,UAAW,GAAG,wBAEtC,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG,UAAU,GAAG,OAAO,CAAC,YAAY,EAAE,MAAM,CAAC,GAAG,aAAa,CAAC,YAAY,CAAC,CAAC;AAEnG;;;;;;;;GAQG;AACH,wBAAsB,MAAM,CAC1B,KAAK,EAAE,WAAW,GAAG,WAAW,CAAC,WAAW,CAAC,EAC7C,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAChC,OAAO,GAAE,eAAe,GAAG,SAAc,GACxC,OAAO,CAAC,QAAQ,CAAC,CAuBnB;AAoDD,eAAO,MAAM,eAAe,SAAU,GAAG,0BACsD,CAAC;AAEhG;;;GAGG;AACH,eAAO,MAAM,gCAAgC,iHAO5C,CAAC;AAEF,eAAO,MAAM,2BAA2B,iHAKvC,CAAC;AAEF,eAAO,MAAM,UAAU,wDAA6D,QAAQ,QAAQ,CAInG,CAAC"}
|