@kenkaiiii/gg-ai 4.3.169 → 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 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);
@@ -782,7 +783,10 @@ function createClient(options) {
782
783
  maxRetries: 2,
783
784
  ...isOAuth ? {
784
785
  defaultHeaders: {
785
- "user-agent": "claude-cli/2.1.75",
786
+ // Anthropic's OAuth edge validates the claude-cli version. Callers
787
+ // (ggcoder) resolve the live version at runtime; the literal here
788
+ // is the offline fallback for direct gg-ai consumers.
789
+ "user-agent": options.userAgent ?? "claude-cli/2.1.75 (external, cli)",
786
790
  "x-app": "cli"
787
791
  }
788
792
  } : {}
@@ -827,16 +831,28 @@ async function* runStream(options) {
827
831
  ...options.temperature != null && !thinking ? { temperature: options.temperature } : {},
828
832
  ...options.topP != null ? { top_p: options.topP } : {},
829
833
  ...options.stop ? { stop_sequences: options.stop } : {},
830
- ...options.tools?.length || options.serverTools?.length || options.webSearch ? {
831
- tools: [
832
- ...options.tools?.length ? toAnthropicTools(options.tools, {
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
+ {
833
844
  ...supportsFirstPartyToolExtras && cacheControl ? { cacheControl } : {},
834
845
  ...supportsFirstPartyToolExtras ? { enableFineGrainedToolStreaming: true } : {}
835
- }) : [],
836
- ...options.serverTools ?? [],
837
- ...options.webSearch ? [{ type: "web_search_20250305", name: "web_search" }] : []
838
- ]
839
- } : {},
846
+ }
847
+ ) : [];
848
+ return {
849
+ tools: [
850
+ ...clientTools,
851
+ ...options.serverTools ?? [],
852
+ ...options.webSearch ? [{ type: "web_search_20250305", name: "web_search" }] : []
853
+ ]
854
+ };
855
+ })() : {},
840
856
  ...options.toolChoice && options.tools?.length ? { tool_choice: toAnthropicToolChoice(options.toolChoice) } : {},
841
857
  ...(() => {
842
858
  const contextEdits = [
@@ -921,7 +937,11 @@ async function* runStream(options) {
921
937
  accum.raw = block;
922
938
  }
923
939
  blocks.set(idx, accum);
924
- yield keepalive;
940
+ if (block.type === "thinking") {
941
+ yield { type: "thinking_delta", text: "" };
942
+ } else {
943
+ yield keepalive;
944
+ }
925
945
  break;
926
946
  }
927
947
  case "content_block_delta": {
@@ -1487,6 +1507,17 @@ function toError2(err, provider = "openai") {
1487
1507
 
1488
1508
  // src/providers/openai-codex.ts
1489
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
1490
1521
  var DEFAULT_BASE_URL = "https://chatgpt.com/backend-api";
1491
1522
  function streamOpenAICodex(options) {
1492
1523
  return new StreamResult(runStream3(options));
@@ -1564,9 +1595,15 @@ async function* runStream3(options) {
1564
1595
  let inputTokens = 0;
1565
1596
  let outputTokens = 0;
1566
1597
  let cacheRead = 0;
1598
+ const diagStart = Date.now();
1599
+ const diagSeen = /* @__PURE__ */ new Set();
1567
1600
  for await (const event of parseSSE(response.body)) {
1568
1601
  const type = event.type;
1569
1602
  if (!type) continue;
1603
+ if (!diagSeen.has(type)) {
1604
+ diagSeen.add(type);
1605
+ providerDiag("codex_event_first", { type, sinceStartMs: Date.now() - diagStart });
1606
+ }
1570
1607
  if (type === "error") {
1571
1608
  const nested = event.error ?? void 0;
1572
1609
  const message = nested?.message ?? event.message ?? "Codex stream emitted an error chunk without a message.";
@@ -1594,6 +1631,12 @@ async function* runStream3(options) {
1594
1631
  const delta = event.delta;
1595
1632
  yield { type: "thinking_delta", text: delta };
1596
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
+ }
1597
1640
  if (type === "response.output_item.added") {
1598
1641
  const item = event.item;
1599
1642
  if (item?.type === "function_call") {
@@ -2114,6 +2157,7 @@ function registerPalsuProvider(config) {
2114
2157
  palsuToolCall,
2115
2158
  providerRegistry,
2116
2159
  registerPalsuProvider,
2160
+ setProviderDiagnostic,
2117
2161
  stream
2118
2162
  });
2119
2163
  //# sourceMappingURL=index.cjs.map