Sfoglia il codice sorgente

feat(paas): add project artifact library

Aggregate ended project runs into a searchable artifact page grouped by
source conversation, with type filters, preview, save, and run navigation.
Workspace listings hide virtualenv and dependency internals and only the
first files of a large run stay expanded by default.
241880436@seecoder.cn 3 giorni fa
parent
commit
fafa4338eb

+ 1 - 1
PAAS_PRODUCT_IMPLEMENTATION_PLAN.zh-CN.md

@@ -1442,7 +1442,7 @@ git commit -m "test(paas): cover project workspace and agent routing"
 
 1. **P0-B Research Inbox**:统一聚合待审批、失败、完成未读、连接异常和预算告警。
 2. **P1 Run Inspector 2.0**:阶段时间线、子智能体参与、证据、成本、恢复点。
-3. **P1 成果资产库**:项目级文件树、来源、版本、比较、打包导出。
+3. **P1 成果资产库**:项目级文件树、来源、版本、比较、打包导出。(2026-12-01 已落地第一阶段:最近 40 个已结束任务的成果聚合、来源会话、搜索/类型筛选、预览与保存;文件树、版本与打包导出留待后续。)
 4. **P2 项目上下文与团队能力**:上下文包、记忆、分享、权限、云端同步。
 
 ## Self-Review

+ 72 - 0
packages/app/e2e/paas/artifacts.spec.ts

@@ -0,0 +1,72 @@
+import { expect, test } from "@playwright/test"
+
+test("project artifact library aggregates ended runs and previews files", async ({ page }) => {
+  await page.goto("/e2e/paas/index.html?completed&files")
+  await page.getByLabel("API Key", { exact: true }).fill("artifacts")
+  await page.getByRole("button", { name: "连接平台", exact: true }).click()
+  await page
+    .getByRole("button", { name: /已有研究/ })
+    .first()
+    .click()
+
+  await page.locator(".paas-sidebar").getByRole("button", { name: "成果", exact: true }).click()
+  await expect(page.getByRole("heading", { name: "成果", exact: true })).toBeVisible()
+  const group = page.getByRole("region", { name: "已有研究 的成果" })
+  await expect(group).toBeVisible()
+  await expect(group.getByText("研究计划.pdf", { exact: true })).toBeVisible()
+  await expect(group.getByText("研究计划.md", { exact: true })).toBeVisible()
+  await expect(group.getByText("config.yml", { exact: true })).toBeVisible()
+  await expect(page.getByText("6 个文件", { exact: true })).toBeVisible()
+
+  // Duplicate artifact names collapse into one row.
+  await expect(group.getByText("manifest.json", { exact: true })).toHaveCount(1)
+
+  await page.getByRole("button", { name: "预览 研究计划.md", exact: true }).click()
+  const preview = page.getByLabel("右侧预览", { exact: true })
+  await expect(preview).toBeVisible()
+  await expect(preview.getByText("可预览的研究计划", { exact: true })).toBeVisible()
+
+  await page.getByRole("button", { name: "保存 研究计划.md", exact: true }).click()
+  await expect(page.getByText("已保存 研究计划.md", { exact: true })).toBeVisible()
+})
+
+test("artifact library filters by type and search", async ({ page }) => {
+  await page.goto("/e2e/paas/index.html?completed&files")
+  await page.getByLabel("API Key", { exact: true }).fill("artifacts-filter")
+  await page.getByRole("button", { name: "连接平台", exact: true }).click()
+  await page
+    .getByRole("button", { name: /已有研究/ })
+    .first()
+    .click()
+  await page.locator(".paas-sidebar").getByRole("button", { name: "成果", exact: true }).click()
+  const library = page.locator(".paas-artifact-page")
+
+  await page.getByRole("button", { name: "数据 · 3", exact: true }).click()
+  await expect(library.getByText("config.yml", { exact: true })).toBeVisible()
+  await expect(library.getByText("研究计划.md", { exact: true })).toHaveCount(0)
+
+  await page.getByRole("button", { name: "全部 · 6", exact: true }).click()
+  await page.getByLabel("搜索成果", { exact: true }).fill("不存在")
+  await expect(library.getByText("没有匹配的成果", { exact: true })).toBeVisible()
+  await page.getByRole("button", { name: "清除筛选", exact: true }).click()
+  await expect(library.getByText("研究计划.md", { exact: true })).toBeVisible()
+})
+
+test("artifact library is scoped to the active project", async ({ page }) => {
+  await page.goto("/e2e/paas/index.html?completed")
+  await page.getByLabel("API Key", { exact: true }).fill("artifacts-scope")
+  await page.getByRole("button", { name: "连接平台", exact: true }).click()
+  await page
+    .getByRole("button", { name: /已有研究/ })
+    .first()
+    .click()
+
+  await page.getByRole("button", { name: "新建项目", exact: true }).click()
+  await page.getByLabel("项目名称", { exact: true }).fill("第二个项目")
+  await page.getByRole("button", { name: "创建项目", exact: true }).click()
+  await expect(page.getByLabel("切换项目", { exact: true })).toContainText("第二个项目")
+
+  await page.locator(".paas-sidebar").getByRole("button", { name: "成果", exact: true }).click()
+  await expect(page.getByText("还没有可归档的成果", { exact: true })).toBeVisible()
+  await expect(page.getByText("研究计划.md", { exact: true })).toHaveCount(0)
+})

+ 12 - 0
packages/app/src/pages/paas/README.md

@@ -53,6 +53,18 @@
 - 可切换到执行服务日志回放;读取失败可重试,不影响任务控制与成果。
 - 不包含跨阶段证据台账、checkpoint 可视化时间线和子智能体关系图。
 
+## P1 成果资产库(2026-12-01)
+
+- 侧栏新增“成果”页,按当前项目聚合**已结束任务**生成的成果与工作文件,支持全文搜索与文档/图片/数据/文件筛选。
+- 来源任务来自平台任务索引与本机会话记录,按 `thread_id` 归属当前项目;归档项目与归档会话不纳入。
+- 同名文件去重,优先保留带平台身份的平台成果;工作文件补齐路径、大小等缺失信息。
+- 按来源会话分组;同一会话的多次运行合并,同名文件保留最新一版;每个分组只展开前 8 个文件,其余折叠(最多展开 200 个)。
+- 工作区列表中的虚拟环境、依赖目录(`site-packages`、`node_modules`、`venv`、`__pycache__` 等)不纳入成果。
+- 每个分组显示来源会话、智能体、时间与文件数,可打开任务回到会话中的运行详情。
+- 文件可直接在右侧预览或保存;预览沿用会话页的同一控制器与缓存,切换到其他页面会关闭预览栏。
+- 只聚合最近 40 个已结束任务;更早记录需在平台任务中查看。单任务读取失败不阻断其余成果,并明确列出未同步任务。
+- 运行中任务不纳入,避免把持续变化的中间文件当作成果。
+
 ---
 
 # AgentPaaS 工作台:第一阶段 GUI

+ 147 - 0
packages/app/src/pages/paas/artifact-library.test.ts

@@ -0,0 +1,147 @@
+import { expect, test } from "bun:test"
+import { artifactCategory, artifactRuns, filterArtifacts, readRunArtifacts, type ArtifactChat } from "./artifact-library"
+
+const chats: ArtifactChat[] = [
+  {
+    id: "chat-a",
+    agentID: "research",
+    projectID: "project-a",
+    title: "已有研究",
+    threadID: "thread-a",
+    messages: [
+      { role: "user", status: "completed", runID: "run-message" },
+      { role: "assistant", status: "completed", runID: "run-message", updated: 1000 },
+      { role: "assistant", status: "running", runID: "run-active" },
+    ],
+  },
+  {
+    id: "chat-b",
+    agentID: "research",
+    projectID: "project-a",
+    title: "已归档会话",
+    threadID: "thread-b",
+    archived: true,
+    messages: [],
+  },
+  {
+    id: "chat-c",
+    agentID: "data67",
+    projectID: "project-b",
+    title: "另一个项目",
+    threadID: "thread-c",
+    messages: [{ role: "assistant", status: "completed", runID: "run-other", updated: 5000 }],
+  },
+]
+
+test("collects archived runs for one project from tasks and loaded messages", () => {
+  const runs = artifactRuns({
+    chats,
+    projectID: "project-a",
+    tasks: [
+      {
+        run_id: "run-task",
+        agent_id: "research",
+        thread_id: "thread-a",
+        status: "completed",
+        created_at: "2026-11-30T10:00:00Z",
+        updated_at: "2026-11-30T10:00:05Z",
+      },
+      { run_id: "run-message", agent_id: "research", thread_id: "thread-a", status: "completed", updated_at: "2026-11-30T09:00:00Z" },
+      { run_id: "run-running", agent_id: "research", thread_id: "thread-a", status: "running" },
+      { run_id: "run-archived", agent_id: "research", thread_id: "thread-b", status: "completed" },
+      { run_id: "run-other", agent_id: "data67", thread_id: "thread-c", status: "completed" },
+      { run_id: "run-unassigned", agent_id: "research", status: "completed" },
+    ],
+  })
+  expect(runs.map((run) => run.runID)).toEqual(["run-task", "run-message"])
+  // The task index snapshot keeps the later timestamp for a run it shares with the message history.
+  expect(runs[1].at).toBe(Date.parse("2026-11-30T09:00:00Z"))
+  expect(runs[0].chatTitle).toBe("已有研究")
+  expect(runs[0].task?.run_id).toBe("run-task")
+})
+
+test("merges artifact and workspace files without duplicating names", () => {
+  const run = { agentID: "research", runID: "run-1", chatID: "chat-a", chatTitle: "已有研究", at: 10 }
+  const entries = readRunArtifacts({
+    run,
+    detail: {
+      artifacts: [
+        { artifact_id: "artifact-1", name: "研究计划.pdf" },
+        { artifact_id: "artifact-1", name: "研究计划.pdf" },
+        { artifact_id: "artifact-2", name: "manifest.json" },
+      ],
+    },
+    files: {
+      files: [
+        { name: "研究计划.pdf", path: "final/研究计划.pdf", size: 128 },
+        { name: "evidence.md", path: "final/evidence.md", mime_type: "text/markdown", size: 42 },
+        { name: "trace.json", path: "work/trace.json", size: 9 },
+      ],
+    },
+  })
+  expect(entries).toHaveLength(4)
+  const plan = entries.find((entry) => entry.name === "研究计划.pdf")!
+  expect(plan.source).toBe("artifact")
+  expect(plan.artifactID).toBe("artifact-1")
+  // Workspace metadata fills gaps the artifact record did not provide.
+  expect(plan.path).toBe("final/研究计划.pdf")
+  expect(plan.size).toBe(128)
+  expect(entries.find((entry) => entry.name === "evidence.md")?.source).toBe("file")
+})
+
+test("tolerates missing lists and empty identifiers", () => {
+  const run = { agentID: "research", runID: "run-1", chatID: "chat-a", chatTitle: "已有研究", at: 10 }
+  expect(readRunArtifacts({ run, detail: {}, files: { files: [] } })).toEqual([])
+  const entries = readRunArtifacts({
+    run,
+    detail: { artifacts: [{ name: "无编号成果.pdf" }, { artifact_id: "artifact-3" }] },
+    files: undefined,
+  })
+  expect(entries.map((entry) => entry.name)).toEqual(["artifact-3"])
+  expect(entries[0].artifactID).toBe("artifact-3")
+})
+
+test("hides virtualenv and dependency internals from workspace listings", () => {
+  const run = { agentID: "data67", runID: "run-1", chatID: "chat-a", chatTitle: "图表任务", at: 10 }
+  const entries = readRunArtifacts({
+    run,
+    detail: { artifacts: [{ artifact_id: "artifact-1", name: "bar.png" }] },
+    files: {
+      files: [
+        { name: "bar.png", path: "outputs/bar.png" },
+        { name: "sales.csv", path: "workspace/sales.csv" },
+        { name: "__init__.py", path: ".venv/Lib/site-packages/numpy/__init__.py" },
+        { name: "matplotlib", path: "venv/lib/python3.12/site-packages/matplotlib" },
+        { name: "module.pyc", path: "workspace/__pycache__/module.pyc" },
+        { name: "state.json", path: "workspace/.ipynb_checkpoints/state.json" },
+      ],
+    },
+  })
+  expect(entries.map((entry) => entry.name).sort()).toEqual(["bar.png", "sales.csv"])
+})
+
+test("classifies and filters artifacts by type and search text", () => {
+  expect(artifactCategory({ name: "report.md" })).toBe("document")
+  expect(artifactCategory({ name: "figure.png" })).toBe("image")
+  expect(artifactCategory({ name: "trace.json" })).toBe("data")
+  expect(artifactCategory({ name: "dataset.csv" })).toBe("data")
+  expect(artifactCategory({ name: "archive.zip" })).toBe("other")
+
+  const run = { agentID: "research", runID: "run-1", chatID: "chat-a", chatTitle: "已有研究", at: 10 }
+  const entries = readRunArtifacts({
+    run,
+    detail: { artifacts: [] },
+    files: {
+      files: [
+        { name: "report.md", path: "final/report.md" },
+        { name: "figure.png", path: "final/figure.png" },
+        { name: "trace.json", path: "work/trace.json" },
+      ],
+    },
+  })
+  expect(filterArtifacts(entries, { query: "", category: "image" }).map((entry) => entry.name)).toEqual(["figure.png"])
+  expect(filterArtifacts(entries, { query: "已有研究", category: "all" })).toHaveLength(3)
+  expect(filterArtifacts(entries, { query: "report", category: "all" }).map((entry) => entry.name)).toEqual([
+    "report.md",
+  ])
+})

+ 232 - 0
packages/app/src/pages/paas/artifact-library.ts

@@ -0,0 +1,232 @@
+import { paasPreviewKind, paasRecord, paasStatus, paasText } from "@/paas"
+
+export type ArtifactChat = {
+  id: string
+  agentID?: string
+  projectID?: string
+  title: string
+  threadID: string
+  archived?: boolean
+  messages: {
+    role?: string
+    status?: string
+    runID?: string
+    started?: number
+    updated?: number
+  }[]
+}
+
+export type ArtifactRun = {
+  agentID: string
+  runID: string
+  chatID: string
+  chatTitle: string
+  at: number
+  task?: Record<string, unknown>
+}
+
+export type ArtifactEntry = {
+  id: string
+  name: string
+  mime?: string
+  size?: number
+  path?: string
+  artifactID?: string
+  agentID: string
+  runID: string
+  chatID: string
+  chatTitle: string
+  at: number
+  source: "artifact" | "file"
+}
+
+export type ArtifactCategory = "document" | "image" | "data" | "other"
+
+// Only runs that ended can be archived; active runs keep changing their workspace.
+const archivedStatuses = new Set(["completed", "partial", "failed", "cancelled"])
+
+const dataExtensions = new Set([
+  "json",
+  "jsonl",
+  "yaml",
+  "yml",
+  "toml",
+  "ini",
+  "cfg",
+  "csv",
+  "tsv",
+  "log",
+  "lock",
+])
+
+export function artifactRuns(input: {
+  chats: ArtifactChat[]
+  tasks: Record<string, unknown>[]
+  projectID: string
+}): ArtifactRun[] {
+  const chats = input.chats.filter((chat) => chat.projectID === input.projectID && !chat.archived)
+  const threads = new Map<string, ArtifactChat>()
+  for (const chat of chats) if (chat.threadID && !threads.has(chat.threadID)) threads.set(chat.threadID, chat)
+  const runs = new Map<string, ArtifactRun>()
+  const add = (run: ArtifactRun) => {
+    const key = `${run.agentID}:${run.runID}`
+    const previous = runs.get(key)
+    if (!previous) {
+      runs.set(key, run)
+      return
+    }
+    runs.set(key, { ...run, at: Math.max(previous.at, run.at), task: run.task || previous.task })
+  }
+
+  for (const task of input.tasks) {
+    const runID = paasText(task.run_id) || paasText(task.id)
+    const threadID = paasText(task.thread_id) || paasText(task.session_id)
+    const chat = threadID ? threads.get(threadID) : undefined
+    if (!runID || !chat || !archivedStatuses.has(paasStatus(task))) continue
+    const agentID = paasText(task.agent_id) || chat.agentID
+    if (!agentID) continue
+    add({
+      agentID,
+      runID,
+      chatID: chat.id,
+      chatTitle: chat.title,
+      at: time(task.updated_at) || time(task.completed_at) || time(task.created_at),
+      task,
+    })
+  }
+
+  for (const chat of chats) {
+    const agentID = chat.agentID
+    if (!agentID) continue
+    for (const message of chat.messages) {
+      if (message.role !== "assistant" || !message.runID || !archivedStatuses.has(message.status || "")) continue
+      add({
+        agentID,
+        runID: message.runID,
+        chatID: chat.id,
+        chatTitle: chat.title,
+        at: message.updated || message.started || 0,
+      })
+    }
+  }
+
+  return [...runs.values()].sort((a, b) => b.at - a.at)
+}
+
+export function readRunArtifacts(input: { run: ArtifactRun; detail: unknown; files: unknown }): ArtifactEntry[] {
+  const entries = new Map<string, ArtifactEntry>()
+  const add = (entry: ArtifactEntry) => {
+    const key = entry.name.trim().toLocaleLowerCase()
+    if (key) entries.set(key, entry)
+  }
+  // Artifacts win over workspace copies of the same name because they keep the
+  // platform download identity; workspace-only files fill in the rest.
+  for (const file of rows(input.detail, "artifacts")) {
+    const name = paasText(file.name) || paasText(file.artifact_id)
+    const artifactID = paasText(file.artifact_id) || paasText(file.id)
+    if (!name || !artifactID) continue
+    add({
+      ...envelope(input.run, "artifact"),
+      id: `${input.run.agentID}:${input.run.runID}:artifact:${artifactID}`,
+      name,
+      artifactID,
+      mime: paasText(file.mime_type) || undefined,
+      size: typeof file.size === "number" ? file.size : undefined,
+    })
+  }
+  for (const file of rows(input.files, "files")) {
+    const path = paasText(file.path)
+    const name = paasText(file.name) || path.split("/").at(-1) || ""
+    const key = name.trim().toLocaleLowerCase()
+    if (!key || dependencyFile(path, name)) continue
+    const previous = entries.get(key)
+    if (previous) {
+      entries.set(key, {
+        ...previous,
+        mime: previous.mime || paasText(file.mime_type) || undefined,
+        size: previous.size ?? (typeof file.size === "number" ? file.size : undefined),
+        path: previous.path || path || undefined,
+      })
+      continue
+    }
+    add({
+      ...envelope(input.run, "file"),
+      id: `${input.run.agentID}:${input.run.runID}:file:${path || name}`,
+      name,
+      path: path || undefined,
+      mime: paasText(file.mime_type) || undefined,
+      size: typeof file.size === "number" ? file.size : undefined,
+    })
+  }
+  return [...entries.values()]
+}
+
+function envelope(run: ArtifactRun, source: ArtifactEntry["source"]) {
+  return {
+    agentID: run.agentID,
+    runID: run.runID,
+    chatID: run.chatID,
+    chatTitle: run.chatTitle,
+    at: run.at,
+    source,
+  }
+}
+
+function rows(value: unknown, key: string): Record<string, unknown>[] {
+  const list = paasRecord(value)?.[key]
+  if (!Array.isArray(list)) return []
+  return list.flatMap((row) => {
+    const item = paasRecord(row)
+    return item ? [item] : []
+  })
+}
+
+// Workspace listing can include the whole virtualenv; environment internals are
+// not research outputs, so the library hides them instead of flooding the page.
+const dependencySegments = new Set([
+  "node_modules",
+  "site-packages",
+  "dist-packages",
+  ".venv",
+  "venv",
+  "env",
+  "__pycache__",
+  ".git",
+  ".tox",
+  ".mypy_cache",
+  ".pytest_cache",
+  ".ipynb_checkpoints",
+])
+
+function dependencyFile(path: string, name: string) {
+  if (/\.pyc$/i.test(name) || /\.egg-info([\\/]|$)/i.test(path)) return true
+  const segments = `${path}/${name}`.split(/[\\/]+/)
+  return segments.some((segment) => dependencySegments.has(segment.toLocaleLowerCase()))
+}
+
+export function artifactCategory(file: { name: string; mime?: string }): ArtifactCategory {
+  const kind = paasPreviewKind(file.name, file.mime || "")
+  if (kind === "image") return "image"
+  const extension = file.name.split(".").pop()?.toLocaleLowerCase() || ""
+  if (dataExtensions.has(extension)) return "data"
+  if (kind === "markdown" || kind === "pdf" || kind === "text") return "document"
+  return "other"
+}
+
+export function filterArtifacts(
+  entries: ArtifactEntry[],
+  input: { query: string; category: ArtifactCategory | "all" },
+): ArtifactEntry[] {
+  const query = input.query.trim().toLocaleLowerCase()
+  return entries.filter(
+    (entry) =>
+      (input.category === "all" || artifactCategory(entry) === input.category) &&
+      (!query ||
+        `${entry.name} ${entry.chatTitle} ${entry.mime || ""}`.toLocaleLowerCase().includes(query)),
+  )
+}
+
+function time(value: unknown) {
+  const result = typeof value === "number" ? value : Date.parse(paasText(value))
+  return Number.isFinite(result) ? result : 0
+}

+ 409 - 0
packages/app/src/pages/paas/artifacts.tsx

@@ -0,0 +1,409 @@
+import { For, Show, createEffect, createMemo, on, onCleanup } from "solid-js"
+import { createStore } from "solid-js/store"
+import { ResearchIcon } from "./research-icon"
+import { paasRecord, paasRunDetail, paasText, type PaasPlatform } from "@/paas"
+import {
+  artifactCategory,
+  artifactRuns,
+  filterArtifacts,
+  readRunArtifacts,
+  type ArtifactCategory,
+  type ArtifactChat,
+  type ArtifactEntry,
+  type ArtifactRun,
+} from "./artifact-library"
+import type { PaasPreviewFile } from "./preview"
+
+const categories: { id: ArtifactCategory | "all"; label: string }[] = [
+  { id: "all", label: "全部" },
+  { id: "document", label: "文档" },
+  { id: "image", label: "图片" },
+  { id: "data", label: "数据" },
+  { id: "other", label: "其他" },
+]
+
+const categoryLabels: Record<ArtifactCategory, string> = {
+  document: "文档",
+  image: "图片",
+  data: "数据",
+  other: "文件",
+}
+
+const maxRuns = 40
+const cache = new Map<string, ArtifactEntry[]>()
+
+function formatSize(value?: number) {
+  if (!value || value < 0) return ""
+  if (value < 1024) return `${value} B`
+  if (value < 1024 * 1024) return `${Math.round(value / 1024)} KB`
+  return `${(value / 1024 / 1024).toFixed(1)} MB`
+}
+
+function formatTime(value: number) {
+  if (!value) return ""
+  return new Date(value).toLocaleString("zh-CN", {
+    month: "numeric",
+    day: "numeric",
+    hour: "2-digit",
+    minute: "2-digit",
+  })
+}
+
+export function PaasArtifacts(props: {
+  api?: PaasPlatform
+  connected: boolean
+  scope?: string
+  projectID: string
+  projectName: string
+  chats: () => ArtifactChat[]
+  tasks: () => Record<string, unknown>[]
+  agents: Record<string, unknown>[]
+  onOpenRun: (run: ArtifactRun) => void
+  onPreview: (file: PaasPreviewFile) => void
+  onNewResearch?: () => void
+}) {
+  const [state, setState] = createStore({
+    entries: [] as ArtifactEntry[],
+    loading: false,
+    loaded: false,
+    failed: [] as string[],
+    updated: "",
+    notice: "",
+    saving: "",
+  })
+  const [filters, setFilters] = createStore({
+    query: "",
+    category: "all" as ArtifactCategory | "all",
+  })
+  const runs = createMemo(() =>
+    artifactRuns({ chats: props.chats(), tasks: props.tasks(), projectID: props.projectID }),
+  )
+  const targets = createMemo(() => runs().slice(0, maxRuns))
+  const signature = createMemo(() => targets().map((run) => `${run.agentID}:${run.runID}`).join("|"))
+  // Re-running a chat often republishes the same workspace files; keep the newest copy per chat.
+  const library = createMemo(() => {
+    const seen = new Map<string, ArtifactEntry>()
+    for (const entry of state.entries) {
+      const key = `${entry.agentID}:${entry.chatID || entry.runID}:${entry.name.toLocaleLowerCase()}`
+      if (!seen.has(key)) seen.set(key, entry)
+    }
+    return [...seen.values()]
+  })
+  const entries = createMemo(() => filterArtifacts(library(), { query: filters.query, category: filters.category }))
+  const groups = createMemo(() => {
+    const runsByKey = new Map(targets().map((run) => [`${run.agentID}:${run.runID}`, run]))
+    const result = new Map<string, { run: ArtifactRun; entries: ArtifactEntry[]; runs: Set<string> }>()
+    for (const entry of entries()) {
+      const key = entry.chatID ? `${entry.agentID}:${entry.chatID}` : `${entry.agentID}:${entry.runID}`
+      const run =
+        runsByKey.get(`${entry.agentID}:${entry.runID}`) ||
+        ({
+          agentID: entry.agentID,
+          runID: entry.runID,
+          chatID: entry.chatID,
+          chatTitle: entry.chatTitle,
+          at: entry.at,
+        } satisfies ArtifactRun)
+      const group = result.get(key) || { run, entries: [], runs: new Set<string>() }
+      group.entries.push(entry)
+      group.runs.add(entry.runID)
+      if (run.at > group.run.at) group.run = run
+      result.set(key, group)
+    }
+    for (const group of result.values()) group.entries.sort(byRelevance)
+    return [...result.values()].sort((a, b) => b.run.at - a.run.at)
+  })
+  const counts = createMemo(() => {
+    const result: Record<string, number> = { all: library().length }
+    for (const entry of library()) {
+      const category = artifactCategory(entry)
+      result[category] = (result[category] || 0) + 1
+    }
+    return result
+  })
+  const agentName = (agentID: string) =>
+    paasText(props.agents.find((agent) => paasText(agent.id) === agentID)?.name) || agentID
+  const narrowed = () => !!filters.query.trim() || filters.category !== "all"
+  const cacheKey = (run: ArtifactRun) => `${props.scope || ""}:${run.agentID}:${run.runID}`
+  let epoch = 0
+  onCleanup(() => {
+    epoch++
+  })
+
+  const load = async (force = false) => {
+    const current = ++epoch
+    setState({ notice: "" })
+    if (!props.connected || !props.api) {
+      setState({ entries: [], loading: false, loaded: false, failed: [] })
+      return
+    }
+    const list = targets()
+    setState({ loading: true, failed: [] })
+    const collected: ArtifactEntry[] = []
+    const failed: string[] = []
+    await pool(list, 4, async (run) => {
+      const key = cacheKey(run)
+      const cached = !force ? cache.get(key) : undefined
+      if (cached) {
+        collected.push(...cached)
+        return
+      }
+      const [detail, files] = await Promise.all([
+        paasRunDetail(props.api!, run.agentID, run.runID).catch(() => undefined),
+        props.api!.request({ action: "run-files", agentID: run.agentID, runID: run.runID }).catch(() => undefined),
+      ])
+      if (!detail && !files) {
+        failed.push(run.chatTitle)
+        return
+      }
+      const items = readRunArtifacts({ run, detail, files })
+      cache.set(key, items)
+      collected.push(...items)
+    })
+    if (current !== epoch) return
+    setState({
+      entries: collected.sort((a, b) => b.at - a.at || a.name.localeCompare(b.name, "zh-CN")),
+      loading: false,
+      loaded: true,
+      failed,
+      updated: new Date().toLocaleTimeString(),
+    })
+  }
+  createEffect(
+    on(
+      [() => props.connected, () => props.scope, () => props.projectID, signature],
+      () => void load(),
+    ),
+  )
+
+  const save = async (entry: ArtifactEntry) => {
+    if (!props.api || state.saving) return
+    setState({ saving: entry.id, notice: "" })
+    try {
+      const result = paasRecord(
+        await props.api.request({
+          action: "download",
+          agentID: entry.agentID,
+          runID: entry.runID,
+          name: entry.name,
+          path: entry.path,
+          artifactID: entry.artifactID,
+        }),
+      )
+      setState(
+        "notice",
+        result?.saved ? `已保存 ${entry.name}` : `${entry.name} 未保存,文件仍保留在平台。`,
+      )
+    } catch (error) {
+      setState("notice", error instanceof Error ? error.message : "保存失败,请重试。")
+    } finally {
+      setState("saving", "")
+    }
+  }
+
+  const card = (entry: ArtifactEntry) => {
+    const category = artifactCategory(entry)
+    return (
+      <li class="paas-artifact-row">
+        <span class="paas-artifact-kind" data-category={category}>
+          {categoryLabels[category]}
+        </span>
+        <div class="paas-artifact-name">
+          <strong title={entry.name}>{entry.name}</strong>
+          <small>
+            {[entry.mime, formatSize(entry.size)].filter(Boolean).join(" · ") || entry.name.split(".").pop()?.toUpperCase()}
+          </small>
+        </div>
+        <div class="paas-artifact-actions">
+          <button
+            type="button"
+            aria-label={`预览 ${entry.name}`}
+            onClick={() =>
+              props.onPreview({
+                agentID: entry.agentID,
+                runID: entry.runID,
+                name: entry.name,
+                path: entry.path,
+                artifactID: entry.artifactID,
+                mime: entry.mime,
+                size: entry.size,
+              })
+            }
+          >
+            预览
+          </button>
+          <button
+            type="button"
+            aria-label={`保存 ${entry.name}`}
+            disabled={!!state.saving}
+            onClick={() => void save(entry)}
+          >
+            {state.saving === entry.id ? "保存中…" : "保存"}
+          </button>
+        </div>
+      </li>
+    )
+  }
+
+  return (
+    <section class="paas-artifact-page" aria-label="项目成果">
+      <div class="paas-section-title">
+        <div>
+          <h1>成果</h1>
+          <p>{props.projectName} · 聚合项目内已结束任务生成的文件,可预览或保存。</p>
+        </div>
+        <button type="button" disabled={!props.connected || state.loading} onClick={() => void load(true)}>
+          {state.loading ? "正在同步…" : "刷新成果"}
+        </button>
+      </div>
+      <div class="paas-artifact-counts">
+        <span>{library().length} 个文件</span>
+        <span>{groups().length} 个会话</span>
+        <small>{state.updated ? `更新于 ${state.updated}` : "正在读取项目成果…"}</small>
+      </div>
+      <div class="paas-artifact-toolbar">
+        <label>
+          搜索成果
+          <input
+            type="search"
+            placeholder="文件名或来源会话"
+            value={filters.query}
+            onInput={(event) => setFilters("query", event.currentTarget.value)}
+          />
+        </label>
+        <div class="paas-artifact-filter" role="group" aria-label="成果类型">
+          <For each={categories}>
+            {(category) => (
+              <button
+                type="button"
+                aria-pressed={filters.category === category.id}
+                onClick={() => setFilters("category", category.id)}
+              >
+                {category.label}
+                <Show when={(counts()[category.id] || 0) > 0}> · {counts()[category.id]}</Show>
+              </button>
+            )}
+          </For>
+        </div>
+      </div>
+      <Show when={state.notice}>
+        <p class="paas-notice" role="status">
+          {state.notice}
+        </p>
+      </Show>
+      <Show when={state.failed.length}>
+        <div class="paas-notice" role="status">
+          <p>部分任务的成果暂未同步,已展示其余内容;可稍后刷新重试。</p>
+          <details>
+            <summary>查看未同步任务 · {state.failed.length}</summary>
+            <p>{state.failed.join("、")}</p>
+          </details>
+        </div>
+      </Show>
+      <Show when={runs().length > maxRuns}>
+        <p class="paas-muted">仅聚合最近 {maxRuns} 个已结束任务;更早任务可在平台任务中查看。</p>
+      </Show>
+      <Show
+        when={props.connected && (state.loading || groups().length)}
+        fallback={
+          <div class="paas-task-empty">
+            <ResearchIcon kind="evidence" />
+            <strong>
+              {!props.connected
+                ? "连接平台后加载成果"
+                : !state.loaded
+                  ? "正在读取项目成果…"
+                  : runs().length && narrowed()
+                    ? "没有匹配的成果"
+                    : "还没有可归档的成果"}
+            </strong>
+            <p>
+              {!props.connected
+                ? "连接后会自动同步当前项目已结束任务的成果。"
+                : !state.loaded
+                  ? "请稍候。"
+                  : runs().length && narrowed()
+                    ? "调整搜索或类型筛选,或清除筛选条件。"
+                    : runs().length
+                      ? "已结束的任务没有返回可归档文件;可打开任务查看运行详情。"
+                      : "完成一项研究任务后,生成的文件会汇总到这里。"}
+            </p>
+            <Show when={props.connected && state.loaded && runs().length && narrowed()}>
+              <button type="button" onClick={() => setFilters({ query: "", category: "all" })}>
+                清除筛选
+              </button>
+            </Show>
+            <Show when={props.connected && state.loaded && !runs().length && props.onNewResearch}>
+              <button type="button" class="paas-primary" onClick={props.onNewResearch}>
+                开始新研究
+              </button>
+            </Show>
+          </div>
+        }
+      >
+        <Show when={state.loading && !state.loaded}>
+          <p class="paas-muted" role="status">
+            正在读取项目成果…
+          </p>
+        </Show>
+        <div class="paas-artifact-groups">
+          <For each={groups()}>
+            {(group) => (
+              <section class="paas-artifact-group" aria-label={`${group.run.chatTitle} 的成果`}>
+                <header>
+                  <div>
+                    <strong>{group.run.chatTitle}</strong>
+                    <span>
+                      {agentName(group.run.agentID)}
+                      <Show when={formatTime(group.run.at)}> · {formatTime(group.run.at)}</Show>
+                      <Show when={group.runs.size > 1}> · {group.runs.size} 个任务</Show>
+                      {" · "}
+                      {group.entries.length} 个文件
+                    </span>
+                  </div>
+                  <button type="button" onClick={() => props.onOpenRun(group.run)}>
+                    打开任务
+                  </button>
+                </header>
+                <ul>
+                  <For each={group.entries.slice(0, 8)}>{card}</For>
+                </ul>
+                <Show when={group.entries.length > 8}>
+                  <details class="paas-artifact-more">
+                    <summary>展开其余 {group.entries.length - 8} 个文件</summary>
+                    <ul>
+                      <For each={group.entries.slice(8, 200)}>{card}</For>
+                    </ul>
+                    <Show when={group.entries.length > 200}>
+                      <p class="paas-muted">
+                        此处最多展开 200 个文件;该任务工作区共 {group.entries.length} 个文件,其余请在任务中查看。
+                      </p>
+                    </Show>
+                  </details>
+                </Show>
+              </section>
+            )}
+          </For>
+        </div>
+      </Show>
+    </section>
+  )
+}
+
+async function pool<T>(items: T[], limit: number, task: (item: T) => Promise<void>) {
+  let index = 0
+  const workers = Array.from({ length: Math.min(limit, items.length) }, async () => {
+    while (index < items.length) await task(items[index++])
+  })
+  await Promise.all(workers)
+}
+
+const categoryRank: Record<ArtifactCategory, number> = { document: 0, image: 1, data: 2, other: 3 }
+
+function byRelevance(a: ArtifactEntry, b: ArtifactEntry) {
+  return (
+    categoryRank[artifactCategory(a)] - categoryRank[artifactCategory(b)] ||
+    Number(a.source !== "artifact") - Number(b.source !== "artifact") ||
+    a.name.localeCompare(b.name, "zh-CN")
+  )
+}

+ 4 - 0
packages/app/src/pages/paas/chat.tsx

@@ -30,6 +30,7 @@ import {
   hasConversationHistory,
   hasResearchContent,
   working,
+  type ResearchChat,
   type ResearchMessage,
 } from "./chat-state"
 import { createMaterials } from "./materials"
@@ -68,6 +69,7 @@ export function PaasChat(props: {
   inboxMount?: HTMLElement
   registerNewSession?: (create: (() => void) | undefined) => void
   registerRename?: (rename: ((title: string) => void) | undefined) => void
+  registerChats?: (get: (() => ResearchChat[]) | undefined) => void
   onTitle?: (title: string) => void
   onPreviewFile?: (file: PaasPreviewFile) => void
   previewFile?: PaasPreviewFile
@@ -325,9 +327,11 @@ export function PaasChat(props: {
     }
     props.registerNewSession?.(create)
     props.registerRename?.((title) => model.rename(title))
+    props.registerChats?.(() => state.chats)
     onCleanup(() => {
       props.registerNewSession?.(undefined)
       props.registerRename?.(undefined)
+      props.registerChats?.(undefined)
     })
   })
   onCleanup(() => {

+ 26 - 2
packages/app/src/pages/paas/index.tsx

@@ -29,6 +29,8 @@ import {
 } from "./layout"
 import { PaasPreview, clearPreviewCache, type PaasPreviewFile } from "./preview"
 import { PaasChat } from "./chat"
+import type { ResearchChat } from "./chat-state"
+import { PaasArtifacts } from "./artifacts"
 import { groupAgents, resolveAgentProfile } from "./agent-profiles"
 import { ProjectSwitcher } from "./project-switcher"
 import { bindProjectWorkspace, newProject, readProjectState, writeProjectState } from "./projects"
@@ -47,6 +49,7 @@ const pages = [
   { id: "chat", icon: "chat", name: "会话" },
   { id: "agents", icon: "agent", name: "智能体" },
   { id: "tasks", icon: "tasks", name: "平台任务" },
+  { id: "artifacts", icon: "evidence", name: "成果" },
   { id: "connection", icon: "settings", name: "平台设置" },
 ] as const
 
@@ -126,6 +129,7 @@ export default function PaasWorkspace(
   const [actionsMount, setActionsMount] = createSignal<HTMLDivElement>()
   const [inboxMount, setInboxMount] = createSignal<HTMLElement>()
   const actions: { newSession?: () => void; rename?: (title: string) => void } = {}
+  let chatsAccessor: (() => ResearchChat[]) | undefined
   let navToggle: HTMLButtonElement | undefined
   let navElement: HTMLElement | undefined
   const saveNavLayout = () => {
@@ -389,7 +393,7 @@ export default function PaasWorkspace(
   const goPage = (page: string) => {
     setUI("navOpen", false)
     workspace.setState("page", page)
-    if (page === "tasks") void tasks.refresh()
+    if (page === "tasks" || page === "artifacts") void tasks.refresh()
   }
   props.registerMenuCommand?.((id) => {
     if (id === "settings.open") {
@@ -1005,6 +1009,7 @@ export default function PaasWorkspace(
               inboxTasks={() => tasks.state.rows}
               registerNewSession={(create) => (actions.newSession = create)}
               registerRename={(rename) => (actions.rename = rename)}
+              registerChats={(get) => (chatsAccessor = get)}
               onTitle={(title) => setUI("chatTitle", title)}
               onPreviewFile={openPreview}
               previewFile={previewFile()}
@@ -1318,6 +1323,25 @@ export default function PaasWorkspace(
                 onNewResearch={() => actions.newSession?.()}
               />
             </Match>
+
+            <Match when={state.page === "artifacts"}>
+              <PaasArtifacts
+                api={platform.paas}
+                connected={state.connected}
+                scope={state.scope}
+                projectID={projects.activeID}
+                projectName={activeProject()?.name || "我的研究"}
+                chats={() => chatsAccessor?.() ?? []}
+                tasks={() => tasks.state.rows}
+                agents={state.agents}
+                onOpenRun={(run) => {
+                  setUI("chatTask", run.task || { run_id: run.runID, agent_id: run.agentID })
+                  workspace.setState("page", "chat")
+                }}
+                onPreview={openPreview}
+                onNewResearch={() => actions.newSession?.()}
+              />
+            </Match>
             <Match when={state.page === "resources"}>
               {settingsTabs()}
               <div
@@ -1496,7 +1520,7 @@ export default function PaasWorkspace(
           </Switch>
         </div>
       </main>
-      <Show when={state.page === "chat" && previewOpen()}>
+      <Show when={(state.page === "chat" || state.page === "artifacts") && previewOpen()}>
         <div
           class="paas-splitter paas-splitter-preview"
           role="separator"

+ 205 - 0
packages/app/src/pages/paas/studio.css

@@ -350,6 +350,196 @@
 .paas-task-page tbody tr:hover {
   background: var(--background-weak);
 }
+.paas-artifact-counts {
+  display: flex;
+  flex-wrap: wrap;
+  align-items: center;
+  gap: 10px;
+  padding: 0 0 8px;
+}
+.paas-artifact-counts > span {
+  background: var(--background-weak);
+  border-radius: 20px;
+  padding: 5px 12px;
+  font-size: var(--paas-type-caption);
+}
+.paas-artifact-counts > small {
+  margin-left: auto;
+  color: var(--text-weak);
+  font-variant-numeric: tabular-nums;
+}
+.paas-artifact-toolbar {
+  display: grid;
+  grid-template-columns: minmax(0, 1fr) auto;
+  gap: 16px;
+  align-items: end;
+  margin: 16px 0 20px;
+}
+.paas-artifact-toolbar > label {
+  display: flex;
+  flex-direction: column;
+  gap: 6px;
+  min-width: 0;
+  color: var(--text-weak);
+  font-size: var(--paas-type-caption);
+}
+.paas-artifact-toolbar input {
+  width: 100%;
+  padding: 9px 12px;
+  border: 1px solid var(--border-weak-base);
+  border-radius: 10px;
+  background: var(--background-base);
+  color: var(--text-base);
+  font: inherit;
+  font-size: var(--paas-type-body);
+}
+.paas-artifact-filter {
+  display: flex;
+  flex-wrap: wrap;
+  gap: 6px;
+}
+.paas-artifact-filter button {
+  border-radius: 999px;
+  padding: 6px 12px;
+  font-size: var(--paas-type-caption);
+  background: var(--background-base);
+}
+.paas-artifact-filter button[aria-pressed="true"] {
+  background: var(--paas-accent);
+  border-color: var(--paas-accent);
+  color: var(--paas-accent-contrast);
+}
+.paas-artifact-page > .paas-muted {
+  margin: 0 0 12px;
+  font-size: var(--paas-type-meta);
+}
+.paas-artifact-groups {
+  display: flex;
+  flex-direction: column;
+  gap: 18px;
+}
+.paas-artifact-group {
+  border: 1px solid var(--border-weak-base);
+  border-radius: 14px;
+  background: var(--paas-surface);
+  overflow: hidden;
+}
+.paas-artifact-group > header {
+  display: flex;
+  align-items: center;
+  justify-content: space-between;
+  gap: 12px;
+  padding: 13px 16px;
+  border-bottom: 1px solid var(--border-weak-base);
+  background: var(--background-weak);
+}
+.paas-artifact-group > header > div {
+  display: flex;
+  flex-direction: column;
+  gap: 2px;
+  min-width: 0;
+}
+.paas-artifact-group > header strong {
+  font-size: var(--paas-type-body);
+  overflow: hidden;
+  text-overflow: ellipsis;
+  white-space: nowrap;
+}
+.paas-artifact-group > header span {
+  color: var(--text-weak);
+  font-size: var(--paas-type-meta);
+}
+.paas-artifact-group > header > button {
+  flex-shrink: 0;
+  padding: 5px 11px;
+  font-size: var(--paas-type-meta);
+}
+.paas-artifact-group > ul {
+  display: flex;
+  flex-direction: column;
+  margin: 0;
+  padding: 0;
+  list-style: none;
+}
+.paas-artifact-row {
+  display: grid;
+  grid-template-columns: auto minmax(0, 1fr) auto;
+  align-items: center;
+  gap: 12px;
+  padding: 10px 16px;
+  border-top: 1px solid var(--border-weak-base);
+}
+.paas-artifact-row:first-child {
+  border-top: 0;
+}
+.paas-artifact-kind {
+  min-width: 42px;
+  padding: 3px 7px;
+  border-radius: 6px;
+  background: var(--background-weak);
+  color: var(--text-weak);
+  font-size: 11px;
+  text-align: center;
+}
+.paas-artifact-kind[data-category="document"] {
+  background: color-mix(in srgb, var(--paas-accent) 10%, transparent);
+  color: var(--paas-accent);
+}
+.paas-artifact-kind[data-category="image"] {
+  background: color-mix(in srgb, #88d8bc 24%, transparent);
+  color: light-dark(#1f6b55, #9fe5cc);
+}
+.paas-artifact-kind[data-category="data"] {
+  background: color-mix(in srgb, #ffd06c 28%, transparent);
+  color: light-dark(#8a6212, #f2cf86);
+}
+.paas-artifact-name {
+  display: flex;
+  flex-direction: column;
+  gap: 2px;
+  min-width: 0;
+}
+.paas-artifact-name strong {
+  font-size: var(--paas-type-caption);
+  font-weight: 600;
+  overflow: hidden;
+  text-overflow: ellipsis;
+  white-space: nowrap;
+}
+.paas-artifact-name small {
+  color: var(--text-weak);
+  font-size: var(--paas-type-meta);
+  overflow: hidden;
+  text-overflow: ellipsis;
+  white-space: nowrap;
+}
+.paas-artifact-actions {
+  display: flex;
+  gap: 6px;
+}
+.paas-artifact-actions button {
+  padding: 5px 10px;
+  font-size: var(--paas-type-meta);
+  white-space: nowrap;
+}
+.paas-artifact-more {
+  border-top: 1px solid var(--border-weak-base);
+}
+.paas-artifact-more > summary {
+  padding: 10px 16px;
+  color: var(--text-weak);
+  font-size: var(--paas-type-meta);
+  cursor: pointer;
+}
+.paas-artifact-more > .paas-muted {
+  margin: 0;
+  padding: 0 16px 12px;
+  font-size: var(--paas-type-meta);
+}
+.paas-artifact-page > .paas-task-empty {
+  display: flex;
+  flex-direction: column;
+}
 .paas-edit-footer {
   padding-block: 16px;
 }
@@ -605,6 +795,21 @@
   .paas-task-page > .paas-toolbar > label:first-child {
     grid-column: 1 / -1;
   }
+  .paas-artifact-toolbar {
+    grid-template-columns: minmax(0, 1fr);
+    gap: 12px;
+  }
+  .paas-artifact-counts > small {
+    flex-basis: 100%;
+    margin-left: 0;
+  }
+  .paas-artifact-row {
+    grid-template-columns: auto minmax(0, 1fr);
+    row-gap: 8px;
+  }
+  .paas-artifact-actions {
+    grid-column: 2;
+  }
   .paas-task-counts > small {
     flex-basis: 100%;
     margin-left: 0;