@workclaw/openclaw-workclaw 1.0.25 → 1.0.27

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 (161) hide show
  1. package/dist/api.d.ts +4 -0
  2. package/dist/api.d.ts.map +1 -0
  3. package/dist/api.js +379 -0
  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 +12 -0
  7. package/dist/index.d.ts.map +1 -0
  8. package/dist/index.js +2088 -0
  9. package/dist/jiti-4i2h0FGP.js +4814 -0
  10. package/dist/setup-entry.d.ts +3 -0
  11. package/dist/setup-entry.d.ts.map +1 -0
  12. package/dist/setup-entry.js +182 -0
  13. package/dist/src/accounts.d.ts +67 -0
  14. package/dist/src/accounts.d.ts.map +1 -0
  15. package/dist/src/api/accounts-api.d.ts +3 -0
  16. package/dist/src/api/accounts-api.d.ts.map +1 -0
  17. package/dist/src/api/prompts-api.d.ts +3 -0
  18. package/dist/src/api/prompts-api.d.ts.map +1 -0
  19. package/dist/src/api/session-api.d.ts +3 -0
  20. package/dist/src/api/session-api.d.ts.map +1 -0
  21. package/dist/src/api/skills-api.d.ts +3 -0
  22. package/dist/src/api/skills-api.d.ts.map +1 -0
  23. package/dist/src/api/workspace.d.ts +4 -0
  24. package/dist/src/api/workspace.d.ts.map +1 -0
  25. package/dist/src/channel.d.ts +12 -0
  26. package/dist/src/channel.d.ts.map +1 -0
  27. package/dist/src/config-schema.d.ts +88 -0
  28. package/dist/src/config-schema.d.ts.map +1 -0
  29. package/dist/src/connection/workclaw-client.d.ts +149 -0
  30. package/dist/src/connection/workclaw-client.d.ts.map +1 -0
  31. package/dist/src/gateway/agent-handlers.d.ts +13 -0
  32. package/dist/src/gateway/agent-handlers.d.ts.map +1 -0
  33. package/dist/src/gateway/config-writer.d.ts +72 -0
  34. package/dist/src/gateway/config-writer.d.ts.map +1 -0
  35. package/dist/src/gateway/cron-tasks-handler.d.ts +20 -0
  36. package/dist/src/gateway/cron-tasks-handler.d.ts.map +1 -0
  37. package/dist/src/gateway/message-context.d.ts +81 -0
  38. package/dist/src/gateway/message-context.d.ts.map +1 -0
  39. package/dist/src/gateway/message-dispatcher.d.ts +17 -0
  40. package/dist/src/gateway/message-dispatcher.d.ts.map +1 -0
  41. package/dist/src/gateway/reconnect.d.ts +25 -0
  42. package/dist/src/gateway/reconnect.d.ts.map +1 -0
  43. package/dist/src/gateway/skills-handler.d.ts +30 -0
  44. package/dist/src/gateway/skills-handler.d.ts.map +1 -0
  45. package/dist/src/gateway/skills-list-handler.d.ts +28 -0
  46. package/dist/src/gateway/skills-list-handler.d.ts.map +1 -0
  47. package/dist/src/gateway/tools-list-handler.d.ts +31 -0
  48. package/dist/src/gateway/tools-list-handler.d.ts.map +1 -0
  49. package/dist/src/gateway/workclaw-gateway.d.ts +11 -0
  50. package/dist/src/gateway/workclaw-gateway.d.ts.map +1 -0
  51. package/dist/src/media/upload.d.ts +14 -0
  52. package/dist/src/media/upload.d.ts.map +1 -0
  53. package/dist/src/outbound/index.d.ts +39 -0
  54. package/dist/src/outbound/index.d.ts.map +1 -0
  55. package/dist/src/outbound/workclaw-sender.d.ts +38 -0
  56. package/dist/src/outbound/workclaw-sender.d.ts.map +1 -0
  57. package/dist/src/runtime.d.ts +118 -0
  58. package/dist/src/runtime.d.ts.map +1 -0
  59. package/dist/src/secret-contract-api.d.ts +5 -0
  60. package/dist/src/secret-contract-api.d.ts.map +1 -0
  61. package/{src/send.ts → 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 -0
  64. package/dist/src/setup-api.d.ts.map +1 -0
  65. package/dist/src/setup-core.d.ts +4 -0
  66. package/dist/src/setup-core.d.ts.map +1 -0
  67. package/dist/src/setup-surface.d.ts +8 -0
  68. package/dist/src/setup-surface.d.ts.map +1 -0
  69. package/dist/src/tools/openclaw-workclaw-cron/api/index.d.ts +91 -0
  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 +11 -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 +14 -0
  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 +16 -0
  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 +12 -0
  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 +12 -0
  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 +12 -0
  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 +12 -0
  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 +13 -0
  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 +12 -0
  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 +12 -0
  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 +15 -0
  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 +16 -0
  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 +53 -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 +41 -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 +11 -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 +6 -0
  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 +6 -0
  104. package/dist/src/tools/openclaw-workclaw-system/src/token/index.d.ts.map +1 -0
  105. package/dist/src/types.d.ts +39 -0
  106. package/dist/src/types.d.ts.map +1 -0
  107. package/dist/src/utils/content.d.ts +16 -0
  108. package/dist/src/utils/content.d.ts.map +1 -0
  109. package/openclaw.plugin.json +11 -0
  110. package/package.json +69 -45
  111. package/api.ts +0 -3
  112. package/index.ts +0 -325
  113. package/setup-entry.ts +0 -13
  114. package/src/accounts.ts +0 -360
  115. package/src/api/accounts-api.ts +0 -156
  116. package/src/api/prompts-api.ts +0 -122
  117. package/src/api/session-api.ts +0 -246
  118. package/src/api/skills-api.ts +0 -74
  119. package/src/api/workspace.ts +0 -45
  120. package/src/channel.ts +0 -226
  121. package/src/config-schema.ts +0 -60
  122. package/src/connection/workclaw-client.ts +0 -618
  123. package/src/gateway/agent-handlers.ts +0 -551
  124. package/src/gateway/config-writer.ts +0 -378
  125. package/src/gateway/cron-tasks-handler.ts +0 -230
  126. package/src/gateway/message-context.ts +0 -645
  127. package/src/gateway/message-dispatcher.ts +0 -688
  128. package/src/gateway/reconnect.ts +0 -260
  129. package/src/gateway/skills-handler.ts +0 -805
  130. package/src/gateway/skills-list-handler.ts +0 -332
  131. package/src/gateway/tools-list-handler.ts +0 -161
  132. package/src/gateway/workclaw-gateway.ts +0 -304
  133. package/src/media/upload.ts +0 -168
  134. package/src/outbound/index.ts +0 -191
  135. package/src/outbound/workclaw-sender.ts +0 -161
  136. package/src/runtime.ts +0 -520
  137. package/src/secret-contract-api.ts +0 -4
  138. package/src/setup-api.ts +0 -3
  139. package/src/setup-core.ts +0 -25
  140. package/src/setup-surface.ts +0 -498
  141. package/src/tools/openclaw-workclaw-cron/api/index.ts +0 -326
  142. package/src/tools/openclaw-workclaw-cron/index.ts +0 -39
  143. package/src/tools/openclaw-workclaw-cron/src/add/params.ts +0 -177
  144. package/src/tools/openclaw-workclaw-cron/src/add/sync.ts +0 -188
  145. package/src/tools/openclaw-workclaw-cron/src/disable/params.ts +0 -100
  146. package/src/tools/openclaw-workclaw-cron/src/disable/sync.ts +0 -127
  147. package/src/tools/openclaw-workclaw-cron/src/enable/params.ts +0 -100
  148. package/src/tools/openclaw-workclaw-cron/src/enable/sync.ts +0 -127
  149. package/src/tools/openclaw-workclaw-cron/src/notify/sync.ts +0 -148
  150. package/src/tools/openclaw-workclaw-cron/src/remove/params.ts +0 -109
  151. package/src/tools/openclaw-workclaw-cron/src/remove/sync.ts +0 -127
  152. package/src/tools/openclaw-workclaw-cron/src/update/params.ts +0 -195
  153. package/src/tools/openclaw-workclaw-cron/src/update/sync.ts +0 -161
  154. package/src/tools/openclaw-workclaw-cron/types/index.ts +0 -55
  155. package/src/tools/openclaw-workclaw-cron/utils/index.ts +0 -141
  156. package/src/tools/openclaw-workclaw-system/index.ts +0 -17
  157. package/src/tools/openclaw-workclaw-system/src/get/index.ts +0 -77
  158. package/src/tools/openclaw-workclaw-system/src/token/index.ts +0 -93
  159. package/src/types.ts +0 -50
  160. package/src/utils/content.ts +0 -40
  161. package/tsconfig.json +0 -34
package/dist/api.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export { workclawPlugin } from './src/channel.js';
2
+ export * from './src/setup-core.js';
3
+ export * from './src/setup-surface.js';
4
+ //# sourceMappingURL=api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,cAAc,qBAAqB,CAAA;AACnC,cAAc,wBAAwB,CAAA"}
package/dist/api.js ADDED
@@ -0,0 +1,379 @@
1
+ import { D as DEFAULT_ACCOUNT_ID, k as inspectWorkclawCredentials, l as resolveDefaultWorkclawAccountId, d as doFetchJson } from "./channel-DSvR6Irx.js";
2
+ import { w } from "./channel-DSvR6Irx.js";
3
+ import "node:path";
4
+ import "./jiti-4i2h0FGP.js";
5
+ import "node:fs/promises";
6
+ function formatTerminalLink(label, url, opts) {
7
+ const esc = "\x1B";
8
+ const safeLabel = label.replaceAll(esc, "");
9
+ const safeUrl = url.replaceAll(esc, "");
10
+ if (!process.stdout.isTTY) return opts?.fallback ?? `${safeLabel} (${safeUrl})`;
11
+ return `\x1B]8;;${safeUrl}\x07${safeLabel}\x1B]8;;\x07`;
12
+ }
13
+ function resolveDocsRoot() {
14
+ return "https://docs.openclaw.ai";
15
+ }
16
+ function formatDocsLink(path, label, opts) {
17
+ const trimmed = path.trim();
18
+ const docsRoot = resolveDocsRoot();
19
+ const url = trimmed.startsWith("http") ? trimmed : `${docsRoot}${trimmed.startsWith("/") ? trimmed : `/${trimmed}`}`;
20
+ return formatTerminalLink(label, url, {
21
+ fallback: url
22
+ });
23
+ }
24
+ function patchTopLevelChannelConfigSection(params) {
25
+ const channelConfig = { ...params.cfg.channels?.[params.channel] };
26
+ for (const field of params.clearFields ?? []) delete channelConfig[field];
27
+ return {
28
+ ...params.cfg,
29
+ channels: {
30
+ ...params.cfg.channels,
31
+ [params.channel]: {
32
+ ...channelConfig,
33
+ ...params.enabled ? { enabled: true } : {},
34
+ ...params.patch
35
+ }
36
+ }
37
+ };
38
+ }
39
+ const channel = "openclaw-workclaw";
40
+ function normalizeString(value) {
41
+ if (typeof value !== "string") {
42
+ return void 0;
43
+ }
44
+ const trimmed = value.trim();
45
+ return trimmed || void 0;
46
+ }
47
+ function trimTrailingSlash(value) {
48
+ return value.endsWith("/") ? value.slice(0, -1) : value;
49
+ }
50
+ function resolveSetupApiBases(cfg) {
51
+ const workclawCfg = cfg.channels?.["openclaw-workclaw"];
52
+ const configuredBaseUrl = normalizeString(workclawCfg?.baseUrl) ?? normalizeString(process.env.WORKCLAW_BASE_URL);
53
+ const configuredAuthBaseUrl = normalizeString(process.env.WORKCLAW_AUTH_BASE_URL);
54
+ const configuredOpenApiBaseUrl = normalizeString(process.env.WORKCLAW_OPEN_API_BASE_URL);
55
+ const defaultAuthBaseUrl = "https://workbrain.cn/backend-api";
56
+ const defaultOpenApiBaseUrl = `${defaultAuthBaseUrl}/open-apis`;
57
+ const fromBaseUrl = (() => {
58
+ if (!configuredBaseUrl) {
59
+ return null;
60
+ }
61
+ const normalized = trimTrailingSlash(configuredBaseUrl);
62
+ if (normalized.endsWith("/open-apis")) {
63
+ return {
64
+ authBaseUrl: normalized.slice(0, -"/open-apis".length),
65
+ openApiBaseUrl: normalized
66
+ };
67
+ }
68
+ return {
69
+ authBaseUrl: normalized,
70
+ openApiBaseUrl: `${normalized}/open-apis`
71
+ };
72
+ })();
73
+ return {
74
+ authBaseUrl: trimTrailingSlash(
75
+ configuredAuthBaseUrl ?? fromBaseUrl?.authBaseUrl ?? defaultAuthBaseUrl
76
+ ),
77
+ openApiBaseUrl: trimTrailingSlash(
78
+ configuredOpenApiBaseUrl ?? fromBaseUrl?.openApiBaseUrl ?? defaultOpenApiBaseUrl
79
+ ),
80
+ allowInsecureTls: workclawCfg?.allowInsecureTls,
81
+ requestTimeout: workclawCfg?.requestTimeout
82
+ };
83
+ }
84
+ function isWorkclawConfigured(cfg) {
85
+ const workclawCfg = cfg.channels?.["openclaw-workclaw"];
86
+ const isConfigured = (value) => {
87
+ const asString = normalizeString(value);
88
+ return !!asString;
89
+ };
90
+ const topLevelConfigured = isConfigured(workclawCfg?.appKey) && isConfigured(workclawCfg?.appSecret);
91
+ const accountConfigured = Object.values(workclawCfg?.accounts ?? {}).some((account) => {
92
+ if (!account || typeof account !== "object") {
93
+ return false;
94
+ }
95
+ const hasOwnAppKey = Object.prototype.hasOwnProperty.call(account, "appKey");
96
+ const hasOwnAppSecret = Object.prototype.hasOwnProperty.call(account, "appSecret");
97
+ const accountAppKeyConfigured = hasOwnAppKey ? isConfigured(account.appKey) : isConfigured(workclawCfg?.appKey);
98
+ const accountSecretConfigured = hasOwnAppSecret ? isConfigured(account.appSecret) : isConfigured(workclawCfg?.appSecret);
99
+ return accountAppKeyConfigured && accountSecretConfigured;
100
+ });
101
+ return topLevelConfigured || accountConfigured;
102
+ }
103
+ function patchWorkclawConfig(cfg, accountId, patch) {
104
+ const workclawCfg = cfg.channels?.["openclaw-workclaw"];
105
+ if (accountId === DEFAULT_ACCOUNT_ID) {
106
+ return patchTopLevelChannelConfigSection({
107
+ cfg,
108
+ channel,
109
+ enabled: true,
110
+ patch
111
+ });
112
+ }
113
+ const nextAccountPatch = {
114
+ ...workclawCfg?.accounts?.[accountId],
115
+ enabled: true,
116
+ ...patch
117
+ };
118
+ return patchTopLevelChannelConfigSection({
119
+ cfg,
120
+ channel,
121
+ enabled: true,
122
+ patch: {
123
+ accounts: {
124
+ ...workclawCfg?.accounts,
125
+ [accountId]: nextAccountPatch
126
+ }
127
+ }
128
+ });
129
+ }
130
+ async function noteWorkclawCredentialHelp(prompter) {
131
+ await prompter.note(
132
+ [
133
+ "智小途插件安装引导",
134
+ "",
135
+ "准备事项:",
136
+ "1. 访问 workbrain.cn 获取 App Key 和 App Secret",
137
+ "2. 确保您的账号已开通智小途服务",
138
+ "3. 准备好您的手机号(用于获取配置信息)",
139
+ "",
140
+ `文档: ${formatDocsLink("/channels/openclaw-workclaw", "智小途")}`
141
+ ].join("\n"),
142
+ "智小途配置"
143
+ );
144
+ }
145
+ async function promptWorkclawAppKey(params) {
146
+ return (await params.prompter.text({
147
+ message: "智小途 App Key",
148
+ initialValue: params.initialValue,
149
+ validate: (value) => value?.trim() ? void 0 : "App Key 不能为空"
150
+ })).trim();
151
+ }
152
+ async function promptWorkclawAppSecret(params) {
153
+ return (await params.prompter.text({
154
+ message: "智小途 App Secret",
155
+ initialValue: params.initialValue,
156
+ validate: (value) => value?.trim() ? void 0 : "App Secret 不能为空"
157
+ })).trim();
158
+ }
159
+ async function promptWorkclawPhone(params) {
160
+ return (await params.prompter.text({
161
+ message: "智小途手机号",
162
+ initialValue: params.initialValue,
163
+ validate: (value) => {
164
+ if (!value?.trim())
165
+ return "手机号不能为空";
166
+ if (!/^1[3-9]\d{9}$/.test(value.trim()))
167
+ return "请输入正确的手机号格式";
168
+ return void 0;
169
+ }
170
+ })).trim();
171
+ }
172
+ async function fetchAgentInfoByPhone(cfg, appKey, appSecret, phone, prompter) {
173
+ prompter.note?.("正在通过手机号获取配置信息...", "获取配置");
174
+ try {
175
+ const { authBaseUrl, openApiBaseUrl, allowInsecureTls, requestTimeout } = resolveSetupApiBases(cfg);
176
+ const tokenData = await doFetchJson(
177
+ `${authBaseUrl}/authen/v1/access_token/internal`,
178
+ {
179
+ method: "POST",
180
+ headers: {
181
+ "Content-Type": "application/json"
182
+ },
183
+ body: JSON.stringify({
184
+ app_key: appKey,
185
+ app_secret: appSecret
186
+ })
187
+ },
188
+ allowInsecureTls,
189
+ requestTimeout
190
+ );
191
+ if (tokenData.code !== 200 || !tokenData.data?.accessToken) {
192
+ prompter.note?.(`获取 Token 失败: ${tokenData.message || "未知错误"}`, "获取配置");
193
+ return null;
194
+ }
195
+ const accessToken = tokenData.data.accessToken;
196
+ const agentData = await doFetchJson(
197
+ `${openApiBaseUrl}/instance/local/agentInf`,
198
+ {
199
+ method: "POST",
200
+ headers: {
201
+ "Content-Type": "application/json",
202
+ "Authorization": `Bearer ${accessToken}`
203
+ },
204
+ body: JSON.stringify({
205
+ appKey,
206
+ phone
207
+ })
208
+ },
209
+ allowInsecureTls,
210
+ requestTimeout
211
+ );
212
+ if (agentData.code !== 200 || !agentData.data) {
213
+ prompter.note?.(`获取配置信息失败: ${agentData.message || "未知错误"}`, "获取配置");
214
+ return null;
215
+ }
216
+ prompter.note?.(`成功获取配置信息`, "获取配置");
217
+ return {
218
+ agentId: agentData.data.agentId,
219
+ userId: agentData.data.userId
220
+ };
221
+ } catch (error) {
222
+ prompter.note?.(`获取配置失败: ${error.message}`, "获取配置");
223
+ return null;
224
+ }
225
+ }
226
+ async function runNewAppFlow(params) {
227
+ const { prompter } = params;
228
+ let next = params.cfg;
229
+ await noteWorkclawCredentialHelp(prompter);
230
+ const appKey = await promptWorkclawAppKey({
231
+ prompter,
232
+ initialValue: normalizeString(process.env.WORKCLAW_APP_KEY)
233
+ });
234
+ const appSecret = await promptWorkclawAppSecret({
235
+ prompter,
236
+ initialValue: normalizeString(process.env.WORKCLAW_APP_SECRET)
237
+ });
238
+ const phone = await promptWorkclawPhone({
239
+ prompter,
240
+ initialValue: normalizeString(process.env.WORKCLAW_PHONE)
241
+ });
242
+ next = patchWorkclawConfig(next, DEFAULT_ACCOUNT_ID, {
243
+ appKey,
244
+ appSecret,
245
+ enabled: true
246
+ });
247
+ const agentInfo = await fetchAgentInfoByPhone(next, appKey, appSecret, phone, prompter);
248
+ if (agentInfo) {
249
+ const accountConfig = {
250
+ enabled: true
251
+ };
252
+ if (agentInfo.agentId) {
253
+ accountConfig.agentId = agentInfo.agentId;
254
+ }
255
+ if (agentInfo.userId) {
256
+ accountConfig.userId = agentInfo.userId;
257
+ }
258
+ next = patchWorkclawConfig(next, DEFAULT_ACCOUNT_ID, accountConfig);
259
+ }
260
+ next = patchWorkclawConfig(next, DEFAULT_ACCOUNT_ID, {
261
+ dmPolicy: "open",
262
+ allowFrom: ["*"]
263
+ });
264
+ await prompter.note("智小途配置完成!", "");
265
+ return { cfg: next };
266
+ }
267
+ async function runEditFlow(params) {
268
+ const workclawCfg = params.cfg.channels?.["openclaw-workclaw"];
269
+ const existingAppKey = workclawCfg?.appKey;
270
+ await params.prompter.note(
271
+ `当前配置的 App Key: ${existingAppKey ?? "(未配置)"}`,
272
+ "智小途配置"
273
+ );
274
+ const useExisting = await params.prompter.confirm({
275
+ message: `使用现有的智小途配置 (App Key: ${existingAppKey})?`,
276
+ initialValue: true
277
+ });
278
+ if (!useExisting) {
279
+ return runNewAppFlow(params);
280
+ }
281
+ await params.prompter.note("保持现有配置不变。", "");
282
+ return { cfg: params.cfg };
283
+ }
284
+ async function runProbeFlow(params) {
285
+ const workclawCfg = params.cfg.channels?.["openclaw-workclaw"];
286
+ const resolvedCredentials = inspectWorkclawCredentials(workclawCfg);
287
+ if (resolvedCredentials) {
288
+ try {
289
+ const probeResult = await resolvedCredentials();
290
+ params.prompter.note(
291
+ `智小途连接测试成功! ${probeResult.botName ? `Bot名称: ${probeResult.botName}` : ""}`,
292
+ "连接测试"
293
+ );
294
+ } catch {
295
+ params.prompter.note("智小途连接测试失败,请检查配置。", "连接测试");
296
+ }
297
+ }
298
+ return params.cfg;
299
+ }
300
+ const workclawSetupWizard = {
301
+ channel,
302
+ resolveAccountIdForConfigure: ({ accountOverride, defaultAccountId, cfg }) => (typeof accountOverride === "string" && accountOverride.trim() ? accountOverride.trim() : void 0) ?? resolveDefaultWorkclawAccountId(cfg) ?? 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
+ } catch {
320
+ }
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 });
347
+ if (result === null) {
348
+ return { cfg };
349
+ }
350
+ cfg = result.cfg;
351
+ } else {
352
+ cfg = (await runNewAppFlow({ cfg, prompter })).cfg;
353
+ }
354
+ await runProbeFlow({ cfg, prompter });
355
+ return { cfg };
356
+ },
357
+ disable: (cfg) => patchTopLevelChannelConfigSection({
358
+ cfg,
359
+ channel,
360
+ patch: { enabled: false }
361
+ })
362
+ };
363
+ function setWorkclawNamedAccountEnabled(cfg, accountId, enabled) {
364
+ return patchWorkclawConfig(cfg, accountId, { enabled });
365
+ }
366
+ const workclawSetupAdapter = {
367
+ resolveAccountId: ({ cfg, accountId }) => accountId?.trim() || resolveDefaultWorkclawAccountId(cfg),
368
+ applyAccountConfig: ({ cfg, accountId }) => {
369
+ const isDefault = !accountId || accountId === DEFAULT_ACCOUNT_ID;
370
+ return patchWorkclawConfig(cfg, isDefault ? DEFAULT_ACCOUNT_ID : accountId, { enabled: true });
371
+ }
372
+ };
373
+ export {
374
+ patchWorkclawConfig,
375
+ setWorkclawNamedAccountEnabled,
376
+ w as workclawPlugin,
377
+ workclawSetupAdapter,
378
+ workclawSetupWizard
379
+ };