rol-websocket-channel 1.4.8 → 1.4.9

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.
Files changed (38) hide show
  1. package/dist/index.js +623 -617
  2. package/dist/message-handler.js +515 -515
  3. package/dist/src/admin/cli-manifest.test.js +62 -0
  4. package/dist/src/admin/cli.js +43 -43
  5. package/dist/src/admin/jsonrpc.js +60 -60
  6. package/dist/src/admin/lib/fs.js +30 -30
  7. package/dist/src/admin/lib/paths.js +80 -80
  8. package/dist/src/admin/methods/admin.js +60 -60
  9. package/dist/src/admin/methods/agents-extended.js +251 -251
  10. package/dist/src/admin/methods/artifacts.js +736 -736
  11. package/dist/src/admin/methods/artifacts.test.js +210 -210
  12. package/dist/src/admin/methods/cron.js +250 -250
  13. package/dist/src/admin/methods/index.js +104 -104
  14. package/dist/src/admin/methods/mem9.js +309 -309
  15. package/dist/src/admin/methods/mem9.test.js +34 -34
  16. package/dist/src/admin/methods/memory.js +363 -363
  17. package/dist/src/admin/methods/models-extended.js +190 -190
  18. package/dist/src/admin/methods/models.js +195 -195
  19. package/dist/src/admin/methods/pairing.js +268 -268
  20. package/dist/src/admin/methods/sessions-extended.js +215 -215
  21. package/dist/src/admin/methods/sessions.js +75 -75
  22. package/dist/src/admin/methods/skills-extended.js +157 -157
  23. package/dist/src/admin/methods/skills-toggle.js +183 -183
  24. package/dist/src/admin/methods/skills.js +528 -528
  25. package/dist/src/admin/methods/system.js +271 -271
  26. package/dist/src/admin/methods/usage.js +1170 -1170
  27. package/dist/src/admin/types.js +1 -1
  28. package/dist/src/mqtt/connection-manager.js +209 -209
  29. package/dist/src/mqtt/index.js +5 -5
  30. package/dist/src/mqtt/mqtt-client.js +110 -110
  31. package/dist/src/mqtt/mqtt.test.js +418 -418
  32. package/dist/src/mqtt/types.js +2 -2
  33. package/dist/src/shared/context.js +24 -24
  34. package/dist/src/shared/wrapper.js +23 -23
  35. package/index.ts +6 -0
  36. package/openclaw.plugin.json +7 -0
  37. package/package.json +1 -1
  38. package/src/admin/cli-manifest.test.ts +67 -0
@@ -1,515 +1,515 @@
1
- /**
2
- * 消息处理器类
3
- * 根据消息类型调用对应的 admin 方法
4
- */
5
- import { getContext } from './src/shared/context.js';
6
- import { wrapAdminCall } from './src/shared/wrapper.js';
7
- import { getAgents, getConfig } from './src/admin/methods/admin.js';
8
- import { createAgent, deleteAgent, listAgents, updateAgent } from './src/admin/methods/agents-extended.js';
9
- import { createArtifactRecord, ensureArtifactUploaded, getArtifactContent, getArtifactPresignedPost, listArtifacts, markArtifactUploaded, refreshArtifacts } from './src/admin/methods/artifacts.js';
10
- import { addCron, disableCron, enableCron, getCronStatus, listCron, listCronRuns, renameCron, removeCron, rescheduleCron, runCron, setCronContent, updateCronMessage, updateCronSystemEvent } from './src/admin/methods/cron.js';
11
- import { listSessions } from './src/admin/methods/sessions.js';
12
- import { getSession, prepareMessage, attachSkill } from './src/admin/methods/sessions-extended.js';
13
- import { getModels } from './src/admin/methods/models.js';
14
- import { setModel, updateModels } from './src/admin/methods/models-extended.js';
15
- import { getUsagePageSummary, getUsageTimeseries, getUsageBreakdown, getUsageSummary, } from './src/admin/methods/usage.js';
16
- import { listInstalledSkills, installSkillFromNpm, searchClawHubSkills, installSkillFromClawHub, updateSkillFromClawHub } from './src/admin/methods/skills.js';
17
- import { uninstallSkill } from './src/admin/methods/skills-extended.js';
18
- import { toggleSkill } from './src/admin/methods/skills-toggle.js';
19
- import { listMemoryFiles, getMemoryFile, backupMemory, exportMemoryZip, getMemoryPresignedPost, createMemoryBackupRecord, importMemoryZip, } from './src/admin/methods/memory.js';
20
- import { getMem9Config, installMem9, reconnectMem9 } from './src/admin/methods/mem9.js';
21
- import { doctorFix, logs, openclawUpdate, pluginSelfUpdate, restart, stop } from './src/admin/methods/system.js';
22
- export class MessageHandler {
23
- /**
24
- * 示例方法:处理 ping 类型的消息
25
- * @param data - 消息数据
26
- * @returns 处理结果
27
- */
28
- async ping(data) {
29
- return {
30
- message: "pong",
31
- timestamp: Date.now(),
32
- received: data,
33
- };
34
- }
35
- /**
36
- * 获取 agents 配置
37
- */
38
- async agentsGet(data) {
39
- return wrapAdminCall(async () => {
40
- const context = getContext();
41
- return await getAgents(data, context);
42
- });
43
- }
44
- async agentsList(data) {
45
- return wrapAdminCall(async () => {
46
- const context = getContext();
47
- return await listAgents(data, context);
48
- });
49
- }
50
- async agentsCreate(data) {
51
- return wrapAdminCall(async () => {
52
- const context = getContext();
53
- return await createAgent(data, context);
54
- });
55
- }
56
- async agentsDelete(data) {
57
- return wrapAdminCall(async () => {
58
- const context = getContext();
59
- return await deleteAgent(data, context);
60
- });
61
- }
62
- /**
63
- * 更新 agent 配置
64
- */
65
- async agentsUpdate(data) {
66
- return wrapAdminCall(async () => {
67
- const context = getContext();
68
- return await updateAgent(data, context);
69
- });
70
- }
71
- /**
72
- * 获取配置
73
- */
74
- async configGet(data) {
75
- return wrapAdminCall(async () => {
76
- const context = getContext();
77
- return await getConfig(data, context);
78
- });
79
- }
80
- async cronList(data) {
81
- return wrapAdminCall(async () => {
82
- const context = getContext();
83
- return await listCron(data, context);
84
- });
85
- }
86
- async cronStatus(data) {
87
- return wrapAdminCall(async () => {
88
- const context = getContext();
89
- return await getCronStatus(data, context);
90
- });
91
- }
92
- async cronRuns(data) {
93
- return wrapAdminCall(async () => {
94
- const context = getContext();
95
- return await listCronRuns(data, context);
96
- });
97
- }
98
- async cronAdd(data) {
99
- return wrapAdminCall(async () => {
100
- const context = getContext();
101
- return await addCron(data, context);
102
- });
103
- }
104
- async cronRename(data) {
105
- return wrapAdminCall(async () => {
106
- const context = getContext();
107
- return await renameCron(data, context);
108
- });
109
- }
110
- async cronReschedule(data) {
111
- return wrapAdminCall(async () => {
112
- const context = getContext();
113
- return await rescheduleCron(data, context);
114
- });
115
- }
116
- async cronSetContent(data) {
117
- return wrapAdminCall(async () => {
118
- const context = getContext();
119
- return await setCronContent(data, context);
120
- });
121
- }
122
- async cronUpdateMessage(data) {
123
- return wrapAdminCall(async () => {
124
- const context = getContext();
125
- return await updateCronMessage(data, context);
126
- });
127
- }
128
- async cronUpdateSystemEvent(data) {
129
- return wrapAdminCall(async () => {
130
- const context = getContext();
131
- return await updateCronSystemEvent(data, context);
132
- });
133
- }
134
- async cronEnable(data) {
135
- return wrapAdminCall(async () => {
136
- const context = getContext();
137
- return await enableCron(data, context);
138
- });
139
- }
140
- async cronDisable(data) {
141
- return wrapAdminCall(async () => {
142
- const context = getContext();
143
- return await disableCron(data, context);
144
- });
145
- }
146
- async cronRun(data) {
147
- return wrapAdminCall(async () => {
148
- const context = getContext();
149
- return await runCron(data, context);
150
- });
151
- }
152
- async cronRemove(data) {
153
- return wrapAdminCall(async () => {
154
- const context = getContext();
155
- return await removeCron(data, context);
156
- });
157
- }
158
- /**
159
- * 列出 sessions
160
- */
161
- async sessionsList(data) {
162
- return wrapAdminCall(async () => {
163
- const context = getContext();
164
- return await listSessions(data, context);
165
- });
166
- }
167
- /**
168
- * 获取单个 session 详情和消息记录
169
- */
170
- async sessionsGet(data) {
171
- return wrapAdminCall(async () => {
172
- const context = getContext();
173
- return await getSession(data, context);
174
- });
175
- }
176
- /**
177
- * 准备向 session 发送的消息
178
- * 注意:这只是准备消息数据,实际发送需要通过 MQTT sender 消息
179
- */
180
- async sessionsPrepareMessage(data) {
181
- return wrapAdminCall(async () => {
182
- const context = getContext();
183
- return await prepareMessage(data, context);
184
- });
185
- }
186
- /**
187
- * 附加 skill 到消息
188
- */
189
- async sessionsAttachSkill(data) {
190
- return wrapAdminCall(async () => {
191
- const context = getContext();
192
- return await attachSkill(data, context);
193
- });
194
- }
195
- /**
196
- * 获取 models 配置
197
- */
198
- async modelsGet(data) {
199
- return wrapAdminCall(async () => {
200
- const context = getContext();
201
- return await getModels(data, context);
202
- });
203
- }
204
- /**
205
- * 更新 models 配置
206
- */
207
- async modelsUpdate(data) {
208
- return wrapAdminCall(async () => {
209
- const context = getContext();
210
- return await updateModels(data, context);
211
- });
212
- }
213
- async modelsSet(data) {
214
- return wrapAdminCall(async () => {
215
- const context = getContext();
216
- return await setModel(data, context);
217
- });
218
- }
219
- /**
220
- * 获取 usage summary
221
- */
222
- async usageSummary(data) {
223
- return wrapAdminCall(async () => {
224
- const context = getContext();
225
- return await getUsageSummary(data, context);
226
- });
227
- }
228
- /**
229
- * 获取 usage page summary
230
- */
231
- async usagePageSummary(data) {
232
- return wrapAdminCall(async () => {
233
- const context = getContext();
234
- return await getUsagePageSummary(data, context);
235
- });
236
- }
237
- /**
238
- * 获取 usage timeseries
239
- */
240
- async usageTimeseries(data) {
241
- return wrapAdminCall(async () => {
242
- const context = getContext();
243
- return await getUsageTimeseries(data, context);
244
- });
245
- }
246
- /**
247
- * 获取 usage breakdown
248
- */
249
- async usageBreakdown(data) {
250
- return wrapAdminCall(async () => {
251
- const context = getContext();
252
- return await getUsageBreakdown(data, context);
253
- });
254
- }
255
- /**
256
- * 列出已安装的 skills
257
- */
258
- async skillsListInstalled(data) {
259
- return wrapAdminCall(async () => {
260
- const context = getContext();
261
- return await listInstalledSkills(data, context);
262
- });
263
- }
264
- /**
265
- * 从 npm 安装 skill
266
- */
267
- async skillsInstallFromNpm(data) {
268
- return wrapAdminCall(async () => {
269
- const context = getContext();
270
- return await installSkillFromNpm(data, context);
271
- });
272
- }
273
- async skillsSearchClawHub(data) {
274
- return wrapAdminCall(async () => {
275
- const context = getContext();
276
- return await searchClawHubSkills(data, context);
277
- });
278
- }
279
- async skillsInstallFromClawHub(data) {
280
- return wrapAdminCall(async () => {
281
- const context = getContext();
282
- return await installSkillFromClawHub(data, context);
283
- });
284
- }
285
- async skillsUpdateFromClawHub(data) {
286
- return wrapAdminCall(async () => {
287
- const context = getContext();
288
- return await updateSkillFromClawHub(data, context);
289
- });
290
- }
291
- /**
292
- * 获取已安装 skill 详情
293
- */
294
- async skillsGetInstalled(data) {
295
- return wrapAdminCall(async () => {
296
- const context = getContext();
297
- const slug = typeof data?.slug === 'string' ? data.slug : null;
298
- if (!slug) {
299
- throw new Error('Missing required parameter: slug');
300
- }
301
- const result = await listInstalledSkills({}, context);
302
- const items = Array.isArray(result?.items) ? result.items : [];
303
- const skill = items.find((item) => item && typeof item === 'object' && item.slug === slug);
304
- if (!skill) {
305
- throw new Error(`Skill not installed: ${slug}`);
306
- }
307
- return skill;
308
- });
309
- }
310
- /**
311
- * 卸载 skill
312
- */
313
- async skillsUninstall(data) {
314
- return wrapAdminCall(async () => {
315
- const context = getContext();
316
- return await uninstallSkill(data, context);
317
- });
318
- }
319
- /**
320
- * 启用或停用 skill
321
- */
322
- async skillsToggle(data) {
323
- return wrapAdminCall(async () => {
324
- const context = getContext();
325
- return await toggleSkill(data, context);
326
- });
327
- }
328
- /**
329
- * 列出 memory 文件
330
- */
331
- async memoryListFiles(data) {
332
- return wrapAdminCall(async () => {
333
- const context = getContext();
334
- return await listMemoryFiles(data, context);
335
- });
336
- }
337
- /**
338
- * 获取 memory 文件内容
339
- */
340
- async memoryGetFile(data) {
341
- return wrapAdminCall(async () => {
342
- const context = getContext();
343
- return await getMemoryFile(data, context);
344
- });
345
- }
346
- /**
347
- * 备份 memory
348
- */
349
- async memoryBackup(data) {
350
- return wrapAdminCall(async () => {
351
- const context = getContext();
352
- return await backupMemory(data, context);
353
- });
354
- }
355
- /**
356
- * 导出 memory zip
357
- */
358
- async memoryExportZip(data) {
359
- return wrapAdminCall(async () => {
360
- const context = getContext();
361
- return await exportMemoryZip(data, context);
362
- });
363
- }
364
- async memoryGetPresignedPost(data) {
365
- return wrapAdminCall(async () => {
366
- const context = getContext();
367
- return await getMemoryPresignedPost(data, context);
368
- });
369
- }
370
- async memoryCreateBackupRecord(data) {
371
- return wrapAdminCall(async () => {
372
- const context = getContext();
373
- return await createMemoryBackupRecord(data, context);
374
- });
375
- }
376
- /**
377
- * 导入 memory zip
378
- */
379
- async memoryImportZip(data) {
380
- return wrapAdminCall(async () => {
381
- const context = getContext();
382
- return await importMemoryZip(data, context);
383
- });
384
- }
385
- async artifactsList(data) {
386
- return wrapAdminCall(async () => {
387
- const context = getContext();
388
- return await listArtifacts(data, context);
389
- });
390
- }
391
- async artifactsRefresh(data) {
392
- return wrapAdminCall(async () => {
393
- const context = getContext();
394
- return await refreshArtifacts(data, context);
395
- });
396
- }
397
- async artifactsGetContent(data) {
398
- return wrapAdminCall(async () => {
399
- const context = getContext();
400
- return await getArtifactContent(data, context);
401
- });
402
- }
403
- async artifactsEnsureUploaded(data) {
404
- return wrapAdminCall(async () => {
405
- const context = getContext();
406
- return await ensureArtifactUploaded(data, context);
407
- });
408
- }
409
- async artifactsGetPresignedPost(data) {
410
- return wrapAdminCall(async () => {
411
- const context = getContext();
412
- return await getArtifactPresignedPost(data, context);
413
- });
414
- }
415
- async artifactsCreateRecord(data) {
416
- return wrapAdminCall(async () => {
417
- const context = getContext();
418
- return await createArtifactRecord(data, context);
419
- });
420
- }
421
- async artifactsMarkUploaded(data) {
422
- return wrapAdminCall(async () => {
423
- const context = getContext();
424
- return await markArtifactUploaded(data, context);
425
- });
426
- }
427
- async mem9Install(_data) {
428
- return wrapAdminCall(async () => {
429
- const context = getContext();
430
- return await installMem9(context);
431
- });
432
- }
433
- async mem9GetConfig(_data) {
434
- return wrapAdminCall(async () => {
435
- const context = getContext();
436
- return await getMem9Config(context);
437
- });
438
- }
439
- async mem9Reconnect(data) {
440
- return wrapAdminCall(async () => {
441
- const context = getContext();
442
- const key = typeof data?.key === 'string' ? data.key : '';
443
- return await reconnectMem9(key, context);
444
- });
445
- }
446
- /**
447
- * 重启 OpenClaw Gateway
448
- */
449
- async systemRestart(data) {
450
- return wrapAdminCall(async () => {
451
- const context = getContext();
452
- return await restart(data, context);
453
- });
454
- }
455
- /**
456
- * 停止 OpenClaw Gateway
457
- */
458
- async systemStop(data) {
459
- return wrapAdminCall(async () => {
460
- const context = getContext();
461
- return await stop(data, context);
462
- });
463
- }
464
- /**
465
- * 运行诊断并自动修复
466
- */
467
- async systemDoctorFix(data) {
468
- return wrapAdminCall(async () => {
469
- const context = getContext();
470
- return await doctorFix(data, context);
471
- });
472
- }
473
- /**
474
- * 获取最近100条日志
475
- */
476
- async systemLogs(data) {
477
- return wrapAdminCall(async () => {
478
- const context = getContext();
479
- return await logs(data, context);
480
- });
481
- }
482
- async openclawUpdate(data) {
483
- return wrapAdminCall(async () => {
484
- const context = getContext();
485
- return await openclawUpdate(data, context);
486
- });
487
- }
488
- async pluginSelfUpdate(data) {
489
- return wrapAdminCall(async () => {
490
- const context = getContext();
491
- return await pluginSelfUpdate(data, context);
492
- });
493
- }
494
- /**
495
- * 示例方法:处理 status 类型的消息
496
- */
497
- async status(data) {
498
- return {
499
- status: "running",
500
- uptime: process.uptime(),
501
- memory: process.memoryUsage(),
502
- };
503
- }
504
- /**
505
- * 示例方法:处理 echo 类型的消息
506
- */
507
- async echo(data) {
508
- return {
509
- echoed: true,
510
- data: data,
511
- };
512
- }
513
- }
514
- // 导出单例实例
515
- export const messageHandler = new MessageHandler();
1
+ /**
2
+ * 消息处理器类
3
+ * 根据消息类型调用对应的 admin 方法
4
+ */
5
+ import { getContext } from './src/shared/context.js';
6
+ import { wrapAdminCall } from './src/shared/wrapper.js';
7
+ import { getAgents, getConfig } from './src/admin/methods/admin.js';
8
+ import { createAgent, deleteAgent, listAgents, updateAgent } from './src/admin/methods/agents-extended.js';
9
+ import { createArtifactRecord, ensureArtifactUploaded, getArtifactContent, getArtifactPresignedPost, listArtifacts, markArtifactUploaded, refreshArtifacts } from './src/admin/methods/artifacts.js';
10
+ import { addCron, disableCron, enableCron, getCronStatus, listCron, listCronRuns, renameCron, removeCron, rescheduleCron, runCron, setCronContent, updateCronMessage, updateCronSystemEvent } from './src/admin/methods/cron.js';
11
+ import { listSessions } from './src/admin/methods/sessions.js';
12
+ import { getSession, prepareMessage, attachSkill } from './src/admin/methods/sessions-extended.js';
13
+ import { getModels } from './src/admin/methods/models.js';
14
+ import { setModel, updateModels } from './src/admin/methods/models-extended.js';
15
+ import { getUsagePageSummary, getUsageTimeseries, getUsageBreakdown, getUsageSummary, } from './src/admin/methods/usage.js';
16
+ import { listInstalledSkills, installSkillFromNpm, searchClawHubSkills, installSkillFromClawHub, updateSkillFromClawHub } from './src/admin/methods/skills.js';
17
+ import { uninstallSkill } from './src/admin/methods/skills-extended.js';
18
+ import { toggleSkill } from './src/admin/methods/skills-toggle.js';
19
+ import { listMemoryFiles, getMemoryFile, backupMemory, exportMemoryZip, getMemoryPresignedPost, createMemoryBackupRecord, importMemoryZip, } from './src/admin/methods/memory.js';
20
+ import { getMem9Config, installMem9, reconnectMem9 } from './src/admin/methods/mem9.js';
21
+ import { doctorFix, logs, openclawUpdate, pluginSelfUpdate, restart, stop } from './src/admin/methods/system.js';
22
+ export class MessageHandler {
23
+ /**
24
+ * 示例方法:处理 ping 类型的消息
25
+ * @param data - 消息数据
26
+ * @returns 处理结果
27
+ */
28
+ async ping(data) {
29
+ return {
30
+ message: "pong",
31
+ timestamp: Date.now(),
32
+ received: data,
33
+ };
34
+ }
35
+ /**
36
+ * 获取 agents 配置
37
+ */
38
+ async agentsGet(data) {
39
+ return wrapAdminCall(async () => {
40
+ const context = getContext();
41
+ return await getAgents(data, context);
42
+ });
43
+ }
44
+ async agentsList(data) {
45
+ return wrapAdminCall(async () => {
46
+ const context = getContext();
47
+ return await listAgents(data, context);
48
+ });
49
+ }
50
+ async agentsCreate(data) {
51
+ return wrapAdminCall(async () => {
52
+ const context = getContext();
53
+ return await createAgent(data, context);
54
+ });
55
+ }
56
+ async agentsDelete(data) {
57
+ return wrapAdminCall(async () => {
58
+ const context = getContext();
59
+ return await deleteAgent(data, context);
60
+ });
61
+ }
62
+ /**
63
+ * 更新 agent 配置
64
+ */
65
+ async agentsUpdate(data) {
66
+ return wrapAdminCall(async () => {
67
+ const context = getContext();
68
+ return await updateAgent(data, context);
69
+ });
70
+ }
71
+ /**
72
+ * 获取配置
73
+ */
74
+ async configGet(data) {
75
+ return wrapAdminCall(async () => {
76
+ const context = getContext();
77
+ return await getConfig(data, context);
78
+ });
79
+ }
80
+ async cronList(data) {
81
+ return wrapAdminCall(async () => {
82
+ const context = getContext();
83
+ return await listCron(data, context);
84
+ });
85
+ }
86
+ async cronStatus(data) {
87
+ return wrapAdminCall(async () => {
88
+ const context = getContext();
89
+ return await getCronStatus(data, context);
90
+ });
91
+ }
92
+ async cronRuns(data) {
93
+ return wrapAdminCall(async () => {
94
+ const context = getContext();
95
+ return await listCronRuns(data, context);
96
+ });
97
+ }
98
+ async cronAdd(data) {
99
+ return wrapAdminCall(async () => {
100
+ const context = getContext();
101
+ return await addCron(data, context);
102
+ });
103
+ }
104
+ async cronRename(data) {
105
+ return wrapAdminCall(async () => {
106
+ const context = getContext();
107
+ return await renameCron(data, context);
108
+ });
109
+ }
110
+ async cronReschedule(data) {
111
+ return wrapAdminCall(async () => {
112
+ const context = getContext();
113
+ return await rescheduleCron(data, context);
114
+ });
115
+ }
116
+ async cronSetContent(data) {
117
+ return wrapAdminCall(async () => {
118
+ const context = getContext();
119
+ return await setCronContent(data, context);
120
+ });
121
+ }
122
+ async cronUpdateMessage(data) {
123
+ return wrapAdminCall(async () => {
124
+ const context = getContext();
125
+ return await updateCronMessage(data, context);
126
+ });
127
+ }
128
+ async cronUpdateSystemEvent(data) {
129
+ return wrapAdminCall(async () => {
130
+ const context = getContext();
131
+ return await updateCronSystemEvent(data, context);
132
+ });
133
+ }
134
+ async cronEnable(data) {
135
+ return wrapAdminCall(async () => {
136
+ const context = getContext();
137
+ return await enableCron(data, context);
138
+ });
139
+ }
140
+ async cronDisable(data) {
141
+ return wrapAdminCall(async () => {
142
+ const context = getContext();
143
+ return await disableCron(data, context);
144
+ });
145
+ }
146
+ async cronRun(data) {
147
+ return wrapAdminCall(async () => {
148
+ const context = getContext();
149
+ return await runCron(data, context);
150
+ });
151
+ }
152
+ async cronRemove(data) {
153
+ return wrapAdminCall(async () => {
154
+ const context = getContext();
155
+ return await removeCron(data, context);
156
+ });
157
+ }
158
+ /**
159
+ * 列出 sessions
160
+ */
161
+ async sessionsList(data) {
162
+ return wrapAdminCall(async () => {
163
+ const context = getContext();
164
+ return await listSessions(data, context);
165
+ });
166
+ }
167
+ /**
168
+ * 获取单个 session 详情和消息记录
169
+ */
170
+ async sessionsGet(data) {
171
+ return wrapAdminCall(async () => {
172
+ const context = getContext();
173
+ return await getSession(data, context);
174
+ });
175
+ }
176
+ /**
177
+ * 准备向 session 发送的消息
178
+ * 注意:这只是准备消息数据,实际发送需要通过 MQTT sender 消息
179
+ */
180
+ async sessionsPrepareMessage(data) {
181
+ return wrapAdminCall(async () => {
182
+ const context = getContext();
183
+ return await prepareMessage(data, context);
184
+ });
185
+ }
186
+ /**
187
+ * 附加 skill 到消息
188
+ */
189
+ async sessionsAttachSkill(data) {
190
+ return wrapAdminCall(async () => {
191
+ const context = getContext();
192
+ return await attachSkill(data, context);
193
+ });
194
+ }
195
+ /**
196
+ * 获取 models 配置
197
+ */
198
+ async modelsGet(data) {
199
+ return wrapAdminCall(async () => {
200
+ const context = getContext();
201
+ return await getModels(data, context);
202
+ });
203
+ }
204
+ /**
205
+ * 更新 models 配置
206
+ */
207
+ async modelsUpdate(data) {
208
+ return wrapAdminCall(async () => {
209
+ const context = getContext();
210
+ return await updateModels(data, context);
211
+ });
212
+ }
213
+ async modelsSet(data) {
214
+ return wrapAdminCall(async () => {
215
+ const context = getContext();
216
+ return await setModel(data, context);
217
+ });
218
+ }
219
+ /**
220
+ * 获取 usage summary
221
+ */
222
+ async usageSummary(data) {
223
+ return wrapAdminCall(async () => {
224
+ const context = getContext();
225
+ return await getUsageSummary(data, context);
226
+ });
227
+ }
228
+ /**
229
+ * 获取 usage page summary
230
+ */
231
+ async usagePageSummary(data) {
232
+ return wrapAdminCall(async () => {
233
+ const context = getContext();
234
+ return await getUsagePageSummary(data, context);
235
+ });
236
+ }
237
+ /**
238
+ * 获取 usage timeseries
239
+ */
240
+ async usageTimeseries(data) {
241
+ return wrapAdminCall(async () => {
242
+ const context = getContext();
243
+ return await getUsageTimeseries(data, context);
244
+ });
245
+ }
246
+ /**
247
+ * 获取 usage breakdown
248
+ */
249
+ async usageBreakdown(data) {
250
+ return wrapAdminCall(async () => {
251
+ const context = getContext();
252
+ return await getUsageBreakdown(data, context);
253
+ });
254
+ }
255
+ /**
256
+ * 列出已安装的 skills
257
+ */
258
+ async skillsListInstalled(data) {
259
+ return wrapAdminCall(async () => {
260
+ const context = getContext();
261
+ return await listInstalledSkills(data, context);
262
+ });
263
+ }
264
+ /**
265
+ * 从 npm 安装 skill
266
+ */
267
+ async skillsInstallFromNpm(data) {
268
+ return wrapAdminCall(async () => {
269
+ const context = getContext();
270
+ return await installSkillFromNpm(data, context);
271
+ });
272
+ }
273
+ async skillsSearchClawHub(data) {
274
+ return wrapAdminCall(async () => {
275
+ const context = getContext();
276
+ return await searchClawHubSkills(data, context);
277
+ });
278
+ }
279
+ async skillsInstallFromClawHub(data) {
280
+ return wrapAdminCall(async () => {
281
+ const context = getContext();
282
+ return await installSkillFromClawHub(data, context);
283
+ });
284
+ }
285
+ async skillsUpdateFromClawHub(data) {
286
+ return wrapAdminCall(async () => {
287
+ const context = getContext();
288
+ return await updateSkillFromClawHub(data, context);
289
+ });
290
+ }
291
+ /**
292
+ * 获取已安装 skill 详情
293
+ */
294
+ async skillsGetInstalled(data) {
295
+ return wrapAdminCall(async () => {
296
+ const context = getContext();
297
+ const slug = typeof data?.slug === 'string' ? data.slug : null;
298
+ if (!slug) {
299
+ throw new Error('Missing required parameter: slug');
300
+ }
301
+ const result = await listInstalledSkills({}, context);
302
+ const items = Array.isArray(result?.items) ? result.items : [];
303
+ const skill = items.find((item) => item && typeof item === 'object' && item.slug === slug);
304
+ if (!skill) {
305
+ throw new Error(`Skill not installed: ${slug}`);
306
+ }
307
+ return skill;
308
+ });
309
+ }
310
+ /**
311
+ * 卸载 skill
312
+ */
313
+ async skillsUninstall(data) {
314
+ return wrapAdminCall(async () => {
315
+ const context = getContext();
316
+ return await uninstallSkill(data, context);
317
+ });
318
+ }
319
+ /**
320
+ * 启用或停用 skill
321
+ */
322
+ async skillsToggle(data) {
323
+ return wrapAdminCall(async () => {
324
+ const context = getContext();
325
+ return await toggleSkill(data, context);
326
+ });
327
+ }
328
+ /**
329
+ * 列出 memory 文件
330
+ */
331
+ async memoryListFiles(data) {
332
+ return wrapAdminCall(async () => {
333
+ const context = getContext();
334
+ return await listMemoryFiles(data, context);
335
+ });
336
+ }
337
+ /**
338
+ * 获取 memory 文件内容
339
+ */
340
+ async memoryGetFile(data) {
341
+ return wrapAdminCall(async () => {
342
+ const context = getContext();
343
+ return await getMemoryFile(data, context);
344
+ });
345
+ }
346
+ /**
347
+ * 备份 memory
348
+ */
349
+ async memoryBackup(data) {
350
+ return wrapAdminCall(async () => {
351
+ const context = getContext();
352
+ return await backupMemory(data, context);
353
+ });
354
+ }
355
+ /**
356
+ * 导出 memory zip
357
+ */
358
+ async memoryExportZip(data) {
359
+ return wrapAdminCall(async () => {
360
+ const context = getContext();
361
+ return await exportMemoryZip(data, context);
362
+ });
363
+ }
364
+ async memoryGetPresignedPost(data) {
365
+ return wrapAdminCall(async () => {
366
+ const context = getContext();
367
+ return await getMemoryPresignedPost(data, context);
368
+ });
369
+ }
370
+ async memoryCreateBackupRecord(data) {
371
+ return wrapAdminCall(async () => {
372
+ const context = getContext();
373
+ return await createMemoryBackupRecord(data, context);
374
+ });
375
+ }
376
+ /**
377
+ * 导入 memory zip
378
+ */
379
+ async memoryImportZip(data) {
380
+ return wrapAdminCall(async () => {
381
+ const context = getContext();
382
+ return await importMemoryZip(data, context);
383
+ });
384
+ }
385
+ async artifactsList(data) {
386
+ return wrapAdminCall(async () => {
387
+ const context = getContext();
388
+ return await listArtifacts(data, context);
389
+ });
390
+ }
391
+ async artifactsRefresh(data) {
392
+ return wrapAdminCall(async () => {
393
+ const context = getContext();
394
+ return await refreshArtifacts(data, context);
395
+ });
396
+ }
397
+ async artifactsGetContent(data) {
398
+ return wrapAdminCall(async () => {
399
+ const context = getContext();
400
+ return await getArtifactContent(data, context);
401
+ });
402
+ }
403
+ async artifactsEnsureUploaded(data) {
404
+ return wrapAdminCall(async () => {
405
+ const context = getContext();
406
+ return await ensureArtifactUploaded(data, context);
407
+ });
408
+ }
409
+ async artifactsGetPresignedPost(data) {
410
+ return wrapAdminCall(async () => {
411
+ const context = getContext();
412
+ return await getArtifactPresignedPost(data, context);
413
+ });
414
+ }
415
+ async artifactsCreateRecord(data) {
416
+ return wrapAdminCall(async () => {
417
+ const context = getContext();
418
+ return await createArtifactRecord(data, context);
419
+ });
420
+ }
421
+ async artifactsMarkUploaded(data) {
422
+ return wrapAdminCall(async () => {
423
+ const context = getContext();
424
+ return await markArtifactUploaded(data, context);
425
+ });
426
+ }
427
+ async mem9Install(_data) {
428
+ return wrapAdminCall(async () => {
429
+ const context = getContext();
430
+ return await installMem9(context);
431
+ });
432
+ }
433
+ async mem9GetConfig(_data) {
434
+ return wrapAdminCall(async () => {
435
+ const context = getContext();
436
+ return await getMem9Config(context);
437
+ });
438
+ }
439
+ async mem9Reconnect(data) {
440
+ return wrapAdminCall(async () => {
441
+ const context = getContext();
442
+ const key = typeof data?.key === 'string' ? data.key : '';
443
+ return await reconnectMem9(key, context);
444
+ });
445
+ }
446
+ /**
447
+ * 重启 OpenClaw Gateway
448
+ */
449
+ async systemRestart(data) {
450
+ return wrapAdminCall(async () => {
451
+ const context = getContext();
452
+ return await restart(data, context);
453
+ });
454
+ }
455
+ /**
456
+ * 停止 OpenClaw Gateway
457
+ */
458
+ async systemStop(data) {
459
+ return wrapAdminCall(async () => {
460
+ const context = getContext();
461
+ return await stop(data, context);
462
+ });
463
+ }
464
+ /**
465
+ * 运行诊断并自动修复
466
+ */
467
+ async systemDoctorFix(data) {
468
+ return wrapAdminCall(async () => {
469
+ const context = getContext();
470
+ return await doctorFix(data, context);
471
+ });
472
+ }
473
+ /**
474
+ * 获取最近100条日志
475
+ */
476
+ async systemLogs(data) {
477
+ return wrapAdminCall(async () => {
478
+ const context = getContext();
479
+ return await logs(data, context);
480
+ });
481
+ }
482
+ async openclawUpdate(data) {
483
+ return wrapAdminCall(async () => {
484
+ const context = getContext();
485
+ return await openclawUpdate(data, context);
486
+ });
487
+ }
488
+ async pluginSelfUpdate(data) {
489
+ return wrapAdminCall(async () => {
490
+ const context = getContext();
491
+ return await pluginSelfUpdate(data, context);
492
+ });
493
+ }
494
+ /**
495
+ * 示例方法:处理 status 类型的消息
496
+ */
497
+ async status(data) {
498
+ return {
499
+ status: "running",
500
+ uptime: process.uptime(),
501
+ memory: process.memoryUsage(),
502
+ };
503
+ }
504
+ /**
505
+ * 示例方法:处理 echo 类型的消息
506
+ */
507
+ async echo(data) {
508
+ return {
509
+ echoed: true,
510
+ data: data,
511
+ };
512
+ }
513
+ }
514
+ // 导出单例实例
515
+ export const messageHandler = new MessageHandler();