优化agent配置选项加载逻辑

This commit is contained in:
xintaofei
2026-03-26 21:37:30 +08:00
parent d1eaa8f725
commit 5e5c48338b
2 changed files with 17 additions and 7 deletions

View File

@@ -64,6 +64,7 @@ export function useConnectionLifecycle({
respondPermission: connRespondPermission, respondPermission: connRespondPermission,
modes, modes,
configOptions, configOptions,
hasCachedSelectors,
} = conn } = conn
const isInteractiveStatus = status === "connected" || status === "prompting" const isInteractiveStatus = status === "connected" || status === "prompting"
const hasSelectorsData = modes !== null || configOptions !== null const hasSelectorsData = modes !== null || configOptions !== null
@@ -73,15 +74,20 @@ export function useConnectionLifecycle({
null null
) )
const selectorTaskSuppressedRef = useRef(false) const selectorTaskSuppressedRef = useRef(false)
// Visual-only loading indicators for selector chips // Visual-only loading indicators for selector chips.
// Skip loading indicators when we have cached selectors — even if the
// cache contains no modes/configOptions (the agent simply doesn't have
// them), we already know what to show and don't need a loading state.
const modeLoading = const modeLoading =
status === "connecting" || !hasCachedSelectors &&
status === "downloading" || (status === "connecting" ||
(isInteractiveStatus && !effectiveSelectorsReady) status === "downloading" ||
(isInteractiveStatus && !effectiveSelectorsReady))
const configOptionsLoading = const configOptionsLoading =
status === "connecting" || !hasCachedSelectors &&
status === "downloading" || (status === "connecting" ||
(isInteractiveStatus && !effectiveSelectorsReady) status === "downloading" ||
(isInteractiveStatus && !effectiveSelectorsReady))
// Gate for send button: block until the backend session is fully // Gate for send button: block until the backend session is fully
// initialized (selectorsReady from the real backend event, not cache). // initialized (selectorsReady from the real backend event, not cache).
const selectorsLoading = isInteractiveStatus && !selectorsReady const selectorsLoading = isInteractiveStatus && !selectorsReady

View File

@@ -33,6 +33,7 @@ export interface UseConnectionReturn {
promptCapabilities: PromptCapabilitiesInfo promptCapabilities: PromptCapabilitiesInfo
supportsFork: boolean supportsFork: boolean
selectorsReady: boolean selectorsReady: boolean
hasCachedSelectors: boolean
sessionId: string | null sessionId: string | null
modes: SessionModeStateInfo | null modes: SessionModeStateInfo | null
configOptions: SessionConfigOptionInfo[] | null configOptions: SessionConfigOptionInfo[] | null
@@ -84,6 +85,7 @@ export function useConnection(contextKey: string): UseConnectionReturn {
const cached = connection?.agentType const cached = connection?.agentType
? getCachedSelectors(connection.agentType) ? getCachedSelectors(connection.agentType)
: null : null
const hasCachedSelectors = cached !== null
const modes = connection?.modes ?? cached?.modes ?? null const modes = connection?.modes ?? cached?.modes ?? null
const configOptions = const configOptions =
connection?.configOptions ?? cached?.configOptions ?? null connection?.configOptions ?? cached?.configOptions ?? null
@@ -142,6 +144,7 @@ export function useConnection(contextKey: string): UseConnectionReturn {
promptCapabilities, promptCapabilities,
supportsFork, supportsFork,
selectorsReady, selectorsReady,
hasCachedSelectors,
sessionId, sessionId,
modes, modes,
configOptions, configOptions,
@@ -164,6 +167,7 @@ export function useConnection(contextKey: string): UseConnectionReturn {
promptCapabilities, promptCapabilities,
supportsFork, supportsFork,
selectorsReady, selectorsReady,
hasCachedSelectors,
sessionId, sessionId,
modes, modes,
configOptions, configOptions,