@@ -32,13 +32,9 @@ import {
3232 buildInstanceInputForDefinition ,
3333 resolveStartRuntimeForDefinition ,
3434} from "@/features/agents/lib/instanceInputForDefinition" ;
35- import {
36- isManagedAgentActive ,
37- startManagedAgentWithRules ,
38- stopManagedAgentWithRules ,
39- } from "@/features/agents/lib/managedAgentControlActions" ;
4035import { describeLogFile } from "@/features/agents/ui/agentUi" ;
4136import { AgentDialog } from "@/features/agents/ui/AgentDialog" ;
37+ import { useAgentLifecycleActions } from "@/features/profile/ui/useAgentLifecycleActions" ;
4238import {
4339 consumePendingOpenEditAgent ,
4440 type EditAgentFocusTarget ,
@@ -451,42 +447,14 @@ export function UserProfilePanel({
451447 ] ,
452448 ) ;
453449
454- const handleAgentPrimaryAction = React . useCallback ( async ( ) => {
455- if ( ! managedAgent ) return ;
456-
457- try {
458- if ( isManagedAgentActive ( managedAgent ) ) {
459- const result = await stopManagedAgentWithRules ( {
460- agent : managedAgent ,
461- channels : channelsQuery . data ?? [ ] ,
462- relayAgents : relayAgentsQuery . data ?? [ ] ,
463- stopManagedAgent : stopAgentMutation . mutateAsync ,
464- } ) ;
465- toast . success ( result . noticeMessage ?? `Stopped ${ managedAgent . name } .` ) ;
466- return ;
467- }
468-
469- await startManagedAgentWithRules ( {
470- agent : managedAgent ,
471- startManagedAgent : startAgentMutation . mutateAsync ,
472- } ) ;
473- toast . success (
474- managedAgent . backend . type === "provider"
475- ? `Deploying ${ managedAgent . name } .`
476- : `Started ${ managedAgent . name } .` ,
477- ) ;
478- } catch ( error ) {
479- toast . error (
480- error instanceof Error ? error . message : "Agent action failed." ,
481- ) ;
482- }
483- } , [
484- channelsQuery . data ,
485- managedAgent ,
486- relayAgentsQuery . data ,
487- startAgentMutation . mutateAsync ,
488- stopAgentMutation . mutateAsync ,
489- ] ) ;
450+ const { handleAgentPrimaryAction, handleAgentRestart } =
451+ useAgentLifecycleActions ( {
452+ channels : channelsQuery . data ,
453+ managedAgent,
454+ relayAgents : relayAgentsQuery . data ,
455+ startManagedAgent : startAgentMutation . mutateAsync ,
456+ stopManagedAgent : stopAgentMutation . mutateAsync ,
457+ } ) ;
490458
491459 const handleInstantiateAgent = React . useCallback ( async ( ) => {
492460 if ( ! resolvedPersona ) return ;
@@ -828,6 +796,7 @@ export function UserProfilePanel({
828796 followMutation = { followMutation }
829797 agentInstruction = { agentInstruction }
830798 handleAgentPrimaryAction = { handleAgentPrimaryAction }
799+ handleAgentRestart = { handleAgentRestart }
831800 handleEditAgent = { handleEditAgent }
832801 handleEditPersona = { canEditPersona ? handleEditPersona : undefined }
833802 handleInstantiateAgent = { handleInstantiateAgent }
0 commit comments