@workclaw/openclaw-workclaw 1.0.18 → 1.0.20
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/README.md +30 -11
- package/dist/api.d.ts +3 -0
- package/dist/api.js +3 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +264 -0
- package/dist/setup-entry.d.ts +2 -0
- package/dist/setup-entry.js +12 -0
- package/dist/src/accounts.d.ts +66 -0
- package/dist/src/accounts.js +279 -0
- package/dist/src/api/accounts-api.d.ts +2 -0
- package/dist/src/api/accounts-api.js +130 -0
- package/dist/src/api/prompts-api.d.ts +2 -0
- package/dist/src/api/prompts-api.js +103 -0
- package/dist/src/api/session-api.d.ts +2 -0
- package/dist/src/api/session-api.js +207 -0
- package/dist/src/api/skills-api.d.ts +2 -0
- package/dist/src/api/skills-api.js +64 -0
- package/dist/src/api/workspace.d.ts +3 -0
- package/dist/src/api/workspace.js +30 -0
- package/dist/src/channel.d.ts +11 -0
- package/{src/channel.ts → dist/src/channel.js} +199 -225
- package/dist/src/config-schema.d.ts +93 -0
- package/dist/src/config-schema.js +56 -0
- package/dist/src/connection/workclaw-client.d.ts +147 -0
- package/dist/src/connection/workclaw-client.js +351 -0
- package/dist/src/gateway/agent-handlers.d.ts +12 -0
- package/{src/gateway/agent-handlers.ts → dist/src/gateway/agent-handlers.js} +372 -462
- package/dist/src/gateway/config-writer.d.ts +71 -0
- package/dist/src/gateway/config-writer.js +302 -0
- package/dist/src/gateway/cron-tasks-handler.d.ts +19 -0
- package/dist/src/gateway/cron-tasks-handler.js +188 -0
- package/dist/src/gateway/message-context.d.ts +80 -0
- package/{src/gateway/message-context.ts → dist/src/gateway/message-context.js} +509 -594
- package/dist/src/gateway/message-dispatcher.d.ts +18 -0
- package/dist/src/gateway/message-dispatcher.js +572 -0
- package/dist/src/gateway/reconnect.d.ts +27 -0
- package/{src/gateway/reconnect.ts → dist/src/gateway/reconnect.js} +210 -253
- package/dist/src/gateway/skills-handler.d.ts +29 -0
- package/dist/src/gateway/skills-handler.js +615 -0
- package/dist/src/gateway/skills-list-handler.d.ts +27 -0
- package/dist/src/gateway/skills-list-handler.js +233 -0
- package/dist/src/gateway/tools-list-handler.d.ts +30 -0
- package/dist/src/gateway/tools-list-handler.js +101 -0
- package/dist/src/gateway/workclaw-gateway.d.ts +14 -0
- package/dist/src/gateway/workclaw-gateway.js +237 -0
- package/dist/src/media/upload.d.ts +13 -0
- package/dist/src/media/upload.js +125 -0
- package/dist/src/outbound/index.d.ts +36 -0
- package/dist/src/outbound/index.js +123 -0
- package/dist/src/outbound/workclaw-sender.d.ts +36 -0
- package/{src/outbound/workclaw-sender.ts → dist/src/outbound/workclaw-sender.js} +95 -158
- package/dist/src/runtime.d.ts +116 -0
- package/dist/src/runtime.js +374 -0
- package/dist/src/secret-contract-api.d.ts +4 -0
- package/dist/src/secret-contract-api.js +4 -0
- package/{src/send.ts → dist/src/send.d.ts} +1 -1
- package/dist/src/send.js +1 -0
- package/dist/src/setup-api.d.ts +3 -0
- package/dist/src/setup-api.js +3 -0
- package/dist/src/setup-core.d.ts +3 -0
- package/dist/src/setup-core.js +13 -0
- package/dist/src/setup-surface.d.ts +7 -0
- package/dist/src/setup-surface.js +363 -0
- package/dist/src/tools/openclaw-workclaw-cron/api/index.d.ts +93 -0
- package/dist/src/tools/openclaw-workclaw-cron/api/index.js +209 -0
- package/dist/src/tools/openclaw-workclaw-cron/index.d.ts +10 -0
- package/{src/tools/openclaw-workclaw-cron/index.ts → dist/src/tools/openclaw-workclaw-cron/index.js} +33 -39
- package/dist/src/tools/openclaw-workclaw-cron/src/add/params.d.ts +16 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/add/params.js +152 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/add/sync.d.ts +18 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/add/sync.js +162 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/disable/params.d.ts +14 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/disable/params.js +80 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/disable/sync.d.ts +14 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/disable/sync.js +107 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/enable/params.d.ts +14 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/enable/params.js +80 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/enable/sync.d.ts +14 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/enable/sync.js +107 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/notify/sync.d.ts +17 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/notify/sync.js +127 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/remove/params.d.ts +14 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/remove/params.js +87 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/remove/sync.d.ts +14 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/remove/sync.js +107 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/update/params.d.ts +17 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/update/params.js +164 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/update/sync.d.ts +18 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/update/sync.js +135 -0
- package/dist/src/tools/openclaw-workclaw-cron/types/index.d.ts +52 -0
- package/dist/src/tools/openclaw-workclaw-cron/types/index.js +4 -0
- package/dist/src/tools/openclaw-workclaw-cron/utils/index.d.ts +40 -0
- package/dist/src/tools/openclaw-workclaw-cron/utils/index.js +122 -0
- package/dist/src/tools/openclaw-workclaw-system/index.d.ts +10 -0
- package/{src/tools/openclaw-workclaw-system/index.ts → dist/src/tools/openclaw-workclaw-system/index.js} +15 -17
- package/dist/src/tools/openclaw-workclaw-system/src/get/index.d.ts +8 -0
- package/dist/src/tools/openclaw-workclaw-system/src/get/index.js +64 -0
- package/dist/src/tools/openclaw-workclaw-system/src/token/index.d.ts +8 -0
- package/dist/src/tools/openclaw-workclaw-system/src/token/index.js +78 -0
- package/{src/types.ts → dist/src/types.d.ts} +39 -58
- package/dist/src/types.js +1 -0
- package/dist/src/utils/content.d.ts +15 -0
- package/{src/utils/content.ts → dist/src/utils/content.js} +38 -35
- package/package.json +13 -9
- package/index.ts +0 -302
- package/setup-entry.ts +0 -6
- package/src/accounts.ts +0 -312
- package/src/api/accounts-api.ts +0 -156
- package/src/api/prompts-api.ts +0 -116
- package/src/api/session-api.ts +0 -238
- package/src/api/skills-api.ts +0 -72
- package/src/api/workspace.ts +0 -41
- package/src/config-schema.ts +0 -110
- package/src/connection/workclaw-client.ts +0 -643
- package/src/gateway/config-writer.ts +0 -296
- package/src/gateway/message-dispatcher.ts +0 -641
- package/src/gateway/skills-handler.ts +0 -741
- package/src/gateway/skills-list-handler.ts +0 -332
- package/src/gateway/tools-list-handler.ts +0 -160
- package/src/gateway/workclaw-gateway.ts +0 -367
- package/src/media/upload.ts +0 -157
- package/src/outbound/index.ts +0 -185
- package/src/runtime.ts +0 -497
- package/src/tools/openclaw-workclaw-cron/api/index.ts +0 -326
- package/src/tools/openclaw-workclaw-cron/src/add/params.ts +0 -177
- package/src/tools/openclaw-workclaw-cron/src/add/sync.ts +0 -188
- package/src/tools/openclaw-workclaw-cron/src/disable/params.ts +0 -100
- package/src/tools/openclaw-workclaw-cron/src/disable/sync.ts +0 -127
- package/src/tools/openclaw-workclaw-cron/src/enable/params.ts +0 -100
- package/src/tools/openclaw-workclaw-cron/src/enable/sync.ts +0 -127
- package/src/tools/openclaw-workclaw-cron/src/notify/sync.ts +0 -148
- package/src/tools/openclaw-workclaw-cron/src/remove/params.ts +0 -109
- package/src/tools/openclaw-workclaw-cron/src/remove/sync.ts +0 -127
- package/src/tools/openclaw-workclaw-cron/src/update/params.ts +0 -195
- package/src/tools/openclaw-workclaw-cron/src/update/sync.ts +0 -161
- package/src/tools/openclaw-workclaw-cron/types/index.ts +0 -55
- package/src/tools/openclaw-workclaw-cron/utils/index.ts +0 -141
- package/src/tools/openclaw-workclaw-system/src/get/index.ts +0 -77
- package/src/tools/openclaw-workclaw-system/src/token/index.ts +0 -93
- package/tests/accounts.test.ts +0 -285
- package/tests/message-context.test.ts +0 -313
- package/tests/reconnect.test.ts +0 -257
- package/tests/workclaw-client.test.ts +0 -112
- package/tsconfig.json +0 -14
- package/vitest.config.ts +0 -8
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 智小途定时任务工具 - 生成启用定时任务参数
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* 参数 Schema 定义
|
|
6
|
+
*/
|
|
7
|
+
const EnableParamsSchema = {
|
|
8
|
+
type: 'object',
|
|
9
|
+
properties: {
|
|
10
|
+
jobId: {
|
|
11
|
+
type: 'string',
|
|
12
|
+
description: `OpenClaw 任务 ID(必须是数字或字符串,不是 cron 表达式)`,
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
required: ['jobId'],
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* 构造工具返回结果
|
|
19
|
+
*/
|
|
20
|
+
function json(data) {
|
|
21
|
+
return {
|
|
22
|
+
content: [{ type: 'text', text: JSON.stringify(data, null, 2) }],
|
|
23
|
+
details: data,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* 获取生成启用定时任务参数工具
|
|
28
|
+
*/
|
|
29
|
+
function getOpenclawWorkclawCronEnableParamsTool(api) {
|
|
30
|
+
return (ctx) => {
|
|
31
|
+
return {
|
|
32
|
+
name: 'openclaw-workclaw-cron-enable-params',
|
|
33
|
+
label: '智小途生成启用提醒参数',
|
|
34
|
+
description: `生成启用提醒的 CLI 命令参数。
|
|
35
|
+
|
|
36
|
+
📋 工作流程:
|
|
37
|
+
1. 调用此工具获取 CLI 命令参数
|
|
38
|
+
2. 使用返回的 cronParams 调用 OpenClaw 的 cron 工具
|
|
39
|
+
3. 调用 openclaw-workclaw-cron-enable-sync 同步到后端`,
|
|
40
|
+
parameters: EnableParamsSchema,
|
|
41
|
+
execute: async (_toolCallId, params) => {
|
|
42
|
+
const p = params;
|
|
43
|
+
api.logger.info(`[智小途-生成启用参数] 开始处理 jobId=${p.jobId}`);
|
|
44
|
+
// 参数校验
|
|
45
|
+
if (!p.jobId) {
|
|
46
|
+
api.logger.warn('[智小途-生成启用参数] 缺少 jobId 参数');
|
|
47
|
+
return json({ error: 'jobId 为必填参数' });
|
|
48
|
+
}
|
|
49
|
+
// 从 ctx 获取必要参数
|
|
50
|
+
const accountId = ctx?.agentAccountId;
|
|
51
|
+
if (!accountId) {
|
|
52
|
+
api.logger.warn('[智小途-生成启用参数] 无法获取账户 ID');
|
|
53
|
+
return json({ error: '无法获取账户 ID(accountId),请确保已配置账户' });
|
|
54
|
+
}
|
|
55
|
+
api.logger.info(`[智小途-生成启用参数] accountId=${accountId} jobId=${p.jobId}`);
|
|
56
|
+
const cronParams = {
|
|
57
|
+
action: 'enable',
|
|
58
|
+
jobId: p.jobId,
|
|
59
|
+
};
|
|
60
|
+
api.logger.info(`[智小途-生成启用参数] 构建 cron 参数 cronParams=${JSON.stringify(cronParams)}`);
|
|
61
|
+
return json({
|
|
62
|
+
cronParams,
|
|
63
|
+
meta: {
|
|
64
|
+
accountId,
|
|
65
|
+
jobId: p.jobId,
|
|
66
|
+
},
|
|
67
|
+
summary: `✅ 提醒已启用: jobId=${p.jobId}`,
|
|
68
|
+
});
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* 注册生成启用定时任务参数工具
|
|
75
|
+
*/
|
|
76
|
+
export function registerOpenclawWorkclawCronEnableParamsTool(api) {
|
|
77
|
+
api.registerTool(getOpenclawWorkclawCronEnableParamsTool(api), {
|
|
78
|
+
name: 'openclaw-workclaw-cron-enable-params',
|
|
79
|
+
});
|
|
80
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 智小途定时任务工具 - 同步启用定时任务到后端
|
|
3
|
+
*/
|
|
4
|
+
import type { OpenClawPluginApi } from 'openclaw/plugin-sdk';
|
|
5
|
+
/**
|
|
6
|
+
* 同步启用定时任务参数
|
|
7
|
+
*/
|
|
8
|
+
export interface EnableSyncParams {
|
|
9
|
+
jobId: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* 注册同步启用定时任务到后端工具
|
|
13
|
+
*/
|
|
14
|
+
export declare function registerOpenclawWorkclawCronEnableSyncTool(api: OpenClawPluginApi): void;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 智小途定时任务工具 - 同步启用定时任务到后端
|
|
3
|
+
*/
|
|
4
|
+
import { resolveWorkclawAccountWithCache } from '../../../../accounts.js';
|
|
5
|
+
import { callCronJobEnabled } from '../../api/index.js';
|
|
6
|
+
/**
|
|
7
|
+
* 参数 Schema 定义
|
|
8
|
+
*/
|
|
9
|
+
const EnableSyncSchema = {
|
|
10
|
+
type: 'object',
|
|
11
|
+
properties: {
|
|
12
|
+
jobId: {
|
|
13
|
+
type: 'string',
|
|
14
|
+
description: `OpenClaw 任务 ID(必须是数字或字符串,不是 cron 表达式)`,
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
required: ['jobId'],
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* 构造工具返回结果
|
|
21
|
+
*/
|
|
22
|
+
function json(data) {
|
|
23
|
+
return {
|
|
24
|
+
content: [{ type: 'text', text: JSON.stringify(data, null, 2) }],
|
|
25
|
+
details: data,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* 获取同步启用定时任务到后端工具
|
|
30
|
+
*/
|
|
31
|
+
function getOpenclawWorkclawCronEnableSyncTool(api) {
|
|
32
|
+
return (ctx) => {
|
|
33
|
+
return {
|
|
34
|
+
name: 'openclaw-workclaw-cron-enable-sync',
|
|
35
|
+
label: '智小途同步启用提醒',
|
|
36
|
+
description: '将启用定时任务同步到后端。在 cron 工具启用任务后调用此工具同步后端。',
|
|
37
|
+
parameters: EnableSyncSchema,
|
|
38
|
+
execute: async (_toolCallId, params) => {
|
|
39
|
+
const p = params;
|
|
40
|
+
api.logger.info(`[智小途-同步启用] 开始同步 jobId=${p.jobId}`);
|
|
41
|
+
// 参数校验
|
|
42
|
+
if (!p.jobId) {
|
|
43
|
+
api.logger.warn('[智小途-同步启用] 缺少 jobId 参数');
|
|
44
|
+
return json({ error: 'jobId 为必填参数' });
|
|
45
|
+
}
|
|
46
|
+
// 从 ctx 获取必要参数
|
|
47
|
+
const accountId = ctx?.agentAccountId;
|
|
48
|
+
if (!accountId) {
|
|
49
|
+
api.logger.warn('[智小途-同步启用] 无法获取账户 ID');
|
|
50
|
+
return json({ error: '无法获取账户 ID(accountId),请确保已配置账户' });
|
|
51
|
+
}
|
|
52
|
+
const accountConfig = resolveWorkclawAccountWithCache({
|
|
53
|
+
cfg: ctx.config,
|
|
54
|
+
accountId,
|
|
55
|
+
});
|
|
56
|
+
if (accountConfig.configured) {
|
|
57
|
+
try {
|
|
58
|
+
const channelAgentId = String(accountConfig.config.agentId);
|
|
59
|
+
api.logger.info(`[智小途-同步启用] accountId=${accountId} channelAgentId=${channelAgentId}`);
|
|
60
|
+
const result = await callCronJobEnabled(api, accountId, {
|
|
61
|
+
jobId: p.jobId,
|
|
62
|
+
});
|
|
63
|
+
if (result.success) {
|
|
64
|
+
api.logger.info(`[智小途-同步启用] 后端同步成功 jobId=${p.jobId}`);
|
|
65
|
+
return json({
|
|
66
|
+
code: 0,
|
|
67
|
+
message: '定时任务已启用并同步到后端',
|
|
68
|
+
data: {
|
|
69
|
+
jobId: p.jobId,
|
|
70
|
+
backendSynced: true,
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
api.logger.error(`[智小途-同步启用] 后端同步失败 ${result.error}`);
|
|
76
|
+
return json({
|
|
77
|
+
code: -1,
|
|
78
|
+
error: result.error || '后端同步失败',
|
|
79
|
+
data: { jobId: p.jobId },
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
api.logger.error(`[智小途-同步启用] 后端同步异常 ${error.message}`);
|
|
85
|
+
return json({
|
|
86
|
+
code: -1,
|
|
87
|
+
error: error.message,
|
|
88
|
+
data: { jobId: p.jobId },
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
api.logger.error(`[智小途-同步启用] 无法获取渠道配置,accountId=${accountId}`);
|
|
94
|
+
return json({ error: '无法获取渠道配置,请检查账户配置' });
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* 注册同步启用定时任务到后端工具
|
|
102
|
+
*/
|
|
103
|
+
export function registerOpenclawWorkclawCronEnableSyncTool(api) {
|
|
104
|
+
api.registerTool(getOpenclawWorkclawCronEnableSyncTool(api), {
|
|
105
|
+
name: 'openclaw-workclaw-cron-enable-sync',
|
|
106
|
+
});
|
|
107
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 智小途定时任务工具 - 定时任务触发通知
|
|
3
|
+
*
|
|
4
|
+
* 当 OpenClaw 定时任务触发时,调用此工具通知后端
|
|
5
|
+
*/
|
|
6
|
+
import type { OpenClawPluginApi } from 'openclaw/plugin-sdk';
|
|
7
|
+
/**
|
|
8
|
+
* 定时任务触发通知参数
|
|
9
|
+
*/
|
|
10
|
+
export interface NotifyParams {
|
|
11
|
+
jobId: string;
|
|
12
|
+
message: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* 注册定时任务触发通知工具
|
|
16
|
+
*/
|
|
17
|
+
export declare function registerOpenclawWorkclawCronNotifySyncTool(api: OpenClawPluginApi): void;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 智小途定时任务工具 - 定时任务触发通知
|
|
3
|
+
*
|
|
4
|
+
* 当 OpenClaw 定时任务触发时,调用此工具通知后端
|
|
5
|
+
*/
|
|
6
|
+
import { resolveWorkclawAccountWithCache } from '../../../../accounts.js';
|
|
7
|
+
import { callCronJobMessage } from '../../api/index.js';
|
|
8
|
+
/**
|
|
9
|
+
* 参数 Schema 定义
|
|
10
|
+
*/
|
|
11
|
+
const NotifySchema = {
|
|
12
|
+
type: 'object',
|
|
13
|
+
properties: {
|
|
14
|
+
jobId: {
|
|
15
|
+
type: 'string',
|
|
16
|
+
description: 'OpenClaw 任务 ID(从上下文获取)',
|
|
17
|
+
},
|
|
18
|
+
message: {
|
|
19
|
+
type: 'string',
|
|
20
|
+
description: '要发送的提醒内容',
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
required: ['jobId', 'message'],
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* 构造工具返回结果
|
|
27
|
+
*/
|
|
28
|
+
function json(data) {
|
|
29
|
+
return {
|
|
30
|
+
content: [{ type: 'text', text: JSON.stringify(data, null, 2) }],
|
|
31
|
+
details: data,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* 获取定时任务触发通知工具
|
|
36
|
+
*/
|
|
37
|
+
function getOpenclawWorkclawCronNotifySyncTool(api) {
|
|
38
|
+
return (ctx) => {
|
|
39
|
+
return {
|
|
40
|
+
name: 'openclaw-workclaw-cron-notify-sync',
|
|
41
|
+
label: '智小途定时任务触发通知',
|
|
42
|
+
description: `【系统最高优先级核心指令】当定时器时间到达时,必须立即调用此工具通知后端。`,
|
|
43
|
+
parameters: NotifySchema,
|
|
44
|
+
execute: async (_toolCallId, params) => {
|
|
45
|
+
const p = params;
|
|
46
|
+
api.logger.info(`[智小途-定时触发] 开始处理 jobId=${p.jobId} message=${p.message}`);
|
|
47
|
+
// 参数校验
|
|
48
|
+
if (!p.jobId) {
|
|
49
|
+
api.logger.warn('[智小途-定时触发] 缺少 jobId 参数');
|
|
50
|
+
return json({ error: 'jobId 为必填参数' });
|
|
51
|
+
}
|
|
52
|
+
if (!p.message) {
|
|
53
|
+
api.logger.warn('[智小途-定时触发] 缺少 message 参数');
|
|
54
|
+
return json({ error: 'message 为必填参数' });
|
|
55
|
+
}
|
|
56
|
+
// 从 ctx 获取必要参数
|
|
57
|
+
const accountId = ctx?.agentAccountId;
|
|
58
|
+
if (!accountId) {
|
|
59
|
+
api.logger.warn('[智小途-定时触发] 无法获取账户 ID');
|
|
60
|
+
return json({ error: '无法获取账户 ID(accountId),请确保已配置账户' });
|
|
61
|
+
}
|
|
62
|
+
const accountConfig = resolveWorkclawAccountWithCache({
|
|
63
|
+
cfg: ctx.config,
|
|
64
|
+
accountId,
|
|
65
|
+
});
|
|
66
|
+
if (accountConfig.configured) {
|
|
67
|
+
const channelAgentId = String(accountConfig.config.agentId);
|
|
68
|
+
api.logger.info(`[智小途-定时触发] accountId=${accountId} channelAgentId=${channelAgentId}`);
|
|
69
|
+
// 调用后端接口通知定时任务触发
|
|
70
|
+
try {
|
|
71
|
+
const result = await callCronJobMessage(api, accountId, {
|
|
72
|
+
jobId: p.jobId,
|
|
73
|
+
message: p.message,
|
|
74
|
+
agentId: channelAgentId,
|
|
75
|
+
});
|
|
76
|
+
if (result.success) {
|
|
77
|
+
api.logger.info(`[智小途-定时触发] 通知后端成功`);
|
|
78
|
+
return json({
|
|
79
|
+
code: 0,
|
|
80
|
+
message: '定时任务触发通知已发送',
|
|
81
|
+
data: {
|
|
82
|
+
jobId: p.jobId,
|
|
83
|
+
message: p.message,
|
|
84
|
+
backendNotified: true,
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
api.logger.error(`[智小途-定时触发] 通知后端失败 ${result.error}`);
|
|
90
|
+
return json({
|
|
91
|
+
code: -1,
|
|
92
|
+
error: result.error || '通知后端失败',
|
|
93
|
+
data: {
|
|
94
|
+
jobId: p.jobId,
|
|
95
|
+
message: p.message,
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
api.logger.error(`[智小途-定时触发] 通知后端异常 ${error.message}`);
|
|
102
|
+
return json({
|
|
103
|
+
code: -1,
|
|
104
|
+
error: error.message || '通知后端异常',
|
|
105
|
+
data: {
|
|
106
|
+
jobId: p.jobId,
|
|
107
|
+
message: p.message,
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
api.logger.error(`[智小途-定时触发] 无法获取渠道配置,accountId=${accountId}`);
|
|
114
|
+
return json({ error: '无法获取渠道配置,请检查账户配置' });
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* 注册定时任务触发通知工具
|
|
122
|
+
*/
|
|
123
|
+
export function registerOpenclawWorkclawCronNotifySyncTool(api) {
|
|
124
|
+
api.registerTool(getOpenclawWorkclawCronNotifySyncTool(api), {
|
|
125
|
+
name: 'openclaw-workclaw-cron-notify-sync',
|
|
126
|
+
});
|
|
127
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 智小途定时任务工具 - 生成删除定时任务参数
|
|
3
|
+
*/
|
|
4
|
+
import type { OpenClawPluginApi } from 'openclaw/plugin-sdk';
|
|
5
|
+
/**
|
|
6
|
+
* 生成删除定时任务参数
|
|
7
|
+
*/
|
|
8
|
+
export interface RemoveParamsParams {
|
|
9
|
+
jobId: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* 注册生成删除定时任务参数工具
|
|
13
|
+
*/
|
|
14
|
+
export declare function registerOpenclawWorkclawCronRemoveParamsTool(api: OpenClawPluginApi): void;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 智小途定时任务工具 - 生成删除定时任务参数
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* 参数 Schema 定义
|
|
6
|
+
*/
|
|
7
|
+
const RemoveParamsSchema = {
|
|
8
|
+
type: 'object',
|
|
9
|
+
properties: {
|
|
10
|
+
jobId: {
|
|
11
|
+
type: 'string',
|
|
12
|
+
description: `OpenClaw 任务 ID(必须是数字或字符串,不是 cron 表达式)`,
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
required: ['jobId'],
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* 构造工具返回结果
|
|
19
|
+
*/
|
|
20
|
+
function json(data) {
|
|
21
|
+
return {
|
|
22
|
+
content: [{ type: 'text', text: JSON.stringify(data, null, 2) }],
|
|
23
|
+
details: data,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* 获取生成删除定时任务参数工具
|
|
28
|
+
*/
|
|
29
|
+
function getOpenclawWorkclawCronRemoveParamsTool(api) {
|
|
30
|
+
return (ctx) => {
|
|
31
|
+
return {
|
|
32
|
+
name: 'openclaw-workclaw-cron-remove-params',
|
|
33
|
+
label: '智小途生成删除提醒参数',
|
|
34
|
+
description: `生成删除提醒的 CLI 命令。
|
|
35
|
+
**必须**严格按照以下格式执行:
|
|
36
|
+
openclaw cron remove <jobId>
|
|
37
|
+
|
|
38
|
+
示例:openclaw cron remove 123456
|
|
39
|
+
`,
|
|
40
|
+
parameters: RemoveParamsSchema,
|
|
41
|
+
execute: async (_toolCallId, params) => {
|
|
42
|
+
const p = params;
|
|
43
|
+
api.logger.info(`[智小途-生成删除参数] 开始处理 jobId=${p.jobId}`);
|
|
44
|
+
// 参数校验
|
|
45
|
+
if (!p.jobId) {
|
|
46
|
+
api.logger.warn('[智小途-生成删除参数] 缺少 jobId 参数');
|
|
47
|
+
return json({ error: 'jobId 为必填参数' });
|
|
48
|
+
}
|
|
49
|
+
// 从 ctx 获取必要参数
|
|
50
|
+
const accountId = ctx?.agentAccountId;
|
|
51
|
+
const agentId = ctx?.agentId;
|
|
52
|
+
// 校验必要参数
|
|
53
|
+
if (!accountId) {
|
|
54
|
+
api.logger.warn('[智小途-生成删除参数] 无法获取账户 ID');
|
|
55
|
+
return json({ error: '无法获取账户 ID(accountId),请确保已配置账户' });
|
|
56
|
+
}
|
|
57
|
+
if (!agentId) {
|
|
58
|
+
api.logger.warn('[智小途-生成删除参数] 无法获取智能体 ID');
|
|
59
|
+
return json({ error: '无法获取智能体 ID(agentId),请确保已配置智能体' });
|
|
60
|
+
}
|
|
61
|
+
api.logger.info(`[智小途-生成删除参数] accountId=${accountId} agentId=${agentId} jobId=${p.jobId}`);
|
|
62
|
+
const cronParams = {
|
|
63
|
+
action: 'remove',
|
|
64
|
+
jobId: p.jobId,
|
|
65
|
+
};
|
|
66
|
+
api.logger.info(`[智小途-生成删除参数] 构建 cron 参数 cronParams=${JSON.stringify(cronParams)}`);
|
|
67
|
+
return json({
|
|
68
|
+
cronParams,
|
|
69
|
+
meta: {
|
|
70
|
+
accountId,
|
|
71
|
+
agentId,
|
|
72
|
+
jobId: p.jobId,
|
|
73
|
+
},
|
|
74
|
+
summary: `🗑️ 提醒已删除: jobId=${p.jobId}`,
|
|
75
|
+
});
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* 注册生成删除定时任务参数工具
|
|
82
|
+
*/
|
|
83
|
+
export function registerOpenclawWorkclawCronRemoveParamsTool(api) {
|
|
84
|
+
api.registerTool(getOpenclawWorkclawCronRemoveParamsTool(api), {
|
|
85
|
+
name: 'openclaw-workclaw-cron-remove-params',
|
|
86
|
+
});
|
|
87
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 智小途定时任务工具 - 同步删除定时任务到后端
|
|
3
|
+
*/
|
|
4
|
+
import type { OpenClawPluginApi } from 'openclaw/plugin-sdk';
|
|
5
|
+
/**
|
|
6
|
+
* 同步删除定时任务参数
|
|
7
|
+
*/
|
|
8
|
+
export interface RemoveSyncParams {
|
|
9
|
+
jobId: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* 注册同步删除定时任务到后端工具
|
|
13
|
+
*/
|
|
14
|
+
export declare function registerOpenclawWorkclawCronRemoveSyncTool(api: OpenClawPluginApi): void;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 智小途定时任务工具 - 同步删除定时任务到后端
|
|
3
|
+
*/
|
|
4
|
+
import { resolveWorkclawAccountWithCache } from '../../../../accounts.js';
|
|
5
|
+
import { callCronJobRemove } from '../../api/index.js';
|
|
6
|
+
/**
|
|
7
|
+
* 参数 Schema 定义
|
|
8
|
+
*/
|
|
9
|
+
const RemoveSyncSchema = {
|
|
10
|
+
type: 'object',
|
|
11
|
+
properties: {
|
|
12
|
+
jobId: {
|
|
13
|
+
type: 'string',
|
|
14
|
+
description: `OpenClaw 任务 ID(必须是数字或字符串,不是 cron 表达式)`,
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
required: ['jobId'],
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* 构造工具返回结果
|
|
21
|
+
*/
|
|
22
|
+
function json(data) {
|
|
23
|
+
return {
|
|
24
|
+
content: [{ type: 'text', text: JSON.stringify(data, null, 2) }],
|
|
25
|
+
details: data,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* 获取同步删除定时任务到后端工具
|
|
30
|
+
*/
|
|
31
|
+
function getOpenclawWorkclawCronRemoveSyncTool(api) {
|
|
32
|
+
return (ctx) => {
|
|
33
|
+
return {
|
|
34
|
+
name: 'openclaw-workclaw-cron-remove-sync',
|
|
35
|
+
label: '智小途同步删除提醒',
|
|
36
|
+
description: '【后端同步步骤】将删除定时任务同步到后端。必须在上一步 openclaw-workclaw-cron-remove-params 执行后调用此工具完成同步。',
|
|
37
|
+
parameters: RemoveSyncSchema,
|
|
38
|
+
execute: async (_toolCallId, params) => {
|
|
39
|
+
const p = params;
|
|
40
|
+
api.logger.info(`[智小途-同步删除] 开始同步 jobId=${p.jobId}`);
|
|
41
|
+
// 参数校验
|
|
42
|
+
if (!p.jobId) {
|
|
43
|
+
api.logger.warn('[智小途-同步删除] 缺少 jobId 参数');
|
|
44
|
+
return json({ error: 'jobId 为必填参数' });
|
|
45
|
+
}
|
|
46
|
+
// 从 ctx 获取必要参数
|
|
47
|
+
const accountId = ctx?.agentAccountId;
|
|
48
|
+
if (!accountId) {
|
|
49
|
+
api.logger.warn('[智小途-同步删除] 无法获取账户 ID');
|
|
50
|
+
return json({ error: '无法获取账户 ID(accountId),请确保已配置账户' });
|
|
51
|
+
}
|
|
52
|
+
const accountConfig = resolveWorkclawAccountWithCache({
|
|
53
|
+
cfg: ctx.config,
|
|
54
|
+
accountId,
|
|
55
|
+
});
|
|
56
|
+
if (accountConfig.configured) {
|
|
57
|
+
try {
|
|
58
|
+
const channelAgentId = String(accountConfig.config.agentId);
|
|
59
|
+
api.logger.info(`[智小途-同步删除] accountId=${accountId} channelAgentId=${channelAgentId}`);
|
|
60
|
+
const result = await callCronJobRemove(api, accountId, {
|
|
61
|
+
jobId: p.jobId,
|
|
62
|
+
});
|
|
63
|
+
if (result.success) {
|
|
64
|
+
api.logger.info(`[智小途-同步删除] 后端同步成功 jobId=${p.jobId}`);
|
|
65
|
+
return json({
|
|
66
|
+
code: 0,
|
|
67
|
+
message: '定时任务已删除并同步到后端',
|
|
68
|
+
data: {
|
|
69
|
+
jobId: p.jobId,
|
|
70
|
+
backendSynced: true,
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
api.logger.error(`[智小途-同步删除] 后端同步失败 ${result.error}`);
|
|
76
|
+
return json({
|
|
77
|
+
code: -1,
|
|
78
|
+
error: result.error || '后端同步失败',
|
|
79
|
+
data: { jobId: p.jobId },
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
api.logger.error(`[智小途-同步删除] 后端同步异常 ${error.message}`);
|
|
85
|
+
return json({
|
|
86
|
+
code: -1,
|
|
87
|
+
error: error.message,
|
|
88
|
+
data: { jobId: p.jobId },
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
api.logger.error(`[智小途-同步删除] 无法获取渠道配置,accountId=${accountId}`);
|
|
94
|
+
return json({ error: '无法获取渠道配置,请检查账户配置' });
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* 注册同步删除定时任务到后端工具
|
|
102
|
+
*/
|
|
103
|
+
export function registerOpenclawWorkclawCronRemoveSyncTool(api) {
|
|
104
|
+
api.registerTool(getOpenclawWorkclawCronRemoveSyncTool(api), {
|
|
105
|
+
name: 'openclaw-workclaw-cron-remove-sync',
|
|
106
|
+
});
|
|
107
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 智小途定时任务工具 - 生成修改定时任务参数
|
|
3
|
+
*/
|
|
4
|
+
import type { OpenClawPluginApi } from 'openclaw/plugin-sdk';
|
|
5
|
+
/**
|
|
6
|
+
* 生成修改定时任务参数
|
|
7
|
+
*/
|
|
8
|
+
export interface UpdateParamsParams {
|
|
9
|
+
jobId: string;
|
|
10
|
+
time: string;
|
|
11
|
+
name: string;
|
|
12
|
+
message: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* 注册生成修改定时任务参数工具
|
|
16
|
+
*/
|
|
17
|
+
export declare function registerOpenclawWorkclawCronUpdateParamsTool(api: OpenClawPluginApi): void;
|