fix(app): reuse draft command cache across tabs

This commit is contained in:
Mohamed Boudra
2026-06-11 13:17:29 +07:00
parent 08ebe5e7e1
commit a70b5c1e1d
5 changed files with 186 additions and 30 deletions
@@ -0,0 +1,61 @@
import type { AgentProvider } from "@getpaseo/protocol/agent-types";
import { normalizeWorkspacePath } from "@/utils/workspace-identity";
export const AGENT_COMMANDS_QUERY_ROOT = "agentCommands";
export interface AgentCommandsDraftConfig {
provider: AgentProvider;
cwd: string;
modeId?: string;
model?: string;
thinkingOptionId?: string;
featureValues?: Record<string, unknown>;
}
export function normalizeAgentCommandsCwd(cwd: string): string {
return normalizeWorkspacePath(cwd) ?? "";
}
export function agentCommandsQueryRoot(serverId: string) {
return [AGENT_COMMANDS_QUERY_ROOT, serverId] as const;
}
export function sessionAgentCommandsQueryKey(input: { serverId: string; agentId: string }) {
return [...agentCommandsQueryRoot(input.serverId), "session", input.agentId] as const;
}
export function draftAgentCommandsQueryKey(input: {
serverId: string;
draftConfig: AgentCommandsDraftConfig;
}) {
const { draftConfig } = input;
return [
...agentCommandsQueryRoot(input.serverId),
"draft",
draftConfig.provider,
"cwd",
normalizeAgentCommandsCwd(draftConfig.cwd),
"mode",
draftConfig.modeId ?? null,
"model",
draftConfig.model ?? null,
"thinking",
draftConfig.thinkingOptionId ?? null,
"features",
draftConfig.featureValues ?? null,
] as const;
}
export function agentCommandsQueryKey(input: {
serverId: string;
agentId: string;
draftConfig?: AgentCommandsDraftConfig;
}) {
if (input.draftConfig) {
return draftAgentCommandsQueryKey({
serverId: input.serverId,
draftConfig: input.draftConfig,
});
}
return sessionAgentCommandsQueryKey({ serverId: input.serverId, agentId: input.agentId });
}