Documentation
¶
Overview ¶
Package useragent builds User-Agent strings for Stripe API requests.
Index ¶
- func DetectAIAgent(getEnv func(string) string) string
- func DetectAgentHost(getEnv func(string) string) (kind string, raw string)
- func DetectAgentVersion(getEnv func(string) string) string
- func DetectInScreen(getEnv func(string) string) bool
- func DetectInTmux(getEnv func(string) string) bool
- func DetectTerminalProgram(getEnv func(string) string) string
- func GetEncodedStripeUserAgent() string
- func GetEncodedUserAgent() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DetectAIAgent ¶ added in v1.37.2
DetectAIAgent detects if the CLI was invoked by a coding agent, based on well-known env vars. It accepts an environment getter function to allow testing without modifying the actual environment.
Agent-specific variables are checked first. When none match it falls back to the two host variables DetectAgentHost reads, which identify an agent surface and so imply the agent, and finally to AI_AGENT and then AGENT, which some agents report through directly.
func DetectAgentHost ¶ added in v1.50.1
DetectAgentHost reports where the agent ran, as a bounded category and as the host value itself. Both are empty when no agent reported a host and none can be inferred.
kind is what to group by: "desktop", "terminal", "ide", "remote", "sdk", "mcp", or "other" for a host we have not categorized. raw is the normalized host underneath it, reported for every host rather than only uncategorized ones, so that a value we map too coarsely stays recoverable. "claude-desktop" and "claude-desktop-3p" are both desktop, for instance, and without raw nothing downstream can tell them apart.
Reporting raw also means an unmapped host can be identified from the data rather than from a vendor's source, which matters because mapping one otherwise costs a code change, a release, and users upgrading before it is even visible.
Two hosts are inferred rather than reported: Codex names every surface except the terminal, and Grok Build names neither of its two surfaces, so a detected agent of either with no host is inferred from other signals. See the empty-host branch below.
func DetectAgentVersion ¶ added in v1.45.4
DetectAgentVersion returns the agent's own version, parsed out of the identifier it reports through the AI_AGENT convention, or "" when absent or unparseable.
Claude Code encodes it as "claude-code_2-1-227_agent" (dots written as dashes) and has also used "claude-code/2.1.227". No other agent reports a version this way today. Both formats are undocumented, so this validates what it extracts and reports nothing rather than guessing: a wrong version is worse than a missing one.
func DetectInScreen ¶ added in v1.42.3
DetectInScreen detects whether the CLI was invoked from within a GNU Screen session.
func DetectInTmux ¶ added in v1.42.3
DetectInTmux detects whether the CLI was invoked from within a tmux session.
func DetectTerminalProgram ¶ added in v1.42.3
DetectTerminalProgram detects the terminal program the CLI was invoked from, when available.
func GetEncodedStripeUserAgent ¶
func GetEncodedStripeUserAgent() string
GetEncodedStripeUserAgent returns the string to be used as the value for the `X-Stripe-Client-User-Agent` HTTP header.
func GetEncodedUserAgent ¶
func GetEncodedUserAgent() string
GetEncodedUserAgent returns the string to be used as the value for the `User-Agent` HTTP header.
Types ¶
This section is empty.