@kenkaiiii/gg-ai 4.3.170 → 4.3.171
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 +50 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.js +49 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -42,6 +42,7 @@ __export(index_exports, {
|
|
|
42
42
|
palsuToolCall: () => palsuToolCall,
|
|
43
43
|
providerRegistry: () => providerRegistry,
|
|
44
44
|
registerPalsuProvider: () => registerPalsuProvider,
|
|
45
|
+
setProviderDiagnostic: () => setProviderDiagnostic,
|
|
45
46
|
stream: () => stream
|
|
46
47
|
});
|
|
47
48
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -830,16 +831,28 @@ async function* runStream(options) {
|
|
|
830
831
|
...options.temperature != null && !thinking ? { temperature: options.temperature } : {},
|
|
831
832
|
...options.topP != null ? { top_p: options.topP } : {},
|
|
832
833
|
...options.stop ? { stop_sequences: options.stop } : {},
|
|
833
|
-
...options.tools?.length || options.serverTools?.length || options.webSearch ? {
|
|
834
|
-
|
|
835
|
-
|
|
834
|
+
...options.tools?.length || options.serverTools?.length || options.webSearch ? (() => {
|
|
835
|
+
const reservedServerNames = /* @__PURE__ */ new Set();
|
|
836
|
+
if (options.webSearch) reservedServerNames.add("web_search");
|
|
837
|
+
for (const t of options.serverTools ?? []) {
|
|
838
|
+
const name = t.name;
|
|
839
|
+
if (name) reservedServerNames.add(name);
|
|
840
|
+
}
|
|
841
|
+
const clientTools = options.tools?.length ? toAnthropicTools(
|
|
842
|
+
options.tools.filter((t) => !reservedServerNames.has(t.name)),
|
|
843
|
+
{
|
|
836
844
|
...supportsFirstPartyToolExtras && cacheControl ? { cacheControl } : {},
|
|
837
845
|
...supportsFirstPartyToolExtras ? { enableFineGrainedToolStreaming: true } : {}
|
|
838
|
-
}
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
846
|
+
}
|
|
847
|
+
) : [];
|
|
848
|
+
return {
|
|
849
|
+
tools: [
|
|
850
|
+
...clientTools,
|
|
851
|
+
...options.serverTools ?? [],
|
|
852
|
+
...options.webSearch ? [{ type: "web_search_20250305", name: "web_search" }] : []
|
|
853
|
+
]
|
|
854
|
+
};
|
|
855
|
+
})() : {},
|
|
843
856
|
...options.toolChoice && options.tools?.length ? { tool_choice: toAnthropicToolChoice(options.toolChoice) } : {},
|
|
844
857
|
...(() => {
|
|
845
858
|
const contextEdits = [
|
|
@@ -924,7 +937,11 @@ async function* runStream(options) {
|
|
|
924
937
|
accum.raw = block;
|
|
925
938
|
}
|
|
926
939
|
blocks.set(idx, accum);
|
|
927
|
-
|
|
940
|
+
if (block.type === "thinking") {
|
|
941
|
+
yield { type: "thinking_delta", text: "" };
|
|
942
|
+
} else {
|
|
943
|
+
yield keepalive;
|
|
944
|
+
}
|
|
928
945
|
break;
|
|
929
946
|
}
|
|
930
947
|
case "content_block_delta": {
|
|
@@ -1490,6 +1507,17 @@ function toError2(err, provider = "openai") {
|
|
|
1490
1507
|
|
|
1491
1508
|
// src/providers/openai-codex.ts
|
|
1492
1509
|
var import_node_os = __toESM(require("os"), 1);
|
|
1510
|
+
|
|
1511
|
+
// src/utils/diag.ts
|
|
1512
|
+
var _diagFn = null;
|
|
1513
|
+
function setProviderDiagnostic(fn) {
|
|
1514
|
+
_diagFn = fn;
|
|
1515
|
+
}
|
|
1516
|
+
function providerDiag(phase, data) {
|
|
1517
|
+
_diagFn?.(phase, data);
|
|
1518
|
+
}
|
|
1519
|
+
|
|
1520
|
+
// src/providers/openai-codex.ts
|
|
1493
1521
|
var DEFAULT_BASE_URL = "https://chatgpt.com/backend-api";
|
|
1494
1522
|
function streamOpenAICodex(options) {
|
|
1495
1523
|
return new StreamResult(runStream3(options));
|
|
@@ -1567,9 +1595,15 @@ async function* runStream3(options) {
|
|
|
1567
1595
|
let inputTokens = 0;
|
|
1568
1596
|
let outputTokens = 0;
|
|
1569
1597
|
let cacheRead = 0;
|
|
1598
|
+
const diagStart = Date.now();
|
|
1599
|
+
const diagSeen = /* @__PURE__ */ new Set();
|
|
1570
1600
|
for await (const event of parseSSE(response.body)) {
|
|
1571
1601
|
const type = event.type;
|
|
1572
1602
|
if (!type) continue;
|
|
1603
|
+
if (!diagSeen.has(type)) {
|
|
1604
|
+
diagSeen.add(type);
|
|
1605
|
+
providerDiag("codex_event_first", { type, sinceStartMs: Date.now() - diagStart });
|
|
1606
|
+
}
|
|
1573
1607
|
if (type === "error") {
|
|
1574
1608
|
const nested = event.error ?? void 0;
|
|
1575
1609
|
const message = nested?.message ?? event.message ?? "Codex stream emitted an error chunk without a message.";
|
|
@@ -1597,6 +1631,12 @@ async function* runStream3(options) {
|
|
|
1597
1631
|
const delta = event.delta;
|
|
1598
1632
|
yield { type: "thinking_delta", text: delta };
|
|
1599
1633
|
}
|
|
1634
|
+
if (type === "response.output_item.added") {
|
|
1635
|
+
const item = event.item;
|
|
1636
|
+
if (item?.type === "reasoning") {
|
|
1637
|
+
yield { type: "thinking_delta", text: "" };
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1600
1640
|
if (type === "response.output_item.added") {
|
|
1601
1641
|
const item = event.item;
|
|
1602
1642
|
if (item?.type === "function_call") {
|
|
@@ -2117,6 +2157,7 @@ function registerPalsuProvider(config) {
|
|
|
2117
2157
|
palsuToolCall,
|
|
2118
2158
|
providerRegistry,
|
|
2119
2159
|
registerPalsuProvider,
|
|
2160
|
+
setProviderDiagnostic,
|
|
2120
2161
|
stream
|
|
2121
2162
|
});
|
|
2122
2163
|
//# sourceMappingURL=index.cjs.map
|