Explorar el Código

fix(paas): close final inbox review findings

241880436@seecoder.cn hace 4 días
padre
commit
e1831fd637

+ 34 - 0
packages/app/e2e/paas/inbox.spec.ts

@@ -47,6 +47,40 @@ test("inbox panel closes on Escape inside it and on an outside pointer click", a
   await expect(panel).toHaveCount(0)
   await expect(panel).toHaveCount(0)
 })
 })
 
 
+test("non-active completed chat is recovered from the task index after reload", async ({ page }) => {
+  const connect = async (apiKey: string) => {
+    await page.getByLabel("API Key", { exact: true }).fill(apiKey)
+    await page.getByRole("button", { name: "连接平台", exact: true }).click()
+    await page.getByRole("textbox", { name: "消息", exact: true }).waitFor()
+  }
+  await page.goto("/e2e/paas/index.html?completed")
+  await connect("inbox-recover")
+  await page
+    .getByRole("button", { name: /已有研究/ })
+    .first()
+    .click()
+  await expect(page.getByRole("heading", { name: "研究计划", exact: true })).toBeVisible()
+  await expect(page.getByRole("button", { name: "待处理 1 项", exact: true })).toBeVisible()
+
+  // Switch to another chat with a saved draft so the completed chat is persisted but not active.
+  await page.locator(".paas-chat-header-actions").getByRole("button", { name: "新会话", exact: true }).click()
+  await expect(page.locator(".paas-topbar-chat-title")).toHaveText("新会话")
+  await page.getByRole("textbox", { name: "消息", exact: true }).fill("让完成会话保持非活动")
+
+  await page.reload()
+  await connect("inbox-recover")
+  // The completed history is never opened here; its cache loads without messages.
+  await expect(page.locator(".paas-topbar-chat-title")).toHaveText("新会话")
+  await expect(page.getByRole("heading", { name: "研究计划", exact: true })).toHaveCount(0)
+
+  await page.locator(".paas-sidebar").getByRole("button", { name: "平台任务", exact: true }).click()
+  await expect(page.locator(".paas-task-title")).toHaveText("分析材料")
+  const inbox = page.getByRole("button", { name: "待处理 1 项", exact: true })
+  await expect(inbox).toBeVisible()
+  await inbox.click()
+  await expect(page.getByRole("dialog", { name: "待处理" }).getByRole("button", { name: /已有研究/ })).toBeVisible()
+})
+
 test("opening an approval keeps it listed in inbox", async ({ page }) => {
 test("opening an approval keeps it listed in inbox", async ({ page }) => {
   await page.goto("/e2e/paas/index.html")
   await page.goto("/e2e/paas/index.html")
   await page.getByLabel("API Key", { exact: true }).fill("inbox-approval")
   await page.getByLabel("API Key", { exact: true }).fill("inbox-approval")

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

@@ -31,6 +31,9 @@
 - Inbox 只展示真实可确认状态;待确认和失败不会因为已读而消失。
 - Inbox 只展示真实可确认状态;待确认和失败不会因为已读而消失。
 - 完成未读的已读状态保存在本机,按平台作用域、窗口和项目隔离,不伪装成平台已读。
 - 完成未读的已读状态保存在本机,按平台作用域、窗口和项目隔离,不伪装成平台已读。
 - 任务索引只有在 `thread_id` 属于当前项目会话时才纳入 Inbox。
 - 任务索引只有在 `thread_id` 属于当前项目会话时才纳入 Inbox。
+- 非活动会话的完成未读按「本机已保存的会话 → 平台任务索引」恢复:重新连接后即可计入 Inbox,无需再次打开该会话。
+- v1 恢复限制:终态任务若早于当前任务历史窗口,或会话没有保存 `thread_id`,可能要打开会话后才会出现在 Inbox。
+- 本机归档的会话不进入 Inbox,归档的失败与完成不会长期占用顶栏入口。
 - Inbox v1 只覆盖当前项目;跨项目全局 Inbox 留到后续计划。
 - Inbox v1 只覆盖当前项目;跨项目全局 Inbox 留到后续计划。
 
 
 ---
 ---

+ 38 - 17
packages/app/src/pages/paas/inbox-panel.tsx

@@ -1,10 +1,23 @@
-import { For, Show, onCleanup, onMount } from "solid-js"
+import { Index, Show, onCleanup, onMount } from "solid-js"
 import { ResearchIcon } from "./research-icon"
 import { ResearchIcon } from "./research-icon"
 import { createInboxOpenState } from "./inbox-panel-state"
 import { createInboxOpenState } from "./inbox-panel-state"
 import type { InboxItem } from "./inbox"
 import type { InboxItem } from "./inbox"
 
 
 const labels = { approval: "待确认", failed: "失败", unread: "未读结果" }
 const labels = { approval: "待确认", failed: "失败", unread: "未读结果" }
 
 
+const stamp = (at: number) => {
+  if (!at) return ""
+  const date = new Date(at)
+  if (Number.isNaN(date.getTime())) return ""
+  return date.toLocaleString("zh-CN", {
+    ...(date.getFullYear() === new Date().getFullYear() ? {} : { year: "numeric" }),
+    month: "numeric",
+    day: "numeric",
+    hour: "2-digit",
+    minute: "2-digit",
+  })
+}
+
 export function InboxPanel(props: { items: InboxItem[]; onOpen: (item: InboxItem) => void }) {
 export function InboxPanel(props: { items: InboxItem[]; onOpen: (item: InboxItem) => void }) {
   const { open, setOpen } = createInboxOpenState(() => props.items)
   const { open, setOpen } = createInboxOpenState(() => props.items)
   let root: HTMLDetailsElement | undefined
   let root: HTMLDetailsElement | undefined
@@ -42,22 +55,30 @@ export function InboxPanel(props: { items: InboxItem[]; onOpen: (item: InboxItem
             <strong>待处理</strong>
             <strong>待处理</strong>
             <span>{props.items.length} 项</span>
             <span>{props.items.length} 项</span>
           </header>
           </header>
-          <For each={props.items}>
-            {(item) => (
-              <button
-                type="button"
-                class={`paas-inbox-item is-${item.kind}`}
-                onClick={() => {
-                  setOpen(false)
-                  props.onOpen(item)
-                }}
-              >
-                <span>{labels[item.kind]}</span>
-                <strong>{item.title}</strong>
-                <small>{item.detail}</small>
-              </button>
-            )}
-          </For>
+          <Index each={props.items}>
+            {(item) => {
+              const at = () => item().at
+              return (
+                <button
+                  type="button"
+                  class={`paas-inbox-item is-${item().kind}`}
+                  onClick={() => {
+                    setOpen(false)
+                    props.onOpen(item())
+                  }}
+                >
+                  <span>{labels[item().kind]}</span>
+                  <strong>{item().title}</strong>
+                  <small>{item().detail}</small>
+                  <Show when={stamp(at())}>
+                    <time class="paas-inbox-time" dateTime={new Date(at()).toISOString()}>
+                      {stamp(at())}
+                    </time>
+                  </Show>
+                </button>
+              )
+            }}
+          </Index>
         </section>
         </section>
       </details>
       </details>
     </Show>
     </Show>

+ 21 - 0
packages/app/src/pages/paas/inbox.test.ts

@@ -63,3 +63,24 @@ test("seen only hides completed unread items", () => {
   })
   })
   expect(items.map((item) => item.kind)).toEqual(["approval"])
   expect(items.map((item) => item.kind)).toEqual(["approval"])
 })
 })
+
+test("archived chats contribute no inbox items, including task-index rows", () => {
+  const items = buildProjectInbox({
+    projectID: "p1",
+    seen: new Set<string>(),
+    chats: [
+      {
+        ...chat("a", "p1", [
+          { id: "m1", role: "assistant", runID: "run-a", status: "failed", text: "", error: "失败" },
+          { id: "m2", role: "assistant", runID: "run-b", status: "completed", text: "完成报告" },
+        ]),
+        archived: true,
+      },
+    ],
+    tasks: [
+      { run_id: "run-c", thread_id: "thread-a", status: "failed", input: "归档任务" },
+      { run_id: "run-d", thread_id: "thread-a", status: "completed", input: "归档完成" },
+    ],
+  })
+  expect(items).toEqual([])
+})

+ 3 - 1
packages/app/src/pages/paas/inbox.ts

@@ -30,6 +30,7 @@ type Chat = {
   title: string
   title: string
   name: string
   name: string
   threadID: string
   threadID: string
+  archived?: boolean
   messages: Message[]
   messages: Message[]
 }
 }
 
 
@@ -44,7 +45,8 @@ export function buildProjectInbox(input: {
   tasks: Record<string, unknown>[]
   tasks: Record<string, unknown>[]
   seen: Set<string>
   seen: Set<string>
 }): InboxItem[] {
 }): InboxItem[] {
-  const chats = input.chats.filter((chat) => chat.projectID === input.projectID)
+  // Archived chats are intentionally inert: otherwise an archived failure would pin the badge forever.
+  const chats = input.chats.filter((chat) => chat.projectID === input.projectID && !chat.archived)
   const threads = new Set(chats.map((chat) => chat.threadID).filter(Boolean))
   const threads = new Set(chats.map((chat) => chat.threadID).filter(Boolean))
   const items = new Map<string, InboxItem>()
   const items = new Map<string, InboxItem>()
   const add = (item: InboxItem) => {
   const add = (item: InboxItem) => {

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

@@ -896,6 +896,10 @@
   color: var(--text-weak);
   color: var(--text-weak);
   font-size: var(--paas-type-meta);
   font-size: var(--paas-type-meta);
 }
 }
+.paas-inbox-item > .paas-inbox-time {
+  color: var(--text-weak);
+  font-size: var(--paas-type-meta);
+}
 .paas-inbox-item.is-approval > span {
 .paas-inbox-item.is-approval > span {
   color: var(--paas-accent);
   color: var(--paas-accent);
 }
 }