@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.js
CHANGED
|
@@ -1498,6 +1498,9 @@ function parseToolArguments2(argsJson) {
|
|
|
1498
1498
|
return {};
|
|
1499
1499
|
}
|
|
1500
1500
|
}
|
|
1501
|
+
function outputTextKey(itemId, contentIndex) {
|
|
1502
|
+
return `${itemId ?? ""}:${contentIndex ?? 0}`;
|
|
1503
|
+
}
|
|
1501
1504
|
function streamOpenAICodex(options) {
|
|
1502
1505
|
return new StreamResult(runStream3(options));
|
|
1503
1506
|
}
|
|
@@ -1581,6 +1584,8 @@ async function* runStream3(options) {
|
|
|
1581
1584
|
const contentParts = [];
|
|
1582
1585
|
let textAccum = "";
|
|
1583
1586
|
const toolCalls = /* @__PURE__ */ new Map();
|
|
1587
|
+
const outputItemTypes = /* @__PURE__ */ new Map();
|
|
1588
|
+
const outputTextByPart = /* @__PURE__ */ new Map();
|
|
1584
1589
|
let inputTokens = 0;
|
|
1585
1590
|
let outputTokens = 0;
|
|
1586
1591
|
let cacheRead = 0;
|
|
@@ -1613,16 +1618,48 @@ async function* runStream3(options) {
|
|
|
1613
1618
|
}
|
|
1614
1619
|
if (type === "response.output_text.delta") {
|
|
1615
1620
|
const delta = event.delta;
|
|
1616
|
-
|
|
1617
|
-
|
|
1621
|
+
const itemId = event.item_id;
|
|
1622
|
+
const contentIndex = event.content_index;
|
|
1623
|
+
const key = outputTextKey(itemId, contentIndex);
|
|
1624
|
+
outputTextByPart.set(key, `${outputTextByPart.get(key) ?? ""}${delta}`);
|
|
1625
|
+
if (itemId && outputItemTypes.get(itemId) === "reasoning") {
|
|
1626
|
+
yield { type: "thinking_delta", text: delta };
|
|
1627
|
+
} else {
|
|
1628
|
+
textAccum += delta;
|
|
1629
|
+
yield { type: "text_delta", text: delta };
|
|
1630
|
+
}
|
|
1631
|
+
}
|
|
1632
|
+
if (type === "response.output_text.done") {
|
|
1633
|
+
const fullText = event.text;
|
|
1634
|
+
if (fullText) {
|
|
1635
|
+
const itemId = event.item_id;
|
|
1636
|
+
const contentIndex = event.content_index;
|
|
1637
|
+
const key = outputTextKey(itemId, contentIndex);
|
|
1638
|
+
const streamedText = outputTextByPart.get(key) ?? "";
|
|
1639
|
+
const missingText = streamedText ? fullText.slice(streamedText.length) : fullText;
|
|
1640
|
+
outputTextByPart.set(key, fullText);
|
|
1641
|
+
if (missingText && fullText.startsWith(streamedText)) {
|
|
1642
|
+
if (itemId && outputItemTypes.get(itemId) === "reasoning") {
|
|
1643
|
+
yield { type: "thinking_delta", text: missingText };
|
|
1644
|
+
} else {
|
|
1645
|
+
textAccum += missingText;
|
|
1646
|
+
yield { type: "text_delta", text: missingText };
|
|
1647
|
+
}
|
|
1648
|
+
}
|
|
1649
|
+
}
|
|
1618
1650
|
}
|
|
1619
|
-
if (type === "response.reasoning_summary_text.delta") {
|
|
1651
|
+
if (type === "response.reasoning_summary_text.delta" || type === "response.reasoning_summary.delta" || type === "response.reasoning_text.delta" || type === "response.reasoning.delta") {
|
|
1620
1652
|
const delta = event.delta;
|
|
1621
1653
|
yield { type: "thinking_delta", text: delta };
|
|
1622
1654
|
}
|
|
1623
1655
|
if (type === "response.output_item.added") {
|
|
1624
1656
|
const item = event.item;
|
|
1625
|
-
|
|
1657
|
+
const itemId = item?.id;
|
|
1658
|
+
const itemType = item?.type;
|
|
1659
|
+
if (itemId && itemType) {
|
|
1660
|
+
outputItemTypes.set(itemId, itemType);
|
|
1661
|
+
}
|
|
1662
|
+
if (itemType === "reasoning") {
|
|
1626
1663
|
yield { type: "thinking_delta", text: "" };
|
|
1627
1664
|
}
|
|
1628
1665
|
}
|