@core-ai/openai 0.22.0 → 0.23.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.
|
@@ -271,7 +271,10 @@ var openaiCompatProviderOptionsSchema = openaiChatGenerateProviderOptionsSchema;
|
|
|
271
271
|
var openaiCompatGenerateProviderOptionsSchema = openaiChatGenerateProviderOptionsSchema;
|
|
272
272
|
|
|
273
273
|
// src/chat-completions/chat-model.ts
|
|
274
|
-
import {
|
|
274
|
+
import {
|
|
275
|
+
createObjectStream,
|
|
276
|
+
createChatStream
|
|
277
|
+
} from "@core-ai/core-ai";
|
|
275
278
|
|
|
276
279
|
// src/chat-completions/chat-adapter.ts
|
|
277
280
|
import {
|
|
@@ -895,6 +898,7 @@ var TOKEN_LIMIT_PATTERNS = [
|
|
|
895
898
|
/maximum context length is (\d+) tokens.*you requested (\d+) tokens/i,
|
|
896
899
|
/configured limit of (\d+) tokens.*resulted in (\d+) tokens/i
|
|
897
900
|
];
|
|
901
|
+
var CONTEXT_LENGTH_MESSAGE_PATTERN = /\binput exceeds the context window\b/i;
|
|
898
902
|
var OVERLOAD_MESSAGE_ELIGIBLE_STATUS_CODES = /* @__PURE__ */ new Set([500, 502, 503, 504]);
|
|
899
903
|
function wrapOpenAIError(error, provider = "openai") {
|
|
900
904
|
if (isOpenAIAbortError(error)) {
|
|
@@ -902,7 +906,11 @@ function wrapOpenAIError(error, provider = "openai") {
|
|
|
902
906
|
}
|
|
903
907
|
const message = getErrorMessage(error);
|
|
904
908
|
const statusCode = error instanceof APIError ? error.status : getHttpStatusCode(error, ["status"]);
|
|
905
|
-
const options = {
|
|
909
|
+
const options = {
|
|
910
|
+
statusCode,
|
|
911
|
+
code: getProviderErrorCode(error) ?? getProviderErrorType(error),
|
|
912
|
+
cause: error
|
|
913
|
+
};
|
|
906
914
|
const contextLength = getContextLengthDetails(error, message);
|
|
907
915
|
if (contextLength) {
|
|
908
916
|
return new ContextLengthExceededError(message, provider, {
|
|
@@ -928,11 +936,16 @@ function wrapOpenAIError(error, provider = "openai") {
|
|
|
928
936
|
retryAfterSeconds: getRetryAfterSecondsFromError(error)
|
|
929
937
|
});
|
|
930
938
|
}
|
|
931
|
-
if (isTransientUnavailableStatus(statusCode)) {
|
|
939
|
+
if (isTransientUnavailableStatus(statusCode) || isOpenAIServerError(error)) {
|
|
932
940
|
return new ServiceUnavailableError(message, provider, options);
|
|
933
941
|
}
|
|
934
942
|
return new ProviderError(message, provider, options);
|
|
935
943
|
}
|
|
944
|
+
function isOpenAIServerError(error) {
|
|
945
|
+
const code = getProviderErrorCode(error);
|
|
946
|
+
const type = getProviderErrorType(error);
|
|
947
|
+
return code === "server_error" || code === "service_unavailable" || type === "server_error";
|
|
948
|
+
}
|
|
936
949
|
function isOpenAIAbortError(error) {
|
|
937
950
|
return error instanceof APIUserAbortError || isAbortErrorByName(error);
|
|
938
951
|
}
|
|
@@ -963,7 +976,7 @@ function getContextLengthDetails(error, fallbackMessage) {
|
|
|
963
976
|
if (tokenCounts) {
|
|
964
977
|
return tokenCounts;
|
|
965
978
|
}
|
|
966
|
-
if (!isKnownContextLengthCode) {
|
|
979
|
+
if (!isKnownContextLengthCode && !CONTEXT_LENGTH_MESSAGE_PATTERN.test(providerMessage)) {
|
|
967
980
|
return void 0;
|
|
968
981
|
}
|
|
969
982
|
return {};
|
|
@@ -994,7 +1007,7 @@ function isAzureOpenAIBackendCapacityError(error) {
|
|
|
994
1007
|
function isOpenAIInsufficientQuota(error) {
|
|
995
1008
|
const code = getProviderErrorCode(error);
|
|
996
1009
|
const type = getProviderErrorType(error);
|
|
997
|
-
return code === "insufficient_quota" || type === "insufficient_quota";
|
|
1010
|
+
return code === "insufficient_quota" || type === "insufficient_quota" || code === "credit_balance_exhausted";
|
|
998
1011
|
}
|
|
999
1012
|
function isAzureOpenAINoCapacity(error) {
|
|
1000
1013
|
return getProviderErrorCode(error) === "NoCapacity";
|
|
@@ -1323,7 +1336,10 @@ function createOpenAIChatCompletionsModel(client, modelId, modelOptions) {
|
|
|
1323
1336
|
await callOpenAIChatCompletionsApi(request, options.signal),
|
|
1324
1337
|
adapterOptions
|
|
1325
1338
|
),
|
|
1326
|
-
{
|
|
1339
|
+
{
|
|
1340
|
+
signal: options.signal,
|
|
1341
|
+
mapError: (error) => wrapOpenAIError(error, provider)
|
|
1342
|
+
}
|
|
1327
1343
|
);
|
|
1328
1344
|
}
|
|
1329
1345
|
return {
|
|
@@ -1380,7 +1396,10 @@ import {
|
|
|
1380
1396
|
} from "@core-ai/core-ai";
|
|
1381
1397
|
|
|
1382
1398
|
// src/chat-model.ts
|
|
1383
|
-
import {
|
|
1399
|
+
import {
|
|
1400
|
+
createObjectStream as createObjectStream2,
|
|
1401
|
+
createChatStream as createChatStream2
|
|
1402
|
+
} from "@core-ai/core-ai";
|
|
1384
1403
|
|
|
1385
1404
|
// src/chat-adapter.ts
|
|
1386
1405
|
import {
|
|
@@ -2127,7 +2146,10 @@ function createOpenAIChatModel(client, modelId, capabilities, providerId = DEFAU
|
|
|
2127
2146
|
await callOpenAIResponsesApi(request, options.signal),
|
|
2128
2147
|
{ providerId: provider }
|
|
2129
2148
|
),
|
|
2130
|
-
{
|
|
2149
|
+
{
|
|
2150
|
+
signal: options.signal,
|
|
2151
|
+
mapError: (error) => wrapOpenAIError(error, provider)
|
|
2152
|
+
}
|
|
2131
2153
|
);
|
|
2132
2154
|
}
|
|
2133
2155
|
return {
|
package/dist/compat.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
openaiImageProviderOptionsSchema,
|
|
11
11
|
openaiResponsesGenerateProviderOptionsSchema,
|
|
12
12
|
openaiResponsesProviderOptionsSchema
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-KLH5XIHP.js";
|
|
14
14
|
|
|
15
15
|
// src/provider.ts
|
|
16
16
|
function createOpenAI(options = {}) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@core-ai/openai",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.0",
|
|
4
4
|
"description": "OpenAI provider package for @core-ai/core-ai",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Omnifact (https://omnifact.ai)",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"test:watch": "vitest"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@core-ai/core-ai": "^0.
|
|
53
|
+
"@core-ai/core-ai": "^0.23.0",
|
|
54
54
|
"openai": "^6.46.0"
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|