cbfff9bc8a
Filter the agent profile dropdown in both the Create Task dialog and the New Session dialog to only show agents that are actually configured for the selected executor profile. For local/worktree executors, no gating (agents need no extra creds). For Docker/Sprites profiles, an agent is "configured" iff one of its remote-auth methods has a value in `remote_credentials` or a non-null secret in `remote_auth_secrets`. Agents without an entry in the remote auth catalog (Copilot, Amp, OpenCode, TUI, mock) cannot carry creds on remote executors and are blocked. Spec IDs match `AgentProfileOption.agent_name` (the registry-type string like "claude-acp"); `agent_id` is a DB UUID and unrelated to the catalog. The Create Task footer surfaces a "No agent profile is configured for X" tooltip and disables submit when the selected executor profile has no compatible agents. The New Session dialog auto-swaps to the first compatible agent and shows the same banner inline. `useRemoteAuthSpecs` returns a `loaded` flag so callers don't filter during the initial fetch (would otherwise hide everything).
51 lines
2.0 KiB
TypeScript
51 lines
2.0 KiB
TypeScript
import type { ExecutorProfile } from "@/lib/types/http";
|
|
import type { RemoteAuthSpec } from "@/lib/api/domains/settings-api";
|
|
|
|
const REMOTE_EXECUTOR_TYPES = new Set(["local_docker", "remote_docker", "sprites"]);
|
|
|
|
export function executorRequiresAgentCredentials(executorType?: string | null): boolean {
|
|
if (!executorType) return false;
|
|
return REMOTE_EXECUTOR_TYPES.has(executorType);
|
|
}
|
|
|
|
function parseJSON<T>(raw: string | undefined, fallback: T): T {
|
|
if (!raw) return fallback;
|
|
try {
|
|
return JSON.parse(raw) as T;
|
|
} catch {
|
|
return fallback;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* For local/worktree executors, agents need no extra credentials → always supported.
|
|
* For remote executors (Docker/Sprites), the executor profile must carry either:
|
|
* - a non-env auth method ID for the agent's spec in `remote_credentials`, or
|
|
* - a non-null secret keyed by an env method ID in `remote_auth_secrets`.
|
|
* Agents without a remote-auth spec (Copilot/Amp/OpenCode/TUI/mock) cannot
|
|
* carry credentials on remote executors → blocked.
|
|
*
|
|
* Spec IDs are registry-type strings ("claude-acp", "codex-acp", …) which the
|
|
* frontend exposes as `AgentProfileOption.agent_name`. `agent_id` is a DB UUID
|
|
* and is unrelated to the catalog.
|
|
*/
|
|
export function isAgentConfiguredOnExecutor(
|
|
agent: { agent_name: string },
|
|
executorProfile: Pick<ExecutorProfile, "config" | "executor_type">,
|
|
authSpecs: RemoteAuthSpec[],
|
|
): boolean {
|
|
if (!executorRequiresAgentCredentials(executorProfile.executor_type)) return true;
|
|
|
|
const spec = authSpecs.find((s) => s.id === agent.agent_name);
|
|
if (!spec) return false;
|
|
|
|
const credentials = new Set(parseJSON<string[]>(executorProfile.config?.remote_credentials, []));
|
|
if (spec.methods.some((m) => m.type !== "env" && credentials.has(m.method_id))) return true;
|
|
|
|
const secrets = parseJSON<Record<string, string | null>>(
|
|
executorProfile.config?.remote_auth_secrets,
|
|
{},
|
|
);
|
|
return spec.methods.some((m) => m.type === "env" && secrets[m.method_id]);
|
|
}
|