Class: Stripe::APIRequestor::SystemProfiler

Inherits:
Object
  • Object
show all
Defined in:
lib/stripe/api_requestor.rb

Overview

SystemProfiler extracts information about the system that we’re running in so that we can generate a rich user agent header to help debug integrations.

Constant Summary collapse

AI_AGENTS =
[
  # aiAgents: The beginning of the section generated from our OpenAPI spec
  %w[ANTIGRAVITY_CLI_ALIAS antigravity],
  %w[CLAUDECODE claude_code],
  %w[CLINE_ACTIVE cline],
  %w[CODEX_SANDBOX codex_cli],
  %w[CODEX_THREAD_ID codex_cli],
  %w[CODEX_SANDBOX_NETWORK_DISABLED codex_cli],
  %w[CODEX_CI codex_cli],
  %w[CURSOR_AGENT cursor],
  %w[GEMINI_CLI gemini_cli],
  %w[OPENCLAW_SHELL openclaw],
  %w[OPENCODE open_code],
  # aiAgents: The end of the section generated from our OpenAPI spec
].freeze

Class Method Summary collapse

Class Method Details

.detect_ai_agent(env = ENV) ⇒ Object



1116
1117
1118
1119
1120
1121
# File 'lib/stripe/api_requestor.rb', line 1116

def self.detect_ai_agent(env = ENV)
  AI_AGENTS.each do |env_var, agent_name|
    return agent_name if env[env_var] && !env[env_var].empty?
  end
  ""
end

.user_agentObject



1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
# File 'lib/stripe/api_requestor.rb', line 1123

def self.user_agent
  lang_version = "#{RUBY_VERSION} p#{RUBY_PATCHLEVEL} " \
                 "(#{RUBY_RELEASE_DATE})"

  ua = {
    application: Stripe.app_info,
    bindings_version: Stripe::VERSION,
    lang: "ruby",
    lang_version: lang_version,
    engine: defined?(RUBY_ENGINE) ? RUBY_ENGINE : "",
  }.delete_if { |_k, v| v.nil? }

  ua[:platform] = RUBY_PLATFORM if Stripe.enable_telemetry?

  ai_agent = detect_ai_agent
  ua[:ai_agent] = ai_agent unless ai_agent.empty?

  ua
end