@anthropic-ai/sdk 0.6.2 → 0.6.8
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 +117 -0
- package/README.md +16 -6
- 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 +101 -0
- package/{src/_shims/ReadableStream.js → _shims/auto/types.js} +0 -2
- package/_shims/{ReadableStream.js → 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 +81 -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 +90 -0
- package/_shims/node-runtime.js.map +1 -0
- package/_shims/node-runtime.mjs +56 -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 +37 -0
- package/_shims/registry.d.ts.map +1 -0
- package/_shims/registry.js +41 -0
- package/_shims/registry.js.map +1 -0
- package/_shims/registry.mjs +37 -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 +78 -0
- package/_shims/web-runtime.js.map +1 -0
- package/_shims/web-runtime.mjs +71 -0
- package/_shims/web-runtime.mjs.map +1 -0
- package/_shims/web-types.d.ts +83 -0
- package/_shims/web-types.js +3 -0
- package/_shims/web-types.mjs +3 -0
- package/core.d.ts +172 -224
- package/core.d.ts.map +1 -1
- package/core.js +701 -736
- package/core.js.map +1 -1
- package/core.mjs +694 -688
- package/core.mjs.map +1 -1
- package/error.d.ts +32 -32
- package/error.d.ts.map +1 -1
- package/error.js +105 -106
- package/error.js.map +1 -1
- package/error.mjs +101 -91
- package/error.mjs.map +1 -1
- package/index.d.mts +110 -117
- package/index.d.ts +110 -117
- package/index.d.ts.map +1 -1
- package/index.js +107 -159
- package/index.js.map +1 -1
- package/index.mjs +84 -104
- package/index.mjs.map +1 -1
- package/package.json +36 -21
- package/resource.d.ts +10 -10
- package/resource.js +12 -12
- package/resource.mjs +10 -10
- package/resources/completions.d.ts +136 -142
- package/resources/completions.d.ts.map +1 -1
- package/resources/completions.js +9 -14
- package/resources/completions.js.map +1 -1
- package/resources/completions.mjs +6 -11
- package/resources/completions.mjs.map +1 -1
- package/resources/index.d.ts +2 -9
- package/resources/index.d.ts.map +1 -1
- package/resources/index.js +5 -10
- package/resources/index.js.map +1 -1
- package/resources/index.mjs +2 -2
- package/resources/index.mjs.map +1 -1
- package/resources/top-level.d.ts +1 -1
- package/resources/top-level.js +3 -3
- package/resources/top-level.mjs +1 -1
- 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 +101 -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 +81 -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 +83 -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 +67 -0
- package/src/_shims/web-runtime.ts +103 -0
- package/src/_shims/web-types.d.ts +83 -0
- package/src/_shims/web-types.js +3 -0
- package/src/_shims/web-types.mjs +3 -0
- package/src/core.ts +107 -56
- package/src/error.ts +20 -8
- package/src/index.ts +24 -17
- package/src/resources/completions.ts +11 -11
- package/src/resources/index.ts +0 -1
- package/src/shims/node.ts +50 -0
- package/src/shims/web.ts +50 -0
- package/src/streaming.ts +164 -59
- package/src/tsconfig.json +11 -0
- package/src/uploads.ts +11 -15
- package/src/version.ts +1 -1
- package/streaming.d.ts +11 -8
- package/streaming.d.ts.map +1 -1
- package/streaming.js +300 -192
- package/streaming.js.map +1 -1
- package/streaming.mjs +296 -188
- package/streaming.mjs.map +1 -1
- package/uploads.d.ts +23 -39
- package/uploads.d.ts.map +1 -1
- package/uploads.js +111 -157
- package/uploads.js.map +1 -1
- package/uploads.mjs +107 -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.d.ts +0 -38
- package/_shims/ReadableStream.mjs +0 -7
- 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/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/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/fetch.d.ts +0 -60
- package/_shims/fetch.js +0 -13
- package/_shims/fetch.mjs +0 -15
- package/_shims/fetch.node.d.ts +0 -64
- package/_shims/fetch.node.js +0 -12
- package/_shims/fetch.node.mjs +0 -14
- 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/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/formdata.d.ts +0 -43
- package/_shims/formdata.js +0 -17
- package/_shims/formdata.mjs +0 -20
- package/_shims/formdata.node.d.ts +0 -45
- package/_shims/formdata.node.js +0 -11
- package/_shims/formdata.node.mjs +0 -9
- 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/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/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/_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/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.d.ts +0 -60
- package/src/_shims/fetch.deno.ts +0 -23
- package/src/_shims/fetch.js +0 -13
- package/src/_shims/fetch.mjs +0 -15
- 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/fileFromPath.node.ts +0 -29
- package/src/_shims/fileFromPath.ts +0 -29
- package/src/_shims/formdata.d.ts +0 -43
- package/src/_shims/formdata.deno.ts +0 -16
- package/src/_shims/formdata.js +0 -17
- package/src/_shims/formdata.mjs +0 -20
- package/src/_shims/formdata.node.d.ts +0 -45
- package/src/_shims/formdata.node.js +0 -11
- package/src/_shims/formdata.node.mjs +0 -9
- 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,106 +1,216 @@
|
|
|
1
|
+
import { ReadableStream } from "./_shims/index.mjs";
|
|
2
|
+
import { AnthropicError } from "./error.mjs";
|
|
1
3
|
import { safeJSON, createResponseHeaders } from '@anthropic-ai/sdk/core';
|
|
2
4
|
import { APIError } from '@anthropic-ai/sdk/error';
|
|
3
5
|
export class Stream {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
this.decoder = new SSEDecoder();
|
|
8
|
-
}
|
|
9
|
-
async *iterMessages() {
|
|
10
|
-
if (!this.response.body) {
|
|
11
|
-
this.controller.abort();
|
|
12
|
-
throw new Error(`Attempted to iterate over a response with no body`);
|
|
6
|
+
constructor(iterator, controller) {
|
|
7
|
+
this.iterator = iterator;
|
|
8
|
+
this.controller = controller;
|
|
13
9
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
10
|
+
static fromSSEResponse(response, controller) {
|
|
11
|
+
let consumed = false;
|
|
12
|
+
const decoder = new SSEDecoder();
|
|
13
|
+
async function* iterMessages() {
|
|
14
|
+
if (!response.body) {
|
|
15
|
+
controller.abort();
|
|
16
|
+
throw new AnthropicError(`Attempted to iterate over a response with no body`);
|
|
17
|
+
}
|
|
18
|
+
const lineDecoder = new LineDecoder();
|
|
19
|
+
const iter = readableStreamAsyncIterable(response.body);
|
|
20
|
+
for await (const chunk of iter) {
|
|
21
|
+
for (const line of lineDecoder.decode(chunk)) {
|
|
22
|
+
const sse = decoder.decode(line);
|
|
23
|
+
if (sse)
|
|
24
|
+
yield sse;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
for (const line of lineDecoder.flush()) {
|
|
28
|
+
const sse = decoder.decode(line);
|
|
29
|
+
if (sse)
|
|
30
|
+
yield sse;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
async function* iterator() {
|
|
34
|
+
if (consumed) {
|
|
35
|
+
throw new Error('Cannot iterate over a consumed stream, use `.tee()` to split the stream.');
|
|
36
|
+
}
|
|
37
|
+
consumed = true;
|
|
38
|
+
let done = false;
|
|
39
|
+
try {
|
|
40
|
+
for await (const sse of iterMessages()) {
|
|
41
|
+
if (sse.event === 'completion') {
|
|
42
|
+
try {
|
|
43
|
+
yield JSON.parse(sse.data);
|
|
44
|
+
}
|
|
45
|
+
catch (e) {
|
|
46
|
+
console.error(`Could not parse message into JSON:`, sse.data);
|
|
47
|
+
console.error(`From chunk:`, sse.raw);
|
|
48
|
+
throw e;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (sse.event === 'ping') {
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
if (sse.event === 'error') {
|
|
55
|
+
const errText = sse.data;
|
|
56
|
+
const errJSON = safeJSON(errText);
|
|
57
|
+
const errMessage = errJSON ? undefined : errText;
|
|
58
|
+
throw APIError.generate(undefined, errJSON, errMessage, createResponseHeaders(response.headers));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
done = true;
|
|
62
|
+
}
|
|
63
|
+
catch (e) {
|
|
64
|
+
// If the user calls `stream.controller.abort()`, we should exit without throwing.
|
|
65
|
+
if (e instanceof Error && e.name === 'AbortError')
|
|
66
|
+
return;
|
|
67
|
+
throw e;
|
|
68
|
+
}
|
|
69
|
+
finally {
|
|
70
|
+
// If the user `break`s, abort the ongoing request.
|
|
71
|
+
if (!done)
|
|
72
|
+
controller.abort();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return new Stream(iterator, controller);
|
|
25
76
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
77
|
+
// Generates a Stream from a newline-separated ReadableStream where each item
|
|
78
|
+
// is a JSON Value.
|
|
79
|
+
static fromReadableStream(readableStream, controller) {
|
|
80
|
+
let consumed = false;
|
|
81
|
+
async function* iterLines() {
|
|
82
|
+
const lineDecoder = new LineDecoder();
|
|
83
|
+
const iter = readableStreamAsyncIterable(readableStream);
|
|
84
|
+
for await (const chunk of iter) {
|
|
85
|
+
for (const line of lineDecoder.decode(chunk)) {
|
|
86
|
+
yield line;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
for (const line of lineDecoder.flush()) {
|
|
90
|
+
yield line;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
async function* iterator() {
|
|
94
|
+
if (consumed) {
|
|
95
|
+
throw new Error('Cannot iterate over a consumed stream, use `.tee()` to split the stream.');
|
|
96
|
+
}
|
|
97
|
+
consumed = true;
|
|
98
|
+
let done = false;
|
|
99
|
+
try {
|
|
100
|
+
for await (const line of iterLines()) {
|
|
101
|
+
if (done)
|
|
102
|
+
continue;
|
|
103
|
+
if (line)
|
|
104
|
+
yield JSON.parse(line);
|
|
105
|
+
}
|
|
106
|
+
done = true;
|
|
107
|
+
}
|
|
108
|
+
catch (e) {
|
|
109
|
+
// If the user calls `stream.controller.abort()`, we should exit without throwing.
|
|
110
|
+
if (e instanceof Error && e.name === 'AbortError')
|
|
111
|
+
return;
|
|
112
|
+
throw e;
|
|
113
|
+
}
|
|
114
|
+
finally {
|
|
115
|
+
// If the user `break`s, abort the ongoing request.
|
|
116
|
+
if (!done)
|
|
117
|
+
controller.abort();
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return new Stream(iterator, controller);
|
|
63
121
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
class SSEDecoder {
|
|
67
|
-
constructor() {
|
|
68
|
-
this.event = null;
|
|
69
|
-
this.data = [];
|
|
70
|
-
this.chunks = [];
|
|
71
|
-
}
|
|
72
|
-
decode(line) {
|
|
73
|
-
if (line.endsWith('\r')) {
|
|
74
|
-
line = line.substring(0, line.length - 1);
|
|
122
|
+
[Symbol.asyncIterator]() {
|
|
123
|
+
return this.iterator();
|
|
75
124
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
125
|
+
tee() {
|
|
126
|
+
const left = [];
|
|
127
|
+
const right = [];
|
|
128
|
+
const iterator = this.iterator();
|
|
129
|
+
const teeIterator = (queue) => {
|
|
130
|
+
return {
|
|
131
|
+
next: () => {
|
|
132
|
+
if (queue.length === 0) {
|
|
133
|
+
const result = iterator.next();
|
|
134
|
+
left.push(result);
|
|
135
|
+
right.push(result);
|
|
136
|
+
}
|
|
137
|
+
return queue.shift();
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
};
|
|
141
|
+
return [
|
|
142
|
+
new Stream(() => teeIterator(left), this.controller),
|
|
143
|
+
new Stream(() => teeIterator(right), this.controller),
|
|
144
|
+
];
|
|
88
145
|
}
|
|
89
|
-
this
|
|
90
|
-
|
|
91
|
-
|
|
146
|
+
// Converts this stream to a newline-separated ReadableStream of JSON Stringified values in the stream
|
|
147
|
+
// which can be turned back into a Stream with Stream.fromReadableStream.
|
|
148
|
+
toReadableStream() {
|
|
149
|
+
const self = this;
|
|
150
|
+
let iter;
|
|
151
|
+
const encoder = new TextEncoder();
|
|
152
|
+
return new ReadableStream({
|
|
153
|
+
async start() {
|
|
154
|
+
iter = self[Symbol.asyncIterator]();
|
|
155
|
+
},
|
|
156
|
+
async pull(ctrl) {
|
|
157
|
+
try {
|
|
158
|
+
const { value, done } = await iter.next();
|
|
159
|
+
if (done)
|
|
160
|
+
return ctrl.close();
|
|
161
|
+
const bytes = encoder.encode(JSON.stringify(value) + '\n');
|
|
162
|
+
ctrl.enqueue(bytes);
|
|
163
|
+
}
|
|
164
|
+
catch (err) {
|
|
165
|
+
ctrl.error(err);
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
async cancel() {
|
|
169
|
+
await iter.return?.();
|
|
170
|
+
},
|
|
171
|
+
});
|
|
92
172
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
173
|
+
}
|
|
174
|
+
class SSEDecoder {
|
|
175
|
+
constructor() {
|
|
176
|
+
this.event = null;
|
|
177
|
+
this.data = [];
|
|
178
|
+
this.chunks = [];
|
|
96
179
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
180
|
+
decode(line) {
|
|
181
|
+
if (line.endsWith('\r')) {
|
|
182
|
+
line = line.substring(0, line.length - 1);
|
|
183
|
+
}
|
|
184
|
+
if (!line) {
|
|
185
|
+
// empty line and we didn't previously encounter any messages
|
|
186
|
+
if (!this.event && !this.data.length)
|
|
187
|
+
return null;
|
|
188
|
+
const sse = {
|
|
189
|
+
event: this.event,
|
|
190
|
+
data: this.data.join('\n'),
|
|
191
|
+
raw: this.chunks,
|
|
192
|
+
};
|
|
193
|
+
this.event = null;
|
|
194
|
+
this.data = [];
|
|
195
|
+
this.chunks = [];
|
|
196
|
+
return sse;
|
|
197
|
+
}
|
|
198
|
+
this.chunks.push(line);
|
|
199
|
+
if (line.startsWith(':')) {
|
|
200
|
+
return null;
|
|
201
|
+
}
|
|
202
|
+
let [fieldname, _, value] = partition(line, ':');
|
|
203
|
+
if (value.startsWith(' ')) {
|
|
204
|
+
value = value.substring(1);
|
|
205
|
+
}
|
|
206
|
+
if (fieldname === 'event') {
|
|
207
|
+
this.event = value;
|
|
208
|
+
}
|
|
209
|
+
else if (fieldname === 'data') {
|
|
210
|
+
this.data.push(value);
|
|
211
|
+
}
|
|
212
|
+
return null;
|
|
101
213
|
}
|
|
102
|
-
return null;
|
|
103
|
-
}
|
|
104
214
|
}
|
|
105
215
|
/**
|
|
106
216
|
* A re-implementation of httpx's `LineDecoder` in Python that handles incrementally
|
|
@@ -109,87 +219,82 @@ class SSEDecoder {
|
|
|
109
219
|
* https://github.com/encode/httpx/blob/920333ea98118e9cf617f246905d7b202510941c/httpx/_decoders.py#L258
|
|
110
220
|
*/
|
|
111
221
|
class LineDecoder {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
decode(chunk) {
|
|
117
|
-
let text = this.decodeText(chunk);
|
|
118
|
-
if (this.trailingCR) {
|
|
119
|
-
text = '\r' + text;
|
|
120
|
-
this.trailingCR = false;
|
|
222
|
+
constructor() {
|
|
223
|
+
this.buffer = [];
|
|
224
|
+
this.trailingCR = false;
|
|
121
225
|
}
|
|
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
|
-
if (typeof Buffer !== 'undefined') {
|
|
150
|
-
if (bytes instanceof Buffer) {
|
|
151
|
-
return bytes.toString();
|
|
152
|
-
}
|
|
153
|
-
if (bytes instanceof Uint8Array) {
|
|
154
|
-
return Buffer.from(bytes).toString();
|
|
155
|
-
}
|
|
156
|
-
throw new Error(
|
|
157
|
-
`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
|
-
);
|
|
226
|
+
decode(chunk) {
|
|
227
|
+
let text = this.decodeText(chunk);
|
|
228
|
+
if (this.trailingCR) {
|
|
229
|
+
text = '\r' + text;
|
|
230
|
+
this.trailingCR = false;
|
|
231
|
+
}
|
|
232
|
+
if (text.endsWith('\r')) {
|
|
233
|
+
this.trailingCR = true;
|
|
234
|
+
text = text.slice(0, -1);
|
|
235
|
+
}
|
|
236
|
+
if (!text) {
|
|
237
|
+
return [];
|
|
238
|
+
}
|
|
239
|
+
const trailingNewline = LineDecoder.NEWLINE_CHARS.has(text[text.length - 1] || '');
|
|
240
|
+
let lines = text.split(LineDecoder.NEWLINE_REGEXP);
|
|
241
|
+
if (lines.length === 1 && !trailingNewline) {
|
|
242
|
+
this.buffer.push(lines[0]);
|
|
243
|
+
return [];
|
|
244
|
+
}
|
|
245
|
+
if (this.buffer.length > 0) {
|
|
246
|
+
lines = [this.buffer.join('') + lines[0], ...lines.slice(1)];
|
|
247
|
+
this.buffer = [];
|
|
248
|
+
}
|
|
249
|
+
if (!trailingNewline) {
|
|
250
|
+
this.buffer = [lines.pop() || ''];
|
|
251
|
+
}
|
|
252
|
+
return lines;
|
|
159
253
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
254
|
+
decodeText(bytes) {
|
|
255
|
+
if (bytes == null)
|
|
256
|
+
return '';
|
|
257
|
+
if (typeof bytes === 'string')
|
|
258
|
+
return bytes;
|
|
259
|
+
// Node:
|
|
260
|
+
if (typeof Buffer !== 'undefined') {
|
|
261
|
+
if (bytes instanceof Buffer) {
|
|
262
|
+
return bytes.toString();
|
|
263
|
+
}
|
|
264
|
+
if (bytes instanceof Uint8Array) {
|
|
265
|
+
return Buffer.from(bytes).toString();
|
|
266
|
+
}
|
|
267
|
+
throw new AnthropicError(`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.`);
|
|
268
|
+
}
|
|
269
|
+
// Browser
|
|
270
|
+
if (typeof TextDecoder !== 'undefined') {
|
|
271
|
+
if (bytes instanceof Uint8Array || bytes instanceof ArrayBuffer) {
|
|
272
|
+
this.textDecoder ?? (this.textDecoder = new TextDecoder('utf8'));
|
|
273
|
+
return this.textDecoder.decode(bytes);
|
|
274
|
+
}
|
|
275
|
+
throw new AnthropicError(`Unexpected: received non-Uint8Array/ArrayBuffer (${bytes.constructor.name}) in a web platform. Please report this error.`);
|
|
276
|
+
}
|
|
277
|
+
throw new AnthropicError(`Unexpected: neither Buffer nor TextDecoder are available as globals. Please report this error.`);
|
|
169
278
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
279
|
+
flush() {
|
|
280
|
+
if (!this.buffer.length && !this.trailingCR) {
|
|
281
|
+
return [];
|
|
282
|
+
}
|
|
283
|
+
const lines = [this.buffer.join('')];
|
|
284
|
+
this.buffer = [];
|
|
285
|
+
this.trailingCR = false;
|
|
286
|
+
return lines;
|
|
177
287
|
}
|
|
178
|
-
const lines = [this.buffer.join('')];
|
|
179
|
-
this.buffer = [];
|
|
180
|
-
this.trailingCR = false;
|
|
181
|
-
return lines;
|
|
182
|
-
}
|
|
183
288
|
}
|
|
184
289
|
// prettier-ignore
|
|
185
290
|
LineDecoder.NEWLINE_CHARS = new Set(['\n', '\r', '\x0b', '\x0c', '\x1c', '\x1d', '\x1e', '\x85', '\u2028', '\u2029']);
|
|
186
291
|
LineDecoder.NEWLINE_REGEXP = /\r\n|[\n\r\x0b\x0c\x1c\x1d\x1e\x85\u2028\u2029]/g;
|
|
187
292
|
function partition(str, delimiter) {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
293
|
+
const index = str.indexOf(delimiter);
|
|
294
|
+
if (index !== -1) {
|
|
295
|
+
return [str.substring(0, index), delimiter, str.substring(index + delimiter.length)];
|
|
296
|
+
}
|
|
297
|
+
return [str, '', ''];
|
|
193
298
|
}
|
|
194
299
|
/**
|
|
195
300
|
* Most browsers don't yet have async iterable support for ReadableStream,
|
|
@@ -198,28 +303,31 @@ function partition(str, delimiter) {
|
|
|
198
303
|
* This polyfill was pulled from https://github.com/MattiasBuelens/web-streams-polyfill/pull/122#issuecomment-1627354490
|
|
199
304
|
*/
|
|
200
305
|
function readableStreamAsyncIterable(stream) {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
306
|
+
if (stream[Symbol.asyncIterator])
|
|
307
|
+
return stream;
|
|
308
|
+
const reader = stream.getReader();
|
|
309
|
+
return {
|
|
310
|
+
async next() {
|
|
311
|
+
try {
|
|
312
|
+
const result = await reader.read();
|
|
313
|
+
if (result?.done)
|
|
314
|
+
reader.releaseLock(); // release lock when stream becomes closed
|
|
315
|
+
return result;
|
|
316
|
+
}
|
|
317
|
+
catch (e) {
|
|
318
|
+
reader.releaseLock(); // release lock when stream becomes errored
|
|
319
|
+
throw e;
|
|
320
|
+
}
|
|
321
|
+
},
|
|
322
|
+
async return() {
|
|
323
|
+
const cancelPromise = reader.cancel();
|
|
324
|
+
reader.releaseLock();
|
|
325
|
+
await cancelPromise;
|
|
326
|
+
return { done: true, value: undefined };
|
|
327
|
+
},
|
|
328
|
+
[Symbol.asyncIterator]() {
|
|
329
|
+
return this;
|
|
330
|
+
},
|
|
331
|
+
};
|
|
224
332
|
}
|
|
225
|
-
//# sourceMappingURL=streaming.mjs.map
|
|
333
|
+
//# sourceMappingURL=streaming.mjs.map
|
package/streaming.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"streaming.mjs","sourceRoot":"","sources":["src/streaming.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"streaming.mjs","sourceRoot":"","sources":["src/streaming.ts"],"names":[],"mappings":"OAAO,EAAE,cAAc,EAAiB;OACjC,EAAE,cAAc,EAAE;OAElB,EAAE,QAAQ,EAAE,qBAAqB,EAAE,MAAM,wBAAwB;OACjE,EAAE,QAAQ,EAAE,MAAM,yBAAyB;AAUlD,MAAM,OAAO,MAAM;IAGjB,YAAoB,QAAmC,EAAE,UAA2B;Q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