@core-ai/openai 0.24.0 → 0.26.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.
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
import {
|
|
3
3
|
getRegisteredModelCapabilities,
|
|
4
4
|
MULTIMODAL_INPUT_MODALITIES,
|
|
5
|
+
SUPPORTED_TOOL_SCHEMA_STRICTNESS,
|
|
5
6
|
stripModelDateSuffix,
|
|
6
7
|
TEXT_ONLY_MODALITIES,
|
|
8
|
+
UNSUPPORTED_TOOL_SCHEMA_STRICTNESS,
|
|
7
9
|
UNKNOWN_MODEL
|
|
8
10
|
} from "@core-ai/core-ai";
|
|
9
11
|
var STANDARD_EFFORTS = [
|
|
@@ -37,7 +39,8 @@ function createCapabilities({
|
|
|
37
39
|
supportedEfforts,
|
|
38
40
|
restrictsSamplingParams,
|
|
39
41
|
maxTokensParameter = "max_completion_tokens",
|
|
40
|
-
modalities = MULTIMODAL_INPUT_MODALITIES
|
|
42
|
+
modalities = MULTIMODAL_INPUT_MODALITIES,
|
|
43
|
+
strictToolSchemas = SUPPORTED_TOOL_SCHEMA_STRICTNESS
|
|
41
44
|
}) {
|
|
42
45
|
return {
|
|
43
46
|
reasoning: {
|
|
@@ -47,6 +50,9 @@ function createCapabilities({
|
|
|
47
50
|
supportedToolChoices: ["auto", "none", "required", "tool"]
|
|
48
51
|
},
|
|
49
52
|
modalities,
|
|
53
|
+
tools: {
|
|
54
|
+
strictSchemas: strictToolSchemas
|
|
55
|
+
},
|
|
50
56
|
chatCompletions: {
|
|
51
57
|
maxTokensParameter
|
|
52
58
|
}
|
|
@@ -83,7 +89,8 @@ var GPT_5_HIGH_REASONING_CAPABILITIES = createCapabilities({
|
|
|
83
89
|
});
|
|
84
90
|
function createNoReasoningCapabilities({
|
|
85
91
|
maxTokensParameter,
|
|
86
|
-
modalities = MULTIMODAL_INPUT_MODALITIES
|
|
92
|
+
modalities = MULTIMODAL_INPUT_MODALITIES,
|
|
93
|
+
strictToolSchemas = SUPPORTED_TOOL_SCHEMA_STRICTNESS
|
|
87
94
|
}) {
|
|
88
95
|
return {
|
|
89
96
|
reasoning: {
|
|
@@ -93,6 +100,9 @@ function createNoReasoningCapabilities({
|
|
|
93
100
|
supportedToolChoices: ["auto", "none", "required", "tool"]
|
|
94
101
|
},
|
|
95
102
|
modalities,
|
|
103
|
+
tools: {
|
|
104
|
+
strictSchemas: strictToolSchemas
|
|
105
|
+
},
|
|
96
106
|
chatCompletions: {
|
|
97
107
|
maxTokensParameter
|
|
98
108
|
}
|
|
@@ -101,21 +111,19 @@ function createNoReasoningCapabilities({
|
|
|
101
111
|
var NO_REASONING_CAPABILITIES = createNoReasoningCapabilities({
|
|
102
112
|
maxTokensParameter: "max_tokens"
|
|
103
113
|
});
|
|
104
|
-
var NO_REASONING_TEXT_ONLY_CAPABILITIES = createNoReasoningCapabilities({
|
|
105
|
-
maxTokensParameter: "max_tokens",
|
|
106
|
-
modalities: TEXT_ONLY_MODALITIES
|
|
107
|
-
});
|
|
108
114
|
var NO_REASONING_EFFORT_TEXT_ONLY_CAPABILITIES = createNoReasoningCapabilities({
|
|
109
115
|
maxTokensParameter: "max_completion_tokens",
|
|
110
116
|
modalities: TEXT_ONLY_MODALITIES
|
|
111
117
|
});
|
|
112
118
|
var AUDIO_CAPABILITIES = createNoReasoningCapabilities({
|
|
113
119
|
maxTokensParameter: "max_completion_tokens",
|
|
114
|
-
modalities: OPENAI_AUDIO_INPUT_MODALITIES
|
|
120
|
+
modalities: OPENAI_AUDIO_INPUT_MODALITIES,
|
|
121
|
+
strictToolSchemas: UNSUPPORTED_TOOL_SCHEMA_STRICTNESS
|
|
115
122
|
});
|
|
116
123
|
var GPT_4O_AUDIO_CAPABILITIES = createNoReasoningCapabilities({
|
|
117
124
|
maxTokensParameter: "max_tokens",
|
|
118
|
-
modalities: OPENAI_AUDIO_INPUT_MODALITIES
|
|
125
|
+
modalities: OPENAI_AUDIO_INPUT_MODALITIES,
|
|
126
|
+
strictToolSchemas: UNSUPPORTED_TOOL_SCHEMA_STRICTNESS
|
|
119
127
|
});
|
|
120
128
|
var O_SERIES_MAX_REASONING_CAPABILITIES = createCapabilities({
|
|
121
129
|
supportedEfforts: MAX_EFFORTS,
|
|
@@ -126,7 +134,17 @@ var O_SERIES_TEXT_ONLY_CAPABILITIES = createCapabilities({
|
|
|
126
134
|
restrictsSamplingParams: false,
|
|
127
135
|
modalities: TEXT_ONLY_MODALITIES
|
|
128
136
|
});
|
|
137
|
+
var LEGACY_NO_STRICT_TOOLS_CAPABILITIES = createNoReasoningCapabilities({
|
|
138
|
+
maxTokensParameter: "max_tokens",
|
|
139
|
+
strictToolSchemas: UNSUPPORTED_TOOL_SCHEMA_STRICTNESS
|
|
140
|
+
});
|
|
141
|
+
var LEGACY_NO_STRICT_TOOLS_TEXT_ONLY_CAPABILITIES = createNoReasoningCapabilities({
|
|
142
|
+
maxTokensParameter: "max_tokens",
|
|
143
|
+
modalities: TEXT_ONLY_MODALITIES,
|
|
144
|
+
strictToolSchemas: UNSUPPORTED_TOOL_SCHEMA_STRICTNESS
|
|
145
|
+
});
|
|
129
146
|
var OPENAI_MODEL_CAPABILITIES = {
|
|
147
|
+
"gpt-4o-2024-05-13": LEGACY_NO_STRICT_TOOLS_CAPABILITIES,
|
|
130
148
|
"gpt-5.6-sol": GPT_5_MAX_REASONING_CAPABILITIES,
|
|
131
149
|
"gpt-5.6-terra": SAMPLING_RESTRICTED_STANDARD_CAPABILITIES,
|
|
132
150
|
"gpt-5.6-luna": GPT_5_MINIMAL_REASONING_CAPABILITIES,
|
|
@@ -160,8 +178,8 @@ var OPENAI_MODEL_CAPABILITIES = {
|
|
|
160
178
|
"gpt-4.1-nano": NO_REASONING_CAPABILITIES,
|
|
161
179
|
"gpt-4o": NO_REASONING_CAPABILITIES,
|
|
162
180
|
"gpt-4o-mini": NO_REASONING_CAPABILITIES,
|
|
163
|
-
"gpt-4-turbo":
|
|
164
|
-
"gpt-3.5-turbo":
|
|
181
|
+
"gpt-4-turbo": LEGACY_NO_STRICT_TOOLS_CAPABILITIES,
|
|
182
|
+
"gpt-3.5-turbo": LEGACY_NO_STRICT_TOOLS_TEXT_ONLY_CAPABILITIES,
|
|
165
183
|
"gpt-audio-1.5": AUDIO_CAPABILITIES,
|
|
166
184
|
"gpt-audio": AUDIO_CAPABILITIES,
|
|
167
185
|
"gpt-audio-mini": AUDIO_CAPABILITIES,
|
|
@@ -177,7 +195,14 @@ var OPENAI_REASONING_EFFORT_MAP = {
|
|
|
177
195
|
max: "xhigh"
|
|
178
196
|
};
|
|
179
197
|
function getOpenAIModelCapabilities(modelId) {
|
|
180
|
-
return getRegisteredModelCapabilities(
|
|
198
|
+
return getRegisteredModelCapabilities(
|
|
199
|
+
OPENAI_MODEL_CAPABILITIES,
|
|
200
|
+
getFineTuneBaseModelId(modelId) ?? modelId
|
|
201
|
+
) ?? UNKNOWN_MODEL_CAPABILITIES;
|
|
202
|
+
}
|
|
203
|
+
var FINE_TUNE_MODEL_ID_PATTERN = /^ft:([^:]+):/;
|
|
204
|
+
function getFineTuneBaseModelId(modelId) {
|
|
205
|
+
return FINE_TUNE_MODEL_ID_PATTERN.exec(modelId)?.[1];
|
|
181
206
|
}
|
|
182
207
|
function toOpenAIResponsesCapabilities(capabilities) {
|
|
183
208
|
if (!capabilities.modalities.input.includes("audio")) {
|
|
@@ -204,7 +229,8 @@ var openaiResponsesGenerateProviderOptionsSchema = z.object({
|
|
|
204
229
|
serviceTier: z.enum(["auto", "default", "flex", "scale", "priority"]).optional(),
|
|
205
230
|
include: z.array(z.string()).optional(),
|
|
206
231
|
parallelToolCalls: z.boolean().optional(),
|
|
207
|
-
user: z.string().optional()
|
|
232
|
+
user: z.string().optional(),
|
|
233
|
+
promptCacheKey: z.string().optional()
|
|
208
234
|
}).strict();
|
|
209
235
|
var openaiChatGenerateProviderOptionsSchema = openaiResponsesGenerateProviderOptionsSchema.omit({
|
|
210
236
|
include: true
|
|
@@ -235,11 +261,14 @@ function parseOpenAIProviderOptions(providerOptions, key, schema) {
|
|
|
235
261
|
}
|
|
236
262
|
return schema.parse(rawOptions);
|
|
237
263
|
}
|
|
238
|
-
function parseOpenAIResponsesGenerateProviderOptions(providerOptions
|
|
264
|
+
function parseOpenAIResponsesGenerateProviderOptions(providerOptions, config = {
|
|
265
|
+
key: "openai",
|
|
266
|
+
schema: openaiResponsesGenerateProviderOptionsSchema
|
|
267
|
+
}) {
|
|
239
268
|
return parseOpenAIProviderOptions(
|
|
240
269
|
providerOptions,
|
|
241
|
-
|
|
242
|
-
|
|
270
|
+
config.key,
|
|
271
|
+
config.schema
|
|
243
272
|
);
|
|
244
273
|
}
|
|
245
274
|
function parseOpenAIChatGenerateProviderOptions(providerOptions, config = {
|
|
@@ -285,17 +314,37 @@ import {
|
|
|
285
314
|
} from "@core-ai/core-ai";
|
|
286
315
|
|
|
287
316
|
// src/shared/tools.ts
|
|
288
|
-
import {
|
|
289
|
-
|
|
317
|
+
import {
|
|
318
|
+
normalizeStrictJsonSchema,
|
|
319
|
+
validateToolSchemaStrictness,
|
|
320
|
+
zodSchemaToJsonSchema
|
|
321
|
+
} from "@core-ai/core-ai";
|
|
322
|
+
function convertTools(tools, options) {
|
|
323
|
+
validateToolSchemaStrictness({ tools, ...options });
|
|
290
324
|
return Object.values(tools).map((tool) => ({
|
|
291
325
|
type: "function",
|
|
292
326
|
function: {
|
|
293
327
|
name: tool.name,
|
|
294
328
|
description: tool.description,
|
|
295
|
-
parameters:
|
|
329
|
+
parameters: convertToolParameters(tool),
|
|
330
|
+
...tool.strict === true ? { strict: true } : {}
|
|
296
331
|
}
|
|
297
332
|
}));
|
|
298
333
|
}
|
|
334
|
+
function convertResponseTools(tools, options) {
|
|
335
|
+
validateToolSchemaStrictness({ tools, ...options });
|
|
336
|
+
return Object.values(tools).map((tool) => ({
|
|
337
|
+
type: "function",
|
|
338
|
+
name: tool.name,
|
|
339
|
+
description: tool.description,
|
|
340
|
+
parameters: convertToolParameters(tool),
|
|
341
|
+
strict: tool.strict === true
|
|
342
|
+
}));
|
|
343
|
+
}
|
|
344
|
+
function convertToolParameters(tool) {
|
|
345
|
+
const schema = zodSchemaToJsonSchema(tool.parameters);
|
|
346
|
+
return tool.strict === true ? normalizeStrictJsonSchema(schema) : schema;
|
|
347
|
+
}
|
|
299
348
|
function convertToolChoice(choice) {
|
|
300
349
|
if (typeof choice === "string") {
|
|
301
350
|
return choice;
|
|
@@ -308,6 +357,14 @@ function convertToolChoice(choice) {
|
|
|
308
357
|
};
|
|
309
358
|
}
|
|
310
359
|
|
|
360
|
+
// src/shared/usage.ts
|
|
361
|
+
function normalizeOutputTokens(outputTokens, reasoningTokens, accounting = "included") {
|
|
362
|
+
if (accounting === "separate" && reasoningTokens !== void 0) {
|
|
363
|
+
return outputTokens + reasoningTokens;
|
|
364
|
+
}
|
|
365
|
+
return outputTokens;
|
|
366
|
+
}
|
|
367
|
+
|
|
311
368
|
// src/shared/utils.ts
|
|
312
369
|
import { ValidationError } from "@core-ai/core-ai";
|
|
313
370
|
function safeParseJsonObject(json) {
|
|
@@ -529,7 +586,13 @@ function createRequestBase(modelId, options, adapterOptions) {
|
|
|
529
586
|
return {
|
|
530
587
|
model: modelId,
|
|
531
588
|
messages: convertMessages(options.messages, adapterOptions),
|
|
532
|
-
...options.tools && Object.keys(options.tools).length > 0 ? {
|
|
589
|
+
...options.tools && Object.keys(options.tools).length > 0 ? {
|
|
590
|
+
tools: convertTools(options.tools, {
|
|
591
|
+
capabilities: adapterOptions.capabilities,
|
|
592
|
+
modelId,
|
|
593
|
+
providerId: adapterOptions.providerId
|
|
594
|
+
})
|
|
595
|
+
} : {},
|
|
533
596
|
...options.toolChoice ? { tool_choice: convertToolChoice(options.toolChoice) } : {},
|
|
534
597
|
...reasoningFields,
|
|
535
598
|
...mapSamplingToRequestFields(modelId, options, adapterOptions)
|
|
@@ -552,7 +615,8 @@ function mapOpenAIProviderOptionsToRequestFields(options) {
|
|
|
552
615
|
...options?.stopSequences ? { stop: options.stopSequences } : {},
|
|
553
616
|
...options?.frequencyPenalty !== void 0 ? { frequency_penalty: options.frequencyPenalty } : {},
|
|
554
617
|
...options?.presencePenalty !== void 0 ? { presence_penalty: options.presencePenalty } : {},
|
|
555
|
-
...options?.seed !== void 0 ? { seed: options.seed } : {}
|
|
618
|
+
...options?.seed !== void 0 ? { seed: options.seed } : {},
|
|
619
|
+
...options?.promptCacheKey !== void 0 ? { prompt_cache_key: options.promptCacheKey } : {}
|
|
556
620
|
};
|
|
557
621
|
}
|
|
558
622
|
function mapResponseFormatToRequestFields(format) {
|
|
@@ -616,7 +680,11 @@ function mapGenerateResponse(response, adapterOptions = {}) {
|
|
|
616
680
|
finishReason: mapFinishReason(firstChoice.finish_reason),
|
|
617
681
|
usage: {
|
|
618
682
|
inputTokens: response.usage?.prompt_tokens ?? 0,
|
|
619
|
-
outputTokens:
|
|
683
|
+
outputTokens: normalizeOutputTokens(
|
|
684
|
+
response.usage?.completion_tokens ?? 0,
|
|
685
|
+
reasoningTokens,
|
|
686
|
+
adapterOptions.reasoningTokenAccounting
|
|
687
|
+
),
|
|
620
688
|
inputTokenDetails: {
|
|
621
689
|
cacheReadTokens: response.usage?.prompt_tokens_details?.cached_tokens ?? 0,
|
|
622
690
|
cacheWriteTokens: 0
|
|
@@ -715,7 +783,11 @@ async function* transformStream(stream, adapterOptions = {}) {
|
|
|
715
783
|
const reasoningTokens = chunk.usage.completion_tokens_details?.reasoning_tokens;
|
|
716
784
|
usage = {
|
|
717
785
|
inputTokens: chunk.usage.prompt_tokens ?? 0,
|
|
718
|
-
outputTokens:
|
|
786
|
+
outputTokens: normalizeOutputTokens(
|
|
787
|
+
chunk.usage.completion_tokens ?? 0,
|
|
788
|
+
reasoningTokens,
|
|
789
|
+
adapterOptions.reasoningTokenAccounting
|
|
790
|
+
),
|
|
719
791
|
inputTokenDetails: {
|
|
720
792
|
cacheReadTokens: chunk.usage.prompt_tokens_details?.cached_tokens ?? 0,
|
|
721
793
|
cacheWriteTokens: 0
|
|
@@ -1310,6 +1382,7 @@ function createOpenAIChatCompletionsModel(client, modelId, modelOptions) {
|
|
|
1310
1382
|
capabilities,
|
|
1311
1383
|
compatibility: compatibilityOptions !== void 0 && compatibilityOptions.reasoning !== false,
|
|
1312
1384
|
maxTokensParameter: compatibilityOptions?.maxTokensParameter,
|
|
1385
|
+
reasoningTokenAccounting: compatibilityOptions?.reasoningTokenAccounting,
|
|
1313
1386
|
providerId: provider,
|
|
1314
1387
|
providerOptions: modelOptions.providerOptions,
|
|
1315
1388
|
reasoning: typeof compatibilityOptions?.reasoning === "object" ? compatibilityOptions.reasoning : void 0
|
|
@@ -1411,9 +1484,11 @@ import {
|
|
|
1411
1484
|
} from "@core-ai/core-ai";
|
|
1412
1485
|
var DEFAULT_PROVIDER_ID = "openai";
|
|
1413
1486
|
function resolveAdapterOptions(modelId, adapterOptions) {
|
|
1414
|
-
const capabilities = adapterOptions.capabilities ?? getOpenAIModelCapabilities(modelId);
|
|
1415
1487
|
return {
|
|
1416
|
-
capabilities
|
|
1488
|
+
// Callers that pass capabilities (the provider factory) have already
|
|
1489
|
+
// applied the Responses-specific restrictions; only the fallback
|
|
1490
|
+
// lookup applies them here.
|
|
1491
|
+
capabilities: adapterOptions.capabilities ?? toOpenAIResponsesCapabilities(getOpenAIModelCapabilities(modelId)),
|
|
1417
1492
|
// Also the ownership key for encrypted reasoning metadata — Azure
|
|
1418
1493
|
// (`azure-openai`) must not share the `openai` namespace.
|
|
1419
1494
|
providerId: adapterOptions.providerId ?? DEFAULT_PROVIDER_ID
|
|
@@ -1573,7 +1648,8 @@ function createStreamRequest2(modelId, options, adapterOptions = {}) {
|
|
|
1573
1648
|
function createRequest2(modelId, options, stream, adapterOptions) {
|
|
1574
1649
|
const resolved = resolveAdapterOptions(modelId, adapterOptions);
|
|
1575
1650
|
const openaiOptions = parseOpenAIResponsesGenerateProviderOptions(
|
|
1576
|
-
options.providerOptions
|
|
1651
|
+
options.providerOptions,
|
|
1652
|
+
adapterOptions.providerOptions
|
|
1577
1653
|
);
|
|
1578
1654
|
const request = {
|
|
1579
1655
|
...createRequestBase2(modelId, options, resolved),
|
|
@@ -1581,7 +1657,8 @@ function createRequest2(modelId, options, stream, adapterOptions) {
|
|
|
1581
1657
|
...options.structuredOutputFormat ? { text: { format: options.structuredOutputFormat } } : {},
|
|
1582
1658
|
...mapOpenAIProviderOptionsToRequestFields2(openaiOptions)
|
|
1583
1659
|
};
|
|
1584
|
-
|
|
1660
|
+
const reasoningMode = resolved.capabilities.reasoning.mode;
|
|
1661
|
+
if (reasoningMode === "always-on" || options.reasoning && reasoningMode !== "unsupported") {
|
|
1585
1662
|
request.include = mergeInclude(request.include, [
|
|
1586
1663
|
ENCRYPTED_REASONING_INCLUDE
|
|
1587
1664
|
]);
|
|
@@ -1603,7 +1680,13 @@ function createRequestBase2(modelId, options, { capabilities, providerId }) {
|
|
|
1603
1680
|
includeReasoning: capabilities.reasoning.mode !== "unsupported",
|
|
1604
1681
|
providerId
|
|
1605
1682
|
}),
|
|
1606
|
-
...options.tools && Object.keys(options.tools).length > 0 ? {
|
|
1683
|
+
...options.tools && Object.keys(options.tools).length > 0 ? {
|
|
1684
|
+
tools: convertResponseTools(options.tools, {
|
|
1685
|
+
capabilities,
|
|
1686
|
+
modelId,
|
|
1687
|
+
providerId
|
|
1688
|
+
})
|
|
1689
|
+
} : {},
|
|
1607
1690
|
...options.toolChoice ? { tool_choice: convertResponseToolChoice(options.toolChoice) } : {},
|
|
1608
1691
|
...mapReasoningToRequestFields2(options, capabilities),
|
|
1609
1692
|
...mapSamplingToRequestFields2(options)
|
|
@@ -1619,14 +1702,6 @@ function validateResponsesInputModalities(options) {
|
|
|
1619
1702
|
throw error;
|
|
1620
1703
|
}
|
|
1621
1704
|
}
|
|
1622
|
-
function convertResponseTools(tools) {
|
|
1623
|
-
return convertTools(tools).map((tool) => ({
|
|
1624
|
-
type: "function",
|
|
1625
|
-
name: tool.function.name,
|
|
1626
|
-
description: tool.function.description,
|
|
1627
|
-
parameters: tool.function.parameters
|
|
1628
|
-
}));
|
|
1629
|
-
}
|
|
1630
1705
|
function convertResponseToolChoice(choice) {
|
|
1631
1706
|
const converted = convertToolChoice(choice);
|
|
1632
1707
|
if (typeof converted === "string") {
|
|
@@ -1659,7 +1734,8 @@ function mapOpenAIProviderOptionsToRequestFields2(options) {
|
|
|
1659
1734
|
...options?.serviceTier !== void 0 ? { service_tier: options.serviceTier } : {},
|
|
1660
1735
|
...options?.include ? { include: options.include } : {},
|
|
1661
1736
|
...options?.parallelToolCalls !== void 0 ? { parallel_tool_calls: options.parallelToolCalls } : {},
|
|
1662
|
-
...options?.user !== void 0 ? { user: options.user } : {}
|
|
1737
|
+
...options?.user !== void 0 ? { user: options.user } : {},
|
|
1738
|
+
...options?.promptCacheKey !== void 0 ? { prompt_cache_key: options.promptCacheKey } : {}
|
|
1663
1739
|
};
|
|
1664
1740
|
}
|
|
1665
1741
|
function mapGenerateResponse2(response, adapterOptions = {}) {
|
|
@@ -2115,7 +2191,7 @@ function mapReasoningToRequestFields2(options, capabilities) {
|
|
|
2115
2191
|
if (!options.reasoning) {
|
|
2116
2192
|
return {};
|
|
2117
2193
|
}
|
|
2118
|
-
if (capabilities.reasoning.mode === "unsupported") {
|
|
2194
|
+
if (capabilities.reasoning.mode === "unsupported" || capabilities.reasoning.supportedEfforts.length === 0) {
|
|
2119
2195
|
return {};
|
|
2120
2196
|
}
|
|
2121
2197
|
const effort = toOpenAIReasoningEffort(
|
|
@@ -2142,9 +2218,13 @@ function isReasoningItem(item) {
|
|
|
2142
2218
|
}
|
|
2143
2219
|
|
|
2144
2220
|
// src/chat-model.ts
|
|
2145
|
-
function createOpenAIChatModel(client, modelId, capabilities,
|
|
2146
|
-
const provider = providerId;
|
|
2147
|
-
const adapterOptions = {
|
|
2221
|
+
function createOpenAIChatModel(client, modelId, capabilities, modelOptions = {}) {
|
|
2222
|
+
const provider = modelOptions.providerId ?? DEFAULT_PROVIDER_ID;
|
|
2223
|
+
const adapterOptions = {
|
|
2224
|
+
capabilities,
|
|
2225
|
+
providerId: provider,
|
|
2226
|
+
providerOptions: modelOptions.providerOptions
|
|
2227
|
+
};
|
|
2148
2228
|
async function callOpenAIResponsesApi(request, signal) {
|
|
2149
2229
|
try {
|
|
2150
2230
|
return await client.responses.create(request, {
|
|
@@ -2313,37 +2393,39 @@ function createOpenAIProvider(options, factoryOptions = {}) {
|
|
|
2313
2393
|
});
|
|
2314
2394
|
const providerId = factoryOptions.providerId ?? "openai";
|
|
2315
2395
|
const compatibilityOptions = typeof factoryOptions.compatibility === "object" ? factoryOptions.compatibility : void 0;
|
|
2316
|
-
const
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
providerId
|
|
2326
|
-
|
|
2327
|
-
|
|
2396
|
+
const resolveCapabilities = (modelId) => getRegisteredModelCapabilities2(
|
|
2397
|
+
factoryOptions.modelCapabilities,
|
|
2398
|
+
modelId
|
|
2399
|
+
) ?? getOpenAIModelCapabilities(modelId);
|
|
2400
|
+
const createResponsesModel = (modelId) => createOpenAIChatModel(
|
|
2401
|
+
client,
|
|
2402
|
+
modelId,
|
|
2403
|
+
toOpenAIResponsesCapabilities(resolveCapabilities(modelId)),
|
|
2404
|
+
{
|
|
2405
|
+
providerId,
|
|
2406
|
+
providerOptions: {
|
|
2407
|
+
key: providerId,
|
|
2408
|
+
schema: factoryOptions.responsesProviderOptionsSchema ?? openaiResponsesGenerateProviderOptionsSchema
|
|
2409
|
+
}
|
|
2410
|
+
}
|
|
2411
|
+
);
|
|
2328
2412
|
const createChatCompletionsModel = (modelId) => {
|
|
2329
|
-
const capabilities =
|
|
2330
|
-
factoryOptions.modelCapabilities,
|
|
2331
|
-
modelId
|
|
2332
|
-
) ?? getOpenAIModelCapabilities(modelId);
|
|
2413
|
+
const capabilities = resolveCapabilities(modelId);
|
|
2333
2414
|
const compatibility = factoryOptions.compatibility ? {
|
|
2334
2415
|
reasoning: typeof compatibilityOptions?.reasoning === "object" ? {
|
|
2335
2416
|
...compatibilityOptions.reasoning,
|
|
2336
2417
|
providerMetadataKey: compatibilityOptions.reasoning.providerMetadataKey ?? providerId
|
|
2337
2418
|
} : compatibilityOptions?.reasoning ?? true,
|
|
2338
2419
|
structuredOutputMode: compatibilityOptions?.structuredOutputMode,
|
|
2339
|
-
maxTokensParameter: compatibilityOptions?.maxTokensParameter
|
|
2420
|
+
maxTokensParameter: compatibilityOptions?.maxTokensParameter,
|
|
2421
|
+
reasoningTokenAccounting: compatibilityOptions?.reasoningTokenAccounting
|
|
2340
2422
|
} : void 0;
|
|
2341
2423
|
return createOpenAIChatCompletionsModel(client, modelId, {
|
|
2342
2424
|
providerId,
|
|
2343
2425
|
capabilities,
|
|
2344
2426
|
compatibility,
|
|
2345
2427
|
providerOptions: {
|
|
2346
|
-
key:
|
|
2428
|
+
key: providerId,
|
|
2347
2429
|
schema: factoryOptions.providerOptionsSchema ?? openaiChatGenerateProviderOptionsSchema
|
|
2348
2430
|
}
|
|
2349
2431
|
});
|
package/dist/compat.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as _core_ai_core_ai from '@core-ai/core-ai';
|
|
2
2
|
import { ChatModel } from '@core-ai/core-ai';
|
|
3
|
-
import { O as OpenAIChatClient, a as OpenAIProvider, b as OpenAIProviderBaseOptions } from './provider-factory-
|
|
4
|
-
export { c as OpenAICompatGenerateProviderOptions, d as OpenAICompatRequestOptions, o as openaiCompatGenerateProviderOptionsSchema, e as openaiCompatProviderOptionsSchema } from './provider-factory-
|
|
3
|
+
import { O as OpenAIChatClient, a as OpenAIProvider, b as OpenAIProviderBaseOptions } from './provider-factory-BIr9zZ2d.js';
|
|
4
|
+
export { c as OpenAICompatGenerateProviderOptions, d as OpenAICompatRequestOptions, o as openaiCompatGenerateProviderOptionsSchema, e as openaiCompatProviderOptionsSchema } from './provider-factory-BIr9zZ2d.js';
|
|
5
5
|
import 'openai';
|
|
6
6
|
import 'zod';
|
|
7
7
|
|
package/dist/compat.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as OpenAIProvider$1, b as OpenAIProviderBaseOptions } from './provider-factory-
|
|
2
|
-
export { O as OpenAIChatClient, f as OpenAIChatCompletionsModelOptions, g as OpenAIChatGenerateProviderOptions, h as OpenAIChatProvider, c as OpenAICompatGenerateProviderOptions, d as OpenAICompatRequestOptions,
|
|
1
|
+
import { a as OpenAIProvider$1, b as OpenAIProviderBaseOptions } from './provider-factory-BIr9zZ2d.js';
|
|
2
|
+
export { O as OpenAIChatClient, f as OpenAIChatCompletionsModelOptions, g as OpenAIChatGenerateProviderOptions, h as OpenAIChatGenerateProviderOptionsConfig, i as OpenAIChatProvider, c as OpenAICompatGenerateProviderOptions, d as OpenAICompatRequestOptions, j as OpenAICompatibility, k as OpenAICompatibilityOptions, l as OpenAIEmbedProviderOptions, m as OpenAIImageProviderOptions, n as OpenAIModelCapabilities, p as OpenAIProviderFactoryOptions, q as OpenAIReasoningTokenAccounting, r as OpenAIResponsesGenerateProviderOptions, s as OpenAIResponsesGenerateProviderOptionsConfig, t as OpenAIResponsesProviderOptions, u as OpenAIStructuredOutputMode, v as createOpenAIChatCompletionsModel, w as createOpenAIProvider, x as getOpenAIModelCapabilities, y as openaiChatGenerateProviderOptionsSchema, o as openaiCompatGenerateProviderOptionsSchema, e as openaiCompatProviderOptionsSchema, z as openaiEmbedProviderOptionsSchema, A as openaiImageProviderOptionsSchema, B as openaiResponsesGenerateProviderOptionsSchema, C as openaiResponsesProviderOptionsSchema } from './provider-factory-BIr9zZ2d.js';
|
|
3
3
|
import 'openai';
|
|
4
4
|
import '@core-ai/core-ai';
|
|
5
5
|
import 'zod';
|
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-FOVN4IGD.js";
|
|
14
14
|
|
|
15
15
|
// src/provider.ts
|
|
16
16
|
function createOpenAI(options = {}) {
|
|
@@ -12,6 +12,13 @@ declare function getOpenAIModelCapabilities(modelId: string): OpenAIModelCapabil
|
|
|
12
12
|
|
|
13
13
|
type OpenAIStructuredOutputMode = 'json-schema' | 'tool' | 'json-object';
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* How an endpoint reports reasoning tokens relative to its output-token total.
|
|
17
|
+
* `included` (OpenAI): the output total already contains them. `separate`
|
|
18
|
+
* (e.g. xAI Chat Completions): they are reported only in the details object.
|
|
19
|
+
*/
|
|
20
|
+
type OpenAIReasoningTokenAccounting = 'included' | 'separate';
|
|
21
|
+
|
|
15
22
|
type OpenAIReasoningCompatibilityOptions = {
|
|
16
23
|
requestField: 'reasoning_content' | 'reasoning';
|
|
17
24
|
providerMetadataKey?: string;
|
|
@@ -20,10 +27,12 @@ type OpenAICompatibilityOptions = {
|
|
|
20
27
|
reasoning?: boolean | OpenAIReasoningCompatibilityOptions;
|
|
21
28
|
structuredOutputMode?: OpenAIStructuredOutputMode;
|
|
22
29
|
maxTokensParameter?: OpenAIChatCompletionsCapabilities['maxTokensParameter'];
|
|
30
|
+
/** Chat Completions only. Defaults to `included`. */
|
|
31
|
+
reasoningTokenAccounting?: OpenAIReasoningTokenAccounting;
|
|
23
32
|
};
|
|
24
33
|
type OpenAICompatibility = boolean | OpenAICompatibilityOptions;
|
|
25
34
|
type OpenAIResolvedReasoningCompatibilityOptions = Required<OpenAIReasoningCompatibilityOptions>;
|
|
26
|
-
type OpenAIResolvedCompatibilityOptions = Pick<OpenAICompatibilityOptions, 'structuredOutputMode' | 'maxTokensParameter'> & {
|
|
35
|
+
type OpenAIResolvedCompatibilityOptions = Pick<OpenAICompatibilityOptions, 'structuredOutputMode' | 'maxTokensParameter' | 'reasoningTokenAccounting'> & {
|
|
27
36
|
reasoning: boolean | OpenAIResolvedReasoningCompatibilityOptions;
|
|
28
37
|
};
|
|
29
38
|
|
|
@@ -39,6 +48,7 @@ declare const openaiResponsesGenerateProviderOptionsSchema: z.ZodObject<{
|
|
|
39
48
|
include: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
40
49
|
parallelToolCalls: z.ZodOptional<z.ZodBoolean>;
|
|
41
50
|
user: z.ZodOptional<z.ZodString>;
|
|
51
|
+
promptCacheKey: z.ZodOptional<z.ZodString>;
|
|
42
52
|
}, z.core.$strict>;
|
|
43
53
|
type OpenAIResponsesGenerateProviderOptions = z.infer<typeof openaiResponsesGenerateProviderOptionsSchema>;
|
|
44
54
|
declare const openaiChatGenerateProviderOptionsSchema: z.ZodObject<{
|
|
@@ -52,12 +62,17 @@ declare const openaiChatGenerateProviderOptionsSchema: z.ZodObject<{
|
|
|
52
62
|
priority: "priority";
|
|
53
63
|
}>>;
|
|
54
64
|
parallelToolCalls: z.ZodOptional<z.ZodBoolean>;
|
|
65
|
+
promptCacheKey: z.ZodOptional<z.ZodString>;
|
|
55
66
|
stopSequences: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
56
67
|
frequencyPenalty: z.ZodOptional<z.ZodNumber>;
|
|
57
68
|
presencePenalty: z.ZodOptional<z.ZodNumber>;
|
|
58
69
|
seed: z.ZodOptional<z.ZodNumber>;
|
|
59
70
|
}, z.core.$strict>;
|
|
60
71
|
type OpenAIChatGenerateProviderOptions = z.infer<typeof openaiChatGenerateProviderOptionsSchema>;
|
|
72
|
+
type OpenAIResponsesGenerateProviderOptionsConfig = {
|
|
73
|
+
key: string;
|
|
74
|
+
schema: z.ZodType<OpenAIResponsesGenerateProviderOptions>;
|
|
75
|
+
};
|
|
61
76
|
type OpenAIChatGenerateProviderOptionsConfig = {
|
|
62
77
|
key: string;
|
|
63
78
|
schema: z.ZodType<OpenAIChatGenerateProviderOptions>;
|
|
@@ -128,6 +143,7 @@ declare const openaiResponsesProviderOptionsSchema: z.ZodObject<{
|
|
|
128
143
|
include: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
129
144
|
parallelToolCalls: z.ZodOptional<z.ZodBoolean>;
|
|
130
145
|
user: z.ZodOptional<z.ZodString>;
|
|
146
|
+
promptCacheKey: z.ZodOptional<z.ZodString>;
|
|
131
147
|
}, z.core.$strict>;
|
|
132
148
|
type OpenAIResponsesProviderOptions = OpenAIResponsesGenerateProviderOptions;
|
|
133
149
|
declare const openaiCompatProviderOptionsSchema: z.ZodObject<{
|
|
@@ -141,6 +157,7 @@ declare const openaiCompatProviderOptionsSchema: z.ZodObject<{
|
|
|
141
157
|
priority: "priority";
|
|
142
158
|
}>>;
|
|
143
159
|
parallelToolCalls: z.ZodOptional<z.ZodBoolean>;
|
|
160
|
+
promptCacheKey: z.ZodOptional<z.ZodString>;
|
|
144
161
|
stopSequences: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
145
162
|
frequencyPenalty: z.ZodOptional<z.ZodNumber>;
|
|
146
163
|
presencePenalty: z.ZodOptional<z.ZodNumber>;
|
|
@@ -157,6 +174,7 @@ declare const openaiCompatGenerateProviderOptionsSchema: z.ZodObject<{
|
|
|
157
174
|
priority: "priority";
|
|
158
175
|
}>>;
|
|
159
176
|
parallelToolCalls: z.ZodOptional<z.ZodBoolean>;
|
|
177
|
+
promptCacheKey: z.ZodOptional<z.ZodString>;
|
|
160
178
|
stopSequences: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
161
179
|
frequencyPenalty: z.ZodOptional<z.ZodNumber>;
|
|
162
180
|
presencePenalty: z.ZodOptional<z.ZodNumber>;
|
|
@@ -172,6 +190,7 @@ type OpenAIChatCompletionsAdapterOptions = {
|
|
|
172
190
|
providerId?: string;
|
|
173
191
|
providerOptions?: OpenAIChatGenerateProviderOptionsConfig;
|
|
174
192
|
reasoning?: OpenAIResolvedReasoningCompatibilityOptions;
|
|
193
|
+
reasoningTokenAccounting?: OpenAIReasoningTokenAccounting;
|
|
175
194
|
};
|
|
176
195
|
|
|
177
196
|
type OpenAIChatClient = {
|
|
@@ -201,12 +220,15 @@ type OpenAIChatProvider = {
|
|
|
201
220
|
};
|
|
202
221
|
type OpenAIProviderFactoryOptions = {
|
|
203
222
|
modelCapabilities?: ModelCapabilitiesRegistry;
|
|
223
|
+
/** Also the `providerOptions` and reasoning `providerMetadata` key. */
|
|
204
224
|
providerId?: string;
|
|
205
|
-
|
|
225
|
+
/** Chat Completions provider options schema. */
|
|
206
226
|
providerOptionsSchema?: OpenAIChatGenerateProviderOptionsConfig['schema'];
|
|
227
|
+
/** Responses API provider options schema. */
|
|
228
|
+
responsesProviderOptionsSchema?: OpenAIResponsesGenerateProviderOptionsConfig['schema'];
|
|
207
229
|
defaultApi?: 'responses' | 'chat-completions';
|
|
208
230
|
compatibility?: OpenAICompatibility;
|
|
209
231
|
};
|
|
210
232
|
declare function createOpenAIProvider(options: OpenAIProviderBaseOptions, factoryOptions?: OpenAIProviderFactoryOptions): OpenAIProvider;
|
|
211
233
|
|
|
212
|
-
export { type OpenAIChatClient as O, type OpenAIProvider as a, type OpenAIProviderBaseOptions as b, type OpenAICompatGenerateProviderOptions as c, type OpenAICompatRequestOptions as d, openaiCompatProviderOptionsSchema as e, type OpenAIChatCompletionsModelOptions as f, type OpenAIChatGenerateProviderOptions as g, type
|
|
234
|
+
export { openaiImageProviderOptionsSchema as A, openaiResponsesGenerateProviderOptionsSchema as B, openaiResponsesProviderOptionsSchema as C, type OpenAIChatClient as O, type OpenAIProvider as a, type OpenAIProviderBaseOptions as b, type OpenAICompatGenerateProviderOptions as c, type OpenAICompatRequestOptions as d, openaiCompatProviderOptionsSchema as e, type OpenAIChatCompletionsModelOptions as f, type OpenAIChatGenerateProviderOptions as g, type OpenAIChatGenerateProviderOptionsConfig as h, type OpenAIChatProvider as i, type OpenAICompatibility as j, type OpenAICompatibilityOptions as k, type OpenAIEmbedProviderOptions as l, type OpenAIImageProviderOptions as m, type OpenAIModelCapabilities as n, openaiCompatGenerateProviderOptionsSchema as o, type OpenAIProviderFactoryOptions as p, type OpenAIReasoningTokenAccounting as q, type OpenAIResponsesGenerateProviderOptions as r, type OpenAIResponsesGenerateProviderOptionsConfig as s, type OpenAIResponsesProviderOptions as t, type OpenAIStructuredOutputMode as u, createOpenAIChatCompletionsModel as v, createOpenAIProvider as w, getOpenAIModelCapabilities as x, openaiChatGenerateProviderOptionsSchema as y, openaiEmbedProviderOptionsSchema as z };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@core-ai/openai",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.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.26.0",
|
|
54
54
|
"openai": "^6.46.0"
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|