@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 +54 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -1
- package/dist/index.d.ts +17 -1
- package/dist/index.js +53 -10
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -189,6 +189,12 @@ interface StreamOptions {
|
|
|
189
189
|
* stalls — broken SSE connections (transient CDN / proxy issues) often
|
|
190
190
|
* recover when the same request is issued over a plain HTTP request/response. */
|
|
191
191
|
streaming?: boolean;
|
|
192
|
+
/** Override the User-Agent sent with OAuth-authenticated Anthropic requests.
|
|
193
|
+
* Anthropic's OAuth edge rejects requests whose claude-cli version lags too
|
|
194
|
+
* far behind the real Claude Code release; callers that track the live
|
|
195
|
+
* version should pass it here. Ignored for non-Anthropic providers and for
|
|
196
|
+
* Anthropic requests using a regular API key. */
|
|
197
|
+
userAgent?: string;
|
|
192
198
|
}
|
|
193
199
|
|
|
194
200
|
/**
|
|
@@ -365,6 +371,16 @@ declare function formatError(err: unknown): FormattedError;
|
|
|
365
371
|
*/
|
|
366
372
|
declare function formatErrorForDisplay(err: unknown): string;
|
|
367
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
|
+
|
|
368
384
|
interface PalsuProviderState {
|
|
369
385
|
callCount: number;
|
|
370
386
|
}
|
|
@@ -434,4 +450,4 @@ interface PalsuProviderConfig {
|
|
|
434
450
|
*/
|
|
435
451
|
declare function registerPalsuProvider(config?: PalsuProviderConfig): PalsuProviderHandle;
|
|
436
452
|
|
|
437
|
-
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
|
@@ -189,6 +189,12 @@ interface StreamOptions {
|
|
|
189
189
|
* stalls — broken SSE connections (transient CDN / proxy issues) often
|
|
190
190
|
* recover when the same request is issued over a plain HTTP request/response. */
|
|
191
191
|
streaming?: boolean;
|
|
192
|
+
/** Override the User-Agent sent with OAuth-authenticated Anthropic requests.
|
|
193
|
+
* Anthropic's OAuth edge rejects requests whose claude-cli version lags too
|
|
194
|
+
* far behind the real Claude Code release; callers that track the live
|
|
195
|
+
* version should pass it here. Ignored for non-Anthropic providers and for
|
|
196
|
+
* Anthropic requests using a regular API key. */
|
|
197
|
+
userAgent?: string;
|
|
192
198
|
}
|
|
193
199
|
|
|
194
200
|
/**
|
|
@@ -365,6 +371,16 @@ declare function formatError(err: unknown): FormattedError;
|
|
|
365
371
|
*/
|
|
366
372
|
declare function formatErrorForDisplay(err: unknown): string;
|
|
367
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
|
+
|
|
368
384
|
interface PalsuProviderState {
|
|
369
385
|
callCount: number;
|
|
370
386
|
}
|
|
@@ -434,4 +450,4 @@ interface PalsuProviderConfig {
|
|
|
434
450
|
*/
|
|
435
451
|
declare function registerPalsuProvider(config?: PalsuProviderConfig): PalsuProviderHandle;
|
|
436
452
|
|
|
437
|
-
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
|
@@ -734,7 +734,10 @@ function createClient(options) {
|
|
|
734
734
|
maxRetries: 2,
|
|
735
735
|
...isOAuth ? {
|
|
736
736
|
defaultHeaders: {
|
|
737
|
-
|
|
737
|
+
// Anthropic's OAuth edge validates the claude-cli version. Callers
|
|
738
|
+
// (ggcoder) resolve the live version at runtime; the literal here
|
|
739
|
+
// is the offline fallback for direct gg-ai consumers.
|
|
740
|
+
"user-agent": options.userAgent ?? "claude-cli/2.1.75 (external, cli)",
|
|
738
741
|
"x-app": "cli"
|
|
739
742
|
}
|
|
740
743
|
} : {}
|
|
@@ -779,16 +782,28 @@ async function* runStream(options) {
|
|
|
779
782
|
...options.temperature != null && !thinking ? { temperature: options.temperature } : {},
|
|
780
783
|
...options.topP != null ? { top_p: options.topP } : {},
|
|
781
784
|
...options.stop ? { stop_sequences: options.stop } : {},
|
|
782
|
-
...options.tools?.length || options.serverTools?.length || options.webSearch ? {
|
|
783
|
-
|
|
784
|
-
|
|
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
|
+
{
|
|
785
795
|
...supportsFirstPartyToolExtras && cacheControl ? { cacheControl } : {},
|
|
786
796
|
...supportsFirstPartyToolExtras ? { enableFineGrainedToolStreaming: true } : {}
|
|
787
|
-
}
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
797
|
+
}
|
|
798
|
+
) : [];
|
|
799
|
+
return {
|
|
800
|
+
tools: [
|
|
801
|
+
...clientTools,
|
|
802
|
+
...options.serverTools ?? [],
|
|
803
|
+
...options.webSearch ? [{ type: "web_search_20250305", name: "web_search" }] : []
|
|
804
|
+
]
|
|
805
|
+
};
|
|
806
|
+
})() : {},
|
|
792
807
|
...options.toolChoice && options.tools?.length ? { tool_choice: toAnthropicToolChoice(options.toolChoice) } : {},
|
|
793
808
|
...(() => {
|
|
794
809
|
const contextEdits = [
|
|
@@ -873,7 +888,11 @@ async function* runStream(options) {
|
|
|
873
888
|
accum.raw = block;
|
|
874
889
|
}
|
|
875
890
|
blocks.set(idx, accum);
|
|
876
|
-
|
|
891
|
+
if (block.type === "thinking") {
|
|
892
|
+
yield { type: "thinking_delta", text: "" };
|
|
893
|
+
} else {
|
|
894
|
+
yield keepalive;
|
|
895
|
+
}
|
|
877
896
|
break;
|
|
878
897
|
}
|
|
879
898
|
case "content_block_delta": {
|
|
@@ -1439,6 +1458,17 @@ function toError2(err, provider = "openai") {
|
|
|
1439
1458
|
|
|
1440
1459
|
// src/providers/openai-codex.ts
|
|
1441
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
|
|
1442
1472
|
var DEFAULT_BASE_URL = "https://chatgpt.com/backend-api";
|
|
1443
1473
|
function streamOpenAICodex(options) {
|
|
1444
1474
|
return new StreamResult(runStream3(options));
|
|
@@ -1516,9 +1546,15 @@ async function* runStream3(options) {
|
|
|
1516
1546
|
let inputTokens = 0;
|
|
1517
1547
|
let outputTokens = 0;
|
|
1518
1548
|
let cacheRead = 0;
|
|
1549
|
+
const diagStart = Date.now();
|
|
1550
|
+
const diagSeen = /* @__PURE__ */ new Set();
|
|
1519
1551
|
for await (const event of parseSSE(response.body)) {
|
|
1520
1552
|
const type = event.type;
|
|
1521
1553
|
if (!type) continue;
|
|
1554
|
+
if (!diagSeen.has(type)) {
|
|
1555
|
+
diagSeen.add(type);
|
|
1556
|
+
providerDiag("codex_event_first", { type, sinceStartMs: Date.now() - diagStart });
|
|
1557
|
+
}
|
|
1522
1558
|
if (type === "error") {
|
|
1523
1559
|
const nested = event.error ?? void 0;
|
|
1524
1560
|
const message = nested?.message ?? event.message ?? "Codex stream emitted an error chunk without a message.";
|
|
@@ -1546,6 +1582,12 @@ async function* runStream3(options) {
|
|
|
1546
1582
|
const delta = event.delta;
|
|
1547
1583
|
yield { type: "thinking_delta", text: delta };
|
|
1548
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
|
+
}
|
|
1549
1591
|
if (type === "response.output_item.added") {
|
|
1550
1592
|
const item = event.item;
|
|
1551
1593
|
if (item?.type === "function_call") {
|
|
@@ -2065,6 +2107,7 @@ export {
|
|
|
2065
2107
|
palsuToolCall,
|
|
2066
2108
|
providerRegistry,
|
|
2067
2109
|
registerPalsuProvider,
|
|
2110
|
+
setProviderDiagnostic,
|
|
2068
2111
|
stream
|
|
2069
2112
|
};
|
|
2070
2113
|
//# sourceMappingURL=index.js.map
|