@kenkaiiii/gg-ai 5.87.2 → 5.87.3
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 +167 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -1
- package/dist/index.d.ts +14 -1
- package/dist/index.js +163 -23
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1018,6 +1018,19 @@ declare function prewarmAnthropicCache(options: {
|
|
|
1018
1018
|
signal?: AbortSignal;
|
|
1019
1019
|
}): Promise<void>;
|
|
1020
1020
|
|
|
1021
|
+
declare const CLAUDE_CODE_FALLBACK_VERSION = "2.1.316";
|
|
1022
|
+
/** Test hook: the pending background refresh, if any. */
|
|
1023
|
+
declare function pendingClaudeCodeVersionRefresh(): Promise<void> | null;
|
|
1024
|
+
/**
|
|
1025
|
+
* Resolve the current Claude Code release version for spoofing the claude-cli
|
|
1026
|
+
* User-Agent on OAuth and inference requests. Cached in-memory for the process
|
|
1027
|
+
* lifetime and on disk for 24h. Falls back to a hardcoded constant if the npm
|
|
1028
|
+
* registry is unreachable and no cache exists.
|
|
1029
|
+
*/
|
|
1030
|
+
declare function getClaudeCodeVersion(): Promise<string>;
|
|
1031
|
+
/** Build the User-Agent string Anthropic's OAuth + inference edges expect. */
|
|
1032
|
+
declare function getClaudeCliUserAgent(): Promise<string>;
|
|
1033
|
+
|
|
1021
1034
|
interface PalsuProviderState {
|
|
1022
1035
|
/** `stream()` calls served. */
|
|
1023
1036
|
callCount: number;
|
|
@@ -1104,4 +1117,4 @@ declare function palsuEmbedding(text: string, dimensions?: number): number[];
|
|
|
1104
1117
|
/** Deterministic fake relevance: the share of distinct query words found in the document (0–1). */
|
|
1105
1118
|
declare function palsuRerankScore(query: string, document: string): number;
|
|
1106
1119
|
|
|
1107
|
-
export { type AssistantMessage, CODEX_CLIENT_VERSION, type CacheRetention, type ChatErrorReason, type ContentPart, type DoneEvent, type EmbedInputType, type EmbedOptions, type EmbedResult, type EmbedUsage, type ErrorEvent, type ErrorSource, EventStream, FAST_MODE_SUFFIX, type FastModeRejection, type FastModeResolution, type FormattedChatError, type FormattedError, GGAIError, type ImageContent, type Message, type MessageProvenance, type MessageProvenanceKind, type MessageProvenanceSource, type MessageProvenanceVisibility, type OpenRouterProviderPreferences, type PalsuModelConfig, type PalsuModelHandle, type PalsuProviderConfig, type PalsuProviderHandle, type PalsuProviderState, type PalsuResponse, type PalsuResponseFactory, type PreparedContext, type Provider, type ProviderCapability, type ProviderDiagnosticFn, type ProviderEmbedFn, type ProviderEmbedRequest, type ProviderEmbedResponse, type ProviderEntry, ProviderError, type ProviderOptions, type ProviderRerankFn, type ProviderRerankRequest, type ProviderRerankResponse, type ProviderStreamFn, REDACTED as REDACTION_MARKER, type RawContent, type RedactionOptions, type RerankOptions, type RerankResponse, type RerankResult, type RerankUsage, ResponseStalledError, type ServerToolCall, type ServerToolCallEvent, type ServerToolDefinition, type ServerToolResult, type ServerToolResultEvent, type StopReason, type StreamEvent, type StreamOptions, type StreamResponse, StreamResult, type SystemMessage, TOOL_CALL_NAME_RULES, type TextContent, type TextDeltaEvent, type ThinkingContent, type ThinkingDeltaEvent, type ThinkingLevel, type Tool, type ToolCall, type ToolCallDeltaEvent, type ToolCallDoneEvent, type ToolCallNameRule, type ToolChoice, type ToolResult, type ToolResultContent, type ToolResultMessage, type Usage, type UserMessage, type VideoContent, clampProviderContextImages, classifyProviderError, continuesTurn, describeFastModeRejection, dropInvalidToolCalls, embed, environmentSecrets, formatChatError, formatError, formatErrorForDisplay, hasLoneSurrogate, isHardBillingMessage, isUsageLimitError, isValidToolCallName, localWireModelId, opensTurn, palsuAssistantMessage, palsuEmbedding, palsuRerankScore, palsuText, palsuThinking, palsuToolCall, parseFastModeRejection, prewarmAnthropicCache, providerRegistry, redactText, redactValue, registerPalsuProvider, rerank, resolveFastModeModel, resolveToolSchema, sanitizeMessagesForWire, setProviderDiagnostic, sliceHead, sliceTail, stream, toAnthropicMessages, toOpenAIMessages, toWellFormedText, toolCallNameRuleFor, usesResponsesLite };
|
|
1120
|
+
export { type AssistantMessage, CLAUDE_CODE_FALLBACK_VERSION, CODEX_CLIENT_VERSION, type CacheRetention, type ChatErrorReason, type ContentPart, type DoneEvent, type EmbedInputType, type EmbedOptions, type EmbedResult, type EmbedUsage, type ErrorEvent, type ErrorSource, EventStream, FAST_MODE_SUFFIX, type FastModeRejection, type FastModeResolution, type FormattedChatError, type FormattedError, GGAIError, type ImageContent, type Message, type MessageProvenance, type MessageProvenanceKind, type MessageProvenanceSource, type MessageProvenanceVisibility, type OpenRouterProviderPreferences, type PalsuModelConfig, type PalsuModelHandle, type PalsuProviderConfig, type PalsuProviderHandle, type PalsuProviderState, type PalsuResponse, type PalsuResponseFactory, type PreparedContext, type Provider, type ProviderCapability, type ProviderDiagnosticFn, type ProviderEmbedFn, type ProviderEmbedRequest, type ProviderEmbedResponse, type ProviderEntry, ProviderError, type ProviderOptions, type ProviderRerankFn, type ProviderRerankRequest, type ProviderRerankResponse, type ProviderStreamFn, REDACTED as REDACTION_MARKER, type RawContent, type RedactionOptions, type RerankOptions, type RerankResponse, type RerankResult, type RerankUsage, ResponseStalledError, type ServerToolCall, type ServerToolCallEvent, type ServerToolDefinition, type ServerToolResult, type ServerToolResultEvent, type StopReason, type StreamEvent, type StreamOptions, type StreamResponse, StreamResult, type SystemMessage, TOOL_CALL_NAME_RULES, type TextContent, type TextDeltaEvent, type ThinkingContent, type ThinkingDeltaEvent, type ThinkingLevel, type Tool, type ToolCall, type ToolCallDeltaEvent, type ToolCallDoneEvent, type ToolCallNameRule, type ToolChoice, type ToolResult, type ToolResultContent, type ToolResultMessage, type Usage, type UserMessage, type VideoContent, clampProviderContextImages, classifyProviderError, continuesTurn, describeFastModeRejection, dropInvalidToolCalls, embed, environmentSecrets, formatChatError, formatError, formatErrorForDisplay, getClaudeCliUserAgent, getClaudeCodeVersion, hasLoneSurrogate, isHardBillingMessage, isUsageLimitError, isValidToolCallName, localWireModelId, opensTurn, palsuAssistantMessage, palsuEmbedding, palsuRerankScore, palsuText, palsuThinking, palsuToolCall, parseFastModeRejection, pendingClaudeCodeVersionRefresh, prewarmAnthropicCache, providerRegistry, redactText, redactValue, registerPalsuProvider, rerank, resolveFastModeModel, resolveToolSchema, sanitizeMessagesForWire, setProviderDiagnostic, sliceHead, sliceTail, stream, toAnthropicMessages, toOpenAIMessages, toWellFormedText, toolCallNameRuleFor, usesResponsesLite };
|
package/dist/index.d.ts
CHANGED
|
@@ -1018,6 +1018,19 @@ declare function prewarmAnthropicCache(options: {
|
|
|
1018
1018
|
signal?: AbortSignal;
|
|
1019
1019
|
}): Promise<void>;
|
|
1020
1020
|
|
|
1021
|
+
declare const CLAUDE_CODE_FALLBACK_VERSION = "2.1.316";
|
|
1022
|
+
/** Test hook: the pending background refresh, if any. */
|
|
1023
|
+
declare function pendingClaudeCodeVersionRefresh(): Promise<void> | null;
|
|
1024
|
+
/**
|
|
1025
|
+
* Resolve the current Claude Code release version for spoofing the claude-cli
|
|
1026
|
+
* User-Agent on OAuth and inference requests. Cached in-memory for the process
|
|
1027
|
+
* lifetime and on disk for 24h. Falls back to a hardcoded constant if the npm
|
|
1028
|
+
* registry is unreachable and no cache exists.
|
|
1029
|
+
*/
|
|
1030
|
+
declare function getClaudeCodeVersion(): Promise<string>;
|
|
1031
|
+
/** Build the User-Agent string Anthropic's OAuth + inference edges expect. */
|
|
1032
|
+
declare function getClaudeCliUserAgent(): Promise<string>;
|
|
1033
|
+
|
|
1021
1034
|
interface PalsuProviderState {
|
|
1022
1035
|
/** `stream()` calls served. */
|
|
1023
1036
|
callCount: number;
|
|
@@ -1104,4 +1117,4 @@ declare function palsuEmbedding(text: string, dimensions?: number): number[];
|
|
|
1104
1117
|
/** Deterministic fake relevance: the share of distinct query words found in the document (0–1). */
|
|
1105
1118
|
declare function palsuRerankScore(query: string, document: string): number;
|
|
1106
1119
|
|
|
1107
|
-
export { type AssistantMessage, CODEX_CLIENT_VERSION, type CacheRetention, type ChatErrorReason, type ContentPart, type DoneEvent, type EmbedInputType, type EmbedOptions, type EmbedResult, type EmbedUsage, type ErrorEvent, type ErrorSource, EventStream, FAST_MODE_SUFFIX, type FastModeRejection, type FastModeResolution, type FormattedChatError, type FormattedError, GGAIError, type ImageContent, type Message, type MessageProvenance, type MessageProvenanceKind, type MessageProvenanceSource, type MessageProvenanceVisibility, type OpenRouterProviderPreferences, type PalsuModelConfig, type PalsuModelHandle, type PalsuProviderConfig, type PalsuProviderHandle, type PalsuProviderState, type PalsuResponse, type PalsuResponseFactory, type PreparedContext, type Provider, type ProviderCapability, type ProviderDiagnosticFn, type ProviderEmbedFn, type ProviderEmbedRequest, type ProviderEmbedResponse, type ProviderEntry, ProviderError, type ProviderOptions, type ProviderRerankFn, type ProviderRerankRequest, type ProviderRerankResponse, type ProviderStreamFn, REDACTED as REDACTION_MARKER, type RawContent, type RedactionOptions, type RerankOptions, type RerankResponse, type RerankResult, type RerankUsage, ResponseStalledError, type ServerToolCall, type ServerToolCallEvent, type ServerToolDefinition, type ServerToolResult, type ServerToolResultEvent, type StopReason, type StreamEvent, type StreamOptions, type StreamResponse, StreamResult, type SystemMessage, TOOL_CALL_NAME_RULES, type TextContent, type TextDeltaEvent, type ThinkingContent, type ThinkingDeltaEvent, type ThinkingLevel, type Tool, type ToolCall, type ToolCallDeltaEvent, type ToolCallDoneEvent, type ToolCallNameRule, type ToolChoice, type ToolResult, type ToolResultContent, type ToolResultMessage, type Usage, type UserMessage, type VideoContent, clampProviderContextImages, classifyProviderError, continuesTurn, describeFastModeRejection, dropInvalidToolCalls, embed, environmentSecrets, formatChatError, formatError, formatErrorForDisplay, hasLoneSurrogate, isHardBillingMessage, isUsageLimitError, isValidToolCallName, localWireModelId, opensTurn, palsuAssistantMessage, palsuEmbedding, palsuRerankScore, palsuText, palsuThinking, palsuToolCall, parseFastModeRejection, prewarmAnthropicCache, providerRegistry, redactText, redactValue, registerPalsuProvider, rerank, resolveFastModeModel, resolveToolSchema, sanitizeMessagesForWire, setProviderDiagnostic, sliceHead, sliceTail, stream, toAnthropicMessages, toOpenAIMessages, toWellFormedText, toolCallNameRuleFor, usesResponsesLite };
|
|
1120
|
+
export { type AssistantMessage, CLAUDE_CODE_FALLBACK_VERSION, CODEX_CLIENT_VERSION, type CacheRetention, type ChatErrorReason, type ContentPart, type DoneEvent, type EmbedInputType, type EmbedOptions, type EmbedResult, type EmbedUsage, type ErrorEvent, type ErrorSource, EventStream, FAST_MODE_SUFFIX, type FastModeRejection, type FastModeResolution, type FormattedChatError, type FormattedError, GGAIError, type ImageContent, type Message, type MessageProvenance, type MessageProvenanceKind, type MessageProvenanceSource, type MessageProvenanceVisibility, type OpenRouterProviderPreferences, type PalsuModelConfig, type PalsuModelHandle, type PalsuProviderConfig, type PalsuProviderHandle, type PalsuProviderState, type PalsuResponse, type PalsuResponseFactory, type PreparedContext, type Provider, type ProviderCapability, type ProviderDiagnosticFn, type ProviderEmbedFn, type ProviderEmbedRequest, type ProviderEmbedResponse, type ProviderEntry, ProviderError, type ProviderOptions, type ProviderRerankFn, type ProviderRerankRequest, type ProviderRerankResponse, type ProviderStreamFn, REDACTED as REDACTION_MARKER, type RawContent, type RedactionOptions, type RerankOptions, type RerankResponse, type RerankResult, type RerankUsage, ResponseStalledError, type ServerToolCall, type ServerToolCallEvent, type ServerToolDefinition, type ServerToolResult, type ServerToolResultEvent, type StopReason, type StreamEvent, type StreamOptions, type StreamResponse, StreamResult, type SystemMessage, TOOL_CALL_NAME_RULES, type TextContent, type TextDeltaEvent, type ThinkingContent, type ThinkingDeltaEvent, type ThinkingLevel, type Tool, type ToolCall, type ToolCallDeltaEvent, type ToolCallDoneEvent, type ToolCallNameRule, type ToolChoice, type ToolResult, type ToolResultContent, type ToolResultMessage, type Usage, type UserMessage, type VideoContent, clampProviderContextImages, classifyProviderError, continuesTurn, describeFastModeRejection, dropInvalidToolCalls, embed, environmentSecrets, formatChatError, formatError, formatErrorForDisplay, getClaudeCliUserAgent, getClaudeCodeVersion, hasLoneSurrogate, isHardBillingMessage, isUsageLimitError, isValidToolCallName, localWireModelId, opensTurn, palsuAssistantMessage, palsuEmbedding, palsuRerankScore, palsuText, palsuThinking, palsuToolCall, parseFastModeRejection, pendingClaudeCodeVersionRefresh, prewarmAnthropicCache, providerRegistry, redactText, redactValue, registerPalsuProvider, rerank, resolveFastModeModel, resolveToolSchema, sanitizeMessagesForWire, setProviderDiagnostic, sliceHead, sliceTail, stream, toAnthropicMessages, toOpenAIMessages, toWellFormedText, toolCallNameRuleFor, usesResponsesLite };
|
package/dist/index.js
CHANGED
|
@@ -554,6 +554,145 @@ var StreamResult = class _StreamResult {
|
|
|
554
554
|
}
|
|
555
555
|
};
|
|
556
556
|
|
|
557
|
+
// src/claude-code-version.ts
|
|
558
|
+
import fs from "fs/promises";
|
|
559
|
+
import os from "os";
|
|
560
|
+
import path from "path";
|
|
561
|
+
|
|
562
|
+
// src/utils/diag.ts
|
|
563
|
+
var _diagFn = null;
|
|
564
|
+
function setProviderDiagnostic(fn) {
|
|
565
|
+
_diagFn = fn;
|
|
566
|
+
}
|
|
567
|
+
function providerDiag(phase, data) {
|
|
568
|
+
_diagFn?.(phase, data);
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
// src/claude-code-version.ts
|
|
572
|
+
var NPM_LATEST_URL = "https://registry.npmjs.org/@anthropic-ai/claude-code/latest";
|
|
573
|
+
var CACHE_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
574
|
+
var FETCH_TIMEOUT_MS = 3e3;
|
|
575
|
+
var CLAUDE_CODE_FALLBACK_VERSION = "2.1.316";
|
|
576
|
+
function isOlder(a, b) {
|
|
577
|
+
const pa = a.split(".").map((n) => Number.parseInt(n, 10) || 0);
|
|
578
|
+
const pb = b.split(".").map((n) => Number.parseInt(n, 10) || 0);
|
|
579
|
+
for (let i = 0; i < Math.max(pa.length, pb.length); i++) {
|
|
580
|
+
const x = pa[i] ?? 0;
|
|
581
|
+
const y = pb[i] ?? 0;
|
|
582
|
+
if (x !== y) return x < y;
|
|
583
|
+
}
|
|
584
|
+
return false;
|
|
585
|
+
}
|
|
586
|
+
function atLeastFallback(version) {
|
|
587
|
+
return isOlder(version, CLAUDE_CODE_FALLBACK_VERSION) ? CLAUDE_CODE_FALLBACK_VERSION : version;
|
|
588
|
+
}
|
|
589
|
+
var memoryCache = null;
|
|
590
|
+
var inflight = null;
|
|
591
|
+
function agentDir() {
|
|
592
|
+
return path.join(os.homedir(), ".gg");
|
|
593
|
+
}
|
|
594
|
+
function cachePath() {
|
|
595
|
+
return path.join(agentDir(), "claude-code-version.json");
|
|
596
|
+
}
|
|
597
|
+
async function readDiskCache() {
|
|
598
|
+
try {
|
|
599
|
+
const raw = await fs.readFile(cachePath(), "utf-8");
|
|
600
|
+
const parsed = JSON.parse(raw);
|
|
601
|
+
if (typeof parsed.version === "string" && typeof parsed.fetchedAt === "number") {
|
|
602
|
+
return parsed;
|
|
603
|
+
}
|
|
604
|
+
return null;
|
|
605
|
+
} catch {
|
|
606
|
+
return null;
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
async function writeDiskCache(data) {
|
|
610
|
+
try {
|
|
611
|
+
await fs.mkdir(agentDir(), { recursive: true, mode: 448 });
|
|
612
|
+
await fs.writeFile(cachePath(), JSON.stringify(data), { mode: 384 });
|
|
613
|
+
} catch (err) {
|
|
614
|
+
providerDiag("claude_code_version_cache_write_failed", {
|
|
615
|
+
error: err instanceof Error ? err.message : String(err)
|
|
616
|
+
});
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
async function fetchLatest() {
|
|
620
|
+
const controller = new AbortController();
|
|
621
|
+
const timer = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
|
|
622
|
+
try {
|
|
623
|
+
const response = await fetch(NPM_LATEST_URL, { signal: controller.signal });
|
|
624
|
+
if (!response.ok) return null;
|
|
625
|
+
const data = await response.json();
|
|
626
|
+
if (typeof data.version === "string" && /^\d/.test(data.version)) {
|
|
627
|
+
return data.version;
|
|
628
|
+
}
|
|
629
|
+
return null;
|
|
630
|
+
} catch {
|
|
631
|
+
return null;
|
|
632
|
+
} finally {
|
|
633
|
+
clearTimeout(timer);
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
var refreshing = null;
|
|
637
|
+
function refreshInBackground() {
|
|
638
|
+
refreshing ??= (async () => {
|
|
639
|
+
try {
|
|
640
|
+
const fetched = await fetchLatest();
|
|
641
|
+
if (!fetched) return;
|
|
642
|
+
await writeDiskCache({ version: fetched, fetchedAt: Date.now() });
|
|
643
|
+
memoryCache = { version: fetched, expiresAt: Date.now() + CACHE_TTL_MS };
|
|
644
|
+
} finally {
|
|
645
|
+
refreshing = null;
|
|
646
|
+
}
|
|
647
|
+
})();
|
|
648
|
+
return refreshing;
|
|
649
|
+
}
|
|
650
|
+
function pendingClaudeCodeVersionRefresh() {
|
|
651
|
+
return refreshing;
|
|
652
|
+
}
|
|
653
|
+
async function getClaudeCodeVersion() {
|
|
654
|
+
if (memoryCache && Date.now() < memoryCache.expiresAt) {
|
|
655
|
+
return memoryCache.version;
|
|
656
|
+
}
|
|
657
|
+
if (inflight) return inflight;
|
|
658
|
+
inflight = (async () => {
|
|
659
|
+
const disk = await readDiskCache();
|
|
660
|
+
const diskFresh = disk && Date.now() - disk.fetchedAt < CACHE_TTL_MS;
|
|
661
|
+
if (disk && diskFresh) {
|
|
662
|
+
const version = atLeastFallback(disk.version);
|
|
663
|
+
memoryCache = { version, expiresAt: Date.now() + CACHE_TTL_MS };
|
|
664
|
+
return version;
|
|
665
|
+
}
|
|
666
|
+
if (disk) {
|
|
667
|
+
const version = atLeastFallback(disk.version);
|
|
668
|
+
memoryCache = { version, expiresAt: Date.now() + 5 * 60 * 1e3 };
|
|
669
|
+
void refreshInBackground();
|
|
670
|
+
return version;
|
|
671
|
+
}
|
|
672
|
+
const fetched = await fetchLatest();
|
|
673
|
+
if (fetched) {
|
|
674
|
+
await writeDiskCache({ version: fetched, fetchedAt: Date.now() });
|
|
675
|
+
memoryCache = { version: fetched, expiresAt: Date.now() + CACHE_TTL_MS };
|
|
676
|
+
return fetched;
|
|
677
|
+
}
|
|
678
|
+
const resolved = CLAUDE_CODE_FALLBACK_VERSION;
|
|
679
|
+
memoryCache = { version: resolved, expiresAt: Date.now() + 5 * 60 * 1e3 };
|
|
680
|
+
providerDiag("claude_code_version_fallback", { version: resolved });
|
|
681
|
+
return resolved;
|
|
682
|
+
})();
|
|
683
|
+
try {
|
|
684
|
+
return await inflight;
|
|
685
|
+
} finally {
|
|
686
|
+
inflight = null;
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
function claudeCliUserAgent(version) {
|
|
690
|
+
return `claude-cli/${version} (external, cli)`;
|
|
691
|
+
}
|
|
692
|
+
async function getClaudeCliUserAgent() {
|
|
693
|
+
return claudeCliUserAgent(await getClaudeCodeVersion());
|
|
694
|
+
}
|
|
695
|
+
|
|
557
696
|
// src/utils/provider-options.ts
|
|
558
697
|
var RESERVED_BODY_FIELDS = /* @__PURE__ */ new Set([
|
|
559
698
|
"contents",
|
|
@@ -1824,9 +1963,13 @@ function sumUsageIterations(usage) {
|
|
|
1824
1963
|
}
|
|
1825
1964
|
return totals;
|
|
1826
1965
|
}
|
|
1966
|
+
async function withClaudeUserAgent(options) {
|
|
1967
|
+
if (options.userAgent || !options.apiKey?.startsWith("sk-ant-oat")) return options;
|
|
1968
|
+
return { ...options, userAgent: await getClaudeCliUserAgent() };
|
|
1969
|
+
}
|
|
1827
1970
|
function createClient(options) {
|
|
1828
1971
|
const isOAuth = options.apiKey?.startsWith("sk-ant-oat");
|
|
1829
|
-
const userAgent = isOAuth ? options.userAgent ??
|
|
1972
|
+
const userAgent = isOAuth ? options.userAgent ?? claudeCliUserAgent(CLAUDE_CODE_FALLBACK_VERSION) : "";
|
|
1830
1973
|
const cacheKey = `${options.apiKey ?? ""}|${options.baseUrl ?? ""}|${userAgent}`;
|
|
1831
1974
|
if (!options.fetch) {
|
|
1832
1975
|
const cached = anthropicClientCache.get(cacheKey);
|
|
@@ -1856,11 +1999,13 @@ function createClient(options) {
|
|
|
1856
1999
|
}
|
|
1857
2000
|
async function prewarmAnthropicCache(options) {
|
|
1858
2001
|
try {
|
|
1859
|
-
const client = createClient(
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
2002
|
+
const client = createClient(
|
|
2003
|
+
await withClaudeUserAgent({
|
|
2004
|
+
apiKey: options.apiKey,
|
|
2005
|
+
baseUrl: options.baseUrl,
|
|
2006
|
+
userAgent: options.userAgent
|
|
2007
|
+
})
|
|
2008
|
+
);
|
|
1864
2009
|
const cacheControl = toAnthropicCacheControl(options.cacheRetention ?? "long", options.baseUrl);
|
|
1865
2010
|
const { system, messages } = toAnthropicMessages(
|
|
1866
2011
|
[
|
|
@@ -1914,7 +2059,7 @@ function streamAnthropic(options) {
|
|
|
1914
2059
|
return new StreamResult(runStream(options), options.signal);
|
|
1915
2060
|
}
|
|
1916
2061
|
async function* runStream(options) {
|
|
1917
|
-
const client = createClient(options);
|
|
2062
|
+
const client = createClient(await withClaudeUserAgent(options));
|
|
1918
2063
|
const isOAuth = options.apiKey?.startsWith("sk-ant-oat");
|
|
1919
2064
|
const useStreaming = options.streaming !== false && !options.prewarm;
|
|
1920
2065
|
const cacheControl = toAnthropicCacheControl(options.cacheRetention, options.baseUrl);
|
|
@@ -2495,15 +2640,6 @@ function fnv1aHash(value) {
|
|
|
2495
2640
|
return (hash >>> 0).toString(16).padStart(8, "0");
|
|
2496
2641
|
}
|
|
2497
2642
|
|
|
2498
|
-
// src/utils/diag.ts
|
|
2499
|
-
var _diagFn = null;
|
|
2500
|
-
function setProviderDiagnostic(fn) {
|
|
2501
|
-
_diagFn = fn;
|
|
2502
|
-
}
|
|
2503
|
-
function providerDiag(phase, data) {
|
|
2504
|
-
_diagFn?.(phase, data);
|
|
2505
|
-
}
|
|
2506
|
-
|
|
2507
2643
|
// src/providers/moonshot-video.ts
|
|
2508
2644
|
async function uploadMoonshotVideos(client, messages, signal) {
|
|
2509
2645
|
for (const msg of messages) {
|
|
@@ -2729,11 +2865,11 @@ async function* runStream2(options) {
|
|
|
2729
2865
|
}
|
|
2730
2866
|
const requestParams = mergeProviderOptions(params, options.providerOptions);
|
|
2731
2867
|
if (getEnvironment()?.GGAI_DUMP_REQUEST) {
|
|
2732
|
-
const
|
|
2868
|
+
const fs2 = await import("fs");
|
|
2733
2869
|
const ts = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
|
|
2734
2870
|
const dumpPath = `/tmp/ggai-request-${ts}.json`;
|
|
2735
|
-
|
|
2736
|
-
|
|
2871
|
+
fs2.writeFileSync(dumpPath, JSON.stringify(requestParams, null, 2));
|
|
2872
|
+
fs2.appendFileSync(
|
|
2737
2873
|
"/tmp/ggai-requests.log",
|
|
2738
2874
|
`[${ts}] ${dumpPath} messages=${requestParams.messages.length}
|
|
2739
2875
|
`
|
|
@@ -3063,7 +3199,7 @@ function toError2(err, provider = "openai") {
|
|
|
3063
3199
|
}
|
|
3064
3200
|
|
|
3065
3201
|
// src/providers/openai-codex.ts
|
|
3066
|
-
import
|
|
3202
|
+
import os2 from "os";
|
|
3067
3203
|
import * as zstd from "@bokuweb/zstd-wasm";
|
|
3068
3204
|
|
|
3069
3205
|
// src/utils/sse.ts
|
|
@@ -3665,7 +3801,7 @@ async function* runStream3(options, retriedWithoutReasoning = false) {
|
|
|
3665
3801
|
Authorization: `Bearer ${options.apiKey}`,
|
|
3666
3802
|
"OpenAI-Beta": "responses=experimental",
|
|
3667
3803
|
originator: responsesLite ? "codex_cli_rs" : "ggcoder",
|
|
3668
|
-
"User-Agent": responsesLite ? `codex_cli_rs/${CODEX_CLIENT_VERSION}` : `ggcoder (${
|
|
3804
|
+
"User-Agent": responsesLite ? `codex_cli_rs/${CODEX_CLIENT_VERSION}` : `ggcoder (${os2.platform()} ${os2.release()}; ${os2.arch()})`,
|
|
3669
3805
|
...responsesLite ? { version: CODEX_CLIENT_VERSION } : {},
|
|
3670
3806
|
...liteShape ? { "X-OpenAI-Internal-Codex-Responses-Lite": "true" } : {}
|
|
3671
3807
|
};
|
|
@@ -4789,8 +4925,8 @@ function bound(text) {
|
|
|
4789
4925
|
const trimmed = text.trim();
|
|
4790
4926
|
return trimmed.length > MAX_ERROR_MESSAGE_CHARS ? `${trimmed.slice(0, MAX_ERROR_MESSAGE_CHARS)}\u2026` : trimmed;
|
|
4791
4927
|
}
|
|
4792
|
-
function joinUrl(baseUrl,
|
|
4793
|
-
return `${baseUrl.replace(/\/+$/, "")}/${
|
|
4928
|
+
function joinUrl(baseUrl, path2) {
|
|
4929
|
+
return `${baseUrl.replace(/\/+$/, "")}/${path2.replace(/^\/+/, "")}`;
|
|
4794
4930
|
}
|
|
4795
4931
|
|
|
4796
4932
|
// src/providers/gemini-embeddings.ts
|
|
@@ -6000,6 +6136,7 @@ function palsuRerankScore(query, document) {
|
|
|
6000
6136
|
return hits / queryTokens.size;
|
|
6001
6137
|
}
|
|
6002
6138
|
export {
|
|
6139
|
+
CLAUDE_CODE_FALLBACK_VERSION,
|
|
6003
6140
|
CODEX_CLIENT_VERSION,
|
|
6004
6141
|
EventStream,
|
|
6005
6142
|
FAST_MODE_SUFFIX,
|
|
@@ -6019,6 +6156,8 @@ export {
|
|
|
6019
6156
|
formatChatError,
|
|
6020
6157
|
formatError,
|
|
6021
6158
|
formatErrorForDisplay,
|
|
6159
|
+
getClaudeCliUserAgent,
|
|
6160
|
+
getClaudeCodeVersion,
|
|
6022
6161
|
hasLoneSurrogate,
|
|
6023
6162
|
isHardBillingMessage,
|
|
6024
6163
|
isUsageLimitError,
|
|
@@ -6032,6 +6171,7 @@ export {
|
|
|
6032
6171
|
palsuThinking,
|
|
6033
6172
|
palsuToolCall,
|
|
6034
6173
|
parseFastModeRejection,
|
|
6174
|
+
pendingClaudeCodeVersionRefresh,
|
|
6035
6175
|
prewarmAnthropicCache,
|
|
6036
6176
|
providerRegistry,
|
|
6037
6177
|
redactText,
|