Skip to content

Commit 3470e06

Browse files
committed
refactor to ts
1 parent 73aacf0 commit 3470e06

File tree

78 files changed

+12469
-6459
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+12469
-6459
lines changed

dashboard/server.ts

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import http from "http";
2+
import fs from "fs";
3+
import path from "path";
4+
5+
const PORT = 3001;
6+
7+
interface MimeTypes {
8+
[key: string]: string;
9+
}
10+
11+
const MIME_TYPES: MimeTypes = {
12+
".html": "text/html",
13+
".js": "text/javascript",
14+
".css": "text/css",
15+
".json": "application/json",
16+
".png": "image/png",
17+
".jpg": "image/jpg",
18+
".gif": "image/gif",
19+
".svg": "image/svg+xml",
20+
".ico": "image/x-icon",
21+
};
22+
23+
const server = http.createServer((req, res) => {
24+
console.log(`${req.method} ${req.url}`);
25+
26+
if (!req.url) {
27+
res.writeHead(400);
28+
res.end("Bad request: URL missing");
29+
return;
30+
}
31+
32+
// Handle the root path
33+
let filePath: string;
34+
if (req.url === "/") {
35+
filePath = path.join(__dirname, "../public/dashboard.html");
36+
} else if (req.url === "/index.js") {
37+
// Serve the main JS file from public folder
38+
filePath = path.join(__dirname, "../public/index.js");
39+
} else if (req.url === "/index.css") {
40+
// Serve the main CSS file from public folder
41+
filePath = path.join(__dirname, "../public/index.css");
42+
} else if (req.url.startsWith("/metrics/")) {
43+
// Serve metrics files from the metrics directory
44+
const metricsPath =
45+
req.url === "/metrics/summary.json"
46+
? path.join(__dirname, "../metrics", req.url.replace("/metrics/", ""))
47+
: path.join(
48+
__dirname,
49+
"../metrics/tasks",
50+
req.url.replace("/metrics/", ""),
51+
);
52+
filePath = metricsPath;
53+
} else if (req.url.startsWith("/docs/")) {
54+
// Serve docs assets
55+
filePath = path.join(__dirname, "../public", req.url);
56+
} else {
57+
// Serve other static files from the public directory
58+
filePath = path.join(__dirname, "../public", req.url);
59+
}
60+
61+
// Get the file extension
62+
const extname = path.extname(filePath);
63+
const contentType = MIME_TYPES[extname] || "application/octet-stream";
64+
65+
// Read the file
66+
fs.readFile(filePath, (err, content) => {
67+
if (err) {
68+
if (err.code === "ENOENT") {
69+
// Page not found
70+
console.error(`File not found: ${filePath}`);
71+
res.writeHead(404);
72+
res.end("404 Not Found");
73+
} else {
74+
// Server error
75+
console.error(`Server error: ${err.code}`);
76+
res.writeHead(500);
77+
res.end(`Server Error: ${err.code}`);
78+
}
79+
} else {
80+
// Success
81+
res.writeHead(200, { "Content-Type": contentType });
82+
res.end(content, "utf-8");
83+
}
84+
});
85+
});
86+
87+
server.listen(PORT, () => {
88+
console.log(`Server running at http://localhost:${PORT}/`);
89+
console.log("Press Ctrl+C to stop the server");
90+
});

dist/cli/extract-chat-metrics.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/usr/bin/env node
2+
export {};

dist/cli/extract-chat-metrics.js

Lines changed: 279 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)