Files
apes-sidebar/src/client/subagent-chat.ts
T
Menghuan1918 9ccc147e00 feat(tasks): 第二轮真机反馈——聚合条动作行、模式 chip、弹窗用量/耗时、原生侧栏转录、动效
用户在自己跑的 3080 实例上测完报回六条,逐条修:

1. 「已完成的聚合卡下方空荡荡」= 上一轮把计数收进徽标后那条只剩一个
   chevron(我的取舍造成)。小条改为动作行:组图标 + 「展开」(新词条
   tasksFoldExpandShort × 20 词典)+ 出错尾注 + 展开箭头。
2. 「展开后的子代理点不回去」= 真缺陷:expandedGroups 压过了 foldedIds,
   展开组内卡片的 chevron 失效。改成手动折叠优先(手动 → 页级规则 →
   组展开),补模型 + 组件两层判别性用例。
3. 「一次性一直显示」→ 模式词搬进徽标行成 chip(用户口径)。智能体卡不再
   有 mono 元信息行,卡片高度预算拆成 GRAPH_AGENT_NODE_H / GRAPH_NODE_H
   (只有 workflow run 卡保留元信息行),rowStrideFor(nodes) 按模型里有没有
   run 选行距。
4. 动效:接入 @formkit/auto-animate(用户选定,~3KB、无依赖无安装脚本)+
   useAutoAnimateRef 包装(WAAPI 守卫 → jsdom 空转、尊重 reduced-motion),
   挂到画布卡片层 / 树视图 / 任务抽屉;详情卡另加 140ms 入场关键帧。核心
   bundle +56KB(未压缩 CJS)。
5. 弹窗多两项:Token 用量(宿主 tokenUsage 四桶求和,悬停给明细)+ 耗时
   (宿主 subagentTiming,按 3s 轮询刷新)。SidebarProjectionSnapshot 镜像
   补两个键、模型新增 metrics 入参;**按存在性渲染**,没有测量就不显示这一
   行(0 是投影初始态,与「没工作过」不可区分)。
6. 「查看转录」改为在原生右侧栏打开:宿主 ui-subagent 的 subagentchat tab
   类型(宿主自己的子代理列表就是点行=主窗、点 chevron=侧栏)。插件照抄其
   地址公式并调 openResource(..., { kind, preferNewPane: true }),三级降级回
   主窗;页脚变「主按钮 + caret 菜单(在主窗口中打开)」。

测试 2238 passed / 17 skipped(191 文件)、tsc 0 错误、eslint 0 错误、构建
通过;新构建已装进 sidebar-test profile,:3080 上挂载正常、0 pageerror。
动效观感与真实数据的两行数值未在真机逐帧核验(右栏在无头上下文里被
transform 移出视口,合成点击不稳)——已如实记进设计文档的第二轮偏差段。
2026-10-11 23:15:40 +08:00

86 lines
3.7 KiB
TypeScript

/**
* The host's OWN "subagent transcript in the right sidebar" affordance.
*
* DSH ships a native right-sidebar tab type for child transcripts
* (`@deepseek-ai/dsh-client-ui-subagent`, kind `subagentchat`, registered at the
* `builtin` band) and its subagent list already uses it: clicking a row opens
* the transcript in the MAIN view, and the small chevron beside it opens the
* same transcript in the sidebar. The Tasks page therefore hands the child over
* instead of re-implementing a transcript pane — one click opens the native tab,
* and the main column keeps whatever the reader was looking at.
*
* The address is `dsh-resource://subagentchat/session/<childId>?parent=&mode=`.
* The host exports neither its builder nor its parser to third parties, so the
* two lines below are a deliberate copy of the host's own formula; the parser
* (`parseSubagentChatAddress`) is the contract that keeps them honest.
*
* Every failure path answers `false` so the caller can fall back to the
* main-view jump it used before: a deployment without `ui-subagent` has no such
* tab type at all, and the public write face THROWS when no session seat is
* mounted (a global panel, a column that was never mounted).
*/
import type { Context, SidebarSubagentAddress } from '../context-types.ts'
/** The host's tab kind for an embedded child conversation. */
export const SUBAGENT_CHAT_KIND = 'subagentchat'
/** The host's `dsh-resource://` prefix for that tab type. */
export const SUBAGENT_CHAT_ADDRESS = 'dsh-resource://subagentchat/session/'
/** The tab registry, probed structurally (the service can arrive late). */
interface TabRegistryFace {
get?(kind: string): unknown
}
/** The write face of the native right column, structurally probed. */
interface SidebarRightFace {
openResource?(address: string, options?: { kind?: string; preferNewPane?: boolean }): void
}
/**
* The host's own subagent-chat resource address for one child session.
* @param address - the child's lineage (parent, child, mode).
*/
export function subagentChatAddress(address: SidebarSubagentAddress): string {
const query = new URLSearchParams({ parent: address.parentSessionId, mode: address.mode })
return `${SUBAGENT_CHAT_ADDRESS}${encodeURIComponent(address.childSessionId)}?${query}`
}
/** Whether the host can host a child transcript in its right column. */
export function hasTranscriptAside(ctx: Context): boolean {
try {
const tabs = ctx.get('sidebarRightTabs') as unknown as TabRegistryFace | undefined
if (tabs?.get?.(SUBAGENT_CHAT_KIND) === undefined) return false
return typeof (ctx.get('sidebarRight') as unknown as SidebarRightFace | undefined)?.openResource === 'function'
} catch {
return false
}
}
/**
* Open one child's transcript in the native right sidebar.
*
* @param ctx - the client context.
* @param address - the child to open.
* @returns whether the sidebar took it; `false` means the caller must fall back
* to the main-view jump (no such tab type, no right column, or the host threw
* because no session seat is mounted).
*/
export function openTranscriptAside(ctx: Context, address: SidebarSubagentAddress): boolean {
if (!hasTranscriptAside(ctx)) return false
try {
const right = ctx.get('sidebarRight') as unknown as SidebarRightFace
// `preferNewPane` mirrors the host's own subagent list: the transcript sits
// beside whatever the reader already has open, and degrades to the target
// pane when splitting is not allowed.
right.openResource?.(subagentChatAddress(address), {
kind: SUBAGENT_CHAT_KIND,
preferNewPane: true,
})
return true
} catch (error) {
console.error('[dsh-better-sidebar] open the child transcript in the sidebar failed:', error)
return false
}
}