@@ -23,7 +23,7 @@ import {
2323 type ScopedThreadRef ,
2424 type SidebarProjectGroupingMode ,
2525} from "@t3tools/contracts" ;
26- import { scopeThreadRef } from "@t3tools/client-runtime/environment" ;
26+ import { scopeThreadRef , scopedThreadKey } from "@t3tools/client-runtime/environment" ;
2727import { presentThreadShell } from "@t3tools/client-runtime/state/shell" ;
2828import {
2929 isAtomCommandInterrupted ,
@@ -59,6 +59,7 @@ import {
5959import { resolveServerBackgroundActivitySettings } from "@t3tools/shared/backgroundActivitySettings" ;
6060import { createModelSelection } from "@t3tools/shared/model" ;
6161import * as Duration from "effect/Duration" ;
62+ import type { AsyncResult } from "effect/reactivity" ;
6263import * as Equal from "effect/Equal" ;
6364import * as Schema from "effect/Schema" ;
6465import { APP_VERSION , HOSTED_APP_CHANNEL , HOSTED_APP_CHANNEL_LABEL } from "../../branding" ;
@@ -97,6 +98,8 @@ import { useScopedModelDisabledReason } from "./useScopedModelAvailability";
9798import { useSettingsScope } from "./SettingsScopeContext" ;
9899import { ProjectDefaultsSettings } from "./ProjectDefaultsSettings" ;
99100import { useThreadActions } from "../../hooks/useThreadActions" ;
101+ import { useClientSettings } from "../../hooks/useSettings" ;
102+ import { deleteSelectedThreadEntries } from "../Sidebar.logic" ;
100103import { useDesktopUpdateState } from "../../state/desktopUpdate" ;
101104import {
102105 getCustomModelOptionsByInstance ,
@@ -3332,7 +3335,9 @@ export function GeneralSettingsPanel() {
33323335
33333336export function ArchivedThreadsPanel ( ) {
33343337 const { scope, groups : projectGroups , environments } = useSettingsScope ( ) ;
3335- const { unarchiveThread, confirmAndDeleteThread } = useThreadActions ( ) ;
3338+ const { unarchiveThread, deleteThread, confirmAndDeleteThread } = useThreadActions ( ) ;
3339+ const confirmThreadDelete = useClientSettings ( ( settings ) => settings . confirmThreadDelete ) ;
3340+ const [ pendingBulkGroupKey , setPendingBulkGroupKey ] = useState < string | null > ( null ) ;
33363341 const {
33373342 snapshots : archivedSnapshots ,
33383343 error : archiveError ,
@@ -3464,6 +3469,84 @@ export function ArchivedThreadsPanel() {
34643469 }
34653470 } ;
34663471
3472+ const handleUnarchiveAllThreads = async ( threadRefs : readonly ScopedThreadRef [ ] ) => {
3473+ let firstFailure : AsyncResult . Failure < unknown , unknown > | null = null ;
3474+ for ( const threadRef of threadRefs ) {
3475+ const result = await unarchiveThread ( threadRef ) ;
3476+ if ( result . _tag === "Success" ) continue ;
3477+ if ( isAtomCommandInterrupted ( result ) ) break ;
3478+ firstFailure ??= result ;
3479+ }
3480+ refreshArchivedThreads ( ) ;
3481+ if ( firstFailure !== null ) {
3482+ const error = squashAtomCommandFailure ( firstFailure ) ;
3483+ toastManager . add (
3484+ stackedThreadToast ( {
3485+ type : "error" ,
3486+ title : "Failed to unarchive threads" ,
3487+ description : error instanceof Error ? error . message : "An error occurred." ,
3488+ } ) ,
3489+ ) ;
3490+ }
3491+ } ;
3492+
3493+ const handleDeleteAllThreads = async (
3494+ threadRefs : readonly ScopedThreadRef [ ] ,
3495+ projectTitle : string ,
3496+ ) => {
3497+ const api = readLocalApi ( ) ;
3498+ if ( ! api ) return ;
3499+ if ( confirmThreadDelete ) {
3500+ const count = threadRefs . length ;
3501+ const confirmed = await settlePromise ( ( ) =>
3502+ api . dialogs . confirm (
3503+ [
3504+ `Delete ${ count } archived thread${ count === 1 ? "" : "s" } in "${ projectTitle } "?` ,
3505+ "This permanently clears conversation history for these threads." ,
3506+ ] . join ( "\n" ) ,
3507+ { variant : "destructive" } ,
3508+ ) ,
3509+ ) ;
3510+ if ( confirmed . _tag === "Failure" || ! confirmed . value ) return ;
3511+ }
3512+ const { firstFailure } = await deleteSelectedThreadEntries ( {
3513+ entries : threadRefs . map ( ( threadRef ) => ( {
3514+ threadKey : scopedThreadKey ( threadRef ) ,
3515+ threadRef,
3516+ } ) ) ,
3517+ delete : ( { threadRef } , deletedThreadKeys ) => deleteThread ( threadRef , { deletedThreadKeys } ) ,
3518+ } ) ;
3519+ refreshArchivedThreads ( ) ;
3520+ if ( firstFailure !== null ) {
3521+ const error = squashAtomCommandFailure ( firstFailure ) ;
3522+ toastManager . add (
3523+ stackedThreadToast ( {
3524+ type : "error" ,
3525+ title : "Failed to delete threads" ,
3526+ description : error instanceof Error ? error . message : "An error occurred." ,
3527+ } ) ,
3528+ ) ;
3529+ }
3530+ } ;
3531+
3532+ const runBulkAction = ( groupKey : string , action : ( ) => Promise < void > ) => {
3533+ setPendingBulkGroupKey ( groupKey ) ;
3534+ void ( async ( ) => {
3535+ const result = await settlePromise ( action ) ;
3536+ setPendingBulkGroupKey ( null ) ;
3537+ if ( result . _tag === "Failure" ) {
3538+ const error = squashAtomCommandFailure ( result ) ;
3539+ toastManager . add (
3540+ stackedThreadToast ( {
3541+ type : "error" ,
3542+ title : "Archived thread action failed" ,
3543+ description : error instanceof Error ? error . message : "An error occurred." ,
3544+ } ) ,
3545+ ) ;
3546+ }
3547+ } ) ( ) ;
3548+ } ;
3549+
34673550 const handleArchivedThreadContextMenu = async (
34683551 threadRef : ScopedThreadRef ,
34693552 title : string ,
@@ -3522,6 +3605,47 @@ export function ArchivedThreadsPanel() {
35223605 id = { index === 0 ? searchableSetting ( "archive" ) . id : undefined }
35233606 title = { title }
35243607 icon = { < ProjectFavicon project = { project } /> }
3608+ headerAction = {
3609+ < div className = "flex items-center gap-1" >
3610+ < Button
3611+ type = "button"
3612+ size = "xs"
3613+ variant = "ghost-muted"
3614+ disabled = { pendingBulkGroupKey !== null }
3615+ onClick = { ( ) =>
3616+ runBulkAction ( key , ( ) =>
3617+ handleUnarchiveAllThreads (
3618+ projectThreads . map ( ( thread ) =>
3619+ scopeThreadRef ( thread . environmentId , thread . id ) ,
3620+ ) ,
3621+ ) ,
3622+ )
3623+ }
3624+ >
3625+ < ArchiveX className = "size-3" />
3626+ Unarchive all
3627+ </ Button >
3628+ < Button
3629+ type = "button"
3630+ size = "xs"
3631+ variant = "ghost-destructive"
3632+ disabled = { pendingBulkGroupKey !== null }
3633+ onClick = { ( ) =>
3634+ runBulkAction ( key , ( ) =>
3635+ handleDeleteAllThreads (
3636+ projectThreads . map ( ( thread ) =>
3637+ scopeThreadRef ( thread . environmentId , thread . id ) ,
3638+ ) ,
3639+ title ,
3640+ ) ,
3641+ )
3642+ }
3643+ >
3644+ < Trash2Icon className = "size-3" />
3645+ Delete all
3646+ </ Button >
3647+ </ div >
3648+ }
35253649 >
35263650 { projectThreads . map ( ( thread ) => (
35273651 < SettingsRow
0 commit comments