mirror of
https://github.com/allaunthefox/Research-Stack.git
synced 2026-07-31 03:05:21 +00:00
- Garage scale-out complete: 6 nodes across 6 zones with replication_factor=3 - neon-64gb: added to Garage cluster (zone netcup-arm, 93 GiB) - steamdeck: installed Garage v2.3.0, added to cluster (zone gpu, 373 GiB) - nixos-laptop: converted from k3s server to agent in cupfox cluster - qfox-1: k3s agent rejoined cupfox cluster - Cloudflare Workers: WASM trinary VM deployed at wasm-compute-edge.researchstack.workers.dev - node-registry.json: updated with all 6 Garage nodes - Documentation: AGENTS.md, WIKI.md, ROADMAP.md, LLM-Context.md updated - Lake build: 3313 jobs, 0 errors Build: 3313 jobs, 0 errors (lake build Compiler)
59 lines
1.8 KiB
JavaScript
59 lines
1.8 KiB
JavaScript
import wasmModule from "./wasm_compute_bg.wasm";
|
|
import { initSync, VmState } from "./wasm_compute.js";
|
|
|
|
initSync(wasmModule);
|
|
|
|
export default {
|
|
async fetch(request, env, ctx) {
|
|
if (request.method !== "POST") {
|
|
return new Response("Method Not Allowed. Use POST.", { status: 405 });
|
|
}
|
|
|
|
const contentType = request.headers.get("content-type") || "";
|
|
|
|
try {
|
|
const vm = new VmState();
|
|
|
|
if (contentType.includes("application/json")) {
|
|
const body = await request.json();
|
|
if (body.reset) {
|
|
vm.reset();
|
|
}
|
|
if (Array.isArray(body.steps)) {
|
|
for (const s of body.steps) {
|
|
vm.step(s.op || 0, s.idx || 0, s.val || 0);
|
|
}
|
|
}
|
|
const scalar = vm.derive_scalar();
|
|
return new Response(JSON.stringify({ scalar }), {
|
|
headers: { "content-type": "application/json" }
|
|
});
|
|
} else {
|
|
const buffer = await request.arrayBuffer();
|
|
const view = new DataView(buffer);
|
|
const len = buffer.byteLength;
|
|
|
|
for (let offset = 0; offset + 2 < len; offset += 3) {
|
|
const op = view.getUint8(offset);
|
|
const idx = view.getUint8(offset + 1);
|
|
const val = view.getInt8(offset + 2);
|
|
vm.step(op, idx, val);
|
|
}
|
|
|
|
const scalar = vm.derive_scalar();
|
|
const responseBuf = new ArrayBuffer(2);
|
|
const responseView = new DataView(responseBuf);
|
|
responseView.setUint16(0, scalar, false);
|
|
|
|
return new Response(responseBuf, {
|
|
headers: { "content-type": "application/octet-stream" }
|
|
});
|
|
}
|
|
} catch (err) {
|
|
return new Response(JSON.stringify({ error: err.message }), {
|
|
status: 400,
|
|
headers: { "content-type": "application/json" }
|
|
});
|
|
}
|
|
}
|
|
};
|