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