Skip to content

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

Respect the Enter preference in the question card's own-answer field

klarkxy362edb11dc8b
diff --git a/app/test/chat.test.mjs b/app/test/chat.test.mjs
index 0c1c2c82..1429f376 100644
--- a/app/test/chat.test.mjs
+++ b/app/test/chat.test.mjs
@@ -12,7 +12,6 @@ import { build } from 'esbuild'
const stubs = {
'cells.js': 'export const Bubbles = () => null\nexport const ChatRows = () => null\nexport const Shimmer = () => null\n',
'model-menu.js': 'export const ModelChoiceDock = () => null\n',
- 'questions.js': 'export const PendingQuestion = () => null\n',
'api.js': "export const call = async () => ({ sessionId: 'b1', items: [], cursor: null })\n",
}
const { outputFiles } = await build({
@@ -22,7 +21,7 @@ const { outputFiles } = await build({
plugins: [{
name: 'app-chat-stubs',
setup(bundler) {
- bundler.onResolve({ filter: /src\/client\/(cells|model-menu|questions|api)\.js$/ }, args => ({ path: args.path.split('/').pop(), namespace: 'app-chat-stub' }))
+ bundler.onResolve({ filter: /src\/client\/(cells|model-menu|api)\.js$/ }, args => ({ path: args.path.split('/').pop(), namespace: 'app-chat-stub' }))
bundler.onLoad({ filter: /.*/, namespace: 'app-chat-stub' }, args => ({ contents: stubs[args.path], loader: 'js' }))
},
}],
@@ -56,6 +55,8 @@ const react = {
useEffect: effect, useLayoutEffect: effect,
useMemo: make => make(),
useCallback: fn => fn,
+ useId: () => slot(() => ({ id: 'card-id' })).id,
+ useSyncExternalStore: (subscribe, getSnapshot) => getSnapshot(),
}
const module = { exports: {} }
runInNewContext(outputFiles[0].text, {
@@ -66,7 +67,7 @@ runInNewContext(outputFiles[0].text, {
throw new Error(`no platform module ${name}`)
},
window: { addEventListener() {}, removeEventListener() {}, innerHeight: 800 },
- document: { querySelector: () => null, body: {}, documentElement: { addEventListener() {}, removeEventListener() {} } },
+ document: { querySelector: () => null, body: {}, activeElement: null, addEventListener() {}, removeEventListener() {}, documentElement: { addEventListener() {}, removeEventListener() {} } },
navigator: { language: 'en' },
setTimeout: () => 0, clearTimeout() {},
requestAnimationFrame: () => 0, cancelAnimationFrame() {}, performance: { now: () => 0 },
@@ -103,8 +104,9 @@ const all = (node, check) => {
if (!node || typeof node !== 'object') return []
return [...(check(node) ? [node] : []), ...all(node.props.children, check)]
}
-const textarea = node => all(node, child => child.type === 'textarea')[0]
+const textarea = node => all(node, child => child.type === 'textarea' && child.props?.['data-composer-input'] !== undefined)[0]
const sendButton = node => all(node, child => child.type === 'button' && child.props?.className === 'dsb-send')[0]
+const answerField = node => all(node, child => child.props?.className === 'bt-q-input')[0]
const enter = (extra = {}) => ({
key: 'Enter', shiftKey: false, nativeEvent: { isComposing: false }, prevented: false,
preventDefault() { this.prevented = true }, ...extra,
@@ -114,9 +116,10 @@ const plain = value => JSON.parse(JSON.stringify(value))
// Mounts a Bot's chat with `prefs` in the roster, types a draft, and returns the
// send log plus the rendered tree accessor.
-const view = (prefs, ready = true) => {
+const view = (prefs, ready = true, question) => {
const sent = []
- const roster = { ready, prefs, byId: { b1: { id: 'b1', name: 'Bot' } }, roomsById: {}, questions: {} }
+ const answered = []
+ const roster = { ready, prefs, byId: { b1: { id: 'b1', name: 'Bot' } }, roomsById: {}, questions: question ? { b1: question } : {} }
const team = {
actions: {
noteSent() {},
@@ -125,6 +128,8 @@ const view = (prefs, ready = true) => {
openVoice() {},
clearQuote() {},
canReferenceChat: () => false,
+ answerQuestion: async (sessionId, id, answer) => { answered.push([sessionId, id, answer]) },
+ dismissQuestion() {},
},
hooks: {
useRoster: select => select(roster),
@@ -135,7 +140,7 @@ const view = (prefs, ready = true) => {
}
const instance = mount({ sessionId: 'b1', team })
textarea(instance.render()).props.onChange({ target: { value: 'hi' } })
- return { sent, tree: () => instance.render() }
+ return { sent, answered, tree: () => instance.render() }
}
test('with Enter sending on, a plain Enter sends the draft and clears it', async () => {
@@ -172,6 +177,26 @@ test('a roster without the flag keeps the default: Enter sends', async () => {
assert.deepEqual(plain(sent), [['b1', 'hi']])
})
+// The Bot's ask_user card shares the composer preference: off, a plain Enter in
+// the own-answer field is the field's newline and the card's Submit answers.
+test('the ask_user own-answer field honors the Enter preference', async () => {
+ const question = { id: 'q1', question: 'Pick?', options: ['Alpha', 'Beta'], allowCustom: true }
+ const sending = view({ enterToSend: true }, true, question)
+ answerField(sending.tree()).props.onChange({ target: { value: 'own' } })
+ const on = enter()
+ answerField(sending.tree()).props.onKeyDown(on)
+ await tick()
+ assert.equal(on.prevented, true)
+ assert.deepEqual(plain(sending.answered), [['b1', 'q1', { selected: [], custom: 'own' }]])
+ const keeping = view({ enterToSend: false }, true, question)
+ answerField(keeping.tree()).props.onChange({ target: { value: 'own' } })
+ const off = enter()
+ answerField(keeping.tree()).props.onKeyDown(off)
+ await tick()
+ assert.equal(off.prevented, false)
+ assert.deepEqual(plain(keeping.answered), [])
+})
+
test('Shift+Enter and IME confirmation keep their default behavior', async () => {
for (const extra of [{ shiftKey: true }, { nativeEvent: { isComposing: true } }]) {
const { sent, tree } = view({ enterToSend: true })
diff --git a/app/ui/src/chat.js b/app/ui/src/chat.js
index 3575988a..677447c9 100644
--- a/app/ui/src/chat.js
+++ b/app/ui/src/chat.js
@@ -188,7 +188,7 @@ export function Chat({ sessionId, team }) {
stream?.text ? h(Bubbles, { texts: [stream.text], roster, selfId: bot?.id, actions, streaming: true, sessionId }) : null,
// The Bot views' activity row (from the header pill) draws itself in here.
h('div', { 'data-chat-running': '' }),
- question ? h(PendingQuestion, { key: JSON.stringify([sessionId, question.id]), sessionId, question, actions, inline: true }) : null))),
+ question ? h(PendingQuestion, { key: JSON.stringify([sessionId, question.id]), sessionId, question, actions, inline: true, enterToSend: sendsOnEnter(roster.prefs) }) : null))),
h('div', { className: 'dsb-composer-root' },
h(ModelChoiceDock, { sessionId, useRoster: hooks.useRoster, actions }),
h(Composer, {
diff --git a/ds-bot/client.js b/ds-bot/client.js
index b56b8dfe..046bcbe1 100644
--- a/ds-bot/client.js
+++ b/ds-bot/client.js
@@ -3997,6 +3997,21 @@ function CellEmpty({ className }) {
return (0, import_react4.createElement)("span", { ref, className, hidden: true, "data-bt-empty": true });
}
+// src/client/enter-key.js
+var sendsOnEnter = (prefs) => prefs?.enterToSend !== false;
+function insertComposerNewline(event, inputActions) {
+ if (event.key !== "Enter" || event.shiftKey || event.altKey || event.ctrlKey || event.metaKey || event.isComposing || event.keyCode === 229 || event.getModifierState?.("AltGraph")) return false;
+ const target = event.target;
+ if (typeof target?.closest !== "function" || !target.closest('[data-composer-card] [role="textbox"]')) return false;
+ if (target.closest("[data-composer-composing]")) return false;
+ if (target.ownerDocument?.querySelector('[role="listbox"]')) return false;
+ if (typeof inputActions?.captureInsertion !== "function" || typeof inputActions?.insertText !== "function") return false;
+ event.preventDefault();
+ event.stopImmediatePropagation();
+ inputActions.insertText("\n", inputActions.captureInsertion());
+ return true;
+}
+
// src/client/card-hold.js
var import_react5 = require("react");
function useDockHold(sessionId, kind, requestId, actions, inline) {
@@ -4049,7 +4064,7 @@ function useOptionKeys(count, onPick, ownRef) {
}, [count, ownRef]);
return count > 0 && listening <= 1;
}
-function QuestionView({ question, onAnswer, onDismiss, onInteract, busy = false, ownAnswer = false, raised = false }) {
+function QuestionView({ question, onAnswer, onDismiss, onInteract, busy = false, ownAnswer = false, raised = false, enterToSend = true }) {
const [own, setOwn] = (0, import_react6.useState)("");
const [picked, setPicked] = (0, import_react6.useState)([]);
const ownRef = (0, import_react6.useRef)(null);
@@ -4092,7 +4107,7 @@ function QuestionView({ question, onAnswer, onDismiss, onInteract, busy = false,
}
},
onKeyDown: (event) => {
- if (event.key !== "Enter" || event.shiftKey || event.nativeEvent.isComposing) return;
+ if (event.key !== "Enter" || !enterToSend || event.shiftKey || event.nativeEvent.isComposing) return;
event.preventDefault();
submit();
}
@@ -4224,7 +4239,7 @@ function QuestionCard({ matched }) {
};
return (0, import_react6.createElement)(QuestionView, { key: index, question, onAnswer, onDismiss: () => pending.dismiss(), ownAnswer: true, raised: true });
}
-function PendingQuestion({ sessionId, question, actions, inline }) {
+function PendingQuestion({ sessionId, question, actions, inline, enterToSend = true }) {
const [answered, setAnswered] = (0, import_react6.useState)(null);
const [busy, setBusy] = (0, import_react6.useState)(false);
const busyRef = (0, import_react6.useRef)(false);
@@ -4245,7 +4260,7 @@ function PendingQuestion({ sessionId, question, actions, inline }) {
return (0, import_react6.createElement)(
"div",
{ className: inline ? "bt-q-inline" : "bt-q-dock" },
- (0, import_react6.createElement)(QuestionView, { key: question.id, question, onAnswer, onDismiss, onInteract: hold, busy, ownAnswer: question.allowCustom === true, raised: !inline })
+ (0, import_react6.createElement)(QuestionView, { key: question.id, question, onAnswer, onDismiss, onInteract: hold, busy, ownAnswer: question.allowCustom === true, raised: !inline, enterToSend })
);
}
function QuestionDock({ sessionId, useRoster, useCards, useHeldCards, actions }) {
@@ -4253,7 +4268,7 @@ function QuestionDock({ sessionId, useRoster, useCards, useHeldCards, actions })
const drawn = useCards?.((state) => state[sessionId]?.[question?.callId] > 0) === true;
const held = useHeldCards?.((state) => state[sessionId]?.[heldCardKey("question", question?.id)] > 0) === true;
if (question === void 0 || question.callId && drawn && !held) return null;
- return (0, import_react6.createElement)(PendingQuestion, { key: JSON.stringify([sessionId, question.id]), sessionId, question, actions, inline: false });
+ return (0, import_react6.createElement)(PendingQuestion, { key: JSON.stringify([sessionId, question.id]), sessionId, question, actions, inline: false, enterToSend: useRoster((value) => sendsOnEnter(value.prefs)) });
}
function AnsweredCell({ node }) {
const data = node.data ?? {};
@@ -8935,7 +8950,7 @@ function renderCall(call2, { sessionId, roster, actions, useUi, useWork, findBot
const question = roster.questions?.[sessionId];
if (!question || question.callId !== call2.callId) return (0, import_react17.createElement)(CellEmpty, { className: "bt-q-gone" });
if (heldCards?.[heldCardKey("question", question.id)] > 0) return (0, import_react17.createElement)(CellEmpty);
- return (0, import_react17.createElement)(PendingQuestion, { key: JSON.stringify([sessionId, question.id]), sessionId, question, actions, inline: true });
+ return (0, import_react17.createElement)(PendingQuestion, { key: JSON.stringify([sessionId, question.id]), sessionId, question, actions, inline: true, enterToSend: sendsOnEnter(roster.prefs) });
}
case "show_view":
return (0, import_react17.createElement)(WidgetCell, { sessionId, callId: call2.callId, args: { text: arg, value: argValue }, done, isError: call2.isError, roster, actions, heldCards });
@@ -10687,21 +10702,6 @@ function NewMessagePills({ sessionId, useSessions, useUi, useTurnClock }) {
);
}
-// src/client/enter-key.js
-var sendsOnEnter = (prefs) => prefs?.enterToSend !== false;
-function insertComposerNewline(event, inputActions) {
- if (event.key !== "Enter" || event.shiftKey || event.altKey || event.ctrlKey || event.metaKey || event.isComposing || event.keyCode === 229 || event.getModifierState?.("AltGraph")) return false;
- const target = event.target;
- if (typeof target?.closest !== "function" || !target.closest('[data-composer-card] [role="textbox"]')) return false;
- if (target.closest("[data-composer-composing]")) return false;
- if (target.ownerDocument?.querySelector('[role="listbox"]')) return false;
- if (typeof inputActions?.captureInsertion !== "function" || typeof inputActions?.insertText !== "function") return false;
- event.preventDefault();
- event.stopImmediatePropagation();
- inputActions.insertText("\n", inputActions.captureInsertion());
- return true;
-}
-
// src/client/composer.js
var import_react21 = require("react");
var import_react_dom5 = require("react-dom");
diff --git a/ds-bot/src/client/cells.js b/ds-bot/src/client/cells.js
index 0127ff05..77895e73 100644
--- a/ds-bot/src/client/cells.js
+++ b/ds-bot/src/client/cells.js
@@ -6,6 +6,7 @@ import { linkMentions, mentionTarget, dayLabel, contentText, stripHeader, isHidd
import { SmileIcon, ReplyIcon, DotsIcon, CheckIcon, DownloadIcon, CopyIcon, MemoryIcon } from './icons.js'
import { colorOf, toolState, BotMark, RoomAvatar } from './mark.js'
import { CellEmpty } from './cell-empty.js'
+import { sendsOnEnter } from './enter-key.js'
import { SettledQuestion, PendingQuestion } from './questions.js'
import { AnsweredReply, WidgetCell } from './widget-cell.js'
import { SecretToolCell } from './secret-card.js'
@@ -1086,7 +1087,7 @@ function renderCall(call, { sessionId, roster, actions, useUi, useWork, findBot,
// Answered or closed: the card leaves no gap where it was.
if (!question || question.callId !== call.callId) return h(CellEmpty, { className: 'bt-q-gone' })
if (heldCards?.[heldCardKey('question', question.id)] > 0) return h(CellEmpty)
- return h(PendingQuestion, { key: JSON.stringify([sessionId, question.id]), sessionId, question, actions, inline: true })
+ return h(PendingQuestion, { key: JSON.stringify([sessionId, question.id]), sessionId, question, actions, inline: true, enterToSend: sendsOnEnter(roster.prefs) })
}
case 'show_view':
return h(WidgetCell, { sessionId, callId: call.callId, args: { text: arg, value: argValue }, done, isError: call.isError, roster, actions, heldCards })
diff --git a/ds-bot/src/client/questions.js b/ds-bot/src/client/questions.js
index 9428a41b..9345aab3 100644
--- a/ds-bot/src/client/questions.js
+++ b/ds-bot/src/client/questions.js
@@ -1,6 +1,7 @@
import { createElement as h, useEffect, useId, useRef, useState, useSyncExternalStore } from 'react'
import { CloseIcon, CheckIcon } from './icons.js'
import { CellEmpty } from './cell-empty.js'
+import { sendsOnEnter } from './enter-key.js'
import { t } from './i18n.js'
import { useDockHold } from './card-hold.js'
import { createSource, heldCardKey } from './sources.js'
@@ -55,7 +56,7 @@ export function useOptionKeys(count, onPick, ownRef) {
// A question shows two ways: as a bubble in the transcript, and raised when it
// sits in the dock above the composer.
-function QuestionView({ question, onAnswer, onDismiss, onInteract, busy = false, ownAnswer = false, raised = false }) {
+function QuestionView({ question, onAnswer, onDismiss, onInteract, busy = false, ownAnswer = false, raised = false, enterToSend = true }) {
const [own, setOwn] = useState('')
const [picked, setPicked] = useState([])
const ownRef = useRef(null)
@@ -86,7 +87,7 @@ function QuestionView({ question, onAnswer, onDismiss, onInteract, busy = false,
'aria-keyshortcuts': hints ? ownLetter?.toLowerCase() : undefined,
onChange: (event) => { if (!busy) { onInteract?.(); setOwn(event.target.value) } },
onKeyDown: (event) => {
- if (event.key !== 'Enter' || event.shiftKey || event.nativeEvent.isComposing) return
+ if (event.key !== 'Enter' || !enterToSend || event.shiftKey || event.nativeEvent.isComposing) return
event.preventDefault()
submit()
},
@@ -179,7 +180,7 @@ export function QuestionCard({ matched }) {
return h(QuestionView, { key: index, question, onAnswer, onDismiss: () => pending.dismiss(), ownAnswer: true, raised: true })
}
-export function PendingQuestion({ sessionId, question, actions, inline }) {
+export function PendingQuestion({ sessionId, question, actions, inline, enterToSend = true }) {
const [answered, setAnswered] = useState(null)
const [busy, setBusy] = useState(false)
const busyRef = useRef(false)
@@ -200,7 +201,7 @@ export function PendingQuestion({ sessionId, question, actions, inline }) {
const onAnswer = answer => run(() => actions.answerQuestion(sessionId, question.id, { selected: answer.selected ?? [], custom: answer.custom ?? '' }))
const onDismiss = () => run(() => actions.dismissQuestion(sessionId))
return h('div', { className: inline ? 'bt-q-inline' : 'bt-q-dock' },
- h(QuestionView, { key: question.id, question, onAnswer, onDismiss, onInteract: hold, busy, ownAnswer: question.allowCustom === true, raised: !inline }))
+ h(QuestionView, { key: question.id, question, onAnswer, onDismiss, onInteract: hold, busy, ownAnswer: question.allowCustom === true, raised: !inline, enterToSend }))
}
// Questions asked by a tool call render inline at that call (see ToolCell); the dock
@@ -211,7 +212,7 @@ export function QuestionDock({ sessionId, useRoster, useCards, useHeldCards, act
const drawn = useCards?.(state => state[sessionId]?.[question?.callId] > 0) === true
const held = useHeldCards?.(state => state[sessionId]?.[heldCardKey('question', question?.id)] > 0) === true
if (question === undefined || (question.callId && drawn && !held)) return null
- return h(PendingQuestion, { key: JSON.stringify([sessionId, question.id]), sessionId, question, actions, inline: false })
+ return h(PendingQuestion, { key: JSON.stringify([sessionId, question.id]), sessionId, question, actions, inline: false, enterToSend: useRoster(value => sendsOnEnter(value.prefs)) })
}
// An answered card in the transcript: the question stays where it was asked, with the
diff --git a/ds-bot/test/card-hold.test.js b/ds-bot/test/card-hold.test.js
index dd48cf9a..602e7b09 100644
--- a/ds-bot/test/card-hold.test.js
+++ b/ds-bot/test/card-hold.test.js
@@ -193,6 +193,52 @@ test('a question keeps its custom answer and selection while submitting, after f
assert.equal(count('chief', 'question', question.id), 0)
})
+// The Bot ask_user card shares the composer preference: while Enter sends, a plain
+// Enter answers; off, it is the field's own newline and the Submit button answers.
+test('the own-answer field honors the Enter preference', async () => {
+ const enter = (extra = {}) => ({
+ key: 'Enter', shiftKey: false, nativeEvent: { isComposing: false }, prevented: false,
+ preventDefault() { this.prevented = true }, ...extra,
+ })
+ const cards = []
+ const mountCard = (enterToSend) => {
+ const { actions } = lease()
+ const sent = []
+ actions.answerQuestion = (...args) => { sent.push(args); return Promise.resolve() }
+ const pending = mount(PendingQuestion, { actions, sessionId: 'chief', question: { ...question, multiSelect: false }, inline: false, enterToSend })
+ const view = mount(childOf(pending.render()).type, childOf(pending.render()).props)
+ cards.push(pending, view)
+ const form = view.render()
+ field(form).props.onChange({ target: { value: 'My own words' } })
+ return { sent, form: () => view.render() }
+ }
+ const sending = mountCard(true)
+ const on = enter()
+ field(sending.form()).props.onKeyDown(on)
+ await tick()
+ assert.equal(on.prevented, true)
+ assert.deepEqual(plain(sending.sent), [['chief', 'question', { selected: [], custom: 'My own words' }]])
+ const keeping = mountCard(false)
+ const off = enter()
+ field(keeping.form()).props.onKeyDown(off)
+ await tick()
+ assert.equal(off.prevented, false)
+ assert.deepEqual(plain(keeping.sent), [])
+ keeping.form().props.onSubmit({ preventDefault() {} })
+ await tick()
+ assert.deepEqual(plain(keeping.sent), [['chief', 'question', { selected: [], custom: 'My own words' }]])
+ const shifted = mountCard(true)
+ for (const extra of [{ shiftKey: true }, { nativeEvent: { isComposing: true } }]) {
+ const event = enter(extra)
+ field(shifted.form()).props.onKeyDown(event)
+ assert.equal(event.prevented, false)
+ }
+ await tick()
+ assert.deepEqual(plain(shifted.sent), [])
+ // Mounted cards count as open for the letter keys; leave none behind.
+ for (const instance of cards) instance.unmount()
+})
+
test('keyboard selection owns a dock card and busy questions cannot submit or dismiss twice', async () => {
const { actions, count } = lease()
const wait = deferred()