@xopcai/xopc 0.0.464 → 0.0.465
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/browser-ext/manifest.json +1 -1
- package/dist/extensions/feishu/src/adapters/cli-login.js +23 -49
- package/dist/extensions/feishu/src/adapters/gateway-setup.d.ts +3 -0
- package/dist/extensions/feishu/src/adapters/gateway-setup.js +180 -128
- package/dist/extensions/feishu/src/adapters/onboard-cli.d.ts +1 -1
- package/dist/extensions/feishu/src/adapters/onboard-cli.js +27 -15
- package/dist/extensions/feishu/src/auth/app-registration.d.ts +1 -0
- package/dist/extensions/feishu/src/auth/app-registration.js +12 -9
- package/dist/extensions/feishu/src/outbound/outbound-adapter.js +40 -16
- package/dist/extensions/feishu/src/plugin.d.ts +2 -0
- package/dist/extensions/feishu/src/plugin.js +37 -23
- package/dist/extensions/feishu/src/status/status-adapter.d.ts +1 -1
- package/dist/extensions/feishu/src/status/status-adapter.js +8 -5
- package/dist/extensions/feishu/src/streaming/streaming-adapter.js +97 -69
- package/dist/extensions/feishu/src/transport/client/bot-info.d.ts +10 -0
- package/dist/extensions/feishu/src/transport/client/bot-info.js +34 -0
- package/dist/extensions/feishu/src/transport/client/client.d.ts +7 -1
- package/dist/extensions/feishu/src/transport/client/client.js +6 -5
- package/dist/extensions/feishu/src/transport/client/install-sdk.d.ts +2 -0
- package/dist/extensions/feishu/src/transport/client/install-sdk.js +77 -0
- package/dist/extensions/feishu/src/transport/client/lark-sdk.d.ts +2 -0
- package/dist/extensions/feishu/src/transport/client/lark-sdk.js +27 -3
- package/dist/extensions/feishu/src/transport/client/sdk-catalog.d.ts +1 -0
- package/dist/extensions/feishu/src/transport/client/sdk-catalog.js +317 -0
- package/dist/extensions/feishu/src/transport/reliability/inbound-pipeline.d.ts +1 -1
- package/dist/extensions/feishu/src/transport/reliability/inbound-pipeline.js +13 -5
- package/dist/extensions/feishu/src/transport/reliability/message-ingress.d.ts +21 -0
- package/dist/extensions/feishu/src/transport/reliability/message-ingress.js +313 -0
- package/dist/extensions/feishu/src/transport/socket-mode/monitor.d.ts +1 -0
- package/dist/extensions/feishu/src/transport/socket-mode/monitor.js +56 -171
- package/dist/extensions/feishu/src/transport/webhook/monitor.d.ts +1 -0
- package/dist/extensions/feishu/src/transport/webhook/monitor.js +10 -102
- package/dist/extensions/telegram/src/account-manager.d.ts +1 -0
- package/dist/extensions/telegram/src/account-manager.js +3 -0
- package/dist/extensions/telegram/src/adapters/debounce-keys.js +7 -2
- package/dist/extensions/telegram/src/adapters/gateway-setup.js +113 -63
- package/dist/extensions/telegram/src/adapters/streaming-adapter.js +8 -4
- package/dist/extensions/telegram/src/doctor.js +1 -1
- package/dist/extensions/telegram/src/inbound-coalescer.d.ts +8 -6
- package/dist/extensions/telegram/src/inbound-coalescer.js +47 -88
- package/dist/extensions/telegram/src/inbound-processor.js +5 -1
- package/dist/extensions/telegram/src/outbound-sender.js +16 -23
- package/dist/extensions/telegram/src/plugin.js +80 -57
- package/dist/extensions/telegram/src/polling-session.d.ts +3 -6
- package/dist/extensions/telegram/src/polling-session.js +107 -94
- package/dist/extensions/telegram/src/rich-message.d.ts +4 -0
- package/dist/extensions/telegram/src/rich-message.js +23 -0
- package/dist/extensions/telegram/src/timeout-abort.d.ts +1 -1
- package/dist/extensions/telegram/src/timeout-abort.js +9 -3
- package/dist/extensions/telegram/src/update-offset-store.d.ts +1 -0
- package/dist/extensions/telegram/src/update-offset-store.js +6 -1
- package/dist/extensions/telegram/xopc.extension.json +1 -1
- package/dist/extensions/weixin/src/api/api.d.ts +1 -0
- package/dist/extensions/weixin/src/api/api.js +12 -6
- package/dist/extensions/weixin/src/api/types.d.ts +5 -2
- package/dist/extensions/weixin/src/auth/login-qr.d.ts +7 -1
- package/dist/extensions/weixin/src/auth/login-qr.js +48 -13
- package/dist/extensions/weixin/src/cdn/pic-decrypt.d.ts +2 -2
- package/dist/extensions/weixin/src/cdn/pic-decrypt.js +37 -25
- package/dist/extensions/weixin/src/cli/gateway-qr-login.d.ts +8 -0
- package/dist/extensions/weixin/src/cli/gateway-qr-login.js +45 -6
- package/dist/extensions/weixin/src/cli/qr-login.d.ts +1 -1
- package/dist/extensions/weixin/src/cli/qr-login.js +9 -3
- package/dist/extensions/weixin/src/media/media-download.d.ts +1 -0
- package/dist/extensions/weixin/src/media/media-download.js +4 -5
- package/dist/extensions/weixin/src/messaging/process-message.d.ts +2 -0
- package/dist/extensions/weixin/src/messaging/process-message.js +90 -65
- package/dist/extensions/weixin/src/messaging/quote-cache.d.ts +10 -0
- package/dist/extensions/weixin/src/messaging/quote-cache.js +46 -0
- package/dist/extensions/weixin/src/monitor/monitor.d.ts +3 -3
- package/dist/extensions/weixin/src/monitor/monitor.js +108 -104
- package/dist/extensions/weixin/src/plugin.d.ts +5 -1
- package/dist/extensions/weixin/src/plugin.js +138 -42
- package/dist/gateway/static/root/assets/{capabilities-page-rTjkjo71.js → capabilities-page-U_hQx5ou.js} +2 -2
- package/dist/gateway/static/root/assets/channels-BUzno8Pi.js +1 -0
- package/dist/gateway/static/root/assets/extension-settings-page-BvUtZGLT.js +1 -0
- package/dist/gateway/static/root/assets/index-Cdo4_zon.js +11 -0
- package/dist/gateway/static/root/assets/index-DYTktubl.css +1 -0
- package/dist/gateway/static/root/assets/{route-preload-5iwjWERk.js → route-preload-ClsAFFQc.js} +2 -2
- package/dist/gateway/static/root/assets/schema-form-BxBDgLrg.js +1 -0
- package/dist/gateway/static/root/assets/{settings-page-DNiRlM5x.js → settings-page-M6XwzIyu.js} +1 -1
- package/dist/gateway/static/root/assets/understanding-refresh-store-CM6bUcaJ.js +1 -0
- package/dist/gateway/static/root/assets/user-model-page-CBcGMhrR.js +2 -0
- package/dist/gateway/static/root/index.html +4 -4
- package/dist/package.js +1 -1
- package/dist/src/agent/inbound/inbound-loop.js +14 -0
- package/dist/src/agent/messaging/outbound-coordinator.js +1 -1
- package/dist/src/channels/connection-probe.d.ts +23 -0
- package/dist/src/channels/connection-probe.js +98 -0
- package/dist/src/channels/manager.d.ts +2 -0
- package/dist/src/channels/manager.js +5 -0
- package/dist/src/channels/message-journal.d.ts +25 -0
- package/dist/src/channels/message-journal.js +79 -0
- package/dist/src/channels/outbound-sender.d.ts +8 -0
- package/dist/src/channels/outbound-sender.js +60 -1
- package/dist/src/channels/plugins/types.adapters.d.ts +4 -0
- package/dist/src/channels/verified-inbound.js +20 -14
- package/dist/src/gateway/hono/routes/channels.js +23 -10
- package/dist/src/gateway/hono/routes/home.js +1 -1
- package/dist/src/gateway/hono/routes/user-model.js +48 -20
- package/dist/src/gateway/service.js +5 -5
- package/dist/src/home-intelligence/host.js +5 -5
- package/dist/src/infra/bus/index.d.ts +1 -1
- package/dist/src/infra/bus/queue.d.ts +16 -3
- package/dist/src/infra/bus/queue.js +74 -3
- package/dist/src/infra/debounce.d.ts +1 -0
- package/dist/src/infra/debounce.js +40 -35
- package/dist/src/knowledge-memory/index.js +2 -2
- package/dist/src/knowledge-memory/repository.d.ts +9 -0
- package/dist/src/knowledge-memory/repository.js +12 -2
- package/dist/src/runtime-tools/types.d.ts +1 -1
- package/package.json +5 -6
- package/dist/gateway/static/root/assets/channels-DvB2fwPI.js +0 -1
- package/dist/gateway/static/root/assets/extension-settings-page-DKAJE4h9.js +0 -1
- package/dist/gateway/static/root/assets/index-BGA-G-Bp.css +0 -1
- package/dist/gateway/static/root/assets/index-pmlYYCCU.js +0 -11
- package/dist/gateway/static/root/assets/schema-form-C9TYGa0_.js +0 -1
- package/dist/gateway/static/root/assets/understanding-refresh-store-Cf0DUO_C.js +0 -1
- package/dist/gateway/static/root/assets/user-model-page-CdB9qH57.js +0 -2
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"minimum_chrome_version": "120",
|
|
4
4
|
"default_locale": "en",
|
|
5
5
|
"name": "__MSG_appName__",
|
|
6
|
-
"version": "0.0.
|
|
6
|
+
"version": "0.0.465",
|
|
7
7
|
"description": "__MSG_appDescription__",
|
|
8
8
|
"key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqnpr4vpLC/nmvy+wiOWk3SWlp2nEZkFijfk8ivGw7StNZgCK90nOMvwhdEtlkk3GOWDvdVnq8HxCsM3UNQ8FnGUyerpH1FJXqXuradxeHf8ZxFjiQU/mIWfnKbUuONWQORon3/pigyoXoK/VUXgg0Wbm/rbVwsS0bv+25R6m+mZgBspOLeKuoH7ivhL+48WV6POtMBsFPZweY26477EM7ukh+56Ff5ENevB8ymxBBn7qK5ZoeZd2a23U8ioX5TsHfe6fnrjitPWjIxD8G0NoKQxcaa/Mo+xs+T6UiLKxP0wjz5bm7jB5H+CXtkRJqzBWUB0h+RSLJckzZfA8BAJrRwIDAQAB",
|
|
9
9
|
"permissions": [
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { mergeDistinctSenderIds } from "../../../../src/channels/pairing/preseed-allow-from.js";
|
|
2
|
+
import { loadConfig, saveConfig } from "../../../../src/config/loader.js";
|
|
3
|
+
import { resolveFeishuAccount } from "../state/accounts.js";
|
|
4
|
+
import { ensureFeishuLarkSdk } from "../transport/client/lark-sdk.js";
|
|
2
5
|
import { beginAppRegistration, initAppRegistration, pollAppRegistration, printQrCode } from "../auth/app-registration.js";
|
|
3
|
-
import
|
|
4
|
-
import { confirm, input, select } from "@inquirer/prompts";
|
|
6
|
+
import { buildFeishuConfig } from "./gateway-setup.js";
|
|
7
|
+
import { confirm, input, password, select } from "@inquirer/prompts";
|
|
5
8
|
//#region extensions/feishu/src/adapters/cli-login.ts
|
|
6
9
|
/**
|
|
7
10
|
* Feishu CLI Login adapter — implements `ChannelCliLoginAdapter`.
|
|
@@ -9,24 +12,6 @@ import { confirm, input, select } from "@inquirer/prompts";
|
|
|
9
12
|
* Provides interactive credential setup for Feishu channel onboarding.
|
|
10
13
|
* Supports QR scan-to-create and manual credential input.
|
|
11
14
|
*/
|
|
12
|
-
function loadConfigFromPath(configPath) {
|
|
13
|
-
try {
|
|
14
|
-
const raw = fs.readFileSync(configPath, "utf8");
|
|
15
|
-
return JSON.parse(raw);
|
|
16
|
-
} catch {
|
|
17
|
-
return {};
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
function writeConfigToPath(configPath, config) {
|
|
21
|
-
fs.writeFileSync(configPath, JSON.stringify(config, null, 2) + "\n", "utf8");
|
|
22
|
-
}
|
|
23
|
-
function isFeishuConfigured(config) {
|
|
24
|
-
const feishu = config.channels?.feishu;
|
|
25
|
-
if (!feishu) return false;
|
|
26
|
-
const appId = typeof feishu.appId === "string" ? feishu.appId.trim() : "";
|
|
27
|
-
const appSecret = typeof feishu.appSecret === "string" ? feishu.appSecret.trim() : "";
|
|
28
|
-
return Boolean(appId && appSecret);
|
|
29
|
-
}
|
|
30
15
|
function parseAllowlistRaw(raw) {
|
|
31
16
|
if (!raw.trim()) return [];
|
|
32
17
|
return raw.split(/[,\s\n]+/).map((entry) => entry.trim()).filter(Boolean).map((entry) => {
|
|
@@ -69,7 +54,8 @@ async function acquireCredentials(params) {
|
|
|
69
54
|
appId: outcome.result.appId,
|
|
70
55
|
appSecret: outcome.result.appSecret,
|
|
71
56
|
domain: outcome.result.domain,
|
|
72
|
-
ownerOpenId: outcome.result.openId
|
|
57
|
+
ownerOpenId: outcome.result.openId,
|
|
58
|
+
scanned: true
|
|
73
59
|
};
|
|
74
60
|
}
|
|
75
61
|
const reason = outcome.status === "access_denied" ? "User denied authorization." : outcome.status === "expired" ? "Session expired." : outcome.status === "timeout" ? "Scan timed out." : `Error: ${"message" in outcome ? outcome.message : "unknown"}`;
|
|
@@ -82,7 +68,7 @@ async function acquireCredentials(params) {
|
|
|
82
68
|
default: params.existingAppId || void 0,
|
|
83
69
|
validate: (value) => value.trim().length > 0 || "App ID cannot be empty"
|
|
84
70
|
})).trim(),
|
|
85
|
-
appSecret: (await
|
|
71
|
+
appSecret: (await password({
|
|
86
72
|
message: "App Secret:",
|
|
87
73
|
validate: (value) => value.trim().length > 0 || "App Secret cannot be empty"
|
|
88
74
|
})).trim(),
|
|
@@ -95,7 +81,7 @@ async function promptSecurityPolicies(ownerOpenId) {
|
|
|
95
81
|
choices: [
|
|
96
82
|
{
|
|
97
83
|
value: "open",
|
|
98
|
-
name: "open
|
|
84
|
+
name: "open",
|
|
99
85
|
description: "Anyone can DM the bot after setup"
|
|
100
86
|
},
|
|
101
87
|
{
|
|
@@ -114,7 +100,7 @@ async function promptSecurityPolicies(ownerOpenId) {
|
|
|
114
100
|
description: "Disable DMs"
|
|
115
101
|
}
|
|
116
102
|
],
|
|
117
|
-
default: "
|
|
103
|
+
default: ownerOpenId?.trim() ? "allowlist" : "pairing"
|
|
118
104
|
});
|
|
119
105
|
let allowFrom = [];
|
|
120
106
|
if (dmPolicy === "allowlist") {
|
|
@@ -166,10 +152,10 @@ async function promptSecurityPolicies(ownerOpenId) {
|
|
|
166
152
|
const feishuCliLoginAdapter = { async runLogin(params) {
|
|
167
153
|
const { configPath, verbose, timeoutMs = 48e4, accountId, writeConfig = true } = params;
|
|
168
154
|
if (verbose) console.log(`[feishu-login] configPath=${configPath}, timeoutMs=${timeoutMs}`);
|
|
169
|
-
const config =
|
|
170
|
-
const
|
|
171
|
-
const existingAppId =
|
|
172
|
-
const alreadyConfigured =
|
|
155
|
+
const config = loadConfig(configPath);
|
|
156
|
+
const target = resolveFeishuAccount(config, accountId);
|
|
157
|
+
const existingAppId = target.appId ?? "";
|
|
158
|
+
const alreadyConfigured = target.configured;
|
|
173
159
|
console.log(`\n${"=".repeat(50)}`);
|
|
174
160
|
console.log("📱 Feishu / Lark login");
|
|
175
161
|
console.log(`${"=".repeat(50)}\n`);
|
|
@@ -190,35 +176,23 @@ const feishuCliLoginAdapter = { async runLogin(params) {
|
|
|
190
176
|
existingAppId,
|
|
191
177
|
timeoutMs
|
|
192
178
|
});
|
|
193
|
-
|
|
194
|
-
const
|
|
195
|
-
...existingFeishu ?? {},
|
|
196
|
-
enabled: true,
|
|
179
|
+
if (writeConfig) await ensureFeishuLarkSdk();
|
|
180
|
+
const base = buildFeishuConfig(config, {
|
|
197
181
|
appId: credentials.appId,
|
|
198
182
|
appSecret: credentials.appSecret,
|
|
199
183
|
domain: credentials.domain,
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
groupAllowFrom: policies.groupAllowFrom,
|
|
205
|
-
requireMention: policies.requireMention
|
|
206
|
-
};
|
|
207
|
-
const nextConfig = {
|
|
208
|
-
...config,
|
|
209
|
-
channels: {
|
|
210
|
-
...config.channels,
|
|
211
|
-
feishu: nextFeishu
|
|
212
|
-
}
|
|
213
|
-
};
|
|
184
|
+
openId: credentials.ownerOpenId
|
|
185
|
+
}, target.accountId);
|
|
186
|
+
const account = (base.channels?.feishu).accounts?.[target.accountId];
|
|
187
|
+
if (!credentials.scanned && account) Object.assign(account, await promptSecurityPolicies(credentials.ownerOpenId));
|
|
214
188
|
if (writeConfig) {
|
|
215
|
-
|
|
189
|
+
await saveConfig(base, configPath);
|
|
216
190
|
console.log(`✅ Feishu configuration saved to ${configPath}\n`);
|
|
217
191
|
} else console.log("✅ Feishu credentials acquired (--credentials-only: config not updated).\n");
|
|
218
192
|
return {
|
|
219
193
|
ok: true,
|
|
220
|
-
message: `Feishu
|
|
221
|
-
accountId: accountId
|
|
194
|
+
message: `Feishu authorized. Send a message after starting the Gateway (App ID: ${credentials.appId}).`,
|
|
195
|
+
accountId: target.accountId
|
|
222
196
|
};
|
|
223
197
|
} };
|
|
224
198
|
//#endregion
|
|
@@ -1,2 +1,5 @@
|
|
|
1
|
+
import type { Config } from '@xopcai/xopc/config/schema.js';
|
|
1
2
|
import type { ChannelRuntimeActionAdapter } from '@xopcai/xopc/channels/plugins/types.adapters.js';
|
|
3
|
+
import { type AppRegistrationResult } from '../auth/app-registration.js';
|
|
4
|
+
export declare function buildFeishuConfig(config: Config, result: AppRegistrationResult, accountId?: string): Config;
|
|
2
5
|
export declare const feishuGatewaySetupActions: ChannelRuntimeActionAdapter;
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { cancelChannelConnectionProbe, getChannelConnectionProbe, startChannelConnectionProbe } from "../../../../src/channels/connection-probe.js";
|
|
2
|
+
import { ensureFeishuLarkSdk } from "../transport/client/lark-sdk.js";
|
|
3
|
+
import { probeFeishuBot } from "../transport/client/bot-info.js";
|
|
2
4
|
import { beginAppRegistration, initAppRegistration, pollAppRegistration } from "../auth/app-registration.js";
|
|
5
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
3
6
|
//#region extensions/feishu/src/adapters/gateway-setup.ts
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
function
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
setTimeout(() => completedSessions.delete(conversationId), 10 * 6e4);
|
|
7
|
+
const sessions = /* @__PURE__ */ new Map();
|
|
8
|
+
const channelHash = (cfg) => createHash("sha256").update(JSON.stringify(cfg.channels?.feishu ?? {})).digest("hex");
|
|
9
|
+
function cancelSetup(id) {
|
|
10
|
+
sessions.get(id)?.controller.abort();
|
|
11
|
+
sessions.delete(id);
|
|
10
12
|
}
|
|
11
13
|
function readInput(input) {
|
|
12
14
|
return input && typeof input === "object" && !Array.isArray(input) ? input : {};
|
|
@@ -14,51 +16,45 @@ function readInput(input) {
|
|
|
14
16
|
function normalizeDomain(input) {
|
|
15
17
|
return input === "lark" ? "lark" : "feishu";
|
|
16
18
|
}
|
|
17
|
-
function buildFeishuConfig(config, result) {
|
|
19
|
+
function buildFeishuConfig(config, result, accountId = "default") {
|
|
18
20
|
const existing = config.channels?.feishu;
|
|
21
|
+
const account = Object.hasOwn(existing?.accounts ?? {}, accountId) ? existing?.accounts?.[accountId] : void 0;
|
|
19
22
|
const ownerOpenId = result.openId?.trim();
|
|
20
|
-
const
|
|
21
|
-
const
|
|
23
|
+
const sameApp = account?.appId === result.appId && (account.domain ?? existing?.domain ?? "feishu") === result.domain;
|
|
24
|
+
const access = sameApp ? {} : {
|
|
25
|
+
dmPolicy: ownerOpenId ? "allowlist" : "pairing",
|
|
26
|
+
allowFrom: ownerOpenId ? [ownerOpenId] : [],
|
|
27
|
+
groupPolicy: "allowlist",
|
|
28
|
+
groupAllowFrom: [],
|
|
29
|
+
requireMention: true,
|
|
30
|
+
tools: {
|
|
31
|
+
doc: false,
|
|
32
|
+
wiki: false,
|
|
33
|
+
drive: false,
|
|
34
|
+
perm: false,
|
|
35
|
+
bitable: false,
|
|
36
|
+
scopes: false
|
|
37
|
+
}
|
|
38
|
+
};
|
|
22
39
|
return {
|
|
23
40
|
...config,
|
|
24
41
|
channels: {
|
|
25
42
|
...config.channels,
|
|
26
43
|
feishu: {
|
|
27
|
-
...existing
|
|
44
|
+
...existing,
|
|
28
45
|
enabled: true,
|
|
29
46
|
accounts: {
|
|
30
47
|
...existing?.accounts,
|
|
31
|
-
|
|
32
|
-
...
|
|
48
|
+
[accountId]: {
|
|
49
|
+
...sameApp ? account : void 0,
|
|
50
|
+
...access,
|
|
33
51
|
enabled: true,
|
|
34
52
|
appId: result.appId,
|
|
35
|
-
appSecret: result.appSecret
|
|
53
|
+
appSecret: result.appSecret,
|
|
54
|
+
domain: result.domain,
|
|
55
|
+
connectionMode: sameApp ? account.connectionMode ?? existing?.connectionMode ?? "websocket" : "websocket"
|
|
36
56
|
}
|
|
37
|
-
}
|
|
38
|
-
domain: result.domain,
|
|
39
|
-
connectionMode: "websocket",
|
|
40
|
-
dmPolicy: existing?.dmPolicy ?? "open",
|
|
41
|
-
groupPolicy: existing?.groupPolicy ?? "allowlist",
|
|
42
|
-
allowFrom,
|
|
43
|
-
groupAllowFrom: Array.isArray(existing?.groupAllowFrom) ? existing.groupAllowFrom : allowFrom,
|
|
44
|
-
requireMention: typeof existing?.requireMention === "boolean" ? existing.requireMention : true,
|
|
45
|
-
streaming: typeof existing?.streaming === "boolean" ? existing.streaming : false,
|
|
46
|
-
reactionNotifications: existing?.reactionNotifications ?? "own",
|
|
47
|
-
actions: {
|
|
48
|
-
...existing?.actions,
|
|
49
|
-
reactions: true
|
|
50
|
-
},
|
|
51
|
-
tools: {
|
|
52
|
-
doc: true,
|
|
53
|
-
wiki: true,
|
|
54
|
-
drive: true,
|
|
55
|
-
perm: false,
|
|
56
|
-
bitable: true,
|
|
57
|
-
scopes: true,
|
|
58
|
-
...existing?.tools
|
|
59
|
-
},
|
|
60
|
-
historyLimit: typeof existing?.historyLimit === "number" ? existing.historyLimit : 50,
|
|
61
|
-
textChunkLimit: typeof existing?.textChunkLimit === "number" ? existing.textChunkLimit : 4e3
|
|
57
|
+
}
|
|
62
58
|
}
|
|
63
59
|
}
|
|
64
60
|
};
|
|
@@ -66,52 +62,59 @@ function buildFeishuConfig(config, result) {
|
|
|
66
62
|
function isZh(locale) {
|
|
67
63
|
return locale?.toLowerCase().startsWith("zh") === true;
|
|
68
64
|
}
|
|
69
|
-
function
|
|
70
|
-
const zh = isZh(locale);
|
|
71
|
-
if (!state && active) return {
|
|
72
|
-
type: "poll",
|
|
73
|
-
phase: "pending",
|
|
74
|
-
ok: void 0,
|
|
75
|
-
qrPayload: active.qrPayload,
|
|
76
|
-
message: zh ? "等待飞书 / Lark 确认…" : "Waiting for Feishu/Lark confirmation..."
|
|
77
|
-
};
|
|
78
|
-
if (!state) return {
|
|
79
|
-
type: "poll",
|
|
80
|
-
phase: "unknown",
|
|
81
|
-
ok: false,
|
|
82
|
-
message: zh ? "没有活动的飞书配置会话。请重新开始,二维码可能已过期。" : "No active Feishu setup session. Start again or the QR may have expired."
|
|
83
|
-
};
|
|
84
|
-
if (state.ok === false) return {
|
|
85
|
-
type: "poll",
|
|
86
|
-
phase: "done",
|
|
87
|
-
ok: false,
|
|
88
|
-
message: state.message
|
|
89
|
-
};
|
|
65
|
+
function setupVerification(result, accountId, zh, info) {
|
|
90
66
|
return {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
67
|
+
...startChannelConnectionProbe({
|
|
68
|
+
channel: "feishu",
|
|
69
|
+
accountId,
|
|
70
|
+
identity: result.appId,
|
|
71
|
+
ownerId: result.openId?.trim(),
|
|
72
|
+
zh,
|
|
73
|
+
configChanged: true
|
|
74
|
+
}),
|
|
75
|
+
...info.ok && info.name ? { botName: info.name } : {},
|
|
76
|
+
...!info.ok ? { setupHint: zh ? "若找不到机器人,请在开放平台检查机器人能力、长连接事件订阅、发布和管理员审批。" : "If the bot is unavailable, check bot access, long-connection subscriptions, publication and administrator approval." } : {}
|
|
99
77
|
};
|
|
100
78
|
}
|
|
101
|
-
|
|
102
|
-
if (!state || state.ok === false) return void 0;
|
|
103
|
-
return buildFeishuConfig(cfg, state.result);
|
|
104
|
-
}
|
|
105
|
-
const feishuGatewaySetupActions = { async runAction({ cfg, actionId, input, locale }) {
|
|
79
|
+
const feishuGatewaySetupActions = { async runAction({ cfg, actionId, input, locale, accountId: requestedAccountId }) {
|
|
106
80
|
const zh = isZh(locale);
|
|
81
|
+
const raw = readInput(input);
|
|
82
|
+
const id = typeof raw.conversationId === "string" ? raw.conversationId : "";
|
|
83
|
+
const accountId = requestedAccountId || "default";
|
|
84
|
+
const domain = normalizeDomain(raw.domain);
|
|
85
|
+
if (actionId === "setup.verify.status") return {
|
|
86
|
+
ok: true,
|
|
87
|
+
payload: getChannelConnectionProbe("feishu", accountId, id, zh)
|
|
88
|
+
};
|
|
89
|
+
if (actionId === "setup.verify.cancel") {
|
|
90
|
+
cancelChannelConnectionProbe("feishu", accountId, id);
|
|
91
|
+
return {
|
|
92
|
+
ok: true,
|
|
93
|
+
payload: { type: "ok" }
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
if (actionId === "setup.cancel") {
|
|
97
|
+
if (sessions.get(id)?.accountId === accountId) cancelSetup(id);
|
|
98
|
+
return {
|
|
99
|
+
ok: true,
|
|
100
|
+
payload: { type: "ok" }
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
if (actionId === "setup.start" || actionId === "setup.manual") try {
|
|
104
|
+
await ensureFeishuLarkSdk();
|
|
105
|
+
} catch {
|
|
106
|
+
return {
|
|
107
|
+
ok: false,
|
|
108
|
+
message: zh ? "飞书组件安装失败。请检查网络后重试。" : "Could not install the Feishu component. Check the network and retry."
|
|
109
|
+
};
|
|
110
|
+
}
|
|
107
111
|
if (actionId === "setup.start") {
|
|
108
|
-
const domain = normalizeDomain(readInput(input).domain);
|
|
109
112
|
if (!await initAppRegistration(domain)) return {
|
|
110
113
|
ok: true,
|
|
111
114
|
payload: {
|
|
112
115
|
type: "form",
|
|
113
116
|
submitAction: "setup.manual",
|
|
114
|
-
message: zh ? "
|
|
117
|
+
message: zh ? "扫码创建暂不可用,请填写应用凭据。" : "Scan-to-create is unavailable. Enter app credentials.",
|
|
115
118
|
schema: {
|
|
116
119
|
type: "object",
|
|
117
120
|
properties: {
|
|
@@ -127,8 +130,7 @@ const feishuGatewaySetupActions = { async runAction({ cfg, actionId, input, loca
|
|
|
127
130
|
domain: {
|
|
128
131
|
type: "string",
|
|
129
132
|
enum: ["feishu", "lark"],
|
|
130
|
-
default: domain
|
|
131
|
-
title: zh ? "域名" : "Domain"
|
|
133
|
+
default: domain
|
|
132
134
|
}
|
|
133
135
|
},
|
|
134
136
|
required: ["appId", "appSecret"]
|
|
@@ -137,89 +139,139 @@ const feishuGatewaySetupActions = { async runAction({ cfg, actionId, input, loca
|
|
|
137
139
|
}
|
|
138
140
|
};
|
|
139
141
|
const begin = await beginAppRegistration(domain);
|
|
140
|
-
const conversationId =
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
rememberCompleted(conversationId, {
|
|
161
|
-
phase: "done",
|
|
142
|
+
const conversationId = randomUUID();
|
|
143
|
+
const expireInSec = Math.max(1, Math.min(600, begin.expireInSec));
|
|
144
|
+
for (const [activeId, active] of sessions) if (active.accountId === accountId) cancelSetup(activeId);
|
|
145
|
+
const session = {
|
|
146
|
+
accountId,
|
|
147
|
+
controller: new AbortController(),
|
|
148
|
+
configHash: channelHash(cfg),
|
|
149
|
+
qrUrl: begin.qrUrl,
|
|
150
|
+
expiresAt: Date.now() + expireInSec * 1e3
|
|
151
|
+
};
|
|
152
|
+
sessions.set(conversationId, session);
|
|
153
|
+
setTimeout(() => cancelSetup(conversationId), expireInSec * 1e3).unref();
|
|
154
|
+
pollAppRegistration({
|
|
155
|
+
deviceCode: begin.deviceCode,
|
|
156
|
+
intervalSec: begin.intervalSec,
|
|
157
|
+
expireInSec,
|
|
158
|
+
initialDomain: domain,
|
|
159
|
+
signal: session.controller.signal
|
|
160
|
+
}).then((outcome) => {
|
|
161
|
+
if (outcome.status === "success") session.outcome = {
|
|
162
162
|
ok: true,
|
|
163
|
-
accountId: "default",
|
|
164
|
-
appId: outcome.result.appId,
|
|
165
|
-
domain: outcome.result.domain,
|
|
166
163
|
result: outcome.result
|
|
167
|
-
}
|
|
168
|
-
|
|
164
|
+
};
|
|
165
|
+
else session.outcome = {
|
|
166
|
+
ok: false,
|
|
167
|
+
message: outcome.status === "access_denied" ? zh ? "已拒绝授权。" : "Authorization denied." : zh ? "授权未完成,请重试。" : "Authorization did not finish. Please retry."
|
|
168
|
+
};
|
|
169
|
+
}).catch(() => {
|
|
170
|
+
session.outcome = {
|
|
171
|
+
ok: false,
|
|
172
|
+
message: zh ? "授权已结束。" : "Authorization ended."
|
|
173
|
+
};
|
|
174
|
+
});
|
|
169
175
|
return {
|
|
170
176
|
ok: true,
|
|
171
177
|
payload: {
|
|
172
178
|
type: "qr",
|
|
173
179
|
conversationId,
|
|
180
|
+
accountId,
|
|
174
181
|
qrPayload: begin.qrUrl,
|
|
175
182
|
statusAction: "setup.status",
|
|
183
|
+
cancelAction: "setup.cancel",
|
|
184
|
+
expiresInSec: expireInSec,
|
|
176
185
|
pollIntervalMs: Math.max(1e3, begin.intervalSec * 1e3),
|
|
177
|
-
|
|
178
|
-
message: zh ? "请使用飞书 / Lark 扫码创建并授权应用。" : "Scan with Feishu/Lark to create and authorize an app."
|
|
186
|
+
message: zh ? "使用飞书或 Lark 扫码创建并授权应用。" : "Scan with Feishu or Lark to create and authorize the app."
|
|
179
187
|
}
|
|
180
188
|
};
|
|
181
189
|
}
|
|
182
190
|
if (actionId === "setup.status") {
|
|
183
|
-
const
|
|
184
|
-
|
|
185
|
-
|
|
191
|
+
const session = sessions.get(id);
|
|
192
|
+
if (!session || session.accountId !== accountId || session.expiresAt <= Date.now()) return {
|
|
193
|
+
ok: true,
|
|
194
|
+
payload: {
|
|
195
|
+
type: "poll",
|
|
196
|
+
phase: "unknown",
|
|
197
|
+
ok: false,
|
|
198
|
+
message: zh ? "二维码已过期,请重新连接。" : "The QR code expired. Connect again."
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
if (session.configHash !== channelHash(cfg)) {
|
|
202
|
+
cancelSetup(id);
|
|
203
|
+
return {
|
|
204
|
+
ok: true,
|
|
205
|
+
payload: {
|
|
206
|
+
type: "poll",
|
|
207
|
+
phase: "done",
|
|
208
|
+
ok: false,
|
|
209
|
+
message: zh ? "飞书设置已变更,请重新连接。" : "Feishu settings changed. Connect again."
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
if (!session.outcome) return {
|
|
214
|
+
ok: true,
|
|
215
|
+
payload: {
|
|
216
|
+
type: "poll",
|
|
217
|
+
phase: "pending",
|
|
218
|
+
qrPayload: session.qrUrl
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
if (session.outcome.ok === false) {
|
|
222
|
+
const { message } = session.outcome;
|
|
223
|
+
cancelSetup(id);
|
|
224
|
+
return {
|
|
225
|
+
ok: true,
|
|
226
|
+
payload: {
|
|
227
|
+
type: "poll",
|
|
228
|
+
phase: "done",
|
|
229
|
+
ok: false,
|
|
230
|
+
message
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
const { result } = session.outcome;
|
|
235
|
+
const info = await probeFeishuBot(result).catch(() => ({ ok: false }));
|
|
236
|
+
if (sessions.get(id) !== session) return {
|
|
186
237
|
ok: false,
|
|
187
|
-
message: zh ? "
|
|
238
|
+
message: zh ? "授权会话已结束。" : "Authorization session ended."
|
|
188
239
|
};
|
|
189
|
-
const completed = completedSessions.get(conversationId);
|
|
190
240
|
return {
|
|
191
241
|
ok: true,
|
|
192
|
-
|
|
193
|
-
|
|
242
|
+
nextConfig: buildFeishuConfig(cfg, result, accountId),
|
|
243
|
+
beforeConfigSaved: () => {
|
|
244
|
+
if (sessions.get(id) !== session) throw new Error("Feishu setup session is no longer active");
|
|
245
|
+
},
|
|
246
|
+
onConfigSaved: () => {
|
|
247
|
+
cancelSetup(id);
|
|
248
|
+
return setupVerification(result, accountId, zh, info);
|
|
249
|
+
}
|
|
194
250
|
};
|
|
195
251
|
}
|
|
196
252
|
if (actionId === "setup.manual") {
|
|
197
|
-
const raw = readInput(input);
|
|
198
253
|
const appId = typeof raw.appId === "string" ? raw.appId.trim() : "";
|
|
199
254
|
const appSecret = typeof raw.appSecret === "string" ? raw.appSecret.trim() : "";
|
|
200
|
-
const domain = normalizeDomain(raw.domain);
|
|
201
255
|
if (!appId || !appSecret) return {
|
|
202
256
|
ok: false,
|
|
203
|
-
message: zh ? "App ID 和 App Secret
|
|
257
|
+
message: zh ? "请填写 App ID 和 App Secret。" : "Enter the App ID and App Secret."
|
|
204
258
|
};
|
|
259
|
+
const result = {
|
|
260
|
+
appId,
|
|
261
|
+
appSecret,
|
|
262
|
+
domain
|
|
263
|
+
};
|
|
264
|
+
const info = await probeFeishuBot(result).catch(() => ({ ok: false }));
|
|
205
265
|
return {
|
|
206
266
|
ok: true,
|
|
207
|
-
nextConfig: buildFeishuConfig(cfg,
|
|
208
|
-
|
|
209
|
-
appSecret,
|
|
210
|
-
domain
|
|
211
|
-
}),
|
|
212
|
-
payload: {
|
|
213
|
-
type: "ok",
|
|
214
|
-
message: zh ? "飞书配置已保存。" : "Feishu configuration saved.",
|
|
215
|
-
configChanged: true
|
|
216
|
-
}
|
|
267
|
+
nextConfig: buildFeishuConfig(cfg, result, accountId),
|
|
268
|
+
onConfigSaved: () => setupVerification(result, accountId, zh, info)
|
|
217
269
|
};
|
|
218
270
|
}
|
|
219
271
|
return {
|
|
220
272
|
ok: false,
|
|
221
|
-
message:
|
|
273
|
+
message: zh ? "不支持的飞书操作。" : "Unsupported Feishu action."
|
|
222
274
|
};
|
|
223
275
|
} };
|
|
224
276
|
//#endregion
|
|
225
|
-
export { feishuGatewaySetupActions };
|
|
277
|
+
export { buildFeishuConfig, feishuGatewaySetupActions };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Feishu interactive onboarding (CLI onboard) — {@link ChannelOnboardAdapter}.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* Stores credentials in the selected Feishu account.
|
|
5
5
|
*/
|
|
6
6
|
import type { ChannelOnboardAdapter } from '@xopcai/xopc/channels/plugins/types.adapters.js';
|
|
7
7
|
export declare const feishuOnboardAdapter: ChannelOnboardAdapter;
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { mergeDistinctSenderIds } from "../../../../src/channels/pairing/preseed-allow-from.js";
|
|
2
|
+
import { resolveFeishuAccount } from "../state/accounts.js";
|
|
3
|
+
import { ensureFeishuLarkSdk } from "../transport/client/lark-sdk.js";
|
|
2
4
|
import { beginAppRegistration, initAppRegistration, pollAppRegistration, printQrCode } from "../auth/app-registration.js";
|
|
3
|
-
import {
|
|
5
|
+
import { buildFeishuConfig } from "./gateway-setup.js";
|
|
6
|
+
import { confirm, input, password, select } from "@inquirer/prompts";
|
|
4
7
|
//#region extensions/feishu/src/adapters/onboard-cli.ts
|
|
5
8
|
/**
|
|
6
9
|
* Feishu interactive onboarding (CLI onboard) — {@link ChannelOnboardAdapter}.
|
|
7
10
|
*
|
|
8
|
-
*
|
|
11
|
+
* Stores credentials in the selected Feishu account.
|
|
9
12
|
*/
|
|
10
13
|
function isFeishuConfigured(config) {
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
const appId = typeof feishu.appId === "string" ? feishu.appId.trim() : "";
|
|
14
|
-
const appSecret = typeof feishu.appSecret === "string" ? feishu.appSecret.trim() : "";
|
|
15
|
-
return feishu.enabled === true && Boolean(appId && appSecret);
|
|
14
|
+
const account = resolveFeishuAccount(config);
|
|
15
|
+
return account.enabled && account.configured;
|
|
16
16
|
}
|
|
17
17
|
function parseAllowlistRaw(raw) {
|
|
18
18
|
if (!raw.trim()) return [];
|
|
@@ -25,9 +25,10 @@ async function configureFeishu(config) {
|
|
|
25
25
|
console.log(`\n${"=".repeat(50)}`);
|
|
26
26
|
console.log("📱 Feishu / Lark setup");
|
|
27
27
|
console.log(`${"=".repeat(50)}\n`);
|
|
28
|
-
const
|
|
29
|
-
const
|
|
30
|
-
const
|
|
28
|
+
const target = resolveFeishuAccount(config);
|
|
29
|
+
const existing = target;
|
|
30
|
+
const existingAppId = target.appId ?? "";
|
|
31
|
+
const existingDomain = target.domain;
|
|
31
32
|
if (existing?.enabled === true && existingAppId) {
|
|
32
33
|
if (!await confirm({
|
|
33
34
|
message: "A Feishu config already exists. Reconfigure it?",
|
|
@@ -72,7 +73,9 @@ async function configureFeishu(config) {
|
|
|
72
73
|
appSecret = outcome.result.appSecret;
|
|
73
74
|
domain = outcome.result.domain;
|
|
74
75
|
ownerOpenId = outcome.result.openId;
|
|
75
|
-
console.log(
|
|
76
|
+
console.log(`App authorized in "${domain}". Send a message after starting the Gateway.\n`);
|
|
77
|
+
await ensureFeishuLarkSdk();
|
|
78
|
+
return buildFeishuConfig(config, outcome.result, target.accountId);
|
|
76
79
|
}
|
|
77
80
|
}
|
|
78
81
|
if (!appId || !appSecret) {
|
|
@@ -82,7 +85,7 @@ async function configureFeishu(config) {
|
|
|
82
85
|
default: existingAppId || void 0,
|
|
83
86
|
validate: (v) => v.trim().length > 0 || "App ID cannot be empty"
|
|
84
87
|
})).trim();
|
|
85
|
-
appSecret = (await
|
|
88
|
+
appSecret = (await password({
|
|
86
89
|
message: "App Secret:",
|
|
87
90
|
validate: (v) => v.trim().length > 0 || "App Secret cannot be empty"
|
|
88
91
|
})).trim();
|
|
@@ -134,7 +137,7 @@ async function configureFeishu(config) {
|
|
|
134
137
|
choices: [
|
|
135
138
|
{
|
|
136
139
|
value: "open",
|
|
137
|
-
name: "open
|
|
140
|
+
name: "open",
|
|
138
141
|
description: "Anyone can DM the bot after setup"
|
|
139
142
|
},
|
|
140
143
|
{
|
|
@@ -153,7 +156,7 @@ async function configureFeishu(config) {
|
|
|
153
156
|
description: "Disable DMs"
|
|
154
157
|
}
|
|
155
158
|
],
|
|
156
|
-
default: "
|
|
159
|
+
default: ownerOpenId?.trim() ? "allowlist" : "pairing"
|
|
157
160
|
});
|
|
158
161
|
let allowFrom;
|
|
159
162
|
if (dmPolicy === "allowlist") {
|
|
@@ -311,11 +314,20 @@ async function configureFeishu(config) {
|
|
|
311
314
|
historyLimit: typeof existing?.historyLimit === "number" ? existing.historyLimit : 50,
|
|
312
315
|
textChunkLimit: typeof existing?.textChunkLimit === "number" ? existing.textChunkLimit : 4e3
|
|
313
316
|
};
|
|
317
|
+
await ensureFeishuLarkSdk();
|
|
318
|
+
const section = config.channels?.feishu;
|
|
314
319
|
const newConfig = {
|
|
315
320
|
...config,
|
|
316
321
|
channels: {
|
|
317
322
|
...config.channels,
|
|
318
|
-
feishu:
|
|
323
|
+
feishu: {
|
|
324
|
+
...section,
|
|
325
|
+
enabled: true,
|
|
326
|
+
accounts: {
|
|
327
|
+
...section?.accounts,
|
|
328
|
+
[target.accountId]: nextFeishu
|
|
329
|
+
}
|
|
330
|
+
}
|
|
319
331
|
}
|
|
320
332
|
};
|
|
321
333
|
console.log("\n✅ Feishu configuration complete\n");
|