🤖 Open-source, local-first alternative to Grok Bot, OpenAI dots and Claude Duet. Your own AI bots on any model: GPT, Claude, Gemini, Grok, DeepSeek, Kimi, GLM and 70+ more through one Modelflare key. Reach them in the app, WeChat or Feishu; they remember you, work in the background, run commands and use your computer. Pay per use.
Python ai-agentai-assistantchatbotclaudecomputer-usedeepseekdesktop-appdshelectronfeishugeminigptgrokllmlocal-firstmodelflaremulti-modelopenai-compatiblepersonal-ai-agentwechat
fix(ui): trim 谁能使用 and the Feishu connect area to what is needed
Marla2177f7ff69ec
diff --git a/docs/development.md b/docs/development.mdindex 41619c5..920bc11 100644--- a/docs/development.md+++ b/docs/development.md@@ -136,7 +136,7 @@ docker exec amb cat /data/ui-token # 打开 http://<主机>:3600/?token=<令代理跑在你自己的电脑上(甚至可能是完全权限),所以默认**只有主人和你允许的人**能和机器人对话,每个机器人、每个渠道分开算(`src/core/access.ts`):-- **主人**:微信是扫码登录的那个微信;飞书用 App ID / App Secret 连接、不扫码,连上之后**第一个给机器人发单聊消息的人**就是主人(先到先得)——连上后用你自己的飞书给机器人发一句话就完成绑定,这条消息照常回复。扫码时没拿到扫码者的微信也一样。机器人设置 → 谁能使用 里显示「飞书主人:…(第一个发消息的人)」,点「更换」(要确认)清掉主人,下一个发消息的人成为主人;换一个飞书应用或断开飞书时也会清掉。拒绝过的人不会成为主人。本机的网页对话不受限制。+- **主人**:微信是扫码登录的那个微信;飞书用 App ID / App Secret 连接、不扫码,连上之后**第一个给机器人发单聊消息的人**就是主人(先到先得)——连上后用你自己的飞书给机器人发一句话就完成绑定,这条消息照常回复。扫码时没拿到扫码者的微信也一样。机器人设置 → 谁能使用 里显示飞书主人,点「更换」(要确认)清掉主人,下一个发消息的人成为主人;换一个飞书应用或断开飞书时也会清掉。拒绝过的人不会成为主人。本机的网页对话不受限制。- **其他人**发消息:只收到一句「你还没有被允许使用这个机器人,已通知主人」(同一个人每小时最多一次),不进队列、不调用模型、不花钱。请求出现在信息面板(允许 / 拒绝),也会带 4 位配对码发给主人(每个机器人每小时最多 3 条;主人 24 小时内在那个渠道说过话才发得出去),主人在聊天里回复「同意 1234」/「拒绝 1234」即可。配对码不会和工具审批的编号撞。被拒绝的人之后发什么都不回。- 允许名单在 机器人设置 → 谁能使用 里,可以移除(移除后他再发消息会重新申请);`/status` 也会显示。- 升级时,已经和机器人有单聊会话的人自动加入允许名单(标为「升级前已在使用」),不会被拦在外面;换一个微信重新扫码时,原来的主人也留在名单里。diff --git a/docs/development_en.md b/docs/development_en.mdindex 59c6ae6..25aeeba 100644--- a/docs/development_en.md+++ b/docs/development_en.md@@ -136,7 +136,7 @@ In agent mode each bot has a file permission preset. Switch it with the permissiThe agent runs on your own computer (possibly with full access), so by default **only the owner and people you allow** can talk to a bot, per bot and per channel (`src/core/access.ts`):-- **Owner**: on WeChat, the account that scanned the QR code. Feishu connects with an App ID and App Secret and no scan, so **the first person to message the bot one-to-one after it is connected** becomes the owner (trust on first use): once it is connected, send the bot one line from your own Feishu, and that message is answered as usual. A WeChat login that did not report the scanner's id works the same way. Bot settings → Who can use shows "Feishu owner: … (first to message)"; "Change" (after a confirmation) clears the owner so the next person to message becomes the owner. Switching to another Feishu app or disconnecting Feishu clears it too. People who were denied never become the owner. The local web chat is never restricted.+- **Owner**: on WeChat, the account that scanned the QR code. Feishu connects with an App ID and App Secret and no scan, so **the first person to message the bot one-to-one after it is connected** becomes the owner (trust on first use): once it is connected, send the bot one line from your own Feishu, and that message is answered as usual. A WeChat login that did not report the scanner's id works the same way. Bot settings → Who can use shows the Feishu owner; "Change" (after a confirmation) clears the owner so the next person to message becomes the owner. Switching to another Feishu app or disconnecting Feishu clears it too. People who were denied never become the owner. The local web chat is never restricted.- **Anyone else** gets a single line, "you are not allowed to use this bot yet, the owner has been told" (at most once an hour per person); the message is not queued, no model is called and nothing is spent. The request shows in the info panel (allow / deny) and is sent to the owner with a 4-digit pairing code (at most 3 per bot per hour, and only if the owner spoke on that channel in the last 24 hours); the owner replies `同意 1234` / `拒绝 1234` (or `yes 1234` / `no 1234`) in chat. Pairing codes never collide with tool-approval codes. People who were denied get no reply at all.- The allowlist is in Bot settings → Who can use; entries can be removed (they can ask again by sending a message). `/status` shows it too.- On upgrade, everyone who already had a direct conversation with a bot is put on its allowlist (marked "used before the upgrade"), so nobody is cut off; re-scanning with another WeChat account keeps the previous owner on the list.diff --git a/src/diagnostics.ts b/src/diagnostics.tsindex 895454d..6a63b39 100644--- a/src/diagnostics.ts+++ b/src/diagnostics.ts@@ -403,7 +403,7 @@ export function diagnosticsReport(app: App, lines = 200): string {const ps = pwshReportLine(s.pwsh);if (ps) out.push(ps);const ob = s.outbox;- if (ob) out.push(`[出站队列] 等待发送 ${ob.pending} 条(重试中 ${ob.retrying})${ob.lastError ? ` · 最近错误:${ob.lastError}` : ""} · 等对方发消息后再发 ${ob.held} 条 · 最近 7 天没发出去 ${ob.gone7d} 条${ob.lastGone ? ` · 最近一次:${ob.lastGone}` : ""}`);+ if (ob) out.push(`[出站队列] 等待发送 ${ob.pending} 条(重试中 ${ob.retrying})${ob.lastError ? ` · 最近错误:${ob.lastError}` : ""}${ob.held ? ` · 等对方发消息后再发 ${ob.held} 条` : ""} · 最近 7 天没发出去 ${ob.gone7d} 条${ob.lastGone ? ` · 最近一次:${ob.lastGone}` : ""}`);const m = app.lastDiagnostics.model;if (m) {out.push("");diff --git a/src/web/server.ts b/src/web/server.tsindex 6a768af..03891ad 100644--- a/src/web/server.ts+++ b/src/web/server.ts@@ -649,7 +649,7 @@ export async function startWebServer(app: App, opts: { port?: number; host?: strconst o = v.owners[ch];if (!o) return null;const e = (o.entryId ? app.store.getAccessById(o.entryId) : undefined) ?? { channel: ch, peerId: o.peerId, senderId: o.peerId, name: "" };- return { peer: shortPeer(o.peerId), name: peerName(e), who: whoText(e), via: o.via };+ return { peer: shortPeer(o.peerId), name: peerName(e), via: o.via };};return send(res, 200, {policy: v.policy,@@ -671,7 +671,7 @@ export async function startWebServer(app: App, opts: { port?: number; host?: strif (seg[2] === "access" && seg[3] === "owner" && seg.length === 5 && m === "DELETE") {const ch = seg[4];if (ch !== "weixin" && ch !== "feishu") throw new HttpError(404, "没有这个渠道");- if (app.access.owner(id, ch)?.via === "login") throw new HttpError(409, "微信的主人是扫码登录的人;要换主人,请用那个微信重新扫码");+ if (app.access.owner(id, ch)?.via === "login") throw new HttpError(409, "微信主人要重新扫码才能更换");app.access.resetOwner(id, ch);return send(res, 200, { ok: true });}diff --git a/test/access.e2e.test.ts b/test/access.e2e.test.tsindex 72d67ab..c7c885d 100644--- a/test/access.e2e.test.ts+++ b/test/access.e2e.test.ts@@ -169,7 +169,7 @@ describe("飞书:第一个发消息的人成为主人", () => {expect([...feishu.cards.values()].at(-1)).toBe("[mock-a] 你说:我是老板");expect(feishu.texts.length).toBe(texts);const acc = (await api("/bots/default/access")).json;- expect(acc.owners.feishu).toEqual({ via: "first-message", peer: "oc_boss", name: "ou_boss", who: "飞书用户 ou_boss" });+ expect(acc.owners.feishu).toEqual({ via: "first-message", peer: "oc_boss", name: "ou_boss" });expect(acc.requests.filter((r: any) => r.channel === "feishu")).toEqual([]);// 同事来了:飞书主人和微信主人都收到配对码,主人在飞书里回复「允许 1234」diff --git a/ui/screens/bot-settings.js b/ui/screens/bot-settings.jsindex e513b07..2644d91 100644--- a/ui/screens/bot-settings.js+++ b/ui/screens/bot-settings.js@@ -79,8 +79,8 @@ function BudgetRows({ bot, budget, account, onSaved, onOpenSettings }) {}/**- * 谁能使用:只有主人和允许名单里的人。主人 = 扫码登录的微信 / 连上之后第一个发消息的人(可以「更换」:下一个发消息的人成为主人);- * 允许名单和拒绝过的人可以移除(移除后他再发消息会重新申请)。+ * 谁能使用:只有主人和允许名单里的人。主人 = 扫码登录的微信 / 连上之后第一个发消息的人,后者可以更换(下一个发消息的人成为主人)。+ * 允许名单和拒绝过的人可以移除(移除后他再发消息会重新申请)。没有的项不显示。*/function AccessRows({ botId }) {const [d, setD] = useState(null);@@ -109,7 +109,7 @@ function AccessRows({ botId }) {};const resetOwner = async (ch, o) => {const name = CHANNEL_NAME[ch];- if (!(await confirmSheet({ title: `更换${name}主人?`, body: `「${o.name}」不再是主人,之后发消息需要重新被允许。下一个给机器人发消息的人会成为${name}主人:用你自己的${name}发一句话就行。`, confirmLabel: "更换", danger: true }))) return;+ if (!(await confirmSheet({ title: `更换${name}主人?`, body: `下一个给机器人发消息的人会成为${name}主人,「${o.name}」需要重新被允许。`, confirmLabel: "更换", danger: true }))) return;call(`owner/${ch}`, "DELETE");};if (!d) return html`<div class="list-head">谁能使用</div><div class="list"><div class="row"><${Skeleton} w="45%" /></div></div>`;@@ -117,27 +117,23 @@ function AccessRows({ botId }) {const denied = d.entries.filter((e) => e.status === "denied");const owner = (ch) => {const o = d.owners[ch];- if (o) {- return html`<${Row} id=${`access-${ch}`} name=${`${CHANNEL_NAME[ch]}主人:${o.name}(${o.via === "login" ? "扫码登录的微信" : "第一个发消息的人"})`}>- ${o.via !== "login" && html`<button type="button" class="text" onClick=${() => resetOwner(ch, o)}>更换</button>`}- <//>`;- }- const sub = ch === "weixin" ? "扫码登录后,扫码的那个微信就是主人" : `还没有:用你自己的${CHANNEL_NAME[ch]}给机器人发一句话,就完成绑定`;- return html`<${Row} id=${`access-${ch}`} name=${`${CHANNEL_NAME[ch]}主人`} sub=${sub} />`;+ return o && html`<${Row} id=${`access-${ch}`} name=${`${CHANNEL_NAME[ch]}主人`}>+ <span class="val">${o.name}</span>+ ${o.via !== "login" && html`<button type="button" class="text" onClick=${() => resetOwner(ch, o)}>更换</button>`}+ <//>`;};return html`<div class="list-head">谁能使用</div><div class="list">- <${Row} id="access" name="只有主人和你允许的人" sub="其他人发消息只会收到一句提示,不会调用模型;请求出现在信息面板,也会带配对码发给主人" />+ <${Row} id="access" name="只有主人和你允许的人" />${owner("weixin")}${owner("feishu")}</div>- <div class="list-head">允许名单${allowed.length > 0 && html`<span class="badge count">${allowed.length}</span>`}</div>- <div class="list">- ${!allowed.length && html`<div class="row"><span class="hint">还没有允许别人。有人给机器人发消息后,会出现在信息面板的「使用请求」里。</span></div>`}- ${allowed.map((e) => html`<${Row} key=${e.id} id=${`access-${e.id}`} name=${e.who} sub=${[SOURCE_LABEL[e.source] || e.source, e.decidedAt ? fmtAgo(e.decidedAt) : ""].filter(Boolean).join(" · ")}>- <button type="button" class="text danger" onClick=${() => remove(e)}>移除</button>- <//>`)}- </div>+ ${allowed.length > 0 && html`<div class="list-head">允许名单<span class="badge count">${allowed.length}</span></div>+ <div class="list">+ ${allowed.map((e) => html`<${Row} key=${e.id} id=${`access-${e.id}`} name=${e.who} sub=${[SOURCE_LABEL[e.source] || e.source, e.decidedAt ? fmtAgo(e.decidedAt) : ""].filter(Boolean).join(" · ")}>+ <button type="button" class="text danger" onClick=${() => remove(e)}>移除</button>+ <//>`)}+ </div>`}${denied.length > 0 && html`<div class="list-head">拒绝过的人</div><div class="list">${denied.map((e) => html`<${Row} key=${e.id} id=${`access-${e.id}`} name=${e.who} sub=${`${fmtAgo(e.decidedAt)}拒绝 · 他再发消息不会收到任何回复`}>diff --git a/ui/screens/info-panel.js b/ui/screens/info-panel.jsindex 303d02a..80af7cf 100644--- a/ui/screens/info-panel.js+++ b/ui/screens/info-panel.js@@ -40,7 +40,7 @@ function FeishuRow({ bot, st, owner, reload }) {setBusy(false);};const clear = async () => {- if (!(await confirmSheet({ title: "断开飞书?", body: "会清除这个机器人的飞书 App ID 与 App Secret;重新连接后,第一个发消息的人成为飞书主人。", confirmLabel: "断开", danger: true }))) return;+ if (!(await confirmSheet({ title: "断开飞书?", body: "会清除这个机器人的飞书 App ID 与 App Secret。", confirmLabel: "断开", danger: true }))) return;try {await api(`/bots/${bot.id}/feishu`, { method: "DELETE" });setAppId("");@@ -62,13 +62,12 @@ function FeishuRow({ bot, st, owner, reload }) {<button type="button" class="btn primary" disabled=${!appId.trim() || busy} onClick=${save}>${busy ? html`<${Spinner} />` : "保存并连接"}</button>${bot.feishuAppId && html`<button type="button" class="text danger" onClick=${clear}>断开</button>`}</div>- ${owner === null && html`<p class="hint">${bot.feishuAppId ? "" : "连接后,"}用你自己的飞书给机器人发一句话,就完成绑定。</p>`}- ${owner && html`<p class="hint">飞书主人:${owner.name}(第一个发消息的人)</p>`}+ ${bot.feishuAppId && owner === null && html`<p class="hint">用你自己的飞书给机器人发一句话,就完成绑定。</p>`}<p class="hint">在飞书开放平台启用「机器人」,事件订阅选「使用长连接接收事件」并订阅 <code>im.message.receive_v1</code>;权限:<code>im:message.p2p_msg:readonly</code>、<code>im:message:send_as_bot</code>、<code>cardkit:card:write</code>。</p></div>`}`;}-function WeixinRow({ bot, st, owner, reload }) {+function WeixinRow({ bot, st, reload }) {const [open, setOpen] = useState(false);const [code, setCode] = useState("");const login = st.login;@@ -95,7 +94,6 @@ function WeixinRow({ bot, st, owner, reload }) {${login && login.state === "need_verifycode" && html`<div class="actions"><input class="field" style="width:140px" placeholder="验证码" value=${code} onInput=${(e) => setCode(e.target.value)} /><button type="button" class="btn" onClick=${() => call("/verify", { code }).then(() => setCode(""))}>提交</button></div>`}${st.account && st.account.pausedUntil > Date.now() && html`<p class="hint">暂停至 ${fmtTime(st.account.pausedUntil)}</p>`}- ${st.account && owner === null && html`<p class="hint">用你自己的微信给机器人发一句话,就完成绑定。</p>`}<div class="actions">${active ? html`<button type="button" class="btn" onClick=${() => call("/cancel")}>取消</button>` : html`<button type="button" class="btn primary" onClick=${() => call("/login")}>${st.account ? "重新扫码登录" : "扫码登录"}</button>`}<button type="button" class="text" onClick=${() => call("", { enabled: !bot.weixinEnabled })}>${bot.weixinEnabled ? "停用微信渠道" : "启用微信渠道"}</button>@@ -131,7 +129,7 @@ function AccessRequests({ botId, data, reload }) {<${Button} variant="primary" loading=${busy === r.id + "approve"} disabled=${!!busy} onClick=${() => act(r, "approve")}>允许</${Button}><${Button} loading=${busy === r.id + "deny"} disabled=${!!busy} onClick=${() => act(r, "deny")}>拒绝</${Button}></div>- <span class="hint">他只收到一句提示,没有调用模型。主人在聊天里回复「同意 ${r.code}」也可以。</span>+ <span class="hint">也可以在聊天里回复「同意 ${r.code}」。</span></div></div>`)}</div>`;}@@ -229,7 +227,7 @@ export function InfoPanel({ bot, onClose, onOpenBotSettings, onOpenChat }) {<div class="list-head">渠道</div><div class="list">${detail && detail.bot- ? html`<${FeishuRow} bot=${detail.bot} st=${detail.channels.feishu} owner=${access ? access.owners.feishu : undefined} reload=${reloadDetail} /><${WeixinRow} bot=${detail.bot} st=${detail.channels.weixin} owner=${access ? access.owners.weixin : undefined} reload=${reloadDetail} />`+ ? html`<${FeishuRow} bot=${detail.bot} st=${detail.channels.feishu} owner=${access ? access.owners.feishu : undefined} reload=${reloadDetail} /><${WeixinRow} bot=${detail.bot} st=${detail.channels.weixin} reload=${reloadDetail} />`: html`<div class="row"><${Skeleton} w="50%" /></div><div class="row"><${Skeleton} w="40%" /></div>`}</div>