🤖 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
feat(ui): 余额不再常驻左下角,点头像才弹出
dyk98edfd0e52420c
diff --git a/docs/development.md b/docs/development.mdindex 5944571..509a0a8 100644--- a/docs/development.md+++ b/docs/development.md@@ -91,7 +91,7 @@ docker exec amb cat /data/ui-token # 打开 http://<主机>:3600/?token=<令- 首次启动只有一个按钮「登录 / 注册 Modelflare」:在系统浏览器里登录(没有账户可当场注册)并点「继续」授权,回到本程序后自动为这台电脑签发一把专用 API Key 并连接 → 选默认模型 → 开始对话。Docker 或远程部署收不到浏览器登录的回调,首次启动页改为填写 API Key(校验 `GET https://modelflare.dev/v1/models`)。- 登录方式:OIDC 授权码 + PKCE(RFC 7636),按 RFC 8252 作为原生应用——本程序是公共客户端(`client_id` 为 `anymodel-bot`,没有也不需要客户端密钥),授权结果回调到本机 `127.0.0.1` 的临时端口。在 Modelflare 网页个人资料页的「已授权的应用」里可以随时撤销;撤销后本程序会发现并回到登录页。- 账户凭据(refresh token)存在数据目录的 `modelflare-account.json`(权限 600),桌面版用系统钥匙串加密(Electron safeStorage);界面只拿到账户名称。「退出登录」会撤销这台电脑的授权,Modelflare 同时删除登录时为它和各机器人签发的 Key。-- 余额:侧栏左下角和 设置 → Modelflare 显示账户钱包余额(只用 API Key 时读 `/v1/dashboard/billing/credit_grants`);「充值」打开 Modelflare 网页,回到窗口时自动刷新。余额低于提醒线(默认 1 美元,可改或关闭)时在应用里提醒一次,也可以设置让机器人发到你的微信 / 飞书。+- 余额:不常驻显示,点侧栏左下角的头像弹出,设置 → Modelflare 里也有,显示账户钱包余额(只用 API Key 时读 `/v1/dashboard/billing/credit_grants`);「充值」打开 Modelflare 网页,回到窗口时自动刷新。余额低于提醒线(默认 1 美元,可改或关闭)时在应用里提醒一次,也可以设置让机器人发到你的微信 / 飞书。- 登录后还能在 设置 → Modelflare 查看按天、按模型的用量,Modelflare 发来的通知,以及复制邀请链接。- 机器人预算(需要登录):机器人设置 → 预算,开启后这个机器人用自己的 Key(内置网关里单独的 provider),最多花设定的美元数;关闭后回到共用的 Key。- 生图 / 生视频:代理模式下机器人有 `media_models`(可用模型、默认模型、参数范围、参考价)、`media_docs`(从 docs.modelflare.dev 实时读该模型的请求格式)、`generate_image`、`generate_video` 四个工具,并自带一份 media 技能说明。各模型的参数格式不同,机器人按文档写请求体,工作区里的参考图写成 `workspace:路径` 即可;Key 始终只在本程序里,由本程序带着该机器人用的 Key 调 Modelflare,结果存进机器人工作区的 `media/`,再交付到聊天。@@ -121,7 +121,7 @@ docker exec amb cat /data/ui-token # 打开 http://<主机>:3600/?token=<令## 界面-- 侧栏:机器人列表(头像 + 名称 + 最近一条消息),+ 新建,右键 重命名 / 删除;左下角账户按钮打开设置(`⌘/Ctrl+,`)。+- 侧栏:机器人列表(头像 + 名称 + 最近一条消息),+ 新建,右键 重命名 / 删除;左下角点头像看余额,点齿轮打开设置(`⌘/Ctrl+,`)。- 对话页:顶部悬浮的机器人名称胶囊打开信息面板(`⌘/Ctrl+⇧+I`:默认由它回复的渠道账号、待审批、任务和规则、记忆、最近会话,⚙ 进机器人设置);回复流式显示(Markdown、代码块一键复制),可随时停止(`Esc`);审批与提问以卡片形式出现在对话里;向上翻阅时不会被拉回底部。- 命令面板 `⌘/Ctrl+K`;外观(跟随系统 / 浅色 / 深色)在 设置 → 常规。- 语言:简体中文 / English,设置 → 常规 → 语言(引导页右上角、命令面板里也能切),默认跟随系统(系统语言不是中文也不是英文时用英文)。偏好存在 config.json 的 `ui.lang`,托盘菜单、服务端报错和状态文字、机器人发到微信 / 飞书的系统消息(`/help`、审批提示等)都跟着它;命令行 / Docker 下"跟随系统"看 `AMB_LANG`,再看 `LC_ALL` / `LANG`,都没有时用简体中文。日志、发给模型的提示词和用户自己起的机器人名不翻译。diff --git a/docs/development_en.md b/docs/development_en.mdindex 59a9f40..dfb36ae 100644--- a/docs/development_en.md+++ b/docs/development_en.md@@ -91,7 +91,7 @@ Inside the container the console listens on 0.0.0.0, so token access is enforced- First launch shows a single button, "Sign in / Sign up for Modelflare": sign in in your system browser (you can sign up on the spot) and click Continue to authorize. Back in the app, a dedicated API key is issued for this computer and connected → pick a default model → start chatting. Docker and remote deployments cannot receive the browser callback, so their first-run screen asks for an API key instead (validated with `GET https://modelflare.dev/v1/models`).- Sign-in method: OIDC authorization code + PKCE (RFC 7636), as a native app per RFC 8252. The app is a public client (`client_id` is `anymodel-bot`; it has and needs no client secret), and the authorization result is delivered to a temporary port on `127.0.0.1`. You can revoke access at any time under "Authorized apps" on your Modelflare profile page; the app notices and returns to the sign-in screen.- The account credential (refresh token) is stored in `modelflare-account.json` in the data directory (mode 600); the desktop app encrypts it with the system keychain (Electron safeStorage). The UI only receives the account name. "Sign out" revokes this computer's authorization, and Modelflare deletes the keys it issued for it and its bots at sign-in.-- Balance: the bottom-left of the sidebar and Settings → Modelflare show the wallet balance (with only an API key, it reads `/v1/dashboard/billing/credit_grants`). "Top up" opens the Modelflare website, and the balance refreshes when you return to the window. When the balance drops below the reminder threshold (1 US dollar by default; adjustable or off), the app reminds you once, and can also have a bot message you on WeChat / Feishu.+- Balance: not always on screen. Click the avatar at the bottom-left of the sidebar to see it, or open Settings → Modelflare. Both show the wallet balance (with only an API key, it reads `/v1/dashboard/billing/credit_grants`). "Top up" opens the Modelflare website, and the balance refreshes when you return to the window. When the balance drops below the reminder threshold (1 US dollar by default; adjustable or off), the app reminds you once, and can also have a bot message you on WeChat / Feishu.- When signed in, Settings → Modelflare also shows usage per day and per model, notifications from Modelflare, and your invite link.- Bot budgets (requires sign-in): Bot settings → Budget. When enabled, the bot uses its own key (a separate provider in the gateway) capped at the dollar amount you set; when disabled it goes back to the shared key.- Image / video generation: in agent mode, bots get four tools — `media_models` (available models, defaults, parameter ranges, reference prices), `media_docs` (reads the model's request format live from docs.modelflare.dev), `generate_image` and `generate_video` — plus a bundled media skill. Parameter formats differ per model, so the bot writes the request body from the docs; reference images in the workspace are written as `workspace:path`. The key never leaves the app: the app calls Modelflare with the bot's key, saves results in the bot workspace's `media/`, and delivers them to the chat.@@ -121,7 +121,7 @@ Inside the container the console listens on 0.0.0.0, so token access is enforced## Interface-- Sidebar: bot list (avatar + name + latest message), + New, right-click to rename / delete; the account button at the bottom-left opens Settings (`⌘/Ctrl+,`).+- Sidebar: bot list (avatar + name + latest message), + New, right-click to rename / delete; at the bottom-left, the avatar shows your balance and the gear opens Settings (`⌘/Ctrl+,`).- Chat screen: the floating bot-name pill at the top opens the info panel (`⌘/Ctrl+⇧+I`: channel accounts this bot answers by default, pending approvals, tasks and rules, memory, recent sessions; ⚙ opens bot settings). Replies stream in (Markdown, one-click copy for code blocks) and can be stopped at any time (`Esc`). Approvals and questions appear as cards in the chat. Scrolling up is never yanked back to the bottom.- Command palette `⌘/Ctrl+K`; appearance (system / light / dark) is in Settings → General.- Language: 简体中文 / English, in Settings → General → Language (also at the top-right of the onboarding screen and in the command palette). It follows the system by default (English when the system language is neither Chinese nor English). The preference is stored in `ui.lang` in config.json; the tray menu, server error and status messages, and system messages bots send to WeChat / Feishu (`/help`, approval prompts, …) all follow it. On the command line / Docker, "System" means `AMB_LANG`, then `LC_ALL` / `LANG`, falling back to Simplified Chinese. Logs, prompts sent to the model and bot names users chose are not translated.diff --git a/site/src/components/DemoTour.astro b/site/src/components/DemoTour.astroindex 41f9e42..0a394b4 100644--- a/site/src/components/DemoTour.astro+++ b/site/src/components/DemoTour.astro@@ -149,7 +149,7 @@ const tplIcons = [I.file, I.chat, I.terminal];<span data-at="4500"><span class="tw-row__av"><BotFace char="yellow" size={30} /></span><span class="tw-row__body"><b>{code}</b><span class="tw-row__snip">{u.noChat}</span></span></span></div></div>- <div class="tw__acct"><span class="tw__me">M</span><span class="tw__who">Modelflare<small class="tnum">$12.40</small></span><Fragment set:html={ic(I.gear)} /></div>+ <div class="tw__acct"><span class="tw__me">M</span><span class="tw__who">Modelflare</span><Fragment set:html={ic(I.gear)} /></div></div><div class="tw__main"><div class="tw-head">@@ -206,7 +206,7 @@ const tplIcons = [I.file, I.chat, I.terminal];</div>))}</div>- <div class="tw__acct"><span class="tw__me">M</span><span class="tw__who">Modelflare<small class="tnum">$12.40</small></span><Fragment set:html={ic(I.gear)} /></div>+ <div class="tw__acct"><span class="tw__me">M</span><span class="tw__who">Modelflare</span><Fragment set:html={ic(I.gear)} /></div></div><div class="tw__main"><div class="tw-head">@@ -262,7 +262,7 @@ const tplIcons = [I.file, I.chat, I.terminal];</div>))}</div>- <div class="tw__acct"><span class="tw__me">M</span><span class="tw__who">Modelflare<small class="tnum">$12.40</small></span><Fragment set:html={ic(I.gear)} /></div>+ <div class="tw__acct"><span class="tw__me">M</span><span class="tw__who">Modelflare</span><Fragment set:html={ic(I.gear)} /></div></div><div class="tw__main"><div class="tw-head">diff --git a/site/src/i18n/en.ts b/site/src/i18n/en.tsindex 32b499d..f8ec3c2 100644--- a/site/src/i18n/en.ts+++ b/site/src/i18n/en.ts@@ -60,7 +60,6 @@ export const en: Dict = {digest: "3 decisions · 2 to-dos",search: "Search",account: "My account",- balance: "Balance",working: "Working…",thinking: "Thinking…",took: "Worked for {s}",diff --git a/site/src/i18n/zh.ts b/site/src/i18n/zh.tsindex a6dedfa..b6f2944 100644--- a/site/src/i18n/zh.ts+++ b/site/src/i18n/zh.ts@@ -62,7 +62,6 @@ export const zh = {digest: "3 个决定 · 2 个待办",search: "搜索",account: "我的账户",- balance: "余额",working: "正在工作…",thinking: "思考中…",took: "用时 {s}",diff --git a/site/src/sections/Hero.astro b/site/src/sections/Hero.astroindex 6388c70..4adacc9 100644--- a/site/src/sections/Hero.astro+++ b/site/src/sections/Hero.astro@@ -297,7 +297,7 @@ const ic = (d: string, size = 16, cls = "aic") => `<svg class="${cls}" width="${</div>))}</div>- <div class="awin__acct"><span class="awin__me">{s.account.slice(0, 1).toUpperCase()}</span><span class="awin__who">{s.account}<small>{s.balance} $12.40</small></span><Fragment set:html={ic(I.gear)} /></div>+ <div class="awin__acct"><span class="awin__me">{s.account.slice(0, 1).toUpperCase()}</span><span class="awin__who">{s.account}</span><Fragment set:html={ic(I.gear)} /></div></div><div class="awin__main">diff --git a/site/src/styles/home.css b/site/src/styles/home.cssindex 8c56841..1866790 100644--- a/site/src/styles/home.css+++ b/site/src/styles/home.css@@ -414,7 +414,6 @@.awin__acct { display: flex; flex: none; align-items: center; gap: 10px; height: 44px; margin: 8px; padding: 0 10px; border-radius: 12px; color: var(--a-muted); }.awin__me { display: grid; place-items: center; flex: none; width: 28px; height: 28px; border-radius: 50%; background: var(--a-pill); color: var(--a-fg2); font-size: 12.5px; font-weight: 600; }.awin__who { flex: 1; min-width: 0; display: grid; color: var(--a-fg); font-size: 13px; font-weight: 500; line-height: 1.35; white-space: nowrap; }- .awin__who small { color: var(--a-muted); font-size: 11px; font-weight: 400; font-variant-numeric: tabular-nums; }/* 主区(ui/css/chat.css):顶栏(头像 + 名称 | 新对话 · 信息面板)→ 对话 → 玻璃输入框(文字区 + 工具栏:加号 · 权限 | 模型 · 发送) */.awin__main { display: flex; flex-direction: column; min-width: 0; min-height: 0; margin: 8px 8px 8px 0; overflow: hidden; border-radius: 12px; background: var(--a-surface); box-shadow: var(--a-shadow-pane); }diff --git a/site/src/styles/tour.css b/site/src/styles/tour.cssindex c7a21b5..8c3e332 100644--- a/site/src/styles/tour.css+++ b/site/src/styles/tour.css@@ -124,7 +124,6 @@.tw__acct { display: flex; flex: none; align-items: center; gap: 9px; height: 40px; margin: 8px; padding: 0 8px; border-radius: 11px; color: var(--a-muted); }.tw__me { display: grid; place-items: center; flex: none; width: 26px; height: 26px; border-radius: 50%; background: var(--a-pill); color: var(--a-fg2); font-size: 12px; font-weight: 600; }.tw__who { flex: 1; min-width: 0; display: grid; color: var(--a-fg); font-size: 12.5px; font-weight: 500; line-height: 1.35; white-space: nowrap; }- .tw__who small { color: var(--a-muted); font-size: 11px; font-weight: 400; }/* 主区(ui/css/chat.css):顶栏 → 对话 → 玻璃输入框 */.tw__main { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; margin: 8px 8px 8px 0; overflow: hidden; border-radius: 11px; background: var(--a-surface); box-shadow: var(--a-shadow-pane); }diff --git a/ui/css/shell.css b/ui/css/shell.cssindex ba2d27a..91c37cd 100644--- a/ui/css/shell.css+++ b/ui/css/shell.css@@ -177,7 +177,7 @@ button.thread:active { background: var(--side-press); }}/* 账户行的下沿和主区的下沿对齐(都离窗口下沿 --pane-gap) */-.side-foot { flex: none; display: flex; align-items: center; padding: var(--side-inset); }+.side-foot { flex: none; display: flex; align-items: center; gap: var(--space-1); padding: var(--side-inset); }.account {--focus-offset: -2px;display: flex; align-items: center; gap: var(--space-2-5); min-width: 0; flex: 1; height: var(--ctl-2xl); padding: 0 var(--side-row-px);@@ -192,8 +192,11 @@ button.thread:active { background: var(--side-press); }font-weight: var(--fw-semibold); font-size: var(--fs-sm); color: var(--fg-2);}.account .who { flex: 1; min-width: 0; font-size: var(--fs-md); font-weight: var(--fw-medium); color: var(--fg); line-height: var(--lh-snug); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }-.account .who .bal { display: block; font-size: var(--fs-2xs); font-weight: var(--fw-regular); color: var(--muted); }-.account .who .bal.low { color: var(--red); }+/* 账户浮层:余额只在这里显示,点头像才弹出(常驻显示会让人觉得一直在花钱) */+.account-pop { display: grid; gap: var(--space-2-5); padding: var(--space-3); }+.account-pop-name { font-size: var(--fs-sm); font-weight: var(--fw-medium); color: var(--fg); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }+.account-pop-bal { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); }+.account-pop-label { font-size: var(--fs-2xs); color: var(--muted); }/* 余额不足:和其他出错的提示行一样只铺一层淡红(--red-wash),字用 --fg,前面一个红点;悬停、按下时淡红加深一级,不加下划线(整条都是链接) */.low-balance {@@ -206,8 +209,6 @@ button.thread:active { background: var(--side-press); }.low-balance::before { content: ""; width: 6px; height: 6px; border-radius: 50%; flex: none; background: var(--red); }.low-balance:hover { --low-wash: color-mix(in srgb, var(--red) 14%, transparent); text-decoration: none; }.low-balance:active { --low-wash: color-mix(in srgb, var(--red) 20%, transparent); }-.account > .ic { color: var(--muted); transition: color var(--t-fast); }-.account:hover > .ic { color: var(--fg); }/* —— 窗口标题栏:桌面版没有系统标题栏,侧栏顶部这一行(--pane-gap + --head-h)就是标题栏。左上角归谁看平台:macOS 是红绿灯(应用名在菜单栏里,这里不再放 Logo),Windows 是应用图标 + 名称(Windows 的习惯)。diff --git a/ui/design/gallery.js b/ui/design/gallery.jsindex ed0e7cd..b9ee63d 100644--- a/ui/design/gallery.js+++ b/ui/design/gallery.js@@ -319,8 +319,8 @@ const STATE_ROWS = [["默认", () => html`<label class="side-search" style="width: 200px; margin: 0"><${Icon} name="search" size="sm" /><input placeholder="搜索" tabindex="-1" /></label>`],["悬停", () => html`<label class="side-search is-hover" style="width: 200px; margin: 0"><${Icon} name="search" size="sm" /><input placeholder="搜索" tabindex="-1" /></label>`],["聚焦", () => html`<label class="side-search is-focus" style="width: 200px; margin: 0"><${Icon} name="search" size="sm" /><input value="日报" tabindex="-1" /></label>`],- ["账户 · 悬停", () => html`<button type="button" class="account is-hover" style="width: 200px"><span class="me">R</span><span class="who">root</span><${Icon} name="gear" /></button>`],- ["账户 · 打开", () => html`<button type="button" class="account on" style="width: 200px"><span class="me">R</span><span class="who">root</span><${Icon} name="gear" /></button>`]] },+ ["账户 · 悬停", () => html`<button type="button" class="account is-hover" style="width: 200px"><span class="me">R</span><span class="who">root</span></button>`],+ ["账户 · 打开", () => html`<button type="button" class="account on" style="width: 200px"><span class="me">R</span><span class="who">root</span></button>`]] },{ name: "余额不足提示", note: ".low-balance · 一层淡红 + 红点,字用 --fg;悬停、按下淡红加深", ctx: "side", cells: basic((c) => html`<a class=${`low-balance ${c}`} href="#states" style="width: 220px; margin: 0">余额只剩 $0.42,去充值 ↗</a>`) },{ name: "选角色", note: ".avatar-opt · 选中比悬停深一级、名字变实,不描边", cells: [...basic((c) => html`<button type="button" class=${`avatar-opt ${c}`}><${BotAvatar} char="green" size=${36} /><span class="avatar-name">${BOT_CHARS.green.name}</span></button>`),diff --git a/ui/locales/en/sidebar.js b/ui/locales/en/sidebar.jsindex 10d3d9d..7bb4692 100644--- a/ui/locales/en/sidebar.js+++ b/ui/locales/en/sidebar.js@@ -3,7 +3,10 @@ export default {localUser: "Local user",settingsTitle: "Settings (⌘,)",openSettings: "Open Settings",- balance: "Balance {amount}",+ account: "Account",+ accountDetails: "Account and usage",+ balance: "Balance",+ topUp: "Top up ↗",lowBalance: "Only {amount} left — top up ↗",renamed: "Renamed",delete: {diff --git a/ui/locales/zh-CN/sidebar.js b/ui/locales/zh-CN/sidebar.jsindex 3e152af..7e2f5f3 100644--- a/ui/locales/zh-CN/sidebar.js+++ b/ui/locales/zh-CN/sidebar.js@@ -4,7 +4,10 @@ export default {localUser: "本机用户",settingsTitle: "设置(⌘,)",openSettings: "打开设置",- balance: "余额 {amount}",+ account: "账户",+ accountDetails: "账户和用量",+ balance: "余额",+ topUp: "充值 ↗",lowBalance: "余额只剩 {amount},去充值 ↗",renamed: "已重命名",delete: {diff --git a/ui/main.js b/ui/main.jsindex bfb938a..1e36832 100644--- a/ui/main.js+++ b/ui/main.js@@ -378,7 +378,7 @@ function App() {username=${status && status.username} account=${managed ? account : null} />`: html`<${Sidebar} bots=${bots} botsError=${botsErr} reloadBots=${reloadBots} selectedId=${bot && bot.id} view=${view === "chat" && bots && !bots.length ? "new" : view}previews=${previews} pending=${pending} working=${working} needs=${needs} username=${status && status.username} account=${managed ? account : null}- onNew=${newBot} onSelect=${openChat} onNeeds=${openNeeds} onDeleted=${onDeleted} onOpenSettings=${() => openSettings()} onBotSettings=${openBotSettings} onGuide=${startGuide} />`}+ onNew=${newBot} onSelect=${openChat} onNeeds=${openNeeds} onDeleted=${onDeleted} onOpenSettings=${(tab) => openSettings(tab)} onBotSettings=${openBotSettings} onGuide=${startGuide} />`}<${Splitter} class="split-side" size="--side-w" label=${t("app.resizeSide")} value=${sideW} room=${room("--panel-track")} onCommit=${(v) => setPrefs({ sideW: v })} /><main class="main">${view === "chat" && bot && html`<${ChatScreen} key=${bot.id} bot=${bot} models=${models} modelsError=${modelsError} reloadModels=${reloadModels}diff --git a/ui/screens/settings.js b/ui/screens/settings.jsindex 6a6a194..e38ea40 100644--- a/ui/screens/settings.js+++ b/ui/screens/settings.js@@ -165,7 +165,7 @@ export function SettingsSide({ tab, query, onQuery, onTab, onBack, username, acconClick=${() => { onQuery(""); onTab(id); }}><${Icon} name=${icon} size="md" /><span>${tabLabel(label)}</span></button>`;})}</nav>- <div class="side-foot"><${AccountButton} username=${username} account=${account} on onClick=${() => onTab("general")} /></div>+ <div class="side-foot"><${AccountButton} username=${username} account=${account} settingsOn onSettings=${() => onTab("general")} onModelflare=${() => { onQuery(""); onTab("modelflare"); }} /></div></aside>`;}diff --git a/ui/screens/sidebar.js b/ui/screens/sidebar.jsindex a362aff..dbf5a02 100644--- a/ui/screens/sidebar.js+++ b/ui/screens/sidebar.js@@ -1,9 +1,9 @@// 侧栏 280(参考 Grok Bot,宽度可以拖右边的分隔条调整):顶部只有新建按钮,常驻搜索框,-// 机器人行(头像 + 名称 + 时间 + 一行预览;悬停出现"更多",和右键是同一份菜单),左下角账户(打开设置)。+// 机器人行(头像 + 名称 + 时间 + 一行预览;悬停出现"更多",和右键是同一份菜单),左下角账户(点头像看余额,点齿轮打开设置)。// 新建在主区的新建页(screens/new-bot.js);新建页打开时列表顶部有一行占位的"新机器人"。// 有事在等你时,机器人列表上方多一行「需要你 N」(没事时没有这一行);机器人行的第二行换成最早那件事。import { useEffect, useRef, useState } from "preact/hooks";-import { html, Icon, IconButton, Menu, Skeleton } from "../components/ui.js";+import { html, Icon, IconButton, Menu, Popover, Skeleton } from "../components/ui.js";import { BotAvatar } from "../components/avatar.js";import { GuidePill } from "../components/guide.js";import { api } from "../lib/api.js";@@ -13,15 +13,33 @@ import { MF_TOPUP, usd } from "../lib/links.js";import { t } from "../lib/i18n.js";import { NeedsRow } from "./needs-you.js";-/** 左下角账户:头像字母 + 名称(登录后是 Modelflare 账户名)与余额 + 齿轮,点开设置 */-export function AccountButton({ username, account, on, onClick }) {+/**+ * 左下角账户:头像字母 + 名称(登录后是 Modelflare 账户名),旁边是设置齿轮。+ * 余额不常驻:用户反馈一直看到它,会觉得一直在花钱。点头像才弹出来;余额低于提醒线时另有 LowBalance 提示。+ * 没有余额可看时(没登录、不是 Modelflare 托管),点头像和点齿轮一样打开设置。+ */+export function AccountButton({ username, account, settingsOn, onSettings, onModelflare }) {+ const [open, setOpen] = useState(false);+ const ref = useRef(null);const me = ((account && account.state === "signed_in" && account.name) || username || t("sidebar.localUser")).trim();const bal = account && account.balanceUsd !== null && account.balanceUsd !== undefined ? usd(account.balanceUsd) : "";- return html`<button type="button" class=${`account${on ? " on" : ""}`} title=${t("sidebar.settingsTitle")} aria-label=${t("sidebar.openSettings")} onClick=${onClick}>- <span class="me" aria-hidden="true">${me.slice(0, 1).toUpperCase()}</span>- <span class="who">${me}${bal && html`<span class=${`bal num${account.lowBalance ? " low" : ""}`}>${t("sidebar.balance", { amount: bal })}</span>`}</span>- <${Icon} name="gear" size="md" />- </button>`;+ return html`<button type="button" class=${`account${open ? " on" : ""}`} ref=${ref}+ aria-label=${bal ? t("sidebar.account") : t("sidebar.openSettings")} aria-haspopup=${bal ? "dialog" : undefined} aria-expanded=${bal ? open : undefined}+ onClick=${bal ? () => setOpen((v) => !v) : onSettings}>+ <span class="me" aria-hidden="true">${me.slice(0, 1).toUpperCase()}</span>+ <span class="who">${me}</span>+ </button>+ <${IconButton} icon="gear" iconSize="md" label=${t("sidebar.settingsTitle")} on=${settingsOn} onClick=${onSettings} />+ ${open && bal && html`<${Popover} anchor=${ref.current} prefer="up" width=${240} label=${t("sidebar.account")} onClose=${() => setOpen(false)}>+ <div class="account-pop">+ <div class="account-pop-name">${me}</div>+ <div class="account-pop-bal">+ <div><div class="account-pop-label">${t("sidebar.balance")}</div><div class=${`balance${account.lowBalance ? " low" : ""}`}>${bal}</div></div>+ <a class="btn sm" href=${MF_TOPUP} target="_blank" rel="noopener noreferrer">${t("sidebar.topUp")}</a>+ </div>+ </div>+ <div class="foot"><button type="button" onClick=${() => { setOpen(false); onModelflare(); }}>${t("sidebar.accountDetails")}</button></div>+ <//>`}`;}/** 余额低于提醒线时,侧栏底部常驻一条提示 */@@ -115,7 +133,7 @@ export function Sidebar({ bots, botsError, reloadBots, selectedId, view, preview</nav><${LowBalance} account=${account} />${bots && bots.length > 0 && html`<${GuidePill} onGo=${onGuide} />`}- <div class="side-foot"><${AccountButton} username=${username} account=${account} onClick=${onOpenSettings} /></div>+ <div class="side-foot"><${AccountButton} username=${username} account=${account} onSettings=${() => onOpenSettings()} onModelflare=${() => onOpenSettings("modelflare")} /></div>${ctx && html`<${Menu} anchor=${ctx.el || { left: ctx.x, right: ctx.x, top: ctx.y, bottom: ctx.y, width: 0 }} align=${ctx.el ? "right" : undefined}width=${200} label=${t("sidebar.actionsFor", { name: ctx.bot.name })} onClose=${() => setCtx(null)}items=${[