+
+
setTimeRange(value as RealtimeRange)}
@@ -247,16 +192,24 @@ export function RealtimeStatusPage() {
-
- {METRICS.map((metric) => (
-
- ))}
-
+
+ {t("statistics.realtimeScope")}
+ {snapshot &&
+ ` · ${t("statistics.updated", { time: new Intl.DateTimeFormat(locale, { hour: "2-digit", minute: "2-digit", second: "2-digit" }).format(new Date(snapshot.until)) })}`}
+
+
+ {valueLabels && (
+
+ {METRICS.map((metric) => (
+
+ ))}
+
+ )}
)
}
diff --git a/monkeyai/admin/src/pages/task-history-page.tsx b/monkeyai/admin/src/pages/task-history-page.tsx
index 90529d0c..a84ecee7 100644
--- a/monkeyai/admin/src/pages/task-history-page.tsx
+++ b/monkeyai/admin/src/pages/task-history-page.tsx
@@ -6,7 +6,7 @@ import {
Search02Icon,
} from "@hugeicons/core-free-icons"
import { HugeiconsIcon } from "@hugeicons/react"
-import { endOfDay, startOfDay } from "date-fns"
+import { addDays, startOfDay } from "date-fns"
import {
ar,
de,
@@ -22,6 +22,8 @@ import {
} from "date-fns/locale"
import { useTranslation } from "react-i18next"
+import { useStatistics } from "@/hooks/use-statistics"
+import { StatisticsFeedback } from "@/components/statistics-feedback"
import { Avatar, AvatarFallback } from "@/components/ui/avatar"
import { Button } from "@/components/ui/button"
import { Calendar } from "@/components/ui/calendar"
@@ -50,27 +52,21 @@ import {
TableRow,
} from "@/components/ui/table"
-type TaskStatus = "completed" | "running" | "failed" | "cancelled"
-type TaskType = "conversation" | "workflow" | "retrieval" | "tool" | "scheduled"
-type ClientType = "desktop" | "web" | "extension" | "mobile"
-
type TaskHistoryEntry = {
id: string
title: string
- type: TaskType
- clientType: ClientType
- clientName: string
- deviceId: string
- owner: string
- ownerEmail: string
- status: TaskStatus
- startedAt: string
- lastActiveAt: string
- conversationCount: number
- durationSeconds: number | null
- inputTokens: number
- outputTokens: number
- credits: number
+ user_name: string
+ user_email: string
+ started_at: string
+ last_active_at: string
+ turn_count: number
+}
+
+type TaskHistory = {
+ items: TaskHistoryEntry[]
+ total: number
+ page: number
+ page_size: number
}
type TaskHistoryFilters = {
@@ -168,225 +164,6 @@ function DatePickerField({
)
}
-const TASK_HISTORY: TaskHistoryEntry[] = [
- {
- id: "task_9f2c8a1d",
- title: "生成季度经营分析报告",
- type: "workflow",
- clientType: "desktop",
- clientName: "MonkeyCode macOS",
- deviceId: "MCP-MAC-7H2K",
- owner: "张明",
- ownerEmail: "zhangming@example.com",
- status: "completed",
- startedAt: "2026-09-02T07:42:18Z",
- lastActiveAt: "2026-09-02T07:44:46Z",
- conversationCount: 18,
- durationSeconds: 148,
- inputTokens: 128640,
- outputTokens: 24680,
- credits: 96,
- },
- {
- id: "task_8b4e6f20",
- title: "排查订单服务响应变慢问题",
- type: "conversation",
- clientType: "web",
- clientName: "Web Console",
- deviceId: "WEB-SESSION-83A1",
- owner: "李娜",
- ownerEmail: "lina@example.com",
- status: "running",
- startedAt: "2026-09-02T07:35:04Z",
- lastActiveAt: "2026-09-02T07:48:12Z",
- conversationCount: 12,
- durationSeconds: null,
- inputTokens: 46920,
- outputTokens: 8640,
- credits: 35,
- },
- {
- id: "task_72ad3c94",
- title: "整理竞品功能调研结果",
- type: "retrieval",
- clientType: "extension",
- clientName: "Chrome Extension",
- deviceId: "EXT-CHROME-2D91",
- owner: "王琦",
- ownerEmail: "wangqi@example.com",
- status: "completed",
- startedAt: "2026-09-02T06:58:31Z",
- lastActiveAt: "2026-09-02T06:59:45Z",
- conversationCount: 6,
- durationSeconds: 74,
- inputTokens: 58940,
- outputTokens: 11320,
- credits: 44,
- },
- {
- id: "task_615ee4b7",
- title: "修复移动端登录状态丢失",
- type: "tool",
- clientType: "desktop",
- clientName: "MonkeyCode Windows",
- deviceId: "MCP-WIN-4F6B",
- owner: "陈晨",
- ownerEmail: "chenchen@example.com",
- status: "failed",
- startedAt: "2026-09-02T06:26:47Z",
- lastActiveAt: "2026-09-02T06:27:39Z",
- conversationCount: 9,
- durationSeconds: 52,
- inputTokens: 31760,
- outputTokens: 4280,
- credits: 23,
- },
- {
- id: "task_5cd8913a",
- title: "同步产品帮助中心知识库",
- type: "scheduled",
- clientType: "web",
- clientName: "Web Console",
- deviceId: "WEB-SCHEDULER",
- owner: "系统",
- ownerEmail: "system@monkeyai.local",
- status: "completed",
- startedAt: "2026-09-02T05:00:00Z",
- lastActiveAt: "2026-09-02T05:03:56Z",
- conversationCount: 4,
- durationSeconds: 236,
- inputTokens: 284500,
- outputTokens: 18720,
- credits: 158,
- },
- {
- id: "task_49e72b6c",
- title: "总结客户访谈录音",
- type: "conversation",
- clientType: "mobile",
- clientName: "MonkeyCode iOS",
- deviceId: "IOS-15PM-8A31",
- owner: "周悦",
- ownerEmail: "zhouyue@example.com",
- status: "cancelled",
- startedAt: "2026-09-02T04:42:16Z",
- lastActiveAt: "2026-09-02T04:42:47Z",
- conversationCount: 3,
- durationSeconds: 31,
- inputTokens: 18420,
- outputTokens: 2180,
- credits: 12,
- },
- {
- id: "task_330af85e",
- title: "生成 API 接口测试用例",
- type: "workflow",
- clientType: "desktop",
- clientName: "MonkeyCode Linux",
- deviceId: "MCP-LINUX-91C7",
- owner: "赵磊",
- ownerEmail: "zhaolei@example.com",
- status: "completed",
- startedAt: "2026-09-02T03:54:02Z",
- lastActiveAt: "2026-09-02T03:55:54Z",
- conversationCount: 15,
- durationSeconds: 112,
- inputTokens: 96480,
- outputTokens: 22460,
- credits: 78,
- },
- {
- id: "task_2ed64a10",
- title: "检查发布分支代码变更",
- type: "tool",
- clientType: "extension",
- clientName: "VS Code Extension",
- deviceId: "EXT-VSCODE-44E2",
- owner: "张明",
- ownerEmail: "zhangming@example.com",
- status: "completed",
- startedAt: "2026-09-02T03:18:49Z",
- lastActiveAt: "2026-09-02T03:20:18Z",
- conversationCount: 8,
- durationSeconds: 89,
- inputTokens: 74120,
- outputTokens: 12680,
- credits: 55,
- },
- {
- id: "task_1a9c37fd",
- title: "提取合同中的风险条款",
- type: "retrieval",
- clientType: "mobile",
- clientName: "MonkeyCode Android",
- deviceId: "ANDROID-P9-6D0A",
- owner: "李娜",
- ownerEmail: "lina@example.com",
- status: "completed",
- startedAt: "2026-09-02T02:47:35Z",
- lastActiveAt: "2026-09-02T02:48:43Z",
- conversationCount: 5,
- durationSeconds: 68,
- inputTokens: 52640,
- outputTokens: 9780,
- credits: 41,
- },
- {
- id: "task_0f5632bc",
- title: "分析本周客服会话主题",
- type: "scheduled",
- clientType: "web",
- clientName: "Web Console",
- deviceId: "WEB-SCHEDULER",
- owner: "系统",
- ownerEmail: "system@monkeyai.local",
- status: "failed",
- startedAt: "2026-09-02T02:00:00Z",
- lastActiveAt: "2026-09-02T02:03:04Z",
- conversationCount: 7,
- durationSeconds: 184,
- inputTokens: 192300,
- outputTokens: 15640,
- credits: 121,
- },
- {
- id: "task_f82d10a7",
- title: "优化数据导入脚本",
- type: "conversation",
- clientType: "desktop",
- clientName: "MonkeyCode macOS",
- deviceId: "MCP-MAC-7H2K",
- owner: "张明",
- ownerEmail: "zhangming@example.com",
- status: "completed",
- startedAt: "2026-09-02T01:26:53Z",
- lastActiveAt: "2026-09-02T01:30:16Z",
- conversationCount: 21,
- durationSeconds: 203,
- inputTokens: 156840,
- outputTokens: 31860,
- credits: 117,
- },
- {
- id: "task_e47ba291",
- title: "制作新品发布会内容大纲",
- type: "workflow",
- clientType: "web",
- clientName: "Web Console",
- deviceId: "WEB-SESSION-61B3",
- owner: "周悦",
- ownerEmail: "zhouyue@example.com",
- status: "completed",
- startedAt: "2026-09-02T00:38:12Z",
- lastActiveAt: "2026-09-02T00:40:18Z",
- conversationCount: 14,
- durationSeconds: 126,
- inputTokens: 88260,
- outputTokens: 19740,
- credits: 69,
- },
-]
-
export function TaskHistoryPage() {
const { i18n, t } = useTranslation()
const [filterInput, setFilterInput] =
@@ -398,44 +175,26 @@ export function TaskHistoryPage() {
const language = locale.split("-")[0]
const calendarLocale = DATE_LOCALES[locale] ?? DATE_LOCALES[language] ?? enUS
- const filteredTasks = useMemo(() => {
- const taskNameQuery = filters.taskName.trim().toLocaleLowerCase(locale)
- const userNameQuery = filters.userName.trim().toLocaleLowerCase(locale)
- const startTimestamp = filters.startTime
- ? startOfDay(filters.startTime).getTime()
- : null
- const endTimestamp = filters.endTime
- ? endOfDay(filters.endTime).getTime()
- : null
-
- return TASK_HISTORY.filter((task) => {
- const startedAt = new Date(task.startedAt).getTime()
- const matchesTaskName =
- taskNameQuery.length === 0 ||
- [task.id, task.title].some((value) =>
- value.toLocaleLowerCase(locale).includes(taskNameQuery)
- )
- const matchesUserName =
- userNameQuery.length === 0 ||
- [task.owner, task.ownerEmail].some((value) =>
- value.toLocaleLowerCase(locale).includes(userNameQuery)
- )
- const matchesStartTime =
- startTimestamp === null || startedAt >= startTimestamp
- const matchesEndTime = endTimestamp === null || startedAt <= endTimestamp
-
- return (
- matchesTaskName && matchesUserName && matchesStartTime && matchesEndTime
- )
- })
- }, [filters, locale])
-
- const pageCount = Math.max(1, Math.ceil(filteredTasks.length / pageSize))
- const currentPage = Math.min(page, pageCount)
+ const query = new URLSearchParams({
+ task: filters.taskName,
+ user: filters.userName,
+ page: String(page),
+ page_size: String(pageSize),
+ })
+ if (filters.startTime)
+ query.set("from", startOfDay(filters.startTime).toISOString())
+ if (filters.endTime)
+ query.set("until", startOfDay(addDays(filters.endTime, 1)).toISOString())
+ const request = useStatistics
(
+ `/api/admin/v1/statistics/history?${query}`
+ )
+ const total = request.data?.total ?? 0
+ const pageCount = Math.max(1, Math.ceil(total / pageSize))
+ const currentPage = request.data?.page ?? page
const pageStart = (currentPage - 1) * pageSize
- const visibleTasks = filteredTasks.slice(pageStart, pageStart + pageSize)
- const firstVisible = filteredTasks.length === 0 ? 0 : pageStart + 1
- const lastVisible = Math.min(pageStart + pageSize, filteredTasks.length)
+ const visibleTasks = request.data?.items ?? []
+ const firstVisible = total === 0 ? 0 : pageStart + 1
+ const lastVisible = Math.min(pageStart + pageSize, total)
const numberFormatter = useMemo(() => new Intl.NumberFormat(locale), [locale])
const dateFormatter = useMemo(
() =>
@@ -464,11 +223,13 @@ export function TaskHistoryPage() {
const applySearch = (event: FormEvent) => {
event.preventDefault()
setFilters(filterInput)
+ request.reload()
resetPage()
}
return (
@@ -675,8 +442,10 @@ export function TaskHistoryPage() {
type="button"
variant="outline"
size="icon-sm"
- disabled={currentPage === 1}
- onClick={() => setPage((value) => Math.max(1, value - 1))}
+ disabled={
+ request.loading || !!request.error || currentPage === 1
+ }
+ onClick={() => setPage(Math.max(1, currentPage - 1))}
aria-label={t("pages.operationLogs.pagination.previous")}
>