@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.d.cts CHANGED
@@ -371,6 +371,16 @@ declare function formatError(err: unknown): FormattedError;
371
371
  */
372
372
  declare function formatErrorForDisplay(err: unknown): string;
373
373
 
374
+ /**
375
+ * Provider-level diagnostic hook. Mirrors the pattern used by gg-agent's
376
+ * setStreamDiagnostic — the host app wires a callback (typically writing to
377
+ * a debug log) and providers call `providerDiag(...)` to record interesting
378
+ * lifecycle events (e.g. raw SSE event types and timings).
379
+ */
380
+ type ProviderDiagnosticFn = (phase: string, data?: Record<string, unknown>) => void;
381
+ /** Register a diagnostic callback for provider-level tracing. */
382
+ declare function setProviderDiagnostic(fn: ProviderDiagnosticFn | null): void;
383
+
374
384
  interface PalsuProviderState {
375
385
  callCount: number;
376
386
  }
@@ -440,4 +450,4 @@ interface PalsuProviderConfig {
440
450
  */
441
451
  declare function registerPalsuProvider(config?: PalsuProviderConfig): PalsuProviderHandle;
442
452
 
443
- export { type AssistantMessage, type CacheRetention, type ContentPart, type DoneEvent, type ErrorEvent, type ErrorSource, EventStream, type FormattedError, GGAIError, type ImageContent, type Message, type PalsuModelConfig, type PalsuModelHandle, type PalsuProviderConfig, type PalsuProviderHandle, type PalsuProviderState, type PalsuResponse, type PalsuResponseFactory, type Provider, type ProviderEntry, ProviderError, type ProviderStreamFn, type RawContent, type ServerToolCall, type ServerToolCallEvent, type ServerToolDefinition, type ServerToolResult, type ServerToolResultEvent, type StopReason, type StreamEvent, type StreamOptions, type StreamResponse, StreamResult, type SystemMessage, type TextContent, type TextDeltaEvent, type ThinkingContent, type ThinkingDeltaEvent, type ThinkingLevel, type Tool, type ToolCall, type ToolCallDeltaEvent, type ToolCallDoneEvent, type ToolChoice, type ToolResult, type ToolResultContent, type ToolResultMessage, type Usage, type UserMessage, formatError, formatErrorForDisplay, palsuAssistantMessage, palsuText, palsuThinking, palsuToolCall, providerRegistry, registerPalsuProvider, stream };
453
+ export { type AssistantMessage, type CacheRetention, type ContentPart, type DoneEvent, type ErrorEvent, type ErrorSource, EventStream, type FormattedError, GGAIError, type ImageContent, type Message, type PalsuModelConfig, type PalsuModelHandle, type PalsuProviderConfig, type PalsuProviderHandle, type PalsuProviderState, type PalsuResponse, type PalsuResponseFactory, type Provider, type ProviderDiagnosticFn, type ProviderEntry, ProviderError, type ProviderStreamFn, type RawContent, type ServerToolCall, type ServerToolCallEvent, type ServerToolDefinition, type ServerToolResult, type ServerToolResultEvent, type StopReason, type StreamEvent, type StreamOptions, type StreamResponse, StreamResult, type SystemMessage, type TextContent, type TextDeltaEvent, type ThinkingContent, type ThinkingDeltaEvent, type ThinkingLevel, type Tool, type ToolCall, type ToolCallDeltaEvent, type ToolCallDoneEvent, type ToolChoice, type ToolResult, type ToolResultContent, type ToolResultMessage, type Usage, type UserMessage, formatError, formatErrorForDisplay, palsuAssistantMessage, palsuText, palsuThinking, palsuToolCall, providerRegistry, registerPalsuProvider, setProviderDiagnostic, stream };
package/dist/index.d.ts CHANGED
@@ -371,6 +371,16 @@ declare function formatError(err: unknown): FormattedError;
371
371
  */
372
372
  declare function formatErrorForDisplay(err: unknown): string;
373
373
 
374
+ /**
375
+ * Provider-level diagnostic hook. Mirrors the pattern used by gg-agent's
376
+ * setStreamDiagnostic — the host app wires a callback (typically writing to
377
+ * a debug log) and providers call `providerDiag(...)` to record interesting
378
+ * lifecycle events (e.g. raw SSE event types and timings).
379
+ */
380
+ type ProviderDiagnosticFn = (phase: string, data?: Record<string, unknown>) => void;
381
+ /** Register a diagnostic callback for provider-level tracing. */
382
+ declare function setProviderDiagnostic(fn: ProviderDiagnosticFn | null): void;
383
+
374
384
  interface PalsuProviderState {
375
385
  callCount: number;
376
386
  }
@@ -440,4 +450,4 @@ interface PalsuProviderConfig {
440
450
  */
441
451
  declare function registerPalsuProvider(config?: PalsuProviderConfig): PalsuProviderHandle;
442
452
 
443
- export { type AssistantMessage, type CacheRetention, type ContentPart, type DoneEvent, type ErrorEvent, type ErrorSource, EventStream, type FormattedError, GGAIError, type ImageContent, type Message, type PalsuModelConfig, type PalsuModelHandle, type PalsuProviderConfig, type PalsuProviderHandle, type PalsuProviderState, type PalsuResponse, type PalsuResponseFactory, type Provider, type ProviderEntry, ProviderError, type ProviderStreamFn, type RawContent, type ServerToolCall, type ServerToolCallEvent, type ServerToolDefinition, type ServerToolResult, type ServerToolResultEvent, type StopReason, type StreamEvent, type StreamOptions, type StreamResponse, StreamResult, type SystemMessage, type TextContent, type TextDeltaEvent, type ThinkingContent, type ThinkingDeltaEvent, type ThinkingLevel, type Tool, type ToolCall, type ToolCallDeltaEvent, type ToolCallDoneEvent, type ToolChoice, type ToolResult, type ToolResultContent, type ToolResultMessage, type Usage, type UserMessage, formatError, formatErrorForDisplay, palsuAssistantMessage, palsuText, palsuThinking, palsuToolCall, providerRegistry, registerPalsuProvider, stream };
453
+ export { type AssistantMessage, type CacheRetention, type ContentPart, type DoneEvent, type ErrorEvent, type ErrorSource, EventStream, type FormattedError, GGAIError, type ImageContent, type Message, type PalsuModelConfig, type PalsuModelHandle, type PalsuProviderConfig, type PalsuProviderHandle, type PalsuProviderState, type PalsuResponse, type PalsuResponseFactory, type Provider, type ProviderDiagnosticFn, type ProviderEntry, ProviderError, type ProviderStreamFn, type RawContent, type ServerToolCall, type ServerToolCallEvent, type ServerToolDefinition, type ServerToolResult, type ServerToolResultEvent, type StopReason, type StreamEvent, type StreamOptions, type StreamResponse, StreamResult, type SystemMessage, type TextContent, type TextDeltaEvent, type ThinkingContent, type ThinkingDeltaEvent, type ThinkingLevel, type Tool, type ToolCall, type ToolCallDeltaEvent, type ToolCallDoneEvent, type ToolChoice, type ToolResult, type ToolResultContent, type ToolResultMessage, type Usage, type UserMessage, formatError, formatErrorForDisplay, palsuAssistantMessage, palsuText, palsuThinking, palsuToolCall, providerRegistry, registerPalsuProvider, setProviderDiagnostic, stream };
package/dist/index.js CHANGED
@@ -782,16 +782,28 @@ async function* runStream(options) {
782
782
  ...options.temperature != null && !thinking ? { temperature: options.temperature } : {},
783
783
  ...options.topP != null ? { top_p: options.topP } : {},
784
784
  ...options.stop ? { stop_sequences: options.stop } : {},
785
- ...options.tools?.length || options.serverTools?.length || options.webSearch ? {
786
- tools: [
787
- ...options.tools?.length ? toAnthropicTools(options.tools, {
785
+ ...options.tools?.length || options.serverTools?.length || options.webSearch ? (() => {
786
+ const reservedServerNames = /* @__PURE__ */ new Set();
787
+ if (options.webSearch) reservedServerNames.add("web_search");
788
+ for (const t of options.serverTools ?? []) {
789
+ const name = t.name;
790
+ if (name) reservedServerNames.add(name);
791
+ }
792
+ const clientTools = options.tools?.length ? toAnthropicTools(
793
+ options.tools.filter((t) => !reservedServerNames.has(t.name)),
794
+ {
788
795
  ...supportsFirstPartyToolExtras && cacheControl ? { cacheControl } : {},
789
796
  ...supportsFirstPartyToolExtras ? { enableFineGrainedToolStreaming: true } : {}
790
- }) : [],
791
- ...options.serverTools ?? [],
792
- ...options.webSearch ? [{ type: "web_search_20250305", name: "web_search" }] : []
793
- ]
794
- } : {},
797
+ }
798
+ ) : [];
799
+ return {
800
+ tools: [
801
+ ...clientTools,
802
+ ...options.serverTools ?? [],
803
+ ...options.webSearch ? [{ type: "web_search_20250305", name: "web_search" }] : []
804
+ ]
805
+ };
806
+ })() : {},
795
807
  ...options.toolChoice && options.tools?.length ? { tool_choice: toAnthropicToolChoice(options.toolChoice) } : {},
796
808
  ...(() => {
797
809
  const contextEdits = [
@@ -876,7 +888,11 @@ async function* runStream(options) {
876
888
  accum.raw = block;
877
889
  }
878
890
  blocks.set(idx, accum);
879
- yield keepalive;
891
+ if (block.type === "thinking") {
892
+ yield { type: "thinking_delta", text: "" };
893
+ } else {
894
+ yield keepalive;
895
+ }
880
896
  break;
881
897
  }
882
898
  case "content_block_delta": {
@@ -1442,6 +1458,17 @@ function toError2(err, provider = "openai") {
1442
1458
 
1443
1459
  // src/providers/openai-codex.ts
1444
1460
  import os from "os";
1461
+
1462
+ // src/utils/diag.ts
1463
+ var _diagFn = null;
1464
+ function setProviderDiagnostic(fn) {
1465
+ _diagFn = fn;
1466
+ }
1467
+ function providerDiag(phase, data) {
1468
+ _diagFn?.(phase, data);
1469
+ }
1470
+
1471
+ // src/providers/openai-codex.ts
1445
1472
  var DEFAULT_BASE_URL = "https://chatgpt.com/backend-api";
1446
1473
  function streamOpenAICodex(options) {
1447
1474
  return new StreamResult(runStream3(options));
@@ -1519,9 +1546,15 @@ async function* runStream3(options) {
1519
1546
  let inputTokens = 0;
1520
1547
  let outputTokens = 0;
1521
1548
  let cacheRead = 0;
1549
+ const diagStart = Date.now();
1550
+ const diagSeen = /* @__PURE__ */ new Set();
1522
1551
  for await (const event of parseSSE(response.body)) {
1523
1552
  const type = event.type;
1524
1553
  if (!type) continue;
1554
+ if (!diagSeen.has(type)) {
1555
+ diagSeen.add(type);
1556
+ providerDiag("codex_event_first", { type, sinceStartMs: Date.now() - diagStart });
1557
+ }
1525
1558
  if (type === "error") {
1526
1559
  const nested = event.error ?? void 0;
1527
1560
  const message = nested?.message ?? event.message ?? "Codex stream emitted an error chunk without a message.";
@@ -1549,6 +1582,12 @@ async function* runStream3(options) {
1549
1582
  const delta = event.delta;
1550
1583
  yield { type: "thinking_delta", text: delta };
1551
1584
  }
1585
+ if (type === "response.output_item.added") {
1586
+ const item = event.item;
1587
+ if (item?.type === "reasoning") {
1588
+ yield { type: "thinking_delta", text: "" };
1589
+ }
1590
+ }
1552
1591
  if (type === "response.output_item.added") {
1553
1592
  const item = event.item;
1554
1593
  if (item?.type === "function_call") {
@@ -2068,6 +2107,7 @@ export {
2068
2107
  palsuToolCall,
2069
2108
  providerRegistry,
2070
2109
  registerPalsuProvider,
2110
+ setProviderDiagnostic,
2071
2111
  stream
2072
2112
  };
2073
2113
  //# sourceMappingURL=index.js.map