@kenkaiiii/gg-core 5.93.0 → 5.94.0

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
@@ -1,7 +1,6 @@
1
1
  import { ModelInfo } from './model-registry.cjs';
2
2
  export { ContextWindowOptions, DEFAULT_MAX_VIDEO_BYTES, HIDDEN_PROVIDERS, MODELS, ModelBilling, clearRuntimeModels, getAllModels, getAuthStorageKey, getAuthStorageKeys, getContextWindow, getDefaultModel, getDefaultThinkingLevel, getListedModels, getMaxThinkingLevel, getModel, getModelsForProvider, getProviderCatalog, getSummaryModel, getToolResultCharLimit, getVideoByteLimit, isHiddenProvider, isPaidModel, registerRuntimeModels, setProviderCatalog, usesOpenAICodexTransport, withoutPaidTier } from './model-registry.cjs';
3
3
  import { ThinkingLevel, Provider } from '@kenkaiiii/gg-ai';
4
- export { getClaudeCliUserAgent, getClaudeCodeVersion, pendingClaudeCodeVersionRefresh } from '@kenkaiiii/gg-ai';
5
4
  export { AppPaths, getAppPaths } from './paths.cjs';
6
5
 
7
6
  /** gg-ai's OPENROUTER_BASE_URL — where the openrouter transport goes with no override. */
@@ -225,6 +224,99 @@ interface OAuthLoginCallbacks {
225
224
  onStatus: (message: string) => void;
226
225
  }
227
226
 
227
+ interface ClaudeCodePlatformAsset {
228
+ url: string;
229
+ /** npm `dist.integrity`: "sha512-<base64>". */
230
+ integrity: string;
231
+ bin: string;
232
+ }
233
+ interface ClaudeCodeManifest {
234
+ sdkVersion: string;
235
+ claudeCodeVersion: string;
236
+ platforms: Record<string, ClaudeCodePlatformAsset>;
237
+ }
238
+ declare const CLAUDE_CODE_MANIFEST: ClaudeCodeManifest;
239
+ /** auth.json key for "signed in with Claude through Claude Code". Holds only the marker. */
240
+ declare const CLAUDE_CODE_AUTH_KEY = "anthropic-claude-code";
241
+ declare const CLAUDE_CODE_AUTH_MARKER: {
242
+ readonly via: "claude-code";
243
+ };
244
+ declare function isClaudeCodeAuthMarker(value: unknown): boolean;
245
+ /** An old GG Claude sign-in token (`sk-ant-oat…`). It no longer works; the user must sign in again. */
246
+ declare function isLegacyClaudeOAuth(value: unknown): boolean;
247
+ type ClaudeCodeInstallProgress = {
248
+ phase: "download";
249
+ receivedBytes: number;
250
+ totalBytes?: number;
251
+ } | {
252
+ phase: "verify";
253
+ } | {
254
+ phase: "extract";
255
+ };
256
+ interface ClaudeCodeRuntimeOptions {
257
+ /** Defaults to `~/.gg/claude-code`. */
258
+ home?: string;
259
+ manifest?: ClaudeCodeManifest;
260
+ /** Platform key in the manifest; detected from the running process by default. */
261
+ platformKey?: string;
262
+ }
263
+ interface EnsureClaudeCodeOptions extends ClaudeCodeRuntimeOptions {
264
+ onProgress?: (progress: ClaudeCodeInstallProgress) => void;
265
+ signal?: AbortSignal;
266
+ fetch?: typeof fetch;
267
+ }
268
+ interface ClaudeCodeRunOptions extends ClaudeCodeRuntimeOptions {
269
+ /** Executable to run instead of the installed binary (tests). */
270
+ binary?: string;
271
+ /** Arguments placed before the `auth …` arguments (tests run a script via node). */
272
+ binaryArgs?: string[];
273
+ signal?: AbortSignal;
274
+ /** How long sign-in waits for the browser URL before falling back to the paste-code page. */
275
+ browserWaitMs?: number;
276
+ }
277
+ interface ClaudeCodeAuthStatus {
278
+ loggedIn: boolean;
279
+ /** "claude.ai" for a Claude subscription. */
280
+ authMethod?: string;
281
+ email?: string;
282
+ subscriptionType?: string;
283
+ }
284
+ interface PlatformInfo {
285
+ platform: NodeJS.Platform;
286
+ arch: string;
287
+ musl: boolean;
288
+ }
289
+ /** Manifest key for a platform, or null where Claude Code has no build. */
290
+ declare function claudeCodePlatformKey(info?: PlatformInfo): string | null;
291
+ declare function claudeCodeHome(opts?: ClaudeCodeRuntimeOptions): string;
292
+ declare function claudeCodeConfigDir(opts?: ClaudeCodeRuntimeOptions): string;
293
+ /** Where the pinned binary lives once installed (it may not exist yet). */
294
+ declare function claudeCodeBinaryPath(opts?: ClaudeCodeRuntimeOptions): string;
295
+ /** The installed binary for the pinned version, or null when it still needs downloading. */
296
+ declare function resolveClaudeCodeBinary(opts?: ClaudeCodeRuntimeOptions): string | null;
297
+ /**
298
+ * Download, verify and unpack the pinned Claude Code binary if it isn't
299
+ * installed yet. Concurrent callers in this process share one download;
300
+ * other processes race safely because each unpacks into its own staging dir
301
+ * and only one rename wins.
302
+ */
303
+ declare function ensureClaudeCodeBinary(opts?: EnsureClaudeCodeOptions): Promise<string>;
304
+ /** Plain-language status line for an install progress event. */
305
+ declare function formatClaudeCodeInstallProgress(progress: ClaudeCodeInstallProgress): string;
306
+ /** Environment for every Claude Code process GG Coder starts: our own login, no stray keys. */
307
+ declare function claudeCodeEnv(opts?: ClaudeCodeRuntimeOptions, base?: NodeJS.ProcessEnv): Record<string, string>;
308
+ /** `claude auth status` for GG Coder's own login. Logged out when the binary is missing. */
309
+ declare function claudeCodeAuthStatus(opts?: ClaudeCodeRunOptions): Promise<ClaudeCodeAuthStatus>;
310
+ declare function logoutClaudeCode(opts?: ClaudeCodeRunOptions): Promise<void>;
311
+ /** The browser sign-in URL with Claude Code's localhost callback instead of the paste-code page. */
312
+ declare function claudeCodeCallbackUrl(manualUrl: string, captured: string): string | null;
313
+ /**
314
+ * Run `claude auth login` for GG Coder's own Claude login. The browser URL goes
315
+ * to `onOpenUrl`; Claude Code's localhost callback finishes sign-in, and a
316
+ * pasted code (from the fallback page) is accepted too.
317
+ */
318
+ declare function loginClaudeCode(callbacks: OAuthLoginCallbacks, opts?: ClaudeCodeRunOptions): Promise<void>;
319
+
228
320
  /**
229
321
  * Storage key for Kimi Code OAuth credentials. Kept distinct from the
230
322
  * `moonshot` API-key entry so a user can configure BOTH and we always
@@ -347,6 +439,16 @@ declare class AuthStorage {
347
439
  * satisfies it.
348
440
  */
349
441
  hasProviderAuth(provider: string): Promise<boolean>;
442
+ /** True when the user signed in with Claude through Claude Code (marker only, no token). */
443
+ hasClaudeCodeLogin(): Promise<boolean>;
444
+ /** Record a Claude Code sign-in. Claude Code keeps the token; auth.json gets only the marker. */
445
+ setClaudeCodeLogin(): Promise<void>;
446
+ /**
447
+ * Remove an old GG Claude sign-in token (`sk-ant-oat…`), if any. True when one
448
+ * was removed, so the caller can tell the user once to sign in with Claude again.
449
+ */
450
+ takeLegacyClaudeSignIn(): Promise<boolean>;
451
+ clearClaudeCodeLogin(): Promise<void>;
350
452
  /** Endpoint ids that currently have a `local:<id>` credential stored. */
351
453
  listLocalEndpointIds(): Promise<string[]>;
352
454
  /**
@@ -466,6 +568,82 @@ declare class NotLoggedInError extends Error {
466
568
  constructor(provider: string);
467
569
  }
468
570
 
571
+ type ClaudeCodeSignInOptions = EnsureClaudeCodeOptions & ClaudeCodeRunOptions;
572
+ /**
573
+ * "Sign in with Claude": download Claude Code if it is missing, run its browser
574
+ * sign-in, confirm it with `claude auth status`, then record the marker.
575
+ */
576
+ declare function signInWithClaudeCode(auth: Pick<AuthStorage, "setClaudeCodeLogin">, callbacks: OAuthLoginCallbacks, opts?: ClaudeCodeSignInOptions): Promise<ClaudeCodeAuthStatus>;
577
+ /** Sign out of Claude Code and drop the marker. The marker goes even if `claude auth logout` fails. */
578
+ declare function signOutOfClaudeCode(auth: Pick<AuthStorage, "clearClaudeCodeLogin">, opts?: ClaudeCodeRunOptions): Promise<void>;
579
+
580
+ type SubscriptionUsageProvider = "anthropic" | "openai" | "moonshot";
581
+ /** Providers whose usage endpoint we call with a token. Claude reports its own (claude-code/usage.ts). */
582
+ type FetchedSubscriptionUsageProvider = Exclude<SubscriptionUsageProvider, "anthropic">;
583
+ interface SubscriptionUsageWindow {
584
+ kind: "current" | "weekly";
585
+ label: string;
586
+ usedPercent: number;
587
+ /** Unix epoch milliseconds. */
588
+ resetsAt?: number;
589
+ }
590
+ interface SubscriptionUsageSnapshot {
591
+ provider: SubscriptionUsageProvider;
592
+ displayName: string;
593
+ windows: SubscriptionUsageWindow[];
594
+ fetchedAt: number;
595
+ }
596
+ declare class SubscriptionUsageError extends Error {
597
+ readonly status?: number | undefined;
598
+ readonly retryAfterMs?: number | undefined;
599
+ constructor(message: string, status?: number | undefined, retryAfterMs?: number | undefined);
600
+ }
601
+ type FetchFn = (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
602
+ interface FetchSubscriptionUsageOptions {
603
+ fetchFn?: FetchFn;
604
+ timeoutMs?: number;
605
+ now?: () => number;
606
+ }
607
+ /**
608
+ * Fetch subscription quota windows with an already-resolved OAuth credential.
609
+ * Tokens stay server-side: callers expose only the normalized percentages and
610
+ * reset timestamps to their UI.
611
+ */
612
+ declare function fetchSubscriptionUsage(provider: FetchedSubscriptionUsageProvider, credentials: Pick<OAuthCredentials, "accessToken" | "accountId">, options?: FetchSubscriptionUsageOptions): Promise<SubscriptionUsageSnapshot>;
613
+
614
+ /** The parts of the SDK's `rate_limit_event.rate_limit_info` the usage meter reads. */
615
+ interface ClaudeCodeRateLimitInfo {
616
+ rateLimitType?: string;
617
+ /** Fraction of the window used, 0–1. */
618
+ utilization?: number;
619
+ /** Unix epoch seconds. */
620
+ resetsAt?: number;
621
+ /** Not in the SDK types yet; carries every window the response reported. */
622
+ unifiedWindows?: Record<string, {
623
+ utilization?: number;
624
+ resetsAt?: number;
625
+ } | undefined>;
626
+ }
627
+ /**
628
+ * Fold one SDK rate-limit report into the last snapshot. A report can carry a
629
+ * single window, so windows it doesn't mention keep their previous values.
630
+ */
631
+ declare function mergeClaudeCodeRateLimit(info: ClaudeCodeRateLimitInfo, previous: SubscriptionUsageSnapshot | null, now?: number): SubscriptionUsageSnapshot;
632
+ /**
633
+ * The latest Claude subscription usage Claude Code reported, from any GG
634
+ * process on this machine. Windows whose reset time has passed are dropped:
635
+ * their old percentage no longer holds and the new one isn't known yet.
636
+ */
637
+ declare function readClaudeCodeUsage(opts?: ClaudeCodeRuntimeOptions & {
638
+ now?: number;
639
+ }): Promise<SubscriptionUsageSnapshot | null>;
640
+ /** Save an SDK rate-limit report so the usage meter (app or CLI) can show it. */
641
+ declare function recordClaudeCodeRateLimit(info: ClaudeCodeRateLimitInfo, opts?: ClaudeCodeRuntimeOptions & {
642
+ now?: number;
643
+ }): Promise<void>;
644
+ /** Forget saved usage, e.g. on sign-out, so another account never inherits it. */
645
+ declare function clearClaudeCodeUsage(opts?: ClaudeCodeRuntimeOptions): Promise<void>;
646
+
469
647
  /**
470
648
  * MiniMax runs two separate platforms, and a key only works on the one that
471
649
  * issued it: Global (platform.minimax.io) or Mainland China
@@ -577,46 +755,11 @@ declare function describeAuthMethods(provider: string): AuthMethodMeta[];
577
755
  */
578
756
  declare function authPriorityNote(provider: string): string | undefined;
579
757
 
580
- type SubscriptionUsageProvider = "anthropic" | "openai" | "moonshot";
581
- interface SubscriptionUsageWindow {
582
- kind: "current" | "weekly";
583
- label: string;
584
- usedPercent: number;
585
- /** Unix epoch milliseconds. */
586
- resetsAt?: number;
587
- }
588
- interface SubscriptionUsageSnapshot {
589
- provider: SubscriptionUsageProvider;
590
- displayName: string;
591
- windows: SubscriptionUsageWindow[];
592
- fetchedAt: number;
593
- }
594
- declare class SubscriptionUsageError extends Error {
595
- readonly status?: number | undefined;
596
- readonly retryAfterMs?: number | undefined;
597
- constructor(message: string, status?: number | undefined, retryAfterMs?: number | undefined);
598
- }
599
- type FetchFn = (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
600
- interface FetchSubscriptionUsageOptions {
601
- fetchFn?: FetchFn;
602
- timeoutMs?: number;
603
- now?: () => number;
604
- }
605
- /**
606
- * Fetch subscription quota windows with an already-resolved OAuth credential.
607
- * Tokens stay server-side: callers expose only the normalized percentages and
608
- * reset timestamps to their UI.
609
- */
610
- declare function fetchSubscriptionUsage(provider: SubscriptionUsageProvider, credentials: Pick<OAuthCredentials, "accessToken" | "accountId">, options?: FetchSubscriptionUsageOptions): Promise<SubscriptionUsageSnapshot>;
611
-
612
758
  declare function generatePKCE(): Promise<{
613
759
  verifier: string;
614
760
  challenge: string;
615
761
  }>;
616
762
 
617
- declare function loginAnthropic(callbacks: OAuthLoginCallbacks): Promise<OAuthCredentials>;
618
- declare function refreshAnthropicToken(refreshToken: string): Promise<OAuthCredentials>;
619
-
620
763
  declare function loginOpenAI(callbacks: OAuthLoginCallbacks): Promise<OAuthCredentials>;
621
764
  declare function refreshOpenAIToken(refreshToken: string): Promise<OAuthCredentials>;
622
765
 
@@ -907,4 +1050,4 @@ interface AutoUpdater {
907
1050
  }
908
1051
  declare function createAutoUpdater(config: AutoUpdateConfig): AutoUpdater;
909
1052
 
910
- export { AUTH_PROVIDERS, type ApiKeyVariant, type AuthMethod, type AuthMethodMeta, type AuthProviderMeta, AuthStorage, type AutoUpdateConfig, type AutoUpdater, DEFAULT_LOCAL_ENDPOINTS, type DiscoverOptions, type DiscoveryResult, type DualAuthProvider, FALLBACK_CONTEXT_WINDOW, GEMINI_API_KEY, GEMINI_API_KEY_BASE_URL, type InlineButton, LOCAL_API_KEY_PLACEHOLDER, LOCAL_AUTH_KEY_PREFIX, type LocalEndpoint, type LocalEndpointKind, type LocalEndpointProbe, type LocalModel, type LogLevel, MINIMAX_CN_BASE_URL, MINIMAX_GLOBAL_BASE_URL, MOONSHOT_OAUTH_KEY, ModelInfo, NotLoggedInError, type OAuthCredentials, type OAuthLoginCallbacks, OPENROUTER_DEFAULT_BASE_URL, PLAN_MODE_THINKING_CAP, type ParsedOpenRouterCatalog, type ProbeOptions, type ProgressCallback, SubscriptionUsageError, type SubscriptionUsageProvider, type SubscriptionUsageSnapshot, type SubscriptionUsageWindow, TelegramBot, type TelegramConfig, type TelegramMessage, type TelegramUpdate, type TelegramVoiceMessage, XAI_OAUTH_KEY, XIAOMI_CREDITS_KEY, XIAOMI_TOKEN_PLAN_BASE_URLS, authPriorityNote, clampThinkingForPlanMode, clearLocalDiscoveryCache, closeLogger, createAutoUpdater, decodeOggOpus, describeAuthMethods, detectMiniMaxBaseUrl, detectXiaomiTokenPlanBaseUrl, discoverLocalModels, downmixToMono, dualAuthProvider, dualAuthProviderByOAuthKey, endpointRoot, fetchSubscriptionUsage, findProbedModel, formatLocalModelId, generatePKCE, getAuthProvider, getLowestThinkingLevel, getNextThinkingLevel, getSessionId, getSupportedThinkingLevels, grokCliBaseUrl, grokCliHeaders, isGrokCliEndpoint, isKimiCodingEndpoint, isLocalModelId, isLoggerOpen, isModelLoaded, isThinkingLevelSupported, kimiCodeBaseUrl, kimiCodingHeaders, localAuthStorageKey, localModelShortName, log, loginAnthropic, loginGemini, loginKimi, loginOpenAI, loginXai, oauthStorageKey, ollamaServedContext, openLog, parseLocalModelId, parseOpenRouterCatalog, probeEndpoint, providerStorageKeys, readStoredBaseUrlSync, refreshAnthropicToken, refreshGeminiToken, refreshKimiToken, refreshOpenAIToken, refreshXaiToken, registerLogCleanup, resample, setProgressCallback, toModelInfo, transcribeVoice, withFileLock };
1053
+ export { AUTH_PROVIDERS, type ApiKeyVariant, type AuthMethod, type AuthMethodMeta, type AuthProviderMeta, AuthStorage, type AutoUpdateConfig, type AutoUpdater, CLAUDE_CODE_AUTH_KEY, CLAUDE_CODE_AUTH_MARKER, CLAUDE_CODE_MANIFEST, type ClaudeCodeAuthStatus, type ClaudeCodeInstallProgress, type ClaudeCodeManifest, type ClaudeCodePlatformAsset, type ClaudeCodeRateLimitInfo, type ClaudeCodeRunOptions, type ClaudeCodeRuntimeOptions, type ClaudeCodeSignInOptions, DEFAULT_LOCAL_ENDPOINTS, type DiscoverOptions, type DiscoveryResult, type DualAuthProvider, type EnsureClaudeCodeOptions, FALLBACK_CONTEXT_WINDOW, type FetchedSubscriptionUsageProvider, GEMINI_API_KEY, GEMINI_API_KEY_BASE_URL, type InlineButton, LOCAL_API_KEY_PLACEHOLDER, LOCAL_AUTH_KEY_PREFIX, type LocalEndpoint, type LocalEndpointKind, type LocalEndpointProbe, type LocalModel, type LogLevel, MINIMAX_CN_BASE_URL, MINIMAX_GLOBAL_BASE_URL, MOONSHOT_OAUTH_KEY, ModelInfo, NotLoggedInError, type OAuthCredentials, type OAuthLoginCallbacks, OPENROUTER_DEFAULT_BASE_URL, PLAN_MODE_THINKING_CAP, type ParsedOpenRouterCatalog, type ProbeOptions, type ProgressCallback, SubscriptionUsageError, type SubscriptionUsageProvider, type SubscriptionUsageSnapshot, type SubscriptionUsageWindow, TelegramBot, type TelegramConfig, type TelegramMessage, type TelegramUpdate, type TelegramVoiceMessage, XAI_OAUTH_KEY, XIAOMI_CREDITS_KEY, XIAOMI_TOKEN_PLAN_BASE_URLS, authPriorityNote, clampThinkingForPlanMode, claudeCodeAuthStatus, claudeCodeBinaryPath, claudeCodeCallbackUrl, claudeCodeConfigDir, claudeCodeEnv, claudeCodeHome, claudeCodePlatformKey, clearClaudeCodeUsage, clearLocalDiscoveryCache, closeLogger, createAutoUpdater, decodeOggOpus, describeAuthMethods, detectMiniMaxBaseUrl, detectXiaomiTokenPlanBaseUrl, discoverLocalModels, downmixToMono, dualAuthProvider, dualAuthProviderByOAuthKey, endpointRoot, ensureClaudeCodeBinary, fetchSubscriptionUsage, findProbedModel, formatClaudeCodeInstallProgress, formatLocalModelId, generatePKCE, getAuthProvider, getLowestThinkingLevel, getNextThinkingLevel, getSessionId, getSupportedThinkingLevels, grokCliBaseUrl, grokCliHeaders, isClaudeCodeAuthMarker, isGrokCliEndpoint, isKimiCodingEndpoint, isLegacyClaudeOAuth, isLocalModelId, isLoggerOpen, isModelLoaded, isThinkingLevelSupported, kimiCodeBaseUrl, kimiCodingHeaders, localAuthStorageKey, localModelShortName, log, loginClaudeCode, loginGemini, loginKimi, loginOpenAI, loginXai, logoutClaudeCode, mergeClaudeCodeRateLimit, oauthStorageKey, ollamaServedContext, openLog, parseLocalModelId, parseOpenRouterCatalog, probeEndpoint, providerStorageKeys, readClaudeCodeUsage, readStoredBaseUrlSync, recordClaudeCodeRateLimit, refreshGeminiToken, refreshKimiToken, refreshOpenAIToken, refreshXaiToken, registerLogCleanup, resample, resolveClaudeCodeBinary, setProgressCallback, signInWithClaudeCode, signOutOfClaudeCode, toModelInfo, transcribeVoice, withFileLock };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import { ModelInfo } from './model-registry.js';
2
2
  export { ContextWindowOptions, DEFAULT_MAX_VIDEO_BYTES, HIDDEN_PROVIDERS, MODELS, ModelBilling, clearRuntimeModels, getAllModels, getAuthStorageKey, getAuthStorageKeys, getContextWindow, getDefaultModel, getDefaultThinkingLevel, getListedModels, getMaxThinkingLevel, getModel, getModelsForProvider, getProviderCatalog, getSummaryModel, getToolResultCharLimit, getVideoByteLimit, isHiddenProvider, isPaidModel, registerRuntimeModels, setProviderCatalog, usesOpenAICodexTransport, withoutPaidTier } from './model-registry.js';
3
3
  import { ThinkingLevel, Provider } from '@kenkaiiii/gg-ai';
4
- export { getClaudeCliUserAgent, getClaudeCodeVersion, pendingClaudeCodeVersionRefresh } from '@kenkaiiii/gg-ai';
5
4
  export { AppPaths, getAppPaths } from './paths.js';
6
5
 
7
6
  /** gg-ai's OPENROUTER_BASE_URL — where the openrouter transport goes with no override. */
@@ -225,6 +224,99 @@ interface OAuthLoginCallbacks {
225
224
  onStatus: (message: string) => void;
226
225
  }
227
226
 
227
+ interface ClaudeCodePlatformAsset {
228
+ url: string;
229
+ /** npm `dist.integrity`: "sha512-<base64>". */
230
+ integrity: string;
231
+ bin: string;
232
+ }
233
+ interface ClaudeCodeManifest {
234
+ sdkVersion: string;
235
+ claudeCodeVersion: string;
236
+ platforms: Record<string, ClaudeCodePlatformAsset>;
237
+ }
238
+ declare const CLAUDE_CODE_MANIFEST: ClaudeCodeManifest;
239
+ /** auth.json key for "signed in with Claude through Claude Code". Holds only the marker. */
240
+ declare const CLAUDE_CODE_AUTH_KEY = "anthropic-claude-code";
241
+ declare const CLAUDE_CODE_AUTH_MARKER: {
242
+ readonly via: "claude-code";
243
+ };
244
+ declare function isClaudeCodeAuthMarker(value: unknown): boolean;
245
+ /** An old GG Claude sign-in token (`sk-ant-oat…`). It no longer works; the user must sign in again. */
246
+ declare function isLegacyClaudeOAuth(value: unknown): boolean;
247
+ type ClaudeCodeInstallProgress = {
248
+ phase: "download";
249
+ receivedBytes: number;
250
+ totalBytes?: number;
251
+ } | {
252
+ phase: "verify";
253
+ } | {
254
+ phase: "extract";
255
+ };
256
+ interface ClaudeCodeRuntimeOptions {
257
+ /** Defaults to `~/.gg/claude-code`. */
258
+ home?: string;
259
+ manifest?: ClaudeCodeManifest;
260
+ /** Platform key in the manifest; detected from the running process by default. */
261
+ platformKey?: string;
262
+ }
263
+ interface EnsureClaudeCodeOptions extends ClaudeCodeRuntimeOptions {
264
+ onProgress?: (progress: ClaudeCodeInstallProgress) => void;
265
+ signal?: AbortSignal;
266
+ fetch?: typeof fetch;
267
+ }
268
+ interface ClaudeCodeRunOptions extends ClaudeCodeRuntimeOptions {
269
+ /** Executable to run instead of the installed binary (tests). */
270
+ binary?: string;
271
+ /** Arguments placed before the `auth …` arguments (tests run a script via node). */
272
+ binaryArgs?: string[];
273
+ signal?: AbortSignal;
274
+ /** How long sign-in waits for the browser URL before falling back to the paste-code page. */
275
+ browserWaitMs?: number;
276
+ }
277
+ interface ClaudeCodeAuthStatus {
278
+ loggedIn: boolean;
279
+ /** "claude.ai" for a Claude subscription. */
280
+ authMethod?: string;
281
+ email?: string;
282
+ subscriptionType?: string;
283
+ }
284
+ interface PlatformInfo {
285
+ platform: NodeJS.Platform;
286
+ arch: string;
287
+ musl: boolean;
288
+ }
289
+ /** Manifest key for a platform, or null where Claude Code has no build. */
290
+ declare function claudeCodePlatformKey(info?: PlatformInfo): string | null;
291
+ declare function claudeCodeHome(opts?: ClaudeCodeRuntimeOptions): string;
292
+ declare function claudeCodeConfigDir(opts?: ClaudeCodeRuntimeOptions): string;
293
+ /** Where the pinned binary lives once installed (it may not exist yet). */
294
+ declare function claudeCodeBinaryPath(opts?: ClaudeCodeRuntimeOptions): string;
295
+ /** The installed binary for the pinned version, or null when it still needs downloading. */
296
+ declare function resolveClaudeCodeBinary(opts?: ClaudeCodeRuntimeOptions): string | null;
297
+ /**
298
+ * Download, verify and unpack the pinned Claude Code binary if it isn't
299
+ * installed yet. Concurrent callers in this process share one download;
300
+ * other processes race safely because each unpacks into its own staging dir
301
+ * and only one rename wins.
302
+ */
303
+ declare function ensureClaudeCodeBinary(opts?: EnsureClaudeCodeOptions): Promise<string>;
304
+ /** Plain-language status line for an install progress event. */
305
+ declare function formatClaudeCodeInstallProgress(progress: ClaudeCodeInstallProgress): string;
306
+ /** Environment for every Claude Code process GG Coder starts: our own login, no stray keys. */
307
+ declare function claudeCodeEnv(opts?: ClaudeCodeRuntimeOptions, base?: NodeJS.ProcessEnv): Record<string, string>;
308
+ /** `claude auth status` for GG Coder's own login. Logged out when the binary is missing. */
309
+ declare function claudeCodeAuthStatus(opts?: ClaudeCodeRunOptions): Promise<ClaudeCodeAuthStatus>;
310
+ declare function logoutClaudeCode(opts?: ClaudeCodeRunOptions): Promise<void>;
311
+ /** The browser sign-in URL with Claude Code's localhost callback instead of the paste-code page. */
312
+ declare function claudeCodeCallbackUrl(manualUrl: string, captured: string): string | null;
313
+ /**
314
+ * Run `claude auth login` for GG Coder's own Claude login. The browser URL goes
315
+ * to `onOpenUrl`; Claude Code's localhost callback finishes sign-in, and a
316
+ * pasted code (from the fallback page) is accepted too.
317
+ */
318
+ declare function loginClaudeCode(callbacks: OAuthLoginCallbacks, opts?: ClaudeCodeRunOptions): Promise<void>;
319
+
228
320
  /**
229
321
  * Storage key for Kimi Code OAuth credentials. Kept distinct from the
230
322
  * `moonshot` API-key entry so a user can configure BOTH and we always
@@ -347,6 +439,16 @@ declare class AuthStorage {
347
439
  * satisfies it.
348
440
  */
349
441
  hasProviderAuth(provider: string): Promise<boolean>;
442
+ /** True when the user signed in with Claude through Claude Code (marker only, no token). */
443
+ hasClaudeCodeLogin(): Promise<boolean>;
444
+ /** Record a Claude Code sign-in. Claude Code keeps the token; auth.json gets only the marker. */
445
+ setClaudeCodeLogin(): Promise<void>;
446
+ /**
447
+ * Remove an old GG Claude sign-in token (`sk-ant-oat…`), if any. True when one
448
+ * was removed, so the caller can tell the user once to sign in with Claude again.
449
+ */
450
+ takeLegacyClaudeSignIn(): Promise<boolean>;
451
+ clearClaudeCodeLogin(): Promise<void>;
350
452
  /** Endpoint ids that currently have a `local:<id>` credential stored. */
351
453
  listLocalEndpointIds(): Promise<string[]>;
352
454
  /**
@@ -466,6 +568,82 @@ declare class NotLoggedInError extends Error {
466
568
  constructor(provider: string);
467
569
  }
468
570
 
571
+ type ClaudeCodeSignInOptions = EnsureClaudeCodeOptions & ClaudeCodeRunOptions;
572
+ /**
573
+ * "Sign in with Claude": download Claude Code if it is missing, run its browser
574
+ * sign-in, confirm it with `claude auth status`, then record the marker.
575
+ */
576
+ declare function signInWithClaudeCode(auth: Pick<AuthStorage, "setClaudeCodeLogin">, callbacks: OAuthLoginCallbacks, opts?: ClaudeCodeSignInOptions): Promise<ClaudeCodeAuthStatus>;
577
+ /** Sign out of Claude Code and drop the marker. The marker goes even if `claude auth logout` fails. */
578
+ declare function signOutOfClaudeCode(auth: Pick<AuthStorage, "clearClaudeCodeLogin">, opts?: ClaudeCodeRunOptions): Promise<void>;
579
+
580
+ type SubscriptionUsageProvider = "anthropic" | "openai" | "moonshot";
581
+ /** Providers whose usage endpoint we call with a token. Claude reports its own (claude-code/usage.ts). */
582
+ type FetchedSubscriptionUsageProvider = Exclude<SubscriptionUsageProvider, "anthropic">;
583
+ interface SubscriptionUsageWindow {
584
+ kind: "current" | "weekly";
585
+ label: string;
586
+ usedPercent: number;
587
+ /** Unix epoch milliseconds. */
588
+ resetsAt?: number;
589
+ }
590
+ interface SubscriptionUsageSnapshot {
591
+ provider: SubscriptionUsageProvider;
592
+ displayName: string;
593
+ windows: SubscriptionUsageWindow[];
594
+ fetchedAt: number;
595
+ }
596
+ declare class SubscriptionUsageError extends Error {
597
+ readonly status?: number | undefined;
598
+ readonly retryAfterMs?: number | undefined;
599
+ constructor(message: string, status?: number | undefined, retryAfterMs?: number | undefined);
600
+ }
601
+ type FetchFn = (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
602
+ interface FetchSubscriptionUsageOptions {
603
+ fetchFn?: FetchFn;
604
+ timeoutMs?: number;
605
+ now?: () => number;
606
+ }
607
+ /**
608
+ * Fetch subscription quota windows with an already-resolved OAuth credential.
609
+ * Tokens stay server-side: callers expose only the normalized percentages and
610
+ * reset timestamps to their UI.
611
+ */
612
+ declare function fetchSubscriptionUsage(provider: FetchedSubscriptionUsageProvider, credentials: Pick<OAuthCredentials, "accessToken" | "accountId">, options?: FetchSubscriptionUsageOptions): Promise<SubscriptionUsageSnapshot>;
613
+
614
+ /** The parts of the SDK's `rate_limit_event.rate_limit_info` the usage meter reads. */
615
+ interface ClaudeCodeRateLimitInfo {
616
+ rateLimitType?: string;
617
+ /** Fraction of the window used, 0–1. */
618
+ utilization?: number;
619
+ /** Unix epoch seconds. */
620
+ resetsAt?: number;
621
+ /** Not in the SDK types yet; carries every window the response reported. */
622
+ unifiedWindows?: Record<string, {
623
+ utilization?: number;
624
+ resetsAt?: number;
625
+ } | undefined>;
626
+ }
627
+ /**
628
+ * Fold one SDK rate-limit report into the last snapshot. A report can carry a
629
+ * single window, so windows it doesn't mention keep their previous values.
630
+ */
631
+ declare function mergeClaudeCodeRateLimit(info: ClaudeCodeRateLimitInfo, previous: SubscriptionUsageSnapshot | null, now?: number): SubscriptionUsageSnapshot;
632
+ /**
633
+ * The latest Claude subscription usage Claude Code reported, from any GG
634
+ * process on this machine. Windows whose reset time has passed are dropped:
635
+ * their old percentage no longer holds and the new one isn't known yet.
636
+ */
637
+ declare function readClaudeCodeUsage(opts?: ClaudeCodeRuntimeOptions & {
638
+ now?: number;
639
+ }): Promise<SubscriptionUsageSnapshot | null>;
640
+ /** Save an SDK rate-limit report so the usage meter (app or CLI) can show it. */
641
+ declare function recordClaudeCodeRateLimit(info: ClaudeCodeRateLimitInfo, opts?: ClaudeCodeRuntimeOptions & {
642
+ now?: number;
643
+ }): Promise<void>;
644
+ /** Forget saved usage, e.g. on sign-out, so another account never inherits it. */
645
+ declare function clearClaudeCodeUsage(opts?: ClaudeCodeRuntimeOptions): Promise<void>;
646
+
469
647
  /**
470
648
  * MiniMax runs two separate platforms, and a key only works on the one that
471
649
  * issued it: Global (platform.minimax.io) or Mainland China
@@ -577,46 +755,11 @@ declare function describeAuthMethods(provider: string): AuthMethodMeta[];
577
755
  */
578
756
  declare function authPriorityNote(provider: string): string | undefined;
579
757
 
580
- type SubscriptionUsageProvider = "anthropic" | "openai" | "moonshot";
581
- interface SubscriptionUsageWindow {
582
- kind: "current" | "weekly";
583
- label: string;
584
- usedPercent: number;
585
- /** Unix epoch milliseconds. */
586
- resetsAt?: number;
587
- }
588
- interface SubscriptionUsageSnapshot {
589
- provider: SubscriptionUsageProvider;
590
- displayName: string;
591
- windows: SubscriptionUsageWindow[];
592
- fetchedAt: number;
593
- }
594
- declare class SubscriptionUsageError extends Error {
595
- readonly status?: number | undefined;
596
- readonly retryAfterMs?: number | undefined;
597
- constructor(message: string, status?: number | undefined, retryAfterMs?: number | undefined);
598
- }
599
- type FetchFn = (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
600
- interface FetchSubscriptionUsageOptions {
601
- fetchFn?: FetchFn;
602
- timeoutMs?: number;
603
- now?: () => number;
604
- }
605
- /**
606
- * Fetch subscription quota windows with an already-resolved OAuth credential.
607
- * Tokens stay server-side: callers expose only the normalized percentages and
608
- * reset timestamps to their UI.
609
- */
610
- declare function fetchSubscriptionUsage(provider: SubscriptionUsageProvider, credentials: Pick<OAuthCredentials, "accessToken" | "accountId">, options?: FetchSubscriptionUsageOptions): Promise<SubscriptionUsageSnapshot>;
611
-
612
758
  declare function generatePKCE(): Promise<{
613
759
  verifier: string;
614
760
  challenge: string;
615
761
  }>;
616
762
 
617
- declare function loginAnthropic(callbacks: OAuthLoginCallbacks): Promise<OAuthCredentials>;
618
- declare function refreshAnthropicToken(refreshToken: string): Promise<OAuthCredentials>;
619
-
620
763
  declare function loginOpenAI(callbacks: OAuthLoginCallbacks): Promise<OAuthCredentials>;
621
764
  declare function refreshOpenAIToken(refreshToken: string): Promise<OAuthCredentials>;
622
765
 
@@ -907,4 +1050,4 @@ interface AutoUpdater {
907
1050
  }
908
1051
  declare function createAutoUpdater(config: AutoUpdateConfig): AutoUpdater;
909
1052
 
910
- export { AUTH_PROVIDERS, type ApiKeyVariant, type AuthMethod, type AuthMethodMeta, type AuthProviderMeta, AuthStorage, type AutoUpdateConfig, type AutoUpdater, DEFAULT_LOCAL_ENDPOINTS, type DiscoverOptions, type DiscoveryResult, type DualAuthProvider, FALLBACK_CONTEXT_WINDOW, GEMINI_API_KEY, GEMINI_API_KEY_BASE_URL, type InlineButton, LOCAL_API_KEY_PLACEHOLDER, LOCAL_AUTH_KEY_PREFIX, type LocalEndpoint, type LocalEndpointKind, type LocalEndpointProbe, type LocalModel, type LogLevel, MINIMAX_CN_BASE_URL, MINIMAX_GLOBAL_BASE_URL, MOONSHOT_OAUTH_KEY, ModelInfo, NotLoggedInError, type OAuthCredentials, type OAuthLoginCallbacks, OPENROUTER_DEFAULT_BASE_URL, PLAN_MODE_THINKING_CAP, type ParsedOpenRouterCatalog, type ProbeOptions, type ProgressCallback, SubscriptionUsageError, type SubscriptionUsageProvider, type SubscriptionUsageSnapshot, type SubscriptionUsageWindow, TelegramBot, type TelegramConfig, type TelegramMessage, type TelegramUpdate, type TelegramVoiceMessage, XAI_OAUTH_KEY, XIAOMI_CREDITS_KEY, XIAOMI_TOKEN_PLAN_BASE_URLS, authPriorityNote, clampThinkingForPlanMode, clearLocalDiscoveryCache, closeLogger, createAutoUpdater, decodeOggOpus, describeAuthMethods, detectMiniMaxBaseUrl, detectXiaomiTokenPlanBaseUrl, discoverLocalModels, downmixToMono, dualAuthProvider, dualAuthProviderByOAuthKey, endpointRoot, fetchSubscriptionUsage, findProbedModel, formatLocalModelId, generatePKCE, getAuthProvider, getLowestThinkingLevel, getNextThinkingLevel, getSessionId, getSupportedThinkingLevels, grokCliBaseUrl, grokCliHeaders, isGrokCliEndpoint, isKimiCodingEndpoint, isLocalModelId, isLoggerOpen, isModelLoaded, isThinkingLevelSupported, kimiCodeBaseUrl, kimiCodingHeaders, localAuthStorageKey, localModelShortName, log, loginAnthropic, loginGemini, loginKimi, loginOpenAI, loginXai, oauthStorageKey, ollamaServedContext, openLog, parseLocalModelId, parseOpenRouterCatalog, probeEndpoint, providerStorageKeys, readStoredBaseUrlSync, refreshAnthropicToken, refreshGeminiToken, refreshKimiToken, refreshOpenAIToken, refreshXaiToken, registerLogCleanup, resample, setProgressCallback, toModelInfo, transcribeVoice, withFileLock };
1053
+ export { AUTH_PROVIDERS, type ApiKeyVariant, type AuthMethod, type AuthMethodMeta, type AuthProviderMeta, AuthStorage, type AutoUpdateConfig, type AutoUpdater, CLAUDE_CODE_AUTH_KEY, CLAUDE_CODE_AUTH_MARKER, CLAUDE_CODE_MANIFEST, type ClaudeCodeAuthStatus, type ClaudeCodeInstallProgress, type ClaudeCodeManifest, type ClaudeCodePlatformAsset, type ClaudeCodeRateLimitInfo, type ClaudeCodeRunOptions, type ClaudeCodeRuntimeOptions, type ClaudeCodeSignInOptions, DEFAULT_LOCAL_ENDPOINTS, type DiscoverOptions, type DiscoveryResult, type DualAuthProvider, type EnsureClaudeCodeOptions, FALLBACK_CONTEXT_WINDOW, type FetchedSubscriptionUsageProvider, GEMINI_API_KEY, GEMINI_API_KEY_BASE_URL, type InlineButton, LOCAL_API_KEY_PLACEHOLDER, LOCAL_AUTH_KEY_PREFIX, type LocalEndpoint, type LocalEndpointKind, type LocalEndpointProbe, type LocalModel, type LogLevel, MINIMAX_CN_BASE_URL, MINIMAX_GLOBAL_BASE_URL, MOONSHOT_OAUTH_KEY, ModelInfo, NotLoggedInError, type OAuthCredentials, type OAuthLoginCallbacks, OPENROUTER_DEFAULT_BASE_URL, PLAN_MODE_THINKING_CAP, type ParsedOpenRouterCatalog, type ProbeOptions, type ProgressCallback, SubscriptionUsageError, type SubscriptionUsageProvider, type SubscriptionUsageSnapshot, type SubscriptionUsageWindow, TelegramBot, type TelegramConfig, type TelegramMessage, type TelegramUpdate, type TelegramVoiceMessage, XAI_OAUTH_KEY, XIAOMI_CREDITS_KEY, XIAOMI_TOKEN_PLAN_BASE_URLS, authPriorityNote, clampThinkingForPlanMode, claudeCodeAuthStatus, claudeCodeBinaryPath, claudeCodeCallbackUrl, claudeCodeConfigDir, claudeCodeEnv, claudeCodeHome, claudeCodePlatformKey, clearClaudeCodeUsage, clearLocalDiscoveryCache, closeLogger, createAutoUpdater, decodeOggOpus, describeAuthMethods, detectMiniMaxBaseUrl, detectXiaomiTokenPlanBaseUrl, discoverLocalModels, downmixToMono, dualAuthProvider, dualAuthProviderByOAuthKey, endpointRoot, ensureClaudeCodeBinary, fetchSubscriptionUsage, findProbedModel, formatClaudeCodeInstallProgress, formatLocalModelId, generatePKCE, getAuthProvider, getLowestThinkingLevel, getNextThinkingLevel, getSessionId, getSupportedThinkingLevels, grokCliBaseUrl, grokCliHeaders, isClaudeCodeAuthMarker, isGrokCliEndpoint, isKimiCodingEndpoint, isLegacyClaudeOAuth, isLocalModelId, isLoggerOpen, isModelLoaded, isThinkingLevelSupported, kimiCodeBaseUrl, kimiCodingHeaders, localAuthStorageKey, localModelShortName, log, loginClaudeCode, loginGemini, loginKimi, loginOpenAI, loginXai, logoutClaudeCode, mergeClaudeCodeRateLimit, oauthStorageKey, ollamaServedContext, openLog, parseLocalModelId, parseOpenRouterCatalog, probeEndpoint, providerStorageKeys, readClaudeCodeUsage, readStoredBaseUrlSync, recordClaudeCodeRateLimit, refreshGeminiToken, refreshKimiToken, refreshOpenAIToken, refreshXaiToken, registerLogCleanup, resample, resolveClaudeCodeBinary, setProgressCallback, signInWithClaudeCode, signOutOfClaudeCode, toModelInfo, transcribeVoice, withFileLock };