diff --git a/CLAUDE.md b/CLAUDE.md index b011329e..68ca3fe5 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -79,7 +79,7 @@ The frontend (`frontend-web/`) is a React 19 + Vite SPA: - **Routing**: React Router v7; top-level routes in `src/pages/PageRoutes.tsx`, workspace sub-routes in `src/pages/WorkspaceRoutes.tsx` - **Pages**: `ChatPage` (thread chat), `AgentChatPage` (custom agent chat), `AgentsPage`/`NewAgentPage` (agent management), `ScheduledTasksPage`/`ScheduledTaskRunDetailPage` (scheduled tasks), `LightAppManagementPage`/`LightAppListPage`/`LightAppIframeView` (轻应用中心 — register/list/embed mini-apps) -- **定时任务「JSON → HTML 模板填充」(模板数据转换器)**: a third scheduled-task execution mode. In the create/edit dialog (`ScheduledTasksPage.tsx`), selecting the built-in agent **「模板数据转换器」** (`execution_agent_name === "template-json-builder"`, `TEMPLATE_BUILDER_AGENT_ID`) reveals a 「HTML模板」 select (`useHtmlTemplates` → `GET /api/scheduled-tasks/html-templates`) + a **.json 上传** button (reads the file's text into the prompt box) and **hides** the 必须生成 HTML/Markdown switches (this mode always outputs HTML). The chosen template persists as `execution_context.template_config.template_id` (`TemplateFillConfig` in `core/scheduled-tasks/types.ts`). At run time the backend converts the source JSON (the task prompt) into that template's `DATA` structure, validates (retry-on-fail), fills the template, and stores an HTML page previewable via the existing run-detail HTML preview. The source JSON is **any** shape — the agent's `SOUL.md` maps it to the template's schema skeleton. See the backend CLAUDE.md「Template-fill mode」for the engine (`deerflow/runtime/scheduler/template_fill.py`), agent seed, and dispatch. +- **定时任务「JSON → HTML 模板填充」(模板数据转换器)**: a third scheduled-task execution mode. In the create/edit dialog (`ScheduledTasksPage.tsx`), selecting the built-in agent **「模板数据转换器」** (`execution_agent_name === "template-json-builder"`, `TEMPLATE_BUILDER_AGENT_ID`) reveals a 「HTML模板」 select (`useHtmlTemplates` → `GET /api/scheduled-tasks/html-templates`) + a **.json 上传** button (reads the file's text into the prompt box) and **hides** the 必须生成 HTML/Markdown switches (this mode always outputs HTML). The chosen template persists as `execution_context.template_config.template_id` (`TemplateFillConfig` in `core/scheduled-tasks/types.ts`). At run time the backend converts the source JSON (the task prompt) into that template's `DATA` structure, validates (retry-on-fail), fills the template, and stores an HTML page previewable via the existing run-detail HTML preview. The source can be **pure JSON, plain text, or text-with-embedded-JSON** — the backend pre-extracts any embedded JSON and the agent's `SOUL.md` maps it (or the plain text's semantics) to the template's schema skeleton. See the backend CLAUDE.md「Template-fill mode」for the engine (`deerflow/runtime/scheduler/template_fill.py`), agent seed, and dispatch. - **轻应用中心 (Light App Center)**: a sibling of 任务管理 in the sidebar with two pages — 应用管理 (admin registers `window_open` or `iframe` mini-apps with a route-param builder: login params resolved from `localStorage.userInfo`, theme params literal) and 应用列表 (card grid of `window_open` apps, `window.open` launch). `iframe` apps are mounted under a chosen parent menu (XK/PG/TY/综合管理) and **dynamically injected into the sidebar** by `core/page-layout/use-sidebar-menu.ts` (`useSidebarMenuItems`), opening in the `LightAppIframeView` host. Client + React Query hooks in `strategy-components/api/light-apps.ts`; URL builder/constants in `strategy-components/lib/light-app.ts`. Backend: `/api/light-apps` (global/shared, admin-gated writes). - **菜单管理 (Menu Management, admin-only)**: an **overlay** over the static sidebar menu — `MenuManagementPage` (`pages/MenuManagementPage.tsx`, route `/page/strategy/admin/menu-management`, opened from the admin-only 「菜单管理」 item in the **bottom-left settings dropdown** of `components/page-sidebar.tsx`). Admins rename / 停用·启用 / reorder (↑↓ or @dnd-kit drag) / re-parent (horizontal drag **or** the edit dialog's 「移动到」parent selector) any node across 一级/二级/三级, **including injected iframe light-app nodes** (`light-app-`). The static tree (`core/page-layout/sidebar-menu.ts`) stays the source of icons/routes; only per-node deltas (`label`/`disabled`/`parentId`/`sortOrder`) persist to the backend. Merge logic in `core/page-layout/menu-overrides.ts` (`applyMenuOverrides`, applied in `use-sidebar-menu.ts` after light-app injection, before role filter; disabling a node hides its whole subtree) — strict **3-level cap** (`wouldExceedDepth`). Client `strategy-components/api/menu-overrides.ts`. Backend: `/api/menu-overrides` (global/shared; open read, admin atomic replace-all). - **敏感词管理 (Sensitive Word Management)**: configures the **展示层脱敏映射** (原始词 → 替换词). **Gated on the username `lqq`** (not the admin role) — `getAccountDisplayName().toLowerCase() === "lqq"` (username = email `@` prefix, else `user_id`, same as the profile page); the dropdown entry, the route guard, and the page-level guard all use this check. `src/lib/desensitize.ts` ships a frozen seed map `SEED_DESENSITIZE_MAP` (the deployment seed) plus a live mutable `DESENSITIZE_MAP` (initialized from the seed so `desensitize()` works before any fetch). `DesensitizeWordsLoader` (mounted in `App.tsx` `AppProviders`) fetches `/api/sensitive-words` on startup and, if non-empty, calls `replaceDesensitizeMap(...)` to make the backend config the source of truth (empty/failed → keep seed). Page `SensitiveWordsPage.tsx` (route `/page/strategy/admin/sensitive-words`, opened from the 「敏感词管理」 item in the **bottom-left settings dropdown** of `components/page-sidebar.tsx`, present in **both** full + collapsed sidebar modes) lists/adds/edits/启停/deletes words and saves the **whole set atomically** (replace-all); a 「导入种子词」 button merges any missing `SEED_DESENSITIZE_MAP` entries into the editor. Client + hooks in `strategy-components/api/sensitive-words.ts` (`wordsToMap` folds enabled rows into the runtime map). Backend: `/api/sensitive-words` (global/shared; open read, write allowed for admin **or** the `lqq` account), mirroring 菜单管理's store shape. **侧边栏 + 导航栏 menu labels are desensitized** at the data source: `useSidebarMenuItems`/`useActiveThirdLevel` (`core/page-layout/use-sidebar-menu.ts`) map every node's `label` through a desensitizer built **directly from the `/api/sensitive-words` query** (`makeDesensitizer(wordsToMap(words))`, falling back to the global seed `desensitize` while empty) — this sidesteps the `replaceDesensitizeMap` effect-timing race. Only `label` is rewritten; `path`/`id`/`icon` are untouched so routing/highlight are unaffected. All nav surfaces (`page-sidebar.tsx`, `page-sidebar-dark.tsx`, `page-sidebar-v1.tsx`, `strategy-components/Header.tsx`, `PageRoutes.tsx`) consume this hook and are covered; `MenuManagementPage` uses the raw tree so admins still edit real labels. @@ -90,7 +90,7 @@ The frontend (`frontend-web/`) is a React 19 + Vite SPA: - **UI**: Radix UI primitives + TailwindCSS v4 + shadcn-style components in `src/components/ui/` - **Shims**: `src/shims/` provides `next/link` and `next/navigation` polyfills (original code was Next.js) - **Login URL params** (`LoginPage.tsx`, frontend-only — the backend never sees these): besides the auth params (`ticket`/`userId`/`env`/`theme`/`yUserId`/`token`/`access_token`/`authToken`/`password`), the page supports a **task deep-link** via `?taskId=&goPath=`. After login it calls the consumer API `GET {VITE_AIPI_CONSUMER_URL}/taskAnalyseSearch/cop-task-detail?taskId=` (header `Authorization: Bearer admin`, auto-injected by `utils/request.ts`), stashes the full `data` (`id/overview/taskDirection/taskName/taskContent`) into `sessionStorage["login.copTaskDetail"]`, then routes by `goPath`: base codes `3qfx`/`rwfx`/`xdfx` → that business's configured **single agent** Q&A inside a **任务工作区** (resolved via `/api/business-mapping`; `resolveTaskDeeplinkTarget` calls `persistTaskContext({taskId, agentId, openingText})` and navigates to the `…/chats` **index**, which opens the latest task conversation or 新建 — a 1:N task↔对话 workspace, NOT `pendingAgentMessage`); the `-A` suffix (`3qfx-A`/…) → **multi-agent roundtable** with `roundtablePrefill.businessCode` so the page auto-selects the configured 业务链条. **xdfx's deep-link `?taskId=` is actually an 行动id, not a 任务id** — `resolveDeeplinkTaskId(goPath, rawId)` (called in `LoginPage` before everything) detects `xdfx`/`xdfx-A` and resolves it via `GET {action_detail_url}/{actionId}` → `data.taskId` (`fetchTaskIdFromAction`; `action_test`+`mock.action_detail` for offline testing); the resolved 任务id then drives `cop-task-detail`, the purpose tree, and the 1:N binding (other businesses pass the id through unchanged). **xdfx additionally partitions its chat records by 行动id (action_id), NOT by task_id**: `resolveTaskDeeplinkTarget` sets `partitionByAction:true` + keeps the raw action_id as `TaskContext.actionId`, so new threads are tagged `metadata.{taskId,actionId}` (taskId kept only to preserve the backend「任务深链对话全局共享」semantics, which keys off `metadata.taskId`) and the conversation list filters by `actionId` (+`agent_id`) — different actions of the same task get separate lists. xdfx's first-question opening text also appends `行动id(action_id)为…` (see `buildOpeningText` / `taskThreadMetadata`). goPath→businessCode: `3qfx`→`3Q`, `rwfx`→`6BF`, `xdfx`→`7BF`. The roundtable target also threads the URL `taskId` into `roundtablePrefill.taskId` (`resolveTaskDeeplinkTarget(goPath, detail, taskId)`), which turns on two taskId-scoped behaviors: (1) **separate, unpartitioned per-task storage** — taskId 会商聊天记录 live in their **own** store/table (`roundtable_task_drafts`), keyed **only by `task_id`** (one taskId = many records, shared across users, **no user 分权** at all; `created_by` is audit-only), kept entirely out of the per-user personal store (`roundtable_drafts`, now strictly per-user) so the two never mix. Backend router `/api/roundtable-task-drafts` (`GET /by-task/{id}` + `/by-task/{id}/latest`, `POST`, `GET/PUT/DELETE /{id}` — all user-agnostic); frontend client `roundtable-planning/api/task-drafts.ts`, and `useDraftPersistence`/`useRoundtableDrafts` route **all** CRUD to it when a `taskId` is present (else the personal `drafts.ts`). The matching **background jobs** are shared by task too: `roundtable_jobs.task_id` marks a task job; reads/dedup/stream/resume/cancel pass `?task_id=` so any user opening the task sees the same running 研讨 (progress/flowchart), and the executor writes the final report back to the task-draft store. Existing rows are moved over by `scripts/migrate_roundtable_task_drafts.py` (migration `20260618_01`). The history dropdown filters to the task and 新建 keeps the binding; (2) **Step-3 auto structured output** — after the `roundtable-summary` agent writes the Markdown report it automatically runs a second round emitting a `flow-json` flowchart (`useStep3Summary` `autoFlow`+`chainLevels`), whose hierarchy follows the business chain's stage goals (任务 → 目的 → 行为体 → …; coordinatorPrompt-specified hierarchy wins) and whose nodes never carry 阶段编号/阶段名 (the prior bug). **Both targets render embedded under the 任务管理 layout** — nested routes under `task-management//{roundtable,agent/:agent_id/chats}` in `StrategyRoutes.tsx` (`` = `plan-task-sentiment` / `plan-task/plan-task-fx` / `plan-task/plan-task-action`, matching the COH中任务 menu paths in `sidebar-menu.ts`) so the global sidebar keeps 任务管理 → COH中任务 → the matching business highlighted. **All three single-agent businesses share `TaskFxWorkspace`** (`task-components/TaskFxWorkspace.tsx`): left = a「当前任务」card (`readCopTaskDetail()` 任务名称 + 简介, desensitized, 留存 above 新建对话) + per-task 1:N conversation list (`useTaskThreads(taskId, agentId, actionId?)` — filtered by **both** `metadata.taskId` AND `metadata.agent_id` so the three businesses' conversations stay isolated even though they share one taskId; **xdfx** passes a third `actionId` so it filters by `metadata.actionId` too, partitioning chat records per 行动 — `useChatsBase` derives it from `TaskContext.partitionByAction`) + 新建对话; the `…/chats` index (`TaskFxIndexResolver`) opens the latest task thread or 新建. The right `:thread_id` host differs by business: **rwfx** → `TaskFxChat` (`AgentChatPage taskGate`) = full workspace (non-`lite`): 目的树闸门 panel + 清除记录 (placed under 新建对话); **xdfx** → also `TaskFxChat` (same 目的树闸门 query+display, same `purpose_detail_url`) but workspace passed `lite`, **plus its own「清除记录」button** (`ActionClearButton`, under 新建对话) that deletes **by 行动id**: opening its confirm dialog first runs a「行动历史是否存在」pre-check (`fetchActionHistoryExists`; query endpoint `task_deeplink.action_history_url` is **address-TBD** — empty ⇒ unknown, does **not** block the delete; once a definite「无历史」comes back it disables 确认清除), then deletes via the **shared** delete endpoint `task_deeplink.delete_url` (migrated to `dropSixOrSevenData`, used by **both** rwfx + xdfx — Six=6BF/rwfx, Seven=7BF/xdfx): `deleteTaskPurpose(id, {idKind})` sends rwfx `?taskId=` (omits actionId) / xdfx `?actionId=` (omits taskId) — the unused param is **absent from the URL**, not null. `deleteTaskPurpose` + `fetchActionHistoryExists` live in `core/auth/task-purpose.ts`. **3qfx** → `TaskBindChat` (`AgentChatPage taskBind`, `lite`) = 1:N list only, no gate, and 新建对话 **auto-sends** the task opening text (`taskAutoSendText`; gate businesses send it via the gate's 开始问答 instead). **rwfx auto-starts the first Q&A when the 任务目的 query returns empty** (`TaskPurposePanel autoStartWhenEmpty`, threaded from the rwfx `TaskFxChat` only), **but gated by the 3q precheck**: on entering the rwfx workspace `RwfxSqGateProvider` (`task-components/rwfx-sq-gate.tsx`, wraps the workspace, rwfx only) calls `fetchSqReportStatus(taskId)` — `incomplete`(3q 无数据) pops the「3q 未完成,是否前往 3qfx」dialog AND **holds the auto-send**; the question is only sent when the user picks「暂不」(or dismisses — i.e. does NOT go to 3q analysis), while「前往 3qfx」navigates and discards the send. `complete`/`unknown` send immediately (no dialog). The panel's auto-start calls `useRwfxSqGate().gateStart(onStart)` instead of `onStart()`; the manual「开始问答」/覆盖确认 path is unchanged (ungated). This replaced the old standalone `RwfxSqReportGate` (which popped the same dialog but did not gate the auto-send). The 目的树闸门 (`TaskPurposePanel`) defaults **collapsed** and now keeps only 弹框查看 + 开始问答; the former jump buttons (编辑/下一步/3q详情/切换三情/弹框查看) all moved to the **configurable bottom 快捷跳转 bar** (`TaskJumpBar`, red 红底白字 buttons, right-aligned) driven by 按钮管理 — see the 按钮管理 bullet. `TaskPurposeDialog` (exported from `TaskPurposePanel`) backs both the gate zoom and the bottom bar's `purpose`-type button. `chatBasePath` keeps the post-send URL rewrite + new-chat button in the task-management context. Backend config `task_deeplink` (`config.yaml`, surfaced by `GET /api/public/config/task-deeplink`, mirrored in `core/auth/task-deeplink-config.ts`) adds `action_test`/`action_detail_url`/`detail_3q_url` + `mock.action_detail`. Any failure (no consumer URL / fetch error / unmapped goPath / unresolvable action id / no configured agent) silently falls back to the default home. Helpers: `core/auth/task-deeplink.ts`, `core/auth/task-purpose.ts`, `core/auth/task-deeplink-config.ts`, `core/threads/use-task-threads.ts`. -- **iframe 嵌入模式 (外部系统用 iframe 套用深链问答/会商)** — 三个**按标签页**开关,全部由深链 URL 参数开启、存进同一份 `sessionStorage` 会话(`embed.session`,键名常量在 `core/embed/embed-session.ts`),跨登录跳转/刷新/页内导航存活,**绝不跨标签污染**同浏览器另开的正常系统页。核心隔离手法:用 `sessionStorage`(按标签页/浏览上下文隔离,iframe 即便同源也有独立一份)而非 `localStorage`(跨标签共享)。开关:(1) **`?embed=1`(可带 `&theme=`)** — 去全局 chrome(`PageLayout` 的 `pageSidebarAllowed && !isEmbedActive()` → 隐藏 Header + PageSidebar)+ 按外部主题色**强制**明/暗:走 next-themes 的 `forcedTheme`(`App.tsx` `AppProviders` 调 `resolveForcedEmbedTheme`,**不写** localStorage `strategy-theme`),离散映射 `dark-blue`/`dark`→深、其余→浅;嵌入侧**绝不**调 `setTheme`/`persistSidebarEnabled`(那俩落 localStorage 跨标签污染,`LoginPage` 据 `readEmbedParam` 跳过)。(2) **`?hideJump=1`** — 隐藏深链底部「快捷跳转」栏 `TaskJumpBar` 的两部分(底部「下一步」等按钮 + 右侧垂直居中悬浮菜单),单智能体问答 + 会商共用该栏,`isJumpBarHidden()` 为真时整条 `return null`。(3) **登录用户隔离** — 嵌入态下鉴权/身份键(`deerflow.auth` token、`userInfo`、`login.*`、`tools_token`、maxkey/userDetail token)全部经 `core/auth/scoped-storage.ts` 的 `authStorage()`(嵌入→sessionStorage / 正常→localStorage)读写,使 iframe 里登录的用户与正常登录用户**完全隔离**、互不覆盖;所有 token 读取都过 `getStoredAuth()`/`getAuthorizationHeaderValue()`(API 客户端 `core/api/*` 全走这俩),改中心函数即让全体调用方自动隔离;跨标签账号变更监听 `AuthSyncWatcher`(`core/auth/sync.tsx`)在嵌入态禁用。嵌入会话在 `main.tsx` 渲染前 `syncEmbedSessionFromCurrentUrl()` 同步启用(早于任何鉴权写入,避免首帧 effect 顺序漏写 localStorage);`AppProviders` 的 effect 再按 SPA 导航同步。`embed=0`/`hideJump=0` 可显式关闭。正常(非嵌入)标签页所有 `isXxx()` 恒 false,行为**零变化**。第三个开关 `?isolate=1`(**独立登录会话**)把同一套**登录用户隔离**单独提供给**普通(带 chrome)标签页**——只切换鉴权存储、不去 chrome / 不强制主题 / 不动跳转栏:`authStorage()` 的条件从「仅嵌入」放宽为 `isEmbedActive() || isIsolatedSession()`,`AuthSyncWatcher` 的跨标签监听对嵌入态**或**独立态都即时忽略(handler 内实时判,运行时开关也即刻生效)。除 URL 参数外,**设置 → 外观 →「登录会话」** 有一个 Switch「独立登录会话(本标签页)」运行时切换(`setIsolatedSession`,`appearance-settings-page.tsx`):**开启时先 `migrateAuthToSession()`**(`scoped-storage.ts`,把 localStorage 的受保护键 `deerflow.auth`/`userInfo`/`userId`/`tools_token` + `login.*` 前缀快照搬进 sessionStorage)再翻标志,故无感不登出;此后本标签页登录态独立——别处登录/换号影响不到它,它换号也影响不到别人,但关掉该标签即结束(需重登)。开启给 toast 提示。 +- **iframe 嵌入模式 (外部系统用 iframe 套用深链问答/会商)** — 三个**按标签页**开关,全部由深链 URL 参数开启、存进同一份 `sessionStorage` 会话(`embed.session`,键名常量在 `core/embed/embed-session.ts`),跨登录跳转/刷新/页内导航存活,**绝不跨标签污染**同浏览器另开的正常系统页。核心隔离手法:用 `sessionStorage`(按标签页/浏览上下文隔离,iframe 即便同源也有独立一份)而非 `localStorage`(跨标签共享)。开关:(1) **`?embed=1`(可带 `&theme=`)** — 去全局 chrome(`PageLayout` 的 `pageSidebarAllowed && !isEmbedActive()` → 隐藏 Header + PageSidebar)+ 按外部主题色**强制**明/暗:走 next-themes 的 `forcedTheme`(`App.tsx` `AppProviders` 调 `resolveForcedEmbedTheme`,**不写** localStorage `strategy-theme`),离散映射 `dark-blue`/`dark`→深、其余→浅;嵌入侧**绝不**调 `setTheme`/`persistSidebarEnabled`(那俩落 localStorage 跨标签污染,`LoginPage` 据 `readEmbedParam` 跳过)。(2) **`?hideJump=1`** — 隐藏深链底部「快捷跳转」栏 `TaskJumpBar` 的两部分(底部「下一步」等按钮 + 右侧垂直居中悬浮菜单),单智能体问答 + 会商共用该栏,`isJumpBarHidden()` 为真时整条 `return null`。(2.5) **`?hideChrome=1`** — **仅**去全局 chrome(Header 导航栏 + PageSidebar 侧边栏),**不**强制主题、**不**隔离鉴权(区别于 `embed`:只想要一个干净全屏页面,如「大屏绘制」`/page/strategy/dashboard-agent?taskId=…&hideChrome=1`)。新增 `EmbedSession.hideChrome` 字段 + `readHideChromeParam()` + `isChromeHidden()`(取 `embed || hideChrome` 之并),与 `hideJump` 完全对称;`PageRoutes.tsx` 的 `PageLayout` 把 `chromeHidden`(`isChromeHidden() || readHideChromeParam(location.search)==="on"`)并入 `pageSidebarAllowed`,且其**优先级高于** dashboard-agent 路由原本的强制全局 chrome(`forceChromeForDashboardAgent`)。`hideChrome=0` 可显式关闭。(3) **登录用户隔离** — 嵌入态下鉴权/身份键(`deerflow.auth` token、`userInfo`、`login.*`、`tools_token`、maxkey/userDetail token)全部经 `core/auth/scoped-storage.ts` 的 `authStorage()`(嵌入→sessionStorage / 正常→localStorage)读写,使 iframe 里登录的用户与正常登录用户**完全隔离**、互不覆盖;所有 token 读取都过 `getStoredAuth()`/`getAuthorizationHeaderValue()`(API 客户端 `core/api/*` 全走这俩),改中心函数即让全体调用方自动隔离;跨标签账号变更监听 `AuthSyncWatcher`(`core/auth/sync.tsx`)在嵌入态禁用。嵌入会话在 `main.tsx` 渲染前 `syncEmbedSessionFromCurrentUrl()` 同步启用(早于任何鉴权写入,避免首帧 effect 顺序漏写 localStorage);`AppProviders` 的 effect 再按 SPA 导航同步。`embed=0`/`hideJump=0` 可显式关闭。正常(非嵌入)标签页所有 `isXxx()` 恒 false,行为**零变化**。第三个开关 `?isolate=1`(**独立登录会话**)把同一套**登录用户隔离**单独提供给**普通(带 chrome)标签页**——只切换鉴权存储、不去 chrome / 不强制主题 / 不动跳转栏:`authStorage()` 的条件从「仅嵌入」放宽为 `isEmbedActive() || isIsolatedSession()`,`AuthSyncWatcher` 的跨标签监听对嵌入态**或**独立态都即时忽略(handler 内实时判,运行时开关也即刻生效)。除 URL 参数外,**设置 → 外观 →「登录会话」** 有一个 Switch「独立登录会话(本标签页)」运行时切换(`setIsolatedSession`,`appearance-settings-page.tsx`):**开启时先 `migrateAuthToSession()`**(`scoped-storage.ts`,把 localStorage 的受保护键 `deerflow.auth`/`userInfo`/`userId`/`tools_token` + `login.*` 前缀快照搬进 sessionStorage)再翻标志,故无感不登出;此后本标签页登录态独立——别处登录/换号影响不到它,它换号也影响不到别人,但关掉该标签即结束(需重登)。开启给 toast 提示。 - **操作日志(Y-Log)上报** — 用户的关键操作(登录登出/查询/查看/增删改/启停/导入导出/问答等)成功后,**前端直连**外部接口 `POST {write_url}`(默认 `https://ch1.b.uat.4.cn/api/y-log/write`)记一条审计日志。核心模块 `src/core/log/`:`y-log.ts`(`writeYLog(params)` + `OptType` 枚举 0/1/3..12;**异步即发即忘、永不 await、永不抛错、失败静默**,自动把完整 url 转相对路径去 ip/host、对象入参/返回自动 `JSON.stringify` + 50k 裁剪、`optResult` 恒 0 只报成功),`y-log-config.ts`(从公开只读 `GET /api/public/config/y-log` 拉 `{enabled, writeUrl}`,模块级缓存 + 去重 + 默认兜底;`App.tsx` `AppProviders` 启动预热 `fetchYLogConfig()`),`y-log-token.ts`(token1 = token 登录的 `?authToken=`,经 [[scoped-storage]] 的 `authStorage*` 存取,嵌入态自动隔离)。**双门控**:仅当①存在 token1(即用 token 登录,`LoginPage` 成功后 `persistYLogToken(authToken)`,登出 `account-settings-page.tsx` 先报后清 token1)且②配置 `enabled && writeUrl` 才上报;否则一律不发。`optDetail` 统一「B1-CM助手-…」(**禁内部框架名**)。埋点**广覆盖**各 API client 的成功路径——原则是「一个用户操作(查看/查询/新增/编辑/删除/启停/导入导出)= 一条日志」,每个 API client 的**单条详情 GET(查看→view 4)/ 列表查询 GET(search 3)/ 新增 POST(create 9)/ 改 PUT·PATCH(edit 5)/ 删 DELETE(delete 6)/ 启停(enabled 11 / disabled 10)/ 导入导出(import 7 / export 8)**都各落一条,仅跳过高频 typeahead/状态轮询/纯 bootstrap config 读。覆盖文件:`strategy-components/api/{sensitive-words,menu-overrides,task-buttons,skill-addresses,light-apps,business-mapping}.ts`、`roundtable-planning/api/{drafts,task-drafts,roundtable-jobs,recommend,chains,multi-agent,dashboard-sessions}.ts`、`core/{agents,scheduled-tasks,knowledge,positions,tags,studio,system-settings,memory,mcp,models,custom-prompts,user-preferences,notifications,recommended-questions,user-qa,curator,admin,thread-shares,roundtable-draft-shares,tool-metrics,llm-metrics,note,artifacts}/api.ts`、`core/api/markdown-docx-export.ts`。**问答(Q&A)改为「一次大模型调用 = 一条日志」**:在共享的 `core/threads/hooks.ts` `useThreadStream` 的 `onLangChainEvent` 里监听 `on_chat_model_end`,每次模型调用结束就上报一条(optType 12,`reqParam` 取本次 input 的最后一条 user 文本 + 模型名,`returnParam` 取本次输出文本)——一个问答轮次里 lead agent / 子代理的**每次** LLM 调用都各记一条,覆盖所有走 `useThreadStream` 的页面(`ChatPage`/`AgentChatPage`/创建智能体/iframe/会商等);`ChatPage`/`AgentChatPage` 的 `onFinish` 仍额外保留一条轮次汇总。后端仅新增公开只读配置:`deerflow/config/y_log_config.py`(`YLogConfig{enabled,write_url}`)挂到 `AppConfig.y_log`,`app/gateway/routers/public_config.py` 加 `GET /api/public/config/y-log`,地址写在 `config.yaml` 的 `y_log` 段(mtime 热重载,前端无需重建);**不做后端代理**。Tests:`tests/test_y_log_config.py`。 ### Configuration diff --git a/frontend-web/docs/测试-chouqu.md b/frontend-web/docs/测试-chouqu.md new file mode 100644 index 00000000..6bfebde0 --- /dev/null +++ b/frontend-web/docs/测试-chouqu.md @@ -0,0 +1,148 @@ +# 定时任务 — 模板填充「源数据抽取」手工测试清单 + +> 覆盖功能:定时任务「模板数据转换器」内置 agent —— 把用户传入的源数据转换成 HTML +> 模板的 `DATA` 结构并填充生成可预览页面。**重点测「源数据抽取」**:源可能是 +> ① 纯 JSON、② 含 JSON 的文本、③ 纯文本,三种形态都要正确处理。 +> +> 测试环境:后端 `http://localhost:8001`(`make dev`),前端 `http://localhost:5174`(`pnpm dev`)。 +> 相关代码:`deerflow/runtime/scheduler/template_fill.py`(`extract_embedded_json`)、 +> `service.py`(`_run_template_fill_attempt` / `_build_conversion_prompt`)、 +> `pages/ScheduledTasksPage.tsx`。 + +--- + +## 前置 — 进入表单 + +| # | 步骤 | 预期结果 | +|---|------|----------| +| 0.1 | 任务管理 → 新建定时任务 | 弹出「新建定时任务」对话框 | +| 0.2 | 「执行智能体」下拉选择 **模板数据转换器** | 表单出现「HTML 模板」下拉;「必须生成 HTML/Markdown」两个开关隐藏 | +| 0.3 | 「HTML 模板」下拉选择 **no.1** | 下方出现「上传 .json」按钮 + 源数据文本框;说明含「未提供源 JSON 时,将直接展示该模板的默认数据」| + +--- + +## T1 — 源形态①:纯 JSON + +| # | 步骤 / 输入 | 预期结果 | +|---|------|----------| +| 1.1 | 在源数据框粘贴纯 JSON(示例见下「样例 A」) | 文本框正常接收,无报错 | +| 1.2 | 保存任务 → 「立即执行」 | 执行记录新增一条,状态最终 succeeded | +| 1.3 | 打开执行记录 → HTML 预览 | 渲染出 no.1 大屏,**总览指标/各列表数据来自粘贴的 JSON**(而非模板默认值)| +| 1.4 | 执行记录正文 | 文案为「已根据源数据填充模板「no.1」生成页面」| + +## T2 — 源形态②:含 JSON 的文本(抽取重点) + +| # | 步骤 / 输入 | 预期结果 | +|---|------|----------| +| 2.1 | 粘贴「样例 B」(前后是中文说明,中间夹一段 JSON) | 文本框正常接收 | +| 2.2 | 保存 → 立即执行 → 查看 HTML | 页面数据以**夹带的 JSON 为准**填充;正文里的补充说明(如「重点突出 X」)被一并参考 | +| 2.3 | 验证抽取正确性:JSON 字符串值里含 `}`(如 `"备注": "进度 80%}尚未完成"`) | 不会被误判为 JSON 块提前结束,整段 JSON 被完整抽取 | + +## T3 — 源形态③:纯文本(无 JSON) + +| # | 步骤 / 输入 | 预期结果 | +|---|------|----------| +| 3.1 | 粘贴「样例 C」(一段纯中文描述,无任何 JSON) | 文本框正常接收 | +| 3.2 | 保存 → 立即执行 → 查看 HTML | 智能体**理解文本语义**后据实填充模板,产出完整可预览页面(数据可能较稀疏但结构完整)| +| 3.3 | 不应报「未返回 JSON」类硬失败(除非模型彻底失败重试耗尽)| 状态 succeeded | + +## T4 — 空源 → 模板默认数据 + +| # | 步骤 | 预期结果 | +|---|------|----------| +| 4.1 | 源数据框留空,保存 → 立即执行 | **不调用模型**,直接用 no.1 模板自带的默认数据生成 | +| 4.2 | 执行记录正文 | 「未提供源数据,已用模板「no.1」的默认数据生成页面」| +| 4.3 | HTML 预览 | 展示模板内置的默认大屏 | + +## T5 — 上传 .json 文件 + +| # | 步骤 | 预期结果 | +|---|------|----------| +| 5.1 | 点击「上传 .json 文件」,选一个合法 `.json` | 文件内容被读入源数据文本框 | +| 5.2 | 上传一个非法 JSON 内容的文件 | toast 提示「文件不是合法 JSON,已填入文本框请检查」,内容仍填入(可手改)| +| 5.3 | 连续上传同一个文件两次 | 第二次仍能触发读取(input 已被重置 value)| + +## T6 — no.2(只展示模板) + +| # | 步骤 | 预期结果 | +|---|------|----------| +| 6.1 | 「HTML 模板」下拉选 **no.2** | **隐藏**上传按钮与源数据文本框;显示「该模板暂为直接展示已有数据,无需填写」| +| 6.2 | 即使之前填过源数据,保存 → 立即执行 | 忽略源数据,**原样输出** no.2 现有页面 | +| 6.3 | 执行记录正文 | 「已展示模板「no.2」的现有数据」| + +## T7 — 编辑回显 + +| # | 步骤 | 预期结果 | +|---|------|----------| +| 7.1 | 对已保存的模板任务点「编辑」 | 「执行智能体」「HTML 模板」「源数据」均正确回显 | +| 7.2 | 把模板从 no.1 改成 no.2 再保存 | 切到 no.2 时源数据区即时隐藏;保存后执行走只展示分支 | + +--- + +## 样例数据(可直接复制粘贴到源数据框) + +### 样例 A — 纯 JSON + +```json +{ + "overview": { + "核心指标": [ + { "名称": "综合区域", "数值": 7, "单位": "区", "说明": "测试数据" }, + { "名称": "组织与单位", "数值": 188, "单位": "个", "说明": "测试数据" } + ] + }, + "regions": [ + { "name": "测试区域甲", "scope": "本岛西岸" } + ], + "equipment": [ + { "name_zh": "测试装备X", "category": "无人系统", "status": "列装" } + ] +} +``` + +> 预期:总览第一项「综合区域」显示 **7**,「组织与单位」显示 **188**,区域/装备出现「测试区域甲」「测试装备X」。 + +### 样例 B — 含 JSON 的文本 + +``` +这是本月台海态势数据,请据此填充大屏,重点突出离岛防卫: + +{"overview": {"核心指标": [{"名称": "综合区域", "数值": 9, "单位": "区", "说明": "含离岛"}]}, "regions": [{"name": "离岛防区", "scope": "外岛", "备注": "进度 80%}尚未完成"}]} + +以上数据来自 6 月例会,务必准确,不要臆造未提供的字段。 +``` + +> 预期:① 数据以中间 JSON 为准(综合区域=9、出现「离岛防区」);② 字符串里的 `}`(`进度 80%}`)不破坏抽取;③ 前后的「重点突出离岛防卫」「务必准确」作为补充说明被模型参考。 + +### 样例 C — 纯文本 + +``` +请整理一份台湾滨海防卫概览:覆盖本岛沿岸 9 个综合区域,组织与单位约 280 个, +装备条目近百项(含无人系统、防空、海军平台等类别),并列出若干关键节点与近期演习。 +数据以离线知识为准,没有的字段留空即可。 +``` + +> 预期:智能体理解语义后据实填充,产出结构完整的页面(具体数值取决于模型,可较稀疏),不报硬失败。 + +--- + +## 后端单元测试(自动化补充) + +```bash +# 在 offline-backend-20260512/backend/ 下运行 +PYTHONPATH=. uv run --no-sync pytest tests/test_template_fill.py -v # 引擎:抽取/校验/填充/注册表 +PYTHONPATH=. uv run --no-sync pytest tests/test_template_fill_attempt.py -v # 调度器执行分支:三形态/默认/只展示/重试 +PYTHONPATH=. uv run --no-sync pytest tests/test_template_builder_seed.py -v # 内置 agent 种子 +``` + +抽取相关关键用例: +- `test_extract_embedded_json_pure_object` / `_pure_array` —— 纯 JSON。 +- `test_extract_embedded_json_text_with_json` / `_fenced` —— 含 JSON 的文本 / ```json 围栏。 +- `test_extract_embedded_json_plain_text_returns_none` —— 纯文本返回 None。 +- `test_extract_embedded_json_ignores_braces_in_strings` —— 引号内 `}` 不误判。 +- `test_text_with_embedded_json_surfaced_in_prompt` —— 转换 prompt 单独标注「识别到的结构化数据」。 +- `test_plain_text_source_converts` —— 纯文本仍照常转换。 +- `test_empty_source_uses_template_default` —— 空源用模板默认数据。 +- `test_display_only_template_renders_as_is` —— no.2 原样输出。 + +三个文件应全部通过(0 failed)。 diff --git a/frontend-web/src/core/embed/embed-session.ts b/frontend-web/src/core/embed/embed-session.ts index 6dcf0de1..8e0f8a32 100644 --- a/frontend-web/src/core/embed/embed-session.ts +++ b/frontend-web/src/core/embed/embed-session.ts @@ -39,6 +39,12 @@ export interface EmbedSession { theme: EmbedTheme; /** 隐藏深链底部「快捷跳转」栏(TaskJumpBar:底部按钮 + 右侧悬浮菜单)。 */ hideJump: boolean; + /** + * 仅去全局 chrome(Header 导航栏 + PageSidebar 侧边栏),**不**强制主题、**不**隔离鉴权。 + * 区别于 `embed`:嵌入态会额外强制主题 + 走 sessionStorage 隔离登录身份;`hideChrome` 只想要 + * 一个干净的全屏页面(如「大屏绘制」`?hideChrome=1`),其余行为与正常标签页完全一致。 + */ + hideChrome: boolean; /** 独立会话:鉴权身份按本标签页隔离(走 sessionStorage),用于同浏览器登录不同账号互不覆盖。 */ isolate: boolean; } @@ -69,6 +75,11 @@ export function readHideJumpParam(search: string): FlagParam { return readFlagParam(search, "hideJump"); } +/** 读 URL 里的 `hideChrome` 三态(仅去全局导航栏 + 侧边栏)。 */ +export function readHideChromeParam(search: string): FlagParam { + return readFlagParam(search, "hideChrome"); +} + /** 读 URL 里的 `isolate` 三态(独立会话登录)。 */ export function readIsolateParam(search: string): FlagParam { return readFlagParam(search, "isolate"); @@ -99,6 +110,7 @@ export function readEmbedSession(): EmbedSession | null { embed: p.embed === true, theme: p.theme === "dark" ? "dark" : "light", hideJump: p.hideJump === true, + hideChrome: p.hideChrome === true, isolate: p.isolate === true, }; } catch { @@ -109,7 +121,7 @@ export function readEmbedSession(): EmbedSession | null { /** 写会话;无任何开关置位时直接清除(保持 sessionStorage 干净)。隐私模式/quota 异常静默失败。 */ function writeEmbedSession(next: EmbedSession): void { try { - if (!next.embed && !next.hideJump && !next.isolate) { + if (!next.embed && !next.hideJump && !next.hideChrome && !next.isolate) { sessionStorage.removeItem(EMBED_SESSION_KEY); return; } @@ -129,6 +141,16 @@ export function isJumpBarHidden(): boolean { return readEmbedSession()?.hideJump === true; } +/** + * 本标签页是否要去全局 chrome(Header 导航栏 + PageSidebar 侧边栏)。 + * `embed` 已隐含去 chrome,故这里取「embed || hideChrome」之并——任一置位都隐藏。 + * 与 `isEmbedActive()` 的差别:`hideChrome` 不强制主题、不隔离鉴权,只去 chrome。 + */ +export function isChromeHidden(): boolean { + const s = readEmbedSession(); + return s?.embed === true || s?.hideChrome === true; +} + /** * 本标签页是否处于独立会话态:鉴权身份按标签页隔离(走 sessionStorage)。 * `embed` 已隐含同样的隔离,故 `authStorage()` 取「embed || isolate」之并;这里只判 `isolate`, @@ -146,7 +168,7 @@ export function isIsolatedSession(): boolean { export function syncEmbedSessionFromSearch(search: string): void { const cur = readEmbedSession() ?? - { embed: false, theme: "light" as EmbedTheme, hideJump: false, isolate: false }; + { embed: false, theme: "light" as EmbedTheme, hideJump: false, hideChrome: false, isolate: false }; const next: EmbedSession = { ...cur }; const embedParam = readEmbedParam(search); @@ -161,6 +183,10 @@ export function syncEmbedSessionFromSearch(search: string): void { if (hideJumpParam === "on") next.hideJump = true; else if (hideJumpParam === "off") next.hideJump = false; + const hideChromeParam = readHideChromeParam(search); + if (hideChromeParam === "on") next.hideChrome = true; + else if (hideChromeParam === "off") next.hideChrome = false; + const isolateParam = readIsolateParam(search); if (isolateParam === "on") next.isolate = true; else if (isolateParam === "off") next.isolate = false; @@ -208,6 +234,6 @@ export function resolveForcedEmbedTheme(search: string): EmbedTheme | undefined export function setIsolatedSession(on: boolean): void { const cur = readEmbedSession() ?? - { embed: false, theme: "light" as EmbedTheme, hideJump: false, isolate: false }; + { embed: false, theme: "light" as EmbedTheme, hideJump: false, hideChrome: false, isolate: false }; writeEmbedSession({ ...cur, isolate: on }); } diff --git a/frontend-web/src/pages/LoginPage.tsx b/frontend-web/src/pages/LoginPage.tsx index 8aa6a45b..0662c5bd 100644 --- a/frontend-web/src/pages/LoginPage.tsx +++ b/frontend-web/src/pages/LoginPage.tsx @@ -82,6 +82,17 @@ export default function LoginPage() { // 任务深链:外部系统带 ?taskId=&goPath= 时,登录后拉任务详情并直送对应问答/会商页 const taskId = searchParams.get('taskId')?.trim() ?? ''; const goPath = searchParams.get('goPath')?.trim() ?? ''; + // 通用「登录后跳指定页」:?redirect=page/strategy/dashboard-agent(值可不带前导斜杠, + // 也可自带 query,如 page/strategy/dashboard-agent?taskId=1580——记得整体 URL 编码)。 + // 优先级最高:显式指定即按它跳,先于 taskId/goPath 深链与默认首页。出于安全只接受**站内 + // 相对路径**:拒绝带协议的绝对 URL(http(s):、javascript: 等)、协议相对 URL(//host)与反斜杠, + // 避免开放式跳转;缺前导斜杠时自动补全。 + const redirectTo = useMemo(() => { + const raw = searchParams.get('redirect')?.trim() ?? ''; + if (!raw) return ''; + if (/^[a-z][a-z0-9+.-]*:/i.test(raw) || raw.startsWith('//') || raw.includes('\\')) return ''; + return raw.startsWith('/') ? raw : `/${raw}`; + }, [searchParams]); const externalParams = useMemo( () => ({ theme: searchParams.get('theme') ?? '', @@ -186,6 +197,13 @@ export default function LoginPage() { if (!isEmbed) persistSidebarEnabled(sidebarEnabled); setStatus('success'); + // 通用跳转:显式 ?redirect= 指定站内页面时,登录后直接跳过去(优先级最高, + // 先于 taskId/goPath 深链与默认首页)。value 自带的 query 会被原样保留。 + if (redirectTo) { + navigate(redirectTo, { replace: true }); + return; + } + // 任务深链:带 taskId + goPath 时拉任务详情并直送对应问答/会商页; // 任一环节失败(无地址/拉取失败/未配置智能体/goPath 无法识别)都回退默认首页。 if (taskId && goPath) { @@ -238,6 +256,7 @@ export default function LoginPage() { gatePassword, taskId, goPath, + redirectTo, isEmbed, ]); diff --git a/frontend-web/src/pages/PageRoutes.tsx b/frontend-web/src/pages/PageRoutes.tsx index a49f984c..208f82bc 100644 --- a/frontend-web/src/pages/PageRoutes.tsx +++ b/frontend-web/src/pages/PageRoutes.tsx @@ -6,7 +6,12 @@ import { PageSidebarDark } from "@/components/page-sidebar-dark"; import { isChatsIframeWorkspacePath } from "@/core/page-layout/chats-iframe-route"; import { readSidebarEnabled } from "@/core/page-layout/sidebar-enabled"; import { isWujieEnv } from "@/core/embed/wujie"; -import { isEmbedActive, readEmbedParam } from "@/core/embed/embed-session"; +import { + isEmbedActive, + isChromeHidden, + readEmbedParam, + readHideChromeParam, +} from "@/core/embed/embed-session"; import { useTheme } from "@/contexts/ThemeContext"; import { useLocation } from "react-router-dom"; import { useActiveThirdLevel } from "@/core/page-layout/use-sidebar-menu"; @@ -44,6 +49,13 @@ function PageLayout() { () => isEmbedActive() || readEmbedParam(location.search) === "on", [location.pathname, location.search], ); + // `?hideChrome=1`:仅去全局导航栏 + 侧边栏(不强制主题/不隔离鉴权),用于「大屏绘制」等想要 + // 干净全屏的页面。与 embed 一样按标签页 sessionStorage 持久化,跨登录跳转/页内导航存活;非置位 + // 标签页恒为 false,不受影响。按 location 重算以跟随页内导航。 + const chromeHidden = useMemo( + () => isChromeHidden() || readHideChromeParam(location.search) === "on", + [location.pathname, location.search], + ); // 「大屏绘制」独立页(/page/strategy/dashboard-agent)本就是「带导航栏 + 侧边栏」的独立页, // 但它常被深链「上一步」从去 chrome 的工作区/新标签打开——那里 chromeByPreference 可能为 false // (界面模式非全量、或会话级 sidebar 未置位),导致整页没有顶栏/侧栏。故对该路由**强制全局 chrome** @@ -52,7 +64,9 @@ function PageLayout() { const pageSidebarAllowed = (forceChromeForDashboardAgent || chromeByPreference) && !isChatsIframeWorkspacePath(location.pathname) && - !embedActive; + !embedActive && + // `?hideChrome=1` 显式去 chrome:优先级高于上面对 dashboard-agent 的强制全局 chrome。 + !chromeHidden; // h-full(100%)而非 h-screen(100vh):配合 globals.css 的 html/body/#root height:100% // 高度链,根布局跟随容器高度。全屏下 100% 解析到视口,与 h-screen 等价;无界等嵌套 diff --git a/frontend-web/src/roundtable-planning/dashboard-agent/Disposal.tsx b/frontend-web/src/roundtable-planning/dashboard-agent/Disposal.tsx index 875e302b..c641b947 100644 --- a/frontend-web/src/roundtable-planning/dashboard-agent/Disposal.tsx +++ b/frontend-web/src/roundtable-planning/dashboard-agent/Disposal.tsx @@ -230,23 +230,32 @@ function DisposalReal({ data }: { data: DisposalData }) { key={i} className="rounded-md border border-slate-200 bg-slate-50/60 p-4 dark:border-[var(--dash-border)] dark:bg-[var(--dash-elev)]" > - {/* 标题行:序号 + 建议内容 + 口径基调 */} -
+ {/* 标题行:序号 + 建议内容(基调移到下方独立成行,长文不再挤压标题) */} +
{i + 1}
{d.content || "—"}
- {d.tone && ( - - {d.tone} - - )}
+ {/* 基调:拆成关键词小药丸,整行自适应换行——长基调不再被压成右侧一长条。 + 与序号对齐缩进(序号 20px + gap 10px = 30px)。 */} + {d.tone && ( +
+ + 基调 + + {splitTone(d.tone).map((t, ti) => ( + + {t} + + ))} +
+ )} {/* 其余字段:带标签两列网格 */} {(d.method || d.effect || d.subject || d.basis) && ( -
+
{d.method && } {d.effect && } {d.subject && } @@ -262,6 +271,21 @@ function DisposalReal({ data }: { data: DisposalData }) { ); } +/** + * 把「基调」串按常见分隔符(顿号 / 逗号 / 斜杠 / 分号 / 竖线 / 空白)拆成关键词数组,去空去重。 + * 整串无分隔符(单个词或一句话)则原样返回单个元素——既支持「悲愤、追责、人道主义审判」拆成 + * 三枚药丸,也兼容只有一个基调词的情况。 + */ +function splitTone(raw: string): string[] { + const parts = raw + .split(/[、,,//;;||\s]+/) + .map((s) => s.trim()) + .filter(Boolean); + const seen = new Set(); + const uniq = parts.filter((p) => (seen.has(p) ? false : (seen.add(p), true))); + return uniq.length > 0 ? uniq : [raw.trim()]; +} + /** 处置建议卡片里的「标签 + 值」字段(标签红色小字,值正文)。 */ function Field({ label, value }: { label: string; value: string }) { const ds = useDesensitize(); diff --git a/frontend-web/src/roundtable-planning/hooks/useStep2Orchestration.ts b/frontend-web/src/roundtable-planning/hooks/useStep2Orchestration.ts index ff8615d0..4f843cfc 100644 --- a/frontend-web/src/roundtable-planning/hooks/useStep2Orchestration.ts +++ b/frontend-web/src/roundtable-planning/hooks/useStep2Orchestration.ts @@ -837,12 +837,22 @@ export function useStep2Orchestration( const findSeatArtifactSource = useCallback( ( rawPath: string, - ): { seatThreadId: string; messageId: string; toolCallId: string } | null => { + ): { + seatThreadId: string; + messageId: string; + toolCallId: string; + /** stub 里捕获的文件内容(仅 write_file 有;str_replace / 跨账号草稿恢复时常为 undefined)。 */ + content?: string; + } | null => { const target = rawPath.trim(); if (!target) return null; const targetBase = target.split("/").pop() ?? target; + const readContent = (tc: { args?: unknown }): string | undefined => { + const c = (tc.args as { content?: unknown })?.content; + return typeof c === "string" ? c : undefined; + }; let basenameMatch: - | { seatThreadId: string; messageId: string; toolCallId: string } + | { seatThreadId: string; messageId: string; toolCallId: string; content?: string } | null = null; for (const [seatThreadId, msgs] of Object.entries( seatStubMessagesRef.current, @@ -857,10 +867,10 @@ export function useStep2Orchestration( : ""; if (!p) continue; if (p === target) { - return { seatThreadId, messageId: msg.id, toolCallId: tc.id }; + return { seatThreadId, messageId: msg.id, toolCallId: tc.id, content: readContent(tc) }; } if (!basenameMatch && (p.split("/").pop() ?? p) === targetBase) { - basenameMatch = { seatThreadId, messageId: msg.id, toolCallId: tc.id }; + basenameMatch = { seatThreadId, messageId: msg.id, toolCallId: tc.id, content: readContent(tc) }; } } } @@ -879,10 +889,11 @@ export function useStep2Orchestration( if (!normalized) return; // present_files 呈现的文件多半是子智能体 write_file 写入的:真实内容/thread 在 stub 里。 - // 先反查 stub 走虚拟预览(内存内容)—— 关闭沙箱后再点文件卡也能显示,且不受 - // 总控 coordinator thread 在后端 artifacts 路由下 not found 的影响。 + // 先反查 stub:**仅当 stub 内存里确有内容**(流式期间 / 草稿恢复时捕获了 write_file content) + // 才走虚拟预览——关闭沙箱后再点也能显示,且不受总控 coordinator thread 在 artifacts 路由 + // not found 的影响。 const seatSource = findSeatArtifactSource(normalized); - if (seatSource) { + if (seatSource && typeof seatSource.content === "string" && seatSource.content.length > 0) { const virtualUrl = buildWriteFileVirtualUrl( normalized, seatSource.messageId, @@ -896,9 +907,14 @@ export function useStep2Orchestration( return; } - if (!threadId) return; + // stub 无内容(str_replace、或**别的账号**打开共享任务会商草稿时 stub 没带上内容)→ 落 HTTP + // artifacts 接口拉取。优先用真实「子席位 thread」(present_files 的文件物理落在子席位、且 + // 是 thread_type=roundtable 线程,后端按对话创建者解析路径 + 放行跨账号访问),它比 coordinator + // thread 更可能命中(coordinator 没有该文件 → 404)。这是修复「跨账号看不到第二步文件产物」的关键。 + const effectiveThreadId = seatSource?.seatThreadId || threadId; + if (!effectiveThreadId) return; - setActiveArtifactThreadId(threadId); + setActiveArtifactThreadId(effectiveThreadId); const prev = artifactPathsRef.current; if (!prev.includes(normalized)) { const next = [...prev, normalized]; diff --git a/frontend-web/src/roundtable-planning/pages/DashboardAgentPage.tsx b/frontend-web/src/roundtable-planning/pages/DashboardAgentPage.tsx index bbafd103..0432763b 100644 --- a/frontend-web/src/roundtable-planning/pages/DashboardAgentPage.tsx +++ b/frontend-web/src/roundtable-planning/pages/DashboardAgentPage.tsx @@ -15,7 +15,7 @@ import { useCallback, useEffect, useMemo, useRef, useState } from "react"; import { useLocation, useSearchParams } from "react-router-dom"; import { toast } from "sonner"; -import { Loader2, RefreshCw, Sparkles } from "lucide-react"; +import { Inbox, Loader2, RefreshCw, Sparkles } from "lucide-react"; import { fetchDashboardInputJson } from "@/core/auth/dashboard-input"; import { readCopTaskDetail } from "@/core/auth/task-deeplink"; @@ -77,6 +77,16 @@ function deepDesensitize(value: T, fn: (s: string) => string): T { type DashView = "chat" | "page"; type RenderMode = "app" | "html"; +/** + * 战情报告是否含可展示内容。`parseSqReport` **永远**返回非 null 的 SqReport 对象(各类目可为 null), + * 故判空必须看「是否至少有一个类目非空」,不能用 `!!report`——否则全类目皆空时仍误判为有数据, + * 进而渲染出 DEMO 兜底的大屏标题 + 空导航 Tab。全空 → 整页走空状态(不渲染大屏标题/导航/页脚)。 + */ +function sqReportHasContent(r: SqReport | null): boolean { + if (!r) return false; + return !!(r.enemy || r.ours || r.environment || r.judgement || r.decision || r.disposal); +} + /** * 静态页面阶段开关(先按设计图搭总览版式,动态数据后续再接): * - 默认落在「大屏页面」视图,直接展示 SituationOverview 静态版式; @@ -284,9 +294,10 @@ export default function DashboardAgentPage() { } }, [sqReport, desensitizeText]); - // 是否有可展示的真实数据:战情报告(safeReport)或已生成的大屏(report-json / HTML)。 - // 三者皆无 → 不渲染大屏的导航栏与标题,仅显示「暂无数据」。 - const hasData = !!safeReport || !!dashboardData || !!dashboardHtml; + // 是否有可展示的真实数据:战情报告**至少一个类目非空**(safeReport 恒为非 null 对象,不能用 + // `!!safeReport` 判空,见 sqReportHasContent),或已生成的大屏(report-json / HTML)。 + // 三者皆无 → 不渲染大屏的导航栏与标题,改显示整页空状态。 + const hasData = sqReportHasContent(safeReport) || !!dashboardData || !!dashboardHtml; // 战情多页:总览 + 六个详情页;详情页传入对应的(脱敏后)真实数据(无则页面回退占位)。 // 导航 Tab 文本(label)也经 desensitizeText 脱敏后再传给 DashboardApp 渲染导航栏。 @@ -410,9 +421,25 @@ export default function DashboardAgentPage() {
) : view === "page" ? ( !hasData ? ( - // 无数据:隐藏大屏导航栏与顶部标题,仅显示「暂无数据」。 -
- 暂无数据 + // 无数据:不渲染大屏标题/导航 Tab/页脚,整页改为一个干净的空状态(图标 + 文案 + 重试)。 +
+
+
+
+ +
+
+

+ 暂无大屏数据 +

+
) : renderMode === "html" && htmlBlobUrl ? (