mslxdff 0.1.94 → 0.1.95
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/package.json
CHANGED
package/src/chat/repl.js
CHANGED
|
@@ -5,6 +5,7 @@ import { loadHistory, saveHistory, histPath } from "./store.js";
|
|
|
5
5
|
import { CHAT_PREFERRED } from "./config.js";
|
|
6
6
|
import { createEngine } from "./engine.js";
|
|
7
7
|
import { printBanner, printFooter, handleSlash, createReadline, createSpinner, estimateChars } from "./terminal.js";
|
|
8
|
+
import { assertChatNode } from "../readline-compat.js";
|
|
8
9
|
|
|
9
10
|
function trace(line) {
|
|
10
11
|
if (process.env.MSLXDFF_CHAT_TRACE === "0") return;
|
|
@@ -12,6 +13,7 @@ function trace(line) {
|
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
export async function startRepl({ singleShot } = {}) {
|
|
16
|
+
if (!assertChatNode()) process.exit(1);
|
|
15
17
|
const models = getModelsForPrompt();
|
|
16
18
|
const system = buildSystemPrompt({ modelsOverride: models });
|
|
17
19
|
let messages = [{ role: "system", content: system }];
|
package/src/chat/terminal.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { createInterface } from "../readline-compat.js";
|
|
2
2
|
import { stdin, stdout } from "node:process";
|
|
3
3
|
import { formatBannerLines, formatStatsDetail, collectStats, probeGateway } from "./stats.js";
|
|
4
4
|
import { createSpinner } from "./spinner.js";
|
|
@@ -89,7 +89,7 @@ export function handleSlash(line, ctx) {
|
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
export function createReadline(promptStr) {
|
|
92
|
-
return
|
|
92
|
+
return createInterface({ input: stdin, output: stdout, prompt: promptStr });
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
export { createSpinner, loadHistory, saveHistory, histPath, estimateChars };
|
|
@@ -109,8 +109,8 @@ export async function handleProviderKeys(id, sub, rest, args) {
|
|
|
109
109
|
}
|
|
110
110
|
if (process.stdin.isTTY && process.stdout.isTTY) {
|
|
111
111
|
const { loadProviderKeys, addProviderKey } = await import("../../../state.js");
|
|
112
|
-
const
|
|
113
|
-
const rl =
|
|
112
|
+
const { createInterface } = await import("../../../readline-compat.js");
|
|
113
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout, terminal: true });
|
|
114
114
|
console.log(`Enter ${id} API keys, one per line (input hidden). Blank line to finish:`);
|
|
115
115
|
const existing = loadProviderKeys(id);
|
|
116
116
|
const collected = [];
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// readline 兼容层:`node:readline/promises` 需要 Node 17+,老 Node(如 VPS 的 16)
|
|
2
|
+
// 会 `ERR_UNKNOWN_BUILTIN_MODULE` 直接崩在 import 期,连人话报错都来不及打。
|
|
3
|
+
// 这里只用回调版 `node:readline`(Node 12+ 全有),把 `question` 包成 Promise;
|
|
4
|
+
// `prompt()/close()/for await` 回调版原生即有,对我们用到的部分行为一致。
|
|
5
|
+
import readline from "node:readline";
|
|
6
|
+
|
|
7
|
+
export function createInterface(opts) {
|
|
8
|
+
const rl = readline.createInterface(opts);
|
|
9
|
+
const ask = rl.question.bind(rl);
|
|
10
|
+
rl.question = (query) => new Promise((resolve) => ask(query, (ans) => resolve(ans)));
|
|
11
|
+
return rl;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function nodeMajor() {
|
|
15
|
+
return Number(String(process.versions?.node || "0").split(".")[0]) || 0;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// -chat 全链路依赖 global fetch(Node 18+),老 Node 放行只会崩得更难看,
|
|
19
|
+
// 不如在入口给一句人话。返回 true=通过,false=已打印升级指引。
|
|
20
|
+
export function assertChatNode({ min = 18 } = {}) {
|
|
21
|
+
const major = nodeMajor();
|
|
22
|
+
if (major >= min) return true;
|
|
23
|
+
console.error(`Node 版本过旧(当前 v${process.versions.node}),-chat 需要 Node ${min}+(推荐 20+,见 package.json engines)。`);
|
|
24
|
+
console.error("先升级 Node 再重试:nvm install 20 && nvm use 20,或到 https://nodejs.org/ 下 LTS。");
|
|
25
|
+
return false;
|
|
26
|
+
}
|