@nxuss/lemma 0.4.0 ā 0.4.1
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/cjs/api/server.js +1 -1
- package/dist/cjs/cli/stack.d.ts +20 -0
- package/dist/cjs/cli/stack.d.ts.map +1 -0
- package/dist/cjs/cli/stack.js +76 -0
- package/dist/cjs/cli/stack.js.map +1 -0
- package/dist/esm/api/server.js +1 -1
- package/dist/esm/cli/stack.d.ts +20 -0
- package/dist/esm/cli/stack.d.ts.map +1 -0
- package/dist/esm/cli/stack.js +73 -0
- package/dist/esm/cli/stack.js.map +1 -0
- package/lemma-proxy.cjs +114 -16
- package/package.json +1 -1
package/dist/cjs/api/server.js
CHANGED
|
@@ -23,7 +23,7 @@ class DashboardAPIServer {
|
|
|
23
23
|
this.eventLog = [];
|
|
24
24
|
this.cacheStore = null;
|
|
25
25
|
this.server = null;
|
|
26
|
-
this.port = config.port ||
|
|
26
|
+
this.port = config.port || 8083;
|
|
27
27
|
this.host = config.host || '0.0.0.0';
|
|
28
28
|
this.app = (0, express_1.default)();
|
|
29
29
|
this.httpServer = http_1.default.createServer(this.app);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { WebSocketServer } from '../core/WebSocketServer';
|
|
2
|
+
import { OrchestrationEngine } from '../core/OrchestrationEngine';
|
|
3
|
+
import { SubconsciousEngine } from '../core/SubconsciousEngine';
|
|
4
|
+
import { DashboardAPIServer } from '../api/server';
|
|
5
|
+
/**
|
|
6
|
+
* Lemma Stack Orchestrator
|
|
7
|
+
* Starts the Router, Subconscious Engine, and Dashboard API
|
|
8
|
+
*/
|
|
9
|
+
export declare function startStack(options?: {
|
|
10
|
+
wsPort?: number;
|
|
11
|
+
apiPort?: number;
|
|
12
|
+
chromaUrl?: string;
|
|
13
|
+
ollamaUrl?: string;
|
|
14
|
+
}): Promise<{
|
|
15
|
+
wsServer: WebSocketServer;
|
|
16
|
+
subconsciousEngine: SubconsciousEngine;
|
|
17
|
+
orchestrationEngine: OrchestrationEngine;
|
|
18
|
+
dashboardAPIServer: DashboardAPIServer;
|
|
19
|
+
}>;
|
|
20
|
+
//# sourceMappingURL=stack.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stack.d.ts","sourceRoot":"","sources":["../../../src/cli/stack.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAEhE,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAGnD;;;GAGG;AACH,wBAAsB,UAAU,CAAC,OAAO,GAAE;IACxC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACf;;;;;GAiFL"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.startStack = startStack;
|
|
4
|
+
const WebSocketServer_1 = require("../core/WebSocketServer");
|
|
5
|
+
const OrchestrationEngine_1 = require("../core/OrchestrationEngine");
|
|
6
|
+
const SubconsciousEngine_1 = require("../core/SubconsciousEngine");
|
|
7
|
+
const DashboardBroadcaster_1 = require("../core/DashboardBroadcaster");
|
|
8
|
+
const server_1 = require("../api/server");
|
|
9
|
+
/**
|
|
10
|
+
* Lemma Stack Orchestrator
|
|
11
|
+
* Starts the Router, Subconscious Engine, and Dashboard API
|
|
12
|
+
*/
|
|
13
|
+
async function startStack(options = {}) {
|
|
14
|
+
const wsPort = options.wsPort || parseInt(process.env.WS_PORT || '8080');
|
|
15
|
+
const apiPort = options.apiPort || parseInt(process.env.DASHBOARD_API_PORT || '8083');
|
|
16
|
+
const chromaUrl = options.chromaUrl || process.env.CHROMA_URL || 'http://localhost:8000';
|
|
17
|
+
const ollamaUrl = options.ollamaUrl || process.env.OLLAMA_URL || 'http://localhost:11434';
|
|
18
|
+
console.log('š§ Starting Lemma Full Stack...');
|
|
19
|
+
console.log(` WebSocket Port: ${wsPort}`);
|
|
20
|
+
console.log(` Dashboard API: http://localhost:${apiPort}`);
|
|
21
|
+
console.log(` ChromaDB URL: ${chromaUrl}`);
|
|
22
|
+
console.log(` Ollama URL: ${ollamaUrl}\n`);
|
|
23
|
+
try {
|
|
24
|
+
// 1. Initialize WebSocket Server
|
|
25
|
+
const wsServer = new WebSocketServer_1.WebSocketServer({
|
|
26
|
+
port: wsPort,
|
|
27
|
+
heartbeatInterval: 30000,
|
|
28
|
+
connectionTimeout: 60000,
|
|
29
|
+
maxConnections: 100,
|
|
30
|
+
});
|
|
31
|
+
// 2. Initialize Subconscious Engine
|
|
32
|
+
const subconsciousEngine = new SubconsciousEngine_1.SubconsciousEngine();
|
|
33
|
+
// 3. Initialize Orchestration Engine
|
|
34
|
+
const orchestrationEngine = new OrchestrationEngine_1.OrchestrationEngine(wsServer, subconsciousEngine);
|
|
35
|
+
// 4. Initialize Dashboard Broadcaster
|
|
36
|
+
const dashboardBroadcaster = new DashboardBroadcaster_1.DashboardBroadcaster(wsServer, orchestrationEngine);
|
|
37
|
+
orchestrationEngine.setDashboardBroadcaster(dashboardBroadcaster);
|
|
38
|
+
// 5. Initialize Dashboard API Server
|
|
39
|
+
const dashboardAPIServer = new server_1.DashboardAPIServer({
|
|
40
|
+
port: apiPort,
|
|
41
|
+
});
|
|
42
|
+
// Start everything
|
|
43
|
+
await wsServer.start();
|
|
44
|
+
await subconsciousEngine.initialize();
|
|
45
|
+
dashboardAPIServer.setOrchestrationContext(orchestrationEngine, wsServer.getAgentRegistry?.() || { getAgents: () => [] }, subconsciousEngine);
|
|
46
|
+
await dashboardAPIServer.start();
|
|
47
|
+
dashboardBroadcaster.start(2000);
|
|
48
|
+
console.log('\nš Lemma Stack is ready!');
|
|
49
|
+
// Graceful shutdown
|
|
50
|
+
const shutdown = async () => {
|
|
51
|
+
console.log('\nš Shutting down Lemma Stack...');
|
|
52
|
+
dashboardBroadcaster.stop();
|
|
53
|
+
await dashboardAPIServer.stop();
|
|
54
|
+
await wsServer.stop();
|
|
55
|
+
await subconsciousEngine.shutdown();
|
|
56
|
+
process.exit(0);
|
|
57
|
+
};
|
|
58
|
+
process.on('SIGINT', shutdown);
|
|
59
|
+
process.on('SIGTERM', shutdown);
|
|
60
|
+
return {
|
|
61
|
+
wsServer,
|
|
62
|
+
subconsciousEngine,
|
|
63
|
+
orchestrationEngine,
|
|
64
|
+
dashboardAPIServer
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
console.error('ā Failed to start Lemma Stack:', error);
|
|
69
|
+
process.exit(1);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
// If run directly
|
|
73
|
+
if (require.main === module) {
|
|
74
|
+
startStack();
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=stack.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stack.js","sourceRoot":"","sources":["../../../src/cli/stack.ts"],"names":[],"mappings":";;AAWA,gCAsFC;AAjGD,6DAA0D;AAC1D,qEAAkE;AAClE,mEAAgE;AAChE,uEAAoE;AACpE,0CAAmD;AAGnD;;;GAGG;AACI,KAAK,UAAU,UAAU,CAAC,UAK7B,EAAE;IACJ,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,IAAI,MAAM,CAAC,CAAC;IACzE,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI,MAAM,CAAC,CAAC;IACtF,MAAM,SAAS,GAAG,OAAO,CAAC,SA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|
20
|
-
this.port = config.port ||
|
|
20
|
+
this.port = config.port || 8083;
|
|
21
21
|
this.host = config.host || '0.0.0.0';
|
|
22
22
|
this.app = express();
|
|
23
23
|
this.httpServer = http.createServer(this.app);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { WebSocketServer } from '../core/WebSocketServer';
|
|
2
|
+
import { OrchestrationEngine } from '../core/OrchestrationEngine';
|
|
3
|
+
import { SubconsciousEngine } from '../core/SubconsciousEngine';
|
|
4
|
+
import { DashboardAPIServer } from '../api/server';
|
|
5
|
+
/**
|
|
6
|
+
* Lemma Stack Orchestrator
|
|
7
|
+
* Starts the Router, Subconscious Engine, and Dashboard API
|
|
8
|
+
*/
|
|
9
|
+
export declare function startStack(options?: {
|
|
10
|
+
wsPort?: number;
|
|
11
|
+
apiPort?: number;
|
|
12
|
+
chromaUrl?: string;
|
|
13
|
+
ollamaUrl?: string;
|
|
14
|
+
}): Promise<{
|
|
15
|
+
wsServer: WebSocketServer;
|
|
16
|
+
subconsciousEngine: SubconsciousEngine;
|
|
17
|
+
orchestrationEngine: OrchestrationEngine;
|
|
18
|
+
dashboardAPIServer: DashboardAPIServer;
|
|
19
|
+
}>;
|
|
20
|
+
//# sourceMappingURL=stack.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stack.d.ts","sourceRoot":"","sources":["../../../src/cli/stack.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAEhE,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAGnD;;;GAGG;AACH,wBAAsB,UAAU,CAAC,OAAO,GAAE;IACxC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACf;;;;;GAiFL"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { WebSocketServer } from '../core/WebSocketServer';
|
|
2
|
+
import { OrchestrationEngine } from '../core/OrchestrationEngine';
|
|
3
|
+
import { SubconsciousEngine } from '../core/SubconsciousEngine';
|
|
4
|
+
import { DashboardBroadcaster } from '../core/DashboardBroadcaster';
|
|
5
|
+
import { DashboardAPIServer } from '../api/server';
|
|
6
|
+
/**
|
|
7
|
+
* Lemma Stack Orchestrator
|
|
8
|
+
* Starts the Router, Subconscious Engine, and Dashboard API
|
|
9
|
+
*/
|
|
10
|
+
export async function startStack(options = {}) {
|
|
11
|
+
const wsPort = options.wsPort || parseInt(process.env.WS_PORT || '8080');
|
|
12
|
+
const apiPort = options.apiPort || parseInt(process.env.DASHBOARD_API_PORT || '8083');
|
|
13
|
+
const chromaUrl = options.chromaUrl || process.env.CHROMA_URL || 'http://localhost:8000';
|
|
14
|
+
const ollamaUrl = options.ollamaUrl || process.env.OLLAMA_URL || 'http://localhost:11434';
|
|
15
|
+
console.log('š§ Starting Lemma Full Stack...');
|
|
16
|
+
console.log(` WebSocket Port: ${wsPort}`);
|
|
17
|
+
console.log(` Dashboard API: http://localhost:${apiPort}`);
|
|
18
|
+
console.log(` ChromaDB URL: ${chromaUrl}`);
|
|
19
|
+
console.log(` Ollama URL: ${ollamaUrl}\n`);
|
|
20
|
+
try {
|
|
21
|
+
// 1. Initialize WebSocket Server
|
|
22
|
+
const wsServer = new WebSocketServer({
|
|
23
|
+
port: wsPort,
|
|
24
|
+
heartbeatInterval: 30000,
|
|
25
|
+
connectionTimeout: 60000,
|
|
26
|
+
maxConnections: 100,
|
|
27
|
+
});
|
|
28
|
+
// 2. Initialize Subconscious Engine
|
|
29
|
+
const subconsciousEngine = new SubconsciousEngine();
|
|
30
|
+
// 3. Initialize Orchestration Engine
|
|
31
|
+
const orchestrationEngine = new OrchestrationEngine(wsServer, subconsciousEngine);
|
|
32
|
+
// 4. Initialize Dashboard Broadcaster
|
|
33
|
+
const dashboardBroadcaster = new DashboardBroadcaster(wsServer, orchestrationEngine);
|
|
34
|
+
orchestrationEngine.setDashboardBroadcaster(dashboardBroadcaster);
|
|
35
|
+
// 5. Initialize Dashboard API Server
|
|
36
|
+
const dashboardAPIServer = new DashboardAPIServer({
|
|
37
|
+
port: apiPort,
|
|
38
|
+
});
|
|
39
|
+
// Start everything
|
|
40
|
+
await wsServer.start();
|
|
41
|
+
await subconsciousEngine.initialize();
|
|
42
|
+
dashboardAPIServer.setOrchestrationContext(orchestrationEngine, wsServer.getAgentRegistry?.() || { getAgents: () => [] }, subconsciousEngine);
|
|
43
|
+
await dashboardAPIServer.start();
|
|
44
|
+
dashboardBroadcaster.start(2000);
|
|
45
|
+
console.log('\nš Lemma Stack is ready!');
|
|
46
|
+
// Graceful shutdown
|
|
47
|
+
const shutdown = async () => {
|
|
48
|
+
console.log('\nš Shutting down Lemma Stack...');
|
|
49
|
+
dashboardBroadcaster.stop();
|
|
50
|
+
await dashboardAPIServer.stop();
|
|
51
|
+
await wsServer.stop();
|
|
52
|
+
await subconsciousEngine.shutdown();
|
|
53
|
+
process.exit(0);
|
|
54
|
+
};
|
|
55
|
+
process.on('SIGINT', shutdown);
|
|
56
|
+
process.on('SIGTERM', shutdown);
|
|
57
|
+
return {
|
|
58
|
+
wsServer,
|
|
59
|
+
subconsciousEngine,
|
|
60
|
+
orchestrationEngine,
|
|
61
|
+
dashboardAPIServer
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
console.error('ā Failed to start Lemma Stack:', error);
|
|
66
|
+
process.exit(1);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
// If run directly
|
|
70
|
+
if (require.main === module) {
|
|
71
|
+
startStack();
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=stack.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1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,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC,CAAC;QAEF,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAC/B,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;QAEhC,OAAO;YACL,QAAQ;YACR,kBAAkB;YAClB,mBAAmB;YACnB,kBAAkB;SACnB,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,gCAAgC,EAAE,KAAK,CAAC,CAAC;QACvD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAED,kBAAkB;AAClB,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;IAC5B,UAAU,EAAE,CAAC;AACf,CAAC"}
|
package/lemma-proxy.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
'use strict';
|
|
3
3
|
/**
|
|
4
|
-
* Lemma Proxy v0.4.
|
|
4
|
+
* Lemma Proxy v0.4.1 ā Universal AI Cache CLI
|
|
5
5
|
* Commands: start, stop, stats, status, activate <key>
|
|
6
6
|
*/
|
|
7
7
|
|
|
@@ -467,14 +467,14 @@ class LemmaServer {
|
|
|
467
467
|
server.listen(this.port, () => {
|
|
468
468
|
fs.writeFileSync(PID_FILE, String(process.pid));
|
|
469
469
|
fs.writeFileSync(PORT_FILE, String(this.port));
|
|
470
|
-
console.log(`\nš Lemma Proxy v0.4.
|
|
470
|
+
console.log(`\nš Lemma Proxy v0.4.1\nš Project : ${this.projectName}\nš Port : ${this.port}\n`);
|
|
471
471
|
});
|
|
472
472
|
process.on('SIGTERM', () => server.close());
|
|
473
473
|
}
|
|
474
474
|
}
|
|
475
475
|
|
|
476
476
|
// āā CLI āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
|
|
477
|
-
program.name('lemma').description('Lemma Proxy CLI').version('0.4.
|
|
477
|
+
program.name('lemma').description('Lemma Proxy CLI ā Intelligent AI Gateway').version('0.4.1');
|
|
478
478
|
|
|
479
479
|
program.command('start')
|
|
480
480
|
.description('Start the proxy server')
|
|
@@ -494,15 +494,28 @@ program.command('start')
|
|
|
494
494
|
console.log(' ā
ChromaDB requested');
|
|
495
495
|
|
|
496
496
|
// 2. Start Dashboard
|
|
497
|
-
|
|
497
|
+
// Use port 8082 to avoid conflicts
|
|
498
|
+
const dash = spawn('npm', ['run', 'dev', '--prefix', 'dashboard', '--', '--port', '8082'], { stdio: 'ignore', detached: true });
|
|
498
499
|
dash.unref();
|
|
499
|
-
console.log(' ā
Dashboard requested (http://localhost:
|
|
500
|
+
console.log(' ā
Dashboard requested (http://localhost:8082)');
|
|
500
501
|
|
|
501
|
-
// 3. Start Router (
|
|
502
|
+
// 3. Start Router (using internal script)
|
|
502
503
|
console.log(' š Starting Router & Proxy...\n');
|
|
503
|
-
|
|
504
|
+
|
|
505
|
+
// Fallback for dev/package mode
|
|
506
|
+
const stackScript = fs.existsSync(path.join(__dirname, 'dist', 'cjs', 'cli', 'stack.js'))
|
|
507
|
+
? path.join(__dirname, 'dist', 'cjs', 'cli', 'stack.js')
|
|
508
|
+
: (fs.existsSync(path.join(__dirname, 'src', 'cli', 'stack.ts')) ? 'src/cli/stack.ts' : null);
|
|
509
|
+
|
|
510
|
+
if (!stackScript) {
|
|
511
|
+
console.error('ā Error: Could not find Lemma Stack script. Reinstall the package.');
|
|
512
|
+
process.exit(1);
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
const routerCmd = stackScript.endsWith('.ts') ? ['npx', 'tsx', stackScript] : ['node', stackScript];
|
|
516
|
+
const router = spawn(routerCmd[0], routerCmd.slice(1), {
|
|
504
517
|
stdio: 'inherit',
|
|
505
|
-
env: { ...process.env,
|
|
518
|
+
env: { ...process.env, WS_PORT: '8080', DASHBOARD_API_PORT: '8083' }
|
|
506
519
|
});
|
|
507
520
|
|
|
508
521
|
// Start Proxy Server alongside
|
|
@@ -519,13 +532,98 @@ program.command('start')
|
|
|
519
532
|
}
|
|
520
533
|
});
|
|
521
534
|
|
|
522
|
-
program.command('stop')
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
535
|
+
program.command('stop')
|
|
536
|
+
.description('Stop the proxy server')
|
|
537
|
+
.action(() => {
|
|
538
|
+
try {
|
|
539
|
+
if (fs.existsSync(PID_FILE)) {
|
|
540
|
+
const pid = fs.readFileSync(PID_FILE, 'utf8');
|
|
541
|
+
process.kill(parseInt(pid), 'SIGTERM');
|
|
542
|
+
console.log('ā
Stopped');
|
|
543
|
+
} else {
|
|
544
|
+
console.log('ā ļø No PID file found. Checking for processes...');
|
|
545
|
+
// Fallback for windows/mac: kill by port or name
|
|
546
|
+
}
|
|
547
|
+
} catch { console.log('ā ļø Could not stop process.'); }
|
|
548
|
+
if (fs.existsSync(PID_FILE)) fs.unlinkSync(PID_FILE);
|
|
549
|
+
});
|
|
550
|
+
|
|
551
|
+
program.command('status')
|
|
552
|
+
.description('Check proxy status')
|
|
553
|
+
.action(async () => {
|
|
554
|
+
const port = fs.existsSync(PORT_FILE) ? fs.readFileSync(PORT_FILE, 'utf8') : '8081';
|
|
555
|
+
try {
|
|
556
|
+
const resp = await axios.get(`http://localhost:${port}/health`, { timeout: 1000 });
|
|
557
|
+
if (resp.data && resp.data.status === 'ok') {
|
|
558
|
+
console.log(`ā
Running (Project: ${resp.data.project}, Port: ${port})`);
|
|
559
|
+
} else {
|
|
560
|
+
console.log('ā Stopped (Health check failed)');
|
|
561
|
+
}
|
|
562
|
+
} catch {
|
|
563
|
+
console.log('ā Stopped');
|
|
564
|
+
if (fs.existsSync(PID_FILE)) fs.unlinkSync(PID_FILE);
|
|
565
|
+
}
|
|
566
|
+
});
|
|
567
|
+
|
|
568
|
+
program.command('stats')
|
|
569
|
+
.description('Show usage statistics')
|
|
570
|
+
.action(() => {
|
|
571
|
+
const stats = loadStats();
|
|
572
|
+
const usage = loadUsage();
|
|
573
|
+
const project = detectProject();
|
|
574
|
+
const s = stats[project] || { total:0, hits:0, misses:0, totalLatency:0, totalTokensSaved:0 };
|
|
575
|
+
|
|
576
|
+
console.log(`\nš Lemma Stats for [${project}]`);
|
|
577
|
+
console.log(`āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā`);
|
|
578
|
+
console.log(`Total Requests : ${s.total}`);
|
|
579
|
+
console.log(`Cache Hits : ${s.hits} (${((s.hits/s.total||0)*100).toFixed(1)}%)`);
|
|
580
|
+
console.log(`Tokens Saved : ${s.totalTokensSaved.toLocaleString()}`);
|
|
581
|
+
console.log(`Avg Latency : ${(s.totalLatency/(s.total||1)).toFixed(2)}ms`);
|
|
582
|
+
console.log(`Tier : ${isPro() ? 'PRO' : 'FREE'}`);
|
|
583
|
+
if (!isPro()) console.log(`Free Usage : ${usage.count}/${FREE_LIMIT} requests`);
|
|
584
|
+
console.log(`āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā\n`);
|
|
585
|
+
});
|
|
586
|
+
|
|
587
|
+
program.command('activate <key>')
|
|
588
|
+
.description('Activate Pro features with a license key')
|
|
589
|
+
.action(async (key) => {
|
|
590
|
+
console.log('š Validating license key...');
|
|
591
|
+
try {
|
|
592
|
+
const res = await validateKeyRemote(key);
|
|
593
|
+
if (res.valid) {
|
|
594
|
+
writeJson(LICENSE_FILE, { key, isPro: true, activatedAt: new Date().toISOString() });
|
|
595
|
+
console.log('ā
License activated! Enjoy Pro features.');
|
|
596
|
+
} else {
|
|
597
|
+
console.log('ā Invalid license key.');
|
|
598
|
+
}
|
|
599
|
+
} catch (e) {
|
|
600
|
+
console.error('ā Error validating key:', e.message);
|
|
601
|
+
}
|
|
602
|
+
});
|
|
603
|
+
|
|
604
|
+
program.command('init')
|
|
605
|
+
.description('Initialize Lemma in the current project (auto-discovery)')
|
|
606
|
+
.action(() => {
|
|
607
|
+
const project = detectProject();
|
|
608
|
+
console.log(`š ļø Initializing Lemma for [${project}]...`);
|
|
609
|
+
|
|
610
|
+
const envFile = path.join(process.cwd(), '.env');
|
|
611
|
+
const lemmaConfig = `\n# Lemma AI Gateway Configuration\nOPENAI_BASE_URL=http://localhost:8081/v1\nLEMMA_PROJECT=${project}\n`;
|
|
612
|
+
|
|
613
|
+
if (fs.existsSync(envFile)) {
|
|
614
|
+
const content = fs.readFileSync(envFile, 'utf8');
|
|
615
|
+
if (content.includes('OPENAI_BASE_URL')) {
|
|
616
|
+
console.log('ā ļø OPENAI_BASE_URL already exists in .env. Please update it manually to: http://localhost:8081/v1');
|
|
617
|
+
} else {
|
|
618
|
+
fs.appendFileSync(envFile, lemmaConfig);
|
|
619
|
+
console.log('ā
Added Lemma configuration to .env');
|
|
620
|
+
}
|
|
621
|
+
} else {
|
|
622
|
+
fs.writeFileSync(envFile, lemmaConfig);
|
|
623
|
+
console.log('ā
Created .env with Lemma configuration');
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
console.log('\nš Done! Run "lemma start" to begin.');
|
|
627
|
+
});
|
|
530
628
|
|
|
531
629
|
program.parse(process.argv);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nxuss/lemma",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Intelligent AI Gateway ā Semantic cache, Privacy Firewall, and Autonomous Cost-Optimization for AI Agents.",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"module": "./dist/esm/index.js",
|