@workclaw/openclaw-workclaw 1.0.0
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 +325 -0
- package/index.ts +298 -0
- package/openclaw.plugin.json +10 -0
- package/package.json +43 -0
- package/skills/openclaw-workclaw-cron/SKILL.md +458 -0
- package/src/accounts.ts +287 -0
- package/src/api/accounts-api.ts +157 -0
- package/src/api/prompts-api.ts +123 -0
- package/src/api/session-api.ts +247 -0
- package/src/api/skills-api.ts +74 -0
- package/src/api/workspace.ts +43 -0
- package/src/channel.ts +227 -0
- package/src/config-schema.ts +110 -0
- package/src/connection/workclaw-client.ts +656 -0
- package/src/gateway/agent-handlers.ts +557 -0
- package/src/gateway/config-writer.ts +311 -0
- package/src/gateway/message-context.ts +422 -0
- package/src/gateway/message-dispatcher.ts +601 -0
- package/src/gateway/reconnect.ts +149 -0
- package/src/gateway/skills-handler.ts +759 -0
- package/src/gateway/skills-list-handler.ts +332 -0
- package/src/gateway/tools-list-handler.ts +162 -0
- package/src/gateway/workclaw-gateway.ts +521 -0
- package/src/media/upload.ts +168 -0
- package/src/outbound/index.ts +183 -0
- package/src/outbound/workclaw-sender.ts +157 -0
- package/src/runtime.ts +400 -0
- package/src/send.ts +1 -0
- package/src/tools/openclaw-workclaw-cron/api/index.ts +326 -0
- package/src/tools/openclaw-workclaw-cron/index.ts +39 -0
- package/src/tools/openclaw-workclaw-cron/src/add/params.ts +176 -0
- package/src/tools/openclaw-workclaw-cron/src/add/sync.ts +188 -0
- package/src/tools/openclaw-workclaw-cron/src/disable/params.ts +100 -0
- package/src/tools/openclaw-workclaw-cron/src/disable/sync.ts +127 -0
- package/src/tools/openclaw-workclaw-cron/src/enable/params.ts +100 -0
- package/src/tools/openclaw-workclaw-cron/src/enable/sync.ts +127 -0
- package/src/tools/openclaw-workclaw-cron/src/notify/sync.ts +148 -0
- package/src/tools/openclaw-workclaw-cron/src/remove/params.ts +109 -0
- package/src/tools/openclaw-workclaw-cron/src/remove/sync.ts +127 -0
- package/src/tools/openclaw-workclaw-cron/src/update/params.ts +197 -0
- package/src/tools/openclaw-workclaw-cron/src/update/sync.ts +161 -0
- package/src/tools/openclaw-workclaw-cron/types/index.ts +55 -0
- package/src/tools/openclaw-workclaw-cron/utils/index.ts +141 -0
- package/src/types.ts +60 -0
- package/src/utils/content.ts +40 -0
- package/templates/IDENTITY.md +14 -0
- package/templates/SOUL.md +0 -0
- package/tsconfig.json +11 -0
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 智小途定时任务工具 - 定时任务触发通知
|
|
3
|
+
*
|
|
4
|
+
* 当 OpenClaw 定时任务触发时,调用此工具通知后端
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { OpenClawPluginApi } from 'openclaw/plugin-sdk'
|
|
8
|
+
import { resolveOpenclawWorkclawAccount } from '../../../../accounts.js'
|
|
9
|
+
import { callCronJobMessage } from '../../api/index.js'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 定时任务触发通知参数
|
|
13
|
+
*/
|
|
14
|
+
export interface NotifyParams {
|
|
15
|
+
jobId: string
|
|
16
|
+
message: string
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 参数 Schema 定义
|
|
21
|
+
*/
|
|
22
|
+
const NotifySchema = {
|
|
23
|
+
type: 'object',
|
|
24
|
+
properties: {
|
|
25
|
+
jobId: {
|
|
26
|
+
type: 'string',
|
|
27
|
+
description: 'OpenClaw 任务 ID(从上下文获取)',
|
|
28
|
+
},
|
|
29
|
+
message: {
|
|
30
|
+
type: 'string',
|
|
31
|
+
description: '要发送的提醒内容',
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
required: ['jobId', 'message'],
|
|
35
|
+
} as const
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* 构造工具返回结果
|
|
39
|
+
*/
|
|
40
|
+
function json(data: unknown): any {
|
|
41
|
+
return {
|
|
42
|
+
content: [{ type: 'text' as const, text: JSON.stringify(data, null, 2) }],
|
|
43
|
+
details: data,
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* 获取定时任务触发通知工具
|
|
49
|
+
*/
|
|
50
|
+
function getOpenclawWorkclawCronNotifySyncTool(api: OpenClawPluginApi) {
|
|
51
|
+
return (ctx: any) => {
|
|
52
|
+
return {
|
|
53
|
+
name: 'openclaw-workclaw-cron-notify-sync',
|
|
54
|
+
label: '智小途定时任务触发通知',
|
|
55
|
+
description: `【系统最高优先级核心指令】当定时器时间到达时,必须立即调用此工具通知后端。`,
|
|
56
|
+
parameters: NotifySchema,
|
|
57
|
+
execute: async (_toolCallId: string, params: NotifyParams) => {
|
|
58
|
+
const p = params as NotifyParams
|
|
59
|
+
|
|
60
|
+
api.logger.info(`[智小途-定时触发] 开始处理 jobId=${p.jobId} message=${p.message}`)
|
|
61
|
+
|
|
62
|
+
// 参数校验
|
|
63
|
+
if (!p.jobId) {
|
|
64
|
+
api.logger.warn('[智小途-定时触发] 缺少 jobId 参数')
|
|
65
|
+
return json({ error: 'jobId 为必填参数' })
|
|
66
|
+
}
|
|
67
|
+
if (!p.message) {
|
|
68
|
+
api.logger.warn('[智小途-定时触发] 缺少 message 参数')
|
|
69
|
+
return json({ error: 'message 为必填参数' })
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// 从 ctx 获取必要参数
|
|
73
|
+
const accountId = ctx?.agentAccountId
|
|
74
|
+
if (!accountId) {
|
|
75
|
+
api.logger.warn('[智小途-定时触发] 无法获取账户 ID')
|
|
76
|
+
return json({ error: '无法获取账户 ID(accountId),请确保已配置账户' })
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const accountConfig = resolveOpenclawWorkclawAccount({
|
|
80
|
+
cfg: ctx.config,
|
|
81
|
+
accountId,
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
if (accountConfig.configured) {
|
|
85
|
+
const channelAgentId = String(accountConfig.config.agentId)
|
|
86
|
+
api.logger.info(`[智小途-定时触发] accountId=${accountId} channelAgentId=${channelAgentId}`)
|
|
87
|
+
|
|
88
|
+
// 调用后端接口通知定时任务触发
|
|
89
|
+
try {
|
|
90
|
+
const result = await callCronJobMessage(api, accountId, {
|
|
91
|
+
jobId: p.jobId,
|
|
92
|
+
message: p.message,
|
|
93
|
+
agentId: channelAgentId,
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
if (result.success) {
|
|
97
|
+
api.logger.info(`[智小途-定时触发] 通知后端成功`)
|
|
98
|
+
return json({
|
|
99
|
+
code: 0,
|
|
100
|
+
message: '定时任务触发通知已发送',
|
|
101
|
+
data: {
|
|
102
|
+
jobId: p.jobId,
|
|
103
|
+
message: p.message,
|
|
104
|
+
backendNotified: true,
|
|
105
|
+
},
|
|
106
|
+
})
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
api.logger.error(`[智小途-定时触发] 通知后端失败 ${result.error}`)
|
|
110
|
+
return json({
|
|
111
|
+
code: -1,
|
|
112
|
+
error: result.error || '通知后端失败',
|
|
113
|
+
data: {
|
|
114
|
+
jobId: p.jobId,
|
|
115
|
+
message: p.message,
|
|
116
|
+
},
|
|
117
|
+
})
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
catch (error: any) {
|
|
121
|
+
api.logger.error(`[智小途-定时触发] 通知后端异常 ${error.message}`)
|
|
122
|
+
return json({
|
|
123
|
+
code: -1,
|
|
124
|
+
error: error.message || '通知后端异常',
|
|
125
|
+
data: {
|
|
126
|
+
jobId: p.jobId,
|
|
127
|
+
message: p.message,
|
|
128
|
+
},
|
|
129
|
+
})
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
api.logger.error(`[智小途-定时触发] 无法获取渠道配置,accountId=${accountId}`)
|
|
134
|
+
return json({ error: '无法获取渠道配置,请检查账户配置' })
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* 注册定时任务触发通知工具
|
|
143
|
+
*/
|
|
144
|
+
export function registerOpenclawWorkclawCronNotifySyncTool(api: OpenClawPluginApi): void {
|
|
145
|
+
(api.registerTool as any)(getOpenclawWorkclawCronNotifySyncTool(api), {
|
|
146
|
+
name: 'openclaw-workclaw-cron-notify-sync',
|
|
147
|
+
})
|
|
148
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 智小途定时任务工具 - 生成删除定时任务参数
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { OpenClawPluginApi } from 'openclaw/plugin-sdk'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 生成删除定时任务参数
|
|
9
|
+
*/
|
|
10
|
+
export interface RemoveParamsParams {
|
|
11
|
+
jobId: string
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 参数 Schema 定义
|
|
16
|
+
*/
|
|
17
|
+
const RemoveParamsSchema = {
|
|
18
|
+
type: 'object',
|
|
19
|
+
properties: {
|
|
20
|
+
jobId: {
|
|
21
|
+
type: 'string',
|
|
22
|
+
description: 'OpenClaw 任务 ID',
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
required: ['jobId'],
|
|
26
|
+
} as const
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 构造工具返回结果
|
|
30
|
+
*/
|
|
31
|
+
function json(data: unknown): any {
|
|
32
|
+
return {
|
|
33
|
+
content: [{ type: 'text' as const, text: JSON.stringify(data, null, 2) }],
|
|
34
|
+
details: data,
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 获取生成删除定时任务参数工具
|
|
40
|
+
*/
|
|
41
|
+
function getOpenclawWorkclawCronRemoveParamsTool(api: OpenClawPluginApi) {
|
|
42
|
+
return (ctx: any) => {
|
|
43
|
+
return {
|
|
44
|
+
name: 'openclaw-workclaw-cron-remove-params',
|
|
45
|
+
label: '智小途生成删除提醒参数',
|
|
46
|
+
description: `生成删除提醒的 CLI 命令。
|
|
47
|
+
**必须**严格按照以下格式执行:
|
|
48
|
+
openclaw cron remove <jobId>
|
|
49
|
+
|
|
50
|
+
示例:openclaw cron remove 123456
|
|
51
|
+
`,
|
|
52
|
+
parameters: RemoveParamsSchema,
|
|
53
|
+
execute: async (_toolCallId: string, params: RemoveParamsParams) => {
|
|
54
|
+
const p = params as RemoveParamsParams
|
|
55
|
+
|
|
56
|
+
api.logger.info(`[智小途-生成删除参数] 开始处理 jobId=${p.jobId}`)
|
|
57
|
+
|
|
58
|
+
// 参数校验
|
|
59
|
+
if (!p.jobId) {
|
|
60
|
+
api.logger.warn('[智小途-生成删除参数] 缺少 jobId 参数')
|
|
61
|
+
return json({ error: 'jobId 为必填参数' })
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// 从 ctx 获取必要参数
|
|
65
|
+
const accountId = ctx?.agentAccountId
|
|
66
|
+
const agentId = ctx?.agentId
|
|
67
|
+
|
|
68
|
+
// 校验必要参数
|
|
69
|
+
if (!accountId) {
|
|
70
|
+
api.logger.warn('[智小途-生成删除参数] 无法获取账户 ID')
|
|
71
|
+
return json({ error: '无法获取账户 ID(accountId),请确保已配置账户' })
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (!agentId) {
|
|
75
|
+
api.logger.warn('[智小途-生成删除参数] 无法获取智能体 ID')
|
|
76
|
+
return json({ error: '无法获取智能体 ID(agentId),请确保已配置智能体' })
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
api.logger.info(`[智小途-生成删除参数] accountId=${accountId} agentId=${agentId} jobId=${p.jobId}`)
|
|
80
|
+
|
|
81
|
+
const cronParams = {
|
|
82
|
+
action: 'remove' as const,
|
|
83
|
+
jobId: p.jobId,
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
api.logger.info(`[智小途-生成删除参数] 构建 cron 参数 cronParams=${JSON.stringify(cronParams)}`)
|
|
87
|
+
|
|
88
|
+
return json({
|
|
89
|
+
cronParams,
|
|
90
|
+
meta: {
|
|
91
|
+
accountId,
|
|
92
|
+
agentId,
|
|
93
|
+
jobId: p.jobId,
|
|
94
|
+
},
|
|
95
|
+
summary: `🗑️ 提醒已删除: jobId=${p.jobId}`,
|
|
96
|
+
})
|
|
97
|
+
},
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* 注册生成删除定时任务参数工具
|
|
104
|
+
*/
|
|
105
|
+
export function registerOpenclawWorkclawCronRemoveParamsTool(api: OpenClawPluginApi): void {
|
|
106
|
+
(api.registerTool as any)(getOpenclawWorkclawCronRemoveParamsTool(api), {
|
|
107
|
+
name: 'openclaw-workclaw-cron-remove-params',
|
|
108
|
+
})
|
|
109
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,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',
|
|
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
|
+
}
|