@workclaw/openclaw-workclaw 1.0.17 → 1.0.19
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 +364 -325
- package/dist/api.d.ts +3 -0
- package/dist/api.js +3 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +263 -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 +28 -0
- package/dist/src/channel.d.ts +11 -0
- package/dist/src/channel.js +198 -0
- 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/dist/src/gateway/agent-handlers.js +433 -0
- package/dist/src/gateway/config-writer.d.ts +71 -0
- package/dist/src/gateway/config-writer.js +312 -0
- package/dist/src/gateway/message-context.d.ts +76 -0
- package/dist/src/gateway/message-context.js +499 -0
- package/dist/src/gateway/message-dispatcher.d.ts +19 -0
- package/dist/src/gateway/message-dispatcher.js +512 -0
- package/dist/src/gateway/reconnect.d.ts +27 -0
- package/dist/src/gateway/reconnect.js +206 -0
- package/dist/src/gateway/skills-handler.d.ts +29 -0
- package/dist/src/gateway/skills-handler.js +576 -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 +223 -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/dist/src/outbound/workclaw-sender.js +95 -0
- 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/dist/src/send.d.ts +1 -0
- 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/dist/src/types.d.ts +39 -0
- package/dist/src/types.js +1 -0
- package/dist/src/utils/content.d.ts +15 -0
- package/dist/src/utils/content.js +38 -0
- package/openclaw.plugin.json +1 -0
- package/package.json +62 -42
- package/skills/openclaw-workclaw-cron/SKILL.md +45 -28
- package/index.ts +0 -302
- package/src/accounts.ts +0 -287
- package/src/api/accounts-api.ts +0 -157
- package/src/api/prompts-api.ts +0 -123
- package/src/api/session-api.ts +0 -247
- package/src/api/skills-api.ts +0 -74
- package/src/api/workspace.ts +0 -43
- package/src/channel.ts +0 -227
- package/src/config-schema.ts +0 -110
- package/src/connection/workclaw-client.ts +0 -656
- package/src/gateway/agent-handlers.ts +0 -557
- package/src/gateway/config-writer.ts +0 -311
- package/src/gateway/message-context.ts +0 -422
- package/src/gateway/message-dispatcher.ts +0 -601
- package/src/gateway/reconnect.ts +0 -149
- package/src/gateway/skills-handler.ts +0 -805
- package/src/gateway/skills-list-handler.ts +0 -332
- package/src/gateway/tools-list-handler.ts +0 -162
- package/src/gateway/workclaw-gateway.ts +0 -525
- package/src/media/upload.ts +0 -168
- package/src/outbound/index.ts +0 -183
- package/src/outbound/workclaw-sender.ts +0 -157
- package/src/runtime.ts +0 -400
- package/src/send.ts +0 -1
- package/src/tools/openclaw-workclaw-cron/api/index.ts +0 -326
- package/src/tools/openclaw-workclaw-cron/src/add/params.ts +0 -176
- 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 -197
- 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/src/types.ts +0 -60
- package/src/utils/content.ts +0 -40
- package/tsconfig.json +0 -11
package/{src/tools/openclaw-workclaw-cron/index.ts → dist/src/tools/openclaw-workclaw-cron/index.js}
RENAMED
|
@@ -1,39 +1,33 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 智小途定时任务工具 - 统一出口
|
|
3
|
-
*
|
|
4
|
-
* 提供统一的工具注册入口,一次性注册所有定时任务相关工具
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
registerOpenclawWorkclawCronUpdateSyncTool(api)
|
|
35
|
-
registerOpenclawWorkclawCronEnableSyncTool(api)
|
|
36
|
-
registerOpenclawWorkclawCronDisableSyncTool(api)
|
|
37
|
-
|
|
38
|
-
registerOpenclawWorkclawCronNotifySyncTool(api)
|
|
39
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* 智小途定时任务工具 - 统一出口
|
|
3
|
+
*
|
|
4
|
+
* 提供统一的工具注册入口,一次性注册所有定时任务相关工具
|
|
5
|
+
*/
|
|
6
|
+
import { registerOpenclawWorkclawCronAddParamsTool } from './src/add/params.js';
|
|
7
|
+
import { registerOpenclawWorkclawCronAddSyncTool } from './src/add/sync.js';
|
|
8
|
+
import { registerOpenclawWorkclawCronDisableParamsTool } from './src/disable/params.js';
|
|
9
|
+
import { registerOpenclawWorkclawCronDisableSyncTool } from './src/disable/sync.js';
|
|
10
|
+
import { registerOpenclawWorkclawCronEnableParamsTool } from './src/enable/params.js';
|
|
11
|
+
import { registerOpenclawWorkclawCronEnableSyncTool } from './src/enable/sync.js';
|
|
12
|
+
import { registerOpenclawWorkclawCronNotifySyncTool } from './src/notify/sync.js';
|
|
13
|
+
import { registerOpenclawWorkclawCronRemoveParamsTool } from './src/remove/params.js';
|
|
14
|
+
import { registerOpenclawWorkclawCronRemoveSyncTool } from './src/remove/sync.js';
|
|
15
|
+
import { registerOpenclawWorkclawCronUpdateParamsTool } from './src/update/params.js';
|
|
16
|
+
import { registerOpenclawWorkclawCronUpdateSyncTool } from './src/update/sync.js';
|
|
17
|
+
/**
|
|
18
|
+
* 统一注册所有定时任务工具
|
|
19
|
+
* @param api - OpenClaw API 实例
|
|
20
|
+
*/
|
|
21
|
+
export function registerAllOpenclawWorkclawCronTools(api) {
|
|
22
|
+
registerOpenclawWorkclawCronAddParamsTool(api);
|
|
23
|
+
registerOpenclawWorkclawCronRemoveParamsTool(api);
|
|
24
|
+
registerOpenclawWorkclawCronUpdateParamsTool(api);
|
|
25
|
+
registerOpenclawWorkclawCronEnableParamsTool(api);
|
|
26
|
+
registerOpenclawWorkclawCronDisableParamsTool(api);
|
|
27
|
+
registerOpenclawWorkclawCronAddSyncTool(api);
|
|
28
|
+
registerOpenclawWorkclawCronRemoveSyncTool(api);
|
|
29
|
+
registerOpenclawWorkclawCronUpdateSyncTool(api);
|
|
30
|
+
registerOpenclawWorkclawCronEnableSyncTool(api);
|
|
31
|
+
registerOpenclawWorkclawCronDisableSyncTool(api);
|
|
32
|
+
registerOpenclawWorkclawCronNotifySyncTool(api);
|
|
33
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 智小途定时任务工具 - 生成创建定时任务参数
|
|
3
|
+
*/
|
|
4
|
+
import type { OpenClawPluginApi } from 'openclaw/plugin-sdk';
|
|
5
|
+
/**
|
|
6
|
+
* 生成创建定时任务参数
|
|
7
|
+
*/
|
|
8
|
+
export interface AddParamsParams {
|
|
9
|
+
time: string;
|
|
10
|
+
name: string;
|
|
11
|
+
message: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* 注册生成创建定时任务参数工具
|
|
15
|
+
*/
|
|
16
|
+
export declare function registerOpenclawWorkclawCronAddParamsTool(api: OpenClawPluginApi): void;
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 智小途定时任务工具 - 生成创建定时任务参数
|
|
3
|
+
*/
|
|
4
|
+
import { isCronExpression, relativeToCron, validateTimeFormat } from '../../utils/index.js';
|
|
5
|
+
/**
|
|
6
|
+
* 参数 Schema 定义
|
|
7
|
+
*/
|
|
8
|
+
const AddParamsSchema = {
|
|
9
|
+
type: 'object',
|
|
10
|
+
properties: {
|
|
11
|
+
time: {
|
|
12
|
+
type: 'string',
|
|
13
|
+
description: '⏰ 时间(核心!),支持相对时间和 cron 表达式,工具自动转换',
|
|
14
|
+
},
|
|
15
|
+
name: {
|
|
16
|
+
type: 'string',
|
|
17
|
+
description: '任务名称',
|
|
18
|
+
},
|
|
19
|
+
message: {
|
|
20
|
+
type: 'string',
|
|
21
|
+
description: '提醒内容',
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
required: ['time', 'name', 'message'],
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* 构造工具返回结果
|
|
28
|
+
*/
|
|
29
|
+
function json(data) {
|
|
30
|
+
return {
|
|
31
|
+
content: [{ type: 'text', text: JSON.stringify(data, null, 2) }],
|
|
32
|
+
details: data,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* 获取生成创建定时任务参数工具
|
|
37
|
+
*/
|
|
38
|
+
function getOpenclawWorkclawCronAddParamsTool(api) {
|
|
39
|
+
return (ctx) => {
|
|
40
|
+
return {
|
|
41
|
+
name: 'openclaw-workclaw-cron-add-params',
|
|
42
|
+
label: '智小途生成创建提醒参数',
|
|
43
|
+
description: `【核心工具】生成创建提醒的 cronParams 参数。
|
|
44
|
+
|
|
45
|
+
📋 工作流程(必须按顺序执行):
|
|
46
|
+
1. 调用此工具获取 cronParams 参数
|
|
47
|
+
2. 使用返回的 cronParams 调用 OpenClaw 的 cron 工具
|
|
48
|
+
3. 从 cron 工具返回值中提取 jobId(返回格式:{"success": true, "jobId": "xxx"})
|
|
49
|
+
4. 必须调用 openclaw-workclaw-cron-add-sync 同步到后端
|
|
50
|
+
|
|
51
|
+
⏰ 时间格式(核心!):
|
|
52
|
+
- time 参数支持相对时间(如 "5m"、"1h"、"2d")和 cron 表达式
|
|
53
|
+
- 工具会自动将所有时间统一转换为 cron 表达式
|
|
54
|
+
- 严禁使用 --at 参数或其他绝对时间格式
|
|
55
|
+
- 最终 CLI 命令必须使用 --cron 参数
|
|
56
|
+
|
|
57
|
+
🔒 强制规则:
|
|
58
|
+
- schedule.kind 必须是 "cron"
|
|
59
|
+
- 必须使用 --cron 参数传递 cron 表达式
|
|
60
|
+
|
|
61
|
+
⚠️ 必须从 cron 工具返回值中提取 jobId,不能凭空编造!`,
|
|
62
|
+
parameters: AddParamsSchema,
|
|
63
|
+
execute: async (_toolCallId, params) => {
|
|
64
|
+
const p = params;
|
|
65
|
+
api.logger.info(`[智小途-生成参数] 开始生成创建提醒参数 name=${p.name} time=${p.time}`);
|
|
66
|
+
// 参数校验
|
|
67
|
+
if (!p.time) {
|
|
68
|
+
api.logger.warn('[智小途-生成参数] 缺少时间参数');
|
|
69
|
+
return json({ error: 'time(时间)为必填参数' });
|
|
70
|
+
}
|
|
71
|
+
if (!p.name) {
|
|
72
|
+
api.logger.warn('[智小途-生成参数] 缺少任务名称参数');
|
|
73
|
+
return json({ error: 'name(任务名称)为必填参数' });
|
|
74
|
+
}
|
|
75
|
+
if (!p.message) {
|
|
76
|
+
api.logger.warn('[智小途-生成参数] 缺少用户消息参数');
|
|
77
|
+
return json({ error: 'message(用户消息)为必填参数' });
|
|
78
|
+
}
|
|
79
|
+
// 从 ctx 获取必要参数
|
|
80
|
+
const accountId = ctx?.agentAccountId;
|
|
81
|
+
if (!accountId) {
|
|
82
|
+
api.logger.warn('[智小途-生成参数] 无法获取账户 ID');
|
|
83
|
+
return json({ error: '无法获取账户 ID(accountId),请确保已配置账户' });
|
|
84
|
+
}
|
|
85
|
+
api.logger.info(`[智小途-生成参数] accountId=${accountId} name=${p.name}`);
|
|
86
|
+
// 校验时间格式
|
|
87
|
+
const timeValidation = validateTimeFormat(p.time);
|
|
88
|
+
if (!timeValidation.valid) {
|
|
89
|
+
api.logger.warn(`[智小途-生成参数] 时间格式校验失败: ${timeValidation.error}`);
|
|
90
|
+
return json({ error: timeValidation.error });
|
|
91
|
+
}
|
|
92
|
+
// 判断时间类型并转换为 cron 表达式
|
|
93
|
+
const isCron = isCronExpression(p.time);
|
|
94
|
+
let isOneTime = false;
|
|
95
|
+
let cronExpr;
|
|
96
|
+
if (!isCron) {
|
|
97
|
+
// 相对时间转换为 cron 表达式
|
|
98
|
+
isOneTime = true;
|
|
99
|
+
cronExpr = relativeToCron(p.time.trim());
|
|
100
|
+
api.logger.info(`[智小途-生成参数] 相对时间转换为 cron 表达式 cronExpr=${cronExpr}`);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
cronExpr = p.time.trim();
|
|
104
|
+
}
|
|
105
|
+
// 构建 cron 参数
|
|
106
|
+
const cronParams = {
|
|
107
|
+
action: 'add',
|
|
108
|
+
account: accountId,
|
|
109
|
+
job: {
|
|
110
|
+
name: p.name,
|
|
111
|
+
schedule: {
|
|
112
|
+
kind: 'cron',
|
|
113
|
+
expr: cronExpr,
|
|
114
|
+
tz: 'Asia/Shanghai',
|
|
115
|
+
},
|
|
116
|
+
sessionTarget: 'isolated',
|
|
117
|
+
wakeMode: 'now',
|
|
118
|
+
deleteAfterRun: isOneTime ? true : undefined,
|
|
119
|
+
payload: {
|
|
120
|
+
kind: 'agentTurn',
|
|
121
|
+
message: p.message,
|
|
122
|
+
},
|
|
123
|
+
delivery: {
|
|
124
|
+
mode: 'announce',
|
|
125
|
+
channel: 'openclaw-workclaw',
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
api.logger.info(`[智小途-生成参数] 构建 cron 参数 cronParams=${JSON.stringify(cronParams)}`);
|
|
130
|
+
return json({
|
|
131
|
+
cronParams,
|
|
132
|
+
meta: {
|
|
133
|
+
accountId,
|
|
134
|
+
name: p.name,
|
|
135
|
+
kind: 'cron',
|
|
136
|
+
expr: cronExpr,
|
|
137
|
+
message: p.message,
|
|
138
|
+
},
|
|
139
|
+
summary: `⏰ 提醒已生成: "${p.name}" (${p.time})`,
|
|
140
|
+
});
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* 注册生成创建定时任务参数工具
|
|
147
|
+
*/
|
|
148
|
+
export function registerOpenclawWorkclawCronAddParamsTool(api) {
|
|
149
|
+
api.registerTool(getOpenclawWorkclawCronAddParamsTool(api), {
|
|
150
|
+
name: 'openclaw-workclaw-cron-add-params',
|
|
151
|
+
});
|
|
152
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 智小途定时任务工具 - 同步创建定时任务到后端
|
|
3
|
+
*/
|
|
4
|
+
import type { OpenClawPluginApi } from 'openclaw/plugin-sdk';
|
|
5
|
+
/**
|
|
6
|
+
* 同步创建定时任务参数
|
|
7
|
+
*/
|
|
8
|
+
export interface AddSyncParams {
|
|
9
|
+
jobId: string;
|
|
10
|
+
name: string;
|
|
11
|
+
kind: 'cron';
|
|
12
|
+
expr?: string;
|
|
13
|
+
message: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* 注册同步创建定时任务到后端工具
|
|
17
|
+
*/
|
|
18
|
+
export declare function registerOpenclawWorkclawCronAddSyncTool(api: OpenClawPluginApi): void;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 智小途定时任务工具 - 同步创建定时任务到后端
|
|
3
|
+
*/
|
|
4
|
+
import { resolveWorkclawAccountWithCache } from '../../../../accounts.js';
|
|
5
|
+
import { callCronJobAdd } from '../../api/index.js';
|
|
6
|
+
/**
|
|
7
|
+
* 参数 Schema 定义
|
|
8
|
+
*/
|
|
9
|
+
const AddSyncSchema = {
|
|
10
|
+
type: 'object',
|
|
11
|
+
properties: {
|
|
12
|
+
jobId: {
|
|
13
|
+
type: 'string',
|
|
14
|
+
description: `⛔ 重要:jobId 必须从 OpenClaw cron 工具返回值中提取,格式:{"success": true, "jobId": "123456"}
|
|
15
|
+
|
|
16
|
+
常见错误:
|
|
17
|
+
- 把 cron 表达式(如 "31 12 11 31 3 *")当作 jobId
|
|
18
|
+
- 把 name 当作 jobId
|
|
19
|
+
- 编造 jobId
|
|
20
|
+
|
|
21
|
+
正确做法:
|
|
22
|
+
1. 调用 openclaw-workclaw-cron-add-params
|
|
23
|
+
2. 用返回的 cronParams 调用 cron 工具
|
|
24
|
+
3. 从返回值提取 jobId(如 "7382945612345")
|
|
25
|
+
4. 用提取到的 jobId 调用此工具`,
|
|
26
|
+
},
|
|
27
|
+
name: {
|
|
28
|
+
type: 'string',
|
|
29
|
+
description: '任务名称,与 add-params 中传入的 name 一致',
|
|
30
|
+
},
|
|
31
|
+
kind: {
|
|
32
|
+
type: 'string',
|
|
33
|
+
description: '任务类型',
|
|
34
|
+
enum: ['cron'],
|
|
35
|
+
},
|
|
36
|
+
expr: {
|
|
37
|
+
type: 'string',
|
|
38
|
+
description: 'Cron 表达式',
|
|
39
|
+
},
|
|
40
|
+
message: {
|
|
41
|
+
type: 'string',
|
|
42
|
+
description: '提醒消息,与 add-params 中传入的 message 一致',
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
required: ['jobId', 'name', 'kind', 'message'],
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* 构造工具返回结果
|
|
49
|
+
*/
|
|
50
|
+
function json(data) {
|
|
51
|
+
return {
|
|
52
|
+
content: [{ type: 'text', text: JSON.stringify(data, null, 2) }],
|
|
53
|
+
details: data,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* 获取同步创建定时任务到后端工具
|
|
58
|
+
*/
|
|
59
|
+
function getOpenclawWorkclawCronAddSyncTool(api) {
|
|
60
|
+
return (ctx) => {
|
|
61
|
+
return {
|
|
62
|
+
name: 'openclaw-workclaw-cron-add-sync',
|
|
63
|
+
label: '智小途同步创建提醒',
|
|
64
|
+
description: `【后端同步步骤】将创建定时任务同步到后端。必须在上一步 openclaw-workclaw-cron-add-params 执行后调用此工具完成同步。
|
|
65
|
+
|
|
66
|
+
⚠️ jobId 必须是 cron 工具返回值 {"success": true, "jobId": "xxx"} 中的 jobId 字段!`,
|
|
67
|
+
parameters: AddSyncSchema,
|
|
68
|
+
execute: async (_toolCallId, params) => {
|
|
69
|
+
const p = params;
|
|
70
|
+
api.logger.info(`[智小途-同步创建] 开始同步 jobId=${p.jobId} name=${p.name}`);
|
|
71
|
+
// 参数校验
|
|
72
|
+
if (!p.jobId) {
|
|
73
|
+
api.logger.warn('[智小途-同步创建] 缺少 jobId 参数');
|
|
74
|
+
return json({ error: 'jobId 为必填参数' });
|
|
75
|
+
}
|
|
76
|
+
// 检查 jobId 是否被错误地设置为 cron 表达式
|
|
77
|
+
const jobIdTrimmed = p.jobId.trim();
|
|
78
|
+
const parts = jobIdTrimmed.split(/\s+/);
|
|
79
|
+
const isCronExpression = parts.length >= 5 && parts.length <= 6 && jobIdTrimmed.includes('*');
|
|
80
|
+
if (isCronExpression) {
|
|
81
|
+
api.logger.error(`[智小途-同步创建] jobId 格式错误!jobId=${p.jobId},看起来像 cron 表达式`);
|
|
82
|
+
return json({
|
|
83
|
+
error: `jobId="${p.jobId}" 是 cron 表达式,不是任务 ID!jobId 应来自 cron 工具返回值,如 "123456" 或 "abc123"`,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
if (!p.name) {
|
|
87
|
+
api.logger.warn('[智小途-同步创建] 缺少 name 参数');
|
|
88
|
+
return json({ error: 'name 为必填参数' });
|
|
89
|
+
}
|
|
90
|
+
if (!p.message) {
|
|
91
|
+
api.logger.warn('[智小途-同步创建] 缺少 message 参数');
|
|
92
|
+
return json({ error: 'message 为必填参数' });
|
|
93
|
+
}
|
|
94
|
+
// 从 ctx 获取必要参数
|
|
95
|
+
const accountId = ctx?.agentAccountId;
|
|
96
|
+
if (!accountId) {
|
|
97
|
+
api.logger.warn('[智小途-同步创建] 无法获取账户 ID');
|
|
98
|
+
return json({ error: '无法获取账户 ID(accountId),请确保已配置账户' });
|
|
99
|
+
}
|
|
100
|
+
const accountConfig = resolveWorkclawAccountWithCache({
|
|
101
|
+
cfg: ctx.config,
|
|
102
|
+
accountId,
|
|
103
|
+
});
|
|
104
|
+
if (accountConfig.configured) {
|
|
105
|
+
try {
|
|
106
|
+
const channelAgentId = String(accountConfig.config.agentId);
|
|
107
|
+
api.logger.info(`[智小途-同步创建] accountId=${accountId} channelAgentId=${channelAgentId}`);
|
|
108
|
+
const result = await callCronJobAdd(api, accountId, {
|
|
109
|
+
jobId: p.jobId,
|
|
110
|
+
name: p.name,
|
|
111
|
+
kind: p.kind,
|
|
112
|
+
expr: p.expr,
|
|
113
|
+
message: p.message,
|
|
114
|
+
messageId: channelAgentId,
|
|
115
|
+
});
|
|
116
|
+
if (result.success) {
|
|
117
|
+
api.logger.info(`[智小途-同步创建] 后端同步成功 jobId=${p.jobId}`);
|
|
118
|
+
return json({
|
|
119
|
+
code: 0,
|
|
120
|
+
message: '定时任务已创建并同步到后端',
|
|
121
|
+
data: {
|
|
122
|
+
jobId: p.jobId,
|
|
123
|
+
name: p.name,
|
|
124
|
+
message: p.message,
|
|
125
|
+
backendSynced: true,
|
|
126
|
+
},
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
api.logger.error(`[智小途-同步创建] 后端同步失败 ${result.error}`);
|
|
131
|
+
return json({
|
|
132
|
+
code: -1,
|
|
133
|
+
error: result.error || '后端同步失败',
|
|
134
|
+
data: { jobId: p.jobId, name: p.name },
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
api.logger.error(`[智小途-同步创建] 后端同步异常 ${error.message}`);
|
|
140
|
+
return json({
|
|
141
|
+
code: -1,
|
|
142
|
+
error: error.message,
|
|
143
|
+
data: { jobId: p.jobId, name: p.name },
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
api.logger.error(`[智小途-同步创建] 无法获取渠道配置,accountId=${accountId}`);
|
|
149
|
+
return json({ error: '无法获取渠道配置,请检查账户配置' });
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
};
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* 注册同步创建定时任务到后端工具
|
|
157
|
+
*/
|
|
158
|
+
export function registerOpenclawWorkclawCronAddSyncTool(api) {
|
|
159
|
+
api.registerTool(getOpenclawWorkclawCronAddSyncTool(api), {
|
|
160
|
+
name: 'openclaw-workclaw-cron-add-sync',
|
|
161
|
+
});
|
|
162
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 智小途定时任务工具 - 生成禁用定时任务参数
|
|
3
|
+
*/
|
|
4
|
+
import type { OpenClawPluginApi } from 'openclaw/plugin-sdk';
|
|
5
|
+
/**
|
|
6
|
+
* 生成禁用定时任务参数
|
|
7
|
+
*/
|
|
8
|
+
export interface DisableParamsParams {
|
|
9
|
+
jobId: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* 注册生成禁用定时任务参数工具
|
|
13
|
+
*/
|
|
14
|
+
export declare function registerOpenclawWorkclawCronDisableParamsTool(api: OpenClawPluginApi): void;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 智小途定时任务工具 - 生成禁用定时任务参数
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* 参数 Schema 定义
|
|
6
|
+
*/
|
|
7
|
+
const DisableParamsSchema = {
|
|
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 getOpenclawWorkclawCronDisableParamsTool(api) {
|
|
30
|
+
return (ctx) => {
|
|
31
|
+
return {
|
|
32
|
+
name: 'openclaw-workclaw-cron-disable-params',
|
|
33
|
+
label: '智小途生成禁用提醒参数',
|
|
34
|
+
description: `生成禁用提醒的 CLI 命令参数。
|
|
35
|
+
|
|
36
|
+
📋 工作流程:
|
|
37
|
+
1. 调用此工具获取 CLI 命令参数
|
|
38
|
+
2. 使用返回的 cronParams 调用 OpenClaw 的 cron 工具
|
|
39
|
+
3. 调用 openclaw-workclaw-cron-disable-sync 同步到后端`,
|
|
40
|
+
parameters: DisableParamsSchema,
|
|
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: 'disable',
|
|
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 registerOpenclawWorkclawCronDisableParamsTool(api) {
|
|
77
|
+
api.registerTool(getOpenclawWorkclawCronDisableParamsTool(api), {
|
|
78
|
+
name: 'openclaw-workclaw-cron-disable-params',
|
|
79
|
+
});
|
|
80
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 智小途定时任务工具 - 同步禁用定时任务到后端
|
|
3
|
+
*/
|
|
4
|
+
import type { OpenClawPluginApi } from 'openclaw/plugin-sdk';
|
|
5
|
+
/**
|
|
6
|
+
* 同步禁用定时任务参数
|
|
7
|
+
*/
|
|
8
|
+
export interface DisableSyncParams {
|
|
9
|
+
jobId: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* 注册同步禁用定时任务到后端工具
|
|
13
|
+
*/
|
|
14
|
+
export declare function registerOpenclawWorkclawCronDisableSyncTool(api: OpenClawPluginApi): void;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 智小途定时任务工具 - 同步禁用定时任务到后端
|
|
3
|
+
*/
|
|
4
|
+
import { resolveWorkclawAccountWithCache } from '../../../../accounts.js';
|
|
5
|
+
import { callCronJobDisabled } from '../../api/index.js';
|
|
6
|
+
/**
|
|
7
|
+
* 参数 Schema 定义
|
|
8
|
+
*/
|
|
9
|
+
const DisableSyncSchema = {
|
|
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 getOpenclawWorkclawCronDisableSyncTool(api) {
|
|
32
|
+
return (ctx) => {
|
|
33
|
+
return {
|
|
34
|
+
name: 'openclaw-workclaw-cron-disable-sync',
|
|
35
|
+
label: '智小途同步禁用提醒',
|
|
36
|
+
description: '将禁用定时任务同步到后端。在 cron 工具禁用任务后调用此工具同步后端。',
|
|
37
|
+
parameters: DisableSyncSchema,
|
|
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 callCronJobDisabled(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 registerOpenclawWorkclawCronDisableSyncTool(api) {
|
|
104
|
+
api.registerTool(getOpenclawWorkclawCronDisableSyncTool(api), {
|
|
105
|
+
name: 'openclaw-workclaw-cron-disable-sync',
|
|
106
|
+
});
|
|
107
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 智小途定时任务工具 - 生成启用定时任务参数
|
|
3
|
+
*/
|
|
4
|
+
import type { OpenClawPluginApi } from 'openclaw/plugin-sdk';
|
|
5
|
+
/**
|
|
6
|
+
* 生成启用定时任务参数
|
|
7
|
+
*/
|
|
8
|
+
export interface EnableParamsParams {
|
|
9
|
+
jobId: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* 注册生成启用定时任务参数工具
|
|
13
|
+
*/
|
|
14
|
+
export declare function registerOpenclawWorkclawCronEnableParamsTool(api: OpenClawPluginApi): void;
|