@mushinjs/plugin-agent 0.0.0-stage → 0.2.0-next.20261112165327
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/index.d.ts +274 -0
- package/dist/index.js +942 -0
- package/dist/index.js.map +1 -0
- package/dist/prompt.d.ts +29 -0
- package/dist/prompt.js +53 -0
- package/dist/prompt.js.map +1 -0
- package/dist/settings.d.ts +75 -0
- package/dist/settings.js +128 -0
- package/dist/settings.js.map +1 -0
- package/dist/skills.d.ts +43 -0
- package/dist/skills.js +126 -0
- package/dist/skills.js.map +1 -0
- package/package.json +55 -3
- package/README.md +0 -3
package/dist/skills.js
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { z } from "@mushinjs/core";
|
|
2
|
+
// src/skills.ts
|
|
3
|
+
const skillFields = {
|
|
4
|
+
name: z.string().trim().min(1).max(80),
|
|
5
|
+
description: z.string().trim().max(300).default(""),
|
|
6
|
+
instructions: z.string().min(1).max(2e4).describe("The steps, in Markdown"),
|
|
7
|
+
whenToUse: z.string().max(500).optional(),
|
|
8
|
+
tools: z.array(z.string()).max(30).optional().describe("Action names it tends to use, e.g. bots.logs"),
|
|
9
|
+
scenes: z.array(z.string()).max(20).optional().describe("Scene keys where it is recommended: overview, bots, botDetail, providers, flows, flowEditor, plugins, logs, personas, knowledge, settings, agent")
|
|
10
|
+
};
|
|
11
|
+
const skillInput = z.object(skillFields);
|
|
12
|
+
/** Skills that ship with the Agent. */
|
|
13
|
+
const BUILTIN_SKILLS = [
|
|
14
|
+
{
|
|
15
|
+
id: "diagnose-bot",
|
|
16
|
+
name: "排查机器人连接",
|
|
17
|
+
description: "机器人离线、连不上 NapCat 或不回复时,按步骤找出原因",
|
|
18
|
+
whenToUse: "机器人状态不是在线,或者在线但不回复消息",
|
|
19
|
+
instructions: [
|
|
20
|
+
"1. 用 bots.list 找到这个机器人,记下状态和错误信息。",
|
|
21
|
+
"2. 用 bots.logs 读它最近的日志:连接地址、NapCat 的 self id、令牌是否被拒绝、登录记录。",
|
|
22
|
+
"3. 根据日志判断:地址或端口不对、NapCat 没开 WebSocket、令牌不一致、消息格式不是 array、反向连接地址不对。",
|
|
23
|
+
"4. 在线但不回复时,用 bots.plugins.list 看插件是否启用,用 flows.route 看一条消息会被谁处理。",
|
|
24
|
+
"5. 给出最可能的原因和具体修改步骤;能直接改的配置(地址、令牌)先说明再改,改完用 bots.get 确认状态。"
|
|
25
|
+
].join("\n"),
|
|
26
|
+
tools: [
|
|
27
|
+
"bots.list",
|
|
28
|
+
"bots.logs",
|
|
29
|
+
"bots.get",
|
|
30
|
+
"bots.plugins.list",
|
|
31
|
+
"flows.route"
|
|
32
|
+
],
|
|
33
|
+
scenes: ["bots", "botDetail"]
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
id: "build-flow",
|
|
37
|
+
name: "搭建流程",
|
|
38
|
+
description: "把一段描述变成可运行的对话流程,并测试通过",
|
|
39
|
+
whenToUse: "想让机器人在某种消息下做某件事",
|
|
40
|
+
instructions: [
|
|
41
|
+
"1. 先问清楚(或从描述中确定):什么消息触发、要回复什么、用在哪个机器人上。",
|
|
42
|
+
"2. 用 flows.nodeTypes 看全部节点类型的一行简介,选出触发器和动作节点(需要计数、冷却、限额时用对应的逻辑节点),再把选中的类型传给 flows.nodeTypes 的 types 读配置和端口。只用列表里有的类型名,不要猜。",
|
|
43
|
+
"3. 用 flows.create 创建流程并绑定机器人,节点之间用 exec 连线,值用 {{节点.输出}} 引用。",
|
|
44
|
+
"4. 用 flows.test 发几条样例消息(包括不该触发的),检查路径和回复;有问题就用 flows.update 修正后再测。",
|
|
45
|
+
"5. 用 ui.navigate 打开 /flows/<id>,简要说明流程怎么工作。"
|
|
46
|
+
].join("\n"),
|
|
47
|
+
tools: [
|
|
48
|
+
"flows.nodeTypes",
|
|
49
|
+
"flows.create",
|
|
50
|
+
"flows.test",
|
|
51
|
+
"flows.update",
|
|
52
|
+
"ui.navigate"
|
|
53
|
+
],
|
|
54
|
+
scenes: ["flows", "flowEditor"]
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
id: "flow-from-chat",
|
|
58
|
+
name: "根据会话创建流程",
|
|
59
|
+
description: "从引用的会话消息出发,搭建并用真实消息验证一个流程",
|
|
60
|
+
whenToUse: "在会话里引用了一条消息,想让机器人对这类消息做出回应",
|
|
61
|
+
instructions: [
|
|
62
|
+
"1. 读消息里的 <quote>:被 → 标出的是用户选中的消息,记下机器人、会话和消息 id。",
|
|
63
|
+
"2. 用 flows.history(带 message)看这条消息已经触发了哪些流程;用 flows.route 看现在发同样内容会被谁处理。",
|
|
64
|
+
"3. 和用户确认想要的效果(触发方式、回复内容、谁能用);能从引用的会话推断的不必再问。",
|
|
65
|
+
"4. 用 flows.nodeTypes 选节点(不带参数看列表,再用 types 读选中节点的配置),用 flows.create 创建流程并绑定到这个机器人。",
|
|
66
|
+
"5. 用 flows.test 带上 sample(引用里给出的 bot、id、channel)验证真实消息能走通;有 AI 节点时用 flows.preview 检查发给模型的内容。再用一两条不该触发的消息测试。",
|
|
67
|
+
"6. 用 ui.navigate 打开 /flows/<id>?sample=<bot>:<channel>:<id>,让用户直接看到样本下的效果。"
|
|
68
|
+
].join("\n"),
|
|
69
|
+
tools: [
|
|
70
|
+
"flows.history",
|
|
71
|
+
"flows.route",
|
|
72
|
+
"flows.nodeTypes",
|
|
73
|
+
"flows.create",
|
|
74
|
+
"flows.update",
|
|
75
|
+
"flows.test",
|
|
76
|
+
"flows.preview",
|
|
77
|
+
"ui.navigate"
|
|
78
|
+
],
|
|
79
|
+
scenes: [
|
|
80
|
+
"botDetail",
|
|
81
|
+
"flows",
|
|
82
|
+
"flowEditor"
|
|
83
|
+
]
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
id: "fix-flow",
|
|
87
|
+
name: "修复流程问题",
|
|
88
|
+
description: "读出流程的校验问题,逐个修好并重新测试",
|
|
89
|
+
whenToUse: "流程编辑器里有错误或警告",
|
|
90
|
+
instructions: [
|
|
91
|
+
"1. 用 flows.get 读当前流程(上下文里有它的 id)和它的 issues。",
|
|
92
|
+
"2. 逐条说明每个问题的原因:缺少节点类型时说明要启用哪个插件;引用不存在的输出时找到正确的节点 id;被其他触发器挡住时用 flows.triggers 看顺序。",
|
|
93
|
+
"3. 能修的用 flows.update 修,修改前简要说明要改什么。",
|
|
94
|
+
"4. 用 flows.test 验证,然后总结改了什么。"
|
|
95
|
+
].join("\n"),
|
|
96
|
+
tools: [
|
|
97
|
+
"flows.get",
|
|
98
|
+
"flows.update",
|
|
99
|
+
"flows.test",
|
|
100
|
+
"flows.triggers"
|
|
101
|
+
],
|
|
102
|
+
scenes: ["flowEditor"]
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
id: "connect-provider",
|
|
106
|
+
name: "连接模型提供商",
|
|
107
|
+
description: "添加一个大模型提供商并测试通过",
|
|
108
|
+
whenToUse: "还没有提供商,或者想换一个模型服务",
|
|
109
|
+
instructions: [
|
|
110
|
+
"1. 问用户要用哪家服务(DeepSeek、通义千问、Moonshot、OpenAI、Anthropic、本地 Ollama)和 API 密钥;本地 Ollama 不需要密钥。",
|
|
111
|
+
"2. 用 providers.types 读配置格式,用 providers.create 创建,填好接口地址和模型。",
|
|
112
|
+
"3. 用 providers.test 测试;失败时根据错误说明原因(密钥、地址、模型名、网络)。",
|
|
113
|
+
"4. 成功后告诉用户延迟,并询问是否设为默认。"
|
|
114
|
+
].join("\n"),
|
|
115
|
+
tools: [
|
|
116
|
+
"providers.types",
|
|
117
|
+
"providers.create",
|
|
118
|
+
"providers.test",
|
|
119
|
+
"providers.setDefault"
|
|
120
|
+
],
|
|
121
|
+
scenes: ["providers", "setup"]
|
|
122
|
+
}
|
|
123
|
+
];
|
|
124
|
+
export { BUILTIN_SKILLS, skillFields, skillInput };
|
|
125
|
+
|
|
126
|
+
//# sourceMappingURL=skills.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skills.js","names":[],"sources":["../src/skills.ts"],"sourcesContent":["import { z } from '@mushinjs/core'\r\n\r\n/** Where a skill comes from: shipped with the Agent, added by a plugin, or written by the user. */\r\nexport type SkillSource = 'builtin' | 'plugin' | 'user'\r\n\r\n/** A reusable way of doing something; picked with `$`, its instructions go into that one message. */\r\nexport interface AgentSkill {\r\n id: string\r\n name: string\r\n /** One line: what it is for. */\r\n description: string\r\n /** The steps, in Markdown. */\r\n instructions: string\r\n /** When to use it, for people picking one. */\r\n whenToUse?: string\r\n /** Actions it tends to use, e.g. `bots.logs`. */\r\n tools?: string[]\r\n /** Scene keys where it is recommended, e.g. `botDetail`. */\r\n scenes?: string[]\r\n source: SkillSource\r\n /** The plugin that added it. */\r\n plugin?: string\r\n /** Off: not offered with `$`. */\r\n enabled: boolean\r\n}\r\n\r\n/** What a plugin passes to `ctx.agent.defineSkill()`. */\r\nexport type SkillDefinition = Omit<AgentSkill, 'source' | 'plugin' | 'enabled'>\r\n\r\nexport const skillFields = {\r\n name: z.string().trim().min(1).max(80),\r\n description: z.string().trim().max(300).default(''),\r\n instructions: z.string().min(1).max(20_000).describe('The steps, in Markdown'),\r\n whenToUse: z.string().max(500).optional(),\r\n tools: z.array(z.string()).max(30).optional().describe('Action names it tends to use, e.g. bots.logs'),\r\n scenes: z.array(z.string()).max(20).optional().describe('Scene keys where it is recommended: overview, bots, botDetail, providers, flows, flowEditor, plugins, logs, personas, knowledge, settings, agent'),\r\n}\r\n\r\nexport const skillInput = z.object(skillFields)\r\n\r\n/** Skills that ship with the Agent. */\r\nexport const BUILTIN_SKILLS: SkillDefinition[] = [\r\n {\r\n id: 'diagnose-bot',\r\n name: '排查机器人连接',\r\n description: '机器人离线、连不上 NapCat 或不回复时,按步骤找出原因',\r\n whenToUse: '机器人状态不是在线,或者在线但不回复消息',\r\n instructions: [\r\n '1. 用 bots.list 找到这个机器人,记下状态和错误信息。',\r\n '2. 用 bots.logs 读它最近的日志:连接地址、NapCat 的 self id、令牌是否被拒绝、登录记录。',\r\n '3. 根据日志判断:地址或端口不对、NapCat 没开 WebSocket、令牌不一致、消息格式不是 array、反向连接地址不对。',\r\n '4. 在线但不回复时,用 bots.plugins.list 看插件是否启用,用 flows.route 看一条消息会被谁处理。',\r\n '5. 给出最可能的原因和具体修改步骤;能直接改的配置(地址、令牌)先说明再改,改完用 bots.get 确认状态。',\r\n ].join('\\n'),\r\n tools: ['bots.list', 'bots.logs', 'bots.get', 'bots.plugins.list', 'flows.route'],\r\n scenes: ['bots', 'botDetail'],\r\n },\r\n {\r\n id: 'build-flow',\r\n name: '搭建流程',\r\n description: '把一段描述变成可运行的对话流程,并测试通过',\r\n whenToUse: '想让机器人在某种消息下做某件事',\r\n instructions: [\r\n '1. 先问清楚(或从描述中确定):什么消息触发、要回复什么、用在哪个机器人上。',\r\n '2. 用 flows.nodeTypes 看全部节点类型的一行简介,选出触发器和动作节点(需要计数、冷却、限额时用对应的逻辑节点),再把选中的类型传给 flows.nodeTypes 的 types 读配置和端口。只用列表里有的类型名,不要猜。',\r\n '3. 用 flows.create 创建流程并绑定机器人,节点之间用 exec 连线,值用 {{节点.输出}} 引用。',\r\n '4. 用 flows.test 发几条样例消息(包括不该触发的),检查路径和回复;有问题就用 flows.update 修正后再测。',\r\n '5. 用 ui.navigate 打开 /flows/<id>,简要说明流程怎么工作。',\r\n ].join('\\n'),\r\n tools: ['flows.nodeTypes', 'flows.create', 'flows.test', 'flows.update', 'ui.navigate'],\r\n scenes: ['flows', 'flowEditor'],\r\n },\r\n {\r\n id: 'flow-from-chat',\r\n name: '根据会话创建流程',\r\n description: '从引用的会话消息出发,搭建并用真实消息验证一个流程',\r\n whenToUse: '在会话里引用了一条消息,想让机器人对这类消息做出回应',\r\n instructions: [\r\n '1. 读消息里的 <quote>:被 → 标出的是用户选中的消息,记下机器人、会话和消息 id。',\r\n '2. 用 flows.history(带 message)看这条消息已经触发了哪些流程;用 flows.route 看现在发同样内容会被谁处理。',\r\n '3. 和用户确认想要的效果(触发方式、回复内容、谁能用);能从引用的会话推断的不必再问。',\r\n '4. 用 flows.nodeTypes 选节点(不带参数看列表,再用 types 读选中节点的配置),用 flows.create 创建流程并绑定到这个机器人。',\r\n '5. 用 flows.test 带上 sample(引用里给出的 bot、id、channel)验证真实消息能走通;有 AI 节点时用 flows.preview 检查发给模型的内容。再用一两条不该触发的消息测试。',\r\n '6. 用 ui.navigate 打开 /flows/<id>?sample=<bot>:<channel>:<id>,让用户直接看到样本下的效果。',\r\n ].join('\\n'),\r\n tools: ['flows.history', 'flows.route', 'flows.nodeTypes', 'flows.create', 'flows.update', 'flows.test', 'flows.preview', 'ui.navigate'],\r\n scenes: ['botDetail', 'flows', 'flowEditor'],\r\n },\r\n {\r\n id: 'fix-flow',\r\n name: '修复流程问题',\r\n description: '读出流程的校验问题,逐个修好并重新测试',\r\n whenToUse: '流程编辑器里有错误或警告',\r\n instructions: [\r\n '1. 用 flows.get 读当前流程(上下文里有它的 id)和它的 issues。',\r\n '2. 逐条说明每个问题的原因:缺少节点类型时说明要启用哪个插件;引用不存在的输出时找到正确的节点 id;被其他触发器挡住时用 flows.triggers 看顺序。',\r\n '3. 能修的用 flows.update 修,修改前简要说明要改什么。',\r\n '4. 用 flows.test 验证,然后总结改了什么。',\r\n ].join('\\n'),\r\n tools: ['flows.get', 'flows.update', 'flows.test', 'flows.triggers'],\r\n scenes: ['flowEditor'],\r\n },\r\n {\r\n id: 'connect-provider',\r\n name: '连接模型提供商',\r\n description: '添加一个大模型提供商并测试通过',\r\n whenToUse: '还没有提供商,或者想换一个模型服务',\r\n instructions: [\r\n '1. 问用户要用哪家服务(DeepSeek、通义千问、Moonshot、OpenAI、Anthropic、本地 Ollama)和 API 密钥;本地 Ollama 不需要密钥。',\r\n '2. 用 providers.types 读配置格式,用 providers.create 创建,填好接口地址和模型。',\r\n '3. 用 providers.test 测试;失败时根据错误说明原因(密钥、地址、模型名、网络)。',\r\n '4. 成功后告诉用户延迟,并询问是否设为默认。',\r\n ].join('\\n'),\r\n tools: ['providers.types', 'providers.create', 'providers.test', 'providers.setDefault'],\r\n scenes: ['providers', 'setup'],\r\n },\r\n]\r\n"],"mappings":";;AA6BA,MAAa,cAAc;CACzB,MAAM,EAAE,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE;CACrC,aAAa,EAAE,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE;CAClD,cAAc,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,GAAM,CAAC,CAAC,SAAS,wBAAwB;CAC7E,WAAW,EAAE,OAAO,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,SAAS;CACxC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS,8CAA8C;CACrG,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS,kJAAkJ;AAC5M;AAEA,MAAa,aAAa,EAAE,OAAO,WAAW;;AAG9C,MAAa,iBAAoC;CAC/C;EACE,IAAI;EACJ,MAAM;EACN,aAAa;EACb,WAAW;EACX,cAAc;GACZ;GACA;GACA;GACA;GACA;EACF,CAAC,CAAC,KAAK,IAAI;EACX,OAAO;GAAC;GAAa;GAAa;GAAY;GAAqB;EAAa;EAChF,QAAQ,CAAC,QAAQ,WAAW;CAC9B;CACA;EACE,IAAI;EACJ,MAAM;EACN,aAAa;EACb,WAAW;EACX,cAAc;GACZ;GACA;GACA;GACA;GACA;EACF,CAAC,CAAC,KAAK,IAAI;EACX,OAAO;GAAC;GAAmB;GAAgB;GAAc;GAAgB;EAAa;EACtF,QAAQ,CAAC,SAAS,YAAY;CAChC;CACA;EACE,IAAI;EACJ,MAAM;EACN,aAAa;EACb,WAAW;EACX,cAAc;GACZ;GACA;GACA;GACA;GACA;GACA;EACF,CAAC,CAAC,KAAK,IAAI;EACX,OAAO;GAAC;GAAiB;GAAe;GAAmB;GAAgB;GAAgB;GAAc;GAAiB;EAAa;EACvI,QAAQ;GAAC;GAAa;GAAS;EAAY;CAC7C;CACA;EACE,IAAI;EACJ,MAAM;EACN,aAAa;EACb,WAAW;EACX,cAAc;GACZ;GACA;GACA;GACA;EACF,CAAC,CAAC,KAAK,IAAI;EACX,OAAO;GAAC;GAAa;GAAgB;GAAc;EAAgB;EACnE,QAAQ,CAAC,YAAY;CACvB;CACA;EACE,IAAI;EACJ,MAAM;EACN,aAAa;EACb,WAAW;EACX,cAAc;GACZ;GACA;GACA;GACA;EACF,CAAC,CAAC,KAAK,IAAI;EACX,OAAO;GAAC;GAAmB;GAAoB;GAAkB;EAAsB;EACvF,QAAQ,CAAC,aAAa,OAAO;CAC/B;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,58 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mushinjs/plugin-agent",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.2.0-next.20261112165327",
|
|
4
|
+
"description": "The Mushin.js Agent",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/mushinjs/mushin.git",
|
|
10
|
+
"directory": "packages/plugin-agent"
|
|
11
|
+
},
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"import": "./dist/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./package.json": "./package.json"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"mushin-plugin"
|
|
27
|
+
],
|
|
28
|
+
"mushin": {
|
|
29
|
+
"kind": "app",
|
|
30
|
+
"displayName": {
|
|
31
|
+
"en": "Agent",
|
|
32
|
+
"zh-CN": "智能体"
|
|
33
|
+
},
|
|
34
|
+
"description": {
|
|
35
|
+
"en": "Operate Mushin.js through natural-language conversation",
|
|
36
|
+
"zh-CN": "通过自然语言对话操作 Mushin.js"
|
|
37
|
+
},
|
|
38
|
+
"provides": [
|
|
39
|
+
"agent"
|
|
40
|
+
],
|
|
41
|
+
"requires": {
|
|
42
|
+
"plugins": {
|
|
43
|
+
"@mushinjs/plugin-storage": "*",
|
|
44
|
+
"@mushinjs/plugin-providers": "*"
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"optional": {
|
|
48
|
+
"plugins": {
|
|
49
|
+
"@mushinjs/plugin-bots": "*"
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
"dependencies": {
|
|
54
|
+
"@mushinjs/core": "0.2.0-next.20261112165327",
|
|
55
|
+
"@mushinjs/plugin-storage": "0.2.0-next.20261112165327",
|
|
56
|
+
"@mushinjs/plugin-providers": "0.2.0-next.20261112165327"
|
|
57
|
+
}
|
|
6
58
|
}
|
package/README.md
DELETED