dsh-cyber-im-avatar 0.18.2 → 0.18.3
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/lib/index.js +52 -18
- package/package.json +2 -1
package/lib/index.js
CHANGED
|
@@ -15,17 +15,6 @@ import { randomBytes } from "node:crypto";
|
|
|
15
15
|
import { dirname } from "node:path";
|
|
16
16
|
import { fileURLToPath } from "node:url";
|
|
17
17
|
|
|
18
|
-
import { State } from "./state.js";
|
|
19
|
-
import { Profiles } from "./profiles.js";
|
|
20
|
-
import { IM } from "./im.js";
|
|
21
|
-
import { MediaStore } from "./media.js";
|
|
22
|
-
import { Poller } from "./poller.js";
|
|
23
|
-
import { Turns } from "./turns.js";
|
|
24
|
-
import { TurnLog } from "./turn-log.js";
|
|
25
|
-
import { App } from "./app.js";
|
|
26
|
-
import { ensureDutyDir } from "./duty.js";
|
|
27
|
-
import { ensureSkill } from "./skill-install.js";
|
|
28
|
-
|
|
29
18
|
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
30
19
|
const PREFIX = "/plugins/im-standin";
|
|
31
20
|
const TOKEN = randomBytes(24).toString("hex");
|
|
@@ -49,6 +38,7 @@ let attachments = null;
|
|
|
49
38
|
let llm = null;
|
|
50
39
|
let permissionPresets = null;
|
|
51
40
|
let mediaTimer = null;
|
|
41
|
+
let bootPromise = null;
|
|
52
42
|
|
|
53
43
|
function cleanupMedia() {
|
|
54
44
|
if (!media || !state) return;
|
|
@@ -64,8 +54,47 @@ function cleanupMedia() {
|
|
|
64
54
|
}
|
|
65
55
|
|
|
66
56
|
// ---- 进程内装配 -----------------------------------------------------------
|
|
57
|
+
/**
|
|
58
|
+
* 装配宿主半,返回可等待的 memo(见 spec 0042)。
|
|
59
|
+
*
|
|
60
|
+
* 入口模块只静态依赖 Node 内置,重模块在 `bootOnce()` 里动态 import:DSH 的
|
|
61
|
+
* web boot 只等入口模块导入完就建 fiber、发布客户端那一行,静态依赖越薄,
|
|
62
|
+
* 这一行越早进 boot 快照,服务重启时越不容易被启动审计当成「导入失败」。
|
|
63
|
+
*/
|
|
67
64
|
function boot() {
|
|
65
|
+
bootPromise ??= bootOnce().catch((e) => {
|
|
66
|
+
bootPromise = null;
|
|
67
|
+
console.warn(LOG, "boot failed:", (e && e.stack) || e);
|
|
68
|
+
throw e;
|
|
69
|
+
});
|
|
70
|
+
return bootPromise;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async function bootOnce() {
|
|
68
74
|
if (app) return app;
|
|
75
|
+
const [
|
|
76
|
+
{ State },
|
|
77
|
+
{ Profiles },
|
|
78
|
+
{ IM },
|
|
79
|
+
{ MediaStore },
|
|
80
|
+
{ Poller },
|
|
81
|
+
{ Turns },
|
|
82
|
+
{ TurnLog },
|
|
83
|
+
{ App },
|
|
84
|
+
{ ensureDutyDir },
|
|
85
|
+
] = await Promise.all([
|
|
86
|
+
import("./state.js"),
|
|
87
|
+
import("./profiles.js"),
|
|
88
|
+
import("./im.js"),
|
|
89
|
+
import("./media.js"),
|
|
90
|
+
import("./poller.js"),
|
|
91
|
+
import("./turns.js"),
|
|
92
|
+
import("./turn-log.js"),
|
|
93
|
+
import("./app.js"),
|
|
94
|
+
import("./duty.js"),
|
|
95
|
+
]);
|
|
96
|
+
// 加载期间插件可能已被 dispose:此时不要再起轮询。
|
|
97
|
+
if (!alive) return null;
|
|
69
98
|
state = new State();
|
|
70
99
|
state.load();
|
|
71
100
|
// 插件安装/首次启动就初始化私有值守台目录与初始 policy.md;本地缺文件也在这里补。
|
|
@@ -115,6 +144,7 @@ function shutdown() {
|
|
|
115
144
|
state = null;
|
|
116
145
|
app = null;
|
|
117
146
|
turnLog = null;
|
|
147
|
+
bootPromise = null;
|
|
118
148
|
registry = null;
|
|
119
149
|
sessionController = null;
|
|
120
150
|
sessions = null;
|
|
@@ -211,7 +241,8 @@ async function handler(req, res) {
|
|
|
211
241
|
}
|
|
212
242
|
}
|
|
213
243
|
|
|
214
|
-
const inst = boot();
|
|
244
|
+
const inst = await boot();
|
|
245
|
+
if (!inst) return send(res, 503, { error: "plugin is shutting down" });
|
|
215
246
|
const out = await inst.handle(path, method, url.searchParams, body);
|
|
216
247
|
return send(res, out.status, out.body);
|
|
217
248
|
}
|
|
@@ -287,7 +318,7 @@ function mount(ctx) {
|
|
|
287
318
|
path: PREFIX,
|
|
288
319
|
handler,
|
|
289
320
|
}));
|
|
290
|
-
boot();
|
|
321
|
+
boot().catch(() => { /* boot() 已打日志,请求到来时会重试 */ });
|
|
291
322
|
} catch (e) {
|
|
292
323
|
console.warn(LOG, "route registration failed:", e && e.message);
|
|
293
324
|
}
|
|
@@ -301,11 +332,14 @@ export function apply(ctx) {
|
|
|
301
332
|
rootCtx = ctx;
|
|
302
333
|
// 插件驱动的会话靠 `/cyber-im-avatar` 自动注入 skill;首次启动时把 skill 装到
|
|
303
334
|
// DSH 扫描的 ~/.agents/skills/。已有手装副本不覆盖(见 skill-install.js)。
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
335
|
+
// 动态 import:这一步不该拖慢入口模块,fiber 与客户端那一行都要尽早出现。
|
|
336
|
+
import("./skill-install.js").then(({ ensureSkill }) => {
|
|
337
|
+
try {
|
|
338
|
+
ensureSkill(console);
|
|
339
|
+
} catch (e) {
|
|
340
|
+
console.warn(LOG, "skill install skipped:", e && e.message);
|
|
341
|
+
}
|
|
342
|
+
}).catch((e) => console.warn(LOG, "skill install unavailable:", e && e.message));
|
|
309
343
|
try {
|
|
310
344
|
mount(ctx);
|
|
311
345
|
} catch (e) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-cyber-im-avatar",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.3",
|
|
4
4
|
"description": "IM 分身壳:在 DSH 侧边栏值守飞书/企业微信/钉钉,命中新消息唤醒绑定 DSH 会话,由 agent 按 skill 闭环自己调 CLI、调研、回复;面板只做消息展示、通知与手动发送。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
},
|
|
33
33
|
"client": {
|
|
34
34
|
"platform": "web",
|
|
35
|
+
"immediately": true,
|
|
35
36
|
"inject": [
|
|
36
37
|
"@deepseek-ai/dsh-client-ui-sidebar",
|
|
37
38
|
"@deepseek-ai/dsh-client-ui-sidebar-right"
|