Module: RailsAgents::Skills::AnthropicContent

Defined in:
lib/rails_agents/skills/anthropic_content.rb

Class Method Summary collapse

Class Method Details

.extract_file_ids(blocks) ⇒ Object



12
13
14
15
16
# File 'lib/rails_agents/skills/anthropic_content.rb', line 12

def extract_file_ids(blocks)
  ids = []
  walk(blocks) { |node| ids << node["file_id"] if node.is_a?(Hash) && !node["file_id"].to_s.empty? }
  ids.uniq
end

.extract_text(blocks) ⇒ Object



8
9
10
# File 'lib/rails_agents/skills/anthropic_content.rb', line 8

def extract_text(blocks)
  Array(blocks).select { |block| block["type"] == "text" }.map { |block| block["text"] }.join("\n").strip
end

.walk(object) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/rails_agents/skills/anthropic_content.rb', line 18

def walk(object)
  case object
  when Array
    object.each { |item| walk(item) { |node| yield node } }
  when Hash
    yield object
    object.each_value { |value| walk(value) { |node| yield node } }
  end
end