优化Agent Connect时的agent状态获取

This commit is contained in:
xintaofei
2026-03-17 23:24:07 +08:00
parent ad062aef96
commit acbdabe9e4
6 changed files with 68 additions and 7 deletions

View File

@@ -15,7 +15,7 @@ import { disposeTauriListener } from "@/lib/tauri-listener"
import { inferLiveToolName } from "@/lib/tool-call-normalization"
import {
acpConnect,
acpListAgents,
acpGetAgentStatus,
acpPrompt,
acpSetMode,
acpSetConfigOption,
@@ -25,7 +25,7 @@ import {
} from "@/lib/tauri"
import type {
AgentType,
AcpAgentInfo,
AcpAgentStatus,
AcpEvent,
AvailableCommandInfo,
ConnectionStatus,
@@ -1169,7 +1169,7 @@ export function AcpConnectionsProvider({ children }: { children: ReactNode }) {
)
const resolveAutoLinkBlockState = useCallback(
(agent: AcpAgentInfo | null): AutoLinkBlockState => {
(agent: AcpAgentStatus | null): AutoLinkBlockState => {
if (!agent) {
return { kind: "missing_config", reason: t("blocked.missingConfig") }
}
@@ -1685,11 +1685,9 @@ export function AcpConnectionsProvider({ children }: { children: ReactNode }) {
try {
if (isAutoLink) {
let configuredAgent: AcpAgentInfo | null = null
let configuredAgent: AcpAgentStatus | null = null
try {
const agents = await acpListAgents()
configuredAgent =
agents.find((agent) => agent.agent_type === agentType) ?? null
configuredAgent = await acpGetAgentStatus(agentType)
} catch (error) {
const reason = t("unableReadAgentConfig", {
message: normalizeErrorMessage(error),

View File

@@ -9,6 +9,7 @@ import type {
SidebarData,
ConnectionInfo,
AcpAgentInfo,
AcpAgentStatus,
AgentSkillScope,
AgentSkillLayout,
AgentSkillItem,
@@ -153,6 +154,12 @@ export async function acpListAgents(): Promise<AcpAgentInfo[]> {
return invoke("acp_list_agents")
}
export async function acpGetAgentStatus(
agentType: AgentType
): Promise<AcpAgentStatus> {
return invoke("acp_get_agent_status", { agentType })
}
export async function acpClearBinaryCache(agentType: AgentType): Promise<void> {
return invoke("acp_clear_binary_cache", { agentType })
}

View File

@@ -463,6 +463,14 @@ export interface AcpAgentInfo {
codex_config_toml: string | null
}
// Lightweight agent status returned by acp_get_agent_status
export interface AcpAgentStatus {
agent_type: AgentType
available: boolean
enabled: boolean
installed_version: string | null
}
export type AgentSkillScope = "global" | "project"
export type AgentSkillLayout = "markdown_file" | "skill_directory"