| package openai |
|
|
| import "strings" |
|
|
| |
| |
| var CodexCLIUserAgentPrefixes = []string{ |
| "codex_vscode/", |
| "codex_cli_rs/", |
| } |
|
|
| |
| |
| var CodexOfficialClientUserAgentPrefixes = []string{ |
| "codex_cli_rs/", |
| "codex_vscode/", |
| "codex_app/", |
| "codex_chatgpt_desktop/", |
| "codex_atlas/", |
| "codex_exec/", |
| "codex_sdk_ts/", |
| "codex ", |
| } |
|
|
| |
| |
| |
| var CodexOfficialClientOriginatorPrefixes = []string{ |
| "codex_", |
| "codex ", |
| } |
|
|
| |
| func IsCodexCLIRequest(userAgent string) bool { |
| ua := normalizeCodexClientHeader(userAgent) |
| if ua == "" { |
| return false |
| } |
| return matchCodexClientHeaderPrefixes(ua, CodexCLIUserAgentPrefixes) |
| } |
|
|
| |
| |
| func IsCodexOfficialClientRequest(userAgent string) bool { |
| ua := normalizeCodexClientHeader(userAgent) |
| if ua == "" { |
| return false |
| } |
| return matchCodexClientHeaderPrefixes(ua, CodexOfficialClientUserAgentPrefixes) |
| } |
|
|
| |
| func IsCodexOfficialClientOriginator(originator string) bool { |
| v := normalizeCodexClientHeader(originator) |
| if v == "" { |
| return false |
| } |
| return matchCodexClientHeaderPrefixes(v, CodexOfficialClientOriginatorPrefixes) |
| } |
|
|
| |
| |
| func IsCodexOfficialClientByHeaders(userAgent, originator string) bool { |
| return IsCodexOfficialClientRequest(userAgent) || IsCodexOfficialClientOriginator(originator) |
| } |
|
|
| func normalizeCodexClientHeader(value string) string { |
| return strings.ToLower(strings.TrimSpace(value)) |
| } |
|
|
| func matchCodexClientHeaderPrefixes(value string, prefixes []string) bool { |
| for _, prefix := range prefixes { |
| normalizedPrefix := normalizeCodexClientHeader(prefix) |
| if normalizedPrefix == "" { |
| continue |
| } |
| |
| if strings.HasPrefix(value, normalizedPrefix) || strings.Contains(value, normalizedPrefix) { |
| return true |
| } |
| } |
| return false |
| } |
|
|