replicas-engine 0.1.4 → 0.1.6
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/index.js +23 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2,11 +2,32 @@
|
|
|
2
2
|
import 'dotenv/config';
|
|
3
3
|
import { serve } from '@hono/node-server';
|
|
4
4
|
import { Hono } from 'hono';
|
|
5
|
+
import { readFile } from 'fs/promises';
|
|
5
6
|
import { authMiddleware } from './middleware/auth.js';
|
|
6
7
|
import codex from './routes/codex.js';
|
|
8
|
+
// NOTE: These constants are duplicated in @replicas/shared/src/workspaces/WorkspaceInitializer.ts
|
|
9
|
+
// If you change these values, you MUST update both locations to keep them in sync.
|
|
10
|
+
const READY_MESSAGE = '========= REPLICAS WORKSPACE READY ==========';
|
|
11
|
+
const COMPLETION_MESSAGE = '========= REPLICAS WORKSPACE INITIALIZATION COMPLETE ==========';
|
|
7
12
|
const app = new Hono();
|
|
8
|
-
app.get('/health', (c) => {
|
|
9
|
-
|
|
13
|
+
app.get('/health', async (c) => {
|
|
14
|
+
try {
|
|
15
|
+
const logContent = await readFile('/var/log/cloud-init-output.log', 'utf-8');
|
|
16
|
+
let status;
|
|
17
|
+
if (logContent.includes(COMPLETION_MESSAGE)) {
|
|
18
|
+
status = 'active';
|
|
19
|
+
}
|
|
20
|
+
else if (logContent.includes(READY_MESSAGE)) {
|
|
21
|
+
status = 'ready';
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
status = 'initializing';
|
|
25
|
+
}
|
|
26
|
+
return c.json({ status, timestamp: new Date().toISOString() });
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
return c.json({ status: 'initializing', timestamp: new Date().toISOString() });
|
|
30
|
+
}
|
|
10
31
|
});
|
|
11
32
|
app.use('*', authMiddleware);
|
|
12
33
|
app.route('/codex', codex);
|