Skip to content

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

Show a Bot's character when its photo does not load

Fei24110931c19e12cb
diff --git a/ds-bot/client.js b/ds-bot/client.js
index 1783c49c..f6ff3bc9 100644
--- a/ds-bot/client.js
+++ b/ds-bot/client.js
@@ -3262,11 +3262,13 @@ function BotMark({ bot, look: given, size = 36, state = "idle", live = false, ga
const maskId = (0, import_react2.useRef)("");
if (maskId.current === "") maskId.current = `bt-mark-${nextMarkSerial()}`;
const [poked, setPoked] = (0, import_react2.useState)(false);
+ const [broken, setBroken] = (0, import_react2.useState)("");
+ const image = look.image && look.image !== broken ? look.image : void 0;
useGaze(ref, gaze);
const common = {
ref,
className: poked ? "bt-mark bt-mark-poke" : "bt-mark",
- "data-shape": look.image ? "image" : shapeId(look.shape),
+ "data-shape": image ? "image" : shapeId(look.shape),
"data-state": STATES.includes(state) ? state : "idle",
"data-live": live ? "" : void 0,
"data-fidget": live ? FIDGETS[fnv1a(`${bot?.id ?? ""}:fidget`) % FIDGETS.length] : void 0,
@@ -3281,7 +3283,7 @@ function BotMark({ bot, look: given, size = 36, state = "idle", live = false, ga
if (/^bt-poke/.test(event.animationName)) setPoked(false);
} : void 0
};
- if (look.image) return (0, import_react2.createElement)("span", common, (0, import_react2.createElement)("img", { className: "bt-mark-img", src: look.image, alt: "", draggable: false }));
+ if (image) return (0, import_react2.createElement)("span", common, (0, import_react2.createElement)("img", { className: "bt-mark-img", src: image, alt: "", draggable: false, onError: () => setBroken(image) }));
const box = shapeOf(look.shape).size;
return (0, import_react2.createElement)("span", common, (0, import_react2.createElement)("svg", { viewBox: `0 0 ${box} ${box}`, dangerouslySetInnerHTML: { __html: characterMarkup(look.shape, look.color).replaceAll(MASK_ID, maskId.current) } }));
}
diff --git a/ds-bot/src/client/mark.js b/ds-bot/src/client/mark.js
index a0058fee..498d23bb 100644
--- a/ds-bot/src/client/mark.js
+++ b/ds-bot/src/client/mark.js
@@ -54,11 +54,14 @@ export function BotMark({ bot, look: given, size = 36, state = 'idle', live = fa
const maskId = useRef('')
if (maskId.current === '') maskId.current = `bt-mark-${nextMarkSerial()}`
const [poked, setPoked] = useState(false)
+ // A photo that does not load shows the character instead; a new photo is tried again.
+ const [broken, setBroken] = useState('')
+ const image = look.image && look.image !== broken ? look.image : undefined
useGaze(ref, gaze)
const common = {
ref,
className: poked ? 'bt-mark bt-mark-poke' : 'bt-mark',
- 'data-shape': look.image ? 'image' : shapeId(look.shape),
+ 'data-shape': image ? 'image' : shapeId(look.shape),
'data-state': STATES.includes(state) ? state : 'idle',
'data-live': live ? '' : undefined,
'data-fidget': live ? FIDGETS[fnv1a(`${bot?.id ?? ''}:fidget`) % FIDGETS.length] : undefined,
@@ -71,7 +74,7 @@ export function BotMark({ bot, look: given, size = 36, state = 'idle', live = fa
onClick: pokeable ? () => setPoked(true) : undefined,
onAnimationEnd: poked ? (event) => { if (/^bt-poke/.test(event.animationName)) setPoked(false) } : undefined,
}
- if (look.image) return h('span', common, h('img', { className: 'bt-mark-img', src: look.image, alt: '', draggable: false }))
+ if (image) return h('span', common, h('img', { className: 'bt-mark-img', src: image, alt: '', draggable: false, onError: () => setBroken(image) }))
const box = shapeOf(look.shape).size
return h('span', common, h('svg', { viewBox: `0 0 ${box} ${box}`, dangerouslySetInnerHTML: { __html: characterMarkup(look.shape, look.color).replaceAll(MASK_ID, maskId.current) } }))
}
diff --git a/ds-bot/test/bot-mark.test.js b/ds-bot/test/bot-mark.test.js
index 72d9b573..507e29f3 100644
--- a/ds-bot/test/bot-mark.test.js
+++ b/ds-bot/test/bot-mark.test.js
@@ -6,17 +6,20 @@ import { fileURLToPath } from 'node:url'
import { build } from 'esbuild'
const bundle = await build({
- stdin: { contents: "export { botState, BotAvatar } from './src/client/mark.js'\nexport { SHELL_CSS } from './src/client/styles.js'", resolveDir: dirname(dirname(fileURLToPath(import.meta.url))) },
+ stdin: { contents: "export { botState, BotAvatar, BotMark } from './src/client/mark.js'\nexport { SHELL_CSS } from './src/client/styles.js'", resolveDir: dirname(dirname(fileURLToPath(import.meta.url))) },
bundle: true, format: 'cjs', platform: 'node', write: false, logLevel: 'silent',
external: ['react', 'react-dom', '@deepseek-ai/dsh-client-ui-primitives'],
})
const module = { exports: {} }
+// A test can queue the values the next useState calls return, and read what was set.
+const states = []
+const sets = []
const react = {
createElement: (type, props, ...children) => ({ type, props: props ?? {}, children: children.flat(Infinity) }),
- useState: initial => [initial, () => {}], useEffect: () => {}, useRef: current => ({ current }), useLayoutEffect: () => {}, Fragment: 'fragment',
+ useState: initial => [states.length > 0 ? states.shift() : initial, value => sets.push(value)], useEffect: () => {}, useRef: current => ({ current }), useLayoutEffect: () => {}, Fragment: 'fragment',
}
runInNewContext(bundle.outputFiles[0].text, { module, exports: module.exports, require: name => (name === 'react' ? react : {}) })
-const { botState, BotAvatar, SHELL_CSS } = module.exports
+const { botState, BotAvatar, BotMark, SHELL_CSS } = module.exports
test('a Bot that waits for work it handed on has a mark of its own, behind a running turn and a question', () => {
assert.equal(botState(false, 'waiting', false), 'waiting')
@@ -34,3 +37,21 @@ test('a waiting Bot does not wear the working badge, since no turn of it runs',
assert.deepEqual(badges('waiting'), [])
assert.deepEqual(badges('working'), ['bt-badge bt-badge-working'])
})
+
+test('a photo that does not load shows the Bot\'s character instead', () => {
+ const photo = 'data:image/png;base64,iVBORw0KGgo='
+ const bot = { id: 'b', name: 'Writer', avatar: { shape: 'fox', image: photo } }
+ const img = BotMark({ bot }).children[0]
+ assert.equal(img.type, 'img')
+ sets.length = 0
+ img.props.onError()
+ assert.deepEqual(sets, [photo])
+ // Rendered again with that photo marked broken: the character, not an empty image.
+ states.push(false, photo)
+ const mark = BotMark({ bot })
+ assert.equal(mark.children[0].type, 'svg')
+ assert.notEqual(mark.props['data-shape'], 'image')
+ // A new photo is tried again.
+ states.push(false, photo)
+ assert.equal(BotMark({ bot: { ...bot, avatar: { ...bot.avatar, image: `${photo}AA` } } }).children[0].type, 'img')
+})