Skip to content

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

Let another window draw the plugin's Bot views

Fei2411aa1150769e4d
diff --git a/ds-bot/client.js b/ds-bot/client.js
index 3e7bc6a5..6593a66c 100644
--- a/ds-bot/client.js
+++ b/ds-bot/client.js
@@ -52,6 +52,7 @@ var ZH = {
"New chat": "新对话",
"New…": "新建",
"Collapse sidebar": "收起侧边栏",
+ "Expand sidebar": "展开侧边栏",
"Animation": "动画",
"Bot animation": "Bot 动画",
"Quiet": "安静",
@@ -1309,6 +1310,185 @@ function countCards(state, sessionId, callIds, delta) {
return { ...state, [sessionId]: own };
}
+// src/client/team-actions.js
+function teamActions({ call: call2, after, partFor, roster, ui: ui2, live, cards, turnClock }) {
+ return {
+ openNewChat: (mode) => {
+ ui2.set((state) => ({ ...state, newChat: mode, menu: null, palette: null }));
+ },
+ openPalette: (query = "") => {
+ ui2.set((state) => ({ ...state, palette: { query, token: Date.now() }, newChat: null, menu: null }));
+ },
+ // The token keeps a late exit timer from closing a palette opened again since.
+ closePalette: (token) => {
+ ui2.set((state) => state.palette && (token === void 0 || state.palette.token === token) ? { ...state, palette: null } : state);
+ },
+ openExchange: (a, b) => {
+ if (a && b) ui2.set((state) => ({ ...state, exchange: [a, b] }));
+ },
+ openVoice: (id) => {
+ if (id) ui2.set((state) => ({ ...state, voice: id, menu: null }));
+ },
+ closeVoice: () => {
+ ui2.set((state) => state.voice ? { ...state, voice: null } : state);
+ },
+ toggleDetails: (id, force) => {
+ ui2.set((state) => {
+ const details = force || state.details !== id || state.view !== "details" ? id : null;
+ return { ...state, renaming: false, tab: null, details, view: "details" };
+ });
+ },
+ // The open panel follows the main view; a subject with no browser (a group
+ // chat, an outside Session) settles on the details view.
+ followPanel: (id) => {
+ ui2.set((state) => {
+ if (!state.details || state.details === id) return state;
+ const view = state.view === "browser" && roster.getSnapshot().byId[id] === void 0 ? "details" : state.view;
+ return { ...state, details: id, view, renaming: false, tab: null };
+ });
+ },
+ showDetails: (id, tab = null) => {
+ ui2.set((state) => ({ ...state, details: id, view: "details", renaming: false, tab }));
+ },
+ // Opening the conversation would move focus to its composer and blur the name field.
+ renameBot: (id) => {
+ ui2.set((state) => ({ ...state, details: id, view: "details", renaming: true, tab: null }));
+ },
+ // `id` opens one Bot (page 'bots') or one group chat (page 'groups').
+ openSettings: (page = "general", id = null) => {
+ ui2.set((state) => ({ ...state, settings: { page, id }, menu: null, palette: null, newChat: null }));
+ },
+ closeSettings: () => {
+ ui2.set((state) => state.settings ? { ...state, settings: null } : state);
+ },
+ openMemory: (botId) => {
+ ui2.set((state) => ({ ...state, memory: botId, menu: null, palette: null }));
+ },
+ closeMemory: () => {
+ ui2.set((state) => state.memory ? { ...state, memory: null } : state);
+ },
+ openConnectors: () => {
+ ui2.set((state) => ({ ...state, settings: { page: "connectors", id: null }, menu: null, palette: null, newChat: null }));
+ },
+ setPanelView: (view) => {
+ if (view !== "details" && view !== "browser") return;
+ ui2.set((state) => state.details && state.view !== view ? { ...state, view } : state);
+ },
+ closePanel: () => {
+ ui2.set((state) => state.details ? { ...state, details: null, view: "details", renaming: false, tab: null } : state);
+ },
+ quote: (sessionId, text) => ui2.set((state) => ({ ...state, quote: { sessionId, text, token: Date.now() } })),
+ clearQuote: (token) => ui2.set((state) => state.quote?.token === token ? { ...state, quote: null } : state),
+ setFlags: (id, flags) => after(call2("set-flags", { id, ...flags })),
+ deleteRoom: (id) => after(call2("delete-room", { id })),
+ openMenu: (menu) => {
+ ui2.set((state) => ({ ...state, menu }));
+ },
+ closeMenu: () => {
+ ui2.set((state) => state.menu ? { ...state, menu: null } : state);
+ },
+ closeOverlay: () => {
+ ui2.set((state) => ({ ...state, newChat: null, exchange: null, details: state.newChat || state.exchange ? state.details : null }));
+ },
+ createBot: (payload) => after(call2("create-bot", payload)),
+ createRoom: (members, options = {}) => after(call2("create-room", { members, ...options })),
+ updateBot: (id, patch) => after(call2("update-bot", { id, ...patch })),
+ refreshModels: () => after(call2("models")).catch(() => {
+ }),
+ efforts: (ref) => call2("efforts", { ref }),
+ folders: () => call2("folders"),
+ folderPick: () => call2("folder-pick"),
+ folderList: (path) => call2("folder-list", { path: path ?? "" }),
+ deleteBot: (id) => after(call2("delete-bot", { id })),
+ duplicateBot: (id) => after(call2("duplicate-bot", { id })),
+ setPrefs: (prefs) => after(call2("set-prefs", prefs)),
+ setMain: (id, main = true, options = {}) => after(call2("set-main", { id, main, ...options })),
+ updateRoom: (id, patch) => after(call2("update-room", { id, ...patch })),
+ send: (sessionId, text) => after(call2("send", { sessionId: partFor(sessionId), text })),
+ answerQuestion: (sessionId, questionId, answer) => after(call2("answer-question", { sessionId: partFor(sessionId), questionId, answer })),
+ dismissQuestion: (sessionId) => after(call2("dismiss-question", { sessionId })),
+ answerApproval: (id, choice) => after(call2("approval-answer", { id, choice })),
+ stopMemberWork: (roomId, botId) => after(call2("stop-member-work", { roomId, botId })),
+ // Values go out in these requests and never come back in a response.
+ secretSet: (payload) => after(call2("secret-set", payload)),
+ secretAllow: (requestId) => after(call2("secret-allow", { requestId })),
+ secretCancel: (requestId) => after(call2("secret-cancel", { requestId })),
+ secretUpdate: (name, scope) => after(call2("secret-update", { name, scope })),
+ secretDelete: (name) => after(call2("secret-delete", { name })),
+ connectorConnect: (id, token) => after(call2("connector-connect", { id, token })),
+ connectorDisconnect: (id) => after(call2("connector-disconnect", { id })),
+ connectorRetry: (id) => after(call2("connector-retry", { id })),
+ saveCapability: (capability) => after(call2("capability-save", capability)),
+ deleteCapability: (name) => after(call2("capability-delete", { name })),
+ approveCapability: (name) => after(call2("capability-approve", { name })),
+ setBotCapability: (botId, name, attached) => after(call2("bot-capability", { botId, name, attached })),
+ schedules: () => call2("schedules"),
+ scheduleCreate: (task) => call2("schedule-create", task),
+ scheduleDelete: (sessionId, id) => call2("schedule-delete", { sessionId, id }),
+ exchange: (a, b) => call2("exchange", { a, b }).catch(() => []),
+ exchangeText: (id) => call2("exchange-text", { id }).catch(() => void 0),
+ fileText: (file) => call2("file-text", { file }).catch(() => void 0),
+ roomProgress: (roomId) => call2("room-progress", { roomId }).catch(() => []),
+ earlier: (sessionId, cursor) => call2("earlier", { sessionId, cursor: cursor ?? null }),
+ // Hours come back in this browser's time zone, so days start at local midnight.
+ usage: () => call2("usage", { timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone }),
+ // `summarize` starts a summary when the entries changed; `regenerate` always does.
+ memoryView: (botId, flags = {}) => call2("memory-view", { botId, ...flags }),
+ memoryAsk: (botId, text) => call2("memory-ask", { botId, text }),
+ memoryForget: (botId, entry) => call2("memory-forget", { botId, scope: entry.scope, topic: entry.topic, text: entry.text }),
+ diagnostics: (payload) => call2("diagnostics", payload),
+ diagnosticsLog: () => call2("diagnostics-log"),
+ diagnosticsClear: () => call2("diagnostics-clear"),
+ repoStars: () => call2("repo-stars"),
+ // A failed action away from any form (a menu, the palette) shows as a toast.
+ reportError: (error, where = "action") => {
+ noteClientError(where, error);
+ ui2.set((state) => ({ ...state, toast: { text: error?.message ?? String(error), token: Date.now() } }));
+ },
+ dismissToast: (token) => ui2.set((state) => state.toast && (token === void 0 || state.toast.token === token) ? { ...state, toast: null } : state),
+ noteTurnTime: (sessionId, turn, key, time) => {
+ if (sessionId === void 0 || !Number.isFinite(turn) || !Number.isFinite(time)) return;
+ turnClock.set((state) => {
+ const turns = state[sessionId] ?? {};
+ const entry = turns[turn] ?? {};
+ const next = key === "first" && entry.first !== void 0 ? Math.min(entry.first, time) : time;
+ if (entry[key] === next) return state;
+ return { ...state, [sessionId]: { ...turns, [turn]: { ...entry, [key]: next } } };
+ });
+ },
+ noteTurnPeer: (sessionId, turn, peerId) => {
+ if (sessionId === void 0 || !Number.isFinite(turn)) return;
+ turnClock.set((state) => {
+ const turns = state[sessionId] ?? {};
+ const entry = turns[turn] ?? {};
+ if (entry.peer === peerId) return state;
+ return { ...state, [sessionId]: { ...turns, [turn]: { ...entry, peer: peerId } } };
+ });
+ },
+ noteLive: (sessionId, id, entry) => {
+ if (sessionId === void 0) return;
+ live.set((state) => {
+ const own = state[sessionId] ?? {};
+ const prev = own[id];
+ if (entry === null ? prev === void 0 : prev !== void 0 && JSON.stringify({ ...prev, at: 0 }) === JSON.stringify({ ...entry, at: 0 })) return state;
+ const next = { ...own };
+ if (entry === null) delete next[id];
+ else next[id] = { ...entry, at: prev?.at ?? Date.now() };
+ return { ...state, [sessionId]: next };
+ });
+ },
+ noteCards: (sessionId, callIds, delta) => {
+ if (sessionId !== void 0) cards.set((state) => countCards(state, sessionId, callIds, delta));
+ },
+ clearLive: (sessionId) => live.set((state) => {
+ if (!state[sessionId]) return state;
+ const next = { ...state };
+ delete next[sessionId];
+ return next;
+ })
+ };
+}
+
// src/client/themes.js
var THEME_KEYS = ["bg", "sidebar", "bubble", "card", "text", "user", "userText", "accent"];
var THEMES = {
@@ -3078,6 +3258,9 @@ function RoomAvatar({ room: room2, roster, size = 36 }) {
);
}
+// src/client/dsh-primitives.js
+var import_dsh_client_ui_primitives = require("@deepseek-ai/dsh-client-ui-primitives");
+
// src/client/icons.js
var import_react3 = require("react");
function PlusIcon() {
@@ -3907,7 +4090,6 @@ function useFold(text, { limit = FOLD_AT, whole, live = false, markdown = true }
// src/client/cells.js
var import_react7 = require("react");
var import_react_dom = require("react-dom");
-var import_dsh_client_ui_primitives = require("@deepseek-ai/dsh-client-ui-primitives");
var mdLabels = () => ({ code: { copyLabel: t("Copy"), copiedLabel: t("Copied") }, footnotes: t("Footnotes") });
function Bubbles({ texts: texts2, roster, selfId, actions, streaming, sessionId, msgKey, useUi, lead, mentions, fold = FOLD_AT, whole }) {
const onClick = (event) => {
@@ -4254,13 +4436,6 @@ function EarlierParts({ sessionId, roster, actions }) {
observer.observe(node);
return () => observer.disconnect();
}, [view.cursor, view.loading, view.failed]);
- const selfId = roster.byId[sessionId]?.id;
- const rows = [];
- for (const item of view.items) {
- const last = rows.at(-1);
- if (item.kind === "bot" && last?.kind === "bot") last.texts.push(item.text);
- else rows.push(item.kind === "bot" ? { kind: "bot", texts: [item.text] } : item);
- }
return (0, import_react7.createElement)(
"div",
{ className: "bt-earlier", role: "feed", "aria-label": t("Earlier messages"), "aria-busy": view.loading },
@@ -4269,32 +4444,55 @@ function EarlierParts({ sessionId, roster, actions }) {
{ ref: top, className: "bt-earlier-top" },
view.loading ? (0, import_react7.createElement)(Shimmer, null, t("Loading earlier messages…")) : view.failed ? (0, import_react7.createElement)("button", { type: "button", className: "bt-soft", onClick: () => load(view.cursor) }, t("Couldn’t load earlier messages · Retry")) : view.cursor ? (0, import_react7.createElement)("button", { type: "button", className: "bt-soft", onClick: () => load(view.cursor) }, t("Load earlier")) : null
),
- rows.map((row, index) => {
- const key = rows.length - index;
- switch (row.kind) {
- case "divider":
- return (0, import_react7.createElement)(PartLine, { key, time: row.time });
- case "user":
- return (0, import_react7.createElement)(EarlierUser, { key, row });
- case "answer":
- return (0, import_react7.createElement)(AnsweredCell, { key, node: { data: row } });
- case "bot":
- return (0, import_react7.createElement)(Bubbles, { key, texts: row.texts, roster, selfId, actions, fold: FOLD_HUGE });
- case "event": {
- if (row.role === "report") return (0, import_react7.createElement)(GroupEvent, { key, prefix: t("Replies from"), room: roster.roomsById[row.roomId], name: t("a group chat"), roster, actions });
- const other = roster.byId[row.botId] ?? { id: row.botId, name: row.name ?? t("a Bot"), color: "gray" };
- const prefix = { stopped: t("Stopped by"), reply: t("Reply from") }[row.role] ?? t("Message from");
- return (0, import_react7.createElement)(EventLine, { key, prefix, bots: [other], onOpen: () => {
- if (selfId && other.id) actions.openExchange(selfId, other.id);
- }, whole: true });
- }
- default:
- return null;
- }
- }),
+ (0, import_react7.createElement)(ChatRows, { items: view.items, sessionId, roster, actions }),
(0, import_react7.createElement)(PartLine, { time: view.startedAt })
);
}
+function ChatRows({ items, sessionId, roster, actions, useUi, clock: clock4 = false }) {
+ const selfId = roster.byId[sessionId]?.id;
+ const rows = [];
+ for (const item of items) {
+ const last = rows.at(-1);
+ if (item.kind === "bot" && last?.kind === "bot") {
+ last.texts.push(item.text);
+ last.end = item.time;
+ } else rows.push(item.kind === "bot" ? { kind: "bot", texts: [item.text], time: item.time, end: item.time } : item);
+ }
+ let before;
+ return rows.flatMap((row, index) => {
+ const key = rows.length - index;
+ const shown = chatRow(row, key, { sessionId, selfId, roster, actions, useUi });
+ if (row.kind === "divider") {
+ before = void 0;
+ return [shown];
+ }
+ const pause = clock4 && Number.isFinite(row.time) && (before === void 0 || row.time - before >= SEPARATOR_GAP_MS);
+ if (Number.isFinite(row.end ?? row.time)) before = row.end ?? row.time;
+ return pause ? [(0, import_react7.createElement)("div", { key: `${key}:clock`, className: "bt-time-sep", role: "separator" }, clockLabel(row.time)), shown] : [shown];
+ });
+}
+function chatRow(row, key, { sessionId, selfId, roster, actions, useUi }) {
+ switch (row.kind) {
+ case "divider":
+ return (0, import_react7.createElement)(PartLine, { key, time: row.time });
+ case "user":
+ return (0, import_react7.createElement)(EarlierUser, { key, row });
+ case "answer":
+ return (0, import_react7.createElement)(AnsweredCell, { key, node: { data: row } });
+ case "bot":
+ return (0, import_react7.createElement)(Bubbles, { key, texts: row.texts, roster, selfId, actions, sessionId: useUi ? sessionId : void 0, msgKey: useUi ? `${sessionId}:${row.time}` : void 0, useUi, fold: FOLD_HUGE });
+ case "event": {
+ if (row.role === "report") return (0, import_react7.createElement)(GroupEvent, { key, prefix: t("Replies from"), room: roster.roomsById[row.roomId], name: t("a group chat"), roster, actions });
+ const other = roster.byId[row.botId] ?? { id: row.botId, name: row.name ?? t("a Bot"), color: "gray" };
+ const prefix = { stopped: t("Stopped by"), reply: t("Reply from") }[row.role] ?? t("Message from");
+ return (0, import_react7.createElement)(EventLine, { key, prefix, bots: [other], onOpen: () => {
+ if (selfId && other.id) actions.openExchange(selfId, other.id);
+ }, whole: true });
+ }
+ default:
+ return null;
+ }
+}
function TriggerCell({ node, sessionId, useRoster, useSessions, useTurnClock, useUi, actions }) {
const roster = useRoster((value) => value);
const data = node.data;
@@ -4941,7 +5139,6 @@ function showsDshRow(dsh, app) {
// src/client/sidebar.js
var import_react9 = require("react");
var import_react_dom3 = require("react-dom");
-var import_dsh_client_ui_primitives2 = require("@deepseek-ai/dsh-client-ui-primitives");
function useMarkedUnread(id, active, marked, actions) {
(0, import_react9.useEffect)(() => {
if (active && marked) actions.clearUnread(id);
@@ -5170,7 +5367,7 @@ function AgentRow({ agent, actions, useSessions, useSessionStatus, useUi, wide,
actions.openMenu({ kind: "agent", id: agent.id, x: event.clientX, y: event.clientY });
}
},
- (0, import_react9.createElement)("span", { className: `bt-agent-ava${running ? " bt-run" : ""}` }, (0, import_react9.createElement)(import_dsh_client_ui_primitives2.FishLogo, { size: 22 })),
+ (0, import_react9.createElement)("span", { className: `bt-agent-ava${running ? " bt-run" : ""}` }, (0, import_react9.createElement)(import_dsh_client_ui_primitives.FishLogo, { size: 22 })),
wide ? (0, import_react9.createElement)(
"span",
{ className: "bt-row-body" },
@@ -6068,17 +6265,18 @@ function ComposerPlus({ sessionId, inputActions, useRoster, actions }) {
}, [open]);
const target = roster.byId?.[sessionId]?.id ?? roster.roomsById?.[sessionId]?.id;
if (sessionId === void 0 || target === void 0) return null;
+ const fileInput = () => button.current?.closest("[data-composer-card]")?.querySelector("input[type=file]");
const toggle = () => {
if (open) {
setOpen(null);
return;
}
const rect = button.current.getBoundingClientRect();
- setOpen({ left: rect.left, bottom: window.innerHeight - rect.top + 8 });
+ setOpen({ left: rect.left, bottom: window.innerHeight - rect.top + 8, files: Boolean(fileInput()) });
};
const attach = () => {
setOpen(null);
- button.current?.closest("[data-composer-card]")?.querySelector("input[type=file]")?.click();
+ fileInput()?.click();
};
const schedule = () => {
setOpen(null);
@@ -6113,7 +6311,7 @@ function ComposerPlus({ sessionId, inputActions, useRoster, actions }) {
style: { left: shown.left, bottom: shown.bottom },
"data-leaving": leaving || void 0
},
- (0, import_react11.createElement)("button", { type: "button", role: "menuitem", onClick: attach }, (0, import_react11.createElement)(PaperclipIcon), (0, import_react11.createElement)("span", { className: "bt-menu-label" }, t("Add files"))),
+ shown.files ? (0, import_react11.createElement)("button", { type: "button", role: "menuitem", onClick: attach }, (0, import_react11.createElement)(PaperclipIcon), (0, import_react11.createElement)("span", { className: "bt-menu-label" }, t("Add files"))) : null,
canReference ? (0, import_react11.createElement)("button", { type: "button", role: "menuitem", onMouseDown: keepComposerFocus, onClick: reference }, (0, import_react11.createElement)(ChatsIcon), (0, import_react11.createElement)("span", { className: "bt-menu-label" }, t("Reference a chat"))) : null,
(0, import_react11.createElement)("button", { type: "button", role: "menuitem", onClick: schedule }, (0, import_react11.createElement)(ClockIcon), (0, import_react11.createElement)("span", { className: "bt-menu-label" }, t("Scheduled task")))
), document.body) : null
@@ -6363,7 +6561,6 @@ function usePaneLeft() {
// src/client/palette.js
var import_react13 = require("react");
-var import_dsh_client_ui_primitives3 = require("@deepseek-ai/dsh-client-ui-primitives");
var PALETTE_EXIT_MS = 160;
function CommandPalette({ start, token, roster, actions, useSessions }) {
const [query, setQuery] = (0, import_react13.useState)(start ?? "");
@@ -6428,7 +6625,7 @@ function CommandPalette({ start, token, roster, actions, useSessions }) {
if (people.length) sections.push([t("Bots"), people]);
const agents = (roster.agents ?? []).filter(() => matchesName("DSH Agent")).map((agent) => ({
key: agent.id,
- avatar: (0, import_react13.createElement)("span", { className: "bt-palette-agent" }, (0, import_react13.createElement)(import_dsh_client_ui_primitives3.FishLogo, { size: 18 })),
+ avatar: (0, import_react13.createElement)("span", { className: "bt-palette-agent" }, (0, import_react13.createElement)(import_dsh_client_ui_primitives.FishLogo, { size: 18 })),
title: "DSH Agent",
subtitle: t("Plain dsh session"),
run: () => actions.openAgent(agent.id)
@@ -8534,7 +8731,6 @@ function CreateBot({ roster, actions, start, brief = "", onBack, canGoBack, onCr
// src/client/new-chat.js
var import_react21 = require("react");
-var import_dsh_client_ui_primitives4 = require("@deepseek-ai/dsh-client-ui-primitives");
function NewChat({ mode, roster, actions }) {
const [query, setQuery] = (0, import_react21.useState)("");
const [picked, setPicked] = (0, import_react21.useState)([]);
@@ -8637,8 +8833,8 @@ function NewChat({ mode, roster, actions }) {
setCursor(0);
inputRef.current?.focus();
} });
- if ((roster.agents ?? []).length === 0) {
- options.push({ key: "agent", icon: (0, import_react21.createElement)(import_dsh_client_ui_primitives4.FishLogo, { size: 16 }), label: t("Add DSH Agent"), run: () => run(async () => {
+ if ((roster.agents ?? []).length === 0 && actions.addAgent) {
+ options.push({ key: "agent", icon: (0, import_react21.createElement)(import_dsh_client_ui_primitives.FishLogo, { size: 16 }), label: t("Add DSH Agent"), run: () => run(async () => {
await actions.addAgent();
close();
}) });
@@ -13902,6 +14098,7 @@ function apply(ctx) {
return ids;
};
const actions = {
+ ...teamActions({ call, after, partFor, roster, ui: ui2, live, cards, turnClock }),
// The full-pane overlays sit above the conversation, so opening one must dismiss them
// or the click appears to do nothing.
isAgentSession: (id) => isAgentSessionId(id),
@@ -13986,63 +14183,6 @@ function apply(ctx) {
toggleSidebar: () => {
ctx.layout.toggleSidebar();
},
- openNewChat: (mode) => {
- ui2.set((state) => ({ ...state, newChat: mode, menu: null, palette: null }));
- },
- openPalette: (query = "") => {
- ui2.set((state) => ({ ...state, palette: { query, token: Date.now() }, newChat: null, menu: null }));
- },
- // The token keeps a late exit timer from closing a palette opened again since.
- closePalette: (token) => {
- ui2.set((state) => state.palette && (token === void 0 || state.palette.token === token) ? { ...state, palette: null } : state);
- },
- openExchange: (a, b) => {
- if (a && b) ui2.set((state) => ({ ...state, exchange: [a, b] }));
- },
- openVoice: (id) => {
- if (id) ui2.set((state) => ({ ...state, voice: id, menu: null }));
- },
- closeVoice: () => {
- ui2.set((state) => state.voice ? { ...state, voice: null } : state);
- },
- toggleDetails: (id, force) => {
- ui2.set((state) => {
- const details = force || state.details !== id || state.view !== "details" ? id : null;
- return { ...state, renaming: false, tab: null, details, view: "details" };
- });
- },
- // The open panel follows the main view; a subject with no browser (a group
- // chat, an outside Session) settles on the details view.
- followPanel: (id) => {
- ui2.set((state) => {
- if (!state.details || state.details === id) return state;
- const view = state.view === "browser" && roster.getSnapshot().byId[id] === void 0 ? "details" : state.view;
- return { ...state, details: id, view, renaming: false, tab: null };
- });
- },
- showDetails: (id, tab = null) => {
- ui2.set((state) => ({ ...state, details: id, view: "details", renaming: false, tab }));
- },
- // Opening the conversation would move focus to its composer and blur the name field.
- renameBot: (id) => {
- ui2.set((state) => ({ ...state, details: id, view: "details", renaming: true, tab: null }));
- },
- // `id` opens one Bot (page 'bots') or one group chat (page 'groups').
- openSettings: (page = "general", id = null) => {
- ui2.set((state) => ({ ...state, settings: { page, id }, menu: null, palette: null, newChat: null }));
- },
- closeSettings: () => {
- ui2.set((state) => state.settings ? { ...state, settings: null } : state);
- },
- openMemory: (botId) => {
- ui2.set((state) => ({ ...state, memory: botId, menu: null, palette: null }));
- },
- closeMemory: () => {
- ui2.set((state) => state.memory ? { ...state, memory: null } : state);
- },
- openConnectors: () => {
- ui2.set((state) => ({ ...state, settings: { page: "connectors", id: null }, menu: null, palette: null, newChat: null }));
- },
// Agent mode hands the surface back to the shell; everything open on the Bot
// surface closes first so nothing stale reopens on the way back.
setSurface: (mode) => {
@@ -14091,69 +14231,7 @@ function apply(ctx) {
const reactions = reactionStore.update((saved) => toggleReaction(saved, key, index, emoji), ui2.getSnapshot().reactions);
ui2.set((state) => ({ ...state, reactions }));
},
- quote: (sessionId, text) => ui2.set((state) => ({ ...state, quote: { sessionId, text, token: Date.now() } })),
- clearQuote: (token) => ui2.set((state) => state.quote?.token === token ? { ...state, quote: null } : state),
clearUnread: (id) => writeUnread(id, false),
- setFlags: (id, flags) => after(call("set-flags", { id, ...flags })),
- deleteRoom: (id) => after(call("delete-room", { id })),
- openMenu: (menu) => {
- ui2.set((state) => ({ ...state, menu }));
- },
- closeMenu: () => {
- ui2.set((state) => state.menu ? { ...state, menu: null } : state);
- },
- closeOverlay: () => {
- ui2.set((state) => ({ ...state, newChat: null, exchange: null, details: state.newChat || state.exchange ? state.details : null }));
- },
- createBot: (payload) => after(call("create-bot", payload)),
- createRoom: (members, options = {}) => after(call("create-room", { members, ...options })),
- updateBot: (id, patch) => after(call("update-bot", { id, ...patch })),
- refreshModels: () => after(call("models")).catch(() => {
- }),
- efforts: (ref) => call("efforts", { ref }),
- folders: () => call("folders"),
- folderPick: () => call("folder-pick"),
- folderList: (path) => call("folder-list", { path: path ?? "" }),
- deleteBot: (id) => after(call("delete-bot", { id })),
- duplicateBot: (id) => after(call("duplicate-bot", { id })),
- setPrefs: (prefs) => after(call("set-prefs", prefs)),
- setMain: (id, main = true, options = {}) => after(call("set-main", { id, main, ...options })),
- updateRoom: (id, patch) => after(call("update-room", { id, ...patch })),
- send: (sessionId, text) => after(call("send", { sessionId: partFor(sessionId), text })),
- answerQuestion: (sessionId, questionId, answer) => after(call("answer-question", { sessionId: partFor(sessionId), questionId, answer })),
- dismissQuestion: (sessionId) => after(call("dismiss-question", { sessionId })),
- answerApproval: (id, choice) => after(call("approval-answer", { id, choice })),
- stopMemberWork: (roomId, botId) => after(call("stop-member-work", { roomId, botId })),
- // Values go out in these requests and never come back in a response.
- secretSet: (payload) => after(call("secret-set", payload)),
- secretAllow: (requestId) => after(call("secret-allow", { requestId })),
- secretCancel: (requestId) => after(call("secret-cancel", { requestId })),
- secretUpdate: (name, scope) => after(call("secret-update", { name, scope })),
- secretDelete: (name) => after(call("secret-delete", { name })),
- connectorConnect: (id, token) => after(call("connector-connect", { id, token })),
- connectorDisconnect: (id) => after(call("connector-disconnect", { id })),
- connectorRetry: (id) => after(call("connector-retry", { id })),
- saveCapability: (capability) => after(call("capability-save", capability)),
- deleteCapability: (name) => after(call("capability-delete", { name })),
- approveCapability: (name) => after(call("capability-approve", { name })),
- setBotCapability: (botId, name, attached) => after(call("bot-capability", { botId, name, attached })),
- schedules: () => call("schedules"),
- scheduleCreate: (task) => call("schedule-create", task),
- scheduleDelete: (sessionId, id) => call("schedule-delete", { sessionId, id }),
- exchange: (a, b) => call("exchange", { a, b }).catch(() => []),
- exchangeText: (id) => call("exchange-text", { id }).catch(() => void 0),
- fileText: (file) => call("file-text", { file }).catch(() => void 0),
- roomProgress: (roomId) => call("room-progress", { roomId }).catch(() => []),
- earlier: (sessionId, cursor) => call("earlier", { sessionId, cursor: cursor ?? null }),
- // Hours come back in this browser's time zone, so days start at local midnight.
- usage: () => call("usage", { timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone }),
- // `summarize` starts a summary when the entries changed; `regenerate` always does.
- memoryView: (botId, flags = {}) => call("memory-view", { botId, ...flags }),
- memoryAsk: (botId, text) => call("memory-ask", { botId, text }),
- memoryForget: (botId, entry) => call("memory-forget", { botId, scope: entry.scope, topic: entry.topic, text: entry.text }),
- diagnostics: (payload) => call("diagnostics", payload),
- diagnosticsLog: () => call("diagnostics-log"),
- diagnosticsClear: () => call("diagnostics-clear"),
// DSH's right sidebar (files, terminals), which a plugin may load after this one.
hasRightSidebar: () => ctx.get("sidebarRight") !== void 0,
toggleRightSidebar: () => {
@@ -14162,13 +14240,7 @@ function apply(ctx) {
} catch (error) {
actions.reportError(error, "right-sidebar");
}
- },
- // A failed action away from any form (a menu, the palette) shows as a toast.
- reportError: (error, where = "action") => {
- noteClientError(where, error);
- ui2.set((state) => ({ ...state, toast: { text: error?.message ?? String(error), token: Date.now() } }));
- },
- dismissToast: (token) => ui2.set((state) => state.toast && (token === void 0 || state.toast.token === token) ? { ...state, toast: null } : state)
+ }
};
if (browsers) {
Object.assign(actions, {
@@ -14205,13 +14277,6 @@ function apply(ctx) {
browserFocus: (tabId) => browsers.focus(tabId)
});
}
- actions.setPanelView = (view) => {
- if (view !== "details" && view !== "browser") return;
- ui2.set((state) => state.details && state.view !== view ? { ...state, view } : state);
- };
- actions.closePanel = () => {
- ui2.set((state) => state.details ? { ...state, details: null, view: "details", renaming: false, tab: null } : state);
- };
actions.signInEntry = () => ctx.slots.entries?.("settings.models.sign-in")?.[0] ?? null;
actions.canSignIn = () => Boolean(actions.signInEntry());
actions.signIn = () => ui2.set((state) => ({ ...state, signIn: (state.signIn ?? 0) + 1 }));
@@ -14243,47 +14308,6 @@ function apply(ctx) {
update.set((previous) => ({ ...value, app: previous.app }));
wakeUpdate();
};
- actions.repoStars = () => call("repo-stars");
- actions.noteTurnTime = (sessionId, turn, key, time) => {
- if (sessionId === void 0 || !Number.isFinite(turn) || !Number.isFinite(time)) return;
- turnClock.set((state) => {
- const turns = state[sessionId] ?? {};
- const entry = turns[turn] ?? {};
- const next = key === "first" && entry.first !== void 0 ? Math.min(entry.first, time) : time;
- if (entry[key] === next) return state;
- return { ...state, [sessionId]: { ...turns, [turn]: { ...entry, [key]: next } } };
- });
- };
- actions.noteTurnPeer = (sessionId, turn, peerId) => {
- if (sessionId === void 0 || !Number.isFinite(turn)) return;
- turnClock.set((state) => {
- const turns = state[sessionId] ?? {};
- const entry = turns[turn] ?? {};
- if (entry.peer === peerId) return state;
- return { ...state, [sessionId]: { ...turns, [turn]: { ...entry, peer: peerId } } };
- });
- };
- actions.noteLive = (sessionId, id, entry) => {
- if (sessionId === void 0) return;
- live.set((state) => {
- const own = state[sessionId] ?? {};
- const prev = own[id];
- if (entry === null ? prev === void 0 : prev !== void 0 && JSON.stringify({ ...prev, at: 0 }) === JSON.stringify({ ...entry, at: 0 })) return state;
- const next = { ...own };
- if (entry === null) delete next[id];
- else next[id] = { ...entry, at: prev?.at ?? Date.now() };
- return { ...state, [sessionId]: next };
- });
- };
- actions.noteCards = (sessionId, callIds, delta) => {
- if (sessionId !== void 0) cards.set((state) => countCards(state, sessionId, callIds, delta));
- };
- actions.clearLive = (sessionId) => live.set((state) => {
- if (!state[sessionId]) return state;
- const next = { ...state };
- delete next[sessionId];
- return next;
- });
const browserPages = browsers?.pages ?? createSource({});
const browserTabs = browsers?.tabs ?? createSource({});
const face = () => ({ actions, hooks: { roster, ui: ui2, activity, work, memoryNews, registry, turnClock, live, cards, browserPages, browserTabs, surface, update } });
diff --git a/ds-bot/src/client/cells.js b/ds-bot/src/client/cells.js
index 5efd94ec..1129c4a5 100644
--- a/ds-bot/src/client/cells.js
+++ b/ds-bot/src/client/cells.js
@@ -1,6 +1,6 @@
import { createElement as h, Fragment, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react'
import { createPortal } from 'react-dom'
-import { MarkdownText } from '@deepseek-ai/dsh-client-ui-primitives'
+import { MarkdownText } from './dsh-primitives.js'
import { inkText } from './inks.js'
import { linkMentions, mentionTarget, dayLabel, contentText, stripHeader, isHiddenTurn, isRelayContext, relaysBefore, relayPart, commRunOf, toolName, toolArgs, reminderPrompts } from './text.js'
import { SmileIcon, ReplyIcon, DotsIcon, CheckIcon, DownloadIcon, CopyIcon, MemoryIcon } from './icons.js'
@@ -311,38 +311,61 @@ function EarlierParts({ sessionId, roster, actions }) {
observer.observe(node)
return () => observer.disconnect()
}, [view.cursor, view.loading, view.failed])
- const selfId = roster.byId[sessionId]?.id
- const rows = []
- for (const item of view.items) {
- const last = rows.at(-1)
- if (item.kind === 'bot' && last?.kind === 'bot') last.texts.push(item.text)
- else rows.push(item.kind === 'bot' ? { kind: 'bot', texts: [item.text] } : item)
- }
return h('div', { className: 'bt-earlier', role: 'feed', 'aria-label': t('Earlier messages'), 'aria-busy': view.loading },
h('div', { ref: top, className: 'bt-earlier-top' },
view.loading ? h(Shimmer, null, t('Loading earlier messages…'))
: view.failed ? h('button', { type: 'button', className: 'bt-soft', onClick: () => load(view.cursor) }, t('Couldn’t load earlier messages · Retry'))
: view.cursor ? h('button', { type: 'button', className: 'bt-soft', onClick: () => load(view.cursor) }, t('Load earlier')) : null),
- rows.map((row, index) => {
- // Pages are prepended, so a row keeps its distance from the end.
- const key = rows.length - index
- switch (row.kind) {
- case 'divider': return h(PartLine, { key, time: row.time })
- case 'user': return h(EarlierUser, { key, row })
- case 'answer': return h(AnsweredCell, { key, node: { data: row } })
- case 'bot': return h(Bubbles, { key, texts: row.texts, roster, selfId, actions, fold: FOLD_HUGE })
- case 'event': {
- if (row.role === 'report') return h(GroupEvent, { key, prefix: t('Replies from'), room: roster.roomsById[row.roomId], name: t('a group chat'), roster, actions })
- const other = roster.byId[row.botId] ?? { id: row.botId, name: row.name ?? t('a Bot'), color: 'gray' }
- const prefix = { stopped: t('Stopped by'), reply: t('Reply from') }[row.role] ?? t('Message from')
- return h(EventLine, { key, prefix, bots: [other], onOpen: () => { if (selfId && other.id) actions.openExchange(selfId, other.id) }, whole: true })
- }
- default: return null
- }
- }),
+ h(ChatRows, { items: view.items, sessionId, roster, actions }),
h(PartLine, { time: view.startedAt }))
}
+// A Bot chat's entries as the host lists them (the `earlier` and `chat` endpoints): the
+// Bot's messages in a row are one block, and a thin line marks where a part begins.
+// `clock` adds the time separators: one above the first entry, and one after each pause.
+export function ChatRows({ items, sessionId, roster, actions, useUi, clock = false }) {
+ const selfId = roster.byId[sessionId]?.id
+ const rows = []
+ for (const item of items) {
+ const last = rows.at(-1)
+ if (item.kind === 'bot' && last?.kind === 'bot') {
+ last.texts.push(item.text)
+ last.end = item.time
+ } else rows.push(item.kind === 'bot' ? { kind: 'bot', texts: [item.text], time: item.time, end: item.time } : item)
+ }
+ let before
+ return rows.flatMap((row, index) => {
+ // Pages are prepended, so a row keeps its distance from the end.
+ const key = rows.length - index
+ const shown = chatRow(row, key, { sessionId, selfId, roster, actions, useUi })
+ // A part's first entry shows its time under the part's line, as a chat's first one does.
+ if (row.kind === 'divider') {
+ before = undefined
+ return [shown]
+ }
+ const pause = clock && Number.isFinite(row.time) && (before === undefined || row.time - before >= SEPARATOR_GAP_MS)
+ if (Number.isFinite(row.end ?? row.time)) before = row.end ?? row.time
+ return pause ? [h('div', { key: `${key}:clock`, className: 'bt-time-sep', role: 'separator' }, clockLabel(row.time)), shown] : [shown]
+ })
+}
+
+// `useUi` gives a block its reactions and its Reply tool.
+function chatRow(row, key, { sessionId, selfId, roster, actions, useUi }) {
+ switch (row.kind) {
+ case 'divider': return h(PartLine, { key, time: row.time })
+ case 'user': return h(EarlierUser, { key, row })
+ case 'answer': return h(AnsweredCell, { key, node: { data: row } })
+ case 'bot': return h(Bubbles, { key, texts: row.texts, roster, selfId, actions, sessionId: useUi ? sessionId : undefined, msgKey: useUi ? `${sessionId}:${row.time}` : undefined, useUi, fold: FOLD_HUGE })
+ case 'event': {
+ if (row.role === 'report') return h(GroupEvent, { key, prefix: t('Replies from'), room: roster.roomsById[row.roomId], name: t('a group chat'), roster, actions })
+ const other = roster.byId[row.botId] ?? { id: row.botId, name: row.name ?? t('a Bot'), color: 'gray' }
+ const prefix = { stopped: t('Stopped by'), reply: t('Reply from') }[row.role] ?? t('Message from')
+ return h(EventLine, { key, prefix, bots: [other], onOpen: () => { if (selfId && other.id) actions.openExchange(selfId, other.id) }, whole: true })
+ }
+ default: return null
+ }
+}
+
export function TriggerCell({ node, sessionId, useRoster, useSessions, useTurnClock, useUi, actions }) {
const roster = useRoster(value => value)
const data = node.data
diff --git a/ds-bot/src/client/composer.js b/ds-bot/src/client/composer.js
index 53fad47c..ce361e08 100644
--- a/ds-bot/src/client/composer.js
+++ b/ds-bot/src/client/composer.js
@@ -122,14 +122,16 @@ export function ComposerPlus({ sessionId, inputActions, useRoster, actions }) {
}, [open])
const target = roster.byId?.[sessionId]?.id ?? roster.roomsById?.[sessionId]?.id
if (sessionId === undefined || target === undefined) return null
+ const fileInput = () => button.current?.closest('[data-composer-card]')?.querySelector('input[type=file]')
const toggle = () => {
if (open) { setOpen(null); return }
const rect = button.current.getBoundingClientRect()
- setOpen({ left: rect.left, bottom: window.innerHeight - rect.top + 8 })
+ // Files go through the composer's own file input; a composer without one takes none.
+ setOpen({ left: rect.left, bottom: window.innerHeight - rect.top + 8, files: Boolean(fileInput()) })
}
const attach = () => {
setOpen(null)
- button.current?.closest('[data-composer-card]')?.querySelector('input[type=file]')?.click()
+ fileInput()?.click()
}
const schedule = () => {
setOpen(null)
@@ -151,7 +153,7 @@ export function ComposerPlus({ sessionId, inputActions, useRoster, actions }) {
ref: menu, className: 'bt-menu bt-menu-up bt-plus-menu', role: 'menu', 'aria-label': t('Add'),
style: { left: shown.left, bottom: shown.bottom }, 'data-leaving': leaving || undefined,
},
- h('button', { type: 'button', role: 'menuitem', onClick: attach }, h(PaperclipIcon), h('span', { className: 'bt-menu-label' }, t('Add files'))),
+ shown.files ? h('button', { type: 'button', role: 'menuitem', onClick: attach }, h(PaperclipIcon), h('span', { className: 'bt-menu-label' }, t('Add files'))) : null,
canReference ? h('button', { type: 'button', role: 'menuitem', onMouseDown: keepComposerFocus, onClick: reference }, h(ChatsIcon), h('span', { className: 'bt-menu-label' }, t('Reference a chat'))) : null,
h('button', { type: 'button', role: 'menuitem', onClick: schedule }, h(ClockIcon), h('span', { className: 'bt-menu-label' }, t('Scheduled task')))), document.body) : null)
}
diff --git a/ds-bot/src/client/dsh-primitives.js b/ds-bot/src/client/dsh-primitives.js
new file mode 100644
index 00000000..993a98b7
--- /dev/null
+++ b/ds-bot/src/client/dsh-primitives.js
@@ -0,0 +1,3 @@
+// The DSH interface primitives the Bot views draw with. The desktop app's window does not
+// load DSH's interface; its build puts its own module in place of this one.
+export { FishLogo, MarkdownText } from '@deepseek-ai/dsh-client-ui-primitives'
diff --git a/ds-bot/src/client/i18n.js b/ds-bot/src/client/i18n.js
index b3f0fd10..d56919b9 100644
--- a/ds-bot/src/client/i18n.js
+++ b/ds-bot/src/client/i18n.js
@@ -15,6 +15,7 @@ const ZH = {
'New chat': '新对话',
'New…': '新建',
'Collapse sidebar': '收起侧边栏',
+ 'Expand sidebar': '展开侧边栏',
'Animation': '动画',
'Bot animation': 'Bot 动画',
'Quiet': '安静',
diff --git a/ds-bot/src/client/index.js b/ds-bot/src/client/index.js
index 8e92c2d8..8e3d404d 100644
--- a/ds-bot/src/client/index.js
+++ b/ds-bot/src/client/index.js
@@ -1,7 +1,8 @@
import { call } from './api.js'
import { isHex, inkText, paintCss } from './inks.js'
import { DEFAULT_MASK, SHAPES, markupCache, maskOf } from './characters.js'
-import { countCards, createSource, EMPTY_ROSTER, indexRoster, isAgentSession } from './sources.js'
+import { createSource, EMPTY_ROSTER, indexRoster, isAgentSession } from './sources.js'
+import { teamActions } from './team-actions.js'
import { themeCss, shellTokens, registry, registerShape, registerTheme, allThemes } from './themes.js'
import { MENTION_ORIGIN, currentPart } from './text.js'
import { SHELL_CSS, CONVERSATION_CSS, installStyles, installCompiledStyles } from './styles.js'
@@ -340,6 +341,7 @@ export function apply(ctx) {
return ids
}
const actions = {
+ ...teamActions({ call, after, partFor, roster, ui, live, cards, turnClock }),
// The full-pane overlays sit above the conversation, so opening one must dismiss them
// or the click appears to do nothing.
isAgentSession: id => isAgentSessionId(id),
@@ -421,37 +423,6 @@ export function apply(ctx) {
},
selectPanel: (id) => { ctx.layout.selectPanel(id) },
toggleSidebar: () => { ctx.layout.toggleSidebar() },
- openNewChat: (mode) => { ui.set(state => ({ ...state, newChat: mode, menu: null, palette: null })) },
- openPalette: (query = '') => { ui.set(state => ({ ...state, palette: { query, token: Date.now() }, newChat: null, menu: null })) },
- // The token keeps a late exit timer from closing a palette opened again since.
- closePalette: (token) => { ui.set(state => (state.palette && (token === undefined || state.palette.token === token) ? { ...state, palette: null } : state)) },
- openExchange: (a, b) => { if (a && b) ui.set(state => ({ ...state, exchange: [a, b] })) },
- openVoice: (id) => { if (id) ui.set(state => ({ ...state, voice: id, menu: null })) },
- closeVoice: () => { ui.set(state => (state.voice ? { ...state, voice: null } : state)) },
- toggleDetails: (id, force) => {
- ui.set((state) => {
- const details = force || state.details !== id || state.view !== 'details' ? id : null
- return { ...state, renaming: false, tab: null, details, view: 'details' }
- })
- },
- // The open panel follows the main view; a subject with no browser (a group
- // chat, an outside Session) settles on the details view.
- followPanel: (id) => {
- ui.set((state) => {
- if (!state.details || state.details === id) return state
- const view = state.view === 'browser' && roster.getSnapshot().byId[id] === undefined ? 'details' : state.view
- return { ...state, details: id, view, renaming: false, tab: null }
- })
- },
- showDetails: (id, tab = null) => { ui.set(state => ({ ...state, details: id, view: 'details', renaming: false, tab })) },
- // Opening the conversation would move focus to its composer and blur the name field.
- renameBot: (id) => { ui.set(state => ({ ...state, details: id, view: 'details', renaming: true, tab: null })) },
- // `id` opens one Bot (page 'bots') or one group chat (page 'groups').
- openSettings: (page = 'general', id = null) => { ui.set(state => ({ ...state, settings: { page, id }, menu: null, palette: null, newChat: null })) },
- closeSettings: () => { ui.set(state => (state.settings ? { ...state, settings: null } : state)) },
- openMemory: (botId) => { ui.set(state => ({ ...state, memory: botId, menu: null, palette: null })) },
- closeMemory: () => { ui.set(state => (state.memory ? { ...state, memory: null } : state)) },
- openConnectors: () => { ui.set(state => ({ ...state, settings: { page: 'connectors', id: null }, menu: null, palette: null, newChat: null })) },
// Agent mode hands the surface back to the shell; everything open on the Bot
// surface closes first so nothing stale reopens on the way back.
setSurface: (mode) => {
@@ -503,62 +474,7 @@ export function apply(ctx) {
const reactions = reactionStore.update(saved => toggleReaction(saved, key, index, emoji), ui.getSnapshot().reactions)
ui.set(state => ({ ...state, reactions }))
},
- quote: (sessionId, text) => ui.set(state => ({ ...state, quote: { sessionId, text, token: Date.now() } })),
- clearQuote: token => ui.set(state => (state.quote?.token === token ? { ...state, quote: null } : state)),
clearUnread: id => writeUnread(id, false),
- setFlags: (id, flags) => after(call('set-flags', { id, ...flags })),
- deleteRoom: id => after(call('delete-room', { id })),
- openMenu: (menu) => { ui.set(state => ({ ...state, menu })) },
- closeMenu: () => { ui.set(state => (state.menu ? { ...state, menu: null } : state)) },
- closeOverlay: () => { ui.set(state => ({ ...state, newChat: null, exchange: null, details: state.newChat || state.exchange ? state.details : null })) },
- createBot: payload => after(call('create-bot', payload)),
- createRoom: (members, options = {}) => after(call('create-room', { members, ...options })),
- updateBot: (id, patch) => after(call('update-bot', { id, ...patch })),
- refreshModels: () => after(call('models')).catch(() => {}),
- efforts: ref => call('efforts', { ref }),
- folders: () => call('folders'),
- folderPick: () => call('folder-pick'),
- folderList: path => call('folder-list', { path: path ?? '' }),
- deleteBot: id => after(call('delete-bot', { id })),
- duplicateBot: id => after(call('duplicate-bot', { id })),
- setPrefs: prefs => after(call('set-prefs', prefs)),
- setMain: (id, main = true, options = {}) => after(call('set-main', { id, main, ...options })),
- updateRoom: (id, patch) => after(call('update-room', { id, ...patch })),
- send: (sessionId, text) => after(call('send', { sessionId: partFor(sessionId), text })),
- answerQuestion: (sessionId, questionId, answer) => after(call('answer-question', { sessionId: partFor(sessionId), questionId, answer })),
- dismissQuestion: sessionId => after(call('dismiss-question', { sessionId })),
- answerApproval: (id, choice) => after(call('approval-answer', { id, choice })),
- stopMemberWork: (roomId, botId) => after(call('stop-member-work', { roomId, botId })),
- // Values go out in these requests and never come back in a response.
- secretSet: payload => after(call('secret-set', payload)),
- secretAllow: requestId => after(call('secret-allow', { requestId })),
- secretCancel: requestId => after(call('secret-cancel', { requestId })),
- secretUpdate: (name, scope) => after(call('secret-update', { name, scope })),
- secretDelete: name => after(call('secret-delete', { name })),
- connectorConnect: (id, token) => after(call('connector-connect', { id, token })),
- connectorDisconnect: id => after(call('connector-disconnect', { id })),
- connectorRetry: id => after(call('connector-retry', { id })),
- saveCapability: capability => after(call('capability-save', capability)),
- deleteCapability: name => after(call('capability-delete', { name })),
- approveCapability: name => after(call('capability-approve', { name })),
- setBotCapability: (botId, name, attached) => after(call('bot-capability', { botId, name, attached })),
- schedules: () => call('schedules'),
- scheduleCreate: task => call('schedule-create', task),
- scheduleDelete: (sessionId, id) => call('schedule-delete', { sessionId, id }),
- exchange: (a, b) => call('exchange', { a, b }).catch(() => []),
- exchangeText: id => call('exchange-text', { id }).catch(() => undefined),
- fileText: file => call('file-text', { file }).catch(() => undefined),
- roomProgress: roomId => call('room-progress', { roomId }).catch(() => []),
- earlier: (sessionId, cursor) => call('earlier', { sessionId, cursor: cursor ?? null }),
- // Hours come back in this browser's time zone, so days start at local midnight.
- usage: () => call('usage', { timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone }),
- // `summarize` starts a summary when the entries changed; `regenerate` always does.
- memoryView: (botId, flags = {}) => call('memory-view', { botId, ...flags }),
- memoryAsk: (botId, text) => call('memory-ask', { botId, text }),
- memoryForget: (botId, entry) => call('memory-forget', { botId, scope: entry.scope, topic: entry.topic, text: entry.text }),
- diagnostics: payload => call('diagnostics', payload),
- diagnosticsLog: () => call('diagnostics-log'),
- diagnosticsClear: () => call('diagnostics-clear'),
// DSH's right sidebar (files, terminals), which a plugin may load after this one.
hasRightSidebar: () => ctx.get('sidebarRight') !== undefined,
toggleRightSidebar: () => {
@@ -568,12 +484,6 @@ export function apply(ctx) {
actions.reportError(error, 'right-sidebar')
}
},
- // A failed action away from any form (a menu, the palette) shows as a toast.
- reportError: (error, where = 'action') => {
- noteClientError(where, error)
- ui.set(state => ({ ...state, toast: { text: error?.message ?? String(error), token: Date.now() } }))
- },
- dismissToast: token => ui.set(state => (state.toast && (token === undefined || state.toast.token === token) ? { ...state, toast: null } : state)),
}
// Without the Desktop bridge these stay undefined, and no browser control renders.
if (browsers) {
@@ -611,11 +521,6 @@ export function apply(ctx) {
browserFocus: (tabId) => browsers.focus(tabId),
})
}
- actions.setPanelView = (view) => {
- if (view !== 'details' && view !== 'browser') return
- ui.set(state => (state.details && state.view !== view ? { ...state, view } : state))
- }
- actions.closePanel = () => { ui.set(state => (state.details ? { ...state, details: null, view: 'details', renaming: false, tab: null } : state)) }
// Whether AccountLauncher holds the shell's settings seat; FooterAccount steps aside if so.
actions.signInEntry = () => ctx.slots.entries?.('settings.models.sign-in')?.[0] ?? null
actions.canSignIn = () => Boolean(actions.signInEntry())
@@ -653,47 +558,6 @@ export function apply(ctx) {
update.set(previous => ({ ...value, app: previous.app }))
wakeUpdate()
}
- actions.repoStars = () => call('repo-stars')
- actions.noteTurnTime = (sessionId, turn, key, time) => {
- if (sessionId === undefined || !Number.isFinite(turn) || !Number.isFinite(time)) return
- turnClock.set((state) => {
- const turns = state[sessionId] ?? {}
- const entry = turns[turn] ?? {}
- const next = key === 'first' && entry.first !== undefined ? Math.min(entry.first, time) : time
- if (entry[key] === next) return state
- return { ...state, [sessionId]: { ...turns, [turn]: { ...entry, [key]: next } } }
- })
- }
- actions.noteTurnPeer = (sessionId, turn, peerId) => {
- if (sessionId === undefined || !Number.isFinite(turn)) return
- turnClock.set((state) => {
- const turns = state[sessionId] ?? {}
- const entry = turns[turn] ?? {}
- if (entry.peer === peerId) return state
- return { ...state, [sessionId]: { ...turns, [turn]: { ...entry, peer: peerId } } }
- })
- }
- actions.noteLive = (sessionId, id, entry) => {
- if (sessionId === undefined) return
- live.set((state) => {
- const own = state[sessionId] ?? {}
- const prev = own[id]
- if (entry === null ? prev === undefined : prev !== undefined && JSON.stringify({ ...prev, at: 0 }) === JSON.stringify({ ...entry, at: 0 })) return state
- const next = { ...own }
- if (entry === null) delete next[id]
- else next[id] = { ...entry, at: prev?.at ?? Date.now() }
- return { ...state, [sessionId]: next }
- })
- }
- actions.noteCards = (sessionId, callIds, delta) => {
- if (sessionId !== undefined) cards.set(state => countCards(state, sessionId, callIds, delta))
- }
- actions.clearLive = sessionId => live.set((state) => {
- if (!state[sessionId]) return state
- const next = { ...state }
- delete next[sessionId]
- return next
- })
const browserPages = browsers?.pages ?? createSource({})
const browserTabs = browsers?.tabs ?? createSource({})
const face = () => ({ actions, hooks: { roster, ui, activity, work, memoryNews, registry, turnClock, live, cards, browserPages, browserTabs, surface, update } })
diff --git a/ds-bot/src/client/new-chat.js b/ds-bot/src/client/new-chat.js
index 4f87e382..fd53a99e 100644
--- a/ds-bot/src/client/new-chat.js
+++ b/ds-bot/src/client/new-chat.js
@@ -1,5 +1,5 @@
import { createElement as h, useRef, useState } from 'react'
-import { FishLogo } from '@deepseek-ai/dsh-client-ui-primitives'
+import { FishLogo } from './dsh-primitives.js'
import { PlusIcon, PeopleIcon, ArrowUpIcon } from './icons.js'
import { AdminStar, BotMark } from './mark.js'
import { useEscape, usePaneLeft } from './overlay-hooks.js'
@@ -97,7 +97,7 @@ export function NewChat({ mode, roster, actions }) {
options.push({ key: 'new', icon: h(PlusIcon), label: t('Create new Bot'), run: createBot })
options.push({ key: 'group', icon: h(PeopleIcon), label: t('Create group chat'), run: () => { setGroup(true); setCursor(0); inputRef.current?.focus() } })
// A team holds at most one DSH Agent; the entry exists only while there is none.
- if ((roster.agents ?? []).length === 0) {
+ if ((roster.agents ?? []).length === 0 && actions.addAgent) {
options.push({ key: 'agent', icon: h(FishLogo, { size: 16 }), label: t('Add DSH Agent'), run: () => run(async () => { await actions.addAgent(); close() }) })
}
}
diff --git a/ds-bot/src/client/palette.js b/ds-bot/src/client/palette.js
index 7de15ff5..128e035f 100644
--- a/ds-bot/src/client/palette.js
+++ b/ds-bot/src/client/palette.js
@@ -1,5 +1,5 @@
import { createElement as h, Fragment, useEffect, useState } from 'react'
-import { FishLogo } from '@deepseek-ai/dsh-client-ui-primitives'
+import { FishLogo } from './dsh-primitives.js'
import { isMainOf } from './sources.js'
import { currentPart, stripHeader } from './text.js'
import { PlusIcon, SearchIcon, PeopleIcon, CloseIcon, GearIcon } from './icons.js'
diff --git a/ds-bot/src/client/sidebar.js b/ds-bot/src/client/sidebar.js
index edb53241..adfb2d36 100644
--- a/ds-bot/src/client/sidebar.js
+++ b/ds-bot/src/client/sidebar.js
@@ -1,6 +1,6 @@
import { createElement as h, Fragment, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from 'react'
import { createPortal } from 'react-dom'
-import { FishLogo } from '@deepseek-ai/dsh-client-ui-primitives'
+import { FishLogo } from './dsh-primitives.js'
import { isMainOf } from './sources.js'
import { currentPart, previewOf, relativeShort } from './text.js'
import { PlusIcon, SearchIcon, SidebarIcon, GaugeIcon, PlugIcon, ClockIcon, GearIcon, PinMarkIcon, ConnectorIcon, SwitchIcon, CloudDownloadIcon } from './icons.js'
diff --git a/ds-bot/src/client/team-actions.js b/ds-bot/src/client/team-actions.js
new file mode 100644
index 00000000..2e36c883
--- /dev/null
+++ b/ds-bot/src/client/team-actions.js
@@ -0,0 +1,149 @@
+import { countCards } from './sources.js'
+import { noteClientError } from './diagnostics.js'
+
+// The actions every window that draws the Bot views shares: dialogs and panels (the `ui`
+// source), requests to the host, and the notes the transcript keeps. The shell around the
+// views adds navigation and its own panels. `after` reads the team again once a request
+// is done; `partFor` maps a Bot id, or any part of its chat, to its current part.
+export function teamActions({ call, after, partFor, roster, ui, live, cards, turnClock }) {
+ return {
+ openNewChat: (mode) => { ui.set(state => ({ ...state, newChat: mode, menu: null, palette: null })) },
+ openPalette: (query = '') => { ui.set(state => ({ ...state, palette: { query, token: Date.now() }, newChat: null, menu: null })) },
+ // The token keeps a late exit timer from closing a palette opened again since.
+ closePalette: (token) => { ui.set(state => (state.palette && (token === undefined || state.palette.token === token) ? { ...state, palette: null } : state)) },
+ openExchange: (a, b) => { if (a && b) ui.set(state => ({ ...state, exchange: [a, b] })) },
+ openVoice: (id) => { if (id) ui.set(state => ({ ...state, voice: id, menu: null })) },
+ closeVoice: () => { ui.set(state => (state.voice ? { ...state, voice: null } : state)) },
+ toggleDetails: (id, force) => {
+ ui.set((state) => {
+ const details = force || state.details !== id || state.view !== 'details' ? id : null
+ return { ...state, renaming: false, tab: null, details, view: 'details' }
+ })
+ },
+ // The open panel follows the main view; a subject with no browser (a group
+ // chat, an outside Session) settles on the details view.
+ followPanel: (id) => {
+ ui.set((state) => {
+ if (!state.details || state.details === id) return state
+ const view = state.view === 'browser' && roster.getSnapshot().byId[id] === undefined ? 'details' : state.view
+ return { ...state, details: id, view, renaming: false, tab: null }
+ })
+ },
+ showDetails: (id, tab = null) => { ui.set(state => ({ ...state, details: id, view: 'details', renaming: false, tab })) },
+ // Opening the conversation would move focus to its composer and blur the name field.
+ renameBot: (id) => { ui.set(state => ({ ...state, details: id, view: 'details', renaming: true, tab: null })) },
+ // `id` opens one Bot (page 'bots') or one group chat (page 'groups').
+ openSettings: (page = 'general', id = null) => { ui.set(state => ({ ...state, settings: { page, id }, menu: null, palette: null, newChat: null })) },
+ closeSettings: () => { ui.set(state => (state.settings ? { ...state, settings: null } : state)) },
+ openMemory: (botId) => { ui.set(state => ({ ...state, memory: botId, menu: null, palette: null })) },
+ closeMemory: () => { ui.set(state => (state.memory ? { ...state, memory: null } : state)) },
+ openConnectors: () => { ui.set(state => ({ ...state, settings: { page: 'connectors', id: null }, menu: null, palette: null, newChat: null })) },
+ setPanelView: (view) => {
+ if (view !== 'details' && view !== 'browser') return
+ ui.set(state => (state.details && state.view !== view ? { ...state, view } : state))
+ },
+ closePanel: () => { ui.set(state => (state.details ? { ...state, details: null, view: 'details', renaming: false, tab: null } : state)) },
+ quote: (sessionId, text) => ui.set(state => ({ ...state, quote: { sessionId, text, token: Date.now() } })),
+ clearQuote: token => ui.set(state => (state.quote?.token === token ? { ...state, quote: null } : state)),
+ setFlags: (id, flags) => after(call('set-flags', { id, ...flags })),
+ deleteRoom: id => after(call('delete-room', { id })),
+ openMenu: (menu) => { ui.set(state => ({ ...state, menu })) },
+ closeMenu: () => { ui.set(state => (state.menu ? { ...state, menu: null } : state)) },
+ closeOverlay: () => { ui.set(state => ({ ...state, newChat: null, exchange: null, details: state.newChat || state.exchange ? state.details : null })) },
+ createBot: payload => after(call('create-bot', payload)),
+ createRoom: (members, options = {}) => after(call('create-room', { members, ...options })),
+ updateBot: (id, patch) => after(call('update-bot', { id, ...patch })),
+ refreshModels: () => after(call('models')).catch(() => {}),
+ efforts: ref => call('efforts', { ref }),
+ folders: () => call('folders'),
+ folderPick: () => call('folder-pick'),
+ folderList: path => call('folder-list', { path: path ?? '' }),
+ deleteBot: id => after(call('delete-bot', { id })),
+ duplicateBot: id => after(call('duplicate-bot', { id })),
+ setPrefs: prefs => after(call('set-prefs', prefs)),
+ setMain: (id, main = true, options = {}) => after(call('set-main', { id, main, ...options })),
+ updateRoom: (id, patch) => after(call('update-room', { id, ...patch })),
+ send: (sessionId, text) => after(call('send', { sessionId: partFor(sessionId), text })),
+ answerQuestion: (sessionId, questionId, answer) => after(call('answer-question', { sessionId: partFor(sessionId), questionId, answer })),
+ dismissQuestion: sessionId => after(call('dismiss-question', { sessionId })),
+ answerApproval: (id, choice) => after(call('approval-answer', { id, choice })),
+ stopMemberWork: (roomId, botId) => after(call('stop-member-work', { roomId, botId })),
+ // Values go out in these requests and never come back in a response.
+ secretSet: payload => after(call('secret-set', payload)),
+ secretAllow: requestId => after(call('secret-allow', { requestId })),
+ secretCancel: requestId => after(call('secret-cancel', { requestId })),
+ secretUpdate: (name, scope) => after(call('secret-update', { name, scope })),
+ secretDelete: name => after(call('secret-delete', { name })),
+ connectorConnect: (id, token) => after(call('connector-connect', { id, token })),
+ connectorDisconnect: id => after(call('connector-disconnect', { id })),
+ connectorRetry: id => after(call('connector-retry', { id })),
+ saveCapability: capability => after(call('capability-save', capability)),
+ deleteCapability: name => after(call('capability-delete', { name })),
+ approveCapability: name => after(call('capability-approve', { name })),
+ setBotCapability: (botId, name, attached) => after(call('bot-capability', { botId, name, attached })),
+ schedules: () => call('schedules'),
+ scheduleCreate: task => call('schedule-create', task),
+ scheduleDelete: (sessionId, id) => call('schedule-delete', { sessionId, id }),
+ exchange: (a, b) => call('exchange', { a, b }).catch(() => []),
+ exchangeText: id => call('exchange-text', { id }).catch(() => undefined),
+ fileText: file => call('file-text', { file }).catch(() => undefined),
+ roomProgress: roomId => call('room-progress', { roomId }).catch(() => []),
+ earlier: (sessionId, cursor) => call('earlier', { sessionId, cursor: cursor ?? null }),
+ // Hours come back in this browser's time zone, so days start at local midnight.
+ usage: () => call('usage', { timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone }),
+ // `summarize` starts a summary when the entries changed; `regenerate` always does.
+ memoryView: (botId, flags = {}) => call('memory-view', { botId, ...flags }),
+ memoryAsk: (botId, text) => call('memory-ask', { botId, text }),
+ memoryForget: (botId, entry) => call('memory-forget', { botId, scope: entry.scope, topic: entry.topic, text: entry.text }),
+ diagnostics: payload => call('diagnostics', payload),
+ diagnosticsLog: () => call('diagnostics-log'),
+ diagnosticsClear: () => call('diagnostics-clear'),
+ repoStars: () => call('repo-stars'),
+ // A failed action away from any form (a menu, the palette) shows as a toast.
+ reportError: (error, where = 'action') => {
+ noteClientError(where, error)
+ ui.set(state => ({ ...state, toast: { text: error?.message ?? String(error), token: Date.now() } }))
+ },
+ dismissToast: token => ui.set(state => (state.toast && (token === undefined || state.toast.token === token) ? { ...state, toast: null } : state)),
+ noteTurnTime: (sessionId, turn, key, time) => {
+ if (sessionId === undefined || !Number.isFinite(turn) || !Number.isFinite(time)) return
+ turnClock.set((state) => {
+ const turns = state[sessionId] ?? {}
+ const entry = turns[turn] ?? {}
+ const next = key === 'first' && entry.first !== undefined ? Math.min(entry.first, time) : time
+ if (entry[key] === next) return state
+ return { ...state, [sessionId]: { ...turns, [turn]: { ...entry, [key]: next } } }
+ })
+ },
+ noteTurnPeer: (sessionId, turn, peerId) => {
+ if (sessionId === undefined || !Number.isFinite(turn)) return
+ turnClock.set((state) => {
+ const turns = state[sessionId] ?? {}
+ const entry = turns[turn] ?? {}
+ if (entry.peer === peerId) return state
+ return { ...state, [sessionId]: { ...turns, [turn]: { ...entry, peer: peerId } } }
+ })
+ },
+ noteLive: (sessionId, id, entry) => {
+ if (sessionId === undefined) return
+ live.set((state) => {
+ const own = state[sessionId] ?? {}
+ const prev = own[id]
+ if (entry === null ? prev === undefined : prev !== undefined && JSON.stringify({ ...prev, at: 0 }) === JSON.stringify({ ...entry, at: 0 })) return state
+ const next = { ...own }
+ if (entry === null) delete next[id]
+ else next[id] = { ...entry, at: prev?.at ?? Date.now() }
+ return { ...state, [sessionId]: next }
+ })
+ },
+ noteCards: (sessionId, callIds, delta) => {
+ if (sessionId !== undefined) cards.set(state => countCards(state, sessionId, callIds, delta))
+ },
+ clearLive: sessionId => live.set((state) => {
+ if (!state[sessionId]) return state
+ const next = { ...state }
+ delete next[sessionId]
+ return next
+ }),
+ }
+}
diff --git a/ds-bot/test/chat-rows.test.js b/ds-bot/test/chat-rows.test.js
new file mode 100644
index 00000000..8a8d6fc5
--- /dev/null
+++ b/ds-bot/test/chat-rows.test.js
@@ -0,0 +1,51 @@
+import assert from 'node:assert/strict'
+import { test } from 'node:test'
+import { fileURLToPath } from 'node:url'
+import { runInNewContext } from 'node:vm'
+import { build } from 'esbuild'
+
+const bundle = await build({
+ entryPoints: [fileURLToPath(new URL('../src/client/cells.js', import.meta.url))],
+ bundle: true, format: 'cjs', platform: 'node', write: false,
+ external: ['react', 'react-dom', '@deepseek-ai/dsh-client-ui-primitives'],
+})
+const module = { exports: {} }
+runInNewContext(bundle.outputFiles[0].text, {
+ module, exports: module.exports, Intl, Date,
+ require: (name) => {
+ const platform = {
+ react: { createElement: (type, props, ...children) => ({ type, props: props ?? {}, children: children.flat(Infinity) }) },
+ 'react-dom': {},
+ '@deepseek-ai/dsh-client-ui-primitives': {},
+ }
+ if (!(name in platform)) throw new Error(`no platform module ${name}`)
+ return platform[name]
+ },
+})
+const { ChatRows } = module.exports
+
+const roster = { byId: { b: { id: 'b', name: 'Writer' } }, roomsById: {} }
+const MINUTE = 60_000
+const shape = rows => [...rows].map(row => (row.props.className === 'bt-time-sep' ? 'clock' : row.type.name === 'Bubbles' ? `bot:${row.props.texts.join('+')}` : row.type.name))
+
+test('a Bot\'s messages in a row are one block', () => {
+ const items = [
+ { kind: 'user', text: 'hi', time: MINUTE },
+ { kind: 'bot', text: 'one', time: 2 * MINUTE },
+ { kind: 'bot', text: 'two', time: 2 * MINUTE },
+ { kind: 'user', text: 'and?', time: 3 * MINUTE },
+ { kind: 'bot', text: 'three', time: 4 * MINUTE },
+ ]
+ assert.deepEqual(shape(ChatRows({ items, sessionId: 'b', roster, actions: {} })), ['EarlierUser', 'bot:one+two', 'EarlierUser', 'bot:three'])
+})
+
+test('with the clock, a time separator sits above the first entry and after each pause of half an hour', () => {
+ const items = [
+ { kind: 'divider', time: 0 },
+ { kind: 'user', text: 'hi', time: MINUTE },
+ { kind: 'bot', text: 'one', time: 2 * MINUTE },
+ { kind: 'bot', text: 'two', time: 40 * MINUTE },
+ { kind: 'user', text: 'back', time: 75 * MINUTE },
+ ]
+ assert.deepEqual(shape(ChatRows({ items, sessionId: 'b', roster, actions: {}, clock: true })), ['PartLine', 'clock', 'EarlierUser', 'bot:one+two', 'clock', 'EarlierUser'])
+})