grepmax 0.13.2 → 0.13.4
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/commands/llm.js
CHANGED
|
@@ -45,12 +45,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
45
45
|
exports.llm = void 0;
|
|
46
46
|
const path = __importStar(require("node:path"));
|
|
47
47
|
const commander_1 = require("commander");
|
|
48
|
+
const index_config_1 = require("../lib/index/index-config");
|
|
48
49
|
const exit_1 = require("../lib/utils/exit");
|
|
49
50
|
function showStatus() {
|
|
50
51
|
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
const config = (0, index_config_1.readGlobalConfig)();
|
|
53
|
+
const enabled = config.llmEnabled === true;
|
|
51
54
|
const { isDaemonRunning, sendDaemonCommand } = yield Promise.resolve().then(() => __importStar(require("../lib/utils/daemon-client")));
|
|
52
55
|
if (!(yield isDaemonRunning())) {
|
|
53
|
-
console.log(
|
|
56
|
+
console.log(`LLM: ${enabled ? "enabled" : "disabled"} · server not running (daemon not started)`);
|
|
54
57
|
return;
|
|
55
58
|
}
|
|
56
59
|
const resp = yield sendDaemonCommand({ cmd: "llm-status" });
|
|
@@ -64,12 +67,12 @@ function showStatus() {
|
|
|
64
67
|
const uptime = Number(resp.uptime) || 0;
|
|
65
68
|
const mins = Math.floor(uptime / 60);
|
|
66
69
|
const secs = uptime % 60;
|
|
67
|
-
console.log(`LLM
|
|
70
|
+
console.log(`LLM: enabled · running (PID: ${resp.pid}, port: ${resp.port})`);
|
|
68
71
|
console.log(` Model: ${model}`);
|
|
69
72
|
console.log(` Uptime: ${mins}m ${secs}s`);
|
|
70
73
|
}
|
|
71
74
|
else {
|
|
72
|
-
console.log(
|
|
75
|
+
console.log(`LLM: ${enabled ? "enabled" : "disabled"} · server not running`);
|
|
73
76
|
}
|
|
74
77
|
});
|
|
75
78
|
}
|
|
@@ -141,3 +144,40 @@ exports.llm
|
|
|
141
144
|
yield (0, exit_1.gracefulExit)();
|
|
142
145
|
}
|
|
143
146
|
}));
|
|
147
|
+
exports.llm
|
|
148
|
+
.command("on")
|
|
149
|
+
.description("Enable LLM features (allows server to start)")
|
|
150
|
+
.action(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
151
|
+
try {
|
|
152
|
+
const config = (0, index_config_1.readGlobalConfig)();
|
|
153
|
+
config.llmEnabled = true;
|
|
154
|
+
(0, index_config_1.writeGlobalConfig)(config);
|
|
155
|
+
console.log("LLM enabled. Use `gmax llm start` to start the server.");
|
|
156
|
+
}
|
|
157
|
+
finally {
|
|
158
|
+
yield (0, exit_1.gracefulExit)();
|
|
159
|
+
}
|
|
160
|
+
}));
|
|
161
|
+
exports.llm
|
|
162
|
+
.command("off")
|
|
163
|
+
.description("Disable LLM features and stop the server if running")
|
|
164
|
+
.action(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
165
|
+
try {
|
|
166
|
+
// Stop server if running
|
|
167
|
+
const { isDaemonRunning, sendDaemonCommand } = yield Promise.resolve().then(() => __importStar(require("../lib/utils/daemon-client")));
|
|
168
|
+
if (yield isDaemonRunning()) {
|
|
169
|
+
const status = yield sendDaemonCommand({ cmd: "llm-status" });
|
|
170
|
+
if (status.ok && status.running) {
|
|
171
|
+
yield sendDaemonCommand({ cmd: "llm-stop" });
|
|
172
|
+
console.log("LLM server stopped.");
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
const config = (0, index_config_1.readGlobalConfig)();
|
|
176
|
+
config.llmEnabled = false;
|
|
177
|
+
(0, index_config_1.writeGlobalConfig)(config);
|
|
178
|
+
console.log("LLM disabled. Server will not auto-start.");
|
|
179
|
+
}
|
|
180
|
+
finally {
|
|
181
|
+
yield (0, exit_1.gracefulExit)();
|
|
182
|
+
}
|
|
183
|
+
}));
|
package/dist/lib/llm/server.js
CHANGED
|
@@ -47,12 +47,13 @@ const node_child_process_1 = require("node:child_process");
|
|
|
47
47
|
const fs = __importStar(require("node:fs"));
|
|
48
48
|
const http = __importStar(require("node:http"));
|
|
49
49
|
const config_1 = require("../../config");
|
|
50
|
+
const index_config_1 = require("../index/index-config");
|
|
50
51
|
const log_rotate_1 = require("../utils/log-rotate");
|
|
51
52
|
const config_2 = require("./config");
|
|
52
53
|
const HEALTH_TIMEOUT_MS = 2000;
|
|
53
54
|
const POLL_INTERVAL_MS = 500;
|
|
54
55
|
const STOP_GRACE_MS = 5000;
|
|
55
|
-
const
|
|
56
|
+
const DEFAULT_IDLE_CHECK_INTERVAL_MS = 5 * 60 * 1000;
|
|
56
57
|
class LlmServer {
|
|
57
58
|
constructor() {
|
|
58
59
|
this.lastRequestTime = 0;
|
|
@@ -79,11 +80,23 @@ class LlmServer {
|
|
|
79
80
|
});
|
|
80
81
|
});
|
|
81
82
|
}
|
|
83
|
+
/** Check if LLM is enabled in global config. */
|
|
84
|
+
isEnabled() {
|
|
85
|
+
return (0, index_config_1.readGlobalConfig)().llmEnabled === true;
|
|
86
|
+
}
|
|
82
87
|
/** Start llama-server, poll until ready, start idle watchdog. */
|
|
83
88
|
start() {
|
|
84
89
|
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
-
if (
|
|
90
|
+
if (!this.isEnabled()) {
|
|
91
|
+
throw new Error("LLM is disabled. Run `gmax llm on` to enable.");
|
|
92
|
+
}
|
|
93
|
+
if (yield this.healthy()) {
|
|
94
|
+
// Adopt an existing server (e.g. after daemon crash + restart)
|
|
95
|
+
this.lastRequestTime = Date.now();
|
|
96
|
+
this.startTime = Date.now();
|
|
97
|
+
this.startIdleWatchdog();
|
|
86
98
|
return;
|
|
99
|
+
}
|
|
87
100
|
// Validate binary
|
|
88
101
|
const binary = this.config.binary;
|
|
89
102
|
try {
|
|
@@ -186,9 +199,12 @@ class LlmServer {
|
|
|
186
199
|
console.log(`[llm] Server force-killed (PID: ${pid})`);
|
|
187
200
|
});
|
|
188
201
|
}
|
|
189
|
-
/** Start if not running. */
|
|
202
|
+
/** Start if not running. Respects llmEnabled config. */
|
|
190
203
|
ensure() {
|
|
191
204
|
return __awaiter(this, void 0, void 0, function* () {
|
|
205
|
+
if (!this.isEnabled()) {
|
|
206
|
+
throw new Error("LLM is disabled. Run `gmax llm on` to enable.");
|
|
207
|
+
}
|
|
192
208
|
if (yield this.healthy()) {
|
|
193
209
|
this.touchIdle();
|
|
194
210
|
return;
|
|
@@ -215,6 +231,7 @@ class LlmServer {
|
|
|
215
231
|
startIdleWatchdog() {
|
|
216
232
|
this.stopIdleWatchdog();
|
|
217
233
|
const timeoutMs = this.config.idleTimeoutMin * 60 * 1000;
|
|
234
|
+
const checkInterval = Math.min(DEFAULT_IDLE_CHECK_INTERVAL_MS, timeoutMs);
|
|
218
235
|
this.idleTimer = setInterval(() => __awaiter(this, void 0, void 0, function* () {
|
|
219
236
|
if (this.lastRequestTime === 0)
|
|
220
237
|
return;
|
|
@@ -222,7 +239,7 @@ class LlmServer {
|
|
|
222
239
|
console.log(`[llm] Server idle for ${this.config.idleTimeoutMin}min, shutting down`);
|
|
223
240
|
yield this.stop();
|
|
224
241
|
}
|
|
225
|
-
}),
|
|
242
|
+
}), checkInterval);
|
|
226
243
|
this.idleTimer.unref();
|
|
227
244
|
}
|
|
228
245
|
stopIdleWatchdog() {
|
package/package.json
CHANGED