feat(diag): 增加现场诊断上报通道 (v0.5.3-local.15)

内嵌视图(DS Bot 等)没有 DevTools,无法读取插件运行现场。新增:
- 服务端 /api/worktable/diag(需鉴权):把客户端上报的 JSON 追加到
  <DSH_HOME>/logs/worktable-diag.log
- 客户端 apply() 在 1.5s/5s 各上报一次:href、__ModuleLoader__ 类型、
  style[data-dsh-plugin] 数量、.dsh-wt_section/.dsh-wt_edgeStrip 数量、
  sidebar/overlayHost 是否存在、body 子元素数、窗口宽度、最近 5 条 window 错误

用途:确认 DS Bot 视图里插件 client 是否加载、哪个座位渲染,据此再修复。
验证:npm run pack 全绿,双资产同源 aafb7ab2…。
This commit is contained in:
wangheng
2026-12-04 09:19:49 +08:00
parent 64a1d46b46
commit 3e7e2799c4
8 changed files with 120 additions and 12 deletions
+32
View File
@@ -3572,6 +3572,38 @@ function buildCustomLayoutPrompt(req: string): string {
export const inject = ['slots', 'locale', 'sessions', 'conversation', 'workspaces']
export function apply(ctx: any) {
// 现场诊断上报:内嵌视图没有 DevTools,把关键事实 POST 到宿主 /api/worktable/diag,
// 直接落到 <DSH_HOME>/logs/worktable-diag.log。上线稳定后可删。
try {
const sendDiag = (tag: string) => {
try {
void fetch('/api/worktable/diag', {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({
tag,
href: String(location.href),
loader: typeof (window as any).__ModuleLoader__,
styles: document.querySelectorAll('style[data-dsh-plugin]').length,
sections: document.querySelectorAll('.dsh-wt_section').length,
strips: document.querySelectorAll('.dsh-wt_edgeStrip').length,
sidebar: !!document.querySelector('aside, nav, [class*="SidebarRoot"], [class*="sidebar"]'),
overlayHost: !!document.querySelector('[data-shell-overlay]'),
bodyKids: document.body ? document.body.children.length : -1,
wide: (window as any).innerWidth,
errors: diagErrors.slice(-5),
}),
})
} catch { /* ignore */ }
}
const diagErrors: string[] = []
window.addEventListener('error', (e: any) => {
try { diagErrors.push(String(e?.message ?? e?.error ?? 'error')) } catch {}
})
window.setTimeout(() => sendDiag('t1500'), 1500)
window.setTimeout(() => sendDiag('t5000'), 5000)
} catch { /* ignore */ }
// 自定义窗口 → 宿主会话桥:保存 sessions/conversation/list 服务引用(模块级)
sessionBridge = { sessions: ctx.sessions ?? null, conversation: ctx.conversation ?? null, list: ctx.sessions?.list ?? null, workspaces: ctx.workspaces ?? null }
clientCtx = ctx