Skip to content

Commit a4d16a9

Browse files
committed
feat(web): restore bulk title regeneration
1 parent a5dfcbd commit a4d16a9

3 files changed

Lines changed: 92 additions & 0 deletions

File tree

‎apps/web/src/components/Sidebar.logic.test.ts‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";
22
import {
33
archiveSelectedThreadEntries,
4+
buildBulkTitleRegenerationContextMenuItem,
45
buildMultiSelectThreadContextMenuItems,
56
createThreadJumpHintVisibilityController,
67
getSidebarThreadIdsToPrewarm,
@@ -149,6 +150,42 @@ describe("archiveSelectedThreadEntries", () => {
149150
});
150151
});
151152

153+
describe("buildBulkTitleRegenerationContextMenuItem", () => {
154+
it("counts only threads that can start a new regeneration", () => {
155+
expect(
156+
buildBulkTitleRegenerationContextMenuItem({
157+
supportedCount: 4,
158+
actionableCount: 3,
159+
}),
160+
).toEqual({
161+
id: "regenerate-title",
162+
label: "Regenerate titles (3)",
163+
});
164+
});
165+
166+
it("shows a disabled progress item when every supported thread is pending", () => {
167+
expect(
168+
buildBulkTitleRegenerationContextMenuItem({
169+
supportedCount: 2,
170+
actionableCount: 0,
171+
}),
172+
).toEqual({
173+
id: "regenerate-title",
174+
label: "Regenerating… (2)",
175+
disabled: true,
176+
});
177+
});
178+
179+
it("omits the action when no selected environment supports it", () => {
180+
expect(
181+
buildBulkTitleRegenerationContextMenuItem({
182+
supportedCount: 0,
183+
actionableCount: 0,
184+
}),
185+
).toBeNull();
186+
});
187+
});
188+
152189
describe("buildMultiSelectThreadContextMenuItems", () => {
153190
it("offers bulk archive with the selected count", () => {
154191
expect(

‎apps/web/src/components/Sidebar.logic.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,24 @@ export function buildMultiSelectThreadContextMenuItems(input: {
9595
];
9696
}
9797

98+
export function buildBulkTitleRegenerationContextMenuItem(input: {
99+
supportedCount: number;
100+
actionableCount: number;
101+
}): ContextMenuItem<"regenerate-title"> | null {
102+
if (input.supportedCount === 0) return null;
103+
if (input.actionableCount === 0) {
104+
return {
105+
id: "regenerate-title",
106+
label: `Regenerating… (${input.supportedCount})`,
107+
disabled: true,
108+
};
109+
}
110+
return {
111+
id: "regenerate-title",
112+
label: `Regenerate titles (${input.actionableCount})`,
113+
};
114+
}
115+
98116
export interface ThreadStatusPill {
99117
label:
100118
| "Working"

‎apps/web/src/components/SidebarV2.tsx‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ import { formatRelativeTimeLabel, parseTimestampDate } from "../timestampFormat"
106106
import type { SidebarThreadSummary } from "../types";
107107
import { cn } from "~/lib/utils";
108108
import {
109+
buildBulkTitleRegenerationContextMenuItem,
109110
formatWorkingDurationLabel,
110111
firstValidTimestampMs,
111112
hasUnseenCompletion,
@@ -1938,6 +1939,18 @@ export default function SidebarV2() {
19381939
serverConfigs.get(thread.environmentId)?.environment.capabilities.threadSnooze === true &&
19391940
canSnooze(thread, { now: selectionNow.toISOString() }),
19401941
);
1942+
const titleRegenerationThreads = selectedThreads.filter(
1943+
(thread) =>
1944+
serverConfigs.get(thread.environmentId)?.environment.capabilities
1945+
.threadTitleRegeneration === true,
1946+
);
1947+
const regeneratableTitleThreads = titleRegenerationThreads.filter(
1948+
(thread) => thread.titleRegeneration == null,
1949+
);
1950+
const titleRegenerationMenuItem = buildBulkTitleRegenerationContextMenuItem({
1951+
supportedCount: titleRegenerationThreads.length,
1952+
actionableCount: regeneratableTitleThreads.length,
1953+
});
19411954
const snoozePresets = resolveSnoozePresets(new Date());
19421955
const clicked = await settlePromise(() =>
19431956
api.contextMenu.show(
@@ -1955,6 +1968,7 @@ export default function SidebarV2() {
19551968
},
19561969
]
19571970
: []),
1971+
...(titleRegenerationMenuItem ? [titleRegenerationMenuItem] : []),
19581972
{ id: "mark-unread", label: `Mark unread (${count})` },
19591973
{ id: "delete", label: `Delete (${count})`, destructive: true },
19601974
],
@@ -1979,6 +1993,28 @@ export default function SidebarV2() {
19791993
}
19801994
return;
19811995
}
1996+
if (clicked.value === "regenerate-title") {
1997+
for (const thread of regeneratableTitleThreads) {
1998+
const result = await updateThreadMetadata({
1999+
environmentId: thread.environmentId,
2000+
input: { threadId: thread.id, regenerateTitle: true },
2001+
});
2002+
if (result._tag === "Success") continue;
2003+
if (!isAtomCommandInterrupted(result)) {
2004+
const error = squashAtomCommandFailure(result);
2005+
toastManager.add(
2006+
stackedThreadToast({
2007+
type: "error",
2008+
title: "Failed to regenerate thread titles",
2009+
description: error instanceof Error ? error.message : "An error occurred.",
2010+
}),
2011+
);
2012+
}
2013+
return;
2014+
}
2015+
clearSelection();
2016+
return;
2017+
}
19822018
if (clicked.value === "settle") {
19832019
// Post-settle navigation must skip threads settling in this same
19842020
// batch — they are all leaving the card block together. Rows that
@@ -2050,6 +2086,7 @@ export default function SidebarV2() {
20502086
markThreadUnread,
20512087
removeFromSelection,
20522088
serverConfigs,
2089+
updateThreadMetadata,
20532090
],
20542091
);
20552092

0 commit comments

Comments
 (0)