Spaces:
Paused
Paused
Upload folder using huggingface_hub (part 10)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/index.ts +23 -0
- node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/internal/README.md +3 -0
- node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/internal/builtin-types.ts +93 -0
- node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/internal/constants.ts +12 -0
- node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/internal/decoders/jsonl.ts +48 -0
- node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/internal/decoders/line.ts +135 -0
- node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/internal/detect-platform.ts +196 -0
- node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/internal/errors.ts +33 -0
- node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/internal/headers.ts +99 -0
- node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/internal/parse.ts +84 -0
- node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/internal/request-options.ts +93 -0
- node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/internal/shim-types.ts +26 -0
- node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/internal/shims.ts +107 -0
- node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/internal/stream-utils.ts +32 -0
- node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/internal/to-file.ts +159 -0
- node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/internal/types.ts +95 -0
- node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/internal/uploads.ts +193 -0
- node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/internal/utils.ts +8 -0
- node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/internal/utils/base64.ts +40 -0
- node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/internal/utils/bytes.ts +32 -0
- node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/internal/utils/env.ts +18 -0
- node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/internal/utils/log.ts +127 -0
- node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/internal/utils/path.ts +88 -0
- node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/internal/utils/sleep.ts +3 -0
- node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/internal/utils/uuid.ts +17 -0
- node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/internal/utils/values.ts +105 -0
- node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/lib/.keep +4 -0
- node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/lib/BetaMessageStream.ts +727 -0
- node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/lib/MessageStream.ts +720 -0
- node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/pagination.ts +2 -0
- node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/resource.ts +2 -0
- node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/resources.ts +1 -0
- node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/resources/beta.ts +3 -0
- node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/resources/beta/beta.ts +388 -0
- node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/resources/beta/files.ts +258 -0
- node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/resources/beta/index.ts +152 -0
- node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/resources/beta/messages.ts +3 -0
- node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/resources/beta/messages/batches.ts +502 -0
- node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/resources/beta/messages/index.ts +139 -0
- node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/resources/beta/messages/messages.ts +2330 -0
- node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/resources/beta/models.ts +118 -0
- node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/resources/completions.ts +231 -0
- node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/resources/index.ts +121 -0
- node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/resources/messages.ts +3 -0
- node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/resources/messages/batches.ts +396 -0
- node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/resources/messages/index.ts +110 -0
- node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/resources/messages/messages.ts +1848 -0
- node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/resources/models.ts +103 -0
- node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/resources/shared.ts +72 -0
- node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/resources/top-level.ts +3 -0
node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/index.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
| 2 |
+
|
| 3 |
+
export { Anthropic as default } from './client';
|
| 4 |
+
|
| 5 |
+
export { type Uploadable, toFile } from './core/uploads';
|
| 6 |
+
export { APIPromise } from './core/api-promise';
|
| 7 |
+
export { BaseAnthropic, Anthropic, type ClientOptions, HUMAN_PROMPT, AI_PROMPT } from './client';
|
| 8 |
+
export { PagePromise } from './core/pagination';
|
| 9 |
+
export {
|
| 10 |
+
AnthropicError,
|
| 11 |
+
APIError,
|
| 12 |
+
APIConnectionError,
|
| 13 |
+
APIConnectionTimeoutError,
|
| 14 |
+
APIUserAbortError,
|
| 15 |
+
NotFoundError,
|
| 16 |
+
ConflictError,
|
| 17 |
+
RateLimitError,
|
| 18 |
+
BadRequestError,
|
| 19 |
+
AuthenticationError,
|
| 20 |
+
InternalServerError,
|
| 21 |
+
PermissionDeniedError,
|
| 22 |
+
UnprocessableEntityError,
|
| 23 |
+
} from './core/error';
|
node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/internal/README.md
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# `internal`
|
| 2 |
+
|
| 3 |
+
The modules in this directory are not importable outside this package and will change between releases.
|
node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/internal/builtin-types.ts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
| 2 |
+
|
| 3 |
+
export type Fetch = (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
|
| 4 |
+
|
| 5 |
+
/**
|
| 6 |
+
* An alias to the builtin `RequestInit` type so we can
|
| 7 |
+
* easily alias it in import statements if there are name clashes.
|
| 8 |
+
*
|
| 9 |
+
* https://developer.mozilla.org/docs/Web/API/RequestInit
|
| 10 |
+
*/
|
| 11 |
+
type _RequestInit = RequestInit;
|
| 12 |
+
|
| 13 |
+
/**
|
| 14 |
+
* An alias to the builtin `Response` type so we can
|
| 15 |
+
* easily alias it in import statements if there are name clashes.
|
| 16 |
+
*
|
| 17 |
+
* https://developer.mozilla.org/docs/Web/API/Response
|
| 18 |
+
*/
|
| 19 |
+
type _Response = Response;
|
| 20 |
+
|
| 21 |
+
/**
|
| 22 |
+
* The type for the first argument to `fetch`.
|
| 23 |
+
*
|
| 24 |
+
* https://developer.mozilla.org/docs/Web/API/Window/fetch#resource
|
| 25 |
+
*/
|
| 26 |
+
type _RequestInfo = Request | URL | string;
|
| 27 |
+
|
| 28 |
+
/**
|
| 29 |
+
* The type for constructing `RequestInit` Headers.
|
| 30 |
+
*
|
| 31 |
+
* https://developer.mozilla.org/docs/Web/API/RequestInit#setting_headers
|
| 32 |
+
*/
|
| 33 |
+
type _HeadersInit = RequestInit['headers'];
|
| 34 |
+
|
| 35 |
+
/**
|
| 36 |
+
* The type for constructing `RequestInit` body.
|
| 37 |
+
*
|
| 38 |
+
* https://developer.mozilla.org/docs/Web/API/RequestInit#body
|
| 39 |
+
*/
|
| 40 |
+
type _BodyInit = RequestInit['body'];
|
| 41 |
+
|
| 42 |
+
/**
|
| 43 |
+
* An alias to the builtin `Array<T>` type so we can
|
| 44 |
+
* easily alias it in import statements if there are name clashes.
|
| 45 |
+
*/
|
| 46 |
+
type _Array<T> = Array<T>;
|
| 47 |
+
|
| 48 |
+
/**
|
| 49 |
+
* An alias to the builtin `Record<K, T>` type so we can
|
| 50 |
+
* easily alias it in import statements if there are name clashes.
|
| 51 |
+
*/
|
| 52 |
+
type _Record<K extends keyof any, T> = Record<K, T>;
|
| 53 |
+
|
| 54 |
+
export type {
|
| 55 |
+
_Array as Array,
|
| 56 |
+
_BodyInit as BodyInit,
|
| 57 |
+
_HeadersInit as HeadersInit,
|
| 58 |
+
_Record as Record,
|
| 59 |
+
_RequestInfo as RequestInfo,
|
| 60 |
+
_RequestInit as RequestInit,
|
| 61 |
+
_Response as Response,
|
| 62 |
+
};
|
| 63 |
+
|
| 64 |
+
/**
|
| 65 |
+
* A copy of the builtin `EndingType` type as it isn't fully supported in certain
|
| 66 |
+
* environments and attempting to reference the global version will error.
|
| 67 |
+
*
|
| 68 |
+
* https://github.com/microsoft/TypeScript/blob/49ad1a3917a0ea57f5ff248159256e12bb1cb705/src/lib/dom.generated.d.ts#L27941
|
| 69 |
+
*/
|
| 70 |
+
type EndingType = 'native' | 'transparent';
|
| 71 |
+
|
| 72 |
+
/**
|
| 73 |
+
* A copy of the builtin `BlobPropertyBag` type as it isn't fully supported in certain
|
| 74 |
+
* environments and attempting to reference the global version will error.
|
| 75 |
+
*
|
| 76 |
+
* https://github.com/microsoft/TypeScript/blob/49ad1a3917a0ea57f5ff248159256e12bb1cb705/src/lib/dom.generated.d.ts#L154
|
| 77 |
+
* https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob#options
|
| 78 |
+
*/
|
| 79 |
+
export interface BlobPropertyBag {
|
| 80 |
+
endings?: EndingType;
|
| 81 |
+
type?: string;
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
/**
|
| 85 |
+
* A copy of the builtin `FilePropertyBag` type as it isn't fully supported in certain
|
| 86 |
+
* environments and attempting to reference the global version will error.
|
| 87 |
+
*
|
| 88 |
+
* https://github.com/microsoft/TypeScript/blob/49ad1a3917a0ea57f5ff248159256e12bb1cb705/src/lib/dom.generated.d.ts#L503
|
| 89 |
+
* https://developer.mozilla.org/en-US/docs/Web/API/File/File#options
|
| 90 |
+
*/
|
| 91 |
+
export interface FilePropertyBag extends BlobPropertyBag {
|
| 92 |
+
lastModified?: number;
|
| 93 |
+
}
|
node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/internal/constants.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// File containing shared constants
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* Model-specific timeout constraints for non-streaming requests
|
| 5 |
+
*/
|
| 6 |
+
export const MODEL_NONSTREAMING_TOKENS: Record<string, number> = {
|
| 7 |
+
'claude-opus-4-20250514': 8192,
|
| 8 |
+
'claude-opus-4-0': 8192,
|
| 9 |
+
'claude-4-opus-20250514': 8192,
|
| 10 |
+
'anthropic.claude-opus-4-20250514-v1:0': 8192,
|
| 11 |
+
'claude-opus-4@20250514': 8192,
|
| 12 |
+
};
|
node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/internal/decoders/jsonl.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { AnthropicError } from '../../core/error';
|
| 2 |
+
import { ReadableStreamToAsyncIterable } from '../shims';
|
| 3 |
+
import { LineDecoder, type Bytes } from './line';
|
| 4 |
+
|
| 5 |
+
export class JSONLDecoder<T> {
|
| 6 |
+
controller: AbortController;
|
| 7 |
+
|
| 8 |
+
constructor(
|
| 9 |
+
private iterator: AsyncIterableIterator<Bytes>,
|
| 10 |
+
controller: AbortController,
|
| 11 |
+
) {
|
| 12 |
+
this.controller = controller;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
private async *decoder(): AsyncIterator<T, any, undefined> {
|
| 16 |
+
const lineDecoder = new LineDecoder();
|
| 17 |
+
for await (const chunk of this.iterator) {
|
| 18 |
+
for (const line of lineDecoder.decode(chunk)) {
|
| 19 |
+
yield JSON.parse(line);
|
| 20 |
+
}
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
for (const line of lineDecoder.flush()) {
|
| 24 |
+
yield JSON.parse(line);
|
| 25 |
+
}
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
[Symbol.asyncIterator](): AsyncIterator<T> {
|
| 29 |
+
return this.decoder();
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
static fromResponse<T>(response: Response, controller: AbortController): JSONLDecoder<T> {
|
| 33 |
+
if (!response.body) {
|
| 34 |
+
controller.abort();
|
| 35 |
+
if (
|
| 36 |
+
typeof (globalThis as any).navigator !== 'undefined' &&
|
| 37 |
+
(globalThis as any).navigator.product === 'ReactNative'
|
| 38 |
+
) {
|
| 39 |
+
throw new AnthropicError(
|
| 40 |
+
`The default react-native fetch implementation does not support streaming. Please use expo/fetch: https://docs.expo.dev/versions/latest/sdk/expo/#expofetch-api`,
|
| 41 |
+
);
|
| 42 |
+
}
|
| 43 |
+
throw new AnthropicError(`Attempted to iterate over a response with no body`);
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
return new JSONLDecoder(ReadableStreamToAsyncIterable<Bytes>(response.body), controller);
|
| 47 |
+
}
|
| 48 |
+
}
|
node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/internal/decoders/line.ts
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { concatBytes, decodeUTF8, encodeUTF8 } from '../utils/bytes';
|
| 2 |
+
|
| 3 |
+
export type Bytes = string | ArrayBuffer | Uint8Array | null | undefined;
|
| 4 |
+
|
| 5 |
+
/**
|
| 6 |
+
* A re-implementation of httpx's `LineDecoder` in Python that handles incrementally
|
| 7 |
+
* reading lines from text.
|
| 8 |
+
*
|
| 9 |
+
* https://github.com/encode/httpx/blob/920333ea98118e9cf617f246905d7b202510941c/httpx/_decoders.py#L258
|
| 10 |
+
*/
|
| 11 |
+
export class LineDecoder {
|
| 12 |
+
// prettier-ignore
|
| 13 |
+
static NEWLINE_CHARS = new Set(['\n', '\r']);
|
| 14 |
+
static NEWLINE_REGEXP = /\r\n|[\n\r]/g;
|
| 15 |
+
|
| 16 |
+
#buffer: Uint8Array;
|
| 17 |
+
#carriageReturnIndex: number | null;
|
| 18 |
+
|
| 19 |
+
constructor() {
|
| 20 |
+
this.#buffer = new Uint8Array();
|
| 21 |
+
this.#carriageReturnIndex = null;
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
decode(chunk: Bytes): string[] {
|
| 25 |
+
if (chunk == null) {
|
| 26 |
+
return [];
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
const binaryChunk =
|
| 30 |
+
chunk instanceof ArrayBuffer ? new Uint8Array(chunk)
|
| 31 |
+
: typeof chunk === 'string' ? encodeUTF8(chunk)
|
| 32 |
+
: chunk;
|
| 33 |
+
|
| 34 |
+
this.#buffer = concatBytes([this.#buffer, binaryChunk]);
|
| 35 |
+
|
| 36 |
+
const lines: string[] = [];
|
| 37 |
+
let patternIndex;
|
| 38 |
+
while ((patternIndex = findNewlineIndex(this.#buffer, this.#carriageReturnIndex)) != null) {
|
| 39 |
+
if (patternIndex.carriage && this.#carriageReturnIndex == null) {
|
| 40 |
+
// skip until we either get a corresponding `\n`, a new `\r` or nothing
|
| 41 |
+
this.#carriageReturnIndex = patternIndex.index;
|
| 42 |
+
continue;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
// we got double \r or \rtext\n
|
| 46 |
+
if (
|
| 47 |
+
this.#carriageReturnIndex != null &&
|
| 48 |
+
(patternIndex.index !== this.#carriageReturnIndex + 1 || patternIndex.carriage)
|
| 49 |
+
) {
|
| 50 |
+
lines.push(decodeUTF8(this.#buffer.subarray(0, this.#carriageReturnIndex - 1)));
|
| 51 |
+
this.#buffer = this.#buffer.subarray(this.#carriageReturnIndex);
|
| 52 |
+
this.#carriageReturnIndex = null;
|
| 53 |
+
continue;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
const endIndex =
|
| 57 |
+
this.#carriageReturnIndex !== null ? patternIndex.preceding - 1 : patternIndex.preceding;
|
| 58 |
+
|
| 59 |
+
const line = decodeUTF8(this.#buffer.subarray(0, endIndex));
|
| 60 |
+
lines.push(line);
|
| 61 |
+
|
| 62 |
+
this.#buffer = this.#buffer.subarray(patternIndex.index);
|
| 63 |
+
this.#carriageReturnIndex = null;
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
return lines;
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
flush(): string[] {
|
| 70 |
+
if (!this.#buffer.length) {
|
| 71 |
+
return [];
|
| 72 |
+
}
|
| 73 |
+
return this.decode('\n');
|
| 74 |
+
}
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
/**
|
| 78 |
+
* This function searches the buffer for the end patterns, (\r or \n)
|
| 79 |
+
* and returns an object with the index preceding the matched newline and the
|
| 80 |
+
* index after the newline char. `null` is returned if no new line is found.
|
| 81 |
+
*
|
| 82 |
+
* ```ts
|
| 83 |
+
* findNewLineIndex('abc\ndef') -> { preceding: 2, index: 3 }
|
| 84 |
+
* ```
|
| 85 |
+
*/
|
| 86 |
+
function findNewlineIndex(
|
| 87 |
+
buffer: Uint8Array,
|
| 88 |
+
startIndex: number | null,
|
| 89 |
+
): { preceding: number; index: number; carriage: boolean } | null {
|
| 90 |
+
const newline = 0x0a; // \n
|
| 91 |
+
const carriage = 0x0d; // \r
|
| 92 |
+
|
| 93 |
+
for (let i = startIndex ?? 0; i < buffer.length; i++) {
|
| 94 |
+
if (buffer[i] === newline) {
|
| 95 |
+
return { preceding: i, index: i + 1, carriage: false };
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
if (buffer[i] === carriage) {
|
| 99 |
+
return { preceding: i, index: i + 1, carriage: true };
|
| 100 |
+
}
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
return null;
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
export function findDoubleNewlineIndex(buffer: Uint8Array): number {
|
| 107 |
+
// This function searches the buffer for the end patterns (\r\r, \n\n, \r\n\r\n)
|
| 108 |
+
// and returns the index right after the first occurrence of any pattern,
|
| 109 |
+
// or -1 if none of the patterns are found.
|
| 110 |
+
const newline = 0x0a; // \n
|
| 111 |
+
const carriage = 0x0d; // \r
|
| 112 |
+
|
| 113 |
+
for (let i = 0; i < buffer.length - 1; i++) {
|
| 114 |
+
if (buffer[i] === newline && buffer[i + 1] === newline) {
|
| 115 |
+
// \n\n
|
| 116 |
+
return i + 2;
|
| 117 |
+
}
|
| 118 |
+
if (buffer[i] === carriage && buffer[i + 1] === carriage) {
|
| 119 |
+
// \r\r
|
| 120 |
+
return i + 2;
|
| 121 |
+
}
|
| 122 |
+
if (
|
| 123 |
+
buffer[i] === carriage &&
|
| 124 |
+
buffer[i + 1] === newline &&
|
| 125 |
+
i + 3 < buffer.length &&
|
| 126 |
+
buffer[i + 2] === carriage &&
|
| 127 |
+
buffer[i + 3] === newline
|
| 128 |
+
) {
|
| 129 |
+
// \r\n\r\n
|
| 130 |
+
return i + 4;
|
| 131 |
+
}
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
return -1;
|
| 135 |
+
}
|
node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/internal/detect-platform.ts
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
| 2 |
+
|
| 3 |
+
import { VERSION } from '../version';
|
| 4 |
+
|
| 5 |
+
export const isRunningInBrowser = () => {
|
| 6 |
+
return (
|
| 7 |
+
// @ts-ignore
|
| 8 |
+
typeof window !== 'undefined' &&
|
| 9 |
+
// @ts-ignore
|
| 10 |
+
typeof window.document !== 'undefined' &&
|
| 11 |
+
// @ts-ignore
|
| 12 |
+
typeof navigator !== 'undefined'
|
| 13 |
+
);
|
| 14 |
+
};
|
| 15 |
+
|
| 16 |
+
type DetectedPlatform = 'deno' | 'node' | 'edge' | 'unknown';
|
| 17 |
+
|
| 18 |
+
/**
|
| 19 |
+
* Note this does not detect 'browser'; for that, use getBrowserInfo().
|
| 20 |
+
*/
|
| 21 |
+
function getDetectedPlatform(): DetectedPlatform {
|
| 22 |
+
if (typeof Deno !== 'undefined' && Deno.build != null) {
|
| 23 |
+
return 'deno';
|
| 24 |
+
}
|
| 25 |
+
if (typeof EdgeRuntime !== 'undefined') {
|
| 26 |
+
return 'edge';
|
| 27 |
+
}
|
| 28 |
+
if (
|
| 29 |
+
Object.prototype.toString.call(
|
| 30 |
+
typeof (globalThis as any).process !== 'undefined' ? (globalThis as any).process : 0,
|
| 31 |
+
) === '[object process]'
|
| 32 |
+
) {
|
| 33 |
+
return 'node';
|
| 34 |
+
}
|
| 35 |
+
return 'unknown';
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
declare const Deno: any;
|
| 39 |
+
declare const EdgeRuntime: any;
|
| 40 |
+
type Arch = 'x32' | 'x64' | 'arm' | 'arm64' | `other:${string}` | 'unknown';
|
| 41 |
+
type PlatformName =
|
| 42 |
+
| 'MacOS'
|
| 43 |
+
| 'Linux'
|
| 44 |
+
| 'Windows'
|
| 45 |
+
| 'FreeBSD'
|
| 46 |
+
| 'OpenBSD'
|
| 47 |
+
| 'iOS'
|
| 48 |
+
| 'Android'
|
| 49 |
+
| `Other:${string}`
|
| 50 |
+
| 'Unknown';
|
| 51 |
+
type Browser = 'ie' | 'edge' | 'chrome' | 'firefox' | 'safari';
|
| 52 |
+
type PlatformProperties = {
|
| 53 |
+
'X-Stainless-Lang': 'js';
|
| 54 |
+
'X-Stainless-Package-Version': string;
|
| 55 |
+
'X-Stainless-OS': PlatformName;
|
| 56 |
+
'X-Stainless-Arch': Arch;
|
| 57 |
+
'X-Stainless-Runtime': 'node' | 'deno' | 'edge' | `browser:${Browser}` | 'unknown';
|
| 58 |
+
'X-Stainless-Runtime-Version': string;
|
| 59 |
+
};
|
| 60 |
+
const getPlatformProperties = (): PlatformProperties => {
|
| 61 |
+
const detectedPlatform = getDetectedPlatform();
|
| 62 |
+
if (detectedPlatform === 'deno') {
|
| 63 |
+
return {
|
| 64 |
+
'X-Stainless-Lang': 'js',
|
| 65 |
+
'X-Stainless-Package-Version': VERSION,
|
| 66 |
+
'X-Stainless-OS': normalizePlatform(Deno.build.os),
|
| 67 |
+
'X-Stainless-Arch': normalizeArch(Deno.build.arch),
|
| 68 |
+
'X-Stainless-Runtime': 'deno',
|
| 69 |
+
'X-Stainless-Runtime-Version':
|
| 70 |
+
typeof Deno.version === 'string' ? Deno.version : Deno.version?.deno ?? 'unknown',
|
| 71 |
+
};
|
| 72 |
+
}
|
| 73 |
+
if (typeof EdgeRuntime !== 'undefined') {
|
| 74 |
+
return {
|
| 75 |
+
'X-Stainless-Lang': 'js',
|
| 76 |
+
'X-Stainless-Package-Version': VERSION,
|
| 77 |
+
'X-Stainless-OS': 'Unknown',
|
| 78 |
+
'X-Stainless-Arch': `other:${EdgeRuntime}`,
|
| 79 |
+
'X-Stainless-Runtime': 'edge',
|
| 80 |
+
'X-Stainless-Runtime-Version': (globalThis as any).process.version,
|
| 81 |
+
};
|
| 82 |
+
}
|
| 83 |
+
// Check if Node.js
|
| 84 |
+
if (detectedPlatform === 'node') {
|
| 85 |
+
return {
|
| 86 |
+
'X-Stainless-Lang': 'js',
|
| 87 |
+
'X-Stainless-Package-Version': VERSION,
|
| 88 |
+
'X-Stainless-OS': normalizePlatform((globalThis as any).process.platform ?? 'unknown'),
|
| 89 |
+
'X-Stainless-Arch': normalizeArch((globalThis as any).process.arch ?? 'unknown'),
|
| 90 |
+
'X-Stainless-Runtime': 'node',
|
| 91 |
+
'X-Stainless-Runtime-Version': (globalThis as any).process.version ?? 'unknown',
|
| 92 |
+
};
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
const browserInfo = getBrowserInfo();
|
| 96 |
+
if (browserInfo) {
|
| 97 |
+
return {
|
| 98 |
+
'X-Stainless-Lang': 'js',
|
| 99 |
+
'X-Stainless-Package-Version': VERSION,
|
| 100 |
+
'X-Stainless-OS': 'Unknown',
|
| 101 |
+
'X-Stainless-Arch': 'unknown',
|
| 102 |
+
'X-Stainless-Runtime': `browser:${browserInfo.browser}`,
|
| 103 |
+
'X-Stainless-Runtime-Version': browserInfo.version,
|
| 104 |
+
};
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
// TODO add support for Cloudflare workers, etc.
|
| 108 |
+
return {
|
| 109 |
+
'X-Stainless-Lang': 'js',
|
| 110 |
+
'X-Stainless-Package-Version': VERSION,
|
| 111 |
+
'X-Stainless-OS': 'Unknown',
|
| 112 |
+
'X-Stainless-Arch': 'unknown',
|
| 113 |
+
'X-Stainless-Runtime': 'unknown',
|
| 114 |
+
'X-Stainless-Runtime-Version': 'unknown',
|
| 115 |
+
};
|
| 116 |
+
};
|
| 117 |
+
|
| 118 |
+
type BrowserInfo = {
|
| 119 |
+
browser: Browser;
|
| 120 |
+
version: string;
|
| 121 |
+
};
|
| 122 |
+
|
| 123 |
+
declare const navigator: { userAgent: string } | undefined;
|
| 124 |
+
|
| 125 |
+
// Note: modified from https://github.com/JS-DevTools/host-environment/blob/b1ab79ecde37db5d6e163c050e54fe7d287d7c92/src/isomorphic.browser.ts
|
| 126 |
+
function getBrowserInfo(): BrowserInfo | null {
|
| 127 |
+
if (typeof navigator === 'undefined' || !navigator) {
|
| 128 |
+
return null;
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
// NOTE: The order matters here!
|
| 132 |
+
const browserPatterns = [
|
| 133 |
+
{ key: 'edge' as const, pattern: /Edge(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
| 134 |
+
{ key: 'ie' as const, pattern: /MSIE(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
| 135 |
+
{ key: 'ie' as const, pattern: /Trident(?:.*rv\:(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
| 136 |
+
{ key: 'chrome' as const, pattern: /Chrome(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
| 137 |
+
{ key: 'firefox' as const, pattern: /Firefox(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
| 138 |
+
{ key: 'safari' as const, pattern: /(?:Version\W+(\d+)\.(\d+)(?:\.(\d+))?)?(?:\W+Mobile\S*)?\W+Safari/ },
|
| 139 |
+
];
|
| 140 |
+
|
| 141 |
+
// Find the FIRST matching browser
|
| 142 |
+
for (const { key, pattern } of browserPatterns) {
|
| 143 |
+
const match = pattern.exec(navigator.userAgent);
|
| 144 |
+
if (match) {
|
| 145 |
+
const major = match[1] || 0;
|
| 146 |
+
const minor = match[2] || 0;
|
| 147 |
+
const patch = match[3] || 0;
|
| 148 |
+
|
| 149 |
+
return { browser: key, version: `${major}.${minor}.${patch}` };
|
| 150 |
+
}
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
return null;
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
const normalizeArch = (arch: string): Arch => {
|
| 157 |
+
// Node docs:
|
| 158 |
+
// - https://nodejs.org/api/process.html#processarch
|
| 159 |
+
// Deno docs:
|
| 160 |
+
// - https://doc.deno.land/deno/stable/~/Deno.build
|
| 161 |
+
if (arch === 'x32') return 'x32';
|
| 162 |
+
if (arch === 'x86_64' || arch === 'x64') return 'x64';
|
| 163 |
+
if (arch === 'arm') return 'arm';
|
| 164 |
+
if (arch === 'aarch64' || arch === 'arm64') return 'arm64';
|
| 165 |
+
if (arch) return `other:${arch}`;
|
| 166 |
+
return 'unknown';
|
| 167 |
+
};
|
| 168 |
+
|
| 169 |
+
const normalizePlatform = (platform: string): PlatformName => {
|
| 170 |
+
// Node platforms:
|
| 171 |
+
// - https://nodejs.org/api/process.html#processplatform
|
| 172 |
+
// Deno platforms:
|
| 173 |
+
// - https://doc.deno.land/deno/stable/~/Deno.build
|
| 174 |
+
// - https://github.com/denoland/deno/issues/14799
|
| 175 |
+
|
| 176 |
+
platform = platform.toLowerCase();
|
| 177 |
+
|
| 178 |
+
// NOTE: this iOS check is untested and may not work
|
| 179 |
+
// Node does not work natively on IOS, there is a fork at
|
| 180 |
+
// https://github.com/nodejs-mobile/nodejs-mobile
|
| 181 |
+
// however it is unknown at the time of writing how to detect if it is running
|
| 182 |
+
if (platform.includes('ios')) return 'iOS';
|
| 183 |
+
if (platform === 'android') return 'Android';
|
| 184 |
+
if (platform === 'darwin') return 'MacOS';
|
| 185 |
+
if (platform === 'win32') return 'Windows';
|
| 186 |
+
if (platform === 'freebsd') return 'FreeBSD';
|
| 187 |
+
if (platform === 'openbsd') return 'OpenBSD';
|
| 188 |
+
if (platform === 'linux') return 'Linux';
|
| 189 |
+
if (platform) return `Other:${platform}`;
|
| 190 |
+
return 'Unknown';
|
| 191 |
+
};
|
| 192 |
+
|
| 193 |
+
let _platformHeaders: PlatformProperties;
|
| 194 |
+
export const getPlatformHeaders = () => {
|
| 195 |
+
return (_platformHeaders ??= getPlatformProperties());
|
| 196 |
+
};
|
node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/internal/errors.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
| 2 |
+
|
| 3 |
+
export function isAbortError(err: unknown) {
|
| 4 |
+
return (
|
| 5 |
+
typeof err === 'object' &&
|
| 6 |
+
err !== null &&
|
| 7 |
+
// Spec-compliant fetch implementations
|
| 8 |
+
(('name' in err && (err as any).name === 'AbortError') ||
|
| 9 |
+
// Expo fetch
|
| 10 |
+
('message' in err && String((err as any).message).includes('FetchRequestCanceledException')))
|
| 11 |
+
);
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
export const castToError = (err: any): Error => {
|
| 15 |
+
if (err instanceof Error) return err;
|
| 16 |
+
if (typeof err === 'object' && err !== null) {
|
| 17 |
+
try {
|
| 18 |
+
if (Object.prototype.toString.call(err) === '[object Error]') {
|
| 19 |
+
// @ts-ignore - not all envs have native support for cause yet
|
| 20 |
+
const error = new Error(err.message, err.cause ? { cause: err.cause } : {});
|
| 21 |
+
if (err.stack) error.stack = err.stack;
|
| 22 |
+
// @ts-ignore - not all envs have native support for cause yet
|
| 23 |
+
if (err.cause && !error.cause) error.cause = err.cause;
|
| 24 |
+
if (err.name) error.name = err.name;
|
| 25 |
+
return error;
|
| 26 |
+
}
|
| 27 |
+
} catch {}
|
| 28 |
+
try {
|
| 29 |
+
return new Error(JSON.stringify(err));
|
| 30 |
+
} catch {}
|
| 31 |
+
}
|
| 32 |
+
return new Error(err);
|
| 33 |
+
};
|
node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/internal/headers.ts
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
| 2 |
+
|
| 3 |
+
import { isReadonlyArray } from './utils/values';
|
| 4 |
+
|
| 5 |
+
type HeaderValue = string | undefined | null;
|
| 6 |
+
export type HeadersLike =
|
| 7 |
+
| Headers
|
| 8 |
+
| readonly HeaderValue[][]
|
| 9 |
+
| Record<string, HeaderValue | readonly HeaderValue[]>
|
| 10 |
+
| undefined
|
| 11 |
+
| null
|
| 12 |
+
| NullableHeaders;
|
| 13 |
+
|
| 14 |
+
const brand_privateNullableHeaders = Symbol.for('brand.privateNullableHeaders') as symbol & {
|
| 15 |
+
description: 'brand.privateNullableHeaders';
|
| 16 |
+
};
|
| 17 |
+
|
| 18 |
+
/**
|
| 19 |
+
* @internal
|
| 20 |
+
* Users can pass explicit nulls to unset default headers. When we parse them
|
| 21 |
+
* into a standard headers type we need to preserve that information.
|
| 22 |
+
*/
|
| 23 |
+
export type NullableHeaders = {
|
| 24 |
+
/** Brand check, prevent users from creating a NullableHeaders. */
|
| 25 |
+
[_: typeof brand_privateNullableHeaders]: true;
|
| 26 |
+
/** Parsed headers. */
|
| 27 |
+
values: Headers;
|
| 28 |
+
/** Set of lowercase header names explicitly set to null. */
|
| 29 |
+
nulls: Set<string>;
|
| 30 |
+
};
|
| 31 |
+
|
| 32 |
+
function* iterateHeaders(headers: HeadersLike): IterableIterator<readonly [string, string | null]> {
|
| 33 |
+
if (!headers) return;
|
| 34 |
+
|
| 35 |
+
if (brand_privateNullableHeaders in headers) {
|
| 36 |
+
const { values, nulls } = headers as NullableHeaders;
|
| 37 |
+
yield* values.entries();
|
| 38 |
+
for (const name of nulls) {
|
| 39 |
+
yield [name, null];
|
| 40 |
+
}
|
| 41 |
+
return;
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
let shouldClear = false;
|
| 45 |
+
let iter: Iterable<readonly (HeaderValue | readonly HeaderValue[])[]>;
|
| 46 |
+
if (headers instanceof Headers) {
|
| 47 |
+
iter = headers.entries();
|
| 48 |
+
} else if (isReadonlyArray(headers)) {
|
| 49 |
+
iter = headers;
|
| 50 |
+
} else {
|
| 51 |
+
shouldClear = true;
|
| 52 |
+
iter = Object.entries(headers ?? {});
|
| 53 |
+
}
|
| 54 |
+
for (let row of iter) {
|
| 55 |
+
const name = row[0];
|
| 56 |
+
if (typeof name !== 'string') throw new TypeError('expected header name to be a string');
|
| 57 |
+
const values = isReadonlyArray(row[1]) ? row[1] : [row[1]];
|
| 58 |
+
let didClear = false;
|
| 59 |
+
for (const value of values) {
|
| 60 |
+
if (value === undefined) continue;
|
| 61 |
+
|
| 62 |
+
// Objects keys always overwrite older headers, they never append.
|
| 63 |
+
// Yield a null to clear the header before adding the new values.
|
| 64 |
+
if (shouldClear && !didClear) {
|
| 65 |
+
didClear = true;
|
| 66 |
+
yield [name, null];
|
| 67 |
+
}
|
| 68 |
+
yield [name, value];
|
| 69 |
+
}
|
| 70 |
+
}
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
export const buildHeaders = (newHeaders: HeadersLike[]): NullableHeaders => {
|
| 74 |
+
const targetHeaders = new Headers();
|
| 75 |
+
const nullHeaders = new Set<string>();
|
| 76 |
+
for (const headers of newHeaders) {
|
| 77 |
+
const seenHeaders = new Set<string>();
|
| 78 |
+
for (const [name, value] of iterateHeaders(headers)) {
|
| 79 |
+
const lowerName = name.toLowerCase();
|
| 80 |
+
if (!seenHeaders.has(lowerName)) {
|
| 81 |
+
targetHeaders.delete(name);
|
| 82 |
+
seenHeaders.add(lowerName);
|
| 83 |
+
}
|
| 84 |
+
if (value === null) {
|
| 85 |
+
targetHeaders.delete(name);
|
| 86 |
+
nullHeaders.add(lowerName);
|
| 87 |
+
} else {
|
| 88 |
+
targetHeaders.append(name, value);
|
| 89 |
+
nullHeaders.delete(lowerName);
|
| 90 |
+
}
|
| 91 |
+
}
|
| 92 |
+
}
|
| 93 |
+
return { [brand_privateNullableHeaders]: true, values: targetHeaders, nulls: nullHeaders };
|
| 94 |
+
};
|
| 95 |
+
|
| 96 |
+
export const isEmptyHeaders = (headers: HeadersLike) => {
|
| 97 |
+
for (const _ of iterateHeaders(headers)) return false;
|
| 98 |
+
return true;
|
| 99 |
+
};
|
node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/internal/parse.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
| 2 |
+
|
| 3 |
+
import type { FinalRequestOptions } from './request-options';
|
| 4 |
+
import { Stream } from '../core/streaming';
|
| 5 |
+
import { type BaseAnthropic } from '../client';
|
| 6 |
+
import { formatRequestDetails, loggerFor } from './utils/log';
|
| 7 |
+
import type { AbstractPage } from '../core/pagination';
|
| 8 |
+
|
| 9 |
+
export type APIResponseProps = {
|
| 10 |
+
response: Response;
|
| 11 |
+
options: FinalRequestOptions;
|
| 12 |
+
controller: AbortController;
|
| 13 |
+
requestLogID: string;
|
| 14 |
+
retryOfRequestLogID: string | undefined;
|
| 15 |
+
startTime: number;
|
| 16 |
+
};
|
| 17 |
+
|
| 18 |
+
export async function defaultParseResponse<T>(
|
| 19 |
+
client: BaseAnthropic,
|
| 20 |
+
props: APIResponseProps,
|
| 21 |
+
): Promise<WithRequestID<T>> {
|
| 22 |
+
const { response, requestLogID, retryOfRequestLogID, startTime } = props;
|
| 23 |
+
const body = await (async () => {
|
| 24 |
+
if (props.options.stream) {
|
| 25 |
+
loggerFor(client).debug('response', response.status, response.url, response.headers, response.body);
|
| 26 |
+
|
| 27 |
+
// Note: there is an invariant here that isn't represented in the type system
|
| 28 |
+
// that if you set `stream: true` the response type must also be `Stream<T>`
|
| 29 |
+
|
| 30 |
+
if (props.options.__streamClass) {
|
| 31 |
+
return props.options.__streamClass.fromSSEResponse(response, props.controller) as any;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
return Stream.fromSSEResponse(response, props.controller) as any;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
// fetch refuses to read the body when the status code is 204.
|
| 38 |
+
if (response.status === 204) {
|
| 39 |
+
return null as T;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
if (props.options.__binaryResponse) {
|
| 43 |
+
return response as unknown as T;
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
const contentType = response.headers.get('content-type');
|
| 47 |
+
const mediaType = contentType?.split(';')[0]?.trim();
|
| 48 |
+
const isJSON = mediaType?.includes('application/json') || mediaType?.endsWith('+json');
|
| 49 |
+
if (isJSON) {
|
| 50 |
+
const json = await response.json();
|
| 51 |
+
return addRequestID(json as T, response);
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
const text = await response.text();
|
| 55 |
+
return text as unknown as T;
|
| 56 |
+
})();
|
| 57 |
+
loggerFor(client).debug(
|
| 58 |
+
`[${requestLogID}] response parsed`,
|
| 59 |
+
formatRequestDetails({
|
| 60 |
+
retryOfRequestLogID,
|
| 61 |
+
url: response.url,
|
| 62 |
+
status: response.status,
|
| 63 |
+
body,
|
| 64 |
+
durationMs: Date.now() - startTime,
|
| 65 |
+
}),
|
| 66 |
+
);
|
| 67 |
+
return body;
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
export type WithRequestID<T> =
|
| 71 |
+
T extends Array<any> | Response | AbstractPage<any> ? T
|
| 72 |
+
: T extends Record<string, any> ? T & { _request_id?: string | null }
|
| 73 |
+
: T;
|
| 74 |
+
|
| 75 |
+
export function addRequestID<T>(value: T, response: Response): WithRequestID<T> {
|
| 76 |
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
| 77 |
+
return value as WithRequestID<T>;
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
return Object.defineProperty(value, '_request_id', {
|
| 81 |
+
value: response.headers.get('request-id'),
|
| 82 |
+
enumerable: false,
|
| 83 |
+
}) as WithRequestID<T>;
|
| 84 |
+
}
|
node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/internal/request-options.ts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
| 2 |
+
|
| 3 |
+
import { NullableHeaders } from './headers';
|
| 4 |
+
|
| 5 |
+
import type { BodyInit } from './builtin-types';
|
| 6 |
+
import { Stream } from '../core/streaming';
|
| 7 |
+
import type { HTTPMethod, MergedRequestInit } from './types';
|
| 8 |
+
import { type HeadersLike } from './headers';
|
| 9 |
+
|
| 10 |
+
export type FinalRequestOptions = RequestOptions & { method: HTTPMethod; path: string };
|
| 11 |
+
|
| 12 |
+
export type RequestOptions = {
|
| 13 |
+
/**
|
| 14 |
+
* The HTTP method for the request (e.g., 'get', 'post', 'put', 'delete').
|
| 15 |
+
*/
|
| 16 |
+
method?: HTTPMethod;
|
| 17 |
+
|
| 18 |
+
/**
|
| 19 |
+
* The URL path for the request.
|
| 20 |
+
*
|
| 21 |
+
* @example "/v1/foo"
|
| 22 |
+
*/
|
| 23 |
+
path?: string;
|
| 24 |
+
|
| 25 |
+
/**
|
| 26 |
+
* Query parameters to include in the request URL.
|
| 27 |
+
*/
|
| 28 |
+
query?: object | undefined | null;
|
| 29 |
+
|
| 30 |
+
/**
|
| 31 |
+
* The request body. Can be a string, JSON object, FormData, or other supported types.
|
| 32 |
+
*/
|
| 33 |
+
body?: unknown;
|
| 34 |
+
|
| 35 |
+
/**
|
| 36 |
+
* HTTP headers to include with the request. Can be a Headers object, plain object, or array of tuples.
|
| 37 |
+
*/
|
| 38 |
+
headers?: HeadersLike;
|
| 39 |
+
|
| 40 |
+
/**
|
| 41 |
+
* The maximum number of times that the client will retry a request in case of a
|
| 42 |
+
* temporary failure, like a network error or a 5XX error from the server.
|
| 43 |
+
*
|
| 44 |
+
* @default 2
|
| 45 |
+
*/
|
| 46 |
+
maxRetries?: number;
|
| 47 |
+
|
| 48 |
+
stream?: boolean | undefined;
|
| 49 |
+
|
| 50 |
+
/**
|
| 51 |
+
* The maximum amount of time (in milliseconds) that the client should wait for a response
|
| 52 |
+
* from the server before timing out a single request.
|
| 53 |
+
*
|
| 54 |
+
* @unit milliseconds
|
| 55 |
+
*/
|
| 56 |
+
timeout?: number;
|
| 57 |
+
|
| 58 |
+
/**
|
| 59 |
+
* Additional `RequestInit` options to be passed to the underlying `fetch` call.
|
| 60 |
+
* These options will be merged with the client's default fetch options.
|
| 61 |
+
*/
|
| 62 |
+
fetchOptions?: MergedRequestInit;
|
| 63 |
+
|
| 64 |
+
/**
|
| 65 |
+
* An AbortSignal that can be used to cancel the request.
|
| 66 |
+
*/
|
| 67 |
+
signal?: AbortSignal | undefined | null;
|
| 68 |
+
|
| 69 |
+
/**
|
| 70 |
+
* A unique key for this request to enable idempotency.
|
| 71 |
+
*/
|
| 72 |
+
idempotencyKey?: string;
|
| 73 |
+
|
| 74 |
+
/**
|
| 75 |
+
* Override the default base URL for this specific request.
|
| 76 |
+
*/
|
| 77 |
+
defaultBaseURL?: string | undefined;
|
| 78 |
+
|
| 79 |
+
__binaryResponse?: boolean | undefined;
|
| 80 |
+
__streamClass?: typeof Stream;
|
| 81 |
+
};
|
| 82 |
+
|
| 83 |
+
export type EncodedContent = { bodyHeaders: HeadersLike; body: BodyInit };
|
| 84 |
+
export type RequestEncoder = (request: { headers: NullableHeaders; body: unknown }) => EncodedContent;
|
| 85 |
+
|
| 86 |
+
export const FallbackEncoder: RequestEncoder = ({ headers, body }) => {
|
| 87 |
+
return {
|
| 88 |
+
bodyHeaders: {
|
| 89 |
+
'content-type': 'application/json',
|
| 90 |
+
},
|
| 91 |
+
body: JSON.stringify(body),
|
| 92 |
+
};
|
| 93 |
+
};
|
node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/internal/shim-types.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* Shims for types that we can't always rely on being available globally.
|
| 5 |
+
*
|
| 6 |
+
* Note: these only exist at the type-level, there is no corresponding runtime
|
| 7 |
+
* version for any of these symbols.
|
| 8 |
+
*/
|
| 9 |
+
|
| 10 |
+
type NeverToAny<T> = T extends never ? any : T;
|
| 11 |
+
|
| 12 |
+
/** @ts-ignore */
|
| 13 |
+
type _DOMReadableStream<R = any> = globalThis.ReadableStream<R>;
|
| 14 |
+
|
| 15 |
+
/** @ts-ignore */
|
| 16 |
+
type _NodeReadableStream<R = any> = import('stream/web').ReadableStream<R>;
|
| 17 |
+
|
| 18 |
+
type _ConditionalNodeReadableStream<R = any> =
|
| 19 |
+
typeof globalThis extends { ReadableStream: any } ? never : _NodeReadableStream<R>;
|
| 20 |
+
|
| 21 |
+
type _ReadableStream<R = any> = NeverToAny<
|
| 22 |
+
| ([0] extends [1 & _DOMReadableStream<R>] ? never : _DOMReadableStream<R>)
|
| 23 |
+
| ([0] extends [1 & _ConditionalNodeReadableStream<R>] ? never : _ConditionalNodeReadableStream<R>)
|
| 24 |
+
>;
|
| 25 |
+
|
| 26 |
+
export type { _ReadableStream as ReadableStream };
|
node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/internal/shims.ts
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* This module provides internal shims and utility functions for environments where certain Node.js or global types may not be available.
|
| 5 |
+
*
|
| 6 |
+
* These are used to ensure we can provide a consistent behaviour between different JavaScript environments and good error
|
| 7 |
+
* messages in cases where an environment isn't fully supported.
|
| 8 |
+
*/
|
| 9 |
+
|
| 10 |
+
import type { Fetch } from './builtin-types';
|
| 11 |
+
import type { ReadableStream } from './shim-types';
|
| 12 |
+
|
| 13 |
+
export function getDefaultFetch(): Fetch {
|
| 14 |
+
if (typeof fetch !== 'undefined') {
|
| 15 |
+
return fetch as any;
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
throw new Error(
|
| 19 |
+
'`fetch` is not defined as a global; Either pass `fetch` to the client, `new Anthropic({ fetch })` or polyfill the global, `globalThis.fetch = fetch`',
|
| 20 |
+
);
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
type ReadableStreamArgs = ConstructorParameters<typeof ReadableStream>;
|
| 24 |
+
|
| 25 |
+
export function makeReadableStream(...args: ReadableStreamArgs): ReadableStream {
|
| 26 |
+
const ReadableStream = (globalThis as any).ReadableStream;
|
| 27 |
+
if (typeof ReadableStream === 'undefined') {
|
| 28 |
+
// Note: All of the platforms / runtimes we officially support already define
|
| 29 |
+
// `ReadableStream` as a global, so this should only ever be hit on unsupported runtimes.
|
| 30 |
+
throw new Error(
|
| 31 |
+
'`ReadableStream` is not defined as a global; You will need to polyfill it, `globalThis.ReadableStream = ReadableStream`',
|
| 32 |
+
);
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
return new ReadableStream(...args);
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
export function ReadableStreamFrom<T>(iterable: Iterable<T> | AsyncIterable<T>): ReadableStream<T> {
|
| 39 |
+
let iter: AsyncIterator<T> | Iterator<T> =
|
| 40 |
+
Symbol.asyncIterator in iterable ? iterable[Symbol.asyncIterator]() : iterable[Symbol.iterator]();
|
| 41 |
+
|
| 42 |
+
return makeReadableStream({
|
| 43 |
+
start() {},
|
| 44 |
+
async pull(controller: any) {
|
| 45 |
+
const { done, value } = await iter.next();
|
| 46 |
+
if (done) {
|
| 47 |
+
controller.close();
|
| 48 |
+
} else {
|
| 49 |
+
controller.enqueue(value);
|
| 50 |
+
}
|
| 51 |
+
},
|
| 52 |
+
async cancel() {
|
| 53 |
+
await iter.return?.();
|
| 54 |
+
},
|
| 55 |
+
});
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
/**
|
| 59 |
+
* Most browsers don't yet have async iterable support for ReadableStream,
|
| 60 |
+
* and Node has a very different way of reading bytes from its "ReadableStream".
|
| 61 |
+
*
|
| 62 |
+
* This polyfill was pulled from https://github.com/MattiasBuelens/web-streams-polyfill/pull/122#issuecomment-1627354490
|
| 63 |
+
*/
|
| 64 |
+
export function ReadableStreamToAsyncIterable<T>(stream: any): AsyncIterableIterator<T> {
|
| 65 |
+
if (stream[Symbol.asyncIterator]) return stream;
|
| 66 |
+
|
| 67 |
+
const reader = stream.getReader();
|
| 68 |
+
return {
|
| 69 |
+
async next() {
|
| 70 |
+
try {
|
| 71 |
+
const result = await reader.read();
|
| 72 |
+
if (result?.done) reader.releaseLock(); // release lock when stream becomes closed
|
| 73 |
+
return result;
|
| 74 |
+
} catch (e) {
|
| 75 |
+
reader.releaseLock(); // release lock when stream becomes errored
|
| 76 |
+
throw e;
|
| 77 |
+
}
|
| 78 |
+
},
|
| 79 |
+
async return() {
|
| 80 |
+
const cancelPromise = reader.cancel();
|
| 81 |
+
reader.releaseLock();
|
| 82 |
+
await cancelPromise;
|
| 83 |
+
return { done: true, value: undefined };
|
| 84 |
+
},
|
| 85 |
+
[Symbol.asyncIterator]() {
|
| 86 |
+
return this;
|
| 87 |
+
},
|
| 88 |
+
};
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
/**
|
| 92 |
+
* Cancels a ReadableStream we don't need to consume.
|
| 93 |
+
* See https://undici.nodejs.org/#/?id=garbage-collection
|
| 94 |
+
*/
|
| 95 |
+
export async function CancelReadableStream(stream: any): Promise<void> {
|
| 96 |
+
if (stream === null || typeof stream !== 'object') return;
|
| 97 |
+
|
| 98 |
+
if (stream[Symbol.asyncIterator]) {
|
| 99 |
+
await stream[Symbol.asyncIterator]().return?.();
|
| 100 |
+
return;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
const reader = stream.getReader();
|
| 104 |
+
const cancelPromise = reader.cancel();
|
| 105 |
+
reader.releaseLock();
|
| 106 |
+
await cancelPromise;
|
| 107 |
+
}
|
node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/internal/stream-utils.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Most browsers don't yet have async iterable support for ReadableStream,
|
| 3 |
+
* and Node has a very different way of reading bytes from its "ReadableStream".
|
| 4 |
+
*
|
| 5 |
+
* This polyfill was pulled from https://github.com/MattiasBuelens/web-streams-polyfill/pull/122#issuecomment-1627354490
|
| 6 |
+
*/
|
| 7 |
+
export function ReadableStreamToAsyncIterable<T>(stream: any): AsyncIterableIterator<T> {
|
| 8 |
+
if (stream[Symbol.asyncIterator]) return stream;
|
| 9 |
+
|
| 10 |
+
const reader = stream.getReader();
|
| 11 |
+
return {
|
| 12 |
+
async next() {
|
| 13 |
+
try {
|
| 14 |
+
const result = await reader.read();
|
| 15 |
+
if (result?.done) reader.releaseLock(); // release lock when stream becomes closed
|
| 16 |
+
return result;
|
| 17 |
+
} catch (e) {
|
| 18 |
+
reader.releaseLock(); // release lock when stream becomes errored
|
| 19 |
+
throw e;
|
| 20 |
+
}
|
| 21 |
+
},
|
| 22 |
+
async return() {
|
| 23 |
+
const cancelPromise = reader.cancel();
|
| 24 |
+
reader.releaseLock();
|
| 25 |
+
await cancelPromise;
|
| 26 |
+
return { done: true, value: undefined };
|
| 27 |
+
},
|
| 28 |
+
[Symbol.asyncIterator]() {
|
| 29 |
+
return this;
|
| 30 |
+
},
|
| 31 |
+
};
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { BlobPart, getName, makeFile, isAsyncIterable } from './uploads';
|
| 2 |
+
import type { FilePropertyBag } from './builtin-types';
|
| 3 |
+
import { checkFileSupport } from './uploads';
|
| 4 |
+
|
| 5 |
+
type BlobLikePart = string | ArrayBuffer | ArrayBufferView | BlobLike | DataView;
|
| 6 |
+
|
| 7 |
+
/**
|
| 8 |
+
* Intended to match DOM Blob, node-fetch Blob, node:buffer Blob, etc.
|
| 9 |
+
* Don't add arrayBuffer here, node-fetch doesn't have it
|
| 10 |
+
*/
|
| 11 |
+
interface BlobLike {
|
| 12 |
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/size) */
|
| 13 |
+
readonly size: number;
|
| 14 |
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/type) */
|
| 15 |
+
readonly type: string;
|
| 16 |
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/text) */
|
| 17 |
+
text(): Promise<string>;
|
| 18 |
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/slice) */
|
| 19 |
+
slice(start?: number, end?: number): BlobLike;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
/**
|
| 23 |
+
* This check adds the arrayBuffer() method type because it is available and used at runtime
|
| 24 |
+
*/
|
| 25 |
+
const isBlobLike = (value: any): value is BlobLike & { arrayBuffer(): Promise<ArrayBuffer> } =>
|
| 26 |
+
value != null &&
|
| 27 |
+
typeof value === 'object' &&
|
| 28 |
+
typeof value.size === 'number' &&
|
| 29 |
+
typeof value.type === 'string' &&
|
| 30 |
+
typeof value.text === 'function' &&
|
| 31 |
+
typeof value.slice === 'function' &&
|
| 32 |
+
typeof value.arrayBuffer === 'function';
|
| 33 |
+
|
| 34 |
+
/**
|
| 35 |
+
* Intended to match DOM File, node:buffer File, undici File, etc.
|
| 36 |
+
*/
|
| 37 |
+
interface FileLike extends BlobLike {
|
| 38 |
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/File/lastModified) */
|
| 39 |
+
readonly lastModified: number;
|
| 40 |
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/File/name) */
|
| 41 |
+
readonly name?: string | undefined;
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
/**
|
| 45 |
+
* This check adds the arrayBuffer() method type because it is available and used at runtime
|
| 46 |
+
*/
|
| 47 |
+
const isFileLike = (value: any): value is FileLike & { arrayBuffer(): Promise<ArrayBuffer> } =>
|
| 48 |
+
value != null &&
|
| 49 |
+
typeof value === 'object' &&
|
| 50 |
+
typeof value.name === 'string' &&
|
| 51 |
+
typeof value.lastModified === 'number' &&
|
| 52 |
+
isBlobLike(value);
|
| 53 |
+
|
| 54 |
+
/**
|
| 55 |
+
* Intended to match DOM Response, node-fetch Response, undici Response, etc.
|
| 56 |
+
*/
|
| 57 |
+
export interface ResponseLike {
|
| 58 |
+
url: string;
|
| 59 |
+
blob(): Promise<BlobLike>;
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
const isResponseLike = (value: any): value is ResponseLike =>
|
| 63 |
+
value != null &&
|
| 64 |
+
typeof value === 'object' &&
|
| 65 |
+
typeof value.url === 'string' &&
|
| 66 |
+
typeof value.blob === 'function';
|
| 67 |
+
|
| 68 |
+
export type ToFileInput =
|
| 69 |
+
| FileLike
|
| 70 |
+
| ResponseLike
|
| 71 |
+
| Exclude<BlobLikePart, string>
|
| 72 |
+
| AsyncIterable<BlobLikePart>;
|
| 73 |
+
|
| 74 |
+
/**
|
| 75 |
+
* Helper for creating a {@link File} to pass to an SDK upload method from a variety of different data formats
|
| 76 |
+
* @param value the raw content of the file. Can be an {@link Uploadable}, {@link BlobLikePart}, or {@link AsyncIterable} of {@link BlobLikePart}s
|
| 77 |
+
* @param {string=} name the name of the file. If omitted, toFile will try to determine a file name from bits if possible
|
| 78 |
+
* @param {Object=} options additional properties
|
| 79 |
+
* @param {string=} options.type the MIME type of the content
|
| 80 |
+
* @param {number=} options.lastModified the last modified timestamp
|
| 81 |
+
* @returns a {@link File} with the given properties
|
| 82 |
+
*/
|
| 83 |
+
export async function toFile(
|
| 84 |
+
value: ToFileInput | PromiseLike<ToFileInput>,
|
| 85 |
+
name?: string | null | undefined,
|
| 86 |
+
options?: FilePropertyBag | undefined,
|
| 87 |
+
): Promise<File> {
|
| 88 |
+
checkFileSupport();
|
| 89 |
+
|
| 90 |
+
// If it's a promise, resolve it.
|
| 91 |
+
value = await value;
|
| 92 |
+
|
| 93 |
+
name ||= getName(value);
|
| 94 |
+
|
| 95 |
+
// If we've been given a `File` we don't need to do anything if the name / options
|
| 96 |
+
// have not been customised.
|
| 97 |
+
if (isFileLike(value)) {
|
| 98 |
+
if (value instanceof File && name == null && options == null) {
|
| 99 |
+
return value;
|
| 100 |
+
}
|
| 101 |
+
return makeFile([await value.arrayBuffer()], name ?? value.name, {
|
| 102 |
+
type: value.type,
|
| 103 |
+
lastModified: value.lastModified,
|
| 104 |
+
...options,
|
| 105 |
+
});
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
if (isResponseLike(value)) {
|
| 109 |
+
const blob = await value.blob();
|
| 110 |
+
name ||= new URL(value.url).pathname.split(/[\\/]/).pop();
|
| 111 |
+
|
| 112 |
+
return makeFile(await getBytes(blob), name, options);
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
const parts = await getBytes(value);
|
| 116 |
+
|
| 117 |
+
if (!options?.type) {
|
| 118 |
+
const type = parts.find((part) => typeof part === 'object' && 'type' in part && part.type);
|
| 119 |
+
if (typeof type === 'string') {
|
| 120 |
+
options = { ...options, type };
|
| 121 |
+
}
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
return makeFile(parts, name, options);
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
async function getBytes(value: BlobLikePart | AsyncIterable<BlobLikePart>): Promise<Array<BlobPart>> {
|
| 128 |
+
let parts: Array<BlobPart> = [];
|
| 129 |
+
if (
|
| 130 |
+
typeof value === 'string' ||
|
| 131 |
+
ArrayBuffer.isView(value) || // includes Uint8Array, Buffer, etc.
|
| 132 |
+
value instanceof ArrayBuffer
|
| 133 |
+
) {
|
| 134 |
+
parts.push(value);
|
| 135 |
+
} else if (isBlobLike(value)) {
|
| 136 |
+
parts.push(value instanceof Blob ? value : await value.arrayBuffer());
|
| 137 |
+
} else if (
|
| 138 |
+
isAsyncIterable(value) // includes Readable, ReadableStream, etc.
|
| 139 |
+
) {
|
| 140 |
+
for await (const chunk of value) {
|
| 141 |
+
parts.push(...(await getBytes(chunk as BlobLikePart))); // TODO, consider validating?
|
| 142 |
+
}
|
| 143 |
+
} else {
|
| 144 |
+
const constructor = value?.constructor?.name;
|
| 145 |
+
throw new Error(
|
| 146 |
+
`Unexpected data type: ${typeof value}${
|
| 147 |
+
constructor ? `; constructor: ${constructor}` : ''
|
| 148 |
+
}${propsForError(value)}`,
|
| 149 |
+
);
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
return parts;
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
function propsForError(value: unknown): string {
|
| 156 |
+
if (typeof value !== 'object' || value === null) return '';
|
| 157 |
+
const props = Object.getOwnPropertyNames(value);
|
| 158 |
+
return `; props: [${props.map((p) => `"${p}"`).join(', ')}]`;
|
| 159 |
+
}
|
node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/internal/types.ts
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
| 2 |
+
|
| 3 |
+
export type PromiseOrValue<T> = T | Promise<T>;
|
| 4 |
+
export type HTTPMethod = 'get' | 'post' | 'put' | 'patch' | 'delete';
|
| 5 |
+
|
| 6 |
+
export type KeysEnum<T> = { [P in keyof Required<T>]: true };
|
| 7 |
+
|
| 8 |
+
export type FinalizedRequestInit = RequestInit & { headers: Headers };
|
| 9 |
+
|
| 10 |
+
type NotAny<T> = [0] extends [1 & T] ? never : T;
|
| 11 |
+
|
| 12 |
+
/**
|
| 13 |
+
* Some environments overload the global fetch function, and Parameters<T> only gets the last signature.
|
| 14 |
+
*/
|
| 15 |
+
type OverloadedParameters<T> =
|
| 16 |
+
T extends (
|
| 17 |
+
{
|
| 18 |
+
(...args: infer A): unknown;
|
| 19 |
+
(...args: infer B): unknown;
|
| 20 |
+
(...args: infer C): unknown;
|
| 21 |
+
(...args: infer D): unknown;
|
| 22 |
+
}
|
| 23 |
+
) ?
|
| 24 |
+
A | B | C | D
|
| 25 |
+
: T extends (
|
| 26 |
+
{
|
| 27 |
+
(...args: infer A): unknown;
|
| 28 |
+
(...args: infer B): unknown;
|
| 29 |
+
(...args: infer C): unknown;
|
| 30 |
+
}
|
| 31 |
+
) ?
|
| 32 |
+
A | B | C
|
| 33 |
+
: T extends (
|
| 34 |
+
{
|
| 35 |
+
(...args: infer A): unknown;
|
| 36 |
+
(...args: infer B): unknown;
|
| 37 |
+
}
|
| 38 |
+
) ?
|
| 39 |
+
A | B
|
| 40 |
+
: T extends (...args: infer A) => unknown ? A
|
| 41 |
+
: never;
|
| 42 |
+
|
| 43 |
+
/* eslint-disable */
|
| 44 |
+
/**
|
| 45 |
+
* These imports attempt to get types from a parent package's dependencies.
|
| 46 |
+
* Unresolved bare specifiers can trigger [automatic type acquisition][1] in some projects, which
|
| 47 |
+
* would cause typescript to show types not present at runtime. To avoid this, we import
|
| 48 |
+
* directly from parent node_modules folders.
|
| 49 |
+
*
|
| 50 |
+
* We need to check multiple levels because we don't know what directory structure we'll be in.
|
| 51 |
+
* For example, pnpm generates directories like this:
|
| 52 |
+
* ```
|
| 53 |
+
* node_modules
|
| 54 |
+
* ├── .pnpm
|
| 55 |
+
* │ └── pkg@1.0.0
|
| 56 |
+
* │ └── node_modules
|
| 57 |
+
* │ └── pkg
|
| 58 |
+
* │ └── internal
|
| 59 |
+
* │ └── types.d.ts
|
| 60 |
+
* ├── pkg -> .pnpm/pkg@1.0.0/node_modules/pkg
|
| 61 |
+
* └── undici
|
| 62 |
+
* ```
|
| 63 |
+
*
|
| 64 |
+
* [1]: https://www.typescriptlang.org/tsconfig/#typeAcquisition
|
| 65 |
+
*/
|
| 66 |
+
/** @ts-ignore For users with \@types/node */
|
| 67 |
+
type UndiciTypesRequestInit = NotAny<import('../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../../../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../../../../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../../../../../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../../../../../../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../../../../../../../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../../../../../../../../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../../../../../../../../../node_modules/undici-types/index.d.ts').RequestInit>;
|
| 68 |
+
/** @ts-ignore For users with undici */
|
| 69 |
+
type UndiciRequestInit = NotAny<import('../node_modules/undici/index.d.ts').RequestInit> | NotAny<import('../../node_modules/undici/index.d.ts').RequestInit> | NotAny<import('../../../node_modules/undici/index.d.ts').RequestInit> | NotAny<import('../../../../node_modules/undici/index.d.ts').RequestInit> | NotAny<import('../../../../../node_modules/undici/index.d.ts').RequestInit> | NotAny<import('../../../../../../node_modules/undici/index.d.ts').RequestInit> | NotAny<import('../../../../../../../node_modules/undici/index.d.ts').RequestInit> | NotAny<import('../../../../../../../../node_modules/undici/index.d.ts').RequestInit> | NotAny<import('../../../../../../../../../node_modules/undici/index.d.ts').RequestInit> | NotAny<import('../../../../../../../../../../node_modules/undici/index.d.ts').RequestInit>;
|
| 70 |
+
/** @ts-ignore For users with \@types/bun */
|
| 71 |
+
type BunRequestInit = globalThis.FetchRequestInit;
|
| 72 |
+
/** @ts-ignore For users with node-fetch@2 */
|
| 73 |
+
type NodeFetch2RequestInit = NotAny<import('../node_modules/@types/node-fetch/index.d.ts').RequestInit> | NotAny<import('../../node_modules/@types/node-fetch/index.d.ts').RequestInit> | NotAny<import('../../../node_modules/@types/node-fetch/index.d.ts').RequestInit> | NotAny<import('../../../../node_modules/@types/node-fetch/index.d.ts').RequestInit> | NotAny<import('../../../../../node_modules/@types/node-fetch/index.d.ts').RequestInit> | NotAny<import('../../../../../../node_modules/@types/node-fetch/index.d.ts').RequestInit> | NotAny<import('../../../../../../../node_modules/@types/node-fetch/index.d.ts').RequestInit> | NotAny<import('../../../../../../../../node_modules/@types/node-fetch/index.d.ts').RequestInit> | NotAny<import('../../../../../../../../../node_modules/@types/node-fetch/index.d.ts').RequestInit> | NotAny<import('../../../../../../../../../../node_modules/@types/node-fetch/index.d.ts').RequestInit>;
|
| 74 |
+
/** @ts-ignore For users with node-fetch@3, doesn't need file extension because types are at ./@types/index.d.ts */
|
| 75 |
+
type NodeFetch3RequestInit = NotAny<import('../node_modules/node-fetch').RequestInit> | NotAny<import('../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../../../../../../node_modules/node-fetch').RequestInit>;
|
| 76 |
+
/** @ts-ignore For users who use Deno */
|
| 77 |
+
type FetchRequestInit = NonNullable<OverloadedParameters<typeof fetch>[1]>;
|
| 78 |
+
/* eslint-enable */
|
| 79 |
+
|
| 80 |
+
type RequestInits =
|
| 81 |
+
| NotAny<UndiciTypesRequestInit>
|
| 82 |
+
| NotAny<UndiciRequestInit>
|
| 83 |
+
| NotAny<BunRequestInit>
|
| 84 |
+
| NotAny<NodeFetch2RequestInit>
|
| 85 |
+
| NotAny<NodeFetch3RequestInit>
|
| 86 |
+
| NotAny<RequestInit>
|
| 87 |
+
| NotAny<FetchRequestInit>;
|
| 88 |
+
|
| 89 |
+
/**
|
| 90 |
+
* This type contains `RequestInit` options that may be available on the current runtime,
|
| 91 |
+
* including per-platform extensions like `dispatcher`, `agent`, `client`, etc.
|
| 92 |
+
*/
|
| 93 |
+
export type MergedRequestInit = RequestInits &
|
| 94 |
+
/** We don't include these in the types as they'll be overridden for every request. */
|
| 95 |
+
Partial<Record<'body' | 'headers' | 'method' | 'signal', never>>;
|
node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/internal/uploads.ts
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { type RequestOptions } from './request-options';
|
| 2 |
+
import type { FilePropertyBag, Fetch } from './builtin-types';
|
| 3 |
+
import type { BaseAnthropic } from '../client';
|
| 4 |
+
import { ReadableStreamFrom } from './shims';
|
| 5 |
+
|
| 6 |
+
export type BlobPart = string | ArrayBuffer | ArrayBufferView | Blob | DataView;
|
| 7 |
+
type FsReadStream = AsyncIterable<Uint8Array> & { path: string | { toString(): string } };
|
| 8 |
+
|
| 9 |
+
// https://github.com/oven-sh/bun/issues/5980
|
| 10 |
+
interface BunFile extends Blob {
|
| 11 |
+
readonly name?: string | undefined;
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
export const checkFileSupport = () => {
|
| 15 |
+
if (typeof File === 'undefined') {
|
| 16 |
+
const { process } = globalThis as any;
|
| 17 |
+
const isOldNode =
|
| 18 |
+
typeof process?.versions?.node === 'string' && parseInt(process.versions.node.split('.')) < 20;
|
| 19 |
+
throw new Error(
|
| 20 |
+
'`File` is not defined as a global, which is required for file uploads.' +
|
| 21 |
+
(isOldNode ?
|
| 22 |
+
" Update to Node 20 LTS or newer, or set `globalThis.File` to `import('node:buffer').File`."
|
| 23 |
+
: ''),
|
| 24 |
+
);
|
| 25 |
+
}
|
| 26 |
+
};
|
| 27 |
+
|
| 28 |
+
/**
|
| 29 |
+
* Typically, this is a native "File" class.
|
| 30 |
+
*
|
| 31 |
+
* We provide the {@link toFile} utility to convert a variety of objects
|
| 32 |
+
* into the File class.
|
| 33 |
+
*
|
| 34 |
+
* For convenience, you can also pass a fetch Response, or in Node,
|
| 35 |
+
* the result of fs.createReadStream().
|
| 36 |
+
*/
|
| 37 |
+
export type Uploadable = File | Response | FsReadStream | BunFile;
|
| 38 |
+
|
| 39 |
+
/**
|
| 40 |
+
* Construct a `File` instance. This is used to ensure a helpful error is thrown
|
| 41 |
+
* for environments that don't define a global `File` yet.
|
| 42 |
+
*/
|
| 43 |
+
export function makeFile(
|
| 44 |
+
fileBits: BlobPart[],
|
| 45 |
+
fileName: string | undefined,
|
| 46 |
+
options?: FilePropertyBag,
|
| 47 |
+
): File {
|
| 48 |
+
checkFileSupport();
|
| 49 |
+
return new File(fileBits as any, fileName ?? 'unknown_file', options);
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
export function getName(value: any): string | undefined {
|
| 53 |
+
return (
|
| 54 |
+
(
|
| 55 |
+
(typeof value === 'object' &&
|
| 56 |
+
value !== null &&
|
| 57 |
+
(('name' in value && value.name && String(value.name)) ||
|
| 58 |
+
('url' in value && value.url && String(value.url)) ||
|
| 59 |
+
('filename' in value && value.filename && String(value.filename)) ||
|
| 60 |
+
('path' in value && value.path && String(value.path)))) ||
|
| 61 |
+
''
|
| 62 |
+
)
|
| 63 |
+
.split(/[\\/]/)
|
| 64 |
+
.pop() || undefined
|
| 65 |
+
);
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
export const isAsyncIterable = (value: any): value is AsyncIterable<any> =>
|
| 69 |
+
value != null && typeof value === 'object' && typeof value[Symbol.asyncIterator] === 'function';
|
| 70 |
+
|
| 71 |
+
/**
|
| 72 |
+
* Returns a multipart/form-data request if any part of the given request body contains a File / Blob value.
|
| 73 |
+
* Otherwise returns the request as is.
|
| 74 |
+
*/
|
| 75 |
+
export const maybeMultipartFormRequestOptions = async (
|
| 76 |
+
opts: RequestOptions,
|
| 77 |
+
fetch: BaseAnthropic | Fetch,
|
| 78 |
+
): Promise<RequestOptions> => {
|
| 79 |
+
if (!hasUploadableValue(opts.body)) return opts;
|
| 80 |
+
|
| 81 |
+
return { ...opts, body: await createForm(opts.body, fetch) };
|
| 82 |
+
};
|
| 83 |
+
|
| 84 |
+
type MultipartFormRequestOptions = Omit<RequestOptions, 'body'> & { body: unknown };
|
| 85 |
+
|
| 86 |
+
export const multipartFormRequestOptions = async (
|
| 87 |
+
opts: MultipartFormRequestOptions,
|
| 88 |
+
fetch: BaseAnthropic | Fetch,
|
| 89 |
+
): Promise<RequestOptions> => {
|
| 90 |
+
return { ...opts, body: await createForm(opts.body, fetch) };
|
| 91 |
+
};
|
| 92 |
+
|
| 93 |
+
const supportsFormDataMap = /* @__PURE__ */ new WeakMap<Fetch, Promise<boolean>>();
|
| 94 |
+
|
| 95 |
+
/**
|
| 96 |
+
* node-fetch doesn't support the global FormData object in recent node versions. Instead of sending
|
| 97 |
+
* properly-encoded form data, it just stringifies the object, resulting in a request body of "[object FormData]".
|
| 98 |
+
* This function detects if the fetch function provided supports the global FormData object to avoid
|
| 99 |
+
* confusing error messages later on.
|
| 100 |
+
*/
|
| 101 |
+
function supportsFormData(fetchObject: BaseAnthropic | Fetch): Promise<boolean> {
|
| 102 |
+
const fetch: Fetch = typeof fetchObject === 'function' ? fetchObject : (fetchObject as any).fetch;
|
| 103 |
+
const cached = supportsFormDataMap.get(fetch);
|
| 104 |
+
if (cached) return cached;
|
| 105 |
+
const promise = (async () => {
|
| 106 |
+
try {
|
| 107 |
+
const FetchResponse = (
|
| 108 |
+
'Response' in fetch ?
|
| 109 |
+
fetch.Response
|
| 110 |
+
: (await fetch('data:,')).constructor) as typeof Response;
|
| 111 |
+
const data = new FormData();
|
| 112 |
+
if (data.toString() === (await new FetchResponse(data).text())) {
|
| 113 |
+
return false;
|
| 114 |
+
}
|
| 115 |
+
return true;
|
| 116 |
+
} catch {
|
| 117 |
+
// avoid false negatives
|
| 118 |
+
return true;
|
| 119 |
+
}
|
| 120 |
+
})();
|
| 121 |
+
supportsFormDataMap.set(fetch, promise);
|
| 122 |
+
return promise;
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
export const createForm = async <T = Record<string, unknown>>(
|
| 126 |
+
body: T | undefined,
|
| 127 |
+
fetch: BaseAnthropic | Fetch,
|
| 128 |
+
): Promise<FormData> => {
|
| 129 |
+
if (!(await supportsFormData(fetch))) {
|
| 130 |
+
throw new TypeError(
|
| 131 |
+
'The provided fetch function does not support file uploads with the current global FormData class.',
|
| 132 |
+
);
|
| 133 |
+
}
|
| 134 |
+
const form = new FormData();
|
| 135 |
+
await Promise.all(Object.entries(body || {}).map(([key, value]) => addFormValue(form, key, value)));
|
| 136 |
+
return form;
|
| 137 |
+
};
|
| 138 |
+
|
| 139 |
+
// We check for Blob not File because Bun.File doesn't inherit from File,
|
| 140 |
+
// but they both inherit from Blob and have a `name` property at runtime.
|
| 141 |
+
const isNamedBlob = (value: unknown): value is Blob => value instanceof Blob && 'name' in value;
|
| 142 |
+
|
| 143 |
+
const isUploadable = (value: unknown) =>
|
| 144 |
+
typeof value === 'object' &&
|
| 145 |
+
value !== null &&
|
| 146 |
+
(value instanceof Response || isAsyncIterable(value) || isNamedBlob(value));
|
| 147 |
+
|
| 148 |
+
const hasUploadableValue = (value: unknown): boolean => {
|
| 149 |
+
if (isUploadable(value)) return true;
|
| 150 |
+
if (Array.isArray(value)) return value.some(hasUploadableValue);
|
| 151 |
+
if (value && typeof value === 'object') {
|
| 152 |
+
for (const k in value) {
|
| 153 |
+
if (hasUploadableValue((value as any)[k])) return true;
|
| 154 |
+
}
|
| 155 |
+
}
|
| 156 |
+
return false;
|
| 157 |
+
};
|
| 158 |
+
|
| 159 |
+
const addFormValue = async (form: FormData, key: string, value: unknown): Promise<void> => {
|
| 160 |
+
if (value === undefined) return;
|
| 161 |
+
if (value == null) {
|
| 162 |
+
throw new TypeError(
|
| 163 |
+
`Received null for "${key}"; to pass null in FormData, you must use the string 'null'`,
|
| 164 |
+
);
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
// TODO: make nested formats configurable
|
| 168 |
+
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
|
| 169 |
+
form.append(key, String(value));
|
| 170 |
+
} else if (value instanceof Response) {
|
| 171 |
+
let options = {} as FilePropertyBag;
|
| 172 |
+
const contentType = value.headers.get('Content-Type');
|
| 173 |
+
if (contentType) {
|
| 174 |
+
options = { type: contentType };
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
form.append(key, makeFile([await value.blob()], getName(value), options));
|
| 178 |
+
} else if (isAsyncIterable(value)) {
|
| 179 |
+
form.append(key, makeFile([await new Response(ReadableStreamFrom(value)).blob()], getName(value)));
|
| 180 |
+
} else if (isNamedBlob(value)) {
|
| 181 |
+
form.append(key, makeFile([value], getName(value), { type: value.type }));
|
| 182 |
+
} else if (Array.isArray(value)) {
|
| 183 |
+
await Promise.all(value.map((entry) => addFormValue(form, key + '[]', entry)));
|
| 184 |
+
} else if (typeof value === 'object') {
|
| 185 |
+
await Promise.all(
|
| 186 |
+
Object.entries(value).map(([name, prop]) => addFormValue(form, `${key}[${name}]`, prop)),
|
| 187 |
+
);
|
| 188 |
+
} else {
|
| 189 |
+
throw new TypeError(
|
| 190 |
+
`Invalid value given to form, expected a string, number, boolean, object, Array, File or Blob but got ${value} instead`,
|
| 191 |
+
);
|
| 192 |
+
}
|
| 193 |
+
};
|
node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/internal/utils.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
| 2 |
+
|
| 3 |
+
export * from './utils/values';
|
| 4 |
+
export * from './utils/base64';
|
| 5 |
+
export * from './utils/env';
|
| 6 |
+
export * from './utils/log';
|
| 7 |
+
export * from './utils/uuid';
|
| 8 |
+
export * from './utils/sleep';
|
node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/internal/utils/base64.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
| 2 |
+
|
| 3 |
+
import { AnthropicError } from '../../core/error';
|
| 4 |
+
import { encodeUTF8 } from './bytes';
|
| 5 |
+
|
| 6 |
+
export const toBase64 = (data: string | Uint8Array | null | undefined): string => {
|
| 7 |
+
if (!data) return '';
|
| 8 |
+
|
| 9 |
+
if (typeof (globalThis as any).Buffer !== 'undefined') {
|
| 10 |
+
return (globalThis as any).Buffer.from(data).toString('base64');
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
if (typeof data === 'string') {
|
| 14 |
+
data = encodeUTF8(data);
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
if (typeof btoa !== 'undefined') {
|
| 18 |
+
return btoa(String.fromCharCode.apply(null, data as any));
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
throw new AnthropicError('Cannot generate base64 string; Expected `Buffer` or `btoa` to be defined');
|
| 22 |
+
};
|
| 23 |
+
|
| 24 |
+
export const fromBase64 = (str: string): Uint8Array => {
|
| 25 |
+
if (typeof (globalThis as any).Buffer !== 'undefined') {
|
| 26 |
+
const buf = (globalThis as any).Buffer.from(str, 'base64');
|
| 27 |
+
return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
if (typeof atob !== 'undefined') {
|
| 31 |
+
const bstr = atob(str);
|
| 32 |
+
const buf = new Uint8Array(bstr.length);
|
| 33 |
+
for (let i = 0; i < bstr.length; i++) {
|
| 34 |
+
buf[i] = bstr.charCodeAt(i);
|
| 35 |
+
}
|
| 36 |
+
return buf;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
throw new AnthropicError('Cannot decode base64 string; Expected `Buffer` or `atob` to be defined');
|
| 40 |
+
};
|
node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/internal/utils/bytes.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export function concatBytes(buffers: Uint8Array[]): Uint8Array {
|
| 2 |
+
let length = 0;
|
| 3 |
+
for (const buffer of buffers) {
|
| 4 |
+
length += buffer.length;
|
| 5 |
+
}
|
| 6 |
+
const output = new Uint8Array(length);
|
| 7 |
+
let index = 0;
|
| 8 |
+
for (const buffer of buffers) {
|
| 9 |
+
output.set(buffer, index);
|
| 10 |
+
index += buffer.length;
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
return output;
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
let encodeUTF8_: (str: string) => Uint8Array;
|
| 17 |
+
export function encodeUTF8(str: string) {
|
| 18 |
+
let encoder;
|
| 19 |
+
return (
|
| 20 |
+
encodeUTF8_ ??
|
| 21 |
+
((encoder = new (globalThis as any).TextEncoder()), (encodeUTF8_ = encoder.encode.bind(encoder)))
|
| 22 |
+
)(str);
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
let decodeUTF8_: (bytes: Uint8Array) => string;
|
| 26 |
+
export function decodeUTF8(bytes: Uint8Array) {
|
| 27 |
+
let decoder;
|
| 28 |
+
return (
|
| 29 |
+
decodeUTF8_ ??
|
| 30 |
+
((decoder = new (globalThis as any).TextDecoder()), (decodeUTF8_ = decoder.decode.bind(decoder)))
|
| 31 |
+
)(bytes);
|
| 32 |
+
}
|
node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/internal/utils/env.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* Read an environment variable.
|
| 5 |
+
*
|
| 6 |
+
* Trims beginning and trailing whitespace.
|
| 7 |
+
*
|
| 8 |
+
* Will return undefined if the environment variable doesn't exist or cannot be accessed.
|
| 9 |
+
*/
|
| 10 |
+
export const readEnv = (env: string): string | undefined => {
|
| 11 |
+
if (typeof (globalThis as any).process !== 'undefined') {
|
| 12 |
+
return (globalThis as any).process.env?.[env]?.trim() ?? undefined;
|
| 13 |
+
}
|
| 14 |
+
if (typeof (globalThis as any).Deno !== 'undefined') {
|
| 15 |
+
return (globalThis as any).Deno.env?.get?.(env)?.trim();
|
| 16 |
+
}
|
| 17 |
+
return undefined;
|
| 18 |
+
};
|
node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/internal/utils/log.ts
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
| 2 |
+
|
| 3 |
+
import { hasOwn } from './values';
|
| 4 |
+
import { type BaseAnthropic } from '../../client';
|
| 5 |
+
import { RequestOptions } from '../request-options';
|
| 6 |
+
|
| 7 |
+
type LogFn = (message: string, ...rest: unknown[]) => void;
|
| 8 |
+
export type Logger = {
|
| 9 |
+
error: LogFn;
|
| 10 |
+
warn: LogFn;
|
| 11 |
+
info: LogFn;
|
| 12 |
+
debug: LogFn;
|
| 13 |
+
};
|
| 14 |
+
export type LogLevel = 'off' | 'error' | 'warn' | 'info' | 'debug';
|
| 15 |
+
|
| 16 |
+
const levelNumbers = {
|
| 17 |
+
off: 0,
|
| 18 |
+
error: 200,
|
| 19 |
+
warn: 300,
|
| 20 |
+
info: 400,
|
| 21 |
+
debug: 500,
|
| 22 |
+
};
|
| 23 |
+
|
| 24 |
+
export const parseLogLevel = (
|
| 25 |
+
maybeLevel: string | undefined,
|
| 26 |
+
sourceName: string,
|
| 27 |
+
client: BaseAnthropic,
|
| 28 |
+
): LogLevel | undefined => {
|
| 29 |
+
if (!maybeLevel) {
|
| 30 |
+
return undefined;
|
| 31 |
+
}
|
| 32 |
+
if (hasOwn(levelNumbers, maybeLevel)) {
|
| 33 |
+
return maybeLevel;
|
| 34 |
+
}
|
| 35 |
+
loggerFor(client).warn(
|
| 36 |
+
`${sourceName} was set to ${JSON.stringify(maybeLevel)}, expected one of ${JSON.stringify(
|
| 37 |
+
Object.keys(levelNumbers),
|
| 38 |
+
)}`,
|
| 39 |
+
);
|
| 40 |
+
return undefined;
|
| 41 |
+
};
|
| 42 |
+
|
| 43 |
+
function noop() {}
|
| 44 |
+
|
| 45 |
+
function makeLogFn(fnLevel: keyof Logger, logger: Logger | undefined, logLevel: LogLevel) {
|
| 46 |
+
if (!logger || levelNumbers[fnLevel] > levelNumbers[logLevel]) {
|
| 47 |
+
return noop;
|
| 48 |
+
} else {
|
| 49 |
+
// Don't wrap logger functions, we want the stacktrace intact!
|
| 50 |
+
return logger[fnLevel].bind(logger);
|
| 51 |
+
}
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
const noopLogger = {
|
| 55 |
+
error: noop,
|
| 56 |
+
warn: noop,
|
| 57 |
+
info: noop,
|
| 58 |
+
debug: noop,
|
| 59 |
+
};
|
| 60 |
+
|
| 61 |
+
let cachedLoggers = /* @__PURE__ */ new WeakMap<Logger, [LogLevel, Logger]>();
|
| 62 |
+
|
| 63 |
+
export function loggerFor(client: BaseAnthropic): Logger {
|
| 64 |
+
const logger = client.logger;
|
| 65 |
+
const logLevel = client.logLevel ?? 'off';
|
| 66 |
+
if (!logger) {
|
| 67 |
+
return noopLogger;
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
const cachedLogger = cachedLoggers.get(logger);
|
| 71 |
+
if (cachedLogger && cachedLogger[0] === logLevel) {
|
| 72 |
+
return cachedLogger[1];
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
const levelLogger = {
|
| 76 |
+
error: makeLogFn('error', logger, logLevel),
|
| 77 |
+
warn: makeLogFn('warn', logger, logLevel),
|
| 78 |
+
info: makeLogFn('info', logger, logLevel),
|
| 79 |
+
debug: makeLogFn('debug', logger, logLevel),
|
| 80 |
+
};
|
| 81 |
+
|
| 82 |
+
cachedLoggers.set(logger, [logLevel, levelLogger]);
|
| 83 |
+
|
| 84 |
+
return levelLogger;
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
export const formatRequestDetails = (details: {
|
| 88 |
+
options?: RequestOptions | undefined;
|
| 89 |
+
headers?: Headers | Record<string, string> | undefined;
|
| 90 |
+
retryOfRequestLogID?: string | undefined;
|
| 91 |
+
retryOf?: string | undefined;
|
| 92 |
+
url?: string | undefined;
|
| 93 |
+
status?: number | undefined;
|
| 94 |
+
method?: string | undefined;
|
| 95 |
+
durationMs?: number | undefined;
|
| 96 |
+
message?: unknown;
|
| 97 |
+
body?: unknown;
|
| 98 |
+
}) => {
|
| 99 |
+
if (details.options) {
|
| 100 |
+
details.options = { ...details.options };
|
| 101 |
+
delete details.options['headers']; // redundant + leaks internals
|
| 102 |
+
}
|
| 103 |
+
if (details.headers) {
|
| 104 |
+
details.headers = Object.fromEntries(
|
| 105 |
+
(details.headers instanceof Headers ? [...details.headers] : Object.entries(details.headers)).map(
|
| 106 |
+
([name, value]) => [
|
| 107 |
+
name,
|
| 108 |
+
(
|
| 109 |
+
name.toLowerCase() === 'x-api-key' ||
|
| 110 |
+
name.toLowerCase() === 'authorization' ||
|
| 111 |
+
name.toLowerCase() === 'cookie' ||
|
| 112 |
+
name.toLowerCase() === 'set-cookie'
|
| 113 |
+
) ?
|
| 114 |
+
'***'
|
| 115 |
+
: value,
|
| 116 |
+
],
|
| 117 |
+
),
|
| 118 |
+
);
|
| 119 |
+
}
|
| 120 |
+
if ('retryOfRequestLogID' in details) {
|
| 121 |
+
if (details.retryOfRequestLogID) {
|
| 122 |
+
details.retryOf = details.retryOfRequestLogID;
|
| 123 |
+
}
|
| 124 |
+
delete details.retryOfRequestLogID;
|
| 125 |
+
}
|
| 126 |
+
return details;
|
| 127 |
+
};
|
node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/internal/utils/path.ts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { AnthropicError } from '../../core/error';
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* Percent-encode everything that isn't safe to have in a path without encoding safe chars.
|
| 5 |
+
*
|
| 6 |
+
* Taken from https://datatracker.ietf.org/doc/html/rfc3986#section-3.3:
|
| 7 |
+
* > unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
|
| 8 |
+
* > sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
|
| 9 |
+
* > pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
|
| 10 |
+
*/
|
| 11 |
+
export function encodeURIPath(str: string) {
|
| 12 |
+
return str.replace(/[^A-Za-z0-9\-._~!$&'()*+,;=:@]+/g, encodeURIComponent);
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
const EMPTY = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.create(null));
|
| 16 |
+
|
| 17 |
+
export const createPathTagFunction = (pathEncoder = encodeURIPath) =>
|
| 18 |
+
function path(statics: readonly string[], ...params: readonly unknown[]): string {
|
| 19 |
+
// If there are no params, no processing is needed.
|
| 20 |
+
if (statics.length === 1) return statics[0]!;
|
| 21 |
+
|
| 22 |
+
let postPath = false;
|
| 23 |
+
const invalidSegments = [];
|
| 24 |
+
const path = statics.reduce((previousValue, currentValue, index) => {
|
| 25 |
+
if (/[?#]/.test(currentValue)) {
|
| 26 |
+
postPath = true;
|
| 27 |
+
}
|
| 28 |
+
const value = params[index];
|
| 29 |
+
let encoded = (postPath ? encodeURIComponent : pathEncoder)('' + value);
|
| 30 |
+
if (
|
| 31 |
+
index !== params.length &&
|
| 32 |
+
(value == null ||
|
| 33 |
+
(typeof value === 'object' &&
|
| 34 |
+
// handle values from other realms
|
| 35 |
+
value.toString ===
|
| 36 |
+
Object.getPrototypeOf(Object.getPrototypeOf((value as any).hasOwnProperty ?? EMPTY) ?? EMPTY)
|
| 37 |
+
?.toString))
|
| 38 |
+
) {
|
| 39 |
+
encoded = value + '';
|
| 40 |
+
invalidSegments.push({
|
| 41 |
+
start: previousValue.length + currentValue.length,
|
| 42 |
+
length: encoded.length,
|
| 43 |
+
error: `Value of type ${Object.prototype.toString
|
| 44 |
+
.call(value)
|
| 45 |
+
.slice(8, -1)} is not a valid path parameter`,
|
| 46 |
+
});
|
| 47 |
+
}
|
| 48 |
+
return previousValue + currentValue + (index === params.length ? '' : encoded);
|
| 49 |
+
}, '');
|
| 50 |
+
|
| 51 |
+
const pathOnly = path.split(/[?#]/, 1)[0]!;
|
| 52 |
+
const invalidSegmentPattern = /(?<=^|\/)(?:\.|%2e){1,2}(?=\/|$)/gi;
|
| 53 |
+
let match;
|
| 54 |
+
|
| 55 |
+
// Find all invalid segments
|
| 56 |
+
while ((match = invalidSegmentPattern.exec(pathOnly)) !== null) {
|
| 57 |
+
invalidSegments.push({
|
| 58 |
+
start: match.index,
|
| 59 |
+
length: match[0].length,
|
| 60 |
+
error: `Value "${match[0]}" can\'t be safely passed as a path parameter`,
|
| 61 |
+
});
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
invalidSegments.sort((a, b) => a.start - b.start);
|
| 65 |
+
|
| 66 |
+
if (invalidSegments.length > 0) {
|
| 67 |
+
let lastEnd = 0;
|
| 68 |
+
const underline = invalidSegments.reduce((acc, segment) => {
|
| 69 |
+
const spaces = ' '.repeat(segment.start - lastEnd);
|
| 70 |
+
const arrows = '^'.repeat(segment.length);
|
| 71 |
+
lastEnd = segment.start + segment.length;
|
| 72 |
+
return acc + spaces + arrows;
|
| 73 |
+
}, '');
|
| 74 |
+
|
| 75 |
+
throw new AnthropicError(
|
| 76 |
+
`Path parameters result in path with invalid segments:\n${invalidSegments
|
| 77 |
+
.map((e) => e.error)
|
| 78 |
+
.join('\n')}\n${path}\n${underline}`,
|
| 79 |
+
);
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
return path;
|
| 83 |
+
};
|
| 84 |
+
|
| 85 |
+
/**
|
| 86 |
+
* URI-encodes path params and ensures no unsafe /./ or /../ path segments are introduced.
|
| 87 |
+
*/
|
| 88 |
+
export const path = /* @__PURE__ */ createPathTagFunction(encodeURIPath);
|
node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/internal/utils/sleep.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
| 2 |
+
|
| 3 |
+
export const sleep = (ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms));
|
node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/internal/utils/uuid.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* https://stackoverflow.com/a/2117523
|
| 5 |
+
*/
|
| 6 |
+
export let uuid4 = function () {
|
| 7 |
+
const { crypto } = globalThis as any;
|
| 8 |
+
if (crypto?.randomUUID) {
|
| 9 |
+
uuid4 = crypto.randomUUID.bind(crypto);
|
| 10 |
+
return crypto.randomUUID();
|
| 11 |
+
}
|
| 12 |
+
const u8 = new Uint8Array(1);
|
| 13 |
+
const randomByte = crypto ? () => crypto.getRandomValues(u8)[0]! : () => (Math.random() * 0xff) & 0xff;
|
| 14 |
+
return '10000000-1000-4000-8000-100000000000'.replace(/[018]/g, (c) =>
|
| 15 |
+
(+c ^ (randomByte() & (15 >> (+c / 4)))).toString(16),
|
| 16 |
+
);
|
| 17 |
+
};
|
node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/internal/utils/values.ts
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
| 2 |
+
|
| 3 |
+
import { AnthropicError } from '../../core/error';
|
| 4 |
+
|
| 5 |
+
// https://url.spec.whatwg.org/#url-scheme-string
|
| 6 |
+
const startsWithSchemeRegexp = /^[a-z][a-z0-9+.-]*:/i;
|
| 7 |
+
|
| 8 |
+
export const isAbsoluteURL = (url: string): boolean => {
|
| 9 |
+
return startsWithSchemeRegexp.test(url);
|
| 10 |
+
};
|
| 11 |
+
|
| 12 |
+
export let isArray = (val: unknown): val is unknown[] => ((isArray = Array.isArray), isArray(val));
|
| 13 |
+
export let isReadonlyArray = isArray as (val: unknown) => val is readonly unknown[];
|
| 14 |
+
|
| 15 |
+
/** Returns an object if the given value isn't an object, otherwise returns as-is */
|
| 16 |
+
export function maybeObj(x: unknown): object {
|
| 17 |
+
if (typeof x !== 'object') {
|
| 18 |
+
return {};
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
return x ?? {};
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
// https://stackoverflow.com/a/34491287
|
| 25 |
+
export function isEmptyObj(obj: Object | null | undefined): boolean {
|
| 26 |
+
if (!obj) return true;
|
| 27 |
+
for (const _k in obj) return false;
|
| 28 |
+
return true;
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
// https://eslint.org/docs/latest/rules/no-prototype-builtins
|
| 32 |
+
export function hasOwn<T extends object = object>(obj: T, key: PropertyKey): key is keyof T {
|
| 33 |
+
return Object.prototype.hasOwnProperty.call(obj, key);
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
export function isObj(obj: unknown): obj is Record<string, unknown> {
|
| 37 |
+
return obj != null && typeof obj === 'object' && !Array.isArray(obj);
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
export const ensurePresent = <T>(value: T | null | undefined): T => {
|
| 41 |
+
if (value == null) {
|
| 42 |
+
throw new AnthropicError(`Expected a value to be given but received ${value} instead.`);
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
return value;
|
| 46 |
+
};
|
| 47 |
+
|
| 48 |
+
export const validatePositiveInteger = (name: string, n: unknown): number => {
|
| 49 |
+
if (typeof n !== 'number' || !Number.isInteger(n)) {
|
| 50 |
+
throw new AnthropicError(`${name} must be an integer`);
|
| 51 |
+
}
|
| 52 |
+
if (n < 0) {
|
| 53 |
+
throw new AnthropicError(`${name} must be a positive integer`);
|
| 54 |
+
}
|
| 55 |
+
return n;
|
| 56 |
+
};
|
| 57 |
+
|
| 58 |
+
export const coerceInteger = (value: unknown): number => {
|
| 59 |
+
if (typeof value === 'number') return Math.round(value);
|
| 60 |
+
if (typeof value === 'string') return parseInt(value, 10);
|
| 61 |
+
|
| 62 |
+
throw new AnthropicError(`Could not coerce ${value} (type: ${typeof value}) into a number`);
|
| 63 |
+
};
|
| 64 |
+
|
| 65 |
+
export const coerceFloat = (value: unknown): number => {
|
| 66 |
+
if (typeof value === 'number') return value;
|
| 67 |
+
if (typeof value === 'string') return parseFloat(value);
|
| 68 |
+
|
| 69 |
+
throw new AnthropicError(`Could not coerce ${value} (type: ${typeof value}) into a number`);
|
| 70 |
+
};
|
| 71 |
+
|
| 72 |
+
export const coerceBoolean = (value: unknown): boolean => {
|
| 73 |
+
if (typeof value === 'boolean') return value;
|
| 74 |
+
if (typeof value === 'string') return value === 'true';
|
| 75 |
+
return Boolean(value);
|
| 76 |
+
};
|
| 77 |
+
|
| 78 |
+
export const maybeCoerceInteger = (value: unknown): number | undefined => {
|
| 79 |
+
if (value === undefined) {
|
| 80 |
+
return undefined;
|
| 81 |
+
}
|
| 82 |
+
return coerceInteger(value);
|
| 83 |
+
};
|
| 84 |
+
|
| 85 |
+
export const maybeCoerceFloat = (value: unknown): number | undefined => {
|
| 86 |
+
if (value === undefined) {
|
| 87 |
+
return undefined;
|
| 88 |
+
}
|
| 89 |
+
return coerceFloat(value);
|
| 90 |
+
};
|
| 91 |
+
|
| 92 |
+
export const maybeCoerceBoolean = (value: unknown): boolean | undefined => {
|
| 93 |
+
if (value === undefined) {
|
| 94 |
+
return undefined;
|
| 95 |
+
}
|
| 96 |
+
return coerceBoolean(value);
|
| 97 |
+
};
|
| 98 |
+
|
| 99 |
+
export const safeJSON = (text: string) => {
|
| 100 |
+
try {
|
| 101 |
+
return JSON.parse(text);
|
| 102 |
+
} catch (err) {
|
| 103 |
+
return undefined;
|
| 104 |
+
}
|
| 105 |
+
};
|
node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/lib/.keep
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
File generated from our OpenAPI spec by Stainless.
|
| 2 |
+
|
| 3 |
+
This directory can be used to store custom files to expand the SDK.
|
| 4 |
+
It is ignored by Stainless code generation and its content (other than this keep file) won't be touched.
|
node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/lib/BetaMessageStream.ts
ADDED
|
@@ -0,0 +1,727 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { isAbortError } from '../internal/errors';
|
| 2 |
+
import { AnthropicError, APIUserAbortError } from '../error';
|
| 3 |
+
import {
|
| 4 |
+
type BetaContentBlock,
|
| 5 |
+
Messages as BetaMessages,
|
| 6 |
+
type BetaMessage,
|
| 7 |
+
type BetaRawMessageStreamEvent as BetaMessageStreamEvent,
|
| 8 |
+
type BetaMessageParam,
|
| 9 |
+
type MessageCreateParams as BetaMessageCreateParams,
|
| 10 |
+
type MessageCreateParamsBase as BetaMessageCreateParamsBase,
|
| 11 |
+
type BetaTextBlock,
|
| 12 |
+
type BetaTextCitation,
|
| 13 |
+
type BetaToolUseBlock,
|
| 14 |
+
type BetaServerToolUseBlock,
|
| 15 |
+
type BetaMCPToolUseBlock,
|
| 16 |
+
} from '../resources/beta/messages/messages';
|
| 17 |
+
import { Stream } from '../streaming';
|
| 18 |
+
import { partialParse } from '../_vendor/partial-json-parser/parser';
|
| 19 |
+
import { type RequestOptions } from '../internal/request-options';
|
| 20 |
+
|
| 21 |
+
export interface MessageStreamEvents {
|
| 22 |
+
connect: () => void;
|
| 23 |
+
streamEvent: (event: BetaMessageStreamEvent, snapshot: BetaMessage) => void;
|
| 24 |
+
text: (textDelta: string, textSnapshot: string) => void;
|
| 25 |
+
citation: (citation: BetaTextCitation, citationsSnapshot: BetaTextCitation[]) => void;
|
| 26 |
+
inputJson: (partialJson: string, jsonSnapshot: unknown) => void;
|
| 27 |
+
thinking: (thinkingDelta: string, thinkingSnapshot: string) => void;
|
| 28 |
+
signature: (signature: string) => void;
|
| 29 |
+
message: (message: BetaMessage) => void;
|
| 30 |
+
contentBlock: (content: BetaContentBlock) => void;
|
| 31 |
+
finalMessage: (message: BetaMessage) => void;
|
| 32 |
+
error: (error: AnthropicError) => void;
|
| 33 |
+
abort: (error: APIUserAbortError) => void;
|
| 34 |
+
end: () => void;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
type MessageStreamEventListeners<Event extends keyof MessageStreamEvents> = {
|
| 38 |
+
listener: MessageStreamEvents[Event];
|
| 39 |
+
once?: boolean;
|
| 40 |
+
}[];
|
| 41 |
+
|
| 42 |
+
const JSON_BUF_PROPERTY = '__json_buf';
|
| 43 |
+
|
| 44 |
+
export type TracksToolInput = BetaToolUseBlock | BetaServerToolUseBlock | BetaMCPToolUseBlock;
|
| 45 |
+
|
| 46 |
+
function tracksToolInput(content: BetaContentBlock): content is TracksToolInput {
|
| 47 |
+
return content.type === 'tool_use' || content.type === 'server_tool_use' || content.type === 'mcp_tool_use';
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
export class BetaMessageStream implements AsyncIterable<BetaMessageStreamEvent> {
|
| 51 |
+
messages: BetaMessageParam[] = [];
|
| 52 |
+
receivedMessages: BetaMessage[] = [];
|
| 53 |
+
#currentMessageSnapshot: BetaMessage | undefined;
|
| 54 |
+
|
| 55 |
+
controller: AbortController = new AbortController();
|
| 56 |
+
|
| 57 |
+
#connectedPromise: Promise<Response | null>;
|
| 58 |
+
#resolveConnectedPromise: (response: Response | null) => void = () => {};
|
| 59 |
+
#rejectConnectedPromise: (error: AnthropicError) => void = () => {};
|
| 60 |
+
|
| 61 |
+
#endPromise: Promise<void>;
|
| 62 |
+
#resolveEndPromise: () => void = () => {};
|
| 63 |
+
#rejectEndPromise: (error: AnthropicError) => void = () => {};
|
| 64 |
+
|
| 65 |
+
#listeners: { [Event in keyof MessageStreamEvents]?: MessageStreamEventListeners<Event> } = {};
|
| 66 |
+
|
| 67 |
+
#ended = false;
|
| 68 |
+
#errored = false;
|
| 69 |
+
#aborted = false;
|
| 70 |
+
#catchingPromiseCreated = false;
|
| 71 |
+
#response: Response | null | undefined;
|
| 72 |
+
#request_id: string | null | undefined;
|
| 73 |
+
|
| 74 |
+
constructor() {
|
| 75 |
+
this.#connectedPromise = new Promise<Response | null>((resolve, reject) => {
|
| 76 |
+
this.#resolveConnectedPromise = resolve;
|
| 77 |
+
this.#rejectConnectedPromise = reject;
|
| 78 |
+
});
|
| 79 |
+
|
| 80 |
+
this.#endPromise = new Promise<void>((resolve, reject) => {
|
| 81 |
+
this.#resolveEndPromise = resolve;
|
| 82 |
+
this.#rejectEndPromise = reject;
|
| 83 |
+
});
|
| 84 |
+
|
| 85 |
+
// Don't let these promises cause unhandled rejection errors.
|
| 86 |
+
// we will manually cause an unhandled rejection error later
|
| 87 |
+
// if the user hasn't registered any error listener or called
|
| 88 |
+
// any promise-returning method.
|
| 89 |
+
this.#connectedPromise.catch(() => {});
|
| 90 |
+
this.#endPromise.catch(() => {});
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
get response(): Response | null | undefined {
|
| 94 |
+
return this.#response;
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
get request_id(): string | null | undefined {
|
| 98 |
+
return this.#request_id;
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
/**
|
| 102 |
+
* Returns the `MessageStream` data, the raw `Response` instance and the ID of the request,
|
| 103 |
+
* returned vie the `request-id` header which is useful for debugging requests and resporting
|
| 104 |
+
* issues to Anthropic.
|
| 105 |
+
*
|
| 106 |
+
* This is the same as the `APIPromise.withResponse()` method.
|
| 107 |
+
*
|
| 108 |
+
* This method will raise an error if you created the stream using `MessageStream.fromReadableStream`
|
| 109 |
+
* as no `Response` is available.
|
| 110 |
+
*/
|
| 111 |
+
async withResponse(): Promise<{
|
| 112 |
+
data: BetaMessageStream;
|
| 113 |
+
response: Response;
|
| 114 |
+
request_id: string | null | undefined;
|
| 115 |
+
}> {
|
| 116 |
+
const response = await this.#connectedPromise;
|
| 117 |
+
if (!response) {
|
| 118 |
+
throw new Error('Could not resolve a `Response` object');
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
return {
|
| 122 |
+
data: this,
|
| 123 |
+
response,
|
| 124 |
+
request_id: response.headers.get('request-id'),
|
| 125 |
+
};
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
/**
|
| 129 |
+
* Intended for use on the frontend, consuming a stream produced with
|
| 130 |
+
* `.toReadableStream()` on the backend.
|
| 131 |
+
*
|
| 132 |
+
* Note that messages sent to the model do not appear in `.on('message')`
|
| 133 |
+
* in this context.
|
| 134 |
+
*/
|
| 135 |
+
static fromReadableStream(stream: ReadableStream): BetaMessageStream {
|
| 136 |
+
const runner = new BetaMessageStream();
|
| 137 |
+
runner._run(() => runner._fromReadableStream(stream));
|
| 138 |
+
return runner;
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
static createMessage(
|
| 142 |
+
messages: BetaMessages,
|
| 143 |
+
params: BetaMessageCreateParamsBase,
|
| 144 |
+
options?: RequestOptions,
|
| 145 |
+
): BetaMessageStream {
|
| 146 |
+
const runner = new BetaMessageStream();
|
| 147 |
+
for (const message of params.messages) {
|
| 148 |
+
runner._addMessageParam(message);
|
| 149 |
+
}
|
| 150 |
+
runner._run(() =>
|
| 151 |
+
runner._createMessage(
|
| 152 |
+
messages,
|
| 153 |
+
{ ...params, stream: true },
|
| 154 |
+
{ ...options, headers: { ...options?.headers, 'X-Stainless-Helper-Method': 'stream' } },
|
| 155 |
+
),
|
| 156 |
+
);
|
| 157 |
+
return runner;
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
protected _run(executor: () => Promise<any>) {
|
| 161 |
+
executor().then(() => {
|
| 162 |
+
this._emitFinal();
|
| 163 |
+
this._emit('end');
|
| 164 |
+
}, this.#handleError);
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
protected _addMessageParam(message: BetaMessageParam) {
|
| 168 |
+
this.messages.push(message);
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
protected _addMessage(message: BetaMessage, emit = true) {
|
| 172 |
+
this.receivedMessages.push(message);
|
| 173 |
+
if (emit) {
|
| 174 |
+
this._emit('message', message);
|
| 175 |
+
}
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
protected async _createMessage(
|
| 179 |
+
messages: BetaMessages,
|
| 180 |
+
params: BetaMessageCreateParams,
|
| 181 |
+
options?: RequestOptions,
|
| 182 |
+
): Promise<void> {
|
| 183 |
+
const signal = options?.signal;
|
| 184 |
+
let abortHandler: (() => void) | undefined;
|
| 185 |
+
if (signal) {
|
| 186 |
+
if (signal.aborted) this.controller.abort();
|
| 187 |
+
abortHandler = this.controller.abort.bind(this.controller);
|
| 188 |
+
signal.addEventListener('abort', abortHandler);
|
| 189 |
+
}
|
| 190 |
+
try {
|
| 191 |
+
this.#beginRequest();
|
| 192 |
+
const { response, data: stream } = await messages
|
| 193 |
+
.create({ ...params, stream: true }, { ...options, signal: this.controller.signal })
|
| 194 |
+
.withResponse();
|
| 195 |
+
this._connected(response);
|
| 196 |
+
for await (const event of stream) {
|
| 197 |
+
this.#addStreamEvent(event);
|
| 198 |
+
}
|
| 199 |
+
if (stream.controller.signal?.aborted) {
|
| 200 |
+
throw new APIUserAbortError();
|
| 201 |
+
}
|
| 202 |
+
this.#endRequest();
|
| 203 |
+
} finally {
|
| 204 |
+
if (signal && abortHandler) {
|
| 205 |
+
signal.removeEventListener('abort', abortHandler);
|
| 206 |
+
}
|
| 207 |
+
}
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
protected _connected(response: Response | null) {
|
| 211 |
+
if (this.ended) return;
|
| 212 |
+
this.#response = response;
|
| 213 |
+
this.#request_id = response?.headers.get('request-id');
|
| 214 |
+
this.#resolveConnectedPromise(response);
|
| 215 |
+
this._emit('connect');
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
get ended(): boolean {
|
| 219 |
+
return this.#ended;
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
get errored(): boolean {
|
| 223 |
+
return this.#errored;
|
| 224 |
+
}
|
| 225 |
+
|
| 226 |
+
get aborted(): boolean {
|
| 227 |
+
return this.#aborted;
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
abort() {
|
| 231 |
+
this.controller.abort();
|
| 232 |
+
}
|
| 233 |
+
|
| 234 |
+
/**
|
| 235 |
+
* Adds the listener function to the end of the listeners array for the event.
|
| 236 |
+
* No checks are made to see if the listener has already been added. Multiple calls passing
|
| 237 |
+
* the same combination of event and listener will result in the listener being added, and
|
| 238 |
+
* called, multiple times.
|
| 239 |
+
* @returns this MessageStream, so that calls can be chained
|
| 240 |
+
*/
|
| 241 |
+
on<Event extends keyof MessageStreamEvents>(event: Event, listener: MessageStreamEvents[Event]): this {
|
| 242 |
+
const listeners: MessageStreamEventListeners<Event> =
|
| 243 |
+
this.#listeners[event] || (this.#listeners[event] = []);
|
| 244 |
+
listeners.push({ listener });
|
| 245 |
+
return this;
|
| 246 |
+
}
|
| 247 |
+
|
| 248 |
+
/**
|
| 249 |
+
* Removes the specified listener from the listener array for the event.
|
| 250 |
+
* off() will remove, at most, one instance of a listener from the listener array. If any single
|
| 251 |
+
* listener has been added multiple times to the listener array for the specified event, then
|
| 252 |
+
* off() must be called multiple times to remove each instance.
|
| 253 |
+
* @returns this MessageStream, so that calls can be chained
|
| 254 |
+
*/
|
| 255 |
+
off<Event extends keyof MessageStreamEvents>(event: Event, listener: MessageStreamEvents[Event]): this {
|
| 256 |
+
const listeners = this.#listeners[event];
|
| 257 |
+
if (!listeners) return this;
|
| 258 |
+
const index = listeners.findIndex((l) => l.listener === listener);
|
| 259 |
+
if (index >= 0) listeners.splice(index, 1);
|
| 260 |
+
return this;
|
| 261 |
+
}
|
| 262 |
+
|
| 263 |
+
/**
|
| 264 |
+
* Adds a one-time listener function for the event. The next time the event is triggered,
|
| 265 |
+
* this listener is removed and then invoked.
|
| 266 |
+
* @returns this MessageStream, so that calls can be chained
|
| 267 |
+
*/
|
| 268 |
+
once<Event extends keyof MessageStreamEvents>(event: Event, listener: MessageStreamEvents[Event]): this {
|
| 269 |
+
const listeners: MessageStreamEventListeners<Event> =
|
| 270 |
+
this.#listeners[event] || (this.#listeners[event] = []);
|
| 271 |
+
listeners.push({ listener, once: true });
|
| 272 |
+
return this;
|
| 273 |
+
}
|
| 274 |
+
|
| 275 |
+
/**
|
| 276 |
+
* This is similar to `.once()`, but returns a Promise that resolves the next time
|
| 277 |
+
* the event is triggered, instead of calling a listener callback.
|
| 278 |
+
* @returns a Promise that resolves the next time given event is triggered,
|
| 279 |
+
* or rejects if an error is emitted. (If you request the 'error' event,
|
| 280 |
+
* returns a promise that resolves with the error).
|
| 281 |
+
*
|
| 282 |
+
* Example:
|
| 283 |
+
*
|
| 284 |
+
* const message = await stream.emitted('message') // rejects if the stream errors
|
| 285 |
+
*/
|
| 286 |
+
emitted<Event extends keyof MessageStreamEvents>(
|
| 287 |
+
event: Event,
|
| 288 |
+
): Promise<
|
| 289 |
+
Parameters<MessageStreamEvents[Event]> extends [infer Param] ? Param
|
| 290 |
+
: Parameters<MessageStreamEvents[Event]> extends [] ? void
|
| 291 |
+
: Parameters<MessageStreamEvents[Event]>
|
| 292 |
+
> {
|
| 293 |
+
return new Promise((resolve, reject) => {
|
| 294 |
+
this.#catchingPromiseCreated = true;
|
| 295 |
+
if (event !== 'error') this.once('error', reject);
|
| 296 |
+
this.once(event, resolve as any);
|
| 297 |
+
});
|
| 298 |
+
}
|
| 299 |
+
|
| 300 |
+
async done(): Promise<void> {
|
| 301 |
+
this.#catchingPromiseCreated = true;
|
| 302 |
+
await this.#endPromise;
|
| 303 |
+
}
|
| 304 |
+
|
| 305 |
+
get currentMessage(): BetaMessage | undefined {
|
| 306 |
+
return this.#currentMessageSnapshot;
|
| 307 |
+
}
|
| 308 |
+
|
| 309 |
+
#getFinalMessage(): BetaMessage {
|
| 310 |
+
if (this.receivedMessages.length === 0) {
|
| 311 |
+
throw new AnthropicError('stream ended without producing a Message with role=assistant');
|
| 312 |
+
}
|
| 313 |
+
return this.receivedMessages.at(-1)!;
|
| 314 |
+
}
|
| 315 |
+
|
| 316 |
+
/**
|
| 317 |
+
* @returns a promise that resolves with the the final assistant Message response,
|
| 318 |
+
* or rejects if an error occurred or the stream ended prematurely without producing a Message.
|
| 319 |
+
*/
|
| 320 |
+
async finalMessage(): Promise<BetaMessage> {
|
| 321 |
+
await this.done();
|
| 322 |
+
return this.#getFinalMessage();
|
| 323 |
+
}
|
| 324 |
+
|
| 325 |
+
#getFinalText(): string {
|
| 326 |
+
if (this.receivedMessages.length === 0) {
|
| 327 |
+
throw new AnthropicError('stream ended without producing a Message with role=assistant');
|
| 328 |
+
}
|
| 329 |
+
const textBlocks = this.receivedMessages
|
| 330 |
+
.at(-1)!
|
| 331 |
+
.content.filter((block): block is BetaTextBlock => block.type === 'text')
|
| 332 |
+
.map((block) => block.text);
|
| 333 |
+
if (textBlocks.length === 0) {
|
| 334 |
+
throw new AnthropicError('stream ended without producing a content block with type=text');
|
| 335 |
+
}
|
| 336 |
+
return textBlocks.join(' ');
|
| 337 |
+
}
|
| 338 |
+
|
| 339 |
+
/**
|
| 340 |
+
* @returns a promise that resolves with the the final assistant Message's text response, concatenated
|
| 341 |
+
* together if there are more than one text blocks.
|
| 342 |
+
* Rejects if an error occurred or the stream ended prematurely without producing a Message.
|
| 343 |
+
*/
|
| 344 |
+
async finalText(): Promise<string> {
|
| 345 |
+
await this.done();
|
| 346 |
+
return this.#getFinalText();
|
| 347 |
+
}
|
| 348 |
+
|
| 349 |
+
#handleError = (error: unknown) => {
|
| 350 |
+
this.#errored = true;
|
| 351 |
+
if (isAbortError(error)) {
|
| 352 |
+
error = new APIUserAbortError();
|
| 353 |
+
}
|
| 354 |
+
if (error instanceof APIUserAbortError) {
|
| 355 |
+
this.#aborted = true;
|
| 356 |
+
return this._emit('abort', error);
|
| 357 |
+
}
|
| 358 |
+
if (error instanceof AnthropicError) {
|
| 359 |
+
return this._emit('error', error);
|
| 360 |
+
}
|
| 361 |
+
if (error instanceof Error) {
|
| 362 |
+
const anthropicError: AnthropicError = new AnthropicError(error.message);
|
| 363 |
+
// @ts-ignore
|
| 364 |
+
anthropicError.cause = error;
|
| 365 |
+
return this._emit('error', anthropicError);
|
| 366 |
+
}
|
| 367 |
+
return this._emit('error', new AnthropicError(String(error)));
|
| 368 |
+
};
|
| 369 |
+
|
| 370 |
+
protected _emit<Event extends keyof MessageStreamEvents>(
|
| 371 |
+
event: Event,
|
| 372 |
+
...args: Parameters<MessageStreamEvents[Event]>
|
| 373 |
+
) {
|
| 374 |
+
// make sure we don't emit any MessageStreamEvents after end
|
| 375 |
+
if (this.#ended) return;
|
| 376 |
+
|
| 377 |
+
if (event === 'end') {
|
| 378 |
+
this.#ended = true;
|
| 379 |
+
this.#resolveEndPromise();
|
| 380 |
+
}
|
| 381 |
+
|
| 382 |
+
const listeners: MessageStreamEventListeners<Event> | undefined = this.#listeners[event];
|
| 383 |
+
if (listeners) {
|
| 384 |
+
this.#listeners[event] = listeners.filter((l) => !l.once) as any;
|
| 385 |
+
listeners.forEach(({ listener }: any) => listener(...args));
|
| 386 |
+
}
|
| 387 |
+
|
| 388 |
+
if (event === 'abort') {
|
| 389 |
+
const error = args[0] as APIUserAbortError;
|
| 390 |
+
if (!this.#catchingPromiseCreated && !listeners?.length) {
|
| 391 |
+
Promise.reject(error);
|
| 392 |
+
}
|
| 393 |
+
this.#rejectConnectedPromise(error);
|
| 394 |
+
this.#rejectEndPromise(error);
|
| 395 |
+
this._emit('end');
|
| 396 |
+
return;
|
| 397 |
+
}
|
| 398 |
+
|
| 399 |
+
if (event === 'error') {
|
| 400 |
+
// NOTE: _emit('error', error) should only be called from #handleError().
|
| 401 |
+
|
| 402 |
+
const error = args[0] as AnthropicError;
|
| 403 |
+
if (!this.#catchingPromiseCreated && !listeners?.length) {
|
| 404 |
+
// Trigger an unhandled rejection if the user hasn't registered any error handlers.
|
| 405 |
+
// If you are seeing stack traces here, make sure to handle errors via either:
|
| 406 |
+
// - runner.on('error', () => ...)
|
| 407 |
+
// - await runner.done()
|
| 408 |
+
// - await runner.final...()
|
| 409 |
+
// - etc.
|
| 410 |
+
Promise.reject(error);
|
| 411 |
+
}
|
| 412 |
+
this.#rejectConnectedPromise(error);
|
| 413 |
+
this.#rejectEndPromise(error);
|
| 414 |
+
this._emit('end');
|
| 415 |
+
}
|
| 416 |
+
}
|
| 417 |
+
|
| 418 |
+
protected _emitFinal() {
|
| 419 |
+
const finalMessage = this.receivedMessages.at(-1);
|
| 420 |
+
if (finalMessage) {
|
| 421 |
+
this._emit('finalMessage', this.#getFinalMessage());
|
| 422 |
+
}
|
| 423 |
+
}
|
| 424 |
+
|
| 425 |
+
#beginRequest() {
|
| 426 |
+
if (this.ended) return;
|
| 427 |
+
this.#currentMessageSnapshot = undefined;
|
| 428 |
+
}
|
| 429 |
+
#addStreamEvent(event: BetaMessageStreamEvent) {
|
| 430 |
+
if (this.ended) return;
|
| 431 |
+
const messageSnapshot = this.#accumulateMessage(event);
|
| 432 |
+
this._emit('streamEvent', event, messageSnapshot);
|
| 433 |
+
|
| 434 |
+
switch (event.type) {
|
| 435 |
+
case 'content_block_delta': {
|
| 436 |
+
const content = messageSnapshot.content.at(-1)!;
|
| 437 |
+
switch (event.delta.type) {
|
| 438 |
+
case 'text_delta': {
|
| 439 |
+
if (content.type === 'text') {
|
| 440 |
+
this._emit('text', event.delta.text, content.text || '');
|
| 441 |
+
}
|
| 442 |
+
break;
|
| 443 |
+
}
|
| 444 |
+
case 'citations_delta': {
|
| 445 |
+
if (content.type === 'text') {
|
| 446 |
+
this._emit('citation', event.delta.citation, content.citations ?? []);
|
| 447 |
+
}
|
| 448 |
+
break;
|
| 449 |
+
}
|
| 450 |
+
case 'input_json_delta': {
|
| 451 |
+
if (tracksToolInput(content) && content.input) {
|
| 452 |
+
this._emit('inputJson', event.delta.partial_json, content.input);
|
| 453 |
+
}
|
| 454 |
+
break;
|
| 455 |
+
}
|
| 456 |
+
case 'thinking_delta': {
|
| 457 |
+
if (content.type === 'thinking') {
|
| 458 |
+
this._emit('thinking', event.delta.thinking, content.thinking);
|
| 459 |
+
}
|
| 460 |
+
break;
|
| 461 |
+
}
|
| 462 |
+
case 'signature_delta': {
|
| 463 |
+
if (content.type === 'thinking') {
|
| 464 |
+
this._emit('signature', content.signature);
|
| 465 |
+
}
|
| 466 |
+
break;
|
| 467 |
+
}
|
| 468 |
+
default:
|
| 469 |
+
checkNever(event.delta);
|
| 470 |
+
}
|
| 471 |
+
break;
|
| 472 |
+
}
|
| 473 |
+
case 'message_stop': {
|
| 474 |
+
this._addMessageParam(messageSnapshot);
|
| 475 |
+
this._addMessage(messageSnapshot, true);
|
| 476 |
+
break;
|
| 477 |
+
}
|
| 478 |
+
case 'content_block_stop': {
|
| 479 |
+
this._emit('contentBlock', messageSnapshot.content.at(-1)!);
|
| 480 |
+
break;
|
| 481 |
+
}
|
| 482 |
+
case 'message_start': {
|
| 483 |
+
this.#currentMessageSnapshot = messageSnapshot;
|
| 484 |
+
break;
|
| 485 |
+
}
|
| 486 |
+
case 'content_block_start':
|
| 487 |
+
case 'message_delta':
|
| 488 |
+
break;
|
| 489 |
+
}
|
| 490 |
+
}
|
| 491 |
+
#endRequest(): BetaMessage {
|
| 492 |
+
if (this.ended) {
|
| 493 |
+
throw new AnthropicError(`stream has ended, this shouldn't happen`);
|
| 494 |
+
}
|
| 495 |
+
const snapshot = this.#currentMessageSnapshot;
|
| 496 |
+
if (!snapshot) {
|
| 497 |
+
throw new AnthropicError(`request ended without sending any chunks`);
|
| 498 |
+
}
|
| 499 |
+
this.#currentMessageSnapshot = undefined;
|
| 500 |
+
return snapshot;
|
| 501 |
+
}
|
| 502 |
+
|
| 503 |
+
protected async _fromReadableStream(
|
| 504 |
+
readableStream: ReadableStream,
|
| 505 |
+
options?: RequestOptions,
|
| 506 |
+
): Promise<void> {
|
| 507 |
+
const signal = options?.signal;
|
| 508 |
+
let abortHandler: (() => void) | undefined;
|
| 509 |
+
if (signal) {
|
| 510 |
+
if (signal.aborted) this.controller.abort();
|
| 511 |
+
abortHandler = this.controller.abort.bind(this.controller);
|
| 512 |
+
signal.addEventListener('abort', abortHandler);
|
| 513 |
+
}
|
| 514 |
+
try {
|
| 515 |
+
this.#beginRequest();
|
| 516 |
+
this._connected(null);
|
| 517 |
+
const stream = Stream.fromReadableStream<BetaMessageStreamEvent>(readableStream, this.controller);
|
| 518 |
+
for await (const event of stream) {
|
| 519 |
+
this.#addStreamEvent(event);
|
| 520 |
+
}
|
| 521 |
+
if (stream.controller.signal?.aborted) {
|
| 522 |
+
throw new APIUserAbortError();
|
| 523 |
+
}
|
| 524 |
+
this.#endRequest();
|
| 525 |
+
} finally {
|
| 526 |
+
if (signal && abortHandler) {
|
| 527 |
+
signal.removeEventListener('abort', abortHandler);
|
| 528 |
+
}
|
| 529 |
+
}
|
| 530 |
+
}
|
| 531 |
+
|
| 532 |
+
/**
|
| 533 |
+
* Mutates this.#currentMessage with the current event. Handling the accumulation of multiple messages
|
| 534 |
+
* will be needed to be handled by the caller, this method will throw if you try to accumulate for multiple
|
| 535 |
+
* messages.
|
| 536 |
+
*/
|
| 537 |
+
#accumulateMessage(event: BetaMessageStreamEvent): BetaMessage {
|
| 538 |
+
let snapshot = this.#currentMessageSnapshot;
|
| 539 |
+
|
| 540 |
+
if (event.type === 'message_start') {
|
| 541 |
+
if (snapshot) {
|
| 542 |
+
throw new AnthropicError(`Unexpected event order, got ${event.type} before receiving "message_stop"`);
|
| 543 |
+
}
|
| 544 |
+
return event.message;
|
| 545 |
+
}
|
| 546 |
+
|
| 547 |
+
if (!snapshot) {
|
| 548 |
+
throw new AnthropicError(`Unexpected event order, got ${event.type} before "message_start"`);
|
| 549 |
+
}
|
| 550 |
+
|
| 551 |
+
switch (event.type) {
|
| 552 |
+
case 'message_stop':
|
| 553 |
+
return snapshot;
|
| 554 |
+
case 'message_delta':
|
| 555 |
+
snapshot.container = event.delta.container;
|
| 556 |
+
snapshot.stop_reason = event.delta.stop_reason;
|
| 557 |
+
snapshot.stop_sequence = event.delta.stop_sequence;
|
| 558 |
+
snapshot.usage.output_tokens = event.usage.output_tokens;
|
| 559 |
+
|
| 560 |
+
if (event.usage.input_tokens != null) {
|
| 561 |
+
snapshot.usage.input_tokens = event.usage.input_tokens;
|
| 562 |
+
}
|
| 563 |
+
|
| 564 |
+
if (event.usage.cache_creation_input_tokens != null) {
|
| 565 |
+
snapshot.usage.cache_creation_input_tokens = event.usage.cache_creation_input_tokens;
|
| 566 |
+
}
|
| 567 |
+
|
| 568 |
+
if (event.usage.cache_read_input_tokens != null) {
|
| 569 |
+
snapshot.usage.cache_read_input_tokens = event.usage.cache_read_input_tokens;
|
| 570 |
+
}
|
| 571 |
+
|
| 572 |
+
if (event.usage.server_tool_use != null) {
|
| 573 |
+
snapshot.usage.server_tool_use = event.usage.server_tool_use;
|
| 574 |
+
}
|
| 575 |
+
|
| 576 |
+
return snapshot;
|
| 577 |
+
case 'content_block_start':
|
| 578 |
+
snapshot.content.push(event.content_block);
|
| 579 |
+
return snapshot;
|
| 580 |
+
case 'content_block_delta': {
|
| 581 |
+
const snapshotContent = snapshot.content.at(event.index);
|
| 582 |
+
|
| 583 |
+
switch (event.delta.type) {
|
| 584 |
+
case 'text_delta': {
|
| 585 |
+
if (snapshotContent?.type === 'text') {
|
| 586 |
+
snapshot.content[event.index] = {
|
| 587 |
+
...snapshotContent,
|
| 588 |
+
text: (snapshotContent.text || '') + event.delta.text,
|
| 589 |
+
};
|
| 590 |
+
}
|
| 591 |
+
break;
|
| 592 |
+
}
|
| 593 |
+
case 'citations_delta': {
|
| 594 |
+
if (snapshotContent?.type === 'text') {
|
| 595 |
+
snapshot.content[event.index] = {
|
| 596 |
+
...snapshotContent,
|
| 597 |
+
citations: [...(snapshotContent.citations ?? []), event.delta.citation],
|
| 598 |
+
};
|
| 599 |
+
}
|
| 600 |
+
break;
|
| 601 |
+
}
|
| 602 |
+
case 'input_json_delta': {
|
| 603 |
+
if (snapshotContent && tracksToolInput(snapshotContent)) {
|
| 604 |
+
// we need to keep track of the raw JSON string as well so that we can
|
| 605 |
+
// re-parse it for each delta, for now we just store it as an untyped
|
| 606 |
+
// non-enumerable property on the snapshot
|
| 607 |
+
let jsonBuf = (snapshotContent as any)[JSON_BUF_PROPERTY] || '';
|
| 608 |
+
jsonBuf += event.delta.partial_json;
|
| 609 |
+
|
| 610 |
+
const newContent = { ...snapshotContent };
|
| 611 |
+
Object.defineProperty(newContent, JSON_BUF_PROPERTY, {
|
| 612 |
+
value: jsonBuf,
|
| 613 |
+
enumerable: false,
|
| 614 |
+
writable: true,
|
| 615 |
+
});
|
| 616 |
+
|
| 617 |
+
if (jsonBuf) {
|
| 618 |
+
try {
|
| 619 |
+
newContent.input = partialParse(jsonBuf);
|
| 620 |
+
} catch (err) {
|
| 621 |
+
const error = new AnthropicError(
|
| 622 |
+
`Unable to parse tool parameter JSON from model. Please retry your request or adjust your prompt. Error: ${err}. JSON: ${jsonBuf}`,
|
| 623 |
+
);
|
| 624 |
+
this.#handleError(error);
|
| 625 |
+
}
|
| 626 |
+
}
|
| 627 |
+
snapshot.content[event.index] = newContent;
|
| 628 |
+
}
|
| 629 |
+
break;
|
| 630 |
+
}
|
| 631 |
+
case 'thinking_delta': {
|
| 632 |
+
if (snapshotContent?.type === 'thinking') {
|
| 633 |
+
snapshot.content[event.index] = {
|
| 634 |
+
...snapshotContent,
|
| 635 |
+
thinking: snapshotContent.thinking + event.delta.thinking,
|
| 636 |
+
};
|
| 637 |
+
}
|
| 638 |
+
break;
|
| 639 |
+
}
|
| 640 |
+
case 'signature_delta': {
|
| 641 |
+
if (snapshotContent?.type === 'thinking') {
|
| 642 |
+
snapshot.content[event.index] = {
|
| 643 |
+
...snapshotContent,
|
| 644 |
+
signature: event.delta.signature,
|
| 645 |
+
};
|
| 646 |
+
}
|
| 647 |
+
break;
|
| 648 |
+
}
|
| 649 |
+
default:
|
| 650 |
+
checkNever(event.delta);
|
| 651 |
+
}
|
| 652 |
+
return snapshot;
|
| 653 |
+
}
|
| 654 |
+
case 'content_block_stop':
|
| 655 |
+
return snapshot;
|
| 656 |
+
}
|
| 657 |
+
}
|
| 658 |
+
|
| 659 |
+
[Symbol.asyncIterator](): AsyncIterator<BetaMessageStreamEvent> {
|
| 660 |
+
const pushQueue: BetaMessageStreamEvent[] = [];
|
| 661 |
+
const readQueue: {
|
| 662 |
+
resolve: (chunk: BetaMessageStreamEvent | undefined) => void;
|
| 663 |
+
reject: (error: unknown) => void;
|
| 664 |
+
}[] = [];
|
| 665 |
+
let done = false;
|
| 666 |
+
|
| 667 |
+
this.on('streamEvent', (event) => {
|
| 668 |
+
const reader = readQueue.shift();
|
| 669 |
+
if (reader) {
|
| 670 |
+
reader.resolve(event);
|
| 671 |
+
} else {
|
| 672 |
+
pushQueue.push(event);
|
| 673 |
+
}
|
| 674 |
+
});
|
| 675 |
+
|
| 676 |
+
this.on('end', () => {
|
| 677 |
+
done = true;
|
| 678 |
+
for (const reader of readQueue) {
|
| 679 |
+
reader.resolve(undefined);
|
| 680 |
+
}
|
| 681 |
+
readQueue.length = 0;
|
| 682 |
+
});
|
| 683 |
+
|
| 684 |
+
this.on('abort', (err) => {
|
| 685 |
+
done = true;
|
| 686 |
+
for (const reader of readQueue) {
|
| 687 |
+
reader.reject(err);
|
| 688 |
+
}
|
| 689 |
+
readQueue.length = 0;
|
| 690 |
+
});
|
| 691 |
+
|
| 692 |
+
this.on('error', (err) => {
|
| 693 |
+
done = true;
|
| 694 |
+
for (const reader of readQueue) {
|
| 695 |
+
reader.reject(err);
|
| 696 |
+
}
|
| 697 |
+
readQueue.length = 0;
|
| 698 |
+
});
|
| 699 |
+
|
| 700 |
+
return {
|
| 701 |
+
next: async (): Promise<IteratorResult<BetaMessageStreamEvent>> => {
|
| 702 |
+
if (!pushQueue.length) {
|
| 703 |
+
if (done) {
|
| 704 |
+
return { value: undefined, done: true };
|
| 705 |
+
}
|
| 706 |
+
return new Promise<BetaMessageStreamEvent | undefined>((resolve, reject) =>
|
| 707 |
+
readQueue.push({ resolve, reject }),
|
| 708 |
+
).then((chunk) => (chunk ? { value: chunk, done: false } : { value: undefined, done: true }));
|
| 709 |
+
}
|
| 710 |
+
const chunk = pushQueue.shift()!;
|
| 711 |
+
return { value: chunk, done: false };
|
| 712 |
+
},
|
| 713 |
+
return: async () => {
|
| 714 |
+
this.abort();
|
| 715 |
+
return { value: undefined, done: true };
|
| 716 |
+
},
|
| 717 |
+
};
|
| 718 |
+
}
|
| 719 |
+
|
| 720 |
+
toReadableStream(): ReadableStream {
|
| 721 |
+
const stream = new Stream(this[Symbol.asyncIterator].bind(this), this.controller);
|
| 722 |
+
return stream.toReadableStream();
|
| 723 |
+
}
|
| 724 |
+
}
|
| 725 |
+
|
| 726 |
+
// used to ensure exhaustive case matching without throwing a runtime error
|
| 727 |
+
function checkNever(x: never) {}
|
node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/lib/MessageStream.ts
ADDED
|
@@ -0,0 +1,720 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { isAbortError } from '../internal/errors';
|
| 2 |
+
import { AnthropicError, APIUserAbortError } from '../error';
|
| 3 |
+
import {
|
| 4 |
+
type ContentBlock,
|
| 5 |
+
Messages,
|
| 6 |
+
type Message,
|
| 7 |
+
type MessageStreamEvent,
|
| 8 |
+
type MessageParam,
|
| 9 |
+
type MessageCreateParams,
|
| 10 |
+
type MessageCreateParamsBase,
|
| 11 |
+
type TextBlock,
|
| 12 |
+
type TextCitation,
|
| 13 |
+
type ToolUseBlock,
|
| 14 |
+
type ServerToolUseBlock,
|
| 15 |
+
} from '../resources/messages';
|
| 16 |
+
import { Stream } from '../streaming';
|
| 17 |
+
import { partialParse } from '../_vendor/partial-json-parser/parser';
|
| 18 |
+
import { RequestOptions } from '../internal/request-options';
|
| 19 |
+
|
| 20 |
+
export interface MessageStreamEvents {
|
| 21 |
+
connect: () => void;
|
| 22 |
+
streamEvent: (event: MessageStreamEvent, snapshot: Message) => void;
|
| 23 |
+
text: (textDelta: string, textSnapshot: string) => void;
|
| 24 |
+
citation: (citation: TextCitation, citationsSnapshot: TextCitation[]) => void;
|
| 25 |
+
inputJson: (partialJson: string, jsonSnapshot: unknown) => void;
|
| 26 |
+
thinking: (thinkingDelta: string, thinkingSnapshot: string) => void;
|
| 27 |
+
signature: (signature: string) => void;
|
| 28 |
+
message: (message: Message) => void;
|
| 29 |
+
contentBlock: (content: ContentBlock) => void;
|
| 30 |
+
finalMessage: (message: Message) => void;
|
| 31 |
+
error: (error: AnthropicError) => void;
|
| 32 |
+
abort: (error: APIUserAbortError) => void;
|
| 33 |
+
end: () => void;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
type MessageStreamEventListeners<Event extends keyof MessageStreamEvents> = {
|
| 37 |
+
listener: MessageStreamEvents[Event];
|
| 38 |
+
once?: boolean;
|
| 39 |
+
}[];
|
| 40 |
+
|
| 41 |
+
const JSON_BUF_PROPERTY = '__json_buf';
|
| 42 |
+
|
| 43 |
+
export type TracksToolInput = ToolUseBlock | ServerToolUseBlock;
|
| 44 |
+
|
| 45 |
+
function tracksToolInput(content: ContentBlock): content is TracksToolInput {
|
| 46 |
+
return content.type === 'tool_use' || content.type === 'server_tool_use';
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
export class MessageStream implements AsyncIterable<MessageStreamEvent> {
|
| 50 |
+
messages: MessageParam[] = [];
|
| 51 |
+
receivedMessages: Message[] = [];
|
| 52 |
+
#currentMessageSnapshot: Message | undefined;
|
| 53 |
+
|
| 54 |
+
controller: AbortController = new AbortController();
|
| 55 |
+
|
| 56 |
+
#connectedPromise: Promise<Response | null>;
|
| 57 |
+
#resolveConnectedPromise: (response: Response | null) => void = () => {};
|
| 58 |
+
#rejectConnectedPromise: (error: AnthropicError) => void = () => {};
|
| 59 |
+
|
| 60 |
+
#endPromise: Promise<void>;
|
| 61 |
+
#resolveEndPromise: () => void = () => {};
|
| 62 |
+
#rejectEndPromise: (error: AnthropicError) => void = () => {};
|
| 63 |
+
|
| 64 |
+
#listeners: { [Event in keyof MessageStreamEvents]?: MessageStreamEventListeners<Event> } = {};
|
| 65 |
+
|
| 66 |
+
#ended = false;
|
| 67 |
+
#errored = false;
|
| 68 |
+
#aborted = false;
|
| 69 |
+
#catchingPromiseCreated = false;
|
| 70 |
+
#response: Response | null | undefined;
|
| 71 |
+
#request_id: string | null | undefined;
|
| 72 |
+
|
| 73 |
+
constructor() {
|
| 74 |
+
this.#connectedPromise = new Promise<Response | null>((resolve, reject) => {
|
| 75 |
+
this.#resolveConnectedPromise = resolve;
|
| 76 |
+
this.#rejectConnectedPromise = reject;
|
| 77 |
+
});
|
| 78 |
+
|
| 79 |
+
this.#endPromise = new Promise<void>((resolve, reject) => {
|
| 80 |
+
this.#resolveEndPromise = resolve;
|
| 81 |
+
this.#rejectEndPromise = reject;
|
| 82 |
+
});
|
| 83 |
+
|
| 84 |
+
// Don't let these promises cause unhandled rejection errors.
|
| 85 |
+
// we will manually cause an unhandled rejection error later
|
| 86 |
+
// if the user hasn't registered any error listener or called
|
| 87 |
+
// any promise-returning method.
|
| 88 |
+
this.#connectedPromise.catch(() => {});
|
| 89 |
+
this.#endPromise.catch(() => {});
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
get response(): Response | null | undefined {
|
| 93 |
+
return this.#response;
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
get request_id(): string | null | undefined {
|
| 97 |
+
return this.#request_id;
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
/**
|
| 101 |
+
* Returns the `MessageStream` data, the raw `Response` instance and the ID of the request,
|
| 102 |
+
* returned vie the `request-id` header which is useful for debugging requests and resporting
|
| 103 |
+
* issues to Anthropic.
|
| 104 |
+
*
|
| 105 |
+
* This is the same as the `APIPromise.withResponse()` method.
|
| 106 |
+
*
|
| 107 |
+
* This method will raise an error if you created the stream using `MessageStream.fromReadableStream`
|
| 108 |
+
* as no `Response` is available.
|
| 109 |
+
*/
|
| 110 |
+
async withResponse(): Promise<{
|
| 111 |
+
data: MessageStream;
|
| 112 |
+
response: Response;
|
| 113 |
+
request_id: string | null | undefined;
|
| 114 |
+
}> {
|
| 115 |
+
const response = await this.#connectedPromise;
|
| 116 |
+
if (!response) {
|
| 117 |
+
throw new Error('Could not resolve a `Response` object');
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
return {
|
| 121 |
+
data: this,
|
| 122 |
+
response,
|
| 123 |
+
request_id: response.headers.get('request-id'),
|
| 124 |
+
};
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
/**
|
| 128 |
+
* Intended for use on the frontend, consuming a stream produced with
|
| 129 |
+
* `.toReadableStream()` on the backend.
|
| 130 |
+
*
|
| 131 |
+
* Note that messages sent to the model do not appear in `.on('message')`
|
| 132 |
+
* in this context.
|
| 133 |
+
*/
|
| 134 |
+
static fromReadableStream(stream: ReadableStream): MessageStream {
|
| 135 |
+
const runner = new MessageStream();
|
| 136 |
+
runner._run(() => runner._fromReadableStream(stream));
|
| 137 |
+
return runner;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
static createMessage(
|
| 141 |
+
messages: Messages,
|
| 142 |
+
params: MessageCreateParamsBase,
|
| 143 |
+
options?: RequestOptions,
|
| 144 |
+
): MessageStream {
|
| 145 |
+
const runner = new MessageStream();
|
| 146 |
+
for (const message of params.messages) {
|
| 147 |
+
runner._addMessageParam(message);
|
| 148 |
+
}
|
| 149 |
+
runner._run(() =>
|
| 150 |
+
runner._createMessage(
|
| 151 |
+
messages,
|
| 152 |
+
{ ...params, stream: true },
|
| 153 |
+
{ ...options, headers: { ...options?.headers, 'X-Stainless-Helper-Method': 'stream' } },
|
| 154 |
+
),
|
| 155 |
+
);
|
| 156 |
+
return runner;
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
protected _run(executor: () => Promise<any>) {
|
| 160 |
+
executor().then(() => {
|
| 161 |
+
this._emitFinal();
|
| 162 |
+
this._emit('end');
|
| 163 |
+
}, this.#handleError);
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
protected _addMessageParam(message: MessageParam) {
|
| 167 |
+
this.messages.push(message);
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
protected _addMessage(message: Message, emit = true) {
|
| 171 |
+
this.receivedMessages.push(message);
|
| 172 |
+
if (emit) {
|
| 173 |
+
this._emit('message', message);
|
| 174 |
+
}
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
protected async _createMessage(
|
| 178 |
+
messages: Messages,
|
| 179 |
+
params: MessageCreateParams,
|
| 180 |
+
options?: RequestOptions,
|
| 181 |
+
): Promise<void> {
|
| 182 |
+
const signal = options?.signal;
|
| 183 |
+
let abortHandler: (() => void) | undefined;
|
| 184 |
+
if (signal) {
|
| 185 |
+
if (signal.aborted) this.controller.abort();
|
| 186 |
+
abortHandler = this.controller.abort.bind(this.controller);
|
| 187 |
+
signal.addEventListener('abort', abortHandler);
|
| 188 |
+
}
|
| 189 |
+
try {
|
| 190 |
+
this.#beginRequest();
|
| 191 |
+
const { response, data: stream } = await messages
|
| 192 |
+
.create({ ...params, stream: true }, { ...options, signal: this.controller.signal })
|
| 193 |
+
.withResponse();
|
| 194 |
+
this._connected(response);
|
| 195 |
+
for await (const event of stream) {
|
| 196 |
+
this.#addStreamEvent(event);
|
| 197 |
+
}
|
| 198 |
+
if (stream.controller.signal?.aborted) {
|
| 199 |
+
throw new APIUserAbortError();
|
| 200 |
+
}
|
| 201 |
+
this.#endRequest();
|
| 202 |
+
} finally {
|
| 203 |
+
if (signal && abortHandler) {
|
| 204 |
+
signal.removeEventListener('abort', abortHandler);
|
| 205 |
+
}
|
| 206 |
+
}
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
protected _connected(response: Response | null) {
|
| 210 |
+
if (this.ended) return;
|
| 211 |
+
this.#response = response;
|
| 212 |
+
this.#request_id = response?.headers.get('request-id');
|
| 213 |
+
this.#resolveConnectedPromise(response);
|
| 214 |
+
this._emit('connect');
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
get ended(): boolean {
|
| 218 |
+
return this.#ended;
|
| 219 |
+
}
|
| 220 |
+
|
| 221 |
+
get errored(): boolean {
|
| 222 |
+
return this.#errored;
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
get aborted(): boolean {
|
| 226 |
+
return this.#aborted;
|
| 227 |
+
}
|
| 228 |
+
|
| 229 |
+
abort() {
|
| 230 |
+
this.controller.abort();
|
| 231 |
+
}
|
| 232 |
+
|
| 233 |
+
/**
|
| 234 |
+
* Adds the listener function to the end of the listeners array for the event.
|
| 235 |
+
* No checks are made to see if the listener has already been added. Multiple calls passing
|
| 236 |
+
* the same combination of event and listener will result in the listener being added, and
|
| 237 |
+
* called, multiple times.
|
| 238 |
+
* @returns this MessageStream, so that calls can be chained
|
| 239 |
+
*/
|
| 240 |
+
on<Event extends keyof MessageStreamEvents>(event: Event, listener: MessageStreamEvents[Event]): this {
|
| 241 |
+
const listeners: MessageStreamEventListeners<Event> =
|
| 242 |
+
this.#listeners[event] || (this.#listeners[event] = []);
|
| 243 |
+
listeners.push({ listener });
|
| 244 |
+
return this;
|
| 245 |
+
}
|
| 246 |
+
|
| 247 |
+
/**
|
| 248 |
+
* Removes the specified listener from the listener array for the event.
|
| 249 |
+
* off() will remove, at most, one instance of a listener from the listener array. If any single
|
| 250 |
+
* listener has been added multiple times to the listener array for the specified event, then
|
| 251 |
+
* off() must be called multiple times to remove each instance.
|
| 252 |
+
* @returns this MessageStream, so that calls can be chained
|
| 253 |
+
*/
|
| 254 |
+
off<Event extends keyof MessageStreamEvents>(event: Event, listener: MessageStreamEvents[Event]): this {
|
| 255 |
+
const listeners = this.#listeners[event];
|
| 256 |
+
if (!listeners) return this;
|
| 257 |
+
const index = listeners.findIndex((l) => l.listener === listener);
|
| 258 |
+
if (index >= 0) listeners.splice(index, 1);
|
| 259 |
+
return this;
|
| 260 |
+
}
|
| 261 |
+
|
| 262 |
+
/**
|
| 263 |
+
* Adds a one-time listener function for the event. The next time the event is triggered,
|
| 264 |
+
* this listener is removed and then invoked.
|
| 265 |
+
* @returns this MessageStream, so that calls can be chained
|
| 266 |
+
*/
|
| 267 |
+
once<Event extends keyof MessageStreamEvents>(event: Event, listener: MessageStreamEvents[Event]): this {
|
| 268 |
+
const listeners: MessageStreamEventListeners<Event> =
|
| 269 |
+
this.#listeners[event] || (this.#listeners[event] = []);
|
| 270 |
+
listeners.push({ listener, once: true });
|
| 271 |
+
return this;
|
| 272 |
+
}
|
| 273 |
+
|
| 274 |
+
/**
|
| 275 |
+
* This is similar to `.once()`, but returns a Promise that resolves the next time
|
| 276 |
+
* the event is triggered, instead of calling a listener callback.
|
| 277 |
+
* @returns a Promise that resolves the next time given event is triggered,
|
| 278 |
+
* or rejects if an error is emitted. (If you request the 'error' event,
|
| 279 |
+
* returns a promise that resolves with the error).
|
| 280 |
+
*
|
| 281 |
+
* Example:
|
| 282 |
+
*
|
| 283 |
+
* const message = await stream.emitted('message') // rejects if the stream errors
|
| 284 |
+
*/
|
| 285 |
+
emitted<Event extends keyof MessageStreamEvents>(
|
| 286 |
+
event: Event,
|
| 287 |
+
): Promise<
|
| 288 |
+
Parameters<MessageStreamEvents[Event]> extends [infer Param] ? Param
|
| 289 |
+
: Parameters<MessageStreamEvents[Event]> extends [] ? void
|
| 290 |
+
: Parameters<MessageStreamEvents[Event]>
|
| 291 |
+
> {
|
| 292 |
+
return new Promise((resolve, reject) => {
|
| 293 |
+
this.#catchingPromiseCreated = true;
|
| 294 |
+
if (event !== 'error') this.once('error', reject);
|
| 295 |
+
this.once(event, resolve as any);
|
| 296 |
+
});
|
| 297 |
+
}
|
| 298 |
+
|
| 299 |
+
async done(): Promise<void> {
|
| 300 |
+
this.#catchingPromiseCreated = true;
|
| 301 |
+
await this.#endPromise;
|
| 302 |
+
}
|
| 303 |
+
|
| 304 |
+
get currentMessage(): Message | undefined {
|
| 305 |
+
return this.#currentMessageSnapshot;
|
| 306 |
+
}
|
| 307 |
+
|
| 308 |
+
#getFinalMessage(): Message {
|
| 309 |
+
if (this.receivedMessages.length === 0) {
|
| 310 |
+
throw new AnthropicError('stream ended without producing a Message with role=assistant');
|
| 311 |
+
}
|
| 312 |
+
return this.receivedMessages.at(-1)!;
|
| 313 |
+
}
|
| 314 |
+
|
| 315 |
+
/**
|
| 316 |
+
* @returns a promise that resolves with the the final assistant Message response,
|
| 317 |
+
* or rejects if an error occurred or the stream ended prematurely without producing a Message.
|
| 318 |
+
*/
|
| 319 |
+
async finalMessage(): Promise<Message> {
|
| 320 |
+
await this.done();
|
| 321 |
+
return this.#getFinalMessage();
|
| 322 |
+
}
|
| 323 |
+
|
| 324 |
+
#getFinalText(): string {
|
| 325 |
+
if (this.receivedMessages.length === 0) {
|
| 326 |
+
throw new AnthropicError('stream ended without producing a Message with role=assistant');
|
| 327 |
+
}
|
| 328 |
+
const textBlocks = this.receivedMessages
|
| 329 |
+
.at(-1)!
|
| 330 |
+
.content.filter((block): block is TextBlock => block.type === 'text')
|
| 331 |
+
.map((block) => block.text);
|
| 332 |
+
if (textBlocks.length === 0) {
|
| 333 |
+
throw new AnthropicError('stream ended without producing a content block with type=text');
|
| 334 |
+
}
|
| 335 |
+
return textBlocks.join(' ');
|
| 336 |
+
}
|
| 337 |
+
|
| 338 |
+
/**
|
| 339 |
+
* @returns a promise that resolves with the the final assistant Message's text response, concatenated
|
| 340 |
+
* together if there are more than one text blocks.
|
| 341 |
+
* Rejects if an error occurred or the stream ended prematurely without producing a Message.
|
| 342 |
+
*/
|
| 343 |
+
async finalText(): Promise<string> {
|
| 344 |
+
await this.done();
|
| 345 |
+
return this.#getFinalText();
|
| 346 |
+
}
|
| 347 |
+
|
| 348 |
+
#handleError = (error: unknown) => {
|
| 349 |
+
this.#errored = true;
|
| 350 |
+
if (isAbortError(error)) {
|
| 351 |
+
error = new APIUserAbortError();
|
| 352 |
+
}
|
| 353 |
+
if (error instanceof APIUserAbortError) {
|
| 354 |
+
this.#aborted = true;
|
| 355 |
+
return this._emit('abort', error);
|
| 356 |
+
}
|
| 357 |
+
if (error instanceof AnthropicError) {
|
| 358 |
+
return this._emit('error', error);
|
| 359 |
+
}
|
| 360 |
+
if (error instanceof Error) {
|
| 361 |
+
const anthropicError: AnthropicError = new AnthropicError(error.message);
|
| 362 |
+
// @ts-ignore
|
| 363 |
+
anthropicError.cause = error;
|
| 364 |
+
return this._emit('error', anthropicError);
|
| 365 |
+
}
|
| 366 |
+
return this._emit('error', new AnthropicError(String(error)));
|
| 367 |
+
};
|
| 368 |
+
|
| 369 |
+
protected _emit<Event extends keyof MessageStreamEvents>(
|
| 370 |
+
event: Event,
|
| 371 |
+
...args: Parameters<MessageStreamEvents[Event]>
|
| 372 |
+
) {
|
| 373 |
+
// make sure we don't emit any MessageStreamEvents after end
|
| 374 |
+
if (this.#ended) return;
|
| 375 |
+
|
| 376 |
+
if (event === 'end') {
|
| 377 |
+
this.#ended = true;
|
| 378 |
+
this.#resolveEndPromise();
|
| 379 |
+
}
|
| 380 |
+
|
| 381 |
+
const listeners: MessageStreamEventListeners<Event> | undefined = this.#listeners[event];
|
| 382 |
+
if (listeners) {
|
| 383 |
+
this.#listeners[event] = listeners.filter((l) => !l.once) as any;
|
| 384 |
+
listeners.forEach(({ listener }: any) => listener(...args));
|
| 385 |
+
}
|
| 386 |
+
|
| 387 |
+
if (event === 'abort') {
|
| 388 |
+
const error = args[0] as APIUserAbortError;
|
| 389 |
+
if (!this.#catchingPromiseCreated && !listeners?.length) {
|
| 390 |
+
Promise.reject(error);
|
| 391 |
+
}
|
| 392 |
+
this.#rejectConnectedPromise(error);
|
| 393 |
+
this.#rejectEndPromise(error);
|
| 394 |
+
this._emit('end');
|
| 395 |
+
return;
|
| 396 |
+
}
|
| 397 |
+
|
| 398 |
+
if (event === 'error') {
|
| 399 |
+
// NOTE: _emit('error', error) should only be called from #handleError().
|
| 400 |
+
|
| 401 |
+
const error = args[0] as AnthropicError;
|
| 402 |
+
if (!this.#catchingPromiseCreated && !listeners?.length) {
|
| 403 |
+
// Trigger an unhandled rejection if the user hasn't registered any error handlers.
|
| 404 |
+
// If you are seeing stack traces here, make sure to handle errors via either:
|
| 405 |
+
// - runner.on('error', () => ...)
|
| 406 |
+
// - await runner.done()
|
| 407 |
+
// - await runner.final...()
|
| 408 |
+
// - etc.
|
| 409 |
+
Promise.reject(error);
|
| 410 |
+
}
|
| 411 |
+
this.#rejectConnectedPromise(error);
|
| 412 |
+
this.#rejectEndPromise(error);
|
| 413 |
+
this._emit('end');
|
| 414 |
+
}
|
| 415 |
+
}
|
| 416 |
+
|
| 417 |
+
protected _emitFinal() {
|
| 418 |
+
const finalMessage = this.receivedMessages.at(-1);
|
| 419 |
+
if (finalMessage) {
|
| 420 |
+
this._emit('finalMessage', this.#getFinalMessage());
|
| 421 |
+
}
|
| 422 |
+
}
|
| 423 |
+
|
| 424 |
+
#beginRequest() {
|
| 425 |
+
if (this.ended) return;
|
| 426 |
+
this.#currentMessageSnapshot = undefined;
|
| 427 |
+
}
|
| 428 |
+
#addStreamEvent(event: MessageStreamEvent) {
|
| 429 |
+
if (this.ended) return;
|
| 430 |
+
const messageSnapshot = this.#accumulateMessage(event);
|
| 431 |
+
this._emit('streamEvent', event, messageSnapshot);
|
| 432 |
+
|
| 433 |
+
switch (event.type) {
|
| 434 |
+
case 'content_block_delta': {
|
| 435 |
+
const content = messageSnapshot.content.at(-1)!;
|
| 436 |
+
switch (event.delta.type) {
|
| 437 |
+
case 'text_delta': {
|
| 438 |
+
if (content.type === 'text') {
|
| 439 |
+
this._emit('text', event.delta.text, content.text || '');
|
| 440 |
+
}
|
| 441 |
+
break;
|
| 442 |
+
}
|
| 443 |
+
case 'citations_delta': {
|
| 444 |
+
if (content.type === 'text') {
|
| 445 |
+
this._emit('citation', event.delta.citation, content.citations ?? []);
|
| 446 |
+
}
|
| 447 |
+
break;
|
| 448 |
+
}
|
| 449 |
+
case 'input_json_delta': {
|
| 450 |
+
if (tracksToolInput(content) && content.input) {
|
| 451 |
+
this._emit('inputJson', event.delta.partial_json, content.input);
|
| 452 |
+
}
|
| 453 |
+
break;
|
| 454 |
+
}
|
| 455 |
+
case 'thinking_delta': {
|
| 456 |
+
if (content.type === 'thinking') {
|
| 457 |
+
this._emit('thinking', event.delta.thinking, content.thinking);
|
| 458 |
+
}
|
| 459 |
+
break;
|
| 460 |
+
}
|
| 461 |
+
case 'signature_delta': {
|
| 462 |
+
if (content.type === 'thinking') {
|
| 463 |
+
this._emit('signature', content.signature);
|
| 464 |
+
}
|
| 465 |
+
break;
|
| 466 |
+
}
|
| 467 |
+
default:
|
| 468 |
+
checkNever(event.delta);
|
| 469 |
+
}
|
| 470 |
+
break;
|
| 471 |
+
}
|
| 472 |
+
case 'message_stop': {
|
| 473 |
+
this._addMessageParam(messageSnapshot);
|
| 474 |
+
this._addMessage(messageSnapshot, true);
|
| 475 |
+
break;
|
| 476 |
+
}
|
| 477 |
+
case 'content_block_stop': {
|
| 478 |
+
this._emit('contentBlock', messageSnapshot.content.at(-1)!);
|
| 479 |
+
break;
|
| 480 |
+
}
|
| 481 |
+
case 'message_start': {
|
| 482 |
+
this.#currentMessageSnapshot = messageSnapshot;
|
| 483 |
+
break;
|
| 484 |
+
}
|
| 485 |
+
case 'content_block_start':
|
| 486 |
+
case 'message_delta':
|
| 487 |
+
break;
|
| 488 |
+
}
|
| 489 |
+
}
|
| 490 |
+
#endRequest(): Message {
|
| 491 |
+
if (this.ended) {
|
| 492 |
+
throw new AnthropicError(`stream has ended, this shouldn't happen`);
|
| 493 |
+
}
|
| 494 |
+
const snapshot = this.#currentMessageSnapshot;
|
| 495 |
+
if (!snapshot) {
|
| 496 |
+
throw new AnthropicError(`request ended without sending any chunks`);
|
| 497 |
+
}
|
| 498 |
+
this.#currentMessageSnapshot = undefined;
|
| 499 |
+
return snapshot;
|
| 500 |
+
}
|
| 501 |
+
|
| 502 |
+
protected async _fromReadableStream(
|
| 503 |
+
readableStream: ReadableStream,
|
| 504 |
+
options?: RequestOptions,
|
| 505 |
+
): Promise<void> {
|
| 506 |
+
const signal = options?.signal;
|
| 507 |
+
let abortHandler: (() => void) | undefined;
|
| 508 |
+
if (signal) {
|
| 509 |
+
if (signal.aborted) this.controller.abort();
|
| 510 |
+
abortHandler = this.controller.abort.bind(this.controller);
|
| 511 |
+
signal.addEventListener('abort', abortHandler);
|
| 512 |
+
}
|
| 513 |
+
try {
|
| 514 |
+
this.#beginRequest();
|
| 515 |
+
this._connected(null);
|
| 516 |
+
const stream = Stream.fromReadableStream<MessageStreamEvent>(readableStream, this.controller);
|
| 517 |
+
for await (const event of stream) {
|
| 518 |
+
this.#addStreamEvent(event);
|
| 519 |
+
}
|
| 520 |
+
if (stream.controller.signal?.aborted) {
|
| 521 |
+
throw new APIUserAbortError();
|
| 522 |
+
}
|
| 523 |
+
this.#endRequest();
|
| 524 |
+
} finally {
|
| 525 |
+
if (signal && abortHandler) {
|
| 526 |
+
signal.removeEventListener('abort', abortHandler);
|
| 527 |
+
}
|
| 528 |
+
}
|
| 529 |
+
}
|
| 530 |
+
|
| 531 |
+
/**
|
| 532 |
+
* Mutates this.#currentMessage with the current event. Handling the accumulation of multiple messages
|
| 533 |
+
* will be needed to be handled by the caller, this method will throw if you try to accumulate for multiple
|
| 534 |
+
* messages.
|
| 535 |
+
*/
|
| 536 |
+
#accumulateMessage(event: MessageStreamEvent): Message {
|
| 537 |
+
let snapshot = this.#currentMessageSnapshot;
|
| 538 |
+
|
| 539 |
+
if (event.type === 'message_start') {
|
| 540 |
+
if (snapshot) {
|
| 541 |
+
throw new AnthropicError(`Unexpected event order, got ${event.type} before receiving "message_stop"`);
|
| 542 |
+
}
|
| 543 |
+
return event.message;
|
| 544 |
+
}
|
| 545 |
+
|
| 546 |
+
if (!snapshot) {
|
| 547 |
+
throw new AnthropicError(`Unexpected event order, got ${event.type} before "message_start"`);
|
| 548 |
+
}
|
| 549 |
+
|
| 550 |
+
switch (event.type) {
|
| 551 |
+
case 'message_stop':
|
| 552 |
+
return snapshot;
|
| 553 |
+
case 'message_delta':
|
| 554 |
+
snapshot.stop_reason = event.delta.stop_reason;
|
| 555 |
+
snapshot.stop_sequence = event.delta.stop_sequence;
|
| 556 |
+
snapshot.usage.output_tokens = event.usage.output_tokens;
|
| 557 |
+
|
| 558 |
+
// Update other usage fields if they exist in the event
|
| 559 |
+
if (event.usage.input_tokens != null) {
|
| 560 |
+
snapshot.usage.input_tokens = event.usage.input_tokens;
|
| 561 |
+
}
|
| 562 |
+
|
| 563 |
+
if (event.usage.cache_creation_input_tokens != null) {
|
| 564 |
+
snapshot.usage.cache_creation_input_tokens = event.usage.cache_creation_input_tokens;
|
| 565 |
+
}
|
| 566 |
+
|
| 567 |
+
if (event.usage.cache_read_input_tokens != null) {
|
| 568 |
+
snapshot.usage.cache_read_input_tokens = event.usage.cache_read_input_tokens;
|
| 569 |
+
}
|
| 570 |
+
|
| 571 |
+
if (event.usage.server_tool_use != null) {
|
| 572 |
+
snapshot.usage.server_tool_use = event.usage.server_tool_use;
|
| 573 |
+
}
|
| 574 |
+
|
| 575 |
+
return snapshot;
|
| 576 |
+
case 'content_block_start':
|
| 577 |
+
snapshot.content.push({ ...event.content_block });
|
| 578 |
+
return snapshot;
|
| 579 |
+
case 'content_block_delta': {
|
| 580 |
+
const snapshotContent = snapshot.content.at(event.index);
|
| 581 |
+
|
| 582 |
+
switch (event.delta.type) {
|
| 583 |
+
case 'text_delta': {
|
| 584 |
+
if (snapshotContent?.type === 'text') {
|
| 585 |
+
snapshot.content[event.index] = {
|
| 586 |
+
...snapshotContent,
|
| 587 |
+
text: (snapshotContent.text || '') + event.delta.text,
|
| 588 |
+
};
|
| 589 |
+
}
|
| 590 |
+
break;
|
| 591 |
+
}
|
| 592 |
+
case 'citations_delta': {
|
| 593 |
+
if (snapshotContent?.type === 'text') {
|
| 594 |
+
snapshot.content[event.index] = {
|
| 595 |
+
...snapshotContent,
|
| 596 |
+
citations: [...(snapshotContent.citations ?? []), event.delta.citation],
|
| 597 |
+
};
|
| 598 |
+
}
|
| 599 |
+
break;
|
| 600 |
+
}
|
| 601 |
+
case 'input_json_delta': {
|
| 602 |
+
if (snapshotContent && tracksToolInput(snapshotContent)) {
|
| 603 |
+
// we need to keep track of the raw JSON string as well so that we can
|
| 604 |
+
// re-parse it for each delta, for now we just store it as an untyped
|
| 605 |
+
// non-enumerable property on the snapshot
|
| 606 |
+
let jsonBuf = (snapshotContent as any)[JSON_BUF_PROPERTY] || '';
|
| 607 |
+
jsonBuf += event.delta.partial_json;
|
| 608 |
+
|
| 609 |
+
const newContent = { ...snapshotContent };
|
| 610 |
+
Object.defineProperty(newContent, JSON_BUF_PROPERTY, {
|
| 611 |
+
value: jsonBuf,
|
| 612 |
+
enumerable: false,
|
| 613 |
+
writable: true,
|
| 614 |
+
});
|
| 615 |
+
|
| 616 |
+
if (jsonBuf) {
|
| 617 |
+
newContent.input = partialParse(jsonBuf);
|
| 618 |
+
}
|
| 619 |
+
snapshot.content[event.index] = newContent;
|
| 620 |
+
}
|
| 621 |
+
break;
|
| 622 |
+
}
|
| 623 |
+
case 'thinking_delta': {
|
| 624 |
+
if (snapshotContent?.type === 'thinking') {
|
| 625 |
+
snapshot.content[event.index] = {
|
| 626 |
+
...snapshotContent,
|
| 627 |
+
thinking: snapshotContent.thinking + event.delta.thinking,
|
| 628 |
+
};
|
| 629 |
+
}
|
| 630 |
+
break;
|
| 631 |
+
}
|
| 632 |
+
case 'signature_delta': {
|
| 633 |
+
if (snapshotContent?.type === 'thinking') {
|
| 634 |
+
snapshot.content[event.index] = {
|
| 635 |
+
...snapshotContent,
|
| 636 |
+
signature: event.delta.signature,
|
| 637 |
+
};
|
| 638 |
+
}
|
| 639 |
+
break;
|
| 640 |
+
}
|
| 641 |
+
default:
|
| 642 |
+
checkNever(event.delta);
|
| 643 |
+
}
|
| 644 |
+
|
| 645 |
+
return snapshot;
|
| 646 |
+
}
|
| 647 |
+
case 'content_block_stop':
|
| 648 |
+
return snapshot;
|
| 649 |
+
}
|
| 650 |
+
}
|
| 651 |
+
|
| 652 |
+
[Symbol.asyncIterator](): AsyncIterator<MessageStreamEvent> {
|
| 653 |
+
const pushQueue: MessageStreamEvent[] = [];
|
| 654 |
+
const readQueue: {
|
| 655 |
+
resolve: (chunk: MessageStreamEvent | undefined) => void;
|
| 656 |
+
reject: (error: unknown) => void;
|
| 657 |
+
}[] = [];
|
| 658 |
+
let done = false;
|
| 659 |
+
|
| 660 |
+
this.on('streamEvent', (event) => {
|
| 661 |
+
const reader = readQueue.shift();
|
| 662 |
+
if (reader) {
|
| 663 |
+
reader.resolve(event);
|
| 664 |
+
} else {
|
| 665 |
+
pushQueue.push(event);
|
| 666 |
+
}
|
| 667 |
+
});
|
| 668 |
+
|
| 669 |
+
this.on('end', () => {
|
| 670 |
+
done = true;
|
| 671 |
+
for (const reader of readQueue) {
|
| 672 |
+
reader.resolve(undefined);
|
| 673 |
+
}
|
| 674 |
+
readQueue.length = 0;
|
| 675 |
+
});
|
| 676 |
+
|
| 677 |
+
this.on('abort', (err) => {
|
| 678 |
+
done = true;
|
| 679 |
+
for (const reader of readQueue) {
|
| 680 |
+
reader.reject(err);
|
| 681 |
+
}
|
| 682 |
+
readQueue.length = 0;
|
| 683 |
+
});
|
| 684 |
+
|
| 685 |
+
this.on('error', (err) => {
|
| 686 |
+
done = true;
|
| 687 |
+
for (const reader of readQueue) {
|
| 688 |
+
reader.reject(err);
|
| 689 |
+
}
|
| 690 |
+
readQueue.length = 0;
|
| 691 |
+
});
|
| 692 |
+
|
| 693 |
+
return {
|
| 694 |
+
next: async (): Promise<IteratorResult<MessageStreamEvent>> => {
|
| 695 |
+
if (!pushQueue.length) {
|
| 696 |
+
if (done) {
|
| 697 |
+
return { value: undefined, done: true };
|
| 698 |
+
}
|
| 699 |
+
return new Promise<MessageStreamEvent | undefined>((resolve, reject) =>
|
| 700 |
+
readQueue.push({ resolve, reject }),
|
| 701 |
+
).then((chunk) => (chunk ? { value: chunk, done: false } : { value: undefined, done: true }));
|
| 702 |
+
}
|
| 703 |
+
const chunk = pushQueue.shift()!;
|
| 704 |
+
return { value: chunk, done: false };
|
| 705 |
+
},
|
| 706 |
+
return: async () => {
|
| 707 |
+
this.abort();
|
| 708 |
+
return { value: undefined, done: true };
|
| 709 |
+
},
|
| 710 |
+
};
|
| 711 |
+
}
|
| 712 |
+
|
| 713 |
+
toReadableStream(): ReadableStream {
|
| 714 |
+
const stream = new Stream(this[Symbol.asyncIterator].bind(this), this.controller);
|
| 715 |
+
return stream.toReadableStream();
|
| 716 |
+
}
|
| 717 |
+
}
|
| 718 |
+
|
| 719 |
+
// used to ensure exhaustive case matching without throwing a runtime error
|
| 720 |
+
function checkNever(x: never) {}
|
node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/pagination.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/** @deprecated Import from ./core/pagination instead */
|
| 2 |
+
export * from './core/pagination';
|
node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/resource.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/** @deprecated Import from ./core/resource instead */
|
| 2 |
+
export * from './core/resource';
|
node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/resources.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
export * from './resources/index';
|
node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/resources/beta.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
| 2 |
+
|
| 3 |
+
export * from './beta/index';
|
node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
| 2 |
+
|
| 3 |
+
import { APIResource } from '../../core/resource';
|
| 4 |
+
import * as FilesAPI from './files';
|
| 5 |
+
import {
|
| 6 |
+
DeletedFile,
|
| 7 |
+
FileDeleteParams,
|
| 8 |
+
FileDownloadParams,
|
| 9 |
+
FileListParams,
|
| 10 |
+
FileMetadata,
|
| 11 |
+
FileMetadataPage,
|
| 12 |
+
FileRetrieveMetadataParams,
|
| 13 |
+
FileUploadParams,
|
| 14 |
+
Files,
|
| 15 |
+
} from './files';
|
| 16 |
+
import * as ModelsAPI from './models';
|
| 17 |
+
import { BetaModelInfo, BetaModelInfosPage, ModelListParams, ModelRetrieveParams, Models } from './models';
|
| 18 |
+
import * as MessagesAPI from './messages/messages';
|
| 19 |
+
import {
|
| 20 |
+
BetaBase64ImageSource,
|
| 21 |
+
BetaBase64PDFBlock,
|
| 22 |
+
BetaBase64PDFSource,
|
| 23 |
+
BetaCacheControlEphemeral,
|
| 24 |
+
BetaCacheCreation,
|
| 25 |
+
BetaCitationCharLocation,
|
| 26 |
+
BetaCitationCharLocationParam,
|
| 27 |
+
BetaCitationContentBlockLocation,
|
| 28 |
+
BetaCitationContentBlockLocationParam,
|
| 29 |
+
BetaCitationPageLocation,
|
| 30 |
+
BetaCitationPageLocationParam,
|
| 31 |
+
BetaCitationSearchResultLocation,
|
| 32 |
+
BetaCitationSearchResultLocationParam,
|
| 33 |
+
BetaCitationWebSearchResultLocationParam,
|
| 34 |
+
BetaCitationsConfigParam,
|
| 35 |
+
BetaCitationsDelta,
|
| 36 |
+
BetaCitationsWebSearchResultLocation,
|
| 37 |
+
BetaCodeExecutionOutputBlock,
|
| 38 |
+
BetaCodeExecutionOutputBlockParam,
|
| 39 |
+
BetaCodeExecutionResultBlock,
|
| 40 |
+
BetaCodeExecutionResultBlockParam,
|
| 41 |
+
BetaCodeExecutionTool20250522,
|
| 42 |
+
BetaCodeExecutionToolResultBlock,
|
| 43 |
+
BetaCodeExecutionToolResultBlockContent,
|
| 44 |
+
BetaCodeExecutionToolResultBlockParam,
|
| 45 |
+
BetaCodeExecutionToolResultBlockParamContent,
|
| 46 |
+
BetaCodeExecutionToolResultError,
|
| 47 |
+
BetaCodeExecutionToolResultErrorCode,
|
| 48 |
+
BetaCodeExecutionToolResultErrorParam,
|
| 49 |
+
BetaContainer,
|
| 50 |
+
BetaContainerUploadBlock,
|
| 51 |
+
BetaContainerUploadBlockParam,
|
| 52 |
+
BetaContentBlock,
|
| 53 |
+
BetaContentBlockParam,
|
| 54 |
+
BetaContentBlockSource,
|
| 55 |
+
BetaContentBlockSourceContent,
|
| 56 |
+
BetaFileDocumentSource,
|
| 57 |
+
BetaFileImageSource,
|
| 58 |
+
BetaImageBlockParam,
|
| 59 |
+
BetaInputJSONDelta,
|
| 60 |
+
BetaMCPToolResultBlock,
|
| 61 |
+
BetaMCPToolUseBlock,
|
| 62 |
+
BetaMCPToolUseBlockParam,
|
| 63 |
+
BetaMessage,
|
| 64 |
+
BetaMessageDeltaUsage,
|
| 65 |
+
BetaMessageParam,
|
| 66 |
+
BetaMessageTokensCount,
|
| 67 |
+
BetaMetadata,
|
| 68 |
+
BetaPlainTextSource,
|
| 69 |
+
BetaRawContentBlockDelta,
|
| 70 |
+
BetaRawContentBlockDeltaEvent,
|
| 71 |
+
BetaRawContentBlockStartEvent,
|
| 72 |
+
BetaRawContentBlockStopEvent,
|
| 73 |
+
BetaRawMessageDeltaEvent,
|
| 74 |
+
BetaRawMessageStartEvent,
|
| 75 |
+
BetaRawMessageStopEvent,
|
| 76 |
+
BetaRawMessageStreamEvent,
|
| 77 |
+
BetaRedactedThinkingBlock,
|
| 78 |
+
BetaRedactedThinkingBlockParam,
|
| 79 |
+
BetaRequestDocumentBlock,
|
| 80 |
+
BetaRequestMCPServerToolConfiguration,
|
| 81 |
+
BetaRequestMCPServerURLDefinition,
|
| 82 |
+
BetaRequestMCPToolResultBlockParam,
|
| 83 |
+
BetaSearchResultBlockParam,
|
| 84 |
+
BetaServerToolUsage,
|
| 85 |
+
BetaServerToolUseBlock,
|
| 86 |
+
BetaServerToolUseBlockParam,
|
| 87 |
+
BetaSignatureDelta,
|
| 88 |
+
BetaStopReason,
|
| 89 |
+
BetaTextBlock,
|
| 90 |
+
BetaTextBlockParam,
|
| 91 |
+
BetaTextCitation,
|
| 92 |
+
BetaTextCitationParam,
|
| 93 |
+
BetaTextDelta,
|
| 94 |
+
BetaThinkingBlock,
|
| 95 |
+
BetaThinkingBlockParam,
|
| 96 |
+
BetaThinkingConfigDisabled,
|
| 97 |
+
BetaThinkingConfigEnabled,
|
| 98 |
+
BetaThinkingConfigParam,
|
| 99 |
+
BetaThinkingDelta,
|
| 100 |
+
BetaTool,
|
| 101 |
+
BetaToolBash20241022,
|
| 102 |
+
BetaToolBash20250124,
|
| 103 |
+
BetaToolChoice,
|
| 104 |
+
BetaToolChoiceAny,
|
| 105 |
+
BetaToolChoiceAuto,
|
| 106 |
+
BetaToolChoiceNone,
|
| 107 |
+
BetaToolChoiceTool,
|
| 108 |
+
BetaToolComputerUse20241022,
|
| 109 |
+
BetaToolComputerUse20250124,
|
| 110 |
+
BetaToolResultBlockParam,
|
| 111 |
+
BetaToolTextEditor20241022,
|
| 112 |
+
BetaToolTextEditor20250124,
|
| 113 |
+
BetaToolTextEditor20250429,
|
| 114 |
+
BetaToolUnion,
|
| 115 |
+
BetaToolUseBlock,
|
| 116 |
+
BetaToolUseBlockParam,
|
| 117 |
+
BetaURLImageSource,
|
| 118 |
+
BetaURLPDFSource,
|
| 119 |
+
BetaUsage,
|
| 120 |
+
BetaWebSearchResultBlock,
|
| 121 |
+
BetaWebSearchResultBlockParam,
|
| 122 |
+
BetaWebSearchTool20250305,
|
| 123 |
+
BetaWebSearchToolRequestError,
|
| 124 |
+
BetaWebSearchToolResultBlock,
|
| 125 |
+
BetaWebSearchToolResultBlockContent,
|
| 126 |
+
BetaWebSearchToolResultBlockParam,
|
| 127 |
+
BetaWebSearchToolResultBlockParamContent,
|
| 128 |
+
BetaWebSearchToolResultError,
|
| 129 |
+
BetaWebSearchToolResultErrorCode,
|
| 130 |
+
MessageCountTokensParams,
|
| 131 |
+
MessageCreateParams,
|
| 132 |
+
MessageCreateParamsNonStreaming,
|
| 133 |
+
MessageCreateParamsStreaming,
|
| 134 |
+
Messages,
|
| 135 |
+
} from './messages/messages';
|
| 136 |
+
|
| 137 |
+
export class Beta extends APIResource {
|
| 138 |
+
models: ModelsAPI.Models = new ModelsAPI.Models(this._client);
|
| 139 |
+
messages: MessagesAPI.Messages = new MessagesAPI.Messages(this._client);
|
| 140 |
+
files: FilesAPI.Files = new FilesAPI.Files(this._client);
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
export type AnthropicBeta =
|
| 144 |
+
| (string & {})
|
| 145 |
+
| 'message-batches-2024-09-24'
|
| 146 |
+
| 'prompt-caching-2024-07-31'
|
| 147 |
+
| 'computer-use-2024-10-22'
|
| 148 |
+
| 'computer-use-2025-01-24'
|
| 149 |
+
| 'pdfs-2024-09-25'
|
| 150 |
+
| 'token-counting-2024-11-01'
|
| 151 |
+
| 'token-efficient-tools-2025-02-19'
|
| 152 |
+
| 'output-128k-2025-02-19'
|
| 153 |
+
| 'files-api-2025-04-14'
|
| 154 |
+
| 'mcp-client-2025-04-04'
|
| 155 |
+
| 'dev-full-thinking-2025-05-14'
|
| 156 |
+
| 'interleaved-thinking-2025-05-14'
|
| 157 |
+
| 'code-execution-2025-05-22'
|
| 158 |
+
| 'extended-cache-ttl-2025-04-11';
|
| 159 |
+
|
| 160 |
+
export interface BetaAPIError {
|
| 161 |
+
message: string;
|
| 162 |
+
|
| 163 |
+
type: 'api_error';
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
export interface BetaAuthenticationError {
|
| 167 |
+
message: string;
|
| 168 |
+
|
| 169 |
+
type: 'authentication_error';
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
export interface BetaBillingError {
|
| 173 |
+
message: string;
|
| 174 |
+
|
| 175 |
+
type: 'billing_error';
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
export type BetaError =
|
| 179 |
+
| BetaInvalidRequestError
|
| 180 |
+
| BetaAuthenticationError
|
| 181 |
+
| BetaBillingError
|
| 182 |
+
| BetaPermissionError
|
| 183 |
+
| BetaNotFoundError
|
| 184 |
+
| BetaRateLimitError
|
| 185 |
+
| BetaGatewayTimeoutError
|
| 186 |
+
| BetaAPIError
|
| 187 |
+
| BetaOverloadedError;
|
| 188 |
+
|
| 189 |
+
export interface BetaErrorResponse {
|
| 190 |
+
error: BetaError;
|
| 191 |
+
|
| 192 |
+
type: 'error';
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
export interface BetaGatewayTimeoutError {
|
| 196 |
+
message: string;
|
| 197 |
+
|
| 198 |
+
type: 'timeout_error';
|
| 199 |
+
}
|
| 200 |
+
|
| 201 |
+
export interface BetaInvalidRequestError {
|
| 202 |
+
message: string;
|
| 203 |
+
|
| 204 |
+
type: 'invalid_request_error';
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
export interface BetaNotFoundError {
|
| 208 |
+
message: string;
|
| 209 |
+
|
| 210 |
+
type: 'not_found_error';
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
export interface BetaOverloadedError {
|
| 214 |
+
message: string;
|
| 215 |
+
|
| 216 |
+
type: 'overloaded_error';
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
export interface BetaPermissionError {
|
| 220 |
+
message: string;
|
| 221 |
+
|
| 222 |
+
type: 'permission_error';
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
export interface BetaRateLimitError {
|
| 226 |
+
message: string;
|
| 227 |
+
|
| 228 |
+
type: 'rate_limit_error';
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
Beta.Models = Models;
|
| 232 |
+
Beta.Messages = Messages;
|
| 233 |
+
Beta.Files = Files;
|
| 234 |
+
|
| 235 |
+
export declare namespace Beta {
|
| 236 |
+
export {
|
| 237 |
+
type AnthropicBeta as AnthropicBeta,
|
| 238 |
+
type BetaAPIError as BetaAPIError,
|
| 239 |
+
type BetaAuthenticationError as BetaAuthenticationError,
|
| 240 |
+
type BetaBillingError as BetaBillingError,
|
| 241 |
+
type BetaError as BetaError,
|
| 242 |
+
type BetaErrorResponse as BetaErrorResponse,
|
| 243 |
+
type BetaGatewayTimeoutError as BetaGatewayTimeoutError,
|
| 244 |
+
type BetaInvalidRequestError as BetaInvalidRequestError,
|
| 245 |
+
type BetaNotFoundError as BetaNotFoundError,
|
| 246 |
+
type BetaOverloadedError as BetaOverloadedError,
|
| 247 |
+
type BetaPermissionError as BetaPermissionError,
|
| 248 |
+
type BetaRateLimitError as BetaRateLimitError,
|
| 249 |
+
};
|
| 250 |
+
|
| 251 |
+
export {
|
| 252 |
+
Models as Models,
|
| 253 |
+
type BetaModelInfo as BetaModelInfo,
|
| 254 |
+
type BetaModelInfosPage as BetaModelInfosPage,
|
| 255 |
+
type ModelRetrieveParams as ModelRetrieveParams,
|
| 256 |
+
type ModelListParams as ModelListParams,
|
| 257 |
+
};
|
| 258 |
+
|
| 259 |
+
export {
|
| 260 |
+
Messages as Messages,
|
| 261 |
+
type BetaBase64ImageSource as BetaBase64ImageSource,
|
| 262 |
+
type BetaBase64PDFSource as BetaBase64PDFSource,
|
| 263 |
+
type BetaCacheControlEphemeral as BetaCacheControlEphemeral,
|
| 264 |
+
type BetaCacheCreation as BetaCacheCreation,
|
| 265 |
+
type BetaCitationCharLocation as BetaCitationCharLocation,
|
| 266 |
+
type BetaCitationCharLocationParam as BetaCitationCharLocationParam,
|
| 267 |
+
type BetaCitationContentBlockLocation as BetaCitationContentBlockLocation,
|
| 268 |
+
type BetaCitationContentBlockLocationParam as BetaCitationContentBlockLocationParam,
|
| 269 |
+
type BetaCitationPageLocation as BetaCitationPageLocation,
|
| 270 |
+
type BetaCitationPageLocationParam as BetaCitationPageLocationParam,
|
| 271 |
+
type BetaCitationSearchResultLocation as BetaCitationSearchResultLocation,
|
| 272 |
+
type BetaCitationSearchResultLocationParam as BetaCitationSearchResultLocationParam,
|
| 273 |
+
type BetaCitationWebSearchResultLocationParam as BetaCitationWebSearchResultLocationParam,
|
| 274 |
+
type BetaCitationsConfigParam as BetaCitationsConfigParam,
|
| 275 |
+
type BetaCitationsDelta as BetaCitationsDelta,
|
| 276 |
+
type BetaCitationsWebSearchResultLocation as BetaCitationsWebSearchResultLocation,
|
| 277 |
+
type BetaCodeExecutionOutputBlock as BetaCodeExecutionOutputBlock,
|
| 278 |
+
type BetaCodeExecutionOutputBlockParam as BetaCodeExecutionOutputBlockParam,
|
| 279 |
+
type BetaCodeExecutionResultBlock as BetaCodeExecutionResultBlock,
|
| 280 |
+
type BetaCodeExecutionResultBlockParam as BetaCodeExecutionResultBlockParam,
|
| 281 |
+
type BetaCodeExecutionTool20250522 as BetaCodeExecutionTool20250522,
|
| 282 |
+
type BetaCodeExecutionToolResultBlock as BetaCodeExecutionToolResultBlock,
|
| 283 |
+
type BetaCodeExecutionToolResultBlockContent as BetaCodeExecutionToolResultBlockContent,
|
| 284 |
+
type BetaCodeExecutionToolResultBlockParam as BetaCodeExecutionToolResultBlockParam,
|
| 285 |
+
type BetaCodeExecutionToolResultBlockParamContent as BetaCodeExecutionToolResultBlockParamContent,
|
| 286 |
+
type BetaCodeExecutionToolResultError as BetaCodeExecutionToolResultError,
|
| 287 |
+
type BetaCodeExecutionToolResultErrorCode as BetaCodeExecutionToolResultErrorCode,
|
| 288 |
+
type BetaCodeExecutionToolResultErrorParam as BetaCodeExecutionToolResultErrorParam,
|
| 289 |
+
type BetaContainer as BetaContainer,
|
| 290 |
+
type BetaContainerUploadBlock as BetaContainerUploadBlock,
|
| 291 |
+
type BetaContainerUploadBlockParam as BetaContainerUploadBlockParam,
|
| 292 |
+
type BetaContentBlock as BetaContentBlock,
|
| 293 |
+
type BetaContentBlockParam as BetaContentBlockParam,
|
| 294 |
+
type BetaContentBlockSource as BetaContentBlockSource,
|
| 295 |
+
type BetaContentBlockSourceContent as BetaContentBlockSourceContent,
|
| 296 |
+
type BetaFileDocumentSource as BetaFileDocumentSource,
|
| 297 |
+
type BetaFileImageSource as BetaFileImageSource,
|
| 298 |
+
type BetaImageBlockParam as BetaImageBlockParam,
|
| 299 |
+
type BetaInputJSONDelta as BetaInputJSONDelta,
|
| 300 |
+
type BetaMCPToolResultBlock as BetaMCPToolResultBlock,
|
| 301 |
+
type BetaMCPToolUseBlock as BetaMCPToolUseBlock,
|
| 302 |
+
type BetaMCPToolUseBlockParam as BetaMCPToolUseBlockParam,
|
| 303 |
+
type BetaMessage as BetaMessage,
|
| 304 |
+
type BetaMessageDeltaUsage as BetaMessageDeltaUsage,
|
| 305 |
+
type BetaMessageParam as BetaMessageParam,
|
| 306 |
+
type BetaMessageTokensCount as BetaMessageTokensCount,
|
| 307 |
+
type BetaMetadata as BetaMetadata,
|
| 308 |
+
type BetaPlainTextSource as BetaPlainTextSource,
|
| 309 |
+
type BetaRawContentBlockDelta as BetaRawContentBlockDelta,
|
| 310 |
+
type BetaRawContentBlockDeltaEvent as BetaRawContentBlockDeltaEvent,
|
| 311 |
+
type BetaRawContentBlockStartEvent as BetaRawContentBlockStartEvent,
|
| 312 |
+
type BetaRawContentBlockStopEvent as BetaRawContentBlockStopEvent,
|
| 313 |
+
type BetaRawMessageDeltaEvent as BetaRawMessageDeltaEvent,
|
| 314 |
+
type BetaRawMessageStartEvent as BetaRawMessageStartEvent,
|
| 315 |
+
type BetaRawMessageStopEvent as BetaRawMessageStopEvent,
|
| 316 |
+
type BetaRawMessageStreamEvent as BetaRawMessageStreamEvent,
|
| 317 |
+
type BetaRedactedThinkingBlock as BetaRedactedThinkingBlock,
|
| 318 |
+
type BetaRedactedThinkingBlockParam as BetaRedactedThinkingBlockParam,
|
| 319 |
+
type BetaRequestDocumentBlock as BetaRequestDocumentBlock,
|
| 320 |
+
type BetaRequestMCPServerToolConfiguration as BetaRequestMCPServerToolConfiguration,
|
| 321 |
+
type BetaRequestMCPServerURLDefinition as BetaRequestMCPServerURLDefinition,
|
| 322 |
+
type BetaRequestMCPToolResultBlockParam as BetaRequestMCPToolResultBlockParam,
|
| 323 |
+
type BetaSearchResultBlockParam as BetaSearchResultBlockParam,
|
| 324 |
+
type BetaServerToolUsage as BetaServerToolUsage,
|
| 325 |
+
type BetaServerToolUseBlock as BetaServerToolUseBlock,
|
| 326 |
+
type BetaServerToolUseBlockParam as BetaServerToolUseBlockParam,
|
| 327 |
+
type BetaSignatureDelta as BetaSignatureDelta,
|
| 328 |
+
type BetaStopReason as BetaStopReason,
|
| 329 |
+
type BetaTextBlock as BetaTextBlock,
|
| 330 |
+
type BetaTextBlockParam as BetaTextBlockParam,
|
| 331 |
+
type BetaTextCitation as BetaTextCitation,
|
| 332 |
+
type BetaTextCitationParam as BetaTextCitationParam,
|
| 333 |
+
type BetaTextDelta as BetaTextDelta,
|
| 334 |
+
type BetaThinkingBlock as BetaThinkingBlock,
|
| 335 |
+
type BetaThinkingBlockParam as BetaThinkingBlockParam,
|
| 336 |
+
type BetaThinkingConfigDisabled as BetaThinkingConfigDisabled,
|
| 337 |
+
type BetaThinkingConfigEnabled as BetaThinkingConfigEnabled,
|
| 338 |
+
type BetaThinkingConfigParam as BetaThinkingConfigParam,
|
| 339 |
+
type BetaThinkingDelta as BetaThinkingDelta,
|
| 340 |
+
type BetaTool as BetaTool,
|
| 341 |
+
type BetaToolBash20241022 as BetaToolBash20241022,
|
| 342 |
+
type BetaToolBash20250124 as BetaToolBash20250124,
|
| 343 |
+
type BetaToolChoice as BetaToolChoice,
|
| 344 |
+
type BetaToolChoiceAny as BetaToolChoiceAny,
|
| 345 |
+
type BetaToolChoiceAuto as BetaToolChoiceAuto,
|
| 346 |
+
type BetaToolChoiceNone as BetaToolChoiceNone,
|
| 347 |
+
type BetaToolChoiceTool as BetaToolChoiceTool,
|
| 348 |
+
type BetaToolComputerUse20241022 as BetaToolComputerUse20241022,
|
| 349 |
+
type BetaToolComputerUse20250124 as BetaToolComputerUse20250124,
|
| 350 |
+
type BetaToolResultBlockParam as BetaToolResultBlockParam,
|
| 351 |
+
type BetaToolTextEditor20241022 as BetaToolTextEditor20241022,
|
| 352 |
+
type BetaToolTextEditor20250124 as BetaToolTextEditor20250124,
|
| 353 |
+
type BetaToolTextEditor20250429 as BetaToolTextEditor20250429,
|
| 354 |
+
type BetaToolUnion as BetaToolUnion,
|
| 355 |
+
type BetaToolUseBlock as BetaToolUseBlock,
|
| 356 |
+
type BetaToolUseBlockParam as BetaToolUseBlockParam,
|
| 357 |
+
type BetaURLImageSource as BetaURLImageSource,
|
| 358 |
+
type BetaURLPDFSource as BetaURLPDFSource,
|
| 359 |
+
type BetaUsage as BetaUsage,
|
| 360 |
+
type BetaWebSearchResultBlock as BetaWebSearchResultBlock,
|
| 361 |
+
type BetaWebSearchResultBlockParam as BetaWebSearchResultBlockParam,
|
| 362 |
+
type BetaWebSearchTool20250305 as BetaWebSearchTool20250305,
|
| 363 |
+
type BetaWebSearchToolRequestError as BetaWebSearchToolRequestError,
|
| 364 |
+
type BetaWebSearchToolResultBlock as BetaWebSearchToolResultBlock,
|
| 365 |
+
type BetaWebSearchToolResultBlockContent as BetaWebSearchToolResultBlockContent,
|
| 366 |
+
type BetaWebSearchToolResultBlockParam as BetaWebSearchToolResultBlockParam,
|
| 367 |
+
type BetaWebSearchToolResultBlockParamContent as BetaWebSearchToolResultBlockParamContent,
|
| 368 |
+
type BetaWebSearchToolResultError as BetaWebSearchToolResultError,
|
| 369 |
+
type BetaWebSearchToolResultErrorCode as BetaWebSearchToolResultErrorCode,
|
| 370 |
+
type BetaBase64PDFBlock as BetaBase64PDFBlock,
|
| 371 |
+
type MessageCreateParams as MessageCreateParams,
|
| 372 |
+
type MessageCreateParamsNonStreaming as MessageCreateParamsNonStreaming,
|
| 373 |
+
type MessageCreateParamsStreaming as MessageCreateParamsStreaming,
|
| 374 |
+
type MessageCountTokensParams as MessageCountTokensParams,
|
| 375 |
+
};
|
| 376 |
+
|
| 377 |
+
export {
|
| 378 |
+
Files as Files,
|
| 379 |
+
type DeletedFile as DeletedFile,
|
| 380 |
+
type FileMetadata as FileMetadata,
|
| 381 |
+
type FileMetadataPage as FileMetadataPage,
|
| 382 |
+
type FileListParams as FileListParams,
|
| 383 |
+
type FileDeleteParams as FileDeleteParams,
|
| 384 |
+
type FileDownloadParams as FileDownloadParams,
|
| 385 |
+
type FileRetrieveMetadataParams as FileRetrieveMetadataParams,
|
| 386 |
+
type FileUploadParams as FileUploadParams,
|
| 387 |
+
};
|
| 388 |
+
}
|
node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/resources/beta/files.ts
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
| 2 |
+
|
| 3 |
+
import { APIResource } from '../../core/resource';
|
| 4 |
+
import * as BetaAPI from './beta';
|
| 5 |
+
import { APIPromise } from '../../core/api-promise';
|
| 6 |
+
import { Page, type PageParams, PagePromise } from '../../core/pagination';
|
| 7 |
+
import { type Uploadable } from '../../core/uploads';
|
| 8 |
+
import { buildHeaders } from '../../internal/headers';
|
| 9 |
+
import { RequestOptions } from '../../internal/request-options';
|
| 10 |
+
import { multipartFormRequestOptions } from '../../internal/uploads';
|
| 11 |
+
import { path } from '../../internal/utils/path';
|
| 12 |
+
|
| 13 |
+
export class Files extends APIResource {
|
| 14 |
+
/**
|
| 15 |
+
* List Files
|
| 16 |
+
*
|
| 17 |
+
* @example
|
| 18 |
+
* ```ts
|
| 19 |
+
* // Automatically fetches more pages as needed.
|
| 20 |
+
* for await (const fileMetadata of client.beta.files.list()) {
|
| 21 |
+
* // ...
|
| 22 |
+
* }
|
| 23 |
+
* ```
|
| 24 |
+
*/
|
| 25 |
+
list(
|
| 26 |
+
params: FileListParams | null | undefined = {},
|
| 27 |
+
options?: RequestOptions,
|
| 28 |
+
): PagePromise<FileMetadataPage, FileMetadata> {
|
| 29 |
+
const { betas, ...query } = params ?? {};
|
| 30 |
+
return this._client.getAPIList('/v1/files', Page<FileMetadata>, {
|
| 31 |
+
query,
|
| 32 |
+
...options,
|
| 33 |
+
headers: buildHeaders([
|
| 34 |
+
{ 'anthropic-beta': [...(betas ?? []), 'files-api-2025-04-14'].toString() },
|
| 35 |
+
options?.headers,
|
| 36 |
+
]),
|
| 37 |
+
});
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
/**
|
| 41 |
+
* Delete File
|
| 42 |
+
*
|
| 43 |
+
* @example
|
| 44 |
+
* ```ts
|
| 45 |
+
* const deletedFile = await client.beta.files.delete(
|
| 46 |
+
* 'file_id',
|
| 47 |
+
* );
|
| 48 |
+
* ```
|
| 49 |
+
*/
|
| 50 |
+
delete(
|
| 51 |
+
fileID: string,
|
| 52 |
+
params: FileDeleteParams | null | undefined = {},
|
| 53 |
+
options?: RequestOptions,
|
| 54 |
+
): APIPromise<DeletedFile> {
|
| 55 |
+
const { betas } = params ?? {};
|
| 56 |
+
return this._client.delete(path`/v1/files/${fileID}`, {
|
| 57 |
+
...options,
|
| 58 |
+
headers: buildHeaders([
|
| 59 |
+
{ 'anthropic-beta': [...(betas ?? []), 'files-api-2025-04-14'].toString() },
|
| 60 |
+
options?.headers,
|
| 61 |
+
]),
|
| 62 |
+
});
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
/**
|
| 66 |
+
* Download File
|
| 67 |
+
*
|
| 68 |
+
* @example
|
| 69 |
+
* ```ts
|
| 70 |
+
* const response = await client.beta.files.download(
|
| 71 |
+
* 'file_id',
|
| 72 |
+
* );
|
| 73 |
+
*
|
| 74 |
+
* const content = await response.blob();
|
| 75 |
+
* console.log(content);
|
| 76 |
+
* ```
|
| 77 |
+
*/
|
| 78 |
+
download(
|
| 79 |
+
fileID: string,
|
| 80 |
+
params: FileDownloadParams | null | undefined = {},
|
| 81 |
+
options?: RequestOptions,
|
| 82 |
+
): APIPromise<Response> {
|
| 83 |
+
const { betas } = params ?? {};
|
| 84 |
+
return this._client.get(path`/v1/files/${fileID}/content`, {
|
| 85 |
+
...options,
|
| 86 |
+
headers: buildHeaders([
|
| 87 |
+
{
|
| 88 |
+
'anthropic-beta': [...(betas ?? []), 'files-api-2025-04-14'].toString(),
|
| 89 |
+
Accept: 'application/binary',
|
| 90 |
+
},
|
| 91 |
+
options?.headers,
|
| 92 |
+
]),
|
| 93 |
+
__binaryResponse: true,
|
| 94 |
+
});
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
/**
|
| 98 |
+
* Get File Metadata
|
| 99 |
+
*
|
| 100 |
+
* @example
|
| 101 |
+
* ```ts
|
| 102 |
+
* const fileMetadata =
|
| 103 |
+
* await client.beta.files.retrieveMetadata('file_id');
|
| 104 |
+
* ```
|
| 105 |
+
*/
|
| 106 |
+
retrieveMetadata(
|
| 107 |
+
fileID: string,
|
| 108 |
+
params: FileRetrieveMetadataParams | null | undefined = {},
|
| 109 |
+
options?: RequestOptions,
|
| 110 |
+
): APIPromise<FileMetadata> {
|
| 111 |
+
const { betas } = params ?? {};
|
| 112 |
+
return this._client.get(path`/v1/files/${fileID}`, {
|
| 113 |
+
...options,
|
| 114 |
+
headers: buildHeaders([
|
| 115 |
+
{ 'anthropic-beta': [...(betas ?? []), 'files-api-2025-04-14'].toString() },
|
| 116 |
+
options?.headers,
|
| 117 |
+
]),
|
| 118 |
+
});
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
/**
|
| 122 |
+
* Upload File
|
| 123 |
+
*
|
| 124 |
+
* @example
|
| 125 |
+
* ```ts
|
| 126 |
+
* const fileMetadata = await client.beta.files.upload({
|
| 127 |
+
* file: fs.createReadStream('path/to/file'),
|
| 128 |
+
* });
|
| 129 |
+
* ```
|
| 130 |
+
*/
|
| 131 |
+
upload(params: FileUploadParams, options?: RequestOptions): APIPromise<FileMetadata> {
|
| 132 |
+
const { betas, ...body } = params;
|
| 133 |
+
return this._client.post(
|
| 134 |
+
'/v1/files',
|
| 135 |
+
multipartFormRequestOptions(
|
| 136 |
+
{
|
| 137 |
+
body,
|
| 138 |
+
...options,
|
| 139 |
+
headers: buildHeaders([
|
| 140 |
+
{ 'anthropic-beta': [...(betas ?? []), 'files-api-2025-04-14'].toString() },
|
| 141 |
+
options?.headers,
|
| 142 |
+
]),
|
| 143 |
+
},
|
| 144 |
+
this._client,
|
| 145 |
+
),
|
| 146 |
+
);
|
| 147 |
+
}
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
export type FileMetadataPage = Page<FileMetadata>;
|
| 151 |
+
|
| 152 |
+
export interface DeletedFile {
|
| 153 |
+
/**
|
| 154 |
+
* ID of the deleted file.
|
| 155 |
+
*/
|
| 156 |
+
id: string;
|
| 157 |
+
|
| 158 |
+
/**
|
| 159 |
+
* Deleted object type.
|
| 160 |
+
*
|
| 161 |
+
* For file deletion, this is always `"file_deleted"`.
|
| 162 |
+
*/
|
| 163 |
+
type?: 'file_deleted';
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
export interface FileMetadata {
|
| 167 |
+
/**
|
| 168 |
+
* Unique object identifier.
|
| 169 |
+
*
|
| 170 |
+
* The format and length of IDs may change over time.
|
| 171 |
+
*/
|
| 172 |
+
id: string;
|
| 173 |
+
|
| 174 |
+
/**
|
| 175 |
+
* RFC 3339 datetime string representing when the file was created.
|
| 176 |
+
*/
|
| 177 |
+
created_at: string;
|
| 178 |
+
|
| 179 |
+
/**
|
| 180 |
+
* Original filename of the uploaded file.
|
| 181 |
+
*/
|
| 182 |
+
filename: string;
|
| 183 |
+
|
| 184 |
+
/**
|
| 185 |
+
* MIME type of the file.
|
| 186 |
+
*/
|
| 187 |
+
mime_type: string;
|
| 188 |
+
|
| 189 |
+
/**
|
| 190 |
+
* Size of the file in bytes.
|
| 191 |
+
*/
|
| 192 |
+
size_bytes: number;
|
| 193 |
+
|
| 194 |
+
/**
|
| 195 |
+
* Object type.
|
| 196 |
+
*
|
| 197 |
+
* For files, this is always `"file"`.
|
| 198 |
+
*/
|
| 199 |
+
type: 'file';
|
| 200 |
+
|
| 201 |
+
/**
|
| 202 |
+
* Whether the file can be downloaded.
|
| 203 |
+
*/
|
| 204 |
+
downloadable?: boolean;
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
export interface FileListParams extends PageParams {
|
| 208 |
+
/**
|
| 209 |
+
* Header param: Optional header to specify the beta version(s) you want to use.
|
| 210 |
+
*/
|
| 211 |
+
betas?: Array<BetaAPI.AnthropicBeta>;
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
export interface FileDeleteParams {
|
| 215 |
+
/**
|
| 216 |
+
* Optional header to specify the beta version(s) you want to use.
|
| 217 |
+
*/
|
| 218 |
+
betas?: Array<BetaAPI.AnthropicBeta>;
|
| 219 |
+
}
|
| 220 |
+
|
| 221 |
+
export interface FileDownloadParams {
|
| 222 |
+
/**
|
| 223 |
+
* Optional header to specify the beta version(s) you want to use.
|
| 224 |
+
*/
|
| 225 |
+
betas?: Array<BetaAPI.AnthropicBeta>;
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
export interface FileRetrieveMetadataParams {
|
| 229 |
+
/**
|
| 230 |
+
* Optional header to specify the beta version(s) you want to use.
|
| 231 |
+
*/
|
| 232 |
+
betas?: Array<BetaAPI.AnthropicBeta>;
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
export interface FileUploadParams {
|
| 236 |
+
/**
|
| 237 |
+
* Body param: The file to upload
|
| 238 |
+
*/
|
| 239 |
+
file: Uploadable;
|
| 240 |
+
|
| 241 |
+
/**
|
| 242 |
+
* Header param: Optional header to specify the beta version(s) you want to use.
|
| 243 |
+
*/
|
| 244 |
+
betas?: Array<BetaAPI.AnthropicBeta>;
|
| 245 |
+
}
|
| 246 |
+
|
| 247 |
+
export declare namespace Files {
|
| 248 |
+
export {
|
| 249 |
+
type DeletedFile as DeletedFile,
|
| 250 |
+
type FileMetadata as FileMetadata,
|
| 251 |
+
type FileMetadataPage as FileMetadataPage,
|
| 252 |
+
type FileListParams as FileListParams,
|
| 253 |
+
type FileDeleteParams as FileDeleteParams,
|
| 254 |
+
type FileDownloadParams as FileDownloadParams,
|
| 255 |
+
type FileRetrieveMetadataParams as FileRetrieveMetadataParams,
|
| 256 |
+
type FileUploadParams as FileUploadParams,
|
|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
|
| 1 |
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
| 2 |
+
|
| 3 |
+
export {
|
| 4 |
+
Beta,
|
| 5 |
+
type AnthropicBeta,
|
| 6 |
+
type BetaAPIError,
|
| 7 |
+
type BetaAuthenticationError,
|
| 8 |
+
type BetaBillingError,
|
| 9 |
+
type BetaError,
|
| 10 |
+
type BetaErrorResponse,
|
| 11 |
+
type BetaGatewayTimeoutError,
|
| 12 |
+
type BetaInvalidRequestError,
|
| 13 |
+
type BetaNotFoundError,
|
| 14 |
+
type BetaOverloadedError,
|
| 15 |
+
type BetaPermissionError,
|
| 16 |
+
type BetaRateLimitError,
|
| 17 |
+
} from './beta';
|
| 18 |
+
export {
|
| 19 |
+
Files,
|
| 20 |
+
type DeletedFile,
|
| 21 |
+
type FileMetadata,
|
| 22 |
+
type FileListParams,
|
| 23 |
+
type FileDeleteParams,
|
| 24 |
+
type FileDownloadParams,
|
| 25 |
+
type FileRetrieveMetadataParams,
|
| 26 |
+
type FileUploadParams,
|
| 27 |
+
type FileMetadataPage,
|
| 28 |
+
} from './files';
|
| 29 |
+
export {
|
| 30 |
+
Messages,
|
| 31 |
+
type BetaBase64ImageSource,
|
| 32 |
+
type BetaBase64PDFSource,
|
| 33 |
+
type BetaCacheControlEphemeral,
|
| 34 |
+
type BetaCacheCreation,
|
| 35 |
+
type BetaCitationCharLocation,
|
| 36 |
+
type BetaCitationCharLocationParam,
|
| 37 |
+
type BetaCitationContentBlockLocation,
|
| 38 |
+
type BetaCitationContentBlockLocationParam,
|
| 39 |
+
type BetaCitationPageLocation,
|
| 40 |
+
type BetaCitationPageLocationParam,
|
| 41 |
+
type BetaCitationSearchResultLocation,
|
| 42 |
+
type BetaCitationSearchResultLocationParam,
|
| 43 |
+
type BetaCitationWebSearchResultLocationParam,
|
| 44 |
+
type BetaCitationsConfigParam,
|
| 45 |
+
type BetaCitationsDelta,
|
| 46 |
+
type BetaCitationsWebSearchResultLocation,
|
| 47 |
+
type BetaCodeExecutionOutputBlock,
|
| 48 |
+
type BetaCodeExecutionOutputBlockParam,
|
| 49 |
+
type BetaCodeExecutionResultBlock,
|
| 50 |
+
type BetaCodeExecutionResultBlockParam,
|
| 51 |
+
type BetaCodeExecutionTool20250522,
|
| 52 |
+
type BetaCodeExecutionToolResultBlock,
|
| 53 |
+
type BetaCodeExecutionToolResultBlockContent,
|
| 54 |
+
type BetaCodeExecutionToolResultBlockParam,
|
| 55 |
+
type BetaCodeExecutionToolResultBlockParamContent,
|
| 56 |
+
type BetaCodeExecutionToolResultError,
|
| 57 |
+
type BetaCodeExecutionToolResultErrorCode,
|
| 58 |
+
type BetaCodeExecutionToolResultErrorParam,
|
| 59 |
+
type BetaContainer,
|
| 60 |
+
type BetaContainerUploadBlock,
|
| 61 |
+
type BetaContainerUploadBlockParam,
|
| 62 |
+
type BetaContentBlock,
|
| 63 |
+
type BetaContentBlockParam,
|
| 64 |
+
type BetaContentBlockSource,
|
| 65 |
+
type BetaContentBlockSourceContent,
|
| 66 |
+
type BetaFileDocumentSource,
|
| 67 |
+
type BetaFileImageSource,
|
| 68 |
+
type BetaImageBlockParam,
|
| 69 |
+
type BetaInputJSONDelta,
|
| 70 |
+
type BetaMCPToolResultBlock,
|
| 71 |
+
type BetaMCPToolUseBlock,
|
| 72 |
+
type BetaMCPToolUseBlockParam,
|
| 73 |
+
type BetaMessage,
|
| 74 |
+
type BetaMessageDeltaUsage,
|
| 75 |
+
type BetaMessageParam,
|
| 76 |
+
type BetaMessageTokensCount,
|
| 77 |
+
type BetaMetadata,
|
| 78 |
+
type BetaPlainTextSource,
|
| 79 |
+
type BetaRawContentBlockDelta,
|
| 80 |
+
type BetaRawContentBlockDeltaEvent,
|
| 81 |
+
type BetaRawContentBlockStartEvent,
|
| 82 |
+
type BetaRawContentBlockStopEvent,
|
| 83 |
+
type BetaRawMessageDeltaEvent,
|
| 84 |
+
type BetaRawMessageStartEvent,
|
| 85 |
+
type BetaRawMessageStopEvent,
|
| 86 |
+
type BetaRawMessageStreamEvent,
|
| 87 |
+
type BetaRedactedThinkingBlock,
|
| 88 |
+
type BetaRedactedThinkingBlockParam,
|
| 89 |
+
type BetaRequestDocumentBlock,
|
| 90 |
+
type BetaRequestMCPServerToolConfiguration,
|
| 91 |
+
type BetaRequestMCPServerURLDefinition,
|
| 92 |
+
type BetaRequestMCPToolResultBlockParam,
|
| 93 |
+
type BetaSearchResultBlockParam,
|
| 94 |
+
type BetaServerToolUsage,
|
| 95 |
+
type BetaServerToolUseBlock,
|
| 96 |
+
type BetaServerToolUseBlockParam,
|
| 97 |
+
type BetaSignatureDelta,
|
| 98 |
+
type BetaStopReason,
|
| 99 |
+
type BetaTextBlock,
|
| 100 |
+
type BetaTextBlockParam,
|
| 101 |
+
type BetaTextCitation,
|
| 102 |
+
type BetaTextCitationParam,
|
| 103 |
+
type BetaTextDelta,
|
| 104 |
+
type BetaThinkingBlock,
|
| 105 |
+
type BetaThinkingBlockParam,
|
| 106 |
+
type BetaThinkingConfigDisabled,
|
| 107 |
+
type BetaThinkingConfigEnabled,
|
| 108 |
+
type BetaThinkingConfigParam,
|
| 109 |
+
type BetaThinkingDelta,
|
| 110 |
+
type BetaTool,
|
| 111 |
+
type BetaToolBash20241022,
|
| 112 |
+
type BetaToolBash20250124,
|
| 113 |
+
type BetaToolChoice,
|
| 114 |
+
type BetaToolChoiceAny,
|
| 115 |
+
type BetaToolChoiceAuto,
|
| 116 |
+
type BetaToolChoiceNone,
|
| 117 |
+
type BetaToolChoiceTool,
|
| 118 |
+
type BetaToolComputerUse20241022,
|
| 119 |
+
type BetaToolComputerUse20250124,
|
| 120 |
+
type BetaToolResultBlockParam,
|
| 121 |
+
type BetaToolTextEditor20241022,
|
| 122 |
+
type BetaToolTextEditor20250124,
|
| 123 |
+
type BetaToolTextEditor20250429,
|
| 124 |
+
type BetaToolUnion,
|
| 125 |
+
type BetaToolUseBlock,
|
| 126 |
+
type BetaToolUseBlockParam,
|
| 127 |
+
type BetaURLImageSource,
|
| 128 |
+
type BetaURLPDFSource,
|
| 129 |
+
type BetaUsage,
|
| 130 |
+
type BetaWebSearchResultBlock,
|
| 131 |
+
type BetaWebSearchResultBlockParam,
|
| 132 |
+
type BetaWebSearchTool20250305,
|
| 133 |
+
type BetaWebSearchToolRequestError,
|
| 134 |
+
type BetaWebSearchToolResultBlock,
|
| 135 |
+
type BetaWebSearchToolResultBlockContent,
|
| 136 |
+
type BetaWebSearchToolResultBlockParam,
|
| 137 |
+
type BetaWebSearchToolResultBlockParamContent,
|
| 138 |
+
type BetaWebSearchToolResultError,
|
| 139 |
+
type BetaWebSearchToolResultErrorCode,
|
| 140 |
+
type BetaBase64PDFBlock,
|
| 141 |
+
type MessageCreateParams,
|
| 142 |
+
type MessageCreateParamsNonStreaming,
|
| 143 |
+
type MessageCreateParamsStreaming,
|
| 144 |
+
type MessageCountTokensParams,
|
| 145 |
+
} from './messages/index';
|
| 146 |
+
export {
|
| 147 |
+
Models,
|
| 148 |
+
type BetaModelInfo,
|
| 149 |
+
type ModelRetrieveParams,
|
| 150 |
+
type ModelListParams,
|
| 151 |
+
type BetaModelInfosPage,
|
| 152 |
+
} from './models';
|
node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/resources/beta/messages.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
| 2 |
+
|
| 3 |
+
export * from './messages/index';
|
node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/resources/beta/messages/batches.ts
ADDED
|
@@ -0,0 +1,502 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
| 2 |
+
|
| 3 |
+
import { APIResource } from '../../../core/resource';
|
| 4 |
+
import * as BetaAPI from '../beta';
|
| 5 |
+
import { APIPromise } from '../../../core/api-promise';
|
| 6 |
+
import * as BetaMessagesAPI from './messages';
|
| 7 |
+
import { Page, type PageParams, PagePromise } from '../../../core/pagination';
|
| 8 |
+
import { buildHeaders } from '../../../internal/headers';
|
| 9 |
+
import { RequestOptions } from '../../../internal/request-options';
|
| 10 |
+
import { JSONLDecoder } from '../../../internal/decoders/jsonl';
|
| 11 |
+
import { AnthropicError } from '../../../error';
|
| 12 |
+
import { path } from '../../../internal/utils/path';
|
| 13 |
+
|
| 14 |
+
export class Batches extends APIResource {
|
| 15 |
+
/**
|
| 16 |
+
* Send a batch of Message creation requests.
|
| 17 |
+
*
|
| 18 |
+
* The Message Batches API can be used to process multiple Messages API requests at
|
| 19 |
+
* once. Once a Message Batch is created, it begins processing immediately. Batches
|
| 20 |
+
* can take up to 24 hours to complete.
|
| 21 |
+
*
|
| 22 |
+
* Learn more about the Message Batches API in our
|
| 23 |
+
* [user guide](/en/docs/build-with-claude/batch-processing)
|
| 24 |
+
*
|
| 25 |
+
* @example
|
| 26 |
+
* ```ts
|
| 27 |
+
* const betaMessageBatch =
|
| 28 |
+
* await client.beta.messages.batches.create({
|
| 29 |
+
* requests: [
|
| 30 |
+
* {
|
| 31 |
+
* custom_id: 'my-custom-id-1',
|
| 32 |
+
* params: {
|
| 33 |
+
* max_tokens: 1024,
|
| 34 |
+
* messages: [
|
| 35 |
+
* { content: 'Hello, world', role: 'user' },
|
| 36 |
+
* ],
|
| 37 |
+
* model: 'claude-sonnet-4-20250514',
|
| 38 |
+
* },
|
| 39 |
+
* },
|
| 40 |
+
* ],
|
| 41 |
+
* });
|
| 42 |
+
* ```
|
| 43 |
+
*/
|
| 44 |
+
create(params: BatchCreateParams, options?: RequestOptions): APIPromise<BetaMessageBatch> {
|
| 45 |
+
const { betas, ...body } = params;
|
| 46 |
+
return this._client.post('/v1/messages/batches?beta=true', {
|
| 47 |
+
body,
|
| 48 |
+
...options,
|
| 49 |
+
headers: buildHeaders([
|
| 50 |
+
{ 'anthropic-beta': [...(betas ?? []), 'message-batches-2024-09-24'].toString() },
|
| 51 |
+
options?.headers,
|
| 52 |
+
]),
|
| 53 |
+
});
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
/**
|
| 57 |
+
* This endpoint is idempotent and can be used to poll for Message Batch
|
| 58 |
+
* completion. To access the results of a Message Batch, make a request to the
|
| 59 |
+
* `results_url` field in the response.
|
| 60 |
+
*
|
| 61 |
+
* Learn more about the Message Batches API in our
|
| 62 |
+
* [user guide](/en/docs/build-with-claude/batch-processing)
|
| 63 |
+
*
|
| 64 |
+
* @example
|
| 65 |
+
* ```ts
|
| 66 |
+
* const betaMessageBatch =
|
| 67 |
+
* await client.beta.messages.batches.retrieve(
|
| 68 |
+
* 'message_batch_id',
|
| 69 |
+
* );
|
| 70 |
+
* ```
|
| 71 |
+
*/
|
| 72 |
+
retrieve(
|
| 73 |
+
messageBatchID: string,
|
| 74 |
+
params: BatchRetrieveParams | null | undefined = {},
|
| 75 |
+
options?: RequestOptions,
|
| 76 |
+
): APIPromise<BetaMessageBatch> {
|
| 77 |
+
const { betas } = params ?? {};
|
| 78 |
+
return this._client.get(path`/v1/messages/batches/${messageBatchID}?beta=true`, {
|
| 79 |
+
...options,
|
| 80 |
+
headers: buildHeaders([
|
| 81 |
+
{ 'anthropic-beta': [...(betas ?? []), 'message-batches-2024-09-24'].toString() },
|
| 82 |
+
options?.headers,
|
| 83 |
+
]),
|
| 84 |
+
});
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
/**
|
| 88 |
+
* List all Message Batches within a Workspace. Most recently created batches are
|
| 89 |
+
* returned first.
|
| 90 |
+
*
|
| 91 |
+
* Learn more about the Message Batches API in our
|
| 92 |
+
* [user guide](/en/docs/build-with-claude/batch-processing)
|
| 93 |
+
*
|
| 94 |
+
* @example
|
| 95 |
+
* ```ts
|
| 96 |
+
* // Automatically fetches more pages as needed.
|
| 97 |
+
* for await (const betaMessageBatch of client.beta.messages.batches.list()) {
|
| 98 |
+
* // ...
|
| 99 |
+
* }
|
| 100 |
+
* ```
|
| 101 |
+
*/
|
| 102 |
+
list(
|
| 103 |
+
params: BatchListParams | null | undefined = {},
|
| 104 |
+
options?: RequestOptions,
|
| 105 |
+
): PagePromise<BetaMessageBatchesPage, BetaMessageBatch> {
|
| 106 |
+
const { betas, ...query } = params ?? {};
|
| 107 |
+
return this._client.getAPIList('/v1/messages/batches?beta=true', Page<BetaMessageBatch>, {
|
| 108 |
+
query,
|
| 109 |
+
...options,
|
| 110 |
+
headers: buildHeaders([
|
| 111 |
+
{ 'anthropic-beta': [...(betas ?? []), 'message-batches-2024-09-24'].toString() },
|
| 112 |
+
options?.headers,
|
| 113 |
+
]),
|
| 114 |
+
});
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
/**
|
| 118 |
+
* Delete a Message Batch.
|
| 119 |
+
*
|
| 120 |
+
* Message Batches can only be deleted once they've finished processing. If you'd
|
| 121 |
+
* like to delete an in-progress batch, you must first cancel it.
|
| 122 |
+
*
|
| 123 |
+
* Learn more about the Message Batches API in our
|
| 124 |
+
* [user guide](/en/docs/build-with-claude/batch-processing)
|
| 125 |
+
*
|
| 126 |
+
* @example
|
| 127 |
+
* ```ts
|
| 128 |
+
* const betaDeletedMessageBatch =
|
| 129 |
+
* await client.beta.messages.batches.delete(
|
| 130 |
+
* 'message_batch_id',
|
| 131 |
+
* );
|
| 132 |
+
* ```
|
| 133 |
+
*/
|
| 134 |
+
delete(
|
| 135 |
+
messageBatchID: string,
|
| 136 |
+
params: BatchDeleteParams | null | undefined = {},
|
| 137 |
+
options?: RequestOptions,
|
| 138 |
+
): APIPromise<BetaDeletedMessageBatch> {
|
| 139 |
+
const { betas } = params ?? {};
|
| 140 |
+
return this._client.delete(path`/v1/messages/batches/${messageBatchID}?beta=true`, {
|
| 141 |
+
...options,
|
| 142 |
+
headers: buildHeaders([
|
| 143 |
+
{ 'anthropic-beta': [...(betas ?? []), 'message-batches-2024-09-24'].toString() },
|
| 144 |
+
options?.headers,
|
| 145 |
+
]),
|
| 146 |
+
});
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
/**
|
| 150 |
+
* Batches may be canceled any time before processing ends. Once cancellation is
|
| 151 |
+
* initiated, the batch enters a `canceling` state, at which time the system may
|
| 152 |
+
* complete any in-progress, non-interruptible requests before finalizing
|
| 153 |
+
* cancellation.
|
| 154 |
+
*
|
| 155 |
+
* The number of canceled requests is specified in `request_counts`. To determine
|
| 156 |
+
* which requests were canceled, check the individual results within the batch.
|
| 157 |
+
* Note that cancellation may not result in any canceled requests if they were
|
| 158 |
+
* non-interruptible.
|
| 159 |
+
*
|
| 160 |
+
* Learn more about the Message Batches API in our
|
| 161 |
+
* [user guide](/en/docs/build-with-claude/batch-processing)
|
| 162 |
+
*
|
| 163 |
+
* @example
|
| 164 |
+
* ```ts
|
| 165 |
+
* const betaMessageBatch =
|
| 166 |
+
* await client.beta.messages.batches.cancel(
|
| 167 |
+
* 'message_batch_id',
|
| 168 |
+
* );
|
| 169 |
+
* ```
|
| 170 |
+
*/
|
| 171 |
+
cancel(
|
| 172 |
+
messageBatchID: string,
|
| 173 |
+
params: BatchCancelParams | null | undefined = {},
|
| 174 |
+
options?: RequestOptions,
|
| 175 |
+
): APIPromise<BetaMessageBatch> {
|
| 176 |
+
const { betas } = params ?? {};
|
| 177 |
+
return this._client.post(path`/v1/messages/batches/${messageBatchID}/cancel?beta=true`, {
|
| 178 |
+
...options,
|
| 179 |
+
headers: buildHeaders([
|
| 180 |
+
{ 'anthropic-beta': [...(betas ?? []), 'message-batches-2024-09-24'].toString() },
|
| 181 |
+
options?.headers,
|
| 182 |
+
]),
|
| 183 |
+
});
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
/**
|
| 187 |
+
* Streams the results of a Message Batch as a `.jsonl` file.
|
| 188 |
+
*
|
| 189 |
+
* Each line in the file is a JSON object containing the result of a single request
|
| 190 |
+
* in the Message Batch. Results are not guaranteed to be in the same order as
|
| 191 |
+
* requests. Use the `custom_id` field to match results to requests.
|
| 192 |
+
*
|
| 193 |
+
* Learn more about the Message Batches API in our
|
| 194 |
+
* [user guide](/en/docs/build-with-claude/batch-processing)
|
| 195 |
+
*
|
| 196 |
+
* @example
|
| 197 |
+
* ```ts
|
| 198 |
+
* const betaMessageBatchIndividualResponse =
|
| 199 |
+
* await client.beta.messages.batches.results(
|
| 200 |
+
* 'message_batch_id',
|
| 201 |
+
* );
|
| 202 |
+
* ```
|
| 203 |
+
*/
|
| 204 |
+
async results(
|
| 205 |
+
messageBatchID: string,
|
| 206 |
+
params: BatchResultsParams | undefined = {},
|
| 207 |
+
options?: RequestOptions,
|
| 208 |
+
): Promise<JSONLDecoder<BetaMessageBatchIndividualResponse>> {
|
| 209 |
+
const batch = await this.retrieve(messageBatchID);
|
| 210 |
+
if (!batch.results_url) {
|
| 211 |
+
throw new AnthropicError(
|
| 212 |
+
`No batch \`results_url\`; Has it finished processing? ${batch.processing_status} - ${batch.id}`,
|
| 213 |
+
);
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
const { betas } = params ?? {};
|
| 217 |
+
return this._client
|
| 218 |
+
.get(batch.results_url, {
|
| 219 |
+
...options,
|
| 220 |
+
headers: buildHeaders([
|
| 221 |
+
{
|
| 222 |
+
'anthropic-beta': [...(betas ?? []), 'message-batches-2024-09-24'].toString(),
|
| 223 |
+
Accept: 'application/binary',
|
| 224 |
+
},
|
| 225 |
+
options?.headers,
|
| 226 |
+
]),
|
| 227 |
+
stream: true,
|
| 228 |
+
__binaryResponse: true,
|
| 229 |
+
})
|
| 230 |
+
._thenUnwrap((_, props) => JSONLDecoder.fromResponse(props.response, props.controller)) as APIPromise<
|
| 231 |
+
JSONLDecoder<BetaMessageBatchIndividualResponse>
|
| 232 |
+
>;
|
| 233 |
+
}
|
| 234 |
+
}
|
| 235 |
+
|
| 236 |
+
export type BetaMessageBatchesPage = Page<BetaMessageBatch>;
|
| 237 |
+
|
| 238 |
+
export interface BetaDeletedMessageBatch {
|
| 239 |
+
/**
|
| 240 |
+
* ID of the Message Batch.
|
| 241 |
+
*/
|
| 242 |
+
id: string;
|
| 243 |
+
|
| 244 |
+
/**
|
| 245 |
+
* Deleted object type.
|
| 246 |
+
*
|
| 247 |
+
* For Message Batches, this is always `"message_batch_deleted"`.
|
| 248 |
+
*/
|
| 249 |
+
type: 'message_batch_deleted';
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
+
export interface BetaMessageBatch {
|
| 253 |
+
/**
|
| 254 |
+
* Unique object identifier.
|
| 255 |
+
*
|
| 256 |
+
* The format and length of IDs may change over time.
|
| 257 |
+
*/
|
| 258 |
+
id: string;
|
| 259 |
+
|
| 260 |
+
/**
|
| 261 |
+
* RFC 3339 datetime string representing the time at which the Message Batch was
|
| 262 |
+
* archived and its results became unavailable.
|
| 263 |
+
*/
|
| 264 |
+
archived_at: string | null;
|
| 265 |
+
|
| 266 |
+
/**
|
| 267 |
+
* RFC 3339 datetime string representing the time at which cancellation was
|
| 268 |
+
* initiated for the Message Batch. Specified only if cancellation was initiated.
|
| 269 |
+
*/
|
| 270 |
+
cancel_initiated_at: string | null;
|
| 271 |
+
|
| 272 |
+
/**
|
| 273 |
+
* RFC 3339 datetime string representing the time at which the Message Batch was
|
| 274 |
+
* created.
|
| 275 |
+
*/
|
| 276 |
+
created_at: string;
|
| 277 |
+
|
| 278 |
+
/**
|
| 279 |
+
* RFC 3339 datetime string representing the time at which processing for the
|
| 280 |
+
* Message Batch ended. Specified only once processing ends.
|
| 281 |
+
*
|
| 282 |
+
* Processing ends when every request in a Message Batch has either succeeded,
|
| 283 |
+
* errored, canceled, or expired.
|
| 284 |
+
*/
|
| 285 |
+
ended_at: string | null;
|
| 286 |
+
|
| 287 |
+
/**
|
| 288 |
+
* RFC 3339 datetime string representing the time at which the Message Batch will
|
| 289 |
+
* expire and end processing, which is 24 hours after creation.
|
| 290 |
+
*/
|
| 291 |
+
expires_at: string;
|
| 292 |
+
|
| 293 |
+
/**
|
| 294 |
+
* Processing status of the Message Batch.
|
| 295 |
+
*/
|
| 296 |
+
processing_status: 'in_progress' | 'canceling' | 'ended';
|
| 297 |
+
|
| 298 |
+
/**
|
| 299 |
+
* Tallies requests within the Message Batch, categorized by their status.
|
| 300 |
+
*
|
| 301 |
+
* Requests start as `processing` and move to one of the other statuses only once
|
| 302 |
+
* processing of the entire batch ends. The sum of all values always matches the
|
| 303 |
+
* total number of requests in the batch.
|
| 304 |
+
*/
|
| 305 |
+
request_counts: BetaMessageBatchRequestCounts;
|
| 306 |
+
|
| 307 |
+
/**
|
| 308 |
+
* URL to a `.jsonl` file containing the results of the Message Batch requests.
|
| 309 |
+
* Specified only once processing ends.
|
| 310 |
+
*
|
| 311 |
+
* Results in the file are not guaranteed to be in the same order as requests. Use
|
| 312 |
+
* the `custom_id` field to match results to requests.
|
| 313 |
+
*/
|
| 314 |
+
results_url: string | null;
|
| 315 |
+
|
| 316 |
+
/**
|
| 317 |
+
* Object type.
|
| 318 |
+
*
|
| 319 |
+
* For Message Batches, this is always `"message_batch"`.
|
| 320 |
+
*/
|
| 321 |
+
type: 'message_batch';
|
| 322 |
+
}
|
| 323 |
+
|
| 324 |
+
export interface BetaMessageBatchCanceledResult {
|
| 325 |
+
type: 'canceled';
|
| 326 |
+
}
|
| 327 |
+
|
| 328 |
+
export interface BetaMessageBatchErroredResult {
|
| 329 |
+
error: BetaAPI.BetaErrorResponse;
|
| 330 |
+
|
| 331 |
+
type: 'errored';
|
| 332 |
+
}
|
| 333 |
+
|
| 334 |
+
export interface BetaMessageBatchExpiredResult {
|
| 335 |
+
type: 'expired';
|
| 336 |
+
}
|
| 337 |
+
|
| 338 |
+
/**
|
| 339 |
+
* This is a single line in the response `.jsonl` file and does not represent the
|
| 340 |
+
* response as a whole.
|
| 341 |
+
*/
|
| 342 |
+
export interface BetaMessageBatchIndividualResponse {
|
| 343 |
+
/**
|
| 344 |
+
* Developer-provided ID created for each request in a Message Batch. Useful for
|
| 345 |
+
* matching results to requests, as results may be given out of request order.
|
| 346 |
+
*
|
| 347 |
+
* Must be unique for each request within the Message Batch.
|
| 348 |
+
*/
|
| 349 |
+
custom_id: string;
|
| 350 |
+
|
| 351 |
+
/**
|
| 352 |
+
* Processing result for this request.
|
| 353 |
+
*
|
| 354 |
+
* Contains a Message output if processing was successful, an error response if
|
| 355 |
+
* processing failed, or the reason why processing was not attempted, such as
|
| 356 |
+
* cancellation or expiration.
|
| 357 |
+
*/
|
| 358 |
+
result: BetaMessageBatchResult;
|
| 359 |
+
}
|
| 360 |
+
|
| 361 |
+
export interface BetaMessageBatchRequestCounts {
|
| 362 |
+
/**
|
| 363 |
+
* Number of requests in the Message Batch that have been canceled.
|
| 364 |
+
*
|
| 365 |
+
* This is zero until processing of the entire Message Batch has ended.
|
| 366 |
+
*/
|
| 367 |
+
canceled: number;
|
| 368 |
+
|
| 369 |
+
/**
|
| 370 |
+
* Number of requests in the Message Batch that encountered an error.
|
| 371 |
+
*
|
| 372 |
+
* This is zero until processing of the entire Message Batch has ended.
|
| 373 |
+
*/
|
| 374 |
+
errored: number;
|
| 375 |
+
|
| 376 |
+
/**
|
| 377 |
+
* Number of requests in the Message Batch that have expired.
|
| 378 |
+
*
|
| 379 |
+
* This is zero until processing of the entire Message Batch has ended.
|
| 380 |
+
*/
|
| 381 |
+
expired: number;
|
| 382 |
+
|
| 383 |
+
/**
|
| 384 |
+
* Number of requests in the Message Batch that are processing.
|
| 385 |
+
*/
|
| 386 |
+
processing: number;
|
| 387 |
+
|
| 388 |
+
/**
|
| 389 |
+
* Number of requests in the Message Batch that have completed successfully.
|
| 390 |
+
*
|
| 391 |
+
* This is zero until processing of the entire Message Batch has ended.
|
| 392 |
+
*/
|
| 393 |
+
succeeded: number;
|
| 394 |
+
}
|
| 395 |
+
|
| 396 |
+
/**
|
| 397 |
+
* Processing result for this request.
|
| 398 |
+
*
|
| 399 |
+
* Contains a Message output if processing was successful, an error response if
|
| 400 |
+
* processing failed, or the reason why processing was not attempted, such as
|
| 401 |
+
* cancellation or expiration.
|
| 402 |
+
*/
|
| 403 |
+
export type BetaMessageBatchResult =
|
| 404 |
+
| BetaMessageBatchSucceededResult
|
| 405 |
+
| BetaMessageBatchErroredResult
|
| 406 |
+
| BetaMessageBatchCanceledResult
|
| 407 |
+
| BetaMessageBatchExpiredResult;
|
| 408 |
+
|
| 409 |
+
export interface BetaMessageBatchSucceededResult {
|
| 410 |
+
message: BetaMessagesAPI.BetaMessage;
|
| 411 |
+
|
| 412 |
+
type: 'succeeded';
|
| 413 |
+
}
|
| 414 |
+
|
| 415 |
+
export interface BatchCreateParams {
|
| 416 |
+
/**
|
| 417 |
+
* Body param: List of requests for prompt completion. Each is an individual
|
| 418 |
+
* request to create a Message.
|
| 419 |
+
*/
|
| 420 |
+
requests: Array<BatchCreateParams.Request>;
|
| 421 |
+
|
| 422 |
+
/**
|
| 423 |
+
* Header param: Optional header to specify the beta version(s) you want to use.
|
| 424 |
+
*/
|
| 425 |
+
betas?: Array<BetaAPI.AnthropicBeta>;
|
| 426 |
+
}
|
| 427 |
+
|
| 428 |
+
export namespace BatchCreateParams {
|
| 429 |
+
export interface Request {
|
| 430 |
+
/**
|
| 431 |
+
* Developer-provided ID created for each request in a Message Batch. Useful for
|
| 432 |
+
* matching results to requests, as results may be given out of request order.
|
| 433 |
+
*
|
| 434 |
+
* Must be unique for each request within the Message Batch.
|
| 435 |
+
*/
|
| 436 |
+
custom_id: string;
|
| 437 |
+
|
| 438 |
+
/**
|
| 439 |
+
* Messages API creation parameters for the individual request.
|
| 440 |
+
*
|
| 441 |
+
* See the [Messages API reference](/en/api/messages) for full documentation on
|
| 442 |
+
* available parameters.
|
| 443 |
+
*/
|
| 444 |
+
params: Omit<BetaMessagesAPI.MessageCreateParamsNonStreaming, 'betas'>;
|
| 445 |
+
}
|
| 446 |
+
}
|
| 447 |
+
|
| 448 |
+
export interface BatchRetrieveParams {
|
| 449 |
+
/**
|
| 450 |
+
* Optional header to specify the beta version(s) you want to use.
|
| 451 |
+
*/
|
| 452 |
+
betas?: Array<BetaAPI.AnthropicBeta>;
|
| 453 |
+
}
|
| 454 |
+
|
| 455 |
+
export interface BatchListParams extends PageParams {
|
| 456 |
+
/**
|
| 457 |
+
* Header param: Optional header to specify the beta version(s) you want to use.
|
| 458 |
+
*/
|
| 459 |
+
betas?: Array<BetaAPI.AnthropicBeta>;
|
| 460 |
+
}
|
| 461 |
+
|
| 462 |
+
export interface BatchDeleteParams {
|
| 463 |
+
/**
|
| 464 |
+
* Optional header to specify the beta version(s) you want to use.
|
| 465 |
+
*/
|
| 466 |
+
betas?: Array<BetaAPI.AnthropicBeta>;
|
| 467 |
+
}
|
| 468 |
+
|
| 469 |
+
export interface BatchCancelParams {
|
| 470 |
+
/**
|
| 471 |
+
* Optional header to specify the beta version(s) you want to use.
|
| 472 |
+
*/
|
| 473 |
+
betas?: Array<BetaAPI.AnthropicBeta>;
|
| 474 |
+
}
|
| 475 |
+
|
| 476 |
+
export interface BatchResultsParams {
|
| 477 |
+
/**
|
| 478 |
+
* Optional header to specify the beta version(s) you want to use.
|
| 479 |
+
*/
|
| 480 |
+
betas?: Array<BetaAPI.AnthropicBeta>;
|
| 481 |
+
}
|
| 482 |
+
|
| 483 |
+
export declare namespace Batches {
|
| 484 |
+
export {
|
| 485 |
+
type BetaDeletedMessageBatch as BetaDeletedMessageBatch,
|
| 486 |
+
type BetaMessageBatch as BetaMessageBatch,
|
| 487 |
+
type BetaMessageBatchCanceledResult as BetaMessageBatchCanceledResult,
|
| 488 |
+
type BetaMessageBatchErroredResult as BetaMessageBatchErroredResult,
|
| 489 |
+
type BetaMessageBatchExpiredResult as BetaMessageBatchExpiredResult,
|
| 490 |
+
type BetaMessageBatchIndividualResponse as BetaMessageBatchIndividualResponse,
|
| 491 |
+
type BetaMessageBatchRequestCounts as BetaMessageBatchRequestCounts,
|
| 492 |
+
type BetaMessageBatchResult as BetaMessageBatchResult,
|
| 493 |
+
type BetaMessageBatchSucceededResult as BetaMessageBatchSucceededResult,
|
| 494 |
+
type BetaMessageBatchesPage as BetaMessageBatchesPage,
|
| 495 |
+
type BatchCreateParams as BatchCreateParams,
|
| 496 |
+
type BatchRetrieveParams as BatchRetrieveParams,
|
| 497 |
+
type BatchListParams as BatchListParams,
|
| 498 |
+
type BatchDeleteParams as BatchDeleteParams,
|
| 499 |
+
type BatchCancelParams as BatchCancelParams,
|
| 500 |
+
type BatchResultsParams as BatchResultsParams,
|
| 501 |
+
};
|
| 502 |
+
}
|
node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/resources/beta/messages/index.ts
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
| 2 |
+
|
| 3 |
+
export {
|
| 4 |
+
Batches,
|
| 5 |
+
type BetaDeletedMessageBatch,
|
| 6 |
+
type BetaMessageBatch,
|
| 7 |
+
type BetaMessageBatchCanceledResult,
|
| 8 |
+
type BetaMessageBatchErroredResult,
|
| 9 |
+
type BetaMessageBatchExpiredResult,
|
| 10 |
+
type BetaMessageBatchIndividualResponse,
|
| 11 |
+
type BetaMessageBatchRequestCounts,
|
| 12 |
+
type BetaMessageBatchResult,
|
| 13 |
+
type BetaMessageBatchSucceededResult,
|
| 14 |
+
type BatchCreateParams,
|
| 15 |
+
type BatchRetrieveParams,
|
| 16 |
+
type BatchListParams,
|
| 17 |
+
type BatchDeleteParams,
|
| 18 |
+
type BatchCancelParams,
|
| 19 |
+
type BatchResultsParams,
|
| 20 |
+
type BetaMessageBatchesPage,
|
| 21 |
+
} from './batches';
|
| 22 |
+
export {
|
| 23 |
+
Messages,
|
| 24 |
+
type BetaBase64ImageSource,
|
| 25 |
+
type BetaBase64PDFSource,
|
| 26 |
+
type BetaCacheControlEphemeral,
|
| 27 |
+
type BetaCacheCreation,
|
| 28 |
+
type BetaCitationCharLocation,
|
| 29 |
+
type BetaCitationCharLocationParam,
|
| 30 |
+
type BetaCitationContentBlockLocation,
|
| 31 |
+
type BetaCitationContentBlockLocationParam,
|
| 32 |
+
type BetaCitationPageLocation,
|
| 33 |
+
type BetaCitationPageLocationParam,
|
| 34 |
+
type BetaCitationSearchResultLocation,
|
| 35 |
+
type BetaCitationSearchResultLocationParam,
|
| 36 |
+
type BetaCitationWebSearchResultLocationParam,
|
| 37 |
+
type BetaCitationsConfigParam,
|
| 38 |
+
type BetaCitationsDelta,
|
| 39 |
+
type BetaCitationsWebSearchResultLocation,
|
| 40 |
+
type BetaCodeExecutionOutputBlock,
|
| 41 |
+
type BetaCodeExecutionOutputBlockParam,
|
| 42 |
+
type BetaCodeExecutionResultBlock,
|
| 43 |
+
type BetaCodeExecutionResultBlockParam,
|
| 44 |
+
type BetaCodeExecutionTool20250522,
|
| 45 |
+
type BetaCodeExecutionToolResultBlock,
|
| 46 |
+
type BetaCodeExecutionToolResultBlockContent,
|
| 47 |
+
type BetaCodeExecutionToolResultBlockParam,
|
| 48 |
+
type BetaCodeExecutionToolResultBlockParamContent,
|
| 49 |
+
type BetaCodeExecutionToolResultError,
|
| 50 |
+
type BetaCodeExecutionToolResultErrorCode,
|
| 51 |
+
type BetaCodeExecutionToolResultErrorParam,
|
| 52 |
+
type BetaContainer,
|
| 53 |
+
type BetaContainerUploadBlock,
|
| 54 |
+
type BetaContainerUploadBlockParam,
|
| 55 |
+
type BetaContentBlock,
|
| 56 |
+
type BetaContentBlockParam,
|
| 57 |
+
type BetaContentBlockSource,
|
| 58 |
+
type BetaContentBlockSourceContent,
|
| 59 |
+
type BetaFileDocumentSource,
|
| 60 |
+
type BetaFileImageSource,
|
| 61 |
+
type BetaImageBlockParam,
|
| 62 |
+
type BetaInputJSONDelta,
|
| 63 |
+
type BetaMCPToolResultBlock,
|
| 64 |
+
type BetaMCPToolUseBlock,
|
| 65 |
+
type BetaMCPToolUseBlockParam,
|
| 66 |
+
type BetaMessage,
|
| 67 |
+
type BetaMessageDeltaUsage,
|
| 68 |
+
type BetaMessageParam,
|
| 69 |
+
type BetaMessageTokensCount,
|
| 70 |
+
type BetaMetadata,
|
| 71 |
+
type BetaPlainTextSource,
|
| 72 |
+
type BetaRawContentBlockDelta,
|
| 73 |
+
type BetaRawContentBlockDeltaEvent,
|
| 74 |
+
type BetaRawContentBlockStartEvent,
|
| 75 |
+
type BetaRawContentBlockStopEvent,
|
| 76 |
+
type BetaRawMessageDeltaEvent,
|
| 77 |
+
type BetaRawMessageStartEvent,
|
| 78 |
+
type BetaRawMessageStopEvent,
|
| 79 |
+
type BetaRawMessageStreamEvent,
|
| 80 |
+
type BetaRedactedThinkingBlock,
|
| 81 |
+
type BetaRedactedThinkingBlockParam,
|
| 82 |
+
type BetaRequestDocumentBlock,
|
| 83 |
+
type BetaRequestMCPServerToolConfiguration,
|
| 84 |
+
type BetaRequestMCPServerURLDefinition,
|
| 85 |
+
type BetaRequestMCPToolResultBlockParam,
|
| 86 |
+
type BetaSearchResultBlockParam,
|
| 87 |
+
type BetaServerToolUsage,
|
| 88 |
+
type BetaServerToolUseBlock,
|
| 89 |
+
type BetaServerToolUseBlockParam,
|
| 90 |
+
type BetaSignatureDelta,
|
| 91 |
+
type BetaStopReason,
|
| 92 |
+
type BetaTextBlock,
|
| 93 |
+
type BetaTextBlockParam,
|
| 94 |
+
type BetaTextCitation,
|
| 95 |
+
type BetaTextCitationParam,
|
| 96 |
+
type BetaTextDelta,
|
| 97 |
+
type BetaThinkingBlock,
|
| 98 |
+
type BetaThinkingBlockParam,
|
| 99 |
+
type BetaThinkingConfigDisabled,
|
| 100 |
+
type BetaThinkingConfigEnabled,
|
| 101 |
+
type BetaThinkingConfigParam,
|
| 102 |
+
type BetaThinkingDelta,
|
| 103 |
+
type BetaTool,
|
| 104 |
+
type BetaToolBash20241022,
|
| 105 |
+
type BetaToolBash20250124,
|
| 106 |
+
type BetaToolChoice,
|
| 107 |
+
type BetaToolChoiceAny,
|
| 108 |
+
type BetaToolChoiceAuto,
|
| 109 |
+
type BetaToolChoiceNone,
|
| 110 |
+
type BetaToolChoiceTool,
|
| 111 |
+
type BetaToolComputerUse20241022,
|
| 112 |
+
type BetaToolComputerUse20250124,
|
| 113 |
+
type BetaToolResultBlockParam,
|
| 114 |
+
type BetaToolTextEditor20241022,
|
| 115 |
+
type BetaToolTextEditor20250124,
|
| 116 |
+
type BetaToolTextEditor20250429,
|
| 117 |
+
type BetaToolUnion,
|
| 118 |
+
type BetaToolUseBlock,
|
| 119 |
+
type BetaToolUseBlockParam,
|
| 120 |
+
type BetaURLImageSource,
|
| 121 |
+
type BetaURLPDFSource,
|
| 122 |
+
type BetaUsage,
|
| 123 |
+
type BetaWebSearchResultBlock,
|
| 124 |
+
type BetaWebSearchResultBlockParam,
|
| 125 |
+
type BetaWebSearchTool20250305,
|
| 126 |
+
type BetaWebSearchToolRequestError,
|
| 127 |
+
type BetaWebSearchToolResultBlock,
|
| 128 |
+
type BetaWebSearchToolResultBlockContent,
|
| 129 |
+
type BetaWebSearchToolResultBlockParam,
|
| 130 |
+
type BetaWebSearchToolResultBlockParamContent,
|
| 131 |
+
type BetaWebSearchToolResultError,
|
| 132 |
+
type BetaWebSearchToolResultErrorCode,
|
| 133 |
+
type BetaBase64PDFBlock,
|
| 134 |
+
type MessageCreateParams,
|
| 135 |
+
type MessageCreateParamsNonStreaming,
|
| 136 |
+
type MessageCreateParamsStreaming,
|
| 137 |
+
type MessageCountTokensParams,
|
| 138 |
+
type BetaMessageStreamParams,
|
| 139 |
+
} from './messages';
|
node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/resources/beta/messages/messages.ts
ADDED
|
@@ -0,0 +1,2330 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
| 2 |
+
|
| 3 |
+
import { APIResource } from '../../../core/resource';
|
| 4 |
+
import * as MessagesMessagesAPI from './messages';
|
| 5 |
+
import * as BetaAPI from '../beta';
|
| 6 |
+
import * as MessagesAPI from '../../messages/messages';
|
| 7 |
+
import * as BatchesAPI from './batches';
|
| 8 |
+
import {
|
| 9 |
+
BatchCancelParams,
|
| 10 |
+
BatchCreateParams,
|
| 11 |
+
BatchDeleteParams,
|
| 12 |
+
BatchListParams,
|
| 13 |
+
BatchResultsParams,
|
| 14 |
+
BatchRetrieveParams,
|
| 15 |
+
Batches,
|
| 16 |
+
BetaDeletedMessageBatch,
|
| 17 |
+
BetaMessageBatch,
|
| 18 |
+
BetaMessageBatchCanceledResult,
|
| 19 |
+
BetaMessageBatchErroredResult,
|
| 20 |
+
BetaMessageBatchExpiredResult,
|
| 21 |
+
BetaMessageBatchIndividualResponse,
|
| 22 |
+
BetaMessageBatchRequestCounts,
|
| 23 |
+
BetaMessageBatchResult,
|
| 24 |
+
BetaMessageBatchSucceededResult,
|
| 25 |
+
BetaMessageBatchesPage,
|
| 26 |
+
} from './batches';
|
| 27 |
+
import { APIPromise } from '../../../core/api-promise';
|
| 28 |
+
import { Stream } from '../../../core/streaming';
|
| 29 |
+
import { buildHeaders } from '../../../internal/headers';
|
| 30 |
+
import { RequestOptions } from '../../../internal/request-options';
|
| 31 |
+
import type { Model } from '../../messages/messages';
|
| 32 |
+
import { BetaMessageStream } from '../../../lib/BetaMessageStream';
|
| 33 |
+
|
| 34 |
+
const DEPRECATED_MODELS: {
|
| 35 |
+
[K in Model]?: string;
|
| 36 |
+
} = {
|
| 37 |
+
'claude-1.3': 'November 6th, 2024',
|
| 38 |
+
'claude-1.3-100k': 'November 6th, 2024',
|
| 39 |
+
'claude-instant-1.1': 'November 6th, 2024',
|
| 40 |
+
'claude-instant-1.1-100k': 'November 6th, 2024',
|
| 41 |
+
'claude-instant-1.2': 'November 6th, 2024',
|
| 42 |
+
'claude-3-sonnet-20240229': 'July 21st, 2025',
|
| 43 |
+
'claude-3-opus-20240229': 'January 5th, 2026',
|
| 44 |
+
'claude-2.1': 'July 21st, 2025',
|
| 45 |
+
'claude-2.0': 'July 21st, 2025',
|
| 46 |
+
};
|
| 47 |
+
import { MODEL_NONSTREAMING_TOKENS } from '../../../internal/constants';
|
| 48 |
+
|
| 49 |
+
export class Messages extends APIResource {
|
| 50 |
+
batches: BatchesAPI.Batches = new BatchesAPI.Batches(this._client);
|
| 51 |
+
|
| 52 |
+
/**
|
| 53 |
+
* Send a structured list of input messages with text and/or image content, and the
|
| 54 |
+
* model will generate the next message in the conversation.
|
| 55 |
+
*
|
| 56 |
+
* The Messages API can be used for either single queries or stateless multi-turn
|
| 57 |
+
* conversations.
|
| 58 |
+
*
|
| 59 |
+
* Learn more about the Messages API in our [user guide](/en/docs/initial-setup)
|
| 60 |
+
*
|
| 61 |
+
* @example
|
| 62 |
+
* ```ts
|
| 63 |
+
* const betaMessage = await client.beta.messages.create({
|
| 64 |
+
* max_tokens: 1024,
|
| 65 |
+
* messages: [{ content: 'Hello, world', role: 'user' }],
|
| 66 |
+
* model: 'claude-sonnet-4-20250514',
|
| 67 |
+
* });
|
| 68 |
+
* ```
|
| 69 |
+
*/
|
| 70 |
+
create(params: MessageCreateParamsNonStreaming, options?: RequestOptions): APIPromise<BetaMessage>;
|
| 71 |
+
create(
|
| 72 |
+
params: MessageCreateParamsStreaming,
|
| 73 |
+
options?: RequestOptions,
|
| 74 |
+
): APIPromise<Stream<BetaRawMessageStreamEvent>>;
|
| 75 |
+
create(
|
| 76 |
+
params: MessageCreateParamsBase,
|
| 77 |
+
options?: RequestOptions,
|
| 78 |
+
): APIPromise<Stream<BetaRawMessageStreamEvent> | BetaMessage>;
|
| 79 |
+
create(
|
| 80 |
+
params: MessageCreateParams,
|
| 81 |
+
options?: RequestOptions,
|
| 82 |
+
): APIPromise<BetaMessage> | APIPromise<Stream<BetaRawMessageStreamEvent>> {
|
| 83 |
+
const { betas, ...body } = params;
|
| 84 |
+
|
| 85 |
+
if (body.model in DEPRECATED_MODELS) {
|
| 86 |
+
console.warn(
|
| 87 |
+
`The model '${body.model}' is deprecated and will reach end-of-life on ${
|
| 88 |
+
DEPRECATED_MODELS[body.model]
|
| 89 |
+
}\nPlease migrate to a newer model. Visit https://docs.anthropic.com/en/docs/resources/model-deprecations for more information.`,
|
| 90 |
+
);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
let timeout = (this._client as any)._options.timeout as number | null;
|
| 94 |
+
if (!body.stream && timeout == null) {
|
| 95 |
+
const maxNonstreamingTokens = MODEL_NONSTREAMING_TOKENS[body.model] ?? undefined;
|
| 96 |
+
timeout = this._client.calculateNonstreamingTimeout(body.max_tokens, maxNonstreamingTokens);
|
| 97 |
+
}
|
| 98 |
+
return this._client.post('/v1/messages?beta=true', {
|
| 99 |
+
body,
|
| 100 |
+
timeout: timeout ?? 600000,
|
| 101 |
+
...options,
|
| 102 |
+
headers: buildHeaders([
|
| 103 |
+
{ ...(betas?.toString() != null ? { 'anthropic-beta': betas?.toString() } : undefined) },
|
| 104 |
+
options?.headers,
|
| 105 |
+
]),
|
| 106 |
+
stream: params.stream ?? false,
|
| 107 |
+
}) as APIPromise<BetaMessage> | APIPromise<Stream<BetaRawMessageStreamEvent>>;
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
/**
|
| 111 |
+
* Create a Message stream
|
| 112 |
+
*/
|
| 113 |
+
stream(body: BetaMessageStreamParams, options?: RequestOptions): BetaMessageStream {
|
| 114 |
+
return BetaMessageStream.createMessage(this, body, options);
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
/**
|
| 118 |
+
* Count the number of tokens in a Message.
|
| 119 |
+
*
|
| 120 |
+
* The Token Count API can be used to count the number of tokens in a Message,
|
| 121 |
+
* including tools, images, and documents, without creating it.
|
| 122 |
+
*
|
| 123 |
+
* Learn more about token counting in our
|
| 124 |
+
* [user guide](/en/docs/build-with-claude/token-counting)
|
| 125 |
+
*
|
| 126 |
+
* @example
|
| 127 |
+
* ```ts
|
| 128 |
+
* const betaMessageTokensCount =
|
| 129 |
+
* await client.beta.messages.countTokens({
|
| 130 |
+
* messages: [{ content: 'string', role: 'user' }],
|
| 131 |
+
* model: 'claude-3-7-sonnet-latest',
|
| 132 |
+
* });
|
| 133 |
+
* ```
|
| 134 |
+
*/
|
| 135 |
+
countTokens(
|
| 136 |
+
params: MessageCountTokensParams,
|
| 137 |
+
options?: RequestOptions,
|
| 138 |
+
): APIPromise<BetaMessageTokensCount> {
|
| 139 |
+
const { betas, ...body } = params;
|
| 140 |
+
return this._client.post('/v1/messages/count_tokens?beta=true', {
|
| 141 |
+
body,
|
| 142 |
+
...options,
|
| 143 |
+
headers: buildHeaders([
|
| 144 |
+
{ 'anthropic-beta': [...(betas ?? []), 'token-counting-2024-11-01'].toString() },
|
| 145 |
+
options?.headers,
|
| 146 |
+
]),
|
| 147 |
+
});
|
| 148 |
+
}
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
export type BetaMessageStreamParams = MessageCreateParamsBase;
|
| 152 |
+
|
| 153 |
+
export interface BetaBase64ImageSource {
|
| 154 |
+
data: string;
|
| 155 |
+
|
| 156 |
+
media_type: 'image/jpeg' | 'image/png' | 'image/gif' | 'image/webp';
|
| 157 |
+
|
| 158 |
+
type: 'base64';
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
export interface BetaBase64PDFSource {
|
| 162 |
+
data: string;
|
| 163 |
+
|
| 164 |
+
media_type: 'application/pdf';
|
| 165 |
+
|
| 166 |
+
type: 'base64';
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
export interface BetaCacheControlEphemeral {
|
| 170 |
+
type: 'ephemeral';
|
| 171 |
+
|
| 172 |
+
/**
|
| 173 |
+
* The time-to-live for the cache control breakpoint.
|
| 174 |
+
*
|
| 175 |
+
* This may be one the following values:
|
| 176 |
+
*
|
| 177 |
+
* - `5m`: 5 minutes
|
| 178 |
+
* - `1h`: 1 hour
|
| 179 |
+
*
|
| 180 |
+
* Defaults to `5m`.
|
| 181 |
+
*/
|
| 182 |
+
ttl?: '5m' | '1h';
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
export interface BetaCacheCreation {
|
| 186 |
+
/**
|
| 187 |
+
* The number of input tokens used to create the 1 hour cache entry.
|
| 188 |
+
*/
|
| 189 |
+
ephemeral_1h_input_tokens: number;
|
| 190 |
+
|
| 191 |
+
/**
|
| 192 |
+
* The number of input tokens used to create the 5 minute cache entry.
|
| 193 |
+
*/
|
| 194 |
+
ephemeral_5m_input_tokens: number;
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
export interface BetaCitationCharLocation {
|
| 198 |
+
cited_text: string;
|
| 199 |
+
|
| 200 |
+
document_index: number;
|
| 201 |
+
|
| 202 |
+
document_title: string | null;
|
| 203 |
+
|
| 204 |
+
end_char_index: number;
|
| 205 |
+
|
| 206 |
+
start_char_index: number;
|
| 207 |
+
|
| 208 |
+
type: 'char_location';
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
export interface BetaCitationCharLocationParam {
|
| 212 |
+
cited_text: string;
|
| 213 |
+
|
| 214 |
+
document_index: number;
|
| 215 |
+
|
| 216 |
+
document_title: string | null;
|
| 217 |
+
|
| 218 |
+
end_char_index: number;
|
| 219 |
+
|
| 220 |
+
start_char_index: number;
|
| 221 |
+
|
| 222 |
+
type: 'char_location';
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
export interface BetaCitationContentBlockLocation {
|
| 226 |
+
cited_text: string;
|
| 227 |
+
|
| 228 |
+
document_index: number;
|
| 229 |
+
|
| 230 |
+
document_title: string | null;
|
| 231 |
+
|
| 232 |
+
end_block_index: number;
|
| 233 |
+
|
| 234 |
+
start_block_index: number;
|
| 235 |
+
|
| 236 |
+
type: 'content_block_location';
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
export interface BetaCitationContentBlockLocationParam {
|
| 240 |
+
cited_text: string;
|
| 241 |
+
|
| 242 |
+
document_index: number;
|
| 243 |
+
|
| 244 |
+
document_title: string | null;
|
| 245 |
+
|
| 246 |
+
end_block_index: number;
|
| 247 |
+
|
| 248 |
+
start_block_index: number;
|
| 249 |
+
|
| 250 |
+
type: 'content_block_location';
|
| 251 |
+
}
|
| 252 |
+
|
| 253 |
+
export interface BetaCitationPageLocation {
|
| 254 |
+
cited_text: string;
|
| 255 |
+
|
| 256 |
+
document_index: number;
|
| 257 |
+
|
| 258 |
+
document_title: string | null;
|
| 259 |
+
|
| 260 |
+
end_page_number: number;
|
| 261 |
+
|
| 262 |
+
start_page_number: number;
|
| 263 |
+
|
| 264 |
+
type: 'page_location';
|
| 265 |
+
}
|
| 266 |
+
|
| 267 |
+
export interface BetaCitationPageLocationParam {
|
| 268 |
+
cited_text: string;
|
| 269 |
+
|
| 270 |
+
document_index: number;
|
| 271 |
+
|
| 272 |
+
document_title: string | null;
|
| 273 |
+
|
| 274 |
+
end_page_number: number;
|
| 275 |
+
|
| 276 |
+
start_page_number: number;
|
| 277 |
+
|
| 278 |
+
type: 'page_location';
|
| 279 |
+
}
|
| 280 |
+
|
| 281 |
+
export interface BetaCitationSearchResultLocation {
|
| 282 |
+
cited_text: string;
|
| 283 |
+
|
| 284 |
+
end_block_index: number;
|
| 285 |
+
|
| 286 |
+
search_result_index: number;
|
| 287 |
+
|
| 288 |
+
source: string;
|
| 289 |
+
|
| 290 |
+
start_block_index: number;
|
| 291 |
+
|
| 292 |
+
title: string | null;
|
| 293 |
+
|
| 294 |
+
type: 'search_result_location';
|
| 295 |
+
}
|
| 296 |
+
|
| 297 |
+
export interface BetaCitationSearchResultLocationParam {
|
| 298 |
+
cited_text: string;
|
| 299 |
+
|
| 300 |
+
end_block_index: number;
|
| 301 |
+
|
| 302 |
+
search_result_index: number;
|
| 303 |
+
|
| 304 |
+
source: string;
|
| 305 |
+
|
| 306 |
+
start_block_index: number;
|
| 307 |
+
|
| 308 |
+
title: string | null;
|
| 309 |
+
|
| 310 |
+
type: 'search_result_location';
|
| 311 |
+
}
|
| 312 |
+
|
| 313 |
+
export interface BetaCitationWebSearchResultLocationParam {
|
| 314 |
+
cited_text: string;
|
| 315 |
+
|
| 316 |
+
encrypted_index: string;
|
| 317 |
+
|
| 318 |
+
title: string | null;
|
| 319 |
+
|
| 320 |
+
type: 'web_search_result_location';
|
| 321 |
+
|
| 322 |
+
url: string;
|
| 323 |
+
}
|
| 324 |
+
|
| 325 |
+
export interface BetaCitationsConfigParam {
|
| 326 |
+
enabled?: boolean;
|
| 327 |
+
}
|
| 328 |
+
|
| 329 |
+
export interface BetaCitationsDelta {
|
| 330 |
+
citation:
|
| 331 |
+
| BetaCitationCharLocation
|
| 332 |
+
| BetaCitationPageLocation
|
| 333 |
+
| BetaCitationContentBlockLocation
|
| 334 |
+
| BetaCitationsWebSearchResultLocation
|
| 335 |
+
| BetaCitationSearchResultLocation;
|
| 336 |
+
|
| 337 |
+
type: 'citations_delta';
|
| 338 |
+
}
|
| 339 |
+
|
| 340 |
+
export interface BetaCitationsWebSearchResultLocation {
|
| 341 |
+
cited_text: string;
|
| 342 |
+
|
| 343 |
+
encrypted_index: string;
|
| 344 |
+
|
| 345 |
+
title: string | null;
|
| 346 |
+
|
| 347 |
+
type: 'web_search_result_location';
|
| 348 |
+
|
| 349 |
+
url: string;
|
| 350 |
+
}
|
| 351 |
+
|
| 352 |
+
export interface BetaCodeExecutionOutputBlock {
|
| 353 |
+
file_id: string;
|
| 354 |
+
|
| 355 |
+
type: 'code_execution_output';
|
| 356 |
+
}
|
| 357 |
+
|
| 358 |
+
export interface BetaCodeExecutionOutputBlockParam {
|
| 359 |
+
file_id: string;
|
| 360 |
+
|
| 361 |
+
type: 'code_execution_output';
|
| 362 |
+
}
|
| 363 |
+
|
| 364 |
+
export interface BetaCodeExecutionResultBlock {
|
| 365 |
+
content: Array<BetaCodeExecutionOutputBlock>;
|
| 366 |
+
|
| 367 |
+
return_code: number;
|
| 368 |
+
|
| 369 |
+
stderr: string;
|
| 370 |
+
|
| 371 |
+
stdout: string;
|
| 372 |
+
|
| 373 |
+
type: 'code_execution_result';
|
| 374 |
+
}
|
| 375 |
+
|
| 376 |
+
export interface BetaCodeExecutionResultBlockParam {
|
| 377 |
+
content: Array<BetaCodeExecutionOutputBlockParam>;
|
| 378 |
+
|
| 379 |
+
return_code: number;
|
| 380 |
+
|
| 381 |
+
stderr: string;
|
| 382 |
+
|
| 383 |
+
stdout: string;
|
| 384 |
+
|
| 385 |
+
type: 'code_execution_result';
|
| 386 |
+
}
|
| 387 |
+
|
| 388 |
+
export interface BetaCodeExecutionTool20250522 {
|
| 389 |
+
/**
|
| 390 |
+
* Name of the tool.
|
| 391 |
+
*
|
| 392 |
+
* This is how the tool will be called by the model and in `tool_use` blocks.
|
| 393 |
+
*/
|
| 394 |
+
name: 'code_execution';
|
| 395 |
+
|
| 396 |
+
type: 'code_execution_20250522';
|
| 397 |
+
|
| 398 |
+
/**
|
| 399 |
+
* Create a cache control breakpoint at this content block.
|
| 400 |
+
*/
|
| 401 |
+
cache_control?: BetaCacheControlEphemeral | null;
|
| 402 |
+
}
|
| 403 |
+
|
| 404 |
+
export interface BetaCodeExecutionToolResultBlock {
|
| 405 |
+
content: BetaCodeExecutionToolResultBlockContent;
|
| 406 |
+
|
| 407 |
+
tool_use_id: string;
|
| 408 |
+
|
| 409 |
+
type: 'code_execution_tool_result';
|
| 410 |
+
}
|
| 411 |
+
|
| 412 |
+
export type BetaCodeExecutionToolResultBlockContent =
|
| 413 |
+
| BetaCodeExecutionToolResultError
|
| 414 |
+
| BetaCodeExecutionResultBlock;
|
| 415 |
+
|
| 416 |
+
export interface BetaCodeExecutionToolResultBlockParam {
|
| 417 |
+
content: BetaCodeExecutionToolResultBlockParamContent;
|
| 418 |
+
|
| 419 |
+
tool_use_id: string;
|
| 420 |
+
|
| 421 |
+
type: 'code_execution_tool_result';
|
| 422 |
+
|
| 423 |
+
/**
|
| 424 |
+
* Create a cache control breakpoint at this content block.
|
| 425 |
+
*/
|
| 426 |
+
cache_control?: BetaCacheControlEphemeral | null;
|
| 427 |
+
}
|
| 428 |
+
|
| 429 |
+
export type BetaCodeExecutionToolResultBlockParamContent =
|
| 430 |
+
| BetaCodeExecutionToolResultErrorParam
|
| 431 |
+
| BetaCodeExecutionResultBlockParam;
|
| 432 |
+
|
| 433 |
+
export interface BetaCodeExecutionToolResultError {
|
| 434 |
+
error_code: BetaCodeExecutionToolResultErrorCode;
|
| 435 |
+
|
| 436 |
+
type: 'code_execution_tool_result_error';
|
| 437 |
+
}
|
| 438 |
+
|
| 439 |
+
export type BetaCodeExecutionToolResultErrorCode =
|
| 440 |
+
| 'invalid_tool_input'
|
| 441 |
+
| 'unavailable'
|
| 442 |
+
| 'too_many_requests'
|
| 443 |
+
| 'execution_time_exceeded';
|
| 444 |
+
|
| 445 |
+
export interface BetaCodeExecutionToolResultErrorParam {
|
| 446 |
+
error_code: BetaCodeExecutionToolResultErrorCode;
|
| 447 |
+
|
| 448 |
+
type: 'code_execution_tool_result_error';
|
| 449 |
+
}
|
| 450 |
+
|
| 451 |
+
/**
|
| 452 |
+
* Information about the container used in the request (for the code execution
|
| 453 |
+
* tool)
|
| 454 |
+
*/
|
| 455 |
+
export interface BetaContainer {
|
| 456 |
+
/**
|
| 457 |
+
* Identifier for the container used in this request
|
| 458 |
+
*/
|
| 459 |
+
id: string;
|
| 460 |
+
|
| 461 |
+
/**
|
| 462 |
+
* The time at which the container will expire.
|
| 463 |
+
*/
|
| 464 |
+
expires_at: string;
|
| 465 |
+
}
|
| 466 |
+
|
| 467 |
+
/**
|
| 468 |
+
* Response model for a file uploaded to the container.
|
| 469 |
+
*/
|
| 470 |
+
export interface BetaContainerUploadBlock {
|
| 471 |
+
file_id: string;
|
| 472 |
+
|
| 473 |
+
type: 'container_upload';
|
| 474 |
+
}
|
| 475 |
+
|
| 476 |
+
/**
|
| 477 |
+
* A content block that represents a file to be uploaded to the container Files
|
| 478 |
+
* uploaded via this block will be available in the container's input directory.
|
| 479 |
+
*/
|
| 480 |
+
export interface BetaContainerUploadBlockParam {
|
| 481 |
+
file_id: string;
|
| 482 |
+
|
| 483 |
+
type: 'container_upload';
|
| 484 |
+
|
| 485 |
+
/**
|
| 486 |
+
* Create a cache control breakpoint at this content block.
|
| 487 |
+
*/
|
| 488 |
+
cache_control?: BetaCacheControlEphemeral | null;
|
| 489 |
+
}
|
| 490 |
+
|
| 491 |
+
/**
|
| 492 |
+
* Response model for a file uploaded to the container.
|
| 493 |
+
*/
|
| 494 |
+
export type BetaContentBlock =
|
| 495 |
+
| BetaTextBlock
|
| 496 |
+
| BetaThinkingBlock
|
| 497 |
+
| BetaRedactedThinkingBlock
|
| 498 |
+
| BetaToolUseBlock
|
| 499 |
+
| BetaServerToolUseBlock
|
| 500 |
+
| BetaWebSearchToolResultBlock
|
| 501 |
+
| BetaCodeExecutionToolResultBlock
|
| 502 |
+
| BetaMCPToolUseBlock
|
| 503 |
+
| BetaMCPToolResultBlock
|
| 504 |
+
| BetaContainerUploadBlock;
|
| 505 |
+
|
| 506 |
+
/**
|
| 507 |
+
* Regular text content.
|
| 508 |
+
*/
|
| 509 |
+
export type BetaContentBlockParam =
|
| 510 |
+
| BetaTextBlockParam
|
| 511 |
+
| BetaImageBlockParam
|
| 512 |
+
| BetaRequestDocumentBlock
|
| 513 |
+
| BetaSearchResultBlockParam
|
| 514 |
+
| BetaThinkingBlockParam
|
| 515 |
+
| BetaRedactedThinkingBlockParam
|
| 516 |
+
| BetaToolUseBlockParam
|
| 517 |
+
| BetaToolResultBlockParam
|
| 518 |
+
| BetaServerToolUseBlockParam
|
| 519 |
+
| BetaWebSearchToolResultBlockParam
|
| 520 |
+
| BetaCodeExecutionToolResultBlockParam
|
| 521 |
+
| BetaMCPToolUseBlockParam
|
| 522 |
+
| BetaRequestMCPToolResultBlockParam
|
| 523 |
+
| BetaContainerUploadBlockParam;
|
| 524 |
+
|
| 525 |
+
export interface BetaContentBlockSource {
|
| 526 |
+
content: string | Array<BetaContentBlockSourceContent>;
|
| 527 |
+
|
| 528 |
+
type: 'content';
|
| 529 |
+
}
|
| 530 |
+
|
| 531 |
+
export type BetaContentBlockSourceContent = BetaTextBlockParam | BetaImageBlockParam;
|
| 532 |
+
|
| 533 |
+
export interface BetaFileDocumentSource {
|
| 534 |
+
file_id: string;
|
| 535 |
+
|
| 536 |
+
type: 'file';
|
| 537 |
+
}
|
| 538 |
+
|
| 539 |
+
export interface BetaFileImageSource {
|
| 540 |
+
file_id: string;
|
| 541 |
+
|
| 542 |
+
type: 'file';
|
| 543 |
+
}
|
| 544 |
+
|
| 545 |
+
export interface BetaImageBlockParam {
|
| 546 |
+
source: BetaBase64ImageSource | BetaURLImageSource | BetaFileImageSource;
|
| 547 |
+
|
| 548 |
+
type: 'image';
|
| 549 |
+
|
| 550 |
+
/**
|
| 551 |
+
* Create a cache control breakpoint at this content block.
|
| 552 |
+
*/
|
| 553 |
+
cache_control?: BetaCacheControlEphemeral | null;
|
| 554 |
+
}
|
| 555 |
+
|
| 556 |
+
export interface BetaInputJSONDelta {
|
| 557 |
+
partial_json: string;
|
| 558 |
+
|
| 559 |
+
type: 'input_json_delta';
|
| 560 |
+
}
|
| 561 |
+
|
| 562 |
+
export interface BetaMCPToolResultBlock {
|
| 563 |
+
content: string | Array<BetaTextBlock>;
|
| 564 |
+
|
| 565 |
+
is_error: boolean;
|
| 566 |
+
|
| 567 |
+
tool_use_id: string;
|
| 568 |
+
|
| 569 |
+
type: 'mcp_tool_result';
|
| 570 |
+
}
|
| 571 |
+
|
| 572 |
+
export interface BetaMCPToolUseBlock {
|
| 573 |
+
id: string;
|
| 574 |
+
|
| 575 |
+
input: unknown;
|
| 576 |
+
|
| 577 |
+
/**
|
| 578 |
+
* The name of the MCP tool
|
| 579 |
+
*/
|
| 580 |
+
name: string;
|
| 581 |
+
|
| 582 |
+
/**
|
| 583 |
+
* The name of the MCP server
|
| 584 |
+
*/
|
| 585 |
+
server_name: string;
|
| 586 |
+
|
| 587 |
+
type: 'mcp_tool_use';
|
| 588 |
+
}
|
| 589 |
+
|
| 590 |
+
export interface BetaMCPToolUseBlockParam {
|
| 591 |
+
id: string;
|
| 592 |
+
|
| 593 |
+
input: unknown;
|
| 594 |
+
|
| 595 |
+
name: string;
|
| 596 |
+
|
| 597 |
+
/**
|
| 598 |
+
* The name of the MCP server
|
| 599 |
+
*/
|
| 600 |
+
server_name: string;
|
| 601 |
+
|
| 602 |
+
type: 'mcp_tool_use';
|
| 603 |
+
|
| 604 |
+
/**
|
| 605 |
+
* Create a cache control breakpoint at this content block.
|
| 606 |
+
*/
|
| 607 |
+
cache_control?: BetaCacheControlEphemeral | null;
|
| 608 |
+
}
|
| 609 |
+
|
| 610 |
+
export interface BetaMessage {
|
| 611 |
+
/**
|
| 612 |
+
* Unique object identifier.
|
| 613 |
+
*
|
| 614 |
+
* The format and length of IDs may change over time.
|
| 615 |
+
*/
|
| 616 |
+
id: string;
|
| 617 |
+
|
| 618 |
+
/**
|
| 619 |
+
* Information about the container used in the request (for the code execution
|
| 620 |
+
* tool)
|
| 621 |
+
*/
|
| 622 |
+
container: BetaContainer | null;
|
| 623 |
+
|
| 624 |
+
/**
|
| 625 |
+
* Content generated by the model.
|
| 626 |
+
*
|
| 627 |
+
* This is an array of content blocks, each of which has a `type` that determines
|
| 628 |
+
* its shape.
|
| 629 |
+
*
|
| 630 |
+
* Example:
|
| 631 |
+
*
|
| 632 |
+
* ```json
|
| 633 |
+
* [{ "type": "text", "text": "Hi, I'm Claude." }]
|
| 634 |
+
* ```
|
| 635 |
+
*
|
| 636 |
+
* If the request input `messages` ended with an `assistant` turn, then the
|
| 637 |
+
* response `content` will continue directly from that last turn. You can use this
|
| 638 |
+
* to constrain the model's output.
|
| 639 |
+
*
|
| 640 |
+
* For example, if the input `messages` were:
|
| 641 |
+
*
|
| 642 |
+
* ```json
|
| 643 |
+
* [
|
| 644 |
+
* {
|
| 645 |
+
* "role": "user",
|
| 646 |
+
* "content": "What's the Greek name for Sun? (A) Sol (B) Helios (C) Sun"
|
| 647 |
+
* },
|
| 648 |
+
* { "role": "assistant", "content": "The best answer is (" }
|
| 649 |
+
* ]
|
| 650 |
+
* ```
|
| 651 |
+
*
|
| 652 |
+
* Then the response `content` might be:
|
| 653 |
+
*
|
| 654 |
+
* ```json
|
| 655 |
+
* [{ "type": "text", "text": "B)" }]
|
| 656 |
+
* ```
|
| 657 |
+
*/
|
| 658 |
+
content: Array<BetaContentBlock>;
|
| 659 |
+
|
| 660 |
+
/**
|
| 661 |
+
* The model that will complete your prompt.\n\nSee
|
| 662 |
+
* [models](https://docs.anthropic.com/en/docs/models-overview) for additional
|
| 663 |
+
* details and options.
|
| 664 |
+
*/
|
| 665 |
+
model: MessagesAPI.Model;
|
| 666 |
+
|
| 667 |
+
/**
|
| 668 |
+
* Conversational role of the generated message.
|
| 669 |
+
*
|
| 670 |
+
* This will always be `"assistant"`.
|
| 671 |
+
*/
|
| 672 |
+
role: 'assistant';
|
| 673 |
+
|
| 674 |
+
/**
|
| 675 |
+
* The reason that we stopped.
|
| 676 |
+
*
|
| 677 |
+
* This may be one the following values:
|
| 678 |
+
*
|
| 679 |
+
* - `"end_turn"`: the model reached a natural stopping point
|
| 680 |
+
* - `"max_tokens"`: we exceeded the requested `max_tokens` or the model's maximum
|
| 681 |
+
* - `"stop_sequence"`: one of your provided custom `stop_sequences` was generated
|
| 682 |
+
* - `"tool_use"`: the model invoked one or more tools
|
| 683 |
+
* - `"pause_turn"`: we paused a long-running turn. You may provide the response
|
| 684 |
+
* back as-is in a subsequent request to let the model continue.
|
| 685 |
+
* - `"refusal"`: when streaming classifiers intervene to handle potential policy
|
| 686 |
+
* violations
|
| 687 |
+
*
|
| 688 |
+
* In non-streaming mode this value is always non-null. In streaming mode, it is
|
| 689 |
+
* null in the `message_start` event and non-null otherwise.
|
| 690 |
+
*/
|
| 691 |
+
stop_reason: BetaStopReason | null;
|
| 692 |
+
|
| 693 |
+
/**
|
| 694 |
+
* Which custom stop sequence was generated, if any.
|
| 695 |
+
*
|
| 696 |
+
* This value will be a non-null string if one of your custom stop sequences was
|
| 697 |
+
* generated.
|
| 698 |
+
*/
|
| 699 |
+
stop_sequence: string | null;
|
| 700 |
+
|
| 701 |
+
/**
|
| 702 |
+
* Object type.
|
| 703 |
+
*
|
| 704 |
+
* For Messages, this is always `"message"`.
|
| 705 |
+
*/
|
| 706 |
+
type: 'message';
|
| 707 |
+
|
| 708 |
+
/**
|
| 709 |
+
* Billing and rate-limit usage.
|
| 710 |
+
*
|
| 711 |
+
* Anthropic's API bills and rate-limits by token counts, as tokens represent the
|
| 712 |
+
* underlying cost to our systems.
|
| 713 |
+
*
|
| 714 |
+
* Under the hood, the API transforms requests into a format suitable for the
|
| 715 |
+
* model. The model's output then goes through a parsing stage before becoming an
|
| 716 |
+
* API response. As a result, the token counts in `usage` will not match one-to-one
|
| 717 |
+
* with the exact visible content of an API request or response.
|
| 718 |
+
*
|
| 719 |
+
* For example, `output_tokens` will be non-zero, even for an empty string response
|
| 720 |
+
* from Claude.
|
| 721 |
+
*
|
| 722 |
+
* Total input tokens in a request is the summation of `input_tokens`,
|
| 723 |
+
* `cache_creation_input_tokens`, and `cache_read_input_tokens`.
|
| 724 |
+
*/
|
| 725 |
+
usage: BetaUsage;
|
| 726 |
+
}
|
| 727 |
+
|
| 728 |
+
export interface BetaMessageDeltaUsage {
|
| 729 |
+
/**
|
| 730 |
+
* The cumulative number of input tokens used to create the cache entry.
|
| 731 |
+
*/
|
| 732 |
+
cache_creation_input_tokens: number | null;
|
| 733 |
+
|
| 734 |
+
/**
|
| 735 |
+
* The cumulative number of input tokens read from the cache.
|
| 736 |
+
*/
|
| 737 |
+
cache_read_input_tokens: number | null;
|
| 738 |
+
|
| 739 |
+
/**
|
| 740 |
+
* The cumulative number of input tokens which were used.
|
| 741 |
+
*/
|
| 742 |
+
input_tokens: number | null;
|
| 743 |
+
|
| 744 |
+
/**
|
| 745 |
+
* The cumulative number of output tokens which were used.
|
| 746 |
+
*/
|
| 747 |
+
output_tokens: number;
|
| 748 |
+
|
| 749 |
+
/**
|
| 750 |
+
* The number of server tool requests.
|
| 751 |
+
*/
|
| 752 |
+
server_tool_use: BetaServerToolUsage | null;
|
| 753 |
+
}
|
| 754 |
+
|
| 755 |
+
export interface BetaMessageParam {
|
| 756 |
+
content: string | Array<BetaContentBlockParam>;
|
| 757 |
+
|
| 758 |
+
role: 'user' | 'assistant';
|
| 759 |
+
}
|
| 760 |
+
|
| 761 |
+
export interface BetaMessageTokensCount {
|
| 762 |
+
/**
|
| 763 |
+
* The total number of tokens across the provided list of messages, system prompt,
|
| 764 |
+
* and tools.
|
| 765 |
+
*/
|
| 766 |
+
input_tokens: number;
|
| 767 |
+
}
|
| 768 |
+
|
| 769 |
+
export interface BetaMetadata {
|
| 770 |
+
/**
|
| 771 |
+
* An external identifier for the user who is associated with the request.
|
| 772 |
+
*
|
| 773 |
+
* This should be a uuid, hash value, or other opaque identifier. Anthropic may use
|
| 774 |
+
* this id to help detect abuse. Do not include any identifying information such as
|
| 775 |
+
* name, email address, or phone number.
|
| 776 |
+
*/
|
| 777 |
+
user_id?: string | null;
|
| 778 |
+
}
|
| 779 |
+
|
| 780 |
+
export interface BetaPlainTextSource {
|
| 781 |
+
data: string;
|
| 782 |
+
|
| 783 |
+
media_type: 'text/plain';
|
| 784 |
+
|
| 785 |
+
type: 'text';
|
| 786 |
+
}
|
| 787 |
+
|
| 788 |
+
export type BetaRawContentBlockDelta =
|
| 789 |
+
| BetaTextDelta
|
| 790 |
+
| BetaInputJSONDelta
|
| 791 |
+
| BetaCitationsDelta
|
| 792 |
+
| BetaThinkingDelta
|
| 793 |
+
| BetaSignatureDelta;
|
| 794 |
+
|
| 795 |
+
export interface BetaRawContentBlockDeltaEvent {
|
| 796 |
+
delta: BetaRawContentBlockDelta;
|
| 797 |
+
|
| 798 |
+
index: number;
|
| 799 |
+
|
| 800 |
+
type: 'content_block_delta';
|
| 801 |
+
}
|
| 802 |
+
|
| 803 |
+
export interface BetaRawContentBlockStartEvent {
|
| 804 |
+
/**
|
| 805 |
+
* Response model for a file uploaded to the container.
|
| 806 |
+
*/
|
| 807 |
+
content_block:
|
| 808 |
+
| BetaTextBlock
|
| 809 |
+
| BetaThinkingBlock
|
| 810 |
+
| BetaRedactedThinkingBlock
|
| 811 |
+
| BetaToolUseBlock
|
| 812 |
+
| BetaServerToolUseBlock
|
| 813 |
+
| BetaWebSearchToolResultBlock
|
| 814 |
+
| BetaCodeExecutionToolResultBlock
|
| 815 |
+
| BetaMCPToolUseBlock
|
| 816 |
+
| BetaMCPToolResultBlock
|
| 817 |
+
| BetaContainerUploadBlock;
|
| 818 |
+
|
| 819 |
+
index: number;
|
| 820 |
+
|
| 821 |
+
type: 'content_block_start';
|
| 822 |
+
}
|
| 823 |
+
|
| 824 |
+
export interface BetaRawContentBlockStopEvent {
|
| 825 |
+
index: number;
|
| 826 |
+
|
| 827 |
+
type: 'content_block_stop';
|
| 828 |
+
}
|
| 829 |
+
|
| 830 |
+
export interface BetaRawMessageDeltaEvent {
|
| 831 |
+
delta: BetaRawMessageDeltaEvent.Delta;
|
| 832 |
+
|
| 833 |
+
type: 'message_delta';
|
| 834 |
+
|
| 835 |
+
/**
|
| 836 |
+
* Billing and rate-limit usage.
|
| 837 |
+
*
|
| 838 |
+
* Anthropic's API bills and rate-limits by token counts, as tokens represent the
|
| 839 |
+
* underlying cost to our systems.
|
| 840 |
+
*
|
| 841 |
+
* Under the hood, the API transforms requests into a format suitable for the
|
| 842 |
+
* model. The model's output then goes through a parsing stage before becoming an
|
| 843 |
+
* API response. As a result, the token counts in `usage` will not match one-to-one
|
| 844 |
+
* with the exact visible content of an API request or response.
|
| 845 |
+
*
|
| 846 |
+
* For example, `output_tokens` will be non-zero, even for an empty string response
|
| 847 |
+
* from Claude.
|
| 848 |
+
*
|
| 849 |
+
* Total input tokens in a request is the summation of `input_tokens`,
|
| 850 |
+
* `cache_creation_input_tokens`, and `cache_read_input_tokens`.
|
| 851 |
+
*/
|
| 852 |
+
usage: BetaMessageDeltaUsage;
|
| 853 |
+
}
|
| 854 |
+
|
| 855 |
+
export namespace BetaRawMessageDeltaEvent {
|
| 856 |
+
export interface Delta {
|
| 857 |
+
/**
|
| 858 |
+
* Information about the container used in the request (for the code execution
|
| 859 |
+
* tool)
|
| 860 |
+
*/
|
| 861 |
+
container: MessagesMessagesAPI.BetaContainer | null;
|
| 862 |
+
|
| 863 |
+
stop_reason: MessagesMessagesAPI.BetaStopReason | null;
|
| 864 |
+
|
| 865 |
+
stop_sequence: string | null;
|
| 866 |
+
}
|
| 867 |
+
}
|
| 868 |
+
|
| 869 |
+
export interface BetaRawMessageStartEvent {
|
| 870 |
+
message: BetaMessage;
|
| 871 |
+
|
| 872 |
+
type: 'message_start';
|
| 873 |
+
}
|
| 874 |
+
|
| 875 |
+
export interface BetaRawMessageStopEvent {
|
| 876 |
+
type: 'message_stop';
|
| 877 |
+
}
|
| 878 |
+
|
| 879 |
+
export type BetaRawMessageStreamEvent =
|
| 880 |
+
| BetaRawMessageStartEvent
|
| 881 |
+
| BetaRawMessageDeltaEvent
|
| 882 |
+
| BetaRawMessageStopEvent
|
| 883 |
+
| BetaRawContentBlockStartEvent
|
| 884 |
+
| BetaRawContentBlockDeltaEvent
|
| 885 |
+
| BetaRawContentBlockStopEvent;
|
| 886 |
+
|
| 887 |
+
export interface BetaRedactedThinkingBlock {
|
| 888 |
+
data: string;
|
| 889 |
+
|
| 890 |
+
type: 'redacted_thinking';
|
| 891 |
+
}
|
| 892 |
+
|
| 893 |
+
export interface BetaRedactedThinkingBlockParam {
|
| 894 |
+
data: string;
|
| 895 |
+
|
| 896 |
+
type: 'redacted_thinking';
|
| 897 |
+
}
|
| 898 |
+
|
| 899 |
+
export interface BetaRequestDocumentBlock {
|
| 900 |
+
source:
|
| 901 |
+
| BetaBase64PDFSource
|
| 902 |
+
| BetaPlainTextSource
|
| 903 |
+
| BetaContentBlockSource
|
| 904 |
+
| BetaURLPDFSource
|
| 905 |
+
| BetaFileDocumentSource;
|
| 906 |
+
|
| 907 |
+
type: 'document';
|
| 908 |
+
|
| 909 |
+
/**
|
| 910 |
+
* Create a cache control breakpoint at this content block.
|
| 911 |
+
*/
|
| 912 |
+
cache_control?: BetaCacheControlEphemeral | null;
|
| 913 |
+
|
| 914 |
+
citations?: BetaCitationsConfigParam;
|
| 915 |
+
|
| 916 |
+
context?: string | null;
|
| 917 |
+
|
| 918 |
+
title?: string | null;
|
| 919 |
+
}
|
| 920 |
+
|
| 921 |
+
export interface BetaRequestMCPServerToolConfiguration {
|
| 922 |
+
allowed_tools?: Array<string> | null;
|
| 923 |
+
|
| 924 |
+
enabled?: boolean | null;
|
| 925 |
+
}
|
| 926 |
+
|
| 927 |
+
export interface BetaRequestMCPServerURLDefinition {
|
| 928 |
+
name: string;
|
| 929 |
+
|
| 930 |
+
type: 'url';
|
| 931 |
+
|
| 932 |
+
url: string;
|
| 933 |
+
|
| 934 |
+
authorization_token?: string | null;
|
| 935 |
+
|
| 936 |
+
tool_configuration?: BetaRequestMCPServerToolConfiguration | null;
|
| 937 |
+
}
|
| 938 |
+
|
| 939 |
+
export interface BetaRequestMCPToolResultBlockParam {
|
| 940 |
+
tool_use_id: string;
|
| 941 |
+
|
| 942 |
+
type: 'mcp_tool_result';
|
| 943 |
+
|
| 944 |
+
/**
|
| 945 |
+
* Create a cache control breakpoint at this content block.
|
| 946 |
+
*/
|
| 947 |
+
cache_control?: BetaCacheControlEphemeral | null;
|
| 948 |
+
|
| 949 |
+
content?: string | Array<BetaTextBlockParam>;
|
| 950 |
+
|
| 951 |
+
is_error?: boolean;
|
| 952 |
+
}
|
| 953 |
+
|
| 954 |
+
export interface BetaSearchResultBlockParam {
|
| 955 |
+
content: Array<BetaTextBlockParam>;
|
| 956 |
+
|
| 957 |
+
source: string;
|
| 958 |
+
|
| 959 |
+
title: string;
|
| 960 |
+
|
| 961 |
+
type: 'search_result';
|
| 962 |
+
|
| 963 |
+
/**
|
| 964 |
+
* Create a cache control breakpoint at this content block.
|
| 965 |
+
*/
|
| 966 |
+
cache_control?: BetaCacheControlEphemeral | null;
|
| 967 |
+
|
| 968 |
+
citations?: BetaCitationsConfigParam;
|
| 969 |
+
}
|
| 970 |
+
|
| 971 |
+
export interface BetaServerToolUsage {
|
| 972 |
+
/**
|
| 973 |
+
* The number of web search tool requests.
|
| 974 |
+
*/
|
| 975 |
+
web_search_requests: number;
|
| 976 |
+
}
|
| 977 |
+
|
| 978 |
+
export interface BetaServerToolUseBlock {
|
| 979 |
+
id: string;
|
| 980 |
+
|
| 981 |
+
input: unknown;
|
| 982 |
+
|
| 983 |
+
name: 'web_search' | 'code_execution';
|
| 984 |
+
|
| 985 |
+
type: 'server_tool_use';
|
| 986 |
+
}
|
| 987 |
+
|
| 988 |
+
export interface BetaServerToolUseBlockParam {
|
| 989 |
+
id: string;
|
| 990 |
+
|
| 991 |
+
input: unknown;
|
| 992 |
+
|
| 993 |
+
name: 'web_search' | 'code_execution';
|
| 994 |
+
|
| 995 |
+
type: 'server_tool_use';
|
| 996 |
+
|
| 997 |
+
/**
|
| 998 |
+
* Create a cache control breakpoint at this content block.
|
| 999 |
+
*/
|
| 1000 |
+
cache_control?: BetaCacheControlEphemeral | null;
|
| 1001 |
+
}
|
| 1002 |
+
|
| 1003 |
+
export interface BetaSignatureDelta {
|
| 1004 |
+
signature: string;
|
| 1005 |
+
|
| 1006 |
+
type: 'signature_delta';
|
| 1007 |
+
}
|
| 1008 |
+
|
| 1009 |
+
export type BetaStopReason =
|
| 1010 |
+
| 'end_turn'
|
| 1011 |
+
| 'max_tokens'
|
| 1012 |
+
| 'stop_sequence'
|
| 1013 |
+
| 'tool_use'
|
| 1014 |
+
| 'pause_turn'
|
| 1015 |
+
| 'refusal';
|
| 1016 |
+
|
| 1017 |
+
export interface BetaTextBlock {
|
| 1018 |
+
/**
|
| 1019 |
+
* Citations supporting the text block.
|
| 1020 |
+
*
|
| 1021 |
+
* The type of citation returned will depend on the type of document being cited.
|
| 1022 |
+
* Citing a PDF results in `page_location`, plain text results in `char_location`,
|
| 1023 |
+
* and content document results in `content_block_location`.
|
| 1024 |
+
*/
|
| 1025 |
+
citations: Array<BetaTextCitation> | null;
|
| 1026 |
+
|
| 1027 |
+
text: string;
|
| 1028 |
+
|
| 1029 |
+
type: 'text';
|
| 1030 |
+
}
|
| 1031 |
+
|
| 1032 |
+
export interface BetaTextBlockParam {
|
| 1033 |
+
text: string;
|
| 1034 |
+
|
| 1035 |
+
type: 'text';
|
| 1036 |
+
|
| 1037 |
+
/**
|
| 1038 |
+
* Create a cache control breakpoint at this content block.
|
| 1039 |
+
*/
|
| 1040 |
+
cache_control?: BetaCacheControlEphemeral | null;
|
| 1041 |
+
|
| 1042 |
+
citations?: Array<BetaTextCitationParam> | null;
|
| 1043 |
+
}
|
| 1044 |
+
|
| 1045 |
+
export type BetaTextCitation =
|
| 1046 |
+
| BetaCitationCharLocation
|
| 1047 |
+
| BetaCitationPageLocation
|
| 1048 |
+
| BetaCitationContentBlockLocation
|
| 1049 |
+
| BetaCitationsWebSearchResultLocation
|
| 1050 |
+
| BetaCitationSearchResultLocation;
|
| 1051 |
+
|
| 1052 |
+
export type BetaTextCitationParam =
|
| 1053 |
+
| BetaCitationCharLocationParam
|
| 1054 |
+
| BetaCitationPageLocationParam
|
| 1055 |
+
| BetaCitationContentBlockLocationParam
|
| 1056 |
+
| BetaCitationWebSearchResultLocationParam
|
| 1057 |
+
| BetaCitationSearchResultLocationParam;
|
| 1058 |
+
|
| 1059 |
+
export interface BetaTextDelta {
|
| 1060 |
+
text: string;
|
| 1061 |
+
|
| 1062 |
+
type: 'text_delta';
|
| 1063 |
+
}
|
| 1064 |
+
|
| 1065 |
+
export interface BetaThinkingBlock {
|
| 1066 |
+
signature: string;
|
| 1067 |
+
|
| 1068 |
+
thinking: string;
|
| 1069 |
+
|
| 1070 |
+
type: 'thinking';
|
| 1071 |
+
}
|
| 1072 |
+
|
| 1073 |
+
export interface BetaThinkingBlockParam {
|
| 1074 |
+
signature: string;
|
| 1075 |
+
|
| 1076 |
+
thinking: string;
|
| 1077 |
+
|
| 1078 |
+
type: 'thinking';
|
| 1079 |
+
}
|
| 1080 |
+
|
| 1081 |
+
export interface BetaThinkingConfigDisabled {
|
| 1082 |
+
type: 'disabled';
|
| 1083 |
+
}
|
| 1084 |
+
|
| 1085 |
+
export interface BetaThinkingConfigEnabled {
|
| 1086 |
+
/**
|
| 1087 |
+
* Determines how many tokens Claude can use for its internal reasoning process.
|
| 1088 |
+
* Larger budgets can enable more thorough analysis for complex problems, improving
|
| 1089 |
+
* response quality.
|
| 1090 |
+
*
|
| 1091 |
+
* Must be ≥1024 and less than `max_tokens`.
|
| 1092 |
+
*
|
| 1093 |
+
* See
|
| 1094 |
+
* [extended thinking](https://docs.anthropic.com/en/docs/build-with-claude/extended-thinking)
|
| 1095 |
+
* for details.
|
| 1096 |
+
*/
|
| 1097 |
+
budget_tokens: number;
|
| 1098 |
+
|
| 1099 |
+
type: 'enabled';
|
| 1100 |
+
}
|
| 1101 |
+
|
| 1102 |
+
/**
|
| 1103 |
+
* Configuration for enabling Claude's extended thinking.
|
| 1104 |
+
*
|
| 1105 |
+
* When enabled, responses include `thinking` content blocks showing Claude's
|
| 1106 |
+
* thinking process before the final answer. Requires a minimum budget of 1,024
|
| 1107 |
+
* tokens and counts towards your `max_tokens` limit.
|
| 1108 |
+
*
|
| 1109 |
+
* See
|
| 1110 |
+
* [extended thinking](https://docs.anthropic.com/en/docs/build-with-claude/extended-thinking)
|
| 1111 |
+
* for details.
|
| 1112 |
+
*/
|
| 1113 |
+
export type BetaThinkingConfigParam = BetaThinkingConfigEnabled | BetaThinkingConfigDisabled;
|
| 1114 |
+
|
| 1115 |
+
export interface BetaThinkingDelta {
|
| 1116 |
+
thinking: string;
|
| 1117 |
+
|
| 1118 |
+
type: 'thinking_delta';
|
| 1119 |
+
}
|
| 1120 |
+
|
| 1121 |
+
export interface BetaTool {
|
| 1122 |
+
/**
|
| 1123 |
+
* [JSON schema](https://json-schema.org/draft/2020-12) for this tool's input.
|
| 1124 |
+
*
|
| 1125 |
+
* This defines the shape of the `input` that your tool accepts and that the model
|
| 1126 |
+
* will produce.
|
| 1127 |
+
*/
|
| 1128 |
+
input_schema: BetaTool.InputSchema;
|
| 1129 |
+
|
| 1130 |
+
/**
|
| 1131 |
+
* Name of the tool.
|
| 1132 |
+
*
|
| 1133 |
+
* This is how the tool will be called by the model and in `tool_use` blocks.
|
| 1134 |
+
*/
|
| 1135 |
+
name: string;
|
| 1136 |
+
|
| 1137 |
+
/**
|
| 1138 |
+
* Create a cache control breakpoint at this content block.
|
| 1139 |
+
*/
|
| 1140 |
+
cache_control?: BetaCacheControlEphemeral | null;
|
| 1141 |
+
|
| 1142 |
+
/**
|
| 1143 |
+
* Description of what this tool does.
|
| 1144 |
+
*
|
| 1145 |
+
* Tool descriptions should be as detailed as possible. The more information that
|
| 1146 |
+
* the model has about what the tool is and how to use it, the better it will
|
| 1147 |
+
* perform. You can use natural language descriptions to reinforce important
|
| 1148 |
+
* aspects of the tool input JSON schema.
|
| 1149 |
+
*/
|
| 1150 |
+
description?: string;
|
| 1151 |
+
|
| 1152 |
+
type?: 'custom' | null;
|
| 1153 |
+
}
|
| 1154 |
+
|
| 1155 |
+
export namespace BetaTool {
|
| 1156 |
+
/**
|
| 1157 |
+
* [JSON schema](https://json-schema.org/draft/2020-12) for this tool's input.
|
| 1158 |
+
*
|
| 1159 |
+
* This defines the shape of the `input` that your tool accepts and that the model
|
| 1160 |
+
* will produce.
|
| 1161 |
+
*/
|
| 1162 |
+
export interface InputSchema {
|
| 1163 |
+
type: 'object';
|
| 1164 |
+
|
| 1165 |
+
properties?: unknown | null;
|
| 1166 |
+
|
| 1167 |
+
required?: Array<string> | null;
|
| 1168 |
+
|
| 1169 |
+
[k: string]: unknown;
|
| 1170 |
+
}
|
| 1171 |
+
}
|
| 1172 |
+
|
| 1173 |
+
export interface BetaToolBash20241022 {
|
| 1174 |
+
/**
|
| 1175 |
+
* Name of the tool.
|
| 1176 |
+
*
|
| 1177 |
+
* This is how the tool will be called by the model and in `tool_use` blocks.
|
| 1178 |
+
*/
|
| 1179 |
+
name: 'bash';
|
| 1180 |
+
|
| 1181 |
+
type: 'bash_20241022';
|
| 1182 |
+
|
| 1183 |
+
/**
|
| 1184 |
+
* Create a cache control breakpoint at this content block.
|
| 1185 |
+
*/
|
| 1186 |
+
cache_control?: BetaCacheControlEphemeral | null;
|
| 1187 |
+
}
|
| 1188 |
+
|
| 1189 |
+
export interface BetaToolBash20250124 {
|
| 1190 |
+
/**
|
| 1191 |
+
* Name of the tool.
|
| 1192 |
+
*
|
| 1193 |
+
* This is how the tool will be called by the model and in `tool_use` blocks.
|
| 1194 |
+
*/
|
| 1195 |
+
name: 'bash';
|
| 1196 |
+
|
| 1197 |
+
type: 'bash_20250124';
|
| 1198 |
+
|
| 1199 |
+
/**
|
| 1200 |
+
* Create a cache control breakpoint at this content block.
|
| 1201 |
+
*/
|
| 1202 |
+
cache_control?: BetaCacheControlEphemeral | null;
|
| 1203 |
+
}
|
| 1204 |
+
|
| 1205 |
+
/**
|
| 1206 |
+
* How the model should use the provided tools. The model can use a specific tool,
|
| 1207 |
+
* any available tool, decide by itself, or not use tools at all.
|
| 1208 |
+
*/
|
| 1209 |
+
export type BetaToolChoice = BetaToolChoiceAuto | BetaToolChoiceAny | BetaToolChoiceTool | BetaToolChoiceNone;
|
| 1210 |
+
|
| 1211 |
+
/**
|
| 1212 |
+
* The model will use any available tools.
|
| 1213 |
+
*/
|
| 1214 |
+
export interface BetaToolChoiceAny {
|
| 1215 |
+
type: 'any';
|
| 1216 |
+
|
| 1217 |
+
/**
|
| 1218 |
+
* Whether to disable parallel tool use.
|
| 1219 |
+
*
|
| 1220 |
+
* Defaults to `false`. If set to `true`, the model will output exactly one tool
|
| 1221 |
+
* use.
|
| 1222 |
+
*/
|
| 1223 |
+
disable_parallel_tool_use?: boolean;
|
| 1224 |
+
}
|
| 1225 |
+
|
| 1226 |
+
/**
|
| 1227 |
+
* The model will automatically decide whether to use tools.
|
| 1228 |
+
*/
|
| 1229 |
+
export interface BetaToolChoiceAuto {
|
| 1230 |
+
type: 'auto';
|
| 1231 |
+
|
| 1232 |
+
/**
|
| 1233 |
+
* Whether to disable parallel tool use.
|
| 1234 |
+
*
|
| 1235 |
+
* Defaults to `false`. If set to `true`, the model will output at most one tool
|
| 1236 |
+
* use.
|
| 1237 |
+
*/
|
| 1238 |
+
disable_parallel_tool_use?: boolean;
|
| 1239 |
+
}
|
| 1240 |
+
|
| 1241 |
+
/**
|
| 1242 |
+
* The model will not be allowed to use tools.
|
| 1243 |
+
*/
|
| 1244 |
+
export interface BetaToolChoiceNone {
|
| 1245 |
+
type: 'none';
|
| 1246 |
+
}
|
| 1247 |
+
|
| 1248 |
+
/**
|
| 1249 |
+
* The model will use the specified tool with `tool_choice.name`.
|
| 1250 |
+
*/
|
| 1251 |
+
export interface BetaToolChoiceTool {
|
| 1252 |
+
/**
|
| 1253 |
+
* The name of the tool to use.
|
| 1254 |
+
*/
|
| 1255 |
+
name: string;
|
| 1256 |
+
|
| 1257 |
+
type: 'tool';
|
| 1258 |
+
|
| 1259 |
+
/**
|
| 1260 |
+
* Whether to disable parallel tool use.
|
| 1261 |
+
*
|
| 1262 |
+
* Defaults to `false`. If set to `true`, the model will output exactly one tool
|
| 1263 |
+
* use.
|
| 1264 |
+
*/
|
| 1265 |
+
disable_parallel_tool_use?: boolean;
|
| 1266 |
+
}
|
| 1267 |
+
|
| 1268 |
+
export interface BetaToolComputerUse20241022 {
|
| 1269 |
+
/**
|
| 1270 |
+
* The height of the display in pixels.
|
| 1271 |
+
*/
|
| 1272 |
+
display_height_px: number;
|
| 1273 |
+
|
| 1274 |
+
/**
|
| 1275 |
+
* The width of the display in pixels.
|
| 1276 |
+
*/
|
| 1277 |
+
display_width_px: number;
|
| 1278 |
+
|
| 1279 |
+
/**
|
| 1280 |
+
* Name of the tool.
|
| 1281 |
+
*
|
| 1282 |
+
* This is how the tool will be called by the model and in `tool_use` blocks.
|
| 1283 |
+
*/
|
| 1284 |
+
name: 'computer';
|
| 1285 |
+
|
| 1286 |
+
type: 'computer_20241022';
|
| 1287 |
+
|
| 1288 |
+
/**
|
| 1289 |
+
* Create a cache control breakpoint at this content block.
|
| 1290 |
+
*/
|
| 1291 |
+
cache_control?: BetaCacheControlEphemeral | null;
|
| 1292 |
+
|
| 1293 |
+
/**
|
| 1294 |
+
* The X11 display number (e.g. 0, 1) for the display.
|
| 1295 |
+
*/
|
| 1296 |
+
display_number?: number | null;
|
| 1297 |
+
}
|
| 1298 |
+
|
| 1299 |
+
export interface BetaToolComputerUse20250124 {
|
| 1300 |
+
/**
|
| 1301 |
+
* The height of the display in pixels.
|
| 1302 |
+
*/
|
| 1303 |
+
display_height_px: number;
|
| 1304 |
+
|
| 1305 |
+
/**
|
| 1306 |
+
* The width of the display in pixels.
|
| 1307 |
+
*/
|
| 1308 |
+
display_width_px: number;
|
| 1309 |
+
|
| 1310 |
+
/**
|
| 1311 |
+
* Name of the tool.
|
| 1312 |
+
*
|
| 1313 |
+
* This is how the tool will be called by the model and in `tool_use` blocks.
|
| 1314 |
+
*/
|
| 1315 |
+
name: 'computer';
|
| 1316 |
+
|
| 1317 |
+
type: 'computer_20250124';
|
| 1318 |
+
|
| 1319 |
+
/**
|
| 1320 |
+
* Create a cache control breakpoint at this content block.
|
| 1321 |
+
*/
|
| 1322 |
+
cache_control?: BetaCacheControlEphemeral | null;
|
| 1323 |
+
|
| 1324 |
+
/**
|
| 1325 |
+
* The X11 display number (e.g. 0, 1) for the display.
|
| 1326 |
+
*/
|
| 1327 |
+
display_number?: number | null;
|
| 1328 |
+
}
|
| 1329 |
+
|
| 1330 |
+
export interface BetaToolResultBlockParam {
|
| 1331 |
+
tool_use_id: string;
|
| 1332 |
+
|
| 1333 |
+
type: 'tool_result';
|
| 1334 |
+
|
| 1335 |
+
/**
|
| 1336 |
+
* Create a cache control breakpoint at this content block.
|
| 1337 |
+
*/
|
| 1338 |
+
cache_control?: BetaCacheControlEphemeral | null;
|
| 1339 |
+
|
| 1340 |
+
content?: string | Array<BetaTextBlockParam | BetaImageBlockParam | BetaSearchResultBlockParam>;
|
| 1341 |
+
|
| 1342 |
+
is_error?: boolean;
|
| 1343 |
+
}
|
| 1344 |
+
|
| 1345 |
+
export interface BetaToolTextEditor20241022 {
|
| 1346 |
+
/**
|
| 1347 |
+
* Name of the tool.
|
| 1348 |
+
*
|
| 1349 |
+
* This is how the tool will be called by the model and in `tool_use` blocks.
|
| 1350 |
+
*/
|
| 1351 |
+
name: 'str_replace_editor';
|
| 1352 |
+
|
| 1353 |
+
type: 'text_editor_20241022';
|
| 1354 |
+
|
| 1355 |
+
/**
|
| 1356 |
+
* Create a cache control breakpoint at this content block.
|
| 1357 |
+
*/
|
| 1358 |
+
cache_control?: BetaCacheControlEphemeral | null;
|
| 1359 |
+
}
|
| 1360 |
+
|
| 1361 |
+
export interface BetaToolTextEditor20250124 {
|
| 1362 |
+
/**
|
| 1363 |
+
* Name of the tool.
|
| 1364 |
+
*
|
| 1365 |
+
* This is how the tool will be called by the model and in `tool_use` blocks.
|
| 1366 |
+
*/
|
| 1367 |
+
name: 'str_replace_editor';
|
| 1368 |
+
|
| 1369 |
+
type: 'text_editor_20250124';
|
| 1370 |
+
|
| 1371 |
+
/**
|
| 1372 |
+
* Create a cache control breakpoint at this content block.
|
| 1373 |
+
*/
|
| 1374 |
+
cache_control?: BetaCacheControlEphemeral | null;
|
| 1375 |
+
}
|
| 1376 |
+
|
| 1377 |
+
export interface BetaToolTextEditor20250429 {
|
| 1378 |
+
/**
|
| 1379 |
+
* Name of the tool.
|
| 1380 |
+
*
|
| 1381 |
+
* This is how the tool will be called by the model and in `tool_use` blocks.
|
| 1382 |
+
*/
|
| 1383 |
+
name: 'str_replace_based_edit_tool';
|
| 1384 |
+
|
| 1385 |
+
type: 'text_editor_20250429';
|
| 1386 |
+
|
| 1387 |
+
/**
|
| 1388 |
+
* Create a cache control breakpoint at this content block.
|
| 1389 |
+
*/
|
| 1390 |
+
cache_control?: BetaCacheControlEphemeral | null;
|
| 1391 |
+
}
|
| 1392 |
+
|
| 1393 |
+
export type BetaToolUnion =
|
| 1394 |
+
| BetaTool
|
| 1395 |
+
| BetaToolBash20241022
|
| 1396 |
+
| BetaToolBash20250124
|
| 1397 |
+
| BetaCodeExecutionTool20250522
|
| 1398 |
+
| BetaToolComputerUse20241022
|
| 1399 |
+
| BetaToolComputerUse20250124
|
| 1400 |
+
| BetaToolTextEditor20241022
|
| 1401 |
+
| BetaToolTextEditor20250124
|
| 1402 |
+
| BetaToolTextEditor20250429
|
| 1403 |
+
| BetaWebSearchTool20250305;
|
| 1404 |
+
|
| 1405 |
+
export interface BetaToolUseBlock {
|
| 1406 |
+
id: string;
|
| 1407 |
+
|
| 1408 |
+
input: unknown;
|
| 1409 |
+
|
| 1410 |
+
name: string;
|
| 1411 |
+
|
| 1412 |
+
type: 'tool_use';
|
| 1413 |
+
}
|
| 1414 |
+
|
| 1415 |
+
export interface BetaToolUseBlockParam {
|
| 1416 |
+
id: string;
|
| 1417 |
+
|
| 1418 |
+
input: unknown;
|
| 1419 |
+
|
| 1420 |
+
name: string;
|
| 1421 |
+
|
| 1422 |
+
type: 'tool_use';
|
| 1423 |
+
|
| 1424 |
+
/**
|
| 1425 |
+
* Create a cache control breakpoint at this content block.
|
| 1426 |
+
*/
|
| 1427 |
+
cache_control?: BetaCacheControlEphemeral | null;
|
| 1428 |
+
}
|
| 1429 |
+
|
| 1430 |
+
export interface BetaURLImageSource {
|
| 1431 |
+
type: 'url';
|
| 1432 |
+
|
| 1433 |
+
url: string;
|
| 1434 |
+
}
|
| 1435 |
+
|
| 1436 |
+
export interface BetaURLPDFSource {
|
| 1437 |
+
type: 'url';
|
| 1438 |
+
|
| 1439 |
+
url: string;
|
| 1440 |
+
}
|
| 1441 |
+
|
| 1442 |
+
export interface BetaUsage {
|
| 1443 |
+
/**
|
| 1444 |
+
* Breakdown of cached tokens by TTL
|
| 1445 |
+
*/
|
| 1446 |
+
cache_creation: BetaCacheCreation | null;
|
| 1447 |
+
|
| 1448 |
+
/**
|
| 1449 |
+
* The number of input tokens used to create the cache entry.
|
| 1450 |
+
*/
|
| 1451 |
+
cache_creation_input_tokens: number | null;
|
| 1452 |
+
|
| 1453 |
+
/**
|
| 1454 |
+
* The number of input tokens read from the cache.
|
| 1455 |
+
*/
|
| 1456 |
+
cache_read_input_tokens: number | null;
|
| 1457 |
+
|
| 1458 |
+
/**
|
| 1459 |
+
* The number of input tokens which were used.
|
| 1460 |
+
*/
|
| 1461 |
+
input_tokens: number;
|
| 1462 |
+
|
| 1463 |
+
/**
|
| 1464 |
+
* The number of output tokens which were used.
|
| 1465 |
+
*/
|
| 1466 |
+
output_tokens: number;
|
| 1467 |
+
|
| 1468 |
+
/**
|
| 1469 |
+
* The number of server tool requests.
|
| 1470 |
+
*/
|
| 1471 |
+
server_tool_use: BetaServerToolUsage | null;
|
| 1472 |
+
|
| 1473 |
+
/**
|
| 1474 |
+
* If the request used the priority, standard, or batch tier.
|
| 1475 |
+
*/
|
| 1476 |
+
service_tier: 'standard' | 'priority' | 'batch' | null;
|
| 1477 |
+
}
|
| 1478 |
+
|
| 1479 |
+
export interface BetaWebSearchResultBlock {
|
| 1480 |
+
encrypted_content: string;
|
| 1481 |
+
|
| 1482 |
+
page_age: string | null;
|
| 1483 |
+
|
| 1484 |
+
title: string;
|
| 1485 |
+
|
| 1486 |
+
type: 'web_search_result';
|
| 1487 |
+
|
| 1488 |
+
url: string;
|
| 1489 |
+
}
|
| 1490 |
+
|
| 1491 |
+
export interface BetaWebSearchResultBlockParam {
|
| 1492 |
+
encrypted_content: string;
|
| 1493 |
+
|
| 1494 |
+
title: string;
|
| 1495 |
+
|
| 1496 |
+
type: 'web_search_result';
|
| 1497 |
+
|
| 1498 |
+
url: string;
|
| 1499 |
+
|
| 1500 |
+
page_age?: string | null;
|
| 1501 |
+
}
|
| 1502 |
+
|
| 1503 |
+
export interface BetaWebSearchTool20250305 {
|
| 1504 |
+
/**
|
| 1505 |
+
* Name of the tool.
|
| 1506 |
+
*
|
| 1507 |
+
* This is how the tool will be called by the model and in `tool_use` blocks.
|
| 1508 |
+
*/
|
| 1509 |
+
name: 'web_search';
|
| 1510 |
+
|
| 1511 |
+
type: 'web_search_20250305';
|
| 1512 |
+
|
| 1513 |
+
/**
|
| 1514 |
+
* If provided, only these domains will be included in results. Cannot be used
|
| 1515 |
+
* alongside `blocked_domains`.
|
| 1516 |
+
*/
|
| 1517 |
+
allowed_domains?: Array<string> | null;
|
| 1518 |
+
|
| 1519 |
+
/**
|
| 1520 |
+
* If provided, these domains will never appear in results. Cannot be used
|
| 1521 |
+
* alongside `allowed_domains`.
|
| 1522 |
+
*/
|
| 1523 |
+
blocked_domains?: Array<string> | null;
|
| 1524 |
+
|
| 1525 |
+
/**
|
| 1526 |
+
* Create a cache control breakpoint at this content block.
|
| 1527 |
+
*/
|
| 1528 |
+
cache_control?: BetaCacheControlEphemeral | null;
|
| 1529 |
+
|
| 1530 |
+
/**
|
| 1531 |
+
* Maximum number of times the tool can be used in the API request.
|
| 1532 |
+
*/
|
| 1533 |
+
max_uses?: number | null;
|
| 1534 |
+
|
| 1535 |
+
/**
|
| 1536 |
+
* Parameters for the user's location. Used to provide more relevant search
|
| 1537 |
+
* results.
|
| 1538 |
+
*/
|
| 1539 |
+
user_location?: BetaWebSearchTool20250305.UserLocation | null;
|
| 1540 |
+
}
|
| 1541 |
+
|
| 1542 |
+
export namespace BetaWebSearchTool20250305 {
|
| 1543 |
+
/**
|
| 1544 |
+
* Parameters for the user's location. Used to provide more relevant search
|
| 1545 |
+
* results.
|
| 1546 |
+
*/
|
| 1547 |
+
export interface UserLocation {
|
| 1548 |
+
type: 'approximate';
|
| 1549 |
+
|
| 1550 |
+
/**
|
| 1551 |
+
* The city of the user.
|
| 1552 |
+
*/
|
| 1553 |
+
city?: string | null;
|
| 1554 |
+
|
| 1555 |
+
/**
|
| 1556 |
+
* The two letter
|
| 1557 |
+
* [ISO country code](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) of the
|
| 1558 |
+
* user.
|
| 1559 |
+
*/
|
| 1560 |
+
country?: string | null;
|
| 1561 |
+
|
| 1562 |
+
/**
|
| 1563 |
+
* The region of the user.
|
| 1564 |
+
*/
|
| 1565 |
+
region?: string | null;
|
| 1566 |
+
|
| 1567 |
+
/**
|
| 1568 |
+
* The [IANA timezone](https://nodatime.org/TimeZones) of the user.
|
| 1569 |
+
*/
|
| 1570 |
+
timezone?: string | null;
|
| 1571 |
+
}
|
| 1572 |
+
}
|
| 1573 |
+
|
| 1574 |
+
export interface BetaWebSearchToolRequestError {
|
| 1575 |
+
error_code: BetaWebSearchToolResultErrorCode;
|
| 1576 |
+
|
| 1577 |
+
type: 'web_search_tool_result_error';
|
| 1578 |
+
}
|
| 1579 |
+
|
| 1580 |
+
export interface BetaWebSearchToolResultBlock {
|
| 1581 |
+
content: BetaWebSearchToolResultBlockContent;
|
| 1582 |
+
|
| 1583 |
+
tool_use_id: string;
|
| 1584 |
+
|
| 1585 |
+
type: 'web_search_tool_result';
|
| 1586 |
+
}
|
| 1587 |
+
|
| 1588 |
+
export type BetaWebSearchToolResultBlockContent =
|
| 1589 |
+
| BetaWebSearchToolResultError
|
| 1590 |
+
| Array<BetaWebSearchResultBlock>;
|
| 1591 |
+
|
| 1592 |
+
export interface BetaWebSearchToolResultBlockParam {
|
| 1593 |
+
content: BetaWebSearchToolResultBlockParamContent;
|
| 1594 |
+
|
| 1595 |
+
tool_use_id: string;
|
| 1596 |
+
|
| 1597 |
+
type: 'web_search_tool_result';
|
| 1598 |
+
|
| 1599 |
+
/**
|
| 1600 |
+
* Create a cache control breakpoint at this content block.
|
| 1601 |
+
*/
|
| 1602 |
+
cache_control?: BetaCacheControlEphemeral | null;
|
| 1603 |
+
}
|
| 1604 |
+
|
| 1605 |
+
export type BetaWebSearchToolResultBlockParamContent =
|
| 1606 |
+
| Array<BetaWebSearchResultBlockParam>
|
| 1607 |
+
| BetaWebSearchToolRequestError;
|
| 1608 |
+
|
| 1609 |
+
export interface BetaWebSearchToolResultError {
|
| 1610 |
+
error_code: BetaWebSearchToolResultErrorCode;
|
| 1611 |
+
|
| 1612 |
+
type: 'web_search_tool_result_error';
|
| 1613 |
+
}
|
| 1614 |
+
|
| 1615 |
+
export type BetaWebSearchToolResultErrorCode =
|
| 1616 |
+
| 'invalid_tool_input'
|
| 1617 |
+
| 'unavailable'
|
| 1618 |
+
| 'max_uses_exceeded'
|
| 1619 |
+
| 'too_many_requests'
|
| 1620 |
+
| 'query_too_long';
|
| 1621 |
+
|
| 1622 |
+
/**
|
| 1623 |
+
* @deprecated BetaRequestDocumentBlock should be used insated
|
| 1624 |
+
*/
|
| 1625 |
+
export type BetaBase64PDFBlock = BetaRequestDocumentBlock;
|
| 1626 |
+
|
| 1627 |
+
export type MessageCreateParams = MessageCreateParamsNonStreaming | MessageCreateParamsStreaming;
|
| 1628 |
+
|
| 1629 |
+
export interface MessageCreateParamsBase {
|
| 1630 |
+
/**
|
| 1631 |
+
* Body param: The maximum number of tokens to generate before stopping.
|
| 1632 |
+
*
|
| 1633 |
+
* Note that our models may stop _before_ reaching this maximum. This parameter
|
| 1634 |
+
* only specifies the absolute maximum number of tokens to generate.
|
| 1635 |
+
*
|
| 1636 |
+
* Different models have different maximum values for this parameter. See
|
| 1637 |
+
* [models](https://docs.anthropic.com/en/docs/models-overview) for details.
|
| 1638 |
+
*/
|
| 1639 |
+
max_tokens: number;
|
| 1640 |
+
|
| 1641 |
+
/**
|
| 1642 |
+
* Body param: Input messages.
|
| 1643 |
+
*
|
| 1644 |
+
* Our models are trained to operate on alternating `user` and `assistant`
|
| 1645 |
+
* conversational turns. When creating a new `Message`, you specify the prior
|
| 1646 |
+
* conversational turns with the `messages` parameter, and the model then generates
|
| 1647 |
+
* the next `Message` in the conversation. Consecutive `user` or `assistant` turns
|
| 1648 |
+
* in your request will be combined into a single turn.
|
| 1649 |
+
*
|
| 1650 |
+
* Each input message must be an object with a `role` and `content`. You can
|
| 1651 |
+
* specify a single `user`-role message, or you can include multiple `user` and
|
| 1652 |
+
* `assistant` messages.
|
| 1653 |
+
*
|
| 1654 |
+
* If the final message uses the `assistant` role, the response content will
|
| 1655 |
+
* continue immediately from the content in that message. This can be used to
|
| 1656 |
+
* constrain part of the model's response.
|
| 1657 |
+
*
|
| 1658 |
+
* Example with a single `user` message:
|
| 1659 |
+
*
|
| 1660 |
+
* ```json
|
| 1661 |
+
* [{ "role": "user", "content": "Hello, Claude" }]
|
| 1662 |
+
* ```
|
| 1663 |
+
*
|
| 1664 |
+
* Example with multiple conversational turns:
|
| 1665 |
+
*
|
| 1666 |
+
* ```json
|
| 1667 |
+
* [
|
| 1668 |
+
* { "role": "user", "content": "Hello there." },
|
| 1669 |
+
* { "role": "assistant", "content": "Hi, I'm Claude. How can I help you?" },
|
| 1670 |
+
* { "role": "user", "content": "Can you explain LLMs in plain English?" }
|
| 1671 |
+
* ]
|
| 1672 |
+
* ```
|
| 1673 |
+
*
|
| 1674 |
+
* Example with a partially-filled response from Claude:
|
| 1675 |
+
*
|
| 1676 |
+
* ```json
|
| 1677 |
+
* [
|
| 1678 |
+
* {
|
| 1679 |
+
* "role": "user",
|
| 1680 |
+
* "content": "What's the Greek name for Sun? (A) Sol (B) Helios (C) Sun"
|
| 1681 |
+
* },
|
| 1682 |
+
* { "role": "assistant", "content": "The best answer is (" }
|
| 1683 |
+
* ]
|
| 1684 |
+
* ```
|
| 1685 |
+
*
|
| 1686 |
+
* Each input message `content` may be either a single `string` or an array of
|
| 1687 |
+
* content blocks, where each block has a specific `type`. Using a `string` for
|
| 1688 |
+
* `content` is shorthand for an array of one content block of type `"text"`. The
|
| 1689 |
+
* following input messages are equivalent:
|
| 1690 |
+
*
|
| 1691 |
+
* ```json
|
| 1692 |
+
* { "role": "user", "content": "Hello, Claude" }
|
| 1693 |
+
* ```
|
| 1694 |
+
*
|
| 1695 |
+
* ```json
|
| 1696 |
+
* { "role": "user", "content": [{ "type": "text", "text": "Hello, Claude" }] }
|
| 1697 |
+
* ```
|
| 1698 |
+
*
|
| 1699 |
+
* Starting with Claude 3 models, you can also send image content blocks:
|
| 1700 |
+
*
|
| 1701 |
+
* ```json
|
| 1702 |
+
* {
|
| 1703 |
+
* "role": "user",
|
| 1704 |
+
* "content": [
|
| 1705 |
+
* {
|
| 1706 |
+
* "type": "image",
|
| 1707 |
+
* "source": {
|
| 1708 |
+
* "type": "base64",
|
| 1709 |
+
* "media_type": "image/jpeg",
|
| 1710 |
+
* "data": "/9j/4AAQSkZJRg..."
|
| 1711 |
+
* }
|
| 1712 |
+
* },
|
| 1713 |
+
* { "type": "text", "text": "What is in this image?" }
|
| 1714 |
+
* ]
|
| 1715 |
+
* }
|
| 1716 |
+
* ```
|
| 1717 |
+
*
|
| 1718 |
+
* We currently support the `base64` source type for images, and the `image/jpeg`,
|
| 1719 |
+
* `image/png`, `image/gif`, and `image/webp` media types.
|
| 1720 |
+
*
|
| 1721 |
+
* See [examples](https://docs.anthropic.com/en/api/messages-examples#vision) for
|
| 1722 |
+
* more input examples.
|
| 1723 |
+
*
|
| 1724 |
+
* Note that if you want to include a
|
| 1725 |
+
* [system prompt](https://docs.anthropic.com/en/docs/system-prompts), you can use
|
| 1726 |
+
* the top-level `system` parameter — there is no `"system"` role for input
|
| 1727 |
+
* messages in the Messages API.
|
| 1728 |
+
*
|
| 1729 |
+
* There is a limit of 100,000 messages in a single request.
|
| 1730 |
+
*/
|
| 1731 |
+
messages: Array<BetaMessageParam>;
|
| 1732 |
+
|
| 1733 |
+
/**
|
| 1734 |
+
* Body param: The model that will complete your prompt.\n\nSee
|
| 1735 |
+
* [models](https://docs.anthropic.com/en/docs/models-overview) for additional
|
| 1736 |
+
* details and options.
|
| 1737 |
+
*/
|
| 1738 |
+
model: MessagesAPI.Model;
|
| 1739 |
+
|
| 1740 |
+
/**
|
| 1741 |
+
* Body param: Container identifier for reuse across requests.
|
| 1742 |
+
*/
|
| 1743 |
+
container?: string | null;
|
| 1744 |
+
|
| 1745 |
+
/**
|
| 1746 |
+
* Body param: MCP servers to be utilized in this request
|
| 1747 |
+
*/
|
| 1748 |
+
mcp_servers?: Array<BetaRequestMCPServerURLDefinition>;
|
| 1749 |
+
|
| 1750 |
+
/**
|
| 1751 |
+
* Body param: An object describing metadata about the request.
|
| 1752 |
+
*/
|
| 1753 |
+
metadata?: BetaMetadata;
|
| 1754 |
+
|
| 1755 |
+
/**
|
| 1756 |
+
* Body param: Determines whether to use priority capacity (if available) or
|
| 1757 |
+
* standard capacity for this request.
|
| 1758 |
+
*
|
| 1759 |
+
* Anthropic offers different levels of service for your API requests. See
|
| 1760 |
+
* [service-tiers](https://docs.anthropic.com/en/api/service-tiers) for details.
|
| 1761 |
+
*/
|
| 1762 |
+
service_tier?: 'auto' | 'standard_only';
|
| 1763 |
+
|
| 1764 |
+
/**
|
| 1765 |
+
* Body param: Custom text sequences that will cause the model to stop generating.
|
| 1766 |
+
*
|
| 1767 |
+
* Our models will normally stop when they have naturally completed their turn,
|
| 1768 |
+
* which will result in a response `stop_reason` of `"end_turn"`.
|
| 1769 |
+
*
|
| 1770 |
+
* If you want the model to stop generating when it encounters custom strings of
|
| 1771 |
+
* text, you can use the `stop_sequences` parameter. If the model encounters one of
|
| 1772 |
+
* the custom sequences, the response `stop_reason` value will be `"stop_sequence"`
|
| 1773 |
+
* and the response `stop_sequence` value will contain the matched stop sequence.
|
| 1774 |
+
*/
|
| 1775 |
+
stop_sequences?: Array<string>;
|
| 1776 |
+
|
| 1777 |
+
/**
|
| 1778 |
+
* Body param: Whether to incrementally stream the response using server-sent
|
| 1779 |
+
* events.
|
| 1780 |
+
*
|
| 1781 |
+
* See [streaming](https://docs.anthropic.com/en/api/messages-streaming) for
|
| 1782 |
+
* details.
|
| 1783 |
+
*/
|
| 1784 |
+
stream?: boolean;
|
| 1785 |
+
|
| 1786 |
+
/**
|
| 1787 |
+
* Body param: System prompt.
|
| 1788 |
+
*
|
| 1789 |
+
* A system prompt is a way of providing context and instructions to Claude, such
|
| 1790 |
+
* as specifying a particular goal or role. See our
|
| 1791 |
+
* [guide to system prompts](https://docs.anthropic.com/en/docs/system-prompts).
|
| 1792 |
+
*/
|
| 1793 |
+
system?: string | Array<BetaTextBlockParam>;
|
| 1794 |
+
|
| 1795 |
+
/**
|
| 1796 |
+
* Body param: Amount of randomness injected into the response.
|
| 1797 |
+
*
|
| 1798 |
+
* Defaults to `1.0`. Ranges from `0.0` to `1.0`. Use `temperature` closer to `0.0`
|
| 1799 |
+
* for analytical / multiple choice, and closer to `1.0` for creative and
|
| 1800 |
+
* generative tasks.
|
| 1801 |
+
*
|
| 1802 |
+
* Note that even with `temperature` of `0.0`, the results will not be fully
|
| 1803 |
+
* deterministic.
|
| 1804 |
+
*/
|
| 1805 |
+
temperature?: number;
|
| 1806 |
+
|
| 1807 |
+
/**
|
| 1808 |
+
* Body param: Configuration for enabling Claude's extended thinking.
|
| 1809 |
+
*
|
| 1810 |
+
* When enabled, responses include `thinking` content blocks showing Claude's
|
| 1811 |
+
* thinking process before the final answer. Requires a minimum budget of 1,024
|
| 1812 |
+
* tokens and counts towards your `max_tokens` limit.
|
| 1813 |
+
*
|
| 1814 |
+
* See
|
| 1815 |
+
* [extended thinking](https://docs.anthropic.com/en/docs/build-with-claude/extended-thinking)
|
| 1816 |
+
* for details.
|
| 1817 |
+
*/
|
| 1818 |
+
thinking?: BetaThinkingConfigParam;
|
| 1819 |
+
|
| 1820 |
+
/**
|
| 1821 |
+
* Body param: How the model should use the provided tools. The model can use a
|
| 1822 |
+
* specific tool, any available tool, decide by itself, or not use tools at all.
|
| 1823 |
+
*/
|
| 1824 |
+
tool_choice?: BetaToolChoice;
|
| 1825 |
+
|
| 1826 |
+
/**
|
| 1827 |
+
* Body param: Definitions of tools that the model may use.
|
| 1828 |
+
*
|
| 1829 |
+
* If you include `tools` in your API request, the model may return `tool_use`
|
| 1830 |
+
* content blocks that represent the model's use of those tools. You can then run
|
| 1831 |
+
* those tools using the tool input generated by the model and then optionally
|
| 1832 |
+
* return results back to the model using `tool_result` content blocks.
|
| 1833 |
+
*
|
| 1834 |
+
* There are two types of tools: **client tools** and **server tools**. The
|
| 1835 |
+
* behavior described below applies to client tools. For
|
| 1836 |
+
* [server tools](https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/overview#server-tools),
|
| 1837 |
+
* see their individual documentation as each has its own behavior (e.g., the
|
| 1838 |
+
* [web search tool](https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/web-search-tool)).
|
| 1839 |
+
*
|
| 1840 |
+
* Each tool definition includes:
|
| 1841 |
+
*
|
| 1842 |
+
* - `name`: Name of the tool.
|
| 1843 |
+
* - `description`: Optional, but strongly-recommended description of the tool.
|
| 1844 |
+
* - `input_schema`: [JSON schema](https://json-schema.org/draft/2020-12) for the
|
| 1845 |
+
* tool `input` shape that the model will produce in `tool_use` output content
|
| 1846 |
+
* blocks.
|
| 1847 |
+
*
|
| 1848 |
+
* For example, if you defined `tools` as:
|
| 1849 |
+
*
|
| 1850 |
+
* ```json
|
| 1851 |
+
* [
|
| 1852 |
+
* {
|
| 1853 |
+
* "name": "get_stock_price",
|
| 1854 |
+
* "description": "Get the current stock price for a given ticker symbol.",
|
| 1855 |
+
* "input_schema": {
|
| 1856 |
+
* "type": "object",
|
| 1857 |
+
* "properties": {
|
| 1858 |
+
* "ticker": {
|
| 1859 |
+
* "type": "string",
|
| 1860 |
+
* "description": "The stock ticker symbol, e.g. AAPL for Apple Inc."
|
| 1861 |
+
* }
|
| 1862 |
+
* },
|
| 1863 |
+
* "required": ["ticker"]
|
| 1864 |
+
* }
|
| 1865 |
+
* }
|
| 1866 |
+
* ]
|
| 1867 |
+
* ```
|
| 1868 |
+
*
|
| 1869 |
+
* And then asked the model "What's the S&P 500 at today?", the model might produce
|
| 1870 |
+
* `tool_use` content blocks in the response like this:
|
| 1871 |
+
*
|
| 1872 |
+
* ```json
|
| 1873 |
+
* [
|
| 1874 |
+
* {
|
| 1875 |
+
* "type": "tool_use",
|
| 1876 |
+
* "id": "toolu_01D7FLrfh4GYq7yT1ULFeyMV",
|
| 1877 |
+
* "name": "get_stock_price",
|
| 1878 |
+
* "input": { "ticker": "^GSPC" }
|
| 1879 |
+
* }
|
| 1880 |
+
* ]
|
| 1881 |
+
* ```
|
| 1882 |
+
*
|
| 1883 |
+
* You might then run your `get_stock_price` tool with `{"ticker": "^GSPC"}` as an
|
| 1884 |
+
* input, and return the following back to the model in a subsequent `user`
|
| 1885 |
+
* message:
|
| 1886 |
+
*
|
| 1887 |
+
* ```json
|
| 1888 |
+
* [
|
| 1889 |
+
* {
|
| 1890 |
+
* "type": "tool_result",
|
| 1891 |
+
* "tool_use_id": "toolu_01D7FLrfh4GYq7yT1ULFeyMV",
|
| 1892 |
+
* "content": "259.75 USD"
|
| 1893 |
+
* }
|
| 1894 |
+
* ]
|
| 1895 |
+
* ```
|
| 1896 |
+
*
|
| 1897 |
+
* Tools can be used for workflows that include running client-side tools and
|
| 1898 |
+
* functions, or more generally whenever you want the model to produce a particular
|
| 1899 |
+
* JSON structure of output.
|
| 1900 |
+
*
|
| 1901 |
+
* See our [guide](https://docs.anthropic.com/en/docs/tool-use) for more details.
|
| 1902 |
+
*/
|
| 1903 |
+
tools?: Array<BetaToolUnion>;
|
| 1904 |
+
|
| 1905 |
+
/**
|
| 1906 |
+
* Body param: Only sample from the top K options for each subsequent token.
|
| 1907 |
+
*
|
| 1908 |
+
* Used to remove "long tail" low probability responses.
|
| 1909 |
+
* [Learn more technical details here](https://towardsdatascience.com/how-to-sample-from-language-models-682bceb97277).
|
| 1910 |
+
*
|
| 1911 |
+
* Recommended for advanced use cases only. You usually only need to use
|
| 1912 |
+
* `temperature`.
|
| 1913 |
+
*/
|
| 1914 |
+
top_k?: number;
|
| 1915 |
+
|
| 1916 |
+
/**
|
| 1917 |
+
* Body param: Use nucleus sampling.
|
| 1918 |
+
*
|
| 1919 |
+
* In nucleus sampling, we compute the cumulative distribution over all the options
|
| 1920 |
+
* for each subsequent token in decreasing probability order and cut it off once it
|
| 1921 |
+
* reaches a particular probability specified by `top_p`. You should either alter
|
| 1922 |
+
* `temperature` or `top_p`, but not both.
|
| 1923 |
+
*
|
| 1924 |
+
* Recommended for advanced use cases only. You usually only need to use
|
| 1925 |
+
* `temperature`.
|
| 1926 |
+
*/
|
| 1927 |
+
top_p?: number;
|
| 1928 |
+
|
| 1929 |
+
/**
|
| 1930 |
+
* Header param: Optional header to specify the beta version(s) you want to use.
|
| 1931 |
+
*/
|
| 1932 |
+
betas?: Array<BetaAPI.AnthropicBeta>;
|
| 1933 |
+
}
|
| 1934 |
+
|
| 1935 |
+
export namespace MessageCreateParams {
|
| 1936 |
+
export type MessageCreateParamsNonStreaming = MessagesMessagesAPI.MessageCreateParamsNonStreaming;
|
| 1937 |
+
export type MessageCreateParamsStreaming = MessagesMessagesAPI.MessageCreateParamsStreaming;
|
| 1938 |
+
}
|
| 1939 |
+
|
| 1940 |
+
export interface MessageCreateParamsNonStreaming extends MessageCreateParamsBase {
|
| 1941 |
+
/**
|
| 1942 |
+
* Body param: Whether to incrementally stream the response using server-sent
|
| 1943 |
+
* events.
|
| 1944 |
+
*
|
| 1945 |
+
* See [streaming](https://docs.anthropic.com/en/api/messages-streaming) for
|
| 1946 |
+
* details.
|
| 1947 |
+
*/
|
| 1948 |
+
stream?: false;
|
| 1949 |
+
}
|
| 1950 |
+
|
| 1951 |
+
export interface MessageCreateParamsStreaming extends MessageCreateParamsBase {
|
| 1952 |
+
/**
|
| 1953 |
+
* Body param: Whether to incrementally stream the response using server-sent
|
| 1954 |
+
* events.
|
| 1955 |
+
*
|
| 1956 |
+
* See [streaming](https://docs.anthropic.com/en/api/messages-streaming) for
|
| 1957 |
+
* details.
|
| 1958 |
+
*/
|
| 1959 |
+
stream: true;
|
| 1960 |
+
}
|
| 1961 |
+
|
| 1962 |
+
export interface MessageCountTokensParams {
|
| 1963 |
+
/**
|
| 1964 |
+
* Body param: Input messages.
|
| 1965 |
+
*
|
| 1966 |
+
* Our models are trained to operate on alternating `user` and `assistant`
|
| 1967 |
+
* conversational turns. When creating a new `Message`, you specify the prior
|
| 1968 |
+
* conversational turns with the `messages` parameter, and the model then generates
|
| 1969 |
+
* the next `Message` in the conversation. Consecutive `user` or `assistant` turns
|
| 1970 |
+
* in your request will be combined into a single turn.
|
| 1971 |
+
*
|
| 1972 |
+
* Each input message must be an object with a `role` and `content`. You can
|
| 1973 |
+
* specify a single `user`-role message, or you can include multiple `user` and
|
| 1974 |
+
* `assistant` messages.
|
| 1975 |
+
*
|
| 1976 |
+
* If the final message uses the `assistant` role, the response content will
|
| 1977 |
+
* continue immediately from the content in that message. This can be used to
|
| 1978 |
+
* constrain part of the model's response.
|
| 1979 |
+
*
|
| 1980 |
+
* Example with a single `user` message:
|
| 1981 |
+
*
|
| 1982 |
+
* ```json
|
| 1983 |
+
* [{ "role": "user", "content": "Hello, Claude" }]
|
| 1984 |
+
* ```
|
| 1985 |
+
*
|
| 1986 |
+
* Example with multiple conversational turns:
|
| 1987 |
+
*
|
| 1988 |
+
* ```json
|
| 1989 |
+
* [
|
| 1990 |
+
* { "role": "user", "content": "Hello there." },
|
| 1991 |
+
* { "role": "assistant", "content": "Hi, I'm Claude. How can I help you?" },
|
| 1992 |
+
* { "role": "user", "content": "Can you explain LLMs in plain English?" }
|
| 1993 |
+
* ]
|
| 1994 |
+
* ```
|
| 1995 |
+
*
|
| 1996 |
+
* Example with a partially-filled response from Claude:
|
| 1997 |
+
*
|
| 1998 |
+
* ```json
|
| 1999 |
+
* [
|
| 2000 |
+
* {
|
| 2001 |
+
* "role": "user",
|
| 2002 |
+
* "content": "What's the Greek name for Sun? (A) Sol (B) Helios (C) Sun"
|
| 2003 |
+
* },
|
| 2004 |
+
* { "role": "assistant", "content": "The best answer is (" }
|
| 2005 |
+
* ]
|
| 2006 |
+
* ```
|
| 2007 |
+
*
|
| 2008 |
+
* Each input message `content` may be either a single `string` or an array of
|
| 2009 |
+
* content blocks, where each block has a specific `type`. Using a `string` for
|
| 2010 |
+
* `content` is shorthand for an array of one content block of type `"text"`. The
|
| 2011 |
+
* following input messages are equivalent:
|
| 2012 |
+
*
|
| 2013 |
+
* ```json
|
| 2014 |
+
* { "role": "user", "content": "Hello, Claude" }
|
| 2015 |
+
* ```
|
| 2016 |
+
*
|
| 2017 |
+
* ```json
|
| 2018 |
+
* { "role": "user", "content": [{ "type": "text", "text": "Hello, Claude" }] }
|
| 2019 |
+
* ```
|
| 2020 |
+
*
|
| 2021 |
+
* Starting with Claude 3 models, you can also send image content blocks:
|
| 2022 |
+
*
|
| 2023 |
+
* ```json
|
| 2024 |
+
* {
|
| 2025 |
+
* "role": "user",
|
| 2026 |
+
* "content": [
|
| 2027 |
+
* {
|
| 2028 |
+
* "type": "image",
|
| 2029 |
+
* "source": {
|
| 2030 |
+
* "type": "base64",
|
| 2031 |
+
* "media_type": "image/jpeg",
|
| 2032 |
+
* "data": "/9j/4AAQSkZJRg..."
|
| 2033 |
+
* }
|
| 2034 |
+
* },
|
| 2035 |
+
* { "type": "text", "text": "What is in this image?" }
|
| 2036 |
+
* ]
|
| 2037 |
+
* }
|
| 2038 |
+
* ```
|
| 2039 |
+
*
|
| 2040 |
+
* We currently support the `base64` source type for images, and the `image/jpeg`,
|
| 2041 |
+
* `image/png`, `image/gif`, and `image/webp` media types.
|
| 2042 |
+
*
|
| 2043 |
+
* See [examples](https://docs.anthropic.com/en/api/messages-examples#vision) for
|
| 2044 |
+
* more input examples.
|
| 2045 |
+
*
|
| 2046 |
+
* Note that if you want to include a
|
| 2047 |
+
* [system prompt](https://docs.anthropic.com/en/docs/system-prompts), you can use
|
| 2048 |
+
* the top-level `system` parameter — there is no `"system"` role for input
|
| 2049 |
+
* messages in the Messages API.
|
| 2050 |
+
*
|
| 2051 |
+
* There is a limit of 100,000 messages in a single request.
|
| 2052 |
+
*/
|
| 2053 |
+
messages: Array<BetaMessageParam>;
|
| 2054 |
+
|
| 2055 |
+
/**
|
| 2056 |
+
* Body param: The model that will complete your prompt.\n\nSee
|
| 2057 |
+
* [models](https://docs.anthropic.com/en/docs/models-overview) for additional
|
| 2058 |
+
* details and options.
|
| 2059 |
+
*/
|
| 2060 |
+
model: MessagesAPI.Model;
|
| 2061 |
+
|
| 2062 |
+
/**
|
| 2063 |
+
* Body param: MCP servers to be utilized in this request
|
| 2064 |
+
*/
|
| 2065 |
+
mcp_servers?: Array<BetaRequestMCPServerURLDefinition>;
|
| 2066 |
+
|
| 2067 |
+
/**
|
| 2068 |
+
* Body param: System prompt.
|
| 2069 |
+
*
|
| 2070 |
+
* A system prompt is a way of providing context and instructions to Claude, such
|
| 2071 |
+
* as specifying a particular goal or role. See our
|
| 2072 |
+
* [guide to system prompts](https://docs.anthropic.com/en/docs/system-prompts).
|
| 2073 |
+
*/
|
| 2074 |
+
system?: string | Array<BetaTextBlockParam>;
|
| 2075 |
+
|
| 2076 |
+
/**
|
| 2077 |
+
* Body param: Configuration for enabling Claude's extended thinking.
|
| 2078 |
+
*
|
| 2079 |
+
* When enabled, responses include `thinking` content blocks showing Claude's
|
| 2080 |
+
* thinking process before the final answer. Requires a minimum budget of 1,024
|
| 2081 |
+
* tokens and counts towards your `max_tokens` limit.
|
| 2082 |
+
*
|
| 2083 |
+
* See
|
| 2084 |
+
* [extended thinking](https://docs.anthropic.com/en/docs/build-with-claude/extended-thinking)
|
| 2085 |
+
* for details.
|
| 2086 |
+
*/
|
| 2087 |
+
thinking?: BetaThinkingConfigParam;
|
| 2088 |
+
|
| 2089 |
+
/**
|
| 2090 |
+
* Body param: How the model should use the provided tools. The model can use a
|
| 2091 |
+
* specific tool, any available tool, decide by itself, or not use tools at all.
|
| 2092 |
+
*/
|
| 2093 |
+
tool_choice?: BetaToolChoice;
|
| 2094 |
+
|
| 2095 |
+
/**
|
| 2096 |
+
* Body param: Definitions of tools that the model may use.
|
| 2097 |
+
*
|
| 2098 |
+
* If you include `tools` in your API request, the model may return `tool_use`
|
| 2099 |
+
* content blocks that represent the model's use of those tools. You can then run
|
| 2100 |
+
* those tools using the tool input generated by the model and then optionally
|
| 2101 |
+
* return results back to the model using `tool_result` content blocks.
|
| 2102 |
+
*
|
| 2103 |
+
* There are two types of tools: **client tools** and **server tools**. The
|
| 2104 |
+
* behavior described below applies to client tools. For
|
| 2105 |
+
* [server tools](https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/overview#server-tools),
|
| 2106 |
+
* see their individual documentation as each has its own behavior (e.g., the
|
| 2107 |
+
* [web search tool](https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/web-search-tool)).
|
| 2108 |
+
*
|
| 2109 |
+
* Each tool definition includes:
|
| 2110 |
+
*
|
| 2111 |
+
* - `name`: Name of the tool.
|
| 2112 |
+
* - `description`: Optional, but strongly-recommended description of the tool.
|
| 2113 |
+
* - `input_schema`: [JSON schema](https://json-schema.org/draft/2020-12) for the
|
| 2114 |
+
* tool `input` shape that the model will produce in `tool_use` output content
|
| 2115 |
+
* blocks.
|
| 2116 |
+
*
|
| 2117 |
+
* For example, if you defined `tools` as:
|
| 2118 |
+
*
|
| 2119 |
+
* ```json
|
| 2120 |
+
* [
|
| 2121 |
+
* {
|
| 2122 |
+
* "name": "get_stock_price",
|
| 2123 |
+
* "description": "Get the current stock price for a given ticker symbol.",
|
| 2124 |
+
* "input_schema": {
|
| 2125 |
+
* "type": "object",
|
| 2126 |
+
* "properties": {
|
| 2127 |
+
* "ticker": {
|
| 2128 |
+
* "type": "string",
|
| 2129 |
+
* "description": "The stock ticker symbol, e.g. AAPL for Apple Inc."
|
| 2130 |
+
* }
|
| 2131 |
+
* },
|
| 2132 |
+
* "required": ["ticker"]
|
| 2133 |
+
* }
|
| 2134 |
+
* }
|
| 2135 |
+
* ]
|
| 2136 |
+
* ```
|
| 2137 |
+
*
|
| 2138 |
+
* And then asked the model "What's the S&P 500 at today?", the model might produce
|
| 2139 |
+
* `tool_use` content blocks in the response like this:
|
| 2140 |
+
*
|
| 2141 |
+
* ```json
|
| 2142 |
+
* [
|
| 2143 |
+
* {
|
| 2144 |
+
* "type": "tool_use",
|
| 2145 |
+
* "id": "toolu_01D7FLrfh4GYq7yT1ULFeyMV",
|
| 2146 |
+
* "name": "get_stock_price",
|
| 2147 |
+
* "input": { "ticker": "^GSPC" }
|
| 2148 |
+
* }
|
| 2149 |
+
* ]
|
| 2150 |
+
* ```
|
| 2151 |
+
*
|
| 2152 |
+
* You might then run your `get_stock_price` tool with `{"ticker": "^GSPC"}` as an
|
| 2153 |
+
* input, and return the following back to the model in a subsequent `user`
|
| 2154 |
+
* message:
|
| 2155 |
+
*
|
| 2156 |
+
* ```json
|
| 2157 |
+
* [
|
| 2158 |
+
* {
|
| 2159 |
+
* "type": "tool_result",
|
| 2160 |
+
* "tool_use_id": "toolu_01D7FLrfh4GYq7yT1ULFeyMV",
|
| 2161 |
+
* "content": "259.75 USD"
|
| 2162 |
+
* }
|
| 2163 |
+
* ]
|
| 2164 |
+
* ```
|
| 2165 |
+
*
|
| 2166 |
+
* Tools can be used for workflows that include running client-side tools and
|
| 2167 |
+
* functions, or more generally whenever you want the model to produce a particular
|
| 2168 |
+
* JSON structure of output.
|
| 2169 |
+
*
|
| 2170 |
+
* See our [guide](https://docs.anthropic.com/en/docs/tool-use) for more details.
|
| 2171 |
+
*/
|
| 2172 |
+
tools?: Array<
|
| 2173 |
+
| BetaTool
|
| 2174 |
+
| BetaToolBash20241022
|
| 2175 |
+
| BetaToolBash20250124
|
| 2176 |
+
| BetaCodeExecutionTool20250522
|
| 2177 |
+
| BetaToolComputerUse20241022
|
| 2178 |
+
| BetaToolComputerUse20250124
|
| 2179 |
+
| BetaToolTextEditor20241022
|
| 2180 |
+
| BetaToolTextEditor20250124
|
| 2181 |
+
| BetaToolTextEditor20250429
|
| 2182 |
+
| BetaWebSearchTool20250305
|
| 2183 |
+
>;
|
| 2184 |
+
|
| 2185 |
+
/**
|
| 2186 |
+
* Header param: Optional header to specify the beta version(s) you want to use.
|
| 2187 |
+
*/
|
| 2188 |
+
betas?: Array<BetaAPI.AnthropicBeta>;
|
| 2189 |
+
}
|
| 2190 |
+
|
| 2191 |
+
Messages.Batches = Batches;
|
| 2192 |
+
|
| 2193 |
+
export declare namespace Messages {
|
| 2194 |
+
export {
|
| 2195 |
+
type BetaBase64ImageSource as BetaBase64ImageSource,
|
| 2196 |
+
type BetaBase64PDFSource as BetaBase64PDFSource,
|
| 2197 |
+
type BetaCacheControlEphemeral as BetaCacheControlEphemeral,
|
| 2198 |
+
type BetaCacheCreation as BetaCacheCreation,
|
| 2199 |
+
type BetaCitationCharLocation as BetaCitationCharLocation,
|
| 2200 |
+
type BetaCitationCharLocationParam as BetaCitationCharLocationParam,
|
| 2201 |
+
type BetaCitationContentBlockLocation as BetaCitationContentBlockLocation,
|
| 2202 |
+
type BetaCitationContentBlockLocationParam as BetaCitationContentBlockLocationParam,
|
| 2203 |
+
type BetaCitationPageLocation as BetaCitationPageLocation,
|
| 2204 |
+
type BetaCitationPageLocationParam as BetaCitationPageLocationParam,
|
| 2205 |
+
type BetaCitationSearchResultLocation as BetaCitationSearchResultLocation,
|
| 2206 |
+
type BetaCitationSearchResultLocationParam as BetaCitationSearchResultLocationParam,
|
| 2207 |
+
type BetaCitationWebSearchResultLocationParam as BetaCitationWebSearchResultLocationParam,
|
| 2208 |
+
type BetaCitationsConfigParam as BetaCitationsConfigParam,
|
| 2209 |
+
type BetaCitationsDelta as BetaCitationsDelta,
|
| 2210 |
+
type BetaCitationsWebSearchResultLocation as BetaCitationsWebSearchResultLocation,
|
| 2211 |
+
type BetaCodeExecutionOutputBlock as BetaCodeExecutionOutputBlock,
|
| 2212 |
+
type BetaCodeExecutionOutputBlockParam as BetaCodeExecutionOutputBlockParam,
|
| 2213 |
+
type BetaCodeExecutionResultBlock as BetaCodeExecutionResultBlock,
|
| 2214 |
+
type BetaCodeExecutionResultBlockParam as BetaCodeExecutionResultBlockParam,
|
| 2215 |
+
type BetaCodeExecutionTool20250522 as BetaCodeExecutionTool20250522,
|
| 2216 |
+
type BetaCodeExecutionToolResultBlock as BetaCodeExecutionToolResultBlock,
|
| 2217 |
+
type BetaCodeExecutionToolResultBlockContent as BetaCodeExecutionToolResultBlockContent,
|
| 2218 |
+
type BetaCodeExecutionToolResultBlockParam as BetaCodeExecutionToolResultBlockParam,
|
| 2219 |
+
type BetaCodeExecutionToolResultBlockParamContent as BetaCodeExecutionToolResultBlockParamContent,
|
| 2220 |
+
type BetaCodeExecutionToolResultError as BetaCodeExecutionToolResultError,
|
| 2221 |
+
type BetaCodeExecutionToolResultErrorCode as BetaCodeExecutionToolResultErrorCode,
|
| 2222 |
+
type BetaCodeExecutionToolResultErrorParam as BetaCodeExecutionToolResultErrorParam,
|
| 2223 |
+
type BetaContainer as BetaContainer,
|
| 2224 |
+
type BetaContainerUploadBlock as BetaContainerUploadBlock,
|
| 2225 |
+
type BetaContainerUploadBlockParam as BetaContainerUploadBlockParam,
|
| 2226 |
+
type BetaContentBlock as BetaContentBlock,
|
| 2227 |
+
type BetaContentBlockParam as BetaContentBlockParam,
|
| 2228 |
+
type BetaContentBlockSource as BetaContentBlockSource,
|
| 2229 |
+
type BetaContentBlockSourceContent as BetaContentBlockSourceContent,
|
| 2230 |
+
type BetaFileDocumentSource as BetaFileDocumentSource,
|
| 2231 |
+
type BetaFileImageSource as BetaFileImageSource,
|
| 2232 |
+
type BetaImageBlockParam as BetaImageBlockParam,
|
| 2233 |
+
type BetaInputJSONDelta as BetaInputJSONDelta,
|
| 2234 |
+
type BetaMCPToolResultBlock as BetaMCPToolResultBlock,
|
| 2235 |
+
type BetaMCPToolUseBlock as BetaMCPToolUseBlock,
|
| 2236 |
+
type BetaMCPToolUseBlockParam as BetaMCPToolUseBlockParam,
|
| 2237 |
+
type BetaMessage as BetaMessage,
|
| 2238 |
+
type BetaMessageDeltaUsage as BetaMessageDeltaUsage,
|
| 2239 |
+
type BetaMessageParam as BetaMessageParam,
|
| 2240 |
+
type BetaMessageTokensCount as BetaMessageTokensCount,
|
| 2241 |
+
type BetaMetadata as BetaMetadata,
|
| 2242 |
+
type BetaPlainTextSource as BetaPlainTextSource,
|
| 2243 |
+
type BetaRawContentBlockDelta as BetaRawContentBlockDelta,
|
| 2244 |
+
type BetaRawContentBlockDeltaEvent as BetaRawContentBlockDeltaEvent,
|
| 2245 |
+
type BetaRawContentBlockStartEvent as BetaRawContentBlockStartEvent,
|
| 2246 |
+
type BetaRawContentBlockStopEvent as BetaRawContentBlockStopEvent,
|
| 2247 |
+
type BetaRawMessageDeltaEvent as BetaRawMessageDeltaEvent,
|
| 2248 |
+
type BetaRawMessageStartEvent as BetaRawMessageStartEvent,
|
| 2249 |
+
type BetaRawMessageStopEvent as BetaRawMessageStopEvent,
|
| 2250 |
+
type BetaRawMessageStreamEvent as BetaRawMessageStreamEvent,
|
| 2251 |
+
type BetaRedactedThinkingBlock as BetaRedactedThinkingBlock,
|
| 2252 |
+
type BetaRedactedThinkingBlockParam as BetaRedactedThinkingBlockParam,
|
| 2253 |
+
type BetaRequestDocumentBlock as BetaRequestDocumentBlock,
|
| 2254 |
+
type BetaRequestMCPServerToolConfiguration as BetaRequestMCPServerToolConfiguration,
|
| 2255 |
+
type BetaRequestMCPServerURLDefinition as BetaRequestMCPServerURLDefinition,
|
| 2256 |
+
type BetaRequestMCPToolResultBlockParam as BetaRequestMCPToolResultBlockParam,
|
| 2257 |
+
type BetaSearchResultBlockParam as BetaSearchResultBlockParam,
|
| 2258 |
+
type BetaServerToolUsage as BetaServerToolUsage,
|
| 2259 |
+
type BetaServerToolUseBlock as BetaServerToolUseBlock,
|
| 2260 |
+
type BetaServerToolUseBlockParam as BetaServerToolUseBlockParam,
|
| 2261 |
+
type BetaSignatureDelta as BetaSignatureDelta,
|
| 2262 |
+
type BetaStopReason as BetaStopReason,
|
| 2263 |
+
type BetaTextBlock as BetaTextBlock,
|
| 2264 |
+
type BetaTextBlockParam as BetaTextBlockParam,
|
| 2265 |
+
type BetaTextCitation as BetaTextCitation,
|
| 2266 |
+
type BetaTextCitationParam as BetaTextCitationParam,
|
| 2267 |
+
type BetaTextDelta as BetaTextDelta,
|
| 2268 |
+
type BetaThinkingBlock as BetaThinkingBlock,
|
| 2269 |
+
type BetaThinkingBlockParam as BetaThinkingBlockParam,
|
| 2270 |
+
type BetaThinkingConfigDisabled as BetaThinkingConfigDisabled,
|
| 2271 |
+
type BetaThinkingConfigEnabled as BetaThinkingConfigEnabled,
|
| 2272 |
+
type BetaThinkingConfigParam as BetaThinkingConfigParam,
|
| 2273 |
+
type BetaThinkingDelta as BetaThinkingDelta,
|
| 2274 |
+
type BetaTool as BetaTool,
|
| 2275 |
+
type BetaToolBash20241022 as BetaToolBash20241022,
|
| 2276 |
+
type BetaToolBash20250124 as BetaToolBash20250124,
|
| 2277 |
+
type BetaToolChoice as BetaToolChoice,
|
| 2278 |
+
type BetaToolChoiceAny as BetaToolChoiceAny,
|
| 2279 |
+
type BetaToolChoiceAuto as BetaToolChoiceAuto,
|
| 2280 |
+
type BetaToolChoiceNone as BetaToolChoiceNone,
|
| 2281 |
+
type BetaToolChoiceTool as BetaToolChoiceTool,
|
| 2282 |
+
type BetaToolComputerUse20241022 as BetaToolComputerUse20241022,
|
| 2283 |
+
type BetaToolComputerUse20250124 as BetaToolComputerUse20250124,
|
| 2284 |
+
type BetaToolResultBlockParam as BetaToolResultBlockParam,
|
| 2285 |
+
type BetaToolTextEditor20241022 as BetaToolTextEditor20241022,
|
| 2286 |
+
type BetaToolTextEditor20250124 as BetaToolTextEditor20250124,
|
| 2287 |
+
type BetaToolTextEditor20250429 as BetaToolTextEditor20250429,
|
| 2288 |
+
type BetaToolUnion as BetaToolUnion,
|
| 2289 |
+
type BetaToolUseBlock as BetaToolUseBlock,
|
| 2290 |
+
type BetaToolUseBlockParam as BetaToolUseBlockParam,
|
| 2291 |
+
type BetaURLImageSource as BetaURLImageSource,
|
| 2292 |
+
type BetaURLPDFSource as BetaURLPDFSource,
|
| 2293 |
+
type BetaUsage as BetaUsage,
|
| 2294 |
+
type BetaWebSearchResultBlock as BetaWebSearchResultBlock,
|
| 2295 |
+
type BetaWebSearchResultBlockParam as BetaWebSearchResultBlockParam,
|
| 2296 |
+
type BetaWebSearchTool20250305 as BetaWebSearchTool20250305,
|
| 2297 |
+
type BetaWebSearchToolRequestError as BetaWebSearchToolRequestError,
|
| 2298 |
+
type BetaWebSearchToolResultBlock as BetaWebSearchToolResultBlock,
|
| 2299 |
+
type BetaWebSearchToolResultBlockContent as BetaWebSearchToolResultBlockContent,
|
| 2300 |
+
type BetaWebSearchToolResultBlockParam as BetaWebSearchToolResultBlockParam,
|
| 2301 |
+
type BetaWebSearchToolResultBlockParamContent as BetaWebSearchToolResultBlockParamContent,
|
| 2302 |
+
type BetaWebSearchToolResultError as BetaWebSearchToolResultError,
|
| 2303 |
+
type BetaWebSearchToolResultErrorCode as BetaWebSearchToolResultErrorCode,
|
| 2304 |
+
type BetaBase64PDFBlock as BetaBase64PDFBlock,
|
| 2305 |
+
type MessageCreateParams as MessageCreateParams,
|
| 2306 |
+
type MessageCreateParamsNonStreaming as MessageCreateParamsNonStreaming,
|
| 2307 |
+
type MessageCreateParamsStreaming as MessageCreateParamsStreaming,
|
| 2308 |
+
type MessageCountTokensParams as MessageCountTokensParams,
|
| 2309 |
+
};
|
| 2310 |
+
|
| 2311 |
+
export {
|
| 2312 |
+
Batches as Batches,
|
| 2313 |
+
type BetaDeletedMessageBatch as BetaDeletedMessageBatch,
|
| 2314 |
+
type BetaMessageBatch as BetaMessageBatch,
|
| 2315 |
+
type BetaMessageBatchCanceledResult as BetaMessageBatchCanceledResult,
|
| 2316 |
+
type BetaMessageBatchErroredResult as BetaMessageBatchErroredResult,
|
| 2317 |
+
type BetaMessageBatchExpiredResult as BetaMessageBatchExpiredResult,
|
| 2318 |
+
type BetaMessageBatchIndividualResponse as BetaMessageBatchIndividualResponse,
|
| 2319 |
+
type BetaMessageBatchRequestCounts as BetaMessageBatchRequestCounts,
|
| 2320 |
+
type BetaMessageBatchResult as BetaMessageBatchResult,
|
| 2321 |
+
type BetaMessageBatchSucceededResult as BetaMessageBatchSucceededResult,
|
| 2322 |
+
type BetaMessageBatchesPage as BetaMessageBatchesPage,
|
| 2323 |
+
type BatchCreateParams as BatchCreateParams,
|
| 2324 |
+
type BatchRetrieveParams as BatchRetrieveParams,
|
| 2325 |
+
type BatchListParams as BatchListParams,
|
| 2326 |
+
type BatchDeleteParams as BatchDeleteParams,
|
| 2327 |
+
type BatchCancelParams as BatchCancelParams,
|
| 2328 |
+
type BatchResultsParams as BatchResultsParams,
|
| 2329 |
+
};
|
| 2330 |
+
}
|
node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/resources/beta/models.ts
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
| 2 |
+
|
| 3 |
+
import { APIResource } from '../../core/resource';
|
| 4 |
+
import * as BetaAPI from './beta';
|
| 5 |
+
import { APIPromise } from '../../core/api-promise';
|
| 6 |
+
import { Page, type PageParams, PagePromise } from '../../core/pagination';
|
| 7 |
+
import { buildHeaders } from '../../internal/headers';
|
| 8 |
+
import { RequestOptions } from '../../internal/request-options';
|
| 9 |
+
import { path } from '../../internal/utils/path';
|
| 10 |
+
|
| 11 |
+
export class Models extends APIResource {
|
| 12 |
+
/**
|
| 13 |
+
* Get a specific model.
|
| 14 |
+
*
|
| 15 |
+
* The Models API response can be used to determine information about a specific
|
| 16 |
+
* model or resolve a model alias to a model ID.
|
| 17 |
+
*
|
| 18 |
+
* @example
|
| 19 |
+
* ```ts
|
| 20 |
+
* const betaModelInfo = await client.beta.models.retrieve(
|
| 21 |
+
* 'model_id',
|
| 22 |
+
* );
|
| 23 |
+
* ```
|
| 24 |
+
*/
|
| 25 |
+
retrieve(
|
| 26 |
+
modelID: string,
|
| 27 |
+
params: ModelRetrieveParams | null | undefined = {},
|
| 28 |
+
options?: RequestOptions,
|
| 29 |
+
): APIPromise<BetaModelInfo> {
|
| 30 |
+
const { betas } = params ?? {};
|
| 31 |
+
return this._client.get(path`/v1/models/${modelID}?beta=true`, {
|
| 32 |
+
...options,
|
| 33 |
+
headers: buildHeaders([
|
| 34 |
+
{ ...(betas?.toString() != null ? { 'anthropic-beta': betas?.toString() } : undefined) },
|
| 35 |
+
options?.headers,
|
| 36 |
+
]),
|
| 37 |
+
});
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
/**
|
| 41 |
+
* List available models.
|
| 42 |
+
*
|
| 43 |
+
* The Models API response can be used to determine which models are available for
|
| 44 |
+
* use in the API. More recently released models are listed first.
|
| 45 |
+
*
|
| 46 |
+
* @example
|
| 47 |
+
* ```ts
|
| 48 |
+
* // Automatically fetches more pages as needed.
|
| 49 |
+
* for await (const betaModelInfo of client.beta.models.list()) {
|
| 50 |
+
* // ...
|
| 51 |
+
* }
|
| 52 |
+
* ```
|
| 53 |
+
*/
|
| 54 |
+
list(
|
| 55 |
+
params: ModelListParams | null | undefined = {},
|
| 56 |
+
options?: RequestOptions,
|
| 57 |
+
): PagePromise<BetaModelInfosPage, BetaModelInfo> {
|
| 58 |
+
const { betas, ...query } = params ?? {};
|
| 59 |
+
return this._client.getAPIList('/v1/models?beta=true', Page<BetaModelInfo>, {
|
| 60 |
+
query,
|
| 61 |
+
...options,
|
| 62 |
+
headers: buildHeaders([
|
| 63 |
+
{ ...(betas?.toString() != null ? { 'anthropic-beta': betas?.toString() } : undefined) },
|
| 64 |
+
options?.headers,
|
| 65 |
+
]),
|
| 66 |
+
});
|
| 67 |
+
}
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
export type BetaModelInfosPage = Page<BetaModelInfo>;
|
| 71 |
+
|
| 72 |
+
export interface BetaModelInfo {
|
| 73 |
+
/**
|
| 74 |
+
* Unique model identifier.
|
| 75 |
+
*/
|
| 76 |
+
id: string;
|
| 77 |
+
|
| 78 |
+
/**
|
| 79 |
+
* RFC 3339 datetime string representing the time at which the model was released.
|
| 80 |
+
* May be set to an epoch value if the release date is unknown.
|
| 81 |
+
*/
|
| 82 |
+
created_at: string;
|
| 83 |
+
|
| 84 |
+
/**
|
| 85 |
+
* A human-readable name for the model.
|
| 86 |
+
*/
|
| 87 |
+
display_name: string;
|
| 88 |
+
|
| 89 |
+
/**
|
| 90 |
+
* Object type.
|
| 91 |
+
*
|
| 92 |
+
* For Models, this is always `"model"`.
|
| 93 |
+
*/
|
| 94 |
+
type: 'model';
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
export interface ModelRetrieveParams {
|
| 98 |
+
/**
|
| 99 |
+
* Optional header to specify the beta version(s) you want to use.
|
| 100 |
+
*/
|
| 101 |
+
betas?: Array<BetaAPI.AnthropicBeta>;
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
export interface ModelListParams extends PageParams {
|
| 105 |
+
/**
|
| 106 |
+
* Header param: Optional header to specify the beta version(s) you want to use.
|
| 107 |
+
*/
|
| 108 |
+
betas?: Array<BetaAPI.AnthropicBeta>;
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
export declare namespace Models {
|
| 112 |
+
export {
|
| 113 |
+
type BetaModelInfo as BetaModelInfo,
|
| 114 |
+
type BetaModelInfosPage as BetaModelInfosPage,
|
| 115 |
+
type ModelRetrieveParams as ModelRetrieveParams,
|
| 116 |
+
type ModelListParams as ModelListParams,
|
| 117 |
+
};
|
| 118 |
+
}
|
node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/resources/completions.ts
ADDED
|
@@ -0,0 +1,231 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
| 2 |
+
|
| 3 |
+
import { APIResource } from '../core/resource';
|
| 4 |
+
import * as CompletionsAPI from './completions';
|
| 5 |
+
import * as BetaAPI from './beta/beta';
|
| 6 |
+
import * as MessagesAPI from './messages/messages';
|
| 7 |
+
import { APIPromise } from '../core/api-promise';
|
| 8 |
+
import { Stream } from '../core/streaming';
|
| 9 |
+
import { buildHeaders } from '../internal/headers';
|
| 10 |
+
import { RequestOptions } from '../internal/request-options';
|
| 11 |
+
|
| 12 |
+
export class Completions extends APIResource {
|
| 13 |
+
/**
|
| 14 |
+
* [Legacy] Create a Text Completion.
|
| 15 |
+
*
|
| 16 |
+
* The Text Completions API is a legacy API. We recommend using the
|
| 17 |
+
* [Messages API](https://docs.anthropic.com/en/api/messages) going forward.
|
| 18 |
+
*
|
| 19 |
+
* Future models and features will not be compatible with Text Completions. See our
|
| 20 |
+
* [migration guide](https://docs.anthropic.com/en/api/migrating-from-text-completions-to-messages)
|
| 21 |
+
* for guidance in migrating from Text Completions to Messages.
|
| 22 |
+
*
|
| 23 |
+
* @example
|
| 24 |
+
* ```ts
|
| 25 |
+
* const completion = await client.completions.create({
|
| 26 |
+
* max_tokens_to_sample: 256,
|
| 27 |
+
* model: 'claude-3-7-sonnet-latest',
|
| 28 |
+
* prompt: '\n\nHuman: Hello, world!\n\nAssistant:',
|
| 29 |
+
* });
|
| 30 |
+
* ```
|
| 31 |
+
*/
|
| 32 |
+
create(params: CompletionCreateParamsNonStreaming, options?: RequestOptions): APIPromise<Completion>;
|
| 33 |
+
create(params: CompletionCreateParamsStreaming, options?: RequestOptions): APIPromise<Stream<Completion>>;
|
| 34 |
+
create(
|
| 35 |
+
params: CompletionCreateParamsBase,
|
| 36 |
+
options?: RequestOptions,
|
| 37 |
+
): APIPromise<Stream<Completion> | Completion>;
|
| 38 |
+
create(
|
| 39 |
+
params: CompletionCreateParams,
|
| 40 |
+
options?: RequestOptions,
|
| 41 |
+
): APIPromise<Completion> | APIPromise<Stream<Completion>> {
|
| 42 |
+
const { betas, ...body } = params;
|
| 43 |
+
return this._client.post('/v1/complete', {
|
| 44 |
+
body,
|
| 45 |
+
timeout: (this._client as any)._options.timeout ?? 600000,
|
| 46 |
+
...options,
|
| 47 |
+
headers: buildHeaders([
|
| 48 |
+
{ ...(betas?.toString() != null ? { 'anthropic-beta': betas?.toString() } : undefined) },
|
| 49 |
+
options?.headers,
|
| 50 |
+
]),
|
| 51 |
+
stream: params.stream ?? false,
|
| 52 |
+
}) as APIPromise<Completion> | APIPromise<Stream<Completion>>;
|
| 53 |
+
}
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
export interface Completion {
|
| 57 |
+
/**
|
| 58 |
+
* Unique object identifier.
|
| 59 |
+
*
|
| 60 |
+
* The format and length of IDs may change over time.
|
| 61 |
+
*/
|
| 62 |
+
id: string;
|
| 63 |
+
|
| 64 |
+
/**
|
| 65 |
+
* The resulting completion up to and excluding the stop sequences.
|
| 66 |
+
*/
|
| 67 |
+
completion: string;
|
| 68 |
+
|
| 69 |
+
/**
|
| 70 |
+
* The model that will complete your prompt.\n\nSee
|
| 71 |
+
* [models](https://docs.anthropic.com/en/docs/models-overview) for additional
|
| 72 |
+
* details and options.
|
| 73 |
+
*/
|
| 74 |
+
model: MessagesAPI.Model;
|
| 75 |
+
|
| 76 |
+
/**
|
| 77 |
+
* The reason that we stopped.
|
| 78 |
+
*
|
| 79 |
+
* This may be one the following values:
|
| 80 |
+
*
|
| 81 |
+
* - `"stop_sequence"`: we reached a stop sequence — either provided by you via the
|
| 82 |
+
* `stop_sequences` parameter, or a stop sequence built into the model
|
| 83 |
+
* - `"max_tokens"`: we exceeded `max_tokens_to_sample` or the model's maximum
|
| 84 |
+
*/
|
| 85 |
+
stop_reason: string | null;
|
| 86 |
+
|
| 87 |
+
/**
|
| 88 |
+
* Object type.
|
| 89 |
+
*
|
| 90 |
+
* For Text Completions, this is always `"completion"`.
|
| 91 |
+
*/
|
| 92 |
+
type: 'completion';
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
export type CompletionCreateParams = CompletionCreateParamsNonStreaming | CompletionCreateParamsStreaming;
|
| 96 |
+
|
| 97 |
+
export interface CompletionCreateParamsBase {
|
| 98 |
+
/**
|
| 99 |
+
* Body param: The maximum number of tokens to generate before stopping.
|
| 100 |
+
*
|
| 101 |
+
* Note that our models may stop _before_ reaching this maximum. This parameter
|
| 102 |
+
* only specifies the absolute maximum number of tokens to generate.
|
| 103 |
+
*/
|
| 104 |
+
max_tokens_to_sample: number;
|
| 105 |
+
|
| 106 |
+
/**
|
| 107 |
+
* Body param: The model that will complete your prompt.\n\nSee
|
| 108 |
+
* [models](https://docs.anthropic.com/en/docs/models-overview) for additional
|
| 109 |
+
* details and options.
|
| 110 |
+
*/
|
| 111 |
+
model: MessagesAPI.Model;
|
| 112 |
+
|
| 113 |
+
/**
|
| 114 |
+
* Body param: The prompt that you want Claude to complete.
|
| 115 |
+
*
|
| 116 |
+
* For proper response generation you will need to format your prompt using
|
| 117 |
+
* alternating `\n\nHuman:` and `\n\nAssistant:` conversational turns. For example:
|
| 118 |
+
*
|
| 119 |
+
* ```
|
| 120 |
+
* "\n\nHuman: {userQuestion}\n\nAssistant:"
|
| 121 |
+
* ```
|
| 122 |
+
*
|
| 123 |
+
* See [prompt validation](https://docs.anthropic.com/en/api/prompt-validation) and
|
| 124 |
+
* our guide to
|
| 125 |
+
* [prompt design](https://docs.anthropic.com/en/docs/intro-to-prompting) for more
|
| 126 |
+
* details.
|
| 127 |
+
*/
|
| 128 |
+
prompt: string;
|
| 129 |
+
|
| 130 |
+
/**
|
| 131 |
+
* Body param: An object describing metadata about the request.
|
| 132 |
+
*/
|
| 133 |
+
metadata?: MessagesAPI.Metadata;
|
| 134 |
+
|
| 135 |
+
/**
|
| 136 |
+
* Body param: Sequences that will cause the model to stop generating.
|
| 137 |
+
*
|
| 138 |
+
* Our models stop on `"\n\nHuman:"`, and may include additional built-in stop
|
| 139 |
+
* sequences in the future. By providing the stop_sequences parameter, you may
|
| 140 |
+
* include additional strings that will cause the model to stop generating.
|
| 141 |
+
*/
|
| 142 |
+
stop_sequences?: Array<string>;
|
| 143 |
+
|
| 144 |
+
/**
|
| 145 |
+
* Body param: Whether to incrementally stream the response using server-sent
|
| 146 |
+
* events.
|
| 147 |
+
*
|
| 148 |
+
* See [streaming](https://docs.anthropic.com/en/api/streaming) for details.
|
| 149 |
+
*/
|
| 150 |
+
stream?: boolean;
|
| 151 |
+
|
| 152 |
+
/**
|
| 153 |
+
* Body param: Amount of randomness injected into the response.
|
| 154 |
+
*
|
| 155 |
+
* Defaults to `1.0`. Ranges from `0.0` to `1.0`. Use `temperature` closer to `0.0`
|
| 156 |
+
* for analytical / multiple choice, and closer to `1.0` for creative and
|
| 157 |
+
* generative tasks.
|
| 158 |
+
*
|
| 159 |
+
* Note that even with `temperature` of `0.0`, the results will not be fully
|
| 160 |
+
* deterministic.
|
| 161 |
+
*/
|
| 162 |
+
temperature?: number;
|
| 163 |
+
|
| 164 |
+
/**
|
| 165 |
+
* Body param: Only sample from the top K options for each subsequent token.
|
| 166 |
+
*
|
| 167 |
+
* Used to remove "long tail" low probability responses.
|
| 168 |
+
* [Learn more technical details here](https://towardsdatascience.com/how-to-sample-from-language-models-682bceb97277).
|
| 169 |
+
*
|
| 170 |
+
* Recommended for advanced use cases only. You usually only need to use
|
| 171 |
+
* `temperature`.
|
| 172 |
+
*/
|
| 173 |
+
top_k?: number;
|
| 174 |
+
|
| 175 |
+
/**
|
| 176 |
+
* Body param: Use nucleus sampling.
|
| 177 |
+
*
|
| 178 |
+
* In nucleus sampling, we compute the cumulative distribution over all the options
|
| 179 |
+
* for each subsequent token in decreasing probability order and cut it off once it
|
| 180 |
+
* reaches a particular probability specified by `top_p`. You should either alter
|
| 181 |
+
* `temperature` or `top_p`, but not both.
|
| 182 |
+
*
|
| 183 |
+
* Recommended for advanced use cases only. You usually only need to use
|
| 184 |
+
* `temperature`.
|
| 185 |
+
*/
|
| 186 |
+
top_p?: number;
|
| 187 |
+
|
| 188 |
+
/**
|
| 189 |
+
* Header param: Optional header to specify the beta version(s) you want to use.
|
| 190 |
+
*/
|
| 191 |
+
betas?: Array<BetaAPI.AnthropicBeta>;
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
export namespace CompletionCreateParams {
|
| 195 |
+
/**
|
| 196 |
+
* @deprecated use `Anthropic.Messages.Metadata` instead
|
| 197 |
+
*/
|
| 198 |
+
export type Metadata = MessagesAPI.Metadata;
|
| 199 |
+
|
| 200 |
+
export type CompletionCreateParamsNonStreaming = CompletionsAPI.CompletionCreateParamsNonStreaming;
|
| 201 |
+
export type CompletionCreateParamsStreaming = CompletionsAPI.CompletionCreateParamsStreaming;
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
export interface CompletionCreateParamsNonStreaming extends CompletionCreateParamsBase {
|
| 205 |
+
/**
|
| 206 |
+
* Body param: Whether to incrementally stream the response using server-sent
|
| 207 |
+
* events.
|
| 208 |
+
*
|
| 209 |
+
* See [streaming](https://docs.anthropic.com/en/api/streaming) for details.
|
| 210 |
+
*/
|
| 211 |
+
stream?: false;
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
export interface CompletionCreateParamsStreaming extends CompletionCreateParamsBase {
|
| 215 |
+
/**
|
| 216 |
+
* Body param: Whether to incrementally stream the response using server-sent
|
| 217 |
+
* events.
|
| 218 |
+
*
|
| 219 |
+
* See [streaming](https://docs.anthropic.com/en/api/streaming) for details.
|
| 220 |
+
*/
|
| 221 |
+
stream: true;
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
export declare namespace Completions {
|
| 225 |
+
export {
|
| 226 |
+
type Completion as Completion,
|
| 227 |
+
type CompletionCreateParams as CompletionCreateParams,
|
| 228 |
+
type CompletionCreateParamsNonStreaming as CompletionCreateParamsNonStreaming,
|
| 229 |
+
type CompletionCreateParamsStreaming as CompletionCreateParamsStreaming,
|
| 230 |
+
};
|
| 231 |
+
}
|
node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/resources/index.ts
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
| 2 |
+
|
| 3 |
+
export * from './shared';
|
| 4 |
+
export {
|
| 5 |
+
Beta,
|
| 6 |
+
type AnthropicBeta,
|
| 7 |
+
type BetaAPIError,
|
| 8 |
+
type BetaAuthenticationError,
|
| 9 |
+
type BetaBillingError,
|
| 10 |
+
type BetaError,
|
| 11 |
+
type BetaErrorResponse,
|
| 12 |
+
type BetaGatewayTimeoutError,
|
| 13 |
+
type BetaInvalidRequestError,
|
| 14 |
+
type BetaNotFoundError,
|
| 15 |
+
type BetaOverloadedError,
|
| 16 |
+
type BetaPermissionError,
|
| 17 |
+
type BetaRateLimitError,
|
| 18 |
+
} from './beta/beta';
|
| 19 |
+
export {
|
| 20 |
+
Completions,
|
| 21 |
+
type Completion,
|
| 22 |
+
type CompletionCreateParams,
|
| 23 |
+
type CompletionCreateParamsNonStreaming,
|
| 24 |
+
type CompletionCreateParamsStreaming,
|
| 25 |
+
} from './completions';
|
| 26 |
+
export {
|
| 27 |
+
Messages,
|
| 28 |
+
type Base64ImageSource,
|
| 29 |
+
type Base64PDFSource,
|
| 30 |
+
type CacheControlEphemeral,
|
| 31 |
+
type CitationCharLocation,
|
| 32 |
+
type CitationCharLocationParam,
|
| 33 |
+
type CitationContentBlockLocation,
|
| 34 |
+
type CitationContentBlockLocationParam,
|
| 35 |
+
type CitationPageLocation,
|
| 36 |
+
type CitationPageLocationParam,
|
| 37 |
+
type CitationWebSearchResultLocationParam,
|
| 38 |
+
type CitationsConfigParam,
|
| 39 |
+
type CitationsDelta,
|
| 40 |
+
type CitationsWebSearchResultLocation,
|
| 41 |
+
type ContentBlock,
|
| 42 |
+
type ContentBlockParam,
|
| 43 |
+
type ContentBlockStartEvent,
|
| 44 |
+
type ContentBlockStopEvent,
|
| 45 |
+
type ContentBlockSource,
|
| 46 |
+
type ContentBlockSourceContent,
|
| 47 |
+
type DocumentBlockParam,
|
| 48 |
+
type ImageBlockParam,
|
| 49 |
+
type InputJSONDelta,
|
| 50 |
+
type Message,
|
| 51 |
+
type MessageCountTokensTool,
|
| 52 |
+
type MessageDeltaEvent,
|
| 53 |
+
type MessageDeltaUsage,
|
| 54 |
+
type MessageParam,
|
| 55 |
+
type MessageStreamParams,
|
| 56 |
+
type MessageTokensCount,
|
| 57 |
+
type Metadata,
|
| 58 |
+
type Model,
|
| 59 |
+
type PlainTextSource,
|
| 60 |
+
type RawContentBlockDelta,
|
| 61 |
+
type RawContentBlockDeltaEvent,
|
| 62 |
+
type RawContentBlockStartEvent,
|
| 63 |
+
type RawContentBlockStopEvent,
|
| 64 |
+
type RawMessageDeltaEvent,
|
| 65 |
+
type RawMessageStartEvent,
|
| 66 |
+
type RawMessageStopEvent,
|
| 67 |
+
type RawMessageStreamEvent,
|
| 68 |
+
type RedactedThinkingBlock,
|
| 69 |
+
type RedactedThinkingBlockParam,
|
| 70 |
+
type ServerToolUsage,
|
| 71 |
+
type ServerToolUseBlock,
|
| 72 |
+
type ServerToolUseBlockParam,
|
| 73 |
+
type SignatureDelta,
|
| 74 |
+
type StopReason,
|
| 75 |
+
type TextBlock,
|
| 76 |
+
type TextBlockParam,
|
| 77 |
+
type TextCitation,
|
| 78 |
+
type TextCitationParam,
|
| 79 |
+
type TextDelta,
|
| 80 |
+
type ThinkingBlock,
|
| 81 |
+
type ThinkingBlockParam,
|
| 82 |
+
type ThinkingConfigDisabled,
|
| 83 |
+
type ThinkingConfigEnabled,
|
| 84 |
+
type ThinkingConfigParam,
|
| 85 |
+
type ThinkingDelta,
|
| 86 |
+
type Tool,
|
| 87 |
+
type ToolBash20250124,
|
| 88 |
+
type ToolChoice,
|
| 89 |
+
type ToolChoiceAny,
|
| 90 |
+
type ToolChoiceAuto,
|
| 91 |
+
type ToolChoiceNone,
|
| 92 |
+
type ToolChoiceTool,
|
| 93 |
+
type ToolResultBlockParam,
|
| 94 |
+
type ToolTextEditor20250124,
|
| 95 |
+
type ToolUnion,
|
| 96 |
+
type ToolUseBlock,
|
| 97 |
+
type ToolUseBlockParam,
|
| 98 |
+
type URLImageSource,
|
| 99 |
+
type URLPDFSource,
|
| 100 |
+
type Usage,
|
| 101 |
+
type WebSearchResultBlock,
|
| 102 |
+
type WebSearchResultBlockParam,
|
| 103 |
+
type WebSearchTool20250305,
|
| 104 |
+
type WebSearchToolRequestError,
|
| 105 |
+
type WebSearchToolResultBlock,
|
| 106 |
+
type WebSearchToolResultBlockContent,
|
| 107 |
+
type WebSearchToolResultBlockParam,
|
| 108 |
+
type WebSearchToolResultBlockParamContent,
|
| 109 |
+
type WebSearchToolResultError,
|
| 110 |
+
type MessageCreateParams,
|
| 111 |
+
type MessageCreateParamsNonStreaming,
|
| 112 |
+
type MessageCreateParamsStreaming,
|
| 113 |
+
type MessageCountTokensParams,
|
| 114 |
+
} from './messages/messages';
|
| 115 |
+
export {
|
| 116 |
+
Models,
|
| 117 |
+
type ModelInfo,
|
| 118 |
+
type ModelRetrieveParams,
|
| 119 |
+
type ModelListParams,
|
| 120 |
+
type ModelInfosPage,
|
| 121 |
+
} from './models';
|
node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/resources/messages.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
| 2 |
+
|
| 3 |
+
export * from './messages/index';
|
node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/resources/messages/batches.ts
ADDED
|
@@ -0,0 +1,396 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
| 2 |
+
|
| 3 |
+
import { APIResource } from '../../core/resource';
|
| 4 |
+
import * as Shared from '../shared';
|
| 5 |
+
import * as MessagesAPI from './messages';
|
| 6 |
+
import { APIPromise } from '../../core/api-promise';
|
| 7 |
+
import { Page, type PageParams, PagePromise } from '../../core/pagination';
|
| 8 |
+
import { buildHeaders } from '../../internal/headers';
|
| 9 |
+
import { RequestOptions } from '../../internal/request-options';
|
| 10 |
+
import { JSONLDecoder } from '../../internal/decoders/jsonl';
|
| 11 |
+
import { AnthropicError } from '../../error';
|
| 12 |
+
import { path } from '../../internal/utils/path';
|
| 13 |
+
|
| 14 |
+
export class Batches extends APIResource {
|
| 15 |
+
/**
|
| 16 |
+
* Send a batch of Message creation requests.
|
| 17 |
+
*
|
| 18 |
+
* The Message Batches API can be used to process multiple Messages API requests at
|
| 19 |
+
* once. Once a Message Batch is created, it begins processing immediately. Batches
|
| 20 |
+
* can take up to 24 hours to complete.
|
| 21 |
+
*
|
| 22 |
+
* Learn more about the Message Batches API in our
|
| 23 |
+
* [user guide](/en/docs/build-with-claude/batch-processing)
|
| 24 |
+
*
|
| 25 |
+
* @example
|
| 26 |
+
* ```ts
|
| 27 |
+
* const messageBatch = await client.messages.batches.create({
|
| 28 |
+
* requests: [
|
| 29 |
+
* {
|
| 30 |
+
* custom_id: 'my-custom-id-1',
|
| 31 |
+
* params: {
|
| 32 |
+
* max_tokens: 1024,
|
| 33 |
+
* messages: [
|
| 34 |
+
* { content: 'Hello, world', role: 'user' },
|
| 35 |
+
* ],
|
| 36 |
+
* model: 'claude-sonnet-4-20250514',
|
| 37 |
+
* },
|
| 38 |
+
* },
|
| 39 |
+
* ],
|
| 40 |
+
* });
|
| 41 |
+
* ```
|
| 42 |
+
*/
|
| 43 |
+
create(body: BatchCreateParams, options?: RequestOptions): APIPromise<MessageBatch> {
|
| 44 |
+
return this._client.post('/v1/messages/batches', { body, ...options });
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
/**
|
| 48 |
+
* This endpoint is idempotent and can be used to poll for Message Batch
|
| 49 |
+
* completion. To access the results of a Message Batch, make a request to the
|
| 50 |
+
* `results_url` field in the response.
|
| 51 |
+
*
|
| 52 |
+
* Learn more about the Message Batches API in our
|
| 53 |
+
* [user guide](/en/docs/build-with-claude/batch-processing)
|
| 54 |
+
*
|
| 55 |
+
* @example
|
| 56 |
+
* ```ts
|
| 57 |
+
* const messageBatch = await client.messages.batches.retrieve(
|
| 58 |
+
* 'message_batch_id',
|
| 59 |
+
* );
|
| 60 |
+
* ```
|
| 61 |
+
*/
|
| 62 |
+
retrieve(messageBatchID: string, options?: RequestOptions): APIPromise<MessageBatch> {
|
| 63 |
+
return this._client.get(path`/v1/messages/batches/${messageBatchID}`, options);
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
/**
|
| 67 |
+
* List all Message Batches within a Workspace. Most recently created batches are
|
| 68 |
+
* returned first.
|
| 69 |
+
*
|
| 70 |
+
* Learn more about the Message Batches API in our
|
| 71 |
+
* [user guide](/en/docs/build-with-claude/batch-processing)
|
| 72 |
+
*
|
| 73 |
+
* @example
|
| 74 |
+
* ```ts
|
| 75 |
+
* // Automatically fetches more pages as needed.
|
| 76 |
+
* for await (const messageBatch of client.messages.batches.list()) {
|
| 77 |
+
* // ...
|
| 78 |
+
* }
|
| 79 |
+
* ```
|
| 80 |
+
*/
|
| 81 |
+
list(
|
| 82 |
+
query: BatchListParams | null | undefined = {},
|
| 83 |
+
options?: RequestOptions,
|
| 84 |
+
): PagePromise<MessageBatchesPage, MessageBatch> {
|
| 85 |
+
return this._client.getAPIList('/v1/messages/batches', Page<MessageBatch>, { query, ...options });
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
/**
|
| 89 |
+
* Delete a Message Batch.
|
| 90 |
+
*
|
| 91 |
+
* Message Batches can only be deleted once they've finished processing. If you'd
|
| 92 |
+
* like to delete an in-progress batch, you must first cancel it.
|
| 93 |
+
*
|
| 94 |
+
* Learn more about the Message Batches API in our
|
| 95 |
+
* [user guide](/en/docs/build-with-claude/batch-processing)
|
| 96 |
+
*
|
| 97 |
+
* @example
|
| 98 |
+
* ```ts
|
| 99 |
+
* const deletedMessageBatch =
|
| 100 |
+
* await client.messages.batches.delete('message_batch_id');
|
| 101 |
+
* ```
|
| 102 |
+
*/
|
| 103 |
+
delete(messageBatchID: string, options?: RequestOptions): APIPromise<DeletedMessageBatch> {
|
| 104 |
+
return this._client.delete(path`/v1/messages/batches/${messageBatchID}`, options);
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
/**
|
| 108 |
+
* Batches may be canceled any time before processing ends. Once cancellation is
|
| 109 |
+
* initiated, the batch enters a `canceling` state, at which time the system may
|
| 110 |
+
* complete any in-progress, non-interruptible requests before finalizing
|
| 111 |
+
* cancellation.
|
| 112 |
+
*
|
| 113 |
+
* The number of canceled requests is specified in `request_counts`. To determine
|
| 114 |
+
* which requests were canceled, check the individual results within the batch.
|
| 115 |
+
* Note that cancellation may not result in any canceled requests if they were
|
| 116 |
+
* non-interruptible.
|
| 117 |
+
*
|
| 118 |
+
* Learn more about the Message Batches API in our
|
| 119 |
+
* [user guide](/en/docs/build-with-claude/batch-processing)
|
| 120 |
+
*
|
| 121 |
+
* @example
|
| 122 |
+
* ```ts
|
| 123 |
+
* const messageBatch = await client.messages.batches.cancel(
|
| 124 |
+
* 'message_batch_id',
|
| 125 |
+
* );
|
| 126 |
+
* ```
|
| 127 |
+
*/
|
| 128 |
+
cancel(messageBatchID: string, options?: RequestOptions): APIPromise<MessageBatch> {
|
| 129 |
+
return this._client.post(path`/v1/messages/batches/${messageBatchID}/cancel`, options);
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
/**
|
| 133 |
+
* Streams the results of a Message Batch as a `.jsonl` file.
|
| 134 |
+
*
|
| 135 |
+
* Each line in the file is a JSON object containing the result of a single request
|
| 136 |
+
* in the Message Batch. Results are not guaranteed to be in the same order as
|
| 137 |
+
* requests. Use the `custom_id` field to match results to requests.
|
| 138 |
+
*
|
| 139 |
+
* Learn more about the Message Batches API in our
|
| 140 |
+
* [user guide](/en/docs/build-with-claude/batch-processing)
|
| 141 |
+
*
|
| 142 |
+
* @example
|
| 143 |
+
* ```ts
|
| 144 |
+
* const messageBatchIndividualResponse =
|
| 145 |
+
* await client.messages.batches.results('message_batch_id');
|
| 146 |
+
* ```
|
| 147 |
+
*/
|
| 148 |
+
async results(
|
| 149 |
+
messageBatchID: string,
|
| 150 |
+
options?: RequestOptions,
|
| 151 |
+
): Promise<JSONLDecoder<MessageBatchIndividualResponse>> {
|
| 152 |
+
const batch = await this.retrieve(messageBatchID);
|
| 153 |
+
if (!batch.results_url) {
|
| 154 |
+
throw new AnthropicError(
|
| 155 |
+
`No batch \`results_url\`; Has it finished processing? ${batch.processing_status} - ${batch.id}`,
|
| 156 |
+
);
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
return this._client
|
| 160 |
+
.get(batch.results_url, {
|
| 161 |
+
...options,
|
| 162 |
+
headers: buildHeaders([{ Accept: 'application/binary' }, options?.headers]),
|
| 163 |
+
stream: true,
|
| 164 |
+
__binaryResponse: true,
|
| 165 |
+
})
|
| 166 |
+
._thenUnwrap((_, props) => JSONLDecoder.fromResponse(props.response, props.controller)) as APIPromise<
|
| 167 |
+
JSONLDecoder<MessageBatchIndividualResponse>
|
| 168 |
+
>;
|
| 169 |
+
}
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
export type MessageBatchesPage = Page<MessageBatch>;
|
| 173 |
+
|
| 174 |
+
export interface DeletedMessageBatch {
|
| 175 |
+
/**
|
| 176 |
+
* ID of the Message Batch.
|
| 177 |
+
*/
|
| 178 |
+
id: string;
|
| 179 |
+
|
| 180 |
+
/**
|
| 181 |
+
* Deleted object type.
|
| 182 |
+
*
|
| 183 |
+
* For Message Batches, this is always `"message_batch_deleted"`.
|
| 184 |
+
*/
|
| 185 |
+
type: 'message_batch_deleted';
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
export interface MessageBatch {
|
| 189 |
+
/**
|
| 190 |
+
* Unique object identifier.
|
| 191 |
+
*
|
| 192 |
+
* The format and length of IDs may change over time.
|
| 193 |
+
*/
|
| 194 |
+
id: string;
|
| 195 |
+
|
| 196 |
+
/**
|
| 197 |
+
* RFC 3339 datetime string representing the time at which the Message Batch was
|
| 198 |
+
* archived and its results became unavailable.
|
| 199 |
+
*/
|
| 200 |
+
archived_at: string | null;
|
| 201 |
+
|
| 202 |
+
/**
|
| 203 |
+
* RFC 3339 datetime string representing the time at which cancellation was
|
| 204 |
+
* initiated for the Message Batch. Specified only if cancellation was initiated.
|
| 205 |
+
*/
|
| 206 |
+
cancel_initiated_at: string | null;
|
| 207 |
+
|
| 208 |
+
/**
|
| 209 |
+
* RFC 3339 datetime string representing the time at which the Message Batch was
|
| 210 |
+
* created.
|
| 211 |
+
*/
|
| 212 |
+
created_at: string;
|
| 213 |
+
|
| 214 |
+
/**
|
| 215 |
+
* RFC 3339 datetime string representing the time at which processing for the
|
| 216 |
+
* Message Batch ended. Specified only once processing ends.
|
| 217 |
+
*
|
| 218 |
+
* Processing ends when every request in a Message Batch has either succeeded,
|
| 219 |
+
* errored, canceled, or expired.
|
| 220 |
+
*/
|
| 221 |
+
ended_at: string | null;
|
| 222 |
+
|
| 223 |
+
/**
|
| 224 |
+
* RFC 3339 datetime string representing the time at which the Message Batch will
|
| 225 |
+
* expire and end processing, which is 24 hours after creation.
|
| 226 |
+
*/
|
| 227 |
+
expires_at: string;
|
| 228 |
+
|
| 229 |
+
/**
|
| 230 |
+
* Processing status of the Message Batch.
|
| 231 |
+
*/
|
| 232 |
+
processing_status: 'in_progress' | 'canceling' | 'ended';
|
| 233 |
+
|
| 234 |
+
/**
|
| 235 |
+
* Tallies requests within the Message Batch, categorized by their status.
|
| 236 |
+
*
|
| 237 |
+
* Requests start as `processing` and move to one of the other statuses only once
|
| 238 |
+
* processing of the entire batch ends. The sum of all values always matches the
|
| 239 |
+
* total number of requests in the batch.
|
| 240 |
+
*/
|
| 241 |
+
request_counts: MessageBatchRequestCounts;
|
| 242 |
+
|
| 243 |
+
/**
|
| 244 |
+
* URL to a `.jsonl` file containing the results of the Message Batch requests.
|
| 245 |
+
* Specified only once processing ends.
|
| 246 |
+
*
|
| 247 |
+
* Results in the file are not guaranteed to be in the same order as requests. Use
|
| 248 |
+
* the `custom_id` field to match results to requests.
|
| 249 |
+
*/
|
| 250 |
+
results_url: string | null;
|
| 251 |
+
|
| 252 |
+
/**
|
| 253 |
+
* Object type.
|
| 254 |
+
*
|
| 255 |
+
* For Message Batches, this is always `"message_batch"`.
|
| 256 |
+
*/
|
| 257 |
+
type: 'message_batch';
|
| 258 |
+
}
|
| 259 |
+
|
| 260 |
+
export interface MessageBatchCanceledResult {
|
| 261 |
+
type: 'canceled';
|
| 262 |
+
}
|
| 263 |
+
|
| 264 |
+
export interface MessageBatchErroredResult {
|
| 265 |
+
error: Shared.ErrorResponse;
|
| 266 |
+
|
| 267 |
+
type: 'errored';
|
| 268 |
+
}
|
| 269 |
+
|
| 270 |
+
export interface MessageBatchExpiredResult {
|
| 271 |
+
type: 'expired';
|
| 272 |
+
}
|
| 273 |
+
|
| 274 |
+
/**
|
| 275 |
+
* This is a single line in the response `.jsonl` file and does not represent the
|
| 276 |
+
* response as a whole.
|
| 277 |
+
*/
|
| 278 |
+
export interface MessageBatchIndividualResponse {
|
| 279 |
+
/**
|
| 280 |
+
* Developer-provided ID created for each request in a Message Batch. Useful for
|
| 281 |
+
* matching results to requests, as results may be given out of request order.
|
| 282 |
+
*
|
| 283 |
+
* Must be unique for each request within the Message Batch.
|
| 284 |
+
*/
|
| 285 |
+
custom_id: string;
|
| 286 |
+
|
| 287 |
+
/**
|
| 288 |
+
* Processing result for this request.
|
| 289 |
+
*
|
| 290 |
+
* Contains a Message output if processing was successful, an error response if
|
| 291 |
+
* processing failed, or the reason why processing was not attempted, such as
|
| 292 |
+
* cancellation or expiration.
|
| 293 |
+
*/
|
| 294 |
+
result: MessageBatchResult;
|
| 295 |
+
}
|
| 296 |
+
|
| 297 |
+
export interface MessageBatchRequestCounts {
|
| 298 |
+
/**
|
| 299 |
+
* Number of requests in the Message Batch that have been canceled.
|
| 300 |
+
*
|
| 301 |
+
* This is zero until processing of the entire Message Batch has ended.
|
| 302 |
+
*/
|
| 303 |
+
canceled: number;
|
| 304 |
+
|
| 305 |
+
/**
|
| 306 |
+
* Number of requests in the Message Batch that encountered an error.
|
| 307 |
+
*
|
| 308 |
+
* This is zero until processing of the entire Message Batch has ended.
|
| 309 |
+
*/
|
| 310 |
+
errored: number;
|
| 311 |
+
|
| 312 |
+
/**
|
| 313 |
+
* Number of requests in the Message Batch that have expired.
|
| 314 |
+
*
|
| 315 |
+
* This is zero until processing of the entire Message Batch has ended.
|
| 316 |
+
*/
|
| 317 |
+
expired: number;
|
| 318 |
+
|
| 319 |
+
/**
|
| 320 |
+
* Number of requests in the Message Batch that are processing.
|
| 321 |
+
*/
|
| 322 |
+
processing: number;
|
| 323 |
+
|
| 324 |
+
/**
|
| 325 |
+
* Number of requests in the Message Batch that have completed successfully.
|
| 326 |
+
*
|
| 327 |
+
* This is zero until processing of the entire Message Batch has ended.
|
| 328 |
+
*/
|
| 329 |
+
succeeded: number;
|
| 330 |
+
}
|
| 331 |
+
|
| 332 |
+
/**
|
| 333 |
+
* Processing result for this request.
|
| 334 |
+
*
|
| 335 |
+
* Contains a Message output if processing was successful, an error response if
|
| 336 |
+
* processing failed, or the reason why processing was not attempted, such as
|
| 337 |
+
* cancellation or expiration.
|
| 338 |
+
*/
|
| 339 |
+
export type MessageBatchResult =
|
| 340 |
+
| MessageBatchSucceededResult
|
| 341 |
+
| MessageBatchErroredResult
|
| 342 |
+
| MessageBatchCanceledResult
|
| 343 |
+
| MessageBatchExpiredResult;
|
| 344 |
+
|
| 345 |
+
export interface MessageBatchSucceededResult {
|
| 346 |
+
message: MessagesAPI.Message;
|
| 347 |
+
|
| 348 |
+
type: 'succeeded';
|
| 349 |
+
}
|
| 350 |
+
|
| 351 |
+
export interface BatchCreateParams {
|
| 352 |
+
/**
|
| 353 |
+
* List of requests for prompt completion. Each is an individual request to create
|
| 354 |
+
* a Message.
|
| 355 |
+
*/
|
| 356 |
+
requests: Array<BatchCreateParams.Request>;
|
| 357 |
+
}
|
| 358 |
+
|
| 359 |
+
export namespace BatchCreateParams {
|
| 360 |
+
export interface Request {
|
| 361 |
+
/**
|
| 362 |
+
* Developer-provided ID created for each request in a Message Batch. Useful for
|
| 363 |
+
* matching results to requests, as results may be given out of request order.
|
| 364 |
+
*
|
| 365 |
+
* Must be unique for each request within the Message Batch.
|
| 366 |
+
*/
|
| 367 |
+
custom_id: string;
|
| 368 |
+
|
| 369 |
+
/**
|
| 370 |
+
* Messages API creation parameters for the individual request.
|
| 371 |
+
*
|
| 372 |
+
* See the [Messages API reference](/en/api/messages) for full documentation on
|
| 373 |
+
* available parameters.
|
| 374 |
+
*/
|
| 375 |
+
params: MessagesAPI.MessageCreateParamsNonStreaming;
|
| 376 |
+
}
|
| 377 |
+
}
|
| 378 |
+
|
| 379 |
+
export interface BatchListParams extends PageParams {}
|
| 380 |
+
|
| 381 |
+
export declare namespace Batches {
|
| 382 |
+
export {
|
| 383 |
+
type DeletedMessageBatch as DeletedMessageBatch,
|
| 384 |
+
type MessageBatch as MessageBatch,
|
| 385 |
+
type MessageBatchCanceledResult as MessageBatchCanceledResult,
|
| 386 |
+
type MessageBatchErroredResult as MessageBatchErroredResult,
|
| 387 |
+
type MessageBatchExpiredResult as MessageBatchExpiredResult,
|
| 388 |
+
type MessageBatchIndividualResponse as MessageBatchIndividualResponse,
|
| 389 |
+
type MessageBatchRequestCounts as MessageBatchRequestCounts,
|
| 390 |
+
type MessageBatchResult as MessageBatchResult,
|
| 391 |
+
type MessageBatchSucceededResult as MessageBatchSucceededResult,
|
| 392 |
+
type MessageBatchesPage as MessageBatchesPage,
|
| 393 |
+
type BatchCreateParams as BatchCreateParams,
|
| 394 |
+
type BatchListParams as BatchListParams,
|
| 395 |
+
};
|
| 396 |
+
}
|
node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/resources/messages/index.ts
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
| 2 |
+
|
| 3 |
+
export {
|
| 4 |
+
Batches,
|
| 5 |
+
type DeletedMessageBatch,
|
| 6 |
+
type MessageBatch,
|
| 7 |
+
type MessageBatchCanceledResult,
|
| 8 |
+
type MessageBatchErroredResult,
|
| 9 |
+
type MessageBatchExpiredResult,
|
| 10 |
+
type MessageBatchIndividualResponse,
|
| 11 |
+
type MessageBatchRequestCounts,
|
| 12 |
+
type MessageBatchResult,
|
| 13 |
+
type MessageBatchSucceededResult,
|
| 14 |
+
type BatchCreateParams,
|
| 15 |
+
type BatchListParams,
|
| 16 |
+
type MessageBatchesPage,
|
| 17 |
+
} from './batches';
|
| 18 |
+
export {
|
| 19 |
+
Messages,
|
| 20 |
+
type Base64ImageSource,
|
| 21 |
+
type Base64PDFSource,
|
| 22 |
+
type CacheControlEphemeral,
|
| 23 |
+
type CitationCharLocation,
|
| 24 |
+
type CitationCharLocationParam,
|
| 25 |
+
type CitationContentBlockLocation,
|
| 26 |
+
type CitationContentBlockLocationParam,
|
| 27 |
+
type CitationPageLocation,
|
| 28 |
+
type CitationPageLocationParam,
|
| 29 |
+
type CitationWebSearchResultLocationParam,
|
| 30 |
+
type CitationsConfigParam,
|
| 31 |
+
type CitationsDelta,
|
| 32 |
+
type CitationsWebSearchResultLocation,
|
| 33 |
+
type ContentBlock,
|
| 34 |
+
type ContentBlockParam,
|
| 35 |
+
type ContentBlockStartEvent,
|
| 36 |
+
type ContentBlockStopEvent,
|
| 37 |
+
type ContentBlockSource,
|
| 38 |
+
type ContentBlockSourceContent,
|
| 39 |
+
type DocumentBlockParam,
|
| 40 |
+
type ImageBlockParam,
|
| 41 |
+
type InputJSONDelta,
|
| 42 |
+
type Message,
|
| 43 |
+
type MessageCountTokensTool,
|
| 44 |
+
type MessageDeltaEvent,
|
| 45 |
+
type MessageDeltaUsage,
|
| 46 |
+
type MessageParam,
|
| 47 |
+
type MessageTokensCount,
|
| 48 |
+
type Metadata,
|
| 49 |
+
type Model,
|
| 50 |
+
type PlainTextSource,
|
| 51 |
+
type RawContentBlockDelta,
|
| 52 |
+
type RawContentBlockDeltaEvent,
|
| 53 |
+
type RawContentBlockStartEvent,
|
| 54 |
+
type RawContentBlockStopEvent,
|
| 55 |
+
type RawMessageDeltaEvent,
|
| 56 |
+
type RawMessageStartEvent,
|
| 57 |
+
type RawMessageStopEvent,
|
| 58 |
+
type RawMessageStreamEvent,
|
| 59 |
+
type RedactedThinkingBlock,
|
| 60 |
+
type RedactedThinkingBlockParam,
|
| 61 |
+
type ServerToolUsage,
|
| 62 |
+
type ServerToolUseBlock,
|
| 63 |
+
type ServerToolUseBlockParam,
|
| 64 |
+
type SignatureDelta,
|
| 65 |
+
type StopReason,
|
| 66 |
+
type TextBlock,
|
| 67 |
+
type TextBlockParam,
|
| 68 |
+
type TextCitation,
|
| 69 |
+
type TextCitationParam,
|
| 70 |
+
type TextDelta,
|
| 71 |
+
type ThinkingBlock,
|
| 72 |
+
type ThinkingBlockParam,
|
| 73 |
+
type ThinkingConfigDisabled,
|
| 74 |
+
type ThinkingConfigEnabled,
|
| 75 |
+
type ThinkingConfigParam,
|
| 76 |
+
type ThinkingDelta,
|
| 77 |
+
type Tool,
|
| 78 |
+
type ToolBash20250124,
|
| 79 |
+
type ToolChoice,
|
| 80 |
+
type ToolChoiceAny,
|
| 81 |
+
type ToolChoiceAuto,
|
| 82 |
+
type ToolChoiceNone,
|
| 83 |
+
type ToolChoiceTool,
|
| 84 |
+
type ToolResultBlockParam,
|
| 85 |
+
type ToolTextEditor20250124,
|
| 86 |
+
type ToolUnion,
|
| 87 |
+
type ToolUseBlock,
|
| 88 |
+
type ToolUseBlockParam,
|
| 89 |
+
type URLImageSource,
|
| 90 |
+
type URLPDFSource,
|
| 91 |
+
type Usage,
|
| 92 |
+
type WebSearchResultBlock,
|
| 93 |
+
type WebSearchResultBlockParam,
|
| 94 |
+
type WebSearchTool20250305,
|
| 95 |
+
type WebSearchToolRequestError,
|
| 96 |
+
type WebSearchToolResultBlock,
|
| 97 |
+
type WebSearchToolResultBlockContent,
|
| 98 |
+
type WebSearchToolResultBlockParam,
|
| 99 |
+
type WebSearchToolResultBlockParamContent,
|
| 100 |
+
type WebSearchToolResultError,
|
| 101 |
+
type MessageStreamEvent,
|
| 102 |
+
type MessageStartEvent,
|
| 103 |
+
type MessageStopEvent,
|
| 104 |
+
type ContentBlockDeltaEvent,
|
| 105 |
+
type MessageCreateParams,
|
| 106 |
+
type MessageCreateParamsBase,
|
| 107 |
+
type MessageCreateParamsNonStreaming,
|
| 108 |
+
type MessageCreateParamsStreaming,
|
| 109 |
+
type MessageCountTokensParams,
|
| 110 |
+
} from './messages';
|
node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/resources/messages/messages.ts
ADDED
|
@@ -0,0 +1,1848 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
| 2 |
+
|
| 3 |
+
import { APIPromise } from '../../core/api-promise';
|
| 4 |
+
import { APIResource } from '../../core/resource';
|
| 5 |
+
import { Stream } from '../../core/streaming';
|
| 6 |
+
import { RequestOptions } from '../../internal/request-options';
|
| 7 |
+
import { MessageStream } from '../../lib/MessageStream';
|
| 8 |
+
import * as BatchesAPI from './batches';
|
| 9 |
+
import {
|
| 10 |
+
BatchCreateParams,
|
| 11 |
+
BatchListParams,
|
| 12 |
+
Batches,
|
| 13 |
+
DeletedMessageBatch,
|
| 14 |
+
MessageBatch,
|
| 15 |
+
MessageBatchCanceledResult,
|
| 16 |
+
MessageBatchErroredResult,
|
| 17 |
+
MessageBatchExpiredResult,
|
| 18 |
+
MessageBatchIndividualResponse,
|
| 19 |
+
MessageBatchRequestCounts,
|
| 20 |
+
MessageBatchResult,
|
| 21 |
+
MessageBatchSucceededResult,
|
| 22 |
+
MessageBatchesPage,
|
| 23 |
+
} from './batches';
|
| 24 |
+
import * as MessagesAPI from './messages';
|
| 25 |
+
|
| 26 |
+
import { MODEL_NONSTREAMING_TOKENS } from '../../internal/constants';
|
| 27 |
+
|
| 28 |
+
export class Messages extends APIResource {
|
| 29 |
+
batches: BatchesAPI.Batches = new BatchesAPI.Batches(this._client);
|
| 30 |
+
|
| 31 |
+
/**
|
| 32 |
+
* Send a structured list of input messages with text and/or image content, and the
|
| 33 |
+
* model will generate the next message in the conversation.
|
| 34 |
+
*
|
| 35 |
+
* The Messages API can be used for either single queries or stateless multi-turn
|
| 36 |
+
* conversations.
|
| 37 |
+
*
|
| 38 |
+
* Learn more about the Messages API in our [user guide](/en/docs/initial-setup)
|
| 39 |
+
*
|
| 40 |
+
* @example
|
| 41 |
+
* ```ts
|
| 42 |
+
* const message = await client.messages.create({
|
| 43 |
+
* max_tokens: 1024,
|
| 44 |
+
* messages: [{ content: 'Hello, world', role: 'user' }],
|
| 45 |
+
* model: 'claude-sonnet-4-20250514',
|
| 46 |
+
* });
|
| 47 |
+
* ```
|
| 48 |
+
*/
|
| 49 |
+
create(body: MessageCreateParamsNonStreaming, options?: RequestOptions): APIPromise<Message>;
|
| 50 |
+
create(
|
| 51 |
+
body: MessageCreateParamsStreaming,
|
| 52 |
+
options?: RequestOptions,
|
| 53 |
+
): APIPromise<Stream<RawMessageStreamEvent>>;
|
| 54 |
+
create(
|
| 55 |
+
body: MessageCreateParamsBase,
|
| 56 |
+
options?: RequestOptions,
|
| 57 |
+
): APIPromise<Stream<RawMessageStreamEvent> | Message>;
|
| 58 |
+
create(
|
| 59 |
+
body: MessageCreateParams,
|
| 60 |
+
options?: RequestOptions,
|
| 61 |
+
): APIPromise<Message> | APIPromise<Stream<RawMessageStreamEvent>> {
|
| 62 |
+
if (body.model in DEPRECATED_MODELS) {
|
| 63 |
+
console.warn(
|
| 64 |
+
`The model '${body.model}' is deprecated and will reach end-of-life on ${
|
| 65 |
+
DEPRECATED_MODELS[body.model]
|
| 66 |
+
}\nPlease migrate to a newer model. Visit https://docs.anthropic.com/en/docs/resources/model-deprecations for more information.`,
|
| 67 |
+
);
|
| 68 |
+
}
|
| 69 |
+
let timeout = (this._client as any)._options.timeout as number | null;
|
| 70 |
+
if (!body.stream && timeout == null) {
|
| 71 |
+
const maxNonstreamingTokens = MODEL_NONSTREAMING_TOKENS[body.model] ?? undefined;
|
| 72 |
+
timeout = this._client.calculateNonstreamingTimeout(body.max_tokens, maxNonstreamingTokens);
|
| 73 |
+
}
|
| 74 |
+
return this._client.post('/v1/messages', {
|
| 75 |
+
body,
|
| 76 |
+
timeout: timeout ?? 600000,
|
| 77 |
+
...options,
|
| 78 |
+
stream: body.stream ?? false,
|
| 79 |
+
}) as APIPromise<Message> | APIPromise<Stream<RawMessageStreamEvent>>;
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
/**
|
| 83 |
+
* Create a Message stream
|
| 84 |
+
*/
|
| 85 |
+
stream(body: MessageStreamParams, options?: RequestOptions): MessageStream {
|
| 86 |
+
return MessageStream.createMessage(this, body, options);
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
/**
|
| 90 |
+
* Count the number of tokens in a Message.
|
| 91 |
+
*
|
| 92 |
+
* The Token Count API can be used to count the number of tokens in a Message,
|
| 93 |
+
* including tools, images, and documents, without creating it.
|
| 94 |
+
*
|
| 95 |
+
* Learn more about token counting in our
|
| 96 |
+
* [user guide](/en/docs/build-with-claude/token-counting)
|
| 97 |
+
*
|
| 98 |
+
* @example
|
| 99 |
+
* ```ts
|
| 100 |
+
* const messageTokensCount =
|
| 101 |
+
* await client.messages.countTokens({
|
| 102 |
+
* messages: [{ content: 'string', role: 'user' }],
|
| 103 |
+
* model: 'claude-3-7-sonnet-latest',
|
| 104 |
+
* });
|
| 105 |
+
* ```
|
| 106 |
+
*/
|
| 107 |
+
countTokens(body: MessageCountTokensParams, options?: RequestOptions): APIPromise<MessageTokensCount> {
|
| 108 |
+
return this._client.post('/v1/messages/count_tokens', { body, ...options });
|
| 109 |
+
}
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
export interface Base64ImageSource {
|
| 113 |
+
data: string;
|
| 114 |
+
|
| 115 |
+
media_type: 'image/jpeg' | 'image/png' | 'image/gif' | 'image/webp';
|
| 116 |
+
|
| 117 |
+
type: 'base64';
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
export interface Base64PDFSource {
|
| 121 |
+
data: string;
|
| 122 |
+
|
| 123 |
+
media_type: 'application/pdf';
|
| 124 |
+
|
| 125 |
+
type: 'base64';
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
export interface CacheControlEphemeral {
|
| 129 |
+
type: 'ephemeral';
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
export interface CitationCharLocation {
|
| 133 |
+
cited_text: string;
|
| 134 |
+
|
| 135 |
+
document_index: number;
|
| 136 |
+
|
| 137 |
+
document_title: string | null;
|
| 138 |
+
|
| 139 |
+
end_char_index: number;
|
| 140 |
+
|
| 141 |
+
start_char_index: number;
|
| 142 |
+
|
| 143 |
+
type: 'char_location';
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
export interface CitationCharLocationParam {
|
| 147 |
+
cited_text: string;
|
| 148 |
+
|
| 149 |
+
document_index: number;
|
| 150 |
+
|
| 151 |
+
document_title: string | null;
|
| 152 |
+
|
| 153 |
+
end_char_index: number;
|
| 154 |
+
|
| 155 |
+
start_char_index: number;
|
| 156 |
+
|
| 157 |
+
type: 'char_location';
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
export interface CitationContentBlockLocation {
|
| 161 |
+
cited_text: string;
|
| 162 |
+
|
| 163 |
+
document_index: number;
|
| 164 |
+
|
| 165 |
+
document_title: string | null;
|
| 166 |
+
|
| 167 |
+
end_block_index: number;
|
| 168 |
+
|
| 169 |
+
start_block_index: number;
|
| 170 |
+
|
| 171 |
+
type: 'content_block_location';
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
export interface CitationContentBlockLocationParam {
|
| 175 |
+
cited_text: string;
|
| 176 |
+
|
| 177 |
+
document_index: number;
|
| 178 |
+
|
| 179 |
+
document_title: string | null;
|
| 180 |
+
|
| 181 |
+
end_block_index: number;
|
| 182 |
+
|
| 183 |
+
start_block_index: number;
|
| 184 |
+
|
| 185 |
+
type: 'content_block_location';
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
export interface CitationPageLocation {
|
| 189 |
+
cited_text: string;
|
| 190 |
+
|
| 191 |
+
document_index: number;
|
| 192 |
+
|
| 193 |
+
document_title: string | null;
|
| 194 |
+
|
| 195 |
+
end_page_number: number;
|
| 196 |
+
|
| 197 |
+
start_page_number: number;
|
| 198 |
+
|
| 199 |
+
type: 'page_location';
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
export interface CitationPageLocationParam {
|
| 203 |
+
cited_text: string;
|
| 204 |
+
|
| 205 |
+
document_index: number;
|
| 206 |
+
|
| 207 |
+
document_title: string | null;
|
| 208 |
+
|
| 209 |
+
end_page_number: number;
|
| 210 |
+
|
| 211 |
+
start_page_number: number;
|
| 212 |
+
|
| 213 |
+
type: 'page_location';
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
export interface CitationWebSearchResultLocationParam {
|
| 217 |
+
cited_text: string;
|
| 218 |
+
|
| 219 |
+
encrypted_index: string;
|
| 220 |
+
|
| 221 |
+
title: string | null;
|
| 222 |
+
|
| 223 |
+
type: 'web_search_result_location';
|
| 224 |
+
|
| 225 |
+
url: string;
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
export interface CitationsConfigParam {
|
| 229 |
+
enabled?: boolean;
|
| 230 |
+
}
|
| 231 |
+
|
| 232 |
+
export interface CitationsDelta {
|
| 233 |
+
citation:
|
| 234 |
+
| CitationCharLocation
|
| 235 |
+
| CitationPageLocation
|
| 236 |
+
| CitationContentBlockLocation
|
| 237 |
+
| CitationsWebSearchResultLocation;
|
| 238 |
+
|
| 239 |
+
type: 'citations_delta';
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
export interface CitationsWebSearchResultLocation {
|
| 243 |
+
cited_text: string;
|
| 244 |
+
|
| 245 |
+
encrypted_index: string;
|
| 246 |
+
|
| 247 |
+
title: string | null;
|
| 248 |
+
|
| 249 |
+
type: 'web_search_result_location';
|
| 250 |
+
|
| 251 |
+
url: string;
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
+
export type ContentBlock =
|
| 255 |
+
| TextBlock
|
| 256 |
+
| ThinkingBlock
|
| 257 |
+
| RedactedThinkingBlock
|
| 258 |
+
| ToolUseBlock
|
| 259 |
+
| ServerToolUseBlock
|
| 260 |
+
| WebSearchToolResultBlock;
|
| 261 |
+
|
| 262 |
+
/**
|
| 263 |
+
* Regular text content.
|
| 264 |
+
*/
|
| 265 |
+
export type ContentBlockParam =
|
| 266 |
+
| TextBlockParam
|
| 267 |
+
| ImageBlockParam
|
| 268 |
+
| DocumentBlockParam
|
| 269 |
+
| ThinkingBlockParam
|
| 270 |
+
| RedactedThinkingBlockParam
|
| 271 |
+
| ToolUseBlockParam
|
| 272 |
+
| ToolResultBlockParam
|
| 273 |
+
| ServerToolUseBlockParam
|
| 274 |
+
| WebSearchToolResultBlockParam;
|
| 275 |
+
|
| 276 |
+
export interface ContentBlockSource {
|
| 277 |
+
content: string | Array<ContentBlockSourceContent>;
|
| 278 |
+
|
| 279 |
+
type: 'content';
|
| 280 |
+
}
|
| 281 |
+
|
| 282 |
+
export type ContentBlockSourceContent = TextBlockParam | ImageBlockParam;
|
| 283 |
+
|
| 284 |
+
export interface DocumentBlockParam {
|
| 285 |
+
source: Base64PDFSource | PlainTextSource | ContentBlockSource | URLPDFSource;
|
| 286 |
+
|
| 287 |
+
type: 'document';
|
| 288 |
+
|
| 289 |
+
/**
|
| 290 |
+
* Create a cache control breakpoint at this content block.
|
| 291 |
+
*/
|
| 292 |
+
cache_control?: CacheControlEphemeral | null;
|
| 293 |
+
|
| 294 |
+
citations?: CitationsConfigParam;
|
| 295 |
+
|
| 296 |
+
context?: string | null;
|
| 297 |
+
|
| 298 |
+
title?: string | null;
|
| 299 |
+
}
|
| 300 |
+
|
| 301 |
+
export interface ImageBlockParam {
|
| 302 |
+
source: Base64ImageSource | URLImageSource;
|
| 303 |
+
|
| 304 |
+
type: 'image';
|
| 305 |
+
|
| 306 |
+
/**
|
| 307 |
+
* Create a cache control breakpoint at this content block.
|
| 308 |
+
*/
|
| 309 |
+
cache_control?: CacheControlEphemeral | null;
|
| 310 |
+
}
|
| 311 |
+
|
| 312 |
+
export interface InputJSONDelta {
|
| 313 |
+
partial_json: string;
|
| 314 |
+
|
| 315 |
+
type: 'input_json_delta';
|
| 316 |
+
}
|
| 317 |
+
|
| 318 |
+
export interface Message {
|
| 319 |
+
/**
|
| 320 |
+
* Unique object identifier.
|
| 321 |
+
*
|
| 322 |
+
* The format and length of IDs may change over time.
|
| 323 |
+
*/
|
| 324 |
+
id: string;
|
| 325 |
+
|
| 326 |
+
/**
|
| 327 |
+
* Content generated by the model.
|
| 328 |
+
*
|
| 329 |
+
* This is an array of content blocks, each of which has a `type` that determines
|
| 330 |
+
* its shape.
|
| 331 |
+
*
|
| 332 |
+
* Example:
|
| 333 |
+
*
|
| 334 |
+
* ```json
|
| 335 |
+
* [{ "type": "text", "text": "Hi, I'm Claude." }]
|
| 336 |
+
* ```
|
| 337 |
+
*
|
| 338 |
+
* If the request input `messages` ended with an `assistant` turn, then the
|
| 339 |
+
* response `content` will continue directly from that last turn. You can use this
|
| 340 |
+
* to constrain the model's output.
|
| 341 |
+
*
|
| 342 |
+
* For example, if the input `messages` were:
|
| 343 |
+
*
|
| 344 |
+
* ```json
|
| 345 |
+
* [
|
| 346 |
+
* {
|
| 347 |
+
* "role": "user",
|
| 348 |
+
* "content": "What's the Greek name for Sun? (A) Sol (B) Helios (C) Sun"
|
| 349 |
+
* },
|
| 350 |
+
* { "role": "assistant", "content": "The best answer is (" }
|
| 351 |
+
* ]
|
| 352 |
+
* ```
|
| 353 |
+
*
|
| 354 |
+
* Then the response `content` might be:
|
| 355 |
+
*
|
| 356 |
+
* ```json
|
| 357 |
+
* [{ "type": "text", "text": "B)" }]
|
| 358 |
+
* ```
|
| 359 |
+
*/
|
| 360 |
+
content: Array<ContentBlock>;
|
| 361 |
+
|
| 362 |
+
/**
|
| 363 |
+
* The model that will complete your prompt.\n\nSee
|
| 364 |
+
* [models](https://docs.anthropic.com/en/docs/models-overview) for additional
|
| 365 |
+
* details and options.
|
| 366 |
+
*/
|
| 367 |
+
model: Model;
|
| 368 |
+
|
| 369 |
+
/**
|
| 370 |
+
* Conversational role of the generated message.
|
| 371 |
+
*
|
| 372 |
+
* This will always be `"assistant"`.
|
| 373 |
+
*/
|
| 374 |
+
role: 'assistant';
|
| 375 |
+
|
| 376 |
+
/**
|
| 377 |
+
* The reason that we stopped.
|
| 378 |
+
*
|
| 379 |
+
* This may be one the following values:
|
| 380 |
+
*
|
| 381 |
+
* - `"end_turn"`: the model reached a natural stopping point
|
| 382 |
+
* - `"max_tokens"`: we exceeded the requested `max_tokens` or the model's maximum
|
| 383 |
+
* - `"stop_sequence"`: one of your provided custom `stop_sequences` was generated
|
| 384 |
+
* - `"tool_use"`: the model invoked one or more tools
|
| 385 |
+
* - `"pause_turn"`: we paused a long-running turn. You may provide the response
|
| 386 |
+
* back as-is in a subsequent request to let the model continue.
|
| 387 |
+
* - `"refusal"`: when streaming classifiers intervene to handle potential policy
|
| 388 |
+
* violations
|
| 389 |
+
*
|
| 390 |
+
* In non-streaming mode this value is always non-null. In streaming mode, it is
|
| 391 |
+
* null in the `message_start` event and non-null otherwise.
|
| 392 |
+
*/
|
| 393 |
+
stop_reason: StopReason | null;
|
| 394 |
+
|
| 395 |
+
/**
|
| 396 |
+
* Which custom stop sequence was generated, if any.
|
| 397 |
+
*
|
| 398 |
+
* This value will be a non-null string if one of your custom stop sequences was
|
| 399 |
+
* generated.
|
| 400 |
+
*/
|
| 401 |
+
stop_sequence: string | null;
|
| 402 |
+
|
| 403 |
+
/**
|
| 404 |
+
* Object type.
|
| 405 |
+
*
|
| 406 |
+
* For Messages, this is always `"message"`.
|
| 407 |
+
*/
|
| 408 |
+
type: 'message';
|
| 409 |
+
|
| 410 |
+
/**
|
| 411 |
+
* Billing and rate-limit usage.
|
| 412 |
+
*
|
| 413 |
+
* Anthropic's API bills and rate-limits by token counts, as tokens represent the
|
| 414 |
+
* underlying cost to our systems.
|
| 415 |
+
*
|
| 416 |
+
* Under the hood, the API transforms requests into a format suitable for the
|
| 417 |
+
* model. The model's output then goes through a parsing stage before becoming an
|
| 418 |
+
* API response. As a result, the token counts in `usage` will not match one-to-one
|
| 419 |
+
* with the exact visible content of an API request or response.
|
| 420 |
+
*
|
| 421 |
+
* For example, `output_tokens` will be non-zero, even for an empty string response
|
| 422 |
+
* from Claude.
|
| 423 |
+
*
|
| 424 |
+
* Total input tokens in a request is the summation of `input_tokens`,
|
| 425 |
+
* `cache_creation_input_tokens`, and `cache_read_input_tokens`.
|
| 426 |
+
*/
|
| 427 |
+
usage: Usage;
|
| 428 |
+
}
|
| 429 |
+
|
| 430 |
+
export type MessageCountTokensTool =
|
| 431 |
+
| Tool
|
| 432 |
+
| ToolBash20250124
|
| 433 |
+
| ToolTextEditor20250124
|
| 434 |
+
| MessageCountTokensTool.TextEditor20250429
|
| 435 |
+
| WebSearchTool20250305;
|
| 436 |
+
|
| 437 |
+
export namespace MessageCountTokensTool {
|
| 438 |
+
export interface TextEditor20250429 {
|
| 439 |
+
/**
|
| 440 |
+
* Name of the tool.
|
| 441 |
+
*
|
| 442 |
+
* This is how the tool will be called by the model and in `tool_use` blocks.
|
| 443 |
+
*/
|
| 444 |
+
name: 'str_replace_based_edit_tool';
|
| 445 |
+
|
| 446 |
+
type: 'text_editor_20250429';
|
| 447 |
+
|
| 448 |
+
/**
|
| 449 |
+
* Create a cache control breakpoint at this content block.
|
| 450 |
+
*/
|
| 451 |
+
cache_control?: MessagesAPI.CacheControlEphemeral | null;
|
| 452 |
+
}
|
| 453 |
+
}
|
| 454 |
+
|
| 455 |
+
export interface MessageDeltaUsage {
|
| 456 |
+
/**
|
| 457 |
+
* The cumulative number of input tokens used to create the cache entry.
|
| 458 |
+
*/
|
| 459 |
+
cache_creation_input_tokens: number | null;
|
| 460 |
+
|
| 461 |
+
/**
|
| 462 |
+
* The cumulative number of input tokens read from the cache.
|
| 463 |
+
*/
|
| 464 |
+
cache_read_input_tokens: number | null;
|
| 465 |
+
|
| 466 |
+
/**
|
| 467 |
+
* The cumulative number of input tokens which were used.
|
| 468 |
+
*/
|
| 469 |
+
input_tokens: number | null;
|
| 470 |
+
|
| 471 |
+
/**
|
| 472 |
+
* The cumulative number of output tokens which were used.
|
| 473 |
+
*/
|
| 474 |
+
output_tokens: number;
|
| 475 |
+
|
| 476 |
+
/**
|
| 477 |
+
* The number of server tool requests.
|
| 478 |
+
*/
|
| 479 |
+
server_tool_use: ServerToolUsage | null;
|
| 480 |
+
}
|
| 481 |
+
|
| 482 |
+
export interface MessageParam {
|
| 483 |
+
content: string | Array<ContentBlockParam>;
|
| 484 |
+
|
| 485 |
+
role: 'user' | 'assistant';
|
| 486 |
+
}
|
| 487 |
+
|
| 488 |
+
export interface MessageTokensCount {
|
| 489 |
+
/**
|
| 490 |
+
* The total number of tokens across the provided list of messages, system prompt,
|
| 491 |
+
* and tools.
|
| 492 |
+
*/
|
| 493 |
+
input_tokens: number;
|
| 494 |
+
}
|
| 495 |
+
|
| 496 |
+
export interface Metadata {
|
| 497 |
+
/**
|
| 498 |
+
* An external identifier for the user who is associated with the request.
|
| 499 |
+
*
|
| 500 |
+
* This should be a uuid, hash value, or other opaque identifier. Anthropic may use
|
| 501 |
+
* this id to help detect abuse. Do not include any identifying information such as
|
| 502 |
+
* name, email address, or phone number.
|
| 503 |
+
*/
|
| 504 |
+
user_id?: string | null;
|
| 505 |
+
}
|
| 506 |
+
|
| 507 |
+
/**
|
| 508 |
+
* The model that will complete your prompt.\n\nSee
|
| 509 |
+
* [models](https://docs.anthropic.com/en/docs/models-overview) for additional
|
| 510 |
+
* details and options.
|
| 511 |
+
*/
|
| 512 |
+
export type Model =
|
| 513 |
+
| 'claude-3-7-sonnet-latest'
|
| 514 |
+
| 'claude-3-7-sonnet-20250219'
|
| 515 |
+
| 'claude-3-5-haiku-latest'
|
| 516 |
+
| 'claude-3-5-haiku-20241022'
|
| 517 |
+
| 'claude-sonnet-4-20250514'
|
| 518 |
+
| 'claude-sonnet-4-0'
|
| 519 |
+
| 'claude-4-sonnet-20250514'
|
| 520 |
+
| 'claude-3-5-sonnet-latest'
|
| 521 |
+
| 'claude-3-5-sonnet-20241022'
|
| 522 |
+
| 'claude-3-5-sonnet-20240620'
|
| 523 |
+
| 'claude-opus-4-0'
|
| 524 |
+
| 'claude-opus-4-20250514'
|
| 525 |
+
| 'claude-4-opus-20250514'
|
| 526 |
+
| 'claude-3-opus-latest'
|
| 527 |
+
| 'claude-3-opus-20240229'
|
| 528 |
+
| 'claude-3-sonnet-20240229'
|
| 529 |
+
| 'claude-3-haiku-20240307'
|
| 530 |
+
| 'claude-2.1'
|
| 531 |
+
| 'claude-2.0'
|
| 532 |
+
| (string & {});
|
| 533 |
+
|
| 534 |
+
const DEPRECATED_MODELS: {
|
| 535 |
+
[K in Model]?: string;
|
| 536 |
+
} = {
|
| 537 |
+
'claude-1.3': 'November 6th, 2024',
|
| 538 |
+
'claude-1.3-100k': 'November 6th, 2024',
|
| 539 |
+
'claude-instant-1.1': 'November 6th, 2024',
|
| 540 |
+
'claude-instant-1.1-100k': 'November 6th, 2024',
|
| 541 |
+
'claude-instant-1.2': 'November 6th, 2024',
|
| 542 |
+
'claude-3-sonnet-20240229': 'July 21st, 2025',
|
| 543 |
+
'claude-3-opus-20240229': 'January 5th, 2026',
|
| 544 |
+
'claude-2.1': 'July 21st, 2025',
|
| 545 |
+
'claude-2.0': 'July 21st, 2025',
|
| 546 |
+
};
|
| 547 |
+
|
| 548 |
+
export interface PlainTextSource {
|
| 549 |
+
data: string;
|
| 550 |
+
|
| 551 |
+
media_type: 'text/plain';
|
| 552 |
+
|
| 553 |
+
type: 'text';
|
| 554 |
+
}
|
| 555 |
+
|
| 556 |
+
export type RawContentBlockDelta =
|
| 557 |
+
| TextDelta
|
| 558 |
+
| InputJSONDelta
|
| 559 |
+
| CitationsDelta
|
| 560 |
+
| ThinkingDelta
|
| 561 |
+
| SignatureDelta;
|
| 562 |
+
|
| 563 |
+
export interface RawContentBlockDeltaEvent {
|
| 564 |
+
delta: RawContentBlockDelta;
|
| 565 |
+
|
| 566 |
+
index: number;
|
| 567 |
+
|
| 568 |
+
type: 'content_block_delta';
|
| 569 |
+
}
|
| 570 |
+
|
| 571 |
+
export interface RawContentBlockStartEvent {
|
| 572 |
+
content_block:
|
| 573 |
+
| TextBlock
|
| 574 |
+
| ThinkingBlock
|
| 575 |
+
| RedactedThinkingBlock
|
| 576 |
+
| ToolUseBlock
|
| 577 |
+
| ServerToolUseBlock
|
| 578 |
+
| WebSearchToolResultBlock;
|
| 579 |
+
|
| 580 |
+
index: number;
|
| 581 |
+
|
| 582 |
+
type: 'content_block_start';
|
| 583 |
+
}
|
| 584 |
+
|
| 585 |
+
export interface RawContentBlockStopEvent {
|
| 586 |
+
index: number;
|
| 587 |
+
|
| 588 |
+
type: 'content_block_stop';
|
| 589 |
+
}
|
| 590 |
+
|
| 591 |
+
export interface RawMessageDeltaEvent {
|
| 592 |
+
delta: RawMessageDeltaEvent.Delta;
|
| 593 |
+
|
| 594 |
+
type: 'message_delta';
|
| 595 |
+
|
| 596 |
+
/**
|
| 597 |
+
* Billing and rate-limit usage.
|
| 598 |
+
*
|
| 599 |
+
* Anthropic's API bills and rate-limits by token counts, as tokens represent the
|
| 600 |
+
* underlying cost to our systems.
|
| 601 |
+
*
|
| 602 |
+
* Under the hood, the API transforms requests into a format suitable for the
|
| 603 |
+
* model. The model's output then goes through a parsing stage before becoming an
|
| 604 |
+
* API response. As a result, the token counts in `usage` will not match one-to-one
|
| 605 |
+
* with the exact visible content of an API request or response.
|
| 606 |
+
*
|
| 607 |
+
* For example, `output_tokens` will be non-zero, even for an empty string response
|
| 608 |
+
* from Claude.
|
| 609 |
+
*
|
| 610 |
+
* Total input tokens in a request is the summation of `input_tokens`,
|
| 611 |
+
* `cache_creation_input_tokens`, and `cache_read_input_tokens`.
|
| 612 |
+
*/
|
| 613 |
+
usage: MessageDeltaUsage;
|
| 614 |
+
}
|
| 615 |
+
|
| 616 |
+
export namespace RawMessageDeltaEvent {
|
| 617 |
+
export interface Delta {
|
| 618 |
+
stop_reason: MessagesAPI.StopReason | null;
|
| 619 |
+
|
| 620 |
+
stop_sequence: string | null;
|
| 621 |
+
}
|
| 622 |
+
}
|
| 623 |
+
|
| 624 |
+
export interface RawMessageStartEvent {
|
| 625 |
+
message: Message;
|
| 626 |
+
|
| 627 |
+
type: 'message_start';
|
| 628 |
+
}
|
| 629 |
+
|
| 630 |
+
export interface RawMessageStopEvent {
|
| 631 |
+
type: 'message_stop';
|
| 632 |
+
}
|
| 633 |
+
|
| 634 |
+
export type RawMessageStreamEvent =
|
| 635 |
+
| RawMessageStartEvent
|
| 636 |
+
| RawMessageDeltaEvent
|
| 637 |
+
| RawMessageStopEvent
|
| 638 |
+
| RawContentBlockStartEvent
|
| 639 |
+
| RawContentBlockDeltaEvent
|
| 640 |
+
| RawContentBlockStopEvent;
|
| 641 |
+
|
| 642 |
+
export interface RedactedThinkingBlock {
|
| 643 |
+
data: string;
|
| 644 |
+
|
| 645 |
+
type: 'redacted_thinking';
|
| 646 |
+
}
|
| 647 |
+
|
| 648 |
+
export interface RedactedThinkingBlockParam {
|
| 649 |
+
data: string;
|
| 650 |
+
|
| 651 |
+
type: 'redacted_thinking';
|
| 652 |
+
}
|
| 653 |
+
|
| 654 |
+
export interface ServerToolUsage {
|
| 655 |
+
/**
|
| 656 |
+
* The number of web search tool requests.
|
| 657 |
+
*/
|
| 658 |
+
web_search_requests: number;
|
| 659 |
+
}
|
| 660 |
+
|
| 661 |
+
export interface ServerToolUseBlock {
|
| 662 |
+
id: string;
|
| 663 |
+
|
| 664 |
+
input: unknown;
|
| 665 |
+
|
| 666 |
+
name: 'web_search';
|
| 667 |
+
|
| 668 |
+
type: 'server_tool_use';
|
| 669 |
+
}
|
| 670 |
+
|
| 671 |
+
export interface ServerToolUseBlockParam {
|
| 672 |
+
id: string;
|
| 673 |
+
|
| 674 |
+
input: unknown;
|
| 675 |
+
|
| 676 |
+
name: 'web_search';
|
| 677 |
+
|
| 678 |
+
type: 'server_tool_use';
|
| 679 |
+
|
| 680 |
+
/**
|
| 681 |
+
* Create a cache control breakpoint at this content block.
|
| 682 |
+
*/
|
| 683 |
+
cache_control?: CacheControlEphemeral | null;
|
| 684 |
+
}
|
| 685 |
+
|
| 686 |
+
export interface SignatureDelta {
|
| 687 |
+
signature: string;
|
| 688 |
+
|
| 689 |
+
type: 'signature_delta';
|
| 690 |
+
}
|
| 691 |
+
|
| 692 |
+
export type StopReason = 'end_turn' | 'max_tokens' | 'stop_sequence' | 'tool_use' | 'pause_turn' | 'refusal';
|
| 693 |
+
|
| 694 |
+
export interface TextBlock {
|
| 695 |
+
/**
|
| 696 |
+
* Citations supporting the text block.
|
| 697 |
+
*
|
| 698 |
+
* The type of citation returned will depend on the type of document being cited.
|
| 699 |
+
* Citing a PDF results in `page_location`, plain text results in `char_location`,
|
| 700 |
+
* and content document results in `content_block_location`.
|
| 701 |
+
*/
|
| 702 |
+
citations: Array<TextCitation> | null;
|
| 703 |
+
|
| 704 |
+
text: string;
|
| 705 |
+
|
| 706 |
+
type: 'text';
|
| 707 |
+
}
|
| 708 |
+
|
| 709 |
+
export interface TextBlockParam {
|
| 710 |
+
text: string;
|
| 711 |
+
|
| 712 |
+
type: 'text';
|
| 713 |
+
|
| 714 |
+
/**
|
| 715 |
+
* Create a cache control breakpoint at this content block.
|
| 716 |
+
*/
|
| 717 |
+
cache_control?: CacheControlEphemeral | null;
|
| 718 |
+
|
| 719 |
+
citations?: Array<TextCitationParam> | null;
|
| 720 |
+
}
|
| 721 |
+
|
| 722 |
+
export type TextCitation =
|
| 723 |
+
| CitationCharLocation
|
| 724 |
+
| CitationPageLocation
|
| 725 |
+
| CitationContentBlockLocation
|
| 726 |
+
| CitationsWebSearchResultLocation;
|
| 727 |
+
|
| 728 |
+
export type TextCitationParam =
|
| 729 |
+
| CitationCharLocationParam
|
| 730 |
+
| CitationPageLocationParam
|
| 731 |
+
| CitationContentBlockLocationParam
|
| 732 |
+
| CitationWebSearchResultLocationParam;
|
| 733 |
+
|
| 734 |
+
export interface TextDelta {
|
| 735 |
+
text: string;
|
| 736 |
+
|
| 737 |
+
type: 'text_delta';
|
| 738 |
+
}
|
| 739 |
+
|
| 740 |
+
export interface ThinkingBlock {
|
| 741 |
+
signature: string;
|
| 742 |
+
|
| 743 |
+
thinking: string;
|
| 744 |
+
|
| 745 |
+
type: 'thinking';
|
| 746 |
+
}
|
| 747 |
+
|
| 748 |
+
export interface ThinkingBlockParam {
|
| 749 |
+
signature: string;
|
| 750 |
+
|
| 751 |
+
thinking: string;
|
| 752 |
+
|
| 753 |
+
type: 'thinking';
|
| 754 |
+
}
|
| 755 |
+
|
| 756 |
+
export interface ThinkingConfigDisabled {
|
| 757 |
+
type: 'disabled';
|
| 758 |
+
}
|
| 759 |
+
|
| 760 |
+
export interface ThinkingConfigEnabled {
|
| 761 |
+
/**
|
| 762 |
+
* Determines how many tokens Claude can use for its internal reasoning process.
|
| 763 |
+
* Larger budgets can enable more thorough analysis for complex problems, improving
|
| 764 |
+
* response quality.
|
| 765 |
+
*
|
| 766 |
+
* Must be ≥1024 and less than `max_tokens`.
|
| 767 |
+
*
|
| 768 |
+
* See
|
| 769 |
+
* [extended thinking](https://docs.anthropic.com/en/docs/build-with-claude/extended-thinking)
|
| 770 |
+
* for details.
|
| 771 |
+
*/
|
| 772 |
+
budget_tokens: number;
|
| 773 |
+
|
| 774 |
+
type: 'enabled';
|
| 775 |
+
}
|
| 776 |
+
|
| 777 |
+
/**
|
| 778 |
+
* Configuration for enabling Claude's extended thinking.
|
| 779 |
+
*
|
| 780 |
+
* When enabled, responses include `thinking` content blocks showing Claude's
|
| 781 |
+
* thinking process before the final answer. Requires a minimum budget of 1,024
|
| 782 |
+
* tokens and counts towards your `max_tokens` limit.
|
| 783 |
+
*
|
| 784 |
+
* See
|
| 785 |
+
* [extended thinking](https://docs.anthropic.com/en/docs/build-with-claude/extended-thinking)
|
| 786 |
+
* for details.
|
| 787 |
+
*/
|
| 788 |
+
export type ThinkingConfigParam = ThinkingConfigEnabled | ThinkingConfigDisabled;
|
| 789 |
+
|
| 790 |
+
export interface ThinkingDelta {
|
| 791 |
+
thinking: string;
|
| 792 |
+
|
| 793 |
+
type: 'thinking_delta';
|
| 794 |
+
}
|
| 795 |
+
|
| 796 |
+
export interface Tool {
|
| 797 |
+
/**
|
| 798 |
+
* [JSON schema](https://json-schema.org/draft/2020-12) for this tool's input.
|
| 799 |
+
*
|
| 800 |
+
* This defines the shape of the `input` that your tool accepts and that the model
|
| 801 |
+
* will produce.
|
| 802 |
+
*/
|
| 803 |
+
input_schema: Tool.InputSchema;
|
| 804 |
+
|
| 805 |
+
/**
|
| 806 |
+
* Name of the tool.
|
| 807 |
+
*
|
| 808 |
+
* This is how the tool will be called by the model and in `tool_use` blocks.
|
| 809 |
+
*/
|
| 810 |
+
name: string;
|
| 811 |
+
|
| 812 |
+
/**
|
| 813 |
+
* Create a cache control breakpoint at this content block.
|
| 814 |
+
*/
|
| 815 |
+
cache_control?: CacheControlEphemeral | null;
|
| 816 |
+
|
| 817 |
+
/**
|
| 818 |
+
* Description of what this tool does.
|
| 819 |
+
*
|
| 820 |
+
* Tool descriptions should be as detailed as possible. The more information that
|
| 821 |
+
* the model has about what the tool is and how to use it, the better it will
|
| 822 |
+
* perform. You can use natural language descriptions to reinforce important
|
| 823 |
+
* aspects of the tool input JSON schema.
|
| 824 |
+
*/
|
| 825 |
+
description?: string;
|
| 826 |
+
|
| 827 |
+
type?: 'custom' | null;
|
| 828 |
+
}
|
| 829 |
+
|
| 830 |
+
export namespace Tool {
|
| 831 |
+
/**
|
| 832 |
+
* [JSON schema](https://json-schema.org/draft/2020-12) for this tool's input.
|
| 833 |
+
*
|
| 834 |
+
* This defines the shape of the `input` that your tool accepts and that the model
|
| 835 |
+
* will produce.
|
| 836 |
+
*/
|
| 837 |
+
export interface InputSchema {
|
| 838 |
+
type: 'object';
|
| 839 |
+
|
| 840 |
+
properties?: unknown | null;
|
| 841 |
+
|
| 842 |
+
required?: Array<string> | null;
|
| 843 |
+
|
| 844 |
+
[k: string]: unknown;
|
| 845 |
+
}
|
| 846 |
+
}
|
| 847 |
+
|
| 848 |
+
export interface ToolBash20250124 {
|
| 849 |
+
/**
|
| 850 |
+
* Name of the tool.
|
| 851 |
+
*
|
| 852 |
+
* This is how the tool will be called by the model and in `tool_use` blocks.
|
| 853 |
+
*/
|
| 854 |
+
name: 'bash';
|
| 855 |
+
|
| 856 |
+
type: 'bash_20250124';
|
| 857 |
+
|
| 858 |
+
/**
|
| 859 |
+
* Create a cache control breakpoint at this content block.
|
| 860 |
+
*/
|
| 861 |
+
cache_control?: CacheControlEphemeral | null;
|
| 862 |
+
}
|
| 863 |
+
|
| 864 |
+
/**
|
| 865 |
+
* How the model should use the provided tools. The model can use a specific tool,
|
| 866 |
+
* any available tool, decide by itself, or not use tools at all.
|
| 867 |
+
*/
|
| 868 |
+
export type ToolChoice = ToolChoiceAuto | ToolChoiceAny | ToolChoiceTool | ToolChoiceNone;
|
| 869 |
+
|
| 870 |
+
/**
|
| 871 |
+
* The model will use any available tools.
|
| 872 |
+
*/
|
| 873 |
+
export interface ToolChoiceAny {
|
| 874 |
+
type: 'any';
|
| 875 |
+
|
| 876 |
+
/**
|
| 877 |
+
* Whether to disable parallel tool use.
|
| 878 |
+
*
|
| 879 |
+
* Defaults to `false`. If set to `true`, the model will output exactly one tool
|
| 880 |
+
* use.
|
| 881 |
+
*/
|
| 882 |
+
disable_parallel_tool_use?: boolean;
|
| 883 |
+
}
|
| 884 |
+
|
| 885 |
+
/**
|
| 886 |
+
* The model will automatically decide whether to use tools.
|
| 887 |
+
*/
|
| 888 |
+
export interface ToolChoiceAuto {
|
| 889 |
+
type: 'auto';
|
| 890 |
+
|
| 891 |
+
/**
|
| 892 |
+
* Whether to disable parallel tool use.
|
| 893 |
+
*
|
| 894 |
+
* Defaults to `false`. If set to `true`, the model will output at most one tool
|
| 895 |
+
* use.
|
| 896 |
+
*/
|
| 897 |
+
disable_parallel_tool_use?: boolean;
|
| 898 |
+
}
|
| 899 |
+
|
| 900 |
+
/**
|
| 901 |
+
* The model will not be allowed to use tools.
|
| 902 |
+
*/
|
| 903 |
+
export interface ToolChoiceNone {
|
| 904 |
+
type: 'none';
|
| 905 |
+
}
|
| 906 |
+
|
| 907 |
+
/**
|
| 908 |
+
* The model will use the specified tool with `tool_choice.name`.
|
| 909 |
+
*/
|
| 910 |
+
export interface ToolChoiceTool {
|
| 911 |
+
/**
|
| 912 |
+
* The name of the tool to use.
|
| 913 |
+
*/
|
| 914 |
+
name: string;
|
| 915 |
+
|
| 916 |
+
type: 'tool';
|
| 917 |
+
|
| 918 |
+
/**
|
| 919 |
+
* Whether to disable parallel tool use.
|
| 920 |
+
*
|
| 921 |
+
* Defaults to `false`. If set to `true`, the model will output exactly one tool
|
| 922 |
+
* use.
|
| 923 |
+
*/
|
| 924 |
+
disable_parallel_tool_use?: boolean;
|
| 925 |
+
}
|
| 926 |
+
|
| 927 |
+
export interface ToolResultBlockParam {
|
| 928 |
+
tool_use_id: string;
|
| 929 |
+
|
| 930 |
+
type: 'tool_result';
|
| 931 |
+
|
| 932 |
+
/**
|
| 933 |
+
* Create a cache control breakpoint at this content block.
|
| 934 |
+
*/
|
| 935 |
+
cache_control?: CacheControlEphemeral | null;
|
| 936 |
+
|
| 937 |
+
content?: string | Array<TextBlockParam | ImageBlockParam>;
|
| 938 |
+
|
| 939 |
+
is_error?: boolean;
|
| 940 |
+
}
|
| 941 |
+
|
| 942 |
+
export interface ToolTextEditor20250124 {
|
| 943 |
+
/**
|
| 944 |
+
* Name of the tool.
|
| 945 |
+
*
|
| 946 |
+
* This is how the tool will be called by the model and in `tool_use` blocks.
|
| 947 |
+
*/
|
| 948 |
+
name: 'str_replace_editor';
|
| 949 |
+
|
| 950 |
+
type: 'text_editor_20250124';
|
| 951 |
+
|
| 952 |
+
/**
|
| 953 |
+
* Create a cache control breakpoint at this content block.
|
| 954 |
+
*/
|
| 955 |
+
cache_control?: CacheControlEphemeral | null;
|
| 956 |
+
}
|
| 957 |
+
|
| 958 |
+
export type ToolUnion =
|
| 959 |
+
| Tool
|
| 960 |
+
| ToolBash20250124
|
| 961 |
+
| ToolTextEditor20250124
|
| 962 |
+
| ToolUnion.TextEditor20250429
|
| 963 |
+
| WebSearchTool20250305;
|
| 964 |
+
|
| 965 |
+
export namespace ToolUnion {
|
| 966 |
+
export interface TextEditor20250429 {
|
| 967 |
+
/**
|
| 968 |
+
* Name of the tool.
|
| 969 |
+
*
|
| 970 |
+
* This is how the tool will be called by the model and in `tool_use` blocks.
|
| 971 |
+
*/
|
| 972 |
+
name: 'str_replace_based_edit_tool';
|
| 973 |
+
|
| 974 |
+
type: 'text_editor_20250429';
|
| 975 |
+
|
| 976 |
+
/**
|
| 977 |
+
* Create a cache control breakpoint at this content block.
|
| 978 |
+
*/
|
| 979 |
+
cache_control?: MessagesAPI.CacheControlEphemeral | null;
|
| 980 |
+
}
|
| 981 |
+
}
|
| 982 |
+
|
| 983 |
+
export interface ToolUseBlock {
|
| 984 |
+
id: string;
|
| 985 |
+
|
| 986 |
+
input: unknown;
|
| 987 |
+
|
| 988 |
+
name: string;
|
| 989 |
+
|
| 990 |
+
type: 'tool_use';
|
| 991 |
+
}
|
| 992 |
+
|
| 993 |
+
export interface ToolUseBlockParam {
|
| 994 |
+
id: string;
|
| 995 |
+
|
| 996 |
+
input: unknown;
|
| 997 |
+
|
| 998 |
+
name: string;
|
| 999 |
+
|
| 1000 |
+
type: 'tool_use';
|
| 1001 |
+
|
| 1002 |
+
/**
|
| 1003 |
+
* Create a cache control breakpoint at this content block.
|
| 1004 |
+
*/
|
| 1005 |
+
cache_control?: CacheControlEphemeral | null;
|
| 1006 |
+
}
|
| 1007 |
+
|
| 1008 |
+
export interface URLImageSource {
|
| 1009 |
+
type: 'url';
|
| 1010 |
+
|
| 1011 |
+
url: string;
|
| 1012 |
+
}
|
| 1013 |
+
|
| 1014 |
+
export interface URLPDFSource {
|
| 1015 |
+
type: 'url';
|
| 1016 |
+
|
| 1017 |
+
url: string;
|
| 1018 |
+
}
|
| 1019 |
+
|
| 1020 |
+
export interface Usage {
|
| 1021 |
+
/**
|
| 1022 |
+
* The number of input tokens used to create the cache entry.
|
| 1023 |
+
*/
|
| 1024 |
+
cache_creation_input_tokens: number | null;
|
| 1025 |
+
|
| 1026 |
+
/**
|
| 1027 |
+
* The number of input tokens read from the cache.
|
| 1028 |
+
*/
|
| 1029 |
+
cache_read_input_tokens: number | null;
|
| 1030 |
+
|
| 1031 |
+
/**
|
| 1032 |
+
* The number of input tokens which were used.
|
| 1033 |
+
*/
|
| 1034 |
+
input_tokens: number;
|
| 1035 |
+
|
| 1036 |
+
/**
|
| 1037 |
+
* The number of output tokens which were used.
|
| 1038 |
+
*/
|
| 1039 |
+
output_tokens: number;
|
| 1040 |
+
|
| 1041 |
+
/**
|
| 1042 |
+
* The number of server tool requests.
|
| 1043 |
+
*/
|
| 1044 |
+
server_tool_use: ServerToolUsage | null;
|
| 1045 |
+
|
| 1046 |
+
/**
|
| 1047 |
+
* If the request used the priority, standard, or batch tier.
|
| 1048 |
+
*/
|
| 1049 |
+
service_tier: 'standard' | 'priority' | 'batch' | null;
|
| 1050 |
+
}
|
| 1051 |
+
|
| 1052 |
+
export interface WebSearchResultBlock {
|
| 1053 |
+
encrypted_content: string;
|
| 1054 |
+
|
| 1055 |
+
page_age: string | null;
|
| 1056 |
+
|
| 1057 |
+
title: string;
|
| 1058 |
+
|
| 1059 |
+
type: 'web_search_result';
|
| 1060 |
+
|
| 1061 |
+
url: string;
|
| 1062 |
+
}
|
| 1063 |
+
|
| 1064 |
+
export interface WebSearchResultBlockParam {
|
| 1065 |
+
encrypted_content: string;
|
| 1066 |
+
|
| 1067 |
+
title: string;
|
| 1068 |
+
|
| 1069 |
+
type: 'web_search_result';
|
| 1070 |
+
|
| 1071 |
+
url: string;
|
| 1072 |
+
|
| 1073 |
+
page_age?: string | null;
|
| 1074 |
+
}
|
| 1075 |
+
|
| 1076 |
+
export interface WebSearchTool20250305 {
|
| 1077 |
+
/**
|
| 1078 |
+
* Name of the tool.
|
| 1079 |
+
*
|
| 1080 |
+
* This is how the tool will be called by the model and in `tool_use` blocks.
|
| 1081 |
+
*/
|
| 1082 |
+
name: 'web_search';
|
| 1083 |
+
|
| 1084 |
+
type: 'web_search_20250305';
|
| 1085 |
+
|
| 1086 |
+
/**
|
| 1087 |
+
* If provided, only these domains will be included in results. Cannot be used
|
| 1088 |
+
* alongside `blocked_domains`.
|
| 1089 |
+
*/
|
| 1090 |
+
allowed_domains?: Array<string> | null;
|
| 1091 |
+
|
| 1092 |
+
/**
|
| 1093 |
+
* If provided, these domains will never appear in results. Cannot be used
|
| 1094 |
+
* alongside `allowed_domains`.
|
| 1095 |
+
*/
|
| 1096 |
+
blocked_domains?: Array<string> | null;
|
| 1097 |
+
|
| 1098 |
+
/**
|
| 1099 |
+
* Create a cache control breakpoint at this content block.
|
| 1100 |
+
*/
|
| 1101 |
+
cache_control?: CacheControlEphemeral | null;
|
| 1102 |
+
|
| 1103 |
+
/**
|
| 1104 |
+
* Maximum number of times the tool can be used in the API request.
|
| 1105 |
+
*/
|
| 1106 |
+
max_uses?: number | null;
|
| 1107 |
+
|
| 1108 |
+
/**
|
| 1109 |
+
* Parameters for the user's location. Used to provide more relevant search
|
| 1110 |
+
* results.
|
| 1111 |
+
*/
|
| 1112 |
+
user_location?: WebSearchTool20250305.UserLocation | null;
|
| 1113 |
+
}
|
| 1114 |
+
|
| 1115 |
+
export namespace WebSearchTool20250305 {
|
| 1116 |
+
/**
|
| 1117 |
+
* Parameters for the user's location. Used to provide more relevant search
|
| 1118 |
+
* results.
|
| 1119 |
+
*/
|
| 1120 |
+
export interface UserLocation {
|
| 1121 |
+
type: 'approximate';
|
| 1122 |
+
|
| 1123 |
+
/**
|
| 1124 |
+
* The city of the user.
|
| 1125 |
+
*/
|
| 1126 |
+
city?: string | null;
|
| 1127 |
+
|
| 1128 |
+
/**
|
| 1129 |
+
* The two letter
|
| 1130 |
+
* [ISO country code](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) of the
|
| 1131 |
+
* user.
|
| 1132 |
+
*/
|
| 1133 |
+
country?: string | null;
|
| 1134 |
+
|
| 1135 |
+
/**
|
| 1136 |
+
* The region of the user.
|
| 1137 |
+
*/
|
| 1138 |
+
region?: string | null;
|
| 1139 |
+
|
| 1140 |
+
/**
|
| 1141 |
+
* The [IANA timezone](https://nodatime.org/TimeZones) of the user.
|
| 1142 |
+
*/
|
| 1143 |
+
timezone?: string | null;
|
| 1144 |
+
}
|
| 1145 |
+
}
|
| 1146 |
+
|
| 1147 |
+
export interface WebSearchToolRequestError {
|
| 1148 |
+
error_code:
|
| 1149 |
+
| 'invalid_tool_input'
|
| 1150 |
+
| 'unavailable'
|
| 1151 |
+
| 'max_uses_exceeded'
|
| 1152 |
+
| 'too_many_requests'
|
| 1153 |
+
| 'query_too_long';
|
| 1154 |
+
|
| 1155 |
+
type: 'web_search_tool_result_error';
|
| 1156 |
+
}
|
| 1157 |
+
|
| 1158 |
+
export interface WebSearchToolResultBlock {
|
| 1159 |
+
content: WebSearchToolResultBlockContent;
|
| 1160 |
+
|
| 1161 |
+
tool_use_id: string;
|
| 1162 |
+
|
| 1163 |
+
type: 'web_search_tool_result';
|
| 1164 |
+
}
|
| 1165 |
+
|
| 1166 |
+
export type WebSearchToolResultBlockContent = WebSearchToolResultError | Array<WebSearchResultBlock>;
|
| 1167 |
+
|
| 1168 |
+
export interface WebSearchToolResultBlockParam {
|
| 1169 |
+
content: WebSearchToolResultBlockParamContent;
|
| 1170 |
+
|
| 1171 |
+
tool_use_id: string;
|
| 1172 |
+
|
| 1173 |
+
type: 'web_search_tool_result';
|
| 1174 |
+
|
| 1175 |
+
/**
|
| 1176 |
+
* Create a cache control breakpoint at this content block.
|
| 1177 |
+
*/
|
| 1178 |
+
cache_control?: CacheControlEphemeral | null;
|
| 1179 |
+
}
|
| 1180 |
+
|
| 1181 |
+
export type WebSearchToolResultBlockParamContent =
|
| 1182 |
+
| Array<WebSearchResultBlockParam>
|
| 1183 |
+
| WebSearchToolRequestError;
|
| 1184 |
+
|
| 1185 |
+
export interface WebSearchToolResultError {
|
| 1186 |
+
error_code:
|
| 1187 |
+
| 'invalid_tool_input'
|
| 1188 |
+
| 'unavailable'
|
| 1189 |
+
| 'max_uses_exceeded'
|
| 1190 |
+
| 'too_many_requests'
|
| 1191 |
+
| 'query_too_long';
|
| 1192 |
+
|
| 1193 |
+
type: 'web_search_tool_result_error';
|
| 1194 |
+
}
|
| 1195 |
+
|
| 1196 |
+
export type MessageStreamEvent = RawMessageStreamEvent;
|
| 1197 |
+
|
| 1198 |
+
export type MessageStartEvent = RawMessageStartEvent;
|
| 1199 |
+
|
| 1200 |
+
export type MessageDeltaEvent = RawMessageDeltaEvent;
|
| 1201 |
+
|
| 1202 |
+
export type MessageStopEvent = RawMessageStopEvent;
|
| 1203 |
+
|
| 1204 |
+
export type ContentBlockStartEvent = RawContentBlockStartEvent;
|
| 1205 |
+
|
| 1206 |
+
export type ContentBlockDeltaEvent = RawContentBlockDeltaEvent;
|
| 1207 |
+
|
| 1208 |
+
export type ContentBlockStopEvent = RawContentBlockStopEvent;
|
| 1209 |
+
|
| 1210 |
+
export type MessageCreateParams = MessageCreateParamsNonStreaming | MessageCreateParamsStreaming;
|
| 1211 |
+
|
| 1212 |
+
export interface MessageCreateParamsBase {
|
| 1213 |
+
/**
|
| 1214 |
+
* The maximum number of tokens to generate before stopping.
|
| 1215 |
+
*
|
| 1216 |
+
* Note that our models may stop _before_ reaching this maximum. This parameter
|
| 1217 |
+
* only specifies the absolute maximum number of tokens to generate.
|
| 1218 |
+
*
|
| 1219 |
+
* Different models have different maximum values for this parameter. See
|
| 1220 |
+
* [models](https://docs.anthropic.com/en/docs/models-overview) for details.
|
| 1221 |
+
*/
|
| 1222 |
+
max_tokens: number;
|
| 1223 |
+
|
| 1224 |
+
/**
|
| 1225 |
+
* Input messages.
|
| 1226 |
+
*
|
| 1227 |
+
* Our models are trained to operate on alternating `user` and `assistant`
|
| 1228 |
+
* conversational turns. When creating a new `Message`, you specify the prior
|
| 1229 |
+
* conversational turns with the `messages` parameter, and the model then generates
|
| 1230 |
+
* the next `Message` in the conversation. Consecutive `user` or `assistant` turns
|
| 1231 |
+
* in your request will be combined into a single turn.
|
| 1232 |
+
*
|
| 1233 |
+
* Each input message must be an object with a `role` and `content`. You can
|
| 1234 |
+
* specify a single `user`-role message, or you can include multiple `user` and
|
| 1235 |
+
* `assistant` messages.
|
| 1236 |
+
*
|
| 1237 |
+
* If the final message uses the `assistant` role, the response content will
|
| 1238 |
+
* continue immediately from the content in that message. This can be used to
|
| 1239 |
+
* constrain part of the model's response.
|
| 1240 |
+
*
|
| 1241 |
+
* Example with a single `user` message:
|
| 1242 |
+
*
|
| 1243 |
+
* ```json
|
| 1244 |
+
* [{ "role": "user", "content": "Hello, Claude" }]
|
| 1245 |
+
* ```
|
| 1246 |
+
*
|
| 1247 |
+
* Example with multiple conversational turns:
|
| 1248 |
+
*
|
| 1249 |
+
* ```json
|
| 1250 |
+
* [
|
| 1251 |
+
* { "role": "user", "content": "Hello there." },
|
| 1252 |
+
* { "role": "assistant", "content": "Hi, I'm Claude. How can I help you?" },
|
| 1253 |
+
* { "role": "user", "content": "Can you explain LLMs in plain English?" }
|
| 1254 |
+
* ]
|
| 1255 |
+
* ```
|
| 1256 |
+
*
|
| 1257 |
+
* Example with a partially-filled response from Claude:
|
| 1258 |
+
*
|
| 1259 |
+
* ```json
|
| 1260 |
+
* [
|
| 1261 |
+
* {
|
| 1262 |
+
* "role": "user",
|
| 1263 |
+
* "content": "What's the Greek name for Sun? (A) Sol (B) Helios (C) Sun"
|
| 1264 |
+
* },
|
| 1265 |
+
* { "role": "assistant", "content": "The best answer is (" }
|
| 1266 |
+
* ]
|
| 1267 |
+
* ```
|
| 1268 |
+
*
|
| 1269 |
+
* Each input message `content` may be either a single `string` or an array of
|
| 1270 |
+
* content blocks, where each block has a specific `type`. Using a `string` for
|
| 1271 |
+
* `content` is shorthand for an array of one content block of type `"text"`. The
|
| 1272 |
+
* following input messages are equivalent:
|
| 1273 |
+
*
|
| 1274 |
+
* ```json
|
| 1275 |
+
* { "role": "user", "content": "Hello, Claude" }
|
| 1276 |
+
* ```
|
| 1277 |
+
*
|
| 1278 |
+
* ```json
|
| 1279 |
+
* { "role": "user", "content": [{ "type": "text", "text": "Hello, Claude" }] }
|
| 1280 |
+
* ```
|
| 1281 |
+
*
|
| 1282 |
+
* Starting with Claude 3 models, you can also send image content blocks:
|
| 1283 |
+
*
|
| 1284 |
+
* ```json
|
| 1285 |
+
* {
|
| 1286 |
+
* "role": "user",
|
| 1287 |
+
* "content": [
|
| 1288 |
+
* {
|
| 1289 |
+
* "type": "image",
|
| 1290 |
+
* "source": {
|
| 1291 |
+
* "type": "base64",
|
| 1292 |
+
* "media_type": "image/jpeg",
|
| 1293 |
+
* "data": "/9j/4AAQSkZJRg..."
|
| 1294 |
+
* }
|
| 1295 |
+
* },
|
| 1296 |
+
* { "type": "text", "text": "What is in this image?" }
|
| 1297 |
+
* ]
|
| 1298 |
+
* }
|
| 1299 |
+
* ```
|
| 1300 |
+
*
|
| 1301 |
+
* We currently support the `base64` source type for images, and the `image/jpeg`,
|
| 1302 |
+
* `image/png`, `image/gif`, and `image/webp` media types.
|
| 1303 |
+
*
|
| 1304 |
+
* See [examples](https://docs.anthropic.com/en/api/messages-examples#vision) for
|
| 1305 |
+
* more input examples.
|
| 1306 |
+
*
|
| 1307 |
+
* Note that if you want to include a
|
| 1308 |
+
* [system prompt](https://docs.anthropic.com/en/docs/system-prompts), you can use
|
| 1309 |
+
* the top-level `system` parameter — there is no `"system"` role for input
|
| 1310 |
+
* messages in the Messages API.
|
| 1311 |
+
*
|
| 1312 |
+
* There is a limit of 100,000 messages in a single request.
|
| 1313 |
+
*/
|
| 1314 |
+
messages: Array<MessageParam>;
|
| 1315 |
+
|
| 1316 |
+
/**
|
| 1317 |
+
* The model that will complete your prompt.\n\nSee
|
| 1318 |
+
* [models](https://docs.anthropic.com/en/docs/models-overview) for additional
|
| 1319 |
+
* details and options.
|
| 1320 |
+
*/
|
| 1321 |
+
model: Model;
|
| 1322 |
+
|
| 1323 |
+
/**
|
| 1324 |
+
* An object describing metadata about the request.
|
| 1325 |
+
*/
|
| 1326 |
+
metadata?: Metadata;
|
| 1327 |
+
|
| 1328 |
+
/**
|
| 1329 |
+
* Determines whether to use priority capacity (if available) or standard capacity
|
| 1330 |
+
* for this request.
|
| 1331 |
+
*
|
| 1332 |
+
* Anthropic offers different levels of service for your API requests. See
|
| 1333 |
+
* [service-tiers](https://docs.anthropic.com/en/api/service-tiers) for details.
|
| 1334 |
+
*/
|
| 1335 |
+
service_tier?: 'auto' | 'standard_only';
|
| 1336 |
+
|
| 1337 |
+
/**
|
| 1338 |
+
* Custom text sequences that will cause the model to stop generating.
|
| 1339 |
+
*
|
| 1340 |
+
* Our models will normally stop when they have naturally completed their turn,
|
| 1341 |
+
* which will result in a response `stop_reason` of `"end_turn"`.
|
| 1342 |
+
*
|
| 1343 |
+
* If you want the model to stop generating when it encounters custom strings of
|
| 1344 |
+
* text, you can use the `stop_sequences` parameter. If the model encounters one of
|
| 1345 |
+
* the custom sequences, the response `stop_reason` value will be `"stop_sequence"`
|
| 1346 |
+
* and the response `stop_sequence` value will contain the matched stop sequence.
|
| 1347 |
+
*/
|
| 1348 |
+
stop_sequences?: Array<string>;
|
| 1349 |
+
|
| 1350 |
+
/**
|
| 1351 |
+
* Whether to incrementally stream the response using server-sent events.
|
| 1352 |
+
*
|
| 1353 |
+
* See [streaming](https://docs.anthropic.com/en/api/messages-streaming) for
|
| 1354 |
+
* details.
|
| 1355 |
+
*/
|
| 1356 |
+
stream?: boolean;
|
| 1357 |
+
|
| 1358 |
+
/**
|
| 1359 |
+
* System prompt.
|
| 1360 |
+
*
|
| 1361 |
+
* A system prompt is a way of providing context and instructions to Claude, such
|
| 1362 |
+
* as specifying a particular goal or role. See our
|
| 1363 |
+
* [guide to system prompts](https://docs.anthropic.com/en/docs/system-prompts).
|
| 1364 |
+
*/
|
| 1365 |
+
system?: string | Array<TextBlockParam>;
|
| 1366 |
+
|
| 1367 |
+
/**
|
| 1368 |
+
* Amount of randomness injected into the response.
|
| 1369 |
+
*
|
| 1370 |
+
* Defaults to `1.0`. Ranges from `0.0` to `1.0`. Use `temperature` closer to `0.0`
|
| 1371 |
+
* for analytical / multiple choice, and closer to `1.0` for creative and
|
| 1372 |
+
* generative tasks.
|
| 1373 |
+
*
|
| 1374 |
+
* Note that even with `temperature` of `0.0`, the results will not be fully
|
| 1375 |
+
* deterministic.
|
| 1376 |
+
*/
|
| 1377 |
+
temperature?: number;
|
| 1378 |
+
|
| 1379 |
+
/**
|
| 1380 |
+
* Configuration for enabling Claude's extended thinking.
|
| 1381 |
+
*
|
| 1382 |
+
* When enabled, responses include `thinking` content blocks showing Claude's
|
| 1383 |
+
* thinking process before the final answer. Requires a minimum budget of 1,024
|
| 1384 |
+
* tokens and counts towards your `max_tokens` limit.
|
| 1385 |
+
*
|
| 1386 |
+
* See
|
| 1387 |
+
* [extended thinking](https://docs.anthropic.com/en/docs/build-with-claude/extended-thinking)
|
| 1388 |
+
* for details.
|
| 1389 |
+
*/
|
| 1390 |
+
thinking?: ThinkingConfigParam;
|
| 1391 |
+
|
| 1392 |
+
/**
|
| 1393 |
+
* How the model should use the provided tools. The model can use a specific tool,
|
| 1394 |
+
* any available tool, decide by itself, or not use tools at all.
|
| 1395 |
+
*/
|
| 1396 |
+
tool_choice?: ToolChoice;
|
| 1397 |
+
|
| 1398 |
+
/**
|
| 1399 |
+
* Definitions of tools that the model may use.
|
| 1400 |
+
*
|
| 1401 |
+
* If you include `tools` in your API request, the model may return `tool_use`
|
| 1402 |
+
* content blocks that represent the model's use of those tools. You can then run
|
| 1403 |
+
* those tools using the tool input generated by the model and then optionally
|
| 1404 |
+
* return results back to the model using `tool_result` content blocks.
|
| 1405 |
+
*
|
| 1406 |
+
* There are two types of tools: **client tools** and **server tools**. The
|
| 1407 |
+
* behavior described below applies to client tools. For
|
| 1408 |
+
* [server tools](https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/overview#server-tools),
|
| 1409 |
+
* see their individual documentation as each has its own behavior (e.g., the
|
| 1410 |
+
* [web search tool](https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/web-search-tool)).
|
| 1411 |
+
*
|
| 1412 |
+
* Each tool definition includes:
|
| 1413 |
+
*
|
| 1414 |
+
* - `name`: Name of the tool.
|
| 1415 |
+
* - `description`: Optional, but strongly-recommended description of the tool.
|
| 1416 |
+
* - `input_schema`: [JSON schema](https://json-schema.org/draft/2020-12) for the
|
| 1417 |
+
* tool `input` shape that the model will produce in `tool_use` output content
|
| 1418 |
+
* blocks.
|
| 1419 |
+
*
|
| 1420 |
+
* For example, if you defined `tools` as:
|
| 1421 |
+
*
|
| 1422 |
+
* ```json
|
| 1423 |
+
* [
|
| 1424 |
+
* {
|
| 1425 |
+
* "name": "get_stock_price",
|
| 1426 |
+
* "description": "Get the current stock price for a given ticker symbol.",
|
| 1427 |
+
* "input_schema": {
|
| 1428 |
+
* "type": "object",
|
| 1429 |
+
* "properties": {
|
| 1430 |
+
* "ticker": {
|
| 1431 |
+
* "type": "string",
|
| 1432 |
+
* "description": "The stock ticker symbol, e.g. AAPL for Apple Inc."
|
| 1433 |
+
* }
|
| 1434 |
+
* },
|
| 1435 |
+
* "required": ["ticker"]
|
| 1436 |
+
* }
|
| 1437 |
+
* }
|
| 1438 |
+
* ]
|
| 1439 |
+
* ```
|
| 1440 |
+
*
|
| 1441 |
+
* And then asked the model "What's the S&P 500 at today?", the model might produce
|
| 1442 |
+
* `tool_use` content blocks in the response like this:
|
| 1443 |
+
*
|
| 1444 |
+
* ```json
|
| 1445 |
+
* [
|
| 1446 |
+
* {
|
| 1447 |
+
* "type": "tool_use",
|
| 1448 |
+
* "id": "toolu_01D7FLrfh4GYq7yT1ULFeyMV",
|
| 1449 |
+
* "name": "get_stock_price",
|
| 1450 |
+
* "input": { "ticker": "^GSPC" }
|
| 1451 |
+
* }
|
| 1452 |
+
* ]
|
| 1453 |
+
* ```
|
| 1454 |
+
*
|
| 1455 |
+
* You might then run your `get_stock_price` tool with `{"ticker": "^GSPC"}` as an
|
| 1456 |
+
* input, and return the following back to the model in a subsequent `user`
|
| 1457 |
+
* message:
|
| 1458 |
+
*
|
| 1459 |
+
* ```json
|
| 1460 |
+
* [
|
| 1461 |
+
* {
|
| 1462 |
+
* "type": "tool_result",
|
| 1463 |
+
* "tool_use_id": "toolu_01D7FLrfh4GYq7yT1ULFeyMV",
|
| 1464 |
+
* "content": "259.75 USD"
|
| 1465 |
+
* }
|
| 1466 |
+
* ]
|
| 1467 |
+
* ```
|
| 1468 |
+
*
|
| 1469 |
+
* Tools can be used for workflows that include running client-side tools and
|
| 1470 |
+
* functions, or more generally whenever you want the model to produce a particular
|
| 1471 |
+
* JSON structure of output.
|
| 1472 |
+
*
|
| 1473 |
+
* See our [guide](https://docs.anthropic.com/en/docs/tool-use) for more details.
|
| 1474 |
+
*/
|
| 1475 |
+
tools?: Array<ToolUnion>;
|
| 1476 |
+
|
| 1477 |
+
/**
|
| 1478 |
+
* Only sample from the top K options for each subsequent token.
|
| 1479 |
+
*
|
| 1480 |
+
* Used to remove "long tail" low probability responses.
|
| 1481 |
+
* [Learn more technical details here](https://towardsdatascience.com/how-to-sample-from-language-models-682bceb97277).
|
| 1482 |
+
*
|
| 1483 |
+
* Recommended for advanced use cases only. You usually only need to use
|
| 1484 |
+
* `temperature`.
|
| 1485 |
+
*/
|
| 1486 |
+
top_k?: number;
|
| 1487 |
+
|
| 1488 |
+
/**
|
| 1489 |
+
* Use nucleus sampling.
|
| 1490 |
+
*
|
| 1491 |
+
* In nucleus sampling, we compute the cumulative distribution over all the options
|
| 1492 |
+
* for each subsequent token in decreasing probability order and cut it off once it
|
| 1493 |
+
* reaches a particular probability specified by `top_p`. You should either alter
|
| 1494 |
+
* `temperature` or `top_p`, but not both.
|
| 1495 |
+
*
|
| 1496 |
+
* Recommended for advanced use cases only. You usually only need to use
|
| 1497 |
+
* `temperature`.
|
| 1498 |
+
*/
|
| 1499 |
+
top_p?: number;
|
| 1500 |
+
}
|
| 1501 |
+
|
| 1502 |
+
export namespace MessageCreateParams {
|
| 1503 |
+
export type MessageCreateParamsNonStreaming = MessagesAPI.MessageCreateParamsNonStreaming;
|
| 1504 |
+
export type MessageCreateParamsStreaming = MessagesAPI.MessageCreateParamsStreaming;
|
| 1505 |
+
}
|
| 1506 |
+
|
| 1507 |
+
export interface MessageCreateParamsNonStreaming extends MessageCreateParamsBase {
|
| 1508 |
+
/**
|
| 1509 |
+
* Whether to incrementally stream the response using server-sent events.
|
| 1510 |
+
*
|
| 1511 |
+
* See [streaming](https://docs.anthropic.com/en/api/messages-streaming) for
|
| 1512 |
+
* details.
|
| 1513 |
+
*/
|
| 1514 |
+
stream?: false;
|
| 1515 |
+
}
|
| 1516 |
+
|
| 1517 |
+
export interface MessageCreateParamsStreaming extends MessageCreateParamsBase {
|
| 1518 |
+
/**
|
| 1519 |
+
* Whether to incrementally stream the response using server-sent events.
|
| 1520 |
+
*
|
| 1521 |
+
* See [streaming](https://docs.anthropic.com/en/api/messages-streaming) for
|
| 1522 |
+
* details.
|
| 1523 |
+
*/
|
| 1524 |
+
stream: true;
|
| 1525 |
+
}
|
| 1526 |
+
|
| 1527 |
+
export type MessageStreamParams = MessageCreateParamsBase;
|
| 1528 |
+
|
| 1529 |
+
export interface MessageCountTokensParams {
|
| 1530 |
+
/**
|
| 1531 |
+
* Input messages.
|
| 1532 |
+
*
|
| 1533 |
+
* Our models are trained to operate on alternating `user` and `assistant`
|
| 1534 |
+
* conversational turns. When creating a new `Message`, you specify the prior
|
| 1535 |
+
* conversational turns with the `messages` parameter, and the model then generates
|
| 1536 |
+
* the next `Message` in the conversation. Consecutive `user` or `assistant` turns
|
| 1537 |
+
* in your request will be combined into a single turn.
|
| 1538 |
+
*
|
| 1539 |
+
* Each input message must be an object with a `role` and `content`. You can
|
| 1540 |
+
* specify a single `user`-role message, or you can include multiple `user` and
|
| 1541 |
+
* `assistant` messages.
|
| 1542 |
+
*
|
| 1543 |
+
* If the final message uses the `assistant` role, the response content will
|
| 1544 |
+
* continue immediately from the content in that message. This can be used to
|
| 1545 |
+
* constrain part of the model's response.
|
| 1546 |
+
*
|
| 1547 |
+
* Example with a single `user` message:
|
| 1548 |
+
*
|
| 1549 |
+
* ```json
|
| 1550 |
+
* [{ "role": "user", "content": "Hello, Claude" }]
|
| 1551 |
+
* ```
|
| 1552 |
+
*
|
| 1553 |
+
* Example with multiple conversational turns:
|
| 1554 |
+
*
|
| 1555 |
+
* ```json
|
| 1556 |
+
* [
|
| 1557 |
+
* { "role": "user", "content": "Hello there." },
|
| 1558 |
+
* { "role": "assistant", "content": "Hi, I'm Claude. How can I help you?" },
|
| 1559 |
+
* { "role": "user", "content": "Can you explain LLMs in plain English?" }
|
| 1560 |
+
* ]
|
| 1561 |
+
* ```
|
| 1562 |
+
*
|
| 1563 |
+
* Example with a partially-filled response from Claude:
|
| 1564 |
+
*
|
| 1565 |
+
* ```json
|
| 1566 |
+
* [
|
| 1567 |
+
* {
|
| 1568 |
+
* "role": "user",
|
| 1569 |
+
* "content": "What's the Greek name for Sun? (A) Sol (B) Helios (C) Sun"
|
| 1570 |
+
* },
|
| 1571 |
+
* { "role": "assistant", "content": "The best answer is (" }
|
| 1572 |
+
* ]
|
| 1573 |
+
* ```
|
| 1574 |
+
*
|
| 1575 |
+
* Each input message `content` may be either a single `string` or an array of
|
| 1576 |
+
* content blocks, where each block has a specific `type`. Using a `string` for
|
| 1577 |
+
* `content` is shorthand for an array of one content block of type `"text"`. The
|
| 1578 |
+
* following input messages are equivalent:
|
| 1579 |
+
*
|
| 1580 |
+
* ```json
|
| 1581 |
+
* { "role": "user", "content": "Hello, Claude" }
|
| 1582 |
+
* ```
|
| 1583 |
+
*
|
| 1584 |
+
* ```json
|
| 1585 |
+
* { "role": "user", "content": [{ "type": "text", "text": "Hello, Claude" }] }
|
| 1586 |
+
* ```
|
| 1587 |
+
*
|
| 1588 |
+
* Starting with Claude 3 models, you can also send image content blocks:
|
| 1589 |
+
*
|
| 1590 |
+
* ```json
|
| 1591 |
+
* {
|
| 1592 |
+
* "role": "user",
|
| 1593 |
+
* "content": [
|
| 1594 |
+
* {
|
| 1595 |
+
* "type": "image",
|
| 1596 |
+
* "source": {
|
| 1597 |
+
* "type": "base64",
|
| 1598 |
+
* "media_type": "image/jpeg",
|
| 1599 |
+
* "data": "/9j/4AAQSkZJRg..."
|
| 1600 |
+
* }
|
| 1601 |
+
* },
|
| 1602 |
+
* { "type": "text", "text": "What is in this image?" }
|
| 1603 |
+
* ]
|
| 1604 |
+
* }
|
| 1605 |
+
* ```
|
| 1606 |
+
*
|
| 1607 |
+
* We currently support the `base64` source type for images, and the `image/jpeg`,
|
| 1608 |
+
* `image/png`, `image/gif`, and `image/webp` media types.
|
| 1609 |
+
*
|
| 1610 |
+
* See [examples](https://docs.anthropic.com/en/api/messages-examples#vision) for
|
| 1611 |
+
* more input examples.
|
| 1612 |
+
*
|
| 1613 |
+
* Note that if you want to include a
|
| 1614 |
+
* [system prompt](https://docs.anthropic.com/en/docs/system-prompts), you can use
|
| 1615 |
+
* the top-level `system` parameter — there is no `"system"` role for input
|
| 1616 |
+
* messages in the Messages API.
|
| 1617 |
+
*
|
| 1618 |
+
* There is a limit of 100,000 messages in a single request.
|
| 1619 |
+
*/
|
| 1620 |
+
messages: Array<MessageParam>;
|
| 1621 |
+
|
| 1622 |
+
/**
|
| 1623 |
+
* The model that will complete your prompt.\n\nSee
|
| 1624 |
+
* [models](https://docs.anthropic.com/en/docs/models-overview) for additional
|
| 1625 |
+
* details and options.
|
| 1626 |
+
*/
|
| 1627 |
+
model: Model;
|
| 1628 |
+
|
| 1629 |
+
/**
|
| 1630 |
+
* System prompt.
|
| 1631 |
+
*
|
| 1632 |
+
* A system prompt is a way of providing context and instructions to Claude, such
|
| 1633 |
+
* as specifying a particular goal or role. See our
|
| 1634 |
+
* [guide to system prompts](https://docs.anthropic.com/en/docs/system-prompts).
|
| 1635 |
+
*/
|
| 1636 |
+
system?: string | Array<TextBlockParam>;
|
| 1637 |
+
|
| 1638 |
+
/**
|
| 1639 |
+
* Configuration for enabling Claude's extended thinking.
|
| 1640 |
+
*
|
| 1641 |
+
* When enabled, responses include `thinking` content blocks showing Claude's
|
| 1642 |
+
* thinking process before the final answer. Requires a minimum budget of 1,024
|
| 1643 |
+
* tokens and counts towards your `max_tokens` limit.
|
| 1644 |
+
*
|
| 1645 |
+
* See
|
| 1646 |
+
* [extended thinking](https://docs.anthropic.com/en/docs/build-with-claude/extended-thinking)
|
| 1647 |
+
* for details.
|
| 1648 |
+
*/
|
| 1649 |
+
thinking?: ThinkingConfigParam;
|
| 1650 |
+
|
| 1651 |
+
/**
|
| 1652 |
+
* How the model should use the provided tools. The model can use a specific tool,
|
| 1653 |
+
* any available tool, decide by itself, or not use tools at all.
|
| 1654 |
+
*/
|
| 1655 |
+
tool_choice?: ToolChoice;
|
| 1656 |
+
|
| 1657 |
+
/**
|
| 1658 |
+
* Definitions of tools that the model may use.
|
| 1659 |
+
*
|
| 1660 |
+
* If you include `tools` in your API request, the model may return `tool_use`
|
| 1661 |
+
* content blocks that represent the model's use of those tools. You can then run
|
| 1662 |
+
* those tools using the tool input generated by the model and then optionally
|
| 1663 |
+
* return results back to the model using `tool_result` content blocks.
|
| 1664 |
+
*
|
| 1665 |
+
* There are two types of tools: **client tools** and **server tools**. The
|
| 1666 |
+
* behavior described below applies to client tools. For
|
| 1667 |
+
* [server tools](https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/overview#server-tools),
|
| 1668 |
+
* see their individual documentation as each has its own behavior (e.g., the
|
| 1669 |
+
* [web search tool](https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/web-search-tool)).
|
| 1670 |
+
*
|
| 1671 |
+
* Each tool definition includes:
|
| 1672 |
+
*
|
| 1673 |
+
* - `name`: Name of the tool.
|
| 1674 |
+
* - `description`: Optional, but strongly-recommended description of the tool.
|
| 1675 |
+
* - `input_schema`: [JSON schema](https://json-schema.org/draft/2020-12) for the
|
| 1676 |
+
* tool `input` shape that the model will produce in `tool_use` output content
|
| 1677 |
+
* blocks.
|
| 1678 |
+
*
|
| 1679 |
+
* For example, if you defined `tools` as:
|
| 1680 |
+
*
|
| 1681 |
+
* ```json
|
| 1682 |
+
* [
|
| 1683 |
+
* {
|
| 1684 |
+
* "name": "get_stock_price",
|
| 1685 |
+
* "description": "Get the current stock price for a given ticker symbol.",
|
| 1686 |
+
* "input_schema": {
|
| 1687 |
+
* "type": "object",
|
| 1688 |
+
* "properties": {
|
| 1689 |
+
* "ticker": {
|
| 1690 |
+
* "type": "string",
|
| 1691 |
+
* "description": "The stock ticker symbol, e.g. AAPL for Apple Inc."
|
| 1692 |
+
* }
|
| 1693 |
+
* },
|
| 1694 |
+
* "required": ["ticker"]
|
| 1695 |
+
* }
|
| 1696 |
+
* }
|
| 1697 |
+
* ]
|
| 1698 |
+
* ```
|
| 1699 |
+
*
|
| 1700 |
+
* And then asked the model "What's the S&P 500 at today?", the model might produce
|
| 1701 |
+
* `tool_use` content blocks in the response like this:
|
| 1702 |
+
*
|
| 1703 |
+
* ```json
|
| 1704 |
+
* [
|
| 1705 |
+
* {
|
| 1706 |
+
* "type": "tool_use",
|
| 1707 |
+
* "id": "toolu_01D7FLrfh4GYq7yT1ULFeyMV",
|
| 1708 |
+
* "name": "get_stock_price",
|
| 1709 |
+
* "input": { "ticker": "^GSPC" }
|
| 1710 |
+
* }
|
| 1711 |
+
* ]
|
| 1712 |
+
* ```
|
| 1713 |
+
*
|
| 1714 |
+
* You might then run your `get_stock_price` tool with `{"ticker": "^GSPC"}` as an
|
| 1715 |
+
* input, and return the following back to the model in a subsequent `user`
|
| 1716 |
+
* message:
|
| 1717 |
+
*
|
| 1718 |
+
* ```json
|
| 1719 |
+
* [
|
| 1720 |
+
* {
|
| 1721 |
+
* "type": "tool_result",
|
| 1722 |
+
* "tool_use_id": "toolu_01D7FLrfh4GYq7yT1ULFeyMV",
|
| 1723 |
+
* "content": "259.75 USD"
|
| 1724 |
+
* }
|
| 1725 |
+
* ]
|
| 1726 |
+
* ```
|
| 1727 |
+
*
|
| 1728 |
+
* Tools can be used for workflows that include running client-side tools and
|
| 1729 |
+
* functions, or more generally whenever you want the model to produce a particular
|
| 1730 |
+
* JSON structure of output.
|
| 1731 |
+
*
|
| 1732 |
+
* See our [guide](https://docs.anthropic.com/en/docs/tool-use) for more details.
|
| 1733 |
+
*/
|
| 1734 |
+
tools?: Array<MessageCountTokensTool>;
|
| 1735 |
+
}
|
| 1736 |
+
|
| 1737 |
+
Messages.Batches = Batches;
|
| 1738 |
+
|
| 1739 |
+
export declare namespace Messages {
|
| 1740 |
+
export {
|
| 1741 |
+
type Base64ImageSource as Base64ImageSource,
|
| 1742 |
+
type Base64PDFSource as Base64PDFSource,
|
| 1743 |
+
type CacheControlEphemeral as CacheControlEphemeral,
|
| 1744 |
+
type CitationCharLocation as CitationCharLocation,
|
| 1745 |
+
type CitationCharLocationParam as CitationCharLocationParam,
|
| 1746 |
+
type CitationContentBlockLocation as CitationContentBlockLocation,
|
| 1747 |
+
type CitationContentBlockLocationParam as CitationContentBlockLocationParam,
|
| 1748 |
+
type CitationPageLocation as CitationPageLocation,
|
| 1749 |
+
type CitationPageLocationParam as CitationPageLocationParam,
|
| 1750 |
+
type CitationWebSearchResultLocationParam as CitationWebSearchResultLocationParam,
|
| 1751 |
+
type CitationsConfigParam as CitationsConfigParam,
|
| 1752 |
+
type CitationsDelta as CitationsDelta,
|
| 1753 |
+
type CitationsWebSearchResultLocation as CitationsWebSearchResultLocation,
|
| 1754 |
+
type ContentBlock as ContentBlock,
|
| 1755 |
+
type ContentBlockParam as ContentBlockParam,
|
| 1756 |
+
type ContentBlockStartEvent as ContentBlockStartEvent,
|
| 1757 |
+
type ContentBlockStopEvent as ContentBlockStopEvent,
|
| 1758 |
+
type ContentBlockSource as ContentBlockSource,
|
| 1759 |
+
type ContentBlockSourceContent as ContentBlockSourceContent,
|
| 1760 |
+
type DocumentBlockParam as DocumentBlockParam,
|
| 1761 |
+
type ImageBlockParam as ImageBlockParam,
|
| 1762 |
+
type InputJSONDelta as InputJSONDelta,
|
| 1763 |
+
type Message as Message,
|
| 1764 |
+
type MessageCountTokensTool as MessageCountTokensTool,
|
| 1765 |
+
type MessageDeltaEvent as MessageDeltaEvent,
|
| 1766 |
+
type MessageDeltaUsage as MessageDeltaUsage,
|
| 1767 |
+
type MessageParam as MessageParam,
|
| 1768 |
+
type MessageTokensCount as MessageTokensCount,
|
| 1769 |
+
type Metadata as Metadata,
|
| 1770 |
+
type Model as Model,
|
| 1771 |
+
type PlainTextSource as PlainTextSource,
|
| 1772 |
+
type RawContentBlockDelta as RawContentBlockDelta,
|
| 1773 |
+
type RawContentBlockDeltaEvent as RawContentBlockDeltaEvent,
|
| 1774 |
+
type RawContentBlockStartEvent as RawContentBlockStartEvent,
|
| 1775 |
+
type RawContentBlockStopEvent as RawContentBlockStopEvent,
|
| 1776 |
+
type RawMessageDeltaEvent as RawMessageDeltaEvent,
|
| 1777 |
+
type RawMessageStartEvent as RawMessageStartEvent,
|
| 1778 |
+
type RawMessageStopEvent as RawMessageStopEvent,
|
| 1779 |
+
type RawMessageStreamEvent as RawMessageStreamEvent,
|
| 1780 |
+
type RedactedThinkingBlock as RedactedThinkingBlock,
|
| 1781 |
+
type RedactedThinkingBlockParam as RedactedThinkingBlockParam,
|
| 1782 |
+
type ServerToolUsage as ServerToolUsage,
|
| 1783 |
+
type ServerToolUseBlock as ServerToolUseBlock,
|
| 1784 |
+
type ServerToolUseBlockParam as ServerToolUseBlockParam,
|
| 1785 |
+
type SignatureDelta as SignatureDelta,
|
| 1786 |
+
type StopReason as StopReason,
|
| 1787 |
+
type TextBlock as TextBlock,
|
| 1788 |
+
type TextBlockParam as TextBlockParam,
|
| 1789 |
+
type TextCitation as TextCitation,
|
| 1790 |
+
type TextCitationParam as TextCitationParam,
|
| 1791 |
+
type TextDelta as TextDelta,
|
| 1792 |
+
type ThinkingBlock as ThinkingBlock,
|
| 1793 |
+
type ThinkingBlockParam as ThinkingBlockParam,
|
| 1794 |
+
type ThinkingConfigDisabled as ThinkingConfigDisabled,
|
| 1795 |
+
type ThinkingConfigEnabled as ThinkingConfigEnabled,
|
| 1796 |
+
type ThinkingConfigParam as ThinkingConfigParam,
|
| 1797 |
+
type ThinkingDelta as ThinkingDelta,
|
| 1798 |
+
type Tool as Tool,
|
| 1799 |
+
type ToolBash20250124 as ToolBash20250124,
|
| 1800 |
+
type ToolChoice as ToolChoice,
|
| 1801 |
+
type ToolChoiceAny as ToolChoiceAny,
|
| 1802 |
+
type ToolChoiceAuto as ToolChoiceAuto,
|
| 1803 |
+
type ToolChoiceNone as ToolChoiceNone,
|
| 1804 |
+
type ToolChoiceTool as ToolChoiceTool,
|
| 1805 |
+
type ToolResultBlockParam as ToolResultBlockParam,
|
| 1806 |
+
type ToolTextEditor20250124 as ToolTextEditor20250124,
|
| 1807 |
+
type ToolUnion as ToolUnion,
|
| 1808 |
+
type ToolUseBlock as ToolUseBlock,
|
| 1809 |
+
type ToolUseBlockParam as ToolUseBlockParam,
|
| 1810 |
+
type URLImageSource as URLImageSource,
|
| 1811 |
+
type URLPDFSource as URLPDFSource,
|
| 1812 |
+
type Usage as Usage,
|
| 1813 |
+
type WebSearchResultBlock as WebSearchResultBlock,
|
| 1814 |
+
type WebSearchResultBlockParam as WebSearchResultBlockParam,
|
| 1815 |
+
type WebSearchTool20250305 as WebSearchTool20250305,
|
| 1816 |
+
type WebSearchToolRequestError as WebSearchToolRequestError,
|
| 1817 |
+
type WebSearchToolResultBlock as WebSearchToolResultBlock,
|
| 1818 |
+
type WebSearchToolResultBlockContent as WebSearchToolResultBlockContent,
|
| 1819 |
+
type WebSearchToolResultBlockParam as WebSearchToolResultBlockParam,
|
| 1820 |
+
type WebSearchToolResultBlockParamContent as WebSearchToolResultBlockParamContent,
|
| 1821 |
+
type WebSearchToolResultError as WebSearchToolResultError,
|
| 1822 |
+
type MessageStreamEvent as MessageStreamEvent,
|
| 1823 |
+
type MessageStartEvent as MessageStartEvent,
|
| 1824 |
+
type MessageStopEvent as MessageStopEvent,
|
| 1825 |
+
type ContentBlockDeltaEvent as ContentBlockDeltaEvent,
|
| 1826 |
+
type MessageCreateParams as MessageCreateParams,
|
| 1827 |
+
type MessageCreateParamsNonStreaming as MessageCreateParamsNonStreaming,
|
| 1828 |
+
type MessageCreateParamsStreaming as MessageCreateParamsStreaming,
|
| 1829 |
+
type MessageStreamParams as MessageStreamParams,
|
| 1830 |
+
type MessageCountTokensParams as MessageCountTokensParams,
|
| 1831 |
+
};
|
| 1832 |
+
|
| 1833 |
+
export {
|
| 1834 |
+
Batches as Batches,
|
| 1835 |
+
type DeletedMessageBatch as DeletedMessageBatch,
|
| 1836 |
+
type MessageBatch as MessageBatch,
|
| 1837 |
+
type MessageBatchCanceledResult as MessageBatchCanceledResult,
|
| 1838 |
+
type MessageBatchErroredResult as MessageBatchErroredResult,
|
| 1839 |
+
type MessageBatchExpiredResult as MessageBatchExpiredResult,
|
| 1840 |
+
type MessageBatchIndividualResponse as MessageBatchIndividualResponse,
|
| 1841 |
+
type MessageBatchRequestCounts as MessageBatchRequestCounts,
|
| 1842 |
+
type MessageBatchResult as MessageBatchResult,
|
| 1843 |
+
type MessageBatchSucceededResult as MessageBatchSucceededResult,
|
| 1844 |
+
type MessageBatchesPage as MessageBatchesPage,
|
| 1845 |
+
type BatchCreateParams as BatchCreateParams,
|
| 1846 |
+
type BatchListParams as BatchListParams,
|
| 1847 |
+
};
|
| 1848 |
+
}
|
node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/resources/models.ts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
| 2 |
+
|
| 3 |
+
import { APIResource } from '../core/resource';
|
| 4 |
+
import * as BetaAPI from './beta/beta';
|
| 5 |
+
import { APIPromise } from '../core/api-promise';
|
| 6 |
+
import { Page, type PageParams, PagePromise } from '../core/pagination';
|
| 7 |
+
import { buildHeaders } from '../internal/headers';
|
| 8 |
+
import { RequestOptions } from '../internal/request-options';
|
| 9 |
+
import { path } from '../internal/utils/path';
|
| 10 |
+
|
| 11 |
+
export class Models extends APIResource {
|
| 12 |
+
/**
|
| 13 |
+
* Get a specific model.
|
| 14 |
+
*
|
| 15 |
+
* The Models API response can be used to determine information about a specific
|
| 16 |
+
* model or resolve a model alias to a model ID.
|
| 17 |
+
*/
|
| 18 |
+
retrieve(
|
| 19 |
+
modelID: string,
|
| 20 |
+
params: ModelRetrieveParams | null | undefined = {},
|
| 21 |
+
options?: RequestOptions,
|
| 22 |
+
): APIPromise<ModelInfo> {
|
| 23 |
+
const { betas } = params ?? {};
|
| 24 |
+
return this._client.get(path`/v1/models/${modelID}`, {
|
| 25 |
+
...options,
|
| 26 |
+
headers: buildHeaders([
|
| 27 |
+
{ ...(betas?.toString() != null ? { 'anthropic-beta': betas?.toString() } : undefined) },
|
| 28 |
+
options?.headers,
|
| 29 |
+
]),
|
| 30 |
+
});
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
/**
|
| 34 |
+
* List available models.
|
| 35 |
+
*
|
| 36 |
+
* The Models API response can be used to determine which models are available for
|
| 37 |
+
* use in the API. More recently released models are listed first.
|
| 38 |
+
*/
|
| 39 |
+
list(
|
| 40 |
+
params: ModelListParams | null | undefined = {},
|
| 41 |
+
options?: RequestOptions,
|
| 42 |
+
): PagePromise<ModelInfosPage, ModelInfo> {
|
| 43 |
+
const { betas, ...query } = params ?? {};
|
| 44 |
+
return this._client.getAPIList('/v1/models', Page<ModelInfo>, {
|
| 45 |
+
query,
|
| 46 |
+
...options,
|
| 47 |
+
headers: buildHeaders([
|
| 48 |
+
{ ...(betas?.toString() != null ? { 'anthropic-beta': betas?.toString() } : undefined) },
|
| 49 |
+
options?.headers,
|
| 50 |
+
]),
|
| 51 |
+
});
|
| 52 |
+
}
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
export type ModelInfosPage = Page<ModelInfo>;
|
| 56 |
+
|
| 57 |
+
export interface ModelInfo {
|
| 58 |
+
/**
|
| 59 |
+
* Unique model identifier.
|
| 60 |
+
*/
|
| 61 |
+
id: string;
|
| 62 |
+
|
| 63 |
+
/**
|
| 64 |
+
* RFC 3339 datetime string representing the time at which the model was released.
|
| 65 |
+
* May be set to an epoch value if the release date is unknown.
|
| 66 |
+
*/
|
| 67 |
+
created_at: string;
|
| 68 |
+
|
| 69 |
+
/**
|
| 70 |
+
* A human-readable name for the model.
|
| 71 |
+
*/
|
| 72 |
+
display_name: string;
|
| 73 |
+
|
| 74 |
+
/**
|
| 75 |
+
* Object type.
|
| 76 |
+
*
|
| 77 |
+
* For Models, this is always `"model"`.
|
| 78 |
+
*/
|
| 79 |
+
type: 'model';
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
export interface ModelRetrieveParams {
|
| 83 |
+
/**
|
| 84 |
+
* Optional header to specify the beta version(s) you want to use.
|
| 85 |
+
*/
|
| 86 |
+
betas?: Array<BetaAPI.AnthropicBeta>;
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
export interface ModelListParams extends PageParams {
|
| 90 |
+
/**
|
| 91 |
+
* Header param: Optional header to specify the beta version(s) you want to use.
|
| 92 |
+
*/
|
| 93 |
+
betas?: Array<BetaAPI.AnthropicBeta>;
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
export declare namespace Models {
|
| 97 |
+
export {
|
| 98 |
+
type ModelInfo as ModelInfo,
|
| 99 |
+
type ModelInfosPage as ModelInfosPage,
|
| 100 |
+
type ModelRetrieveParams as ModelRetrieveParams,
|
| 101 |
+
type ModelListParams as ModelListParams,
|
| 102 |
+
};
|
| 103 |
+
}
|
node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/resources/shared.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
| 2 |
+
|
| 3 |
+
export interface APIErrorObject {
|
| 4 |
+
message: string;
|
| 5 |
+
|
| 6 |
+
type: 'api_error';
|
| 7 |
+
}
|
| 8 |
+
|
| 9 |
+
export interface AuthenticationError {
|
| 10 |
+
message: string;
|
| 11 |
+
|
| 12 |
+
type: 'authentication_error';
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
export interface BillingError {
|
| 16 |
+
message: string;
|
| 17 |
+
|
| 18 |
+
type: 'billing_error';
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
export type ErrorObject =
|
| 22 |
+
| InvalidRequestError
|
| 23 |
+
| AuthenticationError
|
| 24 |
+
| BillingError
|
| 25 |
+
| PermissionError
|
| 26 |
+
| NotFoundError
|
| 27 |
+
| RateLimitError
|
| 28 |
+
| GatewayTimeoutError
|
| 29 |
+
| APIErrorObject
|
| 30 |
+
| OverloadedError;
|
| 31 |
+
|
| 32 |
+
export interface ErrorResponse {
|
| 33 |
+
error: ErrorObject;
|
| 34 |
+
|
| 35 |
+
type: 'error';
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
export interface GatewayTimeoutError {
|
| 39 |
+
message: string;
|
| 40 |
+
|
| 41 |
+
type: 'timeout_error';
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
export interface InvalidRequestError {
|
| 45 |
+
message: string;
|
| 46 |
+
|
| 47 |
+
type: 'invalid_request_error';
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
export interface NotFoundError {
|
| 51 |
+
message: string;
|
| 52 |
+
|
| 53 |
+
type: 'not_found_error';
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
export interface OverloadedError {
|
| 57 |
+
message: string;
|
| 58 |
+
|
| 59 |
+
type: 'overloaded_error';
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
export interface PermissionError {
|
| 63 |
+
message: string;
|
| 64 |
+
|
| 65 |
+
type: 'permission_error';
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
export interface RateLimitError {
|
| 69 |
+
message: string;
|
| 70 |
+
|
| 71 |
+
type: 'rate_limit_error';
|
| 72 |
+
}
|
node_modules/.pnpm/@anthropic-ai+sdk@0.57.0/node_modules/@anthropic-ai/sdk/src/resources/top-level.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
| 2 |
+
|
| 3 |
+
export {};
|