@loghead/core 0.1.6 → 0.1.8

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.
@@ -15,7 +15,8 @@ async function startApiServer(db) {
15
15
  app.use((0, cors_1.default)());
16
16
  app.use(express_1.default.json());
17
17
  await auth.initialize();
18
- console.log(chalk_1.default.bold.green(`āœ” Loghead Core API Server running on http://localhost:${port}`));
18
+ console.log(chalk_1.default.bold.green(`šŸ’» Server running on:\n`));
19
+ console.log(chalk_1.default.green(`http://localhost:${port}`));
19
20
  app.post("/api/ingest", async (req, res) => {
20
21
  try {
21
22
  const authHeader = req.headers.authorization;
@@ -61,8 +62,16 @@ async function startApiServer(db) {
61
62
  res.json(projects);
62
63
  });
63
64
  app.post("/api/projects", (req, res) => {
64
- const projects = db.listProjects();
65
- res.json(projects);
65
+ const { name } = req.body;
66
+ if (!name)
67
+ return res.status(400).json({ error: "Name required" });
68
+ const project = db.createProject(name);
69
+ res.json(project);
70
+ });
71
+ app.delete("/api/projects/:id", (req, res) => {
72
+ const { id } = req.params;
73
+ db.deleteProject(id);
74
+ res.json({ success: true });
66
75
  });
67
76
  app.get("/api/streams", (req, res) => {
68
77
  const projectId = req.query.projectId;
@@ -74,7 +83,17 @@ async function startApiServer(db) {
74
83
  res.status(400).send("Missing projectId");
75
84
  }
76
85
  });
86
+ app.delete("/api/streams/:id", (req, res) => {
87
+ const { id } = req.params;
88
+ db.deleteStream(id);
89
+ res.json({ success: true });
90
+ });
77
91
  app.post("/api/streams", (req, res) => {
92
+ // Deprecated or just listing? The previous code had this returning listStreams for POST?
93
+ // I'll remove it or keep it if CLI uses it?
94
+ // CLI uses db directly.
95
+ // MCP uses GET /api/streams
96
+ // I'll replace this with the actual CREATE logic to be RESTful, or keep /create
78
97
  const projectId = req.body.projectId;
79
98
  if (projectId) {
80
99
  const streams = db.listStreams(projectId);
@@ -86,7 +105,7 @@ async function startApiServer(db) {
86
105
  });
87
106
  app.post("/api/streams/create", async (req, res) => {
88
107
  const body = req.body;
89
- const stream = await db.createStream(body.projectId, body.type, body.name, {});
108
+ const stream = await db.createStream(body.projectId, body.type, body.name, body.config || {});
90
109
  res.json(stream);
91
110
  });
92
111
  app.get("/api/logs", async (req, res) => {
package/dist/cli_main.js CHANGED
@@ -25,8 +25,9 @@ async function main() {
25
25
  console.log("Ensuring database is initialized...");
26
26
  await (0, migrate_1.migrate)(false); // Run migrations silently
27
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"));
28
+ console.log(chalk_1.default.bold.yellow(`\nšŸ”‘ MCP Server Token:`));
29
+ console.log(chalk_1.default.dim("\nUse this token for the MCP Server or other admin integrations.\n"));
30
+ console.log(chalk_1.default.yellow(`${token}`));
30
31
  await (0, server_1.startApiServer)(db);
31
32
  })
32
33
  .command("ui", "Start Terminal UI", {}, async () => {
@@ -21,10 +21,8 @@ class DbService {
21
21
  return true;
22
22
  }
23
23
  listProjects() {
24
- console.error("Listing projects...");
25
24
  try {
26
25
  const projects = client_1.db.prepare("SELECT * FROM projects ORDER BY created_at DESC").all();
27
- console.error(`Found ${projects.length} projects.`);
28
26
  return projects.map((p) => {
29
27
  const streams = client_1.db.prepare("SELECT * FROM data_streams WHERE project_id = ?").all(p.id);
30
28
  return { ...p, streams };
@@ -81,12 +79,15 @@ class DbService {
81
79
  // Manual Transaction
82
80
  const insertTx = client_1.db.transaction(() => {
83
81
  // 1. Insert into logs
84
- client_1.db.prepare("INSERT INTO logs (id, stream_id, content, metadata) VALUES (?, ?, ?, ?)").run(id, streamId, content, metadataStr);
85
- // 2. Get rowid
86
- const rowInfo = client_1.db.prepare("SELECT last_insert_rowid() as rowid").get();
87
- const rowid = rowInfo.rowid;
82
+ const info = client_1.db.prepare("INSERT INTO logs (id, stream_id, content, metadata) VALUES (?, ?, ?, ?)").run(id, streamId, content, metadataStr);
83
+ // 2. Get rowid directly
84
+ const rowid = info.lastInsertRowid;
88
85
  // 3. Insert into vec_logs if embedding exists
89
86
  if (embedding && embedding.length > 0) {
87
+ if (embedding.length !== 1024) {
88
+ console.warn(`[Warning] Embedding dimension mismatch. Expected 1024, got ${embedding.length}. Skipping vector index.`);
89
+ return;
90
+ }
90
91
  const vectorJson = JSON.stringify(embedding);
91
92
  client_1.db.prepare("INSERT INTO vec_logs(rowid, embedding) VALUES (?, ?)").run(rowid, vectorJson);
92
93
  }
package/package.json CHANGED
@@ -1,14 +1,17 @@
1
1
  {
2
2
  "name": "@loghead/core",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "Core API and Database for Loghead",
5
5
  "repository": {
6
6
  "type": "git",
7
- "url": "git+https://github.com/onvo-ai/loggerhead.git"
7
+ "url": "git+https://github.com/onvo-ai/loghead.git"
8
8
  },
9
- "homepage": "https://github.com/onvo-ai/loggerhead#readme",
9
+ "homepage": "https://github.com/onvo-ai/loghead#readme",
10
10
  "bugs": {
11
- "url": "https://github.com/onvo-ai/loggerhead/issues"
11
+ "url": "https://github.com/onvo-ai/loghead/issues"
12
+ },
13
+ "publishConfig": {
14
+ "registry": "https://npm.pkg.github.com"
12
15
  },
13
16
  "main": "dist/index.js",
14
17
  "bin": {
package/src/api/server.ts CHANGED
@@ -15,7 +15,8 @@ export async function startApiServer(db: DbService) {
15
15
 
16
16
  await auth.initialize();
17
17
 
18
- console.log(chalk.bold.green(`āœ” Loghead Core API Server running on http://localhost:${port}`));
18
+ console.log(chalk.bold.green(`šŸ’» Server running on:\n`));
19
+ console.log(chalk.green(`http://localhost:${port}`));
19
20
 
20
21
  app.post("/api/ingest", async (req, res) => {
21
22
  try {
@@ -70,8 +71,16 @@ export async function startApiServer(db: DbService) {
70
71
  });
71
72
 
72
73
  app.post("/api/projects", (req, res) => {
73
- const projects = db.listProjects();
74
- res.json(projects);
74
+ const { name } = req.body;
75
+ if (!name) return res.status(400).json({ error: "Name required" });
76
+ const project = db.createProject(name);
77
+ res.json(project);
78
+ });
79
+
80
+ app.delete("/api/projects/:id", (req, res) => {
81
+ const { id } = req.params;
82
+ db.deleteProject(id);
83
+ res.json({ success: true });
75
84
  });
76
85
 
77
86
  app.get("/api/streams", (req, res) => {
@@ -84,7 +93,18 @@ export async function startApiServer(db: DbService) {
84
93
  }
85
94
  });
86
95
 
96
+ app.delete("/api/streams/:id", (req, res) => {
97
+ const { id } = req.params;
98
+ db.deleteStream(id);
99
+ res.json({ success: true });
100
+ });
101
+
87
102
  app.post("/api/streams", (req, res) => {
103
+ // Deprecated or just listing? The previous code had this returning listStreams for POST?
104
+ // I'll remove it or keep it if CLI uses it?
105
+ // CLI uses db directly.
106
+ // MCP uses GET /api/streams
107
+ // I'll replace this with the actual CREATE logic to be RESTful, or keep /create
88
108
  const projectId = req.body.projectId;
89
109
  if (projectId) {
90
110
  const streams = db.listStreams(projectId);
@@ -96,7 +116,7 @@ export async function startApiServer(db: DbService) {
96
116
 
97
117
  app.post("/api/streams/create", async (req, res) => {
98
118
  const body = req.body;
99
- const stream = await db.createStream(body.projectId, body.type, body.name, {});
119
+ const stream = await db.createStream(body.projectId, body.type, body.name, body.config || {});
100
120
  res.json(stream);
101
121
  });
102
122
 
package/src/cli_main.ts CHANGED
@@ -23,8 +23,9 @@ async function main() {
23
23
  await migrate(false); // Run migrations silently
24
24
 
25
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"));
26
+ console.log(chalk.bold.yellow(`\nšŸ”‘ MCP Server Token:`));
27
+ console.log(chalk.dim("\nUse this token for the MCP Server or other admin integrations.\n"));
28
+ console.log(chalk.yellow(`${token}`));
28
29
 
29
30
  await startApiServer(db);
30
31
  })
@@ -28,10 +28,8 @@ export class DbService {
28
28
  }
29
29
 
30
30
  listProjects(): Project[] {
31
- console.error("Listing projects...");
32
31
  try {
33
32
  const projects = (db.prepare("SELECT * FROM projects ORDER BY created_at DESC") as unknown as DbAny).all();
34
- console.error(`Found ${projects.length} projects.`);
35
33
  return projects.map((p: Project) => {
36
34
  const streams = (db.prepare("SELECT * FROM data_streams WHERE project_id = ?") as unknown as DbAny).all(p.id);
37
35
  return { ...p, streams };
@@ -90,16 +88,19 @@ export class DbService {
90
88
  // Manual Transaction
91
89
  const insertTx = db.transaction(() => {
92
90
  // 1. Insert into logs
93
- (db.prepare("INSERT INTO logs (id, stream_id, content, metadata) VALUES (?, ?, ?, ?)") as unknown as DbAny).run(
91
+ const info = (db.prepare("INSERT INTO logs (id, stream_id, content, metadata) VALUES (?, ?, ?, ?)") as unknown as DbAny).run(
94
92
  id, streamId, content, metadataStr
95
93
  );
96
94
 
97
- // 2. Get rowid
98
- const rowInfo = (db.prepare("SELECT last_insert_rowid() as rowid") as unknown as DbAny).get();
99
- const rowid = rowInfo.rowid;
95
+ // 2. Get rowid directly
96
+ const rowid = info.lastInsertRowid;
100
97
 
101
98
  // 3. Insert into vec_logs if embedding exists
102
99
  if (embedding && embedding.length > 0) {
100
+ if (embedding.length !== 1024) {
101
+ console.warn(`[Warning] Embedding dimension mismatch. Expected 1024, got ${embedding.length}. Skipping vector index.`);
102
+ return;
103
+ }
103
104
  const vectorJson = JSON.stringify(embedding);
104
105
  (db.prepare("INSERT INTO vec_logs(rowid, embedding) VALUES (?, ?)") as unknown as DbAny).run(rowid, vectorJson);
105
106
  }