mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-29 04:14:30 +00:00
feat(asset): record and display agent provenance on assets and audit logs (#380)
* feat(asset): record and display agent provenance on assets and audit logs * style(webui): apply 30% translucent frosted glass background to bot badges * style(webui): match bot icon badge style to thumbnail media overlay (bg-black/60 text-white) * style(webui): use "AI" text badge with pdf overlay style instead of bot icon
This commit is contained in:
@@ -92,6 +92,7 @@ interface BreadcrumbNavProps {
|
||||
name?: string | null
|
||||
previewUrl?: string | null
|
||||
creator?: { id: string; name: string | null } | null
|
||||
agent?: { id: string; name: string } | null
|
||||
}>
|
||||
compareMode?: boolean
|
||||
canCompareVersions?: boolean
|
||||
@@ -376,8 +377,20 @@ export function BreadcrumbNav({
|
||||
<span className="truncate text-sm font-semibold text-foreground">
|
||||
{v.name}
|
||||
</span>
|
||||
<span className="truncate text-xs text-muted-foreground">
|
||||
{v.creator?.name || 'Unknown'}
|
||||
<span className="truncate text-xs text-muted-foreground flex items-center gap-1">
|
||||
{v.agent ? (
|
||||
<>
|
||||
<Bot className="h-3 w-3 shrink-0" />
|
||||
<span className="truncate">
|
||||
{m.user_via_agent({
|
||||
user: v.creator?.name || m.unknown_user(),
|
||||
agent: v.agent.name,
|
||||
})}
|
||||
</span>
|
||||
</>
|
||||
) : (
|
||||
v.creator?.name || m.unknown_user()
|
||||
)}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ import { Input } from '@/ui/components/ui/input'
|
||||
import { Button } from '@/ui/components/ui/button'
|
||||
import { Popover, PopoverContent, PopoverTrigger } from '@/ui/components/ui/popover'
|
||||
import { Checkbox } from '@/ui/components/ui/checkbox'
|
||||
import { Loader2, Search, Filter, Activity, X } from 'lucide-react'
|
||||
import { Loader2, Search, Filter, Activity, X, Bot } from 'lucide-react'
|
||||
import { formatTimeAgo } from '@/ui/lib/time'
|
||||
|
||||
const ALL_AUDIT_ACTIONS = Object.values(AuditAction)
|
||||
@@ -353,9 +353,17 @@ export function AuditLogsDashboard({ teamId }: AuditLogsDashboardProps) {
|
||||
{userName.slice(0, 2).toUpperCase()}
|
||||
</AvatarFallback>
|
||||
</Avatar>
|
||||
<span className="text-xs font-medium text-foreground truncate max-w-[140px]">
|
||||
{userName}
|
||||
<span className="text-xs font-medium text-foreground truncate max-w-[160px]">
|
||||
{log.agent
|
||||
? m.user_via_agent({
|
||||
user: userName,
|
||||
agent: log.agent.name,
|
||||
})
|
||||
: userName}
|
||||
</span>
|
||||
{log.agent && (
|
||||
<Bot className="h-3.5 w-3.5 text-muted-foreground shrink-0" />
|
||||
)}
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell className="py-3 text-xs font-mono text-muted-foreground">
|
||||
|
||||
@@ -110,4 +110,45 @@ describe('FileCard', () => {
|
||||
|
||||
expect(screen.queryByText(/Manage versions|管理版本/i)).toBeNull()
|
||||
})
|
||||
|
||||
it('renders Bot icon badge and user via agent creator when agent created the asset', () => {
|
||||
const agentCreatedItem: AssetInfo = {
|
||||
...fileItem,
|
||||
creator: { id: 'u1', name: 'Alice' },
|
||||
agentId: 'agent-1',
|
||||
agent: { id: 'agent-1', name: 'Copilot Bot' },
|
||||
} as AssetInfo
|
||||
|
||||
renderComponent({ item: agentCreatedItem })
|
||||
|
||||
const agentBadge = screen.getByTestId('agent-badge')
|
||||
expect(agentBadge).toBeTruthy()
|
||||
expect(agentBadge.getAttribute('title')).toBe('Copilot Bot')
|
||||
expect(agentBadge.textContent).toBe('AI')
|
||||
|
||||
// Should show user via agent in author line
|
||||
expect(screen.getByText(/Alice via Copilot Bot|Alice 通过 Copilot Bot/i)).toBeTruthy()
|
||||
})
|
||||
|
||||
it('renders both AI text badge and version badge side-by-side on version stack', () => {
|
||||
const agentStackItem: AssetInfo = {
|
||||
...stackItem,
|
||||
creator: { id: 'u1', name: 'Alice' },
|
||||
agentId: 'agent-1',
|
||||
agent: { id: 'agent-1', name: 'Copilot Bot' },
|
||||
versionStack: {
|
||||
versions: [
|
||||
{ id: 'v1', version: 1, name: 'v1' },
|
||||
{ id: 'stack-123', version: 2, name: 'v2' },
|
||||
],
|
||||
},
|
||||
} as AssetInfo
|
||||
|
||||
renderComponent({ item: agentStackItem })
|
||||
|
||||
const agentBadge = screen.getByTestId('agent-badge')
|
||||
expect(agentBadge).toBeTruthy()
|
||||
expect(agentBadge.textContent).toBe('AI')
|
||||
expect(screen.getByText('v2')).toBeTruthy()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -254,13 +254,24 @@ export function FileCard({
|
||||
/>
|
||||
</div>
|
||||
|
||||
{displayItem.versionStack && (
|
||||
<Badge className="absolute right-2 top-2 z-10">
|
||||
v
|
||||
{displayItem.versionStack.versions.find((v) => v.id === displayItem.id)?.version ??
|
||||
displayItem.versionStack.versions.length}
|
||||
</Badge>
|
||||
)}
|
||||
<div className="absolute right-2 top-2 z-10 flex items-center gap-1.5">
|
||||
{displayItem.agent && (
|
||||
<span
|
||||
className="select-none rounded bg-black/60 px-1 py-0.5 text-xs font-medium text-white"
|
||||
title={displayItem.agent.name}
|
||||
data-testid="agent-badge"
|
||||
>
|
||||
AI
|
||||
</span>
|
||||
)}
|
||||
{displayItem.versionStack && (
|
||||
<Badge>
|
||||
v
|
||||
{displayItem.versionStack.versions.find((v) => v.id === displayItem.id)?.version ??
|
||||
displayItem.versionStack.versions.length}
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="relative aspect-square overflow-hidden bg-muted/30">
|
||||
{displayItem.status === 'uploading' ||
|
||||
@@ -310,7 +321,12 @@ export function FileCard({
|
||||
{displayItem.createdAt &&
|
||||
m.created_by_at({
|
||||
time: formatTimeAgo(displayItem.createdAt),
|
||||
author: displayItem.creator?.name || m.unknown_user(),
|
||||
author: displayItem.agent
|
||||
? m.user_via_agent({
|
||||
user: displayItem.creator?.name || m.unknown_user(),
|
||||
agent: displayItem.agent.name,
|
||||
})
|
||||
: displayItem.creator?.name || m.unknown_user(),
|
||||
})}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -244,6 +244,16 @@ export function FileListItem({
|
||||
</span>
|
||||
)}
|
||||
|
||||
{displayItem.agent && (
|
||||
<span
|
||||
className="select-none rounded bg-black/60 px-1 py-0.5 text-xs font-medium text-white shrink-0"
|
||||
title={displayItem.agent.name}
|
||||
data-testid="agent-badge"
|
||||
>
|
||||
AI
|
||||
</span>
|
||||
)}
|
||||
|
||||
{displayItem.versionStack && (
|
||||
<Badge variant="outline" className="px-1 py-0 text-xs shrink-0">
|
||||
v
|
||||
|
||||
@@ -200,4 +200,31 @@ describe('FileViewerLeftSidebar', () => {
|
||||
behavior: 'auto',
|
||||
})
|
||||
})
|
||||
|
||||
it('renders AI badge on carousel thumbnail when asset has agent', () => {
|
||||
const filesWithAgent: AssetInfo[] = [
|
||||
{
|
||||
id: 'file-agent',
|
||||
name: 'Agent File.png',
|
||||
proxyType: 'image',
|
||||
agentId: 'agent-1',
|
||||
agent: { id: 'agent-1', name: 'DrawBot' },
|
||||
} as AssetInfo,
|
||||
]
|
||||
|
||||
const { container } = render(
|
||||
<FileViewerLeftSidebar
|
||||
projectId="proj-1"
|
||||
currentAssetId="file-agent"
|
||||
parentFolderId="folder-1"
|
||||
initialFiles={filesWithAgent}
|
||||
initialNextCursor={undefined}
|
||||
/>,
|
||||
)
|
||||
|
||||
const agentBadge = container.querySelector('[data-testid="carousel-agent-badge"]')
|
||||
expect(agentBadge).toBeTruthy()
|
||||
expect(agentBadge?.getAttribute('title')).toBe('DrawBot')
|
||||
expect(agentBadge?.textContent).toBe('AI')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -136,13 +136,22 @@ export const FileViewerLeftSidebar: FC<FileViewerLeftSidebarProps> = ({
|
||||
params={{ projectId, fileId: file.id }}
|
||||
search={{ version: undefined }}
|
||||
className={cn(
|
||||
'rounded-lg border overflow-hidden flex items-center justify-center transition-all bg-muted/30 block',
|
||||
'rounded-lg border overflow-hidden flex items-center justify-center transition-all bg-muted/30 block relative',
|
||||
isActive
|
||||
? 'w-[62px] h-[62px] opacity-100'
|
||||
: 'w-[52px] h-[52px] opacity-60 hover:opacity-100',
|
||||
)}
|
||||
>
|
||||
<CarouselFilePreview item={file} />
|
||||
{file.agent && (
|
||||
<span
|
||||
className="absolute top-1 right-1 z-10 pointer-events-none select-none rounded bg-black/60 px-1 py-0.5 text-[10px] font-medium leading-none text-white"
|
||||
title={file.agent.name}
|
||||
data-testid="carousel-agent-badge"
|
||||
>
|
||||
AI
|
||||
</span>
|
||||
)}
|
||||
</Link>
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -16,7 +16,7 @@ import { isSortable, useSortable } from '@dnd-kit/react/sortable'
|
||||
import type { StackVersionInfo } from '@shumai/dtos'
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import { format, parseISO } from 'date-fns'
|
||||
import { FileIcon, GripVertical, MoreVertical, Trash2 } from 'lucide-react'
|
||||
import { Bot, FileIcon, GripVertical, MoreVertical, Trash2 } from 'lucide-react'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { toast } from 'sonner'
|
||||
|
||||
@@ -107,7 +107,19 @@ function SortableVersionRow({
|
||||
</span>
|
||||
{/* Row 2: Creator & Create Date */}
|
||||
<div className="flex items-center gap-1.5 text-xs text-muted-foreground truncate">
|
||||
<span>{version.creator?.name || m.unknown()}</span>
|
||||
{version.agent ? (
|
||||
<span className="flex items-center gap-1 truncate">
|
||||
<Bot className="h-3 w-3 shrink-0" />
|
||||
<span className="truncate">
|
||||
{m.user_via_agent({
|
||||
user: version.creator?.name || m.unknown(),
|
||||
agent: version.agent.name,
|
||||
})}
|
||||
</span>
|
||||
</span>
|
||||
) : (
|
||||
<span>{version.creator?.name || m.unknown()}</span>
|
||||
)}
|
||||
{formattedDate && (
|
||||
<>
|
||||
<span>•</span>
|
||||
|
||||
Reference in New Issue
Block a user