@core-ai/openai 0.6.0 → 0.6.1
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-7CU5JW63.js → chunk-ZHHJ76M7.js} +14 -0
- package/dist/compat.js +1 -1
- package/dist/index.js +117 -64
- package/package.json +2 -2
|
@@ -221,6 +221,20 @@ var DEFAULT_CAPABILITIES = {
|
|
|
221
221
|
}
|
|
222
222
|
};
|
|
223
223
|
var MODEL_CAPABILITIES = {
|
|
224
|
+
"gpt-5.4": {
|
|
225
|
+
reasoning: {
|
|
226
|
+
supportsEffort: true,
|
|
227
|
+
supportedRange: ["low", "medium", "high", "max"],
|
|
228
|
+
restrictsSamplingParams: true
|
|
229
|
+
}
|
|
230
|
+
},
|
|
231
|
+
"gpt-5.4-pro": {
|
|
232
|
+
reasoning: {
|
|
233
|
+
supportsEffort: true,
|
|
234
|
+
supportedRange: ["low", "medium", "high", "max"],
|
|
235
|
+
restrictsSamplingParams: true
|
|
236
|
+
}
|
|
237
|
+
},
|
|
224
238
|
"gpt-5.2": {
|
|
225
239
|
reasoning: {
|
|
226
240
|
supportsEffort: true,
|
package/dist/compat.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
toOpenAIReasoningEffort,
|
|
19
19
|
validateOpenAIReasoningConfig,
|
|
20
20
|
wrapOpenAIError
|
|
21
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-ZHHJ76M7.js";
|
|
22
22
|
|
|
23
23
|
// src/provider.ts
|
|
24
24
|
import OpenAI from "openai";
|
|
@@ -242,9 +242,7 @@ function mapGenerateResponse(response) {
|
|
|
242
242
|
continue;
|
|
243
243
|
}
|
|
244
244
|
if (isOutputMessage(item)) {
|
|
245
|
-
|
|
246
|
-
parts.push(part);
|
|
247
|
-
}
|
|
245
|
+
parts.push(...mapMessageTextParts(item));
|
|
248
246
|
continue;
|
|
249
247
|
}
|
|
250
248
|
if (isFunctionToolCall(item)) {
|
|
@@ -293,12 +291,16 @@ function mapMessageTextParts(message) {
|
|
|
293
291
|
);
|
|
294
292
|
}
|
|
295
293
|
function getTextContent(parts) {
|
|
296
|
-
|
|
297
|
-
return text.length > 0 ? text : null;
|
|
294
|
+
return getJoinedPartText(parts, "text");
|
|
298
295
|
}
|
|
299
296
|
function getReasoningText(parts) {
|
|
300
|
-
|
|
301
|
-
|
|
297
|
+
return getJoinedPartText(parts, "reasoning");
|
|
298
|
+
}
|
|
299
|
+
function getJoinedPartText(parts, type) {
|
|
300
|
+
const text = parts.flatMap(
|
|
301
|
+
(part) => part.type === type && "text" in part ? [part.text] : []
|
|
302
|
+
).join("");
|
|
303
|
+
return text.length > 0 ? text : null;
|
|
302
304
|
}
|
|
303
305
|
function getToolCalls(parts) {
|
|
304
306
|
return parts.flatMap(
|
|
@@ -335,6 +337,33 @@ function mapUsage(usage) {
|
|
|
335
337
|
}
|
|
336
338
|
};
|
|
337
339
|
}
|
|
340
|
+
function getReasoningStartTransition(reasoningStarted) {
|
|
341
|
+
if (reasoningStarted) {
|
|
342
|
+
return {
|
|
343
|
+
nextReasoningStarted: true,
|
|
344
|
+
event: null
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
return {
|
|
348
|
+
nextReasoningStarted: true,
|
|
349
|
+
event: { type: "reasoning-start" }
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
function getReasoningEndTransition(reasoningStarted, providerMetadata) {
|
|
353
|
+
if (!reasoningStarted) {
|
|
354
|
+
return {
|
|
355
|
+
nextReasoningStarted: false,
|
|
356
|
+
event: null
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
return {
|
|
360
|
+
nextReasoningStarted: false,
|
|
361
|
+
event: {
|
|
362
|
+
type: "reasoning-end",
|
|
363
|
+
providerMetadata
|
|
364
|
+
}
|
|
365
|
+
};
|
|
366
|
+
}
|
|
338
367
|
async function* transformStream(stream) {
|
|
339
368
|
const bufferedToolCalls = /* @__PURE__ */ new Map();
|
|
340
369
|
const emittedToolCalls = /* @__PURE__ */ new Set();
|
|
@@ -343,13 +372,19 @@ async function* transformStream(stream) {
|
|
|
343
372
|
const emittedReasoningItems = /* @__PURE__ */ new Set();
|
|
344
373
|
let latestResponse;
|
|
345
374
|
let reasoningStarted = false;
|
|
375
|
+
const upsertBufferedToolCall = (outputIndex, getNextToolCall) => {
|
|
376
|
+
const nextToolCall = getNextToolCall(bufferedToolCalls.get(outputIndex));
|
|
377
|
+
bufferedToolCalls.set(outputIndex, nextToolCall);
|
|
378
|
+
return nextToolCall;
|
|
379
|
+
};
|
|
346
380
|
for await (const event of stream) {
|
|
347
381
|
if (event.type === "response.reasoning_summary_text.delta") {
|
|
348
382
|
seenSummaryDeltas.add(`${event.item_id}:${event.summary_index}`);
|
|
349
383
|
emittedReasoningItems.add(event.item_id);
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
384
|
+
const reasoningStartTransition = getReasoningStartTransition(reasoningStarted);
|
|
385
|
+
reasoningStarted = reasoningStartTransition.nextReasoningStarted;
|
|
386
|
+
if (reasoningStartTransition.event) {
|
|
387
|
+
yield reasoningStartTransition.event;
|
|
353
388
|
}
|
|
354
389
|
yield {
|
|
355
390
|
type: "reasoning-delta",
|
|
@@ -361,9 +396,10 @@ async function* transformStream(stream) {
|
|
|
361
396
|
const key = `${event.item_id}:${event.summary_index}`;
|
|
362
397
|
if (!seenSummaryDeltas.has(key) && event.text.length > 0) {
|
|
363
398
|
emittedReasoningItems.add(event.item_id);
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
399
|
+
const reasoningStartTransition = getReasoningStartTransition(reasoningStarted);
|
|
400
|
+
reasoningStarted = reasoningStartTransition.nextReasoningStarted;
|
|
401
|
+
if (reasoningStartTransition.event) {
|
|
402
|
+
yield reasoningStartTransition.event;
|
|
367
403
|
}
|
|
368
404
|
yield {
|
|
369
405
|
type: "reasoning-delta",
|
|
@@ -384,32 +420,38 @@ async function* transformStream(stream) {
|
|
|
384
420
|
continue;
|
|
385
421
|
}
|
|
386
422
|
const toolCallId = event.item.call_id;
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
423
|
+
const toolCallName = event.item.name;
|
|
424
|
+
const toolCallArguments = event.item.arguments;
|
|
425
|
+
upsertBufferedToolCall(
|
|
426
|
+
event.output_index,
|
|
427
|
+
() => ({
|
|
428
|
+
id: toolCallId,
|
|
429
|
+
name: toolCallName,
|
|
430
|
+
arguments: toolCallArguments
|
|
431
|
+
})
|
|
432
|
+
);
|
|
433
|
+
const shouldStartToolCall = !startedToolCalls.has(toolCallId);
|
|
434
|
+
if (shouldStartToolCall) {
|
|
393
435
|
startedToolCalls.add(toolCallId);
|
|
394
436
|
yield {
|
|
395
437
|
type: "tool-call-start",
|
|
396
438
|
toolCallId,
|
|
397
|
-
toolName:
|
|
439
|
+
toolName: toolCallName
|
|
398
440
|
};
|
|
399
441
|
}
|
|
400
442
|
continue;
|
|
401
443
|
}
|
|
402
444
|
if (event.type === "response.function_call_arguments.delta") {
|
|
403
|
-
const currentToolCall =
|
|
404
|
-
event.output_index
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
if (
|
|
445
|
+
const currentToolCall = upsertBufferedToolCall(
|
|
446
|
+
event.output_index,
|
|
447
|
+
(bufferedToolCall) => ({
|
|
448
|
+
id: bufferedToolCall?.id ?? event.item_id,
|
|
449
|
+
name: bufferedToolCall?.name ?? "",
|
|
450
|
+
arguments: `${bufferedToolCall?.arguments ?? ""}${event.delta}`
|
|
451
|
+
})
|
|
452
|
+
);
|
|
453
|
+
const shouldStartToolCall = !startedToolCalls.has(currentToolCall.id);
|
|
454
|
+
if (shouldStartToolCall) {
|
|
413
455
|
startedToolCalls.add(currentToolCall.id);
|
|
414
456
|
yield {
|
|
415
457
|
type: "tool-call-start",
|
|
@@ -431,9 +473,10 @@ async function* transformStream(stream) {
|
|
|
431
473
|
event.item.summary
|
|
432
474
|
);
|
|
433
475
|
if (summaryText.length > 0) {
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
476
|
+
const reasoningStartTransition = getReasoningStartTransition(reasoningStarted);
|
|
477
|
+
reasoningStarted = reasoningStartTransition.nextReasoningStarted;
|
|
478
|
+
if (reasoningStartTransition.event) {
|
|
479
|
+
yield reasoningStartTransition.event;
|
|
437
480
|
}
|
|
438
481
|
yield {
|
|
439
482
|
type: "reasoning-delta",
|
|
@@ -442,36 +485,41 @@ async function* transformStream(stream) {
|
|
|
442
485
|
}
|
|
443
486
|
}
|
|
444
487
|
const encryptedContent = typeof event.item.encrypted_content === "string" && event.item.encrypted_content.length > 0 ? event.item.encrypted_content : void 0;
|
|
445
|
-
if (
|
|
446
|
-
|
|
447
|
-
|
|
488
|
+
if (encryptedContent) {
|
|
489
|
+
const reasoningStartTransition = getReasoningStartTransition(reasoningStarted);
|
|
490
|
+
reasoningStarted = reasoningStartTransition.nextReasoningStarted;
|
|
491
|
+
if (reasoningStartTransition.event) {
|
|
492
|
+
yield reasoningStartTransition.event;
|
|
493
|
+
}
|
|
448
494
|
}
|
|
449
|
-
|
|
450
|
-
reasoningStarted
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
openai: {
|
|
455
|
-
...encryptedContent ? { encryptedContent } : {}
|
|
456
|
-
}
|
|
495
|
+
const reasoningEndTransition2 = getReasoningEndTransition(
|
|
496
|
+
reasoningStarted,
|
|
497
|
+
{
|
|
498
|
+
openai: {
|
|
499
|
+
...encryptedContent ? { encryptedContent } : {}
|
|
457
500
|
}
|
|
458
|
-
}
|
|
501
|
+
}
|
|
502
|
+
);
|
|
503
|
+
reasoningStarted = reasoningEndTransition2.nextReasoningStarted;
|
|
504
|
+
if (reasoningEndTransition2.event) {
|
|
505
|
+
yield reasoningEndTransition2.event;
|
|
459
506
|
}
|
|
460
507
|
continue;
|
|
461
508
|
}
|
|
462
509
|
if (!isFunctionToolCall(event.item)) {
|
|
463
510
|
continue;
|
|
464
511
|
}
|
|
465
|
-
const
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
512
|
+
const toolCallId = event.item.call_id;
|
|
513
|
+
const toolCallName = event.item.name;
|
|
514
|
+
const toolCallArguments = event.item.arguments;
|
|
515
|
+
const currentToolCall = upsertBufferedToolCall(
|
|
516
|
+
event.output_index,
|
|
517
|
+
(bufferedToolCall) => ({
|
|
518
|
+
id: toolCallId,
|
|
519
|
+
name: toolCallName,
|
|
520
|
+
arguments: toolCallArguments || bufferedToolCall?.arguments || ""
|
|
521
|
+
})
|
|
522
|
+
);
|
|
475
523
|
if (!emittedToolCalls.has(currentToolCall.id)) {
|
|
476
524
|
emittedToolCalls.add(currentToolCall.id);
|
|
477
525
|
yield {
|
|
@@ -489,12 +537,13 @@ async function* transformStream(stream) {
|
|
|
489
537
|
}
|
|
490
538
|
if (event.type === "response.completed") {
|
|
491
539
|
latestResponse = event.response;
|
|
492
|
-
|
|
493
|
-
reasoningStarted
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
540
|
+
const reasoningEndTransition2 = getReasoningEndTransition(
|
|
541
|
+
reasoningStarted,
|
|
542
|
+
{ openai: {} }
|
|
543
|
+
);
|
|
544
|
+
reasoningStarted = reasoningEndTransition2.nextReasoningStarted;
|
|
545
|
+
if (reasoningEndTransition2.event) {
|
|
546
|
+
yield reasoningEndTransition2.event;
|
|
498
547
|
}
|
|
499
548
|
for (const bufferedToolCall of bufferedToolCalls.values()) {
|
|
500
549
|
if (emittedToolCalls.has(bufferedToolCall.id)) {
|
|
@@ -521,8 +570,12 @@ async function* transformStream(stream) {
|
|
|
521
570
|
return;
|
|
522
571
|
}
|
|
523
572
|
}
|
|
524
|
-
|
|
525
|
-
|
|
573
|
+
const reasoningEndTransition = getReasoningEndTransition(reasoningStarted, {
|
|
574
|
+
openai: {}
|
|
575
|
+
});
|
|
576
|
+
reasoningStarted = reasoningEndTransition.nextReasoningStarted;
|
|
577
|
+
if (reasoningEndTransition.event) {
|
|
578
|
+
yield reasoningEndTransition.event;
|
|
526
579
|
}
|
|
527
580
|
const hasToolCalls = bufferedToolCalls.size > 0;
|
|
528
581
|
const usage = latestResponse ? mapUsage(latestResponse.usage) : mapUsage(void 0);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@core-ai/openai",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.1",
|
|
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.6.
|
|
49
|
+
"@core-ai/core-ai": "^0.6.1",
|
|
50
50
|
"openai": "^6.1.0",
|
|
51
51
|
"zod-to-json-schema": "^3.25.1"
|
|
52
52
|
},
|