Documentation
¶
Overview ¶
Package hub keeps one Claude Code session in a stream-json process that several channels (the phone, atc, WhatsApp, other sessions) talk into, and routes its replies back.
ws /ws?channel=<name>
in: {"type":"message","text":...} {"type":"note","text":...} {"type":"interrupt"}
out: text{delta} tool{name} block{text} read joined held done{interrupted,subtype} error{error} notice{text}
ws /events gets every event of every channel, each with its channel.
Index ¶
- Constants
- Variables
- func NewID() string
- type CallConfig
- type CallReq
- type Client
- func (c *Client) Call(ctx context.Context, r CallReq) (string, error)
- func (c *Client) Interrupt(ctx context.Context, channel string) (bool, error)
- func (c *Client) Lines(ctx context.Context) (out []Line, err error)
- func (c *Client) Notice(ctx context.Context) (bool, error)
- func (c *Client) Reset(ctx context.Context) error
- func (c *Client) Send(ctx context.Context, channel, text string) (string, error)
- func (c *Client) Status(ctx context.Context) (st Status, err error)
- func (c *Client) Watch(ctx context.Context, fn func(Event)) error
- type Config
- type Event
- type Hub
- func (h *Hub) Call(ctx context.Context, r CallReq) (string, error)
- func (h *Hub) Handler() http.Handler
- func (h *Hub) HasConversation() bool
- func (h *Hub) Interrupt(ch string, force bool) bool
- func (h *Hub) Left(channel string)
- func (h *Hub) Notice() (bool, error)
- func (h *Hub) Reset(why string) error
- func (h *Hub) Say(channel, text string) (string, error)
- func (h *Hub) Start() error
- func (h *Hub) Status() Status
- func (h *Hub) Stop()
- func (h *Hub) Subscribe(channel string) (<-chan Event, func())
- func (h *Hub) Watch(ctx context.Context, every time.Duration)
- type Line
- type LineSpec
- type OpenLine
- type Status
Constants ¶
const ( Answered = "answered" NoAnswer = "no-answer" Busy = "busy" // Knocked is a call that found the user on the line with an agent: they were told on that call. Knocked = "knocked" )
const ( Phone = "phone" Agent = "agent" // Guest is someone other than the user writing in (a WhatsApp guest); like an agent's report, // the reply reaches no one. Guest = "guest" // GuestCall is a guest calling the assistant's line: spoken like the phone, but not the user. GuestCall = "guest-call" )
Variables ¶
var ErrBusy = errors.New("a turn is running")
var ErrNoPhone = errors.New("no phone line configured (ATC_CALL_LINE)")
var ErrRestarting = errors.New("claude is restarting, try again")
Functions ¶
Types ¶
type CallConfig ¶
type CallConfig struct {
URL string
Number string
Timeout time.Duration
Poll time.Duration
AppAck time.Duration
HTTP *http.Client
}
CallConfig is the call line the hub's session talks on and the one number it dials.
type Client ¶
Client is how atc talks to the hub.
type Config ¶
type Config struct {
Bin string
Args []string
Dir string
State string
// Mode is the text that tells the session how to talk on a channel, "" for none.
Mode func(channel string) string
// News is what changed in atc since it was last asked, or with full how things stand; "" for nothing.
News func(full bool) string
Reset startover.Policy
Call CallConfig
Now func() time.Time
// Guests is the guests' own conversation, which takes the guest channels; nil keeps them here.
Guests *Hub
// GuestDesk is set on that conversation: the user never talks into it, so it is not told where they are.
GuestDesk bool
// OpenLine asks atc for an agent's conversation to take onto a call, LineMode is how those talk; see lines.go.
OpenLine OpenLine
LineMode func(channel string) string
}
type Event ¶
type Event struct {
Type string `json:"type"`
Channel string `json:"channel,omitempty"`
Delta string `json:"delta,omitempty"`
Name string `json:"name,omitempty"`
Text string `json:"text,omitempty"`
Error string `json:"error,omitempty"`
Interrupted bool `json:"interrupted,omitempty"`
Subtype string `json:"subtype,omitempty"`
}
type Hub ¶
type Hub struct {
// contains filtered or unexported fields
}
func (*Hub) Call ¶
Call has the user rung and waits for the outcome. Answered, the call's first message reaches the session with the reason in front of it, so it speaks first and knows why. Not answered, a Notify call puts that in front of the session on the channel it was busy with.
func (*Hub) Handler ¶
Handler serves the hub. With a guests hub (cfg.Guests), what guests say goes to that one, on the same paths, and its own API is under /guests/.
func (*Hub) HasConversation ¶ added in v0.1.1
HasConversation says whether this hub has ever talked to anyone. One that hasn't starts with its first message.
func (*Hub) Interrupt ¶
Interrupt stops the running turn. A channel that is not forcing it (the phone's barge-in) only cuts what is being said to it, and lets a running tool finish first so its result is kept. Claude Code replays a message only about two seconds after taking it, when its answer starts; a cut in that time (the user's turn reopened right after it was sent) stops the turn before it began.
func (*Hub) Left ¶
Left is a channel's connection going away. A phone connection lives exactly as long as a call, so the next call's first message must carry the phone mode again even though the last message was also the phone's (the previous call's end note).
func (*Hub) Notice ¶
Notice is atc saying a session now needs the user. While a phone turn is running a tool, the change joins that turn right away, so the assistant can weigh it into what the user is about to hear; otherwise the next message carries it, since a call only speaks answers to the user's own words.
func (*Hub) Reset ¶
Reset starts the conversation over: the session writes a handover note in one last turn, and a new session starts with it as its first message.
func (*Hub) Say ¶
Say hands text from a channel to the session: "sent", or "held" until the running turn ends.
func (*Hub) Stop ¶
func (h *Hub) Stop()
Stop ends the claude process for good, for tests and shutdown.
type LineSpec ¶
type LineSpec struct {
Session string `json:"session"`
Dir string `json:"dir"`
Args []string `json:"args"`
}
LineSpec is what atc answers to opening a line, beside what the talker uses (title, person, voices).
type Status ¶
type Status struct {
Session string `json:"session"`
PID int `json:"pid"`
Alive bool `json:"alive"`
Context int `json:"context"`
IdleS int `json:"idle_s"`
Owners []string `json:"owners"`
Route string `json:"route,omitempty"`
Pending []string `json:"pending"`
Held []string `json:"held"`
Home string `json:"home,omitempty"`
Call string `json:"call,omitempty"`
OnLine string `json:"onLine,omitempty"`
Channels map[string]int `json:"channels"`
Reset startover.Policy `json:"reset"`
Dir string `json:"dir"`
LastReset time.Time `json:"lastReset,omitzero"`
}