refactor(agent): consolidate agent system into unified AgentManager with provider-based architecture
Replace separate ACP and agent-types modules with unified AgentManager using provider pattern. Migrate Claude and Codex implementations to provider-specific clients. Streamline session-agent integration, remove old ACP notification types, and introduce agent timeline events. Delete obsolete documentation and test files. Add AgentRegistry for persistence and agent-stream-based communication pattern. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,15 +1,9 @@
|
||||
import { View, Text, Pressable, ScrollView } from 'react-native';
|
||||
import { StyleSheet } from 'react-native-unistyles';
|
||||
import type { AgentStatus } from '@server/server/acp/types';
|
||||
import { View, Text, Pressable, ScrollView } from "react-native";
|
||||
import { StyleSheet } from "react-native-unistyles";
|
||||
import type { Agent } from "@/contexts/session-context";
|
||||
|
||||
export interface ActiveProcessesProps {
|
||||
agents: Array<{
|
||||
id: string;
|
||||
status: AgentStatus;
|
||||
type: 'claude';
|
||||
currentModeId?: string;
|
||||
availableModes?: Array<{ id: string; name: string; description?: string | null }>;
|
||||
}>;
|
||||
agents: Agent[];
|
||||
commands: Array<{
|
||||
id: string;
|
||||
name: string;
|
||||
@@ -18,46 +12,44 @@ export interface ActiveProcessesProps {
|
||||
isDead: boolean;
|
||||
exitCode: number | null;
|
||||
}>;
|
||||
viewMode: 'orchestrator' | 'agent';
|
||||
viewMode: "orchestrator" | "agent";
|
||||
activeAgentId: string | null;
|
||||
onSelectAgent: (id: string) => void;
|
||||
onSelectOrchestrator: () => void;
|
||||
}
|
||||
|
||||
function getAgentStatusColor(status: AgentStatus): string {
|
||||
function getAgentStatusColor(status: Agent["status"]): string {
|
||||
switch (status) {
|
||||
case 'initializing':
|
||||
return '#f59e0b'; // orange
|
||||
case 'ready':
|
||||
return '#3b82f6'; // blue
|
||||
case 'processing':
|
||||
return '#fbbf24'; // yellow
|
||||
case 'completed':
|
||||
return '#22c55e'; // green
|
||||
case 'failed':
|
||||
return '#ef4444'; // red
|
||||
case 'killed':
|
||||
return '#9ca3af'; // gray
|
||||
case "initializing":
|
||||
return "#f59e0b";
|
||||
case "idle":
|
||||
return "#22c55e";
|
||||
case "running":
|
||||
return "#3b82f6";
|
||||
case "error":
|
||||
return "#ef4444";
|
||||
case "closed":
|
||||
return "#9ca3af";
|
||||
default:
|
||||
return '#9ca3af';
|
||||
return "#9ca3af";
|
||||
}
|
||||
}
|
||||
|
||||
function getModeName(modeId?: string, availableModes?: Array<{ id: string; name: string }>): string {
|
||||
if (!modeId) return 'unknown';
|
||||
function getModeName(modeId?: string, availableModes?: Agent["availableModes"]): string {
|
||||
if (!modeId) return "unknown";
|
||||
const mode = availableModes?.find((m) => m.id === modeId);
|
||||
return mode?.name || modeId;
|
||||
return mode?.label || modeId;
|
||||
}
|
||||
|
||||
function getModeColor(modeId?: string): string {
|
||||
if (!modeId) return '#9ca3af'; // gray
|
||||
if (!modeId) return "#9ca3af"; // gray
|
||||
|
||||
// Color based on common mode types
|
||||
if (modeId.includes('ask')) return '#f59e0b'; // orange - asks permission
|
||||
if (modeId.includes('code')) return '#22c55e'; // green - writes code
|
||||
if (modeId.includes('architect') || modeId.includes('plan')) return '#3b82f6'; // blue - plans
|
||||
if (modeId.includes("ask")) return "#f59e0b"; // orange - asks permission
|
||||
if (modeId.includes("code")) return "#22c55e"; // green - writes code
|
||||
if (modeId.includes("architect") || modeId.includes("plan")) return "#3b82f6"; // blue - plans
|
||||
|
||||
return '#9ca3af'; // gray - unknown
|
||||
return "#9ca3af"; // gray - unknown
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create((theme) => ({
|
||||
|
||||
@@ -2,51 +2,13 @@ import { View, Text, Pressable, ScrollView } from "react-native";
|
||||
import { router } from "expo-router";
|
||||
import { StyleSheet, useUnistyles } from "react-native-unistyles";
|
||||
import type { Agent } from "@/contexts/session-context";
|
||||
import type { AgentStatus } from "@server/server/acp/types";
|
||||
import { formatTimeAgo } from "@/utils/time";
|
||||
import { getAgentStatusColor, getAgentStatusLabel } from "@/utils/agent-status";
|
||||
|
||||
interface AgentListProps {
|
||||
agents: Map<string, Agent>;
|
||||
}
|
||||
|
||||
function getStatusColor(status: AgentStatus): string {
|
||||
switch (status) {
|
||||
case "initializing":
|
||||
return "#FFA500";
|
||||
case "ready":
|
||||
return "#2563EB";
|
||||
case "processing":
|
||||
return "#FACC15";
|
||||
case "completed":
|
||||
return "#10B981";
|
||||
case "failed":
|
||||
return "#EF4444";
|
||||
case "killed":
|
||||
return "#6B7280";
|
||||
default:
|
||||
return "#6B7280";
|
||||
}
|
||||
}
|
||||
|
||||
function getStatusLabel(status: AgentStatus): string {
|
||||
switch (status) {
|
||||
case "initializing":
|
||||
return "Initializing";
|
||||
case "ready":
|
||||
return "Ready";
|
||||
case "processing":
|
||||
return "Processing";
|
||||
case "completed":
|
||||
return "Completed";
|
||||
case "failed":
|
||||
return "Failed";
|
||||
case "killed":
|
||||
return "Killed";
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
export function AgentList({ agents }: AgentListProps) {
|
||||
const { theme } = useUnistyles();
|
||||
|
||||
@@ -62,8 +24,8 @@ export function AgentList({ agents }: AgentListProps) {
|
||||
return (
|
||||
<ScrollView style={styles.container} showsVerticalScrollIndicator={false}>
|
||||
{agentArray.map((agent) => {
|
||||
const statusColor = getStatusColor(agent.status);
|
||||
const statusLabel = getStatusLabel(agent.status);
|
||||
const statusColor = getAgentStatusColor(agent.status);
|
||||
const statusLabel = getAgentStatusLabel(agent.status);
|
||||
const timeAgo = formatTimeAgo(agent.lastActivityAt);
|
||||
|
||||
return (
|
||||
|
||||
@@ -13,14 +13,8 @@ import Animated, {
|
||||
Easing,
|
||||
type SharedValue,
|
||||
} from "react-native-reanimated";
|
||||
import type { AgentStatus } from "@server/server/acp/types";
|
||||
|
||||
interface Agent {
|
||||
id: string;
|
||||
status: AgentStatus;
|
||||
title?: string;
|
||||
cwd: string;
|
||||
}
|
||||
import type { Agent } from "@/contexts/session-context";
|
||||
import { getAgentStatusColor, getAgentStatusLabel } from "@/utils/agent-status";
|
||||
|
||||
interface AgentSidebarProps {
|
||||
isOpen: boolean;
|
||||
@@ -32,44 +26,6 @@ interface AgentSidebarProps {
|
||||
edgeSwipeTranslateX?: SharedValue<number> | null;
|
||||
}
|
||||
|
||||
function getStatusColor(status: AgentStatus): string {
|
||||
switch (status) {
|
||||
case "initializing":
|
||||
return "#FFA500";
|
||||
case "ready":
|
||||
return "#2563EB";
|
||||
case "processing":
|
||||
return "#FACC15";
|
||||
case "completed":
|
||||
return "#10B981";
|
||||
case "failed":
|
||||
return "#EF4444";
|
||||
case "killed":
|
||||
return "#6B7280";
|
||||
default:
|
||||
return "#6B7280";
|
||||
}
|
||||
}
|
||||
|
||||
function getStatusLabel(status: AgentStatus): string {
|
||||
switch (status) {
|
||||
case "initializing":
|
||||
return "Initializing";
|
||||
case "ready":
|
||||
return "Ready";
|
||||
case "processing":
|
||||
return "Processing";
|
||||
case "completed":
|
||||
return "Completed";
|
||||
case "failed":
|
||||
return "Failed";
|
||||
case "killed":
|
||||
return "Killed";
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
export function AgentSidebar({
|
||||
isOpen,
|
||||
agents,
|
||||
@@ -221,8 +177,8 @@ export function AgentSidebar({
|
||||
<ScrollView style={styles.agentList} showsVerticalScrollIndicator={false}>
|
||||
{agents.map((agent) => {
|
||||
const isActive = agent.id === activeAgentId;
|
||||
const statusColor = getStatusColor(agent.status);
|
||||
const statusLabel = getStatusLabel(agent.status);
|
||||
const statusColor = getAgentStatusColor(agent.status);
|
||||
const statusLabel = getAgentStatusLabel(agent.status);
|
||||
|
||||
return (
|
||||
<Pressable
|
||||
|
||||
@@ -2,6 +2,7 @@ import { View, Text, Pressable } from "react-native";
|
||||
import { StyleSheet, useUnistyles } from "react-native-unistyles";
|
||||
import { ChevronDown } from "lucide-react-native";
|
||||
import { useSession } from "@/contexts/session-context";
|
||||
import type { Agent } from "@/contexts/session-context";
|
||||
import { useState } from "react";
|
||||
import { ModeSelectorModal } from "./mode-selector-modal";
|
||||
|
||||
@@ -24,35 +25,18 @@ export function AgentStatusBar({ agentId }: AgentStatusBarProps) {
|
||||
setAgentMode(agentId, modeId);
|
||||
}
|
||||
|
||||
function getStatusLabel(status: string): string {
|
||||
function getStatusColor(status: Agent["status"]): string {
|
||||
switch (status) {
|
||||
case "ready":
|
||||
return "Ready";
|
||||
case "processing":
|
||||
return "Working";
|
||||
case "completed":
|
||||
return "Completed";
|
||||
case "failed":
|
||||
return "Failed";
|
||||
case "killed":
|
||||
return "Stopped";
|
||||
default:
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
function getStatusColor(status: string): string {
|
||||
switch (status) {
|
||||
case "ready":
|
||||
return theme.colors.palette.green[500];
|
||||
case "processing":
|
||||
return theme.colors.palette.blue[500];
|
||||
case "completed":
|
||||
return theme.colors.palette.gray[500];
|
||||
case "failed":
|
||||
return theme.colors.palette.red[500];
|
||||
case "killed":
|
||||
case "initializing":
|
||||
return theme.colors.palette.orange[500];
|
||||
case "idle":
|
||||
return theme.colors.palette.green[500];
|
||||
case "running":
|
||||
return theme.colors.palette.blue[500];
|
||||
case "error":
|
||||
return theme.colors.palette.red[500];
|
||||
case "closed":
|
||||
return theme.colors.palette.gray[500];
|
||||
default:
|
||||
return theme.colors.mutedForeground;
|
||||
}
|
||||
@@ -70,7 +54,7 @@ export function AgentStatusBar({ agentId }: AgentStatusBarProps) {
|
||||
]}
|
||||
>
|
||||
<Text style={styles.modeBadgeText}>
|
||||
{agent.availableModes?.find((m) => m.id === agent.currentModeId)?.name ||
|
||||
{agent.availableModes?.find((m) => m.id === agent.currentModeId)?.label ||
|
||||
agent.currentModeId ||
|
||||
"default"}
|
||||
</Text>
|
||||
|
||||
@@ -26,6 +26,7 @@ import {
|
||||
import { ToolCallBottomSheet } from "./tool-call-bottom-sheet";
|
||||
import type { StreamItem } from "@/types/stream";
|
||||
import type { SelectedToolCall, PendingPermission } from "@/types/shared";
|
||||
import type { AgentPermissionResponse } from "@server/server/agent/agent-sdk-types";
|
||||
import type { Agent } from "@/contexts/session-context";
|
||||
import { useSession } from "@/contexts/session-context";
|
||||
|
||||
@@ -34,7 +35,7 @@ export interface AgentStreamViewProps {
|
||||
agent: Agent;
|
||||
streamItems: StreamItem[];
|
||||
pendingPermissions: Map<string, PendingPermission>;
|
||||
onPermissionResponse: (requestId: string, optionId: string) => void;
|
||||
onPermissionResponse: (agentId: string, requestId: string, response: AgentPermissionResponse) => void;
|
||||
}
|
||||
|
||||
export function AgentStreamView({
|
||||
@@ -232,30 +233,18 @@ export function AgentStreamView({
|
||||
case "tool_call": {
|
||||
const { payload } = item;
|
||||
|
||||
// Extract data based on source
|
||||
if (payload.source === "acp") {
|
||||
if (payload.source === "agent") {
|
||||
const data = payload.data;
|
||||
// Map ACP status to display status
|
||||
const toolStatus =
|
||||
data.status === "pending" || data.status === "in_progress"
|
||||
? ("executing" as const)
|
||||
: data.status === "completed"
|
||||
? ("completed" as const)
|
||||
: ("failed" as const);
|
||||
|
||||
return (
|
||||
<ToolCall
|
||||
toolName={data.title ?? "Unknown Tool"}
|
||||
kind={data.kind}
|
||||
args={data.rawInput}
|
||||
result={data.rawOutput}
|
||||
status={toolStatus}
|
||||
toolName={`${data.server}/${data.tool}`}
|
||||
args={data.raw}
|
||||
status={data.status as "executing" | "completed" | "failed"}
|
||||
onOpenDetails={() => handleOpenToolCallDetails({ payload })}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
// Orchestrator tool call
|
||||
const data = payload.data;
|
||||
return (
|
||||
<ToolCall
|
||||
@@ -268,9 +257,16 @@ export function AgentStreamView({
|
||||
);
|
||||
}
|
||||
|
||||
case "plan":
|
||||
case "activity_log":
|
||||
case "artifact":
|
||||
return (
|
||||
<ActivityLog
|
||||
type={item.activityType}
|
||||
message={item.message}
|
||||
timestamp={item.timestamp.getTime()}
|
||||
metadata={item.metadata}
|
||||
/>
|
||||
);
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
@@ -318,7 +314,7 @@ export function AgentStreamView({
|
||||
<View style={stylesheet.permissionsContainer}>
|
||||
{pendingPermissionItems.map((permission) => (
|
||||
<PermissionRequestCard
|
||||
key={permission.requestId}
|
||||
key={permission.request.id}
|
||||
permission={permission}
|
||||
onResponse={onPermissionResponse}
|
||||
/>
|
||||
@@ -411,75 +407,17 @@ function PermissionRequestCard({
|
||||
permission,
|
||||
onResponse,
|
||||
}: {
|
||||
permission: {
|
||||
requestId: string;
|
||||
toolCall: any;
|
||||
options: Array<{
|
||||
kind: string;
|
||||
name: string;
|
||||
optionId: string;
|
||||
}>;
|
||||
};
|
||||
onResponse: (requestId: string, optionId: string) => void;
|
||||
permission: PendingPermission;
|
||||
onResponse: (agentId: string, requestId: string, response: AgentPermissionResponse) => void;
|
||||
}) {
|
||||
const { theme } = useUnistyles();
|
||||
|
||||
// Determine permission type and content based on toolCall
|
||||
const getPermissionInfo = () => {
|
||||
const rawInput = permission.toolCall?.rawInput || {};
|
||||
const toolCallId = permission.toolCall?.toolCallId || "";
|
||||
|
||||
console.log("[PermissionCard] Tool call details:", {
|
||||
toolCallId,
|
||||
rawInputKeys: Object.keys(rawInput),
|
||||
rawInput,
|
||||
});
|
||||
|
||||
// Check if this is a plan (ExitPlanMode)
|
||||
if (rawInput.plan) {
|
||||
return {
|
||||
title: "Plan Ready for Review",
|
||||
content: rawInput.plan,
|
||||
type: "plan" as const,
|
||||
};
|
||||
}
|
||||
|
||||
// Check if this is a file operation (Write, Edit, etc.)
|
||||
if (rawInput.file_path) {
|
||||
const operation = toolCallId.includes("Write") ? "Create" : "Edit";
|
||||
const fileContent = rawInput.content || rawInput.new_string || "";
|
||||
const preview =
|
||||
fileContent.length > 500
|
||||
? fileContent.slice(0, 500) + "\n\n... (truncated)"
|
||||
: fileContent;
|
||||
|
||||
return {
|
||||
title: `${operation} File Permission`,
|
||||
content: `File: ${rawInput.file_path}\n\n${preview || "(empty file)"}`,
|
||||
type: "file" as const,
|
||||
};
|
||||
}
|
||||
|
||||
// Check if this is a command (Bash)
|
||||
if (rawInput.command) {
|
||||
return {
|
||||
title: "Run Command Permission",
|
||||
content: `Command: ${rawInput.command}\n\nDescription: ${
|
||||
rawInput.description || "No description"
|
||||
}`,
|
||||
type: "command" as const,
|
||||
};
|
||||
}
|
||||
|
||||
// Fallback - show whatever is in rawInput
|
||||
return {
|
||||
title: "Permission Required",
|
||||
content: JSON.stringify(rawInput, null, 2),
|
||||
type: "unknown" as const,
|
||||
};
|
||||
};
|
||||
|
||||
const permissionInfo = getPermissionInfo();
|
||||
const { request } = permission;
|
||||
const title = request.title ?? request.name ?? "Permission Required";
|
||||
const description = request.description ?? "";
|
||||
const inputPreview = request.input
|
||||
? JSON.stringify(request.input, null, 2)
|
||||
: null;
|
||||
|
||||
return (
|
||||
<View
|
||||
@@ -491,26 +429,25 @@ function PermissionRequestCard({
|
||||
},
|
||||
]}
|
||||
>
|
||||
<Text
|
||||
style={[permissionStyles.title, { color: theme.colors.foreground }]}
|
||||
>
|
||||
{permissionInfo.title}
|
||||
<Text style={[permissionStyles.title, { color: theme.colors.foreground }]}>
|
||||
{title}
|
||||
</Text>
|
||||
|
||||
{permissionInfo.content && (
|
||||
{description ? (
|
||||
<Text style={[permissionStyles.planText, { color: theme.colors.mutedForeground }]}>
|
||||
{description}
|
||||
</Text>
|
||||
) : null}
|
||||
|
||||
{inputPreview && (
|
||||
<View
|
||||
style={[
|
||||
permissionStyles.planContainer,
|
||||
{ backgroundColor: theme.colors.background },
|
||||
]}
|
||||
>
|
||||
<Text
|
||||
style={[
|
||||
permissionStyles.planText,
|
||||
{ color: theme.colors.foreground },
|
||||
]}
|
||||
>
|
||||
{permissionInfo.content}
|
||||
<Text style={[permissionStyles.planText, { color: theme.colors.foreground }]}>
|
||||
{inputPreview}
|
||||
</Text>
|
||||
</View>
|
||||
)}
|
||||
@@ -525,29 +462,45 @@ function PermissionRequestCard({
|
||||
</Text>
|
||||
|
||||
<View style={permissionStyles.optionsContainer}>
|
||||
{permission.options.map((option) => (
|
||||
<Pressable
|
||||
key={option.optionId}
|
||||
<Pressable
|
||||
style={[
|
||||
permissionStyles.optionButton,
|
||||
{ backgroundColor: theme.colors.primary },
|
||||
]}
|
||||
onPress={() =>
|
||||
onResponse(permission.agentId, request.id, { behavior: "allow" })
|
||||
}
|
||||
>
|
||||
<Text
|
||||
style={[
|
||||
permissionStyles.optionButton,
|
||||
{
|
||||
backgroundColor: option.kind.includes("reject")
|
||||
? theme.colors.destructive
|
||||
: theme.colors.primary,
|
||||
},
|
||||
permissionStyles.optionText,
|
||||
{ color: theme.colors.primaryForeground },
|
||||
]}
|
||||
onPress={() => onResponse(permission.requestId, option.optionId)}
|
||||
>
|
||||
<Text
|
||||
style={[
|
||||
permissionStyles.optionText,
|
||||
{ color: theme.colors.primaryForeground },
|
||||
]}
|
||||
>
|
||||
{option.name}
|
||||
</Text>
|
||||
</Pressable>
|
||||
))}
|
||||
Allow
|
||||
</Text>
|
||||
</Pressable>
|
||||
<Pressable
|
||||
style={[
|
||||
permissionStyles.optionButton,
|
||||
{ backgroundColor: theme.colors.destructive },
|
||||
]}
|
||||
onPress={() =>
|
||||
onResponse(permission.agentId, request.id, {
|
||||
behavior: "deny",
|
||||
message: "Denied by user",
|
||||
})
|
||||
}
|
||||
>
|
||||
<Text
|
||||
style={[
|
||||
permissionStyles.optionText,
|
||||
{ color: theme.colors.primaryForeground },
|
||||
]}
|
||||
>
|
||||
Deny
|
||||
</Text>
|
||||
</Pressable>
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { useState, useRef, useEffect, useMemo, useCallback } from "react";
|
||||
import type { ReactElement } from "react";
|
||||
import {
|
||||
View,
|
||||
Text,
|
||||
@@ -28,30 +29,24 @@ import { useSession } from "@/contexts/session-context";
|
||||
import { useRouter } from "expo-router";
|
||||
import { generateMessageId } from "@/types/stream";
|
||||
import {
|
||||
listAgentTypeDefinitions,
|
||||
type AgentType,
|
||||
type AgentTypeDefinition,
|
||||
type AgentModeDefinition,
|
||||
} from "@server/server/acp/agent-types";
|
||||
AGENT_PROVIDER_DEFINITIONS,
|
||||
type AgentProviderDefinition,
|
||||
} from "@server/server/agent/provider-manifest";
|
||||
import type { AgentProvider, AgentMode, AgentSessionConfig } from "@server/server/agent/agent-sdk-types";
|
||||
|
||||
interface CreateAgentModalProps {
|
||||
isVisible: boolean;
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
const agentTypeDefinitions = listAgentTypeDefinitions();
|
||||
const providerDefinitions = AGENT_PROVIDER_DEFINITIONS;
|
||||
const providerDefinitionMap = new Map<AgentProvider, AgentProviderDefinition>(
|
||||
providerDefinitions.map((definition) => [definition.id, definition])
|
||||
);
|
||||
|
||||
const agentTypeDefinitionMap: Record<AgentType, AgentTypeDefinition> =
|
||||
{} as Record<AgentType, AgentTypeDefinition>;
|
||||
for (const definition of agentTypeDefinitions) {
|
||||
agentTypeDefinitionMap[definition.id] = definition;
|
||||
}
|
||||
|
||||
const fallbackDefinition = agentTypeDefinitionMap.claude ?? agentTypeDefinitions[0];
|
||||
const DEFAULT_AGENT_TYPE: AgentType = fallbackDefinition
|
||||
? fallbackDefinition.id
|
||||
: "claude";
|
||||
const DEFAULT_MODE_FOR_DEFAULT_AGENT = fallbackDefinition?.defaultModeId ?? "";
|
||||
const fallbackDefinition = providerDefinitions[0];
|
||||
const DEFAULT_PROVIDER: AgentProvider = fallbackDefinition?.id ?? "claude";
|
||||
const DEFAULT_MODE_FOR_DEFAULT_PROVIDER = fallbackDefinition?.defaultModeId ?? "";
|
||||
const BACKDROP_OPACITY = 0.55;
|
||||
|
||||
export function CreateAgentModal({
|
||||
@@ -71,10 +66,10 @@ export function CreateAgentModal({
|
||||
|
||||
const [isMounted, setIsMounted] = useState(isVisible);
|
||||
const [workingDir, setWorkingDir] = useState("");
|
||||
const [selectedAgentType, setSelectedAgentType] = useState<AgentType>(
|
||||
DEFAULT_AGENT_TYPE
|
||||
const [selectedProvider, setSelectedProvider] = useState<AgentProvider>(
|
||||
DEFAULT_PROVIDER
|
||||
);
|
||||
const [selectedMode, setSelectedMode] = useState(DEFAULT_MODE_FOR_DEFAULT_AGENT);
|
||||
const [selectedMode, setSelectedMode] = useState(DEFAULT_MODE_FOR_DEFAULT_PROVIDER);
|
||||
const [worktreeName, setWorktreeName] = useState("");
|
||||
const [errorMessage, setErrorMessage] = useState("");
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
@@ -82,8 +77,8 @@ export function CreateAgentModal({
|
||||
|
||||
const pendingNavigationAgentIdRef = useRef<string | null>(null);
|
||||
|
||||
const agentDefinition = agentTypeDefinitionMap[selectedAgentType];
|
||||
const modeOptions = agentDefinition?.availableModes ?? [];
|
||||
const agentDefinition = providerDefinitionMap.get(selectedProvider);
|
||||
const modeOptions = agentDefinition?.modes ?? [];
|
||||
|
||||
useEffect(() => {
|
||||
if (!agentDefinition) {
|
||||
@@ -109,8 +104,8 @@ export function CreateAgentModal({
|
||||
const resetFormState = useCallback(() => {
|
||||
setWorkingDir("");
|
||||
setWorktreeName("");
|
||||
setSelectedAgentType(DEFAULT_AGENT_TYPE);
|
||||
setSelectedMode(DEFAULT_MODE_FOR_DEFAULT_AGENT);
|
||||
setSelectedProvider(DEFAULT_PROVIDER);
|
||||
setSelectedMode(DEFAULT_MODE_FOR_DEFAULT_PROVIDER);
|
||||
setErrorMessage("");
|
||||
setIsLoading(false);
|
||||
setPendingRequestId(null);
|
||||
@@ -293,14 +288,17 @@ export function CreateAgentModal({
|
||||
setPendingRequestId(requestId);
|
||||
setErrorMessage("");
|
||||
|
||||
const modeId =
|
||||
modeOptions.length > 0 && selectedMode !== "" ? selectedMode : undefined;
|
||||
const modeId = modeOptions.length > 0 && selectedMode !== "" ? selectedMode : undefined;
|
||||
|
||||
const config: AgentSessionConfig = {
|
||||
provider: selectedProvider,
|
||||
cwd: trimmedPath,
|
||||
...(modeId ? { modeId } : {}),
|
||||
};
|
||||
|
||||
try {
|
||||
createAgent({
|
||||
cwd: trimmedPath,
|
||||
agentType: selectedAgentType,
|
||||
initialMode: modeId,
|
||||
config,
|
||||
worktreeName: worktree || undefined,
|
||||
requestId,
|
||||
});
|
||||
@@ -314,8 +312,8 @@ export function CreateAgentModal({
|
||||
workingDir,
|
||||
worktreeName,
|
||||
selectedMode,
|
||||
selectedAgentType,
|
||||
modeOptions,
|
||||
selectedProvider,
|
||||
isLoading,
|
||||
validateWorktreeName,
|
||||
addRecentPath,
|
||||
@@ -327,20 +325,22 @@ export function CreateAgentModal({
|
||||
return;
|
||||
}
|
||||
|
||||
const unsubscribe = ws.on("agent_created", (message) => {
|
||||
if (message.type !== "agent_created") {
|
||||
const unsubscribe = ws.on("status", (message) => {
|
||||
if (message.type !== "status") {
|
||||
return;
|
||||
}
|
||||
|
||||
const { agentId, requestId } = message.payload;
|
||||
|
||||
if (requestId === pendingRequestId) {
|
||||
console.log("[CreateAgentModal] Agent created:", agentId);
|
||||
setIsLoading(false);
|
||||
setPendingRequestId(null);
|
||||
pendingNavigationAgentIdRef.current = agentId;
|
||||
handleClose();
|
||||
const payload = message.payload as { status: string; agentId?: string; requestId?: string };
|
||||
if (payload.status !== "agent_created") {
|
||||
return;
|
||||
}
|
||||
if (payload.requestId !== pendingRequestId || !payload.agentId) {
|
||||
return;
|
||||
}
|
||||
console.log("[CreateAgentModal] Agent created:", payload.agentId);
|
||||
setIsLoading(false);
|
||||
setPendingRequestId(null);
|
||||
pendingNavigationAgentIdRef.current = payload.agentId;
|
||||
handleClose();
|
||||
});
|
||||
|
||||
return () => {
|
||||
@@ -427,11 +427,11 @@ export function CreateAgentModal({
|
||||
]}
|
||||
>
|
||||
<AssistantSelector
|
||||
agentTypeDefinitions={agentTypeDefinitions}
|
||||
providerDefinitions={providerDefinitions}
|
||||
disabled={isLoading}
|
||||
isStacked={isCompactLayout}
|
||||
selectedAgentType={selectedAgentType}
|
||||
onSelect={setSelectedAgentType}
|
||||
selectedProvider={selectedProvider}
|
||||
onSelect={setSelectedProvider}
|
||||
/>
|
||||
<ModeSelector
|
||||
disabled={isLoading}
|
||||
@@ -496,12 +496,12 @@ interface ModalHeaderProps {
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
function ModalHeader({ paddingTop, paddingLeft, paddingRight, onClose }: ModalHeaderProps): JSX.Element {
|
||||
function ModalHeader({ paddingTop, paddingLeft, paddingRight, onClose }: ModalHeaderProps): ReactElement {
|
||||
return (
|
||||
<View style={[styles.header, { paddingTop, paddingLeft, paddingRight }]}>
|
||||
<Text style={styles.headerTitle}>Create New Agent</Text>
|
||||
<Pressable onPress={onClose} style={styles.closeButton} hitSlop={8}>
|
||||
<X size={20} style={styles.closeIcon} />
|
||||
<X size={20} color={defaultTheme.colors.mutedForeground} />
|
||||
</Pressable>
|
||||
</View>
|
||||
);
|
||||
@@ -521,7 +521,7 @@ function WorkingDirectorySection({
|
||||
errorMessage,
|
||||
recentPaths,
|
||||
onChangeWorkingDir,
|
||||
}: WorkingDirectorySectionProps): JSX.Element {
|
||||
}: WorkingDirectorySectionProps): ReactElement {
|
||||
return (
|
||||
<View style={styles.formSection}>
|
||||
<Text style={styles.label}>Working Directory</Text>
|
||||
@@ -557,26 +557,26 @@ function WorkingDirectorySection({
|
||||
}
|
||||
|
||||
interface AssistantSelectorProps {
|
||||
agentTypeDefinitions: AgentTypeDefinition[];
|
||||
selectedAgentType: AgentType;
|
||||
providerDefinitions: AgentProviderDefinition[];
|
||||
selectedProvider: AgentProvider;
|
||||
disabled: boolean;
|
||||
isStacked: boolean;
|
||||
onSelect: (agentType: AgentType) => void;
|
||||
onSelect: (provider: AgentProvider) => void;
|
||||
}
|
||||
|
||||
function AssistantSelector({
|
||||
agentTypeDefinitions,
|
||||
selectedAgentType,
|
||||
providerDefinitions,
|
||||
selectedProvider,
|
||||
disabled,
|
||||
isStacked,
|
||||
onSelect,
|
||||
}: AssistantSelectorProps): JSX.Element {
|
||||
}: AssistantSelectorProps): ReactElement {
|
||||
return (
|
||||
<View style={[styles.selectorColumn, isStacked && styles.selectorColumnFull]}>
|
||||
<Text style={styles.label}>Assistant</Text>
|
||||
<View style={styles.optionGroup}>
|
||||
{agentTypeDefinitions.map((definition) => {
|
||||
const isSelected = selectedAgentType === definition.id;
|
||||
{providerDefinitions.map((definition) => {
|
||||
const isSelected = selectedProvider === definition.id;
|
||||
return (
|
||||
<Pressable
|
||||
key={definition.id}
|
||||
@@ -608,7 +608,7 @@ function AssistantSelector({
|
||||
}
|
||||
|
||||
interface ModeSelectorProps {
|
||||
modeOptions: AgentModeDefinition[];
|
||||
modeOptions: AgentMode[];
|
||||
selectedMode: string;
|
||||
disabled: boolean;
|
||||
isStacked: boolean;
|
||||
@@ -621,7 +621,7 @@ function ModeSelector({
|
||||
disabled,
|
||||
isStacked,
|
||||
onSelect,
|
||||
}: ModeSelectorProps): JSX.Element {
|
||||
}: ModeSelectorProps): ReactElement {
|
||||
return (
|
||||
<View style={[styles.selectorColumn, isStacked && styles.selectorColumnFull]}>
|
||||
<Text style={styles.label}>Permissions</Text>
|
||||
@@ -652,7 +652,7 @@ function ModeSelector({
|
||||
{isSelected ? <View style={styles.radioInner} /> : null}
|
||||
</View>
|
||||
<View style={styles.modeTextContainer}>
|
||||
<Text style={styles.optionLabel}>{mode.name}</Text>
|
||||
<Text style={styles.optionLabel}>{mode.label}</Text>
|
||||
{mode.description ? <Text style={styles.modeDescription}>{mode.description}</Text> : null}
|
||||
</View>
|
||||
</View>
|
||||
@@ -671,7 +671,7 @@ interface WorktreeSectionProps {
|
||||
onChange: (value: string) => void;
|
||||
}
|
||||
|
||||
function WorktreeSection({ value, isLoading, onChange }: WorktreeSectionProps): JSX.Element {
|
||||
function WorktreeSection({ value, isLoading, onChange }: WorktreeSectionProps): ReactElement {
|
||||
return (
|
||||
<View style={styles.formSection}>
|
||||
<Text style={styles.label}>Worktree Name (Optional)</Text>
|
||||
@@ -742,9 +742,6 @@ const styles = StyleSheet.create((theme) => ({
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
},
|
||||
closeIcon: {
|
||||
color: theme.colors.mutedForeground,
|
||||
},
|
||||
scroll: {
|
||||
flex: 1,
|
||||
},
|
||||
|
||||
@@ -46,7 +46,7 @@ export function ModeSelectorModal({
|
||||
isActive && styles.modeNameActive,
|
||||
]}
|
||||
>
|
||||
{mode.name}
|
||||
{mode.label}
|
||||
</Text>
|
||||
{mode.description && (
|
||||
<Text
|
||||
|
||||
@@ -209,34 +209,23 @@ export function ToolCallBottomSheet({
|
||||
|
||||
const { payload } = selectedToolCall;
|
||||
|
||||
if (payload.source === "acp") {
|
||||
const data = payload.data;
|
||||
|
||||
const content = data.content
|
||||
?.flatMap((item) => {
|
||||
if (item.type === "content" && item.content.type === "text") {
|
||||
return [item.content.text];
|
||||
}
|
||||
return [];
|
||||
})
|
||||
.join("\n");
|
||||
|
||||
return {
|
||||
toolName: data.kind ?? "Unknown Tool",
|
||||
args: data.rawInput,
|
||||
result: content,
|
||||
error: undefined, // ACP doesn't have a separate error field
|
||||
};
|
||||
} else {
|
||||
// Orchestrator tool call
|
||||
if (payload.source === "agent") {
|
||||
const data = payload.data;
|
||||
return {
|
||||
toolName: data.toolName,
|
||||
args: data.arguments,
|
||||
result: data.result,
|
||||
error: data.error,
|
||||
toolName: `${data.server}/${data.tool}`,
|
||||
args: data.raw,
|
||||
result: undefined,
|
||||
error: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
const data = payload.data;
|
||||
return {
|
||||
toolName: data.toolName,
|
||||
args: data.arguments,
|
||||
result: data.result,
|
||||
error: data.error,
|
||||
};
|
||||
}, [selectedToolCall]);
|
||||
|
||||
const editEntries = useMemo(() => {
|
||||
|
||||
Reference in New Issue
Block a user