-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathCodexAuthMethod.ts
More file actions
70 lines (60 loc) · 1.88 KB
/
Copy pathCodexAuthMethod.ts
File metadata and controls
70 lines (60 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import type {AuthenticateRequest, AuthMethod, ClientCapabilities} from "@agentclientprotocol/sdk";
const ApiKeyAuthMethod: AuthMethod = {
id: "api-key",
name: "API Key",
description: "Use an API key to authenticate",
_meta: {
"api-key": {
provider: "openai"
}
}
}
interface ApiKeyAuthRequest extends AuthenticateRequest {
methodId: "api-key";
_meta: {
"api-key": {
apiKey: string;
}
};
}
const ChatGptAuthMethod: AuthMethod = {
id: "chat-gpt",
name: "ChatGPT",
description: "Use ChatGPT to authenticate"
}
export interface ChatGPTAuthRequest extends AuthenticateRequest {
methodId: "chat-gpt";
}
const GatewayAuthMethod: AuthMethod = {
id: "gateway",
name: "Custom model gateway",
description: "Use a custom gateway to authenticate and access models",
_meta: {
"gateway": {
protocol: "openai",
restartRequired: "false"
}
}
}
export interface GatewayAuthRequest extends AuthenticateRequest {
methodId: "gateway";
_meta: {
"gateway": {
baseUrl: string;
headers: Record<string, string>;
providerName?: string;
}
};
}
export function getCodexAuthMethods(clientCapabilities?: ClientCapabilities | null): AuthMethod[] {
const authMethods: AuthMethod[] = [ApiKeyAuthMethod, ChatGptAuthMethod];
const supportsGatewayAuth = clientCapabilities?.auth?._meta?.["gateway"] === true;
if (supportsGatewayAuth) {
authMethods.push(GatewayAuthMethod);
}
return authMethods;
}
export type CodexAuthRequest = ApiKeyAuthRequest | ChatGPTAuthRequest | GatewayAuthRequest;
export function isCodexAuthRequest(request: AuthenticateRequest): request is CodexAuthRequest {
return request.methodId === "api-key" || request.methodId === "chat-gpt" || request.methodId === "gateway";
}