mirror of
https://github.com/dtzp555-max/ocm.git
synced 2026-07-21 21:15:08 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8ae5fdb20c | ||
|
|
c3ed4c9c8f | ||
|
|
0a5f963b14 | ||
|
|
9e3ec7b616 | ||
|
|
55bfdcdbc8 | ||
|
|
c6da627fed | ||
|
|
743b8acea1 | ||
|
|
e0ebe68fb5 | ||
|
|
1c894d4ee7 |
@@ -1,10 +1,30 @@
|
||||
# OpenClaw Manager — 开发日志
|
||||
|
||||
> 最后更新:2026-02-28
|
||||
> 当前版本:v0.7.1
|
||||
> 最后更新:2026-03-01
|
||||
> 当前版本:v0.9.0
|
||||
|
||||
---
|
||||
|
||||
|
||||
## v0.9.0 更新日志(2026-03-01)
|
||||
|
||||
### New Features
|
||||
|
||||
- Agents: Add Agent / Add Sub-Agent 向导支持 Telegram + Discord
|
||||
- Telegram: 传统 group 绑定
|
||||
- Discord: 主 Agent 建议绑定 Channel;Sub-Agent 建议绑定 Thread
|
||||
- Routing: 删除绑定提示文案增强(支持“更换 group/thread → 先删旧绑定再加新绑定”)
|
||||
|
||||
### UX / UI
|
||||
|
||||
- 顶部居中显示醒目的 OCM 版本标识
|
||||
- Agents 页面:Agent Tree 支持显示 bindings 概览(Telegram/Discord)并按 parentAgentId 分组
|
||||
- Setup Guide:补全 Telegram Allow Groups 步骤;Discord guide 按 channel/thread 经验重写
|
||||
|
||||
### Fixes
|
||||
|
||||
- 修复 MAIN_HTML_SCRIPT 内联 JS 语法问题(tree toggle / i18n 单引号等),避免启动自检失败
|
||||
|
||||
## Unreleased(2026-02-28)
|
||||
|
||||
### Dashboard / Layout
|
||||
|
||||
@@ -1,40 +1,74 @@
|
||||
# OpenClaw Manager (OCM)
|
||||
|
||||
A zero-dependency, single-file web dashboard for [OpenClaw](https://github.com/anthropics/openclaw). Manage agents, monitor token usage, and run commands — all from your browser, no `npm install` required.
|
||||
A local control panel for [OpenClaw](https://github.com/anthropics/openclaw) that makes setup checks, agent management, health inspection, and recovery much easier — without living in JSON and terminal tabs all day.
|
||||
|
||||
[中文说明](#中文说明) · [中文使用说明(含截图)](docs/USAGE_GUIDE.zh-CN.md) · [English Guide (with screenshots)](docs/USAGE_GUIDE.en.md)
|
||||
|
||||
---
|
||||
|
||||
## Quick Start
|
||||
## Why OCM exists
|
||||
|
||||
```bash
|
||||
# Clone
|
||||
git clone https://github.com/dtzp555-max/ocm.git
|
||||
cd ocm
|
||||
Running OpenClaw directly is powerful, but the day-to-day workflow can get messy fast:
|
||||
|
||||
# Run (no npm install needed)
|
||||
bash start.sh # macOS / Linux
|
||||
start.bat # Windows
|
||||
- `openclaw.json` is easy to break by hand
|
||||
- agent / bot / channel bindings are hard to visualize
|
||||
- health checks, logs, restarts, and rollback are scattered across terminal commands
|
||||
- when something goes wrong, recovery is slower than it should be
|
||||
|
||||
# Update
|
||||
git pull --ff-only
|
||||
```
|
||||
OCM gives you a **local control panel** for the things that become painful first:
|
||||
- seeing your current setup clearly
|
||||
- operating it more safely
|
||||
- recovering faster when something breaks
|
||||
|
||||
Open [http://localhost:3333](http://localhost:3333) in your browser. For remote access, use `bash start.sh --host 0.0.0.0`.
|
||||
## Docs
|
||||
## Is OCM for you?
|
||||
|
||||
- English guide: docs/USAGE_GUIDE.en.md
|
||||
- 中文使用说明: docs/USAGE_GUIDE.zh-CN.md
|
||||
- FAQ: docs/FAQ.md
|
||||
- Security notes: docs/SECURITY.md
|
||||
- Changelog: docs/CHANGELOG.md
|
||||
**OCM is a good fit if:**
|
||||
- you already run OpenClaw locally
|
||||
- you want a visual control panel for agents, routing, logs, health, and backups
|
||||
- you are tired of editing nested config by hand
|
||||
- you want safer rollback / recovery nearby
|
||||
|
||||
**OCM is probably not the best starting point if:**
|
||||
- you have not installed OpenClaw yet
|
||||
- you expect every OS / channel workflow to be equally mature today
|
||||
- you want a hosted cloud dashboard instead of a local tool
|
||||
|
||||
## Features
|
||||
## What OCM helps you do
|
||||
|
||||
### 1) See your OpenClaw setup clearly
|
||||
- inspect agents and sub-agents in a tree
|
||||
- verify bindings and routing
|
||||
- view models, auth, usage, and health in one place
|
||||
|
||||
### 2) Operate OpenClaw with less risk
|
||||
- restart gateway
|
||||
- inspect logs
|
||||
- run OpenClaw commands from the built-in terminal
|
||||
- make config changes with rollback nearby
|
||||
|
||||
### 3) Recover faster when things go wrong
|
||||
- browse backups / snapshots
|
||||
- roll back config safely
|
||||
- keep troubleshooting and operational tools close to the same UI
|
||||
|
||||
## See it quickly
|
||||
|
||||
These are the highest-value surfaces for first-time users:
|
||||
|
||||
<p>
|
||||
<img src="docs/redacted-screenshots-refresh/dashboard-2026-03-07.jpg" width="860" />
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<img src="docs/redacted-screenshots-refresh/agents-2026-03-07.jpg" width="280" />
|
||||
<img src="docs/redacted-screenshots-refresh/cli-2026-03-07.jpg" width="280" />
|
||||
<img src="docs/redacted-screenshots/actions.jpg" width="180" />
|
||||
</p>
|
||||
|
||||
More screenshots: see the [full usage guide](docs/USAGE_GUIDE.en.md) or the gallery below.
|
||||
|
||||
<details>
|
||||
<summary><b>Screenshots</b> (redacted: no personal paths, no Telegram IDs)</summary>
|
||||
<summary><b>Full screenshots gallery</b> (redacted: no personal paths, no Telegram IDs)</summary>
|
||||
|
||||
<p>
|
||||
<img src="docs/redacted-screenshots/dashboard.jpg" width="240" />
|
||||
@@ -52,6 +86,76 @@ Open [http://localhost:3333](http://localhost:3333) in your browser. For remote
|
||||
|
||||
</details>
|
||||
|
||||
## Quick Start (recommended path)
|
||||
|
||||
```bash
|
||||
# Clone
|
||||
git clone https://github.com/dtzp555-max/ocm.git
|
||||
cd ocm
|
||||
|
||||
# Run (no npm install needed)
|
||||
bash start.sh # macOS / Linux
|
||||
start.bat # Windows
|
||||
```
|
||||
|
||||
Then open [http://localhost:3333](http://localhost:3333).
|
||||
|
||||
For remote access, use:
|
||||
|
||||
```bash
|
||||
bash start.sh --host 0.0.0.0
|
||||
```
|
||||
|
||||
## First-run checklist
|
||||
|
||||
For a good first experience, do these first:
|
||||
|
||||
1. Confirm OCM found the correct OpenClaw directory
|
||||
2. Open **Dashboard** and check gateway health
|
||||
3. Open **Agents** / **Channels** and inspect bindings
|
||||
4. Open the built-in **Terminal** and run one OpenClaw command
|
||||
5. Check **Actions** / backup / rollback so recovery is nearby before you need it
|
||||
|
||||
## Current support status
|
||||
|
||||
**Best supported today**
|
||||
- macOS / Linux
|
||||
- local OpenClaw installations
|
||||
- local health / logs / ops / backup workflows
|
||||
- Telegram-first agent management workflows
|
||||
|
||||
**Supported, but not equally smooth in every case**
|
||||
- Discord agent / thread workflows
|
||||
- more advanced routing setups
|
||||
- mixed environment / service layouts
|
||||
|
||||
**Not the primary path today**
|
||||
- fully beginner-first OpenClaw onboarding
|
||||
- every OS / shell / service combination
|
||||
- WhatsApp-heavy sub-agent topology workflows
|
||||
|
||||
## Common friction points
|
||||
|
||||
The most common reasons OCM feels rough are not usually “the UI is broken”, but environment mismatch:
|
||||
|
||||
- OpenClaw itself is not fully healthy yet
|
||||
- wrong OpenClaw directory
|
||||
- path / permission issues
|
||||
- different service/runtime layouts across machines
|
||||
- channel workflow differences
|
||||
|
||||
That is why OCM should be thought of as a **control panel for an existing OpenClaw setup**, not a magic replacement for all installation complexity.
|
||||
|
||||
## Docs
|
||||
|
||||
- **Start here**: docs/USAGE_GUIDE.en.md
|
||||
- 中文使用说明: docs/USAGE_GUIDE.zh-CN.md
|
||||
- FAQ: docs/FAQ.md
|
||||
- Security notes: docs/SECURITY.md
|
||||
- Changelog: docs/CHANGELOG.md
|
||||
|
||||
## Features by area
|
||||
|
||||
- **Agent Management** — Add main agents and sub-agents through a guided setup flow. View all agents in a tree structure with model selection, workspace browsing, and inline configuration.
|
||||
- **Usage Statistics** — Real token usage data parsed directly from OpenClaw session files. Breakdown by model, agent, and day with a visual chart.
|
||||
- **Model & Auth** — Configure models from your registered provider list. Follow built-in guides for provider authentication setup.
|
||||
@@ -60,14 +164,30 @@ Open [http://localhost:3333](http://localhost:3333) in your browser. For remote
|
||||
- **Backups / Rollback** — Browse auto-snapshots of `openclaw.json*` and restore any previous version (current config is auto-backed up first).
|
||||
- **Bilingual UI** — English and Chinese interface with one-click language switching.
|
||||
|
||||
## What's New (v0.8.x)
|
||||
## What's New (v0.9.x)
|
||||
|
||||
- **Docs refresh (v0.8.x)**: updated English + Chinese guides and refreshed redacted screenshots.
|
||||
- **README screenshots gallery**: all screenshots are now grouped into one collapsible section to keep the homepage short.
|
||||
- **Discord support (v0.9.x)**: add agent/sub-agent flows for Discord (main agent binds channel; sub-agent binds thread).
|
||||
- **README screenshots gallery**: screenshots grouped into a collapsible section so the homepage stays shorter.
|
||||
- **Built-in CLI terminal**: run OpenClaw commands from any page with streaming output, presets, favorites, and Tab completion.
|
||||
- **Ops actions**: restart gateway, view logs, health check, backups (local + NAS), and cron management.
|
||||
- **Telegram-first workflow**: safer sub-agent setup flow + allowlist helper + warnings for group privacy.
|
||||
## Telegram Workflow & Safety
|
||||
|
||||
## Channel Support
|
||||
|
||||
OCM is a local UI for OpenClaw. Core features like agent trees, routing, models/auth, ops, backups, and the built-in CLI are channel-agnostic.
|
||||
|
||||
Current channel positioning:
|
||||
|
||||
- **Telegram** — best supported and most documented today
|
||||
- **Discord** — supported; recommended for private channels/threads with strict allowlist
|
||||
- **Feishu / Lark** — supported in broader OpenClaw ecosystems, but not a primary OCM workflow today
|
||||
- **WhatsApp** — not recommended for sub-agent topology workflows
|
||||
|
||||
## Recommended Workflows
|
||||
|
||||
OCM is **Telegram-first, not Telegram-only**. Telegram is the smoothest path today, but OCM is also useful for local ops, Discord routing, model/auth management, and backups.
|
||||
|
||||
### Telegram Workflow & Safety
|
||||
|
||||
OCM is designed primarily for **Telegram-based OpenClaw workflows**:
|
||||
|
||||
@@ -113,6 +233,18 @@ You can also create `manager-config.json` manually:
|
||||
|
||||
`manager-config.json` is gitignored and won't be committed.
|
||||
|
||||
## First-Run Experience
|
||||
|
||||
The first thing new users need is confidence that OCM is pointed at the right OpenClaw directory and that the gateway is healthy. The Dashboard, built-in CLI, and health/ops actions are intended to make that first-run check fast and visible.
|
||||
|
||||
Recommended first demo flow:
|
||||
|
||||
1. Start OCM
|
||||
2. Open Dashboard and confirm gateway health
|
||||
3. Open Agents / Routing and inspect bindings
|
||||
4. Run one CLI command from the built-in terminal
|
||||
5. Try backup / rollback from Ops
|
||||
|
||||
## Remote Access
|
||||
|
||||
By default OCM binds to `0.0.0.0` (all interfaces). Access it from another device on your LAN using the IP shown at startup. To restrict to localhost only:
|
||||
@@ -155,7 +287,38 @@ MIT
|
||||
|
||||
## 中文说明
|
||||
|
||||
OpenClaw Manager 是一个零依赖的本地 Web 管理界面,用于可视化管理 [OpenClaw](https://github.com/anthropics/openclaw) AI 智能体。所有代码在一个 `.js` 文件中,只需 Node.js 18+,不需要 `npm install`。
|
||||
OpenClaw Manager(OCM)是一个本地 OpenClaw 控制面板,用来更直观地管理 Agent、查看绑定关系、做健康检查、运行内置 CLI,并在改配置或排错时少踩坑。
|
||||
|
||||
### OCM 解决什么问题
|
||||
|
||||
直接使用 OpenClaw 很强,但日常维护很容易变成:
|
||||
- 改 `openclaw.json` 容易手滑
|
||||
- Agent / bot / 群 / 线程绑定关系很难一眼看清
|
||||
- 健康检查、日志、重启、回滚散落在多个终端命令里
|
||||
- 出问题时恢复链路不够顺手
|
||||
|
||||
OCM 的定位不是替代 OpenClaw,而是给现有 OpenClaw 环境加一个**本地控制台**。
|
||||
|
||||
### 适合谁
|
||||
|
||||
**适合:**
|
||||
- 已经在本机跑通 OpenClaw 的用户
|
||||
- 想更直观地管理 Agent / Routing / Health / Logs / Backups 的用户
|
||||
- 不想频繁手改复杂 JSON 的用户
|
||||
|
||||
**暂时不太适合:**
|
||||
- 还没装好 OpenClaw、希望 OCM 包办全部安装复杂度的新手
|
||||
- 默认期待所有平台 / 所有 channel 路线都同样成熟的用户
|
||||
- 想要云端托管产品而不是本地工具的用户
|
||||
|
||||
### OCM 最有价值的三件事
|
||||
|
||||
1. **看清你的 OpenClaw 结构**
|
||||
- Agent 树、绑定关系、模型、认证、健康状态更直观
|
||||
2. **更安全地做运维操作**
|
||||
- 重启 gateway、看日志、跑 CLI、改配置、回滚更顺手
|
||||
3. **出问题时恢复更快**
|
||||
- 备份、回滚、排查入口都更近
|
||||
|
||||
### 快速开始
|
||||
|
||||
@@ -166,43 +329,33 @@ bash start.sh # macOS / Linux
|
||||
start.bat # Windows
|
||||
```
|
||||
|
||||
访问 [http://localhost:3333](http://localhost:3333)。远程访问请使用 `bash start.sh --host 0.0.0.0`。
|
||||
打开 [http://localhost:3333](http://localhost:3333)。
|
||||
|
||||
### 功能
|
||||
### 第一次使用建议先做这几步
|
||||
|
||||
- **Agent 管理** — 添加主 Agent 和子 Agent,树状结构查看,内联切换模型,浏览工作区文件
|
||||
- **使用统计** — 从 OpenClaw 会话文件解析真实 Token 用量,按模型/Agent/日期维度展示
|
||||
- **模型与认证** — 管理注册模型列表,内置 Provider 认证引导
|
||||
- **内置终端** — 实时流式输出,预设命令,收藏夹,Tab 补全
|
||||
- **运维面板** — 重启网关、查看日志、健康检查、本地/NAS 备份、Cron 任务管理
|
||||
- **双语界面** — 中英文一键切换
|
||||
1. 确认 OCM 找到了正确的 OpenClaw 目录
|
||||
2. 打开 **Dashboard** 看 gateway 是否健康
|
||||
3. 打开 **Agents / Channels** 看绑定是否正确
|
||||
4. 打开内置 **Terminal** 跑一条 OpenClaw 命令
|
||||
5. 看一眼 **Actions / 备份 / 回滚**,确保恢复路径就在手边
|
||||
|
||||
### Telegram 场景与安全提示
|
||||
### 当前支持定位
|
||||
|
||||
OCM 主要面向 **Telegram 场景**:
|
||||
**目前最好用的场景:**
|
||||
- macOS / Linux
|
||||
- 本地 OpenClaw 环境
|
||||
- 本地 health / logs / ops / backup 工作流
|
||||
- Telegram-first 的 Agent 管理方式
|
||||
|
||||
- 通过群组绑定主 Agent,并在每条树下管理多个 Sub-Agent
|
||||
- 让每个 Agent 拥有独立 `workspace`、`SOUL.md`、`MEMORY.md`
|
||||
- 通过可视化方式更新 `openclaw.json`,减少手动改配置风险
|
||||
- 建议使用者已具备基础 OpenClaw CLI 操作经验(如 `onboard`、认证、查看网关日志)
|
||||
**支持,但不保证同样顺滑:**
|
||||
- Discord workflow
|
||||
- 更复杂的 routing / service 布局
|
||||
- 混合环境
|
||||
|
||||
关键安全设置(务必确认):
|
||||
### 文档
|
||||
|
||||
- BotFather 里 **Allow Groups = ON**
|
||||
- BotFather 里 **Group Privacy = OFF**
|
||||
- 每个 Agent 群组只保留“你自己 + 对应 Agent/Sub-Agent”
|
||||
- 不要邀请其他人进组(会带来安全和 API 费用风险)
|
||||
|
||||
### 配置
|
||||
|
||||
启动脚本自动检测 `~/.openclaw` 目录。如需指定其他路径:
|
||||
|
||||
```bash
|
||||
bash start.sh --dir /path/to/.openclaw --port 8080
|
||||
```
|
||||
|
||||
也可手动创建 `manager-config.json`:
|
||||
|
||||
```json
|
||||
{ "dir": "~/.openclaw" }
|
||||
```
|
||||
- 英文使用说明:docs/USAGE_GUIDE.en.md
|
||||
- 中文使用说明:docs/USAGE_GUIDE.zh-CN.md
|
||||
- FAQ:docs/FAQ.md
|
||||
- 安全说明:docs/SECURITY.md
|
||||
- 更新记录:docs/CHANGELOG.md
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
|
||||
This is a user-facing summary derived from `DEVLOG.md`.
|
||||
|
||||
## v0.9.0
|
||||
- Agents: Telegram + Discord support in Add Agent / Add Sub-Agent wizard (main agent binds channel; sub-agent binds thread).
|
||||
- UI: top-center OCM version badge; improved Telegram/Discord setup guides.
|
||||
|
||||
## v0.8.2
|
||||
- Docs: reorganize README screenshots into a collapsible gallery to reduce scroll.
|
||||
- Docs: add Backups / Rollback screenshot and README feature blurb.
|
||||
|
||||
@@ -51,3 +51,12 @@ That said, your local OpenClaw config contains sensitive information. Follow the
|
||||
- don't share raw screenshots without redaction
|
||||
|
||||
See: `docs/SECURITY.md`.
|
||||
|
||||
|
||||
## Q: 为什么 OCM 暂时不推荐 WhatsApp 的 sub-agent 工作流?
|
||||
|
||||
WhatsApp 在 bot / group 自动化、权限边界和稳定路由上限制更多。
|
||||
|
||||
OCM 的 sub-agent 模式依赖清晰的会话边界、独立路由和可控权限,因此目前更推荐 Telegram / Discord 这类更容易做隔离的渠道。
|
||||
|
||||
如果未来支持 WhatsApp,更可能先从通知或轻量交互开始,而不是多 sub-agent 群聊拓扑。
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
# OCM Screenshot Refresh Brief
|
||||
|
||||
Goal: refresh only the highest-value README screenshots first, not every screenshot.
|
||||
|
||||
## Redaction rules
|
||||
Always hide or blur:
|
||||
- Telegram / Discord IDs
|
||||
- bindings / peer IDs / thread IDs
|
||||
- local filesystem paths containing Tao's name
|
||||
- account labels if they expose personal identifiers
|
||||
- anything that looks like a secret/token
|
||||
|
||||
## Priority 1 screenshots
|
||||
|
||||
### 1) Dashboard hero
|
||||
Purpose:
|
||||
- show OCM as a real control panel
|
||||
- support the README first-run / health story
|
||||
|
||||
Wanted state:
|
||||
- Dashboard page open
|
||||
- gateway looks healthy if possible
|
||||
- cards readable
|
||||
- top bar clean
|
||||
- no obvious warning/noise unless it helps credibility
|
||||
|
||||
Frame guidance:
|
||||
- browser window wide enough to show full dashboard naturally
|
||||
- keep top navigation visible
|
||||
- avoid cropping too tightly
|
||||
|
||||
### 2) Agents page
|
||||
Purpose:
|
||||
- show the core product value: visible agent topology / structure
|
||||
|
||||
Wanted state:
|
||||
- main agent + several sub-agents visible
|
||||
- structure easy to understand at a glance
|
||||
- avoid visual clutter where possible
|
||||
- keep model selectors/buttons visible, but not the focus
|
||||
|
||||
Frame guidance:
|
||||
- enough width to show the tree clearly
|
||||
- IDs and personal paths redacted
|
||||
|
||||
### 3) CLI / Terminal page
|
||||
Purpose:
|
||||
- show that OCM is not only a viewer; it can operate OpenClaw too
|
||||
|
||||
Wanted state:
|
||||
- built-in terminal open
|
||||
- a real command visible (recommended: `openclaw status` or `openclaw doctor`)
|
||||
- real output visible
|
||||
- do not use tutorial arrows / annotation bubbles
|
||||
|
||||
Frame guidance:
|
||||
- include command input and some output
|
||||
- avoid empty terminal state
|
||||
- redact paths / personal names
|
||||
|
||||
## Priority 2 screenshots
|
||||
- Actions menu
|
||||
- Backup / rollback
|
||||
- Channels
|
||||
- Models
|
||||
- Auth
|
||||
- Cron
|
||||
- Stats
|
||||
|
||||
## Selected refresh set (2026-03-07)
|
||||
- Dashboard: `docs/redacted-screenshots-refresh/dashboard-2026-03-07.jpg`
|
||||
- Agents: `docs/redacted-screenshots-refresh/agents-2026-03-07.jpg`
|
||||
- CLI: `docs/redacted-screenshots-refresh/cli-2026-03-07.jpg`
|
||||
- Keep using existing `docs/redacted-screenshots/actions.jpg` for now
|
||||
|
||||
## Notes
|
||||
- Existing `actions.jpg` is already strong and can stay for now.
|
||||
- The new Dashboard and Agents captures are preferred for README hero/overview use.
|
||||
- The new CLI capture is preferred because it shows a real command and real output.
|
||||
@@ -28,3 +28,25 @@ If you share screenshots publicly:
|
||||
- blur any tokens/keys if visible
|
||||
|
||||
This repo contains **redacted + annotated** screenshots under `docs/annotated-screenshots/`.
|
||||
|
||||
|
||||
## Discord safety
|
||||
|
||||
Recommended defaults (especially for shared/community servers):
|
||||
|
||||
- Prefer **private channels / private threads** as agent boundaries
|
||||
- Use a strict **allowlist** of channels/threads the bot may respond in
|
||||
- Avoid giving memory-enabled or high-privilege agents broad public exposure
|
||||
- Prefer least-privilege Discord permissions for the bot
|
||||
|
||||
## Feishu / Lark safety
|
||||
|
||||
Feishu is more enterprise-oriented and usually needs stricter permission design:
|
||||
|
||||
- Request the smallest permission scope possible
|
||||
- Treat chat/group visibility as a security boundary
|
||||
- Prefer separate chats/spaces for different agents to reduce context bleed
|
||||
|
||||
## WhatsApp note
|
||||
|
||||
WhatsApp is not a recommended target for sub-agent topology workflows. Constraints in bot/group automation make reliable multi-agent isolation and routing harder.
|
||||
|
||||
+52
-11
@@ -2,7 +2,7 @@
|
||||
|
||||
> Audience: People who already have OpenClaw running locally (you can run `openclaw status` and read `openclaw gateway logs`).
|
||||
>
|
||||
> Goal: Use **OpenClaw Manager (OCM)** to make agent/sub-agent setup and day-to-day ops **visual, safer, and easier to audit**.
|
||||
> Goal: Use **OpenClaw Manager (OCM)** as an **OpenClaw control panel** for agent setup, routing, health checks, built-in CLI, and safer config changes.
|
||||
|
||||
---
|
||||
|
||||
@@ -60,7 +60,18 @@ Recommended rule:
|
||||
|
||||
---
|
||||
|
||||
## 2) Start OCM (macOS)
|
||||
## 2) First-run mindset
|
||||
|
||||
For new users, the first win is not “configure everything” — it is:
|
||||
|
||||
1. Confirm OCM found the right OpenClaw directory
|
||||
2. Confirm the gateway is healthy
|
||||
3. Confirm you can inspect agents / bindings
|
||||
4. Confirm the built-in CLI works
|
||||
|
||||
That is why Dashboard + Routing + built-in CLI are the most important first-run surfaces.
|
||||
|
||||
## 3) Start OCM (macOS)
|
||||
|
||||
From the repo directory:
|
||||
|
||||
@@ -78,7 +89,7 @@ bash start.sh --host 127.0.0.1
|
||||
|
||||
---
|
||||
|
||||
## 3) Dashboard: check health first
|
||||
## 4) Dashboard: check health first
|
||||
|
||||
The Dashboard is your “sanity check”:
|
||||
|
||||
@@ -92,11 +103,11 @@ Screenshot:
|
||||
|
||||
---
|
||||
|
||||
## 4) Create a main agent (with its own Telegram bot)
|
||||
## 5) Create a main agent (with its own Telegram bot)
|
||||
|
||||
> Your `main` agent usually exists already. This section is for creating an additional **root agent** that owns its own Telegram bot/account.
|
||||
|
||||
### 4.1 BotFather prerequisites
|
||||
### 5.1 BotFather prerequisites
|
||||
|
||||
1) Create a bot
|
||||
- In Telegram, open **BotFather**
|
||||
@@ -115,7 +126,7 @@ If group privacy is ON, the bot can’t see normal group messages. The symptom o
|
||||
- “typing…” appears frequently
|
||||
- sometimes no response at all
|
||||
|
||||
### 4.2 Add the agent in OCM
|
||||
### 5.2 Add the agent in OCM
|
||||
|
||||
Go to **Agents**:
|
||||
|
||||
@@ -132,15 +143,15 @@ OCM writes the agent + Telegram account/binding into `openclaw.json`.
|
||||
|
||||
---
|
||||
|
||||
## 5) Create a sub-agent (recommended workflow)
|
||||
## 6) Create a sub-agent (recommended workflow)
|
||||
|
||||
### 5.1 Why a new group per sub-agent
|
||||
### 6.1 Why a new group per sub-agent
|
||||
|
||||
- clean context isolation
|
||||
- easier debugging
|
||||
- easy to “turn off” by muting a group
|
||||
|
||||
### 5.2 Step-by-step
|
||||
### 6.2 Step-by-step
|
||||
|
||||
In **Agents** → `+ Add Sub-Agent`:
|
||||
|
||||
@@ -172,7 +183,37 @@ If you use `channels.telegram.allowFrom`, OCM can take “Your Telegram User ID
|
||||
|
||||
---
|
||||
|
||||
## 6) Verify bindings (Channels)
|
||||
|
||||
|
||||
## 6.5) Discord workflow (main agent + sub-agent)
|
||||
|
||||
OCM also supports Discord:
|
||||
|
||||
- **Main agent**: bind to a dedicated **Channel** (channelId)
|
||||
- **Sub-agent**: bind to a dedicated **Thread** under that channel (threadId)
|
||||
|
||||
### 6.5.1 Add a Discord main agent
|
||||
|
||||
Go to **Agents** → `+ Add Agent` → set **Channel = Discord**:
|
||||
|
||||

|
||||
|
||||
Steps:
|
||||
1) Create/select a dedicated Discord **channel** (private recommended)
|
||||
2) Right-click channel → **Copy Link** → paste into the form (auto-parses channelId)
|
||||
|
||||
### 6.5.2 Add a Discord sub-agent (thread-first)
|
||||
|
||||
Go to **Agents** → `+ Add Sub-Agent` → set **Channel = Discord (thread only)**:
|
||||
|
||||

|
||||
|
||||
Steps:
|
||||
1) Create a **thread** under the main channel (one thread per task)
|
||||
2) If it is a private thread, add the bot to the thread
|
||||
3) Right-click thread → **Copy Link** → paste into the form (auto-parses threadId)
|
||||
|
||||
## 7) Verify bindings (Channels)
|
||||
|
||||
Go to **Channels**:
|
||||
|
||||
@@ -184,7 +225,7 @@ Here you can quickly validate:
|
||||
|
||||
---
|
||||
|
||||
## 7) Model settings (Models)
|
||||
## 8) Model settings (Models)
|
||||
|
||||
Go to **Models**:
|
||||
|
||||
|
||||
+54
-13
@@ -2,7 +2,7 @@
|
||||
|
||||
> 面向:已经在本机安装并跑通 OpenClaw 的用户(至少会用 `openclaw status` / `openclaw gateway logs`)
|
||||
>
|
||||
> 目标:用 **OpenClaw Manager (OCM)** 把“创建 Agent / Sub-Agent、绑定 Telegram 群、管理模型/认证、看用量、看 cron”这套流程做成可视化、可回溯、低风险。
|
||||
> 目标:把 **OpenClaw Manager (OCM)** 当成 **OpenClaw 控制台** 来用:管理 Agent、查看 Routing、做健康检查、运行内置 CLI,并更安全地修改配置。
|
||||
|
||||
---
|
||||
|
||||
@@ -54,9 +54,20 @@ OCM 的定位:**把配置变更“可视化 + 可检查 + 可回滚(配合
|
||||
|
||||
---
|
||||
|
||||
## 2) 启动与进入 OCM
|
||||
## 2) 第一次使用时最该确认什么
|
||||
|
||||
### 2.1 启动(macOS)
|
||||
对新用户来说,第一步不是“先把所有配置都改完”,而是先确认四件事:
|
||||
|
||||
1. OCM 找到的是正确的 OpenClaw 目录
|
||||
2. Gateway 是健康的
|
||||
3. Agent / Routing 能正常查看
|
||||
4. 内置终端可以正常跑命令
|
||||
|
||||
所以第一次使用时,最重要的页面其实是 Dashboard、Routing 和内置终端。
|
||||
|
||||
## 3) 启动与进入 OCM
|
||||
|
||||
### 3.1 启动(macOS)
|
||||
|
||||
在 OCM 目录:
|
||||
|
||||
@@ -68,7 +79,7 @@ bash start.sh
|
||||
|
||||
> 需要限制只能本机访问:`bash start.sh --host 127.0.0.1`
|
||||
|
||||
### 2.2 Dashboard(先看健康状态)
|
||||
### 3.2 Dashboard(先看健康状态)
|
||||
|
||||
建议第一步先看 Dashboard,确认:
|
||||
- 机器资源(CPU/RAM/DISK)
|
||||
@@ -81,11 +92,11 @@ bash start.sh
|
||||
|
||||
---
|
||||
|
||||
## 3) 创建主 Agent(Main Agent / 独立 Bot)
|
||||
## 4) 创建主 Agent(Main Agent / 独立 Bot)
|
||||
|
||||
> 你的 `main` 一般是默认存在的;这里重点讲“新增一个 **拥有独立 Telegram bot 的主 Agent**”。
|
||||
|
||||
### 3.1 BotFather 侧准备(必须)
|
||||
### 4.1 BotFather 侧准备(必须)
|
||||
|
||||
1) 创建 bot
|
||||
- 在 Telegram 找 **BotFather**
|
||||
@@ -101,7 +112,7 @@ bash start.sh
|
||||
|
||||
> 如果 Group Privacy 没关,bot 在群里看不到普通消息,会表现成“经常 typing 但没输出 / 没反应”。
|
||||
|
||||
### 3.2 在 OCM 添加主 Agent
|
||||
### 4.2 在 OCM 添加主 Agent
|
||||
|
||||
进入 **Agents** 页面:
|
||||
|
||||
@@ -117,14 +128,14 @@ bash start.sh
|
||||
|
||||
---
|
||||
|
||||
## 4) 创建 Sub-Agent(最常用)
|
||||
## 5) 创建 Sub-Agent(最常用)
|
||||
|
||||
### 4.1 为什么 Sub-Agent 要用“新群”
|
||||
### 5.1 为什么 Sub-Agent 要用“新群”
|
||||
|
||||
- 让每个 Sub-Agent 有自己独立的对话上下文、任务边界
|
||||
- 出问题直接在该群排查,不污染主 Agent 的对话
|
||||
|
||||
### 4.2 Sub-Agent 创建流程(逐步)
|
||||
### 5.2 Sub-Agent 创建流程(逐步)
|
||||
|
||||
进入 **Agents** 页面 → 点击 `+ Add Sub-Agent`,按引导做:
|
||||
|
||||
@@ -155,7 +166,37 @@ OCM 的表单里可以填 “Your Telegram User ID”,让它自动把你的 us
|
||||
|
||||
---
|
||||
|
||||
## 5) 绑定检查(Channels 页)
|
||||
|
||||
|
||||
## 6) Discord 工作流(主 Agent + Sub-Agent)
|
||||
|
||||
OCM 也支持 Discord:
|
||||
|
||||
- **主 Agent**:绑定到一个专用 **Channel**(channelId)
|
||||
- **Sub-Agent**:绑定到该 Channel 下的专用 **Thread**(threadId,thread-first)
|
||||
|
||||
### 5.1 添加 Discord 主 Agent
|
||||
|
||||
进入 **Agents** → `+ Add Agent` → 选择 **渠道 = Discord**:
|
||||
|
||||

|
||||
|
||||
步骤:
|
||||
1) 创建/选择一个专用 Discord Channel(建议私密)
|
||||
2) 右键 Channel → **Copy Link** → 粘贴到表单(自动解析 channelId)
|
||||
|
||||
### 5.2 添加 Discord Sub-Agent(Thread 优先)
|
||||
|
||||
进入 **Agents** → `+ Add Sub-Agent` → 选择 **渠道 = Discord (thread only)**:
|
||||
|
||||

|
||||
|
||||
步骤:
|
||||
1) 在主 Channel 下新建 Thread(建议“一个任务一个 thread”)
|
||||
2) 如果是 private thread,需要把 bot 拉进 thread
|
||||
3) 右键 Thread → **Copy Link** → 粘贴到表单(自动解析 threadId)
|
||||
|
||||
## 7) 绑定检查(Channels 页)
|
||||
|
||||
进入 **Channels**:
|
||||
|
||||
@@ -169,7 +210,7 @@ OCM 的表单里可以填 “Your Telegram User ID”,让它自动把你的 us
|
||||
|
||||
---
|
||||
|
||||
## 6) 模型管理(Models 页)
|
||||
## 8) 模型管理(Models 页)
|
||||
|
||||
进入 **模型**:
|
||||
|
||||
@@ -181,7 +222,7 @@ OCM 的表单里可以填 “Your Telegram User ID”,让它自动把你的 us
|
||||
|
||||
---
|
||||
|
||||
## 7) 认证管理(Auth 页)
|
||||
## 9) 认证管理(Auth 页)
|
||||
|
||||
进入 **认证**:
|
||||
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 26 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 52 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 33 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 126 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 142 KiB |
+489
-113
@@ -24,7 +24,7 @@ const SCRIPT_DIR = __dirname;
|
||||
const MANAGER_CONFIG = path.join(SCRIPT_DIR, 'manager-config.json');
|
||||
let PORT = 3333;
|
||||
let HOST = '0.0.0.0';
|
||||
const APP_VERSION = '0.8.2';
|
||||
const APP_VERSION = '0.9.3';
|
||||
// --port 参数
|
||||
const portIdx = process.argv.indexOf('--port');
|
||||
if (portIdx !== -1 && process.argv[portIdx + 1]) PORT = parseInt(process.argv[portIdx + 1]) || 3333;
|
||||
@@ -315,6 +315,28 @@ ${hasMemory ? initialMemory : '> 暂无初始记录。记忆将通过日常对
|
||||
`;
|
||||
}
|
||||
|
||||
function generateCurrentStateMd() {
|
||||
return `# CURRENT_STATE
|
||||
|
||||
_Last updated: TBD Australia/Brisbane_
|
||||
|
||||
## In Flight
|
||||
- none
|
||||
|
||||
## Blocked / Waiting
|
||||
- none
|
||||
|
||||
## Recently Finished
|
||||
- none
|
||||
|
||||
## Next
|
||||
- none
|
||||
|
||||
## Reset Summary
|
||||
- No active summary yet.
|
||||
`;
|
||||
}
|
||||
|
||||
// ── 请求解析 ──────────────────────────────────────────────────
|
||||
function parseBody(req) {
|
||||
return new Promise((resolve, reject) => {
|
||||
@@ -354,6 +376,7 @@ async function handleApi(req, res, urlObj, body) {
|
||||
})(),
|
||||
primaryModel: cfg.agents?.defaults?.model?.primary || '未配置',
|
||||
platform: process.platform,
|
||||
ocmVersion: APP_VERSION,
|
||||
}));
|
||||
} catch (e) { res.writeHead(500); res.end(JSON.stringify({ ok: false, error: e.message })); }
|
||||
return;
|
||||
@@ -423,7 +446,13 @@ async function handleApi(req, res, urlObj, body) {
|
||||
// Workspace: explicit per-agent, or defaults.workspace for main
|
||||
const workspace = a.workspace || (isMain ? defaultWorkspace : null);
|
||||
return { ...a, workspace, groupId, requireMention: groupId ? (groups[groupId]?.requireMention ?? true) : null,
|
||||
effectiveModel: modelVal || defaults.model?.primary || '默认', hasOwnBot, accountId, parentAccountId };
|
||||
effectiveModel: modelVal || defaults.model?.primary || '默认', hasOwnBot, accountId, parentAccountId, parentAgentId: a.parentAgentId || null, bindings: (bindings||[]).filter(b=>b.agentId===a.id).map(b=>({
|
||||
idx: bindings.indexOf(b),
|
||||
channel: b.match?.channel || '',
|
||||
accountId: b.match?.accountId || '',
|
||||
peerKind: b.match?.peer?.kind || '',
|
||||
peerId: b.match?.peer?.id || ''
|
||||
})) };
|
||||
});
|
||||
res.writeHead(200);
|
||||
res.end(JSON.stringify({ agents: enriched, defaults }));
|
||||
@@ -490,6 +519,7 @@ async function handleApi(req, res, urlObj, body) {
|
||||
const agentName = name || agentId;
|
||||
await fsp.writeFile(path.join(wsPath, 'SOUL.md'), generateSoulMd(agentName, purpose || '', personality || ''), 'utf8');
|
||||
await fsp.writeFile(path.join(wsPath, 'MEMORY.md'), generateMemoryMd(agentName, ''), 'utf8');
|
||||
await fsp.writeFile(path.join(wsPath, 'memory', 'CURRENT_STATE.md'), generateCurrentStateMd(), 'utf8');
|
||||
// Create agents/<id>/ runtime directory (required by OpenClaw gateway)
|
||||
const agentRuntimeDir = path.join(OPENCLAW_DIR, 'agents', agentId);
|
||||
await fsp.mkdir(agentRuntimeDir, { recursive: true });
|
||||
@@ -499,7 +529,7 @@ async function handleApi(req, res, urlObj, body) {
|
||||
ok: true, agentId, workspacePath: wsPath, configBackup: bakPath,
|
||||
notes: [
|
||||
'Agent created with its own bot token',
|
||||
'Workspace directory created with SOUL.md and MEMORY.md',
|
||||
'Workspace directory created with SOUL.md, MEMORY.md, and memory/CURRENT_STATE.md',
|
||||
'Runtime directory created at agents/' + agentId + '/',
|
||||
'Configuration updated and backed up',
|
||||
'Restart gateway to load new bot: openclaw gateway restart'
|
||||
@@ -508,6 +538,145 @@ async function handleApi(req, res, urlObj, body) {
|
||||
return;
|
||||
}
|
||||
|
||||
// POST /api/agents/discord — create top-level Discord agent (single bot, channel binding)
|
||||
if (method === 'POST' && pathname === '/api/agents/discord') {
|
||||
const { agentId, name, workspaceFolder, model, purpose, personality, guildId, channelId } = body;
|
||||
if (!agentId || !/^[a-zA-Z0-9_-]+$/.test(agentId)) {
|
||||
res.writeHead(400); res.end(JSON.stringify({ error: 'Agent ID must contain only alphanumeric characters, underscores, or dashes' })); return;
|
||||
}
|
||||
if (!name || !name.trim()) { res.writeHead(400); res.end(JSON.stringify({ error: 'Name is required' })); return; }
|
||||
const folder = (workspaceFolder || agentId).trim();
|
||||
if (!folder) { res.writeHead(400); res.end(JSON.stringify({ error: 'Workspace folder is required' })); return; }
|
||||
if (!channelId || !String(channelId).trim().match(/^\d+$/)) { res.writeHead(400); res.end(JSON.stringify({ error: 'Discord channelId is required' })); return; }
|
||||
const gid = (guildId || '').trim();
|
||||
|
||||
const cfg = await readConfig();
|
||||
if (cfg.agents?.list?.some(a => a.id === agentId)) {
|
||||
res.writeHead(400); res.end(JSON.stringify({ error: `Agent ID \"${agentId}\" already exists` })); return;
|
||||
}
|
||||
// Prevent workspace reuse
|
||||
const wsAlias = `~/.openclaw/workspaces/${folder}`;
|
||||
if (cfg.agents?.list?.some(a => (a.workspace||'').endsWith(`/workspaces/${folder}`) || a.workspace === wsAlias)) {
|
||||
res.writeHead(400); res.end(JSON.stringify({ error: `Workspace folder \"${folder}\" is already used by another agent` })); return;
|
||||
}
|
||||
|
||||
if (!cfg.agents) cfg.agents = { defaults: {}, list: [] };
|
||||
if (!cfg.agents.list) cfg.agents.list = [];
|
||||
|
||||
const wsPath = path.join(OPENCLAW_DIR, 'workspaces', folder);
|
||||
const agentEntry = { id: agentId, name: name || agentId, workspace: wsAlias };
|
||||
if (model && model !== '__default__') agentEntry.model = { primary: model };
|
||||
cfg.agents.list.push(agentEntry);
|
||||
|
||||
if (!cfg.bindings) cfg.bindings = [];
|
||||
cfg.bindings.unshift({ agentId, match: { channel: 'discord', peer: { kind: 'channel', id: String(channelId).trim() } } });
|
||||
|
||||
if (!cfg.channels) cfg.channels = {};
|
||||
if (!cfg.channels.discord) cfg.channels.discord = {};
|
||||
cfg.channels.discord.enabled = true;
|
||||
if (gid) {
|
||||
if (!cfg.channels.discord.guilds) cfg.channels.discord.guilds = {};
|
||||
if (!cfg.channels.discord.guilds[gid]) cfg.channels.discord.guilds[gid] = {};
|
||||
if (!cfg.channels.discord.guilds[gid].channels) cfg.channels.discord.guilds[gid].channels = {};
|
||||
cfg.channels.discord.guilds[gid].channels[String(channelId).trim()] = { allow: true, requireMention: false };
|
||||
if (cfg.channels.discord.guilds[gid].requireMention === undefined) cfg.channels.discord.guilds[gid].requireMention = false;
|
||||
}
|
||||
|
||||
const bakPath = await writeConfig(cfg, 'create');
|
||||
|
||||
await fsp.mkdir(wsPath, { recursive: true });
|
||||
await fsp.mkdir(path.join(wsPath, 'memory'), { recursive: true });
|
||||
await fsp.writeFile(path.join(wsPath, 'SOUL.md'), generateSoulMd(name || agentId, purpose || '', personality || ''), 'utf8');
|
||||
await fsp.writeFile(path.join(wsPath, 'MEMORY.md'), generateMemoryMd(name || agentId, ''), 'utf8');
|
||||
await fsp.writeFile(path.join(wsPath, 'memory', 'CURRENT_STATE.md'), generateCurrentStateMd(), 'utf8');
|
||||
|
||||
const agentRuntimeDir = path.join(OPENCLAW_DIR, 'agents', agentId);
|
||||
await fsp.mkdir(agentRuntimeDir, { recursive: true });
|
||||
await fsp.mkdir(path.join(agentRuntimeDir, 'sessions'), { recursive: true });
|
||||
|
||||
res.writeHead(200);
|
||||
res.end(JSON.stringify({ ok: true, agentId, workspacePath: wsPath, configBackup: bakPath,
|
||||
notes: [
|
||||
'Discord agent created (single Discord bot)',
|
||||
'Channel binding added',
|
||||
'Workspace + runtime directories created (including memory/CURRENT_STATE.md)',
|
||||
'Configuration updated and backed up',
|
||||
'Restart gateway to apply: openclaw gateway restart'
|
||||
]
|
||||
}));
|
||||
return;
|
||||
}
|
||||
|
||||
// POST /api/agents/discord-sub — create Discord sub-agent (thread-only binding, grouping under parentAgentId)
|
||||
if (method === 'POST' && pathname === '/api/agents/discord-sub') {
|
||||
const { agentId, displayName, workspaceFolder, model, purpose, personality, initialMemory, parentAgentId, guildId, threadId } = body;
|
||||
if (!agentId || !/^[a-zA-Z0-9_-]+$/.test(agentId)) {
|
||||
res.writeHead(400); res.end(JSON.stringify({ error: 'Agent ID must contain only alphanumeric characters, underscores, or dashes' })); return;
|
||||
}
|
||||
if (!parentAgentId || !String(parentAgentId).trim()) {
|
||||
res.writeHead(400); res.end(JSON.stringify({ error: 'Parent Agent ID is required' })); return;
|
||||
}
|
||||
if (!threadId || !String(threadId).trim().match(/^\d+$/)) {
|
||||
res.writeHead(400); res.end(JSON.stringify({ error: 'Discord threadId is required' })); return;
|
||||
}
|
||||
const gid = (guildId || '').trim();
|
||||
|
||||
const cfg = await readConfig();
|
||||
const parentAgent = cfg.agents?.list?.find(a => a.id === parentAgentId);
|
||||
if (!parentAgent) { res.writeHead(404); res.end(JSON.stringify({ error: `Parent agent \"${parentAgentId}\" does not exist` })); return; }
|
||||
if (cfg.agents?.list?.some(a => a.id === agentId)) { res.writeHead(400); res.end(JSON.stringify({ error: `Agent ID \"${agentId}\" already exists` })); return; }
|
||||
|
||||
const folder = (workspaceFolder || agentId).trim();
|
||||
const wsAlias = `~/.openclaw/workspaces/${folder}`;
|
||||
if (cfg.agents?.list?.some(a => (a.workspace||'').endsWith(`/workspaces/${folder}`) || a.workspace === wsAlias)) {
|
||||
res.writeHead(400); res.end(JSON.stringify({ error: `Workspace folder \"${folder}\" is already used by another agent` })); return;
|
||||
}
|
||||
|
||||
const wsPath = path.join(OPENCLAW_DIR, 'workspaces', folder);
|
||||
const agentEntry = { id: agentId, name: displayName || agentId, workspace: wsAlias, parentAgentId: String(parentAgentId).trim() };
|
||||
if (model && model !== '__default__') agentEntry.model = { primary: model };
|
||||
cfg.agents.list.push(agentEntry);
|
||||
|
||||
if (!cfg.bindings) cfg.bindings = [];
|
||||
cfg.bindings.unshift({ agentId, match: { channel: 'discord', peer: { kind: 'channel', id: String(threadId).trim() } } });
|
||||
|
||||
if (!cfg.channels) cfg.channels = {};
|
||||
if (!cfg.channels.discord) cfg.channels.discord = {};
|
||||
cfg.channels.discord.enabled = true;
|
||||
if (gid) {
|
||||
if (!cfg.channels.discord.guilds) cfg.channels.discord.guilds = {};
|
||||
if (!cfg.channels.discord.guilds[gid]) cfg.channels.discord.guilds[gid] = {};
|
||||
if (!cfg.channels.discord.guilds[gid].channels) cfg.channels.discord.guilds[gid].channels = {};
|
||||
cfg.channels.discord.guilds[gid].channels[String(threadId).trim()] = { allow: true, requireMention: false };
|
||||
if (cfg.channels.discord.guilds[gid].requireMention === undefined) cfg.channels.discord.guilds[gid].requireMention = false;
|
||||
}
|
||||
|
||||
const bakPath = await writeConfig(cfg, 'create');
|
||||
|
||||
await fsp.mkdir(wsPath, { recursive: true });
|
||||
await fsp.mkdir(path.join(wsPath, 'memory'), { recursive: true });
|
||||
const name = displayName || agentId;
|
||||
await fsp.writeFile(path.join(wsPath, 'SOUL.md'), generateSoulMd(name, purpose || '', personality || ''), 'utf8');
|
||||
await fsp.writeFile(path.join(wsPath, 'MEMORY.md'), generateMemoryMd(name, initialMemory || ''), 'utf8');
|
||||
await fsp.writeFile(path.join(wsPath, 'memory', 'CURRENT_STATE.md'), generateCurrentStateMd(), 'utf8');
|
||||
|
||||
const agentRuntimeDir = path.join(OPENCLAW_DIR, 'agents', agentId);
|
||||
await fsp.mkdir(agentRuntimeDir, { recursive: true });
|
||||
await fsp.mkdir(path.join(agentRuntimeDir, 'sessions'), { recursive: true });
|
||||
|
||||
res.writeHead(200);
|
||||
res.end(JSON.stringify({ ok: true, agentId, workspacePath: wsPath, configBackup: bakPath,
|
||||
notes: [
|
||||
'Discord sub-agent created (thread-only binding)',
|
||||
'Workspace + runtime directories created (including memory/CURRENT_STATE.md)',
|
||||
'Configuration updated and backed up',
|
||||
'Restart gateway to apply: openclaw gateway restart'
|
||||
]
|
||||
}));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// POST /api/agents — create sub-agent (shares parent bot)
|
||||
if (method === 'POST' && pathname === '/api/agents') {
|
||||
const { agentId, displayName, groupId, workspaceFolder, model, purpose, personality, initialMemory, parentAgentId, telegramUserId } = body;
|
||||
@@ -537,7 +706,7 @@ async function handleApi(req, res, urlObj, body) {
|
||||
const folder = workspaceFolder || agentId;
|
||||
const wsPath = path.join(OPENCLAW_DIR, 'workspaces', folder);
|
||||
const wsAlias= `~/.openclaw/workspaces/${folder}`;
|
||||
const agentEntry = { id: agentId, name: displayName || agentId, workspace: wsAlias };
|
||||
const agentEntry = { id: agentId, name: displayName || agentId, workspace: wsAlias, parentAgentId: String(parentAgentId).trim() };
|
||||
if (model && model !== '__default__') agentEntry.model = { primary: model };
|
||||
cfg.agents.list.push(agentEntry);
|
||||
// Binding uses parent's accountId
|
||||
@@ -563,6 +732,7 @@ async function handleApi(req, res, urlObj, body) {
|
||||
const name = displayName || agentId;
|
||||
await fsp.writeFile(path.join(wsPath, 'SOUL.md'), generateSoulMd(name, purpose, personality), 'utf8');
|
||||
await fsp.writeFile(path.join(wsPath, 'MEMORY.md'), generateMemoryMd(name, initialMemory), 'utf8');
|
||||
await fsp.writeFile(path.join(wsPath, 'memory', 'CURRENT_STATE.md'), generateCurrentStateMd(), 'utf8');
|
||||
// Create agents/<id>/ runtime directory (required by OpenClaw gateway)
|
||||
const agentRuntimeDir = path.join(OPENCLAW_DIR, 'agents', agentId);
|
||||
await fsp.mkdir(agentRuntimeDir, { recursive: true });
|
||||
@@ -571,7 +741,7 @@ async function handleApi(req, res, urlObj, body) {
|
||||
res.end(JSON.stringify({ ok: true, agentId, workspacePath: wsPath, configBackup: bakPath,
|
||||
notes: [
|
||||
'Sub-agent created and shares parent bot',
|
||||
'Workspace and runtime directories created',
|
||||
'Workspace and runtime directories created (including memory/CURRENT_STATE.md)',
|
||||
'Configuration updated and backed up',
|
||||
'Restart gateway to apply: openclaw gateway restart'
|
||||
],
|
||||
@@ -1556,6 +1726,10 @@ header { background:var(--surface); border-bottom:1px solid var(--border); paddi
|
||||
.lang-toggle { background:var(--border); border:none; color:var(--muted); border-radius:6px; padding:5px 10px; font-size:12px; cursor:pointer; }
|
||||
.lang-toggle:hover { background:#3a3f5c; color:var(--text); }
|
||||
|
||||
/* centered version badge */
|
||||
.top-version{ position:absolute; left:50%; transform:translateX(-50%); font-size:12px; font-weight:800; letter-spacing:.3px; color:var(--text); background:rgba(108,99,255,.18); border:1px solid rgba(108,99,255,.45); padding:4px 12px; border-radius:999px; box-shadow:0 6px 18px rgba(0,0,0,.25); }
|
||||
.ver-old{ display:none; }
|
||||
|
||||
/* dropdown menu */
|
||||
.menu-wrap { position:relative; }
|
||||
.menu-btn { background:var(--border); border:none; color:var(--text); border-radius:6px; padding:6px 12px; font-size:13px; cursor:pointer; display:flex; align-items:center; gap:6px; }
|
||||
@@ -1820,7 +1994,9 @@ const MAIN_HTML_BODY = String.raw`
|
||||
<!-- Header / Toolbar -->
|
||||
<header>
|
||||
<span class="logo" title="OpenClaw Manager">🦀 OpenClaw</span>
|
||||
<div class="top-version" id="topVersion">v--</div>
|
||||
<span class="ver" id="versionBadge">v--</span>
|
||||
<span class="ver ver-old" id="ocmVersionBadge">ocm v--</span>
|
||||
<div class="spacer"></div>
|
||||
<div id="healthBadge" title="">
|
||||
<span id="healthIcon">⚠️</span>
|
||||
@@ -1829,7 +2005,7 @@ const MAIN_HTML_BODY = String.raw`
|
||||
</div>
|
||||
<div class="status-row">
|
||||
<div class="dot" id="dot"></div>
|
||||
<span class="status-txt" id="statusTxt">连接中...</span>
|
||||
<span class="status-txt" id="statusTxt"></span>
|
||||
</div>
|
||||
<button class="lang-toggle" onclick="toggleLang()" id="langToggleBtn">EN</button>
|
||||
<div class="menu-wrap">
|
||||
@@ -1880,6 +2056,16 @@ const MAIN_HTML_BODY = String.raw`
|
||||
</div>
|
||||
</div>
|
||||
<div class="dash-gauges" id="dashGauges"><div class="empty">Loading...</div></div>
|
||||
<div class="card dash-notice">
|
||||
<h3 data-i18n="dash.firstRunTitle">🚀 First-run checklist</h3>
|
||||
<ul class="dash-note-list">
|
||||
<li data-i18n="dash.firstRun1">Confirm OCM is pointed at the correct OpenClaw directory.</li>
|
||||
<li data-i18n="dash.firstRun2">Check this Dashboard first: make sure Gateway is running and the system looks healthy.</li>
|
||||
<li data-i18n="dash.firstRun3">Open Agents / Routing and confirm the bindings you expect are actually there.</li>
|
||||
<li data-i18n="dash.firstRun4">Use the built-in Terminal to run <code>openclaw doctor</code> once so you catch environment/auth issues early.</li>
|
||||
<li data-i18n="dash.firstRun5">Before bigger edits, make a backup or check rollback so recovery is nearby if something goes wrong.</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="dash-sections">
|
||||
<div class="card dash-card" id="dashSystem">
|
||||
<h3>🖥️ System Info</h3>
|
||||
@@ -2025,6 +2211,7 @@ const MAIN_HTML_BODY = String.raw`
|
||||
<select id="cliPreset" onchange="onCliPresetSelect()" style="font-size:11px;padding:3px 6px;max-width:180px;background:var(--bg);border:1px solid var(--border);border-radius:6px;color:var(--text)">
|
||||
<option value="" data-i18n="cli.presets">── 常用命令 ──</option>
|
||||
</select>
|
||||
<button class="btn-secondary" style="font-size:11px;padding:3px 10px" onclick="copyCliCommand()" data-i18n="cli.copy">复制命令</button>
|
||||
<button class="btn-secondary" style="font-size:11px;padding:3px 10px" onclick="clearCliOutput()" data-i18n="cli.clear">清空</button>
|
||||
<button class="btn-secondary" style="font-size:11px;padding:3px 10px" onclick="toggleCliPanel()" data-i18n="cli.collapse">▼ 收起</button>
|
||||
</div>
|
||||
@@ -2281,6 +2468,7 @@ const I18N = {
|
||||
'tab.stats':'📊 Stats','tab.cron':'⏰ Cron',
|
||||
'agents.title':'Agents','agents.new':'+ 新建 Subagent',
|
||||
'channels.title':'路由绑定','channels.add':'+ 添加绑定','channels.hint':'用于高级路由管理:维护 Agent 与频道/群组绑定及优先级顺序。日常增减 Agent 请在 Agents 页面操作。',
|
||||
'channels.removeHint':'如果需要更换 Telegram 群或 Discord thread:请先在本页删除旧绑定,然后用新的 ID 重新绑定。也可用于修正绑定错误、群重建(ID 变化)、重复/冲突或临时断开路由。',
|
||||
'channels.filterLabel':'Agent','channels.filterAll':'全部 Agent','channels.emptyFiltered':'当前 Agent 下暂无绑定',
|
||||
'channels.countSuffix':'条绑定','channels.collapse':'折叠','channels.expand':'展开',
|
||||
'models.title':'模型管理','models.primary':'默认主模型','models.fallback':'Fallback 链',
|
||||
@@ -2288,6 +2476,12 @@ const I18N = {
|
||||
'models.onlyCliHint':'模型下拉仅显示 openclaw models list 返回的模型。',
|
||||
'models.modelListErr':'读取 openclaw models list 失败:',
|
||||
'models.modelListEmpty':'未从 openclaw models list 解析到模型。请先运行 openclaw onboard 并确认模型可用。',
|
||||
'dash.firstRunTitle':'🚀 首次使用检查清单',
|
||||
'dash.firstRun1':'先确认 OCM 指向的是正确的 OpenClaw 数据目录。',
|
||||
'dash.firstRun2':'先看 Dashboard:确认 Gateway 正在运行,系统状态看起来正常。',
|
||||
'dash.firstRun3':'打开 Agents / Routing,确认你期望的绑定确实已经存在。',
|
||||
'dash.firstRun4':'用内置终端先运行一次 <code>openclaw doctor</code>,尽早发现环境或认证问题。',
|
||||
'dash.firstRun5':'在做较大改动前,先做一次备份或确认回滚入口,出问题时更容易恢复。',
|
||||
'dash.noticeTitle':'📌 Telegram 使用说明(重要)',
|
||||
'dash.notice1':'OCM 主要面向 Telegram:通过群组绑定 Agent,让每个 Agent 拥有独立 Workspace / SOUL.md / MEMORY.md。',
|
||||
'dash.notice2':'请确保你已有基本 OpenClaw 操作经验。OCM 主要负责可视化更新 openclaw.json,方便增删主 Agent 与 Sub-Agent,并支持多条 Agent 树。',
|
||||
@@ -2319,7 +2513,7 @@ const I18N = {
|
||||
'actions.restoreConfirm':'确认将配置恢复为:\\n{filename}\\n\\n当前配置将先被自动备份。继续?',
|
||||
'actions.restored':'已恢复 ','actions.restoreFail':'恢复失败: ',
|
||||
'actions.setupEmpty':'请填写路径','actions.setupSwitching':'目录已切换,正在刷新...','actions.setupInvalid':'路径无效','actions.setupReqFail':'请求失败: ',
|
||||
'common.loading':'加载中...','common.close':'关闭',
|
||||
'common.loading':'加载中...','common.close':'关闭','status.connecting':'连接中...','status.configReadError':'无法读取配置',
|
||||
'btn.save':'保存','btn.delete':'删除','btn.cancel':'取消','btn.add':'添加','btn.remove':'移除',
|
||||
'agents.addAgent':'+ Add Agent','agents.addSub':'+ Add Sub-Agent','agents.hint':'Add Agent: create a top-level agent (a long-lived role) for a new domain. Add Sub-Agent: create a child under a parent; sub-agents use the parent Telegram bot but have their own workspace + SOUL.md + MEMORY.md, preventing context mixing, improving focus, and saving tokens.',
|
||||
'agents.addAgentTitle':'Add Agent (Main Bot)','agents.addSubTitle':'Add Sub-Agent',
|
||||
@@ -2330,14 +2524,27 @@ const I18N = {
|
||||
'guide.title':'📖 Setup Guide','guide.agent.s1':'Open Telegram, search for <code>@BotFather</code>',
|
||||
'guide.agent.s2':'Send <code>/newbot</code> and follow prompts to name your Bot',
|
||||
'guide.agent.s3':'Copy the <code>Bot Token</code> from BotFather and paste below',
|
||||
'guide.agent.s4':'Send <code>/setprivacy</code> → select your Bot → click <code>Disable</code> (allow Bot to read group messages)',
|
||||
'guide.agent.s4':'In BotFather: <code>/mybots</code> → select your bot → <b>Bot Settings</b> → <b>Allow Groups</b> → <b>Turn on</b> (allow the bot to join groups)',
|
||||
'guide.agent.s5':'Send <code>/setprivacy</code> → select your Bot → click <code>Disable</code> (allow Bot to read group messages)',
|
||||
'guide.sub.s1':'在 BotFather 发送 <code>/newbot</code> 创建新 Bot,获取 Bot Token',
|
||||
'guide.sub.s2':'在 BotFather 发送 <code>/mybots</code> → 选择 Bot → <b>Bot Settings</b> → <b>Group Privacy</b> → <b>Turn off</b>',
|
||||
'guide.sub.s3':'在 Telegram 创建新群组,将 Bot 加入群组(<b>不要加其他人</b>)',
|
||||
'guide.sub.s4':'在群内发一条消息,从 gateway 日志中找到 <code>peer.id</code>(负数)',
|
||||
'guide.sub.s5':'填写下方表单创建 Sub-Agent',
|
||||
'guide.sub.warn':'⚠️ 安全提示:请勿将其他人加入此群组,只有你和 Bot 应在群内。否则其他人也能与 Bot 对话并产生 API 费用。',
|
||||
'guide.agent.discord.s1':'Discord 主 Agent:创建/选择一个专用 <b>Channel</b>(建议私密频道)。',
|
||||
'guide.agent.discord.s2':'右键该 Channel → <b>Copy Link</b>,粘贴到表单里(OCM 自动解析 <code>channelId</code>,可选 <code>guildId</code>)。',
|
||||
'guide.agent.discord.s3':'建议:一个 Channel 只绑定一个主 Agent,避免上下文串台。',
|
||||
'guide.sub.discord.s1':'Discord Sub-Agent:在对应主 Channel 下新建一个 <b>Thread</b>(强烈推荐每个任务一个 thread)。',
|
||||
'guide.sub.discord.s2':'如果是 Private Thread:需要把 Bot/Agent 拉进该 thread(否则读不到消息)。',
|
||||
'guide.sub.discord.s3':'右键该 Thread → <b>Copy Link</b>,粘贴到表单里(OCM 自动解析 <code>threadId</code>)。',
|
||||
'guide.sub.discord.warn':'⚠️ 约定:主 Agent 绑定 Channel;Sub-Agent 绑定 Thread。不要把 Sub-Agent 绑到普通 Channel。',
|
||||
'wiz.telegramId':'你的 Telegram User ID','wiz.telegramIdHint':'💡 可通过 @userinfobot 获取,填写后自动配置 allowFrom 白名单','wiz.telegramIdPh':'例如: 123456789',
|
||||
'wiz.channel':'渠道',
|
||||
'wiz.discordChannel':'Discord 频道链接/ID',
|
||||
'wiz.discordChannelHint':'建议:右键频道 → Copy Link,粘贴后自动解析 channelId(可选 guildId)。',
|
||||
'wiz.discordThread':'Discord Thread 链接/ID(仅 Thread)',
|
||||
'wiz.discordThreadHint':'建议:在主频道内创建 thread → 右键 thread → Copy Link,粘贴后自动解析 threadId。',
|
||||
'agents.empty':'暂无 Agent','agents.main':'主 Agent','agents.bound':'已绑群',
|
||||
'agents.saveModel':'保存模型','agents.viewFiles':'查看文件',
|
||||
'agents.defaultModel':'使用全局默认','agents.custom':'自定义','agents.noModel':'默认',
|
||||
@@ -2370,7 +2577,7 @@ const I18N = {
|
||||
'ch.peerId':'Peer ID','ch.peerIdHint':'(群组 ID 或用户 ID)','ch.peerIdTip':'留空则匹配所有对应类型的 Peer',
|
||||
'ch.submit':'添加绑定',
|
||||
'l.sub':'选择运行模式',
|
||||
'cli.open':'⌨️ 终端','cli.title':'⌨️ CLI 终端','cli.clear':'清空','cli.collapse':'▼ 收起',
|
||||
'cli.open':'⌨️ 终端','cli.title':'⌨️ CLI 终端','cli.copy':'复制命令','cli.clear':'清空','cli.collapse':'▼ 收起',
|
||||
'cli.ready':'── 终端就绪,等待命令 ──','cli.cleared':'── 已清空 ──',
|
||||
'cli.presets':'── 常用命令 ──','cli.builtins':'内置命令','cli.favs':'我的收藏',
|
||||
'cli.run':'▶ 执行','cli.stop':'■ 停止','cli.star':'⭐','cli.manage':'管理',
|
||||
@@ -2401,7 +2608,7 @@ const I18N = {
|
||||
'tab.agents':'🤖 Agents','tab.channels':'🧭 Routing','tab.models':'🧠 Models & Auth','tab.auth':'🔑 Auth',
|
||||
'tab.stats':'📊 Stats','tab.cron':'⏰ Cron',
|
||||
'agents.title':'Agents','agents.new':'+ New Subagent',
|
||||
'channels.title':'Routing Bindings','channels.add':'+ Add Binding','channels.hint':'Advanced routing rules for agent-channel/group bindings and priority order. Use Agents page for daily add/remove workflows.','channels.removeHint':'When to use Remove binding: wrong agent/chat, group recreated (new id), duplicates/conflicts, decommission a sub-agent, or temporarily disconnect routing for safety.',
|
||||
'channels.title':'Routing Bindings','channels.add':'+ Add Binding','channels.hint':'Advanced routing rules for agent-channel/group bindings and priority order. Use Agents page for daily add/remove workflows.','channels.removeHint':'When to use Remove binding: if you need to switch to a new Telegram group / Discord thread, remove the old binding here, then add a new binding with the new ID. Also use this for wrong bindings, recreated groups (new id), duplicates/conflicts, decommissioning, or temporary disconnect.',
|
||||
'channels.filterLabel':'Agent','channels.filterAll':'All Agents','channels.emptyFiltered':'No bindings for selected agent',
|
||||
'channels.countSuffix':'bindings','channels.collapse':'Collapse','channels.expand':'Expand',
|
||||
'models.title':'Model Management','models.primary':'Default Primary Model','models.fallback':'Fallback Chain',
|
||||
@@ -2409,6 +2616,12 @@ const I18N = {
|
||||
'models.onlyCliHint':'Model dropdowns only show IDs returned by openclaw models list.',
|
||||
'models.modelListErr':'Failed to load openclaw models list: ',
|
||||
'models.modelListEmpty':'No model IDs were parsed from openclaw models list. Run openclaw onboard first.',
|
||||
'dash.firstRunTitle':'🚀 First-run checklist',
|
||||
'dash.firstRun1':'Confirm OCM is pointed at the correct OpenClaw directory.',
|
||||
'dash.firstRun2':'Check Dashboard first: make sure Gateway is running and the system looks healthy.',
|
||||
'dash.firstRun3':'Open Agents / Routing and confirm the bindings you expect are actually there.',
|
||||
'dash.firstRun4':'Use the built-in Terminal to run <code>openclaw doctor</code> once so you catch environment or auth issues early.',
|
||||
'dash.firstRun5':'Before bigger edits, make a backup or check rollback so recovery is nearby if something goes wrong.',
|
||||
'dash.noticeTitle':'📌 Telegram Usage Notes (Important)',
|
||||
'dash.notice1':'OCM is primarily for Telegram workflows: bind agents to groups so each agent has isolated Workspace / SOUL.md / MEMORY.md.',
|
||||
'dash.notice2':'Basic OpenClaw CLI experience is required. OCM focuses on visual openclaw.json updates for easier main-agent/sub-agent management and multiple agent trees.',
|
||||
@@ -2440,7 +2653,7 @@ const I18N = {
|
||||
'actions.restoreConfirm':'Restore config to:\\n{filename}\\n\\nCurrent config will be auto-backed up first. Continue?',
|
||||
'actions.restored':'Restored ','actions.restoreFail':'Restore failed: ',
|
||||
'actions.setupEmpty':'Please enter a path','actions.setupSwitching':'Directory switched, refreshing...','actions.setupInvalid':'Invalid path','actions.setupReqFail':'Request failed: ',
|
||||
'common.loading':'Loading...','common.close':'Close',
|
||||
'common.loading':'Loading...','common.close':'Close','status.connecting':'Connecting...','status.configReadError':'Unable to read config',
|
||||
'btn.save':'Save','btn.delete':'Delete','btn.cancel':'Cancel','btn.add':'Add','btn.remove':'Remove',
|
||||
'agents.addAgent':'+ Add Agent','agents.addSub':'+ Add Sub-Agent','agents.hint':'Add Agent: create a top-level agent (a long-lived role) for a new domain. Add Sub-Agent: create a child under a parent; sub-agents use the parent Telegram bot but have their own workspace + SOUL.md + MEMORY.md, preventing context mixing, improving focus, and saving tokens.',
|
||||
'agents.addAgentTitle':'Add Agent (Main Bot)','agents.addSubTitle':'Add Sub-Agent',
|
||||
@@ -2451,14 +2664,28 @@ const I18N = {
|
||||
'guide.title':'📖 Setup Guide','guide.agent.s1':'Open Telegram, search for <code>@BotFather</code>',
|
||||
'guide.agent.s2':'Send <code>/newbot</code> and follow prompts to name your Bot',
|
||||
'guide.agent.s3':'Copy the <code>Bot Token</code> from BotFather and paste below',
|
||||
'guide.agent.s4':'Send <code>/setprivacy</code> → select your Bot → click <code>Disable</code> (allow Bot to read group messages)',
|
||||
'guide.agent.s4':'In BotFather: <code>/mybots</code> → select your bot → <b>Bot Settings</b> → <b>Allow Groups</b> → <b>Turn on</b> (allow the bot to join groups)',
|
||||
'guide.agent.s5':'Send <code>/setprivacy</code> → select your Bot → click <code>Disable</code> (allow Bot to read group messages)',
|
||||
'guide.sub.s1':'Send <code>/newbot</code> to BotFather to create a new Bot and get the Bot Token',
|
||||
'guide.sub.s2':'Send <code>/mybots</code> to BotFather → select your Bot → <b>Bot Settings</b> → <b>Group Privacy</b> → <b>Turn off</b>',
|
||||
'guide.sub.s3':'Create a new Telegram group, add the Bot to the group (<b>do NOT add anyone else</b>)',
|
||||
'guide.sub.s4':'Send a message in the group, find <code>peer.id</code> (negative number) in gateway logs',
|
||||
'guide.sub.s5':'Fill in the form below to create the Sub-Agent',
|
||||
'guide.sub.warn':'⚠️ Security: Do NOT add other people to this group. Only you and the Bot should be in the group. Otherwise others can chat with the Bot and incur API costs.',
|
||||
'guide.agent.discord.s1':'Discord main agent: create/select a dedicated <b>channel</b> (private recommended).',
|
||||
'guide.agent.discord.s2':'Right-click the channel → <b>Copy Link</b>, paste it into the form (OCM auto-parses <code>channelId</code>; optional <code>guildId</code>).',
|
||||
'guide.agent.discord.s3':'Recommended: bind one main agent per channel to avoid context bleed.',
|
||||
'guide.sub.discord.s1':'Discord sub-agent: create a <b>thread</b> under the main channel (one thread per task recommended).',
|
||||
'guide.sub.discord.s2':'If it is a private thread, add the bot/agent to the thread (otherwise it cannot read messages).',
|
||||
'guide.sub.discord.s3':'Right-click the thread → <b>Copy Link</b>, paste into the form (OCM auto-parses the <code>threadId</code>).',
|
||||
'guide.sub.discord.warn':'Important: main agents bind to channels; sub-agents bind to threads. Do not bind sub-agents to normal channels.',
|
||||
'wiz.telegramId':'Your Telegram User ID','wiz.telegramIdHint':'💡 Get it from @userinfobot — auto-configures allowFrom whitelist','wiz.telegramIdPh':'e.g. 123456789',
|
||||
'wiz.channel':'Channel',
|
||||
'wiz.discordChannel':'Discord channel link/ID',
|
||||
'wiz.discordChannelHint':'Tip: right-click channel → Copy Link. Paste to auto-parse channelId (optional guildId).',
|
||||
'wiz.discordThread':'Discord thread link/ID (thread only)',
|
||||
'wiz.discordThreadHint':'Tip: create a thread under your main channel → Copy Link. Paste to auto-parse threadId.',
|
||||
|
||||
'agents.empty':'No Agents','agents.main':'Main Agent','agents.bound':'Bound',
|
||||
'agents.saveModel':'Save Model','agents.viewFiles':'View Files',
|
||||
'agents.defaultModel':'Use Global Default','agents.custom':'custom','agents.noModel':'Default',
|
||||
@@ -2491,7 +2718,7 @@ const I18N = {
|
||||
'ch.peerId':'Peer ID','ch.peerIdHint':'(Group ID or User ID)','ch.peerIdTip':'Leave blank to match all peers of this type',
|
||||
'ch.submit':'Add Binding',
|
||||
'l.sub':'Select Mode',
|
||||
'cli.open':'⌨️ Terminal','cli.title':'⌨️ CLI Terminal','cli.clear':'Clear','cli.collapse':'▼ Collapse',
|
||||
'cli.open':'⌨️ Terminal','cli.title':'⌨️ CLI Terminal','cli.copy':'Copy cmd','cli.clear':'Clear','cli.collapse':'▼ Collapse',
|
||||
'cli.ready':'── Terminal Ready ──','cli.cleared':'── Cleared ──',
|
||||
'cli.presets':'── Presets ──','cli.builtins':'Built-in','cli.favs':'My Favorites',
|
||||
'cli.run':'▶ Run','cli.stop':'■ Stop','cli.star':'⭐','cli.manage':'Manage',
|
||||
@@ -2529,6 +2756,9 @@ const LS = {
|
||||
let lang = LS.get('ocm_lang', 'en');
|
||||
function t(k) { return I18N[lang][k] || I18N.zh[k] || k; }
|
||||
function applyLang() {
|
||||
document.documentElement.lang = lang === 'zh' ? 'zh-CN' : 'en';
|
||||
const st = document.getElementById('statusTxt');
|
||||
if(st && (!st.textContent || st.textContent === '连接中...' || st.textContent === 'Connecting...')) st.textContent = t('status.connecting');
|
||||
document.querySelectorAll('[data-i18n]').forEach(el => { el.textContent = t(el.dataset.i18n); });
|
||||
document.querySelectorAll('[data-i18n-placeholder]').forEach(el => { el.placeholder = t(el.dataset.i18nPlaceholder); });
|
||||
const ltb = document.getElementById('langToggleBtn');
|
||||
@@ -2593,8 +2823,11 @@ async function checkStatus(){
|
||||
if(r.needsSetup){ location.reload(); return; }
|
||||
setDot('ok');
|
||||
document.getElementById('statusTxt').textContent = r.dir.replace(/.*[/\\\\]/,'.../')+' · v'+r.version;
|
||||
document.getElementById('versionBadge').textContent = 'v'+r.version;
|
||||
}catch{ setDot('err'); document.getElementById('statusTxt').textContent='无法读取配置'; }
|
||||
const tv=document.getElementById('topVersion');
|
||||
if(tv) tv.textContent = 'OCM v'+(r.ocmVersion||'--');
|
||||
const vb=document.getElementById('versionBadge'); if(vb) vb.textContent = 'v'+r.version;
|
||||
const ov=document.getElementById('ocmVersionBadge'); if(ov) ov.textContent='ocm v'+(r.ocmVersion||'--');
|
||||
}catch{ setDot('err'); document.getElementById('statusTxt').textContent=t('status.configReadError'); }
|
||||
}
|
||||
|
||||
async function loadAll(){
|
||||
@@ -2755,24 +2988,51 @@ function buildAddAgentForm() {
|
||||
const modelOpts = buildModelOpts('__default__');
|
||||
return '<div class="add-form">' +
|
||||
'<h3>' + t('agents.addAgentTitle') + '</h3>' +
|
||||
'<details class="guide-box" open><summary>' + t('guide.title') + '</summary><ol>' +
|
||||
'<li>' + t('guide.agent.s1') + '</li>' +
|
||||
'<li>' + t('guide.agent.s2') + '</li>' +
|
||||
'<li>' + t('guide.agent.s3') + '</li>' +
|
||||
'<li>' + t('guide.agent.s4') + '</li>' +
|
||||
'<div class="form-group"><label>' + t('wiz.channel') + '</label>' +
|
||||
'<select id="fa-channel" onchange="toggleAddAgentChannel(this.value)">' +
|
||||
'<option value="telegram">Telegram</option>' +
|
||||
'<option value="discord">Discord</option>' +
|
||||
'</select></div>' +
|
||||
|
||||
'<details class="guide-box" open id="fa-guide-telegram"><summary>' + t('guide.title') + '</summary><ol>' +
|
||||
'<li>' + t('guide.agent.s1') + '</li>' +
|
||||
'<li>' + t('guide.agent.s2') + '</li>' +
|
||||
'<li>' + t('guide.agent.s3') + '</li>' +
|
||||
'<li>' + t('guide.agent.s4') + '</li>' +
|
||||
'<li>' + t('guide.agent.s5') + '</li>' +
|
||||
'</ol></details>' +
|
||||
'<div class="form-group"><label>' + t('agents.botToken') + '</label>' +
|
||||
'<input id="fa-token" type="text" placeholder="123456:ABC-DEF...">' +
|
||||
|
||||
'<details class="guide-box" open id="fa-guide-discord" style="display:none"><summary>' + t('guide.title') + '</summary><ol>' +
|
||||
'<li>' + t('guide.agent.discord.s1') + '</li>' +
|
||||
'<li>' + t('guide.agent.discord.s2') + '</li>' +
|
||||
'<li>' + t('guide.agent.discord.s3') + '</li>' +
|
||||
'</ol></details>' +
|
||||
|
||||
'<div id="fa-sec-telegram">' +
|
||||
'<div class="form-group"><label>' + t('agents.botToken') + '</label>' +
|
||||
'<input id="fa-token" type="text" placeholder="123456:ABC-DEF...">' +
|
||||
'</div>' +
|
||||
'</div>' +
|
||||
'<div class="form-group"><label>Agent ID</label>' +
|
||||
'<input id="fa-agentid" type="text" placeholder="research, alice_bot, etc." pattern="[a-zA-Z0-9_-]+">' +
|
||||
'<span class="hint-text">Alphanumeric, underscore, or dash only</span></div>' +
|
||||
'<div class="form-group"><label>' + t('agents.botName') + '</label>' +
|
||||
'<input id="fa-name" type="text" placeholder="' + t('agents.botNamePh') + '">' +
|
||||
|
||||
'<div class="form-row">' +
|
||||
'<div class="form-group"><label>Agent ID</label>' +
|
||||
'<input id="fa-agentid" type="text" placeholder="research, travel_assistant, etc." pattern="[a-zA-Z0-9_-]+">' +
|
||||
'<span class="hint-text">Alphanumeric, underscore, or dash only</span></div>' +
|
||||
'<div class="form-group"><label>' + t('agents.botName') + '</label>' +
|
||||
'<input id="fa-name" type="text" placeholder="' + t('agents.botNamePh') + '">' +
|
||||
'</div>' +
|
||||
'</div>' +
|
||||
'<div class="form-group"><label>Workspace Name</label>' +
|
||||
'<input id="fa-workspace" type="text" placeholder="research, alice_workspace, etc.">' +
|
||||
|
||||
'<div class="form-group"><label>Workspace Folder</label>' +
|
||||
'<input id="fa-workspace" type="text" placeholder="(default = Agent ID)">' +
|
||||
'<span class="hint-text">Each agent must have its own workspace for isolated SOUL/MEMORY.</span></div>' +
|
||||
|
||||
'<div id="fa-sec-discord" style="display:none">' +
|
||||
'<div class="form-group"><label>' + t('wiz.discordChannel') + '</label>' +
|
||||
'<input id="fa-discord-link" type="text" placeholder="https://discord.com/channels/<guildId>/<channelId> or <channelId>">' +
|
||||
'<span class="hint-text">' + t('wiz.discordChannelHint') + '</span></div>' +
|
||||
'</div>' +
|
||||
|
||||
'<div class="form-group"><label>' + t('wiz.model') + '</label>' +
|
||||
'<select id="fa-model">' + modelOpts + '</select>' +
|
||||
'</div>' +
|
||||
@@ -2787,76 +3047,144 @@ function buildAddAgentForm() {
|
||||
'</div></div>';
|
||||
}
|
||||
|
||||
|
||||
function toggleAddAgentChannel(ch){
|
||||
const tg=document.getElementById('fa-sec-telegram');
|
||||
const dg=document.getElementById('fa-sec-discord');
|
||||
const gT=document.getElementById('fa-guide-telegram');
|
||||
const gD=document.getElementById('fa-guide-discord');
|
||||
if(tg) tg.style.display = (ch==='telegram')?'block':'none';
|
||||
if(dg) dg.style.display = (ch==='discord')?'block':'none';
|
||||
if(gT) gT.style.display = (ch==='telegram')?'block':'none';
|
||||
if(gD) gD.style.display = (ch==='discord')?'block':'none';
|
||||
}
|
||||
function buildAddSubForm() {
|
||||
// Build parent agent dropdown (agents with their own bot)
|
||||
const cfg = S.agents || [];
|
||||
const botAgents = cfg.filter(a => a.hasOwnBot);
|
||||
// Parent agent dropdown (all agents as potential parent for grouping)
|
||||
let parentOpts = '';
|
||||
if (botAgents.length === 0) {
|
||||
parentOpts = '<option value="">No agents with bot available</option>';
|
||||
} else {
|
||||
botAgents.forEach(a => {
|
||||
parentOpts += '<option value="' + esc(a.id) + '">' + esc(a.name || a.id) + '</option>';
|
||||
});
|
||||
}
|
||||
if (cfg.length === 0) parentOpts = '<option value="">No agents available</option>';
|
||||
else cfg.forEach(a=>{ parentOpts += '<option value="'+esc(a.id)+'">'+esc(a.name||a.id)+'</option>'; });
|
||||
|
||||
const modelOpts = buildModelOpts('__default__');
|
||||
return '<div class="add-form">' +
|
||||
'<h3>' + t('agents.addSubTitle') + '</h3>' +
|
||||
'<details class="guide-box" open><summary>' + t('guide.title') + '</summary><ol>' +
|
||||
'<li>' + t('guide.sub.s1') + '</li>' +
|
||||
'<li>' + t('guide.sub.s2') + '</li>' +
|
||||
'<li>' + t('guide.sub.s3') + '</li>' +
|
||||
'<li>' + t('guide.sub.s4') + '</li>' +
|
||||
'<li>' + t('guide.sub.s5') + '</li>' +
|
||||
'<div class="form-group"><label>' + t('wiz.channel') + '</label>' +
|
||||
'<select id="fs-channel" onchange="toggleAddSubChannel(this.value)">' +
|
||||
'<option value="telegram">Telegram</option>' +
|
||||
'<option value="discord">Discord (thread only)</option>' +
|
||||
'</select>' +
|
||||
'</div>' +
|
||||
|
||||
'<details class="guide-box" open id="fs-guide-telegram"><summary>' + t('guide.title') + '</summary><ol>' +
|
||||
'<li>' + t('guide.sub.s1') + '</li>' +
|
||||
'<li>' + t('guide.sub.s2') + '</li>' +
|
||||
'<li>' + t('guide.sub.s3') + '</li>' +
|
||||
'<li>' + t('guide.sub.s4') + '</li>' +
|
||||
'<li>' + t('guide.sub.s5') + '</li>' +
|
||||
'</ol>' +
|
||||
'<div style="margin-top:10px;padding:10px 12px;background:rgba(239,68,68,0.1);border:1px solid rgba(239,68,68,0.3);border-radius:8px;font-size:13px;line-height:1.5">' + t('guide.sub.warn') + '</div>' +
|
||||
'</details>' +
|
||||
|
||||
'<details class="guide-box" open id="fs-guide-discord" style="display:none"><summary>' + t('guide.title') + '</summary><ol>' +
|
||||
'<li>' + t('guide.sub.discord.s1') + '</li>' +
|
||||
'<li>' + t('guide.sub.discord.s2') + '</li>' +
|
||||
'<li>' + t('guide.sub.discord.s3') + '</li>' +
|
||||
'</ol>' +
|
||||
'<div style="margin-top:10px;padding:10px 12px;background:rgba(234,179,8,0.12);border:1px solid rgba(234,179,8,0.35);border-radius:8px;font-size:13px;line-height:1.5">' + t('guide.sub.discord.warn') + '</div>' +
|
||||
'</details>' +
|
||||
|
||||
'<div class="form-group"><label>Parent Agent</label>' +
|
||||
'<select id="fs-parent">' + parentOpts + '</select></div>' +
|
||||
'<div class="form-group"><label>' + t('wiz.groupId') + '</label>' +
|
||||
'<input id="fs-gid" placeholder="-100XXXXXXXXXX">' +
|
||||
'<span class="hint-text">' + t('wiz.groupHint') + '</span></div>' +
|
||||
'<div class="form-group"><label>' + t('wiz.telegramId') + '</label>' +
|
||||
'<input id="fs-tgid" placeholder="' + t('wiz.telegramIdPh') + '">' +
|
||||
'<span class="hint-text">' + t('wiz.telegramIdHint') + '</span></div>' +
|
||||
'<select id="fs-parent">' + parentOpts + '</select>' +
|
||||
'<span class="hint-text">Used for grouping only (Discord sub-agents do not share bots).</span>' +
|
||||
'</div>' +
|
||||
|
||||
'<div id="fs-sec-telegram">' +
|
||||
'<div class="form-group"><label>' + t('wiz.groupId') + '</label>' +
|
||||
'<input id="fs-gid" placeholder="-100XXXXXXXXXX">' +
|
||||
'<span class="hint-text">' + t('wiz.groupHint') + '</span>' +
|
||||
'</div>' +
|
||||
'<div class="form-group"><label>' + t('wiz.telegramId') + '</label>' +
|
||||
'<input id="fs-tgid" placeholder="' + t('wiz.telegramIdPh') + '">' +
|
||||
'<span class="hint-text">' + t('wiz.telegramIdHint') + '</span>' +
|
||||
'</div>' +
|
||||
'</div>' +
|
||||
|
||||
'<div id="fs-sec-discord" style="display:none">' +
|
||||
'<div class="form-group"><label>' + t('wiz.discordThread') + '</label>' +
|
||||
'<input id="fs-discord-link" placeholder="https://discord.com/channels/<guildId>/<threadId> or <threadId>">' +
|
||||
'<span class="hint-text">' + t('wiz.discordThreadHint') + '</span>' +
|
||||
'</div>' +
|
||||
'</div>' +
|
||||
|
||||
'<div class="form-row">' +
|
||||
'<div class="form-group"><label>' + t('wiz.agentId') + ' <span style="color:var(--muted);font-weight:400">' + t('wiz.agentIdHint') + '</span></label>' +
|
||||
'<input id="fs-aid" placeholder="' + t('wiz.agentIdPh') + '"></div>' +
|
||||
'<div class="form-group"><label>' + t('wiz.displayName') + '</label>' +
|
||||
'<input id="fs-name" placeholder="' + t('wiz.displayNamePh') + '"></div></div>' +
|
||||
'<div class="form-group"><label>' + t('wiz.agentId') + ' <span style="color:var(--muted);font-weight:400">' + t('wiz.agentIdHint') + '</span></label>' +
|
||||
'<input id="fs-aid" placeholder="' + t('wiz.agentIdPh') + '"></div>' +
|
||||
'<div class="form-group"><label>' + t('wiz.displayName') + '</label>' +
|
||||
'<input id="fs-name" placeholder="' + t('wiz.displayNamePh') + '"></div>' +
|
||||
'</div>' +
|
||||
|
||||
'<div class="form-group"><label>Workspace Folder</label>' +
|
||||
'<input id="fs-workspace" placeholder="(default = Agent ID)">' +
|
||||
'<span class="hint-text">Each sub-agent must have its own workspace for isolated SOUL/MEMORY.</span>' +
|
||||
'</div>' +
|
||||
|
||||
'<div class="form-group"><label>' + t('wiz.model') + '</label>' +
|
||||
'<select id="fs-model">' + modelOpts + '</select></div>' +
|
||||
'<select id="fs-model">' + modelOpts + '</select></div>' +
|
||||
'<div class="form-group"><label>' + t('wiz.purpose') + '</label>' +
|
||||
'<textarea id="fs-purpose" placeholder="' + t('wiz.purposePh') + '" rows="2"></textarea></div>' +
|
||||
'<textarea id="fs-purpose" placeholder="' + t('wiz.purposePh') + '" rows="2"></textarea></div>' +
|
||||
'<div class="form-group"><label>' + t('wiz.soul') + ' <span style="color:var(--muted);font-weight:400">' + t('wiz.soulHint') + '</span></label>' +
|
||||
'<input id="fs-soul" placeholder="' + t('wiz.soulPh') + '"></div>' +
|
||||
'<input id="fs-soul" placeholder="' + t('wiz.soulPh') + '"></div>' +
|
||||
'<div class="form-group"><label>' + t('wiz.memory') + ' <span style="color:var(--muted);font-weight:400">' + t('wiz.memoryHint') + '</span></label>' +
|
||||
'<textarea id="fs-mem" placeholder="' + t('wiz.memoryPh') + '" rows="2"></textarea></div>' +
|
||||
'<textarea id="fs-mem" placeholder="' + t('wiz.memoryPh') + '" rows="2"></textarea></div>' +
|
||||
|
||||
'<div style="display:flex;gap:8px;margin-top:14px">' +
|
||||
'<button class="btn-primary" onclick="submitAddSub()">' + t('agents.addSubSubmit') + '</button>' +
|
||||
'<button class="btn-ghost" onclick="clearAddForm()">' + t('btn.cancel') + '</button>' +
|
||||
'<button class="btn-primary" onclick="submitAddSub()">' + t('agents.addSubSubmit') + '</button>' +
|
||||
'<button class="btn-ghost" onclick="clearAddForm()">' + t('btn.cancel') + '</button>' +
|
||||
'</div></div>';
|
||||
}
|
||||
|
||||
function toggleAddSubChannel(ch){
|
||||
const tg=document.getElementById('fs-sec-telegram');
|
||||
const dg=document.getElementById('fs-sec-discord');
|
||||
const gT=document.getElementById('fs-guide-telegram');
|
||||
const gD=document.getElementById('fs-guide-discord');
|
||||
if(tg) tg.style.display = (ch==='telegram')?'block':'none';
|
||||
if(dg) dg.style.display = (ch==='discord')?'block':'none';
|
||||
if(gT) gT.style.display = (ch==='telegram')?'block':'none';
|
||||
if(gD) gD.style.display = (ch==='discord')?'block':'none';
|
||||
}
|
||||
|
||||
// ── Submit Add Agent (with own bot) ──────────────────────────
|
||||
async function submitAddAgent() {
|
||||
const token = document.getElementById('fa-token').value.trim();
|
||||
const channel = (document.getElementById('fa-channel')?.value||'telegram').trim();
|
||||
const agentId = document.getElementById('fa-agentid').value.trim();
|
||||
const name = document.getElementById('fa-name').value.trim();
|
||||
const workspace = document.getElementById('fa-workspace').value.trim();
|
||||
const workspace = (document.getElementById('fa-workspace').value.trim() || agentId);
|
||||
const model = document.getElementById('fa-model').value;
|
||||
const purpose = (document.getElementById('fa-purpose')?.value||'').trim();
|
||||
const personality = (document.getElementById('fa-soul')?.value||'').trim();
|
||||
if (!token) { toast(t('agents.errToken'), 'err'); return; }
|
||||
|
||||
if (!agentId) { toast('Agent ID is required', 'err'); return; }
|
||||
if (!/^[a-zA-Z0-9_-]+$/.test(agentId)) { toast('Agent ID must contain only alphanumeric characters, underscores, or dashes', 'err'); return; }
|
||||
if (!name) { toast(t('agents.errName'), 'err'); return; }
|
||||
if (!workspace) { toast('Workspace name is required', 'err'); return; }
|
||||
if (!workspace) { toast('Workspace folder is required', 'err'); return; }
|
||||
|
||||
try {
|
||||
const payload = { botToken: token, agentId, name, workspace, model: model === '__default__' ? '' : model, purpose, personality };
|
||||
const r = await api('POST', '/api/agents/bot', payload);
|
||||
if (channel === 'telegram') {
|
||||
const token = document.getElementById('fa-token').value.trim();
|
||||
if (!token) { toast(t('agents.errToken'), 'err'); return; }
|
||||
const payload = { botToken: token, agentId, name, workspace, model: model === '__default__' ? '' : model, purpose, personality };
|
||||
await api('POST', '/api/agents/bot', payload);
|
||||
} else {
|
||||
const link = (document.getElementById('fa-discord-link')?.value||'').trim();
|
||||
const parsed = parseDiscordLinkOrId(link);
|
||||
if (!parsed) { toast('Discord channel link/ID is required', 'err'); return; }
|
||||
const payload = { agentId, name, workspaceFolder: workspace, model: model === '__default__' ? '' : model, purpose, personality,
|
||||
guildId: parsed.guildId, channelId: parsed.channelId };
|
||||
await api('POST', '/api/agents/discord', payload);
|
||||
}
|
||||
toast('Agent created successfully', 'ok');
|
||||
closePopover();
|
||||
clearAddForm();
|
||||
showRestartBanner();
|
||||
await loadAll();
|
||||
} catch (e) {
|
||||
@@ -2866,25 +3194,39 @@ async function submitAddAgent() {
|
||||
|
||||
// ── Submit Add Sub-Agent ────────────────────────────────────
|
||||
async function submitAddSub() {
|
||||
const channel = (document.getElementById('fs-channel')?.value||'telegram').trim();
|
||||
const parentAgentId = document.getElementById('fs-parent').value.trim();
|
||||
const groupId = document.getElementById('fs-gid').value.trim();
|
||||
const telegramUserId = (document.getElementById('fs-tgid')?.value||'').trim();
|
||||
const agentId = document.getElementById('fs-aid').value.trim();
|
||||
const displayName = document.getElementById('fs-name').value.trim();
|
||||
const workspaceFolder = (document.getElementById('fs-workspace')?.value||'').trim() || agentId;
|
||||
const model = document.getElementById('fs-model').value;
|
||||
const purpose = document.getElementById('fs-purpose').value.trim();
|
||||
const personality = document.getElementById('fs-soul').value.trim();
|
||||
const initialMemory = document.getElementById('fs-mem').value.trim();
|
||||
|
||||
if (!parentAgentId) { toast('Parent Agent is required', 'err'); return; }
|
||||
if (!groupId) { toast(t('wiz.errGroupId'), 'err'); return; }
|
||||
if (!agentId) { toast(t('wiz.errAgentId'), 'err'); return; }
|
||||
if (!/^[a-zA-Z0-9_-]+$/.test(agentId)) { toast(t('wiz.errIdFormat'), 'err'); return; }
|
||||
if (telegramUserId && !/^\\d+$/.test(telegramUserId)) { toast('Telegram User ID must be a number', 'err'); return; }
|
||||
if (!workspaceFolder) { toast('Workspace folder is required', 'err'); return; }
|
||||
|
||||
try {
|
||||
const r = await api('POST', '/api/agents', { parentAgentId, agentId, displayName: displayName || agentId, groupId, workspaceFolder: agentId, model: model === '__default__' ? '' : model, purpose, personality, initialMemory, telegramUserId });
|
||||
if (r.error) { toast(r.error, 'err'); return; }
|
||||
if (channel === 'telegram') {
|
||||
const groupId = document.getElementById('fs-gid').value.trim();
|
||||
const telegramUserId = (document.getElementById('fs-tgid')?.value||'').trim();
|
||||
if (!groupId) { toast(t('wiz.errGroupId'), 'err'); return; }
|
||||
if (telegramUserId && !/^\d+$/.test(telegramUserId)) { toast('Telegram User ID must be a number', 'err'); return; }
|
||||
await api('POST', '/api/agents', { parentAgentId, agentId, displayName: displayName || agentId, groupId,
|
||||
workspaceFolder, model: model === '__default__' ? '' : model, purpose, personality, initialMemory, telegramUserId });
|
||||
} else {
|
||||
const link = (document.getElementById('fs-discord-link')?.value||'').trim();
|
||||
const parsed = parseDiscordLinkOrId(link);
|
||||
if (!parsed) { toast('Discord thread link/ID is required', 'err'); return; }
|
||||
await api('POST', '/api/agents/discord-sub', { parentAgentId, agentId, displayName: displayName || agentId,
|
||||
workspaceFolder, model: model === '__default__' ? '' : model, purpose, personality, initialMemory,
|
||||
guildId: parsed.guildId, threadId: parsed.channelId });
|
||||
}
|
||||
toast(t('wiz.created'), 'ok');
|
||||
document.getElementById('addFormArea').innerHTML = '';
|
||||
clearAddForm();
|
||||
showRestartBanner();
|
||||
await loadAll();
|
||||
} catch (e) { toast(e.message, 'err'); }
|
||||
@@ -2895,39 +3237,59 @@ function renderAgents() {
|
||||
const el = document.getElementById('agentTree');
|
||||
if (!S.agents.length) { el.innerHTML = '<div class="empty">' + t('agents.empty') + '</div>'; return; }
|
||||
|
||||
// Build tree: each hasOwnBot agent is a root, others are sub-agents grouped by parentAccountId
|
||||
const roots = S.agents.filter(a => a.hasOwnBot);
|
||||
const subs = S.agents.filter(a => !a.hasOwnBot);
|
||||
// Build grouping: prefer explicit parentAgentId; fallback to telegram bot-root grouping.
|
||||
const byId = {}; (S.agents||[]).forEach(a=>{ byId[a.id]=a; });
|
||||
|
||||
// Map accountId -> root agent for sub-agent grouping
|
||||
const rootByAccount = {};
|
||||
roots.forEach(a => { if (a.accountId) rootByAccount[a.accountId] = a; });
|
||||
|
||||
// Group subs under their parent
|
||||
const subsByRoot = {};
|
||||
const orphanSubs = [];
|
||||
subs.forEach(a => {
|
||||
const parentAcct = a.parentAccountId;
|
||||
if (parentAcct && rootByAccount[parentAcct]) {
|
||||
const rootId = rootByAccount[parentAcct].id;
|
||||
if (!subsByRoot[rootId]) subsByRoot[rootId] = [];
|
||||
subsByRoot[rootId].push(a);
|
||||
} else {
|
||||
orphanSubs.push(a);
|
||||
// infer parentAgentId for legacy telegram sub-agents if missing
|
||||
const accountToRootId = {};
|
||||
(S.agents||[]).forEach(a=>{ if(a.hasOwnBot && a.accountId) accountToRootId[a.accountId]=a.id; });
|
||||
(S.agents||[]).forEach(a=>{
|
||||
if(!a.parentAgentId && !a.hasOwnBot && a.parentAccountId && accountToRootId[a.parentAccountId]){
|
||||
a._inferParentAgentId = accountToRootId[a.parentAccountId];
|
||||
}
|
||||
});
|
||||
|
||||
const roots=[]; const childrenByRoot={}; const orphans=[];
|
||||
(S.agents||[]).forEach(a=>{
|
||||
const pid = a.parentAgentId || a._inferParentAgentId || '';
|
||||
if(pid && byId[pid]){
|
||||
(childrenByRoot[pid] ||= []).push(a);
|
||||
} else {
|
||||
roots.push(a);
|
||||
}
|
||||
});
|
||||
|
||||
function fmtBinding(b){
|
||||
const ch = (b.channel||'').toLowerCase();
|
||||
const peer = b.peerId ? String(b.peerId) : '';
|
||||
const acct = b.accountId ? String(b.accountId) : '';
|
||||
if(ch==='telegram'){
|
||||
if(peer) return '<span class="badge ok ch-badge ch-tg">TG</span> <span class="badge ok">'+esc(peer)+'</span>';
|
||||
if(acct) return '<span class="badge ok ch-badge ch-tg">TG Bot</span> <span class="badge">'+esc(acct)+'</span>';
|
||||
}
|
||||
if(ch==='discord'){
|
||||
if(peer) return '<span class="badge ok ch-badge ch-any">Discord</span> <span class="badge">'+esc(peer)+'</span>';
|
||||
}
|
||||
return '<span class="badge">'+esc(ch||'bind')+'</span>';
|
||||
}
|
||||
|
||||
function bindingsLine(a){
|
||||
const arr = (a.bindings||[]).filter(x=>x.peerId||x.accountId);
|
||||
if(!arr.length) return '';
|
||||
return '<div class="tree-meta">🔗 '+arr.map(fmtBinding).join(' · ')+'</div>';
|
||||
}
|
||||
|
||||
function agentCard(a, isRoot) {
|
||||
let h = '';
|
||||
const icon = isRoot ? '🤖' : '📱';
|
||||
const icon = isRoot ? '🤖' : '🧩';
|
||||
const cls = isRoot ? 'tree-main' : 'tree-child';
|
||||
h += '<div class="' + cls + '">';
|
||||
h += '<div class="tree-title">' + icon + ' ' + esc(a.name || a.id);
|
||||
if (isRoot) h += ' <span class="badge main">' + (a.id === 'main' ? t('agents.main') : 'Bot') + '</span>';
|
||||
if (a.groupId) h += ' <span class="badge ok">' + esc(a.groupId) + '</span>';
|
||||
if (a.id === 'main') h += ' <span class="badge main">' + t('agents.main') + '</span>';
|
||||
h += '</div>';
|
||||
h += '<div class="tree-meta">🧠 ' + esc(a.effectiveModel) + '</div>';
|
||||
if (a.workspace) h += '<div class="tree-meta">📁 ' + esc(a.workspace) + '</div>';
|
||||
h += bindingsLine(a);
|
||||
h += '<div class="tree-actions">';
|
||||
h += '<select class="inline-sel" id="msel-' + a.id + '">' + buildModelOpts(a.effectiveModel !== t('agents.noModel') ? a.effectiveModel : '__default__') + '</select>';
|
||||
h += '<button class="btn-secondary" data-action="saveModel" data-id="' + esc(a.id) + '">' + t('agents.saveModel') + '</button>';
|
||||
@@ -2938,35 +3300,27 @@ function renderAgents() {
|
||||
}
|
||||
|
||||
let html = '<div class="agents-roots">';
|
||||
|
||||
// Render each root with its children, side by side
|
||||
roots.forEach(root => {
|
||||
const children = subsByRoot[root.id] || [];
|
||||
const children = childrenByRoot[root.id] || [];
|
||||
html += '<div class="agent-tree-root">';
|
||||
html += agentCard(root, true);
|
||||
if (children.length) {
|
||||
const treeId = 'tree-' + root.id;
|
||||
html += '<div class="tree-children-wrap">';
|
||||
html += '<button class="tree-toggle" onclick="toggleTree(\\'' + treeId + '\\',this)" title="Expand / Collapse">−</button>';
|
||||
html += '<button class="tree-toggle" data-tree="' + treeId + '" title="Expand / Collapse">−</button>';
|
||||
html += '<div class="tree-children" id="' + treeId + '">';
|
||||
children.forEach(c => { html += agentCard(c, false); });
|
||||
html += '</div></div>';
|
||||
}
|
||||
html += '</div>';
|
||||
});
|
||||
|
||||
// Orphan subs (no matching root — edge case)
|
||||
orphanSubs.forEach(a => {
|
||||
html += '<div class="agent-tree-root">';
|
||||
html += agentCard(a, false);
|
||||
html += '</div>';
|
||||
});
|
||||
|
||||
html += '</div>';
|
||||
el.innerHTML = html;
|
||||
|
||||
// Event delegation for agent tree buttons
|
||||
el.onclick = function(ev) {
|
||||
const tbtn = ev.target.closest('.tree-toggle');
|
||||
if (tbtn && tbtn.dataset.tree) { toggleTree(tbtn.dataset.tree, tbtn); return; }
|
||||
|
||||
const btn = ev.target.closest('[data-action]');
|
||||
if (!btn) return;
|
||||
const action = btn.dataset.action;
|
||||
@@ -3363,7 +3717,14 @@ async function deleteAuth(key){
|
||||
}
|
||||
|
||||
function copyText(txt){
|
||||
navigator.clipboard.writeText(txt).then(()=>toast('已复制','success')).catch(()=>toast('复制失败','error'));
|
||||
navigator.clipboard.writeText(txt).then(()=>toast(lang==='en'?'Copied':'已复制','success')).catch(()=>toast(lang==='en'?'Copy failed':'复制失败','error'));
|
||||
}
|
||||
|
||||
function copyCliCommand(){
|
||||
const inp=document.getElementById('cliInput');
|
||||
const cmd=(inp&&inp.value?inp.value:'').trim();
|
||||
if(!cmd){ toast(lang==='en'?'Nothing to copy (CLI input is empty)':'没有可复制的命令(输入框为空)','error'); return; }
|
||||
copyText(cmd);
|
||||
}
|
||||
|
||||
|
||||
@@ -3603,8 +3964,8 @@ function runCli(){
|
||||
es.addEventListener('done',e=>{
|
||||
try{
|
||||
const d=JSON.parse(e.data);
|
||||
if(d.code===0) cliAppend('\\n✅ 完成 (exit 0)\\n','cli-done-ok');
|
||||
else cliAppend('\\n❌ 退出码 '+d.code+'\\n','cli-done-err');
|
||||
if(d.code===0) cliAppend('\\n✅ Done (exit 0)\\n','cli-done-ok');
|
||||
else cliAppend('\\n❌ Exit code '+d.code+'\\n','cli-done-err');
|
||||
}catch(_){}
|
||||
es.close(); cliEvt=null; setCliRunning(false);
|
||||
});
|
||||
@@ -4071,7 +4432,7 @@ document.querySelectorAll('.tab').forEach(t=>{
|
||||
(function() {
|
||||
LS.del('ocm_mode');
|
||||
applyLang();
|
||||
checkStatus().then(() => { loadAll(); loadDashboard(); }).catch(e => console.error('Init error:', e));
|
||||
checkStatus().then(() => { loadAll(); setTimeout(() => loadDashboard(), 0); }).catch(e => console.error('Init error:', e));
|
||||
startHealthPolling();
|
||||
})();`;
|
||||
|
||||
@@ -4105,6 +4466,21 @@ function assertBrowserScriptSyntax(name, scriptText) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function parseDiscordLinkOrId(input){
|
||||
const raw=(input||'').trim();
|
||||
if(!raw) return null;
|
||||
// URL form: https://discord.com/channels/<guildId>/<channelId>
|
||||
const m = raw.match(/discord(?:app)?\.com\/channels\/(\d+)\/(\d+)/i);
|
||||
if(m) return { guildId: m[1], channelId: m[2] };
|
||||
// Accept plain numeric id
|
||||
if(/^\d+$/.test(raw)) return { guildId: '', channelId: raw };
|
||||
// Accept channel:<id>
|
||||
const m2 = raw.match(/^channel:(\d+)$/i);
|
||||
if(m2) return { guildId: '', channelId: m2[1] };
|
||||
return null;
|
||||
}
|
||||
assertBrowserScriptSyntax('main-html-script', MAIN_HTML_SCRIPT);
|
||||
|
||||
// ── HTTP 服务器 ───────────────────────────────────────────────
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "openclaw-manager",
|
||||
"version": "0.8.2",
|
||||
"description": "A local web UI for managing OpenClaw AI agents — no npm install required",
|
||||
"version": "0.9.3",
|
||||
"description": "A local web UI for managing OpenClaw AI agents \u2014 no npm install required",
|
||||
"main": "openclaw-manager.js",
|
||||
"scripts": {
|
||||
"start": "node openclaw-manager.js",
|
||||
|
||||
Reference in New Issue
Block a user