lantern-harness 0.1.6 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/README.md +1 -1
- package/builtin/session/update-check.mjs +517 -0
- package/cli/lantern.mjs +123 -22
- package/cli/server.mjs +5 -2
- package/dist/500.html +3 -3
- package/dist/_astro/Base.Bum3N3jp.css +1 -0
- package/dist/_astro/Base.astro_astro_type_script_index_0_lang.D0snmAJ_.js +1 -0
- package/dist/_astro/{CaseExecBoard.FJ1Y9b4e.js → CaseExecBoard.BAV4EE3o.js} +1 -1
- package/dist/_astro/{CaseGenerateApp.CT2n4VOf.js → CaseGenerateApp.Bz4ryNJG.js} +1 -1
- package/dist/_astro/{CasesLibrary.BjrehOiI.js → CasesLibrary.BPifyHUA.js} +1 -1
- package/dist/_astro/{ChatApp.Dqfx4FcI.js → ChatApp.DLo31SYZ.js} +5 -5
- package/dist/_astro/{DashboardBoard.wILBO_CD.js → DashboardBoard.DtuJX0Oi.js} +2 -2
- package/dist/_astro/{DocsFileBrowser.D32MgVAR.js → DocsFileBrowser.D3cKurQE.js} +1 -1
- package/dist/_astro/{DocsPager.BARD7JvD.js → DocsPager.rzu4mnzw.js} +1 -1
- package/dist/_astro/{KnowledgeLibrary.C-Sg2R6B.js → KnowledgeLibrary.B0sO4QR1.js} +1 -1
- package/dist/_astro/{NavLibraries.BzInZVDf.js → NavLibraries.Cvg3wery.js} +1 -1
- package/dist/_astro/{PluginsPage.CVyua_fb.js → PluginsPage.DIltPILi.js} +2 -2
- package/dist/_astro/PluginsPage.uvmSuXzi.js +1 -0
- package/dist/_astro/PmBugsBoard.CiaIhCHv.js +1 -0
- package/dist/_astro/PmIterationsBoard.H67QwKFw.js +1 -0
- package/dist/_astro/{PmProjectDetail.CtQdpGes.js → PmProjectDetail.DqDoIg8a.js} +1 -1
- package/dist/_astro/PmProjectsBoard.nOC1Hugt.js +1 -0
- package/dist/_astro/PmRequirementsBoard.BPjZ7khP.js +1 -0
- package/dist/_astro/PmRequirementsBoard.CanxvcKg.js +1 -0
- package/dist/_astro/PmShared.CZnXaUq-.js +1 -0
- package/dist/_astro/{PromptsLibrary.Z1DQBrFL.js → PromptsLibrary.DU9EuSim.js} +1 -1
- package/dist/_astro/{ReportsPage.CGpIPPr9.js → ReportsPage.Cr88iz8c.js} +1 -1
- package/dist/_astro/{RequirementsLibrary.D8078xLd.js → RequirementsLibrary.BwriF8F0.js} +1 -1
- package/dist/_astro/{SearchableSelect.BTJoZC_a.js → SearchableSelect.Ctg8V1Z1.js} +1 -1
- package/dist/_astro/SettingsDialog.kpJwoEl3.js +1 -0
- package/dist/_astro/SpaceSwitcher.BEJo5KFi.js +7 -0
- package/dist/_astro/{TasksBoard.CL-sNPZN.js → TasksBoard.BZi_GBPG.js} +1 -1
- package/dist/_astro/{TemplatesLibrary.d6uIe7I-.js → TemplatesLibrary.T4K9jUex.js} +1 -1
- package/dist/_astro/{TestStatsBoard.CSdXWc4Q.js → TestStatsBoard.Dd1Kcmx6.js} +1 -1
- package/dist/_astro/{TodosBoard.nl23X5Gi.js → TodosBoard.C4yd_JFb.js} +1 -1
- package/dist/_astro/app-config.DKMxjv3g.js +1 -0
- package/dist/_astro/i18n.BXeGGutk.js +7 -0
- package/dist/_astro/{open-docs-in-session.B5cUxqHi.js → open-docs-in-session.B0ZdZNj2.js} +1 -1
- package/dist/_astro/{plugins.DaDJq-mn.js → plugins.D5ypJIXn.js} +1 -1
- package/dist/_astro/pm.BsnTv63L.js +4 -0
- package/dist/_astro/{settings.CMK4PEak.js → settings.CnDCvwnQ.js} +2 -2
- package/dist/_astro/{spaces-client.CoQfaOIO.js → spaces-client.Cai2tHEI.js} +1 -1
- package/dist/_astro/update.DXCPfU4a.js +1 -0
- package/dist/_astro/{view-prefs.Dhdh8Z5a.js → view-prefs.HCowOWXL.js} +1 -1
- package/dist/case-exec/index.html +4 -4
- package/dist/cases/generate/index.html +4 -4
- package/dist/cases/library/index.html +4 -4
- package/dist/dashboard/index.html +4 -4
- package/dist/docs/changelog/index.html +18 -4
- package/dist/docs/install/index.html +3 -3
- package/dist/docs/manual/index.html +15 -5
- package/dist/index.html +4 -4
- package/dist/knowledge/index.html +4 -4
- package/dist/knowledge//345/212/237/350/203/275/346/265/213/350/257/225/347/224/250/344/276/213/347/274/226/345/206/231/350/247/204/350/214/203/index.html +3 -3
- package/dist/plugins/index.html +4 -4
- package/dist/pm/bugs/index.html +4 -4
- package/dist/pm/iterations/index.html +4 -4
- package/dist/pm/projects/detail/index.html +4 -4
- package/dist/pm/projects/index.html +4 -4
- package/dist/pm/requirements/index.html +4 -4
- package/dist/prompts/index.html +4 -4
- package/dist/reports/index.html +4 -4
- package/dist/requirements/index.html +4 -4
- package/dist/tasks/index.html +4 -4
- package/dist/templates/index.html +4 -4
- package/dist/templates//345/212/237/350/203/275/346/265/213/350/257/225/346/212/245/345/221/212//345/212/237/350/203/275/346/265/213/350/257/225/346/212/245/345/221/212/346/250/241/346/235/277/index.html +3 -3
- package/dist/templates//346/200/247/350/203/275/346/265/213/350/257/225/346/212/245/345/221/212//346/200/247/350/203/275/346/265/213/350/257/225/346/212/245/345/221/212/346/250/241/346/235/277/index.html +3 -3
- package/dist/templates//346/200/247/350/203/275/346/265/213/350/257/225/347/224/250/344/276/213//346/200/247/350/203/275/346/265/213/350/257/225/347/224/250/344/276/213/346/250/241/346/235/277/index.html +3 -3
- package/dist/templates//346/216/245/345/217/243/346/265/213/350/257/225/346/212/245/345/221/212//346/216/245/345/217/243/346/265/213/350/257/225/346/212/245/345/221/212/346/250/241/346/235/277/index.html +3 -3
- package/dist/templates//350/207/252/345/212/250/345/214/226/346/265/213/350/257/225/347/224/250/344/276/213//350/207/252/345/212/250/345/214/226/346/265/213/350/257/225/347/224/250/344/276/213/346/250/241/346/235/277/index.html +3 -3
- package/dist/test-stats/index.html +4 -4
- package/dist/todos/index.html +4 -4
- package/docs//346/223/215/344/275/234/346/211/213/345/206/214.md +13 -2
- package/lh-plugins/lh-pm.mjs +18 -4
- package/lh-plugins/lh-update.mjs +171 -0
- package/package.json +1 -1
- package/dist/_astro/Base.DGaLtzMo.css +0 -1
- package/dist/_astro/Base.astro_astro_type_script_index_0_lang.uhTNjhRY.js +0 -1
- package/dist/_astro/PluginsPage.CS1GaJtR.js +0 -1
- package/dist/_astro/PmBugsBoard.BXUu0kNL.js +0 -1
- package/dist/_astro/PmIterationsBoard.Deso1uyK.js +0 -1
- package/dist/_astro/PmProjectsBoard.MM4vxneK.js +0 -1
- package/dist/_astro/PmRequirementsBoard.62ONLCH5.js +0 -1
- package/dist/_astro/PmRequirementsBoard.SLVDgspp.js +0 -1
- package/dist/_astro/PmShared.CwCmF-kI.js +0 -1
- package/dist/_astro/SettingsDialog.BA57gp90.js +0 -1
- package/dist/_astro/SpaceSwitcher.DZ8b_85M.js +0 -7
- package/dist/_astro/app-config.huKxSIlN.js +0 -1
- package/dist/_astro/i18n.Bbh04ngD.js +0 -7
- package/dist/_astro/pm.CpFmMslU.js +0 -4
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["_astro/lib.DJNDi_Ht.js","_astro/react-dom.CqAxpHMt.js","_astro/ExcelFieldTags.B_XMwNNx.js","_astro/jsx-runtime.BUXbF_vF.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{c as e,n as t,t as n}from"./react-dom.CqAxpHMt.js";import{B as r,H as i,
|
|
2
|
+
import{c as e,n as t,t as n}from"./react-dom.CqAxpHMt.js";import{B as r,H as i,U as a,V as o,W as s,i as c,p as l,r as u,t as d,u as f,z as p}from"./app-config.DKMxjv3g.js";import{a as m,i as h,o as g,r as _,t as v}from"./plugins.D5ypJIXn.js";import{a as y,n as b}from"./view-prefs.HCowOWXL.js";import{c as x,d as S,f as C,l as w,n as T,t as E,u as D}from"./SearchableSelect.Ctg8V1Z1.js";import{i as ee,n as te,r as O,t as ne}from"./menu.Bkluqxic.js";import{t as re}from"./jsx-runtime.BUXbF_vF.js";import{t as ie}from"./ConfirmDialog.CBVsDJ8f.js";import{t as k}from"./DatePicker.CMfX7F6z.js";import{t as A}from"./SelectDropdown.Buv7rQJ_.js";import{a as ae,c as j,d as M,f as oe,i as se,n as ce,o as N,r as le,s as ue,t as de,u as fe}from"./ExcelFieldTags.B_XMwNNx.js";import{a as pe,i as P,r as me,s as he,t as F}from"./llm.BZEzE0x2.js";import{_ as I,d as ge,f as L,g as _e,l as ve,r as ye,s as be}from"./project-docs.Cd2gKPKh.js";import{n as xe,t as Se}from"./doc-roots.DAJP9Svr.js";import{i as Ce,n as we,r as Te,t as Ee}from"./prompts-meta.F4wwkjUA.js";import{d as De,f as Oe,l as ke,m as Ae,o as je,p as Me,r as Ne,s as Pe,y as Fe}from"./settings.CnDCvwnQ.js";import{C as Ie,D as Le,E as Re,O as ze,S as Be,T as Ve,_ as He,a as Ue,b as We,c as Ge,d as Ke,f as qe,g as Je,h as Ye,i as Xe,l as Ze,m as Qe,n as $e,o as et,p as tt,r as nt,s as rt,u as it,v as at,w as ot,x as st,y as ct}from"./open-docs-in-session.B0ZdZNj2.js";import{n as R}from"./i18n.BXeGGutk.js";import{$ as lt,A as ut,B as dt,C as ft,D as pt,E as mt,F as ht,G as gt,H as _t,I as vt,J as yt,K as bt,L as xt,M as St,N as Ct,O as wt,P as Tt,Q as Et,R as Dt,T as Ot,U as kt,V as At,W as jt,X as Mt,Y as Nt,Z as Pt,_ as Ft,a as It,at as Lt,b as Rt,c as zt,d as Bt,et as Vt,f as Ht,g as Ut,h as Wt,i as Gt,it as Kt,j as qt,k as Jt,l as Yt,m as Xt,n as Zt,nt as Qt,o as $t,p as en,q as tn,r as nn,rt as rn,s as an,t as on,tt as sn,u as cn,v as z,w as ln,x as un,y as dn,z as fn}from"./PluginsPage.DIltPILi.js";import{C as pn,D as mn,O as hn,P as gn,S as B,T as _n,a as vn,b as yn,d as bn,g as xn,h as Sn,j as Cn,l as wn,r as Tn,s as En,t as Dn,w as On,x as kn,y as An}from"./pm.BsnTv63L.js";import{A as jn,C as V,D as Mn,N as Nn,O as Pn,P as Fn,S as In,T as Ln,_ as Rn,a as zn,b as Bn,c as Vn,d as Hn,g as Un,i as Wn,l as Gn,m as Kn,n as qn,o as Jn,r as Yn,t as Xn,u as H,v as Zn,x as Qn,y as $n}from"./tasks.otRBFydq.js";import{n as er,s as tr,t as nr}from"./report-prompt.Cmw4XzfY.js";import{t as rr}from"./SlideOverDrawer.TPbGEoWn.js";import{t as ir}from"./NamePromptDialog.Dl5kSnQI.js";var U=e(t(),1),ar=e(n(),1),or=`/__tb_sessions/runs`;async function sr(e){try{return(await fetch(or,{signal:e??AbortSignal.timeout(1500)})).ok}catch{return!1}}async function cr(e){let t=await fetch(or,{signal:e??AbortSignal.timeout(3e3)});if(!t.ok)return[];let n=await t.json();return Array.isArray(n.runs)?n.runs:[]}async function lr(e){let t=await fetch(or,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)}),n=await t.json().catch(()=>({}));return t.ok?{ok:!0}:{ok:!1,error:n.error||`HTTP ${t.status}`}}async function ur(e){await fetch(`${or}/${encodeURIComponent(e)}/stop`,{method:`POST`}).catch(()=>{})}async function dr(e){try{let t=await fetch(`${or}/${encodeURIComponent(e)}`,{signal:AbortSignal.timeout(3e3)});return t.status===404?{ok:!1}:t.ok?await t.json():null}catch{return null}}function fr(e){return e===`completed`||e===`stopped`||e===`error`}function pr(e,t,n,r){let i=new AbortController,a=`${or}/${encodeURIComponent(e)}/events?after=${Math.max(0,t)}`;return(async()=>{try{let e=await fetch(a,{headers:{Accept:`text/event-stream`},signal:i.signal});if(!e.ok||!e.body){r?.(Error(`SSE ${e.status}`));return}let t=e.body.getReader(),o=new TextDecoder,s=``;for(;;){let{done:e,value:a}=await t.read();if(e){i.signal.aborted||r?.(Error(`SSE disconnected`));break}s+=o.decode(a,{stream:!0});let c=s.split(`
|
|
3
3
|
`);s=c.pop()??``;for(let e of c){let t=e.trim();if(!t.startsWith(`data:`))continue;let r=t.slice(5).trim();if(r)try{n(JSON.parse(r))}catch{}}}}catch(e){if(e instanceof DOMException&&e.name===`AbortError`)return;r?.(e instanceof Error?e:Error(String(e)))}})(),()=>i.abort()}function mr(e,t,n){let r=!1,i=Math.max(0,t),a=0,o=null,s,c=n.maxAttempts??10,l=()=>{r=!0,s!=null&&clearTimeout(s),s=void 0,o?.(),o=null},u=()=>{r||n.signal?.aborted||(o?.(),o=pr(e,i,e=>{typeof e.seq==`number`&&Number.isFinite(e.seq)&&(i=Math.max(i,e.seq)),n.onEvent(e),e.type===`status`&&fr(e.status)&&(n.onTerminal?.(e),l())},t=>{r||n.signal?.aborted||(async()=>{a+=1;try{let r=await dr(e);if(r?.ok&&typeof r.seq==`number`&&(i=Math.max(i,r.seq)),r?.ok&&fr(r.status)){let e={type:`status`,status:r.status,seq:r.seq,assistant:r.assistant};n.onEvent(e),n.onTerminal?.(e),l();return}if(r&&r.ok===!1){n.onGaveUp?.(Error(t.message||`run not found`)),l();return}}catch{}if(a>=c){n.onGaveUp?.(t),l();return}let r=Math.min(4e3,250*a);s=setTimeout(u,r)})()}))},d=()=>l();return n.signal?.addEventListener(`abort`,d),u(),()=>{n.signal?.removeEventListener(`abort`,d),l()}}function hr(e){for(let t of e)if(t.role===`user`&&typeof t.content==`string`){let e=t.content.trim();if(e)return e}return``}function gr(e,t){let n=(e||``).trim()||`新对话`;return n===`新对话`||n===Ie(t)}function _r(e){let t=String(e??``).trim().replace(/^["「『]+|["」』]+$/g,``).replace(/\s+/g,` `).replace(/^标题[::]\s*/i,``);return t=t.replace(/[。.!!]+$/g,``).trim(),t?t.length>28?`${t.slice(0,28)}…`:t:``}async function vr(e,t,n){let r=t.trim().slice(0,800);if(!r)return null;let i=[{role:`system`,content:`你为对话生成侧栏短标题。只输出标题本身:中文优先,不超过 16 个字,无引号、无标点收尾、无解释。`},{role:`user`,content:`用户首条消息:\n${r}\n\n请给出标题:`}];try{return _r(await me(e,i,n))||null}catch{return null}}function yr(e){let t=Array.isArray(e.messages)?e.messages:[],n=0,r=0,i=0,a=0,o=0;for(let e of t){if(!e||typeof e!=`object`)continue;let t=e;t.role===`user`?n+=1:t.role===`assistant`&&(r+=1);let s=t.usage;if(s&&typeof s==`object`){let e=s;typeof e.promptTokens==`number`&&(i+=e.promptTokens),typeof e.completionTokens==`number`&&(a+=e.completionTokens),typeof e.totalTokens==`number`?o+=e.totalTokens:(typeof e.promptTokens==`number`||typeof e.completionTokens==`number`)&&(o+=(Number(e.promptTokens)||0)+(Number(e.completionTokens)||0))}}let s=e.goal,c=!!(s&&s.status!==`cleared`&&s.text?.trim());return{sessionId:e.id,title:e.title||`新对话`,messageCount:t.length,userCount:n,assistantCount:r,promptTokens:i,completionTokens:a,totalTokens:o,createdAt:e.createdAt,updatedAt:e.updatedAt,hasGoal:c,todoCount:Array.isArray(e.todos)?e.todos.length:0}}function br(e){let t=new Date(e.createdAt).toLocaleString(),n=new Date(e.updatedAt).toLocaleString();return[`会话:${e.title}`,`消息 ${e.messageCount}(用户 ${e.userCount} / 助手 ${e.assistantCount})`,`用量≈ 输入 ${e.promptTokens} · 输出 ${e.completionTokens} · 合计 ${e.totalTokens}`,`待办 ${e.todoCount} · 目标 ${e.hasGoal?`有`:`无`}`,`创建 ${t}`,`更新 ${n}`].join(`
|
|
4
4
|
`)}var xr=new Map,Sr=new Map,Cr=40;function wr(e,t,n=``){return`${e}:${t}:${n}`}function Tr(e){for(;e.size>Cr;){let t=e.keys().next().value;if(t===void 0)break;e.delete(t)}}function Er(e,t,n,r,i=``){let a=e===`outline`?xr:Sr,o=wr(t,n,i),s=a.get(t);if(s&&s.stamp===o)return s.value;let c=r();return a.set(t,{stamp:o,value:c}),Tr(a),c}var Dr=`/__tb_sessions/log`;function Or(e){let t=String(e.userContent??``).trim(),n=String(e.assistantContent??``).trim(),r=String(e.reasoning??``).trim(),i=[];if(t&&i.push({role:`user`,content:t}),n||r){let e={role:`assistant`,content:n};r&&(e.reasoning_content=r),i.push(e)}return i}async function kr(e){try{let t=await fetch(Dr,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e),signal:AbortSignal.timeout(5e3)}),n=await t.json().catch(()=>({}));return t.ok?{ok:!0,path:n.path}:{ok:!1,error:n.error||`HTTP ${t.status}`}}catch(e){return{ok:!1,error:e instanceof Error?e.message:String(e)}}}function Ar(e){return String(e??``).trim()}function jr(e,t=80){let n=Ar(e).replace(/\s+/g,` `);return n?n.length>t?`${n.slice(0,t)}…`:n:``}function Mr(e,t=40){let n=[],r=null;for(let i=0;i<e.length;i++){let a=e[i];if(a.role===`user`){let e=Ar(a.content),t=jr(e);if(!t)continue;r&&n.push({index:n.length+1,userPreview:r.preview,assistantPreview:``,userText:r.text,assistantText:``,userTime:r.time,endMessageIndex:r.messageIndex}),r={text:e,preview:t,time:typeof a.time==`number`?a.time:void 0,messageIndex:i}}else if(a.role===`assistant`&&r){let e=Ar(a.content),t=Ar(a.reasoning)||void 0;n.push({index:n.length+1,userPreview:r.preview,assistantPreview:jr(e)||(t?`(含思考)`:``),userText:r.text,assistantText:e,reasoning:t,reasoningDuration:typeof a.reasoningDuration==`number`?a.reasoningDuration:void 0,userTime:r.time,assistantTime:typeof a.time==`number`?a.time:void 0,endMessageIndex:i}),r=null}if(n.length>=t)break}return r&&n.length<t&&n.push({index:n.length+1,userPreview:r.preview,assistantPreview:``,userText:r.text,assistantText:``,userTime:r.time,endMessageIndex:r.messageIndex}),n}function Nr(e,t){let n=String(t??``).trim();return!n||n===`inherit`||n===e.model?e:{...e,model:n}}var W=`/__tb_fs`,Pr=`你可以使用 office_to_pdf:优先用本机 LibreOffice 转为 PDF;若未安装,则对 docx/xlsx/pptx 降级抽取正文为同目录 .extracted.md(需写权限)。`,Fr={type:`function`,function:{name:`office_to_pdf`,description:`Convert Office docs to PDF via LibreOffice when available; otherwise extract text to .extracted.md for docx/xlsx/pptx.`,parameters:{type:`object`,properties:{path:{type:`string`,description:`Input file path relative to workspace (or absolute when allowed)`},outDir:{type:`string`,description:`Optional output directory (default: same as input)`}},required:[`path`]}}};async function Ir(e,t,n){if(e!==`office_to_pdf`)return JSON.stringify({error:`unknown tool: ${e}`});let r={};try{r=JSON.parse(t||`{}`)}catch{return JSON.stringify({ok:!1,error:`invalid JSON arguments`})}let i=String(r.path??``).trim();if(!i)return JSON.stringify({ok:!1,error:`path is required`});try{let e=await(await fetch(`${W}/office-to-pdf`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({path:i,outDir:typeof r.outDir==`string`?r.outDir:void 0,access:n}),signal:AbortSignal.timeout(13e4)})).json().catch(()=>({}));return JSON.stringify(e,null,2)}catch(e){return JSON.stringify({ok:!1,error:e instanceof Error?e.message:String(e)})}}var Lr=`/__tb_fs`,Rr=`你可以使用 load_workspace_dependencies:查询本机 node / npm / pnpm / python 等可执行文件绝对路径(需本地 fs 服务)。`,zr={type:`function`,function:{name:`load_workspace_dependencies`,description:`Resolve absolute paths of common runtimes/package managers on this machine (node, npm, pnpm, python, …).`,parameters:{type:`object`,properties:{}}}};async function Br(e){if(e!==`load_workspace_dependencies`)return JSON.stringify({error:`unknown tool: ${e}`});try{let e=await fetch(`${Lr}/workspace-dependencies`,{signal:AbortSignal.timeout(8e3)}),t=await e.json().catch(()=>({}));if(!e.ok){let n=typeof t==`object`&&t&&`error`in t?String(t.error):`HTTP ${e.status}`;return JSON.stringify({ok:!1,error:n})}return JSON.stringify(t,null,2)}catch(e){return JSON.stringify({ok:!1,error:e instanceof Error?e.message:String(e)})}}function Vr(e){return Array.isArray(e)}function Hr(e){return Vr(e)?e.some(e=>e.type===`image_url`):!1}function Ur(e){let t=e.filter(e=>e.type===`text`).map(e=>e.text),n=e.filter(e=>e.type===`image_url`).length,r=n>0?`[image-offload] 已卸载 ${n} 张图片(超预算,仅保留最近附图)。`:``;return[{type:`text`,text:[...t,r].filter(Boolean).join(`
|
|
5
5
|
`)||r||`(图片已卸载)`}]}function Wr(e,t={}){let n=Math.max(0,Math.floor(t.keepRecentImageMessages??1)),r=[];for(let t=0;t<e.length;t++){let n=e[t];n.role===`user`&&Hr(n.content)&&r.push(t)}if(r.length<=n)return e;let i=new Set(r.slice(-n)),a=!1,o=e.map((e,t)=>e.role!==`user`||!Hr(e.content)||i.has(t)||!Vr(e.content)?e:(a=!0,{...e,content:Ur(e.content)}));return a?o:e}function Gr(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var Kr=Gr();function qr(e){Kr=e}var Jr={exec:()=>null};function G(e,t=``){let n=typeof e==`string`?e:e.source,r={replace:(e,t)=>{let i=typeof t==`string`?t:t.source;return i=i.replace(Yr.caret,`$1`),n=n.replace(e,i),r},getRegex:()=>new RegExp(n,t)};return r}var Yr={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceTabs:/^\t+/,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] /,listReplaceTask:/^\[[ xX]\] +/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,unescapeTest:/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/gi,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:e=>RegExp(`^( {0,3}${e})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),hrRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}#`),htmlBeginRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}<(?:[a-z].*>|!--)`,`i`)},Xr=/^(?:[ \t]*(?:\n|$))+/,Zr=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,Qr=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,$r=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,ei=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,ti=/(?:[*+-]|\d{1,9}[.)])/,ni=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,ri=G(ni).replace(/bull/g,ti).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,``).getRegex(),ii=G(ni).replace(/bull/g,ti).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),ai=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,oi=/^[^\n]+/,si=/(?!\s*\])(?:\\.|[^\[\]\\])+/,ci=G(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace(`label`,si).replace(`title`,/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),li=G(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,ti).getRegex(),ui=`address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul`,di=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,fi=G(`^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))`,`i`).replace(`comment`,di).replace(`tag`,ui).replace(`attribute`,/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),pi=G(ai).replace(`hr`,$r).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`|lheading`,``).replace(`|table`,``).replace(`blockquote`,` {0,3}>`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace(`list`,` {0,3}(?:[*+-]|1[.)]) `).replace(`html`,`</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,ui).getRegex(),mi={blockquote:G(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace(`paragraph`,pi).getRegex(),code:Zr,def:ci,fences:Qr,heading:ei,hr:$r,html:fi,lheading:ri,list:li,newline:Xr,paragraph:pi,table:Jr,text:oi},hi=G(`^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)`).replace(`hr`,$r).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`blockquote`,` {0,3}>`).replace(`code`,`(?: {4}| {0,3} )[^\\n]`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace(`list`,` {0,3}(?:[*+-]|1[.)]) `).replace(`html`,`</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,ui).getRegex(),gi={...mi,lheading:ii,table:hi,paragraph:G(ai).replace(`hr`,$r).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`|lheading`,``).replace(`table`,hi).replace(`blockquote`,` {0,3}>`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace(`list`,` {0,3}(?:[*+-]|1[.)]) `).replace(`html`,`</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,ui).getRegex()},_i={...mi,html:G(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace(`comment`,di).replace(/tag/g,`(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b`).getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:Jr,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:G(ai).replace(`hr`,$r).replace(`heading`,` *#{1,6} *[^
|
|
@@ -72,7 +72,7 @@ ${e.templateBody?`\n\n### 用例模板:${e.templateTitle||e.templateId||``}\n$
|
|
|
72
72
|
{"需求名称":"...","覆盖需求率":0-100,"未覆盖说明":["..."],"编写说明":"...","用例":[...]}
|
|
73
73
|
- 不要输出 JSON 以外的解释性正文;界面只会展示执行摘要,用例由系统静默入库`}function Zo(e=0){return`正在编写用例…\n\n已用 ${Math.max(0,Math.floor(e))}s · 通常约 30–120 秒\n完成后将给出覆盖率与入库结果。`}function Qo(e){if(!e.ok)return[`**执行失败**`,``,e.error||`未知错误`,``,`可调整插件中的需求 / 模板 / 提示词后重试。`].join(`
|
|
74
74
|
`);let t=[`**执行成功**`,``,`- 需求名称:${e.title||`—`}`,`- 共编写:${e.count??0} 条用例`,`- 覆盖需求率:${e.coverageRate==null?`未给出(已按用例入库)`:`${e.coverageRate}%`}`];e.path&&t.push(`- 入库文件:用例管理/${e.path}`),e.writeNote&&t.push(``,`**编写说明**`,e.writeNote);let n=e.uncovered??[];if(t.push(``,`**未覆盖 / 未编写原因**`),n.length)for(let e of n)t.push(`- ${e}`);else t.push(`- 无(模型未声明未覆盖项)`);let r=e.fieldGaps??[];if(r.length){t.push(``,`**字段完整性检测**`);for(let e of r)t.push(`- ${e}`)}return t.join(`
|
|
75
|
-
`)}async function $o(e){if(!_(`cases`))throw Error(g(`cases`));let t=w(e.caseType),n=Jo(e.title),r=e.outputFormat===`md`?`.md`:e.outputFormat===`csv`?`.csv`:`.xlsx`,i=e.linkedPath||`${n}${r}`;i.includes(`/`)&&!e.linkedPath&&(i=`${n}${r}`);let a=e.headers.length?e.headers:[...fe];return e.outputFormat===`md`?await I(`cases`,i,ue(e.cases,e.title,a)):e.outputFormat===`csv`?await I(`cases`,i,N(e.cases,a)):await _e(`cases`,i,await j(e.cases,a,t.label)),i}async function es(e,t,n){let r=qo(e);if(!r){let e=`未能解析出用例结果,未写入文件`;return{ok:!1,error:e,summary:Qo({ok:!1,error:e})}}let i=t.templateHeaders.length>0?t.templateHeaders:[...fe],a=ce(r.cases,i),o=r.docTitle||n||w(t.caseType).label,s=Yo(a,i);try{let e=await $o({cases:a,headers:i,caseType:t.caseType,outputFormat:t.outputFormat,title:o}),n=Qo({ok:!0,title:o,path:e,count:a.length,coverageRate:r.coverageRate,uncovered:r.uncovered,writeNote:r.writeNote,fieldGaps:s});return{ok:!0,path:e,count:a.length,title:o,coverageRate:r.coverageRate,uncovered:r.uncovered,writeNote:r.writeNote,fieldGaps:s,summary:n}}catch(e){let t=e instanceof Error?e.message:String(e);return{ok:!1,error:t,summary:Qo({ok:!1,error:t})}}}function ts(){let e=u().promptKinds;return
|
|
75
|
+
`)}async function $o(e){if(!_(`cases`))throw Error(g(`cases`));let t=w(e.caseType),n=Jo(e.title),r=e.outputFormat===`md`?`.md`:e.outputFormat===`csv`?`.csv`:`.xlsx`,i=e.linkedPath||`${n}${r}`;i.includes(`/`)&&!e.linkedPath&&(i=`${n}${r}`);let a=e.headers.length?e.headers:[...fe];return e.outputFormat===`md`?await I(`cases`,i,ue(e.cases,e.title,a)):e.outputFormat===`csv`?await I(`cases`,i,N(e.cases,a)):await _e(`cases`,i,await j(e.cases,a,t.label)),i}async function es(e,t,n){let r=qo(e);if(!r){let e=`未能解析出用例结果,未写入文件`;return{ok:!1,error:e,summary:Qo({ok:!1,error:e})}}let i=t.templateHeaders.length>0?t.templateHeaders:[...fe],a=ce(r.cases,i),o=r.docTitle||n||w(t.caseType).label,s=Yo(a,i);try{let e=await $o({cases:a,headers:i,caseType:t.caseType,outputFormat:t.outputFormat,title:o}),n=Qo({ok:!0,title:o,path:e,count:a.length,coverageRate:r.coverageRate,uncovered:r.uncovered,writeNote:r.writeNote,fieldGaps:s});return{ok:!0,path:e,count:a.length,title:o,coverageRate:r.coverageRate,uncovered:r.uncovered,writeNote:r.writeNote,fieldGaps:s,summary:n}}catch(e){let t=e instanceof Error?e.message:String(e);return{ok:!1,error:t,summary:Qo({ok:!1,error:t})}}}function ts(){let e=u().promptKinds;return i(e?.length?e:p)}function ns(e){let t=ts();return t.find(t=>t.id===e)??t[0]??p[0]}function rs(e){let t=i(e);return f({promptKinds:t}),d(),t}function is(e){let t=e.trim();if(!t)throw Error(`类型名称不能为空`);if(t.length>40)throw Error(`类型名称过长(最多 40 字)`);let n=ts();if(n.some(e=>e.label===t))throw Error(`已存在「${t}」`);let i={id:o(),label:t,hint:r(t)};return rs([...n,i]),i}function as(e,t){let n=t.trim();if(!n)throw Error(`类型名称不能为空`);if(n.length>40)throw Error(`类型名称过长(最多 40 字)`);let i=ts(),a=i.findIndex(t=>t.id===e);if(a<0)throw Error(`类型不存在`);if(i.some(t=>t.id!==e&&t.label===n))throw Error(`已存在「${n}」`);let o=i[a],s={...o,label:n,hint:o.id===`case`||o.id===`general`?o.hint:r(n)},c=[...i];return c[a]=s,rs(c),s}function os(e){let t=ts();if(t.length<=1)throw Error(`至少保留一个提示词类型`);if(!t.some(t=>t.id===e))throw Error(`类型不存在`);return rs(t.filter(t=>t.id!==e))}function ss(e){return`${ns(e.kind).label} · ${e.titleHint.trim()||`未命名`}`}function cs(e){let t=e.match(/```(?:json)?\s*([\s\S]*?)```/)?.[1]??e.match(/\{[\s\S]*\}/)?.[0];if(!t)return null;try{let e=JSON.parse(t);if(!e||typeof e!=`object`)return null;let n=e.提示词名称??e.title??e.name,r=e.正文??e.body??e.content??e.markdown,i=typeof n==`string`?n.trim():``,a=typeof r==`string`?r.trim():``;if(!a)return null;let o=e.质检通过??e.qcPass??e.pass,s=typeof o==`boolean`?o:typeof o!=`string`||!/^(false|0|no|否|未通过|fail)/i.test(o.trim()),c=e.质检问题??e.qcIssues??e.issues,l=Array.isArray(c)?c.map(e=>String(e).trim()).filter(Boolean):typeof c==`string`&&c.trim()?[c.trim()]:[],u=e.质检说明??e.qcNote??e.note;return{title:i,body:a,qcPass:s,qcIssues:l,qcNote:typeof u==`string`?u.trim():``}}catch{return null}}function ls(e){return e.replace(/[\\/:*?"<>|]/g,`_`).replace(/\s+/g,``).replace(/\.md$/i,``).slice(0,64)||`未命名提示词`}function us(e,t=``){let n=[...e.qcIssues],r=(e.title||t||`未命名提示词`).trim();e.qcPass||n.push(`模型自检未通过(质检通过=false)`),(!r||r.length<2)&&n.push(`提示词名称过短(至少 2 字)`),r.length>80&&n.push(`提示词名称过长(最多 80 字)`),/[\\/]/.test(r)&&n.push(`提示词名称不可包含路径分隔符`);let i=ls(r),a=`${i}.md`;Ce(a)&&n.push(`不可覆盖受保护提示词「${a}」`),e.body.trim()?e.body.trim().length<80&&n.push(`正文过短(建议不少于 80 字)`):n.push(`正文为空`),!/^#\s+/m.test(e.body)&&!e.body.includes(`
|
|
76
76
|
`)&&n.push(`正文建议使用 Markdown 标题与分段结构`);let o=[...new Set(n.filter(Boolean))];return{ok:o.length===0,issues:o,title:r,fileBase:i}}function ds(e){return`你是资深提示词工程师,擅长为测试与研发场景编写可落地的中文提示词。
|
|
77
77
|
|
|
78
78
|
【任务】
|
|
@@ -108,7 +108,7 @@ ${e.titleHint.trim()||`(可在结果中自拟简洁中文名)`}
|
|
|
108
108
|
- 不要输出 JSON 以外的闲聊;界面只展示执行摘要。`}function fs(e=0){return`正在编写提示词…\n\n已用 ${Math.max(0,Math.floor(e))}s · 通常约 30–90 秒\n完成后将质检并自动入库到提示词管理。`}function ps(e){if(!e.ok){let t=[`**执行失败 / 未入库**`,``,e.error||`质检未通过或解析失败`],n=e.issues??[];if(n.length){t.push(``,`**质检问题**`);for(let e of n)t.push(`- ${e}`)}return t.push(``,`可在对话中补充要求后重新发送,或在插件中修改名称/类型。`),t.join(`
|
|
109
109
|
`)}let t=[`**执行成功**`,``,`- 提示词名称:${e.title||`—`}`];return e.path&&t.push(`- 入库文件:提示词管理/${e.path}`),e.qcNote&&t.push(``,`**质检说明**`,e.qcNote),t.push(``,`下方卡片可点击打开文件。`),t.join(`
|
|
110
110
|
`)}async function ms(e){let t=`${e}.md`;try{let{entries:n}=await be(`prompts`,`.`),r=new Set(n.filter(e=>e.type===`file`).map(e=>e.name));if(!r.has(t))return t;for(let t=2;t<100;t++){let n=`${e}-${t}.md`;if(!r.has(n))return n}}catch{}return`${e}-${Date.now().toString(36)}.md`}async function hs(e,t){let n=cs(e);if(!n){let e=`未能解析出提示词结果,未写入文件`;return{ok:!1,error:e,issues:[],summary:ps({ok:!1,error:e})}}let r=us(n,t.titleHint);if(!r.ok){let e=`入库前质检未通过`;return{ok:!1,error:e,issues:r.issues,summary:ps({ok:!1,error:e,issues:r.issues,qcNote:n.qcNote})}}if(!_(`prompts`)){let e=g(`prompts`);return{ok:!1,error:e,issues:[],summary:ps({ok:!1,error:e})}}try{let e=await ms(r.fileBase);await I(`prompts`,e,n.body.endsWith(`
|
|
111
|
-
`)?n.body:`${n.body}\n`);let t=ps({ok:!0,title:r.title,path:e,qcNote:n.qcNote});return{ok:!0,path:e,title:r.title,qcNote:n.qcNote,summary:t}}catch(e){let t=e instanceof Error?e.message:String(e);return{ok:!1,error:t,issues:[],summary:ps({ok:!1,error:t})}}}function gs(){let e=u().knowledgeCategories;return e?.length?[...e]:[...
|
|
111
|
+
`)?n.body:`${n.body}\n`);let t=ps({ok:!0,title:r.title,path:e,qcNote:n.qcNote});return{ok:!0,path:e,title:r.title,qcNote:n.qcNote,summary:t}}catch(e){let t=e instanceof Error?e.message:String(e);return{ok:!1,error:t,issues:[],summary:ps({ok:!1,error:t})}}}function gs(){let e=u().knowledgeCategories;return e?.length?[...e]:[...a]}function _s(e){let t=s(e);return f({knowledgeCategories:t}),d(),t}function vs(e){let t=e.trim();if(!t)throw Error(`分类名称不能为空`);if(t.length>40)throw Error(`分类名称过长(最多 40 字)`);if(/[\\/]/.test(t))throw Error(`分类名称不可包含路径分隔符`);let n=gs();if(n.includes(t))throw Error(`已存在「${t}」`);return _s([...n,t]),t}function ys(e,t){let n=t.trim();if(!n)throw Error(`分类名称不能为空`);if(n.length>40)throw Error(`分类名称过长(最多 40 字)`);if(/[\\/]/.test(n))throw Error(`分类名称不可包含路径分隔符`);let r=gs(),i=r.indexOf(e);if(i<0)throw Error(`分类不存在`);if(r.some((e,t)=>t!==i&&e===n))throw Error(`已存在「${n}」`);let a=[...r];return a[i]=n,_s(a),n}function bs(e){let t=gs();if(t.length<=1)throw Error(`至少保留一个分类`);if(!t.includes(e))throw Error(`分类不存在`);return _s(t.filter(t=>t!==e))}function xs(e){let t=e.titleHint.trim()||`未命名`;return`${e.category} · ${t}`}function Ss(e){return gs().includes(e)}function Cs(e){let t=e.match(/```(?:json)?\s*([\s\S]*?)```/)?.[1]??e.match(/\{[\s\S]*\}/)?.[0];if(!t)return null;try{let e=JSON.parse(t);if(!e||typeof e!=`object`)return null;let n=e.标题??e.知识库名称??e.title??e.name,r=e.分类??e.category,i=e.描述??e.description,a=e.正文??e.body??e.content??e.markdown,o=typeof n==`string`?n.trim():``,s=typeof r==`string`?r.trim():``,c=typeof i==`string`?i.trim():``,l=typeof a==`string`?a.trim():``;if(!l)return null;let u=e.质检通过??e.qcPass??e.pass,d=typeof u==`boolean`?u:typeof u!=`string`||!/^(false|0|no|否|未通过|fail)/i.test(u.trim()),f=e.质检问题??e.qcIssues??e.issues,p=Array.isArray(f)?f.map(e=>String(e).trim()).filter(Boolean):typeof f==`string`&&f.trim()?[f.trim()]:[],m=e.质检说明??e.qcNote??e.note;return{title:o,category:s,description:c,body:l,qcPass:d,qcIssues:p,qcNote:typeof m==`string`?m.trim():``}}catch{return null}}function ws(e){return e.replace(/[\\/:*?"<>|]/g,`_`).replace(/\s+/g,``).replace(/\.md$/i,``).slice(0,64)||`未命名知识`}function Ts(e){let t=e.trim();return!t||/[:#{}[\],&*?|>!<>=%@`"'\\\n]/.test(t)||/^\s|\s$/.test(e)?JSON.stringify(t):t}function Es(e){return(e.match(/^---\r?\n[\s\S]*?\r?\n---\r?\n?([\s\S]*)$/)?.[1]??e).trim()}function Ds(e){let t=e.description.trim(),n=Es(e.body),r=n.startsWith(`#`)?n:`# ${e.title}\n\n${n}`,i=[`---`,`title: ${Ts(e.title)}`,`category: ${Ts(e.category)}`];return t&&i.push(`description: ${Ts(t)}`),i.push(`---`,``,r,``),i.join(`
|
|
112
112
|
`)}function Os(e,t){let n=[...e.qcIssues],r=(e.title||t.titleHint||`未命名知识`).trim(),i=(e.category||t.category||``).trim();Ss(i)||(i=t.category),e.qcPass||n.push(`模型自检未通过(质检通过=false)`),(!r||r.length<2)&&n.push(`标题过短(至少 2 字)`),r.length>80&&n.push(`标题过长(最多 80 字)`),/[\\/]/.test(r)&&n.push(`标题不可包含路径分隔符`),Ss(i)||n.push(`分类必须是:${gs().join(` / `)}`),e.body.trim()?e.body.trim().length<60&&n.push(`正文过短(建议不少于 60 字)`):n.push(`正文为空`);let a=[...new Set(n.filter(Boolean))];return{ok:a.length===0,issues:a,title:r,category:i,fileBase:ws(r),description:(e.description||``).trim().slice(0,120)}}function ks(e){let t=e.titleHint.trim()||`(可在结果中自拟简洁中文名)`;return`你是资深测试知识库编辑,擅长把规范、方法论、环境约定写成可复用的 Markdown 文档。
|
|
113
113
|
|
|
114
114
|
【任务】
|
|
@@ -202,7 +202,7 @@ ${t}
|
|
|
202
202
|
`)}var Is=`/__tb_fs`,Ls=`你可以使用 Skill 工具(本地 fs 可用时):
|
|
203
203
|
- skill_list:列出工作区 / 项目根下约定目录中的 SKILL.md
|
|
204
204
|
- skill_load:按 id(目录名)或 path 加载技能正文到本轮上下文
|
|
205
|
-
- 需要遵循某技能流程时先 skill_list 再 skill_load,勿臆造技能内容`,Rs=[{type:`function`,function:{name:`skill_list`,description:`List available skills (SKILL.md) under the workspace / project (.cursor/skills, .agents/skills, skills/, or */SKILL.md).`,parameters:{type:`object`,properties:{}}}},{type:`function`,function:{name:`skill_load`,description:`Load a skill by id (directory name) or path to SKILL.md. Returns the skill markdown body (may be truncated).`,parameters:{type:`object`,properties:{name:{type:`string`,description:`Skill id / directory name from skill_list, or relative/absolute path to SKILL.md`},path:{type:`string`,description:`Optional path to SKILL.md (alias of name)`}}}}}];async function zs(e,t){if(e===`skill_list`)try{let e=await fetch(`${Is}/skills`,{signal:AbortSignal.timeout(5e3)}),t=await e.json().catch(()=>({}));return e.ok?JSON.stringify({ok:!0,count:t.count??t.skills?.length??0,skills:t.skills??[]},null,2):JSON.stringify({ok:!1,error:t.error||`HTTP ${e.status}`})}catch(e){return JSON.stringify({ok:!1,error:e instanceof Error?e.message:String(e)})}if(e===`skill_load`){let e={};try{e=JSON.parse(t||`{}`)}catch{return JSON.stringify({ok:!1,error:`invalid JSON arguments`})}let n=String(e.name??e.path??e.id??``).trim();if(!n)return JSON.stringify({ok:!1,error:`name or path is required`});try{let e=await fetch(`${Is}/skill-load`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:n}),signal:AbortSignal.timeout(8e3)}),t=await e.json().catch(()=>({}));if(!e.ok){let n=typeof t==`object`&&t&&`error`in t?String(t.error):`HTTP ${e.status}`;return JSON.stringify({ok:!1,error:n})}return JSON.stringify(t,null,2)}catch(e){return JSON.stringify({ok:!1,error:e instanceof Error?e.message:String(e)})}}return JSON.stringify({error:`unknown tool: ${e}`})}var Bs=`写操作只在用户明确要求时执行;改 / 删之前先用 list 拿到真实 id,不要臆造 id。参数可以用 id,也可以传名称(project / iteration / requirement),系统先精确再忽略大小写匹配。日期一律 YYYY-MM-DD;不确定就不要填,不要凭空猜测。`,Vs=`项目列表工具(空间级,页面在 /pm/projects/):`+Bs+`新建项目只需要 name;归档用 pm_project_update 把 status 改成 archived。删除项目会连带删掉它的迭代、需求与缺陷,执行前先向用户确认影响范围。`,Hs=`迭代管理工具(空间级,页面在 /pm/iterations/):`+Bs+`迭代必须挂在项目下;endDate 不能早于 startDate。进度按日期流逝计算,不要把它当成需求完成度。`,Us=`需求管理工具(空间级,页面在 /pm/requirements/):`+Bs+`需求必须挂在项目下,iterationId 可留空表示未排期;编号 REQ-### 由系统分配,不要自己编。acceptanceCriteria 是 [{ text, done }] 数组,仅在用户给出验收标准时填写。`,Ws=`缺陷管理工具(空间级,页面在 /pm/bugs/):`+Bs+`缺陷必须挂在项目下;iterationId / requirementId 可留空,填了就必须属于同一项目。编号 BUG-### 由系统分配,不要自己编。`,Gs={project:{type:`string`,description:`Project name (exact, then case-insensitive).`},projectId:{type:`string`,description:`Project id from pm_project_list. Prefer this.`},keyword:{type:`string`,description:`Match name / description / title.`},limit:{type:`number`,description:`Max rows, default 50.`}},Ks=[{type:`function`,function:{name:`pm_project_list`,description:`List projects in the current space with iteration / requirement / bug counts. Use before any project write to get ids.`,parameters:{type:`object`,properties:{status:{type:`string`,enum:[...En,`all`]},keyword:{type:`string`},limit:{type:`number`}}}}},{type:`function`,function:{name:`pm_project_add`,description:`Create one or more projects. Only when the user explicitly asks. name is required.`,parameters:{type:`object`,properties:{items:{type:`array`,items:{type:`object`,properties:{name:{type:`string`},description:{type:`string`},status:{type:`string`,enum:En}},required:[`name`]}}},required:[`items`]}}},{type:`function`,function:{name:`pm_project_update`,description:`Update one project by id or name. Only pass fields that change.`,parameters:{type:`object`,properties:{id:{type:`string`},project:{type:`string`,description:`Project name, used when id is omitted.`},name:{type:`string`},description:{type:`string`},status:{type:`string`,enum:En}}}}},{type:`function`,function:{name:`pm_project_delete`,description:`Delete projects by id or name. Also deletes their iterations, requirements and bugs; confirm scope with the user first.`,parameters:{type:`object`,properties:{ids:{type:`array`,items:{type:`string`}},id:{type:`string`},project:{type:`string`}}}}}],qs=[{type:`function`,function:{name:`pm_iteration_list`,description:`List iterations, optionally filtered by project / status. Includes date-based progress and overdue days.`,parameters:{type:`object`,properties:{...Gs,status:{type:`string`,enum:[...vn,`all`]}}}}},{type:`function`,function:{name:`pm_iteration_add`,description:`Create one or more iterations under a project.`,parameters:{type:`object`,properties:{project:{type:`string`,description:`Project name (exact, then case-insensitive).`},projectId:{type:`string`,description:`Project id. Prefer this.`},items:{type:`array`,items:{type:`object`,properties:{name:{type:`string`},startDate:{type:`string`,description:`YYYY-MM-DD.`},endDate:{type:`string`,description:`YYYY-MM-DD, not before startDate.`},status:{type:`string`,enum:vn},remark:{type:`string`}},required:[`name`]}}},required:[`items`]}}},{type:`function`,function:{name:`pm_iteration_update`,description:`Update one iteration by id or name. Use status "done" when the iteration is closed.`,parameters:{type:`object`,properties:{id:{type:`string`},iteration:{type:`string`,description:`Iteration name, used when id is omitted.`},project:{type:`string`},projectId:{type:`string`},name:{type:`string`},startDate:{type:`string`},endDate:{type:`string`},status:{type:`string`,enum:vn},remark:{type:`string`}}}}},{type:`function`,function:{name:`pm_iteration_delete`,description:`Delete iterations by id or name. Requirements and bugs keep existing but lose the iteration link.`,parameters:{type:`object`,properties:{ids:{type:`array`,items:{type:`string`}},id:{type:`string`},iteration:{type:`string`}}}}}],Js=[{type:`function`,function:{name:`pm_requirement_list`,description:`List requirements, optionally filtered by project / iteration / status / priority / keyword.`,parameters:{type:`object`,properties:{...Gs,iteration:{type:`string`},iterationId:{type:`string`},status:{type:`string`,enum:[...bn,`all`]},priority:{type:`string`,enum:[...wn,`all`]}}}}},{type:`function`,function:{name:`pm_requirement_add`,description:`Create one or more requirements under a project. The REQ-### code is assigned by the server.`,parameters:{type:`object`,properties:{project:{type:`string`},projectId:{type:`string`},items:{type:`array`,items:{type:`object`,properties:{title:{type:`string`,description:`需求描述(可多行)`},iterationId:{type:`string`,description:`Optional; must belong to the project.`},iteration:{type:`string`,description:`Iteration name instead of id.`},priority:{type:`string`,enum:wn},status:{type:`string`,enum:bn},description:{type:`string`},acceptanceCriteria:{type:`array`,items:{type:`object`,properties:{text:{type:`string`},done:{type:`boolean`}},required:[`text`]}},githubIssue:{type:`string`}},required:[`title`]}}},required:[`items`]}}},{type:`function`,function:{name:`pm_requirement_update`,description:`Update one requirement by id, REQ code or title. Use status "done" when it is completed.`,parameters:{type:`object`,properties:{id:{type:`string`},requirement:{type:`string`,description:`Requirement title or REQ-###.`},project:{type:`string`},projectId:{type:`string`},iteration:{type:`string`},iterationId:{type:`string`},title:{type:`string`},priority:{type:`string`,enum:wn},status:{type:`string`,enum:bn},description:{type:`string`},acceptanceCriteria:{type:`array`,items:{type:`object`,properties:{text:{type:`string`},done:{type:`boolean`}},required:[`text`]}},githubIssue:{type:`string`}}}}},{type:`function`,function:{name:`pm_requirement_delete`,description:`Delete requirements by id, REQ code or title. Linked bugs lose the link.`,parameters:{type:`object`,properties:{ids:{type:`array`,items:{type:`string`}},id:{type:`string`},requirement:{type:`string`}}}}}],Ys=[{type:`function`,function:{name:`pm_bug_list`,description:`List bugs, optionally filtered by project / iteration / status / severity / keyword.`,parameters:{type:`object`,properties:{...Gs,iteration:{type:`string`},iterationId:{type:`string`},status:{type:`string`,enum:[...Tn,`all`]},severity:{type:`string`,enum:[...Dn,`all`]}}}}},{type:`function`,function:{name:`pm_bug_add`,description:`Create one or more bugs under a project. The BUG-### code is assigned by the server.`,parameters:{type:`object`,properties:{project:{type:`string`},projectId:{type:`string`},items:{type:`array`,items:{type:`object`,properties:{title:{type:`string`},iterationId:{type:`string`},iteration:{type:`string`},requirementId:{type:`string`},requirement:{type:`string`,description:`Requirement title or REQ-###.`},severity:{type:`string`,enum:Dn},status:{type:`string`,enum:Tn},reproduceSteps:{type:`string`},expectedResult:{type:`string`},actualResult:{type:`string`},environment:{type:`string`},githubIssue:{type:`string`},attachment:{type:`string`},remark:{type:`string`}},required:[`title`]}}},required:[`items`]}}},{type:`function`,function:{name:`pm_bug_update`,description:`Update one bug by id, BUG code or title. Use status "closed" when it is verified.`,parameters:{type:`object`,properties:{id:{type:`string`},bug:{type:`string`,description:`Bug title or BUG-###.`},project:{type:`string`},projectId:{type:`string`},iteration:{type:`string`},iterationId:{type:`string`},requirement:{type:`string`},requirementId:{type:`string`},title:{type:`string`},severity:{type:`string`,enum:Dn},status:{type:`string`,enum:Tn},reproduceSteps:{type:`string`},expectedResult:{type:`string`},actualResult:{type:`string`},environment:{type:`string`},githubIssue:{type:`string`},attachment:{type:`string`},remark:{type:`string`}}}}},{type:`function`,function:{name:`pm_bug_delete`,description:`Delete bugs by id, BUG code or title.`,parameters:{type:`object`,properties:{ids:{type:`array`,items:{type:`string`}},id:{type:`string`},bug:{type:`string`}}}}}];function Z(e,t){let n=e[t];return typeof n==`string`?n.trim():``}function Xs(e,t){let n=Z(t,`projectId`);return n?e.projects.some(e=>e.id===n)?n:``:On(e.projects,Z(t,`project`))}function Zs(e,t,n){let r=Z(n,`iterationId`);if(r)return e.iterations.some(e=>e.id===r&&e.projectId===t)?r:``;let i=Z(n,`iteration`);if(!i)return``;let a=e.iterations.find(e=>e.projectId===t&&e.name===i);if(a)return a.id;let o=i.toLowerCase();return e.iterations.find(e=>e.projectId===t&&e.name.toLowerCase()===o)?.id??``}function Qs(e,t,n){let r=Z(n,`requirementId`);if(r)return e.requirements.some(e=>e.id===r&&e.projectId===t)?r:``;let i=Z(n,`requirement`);if(!i)return``;let a=e.requirements.filter(e=>e.projectId===t);return _n(a,i)}function $s(e,t,n,r,i){let a=Z(t,`id`);if(a)return e.some(e=>e.id===a)?{id:a}:{id:``,error:`${r}不存在:${a}`};let o=Z(t,n);if(!o)return{id:``,error:`缺少${r} id 或名称`};let s=o.toLowerCase(),c=e.find(e=>i(e)===o)??e.find(e=>i(e).toLowerCase()===s);return c?{id:c.id}:{id:``,error:`找不到${r}:${o}`}}function ec(e,t){let n={};for(let r of t){if(!(r in e))continue;let t=e[r];t!=null&&(n[r]=t)}return n}function tc(e,t){let n=Z(t,`id`);if(n)return e.requirements.find(e=>e.id===n)??null;let r=Z(t,`requirement`);if(!r)return null;let i=r.toLowerCase();return e.requirements.find(e=>e.autoId.toLowerCase()===i)??e.requirements.find(e=>e.title===r)??e.requirements.find(e=>e.title.toLowerCase()===i)??null}function nc(e,t){let n=Z(t,`id`);if(n)return e.bugs.find(e=>e.id===n)??null;let r=Z(t,`bug`);if(!r)return null;let i=r.toLowerCase();return e.bugs.find(e=>e.autoId.toLowerCase()===i)??e.bugs.find(e=>e.title===r)??e.bugs.find(e=>e.title.toLowerCase()===i)??null}function rc(e,t){let n=t[e.id];return`[${e.id}] ${e.name} | 状态=${e.status} | 迭代=${n?.iterations??0} | 需求=${n?.requirements??0} | 缺陷=${n?.bugs??0}`}function ic(e){let t=hn(e),n=mn(e);return`[${e.id}] ${e.name} | 项目=${e.projectId} | ${e.startDate||`—`} → ${e.endDate||`—`} | 状态=${e.status} | 进度=${t}%`+(n===null?``:` | 逾期${n}天`)}function ac(e){return`[${e.id}] ${e.autoId} ${e.title} | 项目=${e.projectId} | 迭代=${e.iterationId||`—`} | 优先级=${e.priority} | 状态=${e.status}`}function oc(e){return`[${e.id}] ${e.autoId} ${e.title} | 项目=${e.projectId} | 迭代=${e.iterationId||`—`} | 严重程度=${e.severity} | 状态=${e.status}`}function sc(e,t){return e.length?e.map((e,t)=>`${t+1}. ${e}`).join(`
|
|
205
|
+
- 需要遵循某技能流程时先 skill_list 再 skill_load,勿臆造技能内容`,Rs=[{type:`function`,function:{name:`skill_list`,description:`List available skills (SKILL.md) under the workspace / project (.cursor/skills, .agents/skills, skills/, or */SKILL.md).`,parameters:{type:`object`,properties:{}}}},{type:`function`,function:{name:`skill_load`,description:`Load a skill by id (directory name) or path to SKILL.md. Returns the skill markdown body (may be truncated).`,parameters:{type:`object`,properties:{name:{type:`string`,description:`Skill id / directory name from skill_list, or relative/absolute path to SKILL.md`},path:{type:`string`,description:`Optional path to SKILL.md (alias of name)`}}}}}];async function zs(e,t){if(e===`skill_list`)try{let e=await fetch(`${Is}/skills`,{signal:AbortSignal.timeout(5e3)}),t=await e.json().catch(()=>({}));return e.ok?JSON.stringify({ok:!0,count:t.count??t.skills?.length??0,skills:t.skills??[]},null,2):JSON.stringify({ok:!1,error:t.error||`HTTP ${e.status}`})}catch(e){return JSON.stringify({ok:!1,error:e instanceof Error?e.message:String(e)})}if(e===`skill_load`){let e={};try{e=JSON.parse(t||`{}`)}catch{return JSON.stringify({ok:!1,error:`invalid JSON arguments`})}let n=String(e.name??e.path??e.id??``).trim();if(!n)return JSON.stringify({ok:!1,error:`name or path is required`});try{let e=await fetch(`${Is}/skill-load`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:n}),signal:AbortSignal.timeout(8e3)}),t=await e.json().catch(()=>({}));if(!e.ok){let n=typeof t==`object`&&t&&`error`in t?String(t.error):`HTTP ${e.status}`;return JSON.stringify({ok:!1,error:n})}return JSON.stringify(t,null,2)}catch(e){return JSON.stringify({ok:!1,error:e instanceof Error?e.message:String(e)})}}return JSON.stringify({error:`unknown tool: ${e}`})}var Bs=`写操作只在用户明确要求时执行;改 / 删之前先用 list 拿到真实 id,不要臆造 id。参数可以用 id,也可以传名称(project / iteration / requirement),系统先精确再忽略大小写匹配。日期一律 YYYY-MM-DD;不确定就不要填,不要凭空猜测。`,Vs=`项目列表工具(空间级,页面在 /pm/projects/):`+Bs+`新建项目只需要 name;归档用 pm_project_update 把 status 改成 archived。删除项目会连带删掉它的迭代、需求与缺陷,执行前先向用户确认影响范围。`,Hs=`迭代管理工具(空间级,页面在 /pm/iterations/):`+Bs+`迭代必须挂在项目下;endDate 不能早于 startDate。进度按日期流逝计算,不要把它当成需求完成度。`,Us=`需求管理工具(空间级,页面在 /pm/requirements/):`+Bs+`需求必须挂在项目下,iterationId 可留空表示未排期;编号 REQ-### 由系统分配,不要自己编。acceptanceCriteria 是 [{ text, done }] 数组,仅在用户给出验收标准时填写。`,Ws=`缺陷管理工具(空间级,页面在 /pm/bugs/):`+Bs+`缺陷必须挂在项目下;iterationId / requirementId 可留空,填了就必须属于同一项目。编号 BUG-### 由系统分配,不要自己编。`,Gs={project:{type:`string`,description:`Project name (exact, then case-insensitive).`},projectId:{type:`string`,description:`Project id from pm_project_list. Prefer this.`},keyword:{type:`string`,description:`Match name / description / title.`},limit:{type:`number`,description:`Max rows, default 50.`}},Ks=[{type:`function`,function:{name:`pm_project_list`,description:`List projects in the current space with iteration / requirement / bug counts. Use before any project write to get ids.`,parameters:{type:`object`,properties:{status:{type:`string`,enum:[...En,`all`]},keyword:{type:`string`},limit:{type:`number`}}}}},{type:`function`,function:{name:`pm_project_add`,description:`Create one or more projects. Only when the user explicitly asks. name is required.`,parameters:{type:`object`,properties:{items:{type:`array`,items:{type:`object`,properties:{name:{type:`string`},description:{type:`string`},status:{type:`string`,enum:En}},required:[`name`]}}},required:[`items`]}}},{type:`function`,function:{name:`pm_project_update`,description:`Update one project by id or name. Only pass fields that change.`,parameters:{type:`object`,properties:{id:{type:`string`},project:{type:`string`,description:`Project name, used when id is omitted.`},name:{type:`string`},description:{type:`string`},status:{type:`string`,enum:En}}}}},{type:`function`,function:{name:`pm_project_delete`,description:`Delete projects by id or name. Also deletes their iterations, requirements and bugs; confirm scope with the user first.`,parameters:{type:`object`,properties:{ids:{type:`array`,items:{type:`string`}},id:{type:`string`},project:{type:`string`}}}}}],qs=[{type:`function`,function:{name:`pm_iteration_list`,description:`List iterations, optionally filtered by project / status. Includes date-based progress and overdue days.`,parameters:{type:`object`,properties:{...Gs,status:{type:`string`,enum:[...vn,`all`]}}}}},{type:`function`,function:{name:`pm_iteration_add`,description:`Create one or more iterations under a project.`,parameters:{type:`object`,properties:{project:{type:`string`,description:`Project name (exact, then case-insensitive).`},projectId:{type:`string`,description:`Project id. Prefer this.`},items:{type:`array`,items:{type:`object`,properties:{name:{type:`string`},startDate:{type:`string`,description:`YYYY-MM-DD.`},endDate:{type:`string`,description:`YYYY-MM-DD, not before startDate.`},status:{type:`string`,enum:vn},remark:{type:`string`}},required:[`name`]}}},required:[`items`]}}},{type:`function`,function:{name:`pm_iteration_update`,description:`Update one iteration by id or name. Use status "done" when the iteration is closed.`,parameters:{type:`object`,properties:{id:{type:`string`},iteration:{type:`string`,description:`Iteration name, used when id is omitted.`},project:{type:`string`},projectId:{type:`string`},name:{type:`string`},startDate:{type:`string`},endDate:{type:`string`},status:{type:`string`,enum:vn},remark:{type:`string`}}}}},{type:`function`,function:{name:`pm_iteration_delete`,description:`Delete iterations by id or name. Requirements and bugs keep existing but lose the iteration link.`,parameters:{type:`object`,properties:{ids:{type:`array`,items:{type:`string`}},id:{type:`string`},iteration:{type:`string`}}}}}],Js=[{type:`function`,function:{name:`pm_requirement_list`,description:`List requirements, optionally filtered by project / iteration / status / priority / keyword.`,parameters:{type:`object`,properties:{...Gs,iteration:{type:`string`},iterationId:{type:`string`},status:{type:`string`,enum:[...bn,`all`]},priority:{type:`string`,enum:[...wn,`all`]}}}}},{type:`function`,function:{name:`pm_requirement_add`,description:`Create one or more requirements under a project. The REQ-### code is assigned by the server.`,parameters:{type:`object`,properties:{project:{type:`string`},projectId:{type:`string`},items:{type:`array`,items:{type:`object`,properties:{title:{type:`string`,description:`需求描述(可多行)`},iterationId:{type:`string`,description:`Optional; must belong to the project.`},iteration:{type:`string`,description:`Iteration name instead of id.`},priority:{type:`string`,enum:wn},status:{type:`string`,enum:bn},description:{type:`string`},acceptanceCriteria:{type:`array`,items:{type:`object`,properties:{text:{type:`string`},done:{type:`boolean`}},required:[`text`]}},githubIssue:{type:`string`}},required:[`title`]}}},required:[`items`]}}},{type:`function`,function:{name:`pm_requirement_update`,description:`Update one requirement by id, REQ code or title. Use status "done" when it is completed.`,parameters:{type:`object`,properties:{id:{type:`string`},requirement:{type:`string`,description:`Requirement title or REQ-###.`},project:{type:`string`},projectId:{type:`string`},iteration:{type:`string`},iterationId:{type:`string`},title:{type:`string`},priority:{type:`string`,enum:wn},status:{type:`string`,enum:bn},description:{type:`string`},acceptanceCriteria:{type:`array`,items:{type:`object`,properties:{text:{type:`string`},done:{type:`boolean`}},required:[`text`]}},githubIssue:{type:`string`}}}}},{type:`function`,function:{name:`pm_requirement_delete`,description:`Delete requirements by id, REQ code or title. Linked bugs lose the link.`,parameters:{type:`object`,properties:{ids:{type:`array`,items:{type:`string`}},id:{type:`string`},requirement:{type:`string`}}}}}],Ys=[{type:`function`,function:{name:`pm_bug_list`,description:`List bugs, optionally filtered by project / iteration / status / severity / keyword.`,parameters:{type:`object`,properties:{...Gs,iteration:{type:`string`},iterationId:{type:`string`},status:{type:`string`,enum:[...Tn,`all`]},severity:{type:`string`,enum:[...Dn,`all`]}}}}},{type:`function`,function:{name:`pm_bug_add`,description:`Create one or more bugs under a project. The BUG-### code is assigned by the server.`,parameters:{type:`object`,properties:{project:{type:`string`},projectId:{type:`string`},items:{type:`array`,items:{type:`object`,properties:{title:{type:`string`},iterationId:{type:`string`},iteration:{type:`string`},requirementId:{type:`string`},requirement:{type:`string`,description:`Requirement title or REQ-###.`},severity:{type:`string`,enum:Dn},status:{type:`string`,enum:Tn},reproduceSteps:{type:`string`},expectedResult:{type:`string`},actualResult:{type:`string`},environment:{type:`string`},githubIssue:{type:`string`},attachment:{type:`string`},remark:{type:`string`}},required:[`title`]}}},required:[`items`]}}},{type:`function`,function:{name:`pm_bug_update`,description:`Update one bug by id, BUG code or title. Bug status flow: pending → todo → fixed → verifying → passed (or cancelled). Set status "verifying" after a fix is pushed and awaits the user's confirmation; only the user sets "passed".`,parameters:{type:`object`,properties:{id:{type:`string`},bug:{type:`string`,description:`Bug title or BUG-###.`},project:{type:`string`},projectId:{type:`string`},iteration:{type:`string`},iterationId:{type:`string`},requirement:{type:`string`},requirementId:{type:`string`},title:{type:`string`},severity:{type:`string`,enum:Dn},status:{type:`string`,enum:Tn},reproduceSteps:{type:`string`},expectedResult:{type:`string`},actualResult:{type:`string`},environment:{type:`string`},githubIssue:{type:`string`},attachment:{type:`string`},remark:{type:`string`}}}}},{type:`function`,function:{name:`pm_bug_delete`,description:`Delete bugs by id, BUG code or title.`,parameters:{type:`object`,properties:{ids:{type:`array`,items:{type:`string`}},id:{type:`string`},bug:{type:`string`}}}}}];function Z(e,t){let n=e[t];return typeof n==`string`?n.trim():``}function Xs(e,t){let n=Z(t,`projectId`);return n?e.projects.some(e=>e.id===n)?n:``:On(e.projects,Z(t,`project`))}function Zs(e,t,n){let r=Z(n,`iterationId`);if(r)return e.iterations.some(e=>e.id===r&&e.projectId===t)?r:``;let i=Z(n,`iteration`);if(!i)return``;let a=e.iterations.find(e=>e.projectId===t&&e.name===i);if(a)return a.id;let o=i.toLowerCase();return e.iterations.find(e=>e.projectId===t&&e.name.toLowerCase()===o)?.id??``}function Qs(e,t,n){let r=Z(n,`requirementId`);if(r)return e.requirements.some(e=>e.id===r&&e.projectId===t)?r:``;let i=Z(n,`requirement`);if(!i)return``;let a=e.requirements.filter(e=>e.projectId===t);return _n(a,i)}function $s(e,t,n,r,i){let a=Z(t,`id`);if(a)return e.some(e=>e.id===a)?{id:a}:{id:``,error:`${r}不存在:${a}`};let o=Z(t,n);if(!o)return{id:``,error:`缺少${r} id 或名称`};let s=o.toLowerCase(),c=e.find(e=>i(e)===o)??e.find(e=>i(e).toLowerCase()===s);return c?{id:c.id}:{id:``,error:`找不到${r}:${o}`}}function ec(e,t){let n={};for(let r of t){if(!(r in e))continue;let t=e[r];t!=null&&(n[r]=t)}return n}function tc(e,t){let n=Z(t,`id`);if(n)return e.requirements.find(e=>e.id===n)??null;let r=Z(t,`requirement`);if(!r)return null;let i=r.toLowerCase();return e.requirements.find(e=>e.autoId.toLowerCase()===i)??e.requirements.find(e=>e.title===r)??e.requirements.find(e=>e.title.toLowerCase()===i)??null}function nc(e,t){let n=Z(t,`id`);if(n)return e.bugs.find(e=>e.id===n)??null;let r=Z(t,`bug`);if(!r)return null;let i=r.toLowerCase();return e.bugs.find(e=>e.autoId.toLowerCase()===i)??e.bugs.find(e=>e.title===r)??e.bugs.find(e=>e.title.toLowerCase()===i)??null}function rc(e,t){let n=t[e.id];return`[${e.id}] ${e.name} | 状态=${e.status} | 迭代=${n?.iterations??0} | 需求=${n?.requirements??0} | 缺陷=${n?.bugs??0}`}function ic(e){let t=hn(e),n=mn(e);return`[${e.id}] ${e.name} | 项目=${e.projectId} | ${e.startDate||`—`} → ${e.endDate||`—`} | 状态=${e.status} | 进度=${t}%`+(n===null?``:` | 逾期${n}天`)}function ac(e){return`[${e.id}] ${e.autoId} ${e.title} | 项目=${e.projectId} | 迭代=${e.iterationId||`—`} | 优先级=${e.priority} | 状态=${e.status}`}function oc(e){return`[${e.id}] ${e.autoId} ${e.title} | 项目=${e.projectId} | 迭代=${e.iterationId||`—`} | 严重程度=${e.severity} | 状态=${e.status}`}function sc(e,t){return e.length?e.map((e,t)=>`${t+1}. ${e}`).join(`
|
|
206
206
|
`):t}function cc(e,t,n,r){return r.map(r=>{let i=r&&typeof r==`object`?{...r}:{};if(i.projectId=n,t!==`iterations`){let t=Zs(e,n,i);(`iteration`in i||`iterationId`in i)&&(i.iterationId=t)}if(t===`bugs`){let t=Qs(e,n,i);(`requirement`in i||`requirementId`in i)&&(i.requirementId=t)}return delete i.project,delete i.iteration,delete i.requirement,i})}async function lc(e,t,n={}){let r={};try{r=JSON.parse(t||`{}`)}catch{return JSON.stringify({error:`invalid JSON arguments`})}try{let t=await An(),i=Math.max(1,Math.min(200,Number(r.limit)||50));if(e===`pm_project_list`){let e=Z(r,`status`),n=B(t.projects,{status:e||`all`,keyword:Z(r,`keyword`)}).slice(0,i),a=Cn(t);return JSON.stringify({ok:!0,total:t.projects.length,count:n.length,items:n,summary:sc(n.map(e=>rc(e,a)),`当前没有匹配的项目。`)})}if(e===`pm_project_add`){let e=(Array.isArray(r.items)?r.items:[r]).map(e=>e&&typeof e==`object`?e:{}).filter(e=>typeof e.name==`string`);if(!e.length)return JSON.stringify({error:`项目名称不能为空`});let i=await Sn(`projects`,e,{mode:`ai`,sessionId:n.sessionId});return JSON.stringify({ok:!0,count:i.length,items:i,summary:`已创建 ${i.length} 个项目:\n${sc(i.map(e=>rc(e,Cn(t))),``)}`})}if(e===`pm_project_update`){let e=$s(t.projects,r,`project`,`项目`,e=>e.name);if(e.error)return JSON.stringify({error:e.error});let n=ec(r,[`name`,`description`,`status`]);if(!Object.keys(n).length)return JSON.stringify({error:`没有可更新的字段`});let i=await gn(`projects`,e.id,n);return JSON.stringify({ok:!0,item:i,summary:`已更新项目:${i.name}`})}if(e===`pm_project_delete`){let e=Array.isArray(r.ids)?r.ids:[Z(r,`id`)||Z(r,`project`)],n=[];for(let r of e){let e=typeof r==`string`?r.trim():``;if(!e)continue;let i=t.projects.find(t=>t.id===e)??t.projects.find(t=>t.name===e);i&&n.push(i.id)}if(!n.length)return JSON.stringify({error:`缺少项目 id 或名称`});let i=await xn(`projects`,n);return JSON.stringify({ok:!0,...i,summary:`已删除 ${i.removed} 个项目,并连带删除 ${i.cascaded} 条迭代 / 需求 / 缺陷。`})}if(e===`pm_iteration_list`){let e=Xs(t,r),n=Z(r,`status`),a=kn(t.iterations,{projectId:e||`all`,status:n||`all`,keyword:Z(r,`keyword`)}).slice(0,i);return JSON.stringify({ok:!0,total:t.iterations.length,count:a.length,items:a,summary:sc(a.map(ic),`当前没有匹配的迭代。`)})}if(e===`pm_iteration_add`){let e=Xs(t,r);if(!e)return JSON.stringify({error:`请先指定项目(projectId 或 project 名称)`});let i=cc(t,`iterations`,e,Array.isArray(r.items)?r.items:[r]);if(!i.length)return JSON.stringify({error:`迭代名称不能为空`});let a=await Sn(`iterations`,i,{mode:`ai`,sessionId:n.sessionId});return JSON.stringify({ok:!0,count:a.length,items:a,summary:`已创建 ${a.length} 个迭代:\n${sc(a.map(ic),``)}`})}if(e===`pm_iteration_update`){let e=$s(t.iterations,r,`iteration`,`迭代`,e=>e.name);if(e.error)return JSON.stringify({error:e.error});let n=ec(r,[`name`,`startDate`,`endDate`,`status`,`remark`]);if(`projectId`in r||`project`in r){let e=Xs(t,r);if(!e)return JSON.stringify({error:`所属项目不存在`});n.projectId=e}if(!Object.keys(n).length)return JSON.stringify({error:`没有可更新的字段`});let i=await gn(`iterations`,e.id,n);return JSON.stringify({ok:!0,item:i,summary:`已更新迭代:${ic(i)}`})}if(e===`pm_iteration_delete`){let e=Array.isArray(r.ids)?r.ids:[Z(r,`id`)||Z(r,`iteration`)],n=[];for(let r of e){let e=typeof r==`string`?r.trim():``;if(!e)continue;let i=t.iterations.find(t=>t.id===e)??t.iterations.find(t=>t.name===e);i&&n.push(i.id)}if(!n.length)return JSON.stringify({error:`缺少迭代 id 或名称`});let i=await xn(`iterations`,n);return JSON.stringify({ok:!0,...i,summary:`已删除 ${i.removed} 个迭代;关联需求与缺陷已解除迭代关联。`})}if(e===`pm_requirement_list`){let e=Xs(t,r),n=e?Zs(t,e,r):Z(r,`iterationId`)||`all`,a=Z(r,`status`),o=Z(r,`priority`),s=pn(t.requirements,{projectId:e||`all`,iterationId:n||`all`,status:a||`all`,priority:o||`all`,keyword:Z(r,`keyword`)}).slice(0,i);return JSON.stringify({ok:!0,total:t.requirements.length,count:s.length,items:s,summary:sc(s.map(ac),`当前没有匹配的需求。`)})}if(e===`pm_requirement_add`){let e=Xs(t,r);if(!e)return JSON.stringify({error:`请先指定项目(projectId 或 project 名称)`});let i=cc(t,`requirements`,e,Array.isArray(r.items)?r.items:[r]);if(!i.length)return JSON.stringify({error:`需求描述不能为空`});let a=await Sn(`requirements`,i,{mode:`ai`,sessionId:n.sessionId});return JSON.stringify({ok:!0,count:a.length,items:a,summary:`已创建 ${a.length} 条需求:\n${sc(a.map(ac),``)}`})}if(e===`pm_requirement_update`){let e=tc(t,r);if(!e)return JSON.stringify({error:`找不到需求:请传 id、REQ-### 或标题`});let n={id:e.id},i=ec(r,[`title`,`priority`,`status`,`description`,`acceptanceCriteria`,`githubIssue`]),a=`projectId`in r||`project`in r?Xs(t,r):e.projectId;if(!a)return JSON.stringify({error:`所属项目不存在`});if(a!==e.projectId&&(i.projectId=a),(`iterationId`in r||`iteration`in r)&&(i.iterationId=Zs(t,a,r)),!Object.keys(i).length)return JSON.stringify({error:`没有可更新的字段`});let o=await gn(`requirements`,n.id,i);return JSON.stringify({ok:!0,item:o,summary:`已更新需求:${ac(o)}`})}if(e===`pm_requirement_delete`){let e=Array.isArray(r.ids)?r.ids:[Z(r,`id`)||Z(r,`requirement`)],n=[];for(let r of e){let e=typeof r==`string`?r.trim():``;if(!e)continue;let i=_n(t.requirements,e),a=t.requirements.find(t=>t.id===e)??t.requirements.find(t=>t.autoId===e)??t.requirements.find(e=>e.id===i);a&&n.push(a.id)}if(!n.length)return JSON.stringify({error:`缺少需求 id / 编号 / 名称`});let i=await xn(`requirements`,n);return JSON.stringify({ok:!0,...i,summary:`已删除 ${i.removed} 条需求;关联缺陷已解除需求关联。`})}if(e===`pm_bug_list`){let e=Xs(t,r),n=e?Zs(t,e,r):Z(r,`iterationId`)||`all`,a=Z(r,`status`),o=Z(r,`severity`),s=yn(t.bugs,{projectId:e||`all`,iterationId:n||`all`,status:a||`all`,severity:o||`all`,keyword:Z(r,`keyword`)}).slice(0,i);return JSON.stringify({ok:!0,total:t.bugs.length,count:s.length,items:s,summary:sc(s.map(oc),`当前没有匹配的缺陷。`)})}if(e===`pm_bug_add`){let e=Xs(t,r);if(!e)return JSON.stringify({error:`请先指定项目(projectId 或 project 名称)`});let i=cc(t,`bugs`,e,Array.isArray(r.items)?r.items:[r]);if(!i.length)return JSON.stringify({error:`缺陷标题不能为空`});let a=await Sn(`bugs`,i,{mode:`ai`,sessionId:n.sessionId});return JSON.stringify({ok:!0,count:a.length,items:a,summary:`已创建 ${a.length} 条缺陷:\n${sc(a.map(oc),``)}`})}if(e===`pm_bug_update`){let e=nc(t,r);if(!e)return JSON.stringify({error:`找不到缺陷:请传 id、BUG-### 或标题`});let n={id:e.id},i=ec(r,[`title`,`severity`,`status`,`reproduceSteps`,`expectedResult`,`actualResult`,`environment`,`githubIssue`,`attachment`,`remark`]),a=`projectId`in r||`project`in r?Xs(t,r):e.projectId;if(!a)return JSON.stringify({error:`所属项目不存在`});if(a!==e.projectId&&(i.projectId=a),(`iterationId`in r||`iteration`in r)&&(i.iterationId=Zs(t,a,r)),(`requirementId`in r||`requirement`in r)&&(i.requirementId=Qs(t,a,r)),!Object.keys(i).length)return JSON.stringify({error:`没有可更新的字段`});let o=await gn(`bugs`,n.id,i);return JSON.stringify({ok:!0,item:o,summary:`已更新缺陷:${oc(o)}`})}if(e===`pm_bug_delete`){let e=Array.isArray(r.ids)?r.ids:[Z(r,`id`)||Z(r,`bug`)],n=[];for(let r of e){let e=typeof r==`string`?r.trim():``;if(!e)continue;let i=t.bugs.find(t=>t.id===e)??t.bugs.find(t=>t.autoId===e)??t.bugs.find(t=>t.title===e)??t.bugs.find(t=>t.title.toLowerCase()===e.toLowerCase());i&&n.push(i.id)}if(!n.length)return JSON.stringify({error:`缺少缺陷 id / 编号 / 名称`});let i=await xn(`bugs`,n);return JSON.stringify({ok:!0,...i,summary:`已删除 ${i.removed} 条缺陷。`})}return JSON.stringify({error:`unknown pm tool: ${e}`})}catch(e){return JSON.stringify({error:e instanceof Error?e.message:String(e)})}}var uc=`待办事项工具(空间级,跨会话保留,页面在 /todos/):
|
|
207
207
|
- 只有用户明确要求把某件事记成待办时才调用 todo_add:例如「记一下 / 加个待办 / 帮我跟进 / 周五一前完成记得提醒我 / 把这件事加到待办」。
|
|
208
208
|
- 用户只是在聊天里说到一件事、行程或计划,没有要你记录(没有「记 / 待办 / 跟进 / 提醒我」这类意图)时,不要调用 todo_add,也不要弹确认卡片;把内容正常聊完即可。不要从普通对话里自动「提炼」待办。
|
|
@@ -273,4 +273,4 @@ ${t}
|
|
|
273
273
|
|
|
274
274
|
`)}function af(e){let t=rf(e);if(!e.images?.length)return t;let n=[];t?n.push({type:`text`,text:t}):n.push({type:`text`,text:`请查看图片。`});for(let t of e.images)n.push({type:`image_url`,image_url:{url:t.dataUrl}});return n}function of(e){return new Promise((t,n)=>{let r=new FileReader;r.onload=()=>t(String(r.result??``)),r.onerror=()=>n(Error(`读取图片失败`)),r.readAsDataURL(e)})}async function sf(e){if(!ef.includes(e.type)&&!/\.(png|jpe?g|webp|gif)$/i.test(e.name))throw Error(`${e.name||`图片`}:不支持的格式`);if(e.size>10485760)throw Error(`${e.name||`图片`}:超过 ${Math.round(qu/1024/1024)} MB`);let t=await of(e);if(!t.startsWith(`data:image/`))throw Error(`无法识别为图片`);return{id:`img_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,7)}`,name:e.name||`paste-${new Date().toISOString().slice(11,19).replace(/:/g,``)}.png`,size:e.size,mime:e.type||`image/png`,dataUrl:t}}function cf(e,t){return e.length+t.length}var lf=[{value:`low`,label:`Low`,desc:`响应更快,适合简单问答`},{value:`high`,label:`High`,desc:`质量与速度均衡(默认)`},{value:`max`,label:`Max`,desc:`最深推理,适合复杂分析`}],uf=[{value:`readonly`,label:`仅可查看`},{value:`readwrite`,label:`工作区内修改`},{value:`full`,label:`完全权限`}];function df(e){return e===`present`?`交付文件`:e===`todo_write`?`待办`:e.startsWith(`todo_`)?`待办事项`:e===`ask_user_question`?`向用户提问`:e===`bash`?`Bash`:e===`pwsh`?`PowerShell`:e.startsWith(`bash_session_`)||e.startsWith(`pwsh_session_`)?`持久终端`:e.startsWith(`working_directory_`)?`工作目录`:e.startsWith(`skill_`)?`Skill`:e.startsWith(`workspace_changes_`)?`工作区变更`:e===`load_workspace_dependencies`?`工作区依赖`:e===`office_to_pdf`?`Office转PDF`:e===`submit_plan`?`提交计划`:e.startsWith(`goal_`)?`会话目标`:e.startsWith(`schedule_`)?`定时提醒`:e===`list_agents`||e===`spawn_subagent`||e===`fork_subagent`||e.startsWith(`subagent_`)?`子代理`:e===`workflow`?`工作流`:e===`job_list`?`任务列表`:e===`job_output`?`任务输出`:e===`job_kill`?`终止任务`:e===`web_search`?R(`tool.kind.webSearch`):e===`web_fetch`?R(`tool.kind.webFetch`):e.startsWith(`kb_`)?R(`tool.kind.kb`):e.startsWith(`fs_`)?R(`tool.kind.fs`):e.startsWith(`memory_`)?R(`tool.kind.memory`):e}function ff(e){let t=String(e??``).trim();if(!t)return`请求失败`;if(/service_unavailable|too busy|瞬时繁忙|服务繁忙/i.test(t))return`模型服务瞬时繁忙,请稍后重试`;try{let e=JSON.parse(t),n=e?.error??e;if(n&&typeof n==`object`){let e=`${n.message||``} ${n.code||``} ${n.type||``}`;if(/service_unavailable|too busy/i.test(e))return`模型服务瞬时繁忙,请稍后重试`;if(typeof n.message==`string`&&n.message.trim())return n.message.trim()}}catch{}return t.length>280?`${t.slice(0,280)}…`:t}function pf(e){return e===`present`?`fs`:e===`todo_write`||e.startsWith(`todo_`)||e===`ask_user_question`||e===`bash`||e===`pwsh`||e.startsWith(`bash_session_`)||e.startsWith(`pwsh_session_`)||e.startsWith(`working_directory_`)||e.startsWith(`skill_`)||e.startsWith(`workspace_changes_`)||e===`load_workspace_dependencies`||e===`office_to_pdf`||e===`submit_plan`||e.startsWith(`goal_`)||e.startsWith(`schedule_`)||e===`list_agents`||e===`spawn_subagent`||e===`fork_subagent`||e.startsWith(`subagent_`)||e===`workflow`||e.startsWith(`job_`)?`tool`:e===`web_search`?`web_search`:e===`web_fetch`?`web_fetch`:e.startsWith(`fs_`)?`fs`:e.startsWith(`kb_`)?`kb`:e.startsWith(`memory_`)?`memory`:`tool`}function mf({kind:e,status:t}){let n=t===`error`?`w-3.5 h-3.5 shrink-0 text-red-500`:t===`running`?`w-3.5 h-3.5 shrink-0 text-stone-500`:`w-3.5 h-3.5 shrink-0 text-stone-400`;return t===`running`&&e===`thinking`?(0,Q.jsx)(`span`,{className:`w-3.5 h-3.5 shrink-0 rounded-full border-2 border-purple-400 border-t-transparent animate-spin`}):e===`thinking`?(0,Q.jsxs)($,{className:n,children:[(0,Q.jsx)(`circle`,{cx:`12`,cy:`12`,r:`3`}),(0,Q.jsx)(`path`,{d:`M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4`})]}):e===`web_search`||e===`web_fetch`?(0,Q.jsxs)($,{className:n,children:[(0,Q.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`}),(0,Q.jsx)(`path`,{d:`M2 12h20`}),(0,Q.jsx)(`path`,{d:`M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z`})]}):e===`fs`||e===`kb`?(0,Q.jsxs)($,{className:n,children:[(0,Q.jsx)(`path`,{d:`M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z`}),(0,Q.jsx)(`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`})]}):e===`memory`?(0,Q.jsx)($,{className:n,children:(0,Q.jsx)(`path`,{d:`M12 2a4 4 0 0 1 4 4v2h2a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2h2V6a4 4 0 0 1 4-4Z`})}):(0,Q.jsx)($,{className:n,children:(0,Q.jsx)(`path`,{d:`m12 3 1.9 5.8H20l-4.9 3.6 1.9 5.8L12 14.6 7.1 18.2l1.9-5.8L4 8.8h6.1Z`})})}function hf(e,t){if(!t)return``;if(e.startsWith(`web_`))return fn(e,t);if(e===`present`)try{let e=(JSON.parse(t).files??[]).map(e=>e.path).filter(Boolean);return e.slice(0,3).join(`, `)+(e.length>3?`…`:``)}catch{return``}try{let n=JSON.parse(t);if(e===`submit_plan`){let e=typeof n.title==`string`?n.title.trim():``;return e.length>60?`${e.slice(0,60)}…`:e}if(e===`bash`||e===`pwsh`){let e=typeof n.command==`string`?n.command.trim():``,t=n.background===!0?` [bg]`:``;return`${e.length>80?`${e.slice(0,80)}…`:e}${t}`}if(e.startsWith(`bash_session_`)||e.startsWith(`pwsh_session_`)){let e=typeof n.sessionId==`string`?n.sessionId.trim():``,t=typeof n.command==`string`?n.command.trim():``;return[e,t.length>48?`${t.slice(0,48)}…`:t].filter(Boolean).join(` · `)}if(e.startsWith(`working_directory_`)){let e=typeof n.path==`string`?n.path.trim():``;return[typeof n.id==`string`?n.id.trim():``,e].filter(Boolean).join(` · `)}if(e.startsWith(`skill_`))return[typeof n.name==`string`?n.name.trim():``,typeof n.path==`string`?n.path.trim():``].filter(Boolean).join(` · `);if(e.startsWith(`workspace_changes_`))return``;if(e.startsWith(`job_`))return typeof n.jobId==`string`?n.jobId.trim():``;if(e.startsWith(`schedule_`)){let e=typeof n.text==`string`?n.text.trim():``,t=typeof n.id==`string`?n.id.trim():``,r=typeof n.dueAt==`string`?n.dueAt.trim():``,i=typeof n.delayMinutes==`number`&&Number.isFinite(n.delayMinutes)?`+${n.delayMinutes}m`:``;return[e,t,r||i].filter(Boolean).join(` · `)}if(e===`list_agents`||e===`spawn_subagent`||e===`fork_subagent`||e.startsWith(`subagent_`)){let t=typeof n.agent==`string`?n.agent.trim():``,r=typeof n.prompt==`string`?n.prompt.trim():``,i=typeof n.id==`string`?n.id.trim():``,a=r.length>48?`${r.slice(0,48)}…`:r;return[e===`fork_subagent`?`fork`:``,t,i,a].filter(Boolean).join(` · `)}if(e===`workflow`){let e=n.meta;return(typeof e?.name==`string`?e.name.trim():``)||`workflow`}if(e===`fs_glob`||e===`fs_grep`){let e=typeof n.pattern==`string`?n.pattern.trim():``;return[e,typeof n.path==`string`?n.path.trim():``].filter(Boolean).join(` @ `)||e}if(typeof n.path==`string`&&n.path.trim())return n.path.trim();if(typeof n.query==`string`&&n.query.trim())return n.query.trim()}catch{}return``}function gf(e){let t=``,n=0,r=/\r?\n(?:[\t ]*\r?\n)+/g;for(;;){let i=r.exec(e),a=i===null?e.length:i.index+i[0].indexOf(`
|
|
275
275
|
`),o=e.indexOf(`
|
|
276
|
-
`,n);if(o!==-1&&o<=a){let r=e.slice(n,o).trim();r!==``&&(t=r)}if(i===null)return t;n=i.index+i[0].length}}function _f(e,t,n,r){return e===`concise`?r===`running`?R(`tool.running`):null:e===`standard`?R(r===`running`?`tool.callingKind`:`tool.doneKind`,{kind:t}):R(e===`detailed`?r===`running`?`tool.callingNamed`:`tool.doneNamed`:r===`running`?`tool.callingFull`:`tool.doneFull`,{kind:t,name:n})}function $({className:e=``,children:t}){return(0,Q.jsx)(`svg`,{className:e,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:t})}var vf=({className:e=``})=>(0,Q.jsx)($,{className:e,children:(0,Q.jsx)(`path`,{d:`m6 9 6 6 6-6`})}),yf=({className:e=``})=>(0,Q.jsx)($,{className:e,children:(0,Q.jsx)(`path`,{d:`m9 18 6-6-6-6`})}),bf=({className:e=``})=>(0,Q.jsx)($,{className:e,children:(0,Q.jsx)(`path`,{d:`M20 6 9 17l-5-5`})}),xf=({className:e=``})=>(0,Q.jsxs)($,{className:e,children:[(0,Q.jsx)(`rect`,{width:`14`,height:`14`,x:`8`,y:`8`,rx:`2`,ry:`2`}),(0,Q.jsx)(`path`,{d:`M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2`})]}),Sf=({className:e=``})=>(0,Q.jsxs)($,{className:e,children:[(0,Q.jsx)(`ellipse`,{cx:`12`,cy:`5`,rx:`9`,ry:`3`}),(0,Q.jsx)(`path`,{d:`M3 5v14a9 3 0 0 0 18 0V5`}),(0,Q.jsx)(`path`,{d:`M3 12a9 3 0 0 0 18 0`})]}),Cf=({className:e=``})=>(0,Q.jsxs)($,{className:e,children:[(0,Q.jsx)(`path`,{d:`m12 14 4-4`}),(0,Q.jsx)(`path`,{d:`M3.34 19a10 10 0 1 1 17.32 0`})]}),wf=({className:e=``})=>(0,Q.jsxs)($,{className:e,children:[(0,Q.jsx)(`path`,{d:`M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z`}),(0,Q.jsx)(`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`})]}),Tf=({className:e=``})=>(0,Q.jsx)($,{className:e,children:(0,Q.jsx)(`path`,{d:`m16.5 9.4-7.07 7.07a3 3 0 0 1-4.24-4.24l7.07-7.07a2 2 0 1 1 2.83 2.83L8.02 14.1a1 1 0 0 1-1.41-1.41l7.07-7.07`})}),Ef=({className:e=``})=>(0,Q.jsxs)($,{className:e,children:[(0,Q.jsx)(`path`,{d:`m5 12 7-7 7 7`}),(0,Q.jsx)(`path`,{d:`M12 19V5`})]}),Df=({className:e=``,open:t=!1})=>(0,Q.jsx)($,{className:e,children:t?(0,Q.jsx)(Q.Fragment,{children:(0,Q.jsx)(`path`,{d:`m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.55 6A2 2 0 0 1 18.45 20H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.69.9H18a2 2 0 0 1 2 2v2`})}):(0,Q.jsx)(`path`,{d:`M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9l-.81-1.2A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z`})}),Of=({className:e=``,open:t=!1})=>(0,Q.jsx)(`svg`,{className:`${e} tw-arrow ${t?`is-open`:``}`,viewBox:`0 0 12 12`,fill:`currentColor`,"aria-hidden":!0,children:(0,Q.jsx)(`path`,{d:`M4.2 2.4a.75.75 0 0 1 1.2-.57l4.2 3.35a.75.75 0 0 1 0 1.14l-4.2 3.35A.75.75 0 0 1 4.2 9.1V2.9Z`})}),kf=({className:e=``})=>(0,Q.jsxs)($,{className:e,children:[(0,Q.jsx)(`circle`,{cx:`11`,cy:`11`,r:`8`}),(0,Q.jsx)(`path`,{d:`m21 21-4.3-4.3`})]}),Af=({className:e=``})=>(0,Q.jsxs)($,{className:e,children:[(0,Q.jsx)(`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`}),(0,Q.jsx)(`path`,{d:`M12 8v8`}),(0,Q.jsx)(`path`,{d:`M8 12h8`})]}),jf=({className:e=``,filled:t=!1})=>(0,Q.jsx)($,{className:e,children:t?(0,Q.jsx)(`path`,{fill:`currentColor`,stroke:`none`,d:`M12 2a3 3 0 0 1 3 3v3.5l2.5 2.5V13h-3.5V20l-1.5 2-1.5-2v-7H7.5v-2L10 8.5V5a3 3 0 0 1 3-3Z`}):(0,Q.jsx)(`path`,{d:`M12 17v5M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16h14v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V6a2 2 0 0 0-2-2h-2a2 2 0 0 0-2 2z`})}),Mf=({className:e=``})=>(0,Q.jsxs)($,{className:e,children:[(0,Q.jsx)(`circle`,{cx:`12`,cy:`12`,r:`1`,fill:`currentColor`,stroke:`none`}),(0,Q.jsx)(`circle`,{cx:`5`,cy:`12`,r:`1`,fill:`currentColor`,stroke:`none`}),(0,Q.jsx)(`circle`,{cx:`19`,cy:`12`,r:`1`,fill:`currentColor`,stroke:`none`})]}),Nf=({className:e=``})=>(0,Q.jsxs)($,{className:e,children:[(0,Q.jsx)(`path`,{d:`M4 8h16v11a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V8Z`}),(0,Q.jsx)(`path`,{d:`M8 8V5a1 1 0 0 1 1-1h6a1 1 0 0 1 1 1v3`}),(0,Q.jsx)(`path`,{d:`M10 12h4`})]}),Pf=({className:e=``})=>(0,Q.jsxs)($,{className:e,children:[(0,Q.jsx)(`path`,{d:`M12 22v-5`}),(0,Q.jsx)(`path`,{d:`M9 8V2`}),(0,Q.jsx)(`path`,{d:`M15 8V2`}),(0,Q.jsx)(`path`,{d:`M18 8v5a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V8Z`})]});function Ff(e){let t=Math.max(0,Math.floor((Date.now()-e)/1e3));if(t<60)return`刚刚`;let n=Math.floor(t/60);if(n<60)return`${n}分钟`;let r=Math.floor(n/60);if(r<24)return`${r}小时`;let i=Math.floor(r/24);if(i<30)return`${i}天`;let a=Math.floor(i/30);return a<12?`${a}个月`:`${Math.floor(a/12)}年`}function If(e){let t=Ff(e);return t===`刚刚`?`刚刚`:t.endsWith(`前`)?t:`${t}前`}function Lf({open:e,onToggle:t,onRename:n,onDelete:r}){let i=(0,U.useRef)(null);return(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsx)(`button`,{ref:i,type:`button`,"aria-label":`更多`,onClick:e=>{e.stopPropagation(),t()},className:`w-6 h-6 flex items-center justify-center rounded text-(--tw-label-tertiary) hover:text-(--tw-label-primary) hover:bg-(--tw-session-hover-bg)`,children:(0,Q.jsx)(Mf,{className:`w-3.5 h-3.5`})}),(0,Q.jsxs)(Rf,{open:e,anchorRef:i,dataAttr:`data-ws-menu`,children:[(0,Q.jsxs)(`button`,{type:`button`,className:`w-full flex items-center gap-2 px-3 py-1.5 text-left text-[13px] text-stone-700 hover:bg-stone-50`,onClick:e=>{e.stopPropagation(),n()},children:[(0,Q.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Q.jsx)(`path`,{d:`M12 20h9`}),(0,Q.jsx)(`path`,{d:`M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z`})]}),`重命名`]}),r?(0,Q.jsxs)(`button`,{type:`button`,className:`w-full flex items-center gap-2 px-3 py-1.5 text-left text-[13px] text-red-600 hover:bg-red-50`,onClick:e=>{e.stopPropagation(),r()},children:[(0,Q.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Q.jsx)(`path`,{d:`M3 6h18`}),(0,Q.jsx)(`path`,{d:`M8 6V4h8v2`}),(0,Q.jsx)(`path`,{d:`M19 6l-1 14H6L5 6`})]}),`删除工作区`]}):null]})]})}function Rf({open:e,anchorRef:t,dataAttr:n,children:r}){let[i,a]=(0,U.useState)(null);return(0,U.useLayoutEffect)(()=>{if(!e){a(null);return}let n=()=>{let e=t.current;if(!e)return;let n=e.getBoundingClientRect(),r=n.bottom+200>window.innerHeight-8,i=Math.max(8,Math.min(n.left,window.innerWidth-160-8));a({top:r?n.top-4:n.bottom+4,left:i,openUp:r})};return n(),window.addEventListener(`scroll`,n,!0),window.addEventListener(`resize`,n),()=>{window.removeEventListener(`scroll`,n,!0),window.removeEventListener(`resize`,n)}},[e,t]),!e||!i||typeof document>`u`?null:(0,ar.createPortal)((0,Q.jsx)(`div`,{[n]:``,className:`tw-popover tw-popover-anim z-80 w-40 rounded-xl border border-stone-200 py-1 shadow-lg`,style:{position:`fixed`,top:i.top,left:i.left,transform:i.openUp?`translateY(-100%)`:void 0},children:r}),document.body)}function zf({s:e,nested:t=!1,active:n,menuOpen:r,busy:i,onOpen:a,onRename:o,onToggleMenu:s,onTogglePin:c,onToggleArchive:l,onExport:u,onRemove:d,onRestore:f}){let p=(0,U.useRef)(null),m=(0,U.useRef)(null),h=(0,U.useRef)(null),g=(0,U.useRef)(null),_=(0,U.useRef)(null),v=(0,U.useRef)(null),[y,b]=(0,U.useState)(!1),[x,S]=(0,U.useState)(!1),[C,w]=(0,U.useState)(null);function T(){_.current!=null&&(clearTimeout(_.current),_.current=null)}function E(){v.current!=null&&(clearTimeout(v.current),v.current=null)}function D(){E(),v.current=setTimeout(()=>{S(!1),T()},180)}function ee(){E(),T(),_.current=setTimeout(()=>S(!0),1e3)}let te=e.title.trim()||`新对话`;(0,U.useLayoutEffect)(()=>{let e=h.current,t=g.current;if(!e||!t)return;let n=()=>{t.style.maxWidth=`none`,t.style.overflow=`visible`,t.style.display=`inline-block`;let n=t.scrollWidth;t.style.maxWidth=``,t.style.overflow=``,t.style.display=``;let r=e.clientWidth,i=n>r+1;b(i),i?t.style.setProperty(`--tw-marquee-shift`,`${Math.min(0,r-n-28)}px`):t.style.removeProperty(`--tw-marquee-shift`)};n();let r=typeof ResizeObserver<`u`?new ResizeObserver(n):null;return r?.observe(e),()=>r?.disconnect()},[e.title]),(0,U.useLayoutEffect)(()=>{if(!x||r){w(null);return}let e=()=>{let e=p.current;if(!e)return;let t=e.getBoundingClientRect();w({top:t.top+t.height/2,left:t.right+8})};return e(),window.addEventListener(`scroll`,e,!0),window.addEventListener(`resize`,e),()=>{window.removeEventListener(`scroll`,e,!0),window.removeEventListener(`resize`,e)}},[x,r,e.title]),(0,U.useEffect)(()=>{r&&(T(),E(),S(!1))},[r]);let O=i?`生成中`:`空闲`,ne=!!(e.archived||e.deleted);return(0,Q.jsxs)(`div`,{ref:p,className:`tw-session-row relative ${t?`is-nested`:``} ${n?`is-selected`:``} ${r?`is-menu-open`:``} ${i?`is-busy`:``} ${ne?`opacity-50`:``}`,onMouseLeave:()=>{T(),D()},children:[i?(0,Q.jsx)(`span`,{className:`tw-session-busy-slot`,"data-hint":`生成中`,"aria-label":`生成中`,children:(0,Q.jsx)(`span`,{className:`tw-session-busy-dot`,"aria-hidden":!0})}):null,e.pinned&&!ne?(0,Q.jsx)(`span`,{className:`tw-slot`,"aria-hidden":!0,children:(0,Q.jsx)(jf,{filled:!0,className:`tw-pin-indicator w-3 h-3`})}):null,(0,Q.jsx)(`button`,{ref:h,type:`button`,onClick:a,onDoubleClick:o,onMouseEnter:()=>ee(),onMouseLeave:()=>{T(),D()},className:`tw-session-title text-left outline-none focus:outline-none focus-visible:outline-none ${y?`is-overflow`:``}`,children:(0,Q.jsx)(`span`,{ref:g,className:`tw-session-title-inner`,children:e.title})}),(0,Q.jsx)(`span`,{className:`tw-session-time pr-1`,children:Ff(e.updatedAt)}),(0,Q.jsxs)(`div`,{"data-session-menu":``,className:`tw-row-actions items-center gap-0.5 shrink-0`,onClick:e=>e.stopPropagation(),children:[(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsx)(`button`,{ref:m,type:`button`,"aria-label":`更多`,onClick:s,className:`tw-session-action-btn w-6 h-6 flex items-center justify-center rounded`,children:(0,Q.jsx)(Mf,{className:`w-3.5 h-3.5`})}),(0,Q.jsx)(Rf,{open:r,anchorRef:m,dataAttr:`data-session-menu`,children:e.deleted?(0,Q.jsxs)(Q.Fragment,{children:[f?(0,Q.jsx)(`button`,{type:`button`,className:`w-full flex items-center gap-2 px-3 py-1.5 text-left text-[13px] text-stone-700 hover:bg-stone-50`,onClick:f,children:`恢复会话`}):null,(0,Q.jsx)(`button`,{type:`button`,className:`w-full flex items-center gap-2 px-3 py-1.5 text-left text-[13px] text-red-600 hover:bg-red-50`,onClick:d,children:`永久删除`})]}):(0,Q.jsxs)(Q.Fragment,{children:[!e.archived&&(0,Q.jsxs)(`button`,{type:`button`,className:`w-full flex items-center gap-2 px-3 py-1.5 text-left text-[13px] text-stone-700 hover:bg-stone-50`,onClick:c,children:[(0,Q.jsx)(jf,{filled:!!e.pinned,className:`w-3.5 h-3.5`}),e.pinned?`取消置顶`:`置顶会话`]}),(0,Q.jsxs)(`button`,{type:`button`,className:`w-full flex items-center gap-2 px-3 py-1.5 text-left text-[13px] text-stone-700 hover:bg-stone-50`,onClick:o,children:[(0,Q.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Q.jsx)(`path`,{d:`M12 20h9`}),(0,Q.jsx)(`path`,{d:`M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z`})]}),`重命名`]}),(0,Q.jsxs)(`button`,{type:`button`,className:`w-full flex items-center gap-2 px-3 py-1.5 text-left text-[13px] text-stone-700 hover:bg-stone-50`,onClick:l,children:[(0,Q.jsx)(Nf,{className:`w-3.5 h-3.5`}),e.archived?`取消归档`:`归档会话`]}),(0,Q.jsxs)(`button`,{type:`button`,className:`w-full flex items-center gap-2 px-3 py-1.5 text-left text-[13px] text-stone-700 hover:bg-stone-50`,onClick:u,children:[(0,Q.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Q.jsx)(`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`}),(0,Q.jsx)(`polyline`,{points:`7 10 12 15 17 10`}),(0,Q.jsx)(`line`,{x1:`12`,x2:`12`,y1:`15`,y2:`3`})]}),`导出会话`]}),e.archived?(0,Q.jsxs)(`button`,{type:`button`,className:`w-full flex items-center gap-2 px-3 py-1.5 text-left text-[13px] text-red-600 hover:bg-red-50`,onClick:d,children:[(0,Q.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Q.jsx)(`path`,{d:`M3 6h18`}),(0,Q.jsx)(`path`,{d:`M8 6V4h8v2`}),(0,Q.jsx)(`path`,{d:`M19 6l-1 14H6L5 6`})]}),`永久删除`]}):null]})})]}),!e.deleted&&(0,Q.jsx)(`button`,{type:`button`,"aria-label":e.archived?`取消归档`:`归档会话`,"data-hint":e.archived?`取消归档`:`归档会话`,onClick:l,className:`tw-session-action-btn w-6 h-6 flex items-center justify-center rounded`,children:(0,Q.jsx)(Nf,{className:`w-3.5 h-3.5`})}),!e.archived&&!e.deleted&&(0,Q.jsx)(`button`,{type:`button`,"data-hint":e.pinned?`取消置顶`:`置顶`,onClick:c,className:`tw-session-action-btn w-6 h-6 flex items-center justify-center rounded`,children:(0,Q.jsx)(jf,{filled:!!e.pinned,className:`w-3.5 h-3.5`})})]}),x&&!r&&C&&typeof document<`u`?(0,ar.createPortal)((0,Q.jsxs)(`div`,{className:`tw-session-preview`,role:`tooltip`,style:{position:`fixed`,top:C.top,left:C.left,transform:`translateY(-50%)`},onMouseEnter:()=>{T(),E(),S(!0)},onMouseLeave:()=>D(),children:[(0,Q.jsx)(`div`,{className:`tw-session-preview-title`,children:te}),(0,Q.jsx)(`div`,{className:`tw-session-preview-meta`,children:If(e.updatedAt)}),(0,Q.jsx)(`div`,{className:`tw-session-preview-status ${i?`is-busy`:``}`,children:O})]}),document.body):null]})}var Bf=`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`;function Vf({level:e,className:t=``}){return(0,Q.jsxs)($,{className:t,children:[(0,Q.jsx)(`path`,{d:Bf}),e===`readonly`&&(0,Q.jsx)(`path`,{d:`m9 12 2 2 4-4`}),e===`readwrite`&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`path`,{d:`M9 10h6`}),(0,Q.jsx)(`path`,{d:`M9 14h3`})]}),e===`full`&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`path`,{d:`M12 8v4`}),(0,Q.jsx)(`path`,{d:`M12 16h.01`})]})]})}function Hf(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function Uf(e){return`${e.toLocaleString(`en-US`)} tok`}function Wf(e){let t=e/1e3;if(t<60)return`${Math.round(t*10)/10} 秒`;let n=Math.round(t);return`${Math.floor(n/60)} 分 ${n%60} 秒`}function Gf(e){return e>=99.95?`100`:e>=10?String(Math.round(e)):e.toFixed(1)}function Kf(e){let t=0;for(let n of e)t+=/[\u4e00-\u9fff]/.test(n)?1:.25;return Math.max(1,Math.round(t))}function qf(e){return e.uncachedTokens==null?e.cachedTokens==null?e.promptTokens:Math.max(0,e.promptTokens-e.cachedTokens):e.uncachedTokens}function Jf(e){return e?typeof e.completionTokens==`number`&&e.completionTokens>0?e.completionTokens:typeof e.totalTokens==`number`&&typeof e.promptTokens==`number`?Math.max(0,e.totalTokens-e.promptTokens):typeof e.completionTokens==`number`?Math.max(0,e.completionTokens):0:0}function Yf(e,t){return t<=0?null:e/t*100}function Xf(e){return e>=1024?`${(e/1024).toFixed(1)} KB`:`${e} B`}function Zf(e){let t=new Date(e),n=`${String(t.getHours()).padStart(2,`0`)}:${String(t.getMinutes()).padStart(2,`0`)}`;return t.toDateString()===new Date().toDateString()?n:`${t.getMonth()+1}/${t.getDate()} ${n}`}async function Qf(e){try{return await navigator.clipboard.writeText(e),!0}catch{try{let t=document.createElement(`textarea`);t.value=e,t.style.cssText=`position:fixed;opacity:0`,document.body.appendChild(t),t.select();let n=document.execCommand(`copy`);return document.body.removeChild(t),n}catch{return!1}}}function $f({text:e}){let[t,n]=(0,U.useState)(!1),r=(0,U.useRef)(null);(0,U.useEffect)(()=>()=>{r.current!==null&&window.clearTimeout(r.current)},[]);async function i(){t||await Qf(e)&&(n(!0),r.current=window.setTimeout(()=>n(!1),1e3))}return(0,Q.jsx)(`button`,{type:`button`,onClick:i,"aria-label":t?`已复制`:`复制`,className:`tw-icon-btn tw-msg-action-btn inline-flex items-center justify-center rounded-md transition-colors`,children:t?(0,Q.jsx)(bf,{className:`w-3.5 h-3.5 text-emerald-600`}):(0,Q.jsx)(xf,{className:`w-3.5 h-3.5`})})}function ep({pct:e}){return(0,Q.jsxs)(`svg`,{className:`w-3.5 h-3.5 -rotate-90`,viewBox:`0 0 20 20`,"aria-hidden":`true`,children:[(0,Q.jsx)(`circle`,{cx:`10`,cy:`10`,r:`8`,fill:`none`,stroke:`var(--color-stone-200)`,strokeWidth:`3`}),(0,Q.jsx)(`circle`,{cx:`10`,cy:`10`,r:`8`,fill:`none`,stroke:`#4176e6`,strokeWidth:`3`,strokeLinecap:`round`,strokeDasharray:`${Math.max(e,1)/100*50.27} 50.27`})]})}function tp(){let[e,t]=(0,U.useState)(!1),n=(0,U.useRef)(null),r=(0,U.useRef)(null),[i,a]=(0,U.useState)(null);return(0,U.useEffect)(()=>{if(!e){a(null);return}let t=()=>{let e=n.current,t=r.current;if(!e||!t)return;let i=e.getBoundingClientRect(),o=t.getBoundingClientRect(),s=i.left+i.width/2-o.width/2;s=Math.max(12,Math.min(s,window.innerWidth-o.width-12));let c=i.top-o.height-8;c<12&&(c=i.bottom+8),a({position:`fixed`,left:s,top:c,visibility:`visible`})};a({position:`fixed`,left:0,top:0,visibility:`hidden`});let i=requestAnimationFrame(t);return window.addEventListener(`resize`,t),window.addEventListener(`scroll`,t,!0),()=>{cancelAnimationFrame(i),window.removeEventListener(`resize`,t),window.removeEventListener(`scroll`,t,!0)}},[e]),(0,U.useEffect)(()=>{if(!e)return;let i=e=>{e.key===`Escape`&&t(!1)},a=e=>{let i=e.target;n.current?.contains(i)||r.current?.contains(i)||t(!1)};return document.addEventListener(`keydown`,i),document.addEventListener(`click`,a,!0),()=>{document.removeEventListener(`keydown`,i),document.removeEventListener(`click`,a,!0)}},[e]),{open:e,setOpen:t,rootRef:n,panelRef:r,pos:i}}function np({title:e,titleValue:t,icon:n,children:r}){return(0,Q.jsxs)(`div`,{className:`tw-popover w-[min(320px,calc(100vw-24px))] rounded-2xl border border-stone-200 p-3.5 shadow-xl text-left`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-[13px]`,children:[n,(0,Q.jsx)(`span`,{className:`tw-popover-title font-medium text-stone-800`,children:e}),t!==void 0&&(0,Q.jsx)(`span`,{className:`tw-popover-muted ml-auto text-stone-500 tabular-nums`,children:t})]}),(0,Q.jsx)(`div`,{className:`mt-2.5 mb-2.5 border-t border-stone-100`}),r]})}function rp({rows:e}){return(0,Q.jsx)(`dl`,{className:`grid grid-cols-[1fr_auto] gap-x-6 gap-y-2 text-[13px]`,children:e.filter(e=>!e.hide).map(e=>(0,Q.jsxs)(`div`,{className:`contents`,children:[(0,Q.jsx)(`dt`,{className:`text-stone-500`,children:e.label}),(0,Q.jsx)(`dd`,{className:`text-stone-800 tabular-nums text-right`,children:e.value})]},e.label))})}function ip({label:e,icon:t,ariaLabel:n,title:r,titleValue:i,children:a,variant:o=`pill`}){let{open:s,setOpen:c,rootRef:l,panelRef:u,pos:d}=tp();return(0,Q.jsxs)(`span`,{ref:l,className:`relative inline-flex items-center`,children:[(0,Q.jsxs)(`button`,{type:`button`,"aria-haspopup":`dialog`,"aria-expanded":s,"aria-label":n,onClick:()=>c(!s),className:o===`ghost`?`tw-msg-action-meta inline-flex items-center gap-1 tabular-nums transition-colors ${s?`text-stone-600`:`text-stone-400 hover:text-stone-600`}`:`inline-flex items-center gap-1.5 px-2 py-0.5 rounded-full transition-colors ${s?`bg-stone-200/70 text-stone-600`:`hover:bg-stone-200/60 hover:text-stone-600`}`,children:[t,(0,Q.jsx)(`span`,{className:`leading-none`,children:e})]}),s&&(0,ar.createPortal)((0,Q.jsx)(`div`,{ref:u,role:`dialog`,"aria-label":r,style:d??{position:`fixed`,left:0,top:0,visibility:`hidden`},className:`z-80`,children:(0,Q.jsx)(np,{title:r,titleValue:i,icon:t,children:a})}),document.body)]})}function ap({messages:e,busy:t,onRestoreCheckpoint:n}){let[r,i]=(0,U.useState)(()=>new Set),a=(0,U.useMemo)(()=>Mr(e.map(e=>({role:e.role,content:typeof e.content==`string`?e.content:rf(e),time:e.time}))),[e]);function o(e){i(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}return a.length?(0,Q.jsx)(`ol`,{className:`list-none m-0 p-0 w-full max-w-[min(64rem,100%)] mx-auto space-y-2`,children:a.map(e=>{let i=r.has(e.index),a=!!e.assistantText;return(0,Q.jsxs)(`li`,{className:`rounded-xl border bg-white shadow-sm overflow-hidden ${i?`border-[#4176e6]/35`:`border-stone-200`}`,children:[(0,Q.jsxs)(`div`,{className:`flex items-start gap-1 px-3 py-2.5`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>o(e.index),"aria-expanded":i,className:`min-w-0 flex-1 text-left hover:bg-stone-50/80 rounded-lg -mx-1 px-1 py-0.5 transition-colors`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,Q.jsxs)(`span`,{className:`text-[11px] font-medium text-stone-400 tabular-nums`,children:[`第 `,e.index,` 轮`]}),(0,Q.jsx)(vf,{className:`w-3.5 h-3.5 text-stone-400 ml-auto shrink-0 transition-transform ${i?`rotate-180`:``}`})]}),i?null:(0,Q.jsxs)(`div`,{className:`space-y-1 text-[13px] leading-5`,children:[(0,Q.jsxs)(`p`,{className:`m-0 text-stone-800 truncate`,children:[(0,Q.jsx)(`span`,{className:`text-stone-400 mr-1.5`,children:`用户`}),e.userPreview]}),(0,Q.jsxs)(`p`,{className:`m-0 text-stone-600 truncate`,children:[(0,Q.jsx)(`span`,{className:`text-stone-400 mr-1.5`,children:`助手`}),e.assistantPreview||`(待回复)`]})]})]}),n?(0,Q.jsx)(`button`,{type:`button`,disabled:t||!a,"data-hint":a?`截断到本轮末,填入续写并发送`:`待本轮助手回复完成后可从此处继续`,className:`shrink-0 mt-0.5 text-[11px] text-[#4176e6] hover:underline disabled:opacity-40 disabled:no-underline px-1 whitespace-nowrap`,onClick:()=>n(e.endMessageIndex,e.index),children:`从此处继续`}):null]}),i?(0,Q.jsxs)(`div`,{className:`px-3 pb-3 space-y-2.5 text-[13px] leading-5 border-t border-stone-100 pt-2.5`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`div`,{className:`text-[11px] font-medium text-stone-400 mb-0.5`,children:`用户`}),(0,Q.jsx)(`div`,{className:`whitespace-pre-wrap break-words text-stone-800`,children:e.userText||`—`})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`div`,{className:`text-[11px] font-medium text-stone-400 mb-0.5`,children:`助手`}),e.assistantText?(0,Q.jsx)(`div`,{className:`chat-md prose prose-sm prose-stone max-w-none tw-chat-text`,dangerouslySetInnerHTML:{__html:Go(e.assistantText)}}):(0,Q.jsx)(`div`,{className:`text-stone-400`,children:`(待回复)`})]})]}):null]},e.index)})}):(0,Q.jsx)(`div`,{className:`h-full flex items-center justify-center text-sm text-stone-400`,children:`暂无回合(还没有用户/助手对话)`})}function op({messages:e,model:t,systemPromptTokens:n}){let r=e.filter(e=>e.role===`assistant`&&e.usage);if(!r.length)return null;let i=r[r.length-1],a=e.filter(e=>e.role===`user`).length,o=r.length,s=r.reduce((e,t)=>e+(t.usage?.totalTokens??0),0),c=r.reduce((e,t)=>e+(t.usage?.promptTokens??0),0),l=r.reduce((e,t)=>e+(t.usage?.cachedTokens??0),0),u=r.reduce((e,t)=>e+(t.usage?qf(t.usage):0),0),d=r.reduce((e,t)=>e+(t.usage?.cacheWriteTokens??0),0),f=r.reduce((e,t)=>e+Jf(t.usage),0),p=r.some(e=>e.usage?.cachedTokens!=null),m=p?Yf(l,c):null,h=r.reduce((e,t)=>e+(t.llmMs??0),0),g=r.reduce((e,t)=>e+(t.toolMs??0),0),_=r.map(e=>e.ttftMs).filter(e=>e!=null&&e>0),v=_.length?_.reduce((e,t)=>e+t,0)/_.length:0,y=r.reduce((e,t)=>t.llmMs==null||t.ttftMs==null?e:e+Math.max(0,t.llmMs-t.ttftMs),0),b=r.map(e=>e.tps).filter(e=>e!=null&&e>0),x=b.length?b.reduce((e,t)=>e+t,0)/b.length:void 0,S=y>200&&f>0?f/(y/1e3):x??(i.tps&&i.tps>0?i.tps:void 0),C=t?F[t]:void 0,w=i.usage?.promptTokens??0,T=C?Math.min(100,w/C*100):void 0,E=Math.min(n,w),D=Math.max(0,w-E);return(0,Q.jsxs)(`div`,{className:`flex items-center justify-center gap-1 pt-2 text-xs text-stone-400 tabular-nums select-none`,children:[(0,Q.jsx)(ip,{icon:(0,Q.jsx)(Cf,{className:`w-3.5 h-3.5`}),label:(0,Q.jsxs)(Q.Fragment,{children:[a,` 轮 `,o,` 步`,S?` · ${Math.round(S)} tok/s`:``]}),ariaLabel:`会话统计`,title:`会话统计`,children:(0,Q.jsx)(rp,{rows:[{label:`模型用时`,value:h>0?Wf(h):`—`},{label:`工具调用用时`,value:g>0?Wf(g):`—`},{label:`首 token 平均 (TTFT)`,value:_.length?Wf(v):`—`},{label:`输出速度 (TPS)`,value:S?`${Math.round(S)} tok/s`:`—`}]})}),(0,Q.jsx)(ip,{icon:(0,Q.jsx)(Sf,{className:`w-3.5 h-3.5`}),label:(0,Q.jsxs)(Q.Fragment,{children:[Hf(s),` tok`,m==null?``:` · 缓存命中 ${Gf(m)}%`]}),ariaLabel:`Token 用量`,title:`Token 用量`,titleValue:Uf(s),children:(0,Q.jsx)(rp,{rows:[{label:`缓存命中`,value:m==null?`—`:`${Gf(m)}%`,hide:m==null},{label:`未缓存输入`,value:Uf(u)},{label:`缓存读取`,value:Uf(l),hide:!p},{label:`缓存写入`,value:Uf(d),hide:d<=0},{label:`输出`,value:Uf(f)}]})}),T!==void 0&&C&&(0,Q.jsxs)(ip,{icon:(0,Q.jsx)(ep,{pct:T}),label:`${Gf(T)}%`,ariaLabel:`上下文占用`,title:`上下文已用 ${Gf(T)}%`,titleValue:`~${Hf(w)} / ${Hf(C)}`,children:[(0,Q.jsxs)(`div`,{className:`h-2 rounded-full bg-stone-100 overflow-hidden flex mb-3`,children:[(0,Q.jsx)(`span`,{className:`h-full bg-stone-400`,style:{width:`${E/C*100}%`},"data-hint":`系统提示词`}),(0,Q.jsx)(`span`,{className:`h-full bg-[#4176e6]`,style:{width:`${D/C*100}%`},"data-hint":`对话消息`})]}),(0,Q.jsx)(rp,{rows:[{label:`系统提示词`,value:`~${Hf(E)}`},{label:`对话消息`,value:`~${Hf(D)}`}]}),(0,Q.jsx)(`p`,{className:`mt-2.5 text-[11px] leading-4 text-stone-400`,children:`分段为示意估算(API 不返回上下文拆分);总量以最近一轮 prompt_tokens 为准。`})]})]})}function sp({usage:e,model:t}){let n=e.cachedTokens==null?null:Yf(e.cachedTokens,e.promptTokens);return(0,Q.jsx)(ip,{variant:`ghost`,icon:(0,Q.jsx)(Sf,{className:`w-3.5 h-3.5 shrink-0`}),label:(0,Q.jsxs)(Q.Fragment,{children:[`用量 `,Hf(e.totalTokens),` tok`]}),ariaLabel:`本轮用量`,title:`本轮用量`,titleValue:Uf(e.totalTokens),children:(0,Q.jsx)(rp,{rows:[{label:`提供方 / 模型`,value:t??`—`,hide:!t},{label:`缓存命中`,value:n==null?`—`:`${Gf(n)}%`,hide:n==null},{label:`未缓存输入`,value:Uf(qf(e))},{label:`缓存读取`,value:Uf(e.cachedTokens??0),hide:e.cachedTokens==null},{label:`缓存写入`,value:Uf(e.cacheWriteTokens??0),hide:!(e.cacheWriteTokens&&e.cacheWriteTokens>0)},{label:`输出`,value:Uf(e.completionTokens)}]})})}function cp({settings:e}){let[t,n]=(0,U.useState)(!1),[r,i]=(0,U.useState)(null),[a,o]=(0,U.useState)([]),[s,c]=(0,U.useState)(`idle`),l=(0,U.useRef)(null),u=(0,U.useRef)(0);if((0,U.useEffect)(()=>{if(!t)return;let e=()=>{n(!1),i(null)},r=t=>{l.current?.contains(t.target)||e()},a=t=>{t.key===`Escape`&&e()};return document.addEventListener(`mousedown`,r),document.addEventListener(`keydown`,a),()=>{document.removeEventListener(`mousedown`,r),document.removeEventListener(`keydown`,a)}},[t]),(0,U.useEffect)(()=>{if(!t||!e)return;let n=e.availableModels?.length?e.availableModels:[e.model];o(n),c(e.availableModels?.length?`ok`:`loading`);let r=++u.current;P(e.baseURL,e.apiKey).then(t=>{if(r!==u.current)return;let n=t.length?t:[e.model];o(n),c(`ok`),t.length&&Ae({availableModels:t})}).catch(()=>{r===u.current&&c(n.length>1?`ok`:`fail`)})},[t,e]),!e)return(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>Me(`model`),className:`flex items-center gap-1 h-7 shrink-0 pl-2 pr-1 text-[13px] leading-5 font-medium text-stone-500 rounded-md hover:bg-stone-100 transition-colors`,children:[(0,Q.jsx)(`span`,{className:`whitespace-nowrap`,children:`配置模型`}),(0,Q.jsx)(vf,{className:`w-3.5 h-3.5 shrink-0 text-stone-400`})]});let d=e.reasoningEffort??`high`,f=lf.find(e=>e.value===d)?.label??`High`;function p(e){Ae(e),n(!1),i(null)}let m=e=>`w-full flex items-center gap-3 px-3 py-2 rounded-lg text-left text-[13px] transition-colors ${e?`bg-stone-100`:`hover:bg-stone-100`}`;return(0,Q.jsxs)(`div`,{ref:l,className:`relative`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>{n(e=>!e),i(null)},className:`tw-composer-bar-model group flex items-center gap-1 h-7 shrink-0 pl-2 pr-1 text-[13px] leading-5 font-medium rounded-md outline-none focus:outline-none focus-visible:outline-none transition-colors ${t?`bg-stone-100`:`hover:bg-stone-100`}`,title:`${e.model} · ${f}`,"aria-label":`模型 ${e.model},推理 ${f}`,children:[(0,Q.jsx)(`span`,{className:`tw-composer-bar-model-name max-w-40 truncate text-stone-600`,children:e.model}),(0,Q.jsx)(`span`,{className:`tw-composer-bar-effort whitespace-nowrap text-stone-400`,children:f}),(0,Q.jsx)(vf,{className:`w-3.5 h-3.5 shrink-0 text-stone-400 transition-transform ${t?`rotate-180`:``}`})]}),t&&(0,Q.jsxs)(`div`,{className:`tw-popover tw-popover-anim absolute bottom-full right-0 mb-2 w-64 rounded-xl border border-stone-200 p-1 shadow-xl z-50`,children:[(0,Q.jsxs)(`button`,{type:`button`,onMouseEnter:()=>i(`model`),onClick:()=>i(`model`),className:m(r===`model`),children:[(0,Q.jsx)(`span`,{className:`text-stone-700`,children:`模型`}),(0,Q.jsx)(`span`,{className:`ml-auto max-w-32 truncate text-stone-400`,children:e.model}),(0,Q.jsx)(yf,{className:`w-3.5 h-3.5 text-stone-400`})]}),(0,Q.jsxs)(`button`,{type:`button`,onMouseEnter:()=>i(`effort`),onClick:()=>i(`effort`),className:m(r===`effort`),children:[(0,Q.jsx)(`span`,{className:`text-stone-700`,children:`推理等级`}),(0,Q.jsx)(`span`,{className:`ml-auto text-stone-400`,children:f}),(0,Q.jsx)(yf,{className:`w-3.5 h-3.5 text-stone-400`})]}),r===`model`&&(0,Q.jsxs)(`div`,{className:`tw-popover tw-popover-anim absolute right-full bottom-0 mr-1.5 w-64 max-h-72 overflow-y-auto rounded-xl border border-stone-200 p-1 shadow-xl`,children:[s===`loading`&&a.length<=1&&(0,Q.jsx)(`div`,{className:`px-3 py-2 text-xs text-stone-400`,children:`正在识别可用模型…`}),a.map(t=>(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>p({model:t}),className:m(!1),children:[(0,Q.jsx)(`span`,{className:`flex-1 truncate ${t===e.model?`text-stone-900 font-medium`:`text-stone-600`}`,children:t}),t===e.model&&(0,Q.jsx)(bf,{className:`w-3.5 h-3.5 text-[#4176e6]`})]},t)),(0,Q.jsx)(`div`,{className:`mt-1 border-t border-stone-100 pt-1`,children:(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{n(!1),i(null),Me(`model`)},className:`w-full px-3 py-1.5 rounded-lg text-left text-xs text-stone-400 hover:bg-stone-100`,children:s===`fail`?`识别失败,打开设置检查…`:a.length>1?`打开设置 · 模型…`:`打开设置识别可用模型…`})})]}),r===`effort`&&(0,Q.jsx)(`div`,{className:`tw-popover tw-popover-anim absolute right-full bottom-0 mr-1.5 w-60 rounded-xl border border-stone-200 p-1 shadow-xl`,children:lf.map(e=>(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>p({reasoningEffort:e.value}),className:`w-full px-3 py-2 rounded-lg text-left hover:bg-stone-100 transition-colors`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-[13px]`,children:[(0,Q.jsx)(`span`,{className:`flex-1 ${d===e.value?`text-stone-900 font-medium`:`text-stone-600`}`,children:e.label}),d===e.value&&(0,Q.jsx)(bf,{className:`w-3.5 h-3.5 text-[#4176e6]`})]}),(0,Q.jsx)(`div`,{className:`mt-0.5 text-xs text-stone-400`,children:e.desc})]},e.value))})]})]})}var lp=null;function up(){if(!lp){let e=tt();lp={store:e,messages:e.sessions.find(t=>t.id===e.activeId)?.messages??[]}}return lp}function dp({slashDocs:e=[]}){let[t,n]=(0,U.useState)(null),[r,i]=(0,U.useState)(!1),[a,o]=(0,U.useState)(()=>up().store),[s,l]=(0,U.useState)(()=>up().messages),[u,d]=(0,U.useState)(``),[f,p]=(0,U.useState)([]),[_,x]=(0,U.useState)([]),[S,C]=(0,U.useState)([]),[w,T]=(0,U.useState)(Qd),[E,D]=(0,U.useState)(!1),[re,k]=(0,U.useState)(null),A=(0,U.useRef)(null);A.current=re;let[ae,j]=(0,U.useState)(!1),[M,oe]=(0,U.useState)(null),se=(0,U.useRef)(null);se.current=M;let[ce,N]=(0,U.useState)(!1),[le,ue]=(0,U.useState)(null),de=(0,U.useRef)(null);de.current=le;let[fe,P]=(0,U.useState)(null),me=(0,U.useRef)(null);me.current=fe;let F=(0,U.useRef)(null),[I,ge]=(0,U.useState)(null),[_e,be]=(0,U.useState)(0),[Ce,we]=(0,U.useState)(!1),[Te,Ae]=(0,U.useState)(null),[Fe,Ie]=(0,U.useState)(null),[tt,ut]=(0,U.useState)(null),[ft,pt]=(0,U.useState)(null),[mt,ht]=(0,U.useState)(null),[St,wt]=(0,U.useState)(!1),[Tt,At]=(0,U.useState)([]),[Rt,Ut]=(0,U.useState)(null),[nn,an]=(0,U.useState)(`error`);function z(e,t=`error`){an(t),Ut(e)}let[ln,un]=(0,U.useState)(`readonly`),[dn,fn]=(0,U.useState)(!1),[pn,mn]=(0,U.useState)(!0),[hn,gn]=(0,U.useState)(!1),[B,_n]=(0,U.useState)(()=>h()),[vn,yn]=(0,U.useState)(``),[bn,xn]=(0,U.useState)(null),[Sn,Cn]=(0,U.useState)(null),[wn,Tn]=(0,U.useState)(!1),[En,Dn]=(0,U.useState)(null),[On,kn]=(0,U.useState)(null),[An,jn]=(0,U.useState)(null),[V,Mn]=(0,U.useState)(null),[Nn,Pn]=(0,U.useState)(!1),[Fn,In]=(0,U.useState)({}),[Ln,Rn]=(0,U.useState)(``),[Bn,Vn]=(0,U.useState)(!1),[Hn,Un]=(0,U.useState)(null),[Wn,Gn]=(0,U.useState)(()=>b(nf,tf,`dialog`)),[Kn,qn]=(0,U.useState)(()=>typeof window>`u`?{language:`zh-CN`,appearance:`system`,sessionFontSize:14,toolStepDetail:`standard`,busySendBehavior:`queue`,subagentModel:``}:Pe()),[Jn,Yn]=(0,U.useState)(!1),[Xn,H]=(0,U.useState)(null),[Zn,$n]=(0,U.useState)(0),[rr,ar]=(0,U.useState)(!1),[or,fr]=(0,U.useState)(!1),[pr,_r]=(0,U.useState)(!1),[xr,Sr]=(0,U.useState)(!0),[Cr,wr]=(0,U.useState)([]),[Tr,Dr]=(0,U.useState)([]),Ar=!!(B.memory&&bn?.ok),jr=!!B.knowledge,Mr=!!An?.ok,W=!!Sn?.ok,Pr=wn&&!W,Lr=!!En?.ok,Rr=!!(On?.ok&&On.available),Vr=(0,U.useRef)(null),Hr=(0,U.useRef)(new Map),Ur=(0,U.useRef)(null),Gr=(0,U.useRef)(new Map),Kr=(0,U.useRef)(new Map),qr=(0,U.useRef)(new Map),Jr=(0,U.useRef)(null),G=(0,U.useRef)(!1),Yr=(0,U.useRef)(null),Xr=(0,U.useRef)(null),[Zr,Qr]=(0,U.useState)([]),[$r,ei]=(0,U.useState)(null),ti=(0,U.useRef)(null),ni=(0,U.useRef)(0),ri=(0,U.useRef)(new Set),[ii,ai]=(0,U.useState)(`off`),[oi,si]=(0,U.useState)(null),[ci,li]=(0,U.useState)(`day`),[ui,di]=(0,U.useState)(null),[fi,pi]=(0,U.useState)(null),[mi,hi]=(0,U.useState)({}),[gi,_i]=(0,U.useState)(0),[vi,yi]=(0,U.useState)(!1),[bi,xi]=(0,U.useState)(null),[Si,Ci]=(0,U.useState)(!1),[wi,Ti]=(0,U.useState)(``),[Ei,Di]=(0,U.useState)(null),[Oi,ki]=(0,U.useState)(!1),Ai=(0,U.useRef)(null),ji=(0,U.useRef)(null);function Mi(){ji.current!==null&&(window.clearTimeout(ji.current),ji.current=null)}function Ni(){Mi(),ki(!1)}function Pi(e,t,n={}){return new Promise(r=>{Ai.current?.(null),Ai.current=r,Ni(),Di({kind:e,items:t,quick:n.quick,quickNote:n.quickNote})})}function Fi(e){let t=Ai.current;Ai.current=null,ki(!0),Mi(),ji.current=window.setTimeout(()=>{ji.current=null,Di(null),ki(!1)},160),t?.(e)}let Ii=(0,U.useRef)(()=>{});Ii.current=()=>Fi(null),(0,U.useEffect)(()=>{if(!Ei||Oi)return;let e=e=>{let t=e.target;t instanceof Element&&(t.closest(`.tw-create-card`)||t.closest(`[data-headlessui-portal]`)||t.closest(`.tw-select-menu`)||t.closest(`.tw-date-panel`)||Ii.current())};return document.addEventListener(`pointerdown`,e,!0),()=>document.removeEventListener(`pointerdown`,e,!0)},[Ei,Oi]);function Li(e){_r(!1),B[e===`todo`?`todos`:`tasks`]&&(Ni(),Di({kind:e,manual:!0,items:[Rd(e)]}))}async function Ri(e,t){let n=e===`todo`?`待办`:`任务`;try{e===`todo`?await Qn(t.map(e=>({title:e.title.trim(),status:e.status,priority:e.priority,taskId:e.taskId,linkedTask:e.linkedTask,startDate:e.startDate,dueDate:e.dueDate,note:e.note})),{mode:`manual`}):await zn(t.map(e=>({title:e.title.trim(),status:e.status,priority:e.priority,startDate:e.startDate,dueDate:e.dueDate,note:e.note})),{mode:`manual`}),z(`已新增 ${t.length} 条${n},可在侧栏「${n===`待办`?`待办事项`:`任务管理`}」查看。`,`ok`)}catch(e){an(`error`),z(e instanceof Error?e.message:String(e))}}(0,U.useEffect)(()=>()=>{Ai.current?.(null),Ai.current=null,ji.current!==null&&(window.clearTimeout(ji.current),ji.current=null)},[]);let zi=(0,U.useRef)([]),Bi=(0,U.useRef)(null);function Vi(e){zi.current=e,wr(e)}function Hi(e){let t=e.content.trim().replace(/\s+/g,` `);if(t)return t.length>28?`${t.slice(0,28)}…`:t;let n=e.files.length+e.imgs.length+e.refs.length;return n>0?`附件 ${n} 项`:`(空消息)`}let Ui=(0,U.useRef)(null),Wi=(0,U.useRef)(null),Gi=(0,U.useRef)(null),Ki=(0,U.useRef)(null),qi=(0,U.useRef)(null),Ji=(0,U.useRef)(null),Yi=(0,U.useRef)(null),Xi=(0,U.useRef)(null),Zi=(0,U.useRef)({}),Qi=!!(W&&V?.workspace),$i=Xd(u),ea=(()=>{if(!$i||!jr)return[];let t=$i.query.toLowerCase();return(t?e.filter(e=>Vu(e,t)):e).slice(0,10)})(),ta=(()=>{if(!$i||!Qi)return[];let e=$i.query.toLowerCase(),t=Tr.map(e=>({collection:`workspace`,id:`ws:${e.path}`,title:e.name,category:Kt(V?.workspace,V?.projectRoot),description:e.path,format:e.type===`dir`?`dir`:`file`,path:e.path}));return(e?t.filter(t=>Vu(t,e)||t.path.toLowerCase().includes(e)||t.title.toLowerCase().includes(e)):t).slice(0,10)})(),na=[...ea.map(e=>({section:`project`,doc:e})),...ta.map(e=>({section:`workspace`,doc:e}))],ra=!(!$i||rr),ia=Yd(u),aa=v.filter(e=>e.hasPanel&&B[e.id]),oa=!!(ia&&!or&&!ra&&aa.length>0),sa=(0,U.useRef)(!0),ca=(0,U.useRef)(!1),K=(0,U.useRef)(null),la=(0,U.useRef)(null),ua=(0,U.useRef)([]);ua.current=s,la.current=V;function q(e){K.current=e,o(e),at(e)}let da=a?.sessions.find(e=>e.id===a.activeId),J=da?.id,fa=da?.access;(0,U.useEffect)(()=>{J&&un(fa??je())},[J,fa]),(0,U.useEffect)(()=>{let e=!1,t=Oe(()=>n(ke())),r=m(e=>_n(e)),a=De(e=>{qn(e),Ne(e)});return(async()=>{if(await c(),e)return;let t=Pe();qn(t),Ne(t),n(ke()),un(je()),_n(h()),mn(qe());let r=new URLSearchParams(window.location.search),a=r.get(`session`),s=await it({preferSessionId:a});if(e)return;let u=s;if(a&&!u.sessions.some(e=>e.id===a))try{let e=sessionStorage.getItem($e(a));if(e){let t=JSON.parse(e)?.session;t&&t.id===a&&(u={...u,sessions:[t,...u.sessions.filter(e=>e.id!==a)],activeId:a},await Ze(u))}}catch{}if(a)try{sessionStorage.removeItem($e(a))}catch{}let d=r.get(`focusRoot`),f=r.get(`focusPath`),p=r.get(`attachRoot`),m=r.get(`attachPath`),_=r.get(`attachName`),v=null;if(d&&f)try{v=`${d}:${decodeURIComponent(f).replace(/\\/g,`/`).replace(/^\/+/,``)}`}catch{v=`${d}:${f}`}if(a&&u.sessions.some(e=>e.id===a)&&(u=Be(u,a),at(u)),v&&ge(v),p&&m){let e=p;if(e===`cases`||e===`prompts`||e===`knowledge`||e===`templates`){let t=m,n=_||``;try{t=decodeURIComponent(m).replace(/\\/g,`/`).replace(/^\/+/,``),_&&(n=decodeURIComponent(_))}catch{}n||=t.split(`/`).pop()||t;let r=(n.split(`.`).pop()||`md`).toLowerCase(),i=e===`cases`?`用例`:e===`prompts`?`提示词`:e===`knowledge`?`知识库`:`模板`;C([{collection:e,id:`${e}:${t}`,title:n,category:i,path:t,format:r}])}}let y=r.get(`report`);try{let e=new URL(window.location.href);e.searchParams.delete(`report`),e.searchParams.delete(`session`),e.searchParams.delete(`focusRoot`),e.searchParams.delete(`focusPath`),e.searchParams.delete(`attachRoot`),e.searchParams.delete(`attachPath`),e.searchParams.delete(`attachName`),window.history.replaceState({},``,e.pathname+e.search+e.hash)}catch{}let b=[];try{b=(await cr()).map(e=>e.sessionId)}catch{b=[]}let x=new Set(b);u=x.size?{...u,sessions:u.sessions.map(e=>{if(x.has(e.id))return e;let t=ct(e.messages);return t===e.messages?e:{...e,messages:t}})}:We(u);let S=je();u.sessions.some(e=>!e.access)&&(u={...u,sessions:u.sessions.map(e=>e.access?e:{...e,access:S})}),K.current=u,o(u),at(u);let w=u.sessions.find(e=>e.id===u.activeId);if(l(w?.messages??[]),k(w?.caseGen?.active?w.caseGen:null),oe(w?.promptGen?.active?w.promptGen:null),ue(w?.knowledgeGen?.active?w.knowledgeGen:null),P(w?.pluginDev?.active?w.pluginDev:null),un(w?.access??S),w?.pluginDev?.active&&(si(`pluginDev`),w.access!==`readwrite`&&w.access!==`full`)){un(`readwrite`);let e={...u,sessions:u.sessions.map(e=>e.id===u.activeId?{...e,access:`readwrite`}:e)};K.current=e,o(e),at(e)}Qr($c(w?.todos));{let e=bl(w?.goal);ti.current=e,ei(e)}(y===`day`||y===`week`||y===`month`)&&h().reports&&Ua(y),w?.workspacePath&&In(e=>({...e,[w.workspacePath]:!0})),(w?.messages??[]).length||Gn(`dialog`),At(b),i(!0),b.length&&queueMicrotask(()=>{for(let e of b)Aa(e,!0),e===K.current?.activeId&&(G.current=!0,wt(!0),Na(e,0))});try{let e=new URL(window.location.href),t=e.searchParams.get(`plugin`);if(t===`promptGen`||t===`knowledgeGen`||t===`caseGen`||t===`pluginDev`){let n=t;if(h()[n]){if(n===`pluginDev`)Ha();else{let e=K.current?.sessions.find(e=>e.id===K.current?.activeId);if((!e||e.archived||e.deleted||Array.isArray(e.messages)&&e.messages.length>0||e.caseGen?.active||e.promptGen?.active||e.knowledgeGen?.active)&&K.current){let e=K.current.activeId,t=Ca(e)??K.current,n=V?.workspace?.trim()||void 0,r=et(t,{workspacePath:n,access:je()});K.current=r,o(r),at(r),l([]),k(null),oe(null),ue(null),Qr([]),ti.current=null,ei(null),ai(`off`)}n===`promptGen`?j(!0):n===`knowledgeGen`?N(!0):D(!0)}}else z(g(n));e.searchParams.delete(`plugin`),window.history.replaceState({},``,e.pathname+e.search+e.hash)}}catch{}(async()=>{try{if(!await ye(`prompts`))return;let e=(await L(`prompts`,Ee)).content.trim();e&&T(e)}catch{}})(),Ot().then(e=>xn(e)),bt().then(e=>{Cn(e),Tn(!0)}),Yt().then(e=>Dn(e)),cn().then(e=>kn(e)),xt().then(e=>jn(e)),tn().then(e=>{Mn(e),e?.workspace&&In(t=>({...t,[e.workspace]:!0}))})})(),()=>{e=!0,t(),r(),a()}},[]),(0,U.useEffect)(()=>{!B.memory&&Wn===`memory`&&Gn(`dialog`)},[B.memory,Wn]),(0,U.useEffect)(()=>{!B.todos&&Wn===`todos`&&Gn(`dialog`)},[B.todos,Wn]),(0,U.useEffect)(()=>{y(nf,Wn)},[Wn]),(0,U.useEffect)(()=>{if(!B.reports){yn(``);return}let e=!0;return(async()=>{try{await tr(!0);let t=await er();e&&yn(t)}catch{}})(),()=>{e=!1}},[B.reports]),(0,U.useEffect)(()=>{if(!r)return;let e=!1,t=async()=>{if(!K.current)return;let t=await tu();if(e||!K.current)return;let n=K.current,r=!1;for(let e of t){let t=n.sessions.find(t=>t.id===e.sessionId)?.messages??[],i=`<!--tb-schedule:${e.id}-->`;if(!t.some(t=>t.scheduleId===e.id||typeof t.content==`string`&&t.content.includes(i))){let t={role:`assistant`,content:$l(e.text,e.id),time:Date.now(),scheduleId:e.id};n=nt(n,e.sessionId,t),e.sessionId===n.activeId&&(r=!0)}try{typeof Notification<`u`&&Notification.permission===`granted`&&new Notification(`Lantern Harness 定时提醒`,{body:e.text})}catch{}}let i=await Ge();if(!e&&K.current){if(i){let e=Qe(n,i);e!==n&&(n=e,n.activeId&&(r=!0))}if((n!==K.current||t.length)&&q(n),r){let e=n.sessions.find(e=>e.id===n.activeId);l(e?.messages??[])}}};t();let n=window.setInterval(()=>{t()},1e4);return()=>{e=!0,window.clearInterval(n)}},[r]),(0,U.useEffect)(()=>{if(!r||!W||!V)return;let e=a?.sessions.find(e=>e.id===a.activeId);_a(e)},[r,W,a?.activeId,V?.items]),(0,U.useEffect)(()=>{let e=e=>{if(e.key!==`Shift`||e.repeat||e.ctrlKey||e.metaKey||e.altKey)return;let t=document.activeElement;t instanceof HTMLElement&&t!==document.body&&(t.tagName===`TEXTAREA`||t.tagName===`INPUT`||t.tagName===`SELECT`||t.isContentEditable||t.blur())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[]),(0,U.useEffect)(()=>{$n(0),ar(!1)},[$i?.query,$i?.from]),(0,U.useEffect)(()=>{fr(!1),be(0)},[ia?.from]),(0,U.useEffect)(()=>{be(e=>aa.length?Math.min(e,aa.length-1):0)},[aa.length]),(0,U.useEffect)(()=>{if(!ra||!Qi){Qi||Dr([]);return}let e=!1;return Nt(ln,{maxDepth:3,maxEntries:80}).then(t=>{e||Dr(t)}),()=>{e=!0}},[ra,Qi,ln,V?.workspace]),(0,U.useEffect)(()=>{if(!ra)return;let e=Ki.current;e&&e.querySelector(`[data-mention-index="${Zn}"]`)?.scrollIntoView({block:`nearest`})},[Zn,ra,na.length]),(0,U.useEffect)(()=>{if(!oa)return;let e=qi.current;e&&e.querySelector(`[data-plugin-index="${_e}"]`)?.scrollIntoView({block:`nearest`})},[_e,oa,aa.length]),(0,U.useEffect)(()=>{if(!ra&&!oa&&!pr)return;function e(e){let t=e.target;Ki.current?.contains(t)||qi.current?.contains(t)||Ji.current?.contains(t)||Wi.current?.contains(t)||e.target?.closest?.(`[data-add-menu-btn]`)||(ar(!0),fr(!0),_r(!1))}return document.addEventListener(`pointerdown`,e,!0),()=>document.removeEventListener(`pointerdown`,e,!0)},[ra,oa,pr]),(0,U.useEffect)(()=>{if(!Rt||nn!==`ok`)return;function e(e){let t=e.target;Yi.current?.contains(t)||z(null)}let t=window.setTimeout(()=>{document.addEventListener(`pointerdown`,e,!0)},0);return()=>{window.clearTimeout(t),document.removeEventListener(`pointerdown`,e,!0)}},[Rt,nn]),(0,U.useEffect)(()=>{if(!Hn&&!tt)return;function e(e){let t=e.target;t?.closest?.(`[data-session-menu]`)||t?.closest?.(`[data-ws-menu]`)||(Un(null),ut(null))}return document.addEventListener(`pointerdown`,e,!0),()=>document.removeEventListener(`pointerdown`,e,!0)},[Hn,tt]);function pa(){Ot().then(e=>xn(e)),bt().then(e=>{Cn(e),Tn(!0)}),Yt().then(e=>Dn(e)),cn().then(e=>kn(e)),xt().then(e=>jn(e)),tn().then(e=>Mn(e))}function ma(e){Mn(e),In(t=>({...t,[e.workspace]:!0}))}async function ha(e,t=`select`){if(W&&!Nn){Pn(!0),z(null);try{ma(t===`add`?await jt(e):await rn(e))}catch(e){z(e instanceof Error?e.message:String(e))}finally{Pn(!1)}}}function ga(e){let t=la.current;if(!t)return null;let n=e?.workspacePath?.trim();return n&&(n===t.harnessRoot||t.items.some(e=>e.path===n))?n:t.projectRoot?.trim()||null}async function _a(e){if(!W||Nn)return;let t=ga(e);if(!t)return;let n=la.current;if(n&&t!==n.workspace){Pn(!0);try{ma(await rn(t))}catch{}finally{Pn(!1)}}}async function va(e){if(!W||Nn)return;await ha(e.path,`select`);let t=K.current;if(!t)return;let n=t.sessions.find(e=>e.id===t.activeId);n&&!n.workspacePath&&((n.messages??[]).length>0||(q(Ue(t,n.id,e.path)),In(t=>({...t,[e.path]:!0}))))}async function ya(){if(W&&!Nn){Pn(!0),z(null);try{let e=await Pt();if(!e)return;ma(await jt(e))}catch(e){z(e instanceof Error?e.message:String(e))}finally{Pn(!1)}}}async function ba(){let e=ft;if(e&&W&&!Nn){if(e.id===`ws_project`)pt(null);else{pt(null),ut(null),Pn(!0),z(null);try{K.current&&q(ot(K.current,e.path));let t=await Et(e.id);ma(t),t.projectRoot&&In(e=>({...e,[t.projectRoot]:!0}))}catch(e){z(e instanceof Error?e.message:String(e))}finally{Pn(!1)}}}}function xa(e){W&&!Nn&&e.id!==`ws_project`&&(Un(null),ut(null),pt(e))}async function Sa(e){let t=mt;if(ht(null),t&&W){Pn(!0),z(null);try{ma(await lt(t,e))}catch(e){z(e instanceof Error?e.message:String(e))}finally{Pn(!1)}}}function Ca(e){if(!e||!K.current)return K.current;let t=K.current.sessions.find(t=>t.id===e);if(!t||!Ke(t))return K.current;let n=Zi.current[e];return n&&(n.input?.trim()||(n.attachments?.length??0)>0||(n.images?.length??0)>0||(n.docRefs?.length??0)>0)?K.current:(delete Zi.current[e],rt(K.current,e))}function wa(e){$i&&(e.collection!==`workspace`&&!jr?z(g(`knowledge`)):S.length>=$d?z(`最多引用 ${$d} 篇文档`):(z(null),C(t=>t.some(t=>t.collection===e.collection&&t.path===e.path)?t:[...t,{collection:e.collection,id:e.id,title:e.title,category:e.category,path:e.path,format:e.format}].slice(0,$d)),d(u.slice(0,$i.from).replace(/\s+$/,``)),ar(!0),Wi.current?.focus()))}function Ta(){ia&&(d(u.slice(0,ia.from).replace(/\s+$/,``)),fr(!0))}function Ea(e){if(!B[e])return z(g(e)),!1;if(z(null),e===`caseGen`)return D(!0),!0;if(e===`promptGen`)return j(!0),!0;if(e===`knowledgeGen`)return N(!0),!0;if(e===`pluginDev`)return Ha(),!0;if(e===`memory`)return Gn(`memory`),!0;if(e===`knowledge`){let e=u.replace(/\s+$/,``);return d(e?`${e} @`:`@`),ar(!1),requestAnimationFrame(()=>Wi.current?.focus()),!0}return!1}function Da(e){Ta(),Ea(e)}function Oa(){let e=Ui.current;if(!e)return;let t=e.scrollHeight-e.clientHeight-e.scrollTop<=48;if(ca.current){if(!t)return;ca.current=!1}sa.current=t,fn(!t)}function ka(){let e=Ui.current;e&&(sa.current=!0,ca.current=!0,fn(!1),e.scrollTo({top:e.scrollHeight,behavior:`smooth`}))}(0,U.useEffect)(()=>{if(!r||!K.current)return;let e=K.current.sessions.find(e=>e.id===K.current.activeId)?.messages??[],t=JSON.stringify(e)!==JSON.stringify(s),n=Ve(K.current,s,{touchUpdatedAt:t});K.current=n,o(n),at(n),sa.current&&!ca.current&&Ui.current?.scrollTo({top:Ui.current.scrollHeight})},[s,r]),(0,U.useEffect)(()=>{let e=()=>{K.current&&at(K.current)};return window.addEventListener(`pagehide`,e),()=>window.removeEventListener(`pagehide`,e)},[]),(0,U.useLayoutEffect)(()=>{let e=Wi.current;e&&(e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,280)}px`)},[u]),(0,U.useEffect)(()=>{if(!r||!I||!s.length)return;let e=I,t=window.setTimeout(()=>{let t=(Ui.current??document).querySelector(`[data-focus-doc="${CSS.escape(e)}"]`);t instanceof HTMLElement&&(t.scrollIntoView({behavior:`smooth`,block:`center`}),t.classList.add(`ring-2`,`ring-[#4176e6]`,`ring-offset-2`),window.setTimeout(()=>{t.classList.remove(`ring-2`,`ring-[#4176e6]`,`ring-offset-2`)},2400)),ge(null)},80);return()=>window.clearTimeout(t)},[r,I,s]);function Aa(e,t){At(n=>{let r=n.includes(e);return t&&!r?[...n,e]:!t&&r?n.filter(t=>t!==e):n}),K.current?.activeId===e&&(G.current=t,wt(t))}function ja(e){e&&(Hr.current.get(e)?.abort.abort(),Gr.current.get(e)?.(),Gr.current.delete(e),ur(e))}function Ma(e,t){if(t.type===`reasoning`&&t.delta)Pa(e,n=>{let r=n[n.length-1];if(r?.role!==`assistant`)return n;let i=pe((r.reasoning??``)+t.delta),a=[...r.activitySteps??[]],o=a.findIndex(e=>e.kind===`thinking`),s={id:`thinking`,kind:`thinking`,title:`思考`,detail:gf(i).replaceAll(`**`,``).slice(0,80)||void 0,status:`running`};o>=0?a[o]={...a[o],...s}:a.unshift(s);let c=n.slice(),l=qr.current.get(e),u=r.ttftMs;return l&&l.firstToken==null&&(l.firstToken=Date.now(),u=Math.max(0,l.firstToken-l.start)),c[c.length-1]={...r,reasoning:i,activitySteps:a,turnStatus:`running`,ttftMs:u},c});else if(t.type===`content`&&t.delta)Pa(e,n=>{let r=n[n.length-1];if(r?.role!==`assistant`)return n;let i=(r.activitySteps??[]).map(e=>e.kind===`thinking`&&e.status===`running`?{...e,status:`done`}:e),a=n.slice(),o=qr.current.get(e),s=r.ttftMs;return o&&o.firstToken==null&&(o.firstToken=Date.now(),s=Math.max(0,o.firstToken-o.start)),a[a.length-1]={...r,content:pe((r.content??``)+t.delta),activitySteps:i,turnStatus:`running`,ttftMs:s},a});else if(t.type===`tool`&&t.name){let n=df(t.name),r=hf(t.name,t.args),i=`tool_${t.name}_${t.args?.slice(0,24)??``}`;Ia(e,i,t.status);let a=t.status===`done`&&typeof t.result==`string`&&/^\s*\{\s*"error"\s*:/.test(t.result);Pa(e,e=>{let o=e[e.length-1];if(o?.role!==`assistant`)return e;let s=[...o.activitySteps??[]],c=s.findIndex(e=>e.id===i||e.detail===r&&e.title===n&&e.status===`running`),l={id:i,kind:pf(t.name),title:n,detail:r||void 0,status:t.status===`running`?`running`:a?`error`:`done`};c>=0?s[c]={...s[c],...l}:s.push(l);let u=e.slice();return u[u.length-1]={...o,activitySteps:s,turnStatus:`running`},u}),K.current?.activeId===e&&H(_f(Pe().toolStepDetail,n,t.name,t.status===`running`?`running`:`done`))}else if(t.type===`usage`&&t.usage)Pa(e,e=>{let n=e[e.length-1];if(n?.role!==`assistant`)return e;let r=e.slice();return r[r.length-1]={...n,usage:t.usage},r});else if(t.type===`status`){let n=t.status;(n===`completed`||n===`stopped`||n===`error`)&&(Pa(e,e=>{let r=e[e.length-1];if(r?.role!==`assistant`)return e;let i=t.assistant,a=e.slice(),o=typeof i?.toolMs==`number`?i.toolMs:void 0,s=typeof i?.llmMs==`number`?i.llmMs:void 0,c=typeof i?.ttftMs==`number`?i.ttftMs:void 0,l=typeof i?.tps==`number`?i.tps:void 0;return a[a.length-1]={...r,content:typeof i?.content==`string`?i.content:r.content,reasoning:typeof i?.reasoning==`string`?i.reasoning:r.reasoning,reasoningApi:typeof i?.reasoningApi==`string`?i.reasoningApi:r.reasoningApi,activitySteps:(i?.activitySteps??r.activitySteps??[]).map(e=>e.status===`running`?{...e,status:`done`}:e),turnStatus:n===`completed`?`completed`:`stopped`,time:Date.now(),usage:i?.usage??r.usage,model:typeof i?.model==`string`?i.model:r.model,toolMs:o==null?r.toolMs:Math.max(o,r.toolMs??0),llmMs:s??r.llmMs,ttftMs:c??r.ttftMs,tps:l??r.tps},a}),n===`error`&&t.error&&K.current?.activeId===e&&z(ff(t.error)),Hr.current.delete(e),Ur.current===e&&(Ur.current=null),Aa(e,!1),K.current?.activeId===e&&H(null))}}function Na(e,t=0){Gr.current.get(e)?.(),Aa(e,!0),(async()=>{let n=await dr(e),r=t;if(n?.ok&&n.assistant&&(r=Math.max(r,n.seq??0),Pa(e,e=>{let t=e[e.length-1],r=t?.role===`assistant`?t:{role:`assistant`,content:``,turnStatus:`running`},i=n.assistant,a={...r,content:typeof i?.content==`string`?i.content:r.content,reasoning:typeof i?.reasoning==`string`?i.reasoning:r.reasoning,reasoningApi:typeof i?.reasoningApi==`string`?i.reasoningApi:r.reasoningApi,activitySteps:i?.activitySteps??r.activitySteps,turnStatus:n.status===`completed`?`completed`:n.status===`stopped`||n.status===`error`?`stopped`:`running`,usage:i?.usage??r.usage,model:typeof i?.model==`string`?i.model:r.model,llmMs:typeof i?.llmMs==`number`?i.llmMs:r.llmMs,ttftMs:typeof i?.ttftMs==`number`?i.ttftMs:r.ttftMs,toolMs:typeof i?.toolMs==`number`?Math.max(i.toolMs,r.toolMs??0):r.toolMs,tps:typeof i?.tps==`number`?i.tps:r.tps};if(t?.role===`assistant`){let t=e.slice();return t[t.length-1]=a,t}return[...e,a]}),n.status&&n.status!==`running`&&n.status!==`waiting_user`)){Aa(e,!1);return}let i=mr(e,r,{onEvent:t=>Ma(e,t),onGaveUp:t=>{K.current?.activeId===e&&z(t.message||`与服务端回合断开`),Aa(e,!1)}});Gr.current.set(e,i)})()}function Pa(e,t,n){let r=Hr.current.get(e),i=K.current?.sessions.find(t=>t.id===e)?.messages??[],a=r?.messages??(K.current?.activeId===e?ua.current:i),o=typeof t==`function`?t(a):t;r&&(r.messages=o),K.current?.activeId===e&&(ua.current=o,l(o)),K.current&&q(Le(K.current,e,o,{touchUpdatedAt:n?.touchUpdatedAt!==!1}))}function Fa(e){let t=Ur.current??K.current?.activeId;t&&Pa(t,t=>{let n=t[t.length-1];if(n?.role!==`assistant`)return t;let r=t.slice();return r[r.length-1]=e(n),r})}function Ia(e,t,n){let r=`${e}:${t}`;if(n===`running`){Kr.current.set(r,Date.now());return}if(n!==`done`&&n!==`error`)return;let i=Kr.current.get(r);if(Kr.current.delete(r),i==null)return;let a=Math.max(0,Date.now()-i);Pa(e,e=>{let t=e[e.length-1];if(t?.role!==`assistant`)return e;let n=e.slice();return n[n.length-1]={...t,toolMs:(t.toolMs??0)+a},n})}async function La(e){if(!e.length)return;let t=[],n=[],r=cf(f,_);for(let i of e)if(r+t.length>=6)n.push(`${i.name||`图片`}(最多 6 个文件)`);else try{t.push(await sf(i))}catch(e){n.push(e instanceof Error?e.message:String(e))}t.length&&x(e=>[...e,...t].slice(0,6)),z(n.length?`以下图片未添加:${n.join(`、`)}`:null)}function Ra(){d(``),p([]),x([]),C([]),ar(!1),fr(!1)}function za(){if(oi===`plan`&&(co(),ai(`off`)),oi===`pluginDev`){P(null),me.current=null,K.current&&q(Re(K.current,{pluginDev:void 0}));let e=F.current;F.current=null,e===`readonly`&&(un(`readonly`),K.current&&q(Re(K.current,{access:`readonly`})))}si(null)}function Ba(){si(`goal`),requestAnimationFrame(()=>Wi.current?.focus())}function Va(){ai(e=>e===`off`?`planning`:e),si(`plan`),requestAnimationFrame(()=>Wi.current?.focus())}function Ha(){W?(si(`pluginDev`),ln===`readonly`&&(F.current=`readonly`,un(`readwrite`),K.current&&q(Re(K.current,{access:`readwrite`}))),requestAnimationFrame(()=>Wi.current?.focus())):z(`本地文件服务未就绪:插件开发需要读写项目源码`)}function Ua(e){li(e),si(`reports`),window.setTimeout(()=>Wi.current?.focus(),400)}function Wa(e){return e.filter(e=>e.role===`user`||e.role===`assistant`).map(e=>({role:e.role,content:typeof e.content==`string`?e.content:``,reasoning:e.reasoning}))}async function Ga(e){if(!t)return Me(`model`),!1;let n=Wa(ua.current);if(n.length<4)return z(`对话轮次较少,无需压缩`),!1;H(`正在压缩上下文…`);try{let{messages:r,compacted:i}=await gl(t,n,{force:e.force,signal:e.signal});if(!i)return H(null),z(`当前上下文未超过阈值,未压缩`),!1;let a=Date.now(),o=r.map((e,t)=>({role:e.role,content:e.content,reasoning:e.reasoning,time:a+t}));return ua.current=o,l(o),K.current&&q(Ve(K.current,o,{touchUpdatedAt:!0})),H(null),!0}catch(e){return H(null),e instanceof DOMException&&e.name===`AbortError`||z(e instanceof Error?e.message:String(e)),!1}}async function Ka(e,n){let r=e===void 0,i=r&&oi===`reports`?`生成${nr[ci]}`:``,a=(e??u).trim()||i,o=r?f:[],s=r?S:[],c=r?_:[];if(!a&&!o.length&&!s.length&&!c.length)return;if(!t){Me(`model`);return}if(r&&oi===`reports`&&si(null),_l(a)&&!o.length&&!s.length&&!c.length){if(G.current){z(`请等待当前回复结束后再压缩`);return}r&&Ra(),await Ga({force:!0})&&z(null);return}if(oi===`goal`&&a&&!o.length&&!s.length&&!c.length&&!wl(a)&&!_l(a)){r&&Ra();let e={text:a.slice(0,500),status:`active`,updatedAt:Date.now()};ti.current=e,ei(e),ni.current=0,K.current&&q(Re(K.current,{goal:e})),si(null),z(`已设定目标:${e.text}`);return}if(wl(a)&&!o.length&&!s.length&&!c.length){let e=Cl(a);if(r&&Ra(),!e)return;if(e.kind===`show`){let e=$r;z(e&&e.status!==`cleared`?`当前目标(${e.status}):${e.text}`:`当前无会话目标。可用 /goal set <内容> 设定`);return}if(e.kind===`clear`){ti.current=null,ei(null),ni.current=0,K.current&&q(Re(K.current,{goal:void 0})),z(`已清除会话目标`);return}if(e.kind===`done`){if(!$r?.text){z(`当前无目标可标记完成`);return}let e={...$r,status:`done`,updatedAt:Date.now()};ti.current=e,ei(e),ni.current=0,K.current&&q(Re(K.current,{goal:e})),z(`已标记目标完成:${e.text}`);return}if(e.kind===`set`&&e.text){let t={text:e.text.slice(0,500),status:`active`,updatedAt:Date.now()};ti.current=t,ei(t),ni.current=0,K.current&&q(Re(K.current,{goal:t})),z(`已设定目标:${t.text}`);return}return}if(oi===`pluginDev`&&a&&!o.length&&!s.length&&!c.length){if(G.current){z(`请等待当前回复结束后再开始插件开发`);return}await no(a)}let l={id:`q_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,6)}`,content:a,files:[...o],refs:[...s],imgs:[...c]};if(G.current){let e=Pe().busySendBehavior??`queue`;if((n?.forceBusy??e)===`queue`){Vi([...zi.current,l]),r&&Ra();return}Bi.current=l,r&&Ra(),ja(K.current?.activeId)}else await qa(l)}async function qa(n){let r=K.current?.activeId;if(!t||!r||Hr.current.has(r))return;let{content:i,files:a,refs:o,imgs:s}=n;Dl(i)||(ni.current=0),z(null);let c=Date.now(),u={role:`user`,content:i,time:c};a.length&&(u.attachments=a),o.length&&(u.refs=o),s.length&&(u.images=s);let d=ua.current,f=d[d.length-1];f?.role===`assistant`&&!f.content&&!f.reasoning&&(d=d.slice(0,-1));let p=[...d,u];if(pl(Wa(p),t.model)){H(`上下文较长,正在压缩…`);try{let{messages:e,compacted:n}=await gl(t,Wa(p),{force:!1,signal:void 0});if(n){let t=Date.now();p=e.map((e,n)=>({role:e.role,content:e.content,reasoning:e.reasoning,time:t+n})),ua.current=p,l(p),K.current&&q(Ve(K.current,p,{touchUpdatedAt:!0}))}}catch{}H(null)}let m=[...p,{role:`assistant`,content:``,time:c,turnStatus:`running`}];ua.current=m,l(m),Ra();let h=new AbortController;Ur.current=r,Hr.current.set(r,{abort:h,messages:m}),Vr.current=h,Aa(r,!0),sa.current=!0,fn(!1);let g=Wr(p.map(e=>{let t={role:e.role,content:af(e)},n=(e.reasoningApi??e.reasoning)?.trim();return e.role===`assistant`&&n&&(t.reasoning_content=n),t}),{keepRecentImageMessages:1}),_=Ar,v=jr,y=W,b=Mr,x=!!B.todos,S=!!B.tasks,C=!!B.projects,T=!!B.iterations,E=!!B.pmRequirements,D=!!B.bugs,ee=ii===`planning`,te=B.pluginDev&&me.current?.active?me.current:null,O=te?ln===`full`?`full`:`readwrite`:ee?`readonly`:ln,ne=Lr&&O!==`readonly`,re=Rr&&O!==`readonly`,ie=la.current?.workspace?.trim()||``,ae=ie?`\n当前工作区:${ie}`:``,j=B.promptGen&&se.current?.active?se.current:null,M=!j&&B.knowledgeGen&&de.current?.active?de.current:null,ce=!j&&!M&&B.caseGen&&A.current?.active?A.current:null,N=!!(j||M||ce),le=ie,fe=w;if(te)fe=Fs(te,la.current?.harnessRoot||la.current?.projectRoot||ie);else if(j)fe=ds(j);else if(M)fe=ks(M);else if(ce){if(!ce.promptBody?.trim()){z(`生成测试用例已启用,但未选择提示词。请打开插件重新「确认」。`),Hr.current.delete(r),Ur.current=null,Vr.current=null,Aa(r,!1),l(e=>e[e.length-1]?.role===`assistant`&&!e[e.length-1]?.content?e.slice(0,-1):e);return}try{fe=Xo(ce,ce.reqPath?.split(`/`).pop()?.replace(/\.[^.]+$/,``)||``)}catch(e){z(e instanceof Error?e.message:String(e)),Hr.current.delete(r),Ur.current=null,Vr.current=null,Aa(r,!1);return}}if(!N){let e=vn;if(!te&&!e.trim()&&B.reports)try{await tr(!0),e=await er()}catch{}!te&&e.trim()&&(fe=`${fe}\n\n${e.trim()}`);let t=Yc({lastUserMessageAt:[...p].reverse().find(e=>e.role===`user`&&e!==p[p.length-1])?.time??[...p].reverse().find(e=>e.role===`user`)?.time??null,lastInjectAt:Jr.current});if(t.injected&&(Jr.current=t.at),fe=`${fe}\n\n${t.text}`,y)try{let e=await gt();e?.text&&(fe=`${fe}\n\n${dt}\n\n${e.text}`)}catch{}}let P=Jd(fe,g,{memory:_&&!N,knowledge:v&&!N,fs:y&&!N,web:b&&!N,bash:ne&&!N,pwsh:re&&!N,interact:!N,todos:x&&!N,tasks:S&&!N,projects:C&&!N,iterations:T&&!N,pmRequirements:E&&!N,bugs:D&&!N,planPhase:N||te?`off`:ii,goalEnabled:!N,goal:$r,scheduleEnabled:!N,subagentEnabled:!N,workflowEnabled:!N}).map((e,t)=>t===0&&e.role===`system`&&y&&ae&&!N?{...e,content:`${typeof e.content==`string`?e.content:``}${ae}`}:e);if(_&&!N&&!te){H(`记忆注入中…`);let{context:e}=await qt(i,{cwd:le});if(e&&P[0]?.role===`system`){let t=typeof P[0].content==`string`?P[0].content:``;P=[{...P[0],content:`${t}\n\n${e}`},...P.slice(1)]}H(null)}let F=[];N||(v&&F.push(...Uu),y&&(F.push(...yt(O)),F.push(...kt),F.push(...Rs),F.push(...Bc),F.push(zr),ee||(F.push(Fr),F.push(_t))),ne&&(F.push(Gt),F.push(...Zt)),re&&(F.push(zt),F.push(...$t)),(ne||re)&&F.push(...It),b&&F.push(...vt),_&&F.push(...Ft),F.push(Zc),x&&F.push(...fc),S&&F.push(...jc),C&&F.push(...Ks),T&&F.push(...qs),E&&F.push(...Js),D&&F.push(...Ys),F.push(Qc),F.push(...yl),F.push(...Bl),F.push(...au),F.push(...Nu),(ii===`planning`||ii===`approved`)&&F.push(ol));let I=Date.now(),ge=0;qr.current.set(r,{start:I});let L=0,_e=!1,ve=``,ye=!1,be,xe=!!(j||M||ce);function Se(e){return j?fs(e):M?As(e):Zo(e)}function Ce(){return j?`正在编写提示词…`:M?`正在编写知识库…`:`正在编写用例…`}let we=!1;try{let n=``,a=``,o=``;if(xe){H(Ce());let e=()=>{let e=Math.max(0,Math.floor((Date.now()-I)/1e3));Fa(t=>({...t,content:Se(e)}))};e(),be=window.setInterval(e,1e3)}if(!(x||S||C||T||E||D)&&!xe&&!te&&await sr(h.signal)){let e=F.filter(e=>{let t=e.function?.name??``;return!(!t||t===`ask_user_question`||t===`submit_plan`||t===`workflow`||t===`spawn_subagent`||t===`fork_subagent`||t===`list_agents`||t.startsWith(`subagent_`))});(await lr({sessionId:r,messages:P,settings:{baseURL:t.baseURL,apiKey:t.apiKey,model:t.model,reasoningEffort:t.reasoningEffort},tools:e,thinking:!0,workspace:ie||``,access:O})).ok&&(we=!0,await new Promise(e=>{let t=!1,n=()=>{t||(t=!0,e())},i=()=>{ur(r)};h.signal.addEventListener(`abort`,i),Gr.current.get(r)?.();let a=mr(r,0,{signal:h.signal,onEvent:e=>Ma(r,e),onTerminal:e=>{ye=e.status===`completed`,h.signal.removeEventListener(`abort`,i),Gr.current.delete(r),n()},onGaveUp:e=>{K.current?.activeId===r&&z(e.message||`与服务端回合断开`),Pa(r,e=>{let t=e[e.length-1];if(t?.role!==`assistant`)return e;let n=e.slice();return n[n.length-1]={...t,turnStatus:`stopped`,activitySteps:(t.activitySteps??[]).map(e=>e.status===`running`?{...e,status:`done`}:e)},n}),h.signal.removeEventListener(`abort`,i),Gr.current.delete(r),n()}});Gr.current.set(r,()=>{a(),n()})}))}if(!we){let s=he(t,P,h.signal,{tools:F.length?F:void 0,runTool:F.length?async(n,i)=>{Yn(!0);let a=df(n);H(_f(Pe().toolStepDetail,a,n,`running`));let o=Date.now();try{if(n.startsWith(`kb_`))return await Ku(n,i,{base:`/`,docs:e});if(n.startsWith(`fs_`)){let e=await Vt(n,i,O),t=Uc(n,e);if(t&&K.current){let e=Hc(K.current.sessions.find(e=>e.id===r)?.workspaceChanges,t);q(ze(K.current,r,{workspaceChanges:e}))}return e}if(n.startsWith(`skill_`))return await zs(n,i);if(n===`load_workspace_dependencies`)return await Br(n);if(n===`office_to_pdf`)return ee?JSON.stringify({error:`计划模式探查中:请先 submit_plan 并等待批准`}):await Ir(n,i,O);if(n.startsWith(`workspace_changes_`)){let e=K.current?.sessions.find(e=>e.id===r),{text:t,next:i}=Wc(n,e?.workspaceChanges);return i&&K.current&&q(ze(K.current,r,{workspaceChanges:i})),t}if(n.startsWith(`working_directory_`)){let{text:e,info:t}=await Qt(n,i);return t&&(ma(t),n===`working_directory_set`&&K.current&&q(ze(K.current,r,{workspacePath:t.workspace}))),e}if(n===`present`){if(ee)return JSON.stringify({error:`计划模式探查中:请先 submit_plan 并等待批准`});let e=await sn(i,O);try{let t=JSON.parse(e);t.ok&&t.files?.length&&Fa(e=>{let n=e.presentFiles??[],r=new Map(n.map(e=>[e.path,e]));for(let e of t.files)r.set(e.path,e);return{...e,presentFiles:[...r.values()]}})}catch{}return e}if(n===`todo_add`){if(ee)return JSON.stringify({error:`计划模式探查中:请先 submit_plan 并等待批准`});let e;try{e=JSON.parse(i||`{}`).items}catch{e=void 0}let t=zd(`todo`,e);if(!t.length)return JSON.stringify({error:`没有可记录的待办:只有用户明确要求记录待办时才调用 todo_add,并给出待办标题;不要为了弹出卡片而调用工具。`});let n=await wc(t),r=await Pi(`todo`,n.items,{quick:!0,quickNote:n.willCreateRoutine?`确认后会创建任务「日常待办」并关联,状态 / 日期已自动填好`:void 0});if(!r)return JSON.stringify({ok:!1,cancelled:!0,message:`用户取消了新增待办,未写入任何数据。`});let a;try{a=await Tc(r)}catch(e){return JSON.stringify({error:`创建所属任务失败:${e instanceof Error?e.message:String(e)}`})}i=JSON.stringify({items:Bd(`todo`,a)})}if(n===`task_add`){if(ee)return JSON.stringify({error:`计划模式探查中:请先 submit_plan 并等待批准`});let e=zd(`task`,Mc(i));e.length||e.push(Rd(`task`));let t=await Pi(`task`,e);if(!t)return JSON.stringify({ok:!1,cancelled:!0,message:`用户取消了新增任务,未写入任何数据。`});i=JSON.stringify({items:Bd(`task`,t)})}if(n.startsWith(`task_`)){let e=await Nc(n,i,{sessionId:r});if(n===`task_add`)try{let t=JSON.parse(e);t.ok&&t.count&&z(`已创建 ${t.count} 个任务,可在侧栏「任务管理」查看。`,`ok`)}catch{}return e}if(n.startsWith(`todo_`)&&n!==`todo_write`){if(ee&&n!==`todo_list`)return JSON.stringify({error:`计划模式探查中:请先 submit_plan 并等待批准`});let e=await vc(n,i,{sessionId:r});if(n===`todo_add`)try{let t=JSON.parse(e);t.ok&&t.count&&z(`已记录 ${t.count} 条待办,可在侧栏「待办事项」查看。`,`ok`)}catch{}return e}if(n===`todo_write`){let e;try{e=JSON.parse(i||`{}`).todos}catch{return JSON.stringify({error:`invalid JSON arguments`})}let t=$c(e);return K.current?.activeId===r&&Qr(t),K.current&&q(ze(K.current,r,{todos:t})),JSON.stringify({ok:!0,count:t.length,todos:t})}if(n.startsWith(`pm_`)){if(ee&&!n.endsWith(`_list`))return JSON.stringify({error:`计划模式探查中:请先 submit_plan 并等待批准`});let e=await lc(n,i,{sessionId:r});if(n.endsWith(`_add`))try{let t=JSON.parse(e);if(t.ok&&t.count){let e=n.startsWith(`pm_project_`)?`项目列表`:n.startsWith(`pm_iteration_`)?`迭代管理`:n.startsWith(`pm_requirement_`)?`需求管理`:`缺陷管理`,r=n.startsWith(`pm_iteration_`)?`迭代`:n.startsWith(`pm_requirement_`)?`条需求`:n.startsWith(`pm_bug_`)?`条缺陷`:`个项目`;z(`已创建 ${t.count} ${r},可在侧栏「${e}」查看。`,`ok`)}}catch{}return e}if(n.startsWith(`goal_`)){if(n===`goal_get`)return xl(K.current?.activeId===r?ti.current:bl(K.current?.sessions.find(e=>e.id===r)?.goal));if(n===`goal_set`){let e=``;try{e=String(JSON.parse(i||`{}`).text??``).trim()}catch{return JSON.stringify({error:`invalid JSON arguments`})}if(!e)return JSON.stringify({error:`text is required`});let t={text:e.slice(0,500),status:`active`,updatedAt:Date.now()};return K.current?.activeId===r&&(ti.current=t,ei(t),ni.current=0),K.current&&q(ze(K.current,r,{goal:t})),xl(t)}if(n===`goal_done`){let e=K.current?.activeId===r?ti.current:bl(K.current?.sessions.find(e=>e.id===r)?.goal);if(!e?.text)return JSON.stringify({ok:!1,error:`no goal to complete`});let t={...e,status:`done`,updatedAt:Date.now()};return K.current?.activeId===r&&(ti.current=t,ei(t),ni.current=0),K.current&&q(ze(K.current,r,{goal:t})),xl(t)}return n===`goal_clear`?(K.current?.activeId===r&&(ti.current=null,ei(null),ni.current=0),K.current&&q(ze(K.current,r,{goal:void 0})),JSON.stringify({ok:!0,goal:null})):JSON.stringify({error:`unknown tool: ${n}`})}if(n.startsWith(`schedule_`))return await nu(n,i,r);if(n===`list_agents`||n===`spawn_subagent`||n===`fork_subagent`||n.startsWith(`subagent_`))return await Eu(n,i,{settings:Nr(t,Pe().subagentModel),parentSignal:h.signal,access:O,fsEnabled:y,webEnabled:b,parentMessages:g,onHint:e=>H(e),runFs:(e,t,n)=>Vt(e,t,n),runWeb:(e,t)=>Dt(e,t)});if(n===`workflow`)return await zu(n,i,{settings:t,parentSignal:h.signal,access:O,fsEnabled:y,webEnabled:b,parentMessages:g,onHint:e=>H(e),runFs:(e,t,n)=>Vt(e,t,n),runWeb:(e,t)=>Dt(e,t)});if(n===`ask_user_question`){let e=el(i);if(!e.length)return JSON.stringify({error:`questions is required`});let t={};for(let n of e)t[n.id]={selected:[],text:``};return hi(t),_i(0),yi(!1),xi(null),Ci(!1),Ti(``),pi(e),await new Promise((e,t)=>{Yr.current={resolve:e,reject:t};let n=Vr.current,r=()=>{n?.signal.removeEventListener(`abort`,r),so()};n?.signal.addEventListener(`abort`,r)})}if(n===`submit_plan`){let e=sl(i);return e?(di(e),await new Promise((e,t)=>{Xr.current={resolve:e,reject:t};let n=Vr.current,r=()=>{n?.signal.removeEventListener(`abort`,r),co()};n?.signal.addEventListener(`abort`,r)})):JSON.stringify({error:`title and steps are required`})}return n===`bash`?await Ht(i,O):n===`pwsh`?await Wt(i,O):n.startsWith(`bash_session_`)?await Bt(n,i,O):n.startsWith(`pwsh_session_`)?await Xt(n,i,O):n.startsWith(`job_`)?await en(n,i,O):n.startsWith(`web_`)?await Dt(n,i):n.startsWith(`memory_`)?await Ct(n,i,le):JSON.stringify({error:`unknown tool: ${n}`})}finally{let e=Math.max(0,Date.now()-o);Fa(t=>({...t,toolMs:(t.toolMs??0)+e})),Yn(!1),pa()}}:void 0});for await(let e of s){if(e.type===`tool`){let t=df(e.name);H(_f(Pe().toolStepDetail,t,e.name,e.status===`running`?`running`:`done`));let n=hf(e.name,e.args),r=`tool_${e.name}_${e.args?.slice(0,24)??``}`,i=e.status===`done`&&typeof e.result==`string`&&/^\s*\{\s*"error"\s*:/.test(e.result);Fa(a=>{let o=[...a.activitySteps??[]],s=o.findIndex(e=>e.id===r||e.detail===n&&e.title===t&&e.status===`running`),c={id:r,kind:pf(e.name),title:t,detail:n||void 0,status:e.status===`running`?`running`:i?`error`:`done`};return s>=0?o[s]={...o[s],...c}:o.push(c),{...a,activitySteps:o}});continue}if(e.type===`usage`){let n=Date.now(),r=ge?(n-ge)/1e3:0,i=Jf(e.usage),a=r>.2&&i>0?i/r:void 0;Fa(r=>({...r,usage:e.usage,tps:a,model:t.model,ttftMs:ge?ge-I:r.ttftMs,llmMs:n-I}));continue}if(ge===0&&(ge=Date.now(),Fa(e=>({...e,ttftMs:ge-I,model:t.model}))),e.type===`reasoning_api`){Fa(t=>({...t,reasoningApi:e.content}));continue}e.type===`reasoning`&&L===0&&(L=Date.now());let r=e.type===`content`&&L>0&&!_e;if(r&&(_e=!0),xe){e.type===`content`&&(j?a+=e.delta:M?o+=e.delta:n+=e.delta);let t=Se(Math.max(0,Math.floor((Date.now()-I)/1e3)));if(e.type===`reasoning`){ve+=e.delta;let n=pe(ve);Fa(e=>{let i={...e,reasoning:n,content:t};return r&&(i.reasoningDuration=Math.max(1,Math.round((Date.now()-L)/1e3))),i})}else r&&Fa(e=>({...e,content:t,reasoningDuration:Math.max(1,Math.round((Date.now()-L)/1e3))}))}else e.type===`reasoning`&&(ve+=e.delta),Fa(t=>{let n=e.type===`reasoning`?{...t,reasoning:pe(ve)}:{...t,content:pe(t.content+e.delta)};if(e.type===`reasoning`){let e=[...n.activitySteps??[]],t=e.findIndex(e=>e.kind===`thinking`),r={id:`thinking`,kind:`thinking`,title:`思考`,detail:gf(n.reasoning??``).replaceAll(`**`,``).slice(0,80)||void 0,status:`running`};t>=0?e[t]={...e[t],...r}:e.unshift(r),n.activitySteps=e}if(r){n.reasoningDuration=Math.max(1,Math.round((Date.now()-L)/1e3));let e=[...n.activitySteps??[]],t=e.findIndex(e=>e.kind===`thinking`);t>=0&&(e[t]={...e[t],status:`done`}),n.activitySteps=e}return n})}if(ye=!0,!xe){let e=[...K.current?.sessions.find(e=>e.id===r)?.messages??[]].reverse().find(e=>e.role===`assistant`);e&&typeof e.content==`string`&&!e.content.trim()&&z(`模型本轮没有返回正文(可能工具轮次用尽或输出被截断),请重试或回复「继续」`)}{let e=L>0&&!_e?Math.max(1,Math.round((Date.now()-L)/1e3)):null;Fa(t=>{let n=(t.activitySteps??[]).map(e=>e.kind===`thinking`&&e.status===`running`?{...e,status:`done`}:e),r={...t,activitySteps:n};return e!=null&&t.reasoning&&t.reasoningDuration==null&&(r.reasoningDuration=e),r})}if(be!=null&&(window.clearInterval(be),be=void 0),j){H(`正在质检并入库…`);let e=await hs(a,j);if(Fa(t=>({...t,content:e.summary,docsFile:e.ok?{root:`prompts`,path:e.path,name:e.path.split(`/`).pop()||e.title||e.path}:void 0})),e.ok&&K.current){let t={...j,linkedPromptPath:e.path};oe(t),se.current=t,q(Re(K.current,{promptGen:t}))}}else if(M){H(`正在质检并入库…`);let e=await Ns(o,M);if(Fa(t=>({...t,content:e.summary,docsFile:e.ok?{root:`knowledge`,path:e.path,name:e.path.split(`/`).pop()||e.title||e.path,note:e.category}:void 0})),e.ok&&K.current){let t={...M,linkedKnowledgePath:e.path};ue(t),de.current=t,q(Re(K.current,{knowledgeGen:t}))}}else if(ce){H(`正在检测覆盖并入库…`);let e=ce.reqPath?.split(`/`).pop()?.replace(/\.[^.]+$/,``)||i.slice(0,24),t=await es(n,ce,e);if(Fa(e=>({...e,content:t.summary,caseFile:t.ok?{path:t.path,name:t.path.split(`/`).pop()||t.path,count:t.count}:void 0})),t.ok&&K.current){let e={...ce,linkedCasePath:t.path};k(e),A.current=e,q(Re(K.current,{caseGen:e}))}}}we&&ye&&Fa(e=>({...e,turnStatus:e.turnStatus===`stopped`?`stopped`:`completed`,activitySteps:(e.activitySteps??[]).map(e=>e.status===`running`?{...e,status:`done`}:e)}))}catch(e){e instanceof DOMException&&e.name===`AbortError`||K.current?.activeId===r&&z(e instanceof Error?e.message:String(e)),Pa(r,e=>{let t=e[e.length-1];if(t?.role===`assistant`&&!t.content&&!t.reasoning&&!t.activitySteps?.length)return e.slice(0,-1);if(t?.role!==`assistant`)return e;let n=e.slice();return n[n.length-1]={...t,activitySteps:(t.activitySteps??[]).map(e=>e.status===`running`?{...e,status:`done`}:e)},n})}finally{be!=null&&(window.clearInterval(be),be=void 0);let e=Date.now(),n=qr.current.get(r),a=ge||n?.firstToken||0;Fa(n=>{let r=n.llmMs??e-I,i=n.ttftMs??(a?a-I:void 0),o=i==null?0:Math.max(0,(r-i)/1e3),s=Jf(n.usage),c=n.tps??(o>.2&&s>0?s/o:void 0);return{...n,time:e,model:n.model??t.model,llmMs:r,ttftMs:i,tps:c,turnStatus:n.turnStatus===`stopped`||n.turnStatus===`completed`?n.turnStatus:ye?`completed`:(h.signal.aborted||!we)&&n.turnStatus===`running`?`stopped`:n.turnStatus,activitySteps:(n.activitySteps??[]).map(e=>e.status===`running`?{...e,status:`done`}:e)}}),qr.current.delete(r),Hr.current.delete(r),Gr.current.get(r)?.(),Gr.current.delete(r),Ur.current===r&&(Ur.current=null),Vr.current===h&&(Vr.current=null),Aa(r,!1);{let e=Pe().toolStepDetail;e===`full`?window.setTimeout(()=>H(null),2800):e===`detailed`?window.setTimeout(()=>H(null),1200):H(null)}if(ye&&_&&Jt(i,le).finally(()=>{pa()}),ye&&K.current){let e=[...K.current.sessions.find(e=>e.id===r)?.messages??[]].reverse().find(e=>e.role===`assistant`),n=Or({userContent:i,assistantContent:typeof e?.content==`string`?e.content:``,reasoning:e?.reasoning});n.length&&kr({sessionId:r,model:e?.model??t.model,messages:n})}if(ye&&t&&!h.signal.aborted&&K.current){let e=K.current.sessions.find(e=>e.id===r),n=e?.messages??[];if(e&&!ri.current.has(r)&&gr(e.title,n)){let e=hr(n);e&&(ri.current.add(r),vr(t,e).then(e=>{if(!e||!K.current)return;let t=K.current.sessions.find(e=>e.id===r);t&&gr(t.title,t.messages)&&q(Je(K.current,r,e))}))}}let o=K.current?.activeId===r,s=null;if(o){s=Bi.current,Bi.current=null,!s&&zi.current.length&&(s=zi.current[0],Vi(zi.current.slice(1)));let e=Sl(ti.current);if(!s&&!N&&Ol({goalActive:!!e,turnOk:ye,aborted:h.signal.aborted,hasFollowUp:!1,askUserPending:!!Yr.current,roundsUsed:ni.current,maxRounds:3})){let t=ni.current+1;ni.current=t,s={id:`goal_drv_${Date.now().toString(36)}`,content:El(e,t,3),files:[],refs:[],imgs:[]}}}s&&window.setTimeout(()=>{qa(s)},0)}}function Ja(){Bi.current=null,Vi([]),ni.current=0;let e=K.current?.activeId;e&&Pa(e,e=>{let t=e[e.length-1];if(t?.role!==`assistant`)return e;let n=e.slice();return n[n.length-1]={...t,turnStatus:`stopped`,activitySteps:(t.activitySteps??[]).map(e=>e.status===`running`?{...e,status:`done`}:e)},n}),ja(e)}function Ya(e){Vi(zi.current.filter(t=>t.id!==e))}function Xa(e){let t=zi.current.find(t=>t.id===e);t&&(Ya(e),d(t.content),p(t.files),x(t.imgs),C(t.refs),requestAnimationFrame(()=>Wi.current?.focus()))}function Za(e){let t=zi.current.find(t=>t.id===e);t&&(Vi(zi.current.filter(t=>t.id!==e)),G.current?(Bi.current=t,ja(K.current?.activeId)):qa(t))}function Qa(e){let t=[...zi.current],n=e??t.shift()??null;n&&(Vi(t),G.current?(Bi.current=n,ja(K.current?.activeId)):qa(n))}function $a(e,t){let n=!(s[e]?.reasoningOpen??!1);if(l(t=>t.map((t,n)=>n===e?{...t,reasoningOpen:!t.reasoningOpen}:t)),n){let e=t.currentTarget;requestAnimationFrame(()=>{(e.nextElementSibling??e).scrollIntoView({block:`nearest`,behavior:`smooth`})})}}function eo(e){e&&(u.trim()||f.length>0||_.length>0||S.length>0?Zi.current[e]={input:u,attachments:f,images:_,docRefs:S}:delete Zi.current[e])}function Y(e){let t=e?Zi.current[e]:void 0;d(t?.input??``),p(t?.attachments??[]),x(t?.images??[]),C(t?.docRefs??[])}function to(e){e?.abortRun!==!1&&ja(K.current?.activeId),G.current=!1,wt(!1),p([]),x([]),C([]),d(``),z(null),fn(!1),sa.current=!0,e?.clearDraft&&K.current?.activeId&&delete Zi.current[K.current.activeId]}function X(e,t){if(!K.current)return;Gn(`dialog`);let n=K.current.activeId,r=K.current.sessions.find(e=>e.id===n),i=!!r&&!r.archived&&!r.deleted&&(!Array.isArray(r.messages)||r.messages.length===0),a=n=>({...n,title:n.title?.trim()||`新对话`,caseGen:e===`caseGen`?t:void 0,promptGen:e===`promptGen`?t:void 0,knowledgeGen:e===`knowledgeGen`?t:void 0,updatedAt:Date.now()}),o;if(i&&n)to({clearDraft:!0,abortRun:!1}),o={...K.current,activeId:n,sessions:K.current.sessions.map(e=>e.id===n?a(e):e)};else{eo(n),to({clearDraft:!0,abortRun:!1});let e=Ca(n)??K.current,t=V?.workspace?.trim()||void 0;o=et(e,{workspacePath:t,access:je()});let r=o.activeId;o={...o,sessions:o.sessions.map(e=>e.id===r?a(e):e)}}q(o),l([]),k(e===`caseGen`?t:null),A.current=e===`caseGen`?t:null,oe(e===`promptGen`?t:null),se.current=e===`promptGen`?t:null,ue(e===`knowledgeGen`?t:null),de.current=e===`knowledgeGen`?t:null;let s=o.sessions.find(e=>e.id===o.activeId)?.workspacePath||V?.workspace?.trim()||V?.projectRoot;s&&In(e=>({...e,[s]:!0})),_a(o.sessions.find(e=>e.id===o.activeId))}async function no(e){let t=K.current;if(!t)return;let n=t.sessions.find(e=>e.id===t.activeId),r=la.current?.harnessRoot?.trim()||la.current?.projectRoot?.trim()||la.current?.workspace?.trim(),i=n?.pluginDev?.active?n.pluginDev:{active:!0,requirement:e.trim(),confirmedAt:Date.now()};if(q(Re(t,{pluginDev:i,access:ln===`full`?`full`:`readwrite`,...r?{workspacePath:r}:{}})),P(i),me.current=i,F.current=null,co(),ai(`off`),r&&In(e=>({...e,[r]:!0})),W&&r&&la.current?.workspace!==r)try{ma(await rn(r))}catch{}}function ro(e){e?.active?X(`caseGen`,e):(k(null),A.current=null,K.current&&q(Re(K.current,{caseGen:void 0})))}function io(e){e?.active?X(`promptGen`,e):(oe(null),se.current=null,K.current&&q(Re(K.current,{promptGen:void 0})))}function ao(e){e?.active?X(`knowledgeGen`,e):(ue(null),de.current=null,K.current&&q(Re(K.current,{knowledgeGen:void 0})))}function oo(e){if(we(!1),!K.current)return;Gn(`dialog`);let t=K.current.activeId;eo(t),to({clearDraft:!0,abortRun:!1});let n=Ca(t)??K.current,r=e?.trim()||V?.workspace?.trim()||void 0,i=et(n,{workspacePath:r,access:je()});q(i),l([]),k(null),oe(null),ue(null),P(null),me.current=null,Qr([]),ti.current=null,ei(null),ni.current=0,ai(`off`),si(e=>e===`pluginDev`?null:e),so(),co();let a=r||V?.projectRoot;a&&In(e=>({...e,[a]:!0})),_a(i.sessions.find(e=>e.id===i.activeId))}function so(){let e=Yr.current;e&&(Yr.current=null,pi(null),hi({}),_i(0),yi(!1),xi(null),Ci(!1),Ti(``),e.resolve(JSON.stringify({canceled:!0,error:`user aborted`})))}function co(){let e=Xr.current;e&&(Xr.current=null,di(null),e.resolve(JSON.stringify({approved:!1,canceled:!0})))}function lo(){let e=Xr.current;e&&(Xr.current=null,di(null),ai(`approved`),e.resolve(JSON.stringify({approved:!0,message:`用户已批准计划,可以开始实施`})))}function uo(){let e=Xr.current;e&&(Xr.current=null,di(null),ai(`planning`),e.resolve(JSON.stringify({approved:!1,message:`用户驳回了计划,请修订后再次 submit_plan`})))}function fo(){ai(e=>e===`off`?(si(`plan`),`planning`):(co(),si(e=>e===`plan`?null:e),`off`))}function po(e,t){return!e||!t?!1:t.skipped||t.text.trim()!==``?!0:e.options?.length?t.selected.length>0:!1}function mo(e,t,n){let r=Yr.current;if(!r)return;Yr.current=null,pi(null),hi({}),_i(0),yi(!1),xi(null),Ci(!1),Ti(``),z(null);let i=t.filter(e=>e.skipped).length,a=String(n?.skipReason??``).trim();r.resolve(JSON.stringify({answers:t,summary:rl(e,t),...i?{skipped:!0,approvalRequired:!0,...a?{skipReason:a}:{},note:`用户跳过了部分或全部问题:跳过的题不算确认,也未批准实施。`+(a?`用户给出的跳过原因:${a}。`:``)+`本轮只允许只读调研与文字方案,禁止 fs_write / fs_mkdir / 改配置;请先说明采用的默认假设(哪几项按推荐)与准备改动的范围`+(a?`,并针对上述原因给出调整`:``)+`,然后等用户明确回复「开始实施」再动手。`}:{note:`answers 为结构化答案;summary 是同一批答案的中文文本版本,可直接据此继续,无需再次提问。`},...n}))}function ho(e,t,n){hi(r=>{let i=r[e.id]??{selected:[],text:``},a=e.multi_select?n?i.selected.filter(e=>e!==t):[...i.selected,t]:[t];return{...r,[e.id]:{selected:a,text:``,skipped:!1}}}),xi(null),e.multi_select||_i(e=>Math.min(e+1,(fi?.length??1)-1))}function go(e){let t=fi?.length??0;t&&(_i(Math.max(0,Math.min(e,t-1))),xi(null))}function _o(e,t){e&&(hi(n=>{let r=n[e.id]??{selected:[],text:``};return{...n,[e.id]:{selected:e.multi_select?r.selected:[],text:t,skipped:!1}}}),xi(null))}function vo(e,t){let n=t.trim(),r=n&&e.options?.length?tl(e,n):null,i=r?{selected:r,text:``,skipped:!1}:{selected:e.multi_select?mi[e.id]?.selected??[]:[],text:n,skipped:!1},a={...mi,[e.id]:i};hi(a),xi(null),Es?bo(a):go(Cs+1)}function yo(e){return(fi??[]).map(t=>{let n=nl(t,e[t.id]??{selected:[],text:``});return n.skipped||n.text?.trim()||n.selected?.length?n:{id:t.id,selected:[],skipped:!0}})}function bo(e=mi,t=!1){let n=fi;if(!n?.length||!Yr.current)return!1;let r=yo(e),i=r.findIndex(e=>!e.skipped&&!e.text?.trim()&&!e.selected?.length);if(i>=0)return go(i),xi(n[i]?.options?.length?`请先选择选项再提交`:`请先填写回答再提交`),!1;if(!t&&r.some(e=>e.skipped))return Ci(!0),xi(null),!1;let a=wi.trim();return mo(n,r,a?{skipReason:a}:void 0),!0}function xo(){let e=fi,t=ws;if(!e?.length||!t)return;let n={...mi,[t.id]:{selected:[],text:``,skipped:!0}};hi(n),xi(null),Es?bo(n):go(Cs+1)}function So(){bo(mi,!0)}function Co(){Ci(!1);let e=yo(mi).findIndex(e=>e.skipped);go(e>=0?e:0)}function wo(e){if(we(!1),!K.current||(Gn(`dialog`),Un(null),e===K.current.activeId))return;let t=K.current.activeId;eo(t),so(),co(),ai(`off`),z(null),fn(!1),sa.current=!0;let n=Ca(t)??K.current;n.sessions.some(t=>t.id===e)||(n=K.current);let r=Be(n,e),i=r.sessions.find(t=>t.id===e),a=Hr.current.get(e)?.messages??i?.messages??[];ua.current=a,l(a);let o=Hr.current.has(e)||Tt.includes(e);G.current=o,wt(o),Vr.current=Hr.current.get(e)?.abort??null,o&&!Gr.current.has(e)&&Na(e,0),k(i?.caseGen?.active?i.caseGen:null),oe(i?.promptGen?.active?i.promptGen:null),ue(i?.knowledgeGen?.active?i.knowledgeGen:null),P(i?.pluginDev?.active?i.pluginDev:null),si(e=>i?.pluginDev?.active?`pluginDev`:e===`pluginDev`?null:e),Qr($c(i?.todos));{let e=bl(i?.goal);ti.current=e,ei(e),ni.current=0}Y(e),q(r),_a(i)}function To(e){if(!K.current)return;Un(null),ut(null);let t=K.current.activeId===e;t&&to({clearDraft:!0}),delete Zi.current[e];let n=rt(K.current,e);if(q(n),t){let e=n.sessions.find(e=>e.id===n.activeId);l(e?.messages??[]),k(e?.caseGen?.active?e.caseGen:null),oe(e?.promptGen?.active?e.promptGen:null),ue(e?.knowledgeGen?.active?e.knowledgeGen:null),P(e?.pluginDev?.active?e.pluginDev:null),si(t=>e?.pluginDev?.active?`pluginDev`:t===`pluginDev`?null:t)}}function Eo(e,t){if(!K.current)return;Un(null);let n=K.current.activeId===e&&t;n&&to();let r=Xe(K.current,e,t);if(q(r),n){let e=r.sessions.find(e=>e.id===r.activeId);l(e?.messages??[])}}function Do(e){if(!K.current)return;let t=K.current.sessions.find(t=>t.id===e);t&&(Un(null),q(Ye(K.current,e,!t.pinned)))}function Oo(e){K.current&&K.current.sessions.some(t=>t.id===e)&&(Un(null),ut(null),Ae(e))}function ko(){let e=K.current?.activeId,t=K.current?.sessions.find(t=>t.id===e);t?z(Er(`stats`,t.id,t.updatedAt,()=>br(yr(t))),`ok`):z(`无活跃会话可统计`)}function Ao(e){K.current&&Te&&(ri.current.add(Te),q(Je(K.current,Te,e)),Ae(null))}function jo(){mn(e=>(He(!e),!e))}async function Mo(e){let t=Array.from(e.target.files??[]);e.target.value=``,await Fo(t)}function No(){let t=e.map(e=>({collection:e.collection,path:e.path,title:e.title,category:e.category,format:String(e.format)})),n=Tr.map(e=>({collection:`workspace`,path:e.path,title:e.name,category:Kt(V?.workspace,V?.projectRoot),format:e.type===`dir`?`dir`:`file`}));return[...t,...n]}function Po(e){e.length&&C(t=>{let n=[...t];for(let t of e){if(n.length>=$d)break;n.some(e=>e.collection===t.collection&&e.path===t.path)||n.push(t)}return n})}async function Fo(e,t){let n=[],r=[],i=[],a=cf(f,_);for(let o of e)if(a>=6)i.push(`${o.name}(最多 6 个文件)`);else try{let e=await nd(o);e.kind===`image`?r.push(await sf(e.file)):n.push({name:e.name,size:e.size,content:e.content,path:t?.get(o.name)||t?.get(e.name)}),a+=1}catch(e){i.push(e instanceof Error?e.message:String(e))}n.length&&p(e=>[...e,...n]),r.length&&x(e=>[...e,...r]),z(i.length?`以下文件未添加:${i.join(`、`)}`:null),Wi.current?.focus()}function Io(e){let t=e.clipboardData;if(!t)return;let n=Array.from(t.items??[]),r=n.filter(e=>e.kind===`file`&&e.type.startsWith(`image/`)).map(e=>e.getAsFile()).filter(e=>!!e),i=n.filter(e=>e.kind===`file`&&!e.type.startsWith(`image/`)).map(e=>e.getAsFile()).filter(e=>!!e);for(let e of Array.from(t.files??[]))e.type.startsWith(`image/`)?r.some(t=>t.name===e.name&&t.size===e.size)||r.push(e):i.some(t=>t.name===e.name&&t.size===e.size)||i.push(e);let a=dd(t),o=(t.getData(`text/plain`)||``).trim(),s=No(),c=Kt(V?.workspace,V?.projectRoot),l={projectRoot:V?.projectRoot,workspace:V?.workspace,workspaceLabel:c},u=[],d=new Map;for(let e of a){let t=md(e,l);t?(u.push(t),d.set(ad(e),t.path)):d.set(ad(e),e)}let f=null;!r.length&&!i.length&&!a.length&&ld(o)&&(f=hd(o,s));let p=[],m=[];for(let e of i){let t=d.get(e.name),n=(t?md(t,l):null)||hd(e.name,s);n?p.push(n):m.push(e)}(u.length>0||p.length>0||f||r.length>0||m.length>0)&&(e.preventDefault(),z(null),Po([...u,...p,...f?[f]:[]]),r.length&&La(r),m.length&&Fo(m,d),Wi.current?.focus())}function Lo(e){let t=e.target.closest(`[data-copy-code]`);t&&Qf(t.closest(`.code-block`)?.querySelector(`pre`)?.textContent??``).then(e=>{e&&(t.textContent=`已复制`,window.setTimeout(()=>{t.textContent=`复制`},1e3))})}let Ro=s.length===0,zo=!!(u.trim()||f.length||S.length||_.length||oi===`reports`),Bo=-1,Vo=-1;s.forEach((e,t)=>{e.role===`user`?Bo=t:e.role===`assistant`&&(Vo=t)});let Ho=e=>e===Bo||e===Vo?``:`opacity-0 group-hover:opacity-100 group-focus-within:opacity-100 transition-opacity`,Uo=uf.find(e=>e.value===ln)??uf[0],Wo=oi===`pluginDev`,qo=(a?.sessions??[]).filter(e=>!e.archived&&!e.deleted),Jo=(a?.sessions??[]).filter(e=>e.archived&&!e.deleted),Yo=V?.items??[],Qo=new Set(Yo.map(e=>e.path)),$o=V?.workspace??``,ts=V?.projectRoot??``,ns=a?.sessions.find(e=>e.id===a.activeId),rs=ns?.workspacePath,is=!rs||!Qo.has(rs),as=V?.workspace?.trim()||``,os=Yo.find(e=>e.path===as),cs=os?Lt(os,ts):as?Kt(as,ts):`工作区`,ls=Ln.trim().toLowerCase(),us=(0,U.useMemo)(()=>ls?new Set(Lc(a,Ln,{limit:50,includeArchived:!0}).map(e=>e.sessionId)):null,[ls,a,Ln]),[ps,ms]=(0,U.useState)(null);(0,U.useEffect)(()=>{if(!ls){ms(null);return}let e=!1;return ms(null),Rc(Ln,{limit:50,includeArchived:!0}).then(t=>{!e&&t?.hits&&ms(new Set(t.hits.map(e=>e.sessionId)))}),()=>{e=!0}},[ls,Ln]);let gs=ps??us,_s=gs?Jo.filter(e=>gs.has(e.id)):Jo;function vs(e){let t=e.id===`ws_project`||e.path===ts;return st(qo.filter(n=>!(n.workspacePath!==e.path&&(!t||n.workspacePath&&Qo.has(n.workspacePath)))).filter(e=>!gs||gs.has(e.id)))}let ys=Yo.filter(e=>!ls||e.name.toLowerCase().includes(ls)||e.path.toLowerCase().includes(ls)?!0:vs(e).length>0);function bs({s:e,nested:t=!1}){let n=e.id===a?.activeId,r=Hn===e.id,i=Tt.includes(e.id);return(0,Q.jsx)(zf,{s:e,nested:t,active:n,menuOpen:r,busy:i,onOpen:()=>wo(e.id),onRename:()=>Oo(e.id),onToggleMenu:()=>{ut(null),Un(r?null:e.id)},onTogglePin:()=>Do(e.id),onToggleArchive:()=>Eo(e.id,!e.archived),onExport:()=>{Un(null);let t=Il(e,`json`);z(t.ok?`已导出 ${t.filename}`:t.error)},onRemove:()=>{Un(null),ut(null),Ie(e.id)}})}let Ss=fi?.length??0,Cs=Math.max(0,Math.min(gi,Ss-1)),ws=fi?.[Cs],Ts=ws&&mi[ws.id]||{selected:[],text:``},Es=Cs>=Ss-1,Ds=po(ws,Ts),Os=(fi??[]).map((e,t)=>({q:e,index:t})).filter(({q:e})=>mi[e.id]?.skipped);return(0,Q.jsxs)(`div`,{className:`tw-app h-full min-h-0 flex overflow-hidden bg-(--tw-surface-page)`,children:[(0,Q.jsxs)(`aside`,{className:`tw-session-rail shrink-0 border-r border-(--tw-border) flex flex-col transition-[width] ${pn?`w-64`:`w-10`}`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1 ${pn?`px-2.5 pt-2.5`:`px-1 pt-2 justify-center`}`,children:[pn&&(0,Q.jsx)(`div`,{className:`flex-1 min-w-0 text-[13px] font-medium text-stone-700 truncate px-1`,children:R(`chat.workbench`,void 0,Kn.language)}),(0,Q.jsx)(`button`,{type:`button`,"aria-label":pn?`收起侧栏`:`展开侧栏`,onClick:jo,className:`w-8 h-8 shrink-0 flex items-center justify-center rounded-lg text-stone-500 hover:bg-stone-200/70`,children:(0,Q.jsx)($,{className:`w-4 h-4`,children:pn?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`}),(0,Q.jsx)(`path`,{d:`M9 3v18`})]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`}),(0,Q.jsx)(`path`,{d:`M15 3v18`})]})})})]}),pn?(0,Q.jsxs)(`div`,{className:`px-2.5 pt-2 space-y-1.5`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>oo(),className:`w-full h-9 flex items-center justify-center gap-1.5 text-[13px] font-medium text-stone-700 bg-white rounded-full border border-stone-200/80 shadow-sm hover:bg-stone-50 transition-colors`,children:[(0,Q.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Q.jsx)(`path`,{d:`M5 12h14`}),(0,Q.jsx)(`path`,{d:`M12 5v14`})]}),R(`chat.newSession`,void 0,Kn.language)]}),(0,Q.jsxs)(`button`,{type:`button`,"data-hint":`我的插件`,onClick:()=>we(e=>!e),className:`tw-rail-plugin-btn w-full h-9 flex items-center justify-center gap-1.5 text-[13px] font-medium rounded-full transition-colors ${Ce?`is-active`:``}`,children:[(0,Q.jsx)(Pf,{className:`w-3.5 h-3.5`}),`插件`]})]}):(0,Q.jsxs)(`div`,{className:`px-1 pt-1 flex flex-col gap-1`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>oo(),"data-hint":`新会话`,className:`w-8 h-8 flex items-center justify-center rounded-lg text-[#4176e6] hover:bg-white/80`,children:(0,Q.jsxs)($,{className:`w-4 h-4`,children:[(0,Q.jsx)(`path`,{d:`M5 12h14`}),(0,Q.jsx)(`path`,{d:`M12 5v14`})]})}),(0,Q.jsx)(`button`,{type:`button`,"data-hint":`我的插件`,onClick:()=>we(e=>!e),className:`tw-rail-plugin-btn tw-rail-plugin-btn--icon w-8 h-8 flex items-center justify-center rounded-lg ${Ce?`is-active`:``}`,children:(0,Q.jsx)(Pf,{className:`w-4 h-4`})})]}),pn&&(0,Q.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-2 py-3`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1 px-1.5 pb-2`,children:[(0,Q.jsx)(`div`,{className:`flex-1 text-[12px] font-semibold text-stone-500`,children:R(`chat.workspace`,void 0,Kn.language)}),(0,Q.jsx)(`button`,{type:`button`,"aria-label":`搜索`,onClick:()=>{Vn(e=>!e),Bn&&Rn(``)},className:`w-6 h-6 flex items-center justify-center rounded text-stone-400 hover:text-stone-700 hover:bg-stone-200/70`,children:(0,Q.jsx)(kf,{className:`w-3.5 h-3.5`})}),(0,Q.jsx)(`button`,{type:`button`,"data-hint":W?`添加工作区(选择本地文件夹)`:`本地文件服务未就绪`,disabled:!W||Nn,onClick:()=>void ya(),className:`w-6 h-6 flex items-center justify-center rounded text-stone-400 hover:text-stone-700 hover:bg-stone-200/70 disabled:opacity-40`,children:(0,Q.jsx)(Af,{className:`w-3.5 h-3.5`})})]}),Bn&&(0,Q.jsx)(`input`,{value:Ln,onChange:e=>Rn(e.target.value),placeholder:`搜索工作区 / 会话标题 / 消息`,className:`w-full mb-2 px-2.5 py-1.5 text-[12px] rounded-lg border border-stone-200 bg-white text-stone-700 placeholder:text-stone-400 focus:outline-none focus:ring-1 focus:ring-[#4176e6]/40`}),Pr&&(0,Q.jsx)(`div`,{className:`px-1.5 py-2 text-[11px] text-amber-700/80`,children:`本地文件服务未就绪,工作区暂不可用`}),(0,Q.jsxs)(`div`,{className:`space-y-0.5`,children:[ys.map(e=>{let t=vs(e),n=!!(Fn[e.path]??t.length>0),r=e.id===`ws_project`||e.path===ts,i=!!(ns&&(is?r:rs===e.path)),a=tt===e.id;return(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`div`,{className:`tw-project-row group relative ${i?`is-active`:``} ${n?`is-expanded`:``} ${a?`is-menu-open`:``}`,children:[(0,Q.jsxs)(`button`,{type:`button`,"data-hint":e.path,onClick:t=>{t.stopPropagation(),Un(null),ut(null),In(t=>({...t,[e.path]:!n})),W&&e.path!==$o&&ha(e.path,`select`)},className:`flex-1 min-w-0 h-full flex items-center gap-1.5 text-left outline-none focus:outline-none`,children:[(0,Q.jsx)(`span`,{className:`tw-slot tw-folder`,children:(0,Q.jsx)(Df,{open:n,className:`w-3.5 h-3.5`})}),(0,Q.jsx)(`span`,{className:`tw-slot tw-chevron`,children:(0,Q.jsx)(Of,{open:n,className:`w-3 h-3`})}),(0,Q.jsx)(`span`,{className:`tw-project-title`,children:Lt(e,ts)})]}),(0,Q.jsxs)(`div`,{className:`tw-ws-actions relative shrink-0`,"data-ws-menu":``,children:[(0,Q.jsx)(Lf,{open:a,onToggle:()=>{Un(null),ut(a?null:e.id)},onRename:()=>{Un(null),ut(null),ht(e.id)},onDelete:e.id===`ws_project`?void 0:()=>xa(e)}),(0,Q.jsx)(`button`,{type:`button`,"data-hint":`在此工作区新建会话`,onClick:t=>{t.stopPropagation(),oo(e.path)},className:`w-6 h-6 flex items-center justify-center rounded text-(--tw-label-tertiary) hover:text-(--tw-label-primary) hover:bg-(--tw-session-hover-bg)`,children:(0,Q.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Q.jsx)(`path`,{d:`M5 12h14`}),(0,Q.jsx)(`path`,{d:`M12 5v14`})]})})]})]}),(0,Q.jsx)(`div`,{className:`tw-collapse ${n?`is-open`:``}`,children:(0,Q.jsx)(`div`,{className:`tw-collapse-inner`,children:t.map(e=>(0,Q.jsx)(bs,{s:e,nested:!0},e.id))})})]},e.id)}),!ys.length&&W&&(0,Q.jsx)(`div`,{className:`px-2 py-3 text-xs text-stone-400`,children:`暂无工作区`})]}),_s.length>0&&(0,Q.jsxs)(`div`,{className:`mt-3 pt-2 border-t border-stone-200/60`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>gn(e=>!e),className:`w-full flex items-center gap-1 px-1.5 pb-1 text-[11px] text-stone-400 hover:text-stone-600`,children:[(0,Q.jsx)(vf,{className:`w-3 h-3 transition-transform ${hn?`rotate-180`:``}`}),`已归档 (`,_s.length,`)`]}),(0,Q.jsx)(`div`,{className:`tw-collapse ${hn?`is-open`:``}`,children:(0,Q.jsx)(`div`,{className:`tw-collapse-inner space-y-0.5`,children:_s.map(e=>(0,Q.jsx)(bs,{s:e},e.id))})})]})]}),pn&&($o||Jn||Xn)&&(0,Q.jsxs)(`div`,{className:`shrink-0 border-t border-stone-200/60 px-3 py-2 space-y-1`,children:[$o&&(0,Q.jsxs)(`div`,{className:`tw-rail-workspace-footer`,"data-hint":$o,children:[(0,Q.jsx)(`span`,{className:`tw-rail-workspace-label`,"data-i18n":`chat.workspace`,children:`工作区`}),(0,Q.jsx)(`span`,{className:`tw-rail-workspace-name`,children:Kt($o,ts)})]}),(Jn||Xn)&&(0,Q.jsx)(`div`,{className:`text-[11px] text-(--tw-accent)`,children:Xn??R(`tool.running`,void 0,Kn.language)})]})]}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex flex-col flex-1 ${Ce?`hidden`:``}`,children:[Ro?null:(0,Q.jsxs)(`div`,{className:`shrink-0 border-b border-(--tw-border) bg-(--tw-surface-page)`,children:[(0,Q.jsx)(`div`,{className:`flex items-center gap-3 px-6 pt-4 pb-2 min-w-0`,children:(0,Q.jsx)(`button`,{type:`button`,"data-hint":`点击重命名`,onClick:()=>{let e=a?.activeId;e&&Oo(e)},className:`min-w-0 flex-1 text-left text-[18px] leading-7 font-semibold text-(--tw-label-primary) truncate hover:text-[#4176e6] transition-colors`,children:a?.sessions.find(e=>e.id===a.activeId)?.title||`新对话`})}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-6 px-6`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>Gn(`dialog`),className:`relative h-10 text-sm transition-colors ${Wn===`dialog`?`text-[#4176e6] font-medium`:`text-stone-500 hover:text-stone-700`}`,children:[`对话`,Wn===`dialog`&&(0,Q.jsx)(`span`,{className:`absolute left-0 right-0 -bottom-px h-0.5 bg-[#4176e6] rounded-full`})]}),(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>Gn(`thread`),className:`relative h-10 text-sm transition-colors ${Wn===`thread`?`text-[#4176e6] font-medium`:`text-stone-500 hover:text-stone-700`}`,children:[`回合`,Wn===`thread`&&(0,Q.jsx)(`span`,{className:`absolute left-0 right-0 -bottom-px h-0.5 bg-[#4176e6] rounded-full`})]}),B.todos&&(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>Gn(`todos`),className:`relative h-10 text-sm transition-colors ${Wn===`todos`?`text-[#4176e6] font-medium`:`text-stone-500 hover:text-stone-700`}`,children:[`待办`,Wn===`todos`&&(0,Q.jsx)(`span`,{className:`absolute left-0 right-0 -bottom-px h-0.5 bg-[#4176e6] rounded-full`})]}),B.memory&&(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>Gn(`memory`),className:`relative h-10 text-sm transition-colors ${Wn===`memory`?`text-[#4176e6] font-medium`:`text-stone-500 hover:text-stone-700`}`,children:[(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[`记忆`,(bn?.suggestionCount??0)>0?(0,Q.jsx)(`span`,{className:`min-w-4.5 h-4.5 px-1 inline-flex items-center justify-center rounded-full bg-red-500 text-[10px] font-medium text-white tabular-nums leading-none`,"data-hint":`${bn?.suggestionCount} 条待确认`,children:bn.suggestionCount>99?`99+`:bn.suggestionCount}):null]}),Wn===`memory`&&(0,Q.jsx)(`span`,{className:`absolute left-0 right-0 -bottom-px h-0.5 bg-[#4176e6] rounded-full`})]})]}),$r&&$r.status!==`cleared`&&Wn===`dialog`?(0,Q.jsx)(`div`,{className:`px-6 pb-2`,children:(0,Q.jsxs)(`div`,{className:`rounded-xl border border-[#4176e6]/25 bg-[#f5f8ff] px-3 py-2 flex items-start gap-2`,children:[(0,Q.jsxs)(`span`,{className:`text-[11px] font-medium text-[#4176e6] shrink-0 pt-0.5`,children:[`目标`,$r.status===`done`?`·完成`:``]}),(0,Q.jsx)(`span`,{className:`flex-1 min-w-0 text-[12px] leading-5 ${$r.status===`done`?`text-stone-400 line-through`:`text-stone-800`}`,children:$r.text}),(0,Q.jsx)(`button`,{type:`button`,"data-hint":`清除目标`,className:`text-[11px] text-stone-400 hover:text-stone-600 shrink-0`,onClick:()=>{ti.current=null,ei(null),ni.current=0,K.current&&q(Re(K.current,{goal:void 0}))},children:`清除`})]})}):null,Zr.length>0&&Wn===`dialog`?(0,Q.jsx)(`div`,{className:`px-6 pb-3`,children:(0,Q.jsxs)(`div`,{className:`rounded-xl border border-stone-200 bg-white px-3 py-2.5`,children:[(0,Q.jsxs)(`div`,{className:`text-[11px] font-medium text-stone-500 mb-1.5`,children:[`待办 · `,Zr.filter(e=>e.status===`completed`).length,`/`,Zr.length]}),(0,Q.jsx)(`ul`,{className:`space-y-1 max-h-28 overflow-y-auto`,children:Zr.map((e,t)=>(0,Q.jsxs)(`li`,{className:`flex items-start gap-2 text-[12px] text-stone-700`,children:[(0,Q.jsx)(`span`,{className:`mt-0.5 w-3.5 h-3.5 rounded-sm border shrink-0 flex items-center justify-center text-[9px] ${e.status===`completed`?`bg-emerald-500 border-emerald-500 text-white`:e.status===`in_progress`?`border-[#4176e6] text-[#4176e6]`:`border-stone-300 text-transparent`}`,"aria-hidden":!0,children:e.status===`completed`?`✓`:e.status===`in_progress`?`…`:``}),(0,Q.jsx)(`span`,{className:e.status===`completed`?`line-through text-stone-400`:``,children:e.content})]},`${t}-${e.content}`))})]})}):null]}),Wn===`todos`&&B.todos?(0,Q.jsx)(`div`,{className:`flex-1 min-h-0 bg-(--tw-surface-page) tw-pane-enter`,children:(0,Q.jsx)(Id,{})},`todos-${a?.activeId??``}`):Wn===`memory`&&B.memory?(0,Q.jsx)(`div`,{className:`flex-1 min-h-0 bg-(--tw-surface-page) tw-pane-enter`,children:(0,Q.jsx)(Ed,{live:Ar,pluginOn:!!B.memory,workspacePath:a?.sessions.find(e=>e.id===a.activeId)?.workspacePath||V?.projectRoot||``})},`memory-${a?.activeId??``}`):Wn===`thread`?(0,Q.jsx)(`div`,{className:`flex-1 min-h-0 bg-(--tw-surface-page) tw-pane-enter overflow-y-auto px-12 sm:px-16 lg:px-20 py-6`,children:(0,Q.jsx)(ap,{messages:s,busy:!!(a?.activeId&&Tt.includes(a.activeId)),onRestoreCheckpoint:(e,t)=>{let n=K.current?.activeId;if(!n)return;if(Tt.includes(n)||St){z(`请等待当前回复结束后再从此处继续`);return}let r=Math.max(0,Math.min(e,ua.current.length-1)),i=ua.current.slice(0,r+1);ua.current=i,l(i),K.current&&q(Ve(K.current,i,{touchUpdatedAt:!0}));let a=`请从第 ${t} 轮继续`;Gn(`dialog`),d(a),z(`已回到第 ${t} 轮,正在继续…`,`ok`),window.setTimeout(()=>{Ka(a)},0)}})},`thread-${a?.activeId??``}`):(0,Q.jsxs)(`div`,{className:`relative flex-1 min-h-0 flex flex-col${Ro?` justify-center`:``}`,children:[Ro?(0,Q.jsxs)(`div`,{className:`shrink-0 flex flex-col items-center text-center px-8 sm:px-10 lg:px-12 pb-8`,children:[(0,Q.jsx)(`img`,{src:`/brand/brand-mark.png`,alt:``,width:64,height:64,className:`w-16 h-16 rounded-[14px] object-contain`}),(0,Q.jsx)(`h2`,{className:`mt-5 text-[22px] leading-8 font-semibold tracking-tight text-stone-800 text-balance`,children:R(`chat.emptyTitle`,void 0,Kn.language)})]}):null,Ro?null:(0,Q.jsxs)(`div`,{className:`relative flex-1 min-h-0`,children:[(0,Q.jsx)(`div`,{ref:Ui,onScroll:Oa,className:`h-full overflow-y-auto px-8 sm:px-10 lg:px-12 py-6`,style:{fontSize:`var(--tw-session-font-size, ${Kn.sessionFontSize}px)`},children:(0,Q.jsx)(`div`,{className:`w-full max-w-[min(64rem,100%)] mx-auto flex flex-col gap-4`,onClick:Lo,children:s.map((e,n)=>e.role===`user`?(0,Q.jsxs)(`div`,{className:`group flex flex-col items-end gap-1`,children:[e.refs?.length||e.attachments?.length||e.images?.length?(0,Q.jsxs)(`div`,{className:`flex flex-wrap justify-end gap-1.5 max-w-[82%]`,children:[e.refs?.map(e=>(0,Q.jsxs)(`span`,{className:`flex items-center gap-1.5 px-2.5 py-1.5 text-xs text-[#4176e6] bg-white border border-[#4176e6]/30 rounded-lg`,"data-hint":e.path,children:[(0,Q.jsx)(wf,{className:`w-3.5 h-3.5`}),(0,Q.jsx)(`span`,{className:`text-[10px] text-stone-400 shrink-0`,children:Bu(e.format)}),(0,Q.jsx)(`span`,{className:`max-w-40 truncate`,children:e.title})]},e.path)),e.attachments?.map(e=>(0,Q.jsxs)(`span`,{className:`flex items-center gap-1.5 px-2.5 py-1.5 text-xs text-stone-600 bg-white border border-stone-200 rounded-lg`,children:[(0,Q.jsx)(wf,{className:`w-3.5 h-3.5 text-[#4176e6]`}),(0,Q.jsx)(`span`,{className:`max-w-48 truncate`,children:e.name}),(0,Q.jsx)(`span`,{className:`text-stone-400`,children:Xf(e.size)})]},e.name)),e.images?.map(e=>(0,Q.jsx)(`a`,{href:e.dataUrl,target:`_blank`,rel:`noreferrer`,className:`block overflow-hidden rounded-lg border border-stone-200 bg-white`,"data-hint":e.name,children:(0,Q.jsx)(`img`,{src:e.dataUrl,alt:e.name,className:`max-h-40 max-w-48 object-contain`})},e.id))]}):null,e.content&&(0,Q.jsx)(`div`,{className:`tw-chat-text max-w-[82%] px-4 py-2.5 bg-[#edf3fe] rounded-2xl whitespace-pre-wrap break-words`,children:e.content}),(0,Q.jsxs)(`div`,{className:`tw-msg-actions ${Ho(n)}`,children:[e.time!=null&&(0,Q.jsx)(`span`,{className:`tw-msg-action-time pr-0.5`,children:Zf(e.time)}),(0,Q.jsx)($f,{text:e.content})]})]},n):(0,Q.jsxs)(`div`,{className:`group`,children:[e.turnStatus===`stopped`?(0,Q.jsxs)(`div`,{className:`mb-2`,children:[(0,Q.jsx)(`div`,{className:`text-[13px] text-stone-500 py-1`,children:`已停止`}),(0,Q.jsx)(`div`,{className:`border-t border-stone-200/80`})]}):null,(()=>{let t=e.activitySteps??[],r=t.some(e=>e.status===`running`),i=n===s.length-1&&e.turnStatus!==`stopped`&&(St||r),a=i&&!e.content,o=t.filter(e=>e.kind!==`thinking`);if(!(a||e.reasoning||o.length>0||t.length>0))return null;let c=e.reasoningOpen??!1,l=i||c||r,u=a&&!c&&!l&&e.reasoning?gf(e.reasoning).replaceAll(`**`,``):``;return(0,Q.jsxs)(`div`,{className:`mb-2`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:e=>$a(n,e),className:`flex w-full items-center gap-2 py-1 text-left select-none`,children:[a||i&&!e.content?(0,Q.jsx)(`span`,{className:`w-3.5 h-3.5 shrink-0 rounded-full border-2 border-purple-400 border-t-transparent animate-spin`}):(0,Q.jsxs)($,{className:`w-3.5 h-3.5 shrink-0 text-stone-400`,children:[(0,Q.jsx)(`path`,{d:`M15 14c.2-1 .7-1.7 1.5-2.5 1-.9 1.5-2.2 1.5-3.5A6 6 0 0 0 6 8c0 1 .2 2.2 1.5 3.5.7.7 1.3 1.5 1.5 2.5`}),(0,Q.jsx)(`path`,{d:`M9 18h6`}),(0,Q.jsx)(`path`,{d:`M10 22h4`})]}),(0,Q.jsx)(`span`,{className:`text-[13px] font-medium shrink-0 ${i&&!e.content?`text-shimmer`:`text-shimmer-static`}`,children:i&&!e.content?t.some(e=>e.kind!==`thinking`&&e.status===`running`)?`正在分析请求`:`思考中…`:i?`正在生成…`:e.turnStatus===`stopped`?`已完成分析`:`思考完成`}),!i&&e.reasoningDuration!=null&&(0,Q.jsxs)(`span`,{className:`text-xs text-stone-400 shrink-0`,children:[`用时 `,e.reasoningDuration,`s`]}),(0,Q.jsx)(vf,{className:`w-3.5 h-3.5 shrink-0 text-stone-400 transition-transform ${c?`rotate-180`:``}`}),u?(0,Q.jsx)(`span`,{className:`flex-1 min-w-0 truncate text-xs text-shimmer-muted think-mask`,children:u}):null]}),l&&t.length>0?(0,Q.jsx)(`ul`,{className:`mt-1.5 mb-1 pl-5.5 space-y-1.5`,children:t.map(e=>(0,Q.jsxs)(`li`,{className:`text-[12px] flex items-start gap-2 min-w-0 ${e.status===`error`?`text-red-600`:e.status===`running`?`text-stone-600`:`text-stone-500`}`,children:[(0,Q.jsx)(mf,{kind:e.kind,status:e.status}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1 leading-5`,children:[(0,Q.jsx)(`span`,{className:`font-medium ${e.status===`running`?`text-shimmer`:``}`,children:e.title}),e.detail?(0,Q.jsxs)(`span`,{className:`text-stone-400`,children:[` · `,(0,Q.jsx)(`span`,{className:e.status===`error`?`text-red-600`:e.status===`running`?`text-shimmer-muted`:``,"data-hint":e.detail,children:e.detail.length>72?`${e.detail.slice(0,72)}…`:e.detail})]}):e.status===`running`?(0,Q.jsxs)(`span`,{className:`text-stone-400 text-shimmer-muted`,children:[` · `,`…`]}):null]})]},e.id))}):null,c&&e.reasoning?(0,Q.jsx)(`div`,{className:`mt-1.5 mb-2 pl-5.5 text-[13px] leading-5 text-stone-500 whitespace-pre-wrap max-h-80 overflow-y-auto`,children:e.reasoning}):null,e.turnStatus===`stopped`?(0,Q.jsx)(`div`,{className:`mt-1.5 pl-5.5`,children:(0,Q.jsx)(`span`,{className:`tw-turn-stopped-pill`,children:`已停止`})}):null]})})(),e.content?(0,Q.jsx)(`div`,{className:`chat-md prose prose-sm prose-stone max-w-none tw-chat-text`,dangerouslySetInnerHTML:{__html:Go(e.content)}}):null,e.caseFile?(0,Q.jsxs)(`button`,{type:`button`,"data-focus-doc":`cases:${e.caseFile.path.replace(/\\/g,`/`)}`,"data-hint":`双击本地打开`,onDoubleClick:()=>{ve(`cases`,e.caseFile.path).catch(e=>z(e instanceof Error?e.message:String(e)))},className:`mt-3 w-full max-w-md flex items-center gap-3 rounded-xl border border-stone-200 bg-white px-3 py-2.5 text-left hover:border-[#4176e6] hover:bg-[#f5f8ff] transition-colors cursor-pointer`,children:[(0,Q.jsx)(`span`,{className:`w-10 h-10 rounded-lg bg-emerald-50 text-emerald-700 flex items-center justify-center text-[10px] font-semibold shrink-0`,children:e.caseFile.name.split(`.`).pop()?.toUpperCase()||`FILE`}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`span`,{className:`block text-sm text-stone-800 truncate`,children:e.caseFile.name}),(0,Q.jsxs)(`span`,{className:`block text-[11px] text-stone-400 truncate`,children:[xe(`cases`),e.caseFile.path,e.caseFile.count>0?` · ${e.caseFile.count} 条`:``,` · 双击本地打开`]})]})]}):null,e.docsFile?(0,Q.jsxs)(`button`,{type:`button`,"data-focus-doc":`${e.docsFile.root}:${e.docsFile.path.replace(/\\/g,`/`)}`,"data-hint":`点击本地打开`,onClick:()=>{ve(e.docsFile.root,e.docsFile.path).catch(e=>z(e instanceof Error?e.message:String(e)))},className:`mt-3 w-full max-w-md flex items-center gap-3 rounded-xl border border-stone-200 bg-white px-3 py-2.5 text-left hover:border-[#4176e6] hover:bg-[#f5f8ff] transition-colors cursor-pointer`,children:[(0,Q.jsx)(`span`,{className:`w-10 h-10 rounded-lg flex items-center justify-center text-[10px] font-semibold shrink-0 ${e.docsFile.root===`knowledge`?`bg-amber-50 text-amber-800`:`bg-sky-50 text-sky-700`}`,children:e.docsFile.name.split(`.`).pop()?.toUpperCase()||`MD`}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`span`,{className:`block text-sm text-stone-800 truncate`,children:e.docsFile.name}),(0,Q.jsxs)(`span`,{className:`block text-[11px] text-stone-400 truncate`,children:[xe(e.docsFile.root),e.docsFile.path,e.docsFile.note?` · ${e.docsFile.note}`:``,` · 点击打开`]})]})]}):null,e.presentFiles?.length?e.presentFiles.map(e=>(0,Q.jsxs)(`button`,{type:`button`,"data-hint":`点击本地打开`,onClick:()=>{Mt(e.path,ln).catch(e=>z(e instanceof Error?e.message:String(e)))},className:`mt-3 w-full max-w-md flex items-center gap-3 rounded-xl border border-stone-200 bg-white px-3 py-2.5 text-left hover:border-[#4176e6] hover:bg-[#f5f8ff] transition-colors cursor-pointer`,children:[(0,Q.jsx)(`span`,{className:`w-10 h-10 rounded-lg bg-violet-50 text-violet-700 flex items-center justify-center text-[10px] font-semibold shrink-0`,children:e.name.split(`.`).pop()?.toUpperCase()||`FILE`}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`span`,{className:`block text-sm text-stone-800 truncate`,children:e.name}),(0,Q.jsxs)(`span`,{className:`block text-[11px] text-stone-400 truncate`,children:[e.path,e.description?` · ${e.description}`:``,` · 点击打开`]})]})]},e.path)):null,e.content&&!(n===s.length-1&&St)?(0,Q.jsxs)(`div`,{className:`tw-msg-actions mt-1 ${Ho(n)}`,children:[(0,Q.jsx)($f,{text:e.content}),e.usage&&(0,Q.jsx)(sp,{usage:e.usage,model:e.model??t?.model}),e.time!=null&&(0,Q.jsx)(`span`,{className:`tw-msg-action-time`,children:Zf(e.time)})]}):null]},n))})}),dn&&(0,Q.jsx)(`button`,{type:`button`,onClick:ka,"data-hint":`回到底部`,className:`absolute bottom-3 right-8 sm:right-10 lg:right-12 w-8 h-8 rounded-full bg-white border border-stone-200 shadow-md flex items-center justify-center text-stone-500 hover:text-stone-800 transition-colors`,children:(0,Q.jsx)(vf,{className:`w-4 h-4`})})]},`dialog-${a?.activeId??``}`),Rt&&(0,Q.jsx)(`div`,{className:`shrink-0 px-8 sm:px-10 lg:px-12 pb-2`,children:(0,Q.jsxs)(`div`,{ref:Yi,className:`w-full max-w-[min(64rem,100%)] mx-auto flex items-start gap-3 px-4 py-3 rounded-xl text-sm border ${nn===`ok`?`tw-notice-anim`:``} ${nn===`ok`?`bg-emerald-50 border-emerald-200 text-emerald-900`:`bg-red-50 border-red-200 text-red-800`}`,children:[(0,Q.jsx)(`span`,{className:`mt-0.5 w-5 h-5 shrink-0 rounded-full flex items-center justify-center text-xs font-semibold ${nn===`ok`?`bg-emerald-100 text-emerald-700`:`bg-red-100 text-red-600`}`,children:nn===`ok`?`i`:`!`}),(0,Q.jsx)(`pre`,{className:`flex-1 min-w-0 m-0 font-sans text-[13px] leading-5 whitespace-pre-wrap break-words`,children:Rt.replace(/\*\*/g,``).replace(/\s*:\s*\*\*/g,`: `).trim()}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>z(null),className:`shrink-0 text-xs ${nn===`ok`?`text-emerald-500 hover:text-emerald-700`:`text-red-400 hover:text-red-600`}`,children:`关闭`})]})}),(0,Q.jsxs)(`div`,{className:`shrink-0 px-8 sm:px-10 lg:px-12 pb-5`,children:[(0,Q.jsxs)(`div`,{className:`w-full max-w-[min(64rem,100%)] mx-auto`,children:[M?.active&&B.promptGen?(0,Q.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 px-3 py-2 rounded-xl border border-[#4176e6]/30 bg-[#edf3fe] text-xs text-[#3565c7]`,children:[(0,Q.jsxs)(`span`,{className:`flex-1 min-w-0 truncate`,children:[`生成提示词已启用 · `,ss(M)]}),(0,Q.jsx)(`button`,{type:`button`,className:`shrink-0 hover:underline`,onClick:()=>j(!0),children:`改配置`}),(0,Q.jsx)(`button`,{type:`button`,className:`shrink-0 text-stone-500 hover:text-stone-800`,onClick:()=>io(null),children:`取消`})]}):null,le?.active&&B.knowledgeGen?(0,Q.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 px-3 py-2 rounded-xl border border-amber-300/60 bg-amber-50 text-xs text-amber-900`,children:[(0,Q.jsxs)(`span`,{className:`flex-1 min-w-0 truncate`,children:[`生成知识库已启用 · `,xs(le)]}),(0,Q.jsx)(`button`,{type:`button`,className:`shrink-0 hover:underline`,onClick:()=>N(!0),children:`改配置`}),(0,Q.jsx)(`button`,{type:`button`,className:`shrink-0 text-stone-500 hover:text-stone-800`,onClick:()=>ao(null),children:`取消`})]}):null,re?.active&&B.caseGen?(0,Q.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 px-3 py-2 rounded-xl border border-[#4176e6]/30 bg-[#edf3fe] text-xs text-[#3565c7]`,children:[(0,Q.jsxs)(`span`,{className:`flex-1 min-w-0 truncate`,children:[`生成测试用例已启用 · `,Ko(re)]}),(0,Q.jsx)(`button`,{type:`button`,className:`shrink-0 hover:underline`,onClick:()=>D(!0),children:`改配置`}),(0,Q.jsx)(`button`,{type:`button`,className:`shrink-0 text-stone-500 hover:text-stone-800`,onClick:()=>ro(null),children:`取消`})]}):null,Cr.length>0?(0,Q.jsx)(`div`,{className:`mb-2 rounded-xl border border-stone-200/80 bg-stone-100/80 overflow-hidden`,children:Cr.map(e=>(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 border-b border-stone-200/60 last:border-b-0`,children:[(0,Q.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-stone-400 shrink-0`,"aria-hidden":!0}),(0,Q.jsx)(`span`,{className:`flex-1 min-w-0 truncate text-[13px] text-stone-700`,children:Hi(e)}),(0,Q.jsx)(`button`,{type:`button`,"data-hint":`编辑回输入框`,onClick:()=>Xa(e.id),className:`tw-icon-btn w-7 h-7 rounded-md flex items-center justify-center outline-none`,children:(0,Q.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Q.jsx)(`path`,{d:`M12 20h9`}),(0,Q.jsx)(`path`,{d:`M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z`})]})}),(0,Q.jsx)(`button`,{type:`button`,"data-hint":`从队列移除`,onClick:()=>Ya(e.id),className:`tw-icon-btn w-7 h-7 rounded-md flex items-center justify-center outline-none`,children:(0,Q.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Q.jsx)(`path`,{d:`M3 6h18`}),(0,Q.jsx)(`path`,{d:`M8 6V4h8v2`}),(0,Q.jsx)(`path`,{d:`M19 6l-1 14H6L5 6`})]})}),(0,Q.jsx)(`button`,{type:`button`,"data-hint":`插话立即发送(其后队列仍会续发)`,onClick:()=>Za(e.id),className:`tw-icon-btn w-7 h-7 rounded-md flex items-center justify-center outline-none text-[#4176e6]`,children:(0,Q.jsx)(Ef,{className:`w-3.5 h-3.5`})})]},e.id))}):null,ui?(0,Q.jsxs)(`div`,{className:`mb-2 rounded-xl border border-amber-300/60 bg-amber-50/90 px-4 py-3 shadow-sm`,children:[(0,Q.jsx)(`div`,{className:`text-[13px] font-medium text-stone-800 mb-1`,children:`待批准计划`}),(0,Q.jsx)(`div`,{className:`text-[14px] font-medium text-stone-900`,children:ui.title}),ui.summary?(0,Q.jsx)(`p`,{className:`mt-1 text-[13px] text-stone-600 leading-5`,children:ui.summary}):null,(0,Q.jsx)(`ol`,{className:`mt-2 list-decimal pl-5 space-y-1 text-[13px] text-stone-700`,children:ui.steps.map((e,t)=>(0,Q.jsx)(`li`,{children:e},`${t}-${e.slice(0,24)}`))}),(0,Q.jsxs)(`div`,{className:`mt-3 flex items-center justify-end gap-2`,children:[(0,Q.jsx)(`button`,{type:`button`,className:`h-8 px-3 rounded-lg border border-stone-200 bg-white text-[12px] text-stone-600 hover:bg-stone-50`,onClick:()=>uo(),children:`驳回`}),(0,Q.jsx)(`button`,{type:`button`,className:`h-8 px-3 rounded-lg bg-[#4176e6] text-[12px] text-white hover:bg-[#3467d4]`,onClick:()=>lo(),children:`批准实施`})]})]}):null,Ei?(0,Q.jsx)(qd,{kind:Ei.kind,items:Ei.items,manual:Ei.manual,quick:Ei.quick,quickNote:Ei.quickNote,tasksOn:B.tasks,closing:Oi,onConfirm:e=>{Ei.manual?(Fi(null),Ri(Ei.kind,e)):Fi(e)},onCancel:()=>Fi(null)}):null,Ss>0&&ws?(0,Q.jsxs)(`div`,{className:`mb-2 flex max-h-[min(60vh,520px)] flex-col overflow-hidden rounded-2xl border border-stone-200 bg-white shadow-[0_6px_24px_rgba(15,23,42,0.08)]`,children:[(0,Q.jsxs)(`div`,{className:`flex shrink-0 justify-between gap-4 px-5 ${vi?`items-center py-3.5`:`items-start pt-4`}`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`div`,{className:`mb-1 text-[11px] leading-4 text-stone-400`,children:Si?`跳过确认`:ws.header||`模型需要你的确认`}),(0,Q.jsx)(`h3`,{className:`text-[15px] leading-5.5 font-medium text-stone-900`,children:Si?`确认 ${Os.length} 道跳过的题怎么处理`:ws.question})]}),(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[vi?(0,Q.jsx)(`span`,{className:`text-[11px] leading-4 text-stone-400`,children:Si?`已跳过 ${Os.length} 题`:`第 ${Cs+1} 步 / 共 ${Ss} 步`}):null,(0,Q.jsx)(`button`,{type:`button`,"aria-label":vi?`展开问题`:`收起问题`,onClick:()=>yi(e=>!e),className:`grid h-6 w-6 place-items-center rounded-full text-stone-400 outline-none hover:bg-stone-100 hover:text-stone-600`,children:(0,Q.jsx)(vf,{className:`h-4 w-4 transition-transform ${vi?`rotate-180`:``}`})})]})]}),vi?null:Si?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto overscroll-contain px-5 py-2`,children:[(0,Q.jsx)(`p`,{className:`text-[12px] leading-5 text-stone-500`,children:`跳过不算确认,本轮不会开始改代码。留下原因后我只出方案,等你回复「开始实施」。`}),(0,Q.jsx)(`ul`,{className:`mt-2 space-y-1 rounded-lg bg-stone-50 px-3 py-2`,children:Os.map(({q:e,index:t})=>(0,Q.jsxs)(`li`,{className:`text-[12px] leading-5 text-stone-600`,children:[(0,Q.jsxs)(`span`,{className:`text-stone-400`,children:[t+1,`.`]}),` `,e.header?`${e.header} / `:``,e.question,(0,Q.jsx)(`span`,{className:`ml-1 text-stone-400`,children:`— 已跳过`})]},e.id))}),(0,Q.jsx)(`textarea`,{autoFocus:!0,value:wi,onChange:e=>Ti(e.target.value),onKeyDown:e=>{e.key!==`Enter`||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),So())},rows:3,className:`mt-2 w-full resize-none rounded-lg border border-stone-200 px-2.5 py-2 text-[13px] leading-5 outline-none focus:border-[#4176e6]`,placeholder:`为什么跳过这几题?例如:先只做评估,方案我稍后定 / 这几项按你推荐的来`})]}),(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between gap-3 px-5 pt-2 pb-3`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>Co(),className:`h-8 shrink-0 rounded-lg px-2 text-[12px] text-stone-500 outline-none hover:bg-stone-100 hover:text-stone-700`,children:`返回继续回答`}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>So(),className:`h-8 shrink-0 rounded-lg bg-[#4176e6] px-3.5 text-[12px] font-medium text-white hover:bg-[#3467d4]`,children:`提交并继续`})]})]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto overscroll-contain px-3 py-1`,children:[ws.options?.length?(0,Q.jsx)(`div`,{className:`mt-2 flex flex-col gap-0.5`,role:ws.multi_select?`group`:`radiogroup`,children:ws.options.map((e,t)=>{let n=Ts.selected.includes(e.label),r=Zd(e.label);return(0,Q.jsxs)(`button`,{type:`button`,role:ws.multi_select?`checkbox`:`radio`,"aria-checked":n,onClick:()=>ho(ws,e.label,n),className:`flex w-full shrink-0 items-start gap-2 rounded-lg border px-2 py-2 text-left outline-none transition-colors ${n?`border-[#4176e6]/40 bg-[#f2f7ff]`:`border-transparent hover:bg-stone-50`}`,children:[ws.multi_select?(0,Q.jsx)(`span`,{"aria-hidden":`true`,className:`mt-0.5 grid h-4 w-4 shrink-0 place-items-center rounded border ${n?`border-[#4176e6] bg-[#4176e6] text-white`:`border-stone-300 text-transparent`}`,children:(0,Q.jsx)(bf,{className:`h-3 w-3`})}):(0,Q.jsx)(`span`,{"aria-hidden":`true`,className:`mt-0.5 grid h-5 w-5 shrink-0 place-items-center rounded-md text-[11px] font-medium ${n?`bg-[#4176e6] text-white`:`bg-stone-100 text-stone-500`}`,children:t+1}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Q.jsxs)(`span`,{className:`flex flex-wrap items-center gap-x-2 gap-y-0.5`,children:[(0,Q.jsx)(`span`,{className:`text-[13px] leading-5 font-medium text-stone-800`,children:r.label}),r.recommended?(0,Q.jsx)(`span`,{className:`rounded bg-[#edf3fe] px-1 text-[10px] leading-4 font-semibold text-[#4176e6]`,children:`推荐`}):null]}),e.description?(0,Q.jsx)(`span`,{className:`mt-0.5 block text-[12px] leading-4.5 text-stone-400`,children:e.description}):null]})]},`${e.label}-${t}`)})}):(0,Q.jsx)(`div`,{className:`px-1.5 py-2`,children:(0,Q.jsx)(`textarea`,{autoFocus:!0,value:Ts.text,onChange:e=>_o(ws,e.target.value),onKeyDown:e=>{e.key!==`Enter`||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),vo(ws,Ts.text))},rows:2,className:`w-full resize-none rounded-lg border border-stone-200 px-2.5 py-2 text-[13px] leading-5 outline-none focus:border-[#4176e6]`,placeholder:`输入你的回答…`})}),ws.options?.length?(0,Q.jsx)(`div`,{className:`mt-1 px-1.5 pb-1`,children:(0,Q.jsxs)(`div`,{className:`flex items-start gap-2 rounded-lg border border-stone-200 px-2 py-1.5 focus-within:border-[#4176e6]`,children:[(0,Q.jsx)(`span`,{"aria-hidden":`true`,className:`mt-0.5 grid h-4 w-4 shrink-0 place-items-center rounded bg-stone-100 text-[10px] font-medium text-stone-500`,children:`#`}),(0,Q.jsx)(`textarea`,{value:Ts.text,onChange:e=>_o(ws,e.target.value),onKeyDown:e=>{e.key!==`Enter`||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),vo(ws,Ts.text))},rows:1,className:`min-h-5 w-full resize-none bg-transparent text-[13px] leading-5 outline-none`,placeholder:`输入序号选择(如 1${ws.multi_select?` 或 1,3`:``}),也可直接写你的回答`})]})}):null,(0,Q.jsx)(`div`,{className:`px-2 pb-2 pt-1 text-[11px] leading-4 text-stone-400`,children:ws.options?.length?`回车确认这一步;跳过的题会在提交前让你说明原因,不会直接开始实施`:`回车确认;跳过的题会在提交前让你说明原因,不会直接开始实施`})]}),(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between gap-3 px-5 pt-2 pb-3`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Q.jsx)(`button`,{type:`button`,"aria-label":`上一步`,disabled:Cs===0,onClick:()=>go(Cs-1),className:`grid h-6 w-6 place-items-center rounded-full text-stone-400 outline-none hover:bg-stone-100 hover:text-stone-600 disabled:cursor-default disabled:text-stone-200 disabled:hover:bg-transparent`,children:(0,Q.jsx)(yf,{className:`h-4 w-4 rotate-180`})}),(0,Q.jsxs)(`span`,{className:`px-1 text-[12px] font-medium text-stone-500`,children:[`第 `,Cs+1,` 步 / 共 `,Ss,` 步`]}),(0,Q.jsx)(`button`,{type:`button`,"aria-label":`下一步`,disabled:Es,onClick:()=>go(Cs+1),className:`grid h-6 w-6 place-items-center rounded-full text-stone-400 outline-none hover:bg-stone-100 hover:text-stone-600 disabled:cursor-default disabled:text-stone-200 disabled:hover:bg-transparent`,children:(0,Q.jsx)(yf,{className:`h-4 w-4`})})]}),(0,Q.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[bi?(0,Q.jsx)(`span`,{className:`truncate text-[11px] text-rose-500`,children:bi}):null,(0,Q.jsx)(`button`,{type:`button`,onClick:()=>xo(),className:`h-8 shrink-0 rounded-lg px-2 text-[12px] text-stone-500 outline-none hover:bg-stone-100 hover:text-stone-700`,children:`跳过`}),(0,Q.jsx)(`button`,{type:`button`,disabled:!Ds,onClick:()=>Es?bo():go(Cs+1),className:`h-8 shrink-0 rounded-lg bg-[#4176e6] px-3.5 text-[12px] font-medium text-white hover:bg-[#3467d4] disabled:cursor-not-allowed disabled:bg-stone-300`,children:Es?`提交回答`:`下一步`})]})]})]})]}):null,(0,Q.jsxs)(`div`,{ref:Xi,className:`pt-2 rounded-[20px] bg-white border border-stone-200 shadow-[0_4px_20px_rgba(15,23,42,0.06)] transition-shadow focus-within:shadow-[0_4px_24px_rgba(65,118,230,0.14)]`,children:[(S.length>0||f.length>0||_.length>0)&&(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-1.5 px-3 pt-0.5 pb-2`,children:[S.map(e=>(0,Q.jsxs)(`span`,{className:`flex items-center gap-1.5 pl-2.5 pr-1 py-1 text-xs text-[#4176e6] bg-[#edf3fe] border border-[#4176e6]/25 rounded-lg`,"data-hint":e.collection===`workspace`?e.path:`${e.collection}/${e.path}`,children:[(0,Q.jsx)(wf,{className:`w-3.5 h-3.5`}),(0,Q.jsx)(`span`,{className:`text-[10px] text-[#4176e6]/80 shrink-0`,children:e.collection===`workspace`?`工作区`:e.collection===`prompts`||e.collection===`cases`||e.collection===`knowledge`?e.category:Bu(e.format)}),(0,Q.jsx)(`span`,{className:`max-w-48 truncate`,children:e.title}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>C(t=>t.filter(t=>t.collection!==e.collection||t.path!==e.path)),className:`w-5 h-5 flex items-center justify-center rounded text-[#4176e6]/70 hover:text-[#4176e6] hover:bg-white/80`,children:(0,Q.jsxs)($,{className:`w-3 h-3`,children:[(0,Q.jsx)(`path`,{d:`M18 6 6 18`}),(0,Q.jsx)(`path`,{d:`m6 6 12 12`})]})})]},`${e.collection}:${e.path}`)),f.map((e,t)=>(0,Q.jsxs)(`span`,{className:`flex items-center gap-1.5 pl-2.5 pr-1 py-1 text-xs text-[#4176e6] bg-[#edf3fe] border border-[#4176e6]/25 rounded-lg`,"data-hint":e.path||e.name,children:[(0,Q.jsx)(wf,{className:`w-3.5 h-3.5`}),(0,Q.jsx)(`span`,{className:`text-[10px] text-[#4176e6]/80 shrink-0`,children:`文件`}),(0,Q.jsx)(`span`,{className:`max-w-48 truncate`,children:e.name}),(0,Q.jsx)(`button`,{type:`button`,"data-hint":`移除`,onClick:()=>p(e=>e.filter((e,n)=>n!==t)),className:`w-5 h-5 flex items-center justify-center rounded text-[#4176e6]/70 hover:text-[#4176e6] hover:bg-white/80`,children:(0,Q.jsxs)($,{className:`w-3 h-3`,children:[(0,Q.jsx)(`path`,{d:`M18 6 6 18`}),(0,Q.jsx)(`path`,{d:`m6 6 12 12`})]})})]},`${e.name}-${t}`)),_.map(e=>(0,Q.jsxs)(`span`,{className:`relative group inline-flex rounded-lg border border-stone-200 overflow-hidden bg-stone-50`,"data-hint":`${e.name} · ${Xf(e.size)}`,children:[(0,Q.jsx)(`img`,{src:e.dataUrl,alt:e.name,className:`h-14 w-14 object-cover`}),(0,Q.jsx)(`button`,{type:`button`,"data-hint":`移除图片`,onClick:()=>x(t=>t.filter(t=>t.id!==e.id)),className:`absolute top-0.5 right-0.5 w-5 h-5 flex items-center justify-center rounded bg-black/55 text-white hover:bg-black/75`,children:(0,Q.jsxs)($,{className:`w-3 h-3`,children:[(0,Q.jsx)(`path`,{d:`M18 6 6 18`}),(0,Q.jsx)(`path`,{d:`m6 6 12 12`})]})})]},e.id))]}),(0,Q.jsxs)(`div`,{className:`relative`,children:[pr&&!oa&&!ra&&(0,Q.jsx)(`div`,{ref:Ji,className:`tw-composer-menu tw-popover-anim absolute bottom-full left-0 right-0 mb-3 z-40 h-[min(70vh,20rem)] overflow-hidden rounded-xl border border-stone-200 py-2.5 shadow-[0_4px_14px_-4px_rgba(15,23,42,0.08)]`,children:(0,Q.jsxs)(`div`,{className:`tw-dsh-scroll h-full overflow-y-auto overflow-x-hidden`,children:[(0,Q.jsx)(`div`,{className:`px-3 pt-0.5 pb-1.5 text-[11px] font-medium text-stone-400 tracking-wide`,children:`添加`}),(0,Q.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>{_r(!1),Gi.current?.click()},className:`tw-composer-menu-item w-full flex items-center gap-2.5 px-3 py-2 text-left rounded-lg hover:bg-stone-100`,children:[(0,Q.jsx)(Tf,{className:`w-4 h-4 shrink-0 text-stone-500`}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1 text-[13px] text-stone-800`,children:[`文件`,(0,Q.jsx)(`span`,{className:`ml-1.5 text-stone-400 font-normal`,children:`file`})]}),(0,Q.jsx)(`span`,{className:`shrink-0 max-w-[45%] text-right text-[11px] text-stone-400 truncate`,children:`添加本地附件`})]}),(0,Q.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>{_r(!1),Ba()},className:`tw-composer-menu-item w-full flex items-center gap-2.5 px-3 py-2 text-left rounded-lg hover:bg-stone-100`,children:[(0,Q.jsxs)($,{className:`w-4 h-4 shrink-0 text-stone-500`,children:[(0,Q.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`}),(0,Q.jsx)(`circle`,{cx:`12`,cy:`12`,r:`6`}),(0,Q.jsx)(`circle`,{cx:`12`,cy:`12`,r:`2`})]}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1 text-[13px] text-stone-800`,children:[`目标`,(0,Q.jsx)(`span`,{className:`ml-1.5 text-stone-400 font-normal`,children:`goal`})]}),(0,Q.jsx)(`span`,{className:`shrink-0 max-w-[45%] text-right text-[11px] text-stone-400 truncate`,children:`设置或查看长期任务目标`})]}),(0,Q.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>{_r(!1),ii===`off`?Va():fo()},className:`tw-composer-menu-item w-full flex items-center gap-2.5 px-3 py-2 text-left rounded-lg hover:bg-stone-100 ${ii===`planning`?`bg-amber-50`:ii===`approved`?`bg-emerald-50`:``}`,children:[(0,Q.jsxs)($,{className:`w-4 h-4 shrink-0 ${ii===`planning`?`text-amber-800`:ii===`approved`?`text-emerald-800`:`text-stone-500`}`,children:[(0,Q.jsx)(`path`,{d:`M8 6h13`}),(0,Q.jsx)(`path`,{d:`M8 12h13`}),(0,Q.jsx)(`path`,{d:`M8 18h13`}),(0,Q.jsx)(`path`,{d:`M3 6h.01`}),(0,Q.jsx)(`path`,{d:`M3 12h.01`}),(0,Q.jsx)(`path`,{d:`M3 18h.01`})]}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1 text-[13px] text-stone-800`,children:[`计划`,(0,Q.jsx)(`span`,{className:`ml-1.5 text-stone-400 font-normal`,children:`plan`})]}),(0,Q.jsx)(`span`,{className:`shrink-0 max-w-[45%] text-right text-[11px] text-stone-400 truncate`,children:`进入或退出计划模式`})]}),B.todos||B.tasks?(0,Q.jsxs)(Q.Fragment,{children:[B.todos?(0,Q.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>Li(`todo`),className:`tw-composer-menu-item w-full flex items-center gap-2.5 px-3 py-2 text-left rounded-lg hover:bg-stone-100`,children:[(0,Q.jsxs)($,{className:`w-4 h-4 shrink-0 text-stone-500`,children:[(0,Q.jsx)(`path`,{d:`M8 6h13`}),(0,Q.jsx)(`path`,{d:`M8 12h13`}),(0,Q.jsx)(`path`,{d:`M8 18h13`}),(0,Q.jsx)(`path`,{d:`M3 6h.01`}),(0,Q.jsx)(`path`,{d:`M3 12h.01`}),(0,Q.jsx)(`path`,{d:`M3 18h.01`})]}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1 text-[13px] text-stone-800`,children:[`待办`,(0,Q.jsx)(`span`,{className:`ml-1.5 text-stone-400 font-normal`,children:`todo`})]}),(0,Q.jsx)(`span`,{className:`shrink-0 max-w-[45%] text-right text-[11px] text-stone-400 truncate`,children:`手动添加一条待办`})]}):null,B.tasks?(0,Q.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>Li(`task`),className:`tw-composer-menu-item w-full flex items-center gap-2.5 px-3 py-2 text-left rounded-lg hover:bg-stone-100`,children:[(0,Q.jsxs)($,{className:`w-4 h-4 shrink-0 text-stone-500`,children:[(0,Q.jsx)(`path`,{d:`M9 5h10`}),(0,Q.jsx)(`path`,{d:`M9 12h10`}),(0,Q.jsx)(`path`,{d:`M9 19h10`}),(0,Q.jsx)(`path`,{d:`M4 5h.01`}),(0,Q.jsx)(`path`,{d:`M4 12h.01`}),(0,Q.jsx)(`path`,{d:`M4 19h.01`})]}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1 text-[13px] text-stone-800`,children:[`任务`,(0,Q.jsx)(`span`,{className:`ml-1.5 text-stone-400 font-normal`,children:`task`})]}),(0,Q.jsx)(`span`,{className:`shrink-0 max-w-[45%] text-right text-[11px] text-stone-400 truncate`,children:`手动添加一个任务`})]}):null]}):null,aa.length?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`my-1 border-t border-stone-100`}),(0,Q.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>Sr(e=>!e),className:`w-full flex items-center gap-2 px-3 py-1.5 text-left hover:bg-stone-50`,children:[(0,Q.jsx)(`span`,{className:`flex-1 text-[11px] font-medium text-stone-400 tracking-wide`,children:`扩展插件`}),(0,Q.jsx)(vf,{className:`w-3.5 h-3.5 text-stone-400 shrink-0 transition-transform ${xr?`rotate-180`:``}`})]}),xr?aa.map(e=>{let t=e.id===`caseGen`?`case`:e.id===`promptGen`?`prompt`:e.id===`knowledgeGen`?`knowledge`:e.id===`pluginDev`?`dev`:``,n=e.id===`caseGen`?`打开配置后生成用例并写入用例库`:e.id===`promptGen`?`对话生成提示词并写入提示词库`:e.id===`knowledgeGen`?`对话生成规范/方法论并写入知识库`:e.id===`pluginDev`?`输入需求后先评估确认,再开发扩展插件`:``;return(0,Q.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>{_r(!1),Da(e.id)},className:`tw-composer-menu-item w-full flex items-center gap-2.5 px-3 py-2 text-left rounded-lg hover:bg-stone-100`,children:[(0,Q.jsx)(Pf,{className:`w-4 h-4 shrink-0 text-stone-500`}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1 text-[13px] text-stone-800`,children:[e.name,t?(0,Q.jsx)(`span`,{className:`ml-1.5 text-stone-400 font-normal`,children:t}):null]}),n?(0,Q.jsx)(`span`,{className:`shrink-0 max-w-[45%] text-right text-[11px] text-stone-400 truncate`,children:n}):null]},e.id)}):null]}):null,(0,Q.jsx)(`div`,{className:`my-1 border-t border-stone-100`}),(0,Q.jsx)(`div`,{className:`px-3 pt-1 pb-1.5 text-[11px] font-medium text-stone-400 tracking-wide`,children:`指令`}),(0,Q.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>{_r(!1),G.current?z(`请等待当前回复结束后再压缩`):Ga({force:!0}).then(e=>{e&&z(`已压缩上下文`)})},className:`tw-composer-menu-item w-full flex items-center gap-2.5 px-3 py-2 text-left rounded-lg hover:bg-stone-100`,children:[(0,Q.jsx)($,{className:`w-4 h-4 shrink-0 text-stone-500`,children:(0,Q.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`})}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1 text-[13px] text-stone-800`,children:[`压缩`,(0,Q.jsx)(`span`,{className:`ml-1.5 text-stone-400 font-normal`,children:`compact`})]}),(0,Q.jsx)(`span`,{className:`shrink-0 max-w-[45%] text-right text-[11px] text-stone-400 truncate`,children:`压缩以上对话内容`})]}),(0,Q.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>{_r(!1),ko()},className:`tw-composer-menu-item w-full flex items-center gap-2.5 px-3 py-2 text-left rounded-lg hover:bg-stone-100`,children:[(0,Q.jsxs)($,{className:`w-4 h-4 shrink-0 text-stone-500`,children:[(0,Q.jsx)(`path`,{d:`M3 3v18h18`}),(0,Q.jsx)(`path`,{d:`M7 14v4`}),(0,Q.jsx)(`path`,{d:`M12 10v8`}),(0,Q.jsx)(`path`,{d:`M17 6v12`})]}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1 text-[13px] text-stone-800`,children:[`会话统计`,(0,Q.jsx)(`span`,{className:`ml-1.5 text-stone-400 font-normal`,children:`stats`})]}),(0,Q.jsx)(`span`,{className:`shrink-0 max-w-[45%] text-right text-[11px] text-stone-400 truncate`,children:`查看本会话用量摘要`})]})]})}),oa&&(0,Q.jsxs)(`div`,{ref:qi,className:`tw-composer-menu tw-popover-anim absolute bottom-full left-0 right-0 mb-2 mx-2 z-40 max-h-64 overflow-y-auto rounded-xl border border-stone-200 shadow-xl p-1`,children:[(0,Q.jsx)(`div`,{className:`px-3 py-1.5 text-[11px] text-stone-400`,children:`插件`}),aa.map((e,t)=>(0,Q.jsxs)(`button`,{type:`button`,"data-plugin-index":t,onMouseDown:e=>e.preventDefault(),onMouseEnter:()=>be(t),onClick:()=>Da(e.id),className:`tw-composer-menu-item w-full text-left px-3 py-2 rounded-lg transition-colors ${t===_e?`is-active`:``}`,children:[(0,Q.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,Q.jsx)(`div`,{className:`text-[13px] font-medium text-stone-800 flex-1`,children:e.name})}),(0,Q.jsx)(`div`,{className:`mt-0.5 text-xs text-stone-400 line-clamp-2`,children:e.description})]},e.id))]}),ra&&(0,Q.jsx)(`div`,{ref:Ki,className:`tw-composer-menu tw-popover-anim absolute bottom-full left-0 right-0 mb-2 mx-2 z-40 max-h-64 overflow-y-auto rounded-xl border border-stone-200 shadow-xl p-1`,children:na.length===0?(0,Q.jsxs)(`div`,{className:`px-3 py-2 text-xs text-stone-400 space-y-1`,children:[jr?(0,Q.jsx)(`p`,{children:`项目文档:无匹配`}):null,Qi?(0,Q.jsx)(`p`,{children:`工作区:无匹配`}):(0,Q.jsx)(`p`,{children:`工作区:请先在侧栏添加并选择工作区`}),jr?null:(0,Q.jsxs)(`p`,{children:[`「知识库检索」未启用:启用后才能用 @ 引用`,Se(`knowledge`),` / `,Se(`templates`),`文档`]})]}):(0,Q.jsxs)(Q.Fragment,{children:[ea.length>0?(0,Q.jsxs)(`div`,{className:`px-3 py-1.5 text-[11px] font-medium text-stone-400`,children:[`项目文档(`,Se(`knowledge`),` / `,Se(`templates`),`)`]}):null,na.map((e,t)=>{let n=e.doc,r=na[t-1],i=e.section===`workspace`&&r?.section!==`workspace`;return(0,Q.jsxs)(`div`,{children:[i?(0,Q.jsxs)(Q.Fragment,{children:[ea.length>0?(0,Q.jsx)(`div`,{className:`my-1 mx-2 border-t border-stone-200`,role:`separator`}):null,(0,Q.jsx)(`div`,{className:`px-3 py-1.5 text-[11px] font-medium text-stone-400`,children:`工作区`})]}):null,(0,Q.jsxs)(`button`,{type:`button`,"data-mention-index":t,onMouseDown:e=>e.preventDefault(),onClick:()=>wa(n),className:`tw-composer-menu-item w-full text-left px-3 py-2 rounded-lg transition-colors ${t===Zn?`is-active`:``}`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-[13px] text-stone-800`,children:[(0,Q.jsx)(`span`,{className:`text-[11px] px-1.5 py-0.5 rounded bg-stone-100 text-stone-500 shrink-0`,children:n.collection===`knowledge`?Se(`knowledge`):n.collection===`templates`?Se(`templates`):n.format===`dir`?`文件夹`:`文件`}),n.collection===`workspace`?null:(0,Q.jsx)(`span`,{className:`text-[11px] px-1.5 py-0.5 rounded bg-stone-100 text-stone-500 shrink-0`,children:Bu(n.format)}),(0,Q.jsx)(`span`,{className:`truncate font-medium`,children:n.title})]}),(0,Q.jsx)(`div`,{className:`mt-0.5 pl-0 text-xs text-stone-400 truncate`,children:n.collection===`workspace`?n.path:`${n.category}${n.description?` · ${n.description}`:``}`})]})]},`${n.collection}/${n.id}`)}),jr?null:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`my-1 mx-2 border-t border-stone-200`,role:`separator`}),(0,Q.jsx)(`p`,{className:`px-3 py-1.5 text-[11px] text-stone-400`,children:`「知识库检索」未启用:@ 仅引用工作区文件`})]})]})}),(0,Q.jsxs)(`div`,{className:`flex items-start gap-2 px-3`,children:[oi===`goal`?(0,Q.jsxs)(`span`,{className:`tw-composer-mode-chip is-goal`,"data-hint":`会话目标`,children:[(0,Q.jsxs)($,{className:`w-3.5 h-3.5 shrink-0`,children:[(0,Q.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`}),(0,Q.jsx)(`circle`,{cx:`12`,cy:`12`,r:`6`}),(0,Q.jsx)(`circle`,{cx:`12`,cy:`12`,r:`2`})]}),(0,Q.jsx)(`span`,{children:`目标`}),(0,Q.jsx)(`button`,{type:`button`,"aria-label":`取消目标输入`,onClick:()=>si(null),children:(0,Q.jsxs)($,{className:`w-3 h-3`,children:[(0,Q.jsx)(`path`,{d:`M18 6 6 18`}),(0,Q.jsx)(`path`,{d:`m6 6 12 12`})]})})]}):null,oi===`plan`?(0,Q.jsxs)(`span`,{className:`tw-composer-mode-chip is-plan${ii===`approved`?` is-approved`:``}`,"data-hint":ii===`approved`?`计划模式·已批准`:`计划模式·探查中`,children:[(0,Q.jsxs)($,{className:`w-3.5 h-3.5 shrink-0`,children:[(0,Q.jsx)(`path`,{d:`M8 6h13`}),(0,Q.jsx)(`path`,{d:`M8 12h13`}),(0,Q.jsx)(`path`,{d:`M8 18h13`}),(0,Q.jsx)(`path`,{d:`M3 6h.01`}),(0,Q.jsx)(`path`,{d:`M3 12h.01`}),(0,Q.jsx)(`path`,{d:`M3 18h.01`})]}),(0,Q.jsx)(`span`,{children:`计划`}),(0,Q.jsx)(`button`,{type:`button`,"aria-label":`退出计划模式`,onClick:()=>za(),children:(0,Q.jsxs)($,{className:`w-3 h-3`,children:[(0,Q.jsx)(`path`,{d:`M18 6 6 18`}),(0,Q.jsx)(`path`,{d:`m6 6 12 12`})]})})]}):null,oi===`pluginDev`?(0,Q.jsxs)(`span`,{className:`tw-composer-mode-chip is-plugin-dev`,children:[(0,Q.jsxs)($,{className:`w-3.5 h-3.5 shrink-0`,children:[(0,Q.jsx)(`path`,{d:`M9 7V3`}),(0,Q.jsx)(`path`,{d:`M15 7V3`}),(0,Q.jsx)(`path`,{d:`M6 7h12v4a6 6 0 0 1-12 0V7Z`}),(0,Q.jsx)(`path`,{d:`M12 17v4`})]}),(0,Q.jsx)(`span`,{children:`插件开发`}),(0,Q.jsx)(`button`,{type:`button`,"aria-label":`退出插件开发`,onClick:()=>za(),children:(0,Q.jsxs)($,{className:`w-3 h-3`,children:[(0,Q.jsx)(`path`,{d:`M18 6 6 18`}),(0,Q.jsx)(`path`,{d:`m6 6 12 12`})]})})]}):null,oi===`reports`?(0,Q.jsxs)(`span`,{className:`tw-composer-mode-chip is-report`,children:[(0,Q.jsxs)($,{className:`w-3.5 h-3.5 shrink-0`,children:[(0,Q.jsx)(`path`,{d:`M14 3v4a1 1 0 0 0 1 1h4`}),(0,Q.jsx)(`path`,{d:`M5 3h9l5 5v13H5z`}),(0,Q.jsx)(`path`,{d:`M8 13h8`}),(0,Q.jsx)(`path`,{d:`M8 17h5`})]}),(0,Q.jsxs)(`span`,{children:[`生成`,nr[ci]]}),(0,Q.jsx)(`button`,{type:`button`,"aria-label":`取消汇报生成`,onClick:()=>za(),children:(0,Q.jsxs)($,{className:`w-3 h-3`,children:[(0,Q.jsx)(`path`,{d:`M18 6 6 18`}),(0,Q.jsx)(`path`,{d:`m6 6 12 12`})]})})]}):null,(0,Q.jsx)(`textarea`,{ref:Wi,value:u,onChange:e=>d(e.target.value),onPaste:Io,onKeyDown:e=>{if(oa&&aa.length){if(e.key===`ArrowDown`){e.preventDefault(),be(e=>(e+1)%aa.length);return}if(e.key===`ArrowUp`){e.preventDefault(),be(e=>(e-1+aa.length)%aa.length);return}if(e.key===`Escape`){e.preventDefault(),fr(!0),ia&&d(u.slice(0,ia.from));return}if(e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing){e.preventDefault();let t=aa[_e]??aa[0];t&&Da(t.id);return}}if(ra&&na.length){if(e.key===`ArrowDown`){e.preventDefault(),$n(e=>(e+1)%na.length);return}if(e.key===`ArrowUp`){e.preventDefault(),$n(e=>(e-1+na.length)%na.length);return}if(e.key===`Escape`){e.preventDefault(),ar(!0),$i&&d(u.slice(0,$i.from));return}if(e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing){e.preventDefault();let t=na[Zn]?.doc;t&&wa(t);return}}if(e.key===`Escape`&&pr)e.preventDefault(),_r(!1);else if(e.key===`Escape`&&($i||ia)){e.preventDefault(),ar(!0),fr(!0);let t=$i?.from??ia?.from;t!=null&&d(u.slice(0,t))}else if(e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing){e.preventDefault();let t=e.metaKey||e.ctrlKey;if(G.current){if(t){let e=u.trim();if(e||f.length>0||_.length>0||S.length>0){let t={id:`q_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,6)}`,content:e,files:[...f],refs:[...S],imgs:[..._]};Ra(),Qa(t)}else zi.current.length&&Qa();return}Ka(void 0,{forceBusy:Pe().busySendBehavior??`queue`})}else Ka()}},rows:1,placeholder:t?Cr.length>0&&St?`Cmd/Ctrl+Enter 插话发送全部排队消息`:jr?`请输入内容,或用 @ 引用文档`:Qi?`请输入内容,或用 @ 引用工作区文件`:`请输入内容(@ 引用文档需先启用「知识库检索」)`:`请先配置模型(左下角「设置」→ 模型)`,className:`tw-chat-input block min-w-0 flex-1 min-h-13 pl-0 pr-2 pt-1.5 pb-0.5 bg-transparent resize-none focus:outline-none placeholder:text-(--tw-label-tertiary)`})]})]}),(0,Q.jsxs)(`div`,{className:`tw-composer-bar flex items-center gap-1.5 px-3 pb-3 pt-3`,children:[(0,Q.jsx)(`button`,{type:`button`,"data-add-menu-btn":!0,"aria-label":ii===`off`?`添加`:ii===`planning`?`添加(计划模式·探查中)`:`添加(计划模式·已批准)`,onClick:()=>{_r(e=>!e),ar(!0),fr(!0)},className:`tw-icon-btn w-8 h-8 shrink-0 rounded-full flex items-center justify-center outline-none focus:outline-none focus-visible:outline-none transition-colors ${pr?`bg-(--tw-session-hover-bg)`:``}`,children:(0,Q.jsxs)($,{className:`w-4 h-4`,children:[(0,Q.jsx)(`path`,{d:`M5 12h14`}),(0,Q.jsx)(`path`,{d:`M12 5v14`})]})}),W&&(0,Q.jsxs)(O,{children:[(0,Q.jsxs)(ne,{title:as?`工作区:${as}`:`选择工作区`,"aria-label":cs?`工作区:${cs}`:`选择工作区`,disabled:Nn,className:`tw-composer-bar-ws group flex items-center gap-1 h-7 shrink-0 max-w-[min(40vw,11rem)] pl-1.5 pr-1 text-[13px] leading-5 font-medium text-stone-600 rounded-md outline-none focus:outline-none focus-visible:outline-none hover:bg-stone-100 data-[open]:bg-stone-100 transition-colors disabled:opacity-50`,children:[(0,Q.jsx)(Df,{className:`w-3.5 h-3.5 shrink-0 text-stone-500`}),(0,Q.jsx)(`span`,{className:`tw-composer-bar-label truncate`,children:cs}),(0,Q.jsx)(vf,{className:`tw-composer-bar-chevron w-3.5 h-3.5 shrink-0 text-stone-400 transition-transform group-data-[open]:rotate-180`})]}),(0,Q.jsxs)(ee,{transition:!0,anchor:{to:`top start`,gap:8},className:`tw-select-menu tw-menu-anim z-50 w-[min(100vw-2rem,16rem)] rounded-xl border border-stone-200 py-1 shadow-xl focus:outline-none`,children:[(V?.items??[]).map(e=>{let t=e.path===as;return(0,Q.jsx)(te,{children:(0,Q.jsxs)(`button`,{type:`button`,disabled:Nn,onClick:()=>void va(e),className:`w-full flex items-center gap-2.5 px-3 py-2 text-left data-[focus]:bg-stone-100 disabled:opacity-50`,children:[(0,Q.jsx)(Df,{className:`w-4 h-4 shrink-0 text-stone-500`}),(0,Q.jsx)(`span`,{className:`flex-1 min-w-0 truncate text-[13px] ${t?`text-stone-900 font-medium`:`text-stone-700`}`,"data-hint":e.path,children:Lt(e,ts)}),t&&(0,Q.jsx)(bf,{className:`w-3.5 h-3.5 shrink-0 text-[#4176e6]`})]})},e.id)}),(V?.items?.length??0)>0&&(0,Q.jsx)(`div`,{className:`my-1 border-t border-stone-100`}),(0,Q.jsx)(te,{children:(0,Q.jsxs)(`button`,{type:`button`,disabled:Nn,onClick:()=>void ya(),className:`w-full flex items-center gap-2.5 px-3 py-2 text-left text-[13px] text-stone-700 data-[focus]:bg-stone-100 disabled:opacity-50`,children:[(0,Q.jsx)(`span`,{className:`w-4 h-4 shrink-0 flex items-center justify-center text-stone-500 text-base leading-none`,children:`+`}),`添加工作区...`]})})]})]}),(0,Q.jsxs)(O,{children:[(0,Q.jsxs)(ne,{title:`访问权限:${Uo.label}`,"aria-label":`访问权限:${Uo.label}`,className:`tw-composer-bar-access group flex items-center gap-1 h-7 shrink-0 max-w-55 pl-2 pr-1 text-[13px] leading-5 font-medium text-stone-600 rounded-md outline-none focus:outline-none focus-visible:outline-none hover:bg-stone-100 data-[open]:bg-stone-100 transition-colors`,children:[(0,Q.jsx)(Vf,{level:ln,className:`w-3.5 h-3.5 shrink-0 text-stone-500`}),(0,Q.jsx)(`span`,{className:`tw-composer-bar-label truncate`,children:Uo.label}),(0,Q.jsx)(`span`,{className:`ml-0.5 w-1.5 h-1.5 rounded-full shrink-0 ${W?`bg-emerald-500`:`bg-stone-300`}`,"data-hint":W?`Runner 在线`:`Runner 离线`}),(0,Q.jsx)(vf,{className:`tw-composer-bar-chevron w-3.5 h-3.5 shrink-0 text-stone-400 transition-transform group-data-[open]:rotate-180`})]}),(0,Q.jsxs)(ee,{transition:!0,anchor:{to:`top start`,gap:8},className:`tw-select-menu tw-menu-anim z-50 w-56 rounded-xl border border-stone-200 p-1 shadow-xl focus:outline-none`,children:[(0,Q.jsx)(`div`,{className:`px-3 py-1.5 text-[11px] text-stone-400`,children:W?`本地文件服务已连接`:`本地文件服务未就绪`}),uf.map(e=>{let t=Wo&&e.value===`readonly`;return(0,Q.jsx)(te,{disabled:t,children:(0,Q.jsxs)(`button`,{type:`button`,disabled:t,onClick:()=>{un(e.value),K.current&&q(Re(K.current,{access:e.value}))},className:`w-full flex items-center gap-2 px-3 py-2 rounded-lg text-left text-[13px] data-[focus]:bg-stone-100 disabled:cursor-not-allowed`,children:[(0,Q.jsx)(Vf,{level:e.value,className:`w-4 h-4 shrink-0 ${t?`text-stone-300`:`text-stone-500`}`}),(0,Q.jsx)(`span`,{className:`flex-1 ${t?`text-stone-400`:ln===e.value?`text-stone-900 font-medium`:`text-stone-700`}`,children:e.label}),t?(0,Q.jsx)(`span`,{className:`text-[11px] text-stone-400`,children:`插件开发需要写入`}):ln===e.value?(0,Q.jsx)(bf,{className:`w-3.5 h-3.5 text-[#4176e6]`}):null]})},e.value)})]})]}),(0,Q.jsx)(`span`,{className:`flex-1`}),(0,Q.jsx)(cp,{settings:t}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{G.current?Ja():Ka()},disabled:!St&&!zo,"aria-label":St?`停止生成`:`发送`,className:`w-8 h-8 shrink-0 rounded-full flex items-center justify-center outline-none focus:outline-none focus-visible:outline-none transition-colors ${St?`bg-stone-200 text-stone-700 hover:bg-stone-300`:`bg-[#4176e6] text-white hover:bg-[#3565c7] disabled:bg-[#a9c3ef] disabled:cursor-not-allowed`}`,children:St?(0,Q.jsx)(`span`,{className:`w-2.5 h-2.5 bg-current rounded-xs`}):(0,Q.jsx)(Ef,{className:`w-4 h-4`})})]})]}),(0,Q.jsx)(op,{messages:s,model:t?.model,systemPromptTokens:Kf(w)})]}),(0,Q.jsx)(`input`,{ref:Gi,type:`file`,multiple:!0,hidden:!0,accept:[...Qu.map(e=>`.${e}`),`image/*`,`text/*`,`application/json`,`application/vnd.openxmlformats-officedocument.spreadsheetml.sheet`,`application/vnd.openxmlformats-officedocument.wordprocessingml.document`,`application/vnd.ms-excel`,`application/msword`].join(`,`),onChange:e=>void Mo(e)})]})]})]}),Ce?(0,Q.jsx)(`div`,{className:`tw-plugins-rail flex-1 min-w-0 min-h-0 self-stretch h-full overflow-hidden flex flex-col`,children:(0,Q.jsx)(on,{embedded:!0})}):null,(0,Q.jsx)(yd,{open:E,initial:re,onClose:()=>D(!1),onConfirm:e=>ro(e)}),(0,Q.jsx)(bd,{open:ae,initial:M,onClose:()=>j(!1),onConfirm:e=>io(e)}),(0,Q.jsx)(xd,{open:ce,initial:le,onClose:()=>N(!1),onConfirm:e=>ao(e)}),(0,Q.jsx)(ir,{open:!!Te,title:`重命名会话`,label:`会话名称`,placeholder:`请输入会话名称`,initialValue:Te?a?.sessions.find(e=>e.id===Te)?.title??``:``,confirmLabel:`保存`,cancelLabel:`取消`,onClose:()=>Ae(null),onConfirm:Ao}),(0,Q.jsx)(ir,{open:!!mt,title:`重命名工作区`,label:`显示名称`,placeholder:`请输入工作区名称`,initialValue:mt?V?.items.find(e=>e.id===mt)?.name??``:``,confirmLabel:`保存`,cancelLabel:`取消`,onClose:()=>ht(null),onConfirm:e=>void Sa(e)}),(0,Q.jsx)(ie,{open:!!Fe,title:`删除会话`,message:Fe?`确定永久删除「${a?.sessions.find(e=>e.id===Fe)?.title??`该会话`}」?此操作不可恢复。`:``,confirmLabel:`删除`,cancelLabel:`取消`,danger:`outline`,onClose:()=>Ie(null),onConfirm:()=>{if(!Fe)return;let e=Fe;Ie(null),To(e)}}),(0,Q.jsx)(ie,{open:!!ft,title:`删除工作区`,message:ft?`将把「${ft.name}」从工作区列表中移除。文件夹与会话记录会保留,其会话将归入项目根工作区。`:``,confirmLabel:`删除工作区`,cancelLabel:`取消`,danger:`outline`,onClose:()=>pt(null),onConfirm:()=>void ba()})]})}export{dp as default};
|
|
276
|
+
`,n);if(o!==-1&&o<=a){let r=e.slice(n,o).trim();r!==``&&(t=r)}if(i===null)return t;n=i.index+i[0].length}}function _f(e,t,n,r){return e===`concise`?r===`running`?R(`tool.running`):null:e===`standard`?R(r===`running`?`tool.callingKind`:`tool.doneKind`,{kind:t}):R(e===`detailed`?r===`running`?`tool.callingNamed`:`tool.doneNamed`:r===`running`?`tool.callingFull`:`tool.doneFull`,{kind:t,name:n})}function $({className:e=``,children:t}){return(0,Q.jsx)(`svg`,{className:e,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:t})}var vf=({className:e=``})=>(0,Q.jsx)($,{className:e,children:(0,Q.jsx)(`path`,{d:`m6 9 6 6 6-6`})}),yf=({className:e=``})=>(0,Q.jsx)($,{className:e,children:(0,Q.jsx)(`path`,{d:`m9 18 6-6-6-6`})}),bf=({className:e=``})=>(0,Q.jsx)($,{className:e,children:(0,Q.jsx)(`path`,{d:`M20 6 9 17l-5-5`})}),xf=({className:e=``})=>(0,Q.jsxs)($,{className:e,children:[(0,Q.jsx)(`rect`,{width:`14`,height:`14`,x:`8`,y:`8`,rx:`2`,ry:`2`}),(0,Q.jsx)(`path`,{d:`M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2`})]}),Sf=({className:e=``})=>(0,Q.jsxs)($,{className:e,children:[(0,Q.jsx)(`ellipse`,{cx:`12`,cy:`5`,rx:`9`,ry:`3`}),(0,Q.jsx)(`path`,{d:`M3 5v14a9 3 0 0 0 18 0V5`}),(0,Q.jsx)(`path`,{d:`M3 12a9 3 0 0 0 18 0`})]}),Cf=({className:e=``})=>(0,Q.jsxs)($,{className:e,children:[(0,Q.jsx)(`path`,{d:`m12 14 4-4`}),(0,Q.jsx)(`path`,{d:`M3.34 19a10 10 0 1 1 17.32 0`})]}),wf=({className:e=``})=>(0,Q.jsxs)($,{className:e,children:[(0,Q.jsx)(`path`,{d:`M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z`}),(0,Q.jsx)(`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`})]}),Tf=({className:e=``})=>(0,Q.jsx)($,{className:e,children:(0,Q.jsx)(`path`,{d:`m16.5 9.4-7.07 7.07a3 3 0 0 1-4.24-4.24l7.07-7.07a2 2 0 1 1 2.83 2.83L8.02 14.1a1 1 0 0 1-1.41-1.41l7.07-7.07`})}),Ef=({className:e=``})=>(0,Q.jsxs)($,{className:e,children:[(0,Q.jsx)(`path`,{d:`m5 12 7-7 7 7`}),(0,Q.jsx)(`path`,{d:`M12 19V5`})]}),Df=({className:e=``,open:t=!1})=>(0,Q.jsx)($,{className:e,children:t?(0,Q.jsx)(Q.Fragment,{children:(0,Q.jsx)(`path`,{d:`m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.55 6A2 2 0 0 1 18.45 20H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.69.9H18a2 2 0 0 1 2 2v2`})}):(0,Q.jsx)(`path`,{d:`M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9l-.81-1.2A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z`})}),Of=({className:e=``,open:t=!1})=>(0,Q.jsx)(`svg`,{className:`${e} tw-arrow ${t?`is-open`:``}`,viewBox:`0 0 12 12`,fill:`currentColor`,"aria-hidden":!0,children:(0,Q.jsx)(`path`,{d:`M4.2 2.4a.75.75 0 0 1 1.2-.57l4.2 3.35a.75.75 0 0 1 0 1.14l-4.2 3.35A.75.75 0 0 1 4.2 9.1V2.9Z`})}),kf=({className:e=``})=>(0,Q.jsxs)($,{className:e,children:[(0,Q.jsx)(`circle`,{cx:`11`,cy:`11`,r:`8`}),(0,Q.jsx)(`path`,{d:`m21 21-4.3-4.3`})]}),Af=({className:e=``})=>(0,Q.jsxs)($,{className:e,children:[(0,Q.jsx)(`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`}),(0,Q.jsx)(`path`,{d:`M12 8v8`}),(0,Q.jsx)(`path`,{d:`M8 12h8`})]}),jf=({className:e=``,filled:t=!1})=>(0,Q.jsx)($,{className:e,children:t?(0,Q.jsx)(`path`,{fill:`currentColor`,stroke:`none`,d:`M12 2a3 3 0 0 1 3 3v3.5l2.5 2.5V13h-3.5V20l-1.5 2-1.5-2v-7H7.5v-2L10 8.5V5a3 3 0 0 1 3-3Z`}):(0,Q.jsx)(`path`,{d:`M12 17v5M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16h14v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V6a2 2 0 0 0-2-2h-2a2 2 0 0 0-2 2z`})}),Mf=({className:e=``})=>(0,Q.jsxs)($,{className:e,children:[(0,Q.jsx)(`circle`,{cx:`12`,cy:`12`,r:`1`,fill:`currentColor`,stroke:`none`}),(0,Q.jsx)(`circle`,{cx:`5`,cy:`12`,r:`1`,fill:`currentColor`,stroke:`none`}),(0,Q.jsx)(`circle`,{cx:`19`,cy:`12`,r:`1`,fill:`currentColor`,stroke:`none`})]}),Nf=({className:e=``})=>(0,Q.jsxs)($,{className:e,children:[(0,Q.jsx)(`path`,{d:`M4 8h16v11a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V8Z`}),(0,Q.jsx)(`path`,{d:`M8 8V5a1 1 0 0 1 1-1h6a1 1 0 0 1 1 1v3`}),(0,Q.jsx)(`path`,{d:`M10 12h4`})]}),Pf=({className:e=``})=>(0,Q.jsxs)($,{className:e,children:[(0,Q.jsx)(`path`,{d:`M12 22v-5`}),(0,Q.jsx)(`path`,{d:`M9 8V2`}),(0,Q.jsx)(`path`,{d:`M15 8V2`}),(0,Q.jsx)(`path`,{d:`M18 8v5a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V8Z`})]});function Ff(e){let t=Math.max(0,Math.floor((Date.now()-e)/1e3));if(t<60)return`刚刚`;let n=Math.floor(t/60);if(n<60)return`${n}分钟`;let r=Math.floor(n/60);if(r<24)return`${r}小时`;let i=Math.floor(r/24);if(i<30)return`${i}天`;let a=Math.floor(i/30);return a<12?`${a}个月`:`${Math.floor(a/12)}年`}function If(e){let t=Ff(e);return t===`刚刚`?`刚刚`:t.endsWith(`前`)?t:`${t}前`}function Lf({open:e,onToggle:t,onRename:n,onDelete:r}){let i=(0,U.useRef)(null);return(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsx)(`button`,{ref:i,type:`button`,"aria-label":`更多`,onClick:e=>{e.stopPropagation(),t()},className:`w-6 h-6 flex items-center justify-center rounded text-(--tw-label-tertiary) hover:text-(--tw-label-primary) hover:bg-(--tw-session-hover-bg)`,children:(0,Q.jsx)(Mf,{className:`w-3.5 h-3.5`})}),(0,Q.jsxs)(Rf,{open:e,anchorRef:i,dataAttr:`data-ws-menu`,children:[(0,Q.jsxs)(`button`,{type:`button`,className:`w-full flex items-center gap-2 px-3 py-1.5 text-left text-[13px] text-stone-700 hover:bg-stone-50`,onClick:e=>{e.stopPropagation(),n()},children:[(0,Q.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Q.jsx)(`path`,{d:`M12 20h9`}),(0,Q.jsx)(`path`,{d:`M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z`})]}),`重命名`]}),r?(0,Q.jsxs)(`button`,{type:`button`,className:`w-full flex items-center gap-2 px-3 py-1.5 text-left text-[13px] text-red-600 hover:bg-red-50`,onClick:e=>{e.stopPropagation(),r()},children:[(0,Q.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Q.jsx)(`path`,{d:`M3 6h18`}),(0,Q.jsx)(`path`,{d:`M8 6V4h8v2`}),(0,Q.jsx)(`path`,{d:`M19 6l-1 14H6L5 6`})]}),`删除工作区`]}):null]})]})}function Rf({open:e,anchorRef:t,dataAttr:n,children:r}){let[i,a]=(0,U.useState)(null);return(0,U.useLayoutEffect)(()=>{if(!e){a(null);return}let n=()=>{let e=t.current;if(!e)return;let n=e.getBoundingClientRect(),r=n.bottom+200>window.innerHeight-8,i=Math.max(8,Math.min(n.left,window.innerWidth-160-8));a({top:r?n.top-4:n.bottom+4,left:i,openUp:r})};return n(),window.addEventListener(`scroll`,n,!0),window.addEventListener(`resize`,n),()=>{window.removeEventListener(`scroll`,n,!0),window.removeEventListener(`resize`,n)}},[e,t]),!e||!i||typeof document>`u`?null:(0,ar.createPortal)((0,Q.jsx)(`div`,{[n]:``,className:`tw-popover tw-popover-anim z-80 w-40 rounded-xl border border-stone-200 py-1 shadow-lg`,style:{position:`fixed`,top:i.top,left:i.left,transform:i.openUp?`translateY(-100%)`:void 0},children:r}),document.body)}function zf({s:e,nested:t=!1,active:n,menuOpen:r,busy:i,onOpen:a,onRename:o,onToggleMenu:s,onTogglePin:c,onToggleArchive:l,onExport:u,onRemove:d,onRestore:f}){let p=(0,U.useRef)(null),m=(0,U.useRef)(null),h=(0,U.useRef)(null),g=(0,U.useRef)(null),_=(0,U.useRef)(null),v=(0,U.useRef)(null),[y,b]=(0,U.useState)(!1),[x,S]=(0,U.useState)(!1),[C,w]=(0,U.useState)(null);function T(){_.current!=null&&(clearTimeout(_.current),_.current=null)}function E(){v.current!=null&&(clearTimeout(v.current),v.current=null)}function D(){E(),v.current=setTimeout(()=>{S(!1),T()},180)}function ee(){E(),T(),_.current=setTimeout(()=>S(!0),1e3)}let te=e.title.trim()||`新对话`;(0,U.useLayoutEffect)(()=>{let e=h.current,t=g.current;if(!e||!t)return;let n=()=>{t.style.maxWidth=`none`,t.style.overflow=`visible`,t.style.display=`inline-block`;let n=t.scrollWidth;t.style.maxWidth=``,t.style.overflow=``,t.style.display=``;let r=e.clientWidth,i=n>r+1;b(i),i?t.style.setProperty(`--tw-marquee-shift`,`${Math.min(0,r-n-28)}px`):t.style.removeProperty(`--tw-marquee-shift`)};n();let r=typeof ResizeObserver<`u`?new ResizeObserver(n):null;return r?.observe(e),()=>r?.disconnect()},[e.title]),(0,U.useLayoutEffect)(()=>{if(!x||r){w(null);return}let e=()=>{let e=p.current;if(!e)return;let t=e.getBoundingClientRect();w({top:t.top+t.height/2,left:t.right+8})};return e(),window.addEventListener(`scroll`,e,!0),window.addEventListener(`resize`,e),()=>{window.removeEventListener(`scroll`,e,!0),window.removeEventListener(`resize`,e)}},[x,r,e.title]),(0,U.useEffect)(()=>{r&&(T(),E(),S(!1))},[r]);let O=i?`生成中`:`空闲`,ne=!!(e.archived||e.deleted);return(0,Q.jsxs)(`div`,{ref:p,className:`tw-session-row relative ${t?`is-nested`:``} ${n?`is-selected`:``} ${r?`is-menu-open`:``} ${i?`is-busy`:``} ${ne?`opacity-50`:``}`,onMouseLeave:()=>{T(),D()},children:[i?(0,Q.jsx)(`span`,{className:`tw-session-busy-slot`,"data-hint":`生成中`,"aria-label":`生成中`,children:(0,Q.jsx)(`span`,{className:`tw-session-busy-dot`,"aria-hidden":!0})}):null,e.pinned&&!ne?(0,Q.jsx)(`span`,{className:`tw-slot`,"aria-hidden":!0,children:(0,Q.jsx)(jf,{filled:!0,className:`tw-pin-indicator w-3 h-3`})}):null,(0,Q.jsx)(`button`,{ref:h,type:`button`,onClick:a,onDoubleClick:o,onMouseEnter:()=>ee(),onMouseLeave:()=>{T(),D()},className:`tw-session-title text-left outline-none focus:outline-none focus-visible:outline-none ${y?`is-overflow`:``}`,children:(0,Q.jsx)(`span`,{ref:g,className:`tw-session-title-inner`,children:e.title})}),(0,Q.jsx)(`span`,{className:`tw-session-time pr-1`,children:Ff(e.updatedAt)}),(0,Q.jsxs)(`div`,{"data-session-menu":``,className:`tw-row-actions items-center gap-0.5 shrink-0`,onClick:e=>e.stopPropagation(),children:[(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsx)(`button`,{ref:m,type:`button`,"aria-label":`更多`,onClick:s,className:`tw-session-action-btn w-6 h-6 flex items-center justify-center rounded`,children:(0,Q.jsx)(Mf,{className:`w-3.5 h-3.5`})}),(0,Q.jsx)(Rf,{open:r,anchorRef:m,dataAttr:`data-session-menu`,children:e.deleted?(0,Q.jsxs)(Q.Fragment,{children:[f?(0,Q.jsx)(`button`,{type:`button`,className:`w-full flex items-center gap-2 px-3 py-1.5 text-left text-[13px] text-stone-700 hover:bg-stone-50`,onClick:f,children:`恢复会话`}):null,(0,Q.jsx)(`button`,{type:`button`,className:`w-full flex items-center gap-2 px-3 py-1.5 text-left text-[13px] text-red-600 hover:bg-red-50`,onClick:d,children:`永久删除`})]}):(0,Q.jsxs)(Q.Fragment,{children:[!e.archived&&(0,Q.jsxs)(`button`,{type:`button`,className:`w-full flex items-center gap-2 px-3 py-1.5 text-left text-[13px] text-stone-700 hover:bg-stone-50`,onClick:c,children:[(0,Q.jsx)(jf,{filled:!!e.pinned,className:`w-3.5 h-3.5`}),e.pinned?`取消置顶`:`置顶会话`]}),(0,Q.jsxs)(`button`,{type:`button`,className:`w-full flex items-center gap-2 px-3 py-1.5 text-left text-[13px] text-stone-700 hover:bg-stone-50`,onClick:o,children:[(0,Q.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Q.jsx)(`path`,{d:`M12 20h9`}),(0,Q.jsx)(`path`,{d:`M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z`})]}),`重命名`]}),(0,Q.jsxs)(`button`,{type:`button`,className:`w-full flex items-center gap-2 px-3 py-1.5 text-left text-[13px] text-stone-700 hover:bg-stone-50`,onClick:l,children:[(0,Q.jsx)(Nf,{className:`w-3.5 h-3.5`}),e.archived?`取消归档`:`归档会话`]}),(0,Q.jsxs)(`button`,{type:`button`,className:`w-full flex items-center gap-2 px-3 py-1.5 text-left text-[13px] text-stone-700 hover:bg-stone-50`,onClick:u,children:[(0,Q.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Q.jsx)(`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`}),(0,Q.jsx)(`polyline`,{points:`7 10 12 15 17 10`}),(0,Q.jsx)(`line`,{x1:`12`,x2:`12`,y1:`15`,y2:`3`})]}),`导出会话`]}),e.archived?(0,Q.jsxs)(`button`,{type:`button`,className:`w-full flex items-center gap-2 px-3 py-1.5 text-left text-[13px] text-red-600 hover:bg-red-50`,onClick:d,children:[(0,Q.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Q.jsx)(`path`,{d:`M3 6h18`}),(0,Q.jsx)(`path`,{d:`M8 6V4h8v2`}),(0,Q.jsx)(`path`,{d:`M19 6l-1 14H6L5 6`})]}),`永久删除`]}):null]})})]}),!e.deleted&&(0,Q.jsx)(`button`,{type:`button`,"aria-label":e.archived?`取消归档`:`归档会话`,"data-hint":e.archived?`取消归档`:`归档会话`,onClick:l,className:`tw-session-action-btn w-6 h-6 flex items-center justify-center rounded`,children:(0,Q.jsx)(Nf,{className:`w-3.5 h-3.5`})}),!e.archived&&!e.deleted&&(0,Q.jsx)(`button`,{type:`button`,"data-hint":e.pinned?`取消置顶`:`置顶`,onClick:c,className:`tw-session-action-btn w-6 h-6 flex items-center justify-center rounded`,children:(0,Q.jsx)(jf,{filled:!!e.pinned,className:`w-3.5 h-3.5`})})]}),x&&!r&&C&&typeof document<`u`?(0,ar.createPortal)((0,Q.jsxs)(`div`,{className:`tw-session-preview`,role:`tooltip`,style:{position:`fixed`,top:C.top,left:C.left,transform:`translateY(-50%)`},onMouseEnter:()=>{T(),E(),S(!0)},onMouseLeave:()=>D(),children:[(0,Q.jsx)(`div`,{className:`tw-session-preview-title`,children:te}),(0,Q.jsx)(`div`,{className:`tw-session-preview-meta`,children:If(e.updatedAt)}),(0,Q.jsx)(`div`,{className:`tw-session-preview-status ${i?`is-busy`:``}`,children:O})]}),document.body):null]})}var Bf=`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`;function Vf({level:e,className:t=``}){return(0,Q.jsxs)($,{className:t,children:[(0,Q.jsx)(`path`,{d:Bf}),e===`readonly`&&(0,Q.jsx)(`path`,{d:`m9 12 2 2 4-4`}),e===`readwrite`&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`path`,{d:`M9 10h6`}),(0,Q.jsx)(`path`,{d:`M9 14h3`})]}),e===`full`&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`path`,{d:`M12 8v4`}),(0,Q.jsx)(`path`,{d:`M12 16h.01`})]})]})}function Hf(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function Uf(e){return`${e.toLocaleString(`en-US`)} tok`}function Wf(e){let t=e/1e3;if(t<60)return`${Math.round(t*10)/10} 秒`;let n=Math.round(t);return`${Math.floor(n/60)} 分 ${n%60} 秒`}function Gf(e){return e>=99.95?`100`:e>=10?String(Math.round(e)):e.toFixed(1)}function Kf(e){let t=0;for(let n of e)t+=/[\u4e00-\u9fff]/.test(n)?1:.25;return Math.max(1,Math.round(t))}function qf(e){return e.uncachedTokens==null?e.cachedTokens==null?e.promptTokens:Math.max(0,e.promptTokens-e.cachedTokens):e.uncachedTokens}function Jf(e){return e?typeof e.completionTokens==`number`&&e.completionTokens>0?e.completionTokens:typeof e.totalTokens==`number`&&typeof e.promptTokens==`number`?Math.max(0,e.totalTokens-e.promptTokens):typeof e.completionTokens==`number`?Math.max(0,e.completionTokens):0:0}function Yf(e,t){return t<=0?null:e/t*100}function Xf(e){return e>=1024?`${(e/1024).toFixed(1)} KB`:`${e} B`}function Zf(e){let t=new Date(e),n=`${String(t.getHours()).padStart(2,`0`)}:${String(t.getMinutes()).padStart(2,`0`)}`;return t.toDateString()===new Date().toDateString()?n:`${t.getMonth()+1}/${t.getDate()} ${n}`}async function Qf(e){try{return await navigator.clipboard.writeText(e),!0}catch{try{let t=document.createElement(`textarea`);t.value=e,t.style.cssText=`position:fixed;opacity:0`,document.body.appendChild(t),t.select();let n=document.execCommand(`copy`);return document.body.removeChild(t),n}catch{return!1}}}function $f({text:e}){let[t,n]=(0,U.useState)(!1),r=(0,U.useRef)(null);(0,U.useEffect)(()=>()=>{r.current!==null&&window.clearTimeout(r.current)},[]);async function i(){t||await Qf(e)&&(n(!0),r.current=window.setTimeout(()=>n(!1),1e3))}return(0,Q.jsx)(`button`,{type:`button`,onClick:i,"aria-label":t?`已复制`:`复制`,className:`tw-icon-btn tw-msg-action-btn inline-flex items-center justify-center rounded-md transition-colors`,children:t?(0,Q.jsx)(bf,{className:`w-3.5 h-3.5 text-emerald-600`}):(0,Q.jsx)(xf,{className:`w-3.5 h-3.5`})})}function ep({pct:e}){return(0,Q.jsxs)(`svg`,{className:`w-3.5 h-3.5 -rotate-90`,viewBox:`0 0 20 20`,"aria-hidden":`true`,children:[(0,Q.jsx)(`circle`,{cx:`10`,cy:`10`,r:`8`,fill:`none`,stroke:`var(--color-stone-200)`,strokeWidth:`3`}),(0,Q.jsx)(`circle`,{cx:`10`,cy:`10`,r:`8`,fill:`none`,stroke:`#4176e6`,strokeWidth:`3`,strokeLinecap:`round`,strokeDasharray:`${Math.max(e,1)/100*50.27} 50.27`})]})}function tp(){let[e,t]=(0,U.useState)(!1),n=(0,U.useRef)(null),r=(0,U.useRef)(null),[i,a]=(0,U.useState)(null);return(0,U.useEffect)(()=>{if(!e){a(null);return}let t=()=>{let e=n.current,t=r.current;if(!e||!t)return;let i=e.getBoundingClientRect(),o=t.getBoundingClientRect(),s=i.left+i.width/2-o.width/2;s=Math.max(12,Math.min(s,window.innerWidth-o.width-12));let c=i.top-o.height-8;c<12&&(c=i.bottom+8),a({position:`fixed`,left:s,top:c,visibility:`visible`})};a({position:`fixed`,left:0,top:0,visibility:`hidden`});let i=requestAnimationFrame(t);return window.addEventListener(`resize`,t),window.addEventListener(`scroll`,t,!0),()=>{cancelAnimationFrame(i),window.removeEventListener(`resize`,t),window.removeEventListener(`scroll`,t,!0)}},[e]),(0,U.useEffect)(()=>{if(!e)return;let i=e=>{e.key===`Escape`&&t(!1)},a=e=>{let i=e.target;n.current?.contains(i)||r.current?.contains(i)||t(!1)};return document.addEventListener(`keydown`,i),document.addEventListener(`click`,a,!0),()=>{document.removeEventListener(`keydown`,i),document.removeEventListener(`click`,a,!0)}},[e]),{open:e,setOpen:t,rootRef:n,panelRef:r,pos:i}}function np({title:e,titleValue:t,icon:n,children:r}){return(0,Q.jsxs)(`div`,{className:`tw-popover w-[min(320px,calc(100vw-24px))] rounded-2xl border border-stone-200 p-3.5 shadow-xl text-left`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-[13px]`,children:[n,(0,Q.jsx)(`span`,{className:`tw-popover-title font-medium text-stone-800`,children:e}),t!==void 0&&(0,Q.jsx)(`span`,{className:`tw-popover-muted ml-auto text-stone-500 tabular-nums`,children:t})]}),(0,Q.jsx)(`div`,{className:`mt-2.5 mb-2.5 border-t border-stone-100`}),r]})}function rp({rows:e}){return(0,Q.jsx)(`dl`,{className:`grid grid-cols-[1fr_auto] gap-x-6 gap-y-2 text-[13px]`,children:e.filter(e=>!e.hide).map(e=>(0,Q.jsxs)(`div`,{className:`contents`,children:[(0,Q.jsx)(`dt`,{className:`text-stone-500`,children:e.label}),(0,Q.jsx)(`dd`,{className:`text-stone-800 tabular-nums text-right`,children:e.value})]},e.label))})}function ip({label:e,icon:t,ariaLabel:n,title:r,titleValue:i,children:a,variant:o=`pill`}){let{open:s,setOpen:c,rootRef:l,panelRef:u,pos:d}=tp();return(0,Q.jsxs)(`span`,{ref:l,className:`relative inline-flex items-center`,children:[(0,Q.jsxs)(`button`,{type:`button`,"aria-haspopup":`dialog`,"aria-expanded":s,"aria-label":n,onClick:()=>c(!s),className:o===`ghost`?`tw-msg-action-meta inline-flex items-center gap-1 tabular-nums transition-colors ${s?`text-stone-600`:`text-stone-400 hover:text-stone-600`}`:`inline-flex items-center gap-1.5 px-2 py-0.5 rounded-full transition-colors ${s?`bg-stone-200/70 text-stone-600`:`hover:bg-stone-200/60 hover:text-stone-600`}`,children:[t,(0,Q.jsx)(`span`,{className:`leading-none`,children:e})]}),s&&(0,ar.createPortal)((0,Q.jsx)(`div`,{ref:u,role:`dialog`,"aria-label":r,style:d??{position:`fixed`,left:0,top:0,visibility:`hidden`},className:`z-80`,children:(0,Q.jsx)(np,{title:r,titleValue:i,icon:t,children:a})}),document.body)]})}function ap({messages:e,busy:t,onRestoreCheckpoint:n}){let[r,i]=(0,U.useState)(()=>new Set),a=(0,U.useMemo)(()=>Mr(e.map(e=>({role:e.role,content:typeof e.content==`string`?e.content:rf(e),time:e.time}))),[e]);function o(e){i(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}return a.length?(0,Q.jsx)(`ol`,{className:`list-none m-0 p-0 w-full max-w-[min(64rem,100%)] mx-auto space-y-2`,children:a.map(e=>{let i=r.has(e.index),a=!!e.assistantText;return(0,Q.jsxs)(`li`,{className:`rounded-xl border bg-white shadow-sm overflow-hidden ${i?`border-[#4176e6]/35`:`border-stone-200`}`,children:[(0,Q.jsxs)(`div`,{className:`flex items-start gap-1 px-3 py-2.5`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>o(e.index),"aria-expanded":i,className:`min-w-0 flex-1 text-left hover:bg-stone-50/80 rounded-lg -mx-1 px-1 py-0.5 transition-colors`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,Q.jsxs)(`span`,{className:`text-[11px] font-medium text-stone-400 tabular-nums`,children:[`第 `,e.index,` 轮`]}),(0,Q.jsx)(vf,{className:`w-3.5 h-3.5 text-stone-400 ml-auto shrink-0 transition-transform ${i?`rotate-180`:``}`})]}),i?null:(0,Q.jsxs)(`div`,{className:`space-y-1 text-[13px] leading-5`,children:[(0,Q.jsxs)(`p`,{className:`m-0 text-stone-800 truncate`,children:[(0,Q.jsx)(`span`,{className:`text-stone-400 mr-1.5`,children:`用户`}),e.userPreview]}),(0,Q.jsxs)(`p`,{className:`m-0 text-stone-600 truncate`,children:[(0,Q.jsx)(`span`,{className:`text-stone-400 mr-1.5`,children:`助手`}),e.assistantPreview||`(待回复)`]})]})]}),n?(0,Q.jsx)(`button`,{type:`button`,disabled:t||!a,"data-hint":a?`截断到本轮末,填入续写并发送`:`待本轮助手回复完成后可从此处继续`,className:`shrink-0 mt-0.5 text-[11px] text-[#4176e6] hover:underline disabled:opacity-40 disabled:no-underline px-1 whitespace-nowrap`,onClick:()=>n(e.endMessageIndex,e.index),children:`从此处继续`}):null]}),i?(0,Q.jsxs)(`div`,{className:`px-3 pb-3 space-y-2.5 text-[13px] leading-5 border-t border-stone-100 pt-2.5`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`div`,{className:`text-[11px] font-medium text-stone-400 mb-0.5`,children:`用户`}),(0,Q.jsx)(`div`,{className:`whitespace-pre-wrap break-words text-stone-800`,children:e.userText||`—`})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`div`,{className:`text-[11px] font-medium text-stone-400 mb-0.5`,children:`助手`}),e.assistantText?(0,Q.jsx)(`div`,{className:`chat-md prose prose-sm prose-stone max-w-none tw-chat-text`,dangerouslySetInnerHTML:{__html:Go(e.assistantText)}}):(0,Q.jsx)(`div`,{className:`text-stone-400`,children:`(待回复)`})]})]}):null]},e.index)})}):(0,Q.jsx)(`div`,{className:`h-full flex items-center justify-center text-sm text-stone-400`,children:`暂无回合(还没有用户/助手对话)`})}function op({messages:e,model:t,systemPromptTokens:n}){let r=e.filter(e=>e.role===`assistant`&&e.usage);if(!r.length)return null;let i=r[r.length-1],a=e.filter(e=>e.role===`user`).length,o=r.length,s=r.reduce((e,t)=>e+(t.usage?.totalTokens??0),0),c=r.reduce((e,t)=>e+(t.usage?.promptTokens??0),0),l=r.reduce((e,t)=>e+(t.usage?.cachedTokens??0),0),u=r.reduce((e,t)=>e+(t.usage?qf(t.usage):0),0),d=r.reduce((e,t)=>e+(t.usage?.cacheWriteTokens??0),0),f=r.reduce((e,t)=>e+Jf(t.usage),0),p=r.some(e=>e.usage?.cachedTokens!=null),m=p?Yf(l,c):null,h=r.reduce((e,t)=>e+(t.llmMs??0),0),g=r.reduce((e,t)=>e+(t.toolMs??0),0),_=r.map(e=>e.ttftMs).filter(e=>e!=null&&e>0),v=_.length?_.reduce((e,t)=>e+t,0)/_.length:0,y=r.reduce((e,t)=>t.llmMs==null||t.ttftMs==null?e:e+Math.max(0,t.llmMs-t.ttftMs),0),b=r.map(e=>e.tps).filter(e=>e!=null&&e>0),x=b.length?b.reduce((e,t)=>e+t,0)/b.length:void 0,S=y>200&&f>0?f/(y/1e3):x??(i.tps&&i.tps>0?i.tps:void 0),C=t?F[t]:void 0,w=i.usage?.promptTokens??0,T=C?Math.min(100,w/C*100):void 0,E=Math.min(n,w),D=Math.max(0,w-E);return(0,Q.jsxs)(`div`,{className:`flex items-center justify-center gap-1 pt-2 text-xs text-stone-400 tabular-nums select-none`,children:[(0,Q.jsx)(ip,{icon:(0,Q.jsx)(Cf,{className:`w-3.5 h-3.5`}),label:(0,Q.jsxs)(Q.Fragment,{children:[a,` 轮 `,o,` 步`,S?` · ${Math.round(S)} tok/s`:``]}),ariaLabel:`会话统计`,title:`会话统计`,children:(0,Q.jsx)(rp,{rows:[{label:`模型用时`,value:h>0?Wf(h):`—`},{label:`工具调用用时`,value:g>0?Wf(g):`—`},{label:`首 token 平均 (TTFT)`,value:_.length?Wf(v):`—`},{label:`输出速度 (TPS)`,value:S?`${Math.round(S)} tok/s`:`—`}]})}),(0,Q.jsx)(ip,{icon:(0,Q.jsx)(Sf,{className:`w-3.5 h-3.5`}),label:(0,Q.jsxs)(Q.Fragment,{children:[Hf(s),` tok`,m==null?``:` · 缓存命中 ${Gf(m)}%`]}),ariaLabel:`Token 用量`,title:`Token 用量`,titleValue:Uf(s),children:(0,Q.jsx)(rp,{rows:[{label:`缓存命中`,value:m==null?`—`:`${Gf(m)}%`,hide:m==null},{label:`未缓存输入`,value:Uf(u)},{label:`缓存读取`,value:Uf(l),hide:!p},{label:`缓存写入`,value:Uf(d),hide:d<=0},{label:`输出`,value:Uf(f)}]})}),T!==void 0&&C&&(0,Q.jsxs)(ip,{icon:(0,Q.jsx)(ep,{pct:T}),label:`${Gf(T)}%`,ariaLabel:`上下文占用`,title:`上下文已用 ${Gf(T)}%`,titleValue:`~${Hf(w)} / ${Hf(C)}`,children:[(0,Q.jsxs)(`div`,{className:`h-2 rounded-full bg-stone-100 overflow-hidden flex mb-3`,children:[(0,Q.jsx)(`span`,{className:`h-full bg-stone-400`,style:{width:`${E/C*100}%`},"data-hint":`系统提示词`}),(0,Q.jsx)(`span`,{className:`h-full bg-[#4176e6]`,style:{width:`${D/C*100}%`},"data-hint":`对话消息`})]}),(0,Q.jsx)(rp,{rows:[{label:`系统提示词`,value:`~${Hf(E)}`},{label:`对话消息`,value:`~${Hf(D)}`}]}),(0,Q.jsx)(`p`,{className:`mt-2.5 text-[11px] leading-4 text-stone-400`,children:`分段为示意估算(API 不返回上下文拆分);总量以最近一轮 prompt_tokens 为准。`})]})]})}function sp({usage:e,model:t}){let n=e.cachedTokens==null?null:Yf(e.cachedTokens,e.promptTokens);return(0,Q.jsx)(ip,{variant:`ghost`,icon:(0,Q.jsx)(Sf,{className:`w-3.5 h-3.5 shrink-0`}),label:(0,Q.jsxs)(Q.Fragment,{children:[`用量 `,Hf(e.totalTokens),` tok`]}),ariaLabel:`本轮用量`,title:`本轮用量`,titleValue:Uf(e.totalTokens),children:(0,Q.jsx)(rp,{rows:[{label:`提供方 / 模型`,value:t??`—`,hide:!t},{label:`缓存命中`,value:n==null?`—`:`${Gf(n)}%`,hide:n==null},{label:`未缓存输入`,value:Uf(qf(e))},{label:`缓存读取`,value:Uf(e.cachedTokens??0),hide:e.cachedTokens==null},{label:`缓存写入`,value:Uf(e.cacheWriteTokens??0),hide:!(e.cacheWriteTokens&&e.cacheWriteTokens>0)},{label:`输出`,value:Uf(e.completionTokens)}]})})}function cp({settings:e}){let[t,n]=(0,U.useState)(!1),[r,i]=(0,U.useState)(null),[a,o]=(0,U.useState)([]),[s,c]=(0,U.useState)(`idle`),l=(0,U.useRef)(null),u=(0,U.useRef)(0);if((0,U.useEffect)(()=>{if(!t)return;let e=()=>{n(!1),i(null)},r=t=>{l.current?.contains(t.target)||e()},a=t=>{t.key===`Escape`&&e()};return document.addEventListener(`mousedown`,r),document.addEventListener(`keydown`,a),()=>{document.removeEventListener(`mousedown`,r),document.removeEventListener(`keydown`,a)}},[t]),(0,U.useEffect)(()=>{if(!t||!e)return;let n=e.availableModels?.length?e.availableModels:[e.model];o(n),c(e.availableModels?.length?`ok`:`loading`);let r=++u.current;P(e.baseURL,e.apiKey).then(t=>{if(r!==u.current)return;let n=t.length?t:[e.model];o(n),c(`ok`),t.length&&Ae({availableModels:t})}).catch(()=>{r===u.current&&c(n.length>1?`ok`:`fail`)})},[t,e]),!e)return(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>Me(`model`),className:`flex items-center gap-1 h-7 shrink-0 pl-2 pr-1 text-[13px] leading-5 font-medium text-stone-500 rounded-md hover:bg-stone-100 transition-colors`,children:[(0,Q.jsx)(`span`,{className:`whitespace-nowrap`,children:`配置模型`}),(0,Q.jsx)(vf,{className:`w-3.5 h-3.5 shrink-0 text-stone-400`})]});let d=e.reasoningEffort??`high`,f=lf.find(e=>e.value===d)?.label??`High`;function p(e){Ae(e),n(!1),i(null)}let m=e=>`w-full flex items-center gap-3 px-3 py-2 rounded-lg text-left text-[13px] transition-colors ${e?`bg-stone-100`:`hover:bg-stone-100`}`;return(0,Q.jsxs)(`div`,{ref:l,className:`relative`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>{n(e=>!e),i(null)},className:`tw-composer-bar-model group flex items-center gap-1 h-7 shrink-0 pl-2 pr-1 text-[13px] leading-5 font-medium rounded-md outline-none focus:outline-none focus-visible:outline-none transition-colors ${t?`bg-stone-100`:`hover:bg-stone-100`}`,title:`${e.model} · ${f}`,"aria-label":`模型 ${e.model},推理 ${f}`,children:[(0,Q.jsx)(`span`,{className:`tw-composer-bar-model-name max-w-40 truncate text-stone-600`,children:e.model}),(0,Q.jsx)(`span`,{className:`tw-composer-bar-effort whitespace-nowrap text-stone-400`,children:f}),(0,Q.jsx)(vf,{className:`w-3.5 h-3.5 shrink-0 text-stone-400 transition-transform ${t?`rotate-180`:``}`})]}),t&&(0,Q.jsxs)(`div`,{className:`tw-popover tw-popover-anim absolute bottom-full right-0 mb-2 w-64 rounded-xl border border-stone-200 p-1 shadow-xl z-50`,children:[(0,Q.jsxs)(`button`,{type:`button`,onMouseEnter:()=>i(`model`),onClick:()=>i(`model`),className:m(r===`model`),children:[(0,Q.jsx)(`span`,{className:`text-stone-700`,children:`模型`}),(0,Q.jsx)(`span`,{className:`ml-auto max-w-32 truncate text-stone-400`,children:e.model}),(0,Q.jsx)(yf,{className:`w-3.5 h-3.5 text-stone-400`})]}),(0,Q.jsxs)(`button`,{type:`button`,onMouseEnter:()=>i(`effort`),onClick:()=>i(`effort`),className:m(r===`effort`),children:[(0,Q.jsx)(`span`,{className:`text-stone-700`,children:`推理等级`}),(0,Q.jsx)(`span`,{className:`ml-auto text-stone-400`,children:f}),(0,Q.jsx)(yf,{className:`w-3.5 h-3.5 text-stone-400`})]}),r===`model`&&(0,Q.jsxs)(`div`,{className:`tw-popover tw-popover-anim absolute right-full bottom-0 mr-1.5 w-64 max-h-72 overflow-y-auto rounded-xl border border-stone-200 p-1 shadow-xl`,children:[s===`loading`&&a.length<=1&&(0,Q.jsx)(`div`,{className:`px-3 py-2 text-xs text-stone-400`,children:`正在识别可用模型…`}),a.map(t=>(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>p({model:t}),className:m(!1),children:[(0,Q.jsx)(`span`,{className:`flex-1 truncate ${t===e.model?`text-stone-900 font-medium`:`text-stone-600`}`,children:t}),t===e.model&&(0,Q.jsx)(bf,{className:`w-3.5 h-3.5 text-[#4176e6]`})]},t)),(0,Q.jsx)(`div`,{className:`mt-1 border-t border-stone-100 pt-1`,children:(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{n(!1),i(null),Me(`model`)},className:`w-full px-3 py-1.5 rounded-lg text-left text-xs text-stone-400 hover:bg-stone-100`,children:s===`fail`?`识别失败,打开设置检查…`:a.length>1?`打开设置 · 模型…`:`打开设置识别可用模型…`})})]}),r===`effort`&&(0,Q.jsx)(`div`,{className:`tw-popover tw-popover-anim absolute right-full bottom-0 mr-1.5 w-60 rounded-xl border border-stone-200 p-1 shadow-xl`,children:lf.map(e=>(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>p({reasoningEffort:e.value}),className:`w-full px-3 py-2 rounded-lg text-left hover:bg-stone-100 transition-colors`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-[13px]`,children:[(0,Q.jsx)(`span`,{className:`flex-1 ${d===e.value?`text-stone-900 font-medium`:`text-stone-600`}`,children:e.label}),d===e.value&&(0,Q.jsx)(bf,{className:`w-3.5 h-3.5 text-[#4176e6]`})]}),(0,Q.jsx)(`div`,{className:`mt-0.5 text-xs text-stone-400`,children:e.desc})]},e.value))})]})]})}var lp=null;function up(){if(!lp){let e=tt();lp={store:e,messages:e.sessions.find(t=>t.id===e.activeId)?.messages??[]}}return lp}function dp({slashDocs:e=[]}){let[t,n]=(0,U.useState)(null),[r,i]=(0,U.useState)(!1),[a,o]=(0,U.useState)(()=>up().store),[s,l]=(0,U.useState)(()=>up().messages),[u,d]=(0,U.useState)(``),[f,p]=(0,U.useState)([]),[_,x]=(0,U.useState)([]),[S,C]=(0,U.useState)([]),[w,T]=(0,U.useState)(Qd),[E,D]=(0,U.useState)(!1),[re,k]=(0,U.useState)(null),A=(0,U.useRef)(null);A.current=re;let[ae,j]=(0,U.useState)(!1),[M,oe]=(0,U.useState)(null),se=(0,U.useRef)(null);se.current=M;let[ce,N]=(0,U.useState)(!1),[le,ue]=(0,U.useState)(null),de=(0,U.useRef)(null);de.current=le;let[fe,P]=(0,U.useState)(null),me=(0,U.useRef)(null);me.current=fe;let F=(0,U.useRef)(null),[I,ge]=(0,U.useState)(null),[_e,be]=(0,U.useState)(0),[Ce,we]=(0,U.useState)(!1),[Te,Ae]=(0,U.useState)(null),[Fe,Ie]=(0,U.useState)(null),[tt,ut]=(0,U.useState)(null),[ft,pt]=(0,U.useState)(null),[mt,ht]=(0,U.useState)(null),[St,wt]=(0,U.useState)(!1),[Tt,At]=(0,U.useState)([]),[Rt,Ut]=(0,U.useState)(null),[nn,an]=(0,U.useState)(`error`);function z(e,t=`error`){an(t),Ut(e)}let[ln,un]=(0,U.useState)(`readonly`),[dn,fn]=(0,U.useState)(!1),[pn,mn]=(0,U.useState)(!0),[hn,gn]=(0,U.useState)(!1),[B,_n]=(0,U.useState)(()=>h()),[vn,yn]=(0,U.useState)(``),[bn,xn]=(0,U.useState)(null),[Sn,Cn]=(0,U.useState)(null),[wn,Tn]=(0,U.useState)(!1),[En,Dn]=(0,U.useState)(null),[On,kn]=(0,U.useState)(null),[An,jn]=(0,U.useState)(null),[V,Mn]=(0,U.useState)(null),[Nn,Pn]=(0,U.useState)(!1),[Fn,In]=(0,U.useState)({}),[Ln,Rn]=(0,U.useState)(``),[Bn,Vn]=(0,U.useState)(!1),[Hn,Un]=(0,U.useState)(null),[Wn,Gn]=(0,U.useState)(()=>b(nf,tf,`dialog`)),[Kn,qn]=(0,U.useState)(()=>typeof window>`u`?{language:`zh-CN`,appearance:`system`,sessionFontSize:14,toolStepDetail:`standard`,busySendBehavior:`queue`,subagentModel:``}:Pe()),[Jn,Yn]=(0,U.useState)(!1),[Xn,H]=(0,U.useState)(null),[Zn,$n]=(0,U.useState)(0),[rr,ar]=(0,U.useState)(!1),[or,fr]=(0,U.useState)(!1),[pr,_r]=(0,U.useState)(!1),[xr,Sr]=(0,U.useState)(!0),[Cr,wr]=(0,U.useState)([]),[Tr,Dr]=(0,U.useState)([]),Ar=!!(B.memory&&bn?.ok),jr=!!B.knowledge,Mr=!!An?.ok,W=!!Sn?.ok,Pr=wn&&!W,Lr=!!En?.ok,Rr=!!(On?.ok&&On.available),Vr=(0,U.useRef)(null),Hr=(0,U.useRef)(new Map),Ur=(0,U.useRef)(null),Gr=(0,U.useRef)(new Map),Kr=(0,U.useRef)(new Map),qr=(0,U.useRef)(new Map),Jr=(0,U.useRef)(null),G=(0,U.useRef)(!1),Yr=(0,U.useRef)(null),Xr=(0,U.useRef)(null),[Zr,Qr]=(0,U.useState)([]),[$r,ei]=(0,U.useState)(null),ti=(0,U.useRef)(null),ni=(0,U.useRef)(0),ri=(0,U.useRef)(new Set),[ii,ai]=(0,U.useState)(`off`),[oi,si]=(0,U.useState)(null),[ci,li]=(0,U.useState)(`day`),[ui,di]=(0,U.useState)(null),[fi,pi]=(0,U.useState)(null),[mi,hi]=(0,U.useState)({}),[gi,_i]=(0,U.useState)(0),[vi,yi]=(0,U.useState)(!1),[bi,xi]=(0,U.useState)(null),[Si,Ci]=(0,U.useState)(!1),[wi,Ti]=(0,U.useState)(``),[Ei,Di]=(0,U.useState)(null),[Oi,ki]=(0,U.useState)(!1),Ai=(0,U.useRef)(null),ji=(0,U.useRef)(null);function Mi(){ji.current!==null&&(window.clearTimeout(ji.current),ji.current=null)}function Ni(){Mi(),ki(!1)}function Pi(e,t,n={}){return new Promise(r=>{Ai.current?.(null),Ai.current=r,Ni(),Di({kind:e,items:t,quick:n.quick,quickNote:n.quickNote})})}function Fi(e){let t=Ai.current;Ai.current=null,ki(!0),Mi(),ji.current=window.setTimeout(()=>{ji.current=null,Di(null),ki(!1)},160),t?.(e)}let Ii=(0,U.useRef)(()=>{});Ii.current=()=>Fi(null),(0,U.useEffect)(()=>{if(!Ei||Oi)return;let e=e=>{let t=e.target;t instanceof Element&&(t.closest(`.tw-create-card`)||t.closest(`[data-headlessui-portal]`)||t.closest(`.tw-select-menu`)||t.closest(`.tw-date-panel`)||Ii.current())};return document.addEventListener(`pointerdown`,e,!0),()=>document.removeEventListener(`pointerdown`,e,!0)},[Ei,Oi]);function Li(e){_r(!1),B[e===`todo`?`todos`:`tasks`]&&(Ni(),Di({kind:e,manual:!0,items:[Rd(e)]}))}async function Ri(e,t){let n=e===`todo`?`待办`:`任务`;try{e===`todo`?await Qn(t.map(e=>({title:e.title.trim(),status:e.status,priority:e.priority,taskId:e.taskId,linkedTask:e.linkedTask,startDate:e.startDate,dueDate:e.dueDate,note:e.note})),{mode:`manual`}):await zn(t.map(e=>({title:e.title.trim(),status:e.status,priority:e.priority,startDate:e.startDate,dueDate:e.dueDate,note:e.note})),{mode:`manual`}),z(`已新增 ${t.length} 条${n},可在侧栏「${n===`待办`?`待办事项`:`任务管理`}」查看。`,`ok`)}catch(e){an(`error`),z(e instanceof Error?e.message:String(e))}}(0,U.useEffect)(()=>()=>{Ai.current?.(null),Ai.current=null,ji.current!==null&&(window.clearTimeout(ji.current),ji.current=null)},[]);let zi=(0,U.useRef)([]),Bi=(0,U.useRef)(null);function Vi(e){zi.current=e,wr(e)}function Hi(e){let t=e.content.trim().replace(/\s+/g,` `);if(t)return t.length>28?`${t.slice(0,28)}…`:t;let n=e.files.length+e.imgs.length+e.refs.length;return n>0?`附件 ${n} 项`:`(空消息)`}let Ui=(0,U.useRef)(null),Wi=(0,U.useRef)(null),Gi=(0,U.useRef)(null),Ki=(0,U.useRef)(null),qi=(0,U.useRef)(null),Ji=(0,U.useRef)(null),Yi=(0,U.useRef)(null),Xi=(0,U.useRef)(null),Zi=(0,U.useRef)({}),Qi=!!(W&&V?.workspace),$i=Xd(u),ea=(()=>{if(!$i||!jr)return[];let t=$i.query.toLowerCase();return(t?e.filter(e=>Vu(e,t)):e).slice(0,10)})(),ta=(()=>{if(!$i||!Qi)return[];let e=$i.query.toLowerCase(),t=Tr.map(e=>({collection:`workspace`,id:`ws:${e.path}`,title:e.name,category:Kt(V?.workspace,V?.projectRoot),description:e.path,format:e.type===`dir`?`dir`:`file`,path:e.path}));return(e?t.filter(t=>Vu(t,e)||t.path.toLowerCase().includes(e)||t.title.toLowerCase().includes(e)):t).slice(0,10)})(),na=[...ea.map(e=>({section:`project`,doc:e})),...ta.map(e=>({section:`workspace`,doc:e}))],ra=!(!$i||rr),ia=Yd(u),aa=v.filter(e=>e.hasPanel&&B[e.id]),oa=!!(ia&&!or&&!ra&&aa.length>0),sa=(0,U.useRef)(!0),ca=(0,U.useRef)(!1),K=(0,U.useRef)(null),la=(0,U.useRef)(null),ua=(0,U.useRef)([]);ua.current=s,la.current=V;function q(e){K.current=e,o(e),at(e)}let da=a?.sessions.find(e=>e.id===a.activeId),J=da?.id,fa=da?.access;(0,U.useEffect)(()=>{J&&un(fa??je())},[J,fa]),(0,U.useEffect)(()=>{let e=!1,t=Oe(()=>n(ke())),r=m(e=>_n(e)),a=De(e=>{qn(e),Ne(e)});return(async()=>{if(await c(),e)return;let t=Pe();qn(t),Ne(t),n(ke()),un(je()),_n(h()),mn(qe());let r=new URLSearchParams(window.location.search),a=r.get(`session`),s=await it({preferSessionId:a});if(e)return;let u=s;if(a&&!u.sessions.some(e=>e.id===a))try{let e=sessionStorage.getItem($e(a));if(e){let t=JSON.parse(e)?.session;t&&t.id===a&&(u={...u,sessions:[t,...u.sessions.filter(e=>e.id!==a)],activeId:a},await Ze(u))}}catch{}if(a)try{sessionStorage.removeItem($e(a))}catch{}let d=r.get(`focusRoot`),f=r.get(`focusPath`),p=r.get(`attachRoot`),m=r.get(`attachPath`),_=r.get(`attachName`),v=null;if(d&&f)try{v=`${d}:${decodeURIComponent(f).replace(/\\/g,`/`).replace(/^\/+/,``)}`}catch{v=`${d}:${f}`}if(a&&u.sessions.some(e=>e.id===a)&&(u=Be(u,a),at(u)),v&&ge(v),p&&m){let e=p;if(e===`cases`||e===`prompts`||e===`knowledge`||e===`templates`){let t=m,n=_||``;try{t=decodeURIComponent(m).replace(/\\/g,`/`).replace(/^\/+/,``),_&&(n=decodeURIComponent(_))}catch{}n||=t.split(`/`).pop()||t;let r=(n.split(`.`).pop()||`md`).toLowerCase(),i=e===`cases`?`用例`:e===`prompts`?`提示词`:e===`knowledge`?`知识库`:`模板`;C([{collection:e,id:`${e}:${t}`,title:n,category:i,path:t,format:r}])}}let y=r.get(`report`);try{let e=new URL(window.location.href);e.searchParams.delete(`report`),e.searchParams.delete(`session`),e.searchParams.delete(`focusRoot`),e.searchParams.delete(`focusPath`),e.searchParams.delete(`attachRoot`),e.searchParams.delete(`attachPath`),e.searchParams.delete(`attachName`),window.history.replaceState({},``,e.pathname+e.search+e.hash)}catch{}let b=[];try{b=(await cr()).map(e=>e.sessionId)}catch{b=[]}let x=new Set(b);u=x.size?{...u,sessions:u.sessions.map(e=>{if(x.has(e.id))return e;let t=ct(e.messages);return t===e.messages?e:{...e,messages:t}})}:We(u);let S=je();u.sessions.some(e=>!e.access)&&(u={...u,sessions:u.sessions.map(e=>e.access?e:{...e,access:S})}),K.current=u,o(u),at(u);let w=u.sessions.find(e=>e.id===u.activeId);if(l(w?.messages??[]),k(w?.caseGen?.active?w.caseGen:null),oe(w?.promptGen?.active?w.promptGen:null),ue(w?.knowledgeGen?.active?w.knowledgeGen:null),P(w?.pluginDev?.active?w.pluginDev:null),un(w?.access??S),w?.pluginDev?.active&&(si(`pluginDev`),w.access!==`readwrite`&&w.access!==`full`)){un(`readwrite`);let e={...u,sessions:u.sessions.map(e=>e.id===u.activeId?{...e,access:`readwrite`}:e)};K.current=e,o(e),at(e)}Qr($c(w?.todos));{let e=bl(w?.goal);ti.current=e,ei(e)}(y===`day`||y===`week`||y===`month`)&&h().reports&&Ua(y),w?.workspacePath&&In(e=>({...e,[w.workspacePath]:!0})),(w?.messages??[]).length||Gn(`dialog`),At(b),i(!0),b.length&&queueMicrotask(()=>{for(let e of b)Aa(e,!0),e===K.current?.activeId&&(G.current=!0,wt(!0),Na(e,0))});try{let e=new URL(window.location.href),t=e.searchParams.get(`plugin`);if(t===`promptGen`||t===`knowledgeGen`||t===`caseGen`||t===`pluginDev`){let n=t;if(h()[n]){if(n===`pluginDev`)Ha();else{let e=K.current?.sessions.find(e=>e.id===K.current?.activeId);if((!e||e.archived||e.deleted||Array.isArray(e.messages)&&e.messages.length>0||e.caseGen?.active||e.promptGen?.active||e.knowledgeGen?.active)&&K.current){let e=K.current.activeId,t=Ca(e)??K.current,n=V?.workspace?.trim()||void 0,r=et(t,{workspacePath:n,access:je()});K.current=r,o(r),at(r),l([]),k(null),oe(null),ue(null),Qr([]),ti.current=null,ei(null),ai(`off`)}n===`promptGen`?j(!0):n===`knowledgeGen`?N(!0):D(!0)}}else z(g(n));e.searchParams.delete(`plugin`),window.history.replaceState({},``,e.pathname+e.search+e.hash)}}catch{}(async()=>{try{if(!await ye(`prompts`))return;let e=(await L(`prompts`,Ee)).content.trim();e&&T(e)}catch{}})(),Ot().then(e=>xn(e)),bt().then(e=>{Cn(e),Tn(!0)}),Yt().then(e=>Dn(e)),cn().then(e=>kn(e)),xt().then(e=>jn(e)),tn().then(e=>{Mn(e),e?.workspace&&In(t=>({...t,[e.workspace]:!0}))})})(),()=>{e=!0,t(),r(),a()}},[]),(0,U.useEffect)(()=>{!B.memory&&Wn===`memory`&&Gn(`dialog`)},[B.memory,Wn]),(0,U.useEffect)(()=>{!B.todos&&Wn===`todos`&&Gn(`dialog`)},[B.todos,Wn]),(0,U.useEffect)(()=>{y(nf,Wn)},[Wn]),(0,U.useEffect)(()=>{if(!B.reports){yn(``);return}let e=!0;return(async()=>{try{await tr(!0);let t=await er();e&&yn(t)}catch{}})(),()=>{e=!1}},[B.reports]),(0,U.useEffect)(()=>{if(!r)return;let e=!1,t=async()=>{if(!K.current)return;let t=await tu();if(e||!K.current)return;let n=K.current,r=!1;for(let e of t){let t=n.sessions.find(t=>t.id===e.sessionId)?.messages??[],i=`<!--tb-schedule:${e.id}-->`;if(!t.some(t=>t.scheduleId===e.id||typeof t.content==`string`&&t.content.includes(i))){let t={role:`assistant`,content:$l(e.text,e.id),time:Date.now(),scheduleId:e.id};n=nt(n,e.sessionId,t),e.sessionId===n.activeId&&(r=!0)}try{typeof Notification<`u`&&Notification.permission===`granted`&&new Notification(`Lantern Harness 定时提醒`,{body:e.text})}catch{}}let i=await Ge();if(!e&&K.current){if(i){let e=Qe(n,i);e!==n&&(n=e,n.activeId&&(r=!0))}if((n!==K.current||t.length)&&q(n),r){let e=n.sessions.find(e=>e.id===n.activeId);l(e?.messages??[])}}};t();let n=window.setInterval(()=>{t()},1e4);return()=>{e=!0,window.clearInterval(n)}},[r]),(0,U.useEffect)(()=>{if(!r||!W||!V)return;let e=a?.sessions.find(e=>e.id===a.activeId);_a(e)},[r,W,a?.activeId,V?.items]),(0,U.useEffect)(()=>{let e=e=>{if(e.key!==`Shift`||e.repeat||e.ctrlKey||e.metaKey||e.altKey)return;let t=document.activeElement;t instanceof HTMLElement&&t!==document.body&&(t.tagName===`TEXTAREA`||t.tagName===`INPUT`||t.tagName===`SELECT`||t.isContentEditable||t.blur())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[]),(0,U.useEffect)(()=>{$n(0),ar(!1)},[$i?.query,$i?.from]),(0,U.useEffect)(()=>{fr(!1),be(0)},[ia?.from]),(0,U.useEffect)(()=>{be(e=>aa.length?Math.min(e,aa.length-1):0)},[aa.length]),(0,U.useEffect)(()=>{if(!ra||!Qi){Qi||Dr([]);return}let e=!1;return Nt(ln,{maxDepth:3,maxEntries:80}).then(t=>{e||Dr(t)}),()=>{e=!0}},[ra,Qi,ln,V?.workspace]),(0,U.useEffect)(()=>{if(!ra)return;let e=Ki.current;e&&e.querySelector(`[data-mention-index="${Zn}"]`)?.scrollIntoView({block:`nearest`})},[Zn,ra,na.length]),(0,U.useEffect)(()=>{if(!oa)return;let e=qi.current;e&&e.querySelector(`[data-plugin-index="${_e}"]`)?.scrollIntoView({block:`nearest`})},[_e,oa,aa.length]),(0,U.useEffect)(()=>{if(!ra&&!oa&&!pr)return;function e(e){let t=e.target;Ki.current?.contains(t)||qi.current?.contains(t)||Ji.current?.contains(t)||Wi.current?.contains(t)||e.target?.closest?.(`[data-add-menu-btn]`)||(ar(!0),fr(!0),_r(!1))}return document.addEventListener(`pointerdown`,e,!0),()=>document.removeEventListener(`pointerdown`,e,!0)},[ra,oa,pr]),(0,U.useEffect)(()=>{if(!Rt||nn!==`ok`)return;function e(e){let t=e.target;Yi.current?.contains(t)||z(null)}let t=window.setTimeout(()=>{document.addEventListener(`pointerdown`,e,!0)},0);return()=>{window.clearTimeout(t),document.removeEventListener(`pointerdown`,e,!0)}},[Rt,nn]),(0,U.useEffect)(()=>{if(!Hn&&!tt)return;function e(e){let t=e.target;t?.closest?.(`[data-session-menu]`)||t?.closest?.(`[data-ws-menu]`)||(Un(null),ut(null))}return document.addEventListener(`pointerdown`,e,!0),()=>document.removeEventListener(`pointerdown`,e,!0)},[Hn,tt]);function pa(){Ot().then(e=>xn(e)),bt().then(e=>{Cn(e),Tn(!0)}),Yt().then(e=>Dn(e)),cn().then(e=>kn(e)),xt().then(e=>jn(e)),tn().then(e=>Mn(e))}function ma(e){Mn(e),In(t=>({...t,[e.workspace]:!0}))}async function ha(e,t=`select`){if(W&&!Nn){Pn(!0),z(null);try{ma(t===`add`?await jt(e):await rn(e))}catch(e){z(e instanceof Error?e.message:String(e))}finally{Pn(!1)}}}function ga(e){let t=la.current;if(!t)return null;let n=e?.workspacePath?.trim();return n&&(n===t.harnessRoot||t.items.some(e=>e.path===n))?n:t.projectRoot?.trim()||null}async function _a(e){if(!W||Nn)return;let t=ga(e);if(!t)return;let n=la.current;if(n&&t!==n.workspace){Pn(!0);try{ma(await rn(t))}catch{}finally{Pn(!1)}}}async function va(e){if(!W||Nn)return;await ha(e.path,`select`);let t=K.current;if(!t)return;let n=t.sessions.find(e=>e.id===t.activeId);n&&!n.workspacePath&&((n.messages??[]).length>0||(q(Ue(t,n.id,e.path)),In(t=>({...t,[e.path]:!0}))))}async function ya(){if(W&&!Nn){Pn(!0),z(null);try{let e=await Pt();if(!e)return;ma(await jt(e))}catch(e){z(e instanceof Error?e.message:String(e))}finally{Pn(!1)}}}async function ba(){let e=ft;if(e&&W&&!Nn){if(e.id===`ws_project`)pt(null);else{pt(null),ut(null),Pn(!0),z(null);try{K.current&&q(ot(K.current,e.path));let t=await Et(e.id);ma(t),t.projectRoot&&In(e=>({...e,[t.projectRoot]:!0}))}catch(e){z(e instanceof Error?e.message:String(e))}finally{Pn(!1)}}}}function xa(e){W&&!Nn&&e.id!==`ws_project`&&(Un(null),ut(null),pt(e))}async function Sa(e){let t=mt;if(ht(null),t&&W){Pn(!0),z(null);try{ma(await lt(t,e))}catch(e){z(e instanceof Error?e.message:String(e))}finally{Pn(!1)}}}function Ca(e){if(!e||!K.current)return K.current;let t=K.current.sessions.find(t=>t.id===e);if(!t||!Ke(t))return K.current;let n=Zi.current[e];return n&&(n.input?.trim()||(n.attachments?.length??0)>0||(n.images?.length??0)>0||(n.docRefs?.length??0)>0)?K.current:(delete Zi.current[e],rt(K.current,e))}function wa(e){$i&&(e.collection!==`workspace`&&!jr?z(g(`knowledge`)):S.length>=$d?z(`最多引用 ${$d} 篇文档`):(z(null),C(t=>t.some(t=>t.collection===e.collection&&t.path===e.path)?t:[...t,{collection:e.collection,id:e.id,title:e.title,category:e.category,path:e.path,format:e.format}].slice(0,$d)),d(u.slice(0,$i.from).replace(/\s+$/,``)),ar(!0),Wi.current?.focus()))}function Ta(){ia&&(d(u.slice(0,ia.from).replace(/\s+$/,``)),fr(!0))}function Ea(e){if(!B[e])return z(g(e)),!1;if(z(null),e===`caseGen`)return D(!0),!0;if(e===`promptGen`)return j(!0),!0;if(e===`knowledgeGen`)return N(!0),!0;if(e===`pluginDev`)return Ha(),!0;if(e===`memory`)return Gn(`memory`),!0;if(e===`knowledge`){let e=u.replace(/\s+$/,``);return d(e?`${e} @`:`@`),ar(!1),requestAnimationFrame(()=>Wi.current?.focus()),!0}return!1}function Da(e){Ta(),Ea(e)}function Oa(){let e=Ui.current;if(!e)return;let t=e.scrollHeight-e.clientHeight-e.scrollTop<=48;if(ca.current){if(!t)return;ca.current=!1}sa.current=t,fn(!t)}function ka(){let e=Ui.current;e&&(sa.current=!0,ca.current=!0,fn(!1),e.scrollTo({top:e.scrollHeight,behavior:`smooth`}))}(0,U.useEffect)(()=>{if(!r||!K.current)return;let e=K.current.sessions.find(e=>e.id===K.current.activeId)?.messages??[],t=JSON.stringify(e)!==JSON.stringify(s),n=Ve(K.current,s,{touchUpdatedAt:t});K.current=n,o(n),at(n),sa.current&&!ca.current&&Ui.current?.scrollTo({top:Ui.current.scrollHeight})},[s,r]),(0,U.useEffect)(()=>{let e=()=>{K.current&&at(K.current)};return window.addEventListener(`pagehide`,e),()=>window.removeEventListener(`pagehide`,e)},[]),(0,U.useLayoutEffect)(()=>{let e=Wi.current;e&&(e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,280)}px`)},[u]),(0,U.useEffect)(()=>{if(!r||!I||!s.length)return;let e=I,t=window.setTimeout(()=>{let t=(Ui.current??document).querySelector(`[data-focus-doc="${CSS.escape(e)}"]`);t instanceof HTMLElement&&(t.scrollIntoView({behavior:`smooth`,block:`center`}),t.classList.add(`ring-2`,`ring-[#4176e6]`,`ring-offset-2`),window.setTimeout(()=>{t.classList.remove(`ring-2`,`ring-[#4176e6]`,`ring-offset-2`)},2400)),ge(null)},80);return()=>window.clearTimeout(t)},[r,I,s]);function Aa(e,t){At(n=>{let r=n.includes(e);return t&&!r?[...n,e]:!t&&r?n.filter(t=>t!==e):n}),K.current?.activeId===e&&(G.current=t,wt(t))}function ja(e){e&&(Hr.current.get(e)?.abort.abort(),Gr.current.get(e)?.(),Gr.current.delete(e),ur(e))}function Ma(e,t){if(t.type===`reasoning`&&t.delta)Pa(e,n=>{let r=n[n.length-1];if(r?.role!==`assistant`)return n;let i=pe((r.reasoning??``)+t.delta),a=[...r.activitySteps??[]],o=a.findIndex(e=>e.kind===`thinking`),s={id:`thinking`,kind:`thinking`,title:`思考`,detail:gf(i).replaceAll(`**`,``).slice(0,80)||void 0,status:`running`};o>=0?a[o]={...a[o],...s}:a.unshift(s);let c=n.slice(),l=qr.current.get(e),u=r.ttftMs;return l&&l.firstToken==null&&(l.firstToken=Date.now(),u=Math.max(0,l.firstToken-l.start)),c[c.length-1]={...r,reasoning:i,activitySteps:a,turnStatus:`running`,ttftMs:u},c});else if(t.type===`content`&&t.delta)Pa(e,n=>{let r=n[n.length-1];if(r?.role!==`assistant`)return n;let i=(r.activitySteps??[]).map(e=>e.kind===`thinking`&&e.status===`running`?{...e,status:`done`}:e),a=n.slice(),o=qr.current.get(e),s=r.ttftMs;return o&&o.firstToken==null&&(o.firstToken=Date.now(),s=Math.max(0,o.firstToken-o.start)),a[a.length-1]={...r,content:pe((r.content??``)+t.delta),activitySteps:i,turnStatus:`running`,ttftMs:s},a});else if(t.type===`tool`&&t.name){let n=df(t.name),r=hf(t.name,t.args),i=`tool_${t.name}_${t.args?.slice(0,24)??``}`;Ia(e,i,t.status);let a=t.status===`done`&&typeof t.result==`string`&&/^\s*\{\s*"error"\s*:/.test(t.result);Pa(e,e=>{let o=e[e.length-1];if(o?.role!==`assistant`)return e;let s=[...o.activitySteps??[]],c=s.findIndex(e=>e.id===i||e.detail===r&&e.title===n&&e.status===`running`),l={id:i,kind:pf(t.name),title:n,detail:r||void 0,status:t.status===`running`?`running`:a?`error`:`done`};c>=0?s[c]={...s[c],...l}:s.push(l);let u=e.slice();return u[u.length-1]={...o,activitySteps:s,turnStatus:`running`},u}),K.current?.activeId===e&&H(_f(Pe().toolStepDetail,n,t.name,t.status===`running`?`running`:`done`))}else if(t.type===`usage`&&t.usage)Pa(e,e=>{let n=e[e.length-1];if(n?.role!==`assistant`)return e;let r=e.slice();return r[r.length-1]={...n,usage:t.usage},r});else if(t.type===`status`){let n=t.status;(n===`completed`||n===`stopped`||n===`error`)&&(Pa(e,e=>{let r=e[e.length-1];if(r?.role!==`assistant`)return e;let i=t.assistant,a=e.slice(),o=typeof i?.toolMs==`number`?i.toolMs:void 0,s=typeof i?.llmMs==`number`?i.llmMs:void 0,c=typeof i?.ttftMs==`number`?i.ttftMs:void 0,l=typeof i?.tps==`number`?i.tps:void 0;return a[a.length-1]={...r,content:typeof i?.content==`string`?i.content:r.content,reasoning:typeof i?.reasoning==`string`?i.reasoning:r.reasoning,reasoningApi:typeof i?.reasoningApi==`string`?i.reasoningApi:r.reasoningApi,activitySteps:(i?.activitySteps??r.activitySteps??[]).map(e=>e.status===`running`?{...e,status:`done`}:e),turnStatus:n===`completed`?`completed`:`stopped`,time:Date.now(),usage:i?.usage??r.usage,model:typeof i?.model==`string`?i.model:r.model,toolMs:o==null?r.toolMs:Math.max(o,r.toolMs??0),llmMs:s??r.llmMs,ttftMs:c??r.ttftMs,tps:l??r.tps},a}),n===`error`&&t.error&&K.current?.activeId===e&&z(ff(t.error)),Hr.current.delete(e),Ur.current===e&&(Ur.current=null),Aa(e,!1),K.current?.activeId===e&&H(null))}}function Na(e,t=0){Gr.current.get(e)?.(),Aa(e,!0),(async()=>{let n=await dr(e),r=t;if(n?.ok&&n.assistant&&(r=Math.max(r,n.seq??0),Pa(e,e=>{let t=e[e.length-1],r=t?.role===`assistant`?t:{role:`assistant`,content:``,turnStatus:`running`},i=n.assistant,a={...r,content:typeof i?.content==`string`?i.content:r.content,reasoning:typeof i?.reasoning==`string`?i.reasoning:r.reasoning,reasoningApi:typeof i?.reasoningApi==`string`?i.reasoningApi:r.reasoningApi,activitySteps:i?.activitySteps??r.activitySteps,turnStatus:n.status===`completed`?`completed`:n.status===`stopped`||n.status===`error`?`stopped`:`running`,usage:i?.usage??r.usage,model:typeof i?.model==`string`?i.model:r.model,llmMs:typeof i?.llmMs==`number`?i.llmMs:r.llmMs,ttftMs:typeof i?.ttftMs==`number`?i.ttftMs:r.ttftMs,toolMs:typeof i?.toolMs==`number`?Math.max(i.toolMs,r.toolMs??0):r.toolMs,tps:typeof i?.tps==`number`?i.tps:r.tps};if(t?.role===`assistant`){let t=e.slice();return t[t.length-1]=a,t}return[...e,a]}),n.status&&n.status!==`running`&&n.status!==`waiting_user`)){Aa(e,!1);return}let i=mr(e,r,{onEvent:t=>Ma(e,t),onGaveUp:t=>{K.current?.activeId===e&&z(t.message||`与服务端回合断开`),Aa(e,!1)}});Gr.current.set(e,i)})()}function Pa(e,t,n){let r=Hr.current.get(e),i=K.current?.sessions.find(t=>t.id===e)?.messages??[],a=r?.messages??(K.current?.activeId===e?ua.current:i),o=typeof t==`function`?t(a):t;r&&(r.messages=o),K.current?.activeId===e&&(ua.current=o,l(o)),K.current&&q(Le(K.current,e,o,{touchUpdatedAt:n?.touchUpdatedAt!==!1}))}function Fa(e){let t=Ur.current??K.current?.activeId;t&&Pa(t,t=>{let n=t[t.length-1];if(n?.role!==`assistant`)return t;let r=t.slice();return r[r.length-1]=e(n),r})}function Ia(e,t,n){let r=`${e}:${t}`;if(n===`running`){Kr.current.set(r,Date.now());return}if(n!==`done`&&n!==`error`)return;let i=Kr.current.get(r);if(Kr.current.delete(r),i==null)return;let a=Math.max(0,Date.now()-i);Pa(e,e=>{let t=e[e.length-1];if(t?.role!==`assistant`)return e;let n=e.slice();return n[n.length-1]={...t,toolMs:(t.toolMs??0)+a},n})}async function La(e){if(!e.length)return;let t=[],n=[],r=cf(f,_);for(let i of e)if(r+t.length>=6)n.push(`${i.name||`图片`}(最多 6 个文件)`);else try{t.push(await sf(i))}catch(e){n.push(e instanceof Error?e.message:String(e))}t.length&&x(e=>[...e,...t].slice(0,6)),z(n.length?`以下图片未添加:${n.join(`、`)}`:null)}function Ra(){d(``),p([]),x([]),C([]),ar(!1),fr(!1)}function za(){if(oi===`plan`&&(co(),ai(`off`)),oi===`pluginDev`){P(null),me.current=null,K.current&&q(Re(K.current,{pluginDev:void 0}));let e=F.current;F.current=null,e===`readonly`&&(un(`readonly`),K.current&&q(Re(K.current,{access:`readonly`})))}si(null)}function Ba(){si(`goal`),requestAnimationFrame(()=>Wi.current?.focus())}function Va(){ai(e=>e===`off`?`planning`:e),si(`plan`),requestAnimationFrame(()=>Wi.current?.focus())}function Ha(){W?(si(`pluginDev`),ln===`readonly`&&(F.current=`readonly`,un(`readwrite`),K.current&&q(Re(K.current,{access:`readwrite`}))),requestAnimationFrame(()=>Wi.current?.focus())):z(`本地文件服务未就绪:插件开发需要读写项目源码`)}function Ua(e){li(e),si(`reports`),window.setTimeout(()=>Wi.current?.focus(),400)}function Wa(e){return e.filter(e=>e.role===`user`||e.role===`assistant`).map(e=>({role:e.role,content:typeof e.content==`string`?e.content:``,reasoning:e.reasoning}))}async function Ga(e){if(!t)return Me(`model`),!1;let n=Wa(ua.current);if(n.length<4)return z(`对话轮次较少,无需压缩`),!1;H(`正在压缩上下文…`);try{let{messages:r,compacted:i}=await gl(t,n,{force:e.force,signal:e.signal});if(!i)return H(null),z(`当前上下文未超过阈值,未压缩`),!1;let a=Date.now(),o=r.map((e,t)=>({role:e.role,content:e.content,reasoning:e.reasoning,time:a+t}));return ua.current=o,l(o),K.current&&q(Ve(K.current,o,{touchUpdatedAt:!0})),H(null),!0}catch(e){return H(null),e instanceof DOMException&&e.name===`AbortError`||z(e instanceof Error?e.message:String(e)),!1}}async function Ka(e,n){let r=e===void 0,i=r&&oi===`reports`?`生成${nr[ci]}`:``,a=(e??u).trim()||i,o=r?f:[],s=r?S:[],c=r?_:[];if(!a&&!o.length&&!s.length&&!c.length)return;if(!t){Me(`model`);return}if(r&&oi===`reports`&&si(null),_l(a)&&!o.length&&!s.length&&!c.length){if(G.current){z(`请等待当前回复结束后再压缩`);return}r&&Ra(),await Ga({force:!0})&&z(null);return}if(oi===`goal`&&a&&!o.length&&!s.length&&!c.length&&!wl(a)&&!_l(a)){r&&Ra();let e={text:a.slice(0,500),status:`active`,updatedAt:Date.now()};ti.current=e,ei(e),ni.current=0,K.current&&q(Re(K.current,{goal:e})),si(null),z(`已设定目标:${e.text}`);return}if(wl(a)&&!o.length&&!s.length&&!c.length){let e=Cl(a);if(r&&Ra(),!e)return;if(e.kind===`show`){let e=$r;z(e&&e.status!==`cleared`?`当前目标(${e.status}):${e.text}`:`当前无会话目标。可用 /goal set <内容> 设定`);return}if(e.kind===`clear`){ti.current=null,ei(null),ni.current=0,K.current&&q(Re(K.current,{goal:void 0})),z(`已清除会话目标`);return}if(e.kind===`done`){if(!$r?.text){z(`当前无目标可标记完成`);return}let e={...$r,status:`done`,updatedAt:Date.now()};ti.current=e,ei(e),ni.current=0,K.current&&q(Re(K.current,{goal:e})),z(`已标记目标完成:${e.text}`);return}if(e.kind===`set`&&e.text){let t={text:e.text.slice(0,500),status:`active`,updatedAt:Date.now()};ti.current=t,ei(t),ni.current=0,K.current&&q(Re(K.current,{goal:t})),z(`已设定目标:${t.text}`);return}return}if(oi===`pluginDev`&&a&&!o.length&&!s.length&&!c.length){if(G.current){z(`请等待当前回复结束后再开始插件开发`);return}await no(a)}let l={id:`q_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,6)}`,content:a,files:[...o],refs:[...s],imgs:[...c]};if(G.current){let e=Pe().busySendBehavior??`queue`;if((n?.forceBusy??e)===`queue`){Vi([...zi.current,l]),r&&Ra();return}Bi.current=l,r&&Ra(),ja(K.current?.activeId)}else await qa(l)}async function qa(n){let r=K.current?.activeId;if(!t||!r||Hr.current.has(r))return;let{content:i,files:a,refs:o,imgs:s}=n;Dl(i)||(ni.current=0),z(null);let c=Date.now(),u={role:`user`,content:i,time:c};a.length&&(u.attachments=a),o.length&&(u.refs=o),s.length&&(u.images=s);let d=ua.current,f=d[d.length-1];f?.role===`assistant`&&!f.content&&!f.reasoning&&(d=d.slice(0,-1));let p=[...d,u];if(pl(Wa(p),t.model)){H(`上下文较长,正在压缩…`);try{let{messages:e,compacted:n}=await gl(t,Wa(p),{force:!1,signal:void 0});if(n){let t=Date.now();p=e.map((e,n)=>({role:e.role,content:e.content,reasoning:e.reasoning,time:t+n})),ua.current=p,l(p),K.current&&q(Ve(K.current,p,{touchUpdatedAt:!0}))}}catch{}H(null)}let m=[...p,{role:`assistant`,content:``,time:c,turnStatus:`running`}];ua.current=m,l(m),Ra();let h=new AbortController;Ur.current=r,Hr.current.set(r,{abort:h,messages:m}),Vr.current=h,Aa(r,!0),sa.current=!0,fn(!1);let g=Wr(p.map(e=>{let t={role:e.role,content:af(e)},n=(e.reasoningApi??e.reasoning)?.trim();return e.role===`assistant`&&n&&(t.reasoning_content=n),t}),{keepRecentImageMessages:1}),_=Ar,v=jr,y=W,b=Mr,x=!!B.todos,S=!!B.tasks,C=!!B.projects,T=!!B.iterations,E=!!B.pmRequirements,D=!!B.bugs,ee=ii===`planning`,te=B.pluginDev&&me.current?.active?me.current:null,O=te?ln===`full`?`full`:`readwrite`:ee?`readonly`:ln,ne=Lr&&O!==`readonly`,re=Rr&&O!==`readonly`,ie=la.current?.workspace?.trim()||``,ae=ie?`\n当前工作区:${ie}`:``,j=B.promptGen&&se.current?.active?se.current:null,M=!j&&B.knowledgeGen&&de.current?.active?de.current:null,ce=!j&&!M&&B.caseGen&&A.current?.active?A.current:null,N=!!(j||M||ce),le=ie,fe=w;if(te)fe=Fs(te,la.current?.harnessRoot||la.current?.projectRoot||ie);else if(j)fe=ds(j);else if(M)fe=ks(M);else if(ce){if(!ce.promptBody?.trim()){z(`生成测试用例已启用,但未选择提示词。请打开插件重新「确认」。`),Hr.current.delete(r),Ur.current=null,Vr.current=null,Aa(r,!1),l(e=>e[e.length-1]?.role===`assistant`&&!e[e.length-1]?.content?e.slice(0,-1):e);return}try{fe=Xo(ce,ce.reqPath?.split(`/`).pop()?.replace(/\.[^.]+$/,``)||``)}catch(e){z(e instanceof Error?e.message:String(e)),Hr.current.delete(r),Ur.current=null,Vr.current=null,Aa(r,!1);return}}if(!N){let e=vn;if(!te&&!e.trim()&&B.reports)try{await tr(!0),e=await er()}catch{}!te&&e.trim()&&(fe=`${fe}\n\n${e.trim()}`);let t=Yc({lastUserMessageAt:[...p].reverse().find(e=>e.role===`user`&&e!==p[p.length-1])?.time??[...p].reverse().find(e=>e.role===`user`)?.time??null,lastInjectAt:Jr.current});if(t.injected&&(Jr.current=t.at),fe=`${fe}\n\n${t.text}`,y)try{let e=await gt();e?.text&&(fe=`${fe}\n\n${dt}\n\n${e.text}`)}catch{}}let P=Jd(fe,g,{memory:_&&!N,knowledge:v&&!N,fs:y&&!N,web:b&&!N,bash:ne&&!N,pwsh:re&&!N,interact:!N,todos:x&&!N,tasks:S&&!N,projects:C&&!N,iterations:T&&!N,pmRequirements:E&&!N,bugs:D&&!N,planPhase:N||te?`off`:ii,goalEnabled:!N,goal:$r,scheduleEnabled:!N,subagentEnabled:!N,workflowEnabled:!N}).map((e,t)=>t===0&&e.role===`system`&&y&&ae&&!N?{...e,content:`${typeof e.content==`string`?e.content:``}${ae}`}:e);if(_&&!N&&!te){H(`记忆注入中…`);let{context:e}=await qt(i,{cwd:le});if(e&&P[0]?.role===`system`){let t=typeof P[0].content==`string`?P[0].content:``;P=[{...P[0],content:`${t}\n\n${e}`},...P.slice(1)]}H(null)}let F=[];N||(v&&F.push(...Uu),y&&(F.push(...yt(O)),F.push(...kt),F.push(...Rs),F.push(...Bc),F.push(zr),ee||(F.push(Fr),F.push(_t))),ne&&(F.push(Gt),F.push(...Zt)),re&&(F.push(zt),F.push(...$t)),(ne||re)&&F.push(...It),b&&F.push(...vt),_&&F.push(...Ft),F.push(Zc),x&&F.push(...fc),S&&F.push(...jc),C&&F.push(...Ks),T&&F.push(...qs),E&&F.push(...Js),D&&F.push(...Ys),F.push(Qc),F.push(...yl),F.push(...Bl),F.push(...au),F.push(...Nu),(ii===`planning`||ii===`approved`)&&F.push(ol));let I=Date.now(),ge=0;qr.current.set(r,{start:I});let L=0,_e=!1,ve=``,ye=!1,be,xe=!!(j||M||ce);function Se(e){return j?fs(e):M?As(e):Zo(e)}function Ce(){return j?`正在编写提示词…`:M?`正在编写知识库…`:`正在编写用例…`}let we=!1;try{let n=``,a=``,o=``;if(xe){H(Ce());let e=()=>{let e=Math.max(0,Math.floor((Date.now()-I)/1e3));Fa(t=>({...t,content:Se(e)}))};e(),be=window.setInterval(e,1e3)}if(!(x||S||C||T||E||D)&&!xe&&!te&&await sr(h.signal)){let e=F.filter(e=>{let t=e.function?.name??``;return!(!t||t===`ask_user_question`||t===`submit_plan`||t===`workflow`||t===`spawn_subagent`||t===`fork_subagent`||t===`list_agents`||t.startsWith(`subagent_`))});(await lr({sessionId:r,messages:P,settings:{baseURL:t.baseURL,apiKey:t.apiKey,model:t.model,reasoningEffort:t.reasoningEffort},tools:e,thinking:!0,workspace:ie||``,access:O})).ok&&(we=!0,await new Promise(e=>{let t=!1,n=()=>{t||(t=!0,e())},i=()=>{ur(r)};h.signal.addEventListener(`abort`,i),Gr.current.get(r)?.();let a=mr(r,0,{signal:h.signal,onEvent:e=>Ma(r,e),onTerminal:e=>{ye=e.status===`completed`,h.signal.removeEventListener(`abort`,i),Gr.current.delete(r),n()},onGaveUp:e=>{K.current?.activeId===r&&z(e.message||`与服务端回合断开`),Pa(r,e=>{let t=e[e.length-1];if(t?.role!==`assistant`)return e;let n=e.slice();return n[n.length-1]={...t,turnStatus:`stopped`,activitySteps:(t.activitySteps??[]).map(e=>e.status===`running`?{...e,status:`done`}:e)},n}),h.signal.removeEventListener(`abort`,i),Gr.current.delete(r),n()}});Gr.current.set(r,()=>{a(),n()})}))}if(!we){let s=he(t,P,h.signal,{tools:F.length?F:void 0,runTool:F.length?async(n,i)=>{Yn(!0);let a=df(n);H(_f(Pe().toolStepDetail,a,n,`running`));let o=Date.now();try{if(n.startsWith(`kb_`))return await Ku(n,i,{base:`/`,docs:e});if(n.startsWith(`fs_`)){let e=await Vt(n,i,O),t=Uc(n,e);if(t&&K.current){let e=Hc(K.current.sessions.find(e=>e.id===r)?.workspaceChanges,t);q(ze(K.current,r,{workspaceChanges:e}))}return e}if(n.startsWith(`skill_`))return await zs(n,i);if(n===`load_workspace_dependencies`)return await Br(n);if(n===`office_to_pdf`)return ee?JSON.stringify({error:`计划模式探查中:请先 submit_plan 并等待批准`}):await Ir(n,i,O);if(n.startsWith(`workspace_changes_`)){let e=K.current?.sessions.find(e=>e.id===r),{text:t,next:i}=Wc(n,e?.workspaceChanges);return i&&K.current&&q(ze(K.current,r,{workspaceChanges:i})),t}if(n.startsWith(`working_directory_`)){let{text:e,info:t}=await Qt(n,i);return t&&(ma(t),n===`working_directory_set`&&K.current&&q(ze(K.current,r,{workspacePath:t.workspace}))),e}if(n===`present`){if(ee)return JSON.stringify({error:`计划模式探查中:请先 submit_plan 并等待批准`});let e=await sn(i,O);try{let t=JSON.parse(e);t.ok&&t.files?.length&&Fa(e=>{let n=e.presentFiles??[],r=new Map(n.map(e=>[e.path,e]));for(let e of t.files)r.set(e.path,e);return{...e,presentFiles:[...r.values()]}})}catch{}return e}if(n===`todo_add`){if(ee)return JSON.stringify({error:`计划模式探查中:请先 submit_plan 并等待批准`});let e;try{e=JSON.parse(i||`{}`).items}catch{e=void 0}let t=zd(`todo`,e);if(!t.length)return JSON.stringify({error:`没有可记录的待办:只有用户明确要求记录待办时才调用 todo_add,并给出待办标题;不要为了弹出卡片而调用工具。`});let n=await wc(t),r=await Pi(`todo`,n.items,{quick:!0,quickNote:n.willCreateRoutine?`确认后会创建任务「日常待办」并关联,状态 / 日期已自动填好`:void 0});if(!r)return JSON.stringify({ok:!1,cancelled:!0,message:`用户取消了新增待办,未写入任何数据。`});let a;try{a=await Tc(r)}catch(e){return JSON.stringify({error:`创建所属任务失败:${e instanceof Error?e.message:String(e)}`})}i=JSON.stringify({items:Bd(`todo`,a)})}if(n===`task_add`){if(ee)return JSON.stringify({error:`计划模式探查中:请先 submit_plan 并等待批准`});let e=zd(`task`,Mc(i));e.length||e.push(Rd(`task`));let t=await Pi(`task`,e);if(!t)return JSON.stringify({ok:!1,cancelled:!0,message:`用户取消了新增任务,未写入任何数据。`});i=JSON.stringify({items:Bd(`task`,t)})}if(n.startsWith(`task_`)){let e=await Nc(n,i,{sessionId:r});if(n===`task_add`)try{let t=JSON.parse(e);t.ok&&t.count&&z(`已创建 ${t.count} 个任务,可在侧栏「任务管理」查看。`,`ok`)}catch{}return e}if(n.startsWith(`todo_`)&&n!==`todo_write`){if(ee&&n!==`todo_list`)return JSON.stringify({error:`计划模式探查中:请先 submit_plan 并等待批准`});let e=await vc(n,i,{sessionId:r});if(n===`todo_add`)try{let t=JSON.parse(e);t.ok&&t.count&&z(`已记录 ${t.count} 条待办,可在侧栏「待办事项」查看。`,`ok`)}catch{}return e}if(n===`todo_write`){let e;try{e=JSON.parse(i||`{}`).todos}catch{return JSON.stringify({error:`invalid JSON arguments`})}let t=$c(e);return K.current?.activeId===r&&Qr(t),K.current&&q(ze(K.current,r,{todos:t})),JSON.stringify({ok:!0,count:t.length,todos:t})}if(n.startsWith(`pm_`)){if(ee&&!n.endsWith(`_list`))return JSON.stringify({error:`计划模式探查中:请先 submit_plan 并等待批准`});let e=await lc(n,i,{sessionId:r});if(n.endsWith(`_add`))try{let t=JSON.parse(e);if(t.ok&&t.count){let e=n.startsWith(`pm_project_`)?`项目列表`:n.startsWith(`pm_iteration_`)?`迭代管理`:n.startsWith(`pm_requirement_`)?`需求管理`:`缺陷管理`,r=n.startsWith(`pm_iteration_`)?`迭代`:n.startsWith(`pm_requirement_`)?`条需求`:n.startsWith(`pm_bug_`)?`条缺陷`:`个项目`;z(`已创建 ${t.count} ${r},可在侧栏「${e}」查看。`,`ok`)}}catch{}return e}if(n.startsWith(`goal_`)){if(n===`goal_get`)return xl(K.current?.activeId===r?ti.current:bl(K.current?.sessions.find(e=>e.id===r)?.goal));if(n===`goal_set`){let e=``;try{e=String(JSON.parse(i||`{}`).text??``).trim()}catch{return JSON.stringify({error:`invalid JSON arguments`})}if(!e)return JSON.stringify({error:`text is required`});let t={text:e.slice(0,500),status:`active`,updatedAt:Date.now()};return K.current?.activeId===r&&(ti.current=t,ei(t),ni.current=0),K.current&&q(ze(K.current,r,{goal:t})),xl(t)}if(n===`goal_done`){let e=K.current?.activeId===r?ti.current:bl(K.current?.sessions.find(e=>e.id===r)?.goal);if(!e?.text)return JSON.stringify({ok:!1,error:`no goal to complete`});let t={...e,status:`done`,updatedAt:Date.now()};return K.current?.activeId===r&&(ti.current=t,ei(t),ni.current=0),K.current&&q(ze(K.current,r,{goal:t})),xl(t)}return n===`goal_clear`?(K.current?.activeId===r&&(ti.current=null,ei(null),ni.current=0),K.current&&q(ze(K.current,r,{goal:void 0})),JSON.stringify({ok:!0,goal:null})):JSON.stringify({error:`unknown tool: ${n}`})}if(n.startsWith(`schedule_`))return await nu(n,i,r);if(n===`list_agents`||n===`spawn_subagent`||n===`fork_subagent`||n.startsWith(`subagent_`))return await Eu(n,i,{settings:Nr(t,Pe().subagentModel),parentSignal:h.signal,access:O,fsEnabled:y,webEnabled:b,parentMessages:g,onHint:e=>H(e),runFs:(e,t,n)=>Vt(e,t,n),runWeb:(e,t)=>Dt(e,t)});if(n===`workflow`)return await zu(n,i,{settings:t,parentSignal:h.signal,access:O,fsEnabled:y,webEnabled:b,parentMessages:g,onHint:e=>H(e),runFs:(e,t,n)=>Vt(e,t,n),runWeb:(e,t)=>Dt(e,t)});if(n===`ask_user_question`){let e=el(i);if(!e.length)return JSON.stringify({error:`questions is required`});let t={};for(let n of e)t[n.id]={selected:[],text:``};return hi(t),_i(0),yi(!1),xi(null),Ci(!1),Ti(``),pi(e),await new Promise((e,t)=>{Yr.current={resolve:e,reject:t};let n=Vr.current,r=()=>{n?.signal.removeEventListener(`abort`,r),so()};n?.signal.addEventListener(`abort`,r)})}if(n===`submit_plan`){let e=sl(i);return e?(di(e),await new Promise((e,t)=>{Xr.current={resolve:e,reject:t};let n=Vr.current,r=()=>{n?.signal.removeEventListener(`abort`,r),co()};n?.signal.addEventListener(`abort`,r)})):JSON.stringify({error:`title and steps are required`})}return n===`bash`?await Ht(i,O):n===`pwsh`?await Wt(i,O):n.startsWith(`bash_session_`)?await Bt(n,i,O):n.startsWith(`pwsh_session_`)?await Xt(n,i,O):n.startsWith(`job_`)?await en(n,i,O):n.startsWith(`web_`)?await Dt(n,i):n.startsWith(`memory_`)?await Ct(n,i,le):JSON.stringify({error:`unknown tool: ${n}`})}finally{let e=Math.max(0,Date.now()-o);Fa(t=>({...t,toolMs:(t.toolMs??0)+e})),Yn(!1),pa()}}:void 0});for await(let e of s){if(e.type===`tool`){let t=df(e.name);H(_f(Pe().toolStepDetail,t,e.name,e.status===`running`?`running`:`done`));let n=hf(e.name,e.args),r=`tool_${e.name}_${e.args?.slice(0,24)??``}`,i=e.status===`done`&&typeof e.result==`string`&&/^\s*\{\s*"error"\s*:/.test(e.result);Fa(a=>{let o=[...a.activitySteps??[]],s=o.findIndex(e=>e.id===r||e.detail===n&&e.title===t&&e.status===`running`),c={id:r,kind:pf(e.name),title:t,detail:n||void 0,status:e.status===`running`?`running`:i?`error`:`done`};return s>=0?o[s]={...o[s],...c}:o.push(c),{...a,activitySteps:o}});continue}if(e.type===`usage`){let n=Date.now(),r=ge?(n-ge)/1e3:0,i=Jf(e.usage),a=r>.2&&i>0?i/r:void 0;Fa(r=>({...r,usage:e.usage,tps:a,model:t.model,ttftMs:ge?ge-I:r.ttftMs,llmMs:n-I}));continue}if(ge===0&&(ge=Date.now(),Fa(e=>({...e,ttftMs:ge-I,model:t.model}))),e.type===`reasoning_api`){Fa(t=>({...t,reasoningApi:e.content}));continue}e.type===`reasoning`&&L===0&&(L=Date.now());let r=e.type===`content`&&L>0&&!_e;if(r&&(_e=!0),xe){e.type===`content`&&(j?a+=e.delta:M?o+=e.delta:n+=e.delta);let t=Se(Math.max(0,Math.floor((Date.now()-I)/1e3)));if(e.type===`reasoning`){ve+=e.delta;let n=pe(ve);Fa(e=>{let i={...e,reasoning:n,content:t};return r&&(i.reasoningDuration=Math.max(1,Math.round((Date.now()-L)/1e3))),i})}else r&&Fa(e=>({...e,content:t,reasoningDuration:Math.max(1,Math.round((Date.now()-L)/1e3))}))}else e.type===`reasoning`&&(ve+=e.delta),Fa(t=>{let n=e.type===`reasoning`?{...t,reasoning:pe(ve)}:{...t,content:pe(t.content+e.delta)};if(e.type===`reasoning`){let e=[...n.activitySteps??[]],t=e.findIndex(e=>e.kind===`thinking`),r={id:`thinking`,kind:`thinking`,title:`思考`,detail:gf(n.reasoning??``).replaceAll(`**`,``).slice(0,80)||void 0,status:`running`};t>=0?e[t]={...e[t],...r}:e.unshift(r),n.activitySteps=e}if(r){n.reasoningDuration=Math.max(1,Math.round((Date.now()-L)/1e3));let e=[...n.activitySteps??[]],t=e.findIndex(e=>e.kind===`thinking`);t>=0&&(e[t]={...e[t],status:`done`}),n.activitySteps=e}return n})}if(ye=!0,!xe){let e=[...K.current?.sessions.find(e=>e.id===r)?.messages??[]].reverse().find(e=>e.role===`assistant`);e&&typeof e.content==`string`&&!e.content.trim()&&z(`模型本轮没有返回正文(可能工具轮次用尽或输出被截断),请重试或回复「继续」`)}{let e=L>0&&!_e?Math.max(1,Math.round((Date.now()-L)/1e3)):null;Fa(t=>{let n=(t.activitySteps??[]).map(e=>e.kind===`thinking`&&e.status===`running`?{...e,status:`done`}:e),r={...t,activitySteps:n};return e!=null&&t.reasoning&&t.reasoningDuration==null&&(r.reasoningDuration=e),r})}if(be!=null&&(window.clearInterval(be),be=void 0),j){H(`正在质检并入库…`);let e=await hs(a,j);if(Fa(t=>({...t,content:e.summary,docsFile:e.ok?{root:`prompts`,path:e.path,name:e.path.split(`/`).pop()||e.title||e.path}:void 0})),e.ok&&K.current){let t={...j,linkedPromptPath:e.path};oe(t),se.current=t,q(Re(K.current,{promptGen:t}))}}else if(M){H(`正在质检并入库…`);let e=await Ns(o,M);if(Fa(t=>({...t,content:e.summary,docsFile:e.ok?{root:`knowledge`,path:e.path,name:e.path.split(`/`).pop()||e.title||e.path,note:e.category}:void 0})),e.ok&&K.current){let t={...M,linkedKnowledgePath:e.path};ue(t),de.current=t,q(Re(K.current,{knowledgeGen:t}))}}else if(ce){H(`正在检测覆盖并入库…`);let e=ce.reqPath?.split(`/`).pop()?.replace(/\.[^.]+$/,``)||i.slice(0,24),t=await es(n,ce,e);if(Fa(e=>({...e,content:t.summary,caseFile:t.ok?{path:t.path,name:t.path.split(`/`).pop()||t.path,count:t.count}:void 0})),t.ok&&K.current){let e={...ce,linkedCasePath:t.path};k(e),A.current=e,q(Re(K.current,{caseGen:e}))}}}we&&ye&&Fa(e=>({...e,turnStatus:e.turnStatus===`stopped`?`stopped`:`completed`,activitySteps:(e.activitySteps??[]).map(e=>e.status===`running`?{...e,status:`done`}:e)}))}catch(e){e instanceof DOMException&&e.name===`AbortError`||K.current?.activeId===r&&z(e instanceof Error?e.message:String(e)),Pa(r,e=>{let t=e[e.length-1];if(t?.role===`assistant`&&!t.content&&!t.reasoning&&!t.activitySteps?.length)return e.slice(0,-1);if(t?.role!==`assistant`)return e;let n=e.slice();return n[n.length-1]={...t,activitySteps:(t.activitySteps??[]).map(e=>e.status===`running`?{...e,status:`done`}:e)},n})}finally{be!=null&&(window.clearInterval(be),be=void 0);let e=Date.now(),n=qr.current.get(r),a=ge||n?.firstToken||0;Fa(n=>{let r=n.llmMs??e-I,i=n.ttftMs??(a?a-I:void 0),o=i==null?0:Math.max(0,(r-i)/1e3),s=Jf(n.usage),c=n.tps??(o>.2&&s>0?s/o:void 0);return{...n,time:e,model:n.model??t.model,llmMs:r,ttftMs:i,tps:c,turnStatus:n.turnStatus===`stopped`||n.turnStatus===`completed`?n.turnStatus:ye?`completed`:(h.signal.aborted||!we)&&n.turnStatus===`running`?`stopped`:n.turnStatus,activitySteps:(n.activitySteps??[]).map(e=>e.status===`running`?{...e,status:`done`}:e)}}),qr.current.delete(r),Hr.current.delete(r),Gr.current.get(r)?.(),Gr.current.delete(r),Ur.current===r&&(Ur.current=null),Vr.current===h&&(Vr.current=null),Aa(r,!1);{let e=Pe().toolStepDetail;e===`full`?window.setTimeout(()=>H(null),2800):e===`detailed`?window.setTimeout(()=>H(null),1200):H(null)}if(ye&&_&&Jt(i,le).finally(()=>{pa()}),ye&&K.current){let e=[...K.current.sessions.find(e=>e.id===r)?.messages??[]].reverse().find(e=>e.role===`assistant`),n=Or({userContent:i,assistantContent:typeof e?.content==`string`?e.content:``,reasoning:e?.reasoning});n.length&&kr({sessionId:r,model:e?.model??t.model,messages:n})}if(ye&&t&&!h.signal.aborted&&K.current){let e=K.current.sessions.find(e=>e.id===r),n=e?.messages??[];if(e&&!ri.current.has(r)&&gr(e.title,n)){let e=hr(n);e&&(ri.current.add(r),vr(t,e).then(e=>{if(!e||!K.current)return;let t=K.current.sessions.find(e=>e.id===r);t&&gr(t.title,t.messages)&&q(Je(K.current,r,e))}))}}let o=K.current?.activeId===r,s=null;if(o){s=Bi.current,Bi.current=null,!s&&zi.current.length&&(s=zi.current[0],Vi(zi.current.slice(1)));let e=Sl(ti.current);if(!s&&!N&&Ol({goalActive:!!e,turnOk:ye,aborted:h.signal.aborted,hasFollowUp:!1,askUserPending:!!Yr.current,roundsUsed:ni.current,maxRounds:3})){let t=ni.current+1;ni.current=t,s={id:`goal_drv_${Date.now().toString(36)}`,content:El(e,t,3),files:[],refs:[],imgs:[]}}}s&&window.setTimeout(()=>{qa(s)},0)}}function Ja(){Bi.current=null,Vi([]),ni.current=0;let e=K.current?.activeId;e&&Pa(e,e=>{let t=e[e.length-1];if(t?.role!==`assistant`)return e;let n=e.slice();return n[n.length-1]={...t,turnStatus:`stopped`,activitySteps:(t.activitySteps??[]).map(e=>e.status===`running`?{...e,status:`done`}:e)},n}),ja(e)}function Ya(e){Vi(zi.current.filter(t=>t.id!==e))}function Xa(e){let t=zi.current.find(t=>t.id===e);t&&(Ya(e),d(t.content),p(t.files),x(t.imgs),C(t.refs),requestAnimationFrame(()=>Wi.current?.focus()))}function Za(e){let t=zi.current.find(t=>t.id===e);t&&(Vi(zi.current.filter(t=>t.id!==e)),G.current?(Bi.current=t,ja(K.current?.activeId)):qa(t))}function Qa(e){let t=[...zi.current],n=e??t.shift()??null;n&&(Vi(t),G.current?(Bi.current=n,ja(K.current?.activeId)):qa(n))}function $a(e,t){let n=!(s[e]?.reasoningOpen??!1);if(l(t=>t.map((t,n)=>n===e?{...t,reasoningOpen:!t.reasoningOpen}:t)),n){let e=t.currentTarget;requestAnimationFrame(()=>{(e.nextElementSibling??e).scrollIntoView({block:`nearest`,behavior:`smooth`})})}}function eo(e){e&&(u.trim()||f.length>0||_.length>0||S.length>0?Zi.current[e]={input:u,attachments:f,images:_,docRefs:S}:delete Zi.current[e])}function Y(e){let t=e?Zi.current[e]:void 0;d(t?.input??``),p(t?.attachments??[]),x(t?.images??[]),C(t?.docRefs??[])}function to(e){e?.abortRun!==!1&&ja(K.current?.activeId),G.current=!1,wt(!1),p([]),x([]),C([]),d(``),z(null),fn(!1),sa.current=!0,e?.clearDraft&&K.current?.activeId&&delete Zi.current[K.current.activeId]}function X(e,t){if(!K.current)return;Gn(`dialog`);let n=K.current.activeId,r=K.current.sessions.find(e=>e.id===n),i=!!r&&!r.archived&&!r.deleted&&(!Array.isArray(r.messages)||r.messages.length===0),a=n=>({...n,title:n.title?.trim()||`新对话`,caseGen:e===`caseGen`?t:void 0,promptGen:e===`promptGen`?t:void 0,knowledgeGen:e===`knowledgeGen`?t:void 0,updatedAt:Date.now()}),o;if(i&&n)to({clearDraft:!0,abortRun:!1}),o={...K.current,activeId:n,sessions:K.current.sessions.map(e=>e.id===n?a(e):e)};else{eo(n),to({clearDraft:!0,abortRun:!1});let e=Ca(n)??K.current,t=V?.workspace?.trim()||void 0;o=et(e,{workspacePath:t,access:je()});let r=o.activeId;o={...o,sessions:o.sessions.map(e=>e.id===r?a(e):e)}}q(o),l([]),k(e===`caseGen`?t:null),A.current=e===`caseGen`?t:null,oe(e===`promptGen`?t:null),se.current=e===`promptGen`?t:null,ue(e===`knowledgeGen`?t:null),de.current=e===`knowledgeGen`?t:null;let s=o.sessions.find(e=>e.id===o.activeId)?.workspacePath||V?.workspace?.trim()||V?.projectRoot;s&&In(e=>({...e,[s]:!0})),_a(o.sessions.find(e=>e.id===o.activeId))}async function no(e){let t=K.current;if(!t)return;let n=t.sessions.find(e=>e.id===t.activeId),r=la.current?.harnessRoot?.trim()||la.current?.projectRoot?.trim()||la.current?.workspace?.trim(),i=n?.pluginDev?.active?n.pluginDev:{active:!0,requirement:e.trim(),confirmedAt:Date.now()};if(q(Re(t,{pluginDev:i,access:ln===`full`?`full`:`readwrite`,...r?{workspacePath:r}:{}})),P(i),me.current=i,F.current=null,co(),ai(`off`),r&&In(e=>({...e,[r]:!0})),W&&r&&la.current?.workspace!==r)try{ma(await rn(r))}catch{}}function ro(e){e?.active?X(`caseGen`,e):(k(null),A.current=null,K.current&&q(Re(K.current,{caseGen:void 0})))}function io(e){e?.active?X(`promptGen`,e):(oe(null),se.current=null,K.current&&q(Re(K.current,{promptGen:void 0})))}function ao(e){e?.active?X(`knowledgeGen`,e):(ue(null),de.current=null,K.current&&q(Re(K.current,{knowledgeGen:void 0})))}function oo(e){if(we(!1),!K.current)return;Gn(`dialog`);let t=K.current.activeId;eo(t),to({clearDraft:!0,abortRun:!1});let n=Ca(t)??K.current,r=e?.trim()||V?.workspace?.trim()||void 0,i=et(n,{workspacePath:r,access:je()});q(i),l([]),k(null),oe(null),ue(null),P(null),me.current=null,Qr([]),ti.current=null,ei(null),ni.current=0,ai(`off`),si(e=>e===`pluginDev`?null:e),so(),co();let a=r||V?.projectRoot;a&&In(e=>({...e,[a]:!0})),_a(i.sessions.find(e=>e.id===i.activeId))}function so(){let e=Yr.current;e&&(Yr.current=null,pi(null),hi({}),_i(0),yi(!1),xi(null),Ci(!1),Ti(``),e.resolve(JSON.stringify({canceled:!0,error:`user aborted`})))}function co(){let e=Xr.current;e&&(Xr.current=null,di(null),e.resolve(JSON.stringify({approved:!1,canceled:!0})))}function lo(){let e=Xr.current;e&&(Xr.current=null,di(null),ai(`approved`),e.resolve(JSON.stringify({approved:!0,message:`用户已批准计划,可以开始实施`})))}function uo(){let e=Xr.current;e&&(Xr.current=null,di(null),ai(`planning`),e.resolve(JSON.stringify({approved:!1,message:`用户驳回了计划,请修订后再次 submit_plan`})))}function fo(){ai(e=>e===`off`?(si(`plan`),`planning`):(co(),si(e=>e===`plan`?null:e),`off`))}function po(e,t){return!e||!t?!1:t.skipped||t.text.trim()!==``?!0:e.options?.length?t.selected.length>0:!1}function mo(e,t,n){let r=Yr.current;if(!r)return;Yr.current=null,pi(null),hi({}),_i(0),yi(!1),xi(null),Ci(!1),Ti(``),z(null);let i=t.filter(e=>e.skipped).length,a=String(n?.skipReason??``).trim();r.resolve(JSON.stringify({answers:t,summary:rl(e,t),...i?{skipped:!0,approvalRequired:!0,...a?{skipReason:a}:{},note:`用户跳过了部分或全部问题:跳过的题不算确认,也未批准实施。`+(a?`用户给出的跳过原因:${a}。`:``)+`本轮只允许只读调研与文字方案,禁止 fs_write / fs_mkdir / 改配置;请先说明采用的默认假设(哪几项按推荐)与准备改动的范围`+(a?`,并针对上述原因给出调整`:``)+`,然后等用户明确回复「开始实施」再动手。`}:{note:`answers 为结构化答案;summary 是同一批答案的中文文本版本,可直接据此继续,无需再次提问。`},...n}))}function ho(e,t,n){hi(r=>{let i=r[e.id]??{selected:[],text:``},a=e.multi_select?n?i.selected.filter(e=>e!==t):[...i.selected,t]:[t];return{...r,[e.id]:{selected:a,text:``,skipped:!1}}}),xi(null),e.multi_select||_i(e=>Math.min(e+1,(fi?.length??1)-1))}function go(e){let t=fi?.length??0;t&&(_i(Math.max(0,Math.min(e,t-1))),xi(null))}function _o(e,t){e&&(hi(n=>{let r=n[e.id]??{selected:[],text:``};return{...n,[e.id]:{selected:e.multi_select?r.selected:[],text:t,skipped:!1}}}),xi(null))}function vo(e,t){let n=t.trim(),r=n&&e.options?.length?tl(e,n):null,i=r?{selected:r,text:``,skipped:!1}:{selected:e.multi_select?mi[e.id]?.selected??[]:[],text:n,skipped:!1},a={...mi,[e.id]:i};hi(a),xi(null),Es?bo(a):go(Cs+1)}function yo(e){return(fi??[]).map(t=>{let n=nl(t,e[t.id]??{selected:[],text:``});return n.skipped||n.text?.trim()||n.selected?.length?n:{id:t.id,selected:[],skipped:!0}})}function bo(e=mi,t=!1){let n=fi;if(!n?.length||!Yr.current)return!1;let r=yo(e),i=r.findIndex(e=>!e.skipped&&!e.text?.trim()&&!e.selected?.length);if(i>=0)return go(i),xi(n[i]?.options?.length?`请先选择选项再提交`:`请先填写回答再提交`),!1;if(!t&&r.some(e=>e.skipped))return Ci(!0),xi(null),!1;let a=wi.trim();return mo(n,r,a?{skipReason:a}:void 0),!0}function xo(){let e=fi,t=ws;if(!e?.length||!t)return;let n={...mi,[t.id]:{selected:[],text:``,skipped:!0}};hi(n),xi(null),Es?bo(n):go(Cs+1)}function So(){bo(mi,!0)}function Co(){Ci(!1);let e=yo(mi).findIndex(e=>e.skipped);go(e>=0?e:0)}function wo(e){if(we(!1),!K.current||(Gn(`dialog`),Un(null),e===K.current.activeId))return;let t=K.current.activeId;eo(t),so(),co(),ai(`off`),z(null),fn(!1),sa.current=!0;let n=Ca(t)??K.current;n.sessions.some(t=>t.id===e)||(n=K.current);let r=Be(n,e),i=r.sessions.find(t=>t.id===e),a=Hr.current.get(e)?.messages??i?.messages??[];ua.current=a,l(a);let o=Hr.current.has(e)||Tt.includes(e);G.current=o,wt(o),Vr.current=Hr.current.get(e)?.abort??null,o&&!Gr.current.has(e)&&Na(e,0),k(i?.caseGen?.active?i.caseGen:null),oe(i?.promptGen?.active?i.promptGen:null),ue(i?.knowledgeGen?.active?i.knowledgeGen:null),P(i?.pluginDev?.active?i.pluginDev:null),si(e=>i?.pluginDev?.active?`pluginDev`:e===`pluginDev`?null:e),Qr($c(i?.todos));{let e=bl(i?.goal);ti.current=e,ei(e),ni.current=0}Y(e),q(r),_a(i)}function To(e){if(!K.current)return;Un(null),ut(null);let t=K.current.activeId===e;t&&to({clearDraft:!0}),delete Zi.current[e];let n=rt(K.current,e);if(q(n),t){let e=n.sessions.find(e=>e.id===n.activeId);l(e?.messages??[]),k(e?.caseGen?.active?e.caseGen:null),oe(e?.promptGen?.active?e.promptGen:null),ue(e?.knowledgeGen?.active?e.knowledgeGen:null),P(e?.pluginDev?.active?e.pluginDev:null),si(t=>e?.pluginDev?.active?`pluginDev`:t===`pluginDev`?null:t)}}function Eo(e,t){if(!K.current)return;Un(null);let n=K.current.activeId===e&&t;n&&to();let r=Xe(K.current,e,t);if(q(r),n){let e=r.sessions.find(e=>e.id===r.activeId);l(e?.messages??[])}}function Do(e){if(!K.current)return;let t=K.current.sessions.find(t=>t.id===e);t&&(Un(null),q(Ye(K.current,e,!t.pinned)))}function Oo(e){K.current&&K.current.sessions.some(t=>t.id===e)&&(Un(null),ut(null),Ae(e))}function ko(){let e=K.current?.activeId,t=K.current?.sessions.find(t=>t.id===e);t?z(Er(`stats`,t.id,t.updatedAt,()=>br(yr(t))),`ok`):z(`无活跃会话可统计`)}function Ao(e){K.current&&Te&&(ri.current.add(Te),q(Je(K.current,Te,e)),Ae(null))}function jo(){mn(e=>(He(!e),!e))}async function Mo(e){let t=Array.from(e.target.files??[]);e.target.value=``,await Fo(t)}function No(){let t=e.map(e=>({collection:e.collection,path:e.path,title:e.title,category:e.category,format:String(e.format)})),n=Tr.map(e=>({collection:`workspace`,path:e.path,title:e.name,category:Kt(V?.workspace,V?.projectRoot),format:e.type===`dir`?`dir`:`file`}));return[...t,...n]}function Po(e){e.length&&C(t=>{let n=[...t];for(let t of e){if(n.length>=$d)break;n.some(e=>e.collection===t.collection&&e.path===t.path)||n.push(t)}return n})}async function Fo(e,t){let n=[],r=[],i=[],a=cf(f,_);for(let o of e)if(a>=6)i.push(`${o.name}(最多 6 个文件)`);else try{let e=await nd(o);e.kind===`image`?r.push(await sf(e.file)):n.push({name:e.name,size:e.size,content:e.content,path:t?.get(o.name)||t?.get(e.name)}),a+=1}catch(e){i.push(e instanceof Error?e.message:String(e))}n.length&&p(e=>[...e,...n]),r.length&&x(e=>[...e,...r]),z(i.length?`以下文件未添加:${i.join(`、`)}`:null),Wi.current?.focus()}function Io(e){let t=e.clipboardData;if(!t)return;let n=Array.from(t.items??[]),r=n.filter(e=>e.kind===`file`&&e.type.startsWith(`image/`)).map(e=>e.getAsFile()).filter(e=>!!e),i=n.filter(e=>e.kind===`file`&&!e.type.startsWith(`image/`)).map(e=>e.getAsFile()).filter(e=>!!e);for(let e of Array.from(t.files??[]))e.type.startsWith(`image/`)?r.some(t=>t.name===e.name&&t.size===e.size)||r.push(e):i.some(t=>t.name===e.name&&t.size===e.size)||i.push(e);let a=dd(t),o=(t.getData(`text/plain`)||``).trim(),s=No(),c=Kt(V?.workspace,V?.projectRoot),l={projectRoot:V?.projectRoot,workspace:V?.workspace,workspaceLabel:c},u=[],d=new Map;for(let e of a){let t=md(e,l);t?(u.push(t),d.set(ad(e),t.path)):d.set(ad(e),e)}let f=null;!r.length&&!i.length&&!a.length&&ld(o)&&(f=hd(o,s));let p=[],m=[];for(let e of i){let t=d.get(e.name),n=(t?md(t,l):null)||hd(e.name,s);n?p.push(n):m.push(e)}(u.length>0||p.length>0||f||r.length>0||m.length>0)&&(e.preventDefault(),z(null),Po([...u,...p,...f?[f]:[]]),r.length&&La(r),m.length&&Fo(m,d),Wi.current?.focus())}function Lo(e){let t=e.target.closest(`[data-copy-code]`);t&&Qf(t.closest(`.code-block`)?.querySelector(`pre`)?.textContent??``).then(e=>{e&&(t.textContent=`已复制`,window.setTimeout(()=>{t.textContent=`复制`},1e3))})}let Ro=s.length===0,zo=!!(u.trim()||f.length||S.length||_.length||oi===`reports`),Bo=-1,Vo=-1;s.forEach((e,t)=>{e.role===`user`?Bo=t:e.role===`assistant`&&(Vo=t)});let Ho=e=>e===Bo||e===Vo?``:`opacity-0 group-hover:opacity-100 group-focus-within:opacity-100 transition-opacity`,Uo=uf.find(e=>e.value===ln)??uf[0],Wo=oi===`pluginDev`,qo=(a?.sessions??[]).filter(e=>!e.archived&&!e.deleted),Jo=(a?.sessions??[]).filter(e=>e.archived&&!e.deleted),Yo=V?.items??[],Qo=new Set(Yo.map(e=>e.path)),$o=V?.workspace??``,ts=V?.projectRoot??``,ns=a?.sessions.find(e=>e.id===a.activeId),rs=ns?.workspacePath,is=!rs||!Qo.has(rs),as=V?.workspace?.trim()||``,os=Yo.find(e=>e.path===as),cs=os?Lt(os,ts):as?Kt(as,ts):`工作区`,ls=Ln.trim().toLowerCase(),us=(0,U.useMemo)(()=>ls?new Set(Lc(a,Ln,{limit:50,includeArchived:!0}).map(e=>e.sessionId)):null,[ls,a,Ln]),[ps,ms]=(0,U.useState)(null);(0,U.useEffect)(()=>{if(!ls){ms(null);return}let e=!1;return ms(null),Rc(Ln,{limit:50,includeArchived:!0}).then(t=>{!e&&t?.hits&&ms(new Set(t.hits.map(e=>e.sessionId)))}),()=>{e=!0}},[ls,Ln]);let gs=ps??us,_s=gs?Jo.filter(e=>gs.has(e.id)):Jo;function vs(e){let t=e.id===`ws_project`||e.path===ts;return st(qo.filter(n=>!(n.workspacePath!==e.path&&(!t||n.workspacePath&&Qo.has(n.workspacePath)))).filter(e=>!gs||gs.has(e.id)))}let ys=Yo.filter(e=>!ls||e.name.toLowerCase().includes(ls)||e.path.toLowerCase().includes(ls)?!0:vs(e).length>0);function bs({s:e,nested:t=!1}){let n=e.id===a?.activeId,r=Hn===e.id,i=Tt.includes(e.id);return(0,Q.jsx)(zf,{s:e,nested:t,active:n,menuOpen:r,busy:i,onOpen:()=>wo(e.id),onRename:()=>Oo(e.id),onToggleMenu:()=>{ut(null),Un(r?null:e.id)},onTogglePin:()=>Do(e.id),onToggleArchive:()=>Eo(e.id,!e.archived),onExport:()=>{Un(null);let t=Il(e,`json`);z(t.ok?`已导出 ${t.filename}`:t.error)},onRemove:()=>{Un(null),ut(null),Ie(e.id)}})}let Ss=fi?.length??0,Cs=Math.max(0,Math.min(gi,Ss-1)),ws=fi?.[Cs],Ts=ws&&mi[ws.id]||{selected:[],text:``},Es=Cs>=Ss-1,Ds=po(ws,Ts),Os=(fi??[]).map((e,t)=>({q:e,index:t})).filter(({q:e})=>mi[e.id]?.skipped);return(0,Q.jsxs)(`div`,{className:`tw-app h-full min-h-0 flex overflow-hidden bg-(--tw-surface-page)`,children:[(0,Q.jsxs)(`aside`,{className:`tw-session-rail shrink-0 border-r border-(--tw-border) flex flex-col transition-[width] ${pn?`w-64`:`w-10`}`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1 ${pn?`px-2.5 pt-2.5`:`px-1 pt-2 justify-center`}`,children:[pn&&(0,Q.jsx)(`div`,{className:`flex-1 min-w-0 text-[13px] font-medium text-stone-700 truncate px-1`,children:R(`chat.workbench`,void 0,Kn.language)}),(0,Q.jsx)(`button`,{type:`button`,"aria-label":pn?`收起侧栏`:`展开侧栏`,onClick:jo,className:`w-8 h-8 shrink-0 flex items-center justify-center rounded-lg text-stone-500 hover:bg-stone-200/70`,children:(0,Q.jsx)($,{className:`w-4 h-4`,children:pn?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`}),(0,Q.jsx)(`path`,{d:`M9 3v18`})]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`}),(0,Q.jsx)(`path`,{d:`M15 3v18`})]})})})]}),pn?(0,Q.jsxs)(`div`,{className:`px-2.5 pt-2 space-y-1.5`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>oo(),className:`w-full h-9 flex items-center justify-center gap-1.5 text-[13px] font-medium text-stone-700 bg-white rounded-full border border-stone-200/80 shadow-sm hover:bg-stone-50 transition-colors`,children:[(0,Q.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Q.jsx)(`path`,{d:`M5 12h14`}),(0,Q.jsx)(`path`,{d:`M12 5v14`})]}),R(`chat.newSession`,void 0,Kn.language)]}),(0,Q.jsxs)(`button`,{type:`button`,"data-hint":`我的插件`,onClick:()=>we(e=>!e),className:`tw-rail-plugin-btn w-full h-9 flex items-center justify-center gap-1.5 text-[13px] font-medium rounded-full transition-colors ${Ce?`is-active`:``}`,children:[(0,Q.jsx)(Pf,{className:`w-3.5 h-3.5`}),`插件`]})]}):(0,Q.jsxs)(`div`,{className:`px-1 pt-1 flex flex-col gap-1`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>oo(),"data-hint":`新会话`,className:`w-8 h-8 flex items-center justify-center rounded-lg text-[#4176e6] hover:bg-white/80`,children:(0,Q.jsxs)($,{className:`w-4 h-4`,children:[(0,Q.jsx)(`path`,{d:`M5 12h14`}),(0,Q.jsx)(`path`,{d:`M12 5v14`})]})}),(0,Q.jsx)(`button`,{type:`button`,"data-hint":`我的插件`,onClick:()=>we(e=>!e),className:`tw-rail-plugin-btn tw-rail-plugin-btn--icon w-8 h-8 flex items-center justify-center rounded-lg ${Ce?`is-active`:``}`,children:(0,Q.jsx)(Pf,{className:`w-4 h-4`})})]}),pn&&(0,Q.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-2 py-3`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1 px-1.5 pb-2`,children:[(0,Q.jsx)(`div`,{className:`flex-1 text-[12px] font-semibold text-stone-500`,children:R(`chat.workspace`,void 0,Kn.language)}),(0,Q.jsx)(`button`,{type:`button`,"aria-label":`搜索`,onClick:()=>{Vn(e=>!e),Bn&&Rn(``)},className:`w-6 h-6 flex items-center justify-center rounded text-stone-400 hover:text-stone-700 hover:bg-stone-200/70`,children:(0,Q.jsx)(kf,{className:`w-3.5 h-3.5`})}),(0,Q.jsx)(`button`,{type:`button`,"data-hint":W?`添加工作区(选择本地文件夹)`:`本地文件服务未就绪`,disabled:!W||Nn,onClick:()=>void ya(),className:`w-6 h-6 flex items-center justify-center rounded text-stone-400 hover:text-stone-700 hover:bg-stone-200/70 disabled:opacity-40`,children:(0,Q.jsx)(Af,{className:`w-3.5 h-3.5`})})]}),Bn&&(0,Q.jsx)(`input`,{value:Ln,onChange:e=>Rn(e.target.value),placeholder:`搜索工作区 / 会话标题 / 消息`,className:`w-full mb-2 px-2.5 py-1.5 text-[12px] rounded-lg border border-stone-200 bg-white text-stone-700 placeholder:text-stone-400 focus:outline-none focus:ring-1 focus:ring-[#4176e6]/40`}),Pr&&(0,Q.jsx)(`div`,{className:`px-1.5 py-2 text-[11px] text-amber-700/80`,children:`本地文件服务未就绪,工作区暂不可用`}),(0,Q.jsxs)(`div`,{className:`space-y-0.5`,children:[ys.map(e=>{let t=vs(e),n=!!(Fn[e.path]??t.length>0),r=e.id===`ws_project`||e.path===ts,i=!!(ns&&(is?r:rs===e.path)),a=tt===e.id;return(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`div`,{className:`tw-project-row group relative ${i?`is-active`:``} ${n?`is-expanded`:``} ${a?`is-menu-open`:``}`,children:[(0,Q.jsxs)(`button`,{type:`button`,"data-hint":e.path,onClick:t=>{t.stopPropagation(),Un(null),ut(null),In(t=>({...t,[e.path]:!n})),W&&e.path!==$o&&ha(e.path,`select`)},className:`flex-1 min-w-0 h-full flex items-center gap-1.5 text-left outline-none focus:outline-none`,children:[(0,Q.jsx)(`span`,{className:`tw-slot tw-folder`,children:(0,Q.jsx)(Df,{open:n,className:`w-3.5 h-3.5`})}),(0,Q.jsx)(`span`,{className:`tw-slot tw-chevron`,children:(0,Q.jsx)(Of,{open:n,className:`w-3 h-3`})}),(0,Q.jsx)(`span`,{className:`tw-project-title`,children:Lt(e,ts)})]}),(0,Q.jsxs)(`div`,{className:`tw-ws-actions relative shrink-0`,"data-ws-menu":``,children:[(0,Q.jsx)(Lf,{open:a,onToggle:()=>{Un(null),ut(a?null:e.id)},onRename:()=>{Un(null),ut(null),ht(e.id)},onDelete:e.id===`ws_project`?void 0:()=>xa(e)}),(0,Q.jsx)(`button`,{type:`button`,"data-hint":`在此工作区新建会话`,onClick:t=>{t.stopPropagation(),oo(e.path)},className:`w-6 h-6 flex items-center justify-center rounded text-(--tw-label-tertiary) hover:text-(--tw-label-primary) hover:bg-(--tw-session-hover-bg)`,children:(0,Q.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Q.jsx)(`path`,{d:`M5 12h14`}),(0,Q.jsx)(`path`,{d:`M12 5v14`})]})})]})]}),(0,Q.jsx)(`div`,{className:`tw-collapse ${n?`is-open`:``}`,children:(0,Q.jsx)(`div`,{className:`tw-collapse-inner space-y-0.5 pb-0.5`,children:t.map(e=>(0,Q.jsx)(bs,{s:e,nested:!0},e.id))})})]},e.id)}),!ys.length&&W&&(0,Q.jsx)(`div`,{className:`px-2 py-3 text-xs text-stone-400`,children:`暂无工作区`})]}),_s.length>0&&(0,Q.jsxs)(`div`,{className:`mt-3 pt-2 border-t border-stone-200/60`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>gn(e=>!e),className:`w-full flex items-center gap-1 px-1.5 pb-1 text-[11px] text-stone-400 hover:text-stone-600`,children:[(0,Q.jsx)(vf,{className:`w-3 h-3 transition-transform ${hn?`rotate-180`:``}`}),`已归档 (`,_s.length,`)`]}),(0,Q.jsx)(`div`,{className:`tw-collapse ${hn?`is-open`:``}`,children:(0,Q.jsx)(`div`,{className:`tw-collapse-inner space-y-0.5`,children:_s.map(e=>(0,Q.jsx)(bs,{s:e},e.id))})})]})]}),pn&&($o||Jn||Xn)&&(0,Q.jsxs)(`div`,{className:`shrink-0 border-t border-stone-200/60 px-3 py-2 space-y-1`,children:[$o&&(0,Q.jsxs)(`div`,{className:`tw-rail-workspace-footer`,"data-hint":$o,children:[(0,Q.jsx)(`span`,{className:`tw-rail-workspace-label`,"data-i18n":`chat.workspace`,children:`工作区`}),(0,Q.jsx)(`span`,{className:`tw-rail-workspace-name`,children:Kt($o,ts)})]}),(Jn||Xn)&&(0,Q.jsx)(`div`,{className:`text-[11px] text-(--tw-accent)`,children:Xn??R(`tool.running`,void 0,Kn.language)})]})]}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex flex-col flex-1 ${Ce?`hidden`:``}`,children:[Ro?null:(0,Q.jsxs)(`div`,{className:`shrink-0 border-b border-(--tw-border) bg-(--tw-surface-page)`,children:[(0,Q.jsx)(`div`,{className:`flex items-center gap-3 px-6 pt-4 pb-2 min-w-0`,children:(0,Q.jsx)(`button`,{type:`button`,"data-hint":`点击重命名`,onClick:()=>{let e=a?.activeId;e&&Oo(e)},className:`min-w-0 flex-1 text-left text-[18px] leading-7 font-semibold text-(--tw-label-primary) truncate hover:text-[#4176e6] transition-colors`,children:a?.sessions.find(e=>e.id===a.activeId)?.title||`新对话`})}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-6 px-6`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>Gn(`dialog`),className:`relative h-10 text-sm transition-colors ${Wn===`dialog`?`text-[#4176e6] font-medium`:`text-stone-500 hover:text-stone-700`}`,children:[`对话`,Wn===`dialog`&&(0,Q.jsx)(`span`,{className:`absolute left-0 right-0 -bottom-px h-0.5 bg-[#4176e6] rounded-full`})]}),(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>Gn(`thread`),className:`relative h-10 text-sm transition-colors ${Wn===`thread`?`text-[#4176e6] font-medium`:`text-stone-500 hover:text-stone-700`}`,children:[`回合`,Wn===`thread`&&(0,Q.jsx)(`span`,{className:`absolute left-0 right-0 -bottom-px h-0.5 bg-[#4176e6] rounded-full`})]}),B.todos&&(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>Gn(`todos`),className:`relative h-10 text-sm transition-colors ${Wn===`todos`?`text-[#4176e6] font-medium`:`text-stone-500 hover:text-stone-700`}`,children:[`待办`,Wn===`todos`&&(0,Q.jsx)(`span`,{className:`absolute left-0 right-0 -bottom-px h-0.5 bg-[#4176e6] rounded-full`})]}),B.memory&&(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>Gn(`memory`),className:`relative h-10 text-sm transition-colors ${Wn===`memory`?`text-[#4176e6] font-medium`:`text-stone-500 hover:text-stone-700`}`,children:[(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[`记忆`,(bn?.suggestionCount??0)>0?(0,Q.jsx)(`span`,{className:`min-w-4.5 h-4.5 px-1 inline-flex items-center justify-center rounded-full bg-red-500 text-[10px] font-medium text-white tabular-nums leading-none`,"data-hint":`${bn?.suggestionCount} 条待确认`,children:bn.suggestionCount>99?`99+`:bn.suggestionCount}):null]}),Wn===`memory`&&(0,Q.jsx)(`span`,{className:`absolute left-0 right-0 -bottom-px h-0.5 bg-[#4176e6] rounded-full`})]})]}),$r&&$r.status!==`cleared`&&Wn===`dialog`?(0,Q.jsx)(`div`,{className:`px-6 pb-2`,children:(0,Q.jsxs)(`div`,{className:`rounded-xl border border-[#4176e6]/25 bg-[#f5f8ff] px-3 py-2 flex items-start gap-2`,children:[(0,Q.jsxs)(`span`,{className:`text-[11px] font-medium text-[#4176e6] shrink-0 pt-0.5`,children:[`目标`,$r.status===`done`?`·完成`:``]}),(0,Q.jsx)(`span`,{className:`flex-1 min-w-0 text-[12px] leading-5 ${$r.status===`done`?`text-stone-400 line-through`:`text-stone-800`}`,children:$r.text}),(0,Q.jsx)(`button`,{type:`button`,"data-hint":`清除目标`,className:`text-[11px] text-stone-400 hover:text-stone-600 shrink-0`,onClick:()=>{ti.current=null,ei(null),ni.current=0,K.current&&q(Re(K.current,{goal:void 0}))},children:`清除`})]})}):null,Zr.length>0&&Wn===`dialog`?(0,Q.jsx)(`div`,{className:`px-6 pb-3`,children:(0,Q.jsxs)(`div`,{className:`rounded-xl border border-stone-200 bg-white px-3 py-2.5`,children:[(0,Q.jsxs)(`div`,{className:`text-[11px] font-medium text-stone-500 mb-1.5`,children:[`待办 · `,Zr.filter(e=>e.status===`completed`).length,`/`,Zr.length]}),(0,Q.jsx)(`ul`,{className:`space-y-1 max-h-28 overflow-y-auto`,children:Zr.map((e,t)=>(0,Q.jsxs)(`li`,{className:`flex items-start gap-2 text-[12px] text-stone-700`,children:[(0,Q.jsx)(`span`,{className:`mt-0.5 w-3.5 h-3.5 rounded-sm border shrink-0 flex items-center justify-center text-[9px] ${e.status===`completed`?`bg-emerald-500 border-emerald-500 text-white`:e.status===`in_progress`?`border-[#4176e6] text-[#4176e6]`:`border-stone-300 text-transparent`}`,"aria-hidden":!0,children:e.status===`completed`?`✓`:e.status===`in_progress`?`…`:``}),(0,Q.jsx)(`span`,{className:e.status===`completed`?`line-through text-stone-400`:``,children:e.content})]},`${t}-${e.content}`))})]})}):null]}),Wn===`todos`&&B.todos?(0,Q.jsx)(`div`,{className:`flex-1 min-h-0 bg-(--tw-surface-page) tw-pane-enter`,children:(0,Q.jsx)(Id,{})},`todos-${a?.activeId??``}`):Wn===`memory`&&B.memory?(0,Q.jsx)(`div`,{className:`flex-1 min-h-0 bg-(--tw-surface-page) tw-pane-enter`,children:(0,Q.jsx)(Ed,{live:Ar,pluginOn:!!B.memory,workspacePath:a?.sessions.find(e=>e.id===a.activeId)?.workspacePath||V?.projectRoot||``})},`memory-${a?.activeId??``}`):Wn===`thread`?(0,Q.jsx)(`div`,{className:`flex-1 min-h-0 bg-(--tw-surface-page) tw-pane-enter overflow-y-auto px-12 sm:px-16 lg:px-20 py-6`,children:(0,Q.jsx)(ap,{messages:s,busy:!!(a?.activeId&&Tt.includes(a.activeId)),onRestoreCheckpoint:(e,t)=>{let n=K.current?.activeId;if(!n)return;if(Tt.includes(n)||St){z(`请等待当前回复结束后再从此处继续`);return}let r=Math.max(0,Math.min(e,ua.current.length-1)),i=ua.current.slice(0,r+1);ua.current=i,l(i),K.current&&q(Ve(K.current,i,{touchUpdatedAt:!0}));let a=`请从第 ${t} 轮继续`;Gn(`dialog`),d(a),z(`已回到第 ${t} 轮,正在继续…`,`ok`),window.setTimeout(()=>{Ka(a)},0)}})},`thread-${a?.activeId??``}`):(0,Q.jsxs)(`div`,{className:`relative flex-1 min-h-0 flex flex-col${Ro?` justify-center`:``}`,children:[Ro?(0,Q.jsxs)(`div`,{className:`shrink-0 flex flex-col items-center text-center px-8 sm:px-10 lg:px-12 pb-8`,children:[(0,Q.jsx)(`img`,{src:`/brand/brand-mark.png`,alt:``,width:64,height:64,className:`w-16 h-16 rounded-[14px] object-contain`}),(0,Q.jsx)(`h2`,{className:`mt-5 text-[22px] leading-8 font-semibold tracking-tight text-stone-800 text-balance`,children:R(`chat.emptyTitle`,void 0,Kn.language)})]}):null,Ro?null:(0,Q.jsxs)(`div`,{className:`relative flex-1 min-h-0`,children:[(0,Q.jsx)(`div`,{ref:Ui,onScroll:Oa,className:`h-full overflow-y-auto px-8 sm:px-10 lg:px-12 py-6`,style:{fontSize:`var(--tw-session-font-size, ${Kn.sessionFontSize}px)`},children:(0,Q.jsx)(`div`,{className:`w-full max-w-[min(64rem,100%)] mx-auto flex flex-col gap-4`,onClick:Lo,children:s.map((e,n)=>e.role===`user`?(0,Q.jsxs)(`div`,{className:`group flex flex-col items-end gap-1`,children:[e.refs?.length||e.attachments?.length||e.images?.length?(0,Q.jsxs)(`div`,{className:`flex flex-wrap justify-end gap-1.5 max-w-[82%]`,children:[e.refs?.map(e=>(0,Q.jsxs)(`span`,{className:`flex items-center gap-1.5 px-2.5 py-1.5 text-xs text-[#4176e6] bg-white border border-[#4176e6]/30 rounded-lg`,"data-hint":e.path,children:[(0,Q.jsx)(wf,{className:`w-3.5 h-3.5`}),(0,Q.jsx)(`span`,{className:`text-[10px] text-stone-400 shrink-0`,children:Bu(e.format)}),(0,Q.jsx)(`span`,{className:`max-w-40 truncate`,children:e.title})]},e.path)),e.attachments?.map(e=>(0,Q.jsxs)(`span`,{className:`flex items-center gap-1.5 px-2.5 py-1.5 text-xs text-stone-600 bg-white border border-stone-200 rounded-lg`,children:[(0,Q.jsx)(wf,{className:`w-3.5 h-3.5 text-[#4176e6]`}),(0,Q.jsx)(`span`,{className:`max-w-48 truncate`,children:e.name}),(0,Q.jsx)(`span`,{className:`text-stone-400`,children:Xf(e.size)})]},e.name)),e.images?.map(e=>(0,Q.jsx)(`a`,{href:e.dataUrl,target:`_blank`,rel:`noreferrer`,className:`block overflow-hidden rounded-lg border border-stone-200 bg-white`,"data-hint":e.name,children:(0,Q.jsx)(`img`,{src:e.dataUrl,alt:e.name,className:`max-h-40 max-w-48 object-contain`})},e.id))]}):null,e.content&&(0,Q.jsx)(`div`,{className:`tw-chat-text max-w-[82%] px-4 py-2.5 bg-[#edf3fe] rounded-2xl whitespace-pre-wrap break-words`,children:e.content}),(0,Q.jsxs)(`div`,{className:`tw-msg-actions ${Ho(n)}`,children:[e.time!=null&&(0,Q.jsx)(`span`,{className:`tw-msg-action-time pr-0.5`,children:Zf(e.time)}),(0,Q.jsx)($f,{text:e.content})]})]},n):(0,Q.jsxs)(`div`,{className:`group`,children:[e.turnStatus===`stopped`?(0,Q.jsxs)(`div`,{className:`mb-2`,children:[(0,Q.jsx)(`div`,{className:`text-[13px] text-stone-500 py-1`,children:`已停止`}),(0,Q.jsx)(`div`,{className:`border-t border-stone-200/80`})]}):null,(()=>{let t=e.activitySteps??[],r=t.some(e=>e.status===`running`),i=n===s.length-1&&e.turnStatus!==`stopped`&&(St||r),a=i&&!e.content,o=t.filter(e=>e.kind!==`thinking`);if(!(a||e.reasoning||o.length>0||t.length>0))return null;let c=e.reasoningOpen??!1,l=i||c||r,u=a&&!c&&!l&&e.reasoning?gf(e.reasoning).replaceAll(`**`,``):``;return(0,Q.jsxs)(`div`,{className:`mb-2`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:e=>$a(n,e),className:`flex w-full items-center gap-2 py-1 text-left select-none`,children:[a||i&&!e.content?(0,Q.jsx)(`span`,{className:`w-3.5 h-3.5 shrink-0 rounded-full border-2 border-purple-400 border-t-transparent animate-spin`}):(0,Q.jsxs)($,{className:`w-3.5 h-3.5 shrink-0 text-stone-400`,children:[(0,Q.jsx)(`path`,{d:`M15 14c.2-1 .7-1.7 1.5-2.5 1-.9 1.5-2.2 1.5-3.5A6 6 0 0 0 6 8c0 1 .2 2.2 1.5 3.5.7.7 1.3 1.5 1.5 2.5`}),(0,Q.jsx)(`path`,{d:`M9 18h6`}),(0,Q.jsx)(`path`,{d:`M10 22h4`})]}),(0,Q.jsx)(`span`,{className:`text-[13px] font-medium shrink-0 ${i&&!e.content?`text-shimmer`:`text-shimmer-static`}`,children:i&&!e.content?t.some(e=>e.kind!==`thinking`&&e.status===`running`)?`正在分析请求`:`思考中…`:i?`正在生成…`:e.turnStatus===`stopped`?`已完成分析`:`思考完成`}),!i&&e.reasoningDuration!=null&&(0,Q.jsxs)(`span`,{className:`text-xs text-stone-400 shrink-0`,children:[`用时 `,e.reasoningDuration,`s`]}),(0,Q.jsx)(vf,{className:`w-3.5 h-3.5 shrink-0 text-stone-400 transition-transform ${c?`rotate-180`:``}`}),u?(0,Q.jsx)(`span`,{className:`flex-1 min-w-0 truncate text-xs text-shimmer-muted think-mask`,children:u}):null]}),l&&t.length>0?(0,Q.jsx)(`ul`,{className:`mt-1.5 mb-1 pl-5.5 space-y-1.5`,children:t.map(e=>(0,Q.jsxs)(`li`,{className:`text-[12px] flex items-start gap-2 min-w-0 ${e.status===`error`?`text-red-600`:e.status===`running`?`text-stone-600`:`text-stone-500`}`,children:[(0,Q.jsx)(mf,{kind:e.kind,status:e.status}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1 leading-5`,children:[(0,Q.jsx)(`span`,{className:`font-medium ${e.status===`running`?`text-shimmer`:``}`,children:e.title}),e.detail?(0,Q.jsxs)(`span`,{className:`text-stone-400`,children:[` · `,(0,Q.jsx)(`span`,{className:e.status===`error`?`text-red-600`:e.status===`running`?`text-shimmer-muted`:``,"data-hint":e.detail,children:e.detail.length>72?`${e.detail.slice(0,72)}…`:e.detail})]}):e.status===`running`?(0,Q.jsxs)(`span`,{className:`text-stone-400 text-shimmer-muted`,children:[` · `,`…`]}):null]})]},e.id))}):null,c&&e.reasoning?(0,Q.jsx)(`div`,{className:`mt-1.5 mb-2 pl-5.5 text-[13px] leading-5 text-stone-500 whitespace-pre-wrap max-h-80 overflow-y-auto`,children:e.reasoning}):null,e.turnStatus===`stopped`?(0,Q.jsx)(`div`,{className:`mt-1.5 pl-5.5`,children:(0,Q.jsx)(`span`,{className:`tw-turn-stopped-pill`,children:`已停止`})}):null]})})(),e.content?(0,Q.jsx)(`div`,{className:`chat-md prose prose-sm prose-stone max-w-none tw-chat-text`,dangerouslySetInnerHTML:{__html:Go(e.content)}}):null,e.caseFile?(0,Q.jsxs)(`button`,{type:`button`,"data-focus-doc":`cases:${e.caseFile.path.replace(/\\/g,`/`)}`,"data-hint":`双击本地打开`,onDoubleClick:()=>{ve(`cases`,e.caseFile.path).catch(e=>z(e instanceof Error?e.message:String(e)))},className:`mt-3 w-full max-w-md flex items-center gap-3 rounded-xl border border-stone-200 bg-white px-3 py-2.5 text-left hover:border-[#4176e6] hover:bg-[#f5f8ff] transition-colors cursor-pointer`,children:[(0,Q.jsx)(`span`,{className:`w-10 h-10 rounded-lg bg-emerald-50 text-emerald-700 flex items-center justify-center text-[10px] font-semibold shrink-0`,children:e.caseFile.name.split(`.`).pop()?.toUpperCase()||`FILE`}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`span`,{className:`block text-sm text-stone-800 truncate`,children:e.caseFile.name}),(0,Q.jsxs)(`span`,{className:`block text-[11px] text-stone-400 truncate`,children:[xe(`cases`),e.caseFile.path,e.caseFile.count>0?` · ${e.caseFile.count} 条`:``,` · 双击本地打开`]})]})]}):null,e.docsFile?(0,Q.jsxs)(`button`,{type:`button`,"data-focus-doc":`${e.docsFile.root}:${e.docsFile.path.replace(/\\/g,`/`)}`,"data-hint":`点击本地打开`,onClick:()=>{ve(e.docsFile.root,e.docsFile.path).catch(e=>z(e instanceof Error?e.message:String(e)))},className:`mt-3 w-full max-w-md flex items-center gap-3 rounded-xl border border-stone-200 bg-white px-3 py-2.5 text-left hover:border-[#4176e6] hover:bg-[#f5f8ff] transition-colors cursor-pointer`,children:[(0,Q.jsx)(`span`,{className:`w-10 h-10 rounded-lg flex items-center justify-center text-[10px] font-semibold shrink-0 ${e.docsFile.root===`knowledge`?`bg-amber-50 text-amber-800`:`bg-sky-50 text-sky-700`}`,children:e.docsFile.name.split(`.`).pop()?.toUpperCase()||`MD`}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`span`,{className:`block text-sm text-stone-800 truncate`,children:e.docsFile.name}),(0,Q.jsxs)(`span`,{className:`block text-[11px] text-stone-400 truncate`,children:[xe(e.docsFile.root),e.docsFile.path,e.docsFile.note?` · ${e.docsFile.note}`:``,` · 点击打开`]})]})]}):null,e.presentFiles?.length?e.presentFiles.map(e=>(0,Q.jsxs)(`button`,{type:`button`,"data-hint":`点击本地打开`,onClick:()=>{Mt(e.path,ln).catch(e=>z(e instanceof Error?e.message:String(e)))},className:`mt-3 w-full max-w-md flex items-center gap-3 rounded-xl border border-stone-200 bg-white px-3 py-2.5 text-left hover:border-[#4176e6] hover:bg-[#f5f8ff] transition-colors cursor-pointer`,children:[(0,Q.jsx)(`span`,{className:`w-10 h-10 rounded-lg bg-violet-50 text-violet-700 flex items-center justify-center text-[10px] font-semibold shrink-0`,children:e.name.split(`.`).pop()?.toUpperCase()||`FILE`}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`span`,{className:`block text-sm text-stone-800 truncate`,children:e.name}),(0,Q.jsxs)(`span`,{className:`block text-[11px] text-stone-400 truncate`,children:[e.path,e.description?` · ${e.description}`:``,` · 点击打开`]})]})]},e.path)):null,e.content&&!(n===s.length-1&&St)?(0,Q.jsxs)(`div`,{className:`tw-msg-actions mt-1 ${Ho(n)}`,children:[(0,Q.jsx)($f,{text:e.content}),e.usage&&(0,Q.jsx)(sp,{usage:e.usage,model:e.model??t?.model}),e.time!=null&&(0,Q.jsx)(`span`,{className:`tw-msg-action-time`,children:Zf(e.time)})]}):null]},n))})}),dn&&(0,Q.jsx)(`button`,{type:`button`,onClick:ka,"aria-label":`回到底部`,className:`absolute bottom-3 right-8 sm:right-10 lg:right-12 w-8 h-8 rounded-full bg-white border border-stone-200 shadow-md flex items-center justify-center text-stone-500 hover:text-stone-800 transition-colors`,children:(0,Q.jsx)(vf,{className:`w-4 h-4`})})]},`dialog-${a?.activeId??``}`),Rt&&(0,Q.jsx)(`div`,{className:`shrink-0 px-8 sm:px-10 lg:px-12 pb-2`,children:(0,Q.jsxs)(`div`,{ref:Yi,className:`w-full max-w-[min(64rem,100%)] mx-auto flex items-start gap-3 px-4 py-3 rounded-xl text-sm border ${nn===`ok`?`tw-notice-anim`:``} ${nn===`ok`?`bg-emerald-50 border-emerald-200 text-emerald-900`:`bg-red-50 border-red-200 text-red-800`}`,children:[(0,Q.jsx)(`span`,{className:`mt-0.5 w-5 h-5 shrink-0 rounded-full flex items-center justify-center text-xs font-semibold ${nn===`ok`?`bg-emerald-100 text-emerald-700`:`bg-red-100 text-red-600`}`,children:nn===`ok`?`i`:`!`}),(0,Q.jsx)(`pre`,{className:`flex-1 min-w-0 m-0 font-sans text-[13px] leading-5 whitespace-pre-wrap break-words`,children:Rt.replace(/\*\*/g,``).replace(/\s*:\s*\*\*/g,`: `).trim()}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>z(null),className:`shrink-0 text-xs ${nn===`ok`?`text-emerald-500 hover:text-emerald-700`:`text-red-400 hover:text-red-600`}`,children:`关闭`})]})}),(0,Q.jsxs)(`div`,{className:`shrink-0 px-8 sm:px-10 lg:px-12 pb-5`,children:[(0,Q.jsxs)(`div`,{className:`w-full max-w-[min(64rem,100%)] mx-auto`,children:[M?.active&&B.promptGen?(0,Q.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 px-3 py-2 rounded-xl border border-[#4176e6]/30 bg-[#edf3fe] text-xs text-[#3565c7]`,children:[(0,Q.jsxs)(`span`,{className:`flex-1 min-w-0 truncate`,children:[`生成提示词已启用 · `,ss(M)]}),(0,Q.jsx)(`button`,{type:`button`,className:`shrink-0 hover:underline`,onClick:()=>j(!0),children:`改配置`}),(0,Q.jsx)(`button`,{type:`button`,className:`shrink-0 text-stone-500 hover:text-stone-800`,onClick:()=>io(null),children:`取消`})]}):null,le?.active&&B.knowledgeGen?(0,Q.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 px-3 py-2 rounded-xl border border-amber-300/60 bg-amber-50 text-xs text-amber-900`,children:[(0,Q.jsxs)(`span`,{className:`flex-1 min-w-0 truncate`,children:[`生成知识库已启用 · `,xs(le)]}),(0,Q.jsx)(`button`,{type:`button`,className:`shrink-0 hover:underline`,onClick:()=>N(!0),children:`改配置`}),(0,Q.jsx)(`button`,{type:`button`,className:`shrink-0 text-stone-500 hover:text-stone-800`,onClick:()=>ao(null),children:`取消`})]}):null,re?.active&&B.caseGen?(0,Q.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 px-3 py-2 rounded-xl border border-[#4176e6]/30 bg-[#edf3fe] text-xs text-[#3565c7]`,children:[(0,Q.jsxs)(`span`,{className:`flex-1 min-w-0 truncate`,children:[`生成测试用例已启用 · `,Ko(re)]}),(0,Q.jsx)(`button`,{type:`button`,className:`shrink-0 hover:underline`,onClick:()=>D(!0),children:`改配置`}),(0,Q.jsx)(`button`,{type:`button`,className:`shrink-0 text-stone-500 hover:text-stone-800`,onClick:()=>ro(null),children:`取消`})]}):null,Cr.length>0?(0,Q.jsx)(`div`,{className:`mb-2 rounded-xl border border-stone-200/80 bg-stone-100/80 overflow-hidden`,children:Cr.map(e=>(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 border-b border-stone-200/60 last:border-b-0`,children:[(0,Q.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-stone-400 shrink-0`,"aria-hidden":!0}),(0,Q.jsx)(`span`,{className:`flex-1 min-w-0 truncate text-[13px] text-stone-700`,children:Hi(e)}),(0,Q.jsx)(`button`,{type:`button`,"data-hint":`编辑回输入框`,onClick:()=>Xa(e.id),className:`tw-icon-btn w-7 h-7 rounded-md flex items-center justify-center outline-none`,children:(0,Q.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Q.jsx)(`path`,{d:`M12 20h9`}),(0,Q.jsx)(`path`,{d:`M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z`})]})}),(0,Q.jsx)(`button`,{type:`button`,"data-hint":`从队列移除`,onClick:()=>Ya(e.id),className:`tw-icon-btn w-7 h-7 rounded-md flex items-center justify-center outline-none`,children:(0,Q.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Q.jsx)(`path`,{d:`M3 6h18`}),(0,Q.jsx)(`path`,{d:`M8 6V4h8v2`}),(0,Q.jsx)(`path`,{d:`M19 6l-1 14H6L5 6`})]})}),(0,Q.jsx)(`button`,{type:`button`,"data-hint":`插话立即发送(其后队列仍会续发)`,onClick:()=>Za(e.id),className:`tw-icon-btn w-7 h-7 rounded-md flex items-center justify-center outline-none text-[#4176e6]`,children:(0,Q.jsx)(Ef,{className:`w-3.5 h-3.5`})})]},e.id))}):null,ui?(0,Q.jsxs)(`div`,{className:`mb-2 rounded-xl border border-amber-300/60 bg-amber-50/90 px-4 py-3 shadow-sm`,children:[(0,Q.jsx)(`div`,{className:`text-[13px] font-medium text-stone-800 mb-1`,children:`待批准计划`}),(0,Q.jsx)(`div`,{className:`text-[14px] font-medium text-stone-900`,children:ui.title}),ui.summary?(0,Q.jsx)(`p`,{className:`mt-1 text-[13px] text-stone-600 leading-5`,children:ui.summary}):null,(0,Q.jsx)(`ol`,{className:`mt-2 list-decimal pl-5 space-y-1 text-[13px] text-stone-700`,children:ui.steps.map((e,t)=>(0,Q.jsx)(`li`,{children:e},`${t}-${e.slice(0,24)}`))}),(0,Q.jsxs)(`div`,{className:`mt-3 flex items-center justify-end gap-2`,children:[(0,Q.jsx)(`button`,{type:`button`,className:`h-8 px-3 rounded-lg border border-stone-200 bg-white text-[12px] text-stone-600 hover:bg-stone-50`,onClick:()=>uo(),children:`驳回`}),(0,Q.jsx)(`button`,{type:`button`,className:`h-8 px-3 rounded-lg bg-[#4176e6] text-[12px] text-white hover:bg-[#3467d4]`,onClick:()=>lo(),children:`批准实施`})]})]}):null,Ei?(0,Q.jsx)(qd,{kind:Ei.kind,items:Ei.items,manual:Ei.manual,quick:Ei.quick,quickNote:Ei.quickNote,tasksOn:B.tasks,closing:Oi,onConfirm:e=>{Ei.manual?(Fi(null),Ri(Ei.kind,e)):Fi(e)},onCancel:()=>Fi(null)}):null,Ss>0&&ws?(0,Q.jsxs)(`div`,{className:`mb-2 flex max-h-[min(60vh,520px)] flex-col overflow-hidden rounded-2xl border border-stone-200 bg-white shadow-[0_6px_24px_rgba(15,23,42,0.08)]`,children:[(0,Q.jsxs)(`div`,{className:`flex shrink-0 justify-between gap-4 px-5 ${vi?`items-center py-3.5`:`items-start pt-4`}`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`div`,{className:`mb-1 text-[11px] leading-4 text-stone-400`,children:Si?`跳过确认`:ws.header||`模型需要你的确认`}),(0,Q.jsx)(`h3`,{className:`text-[15px] leading-5.5 font-medium text-stone-900`,children:Si?`确认 ${Os.length} 道跳过的题怎么处理`:ws.question})]}),(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[vi?(0,Q.jsx)(`span`,{className:`text-[11px] leading-4 text-stone-400`,children:Si?`已跳过 ${Os.length} 题`:`第 ${Cs+1} 步 / 共 ${Ss} 步`}):null,(0,Q.jsx)(`button`,{type:`button`,"aria-label":vi?`展开问题`:`收起问题`,onClick:()=>yi(e=>!e),className:`grid h-6 w-6 place-items-center rounded-full text-stone-400 outline-none hover:bg-stone-100 hover:text-stone-600`,children:(0,Q.jsx)(vf,{className:`h-4 w-4 transition-transform ${vi?`rotate-180`:``}`})})]})]}),vi?null:Si?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto overscroll-contain px-5 py-2`,children:[(0,Q.jsx)(`p`,{className:`text-[12px] leading-5 text-stone-500`,children:`跳过不算确认,本轮不会开始改代码。留下原因后我只出方案,等你回复「开始实施」。`}),(0,Q.jsx)(`ul`,{className:`mt-2 space-y-1 rounded-lg bg-stone-50 px-3 py-2`,children:Os.map(({q:e,index:t})=>(0,Q.jsxs)(`li`,{className:`text-[12px] leading-5 text-stone-600`,children:[(0,Q.jsxs)(`span`,{className:`text-stone-400`,children:[t+1,`.`]}),` `,e.header?`${e.header} / `:``,e.question,(0,Q.jsx)(`span`,{className:`ml-1 text-stone-400`,children:`— 已跳过`})]},e.id))}),(0,Q.jsx)(`textarea`,{autoFocus:!0,value:wi,onChange:e=>Ti(e.target.value),onKeyDown:e=>{e.key!==`Enter`||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),So())},rows:3,className:`mt-2 w-full resize-none rounded-lg border border-stone-200 px-2.5 py-2 text-[13px] leading-5 outline-none focus:border-[#4176e6]`,placeholder:`为什么跳过这几题?例如:先只做评估,方案我稍后定 / 这几项按你推荐的来`})]}),(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between gap-3 px-5 pt-2 pb-3`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>Co(),className:`h-8 shrink-0 rounded-lg px-2 text-[12px] text-stone-500 outline-none hover:bg-stone-100 hover:text-stone-700`,children:`返回继续回答`}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>So(),className:`h-8 shrink-0 rounded-lg bg-[#4176e6] px-3.5 text-[12px] font-medium text-white hover:bg-[#3467d4]`,children:`提交并继续`})]})]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto overscroll-contain px-3 py-1`,children:[ws.options?.length?(0,Q.jsx)(`div`,{className:`mt-2 flex flex-col gap-0.5`,role:ws.multi_select?`group`:`radiogroup`,children:ws.options.map((e,t)=>{let n=Ts.selected.includes(e.label),r=Zd(e.label);return(0,Q.jsxs)(`button`,{type:`button`,role:ws.multi_select?`checkbox`:`radio`,"aria-checked":n,onClick:()=>ho(ws,e.label,n),className:`flex w-full shrink-0 items-start gap-2 rounded-lg border px-2 py-2 text-left outline-none transition-colors ${n?`border-[#4176e6]/40 bg-[#f2f7ff]`:`border-transparent hover:bg-stone-50`}`,children:[ws.multi_select?(0,Q.jsx)(`span`,{"aria-hidden":`true`,className:`mt-0.5 grid h-4 w-4 shrink-0 place-items-center rounded border ${n?`border-[#4176e6] bg-[#4176e6] text-white`:`border-stone-300 text-transparent`}`,children:(0,Q.jsx)(bf,{className:`h-3 w-3`})}):(0,Q.jsx)(`span`,{"aria-hidden":`true`,className:`mt-0.5 grid h-5 w-5 shrink-0 place-items-center rounded-md text-[11px] font-medium ${n?`bg-[#4176e6] text-white`:`bg-stone-100 text-stone-500`}`,children:t+1}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Q.jsxs)(`span`,{className:`flex flex-wrap items-center gap-x-2 gap-y-0.5`,children:[(0,Q.jsx)(`span`,{className:`text-[13px] leading-5 font-medium text-stone-800`,children:r.label}),r.recommended?(0,Q.jsx)(`span`,{className:`rounded bg-[#edf3fe] px-1 text-[10px] leading-4 font-semibold text-[#4176e6]`,children:`推荐`}):null]}),e.description?(0,Q.jsx)(`span`,{className:`mt-0.5 block text-[12px] leading-4.5 text-stone-400`,children:e.description}):null]})]},`${e.label}-${t}`)})}):(0,Q.jsx)(`div`,{className:`px-1.5 py-2`,children:(0,Q.jsx)(`textarea`,{autoFocus:!0,value:Ts.text,onChange:e=>_o(ws,e.target.value),onKeyDown:e=>{e.key!==`Enter`||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),vo(ws,Ts.text))},rows:2,className:`w-full resize-none rounded-lg border border-stone-200 px-2.5 py-2 text-[13px] leading-5 outline-none focus:border-[#4176e6]`,placeholder:`输入你的回答…`})}),ws.options?.length?(0,Q.jsx)(`div`,{className:`mt-1 px-1.5 pb-1`,children:(0,Q.jsxs)(`div`,{className:`flex items-start gap-2 rounded-lg border border-stone-200 px-2 py-1.5 focus-within:border-[#4176e6]`,children:[(0,Q.jsx)(`span`,{"aria-hidden":`true`,className:`mt-0.5 grid h-4 w-4 shrink-0 place-items-center rounded bg-stone-100 text-[10px] font-medium text-stone-500`,children:`#`}),(0,Q.jsx)(`textarea`,{value:Ts.text,onChange:e=>_o(ws,e.target.value),onKeyDown:e=>{e.key!==`Enter`||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),vo(ws,Ts.text))},rows:1,className:`min-h-5 w-full resize-none bg-transparent text-[13px] leading-5 outline-none`,placeholder:`输入序号选择(如 1${ws.multi_select?` 或 1,3`:``}),也可直接写你的回答`})]})}):null,(0,Q.jsx)(`div`,{className:`px-2 pb-2 pt-1 text-[11px] leading-4 text-stone-400`,children:ws.options?.length?`回车确认这一步;跳过的题会在提交前让你说明原因,不会直接开始实施`:`回车确认;跳过的题会在提交前让你说明原因,不会直接开始实施`})]}),(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between gap-3 px-5 pt-2 pb-3`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Q.jsx)(`button`,{type:`button`,"aria-label":`上一步`,disabled:Cs===0,onClick:()=>go(Cs-1),className:`grid h-6 w-6 place-items-center rounded-full text-stone-400 outline-none hover:bg-stone-100 hover:text-stone-600 disabled:cursor-default disabled:text-stone-200 disabled:hover:bg-transparent`,children:(0,Q.jsx)(yf,{className:`h-4 w-4 rotate-180`})}),(0,Q.jsxs)(`span`,{className:`px-1 text-[12px] font-medium text-stone-500`,children:[`第 `,Cs+1,` 步 / 共 `,Ss,` 步`]}),(0,Q.jsx)(`button`,{type:`button`,"aria-label":`下一步`,disabled:Es,onClick:()=>go(Cs+1),className:`grid h-6 w-6 place-items-center rounded-full text-stone-400 outline-none hover:bg-stone-100 hover:text-stone-600 disabled:cursor-default disabled:text-stone-200 disabled:hover:bg-transparent`,children:(0,Q.jsx)(yf,{className:`h-4 w-4`})})]}),(0,Q.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[bi?(0,Q.jsx)(`span`,{className:`truncate text-[11px] text-rose-500`,children:bi}):null,(0,Q.jsx)(`button`,{type:`button`,onClick:()=>xo(),className:`h-8 shrink-0 rounded-lg px-2 text-[12px] text-stone-500 outline-none hover:bg-stone-100 hover:text-stone-700`,children:`跳过`}),(0,Q.jsx)(`button`,{type:`button`,disabled:!Ds,onClick:()=>Es?bo():go(Cs+1),className:`h-8 shrink-0 rounded-lg bg-[#4176e6] px-3.5 text-[12px] font-medium text-white hover:bg-[#3467d4] disabled:cursor-not-allowed disabled:bg-stone-300`,children:Es?`提交回答`:`下一步`})]})]})]})]}):null,(0,Q.jsxs)(`div`,{ref:Xi,className:`pt-2 rounded-[20px] bg-white border border-stone-200 shadow-[0_4px_20px_rgba(15,23,42,0.06)] transition-shadow focus-within:shadow-[0_4px_24px_rgba(65,118,230,0.14)]`,children:[(S.length>0||f.length>0||_.length>0)&&(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-1.5 px-3 pt-0.5 pb-2`,children:[S.map(e=>(0,Q.jsxs)(`span`,{className:`flex items-center gap-1.5 pl-2.5 pr-1 py-1 text-xs text-[#4176e6] bg-[#edf3fe] border border-[#4176e6]/25 rounded-lg`,"data-hint":e.collection===`workspace`?e.path:`${e.collection}/${e.path}`,children:[(0,Q.jsx)(wf,{className:`w-3.5 h-3.5`}),(0,Q.jsx)(`span`,{className:`text-[10px] text-[#4176e6]/80 shrink-0`,children:e.collection===`workspace`?`工作区`:e.collection===`prompts`||e.collection===`cases`||e.collection===`knowledge`?e.category:Bu(e.format)}),(0,Q.jsx)(`span`,{className:`max-w-48 truncate`,children:e.title}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>C(t=>t.filter(t=>t.collection!==e.collection||t.path!==e.path)),className:`w-5 h-5 flex items-center justify-center rounded text-[#4176e6]/70 hover:text-[#4176e6] hover:bg-white/80`,children:(0,Q.jsxs)($,{className:`w-3 h-3`,children:[(0,Q.jsx)(`path`,{d:`M18 6 6 18`}),(0,Q.jsx)(`path`,{d:`m6 6 12 12`})]})})]},`${e.collection}:${e.path}`)),f.map((e,t)=>(0,Q.jsxs)(`span`,{className:`flex items-center gap-1.5 pl-2.5 pr-1 py-1 text-xs text-[#4176e6] bg-[#edf3fe] border border-[#4176e6]/25 rounded-lg`,"data-hint":e.path||e.name,children:[(0,Q.jsx)(wf,{className:`w-3.5 h-3.5`}),(0,Q.jsx)(`span`,{className:`text-[10px] text-[#4176e6]/80 shrink-0`,children:`文件`}),(0,Q.jsx)(`span`,{className:`max-w-48 truncate`,children:e.name}),(0,Q.jsx)(`button`,{type:`button`,"data-hint":`移除`,onClick:()=>p(e=>e.filter((e,n)=>n!==t)),className:`w-5 h-5 flex items-center justify-center rounded text-[#4176e6]/70 hover:text-[#4176e6] hover:bg-white/80`,children:(0,Q.jsxs)($,{className:`w-3 h-3`,children:[(0,Q.jsx)(`path`,{d:`M18 6 6 18`}),(0,Q.jsx)(`path`,{d:`m6 6 12 12`})]})})]},`${e.name}-${t}`)),_.map(e=>(0,Q.jsxs)(`span`,{className:`relative group inline-flex rounded-lg border border-stone-200 overflow-hidden bg-stone-50`,"data-hint":`${e.name} · ${Xf(e.size)}`,children:[(0,Q.jsx)(`img`,{src:e.dataUrl,alt:e.name,className:`h-14 w-14 object-cover`}),(0,Q.jsx)(`button`,{type:`button`,"data-hint":`移除图片`,onClick:()=>x(t=>t.filter(t=>t.id!==e.id)),className:`absolute top-0.5 right-0.5 w-5 h-5 flex items-center justify-center rounded bg-black/55 text-white hover:bg-black/75`,children:(0,Q.jsxs)($,{className:`w-3 h-3`,children:[(0,Q.jsx)(`path`,{d:`M18 6 6 18`}),(0,Q.jsx)(`path`,{d:`m6 6 12 12`})]})})]},e.id))]}),(0,Q.jsxs)(`div`,{className:`relative`,children:[pr&&!oa&&!ra&&(0,Q.jsx)(`div`,{ref:Ji,className:`tw-composer-menu tw-popover-anim absolute bottom-full left-0 right-0 mb-3 z-40 h-[min(70vh,20rem)] overflow-hidden rounded-xl border border-stone-200 py-2.5 shadow-[0_4px_14px_-4px_rgba(15,23,42,0.08)]`,children:(0,Q.jsxs)(`div`,{className:`tw-dsh-scroll h-full overflow-y-auto overflow-x-hidden`,children:[(0,Q.jsx)(`div`,{className:`px-3 pt-0.5 pb-1.5 text-[11px] font-medium text-stone-400 tracking-wide`,children:`添加`}),(0,Q.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>{_r(!1),Gi.current?.click()},className:`tw-composer-menu-item w-full flex items-center gap-2.5 px-3 py-2 text-left rounded-lg hover:bg-stone-100`,children:[(0,Q.jsx)(Tf,{className:`w-4 h-4 shrink-0 text-stone-500`}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1 text-[13px] text-stone-800`,children:[`文件`,(0,Q.jsx)(`span`,{className:`ml-1.5 text-stone-400 font-normal`,children:`file`})]}),(0,Q.jsx)(`span`,{className:`shrink-0 max-w-[45%] text-right text-[11px] text-stone-400 truncate`,children:`添加本地附件`})]}),(0,Q.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>{_r(!1),Ba()},className:`tw-composer-menu-item w-full flex items-center gap-2.5 px-3 py-2 text-left rounded-lg hover:bg-stone-100`,children:[(0,Q.jsxs)($,{className:`w-4 h-4 shrink-0 text-stone-500`,children:[(0,Q.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`}),(0,Q.jsx)(`circle`,{cx:`12`,cy:`12`,r:`6`}),(0,Q.jsx)(`circle`,{cx:`12`,cy:`12`,r:`2`})]}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1 text-[13px] text-stone-800`,children:[`目标`,(0,Q.jsx)(`span`,{className:`ml-1.5 text-stone-400 font-normal`,children:`goal`})]}),(0,Q.jsx)(`span`,{className:`shrink-0 max-w-[45%] text-right text-[11px] text-stone-400 truncate`,children:`设置或查看长期任务目标`})]}),(0,Q.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>{_r(!1),ii===`off`?Va():fo()},className:`tw-composer-menu-item w-full flex items-center gap-2.5 px-3 py-2 text-left rounded-lg hover:bg-stone-100 ${ii===`planning`?`bg-amber-50`:ii===`approved`?`bg-emerald-50`:``}`,children:[(0,Q.jsxs)($,{className:`w-4 h-4 shrink-0 ${ii===`planning`?`text-amber-800`:ii===`approved`?`text-emerald-800`:`text-stone-500`}`,children:[(0,Q.jsx)(`path`,{d:`M8 6h13`}),(0,Q.jsx)(`path`,{d:`M8 12h13`}),(0,Q.jsx)(`path`,{d:`M8 18h13`}),(0,Q.jsx)(`path`,{d:`M3 6h.01`}),(0,Q.jsx)(`path`,{d:`M3 12h.01`}),(0,Q.jsx)(`path`,{d:`M3 18h.01`})]}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1 text-[13px] text-stone-800`,children:[`计划`,(0,Q.jsx)(`span`,{className:`ml-1.5 text-stone-400 font-normal`,children:`plan`})]}),(0,Q.jsx)(`span`,{className:`shrink-0 max-w-[45%] text-right text-[11px] text-stone-400 truncate`,children:`进入或退出计划模式`})]}),B.todos||B.tasks?(0,Q.jsxs)(Q.Fragment,{children:[B.todos?(0,Q.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>Li(`todo`),className:`tw-composer-menu-item w-full flex items-center gap-2.5 px-3 py-2 text-left rounded-lg hover:bg-stone-100`,children:[(0,Q.jsxs)($,{className:`w-4 h-4 shrink-0 text-stone-500`,children:[(0,Q.jsx)(`path`,{d:`M8 6h13`}),(0,Q.jsx)(`path`,{d:`M8 12h13`}),(0,Q.jsx)(`path`,{d:`M8 18h13`}),(0,Q.jsx)(`path`,{d:`M3 6h.01`}),(0,Q.jsx)(`path`,{d:`M3 12h.01`}),(0,Q.jsx)(`path`,{d:`M3 18h.01`})]}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1 text-[13px] text-stone-800`,children:[`待办`,(0,Q.jsx)(`span`,{className:`ml-1.5 text-stone-400 font-normal`,children:`todo`})]}),(0,Q.jsx)(`span`,{className:`shrink-0 max-w-[45%] text-right text-[11px] text-stone-400 truncate`,children:`手动添加一条待办`})]}):null,B.tasks?(0,Q.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>Li(`task`),className:`tw-composer-menu-item w-full flex items-center gap-2.5 px-3 py-2 text-left rounded-lg hover:bg-stone-100`,children:[(0,Q.jsxs)($,{className:`w-4 h-4 shrink-0 text-stone-500`,children:[(0,Q.jsx)(`path`,{d:`M9 5h10`}),(0,Q.jsx)(`path`,{d:`M9 12h10`}),(0,Q.jsx)(`path`,{d:`M9 19h10`}),(0,Q.jsx)(`path`,{d:`M4 5h.01`}),(0,Q.jsx)(`path`,{d:`M4 12h.01`}),(0,Q.jsx)(`path`,{d:`M4 19h.01`})]}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1 text-[13px] text-stone-800`,children:[`任务`,(0,Q.jsx)(`span`,{className:`ml-1.5 text-stone-400 font-normal`,children:`task`})]}),(0,Q.jsx)(`span`,{className:`shrink-0 max-w-[45%] text-right text-[11px] text-stone-400 truncate`,children:`手动添加一个任务`})]}):null]}):null,aa.length?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`my-1 border-t border-stone-100`}),(0,Q.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>Sr(e=>!e),className:`w-full flex items-center gap-2 px-3 py-1.5 text-left hover:bg-stone-50`,children:[(0,Q.jsx)(`span`,{className:`flex-1 text-[11px] font-medium text-stone-400 tracking-wide`,children:`扩展插件`}),(0,Q.jsx)(vf,{className:`w-3.5 h-3.5 text-stone-400 shrink-0 transition-transform ${xr?`rotate-180`:``}`})]}),xr?aa.map(e=>{let t=e.id===`caseGen`?`case`:e.id===`promptGen`?`prompt`:e.id===`knowledgeGen`?`knowledge`:e.id===`pluginDev`?`dev`:``,n=e.id===`caseGen`?`打开配置后生成用例并写入用例库`:e.id===`promptGen`?`对话生成提示词并写入提示词库`:e.id===`knowledgeGen`?`对话生成规范/方法论并写入知识库`:e.id===`pluginDev`?`输入需求后先评估确认,再开发扩展插件`:``;return(0,Q.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>{_r(!1),Da(e.id)},className:`tw-composer-menu-item w-full flex items-center gap-2.5 px-3 py-2 text-left rounded-lg hover:bg-stone-100`,children:[(0,Q.jsx)(Pf,{className:`w-4 h-4 shrink-0 text-stone-500`}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1 text-[13px] text-stone-800`,children:[e.name,t?(0,Q.jsx)(`span`,{className:`ml-1.5 text-stone-400 font-normal`,children:t}):null]}),n?(0,Q.jsx)(`span`,{className:`shrink-0 max-w-[45%] text-right text-[11px] text-stone-400 truncate`,children:n}):null]},e.id)}):null]}):null,(0,Q.jsx)(`div`,{className:`my-1 border-t border-stone-100`}),(0,Q.jsx)(`div`,{className:`px-3 pt-1 pb-1.5 text-[11px] font-medium text-stone-400 tracking-wide`,children:`指令`}),(0,Q.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>{_r(!1),G.current?z(`请等待当前回复结束后再压缩`):Ga({force:!0}).then(e=>{e&&z(`已压缩上下文`)})},className:`tw-composer-menu-item w-full flex items-center gap-2.5 px-3 py-2 text-left rounded-lg hover:bg-stone-100`,children:[(0,Q.jsx)($,{className:`w-4 h-4 shrink-0 text-stone-500`,children:(0,Q.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`})}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1 text-[13px] text-stone-800`,children:[`压缩`,(0,Q.jsx)(`span`,{className:`ml-1.5 text-stone-400 font-normal`,children:`compact`})]}),(0,Q.jsx)(`span`,{className:`shrink-0 max-w-[45%] text-right text-[11px] text-stone-400 truncate`,children:`压缩以上对话内容`})]}),(0,Q.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>{_r(!1),ko()},className:`tw-composer-menu-item w-full flex items-center gap-2.5 px-3 py-2 text-left rounded-lg hover:bg-stone-100`,children:[(0,Q.jsxs)($,{className:`w-4 h-4 shrink-0 text-stone-500`,children:[(0,Q.jsx)(`path`,{d:`M3 3v18h18`}),(0,Q.jsx)(`path`,{d:`M7 14v4`}),(0,Q.jsx)(`path`,{d:`M12 10v8`}),(0,Q.jsx)(`path`,{d:`M17 6v12`})]}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1 text-[13px] text-stone-800`,children:[`会话统计`,(0,Q.jsx)(`span`,{className:`ml-1.5 text-stone-400 font-normal`,children:`stats`})]}),(0,Q.jsx)(`span`,{className:`shrink-0 max-w-[45%] text-right text-[11px] text-stone-400 truncate`,children:`查看本会话用量摘要`})]})]})}),oa&&(0,Q.jsxs)(`div`,{ref:qi,className:`tw-composer-menu tw-popover-anim absolute bottom-full left-0 right-0 mb-2 mx-2 z-40 max-h-64 overflow-y-auto rounded-xl border border-stone-200 shadow-xl p-1`,children:[(0,Q.jsx)(`div`,{className:`px-3 py-1.5 text-[11px] text-stone-400`,children:`插件`}),aa.map((e,t)=>(0,Q.jsxs)(`button`,{type:`button`,"data-plugin-index":t,onMouseDown:e=>e.preventDefault(),onMouseEnter:()=>be(t),onClick:()=>Da(e.id),className:`tw-composer-menu-item w-full text-left px-3 py-2 rounded-lg transition-colors ${t===_e?`is-active`:``}`,children:[(0,Q.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,Q.jsx)(`div`,{className:`text-[13px] font-medium text-stone-800 flex-1`,children:e.name})}),(0,Q.jsx)(`div`,{className:`mt-0.5 text-xs text-stone-400 line-clamp-2`,children:e.description})]},e.id))]}),ra&&(0,Q.jsx)(`div`,{ref:Ki,className:`tw-composer-menu tw-popover-anim absolute bottom-full left-0 right-0 mb-2 mx-2 z-40 max-h-64 overflow-y-auto rounded-xl border border-stone-200 shadow-xl p-1`,children:na.length===0?(0,Q.jsxs)(`div`,{className:`px-3 py-2 text-xs text-stone-400 space-y-1`,children:[jr?(0,Q.jsx)(`p`,{children:`项目文档:无匹配`}):null,Qi?(0,Q.jsx)(`p`,{children:`工作区:无匹配`}):(0,Q.jsx)(`p`,{children:`工作区:请先在侧栏添加并选择工作区`}),jr?null:(0,Q.jsxs)(`p`,{children:[`「知识库检索」未启用:启用后才能用 @ 引用`,Se(`knowledge`),` / `,Se(`templates`),`文档`]})]}):(0,Q.jsxs)(Q.Fragment,{children:[ea.length>0?(0,Q.jsxs)(`div`,{className:`px-3 py-1.5 text-[11px] font-medium text-stone-400`,children:[`项目文档(`,Se(`knowledge`),` / `,Se(`templates`),`)`]}):null,na.map((e,t)=>{let n=e.doc,r=na[t-1],i=e.section===`workspace`&&r?.section!==`workspace`;return(0,Q.jsxs)(`div`,{children:[i?(0,Q.jsxs)(Q.Fragment,{children:[ea.length>0?(0,Q.jsx)(`div`,{className:`my-1 mx-2 border-t border-stone-200`,role:`separator`}):null,(0,Q.jsx)(`div`,{className:`px-3 py-1.5 text-[11px] font-medium text-stone-400`,children:`工作区`})]}):null,(0,Q.jsxs)(`button`,{type:`button`,"data-mention-index":t,onMouseDown:e=>e.preventDefault(),onClick:()=>wa(n),className:`tw-composer-menu-item w-full text-left px-3 py-2 rounded-lg transition-colors ${t===Zn?`is-active`:``}`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-[13px] text-stone-800`,children:[(0,Q.jsx)(`span`,{className:`text-[11px] px-1.5 py-0.5 rounded bg-stone-100 text-stone-500 shrink-0`,children:n.collection===`knowledge`?Se(`knowledge`):n.collection===`templates`?Se(`templates`):n.format===`dir`?`文件夹`:`文件`}),n.collection===`workspace`?null:(0,Q.jsx)(`span`,{className:`text-[11px] px-1.5 py-0.5 rounded bg-stone-100 text-stone-500 shrink-0`,children:Bu(n.format)}),(0,Q.jsx)(`span`,{className:`truncate font-medium`,children:n.title})]}),(0,Q.jsx)(`div`,{className:`mt-0.5 pl-0 text-xs text-stone-400 truncate`,children:n.collection===`workspace`?n.path:`${n.category}${n.description?` · ${n.description}`:``}`})]})]},`${n.collection}/${n.id}`)}),jr?null:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`my-1 mx-2 border-t border-stone-200`,role:`separator`}),(0,Q.jsx)(`p`,{className:`px-3 py-1.5 text-[11px] text-stone-400`,children:`「知识库检索」未启用:@ 仅引用工作区文件`})]})]})}),(0,Q.jsxs)(`div`,{className:`flex items-start gap-2 px-3`,children:[oi===`goal`?(0,Q.jsxs)(`span`,{className:`tw-composer-mode-chip is-goal`,"data-hint":`会话目标`,children:[(0,Q.jsxs)($,{className:`w-3.5 h-3.5 shrink-0`,children:[(0,Q.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`}),(0,Q.jsx)(`circle`,{cx:`12`,cy:`12`,r:`6`}),(0,Q.jsx)(`circle`,{cx:`12`,cy:`12`,r:`2`})]}),(0,Q.jsx)(`span`,{children:`目标`}),(0,Q.jsx)(`button`,{type:`button`,"aria-label":`取消目标输入`,onClick:()=>si(null),children:(0,Q.jsxs)($,{className:`w-3 h-3`,children:[(0,Q.jsx)(`path`,{d:`M18 6 6 18`}),(0,Q.jsx)(`path`,{d:`m6 6 12 12`})]})})]}):null,oi===`plan`?(0,Q.jsxs)(`span`,{className:`tw-composer-mode-chip is-plan${ii===`approved`?` is-approved`:``}`,"data-hint":ii===`approved`?`计划模式·已批准`:`计划模式·探查中`,children:[(0,Q.jsxs)($,{className:`w-3.5 h-3.5 shrink-0`,children:[(0,Q.jsx)(`path`,{d:`M8 6h13`}),(0,Q.jsx)(`path`,{d:`M8 12h13`}),(0,Q.jsx)(`path`,{d:`M8 18h13`}),(0,Q.jsx)(`path`,{d:`M3 6h.01`}),(0,Q.jsx)(`path`,{d:`M3 12h.01`}),(0,Q.jsx)(`path`,{d:`M3 18h.01`})]}),(0,Q.jsx)(`span`,{children:`计划`}),(0,Q.jsx)(`button`,{type:`button`,"aria-label":`退出计划模式`,onClick:()=>za(),children:(0,Q.jsxs)($,{className:`w-3 h-3`,children:[(0,Q.jsx)(`path`,{d:`M18 6 6 18`}),(0,Q.jsx)(`path`,{d:`m6 6 12 12`})]})})]}):null,oi===`pluginDev`?(0,Q.jsxs)(`span`,{className:`tw-composer-mode-chip is-plugin-dev`,children:[(0,Q.jsxs)($,{className:`w-3.5 h-3.5 shrink-0`,children:[(0,Q.jsx)(`path`,{d:`M9 7V3`}),(0,Q.jsx)(`path`,{d:`M15 7V3`}),(0,Q.jsx)(`path`,{d:`M6 7h12v4a6 6 0 0 1-12 0V7Z`}),(0,Q.jsx)(`path`,{d:`M12 17v4`})]}),(0,Q.jsx)(`span`,{children:`插件开发`}),(0,Q.jsx)(`button`,{type:`button`,"aria-label":`退出插件开发`,onClick:()=>za(),children:(0,Q.jsxs)($,{className:`w-3 h-3`,children:[(0,Q.jsx)(`path`,{d:`M18 6 6 18`}),(0,Q.jsx)(`path`,{d:`m6 6 12 12`})]})})]}):null,oi===`reports`?(0,Q.jsxs)(`span`,{className:`tw-composer-mode-chip is-report`,children:[(0,Q.jsxs)($,{className:`w-3.5 h-3.5 shrink-0`,children:[(0,Q.jsx)(`path`,{d:`M14 3v4a1 1 0 0 0 1 1h4`}),(0,Q.jsx)(`path`,{d:`M5 3h9l5 5v13H5z`}),(0,Q.jsx)(`path`,{d:`M8 13h8`}),(0,Q.jsx)(`path`,{d:`M8 17h5`})]}),(0,Q.jsxs)(`span`,{children:[`生成`,nr[ci]]}),(0,Q.jsx)(`button`,{type:`button`,"aria-label":`取消汇报生成`,onClick:()=>za(),children:(0,Q.jsxs)($,{className:`w-3 h-3`,children:[(0,Q.jsx)(`path`,{d:`M18 6 6 18`}),(0,Q.jsx)(`path`,{d:`m6 6 12 12`})]})})]}):null,(0,Q.jsx)(`textarea`,{ref:Wi,value:u,onChange:e=>d(e.target.value),onPaste:Io,onKeyDown:e=>{if(oa&&aa.length){if(e.key===`ArrowDown`){e.preventDefault(),be(e=>(e+1)%aa.length);return}if(e.key===`ArrowUp`){e.preventDefault(),be(e=>(e-1+aa.length)%aa.length);return}if(e.key===`Escape`){e.preventDefault(),fr(!0),ia&&d(u.slice(0,ia.from));return}if(e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing){e.preventDefault();let t=aa[_e]??aa[0];t&&Da(t.id);return}}if(ra&&na.length){if(e.key===`ArrowDown`){e.preventDefault(),$n(e=>(e+1)%na.length);return}if(e.key===`ArrowUp`){e.preventDefault(),$n(e=>(e-1+na.length)%na.length);return}if(e.key===`Escape`){e.preventDefault(),ar(!0),$i&&d(u.slice(0,$i.from));return}if(e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing){e.preventDefault();let t=na[Zn]?.doc;t&&wa(t);return}}if(e.key===`Escape`&&pr)e.preventDefault(),_r(!1);else if(e.key===`Escape`&&($i||ia)){e.preventDefault(),ar(!0),fr(!0);let t=$i?.from??ia?.from;t!=null&&d(u.slice(0,t))}else if(e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing){e.preventDefault();let t=e.metaKey||e.ctrlKey;if(G.current){if(t){let e=u.trim();if(e||f.length>0||_.length>0||S.length>0){let t={id:`q_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,6)}`,content:e,files:[...f],refs:[...S],imgs:[..._]};Ra(),Qa(t)}else zi.current.length&&Qa();return}Ka(void 0,{forceBusy:Pe().busySendBehavior??`queue`})}else Ka()}},rows:1,placeholder:t?Cr.length>0&&St?`Cmd/Ctrl+Enter 插话发送全部排队消息`:jr?`请输入内容,或用 @ 引用文档`:Qi?`请输入内容,或用 @ 引用工作区文件`:`请输入内容(@ 引用文档需先启用「知识库检索」)`:`请先配置模型(左下角「设置」→ 模型)`,className:`tw-chat-input block min-w-0 flex-1 min-h-13 pl-0 pr-2 pt-1.5 pb-0.5 bg-transparent resize-none focus:outline-none placeholder:text-(--tw-label-tertiary)`})]})]}),(0,Q.jsxs)(`div`,{className:`tw-composer-bar flex items-center gap-1.5 px-3 pb-3 pt-3`,children:[(0,Q.jsx)(`button`,{type:`button`,"data-add-menu-btn":!0,"aria-label":ii===`off`?`添加`:ii===`planning`?`添加(计划模式·探查中)`:`添加(计划模式·已批准)`,onClick:()=>{_r(e=>!e),ar(!0),fr(!0)},className:`tw-icon-btn w-8 h-8 shrink-0 rounded-full flex items-center justify-center outline-none focus:outline-none focus-visible:outline-none transition-colors ${pr?`bg-(--tw-session-hover-bg)`:``}`,children:(0,Q.jsxs)($,{className:`w-4 h-4`,children:[(0,Q.jsx)(`path`,{d:`M5 12h14`}),(0,Q.jsx)(`path`,{d:`M12 5v14`})]})}),W&&(0,Q.jsxs)(O,{children:[(0,Q.jsxs)(ne,{title:as?`工作区:${as}`:`选择工作区`,"aria-label":cs?`工作区:${cs}`:`选择工作区`,disabled:Nn,className:`tw-composer-bar-ws group flex items-center gap-1 h-7 shrink-0 max-w-[min(40vw,11rem)] pl-1.5 pr-1 text-[13px] leading-5 font-medium text-stone-600 rounded-md outline-none focus:outline-none focus-visible:outline-none hover:bg-stone-100 data-[open]:bg-stone-100 transition-colors disabled:opacity-50`,children:[(0,Q.jsx)(Df,{className:`w-3.5 h-3.5 shrink-0 text-stone-500`}),(0,Q.jsx)(`span`,{className:`tw-composer-bar-label truncate`,children:cs}),(0,Q.jsx)(vf,{className:`tw-composer-bar-chevron w-3.5 h-3.5 shrink-0 text-stone-400 transition-transform group-data-[open]:rotate-180`})]}),(0,Q.jsxs)(ee,{transition:!0,anchor:{to:`top start`,gap:8},className:`tw-select-menu tw-menu-anim z-50 w-[min(100vw-2rem,16rem)] rounded-xl border border-stone-200 py-1 shadow-xl focus:outline-none`,children:[(V?.items??[]).map(e=>{let t=e.path===as;return(0,Q.jsx)(te,{children:(0,Q.jsxs)(`button`,{type:`button`,disabled:Nn,onClick:()=>void va(e),className:`w-full flex items-center gap-2.5 px-3 py-2 text-left data-[focus]:bg-stone-100 disabled:opacity-50`,children:[(0,Q.jsx)(Df,{className:`w-4 h-4 shrink-0 text-stone-500`}),(0,Q.jsx)(`span`,{className:`flex-1 min-w-0 truncate text-[13px] ${t?`text-stone-900 font-medium`:`text-stone-700`}`,"data-hint":e.path,children:Lt(e,ts)}),t&&(0,Q.jsx)(bf,{className:`w-3.5 h-3.5 shrink-0 text-[#4176e6]`})]})},e.id)}),(V?.items?.length??0)>0&&(0,Q.jsx)(`div`,{className:`my-1 border-t border-stone-100`}),(0,Q.jsx)(te,{children:(0,Q.jsxs)(`button`,{type:`button`,disabled:Nn,onClick:()=>void ya(),className:`w-full flex items-center gap-2.5 px-3 py-2 text-left text-[13px] text-stone-700 data-[focus]:bg-stone-100 disabled:opacity-50`,children:[(0,Q.jsx)(`span`,{className:`w-4 h-4 shrink-0 flex items-center justify-center text-stone-500 text-base leading-none`,children:`+`}),`添加工作区...`]})})]})]}),(0,Q.jsxs)(O,{children:[(0,Q.jsxs)(ne,{title:`访问权限:${Uo.label}`,"aria-label":`访问权限:${Uo.label}`,className:`tw-composer-bar-access group flex items-center gap-1 h-7 shrink-0 max-w-55 pl-2 pr-1 text-[13px] leading-5 font-medium text-stone-600 rounded-md outline-none focus:outline-none focus-visible:outline-none hover:bg-stone-100 data-[open]:bg-stone-100 transition-colors`,children:[(0,Q.jsx)(Vf,{level:ln,className:`w-3.5 h-3.5 shrink-0 text-stone-500`}),(0,Q.jsx)(`span`,{className:`tw-composer-bar-label truncate`,children:Uo.label}),(0,Q.jsx)(`span`,{className:`ml-0.5 w-1.5 h-1.5 rounded-full shrink-0 ${W?`bg-emerald-500`:`bg-stone-300`}`,"data-hint":W?`Runner 在线`:`Runner 离线`}),(0,Q.jsx)(vf,{className:`tw-composer-bar-chevron w-3.5 h-3.5 shrink-0 text-stone-400 transition-transform group-data-[open]:rotate-180`})]}),(0,Q.jsxs)(ee,{transition:!0,anchor:{to:`top start`,gap:8},className:`tw-select-menu tw-menu-anim z-50 w-56 rounded-xl border border-stone-200 p-1 shadow-xl focus:outline-none`,children:[(0,Q.jsx)(`div`,{className:`px-3 py-1.5 text-[11px] text-stone-400`,children:W?`本地文件服务已连接`:`本地文件服务未就绪`}),uf.map(e=>{let t=Wo&&e.value===`readonly`;return(0,Q.jsx)(te,{disabled:t,children:(0,Q.jsxs)(`button`,{type:`button`,disabled:t,onClick:()=>{un(e.value),K.current&&q(Re(K.current,{access:e.value}))},className:`w-full flex items-center gap-2 px-3 py-2 rounded-lg text-left text-[13px] data-[focus]:bg-stone-100 disabled:cursor-not-allowed`,children:[(0,Q.jsx)(Vf,{level:e.value,className:`w-4 h-4 shrink-0 ${t?`text-stone-300`:`text-stone-500`}`}),(0,Q.jsx)(`span`,{className:`flex-1 ${t?`text-stone-400`:ln===e.value?`text-stone-900 font-medium`:`text-stone-700`}`,children:e.label}),t?(0,Q.jsx)(`span`,{className:`text-[11px] text-stone-400`,children:`插件开发需要写入`}):ln===e.value?(0,Q.jsx)(bf,{className:`w-3.5 h-3.5 text-[#4176e6]`}):null]})},e.value)})]})]}),(0,Q.jsx)(`span`,{className:`flex-1`}),(0,Q.jsx)(cp,{settings:t}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{G.current?Ja():Ka()},disabled:!St&&!zo,"aria-label":St?`停止生成`:`发送`,className:`w-8 h-8 shrink-0 rounded-full flex items-center justify-center outline-none focus:outline-none focus-visible:outline-none transition-colors ${St?`bg-stone-200 text-stone-700 hover:bg-stone-300`:`bg-[#4176e6] text-white hover:bg-[#3565c7] disabled:bg-[#a9c3ef] disabled:cursor-not-allowed`}`,children:St?(0,Q.jsx)(`span`,{className:`w-2.5 h-2.5 bg-current rounded-xs`}):(0,Q.jsx)(Ef,{className:`w-4 h-4`})})]})]}),(0,Q.jsx)(op,{messages:s,model:t?.model,systemPromptTokens:Kf(w)})]}),(0,Q.jsx)(`input`,{ref:Gi,type:`file`,multiple:!0,hidden:!0,accept:[...Qu.map(e=>`.${e}`),`image/*`,`text/*`,`application/json`,`application/vnd.openxmlformats-officedocument.spreadsheetml.sheet`,`application/vnd.openxmlformats-officedocument.wordprocessingml.document`,`application/vnd.ms-excel`,`application/msword`].join(`,`),onChange:e=>void Mo(e)})]})]})]}),Ce?(0,Q.jsx)(`div`,{className:`tw-plugins-rail flex-1 min-w-0 min-h-0 self-stretch h-full overflow-hidden flex flex-col`,children:(0,Q.jsx)(on,{embedded:!0})}):null,(0,Q.jsx)(yd,{open:E,initial:re,onClose:()=>D(!1),onConfirm:e=>ro(e)}),(0,Q.jsx)(bd,{open:ae,initial:M,onClose:()=>j(!1),onConfirm:e=>io(e)}),(0,Q.jsx)(xd,{open:ce,initial:le,onClose:()=>N(!1),onConfirm:e=>ao(e)}),(0,Q.jsx)(ir,{open:!!Te,title:`重命名会话`,label:`会话名称`,placeholder:`请输入会话名称`,initialValue:Te?a?.sessions.find(e=>e.id===Te)?.title??``:``,confirmLabel:`保存`,cancelLabel:`取消`,onClose:()=>Ae(null),onConfirm:Ao}),(0,Q.jsx)(ir,{open:!!mt,title:`重命名工作区`,label:`显示名称`,placeholder:`请输入工作区名称`,initialValue:mt?V?.items.find(e=>e.id===mt)?.name??``:``,confirmLabel:`保存`,cancelLabel:`取消`,onClose:()=>ht(null),onConfirm:e=>void Sa(e)}),(0,Q.jsx)(ie,{open:!!Fe,title:`删除会话`,message:Fe?`确定永久删除「${a?.sessions.find(e=>e.id===Fe)?.title??`该会话`}」?此操作不可恢复。`:``,confirmLabel:`删除`,cancelLabel:`取消`,danger:`outline`,onClose:()=>Ie(null),onConfirm:()=>{if(!Fe)return;let e=Fe;Ie(null),To(e)}}),(0,Q.jsx)(ie,{open:!!ft,title:`删除工作区`,message:ft?`将把「${ft.name}」从工作区列表中移除。文件夹与会话记录会保留,其会话将归入项目根工作区。`:``,confirmLabel:`删除工作区`,cancelLabel:`取消`,danger:`outline`,onClose:()=>pt(null),onConfirm:()=>void ba()})]})}export{dp as default};
|