@anthropic-ai/sdk 0.6.1 → 0.6.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +127 -0
- package/README.md +16 -6
- package/_shims/MultipartBody.d.ts +9 -0
- package/_shims/MultipartBody.d.ts.map +1 -0
- package/_shims/MultipartBody.js +16 -0
- package/_shims/MultipartBody.js.map +1 -0
- package/_shims/MultipartBody.mjs +12 -0
- package/_shims/MultipartBody.mjs.map +1 -0
- package/_shims/README.md +46 -0
- package/{src/_shims/ReadableStream.node.ts → _shims/auto/runtime-bun.d.ts} +2 -3
- package/_shims/auto/runtime-bun.d.ts.map +1 -0
- package/_shims/auto/runtime-bun.js +21 -0
- package/_shims/auto/runtime-bun.js.map +1 -0
- package/_shims/auto/runtime-bun.mjs +2 -0
- package/_shims/auto/runtime-bun.mjs.map +1 -0
- package/_shims/auto/runtime-node.d.ts +5 -0
- package/_shims/auto/runtime-node.d.ts.map +1 -0
- package/_shims/auto/runtime-node.js +21 -0
- package/_shims/auto/runtime-node.js.map +1 -0
- package/_shims/auto/runtime-node.mjs +2 -0
- package/_shims/auto/runtime-node.mjs.map +1 -0
- package/_shims/auto/runtime.d.ts +5 -0
- package/_shims/auto/runtime.d.ts.map +1 -0
- package/_shims/auto/runtime.js +21 -0
- package/_shims/auto/runtime.js.map +1 -0
- package/_shims/auto/runtime.mjs +2 -0
- package/_shims/auto/runtime.mjs.map +1 -0
- package/_shims/auto/types-node.d.ts +5 -0
- package/_shims/auto/types-node.d.ts.map +1 -0
- package/_shims/auto/types-node.js +21 -0
- package/_shims/auto/types-node.js.map +1 -0
- package/_shims/auto/types-node.mjs +2 -0
- package/_shims/auto/types-node.mjs.map +1 -0
- package/_shims/auto/types.d.ts +101 -0
- package/{src/_shims/ReadableStream.js → _shims/auto/types.js} +0 -2
- package/_shims/{ReadableStream.js → auto/types.mjs} +0 -2
- package/_shims/bun-runtime.d.ts +6 -0
- package/_shims/bun-runtime.d.ts.map +1 -0
- package/_shims/bun-runtime.js +14 -0
- package/_shims/bun-runtime.js.map +1 -0
- package/_shims/bun-runtime.mjs +10 -0
- package/_shims/bun-runtime.mjs.map +1 -0
- package/_shims/index.d.ts +81 -0
- package/_shims/index.js +13 -0
- package/_shims/index.mjs +7 -0
- package/_shims/manual-types.d.ts +12 -0
- package/_shims/manual-types.js +3 -0
- package/_shims/manual-types.mjs +3 -0
- package/_shims/node-runtime.d.ts +3 -0
- package/_shims/node-runtime.d.ts.map +1 -0
- package/_shims/node-runtime.js +89 -0
- package/_shims/node-runtime.js.map +1 -0
- package/_shims/node-runtime.mjs +56 -0
- package/_shims/node-runtime.mjs.map +1 -0
- package/_shims/node-types.d.ts +42 -0
- package/_shims/node-types.js +3 -0
- package/_shims/node-types.mjs +3 -0
- package/_shims/registry.d.ts +37 -0
- package/_shims/registry.d.ts.map +1 -0
- package/_shims/registry.js +41 -0
- package/_shims/registry.js.map +1 -0
- package/_shims/registry.mjs +37 -0
- package/_shims/registry.mjs.map +1 -0
- package/_shims/web-runtime.d.ts +5 -0
- package/_shims/web-runtime.d.ts.map +1 -0
- package/_shims/web-runtime.js +78 -0
- package/_shims/web-runtime.js.map +1 -0
- package/_shims/web-runtime.mjs +71 -0
- package/_shims/web-runtime.mjs.map +1 -0
- package/_shims/web-types.d.ts +83 -0
- package/_shims/web-types.js +3 -0
- package/_shims/web-types.mjs +3 -0
- package/core.d.ts +172 -216
- package/core.d.ts.map +1 -1
- package/core.js +701 -729
- package/core.js.map +1 -1
- package/core.mjs +694 -681
- package/core.mjs.map +1 -1
- package/error.d.ts +32 -32
- package/error.d.ts.map +1 -1
- package/error.js +105 -106
- package/error.js.map +1 -1
- package/error.mjs +101 -91
- package/error.mjs.map +1 -1
- package/index.d.mts +110 -117
- package/index.d.ts +110 -117
- package/index.d.ts.map +1 -1
- package/index.js +107 -160
- package/index.js.map +1 -1
- package/index.mjs +84 -105
- package/index.mjs.map +1 -1
- package/package.json +36 -21
- package/resource.d.ts +10 -10
- package/resource.js +12 -12
- package/resource.mjs +10 -10
- package/resources/completions.d.ts +136 -142
- package/resources/completions.d.ts.map +1 -1
- package/resources/completions.js +9 -14
- package/resources/completions.js.map +1 -1
- package/resources/completions.mjs +6 -11
- package/resources/completions.mjs.map +1 -1
- package/resources/index.d.ts +2 -9
- package/resources/index.d.ts.map +1 -1
- package/resources/index.js +5 -10
- package/resources/index.js.map +1 -1
- package/resources/index.mjs +2 -2
- package/resources/index.mjs.map +1 -1
- package/resources/top-level.d.ts +1 -1
- package/resources/top-level.js +3 -3
- package/resources/top-level.mjs +1 -1
- package/shims/node.d.ts +29 -0
- package/shims/node.d.ts.map +1 -0
- package/shims/node.js +31 -0
- package/shims/node.js.map +1 -0
- package/shims/node.mjs +5 -0
- package/shims/node.mjs.map +1 -0
- package/shims/web.d.ts +26 -0
- package/shims/web.d.ts.map +1 -0
- package/shims/web.js +31 -0
- package/shims/web.js.map +1 -0
- package/shims/web.mjs +5 -0
- package/shims/web.mjs.map +1 -0
- package/src/_shims/MultipartBody.ts +9 -0
- package/src/_shims/README.md +46 -0
- package/src/_shims/auto/runtime-bun.ts +4 -0
- package/src/_shims/auto/runtime-node.ts +4 -0
- package/src/_shims/auto/runtime.ts +4 -0
- package/src/_shims/auto/types-node.ts +4 -0
- package/src/_shims/auto/types.d.ts +101 -0
- package/src/_shims/auto/types.js +3 -0
- package/src/_shims/auto/types.mjs +3 -0
- package/src/_shims/bun-runtime.ts +14 -0
- package/src/_shims/index.d.ts +81 -0
- package/src/_shims/index.js +13 -0
- package/src/_shims/index.mjs +7 -0
- package/src/_shims/manual-types.d.ts +12 -0
- package/src/_shims/manual-types.js +3 -0
- package/src/_shims/manual-types.mjs +3 -0
- package/src/_shims/node-runtime.ts +81 -0
- package/src/_shims/node-types.d.ts +42 -0
- package/src/_shims/node-types.js +3 -0
- package/src/_shims/node-types.mjs +3 -0
- package/src/_shims/registry.ts +67 -0
- package/src/_shims/web-runtime.ts +103 -0
- package/src/_shims/web-types.d.ts +83 -0
- package/src/_shims/web-types.js +3 -0
- package/src/_shims/web-types.mjs +3 -0
- package/src/core.ts +124 -61
- package/src/error.ts +20 -8
- package/src/index.ts +27 -22
- package/src/resources/completions.ts +11 -11
- package/src/resources/index.ts +0 -1
- package/src/shims/node.ts +50 -0
- package/src/shims/web.ts +50 -0
- package/src/streaming.ts +166 -56
- package/src/tsconfig.json +11 -0
- package/src/uploads.ts +11 -15
- package/src/version.ts +1 -1
- package/streaming.d.ts +11 -8
- package/streaming.d.ts.map +1 -1
- package/streaming.js +300 -192
- package/streaming.js.map +1 -1
- package/streaming.mjs +296 -188
- package/streaming.mjs.map +1 -1
- package/uploads.d.ts +23 -39
- package/uploads.d.ts.map +1 -1
- package/uploads.js +111 -157
- package/uploads.js.map +1 -1
- package/uploads.mjs +107 -133
- package/uploads.mjs.map +1 -1
- package/version.d.ts +2 -2
- package/version.js +4 -4
- package/version.mjs +2 -2
- package/_shims/ReadableStream.d.ts +0 -38
- package/_shims/ReadableStream.mjs +0 -7
- package/_shims/ReadableStream.node.d.ts +0 -6
- package/_shims/ReadableStream.node.d.ts.map +0 -1
- package/_shims/ReadableStream.node.js +0 -14
- package/_shims/ReadableStream.node.js.map +0 -1
- package/_shims/ReadableStream.node.mjs +0 -3
- package/_shims/ReadableStream.node.mjs.map +0 -1
- package/_shims/agent.d.ts +0 -9
- package/_shims/agent.d.ts.map +0 -1
- package/_shims/agent.js +0 -14
- package/_shims/agent.js.map +0 -1
- package/_shims/agent.mjs +0 -10
- package/_shims/agent.mjs.map +0 -1
- package/_shims/agent.node.d.ts +0 -7
- package/_shims/agent.node.d.ts.map +0 -1
- package/_shims/agent.node.js +0 -28
- package/_shims/agent.node.js.map +0 -1
- package/_shims/agent.node.mjs +0 -16
- package/_shims/agent.node.mjs.map +0 -1
- package/_shims/fetch.d.ts +0 -59
- package/_shims/fetch.js +0 -13
- package/_shims/fetch.mjs +0 -15
- package/_shims/fetch.node.d.ts +0 -63
- package/_shims/fetch.node.js +0 -12
- package/_shims/fetch.node.mjs +0 -14
- package/_shims/fileFromPath.d.ts +0 -22
- package/_shims/fileFromPath.d.ts.map +0 -1
- package/_shims/fileFromPath.js +0 -16
- package/_shims/fileFromPath.js.map +0 -1
- package/_shims/fileFromPath.mjs +0 -12
- package/_shims/fileFromPath.mjs.map +0 -1
- package/_shims/fileFromPath.node.d.ts +0 -17
- package/_shims/fileFromPath.node.d.ts.map +0 -1
- package/_shims/fileFromPath.node.js +0 -17
- package/_shims/fileFromPath.node.js.map +0 -1
- package/_shims/fileFromPath.node.mjs +0 -13
- package/_shims/fileFromPath.node.mjs.map +0 -1
- package/_shims/formdata.d.ts +0 -43
- package/_shims/formdata.js +0 -17
- package/_shims/formdata.mjs +0 -20
- package/_shims/formdata.node.d.ts +0 -45
- package/_shims/formdata.node.js +0 -11
- package/_shims/formdata.node.mjs +0 -9
- package/_shims/getMultipartRequestOptions.d.ts +0 -10
- package/_shims/getMultipartRequestOptions.d.ts.map +0 -1
- package/_shims/getMultipartRequestOptions.js +0 -12
- package/_shims/getMultipartRequestOptions.js.map +0 -1
- package/_shims/getMultipartRequestOptions.mjs +0 -8
- package/_shims/getMultipartRequestOptions.mjs.map +0 -1
- package/_shims/getMultipartRequestOptions.node.d.ts +0 -10
- package/_shims/getMultipartRequestOptions.node.d.ts.map +0 -1
- package/_shims/getMultipartRequestOptions.node.js +0 -22
- package/_shims/getMultipartRequestOptions.node.js.map +0 -1
- package/_shims/getMultipartRequestOptions.node.mjs +0 -18
- package/_shims/getMultipartRequestOptions.node.mjs.map +0 -1
- package/_shims/node-readable.d.ts +0 -23
- package/_shims/node-readable.d.ts.map +0 -1
- package/_shims/node-readable.js +0 -11
- package/_shims/node-readable.js.map +0 -1
- package/_shims/node-readable.mjs +0 -7
- package/_shims/node-readable.mjs.map +0 -1
- package/_shims/node-readable.node.d.ts +0 -8
- package/_shims/node-readable.node.d.ts.map +0 -1
- package/_shims/node-readable.node.js +0 -9
- package/_shims/node-readable.node.js.map +0 -1
- package/_shims/node-readable.node.mjs +0 -5
- package/_shims/node-readable.node.mjs.map +0 -1
- package/src/_shims/ReadableStream.d.ts +0 -38
- package/src/_shims/ReadableStream.mjs +0 -7
- package/src/_shims/agent.node.ts +0 -22
- package/src/_shims/agent.ts +0 -12
- package/src/_shims/fetch.d.ts +0 -59
- package/src/_shims/fetch.deno.ts +0 -23
- package/src/_shims/fetch.js +0 -13
- package/src/_shims/fetch.mjs +0 -15
- package/src/_shims/fetch.node.d.ts +0 -63
- package/src/_shims/fetch.node.js +0 -12
- package/src/_shims/fetch.node.mjs +0 -14
- package/src/_shims/fileFromPath.node.ts +0 -29
- package/src/_shims/fileFromPath.ts +0 -29
- package/src/_shims/formdata.d.ts +0 -43
- package/src/_shims/formdata.deno.ts +0 -16
- package/src/_shims/formdata.js +0 -17
- package/src/_shims/formdata.mjs +0 -20
- package/src/_shims/formdata.node.d.ts +0 -45
- package/src/_shims/formdata.node.js +0 -11
- package/src/_shims/formdata.node.mjs +0 -9
- package/src/_shims/getMultipartRequestOptions.node.ts +0 -25
- package/src/_shims/getMultipartRequestOptions.ts +0 -14
- package/src/_shims/node-readable.node.ts +0 -10
- package/src/_shims/node-readable.ts +0 -30
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Disclaimer: modules in _shims aren't intended to be imported by SDK users.
|
|
3
|
+
*/
|
|
4
|
+
export type Agent = any;
|
|
5
|
+
|
|
6
|
+
declare const _fetch: typeof fetch;
|
|
7
|
+
export { _fetch as fetch };
|
|
8
|
+
|
|
9
|
+
type _Request = Request;
|
|
10
|
+
export { _Request as Request };
|
|
11
|
+
|
|
12
|
+
type _RequestInfo = RequestInfo;
|
|
13
|
+
export { type _RequestInfo as RequestInfo };
|
|
14
|
+
|
|
15
|
+
type _RequestInit = RequestInit;
|
|
16
|
+
export { type _RequestInit as RequestInit };
|
|
17
|
+
|
|
18
|
+
type _Response = Response;
|
|
19
|
+
export { _Response as Response };
|
|
20
|
+
|
|
21
|
+
type _ResponseInit = ResponseInit;
|
|
22
|
+
export { type _ResponseInit as ResponseInit };
|
|
23
|
+
|
|
24
|
+
type _ResponseType = ResponseType;
|
|
25
|
+
export { type _ResponseType as ResponseType };
|
|
26
|
+
|
|
27
|
+
type _BodyInit = BodyInit;
|
|
28
|
+
export { type _BodyInit as BodyInit };
|
|
29
|
+
|
|
30
|
+
type _Headers = Headers;
|
|
31
|
+
export { _Headers as Headers };
|
|
32
|
+
|
|
33
|
+
type _HeadersInit = HeadersInit;
|
|
34
|
+
export { type _HeadersInit as HeadersInit };
|
|
35
|
+
|
|
36
|
+
type EndingType = 'native' | 'transparent';
|
|
37
|
+
|
|
38
|
+
export interface BlobPropertyBag {
|
|
39
|
+
endings?: EndingType;
|
|
40
|
+
type?: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface FilePropertyBag extends BlobPropertyBag {
|
|
44
|
+
lastModified?: number;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export type FileFromPathOptions = Omit<FilePropertyBag, 'lastModified'>;
|
|
48
|
+
|
|
49
|
+
type _FormData = FormData;
|
|
50
|
+
declare const _FormData: typeof FormData;
|
|
51
|
+
export { _FormData as FormData };
|
|
52
|
+
|
|
53
|
+
type _File = File;
|
|
54
|
+
declare const _File: typeof File;
|
|
55
|
+
export { _File as File };
|
|
56
|
+
|
|
57
|
+
type _Blob = Blob;
|
|
58
|
+
declare const _Blob: typeof Blob;
|
|
59
|
+
export { _Blob as Blob };
|
|
60
|
+
|
|
61
|
+
export declare class Readable {
|
|
62
|
+
readable: boolean;
|
|
63
|
+
readonly readableEnded: boolean;
|
|
64
|
+
readonly readableFlowing: boolean | null;
|
|
65
|
+
readonly readableHighWaterMark: number;
|
|
66
|
+
readonly readableLength: number;
|
|
67
|
+
readonly readableObjectMode: boolean;
|
|
68
|
+
destroyed: boolean;
|
|
69
|
+
read(size?: number): any;
|
|
70
|
+
pause(): this;
|
|
71
|
+
resume(): this;
|
|
72
|
+
isPaused(): boolean;
|
|
73
|
+
destroy(error?: Error): this;
|
|
74
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<any>;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export declare class FsReadStream extends Readable {
|
|
78
|
+
path: {}; // node type is string | Buffer
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
type _ReadableStream<R = any> = ReadableStream<R>;
|
|
82
|
+
declare const _ReadableStream: typeof ReadableStream;
|
|
83
|
+
export { _ReadableStream as ReadableStream };
|
package/src/core.ts
CHANGED
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
import { VERSION } from './version';
|
|
2
2
|
import { Stream } from './streaming';
|
|
3
|
-
import { APIError, APIConnectionError, APIConnectionTimeoutError, APIUserAbortError } from './error';
|
|
4
|
-
import type { Readable } from './_shims/node-readable';
|
|
5
|
-
import { getDefaultAgent, type Agent } from './_shims/agent';
|
|
6
3
|
import {
|
|
4
|
+
AnthropicError,
|
|
5
|
+
APIError,
|
|
6
|
+
APIConnectionError,
|
|
7
|
+
APIConnectionTimeoutError,
|
|
8
|
+
APIUserAbortError,
|
|
9
|
+
} from './error';
|
|
10
|
+
import {
|
|
11
|
+
kind as shimsKind,
|
|
12
|
+
type Readable,
|
|
13
|
+
getDefaultAgent,
|
|
14
|
+
type Agent,
|
|
7
15
|
fetch,
|
|
8
|
-
isPolyfilled as fetchIsPolyfilled,
|
|
9
16
|
type RequestInfo,
|
|
10
17
|
type RequestInit,
|
|
11
18
|
type Response,
|
|
12
|
-
|
|
19
|
+
type HeadersInit,
|
|
20
|
+
} from './_shims/index';
|
|
13
21
|
export { type Response };
|
|
14
22
|
import { isMultipartBody } from './uploads';
|
|
15
23
|
export {
|
|
@@ -34,9 +42,11 @@ type APIResponseProps = {
|
|
|
34
42
|
async function defaultParseResponse<T>(props: APIResponseProps): Promise<T> {
|
|
35
43
|
const { response } = props;
|
|
36
44
|
if (props.options.stream) {
|
|
45
|
+
debug('response', response.status, response.url, response.headers, response.body);
|
|
46
|
+
|
|
37
47
|
// Note: there is an invariant here that isn't represented in the type system
|
|
38
48
|
// that if you set `stream: true` the response type must also be `Stream<T>`
|
|
39
|
-
return
|
|
49
|
+
return Stream.fromSSEResponse(response, props.controller) as any;
|
|
40
50
|
}
|
|
41
51
|
|
|
42
52
|
const contentType = response.headers.get('content-type');
|
|
@@ -51,7 +61,7 @@ async function defaultParseResponse<T>(props: APIResponseProps): Promise<T> {
|
|
|
51
61
|
// TODO handle blob, arraybuffer, other content types, etc.
|
|
52
62
|
const text = await response.text();
|
|
53
63
|
debug('response', response.status, response.url, response.headers, text);
|
|
54
|
-
return text as T;
|
|
64
|
+
return text as any as T;
|
|
55
65
|
}
|
|
56
66
|
|
|
57
67
|
/**
|
|
@@ -83,6 +93,12 @@ export class APIPromise<T> extends Promise<T> {
|
|
|
83
93
|
*
|
|
84
94
|
* If you want to parse the response body but still get the `Response`
|
|
85
95
|
* instance, you can use {@link withResponse()}.
|
|
96
|
+
*
|
|
97
|
+
* 👋 Getting the wrong TypeScript type for `Response`?
|
|
98
|
+
* Try setting `"moduleResolution": "NodeNext"` if you can,
|
|
99
|
+
* or add one of these imports before your first `import … from '@anthropic-ai/sdk'`:
|
|
100
|
+
* - `import '@anthropic-ai/sdk/shims/node'` (if you're running on Node)
|
|
101
|
+
* - `import '@anthropic-ai/sdk/shims/web'` (otherwise)
|
|
86
102
|
*/
|
|
87
103
|
asResponse(): Promise<Response> {
|
|
88
104
|
return this.responsePromise.then((p) => p.response);
|
|
@@ -92,6 +108,13 @@ export class APIPromise<T> extends Promise<T> {
|
|
|
92
108
|
*
|
|
93
109
|
* If you just want to get the raw `Response` instance without parsing it,
|
|
94
110
|
* you can use {@link asResponse()}.
|
|
111
|
+
*
|
|
112
|
+
*
|
|
113
|
+
* 👋 Getting the wrong TypeScript type for `Response`?
|
|
114
|
+
* Try setting `"moduleResolution": "NodeNext"` if you can,
|
|
115
|
+
* or add one of these imports before your first `import … from '@anthropic-ai/sdk'`:
|
|
116
|
+
* - `import '@anthropic-ai/sdk/shims/node'` (if you're running on Node)
|
|
117
|
+
* - `import '@anthropic-ai/sdk/shims/web'` (otherwise)
|
|
95
118
|
*/
|
|
96
119
|
async withResponse(): Promise<{ data: T; response: Response }> {
|
|
97
120
|
const [data, response] = await Promise.all([this.parse(), this.asResponse()]);
|
|
@@ -153,7 +176,7 @@ export abstract class APIClient {
|
|
|
153
176
|
this.fetch = overridenFetch ?? fetch;
|
|
154
177
|
}
|
|
155
178
|
|
|
156
|
-
protected authHeaders(): Headers {
|
|
179
|
+
protected authHeaders(opts: FinalRequestOptions): Headers {
|
|
157
180
|
return {};
|
|
158
181
|
}
|
|
159
182
|
|
|
@@ -165,13 +188,13 @@ export abstract class APIClient {
|
|
|
165
188
|
* Authorization: 'Bearer 123',
|
|
166
189
|
* }
|
|
167
190
|
*/
|
|
168
|
-
protected defaultHeaders(): Headers {
|
|
191
|
+
protected defaultHeaders(opts: FinalRequestOptions): Headers {
|
|
169
192
|
return {
|
|
170
193
|
Accept: 'application/json',
|
|
171
194
|
'Content-Type': 'application/json',
|
|
172
195
|
'User-Agent': this.getUserAgent(),
|
|
173
196
|
...getPlatformHeaders(),
|
|
174
|
-
...this.authHeaders(),
|
|
197
|
+
...this.authHeaders(opts),
|
|
175
198
|
};
|
|
176
199
|
}
|
|
177
200
|
|
|
@@ -272,11 +295,11 @@ export abstract class APIClient {
|
|
|
272
295
|
|
|
273
296
|
const reqHeaders: Record<string, string> = {
|
|
274
297
|
...(contentLength && { 'Content-Length': contentLength }),
|
|
275
|
-
...this.defaultHeaders(),
|
|
298
|
+
...this.defaultHeaders(options),
|
|
276
299
|
...headers,
|
|
277
300
|
};
|
|
278
301
|
// let builtin fetch set the Content-Type for multipart bodies
|
|
279
|
-
if (isMultipartBody(options.body) &&
|
|
302
|
+
if (isMultipartBody(options.body) && shimsKind !== 'node') {
|
|
280
303
|
delete reqHeaders['Content-Type'];
|
|
281
304
|
}
|
|
282
305
|
|
|
@@ -304,7 +327,19 @@ export abstract class APIClient {
|
|
|
304
327
|
* This is useful for cases where you want to add certain headers based off of
|
|
305
328
|
* the request properties, e.g. `method` or `url`.
|
|
306
329
|
*/
|
|
307
|
-
protected async prepareRequest(
|
|
330
|
+
protected async prepareRequest(
|
|
331
|
+
request: RequestInit,
|
|
332
|
+
{ url, options }: { url: string; options: FinalRequestOptions },
|
|
333
|
+
): Promise<void> {}
|
|
334
|
+
|
|
335
|
+
protected parseHeaders(headers: HeadersInit | null | undefined): Record<string, string> {
|
|
336
|
+
return (
|
|
337
|
+
!headers ? {}
|
|
338
|
+
: Symbol.iterator in headers ?
|
|
339
|
+
Object.fromEntries(Array.from(headers as Iterable<string[]>).map((header) => [...header]))
|
|
340
|
+
: { ...headers }
|
|
341
|
+
);
|
|
342
|
+
}
|
|
308
343
|
|
|
309
344
|
protected makeStatusError(
|
|
310
345
|
status: number | undefined,
|
|
@@ -333,7 +368,7 @@ export abstract class APIClient {
|
|
|
333
368
|
|
|
334
369
|
const { req, url, timeout } = this.buildRequest(options);
|
|
335
370
|
|
|
336
|
-
await this.prepareRequest(req, { url });
|
|
371
|
+
await this.prepareRequest(req, { url, options });
|
|
337
372
|
|
|
338
373
|
debug('request', url, options, req.headers);
|
|
339
374
|
|
|
@@ -364,7 +399,7 @@ export abstract class APIClient {
|
|
|
364
399
|
return this.retryRequest(options, retriesRemaining, responseHeaders);
|
|
365
400
|
}
|
|
366
401
|
|
|
367
|
-
const errText = await response.text().catch(() =>
|
|
402
|
+
const errText = await response.text().catch((e) => castToError(e).message);
|
|
368
403
|
const errJSON = safeJSON(errText);
|
|
369
404
|
const errMessage = errJSON ? undefined : errText;
|
|
370
405
|
|
|
@@ -385,7 +420,7 @@ export abstract class APIClient {
|
|
|
385
420
|
return new PagePromise<PageClass, Item>(this, request, Page);
|
|
386
421
|
}
|
|
387
422
|
|
|
388
|
-
buildURL<Req
|
|
423
|
+
buildURL<Req extends Record<string, unknown>>(path: string, query: Req | null | undefined): string {
|
|
389
424
|
const url =
|
|
390
425
|
isAbsoluteURL(path) ?
|
|
391
426
|
new URL(path)
|
|
@@ -413,7 +448,7 @@ export abstract class APIClient {
|
|
|
413
448
|
if (value === null) {
|
|
414
449
|
return `${encodeURIComponent(key)}=`;
|
|
415
450
|
}
|
|
416
|
-
throw new
|
|
451
|
+
throw new AnthropicError(
|
|
417
452
|
`Cannot stringify type ${typeof value}; Expected string, number, boolean, or null. If you need to pass nested query parameters, you can manually encode them, e.g. { query: { 'foo[key1]': value1, 'foo[key2]': value2 } }, and please open a GitHub issue requesting better support for your use case.`,
|
|
418
453
|
);
|
|
419
454
|
})
|
|
@@ -431,11 +466,14 @@ export abstract class APIClient {
|
|
|
431
466
|
|
|
432
467
|
const timeout = setTimeout(() => controller.abort(), ms);
|
|
433
468
|
|
|
434
|
-
return
|
|
435
|
-
.
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
469
|
+
return (
|
|
470
|
+
this.getRequestClient()
|
|
471
|
+
// use undefined this binding; fetch errors if bound to something else in browser/cloudflare
|
|
472
|
+
.fetch.call(undefined, url, { signal: controller.signal as any, ...options })
|
|
473
|
+
.finally(() => {
|
|
474
|
+
clearTimeout(timeout);
|
|
475
|
+
})
|
|
476
|
+
);
|
|
439
477
|
}
|
|
440
478
|
|
|
441
479
|
protected getRequestClient(): RequestClient {
|
|
@@ -450,6 +488,9 @@ export abstract class APIClient {
|
|
|
450
488
|
if (shouldRetryHeader === 'true') return true;
|
|
451
489
|
if (shouldRetryHeader === 'false') return false;
|
|
452
490
|
|
|
491
|
+
// Retry on request timeouts.
|
|
492
|
+
if (response.status === 408) return true;
|
|
493
|
+
|
|
453
494
|
// Retry on lock timeouts.
|
|
454
495
|
if (response.status === 409) return true;
|
|
455
496
|
|
|
@@ -470,32 +511,37 @@ export abstract class APIClient {
|
|
|
470
511
|
retriesRemaining -= 1;
|
|
471
512
|
|
|
472
513
|
// About the Retry-After header: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
514
|
+
let timeoutMillis: number | undefined;
|
|
515
|
+
const retryAfterHeader = responseHeaders?.['retry-after'];
|
|
516
|
+
if (retryAfterHeader) {
|
|
517
|
+
const timeoutSeconds = parseInt(retryAfterHeader);
|
|
518
|
+
if (!Number.isNaN(timeoutSeconds)) {
|
|
519
|
+
timeoutMillis = timeoutSeconds * 1000;
|
|
520
|
+
} else {
|
|
521
|
+
timeoutMillis = Date.parse(retryAfterHeader) - Date.now();
|
|
522
|
+
}
|
|
523
|
+
}
|
|
477
524
|
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
525
|
+
// If the API asks us to wait a certain amount of time (and it's a reasonable amount),
|
|
526
|
+
// just do what it says, but otherwise calculate a default
|
|
527
|
+
if (
|
|
528
|
+
!timeoutMillis ||
|
|
529
|
+
!Number.isInteger(timeoutMillis) ||
|
|
530
|
+
timeoutMillis <= 0 ||
|
|
531
|
+
timeoutMillis > 60 * 1000
|
|
532
|
+
) {
|
|
533
|
+
const maxRetries = options.maxRetries ?? this.maxRetries;
|
|
534
|
+
timeoutMillis = this.calculateDefaultRetryTimeoutMillis(retriesRemaining, maxRetries);
|
|
535
|
+
}
|
|
536
|
+
await sleep(timeoutMillis);
|
|
481
537
|
|
|
482
538
|
return this.makeRequest(options, retriesRemaining);
|
|
483
539
|
}
|
|
484
540
|
|
|
485
|
-
private
|
|
486
|
-
retriesRemaining: number,
|
|
487
|
-
retryAfter: number,
|
|
488
|
-
maxRetries: number,
|
|
489
|
-
): number {
|
|
541
|
+
private calculateDefaultRetryTimeoutMillis(retriesRemaining: number, maxRetries: number): number {
|
|
490
542
|
const initialRetryDelay = 0.5;
|
|
491
543
|
const maxRetryDelay = 2;
|
|
492
544
|
|
|
493
|
-
// If the API asks us to wait a certain amount of time (and it's a reasonable amount),
|
|
494
|
-
// just do what it says.
|
|
495
|
-
if (Number.isInteger(retryAfter) && retryAfter <= 60) {
|
|
496
|
-
return retryAfter;
|
|
497
|
-
}
|
|
498
|
-
|
|
499
545
|
const numRetries = maxRetries - retriesRemaining;
|
|
500
546
|
|
|
501
547
|
// Apply exponential backoff, but not more than the max.
|
|
@@ -504,7 +550,7 @@ export abstract class APIClient {
|
|
|
504
550
|
// Apply some jitter, plus-or-minus half a second.
|
|
505
551
|
const jitter = Math.random() - 0.5;
|
|
506
552
|
|
|
507
|
-
return sleepSeconds + jitter;
|
|
553
|
+
return (sleepSeconds + jitter) * 1000;
|
|
508
554
|
}
|
|
509
555
|
|
|
510
556
|
private getUserAgent(): string {
|
|
@@ -563,10 +609,10 @@ export abstract class AbstractPage<Item> implements AsyncIterable<Item> {
|
|
|
563
609
|
return this.nextPageInfo() != null;
|
|
564
610
|
}
|
|
565
611
|
|
|
566
|
-
async getNextPage(): Promise<
|
|
612
|
+
async getNextPage(): Promise<this> {
|
|
567
613
|
const nextInfo = this.nextPageInfo();
|
|
568
614
|
if (!nextInfo) {
|
|
569
|
-
throw new
|
|
615
|
+
throw new AnthropicError(
|
|
570
616
|
'No next page expected; please check `.hasNextPage()` before calling `.getNextPage()`.',
|
|
571
617
|
);
|
|
572
618
|
}
|
|
@@ -576,7 +622,7 @@ export abstract class AbstractPage<Item> implements AsyncIterable<Item> {
|
|
|
576
622
|
} else if ('url' in nextInfo) {
|
|
577
623
|
const params = [...Object.entries(nextOptions.query || {}), ...nextInfo.url.searchParams.entries()];
|
|
578
624
|
for (const [key, value] of params) {
|
|
579
|
-
nextInfo.url.searchParams.set(key, value);
|
|
625
|
+
nextInfo.url.searchParams.set(key, value as any);
|
|
580
626
|
}
|
|
581
627
|
nextOptions.query = undefined;
|
|
582
628
|
nextOptions.path = nextInfo.url.toString();
|
|
@@ -702,7 +748,7 @@ const requestOptionsKeys: KeysEnum<RequestOptions> = {
|
|
|
702
748
|
idempotencyKey: true,
|
|
703
749
|
};
|
|
704
750
|
|
|
705
|
-
export const isRequestOptions = (obj: unknown): obj is RequestOptions => {
|
|
751
|
+
export const isRequestOptions = (obj: unknown): obj is RequestOptions<Record<string, unknown> | Readable> => {
|
|
706
752
|
return (
|
|
707
753
|
typeof obj === 'object' &&
|
|
708
754
|
obj !== null &&
|
|
@@ -888,14 +934,14 @@ const isAbsoluteURL = (url: string): boolean => {
|
|
|
888
934
|
return startsWithSchemeRegexp.test(url);
|
|
889
935
|
};
|
|
890
936
|
|
|
891
|
-
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
937
|
+
export const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
892
938
|
|
|
893
939
|
const validatePositiveInteger = (name: string, n: unknown): number => {
|
|
894
940
|
if (typeof n !== 'number' || !Number.isInteger(n)) {
|
|
895
|
-
throw new
|
|
941
|
+
throw new AnthropicError(`${name} must be an integer`);
|
|
896
942
|
}
|
|
897
943
|
if (n < 0) {
|
|
898
|
-
throw new
|
|
944
|
+
throw new AnthropicError(`${name} must be a positive integer`);
|
|
899
945
|
}
|
|
900
946
|
return n;
|
|
901
947
|
};
|
|
@@ -906,7 +952,7 @@ export const castToError = (err: any): Error => {
|
|
|
906
952
|
};
|
|
907
953
|
|
|
908
954
|
export const ensurePresent = <T>(value: T | null | undefined): T => {
|
|
909
|
-
if (value == null) throw new
|
|
955
|
+
if (value == null) throw new AnthropicError(`Expected a value to be given but received ${value} instead.`);
|
|
910
956
|
return value;
|
|
911
957
|
};
|
|
912
958
|
|
|
@@ -929,14 +975,14 @@ export const coerceInteger = (value: unknown): number => {
|
|
|
929
975
|
if (typeof value === 'number') return Math.round(value);
|
|
930
976
|
if (typeof value === 'string') return parseInt(value, 10);
|
|
931
977
|
|
|
932
|
-
throw new
|
|
978
|
+
throw new AnthropicError(`Could not coerce ${value} (type: ${typeof value}) into a number`);
|
|
933
979
|
};
|
|
934
980
|
|
|
935
981
|
export const coerceFloat = (value: unknown): number => {
|
|
936
982
|
if (typeof value === 'number') return value;
|
|
937
983
|
if (typeof value === 'string') return parseFloat(value);
|
|
938
984
|
|
|
939
|
-
throw new
|
|
985
|
+
throw new AnthropicError(`Could not coerce ${value} (type: ${typeof value}) into a number`);
|
|
940
986
|
};
|
|
941
987
|
|
|
942
988
|
export const coerceBoolean = (value: unknown): boolean => {
|
|
@@ -1015,16 +1061,33 @@ export const isHeadersProtocol = (headers: any): headers is HeadersProtocol => {
|
|
|
1015
1061
|
return typeof headers?.get === 'function';
|
|
1016
1062
|
};
|
|
1017
1063
|
|
|
1018
|
-
export const
|
|
1019
|
-
const
|
|
1020
|
-
if (isHeadersProtocol(headers))
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1064
|
+
export const getRequiredHeader = (headers: HeadersLike, header: string): string => {
|
|
1065
|
+
const lowerCasedHeader = header.toLowerCase();
|
|
1066
|
+
if (isHeadersProtocol(headers)) {
|
|
1067
|
+
// to deal with the case where the header looks like Stainless-Event-Id
|
|
1068
|
+
const intercapsHeader =
|
|
1069
|
+
header[0]?.toUpperCase() +
|
|
1070
|
+
header.substring(1).replace(/([^\w])(\w)/g, (_m, g1, g2) => g1 + g2.toUpperCase());
|
|
1071
|
+
for (const key of [header, lowerCasedHeader, header.toUpperCase(), intercapsHeader]) {
|
|
1072
|
+
const value = headers.get(key);
|
|
1073
|
+
if (value) {
|
|
1074
|
+
return value;
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
1026
1077
|
}
|
|
1027
|
-
|
|
1078
|
+
|
|
1079
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
1080
|
+
if (key.toLowerCase() === lowerCasedHeader) {
|
|
1081
|
+
if (Array.isArray(value)) {
|
|
1082
|
+
if (value.length <= 1) return value[0];
|
|
1083
|
+
console.warn(`Received ${value.length} entries for the ${header} header, using the first entry.`);
|
|
1084
|
+
return value[0];
|
|
1085
|
+
}
|
|
1086
|
+
return value;
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
throw new Error(`Could not find ${header} header`);
|
|
1028
1091
|
};
|
|
1029
1092
|
|
|
1030
1093
|
/**
|
|
@@ -1040,5 +1103,5 @@ export const toBase64 = (str: string | null | undefined): string => {
|
|
|
1040
1103
|
return btoa(str);
|
|
1041
1104
|
}
|
|
1042
1105
|
|
|
1043
|
-
throw new
|
|
1106
|
+
throw new AnthropicError('Cannot generate b64 string; Expected `Buffer` or `btoa` to be defined');
|
|
1044
1107
|
};
|
package/src/error.ts
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
import { castToError, Headers } from './core';
|
|
4
4
|
|
|
5
|
-
export class
|
|
5
|
+
export class AnthropicError extends Error {}
|
|
6
|
+
|
|
7
|
+
export class APIError extends AnthropicError {
|
|
6
8
|
readonly status: number | undefined;
|
|
7
9
|
readonly headers: Headers | undefined;
|
|
8
10
|
readonly error: Object | undefined;
|
|
@@ -13,20 +15,30 @@ export class APIError extends Error {
|
|
|
13
15
|
message: string | undefined,
|
|
14
16
|
headers: Headers | undefined,
|
|
15
17
|
) {
|
|
16
|
-
super(APIError.makeMessage(error, message));
|
|
18
|
+
super(`${APIError.makeMessage(status, error, message)}`);
|
|
17
19
|
this.status = status;
|
|
18
20
|
this.headers = headers;
|
|
19
21
|
this.error = error;
|
|
20
22
|
}
|
|
21
23
|
|
|
22
|
-
private static makeMessage(error: any, message: string | undefined) {
|
|
23
|
-
|
|
24
|
+
private static makeMessage(status: number | undefined, error: any, message: string | undefined) {
|
|
25
|
+
const msg =
|
|
24
26
|
error?.message ?
|
|
25
27
|
typeof error.message === 'string' ? error.message
|
|
26
28
|
: JSON.stringify(error.message)
|
|
27
29
|
: error ? JSON.stringify(error)
|
|
28
|
-
: message
|
|
29
|
-
|
|
30
|
+
: message;
|
|
31
|
+
|
|
32
|
+
if (status && msg) {
|
|
33
|
+
return `${status} ${msg}`;
|
|
34
|
+
}
|
|
35
|
+
if (status) {
|
|
36
|
+
return `${status} status code (no body)`;
|
|
37
|
+
}
|
|
38
|
+
if (msg) {
|
|
39
|
+
return msg;
|
|
40
|
+
}
|
|
41
|
+
return '(no status code or body)';
|
|
30
42
|
}
|
|
31
43
|
|
|
32
44
|
static generate(
|
|
@@ -97,8 +109,8 @@ export class APIConnectionError extends APIError {
|
|
|
97
109
|
}
|
|
98
110
|
|
|
99
111
|
export class APIConnectionTimeoutError extends APIConnectionError {
|
|
100
|
-
constructor() {
|
|
101
|
-
super({ message: 'Request timed out.' });
|
|
112
|
+
constructor({ message }: { message?: string } = {}) {
|
|
113
|
+
super({ message: message ?? 'Request timed out.' });
|
|
102
114
|
}
|
|
103
115
|
}
|
|
104
116
|
|
package/src/index.ts
CHANGED
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless.
|
|
2
2
|
|
|
3
3
|
import * as Core from './core';
|
|
4
|
-
import * as API from './resources/index';
|
|
5
4
|
import * as Errors from './error';
|
|
6
|
-
import type
|
|
5
|
+
import { type Agent } from './_shims/index';
|
|
7
6
|
import * as Uploads from './uploads';
|
|
7
|
+
import * as API from "./pic-ai/sdk/resources/index";
|
|
8
8
|
|
|
9
9
|
export interface ClientOptions {
|
|
10
10
|
/**
|
|
11
|
-
* Defaults to process.env[
|
|
11
|
+
* Defaults to process.env['ANTHROPIC_API_KEY'].
|
|
12
12
|
*/
|
|
13
13
|
apiKey?: string | null;
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Defaults to process.env['ANTHROPIC_AUTH_TOKEN'].
|
|
17
|
+
*/
|
|
18
|
+
authToken?: string | null;
|
|
19
|
+
|
|
15
20
|
/**
|
|
16
21
|
* Override the default base URL for the API, e.g., "https://api.example.com/v2/"
|
|
17
22
|
*/
|
|
@@ -65,21 +70,20 @@ export interface ClientOptions {
|
|
|
65
70
|
* param to `undefined` in request options.
|
|
66
71
|
*/
|
|
67
72
|
defaultQuery?: Core.DefaultQuery;
|
|
68
|
-
|
|
69
|
-
authToken?: string | null;
|
|
70
73
|
}
|
|
71
74
|
|
|
72
75
|
/** API Client for interfacing with the Anthropic API. */
|
|
73
76
|
export class Anthropic extends Core.APIClient {
|
|
74
77
|
apiKey: string | null;
|
|
75
|
-
authToken
|
|
78
|
+
authToken: string | null;
|
|
76
79
|
|
|
77
80
|
private _options: ClientOptions;
|
|
78
81
|
|
|
79
82
|
/**
|
|
80
83
|
* API Client for interfacing with the Anthropic API.
|
|
81
84
|
*
|
|
82
|
-
* @param {string | null} [opts.apiKey
|
|
85
|
+
* @param {string | null} [opts.apiKey==process.env['ANTHROPIC_API_KEY'] ?? null]
|
|
86
|
+
* @param {string | null} [opts.authToken==process.env['ANTHROPIC_AUTH_TOKEN'] ?? null]
|
|
83
87
|
* @param {string} [opts.baseURL] - Override the default base URL for the API.
|
|
84
88
|
* @param {number} [opts.timeout=10 minutes] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
|
|
85
89
|
* @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections.
|
|
@@ -87,20 +91,17 @@ export class Anthropic extends Core.APIClient {
|
|
|
87
91
|
* @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.
|
|
88
92
|
* @param {Core.Headers} opts.defaultHeaders - Default headers to include with every request to the API.
|
|
89
93
|
* @param {Core.DefaultQuery} opts.defaultQuery - Default query parameters to include with every request to the API.
|
|
90
|
-
* @param {string | null} [opts.authToken]
|
|
91
94
|
*/
|
|
92
95
|
constructor({
|
|
93
96
|
apiKey = Core.readEnv('ANTHROPIC_API_KEY') ?? null,
|
|
94
97
|
authToken = Core.readEnv('ANTHROPIC_AUTH_TOKEN') ?? null,
|
|
95
98
|
...opts
|
|
96
99
|
}: ClientOptions = {}) {
|
|
97
|
-
undefined;
|
|
98
|
-
|
|
99
100
|
const options: ClientOptions = {
|
|
100
101
|
apiKey,
|
|
101
102
|
authToken,
|
|
102
|
-
baseURL: `https://api.anthropic.com`,
|
|
103
103
|
...opts,
|
|
104
|
+
baseURL: opts.baseURL ?? `https://api.anthropic.com`,
|
|
104
105
|
};
|
|
105
106
|
|
|
106
107
|
super({
|
|
@@ -122,9 +123,9 @@ export class Anthropic extends Core.APIClient {
|
|
|
122
123
|
return this._options.defaultQuery;
|
|
123
124
|
}
|
|
124
125
|
|
|
125
|
-
protected override defaultHeaders(): Core.Headers {
|
|
126
|
+
protected override defaultHeaders(opts: Core.FinalRequestOptions): Core.Headers {
|
|
126
127
|
return {
|
|
127
|
-
...super.defaultHeaders(),
|
|
128
|
+
...super.defaultHeaders(opts),
|
|
128
129
|
'anthropic-version': '2023-06-01',
|
|
129
130
|
...this._options.defaultHeaders,
|
|
130
131
|
};
|
|
@@ -150,26 +151,28 @@ export class Anthropic extends Core.APIClient {
|
|
|
150
151
|
);
|
|
151
152
|
}
|
|
152
153
|
|
|
153
|
-
protected override authHeaders(): Core.Headers {
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
|
|
154
|
+
protected override authHeaders(opts: Core.FinalRequestOptions): Core.Headers {
|
|
155
|
+
const apiKeyAuth = this.apiKeyAuth(opts);
|
|
156
|
+
const bearerAuth = this.bearerAuth(opts);
|
|
157
|
+
|
|
158
|
+
if (apiKeyAuth != null && !Core.isEmptyObj(apiKeyAuth)) {
|
|
159
|
+
return apiKeyAuth;
|
|
157
160
|
}
|
|
158
|
-
|
|
159
|
-
if (
|
|
160
|
-
return
|
|
161
|
+
|
|
162
|
+
if (bearerAuth != null && !Core.isEmptyObj(bearerAuth)) {
|
|
163
|
+
return bearerAuth;
|
|
161
164
|
}
|
|
162
165
|
return {};
|
|
163
166
|
}
|
|
164
167
|
|
|
165
|
-
protected
|
|
168
|
+
protected apiKeyAuth(opts: Core.FinalRequestOptions): Core.Headers {
|
|
166
169
|
if (this.apiKey == null) {
|
|
167
170
|
return {};
|
|
168
171
|
}
|
|
169
172
|
return { 'X-Api-Key': this.apiKey };
|
|
170
173
|
}
|
|
171
174
|
|
|
172
|
-
protected
|
|
175
|
+
protected bearerAuth(opts: Core.FinalRequestOptions): Core.Headers {
|
|
173
176
|
if (this.authToken == null) {
|
|
174
177
|
return {};
|
|
175
178
|
}
|
|
@@ -180,6 +183,7 @@ export class Anthropic extends Core.APIClient {
|
|
|
180
183
|
static HUMAN_PROMPT = '\n\nHuman:';
|
|
181
184
|
static AI_PROMPT = '\n\nAssistant:';
|
|
182
185
|
|
|
186
|
+
static AnthropicError = Errors.AnthropicError;
|
|
183
187
|
static APIError = Errors.APIError;
|
|
184
188
|
static APIConnectionError = Errors.APIConnectionError;
|
|
185
189
|
static APIConnectionTimeoutError = Errors.APIConnectionTimeoutError;
|
|
@@ -197,6 +201,7 @@ export class Anthropic extends Core.APIClient {
|
|
|
197
201
|
export const { HUMAN_PROMPT, AI_PROMPT } = Anthropic;
|
|
198
202
|
|
|
199
203
|
export const {
|
|
204
|
+
AnthropicError,
|
|
200
205
|
APIError,
|
|
201
206
|
APIConnectionError,
|
|
202
207
|
APIConnectionTimeoutError,
|