@loghead/core 0.1.3 ā 0.1.5
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_main.js +8 -1
- package/dist/services/auth.js +15 -0
- package/package.json +2 -1
- package/src/cli_main.ts +10 -1
- package/src/services/auth.ts +19 -0
package/dist/cli_main.js
CHANGED
|
@@ -11,7 +11,10 @@ const server_1 = require("./api/server");
|
|
|
11
11
|
const migrate_1 = require("./db/migrate");
|
|
12
12
|
// import { ensureInfrastructure } from "./utils/startup"; // Might need adjustment
|
|
13
13
|
const main_1 = require("./ui/main");
|
|
14
|
+
const auth_1 = require("./services/auth");
|
|
15
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
14
16
|
const db = new db_1.DbService();
|
|
17
|
+
const auth = new auth_1.AuthService();
|
|
15
18
|
async function main() {
|
|
16
19
|
const argv = await (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
|
|
17
20
|
.command("init", "Initialize/Migrate database", {}, async () => {
|
|
@@ -19,7 +22,11 @@ async function main() {
|
|
|
19
22
|
await (0, migrate_1.migrate)();
|
|
20
23
|
})
|
|
21
24
|
.command("start", "Start API Server", {}, async () => {
|
|
22
|
-
|
|
25
|
+
console.log("Ensuring database is initialized...");
|
|
26
|
+
await (0, migrate_1.migrate)(false); // Run migrations silently
|
|
27
|
+
const token = await auth.getOrCreateMcpToken();
|
|
28
|
+
console.log(chalk_1.default.bold.yellow(`\nš MCP Server Token: ${token}`));
|
|
29
|
+
console.log(chalk_1.default.dim("Use this token for the MCP Server or other admin integrations.\n"));
|
|
23
30
|
await (0, server_1.startApiServer)(db);
|
|
24
31
|
})
|
|
25
32
|
.command("ui", "Start Terminal UI", {}, async () => {
|
package/dist/services/auth.js
CHANGED
|
@@ -22,6 +22,21 @@ class AuthService {
|
|
|
22
22
|
}
|
|
23
23
|
this.secretKey = rawSecret;
|
|
24
24
|
}
|
|
25
|
+
async getOrCreateMcpToken() {
|
|
26
|
+
await this.initialize();
|
|
27
|
+
if (!this.secretKey)
|
|
28
|
+
throw new Error("Auth not initialized");
|
|
29
|
+
// Check if token exists in DB
|
|
30
|
+
const row = client_1.db.prepare("SELECT value FROM system_config WHERE key = 'mcp_token'").get();
|
|
31
|
+
if (row?.value) {
|
|
32
|
+
return row.value;
|
|
33
|
+
}
|
|
34
|
+
// Create new token
|
|
35
|
+
// A system token that has access to everything (conceptually)
|
|
36
|
+
const token = jsonwebtoken_1.default.sign({ sub: "system:mcp", iss: "loghead", role: "admin" }, this.secretKey, { algorithm: "HS512" });
|
|
37
|
+
client_1.db.prepare("INSERT INTO system_config (key, value) VALUES ('mcp_token', ?)").run(token);
|
|
38
|
+
return token;
|
|
39
|
+
}
|
|
25
40
|
async createStreamToken(streamId) {
|
|
26
41
|
await this.initialize();
|
|
27
42
|
if (!this.secretKey)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loghead/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "Core API and Database for Loghead",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"better-sqlite3": "^9.4.0",
|
|
18
|
+
"sqlite-vec": "^0.1.0",
|
|
18
19
|
"express": "^4.18.2",
|
|
19
20
|
"cors": "^2.8.5",
|
|
20
21
|
"dotenv": "^16.4.1",
|
package/src/cli_main.ts
CHANGED
|
@@ -6,8 +6,11 @@ import { startApiServer } from "./api/server";
|
|
|
6
6
|
import { migrate } from "./db/migrate";
|
|
7
7
|
// import { ensureInfrastructure } from "./utils/startup"; // Might need adjustment
|
|
8
8
|
import { startTui } from "./ui/main";
|
|
9
|
+
import { AuthService } from "./services/auth";
|
|
10
|
+
import chalk from "chalk";
|
|
9
11
|
|
|
10
12
|
const db = new DbService();
|
|
13
|
+
const auth = new AuthService();
|
|
11
14
|
|
|
12
15
|
async function main() {
|
|
13
16
|
const argv = await yargs(hideBin(process.argv))
|
|
@@ -16,7 +19,13 @@ async function main() {
|
|
|
16
19
|
await migrate();
|
|
17
20
|
})
|
|
18
21
|
.command("start", "Start API Server", {}, async () => {
|
|
19
|
-
|
|
22
|
+
console.log("Ensuring database is initialized...");
|
|
23
|
+
await migrate(false); // Run migrations silently
|
|
24
|
+
|
|
25
|
+
const token = await auth.getOrCreateMcpToken();
|
|
26
|
+
console.log(chalk.bold.yellow(`\nš MCP Server Token: ${token}`));
|
|
27
|
+
console.log(chalk.dim("Use this token for the MCP Server or other admin integrations.\n"));
|
|
28
|
+
|
|
20
29
|
await startApiServer(db);
|
|
21
30
|
})
|
|
22
31
|
.command("ui", "Start Terminal UI", {}, async () => {
|
package/src/services/auth.ts
CHANGED
|
@@ -26,6 +26,25 @@ export class AuthService {
|
|
|
26
26
|
this.secretKey = rawSecret;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
async getOrCreateMcpToken(): Promise<string> {
|
|
30
|
+
await this.initialize();
|
|
31
|
+
if (!this.secretKey) throw new Error("Auth not initialized");
|
|
32
|
+
|
|
33
|
+
// Check if token exists in DB
|
|
34
|
+
const row = (db.prepare("SELECT value FROM system_config WHERE key = 'mcp_token'") as unknown as DbAny).get();
|
|
35
|
+
if (row?.value) {
|
|
36
|
+
return row.value;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Create new token
|
|
40
|
+
// A system token that has access to everything (conceptually)
|
|
41
|
+
const token = jwt.sign({ sub: "system:mcp", iss: "loghead", role: "admin" }, this.secretKey, { algorithm: "HS512" });
|
|
42
|
+
|
|
43
|
+
(db.prepare("INSERT INTO system_config (key, value) VALUES ('mcp_token', ?)") as unknown as DbAny).run(token);
|
|
44
|
+
|
|
45
|
+
return token;
|
|
46
|
+
}
|
|
47
|
+
|
|
29
48
|
async createStreamToken(streamId: string): Promise<string> {
|
|
30
49
|
await this.initialize();
|
|
31
50
|
if (!this.secretKey) throw new Error("Auth not initialized");
|