@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.
- package/dist/api.d.ts +4 -3
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +379 -3
- package/dist/channel-DSvR6Irx.js +50017 -0
- package/dist/cron-tasks-handler-C-mP3VmV.js +152 -0
- package/dist/index.d.ts +5 -4
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2056 -232
- package/dist/jiti-4i2h0FGP.js +4814 -0
- package/dist/setup-entry.d.ts +2 -1
- package/dist/setup-entry.d.ts.map +1 -0
- package/dist/setup-entry.js +181 -11
- package/dist/src/accounts.d.ts +3 -2
- package/dist/src/accounts.d.ts.map +1 -0
- package/dist/src/api/accounts-api.d.ts +2 -1
- package/dist/src/api/accounts-api.d.ts.map +1 -0
- package/dist/src/api/prompts-api.d.ts +2 -1
- package/dist/src/api/prompts-api.d.ts.map +1 -0
- package/dist/src/api/session-api.d.ts +2 -1
- package/dist/src/api/session-api.d.ts.map +1 -0
- package/dist/src/api/skills-api.d.ts +2 -1
- package/dist/src/api/skills-api.d.ts.map +1 -0
- package/dist/src/api/workspace.d.ts +2 -1
- package/dist/src/api/workspace.d.ts.map +1 -0
- package/dist/src/channel.d.ts +3 -2
- package/dist/src/channel.d.ts.map +1 -0
- package/dist/src/config-schema.d.ts +1 -6
- package/dist/src/config-schema.d.ts.map +1 -0
- package/dist/src/connection/workclaw-client.d.ts +6 -4
- package/dist/src/connection/workclaw-client.d.ts.map +1 -0
- package/dist/src/gateway/agent-handlers.d.ts +3 -2
- package/dist/src/gateway/agent-handlers.d.ts.map +1 -0
- package/dist/src/gateway/config-writer.d.ts +3 -2
- package/dist/src/gateway/config-writer.d.ts.map +1 -0
- package/dist/src/gateway/cron-tasks-handler.d.ts +1 -0
- package/dist/src/gateway/cron-tasks-handler.d.ts.map +1 -0
- package/dist/src/gateway/message-context.d.ts +2 -1
- package/dist/src/gateway/message-context.d.ts.map +1 -0
- package/dist/src/gateway/message-dispatcher.d.ts +3 -4
- package/dist/src/gateway/message-dispatcher.d.ts.map +1 -0
- package/dist/src/gateway/reconnect.d.ts +3 -5
- package/dist/src/gateway/reconnect.d.ts.map +1 -0
- package/dist/src/gateway/skills-handler.d.ts +1 -0
- package/dist/src/gateway/skills-handler.d.ts.map +1 -0
- package/dist/src/gateway/skills-list-handler.d.ts +1 -0
- package/dist/src/gateway/skills-list-handler.d.ts.map +1 -0
- package/dist/src/gateway/tools-list-handler.d.ts +1 -0
- package/dist/src/gateway/tools-list-handler.d.ts.map +1 -0
- package/dist/src/gateway/workclaw-gateway.d.ts +4 -7
- package/dist/src/gateway/workclaw-gateway.d.ts.map +1 -0
- package/dist/src/media/upload.d.ts +1 -0
- package/dist/src/media/upload.d.ts.map +1 -0
- package/dist/src/outbound/index.d.ts +9 -6
- package/dist/src/outbound/index.d.ts.map +1 -0
- package/dist/src/outbound/workclaw-sender.d.ts +6 -4
- package/dist/src/outbound/workclaw-sender.d.ts.map +1 -0
- package/dist/src/runtime.d.ts +11 -9
- package/dist/src/runtime.d.ts.map +1 -0
- package/dist/src/secret-contract-api.d.ts +1 -0
- package/dist/src/secret-contract-api.d.ts.map +1 -0
- package/dist/src/send.d.ts +2 -1
- package/dist/src/send.d.ts.map +1 -0
- package/dist/src/setup-api.d.ts +4 -3
- package/dist/src/setup-api.d.ts.map +1 -0
- package/dist/src/setup-core.d.ts +2 -1
- package/dist/src/setup-core.d.ts.map +1 -0
- package/dist/src/setup-surface.d.ts +3 -2
- package/dist/src/setup-surface.d.ts.map +1 -0
- package/dist/src/tools/openclaw-workclaw-cron/api/index.d.ts +2 -4
- package/dist/src/tools/openclaw-workclaw-cron/api/index.d.ts.map +1 -0
- package/dist/src/tools/openclaw-workclaw-cron/index.d.ts +1 -0
- package/dist/src/tools/openclaw-workclaw-cron/index.d.ts.map +1 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/add/params.d.ts +2 -4
- package/dist/src/tools/openclaw-workclaw-cron/src/add/params.d.ts.map +1 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/add/sync.d.ts +2 -4
- package/dist/src/tools/openclaw-workclaw-cron/src/add/sync.d.ts.map +1 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/disable/params.d.ts +2 -4
- package/dist/src/tools/openclaw-workclaw-cron/src/disable/params.d.ts.map +1 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/disable/sync.d.ts +2 -4
- package/dist/src/tools/openclaw-workclaw-cron/src/disable/sync.d.ts.map +1 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/enable/params.d.ts +2 -4
- package/dist/src/tools/openclaw-workclaw-cron/src/enable/params.d.ts.map +1 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/enable/sync.d.ts +2 -4
- package/dist/src/tools/openclaw-workclaw-cron/src/enable/sync.d.ts.map +1 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/notify/sync.d.ts +2 -6
- package/dist/src/tools/openclaw-workclaw-cron/src/notify/sync.d.ts.map +1 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/remove/params.d.ts +2 -4
- package/dist/src/tools/openclaw-workclaw-cron/src/remove/params.d.ts.map +1 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/remove/sync.d.ts +2 -4
- package/dist/src/tools/openclaw-workclaw-cron/src/remove/sync.d.ts.map +1 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/update/params.d.ts +2 -4
- package/dist/src/tools/openclaw-workclaw-cron/src/update/params.d.ts.map +1 -0
- package/dist/src/tools/openclaw-workclaw-cron/src/update/sync.d.ts +2 -4
- package/dist/src/tools/openclaw-workclaw-cron/src/update/sync.d.ts.map +1 -0
- package/dist/src/tools/openclaw-workclaw-cron/types/index.d.ts +1 -0
- package/dist/src/tools/openclaw-workclaw-cron/types/index.d.ts.map +1 -0
- package/dist/src/tools/openclaw-workclaw-cron/utils/index.d.ts +1 -0
- package/dist/src/tools/openclaw-workclaw-cron/utils/index.d.ts.map +1 -0
- package/dist/src/tools/openclaw-workclaw-system/index.d.ts +1 -0
- package/dist/src/tools/openclaw-workclaw-system/index.d.ts.map +1 -0
- package/dist/src/tools/openclaw-workclaw-system/src/get/index.d.ts +2 -4
- package/dist/src/tools/openclaw-workclaw-system/src/get/index.d.ts.map +1 -0
- package/dist/src/tools/openclaw-workclaw-system/src/token/index.d.ts +2 -4
- package/dist/src/tools/openclaw-workclaw-system/src/token/index.d.ts.map +1 -0
- package/dist/src/types.d.ts +7 -7
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/utils/content.d.ts +1 -0
- package/dist/src/utils/content.d.ts.map +1 -0
- package/openclaw.plugin.json +6 -0
- package/package.json +69 -45
- package/api.ts +0 -3
- package/dist/src/accounts.js +0 -279
- package/dist/src/api/accounts-api.js +0 -130
- package/dist/src/api/prompts-api.js +0 -103
- package/dist/src/api/session-api.js +0 -207
- package/dist/src/api/skills-api.js +0 -64
- package/dist/src/api/workspace.js +0 -30
- package/dist/src/channel.js +0 -199
- package/dist/src/config-schema.js +0 -56
- package/dist/src/connection/workclaw-client.js +0 -351
- package/dist/src/gateway/agent-handlers.js +0 -433
- package/dist/src/gateway/config-writer.js +0 -302
- package/dist/src/gateway/cron-tasks-handler.js +0 -188
- package/dist/src/gateway/message-context.js +0 -509
- package/dist/src/gateway/message-dispatcher.js +0 -572
- package/dist/src/gateway/reconnect.js +0 -210
- package/dist/src/gateway/skills-handler.js +0 -615
- package/dist/src/gateway/skills-list-handler.js +0 -233
- package/dist/src/gateway/tools-list-handler.js +0 -101
- package/dist/src/gateway/workclaw-gateway.js +0 -237
- package/dist/src/media/upload.js +0 -125
- package/dist/src/outbound/index.js +0 -123
- package/dist/src/outbound/workclaw-sender.js +0 -95
- package/dist/src/runtime.js +0 -374
- package/dist/src/secret-contract-api.js +0 -4
- package/dist/src/send.js +0 -1
- package/dist/src/setup-api.js +0 -3
- package/dist/src/setup-core.js +0 -13
- package/dist/src/setup-surface.js +0 -363
- package/dist/src/tools/openclaw-workclaw-cron/api/index.js +0 -209
- package/dist/src/tools/openclaw-workclaw-cron/index.js +0 -33
- package/dist/src/tools/openclaw-workclaw-cron/src/add/params.js +0 -152
- package/dist/src/tools/openclaw-workclaw-cron/src/add/sync.js +0 -162
- package/dist/src/tools/openclaw-workclaw-cron/src/disable/params.js +0 -80
- package/dist/src/tools/openclaw-workclaw-cron/src/disable/sync.js +0 -107
- package/dist/src/tools/openclaw-workclaw-cron/src/enable/params.js +0 -80
- package/dist/src/tools/openclaw-workclaw-cron/src/enable/sync.js +0 -107
- package/dist/src/tools/openclaw-workclaw-cron/src/notify/sync.js +0 -127
- package/dist/src/tools/openclaw-workclaw-cron/src/remove/params.js +0 -87
- package/dist/src/tools/openclaw-workclaw-cron/src/remove/sync.js +0 -107
- package/dist/src/tools/openclaw-workclaw-cron/src/update/params.js +0 -164
- package/dist/src/tools/openclaw-workclaw-cron/src/update/sync.js +0 -135
- package/dist/src/tools/openclaw-workclaw-cron/types/index.js +0 -4
- package/dist/src/tools/openclaw-workclaw-cron/utils/index.js +0 -122
- package/dist/src/tools/openclaw-workclaw-system/index.js +0 -15
- package/dist/src/tools/openclaw-workclaw-system/src/get/index.js +0 -64
- package/dist/src/tools/openclaw-workclaw-system/src/token/index.js +0 -78
- package/dist/src/types.js +0 -1
- package/dist/src/utils/content.js +0 -38
- package/index.ts +0 -325
- package/setup-entry.ts +0 -13
- package/src/accounts.ts +0 -360
- package/src/api/accounts-api.ts +0 -156
- package/src/api/prompts-api.ts +0 -122
- package/src/api/session-api.ts +0 -246
- package/src/api/skills-api.ts +0 -74
- package/src/api/workspace.ts +0 -45
- package/src/channel.ts +0 -226
- package/src/config-schema.ts +0 -60
- package/src/connection/workclaw-client.ts +0 -618
- package/src/gateway/agent-handlers.ts +0 -551
- package/src/gateway/config-writer.ts +0 -378
- package/src/gateway/cron-tasks-handler.ts +0 -230
- package/src/gateway/message-context.ts +0 -645
- package/src/gateway/message-dispatcher.ts +0 -688
- package/src/gateway/reconnect.ts +0 -260
- package/src/gateway/skills-handler.ts +0 -805
- package/src/gateway/skills-list-handler.ts +0 -332
- package/src/gateway/tools-list-handler.ts +0 -161
- package/src/gateway/workclaw-gateway.ts +0 -298
- package/src/media/upload.ts +0 -168
- package/src/outbound/index.ts +0 -191
- package/src/outbound/workclaw-sender.ts +0 -161
- package/src/runtime.ts +0 -520
- package/src/secret-contract-api.ts +0 -4
- package/src/send.ts +0 -1
- package/src/setup-api.ts +0 -3
- package/src/setup-core.ts +0 -25
- package/src/setup-surface.ts +0 -498
- package/src/tools/openclaw-workclaw-cron/api/index.ts +0 -326
- package/src/tools/openclaw-workclaw-cron/index.ts +0 -39
- package/src/tools/openclaw-workclaw-cron/src/add/params.ts +0 -177
- package/src/tools/openclaw-workclaw-cron/src/add/sync.ts +0 -188
- package/src/tools/openclaw-workclaw-cron/src/disable/params.ts +0 -100
- package/src/tools/openclaw-workclaw-cron/src/disable/sync.ts +0 -127
- package/src/tools/openclaw-workclaw-cron/src/enable/params.ts +0 -100
- package/src/tools/openclaw-workclaw-cron/src/enable/sync.ts +0 -127
- package/src/tools/openclaw-workclaw-cron/src/notify/sync.ts +0 -148
- package/src/tools/openclaw-workclaw-cron/src/remove/params.ts +0 -109
- package/src/tools/openclaw-workclaw-cron/src/remove/sync.ts +0 -127
- package/src/tools/openclaw-workclaw-cron/src/update/params.ts +0 -195
- package/src/tools/openclaw-workclaw-cron/src/update/sync.ts +0 -161
- package/src/tools/openclaw-workclaw-cron/types/index.ts +0 -55
- package/src/tools/openclaw-workclaw-cron/utils/index.ts +0 -141
- package/src/tools/openclaw-workclaw-system/index.ts +0 -17
- package/src/tools/openclaw-workclaw-system/src/get/index.ts +0 -77
- package/src/tools/openclaw-workclaw-system/src/token/index.ts +0 -93
- package/src/types.ts +0 -50
- package/src/utils/content.ts +0 -40
- package/tsconfig.json +0 -34
package/dist/api.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export { workclawPlugin } from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
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
CHANGED
|
@@ -1,3 +1,379 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
+
};
|