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