Cache provider models by server and provider
This commit is contained in:
@@ -0,0 +1,31 @@
|
|||||||
|
import { QueryClient, QueryObserver } from "@tanstack/react-query";
|
||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
|
||||||
|
import { isProviderModelsQueryLoading } from "./agent-status-bar.model-loading";
|
||||||
|
|
||||||
|
describe("isProviderModelsQueryLoading", () => {
|
||||||
|
it("does not treat a disabled pending query as loading", () => {
|
||||||
|
const queryClient = new QueryClient();
|
||||||
|
const observer = new QueryObserver(queryClient, {
|
||||||
|
queryKey: ["providerModels", "server-1", "__missing_provider__"],
|
||||||
|
enabled: false,
|
||||||
|
queryFn: async () => [],
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = observer.getCurrentResult();
|
||||||
|
|
||||||
|
expect(result.isPending).toBe(true);
|
||||||
|
expect(result.isLoading).toBe(false);
|
||||||
|
expect(result.isFetching).toBe(false);
|
||||||
|
expect(isProviderModelsQueryLoading(result)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("treats an active fetch as loading", () => {
|
||||||
|
expect(
|
||||||
|
isProviderModelsQueryLoading({
|
||||||
|
isLoading: false,
|
||||||
|
isFetching: true,
|
||||||
|
}),
|
||||||
|
).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
interface ProviderModelsQueryState {
|
||||||
|
isFetching: boolean;
|
||||||
|
isLoading: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isProviderModelsQueryLoading(input: ProviderModelsQueryState): boolean {
|
||||||
|
return input.isLoading || input.isFetching;
|
||||||
|
}
|
||||||
@@ -33,6 +33,7 @@ import {
|
|||||||
getStatusSelectorHint,
|
getStatusSelectorHint,
|
||||||
resolveAgentModelSelection,
|
resolveAgentModelSelection,
|
||||||
} from "@/components/agent-status-bar.utils";
|
} from "@/components/agent-status-bar.utils";
|
||||||
|
import { isProviderModelsQueryLoading } from "@/components/agent-status-bar.model-loading";
|
||||||
|
|
||||||
type StatusOption = {
|
type StatusOption = {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -634,12 +635,7 @@ export function AgentStatusBar({ agentId, serverId }: AgentStatusBarProps) {
|
|||||||
const client = useSessionStore((state) => state.sessions[serverId]?.client ?? null);
|
const client = useSessionStore((state) => state.sessions[serverId]?.client ?? null);
|
||||||
|
|
||||||
const modelsQuery = useQuery({
|
const modelsQuery = useQuery({
|
||||||
queryKey: [
|
queryKey: ["providerModels", serverId, agent?.provider ?? "__missing_provider__"],
|
||||||
"providerModels",
|
|
||||||
serverId,
|
|
||||||
agent?.provider ?? "__missing_provider__",
|
|
||||||
agent?.cwd ?? "__missing_cwd__",
|
|
||||||
],
|
|
||||||
enabled: Boolean(client && agent?.provider),
|
enabled: Boolean(client && agent?.provider),
|
||||||
staleTime: 5 * 60 * 1000,
|
staleTime: 5 * 60 * 1000,
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
@@ -753,7 +749,7 @@ export function AgentStatusBar({ agentId, serverId }: AgentStatusBarProps) {
|
|||||||
console.warn("[AgentStatusBar] setAgentThinkingOption failed", error);
|
console.warn("[AgentStatusBar] setAgentThinkingOption failed", error);
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
isModelLoading={modelsQuery.isPending || modelsQuery.isFetching}
|
isModelLoading={isProviderModelsQueryLoading(modelsQuery)}
|
||||||
disabled={!client}
|
disabled={!client}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -418,7 +418,7 @@ export function useAgentFormState(options: UseAgentFormStateOptions = {}): UseAg
|
|||||||
}, [formState.workingDir]);
|
}, [formState.workingDir]);
|
||||||
|
|
||||||
const providerModelsQuery = useQuery({
|
const providerModelsQuery = useQuery({
|
||||||
queryKey: ["providerModels", formState.serverId, formState.provider, debouncedCwd],
|
queryKey: ["providerModels", formState.serverId, formState.provider],
|
||||||
enabled: Boolean(
|
enabled: Boolean(
|
||||||
isVisible &&
|
isVisible &&
|
||||||
isTargetDaemonReady &&
|
isTargetDaemonReady &&
|
||||||
@@ -446,7 +446,7 @@ export function useAgentFormState(options: UseAgentFormStateOptions = {}): UseAg
|
|||||||
|
|
||||||
const allProviderModelQueries = useQueries({
|
const allProviderModelQueries = useQueries({
|
||||||
queries: providerDefinitions.map((def) => ({
|
queries: providerDefinitions.map((def) => ({
|
||||||
queryKey: ["providerModels", formState.serverId, def.id, debouncedCwd],
|
queryKey: ["providerModels", formState.serverId, def.id],
|
||||||
enabled: Boolean(
|
enabled: Boolean(
|
||||||
isVisible && isTargetDaemonReady && formState.serverId && client && isConnected,
|
isVisible && isTargetDaemonReady && formState.serverId && client && isConnected,
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user