Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion desktop/src/features/agents/ui/AgentsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export function AgentsView() {
isActionPending={isActionPending}
isAgentsLoading={agents.managedAgentsQuery.isLoading}
startingAgentPubkey={agents.startingAgentPubkey}
startingPersonaId={agents.startingPersonaId}
startingPersonaIds={agents.startingPersonaIds}
onBulkRemoveStopped={() => {
void agents.handleBulkRemoveStopped();
}}
Expand Down
12 changes: 6 additions & 6 deletions desktop/src/features/agents/ui/UnifiedAgentsSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type UnifiedAgentsSectionProps = {
isActionPending: boolean;
isAgentsLoading: boolean;
startingAgentPubkey: string | null;
startingPersonaId: string | null;
startingPersonaIds: ReadonlySet<string>;
onBulkRemoveStopped: () => void;
onBulkStopRunning: () => void;
onCreateAgent: () => void;
Expand Down Expand Up @@ -72,7 +72,7 @@ export function UnifiedAgentsSection(props: UnifiedAgentsSectionProps) {
isActionPending,
isAgentsLoading,
startingAgentPubkey,
startingPersonaId,
startingPersonaIds,
onBulkRemoveStopped,
onBulkStopRunning,
onCreateAgent,
Expand Down Expand Up @@ -174,7 +174,7 @@ export function UnifiedAgentsSection(props: UnifiedAgentsSectionProps) {
key={group.persona.id}
persona={group.persona}
startingAgentPubkey={startingAgentPubkey}
startingPersonaId={startingPersonaId}
startingPersonaIds={startingPersonaIds}
onOpenAgentProfile={onOpenAgentProfile}
onOpenPersonaProfile={onOpenPersonaProfile}
onStartAgent={onStartAgent}
Expand Down Expand Up @@ -253,7 +253,7 @@ function AgentPersonaCard({
agent,
persona,
startingAgentPubkey,
startingPersonaId,
startingPersonaIds,
onOpenAgentProfile,
onOpenPersonaProfile,
onStartAgent,
Expand All @@ -262,7 +262,7 @@ function AgentPersonaCard({
agent: ManagedAgent | undefined;
persona: AgentPersona;
startingAgentPubkey: string | null;
startingPersonaId: string | null;
startingPersonaIds: ReadonlySet<string>;
onOpenAgentProfile: (
pubkey: string,
options?: ProfilePanelOpenOptions,
Expand Down Expand Up @@ -307,7 +307,7 @@ function AgentPersonaCard({
activeTestId={`persona-runtime-active-${persona.id}`}
avatarUrl={avatarUrl}
isActive={false}
isStarting={startingPersonaId === persona.id}
isStarting={startingPersonaIds.has(persona.id)}
label={title}
startTestId={`persona-runtime-start-${persona.id}`}
onStart={() => onStartPersona(persona)}
Expand Down
28 changes: 22 additions & 6 deletions desktop/src/features/agents/ui/useManagedAgentActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ export function useManagedAgentActions() {
React.useState<ManagedAgent | null>(null);
const [createdAgent, setCreatedAgent] =
React.useState<CreateManagedAgentResponse | null>(null);
const [startingPersonaIds, setStartingPersonaIds] = React.useState<
ReadonlySet<string>
>(() => new Set());
const startingPersonaIdsRef = React.useRef(new Set<string>());
const [logAgentPubkey, setLogAgentPubkey] = React.useState<string | null>(
null,
);
Expand Down Expand Up @@ -177,7 +181,22 @@ export function useManagedAgentActions() {
return filterAvailableRuntimes(result.data);
}

function setPersonaStartPending(personaId: string, pending: boolean) {
const next = new Set(startingPersonaIdsRef.current);
if (pending) {
next.add(personaId);
} else {
next.delete(personaId);
}
startingPersonaIdsRef.current = next;
setStartingPersonaIds(next);
}

async function handleStartPersona(persona: AgentPersona) {
if (startingPersonaIdsRef.current.has(persona.id)) {
return;
}
setPersonaStartPending(persona.id, true);
clearFeedback();
try {
const runtimes = await getAvailableRuntimesForStart();
Expand Down Expand Up @@ -238,6 +257,8 @@ export function useManagedAgentActions() {
setActionErrorMessage(
error instanceof Error ? error.message : "Failed to start agent.",
);
} finally {
setPersonaStartPending(persona.id, false);
}
}

Expand Down Expand Up @@ -436,11 +457,6 @@ export function useManagedAgentActions() {
startMutation.isPending && typeof startMutation.variables === "string"
? startMutation.variables
: null;
const startingPersonaId =
createAgentMutation.isPending &&
typeof createAgentMutation.variables?.personaId === "string"
? createAgentMutation.variables.personaId
: null;

return {
relayAgentsQuery,
Expand All @@ -465,7 +481,7 @@ export function useManagedAgentActions() {
actionErrorMessage,
setActionErrorMessage,
startingAgentPubkey,
startingPersonaId,
startingPersonaIds,
handleStart,
handleStartPersona,
handleStop,
Expand Down
Loading