@kenkaiiii/gg-ai 4.3.215 → 4.3.217
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.cjs +39 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +39 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1521,6 +1521,9 @@ function parseToolArguments2(argsJson) {
|
|
|
1521
1521
|
function outputTextKey(itemId, contentIndex) {
|
|
1522
1522
|
return `${itemId ?? ""}:${contentIndex ?? 0}`;
|
|
1523
1523
|
}
|
|
1524
|
+
function isVisibleOutputItem(itemType) {
|
|
1525
|
+
return itemType === "message";
|
|
1526
|
+
}
|
|
1524
1527
|
function streamOpenAICodex(options) {
|
|
1525
1528
|
return new StreamResult(runStream3(options));
|
|
1526
1529
|
}
|
|
@@ -1604,6 +1607,7 @@ async function* runStream3(options) {
|
|
|
1604
1607
|
const toolCalls = /* @__PURE__ */ new Map();
|
|
1605
1608
|
const outputItemTypes = /* @__PURE__ */ new Map();
|
|
1606
1609
|
const outputTextByPart = /* @__PURE__ */ new Map();
|
|
1610
|
+
const pendingOutputTextByPart = /* @__PURE__ */ new Map();
|
|
1607
1611
|
let inputTokens = 0;
|
|
1608
1612
|
let outputTokens = 0;
|
|
1609
1613
|
let cacheRead = 0;
|
|
@@ -1640,11 +1644,19 @@ async function* runStream3(options) {
|
|
|
1640
1644
|
const contentIndex = event.content_index;
|
|
1641
1645
|
const key = outputTextKey(itemId, contentIndex);
|
|
1642
1646
|
outputTextByPart.set(key, `${outputTextByPart.get(key) ?? ""}${delta}`);
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
} else {
|
|
1647
|
+
const itemType = itemId ? outputItemTypes.get(itemId) : void 0;
|
|
1648
|
+
if (itemId && isVisibleOutputItem(itemType)) {
|
|
1646
1649
|
textAccum += delta;
|
|
1647
1650
|
yield { type: "text_delta", text: delta };
|
|
1651
|
+
} else if (itemId && itemType == null) {
|
|
1652
|
+
const pending = pendingOutputTextByPart.get(key);
|
|
1653
|
+
pendingOutputTextByPart.set(key, {
|
|
1654
|
+
itemId,
|
|
1655
|
+
contentIndex: contentIndex ?? 0,
|
|
1656
|
+
text: `${pending?.text ?? ""}${delta}`
|
|
1657
|
+
});
|
|
1658
|
+
} else if (options.thinking) {
|
|
1659
|
+
yield { type: "thinking_delta", text: delta };
|
|
1648
1660
|
}
|
|
1649
1661
|
}
|
|
1650
1662
|
if (type === "response.output_text.done") {
|
|
@@ -1657,11 +1669,19 @@ async function* runStream3(options) {
|
|
|
1657
1669
|
const missingText = streamedText ? fullText.slice(streamedText.length) : fullText;
|
|
1658
1670
|
outputTextByPart.set(key, fullText);
|
|
1659
1671
|
if (missingText && fullText.startsWith(streamedText)) {
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
} else {
|
|
1672
|
+
const itemType = itemId ? outputItemTypes.get(itemId) : void 0;
|
|
1673
|
+
if (itemId && isVisibleOutputItem(itemType)) {
|
|
1663
1674
|
textAccum += missingText;
|
|
1664
1675
|
yield { type: "text_delta", text: missingText };
|
|
1676
|
+
} else if (itemId && itemType == null) {
|
|
1677
|
+
const pending = pendingOutputTextByPart.get(key);
|
|
1678
|
+
pendingOutputTextByPart.set(key, {
|
|
1679
|
+
itemId,
|
|
1680
|
+
contentIndex: contentIndex ?? 0,
|
|
1681
|
+
text: `${pending?.text ?? ""}${missingText}`
|
|
1682
|
+
});
|
|
1683
|
+
} else if (options.thinking) {
|
|
1684
|
+
yield { type: "thinking_delta", text: missingText };
|
|
1665
1685
|
}
|
|
1666
1686
|
}
|
|
1667
1687
|
}
|
|
@@ -1680,6 +1700,19 @@ async function* runStream3(options) {
|
|
|
1680
1700
|
if (itemType === "reasoning" && options.thinking) {
|
|
1681
1701
|
yield { type: "thinking_delta", text: "" };
|
|
1682
1702
|
}
|
|
1703
|
+
if (itemId && itemType) {
|
|
1704
|
+
const pending = [...pendingOutputTextByPart.entries()].filter(([, pendingPart]) => pendingPart.itemId === itemId).sort(([, a], [, b]) => a.contentIndex - b.contentIndex);
|
|
1705
|
+
for (const [key, pendingPart] of pending) {
|
|
1706
|
+
pendingOutputTextByPart.delete(key);
|
|
1707
|
+
if (!pendingPart.text) continue;
|
|
1708
|
+
if (isVisibleOutputItem(itemType)) {
|
|
1709
|
+
textAccum += pendingPart.text;
|
|
1710
|
+
yield { type: "text_delta", text: pendingPart.text };
|
|
1711
|
+
} else if (options.thinking) {
|
|
1712
|
+
yield { type: "thinking_delta", text: pendingPart.text };
|
|
1713
|
+
}
|
|
1714
|
+
}
|
|
1715
|
+
}
|
|
1683
1716
|
}
|
|
1684
1717
|
if (type === "response.output_item.added") {
|
|
1685
1718
|
const item = event.item;
|