mirror of
https://github.com/siteboon/claudecodeui.git
synced 2026-05-16 09:13:36 +00:00
refactor: optimize CodexProvider to use a shared SDK client instance
This commit is contained in:
@@ -57,6 +57,8 @@ type CodexSdkModule = {
|
||||
* Codex SDK provider implementation.
|
||||
*/
|
||||
export class CodexProvider extends BaseSdkProvider {
|
||||
private codexClientPromise: Promise<CodexSdkClient> | null = null;
|
||||
|
||||
constructor() {
|
||||
super('codex', {
|
||||
supportsRuntimePermissionRequests: false,
|
||||
@@ -111,8 +113,7 @@ export class CodexProvider extends BaseSdkProvider {
|
||||
stream: AsyncIterable<unknown>;
|
||||
stop: () => Promise<boolean>;
|
||||
}> {
|
||||
const sdkModule = await this.loadCodexSdkModule();
|
||||
const client = new sdkModule.Codex();
|
||||
const client = await this.getCodexClient();
|
||||
|
||||
const threadOptions: Record<string, unknown> = {
|
||||
model: input.model,
|
||||
@@ -139,6 +140,22 @@ export class CodexProvider extends BaseSdkProvider {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a shared Codex SDK client instance for this provider.
|
||||
*/
|
||||
private async getCodexClient(): Promise<CodexSdkClient> {
|
||||
if (!this.codexClientPromise) {
|
||||
this.codexClientPromise = this.loadCodexSdkModule()
|
||||
.then((sdkModule) => new sdkModule.Codex())
|
||||
.catch((error) => {
|
||||
this.codexClientPromise = null;
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
|
||||
return this.codexClientPromise;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds Codex prompt items. Images are sent as `local_image` entries for SDK-native image support.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user