Skip to content

Commit 15e5d60

Browse files
authored
Add agent name to sidebar, update queries (#12)
## Changes - Show all tasks in sidebar if no agent is selected - Show the agent name in the sidebar - If there is more than one agent for a task just show the first and the # of agents more - Update get single task, task list, and infinite task list to use the proper sdk types and pass the relationships query param\
1 parent f405ef1 commit 15e5d60

File tree

4 files changed

+68
-35
lines changed

4 files changed

+68
-35
lines changed

agentex-ui/components/agentex/task-sidebar.tsx

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,39 @@ import { Skeleton } from '@/components/ui/skeleton';
2222
import { useInfiniteTasks } from '@/hooks/use-tasks';
2323
import { cn } from '@/lib/utils';
2424

25-
import type { Task } from 'agentex/resources';
25+
import type { TaskListResponse } from 'agentex/resources';
2626

2727
type TaskButtonProps = {
28-
task: Task;
29-
selectedTaskID: Task['id'] | null;
30-
selectTask: (taskID: Task['id'] | null) => void;
28+
task: TaskListResponse.TaskListResponseItem;
29+
selectedTaskID: TaskListResponse.TaskListResponseItem['id'] | null;
30+
selectTask: (
31+
taskID: TaskListResponse.TaskListResponseItem['id'] | null
32+
) => void;
3133
};
3234

3335
function TaskButton({ task, selectedTaskID, selectTask }: TaskButtonProps) {
3436
const taskName = createTaskName(task);
37+
const createdAtString = useMemo(
38+
() =>
39+
task.created_at
40+
? formatDistanceToNow(new Date(task.created_at), {
41+
addSuffix: true,
42+
})
43+
: 'No date',
44+
[task.created_at]
45+
);
46+
const agentsString = useMemo(() => {
47+
if (!task.agents || task.agents.length === 0) return 'No agents';
48+
49+
const firstAgent = task.agents[0];
50+
if (!firstAgent) return 'No agents';
51+
52+
if (task.agents.length === 1) {
53+
return firstAgent.name;
54+
}
55+
56+
return `${firstAgent.name} + ${task.agents.length - 1} more`;
57+
}, [task.agents]);
3558

3659
return (
3760
<motion.div
@@ -69,27 +92,29 @@ function TaskButton({ task, selectedTaskID, selectTask }: TaskButtonProps) {
6992
}}
7093
>
7194
<span className="w-full truncate text-sm">{taskName}</span>
72-
<span
95+
<div
7396
className={cn(
74-
'text-muted-foreground text-xs',
75-
task.created_at ? 'block' : 'invisible'
97+
'text-muted-foreground w-full truncate text-xs',
98+
(task.agents && task.agents.length > 0) || task.created_at
99+
? 'block'
100+
: 'invisible'
76101
)}
77102
>
78-
{task.created_at
79-
? formatDistanceToNow(new Date(task.created_at), {
80-
addSuffix: true,
81-
})
82-
: 'No date'}
83-
</span>
103+
{createdAtString}
104+
{task.agents && task.agents.length > 0 && task.created_at && ' • '}
105+
{agentsString}
106+
</div>
84107
</Button>
85108
</motion.div>
86109
);
87110
}
88111

89112
export type TaskSidebarProps = {
90-
selectedTaskID: Task['id'] | null;
113+
selectedTaskID: TaskListResponse.TaskListResponseItem['id'] | null;
91114
selectedAgentName?: string;
92-
onSelectTask: (taskID: Task['id'] | null) => void;
115+
onSelectTask: (
116+
taskID: TaskListResponse.TaskListResponseItem['id'] | null
117+
) => void;
93118
};
94119

95120
export function TaskSidebar({
@@ -138,7 +163,7 @@ export function TaskSidebar({
138163
}, [hasNextPage, isFetchingNextPage, fetchNextPage]);
139164

140165
const handleTaskSelect = useCallback(
141-
(taskID: Task['id'] | null) => {
166+
(taskID: TaskListResponse.TaskListResponseItem['id'] | null) => {
142167
onSelectTask(taskID);
143168
},
144169
[onSelectTask]
@@ -265,7 +290,7 @@ function SidebarHeader({
265290
);
266291
}
267292

268-
function createTaskName(task: Task): string {
293+
function createTaskName(task: TaskListResponse.TaskListResponseItem): string {
269294
if (
270295
task?.params?.description &&
271296
typeof task.params.description === 'string'

agentex-ui/hooks/use-tasks.ts

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { useInfiniteQuery, useQuery } from '@tanstack/react-query';
22

33
import type AgentexSDK from 'agentex';
4-
import type { Task, TaskListParams } from 'agentex/resources';
4+
import type {
5+
TaskListResponse,
6+
TaskListParams,
7+
TaskRetrieveResponse,
8+
} from 'agentex/resources';
59

610
/**
711
* Query key factory for tasks
@@ -26,8 +30,11 @@ export function useTasks(
2630

2731
return useQuery({
2832
queryKey: tasksKeys.byAgentName(agentName),
29-
queryFn: async (): Promise<Task[]> => {
30-
const params = agentName ? { agent_name: agentName } : undefined;
33+
queryFn: async (): Promise<TaskListResponse> => {
34+
const params: TaskListParams = {
35+
relationships: ['agents'],
36+
...(agentName ? { agent_name: agentName } : {}),
37+
};
3138
return agentexClient.tasks.list(params);
3239
},
3340
staleTime: 30 * 1000, // 30 seconds
@@ -47,8 +54,10 @@ export function useTask({
4754
}) {
4855
return useQuery({
4956
queryKey: tasksKeys.byId(taskId),
50-
queryFn: async (): Promise<Task> => {
51-
return agentexClient.tasks.retrieve(taskId);
57+
queryFn: async (): Promise<TaskRetrieveResponse> => {
58+
return agentexClient.tasks.retrieve(taskId, {
59+
relationships: ['agents'],
60+
});
5261
},
5362
enabled: !!taskId,
5463
staleTime: 30 * 1000,
@@ -66,14 +75,13 @@ export function useInfiniteTasks(
6675

6776
return useInfiniteQuery({
6877
queryKey: tasksKeys.byAgentName(agentName),
69-
queryFn: async ({ pageParam = 1 }): Promise<Task[]> => {
70-
const params: TaskListParams | undefined = agentName
71-
? {
72-
agent_name: agentName,
73-
limit,
74-
page_number: pageParam as number,
75-
}
76-
: undefined;
78+
queryFn: async ({ pageParam = 1 }): Promise<TaskListResponse> => {
79+
const params: TaskListParams = {
80+
limit,
81+
page_number: pageParam as number,
82+
relationships: ['agents'],
83+
...(agentName ? { agent_name: agentName } : {}),
84+
};
7785
return agentexClient.tasks.list(params);
7886
},
7987
getNextPageParam: (lastPage, allPages) => {

agentex-ui/package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

agentex-ui/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"@tailwindcss/postcss": "^4",
3636
"@tanstack/react-query": "^5.90.3",
3737
"@uiw/react-codemirror": "^4.25.2",
38-
"agentex": "^0.1.0-alpha.7",
38+
"agentex": "^0.1.0-alpha.8",
3939
"ai": "^5.0.72",
4040
"class-variance-authority": "^0.7.1",
4141
"clsx": "^2.1.1",

0 commit comments

Comments
 (0)