A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Ask for a missing API key in the app's first model choice
Fei24112fc536aa0a16
diff --git a/app/README.md b/app/README.mdindex 62aa2e34..1ad18087 100644--- a/app/README.md+++ b/app/README.md@@ -19,7 +19,7 @@ npm installs `ds-bot` from `../ds-bot` as a copy of its package files (`install-| `DS_BOT_HOME` | The data location: the `DSH_HOME` of the app | `~/.ds-bot` || `DS_BOT_SHELL_DATA` | The app's own data (window, Chromium storage) | Electron's `userData` (Windows: `%APPDATA%\DeepSeek Bot`) |-The Host reads model settings and keys the way DSH does: environment variables such as `DEEPSEEK_API_KEY`, and `.env` and `.credentials.yaml` in the data location.+The Host reads model settings and keys the way DSH does: environment variables such as `DEEPSEEK_API_KEY`, and `.env` and `.credentials.yaml` in the data location. When no model has its API key, the first Main Bot asks for one in its chat and saves it to `.credentials.yaml`.## The profilediff --git a/app/ui/src/team.js b/app/ui/src/team.jsindex 34938396..0d71a7c9 100644--- a/app/ui/src/team.js+++ b/app/ui/src/team.js@@ -170,6 +170,8 @@ export function createTeam() {},// The window has no DSH status bar, so the Bot's details show its figures.runStats: botId => call('run-stats', { botId }),+ // Nor DSH's settings, so a first model choice takes a missing API key itself.+ saveModelKey: (provider, value) => after(call('model-key', { provider, value })),// Nothing else draws in the window: no shell panels, right sidebar, "@" menu or voice plugin.hasRightSidebar: () => false,canReferenceChat: () => false,diff --git a/docs/plans/2026-10-16-desktop-app.md b/docs/plans/2026-10-16-desktop-app.mdindex e9856dc2..eaf26eae 100644--- a/docs/plans/2026-10-16-desktop-app.md+++ b/docs/plans/2026-10-16-desktop-app.md@@ -81,7 +81,7 @@## 已知限制-- 窗口里还没有:群聊的历史消息、工具卡片和审批、首次启动和导入、DeepSeek 账号登录、每个 Bot 的浏览器、更新。侧栏每一行的最新一句只显示打开窗口以后的新消息。插件版里打开 DSH 自己界面的入口(连接插件、管理模型、Harness 设置,「+」里的添加文件和引用对话)窗口里也没有。模型和密钥目前用环境变量,或数据位置里的 `.env`、`.credentials.yaml` 设置。+- 窗口里还没有:群聊的历史消息、工具卡片和审批、首次启动和导入、DeepSeek 账号登录、每个 Bot 的浏览器、更新。侧栏每一行的最新一句只显示打开窗口以后的新消息。插件版里打开 DSH 自己界面的入口(连接插件、管理模型、Harness 设置,「+」里的添加文件和引用对话)窗口里也没有。模型和密钥目前用环境变量,或数据位置里的 `.env`、`.credentials.yaml` 设置;没有一个模型有 API key 时,第一个主 Bot 在对话里请用户填,存进 `.credentials.yaml`。- 不签名:Windows 第一次运行会弹出 SmartScreen 警告,macOS 要在系统设置里手动放行。- 会话里记着工作文件夹的完整路径,不能改。所以导入和搬工作文件夹都要换段。- 安装的 `@deepseek-ai/dsh` 包带着 DSH 的网页前端、Office 套件和语音包,所以安装包里仍有这些文件,只是不加载。diff --git a/ds-bot/client.js b/ds-bot/client.jsindex 1399b40c..2d5c8f26 100644--- a/ds-bot/client.js+++ b/ds-bot/client.js@@ -151,6 +151,12 @@ var ZH = {"{model} is not available anymore. Pick another model for me.": "{model} 已经不可用了。给我换一个模型吧。","Hi, I'm {name}. I don't have a model yet. How do you want to set one up?": "你好,我是 {name}。我还没有可用的模型。你想怎么配置?","Hi, I'm {name}. Pick a model for me first. You can change it later in my details.": "你好,我是 {name}。先给我选一个模型吧,以后可以在我的详情里换。",+ "Hi, I'm {name}. I need a {provider} API key before I can start.": "你好,我是 {name}。开始之前,我需要一个 {provider} API key。",+ "{provider} API key": "{provider} API key",+ "Enter the API key": "请填入 API key",+ "Paste only the key, not a NAME=value line": "只粘贴 key 本身,不要带「名字=」",+ "Paste the key without quotes": "粘贴时不要带引号",+ "An API key has no spaces or special characters": "API key 里不能有空格或特殊字符","Mode": "模式","Sign in to DeepSeek": "登录 DeepSeek 账号","Enter a DeepSeek API key": "填入 DeepSeek API key",@@ -911,6 +917,8 @@ var ZH = {};var HOST_ERRORS = [[/^Model (.+) is not available\. Available: (.*)$/, "模型 $1 不可用。可用的:$2"],+ [/^The API key for (.+) is set outside DS Bot and cannot be changed here$/, "$1 的 API key 是在 DS Bot 之外设置的,这里改不了"],+ [/^(.+) takes no API key here$/, "$1 不能在这里填 API key"],[/^A Bot named (.+) already exists$/, "已经有叫 $1 的 Bot 了"],[/^Name (.*) is not available$/, "名字 $1 不可用"],[/^"(.+)" calls everyone in a group, so it cannot be a Bot name$/, "「$1」在群里表示所有人,不能用作 Bot 名字"],@@ -7020,8 +7028,10 @@ function ModelChoiceDock({ sessionId, useRoster, actions }) {}, [shown, sessionId]);if (!bot || currentPart(bot) !== sessionId || !roster.ready) return null;const models = roster.models ?? [];+ const usable = models.filter((model) => !model.needsKey);const lost = bot.model ? !models.some((model) => model.ref === bot.model) : false;if (bot.model && (!lost || models.length === 0)) return null;+ const keyFor = usable.length === 0 && actions.saveModelKey ? models.find((model) => model.needsKey) : void 0;const pick2 = (ref) => {setBusy(ref);setError("");@@ -7030,9 +7040,9 @@ function ModelChoiceDock({ sessionId, useRoster, actions }) {void actions.refreshModels?.();}).finally(() => setBusy(""));};- const text = lost ? t("{model} is not available anymore. Pick another model for me.", { model: bot.model.split("/").slice(1).join("/") }) : models.length === 0 ? t("Hi, I'm {name}. I don't have a model yet. How do you want to set one up?", { name: bot.name }) : t("Hi, I'm {name}. Pick a model for me first. You can change it later in my details.", { name: bot.name });- const choices = models.length === 0 ? setupChoices(actions).map(([label, run]) => (0, import_react14.createElement)("button", { key: label, type: "button", className: "bt-model-chip", onClick: run }, label)) : [- ...groupModels(models).map(([provider, list]) => (0, import_react14.createElement)(+ const text = lost ? t("{model} is not available anymore. Pick another model for me.", { model: bot.model.split("/").slice(1).join("/") }) : keyFor ? t("Hi, I'm {name}. I need a {provider} API key before I can start.", { name: bot.name, provider: keyFor.providerName ?? keyFor.provider }) : usable.length === 0 ? t("Hi, I'm {name}. I don't have a model yet. How do you want to set one up?", { name: bot.name }) : t("Hi, I'm {name}. Pick a model for me first. You can change it later in my details.", { name: bot.name });+ const choices = usable.length === 0 ? setupChoices(actions).map(([label, run]) => (0, import_react14.createElement)("button", { key: label, type: "button", className: "bt-model-chip", onClick: run }, label)) : [+ ...groupModels(usable).map(([provider, list]) => (0, import_react14.createElement)("div",{ key: list[0].provider ?? provider, className: "bt-model-choice-group", role: "group", "aria-label": provider },(0, import_react14.createElement)("div", { className: "bt-model-choice-provider", "aria-hidden": true }, provider),@@ -7066,10 +7076,35 @@ function ModelChoiceDock({ sessionId, useRoster, actions }) {))),- (0, import_react14.createElement)("div", { className: "bt-model-chips", role: "group", "aria-label": t("Choose a model") }, choices),+ keyFor ? (0, import_react14.createElement)(ModelKeyCard, { key: keyFor.provider, model: keyFor, actions }) : (0, import_react14.createElement)("div", { className: "bt-model-chips", role: "group", "aria-label": t("Choose a model") }, choices),error ? (0, import_react14.createElement)("div", { className: "bt-secret-error bt-model-error", role: "alert" }, error) : null);}+function ModelKeyCard({ model, actions }) {+ const [value, setValue] = (0, import_react14.useState)("");+ const [busy, setBusy] = (0, import_react14.useState)(false);+ const [error, setError] = (0, import_react14.useState)("");+ const label = t("{provider} API key", { provider: model.providerName ?? model.provider });+ const ready = value.trim() !== "" && !busy;+ const save = () => {+ if (!ready) return;+ setBusy(true);+ setError("");+ void Promise.resolve(actions.saveModelKey(model.provider, value)).then(() => setValue(""), (failure) => setError(hostText(failure?.message ?? String(failure)))).finally(() => setBusy(false));+ };+ return (0, import_react14.createElement)(+ "div",+ { className: "bt-q bt-model-key", role: "group", "aria-label": label },+ (0, import_react14.createElement)("div", { className: "bt-model-key-title" }, (0, import_react14.createElement)(KeyIcon), label),+ (0, import_react14.createElement)("label", { className: "bt-q-field bt-secret-field" }, (0, import_react14.createElement)(MaskedInput, { value, onChange: setValue, onEnter: save, label, autoFocus: true })),+ error ? (0, import_react14.createElement)("div", { className: "bt-secret-error", role: "alert" }, error) : null,+ (0, import_react14.createElement)(+ "div",+ { className: "bt-q-foot" },+ (0, import_react14.createElement)("button", { type: "button", className: "bt-q-submit", disabled: !ready, onClick: save }, busy ? t("Saving…") : t("Save"))+ )+ );+}function setupChoices(actions) {return [actions.canSignIn?.() ? [t("Sign in to DeepSeek"), () => actions.signIn()] : null,@@ -7130,6 +7165,10 @@ var MODEL_CSS = `.bt-model-chip:disabled{cursor:default}.bt-model-chip:disabled:not([aria-busy]){opacity:.5}.bt-model-error{margin-left:30px}+.bt-q.bt-model-key{margin:0 0 0 30px;width:min(480px,calc(100% - 30px));gap:10px}+.bt-model-key-title{display:flex;align-items:center;gap:6px;font-size:13px;line-height:18px;font-weight:500;color:var(--bt-ink-2)}+.bt-model-key-title svg{flex:none;width:16px;height:16px}+.bt-model-key .bt-q-foot{margin-top:2px}@keyframes bt-model-in{from{opacity:0;transform:translateY(6px)}}.bt-model-spin{flex:none;width:14px;height:14px;border-radius:50%;border:1.5px solid var(--bt-line-2);border-top-color:var(--bt-ink-2);animation:bt-model-spin .7s linear infinite}@keyframes bt-model-spin{to{transform:rotate(360deg)}}diff --git a/ds-bot/src/client/i18n.js b/ds-bot/src/client/i18n.jsindex 2cfa3f8c..eb80a5b8 100644--- a/ds-bot/src/client/i18n.js+++ b/ds-bot/src/client/i18n.js@@ -115,6 +115,12 @@ const ZH = {'{model} is not available anymore. Pick another model for me.': '{model} 已经不可用了。给我换一个模型吧。',"Hi, I'm {name}. I don't have a model yet. How do you want to set one up?": '你好,我是 {name}。我还没有可用的模型。你想怎么配置?',"Hi, I'm {name}. Pick a model for me first. You can change it later in my details.": '你好,我是 {name}。先给我选一个模型吧,以后可以在我的详情里换。',+ "Hi, I'm {name}. I need a {provider} API key before I can start.": '你好,我是 {name}。开始之前,我需要一个 {provider} API key。',+ '{provider} API key': '{provider} API key',+ 'Enter the API key': '请填入 API key',+ 'Paste only the key, not a NAME=value line': '只粘贴 key 本身,不要带「名字=」',+ 'Paste the key without quotes': '粘贴时不要带引号',+ 'An API key has no spaces or special characters': 'API key 里不能有空格或特殊字符','Mode': '模式','Sign in to DeepSeek': '登录 DeepSeek 账号','Enter a DeepSeek API key': '填入 DeepSeek API key',@@ -864,6 +870,8 @@ const ZH = {// interface shows them. Static ones go through ZH, these carry names or numbers.const HOST_ERRORS = [[/^Model (.+) is not available\. Available: (.*)$/, '模型 $1 不可用。可用的:$2'],+ [/^The API key for (.+) is set outside DS Bot and cannot be changed here$/, '$1 的 API key 是在 DS Bot 之外设置的,这里改不了'],+ [/^(.+) takes no API key here$/, '$1 不能在这里填 API key'],[/^A Bot named (.+) already exists$/, '已经有叫 $1 的 Bot 了'],[/^Name (.*) is not available$/, '名字 $1 不可用'],[/^"(.+)" calls everyone in a group, so it cannot be a Bot name$/, '「$1」在群里表示所有人,不能用作 Bot 名字'],diff --git a/ds-bot/src/client/model-menu.js b/ds-bot/src/client/model-menu.jsindex 642b5324..888bf7f8 100644--- a/ds-bot/src/client/model-menu.js+++ b/ds-bot/src/client/model-menu.js@@ -3,8 +3,9 @@ import { createPortal } from 'react-dom'import { currentPart } from './text.js'import { CheckIcon, SlidersIcon } from './icons.js'import { BotMark } from './mark.js'+import { KeyIcon, MaskedInput } from './secret-card.js'import { SPRING_POP, SPRING_SHAPE, spring, useLinger } from './motion.js'-import { t } from './i18n.js'+import { hostText, t } from './i18n.js'const MENU_EXIT_MS = 120@@ -197,9 +198,13 @@ export function ModelChoiceDock({ sessionId, useRoster, actions }) {useEffect(() => { if (shown) void actions.refreshModels?.() }, [shown, sessionId])if (!bot || currentPart(bot) !== sessionId || !roster.ready) return nullconst models = roster.models ?? []+ // A model whose provider has no API key fails every turn, so it is no choice.+ const usable = models.filter(model => !model.needsKey)const lost = bot.model ? !models.some(model => model.ref === bot.model) : false// An unknown catalog (none listed) cannot tell a lost model from a slow provider.if (bot.model && (!lost || models.length === 0)) return null+ // A window without DSH's own settings takes the missing key here.+ const keyFor = usable.length === 0 && actions.saveModelKey ? models.find(model => model.needsKey) : undefinedconst pick = (ref) => {setBusy(ref)setError('')@@ -210,13 +215,15 @@ export function ModelChoiceDock({ sessionId, useRoster, actions }) {// The pick reads as the Bot's own first message, with the choices as replies under it.const text = lost? t('{model} is not available anymore. Pick another model for me.', { model: bot.model.split('/').slice(1).join('/') })- : models.length === 0- ? t("Hi, I'm {name}. I don't have a model yet. How do you want to set one up?", { name: bot.name })- : t("Hi, I'm {name}. Pick a model for me first. You can change it later in my details.", { name: bot.name })- const choices = models.length === 0+ : keyFor+ ? t("Hi, I'm {name}. I need a {provider} API key before I can start.", { name: bot.name, provider: keyFor.providerName ?? keyFor.provider })+ : usable.length === 0+ ? t("Hi, I'm {name}. I don't have a model yet. How do you want to set one up?", { name: bot.name })+ : t("Hi, I'm {name}. Pick a model for me first. You can change it later in my details.", { name: bot.name })+ const choices = usable.length === 0? setupChoices(actions).map(([label, run]) => h('button', { key: label, type: 'button', className: 'bt-model-chip', onClick: run }, label)): [- ...groupModels(models).map(([provider, list]) => h('div', { key: list[0].provider ?? provider, className: 'bt-model-choice-group', role: 'group', 'aria-label': provider },+ ...groupModels(usable).map(([provider, list]) => h('div', { key: list[0].provider ?? provider, className: 'bt-model-choice-group', role: 'group', 'aria-label': provider },h('div', { className: 'bt-model-choice-provider', 'aria-hidden': true }, provider),h('div', { className: 'bt-model-choice-chips' }, list.map(model => h('button', {key: model.ref, type: 'button', className: 'bt-model-chip', disabled: busy !== '', 'aria-busy': busy === model.ref || undefined,@@ -232,10 +239,36 @@ export function ModelChoiceDock({ sessionId, useRoster, actions }) {h('div', { className: 'bt-msg-line' },h(BotMark, { bot, size: 22 }),h('div', { className: 'bt-bubble' }, text)))),- h('div', { className: 'bt-model-chips', role: 'group', 'aria-label': t('Choose a model') }, choices),+ keyFor+ ? h(ModelKeyCard, { key: keyFor.provider, model: keyFor, actions })+ : h('div', { className: 'bt-model-chips', role: 'group', 'aria-label': t('Choose a model') }, choices),error ? h('div', { className: 'bt-secret-error bt-model-error', role: 'alert' }, error) : null)}+// The provider's API key, saved through the host; once it is set, the provider's+// models become the choices.+function ModelKeyCard({ model, actions }) {+ const [value, setValue] = useState('')+ const [busy, setBusy] = useState(false)+ const [error, setError] = useState('')+ const label = t('{provider} API key', { provider: model.providerName ?? model.provider })+ const ready = value.trim() !== '' && !busy+ const save = () => {+ if (!ready) return+ setBusy(true)+ setError('')+ void Promise.resolve(actions.saveModelKey(model.provider, value))+ .then(() => setValue(''), failure => setError(hostText(failure?.message ?? String(failure))))+ .finally(() => setBusy(false))+ }+ return h('div', { className: 'bt-q bt-model-key', role: 'group', 'aria-label': label },+ h('div', { className: 'bt-model-key-title' }, h(KeyIcon), label),+ h('label', { className: 'bt-q-field bt-secret-field' }, h(MaskedInput, { value, onChange: setValue, onEnter: save, label, autoFocus: true })),+ error ? h('div', { className: 'bt-secret-error', role: 'alert' }, error) : null,+ h('div', { className: 'bt-q-foot' },+ h('button', { type: 'button', className: 'bt-q-submit', disabled: !ready, onClick: save }, busy ? t('Saving…') : t('Save'))))+}+// Ways to get a first model. The DeepSeek sign-in exists only where the shell carries// its account plugin (the Desktop); the API key and custom models use the shell's// own editors.@@ -301,6 +334,10 @@ export const MODEL_CSS = `.bt-model-chip:disabled{cursor:default}.bt-model-chip:disabled:not([aria-busy]){opacity:.5}.bt-model-error{margin-left:30px}+.bt-q.bt-model-key{margin:0 0 0 30px;width:min(480px,calc(100% - 30px));gap:10px}+.bt-model-key-title{display:flex;align-items:center;gap:6px;font-size:13px;line-height:18px;font-weight:500;color:var(--bt-ink-2)}+.bt-model-key-title svg{flex:none;width:16px;height:16px}+.bt-model-key .bt-q-foot{margin-top:2px}@keyframes bt-model-in{from{opacity:0;transform:translateY(6px)}}.bt-model-spin{flex:none;width:14px;height:14px;border-radius:50%;border:1.5px solid var(--bt-line-2);border-top-color:var(--bt-ink-2);animation:bt-model-spin .7s linear infinite}@keyframes bt-model-spin{to{transform:rotate(360deg)}}diff --git a/ds-bot/test/model-menu.test.js b/ds-bot/test/model-menu.test.jsindex f8f4df59..444a8f2f 100644--- a/ds-bot/test/model-menu.test.js+++ b/ds-bot/test/model-menu.test.js@@ -109,3 +109,29 @@ test('the Thinking section always offers Default, so a picked level can be clearassert.deepEqual([...effortRows({ efforts }).map(row => row.effort)], [undefined, 'low', 'high'])assert.equal(effortRows({ efforts: [] }).length, 0)})++const keyless = [+ { ref: 'official/flash', provider: 'official', providerName: 'DeepSeek', name: 'DeepSeek Flash', needsKey: true },+ { ref: 'official/pro', provider: 'official', providerName: 'DeepSeek', name: 'DeepSeek Pro', needsKey: true },+]++test('models that need an API key are no choice', () => {+ const buttons = tree => nodes(tree, node => node.type === 'button').map(button => button.children[0])+ assert.deepEqual(buttons(dock([...keyless, models[1]], { harness: false }).tree), ['DeepSeek Flash'])+ // Where DSH's own settings are, they take the key.+ assert.deepEqual(buttons(dock(keyless).tree), ['Enter a DeepSeek API key', 'Open settings to set up a custom model'])+})++test('a window without DSH settings asks for the missing API key in the first choice', () => {+ const saved = []+ const bot = { id: 'chief', name: 'Chief' }+ const tree = ModelChoiceDock({+ sessionId: bot.id,+ useRoster: select => select({ ready: true, byId: { chief: bot }, models: keyless }),+ actions: { saveModelKey: (provider, value) => { saved.push([provider, value]) } },+ })+ assert.match(nodes(tree, node => node.props.className === 'bt-bubble')[0].children[0], /need a DeepSeek API key/)+ const [card] = nodes(tree, node => node.props.model !== undefined)+ assert.equal(card.props.model.provider, 'official')+ assert.equal(nodes(tree, node => node.props.className === 'bt-model-chips').length, 0)+})