Class: XAeonAgents::Providers::Cline

Inherits:
RubyLLM::Providers::OpenAI
  • Object
show all
Defined in:
lib/x_aeon_agents/providers/cline.rb

Overview

Cline API integration.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.configuration_optionsArray<Symbol>

Returns The available configuration keys for the Cline provider.

Returns:

  • (Array<Symbol>)

    The available configuration keys for the Cline provider.



72
73
74
# File 'lib/x_aeon_agents/providers/cline.rb', line 72

def configuration_options
  %i[cline_api_base cline_api_key]
end

.configuration_requirementsArray<Symbol>

Returns The required configuration keys for the Cline provider.

Returns:

  • (Array<Symbol>)

    The required configuration keys for the Cline provider.



67
68
69
# File 'lib/x_aeon_agents/providers/cline.rb', line 67

def configuration_requirements
  %i[cline_api_base cline_api_key]
end

Instance Method Details

#api_baseString

Returns The base API URL.

Returns:

  • (String)

    The base API URL



15
16
17
# File 'lib/x_aeon_agents/providers/cline.rb', line 15

def api_base
  @config.cline_api_base || 'https://api.cline.bot/api/v1'
end

#headersHash{String => String}

Returns HTTP headers to add to the queries.

Returns:

  • (Hash{String => String})

    HTTP headers to add to the queries



20
21
22
23
24
# File 'lib/x_aeon_agents/providers/cline.rb', line 20

def headers
  {
    'Authorization' => "Bearer #{@config.cline_api_key}"
  }
end

#parse_completion_response(response) ⇒ RubyLLM::Message?

Parses the completion response from the Cline API into a [RubyLLM::Message].

Handles empty responses, API errors, message extraction, content/thinking parsing, token usage tracking (including cached and reasoning tokens), and tool calls.

Parameters:

  • response (Faraday::Response)

    The raw HTTP response from the Cline API.

Returns:

  • (RubyLLM::Message, nil)

    The parsed message, or nil if the response body is empty or no message data is present.

Raises:

  • (Error)


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/x_aeon_agents/providers/cline.rb', line 34

def parse_completion_response(response)
  data = response.body
  return if data.empty?

  raise Error.new(response, data['error']) if data['error']

  message_data = data.dig('data', 'choices', 0, 'message')
  return unless message_data

  usage = data.dig('data', 'usage') || {}
  cached_tokens = usage.dig('prompt_tokens_details', 'cached_tokens')
  thinking_tokens = usage.dig('completion_tokens_details', 'reasoning_tokens')
  content, thinking_from_blocks = extract_content_and_thinking(message_data['content'])
  thinking_text = thinking_from_blocks || extract_thinking_text(message_data)
  thinking_signature = extract_thinking_signature(message_data)

  RubyLLM::Message.new(
    role: :assistant,
    content: content,
    thinking: RubyLLM::Thinking.build(text: thinking_text, signature: thinking_signature),
    tool_calls: parse_tool_calls(message_data['tool_calls']),
    input_tokens: usage['prompt_tokens'],
    output_tokens: usage['completion_tokens'],
    cached_tokens: cached_tokens,
    cache_creation_tokens: 0,
    thinking_tokens: thinking_tokens,
    model_id: data.dig('data', 'model'),
    raw: response
  )
end