]> git.giacomolli.uk - onechat/blobdiff - turn.go
Limit the time of each Telegram send call
[onechat] / turn.go
diff --git a/turn.go b/turn.go
index f8faad83d0a8be375b4e9fd3b2f9e6766284d2cf..0b2b29eed4fcc65d996c57e25570b2667a178037 100644 (file)
--- 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