Add all the original files from the deleted 0.2.8 npm package

This commit is contained in:
daniel nakov
2025-02-26 19:31:54 -05:00
parent 8bf1bb8913
commit ca97a02201
323 changed files with 26218 additions and 2 deletions

31
vendor/sdk/internal/decoders/jsonl.mjs vendored Normal file
View File

@@ -0,0 +1,31 @@
import { AnthropicError } from "../../error.mjs";
import { ReadableStreamToAsyncIterable } from "../stream-utils.mjs";
import { LineDecoder } from "./line.mjs";
export class JSONLDecoder {
constructor(iterator, controller) {
this.iterator = iterator;
this.controller = controller;
}
async *decoder() {
const lineDecoder = new LineDecoder();
for await (const chunk of this.iterator) {
for (const line of lineDecoder.decode(chunk)) {
yield JSON.parse(line);
}
}
for (const line of lineDecoder.flush()) {
yield JSON.parse(line);
}
}
[Symbol.asyncIterator]() {
return this.decoder();
}
static fromResponse(response, controller) {
if (!response.body) {
controller.abort();
throw new AnthropicError(`Attempted to iterate over a response with no body`);
}
return new JSONLDecoder(ReadableStreamToAsyncIterable(response.body), controller);
}
}
//# sourceMappingURL=jsonl.mjs.map