ellm-proxy 0.0.10 → 0.0.12
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 +48 -14
- package/dist/server.js +46 -12
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -35167,11 +35167,13 @@ import { existsSync as existsSync2, mkdirSync as mkdirSync3, readFileSync as rea
|
|
|
35167
35167
|
import { spawn as spawn3 } from "node:child_process";
|
|
35168
35168
|
import { homedir as homedir2, platform as platform8 } from "node:os";
|
|
35169
35169
|
import { join as join6 } from "node:path";
|
|
35170
|
+
var AUTOSTART_VBS = "ellm-proxy-autostart.vbs";
|
|
35170
35171
|
var AUTOSTART_CMD = "ellm-proxy-autostart.cmd";
|
|
35171
35172
|
var PLIST_LABEL = "com.ellm-proxy.autostart";
|
|
35172
35173
|
var LINUX_UNIT = "ellm-proxy.service";
|
|
35173
35174
|
var OPT_OUT_FILE = "autostart.opt-out";
|
|
35174
|
-
var MARKER = "ellm-proxy-
|
|
35175
|
+
var MARKER = "ellm-proxy-v3";
|
|
35176
|
+
var V2_MARKER = "ellm-proxy-v2";
|
|
35175
35177
|
var ENV_WHITELIST_PREFIX = "ELLM_";
|
|
35176
35178
|
var ENV_WHITELIST_KEYS = /* @__PURE__ */ new Set(["WEBUI_USERNAME", "WEBUI_PASSWORD"]);
|
|
35177
35179
|
function collectAutostartEnv(env10 = process.env) {
|
|
@@ -35200,7 +35202,7 @@ function runExit(cmd, args) {
|
|
|
35200
35202
|
function platformItemPath() {
|
|
35201
35203
|
switch (platform8()) {
|
|
35202
35204
|
case "win32":
|
|
35203
|
-
return join6(windowsStartupDir(),
|
|
35205
|
+
return join6(windowsStartupDir(), AUTOSTART_VBS);
|
|
35204
35206
|
case "darwin":
|
|
35205
35207
|
return join6(homedir2(), "Library", "LaunchAgents", `${PLIST_LABEL}.plist`);
|
|
35206
35208
|
case "linux":
|
|
@@ -35210,15 +35212,26 @@ function platformItemPath() {
|
|
|
35210
35212
|
}
|
|
35211
35213
|
}
|
|
35212
35214
|
function windowsBody(nodePath, target) {
|
|
35215
|
+
const logPath = join6(target.appDir, "logs", "autostart.log");
|
|
35213
35216
|
const lines = [
|
|
35214
35217
|
"@echo off",
|
|
35218
|
+
// echo 按 OEM 代码页(GBK)写重定向,node 按 UTF-8 写——不切页日志会两种编码混写必然一半乱码
|
|
35219
|
+
"chcp 65001 >nul",
|
|
35215
35220
|
`rem Auto-generated by "ellm-proxy autostart on" (${MARKER}). Disable with "ellm-proxy autostart off".`,
|
|
35216
35221
|
...Object.entries(target.env).map(([k, v]) => `set "${k}=${v}"`),
|
|
35217
|
-
|
|
35222
|
+
`>> "${logPath}" echo [%date% %time%] autostart launching.`,
|
|
35223
|
+
`"${nodePath}" "${target.serverJs}" >> "${logPath}" 2>&1`,
|
|
35218
35224
|
""
|
|
35219
35225
|
];
|
|
35220
35226
|
return lines.join("\r\n");
|
|
35221
35227
|
}
|
|
35228
|
+
function windowsVbsBody(cmdPath) {
|
|
35229
|
+
return [
|
|
35230
|
+
`' Auto-generated by "ellm-proxy autostart on" (${MARKER}). Disable with "ellm-proxy autostart off".`,
|
|
35231
|
+
`CreateObject("WScript.Shell").Run """${cmdPath}""", 0, False`,
|
|
35232
|
+
""
|
|
35233
|
+
].join("\r\n");
|
|
35234
|
+
}
|
|
35222
35235
|
function darwinBody(nodePath, target) {
|
|
35223
35236
|
const logPath = join6(target.appDir, "logs", "autostart.log");
|
|
35224
35237
|
const envEntries = Object.entries(target.env).map(([k, v]) => ` <string>${k}</string>
|
|
@@ -35267,9 +35280,13 @@ function linuxBody(nodePath, target) {
|
|
|
35267
35280
|
].join("\n");
|
|
35268
35281
|
}
|
|
35269
35282
|
async function windowsOn(nodePath, target) {
|
|
35270
|
-
const
|
|
35271
|
-
|
|
35272
|
-
|
|
35283
|
+
const startupDir = windowsStartupDir();
|
|
35284
|
+
mkdirSync3(join6(target.appDir, "logs"), { recursive: true });
|
|
35285
|
+
const cmdPath = join6(target.appDir, AUTOSTART_CMD);
|
|
35286
|
+
writeFileSync3(cmdPath, windowsBody(nodePath, target), "utf-8");
|
|
35287
|
+
writeFileSync3(join6(startupDir, AUTOSTART_VBS), `\uFEFF${windowsVbsBody(cmdPath)}`, "utf16le");
|
|
35288
|
+
rmSync2(join6(startupDir, AUTOSTART_CMD), { force: true });
|
|
35289
|
+
return join6(startupDir, AUTOSTART_VBS);
|
|
35273
35290
|
}
|
|
35274
35291
|
async function darwinOn(nodePath, target) {
|
|
35275
35292
|
const itemPath = join6(homedir2(), "Library", "LaunchAgents", `${PLIST_LABEL}.plist`);
|
|
@@ -35301,10 +35318,13 @@ async function linuxOn(nodePath, target) {
|
|
|
35301
35318
|
return itemPath;
|
|
35302
35319
|
}
|
|
35303
35320
|
async function windowsOff() {
|
|
35304
|
-
const
|
|
35305
|
-
|
|
35306
|
-
|
|
35307
|
-
|
|
35321
|
+
const startupDir = windowsStartupDir();
|
|
35322
|
+
const vbsPath = join6(startupDir, AUTOSTART_VBS);
|
|
35323
|
+
const legacyCmd = join6(startupDir, AUTOSTART_CMD);
|
|
35324
|
+
const existed = existsSync2(vbsPath) || existsSync2(legacyCmd);
|
|
35325
|
+
rmSync2(vbsPath, { force: true });
|
|
35326
|
+
rmSync2(legacyCmd, { force: true });
|
|
35327
|
+
return existed;
|
|
35308
35328
|
}
|
|
35309
35329
|
async function darwinOff() {
|
|
35310
35330
|
const itemPath = join6(homedir2(), "Library", "LaunchAgents", `${PLIST_LABEL}.plist`);
|
|
@@ -35321,18 +35341,32 @@ async function linuxOff() {
|
|
|
35321
35341
|
await runExit("systemctl", ["--user", "daemon-reload"]);
|
|
35322
35342
|
return true;
|
|
35323
35343
|
}
|
|
35344
|
+
function readTextDetectingBom(path7) {
|
|
35345
|
+
const buf = readFileSync5(path7);
|
|
35346
|
+
if (buf.length >= 2 && buf[0] === 255 && buf[1] === 254) return buf.toString("utf16le").slice(1);
|
|
35347
|
+
return buf.toString("utf-8");
|
|
35348
|
+
}
|
|
35324
35349
|
function autostartStatus(appDir) {
|
|
35325
35350
|
const itemPath = platformItemPath();
|
|
35326
35351
|
let enabled = false;
|
|
35327
35352
|
let outdated = false;
|
|
35328
35353
|
if (itemPath && existsSync2(itemPath)) {
|
|
35329
35354
|
try {
|
|
35330
|
-
|
|
35331
|
-
if (content.includes(MARKER)) enabled = true;
|
|
35355
|
+
if (readTextDetectingBom(itemPath).includes(MARKER)) enabled = true;
|
|
35332
35356
|
else outdated = true;
|
|
35333
35357
|
} catch {
|
|
35334
35358
|
}
|
|
35335
35359
|
}
|
|
35360
|
+
if (platform8() === "win32" && !enabled) {
|
|
35361
|
+
const legacyCmd = join6(windowsStartupDir(), AUTOSTART_CMD);
|
|
35362
|
+
if (existsSync2(legacyCmd)) {
|
|
35363
|
+
try {
|
|
35364
|
+
if (readTextDetectingBom(legacyCmd).includes(MARKER) || readTextDetectingBom(legacyCmd).includes(V2_MARKER))
|
|
35365
|
+
outdated = true;
|
|
35366
|
+
} catch {
|
|
35367
|
+
}
|
|
35368
|
+
}
|
|
35369
|
+
}
|
|
35336
35370
|
return {
|
|
35337
35371
|
platform: platform8(),
|
|
35338
35372
|
enabled,
|
|
@@ -35370,7 +35404,7 @@ async function ensureAutostartOnStart(target) {
|
|
|
35370
35404
|
if (status.enabled) return;
|
|
35371
35405
|
if (status.optOut) return;
|
|
35372
35406
|
const { itemPath } = await enableAutostart(target);
|
|
35373
|
-
console.log(status.outdated ? `\u5DF2\
|
|
35407
|
+
console.log(status.outdated ? `\u5DF2\u66F4\u65B0\u5F00\u673A\u81EA\u542F\u9879: ${itemPath}` : `\u5DF2\u81EA\u52A8\u6CE8\u518C\u5F00\u673A\u81EA\u542F: ${itemPath}`);
|
|
35374
35408
|
console.log("\u7981\u7528\u65B9\u5F0F: ellm-proxy autostart off \u6216\u7BA1\u7406\u53F0\u8BBE\u7F6E\u9875\u3002");
|
|
35375
35409
|
} catch (err) {
|
|
35376
35410
|
console.warn(`\u5F00\u673A\u81EA\u542F\u6CE8\u518C\u5931\u8D25\uFF08\u4E0D\u5F71\u54CD\u672C\u6B21\u542F\u52A8\uFF09: ${err instanceof Error ? err.message : String(err)}`);
|
|
@@ -35678,7 +35712,7 @@ cli.command(
|
|
|
35678
35712
|
nodePath: await resolveInterpreter()
|
|
35679
35713
|
});
|
|
35680
35714
|
console.log("\u5F00\u673A\u81EA\u542F\u5DF2\u5F00\u542F\uFF08\u767B\u5F55\u65F6\u89E6\u53D1\uFF09\uFF1A");
|
|
35681
|
-
console.log(` \u81EA\u542F\u9879 : ${itemPath}\uFF08\
|
|
35715
|
+
console.log(` \u81EA\u542F\u9879 : ${itemPath}\uFF08\u767B\u5F55\u65F6\u65E0\u7A97\u53E3\u540E\u53F0\u542F\u52A8\uFF09`);
|
|
35682
35716
|
console.log(" \u7981\u7528\u65B9\u5F0F : ellm-proxy autostart off");
|
|
35683
35717
|
} else {
|
|
35684
35718
|
const { removed } = await disableAutostart({ appDir });
|
package/dist/server.js
CHANGED
|
@@ -20586,11 +20586,13 @@ import { existsSync as existsSync7, mkdirSync as mkdirSync4, readFileSync as rea
|
|
|
20586
20586
|
import { spawn as spawn2 } from "node:child_process";
|
|
20587
20587
|
import { homedir, platform } from "node:os";
|
|
20588
20588
|
import { join as join5 } from "node:path";
|
|
20589
|
+
var AUTOSTART_VBS = "ellm-proxy-autostart.vbs";
|
|
20589
20590
|
var AUTOSTART_CMD = "ellm-proxy-autostart.cmd";
|
|
20590
20591
|
var PLIST_LABEL = "com.ellm-proxy.autostart";
|
|
20591
20592
|
var LINUX_UNIT = "ellm-proxy.service";
|
|
20592
20593
|
var OPT_OUT_FILE = "autostart.opt-out";
|
|
20593
|
-
var MARKER = "ellm-proxy-
|
|
20594
|
+
var MARKER = "ellm-proxy-v3";
|
|
20595
|
+
var V2_MARKER = "ellm-proxy-v2";
|
|
20594
20596
|
var ENV_WHITELIST_PREFIX = "ELLM_";
|
|
20595
20597
|
var ENV_WHITELIST_KEYS = /* @__PURE__ */ new Set(["WEBUI_USERNAME", "WEBUI_PASSWORD"]);
|
|
20596
20598
|
function collectAutostartEnv(env = process.env) {
|
|
@@ -20619,7 +20621,7 @@ function runExit(cmd, args) {
|
|
|
20619
20621
|
function platformItemPath() {
|
|
20620
20622
|
switch (platform()) {
|
|
20621
20623
|
case "win32":
|
|
20622
|
-
return join5(windowsStartupDir(),
|
|
20624
|
+
return join5(windowsStartupDir(), AUTOSTART_VBS);
|
|
20623
20625
|
case "darwin":
|
|
20624
20626
|
return join5(homedir(), "Library", "LaunchAgents", `${PLIST_LABEL}.plist`);
|
|
20625
20627
|
case "linux":
|
|
@@ -20629,15 +20631,26 @@ function platformItemPath() {
|
|
|
20629
20631
|
}
|
|
20630
20632
|
}
|
|
20631
20633
|
function windowsBody(nodePath, target) {
|
|
20634
|
+
const logPath = join5(target.appDir, "logs", "autostart.log");
|
|
20632
20635
|
const lines = [
|
|
20633
20636
|
"@echo off",
|
|
20637
|
+
// echo 按 OEM 代码页(GBK)写重定向,node 按 UTF-8 写——不切页日志会两种编码混写必然一半乱码
|
|
20638
|
+
"chcp 65001 >nul",
|
|
20634
20639
|
`rem Auto-generated by "ellm-proxy autostart on" (${MARKER}). Disable with "ellm-proxy autostart off".`,
|
|
20635
20640
|
...Object.entries(target.env).map(([k, v]) => `set "${k}=${v}"`),
|
|
20636
|
-
|
|
20641
|
+
`>> "${logPath}" echo [%date% %time%] autostart launching.`,
|
|
20642
|
+
`"${nodePath}" "${target.serverJs}" >> "${logPath}" 2>&1`,
|
|
20637
20643
|
""
|
|
20638
20644
|
];
|
|
20639
20645
|
return lines.join("\r\n");
|
|
20640
20646
|
}
|
|
20647
|
+
function windowsVbsBody(cmdPath) {
|
|
20648
|
+
return [
|
|
20649
|
+
`' Auto-generated by "ellm-proxy autostart on" (${MARKER}). Disable with "ellm-proxy autostart off".`,
|
|
20650
|
+
`CreateObject("WScript.Shell").Run """${cmdPath}""", 0, False`,
|
|
20651
|
+
""
|
|
20652
|
+
].join("\r\n");
|
|
20653
|
+
}
|
|
20641
20654
|
function darwinBody(nodePath, target) {
|
|
20642
20655
|
const logPath = join5(target.appDir, "logs", "autostart.log");
|
|
20643
20656
|
const envEntries = Object.entries(target.env).map(([k, v]) => ` <string>${k}</string>
|
|
@@ -20686,9 +20699,13 @@ function linuxBody(nodePath, target) {
|
|
|
20686
20699
|
].join("\n");
|
|
20687
20700
|
}
|
|
20688
20701
|
async function windowsOn(nodePath, target) {
|
|
20689
|
-
const
|
|
20690
|
-
|
|
20691
|
-
|
|
20702
|
+
const startupDir = windowsStartupDir();
|
|
20703
|
+
mkdirSync4(join5(target.appDir, "logs"), { recursive: true });
|
|
20704
|
+
const cmdPath = join5(target.appDir, AUTOSTART_CMD);
|
|
20705
|
+
writeFileSync5(cmdPath, windowsBody(nodePath, target), "utf-8");
|
|
20706
|
+
writeFileSync5(join5(startupDir, AUTOSTART_VBS), `\uFEFF${windowsVbsBody(cmdPath)}`, "utf16le");
|
|
20707
|
+
rmSync2(join5(startupDir, AUTOSTART_CMD), { force: true });
|
|
20708
|
+
return join5(startupDir, AUTOSTART_VBS);
|
|
20692
20709
|
}
|
|
20693
20710
|
async function darwinOn(nodePath, target) {
|
|
20694
20711
|
const itemPath = join5(homedir(), "Library", "LaunchAgents", `${PLIST_LABEL}.plist`);
|
|
@@ -20720,10 +20737,13 @@ async function linuxOn(nodePath, target) {
|
|
|
20720
20737
|
return itemPath;
|
|
20721
20738
|
}
|
|
20722
20739
|
async function windowsOff() {
|
|
20723
|
-
const
|
|
20724
|
-
|
|
20725
|
-
|
|
20726
|
-
|
|
20740
|
+
const startupDir = windowsStartupDir();
|
|
20741
|
+
const vbsPath = join5(startupDir, AUTOSTART_VBS);
|
|
20742
|
+
const legacyCmd = join5(startupDir, AUTOSTART_CMD);
|
|
20743
|
+
const existed = existsSync7(vbsPath) || existsSync7(legacyCmd);
|
|
20744
|
+
rmSync2(vbsPath, { force: true });
|
|
20745
|
+
rmSync2(legacyCmd, { force: true });
|
|
20746
|
+
return existed;
|
|
20727
20747
|
}
|
|
20728
20748
|
async function darwinOff() {
|
|
20729
20749
|
const itemPath = join5(homedir(), "Library", "LaunchAgents", `${PLIST_LABEL}.plist`);
|
|
@@ -20740,18 +20760,32 @@ async function linuxOff() {
|
|
|
20740
20760
|
await runExit("systemctl", ["--user", "daemon-reload"]);
|
|
20741
20761
|
return true;
|
|
20742
20762
|
}
|
|
20763
|
+
function readTextDetectingBom(path) {
|
|
20764
|
+
const buf = readFileSync6(path);
|
|
20765
|
+
if (buf.length >= 2 && buf[0] === 255 && buf[1] === 254) return buf.toString("utf16le").slice(1);
|
|
20766
|
+
return buf.toString("utf-8");
|
|
20767
|
+
}
|
|
20743
20768
|
function autostartStatus(appDir) {
|
|
20744
20769
|
const itemPath = platformItemPath();
|
|
20745
20770
|
let enabled = false;
|
|
20746
20771
|
let outdated = false;
|
|
20747
20772
|
if (itemPath && existsSync7(itemPath)) {
|
|
20748
20773
|
try {
|
|
20749
|
-
|
|
20750
|
-
if (content.includes(MARKER)) enabled = true;
|
|
20774
|
+
if (readTextDetectingBom(itemPath).includes(MARKER)) enabled = true;
|
|
20751
20775
|
else outdated = true;
|
|
20752
20776
|
} catch {
|
|
20753
20777
|
}
|
|
20754
20778
|
}
|
|
20779
|
+
if (platform() === "win32" && !enabled) {
|
|
20780
|
+
const legacyCmd = join5(windowsStartupDir(), AUTOSTART_CMD);
|
|
20781
|
+
if (existsSync7(legacyCmd)) {
|
|
20782
|
+
try {
|
|
20783
|
+
if (readTextDetectingBom(legacyCmd).includes(MARKER) || readTextDetectingBom(legacyCmd).includes(V2_MARKER))
|
|
20784
|
+
outdated = true;
|
|
20785
|
+
} catch {
|
|
20786
|
+
}
|
|
20787
|
+
}
|
|
20788
|
+
}
|
|
20755
20789
|
return {
|
|
20756
20790
|
platform: platform(),
|
|
20757
20791
|
enabled,
|