Skip to content

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

Show the desktop app's update state in About

Fei2411cdbef1aa45c0
diff --git a/app/src/main.mjs b/app/src/main.mjs
index 01b23662..f1d3a6ea 100644
--- a/app/src/main.mjs
+++ b/app/src/main.mjs
@@ -32,6 +32,9 @@ const IPC = {
browserImportSources: 'ds-bot:browser-import-sources', browserImportPick: 'ds-bot:browser-import-pick',
browserImportLive: 'ds-bot:browser-import-live', browserImportApply: 'ds-bot:browser-import-apply',
browserImportCancel: 'ds-bot:browser-import-cancel',
+ appUpdateState: 'ds-bot:app-update-state', appUpdateCheck: 'ds-bot:app-update-check',
+ appUpdateInstall: 'ds-bot:app-update-install', appUpdateOpen: 'ds-bot:app-update-open',
+ appUpdateChanged: 'ds-bot:app-update-changed',
}
// A cookie export larger than this is not a cookie export.
const IMPORT_FILE_MAX = 32 * 1024 * 1024
@@ -140,6 +143,7 @@ async function start() {
// Not during the import, which a restart would cut short; before the Host, so that an
// update can still come when this version's Host does not start.
updates = startUpdates()
+ updates?.subscribe((state) => { mainWindow?.webContents.send(IPC.appUpdateChanged, state) })
host = newHost()
return host.start()
})()
@@ -216,6 +220,27 @@ async function start() {
assertWindow(event)
if (typeof id === 'string') cookieImports.drop(id)
})
+ // The app's own update state, for the About row. `updates` exists once the ready block
+ // created it; before that (and in runs without an updater) the state is null.
+ ipcMain.handle(IPC.appUpdateState, (event) => {
+ assertWindow(event)
+ return updates?.state() ?? null
+ })
+ ipcMain.handle(IPC.appUpdateCheck, (event) => {
+ assertWindow(event)
+ updates?.check()
+ })
+ ipcMain.handle(IPC.appUpdateInstall, async (event) => {
+ assertWindow(event)
+ if (updates?.state().phase === 'downloaded') await updates.install()
+ })
+ ipcMain.handle(IPC.appUpdateOpen, (event) => {
+ assertWindow(event)
+ const state = updates?.state()
+ if (state?.phase === 'available' && typeof state.page === 'string' && state.page.startsWith('https://')) {
+ void shell.openExternal(state.page)
+ }
+ })
// The plugin keeps the team workspace; the app remembers it for its own checks.
ipcMain.on(IPC.teamWorkspace, (event, path) => {
if (fixed || !fromWindow(event) || typeof path !== 'string' || !isAbsolute(path)) return
diff --git a/app/src/preload.cjs b/app/src/preload.cjs
index 1a83abb5..5479f0d6 100644
--- a/app/src/preload.cjs
+++ b/app/src/preload.cjs
@@ -15,6 +15,8 @@ if (host !== undefined && location.origin === host) {
// The Bot browsers, in the shape of DSH Desktop's browser bridge so that ds-bot drives both
// alike; `forget` clears a key's storage, which here outlives the app.
browser: browserBridge(),
+ // The app's own updater, for the About row's state and buttons.
+ updates: updatesBridge(),
})
const caption = process.argv.find(value => value.startsWith('--ds-bot-caption='))
if (caption !== undefined) {
@@ -62,6 +64,25 @@ function browserBridge() {
}
}
+function updatesBridge() {
+ const listeners = new Set()
+ ipcRenderer.on('ds-bot:app-update-changed', (_event, state) => {
+ for (const listener of [...listeners]) {
+ try { listener(state) } catch (error) { console.error('DeepSeek Bot: an update state handler failed', error) }
+ }
+ })
+ return {
+ state: () => ipcRenderer.invoke('ds-bot:app-update-state'),
+ check: () => ipcRenderer.invoke('ds-bot:app-update-check'),
+ install: () => ipcRenderer.invoke('ds-bot:app-update-install'),
+ open: () => ipcRenderer.invoke('ds-bot:app-update-open'),
+ subscribe(listener) {
+ listeners.add(listener)
+ return () => { listeners.delete(listener) }
+ },
+ }
+}
+
function frameless(height, mica) {
const root = document.documentElement
root.dataset.windowsTitlebar = ''
diff --git a/app/src/updates.mjs b/app/src/updates.mjs
index 76ee31d4..d95ebe6a 100644
--- a/app/src/updates.mjs
+++ b/app/src/updates.mjs
@@ -74,13 +74,38 @@ function isHttpsPage(page) {
}
}
+// The About row shows the checker's phase: checking → current | downloading → downloaded |
+// available | failed. While a check, a download or a ready install is on, a new check must
+// not start, so `check()` is a no-op in those phases.
+const UPDATE_BUSY = new Set(['checking', 'downloading', 'downloaded'])
+
+function stateHolder(log) {
+ let state = { phase: 'checking' }
+ const listeners = new Set()
+ return {
+ state: () => state,
+ set: (next) => {
+ state = next
+ for (const listener of [...listeners]) {
+ try { listener(next) } catch (error) { log.error(`DeepSeek Bot: an update state listener failed: ${error instanceof Error ? error.message : String(error)}`) }
+ }
+ },
+ subscribe: (listener) => {
+ listeners.add(listener)
+ return () => { listeners.delete(listener) }
+ },
+ }
+}
+
// `asset` names the release asset of this install (default: the macOS zip); a release without
// it does not count.
export function watchReleases({ current, arch, fetch = globalThis.fetch, ask, open, feed = RELEASES_URL, log = console, asset }) {
const assetName = asset ?? (version => `DeepSeek-Bot-${version}-mac-${arch}.zip`)
let asked
let latest = Promise.resolve(null)
- const check = () => {
+ const holder = stateHolder(log)
+ const run = () => {
+ holder.set({ phase: 'checking' })
latest = (async () => {
try {
const response = await fetch(feed, {
@@ -88,11 +113,13 @@ export function watchReleases({ current, arch, fetch = globalThis.fetch, ask, op
})
if (!response.ok) {
log.error(`DeepSeek Bot: update check failed: HTTP ${String(response.status)}`)
+ holder.set({ phase: 'failed' })
return null
}
const releases = await response.json()
if (!Array.isArray(releases)) {
log.error('DeepSeek Bot: update check failed: releases response is not an array')
+ holder.set({ phase: 'failed' })
return null
}
const currentVersion = parseVersion(current)
@@ -110,7 +137,10 @@ export function watchReleases({ current, arch, fetch = globalThis.fetch, ask, op
}
if (found === undefined || isNewer(version, found.version)) found = { version, page: release.html_url }
}
- if (found === undefined) return null
+ if (found === undefined) {
+ holder.set({ phase: 'current' })
+ return null
+ }
log.info(`DeepSeek Bot: update ${found.version} available`)
if (ask !== undefined && asked !== found.version) {
asked = found.version
@@ -118,16 +148,20 @@ export function watchReleases({ current, arch, fetch = globalThis.fetch, ask, op
.then(yes => (yes ? open(found.page) : undefined))
.catch((error) => { log.error(`DeepSeek Bot: update ${found.version} not opened: ${error instanceof Error ? error.message : String(error)}`) })
}
+ holder.set({ phase: 'available', version: found.version, page: found.page })
return found
} catch (error) {
log.error(`DeepSeek Bot: update check failed: ${error instanceof Error ? error.message : String(error)}`)
+ holder.set({ phase: 'failed' })
return null
}
})()
}
- check()
+ // A check runs at once and then on the timer; a manual one only starts when none is on.
+ const check = () => { if (!UPDATE_BUSY.has(holder.state().phase)) run() }
+ run()
const timer = setInterval(check, CHECK_EVERY_MS)
- return { stop: () => { clearInterval(timer) }, latest: () => latest }
+ return { stop: () => { clearInterval(timer) }, latest: () => latest, state: holder.state, subscribe: holder.subscribe, check }
}
/**
@@ -144,34 +178,57 @@ export function watchReleases({ current, arch, fetch = globalThis.fetch, ask, op
* stop: () => void,
* latest: () => Promise<{ version: string, downloaded: Promise<boolean> } | null>,
* install: () => Promise<void>,
+ * state: () => { phase: string, version?: string, page?: string },
+ * subscribe: (listener: (state: { phase: string }) => void) => () => void,
+ * check: () => void,
* }} `latest` is what the newest check found: the version and whether its download finished.
- * `install` stops the Host and runs the installer, which opens the app again.
+ * `install` stops the Host and runs the installer, which opens the app again. `state` is
+ * the phase the About row shows; `check` runs the same check the timer does and does
+ * nothing while a check, a download or a ready install is on.
*/
export function watchUpdates({ updater, beforeInstall, ask, feed, log = console }) {
updater.autoDownload = true
updater.autoInstallOnAppQuit = true
if (feed) updater.setFeedURL({ provider: 'generic', url: feed })
+ const holder = stateHolder(log)
const install = async () => {
await beforeInstall()
updater.quitAndInstall(true, true)
}
let asked
+ updater.on('checking-for-update', () => { holder.set({ phase: 'checking' }) })
+ updater.on('update-not-available', () => { holder.set({ phase: 'current' }) })
+ updater.on('update-available', (info) => { holder.set({ phase: 'downloading', version: info?.version }) })
updater.on('update-downloaded', ({ version }) => {
log.info(`DeepSeek Bot: update ${version} downloaded`)
+ holder.set({ phase: 'downloaded', version })
if (ask === undefined || asked === version) return
asked = version
void ask(version).then(now => (now ? install() : undefined))
.catch((error) => { log.error(`DeepSeek Bot: update ${version} not installed: ${error instanceof Error ? error.message : String(error)}`) })
})
- updater.on('error', (error) => { log.error(`DeepSeek Bot: update failed: ${error instanceof Error ? error.message : String(error)}`) })
+ // A downloaded update stays ready: a later failed check does not hide it.
+ updater.on('error', (error) => {
+ log.error(`DeepSeek Bot: update failed: ${error instanceof Error ? error.message : String(error)}`)
+ if (holder.state().phase !== 'downloaded') holder.set({ phase: 'failed' })
+ })
let latest = Promise.resolve(null)
// A failed check or download also comes as an 'error' event.
- const check = () => {
- latest = updater.checkForUpdates().then(result => (result?.isUpdateAvailable && result.downloadPromise
- ? { version: result.updateInfo.version, downloaded: result.downloadPromise.then(() => true, () => false) }
- : null), () => null)
+ // The events normally move the phase; a check that settles without one must not leave it
+ // on `checking`, or the busy guard would also stop the timer's checks.
+ const settled = (next) => { if (holder.state().phase === 'checking') holder.set(next) }
+ const run = () => {
+ latest = updater.checkForUpdates().then((result) => {
+ if (result?.isUpdateAvailable && result.downloadPromise) {
+ settled({ phase: 'downloading', version: result.updateInfo.version })
+ return { version: result.updateInfo.version, downloaded: result.downloadPromise.then(() => true, () => false) }
+ }
+ settled({ phase: 'current' })
+ return null
+ }, () => { settled({ phase: 'failed' }); return null })
}
- check()
+ const check = () => { if (!UPDATE_BUSY.has(holder.state().phase)) run() }
+ run()
const timer = setInterval(check, CHECK_EVERY_MS)
- return { stop: () => { clearInterval(timer) }, latest: () => latest, install }
+ return { stop: () => { clearInterval(timer) }, latest: () => latest, install, state: holder.state, subscribe: holder.subscribe, check }
}
diff --git a/app/test/updates.test.mjs b/app/test/updates.test.mjs
index 637ed761..081a2982 100644
--- a/app/test/updates.test.mjs
+++ b/app/test/updates.test.mjs
@@ -12,14 +12,20 @@ class FakeUpdater extends EventEmitter {
installs = []
failCheck = false
found = null
+ // `wait` leaves the check pending, the way a slow answer from the feed would.
+ wait = false
checkForUpdates() {
this.checks += 1
+ this.emit('checking-for-update')
if (this.failCheck) {
const error = new Error('offline')
this.emit('error', error)
return Promise.reject(error)
}
- return Promise.resolve(this.found?.() ?? { isUpdateAvailable: false, updateInfo: { version: '0.1.7' } })
+ if (this.wait) return new Promise(() => {})
+ const result = this.found?.() ?? { isUpdateAvailable: false, updateInfo: { version: '0.1.7' } }
+ this.emit(result.isUpdateAvailable ? 'update-available' : 'update-not-available', result.updateInfo)
+ return Promise.resolve(result)
}
setFeedURL(options) { this.feeds.push(options) }
quitAndInstall(...args) { this.installs.push(args) }
@@ -306,6 +312,82 @@ describe('watchReleases', () => {
t.mock.timers.tick(4 * 60 * 60_000)
assert.equal(checks, 1)
})
+
+ test('reports checking, then current when nothing is newer or available when one is', async (t) => {
+ const none = watchReleases({
+ current: '0.1.7', arch: 'arm64', fetch: async () => releaseResponse([release('0.1.7')]), log: quietLog(),
+ })
+ t.after(none.stop)
+ assert.deepEqual(none.state(), { phase: 'checking' })
+ assert.equal(await none.latest(), null)
+ assert.deepEqual(none.state(), { phase: 'current' })
+
+ const page = 'https://github.com/Fei2411/DeepSeek-Bot/releases/tag/v0.1.9'
+ const found = watchReleases({
+ current: '0.1.7', arch: 'arm64', fetch: async () => releaseResponse([release('0.1.9', { page })]), log: quietLog(),
+ })
+ t.after(found.stop)
+ assert.deepEqual(await found.latest(), { version: '0.1.9', page })
+ assert.deepEqual(found.state(), { phase: 'available', version: '0.1.9', page })
+ })
+
+ test('a failed check reports failed: HTTP error, bad JSON, non-array, thrown', async (t) => {
+ const cases = [
+ async () => releaseResponse({}, 503),
+ async () => ({ ok: true, status: 200, json: async () => { throw new Error('bad JSON') } }),
+ async () => releaseResponse({ releases: [] }),
+ async () => { throw new Error('offline') },
+ ]
+ for (const fetch of cases) {
+ const updates = watchReleases({ current: '0.1.7', arch: 'arm64', fetch, log: quietLog() })
+ t.after(updates.stop)
+ assert.equal(await updates.latest(), null)
+ assert.deepEqual(updates.state(), { phase: 'failed' })
+ }
+ })
+
+ test('check() runs the same check as the timer, but not while one is on', async (t) => {
+ let calls = 0
+ let gate
+ const updates = watchReleases({
+ current: '0.1.7', arch: 'arm64',
+ fetch: () => { calls += 1; return new Promise((resolve) => { gate = resolve }) },
+ log: quietLog(),
+ })
+ t.after(updates.stop)
+ assert.deepEqual(updates.state(), { phase: 'checking' })
+ updates.check()
+ assert.equal(calls, 1)
+ gate(releaseResponse([release('0.1.7')]))
+ await updates.latest()
+ assert.deepEqual(updates.state(), { phase: 'current' })
+ updates.check()
+ assert.equal(calls, 2)
+ assert.deepEqual(updates.state(), { phase: 'checking' })
+ gate(releaseResponse([release('0.1.7')]))
+ await updates.latest()
+ assert.deepEqual(updates.state(), { phase: 'current' })
+ })
+
+ test('listeners hear every state change until they unsubscribe', async (t) => {
+ const updates = watchReleases({
+ current: '0.1.7', arch: 'arm64', fetch: async () => releaseResponse([release('0.1.7')]), log: quietLog(),
+ })
+ t.after(updates.stop)
+ const seen = []
+ const off = updates.subscribe(state => seen.push(state.phase))
+ await updates.latest()
+ assert.deepEqual(seen, ['current'])
+ updates.check()
+ await updates.latest()
+ await sleep(0)
+ assert.deepEqual(seen, ['current', 'checking', 'current'])
+ off()
+ updates.check()
+ await updates.latest()
+ await sleep(0)
+ assert.deepEqual(seen, ['current', 'checking', 'current'])
+ })
})
describe('watchUpdates', () => {
@@ -417,4 +499,67 @@ describe('watchUpdates', () => {
t.mock.timers.tick(8 * 60 * 60_000)
assert.equal(updater.checks, 2)
})
+
+ test('follows the updater events: checking, current, downloading, downloaded', (t) => {
+ const updater = new FakeUpdater()
+ const updates = watchUpdates({ updater, beforeInstall: async () => {}, log: quietLog() })
+ t.after(updates.stop)
+ // The first check already answered: nothing newer.
+ assert.deepEqual(updates.state(), { phase: 'current' })
+ updater.emit('checking-for-update')
+ assert.deepEqual(updates.state(), { phase: 'checking' })
+ updater.emit('update-available', { version: '0.1.9' })
+ assert.deepEqual(updates.state(), { phase: 'downloading', version: '0.1.9' })
+ updater.emit('update-downloaded', { version: '0.1.9' })
+ assert.deepEqual(updates.state(), { phase: 'downloaded', version: '0.1.9' })
+ })
+
+ test('a failed check or download reports failed, unless an update is already downloaded', (t) => {
+ const updater = new FakeUpdater()
+ const updates = watchUpdates({ updater, beforeInstall: async () => {}, log: quietLog() })
+ t.after(updates.stop)
+ updater.emit('error', new Error('offline'))
+ assert.deepEqual(updates.state(), { phase: 'failed' })
+ updater.emit('update-available', { version: '0.1.9' })
+ updater.emit('error', new Error('sha512 checksum mismatch'))
+ assert.deepEqual(updates.state(), { phase: 'failed' })
+ updater.emit('update-downloaded', { version: '0.1.9' })
+ updater.emit('error', new Error('offline'))
+ assert.deepEqual(updates.state(), { phase: 'downloaded', version: '0.1.9' })
+ })
+
+ test('check() runs the timer\'s check, but not while checking, downloading or downloaded', (t) => {
+ const updater = new FakeUpdater()
+ updater.wait = true
+ const updates = watchUpdates({ updater, beforeInstall: async () => {}, log: quietLog() })
+ t.after(updates.stop)
+ // The first check is still on: the updater has not answered it yet.
+ assert.deepEqual(updates.state(), { phase: 'checking' })
+ updates.check()
+ assert.equal(updater.checks, 1)
+ updater.wait = false
+ updater.emit('update-not-available')
+ updates.check()
+ assert.equal(updater.checks, 2)
+ updater.emit('update-available', { version: '0.1.9' })
+ updates.check()
+ assert.equal(updater.checks, 2)
+ updater.emit('update-downloaded', { version: '0.1.9' })
+ updates.check()
+ assert.equal(updater.checks, 2)
+ })
+
+ test('listeners hear every state change until they unsubscribe', (t) => {
+ const updater = new FakeUpdater()
+ const updates = watchUpdates({ updater, beforeInstall: async () => {}, log: quietLog() })
+ t.after(updates.stop)
+ const seen = []
+ const off = updates.subscribe(state => seen.push(state.phase))
+ updater.emit('checking-for-update')
+ updater.emit('update-available', { version: '0.1.9' })
+ assert.deepEqual(seen, ['checking', 'downloading'])
+ off()
+ updater.emit('update-downloaded', { version: '0.1.9' })
+ assert.deepEqual(seen, ['checking', 'downloading'])
+ })
})
diff --git a/ds-bot/client.js b/ds-bot/client.js
index 0ff263c4..c5c22c9e 100644
--- a/ds-bot/client.js
+++ b/ds-bot/client.js
@@ -890,6 +890,11 @@ var ZH = {
"Checked {time}": "检查于 {time}",
"Could not check for updates.": "没能检查更新。",
"Update checks are off.": "已关闭更新检查。",
+ "Checking for updates…": "正在检查更新…",
+ "Downloading {version}…": "正在下载 {version}…",
+ "{version} is ready; it installs when you restart": "{version} 已下载好,重启后安装",
+ "Restart to update": "重启更新",
+ "{version} is available": "{version} 已发布",
"Installed from a local folder; update it there.": "从本地文件夹安装,请在那里更新。",
"Updates are not offered for this install.": "这种安装方式不提供更新。",
"Updates come with the DeepSeek Bot app.": "随 DeepSeek Bot 应用一起更新。",
@@ -14419,6 +14424,26 @@ function botHint(update) {
const checked = t("Checked {time}", { time: whenText(update.checkedAt) });
return `${update.latest ? t("Up to date") : t("Could not check for updates.")} · ${checked}`;
}
+function ownAppRow(ownApp) {
+ if (ownApp === null || typeof ownApp !== "object") return null;
+ const version = typeof ownApp.version === "string" ? ownApp.version : "";
+ switch (ownApp.phase) {
+ case "checking":
+ return { hint: t("Checking for updates…"), button: null };
+ case "current":
+ return { hint: t("Up to date"), button: "check" };
+ case "downloading":
+ return { hint: t("Downloading {version}…", { version }), button: null };
+ case "downloaded":
+ return { hint: t("{version} is ready; it installs when you restart", { version }), button: "restart" };
+ case "available":
+ return { hint: t("{version} is available", { version }), button: "open" };
+ case "failed":
+ return { hint: t("Could not check for updates."), button: "check" };
+ default:
+ return null;
+ }
+}
function dshHint(dsh, shown) {
if (dsh.phase === "installing") return t("Updating DSH…");
if (dsh.phase === "installed") return t("Restart DSH to start using DSH {version}.", { version: dsh.installed ?? dsh.verified });
@@ -14464,7 +14489,9 @@ function AboutPage({ useUpdate, actions, run: run2, Section, Row: Row3 }) {
const markState = checking ? "searching" : phase === "installing" || dshPhase === "installing" ? "working" : cheer ? "done" : "idle";
const dshNew = showsDshRow(dsh, update.app);
const dshShown = dshNew && dsh.available;
- const botControl = phase === "installed" || phase === "updated" || update.source === "app" ? null : update.available || phase === "installing" ? (0, import_react34.createElement)(
+ const ownRow = update.source === "app" ? ownAppRow(update.ownApp) : null;
+ const ownControl = ownRow?.button === "restart" ? (0, import_react34.createElement)("button", { type: "button", className: "bt-fb-primary", onClick: () => run2(actions.installOwnApp()) }, t("Restart to update")) : ownRow?.button === "check" ? (0, import_react34.createElement)("button", { type: "button", className: "bt-soft bt-soft-sm", onClick: () => run2(actions.checkOwnApp()) }, t("Check for updates")) : ownRow?.button === "open" ? (0, import_react34.createElement)("button", { type: "button", className: "bt-soft bt-soft-sm", onClick: () => run2(actions.openOwnApp()) }, t("Download")) : null;
+ const botControl = ownRow !== null ? ownControl : phase === "installed" || phase === "updated" || update.source === "app" ? null : update.available || phase === "installing" ? (0, import_react34.createElement)(
"button",
{ type: "button", className: "bt-fb-primary", disabled: phase === "installing", onClick: () => run2(actions.installUpdate()) },
phase === "installing" ? t("Updating…") : phase === "failed" ? t("Try again") : t("Update")
@@ -14504,7 +14531,7 @@ function AboutPage({ useUpdate, actions, run: run2, Section, Row: Row3 }) {
(0, import_react34.createElement)(
Section,
{ key: "updates", title: t("Updates") },
- (0, import_react34.createElement)(Row3, { label: "DS Bot", hint: botHint(update) }, botControl, update.available && update.notesUrl ? (0, import_react34.createElement)("a", linkProps(update.notesUrl), t("What's new")) : null),
+ (0, import_react34.createElement)(Row3, { label: "DS Bot", hint: ownRow?.hint ?? botHint(update) }, botControl, update.available && update.notesUrl ? (0, import_react34.createElement)("a", linkProps(update.notesUrl), t("What's new")) : null),
dsh?.current ? (0, import_react34.createElement)(Row3, { label: "DeepSeek Harness", hint: dshHint(dsh, dshShown) }, dshControl) : null
),
(0, import_react34.createElement)(
@@ -18076,7 +18103,7 @@ function apply(ctx) {
if (stopped) return;
const value = await call("update-check", { fresh: false }).catch(() => null);
if (stopped) return;
- if (value) update.set((previous) => ({ ...value, app: previous.app }));
+ if (value) update.set((previous) => ({ ...value, app: previous.app, ownApp: previous.ownApp }));
timer = setTimeout(loop, value?.phase === "installing" || value?.dsh?.phase === "installing" ? 2e3 : 60 * 6e4);
};
wakeUpdate = loop;
@@ -18104,6 +18131,22 @@ function apply(ctx) {
};
}, "ds-bot: app update status");
}
+ const ownAppUpdates = globalThis.dsBotApp?.updates ?? null;
+ if (ownAppUpdates?.state && ownAppUpdates.subscribe) {
+ ctx.effect(() => {
+ let stopped = false;
+ const take = (ownApp) => {
+ if (!stopped && ownApp) update.set((previous) => ({ ...previous, ownApp }));
+ };
+ void ownAppUpdates.state().then(take, () => {
+ });
+ const unsubscribe = ownAppUpdates.subscribe(take);
+ return () => {
+ stopped = true;
+ unsubscribe?.();
+ };
+ }, "ds-bot: own app update state");
+ }
const bridge = (window.dshDesktop?.protocolVersion === 1 ? window.dshDesktop.browser : globalThis.dsBotApp?.browser) ?? null;
const browsers = bridge ? createBotBrowsers({ bridge, createSource }) : null;
if (browsers) {
@@ -18453,9 +18496,18 @@ function apply(ctx) {
};
actions.checkUpdate = async () => {
const value = await call("update-check", { fresh: true });
- update.set((previous) => ({ ...value, app: previous.app }));
+ update.set((previous) => ({ ...value, app: previous.app, ownApp: previous.ownApp }));
wakeUpdate();
};
+ actions.checkOwnApp = async () => {
+ await ownAppUpdates?.check?.();
+ };
+ actions.installOwnApp = async () => {
+ await ownAppUpdates?.install?.();
+ };
+ actions.openOwnApp = async () => {
+ await ownAppUpdates?.open?.();
+ };
const browserPages = browsers?.pages ?? createSource({});
const browserTabs = browsers?.tabs ?? createSource({});
const face = () => ({ actions, hooks: { roster, ui: ui2, activity, work, memoryNews, registry, turnClock, live, cards, heldCards, browserPages, browserTabs, surface, update } });
diff --git a/ds-bot/src/client/about.js b/ds-bot/src/client/about.js
index 232a25d7..6dc05e26 100644
--- a/ds-bot/src/client/about.js
+++ b/ds-bot/src/client/about.js
@@ -30,6 +30,23 @@ function botHint(update) {
return `${update.latest ? t('Up to date') : t('Could not check for updates.')} · ${checked}`
}
+// The DS Bot row in the desktop app shows the app's own update state, kept as ownApp on
+// the update value. Anything that is not a state object (DSH Desktop, DSH Web, an
+// unpackaged app) leaves the row with today's "comes with the app" text.
+export function ownAppRow(ownApp) {
+ if (ownApp === null || typeof ownApp !== 'object') return null
+ const version = typeof ownApp.version === 'string' ? ownApp.version : ''
+ switch (ownApp.phase) {
+ case 'checking': return { hint: t('Checking for updates…'), button: null }
+ case 'current': return { hint: t('Up to date'), button: 'check' }
+ case 'downloading': return { hint: t('Downloading {version}…', { version }), button: null }
+ case 'downloaded': return { hint: t('{version} is ready; it installs when you restart', { version }), button: 'restart' }
+ case 'available': return { hint: t('{version} is available', { version }), button: 'open' }
+ case 'failed': return { hint: t('Could not check for updates.'), button: 'check' }
+ default: return null
+ }
+}
+
function dshHint(dsh, shown) {
if (dsh.phase === 'installing') return t('Updating DSH…')
if (dsh.phase === 'installed') return t('Restart DSH to start using DSH {version}.', { version: dsh.installed ?? dsh.verified })
@@ -69,7 +86,16 @@ export function AboutPage({ useUpdate, actions, run, Section, Row }) {
// Same rule as the sidebar card.
const dshNew = showsDshRow(dsh, update.app)
const dshShown = dshNew && dsh.available
- const botControl = phase === 'installed' || phase === 'updated' || update.source === 'app' ? null
+ const ownRow = update.source === 'app' ? ownAppRow(update.ownApp) : null
+ const ownControl = ownRow?.button === 'restart'
+ ? h('button', { type: 'button', className: 'bt-fb-primary', onClick: () => run(actions.installOwnApp()) }, t('Restart to update'))
+ : ownRow?.button === 'check'
+ ? h('button', { type: 'button', className: 'bt-soft bt-soft-sm', onClick: () => run(actions.checkOwnApp()) }, t('Check for updates'))
+ : ownRow?.button === 'open'
+ ? h('button', { type: 'button', className: 'bt-soft bt-soft-sm', onClick: () => run(actions.openOwnApp()) }, t('Download'))
+ : null
+ const botControl = ownRow !== null ? ownControl
+ : phase === 'installed' || phase === 'updated' || update.source === 'app' ? null
: update.available || phase === 'installing'
? h('button', { type: 'button', className: 'bt-fb-primary', disabled: phase === 'installing', onClick: () => run(actions.installUpdate()) },
phase === 'installing' ? t('Updating…') : phase === 'failed' ? t('Try again') : t('Update'))
@@ -96,7 +122,7 @@ export function AboutPage({ useUpdate, actions, run, Section, Row }) {
stars === null ? null : h('span', { className: 'bt-star-count' }, starCount(stars))) : null),
repo ? h('p', { key: 'ask', className: 'bt-about-ask' }, t('If DS Bot helps you, a star on GitHub helps more people find it.')) : null,
h(Section, { key: 'updates', title: t('Updates') },
- h(Row, { label: 'DS Bot', hint: botHint(update) }, botControl, update.available && update.notesUrl ? h('a', linkProps(update.notesUrl), t("What's new")) : null),
+ h(Row, { label: 'DS Bot', hint: ownRow?.hint ?? botHint(update) }, botControl, update.available && update.notesUrl ? h('a', linkProps(update.notesUrl), t("What's new")) : null),
dsh?.current ? h(Row, { label: 'DeepSeek Harness', hint: dshHint(dsh, dshShown) }, dshControl) : null),
h(Section, { key: 'links', title: t('Links') },
repo ? h(Row, { label: t('Source code'), hint: repo.replace(/^https:\/\//, '') }, h('a', linkProps(repo), h(GitHubMark), t('Open'))) : null,
diff --git a/ds-bot/src/client/i18n.js b/ds-bot/src/client/i18n.js
index a95055a0..5b1ab651 100644
--- a/ds-bot/src/client/i18n.js
+++ b/ds-bot/src/client/i18n.js
@@ -842,6 +842,11 @@ const ZH = {
'Checked {time}': '检查于 {time}',
'Could not check for updates.': '没能检查更新。',
'Update checks are off.': '已关闭更新检查。',
+ 'Checking for updates…': '正在检查更新…',
+ 'Downloading {version}…': '正在下载 {version}…',
+ '{version} is ready; it installs when you restart': '{version} 已下载好,重启后安装',
+ 'Restart to update': '重启更新',
+ '{version} is available': '{version} 已发布',
'Installed from a local folder; update it there.': '从本地文件夹安装,请在那里更新。',
'Updates are not offered for this install.': '这种安装方式不提供更新。',
'Updates come with the DeepSeek Bot app.': '随 DeepSeek Bot 应用一起更新。',
diff --git a/ds-bot/src/client/index.js b/ds-bot/src/client/index.js
index 648b253f..17c9db72 100644
--- a/ds-bot/src/client/index.js
+++ b/ds-bot/src/client/index.js
@@ -208,7 +208,7 @@ export function apply(ctx) {
if (stopped) return
const value = await call('update-check', { fresh: false }).catch(() => null)
if (stopped) return
- if (value) update.set(previous => ({ ...value, app: previous.app }))
+ if (value) update.set(previous => ({ ...value, app: previous.app, ownApp: previous.ownApp }))
timer = setTimeout(loop, value?.phase === 'installing' || value?.dsh?.phase === 'installing' ? 2000 : 60 * 60_000)
}
wakeUpdate = loop
@@ -229,6 +229,19 @@ export function apply(ctx) {
}, 'ds-bot: app update status')
}
+ // The DeepSeek Bot app's own updater; its state goes beside the host's answer as ownApp,
+ // which the About row turns into the app's update state and buttons.
+ const ownAppUpdates = globalThis.dsBotApp?.updates ?? null
+ if (ownAppUpdates?.state && ownAppUpdates.subscribe) {
+ ctx.effect(() => {
+ let stopped = false
+ const take = (ownApp) => { if (!stopped && ownApp) update.set(previous => ({ ...previous, ownApp })) }
+ void ownAppUpdates.state().then(take, () => {})
+ const unsubscribe = ownAppUpdates.subscribe(take)
+ return () => { stopped = true; unsubscribe?.() }
+ }, 'ds-bot: own app update state')
+ }
+
// Bot browsers need a webview bridge: DSH Desktop's, or the desktop app's of the
// same shape. The host serves read_browser only in those two (`browser` in the state).
const bridge = (window.dshDesktop?.protocolVersion === 1 ? window.dshDesktop.browser : globalThis.dsBotApp?.browser) ?? null
@@ -575,9 +588,14 @@ export function apply(ctx) {
}
actions.checkUpdate = async () => {
const value = await call('update-check', { fresh: true })
- update.set(previous => ({ ...value, app: previous.app }))
+ update.set(previous => ({ ...value, app: previous.app, ownApp: previous.ownApp }))
wakeUpdate()
}
+ // The app's own updater answers through its bridge; the state it pushes back re-renders
+ // the About row.
+ actions.checkOwnApp = async () => { await ownAppUpdates?.check?.() }
+ actions.installOwnApp = async () => { await ownAppUpdates?.install?.() }
+ actions.openOwnApp = async () => { await ownAppUpdates?.open?.() }
const browserPages = browsers?.pages ?? createSource({})
const browserTabs = browsers?.tabs ?? createSource({})
const face = () => ({ actions, hooks: { roster, ui, activity, work, memoryNews, registry, turnClock, live, cards, heldCards, browserPages, browserTabs, surface, update } })
diff --git a/ds-bot/test/about.test.js b/ds-bot/test/about.test.js
new file mode 100644
index 00000000..1f499f77
--- /dev/null
+++ b/ds-bot/test/about.test.js
@@ -0,0 +1,101 @@
+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/about.js', import.meta.url))],
+ bundle: true, format: 'cjs', platform: 'node', write: false,
+ external: ['react', 'react-dom', '@deepseek-ai/dsh-client-ui-primitives'],
+})
+const react = {
+ createElement: (type, props, ...children) => ({ type, props: props ?? {}, children: children.flat(Infinity) }),
+ Fragment: 'fragment',
+ useState: initial => [initial, () => {}],
+ useEffect: () => {},
+ useRef: current => ({ current }),
+ useLayoutEffect: () => {},
+}
+const module = { exports: {} }
+runInNewContext(bundle.outputFiles[0].text, {
+ module, exports: module.exports, URL, URLSearchParams, setTimeout, clearTimeout,
+ require: (name) => {
+ if (name === 'react') return react
+ return {}
+ },
+})
+const { AboutPage, ownAppRow } = module.exports
+
+// The DS Bot row in Settings → About, with the row's hint and its buttons' text, class
+// and clicks. `update` is the value the update source holds.
+function page(update) {
+ const calls = []
+ const actions = new Proxy({ repoStars: async () => null }, {
+ get: (target, name) => target[name] ?? (() => calls.push(name)),
+ })
+ const run = promise => promise
+ const tree = AboutPage({ useUpdate: select => select(update), actions, run, Section: 'section', Row: 'row' })
+ const find = (node, pick) => (Array.isArray(node) ? node.flatMap(one => find(one, pick))
+ : node && typeof node === 'object' ? [...pick(node), ...find(node.children, pick)] : [])
+ const [row] = find(tree, node => (node.props?.label === 'DS Bot' ? [node] : []))
+ const buttons = find(row?.children ?? [], node => (node.type === 'button' ? [node] : []))
+ return {
+ hint: row?.props?.hint,
+ buttons: buttons.map(node => ({ text: node.children[0], className: node.props.className, click: () => node.props.onClick() })),
+ calls,
+ }
+}
+
+// 公开#499: in the desktop app the DS Bot row shows the app's own update state.
+test('the six app update states set the DS Bot row\'s hint and button', () => {
+ const cases = [
+ [{ phase: 'checking' }, 'Checking for updates…', []],
+ [{ phase: 'current' }, 'Up to date', [{ text: 'Check for updates', className: 'bt-soft bt-soft-sm', action: 'checkOwnApp' }]],
+ [{ phase: 'downloading', version: '0.2.2' }, 'Downloading 0.2.2…', []],
+ [{ phase: 'downloaded', version: '0.2.2' }, '0.2.2 is ready; it installs when you restart',
+ [{ text: 'Restart to update', className: 'bt-fb-primary', action: 'installOwnApp' }]],
+ [{ phase: 'available', version: '0.2.2', page: 'https://github.com/Fei2411/DeepSeek-Bot/releases/tag/v0.2.2' }, '0.2.2 is available',
+ [{ text: 'Download', className: 'bt-soft bt-soft-sm', action: 'openOwnApp' }]],
+ [{ phase: 'failed' }, 'Could not check for updates.', [{ text: 'Check for updates', className: 'bt-soft bt-soft-sm', action: 'checkOwnApp' }]],
+ ]
+ for (const [ownApp, hint, buttons] of cases) {
+ const view = page({ source: 'app', ownApp })
+ assert.equal(view.hint, hint)
+ assert.equal(view.buttons.length, buttons.length)
+ for (const [index, expected] of buttons.entries()) {
+ assert.equal(view.buttons[index].text, expected.text)
+ assert.equal(view.buttons[index].className, expected.className)
+ view.buttons[index].click()
+ assert.deepEqual(view.calls, [expected.action])
+ view.calls.length = 0
+ }
+ }
+})
+
+test('without an app update state the row keeps today\'s text and no button', () => {
+ for (const ownApp of [undefined, null, 'checking', {}]) {
+ const view = page({ source: 'app', ownApp })
+ assert.equal(view.hint, 'Updates come with the DeepSeek Bot app.')
+ assert.deepEqual(view.buttons, [])
+ }
+})
+
+test('an app update state is ignored outside the app', () => {
+ const view = page({ source: 'registry', checkedAt: Date.now(), latest: '0.2.1', ownApp: { phase: 'downloaded', version: '0.2.2' } })
+ assert.match(view.hint, /^Up to date · Checked /)
+ assert.equal(view.buttons.length, 1)
+ assert.equal(view.buttons[0].text, 'Check for updates')
+})
+
+test('ownAppRow maps each phase to its hint and button kind', () => {
+ assert.equal(ownAppRow(null), null)
+ assert.equal(ownAppRow('downloaded'), null)
+ // The bundled module's realm has its own Object, so compare the fields.
+ const checking = ownAppRow({ phase: 'checking' })
+ assert.equal(checking.hint, 'Checking for updates…')
+ assert.equal(checking.button, null)
+ const downloaded = ownAppRow({ phase: 'downloaded', version: '0.2.2' })
+ assert.equal(downloaded.hint, '0.2.2 is ready; it installs when you restart')
+ assert.equal(downloaded.button, 'restart')
+})