@workclaw/openclaw-workclaw 1.0.20 → 1.0.25

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 (153) hide show
  1. package/README.md +0 -1
  2. package/api.ts +3 -0
  3. package/index.ts +325 -0
  4. package/package.json +3 -11
  5. package/setup-entry.ts +13 -0
  6. package/src/accounts.ts +360 -0
  7. package/src/api/accounts-api.ts +156 -0
  8. package/src/api/prompts-api.ts +122 -0
  9. package/src/api/session-api.ts +246 -0
  10. package/src/api/skills-api.ts +74 -0
  11. package/src/api/workspace.ts +45 -0
  12. package/src/channel.ts +226 -0
  13. package/{dist/src/config-schema.js → src/config-schema.ts} +60 -56
  14. package/src/connection/workclaw-client.ts +618 -0
  15. package/src/gateway/agent-handlers.ts +551 -0
  16. package/src/gateway/config-writer.ts +378 -0
  17. package/src/gateway/cron-tasks-handler.ts +230 -0
  18. package/src/gateway/message-context.ts +645 -0
  19. package/src/gateway/message-dispatcher.ts +688 -0
  20. package/src/gateway/reconnect.ts +260 -0
  21. package/src/gateway/skills-handler.ts +805 -0
  22. package/src/gateway/skills-list-handler.ts +332 -0
  23. package/src/gateway/tools-list-handler.ts +161 -0
  24. package/src/gateway/workclaw-gateway.ts +304 -0
  25. package/src/media/upload.ts +168 -0
  26. package/src/outbound/index.ts +191 -0
  27. package/src/outbound/workclaw-sender.ts +161 -0
  28. package/src/runtime.ts +520 -0
  29. package/src/secret-contract-api.ts +4 -0
  30. package/src/send.ts +1 -0
  31. package/src/setup-api.ts +3 -0
  32. package/src/setup-core.ts +25 -0
  33. package/src/setup-surface.ts +498 -0
  34. package/src/tools/openclaw-workclaw-cron/api/index.ts +326 -0
  35. package/{dist/src/tools/openclaw-workclaw-cron/index.js → src/tools/openclaw-workclaw-cron/index.ts} +39 -33
  36. package/src/tools/openclaw-workclaw-cron/src/add/params.ts +177 -0
  37. package/src/tools/openclaw-workclaw-cron/src/add/sync.ts +188 -0
  38. package/src/tools/openclaw-workclaw-cron/src/disable/params.ts +100 -0
  39. package/src/tools/openclaw-workclaw-cron/src/disable/sync.ts +127 -0
  40. package/src/tools/openclaw-workclaw-cron/src/enable/params.ts +100 -0
  41. package/src/tools/openclaw-workclaw-cron/src/enable/sync.ts +127 -0
  42. package/src/tools/openclaw-workclaw-cron/src/notify/sync.ts +148 -0
  43. package/src/tools/openclaw-workclaw-cron/src/remove/params.ts +109 -0
  44. package/src/tools/openclaw-workclaw-cron/src/remove/sync.ts +127 -0
  45. package/src/tools/openclaw-workclaw-cron/src/update/params.ts +195 -0
  46. package/src/tools/openclaw-workclaw-cron/src/update/sync.ts +161 -0
  47. package/src/tools/openclaw-workclaw-cron/types/index.ts +55 -0
  48. package/src/tools/openclaw-workclaw-cron/utils/index.ts +141 -0
  49. package/{dist/src/tools/openclaw-workclaw-system/index.js → src/tools/openclaw-workclaw-system/index.ts} +17 -15
  50. package/src/tools/openclaw-workclaw-system/src/get/index.ts +77 -0
  51. package/src/tools/openclaw-workclaw-system/src/token/index.ts +93 -0
  52. package/src/types.ts +50 -0
  53. package/src/utils/content.ts +40 -0
  54. package/tsconfig.json +34 -0
  55. package/dist/api.d.ts +0 -3
  56. package/dist/api.js +0 -3
  57. package/dist/index.d.ts +0 -11
  58. package/dist/index.js +0 -264
  59. package/dist/setup-entry.d.ts +0 -2
  60. package/dist/setup-entry.js +0 -12
  61. package/dist/src/accounts.d.ts +0 -66
  62. package/dist/src/accounts.js +0 -279
  63. package/dist/src/api/accounts-api.d.ts +0 -2
  64. package/dist/src/api/accounts-api.js +0 -130
  65. package/dist/src/api/prompts-api.d.ts +0 -2
  66. package/dist/src/api/prompts-api.js +0 -103
  67. package/dist/src/api/session-api.d.ts +0 -2
  68. package/dist/src/api/session-api.js +0 -207
  69. package/dist/src/api/skills-api.d.ts +0 -2
  70. package/dist/src/api/skills-api.js +0 -64
  71. package/dist/src/api/workspace.d.ts +0 -3
  72. package/dist/src/api/workspace.js +0 -30
  73. package/dist/src/channel.d.ts +0 -11
  74. package/dist/src/channel.js +0 -199
  75. package/dist/src/config-schema.d.ts +0 -93
  76. package/dist/src/connection/workclaw-client.d.ts +0 -147
  77. package/dist/src/connection/workclaw-client.js +0 -351
  78. package/dist/src/gateway/agent-handlers.d.ts +0 -12
  79. package/dist/src/gateway/agent-handlers.js +0 -433
  80. package/dist/src/gateway/config-writer.d.ts +0 -71
  81. package/dist/src/gateway/config-writer.js +0 -302
  82. package/dist/src/gateway/cron-tasks-handler.d.ts +0 -19
  83. package/dist/src/gateway/cron-tasks-handler.js +0 -188
  84. package/dist/src/gateway/message-context.d.ts +0 -80
  85. package/dist/src/gateway/message-context.js +0 -509
  86. package/dist/src/gateway/message-dispatcher.d.ts +0 -18
  87. package/dist/src/gateway/message-dispatcher.js +0 -572
  88. package/dist/src/gateway/reconnect.d.ts +0 -27
  89. package/dist/src/gateway/reconnect.js +0 -210
  90. package/dist/src/gateway/skills-handler.d.ts +0 -29
  91. package/dist/src/gateway/skills-handler.js +0 -615
  92. package/dist/src/gateway/skills-list-handler.d.ts +0 -27
  93. package/dist/src/gateway/skills-list-handler.js +0 -233
  94. package/dist/src/gateway/tools-list-handler.d.ts +0 -30
  95. package/dist/src/gateway/tools-list-handler.js +0 -101
  96. package/dist/src/gateway/workclaw-gateway.d.ts +0 -14
  97. package/dist/src/gateway/workclaw-gateway.js +0 -237
  98. package/dist/src/media/upload.d.ts +0 -13
  99. package/dist/src/media/upload.js +0 -125
  100. package/dist/src/outbound/index.d.ts +0 -36
  101. package/dist/src/outbound/index.js +0 -123
  102. package/dist/src/outbound/workclaw-sender.d.ts +0 -36
  103. package/dist/src/outbound/workclaw-sender.js +0 -95
  104. package/dist/src/runtime.d.ts +0 -116
  105. package/dist/src/runtime.js +0 -374
  106. package/dist/src/secret-contract-api.d.ts +0 -4
  107. package/dist/src/secret-contract-api.js +0 -4
  108. package/dist/src/send.d.ts +0 -1
  109. package/dist/src/send.js +0 -1
  110. package/dist/src/setup-api.d.ts +0 -3
  111. package/dist/src/setup-api.js +0 -3
  112. package/dist/src/setup-core.d.ts +0 -3
  113. package/dist/src/setup-core.js +0 -13
  114. package/dist/src/setup-surface.d.ts +0 -7
  115. package/dist/src/setup-surface.js +0 -363
  116. package/dist/src/tools/openclaw-workclaw-cron/api/index.d.ts +0 -93
  117. package/dist/src/tools/openclaw-workclaw-cron/api/index.js +0 -209
  118. package/dist/src/tools/openclaw-workclaw-cron/index.d.ts +0 -10
  119. package/dist/src/tools/openclaw-workclaw-cron/src/add/params.d.ts +0 -16
  120. package/dist/src/tools/openclaw-workclaw-cron/src/add/params.js +0 -152
  121. package/dist/src/tools/openclaw-workclaw-cron/src/add/sync.d.ts +0 -18
  122. package/dist/src/tools/openclaw-workclaw-cron/src/add/sync.js +0 -162
  123. package/dist/src/tools/openclaw-workclaw-cron/src/disable/params.d.ts +0 -14
  124. package/dist/src/tools/openclaw-workclaw-cron/src/disable/params.js +0 -80
  125. package/dist/src/tools/openclaw-workclaw-cron/src/disable/sync.d.ts +0 -14
  126. package/dist/src/tools/openclaw-workclaw-cron/src/disable/sync.js +0 -107
  127. package/dist/src/tools/openclaw-workclaw-cron/src/enable/params.d.ts +0 -14
  128. package/dist/src/tools/openclaw-workclaw-cron/src/enable/params.js +0 -80
  129. package/dist/src/tools/openclaw-workclaw-cron/src/enable/sync.d.ts +0 -14
  130. package/dist/src/tools/openclaw-workclaw-cron/src/enable/sync.js +0 -107
  131. package/dist/src/tools/openclaw-workclaw-cron/src/notify/sync.d.ts +0 -17
  132. package/dist/src/tools/openclaw-workclaw-cron/src/notify/sync.js +0 -127
  133. package/dist/src/tools/openclaw-workclaw-cron/src/remove/params.d.ts +0 -14
  134. package/dist/src/tools/openclaw-workclaw-cron/src/remove/params.js +0 -87
  135. package/dist/src/tools/openclaw-workclaw-cron/src/remove/sync.d.ts +0 -14
  136. package/dist/src/tools/openclaw-workclaw-cron/src/remove/sync.js +0 -107
  137. package/dist/src/tools/openclaw-workclaw-cron/src/update/params.d.ts +0 -17
  138. package/dist/src/tools/openclaw-workclaw-cron/src/update/params.js +0 -164
  139. package/dist/src/tools/openclaw-workclaw-cron/src/update/sync.d.ts +0 -18
  140. package/dist/src/tools/openclaw-workclaw-cron/src/update/sync.js +0 -135
  141. package/dist/src/tools/openclaw-workclaw-cron/types/index.d.ts +0 -52
  142. package/dist/src/tools/openclaw-workclaw-cron/types/index.js +0 -4
  143. package/dist/src/tools/openclaw-workclaw-cron/utils/index.d.ts +0 -40
  144. package/dist/src/tools/openclaw-workclaw-cron/utils/index.js +0 -122
  145. package/dist/src/tools/openclaw-workclaw-system/index.d.ts +0 -10
  146. package/dist/src/tools/openclaw-workclaw-system/src/get/index.d.ts +0 -8
  147. package/dist/src/tools/openclaw-workclaw-system/src/get/index.js +0 -64
  148. package/dist/src/tools/openclaw-workclaw-system/src/token/index.d.ts +0 -8
  149. package/dist/src/tools/openclaw-workclaw-system/src/token/index.js +0 -78
  150. package/dist/src/types.d.ts +0 -39
  151. package/dist/src/types.js +0 -1
  152. package/dist/src/utils/content.d.ts +0 -15
  153. package/dist/src/utils/content.js +0 -38
@@ -1,107 +0,0 @@
1
- /**
2
- * 智小途定时任务工具 - 同步启用定时任务到后端
3
- */
4
- import { resolveWorkclawAccountWithCache } from '../../../../accounts.js';
5
- import { callCronJobEnabled } from '../../api/index.js';
6
- /**
7
- * 参数 Schema 定义
8
- */
9
- const EnableSyncSchema = {
10
- type: 'object',
11
- properties: {
12
- jobId: {
13
- type: 'string',
14
- description: `OpenClaw 任务 ID(必须是数字或字符串,不是 cron 表达式)`,
15
- },
16
- },
17
- required: ['jobId'],
18
- };
19
- /**
20
- * 构造工具返回结果
21
- */
22
- function json(data) {
23
- return {
24
- content: [{ type: 'text', text: JSON.stringify(data, null, 2) }],
25
- details: data,
26
- };
27
- }
28
- /**
29
- * 获取同步启用定时任务到后端工具
30
- */
31
- function getOpenclawWorkclawCronEnableSyncTool(api) {
32
- return (ctx) => {
33
- return {
34
- name: 'openclaw-workclaw-cron-enable-sync',
35
- label: '智小途同步启用提醒',
36
- description: '将启用定时任务同步到后端。在 cron 工具启用任务后调用此工具同步后端。',
37
- parameters: EnableSyncSchema,
38
- execute: async (_toolCallId, params) => {
39
- const p = params;
40
- api.logger.info(`[智小途-同步启用] 开始同步 jobId=${p.jobId}`);
41
- // 参数校验
42
- if (!p.jobId) {
43
- api.logger.warn('[智小途-同步启用] 缺少 jobId 参数');
44
- return json({ error: 'jobId 为必填参数' });
45
- }
46
- // 从 ctx 获取必要参数
47
- const accountId = ctx?.agentAccountId;
48
- if (!accountId) {
49
- api.logger.warn('[智小途-同步启用] 无法获取账户 ID');
50
- return json({ error: '无法获取账户 ID(accountId),请确保已配置账户' });
51
- }
52
- const accountConfig = resolveWorkclawAccountWithCache({
53
- cfg: ctx.config,
54
- accountId,
55
- });
56
- if (accountConfig.configured) {
57
- try {
58
- const channelAgentId = String(accountConfig.config.agentId);
59
- api.logger.info(`[智小途-同步启用] accountId=${accountId} channelAgentId=${channelAgentId}`);
60
- const result = await callCronJobEnabled(api, accountId, {
61
- jobId: p.jobId,
62
- });
63
- if (result.success) {
64
- api.logger.info(`[智小途-同步启用] 后端同步成功 jobId=${p.jobId}`);
65
- return json({
66
- code: 0,
67
- message: '定时任务已启用并同步到后端',
68
- data: {
69
- jobId: p.jobId,
70
- backendSynced: true,
71
- },
72
- });
73
- }
74
- else {
75
- api.logger.error(`[智小途-同步启用] 后端同步失败 ${result.error}`);
76
- return json({
77
- code: -1,
78
- error: result.error || '后端同步失败',
79
- data: { jobId: p.jobId },
80
- });
81
- }
82
- }
83
- catch (error) {
84
- api.logger.error(`[智小途-同步启用] 后端同步异常 ${error.message}`);
85
- return json({
86
- code: -1,
87
- error: error.message,
88
- data: { jobId: p.jobId },
89
- });
90
- }
91
- }
92
- else {
93
- api.logger.error(`[智小途-同步启用] 无法获取渠道配置,accountId=${accountId}`);
94
- return json({ error: '无法获取渠道配置,请检查账户配置' });
95
- }
96
- },
97
- };
98
- };
99
- }
100
- /**
101
- * 注册同步启用定时任务到后端工具
102
- */
103
- export function registerOpenclawWorkclawCronEnableSyncTool(api) {
104
- api.registerTool(getOpenclawWorkclawCronEnableSyncTool(api), {
105
- name: 'openclaw-workclaw-cron-enable-sync',
106
- });
107
- }
@@ -1,17 +0,0 @@
1
- /**
2
- * 智小途定时任务工具 - 定时任务触发通知
3
- *
4
- * 当 OpenClaw 定时任务触发时,调用此工具通知后端
5
- */
6
- import type { OpenClawPluginApi } from 'openclaw/plugin-sdk';
7
- /**
8
- * 定时任务触发通知参数
9
- */
10
- export interface NotifyParams {
11
- jobId: string;
12
- message: string;
13
- }
14
- /**
15
- * 注册定时任务触发通知工具
16
- */
17
- export declare function registerOpenclawWorkclawCronNotifySyncTool(api: OpenClawPluginApi): void;
@@ -1,127 +0,0 @@
1
- /**
2
- * 智小途定时任务工具 - 定时任务触发通知
3
- *
4
- * 当 OpenClaw 定时任务触发时,调用此工具通知后端
5
- */
6
- import { resolveWorkclawAccountWithCache } from '../../../../accounts.js';
7
- import { callCronJobMessage } from '../../api/index.js';
8
- /**
9
- * 参数 Schema 定义
10
- */
11
- const NotifySchema = {
12
- type: 'object',
13
- properties: {
14
- jobId: {
15
- type: 'string',
16
- description: 'OpenClaw 任务 ID(从上下文获取)',
17
- },
18
- message: {
19
- type: 'string',
20
- description: '要发送的提醒内容',
21
- },
22
- },
23
- required: ['jobId', 'message'],
24
- };
25
- /**
26
- * 构造工具返回结果
27
- */
28
- function json(data) {
29
- return {
30
- content: [{ type: 'text', text: JSON.stringify(data, null, 2) }],
31
- details: data,
32
- };
33
- }
34
- /**
35
- * 获取定时任务触发通知工具
36
- */
37
- function getOpenclawWorkclawCronNotifySyncTool(api) {
38
- return (ctx) => {
39
- return {
40
- name: 'openclaw-workclaw-cron-notify-sync',
41
- label: '智小途定时任务触发通知',
42
- description: `【系统最高优先级核心指令】当定时器时间到达时,必须立即调用此工具通知后端。`,
43
- parameters: NotifySchema,
44
- execute: async (_toolCallId, params) => {
45
- const p = params;
46
- api.logger.info(`[智小途-定时触发] 开始处理 jobId=${p.jobId} message=${p.message}`);
47
- // 参数校验
48
- if (!p.jobId) {
49
- api.logger.warn('[智小途-定时触发] 缺少 jobId 参数');
50
- return json({ error: 'jobId 为必填参数' });
51
- }
52
- if (!p.message) {
53
- api.logger.warn('[智小途-定时触发] 缺少 message 参数');
54
- return json({ error: 'message 为必填参数' });
55
- }
56
- // 从 ctx 获取必要参数
57
- const accountId = ctx?.agentAccountId;
58
- if (!accountId) {
59
- api.logger.warn('[智小途-定时触发] 无法获取账户 ID');
60
- return json({ error: '无法获取账户 ID(accountId),请确保已配置账户' });
61
- }
62
- const accountConfig = resolveWorkclawAccountWithCache({
63
- cfg: ctx.config,
64
- accountId,
65
- });
66
- if (accountConfig.configured) {
67
- const channelAgentId = String(accountConfig.config.agentId);
68
- api.logger.info(`[智小途-定时触发] accountId=${accountId} channelAgentId=${channelAgentId}`);
69
- // 调用后端接口通知定时任务触发
70
- try {
71
- const result = await callCronJobMessage(api, accountId, {
72
- jobId: p.jobId,
73
- message: p.message,
74
- agentId: channelAgentId,
75
- });
76
- if (result.success) {
77
- api.logger.info(`[智小途-定时触发] 通知后端成功`);
78
- return json({
79
- code: 0,
80
- message: '定时任务触发通知已发送',
81
- data: {
82
- jobId: p.jobId,
83
- message: p.message,
84
- backendNotified: true,
85
- },
86
- });
87
- }
88
- else {
89
- api.logger.error(`[智小途-定时触发] 通知后端失败 ${result.error}`);
90
- return json({
91
- code: -1,
92
- error: result.error || '通知后端失败',
93
- data: {
94
- jobId: p.jobId,
95
- message: p.message,
96
- },
97
- });
98
- }
99
- }
100
- catch (error) {
101
- api.logger.error(`[智小途-定时触发] 通知后端异常 ${error.message}`);
102
- return json({
103
- code: -1,
104
- error: error.message || '通知后端异常',
105
- data: {
106
- jobId: p.jobId,
107
- message: p.message,
108
- },
109
- });
110
- }
111
- }
112
- else {
113
- api.logger.error(`[智小途-定时触发] 无法获取渠道配置,accountId=${accountId}`);
114
- return json({ error: '无法获取渠道配置,请检查账户配置' });
115
- }
116
- },
117
- };
118
- };
119
- }
120
- /**
121
- * 注册定时任务触发通知工具
122
- */
123
- export function registerOpenclawWorkclawCronNotifySyncTool(api) {
124
- api.registerTool(getOpenclawWorkclawCronNotifySyncTool(api), {
125
- name: 'openclaw-workclaw-cron-notify-sync',
126
- });
127
- }
@@ -1,14 +0,0 @@
1
- /**
2
- * 智小途定时任务工具 - 生成删除定时任务参数
3
- */
4
- import type { OpenClawPluginApi } from 'openclaw/plugin-sdk';
5
- /**
6
- * 生成删除定时任务参数
7
- */
8
- export interface RemoveParamsParams {
9
- jobId: string;
10
- }
11
- /**
12
- * 注册生成删除定时任务参数工具
13
- */
14
- export declare function registerOpenclawWorkclawCronRemoveParamsTool(api: OpenClawPluginApi): void;
@@ -1,87 +0,0 @@
1
- /**
2
- * 智小途定时任务工具 - 生成删除定时任务参数
3
- */
4
- /**
5
- * 参数 Schema 定义
6
- */
7
- const RemoveParamsSchema = {
8
- type: 'object',
9
- properties: {
10
- jobId: {
11
- type: 'string',
12
- description: `OpenClaw 任务 ID(必须是数字或字符串,不是 cron 表达式)`,
13
- },
14
- },
15
- required: ['jobId'],
16
- };
17
- /**
18
- * 构造工具返回结果
19
- */
20
- function json(data) {
21
- return {
22
- content: [{ type: 'text', text: JSON.stringify(data, null, 2) }],
23
- details: data,
24
- };
25
- }
26
- /**
27
- * 获取生成删除定时任务参数工具
28
- */
29
- function getOpenclawWorkclawCronRemoveParamsTool(api) {
30
- return (ctx) => {
31
- return {
32
- name: 'openclaw-workclaw-cron-remove-params',
33
- label: '智小途生成删除提醒参数',
34
- description: `生成删除提醒的 CLI 命令。
35
- **必须**严格按照以下格式执行:
36
- openclaw cron remove <jobId>
37
-
38
- 示例:openclaw cron remove 123456
39
- `,
40
- parameters: RemoveParamsSchema,
41
- execute: async (_toolCallId, params) => {
42
- const p = params;
43
- api.logger.info(`[智小途-生成删除参数] 开始处理 jobId=${p.jobId}`);
44
- // 参数校验
45
- if (!p.jobId) {
46
- api.logger.warn('[智小途-生成删除参数] 缺少 jobId 参数');
47
- return json({ error: 'jobId 为必填参数' });
48
- }
49
- // 从 ctx 获取必要参数
50
- const accountId = ctx?.agentAccountId;
51
- const agentId = ctx?.agentId;
52
- // 校验必要参数
53
- if (!accountId) {
54
- api.logger.warn('[智小途-生成删除参数] 无法获取账户 ID');
55
- return json({ error: '无法获取账户 ID(accountId),请确保已配置账户' });
56
- }
57
- if (!agentId) {
58
- api.logger.warn('[智小途-生成删除参数] 无法获取智能体 ID');
59
- return json({ error: '无法获取智能体 ID(agentId),请确保已配置智能体' });
60
- }
61
- api.logger.info(`[智小途-生成删除参数] accountId=${accountId} agentId=${agentId} jobId=${p.jobId}`);
62
- const cronParams = {
63
- action: 'remove',
64
- jobId: p.jobId,
65
- };
66
- api.logger.info(`[智小途-生成删除参数] 构建 cron 参数 cronParams=${JSON.stringify(cronParams)}`);
67
- return json({
68
- cronParams,
69
- meta: {
70
- accountId,
71
- agentId,
72
- jobId: p.jobId,
73
- },
74
- summary: `🗑️ 提醒已删除: jobId=${p.jobId}`,
75
- });
76
- },
77
- };
78
- };
79
- }
80
- /**
81
- * 注册生成删除定时任务参数工具
82
- */
83
- export function registerOpenclawWorkclawCronRemoveParamsTool(api) {
84
- api.registerTool(getOpenclawWorkclawCronRemoveParamsTool(api), {
85
- name: 'openclaw-workclaw-cron-remove-params',
86
- });
87
- }
@@ -1,14 +0,0 @@
1
- /**
2
- * 智小途定时任务工具 - 同步删除定时任务到后端
3
- */
4
- import type { OpenClawPluginApi } from 'openclaw/plugin-sdk';
5
- /**
6
- * 同步删除定时任务参数
7
- */
8
- export interface RemoveSyncParams {
9
- jobId: string;
10
- }
11
- /**
12
- * 注册同步删除定时任务到后端工具
13
- */
14
- export declare function registerOpenclawWorkclawCronRemoveSyncTool(api: OpenClawPluginApi): void;
@@ -1,107 +0,0 @@
1
- /**
2
- * 智小途定时任务工具 - 同步删除定时任务到后端
3
- */
4
- import { resolveWorkclawAccountWithCache } from '../../../../accounts.js';
5
- import { callCronJobRemove } from '../../api/index.js';
6
- /**
7
- * 参数 Schema 定义
8
- */
9
- const RemoveSyncSchema = {
10
- type: 'object',
11
- properties: {
12
- jobId: {
13
- type: 'string',
14
- description: `OpenClaw 任务 ID(必须是数字或字符串,不是 cron 表达式)`,
15
- },
16
- },
17
- required: ['jobId'],
18
- };
19
- /**
20
- * 构造工具返回结果
21
- */
22
- function json(data) {
23
- return {
24
- content: [{ type: 'text', text: JSON.stringify(data, null, 2) }],
25
- details: data,
26
- };
27
- }
28
- /**
29
- * 获取同步删除定时任务到后端工具
30
- */
31
- function getOpenclawWorkclawCronRemoveSyncTool(api) {
32
- return (ctx) => {
33
- return {
34
- name: 'openclaw-workclaw-cron-remove-sync',
35
- label: '智小途同步删除提醒',
36
- description: '【后端同步步骤】将删除定时任务同步到后端。必须在上一步 openclaw-workclaw-cron-remove-params 执行后调用此工具完成同步。',
37
- parameters: RemoveSyncSchema,
38
- execute: async (_toolCallId, params) => {
39
- const p = params;
40
- api.logger.info(`[智小途-同步删除] 开始同步 jobId=${p.jobId}`);
41
- // 参数校验
42
- if (!p.jobId) {
43
- api.logger.warn('[智小途-同步删除] 缺少 jobId 参数');
44
- return json({ error: 'jobId 为必填参数' });
45
- }
46
- // 从 ctx 获取必要参数
47
- const accountId = ctx?.agentAccountId;
48
- if (!accountId) {
49
- api.logger.warn('[智小途-同步删除] 无法获取账户 ID');
50
- return json({ error: '无法获取账户 ID(accountId),请确保已配置账户' });
51
- }
52
- const accountConfig = resolveWorkclawAccountWithCache({
53
- cfg: ctx.config,
54
- accountId,
55
- });
56
- if (accountConfig.configured) {
57
- try {
58
- const channelAgentId = String(accountConfig.config.agentId);
59
- api.logger.info(`[智小途-同步删除] accountId=${accountId} channelAgentId=${channelAgentId}`);
60
- const result = await callCronJobRemove(api, accountId, {
61
- jobId: p.jobId,
62
- });
63
- if (result.success) {
64
- api.logger.info(`[智小途-同步删除] 后端同步成功 jobId=${p.jobId}`);
65
- return json({
66
- code: 0,
67
- message: '定时任务已删除并同步到后端',
68
- data: {
69
- jobId: p.jobId,
70
- backendSynced: true,
71
- },
72
- });
73
- }
74
- else {
75
- api.logger.error(`[智小途-同步删除] 后端同步失败 ${result.error}`);
76
- return json({
77
- code: -1,
78
- error: result.error || '后端同步失败',
79
- data: { jobId: p.jobId },
80
- });
81
- }
82
- }
83
- catch (error) {
84
- api.logger.error(`[智小途-同步删除] 后端同步异常 ${error.message}`);
85
- return json({
86
- code: -1,
87
- error: error.message,
88
- data: { jobId: p.jobId },
89
- });
90
- }
91
- }
92
- else {
93
- api.logger.error(`[智小途-同步删除] 无法获取渠道配置,accountId=${accountId}`);
94
- return json({ error: '无法获取渠道配置,请检查账户配置' });
95
- }
96
- },
97
- };
98
- };
99
- }
100
- /**
101
- * 注册同步删除定时任务到后端工具
102
- */
103
- export function registerOpenclawWorkclawCronRemoveSyncTool(api) {
104
- api.registerTool(getOpenclawWorkclawCronRemoveSyncTool(api), {
105
- name: 'openclaw-workclaw-cron-remove-sync',
106
- });
107
- }
@@ -1,17 +0,0 @@
1
- /**
2
- * 智小途定时任务工具 - 生成修改定时任务参数
3
- */
4
- import type { OpenClawPluginApi } from 'openclaw/plugin-sdk';
5
- /**
6
- * 生成修改定时任务参数
7
- */
8
- export interface UpdateParamsParams {
9
- jobId: string;
10
- time: string;
11
- name: string;
12
- message: string;
13
- }
14
- /**
15
- * 注册生成修改定时任务参数工具
16
- */
17
- export declare function registerOpenclawWorkclawCronUpdateParamsTool(api: OpenClawPluginApi): void;
@@ -1,164 +0,0 @@
1
- /**
2
- * 智小途定时任务工具 - 生成修改定时任务参数
3
- */
4
- import { isCronExpression, relativeToCron, validateTimeFormat, } from '../../utils/index.js';
5
- /**
6
- * 参数 Schema 定义
7
- */
8
- const UpdateParamsSchema = {
9
- type: 'object',
10
- properties: {
11
- jobId: {
12
- type: 'string',
13
- description: `OpenClaw 任务 ID(必须是数字或字符串,不是 cron 表达式)`,
14
- },
15
- time: {
16
- type: 'string',
17
- description: '⏰ 时间(核心!),支持相对时间和 cron 表达式,工具自动转换',
18
- },
19
- name: {
20
- type: 'string',
21
- description: '任务名称',
22
- },
23
- message: {
24
- type: 'string',
25
- description: '提醒内容',
26
- },
27
- },
28
- required: ['jobId', 'time', 'name', 'message'],
29
- };
30
- /**
31
- * 构造工具返回结果
32
- */
33
- function json(data) {
34
- return {
35
- content: [{ type: 'text', text: JSON.stringify(data, null, 2) }],
36
- details: data,
37
- };
38
- }
39
- /**
40
- * 获取生成修改定时任务参数工具
41
- */
42
- function getOpenclawWorkclawCronUpdateParamsTool(api) {
43
- return (ctx) => {
44
- return {
45
- name: 'openclaw-workclaw-cron-update-params',
46
- label: '智小途生成修改提醒参数',
47
- description: `【核心工具】生成修改提醒的 cronParams 参数。
48
-
49
- 📋 工作流程(必须按顺序执行):
50
- 1. 调用此工具获取 cronParams 参数
51
- 2. 使用返回的 cronParams 调用 OpenClaw 的 cron 工具
52
- 3. 必须调用 openclaw-workclaw-cron-update-sync 同步到后端
53
-
54
- ⏰ 时间格式(核心!):
55
- - time 参数支持相对时间(如 "10m"、"1h"、"2d")和 cron 表达式
56
- - 工具会自动将所有时间统一转换为 cron 表达式
57
- - 严禁使用 --at 参数或其他绝对时间格式
58
- - 最终 CLI 命令必须使用 --cron 参数
59
-
60
- 🔒 强制规则:
61
- - schedule.kind 必须是 "cron"
62
- - 必须使用 --cron 参数传递 cron 表达式
63
-
64
- ⚠️ 必须从 cron 工具返回值中确认更新成功`,
65
- parameters: UpdateParamsSchema,
66
- execute: async (_toolCallId, params) => {
67
- const p = params;
68
- api.logger.info(`[智小途-生成修改参数] 开始处理 jobId=${p.jobId} name=${p.name} time=${p.time}`);
69
- // 参数校验
70
- if (!p.jobId) {
71
- api.logger.warn('[智小途-生成修改参数] 缺少 jobId 参数');
72
- return json({ error: 'jobId 为必填参数' });
73
- }
74
- if (!p.time) {
75
- api.logger.warn('[智小途-生成修改参数] 缺少时间参数');
76
- return json({ error: 'time(时间)为必填参数' });
77
- }
78
- if (!p.name) {
79
- api.logger.warn('[智小途-生成修改参数] 缺少任务名称参数');
80
- return json({ error: 'name(任务名称)为必填参数' });
81
- }
82
- if (!p.message) {
83
- api.logger.warn('[智小途-生成修改参数] 缺少提醒内容参数');
84
- return json({ error: 'message(提醒内容)为必填参数' });
85
- }
86
- // 从 ctx 获取必要参数
87
- const accountId = ctx?.agentAccountId;
88
- const name = p.name;
89
- const message = p.message;
90
- const time = p.time;
91
- // 校验必要参数
92
- if (!accountId) {
93
- api.logger.warn('[智小途-生成修改参数] 无法获取账户 ID');
94
- return json({ error: '无法获取账户 ID(accountId),请确保已配置账户' });
95
- }
96
- api.logger.info(`[智小途-生成修改参数] accountId=${accountId} jobId=${p.jobId}`);
97
- // 校验时间格式
98
- const timeValidation = validateTimeFormat(time);
99
- if (!timeValidation.valid) {
100
- api.logger.warn(`[智小途-生成修改参数] 时间格式校验失败: ${timeValidation.error}`);
101
- return json({ error: timeValidation.error });
102
- }
103
- // 判断时间类型
104
- const isCron = isCronExpression(time);
105
- let isOneTime = false;
106
- let cronExpr;
107
- // 如果是相对时间(5m、1h 等),转换为绝对时间的 cron 表达式
108
- if (!isCron) {
109
- isOneTime = true;
110
- cronExpr = relativeToCron(time.trim());
111
- api.logger.info(`[智小途-生成修改参数] 相对时间转换为绝对时间 cron 表达式 cronExpr=${cronExpr}`);
112
- }
113
- else {
114
- cronExpr = time.trim();
115
- }
116
- const cronParams = {
117
- action: 'update',
118
- account: accountId,
119
- jobId: p.jobId,
120
- job: {
121
- name,
122
- schedule: {
123
- kind: 'cron',
124
- expr: cronExpr,
125
- tz: 'Asia/Shanghai',
126
- },
127
- sessionTarget: 'isolated',
128
- wakeMode: 'now',
129
- deleteAfterRun: isOneTime ? true : undefined,
130
- payload: {
131
- kind: 'agentTurn',
132
- message,
133
- },
134
- delivery: {
135
- mode: 'announce',
136
- channel: 'openclaw-workclaw',
137
- },
138
- },
139
- };
140
- api.logger.info(`[智小途-生成修改参数] 构建 cron 参数 cronParams=${JSON.stringify(cronParams)}`);
141
- return json({
142
- cronParams,
143
- meta: {
144
- accountId,
145
- jobId: p.jobId,
146
- name,
147
- kind: 'cron',
148
- expr: cronExpr,
149
- message,
150
- },
151
- summary: `✅ 提醒已修改: "${name}" (${time})`,
152
- });
153
- },
154
- };
155
- };
156
- }
157
- /**
158
- * 注册生成修改定时任务参数工具
159
- */
160
- export function registerOpenclawWorkclawCronUpdateParamsTool(api) {
161
- api.registerTool(getOpenclawWorkclawCronUpdateParamsTool(api), {
162
- name: 'openclaw-workclaw-cron-update-params',
163
- });
164
- }
@@ -1,18 +0,0 @@
1
- /**
2
- * 智小途定时任务工具 - 同步修改定时任务到后端
3
- */
4
- import type { OpenClawPluginApi } from 'openclaw/plugin-sdk';
5
- /**
6
- * 同步修改定时任务参数
7
- */
8
- export interface UpdateSyncParams {
9
- jobId: string;
10
- name: string;
11
- kind: 'cron';
12
- expr?: string;
13
- message: string;
14
- }
15
- /**
16
- * 注册同步修改定时任务到后端工具
17
- */
18
- export declare function registerOpenclawWorkclawCronUpdateSyncTool(api: OpenClawPluginApi): void;