lantern-harness 0.1.19 → 0.1.20

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.
Files changed (50) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/500.html +4 -4
  3. package/dist/_astro/Base.8d5eaaN-.css +1 -0
  4. package/dist/_astro/{Base.astro_astro_type_script_index_0_lang.BMvdPyIE.js → Base.astro_astro_type_script_index_0_lang.D3Mv75pF.js} +1 -1
  5. package/dist/_astro/CasesLibrary.BghGVLeb.js +19 -0
  6. package/dist/_astro/{ChatApp.azDLrlxw.js → ChatApp.DFRI7l4j.js} +2 -2
  7. package/dist/_astro/{PluginsPage.Du4g_yr4.js → PluginsPage.BkwleEJf.js} +2 -2
  8. package/dist/_astro/PluginsPage.tkNDzVHL.js +1 -0
  9. package/dist/_astro/{PromptsLibrary.17cDZsjQ.js → PromptsLibrary.CjSQTnKT.js} +1 -1
  10. package/dist/_astro/ReqAnalysisBoard.C9g4p0Q1.js +29 -0
  11. package/dist/_astro/{SettingsDialog.BMa8eGFr.js → SettingsDialog.CmY3q7-S.js} +1 -1
  12. package/dist/_astro/app-version.BRO_L8TS.js +1 -0
  13. package/dist/_astro/{story-review.BjrulZG8.js → story-review.BXXv0Ko_.js} +2 -2
  14. package/dist/case-exec/index.html +4 -4
  15. package/dist/cases/generate/index.html +4 -4
  16. package/dist/cases/library/index.html +5 -5
  17. package/dist/dashboard/index.html +4 -4
  18. package/dist/docs/changelog/index.html +21 -5
  19. package/dist/docs/install/index.html +4 -4
  20. package/dist/docs/manual/index.html +9 -8
  21. package/dist/knowledge/index.html +4 -4
  22. 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 +4 -4
  23. package/dist/plugins/index.html +5 -5
  24. package/dist/pm/bugs/index.html +4 -4
  25. package/dist/pm/iterations/index.html +4 -4
  26. package/dist/pm/projects/detail/index.html +4 -4
  27. package/dist/pm/projects/index.html +4 -4
  28. package/dist/pm/requirements/index.html +4 -4
  29. package/dist/prompts/index.html +5 -5
  30. package/dist/reports/index.html +4 -4
  31. package/dist/requirement-analysis/index.html +5 -5
  32. package/dist/requirements/index.html +4 -4
  33. package/dist/tasks/index.html +4 -4
  34. package/dist/templates/index.html +4 -4
  35. 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 +4 -4
  36. 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 +4 -4
  37. 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 +4 -4
  38. 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 +4 -4
  39. 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 +4 -4
  40. package/dist/test-automation/index.html +4 -4
  41. package/dist/test-stats/index.html +4 -4
  42. package/dist/todos/index.html +4 -4
  43. package/dist/workbench/index.html +5 -5
  44. package/docs//346/223/215/344/275/234/346/211/213/345/206/214.md +5 -4
  45. package/package.json +1 -1
  46. package/dist/_astro/Base.VCz1UVxQ.css +0 -1
  47. package/dist/_astro/CasesLibrary.BERmgS2j.js +0 -19
  48. package/dist/_astro/PluginsPage.BNlpKMUM.js +0 -1
  49. package/dist/_astro/ReqAnalysisBoard.CBgma-zG.js +0 -29
  50. package/dist/_astro/app-version.CdxtY1WM.js +0 -1
@@ -1,5 +1,5 @@
1
1
  const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["_astro/lib.S37S0T6S.js","_astro/react.Blvh0GOs.js","_astro/jszip.min.Bh2Mgo40.js","_astro/export.joBT53eb.js"])))=>i.map(i=>d[i]);
2
- import{s as e,t}from"./react.Blvh0GOs.js";import{B as n,H as r,U as i,V as a,W as o,i as s,p as c,r as l,t as u,u as d,z as f}from"./app-config.CF1xVPmo.js";import{a as p,i as m,o as h,s as g,t as _}from"./plugins.DYyAjBXb.js";import{a as v,n as y}from"./view-prefs.D1snIG5o.js";import{t as b}from"./react-dom.DLW9pGCF.js";import{i as x,n as S,r as C,t as w}from"./dialog.DZHZCe_T.js";import{i as T,n as E,r as D,t as O}from"./menu.Dnrpz489.js";import{t as k}from"./jsx-runtime.DUg_B_vD.js";import{t as A}from"./ConfirmDialog.CsMwWevK.js";import{t as ee}from"./DatePicker.Bkl71M49.js";import{t as te}from"./OverflowHint.pvo2Xc8R.js";import{t as j}from"./SelectDropdown.Cb-QtC-D.js";import{showToast as M}from"./Toast.BO2NFckG.js";import{a as ne,i as re,n as ie,o as ae,r as N,t as P}from"./case-types.DS1EQ5yP.js";import{n as oe,t as se}from"./SearchableSelect.mvcBwegf.js";import{a as ce,i as le,t as ue}from"./export.joBT53eb.js";import{a as F,c as de,i as fe,n as I,o as L,r as pe,s as me,t as he}from"./ExcelFieldTags.ytbpKt-Z.js";import{a as ge,i as _e,r as ve,s as ye,t as R}from"./llm.BZEzE0x2.js";import{_ as be,c as xe,f as Se,p as Ce,r as we,u as Te,v as Ee}from"./project-docs.DAw9bzgk.js";import{n as De,t as Oe}from"./doc-roots.DAJP9Svr.js";import{a as ke,l as Ae,n as je,r as Me,t as Ne}from"./prompts-meta.C_MeYq8G.js";import{d as Pe,f as Fe,l as Ie,m as Le,o as Re,p as ze,r as Be,s as Ve,y as He}from"./settings.BvxRxdqa.js";import{C as Ue,D as We,E as z,O as Ge,S as Ke,T as qe,_ as Je,a as Ye,b as Xe,c as Ze,d as Qe,f as $e,g as et,h as tt,i as nt,l as rt,m as it,n as at,o as ot,p as st,r as ct,s as lt,u as ut,v as dt,w as ft,x as pt,y as mt}from"./open-docs-in-session.B6uyOxPn.js";import{t as ht}from"./SlideOverDrawer.HqVYaIjP.js";import{f as gt,h as _t,w as vt}from"./req-analysis.DGQa1vaH.js";import{a as yt,c as bt,i as xt,n as St,o as Ct,r as wt,s as Tt}from"./composer-task.DJmluzPT.js";import{n as Et}from"./i18n.B3BVhlok.js";import{n as Dt,t as Ot}from"./PromptMountDialog.YH2odDZx.js";import{_ as kt,a as At,b as jt,c as Mt,d as Nt,f as Pt,g as Ft,h as It,i as Lt,l as Rt,m as zt,n as Bt,o as Vt,p as Ht,r as Ut,s as Wt,t as Gt,u as Kt,v as qt,y as Jt}from"./fs-tools.3F9MFrLf.js";import{C as Yt,D as Xt,I as B,O as Zt,S as Qt,T as $t,a as en,b as tn,d as nn,g as rn,h as an,j as V,l as on,r as sn,s as cn,t as ln,w as un,x as dn,y as fn}from"./pm.CagBA-ht.js";import{A as pn,C as mn,D as hn,N as gn,O as _n,P as vn,S as yn,T as bn,_ as H,a as xn,b as Sn,c as Cn,d as wn,g as Tn,i as En,l as Dn,m as On,n as kn,o as An,r as jn,t as U,u as W,v as Mn,x as Nn,y as Pn}from"./tasks.BNBkrFC3.js";import{_ as Fn,a as In,c as Ln,d as Rn,f as zn,g as Bn,h as Vn,i as Hn,l as Un,m as Wn,n as Gn,o as Kn,p as qn,r as Jn,s as Yn,t as Xn,u as Zn,v as Qn,y as $n}from"./bash-tools.CPS0ZiKi.js";import{_ as er,a as G,b as tr,d as nr,f as rr,g as ir,h as ar,i as or,l as sr,m as cr,n as lr,o as ur,p as dr,r as fr,s as pr,t as mr,u as hr,v as gr,y as _r}from"./PluginsPage.Du4g_yr4.js";import{c as vr,n as yr,t as br}from"./report-prompt.CAfZ6RIo.js";import{i as xr}from"./ui-auto-prompt.l_EXfDs5.js";import{h as Sr}from"./ui-auto.BmC9JJ_X.js";import{c as Cr,v as wr}from"./story-review.BjrulZG8.js";import{t as Tr}from"./NamePromptDialog.CS1pTTVl.js";var K=e(t(),1),Er=e(b(),1),q=`/__tb_sessions/runs`;async function Dr(e){try{return(await fetch(q,{signal:e??AbortSignal.timeout(1500)})).ok}catch{return!1}}async function Or(e){let t=await fetch(q,{signal:e??AbortSignal.timeout(3e3)});if(!t.ok)return[];let n=await t.json();return Array.isArray(n.runs)?n.runs:[]}async function kr(e){let t=await fetch(q,{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 Ar(e){await fetch(`${q}/${encodeURIComponent(e)}/stop`,{method:`POST`}).catch(()=>{})}async function jr(e){try{let t=await fetch(`${q}/${encodeURIComponent(e)}`,{signal:AbortSignal.timeout(3e3)});return t.status===404?{ok:!1}:t.ok?await t.json():null}catch{return null}}function Mr(e){return e===`completed`||e===`stopped`||e===`error`}function Nr(e,t,n,r){let i=new AbortController,a=`${q}/${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(`
2
+ import{s as e,t}from"./react.Blvh0GOs.js";import{B as n,H as r,U as i,V as a,W as o,i as s,p as c,r as l,t as u,u as d,z as f}from"./app-config.CF1xVPmo.js";import{a as p,i as m,o as h,s as g,t as _}from"./plugins.DYyAjBXb.js";import{a as v,n as y}from"./view-prefs.D1snIG5o.js";import{t as b}from"./react-dom.DLW9pGCF.js";import{i as x,n as S,r as C,t as w}from"./dialog.DZHZCe_T.js";import{i as T,n as E,r as D,t as O}from"./menu.Dnrpz489.js";import{t as k}from"./jsx-runtime.DUg_B_vD.js";import{t as A}from"./ConfirmDialog.CsMwWevK.js";import{t as ee}from"./DatePicker.Bkl71M49.js";import{t as te}from"./OverflowHint.pvo2Xc8R.js";import{t as j}from"./SelectDropdown.Cb-QtC-D.js";import{showToast as M}from"./Toast.BO2NFckG.js";import{a as ne,i as re,n as ie,o as ae,r as N,t as P}from"./case-types.DS1EQ5yP.js";import{n as oe,t as se}from"./SearchableSelect.mvcBwegf.js";import{a as ce,i as le,t as ue}from"./export.joBT53eb.js";import{a as F,c as de,i as fe,n as I,o as L,r as pe,s as me,t as he}from"./ExcelFieldTags.ytbpKt-Z.js";import{a as ge,i as _e,r as ve,s as ye,t as R}from"./llm.BZEzE0x2.js";import{_ as be,c as xe,f as Se,p as Ce,r as we,u as Te,v as Ee}from"./project-docs.DAw9bzgk.js";import{n as De,t as Oe}from"./doc-roots.DAJP9Svr.js";import{a as ke,l as Ae,n as je,r as Me,t as Ne}from"./prompts-meta.C_MeYq8G.js";import{d as Pe,f as Fe,l as Ie,m as Le,o as Re,p as ze,r as Be,s as Ve,y as He}from"./settings.BvxRxdqa.js";import{C as Ue,D as We,E as z,O as Ge,S as Ke,T as qe,_ as Je,a as Ye,b as Xe,c as Ze,d as Qe,f as $e,g as et,h as tt,i as nt,l as rt,m as it,n as at,o as ot,p as st,r as ct,s as lt,u as ut,v as dt,w as ft,x as pt,y as mt}from"./open-docs-in-session.B6uyOxPn.js";import{t as ht}from"./SlideOverDrawer.HqVYaIjP.js";import{f as gt,h as _t,w as vt}from"./req-analysis.DGQa1vaH.js";import{a as yt,c as bt,i as xt,n as St,o as Ct,r as wt,s as Tt}from"./composer-task.DJmluzPT.js";import{n as Et}from"./i18n.B3BVhlok.js";import{n as Dt,t as Ot}from"./PromptMountDialog.YH2odDZx.js";import{_ as kt,a as At,b as jt,c as Mt,d as Nt,f as Pt,g as Ft,h as It,i as Lt,l as Rt,m as zt,n as Bt,o as Vt,p as Ht,r as Ut,s as Wt,t as Gt,u as Kt,v as qt,y as Jt}from"./fs-tools.3F9MFrLf.js";import{C as Yt,D as Xt,I as B,O as Zt,S as Qt,T as $t,a as en,b as tn,d as nn,g as rn,h as an,j as V,l as on,r as sn,s as cn,t as ln,w as un,x as dn,y as fn}from"./pm.CagBA-ht.js";import{A as pn,C as mn,D as hn,N as gn,O as _n,P as vn,S as yn,T as bn,_ as H,a as xn,b as Sn,c as Cn,d as wn,g as Tn,i as En,l as Dn,m as On,n as kn,o as An,r as jn,t as U,u as W,v as Mn,x as Nn,y as Pn}from"./tasks.BNBkrFC3.js";import{_ as Fn,a as In,c as Ln,d as Rn,f as zn,g as Bn,h as Vn,i as Hn,l as Un,m as Wn,n as Gn,o as Kn,p as qn,r as Jn,s as Yn,t as Xn,u as Zn,v as Qn,y as $n}from"./bash-tools.CPS0ZiKi.js";import{_ as er,a as G,b as tr,d as nr,f as rr,g as ir,h as ar,i as or,l as sr,m as cr,n as lr,o as ur,p as dr,r as fr,s as pr,t as mr,u as hr,v as gr,y as _r}from"./PluginsPage.BkwleEJf.js";import{c as vr,n as yr,t as br}from"./report-prompt.CAfZ6RIo.js";import{i as xr}from"./ui-auto-prompt.l_EXfDs5.js";import{h as Sr}from"./ui-auto.BmC9JJ_X.js";import{c as Cr,y as wr}from"./story-review.BXXv0Ko_.js";import{t as Tr}from"./NamePromptDialog.CS1pTTVl.js";var K=e(t(),1),Er=e(b(),1),q=`/__tb_sessions/runs`;async function Dr(e){try{return(await fetch(q,{signal:e??AbortSignal.timeout(1500)})).ok}catch{return!1}}async function Or(e){let t=await fetch(q,{signal:e??AbortSignal.timeout(3e3)});if(!t.ok)return[];let n=await t.json();return Array.isArray(n.runs)?n.runs:[]}async function kr(e){let t=await fetch(q,{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 Ar(e){await fetch(`${q}/${encodeURIComponent(e)}/stop`,{method:`POST`}).catch(()=>{})}async function jr(e){try{let t=await fetch(`${q}/${encodeURIComponent(e)}`,{signal:AbortSignal.timeout(3e3)});return t.status===404?{ok:!1}:t.ok?await t.json():null}catch{return null}}function Mr(e){return e===`completed`||e===`stopped`||e===`error`}function Nr(e,t,n,r){let i=new AbortController,a=`${q}/${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 Pr(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=Nr(e,i,e=>{typeof e.seq==`number`&&Number.isFinite(e.seq)&&(i=Math.max(i,e.seq)),n.onEvent(e),e.type===`status`&&Mr(e.status)&&(n.onTerminal?.(e),l())},t=>{r||n.signal?.aborted||(async()=>{a+=1;try{let r=await jr(e);if(r?.ok&&typeof r.seq==`number`&&(i=Math.max(i,r.seq)),r?.ok&&Mr(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 Fr(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 Ir(e,t){let n=(e||``).trim()||`新对话`;return n===`新对话`||n===Ue(t)}function Lr(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 Rr(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 Lr(await ve(e,i,n))||null}catch{return null}}function zr(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 Vr=new Map,Hr=new Map,Ur=40;function Wr(e,t,n=``){return`${e}:${t}:${n}`}function Gr(e){for(;e.size>Ur;){let t=e.keys().next().value;if(t===void 0)break;e.delete(t)}}function Kr(e,t,n,r,i=``){let a=e===`outline`?Vr:Hr,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}),Gr(a),c}var qr=`/__tb_sessions/log`;function Jr(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 Yr(e){try{let t=await fetch(qr,{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 Xr(e){return String(e??``).trim()}function Zr(e,t=80){let n=Xr(e).replace(/\s+/g,` `);return n?n.length>t?`${n.slice(0,t)}…`:n:``}function Qr(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=Xr(a.content),t=Zr(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=Xr(a.content),t=Xr(a.reasoning)||void 0;n.push({index:n.length+1,userPreview:r.preview,assistantPreview:Zr(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 $r(e,t){let n=String(t??``).trim();return!n||n===`inherit`||n===e.model?e:{...e,model:n}}var ei=`/__tb_fs`,ti=`你可以使用 office_to_pdf:优先用本机 LibreOffice 转为 PDF;若未安装,则对 docx/xlsx/pptx 降级抽取正文为同目录 .extracted.md(需写权限)。`,ni={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 ri(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(`${ei}/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 ii=`/__tb_fs`,ai=`你可以使用 load_workspace_dependencies:查询本机 node / npm / pnpm / python 等可执行文件绝对路径(需本地 fs 服务)。`,oi={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 si(e){if(e!==`load_workspace_dependencies`)return JSON.stringify({error:`unknown tool: ${e}`});try{let e=await fetch(`${ii}/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 ci(e){return Array.isArray(e)}function li(e){return ci(e)?e.some(e=>e.type===`image_url`):!1}function ui(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 di(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`&&li(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`||!li(e.content)||i.has(t)||!ci(e.content)?e:(a=!0,{...e,content:ui(e.content)}));return a?o:e}function fi(e){return e.reqSource?e.reqSource:e.reqPath?{kind:`doc`,path:e.reqPath}:void 0}function pi(e){let t=[e.templateTitle||e.templateId?.split(`/`).pop()||`默认模板`,e.outputFormat.toUpperCase()],n=fi(e);return n?.kind===`stories`?t.push(`${e.docTitle||`用户故事`} · ${n.storyIds.length} 条故事`):n?.kind===`doc`&&t.push(n.path.split(`/`).pop()||n.path),e.testPointIds?.length&&t.push(`${e.testPointIds.length} 条测试点`),t.join(` · `)}function mi(e){let t=e.match(/```(?:json)?\s*([\s\S]*?)```/)?.[1]??e.match(/\{[\s\S]*\}/)?.[0]??e.match(/\[[\s\S]*\]/)?.[0];if(!t)return null;try{let e=JSON.parse(t);if(Array.isArray(e)&&e.length>0)return{docTitle:``,cases:e,coverageRate:null,uncovered:[],writeNote:``};if(e&&typeof e==`object`){let t=e,n=t.用例??t.cases??t.items;if(!Array.isArray(n)||n.length===0)return null;let r=t.需求名称??t.文档名称??t.docTitle??t.title,i=typeof r==`string`?r.trim():``,a=t.覆盖需求率??t.coverageRate??t.coverage,o=null;if(typeof a==`number`&&Number.isFinite(a))o=Math.max(0,Math.min(100,Math.round(a)));else if(typeof a==`string`&&a.trim()){let e=parseInt(a.replace(/%/g,``),10);Number.isFinite(e)&&(o=Math.max(0,Math.min(100,e)))}let s=t.未覆盖说明??t.uncovered??t.omissions,c=Array.isArray(s)?s.map(e=>String(e).trim()).filter(Boolean):typeof s==`string`&&s.trim()?[s.trim()]:[],l=t.编写说明??t.note??t.summary,u=typeof l==`string`?l.trim():``;return{docTitle:i,cases:n,coverageRate:o,uncovered:c,writeNote:u}}}catch{return null}return null}function hi(e){return e.replace(/[\\/:*?"<>|]/g,`_`).replace(/\s+/g,`-`).slice(0,48)||`cases`}function gi(e,t){let n=[];for(let r of t){let t=e.filter(e=>!String(e[r]??``).trim()).length;t===e.length?n.push(`字段「${r}」全部为空`):t>Math.max(2,Math.floor(e.length*.3))&&n.push(`字段「${r}」有 ${t}/${e.length} 条为空`)}return n}function _i(e,t=``){let n=N(e.caseType).label,r=e.templateHeaders.length>0?e.templateHeaders:[...ue],i=e.outputFormat===`md`?`最终结果将保存为 Markdown 表格文件`:e.outputFormat===`csv`?`最终结果将保存为 CSV 文件`:`最终结果将保存为 Excel 文件`,a=e.promptBody.trim();if(!a)throw Error(`请先在生成测试用例插件中选择提示词`);return`${a}
@@ -223,4 +223,4 @@ ${t}
223
223
 
224
224
  `)}function Ol(e){let t=Dl(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 kl(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 Al(e){if(!wl.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(pc/1024/1024)} MB`);let t=await kl(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 jl(e,t){return e.length+t.length}var Ml=[{value:`low`,label:`Low`,desc:`响应更快,适合简单问答`},{value:`high`,label:`High`,desc:`质量与速度均衡(默认)`},{value:`max`,label:`Max`,desc:`最深推理,适合复杂分析`}],Nl=[{value:`readonly`,label:`仅可查看`},{value:`readwrite`,label:`工作区内修改`},{value:`full`,label:`完全权限`}];function Pl(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`?Et(`tool.kind.webSearch`):e===`web_fetch`?Et(`tool.kind.webFetch`):e.startsWith(`kb_`)?Et(`tool.kind.kb`):e.startsWith(`fs_`)?Et(`tool.kind.fs`):e.startsWith(`memory_`)?Et(`tool.kind.memory`):e}function Fl(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 Il(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 Ll({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,Z.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,Z.jsxs)($,{className:n,children:[(0,Z.jsx)(`circle`,{cx:`12`,cy:`12`,r:`3`}),(0,Z.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,Z.jsxs)($,{className:n,children:[(0,Z.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`}),(0,Z.jsx)(`path`,{d:`M2 12h20`}),(0,Z.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,Z.jsxs)($,{className:n,children:[(0,Z.jsx)(`path`,{d:`M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z`}),(0,Z.jsx)(`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`})]}):e===`memory`?(0,Z.jsx)($,{className:n,children:(0,Z.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,Z.jsx)($,{className:n,children:(0,Z.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 Rl(e,t){if(!t)return``;if(e.startsWith(`web_`))return $n(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 zl(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(`
225
225
  `),o=e.indexOf(`
226
- `,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 Bl(e,t,n,r){return e===`concise`?r===`running`?Et(`tool.running`):null:e===`standard`?Et(r===`running`?`tool.callingKind`:`tool.doneKind`,{kind:t}):Et(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,Z.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 Vl=({className:e=``})=>(0,Z.jsx)($,{className:e,children:(0,Z.jsx)(`path`,{d:`m6 9 6 6 6-6`})}),Hl=({className:e=``})=>(0,Z.jsx)($,{className:e,children:(0,Z.jsx)(`path`,{d:`m9 18 6-6-6-6`})}),Ul=({className:e=``})=>(0,Z.jsx)($,{className:e,children:(0,Z.jsx)(`path`,{d:`M20 6 9 17l-5-5`})}),Wl=({className:e=``})=>(0,Z.jsxs)($,{className:e,children:[(0,Z.jsx)(`rect`,{width:`14`,height:`14`,x:`8`,y:`8`,rx:`2`,ry:`2`}),(0,Z.jsx)(`path`,{d:`M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2`})]}),Gl=({className:e=``})=>(0,Z.jsxs)($,{className:e,children:[(0,Z.jsx)(`ellipse`,{cx:`12`,cy:`5`,rx:`9`,ry:`3`}),(0,Z.jsx)(`path`,{d:`M3 5v14a9 3 0 0 0 18 0V5`}),(0,Z.jsx)(`path`,{d:`M3 12a9 3 0 0 0 18 0`})]}),Kl=({className:e=``})=>(0,Z.jsxs)($,{className:e,children:[(0,Z.jsx)(`path`,{d:`m12 14 4-4`}),(0,Z.jsx)(`path`,{d:`M3.34 19a10 10 0 1 1 17.32 0`})]}),ql=({className:e=``})=>(0,Z.jsxs)($,{className:e,children:[(0,Z.jsx)(`path`,{d:`M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z`}),(0,Z.jsx)(`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`})]}),Jl=({className:e=``})=>(0,Z.jsx)($,{className:e,children:(0,Z.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`})}),Yl=({className:e=``})=>(0,Z.jsxs)($,{className:e,children:[(0,Z.jsx)(`path`,{d:`m5 12 7-7 7 7`}),(0,Z.jsx)(`path`,{d:`M12 19V5`})]}),Xl=({className:e=``,open:t=!1})=>(0,Z.jsx)($,{className:e,children:t?(0,Z.jsx)(Z.Fragment,{children:(0,Z.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,Z.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`})}),Zl=({className:e=``,open:t=!1})=>(0,Z.jsx)(`svg`,{className:`${e} tw-arrow ${t?`is-open`:``}`,viewBox:`0 0 12 12`,fill:`currentColor`,"aria-hidden":!0,children:(0,Z.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`})}),Ql=({className:e=``})=>(0,Z.jsxs)($,{className:e,children:[(0,Z.jsx)(`circle`,{cx:`11`,cy:`11`,r:`8`}),(0,Z.jsx)(`path`,{d:`m21 21-4.3-4.3`})]}),$l=({className:e=``})=>(0,Z.jsxs)($,{className:e,children:[(0,Z.jsx)(`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`}),(0,Z.jsx)(`path`,{d:`M12 8v8`}),(0,Z.jsx)(`path`,{d:`M8 12h8`})]}),eu=({className:e=``,filled:t=!1})=>(0,Z.jsx)($,{className:e,children:t?(0,Z.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,Z.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`})}),tu=({className:e=``})=>(0,Z.jsxs)($,{className:e,children:[(0,Z.jsx)(`circle`,{cx:`12`,cy:`12`,r:`1`,fill:`currentColor`,stroke:`none`}),(0,Z.jsx)(`circle`,{cx:`5`,cy:`12`,r:`1`,fill:`currentColor`,stroke:`none`}),(0,Z.jsx)(`circle`,{cx:`19`,cy:`12`,r:`1`,fill:`currentColor`,stroke:`none`})]}),nu=({className:e=``})=>(0,Z.jsxs)($,{className:e,children:[(0,Z.jsx)(`path`,{d:`M4 8h16v11a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V8Z`}),(0,Z.jsx)(`path`,{d:`M8 8V5a1 1 0 0 1 1-1h6a1 1 0 0 1 1 1v3`}),(0,Z.jsx)(`path`,{d:`M10 12h4`})]}),ru=({className:e=``})=>(0,Z.jsxs)($,{className:e,children:[(0,Z.jsx)(`path`,{d:`M12 22v-5`}),(0,Z.jsx)(`path`,{d:`M9 8V2`}),(0,Z.jsx)(`path`,{d:`M15 8V2`}),(0,Z.jsx)(`path`,{d:`M18 8v5a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V8Z`})]});function iu(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 au(e){let t=iu(e);return t===`刚刚`?`刚刚`:t.endsWith(`前`)?t:`${t}前`}function ou({open:e,onToggle:t,onRename:n,onDelete:r}){let i=(0,K.useRef)(null);return(0,Z.jsxs)(`div`,{className:`relative`,children:[(0,Z.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,Z.jsx)(tu,{className:`w-3.5 h-3.5`})}),(0,Z.jsxs)(su,{open:e,anchorRef:i,dataAttr:`data-ws-menu`,children:[(0,Z.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,Z.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Z.jsx)(`path`,{d:`M12 20h9`}),(0,Z.jsx)(`path`,{d:`M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z`})]}),`重命名`]}),r?(0,Z.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,Z.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Z.jsx)(`path`,{d:`M3 6h18`}),(0,Z.jsx)(`path`,{d:`M8 6V4h8v2`}),(0,Z.jsx)(`path`,{d:`M19 6l-1 14H6L5 6`})]}),`删除工作区`]}):null]})]})}function su({open:e,anchorRef:t,dataAttr:n,children:r}){let[i,a]=(0,K.useState)(null);return(0,K.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,Er.createPortal)((0,Z.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 cu({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,K.useRef)(null),m=(0,K.useRef)(null),h=(0,K.useRef)(null),g=(0,K.useRef)(null),_=(0,K.useRef)(null),v=(0,K.useRef)(null),[y,b]=(0,K.useState)(!1),[x,S]=(0,K.useState)(!1),[C,w]=(0,K.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 O(){E(),T(),_.current=setTimeout(()=>S(!0),1e3)}let k=e.title.trim()||`新对话`;(0,K.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,K.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,K.useEffect)(()=>{r&&(T(),E(),S(!1))},[r]);let A=i?`生成中`:`空闲`,ee=!!(e.archived||e.deleted);return(0,Z.jsxs)(`div`,{ref:p,className:`tw-session-row relative ${t?`is-nested`:``} ${n?`is-selected`:``} ${r?`is-menu-open`:``} ${i?`is-busy`:``} ${ee?`opacity-50`:``}`,onMouseLeave:()=>{T(),D()},children:[i?(0,Z.jsx)(`span`,{className:`tw-session-busy-slot`,"data-hint":`生成中`,"aria-label":`生成中`,children:(0,Z.jsx)(`span`,{className:`tw-session-busy-dot`,"aria-hidden":!0})}):null,e.pinned&&!ee?(0,Z.jsx)(`span`,{className:`tw-slot`,"aria-hidden":!0,children:(0,Z.jsx)(eu,{filled:!0,className:`tw-pin-indicator w-3 h-3`})}):null,(0,Z.jsx)(`button`,{ref:h,type:`button`,onClick:a,onDoubleClick:o,onMouseEnter:()=>O(),onMouseLeave:()=>{T(),D()},className:`tw-session-title text-left outline-none focus:outline-none focus-visible:outline-none ${y?`is-overflow`:``}`,children:(0,Z.jsx)(`span`,{ref:g,className:`tw-session-title-inner`,children:e.title})}),(0,Z.jsx)(`span`,{className:`tw-session-time pr-1`,children:iu(e.updatedAt)}),(0,Z.jsxs)(`div`,{"data-session-menu":``,className:`tw-row-actions items-center gap-0.5 shrink-0`,onClick:e=>e.stopPropagation(),children:[(0,Z.jsxs)(`div`,{className:`relative`,children:[(0,Z.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,Z.jsx)(tu,{className:`w-3.5 h-3.5`})}),(0,Z.jsx)(su,{open:r,anchorRef:m,dataAttr:`data-session-menu`,children:e.deleted?(0,Z.jsxs)(Z.Fragment,{children:[f?(0,Z.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,Z.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,Z.jsxs)(Z.Fragment,{children:[!e.archived&&(0,Z.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,Z.jsx)(eu,{filled:!!e.pinned,className:`w-3.5 h-3.5`}),e.pinned?`取消置顶`:`置顶会话`]}),(0,Z.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,Z.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Z.jsx)(`path`,{d:`M12 20h9`}),(0,Z.jsx)(`path`,{d:`M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z`})]}),`重命名`]}),(0,Z.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,Z.jsx)(nu,{className:`w-3.5 h-3.5`}),e.archived?`取消归档`:`归档会话`]}),(0,Z.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,Z.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Z.jsx)(`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`}),(0,Z.jsx)(`polyline`,{points:`7 10 12 15 17 10`}),(0,Z.jsx)(`line`,{x1:`12`,x2:`12`,y1:`15`,y2:`3`})]}),`导出会话`]}),e.archived?(0,Z.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,Z.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Z.jsx)(`path`,{d:`M3 6h18`}),(0,Z.jsx)(`path`,{d:`M8 6V4h8v2`}),(0,Z.jsx)(`path`,{d:`M19 6l-1 14H6L5 6`})]}),`永久删除`]}):null]})})]}),!e.deleted&&(0,Z.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,Z.jsx)(nu,{className:`w-3.5 h-3.5`})}),!e.archived&&!e.deleted&&(0,Z.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,Z.jsx)(eu,{filled:!!e.pinned,className:`w-3.5 h-3.5`})})]}),x&&!r&&C&&typeof document<`u`?(0,Er.createPortal)((0,Z.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,Z.jsx)(`div`,{className:`tw-session-preview-title`,children:k}),(0,Z.jsx)(`div`,{className:`tw-session-preview-meta`,children:au(e.updatedAt)}),(0,Z.jsx)(`div`,{className:`tw-session-preview-status ${i?`is-busy`:``}`,children:A})]}),document.body):null]})}var lu=`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 uu({level:e,className:t=``}){return(0,Z.jsxs)($,{className:t,children:[(0,Z.jsx)(`path`,{d:lu}),e===`readonly`&&(0,Z.jsx)(`path`,{d:`m9 12 2 2 4-4`}),e===`readwrite`&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`path`,{d:`M9 10h6`}),(0,Z.jsx)(`path`,{d:`M9 14h3`})]}),e===`full`&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`path`,{d:`M12 8v4`}),(0,Z.jsx)(`path`,{d:`M12 16h.01`})]})]})}function du(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function fu(e){return`${e.toLocaleString(`en-US`)} tok`}function pu(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 mu(e){return e>=99.95?`100`:e>=10?String(Math.round(e)):e.toFixed(1)}function hu(e){let t=0;for(let n of e)t+=/[\u4e00-\u9fff]/.test(n)?1:.25;return Math.max(1,Math.round(t))}function gu(e){return e.uncachedTokens==null?e.cachedTokens==null?e.promptTokens:Math.max(0,e.promptTokens-e.cachedTokens):e.uncachedTokens}function _u(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 vu(e,t){return t<=0?null:e/t*100}function yu(e){return e>=1024?`${(e/1024).toFixed(1)} KB`:`${e} B`}function bu(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 xu(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 Su({text:e}){let[t,n]=(0,K.useState)(!1),r=(0,K.useRef)(null);(0,K.useEffect)(()=>()=>{r.current!==null&&window.clearTimeout(r.current)},[]);async function i(){t||await xu(e)&&(n(!0),r.current=window.setTimeout(()=>n(!1),1e3))}return(0,Z.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,Z.jsx)(Ul,{className:`w-3.5 h-3.5 text-emerald-600`}):(0,Z.jsx)(Wl,{className:`w-3.5 h-3.5`})})}function Cu({pct:e}){return(0,Z.jsxs)(`svg`,{className:`w-3.5 h-3.5 -rotate-90`,viewBox:`0 0 20 20`,"aria-hidden":`true`,children:[(0,Z.jsx)(`circle`,{cx:`10`,cy:`10`,r:`8`,fill:`none`,stroke:`var(--color-stone-200)`,strokeWidth:`3`}),(0,Z.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 wu(){let[e,t]=(0,K.useState)(!1),n=(0,K.useRef)(null),r=(0,K.useRef)(null),[i,a]=(0,K.useState)(null);return(0,K.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,K.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 Tu({title:e,titleValue:t,icon:n,children:r}){return(0,Z.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,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-[13px]`,children:[n,(0,Z.jsx)(`span`,{className:`tw-popover-title font-medium text-stone-800`,children:e}),t!==void 0&&(0,Z.jsx)(`span`,{className:`tw-popover-muted ml-auto text-stone-500 tabular-nums`,children:t})]}),(0,Z.jsx)(`div`,{className:`mt-2.5 mb-2.5 border-t border-stone-100`}),r]})}function Eu({rows:e}){return(0,Z.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,Z.jsxs)(`div`,{className:`contents`,children:[(0,Z.jsx)(`dt`,{className:`text-stone-500`,children:e.label}),(0,Z.jsx)(`dd`,{className:`text-stone-800 tabular-nums text-right`,children:e.value})]},e.label))})}function Du({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}=wu();return(0,Z.jsxs)(`span`,{ref:l,className:`relative inline-flex items-center`,children:[(0,Z.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,Z.jsx)(`span`,{className:`leading-none`,children:e})]}),s&&(0,Er.createPortal)((0,Z.jsx)(`div`,{ref:u,role:`dialog`,"aria-label":r,style:d??{position:`fixed`,left:0,top:0,visibility:`hidden`},className:`z-80`,children:(0,Z.jsx)(Tu,{title:r,titleValue:i,icon:t,children:a})}),document.body)]})}function Ou({messages:e,busy:t,onRestoreCheckpoint:n}){let[r,i]=(0,K.useState)(()=>new Set),a=(0,K.useMemo)(()=>Qr(e.map(e=>({role:e.role,content:typeof e.content==`string`?e.content:Dl(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,Z.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,Z.jsxs)(`li`,{className:`rounded-xl border bg-white shadow-sm overflow-hidden ${i?`border-[#4176e6]/35`:`border-stone-200`}`,children:[(0,Z.jsxs)(`div`,{className:`flex items-start gap-1 px-3 py-2.5`,children:[(0,Z.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,Z.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,Z.jsxs)(`span`,{className:`text-[11px] font-medium text-stone-400 tabular-nums`,children:[`第 `,e.index,` 轮`]}),(0,Z.jsx)(Vl,{className:`w-3.5 h-3.5 text-stone-400 ml-auto shrink-0 transition-transform ${i?`rotate-180`:``}`})]}),i?null:(0,Z.jsxs)(`div`,{className:`space-y-1 text-[13px] leading-5`,children:[(0,Z.jsxs)(`p`,{className:`m-0 text-stone-800 truncate`,children:[(0,Z.jsx)(`span`,{className:`text-stone-400 mr-1.5`,children:`用户`}),e.userPreview]}),(0,Z.jsxs)(`p`,{className:`m-0 text-stone-600 truncate`,children:[(0,Z.jsx)(`span`,{className:`text-stone-400 mr-1.5`,children:`助手`}),e.assistantPreview||`(待回复)`]})]})]}),n?(0,Z.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,Z.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,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`div`,{className:`text-[11px] font-medium text-stone-400 mb-0.5`,children:`用户`}),(0,Z.jsx)(`div`,{className:`whitespace-pre-wrap break-words text-stone-800`,children:e.userText||`—`})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`div`,{className:`text-[11px] font-medium text-stone-400 mb-0.5`,children:`助手`}),e.assistantText?(0,Z.jsx)(`div`,{className:`chat-md prose prose-sm prose-stone max-w-none tw-chat-text`,dangerouslySetInnerHTML:{__html:Dt(e.assistantText)}}):(0,Z.jsx)(`div`,{className:`text-stone-400`,children:`(待回复)`})]})]}):null]},e.index)})}):(0,Z.jsx)(`div`,{className:`h-full flex items-center justify-center text-sm text-stone-400`,children:`暂无回合(还没有用户/助手对话)`})}function ku({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?gu(t.usage):0),0),d=r.reduce((e,t)=>e+(t.usage?.cacheWriteTokens??0),0),f=r.reduce((e,t)=>e+_u(t.usage),0),p=r.some(e=>e.usage?.cachedTokens!=null),m=p?vu(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?R[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,Z.jsxs)(`div`,{className:`flex items-center justify-center gap-1 pt-2 text-xs text-stone-400 tabular-nums select-none`,children:[(0,Z.jsx)(Du,{icon:(0,Z.jsx)(Kl,{className:`w-3.5 h-3.5`}),label:(0,Z.jsxs)(Z.Fragment,{children:[a,` 轮 `,o,` 步`,S?` · ${Math.round(S)} tok/s`:``]}),ariaLabel:`会话统计`,title:`会话统计`,children:(0,Z.jsx)(Eu,{rows:[{label:`模型用时`,value:h>0?pu(h):`—`},{label:`工具调用用时`,value:g>0?pu(g):`—`},{label:`首 token 平均 (TTFT)`,value:_.length?pu(v):`—`},{label:`输出速度 (TPS)`,value:S?`${Math.round(S)} tok/s`:`—`}]})}),(0,Z.jsx)(Du,{icon:(0,Z.jsx)(Gl,{className:`w-3.5 h-3.5`}),label:(0,Z.jsxs)(Z.Fragment,{children:[du(s),` tok`,m==null?``:` · 缓存命中 ${mu(m)}%`]}),ariaLabel:`Token 用量`,title:`Token 用量`,titleValue:fu(s),children:(0,Z.jsx)(Eu,{rows:[{label:`缓存命中`,value:m==null?`—`:`${mu(m)}%`,hide:m==null},{label:`未缓存输入`,value:fu(u)},{label:`缓存读取`,value:fu(l),hide:!p},{label:`缓存写入`,value:fu(d),hide:d<=0},{label:`输出`,value:fu(f)}]})}),T!==void 0&&C&&(0,Z.jsxs)(Du,{icon:(0,Z.jsx)(Cu,{pct:T}),label:`${mu(T)}%`,ariaLabel:`上下文占用`,title:`上下文已用 ${mu(T)}%`,titleValue:`~${du(w)} / ${du(C)}`,children:[(0,Z.jsxs)(`div`,{className:`h-2 rounded-full bg-stone-100 overflow-hidden flex mb-3`,children:[(0,Z.jsx)(`span`,{className:`h-full bg-stone-400`,style:{width:`${E/C*100}%`},"data-hint":`系统提示词`}),(0,Z.jsx)(`span`,{className:`h-full bg-[#4176e6]`,style:{width:`${D/C*100}%`},"data-hint":`对话消息`})]}),(0,Z.jsx)(Eu,{rows:[{label:`系统提示词`,value:`~${du(E)}`},{label:`对话消息`,value:`~${du(D)}`}]}),(0,Z.jsx)(`p`,{className:`mt-2.5 text-[11px] leading-4 text-stone-400`,children:`分段为示意估算(API 不返回上下文拆分);总量以最近一轮 prompt_tokens 为准。`})]})]})}function Au({usage:e,model:t}){let n=e.cachedTokens==null?null:vu(e.cachedTokens,e.promptTokens);return(0,Z.jsx)(Du,{variant:`ghost`,icon:(0,Z.jsx)(Gl,{className:`w-3.5 h-3.5 shrink-0`}),label:(0,Z.jsxs)(Z.Fragment,{children:[`用量 `,du(e.totalTokens),` tok`]}),ariaLabel:`本轮用量`,title:`本轮用量`,titleValue:fu(e.totalTokens),children:(0,Z.jsx)(Eu,{rows:[{label:`提供方 / 模型`,value:t??`—`,hide:!t},{label:`缓存命中`,value:n==null?`—`:`${mu(n)}%`,hide:n==null},{label:`未缓存输入`,value:fu(gu(e))},{label:`缓存读取`,value:fu(e.cachedTokens??0),hide:e.cachedTokens==null},{label:`缓存写入`,value:fu(e.cacheWriteTokens??0),hide:!(e.cacheWriteTokens&&e.cacheWriteTokens>0)},{label:`输出`,value:fu(e.completionTokens)}]})})}function ju({settings:e}){let[t,n]=(0,K.useState)(!1),[r,i]=(0,K.useState)(null),[a,o]=(0,K.useState)([]),[s,c]=(0,K.useState)(`idle`),l=(0,K.useRef)(null),u=(0,K.useRef)(0);if((0,K.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,K.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;_e(e.baseURL,e.apiKey).then(t=>{if(r!==u.current)return;let n=t.length?t:[e.model];o(n),c(`ok`),t.length&&Le({availableModels:t})}).catch(()=>{r===u.current&&c(n.length>1?`ok`:`fail`)})},[t,e]),!e)return(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>ze(`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,Z.jsx)(`span`,{className:`whitespace-nowrap`,children:`配置模型`}),(0,Z.jsx)(Vl,{className:`w-3.5 h-3.5 shrink-0 text-stone-400`})]});let d=e.reasoningEffort??`high`,f=Ml.find(e=>e.value===d)?.label??`High`;function p(e){Le(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,Z.jsxs)(`div`,{ref:l,className:`relative`,children:[(0,Z.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,Z.jsx)(`span`,{className:`tw-composer-bar-model-name max-w-40 truncate text-stone-600`,children:e.model}),(0,Z.jsx)(`span`,{className:`tw-composer-bar-effort whitespace-nowrap text-stone-400`,children:f}),(0,Z.jsx)(Vl,{className:`w-3.5 h-3.5 shrink-0 text-stone-400 transition-transform ${t?`rotate-180`:``}`})]}),t&&(0,Z.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,Z.jsxs)(`button`,{type:`button`,onMouseEnter:()=>i(`model`),onClick:()=>i(`model`),className:m(r===`model`),children:[(0,Z.jsx)(`span`,{className:`text-stone-700`,children:`模型`}),(0,Z.jsx)(`span`,{className:`ml-auto max-w-32 truncate text-stone-400`,children:e.model}),(0,Z.jsx)(Hl,{className:`w-3.5 h-3.5 text-stone-400`})]}),(0,Z.jsxs)(`button`,{type:`button`,onMouseEnter:()=>i(`effort`),onClick:()=>i(`effort`),className:m(r===`effort`),children:[(0,Z.jsx)(`span`,{className:`text-stone-700`,children:`推理等级`}),(0,Z.jsx)(`span`,{className:`ml-auto text-stone-400`,children:f}),(0,Z.jsx)(Hl,{className:`w-3.5 h-3.5 text-stone-400`})]}),r===`model`&&(0,Z.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,Z.jsx)(`div`,{className:`px-3 py-2 text-xs text-stone-400`,children:`正在识别可用模型…`}),a.map(t=>(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>p({model:t}),className:m(!1),children:[(0,Z.jsx)(`span`,{className:`flex-1 truncate ${t===e.model?`text-stone-900 font-medium`:`text-stone-600`}`,children:t}),t===e.model&&(0,Z.jsx)(Ul,{className:`w-3.5 h-3.5 text-[#4176e6]`})]},t)),(0,Z.jsx)(`div`,{className:`mt-1 border-t border-stone-100 pt-1`,children:(0,Z.jsx)(`button`,{type:`button`,onClick:()=>{n(!1),i(null),ze(`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,Z.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:Ml.map(e=>(0,Z.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,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-[13px]`,children:[(0,Z.jsx)(`span`,{className:`flex-1 ${d===e.value?`text-stone-900 font-medium`:`text-stone-600`}`,children:e.label}),d===e.value&&(0,Z.jsx)(Ul,{className:`w-3.5 h-3.5 text-[#4176e6]`})]}),(0,Z.jsx)(`div`,{className:`mt-0.5 text-xs text-stone-400`,children:e.desc})]},e.value))})]})]})}var Mu=null;function Nu(){if(!Mu){let e=st();Mu={store:e,messages:e.sessions.find(t=>t.id===e.activeId)?.messages??[]}}return Mu}function Pu({slashDocs:e=[]}){let[t,n]=(0,K.useState)(null),[r,i]=(0,K.useState)(!1),[a,o]=(0,K.useState)(()=>Nu().store),[c,l]=(0,K.useState)(()=>Nu().messages),[u,d]=(0,K.useState)(()=>Tt(Nu().store.activeId??``)),[f,m]=(0,K.useState)([]),[b,x]=(0,K.useState)([]),[S,C]=(0,K.useState)([]),[w,k]=(0,K.useState)(Sl),[ee,te]=(0,K.useState)(!1),[j,ne]=(0,K.useState)(null),re=(0,K.useRef)(null);re.current=j;let[ie,ae]=(0,K.useState)(null),[N,P]=(0,K.useState)(!1),[oe,se]=(0,K.useState)(null),ce=(0,K.useRef)(null);ce.current=oe;let[le,ue]=(0,K.useState)(!1),[F,de]=(0,K.useState)(null),fe=(0,K.useRef)(null);fe.current=F;let[I,L]=(0,K.useState)(null),pe=(0,K.useRef)(null);pe.current=I;let me=(0,K.useRef)(null),[he,_e]=(0,K.useState)(null),[ve,R]=(0,K.useState)(0),[be,xe]=(0,K.useState)(!1),[Se,Ee]=(0,K.useState)(null),[ke,Ae]=(0,K.useState)(null),[je,Me]=(0,K.useState)(null),[Le,He]=(0,K.useState)(null),[Ue,st]=(0,K.useState)(null),[ht,gt]=(0,K.useState)(!1),[_t,vt]=(0,K.useState)([]),[Ot,Bt]=(0,K.useState)(null),[Yt,Xt]=(0,K.useState)(`error`);function B(e,t=`error`){Xt(t),Bt(e)}let[Zt,Qt]=(0,K.useState)(`readonly`),[$t,en]=(0,K.useState)(!1),[tn,nn]=(0,K.useState)(!0),[rn,an]=(0,K.useState)(!1),[V,on]=(0,K.useState)(()=>p()),[sn,cn]=(0,K.useState)(``),[ln,un]=(0,K.useState)(null),[dn,fn]=(0,K.useState)(null),[pn,mn]=(0,K.useState)(!1),[hn,gn]=(0,K.useState)(null),[_n,vn]=(0,K.useState)(null),[yn,bn]=(0,K.useState)(null),[H,Sn]=(0,K.useState)(null),[Cn,wn]=(0,K.useState)(!1),[Tn,En]=(0,K.useState)({}),[Dn,On]=(0,K.useState)(``),[kn,An]=(0,K.useState)(!1),[jn,U]=(0,K.useState)(null),[W,Mn]=(0,K.useState)(()=>y(El,Tl,`dialog`)),[Pn,Vn]=(0,K.useState)(()=>typeof window>`u`?{language:`zh-CN`,appearance:`system`,sessionFontSize:14,toolStepDetail:`standard`,busySendBehavior:`queue`,subagentModel:``}:Ve()),[Gn,Kn]=(0,K.useState)(!1),[$n,G]=(0,K.useState)(null),[tr,rr]=(0,K.useState)(0),[ir,or]=(0,K.useState)(!1),[sr,cr]=(0,K.useState)(!1),[lr,ur]=(0,K.useState)(!1),[dr,pr]=(0,K.useState)(!0),[hr,gr]=(0,K.useState)([]),[xr,Sr]=(0,K.useState)([]),Cr=!!(V.memory&&ln?.ok),wr=!!V.knowledge,Er=!!yn?.ok,q=!!dn?.ok,Mr=pn&&!q,Nr=!!hn?.ok,Lr=!!(_n?.ok&&_n.available),Vr=(0,K.useRef)(null),Hr=(0,K.useRef)(new Map),Ur=(0,K.useRef)(null),Wr=(0,K.useRef)(new Map),Gr=(0,K.useRef)(new Map),qr=(0,K.useRef)(new Map),Xr=(0,K.useRef)(null),Zr=(0,K.useRef)(!1),Qr=(0,K.useRef)(null),ei=(0,K.useRef)(null),[ti,ii]=(0,K.useState)([]),[ai,ci]=(0,K.useState)(null),li=(0,K.useRef)(null),ui=(0,K.useRef)(0),fi=(0,K.useRef)(new Set),[mi,hi]=(0,K.useState)(`off`),[gi,yi]=(0,K.useState)(null),[bi,Si]=(0,K.useState)(`day`),[Ci,wi]=(0,K.useState)([]),[Ti,Ei]=(0,K.useState)(null),[Di,ki]=(0,K.useState)(null),[Ai,ji]=(0,K.useState)(null),[Pi,Fi]=(0,K.useState)({}),[Li,Ri]=(0,K.useState)(0),[zi,Bi]=(0,K.useState)(!1),[Vi,Ui]=(0,K.useState)(null),[Wi,Gi]=(0,K.useState)(!1),[Ki,qi]=(0,K.useState)(``),[Ji,Yi]=(0,K.useState)(null),[Qi,$i]=(0,K.useState)(!1),ta=(0,K.useRef)(null),ra=(0,K.useRef)(null);function ia(){ra.current!==null&&(window.clearTimeout(ra.current),ra.current=null)}function sa(){ia(),$i(!1)}function ca(e,t,n={}){return new Promise(r=>{ta.current?.(null),ta.current=r,sa(),Yi({kind:e,items:t,quick:n.quick,quickNote:n.quickNote})})}function la(e){let t=ta.current;ta.current=null,$i(!0),ia(),ra.current=window.setTimeout(()=>{ra.current=null,Yi(null),$i(!1)},160),t?.(e)}let ua=(0,K.useRef)(()=>{});ua.current=()=>la(null),(0,K.useEffect)(()=>{if(!Ji||Qi)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`)||ua.current())};return document.addEventListener(`pointerdown`,e,!0),()=>document.removeEventListener(`pointerdown`,e,!0)},[Ji,Qi]);function da(e){ur(!1),V[e===`todo`?`todos`:`tasks`]&&(sa(),Yi({kind:e,manual:!0,items:[cl(e)]}))}async function fa(e,t){let n=e===`todo`?`待办`:`任务`;try{e===`todo`?await Nn(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 xn(t.map(e=>({title:e.title.trim(),status:e.status,priority:e.priority,startDate:e.startDate,dueDate:e.dueDate,note:e.note})),{mode:`manual`}),B(`已新增 ${t.length} 条${n},可在侧栏「${n===`待办`?`待办事项`:`任务管理`}」查看。`,`ok`)}catch(e){Xt(`error`),B(e instanceof Error?e.message:String(e))}}(0,K.useEffect)(()=>()=>{ta.current?.(null),ta.current=null,ra.current!==null&&(window.clearTimeout(ra.current),ra.current=null)},[]);let J=(0,K.useRef)([]),_a=(0,K.useRef)(null);function va(e){J.current=e,gr(e)}function ya(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 ba=(0,K.useRef)(null),xa=(0,K.useRef)(null),Sa=(0,K.useRef)(null),Ca=(0,K.useRef)(null),wa=(0,K.useRef)(null),Ta=(0,K.useRef)(null),Ea=(0,K.useRef)(null),Da=(0,K.useRef)(null),Oa=(0,K.useRef)({}),ka=!!(q&&H?.workspace),ja=bl(u),Ma=(()=>{if(!ja||!wr)return[];let t=ja.query.toLowerCase();return(t?e.filter(e=>sc(e,t)):e).slice(0,10)})(),Pa=(()=>{if(!ja||!ka)return[];let e=ja.query.toLowerCase(),t=xr.map(e=>({collection:`workspace`,id:`ws:${e.path}`,title:e.name,category:Jt(H?.workspace,H?.projectRoot),description:e.path,format:e.type===`dir`?`dir`:`file`,path:e.path}));return(e?t.filter(t=>sc(t,e)||t.path.toLowerCase().includes(e)||t.title.toLowerCase().includes(e)):t).slice(0,10)})(),Fa=[...Ma.map(e=>({section:`project`,doc:e})),...Pa.map(e=>({section:`workspace`,doc:e}))],Ia=!(!ja||ir),La=yl(u),Ra=_.filter(e=>e.hasPanel&&V[e.id]),Ba=!!(La&&!sr&&!Ia&&Ra.length>0),Va=(0,K.useRef)(!0),Ha=(0,K.useRef)(!1),Y=(0,K.useRef)(null),Ua=(0,K.useRef)(null),Ka=(0,K.useRef)([]);Ka.current=c;let qa=(0,K.useRef)(u);qa.current=u,Ua.current=H,(0,K.useEffect)(()=>{let e=a?.activeId;if(!e)return;let t=window.setTimeout(()=>bt(e,u),400);return()=>window.clearTimeout(t)},[u,a?.activeId]),(0,K.useEffect)(()=>{let e=()=>{let e=Y.current?.activeId;e&&bt(e,qa.current)},t=()=>{document.visibilityState===`hidden`&&e()};return window.addEventListener(`pagehide`,e),document.addEventListener(`visibilitychange`,t),()=>{window.removeEventListener(`pagehide`,e),document.removeEventListener(`visibilitychange`,t)}},[]);function X(e){Y.current=e,o(e),dt(e)}let Ja=a?.sessions.find(e=>e.id===a.activeId),Ya=Ja?.id,$a=Ja?.access;(0,K.useEffect)(()=>{Ya&&Qt($a??Re())},[Ya,$a]),(0,K.useEffect)(()=>{let e=!1,t=Fe(()=>n(Ie())),r=h(e=>on(e)),a=Pe(e=>{Vn(e),Be(e)});return(async()=>{if(await s(),e)return;let t=Ve();Vn(t),Be(t),n(Ie()),Qt(Re()),on(p()),nn($e());let r=new URLSearchParams(window.location.search),a=r.get(`session`),c=await ut({preferSessionId:a});if(e)return;let u=c;if(a&&!u.sessions.some(e=>e.id===a))try{let e=sessionStorage.getItem(at(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 rt(u))}}catch{}if(a)try{sessionStorage.removeItem(at(a))}catch{}let f=r.get(`focusRoot`),m=r.get(`focusPath`),h=r.get(`attachRoot`),_=r.get(`attachPath`),v=r.get(`attachName`),y=null;if(f&&m)try{y=`${f}:${decodeURIComponent(m).replace(/\\/g,`/`).replace(/^\/+/,``)}`}catch{y=`${f}:${m}`}if(a&&u.sessions.some(e=>e.id===a)&&(u=Ke(u,a),dt(u)),y&&_e(y),h&&_){let e=h;if(e===`cases`||e===`prompts`||e===`knowledge`||e===`templates`){let t=_,n=v||``;try{t=decodeURIComponent(_).replace(/\\/g,`/`).replace(/^\/+/,``),v&&(n=decodeURIComponent(v))}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 b=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 x=[];try{x=(await Or()).map(e=>e.sessionId)}catch{x=[]}let S=new Set(x);u=S.size?{...u,sessions:u.sessions.map(e=>{if(S.has(e.id))return e;let t=mt(e.messages);return t===e.messages?e:{...e,messages:t}})}:Xe(u);let w=Re();u.sessions.some(e=>!e.access)&&(u={...u,sessions:u.sessions.map(e=>e.access?e:{...e,access:w})}),Y.current=u,o(u),dt(u);let T=u.sessions.find(e=>e.id===u.activeId);if(l(T?.messages??[]),d(e=>e.trim()?e:Tt(u.activeId)),wi(wt(u.activeId)),ne(T?.caseGen?.active?T.caseGen:null),se(T?.promptGen?.active?T.promptGen:null),de(T?.knowledgeGen?.active?T.knowledgeGen:null),L(T?.pluginDev?.active?T.pluginDev:null),Qt(T?.access??w),T?.pluginDev?.active&&(yi(`pluginDev`),T.access!==`readwrite`&&T.access!==`full`)){Qt(`readwrite`);let e={...u,sessions:u.sessions.map(e=>e.id===u.activeId?{...e,access:`readwrite`}:e)};Y.current=e,o(e),dt(e)}ii(yo(T?.todos));{let e=Bo(T?.goal);li.current=e,ci(e)}(b===`day`||b===`week`||b===`month`)&&p().reports&&ls(b),T?.workspacePath&&En(e=>({...e,[T.workspacePath]:!0})),(T?.messages??[]).length||Mn(`dialog`),vt(x),i(!0),x.length&&queueMicrotask(()=>{for(let e of x)Fo(e,!0),e===Y.current?.activeId&&(Zr.current=!0,gt(!0),Yo(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(p()[n]){if(n===`pluginDev`)cs();else{let t=Y.current?.sessions.find(e=>e.id===Y.current?.activeId);if((!t||t.archived||t.deleted||Array.isArray(t.messages)&&t.messages.length>0||t.caseGen?.active||t.promptGen?.active||t.knowledgeGen?.active)&&Y.current){let e=Y.current.activeId,t=To(e)??Y.current,n=H?.workspace?.trim()||void 0,r=ot(t,{workspacePath:n,access:Re()});Y.current=r,o(r),dt(r),l([]),ne(null),se(null),de(null),ii([]),li.current=null,ci(null),hi(`off`)}if(n===`promptGen`)P(!0);else if(n===`knowledgeGen`)ue(!0);else{let t=e.searchParams.get(`reqDoc`);t&&(ae({docId:t,storyIds:(e.searchParams.get(`stories`)??``).split(`,`).map(e=>e.trim()).filter(Boolean)}),e.searchParams.delete(`reqDoc`),e.searchParams.delete(`stories`)),te(!0)}}}else B(g(n));e.searchParams.delete(`plugin`),window.history.replaceState({},``,e.pathname+e.search+e.hash)}}catch{}(async()=>{try{if(!await we(`prompts`)){M(`提示词管理服务未就绪,系统提示词暂时用内置兜底。`,`error`);return}let e=(await Ce(`prompts`,Ne)).content.trim();e?k(e):M(`「提示词管理/${Ne}」是空的,系统提示词暂时用内置兜底。`,`error`)}catch{M(`没有读到「提示词管理/${Ne}」,系统提示词暂时用内置兜底。`,`error`)}})(),nr().then(e=>un(e)),Wt().then(e=>{fn(e),mn(!0)}),Ln().then(e=>gn(e)),Un().then(e=>vn(e)),Fn().then(e=>bn(e)),Mt().then(e=>{Sn(e),e?.workspace&&En(t=>({...t,[e.workspace]:!0}))})})(),()=>{e=!0,t(),r(),a()}},[]),(0,K.useEffect)(()=>{!V.memory&&W===`memory`&&Mn(`dialog`)},[V.memory,W]),(0,K.useEffect)(()=>{!V.todos&&W===`todos`&&Mn(`dialog`)},[V.todos,W]),(0,K.useEffect)(()=>{v(El,W)},[W]),(0,K.useEffect)(()=>{if(!V.reports){cn(``);return}let e=!0;return(async()=>{try{await vr(!0);let t=await yr();e&&cn(t),t||M(`工作汇报提示词没读到(提示词管理里为空或缺失),汇报不会注入提示词。`,`error`)}catch(e){let t=e instanceof Error?e.message:String(e);M(`读取工作汇报提示词失败:${t}`,`error`)}})(),()=>{e=!1}},[V.reports]),(0,K.useEffect)(()=>{if(!r)return;let e=!1,t=async()=>{if(!Y.current)return;let t=await xs();if(e||!Y.current)return;let n=Y.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:ys(e.text,e.id),time:Date.now(),scheduleId:e.id};n=ct(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 Ze();if(!e&&Y.current){if(i){let e=it(n,i);e!==n&&(n=e,n.activeId&&(r=!0))}if((n!==Y.current||t.length)&&X(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,K.useEffect)(()=>{if(!r||!q||!H)return;let e=a?.sessions.find(e=>e.id===a.activeId);uo(e)},[r,q,a?.activeId,H?.items]),(0,K.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,K.useEffect)(()=>{rr(0),or(!1)},[ja?.query,ja?.from]),(0,K.useEffect)(()=>{cr(!1),R(0)},[La?.from]),(0,K.useEffect)(()=>{R(e=>Ra.length?Math.min(e,Ra.length-1):0)},[Ra.length]),(0,K.useEffect)(()=>{if(!Ia||!ka){ka||Sr([]);return}let e=!1;return Kt(Zt,{maxDepth:3,maxEntries:80}).then(t=>{e||Sr(t)}),()=>{e=!0}},[Ia,ka,Zt,H?.workspace]),(0,K.useEffect)(()=>{if(!Ia)return;let e=Ca.current;e&&e.querySelector(`[data-mention-index="${tr}"]`)?.scrollIntoView({block:`nearest`})},[tr,Ia,Fa.length]),(0,K.useEffect)(()=>{if(!Ba)return;let e=wa.current;e&&e.querySelector(`[data-plugin-index="${ve}"]`)?.scrollIntoView({block:`nearest`})},[ve,Ba,Ra.length]),(0,K.useEffect)(()=>{if(!Ia&&!Ba&&!lr)return;function e(e){let t=e.target;Ca.current?.contains(t)||wa.current?.contains(t)||Ta.current?.contains(t)||xa.current?.contains(t)||e.target?.closest?.(`[data-add-menu-btn]`)||(or(!0),cr(!0),ur(!1))}return document.addEventListener(`pointerdown`,e,!0),()=>document.removeEventListener(`pointerdown`,e,!0)},[Ia,Ba,lr]),(0,K.useEffect)(()=>{if(!Ot||Yt!==`ok`)return;function e(e){let t=e.target;Ea.current?.contains(t)||B(null)}let t=window.setTimeout(()=>{document.addEventListener(`pointerdown`,e,!0)},0);return()=>{window.clearTimeout(t),document.removeEventListener(`pointerdown`,e,!0)}},[Ot,Yt]),(0,K.useEffect)(()=>{if(!jn&&!je)return;function e(e){let t=e.target;t?.closest?.(`[data-session-menu]`)||t?.closest?.(`[data-ws-menu]`)||(U(null),Me(null))}return document.addEventListener(`pointerdown`,e,!0),()=>document.removeEventListener(`pointerdown`,e,!0)},[jn,je]);function eo(){nr().then(e=>un(e)),Wt().then(e=>{fn(e),mn(!0)}),Ln().then(e=>gn(e)),Un().then(e=>vn(e)),Fn().then(e=>bn(e)),Mt().then(e=>Sn(e))}function to(e){Sn(e),En(t=>({...t,[e.workspace]:!0}))}async function io(e,t=`select`){if(q&&!Cn){wn(!0),B(null);try{to(t===`add`?await At(e):await qt(e))}catch(e){B(e instanceof Error?e.message:String(e))}finally{wn(!1)}}}function oo(e){let t=Ua.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 uo(e){if(!q||Cn)return;let t=oo(e);if(!t)return;let n=Ua.current;if(n&&t!==n.workspace){wn(!0);try{to(await qt(t))}catch{}finally{wn(!1)}}}async function fo(e){if(!q||Cn)return;await io(e.path,`select`);let t=Y.current;if(!t)return;let n=t.sessions.find(e=>e.id===t.activeId);n&&!n.workspacePath&&((n.messages??[]).length>0||(X(Ye(t,n.id,e.path)),En(t=>({...t,[e.path]:!0}))))}async function po(){if(q&&!Cn){wn(!0),B(null);try{let e=await Pt();if(!e)return;to(await At(e))}catch(e){B(e instanceof Error?e.message:String(e))}finally{wn(!1)}}}async function mo(){let e=Le;if(e&&q&&!Cn){if(e.id===`ws_project`)He(null);else{He(null),Me(null),wn(!0),B(null);try{Y.current&&X(ft(Y.current,e.path));let t=await Ht(e.id);to(t),t.projectRoot&&En(e=>({...e,[t.projectRoot]:!0}))}catch(e){B(e instanceof Error?e.message:String(e))}finally{wn(!1)}}}}function go(e){q&&!Cn&&e.id!==`ws_project`&&(U(null),Me(null),He(e))}async function wo(e){let t=Ue;if(st(null),t&&q){wn(!0),B(null);try{to(await zt(t,e))}catch(e){B(e instanceof Error?e.message:String(e))}finally{wn(!1)}}}function To(e){if(!e||!Y.current)return Y.current;let t=Y.current.sessions.find(t=>t.id===e);if(!t||!Qe(t))return Y.current;let n=Oa.current[e];return n&&(n.input?.trim()||(n.attachments?.length??0)>0||(n.images?.length??0)>0||(n.docRefs?.length??0)>0)?Y.current:(delete Oa.current[e],Ct(e),lt(Y.current,e))}function Oo(e){ja&&(e.collection!==`workspace`&&!wr?B(g(`knowledge`)):S.length>=Cl?B(`最多引用 ${Cl} 篇文档`):(B(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,Cl)),d(u.slice(0,ja.from).replace(/\s+$/,``)),or(!0),xa.current?.focus()))}function ko(){La&&(d(u.slice(0,La.from).replace(/\s+$/,``)),cr(!0))}function Ao(e){if(!V[e])return B(g(e)),!1;if(B(null),e===`caseGen`)return te(!0),!0;if(e===`promptGen`)return P(!0),!0;if(e===`knowledgeGen`)return ue(!0),!0;if(e===`pluginDev`)return cs(),!0;if(e===`memory`)return Mn(`memory`),!0;if(e===`knowledge`){let e=u.replace(/\s+$/,``);return d(e?`${e} @`:`@`),or(!1),requestAnimationFrame(()=>xa.current?.focus()),!0}return!1}function jo(e){ko(),Ao(e)}function Mo(){let e=ba.current;if(!e)return;let t=e.scrollHeight-e.clientHeight-e.scrollTop<=48;if(Ha.current){if(!t)return;Ha.current=!1}Va.current=t,en(!t)}function Po(){let e=ba.current;e&&(Va.current=!0,Ha.current=!0,en(!1),e.scrollTo({top:e.scrollHeight,behavior:`smooth`}))}(0,K.useEffect)(()=>{if(!r||!Y.current)return;let e=Y.current.sessions.find(e=>e.id===Y.current.activeId)?.messages??[],t=JSON.stringify(e)!==JSON.stringify(c),n=qe(Y.current,c,{touchUpdatedAt:t});Y.current=n,o(n),dt(n),Va.current&&!Ha.current&&ba.current?.scrollTo({top:ba.current.scrollHeight})},[c,r]),(0,K.useEffect)(()=>{let e=()=>{Y.current&&dt(Y.current)};return window.addEventListener(`pagehide`,e),()=>window.removeEventListener(`pagehide`,e)},[]),(0,K.useLayoutEffect)(()=>{let e=xa.current;e&&(e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,280)}px`)},[u]),(0,K.useEffect)(()=>{if(!r||!he||!c.length)return;let e=he,t=window.setTimeout(()=>{let t=(ba.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)),_e(null)},80);return()=>window.clearTimeout(t)},[r,he,c]);function Fo(e,t){vt(n=>{let r=n.includes(e);return t&&!r?[...n,e]:!t&&r?n.filter(t=>t!==e):n}),Y.current?.activeId===e&&(Zr.current=t,gt(t))}function Ro(e){e&&(Hr.current.get(e)?.abort.abort(),Wr.current.get(e)?.(),Wr.current.delete(e),Ar(e))}function Go(e,t){if(t.type===`reasoning`&&t.delta)Xo(e,n=>{let r=n[n.length-1];if(r?.role!==`assistant`)return n;let i=ge((r.reasoning??``)+t.delta),a=[...r.activitySteps??[]],o=a.findIndex(e=>e.kind===`thinking`),s={id:`thinking`,kind:`thinking`,title:`思考`,detail:zl(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)Xo(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:ge((r.content??``)+t.delta),activitySteps:i,turnStatus:`running`,ttftMs:s},a});else if(t.type===`tool`&&t.name){let n=Pl(t.name),r=Rl(t.name,t.args),i=`tool_${t.name}_${t.args?.slice(0,24)??``}`;Qo(e,i,t.status);let a=t.status===`done`&&typeof t.result==`string`&&/^\s*\{\s*"error"\s*:/.test(t.result);Xo(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:Il(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}),Y.current?.activeId===e&&G(Bl(Ve().toolStepDetail,n,t.name,t.status===`running`?`running`:`done`))}else if(t.type===`usage`&&t.usage)Xo(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`)&&(Xo(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&&Y.current?.activeId===e&&B(Fl(t.error)),Hr.current.delete(e),Ur.current===e&&(Ur.current=null),Fo(e,!1),Y.current?.activeId===e&&G(null))}}function Yo(e,t=0){Wr.current.get(e)?.(),Fo(e,!0),(async()=>{let n=await jr(e),r=t;if(n?.ok&&n.assistant&&(r=Math.max(r,n.seq??0),Xo(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`)){Fo(e,!1);return}let i=Pr(e,r,{onEvent:t=>Go(e,t),onGaveUp:t=>{Y.current?.activeId===e&&B(t.message||`与服务端回合断开`),Fo(e,!1)}});Wr.current.set(e,i)})()}function Xo(e,t,n){let r=Hr.current.get(e),i=Y.current?.sessions.find(t=>t.id===e)?.messages??[],a=r?.messages??(Y.current?.activeId===e?Ka.current:i),o=typeof t==`function`?t(a):t;r&&(r.messages=o),Y.current?.activeId===e&&(Ka.current=o,l(o)),Y.current&&X(We(Y.current,e,o,{touchUpdatedAt:n?.touchUpdatedAt!==!1}))}function Zo(e){let t=Ur.current??Y.current?.activeId;t&&Xo(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 Qo(e,t,n){let r=`${e}:${t}`;if(n===`running`){Gr.current.set(r,Date.now());return}if(n!==`done`&&n!==`error`)return;let i=Gr.current.get(r);if(Gr.current.delete(r),i==null)return;let a=Math.max(0,Date.now()-i);Xo(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 $o(e){if(!e.length)return;let t=[],n=[],r=jl(f,b);for(let i of e)if(r+t.length>=6)n.push(`${i.name||`图片`}(最多 6 个文件)`);else try{t.push(await Al(i))}catch(e){n.push(e instanceof Error?e.message:String(e))}t.length&&x(e=>[...e,...t].slice(0,6)),B(n.length?`以下图片未添加:${n.join(`、`)}`:null)}function es(e){let t=Ti;if(!t)return;let n={...t,body:e,at:Date.now()};wi(e=>{let t=e.map(e=>e.id===n.id?n:e);return yt(Y.current?.activeId,t),t}),Ei(null)}function ts(e){xt(Y.current?.activeId,e),wi(t=>t.filter(t=>t.id!==e)),Ei(t=>t?.id===e?null:t)}function rs(){d(``),m([]),x([]),C([]),wi([]),yt(Y.current?.activeId,[]),or(!1),cr(!1)}function is(){if(gi===`plan`&&(Ps(),hi(`off`)),gi===`pluginDev`){L(null),pe.current=null,Y.current&&X(z(Y.current,{pluginDev:void 0}));let e=me.current;me.current=null,e===`readonly`&&(Qt(`readonly`),Y.current&&X(z(Y.current,{access:`readonly`})))}yi(null)}function as(){yi(`goal`),requestAnimationFrame(()=>xa.current?.focus())}function ss(){hi(e=>e===`off`?`planning`:e),yi(`plan`),requestAnimationFrame(()=>xa.current?.focus())}function cs(){q?(yi(`pluginDev`),Zt===`readonly`&&(me.current=`readonly`,Qt(`readwrite`),Y.current&&X(z(Y.current,{access:`readwrite`}))),requestAnimationFrame(()=>xa.current?.focus())):B(`本地文件服务未就绪:插件开发需要读写项目源码`)}function ls(e){Si(e),yi(`reports`),window.setTimeout(()=>xa.current?.focus(),400)}function us(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 ds(e){if(!t)return ze(`model`),!1;let n=us(Ka.current);if(n.length<4)return B(`对话轮次较少,无需压缩`),!1;G(`正在压缩上下文…`);try{let{messages:r,compacted:i}=await Io(t,n,{force:e.force,signal:e.signal});if(!i)return G(null),B(`当前上下文未超过阈值,未压缩`),!1;let a=Date.now(),o=r.map((e,t)=>({role:e.role,content:e.content,reasoning:e.reasoning,time:a+t}));return Ka.current=o,l(o),Y.current&&X(qe(Y.current,o,{touchUpdatedAt:!0})),G(null),!0}catch(e){return G(null),e instanceof DOMException&&e.name===`AbortError`||B(e instanceof Error?e.message:String(e)),!1}}async function fs(e,n){let r=e===void 0,i=r&&gi===`reports`?`生成${br[bi]}`:``,a=r?St(Ci):``,o=(e??u).trim()||i,s=a?o?`${o}\n\n${a}`:a:o,c=r?f:[],l=r?S:[],d=r?b:[];if(!s&&!c.length&&!l.length&&!d.length)return;if(!t){ze(`model`);return}if(r&&gi===`reports`&&yi(null),Lo(s)&&!c.length&&!l.length&&!d.length){if(Zr.current){B(`请等待当前回复结束后再压缩`);return}r&&rs(),await ds({force:!0})&&B(null);return}if(gi===`goal`&&s&&!c.length&&!l.length&&!d.length&&!Wo(s)&&!Lo(s)){r&&rs();let e={text:s.slice(0,500),status:`active`,updatedAt:Date.now()};li.current=e,ci(e),ui.current=0,Y.current&&X(z(Y.current,{goal:e})),yi(null),B(`已设定目标:${e.text}`);return}if(Wo(s)&&!c.length&&!l.length&&!d.length){let e=Uo(s);if(r&&rs(),!e)return;if(e.kind===`show`){let e=ai;B(e&&e.status!==`cleared`?`当前目标(${e.status}):${e.text}`:`当前无会话目标。可用 /goal set <内容> 设定`);return}if(e.kind===`clear`){li.current=null,ci(null),ui.current=0,Y.current&&X(z(Y.current,{goal:void 0})),B(`已清除会话目标`);return}if(e.kind===`done`){if(!ai?.text){B(`当前无目标可标记完成`);return}let e={...ai,status:`done`,updatedAt:Date.now()};li.current=e,ci(e),ui.current=0,Y.current&&X(z(Y.current,{goal:e})),B(`已标记目标完成:${e.text}`);return}if(e.kind===`set`&&e.text){let t={text:e.text.slice(0,500),status:`active`,updatedAt:Date.now()};li.current=t,ci(t),ui.current=0,Y.current&&X(z(Y.current,{goal:t})),B(`已设定目标:${t.text}`);return}return}if(gi===`pluginDev`&&s&&!c.length&&!l.length&&!d.length){if(Zr.current){B(`请等待当前回复结束后再开始插件开发`);return}await Os(s)}let p={id:`q_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,6)}`,content:s,files:[...c],refs:[...l],imgs:[...d]};if(Zr.current){let e=Ve().busySendBehavior??`queue`;if((n?.forceBusy??e)===`queue`){va([...J.current,p]),r&&rs();return}_a.current=p,r&&rs(),Ro(Y.current?.activeId)}else await ps(p)}async function ps(n){let r=Y.current?.activeId;if(!t||!r||Hr.current.has(r))return;let{content:i,files:a,refs:o,imgs:s}=n;qo(i)||(ui.current=0),B(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=Ka.current,f=d[d.length-1];f?.role===`assistant`&&!f.content&&!f.reasoning&&(d=d.slice(0,-1));let p=[...d,u];if(No(us(p),t.model)){G(`上下文较长,正在压缩…`);try{let{messages:e,compacted:n}=await Io(t,us(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})),Ka.current=p,l(p),Y.current&&X(qe(Y.current,p,{touchUpdatedAt:!0}))}}catch{}G(null)}let m=[...p,{role:`assistant`,content:``,time:c,turnStatus:`running`}];Ka.current=m,l(m),rs();let h=new AbortController;Ur.current=r,Hr.current.set(r,{abort:h,messages:m}),Vr.current=h,Fo(r,!0),Va.current=!0,en(!1);let g=di(p.map(e=>{let t={role:e.role,content:Ol(e)},n=(e.reasoningApi??e.reasoning)?.trim();return e.role===`assistant`&&n&&(t.reasoning_content=n),t}),{keepRecentImageMessages:1}),_=Cr,v=wr,y=q,b=Er,x=!!V.todos,S=!!V.tasks,C=!!V.projects,T=!!V.iterations,E=!!V.pmRequirements,D=!!V.bugs,O=mi===`planning`,k=V.pluginDev&&pe.current?.active?pe.current:null,A=k?Zt===`full`?`full`:`readwrite`:O?`readonly`:Zt,ee=Nr&&A!==`readonly`,te=Lr&&A!==`readonly`,j=Ua.current?.workspace?.trim()||``,M=j?`\n当前工作区:${j}`:``,ie=V.promptGen&&ce.current?.active?ce.current:null,ae=!ie&&V.knowledgeGen&&fe.current?.active?fe.current:null,N=!ie&&!ae&&V.caseGen&&re.current?.active?re.current:null,P=!!(ie||ae||N),oe=j,le=w;if(k)le=na(k,Ua.current?.harnessRoot||Ua.current?.projectRoot||j);else if(ie)le=Mi(ie);else if(ae)le=Xi(ae);else if(N){if(!N.promptBody?.trim()){B(`生成测试用例已启用,但未选择提示词。请打开插件重新「确认」。`),Hr.current.delete(r),Ur.current=null,Vr.current=null,Fo(r,!1),l(e=>e[e.length-1]?.role===`assistant`&&!e[e.length-1]?.content?e.slice(0,-1):e);return}try{le=_i(N,N.docTitle||N.reqPath?.split(`/`).pop()?.replace(/\.[^.]+$/,``)||``)}catch(e){B(e instanceof Error?e.message:String(e)),Hr.current.delete(r),Ur.current=null,Vr.current=null,Fo(r,!1);return}}if(!P){let e=sn;if(!k&&!e.trim()&&V.reports)try{await vr(!0),e=await yr()}catch{}!k&&e.trim()&&(le=`${le}\n\n${e.trim()}`);let t=ho({lastUserMessageAt:[...p].reverse().find(e=>e.role===`user`&&e!==p[p.length-1])?.time??[...p].reverse().find(e=>e.role===`user`)?.time??null,lastInjectAt:Xr.current});if(t.injected&&(Xr.current=t.at),le=`${le}\n\n${t.text}`,y)try{let e=await Vt();e?.text&&(le=`${le}\n\n${Gt}\n\n${e.text}`)}catch{}}let ue=vl(le,g,{memory:_&&!P,knowledge:v&&!P,fs:y&&!P,web:b&&!P,bash:ee&&!P,pwsh:te&&!P,interact:!P,todos:x&&!P,tasks:S&&!P,projects:C&&!P,iterations:T&&!P,pmRequirements:E&&!P,bugs:D&&!P,planPhase:P||k?`off`:mi,goalEnabled:!P,goal:ai,scheduleEnabled:!P,subagentEnabled:!P,workflowEnabled:!P}).map((e,t)=>t===0&&e.role===`system`&&y&&M&&!P?{...e,content:`${typeof e.content==`string`?e.content:``}${M}`}:e);if(_&&!P&&!k){G(`记忆注入中…`);let{context:e}=await er(i,{cwd:oe});if(e&&ue[0]?.role===`system`){let t=typeof ue[0].content==`string`?ue[0].content:``;ue=[{...ue[0],content:`${t}\n\n${e}`},...ue.slice(1)]}G(null)}let F=[];P||(v&&F.push(...lc),y&&(F.push(...Rt(A)),F.push(...Lt),F.push(...aa),F.push(...ao),F.push(oi),O||(F.push(ni),F.push(Ut))),ee&&(F.push(Jn),F.push(...Xn)),te&&(F.push(Yn),F.push(...In)),(ee||te)&&F.push(...Hn),b&&F.push(...Bn),_&&F.push(...fr),F.push(_o),x&&F.push(...Na),S&&F.push(...Xa),C&&F.push(...pa),T&&F.push(...ma),E&&F.push(...ha),D&&F.push(...ga),F.push(vo),F.push(...zo),F.push(...os),F.push(...Ts),F.push(...$s),(mi===`planning`||mi===`approved`)&&F.push(Eo));let I=Date.now(),L=0;qr.current.set(r,{start:I});let me=0,he=!1,_e=``,ve=!1,R,be=!!(ie||ae||N);function xe(e){return ie?Ni(e):ae?Zi(e):vi(e)}function Se(){return ie?`正在编写提示词…`:ae?`正在编写知识库…`:`正在编写用例…`}let Ce=!1;try{let n=``,a=``,o=``;if(be){G(Se());let e=()=>{let e=Math.max(0,Math.floor((Date.now()-I)/1e3));Zo(t=>({...t,content:xe(e)}))};e(),R=window.setInterval(e,1e3)}if(!(x||S||C||T||E||D)&&!be&&!k&&await Dr(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 kr({sessionId:r,messages:ue,settings:{baseURL:t.baseURL,apiKey:t.apiKey,model:t.model,reasoningEffort:t.reasoningEffort},tools:e,thinking:!0,workspace:j||``,access:A})).ok&&(Ce=!0,await new Promise(e=>{let t=!1,n=()=>{t||(t=!0,e())},i=()=>{Ar(r)};h.signal.addEventListener(`abort`,i),Wr.current.get(r)?.();let a=Pr(r,0,{signal:h.signal,onEvent:e=>Go(r,e),onTerminal:e=>{ve=e.status===`completed`,h.signal.removeEventListener(`abort`,i),Wr.current.delete(r),n()},onGaveUp:e=>{Y.current?.activeId===r&&B(e.message||`与服务端回合断开`),Xo(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),Wr.current.delete(r),n()}});Wr.current.set(r,()=>{a(),n()})}))}if(!Ce){let s=ye(t,ue,h.signal,{tools:F.length?F:void 0,runTool:F.length?async(n,i)=>{Kn(!0);let a=Pl(n);G(Bl(Ve().toolStepDetail,a,n,`running`));let o=Date.now();try{if(n.startsWith(`kb_`))return await fc(n,i,{base:`/`,docs:e});if(n.startsWith(`fs_`)){let e=await It(n,i,A),t=co(n,e);if(t&&Y.current){let e=so(Y.current.sessions.find(e=>e.id===r)?.workspaceChanges,t);X(Ge(Y.current,r,{workspaceChanges:e}))}return e}if(n.startsWith(`skill_`))return await oa(n,i);if(n===`load_workspace_dependencies`)return await si(n);if(n===`office_to_pdf`)return O?JSON.stringify({error:`计划模式探查中:请先 submit_plan 并等待批准`}):await ri(n,i,A);if(n.startsWith(`workspace_changes_`)){let e=Y.current?.sessions.find(e=>e.id===r),{text:t,next:i}=lo(n,e?.workspaceChanges);return i&&Y.current&&X(Ge(Y.current,r,{workspaceChanges:i})),t}if(n.startsWith(`working_directory_`)){let{text:e,info:t}=await kt(n,i);return t&&(to(t),n===`working_directory_set`&&Y.current&&X(Ge(Y.current,r,{workspacePath:t.workspace}))),e}if(n===`present`){if(O)return JSON.stringify({error:`计划模式探查中:请先 submit_plan 并等待批准`});let e=await Ft(i,A);try{let t=JSON.parse(e);t.ok&&t.files?.length&&Zo(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(O)return JSON.stringify({error:`计划模式探查中:请先 submit_plan 并等待批准`});let e;try{e=JSON.parse(i||`{}`).items}catch{e=void 0}let t=ll(`todo`,e);if(!t.length)return JSON.stringify({error:`没有可记录的待办:只有用户明确要求记录待办时才调用 todo_add,并给出待办标题;不要为了弹出卡片而调用工具。`});let n=await Wa(t),r=await ca(`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 Ga(r)}catch(e){return JSON.stringify({error:`创建所属任务失败:${e instanceof Error?e.message:String(e)}`})}i=JSON.stringify({items:ul(`todo`,a)})}if(n===`task_add`){if(O)return JSON.stringify({error:`计划模式探查中:请先 submit_plan 并等待批准`});let e=ll(`task`,Za(i));e.length||e.push(cl(`task`));let t=await ca(`task`,e);if(!t)return JSON.stringify({ok:!1,cancelled:!0,message:`用户取消了新增任务,未写入任何数据。`});i=JSON.stringify({items:ul(`task`,t)})}if(n.startsWith(`task_`)){let e=await Qa(n,i,{sessionId:r});if(n===`task_add`)try{let t=JSON.parse(e);t.ok&&t.count&&B(`已创建 ${t.count} 个任务,可在侧栏「任务管理」查看。`,`ok`)}catch{}return e}if(n.startsWith(`todo_`)&&n!==`todo_write`){if(O&&n!==`todo_list`)return JSON.stringify({error:`计划模式探查中:请先 submit_plan 并等待批准`});let e=await za(n,i,{sessionId:r});if(n===`todo_add`)try{let t=JSON.parse(e);t.ok&&t.count&&B(`已记录 ${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=yo(e);return Y.current?.activeId===r&&ii(t),Y.current&&X(Ge(Y.current,r,{todos:t})),JSON.stringify({ok:!0,count:t.length,todos:t})}if(n.startsWith(`pm_`)){if(O&&!n.endsWith(`_list`))return JSON.stringify({error:`计划模式探查中:请先 submit_plan 并等待批准`});let e=await Aa(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_`)?`条缺陷`:`个项目`;B(`已创建 ${t.count} ${r},可在侧栏「${e}」查看。`,`ok`)}}catch{}return e}if(n.startsWith(`goal_`)){if(n===`goal_get`)return Vo(Y.current?.activeId===r?li.current:Bo(Y.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 Y.current?.activeId===r&&(li.current=t,ci(t),ui.current=0),Y.current&&X(Ge(Y.current,r,{goal:t})),Vo(t)}if(n===`goal_done`){let e=Y.current?.activeId===r?li.current:Bo(Y.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 Y.current?.activeId===r&&(li.current=t,ci(t),ui.current=0),Y.current&&X(Ge(Y.current,r,{goal:t})),Vo(t)}return n===`goal_clear`?(Y.current?.activeId===r&&(li.current=null,ci(null),ui.current=0),Y.current&&X(Ge(Y.current,r,{goal:void 0})),JSON.stringify({ok:!0,goal:null})):JSON.stringify({error:`unknown tool: ${n}`})}if(n.startsWith(`schedule_`))return await Ss(n,i,r);if(n===`list_agents`||n===`spawn_subagent`||n===`fork_subagent`||n.startsWith(`subagent_`))return await Ks(n,i,{settings:$r(t,Ve().subagentModel),parentSignal:h.signal,access:A,fsEnabled:y,webEnabled:b,parentMessages:g,onHint:e=>G(e),runFs:(e,t,n)=>It(e,t,n),runWeb:(e,t)=>Qn(e,t)});if(n===`workflow`)return await ac(n,i,{settings:t,parentSignal:h.signal,access:A,fsEnabled:y,webEnabled:b,parentMessages:g,onHint:e=>G(e),runFs:(e,t,n)=>It(e,t,n),runWeb:(e,t)=>Qn(e,t)});if(n===`ask_user_question`){let e=bo(i);if(!e.length)return JSON.stringify({error:`questions is required`});let t={};for(let n of e)t[n.id]={selected:[],text:``};return Fi(t),Ri(0),Bi(!1),Ui(null),Gi(!1),qi(``),ji(e),await new Promise((e,t)=>{Qr.current={resolve:e,reject:t};let n=Vr.current,r=()=>{n?.signal.removeEventListener(`abort`,r),Ns()};n?.signal.addEventListener(`abort`,r)})}if(n===`submit_plan`){let e=Do(i);return e?(ki(e),await new Promise((e,t)=>{ei.current={resolve:e,reject:t};let n=Vr.current,r=()=>{n?.signal.removeEventListener(`abort`,r),Ps()};n?.signal.addEventListener(`abort`,r)})):JSON.stringify({error:`title and steps are required`})}return n===`bash`?await Rn(i,A):n===`pwsh`?await Wn(i,A):n.startsWith(`bash_session_`)?await Zn(n,i,A):n.startsWith(`pwsh_session_`)?await qn(n,i,A):n.startsWith(`job_`)?await zn(n,i,A):n.startsWith(`web_`)?await Qn(n,i):n.startsWith(`memory_`)?await _r(n,i,oe):JSON.stringify({error:`unknown tool: ${n}`})}finally{let e=Math.max(0,Date.now()-o);Zo(t=>({...t,toolMs:(t.toolMs??0)+e})),Kn(!1),eo()}}:void 0});for await(let e of s){if(e.type===`tool`){let t=Pl(e.name);G(Bl(Ve().toolStepDetail,t,e.name,e.status===`running`?`running`:`done`));let n=Rl(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);Zo(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:Il(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=L?(n-L)/1e3:0,i=_u(e.usage),a=r>.2&&i>0?i/r:void 0;Zo(r=>({...r,usage:e.usage,tps:a,model:t.model,ttftMs:L?L-I:r.ttftMs,llmMs:n-I}));continue}if(L===0&&(L=Date.now(),Zo(e=>({...e,ttftMs:L-I,model:t.model}))),e.type===`reasoning_api`){Zo(t=>({...t,reasoningApi:e.content}));continue}e.type===`reasoning`&&me===0&&(me=Date.now());let r=e.type===`content`&&me>0&&!he;if(r&&(he=!0),be){e.type===`content`&&(ie?a+=e.delta:ae?o+=e.delta:n+=e.delta);let t=xe(Math.max(0,Math.floor((Date.now()-I)/1e3)));if(e.type===`reasoning`){_e+=e.delta;let n=ge(_e);Zo(e=>{let i={...e,reasoning:n,content:t};return r&&(i.reasoningDuration=Math.max(1,Math.round((Date.now()-me)/1e3))),i})}else r&&Zo(e=>({...e,content:t,reasoningDuration:Math.max(1,Math.round((Date.now()-me)/1e3))}))}else e.type===`reasoning`&&(_e+=e.delta),Zo(t=>{let n=e.type===`reasoning`?{...t,reasoning:ge(_e)}:{...t,content:ge(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:zl(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()-me)/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(ve=!0,!be){let e=[...Y.current?.sessions.find(e=>e.id===r)?.messages??[]].reverse().find(e=>e.role===`assistant`);e&&typeof e.content==`string`&&!e.content.trim()&&B(`模型本轮没有返回正文(可能工具轮次用尽或输出被截断),请重试或回复「继续」`)}{let e=me>0&&!he?Math.max(1,Math.round((Date.now()-me)/1e3)):null;Zo(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(R!=null&&(window.clearInterval(R),R=void 0),ie){G(`正在质检并入库…`);let e=await Ii(a,ie);if(Zo(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&&Y.current){let t={...ie,linkedPromptPath:e.path};se(t),ce.current=t,X(z(Y.current,{promptGen:t}))}}else if(ae){G(`正在质检并入库…`);let e=await ea(o,ae);if(Zo(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&&Y.current){let t={...ae,linkedKnowledgePath:e.path};de(t),fe.current=t,X(z(Y.current,{knowledgeGen:t}))}}else if(N){G(`正在检测覆盖并入库…`);let e=N.reqPath?.split(`/`).pop()?.replace(/\.[^.]+$/,``)||i.slice(0,24),t=await xi(n,N,e);if(Zo(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&&Y.current){let e={...N,linkedCasePath:t.path};ne(e),re.current=e,X(z(Y.current,{caseGen:e}))}}}Ce&&ve&&Zo(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`||Y.current?.activeId===r&&B(e instanceof Error?e.message:String(e)),Xo(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{R!=null&&(window.clearInterval(R),R=void 0);let e=Date.now(),n=qr.current.get(r),a=L||n?.firstToken||0;Zo(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=_u(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:ve?`completed`:(h.signal.aborted||!Ce)&&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),Wr.current.get(r)?.(),Wr.current.delete(r),Ur.current===r&&(Ur.current=null),Vr.current===h&&(Vr.current=null),Fo(r,!1);{let e=Ve().toolStepDetail;e===`full`?window.setTimeout(()=>G(null),2800):e===`detailed`?window.setTimeout(()=>G(null),1200):G(null)}if(ve&&_&&ar(i,oe).finally(()=>{eo()}),ve&&Y.current){let e=[...Y.current.sessions.find(e=>e.id===r)?.messages??[]].reverse().find(e=>e.role===`assistant`),n=Jr({userContent:i,assistantContent:typeof e?.content==`string`?e.content:``,reasoning:e?.reasoning});n.length&&Yr({sessionId:r,model:e?.model??t.model,messages:n})}if(ve&&t&&!h.signal.aborted&&Y.current){let e=Y.current.sessions.find(e=>e.id===r),n=e?.messages??[];if(e&&!fi.current.has(r)&&Ir(e.title,n)){let e=Fr(n);e&&(fi.current.add(r),Rr(t,e).then(e=>{if(!e||!Y.current)return;let t=Y.current.sessions.find(e=>e.id===r);t&&Ir(t.title,t.messages)&&X(et(Y.current,r,e))}))}}let o=Y.current?.activeId===r,s=null;if(o){s=_a.current,_a.current=null,!s&&J.current.length&&(s=J.current[0],va(J.current.slice(1)));let e=Ho(li.current);if(!s&&!P&&Jo({goalActive:!!e,turnOk:ve,aborted:h.signal.aborted,hasFollowUp:!1,askUserPending:!!Qr.current,roundsUsed:ui.current,maxRounds:3})){let t=ui.current+1;ui.current=t,s={id:`goal_drv_${Date.now().toString(36)}`,content:Ko(e,t,3),files:[],refs:[],imgs:[]}}}s&&window.setTimeout(()=>{ps(s)},0)}}function ms(){_a.current=null,va([]),ui.current=0;let e=Y.current?.activeId;e&&Xo(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}),Ro(e)}function hs(e){va(J.current.filter(t=>t.id!==e))}function gs(e){let t=J.current.find(t=>t.id===e);t&&(hs(e),d(t.content),m(t.files),x(t.imgs),C(t.refs),requestAnimationFrame(()=>xa.current?.focus()))}function _s(e){let t=J.current.find(t=>t.id===e);t&&(va(J.current.filter(t=>t.id!==e)),Zr.current?(_a.current=t,Ro(Y.current?.activeId)):ps(t))}function vs(e){let t=[...J.current],n=e??t.shift()??null;n&&(va(t),Zr.current?(_a.current=n,Ro(Y.current?.activeId)):ps(n))}function bs(e,t){let n=!(c[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 Cs(e){e&&(u.trim()||f.length>0||b.length>0||S.length>0?Oa.current[e]={input:u,attachments:f,images:b,docRefs:S}:delete Oa.current[e],bt(e,u))}function ws(e){let t=e?Oa.current[e]:void 0;d(t?.input??Tt(e)),m(t?.attachments??[]),x(t?.images??[]),C(t?.docRefs??[]),wi(wt(e))}function Es(e){e?.abortRun!==!1&&Ro(Y.current?.activeId),Zr.current=!1,gt(!1),m([]),x([]),C([]),wi([]),Ei(null),d(``),B(null),en(!1),Va.current=!0,e?.clearDraft&&Y.current?.activeId&&(delete Oa.current[Y.current.activeId],Ct(Y.current.activeId))}function Ds(e,t){if(!Y.current)return;Mn(`dialog`);let n=Y.current.activeId,r=Y.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)Es({clearDraft:!0,abortRun:!1}),o={...Y.current,activeId:n,sessions:Y.current.sessions.map(e=>e.id===n?a(e):e)};else{Cs(n),Es({clearDraft:!0,abortRun:!1});let e=To(n)??Y.current,t=H?.workspace?.trim()||void 0;o=ot(e,{workspacePath:t,access:Re()});let r=o.activeId;o={...o,sessions:o.sessions.map(e=>e.id===r?a(e):e)}}X(o),l([]),ne(e===`caseGen`?t:null),re.current=e===`caseGen`?t:null,se(e===`promptGen`?t:null),ce.current=e===`promptGen`?t:null,de(e===`knowledgeGen`?t:null),fe.current=e===`knowledgeGen`?t:null;let s=o.sessions.find(e=>e.id===o.activeId)?.workspacePath||H?.workspace?.trim()||H?.projectRoot;s&&En(e=>({...e,[s]:!0})),uo(o.sessions.find(e=>e.id===o.activeId))}async function Os(e){let t=Y.current;if(!t)return;let n=t.sessions.find(e=>e.id===t.activeId),r=Ua.current?.harnessRoot?.trim()||Ua.current?.projectRoot?.trim()||Ua.current?.workspace?.trim(),i=n?.pluginDev?.active?n.pluginDev:{active:!0,requirement:e.trim(),confirmedAt:Date.now()};if(X(z(t,{pluginDev:i,access:Zt===`full`?`full`:`readwrite`,...r?{workspacePath:r}:{}})),L(i),pe.current=i,me.current=null,Ps(),hi(`off`),r&&En(e=>({...e,[r]:!0})),q&&r&&Ua.current?.workspace!==r)try{to(await qt(r))}catch{}}function ks(e){e?.active?Ds(`caseGen`,e):(ne(null),re.current=null,Y.current&&X(z(Y.current,{caseGen:void 0})))}function As(e){e?.active?Ds(`promptGen`,e):(se(null),ce.current=null,Y.current&&X(z(Y.current,{promptGen:void 0})))}function js(e){e?.active?Ds(`knowledgeGen`,e):(de(null),fe.current=null,Y.current&&X(z(Y.current,{knowledgeGen:void 0})))}function Ms(e){if(xe(!1),!Y.current)return;Mn(`dialog`);let t=Y.current.activeId;Cs(t),Es({clearDraft:!0,abortRun:!1});let n=To(t)??Y.current,r=e?.trim()||H?.workspace?.trim()||void 0,i=ot(n,{workspacePath:r,access:Re()});X(i),l([]),ne(null),se(null),de(null),L(null),pe.current=null,ii([]),li.current=null,ci(null),ui.current=0,hi(`off`),yi(e=>e===`pluginDev`?null:e),Ns(),Ps();let a=r||H?.projectRoot;a&&En(e=>({...e,[a]:!0})),uo(i.sessions.find(e=>e.id===i.activeId))}function Ns(){let e=Qr.current;e&&(Qr.current=null,ji(null),Fi({}),Ri(0),Bi(!1),Ui(null),Gi(!1),qi(``),e.resolve(JSON.stringify({canceled:!0,error:`user aborted`})))}function Ps(){let e=ei.current;e&&(ei.current=null,ki(null),e.resolve(JSON.stringify({approved:!1,canceled:!0})))}function Fs(){let e=ei.current;e&&(ei.current=null,ki(null),hi(`approved`),e.resolve(JSON.stringify({approved:!0,message:`用户已批准计划,可以开始实施`})))}function Is(){let e=ei.current;e&&(ei.current=null,ki(null),hi(`planning`),e.resolve(JSON.stringify({approved:!1,message:`用户驳回了计划,请修订后再次 submit_plan`})))}function Ls(){hi(e=>e===`off`?(yi(`plan`),`planning`):(Ps(),yi(e=>e===`plan`?null:e),`off`))}function Rs(e,t){return!e||!t?!1:t.skipped||t.text.trim()!==``?!0:e.options?.length?t.selected.length>0:!1}function zs(e,t,n){let r=Qr.current;if(!r)return;Qr.current=null,ji(null),Fi({}),Ri(0),Bi(!1),Ui(null),Gi(!1),qi(``),B(null);let i=t.filter(e=>e.skipped).length,a=String(n?.skipReason??``).trim();r.resolve(JSON.stringify({answers:t,summary:Co(e,t),...i?{skipped:!0,approvalRequired:!0,...a?{skipReason:a}:{},note:`用户跳过了部分或全部问题:跳过的题不算确认,也未批准实施。`+(a?`用户给出的跳过原因:${a}。`:``)+`本轮只允许只读调研与文字方案,禁止 fs_write / fs_mkdir / 改配置;请先说明采用的默认假设(哪几项按推荐)与准备改动的范围`+(a?`,并针对上述原因给出调整`:``)+`,然后等用户明确回复「开始实施」再动手。`}:{note:`answers 为结构化答案;summary 是同一批答案的中文文本版本,可直接据此继续,无需再次提问。`},...n}))}function Bs(e,t,n){Fi(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}}}),Ui(null),e.multi_select||Ri(e=>Math.min(e+1,(Ai?.length??1)-1))}function Vs(e){let t=Ai?.length??0;t&&(Ri(Math.max(0,Math.min(e,t-1))),Ui(null))}function Hs(e,t){e&&(Fi(n=>{let r=n[e.id]??{selected:[],text:``};return{...n,[e.id]:{selected:e.multi_select?r.selected:[],text:t,skipped:!1}}}),Ui(null))}function Us(e,t){let n=t.trim(),r=n&&e.options?.length?xo(e,n):null,i=r?{selected:r,text:``,skipped:!1}:{selected:e.multi_select?Pi[e.id]?.selected??[]:[],text:n,skipped:!1},a={...Pi,[e.id]:i};Fi(a),Ui(null),al?Gs(a):Vs(rl+1)}function Ws(e){return(Ai??[]).map(t=>{let n=So(t,e[t.id]??{selected:[],text:``});return n.skipped||n.text?.trim()||n.selected?.length?n:{id:t.id,selected:[],skipped:!0}})}function Gs(e=Pi,t=!1){let n=Ai;if(!n?.length||!Qr.current)return!1;let r=Ws(e),i=r.findIndex(e=>!e.skipped&&!e.text?.trim()&&!e.selected?.length);if(i>=0)return Vs(i),Ui(n[i]?.options?.length?`请先选择选项再提交`:`请先填写回答再提交`),!1;if(!t&&r.some(e=>e.skipped))return Gi(!0),Ui(null),!1;let a=Ki.trim();return zs(n,r,a?{skipReason:a}:void 0),!0}function qs(){let e=Ai,t=Q;if(!e?.length||!t)return;let n={...Pi,[t.id]:{selected:[],text:``,skipped:!0}};Fi(n),Ui(null),al?Gs(n):Vs(rl+1)}function Js(){Gs(Pi,!0)}function Ys(){Gi(!1);let e=Ws(Pi).findIndex(e=>e.skipped);Vs(e>=0?e:0)}function Xs(e){if(xe(!1),!Y.current||(Mn(`dialog`),U(null),e===Y.current.activeId))return;let t=Y.current.activeId;Cs(t),Ns(),Ps(),hi(`off`),B(null),en(!1),Va.current=!0;let n=To(t)??Y.current;n.sessions.some(t=>t.id===e)||(n=Y.current);let r=Ke(n,e),i=r.sessions.find(t=>t.id===e),a=Hr.current.get(e)?.messages??i?.messages??[];Ka.current=a,l(a);let o=Hr.current.has(e)||_t.includes(e);Zr.current=o,gt(o),Vr.current=Hr.current.get(e)?.abort??null,o&&!Wr.current.has(e)&&Yo(e,0),ne(i?.caseGen?.active?i.caseGen:null),se(i?.promptGen?.active?i.promptGen:null),de(i?.knowledgeGen?.active?i.knowledgeGen:null),L(i?.pluginDev?.active?i.pluginDev:null),yi(e=>i?.pluginDev?.active?`pluginDev`:e===`pluginDev`?null:e),ii(yo(i?.todos));{let e=Bo(i?.goal);li.current=e,ci(e),ui.current=0}ws(e),X(r),uo(i)}function Zs(e){if(!Y.current)return;U(null),Me(null);let t=Y.current.activeId===e;t&&Es({clearDraft:!0}),delete Oa.current[e],Ct(e),yt(e,[]);let n=lt(Y.current,e);if(X(n),t){let e=n.sessions.find(e=>e.id===n.activeId);l(e?.messages??[]),ne(e?.caseGen?.active?e.caseGen:null),se(e?.promptGen?.active?e.promptGen:null),de(e?.knowledgeGen?.active?e.knowledgeGen:null),L(e?.pluginDev?.active?e.pluginDev:null),yi(t=>e?.pluginDev?.active?`pluginDev`:t===`pluginDev`?null:t)}}function Qs(e,t){if(!Y.current)return;U(null);let n=Y.current.activeId===e&&t;n&&Es();let r=nt(Y.current,e,t);if(X(r),n){let e=r.sessions.find(e=>e.id===r.activeId);l(e?.messages??[])}}function ec(e){if(!Y.current)return;let t=Y.current.sessions.find(t=>t.id===e);t&&(U(null),X(tt(Y.current,e,!t.pinned)))}function tc(e){Y.current&&Y.current.sessions.some(t=>t.id===e)&&(U(null),Me(null),Ee(e))}function nc(){let e=Y.current?.activeId,t=Y.current?.sessions.find(t=>t.id===e);t?B(Kr(`stats`,t.id,t.updatedAt,()=>Br(zr(t))),`ok`):B(`无活跃会话可统计`)}function rc(e){Y.current&&Se&&(fi.current.add(Se),X(et(Y.current,Se,e)),Ee(null))}function ic(){nn(e=>(Je(!e),!e))}async function cc(e){let t=Array.from(e.target.files??[]);e.target.value=``,await pc(t)}function uc(){let t=e.map(e=>({collection:e.collection,path:e.path,title:e.title,category:e.category,format:String(e.format)})),n=xr.map(e=>({collection:`workspace`,path:e.path,title:e.name,category:Jt(H?.workspace,H?.projectRoot),format:e.type===`dir`?`dir`:`file`}));return[...t,...n]}function dc(e){e.length&&C(t=>{let n=[...t];for(let t of e){if(n.length>=Cl)break;n.some(e=>e.collection===t.collection&&e.path===t.path)||n.push(t)}return n})}async function pc(e,t){let n=[],r=[],i=[],a=jl(f,b);for(let o of e)if(a>=6)i.push(`${o.name}(最多 6 个文件)`);else try{let e=await Sc(o);e.kind===`image`?r.push(await Al(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&&m(e=>[...e,...n]),r.length&&x(e=>[...e,...r]),B(i.length?`以下文件未添加:${i.join(`、`)}`:null),xa.current?.focus()}function mc(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=jc(t),o=(t.getData(`text/plain`)||``).trim(),s=uc(),c=Jt(H?.workspace,H?.projectRoot),l={projectRoot:H?.projectRoot,workspace:H?.workspace,workspaceLabel:c},u=[],d=new Map;for(let e of a){let t=Pc(e,l);t?(u.push(t),d.set(Tc(e),t.path)):d.set(Tc(e),e)}let f=null;!r.length&&!i.length&&!a.length&&kc(o)&&(f=Fc(o,s));let p=[],m=[];for(let e of i){let t=d.get(e.name),n=(t?Pc(t,l):null)||Fc(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(),B(null),dc([...u,...p,...f?[f]:[]]),r.length&&$o(r),m.length&&pc(m,d),xa.current?.focus())}function hc(e){let t=e.target.closest(`[data-copy-code]`);t&&xu(t.closest(`.code-block`)?.querySelector(`pre`)?.textContent??``).then(e=>{e&&(t.textContent=`已复制`,window.setTimeout(()=>{t.textContent=`复制`},1e3))})}let gc=c.length===0,_c=!!(u.trim()||f.length||S.length||b.length||Ci.length||gi===`reports`),yc=-1,bc=-1;c.forEach((e,t)=>{e.role===`user`?yc=t:e.role===`assistant`&&(bc=t)});let xc=e=>e===yc||e===bc?``:`opacity-0 group-hover:opacity-100 group-focus-within:opacity-100 transition-opacity`,Cc=Nl.find(e=>e.value===Zt)??Nl[0],wc=gi===`pluginDev`,Ec=(a?.sessions??[]).filter(e=>!e.archived&&!e.deleted),Dc=(a?.sessions??[]).filter(e=>e.archived&&!e.deleted),Oc=H?.items??[],Ac=new Set(Oc.map(e=>e.path)),Mc=H?.workspace??``,Nc=H?.projectRoot??``,Ic=a?.sessions.find(e=>e.id===a.activeId),Lc=Ic?.workspacePath,Rc=!Lc||!Ac.has(Lc),zc=H?.workspace?.trim()||``,Bc=Oc.find(e=>e.path===zc),Vc=Bc?jt(Bc,Nc):zc?Jt(zc,Nc):`工作区`,Hc=Dn.trim().toLowerCase(),qc=(0,K.useMemo)(()=>Hc?new Set(no(a,Dn,{limit:50,includeArchived:!0}).map(e=>e.sessionId)):null,[Hc,a,Dn]),[Jc,Yc]=(0,K.useState)(null);(0,K.useEffect)(()=>{if(!Hc){Yc(null);return}let e=!1;return Yc(null),ro(Dn,{limit:50,includeArchived:!0}).then(t=>{!e&&t?.hits&&Yc(new Set(t.hits.map(e=>e.sessionId)))}),()=>{e=!0}},[Hc,Dn]);let Xc=Jc??qc,Qc=Xc?Dc.filter(e=>Xc.has(e.id)):Dc;function $c(e){let t=e.id===`ws_project`||e.path===Nc;return pt(Ec.filter(n=>!(n.workspacePath!==e.path&&(!t||n.workspacePath&&Ac.has(n.workspacePath)))).filter(e=>!Xc||Xc.has(e.id)))}let el=Oc.filter(e=>!Hc||e.name.toLowerCase().includes(Hc)||e.path.toLowerCase().includes(Hc)?!0:$c(e).length>0);function tl({s:e,nested:t=!1}){let n=e.id===a?.activeId,r=jn===e.id,i=_t.includes(e.id);return(0,Z.jsx)(cu,{s:e,nested:t,active:n,menuOpen:r,busy:i,onOpen:()=>Xs(e.id),onRename:()=>tc(e.id),onToggleMenu:()=>{Me(null),U(r?null:e.id)},onTogglePin:()=>ec(e.id),onToggleArchive:()=>Qs(e.id,!e.archived),onExport:()=>{U(null);let t=ns(e,`json`);B(t.ok?`已导出 ${t.filename}`:t.error)},onRemove:()=>{U(null),Me(null),Ae(e.id)}})}let nl=Ai?.length??0,rl=Math.max(0,Math.min(Li,nl-1)),Q=Ai?.[rl],il=Q&&Pi[Q.id]||{selected:[],text:``},al=rl>=nl-1,sl=Rs(Q,il),dl=(Ai??[]).map((e,t)=>({q:e,index:t})).filter(({q:e})=>Pi[e.id]?.skipped);return(0,Z.jsxs)(`div`,{className:`tw-app h-full min-h-0 flex overflow-hidden bg-(--tw-surface-page)`,children:[(0,Z.jsxs)(`aside`,{className:`tw-session-rail shrink-0 border-r border-(--tw-border) flex flex-col transition-[width] ${tn?`w-64`:`w-10`}`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1 ${tn?`px-2.5 pt-2.5`:`px-1 pt-2 justify-center`}`,children:[tn&&(0,Z.jsx)(`div`,{className:`flex-1 min-w-0 text-[13px] font-medium text-stone-700 truncate px-1`,children:Et(`chat.workbench`,void 0,Pn.language)}),(0,Z.jsx)(`button`,{type:`button`,"aria-label":tn?`收起侧栏`:`展开侧栏`,onClick:ic,className:`w-8 h-8 shrink-0 flex items-center justify-center rounded-lg text-stone-500 hover:bg-stone-200/70`,children:(0,Z.jsx)($,{className:`w-4 h-4`,children:tn?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`}),(0,Z.jsx)(`path`,{d:`M9 3v18`})]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`}),(0,Z.jsx)(`path`,{d:`M15 3v18`})]})})})]}),tn?(0,Z.jsxs)(`div`,{className:`px-2.5 pt-2 space-y-1.5`,children:[(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>Ms(),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,Z.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Z.jsx)(`path`,{d:`M5 12h14`}),(0,Z.jsx)(`path`,{d:`M12 5v14`})]}),Et(`chat.newSession`,void 0,Pn.language)]}),(0,Z.jsxs)(`button`,{type:`button`,"data-hint":`我的插件`,onClick:()=>xe(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 ${be?`is-active`:``}`,children:[(0,Z.jsx)(ru,{className:`w-3.5 h-3.5`}),`插件`]})]}):(0,Z.jsxs)(`div`,{className:`px-1 pt-1 flex flex-col gap-1`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:()=>Ms(),"data-hint":`新会话`,className:`w-8 h-8 flex items-center justify-center rounded-lg text-[#4176e6] hover:bg-white/80`,children:(0,Z.jsxs)($,{className:`w-4 h-4`,children:[(0,Z.jsx)(`path`,{d:`M5 12h14`}),(0,Z.jsx)(`path`,{d:`M12 5v14`})]})}),(0,Z.jsx)(`button`,{type:`button`,"data-hint":`我的插件`,onClick:()=>xe(e=>!e),className:`tw-rail-plugin-btn tw-rail-plugin-btn--icon w-8 h-8 flex items-center justify-center rounded-lg ${be?`is-active`:``}`,children:(0,Z.jsx)(ru,{className:`w-4 h-4`})})]}),tn&&(0,Z.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-2 py-3`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1 px-1.5 pb-2`,children:[(0,Z.jsx)(`div`,{className:`flex-1 text-[12px] font-semibold text-stone-500`,children:Et(`chat.workspace`,void 0,Pn.language)}),(0,Z.jsx)(`button`,{type:`button`,"aria-label":`搜索`,onClick:()=>{An(e=>!e),kn&&On(``)},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,Z.jsx)(Ql,{className:`w-3.5 h-3.5`})}),(0,Z.jsx)(`button`,{type:`button`,"data-hint":q?`添加工作区(选择本地文件夹)`:`本地文件服务未就绪`,disabled:!q||Cn,onClick:()=>void po(),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,Z.jsx)($l,{className:`w-3.5 h-3.5`})})]}),kn&&(0,Z.jsx)(`input`,{value:Dn,onChange:e=>On(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`}),Mr&&(0,Z.jsx)(`div`,{className:`px-1.5 py-2 text-[11px] text-amber-700/80`,children:`本地文件服务未就绪,工作区暂不可用`}),(0,Z.jsxs)(`div`,{className:`space-y-0.5`,children:[el.map(e=>{let t=$c(e),n=!!(Tn[e.path]??t.length>0),r=e.id===`ws_project`||e.path===Nc,i=!!(Ic&&(Rc?r:Lc===e.path)),a=je===e.id;return(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`tw-project-row group relative ${i?`is-active`:``} ${n?`is-expanded`:``} ${a?`is-menu-open`:``}`,children:[(0,Z.jsxs)(`button`,{type:`button`,"data-hint":e.path,onClick:t=>{t.stopPropagation(),U(null),Me(null),En(t=>({...t,[e.path]:!n})),q&&e.path!==Mc&&io(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,Z.jsx)(`span`,{className:`tw-slot tw-folder`,children:(0,Z.jsx)(Xl,{open:n,className:`w-3.5 h-3.5`})}),(0,Z.jsx)(`span`,{className:`tw-slot tw-chevron`,children:(0,Z.jsx)(Zl,{open:n,className:`w-3 h-3`})}),(0,Z.jsx)(`span`,{className:`tw-project-title`,children:jt(e,Nc)})]}),(0,Z.jsxs)(`div`,{className:`tw-ws-actions relative shrink-0`,"data-ws-menu":``,children:[(0,Z.jsx)(ou,{open:a,onToggle:()=>{U(null),Me(a?null:e.id)},onRename:()=>{U(null),Me(null),st(e.id)},onDelete:e.id===`ws_project`?void 0:()=>go(e)}),(0,Z.jsx)(`button`,{type:`button`,"data-hint":`在此工作区新建会话`,onClick:t=>{t.stopPropagation(),Ms(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,Z.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Z.jsx)(`path`,{d:`M5 12h14`}),(0,Z.jsx)(`path`,{d:`M12 5v14`})]})})]})]}),(0,Z.jsx)(`div`,{className:`tw-collapse ${n?`is-open`:``}`,children:(0,Z.jsx)(`div`,{className:`tw-collapse-inner space-y-0.5 pb-0.5`,children:t.map(e=>(0,Z.jsx)(tl,{s:e,nested:!0},e.id))})})]},e.id)}),!el.length&&q&&(0,Z.jsx)(`div`,{className:`px-2 py-3 text-xs text-stone-400`,children:`暂无工作区`})]}),Qc.length>0&&(0,Z.jsxs)(`div`,{className:`mt-3 pt-2 border-t border-stone-200/60`,children:[(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>an(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,Z.jsx)(Vl,{className:`w-3 h-3 transition-transform ${rn?`rotate-180`:``}`}),`已归档 (`,Qc.length,`)`]}),(0,Z.jsx)(`div`,{className:`tw-collapse ${rn?`is-open`:``}`,children:(0,Z.jsx)(`div`,{className:`tw-collapse-inner space-y-0.5`,children:Qc.map(e=>(0,Z.jsx)(tl,{s:e},e.id))})})]})]}),tn&&(Mc||Gn||$n)&&(0,Z.jsxs)(`div`,{className:`shrink-0 border-t border-stone-200/60 px-3 py-2 space-y-1`,children:[Mc&&(0,Z.jsxs)(`div`,{className:`tw-rail-workspace-footer`,"data-hint":Mc,children:[(0,Z.jsx)(`span`,{className:`tw-rail-workspace-label`,"data-i18n":`chat.workspace`,children:`工作区`}),(0,Z.jsx)(`span`,{className:`tw-rail-workspace-name`,children:Jt(Mc,Nc)})]}),(Gn||$n)&&(0,Z.jsx)(`div`,{className:`text-[11px] text-(--tw-accent)`,children:$n??Et(`tool.running`,void 0,Pn.language)})]})]}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex flex-col flex-1 ${be?`hidden`:``}`,children:[gc?null:(0,Z.jsxs)(`div`,{className:`shrink-0 border-b border-(--tw-border) bg-(--tw-surface-page)`,children:[(0,Z.jsx)(`div`,{className:`flex items-center gap-3 px-6 pt-4 pb-2 min-w-0`,children:(0,Z.jsx)(`button`,{type:`button`,"data-hint":`点击重命名`,onClick:()=>{let e=a?.activeId;e&&tc(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,Z.jsxs)(`div`,{className:`flex items-center gap-6 px-6`,children:[(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>Mn(`dialog`),className:`relative h-10 text-sm transition-colors ${W===`dialog`?`text-[#4176e6] font-medium`:`text-stone-500 hover:text-stone-700`}`,children:[`对话`,W===`dialog`&&(0,Z.jsx)(`span`,{className:`absolute left-0 right-0 -bottom-px h-0.5 bg-[#4176e6] rounded-full`})]}),(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>Mn(`thread`),className:`relative h-10 text-sm transition-colors ${W===`thread`?`text-[#4176e6] font-medium`:`text-stone-500 hover:text-stone-700`}`,children:[`回合`,W===`thread`&&(0,Z.jsx)(`span`,{className:`absolute left-0 right-0 -bottom-px h-0.5 bg-[#4176e6] rounded-full`})]}),V.memory&&(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>Mn(`memory`),className:`relative h-10 text-sm transition-colors ${W===`memory`?`text-[#4176e6] font-medium`:`text-stone-500 hover:text-stone-700`}`,children:[(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[`记忆`,(ln?.suggestionCount??0)>0?(0,Z.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":`${ln?.suggestionCount} 条待确认`,children:ln.suggestionCount>99?`99+`:ln.suggestionCount}):null]}),W===`memory`&&(0,Z.jsx)(`span`,{className:`absolute left-0 right-0 -bottom-px h-0.5 bg-[#4176e6] rounded-full`})]}),V.todos&&(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>Mn(`todos`),className:`relative h-10 text-sm transition-colors ${W===`todos`?`text-[#4176e6] font-medium`:`text-stone-500 hover:text-stone-700`}`,children:[`待办`,W===`todos`&&(0,Z.jsx)(`span`,{className:`absolute left-0 right-0 -bottom-px h-0.5 bg-[#4176e6] rounded-full`})]})]}),ai&&ai.status!==`cleared`&&W===`dialog`?(0,Z.jsx)(`div`,{className:`px-6 pb-2`,children:(0,Z.jsxs)(`div`,{className:`rounded-xl border border-[#4176e6]/25 bg-[#f5f8ff] px-3 py-2 flex items-start gap-2`,children:[(0,Z.jsxs)(`span`,{className:`text-[11px] font-medium text-[#4176e6] shrink-0 pt-0.5`,children:[`目标`,ai.status===`done`?`·完成`:``]}),(0,Z.jsx)(`span`,{className:`flex-1 min-w-0 text-[12px] leading-5 ${ai.status===`done`?`text-stone-400 line-through`:`text-stone-800`}`,children:ai.text}),(0,Z.jsx)(`button`,{type:`button`,"data-hint":`清除目标`,className:`text-[11px] text-stone-400 hover:text-stone-600 shrink-0`,onClick:()=>{li.current=null,ci(null),ui.current=0,Y.current&&X(z(Y.current,{goal:void 0}))},children:`清除`})]})}):null,ti.length>0&&W===`dialog`?(0,Z.jsx)(`div`,{className:`px-6 pb-3`,children:(0,Z.jsxs)(`div`,{className:`rounded-xl border border-stone-200 bg-white px-3 py-2.5`,children:[(0,Z.jsxs)(`div`,{className:`text-[11px] font-medium text-stone-500 mb-1.5`,children:[`待办 · `,ti.filter(e=>e.status===`completed`).length,`/`,ti.length]}),(0,Z.jsx)(`ul`,{className:`space-y-1 max-h-28 overflow-y-auto`,children:ti.map((e,t)=>(0,Z.jsxs)(`li`,{className:`flex items-start gap-2 text-[12px] text-stone-700`,children:[(0,Z.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,Z.jsx)(`span`,{className:e.status===`completed`?`line-through text-stone-400`:``,children:e.content})]},`${t}-${e.content}`))})]})}):null]}),W===`todos`&&V.todos?(0,Z.jsx)(`div`,{className:`flex-1 min-h-0 bg-(--tw-surface-page) tw-pane-enter`,children:(0,Z.jsx)(ol,{})},`todos-${a?.activeId??``}`):W===`memory`&&V.memory?(0,Z.jsx)(`div`,{className:`flex-1 min-h-0 bg-(--tw-surface-page) tw-pane-enter`,children:(0,Z.jsx)(Zc,{live:Cr,pluginOn:!!V.memory,workspacePath:a?.sessions.find(e=>e.id===a.activeId)?.workspacePath||H?.projectRoot||``})},`memory-${a?.activeId??``}`):W===`thread`?(0,Z.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,Z.jsx)(Ou,{messages:c,busy:!!(a?.activeId&&_t.includes(a.activeId)),onRestoreCheckpoint:(e,t)=>{let n=Y.current?.activeId;if(!n)return;if(_t.includes(n)||ht){B(`请等待当前回复结束后再从此处继续`);return}let r=Math.max(0,Math.min(e,Ka.current.length-1)),i=Ka.current.slice(0,r+1);Ka.current=i,l(i),Y.current&&X(qe(Y.current,i,{touchUpdatedAt:!0}));let a=`请从第 ${t} 轮继续`;Mn(`dialog`),d(a),B(`已回到第 ${t} 轮,正在继续…`,`ok`),window.setTimeout(()=>{fs(a)},0)}})},`thread-${a?.activeId??``}`):(0,Z.jsxs)(`div`,{className:`relative flex-1 min-h-0 flex flex-col${gc?` justify-center`:``}`,children:[gc?(0,Z.jsxs)(`div`,{className:`shrink-0 flex flex-col items-center text-center px-8 sm:px-10 lg:px-12 pb-8`,children:[(0,Z.jsx)(`img`,{src:`/brand/brand-mark.png`,alt:``,width:64,height:64,className:`w-16 h-16 rounded-[14px] object-contain`}),(0,Z.jsx)(`h2`,{className:`mt-5 text-[22px] leading-8 font-semibold tracking-tight text-stone-800 text-balance`,children:Et(`chat.emptyTitle`,void 0,Pn.language)})]}):null,gc?null:(0,Z.jsxs)(`div`,{className:`relative flex-1 min-h-0`,children:[(0,Z.jsx)(`div`,{ref:ba,onScroll:Mo,className:`h-full overflow-y-auto px-8 sm:px-10 lg:px-12 py-6`,style:{fontSize:`var(--tw-session-font-size, ${Pn.sessionFontSize}px)`},children:(0,Z.jsx)(`div`,{className:`w-full max-w-[min(64rem,100%)] mx-auto flex flex-col gap-4`,onClick:hc,children:c.map((e,n)=>e.role===`user`?(0,Z.jsxs)(`div`,{className:`group flex flex-col items-end gap-1`,children:[e.refs?.length||e.attachments?.length||e.images?.length?(0,Z.jsxs)(`div`,{className:`flex flex-wrap justify-end gap-1.5 max-w-[82%]`,children:[e.refs?.map(e=>(0,Z.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,Z.jsx)(ql,{className:`w-3.5 h-3.5`}),(0,Z.jsx)(`span`,{className:`text-[10px] text-stone-400 shrink-0`,children:oc(e.format)}),(0,Z.jsx)(`span`,{className:`max-w-40 truncate`,children:e.title})]},e.path)),e.attachments?.map(e=>(0,Z.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,Z.jsx)(ql,{className:`w-3.5 h-3.5 text-[#4176e6]`}),(0,Z.jsx)(`span`,{className:`max-w-48 truncate`,children:e.name}),(0,Z.jsx)(`span`,{className:`text-stone-400`,children:yu(e.size)})]},e.name)),e.images?.map(e=>(0,Z.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,Z.jsx)(`img`,{src:e.dataUrl,alt:e.name,className:`max-h-40 max-w-48 object-contain`})},e.id))]}):null,e.content&&(0,Z.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,Z.jsxs)(`div`,{className:`tw-msg-actions ${xc(n)}`,children:[e.time!=null&&(0,Z.jsx)(`span`,{className:`tw-msg-action-time pr-0.5`,children:bu(e.time)}),(0,Z.jsx)(Su,{text:e.content})]})]},n):(0,Z.jsxs)(`div`,{className:`group`,children:[e.turnStatus===`stopped`?(0,Z.jsxs)(`div`,{className:`mb-2`,children:[(0,Z.jsx)(`div`,{className:`text-[13px] text-stone-500 py-1`,children:`已停止`}),(0,Z.jsx)(`div`,{className:`border-t border-stone-200/80`})]}):null,(()=>{let t=e.activitySteps??[],r=t.some(e=>e.status===`running`),i=n===c.length-1&&e.turnStatus!==`stopped`&&(ht||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 s=e.reasoningOpen??!1,l=i||s||r,u=a&&!s&&!l&&e.reasoning?zl(e.reasoning).replaceAll(`**`,``):``;return(0,Z.jsxs)(`div`,{className:`mb-2`,children:[(0,Z.jsxs)(`button`,{type:`button`,onClick:e=>bs(n,e),className:`flex w-full items-center gap-2 py-1 text-left select-none`,children:[a||i&&!e.content?(0,Z.jsx)(`span`,{className:`w-3.5 h-3.5 shrink-0 rounded-full border-2 border-purple-400 border-t-transparent animate-spin`}):(0,Z.jsxs)($,{className:`w-3.5 h-3.5 shrink-0 text-stone-400`,children:[(0,Z.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,Z.jsx)(`path`,{d:`M9 18h6`}),(0,Z.jsx)(`path`,{d:`M10 22h4`})]}),(0,Z.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,Z.jsxs)(`span`,{className:`text-xs text-stone-400 shrink-0`,children:[`用时 `,e.reasoningDuration,`s`]}),(0,Z.jsx)(Vl,{className:`w-3.5 h-3.5 shrink-0 text-stone-400 transition-transform ${s?`rotate-180`:``}`}),u?(0,Z.jsx)(`span`,{className:`flex-1 min-w-0 truncate text-xs text-shimmer-muted think-mask`,children:u}):null]}),l&&t.length>0?(0,Z.jsx)(`ul`,{className:`mt-1.5 mb-1 pl-5.5 space-y-1.5`,children:t.map(e=>(0,Z.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,Z.jsx)(Ll,{kind:e.kind,status:e.status}),(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1 leading-5`,children:[(0,Z.jsx)(`span`,{className:`font-medium ${e.status===`running`?`text-shimmer`:``}`,children:e.title}),e.detail?(0,Z.jsxs)(`span`,{className:`text-stone-400`,children:[` · `,(0,Z.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,Z.jsxs)(`span`,{className:`text-stone-400 text-shimmer-muted`,children:[` · `,`…`]}):null]})]},e.id))}):null,s&&e.reasoning?(0,Z.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,Z.jsx)(`div`,{className:`mt-1.5 pl-5.5`,children:(0,Z.jsx)(`span`,{className:`tw-turn-stopped-pill`,children:`已停止`})}):null]})})(),e.content?(0,Z.jsx)(`div`,{className:`chat-md prose prose-sm prose-stone max-w-none tw-chat-text`,dangerouslySetInnerHTML:{__html:Dt(e.content)}}):null,e.caseFile?(0,Z.jsxs)(`button`,{type:`button`,"data-focus-doc":`cases:${e.caseFile.path.replace(/\\/g,`/`)}`,"data-hint":`双击本地打开`,onDoubleClick:()=>{Te(`cases`,e.caseFile.path).catch(e=>B(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,Z.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,Z.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`span`,{className:`block text-sm text-stone-800 truncate`,children:e.caseFile.name}),(0,Z.jsxs)(`span`,{className:`block text-[11px] text-stone-400 truncate`,children:[De(`cases`),e.caseFile.path,e.caseFile.count>0?` · ${e.caseFile.count} 条`:``,` · 双击本地打开`]})]})]}):null,e.docsFile?(0,Z.jsxs)(`button`,{type:`button`,"data-focus-doc":`${e.docsFile.root}:${e.docsFile.path.replace(/\\/g,`/`)}`,"data-hint":`点击本地打开`,onClick:()=>{Te(e.docsFile.root,e.docsFile.path).catch(e=>B(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,Z.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,Z.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`span`,{className:`block text-sm text-stone-800 truncate`,children:e.docsFile.name}),(0,Z.jsxs)(`span`,{className:`block text-[11px] text-stone-400 truncate`,children:[De(e.docsFile.root),e.docsFile.path,e.docsFile.note?` · ${e.docsFile.note}`:``,` · 点击打开`]})]})]}):null,e.presentFiles?.length?e.presentFiles.map(e=>(0,Z.jsxs)(`button`,{type:`button`,"data-hint":`点击本地打开`,onClick:()=>{Nt(e.path,Zt).catch(e=>B(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,Z.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,Z.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`span`,{className:`block text-sm text-stone-800 truncate`,children:e.name}),(0,Z.jsxs)(`span`,{className:`block text-[11px] text-stone-400 truncate`,children:[e.path,e.description?` · ${e.description}`:``,` · 点击打开`]})]})]},e.path)):null,e.content&&!(n===c.length-1&&ht)?(0,Z.jsxs)(`div`,{className:`tw-msg-actions mt-1 ${xc(n)}`,children:[(0,Z.jsx)(Su,{text:e.content}),e.usage&&(0,Z.jsx)(Au,{usage:e.usage,model:e.model??t?.model}),e.time!=null&&(0,Z.jsx)(`span`,{className:`tw-msg-action-time`,children:bu(e.time)})]}):null]},n))})}),$t&&(0,Z.jsx)(`button`,{type:`button`,onClick:Po,"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,Z.jsx)(Vl,{className:`w-4 h-4`})})]},`dialog-${a?.activeId??``}`),Ot&&(0,Z.jsx)(`div`,{className:`shrink-0 px-8 sm:px-10 lg:px-12 pb-2`,children:(0,Z.jsxs)(`div`,{ref:Ea,className:`w-full max-w-[min(64rem,100%)] mx-auto flex items-start gap-3 px-4 py-3 rounded-xl text-sm border ${Yt===`ok`?`tw-notice-anim`:``} ${Yt===`ok`?`bg-emerald-50 border-emerald-200 text-emerald-900`:`bg-red-50 border-red-200 text-red-800`}`,children:[(0,Z.jsx)(`span`,{className:`mt-0.5 w-5 h-5 shrink-0 rounded-full flex items-center justify-center text-xs font-semibold ${Yt===`ok`?`bg-emerald-100 text-emerald-700`:`bg-red-100 text-red-600`}`,children:Yt===`ok`?`i`:`!`}),(0,Z.jsx)(`pre`,{className:`flex-1 min-w-0 m-0 font-sans text-[13px] leading-5 whitespace-pre-wrap break-words`,children:Ot.replace(/\*\*/g,``).replace(/\s*:\s*\*\*/g,`: `).trim()}),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>B(null),className:`shrink-0 text-xs ${Yt===`ok`?`text-emerald-500 hover:text-emerald-700`:`text-red-400 hover:text-red-600`}`,children:`关闭`})]})}),(0,Z.jsxs)(`div`,{className:`shrink-0 px-8 sm:px-10 lg:px-12 pb-5`,children:[(0,Z.jsxs)(`div`,{className:`w-full max-w-[min(64rem,100%)] mx-auto`,children:[oe?.active&&V.promptGen?(0,Z.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,Z.jsxs)(`span`,{className:`flex-1 min-w-0 truncate`,children:[`生成提示词已启用 · `,Oi(oe)]}),(0,Z.jsx)(`button`,{type:`button`,className:`shrink-0 hover:underline`,onClick:()=>P(!0),children:`改配置`}),(0,Z.jsx)(`button`,{type:`button`,className:`shrink-0 text-stone-500 hover:text-stone-800`,onClick:()=>As(null),children:`取消`})]}):null,F?.active&&V.knowledgeGen?(0,Z.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,Z.jsxs)(`span`,{className:`flex-1 min-w-0 truncate`,children:[`生成知识库已启用 · `,Hi(F)]}),(0,Z.jsx)(`button`,{type:`button`,className:`shrink-0 hover:underline`,onClick:()=>ue(!0),children:`改配置`}),(0,Z.jsx)(`button`,{type:`button`,className:`shrink-0 text-stone-500 hover:text-stone-800`,onClick:()=>js(null),children:`取消`})]}):null,j?.active&&V.caseGen?(0,Z.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,Z.jsxs)(`span`,{className:`flex-1 min-w-0 truncate`,children:[`生成测试用例已启用 · `,pi(j)]}),(0,Z.jsx)(`button`,{type:`button`,className:`shrink-0 hover:underline`,onClick:()=>te(!0),children:`改配置`}),(0,Z.jsx)(`button`,{type:`button`,className:`shrink-0 text-stone-500 hover:text-stone-800`,onClick:()=>ks(null),children:`取消`})]}):null,hr.length>0?(0,Z.jsx)(`div`,{className:`mb-2 rounded-xl border border-stone-200/80 bg-stone-100/80 overflow-hidden`,children:hr.map(e=>(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 border-b border-stone-200/60 last:border-b-0`,children:[(0,Z.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-stone-400 shrink-0`,"aria-hidden":!0}),(0,Z.jsx)(`span`,{className:`flex-1 min-w-0 truncate text-[13px] text-stone-700`,children:ya(e)}),(0,Z.jsx)(`button`,{type:`button`,"data-hint":`编辑回输入框`,onClick:()=>gs(e.id),className:`tw-icon-btn w-7 h-7 rounded-md flex items-center justify-center outline-none`,children:(0,Z.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Z.jsx)(`path`,{d:`M12 20h9`}),(0,Z.jsx)(`path`,{d:`M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z`})]})}),(0,Z.jsx)(`button`,{type:`button`,"data-hint":`从队列移除`,onClick:()=>hs(e.id),className:`tw-icon-btn w-7 h-7 rounded-md flex items-center justify-center outline-none`,children:(0,Z.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Z.jsx)(`path`,{d:`M3 6h18`}),(0,Z.jsx)(`path`,{d:`M8 6V4h8v2`}),(0,Z.jsx)(`path`,{d:`M19 6l-1 14H6L5 6`})]})}),(0,Z.jsx)(`button`,{type:`button`,"data-hint":`插话立即发送(其后队列仍会续发)`,onClick:()=>_s(e.id),className:`tw-icon-btn w-7 h-7 rounded-md flex items-center justify-center outline-none text-[#4176e6]`,children:(0,Z.jsx)(Yl,{className:`w-3.5 h-3.5`})})]},e.id))}):null,Di?(0,Z.jsxs)(`div`,{className:`mb-2 rounded-xl border border-amber-300/60 bg-amber-50/90 px-4 py-3 shadow-sm`,children:[(0,Z.jsx)(`div`,{className:`text-[13px] font-medium text-stone-800 mb-1`,children:`待批准计划`}),(0,Z.jsx)(`div`,{className:`text-[14px] font-medium text-stone-900`,children:Di.title}),Di.summary?(0,Z.jsx)(`p`,{className:`mt-1 text-[13px] text-stone-600 leading-5`,children:Di.summary}):null,(0,Z.jsx)(`ol`,{className:`mt-2 list-decimal pl-5 space-y-1 text-[13px] text-stone-700`,children:Di.steps.map((e,t)=>(0,Z.jsx)(`li`,{children:e},`${t}-${e.slice(0,24)}`))}),(0,Z.jsxs)(`div`,{className:`mt-3 flex items-center justify-end gap-2`,children:[(0,Z.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:()=>Is(),children:`驳回`}),(0,Z.jsx)(`button`,{type:`button`,className:`h-8 px-3 rounded-lg bg-[#4176e6] text-[12px] text-white hover:bg-[#3467d4]`,onClick:()=>Fs(),children:`批准实施`})]})]}):null,Ji?(0,Z.jsx)(_l,{kind:Ji.kind,items:Ji.items,manual:Ji.manual,quick:Ji.quick,quickNote:Ji.quickNote,tasksOn:V.tasks,closing:Qi,onConfirm:e=>{Ji.manual?(la(null),fa(Ji.kind,e)):la(e)},onCancel:()=>la(null)}):null,nl>0&&Q?(0,Z.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,Z.jsxs)(`div`,{className:`flex shrink-0 justify-between gap-4 px-5 ${zi?`items-center py-3.5`:`items-start pt-4`}`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`div`,{className:`mb-1 text-[11px] leading-4 text-stone-400`,children:Wi?`跳过确认`:Q.header||`模型需要你的确认`}),(0,Z.jsx)(`h3`,{className:`text-[15px] leading-5.5 font-medium text-stone-900`,children:Wi?`确认 ${dl.length} 道跳过的题怎么处理`:Q.question})]}),(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[zi?(0,Z.jsx)(`span`,{className:`text-[11px] leading-4 text-stone-400`,children:Wi?`已跳过 ${dl.length} 题`:`第 ${rl+1} 步 / 共 ${nl} 步`}):null,(0,Z.jsx)(`button`,{type:`button`,"aria-label":zi?`展开问题`:`收起问题`,onClick:()=>Bi(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,Z.jsx)(Vl,{className:`h-4 w-4 transition-transform ${zi?`rotate-180`:``}`})})]})]}),zi?null:Wi?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto overscroll-contain px-5 py-2`,children:[(0,Z.jsx)(`p`,{className:`text-[12px] leading-5 text-stone-500`,children:`跳过不算确认,本轮不会开始改代码。留下原因后我只出方案,等你回复「开始实施」。`}),(0,Z.jsx)(`ul`,{className:`mt-2 space-y-1 rounded-lg bg-stone-50 px-3 py-2`,children:dl.map(({q:e,index:t})=>(0,Z.jsxs)(`li`,{className:`text-[12px] leading-5 text-stone-600`,children:[(0,Z.jsxs)(`span`,{className:`text-stone-400`,children:[t+1,`.`]}),` `,e.header?`${e.header} / `:``,e.question,(0,Z.jsx)(`span`,{className:`ml-1 text-stone-400`,children:`— 已跳过`})]},e.id))}),(0,Z.jsx)(`textarea`,{autoFocus:!0,value:Ki,onChange:e=>qi(e.target.value),onKeyDown:e=>{e.key!==`Enter`||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),Js())},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,Z.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between gap-3 px-5 pt-2 pb-3`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:()=>Ys(),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,Z.jsx)(`button`,{type:`button`,onClick:()=>Js(),className:`h-8 shrink-0 rounded-lg bg-[#4176e6] px-3.5 text-[12px] font-medium text-white hover:bg-[#3467d4]`,children:`提交并继续`})]})]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto overscroll-contain px-3 py-1`,children:[Q.options?.length?(0,Z.jsx)(`div`,{className:`mt-2 flex flex-col gap-0.5`,role:Q.multi_select?`group`:`radiogroup`,children:Q.options.map((e,t)=>{let n=il.selected.includes(e.label),r=xl(e.label);return(0,Z.jsxs)(`button`,{type:`button`,role:Q.multi_select?`checkbox`:`radio`,"aria-checked":n,onClick:()=>Bs(Q,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:[Q.multi_select?(0,Z.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,Z.jsx)(Ul,{className:`h-3 w-3`})}):(0,Z.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,Z.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Z.jsxs)(`span`,{className:`flex flex-wrap items-center gap-x-2 gap-y-0.5`,children:[(0,Z.jsx)(`span`,{className:`text-[13px] leading-5 font-medium text-stone-800`,children:r.label}),r.recommended?(0,Z.jsx)(`span`,{className:`rounded bg-[#edf3fe] px-1 text-[10px] leading-4 font-semibold text-[#4176e6]`,children:`推荐`}):null]}),e.description?(0,Z.jsx)(`span`,{className:`mt-0.5 block text-[12px] leading-4.5 text-stone-400`,children:e.description}):null]})]},`${e.label}-${t}`)})}):(0,Z.jsx)(`div`,{className:`px-1.5 py-2`,children:(0,Z.jsx)(`textarea`,{autoFocus:!0,value:il.text,onChange:e=>Hs(Q,e.target.value),onKeyDown:e=>{e.key!==`Enter`||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),Us(Q,il.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:`输入你的回答…`})}),Q.options?.length?(0,Z.jsx)(`div`,{className:`mt-1 px-1.5 pb-1`,children:(0,Z.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,Z.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,Z.jsx)(`textarea`,{value:il.text,onChange:e=>Hs(Q,e.target.value),onKeyDown:e=>{e.key!==`Enter`||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),Us(Q,il.text))},rows:1,className:`min-h-5 w-full resize-none bg-transparent text-[13px] leading-5 outline-none`,placeholder:`输入序号选择(如 1${Q.multi_select?` 或 1,3`:``}),也可直接写你的回答`})]})}):null,(0,Z.jsx)(`div`,{className:`px-2 pb-2 pt-1 text-[11px] leading-4 text-stone-400`,children:Q.options?.length?`回车确认这一步;跳过的题会在提交前让你说明原因,不会直接开始实施`:`回车确认;跳过的题会在提交前让你说明原因,不会直接开始实施`})]}),(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between gap-3 px-5 pt-2 pb-3`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Z.jsx)(`button`,{type:`button`,"aria-label":`上一步`,disabled:rl===0,onClick:()=>Vs(rl-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,Z.jsx)(Hl,{className:`h-4 w-4 rotate-180`})}),(0,Z.jsxs)(`span`,{className:`px-1 text-[12px] font-medium text-stone-500`,children:[`第 `,rl+1,` 步 / 共 `,nl,` 步`]}),(0,Z.jsx)(`button`,{type:`button`,"aria-label":`下一步`,disabled:al,onClick:()=>Vs(rl+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,Z.jsx)(Hl,{className:`h-4 w-4`})})]}),(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[Vi?(0,Z.jsx)(`span`,{className:`truncate text-[11px] text-rose-500`,children:Vi}):null,(0,Z.jsx)(`button`,{type:`button`,onClick:()=>qs(),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,Z.jsx)(`button`,{type:`button`,disabled:!sl,onClick:()=>al?Gs():Vs(rl+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:al?`提交回答`:`下一步`})]})]})]})]}):null,(0,Z.jsxs)(`div`,{ref:Da,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||b.length>0||Ci.length>0)&&(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-1.5 px-3 pt-0.5 pb-2`,children:[Ci.map(e=>(0,Z.jsxs)(`span`,{className:`flex items-center gap-1.5 rounded-lg border border-[#4176e6]/25 bg-[#edf3fe] py-1 pr-1 pl-2.5 text-xs text-[#4176e6]`,children:[(0,Z.jsxs)($,{className:`h-3.5 w-3.5 shrink-0`,children:[(0,Z.jsx)(`path`,{d:`M14 3v4a1 1 0 0 0 1 1h4`}),(0,Z.jsx)(`path`,{d:`M5 3h9l5 5v13H5z`}),(0,Z.jsx)(`path`,{d:`M8 13h8`}),(0,Z.jsx)(`path`,{d:`M8 17h5`})]}),(0,Z.jsx)(`span`,{className:`shrink-0 text-[10px] text-[#4176e6]/80`,children:`要求`}),(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>Ei(e),className:`max-w-56 truncate text-left hover:underline`,children:[e.label,(0,Z.jsx)($,{className:`ml-1 inline h-3 w-3 shrink-0 opacity-50`,children:(0,Z.jsx)(`path`,{d:`m6 9 6 6 6-6`})})]}),e.detail?(0,Z.jsx)(`span`,{className:`max-w-44 truncate text-[10px] text-[#4176e6]/70`,children:e.detail}):null,(0,Z.jsx)(`button`,{type:`button`,onClick:()=>ts(e.id),className:`flex h-5 w-5 items-center justify-center rounded text-[#4176e6]/70 hover:bg-white/80 hover:text-[#4176e6]`,children:(0,Z.jsxs)($,{className:`h-3 w-3`,children:[(0,Z.jsx)(`path`,{d:`M18 6 6 18`}),(0,Z.jsx)(`path`,{d:`m6 6 12 12`})]})})]},e.id)),S.map(e=>(0,Z.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,Z.jsx)(ql,{className:`w-3.5 h-3.5`}),(0,Z.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:oc(e.format)}),(0,Z.jsx)(`span`,{className:`max-w-48 truncate`,children:e.title}),(0,Z.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,Z.jsxs)($,{className:`w-3 h-3`,children:[(0,Z.jsx)(`path`,{d:`M18 6 6 18`}),(0,Z.jsx)(`path`,{d:`m6 6 12 12`})]})})]},`${e.collection}:${e.path}`)),f.map((e,t)=>(0,Z.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,Z.jsx)(ql,{className:`w-3.5 h-3.5`}),(0,Z.jsx)(`span`,{className:`text-[10px] text-[#4176e6]/80 shrink-0`,children:`文件`}),(0,Z.jsx)(`span`,{className:`max-w-48 truncate`,children:e.name}),(0,Z.jsx)(`button`,{type:`button`,"data-hint":`移除`,onClick:()=>m(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,Z.jsxs)($,{className:`w-3 h-3`,children:[(0,Z.jsx)(`path`,{d:`M18 6 6 18`}),(0,Z.jsx)(`path`,{d:`m6 6 12 12`})]})})]},`${e.name}-${t}`)),b.map(e=>(0,Z.jsxs)(`span`,{className:`relative group inline-flex rounded-lg border border-stone-200 overflow-hidden bg-stone-50`,"data-hint":`${e.name} · ${yu(e.size)}`,children:[(0,Z.jsx)(`img`,{src:e.dataUrl,alt:e.name,className:`h-14 w-14 object-cover`}),(0,Z.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,Z.jsxs)($,{className:`w-3 h-3`,children:[(0,Z.jsx)(`path`,{d:`M18 6 6 18`}),(0,Z.jsx)(`path`,{d:`m6 6 12 12`})]})})]},e.id))]}),(0,Z.jsxs)(`div`,{className:`relative`,children:[lr&&!Ba&&!Ia&&(0,Z.jsx)(`div`,{ref:Ta,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,Z.jsxs)(`div`,{className:`tw-dsh-scroll h-full overflow-y-auto overflow-x-hidden`,children:[(0,Z.jsx)(`div`,{className:`px-3 pt-0.5 pb-1.5 text-[11px] font-medium text-stone-400 tracking-wide`,children:`添加`}),(0,Z.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>{ur(!1),Sa.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,Z.jsx)(Jl,{className:`w-4 h-4 shrink-0 text-stone-500`}),(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1 text-[13px] text-stone-800`,children:[`文件`,(0,Z.jsx)(`span`,{className:`ml-1.5 text-stone-400 font-normal`,children:`file`})]}),(0,Z.jsx)(`span`,{className:`shrink-0 max-w-[45%] text-right text-[11px] text-stone-400 truncate`,children:`添加本地附件`})]}),(0,Z.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>{ur(!1),as()},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,Z.jsxs)($,{className:`w-4 h-4 shrink-0 text-stone-500`,children:[(0,Z.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`}),(0,Z.jsx)(`circle`,{cx:`12`,cy:`12`,r:`6`}),(0,Z.jsx)(`circle`,{cx:`12`,cy:`12`,r:`2`})]}),(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1 text-[13px] text-stone-800`,children:[`目标`,(0,Z.jsx)(`span`,{className:`ml-1.5 text-stone-400 font-normal`,children:`goal`})]}),(0,Z.jsx)(`span`,{className:`shrink-0 max-w-[45%] text-right text-[11px] text-stone-400 truncate`,children:`设置或查看长期任务目标`})]}),(0,Z.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>{ur(!1),mi===`off`?ss():Ls()},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 ${mi===`planning`?`bg-amber-50`:mi===`approved`?`bg-emerald-50`:``}`,children:[(0,Z.jsxs)($,{className:`w-4 h-4 shrink-0 ${mi===`planning`?`text-amber-800`:mi===`approved`?`text-emerald-800`:`text-stone-500`}`,children:[(0,Z.jsx)(`path`,{d:`M8 6h13`}),(0,Z.jsx)(`path`,{d:`M8 12h13`}),(0,Z.jsx)(`path`,{d:`M8 18h13`}),(0,Z.jsx)(`path`,{d:`M3 6h.01`}),(0,Z.jsx)(`path`,{d:`M3 12h.01`}),(0,Z.jsx)(`path`,{d:`M3 18h.01`})]}),(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1 text-[13px] text-stone-800`,children:[`计划`,(0,Z.jsx)(`span`,{className:`ml-1.5 text-stone-400 font-normal`,children:`plan`})]}),(0,Z.jsx)(`span`,{className:`shrink-0 max-w-[45%] text-right text-[11px] text-stone-400 truncate`,children:`进入或退出计划模式`})]}),V.todos||V.tasks?(0,Z.jsxs)(Z.Fragment,{children:[V.todos?(0,Z.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>da(`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,Z.jsxs)($,{className:`w-4 h-4 shrink-0 text-stone-500`,children:[(0,Z.jsx)(`path`,{d:`M8 6h13`}),(0,Z.jsx)(`path`,{d:`M8 12h13`}),(0,Z.jsx)(`path`,{d:`M8 18h13`}),(0,Z.jsx)(`path`,{d:`M3 6h.01`}),(0,Z.jsx)(`path`,{d:`M3 12h.01`}),(0,Z.jsx)(`path`,{d:`M3 18h.01`})]}),(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1 text-[13px] text-stone-800`,children:[`待办`,(0,Z.jsx)(`span`,{className:`ml-1.5 text-stone-400 font-normal`,children:`todo`})]}),(0,Z.jsx)(`span`,{className:`shrink-0 max-w-[45%] text-right text-[11px] text-stone-400 truncate`,children:`手动添加一条待办`})]}):null,V.tasks?(0,Z.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>da(`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,Z.jsxs)($,{className:`w-4 h-4 shrink-0 text-stone-500`,children:[(0,Z.jsx)(`path`,{d:`M9 5h10`}),(0,Z.jsx)(`path`,{d:`M9 12h10`}),(0,Z.jsx)(`path`,{d:`M9 19h10`}),(0,Z.jsx)(`path`,{d:`M4 5h.01`}),(0,Z.jsx)(`path`,{d:`M4 12h.01`}),(0,Z.jsx)(`path`,{d:`M4 19h.01`})]}),(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1 text-[13px] text-stone-800`,children:[`任务`,(0,Z.jsx)(`span`,{className:`ml-1.5 text-stone-400 font-normal`,children:`task`})]}),(0,Z.jsx)(`span`,{className:`shrink-0 max-w-[45%] text-right text-[11px] text-stone-400 truncate`,children:`手动添加一个任务`})]}):null]}):null,Ra.length?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`div`,{className:`my-1 border-t border-stone-100`}),(0,Z.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>pr(e=>!e),className:`w-full flex items-center gap-2 px-3 py-1.5 text-left hover:bg-stone-50`,children:[(0,Z.jsx)(`span`,{className:`flex-1 text-[11px] font-medium text-stone-400 tracking-wide`,children:`扩展插件`}),(0,Z.jsx)(Vl,{className:`w-3.5 h-3.5 text-stone-400 shrink-0 transition-transform ${dr?`rotate-180`:``}`})]}),dr?Ra.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,Z.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>{ur(!1),jo(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,Z.jsx)(ru,{className:`w-4 h-4 shrink-0 text-stone-500`}),(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1 text-[13px] text-stone-800`,children:[e.name,t?(0,Z.jsx)(`span`,{className:`ml-1.5 text-stone-400 font-normal`,children:t}):null]}),n?(0,Z.jsx)(`span`,{className:`shrink-0 max-w-[45%] text-right text-[11px] text-stone-400 truncate`,children:n}):null]},e.id)}):null]}):null,(0,Z.jsx)(`div`,{className:`my-1 border-t border-stone-100`}),(0,Z.jsx)(`div`,{className:`px-3 pt-1 pb-1.5 text-[11px] font-medium text-stone-400 tracking-wide`,children:`指令`}),(0,Z.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>{ur(!1),Zr.current?B(`请等待当前回复结束后再压缩`):ds({force:!0}).then(e=>{e&&B(`已压缩上下文`)})},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,Z.jsx)($,{className:`w-4 h-4 shrink-0 text-stone-500`,children:(0,Z.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`})}),(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1 text-[13px] text-stone-800`,children:[`压缩`,(0,Z.jsx)(`span`,{className:`ml-1.5 text-stone-400 font-normal`,children:`compact`})]}),(0,Z.jsx)(`span`,{className:`shrink-0 max-w-[45%] text-right text-[11px] text-stone-400 truncate`,children:`压缩以上对话内容`})]}),(0,Z.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>{ur(!1),nc()},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,Z.jsxs)($,{className:`w-4 h-4 shrink-0 text-stone-500`,children:[(0,Z.jsx)(`path`,{d:`M3 3v18h18`}),(0,Z.jsx)(`path`,{d:`M7 14v4`}),(0,Z.jsx)(`path`,{d:`M12 10v8`}),(0,Z.jsx)(`path`,{d:`M17 6v12`})]}),(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1 text-[13px] text-stone-800`,children:[`会话统计`,(0,Z.jsx)(`span`,{className:`ml-1.5 text-stone-400 font-normal`,children:`stats`})]}),(0,Z.jsx)(`span`,{className:`shrink-0 max-w-[45%] text-right text-[11px] text-stone-400 truncate`,children:`查看本会话用量摘要`})]})]})}),Ba&&(0,Z.jsxs)(`div`,{ref:wa,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,Z.jsx)(`div`,{className:`px-3 py-1.5 text-[11px] text-stone-400`,children:`插件`}),Ra.map((e,t)=>(0,Z.jsxs)(`button`,{type:`button`,"data-plugin-index":t,onMouseDown:e=>e.preventDefault(),onMouseEnter:()=>R(t),onClick:()=>jo(e.id),className:`tw-composer-menu-item w-full text-left px-3 py-2 rounded-lg transition-colors ${t===ve?`is-active`:``}`,children:[(0,Z.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,Z.jsx)(`div`,{className:`text-[13px] font-medium text-stone-800 flex-1`,children:e.name})}),(0,Z.jsx)(`div`,{className:`mt-0.5 text-xs text-stone-400 line-clamp-2`,children:e.description})]},e.id))]}),Ia&&(0,Z.jsx)(`div`,{ref:Ca,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:Fa.length===0?(0,Z.jsxs)(`div`,{className:`px-3 py-2 text-xs text-stone-400 space-y-1`,children:[wr?(0,Z.jsx)(`p`,{children:`项目文档:无匹配`}):null,ka?(0,Z.jsx)(`p`,{children:`工作区:无匹配`}):(0,Z.jsx)(`p`,{children:`工作区:请先在侧栏添加并选择工作区`}),wr?null:(0,Z.jsxs)(`p`,{children:[`「知识库检索」未启用:启用后才能用 @ 引用`,Oe(`knowledge`),` / `,Oe(`templates`),`文档`]})]}):(0,Z.jsxs)(Z.Fragment,{children:[Ma.length>0?(0,Z.jsxs)(`div`,{className:`px-3 py-1.5 text-[11px] font-medium text-stone-400`,children:[`项目文档(`,Oe(`knowledge`),` / `,Oe(`templates`),`)`]}):null,Fa.map((e,t)=>{let n=e.doc,r=Fa[t-1],i=e.section===`workspace`&&r?.section!==`workspace`;return(0,Z.jsxs)(`div`,{children:[i?(0,Z.jsxs)(Z.Fragment,{children:[Ma.length>0?(0,Z.jsx)(`div`,{className:`my-1 mx-2 border-t border-stone-200`,role:`separator`}):null,(0,Z.jsx)(`div`,{className:`px-3 py-1.5 text-[11px] font-medium text-stone-400`,children:`工作区`})]}):null,(0,Z.jsxs)(`button`,{type:`button`,"data-mention-index":t,onMouseDown:e=>e.preventDefault(),onClick:()=>Oo(n),className:`tw-composer-menu-item w-full text-left px-3 py-2 rounded-lg transition-colors ${t===tr?`is-active`:``}`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-[13px] text-stone-800`,children:[(0,Z.jsx)(`span`,{className:`text-[11px] px-1.5 py-0.5 rounded bg-stone-100 text-stone-500 shrink-0`,children:n.collection===`knowledge`?Oe(`knowledge`):n.collection===`templates`?Oe(`templates`):n.format===`dir`?`文件夹`:`文件`}),n.collection===`workspace`?null:(0,Z.jsx)(`span`,{className:`text-[11px] px-1.5 py-0.5 rounded bg-stone-100 text-stone-500 shrink-0`,children:oc(n.format)}),(0,Z.jsx)(`span`,{className:`truncate font-medium`,children:n.title})]}),(0,Z.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}`)}),wr?null:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`div`,{className:`my-1 mx-2 border-t border-stone-200`,role:`separator`}),(0,Z.jsx)(`p`,{className:`px-3 py-1.5 text-[11px] text-stone-400`,children:`「知识库检索」未启用:@ 仅引用工作区文件`})]})]})}),(0,Z.jsxs)(`div`,{className:`flex items-start gap-2 px-3`,children:[gi===`goal`?(0,Z.jsxs)(`span`,{className:`tw-composer-mode-chip is-goal`,"data-hint":`会话目标`,children:[(0,Z.jsxs)($,{className:`w-3.5 h-3.5 shrink-0`,children:[(0,Z.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`}),(0,Z.jsx)(`circle`,{cx:`12`,cy:`12`,r:`6`}),(0,Z.jsx)(`circle`,{cx:`12`,cy:`12`,r:`2`})]}),(0,Z.jsx)(`span`,{children:`目标`}),(0,Z.jsx)(`button`,{type:`button`,"aria-label":`取消目标输入`,onClick:()=>yi(null),children:(0,Z.jsxs)($,{className:`w-3 h-3`,children:[(0,Z.jsx)(`path`,{d:`M18 6 6 18`}),(0,Z.jsx)(`path`,{d:`m6 6 12 12`})]})})]}):null,gi===`plan`?(0,Z.jsxs)(`span`,{className:`tw-composer-mode-chip is-plan${mi===`approved`?` is-approved`:``}`,"data-hint":mi===`approved`?`计划模式·已批准`:`计划模式·探查中`,children:[(0,Z.jsxs)($,{className:`w-3.5 h-3.5 shrink-0`,children:[(0,Z.jsx)(`path`,{d:`M8 6h13`}),(0,Z.jsx)(`path`,{d:`M8 12h13`}),(0,Z.jsx)(`path`,{d:`M8 18h13`}),(0,Z.jsx)(`path`,{d:`M3 6h.01`}),(0,Z.jsx)(`path`,{d:`M3 12h.01`}),(0,Z.jsx)(`path`,{d:`M3 18h.01`})]}),(0,Z.jsx)(`span`,{children:`计划`}),(0,Z.jsx)(`button`,{type:`button`,"aria-label":`退出计划模式`,onClick:()=>is(),children:(0,Z.jsxs)($,{className:`w-3 h-3`,children:[(0,Z.jsx)(`path`,{d:`M18 6 6 18`}),(0,Z.jsx)(`path`,{d:`m6 6 12 12`})]})})]}):null,gi===`pluginDev`?(0,Z.jsxs)(`span`,{className:`tw-composer-mode-chip is-plugin-dev`,children:[(0,Z.jsxs)($,{className:`w-3.5 h-3.5 shrink-0`,children:[(0,Z.jsx)(`path`,{d:`M9 7V3`}),(0,Z.jsx)(`path`,{d:`M15 7V3`}),(0,Z.jsx)(`path`,{d:`M6 7h12v4a6 6 0 0 1-12 0V7Z`}),(0,Z.jsx)(`path`,{d:`M12 17v4`})]}),(0,Z.jsx)(`span`,{children:`插件开发`}),(0,Z.jsx)(`button`,{type:`button`,"aria-label":`退出插件开发`,onClick:()=>is(),children:(0,Z.jsxs)($,{className:`w-3 h-3`,children:[(0,Z.jsx)(`path`,{d:`M18 6 6 18`}),(0,Z.jsx)(`path`,{d:`m6 6 12 12`})]})})]}):null,gi===`reports`?(0,Z.jsxs)(`span`,{className:`tw-composer-mode-chip is-report`,children:[(0,Z.jsxs)($,{className:`w-3.5 h-3.5 shrink-0`,children:[(0,Z.jsx)(`path`,{d:`M14 3v4a1 1 0 0 0 1 1h4`}),(0,Z.jsx)(`path`,{d:`M5 3h9l5 5v13H5z`}),(0,Z.jsx)(`path`,{d:`M8 13h8`}),(0,Z.jsx)(`path`,{d:`M8 17h5`})]}),(0,Z.jsxs)(`span`,{children:[`生成`,br[bi]]}),(0,Z.jsx)(`button`,{type:`button`,"aria-label":`取消汇报生成`,onClick:()=>is(),children:(0,Z.jsxs)($,{className:`w-3 h-3`,children:[(0,Z.jsx)(`path`,{d:`M18 6 6 18`}),(0,Z.jsx)(`path`,{d:`m6 6 12 12`})]})})]}):null,(0,Z.jsx)(`textarea`,{ref:xa,value:u,onChange:e=>d(e.target.value),onPaste:mc,onKeyDown:e=>{if(Ba&&Ra.length){if(e.key===`ArrowDown`){e.preventDefault(),R(e=>(e+1)%Ra.length);return}if(e.key===`ArrowUp`){e.preventDefault(),R(e=>(e-1+Ra.length)%Ra.length);return}if(e.key===`Escape`){e.preventDefault(),cr(!0),La&&d(u.slice(0,La.from));return}if(e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing){e.preventDefault();let t=Ra[ve]??Ra[0];t&&jo(t.id);return}}if(Ia&&Fa.length){if(e.key===`ArrowDown`){e.preventDefault(),rr(e=>(e+1)%Fa.length);return}if(e.key===`ArrowUp`){e.preventDefault(),rr(e=>(e-1+Fa.length)%Fa.length);return}if(e.key===`Escape`){e.preventDefault(),or(!0),ja&&d(u.slice(0,ja.from));return}if(e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing){e.preventDefault();let t=Fa[tr]?.doc;t&&Oo(t);return}}if(e.key===`Escape`&&lr)e.preventDefault(),ur(!1);else if(e.key===`Escape`&&(ja||La)){e.preventDefault(),or(!0),cr(!0);let t=ja?.from??La?.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(Zr.current){if(t){let e=u.trim();if(e||f.length>0||b.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:[...b]};rs(),vs(t)}else J.current.length&&vs();return}fs(void 0,{forceBusy:Ve().busySendBehavior??`queue`})}else fs()}},rows:1,placeholder:t?Ci.length>0?`可补充说明;直接发送会带上「要求」里的完整内容`:hr.length>0&&ht?`Cmd/Ctrl+Enter 插话发送全部排队消息`:wr?`请输入内容,或用 @ 引用文档`:ka?`请输入内容,或用 @ 引用工作区文件`:`请输入内容(@ 引用文档需先启用「知识库检索」)`:`请先配置模型(左下角「设置」→ 模型)`,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,Z.jsxs)(`div`,{className:`tw-composer-bar flex items-center gap-1.5 px-3 pb-3 pt-3`,children:[(0,Z.jsx)(`button`,{type:`button`,"data-add-menu-btn":!0,"aria-label":mi===`off`?`添加`:mi===`planning`?`添加(计划模式·探查中)`:`添加(计划模式·已批准)`,onClick:()=>{ur(e=>!e),or(!0),cr(!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 ${lr?`bg-(--tw-session-hover-bg)`:``}`,children:(0,Z.jsxs)($,{className:`w-4 h-4`,children:[(0,Z.jsx)(`path`,{d:`M5 12h14`}),(0,Z.jsx)(`path`,{d:`M12 5v14`})]})}),q&&(0,Z.jsxs)(D,{children:[(0,Z.jsxs)(O,{title:zc?`工作区:${zc}`:`选择工作区`,"aria-label":Vc?`工作区:${Vc}`:`选择工作区`,disabled:Cn,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,Z.jsx)(Xl,{className:`w-3.5 h-3.5 shrink-0 text-stone-500`}),(0,Z.jsx)(`span`,{className:`tw-composer-bar-label truncate`,children:Vc}),(0,Z.jsx)(Vl,{className:`tw-composer-bar-chevron w-3.5 h-3.5 shrink-0 text-stone-400 transition-transform group-data-[open]:rotate-180`})]}),(0,Z.jsxs)(T,{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:[(H?.items??[]).map(e=>{let t=e.path===zc;return(0,Z.jsx)(E,{children:(0,Z.jsxs)(`button`,{type:`button`,disabled:Cn,onClick:()=>void fo(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,Z.jsx)(Xl,{className:`w-4 h-4 shrink-0 text-stone-500`}),(0,Z.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:jt(e,Nc)}),t&&(0,Z.jsx)(Ul,{className:`w-3.5 h-3.5 shrink-0 text-[#4176e6]`})]})},e.id)}),(H?.items?.length??0)>0&&(0,Z.jsx)(`div`,{className:`my-1 border-t border-stone-100`}),(0,Z.jsx)(E,{children:(0,Z.jsxs)(`button`,{type:`button`,disabled:Cn,onClick:()=>void po(),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,Z.jsx)(`span`,{className:`w-4 h-4 shrink-0 flex items-center justify-center text-stone-500 text-base leading-none`,children:`+`}),`添加工作区...`]})})]})]}),(0,Z.jsxs)(D,{children:[(0,Z.jsxs)(O,{title:`访问权限:${Cc.label}`,"aria-label":`访问权限:${Cc.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,Z.jsx)(uu,{level:Zt,className:`w-3.5 h-3.5 shrink-0 text-stone-500`}),(0,Z.jsx)(`span`,{className:`tw-composer-bar-label truncate`,children:Cc.label}),(0,Z.jsx)(`span`,{className:`ml-0.5 w-1.5 h-1.5 rounded-full shrink-0 ${q?`bg-emerald-500`:`bg-stone-300`}`,"data-hint":q?`Runner 在线`:`Runner 离线`}),(0,Z.jsx)(Vl,{className:`tw-composer-bar-chevron w-3.5 h-3.5 shrink-0 text-stone-400 transition-transform group-data-[open]:rotate-180`})]}),(0,Z.jsxs)(T,{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,Z.jsx)(`div`,{className:`px-3 py-1.5 text-[11px] text-stone-400`,children:q?`本地文件服务已连接`:`本地文件服务未就绪`}),Nl.map(e=>{let t=wc&&e.value===`readonly`;return(0,Z.jsx)(E,{disabled:t,children:(0,Z.jsxs)(`button`,{type:`button`,disabled:t,onClick:()=>{Qt(e.value),Y.current&&X(z(Y.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,Z.jsx)(uu,{level:e.value,className:`w-4 h-4 shrink-0 ${t?`text-stone-300`:`text-stone-500`}`}),(0,Z.jsx)(`span`,{className:`flex-1 ${t?`text-stone-400`:Zt===e.value?`text-stone-900 font-medium`:`text-stone-700`}`,children:e.label}),t?(0,Z.jsx)(`span`,{className:`text-[11px] text-stone-400`,children:`插件开发需要写入`}):Zt===e.value?(0,Z.jsx)(Ul,{className:`w-3.5 h-3.5 text-[#4176e6]`}):null]})},e.value)})]})]}),(0,Z.jsx)(`span`,{className:`flex-1`}),(0,Z.jsx)(ju,{settings:t}),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>{Zr.current?ms():fs()},disabled:!ht&&!_c,"aria-label":ht?`停止生成`:`发送`,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 ${ht?`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:ht?(0,Z.jsx)(`span`,{className:`w-2.5 h-2.5 bg-current rounded-xs`}):(0,Z.jsx)(Yl,{className:`w-4 h-4`})})]})]}),(0,Z.jsx)(ku,{messages:c,model:t?.model,systemPromptTokens:hu(w)})]}),(0,Z.jsx)(`input`,{ref:Sa,type:`file`,multiple:!0,hidden:!0,accept:[...vc.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 cc(e)})]})]})]}),be?(0,Z.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,Z.jsx)(mr,{embedded:!0})}):null,(0,Z.jsx)(Uc,{open:ee,initial:j,presetStories:ie,onClose:()=>{te(!1),ae(null)},onConfirm:e=>ks(e)}),(0,Z.jsx)(Wc,{open:N,initial:oe,onClose:()=>P(!1),onConfirm:e=>As(e)}),(0,Z.jsx)(Gc,{open:le,initial:F,onClose:()=>ue(!1),onConfirm:e=>js(e)}),(0,Z.jsx)(Tr,{open:!!Se,title:`重命名会话`,label:`会话名称`,placeholder:`请输入会话名称`,initialValue:Se?a?.sessions.find(e=>e.id===Se)?.title??``:``,confirmLabel:`保存`,cancelLabel:`取消`,onClose:()=>Ee(null),onConfirm:rc}),(0,Z.jsx)(Tr,{open:!!Ue,title:`重命名工作区`,label:`显示名称`,placeholder:`请输入工作区名称`,initialValue:Ue?H?.items.find(e=>e.id===Ue)?.name??``:``,confirmLabel:`保存`,cancelLabel:`取消`,onClose:()=>st(null),onConfirm:e=>void wo(e)}),(0,Z.jsx)(Kc,{task:Ti,onClose:()=>Ei(null),onSave:es,onRemove:()=>{Ti&&ts(Ti.id)}}),(0,Z.jsx)(A,{open:!!ke,title:`删除会话`,message:ke?`确定永久删除「${a?.sessions.find(e=>e.id===ke)?.title??`该会话`}」?此操作不可恢复。`:``,confirmLabel:`删除`,cancelLabel:`取消`,danger:`outline`,onClose:()=>Ae(null),onConfirm:()=>{if(!ke)return;let e=ke;Ae(null),Zs(e)}}),(0,Z.jsx)(A,{open:!!Le,title:`删除工作区`,message:Le?`将把「${Le.name}」从工作区列表中移除。文件夹与会话记录会保留,其会话将归入项目根工作区。`:``,confirmLabel:`删除工作区`,cancelLabel:`取消`,danger:`outline`,onClose:()=>He(null),onConfirm:()=>void mo()})]})}export{Pu as default};
226
+ `,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 Bl(e,t,n,r){return e===`concise`?r===`running`?Et(`tool.running`):null:e===`standard`?Et(r===`running`?`tool.callingKind`:`tool.doneKind`,{kind:t}):Et(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,Z.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 Vl=({className:e=``})=>(0,Z.jsx)($,{className:e,children:(0,Z.jsx)(`path`,{d:`m6 9 6 6 6-6`})}),Hl=({className:e=``})=>(0,Z.jsx)($,{className:e,children:(0,Z.jsx)(`path`,{d:`m9 18 6-6-6-6`})}),Ul=({className:e=``})=>(0,Z.jsx)($,{className:e,children:(0,Z.jsx)(`path`,{d:`M20 6 9 17l-5-5`})}),Wl=({className:e=``})=>(0,Z.jsxs)($,{className:e,children:[(0,Z.jsx)(`rect`,{width:`14`,height:`14`,x:`8`,y:`8`,rx:`2`,ry:`2`}),(0,Z.jsx)(`path`,{d:`M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2`})]}),Gl=({className:e=``})=>(0,Z.jsxs)($,{className:e,children:[(0,Z.jsx)(`ellipse`,{cx:`12`,cy:`5`,rx:`9`,ry:`3`}),(0,Z.jsx)(`path`,{d:`M3 5v14a9 3 0 0 0 18 0V5`}),(0,Z.jsx)(`path`,{d:`M3 12a9 3 0 0 0 18 0`})]}),Kl=({className:e=``})=>(0,Z.jsxs)($,{className:e,children:[(0,Z.jsx)(`path`,{d:`m12 14 4-4`}),(0,Z.jsx)(`path`,{d:`M3.34 19a10 10 0 1 1 17.32 0`})]}),ql=({className:e=``})=>(0,Z.jsxs)($,{className:e,children:[(0,Z.jsx)(`path`,{d:`M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z`}),(0,Z.jsx)(`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`})]}),Jl=({className:e=``})=>(0,Z.jsx)($,{className:e,children:(0,Z.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`})}),Yl=({className:e=``})=>(0,Z.jsxs)($,{className:e,children:[(0,Z.jsx)(`path`,{d:`m5 12 7-7 7 7`}),(0,Z.jsx)(`path`,{d:`M12 19V5`})]}),Xl=({className:e=``,open:t=!1})=>(0,Z.jsx)($,{className:e,children:t?(0,Z.jsx)(Z.Fragment,{children:(0,Z.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,Z.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`})}),Zl=({className:e=``,open:t=!1})=>(0,Z.jsx)(`svg`,{className:`${e} tw-arrow ${t?`is-open`:``}`,viewBox:`0 0 12 12`,fill:`currentColor`,"aria-hidden":!0,children:(0,Z.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`})}),Ql=({className:e=``})=>(0,Z.jsxs)($,{className:e,children:[(0,Z.jsx)(`circle`,{cx:`11`,cy:`11`,r:`8`}),(0,Z.jsx)(`path`,{d:`m21 21-4.3-4.3`})]}),$l=({className:e=``})=>(0,Z.jsxs)($,{className:e,children:[(0,Z.jsx)(`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`}),(0,Z.jsx)(`path`,{d:`M12 8v8`}),(0,Z.jsx)(`path`,{d:`M8 12h8`})]}),eu=({className:e=``,filled:t=!1})=>(0,Z.jsx)($,{className:e,children:t?(0,Z.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,Z.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`})}),tu=({className:e=``})=>(0,Z.jsxs)($,{className:e,children:[(0,Z.jsx)(`circle`,{cx:`12`,cy:`12`,r:`1`,fill:`currentColor`,stroke:`none`}),(0,Z.jsx)(`circle`,{cx:`5`,cy:`12`,r:`1`,fill:`currentColor`,stroke:`none`}),(0,Z.jsx)(`circle`,{cx:`19`,cy:`12`,r:`1`,fill:`currentColor`,stroke:`none`})]}),nu=({className:e=``})=>(0,Z.jsxs)($,{className:e,children:[(0,Z.jsx)(`path`,{d:`M4 8h16v11a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V8Z`}),(0,Z.jsx)(`path`,{d:`M8 8V5a1 1 0 0 1 1-1h6a1 1 0 0 1 1 1v3`}),(0,Z.jsx)(`path`,{d:`M10 12h4`})]}),ru=({className:e=``})=>(0,Z.jsxs)($,{className:e,children:[(0,Z.jsx)(`path`,{d:`M12 22v-5`}),(0,Z.jsx)(`path`,{d:`M9 8V2`}),(0,Z.jsx)(`path`,{d:`M15 8V2`}),(0,Z.jsx)(`path`,{d:`M18 8v5a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V8Z`})]});function iu(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 au(e){let t=iu(e);return t===`刚刚`?`刚刚`:t.endsWith(`前`)?t:`${t}前`}function ou({open:e,onToggle:t,onRename:n,onDelete:r}){let i=(0,K.useRef)(null);return(0,Z.jsxs)(`div`,{className:`relative`,children:[(0,Z.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,Z.jsx)(tu,{className:`w-3.5 h-3.5`})}),(0,Z.jsxs)(su,{open:e,anchorRef:i,dataAttr:`data-ws-menu`,children:[(0,Z.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,Z.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Z.jsx)(`path`,{d:`M12 20h9`}),(0,Z.jsx)(`path`,{d:`M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z`})]}),`重命名`]}),r?(0,Z.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,Z.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Z.jsx)(`path`,{d:`M3 6h18`}),(0,Z.jsx)(`path`,{d:`M8 6V4h8v2`}),(0,Z.jsx)(`path`,{d:`M19 6l-1 14H6L5 6`})]}),`删除工作区`]}):null]})]})}function su({open:e,anchorRef:t,dataAttr:n,children:r}){let[i,a]=(0,K.useState)(null);return(0,K.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,Er.createPortal)((0,Z.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 cu({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,K.useRef)(null),m=(0,K.useRef)(null),h=(0,K.useRef)(null),g=(0,K.useRef)(null),_=(0,K.useRef)(null),v=(0,K.useRef)(null),[y,b]=(0,K.useState)(!1),[x,S]=(0,K.useState)(!1),[C,w]=(0,K.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 O(){E(),T(),_.current=setTimeout(()=>S(!0),1e3)}let k=e.title.trim()||`新对话`;(0,K.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,K.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,K.useEffect)(()=>{r&&(T(),E(),S(!1))},[r]);let A=i?`生成中`:`空闲`,ee=!!(e.archived||e.deleted);return(0,Z.jsxs)(`div`,{ref:p,className:`tw-session-row relative ${t?`is-nested`:``} ${n?`is-selected`:``} ${r?`is-menu-open`:``} ${i?`is-busy`:``} ${ee?`opacity-50`:``}`,onMouseLeave:()=>{T(),D()},children:[i?(0,Z.jsx)(`span`,{className:`tw-session-busy-slot`,"data-hint":`生成中`,"aria-label":`生成中`,children:(0,Z.jsx)(`span`,{className:`tw-session-busy-dot`,"aria-hidden":!0})}):null,e.pinned&&!ee?(0,Z.jsx)(`span`,{className:`tw-slot`,"aria-hidden":!0,children:(0,Z.jsx)(eu,{filled:!0,className:`tw-pin-indicator w-3 h-3`})}):null,(0,Z.jsx)(`button`,{ref:h,type:`button`,onClick:a,onDoubleClick:o,onMouseEnter:()=>O(),onMouseLeave:()=>{T(),D()},className:`tw-session-title text-left outline-none focus:outline-none focus-visible:outline-none ${y?`is-overflow`:``}`,children:(0,Z.jsx)(`span`,{ref:g,className:`tw-session-title-inner`,children:e.title})}),(0,Z.jsx)(`span`,{className:`tw-session-time pr-1`,children:iu(e.updatedAt)}),(0,Z.jsxs)(`div`,{"data-session-menu":``,className:`tw-row-actions items-center gap-0.5 shrink-0`,onClick:e=>e.stopPropagation(),children:[(0,Z.jsxs)(`div`,{className:`relative`,children:[(0,Z.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,Z.jsx)(tu,{className:`w-3.5 h-3.5`})}),(0,Z.jsx)(su,{open:r,anchorRef:m,dataAttr:`data-session-menu`,children:e.deleted?(0,Z.jsxs)(Z.Fragment,{children:[f?(0,Z.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,Z.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,Z.jsxs)(Z.Fragment,{children:[!e.archived&&(0,Z.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,Z.jsx)(eu,{filled:!!e.pinned,className:`w-3.5 h-3.5`}),e.pinned?`取消置顶`:`置顶会话`]}),(0,Z.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,Z.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Z.jsx)(`path`,{d:`M12 20h9`}),(0,Z.jsx)(`path`,{d:`M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z`})]}),`重命名`]}),(0,Z.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,Z.jsx)(nu,{className:`w-3.5 h-3.5`}),e.archived?`取消归档`:`归档会话`]}),(0,Z.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,Z.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Z.jsx)(`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`}),(0,Z.jsx)(`polyline`,{points:`7 10 12 15 17 10`}),(0,Z.jsx)(`line`,{x1:`12`,x2:`12`,y1:`15`,y2:`3`})]}),`导出会话`]}),e.archived?(0,Z.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,Z.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Z.jsx)(`path`,{d:`M3 6h18`}),(0,Z.jsx)(`path`,{d:`M8 6V4h8v2`}),(0,Z.jsx)(`path`,{d:`M19 6l-1 14H6L5 6`})]}),`永久删除`]}):null]})})]}),!e.deleted&&(0,Z.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,Z.jsx)(nu,{className:`w-3.5 h-3.5`})}),!e.archived&&!e.deleted&&(0,Z.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,Z.jsx)(eu,{filled:!!e.pinned,className:`w-3.5 h-3.5`})})]}),x&&!r&&C&&typeof document<`u`?(0,Er.createPortal)((0,Z.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,Z.jsx)(`div`,{className:`tw-session-preview-title`,children:k}),(0,Z.jsx)(`div`,{className:`tw-session-preview-meta`,children:au(e.updatedAt)}),(0,Z.jsx)(`div`,{className:`tw-session-preview-status ${i?`is-busy`:``}`,children:A})]}),document.body):null]})}var lu=`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 uu({level:e,className:t=``}){return(0,Z.jsxs)($,{className:t,children:[(0,Z.jsx)(`path`,{d:lu}),e===`readonly`&&(0,Z.jsx)(`path`,{d:`m9 12 2 2 4-4`}),e===`readwrite`&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`path`,{d:`M9 10h6`}),(0,Z.jsx)(`path`,{d:`M9 14h3`})]}),e===`full`&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`path`,{d:`M12 8v4`}),(0,Z.jsx)(`path`,{d:`M12 16h.01`})]})]})}function du(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function fu(e){return`${e.toLocaleString(`en-US`)} tok`}function pu(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 mu(e){return e>=99.95?`100`:e>=10?String(Math.round(e)):e.toFixed(1)}function hu(e){let t=0;for(let n of e)t+=/[\u4e00-\u9fff]/.test(n)?1:.25;return Math.max(1,Math.round(t))}function gu(e){return e.uncachedTokens==null?e.cachedTokens==null?e.promptTokens:Math.max(0,e.promptTokens-e.cachedTokens):e.uncachedTokens}function _u(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 vu(e,t){return t<=0?null:e/t*100}function yu(e){return e>=1024?`${(e/1024).toFixed(1)} KB`:`${e} B`}function bu(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 xu(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 Su({text:e}){let[t,n]=(0,K.useState)(!1),r=(0,K.useRef)(null);(0,K.useEffect)(()=>()=>{r.current!==null&&window.clearTimeout(r.current)},[]);async function i(){t||await xu(e)&&(n(!0),r.current=window.setTimeout(()=>n(!1),1e3))}return(0,Z.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,Z.jsx)(Ul,{className:`w-3.5 h-3.5 text-emerald-600`}):(0,Z.jsx)(Wl,{className:`w-3.5 h-3.5`})})}function Cu({pct:e}){return(0,Z.jsxs)(`svg`,{className:`w-3.5 h-3.5 -rotate-90`,viewBox:`0 0 20 20`,"aria-hidden":`true`,children:[(0,Z.jsx)(`circle`,{cx:`10`,cy:`10`,r:`8`,fill:`none`,stroke:`var(--color-stone-200)`,strokeWidth:`3`}),(0,Z.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 wu(){let[e,t]=(0,K.useState)(!1),n=(0,K.useRef)(null),r=(0,K.useRef)(null),[i,a]=(0,K.useState)(null);return(0,K.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,K.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 Tu({title:e,titleValue:t,icon:n,children:r}){return(0,Z.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,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-[13px]`,children:[n,(0,Z.jsx)(`span`,{className:`tw-popover-title font-medium text-stone-800`,children:e}),t!==void 0&&(0,Z.jsx)(`span`,{className:`tw-popover-muted ml-auto text-stone-500 tabular-nums`,children:t})]}),(0,Z.jsx)(`div`,{className:`mt-2.5 mb-2.5 border-t border-stone-100`}),r]})}function Eu({rows:e}){return(0,Z.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,Z.jsxs)(`div`,{className:`contents`,children:[(0,Z.jsx)(`dt`,{className:`text-stone-500`,children:e.label}),(0,Z.jsx)(`dd`,{className:`text-stone-800 tabular-nums text-right`,children:e.value})]},e.label))})}function Du({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}=wu();return(0,Z.jsxs)(`span`,{ref:l,className:`relative inline-flex items-center`,children:[(0,Z.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,Z.jsx)(`span`,{className:`leading-none`,children:e})]}),s&&(0,Er.createPortal)((0,Z.jsx)(`div`,{ref:u,role:`dialog`,"aria-label":r,style:d??{position:`fixed`,left:0,top:0,visibility:`hidden`},className:`z-80`,children:(0,Z.jsx)(Tu,{title:r,titleValue:i,icon:t,children:a})}),document.body)]})}function Ou({messages:e,busy:t,onRestoreCheckpoint:n}){let[r,i]=(0,K.useState)(()=>new Set),a=(0,K.useMemo)(()=>Qr(e.map(e=>({role:e.role,content:typeof e.content==`string`?e.content:Dl(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,Z.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,Z.jsxs)(`li`,{className:`rounded-xl border bg-white shadow-sm overflow-hidden ${i?`border-[#4176e6]/35`:`border-stone-200`}`,children:[(0,Z.jsxs)(`div`,{className:`flex items-start gap-1 px-3 py-2.5`,children:[(0,Z.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,Z.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,Z.jsxs)(`span`,{className:`text-[11px] font-medium text-stone-400 tabular-nums`,children:[`第 `,e.index,` 轮`]}),(0,Z.jsx)(Vl,{className:`w-3.5 h-3.5 text-stone-400 ml-auto shrink-0 transition-transform ${i?`rotate-180`:``}`})]}),i?null:(0,Z.jsxs)(`div`,{className:`space-y-1 text-[13px] leading-5`,children:[(0,Z.jsxs)(`p`,{className:`m-0 text-stone-800 truncate`,children:[(0,Z.jsx)(`span`,{className:`text-stone-400 mr-1.5`,children:`用户`}),e.userPreview]}),(0,Z.jsxs)(`p`,{className:`m-0 text-stone-600 truncate`,children:[(0,Z.jsx)(`span`,{className:`text-stone-400 mr-1.5`,children:`助手`}),e.assistantPreview||`(待回复)`]})]})]}),n?(0,Z.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,Z.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,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`div`,{className:`text-[11px] font-medium text-stone-400 mb-0.5`,children:`用户`}),(0,Z.jsx)(`div`,{className:`whitespace-pre-wrap break-words text-stone-800`,children:e.userText||`—`})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`div`,{className:`text-[11px] font-medium text-stone-400 mb-0.5`,children:`助手`}),e.assistantText?(0,Z.jsx)(`div`,{className:`chat-md prose prose-sm prose-stone max-w-none tw-chat-text`,dangerouslySetInnerHTML:{__html:Dt(e.assistantText)}}):(0,Z.jsx)(`div`,{className:`text-stone-400`,children:`(待回复)`})]})]}):null]},e.index)})}):(0,Z.jsx)(`div`,{className:`h-full flex items-center justify-center text-sm text-stone-400`,children:`暂无回合(还没有用户/助手对话)`})}function ku({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?gu(t.usage):0),0),d=r.reduce((e,t)=>e+(t.usage?.cacheWriteTokens??0),0),f=r.reduce((e,t)=>e+_u(t.usage),0),p=r.some(e=>e.usage?.cachedTokens!=null),m=p?vu(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?R[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,Z.jsxs)(`div`,{className:`flex items-center justify-center gap-1 pt-2 text-xs text-stone-400 tabular-nums select-none`,children:[(0,Z.jsx)(Du,{icon:(0,Z.jsx)(Kl,{className:`w-3.5 h-3.5`}),label:(0,Z.jsxs)(Z.Fragment,{children:[a,` 轮 `,o,` 步`,S?` · ${Math.round(S)} tok/s`:``]}),ariaLabel:`会话统计`,title:`会话统计`,children:(0,Z.jsx)(Eu,{rows:[{label:`模型用时`,value:h>0?pu(h):`—`},{label:`工具调用用时`,value:g>0?pu(g):`—`},{label:`首 token 平均 (TTFT)`,value:_.length?pu(v):`—`},{label:`输出速度 (TPS)`,value:S?`${Math.round(S)} tok/s`:`—`}]})}),(0,Z.jsx)(Du,{icon:(0,Z.jsx)(Gl,{className:`w-3.5 h-3.5`}),label:(0,Z.jsxs)(Z.Fragment,{children:[du(s),` tok`,m==null?``:` · 缓存命中 ${mu(m)}%`]}),ariaLabel:`Token 用量`,title:`Token 用量`,titleValue:fu(s),children:(0,Z.jsx)(Eu,{rows:[{label:`缓存命中`,value:m==null?`—`:`${mu(m)}%`,hide:m==null},{label:`未缓存输入`,value:fu(u)},{label:`缓存读取`,value:fu(l),hide:!p},{label:`缓存写入`,value:fu(d),hide:d<=0},{label:`输出`,value:fu(f)}]})}),T!==void 0&&C&&(0,Z.jsxs)(Du,{icon:(0,Z.jsx)(Cu,{pct:T}),label:`${mu(T)}%`,ariaLabel:`上下文占用`,title:`上下文已用 ${mu(T)}%`,titleValue:`~${du(w)} / ${du(C)}`,children:[(0,Z.jsxs)(`div`,{className:`h-2 rounded-full bg-stone-100 overflow-hidden flex mb-3`,children:[(0,Z.jsx)(`span`,{className:`h-full bg-stone-400`,style:{width:`${E/C*100}%`},"data-hint":`系统提示词`}),(0,Z.jsx)(`span`,{className:`h-full bg-[#4176e6]`,style:{width:`${D/C*100}%`},"data-hint":`对话消息`})]}),(0,Z.jsx)(Eu,{rows:[{label:`系统提示词`,value:`~${du(E)}`},{label:`对话消息`,value:`~${du(D)}`}]}),(0,Z.jsx)(`p`,{className:`mt-2.5 text-[11px] leading-4 text-stone-400`,children:`分段为示意估算(API 不返回上下文拆分);总量以最近一轮 prompt_tokens 为准。`})]})]})}function Au({usage:e,model:t}){let n=e.cachedTokens==null?null:vu(e.cachedTokens,e.promptTokens);return(0,Z.jsx)(Du,{variant:`ghost`,icon:(0,Z.jsx)(Gl,{className:`w-3.5 h-3.5 shrink-0`}),label:(0,Z.jsxs)(Z.Fragment,{children:[`用量 `,du(e.totalTokens),` tok`]}),ariaLabel:`本轮用量`,title:`本轮用量`,titleValue:fu(e.totalTokens),children:(0,Z.jsx)(Eu,{rows:[{label:`提供方 / 模型`,value:t??`—`,hide:!t},{label:`缓存命中`,value:n==null?`—`:`${mu(n)}%`,hide:n==null},{label:`未缓存输入`,value:fu(gu(e))},{label:`缓存读取`,value:fu(e.cachedTokens??0),hide:e.cachedTokens==null},{label:`缓存写入`,value:fu(e.cacheWriteTokens??0),hide:!(e.cacheWriteTokens&&e.cacheWriteTokens>0)},{label:`输出`,value:fu(e.completionTokens)}]})})}function ju({settings:e}){let[t,n]=(0,K.useState)(!1),[r,i]=(0,K.useState)(null),[a,o]=(0,K.useState)([]),[s,c]=(0,K.useState)(`idle`),l=(0,K.useRef)(null),u=(0,K.useRef)(0);if((0,K.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,K.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;_e(e.baseURL,e.apiKey).then(t=>{if(r!==u.current)return;let n=t.length?t:[e.model];o(n),c(`ok`),t.length&&Le({availableModels:t})}).catch(()=>{r===u.current&&c(n.length>1?`ok`:`fail`)})},[t,e]),!e)return(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>ze(`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,Z.jsx)(`span`,{className:`whitespace-nowrap`,children:`配置模型`}),(0,Z.jsx)(Vl,{className:`w-3.5 h-3.5 shrink-0 text-stone-400`})]});let d=e.reasoningEffort??`high`,f=Ml.find(e=>e.value===d)?.label??`High`;function p(e){Le(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,Z.jsxs)(`div`,{ref:l,className:`relative`,children:[(0,Z.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,Z.jsx)(`span`,{className:`tw-composer-bar-model-name max-w-40 truncate text-stone-600`,children:e.model}),(0,Z.jsx)(`span`,{className:`tw-composer-bar-effort whitespace-nowrap text-stone-400`,children:f}),(0,Z.jsx)(Vl,{className:`w-3.5 h-3.5 shrink-0 text-stone-400 transition-transform ${t?`rotate-180`:``}`})]}),t&&(0,Z.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,Z.jsxs)(`button`,{type:`button`,onMouseEnter:()=>i(`model`),onClick:()=>i(`model`),className:m(r===`model`),children:[(0,Z.jsx)(`span`,{className:`text-stone-700`,children:`模型`}),(0,Z.jsx)(`span`,{className:`ml-auto max-w-32 truncate text-stone-400`,children:e.model}),(0,Z.jsx)(Hl,{className:`w-3.5 h-3.5 text-stone-400`})]}),(0,Z.jsxs)(`button`,{type:`button`,onMouseEnter:()=>i(`effort`),onClick:()=>i(`effort`),className:m(r===`effort`),children:[(0,Z.jsx)(`span`,{className:`text-stone-700`,children:`推理等级`}),(0,Z.jsx)(`span`,{className:`ml-auto text-stone-400`,children:f}),(0,Z.jsx)(Hl,{className:`w-3.5 h-3.5 text-stone-400`})]}),r===`model`&&(0,Z.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,Z.jsx)(`div`,{className:`px-3 py-2 text-xs text-stone-400`,children:`正在识别可用模型…`}),a.map(t=>(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>p({model:t}),className:m(!1),children:[(0,Z.jsx)(`span`,{className:`flex-1 truncate ${t===e.model?`text-stone-900 font-medium`:`text-stone-600`}`,children:t}),t===e.model&&(0,Z.jsx)(Ul,{className:`w-3.5 h-3.5 text-[#4176e6]`})]},t)),(0,Z.jsx)(`div`,{className:`mt-1 border-t border-stone-100 pt-1`,children:(0,Z.jsx)(`button`,{type:`button`,onClick:()=>{n(!1),i(null),ze(`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,Z.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:Ml.map(e=>(0,Z.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,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-[13px]`,children:[(0,Z.jsx)(`span`,{className:`flex-1 ${d===e.value?`text-stone-900 font-medium`:`text-stone-600`}`,children:e.label}),d===e.value&&(0,Z.jsx)(Ul,{className:`w-3.5 h-3.5 text-[#4176e6]`})]}),(0,Z.jsx)(`div`,{className:`mt-0.5 text-xs text-stone-400`,children:e.desc})]},e.value))})]})]})}var Mu=null;function Nu(){if(!Mu){let e=st();Mu={store:e,messages:e.sessions.find(t=>t.id===e.activeId)?.messages??[]}}return Mu}function Pu({slashDocs:e=[]}){let[t,n]=(0,K.useState)(null),[r,i]=(0,K.useState)(!1),[a,o]=(0,K.useState)(()=>Nu().store),[c,l]=(0,K.useState)(()=>Nu().messages),[u,d]=(0,K.useState)(()=>Tt(Nu().store.activeId??``)),[f,m]=(0,K.useState)([]),[b,x]=(0,K.useState)([]),[S,C]=(0,K.useState)([]),[w,k]=(0,K.useState)(Sl),[ee,te]=(0,K.useState)(!1),[j,ne]=(0,K.useState)(null),re=(0,K.useRef)(null);re.current=j;let[ie,ae]=(0,K.useState)(null),[N,P]=(0,K.useState)(!1),[oe,se]=(0,K.useState)(null),ce=(0,K.useRef)(null);ce.current=oe;let[le,ue]=(0,K.useState)(!1),[F,de]=(0,K.useState)(null),fe=(0,K.useRef)(null);fe.current=F;let[I,L]=(0,K.useState)(null),pe=(0,K.useRef)(null);pe.current=I;let me=(0,K.useRef)(null),[he,_e]=(0,K.useState)(null),[ve,R]=(0,K.useState)(0),[be,xe]=(0,K.useState)(!1),[Se,Ee]=(0,K.useState)(null),[ke,Ae]=(0,K.useState)(null),[je,Me]=(0,K.useState)(null),[Le,He]=(0,K.useState)(null),[Ue,st]=(0,K.useState)(null),[ht,gt]=(0,K.useState)(!1),[_t,vt]=(0,K.useState)([]),[Ot,Bt]=(0,K.useState)(null),[Yt,Xt]=(0,K.useState)(`error`);function B(e,t=`error`){Xt(t),Bt(e)}let[Zt,Qt]=(0,K.useState)(`readonly`),[$t,en]=(0,K.useState)(!1),[tn,nn]=(0,K.useState)(!0),[rn,an]=(0,K.useState)(!1),[V,on]=(0,K.useState)(()=>p()),[sn,cn]=(0,K.useState)(``),[ln,un]=(0,K.useState)(null),[dn,fn]=(0,K.useState)(null),[pn,mn]=(0,K.useState)(!1),[hn,gn]=(0,K.useState)(null),[_n,vn]=(0,K.useState)(null),[yn,bn]=(0,K.useState)(null),[H,Sn]=(0,K.useState)(null),[Cn,wn]=(0,K.useState)(!1),[Tn,En]=(0,K.useState)({}),[Dn,On]=(0,K.useState)(``),[kn,An]=(0,K.useState)(!1),[jn,U]=(0,K.useState)(null),[W,Mn]=(0,K.useState)(()=>y(El,Tl,`dialog`)),[Pn,Vn]=(0,K.useState)(()=>typeof window>`u`?{language:`zh-CN`,appearance:`system`,sessionFontSize:14,toolStepDetail:`standard`,busySendBehavior:`queue`,subagentModel:``}:Ve()),[Gn,Kn]=(0,K.useState)(!1),[$n,G]=(0,K.useState)(null),[tr,rr]=(0,K.useState)(0),[ir,or]=(0,K.useState)(!1),[sr,cr]=(0,K.useState)(!1),[lr,ur]=(0,K.useState)(!1),[dr,pr]=(0,K.useState)(!0),[hr,gr]=(0,K.useState)([]),[xr,Sr]=(0,K.useState)([]),Cr=!!(V.memory&&ln?.ok),wr=!!V.knowledge,Er=!!yn?.ok,q=!!dn?.ok,Mr=pn&&!q,Nr=!!hn?.ok,Lr=!!(_n?.ok&&_n.available),Vr=(0,K.useRef)(null),Hr=(0,K.useRef)(new Map),Ur=(0,K.useRef)(null),Wr=(0,K.useRef)(new Map),Gr=(0,K.useRef)(new Map),qr=(0,K.useRef)(new Map),Xr=(0,K.useRef)(null),Zr=(0,K.useRef)(!1),Qr=(0,K.useRef)(null),ei=(0,K.useRef)(null),[ti,ii]=(0,K.useState)([]),[ai,ci]=(0,K.useState)(null),li=(0,K.useRef)(null),ui=(0,K.useRef)(0),fi=(0,K.useRef)(new Set),[mi,hi]=(0,K.useState)(`off`),[gi,yi]=(0,K.useState)(null),[bi,Si]=(0,K.useState)(`day`),[Ci,wi]=(0,K.useState)([]),[Ti,Ei]=(0,K.useState)(null),[Di,ki]=(0,K.useState)(null),[Ai,ji]=(0,K.useState)(null),[Pi,Fi]=(0,K.useState)({}),[Li,Ri]=(0,K.useState)(0),[zi,Bi]=(0,K.useState)(!1),[Vi,Ui]=(0,K.useState)(null),[Wi,Gi]=(0,K.useState)(!1),[Ki,qi]=(0,K.useState)(``),[Ji,Yi]=(0,K.useState)(null),[Qi,$i]=(0,K.useState)(!1),ta=(0,K.useRef)(null),ra=(0,K.useRef)(null);function ia(){ra.current!==null&&(window.clearTimeout(ra.current),ra.current=null)}function sa(){ia(),$i(!1)}function ca(e,t,n={}){return new Promise(r=>{ta.current?.(null),ta.current=r,sa(),Yi({kind:e,items:t,quick:n.quick,quickNote:n.quickNote})})}function la(e){let t=ta.current;ta.current=null,$i(!0),ia(),ra.current=window.setTimeout(()=>{ra.current=null,Yi(null),$i(!1)},160),t?.(e)}let ua=(0,K.useRef)(()=>{});ua.current=()=>la(null),(0,K.useEffect)(()=>{if(!Ji||Qi)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`)||ua.current())};return document.addEventListener(`pointerdown`,e,!0),()=>document.removeEventListener(`pointerdown`,e,!0)},[Ji,Qi]);function da(e){ur(!1),V[e===`todo`?`todos`:`tasks`]&&(sa(),Yi({kind:e,manual:!0,items:[cl(e)]}))}async function fa(e,t){let n=e===`todo`?`待办`:`任务`;try{e===`todo`?await Nn(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 xn(t.map(e=>({title:e.title.trim(),status:e.status,priority:e.priority,startDate:e.startDate,dueDate:e.dueDate,note:e.note})),{mode:`manual`}),B(`已新增 ${t.length} 条${n},可在侧栏「${n===`待办`?`待办事项`:`任务管理`}」查看。`,`ok`)}catch(e){Xt(`error`),B(e instanceof Error?e.message:String(e))}}(0,K.useEffect)(()=>()=>{ta.current?.(null),ta.current=null,ra.current!==null&&(window.clearTimeout(ra.current),ra.current=null)},[]);let J=(0,K.useRef)([]),_a=(0,K.useRef)(null);function va(e){J.current=e,gr(e)}function ya(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 ba=(0,K.useRef)(null),xa=(0,K.useRef)(null),Sa=(0,K.useRef)(null),Ca=(0,K.useRef)(null),wa=(0,K.useRef)(null),Ta=(0,K.useRef)(null),Ea=(0,K.useRef)(null),Da=(0,K.useRef)(null),Oa=(0,K.useRef)({}),ka=!!(q&&H?.workspace),ja=bl(u),Ma=(()=>{if(!ja||!wr)return[];let t=ja.query.toLowerCase();return(t?e.filter(e=>sc(e,t)):e).slice(0,10)})(),Pa=(()=>{if(!ja||!ka)return[];let e=ja.query.toLowerCase(),t=xr.map(e=>({collection:`workspace`,id:`ws:${e.path}`,title:e.name,category:Jt(H?.workspace,H?.projectRoot),description:e.path,format:e.type===`dir`?`dir`:`file`,path:e.path}));return(e?t.filter(t=>sc(t,e)||t.path.toLowerCase().includes(e)||t.title.toLowerCase().includes(e)):t).slice(0,10)})(),Fa=[...Ma.map(e=>({section:`project`,doc:e})),...Pa.map(e=>({section:`workspace`,doc:e}))],Ia=!(!ja||ir),La=yl(u),Ra=_.filter(e=>e.hasPanel&&V[e.id]),Ba=!!(La&&!sr&&!Ia&&Ra.length>0),Va=(0,K.useRef)(!0),Ha=(0,K.useRef)(!1),Y=(0,K.useRef)(null),Ua=(0,K.useRef)(null),Ka=(0,K.useRef)([]);Ka.current=c;let qa=(0,K.useRef)(u);qa.current=u,Ua.current=H,(0,K.useEffect)(()=>{let e=a?.activeId;if(!e)return;let t=window.setTimeout(()=>bt(e,u),400);return()=>window.clearTimeout(t)},[u,a?.activeId]),(0,K.useEffect)(()=>{let e=()=>{let e=Y.current?.activeId;e&&bt(e,qa.current)},t=()=>{document.visibilityState===`hidden`&&e()};return window.addEventListener(`pagehide`,e),document.addEventListener(`visibilitychange`,t),()=>{window.removeEventListener(`pagehide`,e),document.removeEventListener(`visibilitychange`,t)}},[]);function X(e){Y.current=e,o(e),dt(e)}let Ja=a?.sessions.find(e=>e.id===a.activeId),Ya=Ja?.id,$a=Ja?.access;(0,K.useEffect)(()=>{Ya&&Qt($a??Re())},[Ya,$a]),(0,K.useEffect)(()=>{let e=!1,t=Fe(()=>n(Ie())),r=h(e=>on(e)),a=Pe(e=>{Vn(e),Be(e)});return(async()=>{if(await s(),e)return;let t=Ve();Vn(t),Be(t),n(Ie()),Qt(Re()),on(p()),nn($e());let r=new URLSearchParams(window.location.search),a=r.get(`session`),c=await ut({preferSessionId:a});if(e)return;let u=c;if(a&&!u.sessions.some(e=>e.id===a))try{let e=sessionStorage.getItem(at(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 rt(u))}}catch{}if(a)try{sessionStorage.removeItem(at(a))}catch{}let f=r.get(`focusRoot`),m=r.get(`focusPath`),h=r.get(`attachRoot`),_=r.get(`attachPath`),v=r.get(`attachName`),y=null;if(f&&m)try{y=`${f}:${decodeURIComponent(m).replace(/\\/g,`/`).replace(/^\/+/,``)}`}catch{y=`${f}:${m}`}if(a&&u.sessions.some(e=>e.id===a)&&(u=Ke(u,a),dt(u)),y&&_e(y),h&&_){let e=h;if(e===`cases`||e===`prompts`||e===`knowledge`||e===`templates`){let t=_,n=v||``;try{t=decodeURIComponent(_).replace(/\\/g,`/`).replace(/^\/+/,``),v&&(n=decodeURIComponent(v))}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 b=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 x=[];try{x=(await Or()).map(e=>e.sessionId)}catch{x=[]}let S=new Set(x);u=S.size?{...u,sessions:u.sessions.map(e=>{if(S.has(e.id))return e;let t=mt(e.messages);return t===e.messages?e:{...e,messages:t}})}:Xe(u);let w=Re();u.sessions.some(e=>!e.access)&&(u={...u,sessions:u.sessions.map(e=>e.access?e:{...e,access:w})}),Y.current=u,o(u),dt(u);let T=u.sessions.find(e=>e.id===u.activeId);if(l(T?.messages??[]),d(e=>e.trim()?e:Tt(u.activeId)),wi(wt(u.activeId)),ne(T?.caseGen?.active?T.caseGen:null),se(T?.promptGen?.active?T.promptGen:null),de(T?.knowledgeGen?.active?T.knowledgeGen:null),L(T?.pluginDev?.active?T.pluginDev:null),Qt(T?.access??w),T?.pluginDev?.active&&(yi(`pluginDev`),T.access!==`readwrite`&&T.access!==`full`)){Qt(`readwrite`);let e={...u,sessions:u.sessions.map(e=>e.id===u.activeId?{...e,access:`readwrite`}:e)};Y.current=e,o(e),dt(e)}ii(yo(T?.todos));{let e=Bo(T?.goal);li.current=e,ci(e)}(b===`day`||b===`week`||b===`month`)&&p().reports&&ls(b),T?.workspacePath&&En(e=>({...e,[T.workspacePath]:!0})),(T?.messages??[]).length||Mn(`dialog`),vt(x),i(!0),x.length&&queueMicrotask(()=>{for(let e of x)Fo(e,!0),e===Y.current?.activeId&&(Zr.current=!0,gt(!0),Yo(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(p()[n]){if(n===`pluginDev`)cs();else{let t=Y.current?.sessions.find(e=>e.id===Y.current?.activeId);if((!t||t.archived||t.deleted||Array.isArray(t.messages)&&t.messages.length>0||t.caseGen?.active||t.promptGen?.active||t.knowledgeGen?.active)&&Y.current){let e=Y.current.activeId,t=To(e)??Y.current,n=H?.workspace?.trim()||void 0,r=ot(t,{workspacePath:n,access:Re()});Y.current=r,o(r),dt(r),l([]),ne(null),se(null),de(null),ii([]),li.current=null,ci(null),hi(`off`)}if(n===`promptGen`)P(!0);else if(n===`knowledgeGen`)ue(!0);else{let t=e.searchParams.get(`reqDoc`);t&&(ae({docId:t,storyIds:(e.searchParams.get(`stories`)??``).split(`,`).map(e=>e.trim()).filter(Boolean)}),e.searchParams.delete(`reqDoc`),e.searchParams.delete(`stories`)),te(!0)}}}else B(g(n));e.searchParams.delete(`plugin`),window.history.replaceState({},``,e.pathname+e.search+e.hash)}}catch{}(async()=>{try{if(!await we(`prompts`)){M(`提示词管理服务未就绪,系统提示词暂时用内置兜底。`,`error`);return}let e=(await Ce(`prompts`,Ne)).content.trim();e?k(e):M(`「提示词管理/${Ne}」是空的,系统提示词暂时用内置兜底。`,`error`)}catch{M(`没有读到「提示词管理/${Ne}」,系统提示词暂时用内置兜底。`,`error`)}})(),nr().then(e=>un(e)),Wt().then(e=>{fn(e),mn(!0)}),Ln().then(e=>gn(e)),Un().then(e=>vn(e)),Fn().then(e=>bn(e)),Mt().then(e=>{Sn(e),e?.workspace&&En(t=>({...t,[e.workspace]:!0}))})})(),()=>{e=!0,t(),r(),a()}},[]),(0,K.useEffect)(()=>{!V.memory&&W===`memory`&&Mn(`dialog`)},[V.memory,W]),(0,K.useEffect)(()=>{!V.todos&&W===`todos`&&Mn(`dialog`)},[V.todos,W]),(0,K.useEffect)(()=>{v(El,W)},[W]),(0,K.useEffect)(()=>{if(!V.reports){cn(``);return}let e=!0;return(async()=>{try{await vr(!0);let t=await yr();e&&cn(t),t||M(`工作汇报提示词没读到(提示词管理里为空或缺失),汇报不会注入提示词。`,`error`)}catch(e){let t=e instanceof Error?e.message:String(e);M(`读取工作汇报提示词失败:${t}`,`error`)}})(),()=>{e=!1}},[V.reports]),(0,K.useEffect)(()=>{if(!r)return;let e=!1,t=async()=>{if(!Y.current)return;let t=await xs();if(e||!Y.current)return;let n=Y.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:ys(e.text,e.id),time:Date.now(),scheduleId:e.id};n=ct(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 Ze();if(!e&&Y.current){if(i){let e=it(n,i);e!==n&&(n=e,n.activeId&&(r=!0))}if((n!==Y.current||t.length)&&X(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,K.useEffect)(()=>{if(!r||!q||!H)return;let e=a?.sessions.find(e=>e.id===a.activeId);uo(e)},[r,q,a?.activeId,H?.items]),(0,K.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,K.useEffect)(()=>{rr(0),or(!1)},[ja?.query,ja?.from]),(0,K.useEffect)(()=>{cr(!1),R(0)},[La?.from]),(0,K.useEffect)(()=>{R(e=>Ra.length?Math.min(e,Ra.length-1):0)},[Ra.length]),(0,K.useEffect)(()=>{if(!Ia||!ka){ka||Sr([]);return}let e=!1;return Kt(Zt,{maxDepth:3,maxEntries:80}).then(t=>{e||Sr(t)}),()=>{e=!0}},[Ia,ka,Zt,H?.workspace]),(0,K.useEffect)(()=>{if(!Ia)return;let e=Ca.current;e&&e.querySelector(`[data-mention-index="${tr}"]`)?.scrollIntoView({block:`nearest`})},[tr,Ia,Fa.length]),(0,K.useEffect)(()=>{if(!Ba)return;let e=wa.current;e&&e.querySelector(`[data-plugin-index="${ve}"]`)?.scrollIntoView({block:`nearest`})},[ve,Ba,Ra.length]),(0,K.useEffect)(()=>{if(!Ia&&!Ba&&!lr)return;function e(e){let t=e.target;Ca.current?.contains(t)||wa.current?.contains(t)||Ta.current?.contains(t)||xa.current?.contains(t)||e.target?.closest?.(`[data-add-menu-btn]`)||(or(!0),cr(!0),ur(!1))}return document.addEventListener(`pointerdown`,e,!0),()=>document.removeEventListener(`pointerdown`,e,!0)},[Ia,Ba,lr]),(0,K.useEffect)(()=>{if(!Ot||Yt!==`ok`)return;function e(e){let t=e.target;Ea.current?.contains(t)||B(null)}let t=window.setTimeout(()=>{document.addEventListener(`pointerdown`,e,!0)},0);return()=>{window.clearTimeout(t),document.removeEventListener(`pointerdown`,e,!0)}},[Ot,Yt]),(0,K.useEffect)(()=>{if(!jn&&!je)return;function e(e){let t=e.target;t?.closest?.(`[data-session-menu]`)||t?.closest?.(`[data-ws-menu]`)||(U(null),Me(null))}return document.addEventListener(`pointerdown`,e,!0),()=>document.removeEventListener(`pointerdown`,e,!0)},[jn,je]);function eo(){nr().then(e=>un(e)),Wt().then(e=>{fn(e),mn(!0)}),Ln().then(e=>gn(e)),Un().then(e=>vn(e)),Fn().then(e=>bn(e)),Mt().then(e=>Sn(e))}function to(e){Sn(e),En(t=>({...t,[e.workspace]:!0}))}async function io(e,t=`select`){if(q&&!Cn){wn(!0),B(null);try{to(t===`add`?await At(e):await qt(e))}catch(e){B(e instanceof Error?e.message:String(e))}finally{wn(!1)}}}function oo(e){let t=Ua.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 uo(e){if(!q||Cn)return;let t=oo(e);if(!t)return;let n=Ua.current;if(n&&t!==n.workspace){wn(!0);try{to(await qt(t))}catch{}finally{wn(!1)}}}async function fo(e){if(!q||Cn)return;await io(e.path,`select`);let t=Y.current;if(!t)return;let n=t.sessions.find(e=>e.id===t.activeId);n&&!n.workspacePath&&((n.messages??[]).length>0||(X(Ye(t,n.id,e.path)),En(t=>({...t,[e.path]:!0}))))}async function po(){if(q&&!Cn){wn(!0),B(null);try{let e=await Pt();if(!e)return;to(await At(e))}catch(e){B(e instanceof Error?e.message:String(e))}finally{wn(!1)}}}async function mo(){let e=Le;if(e&&q&&!Cn){if(e.id===`ws_project`)He(null);else{He(null),Me(null),wn(!0),B(null);try{Y.current&&X(ft(Y.current,e.path));let t=await Ht(e.id);to(t),t.projectRoot&&En(e=>({...e,[t.projectRoot]:!0}))}catch(e){B(e instanceof Error?e.message:String(e))}finally{wn(!1)}}}}function go(e){q&&!Cn&&e.id!==`ws_project`&&(U(null),Me(null),He(e))}async function wo(e){let t=Ue;if(st(null),t&&q){wn(!0),B(null);try{to(await zt(t,e))}catch(e){B(e instanceof Error?e.message:String(e))}finally{wn(!1)}}}function To(e){if(!e||!Y.current)return Y.current;let t=Y.current.sessions.find(t=>t.id===e);if(!t||!Qe(t))return Y.current;let n=Oa.current[e];return n&&(n.input?.trim()||(n.attachments?.length??0)>0||(n.images?.length??0)>0||(n.docRefs?.length??0)>0)?Y.current:(delete Oa.current[e],Ct(e),lt(Y.current,e))}function Oo(e){ja&&(e.collection!==`workspace`&&!wr?B(g(`knowledge`)):S.length>=Cl?B(`最多引用 ${Cl} 篇文档`):(B(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,Cl)),d(u.slice(0,ja.from).replace(/\s+$/,``)),or(!0),xa.current?.focus()))}function ko(){La&&(d(u.slice(0,La.from).replace(/\s+$/,``)),cr(!0))}function Ao(e){if(!V[e])return B(g(e)),!1;if(B(null),e===`caseGen`)return te(!0),!0;if(e===`promptGen`)return P(!0),!0;if(e===`knowledgeGen`)return ue(!0),!0;if(e===`pluginDev`)return cs(),!0;if(e===`memory`)return Mn(`memory`),!0;if(e===`knowledge`){let e=u.replace(/\s+$/,``);return d(e?`${e} @`:`@`),or(!1),requestAnimationFrame(()=>xa.current?.focus()),!0}return!1}function jo(e){ko(),Ao(e)}function Mo(){let e=ba.current;if(!e)return;let t=e.scrollHeight-e.clientHeight-e.scrollTop<=48;if(Ha.current){if(!t)return;Ha.current=!1}Va.current=t,en(!t)}function Po(){let e=ba.current;e&&(Va.current=!0,Ha.current=!0,en(!1),e.scrollTo({top:e.scrollHeight,behavior:`smooth`}))}(0,K.useEffect)(()=>{if(!r||!Y.current)return;let e=Y.current.sessions.find(e=>e.id===Y.current.activeId)?.messages??[],t=JSON.stringify(e)!==JSON.stringify(c),n=qe(Y.current,c,{touchUpdatedAt:t});Y.current=n,o(n),dt(n),Va.current&&!Ha.current&&ba.current?.scrollTo({top:ba.current.scrollHeight})},[c,r]),(0,K.useEffect)(()=>{let e=()=>{Y.current&&dt(Y.current)};return window.addEventListener(`pagehide`,e),()=>window.removeEventListener(`pagehide`,e)},[]),(0,K.useLayoutEffect)(()=>{let e=xa.current;e&&(e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,280)}px`)},[u]),(0,K.useEffect)(()=>{if(!r||!he||!c.length)return;let e=he,t=window.setTimeout(()=>{let t=(ba.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)),_e(null)},80);return()=>window.clearTimeout(t)},[r,he,c]);function Fo(e,t){vt(n=>{let r=n.includes(e);return t&&!r?[...n,e]:!t&&r?n.filter(t=>t!==e):n}),Y.current?.activeId===e&&(Zr.current=t,gt(t))}function Ro(e){e&&(Hr.current.get(e)?.abort.abort(),Wr.current.get(e)?.(),Wr.current.delete(e),Ar(e))}function Go(e,t){if(t.type===`reasoning`&&t.delta)Xo(e,n=>{let r=n[n.length-1];if(r?.role!==`assistant`)return n;let i=ge((r.reasoning??``)+t.delta),a=[...r.activitySteps??[]],o=a.findIndex(e=>e.kind===`thinking`),s={id:`thinking`,kind:`thinking`,title:`思考`,detail:zl(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)Xo(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:ge((r.content??``)+t.delta),activitySteps:i,turnStatus:`running`,ttftMs:s},a});else if(t.type===`tool`&&t.name){let n=Pl(t.name),r=Rl(t.name,t.args),i=`tool_${t.name}_${t.args?.slice(0,24)??``}`;Qo(e,i,t.status);let a=t.status===`done`&&typeof t.result==`string`&&/^\s*\{\s*"error"\s*:/.test(t.result);Xo(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:Il(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}),Y.current?.activeId===e&&G(Bl(Ve().toolStepDetail,n,t.name,t.status===`running`?`running`:`done`))}else if(t.type===`usage`&&t.usage)Xo(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`)&&(Xo(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&&Y.current?.activeId===e&&B(Fl(t.error)),Hr.current.delete(e),Ur.current===e&&(Ur.current=null),Fo(e,!1),Y.current?.activeId===e&&G(null))}}function Yo(e,t=0){Wr.current.get(e)?.(),Fo(e,!0),(async()=>{let n=await jr(e),r=t;if(n?.ok&&n.assistant&&(r=Math.max(r,n.seq??0),Xo(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`)){Fo(e,!1);return}let i=Pr(e,r,{onEvent:t=>Go(e,t),onGaveUp:t=>{Y.current?.activeId===e&&B(t.message||`与服务端回合断开`),Fo(e,!1)}});Wr.current.set(e,i)})()}function Xo(e,t,n){let r=Hr.current.get(e),i=Y.current?.sessions.find(t=>t.id===e)?.messages??[],a=r?.messages??(Y.current?.activeId===e?Ka.current:i),o=typeof t==`function`?t(a):t;r&&(r.messages=o),Y.current?.activeId===e&&(Ka.current=o,l(o)),Y.current&&X(We(Y.current,e,o,{touchUpdatedAt:n?.touchUpdatedAt!==!1}))}function Zo(e){let t=Ur.current??Y.current?.activeId;t&&Xo(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 Qo(e,t,n){let r=`${e}:${t}`;if(n===`running`){Gr.current.set(r,Date.now());return}if(n!==`done`&&n!==`error`)return;let i=Gr.current.get(r);if(Gr.current.delete(r),i==null)return;let a=Math.max(0,Date.now()-i);Xo(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 $o(e){if(!e.length)return;let t=[],n=[],r=jl(f,b);for(let i of e)if(r+t.length>=6)n.push(`${i.name||`图片`}(最多 6 个文件)`);else try{t.push(await Al(i))}catch(e){n.push(e instanceof Error?e.message:String(e))}t.length&&x(e=>[...e,...t].slice(0,6)),B(n.length?`以下图片未添加:${n.join(`、`)}`:null)}function es(e){let t=Ti;if(!t)return;let n={...t,body:e,at:Date.now()};wi(e=>{let t=e.map(e=>e.id===n.id?n:e);return yt(Y.current?.activeId,t),t}),Ei(null)}function ts(e){xt(Y.current?.activeId,e),wi(t=>t.filter(t=>t.id!==e)),Ei(t=>t?.id===e?null:t)}function rs(){d(``),m([]),x([]),C([]),wi([]),yt(Y.current?.activeId,[]),or(!1),cr(!1)}function is(){if(gi===`plan`&&(Ps(),hi(`off`)),gi===`pluginDev`){L(null),pe.current=null,Y.current&&X(z(Y.current,{pluginDev:void 0}));let e=me.current;me.current=null,e===`readonly`&&(Qt(`readonly`),Y.current&&X(z(Y.current,{access:`readonly`})))}yi(null)}function as(){yi(`goal`),requestAnimationFrame(()=>xa.current?.focus())}function ss(){hi(e=>e===`off`?`planning`:e),yi(`plan`),requestAnimationFrame(()=>xa.current?.focus())}function cs(){q?(yi(`pluginDev`),Zt===`readonly`&&(me.current=`readonly`,Qt(`readwrite`),Y.current&&X(z(Y.current,{access:`readwrite`}))),requestAnimationFrame(()=>xa.current?.focus())):B(`本地文件服务未就绪:插件开发需要读写项目源码`)}function ls(e){Si(e),yi(`reports`),window.setTimeout(()=>xa.current?.focus(),400)}function us(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 ds(e){if(!t)return ze(`model`),!1;let n=us(Ka.current);if(n.length<4)return B(`对话轮次较少,无需压缩`),!1;G(`正在压缩上下文…`);try{let{messages:r,compacted:i}=await Io(t,n,{force:e.force,signal:e.signal});if(!i)return G(null),B(`当前上下文未超过阈值,未压缩`),!1;let a=Date.now(),o=r.map((e,t)=>({role:e.role,content:e.content,reasoning:e.reasoning,time:a+t}));return Ka.current=o,l(o),Y.current&&X(qe(Y.current,o,{touchUpdatedAt:!0})),G(null),!0}catch(e){return G(null),e instanceof DOMException&&e.name===`AbortError`||B(e instanceof Error?e.message:String(e)),!1}}async function fs(e,n){let r=e===void 0,i=r&&gi===`reports`?`生成${br[bi]}`:``,a=r?St(Ci):``,o=(e??u).trim()||i,s=a?o?`${o}\n\n${a}`:a:o,c=r?f:[],l=r?S:[],d=r?b:[];if(!s&&!c.length&&!l.length&&!d.length)return;if(!t){ze(`model`);return}if(r&&gi===`reports`&&yi(null),Lo(s)&&!c.length&&!l.length&&!d.length){if(Zr.current){B(`请等待当前回复结束后再压缩`);return}r&&rs(),await ds({force:!0})&&B(null);return}if(gi===`goal`&&s&&!c.length&&!l.length&&!d.length&&!Wo(s)&&!Lo(s)){r&&rs();let e={text:s.slice(0,500),status:`active`,updatedAt:Date.now()};li.current=e,ci(e),ui.current=0,Y.current&&X(z(Y.current,{goal:e})),yi(null),B(`已设定目标:${e.text}`);return}if(Wo(s)&&!c.length&&!l.length&&!d.length){let e=Uo(s);if(r&&rs(),!e)return;if(e.kind===`show`){let e=ai;B(e&&e.status!==`cleared`?`当前目标(${e.status}):${e.text}`:`当前无会话目标。可用 /goal set <内容> 设定`);return}if(e.kind===`clear`){li.current=null,ci(null),ui.current=0,Y.current&&X(z(Y.current,{goal:void 0})),B(`已清除会话目标`);return}if(e.kind===`done`){if(!ai?.text){B(`当前无目标可标记完成`);return}let e={...ai,status:`done`,updatedAt:Date.now()};li.current=e,ci(e),ui.current=0,Y.current&&X(z(Y.current,{goal:e})),B(`已标记目标完成:${e.text}`);return}if(e.kind===`set`&&e.text){let t={text:e.text.slice(0,500),status:`active`,updatedAt:Date.now()};li.current=t,ci(t),ui.current=0,Y.current&&X(z(Y.current,{goal:t})),B(`已设定目标:${t.text}`);return}return}if(gi===`pluginDev`&&s&&!c.length&&!l.length&&!d.length){if(Zr.current){B(`请等待当前回复结束后再开始插件开发`);return}await Os(s)}let p={id:`q_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,6)}`,content:s,files:[...c],refs:[...l],imgs:[...d]};if(Zr.current){let e=Ve().busySendBehavior??`queue`;if((n?.forceBusy??e)===`queue`){va([...J.current,p]),r&&rs();return}_a.current=p,r&&rs(),Ro(Y.current?.activeId)}else await ps(p)}async function ps(n){let r=Y.current?.activeId;if(!t||!r||Hr.current.has(r))return;let{content:i,files:a,refs:o,imgs:s}=n;qo(i)||(ui.current=0),B(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=Ka.current,f=d[d.length-1];f?.role===`assistant`&&!f.content&&!f.reasoning&&(d=d.slice(0,-1));let p=[...d,u],m=new AbortController;if(No(us(p),t.model)){G(`上下文较长,正在压缩…(可在右下角中断)`);try{let{messages:e,compacted:n}=await Io(t,us(p),{force:!1,signal:m.signal});if(n){let t=Date.now();p=e.map((e,n)=>({role:e.role,content:e.content,reasoning:e.reasoning,time:t+n})),Ka.current=p,l(p),Y.current&&X(qe(Y.current,p,{touchUpdatedAt:!0}))}}catch{}G(null)}let h=[...p,{role:`assistant`,content:``,time:c,turnStatus:`running`}];Ka.current=h,l(h),rs(),Ur.current=r,Hr.current.set(r,{abort:m,messages:h}),Vr.current=m,Fo(r,!0),Va.current=!0,en(!1);let g=di(p.map(e=>{let t={role:e.role,content:Ol(e)},n=(e.reasoningApi??e.reasoning)?.trim();return e.role===`assistant`&&n&&(t.reasoning_content=n),t}),{keepRecentImageMessages:1}),_=Cr,v=wr,y=q,b=Er,x=!!V.todos,S=!!V.tasks,C=!!V.projects,T=!!V.iterations,E=!!V.pmRequirements,D=!!V.bugs,O=mi===`planning`,k=V.pluginDev&&pe.current?.active?pe.current:null,A=k?Zt===`full`?`full`:`readwrite`:O?`readonly`:Zt,ee=Nr&&A!==`readonly`,te=Lr&&A!==`readonly`,j=Ua.current?.workspace?.trim()||``,M=j?`\n当前工作区:${j}`:``,ie=V.promptGen&&ce.current?.active?ce.current:null,ae=!ie&&V.knowledgeGen&&fe.current?.active?fe.current:null,N=!ie&&!ae&&V.caseGen&&re.current?.active?re.current:null,P=!!(ie||ae||N),oe=j,le=w;if(k)le=na(k,Ua.current?.harnessRoot||Ua.current?.projectRoot||j);else if(ie)le=Mi(ie);else if(ae)le=Xi(ae);else if(N){if(!N.promptBody?.trim()){B(`生成测试用例已启用,但未选择提示词。请打开插件重新「确认」。`),Hr.current.delete(r),Ur.current=null,Vr.current=null,Fo(r,!1),l(e=>e[e.length-1]?.role===`assistant`&&!e[e.length-1]?.content?e.slice(0,-1):e);return}try{le=_i(N,N.docTitle||N.reqPath?.split(`/`).pop()?.replace(/\.[^.]+$/,``)||``)}catch(e){B(e instanceof Error?e.message:String(e)),Hr.current.delete(r),Ur.current=null,Vr.current=null,Fo(r,!1);return}}if(!P){let e=sn;if(!k&&!e.trim()&&V.reports)try{await vr(!0),e=await yr()}catch{}!k&&e.trim()&&(le=`${le}\n\n${e.trim()}`);let t=ho({lastUserMessageAt:[...p].reverse().find(e=>e.role===`user`&&e!==p[p.length-1])?.time??[...p].reverse().find(e=>e.role===`user`)?.time??null,lastInjectAt:Xr.current});if(t.injected&&(Xr.current=t.at),le=`${le}\n\n${t.text}`,y)try{let e=await Vt();e?.text&&(le=`${le}\n\n${Gt}\n\n${e.text}`)}catch{}}let ue=vl(le,g,{memory:_&&!P,knowledge:v&&!P,fs:y&&!P,web:b&&!P,bash:ee&&!P,pwsh:te&&!P,interact:!P,todos:x&&!P,tasks:S&&!P,projects:C&&!P,iterations:T&&!P,pmRequirements:E&&!P,bugs:D&&!P,planPhase:P||k?`off`:mi,goalEnabled:!P,goal:ai,scheduleEnabled:!P,subagentEnabled:!P,workflowEnabled:!P}).map((e,t)=>t===0&&e.role===`system`&&y&&M&&!P?{...e,content:`${typeof e.content==`string`?e.content:``}${M}`}:e);if(_&&!P&&!k){G(`记忆注入中…`);let{context:e}=await er(i,{cwd:oe});if(e&&ue[0]?.role===`system`){let t=typeof ue[0].content==`string`?ue[0].content:``;ue=[{...ue[0],content:`${t}\n\n${e}`},...ue.slice(1)]}G(null)}let F=[];P||(v&&F.push(...lc),y&&(F.push(...Rt(A)),F.push(...Lt),F.push(...aa),F.push(...ao),F.push(oi),O||(F.push(ni),F.push(Ut))),ee&&(F.push(Jn),F.push(...Xn)),te&&(F.push(Yn),F.push(...In)),(ee||te)&&F.push(...Hn),b&&F.push(...Bn),_&&F.push(...fr),F.push(_o),x&&F.push(...Na),S&&F.push(...Xa),C&&F.push(...pa),T&&F.push(...ma),E&&F.push(...ha),D&&F.push(...ga),F.push(vo),F.push(...zo),F.push(...os),F.push(...Ts),F.push(...$s),(mi===`planning`||mi===`approved`)&&F.push(Eo));let I=Date.now(),L=0;qr.current.set(r,{start:I});let me=0,he=!1,_e=``,ve=!1,R,be=!!(ie||ae||N);function xe(e){return ie?Ni(e):ae?Zi(e):vi(e)}function Se(){return ie?`正在编写提示词…`:ae?`正在编写知识库…`:`正在编写用例…`}let Ce=!1;try{let n=``,a=``,o=``;if(be){G(Se());let e=()=>{let e=Math.max(0,Math.floor((Date.now()-I)/1e3));Zo(t=>({...t,content:xe(e)}))};e(),R=window.setInterval(e,1e3)}if(!(x||S||C||T||E||D)&&!be&&!k&&await Dr(m.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 kr({sessionId:r,messages:ue,settings:{baseURL:t.baseURL,apiKey:t.apiKey,model:t.model,reasoningEffort:t.reasoningEffort},tools:e,thinking:!0,workspace:j||``,access:A})).ok&&(Ce=!0,await new Promise(e=>{let t=!1,n=()=>{t||(t=!0,e())},i=()=>{Ar(r)};m.signal.addEventListener(`abort`,i),Wr.current.get(r)?.();let a=Pr(r,0,{signal:m.signal,onEvent:e=>Go(r,e),onTerminal:e=>{ve=e.status===`completed`,m.signal.removeEventListener(`abort`,i),Wr.current.delete(r),n()},onGaveUp:e=>{Y.current?.activeId===r&&B(e.message||`与服务端回合断开`),Xo(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}),m.signal.removeEventListener(`abort`,i),Wr.current.delete(r),n()}});Wr.current.set(r,()=>{a(),n()})}))}if(!Ce){let s=ye(t,ue,m.signal,{tools:F.length?F:void 0,runTool:F.length?async(n,i)=>{Kn(!0);let a=Pl(n);G(Bl(Ve().toolStepDetail,a,n,`running`));let o=Date.now();try{if(n.startsWith(`kb_`))return await fc(n,i,{base:`/`,docs:e});if(n.startsWith(`fs_`)){let e=await It(n,i,A),t=co(n,e);if(t&&Y.current){let e=so(Y.current.sessions.find(e=>e.id===r)?.workspaceChanges,t);X(Ge(Y.current,r,{workspaceChanges:e}))}return e}if(n.startsWith(`skill_`))return await oa(n,i);if(n===`load_workspace_dependencies`)return await si(n);if(n===`office_to_pdf`)return O?JSON.stringify({error:`计划模式探查中:请先 submit_plan 并等待批准`}):await ri(n,i,A);if(n.startsWith(`workspace_changes_`)){let e=Y.current?.sessions.find(e=>e.id===r),{text:t,next:i}=lo(n,e?.workspaceChanges);return i&&Y.current&&X(Ge(Y.current,r,{workspaceChanges:i})),t}if(n.startsWith(`working_directory_`)){let{text:e,info:t}=await kt(n,i);return t&&(to(t),n===`working_directory_set`&&Y.current&&X(Ge(Y.current,r,{workspacePath:t.workspace}))),e}if(n===`present`){if(O)return JSON.stringify({error:`计划模式探查中:请先 submit_plan 并等待批准`});let e=await Ft(i,A);try{let t=JSON.parse(e);t.ok&&t.files?.length&&Zo(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(O)return JSON.stringify({error:`计划模式探查中:请先 submit_plan 并等待批准`});let e;try{e=JSON.parse(i||`{}`).items}catch{e=void 0}let t=ll(`todo`,e);if(!t.length)return JSON.stringify({error:`没有可记录的待办:只有用户明确要求记录待办时才调用 todo_add,并给出待办标题;不要为了弹出卡片而调用工具。`});let n=await Wa(t),r=await ca(`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 Ga(r)}catch(e){return JSON.stringify({error:`创建所属任务失败:${e instanceof Error?e.message:String(e)}`})}i=JSON.stringify({items:ul(`todo`,a)})}if(n===`task_add`){if(O)return JSON.stringify({error:`计划模式探查中:请先 submit_plan 并等待批准`});let e=ll(`task`,Za(i));e.length||e.push(cl(`task`));let t=await ca(`task`,e);if(!t)return JSON.stringify({ok:!1,cancelled:!0,message:`用户取消了新增任务,未写入任何数据。`});i=JSON.stringify({items:ul(`task`,t)})}if(n.startsWith(`task_`)){let e=await Qa(n,i,{sessionId:r});if(n===`task_add`)try{let t=JSON.parse(e);t.ok&&t.count&&B(`已创建 ${t.count} 个任务,可在侧栏「任务管理」查看。`,`ok`)}catch{}return e}if(n.startsWith(`todo_`)&&n!==`todo_write`){if(O&&n!==`todo_list`)return JSON.stringify({error:`计划模式探查中:请先 submit_plan 并等待批准`});let e=await za(n,i,{sessionId:r});if(n===`todo_add`)try{let t=JSON.parse(e);t.ok&&t.count&&B(`已记录 ${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=yo(e);return Y.current?.activeId===r&&ii(t),Y.current&&X(Ge(Y.current,r,{todos:t})),JSON.stringify({ok:!0,count:t.length,todos:t})}if(n.startsWith(`pm_`)){if(O&&!n.endsWith(`_list`))return JSON.stringify({error:`计划模式探查中:请先 submit_plan 并等待批准`});let e=await Aa(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_`)?`条缺陷`:`个项目`;B(`已创建 ${t.count} ${r},可在侧栏「${e}」查看。`,`ok`)}}catch{}return e}if(n.startsWith(`goal_`)){if(n===`goal_get`)return Vo(Y.current?.activeId===r?li.current:Bo(Y.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 Y.current?.activeId===r&&(li.current=t,ci(t),ui.current=0),Y.current&&X(Ge(Y.current,r,{goal:t})),Vo(t)}if(n===`goal_done`){let e=Y.current?.activeId===r?li.current:Bo(Y.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 Y.current?.activeId===r&&(li.current=t,ci(t),ui.current=0),Y.current&&X(Ge(Y.current,r,{goal:t})),Vo(t)}return n===`goal_clear`?(Y.current?.activeId===r&&(li.current=null,ci(null),ui.current=0),Y.current&&X(Ge(Y.current,r,{goal:void 0})),JSON.stringify({ok:!0,goal:null})):JSON.stringify({error:`unknown tool: ${n}`})}if(n.startsWith(`schedule_`))return await Ss(n,i,r);if(n===`list_agents`||n===`spawn_subagent`||n===`fork_subagent`||n.startsWith(`subagent_`))return await Ks(n,i,{settings:$r(t,Ve().subagentModel),parentSignal:m.signal,access:A,fsEnabled:y,webEnabled:b,parentMessages:g,onHint:e=>G(e),runFs:(e,t,n)=>It(e,t,n),runWeb:(e,t)=>Qn(e,t)});if(n===`workflow`)return await ac(n,i,{settings:t,parentSignal:m.signal,access:A,fsEnabled:y,webEnabled:b,parentMessages:g,onHint:e=>G(e),runFs:(e,t,n)=>It(e,t,n),runWeb:(e,t)=>Qn(e,t)});if(n===`ask_user_question`){let e=bo(i);if(!e.length)return JSON.stringify({error:`questions is required`});let t={};for(let n of e)t[n.id]={selected:[],text:``};return Fi(t),Ri(0),Bi(!1),Ui(null),Gi(!1),qi(``),ji(e),await new Promise((e,t)=>{Qr.current={resolve:e,reject:t};let n=Vr.current,r=()=>{n?.signal.removeEventListener(`abort`,r),Ns()};n?.signal.addEventListener(`abort`,r)})}if(n===`submit_plan`){let e=Do(i);return e?(ki(e),await new Promise((e,t)=>{ei.current={resolve:e,reject:t};let n=Vr.current,r=()=>{n?.signal.removeEventListener(`abort`,r),Ps()};n?.signal.addEventListener(`abort`,r)})):JSON.stringify({error:`title and steps are required`})}return n===`bash`?await Rn(i,A):n===`pwsh`?await Wn(i,A):n.startsWith(`bash_session_`)?await Zn(n,i,A):n.startsWith(`pwsh_session_`)?await qn(n,i,A):n.startsWith(`job_`)?await zn(n,i,A):n.startsWith(`web_`)?await Qn(n,i):n.startsWith(`memory_`)?await _r(n,i,oe):JSON.stringify({error:`unknown tool: ${n}`})}finally{let e=Math.max(0,Date.now()-o);Zo(t=>({...t,toolMs:(t.toolMs??0)+e})),Kn(!1),eo()}}:void 0});for await(let e of s){if(e.type===`tool`){let t=Pl(e.name);G(Bl(Ve().toolStepDetail,t,e.name,e.status===`running`?`running`:`done`));let n=Rl(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);Zo(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:Il(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=L?(n-L)/1e3:0,i=_u(e.usage),a=r>.2&&i>0?i/r:void 0;Zo(r=>({...r,usage:e.usage,tps:a,model:t.model,ttftMs:L?L-I:r.ttftMs,llmMs:n-I}));continue}if(L===0&&(L=Date.now(),Zo(e=>({...e,ttftMs:L-I,model:t.model}))),e.type===`reasoning_api`){Zo(t=>({...t,reasoningApi:e.content}));continue}e.type===`reasoning`&&me===0&&(me=Date.now());let r=e.type===`content`&&me>0&&!he;if(r&&(he=!0),be){e.type===`content`&&(ie?a+=e.delta:ae?o+=e.delta:n+=e.delta);let t=xe(Math.max(0,Math.floor((Date.now()-I)/1e3)));if(e.type===`reasoning`){_e+=e.delta;let n=ge(_e);Zo(e=>{let i={...e,reasoning:n,content:t};return r&&(i.reasoningDuration=Math.max(1,Math.round((Date.now()-me)/1e3))),i})}else r&&Zo(e=>({...e,content:t,reasoningDuration:Math.max(1,Math.round((Date.now()-me)/1e3))}))}else e.type===`reasoning`&&(_e+=e.delta),Zo(t=>{let n=e.type===`reasoning`?{...t,reasoning:ge(_e)}:{...t,content:ge(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:zl(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()-me)/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(ve=!0,!be){let e=[...Y.current?.sessions.find(e=>e.id===r)?.messages??[]].reverse().find(e=>e.role===`assistant`);e&&typeof e.content==`string`&&!e.content.trim()&&B(`模型本轮没有返回正文(可能工具轮次用尽或输出被截断),请重试或回复「继续」`)}{let e=me>0&&!he?Math.max(1,Math.round((Date.now()-me)/1e3)):null;Zo(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(R!=null&&(window.clearInterval(R),R=void 0),ie){G(`正在质检并入库…`);let e=await Ii(a,ie);if(Zo(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&&Y.current){let t={...ie,linkedPromptPath:e.path};se(t),ce.current=t,X(z(Y.current,{promptGen:t}))}}else if(ae){G(`正在质检并入库…`);let e=await ea(o,ae);if(Zo(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&&Y.current){let t={...ae,linkedKnowledgePath:e.path};de(t),fe.current=t,X(z(Y.current,{knowledgeGen:t}))}}else if(N){G(`正在检测覆盖并入库…`);let e=N.reqPath?.split(`/`).pop()?.replace(/\.[^.]+$/,``)||i.slice(0,24),t=await xi(n,N,e);if(Zo(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&&Y.current){let e={...N,linkedCasePath:t.path};ne(e),re.current=e,X(z(Y.current,{caseGen:e}))}}}Ce&&ve&&Zo(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`||Y.current?.activeId===r&&B(e instanceof Error?e.message:String(e)),Xo(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{R!=null&&(window.clearInterval(R),R=void 0);let e=Date.now(),n=qr.current.get(r),a=L||n?.firstToken||0;Zo(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=_u(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:ve?`completed`:(m.signal.aborted||!Ce)&&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),Wr.current.get(r)?.(),Wr.current.delete(r),Ur.current===r&&(Ur.current=null),Vr.current===m&&(Vr.current=null),Fo(r,!1);{let e=Ve().toolStepDetail;e===`full`?window.setTimeout(()=>G(null),2800):e===`detailed`?window.setTimeout(()=>G(null),1200):G(null)}if(ve&&_&&ar(i,oe).finally(()=>{eo()}),ve&&Y.current){let e=[...Y.current.sessions.find(e=>e.id===r)?.messages??[]].reverse().find(e=>e.role===`assistant`),n=Jr({userContent:i,assistantContent:typeof e?.content==`string`?e.content:``,reasoning:e?.reasoning});n.length&&Yr({sessionId:r,model:e?.model??t.model,messages:n})}if(ve&&t&&!m.signal.aborted&&Y.current){let e=Y.current.sessions.find(e=>e.id===r),n=e?.messages??[];if(e&&!fi.current.has(r)&&Ir(e.title,n)){let e=Fr(n);e&&(fi.current.add(r),Rr(t,e).then(e=>{if(!e||!Y.current)return;let t=Y.current.sessions.find(e=>e.id===r);t&&Ir(t.title,t.messages)&&X(et(Y.current,r,e))}))}}let o=Y.current?.activeId===r,s=null;if(o){s=_a.current,_a.current=null,!s&&J.current.length&&(s=J.current[0],va(J.current.slice(1)));let e=Ho(li.current);if(!s&&!P&&Jo({goalActive:!!e,turnOk:ve,aborted:m.signal.aborted,hasFollowUp:!1,askUserPending:!!Qr.current,roundsUsed:ui.current,maxRounds:3})){let t=ui.current+1;ui.current=t,s={id:`goal_drv_${Date.now().toString(36)}`,content:Ko(e,t,3),files:[],refs:[],imgs:[]}}}s&&window.setTimeout(()=>{ps(s)},0)}}function ms(){_a.current=null,va([]),ui.current=0;let e=Y.current?.activeId;e&&Xo(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}),Ro(e)}function hs(e){va(J.current.filter(t=>t.id!==e))}function gs(e){let t=J.current.find(t=>t.id===e);t&&(hs(e),d(t.content),m(t.files),x(t.imgs),C(t.refs),requestAnimationFrame(()=>xa.current?.focus()))}function _s(e){let t=J.current.find(t=>t.id===e);t&&(va(J.current.filter(t=>t.id!==e)),Zr.current?(_a.current=t,Ro(Y.current?.activeId)):ps(t))}function vs(e){let t=[...J.current],n=e??t.shift()??null;n&&(va(t),Zr.current?(_a.current=n,Ro(Y.current?.activeId)):ps(n))}function bs(e,t){let n=!(c[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 Cs(e){e&&(u.trim()||f.length>0||b.length>0||S.length>0?Oa.current[e]={input:u,attachments:f,images:b,docRefs:S}:delete Oa.current[e],bt(e,u))}function ws(e){let t=e?Oa.current[e]:void 0;d(t?.input??Tt(e)),m(t?.attachments??[]),x(t?.images??[]),C(t?.docRefs??[]),wi(wt(e))}function Es(e){e?.abortRun!==!1&&Ro(Y.current?.activeId),Zr.current=!1,gt(!1),m([]),x([]),C([]),wi([]),Ei(null),d(``),B(null),en(!1),Va.current=!0,e?.clearDraft&&Y.current?.activeId&&(delete Oa.current[Y.current.activeId],Ct(Y.current.activeId))}function Ds(e,t){if(!Y.current)return;Mn(`dialog`);let n=Y.current.activeId,r=Y.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)Es({clearDraft:!0,abortRun:!1}),o={...Y.current,activeId:n,sessions:Y.current.sessions.map(e=>e.id===n?a(e):e)};else{Cs(n),Es({clearDraft:!0,abortRun:!1});let e=To(n)??Y.current,t=H?.workspace?.trim()||void 0;o=ot(e,{workspacePath:t,access:Re()});let r=o.activeId;o={...o,sessions:o.sessions.map(e=>e.id===r?a(e):e)}}if(X(o),l([]),ne(e===`caseGen`?t:null),re.current=e===`caseGen`?t:null,se(e===`promptGen`?t:null),ce.current=e===`promptGen`?t:null,de(e===`knowledgeGen`?t:null),fe.current=e===`knowledgeGen`?t:null,e===`caseGen`){let e=t,n=[`请根据以下需求生成测试用例`],r=e.reqSource;r?.kind===`stories`?n.push(`(来源:${e.docTitle||`用户故事`},共 ${r.storyIds.length} 条故事)`):r?.kind===`doc`&&n.push(`(来源文档:${e.docTitle||r.path.split(`/`).pop()||r.path})`),e.testPointIds?.length&&n.push(`,参考 ${e.testPointIds.length} 条测试点`),e.templateTitle&&n.push(`,按「${e.templateTitle}」模板输出`),n.push(`。`),d(n.join(``))}let s=o.sessions.find(e=>e.id===o.activeId)?.workspacePath||H?.workspace?.trim()||H?.projectRoot;s&&En(e=>({...e,[s]:!0})),uo(o.sessions.find(e=>e.id===o.activeId))}async function Os(e){let t=Y.current;if(!t)return;let n=t.sessions.find(e=>e.id===t.activeId),r=Ua.current?.harnessRoot?.trim()||Ua.current?.projectRoot?.trim()||Ua.current?.workspace?.trim(),i=n?.pluginDev?.active?n.pluginDev:{active:!0,requirement:e.trim(),confirmedAt:Date.now()};if(X(z(t,{pluginDev:i,access:Zt===`full`?`full`:`readwrite`,...r?{workspacePath:r}:{}})),L(i),pe.current=i,me.current=null,Ps(),hi(`off`),r&&En(e=>({...e,[r]:!0})),q&&r&&Ua.current?.workspace!==r)try{to(await qt(r))}catch{}}function ks(e){e?.active?Ds(`caseGen`,e):(ne(null),re.current=null,Y.current&&X(z(Y.current,{caseGen:void 0})))}function As(e){e?.active?Ds(`promptGen`,e):(se(null),ce.current=null,Y.current&&X(z(Y.current,{promptGen:void 0})))}function js(e){e?.active?Ds(`knowledgeGen`,e):(de(null),fe.current=null,Y.current&&X(z(Y.current,{knowledgeGen:void 0})))}function Ms(e){if(xe(!1),!Y.current)return;Mn(`dialog`);let t=Y.current.activeId;Cs(t),Es({clearDraft:!0,abortRun:!1});let n=To(t)??Y.current,r=e?.trim()||H?.workspace?.trim()||void 0,i=ot(n,{workspacePath:r,access:Re()});X(i),l([]),ne(null),se(null),de(null),L(null),pe.current=null,ii([]),li.current=null,ci(null),ui.current=0,hi(`off`),yi(e=>e===`pluginDev`?null:e),Ns(),Ps();let a=r||H?.projectRoot;a&&En(e=>({...e,[a]:!0})),uo(i.sessions.find(e=>e.id===i.activeId))}function Ns(){let e=Qr.current;e&&(Qr.current=null,ji(null),Fi({}),Ri(0),Bi(!1),Ui(null),Gi(!1),qi(``),e.resolve(JSON.stringify({canceled:!0,error:`user aborted`})))}function Ps(){let e=ei.current;e&&(ei.current=null,ki(null),e.resolve(JSON.stringify({approved:!1,canceled:!0})))}function Fs(){let e=ei.current;e&&(ei.current=null,ki(null),hi(`approved`),e.resolve(JSON.stringify({approved:!0,message:`用户已批准计划,可以开始实施`})))}function Is(){let e=ei.current;e&&(ei.current=null,ki(null),hi(`planning`),e.resolve(JSON.stringify({approved:!1,message:`用户驳回了计划,请修订后再次 submit_plan`})))}function Ls(){hi(e=>e===`off`?(yi(`plan`),`planning`):(Ps(),yi(e=>e===`plan`?null:e),`off`))}function Rs(e,t){return!e||!t?!1:t.skipped||t.text.trim()!==``?!0:e.options?.length?t.selected.length>0:!1}function zs(e,t,n){let r=Qr.current;if(!r)return;Qr.current=null,ji(null),Fi({}),Ri(0),Bi(!1),Ui(null),Gi(!1),qi(``),B(null);let i=t.filter(e=>e.skipped).length,a=String(n?.skipReason??``).trim();r.resolve(JSON.stringify({answers:t,summary:Co(e,t),...i?{skipped:!0,approvalRequired:!0,...a?{skipReason:a}:{},note:`用户跳过了部分或全部问题:跳过的题不算确认,也未批准实施。`+(a?`用户给出的跳过原因:${a}。`:``)+`本轮只允许只读调研与文字方案,禁止 fs_write / fs_mkdir / 改配置;请先说明采用的默认假设(哪几项按推荐)与准备改动的范围`+(a?`,并针对上述原因给出调整`:``)+`,然后等用户明确回复「开始实施」再动手。`}:{note:`answers 为结构化答案;summary 是同一批答案的中文文本版本,可直接据此继续,无需再次提问。`},...n}))}function Bs(e,t,n){Fi(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}}}),Ui(null),e.multi_select||Ri(e=>Math.min(e+1,(Ai?.length??1)-1))}function Vs(e){let t=Ai?.length??0;t&&(Ri(Math.max(0,Math.min(e,t-1))),Ui(null))}function Hs(e,t){e&&(Fi(n=>{let r=n[e.id]??{selected:[],text:``};return{...n,[e.id]:{selected:e.multi_select?r.selected:[],text:t,skipped:!1}}}),Ui(null))}function Us(e,t){let n=t.trim(),r=n&&e.options?.length?xo(e,n):null,i=r?{selected:r,text:``,skipped:!1}:{selected:e.multi_select?Pi[e.id]?.selected??[]:[],text:n,skipped:!1},a={...Pi,[e.id]:i};Fi(a),Ui(null),al?Gs(a):Vs(rl+1)}function Ws(e){return(Ai??[]).map(t=>{let n=So(t,e[t.id]??{selected:[],text:``});return n.skipped||n.text?.trim()||n.selected?.length?n:{id:t.id,selected:[],skipped:!0}})}function Gs(e=Pi,t=!1){let n=Ai;if(!n?.length||!Qr.current)return!1;let r=Ws(e),i=r.findIndex(e=>!e.skipped&&!e.text?.trim()&&!e.selected?.length);if(i>=0)return Vs(i),Ui(n[i]?.options?.length?`请先选择选项再提交`:`请先填写回答再提交`),!1;if(!t&&r.some(e=>e.skipped))return Gi(!0),Ui(null),!1;let a=Ki.trim();return zs(n,r,a?{skipReason:a}:void 0),!0}function qs(){let e=Ai,t=Q;if(!e?.length||!t)return;let n={...Pi,[t.id]:{selected:[],text:``,skipped:!0}};Fi(n),Ui(null),al?Gs(n):Vs(rl+1)}function Js(){Gs(Pi,!0)}function Ys(){Gi(!1);let e=Ws(Pi).findIndex(e=>e.skipped);Vs(e>=0?e:0)}function Xs(e){if(xe(!1),!Y.current||(Mn(`dialog`),U(null),e===Y.current.activeId))return;let t=Y.current.activeId;Cs(t),Ns(),Ps(),hi(`off`),B(null),en(!1),Va.current=!0;let n=To(t)??Y.current;n.sessions.some(t=>t.id===e)||(n=Y.current);let r=Ke(n,e),i=r.sessions.find(t=>t.id===e),a=Hr.current.get(e)?.messages??i?.messages??[];Ka.current=a,l(a);let o=Hr.current.has(e)||_t.includes(e);Zr.current=o,gt(o),Vr.current=Hr.current.get(e)?.abort??null,o&&!Wr.current.has(e)&&Yo(e,0),ne(i?.caseGen?.active?i.caseGen:null),se(i?.promptGen?.active?i.promptGen:null),de(i?.knowledgeGen?.active?i.knowledgeGen:null),L(i?.pluginDev?.active?i.pluginDev:null),yi(e=>i?.pluginDev?.active?`pluginDev`:e===`pluginDev`?null:e),ii(yo(i?.todos));{let e=Bo(i?.goal);li.current=e,ci(e),ui.current=0}ws(e),X(r),uo(i)}function Zs(e){if(!Y.current)return;U(null),Me(null);let t=Y.current.activeId===e;t&&Es({clearDraft:!0}),delete Oa.current[e],Ct(e),yt(e,[]);let n=lt(Y.current,e);if(X(n),t){let e=n.sessions.find(e=>e.id===n.activeId);l(e?.messages??[]),ne(e?.caseGen?.active?e.caseGen:null),se(e?.promptGen?.active?e.promptGen:null),de(e?.knowledgeGen?.active?e.knowledgeGen:null),L(e?.pluginDev?.active?e.pluginDev:null),yi(t=>e?.pluginDev?.active?`pluginDev`:t===`pluginDev`?null:t)}}function Qs(e,t){if(!Y.current)return;U(null);let n=Y.current.activeId===e&&t;n&&Es();let r=nt(Y.current,e,t);if(X(r),n){let e=r.sessions.find(e=>e.id===r.activeId);l(e?.messages??[])}}function ec(e){if(!Y.current)return;let t=Y.current.sessions.find(t=>t.id===e);t&&(U(null),X(tt(Y.current,e,!t.pinned)))}function tc(e){Y.current&&Y.current.sessions.some(t=>t.id===e)&&(U(null),Me(null),Ee(e))}function nc(){let e=Y.current?.activeId,t=Y.current?.sessions.find(t=>t.id===e);t?B(Kr(`stats`,t.id,t.updatedAt,()=>Br(zr(t))),`ok`):B(`无活跃会话可统计`)}function rc(e){Y.current&&Se&&(fi.current.add(Se),X(et(Y.current,Se,e)),Ee(null))}function ic(){nn(e=>(Je(!e),!e))}async function cc(e){let t=Array.from(e.target.files??[]);e.target.value=``,await pc(t)}function uc(){let t=e.map(e=>({collection:e.collection,path:e.path,title:e.title,category:e.category,format:String(e.format)})),n=xr.map(e=>({collection:`workspace`,path:e.path,title:e.name,category:Jt(H?.workspace,H?.projectRoot),format:e.type===`dir`?`dir`:`file`}));return[...t,...n]}function dc(e){e.length&&C(t=>{let n=[...t];for(let t of e){if(n.length>=Cl)break;n.some(e=>e.collection===t.collection&&e.path===t.path)||n.push(t)}return n})}async function pc(e,t){let n=[],r=[],i=[],a=jl(f,b);for(let o of e)if(a>=6)i.push(`${o.name}(最多 6 个文件)`);else try{let e=await Sc(o);e.kind===`image`?r.push(await Al(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&&m(e=>[...e,...n]),r.length&&x(e=>[...e,...r]),B(i.length?`以下文件未添加:${i.join(`、`)}`:null),xa.current?.focus()}function mc(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=jc(t),o=(t.getData(`text/plain`)||``).trim(),s=uc(),c=Jt(H?.workspace,H?.projectRoot),l={projectRoot:H?.projectRoot,workspace:H?.workspace,workspaceLabel:c},u=[],d=new Map;for(let e of a){let t=Pc(e,l);t?(u.push(t),d.set(Tc(e),t.path)):d.set(Tc(e),e)}let f=null;!r.length&&!i.length&&!a.length&&kc(o)&&(f=Fc(o,s));let p=[],m=[];for(let e of i){let t=d.get(e.name),n=(t?Pc(t,l):null)||Fc(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(),B(null),dc([...u,...p,...f?[f]:[]]),r.length&&$o(r),m.length&&pc(m,d),xa.current?.focus())}function hc(e){let t=e.target.closest(`[data-copy-code]`);t&&xu(t.closest(`.code-block`)?.querySelector(`pre`)?.textContent??``).then(e=>{e&&(t.textContent=`已复制`,window.setTimeout(()=>{t.textContent=`复制`},1e3))})}let gc=c.length===0,_c=!!(u.trim()||f.length||S.length||b.length||Ci.length||gi===`reports`),yc=-1,bc=-1;c.forEach((e,t)=>{e.role===`user`?yc=t:e.role===`assistant`&&(bc=t)});let xc=e=>e===yc||e===bc?``:`opacity-0 group-hover:opacity-100 group-focus-within:opacity-100 transition-opacity`,Cc=Nl.find(e=>e.value===Zt)??Nl[0],wc=gi===`pluginDev`,Ec=(a?.sessions??[]).filter(e=>!e.archived&&!e.deleted),Dc=(a?.sessions??[]).filter(e=>e.archived&&!e.deleted),Oc=H?.items??[],Ac=new Set(Oc.map(e=>e.path)),Mc=H?.workspace??``,Nc=H?.projectRoot??``,Ic=a?.sessions.find(e=>e.id===a.activeId),Lc=Ic?.workspacePath,Rc=!Lc||!Ac.has(Lc),zc=H?.workspace?.trim()||``,Bc=Oc.find(e=>e.path===zc),Vc=Bc?jt(Bc,Nc):zc?Jt(zc,Nc):`工作区`,Hc=Dn.trim().toLowerCase(),qc=(0,K.useMemo)(()=>Hc?new Set(no(a,Dn,{limit:50,includeArchived:!0}).map(e=>e.sessionId)):null,[Hc,a,Dn]),[Jc,Yc]=(0,K.useState)(null);(0,K.useEffect)(()=>{if(!Hc){Yc(null);return}let e=!1;return Yc(null),ro(Dn,{limit:50,includeArchived:!0}).then(t=>{!e&&t?.hits&&Yc(new Set(t.hits.map(e=>e.sessionId)))}),()=>{e=!0}},[Hc,Dn]);let Xc=Jc??qc,Qc=Xc?Dc.filter(e=>Xc.has(e.id)):Dc;function $c(e){let t=e.id===`ws_project`||e.path===Nc;return pt(Ec.filter(n=>!(n.workspacePath!==e.path&&(!t||n.workspacePath&&Ac.has(n.workspacePath)))).filter(e=>!Xc||Xc.has(e.id)))}let el=Oc.filter(e=>!Hc||e.name.toLowerCase().includes(Hc)||e.path.toLowerCase().includes(Hc)?!0:$c(e).length>0);function tl({s:e,nested:t=!1}){let n=e.id===a?.activeId,r=jn===e.id,i=_t.includes(e.id);return(0,Z.jsx)(cu,{s:e,nested:t,active:n,menuOpen:r,busy:i,onOpen:()=>Xs(e.id),onRename:()=>tc(e.id),onToggleMenu:()=>{Me(null),U(r?null:e.id)},onTogglePin:()=>ec(e.id),onToggleArchive:()=>Qs(e.id,!e.archived),onExport:()=>{U(null);let t=ns(e,`json`);B(t.ok?`已导出 ${t.filename}`:t.error)},onRemove:()=>{U(null),Me(null),Ae(e.id)}})}let nl=Ai?.length??0,rl=Math.max(0,Math.min(Li,nl-1)),Q=Ai?.[rl],il=Q&&Pi[Q.id]||{selected:[],text:``},al=rl>=nl-1,sl=Rs(Q,il),dl=(Ai??[]).map((e,t)=>({q:e,index:t})).filter(({q:e})=>Pi[e.id]?.skipped);return(0,Z.jsxs)(`div`,{className:`tw-app h-full min-h-0 flex overflow-hidden bg-(--tw-surface-page)`,children:[(0,Z.jsxs)(`aside`,{className:`tw-session-rail shrink-0 border-r border-(--tw-border) flex flex-col transition-[width] ${tn?`w-64`:`w-10`}`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1 ${tn?`px-2.5 pt-2.5`:`px-1 pt-2 justify-center`}`,children:[tn&&(0,Z.jsx)(`div`,{className:`flex-1 min-w-0 text-[13px] font-medium text-stone-700 truncate px-1`,children:Et(`chat.workbench`,void 0,Pn.language)}),(0,Z.jsx)(`button`,{type:`button`,"aria-label":tn?`收起侧栏`:`展开侧栏`,onClick:ic,className:`w-8 h-8 shrink-0 flex items-center justify-center rounded-lg text-stone-500 hover:bg-stone-200/70`,children:(0,Z.jsx)($,{className:`w-4 h-4`,children:tn?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`}),(0,Z.jsx)(`path`,{d:`M9 3v18`})]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`}),(0,Z.jsx)(`path`,{d:`M15 3v18`})]})})})]}),tn?(0,Z.jsxs)(`div`,{className:`px-2.5 pt-2 space-y-1.5`,children:[(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>Ms(),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,Z.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Z.jsx)(`path`,{d:`M5 12h14`}),(0,Z.jsx)(`path`,{d:`M12 5v14`})]}),Et(`chat.newSession`,void 0,Pn.language)]}),(0,Z.jsxs)(`button`,{type:`button`,"data-hint":`我的插件`,onClick:()=>xe(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 ${be?`is-active`:``}`,children:[(0,Z.jsx)(ru,{className:`w-3.5 h-3.5`}),`插件`]})]}):(0,Z.jsxs)(`div`,{className:`px-1 pt-1 flex flex-col gap-1`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:()=>Ms(),"data-hint":`新会话`,className:`w-8 h-8 flex items-center justify-center rounded-lg text-[#4176e6] hover:bg-white/80`,children:(0,Z.jsxs)($,{className:`w-4 h-4`,children:[(0,Z.jsx)(`path`,{d:`M5 12h14`}),(0,Z.jsx)(`path`,{d:`M12 5v14`})]})}),(0,Z.jsx)(`button`,{type:`button`,"data-hint":`我的插件`,onClick:()=>xe(e=>!e),className:`tw-rail-plugin-btn tw-rail-plugin-btn--icon w-8 h-8 flex items-center justify-center rounded-lg ${be?`is-active`:``}`,children:(0,Z.jsx)(ru,{className:`w-4 h-4`})})]}),tn&&(0,Z.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-2 py-3`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1 px-1.5 pb-2`,children:[(0,Z.jsx)(`div`,{className:`flex-1 text-[12px] font-semibold text-stone-500`,children:Et(`chat.workspace`,void 0,Pn.language)}),(0,Z.jsx)(`button`,{type:`button`,"aria-label":`搜索`,onClick:()=>{An(e=>!e),kn&&On(``)},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,Z.jsx)(Ql,{className:`w-3.5 h-3.5`})}),(0,Z.jsx)(`button`,{type:`button`,"data-hint":q?`添加工作区(选择本地文件夹)`:`本地文件服务未就绪`,disabled:!q||Cn,onClick:()=>void po(),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,Z.jsx)($l,{className:`w-3.5 h-3.5`})})]}),kn&&(0,Z.jsx)(`input`,{value:Dn,onChange:e=>On(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`}),Mr&&(0,Z.jsx)(`div`,{className:`px-1.5 py-2 text-[11px] text-amber-700/80`,children:`本地文件服务未就绪,工作区暂不可用`}),(0,Z.jsxs)(`div`,{className:`space-y-0.5`,children:[el.map(e=>{let t=$c(e),n=!!(Tn[e.path]??t.length>0),r=e.id===`ws_project`||e.path===Nc,i=!!(Ic&&(Rc?r:Lc===e.path)),a=je===e.id;return(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`tw-project-row group relative ${i?`is-active`:``} ${n?`is-expanded`:``} ${a?`is-menu-open`:``}`,children:[(0,Z.jsxs)(`button`,{type:`button`,"data-hint":e.path,onClick:t=>{t.stopPropagation(),U(null),Me(null),En(t=>({...t,[e.path]:!n})),q&&e.path!==Mc&&io(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,Z.jsx)(`span`,{className:`tw-slot tw-folder`,children:(0,Z.jsx)(Xl,{open:n,className:`w-3.5 h-3.5`})}),(0,Z.jsx)(`span`,{className:`tw-slot tw-chevron`,children:(0,Z.jsx)(Zl,{open:n,className:`w-3 h-3`})}),(0,Z.jsx)(`span`,{className:`tw-project-title`,children:jt(e,Nc)})]}),(0,Z.jsxs)(`div`,{className:`tw-ws-actions relative shrink-0`,"data-ws-menu":``,children:[(0,Z.jsx)(ou,{open:a,onToggle:()=>{U(null),Me(a?null:e.id)},onRename:()=>{U(null),Me(null),st(e.id)},onDelete:e.id===`ws_project`?void 0:()=>go(e)}),(0,Z.jsx)(`button`,{type:`button`,"data-hint":`在此工作区新建会话`,onClick:t=>{t.stopPropagation(),Ms(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,Z.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Z.jsx)(`path`,{d:`M5 12h14`}),(0,Z.jsx)(`path`,{d:`M12 5v14`})]})})]})]}),(0,Z.jsx)(`div`,{className:`tw-collapse ${n?`is-open`:``}`,children:(0,Z.jsx)(`div`,{className:`tw-collapse-inner space-y-0.5 pb-0.5`,children:t.map(e=>(0,Z.jsx)(tl,{s:e,nested:!0},e.id))})})]},e.id)}),!el.length&&q&&(0,Z.jsx)(`div`,{className:`px-2 py-3 text-xs text-stone-400`,children:`暂无工作区`})]}),Qc.length>0&&(0,Z.jsxs)(`div`,{className:`mt-3 pt-2 border-t border-stone-200/60`,children:[(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>an(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,Z.jsx)(Vl,{className:`w-3 h-3 transition-transform ${rn?`rotate-180`:``}`}),`已归档 (`,Qc.length,`)`]}),(0,Z.jsx)(`div`,{className:`tw-collapse ${rn?`is-open`:``}`,children:(0,Z.jsx)(`div`,{className:`tw-collapse-inner space-y-0.5`,children:Qc.map(e=>(0,Z.jsx)(tl,{s:e},e.id))})})]})]}),tn&&(Mc||Gn||$n)&&(0,Z.jsxs)(`div`,{className:`shrink-0 border-t border-stone-200/60 px-3 py-2 space-y-1`,children:[Mc&&(0,Z.jsxs)(`div`,{className:`tw-rail-workspace-footer`,"data-hint":Mc,children:[(0,Z.jsx)(`span`,{className:`tw-rail-workspace-label`,"data-i18n":`chat.workspace`,children:`工作区`}),(0,Z.jsx)(`span`,{className:`tw-rail-workspace-name`,children:Jt(Mc,Nc)})]}),(Gn||$n)&&(0,Z.jsx)(`div`,{className:`text-[11px] text-(--tw-accent)`,children:$n??Et(`tool.running`,void 0,Pn.language)})]})]}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex flex-col flex-1 ${be?`hidden`:``}`,children:[gc?null:(0,Z.jsxs)(`div`,{className:`shrink-0 border-b border-(--tw-border) bg-(--tw-surface-page)`,children:[(0,Z.jsx)(`div`,{className:`flex items-center gap-3 px-6 pt-4 pb-2 min-w-0`,children:(0,Z.jsx)(`button`,{type:`button`,"data-hint":`点击重命名`,onClick:()=>{let e=a?.activeId;e&&tc(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,Z.jsxs)(`div`,{className:`flex items-center gap-6 px-6`,children:[(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>Mn(`dialog`),className:`relative h-10 text-sm transition-colors ${W===`dialog`?`text-[#4176e6] font-medium`:`text-stone-500 hover:text-stone-700`}`,children:[`对话`,W===`dialog`&&(0,Z.jsx)(`span`,{className:`absolute left-0 right-0 -bottom-px h-0.5 bg-[#4176e6] rounded-full`})]}),(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>Mn(`thread`),className:`relative h-10 text-sm transition-colors ${W===`thread`?`text-[#4176e6] font-medium`:`text-stone-500 hover:text-stone-700`}`,children:[`回合`,W===`thread`&&(0,Z.jsx)(`span`,{className:`absolute left-0 right-0 -bottom-px h-0.5 bg-[#4176e6] rounded-full`})]}),V.memory&&(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>Mn(`memory`),className:`relative h-10 text-sm transition-colors ${W===`memory`?`text-[#4176e6] font-medium`:`text-stone-500 hover:text-stone-700`}`,children:[(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[`记忆`,(ln?.suggestionCount??0)>0?(0,Z.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":`${ln?.suggestionCount} 条待确认`,children:ln.suggestionCount>99?`99+`:ln.suggestionCount}):null]}),W===`memory`&&(0,Z.jsx)(`span`,{className:`absolute left-0 right-0 -bottom-px h-0.5 bg-[#4176e6] rounded-full`})]}),V.todos&&(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>Mn(`todos`),className:`relative h-10 text-sm transition-colors ${W===`todos`?`text-[#4176e6] font-medium`:`text-stone-500 hover:text-stone-700`}`,children:[`待办`,W===`todos`&&(0,Z.jsx)(`span`,{className:`absolute left-0 right-0 -bottom-px h-0.5 bg-[#4176e6] rounded-full`})]})]}),ai&&ai.status!==`cleared`&&W===`dialog`?(0,Z.jsx)(`div`,{className:`px-6 pb-2`,children:(0,Z.jsxs)(`div`,{className:`rounded-xl border border-[#4176e6]/25 bg-[#f5f8ff] px-3 py-2 flex items-start gap-2`,children:[(0,Z.jsxs)(`span`,{className:`text-[11px] font-medium text-[#4176e6] shrink-0 pt-0.5`,children:[`目标`,ai.status===`done`?`·完成`:``]}),(0,Z.jsx)(`span`,{className:`flex-1 min-w-0 text-[12px] leading-5 ${ai.status===`done`?`text-stone-400 line-through`:`text-stone-800`}`,children:ai.text}),(0,Z.jsx)(`button`,{type:`button`,"data-hint":`清除目标`,className:`text-[11px] text-stone-400 hover:text-stone-600 shrink-0`,onClick:()=>{li.current=null,ci(null),ui.current=0,Y.current&&X(z(Y.current,{goal:void 0}))},children:`清除`})]})}):null,ti.length>0&&W===`dialog`?(0,Z.jsx)(`div`,{className:`px-6 pb-3`,children:(0,Z.jsxs)(`div`,{className:`rounded-xl border border-stone-200 bg-white px-3 py-2.5`,children:[(0,Z.jsxs)(`div`,{className:`text-[11px] font-medium text-stone-500 mb-1.5`,children:[`待办 · `,ti.filter(e=>e.status===`completed`).length,`/`,ti.length]}),(0,Z.jsx)(`ul`,{className:`space-y-1 max-h-28 overflow-y-auto`,children:ti.map((e,t)=>(0,Z.jsxs)(`li`,{className:`flex items-start gap-2 text-[12px] text-stone-700`,children:[(0,Z.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,Z.jsx)(`span`,{className:e.status===`completed`?`line-through text-stone-400`:``,children:e.content})]},`${t}-${e.content}`))})]})}):null]}),W===`todos`&&V.todos?(0,Z.jsx)(`div`,{className:`flex-1 min-h-0 bg-(--tw-surface-page) tw-pane-enter`,children:(0,Z.jsx)(ol,{})},`todos-${a?.activeId??``}`):W===`memory`&&V.memory?(0,Z.jsx)(`div`,{className:`flex-1 min-h-0 bg-(--tw-surface-page) tw-pane-enter`,children:(0,Z.jsx)(Zc,{live:Cr,pluginOn:!!V.memory,workspacePath:a?.sessions.find(e=>e.id===a.activeId)?.workspacePath||H?.projectRoot||``})},`memory-${a?.activeId??``}`):W===`thread`?(0,Z.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,Z.jsx)(Ou,{messages:c,busy:!!(a?.activeId&&_t.includes(a.activeId)),onRestoreCheckpoint:(e,t)=>{let n=Y.current?.activeId;if(!n)return;if(_t.includes(n)||ht){B(`请等待当前回复结束后再从此处继续`);return}let r=Math.max(0,Math.min(e,Ka.current.length-1)),i=Ka.current.slice(0,r+1);Ka.current=i,l(i),Y.current&&X(qe(Y.current,i,{touchUpdatedAt:!0}));let a=`请从第 ${t} 轮继续`;Mn(`dialog`),d(a),B(`已回到第 ${t} 轮,正在继续…`,`ok`),window.setTimeout(()=>{fs(a)},0)}})},`thread-${a?.activeId??``}`):(0,Z.jsxs)(`div`,{className:`relative flex-1 min-h-0 flex flex-col${gc?` justify-center`:``}`,children:[gc?(0,Z.jsxs)(`div`,{className:`shrink-0 flex flex-col items-center text-center px-8 sm:px-10 lg:px-12 pb-8`,children:[(0,Z.jsx)(`img`,{src:`/brand/brand-mark.png`,alt:``,width:64,height:64,className:`w-16 h-16 rounded-[14px] object-contain`}),(0,Z.jsx)(`h2`,{className:`mt-5 text-[22px] leading-8 font-semibold tracking-tight text-stone-800 text-balance`,children:Et(`chat.emptyTitle`,void 0,Pn.language)})]}):null,gc?null:(0,Z.jsxs)(`div`,{className:`relative flex-1 min-h-0`,children:[(0,Z.jsx)(`div`,{ref:ba,onScroll:Mo,className:`h-full overflow-y-auto px-8 sm:px-10 lg:px-12 py-6`,style:{fontSize:`var(--tw-session-font-size, ${Pn.sessionFontSize}px)`},children:(0,Z.jsx)(`div`,{className:`w-full max-w-[min(64rem,100%)] mx-auto flex flex-col gap-4`,onClick:hc,children:c.map((e,n)=>e.role===`user`?(0,Z.jsxs)(`div`,{className:`group flex flex-col items-end gap-1`,children:[e.refs?.length||e.attachments?.length||e.images?.length?(0,Z.jsxs)(`div`,{className:`flex flex-wrap justify-end gap-1.5 max-w-[82%]`,children:[e.refs?.map(e=>(0,Z.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,Z.jsx)(ql,{className:`w-3.5 h-3.5`}),(0,Z.jsx)(`span`,{className:`text-[10px] text-stone-400 shrink-0`,children:oc(e.format)}),(0,Z.jsx)(`span`,{className:`max-w-40 truncate`,children:e.title})]},e.path)),e.attachments?.map(e=>(0,Z.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,Z.jsx)(ql,{className:`w-3.5 h-3.5 text-[#4176e6]`}),(0,Z.jsx)(`span`,{className:`max-w-48 truncate`,children:e.name}),(0,Z.jsx)(`span`,{className:`text-stone-400`,children:yu(e.size)})]},e.name)),e.images?.map(e=>(0,Z.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,Z.jsx)(`img`,{src:e.dataUrl,alt:e.name,className:`max-h-40 max-w-48 object-contain`})},e.id))]}):null,e.content&&(0,Z.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,Z.jsxs)(`div`,{className:`tw-msg-actions ${xc(n)}`,children:[e.time!=null&&(0,Z.jsx)(`span`,{className:`tw-msg-action-time pr-0.5`,children:bu(e.time)}),(0,Z.jsx)(Su,{text:e.content})]})]},n):(0,Z.jsxs)(`div`,{className:`group`,children:[e.turnStatus===`stopped`?(0,Z.jsxs)(`div`,{className:`mb-2`,children:[(0,Z.jsx)(`div`,{className:`text-[13px] text-stone-500 py-1`,children:`已停止`}),(0,Z.jsx)(`div`,{className:`border-t border-stone-200/80`})]}):null,(()=>{let t=e.activitySteps??[],r=t.some(e=>e.status===`running`),i=n===c.length-1&&e.turnStatus!==`stopped`&&(ht||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 s=e.reasoningOpen??!1,l=i||s||r,u=a&&!s&&!l&&e.reasoning?zl(e.reasoning).replaceAll(`**`,``):``;return(0,Z.jsxs)(`div`,{className:`mb-2`,children:[(0,Z.jsxs)(`button`,{type:`button`,onClick:e=>bs(n,e),className:`flex w-full items-center gap-2 py-1 text-left select-none`,children:[a||i&&!e.content?(0,Z.jsx)(`span`,{className:`w-3.5 h-3.5 shrink-0 rounded-full border-2 border-purple-400 border-t-transparent animate-spin`}):(0,Z.jsxs)($,{className:`w-3.5 h-3.5 shrink-0 text-stone-400`,children:[(0,Z.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,Z.jsx)(`path`,{d:`M9 18h6`}),(0,Z.jsx)(`path`,{d:`M10 22h4`})]}),(0,Z.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,Z.jsxs)(`span`,{className:`text-xs text-stone-400 shrink-0`,children:[`用时 `,e.reasoningDuration,`s`]}),(0,Z.jsx)(Vl,{className:`w-3.5 h-3.5 shrink-0 text-stone-400 transition-transform ${s?`rotate-180`:``}`}),u?(0,Z.jsx)(`span`,{className:`flex-1 min-w-0 truncate text-xs text-shimmer-muted think-mask`,children:u}):null]}),l&&t.length>0?(0,Z.jsx)(`ul`,{className:`mt-1.5 mb-1 pl-5.5 space-y-1.5`,children:t.map(e=>(0,Z.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,Z.jsx)(Ll,{kind:e.kind,status:e.status}),(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1 leading-5`,children:[(0,Z.jsx)(`span`,{className:`font-medium ${e.status===`running`?`text-shimmer`:``}`,children:e.title}),e.detail?(0,Z.jsxs)(`span`,{className:`text-stone-400`,children:[` · `,(0,Z.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,Z.jsxs)(`span`,{className:`text-stone-400 text-shimmer-muted`,children:[` · `,`…`]}):null]})]},e.id))}):null,s&&e.reasoning?(0,Z.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,Z.jsx)(`div`,{className:`mt-1.5 pl-5.5`,children:(0,Z.jsx)(`span`,{className:`tw-turn-stopped-pill`,children:`已停止`})}):null]})})(),e.content?(0,Z.jsx)(`div`,{className:`chat-md prose prose-sm prose-stone max-w-none tw-chat-text`,dangerouslySetInnerHTML:{__html:Dt(e.content)}}):null,e.caseFile?(0,Z.jsxs)(`button`,{type:`button`,"data-focus-doc":`cases:${e.caseFile.path.replace(/\\/g,`/`)}`,"data-hint":`双击本地打开`,onDoubleClick:()=>{Te(`cases`,e.caseFile.path).catch(e=>B(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,Z.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,Z.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`span`,{className:`block text-sm text-stone-800 truncate`,children:e.caseFile.name}),(0,Z.jsxs)(`span`,{className:`block text-[11px] text-stone-400 truncate`,children:[De(`cases`),e.caseFile.path,e.caseFile.count>0?` · ${e.caseFile.count} 条`:``,` · 双击本地打开`]})]})]}):null,e.docsFile?(0,Z.jsxs)(`button`,{type:`button`,"data-focus-doc":`${e.docsFile.root}:${e.docsFile.path.replace(/\\/g,`/`)}`,"data-hint":`点击本地打开`,onClick:()=>{Te(e.docsFile.root,e.docsFile.path).catch(e=>B(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,Z.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,Z.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`span`,{className:`block text-sm text-stone-800 truncate`,children:e.docsFile.name}),(0,Z.jsxs)(`span`,{className:`block text-[11px] text-stone-400 truncate`,children:[De(e.docsFile.root),e.docsFile.path,e.docsFile.note?` · ${e.docsFile.note}`:``,` · 点击打开`]})]})]}):null,e.presentFiles?.length?e.presentFiles.map(e=>(0,Z.jsxs)(`button`,{type:`button`,"data-hint":`点击本地打开`,onClick:()=>{Nt(e.path,Zt).catch(e=>B(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,Z.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,Z.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`span`,{className:`block text-sm text-stone-800 truncate`,children:e.name}),(0,Z.jsxs)(`span`,{className:`block text-[11px] text-stone-400 truncate`,children:[e.path,e.description?` · ${e.description}`:``,` · 点击打开`]})]})]},e.path)):null,e.content&&!(n===c.length-1&&ht)?(0,Z.jsxs)(`div`,{className:`tw-msg-actions mt-1 ${xc(n)}`,children:[(0,Z.jsx)(Su,{text:e.content}),e.usage&&(0,Z.jsx)(Au,{usage:e.usage,model:e.model??t?.model}),e.time!=null&&(0,Z.jsx)(`span`,{className:`tw-msg-action-time`,children:bu(e.time)})]}):null]},n))})}),$t&&(0,Z.jsx)(`button`,{type:`button`,onClick:Po,"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,Z.jsx)(Vl,{className:`w-4 h-4`})})]},`dialog-${a?.activeId??``}`),Ot&&(0,Z.jsx)(`div`,{className:`shrink-0 px-8 sm:px-10 lg:px-12 pb-2`,children:(0,Z.jsxs)(`div`,{ref:Ea,className:`w-full max-w-[min(64rem,100%)] mx-auto flex items-start gap-3 px-4 py-3 rounded-xl text-sm border ${Yt===`ok`?`tw-notice-anim`:``} ${Yt===`ok`?`bg-emerald-50 border-emerald-200 text-emerald-900`:`bg-red-50 border-red-200 text-red-800`}`,children:[(0,Z.jsx)(`span`,{className:`mt-0.5 w-5 h-5 shrink-0 rounded-full flex items-center justify-center text-xs font-semibold ${Yt===`ok`?`bg-emerald-100 text-emerald-700`:`bg-red-100 text-red-600`}`,children:Yt===`ok`?`i`:`!`}),(0,Z.jsx)(`pre`,{className:`flex-1 min-w-0 m-0 font-sans text-[13px] leading-5 whitespace-pre-wrap break-words`,children:Ot.replace(/\*\*/g,``).replace(/\s*:\s*\*\*/g,`: `).trim()}),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>B(null),className:`shrink-0 text-xs ${Yt===`ok`?`text-emerald-500 hover:text-emerald-700`:`text-red-400 hover:text-red-600`}`,children:`关闭`})]})}),(0,Z.jsxs)(`div`,{className:`shrink-0 px-8 sm:px-10 lg:px-12 pb-5`,children:[(0,Z.jsxs)(`div`,{className:`w-full max-w-[min(64rem,100%)] mx-auto`,children:[oe?.active&&V.promptGen?(0,Z.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,Z.jsxs)(`span`,{className:`flex-1 min-w-0 truncate`,children:[`生成提示词已启用 · `,Oi(oe)]}),(0,Z.jsx)(`button`,{type:`button`,className:`shrink-0 hover:underline`,onClick:()=>P(!0),children:`改配置`}),(0,Z.jsx)(`button`,{type:`button`,className:`shrink-0 text-stone-500 hover:text-stone-800`,onClick:()=>As(null),children:`取消`})]}):null,F?.active&&V.knowledgeGen?(0,Z.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,Z.jsxs)(`span`,{className:`flex-1 min-w-0 truncate`,children:[`生成知识库已启用 · `,Hi(F)]}),(0,Z.jsx)(`button`,{type:`button`,className:`shrink-0 hover:underline`,onClick:()=>ue(!0),children:`改配置`}),(0,Z.jsx)(`button`,{type:`button`,className:`shrink-0 text-stone-500 hover:text-stone-800`,onClick:()=>js(null),children:`取消`})]}):null,j?.active&&V.caseGen?(0,Z.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,Z.jsxs)(`span`,{className:`flex-1 min-w-0 truncate`,children:[`生成测试用例已启用 · `,pi(j)]}),(0,Z.jsx)(`button`,{type:`button`,className:`shrink-0 hover:underline`,onClick:()=>te(!0),children:`改配置`}),(0,Z.jsx)(`button`,{type:`button`,className:`shrink-0 text-stone-500 hover:text-stone-800`,onClick:()=>ks(null),children:`取消`})]}):null,hr.length>0?(0,Z.jsx)(`div`,{className:`mb-2 rounded-xl border border-stone-200/80 bg-stone-100/80 overflow-hidden`,children:hr.map(e=>(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 border-b border-stone-200/60 last:border-b-0`,children:[(0,Z.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-stone-400 shrink-0`,"aria-hidden":!0}),(0,Z.jsx)(`span`,{className:`flex-1 min-w-0 truncate text-[13px] text-stone-700`,children:ya(e)}),(0,Z.jsx)(`button`,{type:`button`,"data-hint":`编辑回输入框`,onClick:()=>gs(e.id),className:`tw-icon-btn w-7 h-7 rounded-md flex items-center justify-center outline-none`,children:(0,Z.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Z.jsx)(`path`,{d:`M12 20h9`}),(0,Z.jsx)(`path`,{d:`M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z`})]})}),(0,Z.jsx)(`button`,{type:`button`,"data-hint":`从队列移除`,onClick:()=>hs(e.id),className:`tw-icon-btn w-7 h-7 rounded-md flex items-center justify-center outline-none`,children:(0,Z.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Z.jsx)(`path`,{d:`M3 6h18`}),(0,Z.jsx)(`path`,{d:`M8 6V4h8v2`}),(0,Z.jsx)(`path`,{d:`M19 6l-1 14H6L5 6`})]})}),(0,Z.jsx)(`button`,{type:`button`,"data-hint":`插话立即发送(其后队列仍会续发)`,onClick:()=>_s(e.id),className:`tw-icon-btn w-7 h-7 rounded-md flex items-center justify-center outline-none text-[#4176e6]`,children:(0,Z.jsx)(Yl,{className:`w-3.5 h-3.5`})})]},e.id))}):null,Di?(0,Z.jsxs)(`div`,{className:`mb-2 rounded-xl border border-amber-300/60 bg-amber-50/90 px-4 py-3 shadow-sm`,children:[(0,Z.jsx)(`div`,{className:`text-[13px] font-medium text-stone-800 mb-1`,children:`待批准计划`}),(0,Z.jsx)(`div`,{className:`text-[14px] font-medium text-stone-900`,children:Di.title}),Di.summary?(0,Z.jsx)(`p`,{className:`mt-1 text-[13px] text-stone-600 leading-5`,children:Di.summary}):null,(0,Z.jsx)(`ol`,{className:`mt-2 list-decimal pl-5 space-y-1 text-[13px] text-stone-700`,children:Di.steps.map((e,t)=>(0,Z.jsx)(`li`,{children:e},`${t}-${e.slice(0,24)}`))}),(0,Z.jsxs)(`div`,{className:`mt-3 flex items-center justify-end gap-2`,children:[(0,Z.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:()=>Is(),children:`驳回`}),(0,Z.jsx)(`button`,{type:`button`,className:`h-8 px-3 rounded-lg bg-[#4176e6] text-[12px] text-white hover:bg-[#3467d4]`,onClick:()=>Fs(),children:`批准实施`})]})]}):null,Ji?(0,Z.jsx)(_l,{kind:Ji.kind,items:Ji.items,manual:Ji.manual,quick:Ji.quick,quickNote:Ji.quickNote,tasksOn:V.tasks,closing:Qi,onConfirm:e=>{Ji.manual?(la(null),fa(Ji.kind,e)):la(e)},onCancel:()=>la(null)}):null,nl>0&&Q?(0,Z.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,Z.jsxs)(`div`,{className:`flex shrink-0 justify-between gap-4 px-5 ${zi?`items-center py-3.5`:`items-start pt-4`}`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`div`,{className:`mb-1 text-[11px] leading-4 text-stone-400`,children:Wi?`跳过确认`:Q.header||`模型需要你的确认`}),(0,Z.jsx)(`h3`,{className:`text-[15px] leading-5.5 font-medium text-stone-900`,children:Wi?`确认 ${dl.length} 道跳过的题怎么处理`:Q.question})]}),(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[zi?(0,Z.jsx)(`span`,{className:`text-[11px] leading-4 text-stone-400`,children:Wi?`已跳过 ${dl.length} 题`:`第 ${rl+1} 步 / 共 ${nl} 步`}):null,(0,Z.jsx)(`button`,{type:`button`,"aria-label":zi?`展开问题`:`收起问题`,onClick:()=>Bi(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,Z.jsx)(Vl,{className:`h-4 w-4 transition-transform ${zi?`rotate-180`:``}`})})]})]}),zi?null:Wi?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto overscroll-contain px-5 py-2`,children:[(0,Z.jsx)(`p`,{className:`text-[12px] leading-5 text-stone-500`,children:`跳过不算确认,本轮不会开始改代码。留下原因后我只出方案,等你回复「开始实施」。`}),(0,Z.jsx)(`ul`,{className:`mt-2 space-y-1 rounded-lg bg-stone-50 px-3 py-2`,children:dl.map(({q:e,index:t})=>(0,Z.jsxs)(`li`,{className:`text-[12px] leading-5 text-stone-600`,children:[(0,Z.jsxs)(`span`,{className:`text-stone-400`,children:[t+1,`.`]}),` `,e.header?`${e.header} / `:``,e.question,(0,Z.jsx)(`span`,{className:`ml-1 text-stone-400`,children:`— 已跳过`})]},e.id))}),(0,Z.jsx)(`textarea`,{autoFocus:!0,value:Ki,onChange:e=>qi(e.target.value),onKeyDown:e=>{e.key!==`Enter`||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),Js())},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,Z.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between gap-3 px-5 pt-2 pb-3`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:()=>Ys(),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,Z.jsx)(`button`,{type:`button`,onClick:()=>Js(),className:`h-8 shrink-0 rounded-lg bg-[#4176e6] px-3.5 text-[12px] font-medium text-white hover:bg-[#3467d4]`,children:`提交并继续`})]})]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto overscroll-contain px-3 py-1`,children:[Q.options?.length?(0,Z.jsx)(`div`,{className:`mt-2 flex flex-col gap-0.5`,role:Q.multi_select?`group`:`radiogroup`,children:Q.options.map((e,t)=>{let n=il.selected.includes(e.label),r=xl(e.label);return(0,Z.jsxs)(`button`,{type:`button`,role:Q.multi_select?`checkbox`:`radio`,"aria-checked":n,onClick:()=>Bs(Q,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:[Q.multi_select?(0,Z.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,Z.jsx)(Ul,{className:`h-3 w-3`})}):(0,Z.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,Z.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Z.jsxs)(`span`,{className:`flex flex-wrap items-center gap-x-2 gap-y-0.5`,children:[(0,Z.jsx)(`span`,{className:`text-[13px] leading-5 font-medium text-stone-800`,children:r.label}),r.recommended?(0,Z.jsx)(`span`,{className:`rounded bg-[#edf3fe] px-1 text-[10px] leading-4 font-semibold text-[#4176e6]`,children:`推荐`}):null]}),e.description?(0,Z.jsx)(`span`,{className:`mt-0.5 block text-[12px] leading-4.5 text-stone-400`,children:e.description}):null]})]},`${e.label}-${t}`)})}):(0,Z.jsx)(`div`,{className:`px-1.5 py-2`,children:(0,Z.jsx)(`textarea`,{autoFocus:!0,value:il.text,onChange:e=>Hs(Q,e.target.value),onKeyDown:e=>{e.key!==`Enter`||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),Us(Q,il.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:`输入你的回答…`})}),Q.options?.length?(0,Z.jsx)(`div`,{className:`mt-1 px-1.5 pb-1`,children:(0,Z.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,Z.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,Z.jsx)(`textarea`,{value:il.text,onChange:e=>Hs(Q,e.target.value),onKeyDown:e=>{e.key!==`Enter`||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),Us(Q,il.text))},rows:1,className:`min-h-5 w-full resize-none bg-transparent text-[13px] leading-5 outline-none`,placeholder:`输入序号选择(如 1${Q.multi_select?` 或 1,3`:``}),也可直接写你的回答`})]})}):null,(0,Z.jsx)(`div`,{className:`px-2 pb-2 pt-1 text-[11px] leading-4 text-stone-400`,children:Q.options?.length?`回车确认这一步;跳过的题会在提交前让你说明原因,不会直接开始实施`:`回车确认;跳过的题会在提交前让你说明原因,不会直接开始实施`})]}),(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between gap-3 px-5 pt-2 pb-3`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Z.jsx)(`button`,{type:`button`,"aria-label":`上一步`,disabled:rl===0,onClick:()=>Vs(rl-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,Z.jsx)(Hl,{className:`h-4 w-4 rotate-180`})}),(0,Z.jsxs)(`span`,{className:`px-1 text-[12px] font-medium text-stone-500`,children:[`第 `,rl+1,` 步 / 共 `,nl,` 步`]}),(0,Z.jsx)(`button`,{type:`button`,"aria-label":`下一步`,disabled:al,onClick:()=>Vs(rl+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,Z.jsx)(Hl,{className:`h-4 w-4`})})]}),(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[Vi?(0,Z.jsx)(`span`,{className:`truncate text-[11px] text-rose-500`,children:Vi}):null,(0,Z.jsx)(`button`,{type:`button`,onClick:()=>qs(),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,Z.jsx)(`button`,{type:`button`,disabled:!sl,onClick:()=>al?Gs():Vs(rl+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:al?`提交回答`:`下一步`})]})]})]})]}):null,(0,Z.jsxs)(`div`,{ref:Da,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||b.length>0||Ci.length>0)&&(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-1.5 px-3 pt-0.5 pb-2`,children:[Ci.map(e=>(0,Z.jsxs)(`span`,{className:`flex items-center gap-1.5 rounded-lg border border-[#4176e6]/25 bg-[#edf3fe] py-1 pr-1 pl-2.5 text-xs text-[#4176e6]`,children:[(0,Z.jsxs)($,{className:`h-3.5 w-3.5 shrink-0`,children:[(0,Z.jsx)(`path`,{d:`M14 3v4a1 1 0 0 0 1 1h4`}),(0,Z.jsx)(`path`,{d:`M5 3h9l5 5v13H5z`}),(0,Z.jsx)(`path`,{d:`M8 13h8`}),(0,Z.jsx)(`path`,{d:`M8 17h5`})]}),(0,Z.jsx)(`span`,{className:`shrink-0 text-[10px] text-[#4176e6]/80`,children:`要求`}),(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>Ei(e),className:`max-w-56 truncate text-left hover:underline`,children:[e.label,(0,Z.jsx)($,{className:`ml-1 inline h-3 w-3 shrink-0 opacity-50`,children:(0,Z.jsx)(`path`,{d:`m6 9 6 6 6-6`})})]}),e.detail?(0,Z.jsx)(`span`,{className:`max-w-44 truncate text-[10px] text-[#4176e6]/70`,children:e.detail}):null,(0,Z.jsx)(`button`,{type:`button`,onClick:()=>ts(e.id),className:`flex h-5 w-5 items-center justify-center rounded text-[#4176e6]/70 hover:bg-white/80 hover:text-[#4176e6]`,children:(0,Z.jsxs)($,{className:`h-3 w-3`,children:[(0,Z.jsx)(`path`,{d:`M18 6 6 18`}),(0,Z.jsx)(`path`,{d:`m6 6 12 12`})]})})]},e.id)),S.map(e=>(0,Z.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,Z.jsx)(ql,{className:`w-3.5 h-3.5`}),(0,Z.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:oc(e.format)}),(0,Z.jsx)(`span`,{className:`max-w-48 truncate`,children:e.title}),(0,Z.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,Z.jsxs)($,{className:`w-3 h-3`,children:[(0,Z.jsx)(`path`,{d:`M18 6 6 18`}),(0,Z.jsx)(`path`,{d:`m6 6 12 12`})]})})]},`${e.collection}:${e.path}`)),f.map((e,t)=>(0,Z.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,Z.jsx)(ql,{className:`w-3.5 h-3.5`}),(0,Z.jsx)(`span`,{className:`text-[10px] text-[#4176e6]/80 shrink-0`,children:`文件`}),(0,Z.jsx)(`span`,{className:`max-w-48 truncate`,children:e.name}),(0,Z.jsx)(`button`,{type:`button`,"data-hint":`移除`,onClick:()=>m(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,Z.jsxs)($,{className:`w-3 h-3`,children:[(0,Z.jsx)(`path`,{d:`M18 6 6 18`}),(0,Z.jsx)(`path`,{d:`m6 6 12 12`})]})})]},`${e.name}-${t}`)),b.map(e=>(0,Z.jsxs)(`span`,{className:`relative group inline-flex rounded-lg border border-stone-200 overflow-hidden bg-stone-50`,"data-hint":`${e.name} · ${yu(e.size)}`,children:[(0,Z.jsx)(`img`,{src:e.dataUrl,alt:e.name,className:`h-14 w-14 object-cover`}),(0,Z.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,Z.jsxs)($,{className:`w-3 h-3`,children:[(0,Z.jsx)(`path`,{d:`M18 6 6 18`}),(0,Z.jsx)(`path`,{d:`m6 6 12 12`})]})})]},e.id))]}),(0,Z.jsxs)(`div`,{className:`relative`,children:[lr&&!Ba&&!Ia&&(0,Z.jsx)(`div`,{ref:Ta,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,Z.jsxs)(`div`,{className:`tw-dsh-scroll h-full overflow-y-auto overflow-x-hidden`,children:[(0,Z.jsx)(`div`,{className:`px-3 pt-0.5 pb-1.5 text-[11px] font-medium text-stone-400 tracking-wide`,children:`添加`}),(0,Z.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>{ur(!1),Sa.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,Z.jsx)(Jl,{className:`w-4 h-4 shrink-0 text-stone-500`}),(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1 text-[13px] text-stone-800`,children:[`文件`,(0,Z.jsx)(`span`,{className:`ml-1.5 text-stone-400 font-normal`,children:`file`})]}),(0,Z.jsx)(`span`,{className:`shrink-0 max-w-[45%] text-right text-[11px] text-stone-400 truncate`,children:`添加本地附件`})]}),(0,Z.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>{ur(!1),as()},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,Z.jsxs)($,{className:`w-4 h-4 shrink-0 text-stone-500`,children:[(0,Z.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`}),(0,Z.jsx)(`circle`,{cx:`12`,cy:`12`,r:`6`}),(0,Z.jsx)(`circle`,{cx:`12`,cy:`12`,r:`2`})]}),(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1 text-[13px] text-stone-800`,children:[`目标`,(0,Z.jsx)(`span`,{className:`ml-1.5 text-stone-400 font-normal`,children:`goal`})]}),(0,Z.jsx)(`span`,{className:`shrink-0 max-w-[45%] text-right text-[11px] text-stone-400 truncate`,children:`设置或查看长期任务目标`})]}),(0,Z.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>{ur(!1),mi===`off`?ss():Ls()},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 ${mi===`planning`?`bg-amber-50`:mi===`approved`?`bg-emerald-50`:``}`,children:[(0,Z.jsxs)($,{className:`w-4 h-4 shrink-0 ${mi===`planning`?`text-amber-800`:mi===`approved`?`text-emerald-800`:`text-stone-500`}`,children:[(0,Z.jsx)(`path`,{d:`M8 6h13`}),(0,Z.jsx)(`path`,{d:`M8 12h13`}),(0,Z.jsx)(`path`,{d:`M8 18h13`}),(0,Z.jsx)(`path`,{d:`M3 6h.01`}),(0,Z.jsx)(`path`,{d:`M3 12h.01`}),(0,Z.jsx)(`path`,{d:`M3 18h.01`})]}),(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1 text-[13px] text-stone-800`,children:[`计划`,(0,Z.jsx)(`span`,{className:`ml-1.5 text-stone-400 font-normal`,children:`plan`})]}),(0,Z.jsx)(`span`,{className:`shrink-0 max-w-[45%] text-right text-[11px] text-stone-400 truncate`,children:`进入或退出计划模式`})]}),V.todos||V.tasks?(0,Z.jsxs)(Z.Fragment,{children:[V.todos?(0,Z.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>da(`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,Z.jsxs)($,{className:`w-4 h-4 shrink-0 text-stone-500`,children:[(0,Z.jsx)(`path`,{d:`M8 6h13`}),(0,Z.jsx)(`path`,{d:`M8 12h13`}),(0,Z.jsx)(`path`,{d:`M8 18h13`}),(0,Z.jsx)(`path`,{d:`M3 6h.01`}),(0,Z.jsx)(`path`,{d:`M3 12h.01`}),(0,Z.jsx)(`path`,{d:`M3 18h.01`})]}),(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1 text-[13px] text-stone-800`,children:[`待办`,(0,Z.jsx)(`span`,{className:`ml-1.5 text-stone-400 font-normal`,children:`todo`})]}),(0,Z.jsx)(`span`,{className:`shrink-0 max-w-[45%] text-right text-[11px] text-stone-400 truncate`,children:`手动添加一条待办`})]}):null,V.tasks?(0,Z.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>da(`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,Z.jsxs)($,{className:`w-4 h-4 shrink-0 text-stone-500`,children:[(0,Z.jsx)(`path`,{d:`M9 5h10`}),(0,Z.jsx)(`path`,{d:`M9 12h10`}),(0,Z.jsx)(`path`,{d:`M9 19h10`}),(0,Z.jsx)(`path`,{d:`M4 5h.01`}),(0,Z.jsx)(`path`,{d:`M4 12h.01`}),(0,Z.jsx)(`path`,{d:`M4 19h.01`})]}),(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1 text-[13px] text-stone-800`,children:[`任务`,(0,Z.jsx)(`span`,{className:`ml-1.5 text-stone-400 font-normal`,children:`task`})]}),(0,Z.jsx)(`span`,{className:`shrink-0 max-w-[45%] text-right text-[11px] text-stone-400 truncate`,children:`手动添加一个任务`})]}):null]}):null,Ra.length?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`div`,{className:`my-1 border-t border-stone-100`}),(0,Z.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>pr(e=>!e),className:`w-full flex items-center gap-2 px-3 py-1.5 text-left hover:bg-stone-50`,children:[(0,Z.jsx)(`span`,{className:`flex-1 text-[11px] font-medium text-stone-400 tracking-wide`,children:`扩展插件`}),(0,Z.jsx)(Vl,{className:`w-3.5 h-3.5 text-stone-400 shrink-0 transition-transform ${dr?`rotate-180`:``}`})]}),dr?Ra.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,Z.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>{ur(!1),jo(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,Z.jsx)(ru,{className:`w-4 h-4 shrink-0 text-stone-500`}),(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1 text-[13px] text-stone-800`,children:[e.name,t?(0,Z.jsx)(`span`,{className:`ml-1.5 text-stone-400 font-normal`,children:t}):null]}),n?(0,Z.jsx)(`span`,{className:`shrink-0 max-w-[45%] text-right text-[11px] text-stone-400 truncate`,children:n}):null]},e.id)}):null]}):null,(0,Z.jsx)(`div`,{className:`my-1 border-t border-stone-100`}),(0,Z.jsx)(`div`,{className:`px-3 pt-1 pb-1.5 text-[11px] font-medium text-stone-400 tracking-wide`,children:`指令`}),(0,Z.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>{ur(!1),Zr.current?B(`请等待当前回复结束后再压缩`):ds({force:!0}).then(e=>{e&&B(`已压缩上下文`)})},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,Z.jsx)($,{className:`w-4 h-4 shrink-0 text-stone-500`,children:(0,Z.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`})}),(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1 text-[13px] text-stone-800`,children:[`压缩`,(0,Z.jsx)(`span`,{className:`ml-1.5 text-stone-400 font-normal`,children:`compact`})]}),(0,Z.jsx)(`span`,{className:`shrink-0 max-w-[45%] text-right text-[11px] text-stone-400 truncate`,children:`压缩以上对话内容`})]}),(0,Z.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>{ur(!1),nc()},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,Z.jsxs)($,{className:`w-4 h-4 shrink-0 text-stone-500`,children:[(0,Z.jsx)(`path`,{d:`M3 3v18h18`}),(0,Z.jsx)(`path`,{d:`M7 14v4`}),(0,Z.jsx)(`path`,{d:`M12 10v8`}),(0,Z.jsx)(`path`,{d:`M17 6v12`})]}),(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1 text-[13px] text-stone-800`,children:[`会话统计`,(0,Z.jsx)(`span`,{className:`ml-1.5 text-stone-400 font-normal`,children:`stats`})]}),(0,Z.jsx)(`span`,{className:`shrink-0 max-w-[45%] text-right text-[11px] text-stone-400 truncate`,children:`查看本会话用量摘要`})]})]})}),Ba&&(0,Z.jsxs)(`div`,{ref:wa,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,Z.jsx)(`div`,{className:`px-3 py-1.5 text-[11px] text-stone-400`,children:`插件`}),Ra.map((e,t)=>(0,Z.jsxs)(`button`,{type:`button`,"data-plugin-index":t,onMouseDown:e=>e.preventDefault(),onMouseEnter:()=>R(t),onClick:()=>jo(e.id),className:`tw-composer-menu-item w-full text-left px-3 py-2 rounded-lg transition-colors ${t===ve?`is-active`:``}`,children:[(0,Z.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,Z.jsx)(`div`,{className:`text-[13px] font-medium text-stone-800 flex-1`,children:e.name})}),(0,Z.jsx)(`div`,{className:`mt-0.5 text-xs text-stone-400 line-clamp-2`,children:e.description})]},e.id))]}),Ia&&(0,Z.jsx)(`div`,{ref:Ca,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:Fa.length===0?(0,Z.jsxs)(`div`,{className:`px-3 py-2 text-xs text-stone-400 space-y-1`,children:[wr?(0,Z.jsx)(`p`,{children:`项目文档:无匹配`}):null,ka?(0,Z.jsx)(`p`,{children:`工作区:无匹配`}):(0,Z.jsx)(`p`,{children:`工作区:请先在侧栏添加并选择工作区`}),wr?null:(0,Z.jsxs)(`p`,{children:[`「知识库检索」未启用:启用后才能用 @ 引用`,Oe(`knowledge`),` / `,Oe(`templates`),`文档`]})]}):(0,Z.jsxs)(Z.Fragment,{children:[Ma.length>0?(0,Z.jsxs)(`div`,{className:`px-3 py-1.5 text-[11px] font-medium text-stone-400`,children:[`项目文档(`,Oe(`knowledge`),` / `,Oe(`templates`),`)`]}):null,Fa.map((e,t)=>{let n=e.doc,r=Fa[t-1],i=e.section===`workspace`&&r?.section!==`workspace`;return(0,Z.jsxs)(`div`,{children:[i?(0,Z.jsxs)(Z.Fragment,{children:[Ma.length>0?(0,Z.jsx)(`div`,{className:`my-1 mx-2 border-t border-stone-200`,role:`separator`}):null,(0,Z.jsx)(`div`,{className:`px-3 py-1.5 text-[11px] font-medium text-stone-400`,children:`工作区`})]}):null,(0,Z.jsxs)(`button`,{type:`button`,"data-mention-index":t,onMouseDown:e=>e.preventDefault(),onClick:()=>Oo(n),className:`tw-composer-menu-item w-full text-left px-3 py-2 rounded-lg transition-colors ${t===tr?`is-active`:``}`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-[13px] text-stone-800`,children:[(0,Z.jsx)(`span`,{className:`text-[11px] px-1.5 py-0.5 rounded bg-stone-100 text-stone-500 shrink-0`,children:n.collection===`knowledge`?Oe(`knowledge`):n.collection===`templates`?Oe(`templates`):n.format===`dir`?`文件夹`:`文件`}),n.collection===`workspace`?null:(0,Z.jsx)(`span`,{className:`text-[11px] px-1.5 py-0.5 rounded bg-stone-100 text-stone-500 shrink-0`,children:oc(n.format)}),(0,Z.jsx)(`span`,{className:`truncate font-medium`,children:n.title})]}),(0,Z.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}`)}),wr?null:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`div`,{className:`my-1 mx-2 border-t border-stone-200`,role:`separator`}),(0,Z.jsx)(`p`,{className:`px-3 py-1.5 text-[11px] text-stone-400`,children:`「知识库检索」未启用:@ 仅引用工作区文件`})]})]})}),(0,Z.jsxs)(`div`,{className:`flex items-start gap-2 px-3`,children:[gi===`goal`?(0,Z.jsxs)(`span`,{className:`tw-composer-mode-chip is-goal`,"data-hint":`会话目标`,children:[(0,Z.jsxs)($,{className:`w-3.5 h-3.5 shrink-0`,children:[(0,Z.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`}),(0,Z.jsx)(`circle`,{cx:`12`,cy:`12`,r:`6`}),(0,Z.jsx)(`circle`,{cx:`12`,cy:`12`,r:`2`})]}),(0,Z.jsx)(`span`,{children:`目标`}),(0,Z.jsx)(`button`,{type:`button`,"aria-label":`取消目标输入`,onClick:()=>yi(null),children:(0,Z.jsxs)($,{className:`w-3 h-3`,children:[(0,Z.jsx)(`path`,{d:`M18 6 6 18`}),(0,Z.jsx)(`path`,{d:`m6 6 12 12`})]})})]}):null,gi===`plan`?(0,Z.jsxs)(`span`,{className:`tw-composer-mode-chip is-plan${mi===`approved`?` is-approved`:``}`,"data-hint":mi===`approved`?`计划模式·已批准`:`计划模式·探查中`,children:[(0,Z.jsxs)($,{className:`w-3.5 h-3.5 shrink-0`,children:[(0,Z.jsx)(`path`,{d:`M8 6h13`}),(0,Z.jsx)(`path`,{d:`M8 12h13`}),(0,Z.jsx)(`path`,{d:`M8 18h13`}),(0,Z.jsx)(`path`,{d:`M3 6h.01`}),(0,Z.jsx)(`path`,{d:`M3 12h.01`}),(0,Z.jsx)(`path`,{d:`M3 18h.01`})]}),(0,Z.jsx)(`span`,{children:`计划`}),(0,Z.jsx)(`button`,{type:`button`,"aria-label":`退出计划模式`,onClick:()=>is(),children:(0,Z.jsxs)($,{className:`w-3 h-3`,children:[(0,Z.jsx)(`path`,{d:`M18 6 6 18`}),(0,Z.jsx)(`path`,{d:`m6 6 12 12`})]})})]}):null,gi===`pluginDev`?(0,Z.jsxs)(`span`,{className:`tw-composer-mode-chip is-plugin-dev`,children:[(0,Z.jsxs)($,{className:`w-3.5 h-3.5 shrink-0`,children:[(0,Z.jsx)(`path`,{d:`M9 7V3`}),(0,Z.jsx)(`path`,{d:`M15 7V3`}),(0,Z.jsx)(`path`,{d:`M6 7h12v4a6 6 0 0 1-12 0V7Z`}),(0,Z.jsx)(`path`,{d:`M12 17v4`})]}),(0,Z.jsx)(`span`,{children:`插件开发`}),(0,Z.jsx)(`button`,{type:`button`,"aria-label":`退出插件开发`,onClick:()=>is(),children:(0,Z.jsxs)($,{className:`w-3 h-3`,children:[(0,Z.jsx)(`path`,{d:`M18 6 6 18`}),(0,Z.jsx)(`path`,{d:`m6 6 12 12`})]})})]}):null,gi===`reports`?(0,Z.jsxs)(`span`,{className:`tw-composer-mode-chip is-report`,children:[(0,Z.jsxs)($,{className:`w-3.5 h-3.5 shrink-0`,children:[(0,Z.jsx)(`path`,{d:`M14 3v4a1 1 0 0 0 1 1h4`}),(0,Z.jsx)(`path`,{d:`M5 3h9l5 5v13H5z`}),(0,Z.jsx)(`path`,{d:`M8 13h8`}),(0,Z.jsx)(`path`,{d:`M8 17h5`})]}),(0,Z.jsxs)(`span`,{children:[`生成`,br[bi]]}),(0,Z.jsx)(`button`,{type:`button`,"aria-label":`取消汇报生成`,onClick:()=>is(),children:(0,Z.jsxs)($,{className:`w-3 h-3`,children:[(0,Z.jsx)(`path`,{d:`M18 6 6 18`}),(0,Z.jsx)(`path`,{d:`m6 6 12 12`})]})})]}):null,(0,Z.jsx)(`textarea`,{ref:xa,value:u,onChange:e=>d(e.target.value),onPaste:mc,onKeyDown:e=>{if(Ba&&Ra.length){if(e.key===`ArrowDown`){e.preventDefault(),R(e=>(e+1)%Ra.length);return}if(e.key===`ArrowUp`){e.preventDefault(),R(e=>(e-1+Ra.length)%Ra.length);return}if(e.key===`Escape`){e.preventDefault(),cr(!0),La&&d(u.slice(0,La.from));return}if(e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing){e.preventDefault();let t=Ra[ve]??Ra[0];t&&jo(t.id);return}}if(Ia&&Fa.length){if(e.key===`ArrowDown`){e.preventDefault(),rr(e=>(e+1)%Fa.length);return}if(e.key===`ArrowUp`){e.preventDefault(),rr(e=>(e-1+Fa.length)%Fa.length);return}if(e.key===`Escape`){e.preventDefault(),or(!0),ja&&d(u.slice(0,ja.from));return}if(e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing){e.preventDefault();let t=Fa[tr]?.doc;t&&Oo(t);return}}if(e.key===`Escape`&&lr)e.preventDefault(),ur(!1);else if(e.key===`Escape`&&(ja||La)){e.preventDefault(),or(!0),cr(!0);let t=ja?.from??La?.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(Zr.current){if(t){let e=u.trim();if(e||f.length>0||b.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:[...b]};rs(),vs(t)}else J.current.length&&vs();return}fs(void 0,{forceBusy:Ve().busySendBehavior??`queue`})}else fs()}},rows:1,placeholder:t?Ci.length>0?`可补充说明;直接发送会带上「要求」里的完整内容`:hr.length>0&&ht?`Cmd/Ctrl+Enter 插话发送全部排队消息`:wr?`请输入内容,或用 @ 引用文档`:ka?`请输入内容,或用 @ 引用工作区文件`:`请输入内容(@ 引用文档需先启用「知识库检索」)`:`请先配置模型(左下角「设置」→ 模型)`,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,Z.jsxs)(`div`,{className:`tw-composer-bar flex items-center gap-1.5 px-3 pb-3 pt-3`,children:[(0,Z.jsx)(`button`,{type:`button`,"data-add-menu-btn":!0,"aria-label":mi===`off`?`添加`:mi===`planning`?`添加(计划模式·探查中)`:`添加(计划模式·已批准)`,onClick:()=>{ur(e=>!e),or(!0),cr(!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 ${lr?`bg-(--tw-session-hover-bg)`:``}`,children:(0,Z.jsxs)($,{className:`w-4 h-4`,children:[(0,Z.jsx)(`path`,{d:`M5 12h14`}),(0,Z.jsx)(`path`,{d:`M12 5v14`})]})}),q&&(0,Z.jsxs)(D,{children:[(0,Z.jsxs)(O,{title:zc?`工作区:${zc}`:`选择工作区`,"aria-label":Vc?`工作区:${Vc}`:`选择工作区`,disabled:Cn,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,Z.jsx)(Xl,{className:`w-3.5 h-3.5 shrink-0 text-stone-500`}),(0,Z.jsx)(`span`,{className:`tw-composer-bar-label truncate`,children:Vc}),(0,Z.jsx)(Vl,{className:`tw-composer-bar-chevron w-3.5 h-3.5 shrink-0 text-stone-400 transition-transform group-data-[open]:rotate-180`})]}),(0,Z.jsxs)(T,{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:[(H?.items??[]).map(e=>{let t=e.path===zc;return(0,Z.jsx)(E,{children:(0,Z.jsxs)(`button`,{type:`button`,disabled:Cn,onClick:()=>void fo(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,Z.jsx)(Xl,{className:`w-4 h-4 shrink-0 text-stone-500`}),(0,Z.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:jt(e,Nc)}),t&&(0,Z.jsx)(Ul,{className:`w-3.5 h-3.5 shrink-0 text-[#4176e6]`})]})},e.id)}),(H?.items?.length??0)>0&&(0,Z.jsx)(`div`,{className:`my-1 border-t border-stone-100`}),(0,Z.jsx)(E,{children:(0,Z.jsxs)(`button`,{type:`button`,disabled:Cn,onClick:()=>void po(),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,Z.jsx)(`span`,{className:`w-4 h-4 shrink-0 flex items-center justify-center text-stone-500 text-base leading-none`,children:`+`}),`添加工作区...`]})})]})]}),(0,Z.jsxs)(D,{children:[(0,Z.jsxs)(O,{title:`访问权限:${Cc.label}`,"aria-label":`访问权限:${Cc.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,Z.jsx)(uu,{level:Zt,className:`w-3.5 h-3.5 shrink-0 text-stone-500`}),(0,Z.jsx)(`span`,{className:`tw-composer-bar-label truncate`,children:Cc.label}),(0,Z.jsx)(`span`,{className:`ml-0.5 w-1.5 h-1.5 rounded-full shrink-0 ${q?`bg-emerald-500`:`bg-stone-300`}`,"data-hint":q?`Runner 在线`:`Runner 离线`}),(0,Z.jsx)(Vl,{className:`tw-composer-bar-chevron w-3.5 h-3.5 shrink-0 text-stone-400 transition-transform group-data-[open]:rotate-180`})]}),(0,Z.jsxs)(T,{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,Z.jsx)(`div`,{className:`px-3 py-1.5 text-[11px] text-stone-400`,children:q?`本地文件服务已连接`:`本地文件服务未就绪`}),Nl.map(e=>{let t=wc&&e.value===`readonly`;return(0,Z.jsx)(E,{disabled:t,children:(0,Z.jsxs)(`button`,{type:`button`,disabled:t,onClick:()=>{Qt(e.value),Y.current&&X(z(Y.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,Z.jsx)(uu,{level:e.value,className:`w-4 h-4 shrink-0 ${t?`text-stone-300`:`text-stone-500`}`}),(0,Z.jsx)(`span`,{className:`flex-1 ${t?`text-stone-400`:Zt===e.value?`text-stone-900 font-medium`:`text-stone-700`}`,children:e.label}),t?(0,Z.jsx)(`span`,{className:`text-[11px] text-stone-400`,children:`插件开发需要写入`}):Zt===e.value?(0,Z.jsx)(Ul,{className:`w-3.5 h-3.5 text-[#4176e6]`}):null]})},e.value)})]})]}),(0,Z.jsx)(`span`,{className:`flex-1`}),(0,Z.jsx)(ju,{settings:t}),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>{Zr.current?ms():fs()},disabled:!ht&&!_c,"aria-label":ht?`停止生成`:`发送`,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 ${ht?`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:ht?(0,Z.jsx)(`span`,{className:`w-2.5 h-2.5 bg-current rounded-xs`}):(0,Z.jsx)(Yl,{className:`w-4 h-4`})})]})]}),(0,Z.jsx)(ku,{messages:c,model:t?.model,systemPromptTokens:hu(w)})]}),(0,Z.jsx)(`input`,{ref:Sa,type:`file`,multiple:!0,hidden:!0,accept:[...vc.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 cc(e)})]})]})]}),be?(0,Z.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,Z.jsx)(mr,{embedded:!0})}):null,(0,Z.jsx)(Uc,{open:ee,initial:j,presetStories:ie,onClose:()=>{te(!1),ae(null)},onConfirm:e=>ks(e)}),(0,Z.jsx)(Wc,{open:N,initial:oe,onClose:()=>P(!1),onConfirm:e=>As(e)}),(0,Z.jsx)(Gc,{open:le,initial:F,onClose:()=>ue(!1),onConfirm:e=>js(e)}),(0,Z.jsx)(Tr,{open:!!Se,title:`重命名会话`,label:`会话名称`,placeholder:`请输入会话名称`,initialValue:Se?a?.sessions.find(e=>e.id===Se)?.title??``:``,confirmLabel:`保存`,cancelLabel:`取消`,onClose:()=>Ee(null),onConfirm:rc}),(0,Z.jsx)(Tr,{open:!!Ue,title:`重命名工作区`,label:`显示名称`,placeholder:`请输入工作区名称`,initialValue:Ue?H?.items.find(e=>e.id===Ue)?.name??``:``,confirmLabel:`保存`,cancelLabel:`取消`,onClose:()=>st(null),onConfirm:e=>void wo(e)}),(0,Z.jsx)(Kc,{task:Ti,onClose:()=>Ei(null),onSave:es,onRemove:()=>{Ti&&ts(Ti.id)}}),(0,Z.jsx)(A,{open:!!ke,title:`删除会话`,message:ke?`确定永久删除「${a?.sessions.find(e=>e.id===ke)?.title??`该会话`}」?此操作不可恢复。`:``,confirmLabel:`删除`,cancelLabel:`取消`,danger:`outline`,onClose:()=>Ae(null),onConfirm:()=>{if(!ke)return;let e=ke;Ae(null),Zs(e)}}),(0,Z.jsx)(A,{open:!!Le,title:`删除工作区`,message:Le?`将把「${Le.name}」从工作区列表中移除。文件夹与会话记录会保留,其会话将归入项目根工作区。`:``,confirmLabel:`删除工作区`,cancelLabel:`取消`,danger:`outline`,onClose:()=>He(null),onConfirm:()=>void mo()})]})}export{Pu as default};