做第一个即用
不想手写代码的话,请直接在客户端用 即用 → 快速创建即用(见即用概览)。本教程展示一个最小的即用包含哪些内容,方便你审阅或修改。
目标:做一个只有一个页面的小即用。用户粘贴一份变更列表,即用请右侧对话把它整理成发布说明。
开始前:客户端已连接,并配置好了模型;手边有 SoduWork 源码,用来获取 SDK 文件。
1. 创建文件
release-notes-helper/
├─ soduwork-plugin-draft.json
└─ ui/
├─ index.html
├─ app.js
└─ soduwork-app.js 从 client/sdk/soduwork-app.js 复制
ui/index.html
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<title>发布说明</title>
<script src="soduwork-app.js"></script>
</head>
<body>
<h1>发布说明</h1>
<textarea id="changes" rows="10" cols="60" placeholder="每行一条变更"></textarea>
<p><button id="send">生成发布说明</button> <span id="status"></span></p>
<script src="app.js"></script>
</body>
</html>
ui/app.js
const app = window.soduWorkApp;
const status = text => { document.getElementById('status').textContent = text; };
document.getElementById('send').onclick = async () => {
const changes = document.getElementById('changes').value.trim();
if (!changes) return status('请至少填写一条变更。');
const receipt = await app.chat.send({
text: '根据以下变更写一份发布说明:\n' + changes,
requestId: app.createRequestId(),
});
// ok 表示右侧对话已经接收了消息,不代表回复已经完成。
status(receipt.ok ? '已发送到右侧对话。' : receipt.reason);
};
app.events.onRefresh(() => status(''));
2. 编写草稿
soduwork-plugin-draft.json
{
"template": "app",
"key": "release-notes-helper",
"name": "发布说明助手",
"version": "1.0.0",
"author": "你的团队",
"appCategory": "office",
"description": "粘贴一份变更列表,请右侧对话整理成发布说明。",
"instructions": "把用户发来的变更列表整理成发布说明,按新增、改进、修复分组,不要编造变更。",
"ui": {
"contributions": [
{
"id": "main",
"title": "发布说明",
"slot": "workspace.navigation",
"source": {
"type": "package",
"entry": "ui/index.html",
"openMode": "workspace",
"bridge": { "version": 1, "capabilities": ["context.read", "conversation.send", "composer.control"] }
}
}
]
},
"resources": [
{ "path": "ui/index.html", "kind": "ui" },
{ "path": "ui/app.js", "kind": "ui" },
{ "path": "ui/soduwork-app.js", "kind": "ui" }
]
}
| 部分 | 作用 |
|---|---|
instructions | 告诉右侧对话里的 Agent 怎样处理页面发来的内容 |
appCategory | office、game、robot 或 other |
source.type: "package" | 页面随插件分发,不需要服务器 |
bridge.capabilities | conversation.send 允许调用 chat.send。只声明你会调用的能力 |
resources | 页面加载的所有文件,kind 为 ui |
3. 导入
在客户端打开 插件,点 添加插件 → 导入插件,选择 soduwork-plugin-draft.json。客户端会从同一个文件夹收集 resources 里列出的文件,执行预检并安装即用。缺少文件或路径越出文件夹,都会报错。
4. 打开试用
在左侧栏打开 即用,选择 发布说明助手。输入几条变更,点 生成发布说明。这段文字会出现在右侧对话里,Agent 在那里写出发布说明。
确认运行成功
- 页面显示 已发送到右侧对话。
- 右侧对话回复了按新增、改进、修复分组的发布说明。