@khanglvm/llm-router 2.0.1 → 2.0.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/package.json +1 -1
- package/src/node/startup-manager.js +66 -11
package/package.json
CHANGED
|
@@ -11,6 +11,20 @@ import { FIXED_LOCAL_ROUTER_HOST, FIXED_LOCAL_ROUTER_PORT } from "./local-server
|
|
|
11
11
|
|
|
12
12
|
const SERVICE_NAME = "llm-router";
|
|
13
13
|
const LAUNCH_AGENT_ID = "dev.llm-router";
|
|
14
|
+
const STARTUP_ENV_PASSTHROUGH_KEYS = [
|
|
15
|
+
"NODE_EXTRA_CA_CERTS",
|
|
16
|
+
"SSL_CERT_FILE",
|
|
17
|
+
"SSL_CERT_DIR",
|
|
18
|
+
"HTTP_PROXY",
|
|
19
|
+
"HTTPS_PROXY",
|
|
20
|
+
"ALL_PROXY",
|
|
21
|
+
"NO_PROXY",
|
|
22
|
+
"http_proxy",
|
|
23
|
+
"https_proxy",
|
|
24
|
+
"all_proxy",
|
|
25
|
+
"no_proxy",
|
|
26
|
+
"npm_config_cafile"
|
|
27
|
+
];
|
|
14
28
|
|
|
15
29
|
function resolveDarwinDomain() {
|
|
16
30
|
const uid = process.getuid?.();
|
|
@@ -83,13 +97,48 @@ function isMissingServiceMessage(value) {
|
|
|
83
97
|
|| text.includes("unit llm-router.service could not be found");
|
|
84
98
|
}
|
|
85
99
|
|
|
100
|
+
function escapeXml(value) {
|
|
101
|
+
return String(value)
|
|
102
|
+
.replaceAll("&", "&")
|
|
103
|
+
.replaceAll("<", "<")
|
|
104
|
+
.replaceAll(">", ">")
|
|
105
|
+
.replaceAll('"', """)
|
|
106
|
+
.replaceAll("'", "'");
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function buildStartupEnvironment(env = process.env) {
|
|
110
|
+
const configuredCliPath = String(env?.LLM_ROUTER_CLI_PATH || "").trim();
|
|
111
|
+
const startupEnv = {
|
|
112
|
+
LLM_ROUTER_MANAGED_BY_STARTUP: "1",
|
|
113
|
+
LLM_ROUTER_CLI_PATH: configuredCliPath || String(resolveStartupCliEntryPath({ env }) || "").trim()
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
for (const key of STARTUP_ENV_PASSTHROUGH_KEYS) {
|
|
117
|
+
const value = String(env?.[key] || "").trim();
|
|
118
|
+
if (!value) continue;
|
|
119
|
+
startupEnv[key] = value;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return startupEnv;
|
|
123
|
+
}
|
|
124
|
+
|
|
86
125
|
function buildLaunchAgentPlist({ nodePath, cliPath, configPath, host, port, watchConfig, watchBinary, requireAuth }) {
|
|
87
126
|
const logDir = path.join(os.homedir(), "Library", "Logs");
|
|
88
127
|
const stdoutPath = path.join(logDir, "llm-router.out.log");
|
|
89
128
|
const stderrPath = path.join(logDir, "llm-router.err.log");
|
|
90
129
|
const args = [nodePath, cliPath, ...makeExecArgs({ configPath, host, port, watchConfig, watchBinary, requireAuth })];
|
|
130
|
+
const environment = {
|
|
131
|
+
...buildStartupEnvironment({
|
|
132
|
+
...process.env,
|
|
133
|
+
LLM_ROUTER_CLI_PATH: cliPath
|
|
134
|
+
}),
|
|
135
|
+
LLM_ROUTER_CLI_PATH: cliPath
|
|
136
|
+
};
|
|
91
137
|
|
|
92
|
-
const xmlArgs = args.map((arg) => ` <string>${arg}</string>`).join("\n");
|
|
138
|
+
const xmlArgs = args.map((arg) => ` <string>${escapeXml(arg)}</string>`).join("\n");
|
|
139
|
+
const xmlEnvironment = Object.entries(environment)
|
|
140
|
+
.map(([key, value]) => ` <key>${escapeXml(key)}</key>\n <string>${escapeXml(value)}</string>`)
|
|
141
|
+
.join("\n");
|
|
93
142
|
|
|
94
143
|
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
95
144
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
@@ -107,17 +156,14 @@ ${xmlArgs}
|
|
|
107
156
|
<true/>
|
|
108
157
|
<key>EnvironmentVariables</key>
|
|
109
158
|
<dict>
|
|
110
|
-
|
|
111
|
-
<string>1</string>
|
|
112
|
-
<key>LLM_ROUTER_CLI_PATH</key>
|
|
113
|
-
<string>${cliPath}</string>
|
|
159
|
+
${xmlEnvironment}
|
|
114
160
|
</dict>
|
|
115
161
|
<key>StandardOutPath</key>
|
|
116
|
-
<string>${stdoutPath}</string>
|
|
162
|
+
<string>${escapeXml(stdoutPath)}</string>
|
|
117
163
|
<key>StandardErrorPath</key>
|
|
118
|
-
<string>${stderrPath}</string>
|
|
164
|
+
<string>${escapeXml(stderrPath)}</string>
|
|
119
165
|
<key>WorkingDirectory</key>
|
|
120
|
-
<string>${process.cwd()}</string>
|
|
166
|
+
<string>${escapeXml(process.cwd())}</string>
|
|
121
167
|
</dict>
|
|
122
168
|
</plist>
|
|
123
169
|
`;
|
|
@@ -126,6 +172,17 @@ ${xmlArgs}
|
|
|
126
172
|
function buildSystemdService({ nodePath, cliPath, configPath, host, port, watchConfig, watchBinary, requireAuth }) {
|
|
127
173
|
const execArgs = makeExecArgs({ configPath, host, port, watchConfig, watchBinary, requireAuth }).map(quoteArg).join(" ");
|
|
128
174
|
const execStart = `${quoteArg(nodePath)} ${quoteArg(cliPath)} ${execArgs}`;
|
|
175
|
+
const environment = {
|
|
176
|
+
...buildStartupEnvironment({
|
|
177
|
+
...process.env,
|
|
178
|
+
LLM_ROUTER_CLI_PATH: cliPath
|
|
179
|
+
}),
|
|
180
|
+
LLM_ROUTER_CLI_PATH: cliPath,
|
|
181
|
+
NODE_ENV: "production"
|
|
182
|
+
};
|
|
183
|
+
const systemdEnvironment = Object.entries(environment)
|
|
184
|
+
.map(([key, value]) => `Environment=${key}=${value}`)
|
|
185
|
+
.join("\n");
|
|
129
186
|
|
|
130
187
|
return `[Unit]
|
|
131
188
|
Description=LLM Router local route
|
|
@@ -136,9 +193,7 @@ Type=simple
|
|
|
136
193
|
ExecStart=${execStart}
|
|
137
194
|
Restart=always
|
|
138
195
|
RestartSec=2
|
|
139
|
-
|
|
140
|
-
Environment=LLM_ROUTER_MANAGED_BY_STARTUP=1
|
|
141
|
-
Environment=LLM_ROUTER_CLI_PATH=${cliPath}
|
|
196
|
+
${systemdEnvironment}
|
|
142
197
|
WorkingDirectory=${process.cwd()}
|
|
143
198
|
|
|
144
199
|
[Install]
|