@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,363 +0,0 @@
1
- import { DEFAULT_ACCOUNT_ID, formatDocsLink, patchTopLevelChannelConfigSection, } from "openclaw/plugin-sdk/setup";
2
- import { inspectWorkclawCredentials, resolveDefaultWorkclawAccountId } from "./accounts.js";
3
- import { doFetchJson } from "./connection/workclaw-client.js";
4
- const channel = "openclaw-workclaw";
5
- /**
6
- * 规范化字符串值
7
- */
8
- function normalizeString(value) {
9
- if (typeof value !== "string") {
10
- return undefined;
11
- }
12
- const trimmed = value.trim();
13
- return trimmed || undefined;
14
- }
15
- function trimTrailingSlash(value) {
16
- return value.endsWith("/") ? value.slice(0, -1) : value;
17
- }
18
- function resolveSetupApiBases(cfg) {
19
- const workclawCfg = cfg.channels?.["openclaw-workclaw"];
20
- const configuredBaseUrl = normalizeString(workclawCfg?.baseUrl) ??
21
- normalizeString(process.env.WORKCLAW_BASE_URL);
22
- const configuredAuthBaseUrl = normalizeString(process.env.WORKCLAW_AUTH_BASE_URL);
23
- const configuredOpenApiBaseUrl = normalizeString(process.env.WORKCLAW_OPEN_API_BASE_URL);
24
- const defaultAuthBaseUrl = "https://workbrain.cn/backend-api";
25
- const defaultOpenApiBaseUrl = `${defaultAuthBaseUrl}/open-apis`;
26
- const fromBaseUrl = (() => {
27
- if (!configuredBaseUrl) {
28
- return null;
29
- }
30
- const normalized = trimTrailingSlash(configuredBaseUrl);
31
- if (normalized.endsWith("/open-apis")) {
32
- return {
33
- authBaseUrl: normalized.slice(0, -"/open-apis".length),
34
- openApiBaseUrl: normalized,
35
- };
36
- }
37
- return {
38
- authBaseUrl: normalized,
39
- openApiBaseUrl: `${normalized}/open-apis`,
40
- };
41
- })();
42
- return {
43
- authBaseUrl: trimTrailingSlash(configuredAuthBaseUrl ?? fromBaseUrl?.authBaseUrl ?? defaultAuthBaseUrl),
44
- openApiBaseUrl: trimTrailingSlash(configuredOpenApiBaseUrl ?? fromBaseUrl?.openApiBaseUrl ?? defaultOpenApiBaseUrl),
45
- allowInsecureTls: workclawCfg?.allowInsecureTls,
46
- requestTimeout: workclawCfg?.requestTimeout,
47
- };
48
- }
49
- /**
50
- * 检查 Workclaw 是否已配置
51
- */
52
- function isWorkclawConfigured(cfg) {
53
- const workclawCfg = cfg.channels?.["openclaw-workclaw"];
54
- // 检查字符串值是否已配置
55
- const isConfigured = (value) => {
56
- const asString = normalizeString(value);
57
- return !!asString;
58
- };
59
- const topLevelConfigured = isConfigured(workclawCfg?.appKey) &&
60
- isConfigured(workclawCfg?.appSecret);
61
- const accountConfigured = Object.values(workclawCfg?.accounts ?? {}).some((account) => {
62
- if (!account || typeof account !== "object") {
63
- return false;
64
- }
65
- const hasOwnAppKey = Object.prototype.hasOwnProperty.call(account, "appKey");
66
- const hasOwnAppSecret = Object.prototype.hasOwnProperty.call(account, "appSecret");
67
- const accountAppKeyConfigured = hasOwnAppKey
68
- ? isConfigured(account.appKey)
69
- : isConfigured(workclawCfg?.appKey);
70
- const accountSecretConfigured = hasOwnAppSecret
71
- ? isConfigured(account.appSecret)
72
- : isConfigured(workclawCfg?.appSecret);
73
- return accountAppKeyConfigured && accountSecretConfigured;
74
- });
75
- return topLevelConfigured || accountConfigured;
76
- }
77
- /**
78
- * 修补 Workclaw 配置
79
- */
80
- export function patchWorkclawConfig(cfg, accountId, patch) {
81
- const workclawCfg = cfg.channels?.["openclaw-workclaw"];
82
- if (accountId === DEFAULT_ACCOUNT_ID) {
83
- return patchTopLevelChannelConfigSection({
84
- cfg,
85
- channel,
86
- enabled: true,
87
- patch,
88
- });
89
- }
90
- const nextAccountPatch = {
91
- ...workclawCfg?.accounts?.[accountId],
92
- enabled: true,
93
- ...patch,
94
- };
95
- return patchTopLevelChannelConfigSection({
96
- cfg,
97
- channel,
98
- enabled: true,
99
- patch: {
100
- accounts: {
101
- ...workclawCfg?.accounts,
102
- [accountId]: nextAccountPatch,
103
- },
104
- },
105
- });
106
- }
107
- /**
108
- * 提示凭证帮助信息
109
- */
110
- async function noteWorkclawCredentialHelp(prompter) {
111
- await prompter.note([
112
- "智小途插件安装引导",
113
- "",
114
- "准备事项:",
115
- "1. 访问 workbrain.cn 获取 App Key 和 App Secret",
116
- "2. 确保您的账号已开通智小途服务",
117
- "3. 准备好您的手机号(用于获取配置信息)",
118
- "",
119
- `文档: ${formatDocsLink("/channels/openclaw-workclaw", "智小途")}`,
120
- ].join("\n"), "智小途配置");
121
- }
122
- /**
123
- * 提示 App Key 输入
124
- */
125
- async function promptWorkclawAppKey(params) {
126
- return (await params.prompter.text({
127
- message: "智小途 App Key",
128
- initialValue: params.initialValue,
129
- validate: (value) => (value?.trim() ? undefined : "App Key 不能为空"),
130
- })).trim();
131
- }
132
- /**
133
- * 提示 App Secret 输入
134
- */
135
- async function promptWorkclawAppSecret(params) {
136
- return (await params.prompter.text({
137
- message: "智小途 App Secret",
138
- initialValue: params.initialValue,
139
- validate: (value) => (value?.trim() ? undefined : "App Secret 不能为空"),
140
- })).trim();
141
- }
142
- /**
143
- * 提示手机号输入
144
- */
145
- async function promptWorkclawPhone(params) {
146
- return (await params.prompter.text({
147
- message: "智小途手机号",
148
- initialValue: params.initialValue,
149
- validate: (value) => {
150
- if (!value?.trim())
151
- return "手机号不能为空";
152
- if (!/^1[3-9]\d{9}$/.test(value.trim()))
153
- return "请输入正确的手机号格式";
154
- return undefined;
155
- },
156
- })).trim();
157
- }
158
- /**
159
- * 通过手机号获取 agentId 和 userId
160
- */
161
- async function fetchAgentInfoByPhone(cfg, appKey, appSecret, phone, prompter) {
162
- prompter.note?.("正在通过手机号获取配置信息...", "获取配置");
163
- try {
164
- const { authBaseUrl, openApiBaseUrl, allowInsecureTls, requestTimeout } = resolveSetupApiBases(cfg);
165
- // 1. 获取 access token
166
- const tokenData = await doFetchJson(`${authBaseUrl}/authen/v1/access_token/internal`, {
167
- method: "POST",
168
- headers: {
169
- "Content-Type": "application/json",
170
- },
171
- body: JSON.stringify({
172
- app_key: appKey,
173
- app_secret: appSecret,
174
- }),
175
- }, allowInsecureTls, requestTimeout);
176
- if (tokenData.code !== 200 || !tokenData.data?.accessToken) {
177
- prompter.note?.(`获取 Token 失败: ${tokenData.message || "未知错误"}`, "获取配置");
178
- return null;
179
- }
180
- const accessToken = tokenData.data.accessToken;
181
- // 2. 通过手机号获取 agentId 和 userId
182
- const agentData = await doFetchJson(`${openApiBaseUrl}/instance/local/agentInf`, {
183
- method: "POST",
184
- headers: {
185
- "Content-Type": "application/json",
186
- Authorization: `Bearer ${accessToken}`,
187
- },
188
- body: JSON.stringify({
189
- appKey,
190
- phone,
191
- }),
192
- }, allowInsecureTls, requestTimeout);
193
- if (agentData.code !== 200 || !agentData.data) {
194
- prompter.note?.(`获取配置信息失败: ${agentData.message || "未知错误"}`, "获取配置");
195
- return null;
196
- }
197
- prompter.note?.(`成功获取配置信息`, "获取配置");
198
- return {
199
- agentId: agentData.data.agentId,
200
- userId: agentData.data.userId,
201
- };
202
- }
203
- catch (error) {
204
- prompter.note?.(`获取配置失败: ${error.message}`, "获取配置");
205
- return null;
206
- }
207
- }
208
- /**
209
- * 运行新应用流程
210
- */
211
- async function runNewAppFlow(params) {
212
- const { prompter } = params;
213
- let next = params.cfg;
214
- // 1. 显示帮助信息
215
- await noteWorkclawCredentialHelp(prompter);
216
- // 2. 获取 App Key
217
- const appKey = await promptWorkclawAppKey({
218
- prompter,
219
- initialValue: normalizeString(process.env.WORKCLAW_APP_KEY),
220
- });
221
- // 3. 获取 App Secret
222
- const appSecret = await promptWorkclawAppSecret({
223
- prompter,
224
- initialValue: normalizeString(process.env.WORKCLAW_APP_SECRET),
225
- });
226
- // 4. 获取手机号(通过手机号获取 agentId 和 userId)
227
- const phone = await promptWorkclawPhone({
228
- prompter,
229
- initialValue: normalizeString(process.env.WORKCLAW_PHONE),
230
- });
231
- // 5. 配置基础信息
232
- next = patchWorkclawConfig(next, DEFAULT_ACCOUNT_ID, {
233
- appKey,
234
- appSecret,
235
- connectionMode: "websocket",
236
- enabled: true,
237
- });
238
- // 6. 通过手机号获取 agentId 和 userId
239
- const agentInfo = await fetchAgentInfoByPhone(next, appKey, appSecret, phone, prompter);
240
- if (agentInfo) {
241
- // 更新配置中的 agentId 和 userId
242
- const accountConfig = {
243
- enabled: true,
244
- };
245
- if (agentInfo.agentId) {
246
- accountConfig.agentId = agentInfo.agentId;
247
- }
248
- if (agentInfo.userId) {
249
- accountConfig.userId = agentInfo.userId;
250
- }
251
- next = patchWorkclawConfig(next, DEFAULT_ACCOUNT_ID, accountConfig);
252
- }
253
- // 6. DM 策略固定为 open
254
- next = patchWorkclawConfig(next, DEFAULT_ACCOUNT_ID, {
255
- dmPolicy: "open",
256
- allowFrom: ["*"],
257
- });
258
- await prompter.note("智小途配置完成!", "");
259
- return { cfg: next };
260
- }
261
- /**
262
- * 运行编辑配置流程
263
- */
264
- async function runEditFlow(params) {
265
- const workclawCfg = params.cfg.channels?.["openclaw-workclaw"];
266
- const existingAppKey = workclawCfg?.appKey;
267
- await params.prompter.note(`当前配置的 App Key: ${existingAppKey ?? "(未配置)"}`, "智小途配置");
268
- const useExisting = await params.prompter.confirm({
269
- message: `使用现有的智小途配置 (App Key: ${existingAppKey})?`,
270
- initialValue: true,
271
- });
272
- if (!useExisting) {
273
- return runNewAppFlow(params);
274
- }
275
- await params.prompter.note("保持现有配置不变。", "");
276
- return { cfg: params.cfg };
277
- }
278
- /**
279
- * 运行凭证探测流程
280
- */
281
- async function runProbeFlow(params) {
282
- const workclawCfg = params.cfg.channels?.["openclaw-workclaw"];
283
- const resolvedCredentials = inspectWorkclawCredentials(workclawCfg);
284
- if (resolvedCredentials) {
285
- try {
286
- const probeResult = await resolvedCredentials();
287
- params.prompter.note(`智小途连接测试成功! ${probeResult.botName ? `Bot名称: ${probeResult.botName}` : ""}`, "连接测试");
288
- }
289
- catch {
290
- params.prompter.note("智小途连接测试失败,请检查配置。", "连接测试");
291
- }
292
- }
293
- return params.cfg;
294
- }
295
- export { workclawSetupAdapter } from "./setup-core.js";
296
- export const workclawSetupWizard = {
297
- channel,
298
- resolveAccountIdForConfigure: ({ accountOverride, defaultAccountId, cfg }) => (typeof accountOverride === "string" && accountOverride.trim()
299
- ? accountOverride.trim()
300
- : undefined) ??
301
- resolveDefaultWorkclawAccountId(cfg) ??
302
- defaultAccountId,
303
- resolveShouldPromptAccountIds: () => false,
304
- status: {
305
- configuredLabel: "已配置",
306
- unconfiguredLabel: "需要配置",
307
- configuredHint: "已配置",
308
- unconfiguredHint: "需要凭证",
309
- configuredScore: 2,
310
- unconfiguredScore: 0,
311
- resolveConfigured: ({ cfg }) => isWorkclawConfigured(cfg),
312
- resolveStatusLines: async ({ cfg, configured }) => {
313
- const workclawCfg = cfg.channels?.["openclaw-workclaw"];
314
- const resolvedCredentials = inspectWorkclawCredentials(workclawCfg);
315
- let probeResult = null;
316
- if (configured && resolvedCredentials) {
317
- try {
318
- probeResult = await resolvedCredentials();
319
- }
320
- catch { }
321
- }
322
- if (!configured) {
323
- return ["智小途: 需要 App Key 和 App Secret"];
324
- }
325
- if (probeResult?.ok) {
326
- return [`智小途: 已连接${probeResult.botName ? ` (${probeResult.botName})` : ""}`];
327
- }
328
- return ["智小途: 已配置 (连接未验证)"];
329
- },
330
- },
331
- prepare: async ({ cfg, credentialValues }) => {
332
- const alreadyConfigured = isWorkclawConfigured(cfg);
333
- if (alreadyConfigured) {
334
- return {
335
- credentialValues: { ...credentialValues, _flow: "edit" },
336
- };
337
- }
338
- return {
339
- credentialValues: { ...credentialValues, _flow: "new" },
340
- };
341
- },
342
- credentials: [],
343
- finalize: async ({ cfg, prompter, options, credentialValues }) => {
344
- const flow = credentialValues._flow ?? "new";
345
- if (flow === "edit") {
346
- const result = await runEditFlow({ cfg, prompter, options });
347
- if (result === null) {
348
- return { cfg };
349
- }
350
- cfg = result.cfg;
351
- }
352
- else {
353
- cfg = (await runNewAppFlow({ cfg, prompter, options })).cfg;
354
- }
355
- await runProbeFlow({ cfg, prompter });
356
- return { cfg };
357
- },
358
- disable: (cfg) => patchTopLevelChannelConfigSection({
359
- cfg,
360
- channel,
361
- patch: { enabled: false },
362
- }),
363
- };
@@ -1,209 +0,0 @@
1
- /**
2
- * 智小途定时任务工具 - 后端接口封装
3
- */
4
- import { resolveWorkclawAccountWithCache } from '../../../accounts.js';
5
- import { doFetchJson, getWorkclawAccessToken, normalizeBaseUrl } from '../../../connection/workclaw-client.js';
6
- const DEFAULT_MAX_RETRIES = 3;
7
- const DEFAULT_RETRY_DELAY_MS = 1000;
8
- /**
9
- * 睡眠函数
10
- */
11
- function sleep(ms) {
12
- return new Promise(resolve => setTimeout(resolve, ms));
13
- }
14
- /**
15
- * 带重试机制的 fetch 调用
16
- */
17
- async function fetchWithRetry(fetchFn, options = {}) {
18
- const maxRetries = options.maxRetries ?? DEFAULT_MAX_RETRIES;
19
- const retryDelayMs = options.retryDelayMs ?? DEFAULT_RETRY_DELAY_MS;
20
- const retryableErrors = options.retryableErrors ?? [
21
- 'ECONNREFUSED',
22
- 'ETIMEDOUT',
23
- 'ENOTFOUND',
24
- 'ENETUNREACH',
25
- 'EAI_AGAIN',
26
- ];
27
- let lastError = '';
28
- let attempts = 0;
29
- for (let i = 0; i <= maxRetries; i++) {
30
- attempts = i + 1;
31
- try {
32
- const data = await fetchFn();
33
- return { data, attempts };
34
- }
35
- catch (error) {
36
- lastError = error.message || String(error);
37
- const isRetryable = retryableErrors.some(e => lastError.toLowerCase().includes(e.toLowerCase()));
38
- if (i < maxRetries && isRetryable) {
39
- const delay = retryDelayMs * 2 ** i;
40
- await sleep(delay);
41
- continue;
42
- }
43
- break;
44
- }
45
- }
46
- return { error: lastError, attempts };
47
- }
48
- /**
49
- * 脱敏日志输出(隐藏敏感字段)
50
- */
51
- function sanitizePayload(payload) {
52
- const sensitiveFields = [
53
- 'password',
54
- 'secret',
55
- 'token',
56
- 'authorization',
57
- 'appSecret',
58
- 'appSecret',
59
- ];
60
- const sanitized = {};
61
- for (const [key, value] of Object.entries(payload)) {
62
- const lowerKey = key.toLowerCase();
63
- if (sensitiveFields.some(f => lowerKey.includes(f))) {
64
- sanitized[key] = '***';
65
- }
66
- else if (typeof value === 'object' && value !== null) {
67
- sanitized[key] = sanitizePayload(value);
68
- }
69
- else {
70
- sanitized[key] = value;
71
- }
72
- }
73
- return sanitized;
74
- }
75
- /**
76
- * 调用后端 API 的通用方法
77
- * @param api - OpenClaw API 实例
78
- * @param accountId - 账户 ID
79
- * @param path - API 路径
80
- * @param payload - 请求体
81
- * @param options - 可选配置
82
- * @returns 接口调用结果
83
- */
84
- export async function callBackendApi(api, accountId, path, payload, options = {}) {
85
- try {
86
- const account = resolveWorkclawAccountWithCache({
87
- cfg: api.config,
88
- accountId,
89
- });
90
- if (!account.configured) {
91
- api.logger.error(`[智小途-定时任务] 账户未配置 accountId=${accountId}`);
92
- return { success: false, error: 'Account not configured' };
93
- }
94
- const accConfig = account.config;
95
- const tokenCacheKey = accConfig.appKey || accountId;
96
- const baseUrl = normalizeBaseUrl(accConfig.baseUrl);
97
- api.logger.info(`[智小途-定时任务] 正在获取认证 token,accountId=${accountId}`);
98
- const token = await getWorkclawAccessToken(tokenCacheKey, {
99
- baseUrl: accConfig.baseUrl,
100
- appKey: accConfig.appKey,
101
- appSecret: accConfig.appSecret,
102
- allowInsecureTls: accConfig.allowInsecureTls,
103
- requestTimeout: accConfig.requestTimeout,
104
- });
105
- const requestUrl = `${baseUrl}/open-apis${path}`;
106
- const sanitizedPayload = sanitizePayload(payload);
107
- api.logger.info(`[智小途-定时任务] 调用接口 ${requestUrl}`);
108
- api.logger.info(`[智小途-定时任务] 请求参数 ${JSON.stringify(sanitizedPayload)}`);
109
- const maxRetries = options.maxRetries ?? DEFAULT_MAX_RETRIES;
110
- const fetchResult = await fetchWithRetry(() => doFetchJson(requestUrl, {
111
- method: 'POST',
112
- headers: {
113
- 'Content-Type': 'application/json',
114
- 'Authorization': `Bearer ${token}`,
115
- },
116
- body: JSON.stringify(payload),
117
- }, accConfig.allowInsecureTls, accConfig.requestTimeout), { maxRetries });
118
- if (fetchResult.error) {
119
- api.logger.error(`[智小途-定时任务] 接口调用失败(已重试 ${fetchResult.attempts} 次): ${fetchResult.error}`);
120
- return { success: false, error: fetchResult.error, attempts: fetchResult.attempts };
121
- }
122
- const data = fetchResult.data;
123
- api.logger.info(`[智小途-定时任务] 接口响应(尝试 ${fetchResult.attempts} 次): ${JSON.stringify(data)}`);
124
- if (data?.code === 200 || data?.code === 0) {
125
- return { success: true, data, attempts: fetchResult.attempts };
126
- }
127
- else {
128
- const errorMsg = data?.message || data?.msg || 'Unknown error';
129
- api.logger.error(`[智小途-定时任务] 接口返回错误 ${errorMsg}`);
130
- return { success: false, error: errorMsg };
131
- }
132
- }
133
- catch (error) {
134
- api.logger.error(`[智小途-定时任务] 接口调用异常 ${error.message}`);
135
- return { success: false, error: error.message };
136
- }
137
- }
138
- /**
139
- * 调用新增定时任务接口
140
- */
141
- export async function callCronJobAdd(api, accountId, payload) {
142
- api.logger.info(`[智小途-定时任务] 新增定时任务 jobId=${payload.jobId} name=${payload.name}`);
143
- const result = await callBackendApi(api, accountId, '/cron/job/add', {
144
- clawJobId: payload.jobId,
145
- name: payload.name,
146
- kind: payload.kind,
147
- expr: payload.expr || '',
148
- message: payload.message,
149
- agentId: payload.messageId || '0',
150
- });
151
- return { success: result.success, data: result.data, error: result.error };
152
- }
153
- /**
154
- * 调用删除定时任务接口
155
- */
156
- export async function callCronJobRemove(api, accountId, payload) {
157
- api.logger.info(`[智小途-定时任务] 删除定时任务 jobId=${payload.jobId}`);
158
- const result = await callBackendApi(api, accountId, '/cron/job/del', {
159
- clawJobId: payload.jobId,
160
- });
161
- return { success: result.success, data: result.data, error: result.error };
162
- }
163
- /**
164
- * 调用更新定时任务接口
165
- */
166
- export async function callCronJobUpdate(api, accountId, payload) {
167
- api.logger.info(`[智小途-定时任务] 更新定时任务 jobId=${payload.jobId} name=${payload.name} agentId=${payload.agentId}`);
168
- const result = await callBackendApi(api, accountId, '/cron/job/update', {
169
- clawJobId: payload.jobId,
170
- name: payload.name,
171
- kind: payload.kind,
172
- expr: payload.expr || '',
173
- message: payload.message,
174
- agentId: payload.agentId || '0',
175
- });
176
- return { success: result.success, data: result.data, error: result.error };
177
- }
178
- /**
179
- * 调用启用定时任务接口
180
- */
181
- export async function callCronJobEnabled(api, accountId, payload) {
182
- api.logger.info(`[智小途-定时任务] 启用定时任务 jobId=${payload.jobId}`);
183
- const result = await callBackendApi(api, accountId, '/cron/job/enabled', {
184
- clawJobId: payload.jobId,
185
- });
186
- return { success: result.success, data: result.data, error: result.error };
187
- }
188
- /**
189
- * 调用禁用定时任务接口
190
- */
191
- export async function callCronJobDisabled(api, accountId, payload) {
192
- api.logger.info(`[智小途-定时任务] 禁用定时任务 jobId=${payload.jobId}`);
193
- const result = await callBackendApi(api, accountId, '/cron/job/disabled', {
194
- clawJobId: payload.jobId,
195
- });
196
- return { success: result.success, data: result.data, error: result.error };
197
- }
198
- /**
199
- * 调用定时任务触发通知接口
200
- */
201
- export async function callCronJobMessage(api, accountId, payload) {
202
- api.logger.info(`[智小途-定时任务] 定时任务触发通知 jobId=${payload.jobId} message=${payload.message} agentId=${payload.agentId}`);
203
- const result = await callBackendApi(api, accountId, '/cron/job/message', {
204
- clawJobId: payload.jobId,
205
- message: payload.message,
206
- agentId: payload.agentId || '0',
207
- });
208
- return { success: result.success, data: result.data, error: result.error };
209
- }
@@ -1,33 +0,0 @@
1
- /**
2
- * 智小途定时任务工具 - 统一出口
3
- *
4
- * 提供统一的工具注册入口,一次性注册所有定时任务相关工具
5
- */
6
- import { registerOpenclawWorkclawCronAddParamsTool } from './src/add/params.js';
7
- import { registerOpenclawWorkclawCronAddSyncTool } from './src/add/sync.js';
8
- import { registerOpenclawWorkclawCronDisableParamsTool } from './src/disable/params.js';
9
- import { registerOpenclawWorkclawCronDisableSyncTool } from './src/disable/sync.js';
10
- import { registerOpenclawWorkclawCronEnableParamsTool } from './src/enable/params.js';
11
- import { registerOpenclawWorkclawCronEnableSyncTool } from './src/enable/sync.js';
12
- import { registerOpenclawWorkclawCronNotifySyncTool } from './src/notify/sync.js';
13
- import { registerOpenclawWorkclawCronRemoveParamsTool } from './src/remove/params.js';
14
- import { registerOpenclawWorkclawCronRemoveSyncTool } from './src/remove/sync.js';
15
- import { registerOpenclawWorkclawCronUpdateParamsTool } from './src/update/params.js';
16
- import { registerOpenclawWorkclawCronUpdateSyncTool } from './src/update/sync.js';
17
- /**
18
- * 统一注册所有定时任务工具
19
- * @param api - OpenClaw API 实例
20
- */
21
- export function registerAllOpenclawWorkclawCronTools(api) {
22
- registerOpenclawWorkclawCronAddParamsTool(api);
23
- registerOpenclawWorkclawCronRemoveParamsTool(api);
24
- registerOpenclawWorkclawCronUpdateParamsTool(api);
25
- registerOpenclawWorkclawCronEnableParamsTool(api);
26
- registerOpenclawWorkclawCronDisableParamsTool(api);
27
- registerOpenclawWorkclawCronAddSyncTool(api);
28
- registerOpenclawWorkclawCronRemoveSyncTool(api);
29
- registerOpenclawWorkclawCronUpdateSyncTool(api);
30
- registerOpenclawWorkclawCronEnableSyncTool(api);
31
- registerOpenclawWorkclawCronDisableSyncTool(api);
32
- registerOpenclawWorkclawCronNotifySyncTool(api);
33
- }