@anthropic-ai/sdk 0.5.1 → 0.5.2
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/LICENSE +8 -0
- package/README.md +305 -0
- package/package.json +1 -1
- package/src/streaming.ts +71 -11
- package/src/version.ts +1 -1
- package/streaming.d.ts.map +1 -1
- package/streaming.js +58 -10
- package/streaming.js.map +1 -1
- package/streaming.mjs +58 -10
- package/streaming.mjs.map +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
Copyright 2023 Anthropic, PBC.
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
8
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
# Anthropic TypeScript API Library
|
|
2
|
+
|
|
3
|
+
[](https://npmjs.org/package/@anthropic-ai/sdk)
|
|
4
|
+
|
|
5
|
+
The Anthropic TypeScript library provides convenient access to the Anthropic REST API from applications written in server-side JavaScript.
|
|
6
|
+
It includes TypeScript definitions for all request params and response fields.
|
|
7
|
+
|
|
8
|
+
## Migration from v0.4.x and below
|
|
9
|
+
|
|
10
|
+
In `v0.5.0`, we introduced a fully rewritten SDK. The new version offers better error handling, a more robust and intuitive streaming implementation, and more.
|
|
11
|
+
|
|
12
|
+
Key interface changes:
|
|
13
|
+
|
|
14
|
+
1. `new Client(apiKey)` → `new Anthropic({ apiKey })`
|
|
15
|
+
2. `client.complete()` → `client.completions.create()`
|
|
16
|
+
3. `client.completeStream()` → `client.completions.create({ stream: true })`
|
|
17
|
+
1. `onUpdate` callback → `for await (const x of stream)`
|
|
18
|
+
2. full message in stream → delta of message in stream
|
|
19
|
+
|
|
20
|
+
<details>
|
|
21
|
+
<summary>Example diff</summary>
|
|
22
|
+
|
|
23
|
+
```diff ts
|
|
24
|
+
// Import "Anthropic" instead of "Client":
|
|
25
|
+
- import { Client, HUMAN_PROMPT, AI_PROMPT } from '@anthropic-ai/sdk';
|
|
26
|
+
+ import Anthropic, { HUMAN_PROMPT, AI_PROMPT } from '@anthropic-ai/sdk';
|
|
27
|
+
|
|
28
|
+
// Instantiate with "apiKey" as an object property:
|
|
29
|
+
- const client = new Client(apiKey);
|
|
30
|
+
+ const client = new Anthropic({ apiKey });
|
|
31
|
+
// or, simply provide an ANTHROPIC_API_KEY environment variable:
|
|
32
|
+
+ const client = new Anthropic();
|
|
33
|
+
|
|
34
|
+
async function main() {
|
|
35
|
+
// Request & response types are the same as before, but better-typed.
|
|
36
|
+
const params = {
|
|
37
|
+
prompt: `${HUMAN_PROMPT} How many toes do dogs have?${AI_PROMPT}`,
|
|
38
|
+
max_tokens_to_sample: 200,
|
|
39
|
+
model: "claude-1",
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// Instead of "client.complete()", you now call "client.completions.create()":
|
|
43
|
+
- await client.complete(params);
|
|
44
|
+
+ await client.completions.create(params);
|
|
45
|
+
|
|
46
|
+
// Streaming requests now use async iterators instead of callbacks:
|
|
47
|
+
- client.completeStream(params, {
|
|
48
|
+
- onUpdate: (completion) => {
|
|
49
|
+
- console.log(completion.completion); // full text
|
|
50
|
+
- },
|
|
51
|
+
- });
|
|
52
|
+
+ const stream = await client.completions.create({ ...params, stream: true });
|
|
53
|
+
+ for await (const completion of stream) {
|
|
54
|
+
+ process.stdout.write(completion.completion); // incremental text
|
|
55
|
+
+ }
|
|
56
|
+
|
|
57
|
+
// And, since this library uses `Anthropic-Version: 2023-06-01`,
|
|
58
|
+
// completion streams are now incremental diffs of text
|
|
59
|
+
// rather than sending the whole message every time:
|
|
60
|
+
let text = '';
|
|
61
|
+
- await client.completeStream(params, {
|
|
62
|
+
- onUpdate: (completion) => {
|
|
63
|
+
- const diff = completion.completion.replace(text, "");
|
|
64
|
+
- text = completion.completion;
|
|
65
|
+
- process.stdout.write(diff);
|
|
66
|
+
- },
|
|
67
|
+
- });
|
|
68
|
+
+ const stream = await client.completions.create({ ...params, stream: true });
|
|
69
|
+
+ for await (const completion of stream) {
|
|
70
|
+
+ const diff = completion.completion;
|
|
71
|
+
+ text += diff;
|
|
72
|
+
+ process.stdout.write(diff);
|
|
73
|
+
+ }
|
|
74
|
+
console.log('Done; final text is:')
|
|
75
|
+
console.log(text)
|
|
76
|
+
}
|
|
77
|
+
main();
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
</details>
|
|
81
|
+
|
|
82
|
+
## Documentation
|
|
83
|
+
|
|
84
|
+
The API documentation can be found [here](https://docs.anthropic.com/claude/reference/).
|
|
85
|
+
|
|
86
|
+
## Installation
|
|
87
|
+
|
|
88
|
+
```sh
|
|
89
|
+
npm install --save @anthropic-ai/sdk
|
|
90
|
+
# or
|
|
91
|
+
yarn add @anthropic-ai/sdk
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Usage
|
|
95
|
+
|
|
96
|
+
```js
|
|
97
|
+
import Anthropic from '@anthropic-ai/sdk';
|
|
98
|
+
|
|
99
|
+
const anthropic = new Anthropic({
|
|
100
|
+
apiKey: 'my api key', // defaults to process.env["ANTHROPIC_API_KEY"]
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
async function main() {
|
|
104
|
+
const completion = await anthropic.completions.create({
|
|
105
|
+
model: 'claude-1',
|
|
106
|
+
max_tokens_to_sample: 300,
|
|
107
|
+
prompt: `${Anthropic.HUMAN_PROMPT} how does a court case get to the Supreme Court? ${Anthropic.AI_PROMPT}`,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
main().catch(console.error);
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Streaming Responses
|
|
114
|
+
|
|
115
|
+
We provide support for streaming responses using Server Side Events (SSE).
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
import Anthropic from '@anthropic-ai/sdk';
|
|
119
|
+
|
|
120
|
+
const anthropic = new Anthropic();
|
|
121
|
+
|
|
122
|
+
const stream = await anthropic.completions.create({
|
|
123
|
+
prompt: `${Anthropic.HUMAN_PROMPT} Your prompt here ${Anthropic.AI_PROMPT}`,
|
|
124
|
+
model: 'claude-1',
|
|
125
|
+
stream: true,
|
|
126
|
+
max_tokens_to_sample: 300,
|
|
127
|
+
});
|
|
128
|
+
for await (const completion of stream) {
|
|
129
|
+
console.log(completion.completion);
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
If you need to cancel a stream, you can `break` from the loop
|
|
134
|
+
or call `stream.controller.abort()`.
|
|
135
|
+
|
|
136
|
+
### Usage with TypeScript
|
|
137
|
+
|
|
138
|
+
Importing, instantiating, and interacting with the library are the same as above.
|
|
139
|
+
If you like, you may reference our types directly:
|
|
140
|
+
|
|
141
|
+
```ts
|
|
142
|
+
import Anthropic from '@anthropic-ai/sdk';
|
|
143
|
+
|
|
144
|
+
const anthropic = new Anthropic({
|
|
145
|
+
apiKey: 'my api key', // defaults to process.env["ANTHROPIC_API_KEY"]
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
async function main() {
|
|
149
|
+
const params: Anthropic.CompletionCreateParams = {
|
|
150
|
+
prompt: `${Anthropic.HUMAN_PROMPT} how does a court case get to the Supreme Court? ${Anthropic.AI_PROMPT}`,
|
|
151
|
+
max_tokens_to_sample: 300,
|
|
152
|
+
model: 'claude-1',
|
|
153
|
+
};
|
|
154
|
+
const completion: Anthropic.Completion = await anthropic.completions.create(params);
|
|
155
|
+
}
|
|
156
|
+
main().catch(console.error);
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
Documentation for each method, request param, and response field are available in docstrings and will appear on hover in most modern editors.
|
|
160
|
+
|
|
161
|
+
## Handling errors
|
|
162
|
+
|
|
163
|
+
When the library is unable to connect to the API,
|
|
164
|
+
or if the API returns a non-success status code (i.e., 4xx or 5xx response),
|
|
165
|
+
a subclass of `APIError` will be thrown:
|
|
166
|
+
|
|
167
|
+
```ts
|
|
168
|
+
async function main() {
|
|
169
|
+
const completion = await anthropic.completions
|
|
170
|
+
.create({
|
|
171
|
+
prompt: `${Anthropic.HUMAN_PROMPT} Your prompt here ${Anthropic.AI_PROMPT}`,
|
|
172
|
+
max_tokens_to_sample: 300,
|
|
173
|
+
model: 'claude-1',
|
|
174
|
+
})
|
|
175
|
+
.catch((err) => {
|
|
176
|
+
if (err instanceof Anthropic.APIError) {
|
|
177
|
+
console.log(err.status); // 400
|
|
178
|
+
console.log(err.name); // BadRequestError
|
|
179
|
+
console.log(err.headers); // {server: 'nginx', ...}
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
main().catch(console.error);
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
Error codes are as followed:
|
|
187
|
+
|
|
188
|
+
| Status Code | Error Type |
|
|
189
|
+
| ----------- | -------------------------- |
|
|
190
|
+
| 400 | `BadRequestError` |
|
|
191
|
+
| 401 | `AuthenticationError` |
|
|
192
|
+
| 403 | `PermissionDeniedError` |
|
|
193
|
+
| 404 | `NotFoundError` |
|
|
194
|
+
| 422 | `UnprocessableEntityError` |
|
|
195
|
+
| 429 | `RateLimitError` |
|
|
196
|
+
| >=500 | `InternalServerError` |
|
|
197
|
+
| N/A | `APIConnectionError` |
|
|
198
|
+
|
|
199
|
+
### Retries
|
|
200
|
+
|
|
201
|
+
Certain errors will be automatically retried 2 times by default, with a short exponential backoff.
|
|
202
|
+
Connection errors (for example, due to a network connectivity problem), 409 Conflict, 429 Rate Limit,
|
|
203
|
+
and >=500 Internal errors will all be retried by default.
|
|
204
|
+
|
|
205
|
+
You can use the `maxRetries` option to configure or disable this:
|
|
206
|
+
|
|
207
|
+
<!-- prettier-ignore -->
|
|
208
|
+
```js
|
|
209
|
+
// Configure the default for all requests:
|
|
210
|
+
const anthropic = new Anthropic({
|
|
211
|
+
maxRetries: 0, // default is 2
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
// Or, configure per-request:
|
|
215
|
+
await anthropic.completions.create(
|
|
216
|
+
{
|
|
217
|
+
prompt: `${Anthropic.HUMAN_PROMPT} Can you help me effectively ask for a raise at work? ${Anthropic.AI_PROMPT}`,
|
|
218
|
+
max_tokens_to_sample: 300,
|
|
219
|
+
model: 'claude-1',
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
maxRetries: 5,
|
|
223
|
+
},
|
|
224
|
+
);
|
|
225
|
+
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
### Timeouts
|
|
229
|
+
|
|
230
|
+
Requests time out after 60 seconds by default. You can configure this with a `timeout` option:
|
|
231
|
+
|
|
232
|
+
<!-- prettier-ignore -->
|
|
233
|
+
```ts
|
|
234
|
+
// Configure the default for all requests:
|
|
235
|
+
const anthropic = new Anthropic({
|
|
236
|
+
timeout: 20 * 1000, // 20 seconds (default is 60s)
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
// Override per-request:
|
|
240
|
+
await anthropic.completions.create(
|
|
241
|
+
{
|
|
242
|
+
prompt: `${Anthropic.HUMAN_PROMPT} Where can I get a good coffee in my neighbourhood? ${Anthropic.AI_PROMPT}`,
|
|
243
|
+
max_tokens_to_sample: 300,
|
|
244
|
+
model: 'claude-1',
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
timeout: 5 * 1000,
|
|
248
|
+
},
|
|
249
|
+
);
|
|
250
|
+
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
On timeout, an `APIConnectionTimeoutError` is thrown.
|
|
254
|
+
|
|
255
|
+
Note that requests which time out will be [retried twice by default](#retries).
|
|
256
|
+
|
|
257
|
+
## Configuring an HTTP(S) Agent (e.g., for proxies)
|
|
258
|
+
|
|
259
|
+
By default, this library uses a stable agent for all http/https requests to reuse TCP connections, eliminating many TCP & TLS handshakes and shaving around 100ms off most requests.
|
|
260
|
+
|
|
261
|
+
If you would like to disable or customize this behavior, for example to use the API behind a proxy, you can pass an `httpAgent` which is used for all requests (be they http or https), for example:
|
|
262
|
+
|
|
263
|
+
<!-- prettier-ignore -->
|
|
264
|
+
```ts
|
|
265
|
+
import http from 'http';
|
|
266
|
+
import Anthropic from '@anthropic-ai/sdk';
|
|
267
|
+
import HttpsProxyAgent from 'https-proxy-agent';
|
|
268
|
+
|
|
269
|
+
// Configure the default for all requests:
|
|
270
|
+
const anthropic = new Anthropic({
|
|
271
|
+
httpAgent: new HttpsProxyAgent(process.env.PROXY_URL),
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
// Override per-request:
|
|
275
|
+
await anthropic.completions.create(
|
|
276
|
+
{
|
|
277
|
+
prompt: `${Anthropic.HUMAN_PROMPT} How does a court case get to the Supreme Court? ${Anthropic.AI_PROMPT}`,
|
|
278
|
+
max_tokens_to_sample: 300,
|
|
279
|
+
model: 'claude-1',
|
|
280
|
+
},
|
|
281
|
+
{
|
|
282
|
+
baseURL: 'http://localhost:8080/test-api',
|
|
283
|
+
httpAgent: new http.Agent({ keepAlive: false }),
|
|
284
|
+
},
|
|
285
|
+
);
|
|
286
|
+
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
## Status
|
|
290
|
+
|
|
291
|
+
This package is in beta. Its internals and interfaces are not stable
|
|
292
|
+
and subject to change without a major semver bump;
|
|
293
|
+
please reach out if you rely on any undocumented behavior.
|
|
294
|
+
|
|
295
|
+
We are keen for your feedback; please open an [issue](https://www.github.com/anthropics/anthropic-sdk-typescript/issues) with questions, bugs, or suggestions.
|
|
296
|
+
|
|
297
|
+
## Requirements
|
|
298
|
+
|
|
299
|
+
The following runtimes are supported:
|
|
300
|
+
|
|
301
|
+
- Node.js 16 LTS or later ([non-EOL](https://endoflife.date/nodejs)) versions.
|
|
302
|
+
- Deno v1.28.0 or higher (experimental).
|
|
303
|
+
Use `import Anthropic from "npm:@anthropic-ai/sdk"`.
|
|
304
|
+
|
|
305
|
+
If you are interested in other runtime environments, please open or upvote an issue on GitHub.
|
package/package.json
CHANGED
package/src/streaming.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import type { Response } from '@anthropic-ai/sdk/_shims/fetch';
|
|
2
|
+
|
|
2
3
|
import { APIResponse, Headers, createResponseHeaders } from './core';
|
|
4
|
+
|
|
3
5
|
import { safeJSON } from '@anthropic-ai/sdk/core';
|
|
4
6
|
import { APIError } from '@anthropic-ai/sdk/error';
|
|
5
7
|
|
|
8
|
+
type Bytes = string | ArrayBuffer | Uint8Array | Buffer | null | undefined;
|
|
9
|
+
|
|
6
10
|
type ServerSentEvent = {
|
|
7
11
|
event: string | null;
|
|
8
12
|
data: string;
|
|
@@ -85,19 +89,11 @@ export class Stream<Item> implements AsyncIterable<Item>, APIResponse<Stream<Ite
|
|
|
85
89
|
this.controller.abort();
|
|
86
90
|
throw new Error(`Attempted to iterate over a response with no body`);
|
|
87
91
|
}
|
|
88
|
-
|
|
89
92
|
const lineDecoder = new LineDecoder();
|
|
90
93
|
|
|
91
|
-
|
|
92
|
-
for await (const chunk of
|
|
93
|
-
|
|
94
|
-
if (chunk instanceof Buffer) {
|
|
95
|
-
text = chunk.toString();
|
|
96
|
-
} else if ((chunk as any) instanceof Uint8Array) {
|
|
97
|
-
text = Buffer.from(chunk).toString();
|
|
98
|
-
} else {
|
|
99
|
-
text = chunk;
|
|
100
|
-
}
|
|
94
|
+
const iter = readableStreamAsyncIterable<Bytes>(this.response.body);
|
|
95
|
+
for await (const chunk of iter) {
|
|
96
|
+
const text = decodeText(chunk);
|
|
101
97
|
|
|
102
98
|
for (const line of lineDecoder.decode(text)) {
|
|
103
99
|
const sse = this.decoder.decode(line);
|
|
@@ -218,3 +214,67 @@ function partition(str: string, delimiter: string): [string, string, string] {
|
|
|
218
214
|
|
|
219
215
|
return [str, '', ''];
|
|
220
216
|
}
|
|
217
|
+
|
|
218
|
+
let _textDecoder;
|
|
219
|
+
function decodeText(bytes: Bytes): string {
|
|
220
|
+
if (bytes == null) return '';
|
|
221
|
+
if (typeof bytes === 'string') return bytes;
|
|
222
|
+
|
|
223
|
+
// Node:
|
|
224
|
+
if (typeof Buffer !== 'undefined') {
|
|
225
|
+
if (bytes instanceof Buffer) {
|
|
226
|
+
return bytes.toString();
|
|
227
|
+
}
|
|
228
|
+
if (bytes instanceof Uint8Array) {
|
|
229
|
+
return Buffer.from(bytes).toString();
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
throw new Error(`Unexpected: received non-Uint8Array (${bytes.constructor.name}) in Node.`);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// Browser
|
|
236
|
+
if (typeof TextDecoder !== 'undefined') {
|
|
237
|
+
if (bytes instanceof Uint8Array || bytes instanceof ArrayBuffer) {
|
|
238
|
+
_textDecoder ??= new TextDecoder('utf8');
|
|
239
|
+
return _textDecoder.decode(bytes);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
throw new Error(
|
|
243
|
+
`Unexpected: received non-Uint8Array/ArrayBuffer (${
|
|
244
|
+
(bytes as any).constructor.name
|
|
245
|
+
}) in a web platform.`,
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
throw new Error(`Unexpected: neither Buffer nor TextDecoder are available as globals.`);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Most browsers don't yet have async iterable support for ReadableStream,
|
|
254
|
+
* and Node has a very different way of reading bytes from its "ReadableStream".
|
|
255
|
+
*
|
|
256
|
+
* This polyfill was pulled from https://github.com/MattiasBuelens/web-streams-polyfill/pull/122#issuecomment-1624185965
|
|
257
|
+
*
|
|
258
|
+
* We make extensive use of "any" here to avoid pulling in either "node" or "dom" types
|
|
259
|
+
* to library users' type scopes.
|
|
260
|
+
*/
|
|
261
|
+
function readableStreamAsyncIterable<T>(stream: any): AsyncIterableIterator<T> {
|
|
262
|
+
if (stream[Symbol.asyncIterator]) {
|
|
263
|
+
return stream[Symbol.asyncIterator];
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
const reader = stream.getReader();
|
|
267
|
+
|
|
268
|
+
return {
|
|
269
|
+
next() {
|
|
270
|
+
return reader.read();
|
|
271
|
+
},
|
|
272
|
+
async return() {
|
|
273
|
+
reader.releaseLock();
|
|
274
|
+
return { done: true, value: undefined };
|
|
275
|
+
},
|
|
276
|
+
[Symbol.asyncIterator]() {
|
|
277
|
+
return this;
|
|
278
|
+
},
|
|
279
|
+
};
|
|
280
|
+
}
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '0.5.
|
|
1
|
+
export const VERSION = '0.5.2';
|
package/streaming.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"streaming.d.ts","sourceRoot":"","sources":["src/streaming.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"streaming.d.ts","sourceRoot":"","sources":["src/streaming.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAC;AAE/D,OAAO,EAAE,WAAW,EAAE,OAAO,EAAyB,MAAM,QAAQ,CAAC;AAoErE,qBAAa,MAAM,CAAC,IAAI,CAAE,YAAW,aAAa,CAAC,IAAI,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACjF,6GAA6G;IAC7G,QAAQ,EAAE,QAAQ,CAAC;IACnB,+FAA+F;IAC/F,eAAe,EAAE,OAAO,CAAC;IACzB,UAAU,EAAE,eAAe,CAAC;IAE5B,OAAO,CAAC,OAAO,CAAa;gBAEhB,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,eAAe;YAO5C,YAAY;IAuBpB,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,aAAa,CAAC,IAAI,EAAE,GAAG,EAAE,SAAS,CAAC;CAkCrE"}
|
package/streaming.js
CHANGED
|
@@ -56,16 +56,9 @@ class Stream {
|
|
|
56
56
|
throw new Error(`Attempted to iterate over a response with no body`);
|
|
57
57
|
}
|
|
58
58
|
const lineDecoder = new LineDecoder();
|
|
59
|
-
|
|
60
|
-
for await (const chunk of
|
|
61
|
-
|
|
62
|
-
if (chunk instanceof Buffer) {
|
|
63
|
-
text = chunk.toString();
|
|
64
|
-
} else if (chunk instanceof Uint8Array) {
|
|
65
|
-
text = Buffer.from(chunk).toString();
|
|
66
|
-
} else {
|
|
67
|
-
text = chunk;
|
|
68
|
-
}
|
|
59
|
+
const iter = readableStreamAsyncIterable(this.response.body);
|
|
60
|
+
for await (const chunk of iter) {
|
|
61
|
+
const text = decodeText(chunk);
|
|
69
62
|
for (const line of lineDecoder.decode(text)) {
|
|
70
63
|
const sse = this.decoder.decode(line);
|
|
71
64
|
if (sse) yield sse;
|
|
@@ -165,4 +158,59 @@ function partition(str, delimiter) {
|
|
|
165
158
|
}
|
|
166
159
|
return [str, '', ''];
|
|
167
160
|
}
|
|
161
|
+
let _textDecoder;
|
|
162
|
+
function decodeText(bytes) {
|
|
163
|
+
if (bytes == null) return '';
|
|
164
|
+
if (typeof bytes === 'string') return bytes;
|
|
165
|
+
// Node:
|
|
166
|
+
if (typeof Buffer !== 'undefined') {
|
|
167
|
+
if (bytes instanceof Buffer) {
|
|
168
|
+
return bytes.toString();
|
|
169
|
+
}
|
|
170
|
+
if (bytes instanceof Uint8Array) {
|
|
171
|
+
return Buffer.from(bytes).toString();
|
|
172
|
+
}
|
|
173
|
+
throw new Error(`Unexpected: received non-Uint8Array (${bytes.constructor.name}) in Node.`);
|
|
174
|
+
}
|
|
175
|
+
// Browser
|
|
176
|
+
if (typeof TextDecoder !== 'undefined') {
|
|
177
|
+
if (bytes instanceof Uint8Array || bytes instanceof ArrayBuffer) {
|
|
178
|
+
_textDecoder !== null && _textDecoder !== void 0 ?
|
|
179
|
+
_textDecoder
|
|
180
|
+
: (_textDecoder = new TextDecoder('utf8'));
|
|
181
|
+
return _textDecoder.decode(bytes);
|
|
182
|
+
}
|
|
183
|
+
throw new Error(
|
|
184
|
+
`Unexpected: received non-Uint8Array/ArrayBuffer (${bytes.constructor.name}) in a web platform.`,
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
throw new Error(`Unexpected: neither Buffer nor TextDecoder are available as globals.`);
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Most browsers don't yet have async iterable support for ReadableStream,
|
|
191
|
+
* and Node has a very different way of reading bytes from its "ReadableStream".
|
|
192
|
+
*
|
|
193
|
+
* This polyfill was pulled from https://github.com/MattiasBuelens/web-streams-polyfill/pull/122#issuecomment-1624185965
|
|
194
|
+
*
|
|
195
|
+
* We make extensive use of "any" here to avoid pulling in either "node" or "dom" types
|
|
196
|
+
* to library users' type scopes.
|
|
197
|
+
*/
|
|
198
|
+
function readableStreamAsyncIterable(stream) {
|
|
199
|
+
if (stream[Symbol.asyncIterator]) {
|
|
200
|
+
return stream[Symbol.asyncIterator];
|
|
201
|
+
}
|
|
202
|
+
const reader = stream.getReader();
|
|
203
|
+
return {
|
|
204
|
+
next() {
|
|
205
|
+
return reader.read();
|
|
206
|
+
},
|
|
207
|
+
async return() {
|
|
208
|
+
reader.releaseLock();
|
|
209
|
+
return { done: true, value: undefined };
|
|
210
|
+
},
|
|
211
|
+
[Symbol.asyncIterator]() {
|
|
212
|
+
return this;
|
|
213
|
+
},
|
|
214
|
+
};
|
|
215
|
+
}
|
|
168
216
|
//# 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":";;;AAEA,oCAAqE;AAErE,iDAAkD;AAClD,mDAAmD;AAUnD,MAAM,UAAU;IAKd;QACE,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC;QACf,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;IACnB,CAAC;IAED,MAAM,CAAC,IAAY;QACjB,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE;YACvB,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;SAC3C;QAED,IAAI,CAAC,IAAI,EAAE;YACT,6DAA6D;YAC7D,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM;gBAAE,OAAO,IAAI,CAAC;YAElD,MAAM,GAAG,GAAoB;gBAC3B,KAAK,EAAE,IAAI,CAAC,KAAK;gBACjB,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;gBAC1B,GAAG,EAAE,IAAI,CAAC,MAAM;aACjB,CAAC;YAEF,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;YAClB,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC;YACf,IAAI,CAAC,MAAM,GAAG,EAA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,OAAO;QACL,IAAI;YACF,OAAO,MAAM,CAAC,IAAI,EAAE,CAAC;QACvB,CAAC;QACD,KAAK,CAAC,MAAM;YACV,MAAM,CAAC,WAAW,EAAE,CAAC;YACrB,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;QAC1C,CAAC;QACD,CAAC,MAAM,CAAC,aAAa,CAAC;YACpB,OAAO,IAAI,CAAC;QACd,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/streaming.mjs
CHANGED
|
@@ -53,16 +53,9 @@ export class Stream {
|
|
|
53
53
|
throw new Error(`Attempted to iterate over a response with no body`);
|
|
54
54
|
}
|
|
55
55
|
const lineDecoder = new LineDecoder();
|
|
56
|
-
|
|
57
|
-
for await (const chunk of
|
|
58
|
-
|
|
59
|
-
if (chunk instanceof Buffer) {
|
|
60
|
-
text = chunk.toString();
|
|
61
|
-
} else if (chunk instanceof Uint8Array) {
|
|
62
|
-
text = Buffer.from(chunk).toString();
|
|
63
|
-
} else {
|
|
64
|
-
text = chunk;
|
|
65
|
-
}
|
|
56
|
+
const iter = readableStreamAsyncIterable(this.response.body);
|
|
57
|
+
for await (const chunk of iter) {
|
|
58
|
+
const text = decodeText(chunk);
|
|
66
59
|
for (const line of lineDecoder.decode(text)) {
|
|
67
60
|
const sse = this.decoder.decode(line);
|
|
68
61
|
if (sse) yield sse;
|
|
@@ -161,4 +154,59 @@ function partition(str, delimiter) {
|
|
|
161
154
|
}
|
|
162
155
|
return [str, '', ''];
|
|
163
156
|
}
|
|
157
|
+
let _textDecoder;
|
|
158
|
+
function decodeText(bytes) {
|
|
159
|
+
if (bytes == null) return '';
|
|
160
|
+
if (typeof bytes === 'string') return bytes;
|
|
161
|
+
// Node:
|
|
162
|
+
if (typeof Buffer !== 'undefined') {
|
|
163
|
+
if (bytes instanceof Buffer) {
|
|
164
|
+
return bytes.toString();
|
|
165
|
+
}
|
|
166
|
+
if (bytes instanceof Uint8Array) {
|
|
167
|
+
return Buffer.from(bytes).toString();
|
|
168
|
+
}
|
|
169
|
+
throw new Error(`Unexpected: received non-Uint8Array (${bytes.constructor.name}) in Node.`);
|
|
170
|
+
}
|
|
171
|
+
// Browser
|
|
172
|
+
if (typeof TextDecoder !== 'undefined') {
|
|
173
|
+
if (bytes instanceof Uint8Array || bytes instanceof ArrayBuffer) {
|
|
174
|
+
_textDecoder !== null && _textDecoder !== void 0 ?
|
|
175
|
+
_textDecoder
|
|
176
|
+
: (_textDecoder = new TextDecoder('utf8'));
|
|
177
|
+
return _textDecoder.decode(bytes);
|
|
178
|
+
}
|
|
179
|
+
throw new Error(
|
|
180
|
+
`Unexpected: received non-Uint8Array/ArrayBuffer (${bytes.constructor.name}) in a web platform.`,
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
throw new Error(`Unexpected: neither Buffer nor TextDecoder are available as globals.`);
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Most browsers don't yet have async iterable support for ReadableStream,
|
|
187
|
+
* and Node has a very different way of reading bytes from its "ReadableStream".
|
|
188
|
+
*
|
|
189
|
+
* This polyfill was pulled from https://github.com/MattiasBuelens/web-streams-polyfill/pull/122#issuecomment-1624185965
|
|
190
|
+
*
|
|
191
|
+
* We make extensive use of "any" here to avoid pulling in either "node" or "dom" types
|
|
192
|
+
* to library users' type scopes.
|
|
193
|
+
*/
|
|
194
|
+
function readableStreamAsyncIterable(stream) {
|
|
195
|
+
if (stream[Symbol.asyncIterator]) {
|
|
196
|
+
return stream[Symbol.asyncIterator];
|
|
197
|
+
}
|
|
198
|
+
const reader = stream.getReader();
|
|
199
|
+
return {
|
|
200
|
+
next() {
|
|
201
|
+
return reader.read();
|
|
202
|
+
},
|
|
203
|
+
async return() {
|
|
204
|
+
reader.releaseLock();
|
|
205
|
+
return { done: true, value: undefined };
|
|
206
|
+
},
|
|
207
|
+
[Symbol.asyncIterator]() {
|
|
208
|
+
return this;
|
|
209
|
+
},
|
|
210
|
+
};
|
|
211
|
+
}
|
|
164
212
|
//# 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":"OAEO,EAAwB,qBAAqB,EAAE;OAE/C,EAAE,QAAQ,EAAE,MAAM,wBAAwB;OAC1C,EAAE,QAAQ,EAAE,MAAM,yBAAyB;AAUlD,MAAM,UAAU;IAKd;QACE,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC;QACf,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;IACnB,CAAC;IAED,MAAM,CAAC,IAAY;QACjB,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE;YACvB,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;SAC3C;QAED,IAAI,CAAC,IAAI,EAAE;YACT,6DAA6D;YAC7D,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM;gBAAE,OAAO,IAAI,CAAC;YAElD,MAAM,GAAG,GAAoB;gBAC3B,KAAK,EAAE,IAAI,CAAC,KAAK;gBACjB,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;gBAC1B,GAAG,EAAE,IAAI,CAAC,MAAM;aACjB,CAAC;YAEF,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;YAClB,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC;YACf,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;YAEjB,OAAO,GAAG,CAAC;SACZ;QAED,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CA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EAAE,CAAC;YACrB,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;QAC1C,CAAC;QACD,CAAC,MAAM,CAAC,aAAa,CAAC;YACpB,OAAO,IAAI,CAAC;QACd,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = '0.5.
|
|
1
|
+
export declare const VERSION = '0.5.2';
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/version.js
CHANGED
package/version.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const VERSION = '0.5.
|
|
1
|
+
export const VERSION = '0.5.2';
|
|
2
2
|
//# sourceMappingURL=version.mjs.map
|