@loghead/core 0.1.1 → 0.1.3
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/build/loggerhead +0 -0
- package/build/npm/bin/loghead +0 -0
- package/build/npm/package.json +32 -0
- package/deno.lock +1003 -0
- package/dist/api/server.js +111 -0
- package/dist/cli_main.js +68 -0
- package/dist/db/client.js +53 -0
- package/dist/db/migrate.js +65 -0
- package/dist/services/auth.js +48 -0
- package/dist/services/db.js +157 -0
- package/dist/services/ollama.js +40 -0
- package/dist/types.js +2 -0
- package/dist/ui/main.js +71 -0
- package/dist/utils/startup.js +55 -0
- package/loggerhead.db +0 -0
- package/package.json +28 -24
- package/src/api/server.ts +123 -0
- package/src/cli_main.ts +66 -0
- package/src/db/client.ts +19 -0
- package/src/db/migrate.ts +67 -0
- package/src/services/auth.ts +50 -0
- package/src/services/db.ts +171 -0
- package/src/services/ollama.ts +39 -0
- package/src/tests/db.test.ts +63 -0
- package/src/types.ts +31 -0
- package/src/ui/main.ts +78 -0
- package/src/utils/startup.ts +52 -0
- package/tsconfig.json +15 -0
- /package/{bin → build}/loghead +0 -0
- /package/{README.md → build/npm/README.md} +0 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
|
|
2
|
+
export interface Project {
|
|
3
|
+
id: string;
|
|
4
|
+
name: string;
|
|
5
|
+
created_at?: string;
|
|
6
|
+
streams?: Stream[];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface Stream {
|
|
10
|
+
id: string;
|
|
11
|
+
project_id: string;
|
|
12
|
+
type: string;
|
|
13
|
+
name: string;
|
|
14
|
+
config: Record<string, unknown> | string;
|
|
15
|
+
created_at?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface Log {
|
|
19
|
+
id: string;
|
|
20
|
+
stream_id: string;
|
|
21
|
+
content: string;
|
|
22
|
+
timestamp: string;
|
|
23
|
+
metadata: Record<string, unknown> | string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface SearchResult {
|
|
27
|
+
content: string;
|
|
28
|
+
timestamp: string;
|
|
29
|
+
similarity?: number;
|
|
30
|
+
metadata?: Record<string, unknown>;
|
|
31
|
+
}
|
package/src/ui/main.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { DbService } from "../services/db";
|
|
2
|
+
import inquirer from "inquirer";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
|
|
5
|
+
export async function startTui(db: DbService) {
|
|
6
|
+
console.clear();
|
|
7
|
+
console.log(chalk.bold.blue("Loghead Dashboard\n"));
|
|
8
|
+
|
|
9
|
+
while (true) {
|
|
10
|
+
const projects = db.listProjects();
|
|
11
|
+
|
|
12
|
+
if (projects.length === 0) {
|
|
13
|
+
console.log("No projects found. Use 'npx loghead projects add <name>' to create one.");
|
|
14
|
+
break;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const projectChoices = projects.map(p => ({ name: p.name, value: p.id }));
|
|
18
|
+
projectChoices.push({ name: chalk.red("Exit"), value: "exit" });
|
|
19
|
+
|
|
20
|
+
const { projectId } = await inquirer.prompt([{
|
|
21
|
+
type: "list",
|
|
22
|
+
name: "projectId",
|
|
23
|
+
message: "Select a Project",
|
|
24
|
+
choices: projectChoices
|
|
25
|
+
}]);
|
|
26
|
+
|
|
27
|
+
if (projectId === "exit") break;
|
|
28
|
+
|
|
29
|
+
// List streams for project
|
|
30
|
+
while (true) {
|
|
31
|
+
console.clear();
|
|
32
|
+
const project = projects.find(p => p.id === projectId);
|
|
33
|
+
console.log(chalk.bold.blue(`Project: ${project?.name}\n`));
|
|
34
|
+
|
|
35
|
+
const streams = db.listStreams(projectId);
|
|
36
|
+
|
|
37
|
+
if (streams.length === 0) {
|
|
38
|
+
console.log("No streams found.");
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const streamChoices = streams.map(s => ({
|
|
42
|
+
name: `${s.name} (${s.type})`,
|
|
43
|
+
value: s.id
|
|
44
|
+
}));
|
|
45
|
+
streamChoices.push({ name: chalk.yellow("Back"), value: "back" });
|
|
46
|
+
|
|
47
|
+
const { streamId } = await inquirer.prompt([{
|
|
48
|
+
type: "list",
|
|
49
|
+
name: "streamId",
|
|
50
|
+
message: "Select a Stream to view logs",
|
|
51
|
+
choices: streamChoices
|
|
52
|
+
}]);
|
|
53
|
+
|
|
54
|
+
if (streamId === "back") break;
|
|
55
|
+
|
|
56
|
+
// Show logs (simple tail)
|
|
57
|
+
console.clear();
|
|
58
|
+
const stream = streams.find(s => s.id === streamId);
|
|
59
|
+
console.log(chalk.bold.green(`Logs for ${stream?.name}:\n`));
|
|
60
|
+
|
|
61
|
+
const logs = db.getRecentLogs(streamId, 20);
|
|
62
|
+
if (logs.length === 0) {
|
|
63
|
+
console.log("No logs recorded yet.");
|
|
64
|
+
} else {
|
|
65
|
+
// Reverse to show oldest to newest like a log file
|
|
66
|
+
[...logs].reverse().forEach(log => {
|
|
67
|
+
console.log(`${chalk.dim(log.timestamp)} ${log.content}`);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
console.log("\nPress Enter to return...");
|
|
72
|
+
await new Promise<void>(resolve => {
|
|
73
|
+
process.stdin.once('data', () => resolve());
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
console.clear();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import { OllamaService } from "../services/ollama";
|
|
3
|
+
import { migrate } from "../db/migrate";
|
|
4
|
+
|
|
5
|
+
export async function ensureInfrastructure() {
|
|
6
|
+
console.log(chalk.bold.blue("\n🚀Performing system preflight checks..."));
|
|
7
|
+
|
|
8
|
+
// 1. Check Local Ollama
|
|
9
|
+
await checkStep("Checking local Ollama...", async () => {
|
|
10
|
+
try {
|
|
11
|
+
// Node.js fetch needs global fetch or polyfill in Node 18+.
|
|
12
|
+
// Assuming Node 18+ which has fetch.
|
|
13
|
+
const response = await fetch("http://localhost:11434/api/tags");
|
|
14
|
+
if (!response.ok) throw new Error("Ollama is not running");
|
|
15
|
+
} catch {
|
|
16
|
+
throw new Error("Ollama is not accessible at http://localhost:11434. Please install and run Ollama.");
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// 2. Check Database & Migrations (SQLite)
|
|
21
|
+
await checkStep("Initializing database...", async () => {
|
|
22
|
+
try {
|
|
23
|
+
migrate(false);
|
|
24
|
+
} catch (e) {
|
|
25
|
+
console.log(chalk.yellow("\n ➤ Migration failed..."));
|
|
26
|
+
throw e;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// 3. Check Ollama Model
|
|
31
|
+
await checkStep("Checking embedding model (qwen3-embedding)...", async () => {
|
|
32
|
+
const ollama = new OllamaService();
|
|
33
|
+
await ollama.ensureModel();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
console.log(`${chalk.green("✔")} System preflight checks complete`);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async function checkStep(name: string, action: () => Promise<void>) {
|
|
40
|
+
// Print pending state
|
|
41
|
+
process.stdout.write(`${chalk.cyan("○")} ${name}`);
|
|
42
|
+
|
|
43
|
+
try {
|
|
44
|
+
await action();
|
|
45
|
+
// Clear line and print success
|
|
46
|
+
process.stdout.write(`\r${chalk.green("✔")} ${name} \n`);
|
|
47
|
+
} catch (e) {
|
|
48
|
+
process.stdout.write(`\r${chalk.red("✖")} ${name}\n`);
|
|
49
|
+
console.error(chalk.red(` Error: ${e instanceof Error ? e.message : e}`));
|
|
50
|
+
process.exit(1);
|
|
51
|
+
}
|
|
52
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "CommonJS",
|
|
5
|
+
"moduleResolution": "node",
|
|
6
|
+
"outDir": "./dist",
|
|
7
|
+
"rootDir": "./src",
|
|
8
|
+
"strict": true,
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"forceConsistentCasingInFileNames": true
|
|
12
|
+
},
|
|
13
|
+
"include": ["src/**/*"],
|
|
14
|
+
"exclude": ["node_modules", "**/*.test.ts"]
|
|
15
|
+
}
|
/package/{bin → build}/loghead
RENAMED
|
File without changes
|
|
File without changes
|