summaryrefslogtreecommitdiffhomepage
path: root/packages/api/src/routes
diff options
context:
space:
mode:
authorAdam Malczewski <[email protected]>2026-06-03 15:29:45 +0900
committerAdam Malczewski <[email protected]>2026-06-03 15:30:38 +0900
commit5af9bd021c206b9e4330ab6a549dc8d013d91537 (patch)
tree667dca977d6eb78e09006c5553523230daa2b73f /packages/api/src/routes
parentbcc449a5cba183c7358ab48ed4f2140bb1a3238c (diff)
parentbc3ecbe7b72f6da6ed36d0cea5a66de1c440269a (diff)
downloaddispatch-5af9bd021c206b9e4330ab6a549dc8d013d91537.tar.gz
dispatch-5af9bd021c206b9e4330ab6a549dc8d013d91537.zip
Merge branch 'dev' into warm/prompt-cache-warming
# Conflicts: # packages/api/src/agent-manager.ts # packages/api/tests/agent-manager.test.ts # packages/frontend/src/lib/tabs.svelte.ts
Diffstat (limited to 'packages/api/src/routes')
-rw-r--r--packages/api/src/routes/tabs.ts57
1 files changed, 54 insertions, 3 deletions
diff --git a/packages/api/src/routes/tabs.ts b/packages/api/src/routes/tabs.ts
index 28a89f1..2ae60ed 100644
--- a/packages/api/src/routes/tabs.ts
+++ b/packages/api/src/routes/tabs.ts
@@ -19,11 +19,18 @@ import { Hono } from "hono";
export const tabsRoutes = new Hono();
-let getAgentManager: () => { stopTab(id: string): void; deleteTab(id: string): void } | null = () =>
- null;
+let getAgentManager: () => {
+ stopTab(id: string): void;
+ deleteTab(id: string): void;
+ compactTab(tempTabId: string, sourceTabId: string): Promise<void>;
+} | null = () => null;
export function setTabsAgentManager(
- getter: () => { stopTab(id: string): void; deleteTab(id: string): void } | null,
+ getter: () => {
+ stopTab(id: string): void;
+ deleteTab(id: string): void;
+ compactTab(tempTabId: string, sourceTabId: string): Promise<void>;
+ } | null,
): void {
getAgentManager = getter;
}
@@ -64,6 +71,28 @@ tabsRoutes.put("/settings/title-model", async (c) => {
return c.json({ success: true });
});
+// Conversation-compaction model (key+model used to generate the summary).
+// Mirrors the title-model setting. When unset, compaction falls back to the
+// source tab's own key+model.
+tabsRoutes.get("/settings/compaction-model", (c) => {
+ const keyId = getSetting("compaction_model_key_id");
+ const modelId = getSetting("compaction_model_id");
+ return c.json({ keyId, modelId });
+});
+
+tabsRoutes.put("/settings/compaction-model", async (c) => {
+ const body = await c.req.json<{ keyId?: string | null; modelId?: string | null }>();
+ if (body.keyId !== undefined) {
+ if (body.keyId) setSetting("compaction_model_key_id", body.keyId);
+ else deleteSetting("compaction_model_key_id");
+ }
+ if (body.modelId !== undefined) {
+ if (body.modelId) setSetting("compaction_model_id", body.modelId);
+ else deleteSetting("compaction_model_id");
+ }
+ return c.json({ success: true });
+});
+
// Reorder open tabs. Body `{ ids }` is the new left-to-right order of tab ids;
// each tab's `position` is rewritten to its index. Must be declared before the
// `/:id` routes so "reorder" isn't captured as an id param.
@@ -134,6 +163,28 @@ tabsRoutes.get("/:id/chunks", (c) => {
return c.json({ chunks, total, oldestSeq });
});
+// Trigger conversation compaction. The `:id` is the TRANSIENT placeholder tab
+// hosting the "compacting…" UI; `sourceTabId` (body) is the conversation being
+// compacted. Fire-and-forget on the server: progress/outcome is delivered via
+// the `compaction-*` WS events. Returns 202 once the run is kicked off.
+tabsRoutes.post("/:id/compact", async (c) => {
+ const tempTabId = c.req.param("id");
+ const body = await c.req
+ .json<{ sourceTabId?: string }>()
+ .catch(() => ({}) as { sourceTabId?: string });
+ const sourceTabId = body.sourceTabId;
+ if (!sourceTabId || typeof sourceTabId !== "string") {
+ return c.json({ error: "sourceTabId is required" }, 400);
+ }
+ const mgr = getAgentManager();
+ if (!mgr) return c.json({ error: "agent manager unavailable" }, 503);
+ // Run in the background; outcome is emitted over WS.
+ void mgr.compactTab(tempTabId, sourceTabId).catch((err) => {
+ console.error(`[dispatch] compactTab error for ${sourceTabId}:`, err);
+ });
+ return c.json({ success: true }, 202);
+});
+
tabsRoutes.patch("/:id", async (c) => {
const id = c.req.param("id");
const body = await c.req.json<{