'use strict'; window.AssistantLayout = { mount(host, { settings, usage, esc }) { host.innerHTML = `
返回工具DSH 助手${esc(settings.model || '模型未配置')}${settings.runtimePath ? '诊断已配置' : '待配置'}今日 ${usage.calls} / ${usage.limit}

新对话

${[ ['连接健康', 'status'], ['扫描异常', 'bpm'], ['归档失败', 'archive'], ['通知阻断', 'blockers'], ] .map( ([label, command]) => ``, ) .join( '', )}
`; const root = host.querySelector('.assistant-workspace'), body = root.querySelector('.aw-body'), leftButton = root.querySelector('[data-aw-left]'), rightButton = root.querySelector('[data-aw-right]'), closeButton = root.querySelector('[data-aw-close-right]'); let width = 0, leftOpen = true, rightOpen = true, leftWidth = 264, rightWidth = 320, lastWidth = 0; const shell = document.querySelector('#app>.page'); shell?.classList.add('dsh-focused'); function measure() { root.style.height = Math.max( 240, (window.visualViewport?.height || innerHeight) - root.getBoundingClientRect().top, ) + 'px'; width = root.clientWidth; if (width !== lastWidth) { if (width < 880) { leftOpen = false; rightOpen = false; } else if (width < 1180) { leftOpen = false; rightOpen = false; } else if (!lastWidth) { leftOpen = true; rightOpen = true; } lastWidth = width; } apply(); } function apply() { const narrow = width < 880; const columns = window.AssistantNative.computeColumns( width, leftOpen ? leftWidth : 0, rightOpen ? rightWidth : 0, narrow ? 0 : 56, ); if (!narrow && rightOpen && columns.rightbar === 0) rightOpen = false; root.classList.toggle('aw-narrow', narrow); root.classList.toggle('aw-left-open', leftOpen); root.classList.toggle('aw-right-open', rightOpen); root.classList.toggle('aw-left-collapsed', !leftOpen); leftButton.setAttribute('aria-expanded', String(leftOpen)); rightButton.setAttribute('aria-expanded', String(rightOpen)); rightButton.title = rightOpen ? '收起右侧栏' : '展开右侧栏'; body.style.gridTemplateColumns = narrow ? 'minmax(0,1fr)' : `${columns.sidebar}px ${leftOpen ? '5px' : '0px'} minmax(0,1fr) ${rightOpen ? '5px ' + columns.rightbar + 'px' : '0px 0px'}`; root.querySelector('.aw-sidebar').inert = !leftOpen; root.querySelector('.aw-context').inert = !rightOpen; } function closeRight() { rightOpen = false; apply(); rightButton.focus(); } closeButton.onclick = closeRight; leftButton.onclick = () => { leftOpen = !leftOpen; if (width < 880 && leftOpen) rightOpen = false; apply(); if (leftOpen) root.querySelector('#assistant-search').focus(); }; rightButton.onclick = () => { rightOpen = !rightOpen; if (width < 1180 && rightOpen) leftOpen = false; apply(); if (rightOpen) root.querySelector('[data-context-tab][aria-selected=true]').focus(); }; const onKey = (event) => { if ( event.key === 'Escape' && !root.querySelector('dialog[open]') && root.querySelector('#assistant-command-menu').hidden ) { if (width < 880 && leftOpen) { leftOpen = false; apply(); leftButton.focus(); } else if (rightOpen) { rightOpen = false; apply(); rightButton.focus(); } } }; root.addEventListener('keydown', onKey); const disposers = []; for (const [side, selector] of [ ['left', '.aw-drag-left'], ['right', '.aw-drag-right'], ]) { const bar = root.querySelector(selector); let drag = null; const move = (event) => { if (!drag) return; if (side === 'left') leftWidth = window.AssistantNative.clampWidth( drag.value + event.clientX - drag.x, 264, 420, ); else rightWidth = window.AssistantNative.clampWidth( drag.value - event.clientX + drag.x, 300, width * 0.7, ); apply(); }; bar.onpointerdown = (event) => { drag = { x: event.clientX, value: side === 'left' ? leftWidth : rightWidth }; bar.setPointerCapture(event.pointerId); }; bar.onpointermove = move; bar.onpointerup = bar.onpointercancel = () => { drag = null; }; bar.onkeydown = (event) => { if (!['ArrowLeft', 'ArrowRight'].includes(event.key)) return; event.preventDefault(); const delta = event.key === 'ArrowRight' ? 16 : -16; if (side === 'left') leftWidth = window.AssistantNative.clampWidth(leftWidth + delta, 264, 420); else rightWidth = window.AssistantNative.clampWidth(rightWidth - delta, 300, width * 0.7); apply(); }; disposers.push(() => { bar.onpointerdown = bar.onpointermove = bar.onpointerup = bar.onpointercancel = bar.onkeydown = null; }); } const observer = new ResizeObserver(measure); observer.observe(root); window.visualViewport?.addEventListener('resize', measure); measure(); return { root, showRight() { rightOpen = true; if (width < 1180) leftOpen = false; apply(); }, closeLeft() { if (width < 880) { leftOpen = false; apply(); } }, closeRight, dispose() { closeButton.onclick = null; observer.disconnect(); window.visualViewport?.removeEventListener('resize', measure); for (const dispose of disposers) dispose(); root.removeEventListener('keydown', onKey); shell?.classList.remove('dsh-focused'); }, }; }, };