feat: enhance Codex authentication and API key management

- Introduced a new method to check Codex authentication status, allowing for better handling of API keys and OAuth tokens.
- Updated API key management to include OpenAI, enabling users to manage their keys more effectively.
- Enhanced the CodexProvider to support session ID tracking and deduplication of text blocks in assistant messages.
- Improved error handling and logging in authentication routes, providing clearer feedback to users.

These changes improve the overall user experience and security of the Codex integration, ensuring smoother authentication processes and better management of API keys.
This commit is contained in:
DhanushSantosh
2026-01-07 22:49:30 +05:30
parent 2250367ddc
commit 24ea10e818
18 changed files with 837 additions and 61 deletions

View File

@@ -0,0 +1,100 @@
/**
* Codex CLI Model IDs
* Based on OpenAI Codex CLI official models
* Reference: https://developers.openai.com/codex/models/
*/
export type CodexModelId =
| 'gpt-5.2-codex' // Most advanced agentic coding model for complex software engineering
| 'gpt-5-codex' // Purpose-built for Codex CLI with versatile tool use
| 'gpt-5-codex-mini' // Faster workflows optimized for low-latency code Q&A and editing
| 'codex-1' // Version of o3 optimized for software engineering
| 'codex-mini-latest' // Version of o4-mini for Codex, optimized for faster workflows
| 'gpt-5'; // GPT-5 base flagship model
/**
* Codex model metadata
*/
export interface CodexModelConfig {
id: CodexModelId;
label: string;
description: string;
hasThinking: boolean;
/** Whether the model supports vision/image inputs */
supportsVision: boolean;
}
/**
* Complete model map for Codex CLI
*/
export const CODEX_MODEL_CONFIG_MAP: Record<CodexModelId, CodexModelConfig> = {
'gpt-5.2-codex': {
id: 'gpt-5.2-codex',
label: 'GPT-5.2-Codex',
description: 'Most advanced agentic coding model for complex software engineering',
hasThinking: true,
supportsVision: true, // GPT-5 supports vision
},
'gpt-5-codex': {
id: 'gpt-5-codex',
label: 'GPT-5-Codex',
description: 'Purpose-built for Codex CLI with versatile tool use',
hasThinking: true,
supportsVision: true,
},
'gpt-5-codex-mini': {
id: 'gpt-5-codex-mini',
label: 'GPT-5-Codex-Mini',
description: 'Faster workflows optimized for low-latency code Q&A and editing',
hasThinking: false,
supportsVision: true,
},
'codex-1': {
id: 'codex-1',
label: 'Codex-1',
description: 'Version of o3 optimized for software engineering',
hasThinking: true,
supportsVision: true,
},
'codex-mini-latest': {
id: 'codex-mini-latest',
label: 'Codex-Mini-Latest',
description: 'Version of o4-mini for Codex, optimized for faster workflows',
hasThinking: false,
supportsVision: true,
},
'gpt-5': {
id: 'gpt-5',
label: 'GPT-5',
description: 'GPT-5 base flagship model',
hasThinking: true,
supportsVision: true,
},
};
/**
* Helper: Check if model has thinking capability
*/
export function codexModelHasThinking(modelId: CodexModelId): boolean {
return CODEX_MODEL_CONFIG_MAP[modelId]?.hasThinking ?? false;
}
/**
* Helper: Get display name for model
*/
export function getCodexModelLabel(modelId: CodexModelId): string {
return CODEX_MODEL_CONFIG_MAP[modelId]?.label ?? modelId;
}
/**
* Helper: Get all Codex model IDs
*/
export function getAllCodexModelIds(): CodexModelId[] {
return Object.keys(CODEX_MODEL_CONFIG_MAP) as CodexModelId[];
}
/**
* Helper: Check if Codex model supports vision
*/
export function codexModelSupportsVision(modelId: CodexModelId): boolean {
return CODEX_MODEL_CONFIG_MAP[modelId]?.supportsVision ?? true;
}

View File

@@ -42,3 +42,11 @@ export interface CodexCliConfig {
/** List of enabled models */
models?: string[];
}
/** Codex authentication status */
export interface CodexAuthStatus {
authenticated: boolean;
method: 'oauth' | 'api_key' | 'none';
hasCredentialsFile?: boolean;
error?: string;
}

View File

@@ -21,7 +21,13 @@ export type {
} from './provider.js';
// Codex CLI types
export type { CodexSandboxMode, CodexApprovalPolicy, CodexCliConfig } from './codex.js';
export type {
CodexSandboxMode,
CodexApprovalPolicy,
CodexCliConfig,
CodexAuthStatus,
} from './codex.js';
export * from './codex-models.js';
// Feature types
export type { Feature, FeatureImagePath, FeatureTextFilePath, FeatureStatus } from './feature.js';