Repository navigation
zh dev star guides plugin views workbench
Note
目前仅支持 AstrBot ChatUI。
使用 target="chat_workbench" 在 ChatUI 右侧展示界面。文件预览可以由消息或工具打开;笔记、会话分析等常驻页面可以从工作台「+」入口打开。

下载上下文用量示例插件。安装后,打开 ChatUI 会话,点击工作台「+」,在「新工作台」中选择「上下文用量」,无需工具调用。页面从 bridge context 获取当前 sessionId,展示系统指令、工具定义、对话和工具结果的 token 估算。
发送一条消息后点击「刷新」,可以查看最近请求的完整来源分布;未观测过请求的来源显示为未知。数值是估算,不代表模型实际计费 token。常驻页面的注册方式见添加常驻入口。
注册 preview 视图,让工具返回 event.view_result()。title 是标签标题,消息中会保留重新打开的入口。线程面板没有工作台,会将视图显示在消息中。
在 metadata.yaml 中添加:
views:
- name: preview
target: chat_workbench
title: Previewmain.py:
from astrbot.api.event import AstrMessageEvent, filter
from astrbot.api.star import Star
class PreviewPlugin(Star):
@filter.llm_tool(name="open_preview")
async def open_preview(self, event: AstrMessageEvent):
"""Open a preview in the workbench.
Args:
event: Incoming tool event.
Returns:
A view and a text result for the model.
"""
return event.view_result(
name="preview",
title="Notes",
data={"content": "Notes to review."},
text="Opened notes in the workbench.",
)在 views/preview/index.html 和同目录的 app.js 中显示工具返回的数据:
<!doctype html>
<html>
<head><meta charset="utf-8" /><title>Notes</title></head>
<body>
<pre id="content"></pre>
<script type="module" src="./app.js"></script>
</body>
</html>const bridge = window.AstrBotPluginView;
await bridge.ready();
bridge.view.subscribe(({ data }) => {
document.getElementById("content").textContent = data.content;
});工具执行后,工作台显示 Notes 标签和正文。需要操作回调时,按消息交互组件声明 actions,并使用 bridge.view.action()。
在 metadata 中使用 chat_workbench_with_launcher,视图便可以从「+」入口打开,也仍然可以通过 event.view_result() 由插件主动打开:
views:
- name: context
target: chat_workbench_with_launcher
title: 上下文用量
description: 查看当前会话的上下文分布创建入口文件后重载插件。在 ChatUI 工作台点击「+」,选择 上下文用量。从入口打开的同一个视图在每个会话中只保留一个标签。
交互能力取决于打开方式。消息或工具创建的实例带有 context.view,可以使用 view.subscribe/action;打开本身不触发 action,纯预览不需要声明 actions。从「+」打开的实例没有消息快照,使用插件 Web API、文件传输和 SSE,并收到当前 sessionId。同一个页面可检查 context.view,分别处理这两种模式。
sessionId 在未打开会话时为 null。切换会话会恢复对应会话的页面和 context:
const bridge = window.AstrBotPluginView;
await bridge.ready();
bridge.onContext(({ sessionId }) => {
// Fetch session-specific aggregates from your authenticated plugin API.
if (sessionId) bridge.apiGet("usage", { session_id: sessionId });
});插件后端必须用 request.username 校验会话归属,不能把前端传入的 sessionId 当作授权。异步请求要避免旧会话的响应覆盖新会话。所有 target 继续共用主题 CSS tokens 和 onContext()。
仅 chat_workbench_with_launcher 常驻视图(没有 context.view)提供以下接口,通常绑定到用户点击操作:
await bridge.chat.fill("请帮我修改这段文字。");
await bridge.chat.send("请总结我选中的内容。");fill 将文字追加到当前草稿并聚焦聊天框;send 直接发到当前会话,保留已有草稿与暂存附件。没有打开会话、会话已经切换或正在生成时,发送会被拒绝。Promise 在发送请求被接受时完成,不等待 bot 回复完成。
如果插件允许 agent 编辑文档,应在插件后端记录用户提交时的选区和版本,让工具只接收选区 ID 与替换文字。不要依赖提示词要求 agent 保留全文。工具保存后可以通过插件 SSE 通知常驻视图重新读取,客户端仍需保护未保存的本地编辑。
每个用户的标签、选中项和展开/收起状态按会话保存在浏览器中。切换会话时恢复对应的工作台;刷新不会自动打开已关闭的标签。插件业务数据需要由插件后端持久化。
主题、文件传输和 SSE 接口见共享 Bridge API,后端鉴权与数据访问见后端 Web API。
- 首页
- 文档入口
- Top Level
- community events
- config
- deploy
- dev
- others
- platform
- 接入 OneBot v11 协议实现
- 接入钉钉 DingTalk
- 接入 Discord
- 接入 Kook
- 接入飞书
- 接入 LINE
- 接入 Matrix
- 接入 Mattermost
- 接入 Misskey 平台
- 接入 QQ 官方机器人平台
- 通过 QQ官方机器人 接入 QQ (Webhook)
- 通过 QQ官方机器人 接入 QQ (Websockets)
- 接入 Satori 协议
- 接入 server-satori (基于 Koishi)
- 接入 Slack
- 接入消息平台
- 接入 Telegram
- 接入 VoceChat
- AstrBot 接入企业微信
- 接入企业微信智能机器人平台
- AstrBot 接入微信公众平台
- 接入个人微信
- providers
- use
- Home
- Docs Entry
- Top Level
- config
- deploy
- Deploy AstrBot on 1Panel
- Deploy AstrBot on BT Panel
- Deploy AstrBot on CasaOS
- Deploy AstrBot from Source Code
- Community-Provided Deployment Methods
- Deploy via Compshare
- Deploy with AstrBot Desktop Client
- Deploy AstrBot with Docker
- Deploy AstrBot with Kubernetes
- Deploy AstrBot with AstrBot Launcher
- Other Deployments
- Script Deployment
- Installation via System Package Manager
- Preface
- dev
- AstrBot Configuration File
- API Scope–Endpoint Reference
- AstrBot HTTP API
- AstrBot Plugin Market JSON Specification
- AstrBot Plugin Market JSON Specification
- Developing a Platform Adapter
- plugin
- AI
- Agents
- Sessions and Conversations
- Models
- Other APIs
- Tools
- Documentation moved
- Text to Image
- Handling Message Events
- Plugin Configuration
- Plugin Internationalization
- Documentation moved
- Shared Bridge API
- Interactive message component
- Standalone plugin page
- Backend Web APIs
- Workbench page
- Sending Messages
- Session Control
- Minimal Example
- Plugin Storage
- AstrBot Plugin Development Guide 🌠
- Publishing Plugins to the Plugin Marketplace
- ospp
- others
- platform
- Connect OneBot v11 Protocol Implementations
- Connect to DingTalk
- Connecting to Discord
- Connect to KOOK
- Connecting to Lark
- Connecting to LINE
- Connecting to Matrix
- Connecting to Mattermost
- Connecting to Misskey Platform
- Connect QQ Official Bot
- Connect QQ via QQ Official Bot (Webhook)
- Connect QQ via QQ Official Bot (Websockets)
- Connect to Satori Protocol
- Connect server-satori (Koishi)
- Connecting to Slack
- Messaging Platforms
- Connecting to Telegram
- Connect to VoceChat
- Connect AstrBot to WeCom
- Connect to WeCom AI Bot Platform
- Connect AstrBot to WeChat Official Account Platform
- Connect Personal WeChat
- providers
- Connect 302.AI
- Agent Runners
- Built-in Agent Runner
- Connect to Coze
- Connect to Alibaba Cloud Bailian Application
- Connect to DeerFlow
- Connect to Dify
- Connect AIHubMix
- coze
- dashscope
- DeepSeek STT Integration
- DeepSeek TTS Integration
- dify
- Model input images
- Large Language Model Providers
- Connect MiraRouter
- NewAPI
- Connect PPIO Cloud
- Connect LM Studio to Use DeepSeek-R1 and Other Models
- Integrating Ollama
- Connect ShengSuanYun
- Connecting to SiliconFlow
- Connecting Model Services
- Connecting to TokenPony
- use
- Agent Execution Mode {#agent-runner}
- Agent Sandbox Environment
- astrbot sandbox
- AstrBot CLI {#cli-commands}
- Docker-based Code Interpreter
- Built-in Commands
- computer
- Context Compression
- Session Configuration Mappings (formerly Custom Rules)
- AstrBot Knowledge Base
- MCP
- AstrBot Plugins {#astrbot-star}
- Proactive Capabilities
- Skills {#anthropic-skills}
- Subagents {#agent-handsoff-and-subagent}
- Unified Webhook Mode
- Web Search
- DeepSeek Search API
- SerpApi
- WebUI