rol-websocket-channel 1.4.2 → 1.4.8
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/{MQTT-API /346/226/260/345/242/236/346/226/207/344/273/266/345/212/237/350/203/275.md" → MQTT-API 5-6.md } +89 -1
- package/dist/index.js +617 -617
- package/dist/message-handler.js +515 -503
- package/dist/src/admin/cli.js +43 -43
- package/dist/src/admin/jsonrpc.js +60 -60
- package/dist/src/admin/lib/fs.js +30 -30
- package/dist/src/admin/lib/paths.js +80 -80
- package/dist/src/admin/methods/admin.js +60 -60
- package/dist/src/admin/methods/agents-extended.js +251 -251
- package/dist/src/admin/methods/artifacts.js +736 -642
- package/dist/src/admin/methods/artifacts.test.js +210 -191
- package/dist/src/admin/methods/cron.js +250 -250
- package/dist/src/admin/methods/index.js +104 -102
- package/dist/src/admin/methods/mem9.js +309 -270
- package/dist/src/admin/methods/mem9.test.js +34 -0
- package/dist/src/admin/methods/memory.js +363 -363
- package/dist/src/admin/methods/models-extended.js +190 -190
- package/dist/src/admin/methods/models.js +195 -195
- package/dist/src/admin/methods/pairing.js +268 -268
- package/dist/src/admin/methods/sessions-extended.js +215 -215
- package/dist/src/admin/methods/sessions.js +75 -75
- package/dist/src/admin/methods/skills-extended.js +157 -157
- package/dist/src/admin/methods/skills-toggle.js +183 -183
- package/dist/src/admin/methods/skills.js +528 -528
- package/dist/src/admin/methods/system.js +271 -180
- package/dist/src/admin/methods/usage.js +1170 -1170
- package/dist/src/admin/types.js +1 -1
- package/dist/src/mqtt/connection-manager.js +209 -209
- package/dist/src/mqtt/index.js +5 -5
- package/dist/src/mqtt/mqtt-client.js +110 -110
- package/dist/src/mqtt/mqtt.test.js +418 -418
- package/dist/src/mqtt/types.js +2 -2
- package/dist/src/shared/context.js +24 -24
- package/dist/src/shared/wrapper.js +23 -23
- package/message-handler.ts +15 -1
- package/openclaw.plugin.json +73 -0
- package/package.json +1 -1
- package/src/admin/methods/artifacts.test.ts +35 -0
- package/src/admin/methods/artifacts.ts +140 -2
- package/src/admin/methods/index.ts +3 -1
- package/src/admin/methods/mem9.test.ts +39 -0
- package/src/admin/methods/mem9.ts +48 -1
- package/src/admin/methods/system.ts +129 -1
|
@@ -1,183 +1,183 @@
|
|
|
1
|
-
import { readJsonFile, writeJsonFile } from '../lib/fs.js';
|
|
2
|
-
import { JsonRpcException, JSON_RPC_ERRORS } from '../jsonrpc.js';
|
|
3
|
-
import { getInstalledSkillsFromCli } from './skills.js';
|
|
4
|
-
import path from 'node:path';
|
|
5
|
-
/**
|
|
6
|
-
* 启用或停用 skill
|
|
7
|
-
* 通过修改 agents.defaults.skills 数组来控制
|
|
8
|
-
*/
|
|
9
|
-
export const toggleSkill = async (params, context) => {
|
|
10
|
-
const objectParams = expectObject(params);
|
|
11
|
-
const slug = expectString(objectParams.slug, 'slug');
|
|
12
|
-
const enabled = expectBoolean(objectParams.enabled, 'enabled');
|
|
13
|
-
const agentName = typeof objectParams.agentName === 'string' ? objectParams.agentName : 'defaults';
|
|
14
|
-
if (agentName !== 'defaults') {
|
|
15
|
-
throw new JsonRpcException(JSON_RPC_ERRORS.invalidParams, 'Currently only "defaults" agent is supported');
|
|
16
|
-
}
|
|
17
|
-
const allSkills = await getInstalledSkillsFromCli(context);
|
|
18
|
-
const runtimeSkill = allSkills.find((item) => isObject(item) && typeof item.slug === 'string' && item.slug === slug);
|
|
19
|
-
if (!runtimeSkill || !isObject(runtimeSkill)) {
|
|
20
|
-
throw new JsonRpcException(JSON_RPC_ERRORS.invalidParams, `Skill not installed: ${slug}`);
|
|
21
|
-
}
|
|
22
|
-
const bundled = runtimeSkill.bundled === true;
|
|
23
|
-
const configPath = path.join(context.openclawRoot, 'openclaw.json');
|
|
24
|
-
const config = await readJsonFile(configPath);
|
|
25
|
-
if (!config.skills)
|
|
26
|
-
config.skills = {};
|
|
27
|
-
if (!config.skills.entries)
|
|
28
|
-
config.skills.entries = {};
|
|
29
|
-
const skillEntries = config.skills.entries;
|
|
30
|
-
if (!skillEntries[slug] || typeof skillEntries[slug] !== 'object') {
|
|
31
|
-
skillEntries[slug] = {};
|
|
32
|
-
}
|
|
33
|
-
skillEntries[slug].enabled = enabled;
|
|
34
|
-
if (bundled) {
|
|
35
|
-
if (!config.skills)
|
|
36
|
-
config.skills = {};
|
|
37
|
-
const currentAllowBundled = Array.isArray(config.skills.allowBundled)
|
|
38
|
-
? config.skills.allowBundled
|
|
39
|
-
: [];
|
|
40
|
-
const skillIndex = currentAllowBundled.indexOf(slug);
|
|
41
|
-
if (enabled) {
|
|
42
|
-
if (skillIndex === -1) {
|
|
43
|
-
currentAllowBundled.push(slug);
|
|
44
|
-
config.skills.allowBundled = currentAllowBundled;
|
|
45
|
-
await writeJsonFile(configPath, config);
|
|
46
|
-
return {
|
|
47
|
-
success: true,
|
|
48
|
-
action: 'enabled',
|
|
49
|
-
slug,
|
|
50
|
-
bundled: true,
|
|
51
|
-
skillEntry: skillEntries[slug],
|
|
52
|
-
allowBundled: config.skills.allowBundled
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
await writeJsonFile(configPath, config);
|
|
56
|
-
return {
|
|
57
|
-
success: true,
|
|
58
|
-
action: 'already_enabled',
|
|
59
|
-
slug,
|
|
60
|
-
bundled: true,
|
|
61
|
-
skillEntry: skillEntries[slug],
|
|
62
|
-
allowBundled: currentAllowBundled
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
if (skillIndex !== -1) {
|
|
66
|
-
currentAllowBundled.splice(skillIndex, 1);
|
|
67
|
-
config.skills.allowBundled = currentAllowBundled;
|
|
68
|
-
await writeJsonFile(configPath, config);
|
|
69
|
-
return {
|
|
70
|
-
success: true,
|
|
71
|
-
action: 'disabled',
|
|
72
|
-
slug,
|
|
73
|
-
bundled: true,
|
|
74
|
-
skillEntry: skillEntries[slug],
|
|
75
|
-
allowBundled: config.skills.allowBundled
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
await writeJsonFile(configPath, config);
|
|
79
|
-
return {
|
|
80
|
-
success: true,
|
|
81
|
-
action: 'already_disabled',
|
|
82
|
-
slug,
|
|
83
|
-
bundled: true,
|
|
84
|
-
skillEntry: skillEntries[slug],
|
|
85
|
-
allowBundled: currentAllowBundled
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
const installPath = (() => {
|
|
89
|
-
if (!isObject(runtimeSkill))
|
|
90
|
-
return null;
|
|
91
|
-
const p = runtimeSkill.installPath ?? runtimeSkill.customInstallPath;
|
|
92
|
-
return typeof p === 'string' && p.length > 0 ? p : null;
|
|
93
|
-
})();
|
|
94
|
-
if (!installPath) {
|
|
95
|
-
const globalSkillPath = path.join(context.openclawRoot, 'skills', slug);
|
|
96
|
-
const workspaceSkillPath = path.join(context.openclawRoot, 'workspace', '.openclaw', 'skills', slug);
|
|
97
|
-
const { pathExists } = await import('../lib/fs.js');
|
|
98
|
-
if (!(await pathExists(globalSkillPath)) && !(await pathExists(workspaceSkillPath))) {
|
|
99
|
-
throw new JsonRpcException(JSON_RPC_ERRORS.invalidParams, `Skill not installed: ${slug}`);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
if (!config.agents)
|
|
103
|
-
config.agents = {};
|
|
104
|
-
if (!config.agents.defaults)
|
|
105
|
-
config.agents.defaults = {};
|
|
106
|
-
if (!config.agents.defaults.skills)
|
|
107
|
-
config.agents.defaults.skills = [];
|
|
108
|
-
const currentSkills = config.agents.defaults.skills;
|
|
109
|
-
const skillIndex = currentSkills.indexOf(slug);
|
|
110
|
-
if (enabled) {
|
|
111
|
-
// 启用:如果不在列表中,添加
|
|
112
|
-
if (skillIndex === -1) {
|
|
113
|
-
currentSkills.push(slug);
|
|
114
|
-
await writeJsonFile(configPath, config);
|
|
115
|
-
return {
|
|
116
|
-
success: true,
|
|
117
|
-
action: 'enabled',
|
|
118
|
-
slug,
|
|
119
|
-
agentName,
|
|
120
|
-
skillEntry: config.skills.entries[slug],
|
|
121
|
-
currentSkills: config.agents.defaults.skills
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
else {
|
|
125
|
-
await writeJsonFile(configPath, config);
|
|
126
|
-
return {
|
|
127
|
-
success: true,
|
|
128
|
-
action: 'already_enabled',
|
|
129
|
-
slug,
|
|
130
|
-
agentName,
|
|
131
|
-
skillEntry: config.skills.entries[slug],
|
|
132
|
-
currentSkills: config.agents.defaults.skills
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
else {
|
|
137
|
-
// 停用:如果在列表中,移除
|
|
138
|
-
if (skillIndex !== -1) {
|
|
139
|
-
currentSkills.splice(skillIndex, 1);
|
|
140
|
-
await writeJsonFile(configPath, config);
|
|
141
|
-
return {
|
|
142
|
-
success: true,
|
|
143
|
-
action: 'disabled',
|
|
144
|
-
slug,
|
|
145
|
-
agentName,
|
|
146
|
-
skillEntry: config.skills.entries[slug],
|
|
147
|
-
currentSkills: config.agents.defaults.skills
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
else {
|
|
151
|
-
await writeJsonFile(configPath, config);
|
|
152
|
-
return {
|
|
153
|
-
success: true,
|
|
154
|
-
action: 'already_disabled',
|
|
155
|
-
slug,
|
|
156
|
-
agentName,
|
|
157
|
-
skillEntry: config.skills.entries[slug],
|
|
158
|
-
currentSkills: config.agents.defaults.skills
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
};
|
|
163
|
-
function expectObject(value) {
|
|
164
|
-
if (!value || Array.isArray(value) || typeof value !== 'object') {
|
|
165
|
-
throw new JsonRpcException(JSON_RPC_ERRORS.invalidParams, 'Params must be an object');
|
|
166
|
-
}
|
|
167
|
-
return value;
|
|
168
|
-
}
|
|
169
|
-
function expectString(value, fieldName) {
|
|
170
|
-
if (typeof value !== 'string' || value.trim().length === 0) {
|
|
171
|
-
throw new JsonRpcException(JSON_RPC_ERRORS.invalidParams, `Field '${fieldName}' must be a non-empty string`);
|
|
172
|
-
}
|
|
173
|
-
return value.trim();
|
|
174
|
-
}
|
|
175
|
-
function expectBoolean(value, fieldName) {
|
|
176
|
-
if (typeof value !== 'boolean') {
|
|
177
|
-
throw new JsonRpcException(JSON_RPC_ERRORS.invalidParams, `Field '${fieldName}' must be a boolean`);
|
|
178
|
-
}
|
|
179
|
-
return value;
|
|
180
|
-
}
|
|
181
|
-
function isObject(value) {
|
|
182
|
-
return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
|
|
183
|
-
}
|
|
1
|
+
import { readJsonFile, writeJsonFile } from '../lib/fs.js';
|
|
2
|
+
import { JsonRpcException, JSON_RPC_ERRORS } from '../jsonrpc.js';
|
|
3
|
+
import { getInstalledSkillsFromCli } from './skills.js';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
/**
|
|
6
|
+
* 启用或停用 skill
|
|
7
|
+
* 通过修改 agents.defaults.skills 数组来控制
|
|
8
|
+
*/
|
|
9
|
+
export const toggleSkill = async (params, context) => {
|
|
10
|
+
const objectParams = expectObject(params);
|
|
11
|
+
const slug = expectString(objectParams.slug, 'slug');
|
|
12
|
+
const enabled = expectBoolean(objectParams.enabled, 'enabled');
|
|
13
|
+
const agentName = typeof objectParams.agentName === 'string' ? objectParams.agentName : 'defaults';
|
|
14
|
+
if (agentName !== 'defaults') {
|
|
15
|
+
throw new JsonRpcException(JSON_RPC_ERRORS.invalidParams, 'Currently only "defaults" agent is supported');
|
|
16
|
+
}
|
|
17
|
+
const allSkills = await getInstalledSkillsFromCli(context);
|
|
18
|
+
const runtimeSkill = allSkills.find((item) => isObject(item) && typeof item.slug === 'string' && item.slug === slug);
|
|
19
|
+
if (!runtimeSkill || !isObject(runtimeSkill)) {
|
|
20
|
+
throw new JsonRpcException(JSON_RPC_ERRORS.invalidParams, `Skill not installed: ${slug}`);
|
|
21
|
+
}
|
|
22
|
+
const bundled = runtimeSkill.bundled === true;
|
|
23
|
+
const configPath = path.join(context.openclawRoot, 'openclaw.json');
|
|
24
|
+
const config = await readJsonFile(configPath);
|
|
25
|
+
if (!config.skills)
|
|
26
|
+
config.skills = {};
|
|
27
|
+
if (!config.skills.entries)
|
|
28
|
+
config.skills.entries = {};
|
|
29
|
+
const skillEntries = config.skills.entries;
|
|
30
|
+
if (!skillEntries[slug] || typeof skillEntries[slug] !== 'object') {
|
|
31
|
+
skillEntries[slug] = {};
|
|
32
|
+
}
|
|
33
|
+
skillEntries[slug].enabled = enabled;
|
|
34
|
+
if (bundled) {
|
|
35
|
+
if (!config.skills)
|
|
36
|
+
config.skills = {};
|
|
37
|
+
const currentAllowBundled = Array.isArray(config.skills.allowBundled)
|
|
38
|
+
? config.skills.allowBundled
|
|
39
|
+
: [];
|
|
40
|
+
const skillIndex = currentAllowBundled.indexOf(slug);
|
|
41
|
+
if (enabled) {
|
|
42
|
+
if (skillIndex === -1) {
|
|
43
|
+
currentAllowBundled.push(slug);
|
|
44
|
+
config.skills.allowBundled = currentAllowBundled;
|
|
45
|
+
await writeJsonFile(configPath, config);
|
|
46
|
+
return {
|
|
47
|
+
success: true,
|
|
48
|
+
action: 'enabled',
|
|
49
|
+
slug,
|
|
50
|
+
bundled: true,
|
|
51
|
+
skillEntry: skillEntries[slug],
|
|
52
|
+
allowBundled: config.skills.allowBundled
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
await writeJsonFile(configPath, config);
|
|
56
|
+
return {
|
|
57
|
+
success: true,
|
|
58
|
+
action: 'already_enabled',
|
|
59
|
+
slug,
|
|
60
|
+
bundled: true,
|
|
61
|
+
skillEntry: skillEntries[slug],
|
|
62
|
+
allowBundled: currentAllowBundled
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
if (skillIndex !== -1) {
|
|
66
|
+
currentAllowBundled.splice(skillIndex, 1);
|
|
67
|
+
config.skills.allowBundled = currentAllowBundled;
|
|
68
|
+
await writeJsonFile(configPath, config);
|
|
69
|
+
return {
|
|
70
|
+
success: true,
|
|
71
|
+
action: 'disabled',
|
|
72
|
+
slug,
|
|
73
|
+
bundled: true,
|
|
74
|
+
skillEntry: skillEntries[slug],
|
|
75
|
+
allowBundled: config.skills.allowBundled
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
await writeJsonFile(configPath, config);
|
|
79
|
+
return {
|
|
80
|
+
success: true,
|
|
81
|
+
action: 'already_disabled',
|
|
82
|
+
slug,
|
|
83
|
+
bundled: true,
|
|
84
|
+
skillEntry: skillEntries[slug],
|
|
85
|
+
allowBundled: currentAllowBundled
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
const installPath = (() => {
|
|
89
|
+
if (!isObject(runtimeSkill))
|
|
90
|
+
return null;
|
|
91
|
+
const p = runtimeSkill.installPath ?? runtimeSkill.customInstallPath;
|
|
92
|
+
return typeof p === 'string' && p.length > 0 ? p : null;
|
|
93
|
+
})();
|
|
94
|
+
if (!installPath) {
|
|
95
|
+
const globalSkillPath = path.join(context.openclawRoot, 'skills', slug);
|
|
96
|
+
const workspaceSkillPath = path.join(context.openclawRoot, 'workspace', '.openclaw', 'skills', slug);
|
|
97
|
+
const { pathExists } = await import('../lib/fs.js');
|
|
98
|
+
if (!(await pathExists(globalSkillPath)) && !(await pathExists(workspaceSkillPath))) {
|
|
99
|
+
throw new JsonRpcException(JSON_RPC_ERRORS.invalidParams, `Skill not installed: ${slug}`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (!config.agents)
|
|
103
|
+
config.agents = {};
|
|
104
|
+
if (!config.agents.defaults)
|
|
105
|
+
config.agents.defaults = {};
|
|
106
|
+
if (!config.agents.defaults.skills)
|
|
107
|
+
config.agents.defaults.skills = [];
|
|
108
|
+
const currentSkills = config.agents.defaults.skills;
|
|
109
|
+
const skillIndex = currentSkills.indexOf(slug);
|
|
110
|
+
if (enabled) {
|
|
111
|
+
// 启用:如果不在列表中,添加
|
|
112
|
+
if (skillIndex === -1) {
|
|
113
|
+
currentSkills.push(slug);
|
|
114
|
+
await writeJsonFile(configPath, config);
|
|
115
|
+
return {
|
|
116
|
+
success: true,
|
|
117
|
+
action: 'enabled',
|
|
118
|
+
slug,
|
|
119
|
+
agentName,
|
|
120
|
+
skillEntry: config.skills.entries[slug],
|
|
121
|
+
currentSkills: config.agents.defaults.skills
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
await writeJsonFile(configPath, config);
|
|
126
|
+
return {
|
|
127
|
+
success: true,
|
|
128
|
+
action: 'already_enabled',
|
|
129
|
+
slug,
|
|
130
|
+
agentName,
|
|
131
|
+
skillEntry: config.skills.entries[slug],
|
|
132
|
+
currentSkills: config.agents.defaults.skills
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
// 停用:如果在列表中,移除
|
|
138
|
+
if (skillIndex !== -1) {
|
|
139
|
+
currentSkills.splice(skillIndex, 1);
|
|
140
|
+
await writeJsonFile(configPath, config);
|
|
141
|
+
return {
|
|
142
|
+
success: true,
|
|
143
|
+
action: 'disabled',
|
|
144
|
+
slug,
|
|
145
|
+
agentName,
|
|
146
|
+
skillEntry: config.skills.entries[slug],
|
|
147
|
+
currentSkills: config.agents.defaults.skills
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
await writeJsonFile(configPath, config);
|
|
152
|
+
return {
|
|
153
|
+
success: true,
|
|
154
|
+
action: 'already_disabled',
|
|
155
|
+
slug,
|
|
156
|
+
agentName,
|
|
157
|
+
skillEntry: config.skills.entries[slug],
|
|
158
|
+
currentSkills: config.agents.defaults.skills
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
function expectObject(value) {
|
|
164
|
+
if (!value || Array.isArray(value) || typeof value !== 'object') {
|
|
165
|
+
throw new JsonRpcException(JSON_RPC_ERRORS.invalidParams, 'Params must be an object');
|
|
166
|
+
}
|
|
167
|
+
return value;
|
|
168
|
+
}
|
|
169
|
+
function expectString(value, fieldName) {
|
|
170
|
+
if (typeof value !== 'string' || value.trim().length === 0) {
|
|
171
|
+
throw new JsonRpcException(JSON_RPC_ERRORS.invalidParams, `Field '${fieldName}' must be a non-empty string`);
|
|
172
|
+
}
|
|
173
|
+
return value.trim();
|
|
174
|
+
}
|
|
175
|
+
function expectBoolean(value, fieldName) {
|
|
176
|
+
if (typeof value !== 'boolean') {
|
|
177
|
+
throw new JsonRpcException(JSON_RPC_ERRORS.invalidParams, `Field '${fieldName}' must be a boolean`);
|
|
178
|
+
}
|
|
179
|
+
return value;
|
|
180
|
+
}
|
|
181
|
+
function isObject(value) {
|
|
182
|
+
return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
|
|
183
|
+
}
|