refactor: remove AgentRunLog related code and components
- Deleted AgentRunLogResponse struct from skill_response.go. - Removed agent_run_log_repository.go and agent_run_log_service.go files. - Eliminated AgentRunLogDetailDialog component and its related logic from the dashboard. - Removed agent run log fetching functions from admin API. - Updated navigation and localization files to remove references to agent run logs.
This commit is contained in:
@@ -1,440 +0,0 @@
|
||||
"use client"
|
||||
|
||||
import { useEffect, useMemo, useState, type ReactNode } from "react"
|
||||
import { BotMessageSquareIcon, WorkflowIcon } from "lucide-react"
|
||||
import { toast } from "sonner"
|
||||
|
||||
import { ImMessageHTML } from "@/components/im-message-html"
|
||||
import { JsonTreeViewer } from "@/components/json-tree-viewer"
|
||||
import { ProjectDialog } from "@/components/project-dialog"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { fetchAgentRunLog, type AgentRunLog } from "@/lib/api/admin"
|
||||
import { useI18n } from "@/i18n/provider"
|
||||
import { formatDateTime } from "@/lib/utils"
|
||||
|
||||
type AgentRunLogDetailDialogProps = {
|
||||
open: boolean
|
||||
logId: number | null
|
||||
onOpenChange: (open: boolean) => void
|
||||
}
|
||||
|
||||
type TFunction = (key: string, values?: Record<string, string | number>) => string
|
||||
|
||||
export function AgentRunLogDetailDialog({
|
||||
open,
|
||||
logId,
|
||||
onOpenChange,
|
||||
}: AgentRunLogDetailDialogProps) {
|
||||
const t = useI18n()
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [activeLog, setActiveLog] = useState<AgentRunLog | null>(null)
|
||||
|
||||
useEffect(() => {
|
||||
if (!open || !logId) {
|
||||
return
|
||||
}
|
||||
|
||||
let cancelled = false
|
||||
const currentLogId = logId
|
||||
|
||||
async function loadDetail() {
|
||||
setLoading(true)
|
||||
try {
|
||||
const data = await fetchAgentRunLog(currentLogId)
|
||||
if (!cancelled) {
|
||||
setActiveLog(data)
|
||||
}
|
||||
} catch (error) {
|
||||
if (!cancelled) {
|
||||
toast.error(error instanceof Error ? error.message : t("agentRunLog.loadDetailFailed"))
|
||||
onOpenChange(false)
|
||||
}
|
||||
} finally {
|
||||
if (!cancelled) {
|
||||
setLoading(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void loadDetail()
|
||||
|
||||
return () => {
|
||||
cancelled = true
|
||||
}
|
||||
}, [logId, onOpenChange, open, t])
|
||||
|
||||
useEffect(() => {
|
||||
if (open) {
|
||||
return
|
||||
}
|
||||
setLoading(false)
|
||||
setActiveLog(null)
|
||||
}, [open])
|
||||
|
||||
const activeTraceData = useMemo(
|
||||
() => safeParseJSON(activeLog?.traceData ?? ""),
|
||||
[activeLog?.traceData]
|
||||
)
|
||||
const activeToolSearchTrace = useMemo(
|
||||
() => safeParseJSON(activeLog?.toolSearchTrace ?? ""),
|
||||
[activeLog?.toolSearchTrace]
|
||||
)
|
||||
const activeGraphToolTrace = useMemo(
|
||||
() => safeParseJSON(activeLog?.graphToolTrace ?? ""),
|
||||
[activeLog?.graphToolTrace]
|
||||
)
|
||||
|
||||
return (
|
||||
<ProjectDialog
|
||||
open={open}
|
||||
onOpenChange={onOpenChange}
|
||||
title={
|
||||
<span className="flex items-center gap-2">
|
||||
<WorkflowIcon className="size-4" />
|
||||
{t("agentRunLog.detailTitle")}
|
||||
</span>
|
||||
}
|
||||
description={t("agentRunLog.detailDescription")}
|
||||
size="xl"
|
||||
allowFullscreen
|
||||
defaultFullscreen
|
||||
bodyClassName="min-h-0"
|
||||
footer={
|
||||
<Button variant="outline" onClick={() => onOpenChange(false)}>
|
||||
{t("agentRunLog.close")}
|
||||
</Button>
|
||||
}
|
||||
>
|
||||
{loading ? (
|
||||
<div className="py-10 text-sm text-muted-foreground">{t("agentRunLog.loading")}</div>
|
||||
) : activeLog ? (
|
||||
<>
|
||||
<MetaStrip
|
||||
items={[
|
||||
{ label: t("agentRunLog.logId"), value: String(activeLog.id) },
|
||||
{ label: t("agentRunLog.conversationId"), value: String(activeLog.conversationId || "-") },
|
||||
{ label: t("agentRunLog.messageId"), value: String(activeLog.messageId || "-") },
|
||||
{ label: "AI Agent", value: String(activeLog.aiAgentId || "-") },
|
||||
]}
|
||||
/>
|
||||
|
||||
<InfoBlock
|
||||
title={t("agentRunLog.planningStage")}
|
||||
lines={[
|
||||
`plannedAction: ${activeLog.plannedAction || "-"}`,
|
||||
`plannedSkillId: ${activeLog.plannedSkillId || "-"}`,
|
||||
`plannedSkillName: ${activeLog.plannedSkillName || "-"}`,
|
||||
`graphToolCode: ${activeLog.graphToolCode || "-"}`,
|
||||
`recommendedAction: ${activeLog.recommendedAction || "-"}`,
|
||||
`riskLevel: ${activeLog.riskLevel || "-"}`,
|
||||
`ticketDraftReady: ${activeLog.ticketDraftReady ? "true" : "false"}`,
|
||||
`plannedToolCode: ${activeLog.plannedToolCode || "-"}`,
|
||||
`planReason: ${activeLog.planReason || "-"}`,
|
||||
`handoffReason: ${activeLog.handoffReason || "-"}`,
|
||||
`skillRouteTrace: ${activeLog.skillRouteTrace || "-"}`,
|
||||
]}
|
||||
/>
|
||||
<InfoBlock
|
||||
title={t("agentRunLog.hitlStatus")}
|
||||
lines={[
|
||||
`hitlStatus: ${activeLog.hitlStatus || "-"}`,
|
||||
`hitlStatusName: ${getHitlStatusLabel(activeLog.hitlStatus, t) || "-"}`,
|
||||
`hitlSummary: ${getHitlSummary(activeLog.hitlStatus, t) || "-"}`,
|
||||
]}
|
||||
/>
|
||||
<InfoBlock
|
||||
title={t("agentRunLog.executionResult")}
|
||||
lines={[
|
||||
`finalAction: ${activeLog.finalAction || "-"}`,
|
||||
`finalStatus: ${activeLog.finalStatus || "-"}`,
|
||||
`interruptType: ${activeLog.interruptType || "-"}`,
|
||||
`resumeSource: ${activeLog.resumeSource || "-"}`,
|
||||
`latencyMs: ${activeLog.latencyMs} ms`,
|
||||
`createdAt: ${formatDateTime(activeLog.createdAt)}`,
|
||||
]}
|
||||
/>
|
||||
|
||||
<JsonBlock
|
||||
title={t("agentRunLog.dynamicTools")}
|
||||
jsonValue={activeToolSearchTrace}
|
||||
fallbackValue={activeLog.toolSearchTrace}
|
||||
/>
|
||||
<JsonBlock
|
||||
title={t("agentRunLog.graphToolCall")}
|
||||
jsonValue={activeGraphToolTrace}
|
||||
fallbackValue={activeLog.graphToolTrace}
|
||||
/>
|
||||
<TextBlock
|
||||
icon={<BotMessageSquareIcon className="size-4" />}
|
||||
title={t("agentRunLog.userMessage")}
|
||||
value={activeLog.userMessage}
|
||||
renderAsHtml
|
||||
/>
|
||||
<TextBlock
|
||||
icon={<WorkflowIcon className="size-4" />}
|
||||
title={t("agentRunLog.botReply")}
|
||||
value={activeLog.replyText}
|
||||
/>
|
||||
<TextBlock title={t("agentRunLog.errorMessage")} value={activeLog.errorMessage} tone="danger" />
|
||||
<JsonBlock
|
||||
title={t("agentRunLog.trace")}
|
||||
jsonValue={activeTraceData}
|
||||
fallbackValue={activeLog.traceData}
|
||||
/>
|
||||
</>
|
||||
) : (
|
||||
<div className="py-10 text-sm text-muted-foreground">{t("agentRunLog.notFound")}</div>
|
||||
)}
|
||||
</ProjectDialog>
|
||||
)
|
||||
}
|
||||
|
||||
function getHitlStatusLabel(status: string | undefined, t: TFunction) {
|
||||
switch (status) {
|
||||
case "pending":
|
||||
return t("agentRunLog.hitlPending")
|
||||
case "confirmed":
|
||||
return t("agentRunLog.hitlConfirmed")
|
||||
case "cancelled":
|
||||
return t("agentRunLog.hitlCancelled")
|
||||
case "expired":
|
||||
return t("agentRunLog.hitlExpired")
|
||||
case "triggered":
|
||||
return t("agentRunLog.hitlTriggered")
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
function getHitlSummary(status: string | undefined, t: TFunction) {
|
||||
switch (status) {
|
||||
case "pending":
|
||||
return t("agentRunLog.hitlPendingSummary")
|
||||
case "confirmed":
|
||||
return t("agentRunLog.hitlConfirmedSummary")
|
||||
case "cancelled":
|
||||
return t("agentRunLog.hitlCancelledSummary")
|
||||
case "expired":
|
||||
return t("agentRunLog.hitlExpiredSummary")
|
||||
case "triggered":
|
||||
return t("agentRunLog.hitlTriggeredSummary")
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
function safeParseJSON(value: string) {
|
||||
if (!value.trim()) {
|
||||
return null
|
||||
}
|
||||
try {
|
||||
return JSON.parse(value)
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
function MetaStrip({
|
||||
items,
|
||||
}: {
|
||||
items: Array<{ label: string; value: string }>
|
||||
}) {
|
||||
return (
|
||||
<div className="rounded-lg border bg-muted/20 px-4 py-3">
|
||||
<div className="flex flex-wrap gap-x-6 gap-y-2 text-sm">
|
||||
{items.map((item) => (
|
||||
<div key={item.label} className="flex min-w-0 items-center gap-2">
|
||||
<span className="shrink-0 text-xs text-muted-foreground">{item.label}</span>
|
||||
<span className="min-w-0 truncate font-medium">{item.value}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function InfoBlock({ title, lines }: { title: string; lines: string[] }) {
|
||||
return (
|
||||
<div className="rounded-lg border p-4">
|
||||
<div className="text-sm font-medium">{title}</div>
|
||||
<div className="mt-3 space-y-2 text-sm text-muted-foreground">
|
||||
{lines.map((line) => (
|
||||
<div key={line}>{line}</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function TextBlock({
|
||||
title,
|
||||
value,
|
||||
icon,
|
||||
tone = "default",
|
||||
renderAsHtml = false,
|
||||
}: {
|
||||
title: string
|
||||
value?: string
|
||||
icon?: ReactNode
|
||||
tone?: "default" | "danger"
|
||||
renderAsHtml?: boolean
|
||||
}) {
|
||||
const normalizedValue = value?.trim() || ""
|
||||
const html = useMemo(() => {
|
||||
if (!renderAsHtml || !normalizedValue) {
|
||||
return ""
|
||||
}
|
||||
return sanitizeRichHTML(normalizedValue)
|
||||
}, [normalizedValue, renderAsHtml])
|
||||
|
||||
return (
|
||||
<div className="rounded-lg border p-4">
|
||||
<div className="flex items-center gap-2 text-sm font-medium">
|
||||
{icon}
|
||||
{title}
|
||||
</div>
|
||||
{renderAsHtml && normalizedValue ? (
|
||||
<ImMessageHTML
|
||||
html={html}
|
||||
className="mt-3 select-text text-muted-foreground"
|
||||
/>
|
||||
) : (
|
||||
<div
|
||||
className={
|
||||
tone === "danger"
|
||||
? "mt-3 select-text whitespace-pre-wrap wrap-break-word text-sm text-destructive"
|
||||
: "mt-3 select-text whitespace-pre-wrap wrap-break-word text-sm text-muted-foreground"
|
||||
}
|
||||
>
|
||||
{normalizedValue || "-"}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function JsonBlock({
|
||||
title,
|
||||
jsonValue,
|
||||
fallbackValue,
|
||||
}: {
|
||||
title: string
|
||||
jsonValue: unknown
|
||||
fallbackValue?: string
|
||||
}) {
|
||||
const normalizedFallback = fallbackValue?.trim() || ""
|
||||
|
||||
return (
|
||||
<div className="rounded-lg border p-4">
|
||||
<div className="text-sm font-medium">{title}</div>
|
||||
{jsonValue ? (
|
||||
<JsonTreeViewer value={jsonValue} className="mt-3" />
|
||||
) : (
|
||||
<div className="mt-3 select-text whitespace-pre-wrap wrap-break-word text-sm text-muted-foreground">
|
||||
{normalizedFallback || "-"}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function sanitizeRichHTML(value: string) {
|
||||
if (typeof window === "undefined") {
|
||||
return value
|
||||
}
|
||||
|
||||
const doc = new DOMParser().parseFromString(value, "text/html")
|
||||
const allowedTags = new Set([
|
||||
"a",
|
||||
"b",
|
||||
"blockquote",
|
||||
"br",
|
||||
"code",
|
||||
"div",
|
||||
"em",
|
||||
"h1",
|
||||
"h2",
|
||||
"h3",
|
||||
"h4",
|
||||
"h5",
|
||||
"h6",
|
||||
"hr",
|
||||
"img",
|
||||
"li",
|
||||
"ol",
|
||||
"p",
|
||||
"pre",
|
||||
"span",
|
||||
"strong",
|
||||
"table",
|
||||
"tbody",
|
||||
"td",
|
||||
"th",
|
||||
"thead",
|
||||
"tr",
|
||||
"u",
|
||||
"ul",
|
||||
])
|
||||
const allowedAttrs = new Set([
|
||||
"alt",
|
||||
"class",
|
||||
"colspan",
|
||||
"href",
|
||||
"rel",
|
||||
"rowspan",
|
||||
"src",
|
||||
"target",
|
||||
"title",
|
||||
])
|
||||
const walker = doc.createTreeWalker(doc.body, NodeFilter.SHOW_ELEMENT)
|
||||
const elements: Element[] = []
|
||||
|
||||
while (walker.nextNode()) {
|
||||
elements.push(walker.currentNode as Element)
|
||||
}
|
||||
|
||||
for (const element of elements) {
|
||||
const tag = element.tagName.toLowerCase()
|
||||
if (!allowedTags.has(tag)) {
|
||||
element.replaceWith(...Array.from(element.childNodes))
|
||||
continue
|
||||
}
|
||||
|
||||
for (const attr of Array.from(element.attributes)) {
|
||||
const name = attr.name.toLowerCase()
|
||||
const attrValue = attr.value.trim()
|
||||
if (name.startsWith("on") || !allowedAttrs.has(name)) {
|
||||
element.removeAttribute(attr.name)
|
||||
continue
|
||||
}
|
||||
if ((name === "href" || name === "src") && !isSafeURL(attrValue)) {
|
||||
element.removeAttribute(attr.name)
|
||||
}
|
||||
}
|
||||
|
||||
if (tag === "a") {
|
||||
element.setAttribute("target", "_blank")
|
||||
element.setAttribute("rel", "noreferrer noopener")
|
||||
}
|
||||
}
|
||||
|
||||
return doc.body.innerHTML
|
||||
}
|
||||
|
||||
function isSafeURL(value: string) {
|
||||
if (!value) {
|
||||
return false
|
||||
}
|
||||
if (value.startsWith("/")) {
|
||||
return true
|
||||
}
|
||||
if (value.startsWith("data:image/")) {
|
||||
return true
|
||||
}
|
||||
try {
|
||||
const url = new URL(value, window.location.origin)
|
||||
return ["http:", "https:"].includes(url.protocol)
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -1,368 +0,0 @@
|
||||
"use client"
|
||||
|
||||
import { useEffect, useMemo, useState } from "react"
|
||||
import { SearchIcon } from "lucide-react"
|
||||
import { toast } from "sonner"
|
||||
|
||||
import { DashboardListPage } from "@/components/dashboard/list"
|
||||
import { Badge } from "@/components/ui/badge"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { AgentRunLogDetailDialog } from "./_components/detail"
|
||||
import {
|
||||
fetchAgentRunLogs,
|
||||
fetchAIAgentsAll,
|
||||
type AIAgent,
|
||||
type AgentRunLog,
|
||||
} from "@/lib/api/admin"
|
||||
import { useI18n } from "@/i18n/provider"
|
||||
import { formatDateTime } from "@/lib/utils"
|
||||
|
||||
type TFunction = (key: string, values?: Record<string, string | number>) => string
|
||||
|
||||
function getActionOptions(t: TFunction) {
|
||||
return [
|
||||
{ value: "all", label: t("agentRunLog.allActions") },
|
||||
{ value: "rag", label: "RAG" },
|
||||
{ value: "skill", label: "Skill" },
|
||||
{ value: "tool", label: "Tool" },
|
||||
{ value: "graph", label: "Graph" },
|
||||
{ value: "handoff", label: t("agentRunLog.handoff") },
|
||||
{ value: "reply", label: t("agentRunLog.reply") },
|
||||
{ value: "fallback", label: t("agentRunLog.fallback") },
|
||||
]
|
||||
}
|
||||
|
||||
function getFinalStatusOptions(t: TFunction) {
|
||||
return [
|
||||
{ value: "all", label: t("agentRunLog.allStatus") },
|
||||
{ value: "completed", label: "completed" },
|
||||
{ value: "interrupted", label: "interrupted" },
|
||||
{ value: "expired", label: "expired" },
|
||||
{ value: "error", label: "error" },
|
||||
{ value: "fallback", label: "fallback" },
|
||||
]
|
||||
}
|
||||
|
||||
function getHitlStatusOptions(t: TFunction) {
|
||||
return [
|
||||
{ value: "all", label: t("agentRunLog.allHitl") },
|
||||
{ value: "pending", label: t("agentRunLog.hitlPending") },
|
||||
{ value: "confirmed", label: t("agentRunLog.hitlConfirmed") },
|
||||
{ value: "cancelled", label: t("agentRunLog.hitlCancelled") },
|
||||
{ value: "expired", label: t("agentRunLog.hitlExpired") },
|
||||
{ value: "triggered", label: t("agentRunLog.hitlTriggered") },
|
||||
]
|
||||
}
|
||||
|
||||
function getHitlStatusLabel(status: string | undefined, t: TFunction) {
|
||||
switch (status) {
|
||||
case "pending":
|
||||
return t("agentRunLog.hitlPending")
|
||||
case "confirmed":
|
||||
return t("agentRunLog.hitlConfirmed")
|
||||
case "cancelled":
|
||||
return t("agentRunLog.hitlCancelled")
|
||||
case "expired":
|
||||
return t("agentRunLog.hitlExpired")
|
||||
case "triggered":
|
||||
return t("agentRunLog.hitlTriggered")
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
function actionBadgeVariant(action: string) {
|
||||
switch (action) {
|
||||
case "handoff":
|
||||
return "destructive" as const
|
||||
case "skill":
|
||||
return "default" as const
|
||||
case "tool":
|
||||
return "default" as const
|
||||
case "graph":
|
||||
return "default" as const
|
||||
case "rag":
|
||||
return "secondary" as const
|
||||
case "fallback":
|
||||
return "outline" as const
|
||||
default:
|
||||
return "secondary" as const
|
||||
}
|
||||
}
|
||||
|
||||
export default function DashboardAgentRunLogsPage() {
|
||||
const t = useI18n()
|
||||
const [detailOpen, setDetailOpen] = useState(false)
|
||||
const [activeLogId, setActiveLogId] = useState<number | null>(null)
|
||||
const [aiAgents, setAiAgents] = useState<AIAgent[]>([])
|
||||
const actionOptions = useMemo(() => getActionOptions(t), [t])
|
||||
const finalStatusOptions = useMemo(() => getFinalStatusOptions(t), [t])
|
||||
const hitlStatusOptions = useMemo(() => getHitlStatusOptions(t), [t])
|
||||
|
||||
const aiAgentOptions = useMemo(
|
||||
() => [
|
||||
{ value: "all", label: t("agentRunLog.allAgents") },
|
||||
...aiAgents.map((item) => ({
|
||||
value: String(item.id),
|
||||
label: item.name,
|
||||
})),
|
||||
],
|
||||
[aiAgents, t]
|
||||
)
|
||||
|
||||
useEffect(() => {
|
||||
async function loadAIAgents() {
|
||||
try {
|
||||
const data = await fetchAIAgentsAll()
|
||||
setAiAgents(data)
|
||||
} catch (error) {
|
||||
toast.error(error instanceof Error ? error.message : t("agentRunLog.loadAgentsFailed"))
|
||||
}
|
||||
}
|
||||
void loadAIAgents()
|
||||
}, [t])
|
||||
|
||||
return (
|
||||
<>
|
||||
<DashboardListPage<AgentRunLog>
|
||||
filters={[
|
||||
{
|
||||
name: "userMessage",
|
||||
label: t("agentRunLog.filterUserMessage"),
|
||||
placeholder: t("agentRunLog.filterUserMessage"),
|
||||
defaultValue: "",
|
||||
trim: true,
|
||||
className: "min-w-0",
|
||||
inputClassName: "pl-9",
|
||||
icon: <SearchIcon className="size-4" />,
|
||||
},
|
||||
{
|
||||
name: "plannedAction",
|
||||
label: t("agentRunLog.plannedAction"),
|
||||
type: "select",
|
||||
defaultValue: "all",
|
||||
allValue: "all",
|
||||
options: actionOptions,
|
||||
placeholder: t("agentRunLog.plannedAction"),
|
||||
searchPlaceholder: t("agentRunLog.searchAction"),
|
||||
emptyText: t("agentRunLog.emptyAction"),
|
||||
className: "min-w-0",
|
||||
},
|
||||
{
|
||||
name: "finalAction",
|
||||
label: t("agentRunLog.finalAction"),
|
||||
type: "select",
|
||||
defaultValue: "all",
|
||||
allValue: "all",
|
||||
options: actionOptions,
|
||||
placeholder: t("agentRunLog.finalAction"),
|
||||
searchPlaceholder: t("agentRunLog.searchAction"),
|
||||
emptyText: t("agentRunLog.emptyAction"),
|
||||
className: "min-w-0",
|
||||
},
|
||||
{
|
||||
name: "finalStatus",
|
||||
label: t("agentRunLog.finalStatus"),
|
||||
type: "select",
|
||||
defaultValue: "all",
|
||||
allValue: "all",
|
||||
options: finalStatusOptions,
|
||||
placeholder: t("agentRunLog.finalStatus"),
|
||||
searchPlaceholder: t("agentRunLog.searchStatus"),
|
||||
emptyText: t("agentRunLog.emptyStatus"),
|
||||
className: "min-w-0",
|
||||
},
|
||||
{
|
||||
name: "hitlStatus",
|
||||
label: t("agentRunLog.hitlStatus"),
|
||||
type: "select",
|
||||
defaultValue: "all",
|
||||
allValue: "all",
|
||||
options: hitlStatusOptions,
|
||||
placeholder: t("agentRunLog.hitlStatus"),
|
||||
searchPlaceholder: t("agentRunLog.searchHitl"),
|
||||
emptyText: t("agentRunLog.emptyStatus"),
|
||||
className: "min-w-0",
|
||||
},
|
||||
{
|
||||
name: "aiAgentId",
|
||||
label: t("agentRunLog.selectAgent"),
|
||||
type: "select",
|
||||
defaultValue: "all",
|
||||
allValue: "all",
|
||||
options: aiAgentOptions,
|
||||
placeholder: t("agentRunLog.selectAgent"),
|
||||
searchPlaceholder: t("agentRunLog.searchAgent"),
|
||||
emptyText: t("agentRunLog.emptyAgent"),
|
||||
className: "min-w-0",
|
||||
},
|
||||
]}
|
||||
fetchList={fetchAgentRunLogs}
|
||||
renderContent={({ result, loading }) =>
|
||||
!loading && result.results.length === 0 ? (
|
||||
<div className="py-14 text-center text-sm text-muted-foreground">
|
||||
{t("agentRunLog.emptyRows")}
|
||||
</div>
|
||||
) : (
|
||||
<div>
|
||||
<div className="hidden grid-cols-[160px_minmax(0,1.8fr)_110px_minmax(0,1.2fr)_130px_90px_76px] gap-3 border-b bg-muted/40 px-4 py-3 text-sm text-muted-foreground lg:grid">
|
||||
<div>{t("agentRunLog.time")}</div>
|
||||
<div>{t("agentRunLog.userMessage")}</div>
|
||||
<div>{t("agentRunLog.plannedAction")}</div>
|
||||
<div>{t("agentRunLog.skillTool")}</div>
|
||||
<div>{t("agentRunLog.finalStatus")}</div>
|
||||
<div className="text-right">{t("agentRunLog.duration")}</div>
|
||||
<div className="text-right">{t("agentRunLog.actions")}</div>
|
||||
</div>
|
||||
|
||||
<div className="divide-y">
|
||||
{result.results.map((item) => (
|
||||
<article
|
||||
key={item.id}
|
||||
className="grid grid-cols-1 gap-2 px-4 py-3 lg:grid-cols-[160px_minmax(0,1.8fr)_110px_minmax(0,1.2fr)_130px_90px_76px] lg:items-center lg:gap-3"
|
||||
>
|
||||
<div className="min-w-0 text-sm text-muted-foreground">
|
||||
{formatDateTime(item.createdAt)}
|
||||
</div>
|
||||
|
||||
<div className="min-w-0">
|
||||
<UserMessagePreview value={item.userMessage} t={t} />
|
||||
{item.errorMessage ? (
|
||||
<div className="truncate text-xs text-destructive">{item.errorMessage}</div>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
<div className="min-w-0">
|
||||
<Badge variant={actionBadgeVariant(item.plannedAction)}>
|
||||
{item.plannedAction || "-"}
|
||||
</Badge>
|
||||
</div>
|
||||
|
||||
<div className="min-w-0 text-sm">
|
||||
{item.plannedSkillId || item.graphToolCode || item.plannedToolCode ? (
|
||||
<div className="min-w-0 space-y-1">
|
||||
<div className="truncate font-medium">
|
||||
{item.plannedSkillName ||
|
||||
(item.plannedSkillId
|
||||
? `Skill #${item.plannedSkillId}`
|
||||
: "") ||
|
||||
item.graphToolCode ||
|
||||
item.plannedToolCode}
|
||||
</div>
|
||||
{item.plannedSkillId ? (
|
||||
<div className="truncate text-xs text-muted-foreground">
|
||||
Skill #{item.plannedSkillId}
|
||||
</div>
|
||||
) : item.handoffReason ? (
|
||||
<div className="truncate text-xs text-muted-foreground">
|
||||
{t("agentRunLog.handoffReason", { reason: item.handoffReason })}
|
||||
</div>
|
||||
) : item.recommendedAction ? (
|
||||
<div className="truncate text-xs text-muted-foreground">
|
||||
{t("agentRunLog.routingRecommendation", { action: item.recommendedAction })}
|
||||
{item.riskLevel ? ` / ${item.riskLevel} risk` : ""}
|
||||
{item.ticketDraftReady ? ` / ${t("agentRunLog.draftReady")}` : ""}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
) : (
|
||||
<span className="text-muted-foreground">-</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="min-w-0">
|
||||
<div className="space-y-1">
|
||||
<Badge variant={actionBadgeVariant(item.finalAction)}>
|
||||
{item.finalAction || "-"}
|
||||
</Badge>
|
||||
<div className="truncate text-xs text-muted-foreground">
|
||||
{getHitlStatusLabel(item.hitlStatus, t)
|
||||
? `${getHitlStatusLabel(item.hitlStatus, t)} / ${item.finalStatus || "-"}`
|
||||
: item.finalStatus || "-"}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="text-sm text-muted-foreground lg:text-right">
|
||||
{item.latencyMs} ms
|
||||
</div>
|
||||
|
||||
<div className="lg:text-right">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => {
|
||||
setActiveLogId(item.id)
|
||||
setDetailOpen(true)
|
||||
}}
|
||||
>
|
||||
{t("agentRunLog.detail")}
|
||||
</Button>
|
||||
</div>
|
||||
</article>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
labels={{
|
||||
refresh: t("agentRunLog.refresh"),
|
||||
query: t("agentRunLog.query"),
|
||||
loading: t("agentRunLog.loadingRows"),
|
||||
empty: t("agentRunLog.emptyRows"),
|
||||
loadFailed: t("agentRunLog.loadFailed"),
|
||||
}}
|
||||
/>
|
||||
<AgentRunLogDetailDialog
|
||||
open={detailOpen}
|
||||
logId={activeLogId}
|
||||
onOpenChange={(open) => {
|
||||
setDetailOpen(open)
|
||||
if (!open) {
|
||||
setActiveLogId(null)
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
function UserMessagePreview({ value, t }: { value?: string; t: TFunction }) {
|
||||
const preview = useMemo(() => summarizeUserMessage(value, t), [value, t])
|
||||
|
||||
return (
|
||||
<div className="truncate text-sm text-foreground">
|
||||
{preview}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function summarizeUserMessage(value: string | undefined, t: TFunction) {
|
||||
const normalized = value?.trim()
|
||||
if (!normalized) {
|
||||
return "-"
|
||||
}
|
||||
const text = extractTextFromHTML(normalized).replace(/\s+/g, " ").trim()
|
||||
if (text) {
|
||||
return text
|
||||
}
|
||||
if (containsHTML(normalized)) {
|
||||
if (/<img[\s>]/i.test(normalized)) {
|
||||
return t("agentRunLog.imageMessage")
|
||||
}
|
||||
return t("agentRunLog.richMessage")
|
||||
}
|
||||
return normalized
|
||||
}
|
||||
|
||||
function containsHTML(value: string) {
|
||||
return /<[^>]+>/.test(value)
|
||||
}
|
||||
|
||||
function extractTextFromHTML(value: string) {
|
||||
if (typeof window === "undefined") {
|
||||
return value
|
||||
}
|
||||
const doc = new DOMParser().parseFromString(value, "text/html")
|
||||
return doc.body.textContent || ""
|
||||
}
|
||||
Reference in New Issue
Block a user