@core-ai/openai 0.10.1 → 0.10.3
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/index.js +49 -7
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -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.10.
|
|
3
|
+
"version": "0.10.3",
|
|
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.10.
|
|
49
|
+
"@core-ai/core-ai": "^0.10.3",
|
|
50
50
|
"openai": "^6.1.0"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|