mirror of
https://github.com/siteboon/claudecodeui.git
synced 2026-07-02 02:22:55 +08: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.
|
* Codex SDK provider implementation.
|
||||||
*/
|
*/
|
||||||
export class CodexProvider extends BaseSdkProvider {
|
export class CodexProvider extends BaseSdkProvider {
|
||||||
|
private codexClientPromise: Promise<CodexSdkClient> | null = null;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super('codex', {
|
super('codex', {
|
||||||
supportsRuntimePermissionRequests: false,
|
supportsRuntimePermissionRequests: false,
|
||||||
@@ -111,8 +113,7 @@ export class CodexProvider extends BaseSdkProvider {
|
|||||||
stream: AsyncIterable<unknown>;
|
stream: AsyncIterable<unknown>;
|
||||||
stop: () => Promise<boolean>;
|
stop: () => Promise<boolean>;
|
||||||
}> {
|
}> {
|
||||||
const sdkModule = await this.loadCodexSdkModule();
|
const client = await this.getCodexClient();
|
||||||
const client = new sdkModule.Codex();
|
|
||||||
|
|
||||||
const threadOptions: Record<string, unknown> = {
|
const threadOptions: Record<string, unknown> = {
|
||||||
model: input.model,
|
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.
|
* Builds Codex prompt items. Images are sent as `local_image` entries for SDK-native image support.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user