@michengai/dsh-im-connect 0.1.0 → 0.1.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.en.md +224 -0
- package/README.md +204 -19
- package/assets/branding/dsh-banner.png +0 -0
- package/assets/screenshots/dingtalk-chat.jpg +0 -0
- package/assets/screenshots/feishu-chat.jpg +0 -0
- package/assets/screenshots/qq-chat.jpg +0 -0
- package/assets/screenshots/settings-channels.png +0 -0
- package/assets/screenshots/telegram-chat.jpg +0 -0
- package/assets/screenshots/wecom-chat.jpg +0 -0
- package/assets/screenshots/wecom-qr.png +0 -0
- package/assets/screenshots/weixin-chat.jpg +0 -0
- package/assets/screenshots/workspace-channels.png +0 -0
- package/client.js +158 -82
- package/lib/channels/dingtalk-card.d.ts +2 -1
- package/lib/channels/dingtalk-card.d.ts.map +1 -1
- package/lib/channels/dingtalk-card.js +13 -5
- package/lib/channels/dingtalk-card.js.map +1 -1
- package/lib/channels/dingtalk.d.ts +19 -0
- package/lib/channels/dingtalk.d.ts.map +1 -1
- package/lib/channels/dingtalk.js +30 -16
- package/lib/channels/dingtalk.js.map +1 -1
- package/lib/channels/factory.d.ts.map +1 -1
- package/lib/channels/factory.js +3 -0
- package/lib/channels/factory.js.map +1 -1
- package/lib/channels/feishu.d.ts.map +1 -1
- package/lib/channels/feishu.js +5 -2
- package/lib/channels/feishu.js.map +1 -1
- package/lib/channels/meta.d.ts.map +1 -1
- package/lib/channels/meta.js +11 -0
- package/lib/channels/meta.js.map +1 -1
- package/lib/channels/qq.d.ts +9 -0
- package/lib/channels/qq.d.ts.map +1 -0
- package/lib/channels/qq.js +279 -0
- package/lib/channels/qq.js.map +1 -0
- package/lib/channels/qr/hub.d.ts +4 -1
- package/lib/channels/qr/hub.d.ts.map +1 -1
- package/lib/channels/qr/hub.js +27 -0
- package/lib/channels/qr/hub.js.map +1 -1
- package/lib/channels/qr/qq.d.ts +18 -0
- package/lib/channels/qr/qq.d.ts.map +1 -0
- package/lib/channels/qr/qq.js +86 -0
- package/lib/channels/qr/qq.js.map +1 -0
- package/lib/channels/qr/shared.d.ts +3 -0
- package/lib/channels/qr/shared.d.ts.map +1 -1
- package/lib/channels/qr/shared.js.map +1 -1
- package/lib/channels/telegram.d.ts.map +1 -1
- package/lib/channels/telegram.js +39 -8
- package/lib/channels/telegram.js.map +1 -1
- package/lib/channels/wecom.d.ts +1 -0
- package/lib/channels/wecom.d.ts.map +1 -1
- package/lib/channels/wecom.js +35 -15
- package/lib/channels/wecom.js.map +1 -1
- package/lib/channels/weixin.d.ts.map +1 -1
- package/lib/channels/weixin.js +9 -18
- package/lib/channels/weixin.js.map +1 -1
- package/lib/client.js +158 -82
- package/lib/engine/gateway.d.ts +3 -10
- package/lib/engine/gateway.d.ts.map +1 -1
- package/lib/engine/gateway.js +54 -65
- package/lib/engine/gateway.js.map +1 -1
- package/lib/engine/quiet-logger.d.ts +9 -0
- package/lib/engine/quiet-logger.d.ts.map +1 -0
- package/lib/engine/quiet-logger.js +26 -0
- package/lib/engine/quiet-logger.js.map +1 -0
- package/lib/engine/reply-stream.d.ts +25 -0
- package/lib/engine/reply-stream.d.ts.map +1 -0
- package/lib/engine/reply-stream.js +62 -0
- package/lib/engine/reply-stream.js.map +1 -0
- package/lib/engine/session-id.d.ts +1 -1
- package/lib/engine/session-id.d.ts.map +1 -1
- package/lib/engine/session-id.js +1 -1
- package/lib/engine/session-id.js.map +1 -1
- package/lib/engine/types.d.ts +0 -2
- package/lib/engine/types.d.ts.map +1 -1
- package/lib/index.d.ts +0 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +0 -2
- package/lib/index.js.map +1 -1
- package/lib/manager.d.ts +1 -12
- package/lib/manager.d.ts.map +1 -1
- package/lib/manager.js +165 -167
- package/lib/manager.js.map +1 -1
- package/package.json +15 -4
- package/src/channels/dingtalk-card.ts +13 -6
- package/src/channels/dingtalk.ts +43 -18
- package/src/channels/factory.ts +8 -2
- package/src/channels/feishu.ts +6 -2
- package/src/channels/meta.ts +13 -0
- package/src/channels/qq.ts +302 -0
- package/src/channels/qr/hub.ts +27 -3
- package/src/channels/qr/qq.ts +91 -0
- package/src/channels/qr/shared.ts +4 -0
- package/src/channels/telegram.ts +39 -9
- package/src/channels/wecom.ts +37 -16
- package/src/channels/weixin.ts +44 -52
- package/src/engine/gateway.ts +316 -325
- package/src/engine/quiet-logger.ts +23 -0
- package/src/engine/reply-stream.ts +67 -0
- package/src/engine/session-id.ts +3 -2
- package/src/engine/types.ts +1 -3
- package/src/index.ts +2 -5
- package/src/manager.ts +542 -569
- package/src/engine/access.ts +0 -17
package/lib/client.js
CHANGED
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
* dsh-im-connect 浏览器端:IM助理设置页 + 工作区频道槽。
|
|
3
3
|
*/
|
|
4
4
|
window.__ModuleLoader__.load({
|
|
5
|
-
id: "dsh-im-connect",
|
|
5
|
+
id: "@michengai/dsh-im-connect",
|
|
6
6
|
factory: (require) => {
|
|
7
7
|
var module = { exports: {} };
|
|
8
8
|
var exports = module.exports;
|
|
9
9
|
const React = require("react");
|
|
10
|
-
const { useState, useEffect, useCallback, useRef, useSyncExternalStore } = React;
|
|
10
|
+
const { useState, useEffect, useLayoutEffect, useCallback, useRef, useSyncExternalStore } = React;
|
|
11
|
+
const ReactDOM = require("react-dom");
|
|
11
12
|
const EMPTY_EXTRA_TABS = [];
|
|
12
13
|
const inject = ["slots", "sessions", "workspaces"];
|
|
13
14
|
const API_BASE = "/dsh-im-connect/api";
|
|
@@ -81,8 +82,6 @@ window.__ModuleLoader__.load({
|
|
|
81
82
|
.ima-switch i{position:absolute;top:2px;left:20px;width:18px;height:18px;border-radius:50%;background:#fff;transition:left .16s ease}
|
|
82
83
|
.ima-switch.off i{left:2px}
|
|
83
84
|
.ima-error{color:var(--ima-danger);font-size:12px;margin:0 0 12px}
|
|
84
|
-
.ima-pending{margin:0 0 14px;padding:10px 12px;border:1px solid rgba(210,153,34,.35);border-radius:12px}
|
|
85
|
-
.ima-pending-row{display:flex;gap:8px;align-items:center;margin-top:8px}
|
|
86
85
|
.ima-wrap{display:flex;flex-direction:column;min-height:0;flex:1;height:100%;overflow:hidden}.ima-official-tree{flex:1;min-height:0;display:flex;flex-direction:column;overflow:hidden}.ima-native,.ima-rail.ima-native,.ima-rail.dcu-wb{box-sizing:border-box;padding-right:var(--dsh-sidebar-inline-padding,12px)}
|
|
87
86
|
.ima-tabs{display:flex;gap:18px;padding:4px 12px 0;border-bottom:1px solid var(--ima-line)}
|
|
88
87
|
.ima-tab{appearance:none;border:0;background:transparent;color:var(--ima-muted);padding:8px 0;font-size:13px;cursor:pointer}
|
|
@@ -106,7 +105,7 @@ window.__ModuleLoader__.load({
|
|
|
106
105
|
.ima-logo svg{width:28px;height:28px;display:block}
|
|
107
106
|
.ima-logo.sm{width:16px;height:16px;overflow:visible}
|
|
108
107
|
.ima-logo.sm svg{width:16px;height:16px}
|
|
109
|
-
.ima-logo.sm[data-brand="weixin"] svg,.ima-logo.sm[data-brand="feishu"] svg,.ima-logo.sm[data-brand="lark"] svg,.ima-logo.sm[data-brand="telegram"] svg{transform:scale(1.2);transform-origin:center}
|
|
108
|
+
.ima-logo.sm[data-brand="weixin"] svg,.ima-logo.sm[data-brand="feishu"] svg,.ima-logo.sm[data-brand="lark"] svg,.ima-logo.sm[data-brand="telegram"] svg,.ima-logo.sm[data-brand="qq"] svg{transform:scale(1.2);transform-origin:center}
|
|
110
109
|
.ima-logo[data-brand="wecom"]{border-radius:6px;box-shadow:inset 0 0 0 1px rgba(15,23,42,.12);overflow:hidden;background:#fff}
|
|
111
110
|
.ima-logo.sm[data-brand="wecom"]{border-radius:4px}
|
|
112
111
|
.ima-mask{position:fixed;inset:0;background:var(--dsw-alias-bg-mask-1,rgba(0,0,0,.45));backdrop-filter:var(--dsw-mask-blur,blur(8px));display:grid;place-items:center;z-index:80;padding:24px}
|
|
@@ -183,6 +182,12 @@ window.__ModuleLoader__.load({
|
|
|
183
182
|
]);
|
|
184
183
|
}
|
|
185
184
|
|
|
185
|
+
if (id === "qq") {
|
|
186
|
+
return svg("0 0 24 24", [
|
|
187
|
+
h("path", { key: "mark", fill: "#12B7F5", d: "M21.395 15.035a40 40 0 0 0-.803-2.264l-1.079-2.695c.001-.032.014-.562.014-.836C19.526 4.632 17.351 0 12 0S4.474 4.632 4.474 9.241c0 .274.013.804.014.836l-1.08 2.695a39 39 0 0 0-.802 2.264c-1.021 3.283-.69 4.643-.438 4.673.54.065 2.103-2.472 2.103-2.472 0 1.469.756 3.387 2.394 4.771-.612.188-1.363.479-1.845.835-.434.32-.379.646-.301.778.343.578 5.883.369 7.482.189 1.6.18 7.14.389 7.483-.189.078-.132.132-.458-.301-.778-.483-.356-1.233-.646-1.846-.836 1.637-1.384 2.393-3.302 2.393-4.771 0 0 1.563 2.537 2.103 2.472.251-.03.581-1.39-.438-4.673" }),
|
|
188
|
+
]);
|
|
189
|
+
}
|
|
190
|
+
|
|
186
191
|
if (id === "telegram") {
|
|
187
192
|
return svg("0 0 24 24", [
|
|
188
193
|
h("path", { key: "mark", fill: "#26A5E4", d: "M11.944 0A12 12 0 0 0 0 12a12 12 0 0 0 12 12 12 12 0 0 0 12-12A12 12 0 0 0 12 0a12 12 0 0 0-.056 0zm4.962 7.224c.1-.002.321.023.465.14a.506.506 0 0 1 .171.325c.016.093.036.306.02.472-.18 1.898-.962 6.502-1.36 8.627-.168.9-.499 1.201-.82 1.23-.696.065-1.225-.46-1.9-.902-1.056-.693-1.653-1.124-2.678-1.8-1.185-.78-.417-1.21.258-1.91.177-.184 3.247-2.977 3.307-3.23.007-.032.014-.15-.056-.212s-.174-.041-.249-.024c-.106.024-1.793 1.14-5.061 3.345-.48.33-.913.49-1.302.48-.428-.008-1.252-.241-1.865-.44-.752-.245-1.349-.374-1.297-.789.027-.216.325-.437.893-.663 3.498-1.524 5.83-2.529 6.998-3.014 3.332-1.386 4.025-1.627 4.476-1.635z" }),
|
|
@@ -216,6 +221,7 @@ window.__ModuleLoader__.load({
|
|
|
216
221
|
if (ch.id === "lark") return "请使用 Lark 扫描二维码完成配对";
|
|
217
222
|
if (ch.id === "wecom") return "请使用企业微信扫描二维码,快捷绑定机器人";
|
|
218
223
|
if (ch.id === "dingtalk") return "请使用钉钉扫描二维码,自动创建机器人";
|
|
224
|
+
if (ch.id === "qq") return "请使用手机 QQ 扫描二维码,创建开放平台机器人";
|
|
219
225
|
return "请使用对应 App 扫描二维码";
|
|
220
226
|
}
|
|
221
227
|
|
|
@@ -253,7 +259,6 @@ window.__ModuleLoader__.load({
|
|
|
253
259
|
const [tab, setTab] = useState(hasQr ? "qr" : "manual");
|
|
254
260
|
const [pairing, setPairing] = useState(null);
|
|
255
261
|
const [draft, setDraft] = useState({});
|
|
256
|
-
const [accessMode, setAccessMode] = useState(ch.accessMode === "open" ? "open" : "pair");
|
|
257
262
|
const [busy, setBusy] = useState(false);
|
|
258
263
|
const [error, setError] = useState("");
|
|
259
264
|
const alive = useRef(true);
|
|
@@ -265,14 +270,14 @@ window.__ModuleLoader__.load({
|
|
|
265
270
|
api(`/channels/${ch.id}/qr/${refresh ? "refresh" : "start"}`, {
|
|
266
271
|
method: "POST",
|
|
267
272
|
headers: { "content-type": "application/json" },
|
|
268
|
-
body: JSON.stringify(
|
|
273
|
+
body: JSON.stringify({}),
|
|
269
274
|
}).then((data) => {
|
|
270
275
|
if (!alive.current) return;
|
|
271
276
|
if (!data.ok && !data.pairing) setError(data.error || "无法生成二维码");
|
|
272
277
|
setPairing(data.pairing || null);
|
|
273
278
|
}).catch(() => { if (alive.current) setError("无法生成二维码"); })
|
|
274
279
|
.finally(() => { if (alive.current) setBusy(false); });
|
|
275
|
-
}, [ch.id, hasQr
|
|
280
|
+
}, [ch.id, hasQr]);
|
|
276
281
|
|
|
277
282
|
useEffect(() => {
|
|
278
283
|
alive.current = true;
|
|
@@ -296,13 +301,27 @@ window.__ModuleLoader__.load({
|
|
|
296
301
|
|
|
297
302
|
const close = () => {
|
|
298
303
|
alive.current = false;
|
|
299
|
-
if (hasQr) api(
|
|
304
|
+
if (hasQr) api("/channels/" + ch.id + "/qr/cancel", { method: "POST" }).catch(() => undefined);
|
|
300
305
|
onClose();
|
|
301
306
|
};
|
|
307
|
+
const onCloseRef = useRef(onClose);
|
|
308
|
+
onCloseRef.current = onClose;
|
|
309
|
+
useEffect(() => {
|
|
310
|
+
const onKeyDown = (event) => {
|
|
311
|
+
if (event.key !== "Escape") return;
|
|
312
|
+
event.preventDefault();
|
|
313
|
+
event.stopPropagation();
|
|
314
|
+
if (typeof event.stopImmediatePropagation === "function") event.stopImmediatePropagation();
|
|
315
|
+
alive.current = false;
|
|
316
|
+
if (hasQr) api("/channels/" + ch.id + "/qr/cancel", { method: "POST" }).catch(() => undefined);
|
|
317
|
+
onCloseRef.current();
|
|
318
|
+
};
|
|
319
|
+
window.addEventListener("keydown", onKeyDown, true);
|
|
320
|
+
return () => window.removeEventListener("keydown", onKeyDown, true);
|
|
321
|
+
}, [hasQr, ch.id]);
|
|
302
322
|
|
|
303
323
|
const saveManual = () => {
|
|
304
324
|
const config = { ...draft };
|
|
305
|
-
if (ch.id === "dingtalk") config.accessMode = accessMode;
|
|
306
325
|
setBusy(true);
|
|
307
326
|
setError("");
|
|
308
327
|
api(`/channels/${ch.id}/connect`, {
|
|
@@ -326,7 +345,7 @@ window.__ModuleLoader__.load({
|
|
|
326
345
|
const src = qrSrc(pairing);
|
|
327
346
|
const remain = pairing && pairing.remainingSeconds;
|
|
328
347
|
|
|
329
|
-
return h("div", { className: "ima-mask", onClick: close },
|
|
348
|
+
return h("div", { className: "ima-mask", role: "presentation", onClick: close, onKeyDown: (event) => { if (event.key === "Escape") { event.preventDefault(); event.stopPropagation(); close(); } } },
|
|
330
349
|
h("div", { className: "ima-modal", onClick: (e) => e.stopPropagation() },
|
|
331
350
|
h("div", { className: "ima-modal-h" },
|
|
332
351
|
h("h2", null, "配置" + ch.label),
|
|
@@ -348,16 +367,6 @@ window.__ModuleLoader__.load({
|
|
|
348
367
|
remain > 0 && h("p", { className: "ima-hint" }, "二维码 " + Math.floor(remain / 60) + ":" + String(remain % 60).padStart(2, "0") + " 后过期"),
|
|
349
368
|
status === "scanned" && h("p", { className: "ima-hint" }, "已扫码,请在手机上确认"),
|
|
350
369
|
(status === "expired" || status === "failed") && h("p", { className: "ima-error" }, (pairing && pairing.error) || "请重新生成二维码"),
|
|
351
|
-
ch.id === "dingtalk" && h("div", { className: "ima-radio" },
|
|
352
|
-
h("label", null,
|
|
353
|
-
h("input", { type: "radio", name: "am", checked: accessMode === "pair", onChange: () => setAccessMode("pair") }),
|
|
354
|
-
h("span", null, "配对模式", h("small", null, "仅批准过的用户可以驱动本机助手")),
|
|
355
|
-
),
|
|
356
|
-
h("label", null,
|
|
357
|
-
h("input", { type: "radio", name: "am", checked: accessMode === "open", onChange: () => setAccessMode("open") }),
|
|
358
|
-
h("span", null, "开放模式", h("small", null, "该渠道消息默认放行,适合企业内部共用")),
|
|
359
|
-
),
|
|
360
|
-
),
|
|
361
370
|
h("button", { className: "ima-link", disabled: busy, onClick: () => startQr(true) }, "重新生成二维码"),
|
|
362
371
|
)
|
|
363
372
|
),
|
|
@@ -371,16 +380,6 @@ window.__ModuleLoader__.load({
|
|
|
371
380
|
onChange: (e) => setDraft({ ...draft, [f.key]: e.target.value }),
|
|
372
381
|
}),
|
|
373
382
|
)),
|
|
374
|
-
ch.id === "dingtalk" && h("div", { className: "ima-radio" },
|
|
375
|
-
h("label", null,
|
|
376
|
-
h("input", { type: "radio", name: "am2", checked: accessMode === "pair", onChange: () => setAccessMode("pair") }),
|
|
377
|
-
h("span", null, "配对模式", h("small", null, "仅批准过的用户可以驱动本机助手")),
|
|
378
|
-
),
|
|
379
|
-
h("label", null,
|
|
380
|
-
h("input", { type: "radio", name: "am2", checked: accessMode === "open", onChange: () => setAccessMode("open") }),
|
|
381
|
-
h("span", null, "开放模式", h("small", null, "该渠道消息默认放行,适合企业内部共用")),
|
|
382
|
-
),
|
|
383
|
-
),
|
|
384
383
|
h("div", { style: { display: "flex", justifyContent: "flex-end" } },
|
|
385
384
|
h("button", { className: "ima-btn primary", disabled: busy, onClick: saveManual }, busy ? "保存中…" : "确认"),
|
|
386
385
|
),
|
|
@@ -391,14 +390,32 @@ window.__ModuleLoader__.load({
|
|
|
391
390
|
|
|
392
391
|
function ChannelCard({ ch, busy, onAction, onConfigure }) {
|
|
393
392
|
const [menu, setMenu] = useState(false);
|
|
393
|
+
const menuRoot = useRef(null);
|
|
394
|
+
useEffect(() => {
|
|
395
|
+
if (!menu) return undefined;
|
|
396
|
+
const close = (event) => {
|
|
397
|
+
if (menuRoot.current && menuRoot.current.contains(event.target)) return;
|
|
398
|
+
setMenu(false);
|
|
399
|
+
};
|
|
400
|
+
const onKey = (event) => {
|
|
401
|
+
if (event.key === "Escape") setMenu(false);
|
|
402
|
+
};
|
|
403
|
+
document.addEventListener("pointerdown", close, true);
|
|
404
|
+
document.addEventListener("keydown", onKey);
|
|
405
|
+
return () => {
|
|
406
|
+
document.removeEventListener("pointerdown", close, true);
|
|
407
|
+
document.removeEventListener("keydown", onKey);
|
|
408
|
+
};
|
|
409
|
+
}, [menu]);
|
|
410
|
+
|
|
394
411
|
const configuring = !ch.connected;
|
|
395
412
|
const meta = configuring ? "未配置" : (ch.status && ch.status !== "未连接" ? ch.status : "已连接");
|
|
396
|
-
const right = h("div", { className: "ima-actions" },
|
|
413
|
+
const right = h("div", { className: "ima-actions", ref: menuRoot },
|
|
397
414
|
configuring
|
|
398
415
|
? h("button", { className: "ima-btn", disabled: busy, onClick: onConfigure }, busy ? "接入中…" : "配置")
|
|
399
416
|
: [
|
|
400
|
-
h("button", { key: "more", className: "ima-more", "aria-label": ch.label + " 更多", onClick: () => setMenu(!menu) }, "…"),
|
|
401
|
-
menu && h("div", { key: "menu", className: "ima-menu" },
|
|
417
|
+
h("button", { key: "more", className: "ima-more", "aria-label": ch.label + " 更多", "aria-expanded": menu, onClick: (event) => { event.stopPropagation(); setMenu(!menu); } }, "…"),
|
|
418
|
+
menu && h("div", { key: "menu", className: "ima-menu", "data-ima-card-menu": "", onClick: (event) => event.stopPropagation() },
|
|
402
419
|
h("button", { onClick: () => { setMenu(false); onConfigure(); } }, "重新接入"),
|
|
403
420
|
h("button", { onClick: () => { setMenu(false); onAction(ch.id, "disconnect"); } }, "断开"),
|
|
404
421
|
h("button", { onClick: () => { setMenu(false); onAction(ch.id, "remove"); } }, "删除配置"),
|
|
@@ -724,24 +741,22 @@ window.__ModuleLoader__.load({
|
|
|
724
741
|
|
|
725
742
|
function SettingsPage(props) {
|
|
726
743
|
const [channels, setChannels] = useState(null);
|
|
727
|
-
const [pending, setPending] = useState([]);
|
|
728
744
|
const [error, setError] = useState("");
|
|
729
745
|
const [busy, setBusy] = useState({});
|
|
730
746
|
const [editing, setEditing] = useState(null);
|
|
747
|
+
// 请求序号守卫:快速连续操作时丢弃旧 GET 响应,避免旧状态覆盖新状态
|
|
748
|
+
const refreshSeq = useRef(0);
|
|
731
749
|
|
|
732
750
|
const refresh = useCallback(() => {
|
|
751
|
+
const seq = ++refreshSeq.current;
|
|
733
752
|
api("/channels").then((data) => {
|
|
734
|
-
if (
|
|
753
|
+
if (seq !== refreshSeq.current) return;
|
|
754
|
+
if (data.ok) { setChannels(data.channels); setError(""); }
|
|
735
755
|
else setError(data.error || "加载失败");
|
|
736
|
-
}).catch(() => setError("无法连接本机 IM 助理接口"));
|
|
756
|
+
}).catch(() => { if (seq === refreshSeq.current) setError("无法连接本机 IM 助理接口"); });
|
|
737
757
|
}, []);
|
|
738
758
|
|
|
739
759
|
useEffect(() => { ensureStyle(); refresh(); }, [refresh]);
|
|
740
|
-
useEffect(() => {
|
|
741
|
-
if (!(pending || []).length) return;
|
|
742
|
-
const timer = setInterval(refresh, 4000);
|
|
743
|
-
return () => clearInterval(timer);
|
|
744
|
-
}, [pending, refresh]);
|
|
745
760
|
|
|
746
761
|
const onAction = (id, action, body) => {
|
|
747
762
|
setBusy((prev) => ({ ...prev, [id]: true }));
|
|
@@ -767,14 +782,6 @@ window.__ModuleLoader__.load({
|
|
|
767
782
|
),
|
|
768
783
|
h(ComposerBar, { useWorkspaces: props.useWorkspaces, createWorkspace: props.createWorkspace, pickDirectory: props.pickDirectory }),
|
|
769
784
|
error && h("div", { className: "ima-error" }, error),
|
|
770
|
-
pending && pending.length > 0 && h("div", { className: "ima-pending" },
|
|
771
|
-
h("div", null, "有访问请求(仅在关闭全局放行时需要批准)"),
|
|
772
|
-
...pending.map((p) => h("div", { key: p.channelId + p.userId, className: "ima-pending-row" },
|
|
773
|
-
h("span", { style: { flex: 1 } }, (p.username || p.userId) + " · " + p.channelId),
|
|
774
|
-
h("button", { className: "ima-btn", onClick: () => onAction(p.channelId, "approve", { userId: p.userId }) }, "批准"),
|
|
775
|
-
h("button", { className: "ima-btn", onClick: () => onAction(p.channelId, "deny", { userId: p.userId }) }, "拒绝"),
|
|
776
|
-
)),
|
|
777
|
-
),
|
|
778
785
|
channels == null
|
|
779
786
|
? h("div", { className: "ima-empty" }, "加载中…")
|
|
780
787
|
: h("div", { className: "ima-list" },
|
|
@@ -808,7 +815,7 @@ window.__ModuleLoader__.load({
|
|
|
808
815
|
.dcu-wb-session:hover .dcu-wb-actions,.dcu-wb-session.dcu-wb-menu-open .dcu-wb-actions,.ima-native-session:hover .ima-native-actions,.ima-native-session.menu-on .ima-native-actions{display:flex}
|
|
809
816
|
.dcu-wb-more,.ima-native-more{display:grid;place-items:center;width:20px;height:20px;border:0;border-radius:4px;padding:0;background:transparent;color:var(--dsw-alias-label-secondary,var(--ima-muted));cursor:pointer}
|
|
810
817
|
.dcu-wb-empty,.ima-native-empty{padding:14px 8px;color:var(--dsw-alias-label-tertiary,var(--ima-muted));font-size:13px}
|
|
811
|
-
.ima-sess-menu{position:
|
|
818
|
+
.ima-sess-menu{position:fixed;right:auto;top:auto;min-width:132px;padding:6px;border:1px solid var(--dsw-alias-stroke-primary,var(--ima-line));border-radius:10px;background:var(--dsw-specific-menu,var(--dsw-alias-bg-layer-2));z-index:4000}
|
|
812
819
|
.ima-sess-menu button{display:block;width:100%;text-align:left;border:0;background:transparent;color:inherit;padding:7px 10px;border-radius:6px;cursor:pointer;font:13px/18px inherit}
|
|
813
820
|
.ima-sess-menu button:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(255,255,255,.06))}
|
|
814
821
|
.ima-sess-menu button.danger{color:var(--dsw-alias-state-error-primary,var(--ima-danger))}
|
|
@@ -831,7 +838,7 @@ window.__ModuleLoader__.load({
|
|
|
831
838
|
.ima-n-sess:hover .ima-n-time,.ima-n-sess.menu-on .ima-n-time{display:none}
|
|
832
839
|
.ima-n-ico{display:inline-flex;align-items:center;justify-content:center;width:16px;height:16px;border:0;border-radius:4px;padding:0;background:transparent;cursor:pointer;color:var(--dsw-alias-label-tertiary,#81858C)}
|
|
833
840
|
.ima-n-ico:hover{color:var(--dsw-alias-label-primary,var(--ima-text))}
|
|
834
|
-
.ima-n-menu{position:
|
|
841
|
+
.ima-n-menu{position:fixed;right:auto;top:auto;z-index:4000;min-width:218px;max-width:360px;box-sizing:border-box;padding:4px;display:flex;flex-direction:column;border:1px solid var(--dsw-alias-border-inverted,rgba(255,255,255,.12));border-radius:12px;background:var(--dsw-specific-menu,var(--dsw-alias-bg-layer-2));box-shadow:var(--dsw-shadow-lv3,0 8px 24px rgba(0,0,0,.36))}
|
|
835
842
|
.ima-n-menu button{display:flex;align-items:center;gap:8px;width:100%;min-height:40px;padding:8px 10px;border:0;border-radius:10px;background:transparent;cursor:pointer;font-size:14px;line-height:22px;color:var(--dsw-alias-label-primary,var(--ima-text));text-align:left}
|
|
836
843
|
.ima-n-menu button:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(255,255,255,.06))}
|
|
837
844
|
.ima-n-mi{display:inline-flex;flex:none;width:16px;height:16px;align-items:center;justify-content:center;color:var(--dsw-alias-label-tertiary,#81858C)}
|
|
@@ -900,8 +907,50 @@ window.__ModuleLoader__.load({
|
|
|
900
907
|
}
|
|
901
908
|
|
|
902
909
|
|
|
903
|
-
function
|
|
904
|
-
const
|
|
910
|
+
function pointerPoint(event) {
|
|
911
|
+
const x = Number(event && event.clientX);
|
|
912
|
+
const y = Number(event && event.clientY);
|
|
913
|
+
return {
|
|
914
|
+
x: Number.isFinite(x) ? x : 8,
|
|
915
|
+
y: Number.isFinite(y) ? y : 8,
|
|
916
|
+
};
|
|
917
|
+
}
|
|
918
|
+
function clampMenuPoint(x, y, width, height) {
|
|
919
|
+
const pad = 8;
|
|
920
|
+
const vw = window.innerWidth || width + pad * 2;
|
|
921
|
+
const vh = window.innerHeight || height + pad * 2;
|
|
922
|
+
return {
|
|
923
|
+
x: Math.max(pad, Math.min(x, Math.max(pad, vw - width - pad))),
|
|
924
|
+
y: Math.max(pad, Math.min(y, Math.max(pad, vh - height - pad))),
|
|
925
|
+
};
|
|
926
|
+
}
|
|
927
|
+
function SessionPointerMenu({ native, x, y, items, onPick }) {
|
|
928
|
+
const ref = useRef(null);
|
|
929
|
+
const [pos, setPos] = useState(() => clampMenuPoint(x, y, native ? 218 : 132, native ? 176 : 140));
|
|
930
|
+
useLayoutEffect(() => {
|
|
931
|
+
const el = ref.current;
|
|
932
|
+
if (!el) return;
|
|
933
|
+
const rect = el.getBoundingClientRect();
|
|
934
|
+
setPos(clampMenuPoint(x, y, rect.width, rect.height));
|
|
935
|
+
}, [x, y]);
|
|
936
|
+
const node = h("div", {
|
|
937
|
+
ref,
|
|
938
|
+
className: native ? "ima-n-menu" : "ima-sess-menu",
|
|
939
|
+
"data-ima-session-menu": "",
|
|
940
|
+
style: { left: pos.x + "px", top: pos.y + "px" },
|
|
941
|
+
onClick: (event) => event.stopPropagation(),
|
|
942
|
+
}, items.map((item) => h("button", {
|
|
943
|
+
key: item.id,
|
|
944
|
+
type: "button",
|
|
945
|
+
className: item.danger ? "danger" : undefined,
|
|
946
|
+
onClick: () => onPick(item),
|
|
947
|
+
}, native && h("span", { className: "ima-n-mi" }, item.icon), item.label)));
|
|
948
|
+
return ReactDOM.createPortal(node, document.body);
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
function ChannelSessionRow({ sess, selected, onOpen, onChanged, skin, sessionActions, sessionById, menuOpen, onMenuChange }) {
|
|
952
|
+
const menu = !!menuOpen;
|
|
953
|
+
const setMenu = (next) => onMenuChange(!!next);
|
|
905
954
|
const [renaming, setRenaming] = useState(false);
|
|
906
955
|
const [draft, setDraft] = useState(sess.title || sess.chatId || "");
|
|
907
956
|
const title = sess.title || sess.chatId;
|
|
@@ -979,9 +1028,9 @@ window.__ModuleLoader__.load({
|
|
|
979
1028
|
role: "treeitem",
|
|
980
1029
|
tabIndex: 0,
|
|
981
1030
|
"aria-selected": selected,
|
|
982
|
-
onClick: () => onOpen(sess.sessionId),
|
|
983
|
-
onKeyDown: (e) => { if (e.key === "Enter" || e.key === " ") { e.preventDefault(); onOpen(sess.sessionId); } },
|
|
984
|
-
onContextMenu: (e) => { e.preventDefault(); e.stopPropagation();
|
|
1031
|
+
onClick: () => { setMenu(false); onOpen(sess.sessionId); },
|
|
1032
|
+
onKeyDown: (e) => { if (e.key === "Enter" || e.key === " ") { e.preventDefault(); setMenu(false); onOpen(sess.sessionId); } },
|
|
1033
|
+
onContextMenu: (e) => { e.preventDefault(); e.stopPropagation(); onMenuChange(true, e); },
|
|
985
1034
|
},
|
|
986
1035
|
native && h("span", { className: "ima-n-slot" }, (sess.running || (sessionById && sessionById[sess.sessionId] && sessionById[sess.sessionId].running)) ? h(RunningStateDot) : null),
|
|
987
1036
|
h("span", { className: native ? "ima-n-title" : "dcu-wb-session-title" }, title),
|
|
@@ -990,18 +1039,19 @@ window.__ModuleLoader__.load({
|
|
|
990
1039
|
h("button", {
|
|
991
1040
|
type: "button",
|
|
992
1041
|
className: native ? "ima-n-ico" : "dcu-wb-more",
|
|
1042
|
+
"data-ima-session-more": "",
|
|
1043
|
+
"aria-expanded": menu,
|
|
993
1044
|
"aria-label": title + " 更多",
|
|
994
|
-
onClick: (e) => { e.stopPropagation();
|
|
1045
|
+
onClick: (e) => { e.stopPropagation(); onMenuChange(!menu, e); },
|
|
995
1046
|
}, native ? h(IconEllipsis) : h(MoreIcon)),
|
|
996
1047
|
),
|
|
997
|
-
menu && h(
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
),
|
|
1048
|
+
menu && h(SessionPointerMenu, {
|
|
1049
|
+
native,
|
|
1050
|
+
x: menuOpen && menuOpen.x,
|
|
1051
|
+
y: menuOpen && menuOpen.y,
|
|
1052
|
+
items: menuItems,
|
|
1053
|
+
onPick: (item) => { setMenu(false); item.go(); },
|
|
1054
|
+
}),
|
|
1005
1055
|
);
|
|
1006
1056
|
}
|
|
1007
1057
|
|
|
@@ -1031,6 +1081,7 @@ window.__ModuleLoader__.load({
|
|
|
1031
1081
|
const [groups, setGroups] = useState([]);
|
|
1032
1082
|
const [folded, setFolded] = useState({});
|
|
1033
1083
|
const [error, setError] = useState("");
|
|
1084
|
+
const [openMenu, setOpenMenu] = useState(null);
|
|
1034
1085
|
const selectedId = props.selectedId;
|
|
1035
1086
|
const archived = new Set(props.archivedIds || []);
|
|
1036
1087
|
const skin = props.skin || channelSkin;
|
|
@@ -1046,6 +1097,23 @@ window.__ModuleLoader__.load({
|
|
|
1046
1097
|
const timer = setInterval(load, 4000);
|
|
1047
1098
|
return () => clearInterval(timer);
|
|
1048
1099
|
}, []);
|
|
1100
|
+
useEffect(() => {
|
|
1101
|
+
if (!openMenu) return undefined;
|
|
1102
|
+
const onPointerDown = (event) => {
|
|
1103
|
+
const target = event.target;
|
|
1104
|
+
if (target && target.closest && target.closest("[data-ima-session-menu],[data-ima-session-more]")) return;
|
|
1105
|
+
setOpenMenu(null);
|
|
1106
|
+
};
|
|
1107
|
+
const onKeyDown = (event) => {
|
|
1108
|
+
if (event.key === "Escape") setOpenMenu(null);
|
|
1109
|
+
};
|
|
1110
|
+
document.addEventListener("pointerdown", onPointerDown, true);
|
|
1111
|
+
document.addEventListener("keydown", onKeyDown);
|
|
1112
|
+
return () => {
|
|
1113
|
+
document.removeEventListener("pointerdown", onPointerDown, true);
|
|
1114
|
+
document.removeEventListener("keydown", onKeyDown);
|
|
1115
|
+
};
|
|
1116
|
+
}, [openMenu]);
|
|
1049
1117
|
return h("div", { className: native ? "ima-native ima-rail" : "dcu-wb ima-rail" },
|
|
1050
1118
|
h("style", null, WB_CSS),
|
|
1051
1119
|
h("div", { className: native ? "ima-native-tree" : "dcu-wb-tree", role: "tree" },
|
|
@@ -1065,7 +1133,7 @@ window.__ModuleLoader__.load({
|
|
|
1065
1133
|
},
|
|
1066
1134
|
native
|
|
1067
1135
|
? [
|
|
1068
|
-
h("span", { key: "folder", className: "ima-n-slot ima-n-folder" },
|
|
1136
|
+
h("span", { key: "folder", className: "ima-n-slot ima-n-folder" }, h(Logo, { id: g.id, small: true })),
|
|
1069
1137
|
h("span", { key: "chev", className: "ima-n-slot ima-n-chevron" }, h("span", { className: expanded ? "ima-n-arrow open" : "ima-n-arrow" }, h(IconChevron))),
|
|
1070
1138
|
h("span", { key: "title", className: "ima-n-title" }, g.label),
|
|
1071
1139
|
]
|
|
@@ -1080,6 +1148,12 @@ window.__ModuleLoader__.load({
|
|
|
1080
1148
|
sess,
|
|
1081
1149
|
selected: selectedId === sess.sessionId,
|
|
1082
1150
|
sessionById: props.sessionById,
|
|
1151
|
+
menuOpen: openMenu && openMenu.id === sess.sessionId ? openMenu : null,
|
|
1152
|
+
onMenuChange: (open, event) => setOpenMenu((cur) => {
|
|
1153
|
+
if (!open) return cur && cur.id === sess.sessionId ? null : cur;
|
|
1154
|
+
const point = pointerPoint(event);
|
|
1155
|
+
return { id: sess.sessionId, x: point.x, y: point.y };
|
|
1156
|
+
}),
|
|
1083
1157
|
onOpen: open,
|
|
1084
1158
|
onChanged: (next) => setGroups(next),
|
|
1085
1159
|
skin,
|
|
@@ -1462,18 +1536,20 @@ window.__ModuleLoader__.load({
|
|
|
1462
1536
|
exports.inject = inject;
|
|
1463
1537
|
return module.exports;
|
|
1464
1538
|
},
|
|
1465
|
-
});
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1539
|
+
});
|
|
1540
|
+
|
|
1541
|
+
|
|
1542
|
+
|
|
1543
|
+
|
|
1544
|
+
|
|
1545
|
+
|
|
1546
|
+
|
|
1547
|
+
|
|
1548
|
+
|
|
1549
|
+
|
|
1550
|
+
|
|
1551
|
+
|
|
1552
|
+
|
|
1553
|
+
|
|
1554
|
+
|
|
1555
|
+
|
package/lib/engine/gateway.d.ts
CHANGED
|
@@ -1,25 +1,21 @@
|
|
|
1
1
|
import type { Context } from '@deepseek-ai/cordis';
|
|
2
2
|
import { SeenStore } from './seen-store.js';
|
|
3
3
|
import { SessionMapStore } from './session-store.js';
|
|
4
|
-
import type { ChannelAdapter, EngineConfig
|
|
4
|
+
import type { ChannelAdapter, EngineConfig } from './types.js';
|
|
5
5
|
export declare class ImEngine {
|
|
6
6
|
private readonly ctx;
|
|
7
7
|
private readonly store;
|
|
8
8
|
private readonly seen;
|
|
9
9
|
private readonly config;
|
|
10
10
|
private readonly log;
|
|
11
|
-
private readonly onUnauthorized?;
|
|
12
11
|
private readonly channels;
|
|
13
12
|
private readonly router;
|
|
14
13
|
private readonly broker;
|
|
15
14
|
private readonly merger;
|
|
16
|
-
private readonly extraAllow;
|
|
17
|
-
private readonly extraGroups;
|
|
18
|
-
private readonly openChannels;
|
|
19
15
|
private readonly queues;
|
|
20
16
|
private readonly streams;
|
|
21
17
|
private readonly disposeEvents;
|
|
22
|
-
constructor(ctx: Context, store: SessionMapStore, seen: SeenStore, config: EngineConfig, log: (line: string) => void
|
|
18
|
+
constructor(ctx: Context, store: SessionMapStore, seen: SeenStore, config: EngineConfig, log: (line: string) => void);
|
|
23
19
|
renameSession(sessionId: string, title: string): boolean;
|
|
24
20
|
removeSession(sessionId: string): Promise<boolean>;
|
|
25
21
|
ensureSession(sessionId: string): Promise<boolean>;
|
|
@@ -29,18 +25,15 @@ export declare class ImEngine {
|
|
|
29
25
|
attachMappedSessions(): Promise<void>;
|
|
30
26
|
register(channel: ChannelAdapter): void;
|
|
31
27
|
unregister(channelId: string): void;
|
|
32
|
-
addAllowed(channelId: string, userId: string): void;
|
|
33
28
|
dispose(): void;
|
|
34
29
|
private enqueue;
|
|
35
30
|
private handleInbound;
|
|
36
31
|
private handleCommand;
|
|
37
32
|
private inject;
|
|
38
|
-
setAccessMode(channelId: string, mode: 'pair' | 'open'): void;
|
|
39
|
-
private userAllowed;
|
|
40
|
-
private groupAllowed;
|
|
41
33
|
private answerApproval;
|
|
42
34
|
private onApproval;
|
|
43
35
|
private onSessionEvent;
|
|
36
|
+
/** 逐片发送;返回是否至少送达过一片,供调用方决定是否标记已投递。 */
|
|
44
37
|
private deliver;
|
|
45
38
|
}
|
|
46
39
|
//# sourceMappingURL=gateway.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gateway.d.ts","sourceRoot":"","sources":["../../src/engine/gateway.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAIlD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAIpD,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"gateway.d.ts","sourceRoot":"","sources":["../../src/engine/gateway.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAIlD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAIpD,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAa,MAAM,YAAY,CAAA;AAYzE,qBAAa,QAAQ;IAUjB,OAAO,CAAC,QAAQ,CAAC,GAAG;IACpB,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,GAAG;IAbtB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAoC;IAC7D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAe;IACtC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAuB;IAC9C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAe;IACtC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAmC;IAC1D,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAuB;IAC/C,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAwB;gBAGnC,GAAG,EAAE,OAAO,EACZ,KAAK,EAAE,eAAe,EACtB,IAAI,EAAE,SAAS,EACf,MAAM,EAAE,YAAY,EACpB,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI;IA8B9C,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO;IAIlD,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAIlD,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAIxD,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI;IAOzE,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAKzB,aAAa,CAAC,UAAU,EAAE,WAAW,GAAG,iBAAiB,GAAG,aAAa,GAAG,IAAI;IAKhF,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC;IAIrC,QAAQ,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI;IAKvC,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAInC,OAAO,IAAI,IAAI;IAOf,OAAO,CAAC,OAAO;YAUD,aAAa;YAuCb,aAAa;YAoBb,MAAM;YAsBN,cAAc;YAQd,UAAU;YAaV,cAAc;IAyE5B,sCAAsC;YACxB,OAAO;CAatB"}
|