From 03f8ad90d2fc652e35574d5b133323f830d29400 Mon Sep 17 00:00:00 2001 From: yiling Date: Wed, 29 Jul 2026 10:10:07 +0800 Subject: [PATCH] feat(dashboard): add agent sessions view for team owners --- packages/api/src/agent.test.ts | 36 ++ packages/api/src/agent.ts | 16 + packages/core/src/agent/agent.test.ts | 60 +++ packages/core/src/agent/agent.ts | 61 +++- packages/core/src/upload/upload.ts | 8 +- packages/dtos/src/agent.ts | 18 + .../agent/agent-session-logs-dialog.tsx | 342 ++++++++++++++++++ .../webui/components/chat/message-card.tsx | 328 +---------------- .../dashboard/AgentSessionsDashboard.tsx | 194 ++++++++++ packages/webui/messages/en.json | 13 +- packages/webui/messages/zh.json | 13 +- packages/webui/paraglide/messages/_index.d.ts | 10 + packages/webui/paraglide/messages/_index.js | 12 +- .../webui/paraglide/messages/create_time.d.ts | 16 + .../webui/paraglide/messages/create_time.js | 29 ++ .../paraglide/messages/no_sessions_found.d.ts | 16 + .../paraglide/messages/no_sessions_found.js | 29 ++ .../paraglide/messages/session_name.d.ts | 16 + .../webui/paraglide/messages/session_name.js | 29 ++ .../paraglide/messages/session_type.d.ts | 16 + .../webui/paraglide/messages/session_type.js | 29 ++ .../paraglide/messages/session_type_chat.d.ts | 16 + .../paraglide/messages/session_type_chat.js | 29 ++ .../messages/session_type_comment.d.ts | 16 + .../messages/session_type_comment.js | 29 ++ .../messages/session_type_naming.d.ts | 16 + .../paraglide/messages/session_type_naming.js | 29 ++ .../webui/paraglide/messages/sessions.d.ts | 16 + packages/webui/paraglide/messages/sessions.js | 29 ++ .../messages/sessions_description.d.ts | 16 + .../messages/sessions_description.js | 29 ++ .../paraglide/messages/untitled_session.d.ts | 16 + .../paraglide/messages/untitled_session.js | 29 ++ .../routes/teams/$teamId/dashboard.lazy.tsx | 22 +- 34 files changed, 1249 insertions(+), 334 deletions(-) create mode 100644 packages/webui/components/agent/agent-session-logs-dialog.tsx create mode 100644 packages/webui/components/dashboard/AgentSessionsDashboard.tsx create mode 100644 packages/webui/paraglide/messages/create_time.d.ts create mode 100644 packages/webui/paraglide/messages/create_time.js create mode 100644 packages/webui/paraglide/messages/no_sessions_found.d.ts create mode 100644 packages/webui/paraglide/messages/no_sessions_found.js create mode 100644 packages/webui/paraglide/messages/session_name.d.ts create mode 100644 packages/webui/paraglide/messages/session_name.js create mode 100644 packages/webui/paraglide/messages/session_type.d.ts create mode 100644 packages/webui/paraglide/messages/session_type.js create mode 100644 packages/webui/paraglide/messages/session_type_chat.d.ts create mode 100644 packages/webui/paraglide/messages/session_type_chat.js create mode 100644 packages/webui/paraglide/messages/session_type_comment.d.ts create mode 100644 packages/webui/paraglide/messages/session_type_comment.js create mode 100644 packages/webui/paraglide/messages/session_type_naming.d.ts create mode 100644 packages/webui/paraglide/messages/session_type_naming.js create mode 100644 packages/webui/paraglide/messages/sessions.d.ts create mode 100644 packages/webui/paraglide/messages/sessions.js create mode 100644 packages/webui/paraglide/messages/sessions_description.d.ts create mode 100644 packages/webui/paraglide/messages/sessions_description.js create mode 100644 packages/webui/paraglide/messages/untitled_session.d.ts create mode 100644 packages/webui/paraglide/messages/untitled_session.js diff --git a/packages/api/src/agent.test.ts b/packages/api/src/agent.test.ts index 0b78eceb..95f0a344 100644 --- a/packages/api/src/agent.test.ts +++ b/packages/api/src/agent.test.ts @@ -193,4 +193,40 @@ describe('Agent API', () => { expect(res.status).toBe(500) }) }) + + describe('GET /teams/:teamId/agent-sessions', () => { + it('returns paginated agent sessions for team', async () => { + const mockSessionsData = { + data: [ + { + id: 'session1', + name: 'Session 1', + type: 'chat', + createdAt: new Date().toISOString(), + creator: { id: 'u1', name: 'User 1', email: 'u1@shumai.ai', image: null }, + agentId: 'agent1', + }, + ], + pageInfo: { total: 1 }, + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any + vi.mocked(agentService.listSessions).mockResolvedValue(mockSessionsData as any) + + const res = await app.request('/teams/team1/agent-sessions?first=20', { + headers: { 'Content-Type': 'application/json' }, + }) + + expect(res.status).toBe(200) + const data = (await res.json()) as typeof mockSessionsData + expect(data.data).toHaveLength(1) + expect(data.data[0].id).toBe('session1') + expect(data.pageInfo.total).toBe(1) + expect(authzService.hasPermission).toHaveBeenCalledWith({ + user: undefined, + permission: 'Admin', + type: 'team', + id: 'team1', + }) + }) + }) }) diff --git a/packages/api/src/agent.ts b/packages/api/src/agent.ts index 5717fb63..40000ba6 100644 --- a/packages/api/src/agent.ts +++ b/packages/api/src/agent.ts @@ -6,6 +6,7 @@ import { getAvatarUrl } from '@shumai/core/src/user/avatar' import { createAgentRequestSchema, updateAgentRequestSchema, + paginationParamsSchema, AgentInfo, AgentType, } from '@shumai/dtos' @@ -171,5 +172,20 @@ const route = new Hono<{ Variables: { user: User } }>() return c.json(infos, 200) }) + .get('/teams/:teamId/agent-sessions', zValidator('query', paginationParamsSchema), async (c) => { + const teamId = c.req.param('teamId') + const userReq = c.get('user') + const query = c.req.valid('query') + + await authzService.hasPermission({ + user: userReq, + permission: Permission.Admin, + type: ResourceType.Team, + id: teamId, + }) + + const res = await agentService.listSessions(teamId, query) + return c.json(res, 200) + }) export default route diff --git a/packages/core/src/agent/agent.test.ts b/packages/core/src/agent/agent.test.ts index 1361ba32..5544ceb3 100644 --- a/packages/core/src/agent/agent.test.ts +++ b/packages/core/src/agent/agent.test.ts @@ -339,4 +339,64 @@ describe('AgentService', () => { expect(entries[1].id).toBe(entry2.id) }) }) + + describe('listSessions', () => { + test('lists sessions for team and excludes pending id', async () => { + const db = prisma + const svc = new AgentService() + const { team, agent } = await setupTestData(db) + + const user = await db.user.create({ + data: { + name: 'Regular User', + email: 'user@shumai.ai', + }, + }) + + const session1 = await db.agentSession.create({ + data: { + name: 'Session One', + agentId: agent.id, + userId: user.id, + type: 'chat', + cwd: '/tmp', + }, + }) + + const session2 = await db.agentSession.create({ + data: { + name: 'Session Two', + agentId: agent.id, + userId: user.id, + type: 'comment', + cwd: '/tmp', + }, + }) + + // Pending session - should be excluded! + await db.agentSession.create({ + data: { + id: 'pending', + name: 'Pending Session', + agentId: agent.id, + userId: user.id, + type: 'chat', + cwd: '/tmp', + }, + }) + + const res = await svc.listSessions(team.id, { first: 10 }) + + expect(res.data).toHaveLength(2) + expect(res.data.map((s) => s.id)).not.toContain('pending') + const sessionIds = res.data.map((s) => s.id) + expect(sessionIds).toContain(session1.id) + expect(sessionIds).toContain(session2.id) + + const found = res.data.find((s) => s.id === session1.id) + expect(found?.name).toBe('Session One') + expect(found?.type).toBe('chat') + expect(found?.creator?.name).toBe('Regular User') + }) + }) }) diff --git a/packages/core/src/agent/agent.ts b/packages/core/src/agent/agent.ts index 1d9c470f..25879ed0 100644 --- a/packages/core/src/agent/agent.ts +++ b/packages/core/src/agent/agent.ts @@ -1,10 +1,16 @@ -import { prisma } from '@shumai/db' +import { prisma, type Prisma } from '@shumai/db' import { CreateAgentParams, DeleteAgentParams, ListAgentsParams, UpdateAgentParams, + AgentSessionInfo, } from '@shumai/dtos' +import { + paginateQuery, + type PaginatedData, + type PaginationParams, +} from '@shumai/core/src/pagination' import '@shumai/db/src/prisma-json-types' import { s3Service } from '@shumai/core/src/s3/s3' import AdmZip from 'adm-zip' @@ -388,6 +394,59 @@ export class AgentService { } }) } + + async listSessions( + teamId: string, + params: PaginationParams, + ): Promise> { + const where: Prisma.AgentSessionWhereInput = { + id: { not: 'pending' }, + agent: { + teamId, + }, + } + + return await paginateQuery( + async (skip, take) => { + const sessions = await this.prismaClient.agentSession.findMany({ + where, + skip, + take, + orderBy: { id: 'desc' }, + include: { + user: { + select: { + id: true, + name: true, + email: true, + image: true, + }, + }, + }, + }) + + return sessions.map((s) => ({ + id: s.id, + name: s.name, + type: s.type, + createdAt: s.createdAt.toISOString(), + creator: s.user + ? { + id: s.user.id, + name: s.user.name, + email: s.user.email, + image: s.user.image, + } + : null, + agentId: s.agentId, + })) + }, + async () => { + return this.prismaClient.agentSession.count({ where }) + }, + params, + ) + } } export const agentService = new AgentService() diff --git a/packages/core/src/upload/upload.ts b/packages/core/src/upload/upload.ts index a7595c9c..9df9eb86 100644 --- a/packages/core/src/upload/upload.ts +++ b/packages/core/src/upload/upload.ts @@ -1,13 +1,7 @@ import { assetService } from '@shumai/core/src/asset/asset' import { PaginatedData, PaginationParams, paginateQuery } from '@shumai/core/src/pagination' import { s3Service } from '@shumai/core/src/s3/s3' -import { - AssetStatus, - AssetType, - Prisma, - TaskStatus, - prisma, -} from '@shumai/db' +import { AssetStatus, AssetType, Prisma, TaskStatus, prisma } from '@shumai/db' import { ConfirmFileUploadRequest, CreateUploadTaskRequest, diff --git a/packages/dtos/src/agent.ts b/packages/dtos/src/agent.ts index cae05720..b66856ff 100644 --- a/packages/dtos/src/agent.ts +++ b/packages/dtos/src/agent.ts @@ -110,3 +110,21 @@ export const agentSessionEntrySchema = z.object({ entry: z.unknown(), }) export type AgentSessionEntryInfo = z.infer + +export const agentSessionSchema = z.object({ + id: z.string(), + name: z.string().nullable().optional(), + type: z.string(), + createdAt: z.string(), + creator: z + .object({ + id: z.string(), + name: z.string().nullable().optional(), + email: z.string().nullable().optional(), + image: z.string().nullable().optional(), + }) + .nullable() + .optional(), + agentId: z.string().optional(), +}) +export type AgentSessionInfo = z.infer diff --git a/packages/webui/components/agent/agent-session-logs-dialog.tsx b/packages/webui/components/agent/agent-session-logs-dialog.tsx new file mode 100644 index 00000000..18df764a --- /dev/null +++ b/packages/webui/components/agent/agent-session-logs-dialog.tsx @@ -0,0 +1,342 @@ +import React from 'react' +import { useQuery } from '@tanstack/react-query' +import { client } from '@/ui/api/client' +import { + Dialog, + DialogContent, + DialogDescription, + DialogHeader, + DialogTitle, +} from '@/ui/components/ui/dialog' +import { Separator } from '@/ui/components/ui/separator' +import { Skeleton } from '@/ui/components/ui/skeleton' +import { formatTimeAgo } from '@/ui/lib/time' +import { m } from '@/ui/paraglide/messages.js' +import { Terminal } from 'lucide-react' +import Markdown from 'react-markdown' + +interface AgentSessionLogsDialogProps { + sessionId?: string | null + open: boolean + onOpenChange: (open: boolean) => void +} + +const preprocessMarkdown = (text: string): string => { + return text.replace(/<@([a-zA-Z0-9_-]+)>/g, '@$1').replace(/^\[([^\]]+)\]:/gm, '\\[$1\\]:') +} + +export function AgentSessionLogsDialog({ + sessionId, + open, + onOpenChange, +}: AgentSessionLogsDialogProps) { + const { data: logs, isLoading: isLogsLoading } = useQuery({ + queryKey: ['agent-sessions', sessionId, 'entries'], + queryFn: async () => { + if (!sessionId) return [] + const res = await client.api['agent-sessions'][':sessionId'].entries.$get({ + param: { sessionId }, + }) + if (!res.ok) throw new Error('Failed to fetch session logs') + return await res.json() + }, + enabled: open && !!sessionId, + }) + + return ( + + + + + + {m.agent_session_logs()} + + {m.agent_logs_description()} + + +
+ {isLogsLoading ? ( +
+
+ +
+ + +
+
+
+ +
+ + +
+
+
+ ) : logs && logs.length > 0 ? ( +
+ {logs.map((entry) => { + const piEntry = entry.entry as Record | null + const timestampStr = + piEntry?.timestamp || (entry as Record).timestamp + let timestamp = '' + if (typeof timestampStr === 'string' || typeof timestampStr === 'number') { + const dateObj = new Date(timestampStr) + if (!isNaN(dateObj.getTime())) { + timestamp = formatTimeAgo(dateObj.toISOString()) + } + } + + if (piEntry && typeof piEntry === 'object') { + if (piEntry.type === 'message' && piEntry.message) { + const msg = piEntry.message as Record + let badgeColor = 'bg-gray-100 text-gray-800 dark:bg-gray-800 dark:text-gray-200' + let roleName: string = String(msg.role || '') + + if (msg.role === 'user') { + badgeColor = + 'bg-slate-100 text-slate-800 dark:bg-slate-900/30 dark:text-slate-300' + roleName = m.role_user() + } else if (msg.role === 'assistant') { + badgeColor = + 'bg-violet-100 text-violet-800 dark:bg-violet-900/30 dark:text-violet-300' + roleName = m.role_agent() + } else if (msg.role === 'toolResult') { + badgeColor = msg.isError + ? 'bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-300' + : 'bg-emerald-100 text-emerald-800 dark:bg-emerald-900/30 dark:text-emerald-300' + roleName = m.tool_result_with_name({ + name: String(msg.toolName || m.unknown()), + }) + } else if (msg.role === 'thought') { + badgeColor = + 'bg-amber-100 text-amber-800 dark:bg-amber-900/30 dark:text-amber-300' + roleName = m.role_thinking() + } + + const renderToolCallArguments = (args: unknown) => { + let parsedArgs: unknown = args + if (typeof args === 'string') { + try { + parsedArgs = JSON.parse(args) + } catch { + // ignore + } + } + + if ( + parsedArgs && + typeof parsedArgs === 'object' && + !Array.isArray(parsedArgs) + ) { + const obj = parsedArgs as Record + return ( +
+ {Object.entries(obj).map(([key, value]) => { + const valueStr = + value && typeof value === 'object' + ? JSON.stringify(value, null, 2) + : String(value) + return ( +
+ + {key}: + {' '} + + {valueStr} + +
+ ) + })} +
+ ) + } + + return ( +
{String(args)}
+ ) + } + + const renderMessageContent = () => { + const content = msg.content + if (!content) return null + + if (typeof content === 'string') { + if (!content.trim()) return null + return ( +
+ {preprocessMarkdown(content)} +
+ ) + } + + if (Array.isArray(content)) { + const renderedBlocks: React.ReactNode[] = [] + + content.forEach((item, idx) => { + if (!item) return + + if (typeof item === 'string') { + if (!item.trim()) return + renderedBlocks.push( +
+ {preprocessMarkdown(item)} +
, + ) + return + } + + if (typeof item === 'object') { + const itemObj = item as Record + const type = itemObj.type + if (type === 'text') { + const text = itemObj.text + if (typeof text !== 'string' || !text.trim()) return + renderedBlocks.push( +
+ {preprocessMarkdown(text)} +
, + ) + return + } + + if (type === 'toolCall') { + const toolName = String( + itemObj.name || itemObj.toolName || m.unknown(), + ) + const toolArgs = itemObj.arguments || itemObj.args + renderedBlocks.push( +
+
+ {m.calling_tool()}{' '} + + {toolName} + +
+ {!!toolArgs && ( +
+
+ {m.tool_arguments()} +
+ {renderToolCallArguments(toolArgs)} +
+ )} +
, + ) + return + } + + if (type === 'image') { + renderedBlocks.push( +
+ {m.image_object()} +
, + ) + return + } + + // Fallback for other object types + const stringified = JSON.stringify(item, null, 2) + if (stringified === '{}') return + renderedBlocks.push( +
+                                {stringified}
+                              
, + ) + } + }) + + if (renderedBlocks.length === 0) return null + + return ( +
+ {renderedBlocks.map((block, index) => ( + + {index > 0 && } + {block} + + ))} +
+ ) + } + + return null + } + + return ( +
+ {/* Timeline Line */} +
+ + {/* Timeline Node */} +
+ +
+
+ + {roleName} + + + {timestamp} + +
+ + {renderMessageContent()} +
+
+ ) + } + } + + // Fallback for non-message entries or arbitrary entries + return ( +
+
+
+
+
{timestamp}
+
+                        {JSON.stringify(entry.entry, null, 2)}
+                      
+
+
+ ) + })} +
+ ) : ( +
+ +

{m.no_logs_found()}

+

{m.session_no_entries_yet()}

+
+ )} +
+ +
+ ) +} diff --git a/packages/webui/components/chat/message-card.tsx b/packages/webui/components/chat/message-card.tsx index 00e81cd1..6a0bc376 100644 --- a/packages/webui/components/chat/message-card.tsx +++ b/packages/webui/components/chat/message-card.tsx @@ -1,12 +1,5 @@ import { client } from '@/ui/api/client' import { Button } from '@/ui/components/ui/button' -import { - Dialog, - DialogContent, - DialogDescription, - DialogHeader, - DialogTitle, -} from '@/ui/components/ui/dialog' import { DropdownMenu, DropdownMenuContent, @@ -23,11 +16,9 @@ import { AlertDialogHeader, AlertDialogTitle, } from '@/ui/components/ui/alert-dialog' -import { Separator } from '@/ui/components/ui/separator' -import { formatTimeAgo } from '@/ui/lib/time' import type { AttachmentInfo, CommentInfo, UserInfo } from '@shumai/dtos' import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query' -import { Download, File, Terminal, MoreHorizontal, Trash2 } from 'lucide-react' +import { Download, File, MoreHorizontal, Trash2 } from 'lucide-react' import React from 'react' import Markdown from 'react-markdown' import { Avatar, AvatarFallback, AvatarImage } from '../ui/avatar' @@ -37,6 +28,7 @@ import { formatTimecode } from '../viewers/video/utils' import { m } from '@/ui/paraglide/messages.js' import { useUiStore } from '@/ui/stores/ui' import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '../ui/tooltip' +import { AgentSessionLogsDialog } from '../agent/agent-session-logs-dialog' interface MessageCardProps { teamId?: string @@ -192,18 +184,6 @@ export const MessageCard: React.FC = ({ return false }, [me, message.creator?.id]) - const { data: logs, isLoading: isLogsLoading } = useQuery({ - queryKey: ['agent-sessions', message.sessionId, 'entries'], - queryFn: async () => { - const res = await client.api['agent-sessions'][':sessionId'].entries.$get({ - param: { sessionId: message.sessionId! }, - }) - if (!res.ok) throw new Error('Failed to fetch session logs') - return await res.json() - }, - enabled: isLogsOpen && !!message.sessionId, - }) - const renderFormattedMessage = (text: string) => { const parts = text.split(/(<@[a-zA-Z0-9_-]+>)/g) return parts.map((part, index) => { @@ -442,305 +422,11 @@ export const MessageCard: React.FC = ({ {/* Logs Dialog */} - - - - - - {m.agent_session_logs()} - - {m.agent_logs_description()} - - -
- {isLogsLoading ? ( -
-
- -
- - -
-
-
- -
- - -
-
-
- ) : logs && logs.length > 0 ? ( -
- {logs.map((entry) => { - const piEntry = entry.entry as Record | null - const timestampStr = - piEntry?.timestamp || (entry as Record).timestamp - let timestamp = '' - if (typeof timestampStr === 'string' || typeof timestampStr === 'number') { - const dateObj = new Date(timestampStr) - if (!isNaN(dateObj.getTime())) { - timestamp = formatTimeAgo(dateObj.toISOString()) - } - } - - if (piEntry && typeof piEntry === 'object') { - if (piEntry.type === 'message' && piEntry.message) { - const msg = piEntry.message as Record - let badgeColor = - 'bg-gray-100 text-gray-800 dark:bg-gray-800 dark:text-gray-200' - let roleName: string = String(msg.role || '') - - if (msg.role === 'user') { - badgeColor = - 'bg-slate-100 text-slate-800 dark:bg-slate-900/30 dark:text-slate-300' - roleName = m.role_user() - } else if (msg.role === 'assistant') { - badgeColor = - 'bg-violet-100 text-violet-800 dark:bg-violet-900/30 dark:text-violet-300' - roleName = m.role_agent() - } else if (msg.role === 'toolResult') { - badgeColor = msg.isError - ? 'bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-300' - : 'bg-emerald-100 text-emerald-800 dark:bg-emerald-900/30 dark:text-emerald-300' - roleName = m.tool_result_with_name({ - name: String(msg.toolName || m.unknown()), - }) - } else if (msg.role === 'thought') { - badgeColor = - 'bg-amber-100 text-amber-800 dark:bg-amber-900/30 dark:text-amber-300' - roleName = m.role_thinking() - } - - const renderToolCallArguments = (args: unknown) => { - let parsedArgs: unknown = args - if (typeof args === 'string') { - try { - parsedArgs = JSON.parse(args) - } catch { - // ignore - } - } - - if ( - parsedArgs && - typeof parsedArgs === 'object' && - !Array.isArray(parsedArgs) - ) { - const obj = parsedArgs as Record - return ( -
- {Object.entries(obj).map(([key, value]) => { - const valueStr = - value && typeof value === 'object' - ? JSON.stringify(value, null, 2) - : String(value) - return ( -
- - {key}: - {' '} - - {valueStr} - -
- ) - })} -
- ) - } - - return ( -
- {String(args)} -
- ) - } - - const renderMessageContent = () => { - const content = msg.content - if (!content) return null - - if (typeof content === 'string') { - if (!content.trim()) return null - return ( -
- {preprocessMarkdown(content)} -
- ) - } - - if (Array.isArray(content)) { - const renderedBlocks: React.ReactNode[] = [] - - content.forEach((item, idx) => { - if (!item) return - - if (typeof item === 'string') { - if (!item.trim()) return - renderedBlocks.push( -
- {preprocessMarkdown(item)} -
, - ) - return - } - - if (typeof item === 'object') { - const itemObj = item as Record - const type = itemObj.type - if (type === 'text') { - const text = itemObj.text - if (typeof text !== 'string' || !text.trim()) return - renderedBlocks.push( -
- {preprocessMarkdown(text)} -
, - ) - return - } - - if (type === 'toolCall') { - const toolName = String( - itemObj.name || itemObj.toolName || m.unknown(), - ) - const toolArgs = itemObj.arguments || itemObj.args - renderedBlocks.push( -
-
- {m.calling_tool()}{' '} - - {toolName} - -
- {!!toolArgs && ( -
-
- {m.tool_arguments()} -
- {renderToolCallArguments(toolArgs)} -
- )} -
, - ) - return - } - - if (type === 'image') { - renderedBlocks.push( -
- {m.image_object()} -
, - ) - return - } - - // Fallback for other object types - const stringified = JSON.stringify(item, null, 2) - if (stringified === '{}') return - renderedBlocks.push( -
-                                  {stringified}
-                                
, - ) - } - }) - - if (renderedBlocks.length === 0) return null - - return ( -
- {renderedBlocks.map((block, index) => ( - - {index > 0 && } - {block} - - ))} -
- ) - } - - return null - } - - return ( -
- {/* Timeline Line */} -
- - {/* Timeline Node */} -
- -
-
- - {roleName} - - - {timestamp} - -
- - {renderMessageContent()} -
-
- ) - } - } - - // Fallback for non-message entries or arbitrary entries - return ( -
-
-
-
-
{timestamp}
-
-                          {JSON.stringify(entry.entry, null, 2)}
-                        
-
-
- ) - })} -
- ) : ( -
- -

{m.no_logs_found()}

-

- {m.session_no_entries_yet()} -

-
- )} -
- -
+ e.stopPropagation()}> diff --git a/packages/webui/components/dashboard/AgentSessionsDashboard.tsx b/packages/webui/components/dashboard/AgentSessionsDashboard.tsx new file mode 100644 index 00000000..b2d710c9 --- /dev/null +++ b/packages/webui/components/dashboard/AgentSessionsDashboard.tsx @@ -0,0 +1,194 @@ +import { useEffect, useState } from 'react' +import { useInfiniteQuery } from '@tanstack/react-query' +import { useInView } from 'react-intersection-observer' +import { client } from '@/ui/api/client' +import { m } from '@/ui/paraglide/messages.js' +import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/ui/components/ui/card' +import { + Table, + TableBody, + TableCell, + TableHead, + TableHeader, + TableRow, +} from '@/ui/components/ui/table' +import { Avatar, AvatarFallback, AvatarImage } from '@/ui/components/ui/avatar' +import { Badge } from '@/ui/components/ui/badge' +import { Loader2, MessagesSquare } from 'lucide-react' +import { formatTimeAgo } from '@/ui/lib/time' +import { AgentSessionLogsDialog } from '../agent/agent-session-logs-dialog' + +interface AgentSessionsDashboardProps { + teamId: string +} + +export function AgentSessionsDashboard({ teamId }: AgentSessionsDashboardProps) { + const [selectedSessionId, setSelectedSessionId] = useState(null) + const { ref: loadMoreRef, inView } = useInView() + + const { data, isLoading, isError, fetchNextPage, hasNextPage, isFetchingNextPage } = + useInfiniteQuery({ + queryKey: ['teams', teamId, 'agent-sessions'], + queryFn: async ({ pageParam }) => { + const res = await client.api.teams[':teamId']['agent-sessions'].$get({ + param: { teamId }, + query: { + first: '20', + after: pageParam ? String(pageParam) : undefined, + }, + }) + if (!res.ok) throw new Error('Failed to fetch agent sessions') + return await res.json() + }, + initialPageParam: '', + getNextPageParam: (lastPage) => lastPage.pageInfo.cursor || undefined, + enabled: !!teamId, + }) + + useEffect(() => { + if (inView && hasNextPage && !isFetchingNextPage) { + fetchNextPage() + } + }, [inView, hasNextPage, isFetchingNextPage, fetchNextPage]) + + const allSessions = + data?.pages.flatMap((page) => page.data).filter((s) => s.id !== 'pending') || [] + const totalCount = data?.pages[0]?.pageInfo.total ?? allSessions.length + + const getSessionTypeBadge = (type: string) => { + switch (type) { + case 'comment': + return ( + + {m.session_type_comment()} + + ) + case 'chat': + return ( + + {m.session_type_chat()} + + ) + case 'naming': + return ( + + {m.session_type_naming()} + + ) + default: + return ( + + {type} + + ) + } + } + + return ( +
+ + +
+
+ + + {m.sessions()} ({totalCount}) + + + {m.sessions_description()} + +
+
+
+ + {isLoading ? ( +
+ +
+ ) : isError ? ( +
+ Failed to load agent sessions. +
+ ) : allSessions.length === 0 ? ( +
+ +

{m.no_sessions_found()}

+
+ ) : ( +
+ + + + {m.session_name()} + {m.creator()} + {m.session_type()} + {m.create_time()} + + + + {allSessions.map((session) => ( + setSelectedSessionId(session.id)} + className="cursor-pointer hover:bg-muted/50 transition-colors" + > + +
+ + {session.name || m.untitled_session()} + + + {session.id} + +
+
+ +
+ + + + {session.creator?.name?.[0]?.toUpperCase() || '?'} + + + + {session.creator?.name || 'System / Agent'} + +
+
+ {getSessionTypeBadge(session.type)} + + {formatTimeAgo(session.createdAt)} + +
+ ))} +
+
+
+ {isFetchingNextPage && ( + + )} +
+
+ )} +
+
+ + { + if (!open) setSelectedSessionId(null) + }} + /> +
+ ) +} diff --git a/packages/webui/messages/en.json b/packages/webui/messages/en.json index ac1a28f8..6b79c13c 100644 --- a/packages/webui/messages/en.json +++ b/packages/webui/messages/en.json @@ -885,5 +885,16 @@ "members_view": "Members", "access_denied": "Access Denied", "only_owner_dashboard": "Only team owners can access the dashboard.", - "role": "Role" + "role": "Role", + "sessions": "Sessions", + "sessions_description": "View and inspect all agent sessions created within the team.", + "session_name": "Session Name", + "creator": "Creator", + "create_time": "Create Time", + "session_type": "Session Type", + "no_sessions_found": "No sessions found", + "session_type_comment": "Comment", + "session_type_chat": "Chat", + "session_type_naming": "Naming", + "untitled_session": "Untitled Session" } diff --git a/packages/webui/messages/zh.json b/packages/webui/messages/zh.json index 04031fc7..207d3b79 100644 --- a/packages/webui/messages/zh.json +++ b/packages/webui/messages/zh.json @@ -885,5 +885,16 @@ "members_view": "成员", "access_denied": "访问被拒绝", "only_owner_dashboard": "只有团队所有者才能访问仪表盘。", - "role": "角色" + "role": "角色", + "sessions": "会话列表", + "sessions_description": "查看并检查团队内创建的所有 Agent 会话。", + "session_name": "会话名称", + "creator": "创建者", + "create_time": "创建时间", + "session_type": "会话类型", + "no_sessions_found": "未找到会话", + "session_type_comment": "评论", + "session_type_chat": "对话", + "session_type_naming": "命名", + "untitled_session": "未命名会话" } diff --git a/packages/webui/paraglide/messages/_index.d.ts b/packages/webui/paraglide/messages/_index.d.ts index cc08937b..ac915bf6 100644 --- a/packages/webui/paraglide/messages/_index.d.ts +++ b/packages/webui/paraglide/messages/_index.d.ts @@ -832,4 +832,14 @@ export * from "./members_view.js"; export * from "./access_denied.js"; export * from "./only_owner_dashboard.js"; export * from "./role.js"; +export * from "./sessions.js"; +export * from "./sessions_description.js"; +export * from "./session_name.js"; +export * from "./create_time.js"; +export * from "./session_type.js"; +export * from "./no_sessions_found.js"; +export * from "./session_type_comment.js"; +export * from "./session_type_chat.js"; +export * from "./session_type_naming.js"; +export * from "./untitled_session.js"; export type LocalizedString = import("../runtime.js").LocalizedString; diff --git a/packages/webui/paraglide/messages/_index.js b/packages/webui/paraglide/messages/_index.js index e2178a50..db862ce2 100644 --- a/packages/webui/paraglide/messages/_index.js +++ b/packages/webui/paraglide/messages/_index.js @@ -833,4 +833,14 @@ export * from './team_view.js' export * from './members_view.js' export * from './access_denied.js' export * from './only_owner_dashboard.js' -export * from './role.js' \ No newline at end of file +export * from './role.js' +export * from './sessions.js' +export * from './sessions_description.js' +export * from './session_name.js' +export * from './create_time.js' +export * from './session_type.js' +export * from './no_sessions_found.js' +export * from './session_type_comment.js' +export * from './session_type_chat.js' +export * from './session_type_naming.js' +export * from './untitled_session.js' \ No newline at end of file diff --git a/packages/webui/paraglide/messages/create_time.d.ts b/packages/webui/paraglide/messages/create_time.d.ts new file mode 100644 index 00000000..5fc35014 --- /dev/null +++ b/packages/webui/paraglide/messages/create_time.d.ts @@ -0,0 +1,16 @@ +/** +* | output | +* | --- | +* | "Create Time" | +* +* @param {Create_TimeInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const create_time: ((inputs?: Create_TimeInputs, options?: { + locale?: "en" | "zh"; +}) => LocalizedString) & import("../runtime.js").MessageMetadata; +export type LocalizedString = import("../runtime.js").LocalizedString; +export type Create_TimeInputs = {}; diff --git a/packages/webui/paraglide/messages/create_time.js b/packages/webui/paraglide/messages/create_time.js new file mode 100644 index 00000000..75527c7e --- /dev/null +++ b/packages/webui/paraglide/messages/create_time.js @@ -0,0 +1,29 @@ +/* eslint-disable */ +import { getLocale, experimentalStaticLocale } from '../runtime.js'; + +/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */ + +/** @typedef {{}} Create_TimeInputs */ + +const en_create_time = /** @type {(inputs: Create_TimeInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`Create Time`) +}; + +const zh_create_time = /** @type {(inputs: Create_TimeInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`创建时间`) +}; + +/** +* | output | +* | --- | +* | "Create Time" | +* +* @param {Create_TimeInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const create_time = /** @type {((inputs?: Create_TimeInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata} */ ((inputs = {}, options = {}) => { + const locale = experimentalStaticLocale ?? options.locale ?? getLocale() + if (locale === "en") return en_create_time(inputs) + return zh_create_time(inputs) +}); \ No newline at end of file diff --git a/packages/webui/paraglide/messages/no_sessions_found.d.ts b/packages/webui/paraglide/messages/no_sessions_found.d.ts new file mode 100644 index 00000000..1f2f3c0a --- /dev/null +++ b/packages/webui/paraglide/messages/no_sessions_found.d.ts @@ -0,0 +1,16 @@ +/** +* | output | +* | --- | +* | "No sessions found" | +* +* @param {No_Sessions_FoundInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const no_sessions_found: ((inputs?: No_Sessions_FoundInputs, options?: { + locale?: "en" | "zh"; +}) => LocalizedString) & import("../runtime.js").MessageMetadata; +export type LocalizedString = import("../runtime.js").LocalizedString; +export type No_Sessions_FoundInputs = {}; diff --git a/packages/webui/paraglide/messages/no_sessions_found.js b/packages/webui/paraglide/messages/no_sessions_found.js new file mode 100644 index 00000000..439a24fd --- /dev/null +++ b/packages/webui/paraglide/messages/no_sessions_found.js @@ -0,0 +1,29 @@ +/* eslint-disable */ +import { getLocale, experimentalStaticLocale } from '../runtime.js'; + +/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */ + +/** @typedef {{}} No_Sessions_FoundInputs */ + +const en_no_sessions_found = /** @type {(inputs: No_Sessions_FoundInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`No sessions found`) +}; + +const zh_no_sessions_found = /** @type {(inputs: No_Sessions_FoundInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`未找到会话`) +}; + +/** +* | output | +* | --- | +* | "No sessions found" | +* +* @param {No_Sessions_FoundInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const no_sessions_found = /** @type {((inputs?: No_Sessions_FoundInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata} */ ((inputs = {}, options = {}) => { + const locale = experimentalStaticLocale ?? options.locale ?? getLocale() + if (locale === "en") return en_no_sessions_found(inputs) + return zh_no_sessions_found(inputs) +}); \ No newline at end of file diff --git a/packages/webui/paraglide/messages/session_name.d.ts b/packages/webui/paraglide/messages/session_name.d.ts new file mode 100644 index 00000000..5c8ed0b8 --- /dev/null +++ b/packages/webui/paraglide/messages/session_name.d.ts @@ -0,0 +1,16 @@ +/** +* | output | +* | --- | +* | "Session Name" | +* +* @param {Session_NameInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const session_name: ((inputs?: Session_NameInputs, options?: { + locale?: "en" | "zh"; +}) => LocalizedString) & import("../runtime.js").MessageMetadata; +export type LocalizedString = import("../runtime.js").LocalizedString; +export type Session_NameInputs = {}; diff --git a/packages/webui/paraglide/messages/session_name.js b/packages/webui/paraglide/messages/session_name.js new file mode 100644 index 00000000..9ee39cee --- /dev/null +++ b/packages/webui/paraglide/messages/session_name.js @@ -0,0 +1,29 @@ +/* eslint-disable */ +import { getLocale, experimentalStaticLocale } from '../runtime.js'; + +/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */ + +/** @typedef {{}} Session_NameInputs */ + +const en_session_name = /** @type {(inputs: Session_NameInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`Session Name`) +}; + +const zh_session_name = /** @type {(inputs: Session_NameInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`会话名称`) +}; + +/** +* | output | +* | --- | +* | "Session Name" | +* +* @param {Session_NameInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const session_name = /** @type {((inputs?: Session_NameInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata} */ ((inputs = {}, options = {}) => { + const locale = experimentalStaticLocale ?? options.locale ?? getLocale() + if (locale === "en") return en_session_name(inputs) + return zh_session_name(inputs) +}); \ No newline at end of file diff --git a/packages/webui/paraglide/messages/session_type.d.ts b/packages/webui/paraglide/messages/session_type.d.ts new file mode 100644 index 00000000..acfe5262 --- /dev/null +++ b/packages/webui/paraglide/messages/session_type.d.ts @@ -0,0 +1,16 @@ +/** +* | output | +* | --- | +* | "Session Type" | +* +* @param {Session_TypeInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const session_type: ((inputs?: Session_TypeInputs, options?: { + locale?: "en" | "zh"; +}) => LocalizedString) & import("../runtime.js").MessageMetadata; +export type LocalizedString = import("../runtime.js").LocalizedString; +export type Session_TypeInputs = {}; diff --git a/packages/webui/paraglide/messages/session_type.js b/packages/webui/paraglide/messages/session_type.js new file mode 100644 index 00000000..75a6fb76 --- /dev/null +++ b/packages/webui/paraglide/messages/session_type.js @@ -0,0 +1,29 @@ +/* eslint-disable */ +import { getLocale, experimentalStaticLocale } from '../runtime.js'; + +/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */ + +/** @typedef {{}} Session_TypeInputs */ + +const en_session_type = /** @type {(inputs: Session_TypeInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`Session Type`) +}; + +const zh_session_type = /** @type {(inputs: Session_TypeInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`会话类型`) +}; + +/** +* | output | +* | --- | +* | "Session Type" | +* +* @param {Session_TypeInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const session_type = /** @type {((inputs?: Session_TypeInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata} */ ((inputs = {}, options = {}) => { + const locale = experimentalStaticLocale ?? options.locale ?? getLocale() + if (locale === "en") return en_session_type(inputs) + return zh_session_type(inputs) +}); \ No newline at end of file diff --git a/packages/webui/paraglide/messages/session_type_chat.d.ts b/packages/webui/paraglide/messages/session_type_chat.d.ts new file mode 100644 index 00000000..792b1fa3 --- /dev/null +++ b/packages/webui/paraglide/messages/session_type_chat.d.ts @@ -0,0 +1,16 @@ +/** +* | output | +* | --- | +* | "Chat" | +* +* @param {Session_Type_ChatInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const session_type_chat: ((inputs?: Session_Type_ChatInputs, options?: { + locale?: "en" | "zh"; +}) => LocalizedString) & import("../runtime.js").MessageMetadata; +export type LocalizedString = import("../runtime.js").LocalizedString; +export type Session_Type_ChatInputs = {}; diff --git a/packages/webui/paraglide/messages/session_type_chat.js b/packages/webui/paraglide/messages/session_type_chat.js new file mode 100644 index 00000000..511eac24 --- /dev/null +++ b/packages/webui/paraglide/messages/session_type_chat.js @@ -0,0 +1,29 @@ +/* eslint-disable */ +import { getLocale, experimentalStaticLocale } from '../runtime.js'; + +/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */ + +/** @typedef {{}} Session_Type_ChatInputs */ + +const en_session_type_chat = /** @type {(inputs: Session_Type_ChatInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`Chat`) +}; + +const zh_session_type_chat = /** @type {(inputs: Session_Type_ChatInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`对话`) +}; + +/** +* | output | +* | --- | +* | "Chat" | +* +* @param {Session_Type_ChatInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const session_type_chat = /** @type {((inputs?: Session_Type_ChatInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata} */ ((inputs = {}, options = {}) => { + const locale = experimentalStaticLocale ?? options.locale ?? getLocale() + if (locale === "en") return en_session_type_chat(inputs) + return zh_session_type_chat(inputs) +}); \ No newline at end of file diff --git a/packages/webui/paraglide/messages/session_type_comment.d.ts b/packages/webui/paraglide/messages/session_type_comment.d.ts new file mode 100644 index 00000000..39030a56 --- /dev/null +++ b/packages/webui/paraglide/messages/session_type_comment.d.ts @@ -0,0 +1,16 @@ +/** +* | output | +* | --- | +* | "Comment" | +* +* @param {Session_Type_CommentInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const session_type_comment: ((inputs?: Session_Type_CommentInputs, options?: { + locale?: "en" | "zh"; +}) => LocalizedString) & import("../runtime.js").MessageMetadata; +export type LocalizedString = import("../runtime.js").LocalizedString; +export type Session_Type_CommentInputs = {}; diff --git a/packages/webui/paraglide/messages/session_type_comment.js b/packages/webui/paraglide/messages/session_type_comment.js new file mode 100644 index 00000000..625d87da --- /dev/null +++ b/packages/webui/paraglide/messages/session_type_comment.js @@ -0,0 +1,29 @@ +/* eslint-disable */ +import { getLocale, experimentalStaticLocale } from '../runtime.js'; + +/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */ + +/** @typedef {{}} Session_Type_CommentInputs */ + +const en_session_type_comment = /** @type {(inputs: Session_Type_CommentInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`Comment`) +}; + +const zh_session_type_comment = /** @type {(inputs: Session_Type_CommentInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`评论`) +}; + +/** +* | output | +* | --- | +* | "Comment" | +* +* @param {Session_Type_CommentInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const session_type_comment = /** @type {((inputs?: Session_Type_CommentInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata} */ ((inputs = {}, options = {}) => { + const locale = experimentalStaticLocale ?? options.locale ?? getLocale() + if (locale === "en") return en_session_type_comment(inputs) + return zh_session_type_comment(inputs) +}); \ No newline at end of file diff --git a/packages/webui/paraglide/messages/session_type_naming.d.ts b/packages/webui/paraglide/messages/session_type_naming.d.ts new file mode 100644 index 00000000..921cfd06 --- /dev/null +++ b/packages/webui/paraglide/messages/session_type_naming.d.ts @@ -0,0 +1,16 @@ +/** +* | output | +* | --- | +* | "Naming" | +* +* @param {Session_Type_NamingInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const session_type_naming: ((inputs?: Session_Type_NamingInputs, options?: { + locale?: "en" | "zh"; +}) => LocalizedString) & import("../runtime.js").MessageMetadata; +export type LocalizedString = import("../runtime.js").LocalizedString; +export type Session_Type_NamingInputs = {}; diff --git a/packages/webui/paraglide/messages/session_type_naming.js b/packages/webui/paraglide/messages/session_type_naming.js new file mode 100644 index 00000000..db30b4fb --- /dev/null +++ b/packages/webui/paraglide/messages/session_type_naming.js @@ -0,0 +1,29 @@ +/* eslint-disable */ +import { getLocale, experimentalStaticLocale } from '../runtime.js'; + +/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */ + +/** @typedef {{}} Session_Type_NamingInputs */ + +const en_session_type_naming = /** @type {(inputs: Session_Type_NamingInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`Naming`) +}; + +const zh_session_type_naming = /** @type {(inputs: Session_Type_NamingInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`命名`) +}; + +/** +* | output | +* | --- | +* | "Naming" | +* +* @param {Session_Type_NamingInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const session_type_naming = /** @type {((inputs?: Session_Type_NamingInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata} */ ((inputs = {}, options = {}) => { + const locale = experimentalStaticLocale ?? options.locale ?? getLocale() + if (locale === "en") return en_session_type_naming(inputs) + return zh_session_type_naming(inputs) +}); \ No newline at end of file diff --git a/packages/webui/paraglide/messages/sessions.d.ts b/packages/webui/paraglide/messages/sessions.d.ts new file mode 100644 index 00000000..0412a66d --- /dev/null +++ b/packages/webui/paraglide/messages/sessions.d.ts @@ -0,0 +1,16 @@ +/** +* | output | +* | --- | +* | "Sessions" | +* +* @param {SessionsInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const sessions: ((inputs?: SessionsInputs, options?: { + locale?: "en" | "zh"; +}) => LocalizedString) & import("../runtime.js").MessageMetadata; +export type LocalizedString = import("../runtime.js").LocalizedString; +export type SessionsInputs = {}; diff --git a/packages/webui/paraglide/messages/sessions.js b/packages/webui/paraglide/messages/sessions.js new file mode 100644 index 00000000..e2d52304 --- /dev/null +++ b/packages/webui/paraglide/messages/sessions.js @@ -0,0 +1,29 @@ +/* eslint-disable */ +import { getLocale, experimentalStaticLocale } from '../runtime.js'; + +/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */ + +/** @typedef {{}} SessionsInputs */ + +const en_sessions = /** @type {(inputs: SessionsInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`Sessions`) +}; + +const zh_sessions = /** @type {(inputs: SessionsInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`会话列表`) +}; + +/** +* | output | +* | --- | +* | "Sessions" | +* +* @param {SessionsInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const sessions = /** @type {((inputs?: SessionsInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata} */ ((inputs = {}, options = {}) => { + const locale = experimentalStaticLocale ?? options.locale ?? getLocale() + if (locale === "en") return en_sessions(inputs) + return zh_sessions(inputs) +}); \ No newline at end of file diff --git a/packages/webui/paraglide/messages/sessions_description.d.ts b/packages/webui/paraglide/messages/sessions_description.d.ts new file mode 100644 index 00000000..9e44b22c --- /dev/null +++ b/packages/webui/paraglide/messages/sessions_description.d.ts @@ -0,0 +1,16 @@ +/** +* | output | +* | --- | +* | "View and inspect all agent sessions created within the team." | +* +* @param {Sessions_DescriptionInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const sessions_description: ((inputs?: Sessions_DescriptionInputs, options?: { + locale?: "en" | "zh"; +}) => LocalizedString) & import("../runtime.js").MessageMetadata; +export type LocalizedString = import("../runtime.js").LocalizedString; +export type Sessions_DescriptionInputs = {}; diff --git a/packages/webui/paraglide/messages/sessions_description.js b/packages/webui/paraglide/messages/sessions_description.js new file mode 100644 index 00000000..3578bedf --- /dev/null +++ b/packages/webui/paraglide/messages/sessions_description.js @@ -0,0 +1,29 @@ +/* eslint-disable */ +import { getLocale, experimentalStaticLocale } from '../runtime.js'; + +/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */ + +/** @typedef {{}} Sessions_DescriptionInputs */ + +const en_sessions_description = /** @type {(inputs: Sessions_DescriptionInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`View and inspect all agent sessions created within the team.`) +}; + +const zh_sessions_description = /** @type {(inputs: Sessions_DescriptionInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`查看并检查团队内创建的所有 Agent 会话。`) +}; + +/** +* | output | +* | --- | +* | "View and inspect all agent sessions created within the team." | +* +* @param {Sessions_DescriptionInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const sessions_description = /** @type {((inputs?: Sessions_DescriptionInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata} */ ((inputs = {}, options = {}) => { + const locale = experimentalStaticLocale ?? options.locale ?? getLocale() + if (locale === "en") return en_sessions_description(inputs) + return zh_sessions_description(inputs) +}); \ No newline at end of file diff --git a/packages/webui/paraglide/messages/untitled_session.d.ts b/packages/webui/paraglide/messages/untitled_session.d.ts new file mode 100644 index 00000000..c19a7510 --- /dev/null +++ b/packages/webui/paraglide/messages/untitled_session.d.ts @@ -0,0 +1,16 @@ +/** +* | output | +* | --- | +* | "Untitled Session" | +* +* @param {Untitled_SessionInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const untitled_session: ((inputs?: Untitled_SessionInputs, options?: { + locale?: "en" | "zh"; +}) => LocalizedString) & import("../runtime.js").MessageMetadata; +export type LocalizedString = import("../runtime.js").LocalizedString; +export type Untitled_SessionInputs = {}; diff --git a/packages/webui/paraglide/messages/untitled_session.js b/packages/webui/paraglide/messages/untitled_session.js new file mode 100644 index 00000000..fe036caf --- /dev/null +++ b/packages/webui/paraglide/messages/untitled_session.js @@ -0,0 +1,29 @@ +/* eslint-disable */ +import { getLocale, experimentalStaticLocale } from '../runtime.js'; + +/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */ + +/** @typedef {{}} Untitled_SessionInputs */ + +const en_untitled_session = /** @type {(inputs: Untitled_SessionInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`Untitled Session`) +}; + +const zh_untitled_session = /** @type {(inputs: Untitled_SessionInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`未命名会话`) +}; + +/** +* | output | +* | --- | +* | "Untitled Session" | +* +* @param {Untitled_SessionInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const untitled_session = /** @type {((inputs?: Untitled_SessionInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata} */ ((inputs = {}, options = {}) => { + const locale = experimentalStaticLocale ?? options.locale ?? getLocale() + if (locale === "en") return en_untitled_session(inputs) + return zh_untitled_session(inputs) +}); \ No newline at end of file diff --git a/packages/webui/routes/teams/$teamId/dashboard.lazy.tsx b/packages/webui/routes/teams/$teamId/dashboard.lazy.tsx index a928ba53..ed12f1c0 100644 --- a/packages/webui/routes/teams/$teamId/dashboard.lazy.tsx +++ b/packages/webui/routes/teams/$teamId/dashboard.lazy.tsx @@ -5,9 +5,10 @@ import { client } from '@/ui/api/client' import { cn } from '@/ui/lib/utils' import { m } from '@/ui/paraglide/messages.js' import { AiUsageDashboard } from '@/ui/components/dashboard/AiUsageDashboard' -import { BarChart2, Loader2, ShieldAlert } from 'lucide-react' +import { AgentSessionsDashboard } from '@/ui/components/dashboard/AgentSessionsDashboard' +import { BarChart2, Loader2, MessagesSquare, ShieldAlert } from 'lucide-react' -type DashboardTab = 'ai-usage' +type DashboardTab = 'ai-usage' | 'ai-sessions' function TeamDashboardPage() { const { teamId } = Route.useParams() @@ -72,6 +73,22 @@ function TeamDashboardPage() {
)} + +
@@ -79,6 +96,7 @@ function TeamDashboardPage() {
{activeTab === 'ai-usage' && } + {activeTab === 'ai-sessions' && }