@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.
Files changed (147) hide show
  1. package/README.md +364 -325
  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 +263 -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 +28 -0
  20. package/dist/src/channel.d.ts +11 -0
  21. package/dist/src/channel.js +198 -0
  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/dist/src/gateway/agent-handlers.js +433 -0
  28. package/dist/src/gateway/config-writer.d.ts +71 -0
  29. package/dist/src/gateway/config-writer.js +312 -0
  30. package/dist/src/gateway/message-context.d.ts +76 -0
  31. package/dist/src/gateway/message-context.js +499 -0
  32. package/dist/src/gateway/message-dispatcher.d.ts +19 -0
  33. package/dist/src/gateway/message-dispatcher.js +512 -0
  34. package/dist/src/gateway/reconnect.d.ts +27 -0
  35. package/dist/src/gateway/reconnect.js +206 -0
  36. package/dist/src/gateway/skills-handler.d.ts +29 -0
  37. package/dist/src/gateway/skills-handler.js +576 -0
  38. package/dist/src/gateway/skills-list-handler.d.ts +27 -0
  39. package/dist/src/gateway/skills-list-handler.js +233 -0
  40. package/dist/src/gateway/tools-list-handler.d.ts +30 -0
  41. package/dist/src/gateway/tools-list-handler.js +101 -0
  42. package/dist/src/gateway/workclaw-gateway.d.ts +14 -0
  43. package/dist/src/gateway/workclaw-gateway.js +223 -0
  44. package/dist/src/media/upload.d.ts +13 -0
  45. package/dist/src/media/upload.js +125 -0
  46. package/dist/src/outbound/index.d.ts +36 -0
  47. package/dist/src/outbound/index.js +123 -0
  48. package/dist/src/outbound/workclaw-sender.d.ts +36 -0
  49. package/dist/src/outbound/workclaw-sender.js +95 -0
  50. package/dist/src/runtime.d.ts +116 -0
  51. package/dist/src/runtime.js +374 -0
  52. package/dist/src/secret-contract-api.d.ts +4 -0
  53. package/dist/src/secret-contract-api.js +4 -0
  54. package/dist/src/send.d.ts +1 -0
  55. package/dist/src/send.js +1 -0
  56. package/dist/src/setup-api.d.ts +3 -0
  57. package/dist/src/setup-api.js +3 -0
  58. package/dist/src/setup-core.d.ts +3 -0
  59. package/dist/src/setup-core.js +13 -0
  60. package/dist/src/setup-surface.d.ts +7 -0
  61. package/dist/src/setup-surface.js +363 -0
  62. package/dist/src/tools/openclaw-workclaw-cron/api/index.d.ts +93 -0
  63. package/dist/src/tools/openclaw-workclaw-cron/api/index.js +209 -0
  64. package/dist/src/tools/openclaw-workclaw-cron/index.d.ts +10 -0
  65. package/{src/tools/openclaw-workclaw-cron/index.ts → dist/src/tools/openclaw-workclaw-cron/index.js} +33 -39
  66. package/dist/src/tools/openclaw-workclaw-cron/src/add/params.d.ts +16 -0
  67. package/dist/src/tools/openclaw-workclaw-cron/src/add/params.js +152 -0
  68. package/dist/src/tools/openclaw-workclaw-cron/src/add/sync.d.ts +18 -0
  69. package/dist/src/tools/openclaw-workclaw-cron/src/add/sync.js +162 -0
  70. package/dist/src/tools/openclaw-workclaw-cron/src/disable/params.d.ts +14 -0
  71. package/dist/src/tools/openclaw-workclaw-cron/src/disable/params.js +80 -0
  72. package/dist/src/tools/openclaw-workclaw-cron/src/disable/sync.d.ts +14 -0
  73. package/dist/src/tools/openclaw-workclaw-cron/src/disable/sync.js +107 -0
  74. package/dist/src/tools/openclaw-workclaw-cron/src/enable/params.d.ts +14 -0
  75. package/dist/src/tools/openclaw-workclaw-cron/src/enable/params.js +80 -0
  76. package/dist/src/tools/openclaw-workclaw-cron/src/enable/sync.d.ts +14 -0
  77. package/dist/src/tools/openclaw-workclaw-cron/src/enable/sync.js +107 -0
  78. package/dist/src/tools/openclaw-workclaw-cron/src/notify/sync.d.ts +17 -0
  79. package/dist/src/tools/openclaw-workclaw-cron/src/notify/sync.js +127 -0
  80. package/dist/src/tools/openclaw-workclaw-cron/src/remove/params.d.ts +14 -0
  81. package/dist/src/tools/openclaw-workclaw-cron/src/remove/params.js +87 -0
  82. package/dist/src/tools/openclaw-workclaw-cron/src/remove/sync.d.ts +14 -0
  83. package/dist/src/tools/openclaw-workclaw-cron/src/remove/sync.js +107 -0
  84. package/dist/src/tools/openclaw-workclaw-cron/src/update/params.d.ts +17 -0
  85. package/dist/src/tools/openclaw-workclaw-cron/src/update/params.js +164 -0
  86. package/dist/src/tools/openclaw-workclaw-cron/src/update/sync.d.ts +18 -0
  87. package/dist/src/tools/openclaw-workclaw-cron/src/update/sync.js +135 -0
  88. package/dist/src/tools/openclaw-workclaw-cron/types/index.d.ts +52 -0
  89. package/dist/src/tools/openclaw-workclaw-cron/types/index.js +4 -0
  90. package/dist/src/tools/openclaw-workclaw-cron/utils/index.d.ts +40 -0
  91. package/dist/src/tools/openclaw-workclaw-cron/utils/index.js +122 -0
  92. package/dist/src/tools/openclaw-workclaw-system/index.d.ts +10 -0
  93. package/{src/tools/openclaw-workclaw-system/index.ts → dist/src/tools/openclaw-workclaw-system/index.js} +15 -17
  94. package/dist/src/tools/openclaw-workclaw-system/src/get/index.d.ts +8 -0
  95. package/dist/src/tools/openclaw-workclaw-system/src/get/index.js +64 -0
  96. package/dist/src/tools/openclaw-workclaw-system/src/token/index.d.ts +8 -0
  97. package/dist/src/tools/openclaw-workclaw-system/src/token/index.js +78 -0
  98. package/dist/src/types.d.ts +39 -0
  99. package/dist/src/types.js +1 -0
  100. package/dist/src/utils/content.d.ts +15 -0
  101. package/dist/src/utils/content.js +38 -0
  102. package/openclaw.plugin.json +1 -0
  103. package/package.json +62 -42
  104. package/skills/openclaw-workclaw-cron/SKILL.md +45 -28
  105. package/index.ts +0 -302
  106. package/src/accounts.ts +0 -287
  107. package/src/api/accounts-api.ts +0 -157
  108. package/src/api/prompts-api.ts +0 -123
  109. package/src/api/session-api.ts +0 -247
  110. package/src/api/skills-api.ts +0 -74
  111. package/src/api/workspace.ts +0 -43
  112. package/src/channel.ts +0 -227
  113. package/src/config-schema.ts +0 -110
  114. package/src/connection/workclaw-client.ts +0 -656
  115. package/src/gateway/agent-handlers.ts +0 -557
  116. package/src/gateway/config-writer.ts +0 -311
  117. package/src/gateway/message-context.ts +0 -422
  118. package/src/gateway/message-dispatcher.ts +0 -601
  119. package/src/gateway/reconnect.ts +0 -149
  120. package/src/gateway/skills-handler.ts +0 -805
  121. package/src/gateway/skills-list-handler.ts +0 -332
  122. package/src/gateway/tools-list-handler.ts +0 -162
  123. package/src/gateway/workclaw-gateway.ts +0 -525
  124. package/src/media/upload.ts +0 -168
  125. package/src/outbound/index.ts +0 -183
  126. package/src/outbound/workclaw-sender.ts +0 -157
  127. package/src/runtime.ts +0 -400
  128. package/src/send.ts +0 -1
  129. package/src/tools/openclaw-workclaw-cron/api/index.ts +0 -326
  130. package/src/tools/openclaw-workclaw-cron/src/add/params.ts +0 -176
  131. package/src/tools/openclaw-workclaw-cron/src/add/sync.ts +0 -188
  132. package/src/tools/openclaw-workclaw-cron/src/disable/params.ts +0 -100
  133. package/src/tools/openclaw-workclaw-cron/src/disable/sync.ts +0 -127
  134. package/src/tools/openclaw-workclaw-cron/src/enable/params.ts +0 -100
  135. package/src/tools/openclaw-workclaw-cron/src/enable/sync.ts +0 -127
  136. package/src/tools/openclaw-workclaw-cron/src/notify/sync.ts +0 -148
  137. package/src/tools/openclaw-workclaw-cron/src/remove/params.ts +0 -109
  138. package/src/tools/openclaw-workclaw-cron/src/remove/sync.ts +0 -127
  139. package/src/tools/openclaw-workclaw-cron/src/update/params.ts +0 -197
  140. package/src/tools/openclaw-workclaw-cron/src/update/sync.ts +0 -161
  141. package/src/tools/openclaw-workclaw-cron/types/index.ts +0 -55
  142. package/src/tools/openclaw-workclaw-cron/utils/index.ts +0 -141
  143. package/src/tools/openclaw-workclaw-system/src/get/index.ts +0 -77
  144. package/src/tools/openclaw-workclaw-system/src/token/index.ts +0 -93
  145. package/src/types.ts +0 -60
  146. package/src/utils/content.ts +0 -40
  147. package/tsconfig.json +0 -11
@@ -1,127 +0,0 @@
1
- /**
2
- * 智小途定时任务工具 - 同步删除定时任务到后端
3
- */
4
-
5
- import type { OpenClawPluginApi } from 'openclaw/plugin-sdk'
6
- import { resolveOpenclawWorkclawAccount } 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',
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 = resolveOpenclawWorkclawAccount({
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,197 +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',
31
- },
32
- time: {
33
- type: 'string',
34
- description:
35
- '时间描述。相对时间如 "5m"、"1h";cron 表达式如 "0 8 * * *"',
36
- },
37
- name: {
38
- type: 'string',
39
- description: '任务名称',
40
- },
41
- message: {
42
- type: 'string',
43
- description: '提醒内容',
44
- },
45
- },
46
- required: ['jobId', 'time', 'name', 'message'],
47
- } as const
48
-
49
- /**
50
- * 构造工具返回结果
51
- */
52
- function json(data: unknown): any {
53
- return {
54
- content: [{ type: 'text' as const, text: JSON.stringify(data, null, 2) }],
55
- details: data,
56
- }
57
- }
58
-
59
- /**
60
- * 获取生成修改定时任务参数工具
61
- */
62
- function getOpenclawWorkclawCronUpdateParamsTool(api: OpenClawPluginApi) {
63
- return (ctx: any) => {
64
- return {
65
- name: 'openclaw-workclaw-cron-update-params',
66
- label: '智小途生成修改提醒参数',
67
- description: `【必须执行的核心步骤】生成修改提醒的 cronParams 参数。
68
-
69
- 📋 工作流程(必须按顺序执行):
70
- 1. ✅ 调用此工具获取 cronParams 参数
71
- 2. ✅ 使用返回的 cronParams 调用 OpenClaw 的 cron 工具
72
- 3. ✅ 【关键步骤】必须调用 openclaw-workclaw-cron-update-sync 同步到后端
73
-
74
- 🔒 强制规则(必须遵守):
75
- - ✅ 生成的 cronParams 中 schedule.kind 必须是 "cron"
76
- - ✅ 调用 cron 工具时必须使用 --cron 参数
77
- - ❌ 严禁将 cron 表达式转换为 --at 绝对时间参数
78
- - ❌ 严禁将 kind: "cron" 转换为其他类型
79
- - ✅ 使用 --session isolated + --message(agentTurn),禁止使用 --system-event
80
-
81
- ⚠️ 重要提醒:
82
- - time 参数支持相对时间(如 "10m"、"1h"),内部会转换为 cron 表达式
83
- - 最终执行的 CLI 命令必须是 --cron 参数(绝对禁止使用 --at)
84
- - 必须从 cron 工具返回值中确认更新成功
85
- - 如果不执行步骤3,后端的定时任务信息将无法同步更新!
86
- `,
87
- parameters: UpdateParamsSchema,
88
- execute: async (_toolCallId: string, params: UpdateParamsParams) => {
89
- const p = params as UpdateParamsParams
90
-
91
- api.logger.info(`[智小途-生成修改参数] 开始处理 jobId=${p.jobId} name=${p.name} time=${p.time}`)
92
-
93
- // 参数校验
94
- if (!p.jobId) {
95
- api.logger.warn('[智小途-生成修改参数] 缺少 jobId 参数')
96
- return json({ error: 'jobId 为必填参数' })
97
- }
98
- if (!p.time) {
99
- api.logger.warn('[智小途-生成修改参数] 缺少时间参数')
100
- return json({ error: 'time(时间)为必填参数' })
101
- }
102
- if (!p.name) {
103
- api.logger.warn('[智小途-生成修改参数] 缺少任务名称参数')
104
- return json({ error: 'name(任务名称)为必填参数' })
105
- }
106
- if (!p.message) {
107
- api.logger.warn('[智小途-生成修改参数] 缺少提醒内容参数')
108
- return json({ error: 'message(提醒内容)为必填参数' })
109
- }
110
-
111
- // 从 ctx 获取必要参数
112
- const accountId = ctx?.agentAccountId
113
- const name = p.name
114
- const message = p.message
115
- const time = p.time
116
-
117
- // 校验必要参数
118
- if (!accountId) {
119
- api.logger.warn('[智小途-生成修改参数] 无法获取账户 ID')
120
- return json({ error: '无法获取账户 ID(accountId),请确保已配置账户' })
121
- }
122
-
123
- api.logger.info(`[智小途-生成修改参数] accountId=${accountId} jobId=${p.jobId}`)
124
-
125
- // 校验时间格式
126
- const timeValidation = validateTimeFormat(time)
127
- if (!timeValidation.valid) {
128
- api.logger.warn(`[智小途-生成修改参数] 时间格式校验失败: ${timeValidation.error}`)
129
- return json({ error: timeValidation.error })
130
- }
131
-
132
- // 判断时间类型
133
- const isCron = isCronExpression(time)
134
- let isOneTime = false
135
- let cronExpr: string
136
-
137
- // 如果是相对时间(5m、1h 等),转换为绝对时间的 cron 表达式
138
- if (!isCron) {
139
- isOneTime = true
140
- cronExpr = relativeToCron(time.trim())
141
- api.logger.info(`[智小途-生成修改参数] 相对时间转换为绝对时间 cron 表达式 cronExpr=${cronExpr}`)
142
- }
143
- else {
144
- cronExpr = time.trim()
145
- }
146
-
147
- const cronParams = {
148
- action: 'update' as const,
149
- jobId: p.jobId,
150
- job: {
151
- name,
152
- schedule: {
153
- kind: 'cron' as const,
154
- expr: cronExpr,
155
- tz: 'Asia/Shanghai',
156
- },
157
- sessionTarget: 'isolated',
158
- wakeMode: 'now' as const,
159
- deleteAfterRun: isOneTime ? true : undefined,
160
- payload: {
161
- kind: 'agentTurn' as const,
162
- message,
163
- },
164
- delivery: {
165
- mode: 'announce',
166
- channel: 'openclaw-workclaw',
167
- },
168
- },
169
- }
170
-
171
- api.logger.info(`[智小途-生成修改参数] 构建 cron 参数 cronParams=${JSON.stringify(cronParams)}`)
172
-
173
- return json({
174
- cronParams,
175
- meta: {
176
- accountId,
177
- jobId: p.jobId,
178
- name,
179
- kind: 'cron',
180
- expr: cronExpr,
181
- message,
182
- },
183
- summary: `✅ 提醒已修改: "${name}" (${time})`,
184
- })
185
- },
186
- }
187
- }
188
- }
189
-
190
- /**
191
- * 注册生成修改定时任务参数工具
192
- */
193
- export function registerOpenclawWorkclawCronUpdateParamsTool(api: OpenClawPluginApi): void {
194
- (api.registerTool as any)(getOpenclawWorkclawCronUpdateParamsTool(api), {
195
- name: 'openclaw-workclaw-cron-update-params',
196
- })
197
- }
@@ -1,161 +0,0 @@
1
- /**
2
- * 智小途定时任务工具 - 同步修改定时任务到后端
3
- */
4
-
5
- import type { OpenClawPluginApi } from 'openclaw/plugin-sdk'
6
- import { resolveOpenclawWorkclawAccount } 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',
29
- },
30
- name: {
31
- type: 'string',
32
- description: '任务名称',
33
- },
34
- kind: {
35
- type: 'string',
36
- description: '任务类型:at 或 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 = resolveOpenclawWorkclawAccount({
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
- }