oficina / base Public

Place streamed words by UTF-8 byte offset, as Equipo counts

Equipo's delta offsets count UTF-8 bytes, but the draft compared them
with its length in JavaScript characters: after the first é or ’ every
later streamed piece was dropped until the reply arrived. Each draft now
keeps its length in bytes (TextEncoder) to place the next piece.

TestAskStreamCountsBytes streams "café ’quoted’ – done" in several
deltas and checks the bubble holds all of it before the reply.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev bc6de469b6bee7ff917addd0713ce784ef1ace92 parent 462d65d
2 files changed, +31 −2
  • internal/browsertest/thinking_test.go +22 −0
  • internal/look/static/ask.js +9 −2
diff --git a/internal/browsertest/thinking_test.go b/internal/browsertest/thinking_test.go
index 4f40a49..bd524b2 100644
--- a/internal/browsertest/thinking_test.go
+++ b/internal/browsertest/thinking_test.go
@@ -325,3 +325,25 @@ func TestAskThinkingShots(t *testing.T) {
}
}
}
+
+// Equipo's delta offsets count UTF-8 bytes: a reply with letters beyond
+// ASCII streams into the bubble whole, every piece after the first é or ’
+// included, before the reply itself arrives.
+func TestAskStreamCountsBytes(t *testing.T) {
+ rig, f := askBase(t)
+ openPanel(t, rig)
+ th := thinking{t, rig, f}
+ const text = "café ’quoted’ – done"
+ id := th.send("Say something")
+ f.Stream(id, text)
+ drive(t, rig, chromedp.Poll[chromedp.Void](`document.querySelector("#ask-panel .msg.draft")?.textContent === `+strconv.Quote(text),
+ chromedp.WithPollingTimeout(5*time.Second)))
+ if got := th.eval(`[...document.querySelectorAll("#ask-panel .msg.coordinator")].filter(m => m.dataset.id).length + " " + document.querySelectorAll("#ask-panel .msg.coordinator").length`); got != "0 1" {
+ t.Errorf("streamed, before the reply: delivered and drawn Assistant lines %s, want 0 1", got)
+ }
+ f.Answer(id, text, false)
+ th.wait(`[...document.querySelectorAll("#ask-panel .msg.coordinator")].some(m => m.dataset.id && m.textContent === ` + strconv.Quote(text) + `)`)
+ if n := th.eval(`document.querySelectorAll("#ask-panel .msg.coordinator").length + ""`); n != "1" {
+ t.Errorf("answered: %s Assistant lines, want 1", n)
+ }
+}
diff --git a/internal/look/static/ask.js b/internal/look/static/ask.js
index 6d9c24c..081fa3e 100644
--- a/internal/look/static/ask.js
+++ b/internal/look/static/ask.js
@@ -100,7 +100,10 @@ function start(root) {
}
// A streamed word: the turn's thinking bubble, if it shows, holds the
- // draft.
+ // draft. Equipo's offsets count UTF-8 bytes, so each draft keeps its
+ // length in bytes (drafted) to place the next word.
+ const utf8 = new TextEncoder();
+ const drafted = new WeakMap();
function delta(d) {
let li = item("data-draft", d.turn_id);
const bubble = !li && bubbles.get(d.turn_id);
@@ -125,7 +128,11 @@ function start(root) {
thread.append(li);
}
const box = li.querySelector(":scope > .think-line") || li;
- if (d.offset === box.textContent.length) box.textContent += d.text;
+ const at = drafted.get(li) || 0;
+ if (d.offset === at && typeof d.text === "string") {
+ box.textContent += d.text;
+ drafted.set(li, at + utf8.encode(d.text).length);
+ }
scroll();
}