agent-bridge-feishu 1.0.0 → 1.0.2
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/README.md +5 -3
- package/dist/src-ts/plugins/feishu/client.js +41 -19
- package/dist/src-ts/plugins/feishu/index.js +27 -18
- package/dist/src-ts/plugins/feishu/public/app.js +74 -20
- package/dist/src-ts/plugins/feishu/public/index.html +1 -1
- package/dist/src-ts/plugins/feishu/public/style.css +3 -0
- package/package.json +2 -1
- package/plugin.json +1 -1
package/README.md
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
# 飞书通道插件
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
在管理页面打开飞书通道的设置页,点击「创建飞书机器人」。页面会显示二维码和创建链接,授权完成后自动保存凭据并连接。随后在「关联 Agent」表单选择本地 Agent。
|
|
4
4
|
|
|
5
|
-
1. `POST /api/plugins/feishu/setup/begin`,响应中的 `url`
|
|
5
|
+
1. `POST /api/plugins/feishu/setup/begin`,响应中的 `url`(兼容字段 `qr_url`)即飞书授权 URL,`qr_image` 为 PNG 二维码 data URL。
|
|
6
6
|
2. 用户打开 URL 完成授权。
|
|
7
|
-
3.
|
|
7
|
+
3. 按 `interval` 秒间隔轮询 `POST /api/plugins/feishu/setup/poll`,提交第一步返回的 `device_code`;完成后插件会保存 `app_id/app_secret`。凭据不会出现在响应中。
|
|
8
8
|
4. 重载飞书插件,插件通过长连接接收文本消息,并将消息转发到已启动的本地 Agent 插件。
|
|
9
9
|
|
|
10
10
|
也可以直接配置飞书开放平台应用的 `app_id` 和 `app_secret`。通过配置中的 `agent_plugin` 或管理界面的绑定功能指定目标 Agent。
|
|
11
11
|
|
|
12
|
+
保存后 App Secret 以密码掩码保留在输入框,刷新或重连无需再次复制。掩码仅代表后台已保存密钥,状态接口不会返回真实密钥。更换 App ID 时需要填写对应的新密钥。扫码授权完成后自动保存两项凭据并连接;连接失败会显示具体原因,不影响已保存的凭据。
|
|
13
|
+
|
|
12
14
|
飞书应用需要开启机器人能力和接收消息事件权限。插件默认使用飞书中国区 API,可通过 `api_base` 指定其他区域地址。
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FeishuClient = void 0;
|
|
4
4
|
exports.parseFeishuEvent = parseFeishuEvent;
|
|
5
|
+
const node_sdk_1 = require("@larksuiteoapi/node-sdk");
|
|
5
6
|
const defaultTransport = { fetch, WebSocket };
|
|
6
7
|
function parseFeishuEvent(input) {
|
|
7
8
|
if (!input || typeof input !== "object")
|
|
@@ -33,6 +34,7 @@ class FeishuClient {
|
|
|
33
34
|
config;
|
|
34
35
|
transport;
|
|
35
36
|
socket;
|
|
37
|
+
sdkClient;
|
|
36
38
|
token = "";
|
|
37
39
|
tokenExpires = 0;
|
|
38
40
|
constructor(config, transport = defaultTransport) {
|
|
@@ -40,17 +42,47 @@ class FeishuClient {
|
|
|
40
42
|
this.transport = transport;
|
|
41
43
|
}
|
|
42
44
|
async start(onMessage, signal) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
socket.onopen = () => resolve();
|
|
48
|
-
socket.
|
|
49
|
-
}
|
|
50
|
-
|
|
45
|
+
if (this.config.ws_url) {
|
|
46
|
+
const url = this.config.ws_url;
|
|
47
|
+
const socket = new this.transport.WebSocket(url);
|
|
48
|
+
this.socket = socket;
|
|
49
|
+
await new Promise((resolve, reject) => { socket.onopen = () => resolve(); socket.onerror = () => reject(new Error("飞书长连接失败")); });
|
|
50
|
+
socket.onmessage = (event) => { void this.receive(String(event.data), onMessage); };
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
await this.startSdk(onMessage);
|
|
54
|
+
}
|
|
51
55
|
signal?.addEventListener("abort", () => this.close(), { once: true });
|
|
52
56
|
}
|
|
53
|
-
close() { this.socket?.close(); this.socket = undefined; }
|
|
57
|
+
close() { this.sdkClient?.close({ force: true }); this.sdkClient = undefined; this.socket?.close(); this.socket = undefined; }
|
|
58
|
+
async startSdk(onMessage) {
|
|
59
|
+
const dispatcher = new node_sdk_1.EventDispatcher({}).register({
|
|
60
|
+
"im.message.receive_v1": async (data) => { const event = parseFeishuEvent(data); if (event)
|
|
61
|
+
await onMessage(event); },
|
|
62
|
+
});
|
|
63
|
+
try {
|
|
64
|
+
await new Promise((resolve, reject) => {
|
|
65
|
+
const timer = setTimeout(() => { reject(new Error("飞书连接超时,请检查凭据及长连接订阅设置")); }, 20_000);
|
|
66
|
+
const finish = (error) => { clearTimeout(timer); if (error)
|
|
67
|
+
reject(error);
|
|
68
|
+
else
|
|
69
|
+
resolve(); };
|
|
70
|
+
const client = new node_sdk_1.WSClient({
|
|
71
|
+
appId: this.config.app_id, appSecret: this.config.app_secret,
|
|
72
|
+
...(this.config.api_base ? { domain: this.apiBase() } : {}),
|
|
73
|
+
loggerLevel: node_sdk_1.LoggerLevel.fatal,
|
|
74
|
+
handshakeTimeoutMs: 10_000,
|
|
75
|
+
onReady: () => finish(), onError: (error) => finish(error),
|
|
76
|
+
});
|
|
77
|
+
this.sdkClient = client;
|
|
78
|
+
void client.start({ eventDispatcher: dispatcher }).catch(finish);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
this.close();
|
|
83
|
+
throw error;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
54
86
|
async send(peerId, text, threadId) {
|
|
55
87
|
const token = await this.accessToken();
|
|
56
88
|
const body = { receive_id: peerId, msg_type: "text", content: JSON.stringify({ text }) };
|
|
@@ -83,16 +115,6 @@ class FeishuClient {
|
|
|
83
115
|
if (event)
|
|
84
116
|
await onMessage(event);
|
|
85
117
|
}
|
|
86
|
-
async endpoint() {
|
|
87
|
-
const response = await this.transport.fetch(`${this.apiBase()}/open-apis/callback/ws/endpoint?app_id=${encodeURIComponent(this.config.app_id)}&app_secret=${encodeURIComponent(this.config.app_secret)}`);
|
|
88
|
-
if (!response.ok)
|
|
89
|
-
throw new Error(`获取飞书长连接地址失败:HTTP ${response.status}`);
|
|
90
|
-
const result = await response.json();
|
|
91
|
-
const url = result.data?.URL ?? result.data?.url;
|
|
92
|
-
if (result.code && result.code !== 0 || !url)
|
|
93
|
-
throw new Error(`获取飞书长连接地址失败:${result.msg ?? "响应无 URL"}`);
|
|
94
|
-
return url;
|
|
95
|
-
}
|
|
96
118
|
async accessToken() {
|
|
97
119
|
if (this.token && Date.now() < this.tokenExpires)
|
|
98
120
|
return this.token;
|
|
@@ -3,8 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.FeishuPlugin = void 0;
|
|
4
4
|
const promises_1 = require("node:fs/promises");
|
|
5
5
|
const node_path_1 = require("node:path");
|
|
6
|
+
const qrcode_1 = require("qrcode");
|
|
6
7
|
const client_1 = require("./client");
|
|
7
|
-
const manifest = { id: "feishu", version: "1.0.
|
|
8
|
+
const manifest = { id: "feishu", version: "1.0.2", type: "channel", displayName: "飞书通道", entry: "dist/src-ts/plugins/feishu/index.js", apiVersion: "1", process: "in-process", capabilities: ["channel", "channel.bot.setup", "channel.receive", "channel.send", "health"], configSchema: "config.schema.json", managementPage: "/abweb/channels/feishu" };
|
|
8
9
|
class FeishuPlugin {
|
|
9
10
|
options;
|
|
10
11
|
manifest = manifest;
|
|
@@ -57,7 +58,7 @@ class FeishuPlugin {
|
|
|
57
58
|
this.bindings = this.config.bindings && typeof this.config.bindings === "object" ? { ...this.config.bindings } : {};
|
|
58
59
|
if (!this.config.app_id || !this.config.app_secret)
|
|
59
60
|
return;
|
|
60
|
-
this.client
|
|
61
|
+
this.client = this.options.client ?? new client_1.FeishuClient(this.config);
|
|
61
62
|
try {
|
|
62
63
|
await this.client.start((event) => this.onMessage(event));
|
|
63
64
|
this.status = "ready";
|
|
@@ -127,19 +128,23 @@ class FeishuPlugin {
|
|
|
127
128
|
this.json(response, 503, { error: "飞书设置页面资源不可用" });
|
|
128
129
|
}
|
|
129
130
|
};
|
|
130
|
-
configureBot = async (request, response) => {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
131
|
+
configureBot = async (request, response) => {
|
|
132
|
+
try {
|
|
133
|
+
const body = await this.readJson(request);
|
|
134
|
+
const appId = typeof body.app_id === "string" ? body.app_id.trim() : "";
|
|
135
|
+
const providedSecret = typeof body.app_secret === "string" ? body.app_secret.trim() : "";
|
|
136
|
+
const appSecret = providedSecret || (appId === this.config.app_id ? this.config.app_secret : "");
|
|
137
|
+
if (!appId || !appSecret)
|
|
138
|
+
return this.json(response, 400, { error: "新机器人需要同时提供 App ID 和 App Secret" });
|
|
139
|
+
this.config = { ...this.config, app_id: appId, app_secret: appSecret };
|
|
140
|
+
await this.persist();
|
|
141
|
+
this.context?.logger.info("飞书机器人凭据已保存", { appId });
|
|
142
|
+
this.json(response, 200, { app_id: appId, status: "已保存,重载插件后连接" });
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
this.json(response, 400, { error: error instanceof Error ? error.message : String(error) });
|
|
146
|
+
}
|
|
147
|
+
};
|
|
143
148
|
configureSettings = async (request, response) => {
|
|
144
149
|
try {
|
|
145
150
|
const body = await this.readJson(request);
|
|
@@ -166,7 +171,10 @@ class FeishuPlugin {
|
|
|
166
171
|
throw new Error(result.error_description ? `${result.error}: ${result.error_description}` : result.error);
|
|
167
172
|
if (typeof result.device_code !== "string" || typeof result.verification_uri_complete !== "string")
|
|
168
173
|
throw new Error("飞书授权响应缺少设备码或授权 URL");
|
|
169
|
-
|
|
174
|
+
const url = new URL(result.verification_uri_complete);
|
|
175
|
+
if (url.protocol !== "https:")
|
|
176
|
+
throw new Error("飞书授权 URL 必须使用 HTTPS");
|
|
177
|
+
this.json(response, 200, { device_code: result.device_code, url: url.href, qr_url: url.href, qr_image: await (0, qrcode_1.toDataURL)(url.href, { width: 256, margin: 4 }), interval: Number(result.interval ?? 5), expires_in: Number(result.expires_in ?? result.expire_in ?? 600) });
|
|
170
178
|
}
|
|
171
179
|
catch (error) {
|
|
172
180
|
this.json(response, 502, { error: error instanceof Error ? error.message : String(error) });
|
|
@@ -185,11 +193,12 @@ class FeishuPlugin {
|
|
|
185
193
|
if (appId && appSecret) {
|
|
186
194
|
this.config = { ...this.config, app_id: appId, app_secret: appSecret };
|
|
187
195
|
await this.persist();
|
|
196
|
+
this.context?.logger.info("飞书授权凭据已自动保存", { appId });
|
|
188
197
|
return this.json(response, 200, { status: "completed", app_id: appId, owner_open_id: user?.open_id });
|
|
189
198
|
}
|
|
190
199
|
const errorCode = typeof result.error === "string" ? result.error : "";
|
|
191
|
-
const status =
|
|
192
|
-
return this.json(response, 200, { status, ...(status === "error" ? { error: result.error_description || errorCode || "飞书授权响应无效" } : {}) });
|
|
200
|
+
const status = ["authorization_pending", "slow_down"].includes(errorCode) ? "pending" : errorCode === "access_denied" ? "denied" : errorCode === "expired_token" ? "expired" : "error";
|
|
201
|
+
return this.json(response, 200, { status, ...(status === "error" ? { error: result.error_description || errorCode || "飞书授权响应无效" } : {}), ...(errorCode === "slow_down" ? { slow_down: true } : {}) });
|
|
193
202
|
}
|
|
194
203
|
catch (error) {
|
|
195
204
|
this.json(response, 502, { error: error instanceof Error ? error.message : String(error) });
|
|
@@ -3,14 +3,21 @@
|
|
|
3
3
|
const notice = find("#notice");
|
|
4
4
|
const authState = find("#authorization-state");
|
|
5
5
|
const authLink = find("#authorization-link");
|
|
6
|
+
const authDetails = find("#authorization-details");
|
|
7
|
+
const authQr = find("#authorization-qr");
|
|
8
|
+
const authUrl = find("#authorization-url");
|
|
6
9
|
const credentials = find("#credentials");
|
|
7
10
|
const binding = find("#binding");
|
|
8
11
|
const settings = find("#settings");
|
|
9
12
|
let pollTimer;
|
|
13
|
+
let setup = 0;
|
|
14
|
+
let savedAppId = "";
|
|
15
|
+
let secretMasked = false;
|
|
16
|
+
const authorizationKey = "mab-feishu-authorization";
|
|
10
17
|
|
|
11
18
|
async function request(path, method = "GET", body) {
|
|
12
19
|
const token = localStorage.getItem("mab-login-token");
|
|
13
|
-
const response = await fetch(path, { method, headers: { ...(token ? { authorization: `Bearer ${token}` } : {}), ...(body ? { "content-type": "application/json" } : {}) }, ...(body ? { body: JSON.stringify(body) } : {}) });
|
|
20
|
+
const response = await fetch(path, { method, signal: AbortSignal.timeout(30_000), headers: { ...(token ? { authorization: `Bearer ${token}` } : {}), ...(body ? { "content-type": "application/json" } : {}) }, ...(body ? { body: JSON.stringify(body) } : {}) });
|
|
14
21
|
const result = await response.json();
|
|
15
22
|
if (!response.ok) throw new Error(result.error || `请求失败:${response.status}`);
|
|
16
23
|
return result;
|
|
@@ -27,46 +34,93 @@
|
|
|
27
34
|
settings.elements.allow_from.value = state.allow_from || "";
|
|
28
35
|
settings.elements.allow_chats.value = state.allow_chats || "";
|
|
29
36
|
credentials.elements.app_id.value = state.app_id || "";
|
|
30
|
-
|
|
37
|
+
savedAppId = state.configured ? state.app_id : "";
|
|
38
|
+
secretMasked = state.configured;
|
|
39
|
+
credentials.elements.app_secret.value = secretMasked ? "********" : "";
|
|
40
|
+
credentials.elements.app_secret.required = !state.configured;
|
|
41
|
+
credentials.elements.app_secret.placeholder = state.configured ? "已保存,留空使用已有凭据" : "App Secret 必填";
|
|
31
42
|
find("#connection").textContent = state.message || state.status;
|
|
32
43
|
find("#app-id").textContent = state.app_id || "未配置";
|
|
33
44
|
const bound = state.bindings?.[state.app_id] || "";
|
|
34
45
|
find("#bound-agent").textContent = bound || state.agent_plugin || "未关联";
|
|
35
46
|
binding.elements.pluginId.value = bound;
|
|
36
|
-
show(state.configured ? "
|
|
37
|
-
|
|
47
|
+
show(state.configured ? state.status === "ready" ? "机器人已连接" : `凭据已保存,但连接失败:${state.message || state.status}` : "请授权或手动配置机器人凭据", state.configured && state.status !== "ready");
|
|
48
|
+
return state;
|
|
49
|
+
} catch (error) { show(String(error), true); throw error; }
|
|
38
50
|
}
|
|
39
51
|
async function reconnect() {
|
|
40
52
|
await request("/api/plugins/feishu/reload", "POST");
|
|
41
|
-
await load();
|
|
53
|
+
const state = await load();
|
|
54
|
+
if (state.status !== "ready") throw new Error(state.message || "飞书尚未连接");
|
|
42
55
|
}
|
|
43
|
-
async function poll(deviceCode, interval, deadline) {
|
|
44
|
-
if (
|
|
56
|
+
async function poll(deviceCode, interval, deadline, currentSetup) {
|
|
57
|
+
if (currentSetup !== setup) return;
|
|
58
|
+
if (Date.now() >= deadline) { sessionStorage.removeItem(authorizationKey); authState.textContent = "授权已过期,请重新开始"; find("#begin").disabled = false; return; }
|
|
45
59
|
try {
|
|
46
60
|
const result = await request("/api/plugins/feishu/setup/poll", "POST", { device_code: deviceCode });
|
|
47
|
-
if (
|
|
48
|
-
if (result.status === "
|
|
49
|
-
|
|
50
|
-
|
|
61
|
+
if (currentSetup !== setup) return;
|
|
62
|
+
if (result.status === "completed") {
|
|
63
|
+
sessionStorage.removeItem(authorizationKey);
|
|
64
|
+
credentials.elements.app_id.value = result.app_id;
|
|
65
|
+
find("#app-id").textContent = result.app_id;
|
|
66
|
+
authState.textContent = "授权完成,凭据已自动保存,正在连接";
|
|
67
|
+
try { await reconnect(); authState.textContent = "授权完成,机器人已连接"; }
|
|
68
|
+
catch (error) { authState.textContent = "授权完成,凭据已自动保存,但连接失败"; show(String(error), true); }
|
|
69
|
+
find("#begin").disabled = false;
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (["denied", "expired", "error"].includes(result.status)) sessionStorage.removeItem(authorizationKey);
|
|
73
|
+
if (result.status === "denied") { authState.textContent = "授权已拒绝"; find("#begin").disabled = false; return; }
|
|
74
|
+
if (result.status === "expired") { authState.textContent = "授权已过期,请重新开始"; find("#begin").disabled = false; return; }
|
|
75
|
+
if (result.status === "error") { authState.textContent = `授权失败:${result.error || "未知错误"}`; find("#begin").disabled = false; return; }
|
|
51
76
|
authState.textContent = "等待飞书授权";
|
|
52
|
-
|
|
53
|
-
|
|
77
|
+
const nextInterval = interval + (result.slow_down ? 5000 : 0);
|
|
78
|
+
pollTimer = setTimeout(() => void poll(deviceCode, nextInterval, deadline, currentSetup), nextInterval);
|
|
79
|
+
} catch (error) { if (currentSetup === setup) { authState.textContent = `授权检查暂时失败,将重试:${String(error)}`; pollTimer = setTimeout(() => void poll(deviceCode, interval, deadline, currentSetup), interval); } }
|
|
54
80
|
}
|
|
55
81
|
find("#begin").onclick = async () => {
|
|
56
|
-
|
|
82
|
+
const currentSetup = ++setup;
|
|
83
|
+
find("#begin").disabled = true;
|
|
84
|
+
clearTimeout(pollTimer); authLink.hidden = true; authDetails.hidden = true; authState.textContent = "正在申请设备授权";
|
|
57
85
|
try {
|
|
58
86
|
const result = await request("/api/plugins/feishu/setup/begin", "POST");
|
|
87
|
+
if (currentSetup !== setup) return;
|
|
59
88
|
const url = new URL(result.url);
|
|
60
89
|
if (url.protocol !== "https:") throw new Error("飞书授权地址无效");
|
|
61
90
|
authLink.href = url.href; authLink.hidden = false;
|
|
91
|
+
authQr.src = result.qr_image;
|
|
92
|
+
authUrl.textContent = url.href;
|
|
93
|
+
authDetails.hidden = false;
|
|
62
94
|
authState.textContent = "等待飞书授权";
|
|
63
|
-
|
|
64
|
-
|
|
95
|
+
const interval = Math.max(1, Number(result.interval) || 5) * 1000;
|
|
96
|
+
const deadline = Date.now() + (Number(result.expires_in) || 600) * 1000;
|
|
97
|
+
sessionStorage.setItem(authorizationKey, JSON.stringify({ deviceCode: result.device_code, interval, deadline }));
|
|
98
|
+
pollTimer = setTimeout(() => void poll(result.device_code, interval, deadline, currentSetup), interval);
|
|
99
|
+
} catch (error) { if (currentSetup === setup) { authState.textContent = `启动授权失败:${String(error)}`; find("#begin").disabled = false; } }
|
|
100
|
+
};
|
|
101
|
+
credentials.elements.app_id.oninput = () => {
|
|
102
|
+
const changed = credentials.elements.app_id.value.trim() !== savedAppId;
|
|
103
|
+
if (changed && secretMasked) { credentials.elements.app_secret.value = ""; secretMasked = false; }
|
|
104
|
+
credentials.elements.app_secret.required = changed;
|
|
105
|
+
};
|
|
106
|
+
credentials.elements.app_secret.oninput = () => { secretMasked = false; };
|
|
107
|
+
credentials.elements.app_secret.addEventListener("invalid", () => show("首次配置或更换机器人时,App ID 和 App Secret 都需要填写", true));
|
|
108
|
+
credentials.onsubmit = async (event) => {
|
|
109
|
+
event.preventDefault(); const button = credentials.querySelector("button"); button.disabled = true; show("正在保存凭据并连接飞书");
|
|
110
|
+
try { await request("/api/plugins/feishu/bot", "POST", { app_id: credentials.elements.app_id.value.trim(), app_secret: secretMasked ? "" : credentials.elements.app_secret.value }); savedAppId = credentials.elements.app_id.value.trim(); secretMasked = true; credentials.elements.app_secret.value = "********"; await reconnect(); show("凭据已保存,机器人已连接"); }
|
|
111
|
+
catch (error) { show(String(error), true); }
|
|
112
|
+
finally { button.disabled = false; }
|
|
65
113
|
};
|
|
66
|
-
credentials.onsubmit = (event) => { event.preventDefault(); void request("/api/plugins/feishu/bot", "POST", { app_id: credentials.elements.app_id.value.trim(), app_secret: credentials.elements.app_secret.value }).then(reconnect).then(() => show("凭据已保存,正在连接")).catch((error) => show(String(error), true)); };
|
|
67
114
|
binding.onsubmit = (event) => { event.preventDefault(); void request("/api/plugins/feishu/bind", "POST", { pluginId: binding.elements.pluginId.value }).then(load).then(() => show("Agent 已关联")).catch((error) => show(String(error), true)); };
|
|
68
115
|
settings.onsubmit = (event) => { event.preventDefault(); void request("/api/plugins/feishu/settings", "POST", { agent_plugin: settings.elements.agent_plugin.value, allow_from: settings.elements.allow_from.value, allow_chats: settings.elements.allow_chats.value }).then(load).then(() => show("配置已保存")).catch((error) => show(String(error), true)); };
|
|
69
|
-
find("#refresh").onclick = () => void load();
|
|
70
|
-
window.addEventListener("pagehide", () => clearTimeout(pollTimer));
|
|
71
|
-
void load();
|
|
116
|
+
find("#refresh").onclick = () => void load().catch(() => {});
|
|
117
|
+
window.addEventListener("pagehide", () => { setup++; clearTimeout(pollTimer); });
|
|
118
|
+
void load().catch(() => {});
|
|
119
|
+
try {
|
|
120
|
+
const pending = JSON.parse(sessionStorage.getItem(authorizationKey) || "null");
|
|
121
|
+
if (pending && typeof pending.deviceCode === "string" && Number.isFinite(pending.deadline) && Number.isFinite(pending.interval) && pending.interval >= 1000) {
|
|
122
|
+
find("#begin").disabled = true;
|
|
123
|
+
void poll(pending.deviceCode, pending.interval, pending.deadline, setup);
|
|
124
|
+
}
|
|
125
|
+
} catch { sessionStorage.removeItem(authorizationKey); }
|
|
72
126
|
})();
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
<header><h1>飞书机器人</h1><button id="refresh" type="button">刷新</button></header>
|
|
7
7
|
<p id="notice" role="status"></p>
|
|
8
8
|
<dl><div><dt>连接状态</dt><dd id="connection">未配置</dd></div><div><dt>App ID</dt><dd id="app-id">未配置</dd></div><div><dt>关联 Agent</dt><dd id="bound-agent">未关联</dd></div></dl>
|
|
9
|
-
<section><h2
|
|
9
|
+
<section><h2>创建设备授权</h2><div class="actions"><button id="begin" type="button">创建飞书机器人</button><a id="authorization-link" target="_blank" rel="noopener noreferrer" hidden>打开飞书创建链接</a></div><div id="authorization-details" hidden><img id="authorization-qr" width="256" height="256" alt="飞书机器人创建授权二维码"><p id="authorization-url"></p></div><p id="authorization-state" role="status"></p></section>
|
|
10
10
|
<form id="credentials"><h2>手动配置凭据</h2><div class="fields"><label>App ID<input name="app_id" required autocomplete="off"></label><label>App Secret<input name="app_secret" type="password" required autocomplete="new-password"></label></div><button type="submit">保存并连接</button></form>
|
|
11
11
|
<form id="binding"><h2>关联 Agent</h2><div class="fields"><label>Agent<select name="pluginId" required></select></label></div><button type="submit">关联</button></form>
|
|
12
12
|
<form id="settings"><h2>通道配置</h2><div class="fields"><label>默认 Agent<select name="agent_plugin"></select></label><label>允许的 open_id<input name="allow_from"></label><label>允许的 chat_id<input name="allow_chats"></label></div><button type="submit">保存配置</button></form>
|
|
@@ -17,6 +17,9 @@ input, select, button { min-height: 34px; padding: 6px 9px; border: 1px solid #b
|
|
|
17
17
|
button { cursor: pointer; }
|
|
18
18
|
button:hover { background: #e5f2ea; }
|
|
19
19
|
.actions { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
|
|
20
|
+
#authorization-details { margin-top: 12px; }
|
|
21
|
+
#authorization-qr { display: block; width: min(256px, 100%); height: auto; aspect-ratio: 1; }
|
|
22
|
+
#authorization-url { overflow-wrap: anywhere; }
|
|
20
23
|
a { color: #176848; }
|
|
21
24
|
.error { color: #a83427; }
|
|
22
25
|
@media (max-width: 620px) { .fields, dl { grid-template-columns: 1fr; } }
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agent-bridge-feishu",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "agent-bridge 的飞书通道插件。",
|
|
5
5
|
"keywords": ["mu-agent-bridge-plugin", "mu-agent-bridge-channel"],
|
|
6
6
|
"main": "dist/src-ts/plugins/feishu/index.js",
|
|
7
7
|
"files": ["dist/", "plugin.json", "config.schema.json", "README.md"],
|
|
8
8
|
"agentBridge": { "plugin": "./plugin.json", "type": "channel" },
|
|
9
9
|
"engines": { "node": ">=22" },
|
|
10
|
+
"dependencies": { "qrcode": "^1.5.4", "@larksuiteoapi/node-sdk": "1.74.0" },
|
|
10
11
|
"publishConfig": { "access": "public", "registry": "https://registry.npmjs.org" }
|
|
11
12
|
}
|