@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,127 +0,0 @@
1
- /**
2
- * 智小途定时任务工具 - 同步删除定时任务到后端
3
- */
4
-
5
- import type { OpenClawPluginApi } from 'openclaw/plugin-sdk'
6
- import { resolveWorkclawAccountWithCache } from '../../../../accounts.js'
7
- import { callCronJobRemove } from '../../api/index.js'
8
-
9
- /**
10
- * 同步删除定时任务参数
11
- */
12
- export interface RemoveSyncParams {
13
- jobId: string
14
- }
15
-
16
- /**
17
- * 参数 Schema 定义
18
- */
19
- const RemoveSyncSchema = {
20
- type: 'object',
21
- properties: {
22
- jobId: {
23
- type: 'string',
24
- description: `OpenClaw 任务 ID(必须是数字或字符串,不是 cron 表达式)`,
25
- },
26
- },
27
- required: ['jobId'],
28
- } as const
29
-
30
- /**
31
- * 构造工具返回结果
32
- */
33
- function json(data: unknown): any {
34
- return {
35
- content: [{ type: 'text' as const, text: JSON.stringify(data, null, 2) }],
36
- details: data,
37
- }
38
- }
39
-
40
- /**
41
- * 获取同步删除定时任务到后端工具
42
- */
43
- function getOpenclawWorkclawCronRemoveSyncTool(api: OpenClawPluginApi) {
44
- return (ctx: any) => {
45
- return {
46
- name: 'openclaw-workclaw-cron-remove-sync',
47
- label: '智小途同步删除提醒',
48
- description: '【后端同步步骤】将删除定时任务同步到后端。必须在上一步 openclaw-workclaw-cron-remove-params 执行后调用此工具完成同步。',
49
- parameters: RemoveSyncSchema,
50
- execute: async (_toolCallId: string, params: RemoveSyncParams) => {
51
- const p = params as RemoveSyncParams
52
-
53
- api.logger.info(`[智小途-同步删除] 开始同步 jobId=${p.jobId}`)
54
-
55
- // 参数校验
56
- if (!p.jobId) {
57
- api.logger.warn('[智小途-同步删除] 缺少 jobId 参数')
58
- return json({ error: 'jobId 为必填参数' })
59
- }
60
-
61
- // 从 ctx 获取必要参数
62
- const accountId = ctx?.agentAccountId
63
- if (!accountId) {
64
- api.logger.warn('[智小途-同步删除] 无法获取账户 ID')
65
- return json({ error: '无法获取账户 ID(accountId),请确保已配置账户' })
66
- }
67
-
68
- const accountConfig = resolveWorkclawAccountWithCache({
69
- cfg: ctx.config,
70
- accountId,
71
- })
72
-
73
- if (accountConfig.configured) {
74
- try {
75
- const channelAgentId = String(accountConfig.config.agentId)
76
- api.logger.info(`[智小途-同步删除] accountId=${accountId} channelAgentId=${channelAgentId}`)
77
-
78
- const result = await callCronJobRemove(api, accountId, {
79
- jobId: p.jobId,
80
- })
81
-
82
- if (result.success) {
83
- api.logger.info(`[智小途-同步删除] 后端同步成功 jobId=${p.jobId}`)
84
- return json({
85
- code: 0,
86
- message: '定时任务已删除并同步到后端',
87
- data: {
88
- jobId: p.jobId,
89
- backendSynced: true,
90
- },
91
- })
92
- }
93
- else {
94
- api.logger.error(`[智小途-同步删除] 后端同步失败 ${result.error}`)
95
- return json({
96
- code: -1,
97
- error: result.error || '后端同步失败',
98
- data: { jobId: p.jobId },
99
- })
100
- }
101
- }
102
- catch (error: any) {
103
- api.logger.error(`[智小途-同步删除] 后端同步异常 ${error.message}`)
104
- return json({
105
- code: -1,
106
- error: error.message,
107
- data: { jobId: p.jobId },
108
- })
109
- }
110
- }
111
- else {
112
- api.logger.error(`[智小途-同步删除] 无法获取渠道配置,accountId=${accountId}`)
113
- return json({ error: '无法获取渠道配置,请检查账户配置' })
114
- }
115
- },
116
- }
117
- }
118
- }
119
-
120
- /**
121
- * 注册同步删除定时任务到后端工具
122
- */
123
- export function registerOpenclawWorkclawCronRemoveSyncTool(api: OpenClawPluginApi): void {
124
- (api.registerTool as any)(getOpenclawWorkclawCronRemoveSyncTool(api), {
125
- name: 'openclaw-workclaw-cron-remove-sync',
126
- })
127
- }
@@ -1,195 +0,0 @@
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
- }
@@ -1,161 +0,0 @@
1
- /**
2
- * 智小途定时任务工具 - 同步修改定时任务到后端
3
- */
4
-
5
- import type { OpenClawPluginApi } from 'openclaw/plugin-sdk'
6
- import { resolveWorkclawAccountWithCache } from '../../../../accounts.js'
7
- import { callCronJobUpdate } from '../../api/index.js'
8
-
9
- /**
10
- * 同步修改定时任务参数
11
- */
12
- export interface UpdateSyncParams {
13
- jobId: string
14
- name: string
15
- kind: 'cron'
16
- expr?: string
17
- message: string
18
- }
19
-
20
- /**
21
- * 参数 Schema 定义
22
- */
23
- const UpdateSyncSchema = {
24
- type: 'object',
25
- properties: {
26
- jobId: {
27
- type: 'string',
28
- description: `OpenClaw 任务 ID(必须是数字或字符串,不是 cron 表达式)`,
29
- },
30
- name: {
31
- type: 'string',
32
- description: '任务名称',
33
- },
34
- kind: {
35
- type: 'string',
36
- description: '任务类型(仅支持 cron)',
37
- enum: ['cron'],
38
- },
39
- expr: {
40
- type: 'string',
41
- description: 'Cron 表达式(kind=cron 时必填)',
42
- },
43
- message: {
44
- type: 'string',
45
- description: '提醒消息',
46
- },
47
- },
48
- required: ['jobId', 'name', 'kind', 'message'],
49
- } as const
50
-
51
- /**
52
- * 构造工具返回结果
53
- */
54
- function json(data: unknown): any {
55
- return {
56
- content: [{ type: 'text' as const, text: JSON.stringify(data, null, 2) }],
57
- details: data,
58
- }
59
- }
60
-
61
- /**
62
- * 获取同步修改定时任务到后端工具
63
- */
64
- function getOpenclawWorkclawCronUpdateSyncTool(api: OpenClawPluginApi) {
65
- return (ctx: any) => {
66
- return {
67
- name: 'openclaw-workclaw-cron-update-sync',
68
- label: '智小途同步修改提醒',
69
- description: '将修改定时任务同步到后端。在 cron 工具修改任务后调用此工具同步后端。',
70
- parameters: UpdateSyncSchema,
71
- execute: async (_toolCallId: string, params: UpdateSyncParams) => {
72
- const p = params as UpdateSyncParams
73
-
74
- api.logger.info(`[智小途-同步修改] 开始同步 jobId=${p.jobId} name=${p.name}`)
75
-
76
- // 参数校验
77
- if (!p.jobId) {
78
- api.logger.warn('[智小途-同步修改] 缺少 jobId 参数')
79
- return json({ error: 'jobId 为必填参数' })
80
- }
81
- if (!p.name) {
82
- api.logger.warn('[智小途-同步修改] 缺少 name 参数')
83
- return json({ error: 'name 为必填参数' })
84
- }
85
- if (!p.message) {
86
- api.logger.warn('[智小途-同步修改] 缺少 message 参数')
87
- return json({ error: 'message 为必填参数' })
88
- }
89
-
90
- // 从 ctx 获取必要参数
91
- const accountId = ctx?.agentAccountId
92
- const channelUserId = ctx?.From
93
-
94
- // 校验必要参数
95
- if (!accountId) {
96
- api.logger.warn('[智小途-同步修改] 无法获取账户 ID')
97
- return json({ error: '无法获取账户 ID(accountId),请确保已配置账户' })
98
- }
99
-
100
- const accountConfig = resolveWorkclawAccountWithCache({
101
- cfg: ctx.config,
102
- accountId,
103
- })
104
-
105
- const channelAgentId = accountConfig.configured ? String(accountConfig.config.agentId) : '0'
106
-
107
- api.logger.info(`[智小途-同步修改] accountId=${accountId} channelUserId=${channelUserId} channelAgentId=${channelAgentId}`)
108
-
109
- try {
110
- const result = await callCronJobUpdate(api, accountId, {
111
- jobId: p.jobId,
112
- name: p.name,
113
- kind: p.kind,
114
- expr: p.expr,
115
- message: p.message,
116
- agentId: channelAgentId,
117
- })
118
-
119
- if (result.success) {
120
- api.logger.info(`[智小途-同步修改] 后端同步成功 jobId=${p.jobId}`)
121
- return json({
122
- code: 0,
123
- message: '定时任务已修改并同步到后端',
124
- data: {
125
- jobId: p.jobId,
126
- name: p.name,
127
- message: p.message,
128
- backendSynced: true,
129
- },
130
- })
131
- }
132
- else {
133
- api.logger.error(`[智小途-同步修改] 后端同步失败 ${result.error}`)
134
- return json({
135
- code: -1,
136
- error: result.error || '后端同步失败',
137
- data: { jobId: p.jobId, name: p.name },
138
- })
139
- }
140
- }
141
- catch (error: any) {
142
- api.logger.error(`[智小途-同步修改] 后端同步异常 ${error.message}`)
143
- return json({
144
- code: -1,
145
- error: error.message,
146
- data: { jobId: p.jobId, name: p.name },
147
- })
148
- }
149
- },
150
- }
151
- }
152
- }
153
-
154
- /**
155
- * 注册同步修改定时任务到后端工具
156
- */
157
- export function registerOpenclawWorkclawCronUpdateSyncTool(api: OpenClawPluginApi): void {
158
- (api.registerTool as any)(getOpenclawWorkclawCronUpdateSyncTool(api), {
159
- name: 'openclaw-workclaw-cron-update-sync',
160
- })
161
- }
@@ -1,55 +0,0 @@
1
- /**
2
- * 智小途定时任务工具 - 类型定义
3
- */
4
-
5
- /**
6
- * 后端接口请求体
7
- */
8
- export interface CronJobPayload {
9
- agentId: string
10
- messageId: string
11
- clawJobId: string
12
- name: string
13
- kind: 'cron'
14
- expr?: string
15
- message: string
16
- }
17
-
18
- /**
19
- * OpenClaw cron 工具参数
20
- */
21
- export interface OpenClawCronParams {
22
- action: 'add' | 'list' | 'remove' | 'update' | 'enable' | 'disable'
23
- job?: {
24
- agentId: string
25
- name: string
26
- schedule: {
27
- kind: 'cron'
28
- expr: string
29
- tz: string
30
- }
31
- sessionTarget: 'isolated'
32
- wakeMode: 'now'
33
- deleteAfterRun?: boolean
34
- payload: {
35
- kind: 'agentTurn'
36
- message: string
37
- }
38
- delivery: {
39
- mode: 'announce'
40
- channel: string
41
- to: string
42
- }
43
- }
44
- jobId?: string
45
- }
46
-
47
- /**
48
- * 工具返回结果
49
- */
50
- export interface CronToolResult {
51
- success: boolean
52
- jobId?: string
53
- jobs?: any[]
54
- error?: string
55
- }
@@ -1,141 +0,0 @@
1
- /**
2
- * 智小途定时任务工具 - 工具函数
3
- */
4
-
5
- /**
6
- * 解析相对时间字符串
7
- * 支持格式:5m, 1h, 1h30m, 2d, 30s, 1d2h30m 等
8
- * @param timeStr - 时间字符串
9
- * @returns 毫秒数,解析失败返回 null
10
- */
11
- export function parseRelativeTime(timeStr: string): number | null {
12
- const s = timeStr.trim().toLowerCase()
13
-
14
- if (/^\d+$/.test(s)) {
15
- return Number.parseInt(s, 10) * 60_000
16
- }
17
-
18
- let totalMs = 0
19
- let matched = false
20
- const regex = /(\d+(?:\.\d+)?)\s*([dhms])/g
21
-
22
- let match: RegExpExecArray | null
23
- // eslint-disable-next-line no-cond-assign
24
- while ((match = regex.exec(s)) !== null) {
25
- matched = true
26
- const value = Number.parseFloat(match[1])
27
- const unit = match[2]
28
- switch (unit) {
29
- case 'd': totalMs += value * 86_400_000
30
- break
31
- case 'h': totalMs += value * 3_600_000
32
- break
33
- case 'm': totalMs += value * 60_000
34
- break
35
- case 's': totalMs += value * 1_000
36
- break
37
- }
38
- }
39
-
40
- return matched ? Math.round(totalMs) : null
41
- }
42
-
43
- /**
44
- * 判断是否为 cron 表达式
45
- * @param timeStr - 时间字符串
46
- * @returns 是否为 cron 表达式
47
- */
48
- export function isCronExpression(timeStr: string): boolean {
49
- const parts = timeStr.trim().split(/\s+/)
50
- return parts.length >= 3 && parts.length <= 6
51
- }
52
-
53
- /**
54
- * 校验 cron 表达式格式
55
- * @param timeStr - 时间字符串
56
- * @returns 校验结果和错误信息
57
- */
58
- export function validateCronExpression(timeStr: string): { valid: boolean, error?: string } {
59
- const parts = timeStr.trim().split(/\s+/)
60
-
61
- if (parts.length < 3 || parts.length > 6) {
62
- return { valid: false, error: `无效的 cron 表达式:字段数量不正确(期望 3-6 个字段,实际 ${parts.length} 个)` }
63
- }
64
-
65
- const patterns = [
66
- /^(\*|[0-5]?\d(-[0-5]?\d)?(\/[0-5]?\d)?|L(-[0-5]?\d)?|W?)$/,
67
- /^(\*|[0-5]?\d(-[0-5]?\d)?(\/[0-5]?\d)?|L(-[0-5]?\d)?|W?)$/,
68
- /^(\*|[01]?\d|2[0-3](-[01]?\d|2[0-3])?(\/\d|[01]?\d|2[0-3])?|L(-[01]?\d|2[0-3])?|W)?$/,
69
- /^(\*|1[0-2]|0?[1-9](-[1-9]|0?[1-9])?(\/[1-9]|0?[1-9])?|L(-1[0-2]|0?[1-9])?|W)?$/,
70
- /^([*LW]|[0-6](-[0-6])?(\/[0-6])?|L-[0-6])?$/,
71
- /^(\*|L|(\*\/)?\d{1,2})?$/,
72
- ]
73
-
74
- const fieldNames = ['秒', '分钟', '小时', '日期', '月份', '星期']
75
-
76
- for (let i = 0; i < parts.length && i < patterns.length; i++) {
77
- const part = parts[i].trim()
78
- const offset = parts.length - patterns.length
79
-
80
- if (i < offset)
81
- continue
82
-
83
- if (!patterns[i].test(part)) {
84
- return { valid: false, error: `无效的 cron 表达式:${fieldNames[i]}字段 "${part}" 格式不正确` }
85
- }
86
- }
87
-
88
- return { valid: true }
89
- }
90
-
91
- /**
92
- * 校验时间格式(相对时间或 cron 表达式)
93
- * @param timeStr - 时间字符串
94
- * @returns 校验结果和错误信息
95
- */
96
- export function validateTimeFormat(timeStr: string): { valid: boolean, error?: string } {
97
- if (!timeStr || typeof timeStr !== 'string' || timeStr.trim() === '') {
98
- return { valid: false, error: '时间参数不能为空' }
99
- }
100
-
101
- const trimmed = timeStr.trim()
102
-
103
- if (trimmed.startsWith('+') || /^\d+$/.test(trimmed) || /^\d+[dhms]/.test(trimmed)) {
104
- const relativeMs = parseRelativeTime(trimmed)
105
- if (relativeMs === null) {
106
- return { valid: false, error: `无法解析相对时间 "${trimmed}",支持的格式:5m、1h、1h30m、2d、30s 等` }
107
- }
108
- if (relativeMs < 30_000) {
109
- return { valid: false, error: '提醒时间不能少于 30 秒' }
110
- }
111
- return { valid: true }
112
- }
113
-
114
- if (isCronExpression(trimmed)) {
115
- return validateCronExpression(trimmed)
116
- }
117
-
118
- return { valid: false, error: `无法解析时间 "${trimmed}",请使用相对时间(如 5m、1h)或 cron 表达式(如 0 8 * * *)` }
119
- }
120
-
121
- /**
122
- * 将相对时间转换为标准 cron 表达式
123
- * @param timeStr - 相对时间字符串,如 "5m", "1h", "2h30m"
124
- * @returns 标准 cron 表达式(秒 分 时 日 月 星期),格式为 "SS MM HH DD MM *"
125
- */
126
- export function relativeToCron(timeStr: string): string {
127
- const delayMs = parseRelativeTime(timeStr)
128
- if (delayMs === null) {
129
- return timeStr
130
- }
131
-
132
- const futureTime = new Date(Date.now() + delayMs)
133
-
134
- const seconds = futureTime.getSeconds()
135
- const minutes = futureTime.getMinutes()
136
- const hours = futureTime.getHours()
137
- const dayOfMonth = futureTime.getDate()
138
- const month = futureTime.getMonth() + 1
139
-
140
- return `${seconds} ${minutes} ${hours} ${dayOfMonth} ${month} *`
141
- }