|
- export const CODEX_CREDENTIAL_MODE = {
- API_KEY: 'api_key',
- OAUTH: 'oauth',
- };
-
- export function isCodexOAuthCredential(rawKey) {
- const trimmed = String(rawKey || '').trim();
- if (!trimmed.startsWith('{')) {
- return false;
- }
-
- try {
- const parsed = JSON.parse(trimmed);
- if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
- return false;
- }
-
- return (
- String(parsed.access_token || '').trim() !== '' &&
- String(parsed.account_id || '').trim() !== ''
- );
- } catch {
- return false;
- }
- }
-
- export function detectCodexCredentialMode(rawKey) {
- return isCodexOAuthCredential(rawKey)
- ? CODEX_CREDENTIAL_MODE.OAUTH
- : CODEX_CREDENTIAL_MODE.API_KEY;
- }
|