MCPcopy Index your code
hub / github.com/coder/coder / GuessClient

Function GuessClient

aibridge/client.go:30–60  ·  view source on GitHub ↗

GuessClient attempts to guess the client application from the request headers. Not all clients set proper user agent headers, so this is a best-effort approach. Based on https://github.com/coder/aibridge/issues/20#issuecomment-3769444101.

(r *http.Request)

Source from the content-addressed store, hash-verified

28// Not all clients set proper user agent headers, so this is a best-effort approach.
29// Based on https://github.com/coder/aibridge/issues/20#issuecomment-3769444101.
30func GuessClient(r *http.Request) Client {
31 userAgent := strings.ToLower(r.UserAgent())
32 originator := r.Header.Get("originator")
33
34 // Must be kept in sync with documentation: https://github.com/coder/coder/blob/90c11f3386578da053ec5cd9f1475835b980e7c7/docs/ai-coder/ai-bridge/monitoring.md?plain=1#L36-L44
35 switch {
36 case strings.HasPrefix(userAgent, "mux/"):
37 return ClientMux
38 case strings.HasPrefix(userAgent, "claude"):
39 return ClientClaudeCode
40 case strings.HasPrefix(userAgent, "codex"):
41 return ClientCodex
42 case strings.HasPrefix(userAgent, "zed/"):
43 return ClientZed
44 case strings.HasPrefix(userAgent, "githubcopilotchat/"):
45 return ClientCopilotVSC
46 case strings.HasPrefix(userAgent, "copilot/"):
47 return ClientCopilotCLI
48 case strings.HasPrefix(userAgent, "kilo-code/") || originator == "kilo-code":
49 return ClientKilo
50 case strings.HasPrefix(userAgent, "roo-code/") || originator == "roo-code":
51 return ClientRoo
52 case strings.HasPrefix(userAgent, "coder-agents/"):
53 return ClientCoderAgents
54 case strings.HasPrefix(userAgent, "charm crush/") || strings.HasPrefix(userAgent, "charm-crush/"):
55 return ClientCrush
56 case r.Header.Get("x-cursor-client-version") != "":
57 return ClientCursor
58 }
59 return ClientUnknown
60}

Callers 2

TestGuessClientFunction · 0.92
newInterceptionProcessorFunction · 0.85

Calls 1

GetMethod · 0.65

Tested by 1

TestGuessClientFunction · 0.74