Skip to content

Commit 0f70e47

Browse files
cleanup: remove dead code & simplify types
1 parent 7c4bc46 commit 0f70e47

2 files changed

Lines changed: 10 additions & 20 deletions

File tree

src/CodexAcpClient.ts

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {CODEX_API_KEY_ENV_VAR, isCodexAuthRequest, OPENAI_API_KEY_ENV_VAR} from "./CodexAuthMethod";
1+
import {CODEX_API_KEY_ENV_VAR, GatewayAuthMethod, isCodexAuthRequest, OPENAI_API_KEY_ENV_VAR} from "./CodexAuthMethod";
22
import type {EmbeddedResourceResource} from "@agentclientprotocol/sdk";
33
import * as acp from "@agentclientprotocol/sdk";
44
import {type McpServer, RequestError} from "@agentclientprotocol/sdk";
@@ -52,7 +52,7 @@ export const CUSTOM_GATEWAY_PROVIDER_ID = "custom-gateway";
5252
* ACP `LlmProtocol` values Codex can route through the custom gateway, mapped to
5353
* the Codex `wire_api`. Codex only supports the OpenAI Responses wire API here.
5454
*/
55-
const SUPPORTED_GATEWAY_PROTOCOLS: Record<string, GatewayConfig["config"]["wire_api"]> = {
55+
const SUPPORTED_GATEWAY_PROTOCOLS: Record<acp.LlmProtocol, WireApi> = {
5656
openai: "responses",
5757
};
5858

@@ -97,7 +97,7 @@ export class CodexAcpClient {
9797
if (!isCodexAuthRequest(authRequest)) {
9898
throw RequestError.invalidRequest();
9999
}
100-
100+
this.gatewayConfig = null;
101101
switch (authRequest.methodId) {
102102
case "api-key": {
103103
const apiKey = authRequest._meta?.["api-key"]?.apiKey ?? this.readApiKeyFromEnv();
@@ -106,15 +106,13 @@ export class CodexAcpClient {
106106
case "chat-gpt": {
107107
const accountResponse = await this.codexClient.accountRead({refreshToken: true});
108108
if (accountResponse.account?.type === "chatgpt") {
109-
this.gatewayConfig = null;
110109
return true;
111110
}
112111
const loginCompletedPromise = this.awaitNextLoginCompleted();
113112
const loginResponse = await this.codexClient.accountLogin({type: "chatgpt"});
114113
if (loginResponse.type == "chatgpt") {
115114
await open(loginResponse.authUrl);
116115
}
117-
this.gatewayConfig = null;
118116
const result = await loginCompletedPromise;
119117
return result.success;
120118
}
@@ -126,18 +124,13 @@ export class CodexAcpClient {
126124

127125
this.applyGatewayConfig({
128126
baseUrl: gatewaySettings.baseUrl,
127+
apiType: GatewayAuthMethod._meta.gateway.protocol,
129128
headers: gatewaySettings.headers,
130129
providerName: gatewaySettings.providerName,
131130
});
132131

133-
// Early return: model provider information will be sent to Codex later during the session creation
134132
return true;
135-
136133
}
137-
138-
// Reset the gateway config to null if another authentication method was used
139-
this.gatewayConfig = null;
140-
return false;
141134
}
142135

143136
private async authenticateWithApiKey(apiKey: string): Promise<Boolean> {
@@ -146,7 +139,6 @@ export class CodexAcpClient {
146139
type: "apiKey",
147140
apiKey,
148141
});
149-
this.gatewayConfig = null;
150142
const result = await loginCompletedPromise;
151143
return result.success;
152144
}
@@ -225,10 +217,6 @@ export class CodexAcpClient {
225217
return response.requiresOpenaiAuth && !response.account;
226218
}
227219

228-
hasGatewayAuth(): boolean {
229-
return this.gatewayConfig !== null;
230-
}
231-
232220
/**
233221
* Validates and stores custom gateway routing. Shared by the `gateway` auth
234222
* method and the ACP `providers/set` method. Throws `invalid_params` for an
@@ -238,9 +226,9 @@ export class CodexAcpClient {
238226
baseUrl: string;
239227
headers?: Record<string, string> | undefined;
240228
providerName?: string | undefined;
241-
apiType?: acp.LlmProtocol | undefined;
229+
apiType: acp.LlmProtocol;
242230
}): void {
243-
const apiType = params.apiType ?? "openai";
231+
const apiType = params.apiType;
244232
const wireApi = SUPPORTED_GATEWAY_PROTOCOLS[apiType];
245233
if (!wireApi) {
246234
throw RequestError.invalidParams(
@@ -931,13 +919,15 @@ function shouldDeduplicateMcpConflicts(): boolean {
931919
return !disabledByEnv;
932920
}
933921

922+
type WireApi = "responses";
923+
934924
interface GatewayConfig {
935925
modelProvider: string;
936926
config: {
937927
name: string,
938928
base_url: string,
939929
http_headers: Record<string, string>,
940-
wire_api: "responses"
930+
wire_api: WireApi
941931
}
942932
}
943933

src/CodexAuthMethod.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export interface ChatGPTAuthRequest extends AuthenticateRequest {
3434
methodId: "chat-gpt";
3535
}
3636

37-
const GatewayAuthMethod: AuthMethod = {
37+
export const GatewayAuthMethod = {
3838
id: "gateway",
3939
name: "Custom model gateway",
4040
description: "Use a custom gateway to authenticate and access models",

0 commit comments

Comments
 (0)