Class: Ask::ACP::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/ask/acp/server.rb

Overview

ACP server that lets a Ruby agent speak the Agent Client Protocol over stdio.

Handles the JSON-RPC 2.0 transport, method dispatch, and streaming responses. Subclass and implement the method handlers you need.

Examples:

class MyAgent < Ask::ACP::Server
  def handle_initialize(params)
    { protocolVersion: 1, serverInfo: { name: "my-agent", version: "0.1.0" } }
  end

  def handle_session_new(params)
    { session: { id: SecureRandom.uuid, status: "running" } }
  end
end

MyAgent.new.run

Instance Method Summary collapse

Constructor Details

#initializeServer

Returns a new instance of Server.



25
26
27
28
# File 'lib/ask/acp/server.rb', line 25

def initialize
  @methods = {}
  register_defaults
end

Instance Method Details

#runObject

Start reading from stdin and processing requests.



31
32
33
34
35
36
37
38
39
# File 'lib/ask/acp/server.rb', line 31

def run
  $stdin.each_line do |line|
    line = line.strip
    next if line.empty?
    handle(Protocol.parse(line))
  end
rescue => e
  $stderr.puts "ACP server error: #{e.message}"
end