X-Git-Url: http://git.giacomolli.uk/onechat/blobdiff_plain/697c662a48c87ee9be136358129c1f79f4f5a72f..b2873a2a0bf8b0ba648aebac51759e5fed89a2e2:/turn.go?ds=inline diff --git a/turn.go b/turn.go index f8faad8..0b2b29e 100644 --- a/turn.go +++ b/turn.go @@ -18,11 +18,14 @@ type modelClient interface { // Event tells the clients what the agent does as it happens. Kind is the kind // of a logged message (user, reply, tool, echo), or one of ready, busy, idle, -// and error. ID is the ID of a logged message. +// and error. ID is the ID of a logged message. Source names the client that +// sent a user message, such as terminal or telegram, so that each client can +// show the messages of the others. type Event struct { - Kind string `json:"kind"` - ID int `json:"id,omitempty"` - Text string `json:"text,omitempty"` + Kind string `json:"kind"` + ID int `json:"id,omitempty"` + Text string `json:"text,omitempty"` + Source string `json:"source,omitempty"` } // loop runs the turns of one agent. A user message goes to the log when it @@ -98,10 +101,11 @@ func newLoop(agent *Agent, memory *Memory, client modelClient, clock func() time return l, nil } -// Submit logs a user message and wakes the loop. The message joins the next -// request: the first one of a new turn, or the next one of a running turn. -func (l *loop) Submit(text string) (Message, error) { - message, err := l.Append("user", text) +// Submit logs a user message from the client source and wakes the loop. The +// message joins the next request: the first one of a new turn, or the next one +// of a running turn. +func (l *loop) Submit(source, text string) (Message, error) { + message, err := l.record("user", source, text) if err != nil { return Message{}, err } @@ -144,15 +148,22 @@ func (l *loop) Busy() bool { // Append logs a message and tells the clients. The toolbox logs its calls and // results through it. func (l *loop) Append(kind, text string) (Message, error) { + return l.record(kind, "", text) +} + +// record logs a message and tells the clients, with the client source of a user +// message. +func (l *loop) record(kind, source, text string) (Message, error) { message, err := l.memory.Append(kind, text) if err != nil { return Message{}, err } l.notify(Event{ - Kind: kind, - ID: message.ID, - Text: text, + Kind: kind, + ID: message.ID, + Text: text, + Source: source, }) return message, nil