@lih-x-x/kmr 1.0.43 → 1.0.44
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/cli.js +3 -3
- package/dist/index.js +57 -27
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -6,9 +6,9 @@ async function checkUpdate() {
|
|
|
6
6
|
try {
|
|
7
7
|
const res = await fetch(`https://registry.npmjs.org/${"@lih-x-x/kmr"}/latest`, { signal: AbortSignal.timeout(3e3) });
|
|
8
8
|
const data = await res.json();
|
|
9
|
-
if (data.version && data.version !== "1.0.
|
|
9
|
+
if (data.version && data.version !== "1.0.44") {
|
|
10
10
|
console.log(`
|
|
11
|
-
\u2B06\uFE0F \u65B0\u7248\u672C\u53EF\u7528: ${"1.0.
|
|
11
|
+
\u2B06\uFE0F \u65B0\u7248\u672C\u53EF\u7528: ${"1.0.44"} \u2192 ${data.version}`);
|
|
12
12
|
console.log(` \u8FD0\u884C npm install -g ${"@lih-x-x/kmr"} \u66F4\u65B0
|
|
13
13
|
`);
|
|
14
14
|
}
|
|
@@ -56,7 +56,7 @@ KMR\uFF08Key Meetings Record\uFF09\u2014 \u4F1A\u8BAE\u6316\u6398\u673A
|
|
|
56
56
|
kmr --help \u663E\u793A\u5E2E\u52A9
|
|
57
57
|
`);
|
|
58
58
|
} else if (command === "--version" || command === "-v") {
|
|
59
|
-
console.log("1.0.
|
|
59
|
+
console.log("1.0.44");
|
|
60
60
|
} else if (command === "list") {
|
|
61
61
|
const { loadConfig } = await import("./config-L2SVVMAR.js");
|
|
62
62
|
const { JsonStore } = await import("./jsonStore-AL73KEUG.js");
|
package/dist/index.js
CHANGED
|
@@ -640,26 +640,42 @@ var SessionManager = class {
|
|
|
640
640
|
const sessionName = `kmr-${userId}`;
|
|
641
641
|
const userDir = path2.join(this.sessionDir, userId);
|
|
642
642
|
fs2.mkdirSync(userDir, { recursive: true });
|
|
643
|
-
console.log(`[session] \u521B\u5EFA\u65B0 session: ${sessionName}`);
|
|
644
643
|
const agentCmd = this.getAgentCmd();
|
|
644
|
+
let sessionExists = false;
|
|
645
645
|
try {
|
|
646
|
-
await execFileAsync("acpx", [agentCmd, "sessions", "
|
|
647
|
-
timeout:
|
|
646
|
+
const { stdout } = await execFileAsync("acpx", [agentCmd, "sessions", "list"], {
|
|
647
|
+
timeout: 1e4,
|
|
648
648
|
maxBuffer: 1024 * 1024,
|
|
649
649
|
env: getExecEnv()
|
|
650
650
|
});
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
throw new Error(`\u521B\u5EFA\u4F1A\u8BDD\u5931\u8D25: ${err.message}`);
|
|
654
|
-
}
|
|
655
|
-
try {
|
|
656
|
-
await execFileAsync(
|
|
657
|
-
"acpx",
|
|
658
|
-
["--approve-all", agentCmd, "-s", sessionName, SESSION_SKILL],
|
|
659
|
-
{ timeout: this.timeout, maxBuffer: 1024 * 1024, env: getExecEnv() }
|
|
651
|
+
sessionExists = stdout.split("\n").some(
|
|
652
|
+
(line) => !line.includes("[closed]") && line.split(" ")[1]?.trim() === sessionName
|
|
660
653
|
);
|
|
661
|
-
} catch
|
|
662
|
-
|
|
654
|
+
} catch {
|
|
655
|
+
}
|
|
656
|
+
if (sessionExists) {
|
|
657
|
+
console.log(`[session] \u590D\u7528\u5DF2\u6709 acpx session: ${sessionName}`);
|
|
658
|
+
} else {
|
|
659
|
+
console.log(`[session] \u521B\u5EFA\u65B0 session: ${sessionName}`);
|
|
660
|
+
try {
|
|
661
|
+
await execFileAsync("acpx", [agentCmd, "sessions", "ensure", "--name", sessionName], {
|
|
662
|
+
timeout: this.timeout,
|
|
663
|
+
maxBuffer: 1024 * 1024,
|
|
664
|
+
env: getExecEnv()
|
|
665
|
+
});
|
|
666
|
+
} catch (err) {
|
|
667
|
+
console.error(`[session] \u521B\u5EFA session \u5931\u8D25:`, err.message);
|
|
668
|
+
throw new Error(`\u521B\u5EFA\u4F1A\u8BDD\u5931\u8D25: ${err.message}`);
|
|
669
|
+
}
|
|
670
|
+
try {
|
|
671
|
+
await execFileAsync(
|
|
672
|
+
"acpx",
|
|
673
|
+
["--approve-all", agentCmd, "-s", sessionName, SESSION_SKILL],
|
|
674
|
+
{ timeout: this.timeout, maxBuffer: 1024 * 1024, env: getExecEnv() }
|
|
675
|
+
);
|
|
676
|
+
} catch (err) {
|
|
677
|
+
console.error(`[session] \u89D2\u8272\u8BBE\u5B9A\u5931\u8D25:`, err.message);
|
|
678
|
+
}
|
|
663
679
|
}
|
|
664
680
|
this.activeSessions.set(userId, {
|
|
665
681
|
name: sessionName,
|
|
@@ -737,6 +753,16 @@ var SessionManager = class {
|
|
|
737
753
|
}
|
|
738
754
|
this.activeSessions.delete(userId);
|
|
739
755
|
}
|
|
756
|
+
/**
|
|
757
|
+
* 关闭所有活跃 session,服务退出时调用
|
|
758
|
+
*/
|
|
759
|
+
async closeAll() {
|
|
760
|
+
const userIds = [...this.activeSessions.keys()];
|
|
761
|
+
if (userIds.length === 0) return;
|
|
762
|
+
console.log(`[session] \u6B63\u5728\u5173\u95ED ${userIds.length} \u4E2A\u6D3B\u8DC3 session...`);
|
|
763
|
+
await Promise.all(userIds.map((uid) => this.closeSession(uid)));
|
|
764
|
+
console.log(`[session] \u6240\u6709 session \u5DF2\u5173\u95ED`);
|
|
765
|
+
}
|
|
740
766
|
};
|
|
741
767
|
|
|
742
768
|
// src/index.ts
|
|
@@ -1043,22 +1069,26 @@ async function main() {
|
|
|
1043
1069
|
}
|
|
1044
1070
|
}, 6e4);
|
|
1045
1071
|
}
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1072
|
+
let exiting = false;
|
|
1073
|
+
const onExit = async (signal) => {
|
|
1074
|
+
if (exiting) return;
|
|
1075
|
+
exiting = true;
|
|
1076
|
+
console.log(`[exit] \u6536\u5230 ${signal}\uFF0C\u6B63\u5728\u9000\u51FA...`);
|
|
1077
|
+
try {
|
|
1078
|
+
await sessionManager.closeAll();
|
|
1079
|
+
} catch (err) {
|
|
1080
|
+
console.error("[exit] \u5173\u95ED session \u5931\u8D25:", err.message);
|
|
1081
|
+
}
|
|
1082
|
+
if (config.lark.adminOpenId) {
|
|
1053
1083
|
try {
|
|
1054
|
-
await messenger.sendToUser(
|
|
1084
|
+
await messenger.sendToUser(config.lark.adminOpenId, `\u26D4 KMR \u670D\u52A1\u5DF2\u505C\u6B62\uFF08${signal}\uFF09`);
|
|
1055
1085
|
} catch (err) {
|
|
1056
1086
|
console.error("[notify] \u63A8\u9001\u505C\u6B62\u901A\u77E5\u5931\u8D25:", err.message);
|
|
1057
1087
|
}
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1088
|
+
}
|
|
1089
|
+
process.exit(0);
|
|
1090
|
+
};
|
|
1091
|
+
process.on("SIGINT", () => onExit("SIGINT"));
|
|
1092
|
+
process.on("SIGTERM", () => onExit("SIGTERM"));
|
|
1063
1093
|
}
|
|
1064
1094
|
main().catch(console.error);
|