@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.
Files changed (145) hide show
  1. package/README.md +30 -11
  2. package/dist/api.d.ts +3 -0
  3. package/dist/api.js +3 -0
  4. package/dist/index.d.ts +11 -0
  5. package/dist/index.js +264 -0
  6. package/dist/setup-entry.d.ts +2 -0
  7. package/dist/setup-entry.js +12 -0
  8. package/dist/src/accounts.d.ts +66 -0
  9. package/dist/src/accounts.js +279 -0
  10. package/dist/src/api/accounts-api.d.ts +2 -0
  11. package/dist/src/api/accounts-api.js +130 -0
  12. package/dist/src/api/prompts-api.d.ts +2 -0
  13. package/dist/src/api/prompts-api.js +103 -0
  14. package/dist/src/api/session-api.d.ts +2 -0
  15. package/dist/src/api/session-api.js +207 -0
  16. package/dist/src/api/skills-api.d.ts +2 -0
  17. package/dist/src/api/skills-api.js +64 -0
  18. package/dist/src/api/workspace.d.ts +3 -0
  19. package/dist/src/api/workspace.js +30 -0
  20. package/dist/src/channel.d.ts +11 -0
  21. package/{src/channel.ts → dist/src/channel.js} +199 -225
  22. package/dist/src/config-schema.d.ts +93 -0
  23. package/dist/src/config-schema.js +56 -0
  24. package/dist/src/connection/workclaw-client.d.ts +147 -0
  25. package/dist/src/connection/workclaw-client.js +351 -0
  26. package/dist/src/gateway/agent-handlers.d.ts +12 -0
  27. package/{src/gateway/agent-handlers.ts → dist/src/gateway/agent-handlers.js} +372 -462
  28. package/dist/src/gateway/config-writer.d.ts +71 -0
  29. package/dist/src/gateway/config-writer.js +302 -0
  30. package/dist/src/gateway/cron-tasks-handler.d.ts +19 -0
  31. package/dist/src/gateway/cron-tasks-handler.js +188 -0
  32. package/dist/src/gateway/message-context.d.ts +80 -0
  33. package/{src/gateway/message-context.ts → dist/src/gateway/message-context.js} +509 -594
  34. package/dist/src/gateway/message-dispatcher.d.ts +18 -0
  35. package/dist/src/gateway/message-dispatcher.js +572 -0
  36. package/dist/src/gateway/reconnect.d.ts +27 -0
  37. package/{src/gateway/reconnect.ts → dist/src/gateway/reconnect.js} +210 -253
  38. package/dist/src/gateway/skills-handler.d.ts +29 -0
  39. package/dist/src/gateway/skills-handler.js +615 -0
  40. package/dist/src/gateway/skills-list-handler.d.ts +27 -0
  41. package/dist/src/gateway/skills-list-handler.js +233 -0
  42. package/dist/src/gateway/tools-list-handler.d.ts +30 -0
  43. package/dist/src/gateway/tools-list-handler.js +101 -0
  44. package/dist/src/gateway/workclaw-gateway.d.ts +14 -0
  45. package/dist/src/gateway/workclaw-gateway.js +237 -0
  46. package/dist/src/media/upload.d.ts +13 -0
  47. package/dist/src/media/upload.js +125 -0
  48. package/dist/src/outbound/index.d.ts +36 -0
  49. package/dist/src/outbound/index.js +123 -0
  50. package/dist/src/outbound/workclaw-sender.d.ts +36 -0
  51. package/{src/outbound/workclaw-sender.ts → dist/src/outbound/workclaw-sender.js} +95 -158
  52. package/dist/src/runtime.d.ts +116 -0
  53. package/dist/src/runtime.js +374 -0
  54. package/dist/src/secret-contract-api.d.ts +4 -0
  55. package/dist/src/secret-contract-api.js +4 -0
  56. package/{src/send.ts → dist/src/send.d.ts} +1 -1
  57. package/dist/src/send.js +1 -0
  58. package/dist/src/setup-api.d.ts +3 -0
  59. package/dist/src/setup-api.js +3 -0
  60. package/dist/src/setup-core.d.ts +3 -0
  61. package/dist/src/setup-core.js +13 -0
  62. package/dist/src/setup-surface.d.ts +7 -0
  63. package/dist/src/setup-surface.js +363 -0
  64. package/dist/src/tools/openclaw-workclaw-cron/api/index.d.ts +93 -0
  65. package/dist/src/tools/openclaw-workclaw-cron/api/index.js +209 -0
  66. package/dist/src/tools/openclaw-workclaw-cron/index.d.ts +10 -0
  67. package/{src/tools/openclaw-workclaw-cron/index.ts → dist/src/tools/openclaw-workclaw-cron/index.js} +33 -39
  68. package/dist/src/tools/openclaw-workclaw-cron/src/add/params.d.ts +16 -0
  69. package/dist/src/tools/openclaw-workclaw-cron/src/add/params.js +152 -0
  70. package/dist/src/tools/openclaw-workclaw-cron/src/add/sync.d.ts +18 -0
  71. package/dist/src/tools/openclaw-workclaw-cron/src/add/sync.js +162 -0
  72. package/dist/src/tools/openclaw-workclaw-cron/src/disable/params.d.ts +14 -0
  73. package/dist/src/tools/openclaw-workclaw-cron/src/disable/params.js +80 -0
  74. package/dist/src/tools/openclaw-workclaw-cron/src/disable/sync.d.ts +14 -0
  75. package/dist/src/tools/openclaw-workclaw-cron/src/disable/sync.js +107 -0
  76. package/dist/src/tools/openclaw-workclaw-cron/src/enable/params.d.ts +14 -0
  77. package/dist/src/tools/openclaw-workclaw-cron/src/enable/params.js +80 -0
  78. package/dist/src/tools/openclaw-workclaw-cron/src/enable/sync.d.ts +14 -0
  79. package/dist/src/tools/openclaw-workclaw-cron/src/enable/sync.js +107 -0
  80. package/dist/src/tools/openclaw-workclaw-cron/src/notify/sync.d.ts +17 -0
  81. package/dist/src/tools/openclaw-workclaw-cron/src/notify/sync.js +127 -0
  82. package/dist/src/tools/openclaw-workclaw-cron/src/remove/params.d.ts +14 -0
  83. package/dist/src/tools/openclaw-workclaw-cron/src/remove/params.js +87 -0
  84. package/dist/src/tools/openclaw-workclaw-cron/src/remove/sync.d.ts +14 -0
  85. package/dist/src/tools/openclaw-workclaw-cron/src/remove/sync.js +107 -0
  86. package/dist/src/tools/openclaw-workclaw-cron/src/update/params.d.ts +17 -0
  87. package/dist/src/tools/openclaw-workclaw-cron/src/update/params.js +164 -0
  88. package/dist/src/tools/openclaw-workclaw-cron/src/update/sync.d.ts +18 -0
  89. package/dist/src/tools/openclaw-workclaw-cron/src/update/sync.js +135 -0
  90. package/dist/src/tools/openclaw-workclaw-cron/types/index.d.ts +52 -0
  91. package/dist/src/tools/openclaw-workclaw-cron/types/index.js +4 -0
  92. package/dist/src/tools/openclaw-workclaw-cron/utils/index.d.ts +40 -0
  93. package/dist/src/tools/openclaw-workclaw-cron/utils/index.js +122 -0
  94. package/dist/src/tools/openclaw-workclaw-system/index.d.ts +10 -0
  95. package/{src/tools/openclaw-workclaw-system/index.ts → dist/src/tools/openclaw-workclaw-system/index.js} +15 -17
  96. package/dist/src/tools/openclaw-workclaw-system/src/get/index.d.ts +8 -0
  97. package/dist/src/tools/openclaw-workclaw-system/src/get/index.js +64 -0
  98. package/dist/src/tools/openclaw-workclaw-system/src/token/index.d.ts +8 -0
  99. package/dist/src/tools/openclaw-workclaw-system/src/token/index.js +78 -0
  100. package/{src/types.ts → dist/src/types.d.ts} +39 -58
  101. package/dist/src/types.js +1 -0
  102. package/dist/src/utils/content.d.ts +15 -0
  103. package/{src/utils/content.ts → dist/src/utils/content.js} +38 -35
  104. package/package.json +13 -9
  105. package/index.ts +0 -302
  106. package/setup-entry.ts +0 -6
  107. package/src/accounts.ts +0 -312
  108. package/src/api/accounts-api.ts +0 -156
  109. package/src/api/prompts-api.ts +0 -116
  110. package/src/api/session-api.ts +0 -238
  111. package/src/api/skills-api.ts +0 -72
  112. package/src/api/workspace.ts +0 -41
  113. package/src/config-schema.ts +0 -110
  114. package/src/connection/workclaw-client.ts +0 -643
  115. package/src/gateway/config-writer.ts +0 -296
  116. package/src/gateway/message-dispatcher.ts +0 -641
  117. package/src/gateway/skills-handler.ts +0 -741
  118. package/src/gateway/skills-list-handler.ts +0 -332
  119. package/src/gateway/tools-list-handler.ts +0 -160
  120. package/src/gateway/workclaw-gateway.ts +0 -367
  121. package/src/media/upload.ts +0 -157
  122. package/src/outbound/index.ts +0 -185
  123. package/src/runtime.ts +0 -497
  124. package/src/tools/openclaw-workclaw-cron/api/index.ts +0 -326
  125. package/src/tools/openclaw-workclaw-cron/src/add/params.ts +0 -177
  126. package/src/tools/openclaw-workclaw-cron/src/add/sync.ts +0 -188
  127. package/src/tools/openclaw-workclaw-cron/src/disable/params.ts +0 -100
  128. package/src/tools/openclaw-workclaw-cron/src/disable/sync.ts +0 -127
  129. package/src/tools/openclaw-workclaw-cron/src/enable/params.ts +0 -100
  130. package/src/tools/openclaw-workclaw-cron/src/enable/sync.ts +0 -127
  131. package/src/tools/openclaw-workclaw-cron/src/notify/sync.ts +0 -148
  132. package/src/tools/openclaw-workclaw-cron/src/remove/params.ts +0 -109
  133. package/src/tools/openclaw-workclaw-cron/src/remove/sync.ts +0 -127
  134. package/src/tools/openclaw-workclaw-cron/src/update/params.ts +0 -195
  135. package/src/tools/openclaw-workclaw-cron/src/update/sync.ts +0 -161
  136. package/src/tools/openclaw-workclaw-cron/types/index.ts +0 -55
  137. package/src/tools/openclaw-workclaw-cron/utils/index.ts +0 -141
  138. package/src/tools/openclaw-workclaw-system/src/get/index.ts +0 -77
  139. package/src/tools/openclaw-workclaw-system/src/token/index.ts +0 -93
  140. package/tests/accounts.test.ts +0 -285
  141. package/tests/message-context.test.ts +0 -313
  142. package/tests/reconnect.test.ts +0 -257
  143. package/tests/workclaw-client.test.ts +0 -112
  144. package/tsconfig.json +0 -14
  145. package/vitest.config.ts +0 -8
@@ -1,326 +0,0 @@
1
- /**
2
- * 智小途定时任务工具 - 后端接口封装
3
- */
4
-
5
- import type { OpenClawPluginApi } from 'openclaw/plugin-sdk'
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
-
10
- const DEFAULT_MAX_RETRIES = 3
11
- const DEFAULT_RETRY_DELAY_MS = 1000
12
-
13
- /**
14
- * 睡眠函数
15
- */
16
- function sleep(ms: number): Promise<void> {
17
- return new Promise(resolve => setTimeout(resolve, ms))
18
- }
19
-
20
- /**
21
- * 带重试机制的 fetch 调用
22
- */
23
- async function fetchWithRetry<T>(
24
- fetchFn: () => Promise<T>,
25
- options: {
26
- maxRetries?: number
27
- retryDelayMs?: number
28
- retryableErrors?: string[]
29
- } = {},
30
- ): Promise<{ data?: T, error?: string, attempts: number }> {
31
- const maxRetries = options.maxRetries ?? DEFAULT_MAX_RETRIES
32
- const retryDelayMs = options.retryDelayMs ?? DEFAULT_RETRY_DELAY_MS
33
- const retryableErrors = options.retryableErrors ?? [
34
- 'ECONNREFUSED',
35
- 'ETIMEDOUT',
36
- 'ENOTFOUND',
37
- 'ENETUNREACH',
38
- 'EAI_AGAIN',
39
- ]
40
-
41
- let lastError: string = ''
42
- let attempts = 0
43
-
44
- for (let i = 0; i <= maxRetries; i++) {
45
- attempts = i + 1
46
- try {
47
- const data = await fetchFn()
48
- return { data, attempts }
49
- }
50
- catch (error: any) {
51
- lastError = error.message || String(error)
52
-
53
- const isRetryable = retryableErrors.some(
54
- e => lastError.toLowerCase().includes(e.toLowerCase()),
55
- )
56
-
57
- if (i < maxRetries && isRetryable) {
58
- const delay = retryDelayMs * 2 ** i
59
- await sleep(delay)
60
- continue
61
- }
62
-
63
- break
64
- }
65
- }
66
-
67
- return { error: lastError, attempts }
68
- }
69
-
70
- /**
71
- * 脱敏日志输出(隐藏敏感字段)
72
- */
73
- function sanitizePayload(payload: Record<string, any>): Record<string, any> {
74
- const sensitiveFields = [
75
- 'password',
76
- 'secret',
77
- 'token',
78
- 'authorization',
79
- 'appSecret',
80
- 'appSecret',
81
- ]
82
-
83
- const sanitized: Record<string, any> = {}
84
- for (const [key, value] of Object.entries(payload)) {
85
- const lowerKey = key.toLowerCase()
86
- if (sensitiveFields.some(f => lowerKey.includes(f))) {
87
- sanitized[key] = '***'
88
- }
89
- else if (typeof value === 'object' && value !== null) {
90
- sanitized[key] = sanitizePayload(value as Record<string, any>)
91
- }
92
- else {
93
- sanitized[key] = value
94
- }
95
- }
96
- return sanitized
97
- }
98
-
99
- /**
100
- * 调用后端 API 的通用方法
101
- * @param api - OpenClaw API 实例
102
- * @param accountId - 账户 ID
103
- * @param path - API 路径
104
- * @param payload - 请求体
105
- * @param options - 可选配置
106
- * @returns 接口调用结果
107
- */
108
- export async function callBackendApi(
109
- api: OpenClawPluginApi,
110
- accountId: string,
111
- path: string,
112
- payload: Record<string, any>,
113
- options: {
114
- maxRetries?: number
115
- } = {},
116
- ): Promise<{ success: boolean, data?: any, error?: string, attempts?: number }> {
117
- try {
118
- const account = resolveWorkclawAccountWithCache({
119
- cfg: api.config,
120
- accountId,
121
- })
122
-
123
- if (!account.configured) {
124
- api.logger.error(`[智小途-定时任务] 账户未配置 accountId=${accountId}`)
125
- return { success: false, error: 'Account not configured' }
126
- }
127
-
128
- const accConfig = account.config as any
129
- const tokenCacheKey = accConfig.appKey || accountId
130
- const baseUrl = normalizeBaseUrl(accConfig.baseUrl)
131
-
132
- api.logger.info(`[智小途-定时任务] 正在获取认证 token,accountId=${accountId}`)
133
-
134
- const token = await getWorkclawAccessToken(tokenCacheKey, {
135
- baseUrl: accConfig.baseUrl,
136
- appKey: accConfig.appKey,
137
- appSecret: accConfig.appSecret,
138
- allowInsecureTls: accConfig.allowInsecureTls,
139
- requestTimeout: accConfig.requestTimeout,
140
- } as WorkclawConnectionConfig)
141
-
142
- const requestUrl = `${baseUrl}/open-apis${path}`
143
- const sanitizedPayload = sanitizePayload(payload)
144
- api.logger.info(`[智小途-定时任务] 调用接口 ${requestUrl}`)
145
- api.logger.info(`[智小途-定时任务] 请求参数 ${JSON.stringify(sanitizedPayload)}`)
146
-
147
- const maxRetries = options.maxRetries ?? DEFAULT_MAX_RETRIES
148
-
149
- const fetchResult = await fetchWithRetry(
150
- () =>
151
- doFetchJson(
152
- requestUrl,
153
- {
154
- method: 'POST',
155
- headers: {
156
- 'Content-Type': 'application/json',
157
- 'Authorization': `Bearer ${token}`,
158
- },
159
- body: JSON.stringify(payload),
160
- },
161
- accConfig.allowInsecureTls,
162
- accConfig.requestTimeout,
163
- ),
164
- { maxRetries },
165
- )
166
-
167
- if (fetchResult.error) {
168
- api.logger.error(`[智小途-定时任务] 接口调用失败(已重试 ${fetchResult.attempts} 次): ${fetchResult.error}`)
169
- return { success: false, error: fetchResult.error, attempts: fetchResult.attempts }
170
- }
171
-
172
- const data = fetchResult.data
173
- api.logger.info(`[智小途-定时任务] 接口响应(尝试 ${fetchResult.attempts} 次): ${JSON.stringify(data)}`)
174
-
175
- if (data?.code === 200 || data?.code === 0) {
176
- return { success: true, data, attempts: fetchResult.attempts }
177
- }
178
- else {
179
- const errorMsg = data?.message || data?.msg || 'Unknown error'
180
- api.logger.error(`[智小途-定时任务] 接口返回错误 ${errorMsg}`)
181
- return { success: false, error: errorMsg }
182
- }
183
- }
184
- catch (error: any) {
185
- api.logger.error(`[智小途-定时任务] 接口调用异常 ${error.message}`)
186
- return { success: false, error: error.message }
187
- }
188
- }
189
-
190
- /**
191
- * 调用新增定时任务接口
192
- */
193
- export async function callCronJobAdd(
194
- api: OpenClawPluginApi,
195
- accountId: string,
196
- payload: {
197
- jobId: string
198
- name: string
199
- kind: 'cron'
200
- expr?: string
201
- message: string
202
- messageId?: string
203
- },
204
- ): Promise<{ success: boolean, data?: any, error?: string }> {
205
- api.logger.info(`[智小途-定时任务] 新增定时任务 jobId=${payload.jobId} name=${payload.name}`)
206
-
207
- const result = await callBackendApi(api, accountId, '/cron/job/add', {
208
- clawJobId: payload.jobId,
209
- name: payload.name,
210
- kind: payload.kind,
211
- expr: payload.expr || '',
212
- message: payload.message,
213
- agentId: payload.messageId || '0',
214
- })
215
-
216
- return { success: result.success, data: result.data, error: result.error }
217
- }
218
-
219
- /**
220
- * 调用删除定时任务接口
221
- */
222
- export async function callCronJobRemove(
223
- api: OpenClawPluginApi,
224
- accountId: string,
225
- payload: {
226
- jobId: string
227
- },
228
- ): Promise<{ success: boolean, data?: any, error?: string }> {
229
- api.logger.info(`[智小途-定时任务] 删除定时任务 jobId=${payload.jobId}`)
230
-
231
- const result = await callBackendApi(api, accountId, '/cron/job/del', {
232
- clawJobId: payload.jobId,
233
- })
234
-
235
- return { success: result.success, data: result.data, error: result.error }
236
- }
237
-
238
- /**
239
- * 调用更新定时任务接口
240
- */
241
- export async function callCronJobUpdate(
242
- api: OpenClawPluginApi,
243
- accountId: string,
244
- payload: {
245
- jobId: string
246
- name: string
247
- kind: 'cron'
248
- expr?: string
249
- message: string
250
- agentId?: string
251
- },
252
- ): Promise<{ success: boolean, data?: any, error?: string }> {
253
- api.logger.info(`[智小途-定时任务] 更新定时任务 jobId=${payload.jobId} name=${payload.name} agentId=${payload.agentId}`)
254
-
255
- const result = await callBackendApi(api, accountId, '/cron/job/update', {
256
- clawJobId: payload.jobId,
257
- name: payload.name,
258
- kind: payload.kind,
259
- expr: payload.expr || '',
260
- message: payload.message,
261
- agentId: payload.agentId || '0',
262
- })
263
-
264
- return { success: result.success, data: result.data, error: result.error }
265
- }
266
-
267
- /**
268
- * 调用启用定时任务接口
269
- */
270
- export async function callCronJobEnabled(
271
- api: OpenClawPluginApi,
272
- accountId: string,
273
- payload: {
274
- jobId: string
275
- },
276
- ): Promise<{ success: boolean, data?: any, error?: string }> {
277
- api.logger.info(`[智小途-定时任务] 启用定时任务 jobId=${payload.jobId}`)
278
-
279
- const result = await callBackendApi(api, accountId, '/cron/job/enabled', {
280
- clawJobId: payload.jobId,
281
- })
282
-
283
- return { success: result.success, data: result.data, error: result.error }
284
- }
285
-
286
- /**
287
- * 调用禁用定时任务接口
288
- */
289
- export async function callCronJobDisabled(
290
- api: OpenClawPluginApi,
291
- accountId: string,
292
- payload: {
293
- jobId: string
294
- },
295
- ): Promise<{ success: boolean, data?: any, error?: string }> {
296
- api.logger.info(`[智小途-定时任务] 禁用定时任务 jobId=${payload.jobId}`)
297
-
298
- const result = await callBackendApi(api, accountId, '/cron/job/disabled', {
299
- clawJobId: payload.jobId,
300
- })
301
-
302
- return { success: result.success, data: result.data, error: result.error }
303
- }
304
-
305
- /**
306
- * 调用定时任务触发通知接口
307
- */
308
- export async function callCronJobMessage(
309
- api: OpenClawPluginApi,
310
- accountId: string,
311
- payload: {
312
- jobId: string
313
- message: string
314
- agentId?: string
315
- },
316
- ): Promise<{ success: boolean, data?: any, error?: string }> {
317
- api.logger.info(`[智小途-定时任务] 定时任务触发通知 jobId=${payload.jobId} message=${payload.message} agentId=${payload.agentId}`)
318
-
319
- const result = await callBackendApi(api, accountId, '/cron/job/message', {
320
- clawJobId: payload.jobId,
321
- message: payload.message,
322
- agentId: payload.agentId || '0',
323
- })
324
-
325
- return { success: result.success, data: result.data, error: result.error }
326
- }
@@ -1,177 +0,0 @@
1
- /**
2
- * 智小途定时任务工具 - 生成创建定时任务参数
3
- */
4
-
5
- import type { OpenClawPluginApi } from 'openclaw/plugin-sdk'
6
- import { isCronExpression, relativeToCron, validateTimeFormat } from '../../utils/index.js'
7
-
8
- /**
9
- * 生成创建定时任务参数
10
- */
11
- export interface AddParamsParams {
12
- time: string
13
- name: string
14
- message: string
15
- }
16
-
17
- /**
18
- * 参数 Schema 定义
19
- */
20
- const AddParamsSchema = {
21
- type: 'object',
22
- properties: {
23
- time: {
24
- type: 'string',
25
- description: '⏰ 时间(核心!),支持相对时间和 cron 表达式,工具自动转换',
26
- },
27
- name: {
28
- type: 'string',
29
- description: '任务名称',
30
- },
31
- message: {
32
- type: 'string',
33
- description: '提醒内容',
34
- },
35
- },
36
- required: ['time', 'name', 'message'],
37
- } as const
38
-
39
- /**
40
- * 构造工具返回结果
41
- */
42
- function json(data: unknown): any {
43
- return {
44
- content: [{ type: 'text' as const, text: JSON.stringify(data, null, 2) }],
45
- details: data,
46
- }
47
- }
48
-
49
- /**
50
- * 获取生成创建定时任务参数工具
51
- */
52
- function getOpenclawWorkclawCronAddParamsTool(api: OpenClawPluginApi) {
53
- return (ctx: any) => {
54
- return {
55
- name: 'openclaw-workclaw-cron-add-params',
56
- label: '智小途生成创建提醒参数',
57
- description: `【核心工具】生成创建提醒的 cronParams 参数。
58
-
59
- 📋 工作流程(必须按顺序执行):
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
- parameters: AddParamsSchema,
77
- execute: async (_toolCallId: string, params: AddParamsParams) => {
78
- const p = params as AddParamsParams
79
-
80
- api.logger.info(`[智小途-生成参数] 开始生成创建提醒参数 name=${p.name} time=${p.time}`)
81
-
82
- // 参数校验
83
- if (!p.time) {
84
- api.logger.warn('[智小途-生成参数] 缺少时间参数')
85
- return json({ error: 'time(时间)为必填参数' })
86
- }
87
- if (!p.name) {
88
- api.logger.warn('[智小途-生成参数] 缺少任务名称参数')
89
- return json({ error: 'name(任务名称)为必填参数' })
90
- }
91
- if (!p.message) {
92
- api.logger.warn('[智小途-生成参数] 缺少用户消息参数')
93
- return json({ error: 'message(用户消息)为必填参数' })
94
- }
95
-
96
- // 从 ctx 获取必要参数
97
- const accountId = ctx?.agentAccountId
98
- if (!accountId) {
99
- api.logger.warn('[智小途-生成参数] 无法获取账户 ID')
100
- return json({ error: '无法获取账户 ID(accountId),请确保已配置账户' })
101
- }
102
-
103
- api.logger.info(`[智小途-生成参数] accountId=${accountId} name=${p.name}`)
104
-
105
- // 校验时间格式
106
- const timeValidation = validateTimeFormat(p.time)
107
- if (!timeValidation.valid) {
108
- api.logger.warn(`[智小途-生成参数] 时间格式校验失败: ${timeValidation.error}`)
109
- return json({ error: timeValidation.error })
110
- }
111
-
112
- // 判断时间类型并转换为 cron 表达式
113
- const isCron = isCronExpression(p.time)
114
- let isOneTime = false
115
- let cronExpr: string
116
-
117
- if (!isCron) {
118
- // 相对时间转换为 cron 表达式
119
- isOneTime = true
120
- cronExpr = relativeToCron(p.time.trim())
121
- api.logger.info(`[智小途-生成参数] 相对时间转换为 cron 表达式 cronExpr=${cronExpr}`)
122
- }
123
- else {
124
- cronExpr = p.time.trim()
125
- }
126
-
127
- // 构建 cron 参数
128
- const cronParams: Record<string, any> = {
129
- action: 'add' as const,
130
- account: accountId,
131
- job: {
132
- name: p.name,
133
- schedule: {
134
- kind: 'cron' as const,
135
- expr: cronExpr,
136
- tz: 'Asia/Shanghai',
137
- },
138
- sessionTarget: 'isolated',
139
- wakeMode: 'now' as const,
140
- deleteAfterRun: isOneTime ? true : undefined,
141
- payload: {
142
- kind: 'agentTurn' as const,
143
- message: p.message,
144
- },
145
- delivery: {
146
- mode: 'announce',
147
- channel: 'openclaw-workclaw',
148
- },
149
- },
150
- }
151
-
152
- api.logger.info(`[智小途-生成参数] 构建 cron 参数 cronParams=${JSON.stringify(cronParams)}`)
153
-
154
- return json({
155
- cronParams,
156
- meta: {
157
- accountId,
158
- name: p.name,
159
- kind: 'cron',
160
- expr: cronExpr,
161
- message: p.message,
162
- },
163
- summary: `⏰ 提醒已生成: "${p.name}" (${p.time})`,
164
- })
165
- },
166
- }
167
- }
168
- }
169
-
170
- /**
171
- * 注册生成创建定时任务参数工具
172
- */
173
- export function registerOpenclawWorkclawCronAddParamsTool(api: OpenClawPluginApi): void {
174
- (api.registerTool as any)(getOpenclawWorkclawCronAddParamsTool(api), {
175
- name: 'openclaw-workclaw-cron-add-params',
176
- })
177
- }
@@ -1,188 +0,0 @@
1
- /**
2
- * 智小途定时任务工具 - 同步创建定时任务到后端
3
- */
4
-
5
- import type { OpenClawPluginApi } from 'openclaw/plugin-sdk'
6
- import { resolveWorkclawAccountWithCache } from '../../../../accounts.js'
7
- import { callCronJobAdd } from '../../api/index.js'
8
-
9
- /**
10
- * 同步创建定时任务参数
11
- */
12
- export interface AddSyncParams {
13
- jobId: string
14
- name: string
15
- kind: 'cron'
16
- expr?: string
17
- message: string
18
- }
19
-
20
- /**
21
- * 参数 Schema 定义
22
- */
23
- const AddSyncSchema = {
24
- type: 'object',
25
- properties: {
26
- jobId: {
27
- type: 'string',
28
- description: `⛔ 重要:jobId 必须从 OpenClaw cron 工具返回值中提取,格式:{"success": true, "jobId": "123456"}
29
-
30
- 常见错误:
31
- - 把 cron 表达式(如 "31 12 11 31 3 *")当作 jobId
32
- - 把 name 当作 jobId
33
- - 编造 jobId
34
-
35
- 正确做法:
36
- 1. 调用 openclaw-workclaw-cron-add-params
37
- 2. 用返回的 cronParams 调用 cron 工具
38
- 3. 从返回值提取 jobId(如 "7382945612345")
39
- 4. 用提取到的 jobId 调用此工具`,
40
- },
41
- name: {
42
- type: 'string',
43
- description: '任务名称,与 add-params 中传入的 name 一致',
44
- },
45
- kind: {
46
- type: 'string',
47
- description: '任务类型',
48
- enum: ['cron'],
49
- },
50
- expr: {
51
- type: 'string',
52
- description: 'Cron 表达式',
53
- },
54
- message: {
55
- type: 'string',
56
- description: '提醒消息,与 add-params 中传入的 message 一致',
57
- },
58
- },
59
- required: ['jobId', 'name', 'kind', 'message'],
60
- } as const
61
-
62
- /**
63
- * 构造工具返回结果
64
- */
65
- function json(data: unknown): any {
66
- return {
67
- content: [{ type: 'text' as const, text: JSON.stringify(data, null, 2) }],
68
- details: data,
69
- }
70
- }
71
-
72
- /**
73
- * 获取同步创建定时任务到后端工具
74
- */
75
- function getOpenclawWorkclawCronAddSyncTool(api: OpenClawPluginApi) {
76
- return (ctx: any) => {
77
- return {
78
- name: 'openclaw-workclaw-cron-add-sync',
79
- label: '智小途同步创建提醒',
80
- description: `【后端同步步骤】将创建定时任务同步到后端。必须在上一步 openclaw-workclaw-cron-add-params 执行后调用此工具完成同步。
81
-
82
- ⚠️ jobId 必须是 cron 工具返回值 {"success": true, "jobId": "xxx"} 中的 jobId 字段!`,
83
- parameters: AddSyncSchema,
84
- execute: async (_toolCallId: string, params: AddSyncParams) => {
85
- const p = params as AddSyncParams
86
-
87
- api.logger.info(`[智小途-同步创建] 开始同步 jobId=${p.jobId} name=${p.name}`)
88
-
89
- // 参数校验
90
- if (!p.jobId) {
91
- api.logger.warn('[智小途-同步创建] 缺少 jobId 参数')
92
- return json({ error: 'jobId 为必填参数' })
93
- }
94
-
95
- // 检查 jobId 是否被错误地设置为 cron 表达式
96
- const jobIdTrimmed = p.jobId.trim()
97
- const parts = jobIdTrimmed.split(/\s+/)
98
- const isCronExpression = parts.length >= 5 && parts.length <= 6 && jobIdTrimmed.includes('*')
99
-
100
- if (isCronExpression) {
101
- api.logger.error(`[智小途-同步创建] jobId 格式错误!jobId=${p.jobId},看起来像 cron 表达式`)
102
- return json({
103
- error: `jobId="${p.jobId}" 是 cron 表达式,不是任务 ID!jobId 应来自 cron 工具返回值,如 "123456" 或 "abc123"`,
104
- })
105
- }
106
-
107
- if (!p.name) {
108
- api.logger.warn('[智小途-同步创建] 缺少 name 参数')
109
- return json({ error: 'name 为必填参数' })
110
- }
111
- if (!p.message) {
112
- api.logger.warn('[智小途-同步创建] 缺少 message 参数')
113
- return json({ error: 'message 为必填参数' })
114
- }
115
-
116
- // 从 ctx 获取必要参数
117
- const accountId = ctx?.agentAccountId
118
- if (!accountId) {
119
- api.logger.warn('[智小途-同步创建] 无法获取账户 ID')
120
- return json({ error: '无法获取账户 ID(accountId),请确保已配置账户' })
121
- }
122
-
123
- const accountConfig = resolveWorkclawAccountWithCache({
124
- cfg: ctx.config,
125
- accountId,
126
- })
127
-
128
- if (accountConfig.configured) {
129
- try {
130
- const channelAgentId = String(accountConfig.config.agentId)
131
- api.logger.info(`[智小途-同步创建] accountId=${accountId} channelAgentId=${channelAgentId}`)
132
- const result = await callCronJobAdd(api, accountId, {
133
- jobId: p.jobId,
134
- name: p.name,
135
- kind: p.kind,
136
- expr: p.expr,
137
- message: p.message,
138
- messageId: channelAgentId,
139
- })
140
-
141
- if (result.success) {
142
- api.logger.info(`[智小途-同步创建] 后端同步成功 jobId=${p.jobId}`)
143
- return json({
144
- code: 0,
145
- message: '定时任务已创建并同步到后端',
146
- data: {
147
- jobId: p.jobId,
148
- name: p.name,
149
- message: p.message,
150
- backendSynced: true,
151
- },
152
- })
153
- }
154
- else {
155
- api.logger.error(`[智小途-同步创建] 后端同步失败 ${result.error}`)
156
- return json({
157
- code: -1,
158
- error: result.error || '后端同步失败',
159
- data: { jobId: p.jobId, name: p.name },
160
- })
161
- }
162
- }
163
- catch (error: any) {
164
- api.logger.error(`[智小途-同步创建] 后端同步异常 ${error.message}`)
165
- return json({
166
- code: -1,
167
- error: error.message,
168
- data: { jobId: p.jobId, name: p.name },
169
- })
170
- }
171
- }
172
- else {
173
- api.logger.error(`[智小途-同步创建] 无法获取渠道配置,accountId=${accountId}`)
174
- return json({ error: '无法获取渠道配置,请检查账户配置' })
175
- }
176
- },
177
- }
178
- }
179
- }
180
-
181
- /**
182
- * 注册同步创建定时任务到后端工具
183
- */
184
- export function registerOpenclawWorkclawCronAddSyncTool(api: OpenClawPluginApi): void {
185
- (api.registerTool as any)(getOpenclawWorkclawCronAddSyncTool(api), {
186
- name: 'openclaw-workclaw-cron-add-sync',
187
- })
188
- }