@anthropic-ai/sdk 0.6.2 → 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 +109 -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 -224
- package/core.d.ts.map +1 -1
- package/core.js +701 -736
- package/core.js.map +1 -1
- package/core.mjs +694 -688
- 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 -159
- package/index.js.map +1 -1
- package/index.mjs +84 -104
- 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 +107 -56
- package/src/error.ts +20 -8
- package/src/index.ts +24 -17
- 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 +164 -59
- 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 -60
- package/_shims/fetch.js +0 -13
- package/_shims/fetch.mjs +0 -15
- package/_shims/fetch.node.d.ts +0 -64
- 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 -60
- 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 -64
- 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
package/error.mjs
CHANGED
|
@@ -1,116 +1,126 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless.
|
|
2
|
-
import { castToError } from
|
|
3
|
-
export class
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return (
|
|
12
|
-
(
|
|
13
|
-
error === null || error === void 0 ? void 0 : error.message
|
|
14
|
-
) ?
|
|
15
|
-
typeof error.message === 'string' ? error.message
|
|
16
|
-
: JSON.stringify(error.message)
|
|
17
|
-
: error ? JSON.stringify(error)
|
|
18
|
-
: message || 'Unknown error occurred'
|
|
19
|
-
);
|
|
20
|
-
}
|
|
21
|
-
static generate(status, errorResponse, message, headers) {
|
|
22
|
-
if (!status) {
|
|
23
|
-
return new APIConnectionError({ cause: castToError(errorResponse) });
|
|
24
|
-
}
|
|
25
|
-
const error = errorResponse;
|
|
26
|
-
if (status === 400) {
|
|
27
|
-
return new BadRequestError(status, error, message, headers);
|
|
28
|
-
}
|
|
29
|
-
if (status === 401) {
|
|
30
|
-
return new AuthenticationError(status, error, message, headers);
|
|
31
|
-
}
|
|
32
|
-
if (status === 403) {
|
|
33
|
-
return new PermissionDeniedError(status, error, message, headers);
|
|
34
|
-
}
|
|
35
|
-
if (status === 404) {
|
|
36
|
-
return new NotFoundError(status, error, message, headers);
|
|
37
|
-
}
|
|
38
|
-
if (status === 409) {
|
|
39
|
-
return new ConflictError(status, error, message, headers);
|
|
40
|
-
}
|
|
41
|
-
if (status === 422) {
|
|
42
|
-
return new UnprocessableEntityError(status, error, message, headers);
|
|
2
|
+
import { castToError } from "./core.mjs";
|
|
3
|
+
export class AnthropicError extends Error {
|
|
4
|
+
}
|
|
5
|
+
export class APIError extends AnthropicError {
|
|
6
|
+
constructor(status, error, message, headers) {
|
|
7
|
+
super(`${APIError.makeMessage(status, error, message)}`);
|
|
8
|
+
this.status = status;
|
|
9
|
+
this.headers = headers;
|
|
10
|
+
this.error = error;
|
|
43
11
|
}
|
|
44
|
-
|
|
45
|
-
|
|
12
|
+
static makeMessage(status, error, message) {
|
|
13
|
+
const msg = error?.message ?
|
|
14
|
+
typeof error.message === 'string' ? error.message
|
|
15
|
+
: JSON.stringify(error.message)
|
|
16
|
+
: error ? JSON.stringify(error)
|
|
17
|
+
: message;
|
|
18
|
+
if (status && msg) {
|
|
19
|
+
return `${status} ${msg}`;
|
|
20
|
+
}
|
|
21
|
+
if (status) {
|
|
22
|
+
return `${status} status code (no body)`;
|
|
23
|
+
}
|
|
24
|
+
if (msg) {
|
|
25
|
+
return msg;
|
|
26
|
+
}
|
|
27
|
+
return '(no status code or body)';
|
|
46
28
|
}
|
|
47
|
-
|
|
48
|
-
|
|
29
|
+
static generate(status, errorResponse, message, headers) {
|
|
30
|
+
if (!status) {
|
|
31
|
+
return new APIConnectionError({ cause: castToError(errorResponse) });
|
|
32
|
+
}
|
|
33
|
+
const error = errorResponse;
|
|
34
|
+
if (status === 400) {
|
|
35
|
+
return new BadRequestError(status, error, message, headers);
|
|
36
|
+
}
|
|
37
|
+
if (status === 401) {
|
|
38
|
+
return new AuthenticationError(status, error, message, headers);
|
|
39
|
+
}
|
|
40
|
+
if (status === 403) {
|
|
41
|
+
return new PermissionDeniedError(status, error, message, headers);
|
|
42
|
+
}
|
|
43
|
+
if (status === 404) {
|
|
44
|
+
return new NotFoundError(status, error, message, headers);
|
|
45
|
+
}
|
|
46
|
+
if (status === 409) {
|
|
47
|
+
return new ConflictError(status, error, message, headers);
|
|
48
|
+
}
|
|
49
|
+
if (status === 422) {
|
|
50
|
+
return new UnprocessableEntityError(status, error, message, headers);
|
|
51
|
+
}
|
|
52
|
+
if (status === 429) {
|
|
53
|
+
return new RateLimitError(status, error, message, headers);
|
|
54
|
+
}
|
|
55
|
+
if (status >= 500) {
|
|
56
|
+
return new InternalServerError(status, error, message, headers);
|
|
57
|
+
}
|
|
58
|
+
return new APIError(status, error, message, headers);
|
|
49
59
|
}
|
|
50
|
-
return new APIError(status, error, message, headers);
|
|
51
|
-
}
|
|
52
60
|
}
|
|
53
61
|
export class APIUserAbortError extends APIError {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
62
|
+
constructor({ message } = {}) {
|
|
63
|
+
super(undefined, undefined, message || 'Request was aborted.', undefined);
|
|
64
|
+
this.status = undefined;
|
|
65
|
+
}
|
|
58
66
|
}
|
|
59
67
|
export class APIConnectionError extends APIError {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
68
|
+
constructor({ message, cause }) {
|
|
69
|
+
super(undefined, undefined, message || 'Connection error.', undefined);
|
|
70
|
+
this.status = undefined;
|
|
71
|
+
// in some environments the 'cause' property is already declared
|
|
72
|
+
// @ts-ignore
|
|
73
|
+
if (cause)
|
|
74
|
+
this.cause = cause;
|
|
75
|
+
}
|
|
67
76
|
}
|
|
68
77
|
export class APIConnectionTimeoutError extends APIConnectionError {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
78
|
+
constructor({ message } = {}) {
|
|
79
|
+
super({ message: message ?? 'Request timed out.' });
|
|
80
|
+
}
|
|
72
81
|
}
|
|
73
82
|
export class BadRequestError extends APIError {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
83
|
+
constructor() {
|
|
84
|
+
super(...arguments);
|
|
85
|
+
this.status = 400;
|
|
86
|
+
}
|
|
78
87
|
}
|
|
79
88
|
export class AuthenticationError extends APIError {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
89
|
+
constructor() {
|
|
90
|
+
super(...arguments);
|
|
91
|
+
this.status = 401;
|
|
92
|
+
}
|
|
84
93
|
}
|
|
85
94
|
export class PermissionDeniedError extends APIError {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
95
|
+
constructor() {
|
|
96
|
+
super(...arguments);
|
|
97
|
+
this.status = 403;
|
|
98
|
+
}
|
|
90
99
|
}
|
|
91
100
|
export class NotFoundError extends APIError {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
101
|
+
constructor() {
|
|
102
|
+
super(...arguments);
|
|
103
|
+
this.status = 404;
|
|
104
|
+
}
|
|
96
105
|
}
|
|
97
106
|
export class ConflictError extends APIError {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
107
|
+
constructor() {
|
|
108
|
+
super(...arguments);
|
|
109
|
+
this.status = 409;
|
|
110
|
+
}
|
|
102
111
|
}
|
|
103
112
|
export class UnprocessableEntityError extends APIError {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
113
|
+
constructor() {
|
|
114
|
+
super(...arguments);
|
|
115
|
+
this.status = 422;
|
|
116
|
+
}
|
|
108
117
|
}
|
|
109
118
|
export class RateLimitError extends APIError {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
119
|
+
constructor() {
|
|
120
|
+
super(...arguments);
|
|
121
|
+
this.status = 429;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
export class InternalServerError extends APIError {
|
|
114
125
|
}
|
|
115
|
-
|
|
116
|
-
//# sourceMappingURL=error.mjs.map
|
|
126
|
+
//# sourceMappingURL=error.mjs.map
|
package/error.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.mjs","sourceRoot":"","sources":["src/error.ts"],"names":[],"mappings":"AAAA,qDAAqD;OAE9C,EAAE,WAAW,EAAW;AAE/B,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"error.mjs","sourceRoot":"","sources":["src/error.ts"],"names":[],"mappings":"AAAA,qDAAqD;OAE9C,EAAE,WAAW,EAAW;AAE/B,MAAM,OAAO,cAAe,SAAQ,KAAK;CAAG;AAE5C,MAAM,OAAO,QAAS,SAAQ,cAAc;IAK1C,YACE,MAA0B,EAC1B,KAAyB,EACzB,OAA2B,EAC3B,OAA4B;QAE5B,KAAK,CAAC,GAAG,QAAQ,CAAC,WAAW,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;QACzD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAEO,MAAM,CAAC,WAAW,CAAC,MAA0B,EAAE,KAAU,EAAE,OAA2B;QAC5F,MAAM,GAAG,GACP,KAAK,EAAE,OAAO,CAAC,CAAC;YACd,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CA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AC,CAAC;IACtD,CAAC;CACF;AAED,MAAM,OAAO,eAAgB,SAAQ,QAAQ;IAA7C;;QACoB,WAAM,GAAQ,GAAG,CAAC;IACtC,CAAC;CAAA;AAED,MAAM,OAAO,mBAAoB,SAAQ,QAAQ;IAAjD;;QACoB,WAAM,GAAQ,GAAG,CAAC;IACtC,CAAC;CAAA;AAED,MAAM,OAAO,qBAAsB,SAAQ,QAAQ;IAAnD;;QACoB,WAAM,GAAQ,GAAG,CAAC;IACtC,CAAC;CAAA;AAED,MAAM,OAAO,aAAc,SAAQ,QAAQ;IAA3C;;QACoB,WAAM,GAAQ,GAAG,CAAC;IACtC,CAAC;CAAA;AAED,MAAM,OAAO,aAAc,SAAQ,QAAQ;IAA3C;;QACoB,WAAM,GAAQ,GAAG,CAAC;IACtC,CAAC;CAAA;AAED,MAAM,OAAO,wBAAyB,SAAQ,QAAQ;IAAtD;;QACoB,WAAM,GAAQ,GAAG,CAAC;IACtC,CAAC;CAAA;AAED,MAAM,OAAO,cAAe,SAAQ,QAAQ;IAA5C;;QACoB,WAAM,GAAQ,GAAG,CAAC;IACtC,CAAC;CAAA;AAED,MAAM,OAAO,mBAAoB,SAAQ,QAAQ;CAAG"}
|
package/index.d.mts
CHANGED
|
@@ -1,128 +1,121 @@
|
|
|
1
|
-
import * as Core from
|
|
2
|
-
import * as
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import * as
|
|
1
|
+
import * as Core from "./core.js";
|
|
2
|
+
import * as Errors from "./error.js";
|
|
3
|
+
import { type Agent } from "./_shims/index.js";
|
|
4
|
+
import * as Uploads from "./uploads.js";
|
|
5
|
+
import * as API from '@anthropic-ai/sdk/resources/index';
|
|
6
6
|
export interface ClientOptions {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Defaults to process.env['ANTHROPIC_API_KEY'].
|
|
9
|
+
*/
|
|
10
|
+
apiKey?: string | null;
|
|
11
|
+
/**
|
|
12
|
+
* Defaults to process.env['ANTHROPIC_AUTH_TOKEN'].
|
|
13
|
+
*/
|
|
14
|
+
authToken?: string | null;
|
|
15
|
+
/**
|
|
16
|
+
* Override the default base URL for the API, e.g., "https://api.example.com/v2/"
|
|
17
|
+
*/
|
|
18
|
+
baseURL?: string;
|
|
19
|
+
/**
|
|
20
|
+
* The maximum amount of time (in milliseconds) that the client should wait for a response
|
|
21
|
+
* from the server before timing out a single request.
|
|
22
|
+
*
|
|
23
|
+
* Note that request timeouts are retried by default, so in a worst-case scenario you may wait
|
|
24
|
+
* much longer than this timeout before the promise succeeds or fails.
|
|
25
|
+
*/
|
|
26
|
+
timeout?: number;
|
|
27
|
+
/**
|
|
28
|
+
* An HTTP agent used to manage HTTP(S) connections.
|
|
29
|
+
*
|
|
30
|
+
* If not provided, an agent will be constructed by default in the Node.js environment,
|
|
31
|
+
* otherwise no agent is used.
|
|
32
|
+
*/
|
|
33
|
+
httpAgent?: Agent;
|
|
34
|
+
/**
|
|
35
|
+
* Specify a custom `fetch` function implementation.
|
|
36
|
+
*
|
|
37
|
+
* If not provided, we use `node-fetch` on Node.js and otherwise expect that `fetch` is
|
|
38
|
+
* defined globally.
|
|
39
|
+
*/
|
|
40
|
+
fetch?: Core.Fetch | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* The maximum number of times that the client will retry a request in case of a
|
|
43
|
+
* temporary failure, like a network error or a 5XX error from the server.
|
|
44
|
+
*
|
|
45
|
+
* @default 2
|
|
46
|
+
*/
|
|
47
|
+
maxRetries?: number;
|
|
48
|
+
/**
|
|
49
|
+
* Default headers to include with every request to the API.
|
|
50
|
+
*
|
|
51
|
+
* These can be removed in individual requests by explicitly setting the
|
|
52
|
+
* header to `undefined` or `null` in request options.
|
|
53
|
+
*/
|
|
54
|
+
defaultHeaders?: Core.Headers;
|
|
55
|
+
/**
|
|
56
|
+
* Default query parameters to include with every request to the API.
|
|
57
|
+
*
|
|
58
|
+
* These can be removed in individual requests by explicitly setting the
|
|
59
|
+
* param to `undefined` in request options.
|
|
60
|
+
*/
|
|
61
|
+
defaultQuery?: Core.DefaultQuery;
|
|
59
62
|
}
|
|
60
63
|
/** API Client for interfacing with the Anthropic API. */
|
|
61
64
|
export declare class Anthropic extends Core.APIClient {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
65
|
+
apiKey: string | null;
|
|
66
|
+
authToken: string | null;
|
|
67
|
+
private _options;
|
|
68
|
+
/**
|
|
69
|
+
* API Client for interfacing with the Anthropic API.
|
|
70
|
+
*
|
|
71
|
+
* @param {string | null} [opts.apiKey==process.env['ANTHROPIC_API_KEY'] ?? null]
|
|
72
|
+
* @param {string | null} [opts.authToken==process.env['ANTHROPIC_AUTH_TOKEN'] ?? null]
|
|
73
|
+
* @param {string} [opts.baseURL] - Override the default base URL for the API.
|
|
74
|
+
* @param {number} [opts.timeout=10 minutes] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
|
|
75
|
+
* @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections.
|
|
76
|
+
* @param {Core.Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
|
|
77
|
+
* @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.
|
|
78
|
+
* @param {Core.Headers} opts.defaultHeaders - Default headers to include with every request to the API.
|
|
79
|
+
* @param {Core.DefaultQuery} opts.defaultQuery - Default query parameters to include with every request to the API.
|
|
80
|
+
*/
|
|
81
|
+
constructor({ apiKey, authToken, ...opts }?: ClientOptions);
|
|
82
|
+
completions: API.Completions;
|
|
83
|
+
protected defaultQuery(): Core.DefaultQuery | undefined;
|
|
84
|
+
protected defaultHeaders(opts: Core.FinalRequestOptions): Core.Headers;
|
|
85
|
+
protected validateHeaders(headers: Core.Headers, customHeaders: Core.Headers): void;
|
|
86
|
+
protected authHeaders(opts: Core.FinalRequestOptions): Core.Headers;
|
|
87
|
+
protected apiKeyAuth(opts: Core.FinalRequestOptions): Core.Headers;
|
|
88
|
+
protected bearerAuth(opts: Core.FinalRequestOptions): Core.Headers;
|
|
89
|
+
static Anthropic: typeof Anthropic;
|
|
90
|
+
static HUMAN_PROMPT: string;
|
|
91
|
+
static AI_PROMPT: string;
|
|
92
|
+
static AnthropicError: typeof Errors.AnthropicError;
|
|
93
|
+
static APIError: typeof Errors.APIError;
|
|
94
|
+
static APIConnectionError: typeof Errors.APIConnectionError;
|
|
95
|
+
static APIConnectionTimeoutError: typeof Errors.APIConnectionTimeoutError;
|
|
96
|
+
static APIUserAbortError: typeof Errors.APIUserAbortError;
|
|
97
|
+
static NotFoundError: typeof Errors.NotFoundError;
|
|
98
|
+
static ConflictError: typeof Errors.ConflictError;
|
|
99
|
+
static RateLimitError: typeof Errors.RateLimitError;
|
|
100
|
+
static BadRequestError: typeof Errors.BadRequestError;
|
|
101
|
+
static AuthenticationError: typeof Errors.AuthenticationError;
|
|
102
|
+
static InternalServerError: typeof Errors.InternalServerError;
|
|
103
|
+
static PermissionDeniedError: typeof Errors.PermissionDeniedError;
|
|
104
|
+
static UnprocessableEntityError: typeof Errors.UnprocessableEntityError;
|
|
101
105
|
}
|
|
102
106
|
export declare const HUMAN_PROMPT: string, AI_PROMPT: string;
|
|
103
|
-
export declare const APIError: typeof Errors.APIError,
|
|
104
|
-
APIConnectionError: typeof Errors.APIConnectionError,
|
|
105
|
-
APIConnectionTimeoutError: typeof Errors.APIConnectionTimeoutError,
|
|
106
|
-
APIUserAbortError: typeof Errors.APIUserAbortError,
|
|
107
|
-
NotFoundError: typeof Errors.NotFoundError,
|
|
108
|
-
ConflictError: typeof Errors.ConflictError,
|
|
109
|
-
RateLimitError: typeof Errors.RateLimitError,
|
|
110
|
-
BadRequestError: typeof Errors.BadRequestError,
|
|
111
|
-
AuthenticationError: typeof Errors.AuthenticationError,
|
|
112
|
-
InternalServerError: typeof Errors.InternalServerError,
|
|
113
|
-
PermissionDeniedError: typeof Errors.PermissionDeniedError,
|
|
114
|
-
UnprocessableEntityError: typeof Errors.UnprocessableEntityError;
|
|
107
|
+
export declare const AnthropicError: typeof Errors.AnthropicError, APIError: typeof Errors.APIError, APIConnectionError: typeof Errors.APIConnectionError, APIConnectionTimeoutError: typeof Errors.APIConnectionTimeoutError, APIUserAbortError: typeof Errors.APIUserAbortError, NotFoundError: typeof Errors.NotFoundError, ConflictError: typeof Errors.ConflictError, RateLimitError: typeof Errors.RateLimitError, BadRequestError: typeof Errors.BadRequestError, AuthenticationError: typeof Errors.AuthenticationError, InternalServerError: typeof Errors.InternalServerError, PermissionDeniedError: typeof Errors.PermissionDeniedError, UnprocessableEntityError: typeof Errors.UnprocessableEntityError;
|
|
115
108
|
export import toFile = Uploads.toFile;
|
|
116
109
|
export import fileFromPath = Uploads.fileFromPath;
|
|
117
110
|
export declare namespace Anthropic {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
111
|
+
export import toFile = Uploads.toFile;
|
|
112
|
+
export import fileFromPath = Uploads.fileFromPath;
|
|
113
|
+
export import RequestOptions = Core.RequestOptions;
|
|
114
|
+
export import Completions = API.Completions;
|
|
115
|
+
export import Completion = API.Completion;
|
|
116
|
+
export import CompletionCreateParams = API.CompletionCreateParams;
|
|
117
|
+
export import CompletionCreateParamsNonStreaming = API.CompletionCreateParamsNonStreaming;
|
|
118
|
+
export import CompletionCreateParamsStreaming = API.CompletionCreateParamsStreaming;
|
|
126
119
|
}
|
|
127
120
|
export default Anthropic;
|
|
128
|
-
//# sourceMappingURL=index.d.ts.map
|
|
121
|
+
//# sourceMappingURL=index.d.ts.map
|