From 8c0436b76642e7a8f17ca20420e24cf8de9f9b69 Mon Sep 17 00:00:00 2001 From: Alistair Pullen Date: Thu, 12 Sep 2024 22:28:33 +0000 Subject: [PATCH 1/2] feat: update final state display to input field with save button Co-authored-by: Genie --- src/server.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/server.ts b/src/server.ts index 52570f2..5f71580 100644 --- a/src/server.ts +++ b/src/server.ts @@ -151,9 +151,10 @@ ${displayMessages(window)}

END of Context

Back to Top -

Final State:

+

Final State Content:

-${window.meta.final_state.content} + +
From 8739ff7251f6b0b25da3f2acd62728675ce9c3e5 Mon Sep 17 00:00:00 2001 From: Alistair Pullen Date: Thu, 12 Sep 2024 22:29:54 +0000 Subject: [PATCH 2/2] feat: add endpoint to save final state content for context Co-authored-by: Genie --- src/server.ts | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/server.ts b/src/server.ts index 5f71580..1024177 100644 --- a/src/server.ts +++ b/src/server.ts @@ -172,6 +172,49 @@ ${displayMessages(window)} }, ) +app.post("/context/:id/save/", async (c) => { + const id = c.req.param("id") + const finalStateContent = c.req.param("final_state_content") + + const data = await getData(id) + + const out = [] + + const stream = fs + .createReadStream("./context_windows.jsonl") + .pipe(ndjson.parse()) + .on("data", async (obj) => { + if (obj.meta.id === id) { + obj.meta.final_state.content = finalStateContent + out.push(obj) + } else { + out.push(obj) + } + }) + + stream.on("end", () => { + const writeStream = fs.createWriteStream("./context_windows.jsonl") + + out.forEach((obj) => { + writeStream.write(JSON.stringify(obj) + "\n") + }) + + writeStream.end() + + return c.text("Saved", 200) + }) + + stream.on("close", () => { + return c.text("Saved", 200) + }) + + stream.on("error", () => { + return c.text("Error", 500) + }) + + return c.text("Error", 500) +}) + app.get( "/context/:id/json/", ssgParams(async () => {