Module: Xeno::Channels

Defined in:
lib/xeno/channels.rb,
lib/xeno/channels/slack.rb

Overview

The channel registry. A channel normalizes platform input into user messages, owns the session's continuation token, and decides delivery of agent output. HTTP is built in; agent/channels/*.rb declare the rest:

Xeno.channel :slack do
signing_secret Rails.application.credentials.dig(:slack, :signing_secret)
bot_token     Rails.application.credentials.dig(:slack, :bot_token)
end

Delivery is a failable nicety: the durable truth lives in the transcript and event rows, so a failed post logs and moves on.

Defined Under Namespace

Classes: Slack

Class Method Summary collapse

Class Method Details

.build(name, &block) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/xeno/channels.rb', line 26

def build(name, &block)
  case name.to_sym
  when :slack
    Slack.new(&block)
  else
    raise Xeno::Error, "unknown channel type: #{name} (:slack is bundled; http is built in)"
  end
end

.deliver_completion(session, content) ⇒ Object



39
40
41
42
43
# File 'lib/xeno/channels.rb', line 39

def deliver_completion(session, content)
  for_session(session)&.deliver_completion(session, content)
rescue StandardError => e
  Rails.logger.warn("xeno: channel delivery failed for session #{session.id}: #{e.class}: #{e.message}")
end

.deliver_input_request(session, actions) ⇒ Object



45
46
47
48
49
# File 'lib/xeno/channels.rb', line 45

def deliver_input_request(session, actions)
  for_session(session)&.deliver_input_request(session, actions)
rescue StandardError => e
  Rails.logger.warn("xeno: channel input-request delivery failed for session #{session.id}: #{e.class}: #{e.message}")
end

.for_session(session) ⇒ Object



35
36
37
# File 'lib/xeno/channels.rb', line 35

def for_session(session)
  registry[session.channel&.to_sym]
end

.register(name, channel) ⇒ Object



22
23
24
# File 'lib/xeno/channels.rb', line 22

def register(name, channel)
  registry[name.to_sym] = channel
end

.registryObject



18
19
20
# File 'lib/xeno/channels.rb', line 18

def registry
  @registry ||= {}
end

.streamer_for(session) ⇒ Object

A per-reply delta sink (post-then-edit streaming) when the session's channel opts in; nil otherwise. Failable nicety like all delivery.



53
54
55
56
57
58
59
60
61
# File 'lib/xeno/channels.rb', line 53

def streamer_for(session)
  channel = for_session(session)
  return nil unless channel.respond_to?(:streamer_for)

  channel.streamer_for(session)
rescue StandardError => e
  Rails.logger.warn("xeno: channel streamer setup failed for session #{session.id}: #{e.class}: #{e.message}")
  nil
end