Skip to content

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

Show a joined message above the step that answers it

Fei2411139344ef8403
diff --git a/ds-bot/client.js b/ds-bot/client.js
index c248cbbc..1c8ebe1a 100644
--- a/ds-bot/client.js
+++ b/ds-bot/client.js
@@ -3,11 +3,9 @@ window.__ModuleLoader__.load({
id: 'ds-bot',
factory: (require) => {
const module = { exports: {} }
-var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
-var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
@@ -21,14 +19,6 @@ var __copyProps = (to, from, except, desc) => {
}
return to;
};
-var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
- // If the importer is in node compatibility mode or this is not an ESM
- // file that has been converted to a CommonJS file using a Babel-
- // compatible transform (i.e. "__esModule" has not been set), then set
- // "default" to the CommonJS "module.exports" for node compatibility.
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
- mod
-));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/client/index.js
@@ -1422,6 +1412,30 @@ function toolArgs(root) {
value: (key) => object()?.[key]
};
}
+var RELAY_ROLES = /* @__PURE__ */ new Set(["request", "reply", "stopped"]);
+var isRelayContext = (data) => {
+ const source = data?.source;
+ if (source === null || typeof source !== "object" || source.kind !== "bot" || source.handoff === true) return false;
+ return RELAY_ROLES.has(source.role) && typeof source.senderSessionId === "string";
+};
+var stepShows = (step) => (step?.blocks ?? []).some((block) => {
+ if (block === void 0 || block.kind === "tool-call") return false;
+ return block.kind === "text" || block.kind === "reasoning" ? String(block.text ?? "").trim() !== "" : true;
+});
+var stepHasReasoning = (step) => (step?.blocks ?? []).some((block) => block?.kind === "reasoning" && String(block.text ?? "").trim() !== "");
+var relayPart = (data, groupPart) => groupPart === void 0 || (stepHasReasoning(data) ? groupPart === "reasoning" : groupPart === "response");
+function relaysBefore(contexts, steps, step) {
+ const index = steps.findIndex((entry) => entry?.step === step?.step);
+ if (index === -1) return [];
+ let prev = -Infinity;
+ for (let cursor = index - 1; cursor >= 0; cursor -= 1) {
+ if (stepShows(steps[cursor])) {
+ prev = steps[cursor].time;
+ break;
+ }
+ }
+ return (contexts ?? []).filter((data) => isRelayContext(data) && typeof data.time === "number" && data.time >= prev && data.time < step.time);
+}
function commRunOf(order, peers, turn, hiddenTurns = []) {
const turns = [];
for (const entry of order) {
@@ -2456,13 +2470,6 @@ var CONVERSATION_CSS = `
.bt-event-whole>span:first-child{margin-right:2px}
/* One button cannot wrap like separate parts, so a long name is cut to fit the chat. */
.bt-event-whole>.bt-event-name{flex:0 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
-.bt-ctx{min-width:0}
-.bt-ctx-chev{color:var(--bt-ink-3)}
-.bt-ctx-sep{background:var(--bt-ink-3);border-radius:1px;flex:none;width:2px;height:2px;margin:0 8px}
-.bt-ctx-src,.bt-ctx-summary{min-width:0;color:var(--bt-ink-3);font-size:12px;line-height:24px;white-space:nowrap;text-overflow:ellipsis;overflow:hidden}
-.bt-ctx-src{flex:none}
-.bt-ctx-summary{flex:auto}
-.bt-ctx-body{box-sizing:border-box;width:calc(100% - 22px);max-height:141px;margin:4px 0 0 22px;padding:10px 16px 12px 12px;border-radius:8px;background:var(--bt-bubble);color:var(--bt-ink-3);font:400 11px/16px var(--ds-font-family-code,monospace);overflow:auto;white-space:pre-wrap;word-break:break-word}
.bt-time-sep{display:flex;justify-content:center;align-items:center;height:28px;margin:14px 0 8px;font-size:12px;line-height:16px;color:var(--bt-ink-2);white-space:nowrap}
[class*="_scroll"]>[class*="_column"]::before{content:var(--bt-first-sep,none);display:block;flex:none;height:28px;margin:17px 0 12px;font-size:12px;line-height:28px;text-align:center;color:var(--bt-ink-2);white-space:nowrap}
.bt-activity{display:flex;align-items:center;gap:10px;margin:8px 0 4px 2px;font-size:14px;color:var(--bt-ink-2)}
@@ -3609,7 +3616,6 @@ var stepReasoning = (step) => step.blocks.filter((block) => block.kind === "reas
var import_react6 = require("react");
var import_react_dom = require("react-dom");
var import_dsh_client_ui_primitives = require("@deepseek-ai/dsh-client-ui-primitives");
-var dshPrimitives = __toESM(require("@deepseek-ai/dsh-client-ui-primitives"), 1);
var mdLabels = () => ({ code: { copyLabel: t("Copy"), copiedLabel: t("Copied") }, footnotes: t("Footnotes") });
function Bubbles({ texts: texts2, roster, selfId, actions, streaming, sessionId, msgKey, useUi, lead }) {
const onClick = (event) => {
@@ -3739,22 +3745,38 @@ function ThinkingRow({ text }) {
(0, import_react6.createElement)("div", { className: "bt-think-text" }, text)
);
}
-function AssistantCell({ node, groupPart, sessionId, useRoster, useUi, useTurnSteps, actions }) {
+function AssistantCell({ node, groupPart, sessionId, useRoster, useUi, useTurnSteps, useTurnContext, actions }) {
const roster = useRoster((value) => value);
const data = node.data;
const steps = useTurnSteps(String(data.turn));
+ const contexts = useTurnContext(String(data.turn));
const hidden = Boolean(roster.roomsById[sessionId]) || isHiddenTurn(roster, sessionId, data.turn);
const texts2 = groupPart === "reasoning" ? [] : data.blocks.filter((block) => block.kind === "text" && block.text.trim() !== "").map((block) => block.text);
const running = data.status === "running";
useLiveNote(actions, sessionId, `text:${node.key ?? data.seq}`, !hidden && running && texts2.length > 0 ? { text: true } : null);
if (hidden) return null;
const reasoning = groupPart === "response" ? "" : turnReasoning(steps, data);
- if (texts2.length === 0 && !reasoning) return null;
+ const relays = relayPart(data, groupPart) ? relaysBefore(contexts, steps, data) : [];
+ if (texts2.length === 0 && !reasoning && relays.length === 0) return null;
+ const selfId = roster.byId[sessionId]?.id ?? sessionId;
return (0, import_react6.createElement)(
import_react6.Fragment,
null,
+ relays.map((relay) => {
+ const source = relay.source;
+ const sender = roster.byId[source.senderSessionId] ?? { id: source.senderSessionId, name: source.senderName ?? t("a Bot"), color: "gray" };
+ return (0, import_react6.createElement)(EventLine, {
+ key: relay.seq,
+ prefix: source.role === "stopped" ? t("Stopped by") : source.role === "reply" ? t("Reply from") : t("Message from"),
+ bots: [sender],
+ onOpen: () => {
+ if (sender.id) actions.openExchange(selfId, sender.id);
+ },
+ whole: true
+ });
+ }),
reasoning ? (0, import_react6.createElement)(ThinkingRow, { text: reasoning }) : null,
- texts2.length ? (0, import_react6.createElement)(Bubbles, { texts: texts2, roster, selfId: roster.byId[sessionId]?.id ?? sessionId, actions, streaming: running, sessionId, msgKey: `${sessionId}:${data.turn}:${node.key ?? data.seq ?? ""}`, useUi }) : null
+ texts2.length ? (0, import_react6.createElement)(Bubbles, { texts: texts2, roster, selfId, actions, streaming: running, sessionId, msgKey: `${sessionId}:${data.turn}:${node.key ?? data.seq ?? ""}`, useUi }) : null
);
}
function EventLine({ prefix, bots, joiner = t("and"), onOpen, whole = false }) {
@@ -3989,61 +4011,6 @@ function TriggerCell({ node, sessionId, useRoster, useSessions, useTurnClock, us
return (0, import_react6.createElement)("div", { className: "bt-event" }, contentText(data.content).slice(0, 80) || t("Update"));
}
}
-function ContextCell({ node, sessionId, useRoster, actions, t: chatT }) {
- const roster = useRoster((value) => value);
- const data = node.data;
- const source = data.source !== null && typeof data.source === "object" ? data.source : {};
- const selfId = roster.byId[sessionId]?.id ?? sessionId;
- if (source.kind === "bot") {
- if (source.handoff === true || source.role === "kickoff" || source.role === "room" || source.role === "secret") return null;
- if ((source.role === "request" || source.role === "reply" || source.role === "stopped") && typeof source.senderSessionId === "string") {
- const sender = roster.byId[source.senderSessionId] ?? { id: source.senderSessionId, name: source.senderName ?? t("a Bot"), color: "gray" };
- return (0, import_react6.createElement)(EventLine, {
- prefix: source.role === "stopped" ? t("Stopped by") : source.role === "reply" ? t("Reply from") : t("Message from"),
- bots: [sender],
- onOpen: () => {
- if (sender.id) actions.openExchange(selfId, sender.id);
- },
- whole: true
- });
- }
- }
- return (0, import_react6.createElement)(ContextRow, { node, chatT: chatT ?? t });
-}
-var InjectionIcon = dshPrimitives.IconContextInjectionOutlineRegular ?? dshPrimitives.IconContextInjectionOutline16;
-var RecallIcon = dshPrimitives.ReferenceIconRegular ?? dshPrimitives.ReferenceIcon;
-function ContextRow({ node, chatT }) {
- const [open, setOpen] = (0, import_react6.useState)(false);
- const data = node.data;
- const source = data.source !== null && typeof data.source === "object" ? data.source : {};
- const producer = data.producer ?? data.provenance ?? { role: "inject", label: null };
- const label = typeof producer.label === "string" && producer.label !== "" ? producer.label : null;
- const summary = data.form === "notice" && typeof source.summary === "string" && source.summary !== "" ? source.summary : null;
- const recall = producer.role === "recall";
- return (0, import_react6.createElement)(import_dsh_client_ui_primitives.DisclosureRow, {
- className: "bt-ctx",
- icon: recall ? (0, import_react6.createElement)("span", null, (0, import_react6.createElement)(RecallIcon, { kind: "session" })) : (0, import_react6.createElement)(InjectionIcon, { size: 14 }),
- chevronClassName: "bt-ctx-chev",
- title: chatT(recall ? "message.contextRecall" : "message.contextInjection"),
- collapsedContent: label === null ? void 0 : (0, import_react6.createElement)(
- import_react6.Fragment,
- null,
- (0, import_react6.createElement)("span", { className: "bt-ctx-sep", "aria-hidden": true }),
- (0, import_react6.createElement)("span", { className: "bt-ctx-src" }, label),
- summary === null ? null : (0, import_react6.createElement)(
- import_react6.Fragment,
- null,
- (0, import_react6.createElement)("span", { className: "bt-ctx-sep", "aria-hidden": true }),
- (0, import_react6.createElement)("span", { className: "bt-ctx-summary" }, summary)
- )
- ),
- keepContentWhenOpen: true,
- open,
- expandable: true,
- expandOnRowClick: true,
- onToggle: () => setOpen((value) => !value)
- }, (0, import_react6.createElement)("div", { className: "bt-ctx-body" }, contentText(data.content)));
-}
function NewDivider() {
return (0, import_react6.createElement)("div", { className: "bt-new-sep", role: "separator", "aria-label": t("New messages") }, (0, import_react6.createElement)("span", null, t("New")));
}
@@ -12903,6 +12870,11 @@ function apply(ctx) {
const snapshot = chat.getSnapshot();
if (snapshot === void 0) throw new Error("ds-bot: Chat target is unavailable");
return snapshot.nodes.turnDataSource(Number(turn), "assistant-step");
+ },
+ turnContext: (turn) => {
+ const snapshot = chat.getSnapshot();
+ if (snapshot === void 0) throw new Error("ds-bot: Chat target is unavailable");
+ return snapshot.nodes.turnDataSource(Number(turn), "context");
}
} };
};
@@ -12970,7 +12942,6 @@ function apply(ctx) {
shadow("conversation.session.header", { priority: -10, inject: face }, HeaderPill),
shadow("conversation.chat.node", { key: "assistant-step", priority: -10, locale: "chat", inject: assistantFace }, AssistantCell),
shadow("conversation.chat.node", { key: "turn-trigger", priority: -10, locale: "chat", inject: face }, TriggerCell),
- shadow("conversation.chat.node", { key: "context", priority: -10, locale: "chat", inject: face }, ContextCell),
shadow("conversation.chat.node", { key: "tool-call", priority: -10, locale: "chat", inject: face }, ToolCell),
shadow("conversation.chat.node", { key: "turn-process", priority: -10, locale: "chat", inject: face }, TurnProcessCell),
shadow("conversation.chat.node", { key: "turn-tail", priority: -10, locale: "chat", inject: face }, TurnTailCell),
diff --git a/ds-bot/dev/mock-llm.mjs b/ds-bot/dev/mock-llm.mjs
index 27f2e0b6..56528947 100644
--- a/ds-bot/dev/mock-llm.mjs
+++ b/ds-bot/dev/mock-llm.mjs
@@ -158,9 +158,9 @@ function decide(body) {
const call = [...messages].reverse().find(m => m.role === 'assistant' && Array.isArray(m.content) && m.content.some(b => b.type === 'tool_use'))
const used = call?.content.find(b => b.type === 'tool_use' && b.id === result.tool_use_id) ?? call?.content.find(b => b.type === 'tool_use')
// "长任务 N [K]": N steps in one turn, each adding about K thousand characters (default 4).
- const openerAt = messages.findLastIndex(m => m.role === 'user' && !isResults(m) && /^长任务\s*\d+/.test(textOf(m.content)))
+ const openerAt = messages.findLastIndex(m => m.role === 'user' && !isResults(m) && /^长任务\s*\d+/.test(textOf(m.content).trimStart()))
if (openerAt !== -1 && used?.name === 'list_bots') {
- const [, steps, size = 4] = /^长任务\s*(\d+)(?:\s+(\d+))?/.exec(textOf(messages[openerAt].content)).map(Number)
+ const [, steps, size = 4] = /^长任务\s*(\d+)(?:\s+(\d+))?/.exec(textOf(messages[openerAt].content).trimStart()).map(Number)
const done = messages.slice(openerAt + 1).filter(isResults).length
if (done < steps) return [text(filler(size * 1000, `步骤${done + 1}`)), tool('list_bots', {})]
return [text(`长任务做完了,一共 ${done} 步。`)]
@@ -234,9 +234,9 @@ function decide(body) {
// "长任务" keeps stepping when a Bot message splices into its turn (a relayed
// note); only a fresh opener or "[Stopped by" ends it. A spliced "[Message
// from X]" also gets a one-line acknowledgement, as its joined reply's text.
- const longOpener = messages.findLastIndex(m => m.role === 'user' && !isResults(m) && /^长任务\s*\d+/.test(textOf(m.content)))
+ const longOpener = messages.findLastIndex(m => m.role === 'user' && !isResults(m) && /^长任务\s*\d+/.test(textOf(m.content).trimStart()))
if (longOpener !== -1 && /^\[(?:Message|Reply) from /.test(userText)) {
- const [, steps, size = 4] = /^长任务\s*(\d+)(?:\s+(\d+))?/.exec(textOf(messages[longOpener].content)).map(Number)
+ const [, steps, size = 4] = /^长任务\s*(\d+)(?:\s+(\d+))?/.exec(textOf(messages[longOpener].content).trimStart()).map(Number)
const done = messages.slice(longOpener + 1).filter(isResults).length
if (done < steps) {
const joined = /^\[Message from ([^\]]+)\]/.exec(userText)?.[1]
diff --git a/ds-bot/src/client/cells.js b/ds-bot/src/client/cells.js
index 04a4f544..789f778b 100644
--- a/ds-bot/src/client/cells.js
+++ b/ds-bot/src/client/cells.js
@@ -1,9 +1,8 @@
import { createElement as h, Fragment, useEffect, useLayoutEffect, useRef, useState } from 'react'
import { createPortal } from 'react-dom'
-import { DisclosureRow, MarkdownText } from '@deepseek-ai/dsh-client-ui-primitives'
-import * as dshPrimitives from '@deepseek-ai/dsh-client-ui-primitives'
+import { MarkdownText } from '@deepseek-ai/dsh-client-ui-primitives'
import { inkText } from './inks.js'
-import { linkMentions, mentionTarget, dayLabel, contentText, stripHeader, isHiddenTurn, commRunOf, toolName, toolArgs, reminderPrompts } from './text.js'
+import { linkMentions, mentionTarget, dayLabel, contentText, stripHeader, isHiddenTurn, relaysBefore, relayPart, commRunOf, toolName, toolArgs, reminderPrompts } from './text.js'
import { SmileIcon, ReplyIcon, DotsIcon, CheckIcon, DownloadIcon, CopyIcon, MemoryIcon } from './icons.js'
import { colorOf, toolState, BotMark, RoomAvatar } from './mark.js'
import { AnsweredCell, SettledQuestion, PendingQuestion } from './questions.js'
@@ -107,10 +106,11 @@ function ThinkingRow({ text }) {
h('div', { className: 'bt-think-text' }, text))
}
-export function AssistantCell({ node, groupPart, sessionId, useRoster, useUi, useTurnSteps, actions }) {
+export function AssistantCell({ node, groupPart, sessionId, useRoster, useUi, useTurnSteps, useTurnContext, actions }) {
const roster = useRoster(value => value)
const data = node.data
const steps = useTurnSteps(String(data.turn))
+ const contexts = useTurnContext(String(data.turn))
const hidden = Boolean(roster.roomsById[sessionId]) || isHiddenTurn(roster, sessionId, data.turn)
const texts = groupPart === 'reasoning' ? [] : data.blocks.filter(block => block.kind === 'text' && block.text.trim() !== '').map(block => block.text)
const running = data.status === 'running'
@@ -118,10 +118,26 @@ export function AssistantCell({ node, groupPart, sessionId, useRoster, useUi, us
useLiveNote(actions, sessionId, `text:${node.key ?? data.seq}`, !hidden && running && texts.length > 0 ? { text: true } : null)
if (hidden) return null
const reasoning = groupPart === 'response' ? '' : turnReasoning(steps, data)
- if (texts.length === 0 && !reasoning) return null
+ // A relay spliced mid-turn is a 'context' node, hidden from the chat flow on
+ // DSH 0.2; the step that answers it shows the event line where it was read,
+ // once, in the step's first cell.
+ const relays = relayPart(data, groupPart) ? relaysBefore(contexts, steps, data) : []
+ if (texts.length === 0 && !reasoning && relays.length === 0) return null
+ const selfId = roster.byId[sessionId]?.id ?? sessionId
return h(Fragment, null,
+ relays.map(relay => {
+ const source = relay.source
+ const sender = roster.byId[source.senderSessionId] ?? { id: source.senderSessionId, name: source.senderName ?? t('a Bot'), color: 'gray' }
+ return h(EventLine, {
+ key: relay.seq,
+ prefix: source.role === 'stopped' ? t('Stopped by') : source.role === 'reply' ? t('Reply from') : t('Message from'),
+ bots: [sender],
+ onOpen: () => { if (sender.id) actions.openExchange(selfId, sender.id) },
+ whole: true,
+ })
+ }),
reasoning ? h(ThinkingRow, { text: reasoning }) : null,
- texts.length ? h(Bubbles, { texts, roster, selfId: roster.byId[sessionId]?.id ?? sessionId, actions, streaming: running, sessionId, msgKey: `${sessionId}:${data.turn}:${node.key ?? data.seq ?? ''}`, useUi }) : null)
+ texts.length ? h(Bubbles, { texts, roster, selfId, actions, streaming: running, sessionId, msgKey: `${sessionId}:${data.turn}:${node.key ?? data.seq ?? ''}`, useUi }) : null)
}
function EventLine({ prefix, bots, joiner = t('and'), onOpen, whole = false }) {
@@ -343,68 +359,6 @@ export function TriggerCell({ node, sessionId, useRoster, useSessions, useTurnCl
}
}
-// A message that joined a running turn renders as a 'context' node (the
-// 'turn-trigger' key is only a turn's opener). A Bot's request shows as the same
-// event line a trigger gets, but it names no peer and opens no comm run: the
-// turn keeps its own course and answers the joiner directly. Every other
-// context node re-creates DSH's collapsed context row: a keyed slot has no
-// fallback to the renderer this registration shadows, so this one covers them.
-export function ContextCell({ node, sessionId, useRoster, actions, t: chatT }) {
- const roster = useRoster(value => value)
- const data = node.data
- const source = data.source !== null && typeof data.source === 'object' ? data.source : {}
- const selfId = roster.byId[sessionId]?.id ?? sessionId
- if (source.kind === 'bot') {
- if (source.handoff === true || source.role === 'kickoff' || source.role === 'room' || source.role === 'secret') return null
- if ((source.role === 'request' || source.role === 'reply' || source.role === 'stopped') && typeof source.senderSessionId === 'string') {
- const sender = roster.byId[source.senderSessionId] ?? { id: source.senderSessionId, name: source.senderName ?? t('a Bot'), color: 'gray' }
- return h(EventLine, {
- prefix: source.role === 'stopped' ? t('Stopped by') : source.role === 'reply' ? t('Reply from') : t('Message from'),
- bots: [sender],
- onOpen: () => { if (sender.id) actions.openExchange(selfId, sender.id) },
- whole: true,
- })
- }
- }
- return h(ContextRow, { node, chatT: chatT ?? t })
-}
-
-// These icons were renamed from *16 / unsuffixed to *Regular/*Medium in dsh
-// 0.2.x; whichever name the runtime's primitives expose wins.
-const InjectionIcon = dshPrimitives.IconContextInjectionOutlineRegular ?? dshPrimitives.IconContextInjectionOutline16
-const RecallIcon = dshPrimitives.ReferenceIconRegular ?? dshPrimitives.ReferenceIcon
-
-// The collapsed context row DSH shows for injected content: icon, title, a
-// producer label and an optional one-line notice summary, expanding to the
-// message text in a bounded box. The projected `producer` is `provenance`
-// before dsh 0.2.x.
-function ContextRow({ node, chatT }) {
- const [open, setOpen] = useState(false)
- const data = node.data
- const source = data.source !== null && typeof data.source === 'object' ? data.source : {}
- const producer = data.producer ?? data.provenance ?? { role: 'inject', label: null }
- const label = typeof producer.label === 'string' && producer.label !== '' ? producer.label : null
- const summary = data.form === 'notice' && typeof source.summary === 'string' && source.summary !== '' ? source.summary : null
- const recall = producer.role === 'recall'
- return h(DisclosureRow, {
- className: 'bt-ctx',
- icon: recall ? h('span', null, h(RecallIcon, { kind: 'session' })) : h(InjectionIcon, { size: 14 }),
- chevronClassName: 'bt-ctx-chev',
- title: chatT(recall ? 'message.contextRecall' : 'message.contextInjection'),
- collapsedContent: label === null ? undefined : h(Fragment, null,
- h('span', { className: 'bt-ctx-sep', 'aria-hidden': true }),
- h('span', { className: 'bt-ctx-src' }, label),
- summary === null ? null : h(Fragment, null,
- h('span', { className: 'bt-ctx-sep', 'aria-hidden': true }),
- h('span', { className: 'bt-ctx-summary' }, summary))),
- keepContentWhenOpen: true,
- open,
- expandable: true,
- expandOnRowClick: true,
- onToggle: () => setOpen(value => !value),
- }, h('div', { className: 'bt-ctx-body' }, contentText(data.content)))
-}
-
function NewDivider() {
return h('div', { className: 'bt-new-sep', role: 'separator', 'aria-label': t('New messages') }, h('span', null, t('New')))
}
diff --git a/ds-bot/src/client/index.js b/ds-bot/src/client/index.js
index 19442a9f..c92bf0b4 100644
--- a/ds-bot/src/client/index.js
+++ b/ds-bot/src/client/index.js
@@ -13,7 +13,7 @@ import { CHATS_SOURCE, atSources } from './at-menu.js'
import { VOICE_BUNDLE } from './speech.js'
import { sameVersion } from './dsh-offer.js'
import { AnsweredCell, QuestionCard, QuestionDock } from './questions.js'
-import { AssistantCell, TriggerCell, ContextCell, TurnProcessCell, Nothing, TurnTailCell, ToolCell } from './cells.js'
+import { AssistantCell, TriggerCell, TurnProcessCell, Nothing, TurnTailCell, ToolCell } from './cells.js'
import { Overlays } from './overlays.js'
import { createBotBrowsers, serveBrowserReads } from './bot-browsers.js'
import { BROWSER_CSS } from './browser-pane.js'
@@ -690,6 +690,11 @@ export function apply(ctx) {
if (snapshot === undefined) throw new Error('ds-bot: Chat target is unavailable')
return snapshot.nodes.turnDataSource(Number(turn), 'assistant-step')
},
+ turnContext: (turn) => {
+ const snapshot = chat.getSnapshot()
+ if (snapshot === undefined) throw new Error('ds-bot: Chat target is unavailable')
+ return snapshot.nodes.turnDataSource(Number(turn), 'context')
+ },
} }
}
@@ -764,7 +769,6 @@ export function apply(ctx) {
shadow('conversation.session.header', { priority: -10, inject: face }, HeaderPill),
shadow('conversation.chat.node', { key: 'assistant-step', priority: -10, locale: 'chat', inject: assistantFace }, AssistantCell),
shadow('conversation.chat.node', { key: 'turn-trigger', priority: -10, locale: 'chat', inject: face }, TriggerCell),
- shadow('conversation.chat.node', { key: 'context', priority: -10, locale: 'chat', inject: face }, ContextCell),
shadow('conversation.chat.node', { key: 'tool-call', priority: -10, locale: 'chat', inject: face }, ToolCell),
shadow('conversation.chat.node', { key: 'turn-process', priority: -10, locale: 'chat', inject: face }, TurnProcessCell),
shadow('conversation.chat.node', { key: 'turn-tail', priority: -10, locale: 'chat', inject: face }, TurnTailCell),
diff --git a/ds-bot/src/client/styles.js b/ds-bot/src/client/styles.js
index 65160151..1d63c888 100644
--- a/ds-bot/src/client/styles.js
+++ b/ds-bot/src/client/styles.js
@@ -792,13 +792,6 @@ export const CONVERSATION_CSS = `
.bt-event-whole>span:first-child{margin-right:2px}
/* One button cannot wrap like separate parts, so a long name is cut to fit the chat. */
.bt-event-whole>.bt-event-name{flex:0 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
-.bt-ctx{min-width:0}
-.bt-ctx-chev{color:var(--bt-ink-3)}
-.bt-ctx-sep{background:var(--bt-ink-3);border-radius:1px;flex:none;width:2px;height:2px;margin:0 8px}
-.bt-ctx-src,.bt-ctx-summary{min-width:0;color:var(--bt-ink-3);font-size:12px;line-height:24px;white-space:nowrap;text-overflow:ellipsis;overflow:hidden}
-.bt-ctx-src{flex:none}
-.bt-ctx-summary{flex:auto}
-.bt-ctx-body{box-sizing:border-box;width:calc(100% - 22px);max-height:141px;margin:4px 0 0 22px;padding:10px 16px 12px 12px;border-radius:8px;background:var(--bt-bubble);color:var(--bt-ink-3);font:400 11px/16px var(--ds-font-family-code,monospace);overflow:auto;white-space:pre-wrap;word-break:break-word}
.bt-time-sep{display:flex;justify-content:center;align-items:center;height:28px;margin:14px 0 8px;font-size:12px;line-height:16px;color:var(--bt-ink-2);white-space:nowrap}
[class*="_scroll"]>[class*="_column"]::before{content:var(--bt-first-sep,none);display:block;flex:none;height:28px;margin:17px 0 12px;font-size:12px;line-height:28px;text-align:center;color:var(--bt-ink-2);white-space:nowrap}
.bt-activity{display:flex;align-items:center;gap:10px;margin:8px 0 4px 2px;font-size:14px;color:var(--bt-ink-2)}
diff --git a/ds-bot/src/client/text.js b/ds-bot/src/client/text.js
index 2107be10..9ab52280 100644
--- a/ds-bot/src/client/text.js
+++ b/ds-bot/src/client/text.js
@@ -125,6 +125,49 @@ export function toolArgs(root) {
}
}
+// A relay context is a Bot-to-Bot request, reply or stop notice injected into the
+// model's history. ds-bot's own package sources (kickoff, room, secret, handoff
+// parts) are not events in the chat.
+const RELAY_ROLES = new Set(['request', 'reply', 'stopped'])
+export const isRelayContext = (data) => {
+ const source = data?.source
+ if (source === null || typeof source !== 'object' || source.kind !== 'bot' || source.handoff === true) return false
+ return RELAY_ROLES.has(source.role) && typeof source.senderSessionId === 'string'
+}
+
+// 'context' chat nodes never reach the flow on DSH 0.2, so a relay spliced into
+// a running turn would be invisible; the step that answers it renders the line.
+// A relay attaches to the next step that renders a cell: tool-only steps mount
+// nothing (ui-chat gives them no visible node), so `prev` is the previous step
+// with visible content, not the previous step in the list.
+// `contexts` and `steps` are the turn's turnDataSource lists (anchor order) and
+// `step` is the rendering step's own data. A step is found by its number: the
+// cell's node data and the source's entries can be different snapshot objects.
+const stepShows = (step) => (step?.blocks ?? []).some(block => {
+ // ui-chat's mount rule for a step node: non-empty reasoning, or reply content
+ // (`hasAssistantReplyContent`); a tool call alone keeps the node hidden.
+ if (block === undefined || block.kind === 'tool-call') return false
+ return block.kind === 'text' || block.kind === 'reasoning' ? String(block.text ?? '').trim() !== '' : true
+})
+const stepHasReasoning = (step) => (step?.blocks ?? []).some(block => block?.kind === 'reasoning' && String(block.text ?? '').trim() !== '')
+// The step's own cells: a reasoning step emits a 'reasoning' part and a step
+// with reply content a 'response' part, or both. The line belongs in the first
+// of them — before the thinking row, else before the reply.
+export const relayPart = (data, groupPart) => groupPart === undefined || (stepHasReasoning(data) ? groupPart === 'reasoning' : groupPart === 'response')
+export function relaysBefore(contexts, steps, step) {
+ const index = steps.findIndex(entry => entry?.step === step?.step)
+ if (index === -1) return []
+ let prev = -Infinity
+ for (let cursor = index - 1; cursor >= 0; cursor -= 1) {
+ if (stepShows(steps[cursor])) { prev = steps[cursor].time; break }
+ }
+ // The lower bound is inclusive: a relay steered right after the previous
+ // step's assistant/message can share its millisecond, and it still belongs to
+ // this step — its own model call follows the previous one. The upper bound
+ // stays strict: a step's time is its settled message or first visible token.
+ return (contexts ?? []).filter(data => isRelayContext(data) && typeof data.time === 'number' && data.time >= prev && data.time < step.time)
+}
+
// Back-to-back Bot-to-Bot messages fold into one "N messages with" line. A
// hidden exchange turn holds a request and its reply; a visible one (a reply, or a
// request answered to the user) adds only its trigger and ends the run. Group turns
diff --git a/ds-bot/test/tool-node.test.js b/ds-bot/test/tool-node.test.js
index 71203c43..02ad1add 100644
--- a/ds-bot/test/tool-node.test.js
+++ b/ds-bot/test/tool-node.test.js
@@ -1,6 +1,6 @@
import assert from 'node:assert/strict'
import { test } from 'node:test'
-import { toolArgs, toolName } from '../src/client/text.js'
+import { relayPart, relaysBefore, toolArgs, toolName } from '../src/client/text.js'
const argsRaw = JSON.stringify({ name: 'GITHUB_TOKEN', purpose: 'GitHub', questions: [{ question: 'Which?' }] })
@@ -35,3 +35,75 @@ test('an empty name falls back to the call, and unreadable arguments read as abs
assert.equal(toolArgs({ kind: 'tool-result', call: null }).value('x'), undefined)
assert.equal(toolArgs({ argsRaw: '[1]' }).value('0'), undefined)
})
+
+const relay = (time, role = 'request', over = {}) => ({
+ time, source: { kind: 'bot', role, senderSessionId: 'session-sender', ...over },
+})
+const stepAt = (step, time, text = 'some text') => ({ step, time, blocks: text === null ? [{ kind: 'tool-call' }] : [{ kind: 'text', text }] })
+
+test('a relay between steps attaches to the step that follows it only', () => {
+ const steps = [stepAt(1, 10), stepAt(2, 20), stepAt(3, 30)]
+ const contexts = [relay(15), relay(25)]
+ assert.equal(relaysBefore(contexts, steps, steps[0]).length, 0)
+ assert.deepEqual(relaysBefore(contexts, steps, steps[1]), [contexts[0]])
+ assert.deepEqual(relaysBefore(contexts, steps, steps[2]), [contexts[1]])
+})
+
+test('a relay before a tool-only step attaches to the next step that renders', () => {
+ const steps = [stepAt(1, 10), stepAt(2, 20, null), stepAt(3, 30, null), stepAt(4, 40)]
+ const contexts = [relay(15)]
+ assert.deepEqual(relaysBefore(contexts, steps, steps[3]), [contexts[0]])
+})
+
+test('a relay before the first step attaches to it', () => {
+ const steps = [stepAt(1, 10), stepAt(2, 20)]
+ const contexts = [relay(5)]
+ assert.deepEqual(relaysBefore(contexts, steps, steps[0]), [contexts[0]])
+ assert.equal(relaysBefore(contexts, steps, steps[1]).length, 0)
+})
+
+test('the step is found by its number when the cell holds a different copy', () => {
+ const steps = [stepAt(1, 10), stepAt(2, 20), stepAt(3, 30)]
+ const contexts = [relay(15)]
+ assert.deepEqual(relaysBefore(contexts, steps, { ...steps[1] }), [contexts[0]])
+})
+
+test('a relay sharing the previous step’s time attaches to the next step', () => {
+ const steps = [stepAt(1, 10), stepAt(2, 20)]
+ const contexts = [relay(10)]
+ assert.deepEqual(relaysBefore(contexts, steps, steps[1]), [contexts[0]])
+})
+
+test('relayPart puts the line in the step’s first cell', () => {
+ const thinking = { step: 1, time: 10, blocks: [{ kind: 'reasoning', text: 'thought' }, { kind: 'text', text: 'reply' }] }
+ const plain = { step: 2, time: 20, blocks: [{ kind: 'text', text: 'reply' }] }
+ const blank = { step: 3, time: 30, blocks: [{ kind: 'reasoning', text: ' ' }] }
+ assert.equal(relayPart(thinking, 'reasoning'), true)
+ assert.equal(relayPart(thinking, 'response'), false)
+ assert.equal(relayPart(plain, 'response'), true)
+ assert.equal(relayPart(plain, 'reasoning'), false)
+ assert.equal(relayPart(blank, 'response'), true)
+ assert.equal(relayPart(thinking, undefined), true)
+ assert.equal(relayPart(plain, undefined), true)
+})
+
+test('two relays before one step both return, in order', () => {
+ const steps = [stepAt(1, 10), stepAt(2, 30)]
+ const contexts = [relay(12, 'request'), relay(18, 'reply')]
+ assert.deepEqual(relaysBefore(contexts, steps, steps[1]), [contexts[0], contexts[1]])
+})
+
+test('non-relay context and ds-bot package sources are ignored', () => {
+ const steps = [stepAt(1, 10), stepAt(2, 30)]
+ const contexts = [
+ relay(12, 'request', { handoff: true }),
+ relay(14, 'kickoff'),
+ relay(16, 'room'),
+ relay(18, 'secret'),
+ relay(22, 'request', { senderSessionId: undefined }),
+ { time: 24, source: { kind: 'agent-instructions' } },
+ { time: 26, source: null },
+ relay(28, 'request'),
+ ]
+ assert.deepEqual(relaysBefore(contexts, steps, steps[1]), [contexts[7]])
+})