@brainforge/core 3.0.2 → 3.0.4
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.d.ts +1 -0
- package/dist/index.js +25 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1049,12 +1049,27 @@ var BrainForgeServer = class {
|
|
|
1049
1049
|
if (pathname === "/api/state") return await this.fileJson(res, ".brainforge/core.json");
|
|
1050
1050
|
if (pathname === "/api/map") return await this.fileJson(res, ".brainforge/codebase-map.json");
|
|
1051
1051
|
if (pathname === "/api/scan") return await this.fileText(res, "PROFESSOR_REPORT.md");
|
|
1052
|
+
if (pathname === "/api/task/status" && req.method === "POST") return await this.handleTaskStatus(req, res);
|
|
1052
1053
|
await this.static(res, pathname);
|
|
1053
1054
|
} catch (err) {
|
|
1054
1055
|
res.writeHead(500, { "Content-Type": "application/json" });
|
|
1055
1056
|
res.end(JSON.stringify({ error: String(err) }));
|
|
1056
1057
|
}
|
|
1057
1058
|
}
|
|
1059
|
+
async handleTaskStatus(req, res) {
|
|
1060
|
+
try {
|
|
1061
|
+
const body = await readBody(req);
|
|
1062
|
+
const { taskId, status } = JSON.parse(body);
|
|
1063
|
+
const manager = new StateManager(this.workingDir);
|
|
1064
|
+
await manager.load();
|
|
1065
|
+
await manager.updateTaskStatus(taskId, status);
|
|
1066
|
+
this.broadcast("state-update", manager.get());
|
|
1067
|
+
this.json(res, { ok: true });
|
|
1068
|
+
} catch (err) {
|
|
1069
|
+
res.writeHead(400, { "Content-Type": "application/json" });
|
|
1070
|
+
res.end(JSON.stringify({ error: String(err) }));
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1058
1073
|
json(res, data) {
|
|
1059
1074
|
res.writeHead(200, { "Content-Type": "application/json" });
|
|
1060
1075
|
res.end(JSON.stringify(data));
|
|
@@ -1099,6 +1114,16 @@ var BrainForgeServer = class {
|
|
|
1099
1114
|
async function exists(p) {
|
|
1100
1115
|
return fs4.access(p).then(() => true).catch(() => false);
|
|
1101
1116
|
}
|
|
1117
|
+
function readBody(req) {
|
|
1118
|
+
return new Promise((resolve, reject) => {
|
|
1119
|
+
let body = "";
|
|
1120
|
+
req.on("data", (chunk) => {
|
|
1121
|
+
body += chunk.toString();
|
|
1122
|
+
});
|
|
1123
|
+
req.on("end", () => resolve(body));
|
|
1124
|
+
req.on("error", reject);
|
|
1125
|
+
});
|
|
1126
|
+
}
|
|
1102
1127
|
|
|
1103
1128
|
// src/defense/defense.ts
|
|
1104
1129
|
import fs5 from "fs/promises";
|