feat(webui): render a media event as a link fallback

The dashboard has no inline media rendering path yet
(archie-core-1786748942243-6-f109697e). chatStreamSink.Media degrades
a MediaEvent to a link appended to the delta stream -- the same
fallback Telegram's liveReply uses when its own SendMedia call fails
-- rather than the event reaching nowhere.
This commit is contained in:
sam committed 2026-08-23 02:48:06 +10:00
1 parent d7308b9207
commit f6d7d0dce2
2 files changed
+81

No files matched your search

+15
View File
@@ -254,6 +254,21 @@ func (s chatStreamSink) ToolCall(event gateway.ToolCallEvent) {
})
}
// Media has no inline rendering path on the dashboard yet (see
// archie-core-1786748942243-6-f109697e), so it degrades to a link in the
// delta stream -- the same fallback Telegram's liveReply uses when its own
// SendMedia call fails. An attachment with no URL has nothing to link to
// and is skipped rather than emitting an empty line.
func (s chatStreamSink) Media(event gateway.MediaEvent) {
if event.Attachment.URL == "" {
return
}
s.write(chatStreamEvent{
Type: "delta",
Text: "\n\n📎 " + event.Attachment.Type + ": " + event.Attachment.URL,
})
}
// chatShowToolCalls reports config.ChatConfig.ShowToolCalls, the one setting
// shared by every chat channel. Off (the default) when Cfg is nil, matching
// the field's own off-by-default doc comment: a dashboard embedded without
+66
View File
@@ -679,6 +679,72 @@ func TestChatStreamReportsToolCalls(t *testing.T) {
}
}
// The dashboard has no inline media rendering path yet (see
// archie-core-1786748942243-6-f109697e), so a MediaEvent has to degrade to
// a link in the text stream rather than being silently dropped -- the same
// fallback Telegram's liveReply uses when SendMedia itself fails.
func TestChatStreamRendersMediaAsALinkFallback(t *testing.T) {
stream := func(_ context.Context, _ gateway.Message, turn gateway.TurnStream) (string, error) {
turn.Delta("here you go")
turn.Media(gateway.MediaEvent{
ToolName: "video_gen",
Attachment: gateway.MediaAttachment{Type: "video", URL: "https://example.com/v.mp4"},
})
return "here you go", nil
}
server, sessions := chatTestServer(t)
server.Chat.Router.LLMStream = stream
saveWebSession(t, sessions, "web-1")
req := httptest.NewRequestWithContext(context.Background(), http.MethodPost, "/api/chat/stream",
strings.NewReader(`{"channel_id":"browser-web-1","text":"make me a video"}`))
req.Header.Set("Content-Type", "application/json")
res := httptest.NewRecorder()
server.Handler().ServeHTTP(res, req)
if res.Code != http.StatusOK {
t.Fatalf("status = %d, body = %s", res.Code, res.Body)
}
var joined string
for _, ev := range parseChatSSE(t, res.Body.String()) {
if ev.Type == "delta" {
joined += ev.Text
}
}
if !strings.Contains(joined, "https://example.com/v.mp4") {
t.Fatalf("delta stream = %q, want it to contain the asset URL", joined)
}
}
// An event with no URL has nothing to link to, so it must not add an
// empty or broken-looking line to the transcript.
func TestChatStreamSkipsMediaWithNoURL(t *testing.T) {
stream := func(_ context.Context, _ gateway.Message, turn gateway.TurnStream) (string, error) {
turn.Media(gateway.MediaEvent{ToolName: "video_gen", Attachment: gateway.MediaAttachment{Type: "video"}})
return "", nil
}
server, sessions := chatTestServer(t)
server.Chat.Router.LLMStream = stream
saveWebSession(t, sessions, "web-1")
req := httptest.NewRequestWithContext(context.Background(), http.MethodPost, "/api/chat/stream",
strings.NewReader(`{"channel_id":"browser-web-1","text":"make me a video"}`))
req.Header.Set("Content-Type", "application/json")
res := httptest.NewRecorder()
server.Handler().ServeHTTP(res, req)
if res.Code != http.StatusOK {
t.Fatalf("status = %d, body = %s", res.Code, res.Body)
}
for _, ev := range parseChatSSE(t, res.Body.String()) {
if ev.Type == "delta" && ev.Text != "" {
t.Fatalf("got a delta for a URL-less media event: %q", ev.Text)
}
}
}
// config.ChatConfig.ShowToolCalls is off by default and shared by every chat
// channel: an operator who left it unset (or explicitly turned it off) must
// see no tool activity on the dashboard, not just in Telegram. Previously the