@workclaw/openclaw-workclaw 1.0.23 → 1.0.26

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 (210) hide show
  1. package/dist/api.d.ts +4 -3
  2. package/dist/api.d.ts.map +1 -0
  3. package/dist/api.js +379 -3
  4. package/dist/channel-DSvR6Irx.js +50017 -0
  5. package/dist/cron-tasks-handler-C-mP3VmV.js +152 -0
  6. package/dist/index.d.ts +5 -4
  7. package/dist/index.d.ts.map +1 -0
  8. package/dist/index.js +2056 -232
  9. package/dist/jiti-4i2h0FGP.js +4814 -0
  10. package/dist/setup-entry.d.ts +2 -1
  11. package/dist/setup-entry.d.ts.map +1 -0
  12. package/dist/setup-entry.js +181 -11
  13. package/dist/src/accounts.d.ts +3 -2
  14. package/dist/src/accounts.d.ts.map +1 -0
  15. package/dist/src/api/accounts-api.d.ts +2 -1
  16. package/dist/src/api/accounts-api.d.ts.map +1 -0
  17. package/dist/src/api/prompts-api.d.ts +2 -1
  18. package/dist/src/api/prompts-api.d.ts.map +1 -0
  19. package/dist/src/api/session-api.d.ts +2 -1
  20. package/dist/src/api/session-api.d.ts.map +1 -0
  21. package/dist/src/api/skills-api.d.ts +2 -1
  22. package/dist/src/api/skills-api.d.ts.map +1 -0
  23. package/dist/src/api/workspace.d.ts +2 -1
  24. package/dist/src/api/workspace.d.ts.map +1 -0
  25. package/dist/src/channel.d.ts +3 -2
  26. package/dist/src/channel.d.ts.map +1 -0
  27. package/dist/src/config-schema.d.ts +1 -6
  28. package/dist/src/config-schema.d.ts.map +1 -0
  29. package/dist/src/connection/workclaw-client.d.ts +6 -4
  30. package/dist/src/connection/workclaw-client.d.ts.map +1 -0
  31. package/dist/src/gateway/agent-handlers.d.ts +3 -2
  32. package/dist/src/gateway/agent-handlers.d.ts.map +1 -0
  33. package/dist/src/gateway/config-writer.d.ts +3 -2
  34. package/dist/src/gateway/config-writer.d.ts.map +1 -0
  35. package/dist/src/gateway/cron-tasks-handler.d.ts +1 -0
  36. package/dist/src/gateway/cron-tasks-handler.d.ts.map +1 -0
  37. package/dist/src/gateway/message-context.d.ts +2 -1
  38. package/dist/src/gateway/message-context.d.ts.map +1 -0
  39. package/dist/src/gateway/message-dispatcher.d.ts +3 -4
  40. package/dist/src/gateway/message-dispatcher.d.ts.map +1 -0
  41. package/dist/src/gateway/reconnect.d.ts +3 -5
  42. package/dist/src/gateway/reconnect.d.ts.map +1 -0
  43. package/dist/src/gateway/skills-handler.d.ts +1 -0
  44. package/dist/src/gateway/skills-handler.d.ts.map +1 -0
  45. package/dist/src/gateway/skills-list-handler.d.ts +1 -0
  46. package/dist/src/gateway/skills-list-handler.d.ts.map +1 -0
  47. package/dist/src/gateway/tools-list-handler.d.ts +1 -0
  48. package/dist/src/gateway/tools-list-handler.d.ts.map +1 -0
  49. package/dist/src/gateway/workclaw-gateway.d.ts +4 -7
  50. package/dist/src/gateway/workclaw-gateway.d.ts.map +1 -0
  51. package/dist/src/media/upload.d.ts +1 -0
  52. package/dist/src/media/upload.d.ts.map +1 -0
  53. package/dist/src/outbound/index.d.ts +9 -6
  54. package/dist/src/outbound/index.d.ts.map +1 -0
  55. package/dist/src/outbound/workclaw-sender.d.ts +6 -4
  56. package/dist/src/outbound/workclaw-sender.d.ts.map +1 -0
  57. package/dist/src/runtime.d.ts +11 -9
  58. package/dist/src/runtime.d.ts.map +1 -0
  59. package/dist/src/secret-contract-api.d.ts +1 -0
  60. package/dist/src/secret-contract-api.d.ts.map +1 -0
  61. package/dist/src/send.d.ts +2 -1
  62. package/dist/src/send.d.ts.map +1 -0
  63. package/dist/src/setup-api.d.ts +4 -3
  64. package/dist/src/setup-api.d.ts.map +1 -0
  65. package/dist/src/setup-core.d.ts +2 -1
  66. package/dist/src/setup-core.d.ts.map +1 -0
  67. package/dist/src/setup-surface.d.ts +3 -2
  68. package/dist/src/setup-surface.d.ts.map +1 -0
  69. package/dist/src/tools/openclaw-workclaw-cron/api/index.d.ts +2 -4
  70. package/dist/src/tools/openclaw-workclaw-cron/api/index.d.ts.map +1 -0
  71. package/dist/src/tools/openclaw-workclaw-cron/index.d.ts +1 -0
  72. package/dist/src/tools/openclaw-workclaw-cron/index.d.ts.map +1 -0
  73. package/dist/src/tools/openclaw-workclaw-cron/src/add/params.d.ts +2 -4
  74. package/dist/src/tools/openclaw-workclaw-cron/src/add/params.d.ts.map +1 -0
  75. package/dist/src/tools/openclaw-workclaw-cron/src/add/sync.d.ts +2 -4
  76. package/dist/src/tools/openclaw-workclaw-cron/src/add/sync.d.ts.map +1 -0
  77. package/dist/src/tools/openclaw-workclaw-cron/src/disable/params.d.ts +2 -4
  78. package/dist/src/tools/openclaw-workclaw-cron/src/disable/params.d.ts.map +1 -0
  79. package/dist/src/tools/openclaw-workclaw-cron/src/disable/sync.d.ts +2 -4
  80. package/dist/src/tools/openclaw-workclaw-cron/src/disable/sync.d.ts.map +1 -0
  81. package/dist/src/tools/openclaw-workclaw-cron/src/enable/params.d.ts +2 -4
  82. package/dist/src/tools/openclaw-workclaw-cron/src/enable/params.d.ts.map +1 -0
  83. package/dist/src/tools/openclaw-workclaw-cron/src/enable/sync.d.ts +2 -4
  84. package/dist/src/tools/openclaw-workclaw-cron/src/enable/sync.d.ts.map +1 -0
  85. package/dist/src/tools/openclaw-workclaw-cron/src/notify/sync.d.ts +2 -6
  86. package/dist/src/tools/openclaw-workclaw-cron/src/notify/sync.d.ts.map +1 -0
  87. package/dist/src/tools/openclaw-workclaw-cron/src/remove/params.d.ts +2 -4
  88. package/dist/src/tools/openclaw-workclaw-cron/src/remove/params.d.ts.map +1 -0
  89. package/dist/src/tools/openclaw-workclaw-cron/src/remove/sync.d.ts +2 -4
  90. package/dist/src/tools/openclaw-workclaw-cron/src/remove/sync.d.ts.map +1 -0
  91. package/dist/src/tools/openclaw-workclaw-cron/src/update/params.d.ts +2 -4
  92. package/dist/src/tools/openclaw-workclaw-cron/src/update/params.d.ts.map +1 -0
  93. package/dist/src/tools/openclaw-workclaw-cron/src/update/sync.d.ts +2 -4
  94. package/dist/src/tools/openclaw-workclaw-cron/src/update/sync.d.ts.map +1 -0
  95. package/dist/src/tools/openclaw-workclaw-cron/types/index.d.ts +1 -0
  96. package/dist/src/tools/openclaw-workclaw-cron/types/index.d.ts.map +1 -0
  97. package/dist/src/tools/openclaw-workclaw-cron/utils/index.d.ts +1 -0
  98. package/dist/src/tools/openclaw-workclaw-cron/utils/index.d.ts.map +1 -0
  99. package/dist/src/tools/openclaw-workclaw-system/index.d.ts +1 -0
  100. package/dist/src/tools/openclaw-workclaw-system/index.d.ts.map +1 -0
  101. package/dist/src/tools/openclaw-workclaw-system/src/get/index.d.ts +2 -4
  102. package/dist/src/tools/openclaw-workclaw-system/src/get/index.d.ts.map +1 -0
  103. package/dist/src/tools/openclaw-workclaw-system/src/token/index.d.ts +2 -4
  104. package/dist/src/tools/openclaw-workclaw-system/src/token/index.d.ts.map +1 -0
  105. package/dist/src/types.d.ts +7 -7
  106. package/dist/src/types.d.ts.map +1 -0
  107. package/dist/src/utils/content.d.ts +1 -0
  108. package/dist/src/utils/content.d.ts.map +1 -0
  109. package/openclaw.plugin.json +6 -0
  110. package/package.json +69 -45
  111. package/api.ts +0 -3
  112. package/dist/src/accounts.js +0 -279
  113. package/dist/src/api/accounts-api.js +0 -130
  114. package/dist/src/api/prompts-api.js +0 -103
  115. package/dist/src/api/session-api.js +0 -207
  116. package/dist/src/api/skills-api.js +0 -64
  117. package/dist/src/api/workspace.js +0 -30
  118. package/dist/src/channel.js +0 -199
  119. package/dist/src/config-schema.js +0 -56
  120. package/dist/src/connection/workclaw-client.js +0 -351
  121. package/dist/src/gateway/agent-handlers.js +0 -433
  122. package/dist/src/gateway/config-writer.js +0 -302
  123. package/dist/src/gateway/cron-tasks-handler.js +0 -188
  124. package/dist/src/gateway/message-context.js +0 -509
  125. package/dist/src/gateway/message-dispatcher.js +0 -572
  126. package/dist/src/gateway/reconnect.js +0 -210
  127. package/dist/src/gateway/skills-handler.js +0 -615
  128. package/dist/src/gateway/skills-list-handler.js +0 -233
  129. package/dist/src/gateway/tools-list-handler.js +0 -101
  130. package/dist/src/gateway/workclaw-gateway.js +0 -237
  131. package/dist/src/media/upload.js +0 -125
  132. package/dist/src/outbound/index.js +0 -123
  133. package/dist/src/outbound/workclaw-sender.js +0 -95
  134. package/dist/src/runtime.js +0 -374
  135. package/dist/src/secret-contract-api.js +0 -4
  136. package/dist/src/send.js +0 -1
  137. package/dist/src/setup-api.js +0 -3
  138. package/dist/src/setup-core.js +0 -13
  139. package/dist/src/setup-surface.js +0 -363
  140. package/dist/src/tools/openclaw-workclaw-cron/api/index.js +0 -209
  141. package/dist/src/tools/openclaw-workclaw-cron/index.js +0 -33
  142. package/dist/src/tools/openclaw-workclaw-cron/src/add/params.js +0 -152
  143. package/dist/src/tools/openclaw-workclaw-cron/src/add/sync.js +0 -162
  144. package/dist/src/tools/openclaw-workclaw-cron/src/disable/params.js +0 -80
  145. package/dist/src/tools/openclaw-workclaw-cron/src/disable/sync.js +0 -107
  146. package/dist/src/tools/openclaw-workclaw-cron/src/enable/params.js +0 -80
  147. package/dist/src/tools/openclaw-workclaw-cron/src/enable/sync.js +0 -107
  148. package/dist/src/tools/openclaw-workclaw-cron/src/notify/sync.js +0 -127
  149. package/dist/src/tools/openclaw-workclaw-cron/src/remove/params.js +0 -87
  150. package/dist/src/tools/openclaw-workclaw-cron/src/remove/sync.js +0 -107
  151. package/dist/src/tools/openclaw-workclaw-cron/src/update/params.js +0 -164
  152. package/dist/src/tools/openclaw-workclaw-cron/src/update/sync.js +0 -135
  153. package/dist/src/tools/openclaw-workclaw-cron/types/index.js +0 -4
  154. package/dist/src/tools/openclaw-workclaw-cron/utils/index.js +0 -122
  155. package/dist/src/tools/openclaw-workclaw-system/index.js +0 -15
  156. package/dist/src/tools/openclaw-workclaw-system/src/get/index.js +0 -64
  157. package/dist/src/tools/openclaw-workclaw-system/src/token/index.js +0 -78
  158. package/dist/src/types.js +0 -1
  159. package/dist/src/utils/content.js +0 -38
  160. package/index.ts +0 -325
  161. package/setup-entry.ts +0 -13
  162. package/src/accounts.ts +0 -360
  163. package/src/api/accounts-api.ts +0 -156
  164. package/src/api/prompts-api.ts +0 -122
  165. package/src/api/session-api.ts +0 -246
  166. package/src/api/skills-api.ts +0 -74
  167. package/src/api/workspace.ts +0 -45
  168. package/src/channel.ts +0 -226
  169. package/src/config-schema.ts +0 -60
  170. package/src/connection/workclaw-client.ts +0 -618
  171. package/src/gateway/agent-handlers.ts +0 -551
  172. package/src/gateway/config-writer.ts +0 -378
  173. package/src/gateway/cron-tasks-handler.ts +0 -230
  174. package/src/gateway/message-context.ts +0 -645
  175. package/src/gateway/message-dispatcher.ts +0 -688
  176. package/src/gateway/reconnect.ts +0 -260
  177. package/src/gateway/skills-handler.ts +0 -805
  178. package/src/gateway/skills-list-handler.ts +0 -332
  179. package/src/gateway/tools-list-handler.ts +0 -161
  180. package/src/gateway/workclaw-gateway.ts +0 -298
  181. package/src/media/upload.ts +0 -168
  182. package/src/outbound/index.ts +0 -191
  183. package/src/outbound/workclaw-sender.ts +0 -161
  184. package/src/runtime.ts +0 -520
  185. package/src/secret-contract-api.ts +0 -4
  186. package/src/send.ts +0 -1
  187. package/src/setup-api.ts +0 -3
  188. package/src/setup-core.ts +0 -25
  189. package/src/setup-surface.ts +0 -498
  190. package/src/tools/openclaw-workclaw-cron/api/index.ts +0 -326
  191. package/src/tools/openclaw-workclaw-cron/index.ts +0 -39
  192. package/src/tools/openclaw-workclaw-cron/src/add/params.ts +0 -177
  193. package/src/tools/openclaw-workclaw-cron/src/add/sync.ts +0 -188
  194. package/src/tools/openclaw-workclaw-cron/src/disable/params.ts +0 -100
  195. package/src/tools/openclaw-workclaw-cron/src/disable/sync.ts +0 -127
  196. package/src/tools/openclaw-workclaw-cron/src/enable/params.ts +0 -100
  197. package/src/tools/openclaw-workclaw-cron/src/enable/sync.ts +0 -127
  198. package/src/tools/openclaw-workclaw-cron/src/notify/sync.ts +0 -148
  199. package/src/tools/openclaw-workclaw-cron/src/remove/params.ts +0 -109
  200. package/src/tools/openclaw-workclaw-cron/src/remove/sync.ts +0 -127
  201. package/src/tools/openclaw-workclaw-cron/src/update/params.ts +0 -195
  202. package/src/tools/openclaw-workclaw-cron/src/update/sync.ts +0 -161
  203. package/src/tools/openclaw-workclaw-cron/types/index.ts +0 -55
  204. package/src/tools/openclaw-workclaw-cron/utils/index.ts +0 -141
  205. package/src/tools/openclaw-workclaw-system/index.ts +0 -17
  206. package/src/tools/openclaw-workclaw-system/src/get/index.ts +0 -77
  207. package/src/tools/openclaw-workclaw-system/src/token/index.ts +0 -93
  208. package/src/types.ts +0 -50
  209. package/src/utils/content.ts +0 -40
  210. package/tsconfig.json +0 -34
@@ -1,122 +0,0 @@
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
- }
@@ -1,15 +0,0 @@
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
- }
@@ -1,64 +0,0 @@
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
- }
@@ -1,78 +0,0 @@
1
- /**
2
- * 智小途系统信息工具 - 获取用户 AccessToken
3
- */
4
- import { resolveWorkclawAccountWithCache } from '../../../../accounts.js';
5
- import { getWorkclawAccessToken } from '../../../../connection/workclaw-client.js';
6
- /**
7
- * 构造工具返回结果
8
- */
9
- function json(data) {
10
- return {
11
- content: [{ type: 'text', text: JSON.stringify(data, null, 2) }],
12
- details: data,
13
- };
14
- }
15
- /**
16
- * 获取用户 AccessToken 工具
17
- */
18
- function getOpenclawWorkclawSystemTokenTool(api) {
19
- return (ctx) => {
20
- return {
21
- name: 'openclaw-workclaw-system-token',
22
- label: '智小途获取 AccessToken',
23
- description: '获取用户的 AccessToken',
24
- execute: async () => {
25
- api.logger.info('[智小途-系统信息] 开始获取 AccessToken');
26
- const accountId = ctx?.agentAccountId;
27
- if (!accountId) {
28
- api.logger.warn('[智小途-系统信息] 无法获取账户 ID');
29
- return json({ error: '无法获取账户 ID(accountId),请确保已配置账户' });
30
- }
31
- api.logger.info(`[智小途-系统信息] accountId=${accountId}`);
32
- const accountConfig = resolveWorkclawAccountWithCache({
33
- cfg: ctx.config,
34
- accountId,
35
- });
36
- if (!accountConfig.configured) {
37
- api.logger.error('[智小途-系统信息] 账户未配置');
38
- return json({ error: '账户未配置,请检查账户配置' });
39
- }
40
- const accConfig = accountConfig.config;
41
- try {
42
- const tokenCacheKey = accConfig.appKey || accountId;
43
- api.logger.info(`[智小途-系统信息] 正在获取 AccessToken,accountId=${accountId}`);
44
- const accessToken = await getWorkclawAccessToken(tokenCacheKey, {
45
- baseUrl: accConfig.baseUrl,
46
- appKey: accConfig.appKey,
47
- appSecret: accConfig.appSecret,
48
- allowInsecureTls: accConfig.allowInsecureTls,
49
- requestTimeout: accConfig.requestTimeout,
50
- });
51
- api.logger.info('[智小途-系统信息] AccessToken 获取成功');
52
- return json({
53
- code: 0,
54
- message: 'AccessToken 获取成功',
55
- data: {
56
- accessToken,
57
- },
58
- });
59
- }
60
- catch (error) {
61
- api.logger.error(`[智小途-系统信息] AccessToken 获取失败 ${error.message}`);
62
- return json({
63
- code: -1,
64
- error: error.message || 'AccessToken 获取失败',
65
- });
66
- }
67
- },
68
- };
69
- };
70
- }
71
- /**
72
- * 注册获取用户 AccessToken 工具
73
- */
74
- export function registerOpenclawWorkclawSystemTokenTool(api) {
75
- api.registerTool(getOpenclawWorkclawSystemTokenTool(api), {
76
- name: 'openclaw-workclaw-system-token',
77
- });
78
- }
package/dist/src/types.js DELETED
@@ -1 +0,0 @@
1
- export {};
@@ -1,38 +0,0 @@
1
- /**
2
- * Content extraction utilities - copied from SDK's internal implementations
3
- * node_modules/openclaw/dist/plugin-sdk/thread-bindings-SYAnWHuW.js (collectTextContentBlocks)
4
- * node_modules/openclaw/dist/auth-profiles-DRjqKE3G.js (extractToolResultText)
5
- */
6
- /**
7
- * Extract text blocks from chat content array.
8
- * Handles content format: [{ type: "text", text: "..." }]
9
- */
10
- export function collectTextContentBlocks(content) {
11
- if (!Array.isArray(content))
12
- return [];
13
- const parts = [];
14
- for (const block of content) {
15
- if (!block || typeof block !== "object")
16
- continue;
17
- const rec = block;
18
- if (rec.type === "text" && typeof rec.text === "string")
19
- parts.push(rec.text);
20
- }
21
- return parts;
22
- }
23
- /**
24
- * Extract plain text from a tool result object.
25
- * Handles result.content as array of text blocks or direct text fields.
26
- */
27
- export function extractToolResultText(result) {
28
- if (!result || typeof result !== "object")
29
- return;
30
- const record = result;
31
- const texts = collectTextContentBlocks(record.content).map((item) => {
32
- const trimmed = item.trim();
33
- return trimmed ? trimmed : void 0;
34
- }).filter((value) => Boolean(value));
35
- if (texts.length === 0)
36
- return;
37
- return texts.join("\n");
38
- }
package/index.ts DELETED
@@ -1,325 +0,0 @@
1
- import type { OpenClawPluginApi } from 'openclaw/plugin-sdk'
2
- import { mkdir, readFile, writeFile } from 'node:fs/promises'
3
- import path from 'node:path'
4
- import process from 'node:process'
5
- import { fileURLToPath } from 'node:url'
6
- import { emptyPluginConfigSchema } from 'openclaw/plugin-sdk'
7
- import { defineChannelPluginEntry } from 'openclaw/plugin-sdk/core'
8
-
9
- import { createAccountsApiHandler } from './src/api/accounts-api.js'
10
- import { createPromptsApiHandler } from './src/api/prompts-api.js'
11
- import { createSessionApiHandler } from './src/api/session-api.js'
12
- import { createSkillsApiHandler } from './src/api/skills-api.js'
13
- import { isDefaultWorkspace, resolveWorkspaceDir } from './src/api/workspace.js'
14
- import { workclawPlugin } from './src/channel.js'
15
- import { sendMessageWorkclaw } from './src/outbound/index.js'
16
- import {
17
- deleteToolContext,
18
- getToolContext,
19
- getToolResultHint,
20
- getWorkclawLogger,
21
- getWorkclawRuntime,
22
- setToolCallIdToRunIdMapping,
23
- setWorkclawRuntime,
24
- } from './src/runtime.js'
25
-
26
- import { registerAllOpenclawWorkclawCronTools } from './src/tools/openclaw-workclaw-cron/index.js'
27
-
28
- // ============================================================================
29
- // Tool output formatting helpers
30
- // ============================================================================
31
-
32
- function formatToolParams(toolName: string | undefined, params: unknown): string {
33
- if (!params || typeof params !== 'object') {
34
- return ''
35
- }
36
-
37
- const normalizedToolName = (toolName || '').toLowerCase().trim()
38
- const p = params as Record<string, unknown>
39
-
40
- try {
41
- if (normalizedToolName === 'exec' || normalizedToolName === 'bash' || normalizedToolName === 'shell') {
42
- const cmd = p.command || p.cmd
43
- if (cmd)
44
- return `command: ${String(cmd).slice(0, 200)}`
45
- }
46
- else if (
47
- normalizedToolName === 'read'
48
- || normalizedToolName === 'file_read'
49
- || normalizedToolName === 'view'
50
- ) {
51
- const p2 = p.path
52
- if (p2)
53
- return `path: ${p2}`
54
- }
55
- else if (
56
- normalizedToolName === 'write'
57
- || normalizedToolName === 'file_write'
58
- || normalizedToolName === 'edit'
59
- || normalizedToolName === 'patch'
60
- ) {
61
- const p2 = p.path
62
- if (p2)
63
- return `path: ${p2}`
64
- }
65
- else if (
66
- normalizedToolName === 'web_fetch'
67
- || normalizedToolName === 'fetch'
68
- || normalizedToolName === 'http_get'
69
- || normalizedToolName === 'http_request'
70
- || normalizedToolName === 'open_url'
71
- || normalizedToolName === 'browser_open'
72
- || normalizedToolName === 'open'
73
- ) {
74
- const u = p.url
75
- if (u)
76
- return `url: ${u}`
77
- }
78
- else if (
79
- normalizedToolName === 'search'
80
- || normalizedToolName === 'web_search'
81
- || normalizedToolName === 'google_search'
82
- || normalizedToolName === 'browser_search'
83
- || normalizedToolName === 'browser.search'
84
- ) {
85
- const q = p.query || p.q || p.search
86
- if (q)
87
- return `query: ${q}`
88
- }
89
- else if (
90
- normalizedToolName === 'image_generate'
91
- || normalizedToolName === 'generate_image'
92
- || normalizedToolName === 'dalle'
93
- || normalizedToolName === 'text_to_image'
94
- ) {
95
- const prompt = p.prompt
96
- if (prompt)
97
- return `prompt: ${String(prompt).slice(0, 200)}`
98
- }
99
- else if (
100
- normalizedToolName === 'code_interpreter'
101
- || normalizedToolName === 'python'
102
- || normalizedToolName === 'jupyter'
103
- ) {
104
- const code = p.code
105
- if (code)
106
- return `code: ${String(code).slice(0, 200)}`
107
- }
108
- else if (normalizedToolName === 'mcp_deliver' || normalizedToolName === 'deliver') {
109
- const target = p.target || p.to
110
- if (target)
111
- return `target: ${target}`
112
- }
113
- else {
114
- const entries = Object.entries(p)
115
- if (entries.length > 0) {
116
- return entries
117
- .map(([k, v]) => {
118
- const vStr = typeof v === 'string' ? v : JSON.stringify(v)
119
- return vStr.length > 100 ? `${k}: ${vStr.slice(0, 100)}...` : `${k}: ${vStr}`
120
- })
121
- .join('\n')
122
- }
123
- }
124
- }
125
- catch {
126
- return String(params)
127
- }
128
-
129
- return ''
130
- }
131
-
132
- function formatToolOutput(toolName: string | undefined, params: unknown, _result: unknown): string {
133
- return formatToolParams(toolName, params)
134
- }
135
-
136
- // ============================================================================
137
- // Tool hooks
138
- // ============================================================================
139
-
140
- function registerToolHooks(api: OpenClawPluginApi): void {
141
- api.on('agent_end', (event: any, ctx: any) => {
142
- const { runId } = ctx || {}
143
- if (runId) {
144
- deleteToolContext(runId)
145
- api.logger?.info?.(`[ToolHook] agent_end runId=${runId} cleaned up`)
146
- }
147
- return event
148
- })
149
-
150
- api.on('before_tool_call', (event: any, _ctx: any) => {
151
- api.logger?.info?.(`[ToolHook] before_tool_call event=${JSON.stringify(event)}`)
152
- })
153
-
154
- api.on('after_tool_call', (event: any, _ctx: any) => {
155
- api.logger?.info?.(`[ToolHook] after_tool_call event=${JSON.stringify(event)}`)
156
- const { runId, toolCallId, toolName, params, result } = event || {}
157
- const toolCtx = runId ? getToolContext(runId) : undefined
158
-
159
- if (toolCtx && result) {
160
- const content = formatToolOutput(toolName, params, result)
161
- if (content) {
162
- try {
163
- const cfg = getWorkclawRuntime().config.loadConfig()
164
- const formattedToolOutput = {
165
- name: getToolResultHint(toolName),
166
- toolName,
167
- content,
168
- state: 'result',
169
- }
170
- sendMessageWorkclaw({
171
- cfg,
172
- to: toolCtx.target,
173
- text: JSON.stringify(formattedToolOutput),
174
- msgType: '26',
175
- accountId: toolCtx.accountId,
176
- openConversationId: toolCtx.openConversationId,
177
- agentId: toolCtx.agentId,
178
- replyToMessageId: toolCtx.replyToMessageId,
179
- last: false,
180
- source: 'after_tool_call',
181
- }).catch((err) => {
182
- api.logger?.error?.(`[ToolHook] after_tool_call push failed: ${err}`)
183
- })
184
- api.logger?.info?.(`[ToolHook] after_tool_call pushed for toolName=${toolName}`)
185
- }
186
- catch (err) {
187
- api.logger?.error?.(`[ToolHook] after_tool_call push failed: ${err}`)
188
- }
189
- }
190
- }
191
-
192
- if (runId && toolCallId) {
193
- setToolCallIdToRunIdMapping(toolCallId, runId)
194
- }
195
-
196
- return event
197
- })
198
-
199
- api.on('tool_result_persist', (event: any, _ctx: any) => {
200
- return { message: event.message }
201
- })
202
-
203
- api.logger?.info?.(`[ToolHook] Tool execution hooks registered`)
204
- }
205
-
206
- // ============================================================================
207
- // Templates
208
- // ============================================================================
209
-
210
- const templateNames = ['SOUL.md', 'IDENTITY.md'] as const
211
-
212
- /**
213
- * 获取插件所在目录,兼容 Windows 下的 file:// URL 问题。
214
- * 4.2 的插件加载器在 Windows 上可能传入不带协议前缀的路径。
215
- */
216
- function getPluginDir(): string {
217
- try {
218
- const url = import.meta.url
219
- if (!url.startsWith('file://')) {
220
- // Windows 路径被直接传入(不带 file:// 前缀),直接取目录
221
- return path.dirname(url)
222
- }
223
- return path.dirname(fileURLToPath(url))
224
- }
225
- catch {
226
- return process.cwd()
227
- }
228
- }
229
-
230
- async function writeFileIfMissing(filePath: string, content: string): Promise<void> {
231
- try {
232
- await writeFile(filePath, content, { encoding: 'utf-8', flag: 'wx' })
233
- }
234
- catch (error) {
235
- if (
236
- error
237
- && typeof error === 'object'
238
- && 'code' in error
239
- && (error as NodeJS.ErrnoException).code === 'EEXIST'
240
- ) {
241
- return
242
- }
243
- throw error
244
- }
245
- }
246
-
247
- async function releaseTemplates(api: OpenClawPluginApi): Promise<void> {
248
- const workspaceDir = resolveWorkspaceDir(api)
249
- getWorkclawLogger().info(`workspaceDir: ${workspaceDir}`)
250
- // 模板文件在根目录的 templates/ 中,而不是 dist/templates/
251
- const currentDir = getPluginDir()
252
- const templatesDir = path.join(
253
- currentDir.endsWith('dist') ? path.dirname(currentDir) : currentDir,
254
- 'templates',
255
- )
256
- const shouldOverwrite = isDefaultWorkspace(api)
257
-
258
- await mkdir(workspaceDir, { recursive: true })
259
-
260
- await Promise.all(
261
- templateNames.map(async (name) => {
262
- const sourcePath = path.join(templatesDir, name)
263
- const targetPath = path.join(workspaceDir, name)
264
- const content = await readFile(sourcePath, 'utf-8')
265
- if (shouldOverwrite) {
266
- await writeFile(targetPath, content, { encoding: 'utf-8' })
267
- }
268
- else {
269
- await writeFileIfMissing(targetPath, content)
270
- }
271
- }),
272
- )
273
-
274
- api.logger.info(`openclaw-workclaw templates ready: ${workspaceDir}`)
275
- }
276
-
277
- // ============================================================================
278
- // Plugin entry point
279
- // ============================================================================
280
-
281
- export default defineChannelPluginEntry({
282
- id: 'openclaw-workclaw',
283
- name: 'openclaw-workclaw',
284
- description: '智小途 channel plugin',
285
- configSchema: emptyPluginConfigSchema() as any,
286
- plugin: workclawPlugin,
287
- registerFull(api) {
288
- setWorkclawRuntime(api.runtime)
289
-
290
- registerAllOpenclawWorkclawCronTools(api)
291
- registerToolHooks(api)
292
-
293
- api.registerService({
294
- id: 'openclaw-workclaw-templates',
295
- start: async () => {
296
- await releaseTemplates(api)
297
- },
298
- })
299
-
300
- api.registerHttpRoute({
301
- path: '/openclaw-workclaw/workspace/prompts',
302
- handler: createPromptsApiHandler(api),
303
- auth: 'plugin',
304
- })
305
-
306
- api.registerHttpRoute({
307
- path: '/openclaw-workclaw/accounts',
308
- handler: createAccountsApiHandler(api),
309
- auth: 'plugin',
310
- })
311
-
312
- api.registerHttpRoute({
313
- path: '/openclaw-workclaw/skills',
314
- handler: createSkillsApiHandler(api),
315
- auth: 'plugin',
316
- })
317
-
318
- api.registerHttpRoute({
319
- path: '/openclaw-workclaw/sessions',
320
- handler: createSessionApiHandler(api),
321
- auth: 'plugin',
322
- match: 'prefix',
323
- })
324
- },
325
- })
package/setup-entry.ts DELETED
@@ -1,13 +0,0 @@
1
- import { defineBundledChannelSetupEntry } from 'openclaw/plugin-sdk/channel-entry-contract'
2
-
3
- export default defineBundledChannelSetupEntry({
4
- importMetaUrl: import.meta.url,
5
- plugin: {
6
- specifier: './api.js',
7
- exportName: 'workclawPlugin',
8
- },
9
- secrets: {
10
- specifier: './src/secret-contract-api.js',
11
- exportName: 'channelSecrets',
12
- },
13
- })