Skip to content

A personal agent with a browser, terminal, files, and work that keeps going built with CopilotKit and AG-UI.

TypeScript

perf(api): read notifications without full workspace snapshot (#106)

Kevin Rajanb58aa7095b68
diff --git a/apps/server/src/engine/routes.ts b/apps/server/src/engine/routes.ts
index 139bf61..9096c08 100644
--- a/apps/server/src/engine/routes.ts
+++ b/apps/server/src/engine/routes.ts
@@ -130,7 +130,7 @@ export function agentRoutes(service: AgentService): Hono<{ Variables: { owner: s
return c.json(identity);
});
app.get("/notifications", async (c) =>
- c.json((await service.snapshot(c.get("owner"))).notifications),
+ c.json(await service.db.list<AgentNotification>(c.get("owner"), "notifications")),
);
app.post("/notifications/:id/read", async (c) => {
const notification = await service.db.compareAndSwap<AgentNotification>(
diff --git a/tests/agent-api.test.ts b/tests/agent-api.test.ts
index c3b58a3..4de0cdf 100644
--- a/tests/agent-api.test.ts
+++ b/tests/agent-api.test.ts
@@ -254,6 +254,15 @@ test("idea dismissal survives refresh and concurrent acceptance creates one goal
await read(`/tasks/${results[0].taskId}/control`, { action: "cancel" });
});
+test("notification reads do not load the full agent workspace", async (t) => {
+ t.mock.method(server.agent, "snapshot", async () => {
+ throw new Error("notifications route must not call snapshot");
+ });
+ const response = await request("/notifications");
+ assert.equal(response.status, 200, await response.clone().text());
+ assert.ok(Array.isArray(await response.json()));
+});
+
test("sample monitor saves its baseline and deduplicates notifications for repeated changes", async () => {
await read("/sample-page", { text: "No tables available" });
const monitor = await read<Monitor>(