Skip to content

Commit c797ff2

Browse files
committed
fix(tui): do not throw on non-base64 reasoning signatures
1 parent d795522 commit c797ff2

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

‎packages/tui/src/routes/session/message-parts.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ export function ReasoningPart(props: {
120120
export function progressUpdate(state: SessionMessageAssistantReasoning["state"]) {
121121
const signature = state?.signature
122122
if (typeof signature !== "string") return false
123-
return atob(signature.slice(0, 64)).includes("B\tnarration")
123+
// Signatures from other providers or gateways need not be base64; Buffer decodes leniently instead of throwing.
124+
return Buffer.from(signature.slice(0, 64), "base64").toString("latin1").includes("B\tnarration")
124125
}
125126

126127
export function reasoningContent(part: SessionMessageAssistantReasoning) {

‎packages/tui/test/cli/tui/session-rows.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,19 @@ test("assigns assistant boundaries to the first rendered row instead of the firs
314314
expect(messageBoundaryIDs(rows, messages)).toEqual(["user-1", "assistant-1", undefined, undefined])
315315
})
316316

317+
test("reasoning signatures that are not base64 never throw while building rows", () => {
318+
const narration = Buffer.from("\x12\x01B\tnarration").toString("base64")
319+
const messages: SessionMessageInfo[] = [
320+
assistant("assistant-1", [
321+
{ type: "reasoning", text: "Gateway note", state: { signature: "not base64 -_ signature!" } },
322+
{ type: "reasoning", text: "Progress note", state: { signature: narration } },
323+
]),
324+
]
325+
const rows = reduceSessionRows(messages)
326+
327+
expect(rows.map((row) => row.type)).toEqual(["group", "part"])
328+
})
329+
317330
test("assigns stable IDs to tool rows for direct navigation", () => {
318331
const messages: SessionMessageInfo[] = [
319332
assistant("assistant-1", [

0 commit comments

Comments
 (0)