Use replace navigation for agent switches
This commit is contained in:
@@ -198,6 +198,7 @@ function AgentScreenContent({
|
|||||||
: undefined
|
: undefined
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
// Get parent agent ID for back navigation
|
// Get parent agent ID for back navigation
|
||||||
const parentAgentId = agent?.parentAgentId;
|
const parentAgentId = agent?.parentAgentId;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { View, Text, Pressable, FlatList, Modal, RefreshControl, type ListRenderItem } from "react-native";
|
import { View, Text, Pressable, FlatList, Modal, RefreshControl, type ListRenderItem } from "react-native";
|
||||||
import { useCallback, useState, useMemo } from "react";
|
import { useCallback, useMemo, useState } from "react";
|
||||||
import { router } from "expo-router";
|
import { router, usePathname } from "expo-router";
|
||||||
import { StyleSheet, useUnistyles } from "react-native-unistyles";
|
import { StyleSheet, useUnistyles } from "react-native-unistyles";
|
||||||
import { formatTimeAgo } from "@/utils/time";
|
import { formatTimeAgo } from "@/utils/time";
|
||||||
import { getAgentProviderDefinition } from "@server/server/agent/provider-manifest";
|
import { getAgentProviderDefinition } from "@server/server/agent/provider-manifest";
|
||||||
@@ -17,6 +17,7 @@ interface AgentListProps {
|
|||||||
|
|
||||||
export function AgentList({ agents, isRefreshing = false, onRefresh, selectedAgentId }: AgentListProps) {
|
export function AgentList({ agents, isRefreshing = false, onRefresh, selectedAgentId }: AgentListProps) {
|
||||||
const { theme } = useUnistyles();
|
const { theme } = useUnistyles();
|
||||||
|
const pathname = usePathname();
|
||||||
const [actionAgent, setActionAgent] = useState<AggregatedAgent | null>(null);
|
const [actionAgent, setActionAgent] = useState<AggregatedAgent | null>(null);
|
||||||
|
|
||||||
// Sort agents with requires attention at the top
|
// Sort agents with requires attention at the top
|
||||||
@@ -56,7 +57,9 @@ export function AgentList({ agents, isRefreshing = false, onRefresh, selectedAge
|
|||||||
to: "agent",
|
to: "agent",
|
||||||
params: { serverId, agentId },
|
params: { serverId, agentId },
|
||||||
});
|
});
|
||||||
router.push({
|
const shouldReplace = pathname.startsWith("/agent/");
|
||||||
|
const navigate = shouldReplace ? router.replace : router.push;
|
||||||
|
navigate({
|
||||||
pathname: "/agent/[serverId]/[agentId]",
|
pathname: "/agent/[serverId]/[agentId]",
|
||||||
params: {
|
params: {
|
||||||
serverId,
|
serverId,
|
||||||
@@ -64,7 +67,7 @@ export function AgentList({ agents, isRefreshing = false, onRefresh, selectedAge
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
[isActionSheetVisible]
|
[isActionSheetVisible, pathname]
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleAgentLongPress = useCallback((agent: AggregatedAgent) => {
|
const handleAgentLongPress = useCallback((agent: AggregatedAgent) => {
|
||||||
@@ -176,8 +179,14 @@ export function AgentList({ agents, isRefreshing = false, onRefresh, selectedAge
|
|||||||
contentContainerStyle={styles.listContent}
|
contentContainerStyle={styles.listContent}
|
||||||
keyExtractor={keyExtractor}
|
keyExtractor={keyExtractor}
|
||||||
renderItem={renderAgentItem}
|
renderItem={renderAgentItem}
|
||||||
|
extraData={selectedAgentId}
|
||||||
showsVerticalScrollIndicator={false}
|
showsVerticalScrollIndicator={false}
|
||||||
keyboardShouldPersistTaps="handled"
|
keyboardShouldPersistTaps="handled"
|
||||||
|
initialNumToRender={12}
|
||||||
|
windowSize={7}
|
||||||
|
maxToRenderPerBatch={12}
|
||||||
|
updateCellsBatchingPeriod={16}
|
||||||
|
removeClippedSubviews={true}
|
||||||
refreshControl={
|
refreshControl={
|
||||||
onRefresh ? (
|
onRefresh ? (
|
||||||
<RefreshControl
|
<RefreshControl
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { useDaemonConnections } from "@/contexts/daemon-connections-context";
|
|||||||
import { useSessionStore } from "@/stores/session-store";
|
import { useSessionStore } from "@/stores/session-store";
|
||||||
import type { AgentDirectoryEntry } from "@/types/agent-directory";
|
import type { AgentDirectoryEntry } from "@/types/agent-directory";
|
||||||
import type { Agent } from "@/stores/session-store";
|
import type { Agent } from "@/stores/session-store";
|
||||||
|
import { isPerfLoggingEnabled } from "@/utils/perf";
|
||||||
|
|
||||||
export interface AggregatedAgent extends AgentDirectoryEntry {
|
export interface AggregatedAgent extends AgentDirectoryEntry {
|
||||||
serverId: string;
|
serverId: string;
|
||||||
@@ -66,7 +67,7 @@ export function useAggregatedAgents(): AggregatedAgentsResult {
|
|||||||
if (agent.parentAgentId) {
|
if (agent.parentAgentId) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
allAgents.push({
|
const nextAgent: AggregatedAgent = {
|
||||||
id: agent.id,
|
id: agent.id,
|
||||||
serverId,
|
serverId,
|
||||||
serverLabel,
|
serverLabel,
|
||||||
@@ -79,7 +80,8 @@ export function useAggregatedAgents(): AggregatedAgentsResult {
|
|||||||
attentionReason: agent.attentionReason,
|
attentionReason: agent.attentionReason,
|
||||||
attentionTimestamp: agent.attentionTimestamp,
|
attentionTimestamp: agent.attentionTimestamp,
|
||||||
parentAgentId: agent.parentAgentId,
|
parentAgentId: agent.parentAgentId,
|
||||||
});
|
};
|
||||||
|
allAgents.push(nextAgent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,25 +140,27 @@ export function useAggregatedAgents(): AggregatedAgentsResult {
|
|||||||
// isLoading: Generic loading flag (either initial or revalidating)
|
// isLoading: Generic loading flag (either initial or revalidating)
|
||||||
const isLoading = isConnecting;
|
const isLoading = isConnecting;
|
||||||
|
|
||||||
const connectionStatesArray = Array.from(connectionStates.entries()).map(([id, state]) => ({
|
if (isPerfLoggingEnabled()) {
|
||||||
id: id.substring(0, 20) + (id.length > 20 ? '...' : ''),
|
const connectionStatesArray = Array.from(connectionStates.entries()).map(([id, state]) => ({
|
||||||
status: state.status,
|
id: id.substring(0, 20) + (id.length > 20 ? '...' : ''),
|
||||||
sessionReady: state.sessionReady,
|
status: state.status,
|
||||||
hasEverReceivedSessionState: state.hasEverReceivedSessionState,
|
sessionReady: state.sessionReady,
|
||||||
}));
|
hasEverReceivedSessionState: state.hasEverReceivedSessionState,
|
||||||
|
}));
|
||||||
|
|
||||||
console.log('[useAggregatedAgents] States:', {
|
console.log('[useAggregatedAgents] States:', {
|
||||||
hasAnyData,
|
hasAnyData,
|
||||||
isConnecting,
|
isConnecting,
|
||||||
isInitialLoad,
|
isInitialLoad,
|
||||||
isRevalidating,
|
isRevalidating,
|
||||||
totalConnectionStates: connectionStates.size,
|
totalConnectionStates: connectionStates.size,
|
||||||
connectingReasons: connectingReasons.length > 0 ? connectingReasons : 'none',
|
connectingReasons: connectingReasons.length > 0 ? connectingReasons : 'none',
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('[useAggregatedAgents] Connection States Detail:',
|
console.log('[useAggregatedAgents] Connection States Detail:',
|
||||||
JSON.stringify(connectionStatesArray, null, 2)
|
JSON.stringify(connectionStatesArray, null, 2)
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
agents: allAgents,
|
agents: allAgents,
|
||||||
|
|||||||
Reference in New Issue
Block a user