@loghead/core 0.1.23 → 0.1.26
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/api/server.js +24 -6
- package/dist/cli_main.js +2 -4
- package/dist/public/assets/index-BSfBUhxd.js +107 -0
- package/dist/public/assets/index-Zf0dAxdt.css +1 -0
- package/dist/public/index.html +2 -2
- package/package.json +4 -3
- package/dist/public/assets/index-CEQopy59.css +0 -1
- package/dist/public/assets/index-JSs_QfLO.js +0 -95
package/dist/api/server.js
CHANGED
|
@@ -23,6 +23,7 @@ async function startApiServer(db) {
|
|
|
23
23
|
publicPath = path_1.default.join(__dirname, "../../dist/public");
|
|
24
24
|
}
|
|
25
25
|
if (require("fs").existsSync(publicPath)) {
|
|
26
|
+
console.log(chalk_1.default.blue(`Serving frontend from: ${publicPath}`));
|
|
26
27
|
app.use(express_1.default.static(publicPath));
|
|
27
28
|
}
|
|
28
29
|
else {
|
|
@@ -58,24 +59,32 @@ async function startApiServer(db) {
|
|
|
58
59
|
}
|
|
59
60
|
return result;
|
|
60
61
|
};
|
|
61
|
-
// OTLP Logs Ingestion Endpoint
|
|
62
62
|
app.post("/v1/logs", async (req, res) => {
|
|
63
|
+
console.log(`[API] POST /v1/logs received`);
|
|
63
64
|
try {
|
|
64
65
|
const authHeader = req.headers.authorization;
|
|
65
66
|
if (!authHeader || !authHeader.startsWith("Bearer ")) {
|
|
67
|
+
console.warn("[API] /v1/logs Unauthorized: Missing token");
|
|
66
68
|
return res.status(401).json({ code: 16, message: "Unauthenticated" });
|
|
67
69
|
}
|
|
68
70
|
const token = authHeader.split(" ")[1];
|
|
69
71
|
const payload = await auth.verifyToken(token);
|
|
70
72
|
if (!payload || !payload.streamId) {
|
|
73
|
+
console.warn("[API] /v1/logs Unauthorized: Invalid token");
|
|
71
74
|
return res.status(401).json({ code: 16, message: "Invalid token" });
|
|
72
75
|
}
|
|
73
76
|
const streamId = payload.streamId;
|
|
77
|
+
console.log(`[API] Ingesting OTLP logs for stream: ${streamId}`);
|
|
74
78
|
const { resourceLogs } = req.body;
|
|
75
79
|
if (!resourceLogs || !Array.isArray(resourceLogs)) {
|
|
80
|
+
console.warn("[API] /v1/logs Invalid payload");
|
|
76
81
|
return res.status(400).json({ code: 3, message: "Invalid payload" });
|
|
77
82
|
}
|
|
83
|
+
// ... existing logic ...
|
|
78
84
|
let count = 0;
|
|
85
|
+
// ... loop ...
|
|
86
|
+
// (I will keep the existing loop logic but add a log at the end)
|
|
87
|
+
/* ... existing loop code ... */
|
|
79
88
|
for (const resourceLog of resourceLogs) {
|
|
80
89
|
const resourceAttrs = parseOtlpAttributes(resourceLog.resource?.attributes);
|
|
81
90
|
if (resourceLog.scopeLogs) {
|
|
@@ -108,6 +117,7 @@ async function startApiServer(db) {
|
|
|
108
117
|
}
|
|
109
118
|
}
|
|
110
119
|
}
|
|
120
|
+
console.log(`[API] /v1/logs Ingested ${count} logs`);
|
|
111
121
|
res.json({ partialSuccess: {}, logsIngested: count });
|
|
112
122
|
}
|
|
113
123
|
catch (e) {
|
|
@@ -116,24 +126,31 @@ async function startApiServer(db) {
|
|
|
116
126
|
}
|
|
117
127
|
});
|
|
118
128
|
app.post("/api/ingest", async (req, res) => {
|
|
129
|
+
console.log(`[API] POST /api/ingest received`);
|
|
119
130
|
try {
|
|
120
131
|
const authHeader = req.headers.authorization;
|
|
121
132
|
if (!authHeader || !authHeader.startsWith("Bearer ")) {
|
|
133
|
+
console.warn("[API] /api/ingest Unauthorized: Missing token");
|
|
122
134
|
return res.status(401).send("Unauthorized: Missing token");
|
|
123
135
|
}
|
|
124
136
|
const token = authHeader.split(" ")[1];
|
|
125
137
|
const payload = await auth.verifyToken(token);
|
|
126
138
|
if (!payload || !payload.streamId) {
|
|
139
|
+
console.warn("[API] /api/ingest Unauthorized: Invalid token");
|
|
127
140
|
return res.status(401).send("Unauthorized: Invalid token");
|
|
128
141
|
}
|
|
129
142
|
const { streamId, logs } = req.body;
|
|
143
|
+
console.log(`[API] Ingesting logs for stream: ${streamId}`);
|
|
130
144
|
if (streamId !== payload.streamId) {
|
|
145
|
+
console.warn(`[API] /api/ingest Forbidden: Token streamId ${payload.streamId} != body streamId ${streamId}`);
|
|
131
146
|
return res.status(403).send("Forbidden: Token does not match streamId");
|
|
132
147
|
}
|
|
133
148
|
if (!logs) {
|
|
149
|
+
console.warn("[API] /api/ingest Missing logs");
|
|
134
150
|
return res.status(400).send("Missing logs");
|
|
135
151
|
}
|
|
136
152
|
const logEntries = Array.isArray(logs) ? logs : [logs];
|
|
153
|
+
console.log(`[API] Processing ${logEntries.length} log entries`);
|
|
137
154
|
for (const log of logEntries) {
|
|
138
155
|
let content = "";
|
|
139
156
|
let metadata = {};
|
|
@@ -148,6 +165,7 @@ async function startApiServer(db) {
|
|
|
148
165
|
await db.addLog(streamId, content, metadata);
|
|
149
166
|
}
|
|
150
167
|
}
|
|
168
|
+
console.log(`[API] /api/ingest Successfully added ${logEntries.length} logs`);
|
|
151
169
|
res.json({ success: true, count: logEntries.length });
|
|
152
170
|
}
|
|
153
171
|
catch (e) {
|
|
@@ -181,10 +199,6 @@ async function startApiServer(db) {
|
|
|
181
199
|
const projects = db.listProjects();
|
|
182
200
|
res.json(projects);
|
|
183
201
|
});
|
|
184
|
-
app.get("/api/system/token", async (_req, res) => {
|
|
185
|
-
const token = await auth.getOrCreateMcpToken();
|
|
186
|
-
res.json({ token });
|
|
187
|
-
});
|
|
188
202
|
app.post("/api/projects", (req, res) => {
|
|
189
203
|
const { name } = req.body;
|
|
190
204
|
if (!name)
|
|
@@ -280,7 +294,11 @@ async function startApiServer(db) {
|
|
|
280
294
|
res.status(404).send("Dashboard not found. Please build the frontend.");
|
|
281
295
|
}
|
|
282
296
|
});
|
|
283
|
-
app.listen(port, () => {
|
|
297
|
+
const server = app.listen(port, () => {
|
|
284
298
|
// listening
|
|
285
299
|
});
|
|
300
|
+
server.on("error", (e) => {
|
|
301
|
+
console.error("Server error:", e);
|
|
302
|
+
process.exit(1);
|
|
303
|
+
});
|
|
286
304
|
}
|
package/dist/cli_main.js
CHANGED
|
@@ -12,18 +12,17 @@ const migrate_1 = require("./db/migrate");
|
|
|
12
12
|
// import { ensureInfrastructure } from "./utils/startup"; // Might need adjustment
|
|
13
13
|
const auth_1 = require("./services/auth");
|
|
14
14
|
const chalk_1 = __importDefault(require("chalk"));
|
|
15
|
-
const open_1 = __importDefault(require("open"));
|
|
16
15
|
const db = new db_1.DbService();
|
|
17
16
|
const auth = new auth_1.AuthService();
|
|
18
17
|
async function main() {
|
|
19
18
|
const argv = await (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
|
|
20
|
-
.command(["start", "$0"], "Start API Server", {}, async () => {
|
|
19
|
+
.command(["start", "$0"], "Start API Server", {}, async (argv) => {
|
|
21
20
|
// console.log("Ensuring database is initialized...");
|
|
22
21
|
await (0, migrate_1.migrate)(false); // Run migrations silently
|
|
23
22
|
const token = await auth.getOrCreateMcpToken();
|
|
24
23
|
// Start API Server (this sets up express listen)
|
|
25
24
|
await (0, server_1.startApiServer)(db);
|
|
26
|
-
console.clear();
|
|
25
|
+
// console.clear();
|
|
27
26
|
console.log(chalk_1.default.bold.green(`
|
|
28
27
|
▌ ▌ ▌
|
|
29
28
|
▌ ▞▀▖▞▀▌▛▀▖▞▀▖▝▀▖▞▀▌
|
|
@@ -42,7 +41,6 @@ async function main() {
|
|
|
42
41
|
console.log("");
|
|
43
42
|
console.log(chalk_1.default.gray("--------------------------------------------------"));
|
|
44
43
|
console.log(chalk_1.default.gray(" Press Ctrl+C to stop"));
|
|
45
|
-
(0, open_1.default)("http://localhost:4567");
|
|
46
44
|
})
|
|
47
45
|
.command("projects <cmd> [name]", "Manage projects", (yargs) => {
|
|
48
46
|
yargs
|