@appkit/llamacpp-cli 1.7.0 → 1.9.0
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/CHANGELOG.md +42 -0
- package/README.md +84 -0
- package/dist/cli.js +80 -0
- package/dist/cli.js.map +1 -1
- package/dist/commands/config.d.ts +1 -0
- package/dist/commands/config.d.ts.map +1 -1
- package/dist/commands/config.js +167 -12
- package/dist/commands/config.js.map +1 -1
- package/dist/commands/router/config.d.ts +10 -0
- package/dist/commands/router/config.d.ts.map +1 -0
- package/dist/commands/router/config.js +95 -0
- package/dist/commands/router/config.js.map +1 -0
- package/dist/commands/router/restart.d.ts +2 -0
- package/dist/commands/router/restart.d.ts.map +1 -0
- package/dist/commands/router/restart.js +39 -0
- package/dist/commands/router/restart.js.map +1 -0
- package/dist/commands/router/start.d.ts +2 -0
- package/dist/commands/router/start.d.ts.map +1 -0
- package/dist/commands/router/start.js +60 -0
- package/dist/commands/router/start.js.map +1 -0
- package/dist/commands/router/status.d.ts +2 -0
- package/dist/commands/router/status.d.ts.map +1 -0
- package/dist/commands/router/status.js +116 -0
- package/dist/commands/router/status.js.map +1 -0
- package/dist/commands/router/stop.d.ts +2 -0
- package/dist/commands/router/stop.d.ts.map +1 -0
- package/dist/commands/router/stop.js +36 -0
- package/dist/commands/router/stop.js.map +1 -0
- package/dist/lib/router-manager.d.ts +103 -0
- package/dist/lib/router-manager.d.ts.map +1 -0
- package/dist/lib/router-manager.js +393 -0
- package/dist/lib/router-manager.js.map +1 -0
- package/dist/lib/router-server.d.ts +52 -0
- package/dist/lib/router-server.d.ts.map +1 -0
- package/dist/lib/router-server.js +373 -0
- package/dist/lib/router-server.js.map +1 -0
- package/dist/types/router-config.d.ts +18 -0
- package/dist/types/router-config.d.ts.map +1 -0
- package/dist/types/router-config.js +3 -0
- package/dist/types/router-config.js.map +1 -0
- package/package.json +1 -1
- package/src/cli.ts +81 -0
- package/src/commands/config.ts +146 -14
- package/src/commands/router/config.ts +109 -0
- package/src/commands/router/restart.ts +36 -0
- package/src/commands/router/start.ts +60 -0
- package/src/commands/router/status.ts +119 -0
- package/src/commands/router/stop.ts +33 -0
- package/src/lib/router-manager.ts +413 -0
- package/src/lib/router-server.ts +407 -0
- package/src/types/router-config.ts +24 -0
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.routerManager = exports.RouterManager = void 0;
|
|
37
|
+
const path = __importStar(require("path"));
|
|
38
|
+
const fs = __importStar(require("fs/promises"));
|
|
39
|
+
const process_utils_1 = require("../utils/process-utils");
|
|
40
|
+
const file_utils_1 = require("../utils/file-utils");
|
|
41
|
+
class RouterManager {
|
|
42
|
+
constructor() {
|
|
43
|
+
this.configDir = (0, file_utils_1.getConfigDir)();
|
|
44
|
+
this.logsDir = (0, file_utils_1.getLogsDir)();
|
|
45
|
+
this.configPath = path.join(this.configDir, 'router.json');
|
|
46
|
+
this.launchAgentsDir = (0, file_utils_1.getLaunchAgentsDir)();
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Initialize router directories
|
|
50
|
+
*/
|
|
51
|
+
async initialize() {
|
|
52
|
+
await (0, file_utils_1.ensureDir)(this.configDir);
|
|
53
|
+
await (0, file_utils_1.ensureDir)(this.logsDir);
|
|
54
|
+
await (0, file_utils_1.ensureDir)(this.launchAgentsDir);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Get default router configuration
|
|
58
|
+
*/
|
|
59
|
+
getDefaultConfig() {
|
|
60
|
+
return {
|
|
61
|
+
id: 'router',
|
|
62
|
+
port: 9100,
|
|
63
|
+
host: '127.0.0.1',
|
|
64
|
+
label: 'com.llama.router',
|
|
65
|
+
plistPath: path.join(this.launchAgentsDir, 'com.llama.router.plist'),
|
|
66
|
+
stdoutPath: path.join(this.logsDir, 'router.stdout'),
|
|
67
|
+
stderrPath: path.join(this.logsDir, 'router.stderr'),
|
|
68
|
+
healthCheckInterval: 5000,
|
|
69
|
+
requestTimeout: 120000,
|
|
70
|
+
status: 'stopped',
|
|
71
|
+
createdAt: new Date().toISOString(),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Load router configuration
|
|
76
|
+
*/
|
|
77
|
+
async loadConfig() {
|
|
78
|
+
if (!(await (0, file_utils_1.fileExists)(this.configPath))) {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
return await (0, file_utils_1.readJson)(this.configPath);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Save router configuration
|
|
85
|
+
*/
|
|
86
|
+
async saveConfig(config) {
|
|
87
|
+
await (0, file_utils_1.writeJsonAtomic)(this.configPath, config);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Update router configuration with partial changes
|
|
91
|
+
*/
|
|
92
|
+
async updateConfig(updates) {
|
|
93
|
+
const existingConfig = await this.loadConfig();
|
|
94
|
+
if (!existingConfig) {
|
|
95
|
+
throw new Error('Router configuration not found');
|
|
96
|
+
}
|
|
97
|
+
const updatedConfig = { ...existingConfig, ...updates };
|
|
98
|
+
await this.saveConfig(updatedConfig);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Delete router configuration
|
|
102
|
+
*/
|
|
103
|
+
async deleteConfig() {
|
|
104
|
+
if (await (0, file_utils_1.fileExists)(this.configPath)) {
|
|
105
|
+
await fs.unlink(this.configPath);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Generate plist XML content for the router
|
|
110
|
+
*/
|
|
111
|
+
generatePlist(config) {
|
|
112
|
+
// Find the compiled router-server.js file
|
|
113
|
+
// In dev mode (tsx), __dirname is src/lib/
|
|
114
|
+
// In production, __dirname is dist/lib/
|
|
115
|
+
// Always use the compiled dist version for launchctl
|
|
116
|
+
let routerServerPath;
|
|
117
|
+
if (__dirname.includes('/src/')) {
|
|
118
|
+
// Dev mode - point to dist/lib/router-server.js
|
|
119
|
+
const projectRoot = path.resolve(__dirname, '../..');
|
|
120
|
+
routerServerPath = path.join(projectRoot, 'dist/lib/router-server.js');
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
// Production mode - already in dist/lib/
|
|
124
|
+
routerServerPath = path.join(__dirname, 'router-server.js');
|
|
125
|
+
}
|
|
126
|
+
// Use the current Node.js executable path (resolves symlinks)
|
|
127
|
+
const nodePath = process.execPath;
|
|
128
|
+
const args = [
|
|
129
|
+
nodePath,
|
|
130
|
+
routerServerPath,
|
|
131
|
+
'--config', this.configPath,
|
|
132
|
+
];
|
|
133
|
+
const argsXml = args.map(arg => ` <string>${arg}</string>`).join('\n');
|
|
134
|
+
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
135
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
|
|
136
|
+
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
137
|
+
<plist version="1.0">
|
|
138
|
+
<dict>
|
|
139
|
+
<key>Label</key>
|
|
140
|
+
<string>${config.label}</string>
|
|
141
|
+
|
|
142
|
+
<key>ProgramArguments</key>
|
|
143
|
+
<array>
|
|
144
|
+
${argsXml}
|
|
145
|
+
</array>
|
|
146
|
+
|
|
147
|
+
<key>RunAtLoad</key>
|
|
148
|
+
<false/>
|
|
149
|
+
|
|
150
|
+
<key>KeepAlive</key>
|
|
151
|
+
<dict>
|
|
152
|
+
<key>Crashed</key>
|
|
153
|
+
<true/>
|
|
154
|
+
<key>SuccessfulExit</key>
|
|
155
|
+
<false/>
|
|
156
|
+
</dict>
|
|
157
|
+
|
|
158
|
+
<key>StandardOutPath</key>
|
|
159
|
+
<string>${config.stdoutPath}</string>
|
|
160
|
+
|
|
161
|
+
<key>StandardErrorPath</key>
|
|
162
|
+
<string>${config.stderrPath}</string>
|
|
163
|
+
|
|
164
|
+
<key>WorkingDirectory</key>
|
|
165
|
+
<string>/tmp</string>
|
|
166
|
+
|
|
167
|
+
<key>ThrottleInterval</key>
|
|
168
|
+
<integer>10</integer>
|
|
169
|
+
</dict>
|
|
170
|
+
</plist>
|
|
171
|
+
`;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Create and write plist file
|
|
175
|
+
*/
|
|
176
|
+
async createPlist(config) {
|
|
177
|
+
const plistContent = this.generatePlist(config);
|
|
178
|
+
await (0, file_utils_1.writeFileAtomic)(config.plistPath, plistContent);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Delete plist file
|
|
182
|
+
*/
|
|
183
|
+
async deletePlist(config) {
|
|
184
|
+
if (await (0, file_utils_1.fileExists)(config.plistPath)) {
|
|
185
|
+
await fs.unlink(config.plistPath);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Load service (register with launchctl)
|
|
190
|
+
*/
|
|
191
|
+
async loadService(plistPath) {
|
|
192
|
+
await (0, process_utils_1.execCommand)(`launchctl load "${plistPath}"`);
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Unload service (unregister from launchctl)
|
|
196
|
+
*/
|
|
197
|
+
async unloadService(plistPath) {
|
|
198
|
+
try {
|
|
199
|
+
await (0, process_utils_1.execCommand)(`launchctl unload "${plistPath}"`);
|
|
200
|
+
}
|
|
201
|
+
catch (error) {
|
|
202
|
+
// Ignore errors if service is not loaded
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Start service
|
|
207
|
+
*/
|
|
208
|
+
async startService(label) {
|
|
209
|
+
await (0, process_utils_1.execCommand)(`launchctl start ${label}`);
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Stop service
|
|
213
|
+
*/
|
|
214
|
+
async stopService(label) {
|
|
215
|
+
await (0, process_utils_1.execCommand)(`launchctl stop ${label}`);
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Get service status from launchctl
|
|
219
|
+
*/
|
|
220
|
+
async getServiceStatus(label) {
|
|
221
|
+
try {
|
|
222
|
+
const { stdout } = await (0, process_utils_1.execAsync)(`launchctl list | grep ${label}`);
|
|
223
|
+
const lines = stdout.trim().split('\n');
|
|
224
|
+
for (const line of lines) {
|
|
225
|
+
const parts = line.split(/\s+/);
|
|
226
|
+
if (parts.length >= 3) {
|
|
227
|
+
const pidStr = parts[0].trim();
|
|
228
|
+
const exitCodeStr = parts[1].trim();
|
|
229
|
+
const serviceLabel = parts[2].trim();
|
|
230
|
+
if (serviceLabel === label) {
|
|
231
|
+
const pid = pidStr !== '-' ? parseInt(pidStr, 10) : null;
|
|
232
|
+
const exitCode = exitCodeStr !== '-' ? parseInt(exitCodeStr, 10) : null;
|
|
233
|
+
const isRunning = pid !== null;
|
|
234
|
+
return {
|
|
235
|
+
isRunning,
|
|
236
|
+
pid,
|
|
237
|
+
exitCode,
|
|
238
|
+
lastExitReason: this.interpretExitCode(exitCode),
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return {
|
|
244
|
+
isRunning: false,
|
|
245
|
+
pid: null,
|
|
246
|
+
exitCode: null,
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
catch (error) {
|
|
250
|
+
return {
|
|
251
|
+
isRunning: false,
|
|
252
|
+
pid: null,
|
|
253
|
+
exitCode: null,
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Interpret exit code to human-readable reason
|
|
259
|
+
*/
|
|
260
|
+
interpretExitCode(code) {
|
|
261
|
+
if (code === null || code === 0)
|
|
262
|
+
return undefined;
|
|
263
|
+
if (code === -9)
|
|
264
|
+
return 'Force killed (SIGKILL)';
|
|
265
|
+
if (code === -15)
|
|
266
|
+
return 'Terminated (SIGTERM)';
|
|
267
|
+
return `Exit code: ${code}`;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Wait for service to start (with timeout)
|
|
271
|
+
*/
|
|
272
|
+
async waitForServiceStart(label, timeoutMs = 5000) {
|
|
273
|
+
const startTime = Date.now();
|
|
274
|
+
while (Date.now() - startTime < timeoutMs) {
|
|
275
|
+
const status = await this.getServiceStatus(label);
|
|
276
|
+
if (status.isRunning) {
|
|
277
|
+
return true;
|
|
278
|
+
}
|
|
279
|
+
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
280
|
+
}
|
|
281
|
+
return false;
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Wait for service to stop (with timeout)
|
|
285
|
+
*/
|
|
286
|
+
async waitForServiceStop(label, timeoutMs = 5000) {
|
|
287
|
+
const startTime = Date.now();
|
|
288
|
+
while (Date.now() - startTime < timeoutMs) {
|
|
289
|
+
const status = await this.getServiceStatus(label);
|
|
290
|
+
if (!status.isRunning) {
|
|
291
|
+
return true;
|
|
292
|
+
}
|
|
293
|
+
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
294
|
+
}
|
|
295
|
+
return false;
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Start router service
|
|
299
|
+
*/
|
|
300
|
+
async start() {
|
|
301
|
+
await this.initialize();
|
|
302
|
+
let config = await this.loadConfig();
|
|
303
|
+
if (!config) {
|
|
304
|
+
// Create default config
|
|
305
|
+
config = this.getDefaultConfig();
|
|
306
|
+
await this.saveConfig(config);
|
|
307
|
+
}
|
|
308
|
+
// Check if already running
|
|
309
|
+
if (config.status === 'running') {
|
|
310
|
+
throw new Error('Router is already running');
|
|
311
|
+
}
|
|
312
|
+
// Check for throttled state (exit code 78)
|
|
313
|
+
const currentStatus = await this.getServiceStatus(config.label);
|
|
314
|
+
if (currentStatus.exitCode === 78) {
|
|
315
|
+
// Service is throttled - clean up and start fresh
|
|
316
|
+
await this.unloadService(config.plistPath);
|
|
317
|
+
await this.deletePlist(config);
|
|
318
|
+
// Give launchd a moment to clean up
|
|
319
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
320
|
+
}
|
|
321
|
+
// Create plist
|
|
322
|
+
await this.createPlist(config);
|
|
323
|
+
// Load and start service
|
|
324
|
+
try {
|
|
325
|
+
await this.loadService(config.plistPath);
|
|
326
|
+
}
|
|
327
|
+
catch (error) {
|
|
328
|
+
// May already be loaded
|
|
329
|
+
}
|
|
330
|
+
await this.startService(config.label);
|
|
331
|
+
// Wait for startup
|
|
332
|
+
const started = await this.waitForServiceStart(config.label, 5000);
|
|
333
|
+
if (!started) {
|
|
334
|
+
throw new Error('Router failed to start');
|
|
335
|
+
}
|
|
336
|
+
// Update config
|
|
337
|
+
const status = await this.getServiceStatus(config.label);
|
|
338
|
+
await this.updateConfig({
|
|
339
|
+
status: 'running',
|
|
340
|
+
pid: status.pid || undefined,
|
|
341
|
+
lastStarted: new Date().toISOString(),
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Stop router service
|
|
346
|
+
*/
|
|
347
|
+
async stop() {
|
|
348
|
+
const config = await this.loadConfig();
|
|
349
|
+
if (!config) {
|
|
350
|
+
throw new Error('Router configuration not found');
|
|
351
|
+
}
|
|
352
|
+
if (config.status !== 'running') {
|
|
353
|
+
throw new Error('Router is not running');
|
|
354
|
+
}
|
|
355
|
+
// Unload service
|
|
356
|
+
await this.unloadService(config.plistPath);
|
|
357
|
+
// Wait for shutdown
|
|
358
|
+
await this.waitForServiceStop(config.label, 5000);
|
|
359
|
+
// Update config
|
|
360
|
+
await this.updateConfig({
|
|
361
|
+
status: 'stopped',
|
|
362
|
+
pid: undefined,
|
|
363
|
+
lastStopped: new Date().toISOString(),
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Restart router service
|
|
368
|
+
*/
|
|
369
|
+
async restart() {
|
|
370
|
+
try {
|
|
371
|
+
await this.stop();
|
|
372
|
+
}
|
|
373
|
+
catch (error) {
|
|
374
|
+
// May not be running
|
|
375
|
+
}
|
|
376
|
+
await this.start();
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* Get router status
|
|
380
|
+
*/
|
|
381
|
+
async getStatus() {
|
|
382
|
+
const config = await this.loadConfig();
|
|
383
|
+
if (!config) {
|
|
384
|
+
return null;
|
|
385
|
+
}
|
|
386
|
+
const status = await this.getServiceStatus(config.label);
|
|
387
|
+
return { config, status };
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
exports.RouterManager = RouterManager;
|
|
391
|
+
// Export singleton instance
|
|
392
|
+
exports.routerManager = new RouterManager();
|
|
393
|
+
//# sourceMappingURL=router-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router-manager.js","sourceRoot":"","sources":["../../src/lib/router-manager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA6B;AAC7B,gDAAkC;AAElC,0DAAgE;AAChE,oDAS6B;AAS7B,MAAa,aAAa;IAMxB;QACE,IAAI,CAAC,SAAS,GAAG,IAAA,yBAAY,GAAE,CAAC;QAChC,IAAI,CAAC,OAAO,GAAG,IAAA,uBAAU,GAAE,CAAC;QAC5B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;QAC3D,IAAI,CAAC,eAAe,GAAG,IAAA,+BAAkB,GAAE,CAAC;IAC9C,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,UAAU;QACd,MAAM,IAAA,sBAAS,EAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAChC,MAAM,IAAA,sBAAS,EAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC9B,MAAM,IAAA,sBAAS,EAAC,IAAI,CAAC,eAAe,CAAC,CAAC;IACxC,CAAC;IAED;;OAEG;IACH,gBAAgB;QACd,OAAO;YACL,EAAE,EAAE,QAAQ;YACZ,IAAI,EAAE,IAAI;YACV,IAAI,EAAE,WAAW;YACjB,KAAK,EAAE,kBAAkB;YACzB,SAAS,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,wBAAwB,CAAC;YACpE,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,eAAe,CAAC;YACpD,UAAU,EAAE,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CAAC;IAC5B,CAAC;CACF;AAnYD,sCAmYC;AAED,4BAA4B;AACf,QAAA,aAAa,GAAG,IAAI,aAAa,EAAE,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Router HTTP server - proxies requests to backend llama.cpp servers
|
|
4
|
+
*/
|
|
5
|
+
declare class RouterServer {
|
|
6
|
+
private config;
|
|
7
|
+
private server;
|
|
8
|
+
initialize(): Promise<void>;
|
|
9
|
+
start(): Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* Main request handler
|
|
12
|
+
*/
|
|
13
|
+
private handleRequest;
|
|
14
|
+
/**
|
|
15
|
+
* Health check endpoint
|
|
16
|
+
*/
|
|
17
|
+
private handleHealth;
|
|
18
|
+
/**
|
|
19
|
+
* List models endpoint - aggregate from all running servers
|
|
20
|
+
*/
|
|
21
|
+
private handleModels;
|
|
22
|
+
/**
|
|
23
|
+
* Chat completions endpoint - route to backend server
|
|
24
|
+
*/
|
|
25
|
+
private handleChatCompletions;
|
|
26
|
+
/**
|
|
27
|
+
* Embeddings endpoint - route to backend server
|
|
28
|
+
*/
|
|
29
|
+
private handleEmbeddings;
|
|
30
|
+
/**
|
|
31
|
+
* Proxy a request to a backend server
|
|
32
|
+
*/
|
|
33
|
+
private proxyRequest;
|
|
34
|
+
/**
|
|
35
|
+
* Read request body as string
|
|
36
|
+
*/
|
|
37
|
+
private readBody;
|
|
38
|
+
/**
|
|
39
|
+
* Send error response
|
|
40
|
+
*/
|
|
41
|
+
private sendError;
|
|
42
|
+
/**
|
|
43
|
+
* Get all server configurations
|
|
44
|
+
*/
|
|
45
|
+
private getAllServers;
|
|
46
|
+
/**
|
|
47
|
+
* Find a server by model name
|
|
48
|
+
*/
|
|
49
|
+
private findServerForModel;
|
|
50
|
+
}
|
|
51
|
+
export { RouterServer };
|
|
52
|
+
//# sourceMappingURL=router-server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router-server.d.ts","sourceRoot":"","sources":["../../src/lib/router-server.ts"],"names":[],"mappings":";AA4BA;;GAEG;AACH,cAAM,YAAY;IAChB,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,MAAM,CAAe;IAEvB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IA+B3B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAS5B;;OAEG;YACW,aAAa;IAmC3B;;OAEG;YACW,YAAY;IAS1B;;OAEG;YACW,YAAY;IAoB1B;;OAEG;YACW,qBAAqB;IAmCnC;;OAEG;YACW,gBAAgB;IAyC9B;;OAEG;YACW,YAAY;IA4D1B;;OAEG;YACW,QAAQ;IAStB;;OAEG;IACH,OAAO,CAAC,SAAS;IAUjB;;OAEG;YACW,aAAa;IAwB3B;;OAEG;YACW,kBAAkB;CAwCjC;AAkBD,OAAO,EAAE,YAAY,EAAE,CAAC"}
|