cue-console 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,63 @@
1
+ import * as React from "react"
2
+ import { Slot } from "@radix-ui/react-slot"
3
+ import { cva, type VariantProps } from "class-variance-authority"
4
+
5
+ import { cn } from "@/lib/utils"
6
+
7
+ const buttonVariants = cva(
8
+ "inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
9
+ {
10
+ variants: {
11
+ variant: {
12
+ default:
13
+ "bg-primary text-primary-foreground shadow-sm ring-1 ring-white/20 hover:bg-primary/90 hover:shadow-md",
14
+ destructive:
15
+ "bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
16
+ outline:
17
+ "border border-white/45 bg-white/45 shadow-sm backdrop-blur-md hover:bg-white/60 hover:text-foreground dark:border-white/12 dark:bg-white/6 dark:hover:bg-white/10",
18
+ secondary:
19
+ "bg-white/55 text-foreground shadow-sm ring-1 ring-white/35 backdrop-blur-md hover:bg-white/70 dark:bg-white/8 dark:text-foreground dark:ring-white/12 dark:hover:bg-white/12",
20
+ ghost:
21
+ "hover:bg-white/45 hover:text-foreground dark:hover:bg-white/10",
22
+ link: "text-primary underline-offset-4 hover:underline",
23
+ },
24
+ size: {
25
+ default: "h-9 px-4 py-2 has-[>svg]:px-3",
26
+ sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
27
+ lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
28
+ icon: "size-9",
29
+ "icon-sm": "size-8",
30
+ "icon-lg": "size-10",
31
+ },
32
+ },
33
+ defaultVariants: {
34
+ variant: "default",
35
+ size: "default",
36
+ },
37
+ }
38
+ )
39
+
40
+ function Button({
41
+ className,
42
+ variant = "default",
43
+ size = "default",
44
+ asChild = false,
45
+ ...props
46
+ }: React.ComponentProps<"button"> &
47
+ VariantProps<typeof buttonVariants> & {
48
+ asChild?: boolean
49
+ }) {
50
+ const Comp = asChild ? Slot : "button"
51
+
52
+ return (
53
+ <Comp
54
+ data-slot="button"
55
+ data-variant={variant}
56
+ data-size={size}
57
+ className={cn(buttonVariants({ variant, size, className }))}
58
+ {...props}
59
+ />
60
+ )
61
+ }
62
+
63
+ export { Button, buttonVariants }
@@ -0,0 +1,46 @@
1
+ "use client"
2
+
3
+ import * as React from "react"
4
+ import * as CollapsiblePrimitive from "@radix-ui/react-collapsible"
5
+
6
+ import { cn } from "@/lib/utils"
7
+
8
+ const Collapsible = CollapsiblePrimitive.Root
9
+
10
+ const CollapsibleTrigger = React.forwardRef<
11
+ React.ElementRef<typeof CollapsiblePrimitive.CollapsibleTrigger>,
12
+ React.ComponentPropsWithoutRef<typeof CollapsiblePrimitive.CollapsibleTrigger>
13
+ >(({ className, ...props }, ref) => (
14
+ <CollapsiblePrimitive.CollapsibleTrigger
15
+ ref={ref}
16
+ data-slot="collapsible-trigger"
17
+ className={cn(
18
+ "outline-none transition-[color,background-color,box-shadow]",
19
+ "focus-visible:ring-ring/50 focus-visible:ring-[3px]",
20
+ className
21
+ )}
22
+ {...props}
23
+ />
24
+ ))
25
+ CollapsibleTrigger.displayName = "CollapsibleTrigger"
26
+
27
+ const CollapsibleContent = React.forwardRef<
28
+ React.ElementRef<typeof CollapsiblePrimitive.CollapsibleContent>,
29
+ React.ComponentPropsWithoutRef<typeof CollapsiblePrimitive.CollapsibleContent>
30
+ >(({ className, ...props }, ref) => (
31
+ <CollapsiblePrimitive.CollapsibleContent
32
+ ref={ref}
33
+ data-slot="collapsible-content"
34
+ className={cn(
35
+ "overflow-hidden",
36
+ "data-[state=open]:animate-in data-[state=closed]:animate-out",
37
+ "data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
38
+ "data-[state=closed]:slide-out-to-top-1 data-[state=open]:slide-in-from-top-1",
39
+ className
40
+ )}
41
+ {...props}
42
+ />
43
+ ))
44
+ CollapsibleContent.displayName = "CollapsibleContent"
45
+
46
+ export { Collapsible, CollapsibleTrigger, CollapsibleContent }
@@ -0,0 +1,143 @@
1
+ "use client"
2
+
3
+ import * as React from "react"
4
+ import * as DialogPrimitive from "@radix-ui/react-dialog"
5
+ import { XIcon } from "lucide-react"
6
+
7
+ import { cn } from "@/lib/utils"
8
+
9
+ function Dialog({
10
+ ...props
11
+ }: React.ComponentProps<typeof DialogPrimitive.Root>) {
12
+ return <DialogPrimitive.Root data-slot="dialog" {...props} />
13
+ }
14
+
15
+ function DialogTrigger({
16
+ ...props
17
+ }: React.ComponentProps<typeof DialogPrimitive.Trigger>) {
18
+ return <DialogPrimitive.Trigger data-slot="dialog-trigger" {...props} />
19
+ }
20
+
21
+ function DialogPortal({
22
+ ...props
23
+ }: React.ComponentProps<typeof DialogPrimitive.Portal>) {
24
+ return <DialogPrimitive.Portal data-slot="dialog-portal" {...props} />
25
+ }
26
+
27
+ function DialogClose({
28
+ ...props
29
+ }: React.ComponentProps<typeof DialogPrimitive.Close>) {
30
+ return <DialogPrimitive.Close data-slot="dialog-close" {...props} />
31
+ }
32
+
33
+ function DialogOverlay({
34
+ className,
35
+ ...props
36
+ }: React.ComponentProps<typeof DialogPrimitive.Overlay>) {
37
+ return (
38
+ <DialogPrimitive.Overlay
39
+ data-slot="dialog-overlay"
40
+ className={cn(
41
+ "data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/45 backdrop-blur-sm",
42
+ className
43
+ )}
44
+ {...props}
45
+ />
46
+ )
47
+ }
48
+
49
+ function DialogContent({
50
+ className,
51
+ children,
52
+ showCloseButton = true,
53
+ ...props
54
+ }: React.ComponentProps<typeof DialogPrimitive.Content> & {
55
+ showCloseButton?: boolean
56
+ }) {
57
+ return (
58
+ <DialogPortal data-slot="dialog-portal">
59
+ <DialogOverlay />
60
+ <DialogPrimitive.Content
61
+ data-slot="dialog-content"
62
+ className={cn(
63
+ "bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border p-6 shadow-lg duration-200 outline-none sm:max-w-lg",
64
+ className
65
+ )}
66
+ {...props}
67
+ >
68
+ {children}
69
+ {showCloseButton && (
70
+ <DialogPrimitive.Close
71
+ data-slot="dialog-close"
72
+ className="ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4"
73
+ >
74
+ <XIcon />
75
+ <span className="sr-only">Close</span>
76
+ </DialogPrimitive.Close>
77
+ )}
78
+ </DialogPrimitive.Content>
79
+ </DialogPortal>
80
+ )
81
+ }
82
+
83
+ function DialogHeader({ className, ...props }: React.ComponentProps<"div">) {
84
+ return (
85
+ <div
86
+ data-slot="dialog-header"
87
+ className={cn("flex flex-col gap-2 text-center sm:text-left", className)}
88
+ {...props}
89
+ />
90
+ )
91
+ }
92
+
93
+ function DialogFooter({ className, ...props }: React.ComponentProps<"div">) {
94
+ return (
95
+ <div
96
+ data-slot="dialog-footer"
97
+ className={cn(
98
+ "flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",
99
+ className
100
+ )}
101
+ {...props}
102
+ />
103
+ )
104
+ }
105
+
106
+ function DialogTitle({
107
+ className,
108
+ ...props
109
+ }: React.ComponentProps<typeof DialogPrimitive.Title>) {
110
+ return (
111
+ <DialogPrimitive.Title
112
+ data-slot="dialog-title"
113
+ className={cn("text-lg leading-none font-semibold", className)}
114
+ {...props}
115
+ />
116
+ )
117
+ }
118
+
119
+ function DialogDescription({
120
+ className,
121
+ ...props
122
+ }: React.ComponentProps<typeof DialogPrimitive.Description>) {
123
+ return (
124
+ <DialogPrimitive.Description
125
+ data-slot="dialog-description"
126
+ className={cn("text-muted-foreground text-sm", className)}
127
+ {...props}
128
+ />
129
+ )
130
+ }
131
+
132
+ export {
133
+ Dialog,
134
+ DialogClose,
135
+ DialogContent,
136
+ DialogDescription,
137
+ DialogFooter,
138
+ DialogHeader,
139
+ DialogOverlay,
140
+ DialogPortal,
141
+ DialogTitle,
142
+ DialogTrigger,
143
+ }
@@ -0,0 +1,22 @@
1
+ import * as React from "react"
2
+
3
+ import { cn } from "@/lib/utils"
4
+
5
+ function Input({ className, type, ...props }: React.ComponentProps<"input">) {
6
+ return (
7
+ <input
8
+ type={type}
9
+ data-slot="input"
10
+ className={cn(
11
+ "file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground border-input h-9 w-full min-w-0 rounded-xl border bg-white/45 px-3 py-1 text-base shadow-sm backdrop-blur-md transition-[color,box-shadow] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
12
+ "border-white/40 dark:border-white/14 dark:bg-white/6",
13
+ "focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]",
14
+ "aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
15
+ className
16
+ )}
17
+ {...props}
18
+ />
19
+ )
20
+ }
21
+
22
+ export { Input }
@@ -0,0 +1,59 @@
1
+ "use client"
2
+
3
+ import * as React from "react"
4
+ import * as ScrollAreaPrimitive from "@radix-ui/react-scroll-area"
5
+
6
+ import { cn } from "@/lib/utils"
7
+
8
+ const ScrollArea = React.forwardRef<
9
+ React.ElementRef<typeof ScrollAreaPrimitive.Viewport>,
10
+ React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.Root>
11
+ >(({ className, children, ...props }, ref) => {
12
+ return (
13
+ <ScrollAreaPrimitive.Root
14
+ data-slot="scroll-area"
15
+ className={cn("relative", className)}
16
+ {...props}
17
+ >
18
+ <ScrollAreaPrimitive.Viewport
19
+ ref={ref}
20
+ data-slot="scroll-area-viewport"
21
+ className="focus-visible:ring-ring/50 size-full rounded-[inherit] transition-[color,box-shadow] outline-none focus-visible:ring-[3px] focus-visible:outline-1"
22
+ >
23
+ {children}
24
+ </ScrollAreaPrimitive.Viewport>
25
+ <ScrollBar />
26
+ <ScrollAreaPrimitive.Corner />
27
+ </ScrollAreaPrimitive.Root>
28
+ )
29
+ })
30
+ ScrollArea.displayName = "ScrollArea"
31
+
32
+ function ScrollBar({
33
+ className,
34
+ orientation = "vertical",
35
+ ...props
36
+ }: React.ComponentProps<typeof ScrollAreaPrimitive.ScrollAreaScrollbar>) {
37
+ return (
38
+ <ScrollAreaPrimitive.ScrollAreaScrollbar
39
+ data-slot="scroll-area-scrollbar"
40
+ orientation={orientation}
41
+ className={cn(
42
+ "flex touch-none p-0.5 transition-colors select-none",
43
+ orientation === "vertical" &&
44
+ "h-full w-2 border-l border-l-transparent",
45
+ orientation === "horizontal" &&
46
+ "h-2 flex-col border-t border-t-transparent",
47
+ className
48
+ )}
49
+ {...props}
50
+ >
51
+ <ScrollAreaPrimitive.ScrollAreaThumb
52
+ data-slot="scroll-area-thumb"
53
+ className="bg-border/80 hover:bg-border relative flex-1 rounded-full"
54
+ />
55
+ </ScrollAreaPrimitive.ScrollAreaScrollbar>
56
+ )
57
+ }
58
+
59
+ export { ScrollArea, ScrollBar }
@@ -0,0 +1,28 @@
1
+ "use client"
2
+
3
+ import * as React from "react"
4
+ import * as SeparatorPrimitive from "@radix-ui/react-separator"
5
+
6
+ import { cn } from "@/lib/utils"
7
+
8
+ function Separator({
9
+ className,
10
+ orientation = "horizontal",
11
+ decorative = true,
12
+ ...props
13
+ }: React.ComponentProps<typeof SeparatorPrimitive.Root>) {
14
+ return (
15
+ <SeparatorPrimitive.Root
16
+ data-slot="separator"
17
+ decorative={decorative}
18
+ orientation={orientation}
19
+ className={cn(
20
+ "bg-border shrink-0 data-[orientation=horizontal]:h-px data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-px",
21
+ className
22
+ )}
23
+ {...props}
24
+ />
25
+ )
26
+ }
27
+
28
+ export { Separator }
@@ -0,0 +1,300 @@
1
+ "use server";
2
+
3
+ import {
4
+ getPendingRequests,
5
+ getRequestsByAgent,
6
+ getResponsesByAgent,
7
+ getAllAgents,
8
+ getAgentDisplayNames,
9
+ upsertAgentDisplayName,
10
+ getAgentLastRequest,
11
+ getPendingCountByAgent,
12
+ getAgentTimeline,
13
+ getAgentLastResponse,
14
+ sendResponse,
15
+ createGroup,
16
+ getAllGroups,
17
+ getGroupMembers,
18
+ getGroupLastRequest,
19
+ getGroupLastResponse,
20
+ addGroupMember,
21
+ removeGroupMember,
22
+ deleteGroup,
23
+ updateGroupName,
24
+ getGroupPendingCount,
25
+ getGroupPendingRequests,
26
+ getGroupTimeline,
27
+ type CueResponse,
28
+ } from "./db";
29
+
30
+ // Import/export from the shared types file
31
+ import type { ConversationItem, UserResponse } from "./types";
32
+ export type { Group, UserResponse, ImageContent, ConversationItem } from "./types";
33
+ export type { CueRequest, CueResponse, AgentTimelineItem } from "./db";
34
+ import { v4 as uuidv4 } from "uuid";
35
+
36
+ export async function fetchAgentDisplayNames(agentIds: string[]) {
37
+ return getAgentDisplayNames(agentIds);
38
+ }
39
+
40
+ export async function setAgentDisplayName(agentId: string, displayName: string) {
41
+ upsertAgentDisplayName(agentId, displayName);
42
+ return { success: true } as const;
43
+ }
44
+
45
+ // Agent
46
+ export async function fetchAllAgents() {
47
+ return getAllAgents();
48
+ }
49
+
50
+ export async function fetchAgentRequests(agentName: string) {
51
+ return getRequestsByAgent(agentName);
52
+ }
53
+
54
+ export async function fetchAgentResponses(agentName: string) {
55
+ return getResponsesByAgent(agentName);
56
+ }
57
+
58
+ export async function fetchAgentTimeline(
59
+ agentName: string,
60
+ before: string | null,
61
+ limit: number
62
+ ) {
63
+ return getAgentTimeline(agentName, before, limit);
64
+ }
65
+
66
+ export async function fetchAgentLastRequest(agentName: string) {
67
+ return getAgentLastRequest(agentName);
68
+ }
69
+
70
+ export async function fetchAgentPendingCount(agentName: string) {
71
+ return getPendingCountByAgent(agentName);
72
+ }
73
+
74
+ export async function fetchPendingRequests() {
75
+ return getPendingRequests();
76
+ }
77
+
78
+ // Responses
79
+ export async function submitResponse(
80
+ requestId: string,
81
+ text: string,
82
+ images: { mime_type: string; base64_data: string }[] = [],
83
+ mentions: { userId: string; start: number; length: number; display: string }[] = []
84
+ ) {
85
+ try {
86
+ const response: UserResponse = {
87
+ text,
88
+ images,
89
+ mentions: mentions.length > 0 ? mentions : undefined,
90
+ };
91
+ sendResponse(requestId, response, false);
92
+ return { success: true } as const;
93
+ } catch (e) {
94
+ return {
95
+ success: false,
96
+ error: e instanceof Error ? e.message : String(e),
97
+ } as const;
98
+ }
99
+ }
100
+
101
+ export async function cancelRequest(requestId: string) {
102
+ try {
103
+ const response: UserResponse = { text: "", images: [] };
104
+ sendResponse(requestId, response, true);
105
+ return { success: true } as const;
106
+ } catch (e) {
107
+ return {
108
+ success: false,
109
+ error: e instanceof Error ? e.message : String(e),
110
+ } as const;
111
+ }
112
+ }
113
+
114
+ export async function batchRespond(
115
+ requestIds: string[],
116
+ text: string,
117
+ images: { mime_type: string; base64_data: string }[] = [],
118
+ mentions: { userId: string; start: number; length: number; display: string }[] = []
119
+ ) {
120
+ try {
121
+ const response: UserResponse = {
122
+ text,
123
+ images,
124
+ mentions: mentions.length > 0 ? mentions : undefined,
125
+ };
126
+ for (const id of requestIds) {
127
+ sendResponse(id, response, false);
128
+ }
129
+ return { success: true, count: requestIds.length } as const;
130
+ } catch (e) {
131
+ return {
132
+ success: false,
133
+ error: e instanceof Error ? e.message : String(e),
134
+ } as const;
135
+ }
136
+ }
137
+
138
+ // Groups
139
+ export async function fetchAllGroups() {
140
+ return getAllGroups();
141
+ }
142
+
143
+ export async function fetchGroupMembers(groupId: string) {
144
+ return getGroupMembers(groupId);
145
+ }
146
+
147
+ export async function fetchGroupPendingCount(groupId: string) {
148
+ return getGroupPendingCount(groupId);
149
+ }
150
+
151
+ export async function fetchGroupPendingRequests(groupId: string) {
152
+ return getGroupPendingRequests(groupId);
153
+ }
154
+
155
+ export async function fetchGroupTimeline(
156
+ groupId: string,
157
+ before: string | null,
158
+ limit: number
159
+ ) {
160
+ return getGroupTimeline(groupId, before, limit);
161
+ }
162
+
163
+ export async function createNewGroup(name: string, members: string[]) {
164
+ try {
165
+ const id = `grp_${uuidv4().slice(0, 8)}`;
166
+ createGroup(id, name);
167
+ for (const member of members) {
168
+ addGroupMember(id, member);
169
+ }
170
+ return { success: true, id, name } as const;
171
+ } catch (e) {
172
+ return {
173
+ success: false,
174
+ error: e instanceof Error ? e.message : String(e),
175
+ } as const;
176
+ }
177
+ }
178
+
179
+ export async function addMemberToGroup(groupId: string, agentName: string) {
180
+ addGroupMember(groupId, agentName);
181
+ return { success: true };
182
+ }
183
+
184
+ export async function removeMemberFromGroup(
185
+ groupId: string,
186
+ agentName: string
187
+ ) {
188
+ removeGroupMember(groupId, agentName);
189
+ return { success: true };
190
+ }
191
+
192
+ export async function removeGroup(groupId: string) {
193
+ deleteGroup(groupId);
194
+ return { success: true };
195
+ }
196
+
197
+ export async function setGroupName(groupId: string, name: string) {
198
+ updateGroupName(groupId, name);
199
+ return { success: true } as const;
200
+ }
201
+
202
+ // Aggregated data
203
+ export async function fetchConversationList(): Promise<ConversationItem[]> {
204
+ const agents = getAllAgents();
205
+ const groups = getAllGroups();
206
+
207
+ const agentNameMap = getAgentDisplayNames(agents);
208
+
209
+ const items: ConversationItem[] = [];
210
+
211
+ const responsePreview = (r: CueResponse | undefined) => {
212
+ if (!r) return undefined;
213
+ try {
214
+ const parsed = JSON.parse(r.response_json || "{}") as {
215
+ text?: string;
216
+ images?: unknown[];
217
+ };
218
+ const text = (parsed.text || "").trim();
219
+ if (text) return `You: ${text}`;
220
+ if (Array.isArray(parsed.images) && parsed.images.length > 0) return "You: [image]";
221
+ return "You: [message]";
222
+ } catch {
223
+ return "You: [message]";
224
+ }
225
+ };
226
+
227
+ // Groups
228
+ for (const group of groups) {
229
+ const pendingCount = getGroupPendingCount(group.id);
230
+ const members = getGroupMembers(group.id);
231
+ const lastReq = getGroupLastRequest(group.id);
232
+
233
+ const lastResp = getGroupLastResponse(group.id);
234
+ const lastReqTime = lastReq?.created_at;
235
+ const lastRespTime = lastResp?.created_at;
236
+
237
+ const respMsg = responsePreview(lastResp);
238
+
239
+ const lastIsResp =
240
+ !!lastRespTime &&
241
+ (!lastReqTime || new Date(lastRespTime).getTime() >= new Date(lastReqTime).getTime());
242
+
243
+ const lastReqName = lastReq?.agent_id
244
+ ? agentNameMap[lastReq.agent_id] || lastReq.agent_id
245
+ : undefined;
246
+
247
+ items.push({
248
+ type: "group",
249
+ id: group.id,
250
+ name: group.name,
251
+ displayName: `${group.name} (${members.length} members)`,
252
+ pendingCount,
253
+ lastMessage: (
254
+ lastIsResp
255
+ ? respMsg
256
+ : lastReq?.prompt
257
+ ? `${lastReqName}: ${lastReq.prompt}`
258
+ : undefined
259
+ )?.slice(0, 50),
260
+ lastTime: (lastIsResp ? lastRespTime : lastReqTime) || group.created_at,
261
+ });
262
+ }
263
+
264
+ // Agents
265
+ for (const agent of agents) {
266
+ const pendingCount = getPendingCountByAgent(agent);
267
+ const lastReq = getAgentLastRequest(agent);
268
+ const lastResp = getAgentLastResponse(agent);
269
+ const lastReqTime = lastReq?.created_at;
270
+ const lastRespTime = lastResp?.created_at;
271
+
272
+ const respMsg = responsePreview(lastResp);
273
+ const reqMsg = lastReq?.prompt ? `Other: ${lastReq.prompt}` : undefined;
274
+
275
+ const lastIsResp =
276
+ !!lastRespTime &&
277
+ (!lastReqTime || new Date(lastRespTime).getTime() >= new Date(lastReqTime).getTime());
278
+
279
+ items.push({
280
+ type: "agent",
281
+ id: agent,
282
+ name: agent,
283
+ displayName: agentNameMap[agent] || agent,
284
+ pendingCount,
285
+ lastMessage: (lastIsResp ? respMsg : reqMsg)?.slice(0, 50),
286
+ lastTime: (lastIsResp ? lastRespTime : lastReqTime),
287
+ });
288
+ }
289
+
290
+ // Pin pending first, then sort by last activity time
291
+ items.sort((a, b) => {
292
+ if (a.pendingCount > 0 && b.pendingCount === 0) return -1;
293
+ if (a.pendingCount === 0 && b.pendingCount > 0) return 1;
294
+ if (!a.lastTime) return 1;
295
+ if (!b.lastTime) return -1;
296
+ return new Date(b.lastTime).getTime() - new Date(a.lastTime).getTime();
297
+ });
298
+
299
+ return items;
300
+ }