Class: LLM::Repl::Status Private

Inherits:
Object
  • Object
show all
Defined in:
lib/llm/repl/status.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

The LLM::Repl::Status class stores the small status line shown at the top of the REPL.

The status text can be a plain String, a single LLM::Repl::Node (text plus curses attributes), or an Array of either. Attributes on nodes are applied when the window draws the status line.

Instance Method Summary collapse

Constructor Details

#initialize(repl) ⇒ LLM::Repl::Status

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:



17
18
19
20
21
# File 'lib/llm/repl/status.rb', line 17

def initialize(repl)
  @agent = repl.agent
  @provider = @agent.llm.name
  @nodes = [Node.new("idle")]
end

Instance Method Details

#context_barString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (String)


25
26
27
28
29
30
31
32
33
34
# File 'lib/llm/repl/status.rb', line 25

def context_bar
  LLM::Repl::Bar.new(
    ##
    # After compaction the used context is unknown until the next
    # response, so the bar renders an unknown state instead of a
    # stale percentage.
    used: @agent.compacted? ? nil : @agent.usage.total_tokens,
    total: @agent.context_window
  ).to_s
end

#costString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (String)


38
39
40
# File 'lib/llm/repl/status.rb', line 38

def cost
  "$#{@agent.cost}"
end

#nodesArray<LLM::Repl::Node>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The nodes making up the status line.

Returns:



68
69
70
71
72
73
74
# File 'lib/llm/repl/status.rb', line 68

def nodes
  if @agent.compacted?
    [Node.new("Context compacted")]
  else
    @nodes
  end
end

#textString Also known as: to_s

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (String)


57
58
59
# File 'lib/llm/repl/status.rb', line 57

def text
  @nodes.map(&:text).join
end

#text=(value) ⇒ Array<LLM::Repl::Node>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Sets the status text.

Parameters:

Returns:



46
47
48
49
50
51
52
53
# File 'lib/llm/repl/status.rb', line 46

def text=(value)
  @nodes =
    case value
    when Node then [value]
    when Array then value.map { |node| Node === node ? node : Node.new(node) }
    else [Node.new(value)]
    end
end