Skip to content

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

Keep pending cards available while chat history loads

Chimney46a98c28cd19
diff --git a/ds-bot/client.js b/ds-bot/client.js
index 70a0f3d1..26a97877 100644
--- a/ds-bot/client.js
+++ b/ds-bot/client.js
@@ -1800,7 +1800,6 @@ function isHiddenTurn(roster, sessionId, turn) {
return (roster.exchangeTurns[sessionId] ?? []).includes(turn);
}
var toolName = (root) => root.name || root.call?.name;
-var historyLoading = (snapshot) => snapshot?.openState === "cold" || snapshot?.openState === "loading";
function toolArgs(root) {
if (typeof root.args?.text === "function") {
return { text: (key) => root.args.text(key) ?? void 0, value: (key) => typeof root.args.value === "function" ? root.args.value(key) : void 0 };
@@ -3691,11 +3690,10 @@ function PendingQuestion({ sessionId, question, actions, inline }) {
(0, import_react4.createElement)(QuestionView, { key: question.id, question, onAnswer, onDismiss, ownAnswer: question.allowCustom === true, raised: !inline })
);
}
-function QuestionDock({ sessionId, useRoster, useCards, useSession, actions }) {
+function QuestionDock({ sessionId, useRoster, useCards, actions }) {
const question = useRoster((value) => value.questions?.[sessionId]);
const drawn = useCards?.((state) => state[sessionId]?.[question?.callId] > 0) === true;
- const loading = useSession?.(historyLoading) === true;
- if (question === void 0 || question.callId && (drawn || loading)) return null;
+ if (question === void 0 || question.callId && drawn) return null;
return (0, import_react4.createElement)(PendingQuestion, { sessionId, question, actions, inline: false });
}
function AnsweredCell({ node }) {
@@ -3889,13 +3887,12 @@ function SecretToolCell({ sessionId, callId, name, done, content, roster, action
}
return null;
}
-function SecretDock({ sessionId, useRoster, useCards, useSession, actions }) {
+function SecretDock({ sessionId, useRoster, useCards, actions }) {
const roster = useRoster((value) => value);
const shown = useCards?.((state) => state[sessionId]) ?? NONE;
- const loading = useSession?.(historyLoading) === true;
const bot = roster.byId[sessionId];
if (!bot || currentPart(bot) !== sessionId) return null;
- const drawn = (entry) => entry.callId && entry.sessionId === sessionId && (loading || shown[entry.callId] > 0);
+ const drawn = (entry) => entry.callId && entry.sessionId === sessionId && shown[entry.callId] > 0;
const waiting = (roster.secretRequests?.[bot.id] ?? []).filter((entry) => entry.status === "pending" && !drawn(entry));
if (waiting.length === 0) return null;
return (0, import_react5.createElement)("div", { className: "bt-q-dock bt-secret-dock" }, waiting.map((request) => (0, import_react5.createElement)(SecretCard, { key: `${request.id}:${request.kind}`, bot, request, roster, actions })));
diff --git a/ds-bot/src/client/questions.js b/ds-bot/src/client/questions.js
index 4c3db483..c75a14f3 100644
--- a/ds-bot/src/client/questions.js
+++ b/ds-bot/src/client/questions.js
@@ -1,7 +1,6 @@
import { createElement as h, useEffect, useId, useRef, useState } from 'react'
import { CloseIcon, CheckIcon } from './icons.js'
import { t } from './i18n.js'
-import { historyLoading } from './text.js'
// -------------------------------------------------------------------------
// Question cards. `ask_user` cards sit in the transcript and never block the Bot;
@@ -175,12 +174,11 @@ export function PendingQuestion({ sessionId, question, actions, inline }) {
}
// Questions asked by a tool call render inline at that call (see ToolCell); the dock
-// carries the ones whose call the transcript does not draw.
-export function QuestionDock({ sessionId, useRoster, useCards, useSession, actions }) {
+// carries the ones whose call the transcript does not draw, including while history loads.
+export function QuestionDock({ sessionId, useRoster, useCards, actions }) {
const question = useRoster(value => value.questions?.[sessionId])
const drawn = useCards?.(state => state[sessionId]?.[question?.callId] > 0) === true
- const loading = useSession?.(historyLoading) === true
- if (question === undefined || (question.callId && (drawn || loading))) return null
+ if (question === undefined || (question.callId && drawn)) return null
return h(PendingQuestion, { sessionId, question, actions, inline: false })
}
diff --git a/ds-bot/src/client/secret-card.js b/ds-bot/src/client/secret-card.js
index aac8e4f4..3a0cef71 100644
--- a/ds-bot/src/client/secret-card.js
+++ b/ds-bot/src/client/secret-card.js
@@ -5,7 +5,7 @@
import { createElement as h, useEffect, useId, useState } from 'react'
import { CheckIcon, CloseIcon, TrashIcon } from './icons.js'
import { BotAvatar, BotMark } from './mark.js'
-import { contentText, currentPart, historyLoading } from './text.js'
+import { contentText, currentPart } from './text.js'
import { dateLocale, t } from './i18n.js'
import { SPRING_POP, SPRING_SHAPE, spring } from './motion.js'
@@ -155,13 +155,12 @@ export function SecretToolCell({ sessionId, callId, name, done, content, roster,
// A card whose call the transcript does not draw (an earlier part of the chat, a
// hidden turn, a call outside the loaded history) waits above the composer instead.
-export function SecretDock({ sessionId, useRoster, useCards, useSession, actions }) {
+export function SecretDock({ sessionId, useRoster, useCards, actions }) {
const roster = useRoster(value => value)
const shown = useCards?.(state => state[sessionId]) ?? NONE
- const loading = useSession?.(historyLoading) === true
const bot = roster.byId[sessionId]
if (!bot || currentPart(bot) !== sessionId) return null
- const drawn = entry => entry.callId && entry.sessionId === sessionId && (loading || shown[entry.callId] > 0)
+ const drawn = entry => entry.callId && entry.sessionId === sessionId && shown[entry.callId] > 0
const waiting = (roster.secretRequests?.[bot.id] ?? []).filter(entry => entry.status === 'pending' && !drawn(entry))
if (waiting.length === 0) return null
return h('div', { className: 'bt-q-dock bt-secret-dock' }, waiting.map(request => h(SecretCard, { key: `${request.id}:${request.kind}`, bot, request, roster, actions })))
diff --git a/ds-bot/src/client/text.js b/ds-bot/src/client/text.js
index b4bc637a..311023e4 100644
--- a/ds-bot/src/client/text.js
+++ b/ds-bot/src/client/text.js
@@ -109,10 +109,6 @@ export function isHiddenTurn(roster, sessionId, turn) {
export const toolName = root => root.name || root.call?.name
-// While a Session's history loads, a card asked in it may yet be drawn at its call,
-// so the docks hold it back until then.
-export const historyLoading = snapshot => snapshot?.openState === 'cold' || snapshot?.openState === 'loading'
-
export function toolArgs(root) {
if (typeof root.args?.text === 'function') {
return { text: key => root.args.text(key) ?? undefined, value: key => (typeof root.args.value === 'function' ? root.args.value(key) : undefined) }
diff --git a/ds-bot/test/tool-cells.test.js b/ds-bot/test/tool-cells.test.js
index e8b29285..6aceb53b 100644
--- a/ds-bot/test/tool-cells.test.js
+++ b/ds-bot/test/tool-cells.test.js
@@ -286,16 +286,41 @@ test('a card whose call is not drawn waits in the dock; a drawn one shows only a
assert.match(docks(store, roster), /Which draft\?.*Chief needs a key/)
})
-test('the docks hold a card back while the history loads, and keep cards without a call', () => {
+test('the docks keep pending cards through history loading until their calls actually mount', () => {
const store = cardStore()
const roster = team({ questions: { chief: question('program:ptc:1') }, secretRequests: { chief: [request('program:ptc:2')] } })
+ for (const openState of ['cold', 'loading', 'open', 'error']) {
+ const waiting = docks(store, roster, { openState })
+ assert.equal(count(waiting, 'Which draft?'), 1, openState)
+ assert.equal(count(waiting, 'needs a key'), 1, openState)
+ }
+ const root = program([call('ask_user', 'program:ptc:1'), call('request_secret', 'program:ptc:2', { args: { name: 'DEMO_TOKEN' } })])
+ const { out, unmount } = draw(root, store, { roster })
assert.equal(docks(store, roster, { openState: 'loading' }), '')
- assert.equal(docks(store, roster, { openState: 'cold' }), '')
- assert.match(docks(store, roster, { openState: 'error' }), /Which draft\?.*Chief needs a key/)
+ assert.equal(count(text(out), 'Which draft?'), 1)
+ assert.equal(count(text(out), 'needs a key'), 1)
+ unmount()
+ assert.match(docks(store, roster, { openState: 'loading' }), /Which draft\?.*Chief needs a key/)
const free = team({ questions: { chief: question(undefined) }, secretRequests: { chief: [request(undefined)] } })
assert.match(docks(store, free, { openState: 'loading' }), /Which draft\?.*Chief needs a key/)
})
+test('a question can be answered and a secret request canceled before history arrives', async () => {
+ const store = cardStore()
+ const roster = team({ questions: { chief: question('question-call') }, secretRequests: { chief: [request('secret-call')] } })
+ const answers = []
+ const canceled = []
+ const actions = { answerQuestion: async (...args) => answers.push(args), secretCancel: async id => canceled.push(id) }
+ const asking = expand(QuestionDock(dockProps(store, roster, { openState: 'cold', actions })))
+ find(asking, node => node.type === 'button' && node.props.className === 'bt-q-opt').props.onClick()
+ assert.deepEqual(JSON.parse(JSON.stringify(answers)), [['chief', 'question', { selected: ['Short'], custom: '' }]])
+ const secret = expand(SecretDock(dockProps(store, roster, { openState: 'loading', actions })))
+ await find(secret, node => node.props['aria-label'] === 'Cancel the request').props.onClick()
+ assert.deepEqual(canceled, ['request'])
+ effects = []
+ assert.equal(docks(store, team(), { openState: 'loading' }), '')
+})
+
test('a card from an earlier part waits in the dock even when a call here has the same id', () => {
const store = cardStore()
const current = { ...chief, sessionId: 'chief-2', parts: ['chief', 'chief-2'] }