Skip to content

A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.

Draw group replies even when the saved relay is unreadable

Fei2411c54aa10e3174
diff --git a/ds-bot/client.js b/ds-bot/client.js
index 0c7d9bf8..b94b1bdc 100644
--- a/ds-bot/client.js
+++ b/ds-bot/client.js
@@ -620,6 +620,7 @@ var ZH = {
"{name} looked up its own chat for “{text}”": "{name} 在自己的对话里查找「{text}」",
"{name} is typing…": "{name} 正在输入…",
"{name} didn't answer in time": "{name} 没有及时回应",
+ "The group replies could not be shown": "群里的回复显示不出来",
"Paused after {count} Bot relays. Waiting: {names}": "Bot 之间已接力 {count} 次,先停下了。还在等:{names}",
"Continue": "继续",
"{name} paused for your approval": "{name} 停下来等你批准",
@@ -7808,6 +7809,48 @@ function useLiveNote(actions, sessionId, id, entry) {
return () => actions.noteLive(sessionId, id, null);
}, [sessionId, id, key]);
}
+var RELAY_LIST = /"replies"\s*:\s*\[/;
+function parseReplies(text) {
+ try {
+ return { replies: JSON.parse(text).replies ?? [], broken: false };
+ } catch {
+ }
+ const replies = [];
+ const head = RELAY_LIST.exec(text);
+ if (head) {
+ let depth = 0;
+ let from = -1;
+ let inString = false;
+ let escaped = false;
+ for (let i = head.index + head[0].length; i < text.length; i += 1) {
+ const ch = text[i];
+ if (inString) {
+ if (escaped) escaped = false;
+ else if (ch === "\\") escaped = true;
+ else if (ch === '"') inString = false;
+ continue;
+ }
+ if (ch === '"') {
+ inString = true;
+ continue;
+ }
+ if (ch === "{") {
+ if (depth === 0) from = i;
+ depth += 1;
+ } else if (ch === "}") {
+ depth -= 1;
+ if (depth === 0 && from >= 0) {
+ try {
+ replies.push(JSON.parse(text.slice(from, i + 1)));
+ } catch {
+ }
+ from = -1;
+ }
+ } else if (ch === "]" && depth === 0) break;
+ }
+ }
+ return { replies, broken: true };
+}
function GroupReplies({ sessionId, callId, done, content, roster, actions, useUi, useWork }) {
const [live, setLive] = (0, import_react12.useState)({ replies: [], speaking: null });
(0, import_react12.useEffect)(() => {
@@ -7833,17 +7876,18 @@ function GroupReplies({ sessionId, callId, done, content, roster, actions, useUi
};
}, [done, sessionId, callId]);
let replies = live.replies;
+ let broken = false;
if (done) {
- try {
- replies = JSON.parse(contentText(content)).replies ?? [];
- } catch {
- replies = [];
- }
+ const parsed = parseReplies(contentText(content));
+ replies = parsed.replies.length ? parsed.replies : live.replies;
+ broken = parsed.broken;
}
const pending = done || !live.speaking ? [] : [live.speaking];
const speakerTool = useWork?.((work) => work.bots?.[live.speaking]?.tool) ?? void 0;
const speakerDoing = useWork?.((work) => work.bots?.[live.speaking]?.tool ? workPhrase(work.bots[live.speaking]) : void 0) ?? void 0;
- if (replies.length === 0 && pending.length === 0) return null;
+ if (replies.length === 0 && pending.length === 0) {
+ return broken ? (0, import_react12.createElement)("div", { className: "bt-group-replies" }, (0, import_react12.createElement)("div", { className: "bt-event" }, t("The group replies could not be shown"))) : null;
+ }
const room2 = roster.roomsById[sessionId];
return (0, import_react12.createElement)(
"div",
diff --git a/ds-bot/src/client/cells.js b/ds-bot/src/client/cells.js
index 81377b96..1722151c 100644
--- a/ds-bot/src/client/cells.js
+++ b/ds-bot/src/client/cells.js
@@ -811,6 +811,43 @@ function useLiveNote(actions, sessionId, id, entry) {
}, [sessionId, id, key])
}
+// Reads the replies of a settled group_relay result. Compaction can prune the
+// middle of a long tool result, which leaves invalid JSON: then every complete
+// reply object that survived is recovered so the turn still draws what it can.
+const RELAY_LIST = /"replies"\s*:\s*\[/
+function parseReplies(text) {
+ try { return { replies: JSON.parse(text).replies ?? [], broken: false } } catch { /* fall through */ }
+ const replies = []
+ const head = RELAY_LIST.exec(text)
+ if (head) {
+ let depth = 0
+ let from = -1
+ let inString = false
+ let escaped = false
+ for (let i = head.index + head[0].length; i < text.length; i += 1) {
+ const ch = text[i]
+ if (inString) {
+ if (escaped) escaped = false
+ else if (ch === '\\') escaped = true
+ else if (ch === '"') inString = false
+ continue
+ }
+ if (ch === '"') { inString = true; continue }
+ if (ch === '{') {
+ if (depth === 0) from = i
+ depth += 1
+ } else if (ch === '}') {
+ depth -= 1
+ if (depth === 0 && from >= 0) {
+ try { replies.push(JSON.parse(text.slice(from, i + 1))) } catch { /* partial object */ }
+ from = -1
+ }
+ } else if (ch === ']' && depth === 0) break
+ }
+ }
+ return { replies, broken: true }
+}
+
function GroupReplies({ sessionId, callId, done, content, roster, actions, useUi, useWork }) {
const [live, setLive] = useState({ replies: [], speaking: null })
useEffect(() => {
@@ -830,14 +867,21 @@ function GroupReplies({ sessionId, callId, done, content, roster, actions, useUi
return () => { stop = true; clearTimeout(timer) }
}, [done, sessionId, callId])
let replies = live.replies
+ let broken = false
if (done) {
- try { replies = JSON.parse(contentText(content)).replies ?? [] } catch { replies = [] }
+ const parsed = parseReplies(contentText(content))
+ replies = parsed.replies.length ? parsed.replies : live.replies
+ broken = parsed.broken
}
// Members speak one at a time, so only the current speaker is typing.
const pending = done || !live.speaking ? [] : [live.speaking]
const speakerTool = useWork?.(work => work.bots?.[live.speaking]?.tool) ?? undefined
const speakerDoing = useWork?.(work => (work.bots?.[live.speaking]?.tool ? workPhrase(work.bots[live.speaking]) : undefined)) ?? undefined
- if (replies.length === 0 && pending.length === 0) return null
+ if (replies.length === 0 && pending.length === 0) {
+ // A pruned tool result left nothing to draw; keep a marker row instead of an
+ // empty turn, which reads as a blank gap on a narrow first paint.
+ return broken ? h('div', { className: 'bt-group-replies' }, h('div', { className: 'bt-event' }, t('The group replies could not be shown'))) : null
+ }
const room = roster.roomsById[sessionId]
return h('div', { className: 'bt-group-replies' },
stackReplies(replies).map(({ reply, index, texts, time, duration }) => {
diff --git a/ds-bot/src/client/i18n.js b/ds-bot/src/client/i18n.js
index 3eb93caa..78d3384d 100644
--- a/ds-bot/src/client/i18n.js
+++ b/ds-bot/src/client/i18n.js
@@ -565,6 +565,7 @@ const ZH = {
'{name} looked up its own chat for “{text}”': '{name} 在自己的对话里查找「{text}」',
'{name} is typing…': '{name} 正在输入…',
"{name} didn't answer in time": '{name} 没有及时回应',
+ 'The group replies could not be shown': '群里的回复显示不出来',
'Paused after {count} Bot relays. Waiting: {names}': 'Bot 之间已接力 {count} 次,先停下了。还在等:{names}',
'Continue': '继续',
'{name} paused for your approval': '{name} 停下来等你批准',
diff --git a/ds-bot/test/tool-cells.test.js b/ds-bot/test/tool-cells.test.js
index 3af2be17..62443ca7 100644
--- a/ds-bot/test/tool-cells.test.js
+++ b/ds-bot/test/tool-cells.test.js
@@ -591,6 +591,16 @@ test('a secret in a hidden turn shows in the dock instead of nowhere', () => {
unmount()
})
+// 公开#557: compaction prunes the middle of a long relay result, leaving invalid
+// JSON — draw the replies that survived, or a marker row, never a blank turn.
+test('a pruned group relay still draws the replies that survived', () => {
+ const pruned = '{"replies":[{"botId":"writer","text":"Still here."},{"botId":"chief","text":"[... tool result middle pruned ...'
+ const out = show(call('group_relay', 'direct', { content: pruned }), { sessionId: 'room' })
+ assert.match(text(out), /Writer.*Still here\./)
+ const gone = show(call('group_relay', 'direct', { content: '{"replies":[{"botId":"writer","text":"cut' }), { sessionId: 'room' })
+ assert.match(text(gone), /The group replies could not be shown/)
+})
+
// #38: a PTC group round's replies vanished once the round ended.
test('a PTC group relay shows its replies from the sub-call, live and after reload', async () => {
const replies = [{ botId: 'writer', text: 'Hello from Writer.' }, { botId: 'chief', text: 'Hello from Chief.' }]