mirror of
https://github.com/tvytlx/ai-agent-deep-dive.git
synced 2026-04-05 00:24:50 +08:00
Add extracted source directory and README navigation
This commit is contained in:
223
extracted-source/node_modules/@anthropic-ai/sdk/_vendor/partial-json-parser/parser.mjs
generated
vendored
Normal file
223
extracted-source/node_modules/@anthropic-ai/sdk/_vendor/partial-json-parser/parser.mjs
generated
vendored
Normal file
@@ -0,0 +1,223 @@
|
||||
const tokenize = (input) => {
|
||||
let current = 0;
|
||||
let tokens = [];
|
||||
while (current < input.length) {
|
||||
let char = input[current];
|
||||
if (char === '\\') {
|
||||
current++;
|
||||
continue;
|
||||
}
|
||||
if (char === '{') {
|
||||
tokens.push({
|
||||
type: 'brace',
|
||||
value: '{',
|
||||
});
|
||||
current++;
|
||||
continue;
|
||||
}
|
||||
if (char === '}') {
|
||||
tokens.push({
|
||||
type: 'brace',
|
||||
value: '}',
|
||||
});
|
||||
current++;
|
||||
continue;
|
||||
}
|
||||
if (char === '[') {
|
||||
tokens.push({
|
||||
type: 'paren',
|
||||
value: '[',
|
||||
});
|
||||
current++;
|
||||
continue;
|
||||
}
|
||||
if (char === ']') {
|
||||
tokens.push({
|
||||
type: 'paren',
|
||||
value: ']',
|
||||
});
|
||||
current++;
|
||||
continue;
|
||||
}
|
||||
if (char === ':') {
|
||||
tokens.push({
|
||||
type: 'separator',
|
||||
value: ':',
|
||||
});
|
||||
current++;
|
||||
continue;
|
||||
}
|
||||
if (char === ',') {
|
||||
tokens.push({
|
||||
type: 'delimiter',
|
||||
value: ',',
|
||||
});
|
||||
current++;
|
||||
continue;
|
||||
}
|
||||
if (char === '"') {
|
||||
let value = '';
|
||||
let danglingQuote = false;
|
||||
char = input[++current];
|
||||
while (char !== '"') {
|
||||
if (current === input.length) {
|
||||
danglingQuote = true;
|
||||
break;
|
||||
}
|
||||
if (char === '\\') {
|
||||
current++;
|
||||
if (current === input.length) {
|
||||
danglingQuote = true;
|
||||
break;
|
||||
}
|
||||
value += char + input[current];
|
||||
char = input[++current];
|
||||
}
|
||||
else {
|
||||
value += char;
|
||||
char = input[++current];
|
||||
}
|
||||
}
|
||||
char = input[++current];
|
||||
if (!danglingQuote) {
|
||||
tokens.push({
|
||||
type: 'string',
|
||||
value,
|
||||
});
|
||||
}
|
||||
continue;
|
||||
}
|
||||
let WHITESPACE = /\s/;
|
||||
if (char && WHITESPACE.test(char)) {
|
||||
current++;
|
||||
continue;
|
||||
}
|
||||
let NUMBERS = /[0-9]/;
|
||||
if ((char && NUMBERS.test(char)) || char === '-' || char === '.') {
|
||||
let value = '';
|
||||
if (char === '-') {
|
||||
value += char;
|
||||
char = input[++current];
|
||||
}
|
||||
while ((char && NUMBERS.test(char)) || char === '.') {
|
||||
value += char;
|
||||
char = input[++current];
|
||||
}
|
||||
tokens.push({
|
||||
type: 'number',
|
||||
value,
|
||||
});
|
||||
continue;
|
||||
}
|
||||
let LETTERS = /[a-z]/i;
|
||||
if (char && LETTERS.test(char)) {
|
||||
let value = '';
|
||||
while (char && LETTERS.test(char)) {
|
||||
if (current === input.length) {
|
||||
break;
|
||||
}
|
||||
value += char;
|
||||
char = input[++current];
|
||||
}
|
||||
if (value == 'true' || value == 'false' || value === 'null') {
|
||||
tokens.push({
|
||||
type: 'name',
|
||||
value,
|
||||
});
|
||||
}
|
||||
else {
|
||||
// unknown token, e.g. `nul` which isn't quite `null`
|
||||
current++;
|
||||
continue;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
current++;
|
||||
}
|
||||
return tokens;
|
||||
}, strip = (tokens) => {
|
||||
if (tokens.length === 0) {
|
||||
return tokens;
|
||||
}
|
||||
let lastToken = tokens[tokens.length - 1];
|
||||
switch (lastToken.type) {
|
||||
case 'separator':
|
||||
tokens = tokens.slice(0, tokens.length - 1);
|
||||
return strip(tokens);
|
||||
break;
|
||||
case 'number':
|
||||
let lastCharacterOfLastToken = lastToken.value[lastToken.value.length - 1];
|
||||
if (lastCharacterOfLastToken === '.' || lastCharacterOfLastToken === '-') {
|
||||
tokens = tokens.slice(0, tokens.length - 1);
|
||||
return strip(tokens);
|
||||
}
|
||||
case 'string':
|
||||
let tokenBeforeTheLastToken = tokens[tokens.length - 2];
|
||||
if (tokenBeforeTheLastToken?.type === 'delimiter') {
|
||||
tokens = tokens.slice(0, tokens.length - 1);
|
||||
return strip(tokens);
|
||||
}
|
||||
else if (tokenBeforeTheLastToken?.type === 'brace' && tokenBeforeTheLastToken.value === '{') {
|
||||
tokens = tokens.slice(0, tokens.length - 1);
|
||||
return strip(tokens);
|
||||
}
|
||||
break;
|
||||
case 'delimiter':
|
||||
tokens = tokens.slice(0, tokens.length - 1);
|
||||
return strip(tokens);
|
||||
break;
|
||||
}
|
||||
return tokens;
|
||||
}, unstrip = (tokens) => {
|
||||
let tail = [];
|
||||
tokens.map((token) => {
|
||||
if (token.type === 'brace') {
|
||||
if (token.value === '{') {
|
||||
tail.push('}');
|
||||
}
|
||||
else {
|
||||
tail.splice(tail.lastIndexOf('}'), 1);
|
||||
}
|
||||
}
|
||||
if (token.type === 'paren') {
|
||||
if (token.value === '[') {
|
||||
tail.push(']');
|
||||
}
|
||||
else {
|
||||
tail.splice(tail.lastIndexOf(']'), 1);
|
||||
}
|
||||
}
|
||||
});
|
||||
if (tail.length > 0) {
|
||||
tail.reverse().map((item) => {
|
||||
if (item === '}') {
|
||||
tokens.push({
|
||||
type: 'brace',
|
||||
value: '}',
|
||||
});
|
||||
}
|
||||
else if (item === ']') {
|
||||
tokens.push({
|
||||
type: 'paren',
|
||||
value: ']',
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
return tokens;
|
||||
}, generate = (tokens) => {
|
||||
let output = '';
|
||||
tokens.map((token) => {
|
||||
switch (token.type) {
|
||||
case 'string':
|
||||
output += '"' + token.value + '"';
|
||||
break;
|
||||
default:
|
||||
output += token.value;
|
||||
break;
|
||||
}
|
||||
});
|
||||
return output;
|
||||
}, partialParse = (input) => JSON.parse(generate(unstrip(strip(tokenize(input)))));
|
||||
export { partialParse };
|
||||
//# sourceMappingURL=parser.mjs.map
|
||||
559
extracted-source/node_modules/@anthropic-ai/sdk/client.mjs
generated
vendored
Normal file
559
extracted-source/node_modules/@anthropic-ai/sdk/client.mjs
generated
vendored
Normal file
@@ -0,0 +1,559 @@
|
||||
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
||||
var _BaseAnthropic_instances, _a, _BaseAnthropic_encoder, _BaseAnthropic_baseURLOverridden;
|
||||
import { __classPrivateFieldGet, __classPrivateFieldSet } from "./internal/tslib.mjs";
|
||||
import { uuid4 } from "./internal/utils/uuid.mjs";
|
||||
import { validatePositiveInteger, isAbsoluteURL, safeJSON } from "./internal/utils/values.mjs";
|
||||
import { sleep } from "./internal/utils/sleep.mjs";
|
||||
import { castToError, isAbortError } from "./internal/errors.mjs";
|
||||
import { getPlatformHeaders } from "./internal/detect-platform.mjs";
|
||||
import * as Shims from "./internal/shims.mjs";
|
||||
import * as Opts from "./internal/request-options.mjs";
|
||||
import { VERSION } from "./version.mjs";
|
||||
import * as Errors from "./core/error.mjs";
|
||||
import * as Pagination from "./core/pagination.mjs";
|
||||
import * as Uploads from "./core/uploads.mjs";
|
||||
import * as API from "./resources/index.mjs";
|
||||
import { APIPromise } from "./core/api-promise.mjs";
|
||||
import { Completions, } from "./resources/completions.mjs";
|
||||
import { Models } from "./resources/models.mjs";
|
||||
import { Beta, } from "./resources/beta/beta.mjs";
|
||||
import { Messages, } from "./resources/messages/messages.mjs";
|
||||
import { isRunningInBrowser } from "./internal/detect-platform.mjs";
|
||||
import { buildHeaders } from "./internal/headers.mjs";
|
||||
import { readEnv } from "./internal/utils/env.mjs";
|
||||
import { formatRequestDetails, loggerFor, parseLogLevel, } from "./internal/utils/log.mjs";
|
||||
import { isEmptyObj } from "./internal/utils/values.mjs";
|
||||
export const HUMAN_PROMPT = '\\n\\nHuman:';
|
||||
export const AI_PROMPT = '\\n\\nAssistant:';
|
||||
/**
|
||||
* Base class for Anthropic API clients.
|
||||
*/
|
||||
export class BaseAnthropic {
|
||||
/**
|
||||
* API Client for interfacing with the Anthropic API.
|
||||
*
|
||||
* @param {string | null | undefined} [opts.apiKey=process.env['ANTHROPIC_API_KEY'] ?? null]
|
||||
* @param {string | null | undefined} [opts.authToken=process.env['ANTHROPIC_AUTH_TOKEN'] ?? null]
|
||||
* @param {string} [opts.baseURL=process.env['ANTHROPIC_BASE_URL'] ?? https://api.anthropic.com] - Override the default base URL for the API.
|
||||
* @param {number} [opts.timeout=10 minutes] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
|
||||
* @param {MergedRequestInit} [opts.fetchOptions] - Additional `RequestInit` options to be passed to `fetch` calls.
|
||||
* @param {Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
|
||||
* @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.
|
||||
* @param {HeadersLike} opts.defaultHeaders - Default headers to include with every request to the API.
|
||||
* @param {Record<string, string | undefined>} opts.defaultQuery - Default query parameters to include with every request to the API.
|
||||
* @param {boolean} [opts.dangerouslyAllowBrowser=false] - By default, client-side use of this library is not allowed, as it risks exposing your secret API credentials to attackers.
|
||||
*/
|
||||
constructor({ baseURL = readEnv('ANTHROPIC_BASE_URL'), apiKey = readEnv('ANTHROPIC_API_KEY') ?? null, authToken = readEnv('ANTHROPIC_AUTH_TOKEN') ?? null, ...opts } = {}) {
|
||||
_BaseAnthropic_instances.add(this);
|
||||
_BaseAnthropic_encoder.set(this, void 0);
|
||||
const options = {
|
||||
apiKey,
|
||||
authToken,
|
||||
...opts,
|
||||
baseURL: baseURL || `https://api.anthropic.com`,
|
||||
};
|
||||
if (!options.dangerouslyAllowBrowser && isRunningInBrowser()) {
|
||||
throw new Errors.AnthropicError("It looks like you're running in a browser-like environment.\n\nThis is disabled by default, as it risks exposing your secret API credentials to attackers.\nIf you understand the risks and have appropriate mitigations in place,\nyou can set the `dangerouslyAllowBrowser` option to `true`, e.g.,\n\nnew Anthropic({ apiKey, dangerouslyAllowBrowser: true });\n");
|
||||
}
|
||||
this.baseURL = options.baseURL;
|
||||
this.timeout = options.timeout ?? _a.DEFAULT_TIMEOUT /* 10 minutes */;
|
||||
this.logger = options.logger ?? console;
|
||||
const defaultLogLevel = 'warn';
|
||||
// Set default logLevel early so that we can log a warning in parseLogLevel.
|
||||
this.logLevel = defaultLogLevel;
|
||||
this.logLevel =
|
||||
parseLogLevel(options.logLevel, 'ClientOptions.logLevel', this) ??
|
||||
parseLogLevel(readEnv('ANTHROPIC_LOG'), "process.env['ANTHROPIC_LOG']", this) ??
|
||||
defaultLogLevel;
|
||||
this.fetchOptions = options.fetchOptions;
|
||||
this.maxRetries = options.maxRetries ?? 2;
|
||||
this.fetch = options.fetch ?? Shims.getDefaultFetch();
|
||||
__classPrivateFieldSet(this, _BaseAnthropic_encoder, Opts.FallbackEncoder, "f");
|
||||
this._options = options;
|
||||
this.apiKey = typeof apiKey === 'string' ? apiKey : null;
|
||||
this.authToken = authToken;
|
||||
}
|
||||
/**
|
||||
* Create a new client instance re-using the same options given to the current client with optional overriding.
|
||||
*/
|
||||
withOptions(options) {
|
||||
const client = new this.constructor({
|
||||
...this._options,
|
||||
baseURL: this.baseURL,
|
||||
maxRetries: this.maxRetries,
|
||||
timeout: this.timeout,
|
||||
logger: this.logger,
|
||||
logLevel: this.logLevel,
|
||||
fetch: this.fetch,
|
||||
fetchOptions: this.fetchOptions,
|
||||
apiKey: this.apiKey,
|
||||
authToken: this.authToken,
|
||||
...options,
|
||||
});
|
||||
return client;
|
||||
}
|
||||
defaultQuery() {
|
||||
return this._options.defaultQuery;
|
||||
}
|
||||
validateHeaders({ values, nulls }) {
|
||||
if (values.get('x-api-key') || values.get('authorization')) {
|
||||
return;
|
||||
}
|
||||
if (this.apiKey && values.get('x-api-key')) {
|
||||
return;
|
||||
}
|
||||
if (nulls.has('x-api-key')) {
|
||||
return;
|
||||
}
|
||||
if (this.authToken && values.get('authorization')) {
|
||||
return;
|
||||
}
|
||||
if (nulls.has('authorization')) {
|
||||
return;
|
||||
}
|
||||
throw new Error('Could not resolve authentication method. Expected either apiKey or authToken to be set. Or for one of the "X-Api-Key" or "Authorization" headers to be explicitly omitted');
|
||||
}
|
||||
async authHeaders(opts) {
|
||||
return buildHeaders([await this.apiKeyAuth(opts), await this.bearerAuth(opts)]);
|
||||
}
|
||||
async apiKeyAuth(opts) {
|
||||
if (this.apiKey == null) {
|
||||
return undefined;
|
||||
}
|
||||
return buildHeaders([{ 'X-Api-Key': this.apiKey }]);
|
||||
}
|
||||
async bearerAuth(opts) {
|
||||
if (this.authToken == null) {
|
||||
return undefined;
|
||||
}
|
||||
return buildHeaders([{ Authorization: `Bearer ${this.authToken}` }]);
|
||||
}
|
||||
/**
|
||||
* Basic re-implementation of `qs.stringify` for primitive types.
|
||||
*/
|
||||
stringifyQuery(query) {
|
||||
return Object.entries(query)
|
||||
.filter(([_, value]) => typeof value !== 'undefined')
|
||||
.map(([key, value]) => {
|
||||
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
|
||||
return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
|
||||
}
|
||||
if (value === null) {
|
||||
return `${encodeURIComponent(key)}=`;
|
||||
}
|
||||
throw new Errors.AnthropicError(`Cannot stringify type ${typeof value}; Expected string, number, boolean, or null. If you need to pass nested query parameters, you can manually encode them, e.g. { query: { 'foo[key1]': value1, 'foo[key2]': value2 } }, and please open a GitHub issue requesting better support for your use case.`);
|
||||
})
|
||||
.join('&');
|
||||
}
|
||||
getUserAgent() {
|
||||
return `${this.constructor.name}/JS ${VERSION}`;
|
||||
}
|
||||
defaultIdempotencyKey() {
|
||||
return `stainless-node-retry-${uuid4()}`;
|
||||
}
|
||||
makeStatusError(status, error, message, headers) {
|
||||
return Errors.APIError.generate(status, error, message, headers);
|
||||
}
|
||||
buildURL(path, query, defaultBaseURL) {
|
||||
const baseURL = (!__classPrivateFieldGet(this, _BaseAnthropic_instances, "m", _BaseAnthropic_baseURLOverridden).call(this) && defaultBaseURL) || this.baseURL;
|
||||
const url = isAbsoluteURL(path) ?
|
||||
new URL(path)
|
||||
: new URL(baseURL + (baseURL.endsWith('/') && path.startsWith('/') ? path.slice(1) : path));
|
||||
const defaultQuery = this.defaultQuery();
|
||||
if (!isEmptyObj(defaultQuery)) {
|
||||
query = { ...defaultQuery, ...query };
|
||||
}
|
||||
if (typeof query === 'object' && query && !Array.isArray(query)) {
|
||||
url.search = this.stringifyQuery(query);
|
||||
}
|
||||
return url.toString();
|
||||
}
|
||||
_calculateNonstreamingTimeout(maxTokens) {
|
||||
const defaultTimeout = 10 * 60;
|
||||
const expectedTimeout = (60 * 60 * maxTokens) / 128000;
|
||||
if (expectedTimeout > defaultTimeout) {
|
||||
throw new Errors.AnthropicError('Streaming is required for operations that may take longer than 10 minutes. ' +
|
||||
'See https://github.com/anthropics/anthropic-sdk-typescript#streaming-responses for more details');
|
||||
}
|
||||
return defaultTimeout * 1000;
|
||||
}
|
||||
/**
|
||||
* Used as a callback for mutating the given `FinalRequestOptions` object.
|
||||
*/
|
||||
async prepareOptions(options) { }
|
||||
/**
|
||||
* Used as a callback for mutating the given `RequestInit` object.
|
||||
*
|
||||
* This is useful for cases where you want to add certain headers based off of
|
||||
* the request properties, e.g. `method` or `url`.
|
||||
*/
|
||||
async prepareRequest(request, { url, options }) { }
|
||||
get(path, opts) {
|
||||
return this.methodRequest('get', path, opts);
|
||||
}
|
||||
post(path, opts) {
|
||||
return this.methodRequest('post', path, opts);
|
||||
}
|
||||
patch(path, opts) {
|
||||
return this.methodRequest('patch', path, opts);
|
||||
}
|
||||
put(path, opts) {
|
||||
return this.methodRequest('put', path, opts);
|
||||
}
|
||||
delete(path, opts) {
|
||||
return this.methodRequest('delete', path, opts);
|
||||
}
|
||||
methodRequest(method, path, opts) {
|
||||
return this.request(Promise.resolve(opts).then((opts) => {
|
||||
return { method, path, ...opts };
|
||||
}));
|
||||
}
|
||||
request(options, remainingRetries = null) {
|
||||
return new APIPromise(this, this.makeRequest(options, remainingRetries, undefined));
|
||||
}
|
||||
async makeRequest(optionsInput, retriesRemaining, retryOfRequestLogID) {
|
||||
const options = await optionsInput;
|
||||
const maxRetries = options.maxRetries ?? this.maxRetries;
|
||||
if (retriesRemaining == null) {
|
||||
retriesRemaining = maxRetries;
|
||||
}
|
||||
await this.prepareOptions(options);
|
||||
const { req, url, timeout } = await this.buildRequest(options, {
|
||||
retryCount: maxRetries - retriesRemaining,
|
||||
});
|
||||
await this.prepareRequest(req, { url, options });
|
||||
/** Not an API request ID, just for correlating local log entries. */
|
||||
const requestLogID = 'log_' + ((Math.random() * (1 << 24)) | 0).toString(16).padStart(6, '0');
|
||||
const retryLogStr = retryOfRequestLogID === undefined ? '' : `, retryOf: ${retryOfRequestLogID}`;
|
||||
const startTime = Date.now();
|
||||
loggerFor(this).debug(`[${requestLogID}] sending request`, formatRequestDetails({
|
||||
retryOfRequestLogID,
|
||||
method: options.method,
|
||||
url,
|
||||
options,
|
||||
headers: req.headers,
|
||||
}));
|
||||
if (options.signal?.aborted) {
|
||||
throw new Errors.APIUserAbortError();
|
||||
}
|
||||
const controller = new AbortController();
|
||||
const response = await this.fetchWithTimeout(url, req, timeout, controller).catch(castToError);
|
||||
const headersTime = Date.now();
|
||||
if (response instanceof globalThis.Error) {
|
||||
const retryMessage = `retrying, ${retriesRemaining} attempts remaining`;
|
||||
if (options.signal?.aborted) {
|
||||
throw new Errors.APIUserAbortError();
|
||||
}
|
||||
// detect native connection timeout errors
|
||||
// deno throws "TypeError: error sending request for url (https://example/): client error (Connect): tcp connect error: Operation timed out (os error 60): Operation timed out (os error 60)"
|
||||
// undici throws "TypeError: fetch failed" with cause "ConnectTimeoutError: Connect Timeout Error (attempted address: example:443, timeout: 1ms)"
|
||||
// others do not provide enough information to distinguish timeouts from other connection errors
|
||||
const isTimeout = isAbortError(response) ||
|
||||
/timed? ?out/i.test(String(response) + ('cause' in response ? String(response.cause) : ''));
|
||||
if (retriesRemaining) {
|
||||
loggerFor(this).info(`[${requestLogID}] connection ${isTimeout ? 'timed out' : 'failed'} - ${retryMessage}`);
|
||||
loggerFor(this).debug(`[${requestLogID}] connection ${isTimeout ? 'timed out' : 'failed'} (${retryMessage})`, formatRequestDetails({
|
||||
retryOfRequestLogID,
|
||||
url,
|
||||
durationMs: headersTime - startTime,
|
||||
message: response.message,
|
||||
}));
|
||||
return this.retryRequest(options, retriesRemaining, retryOfRequestLogID ?? requestLogID);
|
||||
}
|
||||
loggerFor(this).info(`[${requestLogID}] connection ${isTimeout ? 'timed out' : 'failed'} - error; no more retries left`);
|
||||
loggerFor(this).debug(`[${requestLogID}] connection ${isTimeout ? 'timed out' : 'failed'} (error; no more retries left)`, formatRequestDetails({
|
||||
retryOfRequestLogID,
|
||||
url,
|
||||
durationMs: headersTime - startTime,
|
||||
message: response.message,
|
||||
}));
|
||||
if (isTimeout) {
|
||||
throw new Errors.APIConnectionTimeoutError();
|
||||
}
|
||||
throw new Errors.APIConnectionError({ cause: response });
|
||||
}
|
||||
const specialHeaders = [...response.headers.entries()]
|
||||
.filter(([name]) => name === 'request-id')
|
||||
.map(([name, value]) => ', ' + name + ': ' + JSON.stringify(value))
|
||||
.join('');
|
||||
const responseInfo = `[${requestLogID}${retryLogStr}${specialHeaders}] ${req.method} ${url} ${response.ok ? 'succeeded' : 'failed'} with status ${response.status} in ${headersTime - startTime}ms`;
|
||||
if (!response.ok) {
|
||||
const shouldRetry = await this.shouldRetry(response);
|
||||
if (retriesRemaining && shouldRetry) {
|
||||
const retryMessage = `retrying, ${retriesRemaining} attempts remaining`;
|
||||
// We don't need the body of this response.
|
||||
await Shims.CancelReadableStream(response.body);
|
||||
loggerFor(this).info(`${responseInfo} - ${retryMessage}`);
|
||||
loggerFor(this).debug(`[${requestLogID}] response error (${retryMessage})`, formatRequestDetails({
|
||||
retryOfRequestLogID,
|
||||
url: response.url,
|
||||
status: response.status,
|
||||
headers: response.headers,
|
||||
durationMs: headersTime - startTime,
|
||||
}));
|
||||
return this.retryRequest(options, retriesRemaining, retryOfRequestLogID ?? requestLogID, response.headers);
|
||||
}
|
||||
const retryMessage = shouldRetry ? `error; no more retries left` : `error; not retryable`;
|
||||
loggerFor(this).info(`${responseInfo} - ${retryMessage}`);
|
||||
const errText = await response.text().catch((err) => castToError(err).message);
|
||||
const errJSON = safeJSON(errText);
|
||||
const errMessage = errJSON ? undefined : errText;
|
||||
loggerFor(this).debug(`[${requestLogID}] response error (${retryMessage})`, formatRequestDetails({
|
||||
retryOfRequestLogID,
|
||||
url: response.url,
|
||||
status: response.status,
|
||||
headers: response.headers,
|
||||
message: errMessage,
|
||||
durationMs: Date.now() - startTime,
|
||||
}));
|
||||
const err = this.makeStatusError(response.status, errJSON, errMessage, response.headers);
|
||||
throw err;
|
||||
}
|
||||
loggerFor(this).info(responseInfo);
|
||||
loggerFor(this).debug(`[${requestLogID}] response start`, formatRequestDetails({
|
||||
retryOfRequestLogID,
|
||||
url: response.url,
|
||||
status: response.status,
|
||||
headers: response.headers,
|
||||
durationMs: headersTime - startTime,
|
||||
}));
|
||||
return { response, options, controller, requestLogID, retryOfRequestLogID, startTime };
|
||||
}
|
||||
getAPIList(path, Page, opts) {
|
||||
return this.requestAPIList(Page, opts && 'then' in opts ?
|
||||
opts.then((opts) => ({ method: 'get', path, ...opts }))
|
||||
: { method: 'get', path, ...opts });
|
||||
}
|
||||
requestAPIList(Page, options) {
|
||||
const request = this.makeRequest(options, null, undefined);
|
||||
return new Pagination.PagePromise(this, request, Page);
|
||||
}
|
||||
async fetchWithTimeout(url, init, ms, controller) {
|
||||
const { signal, method, ...options } = init || {};
|
||||
// Avoid creating a closure over `this`, `init`, or `options` to prevent memory leaks.
|
||||
// An arrow function like `() => controller.abort()` captures the surrounding scope,
|
||||
// which includes the request body and other large objects. When the user passes a
|
||||
// long-lived AbortSignal, the listener prevents those objects from being GC'd for
|
||||
// the lifetime of the signal. Using `.bind()` only retains a reference to the
|
||||
// controller itself.
|
||||
const abort = this._makeAbort(controller);
|
||||
if (signal)
|
||||
signal.addEventListener('abort', abort, { once: true });
|
||||
const timeout = setTimeout(abort, ms);
|
||||
const isReadableBody = (globalThis.ReadableStream && options.body instanceof globalThis.ReadableStream) ||
|
||||
(typeof options.body === 'object' && options.body !== null && Symbol.asyncIterator in options.body);
|
||||
const fetchOptions = {
|
||||
signal: controller.signal,
|
||||
...(isReadableBody ? { duplex: 'half' } : {}),
|
||||
method: 'GET',
|
||||
...options,
|
||||
};
|
||||
if (method) {
|
||||
// Custom methods like 'patch' need to be uppercased
|
||||
// See https://github.com/nodejs/undici/issues/2294
|
||||
fetchOptions.method = method.toUpperCase();
|
||||
}
|
||||
try {
|
||||
// use undefined this binding; fetch errors if bound to something else in browser/cloudflare
|
||||
return await this.fetch.call(undefined, url, fetchOptions);
|
||||
}
|
||||
finally {
|
||||
clearTimeout(timeout);
|
||||
}
|
||||
}
|
||||
async shouldRetry(response) {
|
||||
// Note this is not a standard header.
|
||||
const shouldRetryHeader = response.headers.get('x-should-retry');
|
||||
// If the server explicitly says whether or not to retry, obey.
|
||||
if (shouldRetryHeader === 'true')
|
||||
return true;
|
||||
if (shouldRetryHeader === 'false')
|
||||
return false;
|
||||
// Retry on request timeouts.
|
||||
if (response.status === 408)
|
||||
return true;
|
||||
// Retry on lock timeouts.
|
||||
if (response.status === 409)
|
||||
return true;
|
||||
// Retry on rate limits.
|
||||
if (response.status === 429)
|
||||
return true;
|
||||
// Retry internal errors.
|
||||
if (response.status >= 500)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
async retryRequest(options, retriesRemaining, requestLogID, responseHeaders) {
|
||||
let timeoutMillis;
|
||||
// Note the `retry-after-ms` header may not be standard, but is a good idea and we'd like proactive support for it.
|
||||
const retryAfterMillisHeader = responseHeaders?.get('retry-after-ms');
|
||||
if (retryAfterMillisHeader) {
|
||||
const timeoutMs = parseFloat(retryAfterMillisHeader);
|
||||
if (!Number.isNaN(timeoutMs)) {
|
||||
timeoutMillis = timeoutMs;
|
||||
}
|
||||
}
|
||||
// About the Retry-After header: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After
|
||||
const retryAfterHeader = responseHeaders?.get('retry-after');
|
||||
if (retryAfterHeader && !timeoutMillis) {
|
||||
const timeoutSeconds = parseFloat(retryAfterHeader);
|
||||
if (!Number.isNaN(timeoutSeconds)) {
|
||||
timeoutMillis = timeoutSeconds * 1000;
|
||||
}
|
||||
else {
|
||||
timeoutMillis = Date.parse(retryAfterHeader) - Date.now();
|
||||
}
|
||||
}
|
||||
// If the API asks us to wait a certain amount of time (and it's a reasonable amount),
|
||||
// just do what it says, but otherwise calculate a default
|
||||
if (!(timeoutMillis && 0 <= timeoutMillis && timeoutMillis < 60 * 1000)) {
|
||||
const maxRetries = options.maxRetries ?? this.maxRetries;
|
||||
timeoutMillis = this.calculateDefaultRetryTimeoutMillis(retriesRemaining, maxRetries);
|
||||
}
|
||||
await sleep(timeoutMillis);
|
||||
return this.makeRequest(options, retriesRemaining - 1, requestLogID);
|
||||
}
|
||||
calculateDefaultRetryTimeoutMillis(retriesRemaining, maxRetries) {
|
||||
const initialRetryDelay = 0.5;
|
||||
const maxRetryDelay = 8.0;
|
||||
const numRetries = maxRetries - retriesRemaining;
|
||||
// Apply exponential backoff, but not more than the max.
|
||||
const sleepSeconds = Math.min(initialRetryDelay * Math.pow(2, numRetries), maxRetryDelay);
|
||||
// Apply some jitter, take up to at most 25 percent of the retry time.
|
||||
const jitter = 1 - Math.random() * 0.25;
|
||||
return sleepSeconds * jitter * 1000;
|
||||
}
|
||||
calculateNonstreamingTimeout(maxTokens, maxNonstreamingTokens) {
|
||||
const maxTime = 60 * 60 * 1000; // 60 minutes
|
||||
const defaultTime = 60 * 10 * 1000; // 10 minutes
|
||||
const expectedTime = (maxTime * maxTokens) / 128000;
|
||||
if (expectedTime > defaultTime || (maxNonstreamingTokens != null && maxTokens > maxNonstreamingTokens)) {
|
||||
throw new Errors.AnthropicError('Streaming is required for operations that may take longer than 10 minutes. See https://github.com/anthropics/anthropic-sdk-typescript#long-requests for more details');
|
||||
}
|
||||
return defaultTime;
|
||||
}
|
||||
async buildRequest(inputOptions, { retryCount = 0 } = {}) {
|
||||
const options = { ...inputOptions };
|
||||
const { method, path, query, defaultBaseURL } = options;
|
||||
const url = this.buildURL(path, query, defaultBaseURL);
|
||||
if ('timeout' in options)
|
||||
validatePositiveInteger('timeout', options.timeout);
|
||||
options.timeout = options.timeout ?? this.timeout;
|
||||
const { bodyHeaders, body } = this.buildBody({ options });
|
||||
const reqHeaders = await this.buildHeaders({ options: inputOptions, method, bodyHeaders, retryCount });
|
||||
const req = {
|
||||
method,
|
||||
headers: reqHeaders,
|
||||
...(options.signal && { signal: options.signal }),
|
||||
...(globalThis.ReadableStream &&
|
||||
body instanceof globalThis.ReadableStream && { duplex: 'half' }),
|
||||
...(body && { body }),
|
||||
...(this.fetchOptions ?? {}),
|
||||
...(options.fetchOptions ?? {}),
|
||||
};
|
||||
return { req, url, timeout: options.timeout };
|
||||
}
|
||||
async buildHeaders({ options, method, bodyHeaders, retryCount, }) {
|
||||
let idempotencyHeaders = {};
|
||||
if (this.idempotencyHeader && method !== 'get') {
|
||||
if (!options.idempotencyKey)
|
||||
options.idempotencyKey = this.defaultIdempotencyKey();
|
||||
idempotencyHeaders[this.idempotencyHeader] = options.idempotencyKey;
|
||||
}
|
||||
const headers = buildHeaders([
|
||||
idempotencyHeaders,
|
||||
{
|
||||
Accept: 'application/json',
|
||||
'User-Agent': this.getUserAgent(),
|
||||
'X-Stainless-Retry-Count': String(retryCount),
|
||||
...(options.timeout ? { 'X-Stainless-Timeout': String(Math.trunc(options.timeout / 1000)) } : {}),
|
||||
...getPlatformHeaders(),
|
||||
...(this._options.dangerouslyAllowBrowser ?
|
||||
{ 'anthropic-dangerous-direct-browser-access': 'true' }
|
||||
: undefined),
|
||||
'anthropic-version': '2023-06-01',
|
||||
},
|
||||
await this.authHeaders(options),
|
||||
this._options.defaultHeaders,
|
||||
bodyHeaders,
|
||||
options.headers,
|
||||
]);
|
||||
this.validateHeaders(headers);
|
||||
return headers.values;
|
||||
}
|
||||
_makeAbort(controller) {
|
||||
// note: we can't just inline this method inside `fetchWithTimeout()` because then the closure
|
||||
// would capture all request options, and cause a memory leak.
|
||||
return () => controller.abort();
|
||||
}
|
||||
buildBody({ options: { body, headers: rawHeaders } }) {
|
||||
if (!body) {
|
||||
return { bodyHeaders: undefined, body: undefined };
|
||||
}
|
||||
const headers = buildHeaders([rawHeaders]);
|
||||
if (
|
||||
// Pass raw type verbatim
|
||||
ArrayBuffer.isView(body) ||
|
||||
body instanceof ArrayBuffer ||
|
||||
body instanceof DataView ||
|
||||
(typeof body === 'string' &&
|
||||
// Preserve legacy string encoding behavior for now
|
||||
headers.values.has('content-type')) ||
|
||||
// `Blob` is superset of `File`
|
||||
(globalThis.Blob && body instanceof globalThis.Blob) ||
|
||||
// `FormData` -> `multipart/form-data`
|
||||
body instanceof FormData ||
|
||||
// `URLSearchParams` -> `application/x-www-form-urlencoded`
|
||||
body instanceof URLSearchParams ||
|
||||
// Send chunked stream (each chunk has own `length`)
|
||||
(globalThis.ReadableStream && body instanceof globalThis.ReadableStream)) {
|
||||
return { bodyHeaders: undefined, body: body };
|
||||
}
|
||||
else if (typeof body === 'object' &&
|
||||
(Symbol.asyncIterator in body ||
|
||||
(Symbol.iterator in body && 'next' in body && typeof body.next === 'function'))) {
|
||||
return { bodyHeaders: undefined, body: Shims.ReadableStreamFrom(body) };
|
||||
}
|
||||
else {
|
||||
return __classPrivateFieldGet(this, _BaseAnthropic_encoder, "f").call(this, { body, headers });
|
||||
}
|
||||
}
|
||||
}
|
||||
_a = BaseAnthropic, _BaseAnthropic_encoder = new WeakMap(), _BaseAnthropic_instances = new WeakSet(), _BaseAnthropic_baseURLOverridden = function _BaseAnthropic_baseURLOverridden() {
|
||||
return this.baseURL !== 'https://api.anthropic.com';
|
||||
};
|
||||
BaseAnthropic.Anthropic = _a;
|
||||
BaseAnthropic.HUMAN_PROMPT = HUMAN_PROMPT;
|
||||
BaseAnthropic.AI_PROMPT = AI_PROMPT;
|
||||
BaseAnthropic.DEFAULT_TIMEOUT = 600000; // 10 minutes
|
||||
BaseAnthropic.AnthropicError = Errors.AnthropicError;
|
||||
BaseAnthropic.APIError = Errors.APIError;
|
||||
BaseAnthropic.APIConnectionError = Errors.APIConnectionError;
|
||||
BaseAnthropic.APIConnectionTimeoutError = Errors.APIConnectionTimeoutError;
|
||||
BaseAnthropic.APIUserAbortError = Errors.APIUserAbortError;
|
||||
BaseAnthropic.NotFoundError = Errors.NotFoundError;
|
||||
BaseAnthropic.ConflictError = Errors.ConflictError;
|
||||
BaseAnthropic.RateLimitError = Errors.RateLimitError;
|
||||
BaseAnthropic.BadRequestError = Errors.BadRequestError;
|
||||
BaseAnthropic.AuthenticationError = Errors.AuthenticationError;
|
||||
BaseAnthropic.InternalServerError = Errors.InternalServerError;
|
||||
BaseAnthropic.PermissionDeniedError = Errors.PermissionDeniedError;
|
||||
BaseAnthropic.UnprocessableEntityError = Errors.UnprocessableEntityError;
|
||||
BaseAnthropic.toFile = Uploads.toFile;
|
||||
/**
|
||||
* API Client for interfacing with the Anthropic API.
|
||||
*/
|
||||
export class Anthropic extends BaseAnthropic {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.completions = new API.Completions(this);
|
||||
this.messages = new API.Messages(this);
|
||||
this.models = new API.Models(this);
|
||||
this.beta = new API.Beta(this);
|
||||
}
|
||||
}
|
||||
Anthropic.Completions = Completions;
|
||||
Anthropic.Messages = Messages;
|
||||
Anthropic.Models = Models;
|
||||
Anthropic.Beta = Beta;
|
||||
//# sourceMappingURL=client.mjs.map
|
||||
72
extracted-source/node_modules/@anthropic-ai/sdk/core/api-promise.mjs
generated
vendored
Normal file
72
extracted-source/node_modules/@anthropic-ai/sdk/core/api-promise.mjs
generated
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
||||
var _APIPromise_client;
|
||||
import { __classPrivateFieldGet, __classPrivateFieldSet } from "../internal/tslib.mjs";
|
||||
import { defaultParseResponse, addRequestID, } from "../internal/parse.mjs";
|
||||
/**
|
||||
* A subclass of `Promise` providing additional helper methods
|
||||
* for interacting with the SDK.
|
||||
*/
|
||||
export class APIPromise extends Promise {
|
||||
constructor(client, responsePromise, parseResponse = defaultParseResponse) {
|
||||
super((resolve) => {
|
||||
// this is maybe a bit weird but this has to be a no-op to not implicitly
|
||||
// parse the response body; instead .then, .catch, .finally are overridden
|
||||
// to parse the response
|
||||
resolve(null);
|
||||
});
|
||||
this.responsePromise = responsePromise;
|
||||
this.parseResponse = parseResponse;
|
||||
_APIPromise_client.set(this, void 0);
|
||||
__classPrivateFieldSet(this, _APIPromise_client, client, "f");
|
||||
}
|
||||
_thenUnwrap(transform) {
|
||||
return new APIPromise(__classPrivateFieldGet(this, _APIPromise_client, "f"), this.responsePromise, async (client, props) => addRequestID(transform(await this.parseResponse(client, props), props), props.response));
|
||||
}
|
||||
/**
|
||||
* Gets the raw `Response` instance instead of parsing the response
|
||||
* data.
|
||||
*
|
||||
* If you want to parse the response body but still get the `Response`
|
||||
* instance, you can use {@link withResponse()}.
|
||||
*
|
||||
* 👋 Getting the wrong TypeScript type for `Response`?
|
||||
* Try setting `"moduleResolution": "NodeNext"` or add `"lib": ["DOM"]`
|
||||
* to your `tsconfig.json`.
|
||||
*/
|
||||
asResponse() {
|
||||
return this.responsePromise.then((p) => p.response);
|
||||
}
|
||||
/**
|
||||
* Gets the parsed response data, the raw `Response` instance and the ID of the request,
|
||||
* returned via the `request-id` header which is useful for debugging requests and resporting
|
||||
* issues to Anthropic.
|
||||
*
|
||||
* If you just want to get the raw `Response` instance without parsing it,
|
||||
* you can use {@link asResponse()}.
|
||||
*
|
||||
* 👋 Getting the wrong TypeScript type for `Response`?
|
||||
* Try setting `"moduleResolution": "NodeNext"` or add `"lib": ["DOM"]`
|
||||
* to your `tsconfig.json`.
|
||||
*/
|
||||
async withResponse() {
|
||||
const [data, response] = await Promise.all([this.parse(), this.asResponse()]);
|
||||
return { data, response, request_id: response.headers.get('request-id') };
|
||||
}
|
||||
parse() {
|
||||
if (!this.parsedPromise) {
|
||||
this.parsedPromise = this.responsePromise.then((data) => this.parseResponse(__classPrivateFieldGet(this, _APIPromise_client, "f"), data));
|
||||
}
|
||||
return this.parsedPromise;
|
||||
}
|
||||
then(onfulfilled, onrejected) {
|
||||
return this.parse().then(onfulfilled, onrejected);
|
||||
}
|
||||
catch(onrejected) {
|
||||
return this.parse().catch(onrejected);
|
||||
}
|
||||
finally(onfinally) {
|
||||
return this.parse().finally(onfinally);
|
||||
}
|
||||
}
|
||||
_APIPromise_client = new WeakMap();
|
||||
//# sourceMappingURL=api-promise.mjs.map
|
||||
98
extracted-source/node_modules/@anthropic-ai/sdk/core/error.mjs
generated
vendored
Normal file
98
extracted-source/node_modules/@anthropic-ai/sdk/core/error.mjs
generated
vendored
Normal file
@@ -0,0 +1,98 @@
|
||||
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
||||
import { castToError } from "../internal/errors.mjs";
|
||||
export class AnthropicError extends Error {
|
||||
}
|
||||
export class APIError extends AnthropicError {
|
||||
constructor(status, error, message, headers) {
|
||||
super(`${APIError.makeMessage(status, error, message)}`);
|
||||
this.status = status;
|
||||
this.headers = headers;
|
||||
this.requestID = headers?.get('request-id');
|
||||
this.error = error;
|
||||
}
|
||||
static makeMessage(status, error, message) {
|
||||
const msg = error?.message ?
|
||||
typeof error.message === 'string' ?
|
||||
error.message
|
||||
: JSON.stringify(error.message)
|
||||
: error ? JSON.stringify(error)
|
||||
: message;
|
||||
if (status && msg) {
|
||||
return `${status} ${msg}`;
|
||||
}
|
||||
if (status) {
|
||||
return `${status} status code (no body)`;
|
||||
}
|
||||
if (msg) {
|
||||
return msg;
|
||||
}
|
||||
return '(no status code or body)';
|
||||
}
|
||||
static generate(status, errorResponse, message, headers) {
|
||||
if (!status || !headers) {
|
||||
return new APIConnectionError({ message, cause: castToError(errorResponse) });
|
||||
}
|
||||
const error = errorResponse;
|
||||
if (status === 400) {
|
||||
return new BadRequestError(status, error, message, headers);
|
||||
}
|
||||
if (status === 401) {
|
||||
return new AuthenticationError(status, error, message, headers);
|
||||
}
|
||||
if (status === 403) {
|
||||
return new PermissionDeniedError(status, error, message, headers);
|
||||
}
|
||||
if (status === 404) {
|
||||
return new NotFoundError(status, error, message, headers);
|
||||
}
|
||||
if (status === 409) {
|
||||
return new ConflictError(status, error, message, headers);
|
||||
}
|
||||
if (status === 422) {
|
||||
return new UnprocessableEntityError(status, error, message, headers);
|
||||
}
|
||||
if (status === 429) {
|
||||
return new RateLimitError(status, error, message, headers);
|
||||
}
|
||||
if (status >= 500) {
|
||||
return new InternalServerError(status, error, message, headers);
|
||||
}
|
||||
return new APIError(status, error, message, headers);
|
||||
}
|
||||
}
|
||||
export class APIUserAbortError extends APIError {
|
||||
constructor({ message } = {}) {
|
||||
super(undefined, undefined, message || 'Request was aborted.', undefined);
|
||||
}
|
||||
}
|
||||
export class APIConnectionError extends APIError {
|
||||
constructor({ message, cause }) {
|
||||
super(undefined, undefined, message || 'Connection error.', undefined);
|
||||
// in some environments the 'cause' property is already declared
|
||||
// @ts-ignore
|
||||
if (cause)
|
||||
this.cause = cause;
|
||||
}
|
||||
}
|
||||
export class APIConnectionTimeoutError extends APIConnectionError {
|
||||
constructor({ message } = {}) {
|
||||
super({ message: message ?? 'Request timed out.' });
|
||||
}
|
||||
}
|
||||
export class BadRequestError extends APIError {
|
||||
}
|
||||
export class AuthenticationError extends APIError {
|
||||
}
|
||||
export class PermissionDeniedError extends APIError {
|
||||
}
|
||||
export class NotFoundError extends APIError {
|
||||
}
|
||||
export class ConflictError extends APIError {
|
||||
}
|
||||
export class UnprocessableEntityError extends APIError {
|
||||
}
|
||||
export class RateLimitError extends APIError {
|
||||
}
|
||||
export class InternalServerError extends APIError {
|
||||
}
|
||||
//# sourceMappingURL=error.mjs.map
|
||||
177
extracted-source/node_modules/@anthropic-ai/sdk/core/pagination.mjs
generated
vendored
Normal file
177
extracted-source/node_modules/@anthropic-ai/sdk/core/pagination.mjs
generated
vendored
Normal file
@@ -0,0 +1,177 @@
|
||||
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
||||
var _AbstractPage_client;
|
||||
import { __classPrivateFieldGet, __classPrivateFieldSet } from "../internal/tslib.mjs";
|
||||
import { AnthropicError } from "./error.mjs";
|
||||
import { defaultParseResponse } from "../internal/parse.mjs";
|
||||
import { APIPromise } from "./api-promise.mjs";
|
||||
import { maybeObj } from "../internal/utils/values.mjs";
|
||||
export class AbstractPage {
|
||||
constructor(client, response, body, options) {
|
||||
_AbstractPage_client.set(this, void 0);
|
||||
__classPrivateFieldSet(this, _AbstractPage_client, client, "f");
|
||||
this.options = options;
|
||||
this.response = response;
|
||||
this.body = body;
|
||||
}
|
||||
hasNextPage() {
|
||||
const items = this.getPaginatedItems();
|
||||
if (!items.length)
|
||||
return false;
|
||||
return this.nextPageRequestOptions() != null;
|
||||
}
|
||||
async getNextPage() {
|
||||
const nextOptions = this.nextPageRequestOptions();
|
||||
if (!nextOptions) {
|
||||
throw new AnthropicError('No next page expected; please check `.hasNextPage()` before calling `.getNextPage()`.');
|
||||
}
|
||||
return await __classPrivateFieldGet(this, _AbstractPage_client, "f").requestAPIList(this.constructor, nextOptions);
|
||||
}
|
||||
async *iterPages() {
|
||||
let page = this;
|
||||
yield page;
|
||||
while (page.hasNextPage()) {
|
||||
page = await page.getNextPage();
|
||||
yield page;
|
||||
}
|
||||
}
|
||||
async *[(_AbstractPage_client = new WeakMap(), Symbol.asyncIterator)]() {
|
||||
for await (const page of this.iterPages()) {
|
||||
for (const item of page.getPaginatedItems()) {
|
||||
yield item;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* This subclass of Promise will resolve to an instantiated Page once the request completes.
|
||||
*
|
||||
* It also implements AsyncIterable to allow auto-paginating iteration on an unawaited list call, eg:
|
||||
*
|
||||
* for await (const item of client.items.list()) {
|
||||
* console.log(item)
|
||||
* }
|
||||
*/
|
||||
export class PagePromise extends APIPromise {
|
||||
constructor(client, request, Page) {
|
||||
super(client, request, async (client, props) => new Page(client, props.response, await defaultParseResponse(client, props), props.options));
|
||||
}
|
||||
/**
|
||||
* Allow auto-paginating iteration on an unawaited list call, eg:
|
||||
*
|
||||
* for await (const item of client.items.list()) {
|
||||
* console.log(item)
|
||||
* }
|
||||
*/
|
||||
async *[Symbol.asyncIterator]() {
|
||||
const page = await this;
|
||||
for await (const item of page) {
|
||||
yield item;
|
||||
}
|
||||
}
|
||||
}
|
||||
export class Page extends AbstractPage {
|
||||
constructor(client, response, body, options) {
|
||||
super(client, response, body, options);
|
||||
this.data = body.data || [];
|
||||
this.has_more = body.has_more || false;
|
||||
this.first_id = body.first_id || null;
|
||||
this.last_id = body.last_id || null;
|
||||
}
|
||||
getPaginatedItems() {
|
||||
return this.data ?? [];
|
||||
}
|
||||
hasNextPage() {
|
||||
if (this.has_more === false) {
|
||||
return false;
|
||||
}
|
||||
return super.hasNextPage();
|
||||
}
|
||||
nextPageRequestOptions() {
|
||||
if (this.options.query?.['before_id']) {
|
||||
// in reverse
|
||||
const first_id = this.first_id;
|
||||
if (!first_id) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
...this.options,
|
||||
query: {
|
||||
...maybeObj(this.options.query),
|
||||
before_id: first_id,
|
||||
},
|
||||
};
|
||||
}
|
||||
const cursor = this.last_id;
|
||||
if (!cursor) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
...this.options,
|
||||
query: {
|
||||
...maybeObj(this.options.query),
|
||||
after_id: cursor,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
export class TokenPage extends AbstractPage {
|
||||
constructor(client, response, body, options) {
|
||||
super(client, response, body, options);
|
||||
this.data = body.data || [];
|
||||
this.has_more = body.has_more || false;
|
||||
this.next_page = body.next_page || null;
|
||||
}
|
||||
getPaginatedItems() {
|
||||
return this.data ?? [];
|
||||
}
|
||||
hasNextPage() {
|
||||
if (this.has_more === false) {
|
||||
return false;
|
||||
}
|
||||
return super.hasNextPage();
|
||||
}
|
||||
nextPageRequestOptions() {
|
||||
const cursor = this.next_page;
|
||||
if (!cursor) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
...this.options,
|
||||
query: {
|
||||
...maybeObj(this.options.query),
|
||||
page_token: cursor,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
export class PageCursor extends AbstractPage {
|
||||
constructor(client, response, body, options) {
|
||||
super(client, response, body, options);
|
||||
this.data = body.data || [];
|
||||
this.has_more = body.has_more || false;
|
||||
this.next_page = body.next_page || null;
|
||||
}
|
||||
getPaginatedItems() {
|
||||
return this.data ?? [];
|
||||
}
|
||||
hasNextPage() {
|
||||
if (this.has_more === false) {
|
||||
return false;
|
||||
}
|
||||
return super.hasNextPage();
|
||||
}
|
||||
nextPageRequestOptions() {
|
||||
const cursor = this.next_page;
|
||||
if (!cursor) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
...this.options,
|
||||
query: {
|
||||
...maybeObj(this.options.query),
|
||||
page: cursor,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=pagination.mjs.map
|
||||
7
extracted-source/node_modules/@anthropic-ai/sdk/core/resource.mjs
generated
vendored
Normal file
7
extracted-source/node_modules/@anthropic-ai/sdk/core/resource.mjs
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
||||
export class APIResource {
|
||||
constructor(client) {
|
||||
this._client = client;
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=resource.mjs.map
|
||||
283
extracted-source/node_modules/@anthropic-ai/sdk/core/streaming.mjs
generated
vendored
Normal file
283
extracted-source/node_modules/@anthropic-ai/sdk/core/streaming.mjs
generated
vendored
Normal file
@@ -0,0 +1,283 @@
|
||||
var _Stream_client;
|
||||
import { __classPrivateFieldGet, __classPrivateFieldSet } from "../internal/tslib.mjs";
|
||||
import { AnthropicError } from "./error.mjs";
|
||||
import { makeReadableStream } from "../internal/shims.mjs";
|
||||
import { findDoubleNewlineIndex, LineDecoder } from "../internal/decoders/line.mjs";
|
||||
import { ReadableStreamToAsyncIterable } from "../internal/shims.mjs";
|
||||
import { isAbortError } from "../internal/errors.mjs";
|
||||
import { safeJSON } from "../internal/utils/values.mjs";
|
||||
import { encodeUTF8 } from "../internal/utils/bytes.mjs";
|
||||
import { loggerFor } from "../internal/utils/log.mjs";
|
||||
import { APIError } from "./error.mjs";
|
||||
export class Stream {
|
||||
constructor(iterator, controller, client) {
|
||||
this.iterator = iterator;
|
||||
_Stream_client.set(this, void 0);
|
||||
this.controller = controller;
|
||||
__classPrivateFieldSet(this, _Stream_client, client, "f");
|
||||
}
|
||||
static fromSSEResponse(response, controller, client) {
|
||||
let consumed = false;
|
||||
const logger = client ? loggerFor(client) : console;
|
||||
async function* iterator() {
|
||||
if (consumed) {
|
||||
throw new AnthropicError('Cannot iterate over a consumed stream, use `.tee()` to split the stream.');
|
||||
}
|
||||
consumed = true;
|
||||
let done = false;
|
||||
try {
|
||||
for await (const sse of _iterSSEMessages(response, controller)) {
|
||||
if (sse.event === 'completion') {
|
||||
try {
|
||||
yield JSON.parse(sse.data);
|
||||
}
|
||||
catch (e) {
|
||||
logger.error(`Could not parse message into JSON:`, sse.data);
|
||||
logger.error(`From chunk:`, sse.raw);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
if (sse.event === 'message_start' ||
|
||||
sse.event === 'message_delta' ||
|
||||
sse.event === 'message_stop' ||
|
||||
sse.event === 'content_block_start' ||
|
||||
sse.event === 'content_block_delta' ||
|
||||
sse.event === 'content_block_stop') {
|
||||
try {
|
||||
yield JSON.parse(sse.data);
|
||||
}
|
||||
catch (e) {
|
||||
logger.error(`Could not parse message into JSON:`, sse.data);
|
||||
logger.error(`From chunk:`, sse.raw);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
if (sse.event === 'ping') {
|
||||
continue;
|
||||
}
|
||||
if (sse.event === 'error') {
|
||||
throw new APIError(undefined, safeJSON(sse.data) ?? sse.data, undefined, response.headers);
|
||||
}
|
||||
}
|
||||
done = true;
|
||||
}
|
||||
catch (e) {
|
||||
// If the user calls `stream.controller.abort()`, we should exit without throwing.
|
||||
if (isAbortError(e))
|
||||
return;
|
||||
throw e;
|
||||
}
|
||||
finally {
|
||||
// If the user `break`s, abort the ongoing request.
|
||||
if (!done)
|
||||
controller.abort();
|
||||
}
|
||||
}
|
||||
return new Stream(iterator, controller, client);
|
||||
}
|
||||
/**
|
||||
* Generates a Stream from a newline-separated ReadableStream
|
||||
* where each item is a JSON value.
|
||||
*/
|
||||
static fromReadableStream(readableStream, controller, client) {
|
||||
let consumed = false;
|
||||
async function* iterLines() {
|
||||
const lineDecoder = new LineDecoder();
|
||||
const iter = ReadableStreamToAsyncIterable(readableStream);
|
||||
for await (const chunk of iter) {
|
||||
for (const line of lineDecoder.decode(chunk)) {
|
||||
yield line;
|
||||
}
|
||||
}
|
||||
for (const line of lineDecoder.flush()) {
|
||||
yield line;
|
||||
}
|
||||
}
|
||||
async function* iterator() {
|
||||
if (consumed) {
|
||||
throw new AnthropicError('Cannot iterate over a consumed stream, use `.tee()` to split the stream.');
|
||||
}
|
||||
consumed = true;
|
||||
let done = false;
|
||||
try {
|
||||
for await (const line of iterLines()) {
|
||||
if (done)
|
||||
continue;
|
||||
if (line)
|
||||
yield JSON.parse(line);
|
||||
}
|
||||
done = true;
|
||||
}
|
||||
catch (e) {
|
||||
// If the user calls `stream.controller.abort()`, we should exit without throwing.
|
||||
if (isAbortError(e))
|
||||
return;
|
||||
throw e;
|
||||
}
|
||||
finally {
|
||||
// If the user `break`s, abort the ongoing request.
|
||||
if (!done)
|
||||
controller.abort();
|
||||
}
|
||||
}
|
||||
return new Stream(iterator, controller, client);
|
||||
}
|
||||
[(_Stream_client = new WeakMap(), Symbol.asyncIterator)]() {
|
||||
return this.iterator();
|
||||
}
|
||||
/**
|
||||
* Splits the stream into two streams which can be
|
||||
* independently read from at different speeds.
|
||||
*/
|
||||
tee() {
|
||||
const left = [];
|
||||
const right = [];
|
||||
const iterator = this.iterator();
|
||||
const teeIterator = (queue) => {
|
||||
return {
|
||||
next: () => {
|
||||
if (queue.length === 0) {
|
||||
const result = iterator.next();
|
||||
left.push(result);
|
||||
right.push(result);
|
||||
}
|
||||
return queue.shift();
|
||||
},
|
||||
};
|
||||
};
|
||||
return [
|
||||
new Stream(() => teeIterator(left), this.controller, __classPrivateFieldGet(this, _Stream_client, "f")),
|
||||
new Stream(() => teeIterator(right), this.controller, __classPrivateFieldGet(this, _Stream_client, "f")),
|
||||
];
|
||||
}
|
||||
/**
|
||||
* Converts this stream to a newline-separated ReadableStream of
|
||||
* JSON stringified values in the stream
|
||||
* which can be turned back into a Stream with `Stream.fromReadableStream()`.
|
||||
*/
|
||||
toReadableStream() {
|
||||
const self = this;
|
||||
let iter;
|
||||
return makeReadableStream({
|
||||
async start() {
|
||||
iter = self[Symbol.asyncIterator]();
|
||||
},
|
||||
async pull(ctrl) {
|
||||
try {
|
||||
const { value, done } = await iter.next();
|
||||
if (done)
|
||||
return ctrl.close();
|
||||
const bytes = encodeUTF8(JSON.stringify(value) + '\n');
|
||||
ctrl.enqueue(bytes);
|
||||
}
|
||||
catch (err) {
|
||||
ctrl.error(err);
|
||||
}
|
||||
},
|
||||
async cancel() {
|
||||
await iter.return?.();
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
export async function* _iterSSEMessages(response, controller) {
|
||||
if (!response.body) {
|
||||
controller.abort();
|
||||
if (typeof globalThis.navigator !== 'undefined' &&
|
||||
globalThis.navigator.product === 'ReactNative') {
|
||||
throw new AnthropicError(`The default react-native fetch implementation does not support streaming. Please use expo/fetch: https://docs.expo.dev/versions/latest/sdk/expo/#expofetch-api`);
|
||||
}
|
||||
throw new AnthropicError(`Attempted to iterate over a response with no body`);
|
||||
}
|
||||
const sseDecoder = new SSEDecoder();
|
||||
const lineDecoder = new LineDecoder();
|
||||
const iter = ReadableStreamToAsyncIterable(response.body);
|
||||
for await (const sseChunk of iterSSEChunks(iter)) {
|
||||
for (const line of lineDecoder.decode(sseChunk)) {
|
||||
const sse = sseDecoder.decode(line);
|
||||
if (sse)
|
||||
yield sse;
|
||||
}
|
||||
}
|
||||
for (const line of lineDecoder.flush()) {
|
||||
const sse = sseDecoder.decode(line);
|
||||
if (sse)
|
||||
yield sse;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Given an async iterable iterator, iterates over it and yields full
|
||||
* SSE chunks, i.e. yields when a double new-line is encountered.
|
||||
*/
|
||||
async function* iterSSEChunks(iterator) {
|
||||
let data = new Uint8Array();
|
||||
for await (const chunk of iterator) {
|
||||
if (chunk == null) {
|
||||
continue;
|
||||
}
|
||||
const binaryChunk = chunk instanceof ArrayBuffer ? new Uint8Array(chunk)
|
||||
: typeof chunk === 'string' ? encodeUTF8(chunk)
|
||||
: chunk;
|
||||
let newData = new Uint8Array(data.length + binaryChunk.length);
|
||||
newData.set(data);
|
||||
newData.set(binaryChunk, data.length);
|
||||
data = newData;
|
||||
let patternIndex;
|
||||
while ((patternIndex = findDoubleNewlineIndex(data)) !== -1) {
|
||||
yield data.slice(0, patternIndex);
|
||||
data = data.slice(patternIndex);
|
||||
}
|
||||
}
|
||||
if (data.length > 0) {
|
||||
yield data;
|
||||
}
|
||||
}
|
||||
class SSEDecoder {
|
||||
constructor() {
|
||||
this.event = null;
|
||||
this.data = [];
|
||||
this.chunks = [];
|
||||
}
|
||||
decode(line) {
|
||||
if (line.endsWith('\r')) {
|
||||
line = line.substring(0, line.length - 1);
|
||||
}
|
||||
if (!line) {
|
||||
// empty line and we didn't previously encounter any messages
|
||||
if (!this.event && !this.data.length)
|
||||
return null;
|
||||
const sse = {
|
||||
event: this.event,
|
||||
data: this.data.join('\n'),
|
||||
raw: this.chunks,
|
||||
};
|
||||
this.event = null;
|
||||
this.data = [];
|
||||
this.chunks = [];
|
||||
return sse;
|
||||
}
|
||||
this.chunks.push(line);
|
||||
if (line.startsWith(':')) {
|
||||
return null;
|
||||
}
|
||||
let [fieldname, _, value] = partition(line, ':');
|
||||
if (value.startsWith(' ')) {
|
||||
value = value.substring(1);
|
||||
}
|
||||
if (fieldname === 'event') {
|
||||
this.event = value;
|
||||
}
|
||||
else if (fieldname === 'data') {
|
||||
this.data.push(value);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
function partition(str, delimiter) {
|
||||
const index = str.indexOf(delimiter);
|
||||
if (index !== -1) {
|
||||
return [str.substring(0, index), delimiter, str.substring(index + delimiter.length)];
|
||||
}
|
||||
return [str, '', ''];
|
||||
}
|
||||
//# sourceMappingURL=streaming.mjs.map
|
||||
2
extracted-source/node_modules/@anthropic-ai/sdk/core/uploads.mjs
generated
vendored
Normal file
2
extracted-source/node_modules/@anthropic-ai/sdk/core/uploads.mjs
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export { toFile } from "../internal/to-file.mjs";
|
||||
//# sourceMappingURL=uploads.mjs.map
|
||||
2
extracted-source/node_modules/@anthropic-ai/sdk/error.mjs
generated
vendored
Normal file
2
extracted-source/node_modules/@anthropic-ai/sdk/error.mjs
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from "./core/error.mjs";
|
||||
//# sourceMappingURL=error.mjs.map
|
||||
8
extracted-source/node_modules/@anthropic-ai/sdk/index.mjs
generated
vendored
Normal file
8
extracted-source/node_modules/@anthropic-ai/sdk/index.mjs
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
||||
export { Anthropic as default } from "./client.mjs";
|
||||
export { toFile } from "./core/uploads.mjs";
|
||||
export { APIPromise } from "./core/api-promise.mjs";
|
||||
export { BaseAnthropic, Anthropic, HUMAN_PROMPT, AI_PROMPT } from "./client.mjs";
|
||||
export { PagePromise } from "./core/pagination.mjs";
|
||||
export { AnthropicError, APIError, APIConnectionError, APIConnectionTimeoutError, APIUserAbortError, NotFoundError, ConflictError, RateLimitError, BadRequestError, AuthenticationError, InternalServerError, PermissionDeniedError, UnprocessableEntityError, } from "./core/error.mjs";
|
||||
//# sourceMappingURL=index.mjs.map
|
||||
15
extracted-source/node_modules/@anthropic-ai/sdk/internal/constants.mjs
generated
vendored
Normal file
15
extracted-source/node_modules/@anthropic-ai/sdk/internal/constants.mjs
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
// File containing shared constants
|
||||
/**
|
||||
* Model-specific timeout constraints for non-streaming requests
|
||||
*/
|
||||
export const MODEL_NONSTREAMING_TOKENS = {
|
||||
'claude-opus-4-20250514': 8192,
|
||||
'claude-opus-4-0': 8192,
|
||||
'claude-4-opus-20250514': 8192,
|
||||
'anthropic.claude-opus-4-20250514-v1:0': 8192,
|
||||
'claude-opus-4@20250514': 8192,
|
||||
'claude-opus-4-1-20250805': 8192,
|
||||
'anthropic.claude-opus-4-1-20250805-v1:0': 8192,
|
||||
'claude-opus-4-1@20250805': 8192,
|
||||
};
|
||||
//# sourceMappingURL=constants.mjs.map
|
||||
35
extracted-source/node_modules/@anthropic-ai/sdk/internal/decoders/jsonl.mjs
generated
vendored
Normal file
35
extracted-source/node_modules/@anthropic-ai/sdk/internal/decoders/jsonl.mjs
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
import { AnthropicError } from "../../core/error.mjs";
|
||||
import { ReadableStreamToAsyncIterable } from "../shims.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();
|
||||
if (typeof globalThis.navigator !== 'undefined' &&
|
||||
globalThis.navigator.product === 'ReactNative') {
|
||||
throw new AnthropicError(`The default react-native fetch implementation does not support streaming. Please use expo/fetch: https://docs.expo.dev/versions/latest/sdk/expo/#expofetch-api`);
|
||||
}
|
||||
throw new AnthropicError(`Attempted to iterate over a response with no body`);
|
||||
}
|
||||
return new JSONLDecoder(ReadableStreamToAsyncIterable(response.body), controller);
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=jsonl.mjs.map
|
||||
108
extracted-source/node_modules/@anthropic-ai/sdk/internal/decoders/line.mjs
generated
vendored
Normal file
108
extracted-source/node_modules/@anthropic-ai/sdk/internal/decoders/line.mjs
generated
vendored
Normal file
@@ -0,0 +1,108 @@
|
||||
var _LineDecoder_buffer, _LineDecoder_carriageReturnIndex;
|
||||
import { __classPrivateFieldGet, __classPrivateFieldSet } from "../tslib.mjs";
|
||||
import { concatBytes, decodeUTF8, encodeUTF8 } from "../utils/bytes.mjs";
|
||||
/**
|
||||
* A re-implementation of httpx's `LineDecoder` in Python that handles incrementally
|
||||
* reading lines from text.
|
||||
*
|
||||
* https://github.com/encode/httpx/blob/920333ea98118e9cf617f246905d7b202510941c/httpx/_decoders.py#L258
|
||||
*/
|
||||
export class LineDecoder {
|
||||
constructor() {
|
||||
_LineDecoder_buffer.set(this, void 0);
|
||||
_LineDecoder_carriageReturnIndex.set(this, void 0);
|
||||
__classPrivateFieldSet(this, _LineDecoder_buffer, new Uint8Array(), "f");
|
||||
__classPrivateFieldSet(this, _LineDecoder_carriageReturnIndex, null, "f");
|
||||
}
|
||||
decode(chunk) {
|
||||
if (chunk == null) {
|
||||
return [];
|
||||
}
|
||||
const binaryChunk = chunk instanceof ArrayBuffer ? new Uint8Array(chunk)
|
||||
: typeof chunk === 'string' ? encodeUTF8(chunk)
|
||||
: chunk;
|
||||
__classPrivateFieldSet(this, _LineDecoder_buffer, concatBytes([__classPrivateFieldGet(this, _LineDecoder_buffer, "f"), binaryChunk]), "f");
|
||||
const lines = [];
|
||||
let patternIndex;
|
||||
while ((patternIndex = findNewlineIndex(__classPrivateFieldGet(this, _LineDecoder_buffer, "f"), __classPrivateFieldGet(this, _LineDecoder_carriageReturnIndex, "f"))) != null) {
|
||||
if (patternIndex.carriage && __classPrivateFieldGet(this, _LineDecoder_carriageReturnIndex, "f") == null) {
|
||||
// skip until we either get a corresponding `\n`, a new `\r` or nothing
|
||||
__classPrivateFieldSet(this, _LineDecoder_carriageReturnIndex, patternIndex.index, "f");
|
||||
continue;
|
||||
}
|
||||
// we got double \r or \rtext\n
|
||||
if (__classPrivateFieldGet(this, _LineDecoder_carriageReturnIndex, "f") != null &&
|
||||
(patternIndex.index !== __classPrivateFieldGet(this, _LineDecoder_carriageReturnIndex, "f") + 1 || patternIndex.carriage)) {
|
||||
lines.push(decodeUTF8(__classPrivateFieldGet(this, _LineDecoder_buffer, "f").subarray(0, __classPrivateFieldGet(this, _LineDecoder_carriageReturnIndex, "f") - 1)));
|
||||
__classPrivateFieldSet(this, _LineDecoder_buffer, __classPrivateFieldGet(this, _LineDecoder_buffer, "f").subarray(__classPrivateFieldGet(this, _LineDecoder_carriageReturnIndex, "f")), "f");
|
||||
__classPrivateFieldSet(this, _LineDecoder_carriageReturnIndex, null, "f");
|
||||
continue;
|
||||
}
|
||||
const endIndex = __classPrivateFieldGet(this, _LineDecoder_carriageReturnIndex, "f") !== null ? patternIndex.preceding - 1 : patternIndex.preceding;
|
||||
const line = decodeUTF8(__classPrivateFieldGet(this, _LineDecoder_buffer, "f").subarray(0, endIndex));
|
||||
lines.push(line);
|
||||
__classPrivateFieldSet(this, _LineDecoder_buffer, __classPrivateFieldGet(this, _LineDecoder_buffer, "f").subarray(patternIndex.index), "f");
|
||||
__classPrivateFieldSet(this, _LineDecoder_carriageReturnIndex, null, "f");
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
flush() {
|
||||
if (!__classPrivateFieldGet(this, _LineDecoder_buffer, "f").length) {
|
||||
return [];
|
||||
}
|
||||
return this.decode('\n');
|
||||
}
|
||||
}
|
||||
_LineDecoder_buffer = new WeakMap(), _LineDecoder_carriageReturnIndex = new WeakMap();
|
||||
// prettier-ignore
|
||||
LineDecoder.NEWLINE_CHARS = new Set(['\n', '\r']);
|
||||
LineDecoder.NEWLINE_REGEXP = /\r\n|[\n\r]/g;
|
||||
/**
|
||||
* This function searches the buffer for the end patterns, (\r or \n)
|
||||
* and returns an object with the index preceding the matched newline and the
|
||||
* index after the newline char. `null` is returned if no new line is found.
|
||||
*
|
||||
* ```ts
|
||||
* findNewLineIndex('abc\ndef') -> { preceding: 2, index: 3 }
|
||||
* ```
|
||||
*/
|
||||
function findNewlineIndex(buffer, startIndex) {
|
||||
const newline = 0x0a; // \n
|
||||
const carriage = 0x0d; // \r
|
||||
for (let i = startIndex ?? 0; i < buffer.length; i++) {
|
||||
if (buffer[i] === newline) {
|
||||
return { preceding: i, index: i + 1, carriage: false };
|
||||
}
|
||||
if (buffer[i] === carriage) {
|
||||
return { preceding: i, index: i + 1, carriage: true };
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
export function findDoubleNewlineIndex(buffer) {
|
||||
// This function searches the buffer for the end patterns (\r\r, \n\n, \r\n\r\n)
|
||||
// and returns the index right after the first occurrence of any pattern,
|
||||
// or -1 if none of the patterns are found.
|
||||
const newline = 0x0a; // \n
|
||||
const carriage = 0x0d; // \r
|
||||
for (let i = 0; i < buffer.length - 1; i++) {
|
||||
if (buffer[i] === newline && buffer[i + 1] === newline) {
|
||||
// \n\n
|
||||
return i + 2;
|
||||
}
|
||||
if (buffer[i] === carriage && buffer[i + 1] === carriage) {
|
||||
// \r\r
|
||||
return i + 2;
|
||||
}
|
||||
if (buffer[i] === carriage &&
|
||||
buffer[i + 1] === newline &&
|
||||
i + 3 < buffer.length &&
|
||||
buffer[i + 2] === carriage &&
|
||||
buffer[i + 3] === newline) {
|
||||
// \r\n\r\n
|
||||
return i + 4;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
//# sourceMappingURL=line.mjs.map
|
||||
157
extracted-source/node_modules/@anthropic-ai/sdk/internal/detect-platform.mjs
generated
vendored
Normal file
157
extracted-source/node_modules/@anthropic-ai/sdk/internal/detect-platform.mjs
generated
vendored
Normal file
@@ -0,0 +1,157 @@
|
||||
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
||||
import { VERSION } from "../version.mjs";
|
||||
export const isRunningInBrowser = () => {
|
||||
return (
|
||||
// @ts-ignore
|
||||
typeof window !== 'undefined' &&
|
||||
// @ts-ignore
|
||||
typeof window.document !== 'undefined' &&
|
||||
// @ts-ignore
|
||||
typeof navigator !== 'undefined');
|
||||
};
|
||||
/**
|
||||
* Note this does not detect 'browser'; for that, use getBrowserInfo().
|
||||
*/
|
||||
function getDetectedPlatform() {
|
||||
if (typeof Deno !== 'undefined' && Deno.build != null) {
|
||||
return 'deno';
|
||||
}
|
||||
if (typeof EdgeRuntime !== 'undefined') {
|
||||
return 'edge';
|
||||
}
|
||||
if (Object.prototype.toString.call(typeof globalThis.process !== 'undefined' ? globalThis.process : 0) === '[object process]') {
|
||||
return 'node';
|
||||
}
|
||||
return 'unknown';
|
||||
}
|
||||
const getPlatformProperties = () => {
|
||||
const detectedPlatform = getDetectedPlatform();
|
||||
if (detectedPlatform === 'deno') {
|
||||
return {
|
||||
'X-Stainless-Lang': 'js',
|
||||
'X-Stainless-Package-Version': VERSION,
|
||||
'X-Stainless-OS': normalizePlatform(Deno.build.os),
|
||||
'X-Stainless-Arch': normalizeArch(Deno.build.arch),
|
||||
'X-Stainless-Runtime': 'deno',
|
||||
'X-Stainless-Runtime-Version': typeof Deno.version === 'string' ? Deno.version : Deno.version?.deno ?? 'unknown',
|
||||
};
|
||||
}
|
||||
if (typeof EdgeRuntime !== 'undefined') {
|
||||
return {
|
||||
'X-Stainless-Lang': 'js',
|
||||
'X-Stainless-Package-Version': VERSION,
|
||||
'X-Stainless-OS': 'Unknown',
|
||||
'X-Stainless-Arch': `other:${EdgeRuntime}`,
|
||||
'X-Stainless-Runtime': 'edge',
|
||||
'X-Stainless-Runtime-Version': globalThis.process.version,
|
||||
};
|
||||
}
|
||||
// Check if Node.js
|
||||
if (detectedPlatform === 'node') {
|
||||
return {
|
||||
'X-Stainless-Lang': 'js',
|
||||
'X-Stainless-Package-Version': VERSION,
|
||||
'X-Stainless-OS': normalizePlatform(globalThis.process.platform ?? 'unknown'),
|
||||
'X-Stainless-Arch': normalizeArch(globalThis.process.arch ?? 'unknown'),
|
||||
'X-Stainless-Runtime': 'node',
|
||||
'X-Stainless-Runtime-Version': globalThis.process.version ?? 'unknown',
|
||||
};
|
||||
}
|
||||
const browserInfo = getBrowserInfo();
|
||||
if (browserInfo) {
|
||||
return {
|
||||
'X-Stainless-Lang': 'js',
|
||||
'X-Stainless-Package-Version': VERSION,
|
||||
'X-Stainless-OS': 'Unknown',
|
||||
'X-Stainless-Arch': 'unknown',
|
||||
'X-Stainless-Runtime': `browser:${browserInfo.browser}`,
|
||||
'X-Stainless-Runtime-Version': browserInfo.version,
|
||||
};
|
||||
}
|
||||
// TODO add support for Cloudflare workers, etc.
|
||||
return {
|
||||
'X-Stainless-Lang': 'js',
|
||||
'X-Stainless-Package-Version': VERSION,
|
||||
'X-Stainless-OS': 'Unknown',
|
||||
'X-Stainless-Arch': 'unknown',
|
||||
'X-Stainless-Runtime': 'unknown',
|
||||
'X-Stainless-Runtime-Version': 'unknown',
|
||||
};
|
||||
};
|
||||
// Note: modified from https://github.com/JS-DevTools/host-environment/blob/b1ab79ecde37db5d6e163c050e54fe7d287d7c92/src/isomorphic.browser.ts
|
||||
function getBrowserInfo() {
|
||||
if (typeof navigator === 'undefined' || !navigator) {
|
||||
return null;
|
||||
}
|
||||
// NOTE: The order matters here!
|
||||
const browserPatterns = [
|
||||
{ key: 'edge', pattern: /Edge(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
||||
{ key: 'ie', pattern: /MSIE(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
||||
{ key: 'ie', pattern: /Trident(?:.*rv\:(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
||||
{ key: 'chrome', pattern: /Chrome(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
||||
{ key: 'firefox', pattern: /Firefox(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
||||
{ key: 'safari', pattern: /(?:Version\W+(\d+)\.(\d+)(?:\.(\d+))?)?(?:\W+Mobile\S*)?\W+Safari/ },
|
||||
];
|
||||
// Find the FIRST matching browser
|
||||
for (const { key, pattern } of browserPatterns) {
|
||||
const match = pattern.exec(navigator.userAgent);
|
||||
if (match) {
|
||||
const major = match[1] || 0;
|
||||
const minor = match[2] || 0;
|
||||
const patch = match[3] || 0;
|
||||
return { browser: key, version: `${major}.${minor}.${patch}` };
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
const normalizeArch = (arch) => {
|
||||
// Node docs:
|
||||
// - https://nodejs.org/api/process.html#processarch
|
||||
// Deno docs:
|
||||
// - https://doc.deno.land/deno/stable/~/Deno.build
|
||||
if (arch === 'x32')
|
||||
return 'x32';
|
||||
if (arch === 'x86_64' || arch === 'x64')
|
||||
return 'x64';
|
||||
if (arch === 'arm')
|
||||
return 'arm';
|
||||
if (arch === 'aarch64' || arch === 'arm64')
|
||||
return 'arm64';
|
||||
if (arch)
|
||||
return `other:${arch}`;
|
||||
return 'unknown';
|
||||
};
|
||||
const normalizePlatform = (platform) => {
|
||||
// Node platforms:
|
||||
// - https://nodejs.org/api/process.html#processplatform
|
||||
// Deno platforms:
|
||||
// - https://doc.deno.land/deno/stable/~/Deno.build
|
||||
// - https://github.com/denoland/deno/issues/14799
|
||||
platform = platform.toLowerCase();
|
||||
// NOTE: this iOS check is untested and may not work
|
||||
// Node does not work natively on IOS, there is a fork at
|
||||
// https://github.com/nodejs-mobile/nodejs-mobile
|
||||
// however it is unknown at the time of writing how to detect if it is running
|
||||
if (platform.includes('ios'))
|
||||
return 'iOS';
|
||||
if (platform === 'android')
|
||||
return 'Android';
|
||||
if (platform === 'darwin')
|
||||
return 'MacOS';
|
||||
if (platform === 'win32')
|
||||
return 'Windows';
|
||||
if (platform === 'freebsd')
|
||||
return 'FreeBSD';
|
||||
if (platform === 'openbsd')
|
||||
return 'OpenBSD';
|
||||
if (platform === 'linux')
|
||||
return 'Linux';
|
||||
if (platform)
|
||||
return `Other:${platform}`;
|
||||
return 'Unknown';
|
||||
};
|
||||
let _platformHeaders;
|
||||
export const getPlatformHeaders = () => {
|
||||
return (_platformHeaders ?? (_platformHeaders = getPlatformProperties()));
|
||||
};
|
||||
//# sourceMappingURL=detect-platform.mjs.map
|
||||
36
extracted-source/node_modules/@anthropic-ai/sdk/internal/errors.mjs
generated
vendored
Normal file
36
extracted-source/node_modules/@anthropic-ai/sdk/internal/errors.mjs
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
||||
export function isAbortError(err) {
|
||||
return (typeof err === 'object' &&
|
||||
err !== null &&
|
||||
// Spec-compliant fetch implementations
|
||||
(('name' in err && err.name === 'AbortError') ||
|
||||
// Expo fetch
|
||||
('message' in err && String(err.message).includes('FetchRequestCanceledException'))));
|
||||
}
|
||||
export const castToError = (err) => {
|
||||
if (err instanceof Error)
|
||||
return err;
|
||||
if (typeof err === 'object' && err !== null) {
|
||||
try {
|
||||
if (Object.prototype.toString.call(err) === '[object Error]') {
|
||||
// @ts-ignore - not all envs have native support for cause yet
|
||||
const error = new Error(err.message, err.cause ? { cause: err.cause } : {});
|
||||
if (err.stack)
|
||||
error.stack = err.stack;
|
||||
// @ts-ignore - not all envs have native support for cause yet
|
||||
if (err.cause && !error.cause)
|
||||
error.cause = err.cause;
|
||||
if (err.name)
|
||||
error.name = err.name;
|
||||
return error;
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
try {
|
||||
return new Error(JSON.stringify(err));
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
return new Error(err);
|
||||
};
|
||||
//# sourceMappingURL=errors.mjs.map
|
||||
74
extracted-source/node_modules/@anthropic-ai/sdk/internal/headers.mjs
generated
vendored
Normal file
74
extracted-source/node_modules/@anthropic-ai/sdk/internal/headers.mjs
generated
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
||||
import { isReadonlyArray } from "./utils/values.mjs";
|
||||
const brand_privateNullableHeaders = Symbol.for('brand.privateNullableHeaders');
|
||||
function* iterateHeaders(headers) {
|
||||
if (!headers)
|
||||
return;
|
||||
if (brand_privateNullableHeaders in headers) {
|
||||
const { values, nulls } = headers;
|
||||
yield* values.entries();
|
||||
for (const name of nulls) {
|
||||
yield [name, null];
|
||||
}
|
||||
return;
|
||||
}
|
||||
let shouldClear = false;
|
||||
let iter;
|
||||
if (headers instanceof Headers) {
|
||||
iter = headers.entries();
|
||||
}
|
||||
else if (isReadonlyArray(headers)) {
|
||||
iter = headers;
|
||||
}
|
||||
else {
|
||||
shouldClear = true;
|
||||
iter = Object.entries(headers ?? {});
|
||||
}
|
||||
for (let row of iter) {
|
||||
const name = row[0];
|
||||
if (typeof name !== 'string')
|
||||
throw new TypeError('expected header name to be a string');
|
||||
const values = isReadonlyArray(row[1]) ? row[1] : [row[1]];
|
||||
let didClear = false;
|
||||
for (const value of values) {
|
||||
if (value === undefined)
|
||||
continue;
|
||||
// Objects keys always overwrite older headers, they never append.
|
||||
// Yield a null to clear the header before adding the new values.
|
||||
if (shouldClear && !didClear) {
|
||||
didClear = true;
|
||||
yield [name, null];
|
||||
}
|
||||
yield [name, value];
|
||||
}
|
||||
}
|
||||
}
|
||||
export const buildHeaders = (newHeaders) => {
|
||||
const targetHeaders = new Headers();
|
||||
const nullHeaders = new Set();
|
||||
for (const headers of newHeaders) {
|
||||
const seenHeaders = new Set();
|
||||
for (const [name, value] of iterateHeaders(headers)) {
|
||||
const lowerName = name.toLowerCase();
|
||||
if (!seenHeaders.has(lowerName)) {
|
||||
targetHeaders.delete(name);
|
||||
seenHeaders.add(lowerName);
|
||||
}
|
||||
if (value === null) {
|
||||
targetHeaders.delete(name);
|
||||
nullHeaders.add(lowerName);
|
||||
}
|
||||
else {
|
||||
targetHeaders.append(name, value);
|
||||
nullHeaders.delete(lowerName);
|
||||
}
|
||||
}
|
||||
}
|
||||
return { [brand_privateNullableHeaders]: true, values: targetHeaders, nulls: nullHeaders };
|
||||
};
|
||||
export const isEmptyHeaders = (headers) => {
|
||||
for (const _ of iterateHeaders(headers))
|
||||
return false;
|
||||
return true;
|
||||
};
|
||||
//# sourceMappingURL=headers.mjs.map
|
||||
56
extracted-source/node_modules/@anthropic-ai/sdk/internal/parse.mjs
generated
vendored
Normal file
56
extracted-source/node_modules/@anthropic-ai/sdk/internal/parse.mjs
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
||||
import { Stream } from "../core/streaming.mjs";
|
||||
import { formatRequestDetails, loggerFor } from "./utils/log.mjs";
|
||||
export async function defaultParseResponse(client, props) {
|
||||
const { response, requestLogID, retryOfRequestLogID, startTime } = props;
|
||||
const body = await (async () => {
|
||||
if (props.options.stream) {
|
||||
loggerFor(client).debug('response', response.status, response.url, response.headers, response.body);
|
||||
// Note: there is an invariant here that isn't represented in the type system
|
||||
// that if you set `stream: true` the response type must also be `Stream<T>`
|
||||
if (props.options.__streamClass) {
|
||||
return props.options.__streamClass.fromSSEResponse(response, props.controller);
|
||||
}
|
||||
return Stream.fromSSEResponse(response, props.controller);
|
||||
}
|
||||
// fetch refuses to read the body when the status code is 204.
|
||||
if (response.status === 204) {
|
||||
return null;
|
||||
}
|
||||
if (props.options.__binaryResponse) {
|
||||
return response;
|
||||
}
|
||||
const contentType = response.headers.get('content-type');
|
||||
const mediaType = contentType?.split(';')[0]?.trim();
|
||||
const isJSON = mediaType?.includes('application/json') || mediaType?.endsWith('+json');
|
||||
if (isJSON) {
|
||||
const contentLength = response.headers.get('content-length');
|
||||
if (contentLength === '0') {
|
||||
// if there is no content we can't do anything
|
||||
return undefined;
|
||||
}
|
||||
const json = await response.json();
|
||||
return addRequestID(json, response);
|
||||
}
|
||||
const text = await response.text();
|
||||
return text;
|
||||
})();
|
||||
loggerFor(client).debug(`[${requestLogID}] response parsed`, formatRequestDetails({
|
||||
retryOfRequestLogID,
|
||||
url: response.url,
|
||||
status: response.status,
|
||||
body,
|
||||
durationMs: Date.now() - startTime,
|
||||
}));
|
||||
return body;
|
||||
}
|
||||
export function addRequestID(value, response) {
|
||||
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
||||
return value;
|
||||
}
|
||||
return Object.defineProperty(value, '_request_id', {
|
||||
value: response.headers.get('request-id'),
|
||||
enumerable: false,
|
||||
});
|
||||
}
|
||||
//# sourceMappingURL=parse.mjs.map
|
||||
10
extracted-source/node_modules/@anthropic-ai/sdk/internal/request-options.mjs
generated
vendored
Normal file
10
extracted-source/node_modules/@anthropic-ai/sdk/internal/request-options.mjs
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
||||
export const FallbackEncoder = ({ headers, body }) => {
|
||||
return {
|
||||
bodyHeaders: {
|
||||
'content-type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(body),
|
||||
};
|
||||
};
|
||||
//# sourceMappingURL=request-options.mjs.map
|
||||
85
extracted-source/node_modules/@anthropic-ai/sdk/internal/shims.mjs
generated
vendored
Normal file
85
extracted-source/node_modules/@anthropic-ai/sdk/internal/shims.mjs
generated
vendored
Normal file
@@ -0,0 +1,85 @@
|
||||
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
||||
export function getDefaultFetch() {
|
||||
if (typeof fetch !== 'undefined') {
|
||||
return fetch;
|
||||
}
|
||||
throw new Error('`fetch` is not defined as a global; Either pass `fetch` to the client, `new Anthropic({ fetch })` or polyfill the global, `globalThis.fetch = fetch`');
|
||||
}
|
||||
export function makeReadableStream(...args) {
|
||||
const ReadableStream = globalThis.ReadableStream;
|
||||
if (typeof ReadableStream === 'undefined') {
|
||||
// Note: All of the platforms / runtimes we officially support already define
|
||||
// `ReadableStream` as a global, so this should only ever be hit on unsupported runtimes.
|
||||
throw new Error('`ReadableStream` is not defined as a global; You will need to polyfill it, `globalThis.ReadableStream = ReadableStream`');
|
||||
}
|
||||
return new ReadableStream(...args);
|
||||
}
|
||||
export function ReadableStreamFrom(iterable) {
|
||||
let iter = Symbol.asyncIterator in iterable ? iterable[Symbol.asyncIterator]() : iterable[Symbol.iterator]();
|
||||
return makeReadableStream({
|
||||
start() { },
|
||||
async pull(controller) {
|
||||
const { done, value } = await iter.next();
|
||||
if (done) {
|
||||
controller.close();
|
||||
}
|
||||
else {
|
||||
controller.enqueue(value);
|
||||
}
|
||||
},
|
||||
async cancel() {
|
||||
await iter.return?.();
|
||||
},
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Most browsers don't yet have async iterable support for ReadableStream,
|
||||
* and Node has a very different way of reading bytes from its "ReadableStream".
|
||||
*
|
||||
* This polyfill was pulled from https://github.com/MattiasBuelens/web-streams-polyfill/pull/122#issuecomment-1627354490
|
||||
*/
|
||||
export function ReadableStreamToAsyncIterable(stream) {
|
||||
if (stream[Symbol.asyncIterator])
|
||||
return stream;
|
||||
const reader = stream.getReader();
|
||||
return {
|
||||
async next() {
|
||||
try {
|
||||
const result = await reader.read();
|
||||
if (result?.done)
|
||||
reader.releaseLock(); // release lock when stream becomes closed
|
||||
return result;
|
||||
}
|
||||
catch (e) {
|
||||
reader.releaseLock(); // release lock when stream becomes errored
|
||||
throw e;
|
||||
}
|
||||
},
|
||||
async return() {
|
||||
const cancelPromise = reader.cancel();
|
||||
reader.releaseLock();
|
||||
await cancelPromise;
|
||||
return { done: true, value: undefined };
|
||||
},
|
||||
[Symbol.asyncIterator]() {
|
||||
return this;
|
||||
},
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Cancels a ReadableStream we don't need to consume.
|
||||
* See https://undici.nodejs.org/#/?id=garbage-collection
|
||||
*/
|
||||
export async function CancelReadableStream(stream) {
|
||||
if (stream === null || typeof stream !== 'object')
|
||||
return;
|
||||
if (stream[Symbol.asyncIterator]) {
|
||||
await stream[Symbol.asyncIterator]().return?.();
|
||||
return;
|
||||
}
|
||||
const reader = stream.getReader();
|
||||
const cancelPromise = reader.cancel();
|
||||
reader.releaseLock();
|
||||
await cancelPromise;
|
||||
}
|
||||
//# sourceMappingURL=shims.mjs.map
|
||||
93
extracted-source/node_modules/@anthropic-ai/sdk/internal/to-file.mjs
generated
vendored
Normal file
93
extracted-source/node_modules/@anthropic-ai/sdk/internal/to-file.mjs
generated
vendored
Normal file
@@ -0,0 +1,93 @@
|
||||
import { getName, makeFile, isAsyncIterable } from "./uploads.mjs";
|
||||
import { checkFileSupport } from "./uploads.mjs";
|
||||
/**
|
||||
* This check adds the arrayBuffer() method type because it is available and used at runtime
|
||||
*/
|
||||
const isBlobLike = (value) => value != null &&
|
||||
typeof value === 'object' &&
|
||||
typeof value.size === 'number' &&
|
||||
typeof value.type === 'string' &&
|
||||
typeof value.text === 'function' &&
|
||||
typeof value.slice === 'function' &&
|
||||
typeof value.arrayBuffer === 'function';
|
||||
/**
|
||||
* This check adds the arrayBuffer() method type because it is available and used at runtime
|
||||
*/
|
||||
const isFileLike = (value) => value != null &&
|
||||
typeof value === 'object' &&
|
||||
typeof value.name === 'string' &&
|
||||
typeof value.lastModified === 'number' &&
|
||||
isBlobLike(value);
|
||||
const isResponseLike = (value) => value != null &&
|
||||
typeof value === 'object' &&
|
||||
typeof value.url === 'string' &&
|
||||
typeof value.blob === 'function';
|
||||
/**
|
||||
* Helper for creating a {@link File} to pass to an SDK upload method from a variety of different data formats
|
||||
* @param value the raw content of the file. Can be an {@link Uploadable}, BlobLikePart, or AsyncIterable of BlobLikeParts
|
||||
* @param {string=} name the name of the file. If omitted, toFile will try to determine a file name from bits if possible
|
||||
* @param {Object=} options additional properties
|
||||
* @param {string=} options.type the MIME type of the content
|
||||
* @param {number=} options.lastModified the last modified timestamp
|
||||
* @returns a {@link File} with the given properties
|
||||
*/
|
||||
export async function toFile(value, name, options) {
|
||||
checkFileSupport();
|
||||
// If it's a promise, resolve it.
|
||||
value = await value;
|
||||
name || (name = getName(value, true));
|
||||
// If we've been given a `File` we don't need to do anything if the name / options
|
||||
// have not been customised.
|
||||
if (isFileLike(value)) {
|
||||
if (value instanceof File && name == null && options == null) {
|
||||
return value;
|
||||
}
|
||||
return makeFile([await value.arrayBuffer()], name ?? value.name, {
|
||||
type: value.type,
|
||||
lastModified: value.lastModified,
|
||||
...options,
|
||||
});
|
||||
}
|
||||
if (isResponseLike(value)) {
|
||||
const blob = await value.blob();
|
||||
name || (name = new URL(value.url).pathname.split(/[\\/]/).pop());
|
||||
return makeFile(await getBytes(blob), name, options);
|
||||
}
|
||||
const parts = await getBytes(value);
|
||||
if (!options?.type) {
|
||||
const type = parts.find((part) => typeof part === 'object' && 'type' in part && part.type);
|
||||
if (typeof type === 'string') {
|
||||
options = { ...options, type };
|
||||
}
|
||||
}
|
||||
return makeFile(parts, name, options);
|
||||
}
|
||||
async function getBytes(value) {
|
||||
let parts = [];
|
||||
if (typeof value === 'string' ||
|
||||
ArrayBuffer.isView(value) || // includes Uint8Array, Buffer, etc.
|
||||
value instanceof ArrayBuffer) {
|
||||
parts.push(value);
|
||||
}
|
||||
else if (isBlobLike(value)) {
|
||||
parts.push(value instanceof Blob ? value : await value.arrayBuffer());
|
||||
}
|
||||
else if (isAsyncIterable(value) // includes Readable, ReadableStream, etc.
|
||||
) {
|
||||
for await (const chunk of value) {
|
||||
parts.push(...(await getBytes(chunk))); // TODO, consider validating?
|
||||
}
|
||||
}
|
||||
else {
|
||||
const constructor = value?.constructor?.name;
|
||||
throw new Error(`Unexpected data type: ${typeof value}${constructor ? `; constructor: ${constructor}` : ''}${propsForError(value)}`);
|
||||
}
|
||||
return parts;
|
||||
}
|
||||
function propsForError(value) {
|
||||
if (typeof value !== 'object' || value === null)
|
||||
return '';
|
||||
const props = Object.getOwnPropertyNames(value);
|
||||
return `; props: [${props.map((p) => `"${p}"`).join(', ')}]`;
|
||||
}
|
||||
//# sourceMappingURL=to-file.mjs.map
|
||||
17
extracted-source/node_modules/@anthropic-ai/sdk/internal/tslib.mjs
generated
vendored
Normal file
17
extracted-source/node_modules/@anthropic-ai/sdk/internal/tslib.mjs
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
||||
if (kind === "m")
|
||||
throw new TypeError("Private method is not writable");
|
||||
if (kind === "a" && !f)
|
||||
throw new TypeError("Private accessor was defined without a setter");
|
||||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
||||
throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
||||
return kind === "a" ? f.call(receiver, value) : f ? (f.value = value) : state.set(receiver, value), value;
|
||||
}
|
||||
function __classPrivateFieldGet(receiver, state, kind, f) {
|
||||
if (kind === "a" && !f)
|
||||
throw new TypeError("Private accessor was defined without a getter");
|
||||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
||||
throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
||||
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
||||
}
|
||||
export { __classPrivateFieldSet, __classPrivateFieldGet };
|
||||
135
extracted-source/node_modules/@anthropic-ai/sdk/internal/uploads.mjs
generated
vendored
Normal file
135
extracted-source/node_modules/@anthropic-ai/sdk/internal/uploads.mjs
generated
vendored
Normal file
@@ -0,0 +1,135 @@
|
||||
import { ReadableStreamFrom } from "./shims.mjs";
|
||||
export const checkFileSupport = () => {
|
||||
if (typeof File === 'undefined') {
|
||||
const { process } = globalThis;
|
||||
const isOldNode = typeof process?.versions?.node === 'string' && parseInt(process.versions.node.split('.')) < 20;
|
||||
throw new Error('`File` is not defined as a global, which is required for file uploads.' +
|
||||
(isOldNode ?
|
||||
" Update to Node 20 LTS or newer, or set `globalThis.File` to `import('node:buffer').File`."
|
||||
: ''));
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Construct a `File` instance. This is used to ensure a helpful error is thrown
|
||||
* for environments that don't define a global `File` yet.
|
||||
*/
|
||||
export function makeFile(fileBits, fileName, options) {
|
||||
checkFileSupport();
|
||||
return new File(fileBits, fileName ?? 'unknown_file', options);
|
||||
}
|
||||
export function getName(value, stripPath) {
|
||||
const val = (typeof value === 'object' &&
|
||||
value !== null &&
|
||||
(('name' in value && value.name && String(value.name)) ||
|
||||
('url' in value && value.url && String(value.url)) ||
|
||||
('filename' in value && value.filename && String(value.filename)) ||
|
||||
('path' in value && value.path && String(value.path)))) ||
|
||||
'';
|
||||
return stripPath ? val.split(/[\\/]/).pop() || undefined : val;
|
||||
}
|
||||
export const isAsyncIterable = (value) => value != null && typeof value === 'object' && typeof value[Symbol.asyncIterator] === 'function';
|
||||
/**
|
||||
* Returns a multipart/form-data request if any part of the given request body contains a File / Blob value.
|
||||
* Otherwise returns the request as is.
|
||||
*/
|
||||
export const maybeMultipartFormRequestOptions = async (opts, fetch) => {
|
||||
if (!hasUploadableValue(opts.body))
|
||||
return opts;
|
||||
return { ...opts, body: await createForm(opts.body, fetch) };
|
||||
};
|
||||
export const multipartFormRequestOptions = async (opts, fetch, stripFilenames = true) => {
|
||||
return { ...opts, body: await createForm(opts.body, fetch, stripFilenames) };
|
||||
};
|
||||
const supportsFormDataMap = /* @__PURE__ */ new WeakMap();
|
||||
/**
|
||||
* node-fetch doesn't support the global FormData object in recent node versions. Instead of sending
|
||||
* properly-encoded form data, it just stringifies the object, resulting in a request body of "[object FormData]".
|
||||
* This function detects if the fetch function provided supports the global FormData object to avoid
|
||||
* confusing error messages later on.
|
||||
*/
|
||||
function supportsFormData(fetchObject) {
|
||||
const fetch = typeof fetchObject === 'function' ? fetchObject : fetchObject.fetch;
|
||||
const cached = supportsFormDataMap.get(fetch);
|
||||
if (cached)
|
||||
return cached;
|
||||
const promise = (async () => {
|
||||
try {
|
||||
const FetchResponse = ('Response' in fetch ?
|
||||
fetch.Response
|
||||
: (await fetch('data:,')).constructor);
|
||||
const data = new FormData();
|
||||
if (data.toString() === (await new FetchResponse(data).text())) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch {
|
||||
// avoid false negatives
|
||||
return true;
|
||||
}
|
||||
})();
|
||||
supportsFormDataMap.set(fetch, promise);
|
||||
return promise;
|
||||
}
|
||||
export const createForm = async (body, fetch, stripFilenames = true) => {
|
||||
if (!(await supportsFormData(fetch))) {
|
||||
throw new TypeError('The provided fetch function does not support file uploads with the current global FormData class.');
|
||||
}
|
||||
const form = new FormData();
|
||||
await Promise.all(Object.entries(body || {}).map(([key, value]) => addFormValue(form, key, value, stripFilenames)));
|
||||
return form;
|
||||
};
|
||||
// We check for Blob not File because Bun.File doesn't inherit from File,
|
||||
// but they both inherit from Blob and have a `name` property at runtime.
|
||||
const isNamedBlob = (value) => value instanceof Blob && 'name' in value;
|
||||
const isUploadable = (value) => typeof value === 'object' &&
|
||||
value !== null &&
|
||||
(value instanceof Response || isAsyncIterable(value) || isNamedBlob(value));
|
||||
const hasUploadableValue = (value) => {
|
||||
if (isUploadable(value))
|
||||
return true;
|
||||
if (Array.isArray(value))
|
||||
return value.some(hasUploadableValue);
|
||||
if (value && typeof value === 'object') {
|
||||
for (const k in value) {
|
||||
if (hasUploadableValue(value[k]))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
const addFormValue = async (form, key, value, stripFilenames) => {
|
||||
if (value === undefined)
|
||||
return;
|
||||
if (value == null) {
|
||||
throw new TypeError(`Received null for "${key}"; to pass null in FormData, you must use the string 'null'`);
|
||||
}
|
||||
// TODO: make nested formats configurable
|
||||
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
|
||||
form.append(key, String(value));
|
||||
}
|
||||
else if (value instanceof Response) {
|
||||
let options = {};
|
||||
const contentType = value.headers.get('Content-Type');
|
||||
if (contentType) {
|
||||
options = { type: contentType };
|
||||
}
|
||||
form.append(key, makeFile([await value.blob()], getName(value, stripFilenames), options));
|
||||
}
|
||||
else if (isAsyncIterable(value)) {
|
||||
form.append(key, makeFile([await new Response(ReadableStreamFrom(value)).blob()], getName(value, stripFilenames)));
|
||||
}
|
||||
else if (isNamedBlob(value)) {
|
||||
form.append(key, makeFile([value], getName(value, stripFilenames), { type: value.type }));
|
||||
}
|
||||
else if (Array.isArray(value)) {
|
||||
await Promise.all(value.map((entry) => addFormValue(form, key + '[]', entry, stripFilenames)));
|
||||
}
|
||||
else if (typeof value === 'object') {
|
||||
await Promise.all(Object.entries(value).map(([name, prop]) => addFormValue(form, `${key}[${name}]`, prop, stripFilenames)));
|
||||
}
|
||||
else {
|
||||
throw new TypeError(`Invalid value given to form, expected a string, number, boolean, object, Array, File or Blob but got ${value} instead`);
|
||||
}
|
||||
};
|
||||
//# sourceMappingURL=uploads.mjs.map
|
||||
26
extracted-source/node_modules/@anthropic-ai/sdk/internal/utils/bytes.mjs
generated
vendored
Normal file
26
extracted-source/node_modules/@anthropic-ai/sdk/internal/utils/bytes.mjs
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
export function concatBytes(buffers) {
|
||||
let length = 0;
|
||||
for (const buffer of buffers) {
|
||||
length += buffer.length;
|
||||
}
|
||||
const output = new Uint8Array(length);
|
||||
let index = 0;
|
||||
for (const buffer of buffers) {
|
||||
output.set(buffer, index);
|
||||
index += buffer.length;
|
||||
}
|
||||
return output;
|
||||
}
|
||||
let encodeUTF8_;
|
||||
export function encodeUTF8(str) {
|
||||
let encoder;
|
||||
return (encodeUTF8_ ??
|
||||
((encoder = new globalThis.TextEncoder()), (encodeUTF8_ = encoder.encode.bind(encoder))))(str);
|
||||
}
|
||||
let decodeUTF8_;
|
||||
export function decodeUTF8(bytes) {
|
||||
let decoder;
|
||||
return (decodeUTF8_ ??
|
||||
((decoder = new globalThis.TextDecoder()), (decodeUTF8_ = decoder.decode.bind(decoder))))(bytes);
|
||||
}
|
||||
//# sourceMappingURL=bytes.mjs.map
|
||||
18
extracted-source/node_modules/@anthropic-ai/sdk/internal/utils/env.mjs
generated
vendored
Normal file
18
extracted-source/node_modules/@anthropic-ai/sdk/internal/utils/env.mjs
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
||||
/**
|
||||
* Read an environment variable.
|
||||
*
|
||||
* Trims beginning and trailing whitespace.
|
||||
*
|
||||
* Will return undefined if the environment variable doesn't exist or cannot be accessed.
|
||||
*/
|
||||
export const readEnv = (env) => {
|
||||
if (typeof globalThis.process !== 'undefined') {
|
||||
return globalThis.process.env?.[env]?.trim() ?? undefined;
|
||||
}
|
||||
if (typeof globalThis.Deno !== 'undefined') {
|
||||
return globalThis.Deno.env?.get?.(env)?.trim();
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
//# sourceMappingURL=env.mjs.map
|
||||
80
extracted-source/node_modules/@anthropic-ai/sdk/internal/utils/log.mjs
generated
vendored
Normal file
80
extracted-source/node_modules/@anthropic-ai/sdk/internal/utils/log.mjs
generated
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
||||
import { hasOwn } from "./values.mjs";
|
||||
const levelNumbers = {
|
||||
off: 0,
|
||||
error: 200,
|
||||
warn: 300,
|
||||
info: 400,
|
||||
debug: 500,
|
||||
};
|
||||
export const parseLogLevel = (maybeLevel, sourceName, client) => {
|
||||
if (!maybeLevel) {
|
||||
return undefined;
|
||||
}
|
||||
if (hasOwn(levelNumbers, maybeLevel)) {
|
||||
return maybeLevel;
|
||||
}
|
||||
loggerFor(client).warn(`${sourceName} was set to ${JSON.stringify(maybeLevel)}, expected one of ${JSON.stringify(Object.keys(levelNumbers))}`);
|
||||
return undefined;
|
||||
};
|
||||
function noop() { }
|
||||
function makeLogFn(fnLevel, logger, logLevel) {
|
||||
if (!logger || levelNumbers[fnLevel] > levelNumbers[logLevel]) {
|
||||
return noop;
|
||||
}
|
||||
else {
|
||||
// Don't wrap logger functions, we want the stacktrace intact!
|
||||
return logger[fnLevel].bind(logger);
|
||||
}
|
||||
}
|
||||
const noopLogger = {
|
||||
error: noop,
|
||||
warn: noop,
|
||||
info: noop,
|
||||
debug: noop,
|
||||
};
|
||||
let cachedLoggers = /* @__PURE__ */ new WeakMap();
|
||||
export function loggerFor(client) {
|
||||
const logger = client.logger;
|
||||
const logLevel = client.logLevel ?? 'off';
|
||||
if (!logger) {
|
||||
return noopLogger;
|
||||
}
|
||||
const cachedLogger = cachedLoggers.get(logger);
|
||||
if (cachedLogger && cachedLogger[0] === logLevel) {
|
||||
return cachedLogger[1];
|
||||
}
|
||||
const levelLogger = {
|
||||
error: makeLogFn('error', logger, logLevel),
|
||||
warn: makeLogFn('warn', logger, logLevel),
|
||||
info: makeLogFn('info', logger, logLevel),
|
||||
debug: makeLogFn('debug', logger, logLevel),
|
||||
};
|
||||
cachedLoggers.set(logger, [logLevel, levelLogger]);
|
||||
return levelLogger;
|
||||
}
|
||||
export const formatRequestDetails = (details) => {
|
||||
if (details.options) {
|
||||
details.options = { ...details.options };
|
||||
delete details.options['headers']; // redundant + leaks internals
|
||||
}
|
||||
if (details.headers) {
|
||||
details.headers = Object.fromEntries((details.headers instanceof Headers ? [...details.headers] : Object.entries(details.headers)).map(([name, value]) => [
|
||||
name,
|
||||
(name.toLowerCase() === 'x-api-key' ||
|
||||
name.toLowerCase() === 'authorization' ||
|
||||
name.toLowerCase() === 'cookie' ||
|
||||
name.toLowerCase() === 'set-cookie') ?
|
||||
'***'
|
||||
: value,
|
||||
]));
|
||||
}
|
||||
if ('retryOfRequestLogID' in details) {
|
||||
if (details.retryOfRequestLogID) {
|
||||
details.retryOf = details.retryOfRequestLogID;
|
||||
}
|
||||
delete details.retryOfRequestLogID;
|
||||
}
|
||||
return details;
|
||||
};
|
||||
//# sourceMappingURL=log.mjs.map
|
||||
74
extracted-source/node_modules/@anthropic-ai/sdk/internal/utils/path.mjs
generated
vendored
Normal file
74
extracted-source/node_modules/@anthropic-ai/sdk/internal/utils/path.mjs
generated
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
import { AnthropicError } from "../../core/error.mjs";
|
||||
/**
|
||||
* Percent-encode everything that isn't safe to have in a path without encoding safe chars.
|
||||
*
|
||||
* Taken from https://datatracker.ietf.org/doc/html/rfc3986#section-3.3:
|
||||
* > unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
|
||||
* > sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
|
||||
* > pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
|
||||
*/
|
||||
export function encodeURIPath(str) {
|
||||
return str.replace(/[^A-Za-z0-9\-._~!$&'()*+,;=:@]+/g, encodeURIComponent);
|
||||
}
|
||||
const EMPTY = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.create(null));
|
||||
export const createPathTagFunction = (pathEncoder = encodeURIPath) => function path(statics, ...params) {
|
||||
// If there are no params, no processing is needed.
|
||||
if (statics.length === 1)
|
||||
return statics[0];
|
||||
let postPath = false;
|
||||
const invalidSegments = [];
|
||||
const path = statics.reduce((previousValue, currentValue, index) => {
|
||||
if (/[?#]/.test(currentValue)) {
|
||||
postPath = true;
|
||||
}
|
||||
const value = params[index];
|
||||
let encoded = (postPath ? encodeURIComponent : pathEncoder)('' + value);
|
||||
if (index !== params.length &&
|
||||
(value == null ||
|
||||
(typeof value === 'object' &&
|
||||
// handle values from other realms
|
||||
value.toString ===
|
||||
Object.getPrototypeOf(Object.getPrototypeOf(value.hasOwnProperty ?? EMPTY) ?? EMPTY)
|
||||
?.toString))) {
|
||||
encoded = value + '';
|
||||
invalidSegments.push({
|
||||
start: previousValue.length + currentValue.length,
|
||||
length: encoded.length,
|
||||
error: `Value of type ${Object.prototype.toString
|
||||
.call(value)
|
||||
.slice(8, -1)} is not a valid path parameter`,
|
||||
});
|
||||
}
|
||||
return previousValue + currentValue + (index === params.length ? '' : encoded);
|
||||
}, '');
|
||||
const pathOnly = path.split(/[?#]/, 1)[0];
|
||||
const invalidSegmentPattern = /(?<=^|\/)(?:\.|%2e){1,2}(?=\/|$)/gi;
|
||||
let match;
|
||||
// Find all invalid segments
|
||||
while ((match = invalidSegmentPattern.exec(pathOnly)) !== null) {
|
||||
invalidSegments.push({
|
||||
start: match.index,
|
||||
length: match[0].length,
|
||||
error: `Value "${match[0]}" can\'t be safely passed as a path parameter`,
|
||||
});
|
||||
}
|
||||
invalidSegments.sort((a, b) => a.start - b.start);
|
||||
if (invalidSegments.length > 0) {
|
||||
let lastEnd = 0;
|
||||
const underline = invalidSegments.reduce((acc, segment) => {
|
||||
const spaces = ' '.repeat(segment.start - lastEnd);
|
||||
const arrows = '^'.repeat(segment.length);
|
||||
lastEnd = segment.start + segment.length;
|
||||
return acc + spaces + arrows;
|
||||
}, '');
|
||||
throw new AnthropicError(`Path parameters result in path with invalid segments:\n${invalidSegments
|
||||
.map((e) => e.error)
|
||||
.join('\n')}\n${path}\n${underline}`);
|
||||
}
|
||||
return path;
|
||||
};
|
||||
/**
|
||||
* URI-encodes path params and ensures no unsafe /./ or /../ path segments are introduced.
|
||||
*/
|
||||
export const path = /* @__PURE__ */ createPathTagFunction(encodeURIPath);
|
||||
//# sourceMappingURL=path.mjs.map
|
||||
3
extracted-source/node_modules/@anthropic-ai/sdk/internal/utils/sleep.mjs
generated
vendored
Normal file
3
extracted-source/node_modules/@anthropic-ai/sdk/internal/utils/sleep.mjs
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
||||
export const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
//# sourceMappingURL=sleep.mjs.map
|
||||
15
extracted-source/node_modules/@anthropic-ai/sdk/internal/utils/uuid.mjs
generated
vendored
Normal file
15
extracted-source/node_modules/@anthropic-ai/sdk/internal/utils/uuid.mjs
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
||||
/**
|
||||
* https://stackoverflow.com/a/2117523
|
||||
*/
|
||||
export let uuid4 = function () {
|
||||
const { crypto } = globalThis;
|
||||
if (crypto?.randomUUID) {
|
||||
uuid4 = crypto.randomUUID.bind(crypto);
|
||||
return crypto.randomUUID();
|
||||
}
|
||||
const u8 = new Uint8Array(1);
|
||||
const randomByte = crypto ? () => crypto.getRandomValues(u8)[0] : () => (Math.random() * 0xff) & 0xff;
|
||||
return '10000000-1000-4000-8000-100000000000'.replace(/[018]/g, (c) => (+c ^ (randomByte() & (15 >> (+c / 4)))).toString(16));
|
||||
};
|
||||
//# sourceMappingURL=uuid.mjs.map
|
||||
100
extracted-source/node_modules/@anthropic-ai/sdk/internal/utils/values.mjs
generated
vendored
Normal file
100
extracted-source/node_modules/@anthropic-ai/sdk/internal/utils/values.mjs
generated
vendored
Normal file
@@ -0,0 +1,100 @@
|
||||
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
||||
import { AnthropicError } from "../../core/error.mjs";
|
||||
// https://url.spec.whatwg.org/#url-scheme-string
|
||||
const startsWithSchemeRegexp = /^[a-z][a-z0-9+.-]*:/i;
|
||||
export const isAbsoluteURL = (url) => {
|
||||
return startsWithSchemeRegexp.test(url);
|
||||
};
|
||||
export let isArray = (val) => ((isArray = Array.isArray), isArray(val));
|
||||
export let isReadonlyArray = isArray;
|
||||
/** Returns an object if the given value isn't an object, otherwise returns as-is */
|
||||
export function maybeObj(x) {
|
||||
if (typeof x !== 'object') {
|
||||
return {};
|
||||
}
|
||||
return x ?? {};
|
||||
}
|
||||
// https://stackoverflow.com/a/34491287
|
||||
export function isEmptyObj(obj) {
|
||||
if (!obj)
|
||||
return true;
|
||||
for (const _k in obj)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
// https://eslint.org/docs/latest/rules/no-prototype-builtins
|
||||
export function hasOwn(obj, key) {
|
||||
return Object.prototype.hasOwnProperty.call(obj, key);
|
||||
}
|
||||
export function isObj(obj) {
|
||||
return obj != null && typeof obj === 'object' && !Array.isArray(obj);
|
||||
}
|
||||
export const ensurePresent = (value) => {
|
||||
if (value == null) {
|
||||
throw new AnthropicError(`Expected a value to be given but received ${value} instead.`);
|
||||
}
|
||||
return value;
|
||||
};
|
||||
export const validatePositiveInteger = (name, n) => {
|
||||
if (typeof n !== 'number' || !Number.isInteger(n)) {
|
||||
throw new AnthropicError(`${name} must be an integer`);
|
||||
}
|
||||
if (n < 0) {
|
||||
throw new AnthropicError(`${name} must be a positive integer`);
|
||||
}
|
||||
return n;
|
||||
};
|
||||
export const coerceInteger = (value) => {
|
||||
if (typeof value === 'number')
|
||||
return Math.round(value);
|
||||
if (typeof value === 'string')
|
||||
return parseInt(value, 10);
|
||||
throw new AnthropicError(`Could not coerce ${value} (type: ${typeof value}) into a number`);
|
||||
};
|
||||
export const coerceFloat = (value) => {
|
||||
if (typeof value === 'number')
|
||||
return value;
|
||||
if (typeof value === 'string')
|
||||
return parseFloat(value);
|
||||
throw new AnthropicError(`Could not coerce ${value} (type: ${typeof value}) into a number`);
|
||||
};
|
||||
export const coerceBoolean = (value) => {
|
||||
if (typeof value === 'boolean')
|
||||
return value;
|
||||
if (typeof value === 'string')
|
||||
return value === 'true';
|
||||
return Boolean(value);
|
||||
};
|
||||
export const maybeCoerceInteger = (value) => {
|
||||
if (value == null) {
|
||||
return undefined;
|
||||
}
|
||||
return coerceInteger(value);
|
||||
};
|
||||
export const maybeCoerceFloat = (value) => {
|
||||
if (value == null) {
|
||||
return undefined;
|
||||
}
|
||||
return coerceFloat(value);
|
||||
};
|
||||
export const maybeCoerceBoolean = (value) => {
|
||||
if (value == null) {
|
||||
return undefined;
|
||||
}
|
||||
return coerceBoolean(value);
|
||||
};
|
||||
export const safeJSON = (text) => {
|
||||
try {
|
||||
return JSON.parse(text);
|
||||
}
|
||||
catch (err) {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
// Gets a value from an object, deletes the key, and returns the value (or undefined if not found)
|
||||
export const pop = (obj, key) => {
|
||||
const value = obj[key];
|
||||
delete obj[key];
|
||||
return value;
|
||||
};
|
||||
//# sourceMappingURL=values.mjs.map
|
||||
616
extracted-source/node_modules/@anthropic-ai/sdk/lib/BetaMessageStream.mjs
generated
vendored
Normal file
616
extracted-source/node_modules/@anthropic-ai/sdk/lib/BetaMessageStream.mjs
generated
vendored
Normal file
@@ -0,0 +1,616 @@
|
||||
var _BetaMessageStream_instances, _BetaMessageStream_currentMessageSnapshot, _BetaMessageStream_params, _BetaMessageStream_connectedPromise, _BetaMessageStream_resolveConnectedPromise, _BetaMessageStream_rejectConnectedPromise, _BetaMessageStream_endPromise, _BetaMessageStream_resolveEndPromise, _BetaMessageStream_rejectEndPromise, _BetaMessageStream_listeners, _BetaMessageStream_ended, _BetaMessageStream_errored, _BetaMessageStream_aborted, _BetaMessageStream_catchingPromiseCreated, _BetaMessageStream_response, _BetaMessageStream_request_id, _BetaMessageStream_logger, _BetaMessageStream_getFinalMessage, _BetaMessageStream_getFinalText, _BetaMessageStream_handleError, _BetaMessageStream_beginRequest, _BetaMessageStream_addStreamEvent, _BetaMessageStream_endRequest, _BetaMessageStream_accumulateMessage;
|
||||
import { __classPrivateFieldGet, __classPrivateFieldSet } from "../internal/tslib.mjs";
|
||||
import { partialParse } from "../_vendor/partial-json-parser/parser.mjs";
|
||||
import { AnthropicError, APIUserAbortError } from "../error.mjs";
|
||||
import { isAbortError } from "../internal/errors.mjs";
|
||||
import { Stream } from "../streaming.mjs";
|
||||
import { maybeParseBetaMessage } from "./beta-parser.mjs";
|
||||
const JSON_BUF_PROPERTY = '__json_buf';
|
||||
function tracksToolInput(content) {
|
||||
return content.type === 'tool_use' || content.type === 'server_tool_use' || content.type === 'mcp_tool_use';
|
||||
}
|
||||
export class BetaMessageStream {
|
||||
constructor(params, opts) {
|
||||
_BetaMessageStream_instances.add(this);
|
||||
this.messages = [];
|
||||
this.receivedMessages = [];
|
||||
_BetaMessageStream_currentMessageSnapshot.set(this, void 0);
|
||||
_BetaMessageStream_params.set(this, null);
|
||||
this.controller = new AbortController();
|
||||
_BetaMessageStream_connectedPromise.set(this, void 0);
|
||||
_BetaMessageStream_resolveConnectedPromise.set(this, () => { });
|
||||
_BetaMessageStream_rejectConnectedPromise.set(this, () => { });
|
||||
_BetaMessageStream_endPromise.set(this, void 0);
|
||||
_BetaMessageStream_resolveEndPromise.set(this, () => { });
|
||||
_BetaMessageStream_rejectEndPromise.set(this, () => { });
|
||||
_BetaMessageStream_listeners.set(this, {});
|
||||
_BetaMessageStream_ended.set(this, false);
|
||||
_BetaMessageStream_errored.set(this, false);
|
||||
_BetaMessageStream_aborted.set(this, false);
|
||||
_BetaMessageStream_catchingPromiseCreated.set(this, false);
|
||||
_BetaMessageStream_response.set(this, void 0);
|
||||
_BetaMessageStream_request_id.set(this, void 0);
|
||||
_BetaMessageStream_logger.set(this, void 0);
|
||||
_BetaMessageStream_handleError.set(this, (error) => {
|
||||
__classPrivateFieldSet(this, _BetaMessageStream_errored, true, "f");
|
||||
if (isAbortError(error)) {
|
||||
error = new APIUserAbortError();
|
||||
}
|
||||
if (error instanceof APIUserAbortError) {
|
||||
__classPrivateFieldSet(this, _BetaMessageStream_aborted, true, "f");
|
||||
return this._emit('abort', error);
|
||||
}
|
||||
if (error instanceof AnthropicError) {
|
||||
return this._emit('error', error);
|
||||
}
|
||||
if (error instanceof Error) {
|
||||
const anthropicError = new AnthropicError(error.message);
|
||||
// @ts-ignore
|
||||
anthropicError.cause = error;
|
||||
return this._emit('error', anthropicError);
|
||||
}
|
||||
return this._emit('error', new AnthropicError(String(error)));
|
||||
});
|
||||
__classPrivateFieldSet(this, _BetaMessageStream_connectedPromise, new Promise((resolve, reject) => {
|
||||
__classPrivateFieldSet(this, _BetaMessageStream_resolveConnectedPromise, resolve, "f");
|
||||
__classPrivateFieldSet(this, _BetaMessageStream_rejectConnectedPromise, reject, "f");
|
||||
}), "f");
|
||||
__classPrivateFieldSet(this, _BetaMessageStream_endPromise, new Promise((resolve, reject) => {
|
||||
__classPrivateFieldSet(this, _BetaMessageStream_resolveEndPromise, resolve, "f");
|
||||
__classPrivateFieldSet(this, _BetaMessageStream_rejectEndPromise, reject, "f");
|
||||
}), "f");
|
||||
// Don't let these promises cause unhandled rejection errors.
|
||||
// we will manually cause an unhandled rejection error later
|
||||
// if the user hasn't registered any error listener or called
|
||||
// any promise-returning method.
|
||||
__classPrivateFieldGet(this, _BetaMessageStream_connectedPromise, "f").catch(() => { });
|
||||
__classPrivateFieldGet(this, _BetaMessageStream_endPromise, "f").catch(() => { });
|
||||
__classPrivateFieldSet(this, _BetaMessageStream_params, params, "f");
|
||||
__classPrivateFieldSet(this, _BetaMessageStream_logger, opts?.logger ?? console, "f");
|
||||
}
|
||||
get response() {
|
||||
return __classPrivateFieldGet(this, _BetaMessageStream_response, "f");
|
||||
}
|
||||
get request_id() {
|
||||
return __classPrivateFieldGet(this, _BetaMessageStream_request_id, "f");
|
||||
}
|
||||
/**
|
||||
* Returns the `MessageStream` data, the raw `Response` instance and the ID of the request,
|
||||
* returned vie the `request-id` header which is useful for debugging requests and resporting
|
||||
* issues to Anthropic.
|
||||
*
|
||||
* This is the same as the `APIPromise.withResponse()` method.
|
||||
*
|
||||
* This method will raise an error if you created the stream using `MessageStream.fromReadableStream`
|
||||
* as no `Response` is available.
|
||||
*/
|
||||
async withResponse() {
|
||||
__classPrivateFieldSet(this, _BetaMessageStream_catchingPromiseCreated, true, "f");
|
||||
const response = await __classPrivateFieldGet(this, _BetaMessageStream_connectedPromise, "f");
|
||||
if (!response) {
|
||||
throw new Error('Could not resolve a `Response` object');
|
||||
}
|
||||
return {
|
||||
data: this,
|
||||
response,
|
||||
request_id: response.headers.get('request-id'),
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Intended for use on the frontend, consuming a stream produced with
|
||||
* `.toReadableStream()` on the backend.
|
||||
*
|
||||
* Note that messages sent to the model do not appear in `.on('message')`
|
||||
* in this context.
|
||||
*/
|
||||
static fromReadableStream(stream) {
|
||||
const runner = new BetaMessageStream(null);
|
||||
runner._run(() => runner._fromReadableStream(stream));
|
||||
return runner;
|
||||
}
|
||||
static createMessage(messages, params, options, { logger } = {}) {
|
||||
const runner = new BetaMessageStream(params, { logger });
|
||||
for (const message of params.messages) {
|
||||
runner._addMessageParam(message);
|
||||
}
|
||||
__classPrivateFieldSet(runner, _BetaMessageStream_params, { ...params, stream: true }, "f");
|
||||
runner._run(() => runner._createMessage(messages, { ...params, stream: true }, { ...options, headers: { ...options?.headers, 'X-Stainless-Helper-Method': 'stream' } }));
|
||||
return runner;
|
||||
}
|
||||
_run(executor) {
|
||||
executor().then(() => {
|
||||
this._emitFinal();
|
||||
this._emit('end');
|
||||
}, __classPrivateFieldGet(this, _BetaMessageStream_handleError, "f"));
|
||||
}
|
||||
_addMessageParam(message) {
|
||||
this.messages.push(message);
|
||||
}
|
||||
_addMessage(message, emit = true) {
|
||||
this.receivedMessages.push(message);
|
||||
if (emit) {
|
||||
this._emit('message', message);
|
||||
}
|
||||
}
|
||||
async _createMessage(messages, params, options) {
|
||||
const signal = options?.signal;
|
||||
let abortHandler;
|
||||
if (signal) {
|
||||
if (signal.aborted)
|
||||
this.controller.abort();
|
||||
abortHandler = this.controller.abort.bind(this.controller);
|
||||
signal.addEventListener('abort', abortHandler);
|
||||
}
|
||||
try {
|
||||
__classPrivateFieldGet(this, _BetaMessageStream_instances, "m", _BetaMessageStream_beginRequest).call(this);
|
||||
const { response, data: stream } = await messages
|
||||
.create({ ...params, stream: true }, { ...options, signal: this.controller.signal })
|
||||
.withResponse();
|
||||
this._connected(response);
|
||||
for await (const event of stream) {
|
||||
__classPrivateFieldGet(this, _BetaMessageStream_instances, "m", _BetaMessageStream_addStreamEvent).call(this, event);
|
||||
}
|
||||
if (stream.controller.signal?.aborted) {
|
||||
throw new APIUserAbortError();
|
||||
}
|
||||
__classPrivateFieldGet(this, _BetaMessageStream_instances, "m", _BetaMessageStream_endRequest).call(this);
|
||||
}
|
||||
finally {
|
||||
if (signal && abortHandler) {
|
||||
signal.removeEventListener('abort', abortHandler);
|
||||
}
|
||||
}
|
||||
}
|
||||
_connected(response) {
|
||||
if (this.ended)
|
||||
return;
|
||||
__classPrivateFieldSet(this, _BetaMessageStream_response, response, "f");
|
||||
__classPrivateFieldSet(this, _BetaMessageStream_request_id, response?.headers.get('request-id'), "f");
|
||||
__classPrivateFieldGet(this, _BetaMessageStream_resolveConnectedPromise, "f").call(this, response);
|
||||
this._emit('connect');
|
||||
}
|
||||
get ended() {
|
||||
return __classPrivateFieldGet(this, _BetaMessageStream_ended, "f");
|
||||
}
|
||||
get errored() {
|
||||
return __classPrivateFieldGet(this, _BetaMessageStream_errored, "f");
|
||||
}
|
||||
get aborted() {
|
||||
return __classPrivateFieldGet(this, _BetaMessageStream_aborted, "f");
|
||||
}
|
||||
abort() {
|
||||
this.controller.abort();
|
||||
}
|
||||
/**
|
||||
* Adds the listener function to the end of the listeners array for the event.
|
||||
* No checks are made to see if the listener has already been added. Multiple calls passing
|
||||
* the same combination of event and listener will result in the listener being added, and
|
||||
* called, multiple times.
|
||||
* @returns this MessageStream, so that calls can be chained
|
||||
*/
|
||||
on(event, listener) {
|
||||
const listeners = __classPrivateFieldGet(this, _BetaMessageStream_listeners, "f")[event] || (__classPrivateFieldGet(this, _BetaMessageStream_listeners, "f")[event] = []);
|
||||
listeners.push({ listener });
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Removes the specified listener from the listener array for the event.
|
||||
* off() will remove, at most, one instance of a listener from the listener array. If any single
|
||||
* listener has been added multiple times to the listener array for the specified event, then
|
||||
* off() must be called multiple times to remove each instance.
|
||||
* @returns this MessageStream, so that calls can be chained
|
||||
*/
|
||||
off(event, listener) {
|
||||
const listeners = __classPrivateFieldGet(this, _BetaMessageStream_listeners, "f")[event];
|
||||
if (!listeners)
|
||||
return this;
|
||||
const index = listeners.findIndex((l) => l.listener === listener);
|
||||
if (index >= 0)
|
||||
listeners.splice(index, 1);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Adds a one-time listener function for the event. The next time the event is triggered,
|
||||
* this listener is removed and then invoked.
|
||||
* @returns this MessageStream, so that calls can be chained
|
||||
*/
|
||||
once(event, listener) {
|
||||
const listeners = __classPrivateFieldGet(this, _BetaMessageStream_listeners, "f")[event] || (__classPrivateFieldGet(this, _BetaMessageStream_listeners, "f")[event] = []);
|
||||
listeners.push({ listener, once: true });
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* This is similar to `.once()`, but returns a Promise that resolves the next time
|
||||
* the event is triggered, instead of calling a listener callback.
|
||||
* @returns a Promise that resolves the next time given event is triggered,
|
||||
* or rejects if an error is emitted. (If you request the 'error' event,
|
||||
* returns a promise that resolves with the error).
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* const message = await stream.emitted('message') // rejects if the stream errors
|
||||
*/
|
||||
emitted(event) {
|
||||
return new Promise((resolve, reject) => {
|
||||
__classPrivateFieldSet(this, _BetaMessageStream_catchingPromiseCreated, true, "f");
|
||||
if (event !== 'error')
|
||||
this.once('error', reject);
|
||||
this.once(event, resolve);
|
||||
});
|
||||
}
|
||||
async done() {
|
||||
__classPrivateFieldSet(this, _BetaMessageStream_catchingPromiseCreated, true, "f");
|
||||
await __classPrivateFieldGet(this, _BetaMessageStream_endPromise, "f");
|
||||
}
|
||||
get currentMessage() {
|
||||
return __classPrivateFieldGet(this, _BetaMessageStream_currentMessageSnapshot, "f");
|
||||
}
|
||||
/**
|
||||
* @returns a promise that resolves with the the final assistant Message response,
|
||||
* or rejects if an error occurred or the stream ended prematurely without producing a Message.
|
||||
* If structured outputs were used, this will be a ParsedMessage with a `parsed` field.
|
||||
*/
|
||||
async finalMessage() {
|
||||
await this.done();
|
||||
return __classPrivateFieldGet(this, _BetaMessageStream_instances, "m", _BetaMessageStream_getFinalMessage).call(this);
|
||||
}
|
||||
/**
|
||||
* @returns a promise that resolves with the the final assistant Message's text response, concatenated
|
||||
* together if there are more than one text blocks.
|
||||
* Rejects if an error occurred or the stream ended prematurely without producing a Message.
|
||||
*/
|
||||
async finalText() {
|
||||
await this.done();
|
||||
return __classPrivateFieldGet(this, _BetaMessageStream_instances, "m", _BetaMessageStream_getFinalText).call(this);
|
||||
}
|
||||
_emit(event, ...args) {
|
||||
// make sure we don't emit any MessageStreamEvents after end
|
||||
if (__classPrivateFieldGet(this, _BetaMessageStream_ended, "f"))
|
||||
return;
|
||||
if (event === 'end') {
|
||||
__classPrivateFieldSet(this, _BetaMessageStream_ended, true, "f");
|
||||
__classPrivateFieldGet(this, _BetaMessageStream_resolveEndPromise, "f").call(this);
|
||||
}
|
||||
const listeners = __classPrivateFieldGet(this, _BetaMessageStream_listeners, "f")[event];
|
||||
if (listeners) {
|
||||
__classPrivateFieldGet(this, _BetaMessageStream_listeners, "f")[event] = listeners.filter((l) => !l.once);
|
||||
listeners.forEach(({ listener }) => listener(...args));
|
||||
}
|
||||
if (event === 'abort') {
|
||||
const error = args[0];
|
||||
if (!__classPrivateFieldGet(this, _BetaMessageStream_catchingPromiseCreated, "f") && !listeners?.length) {
|
||||
Promise.reject(error);
|
||||
}
|
||||
__classPrivateFieldGet(this, _BetaMessageStream_rejectConnectedPromise, "f").call(this, error);
|
||||
__classPrivateFieldGet(this, _BetaMessageStream_rejectEndPromise, "f").call(this, error);
|
||||
this._emit('end');
|
||||
return;
|
||||
}
|
||||
if (event === 'error') {
|
||||
// NOTE: _emit('error', error) should only be called from #handleError().
|
||||
const error = args[0];
|
||||
if (!__classPrivateFieldGet(this, _BetaMessageStream_catchingPromiseCreated, "f") && !listeners?.length) {
|
||||
// Trigger an unhandled rejection if the user hasn't registered any error handlers.
|
||||
// If you are seeing stack traces here, make sure to handle errors via either:
|
||||
// - runner.on('error', () => ...)
|
||||
// - await runner.done()
|
||||
// - await runner.final...()
|
||||
// - etc.
|
||||
Promise.reject(error);
|
||||
}
|
||||
__classPrivateFieldGet(this, _BetaMessageStream_rejectConnectedPromise, "f").call(this, error);
|
||||
__classPrivateFieldGet(this, _BetaMessageStream_rejectEndPromise, "f").call(this, error);
|
||||
this._emit('end');
|
||||
}
|
||||
}
|
||||
_emitFinal() {
|
||||
const finalMessage = this.receivedMessages.at(-1);
|
||||
if (finalMessage) {
|
||||
this._emit('finalMessage', __classPrivateFieldGet(this, _BetaMessageStream_instances, "m", _BetaMessageStream_getFinalMessage).call(this));
|
||||
}
|
||||
}
|
||||
async _fromReadableStream(readableStream, options) {
|
||||
const signal = options?.signal;
|
||||
let abortHandler;
|
||||
if (signal) {
|
||||
if (signal.aborted)
|
||||
this.controller.abort();
|
||||
abortHandler = this.controller.abort.bind(this.controller);
|
||||
signal.addEventListener('abort', abortHandler);
|
||||
}
|
||||
try {
|
||||
__classPrivateFieldGet(this, _BetaMessageStream_instances, "m", _BetaMessageStream_beginRequest).call(this);
|
||||
this._connected(null);
|
||||
const stream = Stream.fromReadableStream(readableStream, this.controller);
|
||||
for await (const event of stream) {
|
||||
__classPrivateFieldGet(this, _BetaMessageStream_instances, "m", _BetaMessageStream_addStreamEvent).call(this, event);
|
||||
}
|
||||
if (stream.controller.signal?.aborted) {
|
||||
throw new APIUserAbortError();
|
||||
}
|
||||
__classPrivateFieldGet(this, _BetaMessageStream_instances, "m", _BetaMessageStream_endRequest).call(this);
|
||||
}
|
||||
finally {
|
||||
if (signal && abortHandler) {
|
||||
signal.removeEventListener('abort', abortHandler);
|
||||
}
|
||||
}
|
||||
}
|
||||
[(_BetaMessageStream_currentMessageSnapshot = new WeakMap(), _BetaMessageStream_params = new WeakMap(), _BetaMessageStream_connectedPromise = new WeakMap(), _BetaMessageStream_resolveConnectedPromise = new WeakMap(), _BetaMessageStream_rejectConnectedPromise = new WeakMap(), _BetaMessageStream_endPromise = new WeakMap(), _BetaMessageStream_resolveEndPromise = new WeakMap(), _BetaMessageStream_rejectEndPromise = new WeakMap(), _BetaMessageStream_listeners = new WeakMap(), _BetaMessageStream_ended = new WeakMap(), _BetaMessageStream_errored = new WeakMap(), _BetaMessageStream_aborted = new WeakMap(), _BetaMessageStream_catchingPromiseCreated = new WeakMap(), _BetaMessageStream_response = new WeakMap(), _BetaMessageStream_request_id = new WeakMap(), _BetaMessageStream_logger = new WeakMap(), _BetaMessageStream_handleError = new WeakMap(), _BetaMessageStream_instances = new WeakSet(), _BetaMessageStream_getFinalMessage = function _BetaMessageStream_getFinalMessage() {
|
||||
if (this.receivedMessages.length === 0) {
|
||||
throw new AnthropicError('stream ended without producing a Message with role=assistant');
|
||||
}
|
||||
return this.receivedMessages.at(-1);
|
||||
}, _BetaMessageStream_getFinalText = function _BetaMessageStream_getFinalText() {
|
||||
if (this.receivedMessages.length === 0) {
|
||||
throw new AnthropicError('stream ended without producing a Message with role=assistant');
|
||||
}
|
||||
const textBlocks = this.receivedMessages
|
||||
.at(-1)
|
||||
.content.filter((block) => block.type === 'text')
|
||||
.map((block) => block.text);
|
||||
if (textBlocks.length === 0) {
|
||||
throw new AnthropicError('stream ended without producing a content block with type=text');
|
||||
}
|
||||
return textBlocks.join(' ');
|
||||
}, _BetaMessageStream_beginRequest = function _BetaMessageStream_beginRequest() {
|
||||
if (this.ended)
|
||||
return;
|
||||
__classPrivateFieldSet(this, _BetaMessageStream_currentMessageSnapshot, undefined, "f");
|
||||
}, _BetaMessageStream_addStreamEvent = function _BetaMessageStream_addStreamEvent(event) {
|
||||
if (this.ended)
|
||||
return;
|
||||
const messageSnapshot = __classPrivateFieldGet(this, _BetaMessageStream_instances, "m", _BetaMessageStream_accumulateMessage).call(this, event);
|
||||
this._emit('streamEvent', event, messageSnapshot);
|
||||
switch (event.type) {
|
||||
case 'content_block_delta': {
|
||||
const content = messageSnapshot.content.at(-1);
|
||||
switch (event.delta.type) {
|
||||
case 'text_delta': {
|
||||
if (content.type === 'text') {
|
||||
this._emit('text', event.delta.text, content.text || '');
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'citations_delta': {
|
||||
if (content.type === 'text') {
|
||||
this._emit('citation', event.delta.citation, content.citations ?? []);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'input_json_delta': {
|
||||
if (tracksToolInput(content) && content.input) {
|
||||
this._emit('inputJson', event.delta.partial_json, content.input);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'thinking_delta': {
|
||||
if (content.type === 'thinking') {
|
||||
this._emit('thinking', event.delta.thinking, content.thinking);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'signature_delta': {
|
||||
if (content.type === 'thinking') {
|
||||
this._emit('signature', content.signature);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'compaction_delta': {
|
||||
if (content.type === 'compaction' && content.content) {
|
||||
this._emit('compaction', content.content);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
checkNever(event.delta);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'message_stop': {
|
||||
this._addMessageParam(messageSnapshot);
|
||||
this._addMessage(maybeParseBetaMessage(messageSnapshot, __classPrivateFieldGet(this, _BetaMessageStream_params, "f"), { logger: __classPrivateFieldGet(this, _BetaMessageStream_logger, "f") }), true);
|
||||
break;
|
||||
}
|
||||
case 'content_block_stop': {
|
||||
this._emit('contentBlock', messageSnapshot.content.at(-1));
|
||||
break;
|
||||
}
|
||||
case 'message_start': {
|
||||
__classPrivateFieldSet(this, _BetaMessageStream_currentMessageSnapshot, messageSnapshot, "f");
|
||||
break;
|
||||
}
|
||||
case 'content_block_start':
|
||||
case 'message_delta':
|
||||
break;
|
||||
}
|
||||
}, _BetaMessageStream_endRequest = function _BetaMessageStream_endRequest() {
|
||||
if (this.ended) {
|
||||
throw new AnthropicError(`stream has ended, this shouldn't happen`);
|
||||
}
|
||||
const snapshot = __classPrivateFieldGet(this, _BetaMessageStream_currentMessageSnapshot, "f");
|
||||
if (!snapshot) {
|
||||
throw new AnthropicError(`request ended without sending any chunks`);
|
||||
}
|
||||
__classPrivateFieldSet(this, _BetaMessageStream_currentMessageSnapshot, undefined, "f");
|
||||
return maybeParseBetaMessage(snapshot, __classPrivateFieldGet(this, _BetaMessageStream_params, "f"), { logger: __classPrivateFieldGet(this, _BetaMessageStream_logger, "f") });
|
||||
}, _BetaMessageStream_accumulateMessage = function _BetaMessageStream_accumulateMessage(event) {
|
||||
let snapshot = __classPrivateFieldGet(this, _BetaMessageStream_currentMessageSnapshot, "f");
|
||||
if (event.type === 'message_start') {
|
||||
if (snapshot) {
|
||||
throw new AnthropicError(`Unexpected event order, got ${event.type} before receiving "message_stop"`);
|
||||
}
|
||||
return event.message;
|
||||
}
|
||||
if (!snapshot) {
|
||||
throw new AnthropicError(`Unexpected event order, got ${event.type} before "message_start"`);
|
||||
}
|
||||
switch (event.type) {
|
||||
case 'message_stop':
|
||||
return snapshot;
|
||||
case 'message_delta':
|
||||
snapshot.container = event.delta.container;
|
||||
snapshot.stop_reason = event.delta.stop_reason;
|
||||
snapshot.stop_sequence = event.delta.stop_sequence;
|
||||
snapshot.usage.output_tokens = event.usage.output_tokens;
|
||||
snapshot.context_management = event.context_management;
|
||||
if (event.usage.input_tokens != null) {
|
||||
snapshot.usage.input_tokens = event.usage.input_tokens;
|
||||
}
|
||||
if (event.usage.cache_creation_input_tokens != null) {
|
||||
snapshot.usage.cache_creation_input_tokens = event.usage.cache_creation_input_tokens;
|
||||
}
|
||||
if (event.usage.cache_read_input_tokens != null) {
|
||||
snapshot.usage.cache_read_input_tokens = event.usage.cache_read_input_tokens;
|
||||
}
|
||||
if (event.usage.server_tool_use != null) {
|
||||
snapshot.usage.server_tool_use = event.usage.server_tool_use;
|
||||
}
|
||||
if (event.usage.iterations != null) {
|
||||
snapshot.usage.iterations = event.usage.iterations;
|
||||
}
|
||||
return snapshot;
|
||||
case 'content_block_start':
|
||||
snapshot.content.push(event.content_block);
|
||||
return snapshot;
|
||||
case 'content_block_delta': {
|
||||
const snapshotContent = snapshot.content.at(event.index);
|
||||
switch (event.delta.type) {
|
||||
case 'text_delta': {
|
||||
if (snapshotContent?.type === 'text') {
|
||||
snapshot.content[event.index] = {
|
||||
...snapshotContent,
|
||||
text: (snapshotContent.text || '') + event.delta.text,
|
||||
};
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'citations_delta': {
|
||||
if (snapshotContent?.type === 'text') {
|
||||
snapshot.content[event.index] = {
|
||||
...snapshotContent,
|
||||
citations: [...(snapshotContent.citations ?? []), event.delta.citation],
|
||||
};
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'input_json_delta': {
|
||||
if (snapshotContent && tracksToolInput(snapshotContent)) {
|
||||
// we need to keep track of the raw JSON string as well so that we can
|
||||
// re-parse it for each delta, for now we just store it as an untyped
|
||||
// non-enumerable property on the snapshot
|
||||
let jsonBuf = snapshotContent[JSON_BUF_PROPERTY] || '';
|
||||
jsonBuf += event.delta.partial_json;
|
||||
const newContent = { ...snapshotContent };
|
||||
Object.defineProperty(newContent, JSON_BUF_PROPERTY, {
|
||||
value: jsonBuf,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
});
|
||||
if (jsonBuf) {
|
||||
try {
|
||||
newContent.input = partialParse(jsonBuf);
|
||||
}
|
||||
catch (err) {
|
||||
const error = new AnthropicError(`Unable to parse tool parameter JSON from model. Please retry your request or adjust your prompt. Error: ${err}. JSON: ${jsonBuf}`);
|
||||
__classPrivateFieldGet(this, _BetaMessageStream_handleError, "f").call(this, error);
|
||||
}
|
||||
}
|
||||
snapshot.content[event.index] = newContent;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'thinking_delta': {
|
||||
if (snapshotContent?.type === 'thinking') {
|
||||
snapshot.content[event.index] = {
|
||||
...snapshotContent,
|
||||
thinking: snapshotContent.thinking + event.delta.thinking,
|
||||
};
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'signature_delta': {
|
||||
if (snapshotContent?.type === 'thinking') {
|
||||
snapshot.content[event.index] = {
|
||||
...snapshotContent,
|
||||
signature: event.delta.signature,
|
||||
};
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'compaction_delta': {
|
||||
if (snapshotContent?.type === 'compaction') {
|
||||
snapshot.content[event.index] = {
|
||||
...snapshotContent,
|
||||
content: (snapshotContent.content || '') + event.delta.content,
|
||||
};
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
checkNever(event.delta);
|
||||
}
|
||||
return snapshot;
|
||||
}
|
||||
case 'content_block_stop':
|
||||
return snapshot;
|
||||
}
|
||||
}, Symbol.asyncIterator)]() {
|
||||
const pushQueue = [];
|
||||
const readQueue = [];
|
||||
let done = false;
|
||||
this.on('streamEvent', (event) => {
|
||||
const reader = readQueue.shift();
|
||||
if (reader) {
|
||||
reader.resolve(event);
|
||||
}
|
||||
else {
|
||||
pushQueue.push(event);
|
||||
}
|
||||
});
|
||||
this.on('end', () => {
|
||||
done = true;
|
||||
for (const reader of readQueue) {
|
||||
reader.resolve(undefined);
|
||||
}
|
||||
readQueue.length = 0;
|
||||
});
|
||||
this.on('abort', (err) => {
|
||||
done = true;
|
||||
for (const reader of readQueue) {
|
||||
reader.reject(err);
|
||||
}
|
||||
readQueue.length = 0;
|
||||
});
|
||||
this.on('error', (err) => {
|
||||
done = true;
|
||||
for (const reader of readQueue) {
|
||||
reader.reject(err);
|
||||
}
|
||||
readQueue.length = 0;
|
||||
});
|
||||
return {
|
||||
next: async () => {
|
||||
if (!pushQueue.length) {
|
||||
if (done) {
|
||||
return { value: undefined, done: true };
|
||||
}
|
||||
return new Promise((resolve, reject) => readQueue.push({ resolve, reject })).then((chunk) => (chunk ? { value: chunk, done: false } : { value: undefined, done: true }));
|
||||
}
|
||||
const chunk = pushQueue.shift();
|
||||
return { value: chunk, done: false };
|
||||
},
|
||||
return: async () => {
|
||||
this.abort();
|
||||
return { value: undefined, done: true };
|
||||
},
|
||||
};
|
||||
}
|
||||
toReadableStream() {
|
||||
const stream = new Stream(this[Symbol.asyncIterator].bind(this), this.controller);
|
||||
return stream.toReadableStream();
|
||||
}
|
||||
}
|
||||
// used to ensure exhaustive case matching without throwing a runtime error
|
||||
function checkNever(x) { }
|
||||
//# sourceMappingURL=BetaMessageStream.mjs.map
|
||||
591
extracted-source/node_modules/@anthropic-ai/sdk/lib/MessageStream.mjs
generated
vendored
Normal file
591
extracted-source/node_modules/@anthropic-ai/sdk/lib/MessageStream.mjs
generated
vendored
Normal file
@@ -0,0 +1,591 @@
|
||||
var _MessageStream_instances, _MessageStream_currentMessageSnapshot, _MessageStream_params, _MessageStream_connectedPromise, _MessageStream_resolveConnectedPromise, _MessageStream_rejectConnectedPromise, _MessageStream_endPromise, _MessageStream_resolveEndPromise, _MessageStream_rejectEndPromise, _MessageStream_listeners, _MessageStream_ended, _MessageStream_errored, _MessageStream_aborted, _MessageStream_catchingPromiseCreated, _MessageStream_response, _MessageStream_request_id, _MessageStream_logger, _MessageStream_getFinalMessage, _MessageStream_getFinalText, _MessageStream_handleError, _MessageStream_beginRequest, _MessageStream_addStreamEvent, _MessageStream_endRequest, _MessageStream_accumulateMessage;
|
||||
import { __classPrivateFieldGet, __classPrivateFieldSet } from "../internal/tslib.mjs";
|
||||
import { isAbortError } from "../internal/errors.mjs";
|
||||
import { AnthropicError, APIUserAbortError } from "../error.mjs";
|
||||
import { Stream } from "../streaming.mjs";
|
||||
import { partialParse } from "../_vendor/partial-json-parser/parser.mjs";
|
||||
import { maybeParseMessage } from "./parser.mjs";
|
||||
const JSON_BUF_PROPERTY = '__json_buf';
|
||||
function tracksToolInput(content) {
|
||||
return content.type === 'tool_use' || content.type === 'server_tool_use';
|
||||
}
|
||||
export class MessageStream {
|
||||
constructor(params, opts) {
|
||||
_MessageStream_instances.add(this);
|
||||
this.messages = [];
|
||||
this.receivedMessages = [];
|
||||
_MessageStream_currentMessageSnapshot.set(this, void 0);
|
||||
_MessageStream_params.set(this, null);
|
||||
this.controller = new AbortController();
|
||||
_MessageStream_connectedPromise.set(this, void 0);
|
||||
_MessageStream_resolveConnectedPromise.set(this, () => { });
|
||||
_MessageStream_rejectConnectedPromise.set(this, () => { });
|
||||
_MessageStream_endPromise.set(this, void 0);
|
||||
_MessageStream_resolveEndPromise.set(this, () => { });
|
||||
_MessageStream_rejectEndPromise.set(this, () => { });
|
||||
_MessageStream_listeners.set(this, {});
|
||||
_MessageStream_ended.set(this, false);
|
||||
_MessageStream_errored.set(this, false);
|
||||
_MessageStream_aborted.set(this, false);
|
||||
_MessageStream_catchingPromiseCreated.set(this, false);
|
||||
_MessageStream_response.set(this, void 0);
|
||||
_MessageStream_request_id.set(this, void 0);
|
||||
_MessageStream_logger.set(this, void 0);
|
||||
_MessageStream_handleError.set(this, (error) => {
|
||||
__classPrivateFieldSet(this, _MessageStream_errored, true, "f");
|
||||
if (isAbortError(error)) {
|
||||
error = new APIUserAbortError();
|
||||
}
|
||||
if (error instanceof APIUserAbortError) {
|
||||
__classPrivateFieldSet(this, _MessageStream_aborted, true, "f");
|
||||
return this._emit('abort', error);
|
||||
}
|
||||
if (error instanceof AnthropicError) {
|
||||
return this._emit('error', error);
|
||||
}
|
||||
if (error instanceof Error) {
|
||||
const anthropicError = new AnthropicError(error.message);
|
||||
// @ts-ignore
|
||||
anthropicError.cause = error;
|
||||
return this._emit('error', anthropicError);
|
||||
}
|
||||
return this._emit('error', new AnthropicError(String(error)));
|
||||
});
|
||||
__classPrivateFieldSet(this, _MessageStream_connectedPromise, new Promise((resolve, reject) => {
|
||||
__classPrivateFieldSet(this, _MessageStream_resolveConnectedPromise, resolve, "f");
|
||||
__classPrivateFieldSet(this, _MessageStream_rejectConnectedPromise, reject, "f");
|
||||
}), "f");
|
||||
__classPrivateFieldSet(this, _MessageStream_endPromise, new Promise((resolve, reject) => {
|
||||
__classPrivateFieldSet(this, _MessageStream_resolveEndPromise, resolve, "f");
|
||||
__classPrivateFieldSet(this, _MessageStream_rejectEndPromise, reject, "f");
|
||||
}), "f");
|
||||
// Don't let these promises cause unhandled rejection errors.
|
||||
// we will manually cause an unhandled rejection error later
|
||||
// if the user hasn't registered any error listener or called
|
||||
// any promise-returning method.
|
||||
__classPrivateFieldGet(this, _MessageStream_connectedPromise, "f").catch(() => { });
|
||||
__classPrivateFieldGet(this, _MessageStream_endPromise, "f").catch(() => { });
|
||||
__classPrivateFieldSet(this, _MessageStream_params, params, "f");
|
||||
__classPrivateFieldSet(this, _MessageStream_logger, opts?.logger ?? console, "f");
|
||||
}
|
||||
get response() {
|
||||
return __classPrivateFieldGet(this, _MessageStream_response, "f");
|
||||
}
|
||||
get request_id() {
|
||||
return __classPrivateFieldGet(this, _MessageStream_request_id, "f");
|
||||
}
|
||||
/**
|
||||
* Returns the `MessageStream` data, the raw `Response` instance and the ID of the request,
|
||||
* returned vie the `request-id` header which is useful for debugging requests and resporting
|
||||
* issues to Anthropic.
|
||||
*
|
||||
* This is the same as the `APIPromise.withResponse()` method.
|
||||
*
|
||||
* This method will raise an error if you created the stream using `MessageStream.fromReadableStream`
|
||||
* as no `Response` is available.
|
||||
*/
|
||||
async withResponse() {
|
||||
__classPrivateFieldSet(this, _MessageStream_catchingPromiseCreated, true, "f");
|
||||
const response = await __classPrivateFieldGet(this, _MessageStream_connectedPromise, "f");
|
||||
if (!response) {
|
||||
throw new Error('Could not resolve a `Response` object');
|
||||
}
|
||||
return {
|
||||
data: this,
|
||||
response,
|
||||
request_id: response.headers.get('request-id'),
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Intended for use on the frontend, consuming a stream produced with
|
||||
* `.toReadableStream()` on the backend.
|
||||
*
|
||||
* Note that messages sent to the model do not appear in `.on('message')`
|
||||
* in this context.
|
||||
*/
|
||||
static fromReadableStream(stream) {
|
||||
const runner = new MessageStream(null);
|
||||
runner._run(() => runner._fromReadableStream(stream));
|
||||
return runner;
|
||||
}
|
||||
static createMessage(messages, params, options, { logger } = {}) {
|
||||
const runner = new MessageStream(params, { logger });
|
||||
for (const message of params.messages) {
|
||||
runner._addMessageParam(message);
|
||||
}
|
||||
__classPrivateFieldSet(runner, _MessageStream_params, { ...params, stream: true }, "f");
|
||||
runner._run(() => runner._createMessage(messages, { ...params, stream: true }, { ...options, headers: { ...options?.headers, 'X-Stainless-Helper-Method': 'stream' } }));
|
||||
return runner;
|
||||
}
|
||||
_run(executor) {
|
||||
executor().then(() => {
|
||||
this._emitFinal();
|
||||
this._emit('end');
|
||||
}, __classPrivateFieldGet(this, _MessageStream_handleError, "f"));
|
||||
}
|
||||
_addMessageParam(message) {
|
||||
this.messages.push(message);
|
||||
}
|
||||
_addMessage(message, emit = true) {
|
||||
this.receivedMessages.push(message);
|
||||
if (emit) {
|
||||
this._emit('message', message);
|
||||
}
|
||||
}
|
||||
async _createMessage(messages, params, options) {
|
||||
const signal = options?.signal;
|
||||
let abortHandler;
|
||||
if (signal) {
|
||||
if (signal.aborted)
|
||||
this.controller.abort();
|
||||
abortHandler = this.controller.abort.bind(this.controller);
|
||||
signal.addEventListener('abort', abortHandler);
|
||||
}
|
||||
try {
|
||||
__classPrivateFieldGet(this, _MessageStream_instances, "m", _MessageStream_beginRequest).call(this);
|
||||
const { response, data: stream } = await messages
|
||||
.create({ ...params, stream: true }, { ...options, signal: this.controller.signal })
|
||||
.withResponse();
|
||||
this._connected(response);
|
||||
for await (const event of stream) {
|
||||
__classPrivateFieldGet(this, _MessageStream_instances, "m", _MessageStream_addStreamEvent).call(this, event);
|
||||
}
|
||||
if (stream.controller.signal?.aborted) {
|
||||
throw new APIUserAbortError();
|
||||
}
|
||||
__classPrivateFieldGet(this, _MessageStream_instances, "m", _MessageStream_endRequest).call(this);
|
||||
}
|
||||
finally {
|
||||
if (signal && abortHandler) {
|
||||
signal.removeEventListener('abort', abortHandler);
|
||||
}
|
||||
}
|
||||
}
|
||||
_connected(response) {
|
||||
if (this.ended)
|
||||
return;
|
||||
__classPrivateFieldSet(this, _MessageStream_response, response, "f");
|
||||
__classPrivateFieldSet(this, _MessageStream_request_id, response?.headers.get('request-id'), "f");
|
||||
__classPrivateFieldGet(this, _MessageStream_resolveConnectedPromise, "f").call(this, response);
|
||||
this._emit('connect');
|
||||
}
|
||||
get ended() {
|
||||
return __classPrivateFieldGet(this, _MessageStream_ended, "f");
|
||||
}
|
||||
get errored() {
|
||||
return __classPrivateFieldGet(this, _MessageStream_errored, "f");
|
||||
}
|
||||
get aborted() {
|
||||
return __classPrivateFieldGet(this, _MessageStream_aborted, "f");
|
||||
}
|
||||
abort() {
|
||||
this.controller.abort();
|
||||
}
|
||||
/**
|
||||
* Adds the listener function to the end of the listeners array for the event.
|
||||
* No checks are made to see if the listener has already been added. Multiple calls passing
|
||||
* the same combination of event and listener will result in the listener being added, and
|
||||
* called, multiple times.
|
||||
* @returns this MessageStream, so that calls can be chained
|
||||
*/
|
||||
on(event, listener) {
|
||||
const listeners = __classPrivateFieldGet(this, _MessageStream_listeners, "f")[event] || (__classPrivateFieldGet(this, _MessageStream_listeners, "f")[event] = []);
|
||||
listeners.push({ listener });
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Removes the specified listener from the listener array for the event.
|
||||
* off() will remove, at most, one instance of a listener from the listener array. If any single
|
||||
* listener has been added multiple times to the listener array for the specified event, then
|
||||
* off() must be called multiple times to remove each instance.
|
||||
* @returns this MessageStream, so that calls can be chained
|
||||
*/
|
||||
off(event, listener) {
|
||||
const listeners = __classPrivateFieldGet(this, _MessageStream_listeners, "f")[event];
|
||||
if (!listeners)
|
||||
return this;
|
||||
const index = listeners.findIndex((l) => l.listener === listener);
|
||||
if (index >= 0)
|
||||
listeners.splice(index, 1);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Adds a one-time listener function for the event. The next time the event is triggered,
|
||||
* this listener is removed and then invoked.
|
||||
* @returns this MessageStream, so that calls can be chained
|
||||
*/
|
||||
once(event, listener) {
|
||||
const listeners = __classPrivateFieldGet(this, _MessageStream_listeners, "f")[event] || (__classPrivateFieldGet(this, _MessageStream_listeners, "f")[event] = []);
|
||||
listeners.push({ listener, once: true });
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* This is similar to `.once()`, but returns a Promise that resolves the next time
|
||||
* the event is triggered, instead of calling a listener callback.
|
||||
* @returns a Promise that resolves the next time given event is triggered,
|
||||
* or rejects if an error is emitted. (If you request the 'error' event,
|
||||
* returns a promise that resolves with the error).
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* const message = await stream.emitted('message') // rejects if the stream errors
|
||||
*/
|
||||
emitted(event) {
|
||||
return new Promise((resolve, reject) => {
|
||||
__classPrivateFieldSet(this, _MessageStream_catchingPromiseCreated, true, "f");
|
||||
if (event !== 'error')
|
||||
this.once('error', reject);
|
||||
this.once(event, resolve);
|
||||
});
|
||||
}
|
||||
async done() {
|
||||
__classPrivateFieldSet(this, _MessageStream_catchingPromiseCreated, true, "f");
|
||||
await __classPrivateFieldGet(this, _MessageStream_endPromise, "f");
|
||||
}
|
||||
get currentMessage() {
|
||||
return __classPrivateFieldGet(this, _MessageStream_currentMessageSnapshot, "f");
|
||||
}
|
||||
/**
|
||||
* @returns a promise that resolves with the the final assistant Message response,
|
||||
* or rejects if an error occurred or the stream ended prematurely without producing a Message.
|
||||
* If structured outputs were used, this will be a ParsedMessage with a `parsed_output` field.
|
||||
*/
|
||||
async finalMessage() {
|
||||
await this.done();
|
||||
return __classPrivateFieldGet(this, _MessageStream_instances, "m", _MessageStream_getFinalMessage).call(this);
|
||||
}
|
||||
/**
|
||||
* @returns a promise that resolves with the the final assistant Message's text response, concatenated
|
||||
* together if there are more than one text blocks.
|
||||
* Rejects if an error occurred or the stream ended prematurely without producing a Message.
|
||||
*/
|
||||
async finalText() {
|
||||
await this.done();
|
||||
return __classPrivateFieldGet(this, _MessageStream_instances, "m", _MessageStream_getFinalText).call(this);
|
||||
}
|
||||
_emit(event, ...args) {
|
||||
// make sure we don't emit any MessageStreamEvents after end
|
||||
if (__classPrivateFieldGet(this, _MessageStream_ended, "f"))
|
||||
return;
|
||||
if (event === 'end') {
|
||||
__classPrivateFieldSet(this, _MessageStream_ended, true, "f");
|
||||
__classPrivateFieldGet(this, _MessageStream_resolveEndPromise, "f").call(this);
|
||||
}
|
||||
const listeners = __classPrivateFieldGet(this, _MessageStream_listeners, "f")[event];
|
||||
if (listeners) {
|
||||
__classPrivateFieldGet(this, _MessageStream_listeners, "f")[event] = listeners.filter((l) => !l.once);
|
||||
listeners.forEach(({ listener }) => listener(...args));
|
||||
}
|
||||
if (event === 'abort') {
|
||||
const error = args[0];
|
||||
if (!__classPrivateFieldGet(this, _MessageStream_catchingPromiseCreated, "f") && !listeners?.length) {
|
||||
Promise.reject(error);
|
||||
}
|
||||
__classPrivateFieldGet(this, _MessageStream_rejectConnectedPromise, "f").call(this, error);
|
||||
__classPrivateFieldGet(this, _MessageStream_rejectEndPromise, "f").call(this, error);
|
||||
this._emit('end');
|
||||
return;
|
||||
}
|
||||
if (event === 'error') {
|
||||
// NOTE: _emit('error', error) should only be called from #handleError().
|
||||
const error = args[0];
|
||||
if (!__classPrivateFieldGet(this, _MessageStream_catchingPromiseCreated, "f") && !listeners?.length) {
|
||||
// Trigger an unhandled rejection if the user hasn't registered any error handlers.
|
||||
// If you are seeing stack traces here, make sure to handle errors via either:
|
||||
// - runner.on('error', () => ...)
|
||||
// - await runner.done()
|
||||
// - await runner.final...()
|
||||
// - etc.
|
||||
Promise.reject(error);
|
||||
}
|
||||
__classPrivateFieldGet(this, _MessageStream_rejectConnectedPromise, "f").call(this, error);
|
||||
__classPrivateFieldGet(this, _MessageStream_rejectEndPromise, "f").call(this, error);
|
||||
this._emit('end');
|
||||
}
|
||||
}
|
||||
_emitFinal() {
|
||||
const finalMessage = this.receivedMessages.at(-1);
|
||||
if (finalMessage) {
|
||||
this._emit('finalMessage', __classPrivateFieldGet(this, _MessageStream_instances, "m", _MessageStream_getFinalMessage).call(this));
|
||||
}
|
||||
}
|
||||
async _fromReadableStream(readableStream, options) {
|
||||
const signal = options?.signal;
|
||||
let abortHandler;
|
||||
if (signal) {
|
||||
if (signal.aborted)
|
||||
this.controller.abort();
|
||||
abortHandler = this.controller.abort.bind(this.controller);
|
||||
signal.addEventListener('abort', abortHandler);
|
||||
}
|
||||
try {
|
||||
__classPrivateFieldGet(this, _MessageStream_instances, "m", _MessageStream_beginRequest).call(this);
|
||||
this._connected(null);
|
||||
const stream = Stream.fromReadableStream(readableStream, this.controller);
|
||||
for await (const event of stream) {
|
||||
__classPrivateFieldGet(this, _MessageStream_instances, "m", _MessageStream_addStreamEvent).call(this, event);
|
||||
}
|
||||
if (stream.controller.signal?.aborted) {
|
||||
throw new APIUserAbortError();
|
||||
}
|
||||
__classPrivateFieldGet(this, _MessageStream_instances, "m", _MessageStream_endRequest).call(this);
|
||||
}
|
||||
finally {
|
||||
if (signal && abortHandler) {
|
||||
signal.removeEventListener('abort', abortHandler);
|
||||
}
|
||||
}
|
||||
}
|
||||
[(_MessageStream_currentMessageSnapshot = new WeakMap(), _MessageStream_params = new WeakMap(), _MessageStream_connectedPromise = new WeakMap(), _MessageStream_resolveConnectedPromise = new WeakMap(), _MessageStream_rejectConnectedPromise = new WeakMap(), _MessageStream_endPromise = new WeakMap(), _MessageStream_resolveEndPromise = new WeakMap(), _MessageStream_rejectEndPromise = new WeakMap(), _MessageStream_listeners = new WeakMap(), _MessageStream_ended = new WeakMap(), _MessageStream_errored = new WeakMap(), _MessageStream_aborted = new WeakMap(), _MessageStream_catchingPromiseCreated = new WeakMap(), _MessageStream_response = new WeakMap(), _MessageStream_request_id = new WeakMap(), _MessageStream_logger = new WeakMap(), _MessageStream_handleError = new WeakMap(), _MessageStream_instances = new WeakSet(), _MessageStream_getFinalMessage = function _MessageStream_getFinalMessage() {
|
||||
if (this.receivedMessages.length === 0) {
|
||||
throw new AnthropicError('stream ended without producing a Message with role=assistant');
|
||||
}
|
||||
return this.receivedMessages.at(-1);
|
||||
}, _MessageStream_getFinalText = function _MessageStream_getFinalText() {
|
||||
if (this.receivedMessages.length === 0) {
|
||||
throw new AnthropicError('stream ended without producing a Message with role=assistant');
|
||||
}
|
||||
const textBlocks = this.receivedMessages
|
||||
.at(-1)
|
||||
.content.filter((block) => block.type === 'text')
|
||||
.map((block) => block.text);
|
||||
if (textBlocks.length === 0) {
|
||||
throw new AnthropicError('stream ended without producing a content block with type=text');
|
||||
}
|
||||
return textBlocks.join(' ');
|
||||
}, _MessageStream_beginRequest = function _MessageStream_beginRequest() {
|
||||
if (this.ended)
|
||||
return;
|
||||
__classPrivateFieldSet(this, _MessageStream_currentMessageSnapshot, undefined, "f");
|
||||
}, _MessageStream_addStreamEvent = function _MessageStream_addStreamEvent(event) {
|
||||
if (this.ended)
|
||||
return;
|
||||
const messageSnapshot = __classPrivateFieldGet(this, _MessageStream_instances, "m", _MessageStream_accumulateMessage).call(this, event);
|
||||
this._emit('streamEvent', event, messageSnapshot);
|
||||
switch (event.type) {
|
||||
case 'content_block_delta': {
|
||||
const content = messageSnapshot.content.at(-1);
|
||||
switch (event.delta.type) {
|
||||
case 'text_delta': {
|
||||
if (content.type === 'text') {
|
||||
this._emit('text', event.delta.text, content.text || '');
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'citations_delta': {
|
||||
if (content.type === 'text') {
|
||||
this._emit('citation', event.delta.citation, content.citations ?? []);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'input_json_delta': {
|
||||
if (tracksToolInput(content) && content.input) {
|
||||
this._emit('inputJson', event.delta.partial_json, content.input);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'thinking_delta': {
|
||||
if (content.type === 'thinking') {
|
||||
this._emit('thinking', event.delta.thinking, content.thinking);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'signature_delta': {
|
||||
if (content.type === 'thinking') {
|
||||
this._emit('signature', content.signature);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
checkNever(event.delta);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'message_stop': {
|
||||
this._addMessageParam(messageSnapshot);
|
||||
this._addMessage(maybeParseMessage(messageSnapshot, __classPrivateFieldGet(this, _MessageStream_params, "f"), { logger: __classPrivateFieldGet(this, _MessageStream_logger, "f") }), true);
|
||||
break;
|
||||
}
|
||||
case 'content_block_stop': {
|
||||
this._emit('contentBlock', messageSnapshot.content.at(-1));
|
||||
break;
|
||||
}
|
||||
case 'message_start': {
|
||||
__classPrivateFieldSet(this, _MessageStream_currentMessageSnapshot, messageSnapshot, "f");
|
||||
break;
|
||||
}
|
||||
case 'content_block_start':
|
||||
case 'message_delta':
|
||||
break;
|
||||
}
|
||||
}, _MessageStream_endRequest = function _MessageStream_endRequest() {
|
||||
if (this.ended) {
|
||||
throw new AnthropicError(`stream has ended, this shouldn't happen`);
|
||||
}
|
||||
const snapshot = __classPrivateFieldGet(this, _MessageStream_currentMessageSnapshot, "f");
|
||||
if (!snapshot) {
|
||||
throw new AnthropicError(`request ended without sending any chunks`);
|
||||
}
|
||||
__classPrivateFieldSet(this, _MessageStream_currentMessageSnapshot, undefined, "f");
|
||||
return maybeParseMessage(snapshot, __classPrivateFieldGet(this, _MessageStream_params, "f"), { logger: __classPrivateFieldGet(this, _MessageStream_logger, "f") });
|
||||
}, _MessageStream_accumulateMessage = function _MessageStream_accumulateMessage(event) {
|
||||
let snapshot = __classPrivateFieldGet(this, _MessageStream_currentMessageSnapshot, "f");
|
||||
if (event.type === 'message_start') {
|
||||
if (snapshot) {
|
||||
throw new AnthropicError(`Unexpected event order, got ${event.type} before receiving "message_stop"`);
|
||||
}
|
||||
return event.message;
|
||||
}
|
||||
if (!snapshot) {
|
||||
throw new AnthropicError(`Unexpected event order, got ${event.type} before "message_start"`);
|
||||
}
|
||||
switch (event.type) {
|
||||
case 'message_stop':
|
||||
return snapshot;
|
||||
case 'message_delta':
|
||||
snapshot.stop_reason = event.delta.stop_reason;
|
||||
snapshot.stop_sequence = event.delta.stop_sequence;
|
||||
snapshot.usage.output_tokens = event.usage.output_tokens;
|
||||
// Update other usage fields if they exist in the event
|
||||
if (event.usage.input_tokens != null) {
|
||||
snapshot.usage.input_tokens = event.usage.input_tokens;
|
||||
}
|
||||
if (event.usage.cache_creation_input_tokens != null) {
|
||||
snapshot.usage.cache_creation_input_tokens = event.usage.cache_creation_input_tokens;
|
||||
}
|
||||
if (event.usage.cache_read_input_tokens != null) {
|
||||
snapshot.usage.cache_read_input_tokens = event.usage.cache_read_input_tokens;
|
||||
}
|
||||
if (event.usage.server_tool_use != null) {
|
||||
snapshot.usage.server_tool_use = event.usage.server_tool_use;
|
||||
}
|
||||
return snapshot;
|
||||
case 'content_block_start':
|
||||
snapshot.content.push({ ...event.content_block });
|
||||
return snapshot;
|
||||
case 'content_block_delta': {
|
||||
const snapshotContent = snapshot.content.at(event.index);
|
||||
switch (event.delta.type) {
|
||||
case 'text_delta': {
|
||||
if (snapshotContent?.type === 'text') {
|
||||
snapshot.content[event.index] = {
|
||||
...snapshotContent,
|
||||
text: (snapshotContent.text || '') + event.delta.text,
|
||||
};
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'citations_delta': {
|
||||
if (snapshotContent?.type === 'text') {
|
||||
snapshot.content[event.index] = {
|
||||
...snapshotContent,
|
||||
citations: [...(snapshotContent.citations ?? []), event.delta.citation],
|
||||
};
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'input_json_delta': {
|
||||
if (snapshotContent && tracksToolInput(snapshotContent)) {
|
||||
// we need to keep track of the raw JSON string as well so that we can
|
||||
// re-parse it for each delta, for now we just store it as an untyped
|
||||
// non-enumerable property on the snapshot
|
||||
let jsonBuf = snapshotContent[JSON_BUF_PROPERTY] || '';
|
||||
jsonBuf += event.delta.partial_json;
|
||||
const newContent = { ...snapshotContent };
|
||||
Object.defineProperty(newContent, JSON_BUF_PROPERTY, {
|
||||
value: jsonBuf,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
});
|
||||
if (jsonBuf) {
|
||||
newContent.input = partialParse(jsonBuf);
|
||||
}
|
||||
snapshot.content[event.index] = newContent;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'thinking_delta': {
|
||||
if (snapshotContent?.type === 'thinking') {
|
||||
snapshot.content[event.index] = {
|
||||
...snapshotContent,
|
||||
thinking: snapshotContent.thinking + event.delta.thinking,
|
||||
};
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'signature_delta': {
|
||||
if (snapshotContent?.type === 'thinking') {
|
||||
snapshot.content[event.index] = {
|
||||
...snapshotContent,
|
||||
signature: event.delta.signature,
|
||||
};
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
checkNever(event.delta);
|
||||
}
|
||||
return snapshot;
|
||||
}
|
||||
case 'content_block_stop':
|
||||
return snapshot;
|
||||
}
|
||||
}, Symbol.asyncIterator)]() {
|
||||
const pushQueue = [];
|
||||
const readQueue = [];
|
||||
let done = false;
|
||||
this.on('streamEvent', (event) => {
|
||||
const reader = readQueue.shift();
|
||||
if (reader) {
|
||||
reader.resolve(event);
|
||||
}
|
||||
else {
|
||||
pushQueue.push(event);
|
||||
}
|
||||
});
|
||||
this.on('end', () => {
|
||||
done = true;
|
||||
for (const reader of readQueue) {
|
||||
reader.resolve(undefined);
|
||||
}
|
||||
readQueue.length = 0;
|
||||
});
|
||||
this.on('abort', (err) => {
|
||||
done = true;
|
||||
for (const reader of readQueue) {
|
||||
reader.reject(err);
|
||||
}
|
||||
readQueue.length = 0;
|
||||
});
|
||||
this.on('error', (err) => {
|
||||
done = true;
|
||||
for (const reader of readQueue) {
|
||||
reader.reject(err);
|
||||
}
|
||||
readQueue.length = 0;
|
||||
});
|
||||
return {
|
||||
next: async () => {
|
||||
if (!pushQueue.length) {
|
||||
if (done) {
|
||||
return { value: undefined, done: true };
|
||||
}
|
||||
return new Promise((resolve, reject) => readQueue.push({ resolve, reject })).then((chunk) => (chunk ? { value: chunk, done: false } : { value: undefined, done: true }));
|
||||
}
|
||||
const chunk = pushQueue.shift();
|
||||
return { value: chunk, done: false };
|
||||
},
|
||||
return: async () => {
|
||||
this.abort();
|
||||
return { value: undefined, done: true };
|
||||
},
|
||||
};
|
||||
}
|
||||
toReadableStream() {
|
||||
const stream = new Stream(this[Symbol.asyncIterator].bind(this), this.controller);
|
||||
return stream.toReadableStream();
|
||||
}
|
||||
}
|
||||
// used to ensure exhaustive case matching without throwing a runtime error
|
||||
function checkNever(x) { }
|
||||
//# sourceMappingURL=MessageStream.mjs.map
|
||||
75
extracted-source/node_modules/@anthropic-ai/sdk/lib/beta-parser.mjs
generated
vendored
Normal file
75
extracted-source/node_modules/@anthropic-ai/sdk/lib/beta-parser.mjs
generated
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
import { AnthropicError } from "../core/error.mjs";
|
||||
function getOutputFormat(params) {
|
||||
// Prefer output_format (deprecated) over output_config.format for backward compatibility
|
||||
return params?.output_format ?? params?.output_config?.format;
|
||||
}
|
||||
export function maybeParseBetaMessage(message, params, opts) {
|
||||
const outputFormat = getOutputFormat(params);
|
||||
if (!params || !('parse' in (outputFormat ?? {}))) {
|
||||
return {
|
||||
...message,
|
||||
content: message.content.map((block) => {
|
||||
if (block.type === 'text') {
|
||||
const parsedBlock = Object.defineProperty({ ...block }, 'parsed_output', {
|
||||
value: null,
|
||||
enumerable: false,
|
||||
});
|
||||
return Object.defineProperty(parsedBlock, 'parsed', {
|
||||
get() {
|
||||
opts.logger.warn('The `parsed` property on `text` blocks is deprecated, please use `parsed_output` instead.');
|
||||
return null;
|
||||
},
|
||||
enumerable: false,
|
||||
});
|
||||
}
|
||||
return block;
|
||||
}),
|
||||
parsed_output: null,
|
||||
};
|
||||
}
|
||||
return parseBetaMessage(message, params, opts);
|
||||
}
|
||||
export function parseBetaMessage(message, params, opts) {
|
||||
let firstParsedOutput = null;
|
||||
const content = message.content.map((block) => {
|
||||
if (block.type === 'text') {
|
||||
const parsedOutput = parseBetaOutputFormat(params, block.text);
|
||||
if (firstParsedOutput === null) {
|
||||
firstParsedOutput = parsedOutput;
|
||||
}
|
||||
const parsedBlock = Object.defineProperty({ ...block }, 'parsed_output', {
|
||||
value: parsedOutput,
|
||||
enumerable: false,
|
||||
});
|
||||
return Object.defineProperty(parsedBlock, 'parsed', {
|
||||
get() {
|
||||
opts.logger.warn('The `parsed` property on `text` blocks is deprecated, please use `parsed_output` instead.');
|
||||
return parsedOutput;
|
||||
},
|
||||
enumerable: false,
|
||||
});
|
||||
}
|
||||
return block;
|
||||
});
|
||||
return {
|
||||
...message,
|
||||
content,
|
||||
parsed_output: firstParsedOutput,
|
||||
};
|
||||
}
|
||||
function parseBetaOutputFormat(params, content) {
|
||||
const outputFormat = getOutputFormat(params);
|
||||
if (outputFormat?.type !== 'json_schema') {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
if ('parse' in outputFormat) {
|
||||
return outputFormat.parse(content);
|
||||
}
|
||||
return JSON.parse(content);
|
||||
}
|
||||
catch (error) {
|
||||
throw new AnthropicError(`Failed to parse structured output: ${error}`);
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=beta-parser.mjs.map
|
||||
62
extracted-source/node_modules/@anthropic-ai/sdk/lib/parser.mjs
generated
vendored
Normal file
62
extracted-source/node_modules/@anthropic-ai/sdk/lib/parser.mjs
generated
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
import { AnthropicError } from "../core/error.mjs";
|
||||
function getOutputFormat(params) {
|
||||
return params?.output_config?.format;
|
||||
}
|
||||
export function maybeParseMessage(message, params, opts) {
|
||||
const outputFormat = getOutputFormat(params);
|
||||
if (!params || !('parse' in (outputFormat ?? {}))) {
|
||||
return {
|
||||
...message,
|
||||
content: message.content.map((block) => {
|
||||
if (block.type === 'text') {
|
||||
const parsedBlock = Object.defineProperty({ ...block }, 'parsed_output', {
|
||||
value: null,
|
||||
enumerable: false,
|
||||
});
|
||||
return parsedBlock;
|
||||
}
|
||||
return block;
|
||||
}),
|
||||
parsed_output: null,
|
||||
};
|
||||
}
|
||||
return parseMessage(message, params, opts);
|
||||
}
|
||||
export function parseMessage(message, params, opts) {
|
||||
let firstParsedOutput = null;
|
||||
const content = message.content.map((block) => {
|
||||
if (block.type === 'text') {
|
||||
const parsedOutput = parseOutputFormat(params, block.text);
|
||||
if (firstParsedOutput === null) {
|
||||
firstParsedOutput = parsedOutput;
|
||||
}
|
||||
const parsedBlock = Object.defineProperty({ ...block }, 'parsed_output', {
|
||||
value: parsedOutput,
|
||||
enumerable: false,
|
||||
});
|
||||
return parsedBlock;
|
||||
}
|
||||
return block;
|
||||
});
|
||||
return {
|
||||
...message,
|
||||
content,
|
||||
parsed_output: firstParsedOutput,
|
||||
};
|
||||
}
|
||||
function parseOutputFormat(params, content) {
|
||||
const outputFormat = getOutputFormat(params);
|
||||
if (outputFormat?.type !== 'json_schema') {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
if ('parse' in outputFormat) {
|
||||
return outputFormat.parse(content);
|
||||
}
|
||||
return JSON.parse(content);
|
||||
}
|
||||
catch (error) {
|
||||
throw new AnthropicError(`Failed to parse structured output: ${error}`);
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=parser.mjs.map
|
||||
63
extracted-source/node_modules/@anthropic-ai/sdk/lib/stainless-helper-header.mjs
generated
vendored
Normal file
63
extracted-source/node_modules/@anthropic-ai/sdk/lib/stainless-helper-header.mjs
generated
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* Shared utilities for tracking SDK helper usage.
|
||||
*/
|
||||
/**
|
||||
* Symbol used to mark objects created by SDK helpers for tracking.
|
||||
* The value is the helper name (e.g., 'mcpTool', 'betaZodTool').
|
||||
*/
|
||||
export const SDK_HELPER_SYMBOL = Symbol('anthropic.sdk.stainlessHelper');
|
||||
export function wasCreatedByStainlessHelper(value) {
|
||||
return typeof value === 'object' && value !== null && SDK_HELPER_SYMBOL in value;
|
||||
}
|
||||
/**
|
||||
* Collects helper names from tools and messages arrays.
|
||||
* Returns a deduplicated array of helper names found.
|
||||
*/
|
||||
export function collectStainlessHelpers(tools, messages) {
|
||||
const helpers = new Set();
|
||||
// Collect from tools
|
||||
if (tools) {
|
||||
for (const tool of tools) {
|
||||
if (wasCreatedByStainlessHelper(tool)) {
|
||||
helpers.add(tool[SDK_HELPER_SYMBOL]);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Collect from messages and their content blocks
|
||||
if (messages) {
|
||||
for (const message of messages) {
|
||||
if (wasCreatedByStainlessHelper(message)) {
|
||||
helpers.add(message[SDK_HELPER_SYMBOL]);
|
||||
}
|
||||
if (Array.isArray(message.content)) {
|
||||
for (const block of message.content) {
|
||||
if (wasCreatedByStainlessHelper(block)) {
|
||||
helpers.add(block[SDK_HELPER_SYMBOL]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return Array.from(helpers);
|
||||
}
|
||||
/**
|
||||
* Builds x-stainless-helper header value from tools and messages.
|
||||
* Returns an empty object if no helpers are found.
|
||||
*/
|
||||
export function stainlessHelperHeader(tools, messages) {
|
||||
const helpers = collectStainlessHelpers(tools, messages);
|
||||
if (helpers.length === 0)
|
||||
return {};
|
||||
return { 'x-stainless-helper': helpers.join(', ') };
|
||||
}
|
||||
/**
|
||||
* Builds x-stainless-helper header value from a file object.
|
||||
* Returns an empty object if the file is not marked with a helper.
|
||||
*/
|
||||
export function stainlessHelperHeaderFromFile(file) {
|
||||
if (wasCreatedByStainlessHelper(file)) {
|
||||
return { 'x-stainless-helper': file[SDK_HELPER_SYMBOL] };
|
||||
}
|
||||
return {};
|
||||
}
|
||||
//# sourceMappingURL=stainless-helper-header.mjs.map
|
||||
372
extracted-source/node_modules/@anthropic-ai/sdk/lib/tools/BetaToolRunner.mjs
generated
vendored
Normal file
372
extracted-source/node_modules/@anthropic-ai/sdk/lib/tools/BetaToolRunner.mjs
generated
vendored
Normal file
@@ -0,0 +1,372 @@
|
||||
var _BetaToolRunner_instances, _BetaToolRunner_consumed, _BetaToolRunner_mutated, _BetaToolRunner_state, _BetaToolRunner_options, _BetaToolRunner_message, _BetaToolRunner_toolResponse, _BetaToolRunner_completion, _BetaToolRunner_iterationCount, _BetaToolRunner_checkAndCompact, _BetaToolRunner_generateToolResponse;
|
||||
import { __classPrivateFieldGet, __classPrivateFieldSet } from "../../internal/tslib.mjs";
|
||||
import { ToolError } from "./ToolError.mjs";
|
||||
import { AnthropicError } from "../../core/error.mjs";
|
||||
import { buildHeaders } from "../../internal/headers.mjs";
|
||||
import { DEFAULT_SUMMARY_PROMPT, DEFAULT_TOKEN_THRESHOLD } from "./CompactionControl.mjs";
|
||||
import { collectStainlessHelpers } from "../stainless-helper-header.mjs";
|
||||
/**
|
||||
* Just Promise.withResolvers(), which is not available in all environments.
|
||||
*/
|
||||
function promiseWithResolvers() {
|
||||
let resolve;
|
||||
let reject;
|
||||
const promise = new Promise((res, rej) => {
|
||||
resolve = res;
|
||||
reject = rej;
|
||||
});
|
||||
return { promise, resolve: resolve, reject: reject };
|
||||
}
|
||||
/**
|
||||
* A ToolRunner handles the automatic conversation loop between the assistant and tools.
|
||||
*
|
||||
* A ToolRunner is an async iterable that yields either BetaMessage or BetaMessageStream objects
|
||||
* depending on the streaming configuration.
|
||||
*/
|
||||
export class BetaToolRunner {
|
||||
constructor(client, params, options) {
|
||||
_BetaToolRunner_instances.add(this);
|
||||
this.client = client;
|
||||
/** Whether the async iterator has been consumed */
|
||||
_BetaToolRunner_consumed.set(this, false);
|
||||
/** Whether parameters have been mutated since the last API call */
|
||||
_BetaToolRunner_mutated.set(this, false);
|
||||
/** Current state containing the request parameters */
|
||||
_BetaToolRunner_state.set(this, void 0);
|
||||
_BetaToolRunner_options.set(this, void 0);
|
||||
/** Promise for the last message received from the assistant */
|
||||
_BetaToolRunner_message.set(this, void 0);
|
||||
/** Cached tool response to avoid redundant executions */
|
||||
_BetaToolRunner_toolResponse.set(this, void 0);
|
||||
/** Promise resolvers for waiting on completion */
|
||||
_BetaToolRunner_completion.set(this, void 0);
|
||||
/** Number of iterations (API requests) made so far */
|
||||
_BetaToolRunner_iterationCount.set(this, 0);
|
||||
__classPrivateFieldSet(this, _BetaToolRunner_state, {
|
||||
params: {
|
||||
// You can't clone the entire params since there are functions as handlers.
|
||||
// You also don't really need to clone params.messages, but it probably will prevent a foot gun
|
||||
// somewhere.
|
||||
...params,
|
||||
messages: structuredClone(params.messages),
|
||||
},
|
||||
}, "f");
|
||||
const helpers = collectStainlessHelpers(params.tools, params.messages);
|
||||
const helperValue = ['BetaToolRunner', ...helpers].join(', ');
|
||||
__classPrivateFieldSet(this, _BetaToolRunner_options, {
|
||||
...options,
|
||||
headers: buildHeaders([{ 'x-stainless-helper': helperValue }, options?.headers]),
|
||||
}, "f");
|
||||
__classPrivateFieldSet(this, _BetaToolRunner_completion, promiseWithResolvers(), "f");
|
||||
}
|
||||
async *[(_BetaToolRunner_consumed = new WeakMap(), _BetaToolRunner_mutated = new WeakMap(), _BetaToolRunner_state = new WeakMap(), _BetaToolRunner_options = new WeakMap(), _BetaToolRunner_message = new WeakMap(), _BetaToolRunner_toolResponse = new WeakMap(), _BetaToolRunner_completion = new WeakMap(), _BetaToolRunner_iterationCount = new WeakMap(), _BetaToolRunner_instances = new WeakSet(), _BetaToolRunner_checkAndCompact = async function _BetaToolRunner_checkAndCompact() {
|
||||
const compactionControl = __classPrivateFieldGet(this, _BetaToolRunner_state, "f").params.compactionControl;
|
||||
if (!compactionControl || !compactionControl.enabled) {
|
||||
return false;
|
||||
}
|
||||
let tokensUsed = 0;
|
||||
if (__classPrivateFieldGet(this, _BetaToolRunner_message, "f") !== undefined) {
|
||||
try {
|
||||
const message = await __classPrivateFieldGet(this, _BetaToolRunner_message, "f");
|
||||
const totalInputTokens = message.usage.input_tokens +
|
||||
(message.usage.cache_creation_input_tokens ?? 0) +
|
||||
(message.usage.cache_read_input_tokens ?? 0);
|
||||
tokensUsed = totalInputTokens + message.usage.output_tokens;
|
||||
}
|
||||
catch {
|
||||
// If we can't get the message, skip compaction
|
||||
return false;
|
||||
}
|
||||
}
|
||||
const threshold = compactionControl.contextTokenThreshold ?? DEFAULT_TOKEN_THRESHOLD;
|
||||
if (tokensUsed < threshold) {
|
||||
return false;
|
||||
}
|
||||
const model = compactionControl.model ?? __classPrivateFieldGet(this, _BetaToolRunner_state, "f").params.model;
|
||||
const summaryPrompt = compactionControl.summaryPrompt ?? DEFAULT_SUMMARY_PROMPT;
|
||||
const messages = __classPrivateFieldGet(this, _BetaToolRunner_state, "f").params.messages;
|
||||
if (messages[messages.length - 1].role === 'assistant') {
|
||||
// Remove tool_use blocks from the last message to avoid 400 error
|
||||
// (tool_use requires tool_result, which we don't have yet)
|
||||
const lastMessage = messages[messages.length - 1];
|
||||
if (Array.isArray(lastMessage.content)) {
|
||||
const nonToolBlocks = lastMessage.content.filter((block) => block.type !== 'tool_use');
|
||||
if (nonToolBlocks.length === 0) {
|
||||
// If all blocks were tool_use, just remove the message entirely
|
||||
messages.pop();
|
||||
}
|
||||
else {
|
||||
lastMessage.content = nonToolBlocks;
|
||||
}
|
||||
}
|
||||
}
|
||||
const response = await this.client.beta.messages.create({
|
||||
model,
|
||||
messages: [
|
||||
...messages,
|
||||
{
|
||||
role: 'user',
|
||||
content: [
|
||||
{
|
||||
type: 'text',
|
||||
text: summaryPrompt,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
max_tokens: __classPrivateFieldGet(this, _BetaToolRunner_state, "f").params.max_tokens,
|
||||
}, {
|
||||
headers: { 'x-stainless-helper': 'compaction' },
|
||||
});
|
||||
if (response.content[0]?.type !== 'text') {
|
||||
throw new AnthropicError('Expected text response for compaction');
|
||||
}
|
||||
__classPrivateFieldGet(this, _BetaToolRunner_state, "f").params.messages = [
|
||||
{
|
||||
role: 'user',
|
||||
content: response.content,
|
||||
},
|
||||
];
|
||||
return true;
|
||||
}, Symbol.asyncIterator)]() {
|
||||
var _a;
|
||||
if (__classPrivateFieldGet(this, _BetaToolRunner_consumed, "f")) {
|
||||
throw new AnthropicError('Cannot iterate over a consumed stream');
|
||||
}
|
||||
__classPrivateFieldSet(this, _BetaToolRunner_consumed, true, "f");
|
||||
__classPrivateFieldSet(this, _BetaToolRunner_mutated, true, "f");
|
||||
__classPrivateFieldSet(this, _BetaToolRunner_toolResponse, undefined, "f");
|
||||
try {
|
||||
while (true) {
|
||||
let stream;
|
||||
try {
|
||||
if (__classPrivateFieldGet(this, _BetaToolRunner_state, "f").params.max_iterations &&
|
||||
__classPrivateFieldGet(this, _BetaToolRunner_iterationCount, "f") >= __classPrivateFieldGet(this, _BetaToolRunner_state, "f").params.max_iterations) {
|
||||
break;
|
||||
}
|
||||
__classPrivateFieldSet(this, _BetaToolRunner_mutated, false, "f");
|
||||
__classPrivateFieldSet(this, _BetaToolRunner_toolResponse, undefined, "f");
|
||||
__classPrivateFieldSet(this, _BetaToolRunner_iterationCount, (_a = __classPrivateFieldGet(this, _BetaToolRunner_iterationCount, "f"), _a++, _a), "f");
|
||||
__classPrivateFieldSet(this, _BetaToolRunner_message, undefined, "f");
|
||||
const { max_iterations, compactionControl, ...params } = __classPrivateFieldGet(this, _BetaToolRunner_state, "f").params;
|
||||
if (params.stream) {
|
||||
stream = this.client.beta.messages.stream({ ...params }, __classPrivateFieldGet(this, _BetaToolRunner_options, "f"));
|
||||
__classPrivateFieldSet(this, _BetaToolRunner_message, stream.finalMessage(), "f");
|
||||
// Make sure that this promise doesn't throw before we get the option to do something about it.
|
||||
// Error will be caught when we call await this.#message ultimately
|
||||
__classPrivateFieldGet(this, _BetaToolRunner_message, "f").catch(() => { });
|
||||
yield stream;
|
||||
}
|
||||
else {
|
||||
__classPrivateFieldSet(this, _BetaToolRunner_message, this.client.beta.messages.create({ ...params, stream: false }, __classPrivateFieldGet(this, _BetaToolRunner_options, "f")), "f");
|
||||
yield __classPrivateFieldGet(this, _BetaToolRunner_message, "f");
|
||||
}
|
||||
const isCompacted = await __classPrivateFieldGet(this, _BetaToolRunner_instances, "m", _BetaToolRunner_checkAndCompact).call(this);
|
||||
if (!isCompacted) {
|
||||
if (!__classPrivateFieldGet(this, _BetaToolRunner_mutated, "f")) {
|
||||
const { role, content } = await __classPrivateFieldGet(this, _BetaToolRunner_message, "f");
|
||||
__classPrivateFieldGet(this, _BetaToolRunner_state, "f").params.messages.push({ role, content });
|
||||
}
|
||||
const toolMessage = await __classPrivateFieldGet(this, _BetaToolRunner_instances, "m", _BetaToolRunner_generateToolResponse).call(this, __classPrivateFieldGet(this, _BetaToolRunner_state, "f").params.messages.at(-1));
|
||||
if (toolMessage) {
|
||||
__classPrivateFieldGet(this, _BetaToolRunner_state, "f").params.messages.push(toolMessage);
|
||||
}
|
||||
else if (!__classPrivateFieldGet(this, _BetaToolRunner_mutated, "f")) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
if (stream) {
|
||||
stream.abort();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!__classPrivateFieldGet(this, _BetaToolRunner_message, "f")) {
|
||||
throw new AnthropicError('ToolRunner concluded without a message from the server');
|
||||
}
|
||||
__classPrivateFieldGet(this, _BetaToolRunner_completion, "f").resolve(await __classPrivateFieldGet(this, _BetaToolRunner_message, "f"));
|
||||
}
|
||||
catch (error) {
|
||||
__classPrivateFieldSet(this, _BetaToolRunner_consumed, false, "f");
|
||||
// Silence unhandled promise errors
|
||||
__classPrivateFieldGet(this, _BetaToolRunner_completion, "f").promise.catch(() => { });
|
||||
__classPrivateFieldGet(this, _BetaToolRunner_completion, "f").reject(error);
|
||||
__classPrivateFieldSet(this, _BetaToolRunner_completion, promiseWithResolvers(), "f");
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
setMessagesParams(paramsOrMutator) {
|
||||
if (typeof paramsOrMutator === 'function') {
|
||||
__classPrivateFieldGet(this, _BetaToolRunner_state, "f").params = paramsOrMutator(__classPrivateFieldGet(this, _BetaToolRunner_state, "f").params);
|
||||
}
|
||||
else {
|
||||
__classPrivateFieldGet(this, _BetaToolRunner_state, "f").params = paramsOrMutator;
|
||||
}
|
||||
__classPrivateFieldSet(this, _BetaToolRunner_mutated, true, "f");
|
||||
// Invalidate cached tool response since parameters changed
|
||||
__classPrivateFieldSet(this, _BetaToolRunner_toolResponse, undefined, "f");
|
||||
}
|
||||
/**
|
||||
* Get the tool response for the last message from the assistant.
|
||||
* Avoids redundant tool executions by caching results.
|
||||
*
|
||||
* @returns A promise that resolves to a BetaMessageParam containing tool results, or null if no tools need to be executed
|
||||
*
|
||||
* @example
|
||||
* const toolResponse = await runner.generateToolResponse();
|
||||
* if (toolResponse) {
|
||||
* console.log('Tool results:', toolResponse.content);
|
||||
* }
|
||||
*/
|
||||
async generateToolResponse() {
|
||||
const message = (await __classPrivateFieldGet(this, _BetaToolRunner_message, "f")) ?? this.params.messages.at(-1);
|
||||
if (!message) {
|
||||
return null;
|
||||
}
|
||||
return __classPrivateFieldGet(this, _BetaToolRunner_instances, "m", _BetaToolRunner_generateToolResponse).call(this, message);
|
||||
}
|
||||
/**
|
||||
* Wait for the async iterator to complete. This works even if the async iterator hasn't yet started, and
|
||||
* will wait for an instance to start and go to completion.
|
||||
*
|
||||
* @returns A promise that resolves to the final BetaMessage when the iterator completes
|
||||
*
|
||||
* @example
|
||||
* // Start consuming the iterator
|
||||
* for await (const message of runner) {
|
||||
* console.log('Message:', message.content);
|
||||
* }
|
||||
*
|
||||
* // Meanwhile, wait for completion from another part of the code
|
||||
* const finalMessage = await runner.done();
|
||||
* console.log('Final response:', finalMessage.content);
|
||||
*/
|
||||
done() {
|
||||
return __classPrivateFieldGet(this, _BetaToolRunner_completion, "f").promise;
|
||||
}
|
||||
/**
|
||||
* Returns a promise indicating that the stream is done. Unlike .done(), this will eagerly read the stream:
|
||||
* * If the iterator has not been consumed, consume the entire iterator and return the final message from the
|
||||
* assistant.
|
||||
* * If the iterator has been consumed, waits for it to complete and returns the final message.
|
||||
*
|
||||
* @returns A promise that resolves to the final BetaMessage from the conversation
|
||||
* @throws {AnthropicError} If no messages were processed during the conversation
|
||||
*
|
||||
* @example
|
||||
* const finalMessage = await runner.runUntilDone();
|
||||
* console.log('Final response:', finalMessage.content);
|
||||
*/
|
||||
async runUntilDone() {
|
||||
// If not yet consumed, start consuming and wait for completion
|
||||
if (!__classPrivateFieldGet(this, _BetaToolRunner_consumed, "f")) {
|
||||
for await (const _ of this) {
|
||||
// Iterator naturally populates this.#message
|
||||
}
|
||||
}
|
||||
// If consumed but not completed, wait for completion
|
||||
return this.done();
|
||||
}
|
||||
/**
|
||||
* Get the current parameters being used by the ToolRunner.
|
||||
*
|
||||
* @returns A readonly view of the current ToolRunnerParams
|
||||
*
|
||||
* @example
|
||||
* const currentParams = runner.params;
|
||||
* console.log('Current model:', currentParams.model);
|
||||
* console.log('Message count:', currentParams.messages.length);
|
||||
*/
|
||||
get params() {
|
||||
return __classPrivateFieldGet(this, _BetaToolRunner_state, "f").params;
|
||||
}
|
||||
/**
|
||||
* Add one or more messages to the conversation history.
|
||||
*
|
||||
* @param messages - One or more BetaMessageParam objects to add to the conversation
|
||||
*
|
||||
* @example
|
||||
* runner.pushMessages(
|
||||
* { role: 'user', content: 'Also, what about the weather in NYC?' }
|
||||
* );
|
||||
*
|
||||
* @example
|
||||
* // Adding multiple messages
|
||||
* runner.pushMessages(
|
||||
* { role: 'user', content: 'What about NYC?' },
|
||||
* { role: 'user', content: 'And Boston?' }
|
||||
* );
|
||||
*/
|
||||
pushMessages(...messages) {
|
||||
this.setMessagesParams((params) => ({
|
||||
...params,
|
||||
messages: [...params.messages, ...messages],
|
||||
}));
|
||||
}
|
||||
/**
|
||||
* Makes the ToolRunner directly awaitable, equivalent to calling .runUntilDone()
|
||||
* This allows using `await runner` instead of `await runner.runUntilDone()`
|
||||
*/
|
||||
then(onfulfilled, onrejected) {
|
||||
return this.runUntilDone().then(onfulfilled, onrejected);
|
||||
}
|
||||
}
|
||||
_BetaToolRunner_generateToolResponse = async function _BetaToolRunner_generateToolResponse(lastMessage) {
|
||||
if (__classPrivateFieldGet(this, _BetaToolRunner_toolResponse, "f") !== undefined) {
|
||||
return __classPrivateFieldGet(this, _BetaToolRunner_toolResponse, "f");
|
||||
}
|
||||
__classPrivateFieldSet(this, _BetaToolRunner_toolResponse, generateToolResponse(__classPrivateFieldGet(this, _BetaToolRunner_state, "f").params, lastMessage), "f");
|
||||
return __classPrivateFieldGet(this, _BetaToolRunner_toolResponse, "f");
|
||||
};
|
||||
async function generateToolResponse(params, lastMessage = params.messages.at(-1)) {
|
||||
// Only process if the last message is from the assistant and has tool use blocks
|
||||
if (!lastMessage ||
|
||||
lastMessage.role !== 'assistant' ||
|
||||
!lastMessage.content ||
|
||||
typeof lastMessage.content === 'string') {
|
||||
return null;
|
||||
}
|
||||
const toolUseBlocks = lastMessage.content.filter((content) => content.type === 'tool_use');
|
||||
if (toolUseBlocks.length === 0) {
|
||||
return null;
|
||||
}
|
||||
const toolResults = await Promise.all(toolUseBlocks.map(async (toolUse) => {
|
||||
const tool = params.tools.find((t) => ('name' in t ? t.name : t.mcp_server_name) === toolUse.name);
|
||||
if (!tool || !('run' in tool)) {
|
||||
return {
|
||||
type: 'tool_result',
|
||||
tool_use_id: toolUse.id,
|
||||
content: `Error: Tool '${toolUse.name}' not found`,
|
||||
is_error: true,
|
||||
};
|
||||
}
|
||||
try {
|
||||
let input = toolUse.input;
|
||||
if ('parse' in tool && tool.parse) {
|
||||
input = tool.parse(input);
|
||||
}
|
||||
const result = await tool.run(input);
|
||||
return {
|
||||
type: 'tool_result',
|
||||
tool_use_id: toolUse.id,
|
||||
content: result,
|
||||
};
|
||||
}
|
||||
catch (error) {
|
||||
return {
|
||||
type: 'tool_result',
|
||||
tool_use_id: toolUse.id,
|
||||
content: error instanceof ToolError ?
|
||||
error.content
|
||||
: `Error: ${error instanceof Error ? error.message : String(error)}`,
|
||||
is_error: true,
|
||||
};
|
||||
}
|
||||
}));
|
||||
return {
|
||||
role: 'user',
|
||||
content: toolResults,
|
||||
};
|
||||
}
|
||||
//# sourceMappingURL=BetaToolRunner.mjs.map
|
||||
25
extracted-source/node_modules/@anthropic-ai/sdk/lib/tools/CompactionControl.mjs
generated
vendored
Normal file
25
extracted-source/node_modules/@anthropic-ai/sdk/lib/tools/CompactionControl.mjs
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
export const DEFAULT_TOKEN_THRESHOLD = 100000;
|
||||
export const DEFAULT_SUMMARY_PROMPT = `You have been working on the task described above but have not yet completed it. Write a continuation summary that will allow you (or another instance of yourself) to resume work efficiently in a future context window where the conversation history will be replaced with this summary. Your summary should be structured, concise, and actionable. Include:
|
||||
1. Task Overview
|
||||
The user's core request and success criteria
|
||||
Any clarifications or constraints they specified
|
||||
2. Current State
|
||||
What has been completed so far
|
||||
Files created, modified, or analyzed (with paths if relevant)
|
||||
Key outputs or artifacts produced
|
||||
3. Important Discoveries
|
||||
Technical constraints or requirements uncovered
|
||||
Decisions made and their rationale
|
||||
Errors encountered and how they were resolved
|
||||
What approaches were tried that didn't work (and why)
|
||||
4. Next Steps
|
||||
Specific actions needed to complete the task
|
||||
Any blockers or open questions to resolve
|
||||
Priority order if multiple steps remain
|
||||
5. Context to Preserve
|
||||
User preferences or style requirements
|
||||
Domain-specific details that aren't obvious
|
||||
Any promises made to the user
|
||||
Be concise but complete—err on the side of including information that would prevent duplicate work or repeated mistakes. Write in a way that enables immediate resumption of the task.
|
||||
Wrap your summary in <summary></summary> tags.`;
|
||||
//# sourceMappingURL=CompactionControl.mjs.map
|
||||
38
extracted-source/node_modules/@anthropic-ai/sdk/lib/tools/ToolError.mjs
generated
vendored
Normal file
38
extracted-source/node_modules/@anthropic-ai/sdk/lib/tools/ToolError.mjs
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* An error that can be thrown from a tool's `run` method to return structured
|
||||
* content blocks as the error result, rather than just a string message.
|
||||
*
|
||||
* When the ToolRunner catches this error, it will use the `content` property
|
||||
* as the tool result with `is_error: true`.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const tool = {
|
||||
* name: 'my_tool',
|
||||
* run: async (input) => {
|
||||
* if (somethingWentWrong) {
|
||||
* throw new ToolError([
|
||||
* { type: 'text', text: 'Error details here' },
|
||||
* { type: 'image', source: { type: 'base64', data: '...', media_type: 'image/png' } },
|
||||
* ]);
|
||||
* }
|
||||
* return 'success';
|
||||
* },
|
||||
* };
|
||||
* ```
|
||||
*/
|
||||
export class ToolError extends Error {
|
||||
constructor(content) {
|
||||
const message = typeof content === 'string' ? content : (content
|
||||
.map((block) => {
|
||||
if (block.type === 'text')
|
||||
return block.text;
|
||||
return `[${block.type}]`;
|
||||
})
|
||||
.join(' '));
|
||||
super(message);
|
||||
this.name = 'ToolError';
|
||||
this.content = content;
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=ToolError.mjs.map
|
||||
24
extracted-source/node_modules/@anthropic-ai/sdk/resources/beta/beta.mjs
generated
vendored
Normal file
24
extracted-source/node_modules/@anthropic-ai/sdk/resources/beta/beta.mjs
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
||||
import { APIResource } from "../../core/resource.mjs";
|
||||
import * as FilesAPI from "./files.mjs";
|
||||
import { Files, } from "./files.mjs";
|
||||
import * as ModelsAPI from "./models.mjs";
|
||||
import { Models } from "./models.mjs";
|
||||
import * as MessagesAPI from "./messages/messages.mjs";
|
||||
import { Messages, } from "./messages/messages.mjs";
|
||||
import * as SkillsAPI from "./skills/skills.mjs";
|
||||
import { Skills, } from "./skills/skills.mjs";
|
||||
export class Beta extends APIResource {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.models = new ModelsAPI.Models(this._client);
|
||||
this.messages = new MessagesAPI.Messages(this._client);
|
||||
this.files = new FilesAPI.Files(this._client);
|
||||
this.skills = new SkillsAPI.Skills(this._client);
|
||||
}
|
||||
}
|
||||
Beta.Models = Models;
|
||||
Beta.Messages = Messages;
|
||||
Beta.Files = Files;
|
||||
Beta.Skills = Skills;
|
||||
//# sourceMappingURL=beta.mjs.map
|
||||
120
extracted-source/node_modules/@anthropic-ai/sdk/resources/beta/files.mjs
generated
vendored
Normal file
120
extracted-source/node_modules/@anthropic-ai/sdk/resources/beta/files.mjs
generated
vendored
Normal file
@@ -0,0 +1,120 @@
|
||||
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
||||
import { APIResource } from "../../core/resource.mjs";
|
||||
import { Page } from "../../core/pagination.mjs";
|
||||
import { buildHeaders } from "../../internal/headers.mjs";
|
||||
import { stainlessHelperHeaderFromFile } from "../../lib/stainless-helper-header.mjs";
|
||||
import { multipartFormRequestOptions } from "../../internal/uploads.mjs";
|
||||
import { path } from "../../internal/utils/path.mjs";
|
||||
export class Files extends APIResource {
|
||||
/**
|
||||
* List Files
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* // Automatically fetches more pages as needed.
|
||||
* for await (const fileMetadata of client.beta.files.list()) {
|
||||
* // ...
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
list(params = {}, options) {
|
||||
const { betas, ...query } = params ?? {};
|
||||
return this._client.getAPIList('/v1/files', (Page), {
|
||||
query,
|
||||
...options,
|
||||
headers: buildHeaders([
|
||||
{ 'anthropic-beta': [...(betas ?? []), 'files-api-2025-04-14'].toString() },
|
||||
options?.headers,
|
||||
]),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Delete File
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const deletedFile = await client.beta.files.delete(
|
||||
* 'file_id',
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
delete(fileID, params = {}, options) {
|
||||
const { betas } = params ?? {};
|
||||
return this._client.delete(path `/v1/files/${fileID}`, {
|
||||
...options,
|
||||
headers: buildHeaders([
|
||||
{ 'anthropic-beta': [...(betas ?? []), 'files-api-2025-04-14'].toString() },
|
||||
options?.headers,
|
||||
]),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Download File
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const response = await client.beta.files.download(
|
||||
* 'file_id',
|
||||
* );
|
||||
*
|
||||
* const content = await response.blob();
|
||||
* console.log(content);
|
||||
* ```
|
||||
*/
|
||||
download(fileID, params = {}, options) {
|
||||
const { betas } = params ?? {};
|
||||
return this._client.get(path `/v1/files/${fileID}/content`, {
|
||||
...options,
|
||||
headers: buildHeaders([
|
||||
{
|
||||
'anthropic-beta': [...(betas ?? []), 'files-api-2025-04-14'].toString(),
|
||||
Accept: 'application/binary',
|
||||
},
|
||||
options?.headers,
|
||||
]),
|
||||
__binaryResponse: true,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Get File Metadata
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const fileMetadata =
|
||||
* await client.beta.files.retrieveMetadata('file_id');
|
||||
* ```
|
||||
*/
|
||||
retrieveMetadata(fileID, params = {}, options) {
|
||||
const { betas } = params ?? {};
|
||||
return this._client.get(path `/v1/files/${fileID}`, {
|
||||
...options,
|
||||
headers: buildHeaders([
|
||||
{ 'anthropic-beta': [...(betas ?? []), 'files-api-2025-04-14'].toString() },
|
||||
options?.headers,
|
||||
]),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Upload File
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const fileMetadata = await client.beta.files.upload({
|
||||
* file: fs.createReadStream('path/to/file'),
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
upload(params, options) {
|
||||
const { betas, ...body } = params;
|
||||
return this._client.post('/v1/files', multipartFormRequestOptions({
|
||||
body,
|
||||
...options,
|
||||
headers: buildHeaders([
|
||||
{ 'anthropic-beta': [...(betas ?? []), 'files-api-2025-04-14'].toString() },
|
||||
stainlessHelperHeaderFromFile(body.file),
|
||||
options?.headers,
|
||||
]),
|
||||
}, this._client));
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=files.mjs.map
|
||||
200
extracted-source/node_modules/@anthropic-ai/sdk/resources/beta/messages/batches.mjs
generated
vendored
Normal file
200
extracted-source/node_modules/@anthropic-ai/sdk/resources/beta/messages/batches.mjs
generated
vendored
Normal file
@@ -0,0 +1,200 @@
|
||||
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
||||
import { APIResource } from "../../../core/resource.mjs";
|
||||
import { Page } from "../../../core/pagination.mjs";
|
||||
import { buildHeaders } from "../../../internal/headers.mjs";
|
||||
import { JSONLDecoder } from "../../../internal/decoders/jsonl.mjs";
|
||||
import { AnthropicError } from "../../../error.mjs";
|
||||
import { path } from "../../../internal/utils/path.mjs";
|
||||
export class Batches extends APIResource {
|
||||
/**
|
||||
* Send a batch of Message creation requests.
|
||||
*
|
||||
* The Message Batches API can be used to process multiple Messages API requests at
|
||||
* once. Once a Message Batch is created, it begins processing immediately. Batches
|
||||
* can take up to 24 hours to complete.
|
||||
*
|
||||
* Learn more about the Message Batches API in our
|
||||
* [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const betaMessageBatch =
|
||||
* await client.beta.messages.batches.create({
|
||||
* requests: [
|
||||
* {
|
||||
* custom_id: 'my-custom-id-1',
|
||||
* params: {
|
||||
* max_tokens: 1024,
|
||||
* messages: [
|
||||
* { content: 'Hello, world', role: 'user' },
|
||||
* ],
|
||||
* model: 'claude-opus-4-6',
|
||||
* },
|
||||
* },
|
||||
* ],
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
create(params, options) {
|
||||
const { betas, ...body } = params;
|
||||
return this._client.post('/v1/messages/batches?beta=true', {
|
||||
body,
|
||||
...options,
|
||||
headers: buildHeaders([
|
||||
{ 'anthropic-beta': [...(betas ?? []), 'message-batches-2024-09-24'].toString() },
|
||||
options?.headers,
|
||||
]),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* This endpoint is idempotent and can be used to poll for Message Batch
|
||||
* completion. To access the results of a Message Batch, make a request to the
|
||||
* `results_url` field in the response.
|
||||
*
|
||||
* Learn more about the Message Batches API in our
|
||||
* [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const betaMessageBatch =
|
||||
* await client.beta.messages.batches.retrieve(
|
||||
* 'message_batch_id',
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
retrieve(messageBatchID, params = {}, options) {
|
||||
const { betas } = params ?? {};
|
||||
return this._client.get(path `/v1/messages/batches/${messageBatchID}?beta=true`, {
|
||||
...options,
|
||||
headers: buildHeaders([
|
||||
{ 'anthropic-beta': [...(betas ?? []), 'message-batches-2024-09-24'].toString() },
|
||||
options?.headers,
|
||||
]),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* List all Message Batches within a Workspace. Most recently created batches are
|
||||
* returned first.
|
||||
*
|
||||
* Learn more about the Message Batches API in our
|
||||
* [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* // Automatically fetches more pages as needed.
|
||||
* for await (const betaMessageBatch of client.beta.messages.batches.list()) {
|
||||
* // ...
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
list(params = {}, options) {
|
||||
const { betas, ...query } = params ?? {};
|
||||
return this._client.getAPIList('/v1/messages/batches?beta=true', (Page), {
|
||||
query,
|
||||
...options,
|
||||
headers: buildHeaders([
|
||||
{ 'anthropic-beta': [...(betas ?? []), 'message-batches-2024-09-24'].toString() },
|
||||
options?.headers,
|
||||
]),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Delete a Message Batch.
|
||||
*
|
||||
* Message Batches can only be deleted once they've finished processing. If you'd
|
||||
* like to delete an in-progress batch, you must first cancel it.
|
||||
*
|
||||
* Learn more about the Message Batches API in our
|
||||
* [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const betaDeletedMessageBatch =
|
||||
* await client.beta.messages.batches.delete(
|
||||
* 'message_batch_id',
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
delete(messageBatchID, params = {}, options) {
|
||||
const { betas } = params ?? {};
|
||||
return this._client.delete(path `/v1/messages/batches/${messageBatchID}?beta=true`, {
|
||||
...options,
|
||||
headers: buildHeaders([
|
||||
{ 'anthropic-beta': [...(betas ?? []), 'message-batches-2024-09-24'].toString() },
|
||||
options?.headers,
|
||||
]),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Batches may be canceled any time before processing ends. Once cancellation is
|
||||
* initiated, the batch enters a `canceling` state, at which time the system may
|
||||
* complete any in-progress, non-interruptible requests before finalizing
|
||||
* cancellation.
|
||||
*
|
||||
* The number of canceled requests is specified in `request_counts`. To determine
|
||||
* which requests were canceled, check the individual results within the batch.
|
||||
* Note that cancellation may not result in any canceled requests if they were
|
||||
* non-interruptible.
|
||||
*
|
||||
* Learn more about the Message Batches API in our
|
||||
* [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const betaMessageBatch =
|
||||
* await client.beta.messages.batches.cancel(
|
||||
* 'message_batch_id',
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
cancel(messageBatchID, params = {}, options) {
|
||||
const { betas } = params ?? {};
|
||||
return this._client.post(path `/v1/messages/batches/${messageBatchID}/cancel?beta=true`, {
|
||||
...options,
|
||||
headers: buildHeaders([
|
||||
{ 'anthropic-beta': [...(betas ?? []), 'message-batches-2024-09-24'].toString() },
|
||||
options?.headers,
|
||||
]),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Streams the results of a Message Batch as a `.jsonl` file.
|
||||
*
|
||||
* Each line in the file is a JSON object containing the result of a single request
|
||||
* in the Message Batch. Results are not guaranteed to be in the same order as
|
||||
* requests. Use the `custom_id` field to match results to requests.
|
||||
*
|
||||
* Learn more about the Message Batches API in our
|
||||
* [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const betaMessageBatchIndividualResponse =
|
||||
* await client.beta.messages.batches.results(
|
||||
* 'message_batch_id',
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
async results(messageBatchID, params = {}, options) {
|
||||
const batch = await this.retrieve(messageBatchID);
|
||||
if (!batch.results_url) {
|
||||
throw new AnthropicError(`No batch \`results_url\`; Has it finished processing? ${batch.processing_status} - ${batch.id}`);
|
||||
}
|
||||
const { betas } = params ?? {};
|
||||
return this._client
|
||||
.get(batch.results_url, {
|
||||
...options,
|
||||
headers: buildHeaders([
|
||||
{
|
||||
'anthropic-beta': [...(betas ?? []), 'message-batches-2024-09-24'].toString(),
|
||||
Accept: 'application/binary',
|
||||
},
|
||||
options?.headers,
|
||||
]),
|
||||
stream: true,
|
||||
__binaryResponse: true,
|
||||
})
|
||||
._thenUnwrap((_, props) => JSONLDecoder.fromResponse(props.response, props.controller));
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=batches.mjs.map
|
||||
156
extracted-source/node_modules/@anthropic-ai/sdk/resources/beta/messages/messages.mjs
generated
vendored
Normal file
156
extracted-source/node_modules/@anthropic-ai/sdk/resources/beta/messages/messages.mjs
generated
vendored
Normal file
@@ -0,0 +1,156 @@
|
||||
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
||||
import { AnthropicError } from "../../../error.mjs";
|
||||
import { APIResource } from "../../../core/resource.mjs";
|
||||
import { MODEL_NONSTREAMING_TOKENS } from "../../../internal/constants.mjs";
|
||||
import { buildHeaders } from "../../../internal/headers.mjs";
|
||||
import { stainlessHelperHeader } from "../../../lib/stainless-helper-header.mjs";
|
||||
import { parseBetaMessage, } from "../../../lib/beta-parser.mjs";
|
||||
import { BetaMessageStream } from "../../../lib/BetaMessageStream.mjs";
|
||||
import { BetaToolRunner, } from "../../../lib/tools/BetaToolRunner.mjs";
|
||||
import { ToolError } from "../../../lib/tools/ToolError.mjs";
|
||||
import * as BatchesAPI from "./batches.mjs";
|
||||
import { Batches, } from "./batches.mjs";
|
||||
const DEPRECATED_MODELS = {
|
||||
'claude-1.3': 'November 6th, 2024',
|
||||
'claude-1.3-100k': 'November 6th, 2024',
|
||||
'claude-instant-1.1': 'November 6th, 2024',
|
||||
'claude-instant-1.1-100k': 'November 6th, 2024',
|
||||
'claude-instant-1.2': 'November 6th, 2024',
|
||||
'claude-3-sonnet-20240229': 'July 21st, 2025',
|
||||
'claude-3-opus-20240229': 'January 5th, 2026',
|
||||
'claude-2.1': 'July 21st, 2025',
|
||||
'claude-2.0': 'July 21st, 2025',
|
||||
'claude-3-7-sonnet-latest': 'February 19th, 2026',
|
||||
'claude-3-7-sonnet-20250219': 'February 19th, 2026',
|
||||
};
|
||||
const MODELS_TO_WARN_WITH_THINKING_ENABLED = ['claude-opus-4-6'];
|
||||
export class Messages extends APIResource {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.batches = new BatchesAPI.Batches(this._client);
|
||||
}
|
||||
create(params, options) {
|
||||
// Transform deprecated output_format to output_config.format
|
||||
const modifiedParams = transformOutputFormat(params);
|
||||
const { betas, ...body } = modifiedParams;
|
||||
if (body.model in DEPRECATED_MODELS) {
|
||||
console.warn(`The model '${body.model}' is deprecated and will reach end-of-life on ${DEPRECATED_MODELS[body.model]}\nPlease migrate to a newer model. Visit https://docs.anthropic.com/en/docs/resources/model-deprecations for more information.`);
|
||||
}
|
||||
if (body.model in MODELS_TO_WARN_WITH_THINKING_ENABLED &&
|
||||
body.thinking &&
|
||||
body.thinking.type === 'enabled') {
|
||||
console.warn(`Using Claude with ${body.model} and 'thinking.type=enabled' is deprecated. Use 'thinking.type=adaptive' instead which results in better model performance in our testing: https://platform.claude.com/docs/en/build-with-claude/adaptive-thinking`);
|
||||
}
|
||||
let timeout = this._client._options.timeout;
|
||||
if (!body.stream && timeout == null) {
|
||||
const maxNonstreamingTokens = MODEL_NONSTREAMING_TOKENS[body.model] ?? undefined;
|
||||
timeout = this._client.calculateNonstreamingTimeout(body.max_tokens, maxNonstreamingTokens);
|
||||
}
|
||||
// Collect helper info from tools and messages
|
||||
const helperHeader = stainlessHelperHeader(body.tools, body.messages);
|
||||
return this._client.post('/v1/messages?beta=true', {
|
||||
body,
|
||||
timeout: timeout ?? 600000,
|
||||
...options,
|
||||
headers: buildHeaders([
|
||||
{ ...(betas?.toString() != null ? { 'anthropic-beta': betas?.toString() } : undefined) },
|
||||
helperHeader,
|
||||
options?.headers,
|
||||
]),
|
||||
stream: modifiedParams.stream ?? false,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Send a structured list of input messages with text and/or image content, along with an expected `output_format` and
|
||||
* the response will be automatically parsed and available in the `parsed_output` property of the message.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const message = await client.beta.messages.parse({
|
||||
* model: 'claude-3-5-sonnet-20241022',
|
||||
* max_tokens: 1024,
|
||||
* messages: [{ role: 'user', content: 'What is 2+2?' }],
|
||||
* output_format: zodOutputFormat(z.object({ answer: z.number() }), 'math'),
|
||||
* });
|
||||
*
|
||||
* console.log(message.parsed_output?.answer); // 4
|
||||
* ```
|
||||
*/
|
||||
parse(params, options) {
|
||||
options = {
|
||||
...options,
|
||||
headers: buildHeaders([
|
||||
{ 'anthropic-beta': [...(params.betas ?? []), 'structured-outputs-2025-12-15'].toString() },
|
||||
options?.headers,
|
||||
]),
|
||||
};
|
||||
return this.create(params, options).then((message) => parseBetaMessage(message, params, { logger: this._client.logger ?? console }));
|
||||
}
|
||||
/**
|
||||
* Create a Message stream
|
||||
*/
|
||||
stream(body, options) {
|
||||
return BetaMessageStream.createMessage(this, body, options);
|
||||
}
|
||||
/**
|
||||
* Count the number of tokens in a Message.
|
||||
*
|
||||
* The Token Count API can be used to count the number of tokens in a Message,
|
||||
* including tools, images, and documents, without creating it.
|
||||
*
|
||||
* Learn more about token counting in our
|
||||
* [user guide](https://docs.claude.com/en/docs/build-with-claude/token-counting)
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const betaMessageTokensCount =
|
||||
* await client.beta.messages.countTokens({
|
||||
* messages: [{ content: 'string', role: 'user' }],
|
||||
* model: 'claude-opus-4-6',
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
countTokens(params, options) {
|
||||
// Transform deprecated output_format to output_config.format
|
||||
const modifiedParams = transformOutputFormat(params);
|
||||
const { betas, ...body } = modifiedParams;
|
||||
return this._client.post('/v1/messages/count_tokens?beta=true', {
|
||||
body,
|
||||
...options,
|
||||
headers: buildHeaders([
|
||||
{ 'anthropic-beta': [...(betas ?? []), 'token-counting-2024-11-01'].toString() },
|
||||
options?.headers,
|
||||
]),
|
||||
});
|
||||
}
|
||||
toolRunner(body, options) {
|
||||
return new BetaToolRunner(this._client, body, options);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Transform deprecated output_format to output_config.format
|
||||
* Returns a modified copy of the params without mutating the original
|
||||
*/
|
||||
function transformOutputFormat(params) {
|
||||
if (!params.output_format) {
|
||||
return params;
|
||||
}
|
||||
if (params.output_config?.format) {
|
||||
throw new AnthropicError('Both output_format and output_config.format were provided. ' +
|
||||
'Please use only output_config.format (output_format is deprecated).');
|
||||
}
|
||||
const { output_format, ...rest } = params;
|
||||
return {
|
||||
...rest,
|
||||
output_config: {
|
||||
...params.output_config,
|
||||
format: output_format,
|
||||
},
|
||||
};
|
||||
}
|
||||
export { BetaToolRunner } from "../../../lib/tools/BetaToolRunner.mjs";
|
||||
export { ToolError } from "../../../lib/tools/ToolError.mjs";
|
||||
Messages.Batches = Batches;
|
||||
Messages.BetaToolRunner = BetaToolRunner;
|
||||
Messages.ToolError = ToolError;
|
||||
//# sourceMappingURL=messages.mjs.map
|
||||
56
extracted-source/node_modules/@anthropic-ai/sdk/resources/beta/models.mjs
generated
vendored
Normal file
56
extracted-source/node_modules/@anthropic-ai/sdk/resources/beta/models.mjs
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
||||
import { APIResource } from "../../core/resource.mjs";
|
||||
import { Page } from "../../core/pagination.mjs";
|
||||
import { buildHeaders } from "../../internal/headers.mjs";
|
||||
import { path } from "../../internal/utils/path.mjs";
|
||||
export class Models extends APIResource {
|
||||
/**
|
||||
* Get a specific model.
|
||||
*
|
||||
* The Models API response can be used to determine information about a specific
|
||||
* model or resolve a model alias to a model ID.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const betaModelInfo = await client.beta.models.retrieve(
|
||||
* 'model_id',
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
retrieve(modelID, params = {}, options) {
|
||||
const { betas } = params ?? {};
|
||||
return this._client.get(path `/v1/models/${modelID}?beta=true`, {
|
||||
...options,
|
||||
headers: buildHeaders([
|
||||
{ ...(betas?.toString() != null ? { 'anthropic-beta': betas?.toString() } : undefined) },
|
||||
options?.headers,
|
||||
]),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* List available models.
|
||||
*
|
||||
* The Models API response can be used to determine which models are available for
|
||||
* use in the API. More recently released models are listed first.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* // Automatically fetches more pages as needed.
|
||||
* for await (const betaModelInfo of client.beta.models.list()) {
|
||||
* // ...
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
list(params = {}, options) {
|
||||
const { betas, ...query } = params ?? {};
|
||||
return this._client.getAPIList('/v1/models?beta=true', (Page), {
|
||||
query,
|
||||
...options,
|
||||
headers: buildHeaders([
|
||||
{ ...(betas?.toString() != null ? { 'anthropic-beta': betas?.toString() } : undefined) },
|
||||
options?.headers,
|
||||
]),
|
||||
});
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=models.mjs.map
|
||||
93
extracted-source/node_modules/@anthropic-ai/sdk/resources/beta/skills/skills.mjs
generated
vendored
Normal file
93
extracted-source/node_modules/@anthropic-ai/sdk/resources/beta/skills/skills.mjs
generated
vendored
Normal file
@@ -0,0 +1,93 @@
|
||||
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
||||
import { APIResource } from "../../../core/resource.mjs";
|
||||
import * as VersionsAPI from "./versions.mjs";
|
||||
import { Versions, } from "./versions.mjs";
|
||||
import { PageCursor } from "../../../core/pagination.mjs";
|
||||
import { buildHeaders } from "../../../internal/headers.mjs";
|
||||
import { multipartFormRequestOptions } from "../../../internal/uploads.mjs";
|
||||
import { path } from "../../../internal/utils/path.mjs";
|
||||
export class Skills extends APIResource {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.versions = new VersionsAPI.Versions(this._client);
|
||||
}
|
||||
/**
|
||||
* Create Skill
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const skill = await client.beta.skills.create();
|
||||
* ```
|
||||
*/
|
||||
create(params = {}, options) {
|
||||
const { betas, ...body } = params ?? {};
|
||||
return this._client.post('/v1/skills?beta=true', multipartFormRequestOptions({
|
||||
body,
|
||||
...options,
|
||||
headers: buildHeaders([
|
||||
{ 'anthropic-beta': [...(betas ?? []), 'skills-2025-10-02'].toString() },
|
||||
options?.headers,
|
||||
]),
|
||||
}, this._client, false));
|
||||
}
|
||||
/**
|
||||
* Get Skill
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const skill = await client.beta.skills.retrieve('skill_id');
|
||||
* ```
|
||||
*/
|
||||
retrieve(skillID, params = {}, options) {
|
||||
const { betas } = params ?? {};
|
||||
return this._client.get(path `/v1/skills/${skillID}?beta=true`, {
|
||||
...options,
|
||||
headers: buildHeaders([
|
||||
{ 'anthropic-beta': [...(betas ?? []), 'skills-2025-10-02'].toString() },
|
||||
options?.headers,
|
||||
]),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* List Skills
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* // Automatically fetches more pages as needed.
|
||||
* for await (const skillListResponse of client.beta.skills.list()) {
|
||||
* // ...
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
list(params = {}, options) {
|
||||
const { betas, ...query } = params ?? {};
|
||||
return this._client.getAPIList('/v1/skills?beta=true', (PageCursor), {
|
||||
query,
|
||||
...options,
|
||||
headers: buildHeaders([
|
||||
{ 'anthropic-beta': [...(betas ?? []), 'skills-2025-10-02'].toString() },
|
||||
options?.headers,
|
||||
]),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Delete Skill
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const skill = await client.beta.skills.delete('skill_id');
|
||||
* ```
|
||||
*/
|
||||
delete(skillID, params = {}, options) {
|
||||
const { betas } = params ?? {};
|
||||
return this._client.delete(path `/v1/skills/${skillID}?beta=true`, {
|
||||
...options,
|
||||
headers: buildHeaders([
|
||||
{ 'anthropic-beta': [...(betas ?? []), 'skills-2025-10-02'].toString() },
|
||||
options?.headers,
|
||||
]),
|
||||
});
|
||||
}
|
||||
}
|
||||
Skills.Versions = Versions;
|
||||
//# sourceMappingURL=skills.mjs.map
|
||||
96
extracted-source/node_modules/@anthropic-ai/sdk/resources/beta/skills/versions.mjs
generated
vendored
Normal file
96
extracted-source/node_modules/@anthropic-ai/sdk/resources/beta/skills/versions.mjs
generated
vendored
Normal file
@@ -0,0 +1,96 @@
|
||||
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
||||
import { APIResource } from "../../../core/resource.mjs";
|
||||
import { PageCursor } from "../../../core/pagination.mjs";
|
||||
import { buildHeaders } from "../../../internal/headers.mjs";
|
||||
import { multipartFormRequestOptions } from "../../../internal/uploads.mjs";
|
||||
import { path } from "../../../internal/utils/path.mjs";
|
||||
export class Versions extends APIResource {
|
||||
/**
|
||||
* Create Skill Version
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const version = await client.beta.skills.versions.create(
|
||||
* 'skill_id',
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
create(skillID, params = {}, options) {
|
||||
const { betas, ...body } = params ?? {};
|
||||
return this._client.post(path `/v1/skills/${skillID}/versions?beta=true`, multipartFormRequestOptions({
|
||||
body,
|
||||
...options,
|
||||
headers: buildHeaders([
|
||||
{ 'anthropic-beta': [...(betas ?? []), 'skills-2025-10-02'].toString() },
|
||||
options?.headers,
|
||||
]),
|
||||
}, this._client));
|
||||
}
|
||||
/**
|
||||
* Get Skill Version
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const version = await client.beta.skills.versions.retrieve(
|
||||
* 'version',
|
||||
* { skill_id: 'skill_id' },
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
retrieve(version, params, options) {
|
||||
const { skill_id, betas } = params;
|
||||
return this._client.get(path `/v1/skills/${skill_id}/versions/${version}?beta=true`, {
|
||||
...options,
|
||||
headers: buildHeaders([
|
||||
{ 'anthropic-beta': [...(betas ?? []), 'skills-2025-10-02'].toString() },
|
||||
options?.headers,
|
||||
]),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* List Skill Versions
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* // Automatically fetches more pages as needed.
|
||||
* for await (const versionListResponse of client.beta.skills.versions.list(
|
||||
* 'skill_id',
|
||||
* )) {
|
||||
* // ...
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
list(skillID, params = {}, options) {
|
||||
const { betas, ...query } = params ?? {};
|
||||
return this._client.getAPIList(path `/v1/skills/${skillID}/versions?beta=true`, (PageCursor), {
|
||||
query,
|
||||
...options,
|
||||
headers: buildHeaders([
|
||||
{ 'anthropic-beta': [...(betas ?? []), 'skills-2025-10-02'].toString() },
|
||||
options?.headers,
|
||||
]),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Delete Skill Version
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const version = await client.beta.skills.versions.delete(
|
||||
* 'version',
|
||||
* { skill_id: 'skill_id' },
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
delete(version, params, options) {
|
||||
const { skill_id, betas } = params;
|
||||
return this._client.delete(path `/v1/skills/${skill_id}/versions/${version}?beta=true`, {
|
||||
...options,
|
||||
headers: buildHeaders([
|
||||
{ 'anthropic-beta': [...(betas ?? []), 'skills-2025-10-02'].toString() },
|
||||
options?.headers,
|
||||
]),
|
||||
});
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=versions.mjs.map
|
||||
19
extracted-source/node_modules/@anthropic-ai/sdk/resources/completions.mjs
generated
vendored
Normal file
19
extracted-source/node_modules/@anthropic-ai/sdk/resources/completions.mjs
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
||||
import { APIResource } from "../core/resource.mjs";
|
||||
import { buildHeaders } from "../internal/headers.mjs";
|
||||
export class Completions extends APIResource {
|
||||
create(params, options) {
|
||||
const { betas, ...body } = params;
|
||||
return this._client.post('/v1/complete', {
|
||||
body,
|
||||
timeout: this._client._options.timeout ?? 600000,
|
||||
...options,
|
||||
headers: buildHeaders([
|
||||
{ ...(betas?.toString() != null ? { 'anthropic-beta': betas?.toString() } : undefined) },
|
||||
options?.headers,
|
||||
]),
|
||||
stream: params.stream ?? false,
|
||||
});
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=completions.mjs.map
|
||||
7
extracted-source/node_modules/@anthropic-ai/sdk/resources/index.mjs
generated
vendored
Normal file
7
extracted-source/node_modules/@anthropic-ai/sdk/resources/index.mjs
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
||||
export * from "./shared.mjs";
|
||||
export { Beta, } from "./beta/beta.mjs";
|
||||
export { Completions, } from "./completions.mjs";
|
||||
export { Messages, } from "./messages/messages.mjs";
|
||||
export { Models, } from "./models.mjs";
|
||||
//# sourceMappingURL=index.mjs.map
|
||||
149
extracted-source/node_modules/@anthropic-ai/sdk/resources/messages/batches.mjs
generated
vendored
Normal file
149
extracted-source/node_modules/@anthropic-ai/sdk/resources/messages/batches.mjs
generated
vendored
Normal file
@@ -0,0 +1,149 @@
|
||||
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
||||
import { APIResource } from "../../core/resource.mjs";
|
||||
import { Page } from "../../core/pagination.mjs";
|
||||
import { buildHeaders } from "../../internal/headers.mjs";
|
||||
import { JSONLDecoder } from "../../internal/decoders/jsonl.mjs";
|
||||
import { AnthropicError } from "../../error.mjs";
|
||||
import { path } from "../../internal/utils/path.mjs";
|
||||
export class Batches extends APIResource {
|
||||
/**
|
||||
* Send a batch of Message creation requests.
|
||||
*
|
||||
* The Message Batches API can be used to process multiple Messages API requests at
|
||||
* once. Once a Message Batch is created, it begins processing immediately. Batches
|
||||
* can take up to 24 hours to complete.
|
||||
*
|
||||
* Learn more about the Message Batches API in our
|
||||
* [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const messageBatch = await client.messages.batches.create({
|
||||
* requests: [
|
||||
* {
|
||||
* custom_id: 'my-custom-id-1',
|
||||
* params: {
|
||||
* max_tokens: 1024,
|
||||
* messages: [
|
||||
* { content: 'Hello, world', role: 'user' },
|
||||
* ],
|
||||
* model: 'claude-opus-4-6',
|
||||
* },
|
||||
* },
|
||||
* ],
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
create(body, options) {
|
||||
return this._client.post('/v1/messages/batches', { body, ...options });
|
||||
}
|
||||
/**
|
||||
* This endpoint is idempotent and can be used to poll for Message Batch
|
||||
* completion. To access the results of a Message Batch, make a request to the
|
||||
* `results_url` field in the response.
|
||||
*
|
||||
* Learn more about the Message Batches API in our
|
||||
* [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const messageBatch = await client.messages.batches.retrieve(
|
||||
* 'message_batch_id',
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
retrieve(messageBatchID, options) {
|
||||
return this._client.get(path `/v1/messages/batches/${messageBatchID}`, options);
|
||||
}
|
||||
/**
|
||||
* List all Message Batches within a Workspace. Most recently created batches are
|
||||
* returned first.
|
||||
*
|
||||
* Learn more about the Message Batches API in our
|
||||
* [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* // Automatically fetches more pages as needed.
|
||||
* for await (const messageBatch of client.messages.batches.list()) {
|
||||
* // ...
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
list(query = {}, options) {
|
||||
return this._client.getAPIList('/v1/messages/batches', (Page), { query, ...options });
|
||||
}
|
||||
/**
|
||||
* Delete a Message Batch.
|
||||
*
|
||||
* Message Batches can only be deleted once they've finished processing. If you'd
|
||||
* like to delete an in-progress batch, you must first cancel it.
|
||||
*
|
||||
* Learn more about the Message Batches API in our
|
||||
* [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const deletedMessageBatch =
|
||||
* await client.messages.batches.delete('message_batch_id');
|
||||
* ```
|
||||
*/
|
||||
delete(messageBatchID, options) {
|
||||
return this._client.delete(path `/v1/messages/batches/${messageBatchID}`, options);
|
||||
}
|
||||
/**
|
||||
* Batches may be canceled any time before processing ends. Once cancellation is
|
||||
* initiated, the batch enters a `canceling` state, at which time the system may
|
||||
* complete any in-progress, non-interruptible requests before finalizing
|
||||
* cancellation.
|
||||
*
|
||||
* The number of canceled requests is specified in `request_counts`. To determine
|
||||
* which requests were canceled, check the individual results within the batch.
|
||||
* Note that cancellation may not result in any canceled requests if they were
|
||||
* non-interruptible.
|
||||
*
|
||||
* Learn more about the Message Batches API in our
|
||||
* [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const messageBatch = await client.messages.batches.cancel(
|
||||
* 'message_batch_id',
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
cancel(messageBatchID, options) {
|
||||
return this._client.post(path `/v1/messages/batches/${messageBatchID}/cancel`, options);
|
||||
}
|
||||
/**
|
||||
* Streams the results of a Message Batch as a `.jsonl` file.
|
||||
*
|
||||
* Each line in the file is a JSON object containing the result of a single request
|
||||
* in the Message Batch. Results are not guaranteed to be in the same order as
|
||||
* requests. Use the `custom_id` field to match results to requests.
|
||||
*
|
||||
* Learn more about the Message Batches API in our
|
||||
* [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const messageBatchIndividualResponse =
|
||||
* await client.messages.batches.results('message_batch_id');
|
||||
* ```
|
||||
*/
|
||||
async results(messageBatchID, options) {
|
||||
const batch = await this.retrieve(messageBatchID);
|
||||
if (!batch.results_url) {
|
||||
throw new AnthropicError(`No batch \`results_url\`; Has it finished processing? ${batch.processing_status} - ${batch.id}`);
|
||||
}
|
||||
return this._client
|
||||
.get(batch.results_url, {
|
||||
...options,
|
||||
headers: buildHeaders([{ Accept: 'application/binary' }, options?.headers]),
|
||||
stream: true,
|
||||
__binaryResponse: true,
|
||||
})
|
||||
._thenUnwrap((_, props) => JSONLDecoder.fromResponse(props.response, props.controller));
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=batches.mjs.map
|
||||
123
extracted-source/node_modules/@anthropic-ai/sdk/resources/messages/messages.mjs
generated
vendored
Normal file
123
extracted-source/node_modules/@anthropic-ai/sdk/resources/messages/messages.mjs
generated
vendored
Normal file
@@ -0,0 +1,123 @@
|
||||
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
||||
import { APIResource } from "../../core/resource.mjs";
|
||||
import { buildHeaders } from "../../internal/headers.mjs";
|
||||
import { stainlessHelperHeader } from "../../lib/stainless-helper-header.mjs";
|
||||
import { MessageStream } from "../../lib/MessageStream.mjs";
|
||||
import { parseMessage, } from "../../lib/parser.mjs";
|
||||
import * as BatchesAPI from "./batches.mjs";
|
||||
import { Batches, } from "./batches.mjs";
|
||||
import { MODEL_NONSTREAMING_TOKENS } from "../../internal/constants.mjs";
|
||||
export class Messages extends APIResource {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.batches = new BatchesAPI.Batches(this._client);
|
||||
}
|
||||
create(body, options) {
|
||||
if (body.model in DEPRECATED_MODELS) {
|
||||
console.warn(`The model '${body.model}' is deprecated and will reach end-of-life on ${DEPRECATED_MODELS[body.model]}\nPlease migrate to a newer model. Visit https://docs.anthropic.com/en/docs/resources/model-deprecations for more information.`);
|
||||
}
|
||||
if (body.model in MODELS_TO_WARN_WITH_THINKING_ENABLED &&
|
||||
body.thinking &&
|
||||
body.thinking.type === 'enabled') {
|
||||
console.warn(`Using Claude with ${body.model} and 'thinking.type=enabled' is deprecated. Use 'thinking.type=adaptive' instead which results in better model performance in our testing: https://platform.claude.com/docs/en/build-with-claude/adaptive-thinking`);
|
||||
}
|
||||
let timeout = this._client._options.timeout;
|
||||
if (!body.stream && timeout == null) {
|
||||
const maxNonstreamingTokens = MODEL_NONSTREAMING_TOKENS[body.model] ?? undefined;
|
||||
timeout = this._client.calculateNonstreamingTimeout(body.max_tokens, maxNonstreamingTokens);
|
||||
}
|
||||
// Collect helper info from tools and messages
|
||||
const helperHeader = stainlessHelperHeader(body.tools, body.messages);
|
||||
return this._client.post('/v1/messages', {
|
||||
body,
|
||||
timeout: timeout ?? 600000,
|
||||
...options,
|
||||
headers: buildHeaders([helperHeader, options?.headers]),
|
||||
stream: body.stream ?? false,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Send a structured list of input messages with text and/or image content, along with an expected `output_config.format` and
|
||||
* the response will be automatically parsed and available in the `parsed_output` property of the message.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const message = await client.messages.parse({
|
||||
* model: 'claude-sonnet-4-5-20250929',
|
||||
* max_tokens: 1024,
|
||||
* messages: [{ role: 'user', content: 'What is 2+2?' }],
|
||||
* output_config: {
|
||||
* format: zodOutputFormat(z.object({ answer: z.number() })),
|
||||
* },
|
||||
* });
|
||||
*
|
||||
* console.log(message.parsed_output?.answer); // 4
|
||||
* ```
|
||||
*/
|
||||
parse(params, options) {
|
||||
return this.create(params, options).then((message) => parseMessage(message, params, { logger: this._client.logger ?? console }));
|
||||
}
|
||||
/**
|
||||
* Create a Message stream.
|
||||
*
|
||||
* If `output_config.format` is provided with a parseable format (like `zodOutputFormat()`),
|
||||
* the final message will include a `parsed_output` property with the parsed content.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const stream = client.messages.stream({
|
||||
* model: 'claude-sonnet-4-5-20250929',
|
||||
* max_tokens: 1024,
|
||||
* messages: [{ role: 'user', content: 'What is 2+2?' }],
|
||||
* output_config: {
|
||||
* format: zodOutputFormat(z.object({ answer: z.number() })),
|
||||
* },
|
||||
* });
|
||||
*
|
||||
* const message = await stream.finalMessage();
|
||||
* console.log(message.parsed_output?.answer); // 4
|
||||
* ```
|
||||
*/
|
||||
stream(body, options) {
|
||||
return MessageStream.createMessage(this, body, options, { logger: this._client.logger ?? console });
|
||||
}
|
||||
/**
|
||||
* Count the number of tokens in a Message.
|
||||
*
|
||||
* The Token Count API can be used to count the number of tokens in a Message,
|
||||
* including tools, images, and documents, without creating it.
|
||||
*
|
||||
* Learn more about token counting in our
|
||||
* [user guide](https://docs.claude.com/en/docs/build-with-claude/token-counting)
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const messageTokensCount =
|
||||
* await client.messages.countTokens({
|
||||
* messages: [{ content: 'string', role: 'user' }],
|
||||
* model: 'claude-opus-4-6',
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
countTokens(body, options) {
|
||||
return this._client.post('/v1/messages/count_tokens', { body, ...options });
|
||||
}
|
||||
}
|
||||
const DEPRECATED_MODELS = {
|
||||
'claude-1.3': 'November 6th, 2024',
|
||||
'claude-1.3-100k': 'November 6th, 2024',
|
||||
'claude-instant-1.1': 'November 6th, 2024',
|
||||
'claude-instant-1.1-100k': 'November 6th, 2024',
|
||||
'claude-instant-1.2': 'November 6th, 2024',
|
||||
'claude-3-sonnet-20240229': 'July 21st, 2025',
|
||||
'claude-3-opus-20240229': 'January 5th, 2026',
|
||||
'claude-2.1': 'July 21st, 2025',
|
||||
'claude-2.0': 'July 21st, 2025',
|
||||
'claude-3-7-sonnet-latest': 'February 19th, 2026',
|
||||
'claude-3-7-sonnet-20250219': 'February 19th, 2026',
|
||||
'claude-3-5-haiku-latest': 'February 19th, 2026',
|
||||
'claude-3-5-haiku-20241022': 'February 19th, 2026',
|
||||
};
|
||||
const MODELS_TO_WARN_WITH_THINKING_ENABLED = ['claude-opus-4-6'];
|
||||
Messages.Batches = Batches;
|
||||
//# sourceMappingURL=messages.mjs.map
|
||||
41
extracted-source/node_modules/@anthropic-ai/sdk/resources/models.mjs
generated
vendored
Normal file
41
extracted-source/node_modules/@anthropic-ai/sdk/resources/models.mjs
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
||||
import { APIResource } from "../core/resource.mjs";
|
||||
import { Page } from "../core/pagination.mjs";
|
||||
import { buildHeaders } from "../internal/headers.mjs";
|
||||
import { path } from "../internal/utils/path.mjs";
|
||||
export class Models extends APIResource {
|
||||
/**
|
||||
* Get a specific model.
|
||||
*
|
||||
* The Models API response can be used to determine information about a specific
|
||||
* model or resolve a model alias to a model ID.
|
||||
*/
|
||||
retrieve(modelID, params = {}, options) {
|
||||
const { betas } = params ?? {};
|
||||
return this._client.get(path `/v1/models/${modelID}`, {
|
||||
...options,
|
||||
headers: buildHeaders([
|
||||
{ ...(betas?.toString() != null ? { 'anthropic-beta': betas?.toString() } : undefined) },
|
||||
options?.headers,
|
||||
]),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* List available models.
|
||||
*
|
||||
* The Models API response can be used to determine which models are available for
|
||||
* use in the API. More recently released models are listed first.
|
||||
*/
|
||||
list(params = {}, options) {
|
||||
const { betas, ...query } = params ?? {};
|
||||
return this._client.getAPIList('/v1/models', (Page), {
|
||||
query,
|
||||
...options,
|
||||
headers: buildHeaders([
|
||||
{ ...(betas?.toString() != null ? { 'anthropic-beta': betas?.toString() } : undefined) },
|
||||
options?.headers,
|
||||
]),
|
||||
});
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=models.mjs.map
|
||||
2
extracted-source/node_modules/@anthropic-ai/sdk/streaming.mjs
generated
vendored
Normal file
2
extracted-source/node_modules/@anthropic-ai/sdk/streaming.mjs
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from "./core/streaming.mjs";
|
||||
//# sourceMappingURL=streaming.mjs.map
|
||||
2
extracted-source/node_modules/@anthropic-ai/sdk/version.mjs
generated
vendored
Normal file
2
extracted-source/node_modules/@anthropic-ai/sdk/version.mjs
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export const VERSION = '0.74.0'; // x-release-please-version
|
||||
//# sourceMappingURL=version.mjs.map
|
||||
Reference in New Issue
Block a user