From 7b794ef20720e726b59befaa7e9d2b807387719a Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 16 Nov 2026 07:49:54 +0000 Subject: [PATCH] feat: render the v0.1 bot client shell Replace the placeholder Bots page with the three-column shell from the UI design: conversation, library, new bot, setup, and settings. Copy stays in the locale files. Bot, approval, and settings state is in-memory only; the health route is unchanged. Co-authored-by: sys520084 --- CLAUDE.md | 2 +- CONTRIBUTING.md | 1 + README.md | 10 +- README.zh-CN.md | 10 +- docs/quickstart.md | 14 +- packages/dsh-rayrun-bots/README.md | 22 +- packages/dsh-rayrun-bots/client.js | 2062 ++++++++++++++++- packages/dsh-rayrun-bots/index.js | 7 +- packages/dsh-rayrun-bots/locale/en.json | 242 +- packages/dsh-rayrun-bots/locale/zh.json | 242 +- packages/dsh-rayrun-bots/package.json | 3 +- .../dsh-rayrun-bots/test/client-contract.mjs | 118 + 12 files changed, 2639 insertions(+), 94 deletions(-) create mode 100644 packages/dsh-rayrun-bots/test/client-contract.mjs diff --git a/CLAUDE.md b/CLAUDE.md index 760e011..467ffd6 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -76,7 +76,7 @@ Repository: **Rayrun Bot** (`RayrunOS/Rayrun-Bot`). DSH plugin package names kee - `README.md` — product page (English, source of truth); `README.zh-CN.md` — mirror, updated in the same commit. - `docs/` — quick start, architecture, security, FAQ, roadmap, Grok Bot inspiration, MVP plan, client plan, UI design, bot persona, local file design, platform asks. README stays short; detail goes here. -- `packages/dsh-rayrun-bots/` — the whole product layer: bot roster, bot↔session mapping, persistent host, approvals, routines, client panel, and the adapter to the cloud-computer plugin. A1 skeleton exists (`package.json`, `index.js`, `client.js`, `lib/`, `locale/`, `test/`); the bot layer itself is not built yet. +- `packages/dsh-rayrun-bots/` — the whole product layer: bot roster, bot↔session mapping, persistent host, approvals, routines, client panel, and the adapter to the cloud-computer plugin. The package loads (health route + v0.1 client shell). The bot layer itself — roster, sessions, remote approvals, persistence — is not built yet. - `dsh-rayrun-computer` — **a separate project** (`RayrunOS/dsh-rayrun-computer`, MIT), not a directory in this repo. It provides the cloud computers and the `rayrun_*` tools; Rayrun Bot consumes it as a dependency. Never modify, fork or vendor it here. - `package.json` — private workspace root. No dependencies, no build step. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ce9d056..1daa7c1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -36,6 +36,7 @@ There is no build step. Each package carries plain-Node checks under its own - `node packages/dsh-rayrun-bots/test/manifest-check.mjs` - `node packages/dsh-rayrun-bots/test/locale-audit.mjs` - `node packages/dsh-rayrun-bots/test/rpc-contract.mjs` +- `node packages/dsh-rayrun-bots/test/client-contract.mjs` The same checks run in CI (`.github/workflows/checks.yml`) on push and pull requests. Live integration tests need real Rayrun credentials and never run in diff --git a/README.md b/README.md index 528fd3e..a19d84b 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ English | [简体中文](README.zh-CN.md) Rayrun Bot gives the bots in [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) a name, a body and a home. A bot is not a chat session: it has a name, instructions, memory and a schedule, and it lives on your own [Rayrun](https://rayrunos.com/) cloud computer — a Linux machine you can watch and take over — while thinking with your own DeepSeek API key. Nothing is hosted by us: the compute is on your Rayrun account, the model bill is yours, and the approval prompt is the contract. This repository is where that product is built. -> **Status (November 2026).** Pre-alpha. The cloud-computer plugin this project builds on is a separate project at [RayrunOS/dsh-rayrun-computer](https://github.com/RayrunOS/dsh-rayrun-computer); Rayrun Bot adds the bot layer on top of it, and that layer is what this repository is building. The first package skeleton (`packages/dsh-rayrun-bots`) now loads as a bundle, but there is no bot layer or release yet. +> **Status (November 2026).** Pre-alpha. The cloud-computer plugin this project builds on is a separate project at [RayrunOS/dsh-rayrun-computer](https://github.com/RayrunOS/dsh-rayrun-computer); Rayrun Bot adds the bot layer on top of it, and that layer is what this repository is building. `packages/dsh-rayrun-bots` loads as a bundle. Its client half renders the v0.1 shell (chat list, conversation, details, new bot, setup, settings) as an in-memory preview. The host half still only answers a health check. There is no persisted roster, no remote approvals, and no release yet. ## How it works @@ -118,7 +118,7 @@ Rayrun Bot/ ├── package.json # private workspace root ├── docs/ # design docs, plans, platform asks └── packages/ - └── dsh-rayrun-bots/ # A1 skeleton: host/client halves, locale, tests + └── dsh-rayrun-bots/ # health route + v0.1 client shell, locale, tests ``` The cloud-computer plugin (`dsh-rayrun-computer`) is not in this tree: it is a **separate project**, consumed as a dependency. Two plugins in the same DSH profile, one product. The repository and product are called **Rayrun Bot**; the packages keep the `dsh-` prefix that the DSH ecosystem uses. The README is the product page; `docs/` holds the detail. Deeper reads: [quick start](docs/quickstart.md), [architecture](docs/architecture.md), [security](docs/security.md), [FAQ](docs/faq.md), [roadmap](docs/roadmap.md), [Grok Bot inspiration](docs/inspiration.md), [MVP plan](docs/mvp-plan.md), [client plan](docs/client-plan.md), [UI design](docs/ui-design.md), [bot persona](docs/bot-persona.md), [local file design](docs/local-file-design.md), [platform asks](docs/platform-asks.md). Both READMEs are updated in the same commit — English is the source of truth. @@ -133,7 +133,7 @@ dsh plugin --profile web add /absolute/path/to/package # restart DSH afterwards; the page loads the new client half on start ``` -- Checks: `node --check packages/dsh-rayrun-bots/index.js`, `node packages/dsh-rayrun-bots/test/manifest-check.mjs`, `node packages/dsh-rayrun-bots/test/locale-audit.mjs`, `node packages/dsh-rayrun-bots/test/rpc-contract.mjs`; the same checks run in CI on push and pull requests (`.github/workflows/checks.yml`). +- Checks: `node --check` on `packages/dsh-rayrun-bots/index.js` and `client.js`, then `node packages/dsh-rayrun-bots/test/manifest-check.mjs`, `locale-audit.mjs`, `rpc-contract.mjs`, and `client-contract.mjs`; the same checks run in CI on push and pull requests (`.github/workflows/checks.yml`). - Live integration tests need real Rayrun credentials and never run in CI. - Read [`CLAUDE.md`](CLAUDE.md) and [`CONTRIBUTING.md`](CONTRIBUTING.md) before changing anything. Commit messages are in English with `feat:`, `fix:`, `chore:` or `docs:` prefixes. @@ -144,8 +144,8 @@ dsh plugin --profile web add /absolute/path/to/package | | | | --- | --- | | **Works today** (separate project, our dependency) | Seven `rayrun_*` tools, noVNC desktop, per-session cloud/local routing, hash-verified workspace sync, task delegation, worker projection, optional idle stop. Verified on DeepSeek Harness `0.2.1-rc.5`. | -| **This repository** | The repo itself: README, docs, issue and PR templates, agent rules, the dependency boundary, and the `dsh-rayrun-bots` A1 skeleton (placeholder page + health route) with plain-Node checks and a checks-only CI workflow. No bot features and no publishable release yet. | -| **Not built yet** | Bot roster and bot↔session mapping, a persistent DSH host on the machine, remote approvals, routines and triggers, cost bar, IM channel, the two-plugin install path (dependency declaration and version check), npm packages and the release/publish CI path. | +| **This repository** | README, docs, issue and PR templates, agent rules, the dependency boundary, and `dsh-rayrun-bots`: a health route plus the v0.1 client shell (five screens, in-memory preview), with plain-Node checks and a checks-only CI workflow. No persisted bot layer and no publishable release yet. | +| **Not built yet** | Bot roster and bot↔session mapping, a persistent DSH host on the machine, remote approvals that gate a worker, routines that actually run, live usage from the account, IM channel, the two-plugin install path (dependency declaration and version check), npm packages and the release/publish CI path. | | **Platform gaps** | Safe inbound networking (today the token ingress is unusable and only `public` works), idle auto-stop, a spend cap, the session-resume contract. The full list is in [docs/architecture.md](docs/architecture.md). | **v0.1 path** — install from npm → sign in → create a bot → approve its first gated action. Exit criteria are in [docs/roadmap.md](docs/roadmap.md). diff --git a/README.zh-CN.md b/README.zh-CN.md index bd823e1..ef989d6 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -4,7 +4,7 @@ Rayrun Bot 给 [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) 里的 Bot 一个名字、一副身体和一个家。Bot 不是聊天会话:它有名字、指令、记忆和日程,住在你自己的 [Rayrun](https://rayrunos.com/) 云电脑上——一台你能看见、也能接管的 Linux 机器——并用你自己的 DeepSeek API key 思考。没有我们托管的东西:算力记在你自己 Rayrun 账号上,模型账单是你的,审批提示就是约定。本仓库就是把这个产品造出来的地方。 -> **状态(2026 年 11 月)。** Pre-alpha。本项目赖以构建的云电脑插件是一个独立项目,在 [RayrunOS/dsh-rayrun-computer](https://github.com/RayrunOS/dsh-rayrun-computer) 单独维护;Rayrun Bot 在它之上加 Bot 层,本仓库造的就是这一层。第一个包骨架(`packages/dsh-rayrun-bots`)已经能作为 bundle 加载,但还没有 Bot 层,也没有可发布的版本。 +> **状态(2026 年 11 月)。** Pre-alpha。本项目赖以构建的云电脑插件是一个独立项目,在 [RayrunOS/dsh-rayrun-computer](https://github.com/RayrunOS/dsh-rayrun-computer) 单独维护;Rayrun Bot 在它之上加 Bot 层,本仓库造的就是这一层。`packages/dsh-rayrun-bots` 已经能作为 bundle 加载。它的 Client 半区画出了 v0.1 界面(聊天列表、对话、详情、新建 Bot、设置向导、设置页),数据只存在这一页的内存里。Host 半区仍然只回答一次 health 检查。没有持久化的名册,没有远程审批,也没有可发布的版本。 ## 工作原理 @@ -118,7 +118,7 @@ Rayrun Bot/ ├── package.json # 私有 workspace 根 ├── docs/ # 设计文档、计划、平台需求 └── packages/ - └── dsh-rayrun-bots/ # A1 骨架:host/client 两半、locale、测试 + └── dsh-rayrun-bots/ # health 路由 + v0.1 客户端界面、locale、测试 ``` 云电脑插件(`dsh-rayrun-computer`)不在这个树里:它是**独立项目**,作为依赖被复用——同一个 DSH profile 里两个插件,一个产品。仓库和产品都叫 **Rayrun Bot**;插件包保留 `dsh-` 前缀,这是 DSH 插件生态的命名习惯。README 是产品页,细节在 `docs/`。深入阅读:[快速开始](docs/quickstart.md)、[架构](docs/architecture.md)、[安全](docs/security.md)、[FAQ](docs/faq.md)、[路线图](docs/roadmap.md)、[Grok Bot 灵感](docs/inspiration.md)、[MVP 计划](docs/mvp-plan.md)、[客户端计划](docs/client-plan.md)、[界面设计](docs/ui-design.md)、[Bot 人格](docs/bot-persona.md)、[本地文件设计](docs/local-file-design.md)、[平台需求](docs/platform-asks.md)。两份 README 必须在同一个 commit 里更新——英文版为准。 @@ -133,7 +133,7 @@ dsh plugin --profile web add /absolute/path/to/package # 之后重启 DSH;页面启动时会加载新的 Client 半区 ``` -- 检查:`node --check packages/dsh-rayrun-bots/index.js`、`node packages/dsh-rayrun-bots/test/manifest-check.mjs`、`node packages/dsh-rayrun-bots/test/locale-audit.mjs`、`node packages/dsh-rayrun-bots/test/rpc-contract.mjs`;同一组检查在 CI 里对 push 和 pull request 运行(`.github/workflows/checks.yml`)。 +- 检查:对 `packages/dsh-rayrun-bots/index.js` 和 `client.js` 做 `node --check`,然后跑 `node packages/dsh-rayrun-bots/test/manifest-check.mjs`、`locale-audit.mjs`、`rpc-contract.mjs` 和 `client-contract.mjs`;同一组检查在 CI 里对 push 和 pull request 运行(`.github/workflows/checks.yml`)。 - 实时集成测试需要真实 Rayrun 凭据,永远不在 CI 里跑。 - 改任何东西之前先读 [`CLAUDE.md`](CLAUDE.md) 和 [`CONTRIBUTING.md`](CONTRIBUTING.md)。提交信息用英文,前缀 `feat:`、`fix:`、`chore:`、`docs:`。 @@ -144,8 +144,8 @@ dsh plugin --profile web add /absolute/path/to/package | | | | --- | --- | | **今天可用**(独立项目,我们的依赖) | 7 个 `rayrun_*` 工具、noVNC 桌面、按会话的云/本地路由、双端哈希校验的 workspace 同步、任务委托、worker 投影、可选空闲停机。已在 DeepSeek Harness `0.2.1-rc.5` 上验证。 | -| **本仓库** | 仓库本身:README、docs、issue/PR 模板、agent 规则、依赖边界,以及 `dsh-rayrun-bots` 的 A1 骨架(占位页 + health 路由),带普通 Node 检查与只跑检查的 CI workflow。还没有 Bot 功能,也没有可发布版本。 | -| **尚未构建** | Bot 名册与 Bot↔session 映射、机器上的常驻 DSH host、远程审批、routines 与触发器、成本条、IM 通道、两插件安装路径(依赖声明与版本检查)、npm 包以及发布用的 CI 路径。 | +| **本仓库** | README、docs、issue/PR 模板、agent 规则、依赖边界,以及 `dsh-rayrun-bots`:一条 health 路由加上 v0.1 客户端界面(五个画面,内存里的预览),带普通 Node 检查与只跑检查的 CI workflow。还没有持久化的 Bot 层,也没有可发布版本。 | +| **尚未构建** | Bot 名册与 Bot↔session 映射、机器上的常驻 DSH host、能拦住 worker 的远程审批、真正会跑的 routines 与触发器、来自账号的实时用量、IM 通道、两插件安装路径(依赖声明与版本检查)、npm 包以及发布用的 CI 路径。 | | **平台缺口** | 安全入向网络(今天 token ingress 不可用,只有 `public` 能用)、空闲自动停、spend cap、session 续跑契约。完整清单在 [docs/architecture.md](docs/architecture.md)。 | **v0.1 路径**——从 npm 安装 → 登录 → 创建一个 Bot → 批准它的第一个受限动作。验收标准在 [docs/roadmap.md](docs/roadmap.md)。 diff --git a/docs/quickstart.md b/docs/quickstart.md index 9eab5ad..36cffc8 100644 --- a/docs/quickstart.md +++ b/docs/quickstart.md @@ -1,8 +1,9 @@ # Quickstart -*Status: 2026-11-13. Two separate projects. This repository is pre-alpha: it -holds docs, repository scaffolding and the `dsh-rayrun-bots` A1 skeleton, no -publishable code yet. The cloud-computer plugin at +*Status: 2026-11-16. Two separate projects. This repository is pre-alpha: it +holds docs, repository scaffolding, and `dsh-rayrun-bots` — a health route and +the v0.1 client shell. The shell is an in-memory preview. There is no +publishable release yet. The cloud-computer plugin at [RayrunOS/dsh-rayrun-computer](https://github.com/RayrunOS/dsh-rayrun-computer) is untouched and stays its own project; this repository builds the bot layer and reuses that plugin as an external dependency — two plugins in one DSH profile.* @@ -80,7 +81,10 @@ When the bot half lands, the first-run path should be: 4. Talk to it, or let a routine wake it up while you are away. 5. Approve its first gated action from the panel. -None of steps 1–5 exist yet in this repository. See +Installing this package and opening **Bots** shows the v0.1 shell. The roster, +the approval card, and the setup wizard on that page are in-memory preview +state: creating a bot does not put it on a cloud computer, and Allow once does +not send anything. Steps 2–5 do not reach Rayrun yet. See [roadmap.md](roadmap.md) for what each milestone needs. ## What works today vs what is still missing @@ -88,7 +92,7 @@ None of steps 1–5 exist yet in this repository. See | | | | --- | --- | | **Works today** (separate project) | the seven tools, noVNC desktop, per-session cloud/local routing, hash-verified workspace sync, task delegation, worker projection, optional idle stop; verified on DSH `0.2.1-rc.5` | -| **This repository** | README, docs, issue/PR templates, agent rules, and the `dsh-rayrun-bots` A1 skeleton with plain-Node checks and a checks-only CI workflow. No publishable code. | +| **This repository** | README, docs, issue/PR templates, agent rules, and `dsh-rayrun-bots`: a health route plus the v0.1 client shell (in-memory preview), with plain-Node checks and a checks-only CI workflow. No publishable release. | | **Planned, unverified** | two-plugin install: the Rayrun Bot bundle declares `dsh-rayrun-computer` as a dependency so one install loads both host and client halves (W0 spike S6) | | **Not built yet** | bot roster and bot↔session mapping, a persistent DSH host on the machine, remote approvals, routines and triggers, cost bar, IM channel, npm packages and the release/publish CI path | | **Blocked on the Rayrun platform** | safe inbound networking (the token ingress is unusable today and only `public` works), idle auto-stop, a spend cap, the session-resume contract | diff --git a/packages/dsh-rayrun-bots/README.md b/packages/dsh-rayrun-bots/README.md index fe6eb52..9155005 100644 --- a/packages/dsh-rayrun-bots/README.md +++ b/packages/dsh-rayrun-bots/README.md @@ -1,8 +1,8 @@ # dsh-rayrun-bots -The Rayrun Bot plugin package. Status: **A1 skeleton** — the bundle loads, the -client half adds a "Bots" entry with a placeholder page, and the host half answers -one health action. There is no bot layer yet. +The Rayrun Bot plugin package. Status: **client shell** — the bundle loads, the +client half renders the v0.1 screens, and the host half answers one health +action. The screens are an in-memory preview. There is no bot layer yet. ## What it does today @@ -10,11 +10,16 @@ one health action. There is no bot layer yet. `{ ok: true, plugin: "rayrun-bots", version, ready: false }`. `POST` is same-origin gated: a browser `Origin` that does not match the request `Host` is refused with 403. No credentials are touched. -- Client half: a `Bots` sidebar entry and a placeholder page. It does not call - the host yet. +- Client half: a `Bots` sidebar entry and the three-column shell from + [docs/ui-design.md](../../docs/ui-design.md) — chat list, conversation, + details (Activity / Library), new bot, the four-step setup wizard, and + settings. Sample bots, messages, receipts, and the approval card live in the + page only. Deny / Allow once, creating a bot, the wizard, and settings update + that in-memory state. The page does not call the host, and it does not keep a + Rayrun token or a DeepSeek key. -Not built yet: bot roster, chat list, conversation, details panel, approvals, -routines, the adapter to `dsh-rayrun-computer`, and the npm release path. See the +Not built yet: a real bot roster, bot↔session mapping, remote approvals, routines +that run, the adapter to `dsh-rayrun-computer`, and the npm release path. See the repo-level [MVP plan](../../docs/mvp-plan.md) and [client plan](../../docs/client-plan.md). ## Install from a checkout @@ -39,6 +44,7 @@ node --check client.js node test/manifest-check.mjs node test/locale-audit.mjs node test/rpc-contract.mjs +node test/client-contract.mjs ``` The same commands run in the repository's checks-only CI workflow on push and @@ -51,7 +57,7 @@ Live integration tests need real Rayrun credentials and never run in CI. package.json # name, exports, dsh.bundle + dsh.client cordis.patch.yml # the bundle row (id rayrun-bots -> package dsh-rayrun-bots) index.js # host half: same-origin RPC route, health action only -client.js # client half: sidebar "Bots" + placeholder page +client.js # client half: v0.1 shell (in-memory preview) lib/errors.js # stable error codes (shared with docs/mvp-plan.md §4.3) lib/rpc.js # JSON responses and request-body parsing locale/en.json # source copy diff --git a/packages/dsh-rayrun-bots/client.js b/packages/dsh-rayrun-bots/client.js index f92f39a..c1ff4bc 100644 --- a/packages/dsh-rayrun-bots/client.js +++ b/packages/dsh-rayrun-bots/client.js @@ -1,95 +1,2034 @@ /** * Client half of the Rayrun Bot bundle. * - * A1 skeleton: adds a "Bots" entry to the Harness sidebar and a placeholder - * page. It reads nothing from the host yet (the only host action is `health`); - * the real chat list, conversation and details panel will replace this page. + * v0.1 shell: chat list, conversation, details, new bot, setup, and settings, + * in the layout of docs/ui-design.md and docs/mockups/index.html. Copy comes + * from locale/en.json and locale/zh.json (embedded below; the locale audit + * checks they match). The bot host is still health-only, so every bot, message, + * approval, and setting on this page is in-memory preview state. Decisions are + * not sent to a worker and nothing is saved. */ window.__ModuleLoader__.load({ id: 'dsh-rayrun-bots', factory(require) { const React = require('react') const h = React.createElement + const { useEffect, useRef, useState } = React + + const EN = { + "panel": { + "label": "Bots" + }, + "brand": "Rayrun Bot", + "list": { + "search": "Search", + "searchPlaceholder": "Search bots", + "newBot": "New bot", + "settings": "Settings", + "empty": "No matching bots" + }, + "attention": { + "needs": "needs attention", + "unread": "unread", + "working": "working" + }, + "approval": { + "title": "Needs approval", + "allowOnce": "Allow once", + "deny": "Deny", + "waits": "waits for you", + "expires": "expires in {n} min", + "expired": "Expired — the bot did not act", + "irreversible": "This can't be undone.", + "outside": "This shares data outside your computer.", + "warning": "This shares data outside your computer, and it can't be undone.", + "allowedLocal": "Allowed once, on this page only. Nothing was sent.", + "deniedLocal": "Denied, on this page only. Nothing was sent.", + "snippetAllowed": "Allowed once — not sent", + "snippetDenied": "Denied — not sent" + }, + "draft": { + "send": "Send", + "discard": "Discard" + }, + "details": { + "activity": "Activity", + "library": "Library", + "recent": "Recent", + "recentEmpty": "Nothing recent.", + "upcoming": "Upcoming", + "computer": "Computer", + "usage": "Usage", + "jobComputer": "{job} · {computer}" + }, + "receipt": { + "ready": "Ready", + "waiting": "Waiting", + "done": "Done" + }, + "library": { + "today": "Today", + "week": "This week", + "older": "Older", + "empty": "No artifacts yet." + }, + "routine": { + "empty": "No routines yet.", + "on": "on", + "off": "off" + }, + "computer": { + "live": "live", + "reconnecting": "reconnecting…", + "unreachable": "Couldn't reach the computer.", + "sleeping": "sleeping", + "takeOver": "Take over", + "open": "Open", + "view": "View", + "onComputer": "On the computer · {where}", + "desktopLater": "The desktop opens in the cloud-computer plugin. This page can't open it yet." + }, + "notice": { + "recovering": "The bot host is restarting. This conversation resumes on its own.", + "reconnecting": "Computer reconnecting… retrying in 5s", + "attach": "Attachments aren't available in this preview.", + "preview": "In-memory preview. Nothing on this page is saved, and approvals are not sent to a worker." + }, + "composer": { + "placeholder": "Message {name}…", + "attach": "Add attachment", + "send": "Send" + }, + "usage": { + "balanceLine": "Balance {balance} · {hours} machine-hours", + "weekLine": "This week {spend} · idle stop {idle}", + "sampleBalance": "¥41.20", + "sampleHours": "38.4", + "sampleSpend": "¥6.80" + }, + "cost": { + "low": "Balance is low — top up in the Rayrun console. Stop is safe; destroy is not." + }, + "empty": { + "heading": "No bots yet", + "body": "Create one with the plus button. It stays on this page until a bot host exists.", + "thread": "No messages yet. What you type stays on this page.", + "snippet": "No messages yet" + }, + "newBot": { + "title": "New bot", + "sub": "Give it a name and one job. Instructions can be changed later.", + "monogramHint": "Letter avatar · color is assigned from the name", + "name": "Name", + "job": "Job, one line", + "instructions": "Instructions, optional", + "placeholder": "You are {name}, a teammate on the user's team. Your job: …", + "defaultName": "Weekly Watch", + "defaultJob": "Summarises weekly PRs and drafts the digest", + "cancel": "Cancel", + "create": "Create bot" + }, + "persona": { + "template": "You are {name}, a teammate on the user's team.\nYour job: {job}.\nWork in short, factual updates. Say what you did, what you did not do, and what you need next. Ask before any action that leaves this computer (messages, publishing, spending, another machine). Never claim work you have not verified.\nIf something is unclear, ask one question instead of guessing." + }, + "setup": { + "title": "Set up Rayrun Bot", + "sub": "Four steps. Each one says what is missing and where to fix it.", + "back": "Back", + "skip": "Skip for now", + "continue": "Continue", + "steps": { + "dependency": "Dependency", + "rayrun": "Rayrun", + "key": "DeepSeek key", + "bot": "First bot" + }, + "dependencyTitle": "Cloud-computer plugin", + "dependencyBody": "Cloud computers come from the separate dsh-rayrun-computer plugin. This page cannot see whether it is installed.", + "dependencyStatus": "Not checked", + "rayrunTitle": "Connect Rayrun", + "rayrunBody": "The cloud computer is provided by Rayrun. Sign in with your own account. The token stays in the DSH vault.", + "signIn": "Sign in with Rayrun", + "notConnected": "Not connected", + "tokenPlaceholder": "…or paste a Rayrun API token", + "connect": "Connect", + "accountLine": "Account: — · Balance: —", + "signInLater": "Sign-in lives in the cloud-computer plugin. This page can't start it, and it does not store a token.", + "tokenIgnored": "That token was not saved. This page never keeps it, and the bot host cannot store one yet.", + "keyTitle": "DeepSeek key", + "keyBody": "Rayrun injects the key into the agent process. It does not go into the workspace, and this page never stores it.", + "keyPlaceholder": "…or paste a DeepSeek API key", + "keySave": "Save", + "keyIgnored": "That key was not saved. This page never keeps a DeepSeek key.", + "botTitle": "First bot", + "botBody": "Give it a name and one job. It is added to this page only, not to a cloud computer." + }, + "settings": { + "title": "Settings", + "sub": "Account, usage, and the few settings this plugin owns.", + "account": "Account", + "usage": "Usage", + "notifications": "Notifications", + "appearance": "Appearance", + "rayrunAccount": "Rayrun account", + "rayrunHint": "Token stays in the DSH vault · host side only", + "connected": "Connected", + "plugin": "Cloud-computer plugin", + "pluginHint": "dsh-rayrun-computer v1.0.0", + "pluginOk": "OK", + "idle": "Idle stop", + "idleHint": "Stop the computer when idle. Never destroy it.", + "idle15": "15 minutes", + "idle30": "30 minutes", + "idleOff": "Off", + "lowBalance": "Low-balance reminder", + "lowBalanceHint": "Show a notice when the balance drops below this.", + "notify": "Notifications", + "notifyHint": "Notify when a bot finishes or needs you.", + "language": "Language", + "languageHint": "English or 简体中文", + "langEn": "English", + "langZh": "简体中文" + }, + "sample": { + "user": { + "name": "Haoyi", + "initials": "HY", + "foot": "Rayrun connected · {balance}" + }, + "nora": { + "name": "Nora", + "job": "weekly digest", + "snippet": "Draft is in the library, waiting for you", + "time": "20:07", + "user": "Summarize last week's PRs and draft the weekly digest. Wait for me before publishing.", + "day": "Today 20:07", + "reply1": "The draft is ready. I kept it to five sections, and each item links back to its PR.\n\n- **Scope.** 14 merged PRs, 2 still open, 1 reverted.\n- **Draft.** `week-45-digest.md` in the workspace, 420 words.\n- **Next.** Publishing to `#weekly` needs your approval.", + "reply2": "The draft is in the Library tab if you want to read it first. I'll wait for your answer.", + "computerTitle": "On the computer · Feishu #weekly", + "computerSub": "Pasted the digest, waiting for your approval", + "approvalTitle": "Publish “Week 45 digest” to Feishu #weekly", + "approvalMeta": "Requested 20:07 · from this chat", + "r1": "Draft the weekly digest", + "r1meta": "09:13 · 3 artifacts · today ¥3.10", + "r2": "Publish to #weekly", + "r2meta": "Needs your approval · waits for you", + "r3": "Docs refresh", + "r3meta": "08:40 · 3 pages · today ¥0.60", + "f1": "week-45-digest.md", + "f1badge": "420 words", + "f1meta": "Created by Nora · 09:13", + "f2": "channel-preview.png", + "f2badge": "Image", + "f2meta": "Sent in this chat · 09:12", + "f3": "week-44-digest.md", + "f3badge": "Done", + "f3meta": "Created by Nora · Monday", + "f4": "Feishu channel", + "f4badge": "Link", + "f4meta": "Last week" + }, + "eli": { + "name": "Eli", + "job": "channel publish", + "snippet": "Needs approval: publish the digest", + "time": "09:13", + "day": "Today 09:13", + "reply": "Publishing would send the digest to the channel. I'm stopped here until you approve.", + "approvalTitle": "Publish “Week 45 digest” to Feishu #weekly", + "approvalMeta": "Requested 09:13 · from this chat" + }, + "june": { + "name": "June", + "job": "docs", + "snippet": "Docs refresh finished — 3 pages", + "time": "08:40", + "day": "Today 08:40", + "reply": "Docs refresh is finished, 3 pages. Nothing needs your approval.", + "r1": "Docs refresh", + "r1meta": "08:40 · 3 pages · today ¥0.60" + }, + "routine": { + "weekly": "Weekly digest", + "weeklyWhen": "Friday · 09:00", + "inbox": "Inbox sweep", + "inboxWhen": "Weekdays · 08:00", + "standup": "Standup notes", + "standupWhen": "Weekdays · 18:00" + }, + "computerName": "dsh-workspace" + }, + "error": { + "hostDown": "The bot host is not responding." + } +} + const ZH = { + "panel": { + "label": "Bots" + }, + "brand": "Rayrun Bot", + "list": { + "search": "搜索", + "searchPlaceholder": "搜索 Bot", + "newBot": "新建 Bot", + "settings": "设置", + "empty": "没有匹配的 Bot" + }, + "attention": { + "needs": "待你处理", + "unread": "未读", + "working": "工作中" + }, + "approval": { + "title": "需要审批", + "allowOnce": "仅批准这一次", + "deny": "拒绝", + "waits": "等你处理", + "expires": "{n} 分钟后过期", + "expired": "已过期——Bot 没有执行", + "irreversible": "此操作无法撤销。", + "outside": "这会把数据发到你的电脑之外。", + "warning": "这会把数据发到你的电脑之外,且无法撤销。", + "allowedLocal": "只记在这一页:已批准一次。没有发送到任何地方。", + "deniedLocal": "只记在这一页:已拒绝。没有发送到任何地方。", + "snippetAllowed": "已批准一次 · 未发送", + "snippetDenied": "已拒绝 · 未发送" + }, + "draft": { + "send": "发送", + "discard": "丢弃" + }, + "details": { + "activity": "动态", + "library": "资料库", + "recent": "最近", + "recentEmpty": "最近没有动态。", + "upcoming": "即将进行", + "computer": "电脑", + "usage": "用量", + "jobComputer": "{job} · {computer}" + }, + "receipt": { + "ready": "已就绪", + "waiting": "等待中", + "done": "已完成" + }, + "library": { + "today": "今天", + "week": "本周", + "older": "更早", + "empty": "还没有产物。" + }, + "routine": { + "empty": "还没有日程。", + "on": "开", + "off": "关" + }, + "computer": { + "live": "在线", + "reconnecting": "正在重连…", + "unreachable": "连不上电脑。", + "sleeping": "休眠", + "takeOver": "接管", + "open": "打开", + "view": "查看", + "onComputer": "电脑上 · {where}", + "desktopLater": "桌面在云电脑插件里。这一页还打不开它。" + }, + "notice": { + "recovering": "Bot host 正在重启,这个会话会自动恢复。", + "reconnecting": "电脑正在重连… 5 秒后重试", + "attach": "这个预览里还不能添加附件。", + "preview": "这是页内预览。内容不会保存,审批也不会发给 worker。" + }, + "composer": { + "placeholder": "给 {name} 发消息…", + "attach": "添加附件", + "send": "发送" + }, + "usage": { + "balanceLine": "余额 {balance} · {hours} 机时", + "weekLine": "本周 {spend} · 空闲停机 {idle}", + "sampleBalance": "¥41.20", + "sampleHours": "38.4", + "sampleSpend": "¥6.80" + }, + "cost": { + "low": "余额偏低——去 Rayrun 控制台充值。停机会保留磁盘,销毁不会。" + }, + "empty": { + "heading": "还没有 Bot", + "body": "用加号新建一个。在 Bot host 出现之前,它只留在这一页。", + "thread": "还没有消息。你输入的内容只留在这一页。", + "snippet": "还没有消息" + }, + "newBot": { + "title": "新建 Bot", + "sub": "给它一个名字和一项职责,指令之后可以再改。", + "monogramHint": "字母头像 · 颜色由名字自动分配", + "name": "名字", + "job": "职责(一行)", + "instructions": "指令(可选)", + "placeholder": "你是 {name},用户团队里的一名同事。你的职责: …", + "defaultName": "Weekly Watch", + "defaultJob": "Summarises weekly PRs and drafts the digest", + "cancel": "取消", + "create": "创建 Bot" + }, + "persona": { + "template": "你是 {name},用户团队里的一名同事。\n你的职责:{job}。\n用简短、事实性的更新汇报:做了什么、没做什么、下一步需要什么。任何离开这台电脑的动作(发消息、发布、花钱、动另一台机器)先征求同意。不要声称未经验证的结果。不清楚时只问一个关键问题,不要猜。" + }, + "setup": { + "title": "设置 Rayrun Bot", + "sub": "四步。每一步都会显示还缺什么、去哪里补。", + "back": "返回", + "skip": "暂时跳过", + "continue": "继续", + "steps": { + "dependency": "依赖", + "rayrun": "Rayrun", + "key": "DeepSeek key", + "bot": "第一个 Bot" + }, + "dependencyTitle": "检查云电脑插件", + "dependencyBody": "云电脑由单独的 dsh-rayrun-computer 插件提供。这一页还不能检查它是否已安装。", + "dependencyStatus": "未检查", + "rayrunTitle": "连接 Rayrun", + "rayrunBody": "云电脑由 Rayrun 提供。用你自己的账号登录,token 只存在 DSH 凭证库里。", + "signIn": "用 Rayrun 登录", + "notConnected": "未连接", + "tokenPlaceholder": "…或粘贴 Rayrun API token", + "connect": "连接", + "accountLine": "账号:— · 余额:—", + "signInLater": "登录在云电脑插件里完成。这一页不能替你开始,也不会保存 token。", + "tokenIgnored": "没有保存这个 token。这一页不留存它,Bot host 也还不能代存。", + "keyTitle": "DeepSeek key", + "keyBody": "key 由 Rayrun 注入到 agent 进程,不会进入工作区。这一页不保存 key。", + "keyPlaceholder": "…或粘贴 DeepSeek API key", + "keySave": "保存", + "keyIgnored": "没有保存这个 key。这一页不留存 DeepSeek key。", + "botTitle": "第一个 Bot", + "botBody": "给它一个名字和一项职责。它只加到这一页,不会出现在云电脑上。" + }, + "settings": { + "title": "设置", + "sub": "账号、用量,以及这个插件自己的少量设置。", + "account": "账号", + "usage": "用量", + "notifications": "通知", + "appearance": "外观", + "rayrunAccount": "Rayrun 账号", + "rayrunHint": "token 存在 DSH 凭证库 · 只在 Host 侧", + "connected": "已连接", + "plugin": "云电脑插件", + "pluginHint": "dsh-rayrun-computer v1.0.0", + "pluginOk": "正常", + "idle": "空闲停机", + "idleHint": "空闲时停止电脑,绝不销毁。", + "idle15": "15 分钟", + "idle30": "30 分钟", + "idleOff": "关闭", + "lowBalance": "低余额提醒", + "lowBalanceHint": "余额低于该值时显示提示。", + "notify": "通知", + "notifyHint": "Bot 完成或等你处理时通知。", + "language": "语言", + "languageHint": "English 或 简体中文", + "langEn": "English", + "langZh": "简体中文" + }, + "sample": { + "user": { + "name": "Haoyi", + "initials": "HY", + "foot": "Rayrun 已连接 · {balance}" + }, + "nora": { + "name": "Nora", + "job": "每周摘要", + "snippet": "草稿在资料库里,等你答复", + "time": "20:07", + "user": "总结上周的 PR,并起草每周摘要。发布前等我确认。", + "day": "今天 20:07", + "reply1": "草稿好了。我控制在五个小节,每一项都链回了对应 PR。\n\n- **范围。**14 个已合并 PR,2 个仍开着,1 个已回滚。\n- **草稿。**工作区里的 `week-45-digest.md`,420 字。\n- **下一步。**发布到 `#weekly` 需要你批准。", + "reply2": "如果你想先看草稿,它在「资料库」标签里。我会等你答复。", + "computerTitle": "电脑上 · Feishu #weekly", + "computerSub": "已粘贴摘要,等待你的审批", + "approvalTitle": "发布《Week 45 摘要》到 Feishu #weekly", + "approvalMeta": "请求于 20:07 · 来自本对话", + "r1": "起草每周摘要", + "r1meta": "09:13 · 3 个产物 · 今日 ¥3.10", + "r2": "发布到 #weekly", + "r2meta": "需要你的审批 · 等你处理", + "r3": "文档刷新", + "r3meta": "08:40 · 3 页 · 今日 ¥0.60", + "f1": "week-45-digest.md", + "f1badge": "420 字", + "f1meta": "由 Nora 创建 · 09:13", + "f2": "channel-preview.png", + "f2badge": "图片", + "f2meta": "本对话中发送 · 09:12", + "f3": "week-44-digest.md", + "f3badge": "已完成", + "f3meta": "由 Nora 创建 · 周一", + "f4": "Feishu 频道", + "f4badge": "链接", + "f4meta": "上周" + }, + "eli": { + "name": "Eli", + "job": "频道发布", + "snippet": "待审批:发布摘要", + "time": "09:13", + "day": "今天 09:13", + "reply": "发布会把摘要发到频道里,我停在这里等你批准。", + "approvalTitle": "发布《Week 45 摘要》到 Feishu #weekly", + "approvalMeta": "请求于 09:13 · 来自本对话" + }, + "june": { + "name": "June", + "job": "文档", + "snippet": "文档刷新完成 — 3 页", + "time": "08:40", + "day": "今天 08:40", + "reply": "文档刷新完成,一共 3 页。没有需要你批准的动作。", + "r1": "文档刷新", + "r1meta": "08:40 · 3 页 · 今日 ¥0.60" + }, + "routine": { + "weekly": "每周摘要", + "weeklyWhen": "周五 · 09:00", + "inbox": "收件箱清扫", + "inboxWhen": "工作日 · 08:00", + "standup": "站会纪要", + "standupWhen": "工作日 · 18:00" + }, + "computerName": "dsh-workspace" + }, + "error": { + "hostDown": "Bot host 没有响应。" + } +} const PANEL_ID = 'rayrun-bots' + const SAMPLE_COMPUTER = 'dsh-workspace' + const MARK_PATHS = [ + 'M2.97 12.92A2 2 0 0 0 2 14.63v3.24a2 2 0 0 0 .97 1.71l3 1.8a2 2 0 0 0 2.06 0L12 19v-5.5l-5-3-4.03 2.42Z', + 'm7 16.5-4.74-2.85', + 'm7 16.5 5-3', + 'M7 16.5v5.17', + 'M12 13.5V19l3.97 2.38a2 2 0 0 0 2.06 0l3-1.8a2 2 0 0 0 .97-1.71v-3.24a2 2 0 0 0-.97-1.71L17 10.5l-5 3Z', + 'm17 16.5-5-3', + 'm17 16.5 4.74-2.85', + 'M17 16.5v5.17', + 'M7.97 4.42A2 2 0 0 0 7 6.13v4.37l5 3 5-3V6.13a2 2 0 0 0-.97-1.71l-3-1.8a2 2 0 0 0-2.06 0l-3 1.8Z', + 'M12 8 7.26 5.15', + 'm12 8 4.74-2.85', + 'M12 13.5V8', + ] + const AVATAR_PALETTE = [ + ['#1d4ed8', '#e3eafc'], + ['#1e40af', '#e7eefc'], + ['#3730a3', '#ecebfe'], + ['#0f766e', '#e7f4f2'], + ['#9a3412', '#f8eee8'], + ] + const PINNED_AVATARS = new Set(['Nora', 'Eli', 'June', 'Weekly Watch', 'Haoyi']) - const styles = { - page: { - display: 'flex', - flexDirection: 'column', - gap: '10px', - padding: '28px 32px', - maxWidth: '720px', - color: 'var(--dsw-alias-text-1, #0f172a)', - }, - title: { - margin: 0, - fontSize: '18px', - fontWeight: 650, - }, - body: { - margin: 0, - fontSize: '13px', - lineHeight: 1.6, - color: 'var(--dsw-alias-text-2, #5b6472)', - }, - card: { - border: '1px solid var(--dsw-alias-border-l1, #e4e8f0)', - borderRadius: '10px', - padding: '14px 16px', - background: 'var(--dsw-alias-bg-layer-1, #ffffff)', - }, - code: { - fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Consolas, monospace', - fontSize: '12px', - background: 'var(--dsw-alias-bg-layer-2, #f1f4f9)', - borderRadius: '4px', - padding: '1px 4px', - }, + const CSS = ` +.rb-frame, .rb-frame *, .rb-frame *::before, .rb-frame *::after { box-sizing: border-box; } +.rb-frame { height: 100%; min-height: 680px; display: flex; flex-direction: column; background: #fff; color: #0f172a; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif; font-size: 14px; line-height: 1.55; -webkit-font-smoothing: antialiased; } +.rb-frame button, .rb-frame input, .rb-frame textarea, .rb-frame select { font: inherit; color: inherit; } +.rb-frame button.rb-icon { color: #5b6472; } +.rb-frame button.rb-send { color: #fff; } +.rb-frame button.rb-tab { color: #8a93a3; } +.rb-frame button.rb-tab.rb-active { color: #0e2050; } +.rb-frame button.rb-textbtn { color: #8a93a3; } +.rb-frame .rb-snav button { color: #8a93a3; } +.rb-frame .rb-snav button.rb-active { color: #0e2050; } +.rb-frame button { cursor: pointer; } +.rb-frame :focus { outline: none; } +.rb-frame :focus-visible { outline: 2px solid #1d4ed8; outline-offset: 2px; } +.rb-frame ::-webkit-scrollbar { width: 9px; } +.rb-frame ::-webkit-scrollbar-thumb { background: #d5dbe6; border-radius: 5px; } +.rb-app { flex: 1; min-height: 0; display: grid; overflow: hidden; } +.rb-sr { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; } +.rb-list { background: #f7f8fa; border-right: 1px solid #eef1f6; display: flex; flex-direction: column; min-height: 0; min-width: 0; } +.rb-list-top { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 8px; gap: 8px; } +.rb-brand { display: flex; align-items: center; gap: 8px; color: #0e2050; font-weight: 650; font-size: 13px; min-width: 0; } +.rb-mark { flex: none; } +.rb-tools { display: flex; gap: 4px; } +.rb-icon { width: 28px; height: 28px; border: 0; border-radius: 8px; background: transparent; color: #5b6472; display: grid; place-items: center; padding: 0; } +.rb-icon:hover { background: #eef2f8; color: #0f172a; } +.rb-search { margin: 0 16px 8px; } +.rb-search input { width: 100%; background: #fff; border: 1px solid #e4e8f0; border-radius: 9px; padding: 6px 10px; font-size: 13px; } +.rb-current { display: grid; justify-items: center; gap: 5px; padding: 6px 16px 16px; text-align: center; } +.rb-avatar { border-radius: 50%; display: grid; place-items: center; font-weight: 600; color: #1d4ed8; background: #e3eafc; flex: none; } +.rb-avatar.rb-big { width: 52px; height: 52px; font-size: 18px; } +.rb-avatar.rb-mid { width: 34px; height: 34px; font-size: 12px; } +.rb-avatar.rb-sm { width: 26px; height: 26px; font-size: 10px; } +.rb-avatar.rb-new { width: 38px; height: 38px; font-size: 13px; } +.rb-current .rb-name, .rb-profile .rb-name { font-size: 15px; font-weight: 600; } +.rb-current .rb-label, .rb-profile .rb-sub { color: #8a93a3; font-size: 11.5px; } +.rb-profile .rb-sub { font-size: 11px; } +.rb-chats { overflow: auto; padding: 2px 10px 10px; display: flex; flex-direction: column; gap: 1px; min-height: 0; } +.rb-row { display: grid; grid-template-columns: 34px minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 8px 9px; border: 0; border-radius: 10px; background: transparent; text-align: left; width: 100%; } +.rb-row:hover { background: #eef2f8; } +.rb-row.rb-active { background: #eaf1fd; } +.rb-nm { font-size: 13px; font-weight: 500; display: flex; align-items: center; gap: 6px; } +.rb-sn { color: #8a93a3; font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } +.rb-tm { color: #8a93a3; font-size: 10.5px; } +.rb-dot { width: 6px; height: 6px; border-radius: 50%; background: #8a93a3; flex: none; display: inline-block; } +.rb-dot.rb-needs { background: #b45309; } +.rb-dot.rb-working { background: #15803d; } +.rb-dot.rb-unread { background: #5b7fc4; } +.rb-foot { margin-top: auto; border-top: 1px solid #eef1f6; padding: 10px 14px; display: flex; align-items: center; gap: 9px; } +.rb-who { flex: 1; font-size: 12px; min-width: 0; } +.rb-who small { display: block; color: #8a93a3; font-size: 10.5px; } +.rb-textbtn { border: 0; background: transparent; padding: 0; color: #8a93a3; font-size: 10.5px; text-align: left; } +.rb-textbtn:hover { color: #0f172a; } +.rb-empty-list { color: #8a93a3; font-size: 12px; padding: 8px 10px; } +.rb-main { background: #fff; display: flex; flex-direction: column; min-width: 0; min-height: 0; } +.rb-thread { flex: 1; overflow: auto; padding: 26px 34px 12px; display: flex; flex-direction: column; gap: 20px; } +.rb-thread > * { max-width: 760px; width: 100%; align-self: center; } +.rb-day { text-align: center; color: #8a93a3; font-size: 10.5px; margin: 4px 0 2px; } +.rb-msg { display: grid; grid-template-columns: 28px minmax(0, 1fr); gap: 12px; } +.rb-msg-avatar { margin-top: 2px; } +.rb-msg .rb-body { min-width: 0; } +.rb-msg .rb-who-line { font-size: 11.5px; color: #5b6472; margin-bottom: 3px; display: flex; gap: 8px; align-items: baseline; } +.rb-msg .rb-who-line b { color: #0f172a; font-weight: 600; font-size: 12.5px; } +.rb-msg p { margin: 0 0 9px; } +.rb-msg p:last-child { margin-bottom: 0; } +.rb-msg ul { margin: 0 0 9px; padding-left: 18px; } +.rb-msg li { margin-bottom: 3px; } +.rb-msg code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; background: #eef2f8; border-radius: 4px; padding: 1px 4px; } +.rb-msg.rb-user { grid-template-columns: minmax(0, 1fr); justify-items: end; } +.rb-bubble { background: #f1f4f9; border-radius: 12px; padding: 8px 13px; max-width: 560px; font-size: 13.5px; overflow-wrap: anywhere; } +.rb-card { border: 1px solid #e4e8f0; background: #fff; border-radius: 12px; padding: 13px 15px; display: grid; gap: 8px; } +.rb-card-top { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; } +.rb-card-title { font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 6px; min-width: 0; } +.rb-warn { color: #b45309; } +.rb-m { color: #8a93a3; font-size: 10.5px; white-space: nowrap; } +.rb-warnline { color: #b42318; font-size: 11.5px; } +.rb-meta { color: #8a93a3; font-size: 10.5px; } +.rb-result { color: #5b6472; font-size: 12.5px; } +.rb-actions { display: flex; justify-content: flex-end; gap: 8px; padding-top: 2px; } +.rb-btn { border: 1px solid #e4e8f0; background: #fff; color: #0f172a; border-radius: 9px; padding: 5px 12px; font-size: 12.5px; font-weight: 500; } +.rb-btn:hover { background: #f5f7fb; } +.rb-btn.rb-primary { background: #0e2050; border-color: #0e2050; color: #fff; } +.rb-btn.rb-primary:hover { background: #16306e; } +.rb-btn.rb-ghost { border-color: transparent; background: transparent; color: #5b6472; } +.rb-btn.rb-ghost:hover { color: #0f172a; background: #eef2f8; } +.rb-btn:disabled { opacity: .45; cursor: not-allowed; } +.rb-notice { margin: 0 34px 8px; max-width: 760px; align-self: center; width: 100%; color: #b45309; font-size: 11.5px; display: flex; gap: 7px; align-items: center; } +.rb-composer { max-width: 760px; width: 100%; align-self: center; display: flex; align-items: center; gap: 8px; border: 1px solid #e4e8f0; background: #fff; border-radius: 14px; padding: 7px 8px 7px 10px; margin: 0 34px 18px; } +.rb-composer input { flex: 1; border: 0; outline: 0; background: transparent; font-size: 13.5px; min-width: 0; } +.rb-composer input:focus { outline: none; } +.rb-composer input::placeholder { color: #8a93a3; } +.rb-send { width: 30px; height: 30px; border-radius: 50%; border: 0; background: #0e2050; color: #fff; font-size: 13px; display: grid; place-items: center; padding: 0; flex: none; } +.rb-send:hover { background: #16306e; } +.rb-detail { background: #f7f8fa; border-left: 1px solid #eef1f6; display: flex; flex-direction: column; min-height: 0; min-width: 0; overflow: auto; } +.rb-profile { display: grid; justify-items: center; gap: 5px; padding: 22px 16px 12px; text-align: center; } +.rb-tabs { display: flex; justify-content: center; gap: 22px; border-bottom: 1px solid #eef1f6; padding: 4px 16px 0; } +.rb-tab { border: 0; background: transparent; color: #8a93a3; font-size: 12px; padding: 7px 0 9px; border-bottom: 1.5px solid transparent; } +.rb-tab.rb-active { color: #0e2050; border-bottom-color: #1d4ed8; } +.rb-computer-act { display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; gap: 10px; align-items: center; border: 1px solid #e4e8f0; background: #fff; border-radius: 10px; padding: 8px 10px; } +.rb-computer-act .rb-t, .rb-computer .rb-nm { font-size: 12px; } +.rb-computer-act .rb-s, .rb-computer .rb-st, .rb-act .rb-s, .rb-routine .rb-s { color: #8a93a3; font-size: 10.5px; } +.rb-sections { padding: 14px 16px 24px; display: grid; gap: 20px; } +.rb-sec h3 { margin: 0 0 8px; color: #8a93a3; font-size: 10px; font-weight: 500; letter-spacing: .08em; text-transform: uppercase; } +.rb-act { background: #fff; border: 1px solid #e4e8f0; border-radius: 10px; padding: 10px 12px; display: grid; gap: 4px; margin-bottom: 7px; } +.rb-act .rb-t { font-size: 12px; font-weight: 600; display: flex; justify-content: space-between; gap: 8px; } +.rb-ok { color: #15803d; font-weight: 500; font-size: 11px; white-space: nowrap; } +.rb-routine { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 7px 0; border-bottom: 1px solid #eef1f6; } +.rb-routine:last-child { border-bottom: 0; } +.rb-routine .rb-t { font-size: 12px; } +.rb-toggle { width: 34px; height: 19px; border-radius: 10px; border: 0; background: #cbd5e1; position: relative; flex: none; padding: 0; } +.rb-toggle::after { content: ""; position: absolute; top: 2px; left: 2px; width: 15px; height: 15px; border-radius: 50%; background: #fff; transition: left .12s; } +.rb-toggle.rb-on { background: #0e2050; } +.rb-toggle.rb-on::after { left: 17px; } +.rb-computer { display: grid; gap: 8px; } +.rb-comp-row { display: flex; align-items: center; gap: 9px; } +.rb-thumb { width: 44px; height: 30px; border-radius: 5px; background: #0b1b3a; border: 1px solid #e4e8f0; position: relative; overflow: hidden; flex: none; } +.rb-thumb::before { content: ""; position: absolute; inset: 18% 46% 18% 8%; background: #14285a; border-radius: 2px; } +.rb-thumb::after { content: ""; position: absolute; inset: 28% 8% 22% 58%; background: #22407f; border-radius: 2px; } +.rb-comp-acts { display: flex; justify-content: flex-end; gap: 6px; } +.rb-comp-acts .rb-btn { padding: 4px 9px; font-size: 11px; } +.rb-usage { color: #5b6472; font-size: 12px; display: grid; gap: 3px; } +.rb-usage b { color: #0f172a; font-weight: 600; } +.rb-low { color: #b45309; font-size: 12px; } +.rb-faint { color: #8a93a3; font-size: 11px; } +.rb-page { background: #fff; overflow: auto; display: flex; flex-direction: column; min-height: 0; min-width: 0; } +.rb-wizard-wrap { min-height: 100%; display: grid; place-items: center; padding: 40px 20px; } +.rb-wizard { width: 480px; max-width: 100%; } +.rb-wizard h1, .rb-page-inner h1 { margin: 0 0 4px; font-size: 18px; font-weight: 650; } +.rb-wizard .rb-sub { color: #8a93a3; margin: 0 0 24px; font-size: 11.5px; } +.rb-steps { display: flex; gap: 6px; margin-bottom: 24px; } +.rb-step { flex: 1; display: grid; gap: 5px; } +.rb-bar { height: 2px; border-radius: 1px; background: #e4e8f0; } +.rb-step.rb-done .rb-bar { background: #b6c2d6; } +.rb-step.rb-current .rb-bar { background: #0f172a; } +.rb-lbl { font-size: 10px; color: #8a93a3; } +.rb-step.rb-current .rb-lbl { color: #0f172a; } +.rb-wizard h2 { margin: 0 0 6px; font-size: 14px; font-weight: 600; } +.rb-say { color: #5b6472; margin: 0 0 16px; font-size: 12px; } +.rb-line { display: flex; gap: 8px; align-items: center; } +.rb-stack { display: grid; gap: 10px; } +.rb-field { flex: 1; width: 100%; background: #fff; border: 1px solid #e4e8f0; border-radius: 9px; color: #0f172a; padding: 8px 10px; font-size: 13px; } +.rb-field.rb-area { min-height: 66px; resize: vertical; } +.rb-flabel { display: grid; gap: 5px; font-size: 11px; color: #5b6472; } +.rb-form-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 26px; padding-top: 14px; border-top: 1px solid #eef1f6; gap: 12px; } +.rb-mono { margin-bottom: 16px; } +.rb-hint { color: #8a93a3; font-size: 11.5px; } +.rb-page-inner { max-width: 760px; width: 100%; align-self: center; padding: 34px 34px 60px; } +.rb-page-inner .rb-sub { color: #8a93a3; margin: 0 0 22px; font-size: 11.5px; } +.rb-snav { display: flex; gap: 16px; border-bottom: 1px solid #eef1f6; margin-bottom: 8px; } +.rb-snav button { border: 0; background: transparent; color: #8a93a3; font-size: 12px; padding: 8px 0; border-bottom: 1.5px solid transparent; } +.rb-snav button.rb-active { color: #0e2050; border-bottom-color: #1d4ed8; } +.rb-srow { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 13px 0; border-bottom: 1px solid #eef1f6; } +.rb-srow:last-child { border-bottom: 0; } +.rb-srow .rb-l { display: grid; gap: 1px; font-size: 13px; } +.rb-srow .rb-l small { color: #8a93a3; font-size: 11px; } +.rb-srow select, .rb-srow input { background: #fff; border: 1px solid #e4e8f0; border-radius: 8px; color: #0f172a; font-size: 12.5px; padding: 5px 8px; } +.rb-status { display: flex; align-items: center; gap: 6px; color: #5b6472; font-size: 11.5px; border: 0; background: transparent; padding: 0; } +.rb-center-empty { margin: auto; max-width: 420px; text-align: center; display: grid; gap: 8px; justify-items: center; padding: 48px 24px; } +.rb-center-empty h2 { margin: 0; font-size: 18px; font-weight: 650; } +.rb-center-empty p { margin: 0; color: #5b6472; font-size: 13px; } +.rb-thread-empty { color: #8a93a3; font-size: 13px; text-align: center; padding: 24px 0; } +.rb-mini { display: flex; gap: 8px; padding: 8px 12px; border-bottom: 1px solid #eef1f6; } +@media (prefers-reduced-motion: reduce) { + .rb-toggle::after { transition: none; } +} +` + + function lookup(catalog, key) { + const parts = String(key || '').split('.') + let cur = catalog + for (const part of parts) { + if (!cur || typeof cur !== 'object') return key + cur = cur[part] + } + return typeof cur === 'string' ? cur : key } - function PanelIcon({ size }) { - const edge = typeof size === 'number' && size > 0 ? size : 20 + function fill(text, vars) { + return String(text).replace(/\{(\w+)\}/g, (token, name) => { + if (!vars || vars[name] == null || vars[name] === '') return token + return String(vars[name]) + }) + } + + function makeT(catalog) { + return (key, vars) => fill(lookup(catalog, key), vars) + } + + function moneyNumber(value) { + const n = Number(String(value ?? '').replace(/[^\d.]/g, '')) + return Number.isFinite(n) ? n : NaN + } + + function monogram(name) { + const trimmed = String(name || '').trim() + if (!trimmed) return '?' + const chars = Array.from(trimmed) + return chars[0].toUpperCase() + } + + function avatarStyle(seed) { + const key = String(seed || '') + if (PINNED_AVATARS.has(key)) return { color: '#1d4ed8', background: '#e3eafc' } + let hash = 0 + for (const ch of Array.from(key)) hash = (hash * 31 + ch.codePointAt(0)) >>> 0 + const [color, background] = AVATAR_PALETTE[hash % AVATAR_PALETTE.length] + return { color, background } + } + + function botIdFromName(name, bots) { + const ascii = String(name || '').trim().toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '') + const base = ascii || 'bot' + const used = new Set(bots.map((bot) => bot.id)) + let id = base + let n = 2 + while (used.has(id)) { + id = `${base}-${n}` + n += 1 + } + return id + } + + let seq = 0 + function uid(prefix) { + seq += 1 + return `${prefix}-${seq}` + } + + function clock() { + const now = new Date() + const h = String(now.getHours()).padStart(2, '0') + const m = String(now.getMinutes()).padStart(2, '0') + return `${h}:${m}` + } + + function markdownBlocks(text) { + const blocks = [] + let paragraph = [] + let list = [] + const flushParagraph = () => { + if (!paragraph.length) return + const value = paragraph.join(' ').trim() + if (value) blocks.push({ type: 'p', text: value }) + paragraph = [] + } + const flushList = () => { + if (!list.length) return + blocks.push({ type: 'ul', items: list }) + list = [] + } + for (const line of String(text || '').split('\n')) { + const item = /^\s*[-*]\s+(.*)$/.exec(line) + if (item) { + flushParagraph() + list.push(item[1]) + continue + } + if (line.trim() === '') { + flushParagraph() + flushList() + continue + } + flushList() + paragraph.push(line.trim()) + } + flushParagraph() + flushList() + return blocks + } + + function inlineNodes(text, keyPrefix) { + const nodes = [] + const re = /(\*\*([^*]+)\*\*|`([^`]+)`)/g + let last = 0 + let match = re.exec(text) + let index = 0 + while (match) { + if (match.index > last) nodes.push(text.slice(last, match.index)) + if (match[2] != null) nodes.push(h('strong', { key: `${keyPrefix}-b${index}` }, match[2])) + else nodes.push(h('code', { key: `${keyPrefix}-c${index}` }, match[3])) + last = match.index + match[0].length + index += 1 + match = re.exec(text) + } + if (last < text.length) nodes.push(text.slice(last)) + return nodes + } + + function RichText({ text }) { + return markdownBlocks(text).map((block, index) => { + if (block.type === 'ul') { + return h( + 'ul', + { key: `ul${index}` }, + block.items.map((item, itemIndex) => h('li', { key: itemIndex }, inlineNodes(item, `i${index}-${itemIndex}`))), + ) + } + return h('p', { key: `p${index}` }, inlineNodes(block.text, `p${index}`)) + }) + } + + function seedBots() { + return [ + { + id: 'nora', + nameKey: 'sample.nora.name', + jobKey: 'sample.nora.job', + attention: 'working', + timeKey: 'sample.nora.time', + snippetKey: 'sample.nora.snippet', + messages: [ + { id: 'nora-u', kind: 'user', textKey: 'sample.nora.user' }, + { id: 'nora-d', kind: 'day', textKey: 'sample.nora.day' }, + { id: 'nora-b1', kind: 'bot', textKey: 'sample.nora.reply1' }, + { id: 'nora-c', kind: 'computer', titleKey: 'sample.nora.computerTitle', subKey: 'sample.nora.computerSub' }, + { id: 'nora-a', kind: 'approval', approvalId: 'nora-pub' }, + { id: 'nora-b2', kind: 'bot', textKey: 'sample.nora.reply2' }, + ], + approvals: { + 'nora-pub': { + id: 'nora-pub', + titleKey: 'sample.nora.approvalTitle', + metaKey: 'sample.nora.approvalMeta', + state: 'pending', + }, + }, + receipts: [ + { titleKey: 'sample.nora.r1', stateKey: 'receipt.ready', metaKey: 'sample.nora.r1meta' }, + { titleKey: 'sample.nora.r2', stateKey: 'receipt.waiting', metaKey: 'sample.nora.r2meta' }, + { titleKey: 'sample.nora.r3', stateKey: 'receipt.done', metaKey: 'sample.nora.r3meta' }, + ], + routines: [ + { titleKey: 'sample.routine.weekly', scheduleKey: 'sample.routine.weeklyWhen', on: true }, + { titleKey: 'sample.routine.inbox', scheduleKey: 'sample.routine.inboxWhen', on: true }, + { titleKey: 'sample.routine.standup', scheduleKey: 'sample.routine.standupWhen', on: false }, + ], + library: [ + { group: 'today', titleKey: 'sample.nora.f1', badgeKey: 'sample.nora.f1badge', metaKey: 'sample.nora.f1meta' }, + { group: 'today', titleKey: 'sample.nora.f2', badgeKey: 'sample.nora.f2badge', metaKey: 'sample.nora.f2meta' }, + { group: 'week', titleKey: 'sample.nora.f3', badgeKey: 'sample.nora.f3badge', metaKey: 'sample.nora.f3meta' }, + { group: 'older', titleKey: 'sample.nora.f4', badgeKey: 'sample.nora.f4badge', metaKey: 'sample.nora.f4meta' }, + ], + }, + { + id: 'eli', + nameKey: 'sample.eli.name', + jobKey: 'sample.eli.job', + attention: 'needs', + timeKey: 'sample.eli.time', + snippetKey: 'sample.eli.snippet', + messages: [ + { id: 'eli-d', kind: 'day', textKey: 'sample.eli.day' }, + { id: 'eli-b', kind: 'bot', textKey: 'sample.eli.reply' }, + { id: 'eli-a', kind: 'approval', approvalId: 'eli-pub' }, + ], + approvals: { + 'eli-pub': { + id: 'eli-pub', + titleKey: 'sample.eli.approvalTitle', + metaKey: 'sample.eli.approvalMeta', + state: 'pending', + }, + }, + receipts: [ + { titleKey: 'sample.nora.r2', stateKey: 'receipt.waiting', metaKey: 'sample.eli.approvalMeta' }, + ], + routines: [], + library: [], + }, + { + id: 'june', + nameKey: 'sample.june.name', + jobKey: 'sample.june.job', + attention: 'unread', + timeKey: 'sample.june.time', + snippetKey: 'sample.june.snippet', + messages: [ + { id: 'june-d', kind: 'day', textKey: 'sample.june.day' }, + { id: 'june-b', kind: 'bot', textKey: 'sample.june.reply' }, + ], + approvals: {}, + receipts: [ + { titleKey: 'sample.june.r1', stateKey: 'receipt.done', metaKey: 'sample.june.r1meta' }, + ], + routines: [], + library: [], + }, + ] + } + + function createState() { + return { + screen: 'chat', + selectedId: 'nora', + tab: 'activity', + searchOpen: false, + search: '', + composer: '', + flash: null, + live: '', + settingsTab: 'account', + setupStep: 1, + forceList: false, + forceDetail: false, + settings: { + idle: '15', + lowBalance: '10', + notifications: true, + lang: null, + }, + bots: seedBots(), + } + } + + function botName(bot, t) { + return bot.name || t(bot.nameKey) + } + + function botJob(bot, t) { + return bot.job || (bot.jobKey ? t(bot.jobKey) : '') + } + + function botSnippet(bot, t) { + if (bot.snippet) return bot.snippet + if (bot.snippetKey) return t(bot.snippetKey) + return '' + } + + function botTime(bot, t) { + if (bot.time) return bot.time + if (bot.timeKey) return t(bot.timeKey) + return '' + } + + function attentionText(bot, t) { + if (bot.attention === 'needs') return t('attention.needs') + if (bot.attention === 'unread') return t('attention.unread') + if (bot.attention === 'working') return t('attention.working') + return '' + } + + function textOf(entry, t) { + if (entry.text) return entry.text + if (entry.textKey) return t(entry.textKey) + return '' + } + + function fieldText(entry, t, keyName) { + if (entry.text) return entry.text + const key = entry[keyName] + return key ? t(key) : '' + } + + function useDshLang(ctx) { + const locale = ctx?.get?.('locale') ?? ctx?.locale + const read = () => { + try { + return String(locale?.getLocale?.()?.id ?? '') + } catch { + return '' + } + } + const [id, setId] = useState(read) + useEffect(() => { + if (typeof locale?.subscribe !== 'function') return undefined + return locale.subscribe(() => setId(read())) + }, [locale]) + return id + } + + function resolveLang(dshId, override) { + const id = String(override || dshId || '').toLowerCase() + if (id.startsWith('zh')) return 'zh' + if (id.startsWith('en')) return 'en' + return 'en' + } + + function useContainerWidth(ref) { + const [width, setWidth] = useState(1280) + useEffect(() => { + const el = ref.current + if (!el || typeof ResizeObserver !== 'function') return undefined + const measure = () => setWidth(el.clientWidth || 1280) + measure() + const observer = new ResizeObserver(measure) + observer.observe(el) + return () => observer.disconnect() + }, [ref]) + return width + } + + function Mark() { return h( 'svg', { - width: edge, - height: edge, + className: 'rb-mark', + width: 20, + height: 20, viewBox: '0 0 24 24', fill: 'none', - stroke: 'currentColor', - strokeWidth: 1.7, + stroke: '#003d9b', + strokeWidth: 2, strokeLinecap: 'round', strokeLinejoin: 'round', 'aria-hidden': 'true', }, - h('rect', { x: 3.2, y: 4.2, width: 17.6, height: 12.4, rx: 2 }), - h('path', { d: 'M8 20.4h8M12 16.6v3.8' }), - h('circle', { cx: 9, cy: 10.4, r: 1.1 }), - h('circle', { cx: 15, cy: 10.4, r: 1.1 }), + MARK_PATHS.map((d) => h('path', { key: d, d })), + ) + } + + function SearchIcon() { + return h( + 'svg', + { width: 15, height: 15, viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', strokeWidth: 1.8, strokeLinecap: 'round', 'aria-hidden': 'true' }, + h('circle', { cx: 11, cy: 11, r: 7 }), + h('path', { d: 'm16.5 16.5 4.5 4.5' }), + ) + } + + function GearIcon() { + return h( + 'svg', + { width: 15, height: 15, viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', strokeWidth: 1.8, strokeLinecap: 'round', 'aria-hidden': 'true' }, + h('path', { d: 'M4 7h9M18 7h2M4 12h3M11 12h9M4 17h7M15 17h5' }), + h('circle', { cx: 15, cy: 7, r: 2 }), + h('circle', { cx: 9, cy: 12, r: 2 }), + h('circle', { cx: 13, cy: 17, r: 2 }), + ) + } + + function Avatar({ size, name, text, className }) { + return h( + 'div', + { + className: `rb-avatar rb-${size}${className ? ` ${className}` : ''}`, + style: avatarStyle(name), + 'aria-hidden': 'true', + }, + text || monogram(name), ) } - function BotsPage() { + function lineParts(template, vars, boldKeys) { + const nodes = [] + const re = /\{(\w+)\}/g + let last = 0 + let index = 0 + let match = re.exec(template) + while (match) { + if (match.index > last) nodes.push(template.slice(last, match.index)) + const name = match[1] + const value = vars && vars[name] != null ? String(vars[name]) : '' + nodes.push(boldKeys.has(name) ? h('b', { key: `${name}${index}` }, value) : value) + last = match.index + match[0].length + index += 1 + match = re.exec(template) + } + if (last < template.length) nodes.push(template.slice(last)) + return nodes + } + + function Toggle({ on, label, onClick }) { + return h('button', { + type: 'button', + className: on ? 'rb-toggle rb-on' : 'rb-toggle', + 'aria-pressed': on ? 'true' : 'false', + 'aria-label': label, + onClick, + }) + } + + function BotFields({ t, name, job, instructions, onName, onJob, onInstructions }) { return h( 'div', - { style: styles.page }, - h('h1', { style: styles.title }, 'Bots'), + null, h( - 'p', - { style: styles.body }, - 'The bot layer is under construction. This page is the A1 skeleton: the package loads, the client half renders, and the host half answers ', - h('code', { style: styles.code }, 'GET /plugins/rayrun-bots?action=health'), - '.', + 'div', + { className: 'rb-line rb-mono' }, + h(Avatar, { size: 'new', name: name || t('newBot.defaultName') }), + h('div', { className: 'rb-hint' }, t('newBot.monogramHint')), ), h( 'div', - { style: styles.card }, - h('p', { style: styles.body }, 'Nothing here creates a bot yet. The chat list, conversation and details panel arrive with the first real bot-layer milestone.'), + { className: 'rb-stack' }, + h( + 'label', + { className: 'rb-flabel' }, + t('newBot.name'), + h('input', { + className: 'rb-field', + value: name, + maxLength: 40, + onChange: (event) => onName(event.target.value), + }), + ), + h( + 'label', + { className: 'rb-flabel' }, + t('newBot.job'), + h('input', { + className: 'rb-field', + value: job, + maxLength: 80, + onChange: (event) => onJob(event.target.value), + }), + ), + h( + 'label', + { className: 'rb-flabel' }, + t('newBot.instructions'), + h('textarea', { + className: 'rb-field rb-area', + rows: 4, + value: instructions, + placeholder: t('newBot.placeholder', { name: name || t('newBot.defaultName') }), + onChange: (event) => onInstructions(event.target.value), + }), + ), ), ) } + function idleLabel(t, idle) { + if (idle === '30') return t('settings.idle30') + if (idle === '0') return t('settings.idleOff') + return t('settings.idle15') + } + + function BotsApp({ ctx }) { + const [state, setState] = useState(createState) + const dshLang = useDshLang(ctx) + const lang = resolveLang(dshLang, state.settings.lang) + const t = makeT(lang === 'zh' ? ZH : EN) + const frameRef = useRef(null) + const searchRef = useRef(null) + const width = useContainerWidth(frameRef) + + useEffect(() => { + const onKey = (event) => { + if (event.key !== 'Escape') return + setState((current) => { + if (current.searchOpen) return { ...current, searchOpen: false, search: '' } + if (current.screen !== 'chat') return { ...current, screen: 'chat', flash: null } + return current + }) + } + document.addEventListener('keydown', onKey) + return () => document.removeEventListener('keydown', onKey) + }, []) + + useEffect(() => { + if (state.searchOpen) searchRef.current?.focus() + }, [state.searchOpen]) + + const selected = state.bots.find((bot) => bot.id === state.selectedId) || state.bots[0] || null + const listOn = width >= 900 || state.forceList + const detailOn = state.screen === 'chat' && (width >= 1120 || state.forceDetail) + const columns = `${listOn ? '296px ' : ''}minmax(0,1fr)${detailOn ? ' 328px' : ''}` + + const patch = (partial) => setState((current) => ({ ...current, ...partial })) + + const openScreen = (screen) => patch({ screen, flash: null, searchOpen: false }) + + const selectBot = (id) => { + setState((current) => ({ + ...current, + selectedId: id, + screen: 'chat', + tab: 'activity', + forceList: false, + flash: null, + bots: current.bots.map((bot) => (bot.id === id && bot.attention === 'unread' ? { ...bot, attention: null } : bot)), + })) + } + + const updateBot = (id, fn) => { + setState((current) => ({ + ...current, + bots: current.bots.map((bot) => (bot.id === id ? fn(bot) : bot)), + })) + } + + const send = () => { + const text = state.composer.trim() + if (!text || !selected) return + const snippet = text.length > 48 ? `${text.slice(0, 47)}…` : text + setState((current) => ({ + ...current, + composer: '', + flash: null, + bots: current.bots.map((bot) => { + if (bot.id !== selected.id) return bot + return { + ...bot, + snippet, + snippetKey: null, + time: clock(), + timeKey: null, + messages: [...bot.messages, { id: uid('user'), kind: 'user', text }], + } + }), + })) + } + + const decide = (approvalId, decision) => { + if (!selected) return + const allowed = decision === 'allowed' + const sentence = t(allowed ? 'approval.allowedLocal' : 'approval.deniedLocal') + const snippet = t(allowed ? 'approval.snippetAllowed' : 'approval.snippetDenied') + setState((current) => ({ + ...current, + flash: sentence, + live: sentence, + bots: current.bots.map((bot) => { + if (bot.id !== selected.id) return bot + const currentApproval = bot.approvals[approvalId] + if (!currentApproval || currentApproval.state !== 'pending') return bot + const approvals = { ...bot.approvals, [approvalId]: { ...currentApproval, state: decision } } + const stillPending = Object.values(approvals).some((item) => item.state === 'pending') + return { + ...bot, + approvals, + attention: bot.attention === 'needs' && !stillPending ? null : bot.attention, + snippet: stillPending ? bot.snippet : snippet, + snippetKey: stillPending ? bot.snippetKey : null, + } + }), + })) + } + + const createBot = (draft) => { + const name = draft.name.trim() + if (!name) return + const job = draft.job.trim() + const instructions = draft.instructions.trim() || t('persona.template', { name, job: job || '…' }) + setState((current) => { + const id = botIdFromName(name, current.bots) + const bot = { + id, + name, + job, + instructions, + attention: null, + time: '', + snippetKey: 'empty.snippet', + messages: [], + approvals: {}, + receipts: [], + routines: [], + library: [], + } + return { + ...current, + screen: 'chat', + selectedId: id, + tab: 'activity', + flash: null, + bots: [...current.bots, bot], + } + }) + } + + const flash = (text) => patch({ flash: text, live: text }) + + const catalog = lang === 'zh' ? ZH : EN + const balance = moneyNumber(t('usage.sampleBalance')) + const threshold = moneyNumber(state.settings.lowBalance) + const low = Number.isFinite(balance) && Number.isFinite(threshold) && balance < threshold + + const query = state.search.trim().toLowerCase() + const rows = state.bots.filter((bot) => { + if (selected && bot.id === selected.id) return false + if (!query) return true + const hay = `${botName(bot, t)} ${botJob(bot, t)} ${botSnippet(bot, t)}`.toLowerCase() + return hay.includes(query) + }) + + const center = renderCenter({ + state, + t, + selected, + low, + onComposer: (composer) => patch({ composer }), + onSend: send, + onDecide: decide, + onView: () => flash(t('computer.desktopLater')), + onAttach: () => flash(t('notice.attach')), + onCreate: createBot, + onScreen: openScreen, + onSetupStep: (setupStep) => patch({ setupStep }), + onFlash: flash, + onSettings: (partial) => setState((current) => ({ ...current, settings: { ...current.settings, ...partial } })), + onSettingsTab: (settingsTab) => patch({ settingsTab }), + catalog, + width, + onToggleList: () => patch({ forceList: !state.forceList }), + onToggleDetail: () => patch({ forceDetail: !state.forceDetail }), + }) + + return h( + 'div', + { className: 'rb-frame', ref: frameRef, id: 'rayrun-bots-root' }, + h('style', null, CSS), + h('p', { className: 'rb-sr' }, t('notice.preview')), + h('div', { className: 'rb-sr', 'aria-live': 'polite' }, state.live), + h( + 'div', + { className: 'rb-app', style: { gridTemplateColumns: columns } }, + listOn ? h(ChatList, { + t, + state, + rows, + selected, + searchRef, + onSearchToggle: () => patch({ searchOpen: !state.searchOpen, search: state.searchOpen ? '' : state.search }), + onSearch: (search) => patch({ search }), + onSelect: selectBot, + onNew: () => openScreen('newbot'), + onSettings: () => openScreen('settings'), + onSetup: () => { + patch({ screen: 'setup', setupStep: 1, flash: null, searchOpen: false }) + }, + }) : null, + center, + detailOn && selected ? h(Details, { + t, + catalog, + bot: selected, + tab: state.tab, + onTab: (tab) => patch({ tab }), + low, + idle: idleLabel(t, state.settings.idle), + onToggleRoutine: (index) => updateBot(selected.id, (bot) => ({ + ...bot, + routines: bot.routines.map((routine, routineIndex) => (routineIndex === index ? { ...routine, on: !routine.on } : routine)), + })), + onComputer: () => flash(t('computer.desktopLater')), + }) : null, + ), + ) + } + + function ChatList({ t, state, rows, selected, searchRef, onSearchToggle, onSearch, onSelect, onNew, onSettings, onSetup }) { + const userName = t('sample.user.name') + return h( + 'aside', + { className: 'rb-list', 'aria-label': t('panel.label') }, + h( + 'div', + { className: 'rb-list-top' }, + h('div', { className: 'rb-brand' }, h(Mark), h('span', null, t('brand'))), + h( + 'div', + { className: 'rb-tools' }, + h('button', { type: 'button', className: 'rb-icon', title: t('list.search'), 'aria-label': t('list.search'), 'aria-pressed': state.searchOpen ? 'true' : 'false', onClick: onSearchToggle }, h(SearchIcon)), + h('button', { type: 'button', className: 'rb-icon', title: t('list.newBot'), 'aria-label': t('list.newBot'), onClick: onNew }, '+'), + ), + ), + state.searchOpen ? h( + 'div', + { className: 'rb-search' }, + h('input', { + ref: searchRef, + value: state.search, + placeholder: t('list.searchPlaceholder'), + 'aria-label': t('list.search'), + onChange: (event) => onSearch(event.target.value), + }), + ) : null, + selected ? h( + 'div', + { className: 'rb-current' }, + h(Avatar, { size: 'big', name: botName(selected, t) }), + h('div', { className: 'rb-name' }, botName(selected, t)), + h('div', { className: 'rb-label' }, attentionText(selected, t) ? `${botJob(selected, t)} · ${attentionText(selected, t)}` : botJob(selected, t)), + ) : h( + 'div', + { className: 'rb-current' }, + h('div', { className: 'rb-name' }, t('empty.heading')), + h('div', { className: 'rb-label' }, t('empty.body')), + ), + h( + 'div', + { className: 'rb-chats' }, + rows.length ? rows.map((bot, index) => { + const name = botName(bot, t) + const snippet = botSnippet(bot, t) + const attention = attentionText(bot, t) + const active = state.screen === 'chat' && index === 0 + return h( + 'button', + { + type: 'button', + key: bot.id, + className: active ? 'rb-row rb-active' : 'rb-row', + onClick: () => onSelect(bot.id), + 'aria-label': attention ? `${name}. ${snippet}. ${attention}` : `${name}. ${snippet}`, + }, + h(Avatar, { size: 'mid', name }), + h( + 'div', + { style: { minWidth: 0 } }, + h( + 'div', + { className: 'rb-nm' }, + name, + bot.attention ? h('span', { className: `rb-dot rb-${bot.attention}`, title: attention }) : null, + ), + h('div', { className: 'rb-sn' }, snippet), + ), + h('div', { className: 'rb-tm' }, botTime(bot, t)), + ) + }) : h('div', { className: 'rb-empty-list' }, t('list.empty')), + ), + h( + 'div', + { className: 'rb-foot' }, + h(Avatar, { size: 'sm', name: userName, text: t('sample.user.initials') }), + h( + 'div', + { className: 'rb-who' }, + userName, + h( + 'small', + null, + h('button', { + type: 'button', + className: 'rb-textbtn', + onClick: onSetup, + title: t('setup.title'), + }, t('sample.user.foot', { balance: t('usage.sampleBalance') })), + ), + ), + h('button', { type: 'button', className: 'rb-icon', title: t('list.settings'), 'aria-label': t('list.settings'), onClick: onSettings }, h(GearIcon)), + ), + ) + } + + function ApprovalCard({ t, approval, onDecide }) { + const pending = approval.state === 'pending' + const title = fieldText(approval, t, 'titleKey') + const meta = fieldText(approval, t, 'metaKey') + let side = t('approval.waits') + if (approval.state === 'allowed') side = t('approval.snippetAllowed') + if (approval.state === 'denied') side = t('approval.snippetDenied') + return h( + 'div', + { className: 'rb-card', role: 'group', 'aria-label': title }, + h( + 'div', + { className: 'rb-card-top' }, + h('span', { className: 'rb-card-title' }, h('span', { className: 'rb-warn', 'aria-hidden': 'true' }, '⚠'), title), + h('span', { className: 'rb-m' }, side), + ), + pending ? h('div', { className: 'rb-warnline' }, t('approval.warning')) : h('div', { className: 'rb-result' }, t(approval.state === 'allowed' ? 'approval.allowedLocal' : 'approval.deniedLocal')), + h('div', { className: 'rb-meta' }, meta), + pending ? h( + 'div', + { className: 'rb-actions' }, + h('button', { type: 'button', className: 'rb-btn rb-ghost', onClick: () => onDecide(approval.id, 'denied') }, t('approval.deny')), + h('button', { type: 'button', className: 'rb-btn rb-primary', onClick: () => onDecide(approval.id, 'allowed') }, t('approval.allowOnce')), + ) : null, + ) + } + + function Conversation({ t, state, bot, onComposer, onSend, onDecide, onView, onAttach, showListButton, showDetailButton, onToggleList, onToggleDetail }) { + const name = botName(bot, t) + const job = botJob(bot, t) + return h( + 'main', + { className: 'rb-main', 'data-screen': 'chat' }, + showListButton || showDetailButton ? h( + 'div', + { className: 'rb-mini' }, + showListButton ? h('button', { type: 'button', className: 'rb-btn', 'aria-pressed': state.forceList ? 'true' : 'false', onClick: onToggleList }, t('panel.label')) : null, + showDetailButton ? h('button', { type: 'button', className: 'rb-btn', 'aria-pressed': state.forceDetail ? 'true' : 'false', onClick: onToggleDetail }, name) : null, + ) : null, + h( + 'div', + { className: 'rb-thread' }, + bot.messages.length ? bot.messages.map((entry) => { + if (entry.kind === 'day') return h('div', { key: entry.id, className: 'rb-day' }, textOf(entry, t)) + if (entry.kind === 'user') { + return h('div', { key: entry.id, className: 'rb-msg rb-user' }, h('div', { className: 'rb-bubble' }, textOf(entry, t))) + } + if (entry.kind === 'computer') { + return h( + 'div', + { key: entry.id, className: 'rb-computer-act' }, + h('div', { className: 'rb-thumb', 'aria-hidden': 'true' }), + h('div', null, h('div', { className: 'rb-t' }, t(entry.titleKey)), h('div', { className: 'rb-s' }, t(entry.subKey))), + h('button', { type: 'button', className: 'rb-btn rb-ghost', onClick: onView }, t('computer.view')), + ) + } + if (entry.kind === 'approval') { + const approval = bot.approvals[entry.approvalId] + if (!approval) return null + return h(ApprovalCard, { key: entry.id, t, approval, onDecide }) + } + return h( + 'div', + { key: entry.id, className: 'rb-msg' }, + h(Avatar, { size: 'sm', name, className: 'rb-msg-avatar' }), + h( + 'div', + { className: 'rb-body' }, + h('div', { className: 'rb-who-line' }, h('b', null, name), h('span', null, job)), + h(RichText, { text: textOf(entry, t) }), + ), + ) + }) : h('div', { className: 'rb-thread-empty' }, t('empty.thread')), + ), + h( + 'div', + { className: 'rb-notice', role: 'status' }, + h('span', { className: 'rb-dot rb-needs', 'aria-hidden': 'true' }), + state.flash || t('notice.reconnecting'), + ), + h( + 'div', + { className: 'rb-composer' }, + h('button', { type: 'button', className: 'rb-icon', title: t('composer.attach'), 'aria-label': t('composer.attach'), onClick: onAttach }, '+'), + h('input', { + value: state.composer, + placeholder: t('composer.placeholder', { name }), + 'aria-label': t('composer.placeholder', { name }), + onChange: (event) => onComposer(event.target.value), + onKeyDown: (event) => { + if (event.key === 'Enter' && !event.shiftKey) { + event.preventDefault() + onSend() + } + }, + }), + h('button', { type: 'button', className: 'rb-send', title: t('composer.send'), 'aria-label': t('composer.send'), onClick: onSend }, '↑'), + ), + ) + } + + function Details({ t, catalog, bot, tab, onTab, low, idle, onToggleRoutine, onComputer }) { + const name = botName(bot, t) + const job = botJob(bot, t) + const groups = [ + ['today', 'library.today'], + ['week', 'library.week'], + ['older', 'library.older'], + ] + return h( + 'aside', + { className: 'rb-detail', 'aria-label': name }, + h( + 'div', + { className: 'rb-profile' }, + h(Avatar, { size: 'big', name }), + h('div', { className: 'rb-name' }, name), + h('div', { className: 'rb-sub' }, t('details.jobComputer', { job, computer: t('sample.computerName') || SAMPLE_COMPUTER })), + ), + h( + 'div', + { className: 'rb-tabs', role: 'tablist' }, + h('button', { type: 'button', className: tab === 'activity' ? 'rb-tab rb-active' : 'rb-tab', role: 'tab', 'aria-selected': tab === 'activity' ? 'true' : 'false', onClick: () => onTab('activity') }, t('details.activity')), + h('button', { type: 'button', className: tab === 'library' ? 'rb-tab rb-active' : 'rb-tab', role: 'tab', 'aria-selected': tab === 'library' ? 'true' : 'false', onClick: () => onTab('library') }, t('details.library')), + ), + tab === 'activity' ? h( + 'div', + { className: 'rb-sections' }, + h( + 'section', + { className: 'rb-sec' }, + h('h3', null, t('details.recent')), + bot.receipts.length ? bot.receipts.map((receipt, index) => h( + 'div', + { key: index, className: 'rb-act' }, + h('div', { className: 'rb-t' }, h('span', null, t(receipt.titleKey)), h('span', { className: 'rb-ok' }, t(receipt.stateKey))), + h('div', { className: 'rb-s' }, t(receipt.metaKey)), + )) : h('div', { className: 'rb-s' }, t('details.recentEmpty')), + ), + h( + 'section', + { className: 'rb-sec' }, + h('h3', null, t('details.upcoming')), + bot.routines.length ? bot.routines.map((routine, index) => { + const title = t(routine.titleKey) + return h( + 'div', + { key: title, className: 'rb-routine' }, + h('div', null, h('div', { className: 'rb-t' }, title), h('div', { className: 'rb-s' }, t(routine.scheduleKey))), + h(Toggle, { + on: routine.on, + label: `${title} ${routine.on ? t('routine.on') : t('routine.off')}`, + onClick: () => onToggleRoutine(index), + }), + ) + }) : h('div', { className: 'rb-s' }, t('routine.empty')), + ), + h(ComputerBlock, { t, onComputer }), + h(UsageBlock, { t, catalog, idle, low }), + ) : h( + 'div', + { className: 'rb-sections' }, + bot.library.length ? groups.map(([group, labelKey]) => { + const items = bot.library.filter((item) => item.group === group) + if (!items.length) return null + return h( + 'section', + { key: group, className: 'rb-sec' }, + h('h3', null, t(labelKey)), + items.map((item, index) => h( + 'div', + { key: `${group}-${index}`, className: 'rb-act' }, + h('div', { className: 'rb-t' }, h('span', null, t(item.titleKey)), h('span', { className: 'rb-ok' }, t(item.badgeKey))), + h('div', { className: 'rb-s' }, t(item.metaKey)), + )), + ) + }) : h('div', { className: 'rb-s' }, t('library.empty')), + ), + ) + } + + function ComputerBlock({ t, onComputer }) { + return h( + 'section', + { className: 'rb-sec' }, + h('h3', null, t('details.computer')), + h( + 'div', + { className: 'rb-computer' }, + h( + 'div', + { className: 'rb-comp-row' }, + h('div', null, h('div', { className: 'rb-nm' }, t('sample.computerName')), h('div', { className: 'rb-st' }, t('computer.reconnecting'))), + h('div', { className: 'rb-thumb', 'aria-hidden': 'true' }), + ), + h( + 'div', + { className: 'rb-comp-acts' }, + h('button', { type: 'button', className: 'rb-btn', onClick: onComputer }, t('computer.open')), + h('button', { type: 'button', className: 'rb-btn', onClick: onComputer }, t('computer.takeOver')), + ), + ), + ) + } + + function UsageBlock({ t, catalog, idle, low }) { + const balance = t('usage.sampleBalance') + const hours = t('usage.sampleHours') + const spend = t('usage.sampleSpend') + return h( + 'section', + { className: 'rb-sec' }, + h('h3', null, t('details.usage')), + h( + 'div', + { className: 'rb-usage' }, + h('span', null, lineParts(lookup(catalog, 'usage.balanceLine'), { balance, hours }, new Set(['balance']))), + h('span', null, lineParts(lookup(catalog, 'usage.weekLine'), { spend, idle }, new Set(['spend']))), + low ? h('span', { className: 'rb-low' }, t('cost.low')) : null, + ), + ) + } + + function renderCenter(ctx) { + const { state, t, selected, width } = ctx + if (state.screen === 'newbot') return h(NewBotScreen, { t, onCancel: () => ctx.onScreen('chat'), onCreate: ctx.onCreate }) + if (state.screen === 'setup') { + return h(SetupScreen, { + t, + step: state.setupStep, + flash: state.flash, + onStep: ctx.onSetupStep, + onClose: () => ctx.onScreen('chat'), + onCreate: ctx.onCreate, + onFlash: ctx.onFlash, + }) + } + if (state.screen === 'settings') { + return h(SettingsScreen, { + t, + state, + onTab: ctx.onSettingsTab, + onChange: ctx.onSettings, + onSetup: () => { + ctx.onSetupStep(1) + ctx.onScreen('setup') + }, + }) + } + if (!selected) { + return h( + 'main', + { className: 'rb-main', 'data-screen': 'chat' }, + h('div', { className: 'rb-center-empty' }, h('h2', null, t('empty.heading')), h('p', null, t('empty.body')), h('button', { type: 'button', className: 'rb-btn rb-primary', onClick: () => ctx.onScreen('newbot') }, t('newBot.create'))), + ) + } + return h(Conversation, { + t, + state, + bot: selected, + onComposer: ctx.onComposer, + onSend: ctx.onSend, + onDecide: ctx.onDecide, + onView: ctx.onView, + onAttach: ctx.onAttach, + showListButton: width < 900, + showDetailButton: width < 1120, + onToggleList: ctx.onToggleList, + onToggleDetail: ctx.onToggleDetail, + }) + } + + function NewBotScreen({ t, onCancel, onCreate }) { + const [name, setName] = useState(() => t('newBot.defaultName')) + const [job, setJob] = useState(() => t('newBot.defaultJob')) + const [instructions, setInstructions] = useState('') + return h( + 'main', + { className: 'rb-page', 'data-screen': 'newbot' }, + h( + 'div', + { className: 'rb-wizard-wrap' }, + h( + 'div', + { className: 'rb-wizard' }, + h('h1', null, t('newBot.title')), + h('p', { className: 'rb-sub' }, t('newBot.sub')), + h(BotFields, { t, name, job, instructions, onName: setName, onJob: setJob, onInstructions: setInstructions }), + h( + 'div', + { className: 'rb-form-foot' }, + h('button', { type: 'button', className: 'rb-btn rb-ghost', onClick: onCancel }, t('newBot.cancel')), + h('button', { + type: 'button', + className: 'rb-btn rb-primary', + disabled: !name.trim(), + onClick: () => onCreate({ name, job, instructions }), + }, t('newBot.create')), + ), + ), + ), + ) + } + + function SetupScreen({ t, step, flash, onStep, onClose, onCreate, onFlash }) { + const [name, setName] = useState(() => t('newBot.defaultName')) + const [job, setJob] = useState(() => t('newBot.defaultJob')) + const [instructions, setInstructions] = useState('') + const tokenRef = useRef(null) + const keyRef = useRef(null) + const steps = [ + ['dependency', 'setup.steps.dependency'], + ['rayrun', 'setup.steps.rayrun'], + ['key', 'setup.steps.key'], + ['bot', 'setup.steps.bot'], + ] + const canContinue = step === 3 && Boolean(name.trim()) + const back = () => { + if (step === 0) onClose() + else onStep(step - 1) + } + const skip = () => { + if (step >= 3) onClose() + else onStep(step + 1) + } + const next = () => { + if (!canContinue) return + onCreate({ name, job, instructions }) + } + const forget = (ref, key) => { + if (ref.current) ref.current.value = '' + onFlash(t(key)) + } + return h( + 'main', + { className: 'rb-page', 'data-screen': 'setup' }, + h( + 'div', + { className: 'rb-wizard-wrap' }, + h( + 'div', + { className: 'rb-wizard' }, + h('h1', null, t('setup.title')), + h('p', { className: 'rb-sub' }, t('setup.sub')), + h( + 'div', + { className: 'rb-steps' }, + steps.map(([id, labelKey], index) => h( + 'div', + { key: id, className: index < step ? 'rb-step rb-done' : index === step ? 'rb-step rb-current' : 'rb-step' }, + h('div', { className: 'rb-bar' }), + h('div', { className: 'rb-lbl' }, t(labelKey)), + )), + ), + step === 0 ? h( + 'div', + null, + h('h2', null, t('setup.dependencyTitle')), + h('p', { className: 'rb-say' }, t('setup.dependencyBody')), + h('div', { className: 'rb-faint' }, t('setup.dependencyStatus')), + ) : null, + step === 1 ? h( + 'div', + null, + h('h2', null, t('setup.rayrunTitle')), + h('p', { className: 'rb-say' }, t('setup.rayrunBody')), + h( + 'div', + { className: 'rb-line' }, + h('button', { type: 'button', className: 'rb-btn rb-primary', onClick: () => onFlash(t('setup.signInLater')) }, t('setup.signIn')), + h('span', { className: 'rb-faint' }, t('setup.notConnected')), + ), + h( + 'div', + { className: 'rb-line', style: { marginTop: 9 } }, + h('input', { + ref: tokenRef, + className: 'rb-field', + type: 'password', + autoComplete: 'off', + spellCheck: false, + placeholder: t('setup.tokenPlaceholder'), + 'aria-label': t('setup.tokenPlaceholder'), + }), + h('button', { type: 'button', className: 'rb-btn', onClick: () => forget(tokenRef, 'setup.tokenIgnored') }, t('setup.connect')), + ), + h('div', { className: 'rb-faint', style: { marginTop: 10 } }, t('setup.accountLine')), + ) : null, + step === 2 ? h( + 'div', + null, + h('h2', null, t('setup.keyTitle')), + h('p', { className: 'rb-say' }, t('setup.keyBody')), + h( + 'div', + { className: 'rb-line' }, + h('input', { + ref: keyRef, + className: 'rb-field', + type: 'password', + autoComplete: 'off', + spellCheck: false, + placeholder: t('setup.keyPlaceholder'), + 'aria-label': t('setup.keyPlaceholder'), + }), + h('button', { type: 'button', className: 'rb-btn', onClick: () => forget(keyRef, 'setup.keyIgnored') }, t('setup.keySave')), + ), + ) : null, + step === 3 ? h( + 'div', + null, + h('h2', null, t('setup.botTitle')), + h('p', { className: 'rb-say' }, t('setup.botBody')), + h(BotFields, { t, name, job, instructions, onName: setName, onJob: setJob, onInstructions: setInstructions }), + ) : null, + flash ? h('p', { className: 'rb-say', role: 'status', style: { color: '#b45309' } }, flash) : null, + h( + 'div', + { className: 'rb-form-foot' }, + h('button', { type: 'button', className: 'rb-btn rb-ghost', onClick: back }, t('setup.back')), + h( + 'div', + { className: 'rb-line' }, + h('button', { type: 'button', className: 'rb-btn rb-ghost', onClick: skip }, t('setup.skip')), + h('button', { type: 'button', className: 'rb-btn rb-primary', disabled: !canContinue, onClick: next }, t('setup.continue')), + ), + ), + ), + ), + ) + } + + function SettingsScreen({ t, state, onTab, onChange, onSetup }) { + const shownLang = state.settings.lang || (lookup(ZH, 'settings.title') === t('settings.title') ? 'zh' : 'en') + const scrollTo = (id) => { + onTab(id) + const reduce = typeof window.matchMedia === 'function' && window.matchMedia('(prefers-reduced-motion: reduce)').matches + document.getElementById(`rb-settings-${id}`)?.scrollIntoView({ block: 'start', behavior: reduce ? 'auto' : 'smooth' }) + } + return h( + 'main', + { className: 'rb-page', 'data-screen': 'settings' }, + h( + 'div', + { className: 'rb-page-inner' }, + h('h1', null, t('settings.title')), + h('p', { className: 'rb-sub' }, t('settings.sub')), + h( + 'div', + { className: 'rb-snav' }, + ['account', 'usage', 'notifications', 'appearance'].map((id) => h( + 'button', + { + type: 'button', + key: id, + className: state.settingsTab === id ? 'rb-active' : '', + onClick: () => scrollTo(id), + }, + t(`settings.${id}`), + )), + ), + h( + 'div', + { id: 'rb-settings-account', className: 'rb-srow' }, + h('div', { className: 'rb-l' }, t('settings.rayrunAccount'), h('small', null, t('settings.rayrunHint'))), + h( + 'button', + { type: 'button', className: 'rb-status', onClick: onSetup }, + h('span', { className: 'rb-dot rb-working', 'aria-hidden': 'true' }), + t('settings.connected'), + ), + ), + h( + 'div', + { className: 'rb-srow' }, + h('div', { className: 'rb-l' }, t('settings.plugin'), h('small', null, t('settings.pluginHint'))), + h('span', { className: 'rb-status' }, h('span', { className: 'rb-dot rb-working', 'aria-hidden': 'true' }), t('settings.pluginOk')), + ), + h( + 'div', + { id: 'rb-settings-usage', className: 'rb-srow' }, + h('div', { className: 'rb-l' }, t('settings.idle'), h('small', null, t('settings.idleHint'))), + h( + 'select', + { + value: state.settings.idle, + 'aria-label': t('settings.idle'), + onChange: (event) => onChange({ idle: event.target.value }), + }, + h('option', { value: '15' }, t('settings.idle15')), + h('option', { value: '30' }, t('settings.idle30')), + h('option', { value: '0' }, t('settings.idleOff')), + ), + ), + h( + 'div', + { className: 'rb-srow' }, + h('div', { className: 'rb-l' }, t('settings.lowBalance'), h('small', null, t('settings.lowBalanceHint'))), + h('input', { + value: state.settings.lowBalance, + style: { width: 76 }, + inputMode: 'decimal', + 'aria-label': t('settings.lowBalance'), + onChange: (event) => onChange({ lowBalance: event.target.value.replace(/[^\d.]/g, '').slice(0, 8) }), + }), + ), + h( + 'div', + { id: 'rb-settings-notifications', className: 'rb-srow' }, + h('div', { className: 'rb-l' }, t('settings.notify'), h('small', null, t('settings.notifyHint'))), + h(Toggle, { + on: state.settings.notifications, + label: `${t('settings.notify')} ${state.settings.notifications ? t('routine.on') : t('routine.off')}`, + onClick: () => onChange({ notifications: !state.settings.notifications }), + }), + ), + h( + 'div', + { id: 'rb-settings-appearance', className: 'rb-srow' }, + h('div', { className: 'rb-l' }, t('settings.language'), h('small', null, t('settings.languageHint'))), + h( + 'select', + { + value: shownLang, + 'aria-label': t('settings.language'), + onChange: (event) => onChange({ lang: event.target.value }), + }, + h('option', { value: 'en' }, t('settings.langEn')), + h('option', { value: 'zh' }, t('settings.langZh')), + ), + ), + ), + ) + } + + function PanelIcon({ size }) { + const edge = typeof size === 'number' && size > 0 ? size : 20 + return h( + 'svg', + { + width: edge, + height: edge, + viewBox: '0 0 24 24', + fill: 'none', + stroke: 'currentColor', + strokeWidth: 1.7, + strokeLinecap: 'round', + strokeLinejoin: 'round', + 'aria-hidden': 'true', + }, + h('rect', { x: 3.2, y: 4.2, width: 17.6, height: 12.4, rx: 2 }), + h('path', { d: 'M8 20.4h8M12 16.6v3.8' }), + h('circle', { cx: 9, cy: 10.4, r: 1.1 }), + h('circle', { cx: 15, cy: 10.4, r: 1.1 }), + ) + } + return { inject: ['slots'], apply(ctx) { @@ -99,7 +2038,14 @@ window.__ModuleLoader__.load({ name: 'sidebar.panellist', id: PANEL_ID, order: 30, - label: () => 'Bots', + label: () => { + try { + const id = String((ctx.get?.('locale') ?? ctx.locale)?.getLocale?.()?.id ?? '') + return id.toLowerCase().startsWith('zh') ? ZH.panel.label : EN.panel.label + } catch { + return 'Bots' + } + }, }, PanelIcon, ), @@ -110,7 +2056,7 @@ window.__ModuleLoader__.load({ name: 'main', key: PANEL_ID, }, - BotsPage, + () => h(BotsApp, { ctx }), ), ) }, diff --git a/packages/dsh-rayrun-bots/index.js b/packages/dsh-rayrun-bots/index.js index 0f94542..1da5a4d 100644 --- a/packages/dsh-rayrun-bots/index.js +++ b/packages/dsh-rayrun-bots/index.js @@ -1,9 +1,10 @@ /** * Host half of the Rayrun Bot bundle. * - * A1 skeleton: one same-origin RPC route with a health action. Bots, sessions, - * approvals and the adapter to dsh-rayrun-computer are not built yet; the client - * half shows a placeholder page until they are. + * One same-origin RPC route with a health action. Bots, sessions, approvals + * and the adapter to dsh-rayrun-computer are not built yet. The client half + * renders the v0.1 shell from in-memory preview data and does not call this + * route. * * POST is same-origin gated: a browser `Origin` that does not match the `Host` * the request reached is refused. GET is read-only. The route never touches diff --git a/packages/dsh-rayrun-bots/locale/en.json b/packages/dsh-rayrun-bots/locale/en.json index 2e88819..7c8a2cc 100644 --- a/packages/dsh-rayrun-bots/locale/en.json +++ b/packages/dsh-rayrun-bots/locale/en.json @@ -1,11 +1,245 @@ { "panel": { - "label": "Bots", - "title": "Bots" + "label": "Bots" }, - "placeholder": { + "brand": "Rayrun Bot", + "list": { + "search": "Search", + "searchPlaceholder": "Search bots", + "newBot": "New bot", + "settings": "Settings", + "empty": "No matching bots" + }, + "attention": { + "needs": "needs attention", + "unread": "unread", + "working": "working" + }, + "approval": { + "title": "Needs approval", + "allowOnce": "Allow once", + "deny": "Deny", + "waits": "waits for you", + "expires": "expires in {n} min", + "expired": "Expired — the bot did not act", + "irreversible": "This can't be undone.", + "outside": "This shares data outside your computer.", + "warning": "This shares data outside your computer, and it can't be undone.", + "allowedLocal": "Allowed once, on this page only. Nothing was sent.", + "deniedLocal": "Denied, on this page only. Nothing was sent.", + "snippetAllowed": "Allowed once — not sent", + "snippetDenied": "Denied — not sent" + }, + "draft": { + "send": "Send", + "discard": "Discard" + }, + "details": { + "activity": "Activity", + "library": "Library", + "recent": "Recent", + "recentEmpty": "Nothing recent.", + "upcoming": "Upcoming", + "computer": "Computer", + "usage": "Usage", + "jobComputer": "{job} · {computer}" + }, + "receipt": { + "ready": "Ready", + "waiting": "Waiting", + "done": "Done" + }, + "library": { + "today": "Today", + "week": "This week", + "older": "Older", + "empty": "No artifacts yet." + }, + "routine": { + "empty": "No routines yet.", + "on": "on", + "off": "off" + }, + "computer": { + "live": "live", + "reconnecting": "reconnecting…", + "unreachable": "Couldn't reach the computer.", + "sleeping": "sleeping", + "takeOver": "Take over", + "open": "Open", + "view": "View", + "onComputer": "On the computer · {where}", + "desktopLater": "The desktop opens in the cloud-computer plugin. This page can't open it yet." + }, + "notice": { + "recovering": "The bot host is restarting. This conversation resumes on its own.", + "reconnecting": "Computer reconnecting… retrying in 5s", + "attach": "Attachments aren't available in this preview.", + "preview": "In-memory preview. Nothing on this page is saved, and approvals are not sent to a worker." + }, + "composer": { + "placeholder": "Message {name}…", + "attach": "Add attachment", + "send": "Send" + }, + "usage": { + "balanceLine": "Balance {balance} · {hours} machine-hours", + "weekLine": "This week {spend} · idle stop {idle}", + "sampleBalance": "¥41.20", + "sampleHours": "38.4", + "sampleSpend": "¥6.80" + }, + "cost": { + "low": "Balance is low — top up in the Rayrun console. Stop is safe; destroy is not." + }, + "empty": { "heading": "No bots yet", - "body": "The bot layer is being built. This page is the A1 skeleton." + "body": "Create one with the plus button. It stays on this page until a bot host exists.", + "thread": "No messages yet. What you type stays on this page.", + "snippet": "No messages yet" + }, + "newBot": { + "title": "New bot", + "sub": "Give it a name and one job. Instructions can be changed later.", + "monogramHint": "Letter avatar · color is assigned from the name", + "name": "Name", + "job": "Job, one line", + "instructions": "Instructions, optional", + "placeholder": "You are {name}, a teammate on the user's team. Your job: …", + "defaultName": "Weekly Watch", + "defaultJob": "Summarises weekly PRs and drafts the digest", + "cancel": "Cancel", + "create": "Create bot" + }, + "persona": { + "template": "You are {name}, a teammate on the user's team.\nYour job: {job}.\nWork in short, factual updates. Say what you did, what you did not do, and what you need next. Ask before any action that leaves this computer (messages, publishing, spending, another machine). Never claim work you have not verified.\nIf something is unclear, ask one question instead of guessing." + }, + "setup": { + "title": "Set up Rayrun Bot", + "sub": "Four steps. Each one says what is missing and where to fix it.", + "back": "Back", + "skip": "Skip for now", + "continue": "Continue", + "steps": { + "dependency": "Dependency", + "rayrun": "Rayrun", + "key": "DeepSeek key", + "bot": "First bot" + }, + "dependencyTitle": "Cloud-computer plugin", + "dependencyBody": "Cloud computers come from the separate dsh-rayrun-computer plugin. This page cannot see whether it is installed.", + "dependencyStatus": "Not checked", + "rayrunTitle": "Connect Rayrun", + "rayrunBody": "The cloud computer is provided by Rayrun. Sign in with your own account. The token stays in the DSH vault.", + "signIn": "Sign in with Rayrun", + "notConnected": "Not connected", + "tokenPlaceholder": "…or paste a Rayrun API token", + "connect": "Connect", + "accountLine": "Account: — · Balance: —", + "signInLater": "Sign-in lives in the cloud-computer plugin. This page can't start it, and it does not store a token.", + "tokenIgnored": "That token was not saved. This page never keeps it, and the bot host cannot store one yet.", + "keyTitle": "DeepSeek key", + "keyBody": "Rayrun injects the key into the agent process. It does not go into the workspace, and this page never stores it.", + "keyPlaceholder": "…or paste a DeepSeek API key", + "keySave": "Save", + "keyIgnored": "That key was not saved. This page never keeps a DeepSeek key.", + "botTitle": "First bot", + "botBody": "Give it a name and one job. It is added to this page only, not to a cloud computer." + }, + "settings": { + "title": "Settings", + "sub": "Account, usage, and the few settings this plugin owns.", + "account": "Account", + "usage": "Usage", + "notifications": "Notifications", + "appearance": "Appearance", + "rayrunAccount": "Rayrun account", + "rayrunHint": "Token stays in the DSH vault · host side only", + "connected": "Connected", + "plugin": "Cloud-computer plugin", + "pluginHint": "dsh-rayrun-computer v1.0.0", + "pluginOk": "OK", + "idle": "Idle stop", + "idleHint": "Stop the computer when idle. Never destroy it.", + "idle15": "15 minutes", + "idle30": "30 minutes", + "idleOff": "Off", + "lowBalance": "Low-balance reminder", + "lowBalanceHint": "Show a notice when the balance drops below this.", + "notify": "Notifications", + "notifyHint": "Notify when a bot finishes or needs you.", + "language": "Language", + "languageHint": "English or 简体中文", + "langEn": "English", + "langZh": "简体中文" + }, + "sample": { + "user": { + "name": "Haoyi", + "initials": "HY", + "foot": "Rayrun connected · {balance}" + }, + "nora": { + "name": "Nora", + "job": "weekly digest", + "snippet": "Draft is in the library, waiting for you", + "time": "20:07", + "user": "Summarize last week's PRs and draft the weekly digest. Wait for me before publishing.", + "day": "Today 20:07", + "reply1": "The draft is ready. I kept it to five sections, and each item links back to its PR.\n\n- **Scope.** 14 merged PRs, 2 still open, 1 reverted.\n- **Draft.** `week-45-digest.md` in the workspace, 420 words.\n- **Next.** Publishing to `#weekly` needs your approval.", + "reply2": "The draft is in the Library tab if you want to read it first. I'll wait for your answer.", + "computerTitle": "On the computer · Feishu #weekly", + "computerSub": "Pasted the digest, waiting for your approval", + "approvalTitle": "Publish “Week 45 digest” to Feishu #weekly", + "approvalMeta": "Requested 20:07 · from this chat", + "r1": "Draft the weekly digest", + "r1meta": "09:13 · 3 artifacts · today ¥3.10", + "r2": "Publish to #weekly", + "r2meta": "Needs your approval · waits for you", + "r3": "Docs refresh", + "r3meta": "08:40 · 3 pages · today ¥0.60", + "f1": "week-45-digest.md", + "f1badge": "420 words", + "f1meta": "Created by Nora · 09:13", + "f2": "channel-preview.png", + "f2badge": "Image", + "f2meta": "Sent in this chat · 09:12", + "f3": "week-44-digest.md", + "f3badge": "Done", + "f3meta": "Created by Nora · Monday", + "f4": "Feishu channel", + "f4badge": "Link", + "f4meta": "Last week" + }, + "eli": { + "name": "Eli", + "job": "channel publish", + "snippet": "Needs approval: publish the digest", + "time": "09:13", + "day": "Today 09:13", + "reply": "Publishing would send the digest to the channel. I'm stopped here until you approve.", + "approvalTitle": "Publish “Week 45 digest” to Feishu #weekly", + "approvalMeta": "Requested 09:13 · from this chat" + }, + "june": { + "name": "June", + "job": "docs", + "snippet": "Docs refresh finished — 3 pages", + "time": "08:40", + "day": "Today 08:40", + "reply": "Docs refresh is finished, 3 pages. Nothing needs your approval.", + "r1": "Docs refresh", + "r1meta": "08:40 · 3 pages · today ¥0.60" + }, + "routine": { + "weekly": "Weekly digest", + "weeklyWhen": "Friday · 09:00", + "inbox": "Inbox sweep", + "inboxWhen": "Weekdays · 08:00", + "standup": "Standup notes", + "standupWhen": "Weekdays · 18:00" + }, + "computerName": "dsh-workspace" }, "error": { "hostDown": "The bot host is not responding." diff --git a/packages/dsh-rayrun-bots/locale/zh.json b/packages/dsh-rayrun-bots/locale/zh.json index baa5b85..ecfcc23 100644 --- a/packages/dsh-rayrun-bots/locale/zh.json +++ b/packages/dsh-rayrun-bots/locale/zh.json @@ -1,11 +1,245 @@ { "panel": { - "label": "Bots", - "title": "Bots" + "label": "Bots" }, - "placeholder": { + "brand": "Rayrun Bot", + "list": { + "search": "搜索", + "searchPlaceholder": "搜索 Bot", + "newBot": "新建 Bot", + "settings": "设置", + "empty": "没有匹配的 Bot" + }, + "attention": { + "needs": "待你处理", + "unread": "未读", + "working": "工作中" + }, + "approval": { + "title": "需要审批", + "allowOnce": "仅批准这一次", + "deny": "拒绝", + "waits": "等你处理", + "expires": "{n} 分钟后过期", + "expired": "已过期——Bot 没有执行", + "irreversible": "此操作无法撤销。", + "outside": "这会把数据发到你的电脑之外。", + "warning": "这会把数据发到你的电脑之外,且无法撤销。", + "allowedLocal": "只记在这一页:已批准一次。没有发送到任何地方。", + "deniedLocal": "只记在这一页:已拒绝。没有发送到任何地方。", + "snippetAllowed": "已批准一次 · 未发送", + "snippetDenied": "已拒绝 · 未发送" + }, + "draft": { + "send": "发送", + "discard": "丢弃" + }, + "details": { + "activity": "动态", + "library": "资料库", + "recent": "最近", + "recentEmpty": "最近没有动态。", + "upcoming": "即将进行", + "computer": "电脑", + "usage": "用量", + "jobComputer": "{job} · {computer}" + }, + "receipt": { + "ready": "已就绪", + "waiting": "等待中", + "done": "已完成" + }, + "library": { + "today": "今天", + "week": "本周", + "older": "更早", + "empty": "还没有产物。" + }, + "routine": { + "empty": "还没有日程。", + "on": "开", + "off": "关" + }, + "computer": { + "live": "在线", + "reconnecting": "正在重连…", + "unreachable": "连不上电脑。", + "sleeping": "休眠", + "takeOver": "接管", + "open": "打开", + "view": "查看", + "onComputer": "电脑上 · {where}", + "desktopLater": "桌面在云电脑插件里。这一页还打不开它。" + }, + "notice": { + "recovering": "Bot host 正在重启,这个会话会自动恢复。", + "reconnecting": "电脑正在重连… 5 秒后重试", + "attach": "这个预览里还不能添加附件。", + "preview": "这是页内预览。内容不会保存,审批也不会发给 worker。" + }, + "composer": { + "placeholder": "给 {name} 发消息…", + "attach": "添加附件", + "send": "发送" + }, + "usage": { + "balanceLine": "余额 {balance} · {hours} 机时", + "weekLine": "本周 {spend} · 空闲停机 {idle}", + "sampleBalance": "¥41.20", + "sampleHours": "38.4", + "sampleSpend": "¥6.80" + }, + "cost": { + "low": "余额偏低——去 Rayrun 控制台充值。停机会保留磁盘,销毁不会。" + }, + "empty": { "heading": "还没有 Bot", - "body": "Bot 层正在建设中。这个页面是 A1 骨架。" + "body": "用加号新建一个。在 Bot host 出现之前,它只留在这一页。", + "thread": "还没有消息。你输入的内容只留在这一页。", + "snippet": "还没有消息" + }, + "newBot": { + "title": "新建 Bot", + "sub": "给它一个名字和一项职责,指令之后可以再改。", + "monogramHint": "字母头像 · 颜色由名字自动分配", + "name": "名字", + "job": "职责(一行)", + "instructions": "指令(可选)", + "placeholder": "你是 {name},用户团队里的一名同事。你的职责: …", + "defaultName": "Weekly Watch", + "defaultJob": "Summarises weekly PRs and drafts the digest", + "cancel": "取消", + "create": "创建 Bot" + }, + "persona": { + "template": "你是 {name},用户团队里的一名同事。\n你的职责:{job}。\n用简短、事实性的更新汇报:做了什么、没做什么、下一步需要什么。任何离开这台电脑的动作(发消息、发布、花钱、动另一台机器)先征求同意。不要声称未经验证的结果。不清楚时只问一个关键问题,不要猜。" + }, + "setup": { + "title": "设置 Rayrun Bot", + "sub": "四步。每一步都会显示还缺什么、去哪里补。", + "back": "返回", + "skip": "暂时跳过", + "continue": "继续", + "steps": { + "dependency": "依赖", + "rayrun": "Rayrun", + "key": "DeepSeek key", + "bot": "第一个 Bot" + }, + "dependencyTitle": "检查云电脑插件", + "dependencyBody": "云电脑由单独的 dsh-rayrun-computer 插件提供。这一页还不能检查它是否已安装。", + "dependencyStatus": "未检查", + "rayrunTitle": "连接 Rayrun", + "rayrunBody": "云电脑由 Rayrun 提供。用你自己的账号登录,token 只存在 DSH 凭证库里。", + "signIn": "用 Rayrun 登录", + "notConnected": "未连接", + "tokenPlaceholder": "…或粘贴 Rayrun API token", + "connect": "连接", + "accountLine": "账号:— · 余额:—", + "signInLater": "登录在云电脑插件里完成。这一页不能替你开始,也不会保存 token。", + "tokenIgnored": "没有保存这个 token。这一页不留存它,Bot host 也还不能代存。", + "keyTitle": "DeepSeek key", + "keyBody": "key 由 Rayrun 注入到 agent 进程,不会进入工作区。这一页不保存 key。", + "keyPlaceholder": "…或粘贴 DeepSeek API key", + "keySave": "保存", + "keyIgnored": "没有保存这个 key。这一页不留存 DeepSeek key。", + "botTitle": "第一个 Bot", + "botBody": "给它一个名字和一项职责。它只加到这一页,不会出现在云电脑上。" + }, + "settings": { + "title": "设置", + "sub": "账号、用量,以及这个插件自己的少量设置。", + "account": "账号", + "usage": "用量", + "notifications": "通知", + "appearance": "外观", + "rayrunAccount": "Rayrun 账号", + "rayrunHint": "token 存在 DSH 凭证库 · 只在 Host 侧", + "connected": "已连接", + "plugin": "云电脑插件", + "pluginHint": "dsh-rayrun-computer v1.0.0", + "pluginOk": "正常", + "idle": "空闲停机", + "idleHint": "空闲时停止电脑,绝不销毁。", + "idle15": "15 分钟", + "idle30": "30 分钟", + "idleOff": "关闭", + "lowBalance": "低余额提醒", + "lowBalanceHint": "余额低于该值时显示提示。", + "notify": "通知", + "notifyHint": "Bot 完成或等你处理时通知。", + "language": "语言", + "languageHint": "English 或 简体中文", + "langEn": "English", + "langZh": "简体中文" + }, + "sample": { + "user": { + "name": "Haoyi", + "initials": "HY", + "foot": "Rayrun 已连接 · {balance}" + }, + "nora": { + "name": "Nora", + "job": "每周摘要", + "snippet": "草稿在资料库里,等你答复", + "time": "20:07", + "user": "总结上周的 PR,并起草每周摘要。发布前等我确认。", + "day": "今天 20:07", + "reply1": "草稿好了。我控制在五个小节,每一项都链回了对应 PR。\n\n- **范围。**14 个已合并 PR,2 个仍开着,1 个已回滚。\n- **草稿。**工作区里的 `week-45-digest.md`,420 字。\n- **下一步。**发布到 `#weekly` 需要你批准。", + "reply2": "如果你想先看草稿,它在「资料库」标签里。我会等你答复。", + "computerTitle": "电脑上 · Feishu #weekly", + "computerSub": "已粘贴摘要,等待你的审批", + "approvalTitle": "发布《Week 45 摘要》到 Feishu #weekly", + "approvalMeta": "请求于 20:07 · 来自本对话", + "r1": "起草每周摘要", + "r1meta": "09:13 · 3 个产物 · 今日 ¥3.10", + "r2": "发布到 #weekly", + "r2meta": "需要你的审批 · 等你处理", + "r3": "文档刷新", + "r3meta": "08:40 · 3 页 · 今日 ¥0.60", + "f1": "week-45-digest.md", + "f1badge": "420 字", + "f1meta": "由 Nora 创建 · 09:13", + "f2": "channel-preview.png", + "f2badge": "图片", + "f2meta": "本对话中发送 · 09:12", + "f3": "week-44-digest.md", + "f3badge": "已完成", + "f3meta": "由 Nora 创建 · 周一", + "f4": "Feishu 频道", + "f4badge": "链接", + "f4meta": "上周" + }, + "eli": { + "name": "Eli", + "job": "频道发布", + "snippet": "待审批:发布摘要", + "time": "09:13", + "day": "今天 09:13", + "reply": "发布会把摘要发到频道里,我停在这里等你批准。", + "approvalTitle": "发布《Week 45 摘要》到 Feishu #weekly", + "approvalMeta": "请求于 09:13 · 来自本对话" + }, + "june": { + "name": "June", + "job": "文档", + "snippet": "文档刷新完成 — 3 页", + "time": "08:40", + "day": "今天 08:40", + "reply": "文档刷新完成,一共 3 页。没有需要你批准的动作。", + "r1": "文档刷新", + "r1meta": "08:40 · 3 页 · 今日 ¥0.60" + }, + "routine": { + "weekly": "每周摘要", + "weeklyWhen": "周五 · 09:00", + "inbox": "收件箱清扫", + "inboxWhen": "工作日 · 08:00", + "standup": "站会纪要", + "standupWhen": "工作日 · 18:00" + }, + "computerName": "dsh-workspace" }, "error": { "hostDown": "Bot host 没有响应。" diff --git a/packages/dsh-rayrun-bots/package.json b/packages/dsh-rayrun-bots/package.json index 6864ba2..5d7a751 100644 --- a/packages/dsh-rayrun-bots/package.json +++ b/packages/dsh-rayrun-bots/package.json @@ -34,7 +34,8 @@ "platform": "web", "immediately": true, "inject": [ - "@deepseek-ai/dsh-client-ui-sidebar" + "@deepseek-ai/dsh-client-ui-sidebar", + "@deepseek-ai/dsh-client-locale" ] } } diff --git a/packages/dsh-rayrun-bots/test/client-contract.mjs b/packages/dsh-rayrun-bots/test/client-contract.mjs new file mode 100644 index 0000000..7bd41f9 --- /dev/null +++ b/packages/dsh-rayrun-bots/test/client-contract.mjs @@ -0,0 +1,118 @@ +/** + * Client-shell contract. + * + * The page is one file, so the locale catalogs are embedded next to + * locale/en.json and locale/zh.json. This check keeps those copies identical, + * requires the v0.1 copy deck, and refuses a client that still shows the A1 + * placeholder or reaches off the machine. + * + * node test/client-contract.mjs + */ +import assert from 'node:assert/strict' +import { readFileSync } from 'node:fs' +import path from 'node:path' +import { fileURLToPath } from 'node:url' + +const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..') +const client = readFileSync(path.join(root, 'client.js'), 'utf8') +const en = JSON.parse(readFileSync(path.join(root, 'locale/en.json'), 'utf8')) +const zh = JSON.parse(readFileSync(path.join(root, 'locale/zh.json'), 'utf8')) + +function extractCatalog(source, name) { + const token = `const ${name} = ` + const start = source.indexOf(token) + assert.notEqual(start, -1, `missing ${name} catalog`) + let i = start + token.length + while (source[i] === ' ' || source[i] === '\n') i += 1 + assert.equal(source[i], '{', `${name} catalog must be an object literal`) + let depth = 0 + let inString = false + let escaped = false + for (let j = i; j < source.length; j += 1) { + const ch = source[j] + if (inString) { + if (escaped) escaped = false + else if (ch === '\\') escaped = true + else if (ch === '"') inString = false + continue + } + if (ch === '"') inString = true + else if (ch === '{') depth += 1 + else if (ch === '}') { + depth -= 1 + if (depth === 0) return JSON.parse(source.slice(i, j + 1)) + } + } + throw new Error(`unterminated ${name} catalog`) +} + +const embeddedEn = extractCatalog(client, 'EN') +const embeddedZh = extractCatalog(client, 'ZH') +assert.deepEqual(embeddedEn, en, 'client EN catalog drifted from locale/en.json') +assert.deepEqual(embeddedZh, zh, 'client ZH catalog drifted from locale/zh.json') + +function flatten(value, prefix = '', out = []) { + for (const [key, child] of Object.entries(value)) { + const next = prefix ? `${prefix}.${key}` : key + if (child && typeof child === 'object' && !Array.isArray(child)) flatten(child, next, out) + else out.push(next) + } + return out +} + +const keys = new Set(flatten(en)) +const required = [ + 'list.search', + 'list.newBot', + 'attention.needs', + 'attention.unread', + 'attention.working', + 'approval.title', + 'approval.allowOnce', + 'approval.deny', + 'approval.waits', + 'approval.expires', + 'approval.expired', + 'approval.irreversible', + 'approval.outside', + 'draft.send', + 'draft.discard', + 'details.recent', + 'details.upcoming', + 'details.computer', + 'details.usage', + 'computer.live', + 'computer.reconnecting', + 'computer.unreachable', + 'computer.takeOver', + 'notice.recovering', + 'cost.low', + 'error.hostDown', + 'persona.template', +] +for (const key of required) assert.equal(keys.has(key), true, `missing copy-deck key ${key}`) + +assert.equal(zh.approval.allowOnce, '仅批准这一次') +assert.equal(zh.approval.deny, '拒绝') +assert.equal(zh.approval.warning, '这会把数据发到你的电脑之外,且无法撤销。') +assert.equal(zh.sample.nora.user, '总结上周的 PR,并起草每周摘要。发布前等我确认。') +assert.equal(zh.notice.reconnecting, '电脑正在重连… 5 秒后重试') +assert.equal(zh.setup.signIn, '用 Rayrun 登录') +assert.equal(zh.newBot.title, '新建 Bot') +assert.equal(zh.settings.title, '设置') +assert.equal(en.newBot.defaultJob, zh.newBot.defaultJob) + +assert.equal(client.includes('The bot layer is under construction'), false) +assert.equal(client.includes('A1 skeleton'), false) +assert.match(client, /M2\.97 12\.92A2 2 0 0 0 2 14\.63/) +assert.match(client, /stroke: '#003d9b'/) +assert.equal(client.includes('fetch('), false) +assert.equal(client.includes('localStorage'), false) +assert.equal(client.includes('sessionStorage'), false) +assert.equal(/console\.(log|debug|info|warn|error)\(/.test(client), false) +for (const screen of ['chat', 'newbot', 'setup', 'settings']) { + assert.match(client, new RegExp(`data-screen': '${screen}'`)) +} +assert.match(client, /data-screen': 'chat'[\s\S]*library/) + +console.log('client contract ok')