@workclaw/openclaw-workclaw 1.0.17 → 1.0.18
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 +21 -1
- package/index.ts +210 -210
- package/openclaw.plugin.json +1 -0
- package/package.json +11 -4
- package/setup-entry.ts +6 -0
- package/skills/openclaw-workclaw-cron/SKILL.md +45 -28
- package/src/accounts.ts +62 -37
- package/src/api/accounts-api.ts +88 -89
- package/src/api/prompts-api.ts +70 -77
- package/src/api/session-api.ts +99 -108
- package/src/api/skills-api.ts +35 -37
- package/src/api/workspace.ts +27 -29
- package/src/channel.ts +200 -202
- package/src/config-schema.ts +9 -9
- package/src/connection/workclaw-client.ts +554 -567
- package/src/gateway/agent-handlers.ts +392 -426
- package/src/gateway/config-writer.ts +228 -243
- package/src/gateway/message-context.ts +534 -362
- package/src/gateway/message-dispatcher.ts +529 -489
- package/src/gateway/reconnect.ts +217 -113
- package/src/gateway/skills-handler.ts +408 -472
- package/src/gateway/skills-list-handler.ts +9 -9
- package/src/gateway/tools-list-handler.ts +70 -72
- package/src/gateway/workclaw-gateway.ts +328 -486
- package/src/media/upload.ts +83 -94
- package/src/outbound/index.ts +57 -55
- package/src/outbound/workclaw-sender.ts +134 -133
- package/src/runtime.ts +291 -194
- package/src/send.ts +1 -1
- package/src/tools/openclaw-workclaw-cron/api/index.ts +6 -6
- package/src/tools/openclaw-workclaw-cron/src/add/params.ts +20 -19
- package/src/tools/openclaw-workclaw-cron/src/add/sync.ts +2 -2
- package/src/tools/openclaw-workclaw-cron/src/disable/params.ts +1 -1
- package/src/tools/openclaw-workclaw-cron/src/disable/sync.ts +3 -3
- package/src/tools/openclaw-workclaw-cron/src/enable/params.ts +1 -1
- package/src/tools/openclaw-workclaw-cron/src/enable/sync.ts +3 -3
- package/src/tools/openclaw-workclaw-cron/src/notify/sync.ts +2 -2
- package/src/tools/openclaw-workclaw-cron/src/remove/params.ts +1 -1
- package/src/tools/openclaw-workclaw-cron/src/remove/sync.ts +3 -3
- package/src/tools/openclaw-workclaw-cron/src/update/params.ts +195 -197
- package/src/tools/openclaw-workclaw-cron/src/update/sync.ts +4 -4
- package/src/tools/openclaw-workclaw-system/src/get/index.ts +2 -2
- package/src/tools/openclaw-workclaw-system/src/token/index.ts +4 -4
- package/src/types.ts +38 -40
- package/src/utils/content.ts +16 -21
- package/tests/accounts.test.ts +285 -0
- package/tests/message-context.test.ts +313 -0
- package/tests/reconnect.test.ts +257 -0
- package/tests/workclaw-client.test.ts +112 -0
- package/tsconfig.json +8 -5
- package/vitest.config.ts +8 -0
package/src/send.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { sendMessageWorkclaw, getMessageWorkclaw } from "./outbound/index.js";
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import type { OpenClawPluginApi } from 'openclaw/plugin-sdk'
|
|
6
|
-
import type {
|
|
7
|
-
import {
|
|
8
|
-
import { doFetchJson,
|
|
6
|
+
import type { WorkclawConnectionConfig } from '../../../connection/workclaw-client.js'
|
|
7
|
+
import { resolveWorkclawAccountWithCache } from '../../../accounts.js'
|
|
8
|
+
import { doFetchJson, getWorkclawAccessToken, normalizeBaseUrl } from '../../../connection/workclaw-client.js'
|
|
9
9
|
|
|
10
10
|
const DEFAULT_MAX_RETRIES = 3
|
|
11
11
|
const DEFAULT_RETRY_DELAY_MS = 1000
|
|
@@ -115,7 +115,7 @@ export async function callBackendApi(
|
|
|
115
115
|
} = {},
|
|
116
116
|
): Promise<{ success: boolean, data?: any, error?: string, attempts?: number }> {
|
|
117
117
|
try {
|
|
118
|
-
const account =
|
|
118
|
+
const account = resolveWorkclawAccountWithCache({
|
|
119
119
|
cfg: api.config,
|
|
120
120
|
accountId,
|
|
121
121
|
})
|
|
@@ -131,13 +131,13 @@ export async function callBackendApi(
|
|
|
131
131
|
|
|
132
132
|
api.logger.info(`[智小途-定时任务] 正在获取认证 token,accountId=${accountId}`)
|
|
133
133
|
|
|
134
|
-
const token = await
|
|
134
|
+
const token = await getWorkclawAccessToken(tokenCacheKey, {
|
|
135
135
|
baseUrl: accConfig.baseUrl,
|
|
136
136
|
appKey: accConfig.appKey,
|
|
137
137
|
appSecret: accConfig.appSecret,
|
|
138
138
|
allowInsecureTls: accConfig.allowInsecureTls,
|
|
139
139
|
requestTimeout: accConfig.requestTimeout,
|
|
140
|
-
} as
|
|
140
|
+
} as WorkclawConnectionConfig)
|
|
141
141
|
|
|
142
142
|
const requestUrl = `${baseUrl}/open-apis${path}`
|
|
143
143
|
const sanitizedPayload = sanitizePayload(payload)
|
|
@@ -22,7 +22,7 @@ const AddParamsSchema = {
|
|
|
22
22
|
properties: {
|
|
23
23
|
time: {
|
|
24
24
|
type: 'string',
|
|
25
|
-
description: '
|
|
25
|
+
description: '⏰ 时间(核心!),支持相对时间和 cron 表达式,工具自动转换',
|
|
26
26
|
},
|
|
27
27
|
name: {
|
|
28
28
|
type: 'string',
|
|
@@ -54,25 +54,25 @@ function getOpenclawWorkclawCronAddParamsTool(api: OpenClawPluginApi) {
|
|
|
54
54
|
return {
|
|
55
55
|
name: 'openclaw-workclaw-cron-add-params',
|
|
56
56
|
label: '智小途生成创建提醒参数',
|
|
57
|
-
description:
|
|
57
|
+
description: `【核心工具】生成创建提醒的 cronParams 参数。
|
|
58
58
|
|
|
59
59
|
📋 工作流程(必须按顺序执行):
|
|
60
|
-
1.
|
|
61
|
-
2.
|
|
62
|
-
3.
|
|
63
|
-
4.
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
-
|
|
67
|
-
-
|
|
68
|
-
-
|
|
69
|
-
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
-
|
|
73
|
-
-
|
|
74
|
-
|
|
75
|
-
|
|
60
|
+
1. 调用此工具获取 cronParams 参数
|
|
61
|
+
2. 使用返回的 cronParams 调用 OpenClaw 的 cron 工具
|
|
62
|
+
3. 从 cron 工具返回值中提取 jobId(返回格式:{"success": true, "jobId": "xxx"})
|
|
63
|
+
4. 必须调用 openclaw-workclaw-cron-add-sync 同步到后端
|
|
64
|
+
|
|
65
|
+
⏰ 时间格式(核心!):
|
|
66
|
+
- time 参数支持相对时间(如 "5m"、"1h"、"2d")和 cron 表达式
|
|
67
|
+
- 工具会自动将所有时间统一转换为 cron 表达式
|
|
68
|
+
- 严禁使用 --at 参数或其他绝对时间格式
|
|
69
|
+
- 最终 CLI 命令必须使用 --cron 参数
|
|
70
|
+
|
|
71
|
+
🔒 强制规则:
|
|
72
|
+
- schedule.kind 必须是 "cron"
|
|
73
|
+
- 必须使用 --cron 参数传递 cron 表达式
|
|
74
|
+
|
|
75
|
+
⚠️ 必须从 cron 工具返回值中提取 jobId,不能凭空编造!`,
|
|
76
76
|
parameters: AddParamsSchema,
|
|
77
77
|
execute: async (_toolCallId: string, params: AddParamsParams) => {
|
|
78
78
|
const p = params as AddParamsParams
|
|
@@ -125,8 +125,9 @@ function getOpenclawWorkclawCronAddParamsTool(api: OpenClawPluginApi) {
|
|
|
125
125
|
}
|
|
126
126
|
|
|
127
127
|
// 构建 cron 参数
|
|
128
|
-
const cronParams = {
|
|
128
|
+
const cronParams: Record<string, any> = {
|
|
129
129
|
action: 'add' as const,
|
|
130
|
+
account: accountId,
|
|
130
131
|
job: {
|
|
131
132
|
name: p.name,
|
|
132
133
|
schedule: {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import type { OpenClawPluginApi } from 'openclaw/plugin-sdk'
|
|
6
|
-
import {
|
|
6
|
+
import { resolveWorkclawAccountWithCache } from '../../../../accounts.js'
|
|
7
7
|
import { callCronJobAdd } from '../../api/index.js'
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -120,7 +120,7 @@ function getOpenclawWorkclawCronAddSyncTool(api: OpenClawPluginApi) {
|
|
|
120
120
|
return json({ error: '无法获取账户 ID(accountId),请确保已配置账户' })
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
const accountConfig =
|
|
123
|
+
const accountConfig = resolveWorkclawAccountWithCache({
|
|
124
124
|
cfg: ctx.config,
|
|
125
125
|
accountId,
|
|
126
126
|
})
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import type { OpenClawPluginApi } from 'openclaw/plugin-sdk'
|
|
6
|
-
import {
|
|
6
|
+
import { resolveWorkclawAccountWithCache } from '../../../../accounts.js'
|
|
7
7
|
import { callCronJobDisabled } from '../../api/index.js'
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -21,7 +21,7 @@ const DisableSyncSchema = {
|
|
|
21
21
|
properties: {
|
|
22
22
|
jobId: {
|
|
23
23
|
type: 'string',
|
|
24
|
-
description:
|
|
24
|
+
description: `OpenClaw 任务 ID(必须是数字或字符串,不是 cron 表达式)`,
|
|
25
25
|
},
|
|
26
26
|
},
|
|
27
27
|
required: ['jobId'],
|
|
@@ -65,7 +65,7 @@ function getOpenclawWorkclawCronDisableSyncTool(api: OpenClawPluginApi) {
|
|
|
65
65
|
return json({ error: '无法获取账户 ID(accountId),请确保已配置账户' })
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
const accountConfig =
|
|
68
|
+
const accountConfig = resolveWorkclawAccountWithCache({
|
|
69
69
|
cfg: ctx.config,
|
|
70
70
|
accountId,
|
|
71
71
|
})
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import type { OpenClawPluginApi } from 'openclaw/plugin-sdk'
|
|
6
|
-
import {
|
|
6
|
+
import { resolveWorkclawAccountWithCache } from '../../../../accounts.js'
|
|
7
7
|
import { callCronJobEnabled } from '../../api/index.js'
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -21,7 +21,7 @@ const EnableSyncSchema = {
|
|
|
21
21
|
properties: {
|
|
22
22
|
jobId: {
|
|
23
23
|
type: 'string',
|
|
24
|
-
description:
|
|
24
|
+
description: `OpenClaw 任务 ID(必须是数字或字符串,不是 cron 表达式)`,
|
|
25
25
|
},
|
|
26
26
|
},
|
|
27
27
|
required: ['jobId'],
|
|
@@ -65,7 +65,7 @@ function getOpenclawWorkclawCronEnableSyncTool(api: OpenClawPluginApi) {
|
|
|
65
65
|
return json({ error: '无法获取账户 ID(accountId),请确保已配置账户' })
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
const accountConfig =
|
|
68
|
+
const accountConfig = resolveWorkclawAccountWithCache({
|
|
69
69
|
cfg: ctx.config,
|
|
70
70
|
accountId,
|
|
71
71
|
})
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import type { OpenClawPluginApi } from 'openclaw/plugin-sdk'
|
|
8
|
-
import {
|
|
8
|
+
import { resolveWorkclawAccountWithCache } from '../../../../accounts.js'
|
|
9
9
|
import { callCronJobMessage } from '../../api/index.js'
|
|
10
10
|
|
|
11
11
|
/**
|
|
@@ -76,7 +76,7 @@ function getOpenclawWorkclawCronNotifySyncTool(api: OpenClawPluginApi) {
|
|
|
76
76
|
return json({ error: '无法获取账户 ID(accountId),请确保已配置账户' })
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
const accountConfig =
|
|
79
|
+
const accountConfig = resolveWorkclawAccountWithCache({
|
|
80
80
|
cfg: ctx.config,
|
|
81
81
|
accountId,
|
|
82
82
|
})
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import type { OpenClawPluginApi } from 'openclaw/plugin-sdk'
|
|
6
|
-
import {
|
|
6
|
+
import { resolveWorkclawAccountWithCache } from '../../../../accounts.js'
|
|
7
7
|
import { callCronJobRemove } from '../../api/index.js'
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -21,7 +21,7 @@ const RemoveSyncSchema = {
|
|
|
21
21
|
properties: {
|
|
22
22
|
jobId: {
|
|
23
23
|
type: 'string',
|
|
24
|
-
description:
|
|
24
|
+
description: `OpenClaw 任务 ID(必须是数字或字符串,不是 cron 表达式)`,
|
|
25
25
|
},
|
|
26
26
|
},
|
|
27
27
|
required: ['jobId'],
|
|
@@ -65,7 +65,7 @@ function getOpenclawWorkclawCronRemoveSyncTool(api: OpenClawPluginApi) {
|
|
|
65
65
|
return json({ error: '无法获取账户 ID(accountId),请确保已配置账户' })
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
const accountConfig =
|
|
68
|
+
const accountConfig = resolveWorkclawAccountWithCache({
|
|
69
69
|
cfg: ctx.config,
|
|
70
70
|
accountId,
|
|
71
71
|
})
|
|
@@ -1,197 +1,195 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 智小途定时任务工具 - 生成修改定时任务参数
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import type { OpenClawPluginApi } from 'openclaw/plugin-sdk'
|
|
6
|
-
import {
|
|
7
|
-
isCronExpression,
|
|
8
|
-
relativeToCron,
|
|
9
|
-
validateTimeFormat,
|
|
10
|
-
} from '../../utils/index.js'
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* 生成修改定时任务参数
|
|
14
|
-
*/
|
|
15
|
-
export interface UpdateParamsParams {
|
|
16
|
-
jobId: string
|
|
17
|
-
time: string
|
|
18
|
-
name: string
|
|
19
|
-
message: string
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* 参数 Schema 定义
|
|
24
|
-
*/
|
|
25
|
-
const UpdateParamsSchema = {
|
|
26
|
-
type: 'object',
|
|
27
|
-
properties: {
|
|
28
|
-
jobId: {
|
|
29
|
-
type: 'string',
|
|
30
|
-
description:
|
|
31
|
-
},
|
|
32
|
-
time: {
|
|
33
|
-
type: 'string',
|
|
34
|
-
description:
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
-
|
|
76
|
-
-
|
|
77
|
-
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
})
|
|
197
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* 智小途定时任务工具 - 生成修改定时任务参数
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { OpenClawPluginApi } from 'openclaw/plugin-sdk'
|
|
6
|
+
import {
|
|
7
|
+
isCronExpression,
|
|
8
|
+
relativeToCron,
|
|
9
|
+
validateTimeFormat,
|
|
10
|
+
} from '../../utils/index.js'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 生成修改定时任务参数
|
|
14
|
+
*/
|
|
15
|
+
export interface UpdateParamsParams {
|
|
16
|
+
jobId: string
|
|
17
|
+
time: string
|
|
18
|
+
name: string
|
|
19
|
+
message: string
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 参数 Schema 定义
|
|
24
|
+
*/
|
|
25
|
+
const UpdateParamsSchema = {
|
|
26
|
+
type: 'object',
|
|
27
|
+
properties: {
|
|
28
|
+
jobId: {
|
|
29
|
+
type: 'string',
|
|
30
|
+
description: `OpenClaw 任务 ID(必须是数字或字符串,不是 cron 表达式)`,
|
|
31
|
+
},
|
|
32
|
+
time: {
|
|
33
|
+
type: 'string',
|
|
34
|
+
description: '⏰ 时间(核心!),支持相对时间和 cron 表达式,工具自动转换',
|
|
35
|
+
},
|
|
36
|
+
name: {
|
|
37
|
+
type: 'string',
|
|
38
|
+
description: '任务名称',
|
|
39
|
+
},
|
|
40
|
+
message: {
|
|
41
|
+
type: 'string',
|
|
42
|
+
description: '提醒内容',
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
required: ['jobId', 'time', 'name', 'message'],
|
|
46
|
+
} as const
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 构造工具返回结果
|
|
50
|
+
*/
|
|
51
|
+
function json(data: unknown): any {
|
|
52
|
+
return {
|
|
53
|
+
content: [{ type: 'text' as const, text: JSON.stringify(data, null, 2) }],
|
|
54
|
+
details: data,
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* 获取生成修改定时任务参数工具
|
|
60
|
+
*/
|
|
61
|
+
function getOpenclawWorkclawCronUpdateParamsTool(api: OpenClawPluginApi) {
|
|
62
|
+
return (ctx: any) => {
|
|
63
|
+
return {
|
|
64
|
+
name: 'openclaw-workclaw-cron-update-params',
|
|
65
|
+
label: '智小途生成修改提醒参数',
|
|
66
|
+
description: `【核心工具】生成修改提醒的 cronParams 参数。
|
|
67
|
+
|
|
68
|
+
📋 工作流程(必须按顺序执行):
|
|
69
|
+
1. 调用此工具获取 cronParams 参数
|
|
70
|
+
2. 使用返回的 cronParams 调用 OpenClaw 的 cron 工具
|
|
71
|
+
3. 必须调用 openclaw-workclaw-cron-update-sync 同步到后端
|
|
72
|
+
|
|
73
|
+
⏰ 时间格式(核心!):
|
|
74
|
+
- time 参数支持相对时间(如 "10m"、"1h"、"2d")和 cron 表达式
|
|
75
|
+
- 工具会自动将所有时间统一转换为 cron 表达式
|
|
76
|
+
- 严禁使用 --at 参数或其他绝对时间格式
|
|
77
|
+
- 最终 CLI 命令必须使用 --cron 参数
|
|
78
|
+
|
|
79
|
+
🔒 强制规则:
|
|
80
|
+
- schedule.kind 必须是 "cron"
|
|
81
|
+
- 必须使用 --cron 参数传递 cron 表达式
|
|
82
|
+
|
|
83
|
+
⚠️ 必须从 cron 工具返回值中确认更新成功`,
|
|
84
|
+
parameters: UpdateParamsSchema,
|
|
85
|
+
execute: async (_toolCallId: string, params: UpdateParamsParams) => {
|
|
86
|
+
const p = params as UpdateParamsParams
|
|
87
|
+
|
|
88
|
+
api.logger.info(`[智小途-生成修改参数] 开始处理 jobId=${p.jobId} name=${p.name} time=${p.time}`)
|
|
89
|
+
|
|
90
|
+
// 参数校验
|
|
91
|
+
if (!p.jobId) {
|
|
92
|
+
api.logger.warn('[智小途-生成修改参数] 缺少 jobId 参数')
|
|
93
|
+
return json({ error: 'jobId 为必填参数' })
|
|
94
|
+
}
|
|
95
|
+
if (!p.time) {
|
|
96
|
+
api.logger.warn('[智小途-生成修改参数] 缺少时间参数')
|
|
97
|
+
return json({ error: 'time(时间)为必填参数' })
|
|
98
|
+
}
|
|
99
|
+
if (!p.name) {
|
|
100
|
+
api.logger.warn('[智小途-生成修改参数] 缺少任务名称参数')
|
|
101
|
+
return json({ error: 'name(任务名称)为必填参数' })
|
|
102
|
+
}
|
|
103
|
+
if (!p.message) {
|
|
104
|
+
api.logger.warn('[智小途-生成修改参数] 缺少提醒内容参数')
|
|
105
|
+
return json({ error: 'message(提醒内容)为必填参数' })
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// 从 ctx 获取必要参数
|
|
109
|
+
const accountId = ctx?.agentAccountId
|
|
110
|
+
const name = p.name
|
|
111
|
+
const message = p.message
|
|
112
|
+
const time = p.time
|
|
113
|
+
|
|
114
|
+
// 校验必要参数
|
|
115
|
+
if (!accountId) {
|
|
116
|
+
api.logger.warn('[智小途-生成修改参数] 无法获取账户 ID')
|
|
117
|
+
return json({ error: '无法获取账户 ID(accountId),请确保已配置账户' })
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
api.logger.info(`[智小途-生成修改参数] accountId=${accountId} jobId=${p.jobId}`)
|
|
121
|
+
|
|
122
|
+
// 校验时间格式
|
|
123
|
+
const timeValidation = validateTimeFormat(time)
|
|
124
|
+
if (!timeValidation.valid) {
|
|
125
|
+
api.logger.warn(`[智小途-生成修改参数] 时间格式校验失败: ${timeValidation.error}`)
|
|
126
|
+
return json({ error: timeValidation.error })
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// 判断时间类型
|
|
130
|
+
const isCron = isCronExpression(time)
|
|
131
|
+
let isOneTime = false
|
|
132
|
+
let cronExpr: string
|
|
133
|
+
|
|
134
|
+
// 如果是相对时间(5m、1h 等),转换为绝对时间的 cron 表达式
|
|
135
|
+
if (!isCron) {
|
|
136
|
+
isOneTime = true
|
|
137
|
+
cronExpr = relativeToCron(time.trim())
|
|
138
|
+
api.logger.info(`[智小途-生成修改参数] 相对时间转换为绝对时间 cron 表达式 cronExpr=${cronExpr}`)
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
cronExpr = time.trim()
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const cronParams: Record<string, any> = {
|
|
145
|
+
action: 'update' as const,
|
|
146
|
+
account: accountId,
|
|
147
|
+
jobId: p.jobId,
|
|
148
|
+
job: {
|
|
149
|
+
name,
|
|
150
|
+
schedule: {
|
|
151
|
+
kind: 'cron' as const,
|
|
152
|
+
expr: cronExpr,
|
|
153
|
+
tz: 'Asia/Shanghai',
|
|
154
|
+
},
|
|
155
|
+
sessionTarget: 'isolated',
|
|
156
|
+
wakeMode: 'now' as const,
|
|
157
|
+
deleteAfterRun: isOneTime ? true : undefined,
|
|
158
|
+
payload: {
|
|
159
|
+
kind: 'agentTurn' as const,
|
|
160
|
+
message,
|
|
161
|
+
},
|
|
162
|
+
delivery: {
|
|
163
|
+
mode: 'announce',
|
|
164
|
+
channel: 'openclaw-workclaw',
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
api.logger.info(`[智小途-生成修改参数] 构建 cron 参数 cronParams=${JSON.stringify(cronParams)}`)
|
|
170
|
+
|
|
171
|
+
return json({
|
|
172
|
+
cronParams,
|
|
173
|
+
meta: {
|
|
174
|
+
accountId,
|
|
175
|
+
jobId: p.jobId,
|
|
176
|
+
name,
|
|
177
|
+
kind: 'cron',
|
|
178
|
+
expr: cronExpr,
|
|
179
|
+
message,
|
|
180
|
+
},
|
|
181
|
+
summary: `✅ 提醒已修改: "${name}" (${time})`,
|
|
182
|
+
})
|
|
183
|
+
},
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* 注册生成修改定时任务参数工具
|
|
190
|
+
*/
|
|
191
|
+
export function registerOpenclawWorkclawCronUpdateParamsTool(api: OpenClawPluginApi): void {
|
|
192
|
+
(api.registerTool as any)(getOpenclawWorkclawCronUpdateParamsTool(api), {
|
|
193
|
+
name: 'openclaw-workclaw-cron-update-params',
|
|
194
|
+
})
|
|
195
|
+
}
|