Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

1.8 KB
Raw Blame
/**
 * 识别需要用户重新连接 ChatGPT 账号的 OpenAI OAuth 失效原因。
 *
 * 这些字符串来自 Codex app-server / CLI 或 Claude 的 ChatGPT bridge,不应直接展示
 * 给用户;renderer 统一把它们收口为“OpenAI 连接需要更新”的可恢复状态。
 */
export function isCodexOAuthReconnectRequired(reason: string | undefined): boolean {
  if (!reason) return false;
  // "access token could not be refreshed" 覆盖 codex-rs 永久刷新失败的整个文案家族
  // (revoked / expired / already used / account mismatch / unknown)——这些句式只在
  // refresh token 已不可用时产生,重试必然无效,只能重新连接。
  return /app_session_terminated|token_invalidated|token_revoked|refresh_token_reused|Your session has ended|authentication token has been invalidated|authentication token has been revoked|refresh token was already used|refresh_token.*already used|access token could not be refreshed|refresh token (?:was|has been) revoked|bridge auth unavailable for chatgpt\//i.test(
    reason,
  );
}

export type CodexCredentialScope = 'system-shared' | 'instance-isolated' | 'unknown';

export function codexRecoveryDescriptionKey(scope: CodexCredentialScope): string {
  if (scope === 'system-shared') return 'chatgptAuthRecovery.systemSharedInvalidated';
  if (scope === 'instance-isolated') return 'chatgptAuthRecovery.instanceIsolatedInvalidated';
  return 'chatgptAuthRecovery.unknownInvalidated';
}

export function codexRecoveryActionKey(
  scope: CodexCredentialScope,
  check: 'idle' | 'checking' | 'failed',
): string {
  if (check === 'checking') return 'chatgptAuthRecovery.checking';
  if (check === 'failed') return 'chatgptAuthRecovery.recheck';
  return scope === 'system-shared' ? 'chatgptAuthRecovery.openApp' : 'chatgptAuthRecovery.relogin';
}