summaryrefslogtreecommitdiffhomepage
path: root/lib/dispatch/adapter/message.rb
blob: eb51c99dd3c5fcbd438fa0aa8a89814f3f6ec424 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# frozen_string_literal: true

module Dispatch
  module Adapter
    Message = Struct.new(:role, :content, keyword_init: true)

    TextBlock = Struct.new(:type, :text, keyword_init: true) do
      def initialize(text:, type: "text")
        super(type:, text:)
      end
    end

    ImageBlock = Struct.new(:type, :source, :media_type, keyword_init: true) do
      def initialize(source:, media_type:, type: "image")
        super(type:, source:, media_type:)
      end
    end

    ToolUseBlock = Struct.new(:type, :id, :name, :arguments, keyword_init: true) do
      def initialize(id:, name:, arguments:, type: "tool_use")
        super(type:, id:, name:, arguments:)
      end
    end

    ToolResultBlock = Struct.new(:type, :tool_use_id, :content, :is_error, keyword_init: true) do
      def initialize(tool_use_id:, content:, is_error: false, type: "tool_result")
        super(type:, tool_use_id:, content:, is_error:)
      end
    end
  end
end