@core-ai/openai 0.10.2 → 0.11.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-6CVAAVYM.js → chunk-RPCZTXZS.js} +161 -126
- package/dist/compat.d.ts +21 -3
- package/dist/compat.js +18 -4
- package/dist/index.js +50 -8
- package/package.json +2 -2
|
@@ -63,128 +63,6 @@ function parseOpenAIImageProviderOptions(providerOptions) {
|
|
|
63
63
|
var openaiResponsesProviderOptionsSchema = openaiResponsesGenerateProviderOptionsSchema;
|
|
64
64
|
var openaiCompatProviderOptionsSchema = openaiCompatGenerateProviderOptionsSchema;
|
|
65
65
|
|
|
66
|
-
// src/shared/provider-factory.ts
|
|
67
|
-
import OpenAI from "openai";
|
|
68
|
-
|
|
69
|
-
// src/openai-error.ts
|
|
70
|
-
import { APIError, APIUserAbortError } from "openai";
|
|
71
|
-
import { AbortedError, ProviderError } from "@core-ai/core-ai";
|
|
72
|
-
function isOpenAIAbortError(error) {
|
|
73
|
-
return error instanceof APIUserAbortError || error instanceof Error && error.name === "AbortError";
|
|
74
|
-
}
|
|
75
|
-
function wrapOpenAIError(error) {
|
|
76
|
-
if (isOpenAIAbortError(error)) {
|
|
77
|
-
return new AbortedError(error, "openai");
|
|
78
|
-
}
|
|
79
|
-
if (error instanceof APIError) {
|
|
80
|
-
return new ProviderError(error.message, "openai", error.status, error);
|
|
81
|
-
}
|
|
82
|
-
return new ProviderError(
|
|
83
|
-
error instanceof Error ? error.message : String(error),
|
|
84
|
-
"openai",
|
|
85
|
-
void 0,
|
|
86
|
-
error
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// src/embedding-model.ts
|
|
91
|
-
function createOpenAIEmbeddingModel(client, modelId) {
|
|
92
|
-
return {
|
|
93
|
-
provider: "openai",
|
|
94
|
-
modelId,
|
|
95
|
-
async embed(options) {
|
|
96
|
-
try {
|
|
97
|
-
const openaiOptions = parseOpenAIEmbedProviderOptions(
|
|
98
|
-
options.providerOptions
|
|
99
|
-
);
|
|
100
|
-
const response = await client.embeddings.create({
|
|
101
|
-
model: modelId,
|
|
102
|
-
input: options.input,
|
|
103
|
-
...options.dimensions !== void 0 ? { dimensions: options.dimensions } : {},
|
|
104
|
-
...mapOpenAIEmbedProviderOptionsToRequestFields(
|
|
105
|
-
openaiOptions
|
|
106
|
-
)
|
|
107
|
-
});
|
|
108
|
-
return {
|
|
109
|
-
embeddings: response.data.slice().sort((a, b) => a.index - b.index).map((item) => item.embedding),
|
|
110
|
-
usage: {
|
|
111
|
-
inputTokens: response.usage.prompt_tokens
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
} catch (error) {
|
|
115
|
-
throw wrapOpenAIError(error);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
function mapOpenAIEmbedProviderOptionsToRequestFields(options) {
|
|
121
|
-
return {
|
|
122
|
-
...options?.encodingFormat !== void 0 ? { encoding_format: options.encodingFormat } : {},
|
|
123
|
-
...options?.user !== void 0 ? { user: options.user } : {}
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// src/image-model.ts
|
|
128
|
-
function createOpenAIImageModel(client, modelId) {
|
|
129
|
-
return {
|
|
130
|
-
provider: "openai",
|
|
131
|
-
modelId,
|
|
132
|
-
async generate(options) {
|
|
133
|
-
try {
|
|
134
|
-
const openaiOptions = parseOpenAIImageProviderOptions(
|
|
135
|
-
options.providerOptions
|
|
136
|
-
);
|
|
137
|
-
const request = {
|
|
138
|
-
model: modelId,
|
|
139
|
-
prompt: options.prompt,
|
|
140
|
-
...options.n !== void 0 ? { n: options.n } : {},
|
|
141
|
-
...options.size !== void 0 ? { size: options.size } : {},
|
|
142
|
-
...mapOpenAIImageProviderOptionsToRequestFields(
|
|
143
|
-
openaiOptions
|
|
144
|
-
)
|
|
145
|
-
};
|
|
146
|
-
const response = await client.images.generate(
|
|
147
|
-
request
|
|
148
|
-
);
|
|
149
|
-
return {
|
|
150
|
-
images: (response.data ?? []).map((image) => ({
|
|
151
|
-
base64: image.b64_json ?? void 0,
|
|
152
|
-
url: image.url ?? void 0,
|
|
153
|
-
revisedPrompt: image.revised_prompt ?? void 0
|
|
154
|
-
}))
|
|
155
|
-
};
|
|
156
|
-
} catch (error) {
|
|
157
|
-
throw wrapOpenAIError(error);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
function mapOpenAIImageProviderOptionsToRequestFields(options) {
|
|
163
|
-
return {
|
|
164
|
-
...options?.background !== void 0 ? { background: options.background } : {},
|
|
165
|
-
...options?.moderation !== void 0 ? { moderation: options.moderation } : {},
|
|
166
|
-
...options?.outputCompression !== void 0 ? { output_compression: options.outputCompression } : {},
|
|
167
|
-
...options?.outputFormat !== void 0 ? { output_format: options.outputFormat } : {},
|
|
168
|
-
...options?.quality !== void 0 ? { quality: options.quality } : {},
|
|
169
|
-
...options?.responseFormat !== void 0 ? { response_format: options.responseFormat } : {},
|
|
170
|
-
...options?.style !== void 0 ? { style: options.style } : {},
|
|
171
|
-
...options?.user !== void 0 ? { user: options.user } : {}
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
// src/shared/provider-factory.ts
|
|
176
|
-
function createOpenAIProvider(options, createChatModel) {
|
|
177
|
-
const client = options.client ?? new OpenAI({
|
|
178
|
-
apiKey: options.apiKey,
|
|
179
|
-
baseURL: options.baseURL
|
|
180
|
-
});
|
|
181
|
-
return {
|
|
182
|
-
chatModel: (modelId) => createChatModel(client, modelId),
|
|
183
|
-
embeddingModel: (modelId) => createOpenAIEmbeddingModel(client, modelId),
|
|
184
|
-
imageModel: (modelId) => createOpenAIImageModel(client, modelId)
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
|
|
188
66
|
// src/shared/tools.ts
|
|
189
67
|
import { zodSchemaToJsonSchema } from "@core-ai/core-ai";
|
|
190
68
|
var DEFAULT_STRUCTURED_OUTPUT_TOOL_NAME = "core_ai_generate_object";
|
|
@@ -237,6 +115,32 @@ function createStructuredOutputOptions(options) {
|
|
|
237
115
|
};
|
|
238
116
|
}
|
|
239
117
|
|
|
118
|
+
// src/openai-error.ts
|
|
119
|
+
import { APIError, APIUserAbortError } from "openai";
|
|
120
|
+
import { AbortedError, ProviderError } from "@core-ai/core-ai";
|
|
121
|
+
function isOpenAIAbortError(error) {
|
|
122
|
+
return error instanceof APIUserAbortError || error instanceof Error && error.name === "AbortError";
|
|
123
|
+
}
|
|
124
|
+
function wrapOpenAIError(error, provider = "openai") {
|
|
125
|
+
if (isOpenAIAbortError(error)) {
|
|
126
|
+
return new AbortedError(error, provider);
|
|
127
|
+
}
|
|
128
|
+
if (error instanceof APIError) {
|
|
129
|
+
return new ProviderError(
|
|
130
|
+
error.message,
|
|
131
|
+
provider,
|
|
132
|
+
error.status,
|
|
133
|
+
error
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
return new ProviderError(
|
|
137
|
+
error instanceof Error ? error.message : String(error),
|
|
138
|
+
provider,
|
|
139
|
+
void 0,
|
|
140
|
+
error
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
|
|
240
144
|
// src/shared/structured-output.ts
|
|
241
145
|
import {
|
|
242
146
|
StructuredOutputNoObjectGeneratedError,
|
|
@@ -395,10 +299,109 @@ function formatZodIssues(issues) {
|
|
|
395
299
|
});
|
|
396
300
|
}
|
|
397
301
|
|
|
302
|
+
// src/shared/provider-factory.ts
|
|
303
|
+
import OpenAI from "openai";
|
|
304
|
+
|
|
305
|
+
// src/embedding-model.ts
|
|
306
|
+
function createOpenAIEmbeddingModel(client, modelId) {
|
|
307
|
+
return {
|
|
308
|
+
provider: "openai",
|
|
309
|
+
modelId,
|
|
310
|
+
async embed(options) {
|
|
311
|
+
try {
|
|
312
|
+
const openaiOptions = parseOpenAIEmbedProviderOptions(
|
|
313
|
+
options.providerOptions
|
|
314
|
+
);
|
|
315
|
+
const response = await client.embeddings.create({
|
|
316
|
+
model: modelId,
|
|
317
|
+
input: options.input,
|
|
318
|
+
...options.dimensions !== void 0 ? { dimensions: options.dimensions } : {},
|
|
319
|
+
...mapOpenAIEmbedProviderOptionsToRequestFields(
|
|
320
|
+
openaiOptions
|
|
321
|
+
)
|
|
322
|
+
});
|
|
323
|
+
return {
|
|
324
|
+
embeddings: response.data.slice().sort((a, b) => a.index - b.index).map((item) => item.embedding),
|
|
325
|
+
usage: {
|
|
326
|
+
inputTokens: response.usage.prompt_tokens
|
|
327
|
+
}
|
|
328
|
+
};
|
|
329
|
+
} catch (error) {
|
|
330
|
+
throw wrapOpenAIError(error);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
function mapOpenAIEmbedProviderOptionsToRequestFields(options) {
|
|
336
|
+
return {
|
|
337
|
+
...options?.encodingFormat !== void 0 ? { encoding_format: options.encodingFormat } : {},
|
|
338
|
+
...options?.user !== void 0 ? { user: options.user } : {}
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// src/image-model.ts
|
|
343
|
+
function createOpenAIImageModel(client, modelId) {
|
|
344
|
+
return {
|
|
345
|
+
provider: "openai",
|
|
346
|
+
modelId,
|
|
347
|
+
async generate(options) {
|
|
348
|
+
try {
|
|
349
|
+
const openaiOptions = parseOpenAIImageProviderOptions(
|
|
350
|
+
options.providerOptions
|
|
351
|
+
);
|
|
352
|
+
const request = {
|
|
353
|
+
model: modelId,
|
|
354
|
+
prompt: options.prompt,
|
|
355
|
+
...options.n !== void 0 ? { n: options.n } : {},
|
|
356
|
+
...options.size !== void 0 ? { size: options.size } : {},
|
|
357
|
+
...mapOpenAIImageProviderOptionsToRequestFields(
|
|
358
|
+
openaiOptions
|
|
359
|
+
)
|
|
360
|
+
};
|
|
361
|
+
const response = await client.images.generate(
|
|
362
|
+
request
|
|
363
|
+
);
|
|
364
|
+
return {
|
|
365
|
+
images: (response.data ?? []).map((image) => ({
|
|
366
|
+
base64: image.b64_json ?? void 0,
|
|
367
|
+
url: image.url ?? void 0,
|
|
368
|
+
revisedPrompt: image.revised_prompt ?? void 0
|
|
369
|
+
}))
|
|
370
|
+
};
|
|
371
|
+
} catch (error) {
|
|
372
|
+
throw wrapOpenAIError(error);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
function mapOpenAIImageProviderOptionsToRequestFields(options) {
|
|
378
|
+
return {
|
|
379
|
+
...options?.background !== void 0 ? { background: options.background } : {},
|
|
380
|
+
...options?.moderation !== void 0 ? { moderation: options.moderation } : {},
|
|
381
|
+
...options?.outputCompression !== void 0 ? { output_compression: options.outputCompression } : {},
|
|
382
|
+
...options?.outputFormat !== void 0 ? { output_format: options.outputFormat } : {},
|
|
383
|
+
...options?.quality !== void 0 ? { quality: options.quality } : {},
|
|
384
|
+
...options?.responseFormat !== void 0 ? { response_format: options.responseFormat } : {},
|
|
385
|
+
...options?.style !== void 0 ? { style: options.style } : {},
|
|
386
|
+
...options?.user !== void 0 ? { user: options.user } : {}
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
// src/shared/provider-factory.ts
|
|
391
|
+
function createOpenAIProvider(options, createChatModel) {
|
|
392
|
+
const client = options.client ?? new OpenAI({
|
|
393
|
+
apiKey: options.apiKey,
|
|
394
|
+
baseURL: options.baseURL
|
|
395
|
+
});
|
|
396
|
+
return {
|
|
397
|
+
chatModel: (modelId) => createChatModel(client, modelId),
|
|
398
|
+
embeddingModel: (modelId) => createOpenAIEmbeddingModel(client, modelId),
|
|
399
|
+
imageModel: (modelId) => createOpenAIImageModel(client, modelId)
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
|
|
398
403
|
// src/model-capabilities.ts
|
|
399
|
-
import {
|
|
400
|
-
stripModelDateSuffix
|
|
401
|
-
} from "@core-ai/core-ai";
|
|
404
|
+
import { stripModelDateSuffix } from "@core-ai/core-ai";
|
|
402
405
|
var DEFAULT_CAPABILITIES = {
|
|
403
406
|
reasoning: {
|
|
404
407
|
supportsEffort: true,
|
|
@@ -420,6 +423,20 @@ var GPT_5_MINIMAL_REASONING_CAPABILITIES = {
|
|
|
420
423
|
restrictsSamplingParams: true
|
|
421
424
|
}
|
|
422
425
|
};
|
|
426
|
+
var GPT_5_PRO_REASONING_CAPABILITIES = {
|
|
427
|
+
reasoning: {
|
|
428
|
+
supportsEffort: true,
|
|
429
|
+
supportedRange: ["medium", "high", "max"],
|
|
430
|
+
restrictsSamplingParams: true
|
|
431
|
+
}
|
|
432
|
+
};
|
|
433
|
+
var GPT_5_HIGH_REASONING_CAPABILITIES = {
|
|
434
|
+
reasoning: {
|
|
435
|
+
supportsEffort: true,
|
|
436
|
+
supportedRange: ["high"],
|
|
437
|
+
restrictsSamplingParams: true
|
|
438
|
+
}
|
|
439
|
+
};
|
|
423
440
|
var NO_REASONING_EFFORT_CAPABILITIES = {
|
|
424
441
|
reasoning: {
|
|
425
442
|
supportsEffort: false,
|
|
@@ -427,12 +444,27 @@ var NO_REASONING_EFFORT_CAPABILITIES = {
|
|
|
427
444
|
restrictsSamplingParams: false
|
|
428
445
|
}
|
|
429
446
|
};
|
|
447
|
+
var O_SERIES_MAX_REASONING_CAPABILITIES = {
|
|
448
|
+
reasoning: {
|
|
449
|
+
supportsEffort: true,
|
|
450
|
+
supportedRange: ["low", "medium", "high", "max"],
|
|
451
|
+
restrictsSamplingParams: false
|
|
452
|
+
}
|
|
453
|
+
};
|
|
430
454
|
var MODEL_CAPABILITIES = {
|
|
455
|
+
"gpt-5.5": GPT_5_MAX_REASONING_CAPABILITIES,
|
|
456
|
+
"gpt-5.5-pro": GPT_5_PRO_REASONING_CAPABILITIES,
|
|
431
457
|
"gpt-5.4": GPT_5_MAX_REASONING_CAPABILITIES,
|
|
432
|
-
"gpt-5.4-pro":
|
|
458
|
+
"gpt-5.4-pro": GPT_5_PRO_REASONING_CAPABILITIES,
|
|
459
|
+
"gpt-5.4-mini": GPT_5_MAX_REASONING_CAPABILITIES,
|
|
460
|
+
"gpt-5.4-nano": GPT_5_MAX_REASONING_CAPABILITIES,
|
|
461
|
+
"gpt-5.3-codex": GPT_5_MAX_REASONING_CAPABILITIES,
|
|
433
462
|
"gpt-5.2": GPT_5_MAX_REASONING_CAPABILITIES,
|
|
434
463
|
"gpt-5.2-codex": GPT_5_MAX_REASONING_CAPABILITIES,
|
|
435
464
|
"gpt-5.2-pro": GPT_5_MAX_REASONING_CAPABILITIES,
|
|
465
|
+
"gpt-5.1-codex": GPT_5_MAX_REASONING_CAPABILITIES,
|
|
466
|
+
"gpt-5.1-codex-max": GPT_5_MAX_REASONING_CAPABILITIES,
|
|
467
|
+
"gpt-5.1-codex-mini": GPT_5_MAX_REASONING_CAPABILITIES,
|
|
436
468
|
"gpt-5.1": {
|
|
437
469
|
reasoning: {
|
|
438
470
|
supportsEffort: true,
|
|
@@ -443,6 +475,9 @@ var MODEL_CAPABILITIES = {
|
|
|
443
475
|
"gpt-5": GPT_5_MINIMAL_REASONING_CAPABILITIES,
|
|
444
476
|
"gpt-5-mini": GPT_5_MINIMAL_REASONING_CAPABILITIES,
|
|
445
477
|
"gpt-5-nano": GPT_5_MINIMAL_REASONING_CAPABILITIES,
|
|
478
|
+
"gpt-5-pro": GPT_5_HIGH_REASONING_CAPABILITIES,
|
|
479
|
+
"gpt-5-codex": GPT_5_MAX_REASONING_CAPABILITIES,
|
|
480
|
+
"o3-pro": O_SERIES_MAX_REASONING_CAPABILITIES,
|
|
446
481
|
o3: {
|
|
447
482
|
reasoning: {
|
|
448
483
|
supportsEffort: true,
|
package/dist/compat.d.ts
CHANGED
|
@@ -1,11 +1,29 @@
|
|
|
1
|
+
import { ChatModel } from '@core-ai/core-ai';
|
|
2
|
+
import OpenAI from 'openai';
|
|
1
3
|
import { O as OpenAIProvider, a as OpenAIProviderBaseOptions } from './provider-options-DzqvHoId.js';
|
|
2
4
|
export { b as OpenAICompatGenerateProviderOptions, c as OpenAICompatRequestOptions, o as openaiCompatGenerateProviderOptionsSchema, d as openaiCompatProviderOptionsSchema } from './provider-options-DzqvHoId.js';
|
|
3
|
-
import 'openai';
|
|
4
|
-
import '@core-ai/core-ai';
|
|
5
5
|
import 'zod';
|
|
6
6
|
|
|
7
|
+
type OpenAIChatClient = {
|
|
8
|
+
chat: OpenAI['chat'];
|
|
9
|
+
};
|
|
10
|
+
declare function createOpenAICompatChatModel(client: OpenAIChatClient, modelId: string, providerId?: string): ChatModel;
|
|
11
|
+
|
|
7
12
|
type OpenAICompatProviderOptions = OpenAIProviderBaseOptions;
|
|
8
13
|
type OpenAICompatProvider = OpenAIProvider;
|
|
9
14
|
declare function createOpenAICompat(options?: OpenAICompatProviderOptions): OpenAICompatProvider;
|
|
15
|
+
type OpenAICompatChatProviderOptions = {
|
|
16
|
+
apiKey?: string;
|
|
17
|
+
baseURL?: string;
|
|
18
|
+
client?: OpenAIChatClient;
|
|
19
|
+
};
|
|
20
|
+
type OpenAICompatChatProvider = {
|
|
21
|
+
chatModel(modelId: string): ChatModel;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Creates a chat-only OpenAI-compatible provider. Handles client construction
|
|
25
|
+
* internally so consumers do not need a direct dependency on the `openai` package.
|
|
26
|
+
*/
|
|
27
|
+
declare function createOpenAICompatChatProvider(options?: OpenAICompatChatProviderOptions, providerId?: string): OpenAICompatChatProvider;
|
|
10
28
|
|
|
11
|
-
export { type OpenAICompatProvider, type OpenAICompatProviderOptions, createOpenAICompat };
|
|
29
|
+
export { type OpenAIChatClient, type OpenAICompatChatProvider, type OpenAICompatChatProviderOptions, type OpenAICompatProvider, type OpenAICompatProviderOptions, createOpenAICompat, createOpenAICompatChatModel, createOpenAICompatChatProvider };
|
package/dist/compat.js
CHANGED
|
@@ -15,7 +15,10 @@ import {
|
|
|
15
15
|
transformStructuredOutputStream,
|
|
16
16
|
validateOpenAIReasoningConfig,
|
|
17
17
|
wrapOpenAIError
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-RPCZTXZS.js";
|
|
19
|
+
|
|
20
|
+
// src/compat/provider.ts
|
|
21
|
+
import OpenAI from "openai";
|
|
19
22
|
|
|
20
23
|
// src/compat/chat-model.ts
|
|
21
24
|
import { createObjectStream, createChatStream } from "@core-ai/core-ai";
|
|
@@ -369,15 +372,15 @@ function extractTextContent(content) {
|
|
|
369
372
|
}
|
|
370
373
|
|
|
371
374
|
// src/compat/chat-model.ts
|
|
372
|
-
function createOpenAICompatChatModel(client, modelId) {
|
|
373
|
-
const provider =
|
|
375
|
+
function createOpenAICompatChatModel(client, modelId, providerId = "openai") {
|
|
376
|
+
const provider = providerId;
|
|
374
377
|
async function callOpenAIChatCompletionsApi(request, signal) {
|
|
375
378
|
try {
|
|
376
379
|
return await client.chat.completions.create(request, {
|
|
377
380
|
signal
|
|
378
381
|
});
|
|
379
382
|
} catch (error) {
|
|
380
|
-
throw wrapOpenAIError(error);
|
|
383
|
+
throw wrapOpenAIError(error, provider);
|
|
381
384
|
}
|
|
382
385
|
}
|
|
383
386
|
async function generateChat(options) {
|
|
@@ -438,8 +441,19 @@ function createOpenAICompatChatModel(client, modelId) {
|
|
|
438
441
|
function createOpenAICompat(options = {}) {
|
|
439
442
|
return createOpenAIProvider(options, createOpenAICompatChatModel);
|
|
440
443
|
}
|
|
444
|
+
function createOpenAICompatChatProvider(options = {}, providerId = "openai") {
|
|
445
|
+
const client = options.client ?? new OpenAI({
|
|
446
|
+
apiKey: options.apiKey,
|
|
447
|
+
baseURL: options.baseURL
|
|
448
|
+
});
|
|
449
|
+
return {
|
|
450
|
+
chatModel: (modelId) => createOpenAICompatChatModel(client, modelId, providerId)
|
|
451
|
+
};
|
|
452
|
+
}
|
|
441
453
|
export {
|
|
442
454
|
createOpenAICompat,
|
|
455
|
+
createOpenAICompatChatModel,
|
|
456
|
+
createOpenAICompatChatProvider,
|
|
443
457
|
openaiCompatGenerateProviderOptionsSchema,
|
|
444
458
|
openaiCompatProviderOptionsSchema
|
|
445
459
|
};
|
package/dist/index.js
CHANGED
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
transformStructuredOutputStream,
|
|
20
20
|
validateOpenAIReasoningConfig,
|
|
21
21
|
wrapOpenAIError
|
|
22
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-RPCZTXZS.js";
|
|
23
23
|
|
|
24
24
|
// src/chat-model.ts
|
|
25
25
|
import { createObjectStream, createChatStream } from "@core-ai/core-ai";
|
|
@@ -27,6 +27,7 @@ import { createObjectStream, createChatStream } from "@core-ai/core-ai";
|
|
|
27
27
|
// src/chat-adapter.ts
|
|
28
28
|
import { getProviderMetadata } from "@core-ai/core-ai";
|
|
29
29
|
var ENCRYPTED_REASONING_INCLUDE = "reasoning.encrypted_content";
|
|
30
|
+
var REASONING_SUMMARY_SEPARATOR = "\n\n";
|
|
30
31
|
function convertMessages(messages) {
|
|
31
32
|
return messages.flatMap(convertMessage);
|
|
32
33
|
}
|
|
@@ -275,7 +276,7 @@ function mapReasoningPart(item) {
|
|
|
275
276
|
};
|
|
276
277
|
}
|
|
277
278
|
function getReasoningSummaryText(summary) {
|
|
278
|
-
return summary.map((item) => item.text).join(
|
|
279
|
+
return summary.map((item) => item.text).join(REASONING_SUMMARY_SEPARATOR);
|
|
279
280
|
}
|
|
280
281
|
function mapMessageTextParts(message) {
|
|
281
282
|
return message.content.flatMap(
|
|
@@ -283,15 +284,19 @@ function mapMessageTextParts(message) {
|
|
|
283
284
|
);
|
|
284
285
|
}
|
|
285
286
|
function getTextContent(parts) {
|
|
286
|
-
return getJoinedPartText(parts, "text");
|
|
287
|
+
return getJoinedPartText(parts, "text", "");
|
|
287
288
|
}
|
|
288
289
|
function getReasoningText(parts) {
|
|
289
|
-
return getJoinedPartText(
|
|
290
|
+
return getJoinedPartText(
|
|
291
|
+
parts,
|
|
292
|
+
"reasoning",
|
|
293
|
+
REASONING_SUMMARY_SEPARATOR
|
|
294
|
+
);
|
|
290
295
|
}
|
|
291
|
-
function getJoinedPartText(parts, type) {
|
|
296
|
+
function getJoinedPartText(parts, type, separator) {
|
|
292
297
|
const text = parts.flatMap(
|
|
293
298
|
(part) => part.type === type && "text" in part ? [part.text] : []
|
|
294
|
-
).join(
|
|
299
|
+
).join(separator);
|
|
295
300
|
return text.length > 0 ? text : null;
|
|
296
301
|
}
|
|
297
302
|
function getToolCalls(parts) {
|
|
@@ -329,6 +334,12 @@ function mapUsage(usage) {
|
|
|
329
334
|
}
|
|
330
335
|
};
|
|
331
336
|
}
|
|
337
|
+
function getReasoningSummaryKey(part) {
|
|
338
|
+
return `${part.itemId}:${part.summaryIndex}`;
|
|
339
|
+
}
|
|
340
|
+
function isSameReasoningSummaryPart(left, right) {
|
|
341
|
+
return left.itemId === right.itemId && left.summaryIndex === right.summaryIndex;
|
|
342
|
+
}
|
|
332
343
|
function getReasoningStartTransition(reasoningStarted) {
|
|
333
344
|
if (reasoningStarted) {
|
|
334
345
|
return {
|
|
@@ -364,6 +375,7 @@ async function* transformStream(stream) {
|
|
|
364
375
|
const emittedReasoningItems = /* @__PURE__ */ new Set();
|
|
365
376
|
let latestResponse;
|
|
366
377
|
let reasoningStarted = false;
|
|
378
|
+
let latestReasoningSummaryPart;
|
|
367
379
|
const upsertBufferedToolCall = (outputIndex, getNextToolCall) => {
|
|
368
380
|
const nextToolCall = getNextToolCall(bufferedToolCalls.get(outputIndex));
|
|
369
381
|
bufferedToolCalls.set(outputIndex, nextToolCall);
|
|
@@ -380,16 +392,38 @@ async function* transformStream(stream) {
|
|
|
380
392
|
providerMetadata
|
|
381
393
|
);
|
|
382
394
|
reasoningStarted = transition.nextReasoningStarted;
|
|
395
|
+
if (transition.event) {
|
|
396
|
+
latestReasoningSummaryPart = void 0;
|
|
397
|
+
}
|
|
383
398
|
return transition.event;
|
|
384
399
|
};
|
|
400
|
+
const getReasoningSummarySeparatorEvent = (currentPart) => {
|
|
401
|
+
const previousPart = latestReasoningSummaryPart;
|
|
402
|
+
latestReasoningSummaryPart = currentPart;
|
|
403
|
+
if (previousPart === void 0 || isSameReasoningSummaryPart(previousPart, currentPart)) {
|
|
404
|
+
return null;
|
|
405
|
+
}
|
|
406
|
+
return {
|
|
407
|
+
type: "reasoning-delta",
|
|
408
|
+
text: REASONING_SUMMARY_SEPARATOR
|
|
409
|
+
};
|
|
410
|
+
};
|
|
385
411
|
for await (const event of stream) {
|
|
386
412
|
if (event.type === "response.reasoning_summary_text.delta") {
|
|
387
|
-
|
|
413
|
+
const summaryPart = {
|
|
414
|
+
itemId: event.item_id,
|
|
415
|
+
summaryIndex: event.summary_index
|
|
416
|
+
};
|
|
417
|
+
seenSummaryDeltas.add(getReasoningSummaryKey(summaryPart));
|
|
388
418
|
emittedReasoningItems.add(event.item_id);
|
|
389
419
|
const reasoningStartEvent = getNextReasoningStartEvent();
|
|
390
420
|
if (reasoningStartEvent) {
|
|
391
421
|
yield reasoningStartEvent;
|
|
392
422
|
}
|
|
423
|
+
const separatorEvent = getReasoningSummarySeparatorEvent(summaryPart);
|
|
424
|
+
if (separatorEvent) {
|
|
425
|
+
yield separatorEvent;
|
|
426
|
+
}
|
|
393
427
|
yield {
|
|
394
428
|
type: "reasoning-delta",
|
|
395
429
|
text: event.delta
|
|
@@ -397,13 +431,21 @@ async function* transformStream(stream) {
|
|
|
397
431
|
continue;
|
|
398
432
|
}
|
|
399
433
|
if (event.type === "response.reasoning_summary_text.done") {
|
|
400
|
-
const
|
|
434
|
+
const summaryPart = {
|
|
435
|
+
itemId: event.item_id,
|
|
436
|
+
summaryIndex: event.summary_index
|
|
437
|
+
};
|
|
438
|
+
const key = getReasoningSummaryKey(summaryPart);
|
|
401
439
|
if (!seenSummaryDeltas.has(key) && event.text.length > 0) {
|
|
402
440
|
emittedReasoningItems.add(event.item_id);
|
|
403
441
|
const reasoningStartEvent = getNextReasoningStartEvent();
|
|
404
442
|
if (reasoningStartEvent) {
|
|
405
443
|
yield reasoningStartEvent;
|
|
406
444
|
}
|
|
445
|
+
const separatorEvent = getReasoningSummarySeparatorEvent(summaryPart);
|
|
446
|
+
if (separatorEvent) {
|
|
447
|
+
yield separatorEvent;
|
|
448
|
+
}
|
|
407
449
|
yield {
|
|
408
450
|
type: "reasoning-delta",
|
|
409
451
|
text: event.text
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@core-ai/openai",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "OpenAI provider package for @core-ai/core-ai",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Omnifact (https://omnifact.ai)",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"test:watch": "vitest"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@core-ai/core-ai": "^0.
|
|
49
|
+
"@core-ai/core-ai": "^0.11.0",
|
|
50
50
|
"openai": "^6.1.0"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|