Class: Verica::Config

Inherits:
Struct
  • Object
show all
Defined in:
lib/verica/config.rb

Overview

Config resolution: options > env vars > defaults. Pure.

Constant Summary collapse

DEFAULT_ENDPOINT =

Verica's hosted ingest endpoint. Override via the endpoint: option or the VERICA_ENDPOINT env var for self-host or local dev. Only token is required.

'https://ingest.verica.app'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#capture_contentObject

Returns the value of attribute capture_content

Returns:

  • (Object)

    the current value of capture_content



5
6
7
# File 'lib/verica/config.rb', line 5

def capture_content
  @capture_content
end

#conversation_idObject

Returns the value of attribute conversation_id

Returns:

  • (Object)

    the current value of conversation_id



5
6
7
# File 'lib/verica/config.rb', line 5

def conversation_id
  @conversation_id
end

#debugObject

Returns the value of attribute debug

Returns:

  • (Object)

    the current value of debug



5
6
7
# File 'lib/verica/config.rb', line 5

def debug
  @debug
end

#endpointObject

Returns the value of attribute endpoint

Returns:

  • (Object)

    the current value of endpoint



5
6
7
# File 'lib/verica/config.rb', line 5

def endpoint
  @endpoint
end

#service_nameObject

Returns the value of attribute service_name

Returns:

  • (Object)

    the current value of service_name



5
6
7
# File 'lib/verica/config.rb', line 5

def service_name
  @service_name
end

#stream_usageObject

Returns the value of attribute stream_usage

Returns:

  • (Object)

    the current value of stream_usage



5
6
7
# File 'lib/verica/config.rb', line 5

def stream_usage
  @stream_usage
end

#tagsObject

Returns the value of attribute tags

Returns:

  • (Object)

    the current value of tags



5
6
7
# File 'lib/verica/config.rb', line 5

def tags
  @tags
end

#tokenObject

Returns the value of attribute token

Returns:

  • (Object)

    the current value of token



5
6
7
# File 'lib/verica/config.rb', line 5

def token
  @token
end

Class Method Details

.resolve(options, env) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/verica/config.rb', line 11

def self.resolve(options, env)
  token = (options[:token] || env['VERICA_TOKEN'] || '').to_s
  return [nil, ['token']] if token.empty?

  raw_endpoint = (options[:endpoint] || env['VERICA_ENDPOINT'] || DEFAULT_ENDPOINT).to_s
  capture = options[:capture_content]
  capture = env.key?('VERICA_CAPTURE_CONTENT') ? %w[1 true].include?(env['VERICA_CAPTURE_CONTENT']) : true if capture.nil?

  [new(
    token: token,
    endpoint: raw_endpoint.sub(%r{/+\z}, ''),
    capture_content: capture,
    conversation_id: options[:conversation_id],
    tags: Array(options[:tags]).map(&:to_s).reject(&:empty?).uniq,
    service_name: options[:service_name] || env['OTEL_SERVICE_NAME'] || 'app',
    debug: options[:debug].nil? ? %w[1 true].include?(env['VERICA_DEBUG']) : options[:debug],
    # Opt-in: append `stream_options: { include_usage: true }` to streaming
    # calls so the provider emits a final usage chunk (tokens + cost). Off by
    # default because it adds a trailing empty-choices chunk some caller procs
    # may not expect.
    stream_usage: options[:stream_usage].nil? ? %w[1 true].include?(env['VERICA_STREAM_USAGE']) : options[:stream_usage]
  ), []]
end