@@ -105,6 +105,7 @@ import { formatRelativeTimeLabel, parseTimestampDate } from "../timestampFormat"
105105import type { SidebarThreadSummary } from "../types" ;
106106import { cn } from "~/lib/utils" ;
107107import {
108+ buildBulkTitleRegenerationContextMenuItem ,
108109 formatWorkingDurationLabel ,
109110 firstValidTimestampMs ,
110111 hasUnseenCompletion ,
@@ -1881,16 +1882,28 @@ export default function SidebarV2() {
18811882 const count = threadKeys . length ;
18821883 // Snooze (N) is offered when every selected thread can actually take
18831884 // it — a mixed selection with blocked-on-you work would half-apply.
1884- const selectionNow = new Date ( ) . toISOString ( ) ;
1885- const snoozableThreads = threadKeys . flatMap ( ( threadKey ) => {
1885+ const selectionNow = new Date ( ) ;
1886+ const selectedThreads = threadKeys . flatMap ( ( threadKey ) => {
18861887 const thread = threadByKeyRef . current . get ( threadKey ) ;
18871888 return thread ? [ thread ] : [ ] ;
18881889 } ) ;
1889- const canSnoozeSelection = snoozableThreads . every (
1890+ const canSnoozeSelection = selectedThreads . every (
18901891 ( thread ) =>
18911892 serverConfigs . get ( thread . environmentId ) ?. environment . capabilities . threadSnooze === true &&
1892- canSnooze ( thread , { now : selectionNow } ) ,
1893+ canSnooze ( thread , { now : selectionNow . toISOString ( ) } ) ,
18931894 ) ;
1895+ const titleRegenerationThreads = selectedThreads . filter (
1896+ ( thread ) =>
1897+ serverConfigs . get ( thread . environmentId ) ?. environment . capabilities
1898+ . threadTitleRegeneration === true ,
1899+ ) ;
1900+ const regeneratableTitleThreads = titleRegenerationThreads . filter (
1901+ ( thread ) => ! isThreadTitleRegenerationPending ( thread , selectionNow . getTime ( ) ) ,
1902+ ) ;
1903+ const titleRegenerationMenuItem = buildBulkTitleRegenerationContextMenuItem ( {
1904+ supportedCount : titleRegenerationThreads . length ,
1905+ actionableCount : regeneratableTitleThreads . length ,
1906+ } ) ;
18941907 const snoozePresets = resolveSnoozePresets ( new Date ( ) ) ;
18951908 const clicked = await settlePromise ( ( ) =>
18961909 api . contextMenu . show (
@@ -1908,6 +1921,7 @@ export default function SidebarV2() {
19081921 } ,
19091922 ]
19101923 : [ ] ) ,
1924+ ...( titleRegenerationMenuItem ? [ titleRegenerationMenuItem ] : [ ] ) ,
19111925 { id : "mark-unread" , label : `Mark unread (${ count } )` } ,
19121926 { id : "delete" , label : `Delete (${ count } )` , destructive : true } ,
19131927 ] ,
@@ -1923,7 +1937,7 @@ export default function SidebarV2() {
19231937 // Post-snooze navigation must skip threads snoozing in this same
19241938 // batch — they are all leaving the card block together.
19251939 const coSnoozingKeys = new Set ( threadKeys ) ;
1926- for ( const thread of snoozableThreads ) {
1940+ for ( const thread of selectedThreads ) {
19271941 attemptSnooze ( scopeThreadRef ( thread . environmentId , thread . id ) , preset , {
19281942 coSnoozingKeys,
19291943 } ) ;
@@ -1932,6 +1946,28 @@ export default function SidebarV2() {
19321946 }
19331947 return ;
19341948 }
1949+ if ( clicked . value === "regenerate-title" ) {
1950+ for ( const thread of regeneratableTitleThreads ) {
1951+ const result = await updateThreadMetadata ( {
1952+ environmentId : thread . environmentId ,
1953+ input : { threadId : thread . id , regenerateTitle : true } ,
1954+ } ) ;
1955+ if ( result . _tag === "Success" ) continue ;
1956+ if ( ! isAtomCommandInterrupted ( result ) ) {
1957+ const error = squashAtomCommandFailure ( result ) ;
1958+ toastManager . add (
1959+ stackedThreadToast ( {
1960+ type : "error" ,
1961+ title : "Failed to regenerate thread titles" ,
1962+ description : error instanceof Error ? error . message : "An error occurred." ,
1963+ } ) ,
1964+ ) ;
1965+ }
1966+ return ;
1967+ }
1968+ clearSelection ( ) ;
1969+ return ;
1970+ }
19351971 if ( clicked . value === "settle" ) {
19361972 // Post-settle navigation must skip threads settling in this same
19371973 // batch — they are all leaving the card block together. Rows that
@@ -2003,6 +2039,7 @@ export default function SidebarV2() {
20032039 markThreadUnread ,
20042040 removeFromSelection ,
20052041 serverConfigs ,
2042+ updateThreadMetadata ,
20062043 ] ,
20072044 ) ;
20082045
0 commit comments