@core-ai/anthropic 0.22.0 → 0.24.0
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/dist/index.js +16 -3
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
ContextLengthExceededError,
|
|
20
20
|
ModelOverloadedError,
|
|
21
21
|
ProviderError,
|
|
22
|
+
ProviderQuotaExceededError,
|
|
22
23
|
RateLimitError,
|
|
23
24
|
ServiceUnavailableError,
|
|
24
25
|
asRecord,
|
|
@@ -45,7 +46,7 @@ function wrapAnthropicError(error, provider = "anthropic") {
|
|
|
45
46
|
const statusCode = error instanceof APIError ? error.status : getHttpStatusCode(error, ["status"]);
|
|
46
47
|
const providerMessage = getAnthropicErrorMessage(error);
|
|
47
48
|
const errorType = getAnthropicErrorType(error);
|
|
48
|
-
const options = { statusCode, cause: error };
|
|
49
|
+
const options = { statusCode, code: errorType, cause: error };
|
|
49
50
|
const contextLength = getContextLengthDetails(providerMessage, errorType);
|
|
50
51
|
if (contextLength) {
|
|
51
52
|
return new ContextLengthExceededError(message, provider, {
|
|
@@ -56,17 +57,23 @@ function wrapAnthropicError(error, provider = "anthropic") {
|
|
|
56
57
|
if (isAnthropicOverloaded(errorType, providerMessage, message, statusCode)) {
|
|
57
58
|
return new ModelOverloadedError(message, provider, options);
|
|
58
59
|
}
|
|
60
|
+
if (isAnthropicQuotaExceeded(errorType, statusCode)) {
|
|
61
|
+
return new ProviderQuotaExceededError(message, provider, options);
|
|
62
|
+
}
|
|
59
63
|
if (isAnthropicRateLimit(error, statusCode, errorType)) {
|
|
60
64
|
return new RateLimitError(message, provider, {
|
|
61
65
|
...options,
|
|
62
66
|
retryAfterSeconds: getRetryAfterSecondsFromError(error)
|
|
63
67
|
});
|
|
64
68
|
}
|
|
65
|
-
if (isUnavailableStatus(error) || isTransientUnavailableStatus(statusCode)) {
|
|
69
|
+
if (isUnavailableStatus(error) || isTransientUnavailableStatus(statusCode) || isAnthropicServerError(errorType)) {
|
|
66
70
|
return new ServiceUnavailableError(message, provider, options);
|
|
67
71
|
}
|
|
68
72
|
return new ProviderError(message, provider, options);
|
|
69
73
|
}
|
|
74
|
+
function isAnthropicServerError(errorType) {
|
|
75
|
+
return errorType === "api_error" || errorType === "timeout_error";
|
|
76
|
+
}
|
|
70
77
|
function isAnthropicAbortError(error) {
|
|
71
78
|
return error instanceof APIUserAbortError || isAbortErrorByName(error);
|
|
72
79
|
}
|
|
@@ -76,6 +83,9 @@ function isAnthropicOverloaded(errorType, providerMessage, message, statusCode)
|
|
|
76
83
|
statusCode
|
|
77
84
|
);
|
|
78
85
|
}
|
|
86
|
+
function isAnthropicQuotaExceeded(errorType, statusCode) {
|
|
87
|
+
return statusCode === 402 || errorType === "billing_error";
|
|
88
|
+
}
|
|
79
89
|
function indicatesAnthropicOverload(text, statusCode) {
|
|
80
90
|
if (statusCode !== void 0 && !OVERLOAD_MESSAGE_ELIGIBLE_STATUS_CODES.has(statusCode)) {
|
|
81
91
|
return false;
|
|
@@ -1081,7 +1091,10 @@ function createAnthropicChatModel(client, modelId, modelOptions = {}) {
|
|
|
1081
1091
|
options.signal
|
|
1082
1092
|
)
|
|
1083
1093
|
),
|
|
1084
|
-
{
|
|
1094
|
+
{
|
|
1095
|
+
signal: options.signal,
|
|
1096
|
+
mapError: (error) => wrapAnthropicError(error, provider)
|
|
1097
|
+
}
|
|
1085
1098
|
);
|
|
1086
1099
|
}
|
|
1087
1100
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@core-ai/anthropic",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.0",
|
|
4
4
|
"description": "Anthropic provider package for @core-ai/core-ai",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Omnifact (https://omnifact.ai)",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@anthropic-ai/sdk": "^0.110.0",
|
|
48
|
-
"@core-ai/core-ai": "^0.
|
|
48
|
+
"@core-ai/core-ai": "^0.24.0"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"zod": "^4.0.0"
|