@core-ai/openai 0.23.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/{chunk-KLH5XIHP.js → chunk-SCXEGDFV.js} +39 -12
- package/dist/compat.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +2 -2
|
@@ -878,6 +878,7 @@ import {
|
|
|
878
878
|
ContextLengthExceededError,
|
|
879
879
|
ModelOverloadedError,
|
|
880
880
|
ProviderError,
|
|
881
|
+
ProviderQuotaExceededError,
|
|
881
882
|
RateLimitError,
|
|
882
883
|
ServiceUnavailableError,
|
|
883
884
|
asRecord,
|
|
@@ -921,8 +922,8 @@ function wrapOpenAIError(error, provider = "openai") {
|
|
|
921
922
|
if (isAzureOpenAIBackendCapacityError(error)) {
|
|
922
923
|
return new ServiceUnavailableError(message, provider, options);
|
|
923
924
|
}
|
|
924
|
-
if (
|
|
925
|
-
return new
|
|
925
|
+
if (isOpenAIQuotaExceeded(error, statusCode)) {
|
|
926
|
+
return new ProviderQuotaExceededError(message, provider, options);
|
|
926
927
|
}
|
|
927
928
|
if (isAzureOpenAINoCapacity(error)) {
|
|
928
929
|
return new ModelOverloadedError(message, provider, options);
|
|
@@ -1004,13 +1005,14 @@ function isAzureOpenAIBackendCapacityError(error) {
|
|
|
1004
1005
|
const providerMessage = getProviderMessage(error);
|
|
1005
1006
|
return type === "invalid_request_error" && providerMessage?.toLowerCase() === "backend error.";
|
|
1006
1007
|
}
|
|
1007
|
-
function
|
|
1008
|
+
function isOpenAIQuotaExceeded(error, statusCode) {
|
|
1008
1009
|
const code = getProviderErrorCode(error);
|
|
1009
1010
|
const type = getProviderErrorType(error);
|
|
1010
|
-
return code === "insufficient_quota" || type === "insufficient_quota" || code === "credit_balance_exhausted";
|
|
1011
|
+
return statusCode === 402 || code === "insufficient_quota" || type === "insufficient_quota" || code === "credit_balance_exhausted";
|
|
1011
1012
|
}
|
|
1012
1013
|
function isAzureOpenAINoCapacity(error) {
|
|
1013
|
-
|
|
1014
|
+
const code = getProviderErrorCode(error);
|
|
1015
|
+
return code === "NoCapacity" || code === "no_capacity";
|
|
1014
1016
|
}
|
|
1015
1017
|
function getProviderMessage(error) {
|
|
1016
1018
|
if (error instanceof APIError) {
|
|
@@ -1396,12 +1398,10 @@ import {
|
|
|
1396
1398
|
} from "@core-ai/core-ai";
|
|
1397
1399
|
|
|
1398
1400
|
// src/chat-model.ts
|
|
1399
|
-
import {
|
|
1400
|
-
createObjectStream as createObjectStream2,
|
|
1401
|
-
createChatStream as createChatStream2
|
|
1402
|
-
} from "@core-ai/core-ai";
|
|
1401
|
+
import { createObjectStream as createObjectStream2, createChatStream as createChatStream2 } from "@core-ai/core-ai";
|
|
1403
1402
|
|
|
1404
1403
|
// src/chat-adapter.ts
|
|
1404
|
+
import { APIError as APIError2 } from "openai";
|
|
1405
1405
|
import {
|
|
1406
1406
|
getProviderMetadata as getProviderMetadata2,
|
|
1407
1407
|
clampReasoningEffort as clampReasoningEffort2,
|
|
@@ -1663,6 +1663,13 @@ function mapOpenAIProviderOptionsToRequestFields2(options) {
|
|
|
1663
1663
|
};
|
|
1664
1664
|
}
|
|
1665
1665
|
function mapGenerateResponse2(response, adapterOptions = {}) {
|
|
1666
|
+
if (response.status === "failed") {
|
|
1667
|
+
throw createInBandStreamError(
|
|
1668
|
+
response.error ?? {
|
|
1669
|
+
message: "Response failed without error details"
|
|
1670
|
+
}
|
|
1671
|
+
);
|
|
1672
|
+
}
|
|
1666
1673
|
const providerId = adapterOptions.providerId ?? DEFAULT_PROVIDER_ID;
|
|
1667
1674
|
const parts = [];
|
|
1668
1675
|
for (const item of response.output) {
|
|
@@ -1864,6 +1871,16 @@ async function* transformStream2(stream, adapterOptions = {}) {
|
|
|
1864
1871
|
};
|
|
1865
1872
|
};
|
|
1866
1873
|
for await (const event of stream) {
|
|
1874
|
+
if (event.type === "error") {
|
|
1875
|
+
throw createInBandStreamError(event);
|
|
1876
|
+
}
|
|
1877
|
+
if (event.type === "response.failed") {
|
|
1878
|
+
throw createInBandStreamError(
|
|
1879
|
+
event.response.error ?? {
|
|
1880
|
+
message: "Response failed without error details"
|
|
1881
|
+
}
|
|
1882
|
+
);
|
|
1883
|
+
}
|
|
1867
1884
|
if (event.type === "response.reasoning_summary_text.delta") {
|
|
1868
1885
|
const summaryPart = {
|
|
1869
1886
|
itemId: event.item_id,
|
|
@@ -2003,7 +2020,10 @@ async function* transformStream2(stream, adapterOptions = {}) {
|
|
|
2003
2020
|
}
|
|
2004
2021
|
}
|
|
2005
2022
|
const reasoningEndEvent2 = getNextReasoningEndEvent(
|
|
2006
|
-
createReasoningProviderMetadata(
|
|
2023
|
+
createReasoningProviderMetadata(
|
|
2024
|
+
providerId,
|
|
2025
|
+
encryptedContent
|
|
2026
|
+
)
|
|
2007
2027
|
);
|
|
2008
2028
|
if (reasoningEndEvent2) {
|
|
2009
2029
|
yield reasoningEndEvent2;
|
|
@@ -2040,7 +2060,7 @@ async function* transformStream2(stream, adapterOptions = {}) {
|
|
|
2040
2060
|
}
|
|
2041
2061
|
continue;
|
|
2042
2062
|
}
|
|
2043
|
-
if (event.type === "response.completed") {
|
|
2063
|
+
if (event.type === "response.completed" || event.type === "response.incomplete") {
|
|
2044
2064
|
latestResponse = event.response;
|
|
2045
2065
|
yield* closeText();
|
|
2046
2066
|
const reasoningEndEvent2 = getNextReasoningEndEvent(
|
|
@@ -2088,6 +2108,9 @@ async function* transformStream2(stream, adapterOptions = {}) {
|
|
|
2088
2108
|
usage
|
|
2089
2109
|
};
|
|
2090
2110
|
}
|
|
2111
|
+
function createInBandStreamError(body) {
|
|
2112
|
+
return new APIError2(void 0, body, body.message, void 0);
|
|
2113
|
+
}
|
|
2091
2114
|
function mapReasoningToRequestFields2(options, capabilities) {
|
|
2092
2115
|
if (!options.reasoning) {
|
|
2093
2116
|
return {};
|
|
@@ -2137,7 +2160,11 @@ function createOpenAIChatModel(client, modelId, capabilities, providerId = DEFAU
|
|
|
2137
2160
|
request,
|
|
2138
2161
|
options.signal
|
|
2139
2162
|
);
|
|
2140
|
-
|
|
2163
|
+
try {
|
|
2164
|
+
return mapGenerateResponse2(response, { providerId: provider });
|
|
2165
|
+
} catch (error) {
|
|
2166
|
+
throw wrapOpenAIError(error, provider);
|
|
2167
|
+
}
|
|
2141
2168
|
}
|
|
2142
2169
|
async function streamChat(options) {
|
|
2143
2170
|
const request = createStreamRequest2(modelId, options, adapterOptions);
|
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-SCXEGDFV.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.24.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.24.0",
|
|
54
54
|
"openai": "^6.46.0"
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|