* perf(app): retain inactive workspace screens App-wide routes cleared the active workspace selection, which removed the retained workspace deck from the React tree and made returning rebuild every panel. Keep mounted deck entries inactive across those routes and suspend inactive panel subscriptions so state is preserved without background work. * perf(app): suspend remaining inactive queries Retained composers and commit diff panels still subscribed through query hooks that did not receive panel activity. Propagate the existing activity gate so app-wide routes leave those hidden surfaces dormant. * refactor(app): separate panel activity from connectivity A hidden retained panel is still connected to its host. Keep connectivity truthful, pause work inside query and stream owners, and preserve terminal emulator identity while its stream is detached. * test(app): target active retained controls * fix(app): retain compact and terminal route content * fix(app): hide inactive workspace overlays
85 lines
2.6 KiB
TypeScript
85 lines
2.6 KiB
TypeScript
import { useQuery } from "@tanstack/react-query";
|
|
import { useTranslation } from "react-i18next";
|
|
import type { DaemonClient } from "@getpaseo/client/internal/daemon-client";
|
|
import { useRetainedPanelActive } from "@/components/retained-panel";
|
|
import { useHostRuntimeClient, useHostRuntimeIsConnected } from "@/runtime/host-runtime";
|
|
import { agentCommandsQueryKey, type AgentCommandsDraftConfig } from "@/hooks/agent-commands-query";
|
|
|
|
const DRAFT_COMMANDS_STALE_TIME = Number.POSITIVE_INFINITY;
|
|
const SESSION_COMMANDS_STALE_TIME = 60_000;
|
|
|
|
export interface AgentSlashCommand {
|
|
name: string;
|
|
description: string;
|
|
argumentHint: string;
|
|
kind?: string;
|
|
}
|
|
|
|
export type DraftCommandConfig = AgentCommandsDraftConfig;
|
|
|
|
interface ListAgentCommandsOptions {
|
|
agentId: string;
|
|
draftConfig?: DraftCommandConfig;
|
|
}
|
|
|
|
export interface AgentCommandsClient {
|
|
listCommands(options: ListAgentCommandsOptions): ReturnType<DaemonClient["listCommands"]>;
|
|
}
|
|
|
|
export async function fetchAgentCommands(input: {
|
|
client: AgentCommandsClient;
|
|
agentId: string;
|
|
draftConfig?: DraftCommandConfig;
|
|
}): Promise<AgentSlashCommand[]> {
|
|
const response = await input.client.listCommands({
|
|
agentId: input.agentId,
|
|
draftConfig: input.draftConfig,
|
|
});
|
|
return response.commands as AgentSlashCommand[];
|
|
}
|
|
|
|
interface UseAgentCommandsQueryOptions {
|
|
serverId: string;
|
|
agentId: string;
|
|
enabled?: boolean;
|
|
draftConfig?: DraftCommandConfig;
|
|
}
|
|
|
|
export function useAgentCommandsQuery({
|
|
serverId,
|
|
agentId,
|
|
enabled = true,
|
|
draftConfig,
|
|
}: UseAgentCommandsQueryOptions) {
|
|
const { t } = useTranslation();
|
|
const retainedPanelActive = useRetainedPanelActive();
|
|
const queryEnabled = enabled && retainedPanelActive;
|
|
const client = useHostRuntimeClient(serverId);
|
|
const isConnected = useHostRuntimeIsConnected(serverId);
|
|
|
|
const query = useQuery({
|
|
queryKey: agentCommandsQueryKey({ serverId, agentId, draftConfig }),
|
|
queryFn: async () => {
|
|
if (!client) {
|
|
throw new Error(t("common.errors.daemonClientUnavailable"));
|
|
}
|
|
return fetchAgentCommands({ client, agentId, draftConfig });
|
|
},
|
|
enabled: queryEnabled && !!client && isConnected && (!!agentId || !!draftConfig),
|
|
staleTime: draftConfig ? DRAFT_COMMANDS_STALE_TIME : SESSION_COMMANDS_STALE_TIME,
|
|
retry: 3,
|
|
retryDelay: (attemptIndex) => Math.min(1000 * 2 ** attemptIndex, 5000),
|
|
});
|
|
|
|
// isPending is true when the query has never run yet (no cached data and not fetching)
|
|
// isLoading is true when fetching and no data yet
|
|
const isLoading = query.isPending || query.isLoading;
|
|
|
|
return {
|
|
commands: query.data ?? [],
|
|
isLoading,
|
|
isError: query.isError,
|
|
error: query.error,
|
|
};
|
|
}
|