@kenkaiiii/gg-ai 4.3.188 → 4.3.191
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 +41 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +41 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1547,6 +1547,9 @@ function parseToolArguments2(argsJson) {
|
|
|
1547
1547
|
return {};
|
|
1548
1548
|
}
|
|
1549
1549
|
}
|
|
1550
|
+
function outputTextKey(itemId, contentIndex) {
|
|
1551
|
+
return `${itemId ?? ""}:${contentIndex ?? 0}`;
|
|
1552
|
+
}
|
|
1550
1553
|
function streamOpenAICodex(options) {
|
|
1551
1554
|
return new StreamResult(runStream3(options));
|
|
1552
1555
|
}
|
|
@@ -1630,6 +1633,8 @@ async function* runStream3(options) {
|
|
|
1630
1633
|
const contentParts = [];
|
|
1631
1634
|
let textAccum = "";
|
|
1632
1635
|
const toolCalls = /* @__PURE__ */ new Map();
|
|
1636
|
+
const outputItemTypes = /* @__PURE__ */ new Map();
|
|
1637
|
+
const outputTextByPart = /* @__PURE__ */ new Map();
|
|
1633
1638
|
let inputTokens = 0;
|
|
1634
1639
|
let outputTokens = 0;
|
|
1635
1640
|
let cacheRead = 0;
|
|
@@ -1662,16 +1667,48 @@ async function* runStream3(options) {
|
|
|
1662
1667
|
}
|
|
1663
1668
|
if (type === "response.output_text.delta") {
|
|
1664
1669
|
const delta = event.delta;
|
|
1665
|
-
|
|
1666
|
-
|
|
1670
|
+
const itemId = event.item_id;
|
|
1671
|
+
const contentIndex = event.content_index;
|
|
1672
|
+
const key = outputTextKey(itemId, contentIndex);
|
|
1673
|
+
outputTextByPart.set(key, `${outputTextByPart.get(key) ?? ""}${delta}`);
|
|
1674
|
+
if (itemId && outputItemTypes.get(itemId) === "reasoning") {
|
|
1675
|
+
yield { type: "thinking_delta", text: delta };
|
|
1676
|
+
} else {
|
|
1677
|
+
textAccum += delta;
|
|
1678
|
+
yield { type: "text_delta", text: delta };
|
|
1679
|
+
}
|
|
1680
|
+
}
|
|
1681
|
+
if (type === "response.output_text.done") {
|
|
1682
|
+
const fullText = event.text;
|
|
1683
|
+
if (fullText) {
|
|
1684
|
+
const itemId = event.item_id;
|
|
1685
|
+
const contentIndex = event.content_index;
|
|
1686
|
+
const key = outputTextKey(itemId, contentIndex);
|
|
1687
|
+
const streamedText = outputTextByPart.get(key) ?? "";
|
|
1688
|
+
const missingText = streamedText ? fullText.slice(streamedText.length) : fullText;
|
|
1689
|
+
outputTextByPart.set(key, fullText);
|
|
1690
|
+
if (missingText && fullText.startsWith(streamedText)) {
|
|
1691
|
+
if (itemId && outputItemTypes.get(itemId) === "reasoning") {
|
|
1692
|
+
yield { type: "thinking_delta", text: missingText };
|
|
1693
|
+
} else {
|
|
1694
|
+
textAccum += missingText;
|
|
1695
|
+
yield { type: "text_delta", text: missingText };
|
|
1696
|
+
}
|
|
1697
|
+
}
|
|
1698
|
+
}
|
|
1667
1699
|
}
|
|
1668
|
-
if (type === "response.reasoning_summary_text.delta") {
|
|
1700
|
+
if (type === "response.reasoning_summary_text.delta" || type === "response.reasoning_summary.delta" || type === "response.reasoning_text.delta" || type === "response.reasoning.delta") {
|
|
1669
1701
|
const delta = event.delta;
|
|
1670
1702
|
yield { type: "thinking_delta", text: delta };
|
|
1671
1703
|
}
|
|
1672
1704
|
if (type === "response.output_item.added") {
|
|
1673
1705
|
const item = event.item;
|
|
1674
|
-
|
|
1706
|
+
const itemId = item?.id;
|
|
1707
|
+
const itemType = item?.type;
|
|
1708
|
+
if (itemId && itemType) {
|
|
1709
|
+
outputItemTypes.set(itemId, itemType);
|
|
1710
|
+
}
|
|
1711
|
+
if (itemType === "reasoning") {
|
|
1675
1712
|
yield { type: "thinking_delta", text: "" };
|
|
1676
1713
|
}
|
|
1677
1714
|
}
|