| index 9169a5c..3c5514b 100644 |
| --- a/internal/equipo/equipotest/chat.go |
| +++ b/internal/equipo/equipotest/chat.go |
| @@ -32,6 +32,43 @@ type message struct { |
| // Attachments are the files sent with a person's message, in order; |
| // omitted when there are none (wire.Message). |
| Attachments []file `json:"attachments,omitempty"` |
| + // Lookups are what the Assistant looked up for a reply, sent only to |
| + // a Base that draws them (asRead). |
| + Lookups []equipo.Lookup `json:"lookups,omitempty"` |
| +} |
| + |
| +// drawsLookups reports whether r says Base draws lookup answers |
| +// (Base-Capabilities), as Equipo reads it. |
| +func drawsLookups(r *http.Request) bool { |
| + for _, v := range r.Header.Values(equipo.CapabilitiesHeader) { |
| + for _, c := range strings.Split(v, ",") { |
| + if strings.TrimSpace(c) == equipo.CapLookupAnswers { |
| + return true |
| + } |
| + } |
| + } |
| + return false |
| +} |
| + |
| +// asRead is m as a read with draws gets it: its lookups as they are, or, |
| +// for a Base that can't draw them, folded into its text, as Equipo's |
| +// plain-text fallback does (computed at read time, never stored). |
| +func asRead(m message, draws bool) message { |
| + if draws || len(m.Lookups) == 0 { |
| + return m |
| + } |
| + m.Text = equipo.Message{Text: m.Text, Lookups: m.Lookups}.PlainLookups().Text |
| + m.Lookups = nil |
| + return m |
| +} |
| + |
| +// read is msgs as a read with draws gets them (asRead). |
| +func read(msgs []message, draws bool) []message { |
| + out := make([]message, len(msgs)) |
| + for i, m := range msgs { |
| + out[i] = asRead(m, draws) |
| + } |
| + return out |
| } |
| |
| type turn struct { |
| @@ -390,7 +427,7 @@ func (f *Fake) serveChat(w http.ResponseWriter, r *http.Request) { |
| f.snapshot(w, r) |
| case r.Method == http.MethodGet && p == "/messages": |
| f.cmu.Lock() |
| - writeJSON(w, 200, map[string]any{"items": f.tail(), "before": ""}) |
| + writeJSON(w, 200, map[string]any{"items": read(f.tail(), drawsLookups(r)), "before": ""}) |
| f.cmu.Unlock() |
| case r.Method == http.MethodPost && p == "/messages": |
| f.send(w, r, d.id) |
| @@ -445,7 +482,7 @@ func (f *Fake) snapshot(w http.ResponseWriter, r *http.Request) { |
| writeJSON(w, 200, map[string]any{ |
| "me": map[string]any{"id": f.address, "address": f.address, "role": "owner", |
| "person": map[string]any{"name": "Paul"}, "team_id": f.Instance, "team_name": "Tito"}, |
| - "messages": f.tail(), "turns": turns, "cards": cards, "cursor": f.cursor, |
| + "messages": read(f.tail(), drawsLookups(r)), "turns": turns, "cards": cards, "cursor": f.cursor, |
| "available": f.runner == "", "can_attach": f.canAttach(), |
| }) |
| } |
| @@ -600,7 +637,17 @@ func (f *Fake) answerTurn(id, text string) { |
| // Answer answers the running turn with id (one Hold kept running): with |
| // deltas, the reply streamed in word by word first (Stream); then the |
| // reply message, and the turn replied. |
| -func (f *Fake) Answer(id, reply string, deltas bool) { |
| +func (f *Fake) Answer(id, reply string, deltas bool) { f.answerWith(id, reply, deltas, nil) } |
| + |
| +// ReplyWithLookups answers the running turn with id as Answer does (its |
| +// words streamed first), with lookups on the reply, as Equipo attaches |
| +// what the Assistant looked up for it. A read that doesn't say Base draws |
| +// them gets them folded into the text. |
| +func (f *Fake) ReplyWithLookups(id, reply string, lookups ...equipo.Lookup) { |
| + f.answerWith(id, reply, true, lookups) |
| +} |
| + |
| +func (f *Fake) answerWith(id, reply string, deltas bool, lookups []equipo.Lookup) { |
| if deltas { |
| f.Stream(id, reply) |
| } |
| @@ -609,7 +656,8 @@ func (f *Fake) Answer(id, reply string, deltas bool) { |
| if f.turns[id].State != "running" { |
| return |
| } |
| - m := message{ID: f.next("m"), Revision: 1, Role: "assistant", Text: reply, TurnID: id, CreatedAt: time.Now().UTC()} |
| + m := message{ID: f.next("m"), Revision: 1, Role: "assistant", Text: reply, TurnID: id, CreatedAt: time.Now().UTC(), |
| + Lookups: append([]equipo.Lookup(nil), lookups...)} |
| f.messages = append(f.messages, m) |
| f.emit("message", "message", m.ID, 1, id, m) |
| t := f.turns[id] |
| @@ -934,7 +982,7 @@ func (f *Fake) stream(w http.ResponseWriter, r *http.Request) { |
| } |
| after = n |
| } |
| - paused := pausedOK(r) |
| + paused, draws := pausedOK(r), drawsLookups(r) |
| rc := http.NewResponseController(w) |
| w.Header().Set("Content-Type", "text/event-stream") |
| w.WriteHeader(200) |
| @@ -956,6 +1004,9 @@ func (f *Fake) stream(w http.ResponseWriter, r *http.Request) { |
| if c, ok := e.Data.(card); ok { |
| e.Data = asSeen(c, paused) |
| } |
| + if m, ok := e.Data.(message); ok { |
| + e.Data = asRead(m, draws) |
| + } |
| raw, _ := json.Marshal(e) |
| id := "" |
| if e.Cursor != 0 { |