lantern-harness 0.1.18 → 0.1.19

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 (69) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/dist/500.html +3 -3
  3. package/dist/_astro/{Base.astro_astro_type_script_index_0_lang.DZ45xGEk.js → Base.astro_astro_type_script_index_0_lang.BMvdPyIE.js} +1 -1
  4. package/dist/_astro/CaseGenerateApp.DLcUOrpS.js +9 -0
  5. package/dist/_astro/CasesLibrary.BERmgS2j.js +19 -0
  6. package/dist/_astro/{ChatApp.D9NIekGO.js → ChatApp.azDLrlxw.js} +8 -8
  7. package/dist/_astro/KnowledgeLibrary.D0r8ieOZ.js +1 -0
  8. package/dist/_astro/PluginsPage.BNlpKMUM.js +1 -0
  9. package/dist/_astro/{PluginsPage.Bhyuqbq0.js → PluginsPage.Du4g_yr4.js} +1 -1
  10. package/dist/_astro/PromptsLibrary.17cDZsjQ.js +1 -0
  11. package/dist/_astro/ReqAnalysisBoard.CBgma-zG.js +29 -0
  12. package/dist/_astro/{RequirementsLibrary.CgzwlAXi.js → RequirementsLibrary.B5TE-2Ds.js} +1 -1
  13. package/dist/_astro/{SettingsDialog.CDlXEl-R.js → SettingsDialog.BMa8eGFr.js} +1 -1
  14. package/dist/_astro/{SpaceSwitcher.DMoqOVpS.js → SpaceSwitcher.B8dzGxrR.js} +1 -1
  15. package/dist/_astro/{TemplatesLibrary.B5KmjjFw.js → TemplatesLibrary.DazYm5Sh.js} +1 -1
  16. package/dist/_astro/{UiAutoBoard.DJljpjXT.js → UiAutoBoard.BwKG4DcV.js} +1 -1
  17. package/dist/_astro/app-version.CdxtY1WM.js +1 -0
  18. package/dist/_astro/project-docs.DAw9bzgk.js +1 -0
  19. package/dist/_astro/req-analysis.DGQa1vaH.js +6 -0
  20. package/dist/_astro/{story-review.C5gzEzBP.js → story-review.BjrulZG8.js} +1 -1
  21. package/dist/_astro/{ui-auto-prompt.QcLCZoV6.js → ui-auto-prompt.l_EXfDs5.js} +2 -2
  22. package/dist/case-exec/index.html +3 -3
  23. package/dist/cases/generate/index.html +4 -4
  24. package/dist/cases/library/index.html +4 -4
  25. package/dist/dashboard/index.html +3 -3
  26. package/dist/docs/changelog/index.html +43 -4
  27. package/dist/docs/install/index.html +3 -3
  28. package/dist/docs/manual/index.html +8 -7
  29. package/dist/knowledge/index.html +4 -4
  30. package/dist/knowledge//345/212/237/350/203/275/346/265/213/350/257/225/347/224/250/344/276/213/347/274/226/345/206/231/350/247/204/350/214/203/index.html +3 -3
  31. package/dist/plugins/index.html +4 -4
  32. package/dist/pm/bugs/index.html +3 -3
  33. package/dist/pm/iterations/index.html +3 -3
  34. package/dist/pm/projects/detail/index.html +3 -3
  35. package/dist/pm/projects/index.html +3 -3
  36. package/dist/pm/requirements/index.html +3 -3
  37. package/dist/prompts/index.html +4 -4
  38. package/dist/reports/index.html +3 -3
  39. package/dist/requirement-analysis/index.html +4 -4
  40. package/dist/requirements/index.html +4 -4
  41. package/dist/tasks/index.html +3 -3
  42. package/dist/templates/index.html +4 -4
  43. package/dist/templates//345/212/237/350/203/275/346/265/213/350/257/225/346/212/245/345/221/212//345/212/237/350/203/275/346/265/213/350/257/225/346/212/245/345/221/212/346/250/241/346/235/277/index.html +3 -3
  44. package/dist/templates//346/200/247/350/203/275/346/265/213/350/257/225/346/212/245/345/221/212//346/200/247/350/203/275/346/265/213/350/257/225/346/212/245/345/221/212/346/250/241/346/235/277/index.html +3 -3
  45. package/dist/templates//346/200/247/350/203/275/346/265/213/350/257/225/347/224/250/344/276/213//346/200/247/350/203/275/346/265/213/350/257/225/347/224/250/344/276/213/346/250/241/346/235/277/index.html +3 -3
  46. package/dist/templates//346/216/245/345/217/243/346/265/213/350/257/225/346/212/245/345/221/212//346/216/245/345/217/243/346/265/213/350/257/225/346/212/245/345/221/212/346/250/241/346/235/277/index.html +3 -3
  47. package/dist/templates//350/207/252/345/212/250/345/214/226/346/265/213/350/257/225/347/224/250/344/276/213//350/207/252/345/212/250/345/214/226/346/265/213/350/257/225/347/224/250/344/276/213/346/250/241/346/235/277/index.html +3 -3
  48. package/dist/test-automation/index.html +4 -4
  49. package/dist/test-stats/index.html +3 -3
  50. package/dist/todos/index.html +3 -3
  51. package/dist/workbench/index.html +4 -4
  52. package/docs//346/223/215/344/275/234/346/211/213/345/206/214.md +5 -4
  53. package/lh-plugins/case-review-prompt.mjs +67 -54
  54. package/lh-plugins/lh-reports.mjs +65 -6
  55. package/lh-plugins/lh-req-analysis.mjs +9 -1
  56. package/lh-plugins/req-analysis-prompt.mjs +13 -10
  57. package/lh-plugins/story-review-prompt.mjs +26 -16
  58. package/lh-plugins/test-points-prompt.mjs +13 -9
  59. package/lh-plugins/uiauto-prompt.mjs +30 -23
  60. package/package.json +1 -1
  61. package/dist/_astro/CaseGenerateApp.D2ftaUXT.js +0 -9
  62. package/dist/_astro/CasesLibrary.DWXEje9u.js +0 -19
  63. package/dist/_astro/KnowledgeLibrary.Dw-IX3Zt.js +0 -1
  64. package/dist/_astro/PluginsPage.C6ecLD6o.js +0 -1
  65. package/dist/_astro/PromptsLibrary.CEQ2PSE6.js +0 -1
  66. package/dist/_astro/ReqAnalysisBoard.MZap7sCK.js +0 -28
  67. package/dist/_astro/app-version.fDqj9z2r.js +0 -1
  68. package/dist/_astro/project-docs.Cd2gKPKh.js +0 -1
  69. package/dist/_astro/req-analysis.CkLx8c9E.js +0 -6
@@ -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,d as xe,f as Se,g as Ce,l as we,r as Te,s as Ee}from"./project-docs.Cd2gKPKh.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{C as gt,f as _t,h as vt}from"./req-analysis.CkLx8c9E.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.Bhyuqbq0.js";import{c as vr,n as yr,t as br}from"./report-prompt.CAfZ6RIo.js";import{i as xr}from"./ui-auto-prompt.QcLCZoV6.js";import{h as Sr}from"./ui-auto.BmC9JJ_X.js";import{c as Cr,v as wr}from"./story-review.C5gzEzBP.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.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(`
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}
@@ -16,7 +16,7 @@ ${e.testPointBlock?`- 已选测试点要逐条落到用例里,测试点的前
16
16
  {"需求名称":"...","覆盖需求率":0-100,"未覆盖说明":["..."],"编写说明":"...","用例":[...]}
17
17
  - 不要输出 JSON 以外的解释性正文;界面只会展示执行摘要,用例由系统静默入库`}function vi(e=0){return`正在编写用例…\n\n已用 ${Math.max(0,Math.floor(e))}s · 通常约 30–120 秒\n完成后将给出覆盖率与入库结果。`}function yi(e){if(!e.ok)return[`**执行失败**`,``,e.error||`未知错误`,``,`可调整插件中的需求 / 模板 / 提示词后重试。`].join(`
18
18
  `);let t=[`**执行成功**`,``,`- 需求名称:${e.title||`—`}`,`- 共编写:${e.count??0} 条用例`,`- 覆盖需求率:${e.coverageRate==null?`未给出(已按用例入库)`:`${e.coverageRate}%`}`];e.path&&t.push(`- 入库文件:用例管理/${e.path}`),e.writeNote&&t.push(``,`**编写说明**`,e.writeNote);let n=e.uncovered??[];if(t.push(``,`**未覆盖 / 未编写原因**`),n.length)for(let e of n)t.push(`- ${e}`);else t.push(`- 无(模型未声明未覆盖项)`);let r=e.fieldGaps??[];if(r.length){t.push(``,`**字段完整性检测**`);for(let e of r)t.push(`- ${e}`)}return t.join(`
19
- `)}async function bi(e){if(!m(`cases`))throw Error(g(`cases`));let t=N(e.caseType),n=hi(e.title),r=e.outputFormat===`md`?`.md`:e.outputFormat===`csv`?`.csv`:`.xlsx`,i=e.linkedPath||`${n}${r}`;i.includes(`/`)&&!e.linkedPath&&(i=`${n}${r}`);let a=e.headers.length?e.headers:[...ue];return e.outputFormat===`md`?await be(`cases`,i,me(e.cases,e.title,a)):e.outputFormat===`csv`?await be(`cases`,i,L(e.cases,a)):await Ce(`cases`,i,await de(e.cases,a,t.label)),i}async function xi(e,t,n){let r=mi(e);if(!r){let e=`未能解析出用例结果,未写入文件`;return{ok:!1,error:e,summary:yi({ok:!1,error:e})}}let i=t.templateHeaders.length>0?t.templateHeaders:[...ue],a=I(r.cases,i),o=r.docTitle||n||N(t.caseType).label,s=gi(a,i);try{let e=await bi({cases:a,headers:i,caseType:t.caseType,outputFormat:t.outputFormat,title:o}),n=yi({ok:!0,title:o,path:e,count:a.length,coverageRate:r.coverageRate,uncovered:r.uncovered,writeNote:r.writeNote,fieldGaps:s});return{ok:!0,path:e,count:a.length,title:o,coverageRate:r.coverageRate,uncovered:r.uncovered,writeNote:r.writeNote,fieldGaps:s,summary:n}}catch(e){let t=e instanceof Error?e.message:String(e);return{ok:!1,error:t,summary:yi({ok:!1,error:t})}}}function Si(){let e=l().promptKinds;return r(e?.length?e:f)}function Ci(e){let t=Si();return t.find(t=>t.id===e)??t[0]??f[0]}function wi(e){let t=r(e);return d({promptKinds:t}),u(),t}function Ti(e){let t=e.trim();if(!t)throw Error(`类型名称不能为空`);if(t.length>40)throw Error(`类型名称过长(最多 40 字)`);let r=Si();if(r.some(e=>e.label===t))throw Error(`已存在「${t}」`);let i={id:a(),label:t,hint:n(t)};return wi([...r,i]),i}function Ei(e,t){let r=t.trim();if(!r)throw Error(`类型名称不能为空`);if(r.length>40)throw Error(`类型名称过长(最多 40 字)`);let i=Si(),a=i.findIndex(t=>t.id===e);if(a<0)throw Error(`类型不存在`);if(i.some(t=>t.id!==e&&t.label===r))throw Error(`已存在「${r}」`);let o=i[a],s={...o,label:r,hint:o.id===`case`||o.id===`general`?o.hint:n(r)},c=[...i];return c[a]=s,wi(c),s}function Di(e){let t=Si();if(t.length<=1)throw Error(`至少保留一个提示词类型`);if(!t.some(t=>t.id===e))throw Error(`类型不存在`);return wi(t.filter(t=>t.id!==e))}function Oi(e){return`${Ci(e.kind).label} · ${e.titleHint.trim()||`未命名`}`}function ki(e){let t=e.match(/```(?:json)?\s*([\s\S]*?)```/)?.[1]??e.match(/\{[\s\S]*\}/)?.[0];if(!t)return null;try{let e=JSON.parse(t);if(!e||typeof e!=`object`)return null;let n=e.提示词名称??e.title??e.name,r=e.正文??e.body??e.content??e.markdown,i=typeof n==`string`?n.trim():``,a=typeof r==`string`?r.trim():``;if(!a)return null;let o=e.质检通过??e.qcPass??e.pass,s=typeof o==`boolean`?o:typeof o!=`string`||!/^(false|0|no|否|未通过|fail)/i.test(o.trim()),c=e.质检问题??e.qcIssues??e.issues,l=Array.isArray(c)?c.map(e=>String(e).trim()).filter(Boolean):typeof c==`string`&&c.trim()?[c.trim()]:[],u=e.质检说明??e.qcNote??e.note;return{title:i,body:a,qcPass:s,qcIssues:l,qcNote:typeof u==`string`?u.trim():``}}catch{return null}}function Ai(e){return e.replace(/[\\/:*?"<>|]/g,`_`).replace(/\s+/g,``).replace(/\.md$/i,``).slice(0,64)||`未命名提示词`}function ji(e,t=``){let n=[...e.qcIssues],r=(e.title||t||`未命名提示词`).trim();e.qcPass||n.push(`模型自检未通过(质检通过=false)`),(!r||r.length<2)&&n.push(`提示词名称过短(至少 2 字)`),r.length>80&&n.push(`提示词名称过长(最多 80 字)`),/[\\/]/.test(r)&&n.push(`提示词名称不可包含路径分隔符`);let i=Ai(r),a=`${i}.md`;ke(a,p())&&n.push(`不可覆盖受保护提示词「${a}」:${Ae(a,p())}`),e.body.trim()?e.body.trim().length<80&&n.push(`正文过短(建议不少于 80 字)`):n.push(`正文为空`),!/^#\s+/m.test(e.body)&&!e.body.includes(`
19
+ `)}async function bi(e){if(!m(`cases`))throw Error(g(`cases`));let t=N(e.caseType),n=hi(e.title),r=e.outputFormat===`md`?`.md`:e.outputFormat===`csv`?`.csv`:`.xlsx`,i=e.linkedPath||`${n}${r}`;i.includes(`/`)&&!e.linkedPath&&(i=`${n}${r}`);let a=e.headers.length?e.headers:[...ue];return e.outputFormat===`md`?await Ee(`cases`,i,me(e.cases,e.title,a)):e.outputFormat===`csv`?await Ee(`cases`,i,L(e.cases,a)):await be(`cases`,i,await de(e.cases,a,t.label)),i}async function xi(e,t,n){let r=mi(e);if(!r){let e=`未能解析出用例结果,未写入文件`;return{ok:!1,error:e,summary:yi({ok:!1,error:e})}}let i=t.templateHeaders.length>0?t.templateHeaders:[...ue],a=I(r.cases,i),o=r.docTitle||n||N(t.caseType).label,s=gi(a,i);try{let e=await bi({cases:a,headers:i,caseType:t.caseType,outputFormat:t.outputFormat,title:o}),n=yi({ok:!0,title:o,path:e,count:a.length,coverageRate:r.coverageRate,uncovered:r.uncovered,writeNote:r.writeNote,fieldGaps:s});return{ok:!0,path:e,count:a.length,title:o,coverageRate:r.coverageRate,uncovered:r.uncovered,writeNote:r.writeNote,fieldGaps:s,summary:n}}catch(e){let t=e instanceof Error?e.message:String(e);return{ok:!1,error:t,summary:yi({ok:!1,error:t})}}}function Si(){let e=l().promptKinds;return r(e?.length?e:f)}function Ci(e){let t=Si();return t.find(t=>t.id===e)??t[0]??f[0]}function wi(e){let t=r(e);return d({promptKinds:t}),u(),t}function Ti(e){let t=e.trim();if(!t)throw Error(`类型名称不能为空`);if(t.length>40)throw Error(`类型名称过长(最多 40 字)`);let r=Si();if(r.some(e=>e.label===t))throw Error(`已存在「${t}」`);let i={id:a(),label:t,hint:n(t)};return wi([...r,i]),i}function Ei(e,t){let r=t.trim();if(!r)throw Error(`类型名称不能为空`);if(r.length>40)throw Error(`类型名称过长(最多 40 字)`);let i=Si(),a=i.findIndex(t=>t.id===e);if(a<0)throw Error(`类型不存在`);if(i.some(t=>t.id!==e&&t.label===r))throw Error(`已存在「${r}」`);let o=i[a],s={...o,label:r,hint:o.id===`case`||o.id===`general`?o.hint:n(r)},c=[...i];return c[a]=s,wi(c),s}function Di(e){let t=Si();if(t.length<=1)throw Error(`至少保留一个提示词类型`);if(!t.some(t=>t.id===e))throw Error(`类型不存在`);return wi(t.filter(t=>t.id!==e))}function Oi(e){return`${Ci(e.kind).label} · ${e.titleHint.trim()||`未命名`}`}function ki(e){let t=e.match(/```(?:json)?\s*([\s\S]*?)```/)?.[1]??e.match(/\{[\s\S]*\}/)?.[0];if(!t)return null;try{let e=JSON.parse(t);if(!e||typeof e!=`object`)return null;let n=e.提示词名称??e.title??e.name,r=e.正文??e.body??e.content??e.markdown,i=typeof n==`string`?n.trim():``,a=typeof r==`string`?r.trim():``;if(!a)return null;let o=e.质检通过??e.qcPass??e.pass,s=typeof o==`boolean`?o:typeof o!=`string`||!/^(false|0|no|否|未通过|fail)/i.test(o.trim()),c=e.质检问题??e.qcIssues??e.issues,l=Array.isArray(c)?c.map(e=>String(e).trim()).filter(Boolean):typeof c==`string`&&c.trim()?[c.trim()]:[],u=e.质检说明??e.qcNote??e.note;return{title:i,body:a,qcPass:s,qcIssues:l,qcNote:typeof u==`string`?u.trim():``}}catch{return null}}function Ai(e){return e.replace(/[\\/:*?"<>|]/g,`_`).replace(/\s+/g,``).replace(/\.md$/i,``).slice(0,64)||`未命名提示词`}function ji(e,t=``){let n=[...e.qcIssues],r=(e.title||t||`未命名提示词`).trim();e.qcPass||n.push(`模型自检未通过(质检通过=false)`),(!r||r.length<2)&&n.push(`提示词名称过短(至少 2 字)`),r.length>80&&n.push(`提示词名称过长(最多 80 字)`),/[\\/]/.test(r)&&n.push(`提示词名称不可包含路径分隔符`);let i=Ai(r),a=`${i}.md`;ke(a,p())&&n.push(`不可覆盖受保护提示词「${a}」:${Ae(a,p())}`),e.body.trim()?e.body.trim().length<80&&n.push(`正文过短(建议不少于 80 字)`):n.push(`正文为空`),!/^#\s+/m.test(e.body)&&!e.body.includes(`
20
20
  `)&&n.push(`正文建议使用 Markdown 标题与分段结构`);let o=[...new Set(n.filter(Boolean))];return{ok:o.length===0,issues:o,title:r,fileBase:i}}function Mi(e){return`你是资深提示词工程师,擅长为测试与研发场景编写可落地的中文提示词。
21
21
 
22
22
  【任务】
@@ -51,7 +51,7 @@ ${e.titleHint.trim()||`(可在结果中自拟简洁中文名)`}
51
51
  - 「质检通过」为 false 时系统不会入库。
52
52
  - 不要输出 JSON 以外的闲聊;界面只展示执行摘要。`}function Ni(e=0){return`正在编写提示词…\n\n已用 ${Math.max(0,Math.floor(e))}s · 通常约 30–90 秒\n完成后将质检并自动入库到提示词管理。`}function Pi(e){if(!e.ok){let t=[`**执行失败 / 未入库**`,``,e.error||`质检未通过或解析失败`],n=e.issues??[];if(n.length){t.push(``,`**质检问题**`);for(let e of n)t.push(`- ${e}`)}return t.push(``,`可在对话中补充要求后重新发送,或在插件中修改名称/类型。`),t.join(`
53
53
  `)}let t=[`**执行成功**`,``,`- 提示词名称:${e.title||`—`}`];return e.path&&t.push(`- 入库文件:提示词管理/${e.path}`),e.qcNote&&t.push(``,`**质检说明**`,e.qcNote),t.push(``,`下方卡片可点击打开文件。`),t.join(`
54
- `)}async function Fi(e){let t=`${e}.md`;try{let{entries:n}=await Ee(`prompts`,`.`),r=new Set(n.filter(e=>e.type===`file`).map(e=>e.name));if(!r.has(t))return t;for(let t=2;t<100;t++){let n=`${e}-${t}.md`;if(!r.has(n))return n}}catch{}return`${e}-${Date.now().toString(36)}.md`}async function Ii(e,t){let n=ki(e);if(!n){let e=`未能解析出提示词结果,未写入文件`;return{ok:!1,error:e,issues:[],summary:Pi({ok:!1,error:e})}}let r=ji(n,t.titleHint);if(!r.ok){let e=`入库前质检未通过`;return{ok:!1,error:e,issues:r.issues,summary:Pi({ok:!1,error:e,issues:r.issues,qcNote:n.qcNote})}}if(!m(`prompts`)){let e=g(`prompts`);return{ok:!1,error:e,issues:[],summary:Pi({ok:!1,error:e})}}try{let e=await Fi(r.fileBase);await be(`prompts`,e,n.body.endsWith(`
54
+ `)}async function Fi(e){let t=`${e}.md`;try{let{entries:n}=await xe(`prompts`,`.`),r=new Set(n.filter(e=>e.type===`file`).map(e=>e.name));if(!r.has(t))return t;for(let t=2;t<100;t++){let n=`${e}-${t}.md`;if(!r.has(n))return n}}catch{}return`${e}-${Date.now().toString(36)}.md`}async function Ii(e,t){let n=ki(e);if(!n){let e=`未能解析出提示词结果,未写入文件`;return{ok:!1,error:e,issues:[],summary:Pi({ok:!1,error:e})}}let r=ji(n,t.titleHint);if(!r.ok){let e=`入库前质检未通过`;return{ok:!1,error:e,issues:r.issues,summary:Pi({ok:!1,error:e,issues:r.issues,qcNote:n.qcNote})}}if(!m(`prompts`)){let e=g(`prompts`);return{ok:!1,error:e,issues:[],summary:Pi({ok:!1,error:e})}}try{let e=await Fi(r.fileBase);await Ee(`prompts`,e,n.body.endsWith(`
55
55
  `)?n.body:`${n.body}\n`);let t=Pi({ok:!0,title:r.title,path:e,qcNote:n.qcNote});return{ok:!0,path:e,title:r.title,qcNote:n.qcNote,summary:t}}catch(e){let t=e instanceof Error?e.message:String(e);return{ok:!1,error:t,issues:[],summary:Pi({ok:!1,error:t})}}}function Li(){let e=l().knowledgeCategories;return e?.length?[...e]:[...i]}function Ri(e){let t=o(e);return d({knowledgeCategories:t}),u(),t}function zi(e){let t=e.trim();if(!t)throw Error(`分类名称不能为空`);if(t.length>40)throw Error(`分类名称过长(最多 40 字)`);if(/[\\/]/.test(t))throw Error(`分类名称不可包含路径分隔符`);let n=Li();if(n.includes(t))throw Error(`已存在「${t}」`);return Ri([...n,t]),t}function Bi(e,t){let n=t.trim();if(!n)throw Error(`分类名称不能为空`);if(n.length>40)throw Error(`分类名称过长(最多 40 字)`);if(/[\\/]/.test(n))throw Error(`分类名称不可包含路径分隔符`);let r=Li(),i=r.indexOf(e);if(i<0)throw Error(`分类不存在`);if(r.some((e,t)=>t!==i&&e===n))throw Error(`已存在「${n}」`);let a=[...r];return a[i]=n,Ri(a),n}function Vi(e){let t=Li();if(t.length<=1)throw Error(`至少保留一个分类`);if(!t.includes(e))throw Error(`分类不存在`);return Ri(t.filter(t=>t!==e))}function Hi(e){let t=e.titleHint.trim()||`未命名`;return`${e.category} · ${t}`}function Ui(e){return Li().includes(e)}function Wi(e){let t=e.match(/```(?:json)?\s*([\s\S]*?)```/)?.[1]??e.match(/\{[\s\S]*\}/)?.[0];if(!t)return null;try{let e=JSON.parse(t);if(!e||typeof e!=`object`)return null;let n=e.标题??e.知识库名称??e.title??e.name,r=e.分类??e.category,i=e.描述??e.description,a=e.正文??e.body??e.content??e.markdown,o=typeof n==`string`?n.trim():``,s=typeof r==`string`?r.trim():``,c=typeof i==`string`?i.trim():``,l=typeof a==`string`?a.trim():``;if(!l)return null;let u=e.质检通过??e.qcPass??e.pass,d=typeof u==`boolean`?u:typeof u!=`string`||!/^(false|0|no|否|未通过|fail)/i.test(u.trim()),f=e.质检问题??e.qcIssues??e.issues,p=Array.isArray(f)?f.map(e=>String(e).trim()).filter(Boolean):typeof f==`string`&&f.trim()?[f.trim()]:[],m=e.质检说明??e.qcNote??e.note;return{title:o,category:s,description:c,body:l,qcPass:d,qcIssues:p,qcNote:typeof m==`string`?m.trim():``}}catch{return null}}function Gi(e){return e.replace(/[\\/:*?"<>|]/g,`_`).replace(/\s+/g,``).replace(/\.md$/i,``).slice(0,64)||`未命名知识`}function Ki(e){let t=e.trim();return!t||/[:#{}[\],&*?|>!<>=%@`"'\\\n]/.test(t)||/^\s|\s$/.test(e)?JSON.stringify(t):t}function qi(e){return(e.match(/^---\r?\n[\s\S]*?\r?\n---\r?\n?([\s\S]*)$/)?.[1]??e).trim()}function Ji(e){let t=e.description.trim(),n=qi(e.body),r=n.startsWith(`#`)?n:`# ${e.title}\n\n${n}`,i=[`---`,`title: ${Ki(e.title)}`,`category: ${Ki(e.category)}`];return t&&i.push(`description: ${Ki(t)}`),i.push(`---`,``,r,``),i.join(`
56
56
  `)}function Yi(e,t){let n=[...e.qcIssues],r=(e.title||t.titleHint||`未命名知识`).trim(),i=(e.category||t.category||``).trim();Ui(i)||(i=t.category),e.qcPass||n.push(`模型自检未通过(质检通过=false)`),(!r||r.length<2)&&n.push(`标题过短(至少 2 字)`),r.length>80&&n.push(`标题过长(最多 80 字)`),/[\\/]/.test(r)&&n.push(`标题不可包含路径分隔符`),Ui(i)||n.push(`分类必须是:${Li().join(` / `)}`),e.body.trim()?e.body.trim().length<60&&n.push(`正文过短(建议不少于 60 字)`):n.push(`正文为空`);let a=[...new Set(n.filter(Boolean))];return{ok:a.length===0,issues:a,title:r,category:i,fileBase:Gi(r),description:(e.description||``).trim().slice(0,120)}}function Xi(e){let t=e.titleHint.trim()||`(可在结果中自拟简洁中文名)`;return`你是资深测试知识库编辑,擅长把规范、方法论、环境约定写成可复用的 Markdown 文档。
57
57
 
@@ -94,7 +94,7 @@ ${t}
94
94
  - 「质检通过」为 false 时系统不会入库。
95
95
  - 不要输出 JSON 以外的闲聊;界面只展示执行摘要。`}function Zi(e=0){return`正在编写知识库文档…\n\n已用 ${Math.max(0,Math.floor(e))}s · 通常约 30–90 秒\n完成后将质检并自动入库到知识库管理。`}function Qi(e){if(!e.ok){let t=[`**执行失败 / 未入库**`,``,e.error||`质检未通过或解析失败`],n=e.issues??[];if(n.length){t.push(``,`**质检问题**`);for(let e of n)t.push(`- ${e}`)}return t.push(``,`可调整说明后重新发送,或在插件中修改分类/标题。`),t.join(`
96
96
  `)}let t=[`**执行成功**`,``,`- 标题:${e.title||`—`}`];return e.category&&t.push(`- 分类:${e.category}`),e.path&&t.push(`- 入库文件:知识库管理/${e.path}`),e.qcNote&&t.push(``,`**质检说明**`,e.qcNote),t.push(``,`下方卡片可点击打开文件;对话中也可用「@」引用(构建后或刷新列表)。`),t.join(`
97
- `)}async function $i(e){let t=`${e}.md`;try{let{entries:n}=await Ee(`knowledge`,`.`),r=new Set(n.filter(e=>e.type===`file`).map(e=>e.name));if(!r.has(t))return t;for(let t=2;t<100;t++){let n=`${e}-${t}.md`;if(!r.has(n))return n}}catch{}return`${e}-${Date.now().toString(36)}.md`}async function ea(e,t){let n=Wi(e);if(!n){let e=`未能解析出知识库结果,未写入文件`;return{ok:!1,error:e,issues:[],summary:Qi({ok:!1,error:e})}}let r=Yi(n,t);if(!r.ok){let e=`入库前质检未通过`;return{ok:!1,error:e,issues:r.issues,summary:Qi({ok:!1,error:e,issues:r.issues,qcNote:n.qcNote})}}if(!m(`knowledgeLib`)){let e=g(`knowledgeLib`);return{ok:!1,error:e,issues:[],summary:Qi({ok:!1,error:e})}}try{let e=await $i(r.fileBase),t=Ji({title:r.title,category:r.category,description:r.description,body:n.body});await be(`knowledge`,e,t.endsWith(`
97
+ `)}async function $i(e){let t=`${e}.md`;try{let{entries:n}=await xe(`knowledge`,`.`),r=new Set(n.filter(e=>e.type===`file`).map(e=>e.name));if(!r.has(t))return t;for(let t=2;t<100;t++){let n=`${e}-${t}.md`;if(!r.has(n))return n}}catch{}return`${e}-${Date.now().toString(36)}.md`}async function ea(e,t){let n=Wi(e);if(!n){let e=`未能解析出知识库结果,未写入文件`;return{ok:!1,error:e,issues:[],summary:Qi({ok:!1,error:e})}}let r=Yi(n,t);if(!r.ok){let e=`入库前质检未通过`;return{ok:!1,error:e,issues:r.issues,summary:Qi({ok:!1,error:e,issues:r.issues,qcNote:n.qcNote})}}if(!m(`knowledgeLib`)){let e=g(`knowledgeLib`);return{ok:!1,error:e,issues:[],summary:Qi({ok:!1,error:e})}}try{let e=await $i(r.fileBase),t=Ji({title:r.title,category:r.category,description:r.description,body:n.body});await Ee(`knowledge`,e,t.endsWith(`
98
98
  `)?t:`${t}\n`);let i=Qi({ok:!0,title:r.title,path:e,category:r.category,qcNote:n.qcNote});return{ok:!0,path:e,title:r.title,category:r.category,qcNote:n.qcNote,summary:i}}catch(e){let t=e instanceof Error?e.message:String(e);return{ok:!1,error:t,issues:[],summary:Qi({ok:!1,error:t})}}}var ta=`你是 Lantern Harness(仓库 lantern-harness)的「插件开发」助手,只负责在本项目里开发「扩展插件」。
99
99
 
100
100
  # 铁律:先评估、再确认、后开发
@@ -210,11 +210,11 @@ ${t}
210
210
  `)||/\s/.test(t)||t.includes(`://`)||t.includes(`/`)||t.includes(`\\`)?!1:/\.[A-Za-z0-9]{1,16}$/.test(t)}function Ac(e){let t=e.trim();return!t||t.includes(`
211
211
  `)?!1:!!(/^file:/i.test(t)||Oc(t)||(t.includes(`/`)||t.includes(`\\`))&&!/\s/.test(t)&&t.length<512)}function jc(e){let t=[],n=e.getData(`text/uri-list`)||``;for(let e of n.split(/\r?\n/)){let n=e.trim();if(!n||n.startsWith(`#`))continue;let r=Dc(n);r?t.push(r):Oc(n)&&t.push(wc(n))}let r=(e.getData(`text/plain`)||``).trim();if(r&&!r.includes(`
212
212
  `)){let e=Dc(r);e?t.push(e):Ac(r)&&!kc(r)&&t.push(wc(r))}return[...new Set(t)]}function Mc(e){return{collection:e.collection,id:`${e.collection}:${e.path}`,title:e.title||Tc(e.path),category:e.category,path:e.path,format:e.format||Ec(e.path)}}function Nc(e,t){let n=wc(e),r=wc(t).replace(/\/$/,``);return n===r?``:n.startsWith(`${r}/`)?n.slice(r.length+1):null}function Pc(e,t){let n=wc(e.trim()),r=Dc(n);r&&(n=r);let i=t.projectRoot?wc(t.projectRoot):``,a=t.workspace?wc(t.workspace):``,o=n;if(i){let e=Nc(n,i);e!=null&&(o=e)}for(let{prefix:e,aliases:t,collection:n,category:r}of Cc)for(let i of[e,...t??[]])if(o!==i&&o.startsWith(`${i}/`)){let e=o.slice(i.length+1);if(!e)continue;return Mc({collection:n,path:e,title:Tc(e),category:r,format:Ec(e)})}if(a){let e=Nc(n,a);if(e!=null&&e!==``)return Mc({collection:`workspace`,path:e,title:Tc(e),category:t.workspaceLabel||`工作区`,format:Ec(e)})}if(!Oc(o)&&o.includes(`/`)){let e=o.split(`/`)[0]||``,n=Cc.find(t=>t.prefix===e||t.aliases?.includes(e));if(n){let t=o.slice(e.length+1);if(t)return Mc({collection:n.collection,path:t,title:Tc(t),category:n.category,format:Ec(t)})}return Mc({collection:`workspace`,path:o,title:Tc(o),category:t.workspaceLabel||`工作区`,format:Ec(o)})}return null}function Fc(e,t){let n=e.trim();if(!n)return null;let r=n.toLowerCase(),i=t.filter(e=>{let t=Tc(e.path).toLowerCase(),n=(e.title||``).toLowerCase();return t===r||n===r||e.path.toLowerCase()===r});return i.length===1?Mc(i[0]):null}function Ic(e){return[`# ${e.replace(/\.md$/i,``).trim()||`用例生成提示词`}`,``,`> 用例生成提示词:确认后本轮只按这份提示词写用例,工作台的系统提示词不再叠加。`,``,`## 生成用例`,``,`- 逐条覆盖需求 / 用户故事,一条用例只验一个点,不合并步骤;`,`- 前置条件、操作步骤、预期结果要一一对应,步骤给人看也能照着执行;`,`- 正常流程之外补齐边界值、异常与业务规则,非功能(性能 / 兼容 / 安全)按需覆盖;`,`- 每条用例标注优先级 P0–P3,P0 放主流程与核心校验;`,`- 字段与顺序严格跟随用例模板,不要输出模板以外的列。`,``].join(`
213
- `)}async function Lc(e){let t=xr(e);if(!t)throw Error(`文件名不合法:不能包含 / \\ : * ? " < > |`);return await be(`prompts`,t,Ic(t)),t}var Z=k();function Rc({mode:e,entityLabel:t,currentLabel:n,placeholder:r,hint:i,deleteMessage:a,deleteNote:o,error:s=``,onClose:c,onSubmit:l,onDelete:u}){let[d,f]=(0,K.useState)(``),p=(0,K.useRef)(null);if((0,K.useEffect)(()=>{if(e!==`add`&&e!==`edit`)return;f(e===`edit`?n:``);let t=window.setTimeout(()=>{p.current?.focus(),p.current?.select()},50);return()=>window.clearTimeout(t)},[e,n]),typeof document>`u`)return null;let m=d.trim(),h=(0,Z.jsxs)(C,{open:e!==null,onClose:c,transition:!0,className:`relative z-110`,children:[(0,Z.jsx)(w,{transition:!0,className:`tw-dialog-backdrop-anim fixed inset-0 bg-black/30`,"aria-hidden":`true`}),(0,Z.jsx)(`div`,{className:`fixed inset-0 flex items-center justify-center p-4`,children:(0,Z.jsxs)(x,{transition:!0,className:`tw-confirm-dialog tw-dialog-panel-anim relative w-full max-w-sm rounded-xl border border-stone-200 bg-white p-5 shadow-xl`,children:[(0,Z.jsx)(S,{className:`tw-confirm-title pr-8 text-base font-semibold text-stone-900`,children:e===`delete`?`删除${t}`:e===`edit`?`编辑${t}`:`新增${t}`}),e===`delete`?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`p`,{className:`tw-confirm-msg mt-3 text-sm leading-relaxed text-stone-600`,children:a?a(n):`确定删除「${n}」?删除后该项将不再出现在配置里,已生成的内容不受影响。`}),o?(0,Z.jsx)(`p`,{className:`mt-2 rounded-lg bg-stone-50 px-3 py-2 text-[11px] leading-4 text-stone-500`,children:o}):null]}):(0,Z.jsxs)(`label`,{className:`tw-confirm-msg mt-4 block text-xs font-medium text-stone-500`,children:[`名称`,(0,Z.jsx)(`input`,{ref:p,value:d,maxLength:40,onChange:e=>f(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),m&&l(m))},placeholder:r,className:`mt-1.5 h-9 w-full rounded-lg border border-stone-200 bg-white px-3 text-sm text-stone-800 outline-none transition-colors focus:border-[#4176e6] focus:ring-2 focus:ring-[#4176e6]/30`})]}),s?(0,Z.jsx)(`p`,{className:`mt-2 text-[11px] font-normal leading-relaxed text-red-600`,role:`alert`,children:s}):null,e===`delete`||!i?null:(0,Z.jsx)(`p`,{className:`mt-2 text-[11px] leading-4 text-stone-400`,children:i(m)}),(0,Z.jsxs)(`div`,{className:`mt-5 flex justify-end gap-2`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:c,className:`tw-confirm-cancel h-8 rounded-lg px-3 text-sm text-stone-600 transition-colors hover:bg-stone-100`,children:`取消`}),e===`delete`?(0,Z.jsx)(`button`,{type:`button`,onClick:u,className:`h-8 rounded-lg bg-red-600 px-4 text-sm font-medium text-white transition-colors hover:bg-red-700`,children:`删除`}):(0,Z.jsx)(`button`,{type:`button`,disabled:!m,onClick:()=>l(m),className:`h-8 rounded-lg bg-[#4176e6] px-4 text-sm font-medium text-white transition-colors hover:bg-[#3565c7] disabled:opacity-40`,children:e===`edit`?`保存`:`新增`})]})]})})]});return(0,Er.createPortal)(h,document.body)}function zc({mode:e,currentLabel:t,templateFolder:n,error:r=``,onClose:i,onSubmit:a,onDelete:o}){return(0,Z.jsx)(Rc,{mode:e,entityLabel:`用例类型`,currentLabel:t,placeholder:`如:安全测试`,error:r,onClose:i,onSubmit:a,onDelete:o,deleteMessage:e=>(0,Z.jsxs)(Z.Fragment,{children:[`确定删除「`,e,`」?已有用例与模板不会被删除,但该类型将不再出现在生成配置里。`]}),deleteNote:(0,Z.jsxs)(Z.Fragment,{children:[`关联模板目录:测试模板库/`,n,`/`]}),hint:e=>(0,Z.jsxs)(Z.Fragment,{children:[`模板目录随名称生成:测试模板库/`,e||`名称`,`用例/`]})})}var Bc=[{value:`md`,label:`Markdown 表格`},{value:`xlsx`,label:`Excel`},{value:`csv`,label:`CSV`}];async function Vc(e,t){let n=t.find(t=>t.id===e)?.templateFolder??N(e).templateFolder;try{let{entries:e}=await Ee(`templates`,n),t=e.filter(e=>e.type===`file`).sort((e,t)=>(t.mtime??0)-(e.mtime??0)),r=[];for(let e of t){let t=e.name.toLowerCase(),n=[...ue],i=``;try{if(t.endsWith(`.xlsx`)||t.endsWith(`.xls`)){let t=await xe(`templates`,e.path);if(t.encoding===`base64`&&t.contentBase64){let e=F(t.contentBase64);n=e.headers,i=e.body}}else if(t.endsWith(`.csv`)){let t=await Se(`templates`,e.path),r=pe(t.content);n=r.headers,i=r.body}else if(t.endsWith(`.md`)||t.endsWith(`.txt`)){let t=await Se(`templates`,e.path),r=fe(t.content);n=r.headers,i=r.body}}catch{i=``}r.push({id:e.path,title:e.name.replace(/\.[^.]+$/,``),body:i,headers:n})}return r}catch{return[]}}async function Hc(t){let n=t.toLowerCase();if(n.endsWith(`.md`)||n.endsWith(`.txt`)||n.endsWith(`.csv`))return(await Se(`requirements`,t)).content;if(n.endsWith(`.xlsx`)||n.endsWith(`.xls`)){let e=await xe(`requirements`,t);if(e.encoding!==`base64`||!e.contentBase64)throw Error(`无法读取 Excel`);let n=await He(()=>import(`./export.joBT53eb.js`).then(e=>e.s),__vite__mapDeps([3,1])),r=n.read(e.contentBase64,{type:`base64`,cellDates:!0}),i=[];for(let e of r.SheetNames){let t=r.Sheets[e];if(!t)continue;let a=n.utils.sheet_to_csv(t,{blankrows:!1}).trim();a&&i.push(`## 工作表:${e}\n${a}`)}return i.join(`
213
+ `)}async function Lc(e){let t=xr(e);if(!t)throw Error(`文件名不合法:不能包含 / \\ : * ? " < > |`);return await Ee(`prompts`,t,Ic(t)),t}var Z=k();function Rc({mode:e,entityLabel:t,currentLabel:n,placeholder:r,hint:i,deleteMessage:a,deleteNote:o,error:s=``,onClose:c,onSubmit:l,onDelete:u}){let[d,f]=(0,K.useState)(``),p=(0,K.useRef)(null);if((0,K.useEffect)(()=>{if(e!==`add`&&e!==`edit`)return;f(e===`edit`?n:``);let t=window.setTimeout(()=>{p.current?.focus(),p.current?.select()},50);return()=>window.clearTimeout(t)},[e,n]),typeof document>`u`)return null;let m=d.trim(),h=(0,Z.jsxs)(C,{open:e!==null,onClose:c,transition:!0,className:`relative z-110`,children:[(0,Z.jsx)(w,{transition:!0,className:`tw-dialog-backdrop-anim fixed inset-0 bg-black/30`,"aria-hidden":`true`}),(0,Z.jsx)(`div`,{className:`fixed inset-0 flex items-center justify-center p-4`,children:(0,Z.jsxs)(x,{transition:!0,className:`tw-confirm-dialog tw-dialog-panel-anim relative w-full max-w-sm rounded-xl border border-stone-200 bg-white p-5 shadow-xl`,children:[(0,Z.jsx)(S,{className:`tw-confirm-title pr-8 text-base font-semibold text-stone-900`,children:e===`delete`?`删除${t}`:e===`edit`?`编辑${t}`:`新增${t}`}),e===`delete`?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`p`,{className:`tw-confirm-msg mt-3 text-sm leading-relaxed text-stone-600`,children:a?a(n):`确定删除「${n}」?删除后该项将不再出现在配置里,已生成的内容不受影响。`}),o?(0,Z.jsx)(`p`,{className:`mt-2 rounded-lg bg-stone-50 px-3 py-2 text-[11px] leading-4 text-stone-500`,children:o}):null]}):(0,Z.jsxs)(`label`,{className:`tw-confirm-msg mt-4 block text-xs font-medium text-stone-500`,children:[`名称`,(0,Z.jsx)(`input`,{ref:p,value:d,maxLength:40,onChange:e=>f(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),m&&l(m))},placeholder:r,className:`mt-1.5 h-9 w-full rounded-lg border border-stone-200 bg-white px-3 text-sm text-stone-800 outline-none transition-colors focus:border-[#4176e6] focus:ring-2 focus:ring-[#4176e6]/30`})]}),s?(0,Z.jsx)(`p`,{className:`mt-2 text-[11px] font-normal leading-relaxed text-red-600`,role:`alert`,children:s}):null,e===`delete`||!i?null:(0,Z.jsx)(`p`,{className:`mt-2 text-[11px] leading-4 text-stone-400`,children:i(m)}),(0,Z.jsxs)(`div`,{className:`mt-5 flex justify-end gap-2`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:c,className:`tw-confirm-cancel h-8 rounded-lg px-3 text-sm text-stone-600 transition-colors hover:bg-stone-100`,children:`取消`}),e===`delete`?(0,Z.jsx)(`button`,{type:`button`,onClick:u,className:`h-8 rounded-lg bg-red-600 px-4 text-sm font-medium text-white transition-colors hover:bg-red-700`,children:`删除`}):(0,Z.jsx)(`button`,{type:`button`,disabled:!m,onClick:()=>l(m),className:`h-8 rounded-lg bg-[#4176e6] px-4 text-sm font-medium text-white transition-colors hover:bg-[#3565c7] disabled:opacity-40`,children:e===`edit`?`保存`:`新增`})]})]})})]});return(0,Er.createPortal)(h,document.body)}function zc({mode:e,currentLabel:t,templateFolder:n,error:r=``,onClose:i,onSubmit:a,onDelete:o}){return(0,Z.jsx)(Rc,{mode:e,entityLabel:`用例类型`,currentLabel:t,placeholder:`如:安全测试`,error:r,onClose:i,onSubmit:a,onDelete:o,deleteMessage:e=>(0,Z.jsxs)(Z.Fragment,{children:[`确定删除「`,e,`」?已有用例与模板不会被删除,但该类型将不再出现在生成配置里。`]}),deleteNote:(0,Z.jsxs)(Z.Fragment,{children:[`关联模板目录:测试模板库/`,n,`/`]}),hint:e=>(0,Z.jsxs)(Z.Fragment,{children:[`模板目录随名称生成:测试模板库/`,e||`名称`,`用例/`]})})}var Bc=[{value:`md`,label:`Markdown 表格`},{value:`xlsx`,label:`Excel`},{value:`csv`,label:`CSV`}];async function Vc(e,t){let n=t.find(t=>t.id===e)?.templateFolder??N(e).templateFolder;try{let{entries:e}=await xe(`templates`,n),t=e.filter(e=>e.type===`file`).sort((e,t)=>(t.mtime??0)-(e.mtime??0)),r=[];for(let e of t){let t=e.name.toLowerCase(),n=[...ue],i=``;try{if(t.endsWith(`.xlsx`)||t.endsWith(`.xls`)){let t=await Se(`templates`,e.path);if(t.encoding===`base64`&&t.contentBase64){let e=F(t.contentBase64);n=e.headers,i=e.body}}else if(t.endsWith(`.csv`)){let t=await Ce(`templates`,e.path),r=pe(t.content);n=r.headers,i=r.body}else if(t.endsWith(`.md`)||t.endsWith(`.txt`)){let t=await Ce(`templates`,e.path),r=fe(t.content);n=r.headers,i=r.body}}catch{i=``}r.push({id:e.path,title:e.name.replace(/\.[^.]+$/,``),body:i,headers:n})}return r}catch{return[]}}async function Hc(t){let n=t.toLowerCase();if(n.endsWith(`.md`)||n.endsWith(`.txt`)||n.endsWith(`.csv`))return(await Ce(`requirements`,t)).content;if(n.endsWith(`.xlsx`)||n.endsWith(`.xls`)){let e=await Se(`requirements`,t);if(e.encoding!==`base64`||!e.contentBase64)throw Error(`无法读取 Excel`);let n=await He(()=>import(`./export.joBT53eb.js`).then(e=>e.s),__vite__mapDeps([3,1])),r=n.read(e.contentBase64,{type:`base64`,cellDates:!0}),i=[];for(let e of r.SheetNames){let t=r.Sheets[e];if(!t)continue;let a=n.utils.sheet_to_csv(t,{blankrows:!1}).trim();a&&i.push(`## 工作表:${e}\n${a}`)}return i.join(`
214
214
 
215
- `).trim()}if(n.endsWith(`.docx`)){let n=await xe(`requirements`,t);if(n.encoding!==`base64`||!n.contentBase64)throw Error(`无法读取 docx`);let r=atob(n.contentBase64),i=new Uint8Array(r.length);for(let e=0;e<r.length;e++)i[e]=r.charCodeAt(e);return((await(await He(()=>import(`./lib.S37S0T6S.js`).then(t=>e(t.default,1)),__vite__mapDeps([0,1,2]))).extractRawText({arrayBuffer:i.buffer})).value??``).trim()}return``}function Uc({open:e,onClose:t,initial:n,presetStories:r,onConfirm:i}){let[a,o]=(0,K.useState)(!1),[c,l]=(0,K.useState)([]),[d,f]=(0,K.useState)(n?.reqPath??``),[p,g]=(0,K.useState)(n?.reqSource?.kind===`stories`?`stories`:`doc`),[_,v]=(0,K.useState)([]),[y,b]=(0,K.useState)(!1),[x,S]=(0,K.useState)(n?.reqSource?.kind===`stories`?n.reqSource.docId:``),[C,w]=(0,K.useState)(n?.reqSource?.kind===`stories`?n.reqSource.storyIds:[]),[T,E]=(0,K.useState)(()=>re()),[D,O]=(0,K.useState)(n?.caseType??re()[0]?.id??`functional`),[k,A]=(0,K.useState)([]),[ee,ce]=(0,K.useState)(n?.templateId??``),[le,F]=(0,K.useState)([]),[de,fe]=(0,K.useState)(!1),[I,L]=(0,K.useState)(``),[pe,me]=(0,K.useState)(!1),[ge,_e]=(0,K.useState)(n?.promptBody??``),[ve,ye]=(0,K.useState)([]),[R,be]=(0,K.useState)(n?.knowledgePaths??[]),[xe,Ce]=(0,K.useState)(n?.testPointIds??[]),[we,De]=(0,K.useState)(n?.outputFormat??`xlsx`),[Oe,ke]=(0,K.useState)(null),[Ae,je]=(0,K.useState)(!1),[Ne,Pe]=(0,K.useState)(null),[Fe,Ie]=(0,K.useState)(null),[Le,Re]=(0,K.useState)(()=>m(`prompts`)),[ze,Be]=(0,K.useState)(()=>m(`knowledgeLib`)),[Ve,He]=(0,K.useState)(()=>m(`requirements`)),[Ue,We]=(0,K.useState)(()=>m(`templates`)),[z,Ge]=(0,K.useState)(()=>m(`reqAnalysis`)),Ke=(0,K.useMemo)(()=>k.find(e=>e.id===ee)??k[0],[k,ee]),qe=T.find(e=>e.id===D)??T[0]??N(D),Je=qe.label,Ye=(qe.promptPath??``).trim(),Xe=Ye&&le.some(e=>e.path===Ye)?Ye:``,Ze=Le&&de&&!Xe;(0,K.useEffect)(()=>{if(!e)return;if(!Le){L(``);return}if(!de)return;let t=new Set(le.map(e=>e.path)),r=(qe.promptPath??``).trim();if(r&&t.has(r)){L(r);return}let i=(n?.promptPath??``).trim();if(!r&&i&&t.has(i))try{ie(D,i),E(re()),L(i);return}catch{}L(``)},[e,Le,de,le,qe.promptPath,D,n?.promptPath]);async function Qe(e){ie(D,e),E(re()),L(e),me(!1),await u().catch(()=>void 0),Sr(),M(`已为「${Je}」挂载「${e}」`,`success`)}let $e=(0,K.useCallback)(async()=>{async function e(t,n){let{entries:r}=await Ee(`prompts`,t);for(let t of r)t.type===`file`?n.push(t):await e(t.path,n)}try{let t=[];await e(`.`,t);let n=t.filter(e=>!Me(e.path));return n.sort((e,t)=>(t.mtime??0)-(e.mtime??0)),F(n),n}catch{return F([]),[]}},[]);async function et(e){let t=await Lc(e);return await $e(),t}function tt(e){let t=re();E(t),O(n=>{let r=e??n;return t.some(e=>e.id===r)?r:t[0]?.id??n})}function nt(e){try{Ne===`add`?(tt(P(e).id),M(`已新增用例类型「${e}」`,`success`)):Ne===`edit`&&(ae(D,e),tt(D),M(`已重命名为「${e}」`,`success`)),Pe(null),Ie(null)}catch(e){let t=e instanceof Error?e.message:String(e);Ie(t),M(`${Ne===`add`?`新增`:`保存`}失败:${t}`,`error`)}}function rt(){try{let e=T.find(e=>e.id===D)?.label??`该类型`,t=ne(D);E(t),O(t[0]?.id??``),Pe(null),Ie(null),M(`已删除用例类型「${e}」`,`success`)}catch(e){let t=e instanceof Error?e.message:String(e);Ie(t),M(`删除失败:${t}`,`error`)}}(0,K.useEffect)(()=>{let e=()=>{Re(m(`prompts`)),Be(m(`knowledgeLib`)),He(m(`requirements`)),We(m(`templates`)),Ge(m(`reqAnalysis`))},t=h(()=>e());return s().then(e),t},[]),(0,K.useEffect)(()=>{if(!e)return;tt(n?.caseType);let t=n?.reqSource,i=t?.kind===`stories`;g(i?`stories`:`doc`),f(t?.kind===`doc`?t.path:n?.reqPath??``),S(i?t.docId:``),w(i?t.storyIds:[]),O(n?.caseType??re()[0]?.id??`functional`),ce(n?.templateId??``),L(``),fe(!1),me(!1),_e(n?.promptBody??``),be(n?.knowledgePaths??[]),Ce(n?.testPointIds??[]),De(n?.outputFormat??`xlsx`),Pe(null),Ie(null),ke(null),r?.docId&&(g(`stories`),S(r.docId),w(r.storyIds)),(async()=>{let e=await Te(`templates`),t=await Te(`prompts`),n=await Te(`requirements`),i=await Te(`knowledge`);o(e&&t);let a=[];if(m(`reqAnalysis`)&&await _t())try{a=await vt(),a.sort((e,t)=>String(t.updatedAt).localeCompare(String(e.updatedAt))),b(!0),v(a)}catch{b(!1)}else b(!1);if(r?.docId){let e=a.find(e=>e.id===r.docId);e&&(S(e.id),w(r.storyIds.length?r.storyIds:e.stories.map(e=>e.id)))}async function s(e,t,n){let{entries:r}=await Ee(e,t);for(let t of r)t.type===`file`?n.push(t):await s(e,t.path,n)}if(!Ve||!n)l([]),f(``);else try{let e=[];await s(`requirements`,`.`,e),l(e),f(t=>t&&e.some(e=>e.path===t)?t:``)}catch{}if(!ze||!i)ye([]),be([]);else try{let e=[];await s(`knowledge`,`.`,e),e.sort((e,t)=>(t.mtime??0)-(e.mtime??0)),ye(e),be(t=>t.filter(t=>e.some(e=>e.path===t)))}catch{}Le?(await $e(),fe(!0)):(F([]),L(``),_e(``),fe(!0))})()},[e,n,Le,ze,Ve,r,$e]),(0,K.useEffect)(()=>{if(!e||!a)return;if(!Ue){A([]),ce(``);return}let t=!1;return Vc(D,T).then(e=>{t||(A(e),ce(t=>t&&e.some(e=>e.id===t)?t:n?.templateId&&e.some(e=>e.id===n.templateId)?n.templateId:e[0]?.id??``))}),()=>{t=!0}},[e,a,Ue,D,T,n?.templateId]),(0,K.useEffect)(()=>{I?Se(`prompts`,I).then(e=>{let t=e.content??``;_e(t),t.trim()||M(`「提示词管理/${I}」是空的,生成前请先补上提示词内容。`,`error`)}).catch(e=>{_e(``);let t=e instanceof Error?e.message:String(e);M(`没有读到「提示词管理/${I}」:${t}`,`error`)}):_e(``)},[I]);let it=c.map(e=>({value:e.path,label:e.path})),at=k.map(e=>({value:e.id,label:e.title})),ot=le.map(e=>e.path),st=ve.map(e=>({value:e.path,label:e.path.replace(/\.[^.]+$/,``)})),ct=(0,K.useMemo)(()=>_.find(e=>e.id===x)??null,[_,x]),lt=ct?.stories??[],ut=C.filter(e=>lt.some(t=>t.id===e)).length,dt=ct?.testPoints?.points??[],ft=xe.filter(e=>dt.some(t=>t.id===e)),pt=dt.map(e=>({value:e.id,label:`${e.id} · ${Cr[e.dimension].label} ${e.priority} · ${e.title}`})),mt=z?p===`doc`?`切到「用户故事」来源后可选`:ct?dt.length?`选择要覆盖的测试点…`:`这份分析还没有测试点`:`先选择一份需求分析记录`:`需求分析插件未启用`,yt=p===`doc`?`测试点来自「需求分析」拆好的结果:切到「用户故事」来源就能选。`:ct?dt.length?`选中的测试点连同前置 / 步骤 / 预期一起拼进提示词;不选则按需求本身生成。`:`先去需求分析的「测试点」Tab 生成,再回来按测试点写用例。`:`选好需求分析记录后,这里会列出它的测试点。`;async function bt(){je(!0),ke(null);try{if(!Le){ke(`请先在「我的插件」中启用「提示词管理」`);return}if(!Xe||!ge.trim()){let e=Xe?`「提示词管理/${Xe}」还是空的,先补上内容再生成`:`请先为「${Je}」挂载生成提示词(点提示词框选择或新建)`;ke(e),M(e,`error`);return}let e=k.find(e=>e.id===ee)??k[0],r=p===`stories`?x?{kind:`stories`,docId:x,storyIds:C}:void 0:d?{kind:`doc`,path:d}:void 0,a=``,o=``;if(r?.kind===`doc`){a=r.path.split(`/`).pop()?.replace(/\.[^.]+$/,``)??``;try{let e=await Hc(r.path);o=`### 需求文档:${r.path}\n${e.slice(0,16e3)}`}catch(e){ke(e instanceof Error?e.message:String(e));return}}else if(r?.kind===`stories`){if(!y){ke(z?`需求分析服务未就绪,暂时读不到用户故事;可切回「需求文档」`:`需求分析插件未启用,读不到用户故事;可切回「需求文档」`);return}if(!ct){ke(`所选需求分析记录已不存在,请重新选择`);return}if(!ut){ke(`请至少勾选一条用户故事,或点「全选」`);return}a=ct.title,o=`### 用户故事:${ct.title}\n按 US 编号逐条覆盖:每条故事的验收标准与异常场景都要有对应用例。\n${gt(ct,C)}`}let s=[];for(let e of R)try{let t=await Se(`knowledge`,e);s.push(`\n### 知识库:${e}\n${t.content.slice(0,6e3)}`)}catch{s.push(`\n### 知识库:${e}\n(无法读取)`)}let c=dt.filter(e=>ft.includes(e.id));i({active:!0,caseType:D,outputFormat:we,reqPath:r?.kind===`doc`?r.path:void 0,reqSource:r,docTitle:a||void 0,reqBlock:[o,...s].filter(Boolean).join(`
215
+ `).trim()}if(n.endsWith(`.docx`)){let n=await Se(`requirements`,t);if(n.encoding!==`base64`||!n.contentBase64)throw Error(`无法读取 docx`);let r=atob(n.contentBase64),i=new Uint8Array(r.length);for(let e=0;e<r.length;e++)i[e]=r.charCodeAt(e);return((await(await He(()=>import(`./lib.S37S0T6S.js`).then(t=>e(t.default,1)),__vite__mapDeps([0,1,2]))).extractRawText({arrayBuffer:i.buffer})).value??``).trim()}return``}function Uc({open:e,onClose:t,initial:n,presetStories:r,onConfirm:i}){let[a,o]=(0,K.useState)(!1),[c,l]=(0,K.useState)([]),[d,f]=(0,K.useState)(n?.reqPath??``),[p,g]=(0,K.useState)(n?.reqSource?.kind===`stories`?`stories`:`doc`),[_,v]=(0,K.useState)([]),[y,b]=(0,K.useState)(!1),[x,S]=(0,K.useState)(n?.reqSource?.kind===`stories`?n.reqSource.docId:``),[C,w]=(0,K.useState)(n?.reqSource?.kind===`stories`?n.reqSource.storyIds:[]),[T,E]=(0,K.useState)(()=>re()),[D,O]=(0,K.useState)(n?.caseType??re()[0]?.id??`functional`),[k,A]=(0,K.useState)([]),[ee,ce]=(0,K.useState)(n?.templateId??``),[le,F]=(0,K.useState)([]),[de,fe]=(0,K.useState)(!1),[I,L]=(0,K.useState)(``),[pe,me]=(0,K.useState)(!1),[ge,_e]=(0,K.useState)(n?.promptBody??``),[ve,ye]=(0,K.useState)([]),[R,be]=(0,K.useState)(n?.knowledgePaths??[]),[Se,Te]=(0,K.useState)(n?.testPointIds??[]),[Ee,De]=(0,K.useState)(n?.outputFormat??`xlsx`),[Oe,ke]=(0,K.useState)(null),[Ae,je]=(0,K.useState)(!1),[Ne,Pe]=(0,K.useState)(null),[Fe,Ie]=(0,K.useState)(null),[Le,Re]=(0,K.useState)(()=>m(`prompts`)),[ze,Be]=(0,K.useState)(()=>m(`knowledgeLib`)),[Ve,He]=(0,K.useState)(()=>m(`requirements`)),[Ue,We]=(0,K.useState)(()=>m(`templates`)),[z,Ge]=(0,K.useState)(()=>m(`reqAnalysis`)),Ke=(0,K.useMemo)(()=>k.find(e=>e.id===ee)??k[0],[k,ee]),qe=T.find(e=>e.id===D)??T[0]??N(D),Je=qe.label,Ye=(qe.promptPath??``).trim(),Xe=Ye&&le.some(e=>e.path===Ye)?Ye:``,Ze=Le&&de&&!Xe;(0,K.useEffect)(()=>{if(!e)return;if(!Le){L(``);return}if(!de)return;let t=new Set(le.map(e=>e.path)),r=(qe.promptPath??``).trim();if(r&&t.has(r)){L(r);return}let i=(n?.promptPath??``).trim();if(!r&&i&&t.has(i))try{ie(D,i),E(re()),L(i);return}catch{}L(``)},[e,Le,de,le,qe.promptPath,D,n?.promptPath]);async function Qe(e){ie(D,e),E(re()),L(e),me(!1),await u().catch(()=>void 0),Sr(),M(`已为「${Je}」挂载「${e}」`,`success`)}let $e=(0,K.useCallback)(async()=>{async function e(t,n){let{entries:r}=await xe(`prompts`,t);for(let t of r)t.type===`file`?n.push(t):await e(t.path,n)}try{let t=[];await e(`.`,t);let n=t.filter(e=>!Me(e.path));return n.sort((e,t)=>(t.mtime??0)-(e.mtime??0)),F(n),n}catch{return F([]),[]}},[]);async function et(e){let t=await Lc(e);return await $e(),t}function tt(e){let t=re();E(t),O(n=>{let r=e??n;return t.some(e=>e.id===r)?r:t[0]?.id??n})}function nt(e){try{Ne===`add`?(tt(P(e).id),M(`已新增用例类型「${e}」`,`success`)):Ne===`edit`&&(ae(D,e),tt(D),M(`已重命名为「${e}」`,`success`)),Pe(null),Ie(null)}catch(e){let t=e instanceof Error?e.message:String(e);Ie(t),M(`${Ne===`add`?`新增`:`保存`}失败:${t}`,`error`)}}function rt(){try{let e=T.find(e=>e.id===D)?.label??`该类型`,t=ne(D);E(t),O(t[0]?.id??``),Pe(null),Ie(null),M(`已删除用例类型「${e}」`,`success`)}catch(e){let t=e instanceof Error?e.message:String(e);Ie(t),M(`删除失败:${t}`,`error`)}}(0,K.useEffect)(()=>{let e=()=>{Re(m(`prompts`)),Be(m(`knowledgeLib`)),He(m(`requirements`)),We(m(`templates`)),Ge(m(`reqAnalysis`))},t=h(()=>e());return s().then(e),t},[]),(0,K.useEffect)(()=>{if(!e)return;tt(n?.caseType);let t=n?.reqSource,i=t?.kind===`stories`;g(i?`stories`:`doc`),f(t?.kind===`doc`?t.path:n?.reqPath??``),S(i?t.docId:``),w(i?t.storyIds:[]),O(n?.caseType??re()[0]?.id??`functional`),ce(n?.templateId??``),L(``),fe(!1),me(!1),_e(n?.promptBody??``),be(n?.knowledgePaths??[]),Te(n?.testPointIds??[]),De(n?.outputFormat??`xlsx`),Pe(null),Ie(null),ke(null),r?.docId&&(g(`stories`),S(r.docId),w(r.storyIds)),(async()=>{let e=await we(`templates`),t=await we(`prompts`),n=await we(`requirements`),i=await we(`knowledge`);o(e&&t);let a=[];if(m(`reqAnalysis`)&&await gt())try{a=await _t(),a.sort((e,t)=>String(t.updatedAt).localeCompare(String(e.updatedAt))),b(!0),v(a)}catch{b(!1)}else b(!1);if(r?.docId){let e=a.find(e=>e.id===r.docId);e&&(S(e.id),w(r.storyIds.length?r.storyIds:e.stories.map(e=>e.id)))}async function s(e,t,n){let{entries:r}=await xe(e,t);for(let t of r)t.type===`file`?n.push(t):await s(e,t.path,n)}if(!Ve||!n)l([]),f(``);else try{let e=[];await s(`requirements`,`.`,e),l(e),f(t=>t&&e.some(e=>e.path===t)?t:``)}catch{}if(!ze||!i)ye([]),be([]);else try{let e=[];await s(`knowledge`,`.`,e),e.sort((e,t)=>(t.mtime??0)-(e.mtime??0)),ye(e),be(t=>t.filter(t=>e.some(e=>e.path===t)))}catch{}Le?(await $e(),fe(!0)):(F([]),L(``),_e(``),fe(!0))})()},[e,n,Le,ze,Ve,r,$e]),(0,K.useEffect)(()=>{if(!e||!a)return;if(!Ue){A([]),ce(``);return}let t=!1;return Vc(D,T).then(e=>{t||(A(e),ce(t=>t&&e.some(e=>e.id===t)?t:n?.templateId&&e.some(e=>e.id===n.templateId)?n.templateId:e[0]?.id??``))}),()=>{t=!0}},[e,a,Ue,D,T,n?.templateId]),(0,K.useEffect)(()=>{I?Ce(`prompts`,I).then(e=>{let t=e.content??``;_e(t),t.trim()||M(`「提示词管理/${I}」是空的,生成前请先补上提示词内容。`,`error`)}).catch(e=>{_e(``);let t=e instanceof Error?e.message:String(e);M(`没有读到「提示词管理/${I}」:${t}`,`error`)}):_e(``)},[I]);let it=c.map(e=>({value:e.path,label:e.path})),at=k.map(e=>({value:e.id,label:e.title})),ot=le.map(e=>e.path),st=ve.map(e=>({value:e.path,label:e.path.replace(/\.[^.]+$/,``)})),ct=(0,K.useMemo)(()=>_.find(e=>e.id===x)??null,[_,x]),lt=ct?.stories??[],ut=C.filter(e=>lt.some(t=>t.id===e)).length,dt=ct?.testPoints?.points??[],ft=Se.filter(e=>dt.some(t=>t.id===e)),pt=dt.map(e=>({value:e.id,label:`${e.id} · ${Cr[e.dimension].label} ${e.priority} · ${e.title}`})),mt=z?p===`doc`?`切到「用户故事」来源后可选`:ct?dt.length?`选择要覆盖的测试点…`:`这份分析还没有测试点`:`先选择一份需求分析记录`:`需求分析插件未启用`,yt=p===`doc`?`测试点来自「需求分析」拆好的结果:切到「用户故事」来源就能选。`:ct?dt.length?`选中的测试点连同前置 / 步骤 / 预期一起拼进提示词;不选则按需求本身生成。`:`先去需求分析的「测试点」Tab 生成,再回来按测试点写用例。`:`选好需求分析记录后,这里会列出它的测试点。`;async function bt(){je(!0),ke(null);try{if(!Le){ke(`请先在「我的插件」中启用「提示词管理」`);return}if(!Xe||!ge.trim()){let e=Xe?`「提示词管理/${Xe}」还是空的,先补上内容再生成`:`请先为「${Je}」挂载生成提示词(点提示词框选择或新建)`;ke(e),M(e,`error`);return}let e=k.find(e=>e.id===ee)??k[0],r=p===`stories`?x?{kind:`stories`,docId:x,storyIds:C}:void 0:d?{kind:`doc`,path:d}:void 0,a=``,o=``;if(r?.kind===`doc`){a=r.path.split(`/`).pop()?.replace(/\.[^.]+$/,``)??``;try{let e=await Hc(r.path);o=`### 需求文档:${r.path}\n${e.slice(0,16e3)}`}catch(e){ke(e instanceof Error?e.message:String(e));return}}else if(r?.kind===`stories`){if(!y){ke(z?`需求分析服务未就绪,暂时读不到用户故事;可切回「需求文档」`:`需求分析插件未启用,读不到用户故事;可切回「需求文档」`);return}if(!ct){ke(`所选需求分析记录已不存在,请重新选择`);return}if(!ut){ke(`请至少勾选一条用户故事,或点「全选」`);return}a=ct.title,o=`### 用户故事:${ct.title}\n按 US 编号逐条覆盖:每条故事的验收标准与异常场景都要有对应用例。\n${vt(ct,C)}`}let s=[];for(let e of R)try{let t=await Ce(`knowledge`,e);s.push(`\n### 知识库:${e}\n${t.content.slice(0,6e3)}`)}catch{s.push(`\n### 知识库:${e}\n(无法读取)`)}let c=dt.filter(e=>ft.includes(e.id));i({active:!0,caseType:D,outputFormat:Ee,reqPath:r?.kind===`doc`?r.path:void 0,reqSource:r,docTitle:a||void 0,reqBlock:[o,...s].filter(Boolean).join(`
216
216
 
217
- `)||void 0,templateId:e?.id,templateTitle:e?.title,promptPath:I,knowledgePaths:R.length?[...R]:void 0,testPointIds:c.length?c.map(e=>e.id):void 0,testPointBlock:c.length?wr(c):void 0,templateHeaders:e?.headers?.length?e.headers:[...ue],templateBody:(e?.body||``).trim(),promptBody:ge.trim(),confirmedAt:Date.now(),linkedCasePath:n?.linkedCasePath}),t()}finally{je(!1)}}return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(ht,{open:e,onClose:t,title:`生成测试用例 · 配置`,closeAriaLabel:`关闭生成测试用例面板`,widthClass:`max-w-3xl`,escDisabled:Ne!==null,footer:(0,Z.jsxs)(`footer`,{className:`shrink-0 border-t border-stone-100 px-4 py-3 flex items-center gap-2`,children:[(0,Z.jsx)(`p`,{className:`flex-1 min-w-0 truncate text-[11px] text-stone-400`,children:`配置仅对当前会话生效,可在输入区胶囊里再改`}),(0,Z.jsx)(`button`,{type:`button`,onClick:t,className:`h-9 px-3 text-sm text-stone-600 rounded-lg hover:bg-stone-100`,children:`取消`}),(0,Z.jsx)(`button`,{type:`button`,disabled:Ae||!a||!Le||!Xe,onClick:()=>void bt(),className:`h-9 px-5 text-sm font-medium text-white bg-[#4176e6] rounded-lg hover:bg-[#3565c7] disabled:opacity-40`,children:`确认`})]}),children:[a?null:(0,Z.jsx)(`div`,{className:`rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-sm text-amber-900`,children:`本地文档服务未就绪,无法读写文档库。`}),Oe?(0,Z.jsx)(`div`,{className:`text-sm text-red-700 bg-red-50 border border-red-200 rounded-lg px-3 py-2`,children:Oe}):null,(0,Z.jsxs)(`div`,{className:`grid grid-cols-1 gap-x-4 gap-y-1 lg:grid-cols-2`,children:[(0,Z.jsxs)(`div`,{className:`order-1 min-w-0`,children:[(0,Z.jsx)(`div`,{className:`mb-1 text-xs font-medium text-stone-500`,children:`用例类型`}),(0,Z.jsx)(j,{options:T.map(e=>({value:e.id,label:e.label})),value:D,onChange:O,dimWhenOpen:!0})]}),(0,Z.jsxs)(`div`,{className:`order-3 min-w-0 lg:order-2`,children:[(0,Z.jsxs)(`div`,{className:`mb-1 text-xs font-medium text-stone-500`,children:[`用例模板`,(0,Z.jsxs)(`span`,{className:`ml-1 font-normal text-stone-400`,children:[`(`,Je,` · `,qe.templateFolder,`)`]})]}),(0,Z.jsx)(se,{options:at,value:Ke?.id??``,onChange:ce,allowEmpty:!1,disabled:!Ue,placeholder:Ue?at.length?`搜索并选择模板…`:`暂无「${qe.templateFolder}」模板`:`测试模板库未启用`})]}),(0,Z.jsxs)(`div`,{className:`order-2 flex min-w-0 items-start justify-end gap-1 pt-1.5 lg:order-3`,children:[(0,Z.jsx)(`button`,{type:`button`,className:`inline-flex h-[23px] items-center rounded border border-stone-200 px-1.5 text-[11px] leading-none text-[#4176e6] transition-colors hover:border-[#4176e6]/40 hover:bg-[#edf3fe]`,onClick:()=>{Ie(null),Pe(`add`)},children:`新增`}),(0,Z.jsx)(`button`,{type:`button`,className:`inline-flex h-[23px] items-center rounded border border-stone-200 px-1.5 text-[11px] leading-none text-stone-600 transition-colors hover:border-stone-300 hover:bg-stone-50`,onClick:()=>{Ie(null),Pe(`edit`)},children:`编辑`}),(0,Z.jsx)(`button`,{type:`button`,className:`inline-flex h-[23px] items-center rounded border border-stone-200 px-1.5 text-[11px] leading-none text-red-600 transition-colors hover:border-red-300 hover:bg-red-50 disabled:opacity-40 disabled:hover:border-stone-200 disabled:hover:bg-transparent`,disabled:T.length<=1,onClick:()=>{Ie(null),Pe(`delete`)},children:`删除`})]}),(0,Z.jsx)(`div`,{className:`order-4 min-w-0 lg:order-4`,children:Ue?Ke?.headers?.length?(0,Z.jsx)(he,{fields:Ke.headers}):null:(0,Z.jsx)(`p`,{className:`mt-1 text-[11px] text-stone-400`,children:`请先在「我的插件」中启用「测试模板库」后再选择;未启用时按默认字段生成。`})})]}),(0,Z.jsxs)(`div`,{className:`grid grid-cols-1 items-start gap-4 lg:grid-cols-2`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`div`,{className:`mb-1 text-xs font-medium text-stone-500`,children:`输出格式`}),(0,Z.jsx)(j,{options:Bc,value:we,onChange:De,dimWhenOpen:!0})]}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`div`,{className:`mb-1 text-xs font-medium text-stone-500`,children:`引用知识库(可多选)`}),(0,Z.jsx)(oe,{options:st,values:R,onChange:be,disabled:!ze,placeholder:ze?st.length?`选择知识库文档…`:`暂无知识库文档`:`知识库管理未启用`}),ze?null:(0,Z.jsx)(`p`,{className:`mt-1 text-[11px] text-stone-400`,children:`请先在「我的插件」中启用「知识库管理」后再引用。`})]})]}),(0,Z.jsxs)(`section`,{className:`rounded-xl border border-stone-200 p-3`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,Z.jsx)(`div`,{className:`text-xs font-medium text-stone-500`,children:`需求来源`}),(0,Z.jsxs)(`div`,{className:`inline-flex rounded-lg border border-stone-200 bg-stone-50 p-0.5`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:()=>g(`doc`),className:`h-7 rounded-md px-2.5 text-xs transition-colors ${p===`doc`?`bg-white text-stone-900 shadow-sm`:`text-stone-500 hover:text-stone-700`}`,children:`需求文档`}),(0,Z.jsx)(`button`,{type:`button`,disabled:!y,onClick:()=>{y&&g(`stories`)},className:`h-7 rounded-md px-2.5 text-xs transition-colors disabled:opacity-40 ${p===`stories`?`bg-white text-stone-900 shadow-sm`:`text-stone-500 hover:text-stone-700`}`,children:`用户故事`})]}),(0,Z.jsx)(`p`,{className:`text-[11px] text-stone-400`,children:p===`stories`?`来自「需求分析」拆好的故事:按 US 编号逐条覆盖,改动后重新生成即可`:`来自「需求文档库」的原始文档`})]}),(0,Z.jsx)(`div`,{className:`mt-2`,children:p===`stories`?(0,Z.jsx)(se,{options:_.map(e=>({value:e.id,label:`${e.title}(${e.stories.length} 个故事)`})),value:x,onChange:e=>{S(e);let t=_.find(t=>t.id===e);w(t?.stories.map(e=>e.id)??[]),Ce([])},allowEmpty:!1,disabled:!y,placeholder:z?y?_.length?`搜索并选择需求分析记录…`:`暂无需求分析记录,请先在「需求分析」拆解`:`需求分析服务未就绪`:`需求分析插件未启用`}):(0,Z.jsx)(se,{options:it,value:d,onChange:f,allowEmpty:!1,disabled:!Ve,placeholder:Ve?it.length?`搜索并选择需求文档…`:`请先在需求文档库中上传`:`需求文档库未启用`})}),p===`stories`?(0,Z.jsxs)(`div`,{className:`mt-2 rounded-lg bg-stone-50/80 p-2.5`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsxs)(`div`,{className:`flex-1 text-[11px] text-stone-500`,children:[`选择故事`,(0,Z.jsxs)(`span`,{className:`ml-1 text-stone-400`,children:[ut,`/`,lt.length]})]}),(0,Z.jsx)(`button`,{type:`button`,className:`text-[11px] text-[#4176e6] hover:underline`,onClick:()=>w(lt.map(e=>e.id)),children:`全选`}),(0,Z.jsx)(`button`,{type:`button`,className:`text-[11px] text-stone-500 hover:underline`,onClick:()=>w([]),children:`全不选`})]}),lt.length?(0,Z.jsx)(`div`,{className:`mt-1.5 grid max-h-56 grid-cols-1 gap-x-4 overflow-y-auto sm:grid-cols-2`,children:lt.map(e=>(0,Z.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-1.5 py-1 text-xs`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,className:`mt-0.5`,checked:C.includes(e.id),onChange:t=>w(n=>t.target.checked?[...n,e.id]:n.filter(t=>t!==e.id))}),(0,Z.jsx)(`span`,{className:`shrink-0 font-mono text-[11px] text-stone-400`,children:e.id}),(0,Z.jsx)(`span`,{className:`min-w-0 flex-1`,children:(0,Z.jsx)(te,{text:e.title,className:`block truncate text-stone-800`})}),(0,Z.jsx)(`span`,{className:`shrink-0 text-[11px] text-stone-400`,children:e.priority})]},e.id))}):(0,Z.jsx)(`p`,{className:`mt-1.5 text-[11px] text-stone-400`,children:x?`这份分析还没有拆出用户故事`:`先选择一份需求分析记录`}),z?null:(0,Z.jsx)(`p`,{className:`mt-1.5 text-[11px] text-stone-400`,children:`需求分析插件已关闭;用户故事来源暂不可用,可改用「需求文档」。`})]}):Ve?null:(0,Z.jsx)(`p`,{className:`mt-1 text-[11px] text-stone-400`,children:`请先在「我的插件」中启用「需求文档库」后再选择。`})]}),(0,Z.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 lg:grid-cols-2`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`mb-1 flex items-center justify-between gap-2`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0 text-xs font-medium text-stone-500`,children:[`测试点(可多选)`,dt.length?(0,Z.jsxs)(`span`,{className:`ml-1 font-normal text-stone-400`,children:[ft.length,`/`,dt.length]}):null]}),dt.length?(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 text-[11px]`,children:[(0,Z.jsx)(`button`,{type:`button`,className:`text-[#4176e6] transition-colors hover:text-[#3565c7]`,onClick:()=>Ce(dt.map(e=>e.id)),children:`全选`}),(0,Z.jsx)(`button`,{type:`button`,className:`text-stone-500 transition-colors hover:text-stone-700`,onClick:()=>Ce([]),children:`清空`})]}):null]}),(0,Z.jsx)(oe,{options:pt,values:ft,onChange:Ce,disabled:!pt.length,placeholder:mt}),(0,Z.jsx)(`p`,{className:`mt-1 text-[11px] text-stone-400`,children:yt})]}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`mb-1 text-xs font-medium text-stone-500`,children:[`提示词`,(0,Z.jsxs)(`span`,{className:`ml-1 font-normal text-stone-400`,children:[`(`,Je,` 挂载)`]})]}),(0,Z.jsx)(`button`,{type:`button`,disabled:!Le,onClick:()=>me(!0),className:`flex h-9 w-full min-w-0 items-center gap-2 rounded-lg border px-2.5 text-left text-sm transition-colors disabled:cursor-not-allowed disabled:opacity-50 ${Ze?`border-amber-300 bg-amber-50/50 text-amber-700 hover:border-amber-400`:`border-stone-200 bg-white text-stone-800 hover:border-stone-300`}`,children:(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:Le?Xe?Xe.replace(/\.md$/i,``):de?`未挂载提示词 · 点击挂载`:`读取提示词…`:`提示词管理未启用`})}),(0,Z.jsx)(`p`,{className:`mt-1 text-[11px] text-stone-400`,children:Le?Ze?de?`当前类型还没有挂载提示词,未挂载时无法确认。`:`正在读取提示词列表…`:`每个用例类型只挂一份提示词:换类型会切到该类型挂载的那份。`:`请先在「我的插件」中启用「提示词管理」后再挂载。`})]})]}),(0,Z.jsxs)(`section`,{className:`rounded-xl border border-stone-200 bg-stone-50/60 px-4 py-3`,children:[(0,Z.jsx)(`div`,{className:`text-xs font-semibold text-stone-600`,children:`本次配置`}),(0,Z.jsxs)(`dl`,{className:`mt-2 grid grid-cols-2 gap-x-4 gap-y-2 sm:grid-cols-3`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`dt`,{className:`text-[10px] text-stone-400`,children:`用例类型`}),(0,Z.jsx)(`dd`,{className:`truncate text-xs text-stone-700`,children:Je})]}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`dt`,{className:`text-[10px] text-stone-400`,children:`用例模板`}),(0,Z.jsx)(`dd`,{className:`truncate text-xs text-stone-700`,children:Ke?.title||`—`})]}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`dt`,{className:`text-[10px] text-stone-400`,children:`输出格式`}),(0,Z.jsx)(`dd`,{className:`truncate text-xs text-stone-700`,children:Bc.find(e=>e.value===we)?.label??we})]}),(0,Z.jsxs)(`div`,{className:`col-span-2 min-w-0`,children:[(0,Z.jsx)(`dt`,{className:`text-[10px] text-stone-400`,children:`需求来源`}),(0,Z.jsx)(`dd`,{className:`truncate text-xs text-stone-700`,children:p===`stories`?ct?`用户故事 · ${ct.title}(${ut}/${lt.length} 条)`:`用户故事 · 未选择`:d?`需求文档 · ${d}`:`需求文档 · 未选择`})]}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`dt`,{className:`text-[10px] text-stone-400`,children:`引用知识库`}),(0,Z.jsx)(`dd`,{className:`truncate text-xs text-stone-700`,children:R.length?`${R.length} 个文档`:`未引用`})]}),(0,Z.jsxs)(`div`,{className:`col-span-2 grid min-w-0 grid-cols-2 gap-x-4 sm:col-span-3`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`dt`,{className:`text-[10px] text-stone-400`,children:`测试点`}),(0,Z.jsx)(`dd`,{className:`truncate text-xs text-stone-700`,children:ft.length?`${ft.length} 条`:`未选择`})]}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`dt`,{className:`text-[10px] text-stone-400`,children:`提示词`}),(0,Z.jsx)(`dd`,{className:`truncate text-xs text-stone-700`,children:Xe?`${Xe.replace(/\.md$/i,``)}(${Je})`:`未挂载`})]})]})]}),(0,Z.jsx)(`p`,{className:`mt-2.5 text-[10px] leading-4 text-stone-400`,children:`确认后在主输入框描述本次生成范围并发送;结果写入用例管理,后续修改仍走该工作台会话。`})]})]}),(0,Z.jsx)(zc,{mode:Ne,currentLabel:qe.label,templateFolder:qe.templateFolder,error:Fe??``,onClose:()=>{Pe(null),Ie(null)},onSubmit:nt,onDelete:rt}),(0,Z.jsx)(Ot,{open:pe,prompts:ot,value:Xe,force:!Xe,onClose:()=>me(!1),onMount:Qe,onCreate:et,target:`用例类型`,createHint:`会按用例生成的模板生成一份(逐条覆盖、边界 / 异常 / 优先级),之后可在「提示词管理」里改。`})]})}function Wc({open:e,onClose:t,initial:n,onConfirm:r}){let[i,a]=(0,K.useState)(!1),[o,s]=(0,K.useState)(``),[c,l]=(0,K.useState)(()=>Si()),[u,d]=(0,K.useState)(Si()[0]?.id??`case`),[f,p]=(0,K.useState)(null),[m,h]=(0,K.useState)(null),[g,_]=(0,K.useState)(null),v=c.find(e=>e.id===u)??c[0]??Ci(u);function y(e){let t=Si();l(t),d(n=>{let r=e??n;return t.some(e=>e.id===r)?r:t[0]?.id??n})}function b(e){let t=m===`add`;try{if(t){let t=Ti(e);y(t.id),M(`已新增提示词类型「${t.label}」`,`success`)}else Ei(u,e),y(u),M(`已重命名为「${e.trim()}」`,`success`);h(null),_(null)}catch(e){let n=e instanceof Error?e.message:String(e);_(n),M(`${t?`新增`:`保存`}提示词类型失败:${n}`,`error`)}}function x(){try{let e=v.label,t=Di(u);l(t),d(t[0]?.id??``),h(null),_(null),p(null),M(`已删除提示词类型「${e}」`,`success`)}catch(e){let t=e instanceof Error?e.message:String(e);_(t),M(`删除提示词类型失败:${t}`,`error`)}}(0,K.useEffect)(()=>{e&&(y(n?.kind),s(n?.titleHint??``),d(n?.kind??Si()[0]?.id??`case`),h(null),_(null),p(null),Te(`prompts`).then(a))},[e,n]);function S(){p(null),i?(r({active:!0,titleHint:o.trim(),kind:u,confirmedAt:Date.now(),linkedPromptPath:n?.linkedPromptPath}),t()):p(`本地文档服务未就绪,无法写入提示词库`)}return(0,Z.jsxs)(ht,{open:e,onClose:t,title:`生成提示词 · 配置`,closeAriaLabel:`关闭生成提示词面板`,escDisabled:m!==null,footer:(0,Z.jsxs)(`footer`,{className:`shrink-0 p-4 border-t border-stone-100 flex items-center gap-2`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:t,className:`h-9 px-3 text-sm text-stone-600 rounded-lg hover:bg-stone-100`,children:`取消`}),(0,Z.jsx)(`button`,{type:`button`,disabled:!i,onClick:S,className:`flex-1 h-9 text-sm font-medium text-white bg-[#4176e6] rounded-lg hover:bg-[#3565c7] disabled:opacity-40`,children:`确认`})]}),children:[i?null:(0,Z.jsx)(`div`,{className:`rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-sm text-amber-900`,children:`本地文档服务未就绪,无法读写提示词库。`}),(0,Z.jsx)(`p`,{className:`text-xs text-stone-500 leading-5`,children:`按所选类型生成可复用提示词:确认后在主输入框描述编写要求并发送,质检通过后写入提示词库,可在「提示词管理」中查看与引用。`}),f?(0,Z.jsx)(`div`,{className:`text-sm text-red-700 bg-red-50 border border-red-200 rounded-lg px-3 py-2`,children:f}):null,(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`mb-1 flex items-center gap-2`,children:[(0,Z.jsx)(`div`,{className:`flex-1 text-xs font-medium text-stone-500`,children:`提示词类型`}),(0,Z.jsx)(`button`,{type:`button`,className:`inline-flex h-[23px] items-center rounded border border-stone-200 px-1.5 text-[11px] leading-none text-[#4176e6] transition-colors hover:border-[#4176e6]/40 hover:bg-[#edf3fe]`,onClick:()=>{h(`add`),_(null)},children:`新增`}),(0,Z.jsx)(`button`,{type:`button`,className:`inline-flex h-[23px] items-center rounded border border-stone-200 px-1.5 text-[11px] leading-none text-stone-600 transition-colors hover:border-stone-300 hover:bg-stone-50`,onClick:()=>{h(`edit`),_(null)},children:`编辑`}),(0,Z.jsx)(`button`,{type:`button`,className:`inline-flex h-[23px] items-center rounded border border-stone-200 px-1.5 text-[11px] leading-none text-red-600 transition-colors hover:border-red-300 hover:bg-red-50 disabled:opacity-40 disabled:hover:border-stone-200 disabled:hover:bg-transparent`,disabled:c.length<=1,onClick:()=>{h(`delete`),_(null)},children:`删除`})]}),(0,Z.jsx)(j,{options:c.map(e=>({value:e.id,label:e.label})),value:u,onChange:d,dimWhenOpen:!0}),(0,Z.jsx)(`p`,{className:`mt-1 text-[11px] text-stone-400 leading-4`,children:v.hint}),(0,Z.jsx)(`p`,{className:`mt-1 text-[11px] text-stone-400 leading-4`,children:`类型决定生成时给模型的写作侧重(例如用例提示词要求约束 JSON 与模板字段), 同时出现在这份提示词的配置标签里;不影响你在主输入框补充的具体要求。`})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`text-xs font-medium text-stone-500`,htmlFor:`pg-title`,children:`期望名称`}),(0,Z.jsx)(`input`,{id:`pg-title`,value:o,onChange:e=>s(e.target.value),placeholder:`如:接口测试用例提示词.md`,className:`mt-1 w-full h-9 px-3 text-sm rounded-lg border border-stone-200 focus:outline-none focus:ring-2 focus:ring-[#4176e6]/40`}),(0,Z.jsx)(`p`,{className:`mt-1.5 text-[11px] text-stone-400 leading-4`,children:`可填期望文件名;留空则由模型自拟。具体编写要求在主输入框描述。`})]}),(0,Z.jsx)(Rc,{mode:m,entityLabel:`提示词类型`,currentLabel:v.label,placeholder:`如:缺陷分析提示词`,error:g??``,onClose:()=>{h(null),_(null)},onSubmit:b,onDelete:x,hint:e=>(0,Z.jsxs)(Z.Fragment,{children:[`类型名称会写入这份提示词的配置标签:`,e||`名称`]}),deleteMessage:e=>(0,Z.jsxs)(Z.Fragment,{children:[`确定删除「`,e,`」?已生成的提示词与文档不会被删除,只是不能再选这个类型。`]})})]})}function Gc({open:e,onClose:t,initial:n,onConfirm:r}){let[i,a]=(0,K.useState)(!1),[o,s]=(0,K.useState)(``),[c,l]=(0,K.useState)(()=>Li()),[u,d]=(0,K.useState)(Li()[0]??`测试规范`),[f,p]=(0,K.useState)(null),[m,h]=(0,K.useState)(null),[g,_]=(0,K.useState)(null);function v(e){let t=Li();l(t),d(n=>{let r=e??n;return t.includes(r)?r:t[0]??n})}function y(e){let t=m===`add`;try{if(t){let t=zi(e);v(t),M(`已新增分类「${t}」`,`success`)}else{let t=Bi(u,e);v(t),M(`已重命名为「${t}」`,`success`)}h(null),_(null)}catch(e){let n=e instanceof Error?e.message:String(e);_(n),M(`${t?`新增`:`保存`}分类失败:${n}`,`error`)}}function b(){try{let e=u,t=Vi(u);l(t),d(t[0]??``),h(null),_(null),p(null),M(`已删除分类「${e}」`,`success`)}catch(e){let t=e instanceof Error?e.message:String(e);_(t),M(`删除分类失败:${t}`,`error`)}}(0,K.useEffect)(()=>{e&&(v(n?.category),s(n?.titleHint??``),d(n?.category??Li()[0]??`测试规范`),h(null),_(null),p(null),Te(`knowledge`).then(a))},[e,n]);function x(){p(null),i?(r({active:!0,titleHint:o.trim(),category:u,confirmedAt:Date.now(),linkedKnowledgePath:n?.linkedKnowledgePath}),t()):p(`本地文档服务未就绪,无法写入知识库`)}return(0,Z.jsxs)(ht,{open:e,onClose:t,title:`生成知识库 · 配置`,closeAriaLabel:`关闭生成知识库面板`,escDisabled:m!==null,footer:(0,Z.jsxs)(`footer`,{className:`shrink-0 p-4 border-t border-stone-100 flex items-center gap-2`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:t,className:`h-9 px-3 text-sm text-stone-600 rounded-lg hover:bg-stone-100`,children:`取消`}),(0,Z.jsx)(`button`,{type:`button`,disabled:!i,onClick:x,className:`flex-1 h-9 text-sm font-medium text-white bg-[#4176e6] rounded-lg hover:bg-[#3565c7] disabled:opacity-40`,children:`确认`})]}),children:[i?null:(0,Z.jsx)(`div`,{className:`rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-sm text-amber-900`,children:`本地文档服务未就绪,无法读写知识库。`}),(0,Z.jsx)(`p`,{className:`text-xs text-stone-500 leading-5`,children:`按所选分类沉淀测试规范、方法论或环境约定:确认后在主输入框粘贴/描述素材并发送,质检通过后写入知识库,可在「知识库管理」中查看与 @ 引用。`}),f?(0,Z.jsx)(`div`,{className:`text-sm text-red-700 bg-red-50 border border-red-200 rounded-lg px-3 py-2`,children:f}):null,(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`mb-1 flex items-center gap-2`,children:[(0,Z.jsx)(`div`,{className:`flex-1 text-xs font-medium text-stone-500`,children:`分类`}),(0,Z.jsx)(`button`,{type:`button`,className:`inline-flex h-[23px] items-center rounded border border-stone-200 px-1.5 text-[11px] leading-none text-[#4176e6] transition-colors hover:border-[#4176e6]/40 hover:bg-[#edf3fe]`,onClick:()=>{h(`add`),_(null)},children:`新增`}),(0,Z.jsx)(`button`,{type:`button`,className:`inline-flex h-[23px] items-center rounded border border-stone-200 px-1.5 text-[11px] leading-none text-stone-600 transition-colors hover:border-stone-300 hover:bg-stone-50`,onClick:()=>{h(`edit`),_(null)},children:`编辑`}),(0,Z.jsx)(`button`,{type:`button`,className:`inline-flex h-[23px] items-center rounded border border-stone-200 px-1.5 text-[11px] leading-none text-red-600 transition-colors hover:border-red-300 hover:bg-red-50 disabled:opacity-40 disabled:hover:border-stone-200 disabled:hover:bg-transparent`,disabled:c.length<=1,onClick:()=>{h(`delete`),_(null)},children:`删除`})]}),(0,Z.jsx)(j,{options:c.map(e=>({value:e,label:e})),value:u,onChange:d,dimWhenOpen:!0}),(0,Z.jsx)(`p`,{className:`mt-1 text-[11px] text-stone-400 leading-4`,children:`分类决定两件事:生成时告诉模型按哪类知识写(规范 / 方法论 / 环境约定侧重不同), 入库时写进文档 frontmatter 的 category,知识库管理里就按它归类展示。`})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`text-xs font-medium text-stone-500`,htmlFor:`kg-title`,children:`期望名称`}),(0,Z.jsx)(`input`,{id:`kg-title`,value:o,onChange:e=>s(e.target.value),placeholder:`如:接口自动化环境约定.md`,className:`mt-1 w-full h-9 px-3 text-sm rounded-lg border border-stone-200 focus:outline-none focus:ring-2 focus:ring-[#4176e6]/40`}),(0,Z.jsx)(`p`,{className:`mt-1.5 text-[11px] text-stone-400 leading-4`,children:`可填期望文件名;留空则由模型自拟。素材与编写要求在主输入框描述。`})]}),(0,Z.jsx)(Rc,{mode:m,entityLabel:`知识库分类`,currentLabel:u,placeholder:`如:安全基线`,error:g??``,onClose:()=>{h(null),_(null)},onSubmit:y,onDelete:b,hint:()=>(0,Z.jsx)(Z.Fragment,{children:`分类写入文档 frontmatter,文件平铺存放于 知识库管理/;改名不会自动迁移已有文件。`}),deleteMessage:e=>(0,Z.jsxs)(Z.Fragment,{children:[`确定删除「`,e,`」?已入库的知识文档不会被删除,但该分类将不能再用于生成。`]})})]})}function Kc({task:e,onClose:t,onSave:n,onRemove:r}){let[i,a]=(0,K.useState)(``),o=!!e;(0,K.useEffect)(()=>{a(e?.body??``)},[e]);let s=!!e&&i.trim()!==e?.body.trim();return(0,Z.jsxs)(C,{open:o,onClose:t,transition:!0,className:`relative z-110`,children:[(0,Z.jsx)(w,{transition:!0,className:`tw-dialog-backdrop-anim fixed inset-0 bg-black/30`,"aria-hidden":`true`}),(0,Z.jsx)(`div`,{className:`fixed inset-0 flex items-center justify-center p-4`,children:(0,Z.jsxs)(x,{transition:!0,className:`tw-dialog-panel-anim relative flex max-h-[85vh] w-full max-w-2xl flex-col rounded-xl border border-stone-200 bg-white p-5 shadow-xl`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:t,className:`absolute top-3.5 right-3.5 flex h-7 w-7 items-center justify-center rounded-md text-stone-400 transition-colors hover:bg-stone-100 hover:text-stone-700`,"aria-label":`关闭`,children:`✕`}),(0,Z.jsx)(S,{className:`pr-8 text-base font-semibold text-stone-900`,children:e?.label||`任务要求`}),(0,Z.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-2 gap-y-0.5 text-[11px] text-stone-400`,children:[(0,Z.jsx)(`span`,{children:`发送时这段要求会随消息一起带给模型`}),e?.detail?(0,Z.jsxs)(`span`,{className:`truncate`,children:[`· `,e.detail]}):null]}),(0,Z.jsx)(`textarea`,{value:i,onChange:e=>a(e.target.value),spellCheck:!1,className:`mt-3 min-h-[240px] flex-1 resize-none overflow-y-auto rounded-lg border border-stone-200 bg-stone-50/60 px-3 py-2.5 font-mono text-[12.5px] leading-relaxed text-stone-700 outline-none focus:border-[#4176e6]/40 focus:bg-white`}),(0,Z.jsxs)(`div`,{className:`mt-4 flex items-center justify-between gap-2`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:r,className:`h-8 rounded-lg border border-stone-200 px-3 text-sm text-stone-500 transition-colors hover:border-red-300 hover:bg-red-50 hover:text-red-600`,children:`移除`}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:t,className:`h-8 rounded-lg border border-stone-200 px-3 text-sm text-stone-600 transition-colors hover:bg-stone-100`,children:`取消`}),(0,Z.jsx)(`button`,{type:`button`,disabled:!i.trim(),onClick:()=>n(i.trim()),className:`h-8 rounded-lg bg-[#4176e6] px-3.5 text-sm text-white transition-colors hover:bg-[#3566d0] disabled:cursor-not-allowed disabled:bg-stone-300`,children:s?`保存修改`:`完成`})]})]})]})})]})}var qc={user:`用户档案`,memory:`长期记忆`,key:`项目关键记忆`,project:`项目日志`};function Jc(e){return e?e.replace(/\\/g,`/`).replace(/^\/Users\/[^/]+/,`~`):``}var Yc={project:{title:`项目日志`,fileHint:`MEMORY.md`,desc:`项目进展流水账,按需查阅,默认不注入上下文。`,curated:!1},key:{title:`项目关键记忆`,fileHint:`KEY.md`,desc:`项目关键约定与事实;写入需经待确认记忆建议采纳后注入。`,curated:!0},memory:{title:`长期记忆`,fileHint:`MEMORY.md`,desc:`全局环境与跨项目事实,注入所有会话;写入需审查建议并经确认。`,curated:!0}},Xc=[{id:`guide`,label:`指南`},{id:`suggestions`,label:`待确认记忆建议`},{id:`project`,label:`项目日志`},{id:`key`,label:`项目关键记忆 KEY.md`},{id:`memory`,label:`长期记忆 MEMORY.md`},{id:`agents`,label:`全局规则 AGENTS.md`},{id:`archive`,label:`归档`},{id:`settings`,label:`设置`}];function Zc({live:e,pluginOn:t,workspacePath:n=``}){let[r,i]=(0,K.useState)(`suggestions`),[a,o]=(0,K.useState)(null),[s,c]=(0,K.useState)({}),[l,u]=(0,K.useState)(``),[d,f]=(0,K.useState)([]),[p,m]=(0,K.useState)([]),[h,g]=(0,K.useState)(`memory`),[_,v]=(0,K.useState)(null),[y,b]=(0,K.useState)([]),[x,S]=(0,K.useState)(null),[C,w]=(0,K.useState)(``),[T,E]=(0,K.useState)(!1),[D,O]=(0,K.useState)(null),[k,ee]=(0,K.useState)(null),[te,j]=(0,K.useState)(null),M=n.trim(),ne=(0,K.useCallback)(async()=>{if(!e)o(null),c({}),f([]),b([]);else{S(null);try{let[e,t,n,i,a]=await Promise.all([nr(),rr(M,`all`),dr(),hr(),Vt().catch(()=>null)]);o(e),c(t.tracks),u(t.projectId||``),f(n),v(i),b(a?.files?.length?a.files:a?.text?[{path:`AGENTS.md`,name:`AGENTS.md`}]:[]),r===`archive`&&m(await sr(h,M))}catch(e){S(e instanceof Error?e.message:String(e))}}},[e,M,r,h]);if((0,K.useEffect)(()=>{ne()},[ne]),!t)return(0,Z.jsxs)(`div`,{className:`h-full flex flex-col items-center justify-center text-center px-6`,children:[(0,Z.jsx)(`p`,{className:`text-sm text-stone-600`,children:`会话记忆未启用`}),(0,Z.jsx)(`p`,{className:`mt-1 text-xs text-stone-400`,children:`在「我的插件」中打开「会话记忆」后,可在此管理记忆轨与待确认记忆建议`})]});if(!e)return(0,Z.jsxs)(`div`,{className:`h-full flex flex-col items-center justify-center text-center px-6`,children:[(0,Z.jsx)(`p`,{className:`text-sm text-stone-600`,children:`会话记忆中间件未就绪`}),(0,Z.jsx)(`p`,{className:`mt-1 text-xs text-stone-400`,children:`本地记忆服务未就绪`})]});let re=r===`memory`||r===`key`,ie=r===`memory`||r===`key`||r===`project`,ae=ie?s[r]?.entries??[]:[],N=ie?s[r]?.path:null,P=a?.path||`.lantern/local/memories`;async function oe(e){E(!0);try{await or(e),await ne()}catch(e){S(e instanceof Error?e.message:String(e))}finally{E(!1)}}async function se(e){E(!0);try{await gr(e),await ne()}catch(e){S(e instanceof Error?e.message:String(e))}finally{E(!1)}}function ce(e){re&&ee(e)}async function le(){if(k==null||!re)return;let e=k;ee(null),E(!0);try{await G(r,e,M),await ne()}catch(e){S(e instanceof Error?e.message:String(e))}finally{E(!1)}}async function ue(){if(te==null)return;let e=te;j(null),E(!0);try{await ur(h,e,M),await ne()}catch(e){S(e instanceof Error?e.message:String(e))}finally{E(!1)}}function F(e){O(e)}async function de(){if(D==null)return;let e=D;O(null),E(!0);try{await pr(r,e,M),await ne()}catch(e){S(e instanceof Error?e.message:String(e))}finally{E(!1)}}async function fe(){if(re&&C.trim()){E(!0);try{await cr(r,C.trim(),M),w(``),await ne()}catch(e){S(e instanceof Error?e.message:String(e))}finally{E(!1)}}}async function I(e){E(!0);try{let t=await tr(e);v(t)}catch(e){S(e instanceof Error?e.message:String(e))}finally{E(!1)}}function L(e){let t=Yc[e],n=e===`key`?`KEY.md`:t.fileHint,r=e===`key`?`项目关键记忆 ${n}`:e===`memory`?`长期记忆 ${n}`:t.title,i=Jc(N)||`${Jc(P)}/…/${n}`;return(0,Z.jsxs)(`div`,{className:`mb-3 space-y-1.5`,children:[(0,Z.jsxs)(`div`,{className:`flex items-start gap-2 flex-wrap min-w-0`,children:[(0,Z.jsx)(`h3`,{className:`text-sm font-semibold text-stone-800`,children:r}),t.curated?null:(0,Z.jsx)(`span`,{className:`px-1.5 py-0.5 text-[10px] rounded bg-stone-100 text-stone-500 border border-stone-200`,children:`只读追加`}),(0,Z.jsxs)(`span`,{className:`text-[11px] text-stone-400 tabular-nums`,children:[ae.length,` 条`]}),(0,Z.jsx)(`span`,{className:`max-w-full break-all whitespace-normal text-[11px] text-[#4176e6] bg-[#edf3fe] border border-[#4176e6]/20 rounded-lg px-2 py-0.5 font-mono leading-4`,"data-hint":N||i,children:i})]}),(0,Z.jsx)(`p`,{className:`text-xs text-stone-500 leading-5 break-words`,children:t.desc}),M?(0,Z.jsxs)(`p`,{className:`text-[11px] text-stone-400 break-all`,children:[`当前会话工作目录:`,(0,Z.jsx)(`span`,{className:`font-mono`,children:M}),l?(0,Z.jsxs)(Z.Fragment,{children:[` · `,`项目 id `,(0,Z.jsx)(`span`,{className:`font-mono`,children:l.slice(0,12)})]}):null]}):null]})}return(0,Z.jsxs)(`div`,{className:`h-full flex flex-col min-h-0`,children:[(0,Z.jsxs)(`div`,{className:`shrink-0 flex flex-wrap items-center gap-2 px-4 py-2 border-b border-stone-200/80`,children:[Xc.map(e=>(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>i(e.id),className:`h-7 px-2.5 text-xs rounded-md whitespace-normal text-left leading-tight ${r===e.id?`bg-stone-900 text-white`:`text-stone-600 hover:bg-stone-100`}`,children:[e.label,e.id===`suggestions`&&d.length>0?(0,Z.jsxs)(`span`,{className:`ml-1 tabular-nums`,children:[`(`,d.length,`)`]}):null]},e.id)),(0,Z.jsxs)(`span`,{className:`text-[11px] text-stone-400 tabular-nums`,children:[a?.entryCount??0,` 条 · 待确认 `,a?.suggestionCount??d.length]})]}),x?(0,Z.jsx)(`div`,{className:`mx-4 mt-3 px-3 py-2 text-sm text-red-700 bg-red-50 border border-red-200 rounded-lg`,children:x}):null,(0,Z.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4`,children:[r===`guide`?(0,Z.jsxs)(`div`,{className:`space-y-3 max-w-2xl`,children:[(0,Z.jsxs)(`section`,{className:`rounded-xl border border-stone-200 bg-white p-4`,children:[(0,Z.jsx)(`h3`,{className:`text-sm font-semibold text-stone-800`,children:`确认制:为什么必须你点头`}),(0,Z.jsx)(`p`,{className:`mt-1.5 text-xs text-stone-500 leading-5`,children:`记忆会改变后续对话行为。长期记忆 / 项目关键记忆经「待确认记忆建议」采纳后才写入并注入;项目日志可直写但不注入。`})]}),(0,Z.jsxs)(`section`,{className:`rounded-xl border border-stone-200 bg-white p-4`,children:[(0,Z.jsx)(`h3`,{className:`text-sm font-semibold text-stone-800`,children:`待确认记忆建议:AI 只提议,你拍板`}),(0,Z.jsx)(`p`,{className:`mt-1.5 text-xs text-stone-500 leading-5`,children:`后台或对话中产出的记忆建议进入独立队列。采纳可写入对应轨;拒绝则丢弃。`}),(0,Z.jsxs)(`ul`,{className:`mt-2 space-y-1.5 text-xs text-stone-600`,children:[(0,Z.jsx)(`li`,{className:`rounded-lg bg-stone-50 border border-stone-100 px-2.5 py-2 break-words`,children:`采纳 → 长期记忆 MEMORY.md / 项目关键记忆 KEY.md`}),(0,Z.jsx)(`li`,{className:`rounded-lg bg-stone-50 border border-stone-100 px-2.5 py-2`,children:`拒绝 → 丢弃,不落盘`})]})]}),(0,Z.jsxs)(`section`,{className:`rounded-xl border border-stone-200 bg-white p-4`,children:[(0,Z.jsx)(`h3`,{className:`text-sm font-semibold text-stone-800`,children:`各轨文件(对齐 dsh)`}),(0,Z.jsxs)(`ul`,{className:`mt-2 space-y-1.5 text-xs text-stone-600`,children:[(0,Z.jsx)(`li`,{className:`rounded-lg bg-stone-50 border border-stone-100 px-2.5 py-2`,children:`项目日志 · 项目目录 MEMORY.md(不注入)`}),(0,Z.jsx)(`li`,{className:`rounded-lg bg-stone-50 border border-stone-100 px-2.5 py-2`,children:`项目关键记忆 KEY.md(注入,需确认)`}),(0,Z.jsx)(`li`,{className:`rounded-lg bg-stone-50 border border-stone-100 px-2.5 py-2`,children:`长期记忆 MEMORY.md(注入,需确认)`}),(0,Z.jsx)(`li`,{className:`rounded-lg bg-stone-50 border border-stone-100 px-2.5 py-2`,children:`全局规则:展示工作区 AGENTS.md 等规则文件`})]})]}),(0,Z.jsxs)(`section`,{className:`rounded-xl border border-stone-200 bg-white p-4`,children:[(0,Z.jsx)(`h3`,{className:`text-sm font-semibold text-stone-800`,children:`编辑与维护`}),(0,Z.jsx)(`p`,{className:`mt-1.5 text-xs text-stone-500 leading-5`,children:`可在本 Tab 浏览条目、手动添加(注入轨)、归档或删除。文件为 § 分隔结构化记忆,用外部编辑器打开时请谨慎修改。`}),(0,Z.jsxs)(`p`,{className:`mt-2 text-[11px] text-amber-700/90`,children:[`存储目录:`,(0,Z.jsx)(`code`,{className:`font-mono`,children:P})]})]})]}):null,r===`suggestions`?(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h3`,{className:`text-sm font-semibold text-stone-800`,children:`待确认记忆建议`}),(0,Z.jsx)(`p`,{className:`mt-1 text-xs text-stone-500 leading-5`,children:`后台审查或对话沉淀产出的记忆建议:采纳后写入记忆文件并注入;拒绝则丢弃。`})]}),d.length===0?(0,Z.jsx)(`div`,{className:`rounded-xl border border-dashed border-stone-200 bg-stone-50/50 px-4 py-16 text-center text-sm text-stone-400`,children:`没有待确认的建议。`}):(0,Z.jsx)(`ul`,{className:`space-y-3`,children:d.map(e=>(0,Z.jsxs)(`li`,{className:`rounded-lg border border-amber-200/80 bg-amber-50/30 p-3`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] text-stone-400 mb-1 flex-wrap`,children:[(0,Z.jsx)(`span`,{className:`px-1.5 py-0.5 rounded bg-amber-100 text-amber-900 border border-amber-200 font-medium`,children:`待确认记忆建议`}),(0,Z.jsx)(`span`,{className:`px-1.5 py-0.5 rounded bg-white text-stone-600 border border-stone-200`,children:qc[e.target]??e.target}),(0,Z.jsx)(`span`,{children:e.time}),e.hits&&e.hits>1?(0,Z.jsxs)(`span`,{children:[`×`,e.hits]}):null]}),(0,Z.jsx)(`p`,{className:`text-sm text-stone-800 whitespace-pre-wrap`,children:e.content}),e.reason?(0,Z.jsxs)(`p`,{className:`mt-1 text-xs text-stone-500`,children:[`原因:`,e.reason]}):null,(0,Z.jsxs)(`div`,{className:`mt-2 flex gap-2`,children:[(0,Z.jsx)(`button`,{type:`button`,disabled:T,onClick:()=>void oe(e.id),className:`h-7 px-2.5 text-xs text-white bg-emerald-600 rounded-md hover:bg-emerald-700 disabled:opacity-40`,children:`采纳`}),(0,Z.jsx)(`button`,{type:`button`,disabled:T,onClick:()=>void se(e.id),className:`h-7 px-2.5 text-xs text-stone-600 border border-stone-200 rounded-md hover:bg-stone-50 disabled:opacity-40`,children:`拒绝`})]})]},e.id))})]}):null,ie?(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[L(r),re?(0,Z.jsxs)(`div`,{className:`rounded-xl border border-stone-200 bg-white p-3 space-y-2`,children:[(0,Z.jsx)(`textarea`,{value:C,onChange:e=>w(e.target.value),placeholder:r===`key`?`输入一条项目关键约定,例如:本仓库包管理器用 pnpm…`:`输入一条想长期记住的全局事实/惯例/环境…`,rows:3,className:`w-full text-sm rounded-lg border border-stone-200 px-3 py-2 focus:outline-none focus:border-[#4176e6] resize-y`}),(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Z.jsx)(`p`,{className:`text-[11px] text-stone-400`,children:`手动写入会直接落盘;重要偏好更推荐走「待确认记忆建议」。`}),(0,Z.jsx)(`button`,{type:`button`,disabled:T||!C.trim(),onClick:()=>void fe(),className:`shrink-0 h-8 px-3 text-xs text-white bg-[#4176e6] rounded-lg disabled:opacity-40`,children:`保存`})]})]}):(0,Z.jsx)(`p`,{className:`text-xs text-stone-400`,children:`本轨由对话中 memory_append 自动追加,一般不注入上下文。`}),ae.length===0?(0,Z.jsx)(`div`,{className:`rounded-xl border border-dashed border-stone-200 bg-stone-50/50 px-4 py-12 text-center text-sm text-stone-400`,children:`(文件不存在或为空)`}):(0,Z.jsx)(`ul`,{className:`space-y-2`,children:ae.map(e=>(0,Z.jsxs)(`li`,{className:`rounded-lg border border-stone-200 bg-white px-3 py-2.5 flex gap-2`,children:[(0,Z.jsx)(`p`,{className:`flex-1 text-sm text-stone-800 whitespace-pre-wrap`,children:e.text}),(0,Z.jsxs)(`div`,{className:`shrink-0 self-start flex flex-col gap-0.5`,children:[re?(0,Z.jsx)(`button`,{type:`button`,disabled:T,onClick:()=>void ce(e.index),className:`h-7 px-2 text-[11px] text-stone-500 hover:bg-stone-50 rounded-md`,children:`归档`}):null,(0,Z.jsx)(`button`,{type:`button`,disabled:T,onClick:()=>void F(e.index),className:`h-7 px-2 text-[11px] text-red-600 hover:bg-red-50 rounded-md`,children:`删除`})]})]},`${r}-${e.index}`))})]}):null,r===`agents`?(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[(0,Z.jsx)(`h3`,{className:`text-sm font-semibold text-stone-800`,children:`全局规则`}),(0,Z.jsx)(`p`,{className:`text-xs text-stone-500 leading-5`,children:`工作区规则文件(AGENTS.md 等),随系统提示注入。`}),y.length===0?(0,Z.jsx)(`div`,{className:`rounded-xl border border-dashed border-stone-200 bg-stone-50/50 px-4 py-12 text-center text-sm text-stone-400`,children:`(未找到规则文件)`}):(0,Z.jsx)(`ul`,{className:`space-y-2 w-full`,children:y.map(e=>{let t=Jc(e.abs)||Jc(e.path)||e.label||e.path||e.name;return(0,Z.jsx)(`li`,{className:`w-full`,children:(0,Z.jsxs)(`div`,{className:`w-full flex items-center gap-4 rounded-xl border border-stone-200 bg-white px-4 py-3.5`,children:[(0,Z.jsx)(`span`,{className:`w-12 h-12 rounded-xl bg-[#edf3fe] text-[#4176e6] flex items-center justify-center text-[11px] font-semibold shrink-0`,children:(e.name.split(`.`).pop()||`MD`).toUpperCase()}),(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`span`,{className:`block text-[15px] font-medium text-stone-800 break-all`,children:e.name||`AGENTS.md`}),(0,Z.jsx)(`span`,{className:`block text-xs text-stone-400 break-all font-mono mt-1`,children:t})]}),(0,Z.jsx)(`button`,{type:`button`,disabled:T,onClick:()=>{S(null),E(!0),Nt(e.path||e.name||`AGENTS.md`,Re(),{abs:e.abs}).catch(e=>S(e instanceof Error?e.message:String(e))).finally(()=>E(!1))},className:`shrink-0 h-9 px-4 text-xs text-[#4176e6] border border-[#4176e6]/30 rounded-lg hover:bg-[#f5f8ff] disabled:opacity-40`,children:`打开文件`})]})},e.abs||e.path)})})]}):null,r===`archive`?(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[(0,Z.jsx)(`div`,{className:`flex gap-2`,children:[`user`,`memory`,`key`].map(e=>(0,Z.jsx)(`button`,{type:`button`,onClick:()=>{g(e)},className:`h-7 px-2.5 text-xs rounded-md ${h===e?`bg-stone-800 text-white`:`border border-stone-200`}`,children:qc[e]??e},e))}),p.length===0?(0,Z.jsx)(`p`,{className:`text-sm text-stone-400 text-center py-10`,children:`暂无归档`}):(0,Z.jsx)(`ul`,{className:`space-y-2`,children:p.map(e=>(0,Z.jsxs)(`li`,{className:`rounded-lg border border-stone-200 bg-white px-3 py-2.5 flex gap-2`,children:[(0,Z.jsx)(`p`,{className:`flex-1 text-sm text-stone-800 whitespace-pre-wrap`,children:e.text}),(0,Z.jsxs)(`div`,{className:`shrink-0 self-start flex flex-col gap-0.5`,children:[(0,Z.jsx)(`button`,{type:`button`,disabled:T,onClick:()=>void(async()=>{E(!0);try{await ir(h,e.index,M),await ne()}catch(e){S(e instanceof Error?e.message:String(e))}finally{E(!1)}})(),className:`h-7 px-2 text-[11px] text-emerald-700 hover:bg-emerald-50 rounded-md`,children:`转正`}),(0,Z.jsx)(`button`,{type:`button`,disabled:T,onClick:()=>j(e.index),className:`h-7 px-2 text-[11px] text-red-600 hover:bg-red-50 rounded-md`,children:`删除`})]})]},`a-${e.index}`))})]}):null,r===`settings`&&_?(0,Z.jsxs)(`div`,{className:`space-y-4 max-w-md`,children:[(0,Z.jsxs)(`label`,{className:`flex items-center justify-between gap-3 text-sm text-stone-700`,children:[(0,Z.jsx)(`span`,{children:`每回合注入 USER / MEMORY / KEY`}),(0,Z.jsx)(`input`,{type:`checkbox`,checked:_.injectMemory,onChange:e=>void I({injectMemory:e.target.checked})})]}),(0,Z.jsxs)(`label`,{className:`flex items-center justify-between gap-3 text-sm text-stone-700`,children:[(0,Z.jsx)(`span`,{children:`收尾提示写 project`}),(0,Z.jsx)(`input`,{type:`checkbox`,checked:_.perTurnProjectWrites,onChange:e=>void I({perTurnProjectWrites:e.target.checked})})]}),(0,Z.jsxs)(`label`,{className:`flex items-center justify-between gap-3 text-sm text-stone-700`,children:[(0,Z.jsx)(`span`,{children:`重要事实用 suggest(KEY)`}),(0,Z.jsx)(`input`,{type:`checkbox`,checked:_.perTurnKeyWrites,onChange:e=>void I({perTurnKeyWrites:e.target.checked})})]}),(0,Z.jsxs)(`p`,{className:`text-xs text-stone-400 leading-5 break-all`,children:[`存储目录:`,(0,Z.jsx)(`code`,{className:`font-mono`,children:a?.path??`.lantern/local/memories`}),`。memory/key 经待确认记忆建议后注入;project 不注入。`]})]}):null]}),(0,Z.jsx)(A,{open:D!=null,title:`删除记忆`,message:`永久删除该条目?此操作不可恢复。`,confirmLabel:`删除`,cancelLabel:`取消`,danger:!0,onClose:()=>O(null),onConfirm:()=>void de()}),(0,Z.jsx)(A,{open:k!=null,title:`归档记忆`,message:`归档该条目?归档后不再注入上下文。`,confirmLabel:`归档`,cancelLabel:`取消`,onClose:()=>ee(null),onConfirm:()=>void le()}),(0,Z.jsx)(A,{open:te!=null,title:`删除归档`,message:`永久删除该归档?此操作不可恢复。`,confirmLabel:`删除`,cancelLabel:`取消`,danger:!0,onClose:()=>j(null),onConfirm:()=>void ue()})]})}var Qc=`/`,$c=[{id:`all`,label:`全部待办`},{id:`open`,label:`未完成`},{id:`done`,label:`已完成`}],el={urgent_important:`bg-red-500`,important:`bg-amber-500`,urgent:`bg-orange-500`,normal:`bg-stone-300`},tl={urgent_important:`text-red-600`,important:`text-amber-600`,urgent:`text-orange-600`,normal:`text-stone-500`};function nl(){let e=new Date;return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`}function rl(e){let t=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e);return t?`${t[1]}/${t[2]}/${t[3]}`:``}function Q(e,t){let n=rl(e.dueDate),r=e.status===`done`||e.status===`cancelled`,i=gn(e,t),a=``,o=`text-stone-500`;return r?a=Sn[e.status]:i===null?(a=`未设置截止`,o=`text-stone-400`):i<0?(a=`逾期 ${Math.abs(i)} 天`,o=`text-red-600`):i===0?(a=`今天截止`,o=`text-[#4176e6]`):a=`剩余 ${i} 天`,{due:n,remain:a,tone:r?`text-stone-400`:o}}function il(e){return[...e].filter(e=>e.status===`done`||e.status===`cancelled`).sort((e,t)=>e.updatedAt<t.updatedAt?1:-1).slice(0,30)}function al(e,t,n){if(t===`done`)return[{key:`done`,label:`已完成 / 已取消`,items:il(e)}];let r=e.filter(e=>{let t=mn(e,n);return t!==`done`&&t!==`cancelled`}),i=[],a=[],o=[],s=[];for(let e of r){let t=gn(e,n);t===null?s.push(e):t<0?i.push(e):t===0?a.push(e):o.push(e)}let c=[{key:`overdue`,label:`已逾期`,items:i,tone:`text-red-600`},{key:`today`,label:`今天截止`,items:a,tone:`text-[#4176e6]`},{key:`later`,label:`接下来`,items:o},{key:`undated`,label:`没有截止日期`,items:s}];return t===`all`&&c.push({key:`done`,label:`已完成 / 已取消`,items:il(e)}),c.filter(e=>e.items.length>0)}function ol(e){let[t,n]=(0,K.useState)(null),[r,i]=(0,K.useState)(null),[a,o]=(0,K.useState)(`all`),[s,c]=(0,K.useState)({}),l=(0,K.useCallback)(async()=>{try{let e=await hn();n(e),i(null)}catch(e){i(e instanceof Error?e.message:String(e))}},[]);(0,K.useEffect)(()=>{l();let e=window.setInterval(()=>void l(),15e3);return()=>window.clearInterval(e)},[l]);let u=nl(),d=(0,K.useMemo)(()=>t?al(t,a,u):[],[t,a,u]),f=(0,K.useMemo)(()=>{let e=t??[],n=0,r=0,i=0;for(let t of e){let e=mn(t,u);if(e===`done`||e===`cancelled`)continue;i+=1;let a=gn(t,u);a!==null&&a<0?n+=1:a===0&&(r+=1)}return{overdue:n,dueToday:r,open:i}},[t,u]);async function p(e){if(s[e.id])return;let t=e.status===`done`?`pending`:`done`;c(t=>({...t,[e.id]:!0})),n(n=>n&&n.map(n=>n.id===e.id?{...n,status:t}:n));try{await vn(e.id,{status:t}),i(null)}catch(t){n(t=>t&&t.map(t=>t.id===e.id?{...t,status:e.status}:t)),i(t instanceof Error?t.message:String(t))}finally{c(t=>{let n={...t};return delete n[e.id],n})}}return e.live===!1?(0,Z.jsxs)(`div`,{className:`h-full flex flex-col items-center justify-center text-center px-6`,children:[(0,Z.jsx)(`p`,{className:`text-sm text-stone-600`,children:`待办事项需要本地服务`}),(0,Z.jsx)(`p`,{className:`mt-1 text-xs text-stone-400`,children:`当前未就绪(仅 npm run dev / 本地一体服务可用)`})]}):(0,Z.jsxs)(`div`,{className:`h-full flex flex-col min-h-0`,children:[(0,Z.jsxs)(`div`,{className:`shrink-0 flex flex-wrap items-center gap-2 px-4 py-2 border-b border-stone-200/80`,children:[$c.map(e=>(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>o(e.id),"aria-pressed":a===e.id,className:`h-7 px-2.5 text-xs rounded-md ${a===e.id?`bg-stone-900 text-white`:`text-stone-600 hover:bg-stone-100`}`,children:[e.label,e.id===`all`&&f.dueToday+f.overdue>0?(0,Z.jsx)(`span`,{className:`ml-1 tabular-nums`,children:f.dueToday+f.overdue}):null]},e.id)),(0,Z.jsxs)(`span`,{className:`ml-auto text-[11px] text-stone-400 tabular-nums`,children:[`未完成 `,f.open,f.overdue?` · 逾期 ${f.overdue}`:``]}),(0,Z.jsx)(`a`,{href:`${Qc}todos/`,className:`text-[11px] text-[#4176e6] hover:underline shrink-0`,children:`打开待办页 →`})]}),r?(0,Z.jsx)(`div`,{className:`mx-4 mt-3 px-3 py-2 text-sm text-red-700 bg-red-50 border border-red-200 rounded-lg`,children:r}):null,(0,Z.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-4 py-3`,children:t===null?(0,Z.jsx)(`div`,{className:`h-full flex items-center justify-center`,children:(0,Z.jsx)(`span`,{className:`tw-lib-spin`,"aria-hidden":`true`})}):d.length===0?(0,Z.jsxs)(`div`,{className:`h-full flex flex-col items-center justify-center text-center px-6`,children:[(0,Z.jsx)(`p`,{className:`text-sm text-stone-500`,children:a===`all`?`当前空间还没有待办`:a===`done`?`还没有已完成的待办`:`当前没有未完成的待办`}),(0,Z.jsx)(`a`,{href:`${Qc}todos/`,className:`mt-2 text-xs text-[#4176e6] hover:underline`,children:`去待办页新增 →`})]}):(0,Z.jsx)(`div`,{className:`space-y-4 max-w-3xl`,children:d.map(e=>(0,Z.jsxs)(`section`,{children:[(0,Z.jsxs)(`h3`,{className:`mb-1.5 flex items-center gap-1.5 px-1 text-[11px] font-medium ${e.tone??`text-stone-500`}`,children:[e.label,(0,Z.jsx)(`span`,{className:`text-stone-400 tabular-nums`,children:e.items.length})]}),(0,Z.jsx)(`ul`,{className:`list-none m-0 p-0 space-y-1`,children:e.items.map(e=>{let t=e.status===`done`||e.status===`cancelled`,n=Q(e,u);return(0,Z.jsxs)(`li`,{className:`group flex items-start gap-2 rounded-lg border border-stone-200 bg-white px-2.5 py-2 hover:border-stone-300`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:()=>void p(e),"aria-label":t?`恢复 ${e.title}`:`完成 ${e.title}`,"aria-pressed":t,className:`mt-0.5 grid h-4 w-4 shrink-0 place-items-center rounded-full border transition-colors ${t?`border-[#4176e6] bg-[#4176e6] text-white`:`border-stone-300 text-transparent hover:border-[#4176e6]`}`,children:(0,Z.jsx)(`svg`,{viewBox:`0 0 20 20`,width:`10`,height:`10`,fill:`none`,stroke:`currentColor`,strokeWidth:`3`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:(0,Z.jsx)(`path`,{d:`m4 10 4 4 8-9`})})}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[13px] leading-5 ${t?`text-stone-400 line-through`:`text-stone-800`}`,children:e.title}),t?(0,Z.jsx)(`span`,{className:`shrink-0 text-[11px] text-stone-400`,children:Sn[e.status]}):e.priority?(0,Z.jsxs)(`span`,{className:`flex shrink-0 items-center gap-1 text-[11px] ${tl[e.priority]??`text-stone-400`}`,children:[(0,Z.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full ${el[e.priority]??`bg-stone-300`}`}),Mn[e.priority]]}):null]}),(0,Z.jsxs)(`div`,{className:`mt-0.5 flex min-w-0 flex-wrap items-center gap-x-1.5 gap-y-0.5 text-[11px] leading-4`,children:[(0,Z.jsx)(`span`,{className:`shrink-0 text-stone-400 tabular-nums`,children:n.due?`截止 ${n.due}`:`无截止日期`}),(0,Z.jsx)(`span`,{className:`shrink-0 text-stone-300`,children:`·`}),(0,Z.jsx)(`span`,{className:`shrink-0 tabular-nums ${n.tone}`,children:n.remain}),e.linkedTask?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`span`,{className:`shrink-0 text-stone-300`,children:`·`}),(0,Z.jsxs)(`span`,{className:`min-w-0 truncate ${t?`text-stone-400`:`text-stone-500`}`,children:[`任务 `,e.linkedTask]})]}):null]})]})]},e.id)})})]},e.key))})})]})}var sl=`__routine__`;function cl(e){return{title:``,status:e===`todo`?`pending`:`pool`,priority:``,taskId:``,linkedTask:``,startDate:pn(),dueDate:pn(),note:``}}function ll(e,t){let n=Array.isArray(t)?t:[],r=[];for(let t of n){if(!t||typeof t!=`object`)continue;let n=t,i=typeof n.title==`string`?n.title.trim():``;if(!i)continue;let a=e===`todo`?Pn:jn,o=e===`todo`?H:U,s=cl(e);r.push({...s,title:i,status:typeof n.status==`string`&&a.includes(n.status)?n.status:e===`todo`?`pending`:`pool`,priority:typeof n.priority==`string`&&o.includes(n.priority)?n.priority:``,taskId:typeof n.taskId==`string`?n.taskId.trim():``,linkedTask:typeof n.linkedTask==`string`?n.linkedTask.trim():``,startDate:typeof n.startDate==`string`?n.startDate.trim().slice(0,10):s.startDate,dueDate:typeof n.dueDate==`string`?n.dueDate.trim().slice(0,10):s.dueDate,note:typeof n.note==`string`?n.note.trim():``})}return r}function ul(e,t){return t.map(t=>{let n={title:t.title.trim(),status:t.status,priority:t.priority,startDate:t.startDate,dueDate:t.dueDate,note:t.note};return e===`todo`&&(n.taskId=t.taskId,n.linkedTask=t.linkedTask),n})}var dl=`text-[11px] font-medium text-stone-500`,fl=`h-9 w-full rounded-lg border border-stone-200 px-2.5 text-[13px] text-stone-800 outline-none focus:border-[#4176e6]`;function pl(e){let t=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e);return t?`${t[1]}/${t[2]}/${t[3]}`:``}function ml(e){return(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-center justify-between gap-2`,children:[(0,Z.jsx)(`span`,{className:`shrink-0 text-[11px] text-stone-400`,children:e.label}),(0,Z.jsx)(`span`,{className:`min-w-0 truncate text-[12px] text-stone-700`,children:e.children})]})}function hl(e){return(0,Z.jsxs)(`div`,{className:`grid grid-cols-[48px_minmax(0,1fr)] items-center gap-x-2`,children:[(0,Z.jsx)(`span`,{className:`text-[11px] text-stone-400`,children:e.label}),(0,Z.jsx)(`span`,{className:`min-w-0 truncate text-[12px] text-stone-700`,children:e.children})]})}function gl(e){let{startDate:t,dueDate:n}=e,r=n||t,i=`h-7 rounded-md px-1.5 text-[12px] text-stone-700 tabular-nums transition-colors hover:bg-stone-100`;return(0,Z.jsxs)(`div`,{className:`grid grid-cols-[48px_minmax(0,1fr)] items-center gap-x-2`,children:[(0,Z.jsx)(`span`,{className:`text-[11px] text-stone-400`,children:`日期`}),(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-center gap-0.5`,children:[(0,Z.jsx)(`span`,{className:`min-w-0 flex-1`,children:(0,Z.jsx)(ee,{value:t,ariaLabel:`开始日期`,placeholder:`开始日期`,clearable:!1,className:i,onChange:t=>{t&&e.onChange({startDate:t,dueDate:t>r?t:r})}})}),(0,Z.jsx)(`span`,{className:`shrink-0 px-0.5 text-[11px] text-stone-300`,"aria-hidden":!0,children:`~`}),(0,Z.jsx)(`span`,{className:`min-w-0 flex-1`,children:(0,Z.jsx)(ee,{value:n,ariaLabel:`截止日期`,placeholder:`截止日期`,clearable:!1,className:i,onChange:n=>{n&&e.onChange({startDate:n<t?n:t,dueDate:n})}})})]})]})}function _l(e){let[t,n]=(0,K.useState)(()=>e.items),[r,i]=(0,K.useState)(0),[a,o]=(0,K.useState)([]);(0,K.useEffect)(()=>{n(e.items),i(0)},[e.items]);let s=e.kind===`todo`,c=!!e.quick&&s,l=s&&e.tasksOn!==!1,u=s&&!c&&l,d=s?`待办`:`任务`,f=s?`待办事项`:`任务管理`;(0,K.useEffect)(()=>{if(!l)return;let e=!0;return W().then(t=>{e&&o(t)}).catch(()=>{}),()=>{e=!1}},[l]);let p=s?Pn:jn,m=s?H:U,h=(0,K.useMemo)(()=>p.map(e=>({value:e,label:s?Sn[e]:En[e]})),[s,p]),g=(0,K.useMemo)(()=>[{value:``,label:`未设置`},...m.map(e=>({value:e,label:s?Mn[e]:kn[e]}))],[s,m]),_=(0,K.useMemo)(()=>[{value:``,label:`不关联`},...a.filter(e=>e.status!==`closed`&&e.status!==`cancelled`).map(e=>({value:e.id,label:e.title}))],[a]),v=(0,K.useMemo)(()=>!!Ha(a),[a]),y=(0,K.useMemo)(()=>{let e=new Set(t.map(e=>e.taskId).filter(Boolean));return[{value:``,label:`不关联`},...v?[]:[{value:sl,label:`${Ba}(确认后自动创建)`}],...a.filter(t=>e.has(t.id)||t.status!==`closed`&&t.status!==`cancelled`).map(e=>({value:e.id,label:e.title}))]},[t,a,v]);function b(e){return e.taskId&&a.some(t=>t.id===e.taskId)?e.taskId:!v&&e.linkedTask.trim()===`日常待办`?sl:``}function x(e,t){if(t===sl){S(e,{taskId:``,linkedTask:Ba});return}let n=a.find(e=>e.id===t);S(e,{taskId:n?.id??``,linkedTask:n?.title??``,...n?{priority:n.priority}:{}})}function S(e,t){n(n=>n.map((n,r)=>r===e?{...n,...t}:n))}function C(e,n){let r=t[e],i=a.find(e=>e.id===n);i?S(e,{taskId:i.id,linkedTask:i.title,startDate:i.startDate||r?.startDate||``,dueDate:i.dueDate||r?.dueDate||``,priority:r?.priority||i.priority||``}):S(e,{taskId:``,linkedTask:``})}function w(e){n(t=>t.filter((t,n)=>n!==e))}let T=t.length>0&&t.every(e=>!!e.title.trim()),E=u&&r>=1,D=c&&t.some(e=>!e.taskId.trim()&&e.linkedTask.trim()===`日常待办`)&&!v,O=E?`所属任务的日期与紧急程度已带到第一页,可回去再调`:c?D?e.quickNote??`确认后会自动创建任务「日常待办」并关联`:`状态 / 所属任务 / 日期已填好(日期可点开改),确认后写入「待办事项」`:`确认后才会写入「${f}」`;return(0,Z.jsxs)(`div`,{className:[`tw-create-card tw-create-card-anim mb-2 flex max-h-[min(62vh,560px)] flex-col overflow-hidden rounded-2xl border border-stone-200 bg-white shadow-[0_6px_24px_rgba(15,23,42,0.08)]`,e.closing?`is-closing`:``].filter(Boolean).join(` `),children:[(0,Z.jsxs)(`div`,{className:`shrink-0 px-5 pt-4`,children:[(0,Z.jsxs)(`div`,{className:`mb-1 flex items-center gap-2 text-[11px] leading-4 text-stone-400`,children:[(0,Z.jsxs)(`span`,{children:[`新增 `,t.length,` 条`,d]}),u?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`span`,{className:`text-stone-300`,children:`·`}),(0,Z.jsxs)(`span`,{className:`tabular-nums`,children:[`第 `,r+1,` / 2 步`]})]}):null]}),(0,Z.jsx)(`h3`,{className:`text-[15px] leading-5.5 font-medium text-stone-900`,children:E?`关联任务`:r===0?`确认内容后再添加到${f}`:f})]}),(0,Z.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto overscroll-contain px-5 py-3`,children:(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[t.map((e,n)=>{let r=a.find(t=>t.id===e.taskId);return(0,Z.jsx)(`div`,{className:`rounded-xl border border-stone-200 bg-stone-50/40 p-3`,children:c?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Z.jsx)(`input`,{value:e.title,onChange:e=>S(n,{title:e.target.value}),placeholder:`待办名称`,className:`${fl} bg-white`,autoFocus:n===0}),t.length>1?(0,Z.jsx)(`button`,{type:`button`,onClick:()=>w(n),"aria-label":`移除这一条`,className:`h-9 shrink-0 rounded-lg px-2 text-[12px] text-stone-400 hover:bg-white hover:text-red-600`,children:`移除`}):null]}),(0,Z.jsxs)(`div`,{className:`mt-2 space-y-1.5 rounded-lg border border-stone-200 bg-white px-2.5 py-2`,children:[(0,Z.jsx)(hl,{label:`状态`,children:Sn[e.status]??`进行中`}),l?(0,Z.jsxs)(`div`,{className:`grid grid-cols-[48px_minmax(0,1fr)] items-center gap-x-2`,children:[(0,Z.jsx)(`span`,{className:`text-[11px] text-stone-400`,children:`所属任务`}),a.length||!v?(0,Z.jsx)(j,{flat:!0,ariaLabel:`所属任务`,menuMatchTrigger:!1,menuMinWidth:200,options:y,value:b(e),onChange:e=>x(n,e),className:`min-w-0`,triggerClassName:`h-7 gap-1 rounded-md border-0 bg-transparent pl-0 pr-0.5 text-[12px] hover:bg-stone-50`}):(0,Z.jsx)(`span`,{className:`min-w-0 truncate text-[12px] text-stone-700`,children:e.linkedTask||`未关联`})]}):null,(0,Z.jsx)(gl,{startDate:e.startDate,dueDate:e.dueDate,onChange:e=>S(n,e)})]})]}):E?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,Z.jsx)(`span`,{className:dl,children:`所属任务`}),a.length?(0,Z.jsx)(j,{flat:!0,ariaLabel:`所属任务`,options:_,value:e.taskId,onChange:e=>C(n,e),className:`w-full`}):(0,Z.jsx)(`span`,{className:`flex h-9 items-center rounded-lg border border-stone-200 bg-white px-2 text-[13px] text-stone-400`,children:`任务管理里还没有任务,可稍后到任务管理关联`})]}),r?(0,Z.jsxs)(`div`,{className:`mt-2 space-y-1.5 rounded-lg border border-stone-200 bg-white px-2.5 py-2`,children:[(0,Z.jsx)(ml,{label:`任务名称`,children:r.title}),(0,Z.jsx)(ml,{label:`状态`,children:En[r.status]??r.status}),(0,Z.jsx)(ml,{label:`紧急程度`,children:r.priority?kn[r.priority]:`未设置`}),(0,Z.jsx)(ml,{label:`开始日期`,children:pl(r.startDate)||`未设置`}),(0,Z.jsx)(ml,{label:`结束日期`,children:pl(r.dueDate)||`未设置`})]}):(0,Z.jsx)(`p`,{className:`mt-2 text-[11px] leading-4 text-stone-400`,children:`选中任务后,它的开始 / 结束日期与紧急程度会自动带到第一页。`})]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Z.jsx)(`input`,{value:e.title,onChange:e=>S(n,{title:e.target.value}),placeholder:s?`待办名称`:`任务名称`,className:`${fl} bg-white`,autoFocus:n===0}),t.length>1?(0,Z.jsx)(`button`,{type:`button`,onClick:()=>w(n),"aria-label":`移除这一条`,className:`h-9 shrink-0 rounded-lg px-2 text-[12px] text-stone-400 hover:bg-white hover:text-red-600`,children:`移除`}):null]}),(0,Z.jsxs)(`div`,{className:`mt-2 grid grid-cols-2 gap-2`,children:[(0,Z.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,Z.jsx)(`span`,{className:dl,children:`状态`}),(0,Z.jsx)(j,{flat:!0,ariaLabel:s?`待办状态`:`任务状态`,options:h,value:e.status,onChange:e=>S(n,{status:e}),className:`w-full`})]}),(0,Z.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,Z.jsx)(`span`,{className:dl,children:`紧急程度`}),(0,Z.jsx)(j,{flat:!0,ariaLabel:`紧急程度`,options:g,value:e.priority,onChange:e=>S(n,{priority:e}),className:`w-full`})]}),(0,Z.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,Z.jsx)(`span`,{className:dl,children:`开始日期`}),(0,Z.jsx)(ee,{value:e.startDate,onChange:e=>S(n,{startDate:e}),placeholder:`选择日期`,className:`h-9 rounded-lg border border-stone-200 bg-white px-2 text-[13px] tabular-nums`})]}),(0,Z.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,Z.jsx)(`span`,{className:dl,children:`截止日期`}),(0,Z.jsx)(ee,{value:e.dueDate,onChange:e=>S(n,{dueDate:e}),placeholder:`选择日期`,className:`h-9 rounded-lg border border-stone-200 bg-white px-2 text-[13px] tabular-nums`})]})]}),(0,Z.jsxs)(`label`,{className:`mt-2 flex flex-col gap-1`,children:[(0,Z.jsx)(`span`,{className:dl,children:`备注`}),(0,Z.jsx)(`input`,{value:e.note,onChange:e=>S(n,{note:e.target.value}),placeholder:`备注(可选)`,className:`${fl} bg-white`})]})]})},n)}),t.length?null:(0,Z.jsx)(`p`,{className:`py-4 text-center text-[12px] text-stone-400`,children:`内容已清空,点「取消」放弃这次新增。`})]})}),(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between gap-3 border-t border-stone-100 px-5 py-3`,children:[(0,Z.jsx)(`span`,{className:`min-w-0 truncate text-[11px] text-stone-400`,children:O}),(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:E?()=>i(0):e.onCancel,className:`h-8 rounded-lg px-3 text-[12px] text-stone-600 outline-none hover:bg-stone-100`,children:E?`上一步`:`取消`}),(0,Z.jsx)(`button`,{type:`button`,disabled:!E&&!T,onClick:()=>{u&&r===0?i(1):e.onConfirm(t)},className:`h-8 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:u&&r===0?`下一步`:e.manual?`提交`:`确认新增`})]})]})]})}function vl(e,t,n){let r=e;if(n.knowledge&&(r=`${r}\n\n${cc}`),n.fs&&(r=`${r}\n\n${Bt}\n\n${ia}\n\n${io}\n\n${ai}\n\n${ti}`),n.bash&&(r=`${r}\n\n${Gn}`),n.pwsh&&(r=`${r}\n\n${Kn}`),n.web&&(r=`${r}\n\n${Vn}`),n.memory&&(r=`${r}\n\n${lr}`),n.interact&&(r=`${r}\n\n${go}`),n.todos&&(r=`${r}\n\n${ja}`),n.tasks&&(r=`${r}\n\n${Ka}`),n.projects&&(r=`${r}\n\n${ca}`),n.iterations&&(r=`${r}\n\n${la}`),n.pmRequirements&&(r=`${r}\n\n${ua}`),n.bugs&&(r=`${r}\n\n${da}`),n.planPhase===`planning`&&(r=`${r}\n\n${wo}`),n.planPhase===`approved`&&(r=`${r}\n\n${To}`),n.goalEnabled){r=`${r}\n\n${Ro}`;let e=Ho(n.goal);e&&(r=`${r}\n\n【当前会话目标】${e}`)}n.scheduleEnabled&&(r=`${r}\n\n${as}`),n.subagentEnabled&&(r=`${r}\n\n${ws}`),n.workflowEnabled&&(r=`${r}\n\n${Qs}`);let i=n.memory?t.slice(-10):t;return[{role:`system`,content:r},...i]}function yl(e){if(!/(?:^|[\s\n])\/$/.test(e))return null;let t=e.lastIndexOf(`/`);return t<0?null:{from:t}}function bl(e){let t=/(?:^|[\s\n])@([^\s@]*)$/.exec(e);if(!t)return null;let n=e.lastIndexOf(`@`);return n<0?null:{from:n,query:t[1]??``}}function xl(e){let t=/\s*(?:[((](?:recommended|推荐)[))])\s*$/i;return t.test(e)?{label:e.replace(t,``),recommended:!0}:{label:e,recommended:!1}}var Sl=je,Cl=5,wl=[`image/png`,`image/jpeg`,`image/jpg`,`image/webp`,`image/gif`],Tl=[`dialog`,`thread`,`todos`,`memory`],El=`chat.tab`;function Dl(e){let t=[];if(e.content&&t.push(e.content),e.refs?.length){let n=e.refs.filter(e=>e.collection!==`workspace`),r=e.refs.filter(e=>e.collection===`workspace`);if(n.length){let e=n.filter(e=>e.collection===`knowledge`||e.collection===`templates`),r=n.filter(e=>e.collection===`prompts`||e.collection===`cases`);if(e.length){let n=e.map(e=>`- ${e.path} 《${e.title}》(${e.category} · ${oc(e.format)})`);t.push(`引用项目文档(请使用 kb_read 读取):\n${n.join(`
217
+ `)||void 0,templateId:e?.id,templateTitle:e?.title,promptPath:I,knowledgePaths:R.length?[...R]:void 0,testPointIds:c.length?c.map(e=>e.id):void 0,testPointBlock:c.length?wr(c):void 0,templateHeaders:e?.headers?.length?e.headers:[...ue],templateBody:(e?.body||``).trim(),promptBody:ge.trim(),confirmedAt:Date.now(),linkedCasePath:n?.linkedCasePath}),t()}finally{je(!1)}}return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(ht,{open:e,onClose:t,title:`生成测试用例 · 配置`,closeAriaLabel:`关闭生成测试用例面板`,widthClass:`max-w-3xl`,escDisabled:Ne!==null,footer:(0,Z.jsxs)(`footer`,{className:`shrink-0 border-t border-stone-100 px-4 py-3 flex items-center gap-2`,children:[(0,Z.jsx)(`p`,{className:`flex-1 min-w-0 truncate text-[11px] text-stone-400`,children:`配置仅对当前会话生效,可在输入区胶囊里再改`}),(0,Z.jsx)(`button`,{type:`button`,onClick:t,className:`h-9 px-3 text-sm text-stone-600 rounded-lg hover:bg-stone-100`,children:`取消`}),(0,Z.jsx)(`button`,{type:`button`,disabled:Ae||!a||!Le||!Xe,onClick:()=>void bt(),className:`h-9 px-5 text-sm font-medium text-white bg-[#4176e6] rounded-lg hover:bg-[#3565c7] disabled:opacity-40`,children:`确认`})]}),children:[a?null:(0,Z.jsx)(`div`,{className:`rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-sm text-amber-900`,children:`本地文档服务未就绪,无法读写文档库。`}),Oe?(0,Z.jsx)(`div`,{className:`text-sm text-red-700 bg-red-50 border border-red-200 rounded-lg px-3 py-2`,children:Oe}):null,(0,Z.jsxs)(`div`,{className:`grid grid-cols-1 gap-x-4 gap-y-1 lg:grid-cols-2`,children:[(0,Z.jsxs)(`div`,{className:`order-1 min-w-0`,children:[(0,Z.jsx)(`div`,{className:`mb-1 text-xs font-medium text-stone-500`,children:`用例类型`}),(0,Z.jsx)(j,{options:T.map(e=>({value:e.id,label:e.label})),value:D,onChange:O,dimWhenOpen:!0})]}),(0,Z.jsxs)(`div`,{className:`order-3 min-w-0 lg:order-2`,children:[(0,Z.jsxs)(`div`,{className:`mb-1 text-xs font-medium text-stone-500`,children:[`用例模板`,(0,Z.jsxs)(`span`,{className:`ml-1 font-normal text-stone-400`,children:[`(`,Je,` · `,qe.templateFolder,`)`]})]}),(0,Z.jsx)(se,{options:at,value:Ke?.id??``,onChange:ce,allowEmpty:!1,disabled:!Ue,placeholder:Ue?at.length?`搜索并选择模板…`:`暂无「${qe.templateFolder}」模板`:`测试模板库未启用`})]}),(0,Z.jsxs)(`div`,{className:`order-2 flex min-w-0 items-start justify-end gap-1 pt-1.5 lg:order-3`,children:[(0,Z.jsx)(`button`,{type:`button`,className:`inline-flex h-[23px] items-center rounded border border-stone-200 px-1.5 text-[11px] leading-none text-[#4176e6] transition-colors hover:border-[#4176e6]/40 hover:bg-[#edf3fe]`,onClick:()=>{Ie(null),Pe(`add`)},children:`新增`}),(0,Z.jsx)(`button`,{type:`button`,className:`inline-flex h-[23px] items-center rounded border border-stone-200 px-1.5 text-[11px] leading-none text-stone-600 transition-colors hover:border-stone-300 hover:bg-stone-50`,onClick:()=>{Ie(null),Pe(`edit`)},children:`编辑`}),(0,Z.jsx)(`button`,{type:`button`,className:`inline-flex h-[23px] items-center rounded border border-stone-200 px-1.5 text-[11px] leading-none text-red-600 transition-colors hover:border-red-300 hover:bg-red-50 disabled:opacity-40 disabled:hover:border-stone-200 disabled:hover:bg-transparent`,disabled:T.length<=1,onClick:()=>{Ie(null),Pe(`delete`)},children:`删除`})]}),(0,Z.jsx)(`div`,{className:`order-4 min-w-0 lg:order-4`,children:Ue?Ke?.headers?.length?(0,Z.jsx)(he,{fields:Ke.headers}):null:(0,Z.jsx)(`p`,{className:`mt-1 text-[11px] text-stone-400`,children:`请先在「我的插件」中启用「测试模板库」后再选择;未启用时按默认字段生成。`})})]}),(0,Z.jsxs)(`div`,{className:`grid grid-cols-1 items-start gap-4 lg:grid-cols-2`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`div`,{className:`mb-1 text-xs font-medium text-stone-500`,children:`输出格式`}),(0,Z.jsx)(j,{options:Bc,value:Ee,onChange:De,dimWhenOpen:!0})]}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`div`,{className:`mb-1 text-xs font-medium text-stone-500`,children:`引用知识库(可多选)`}),(0,Z.jsx)(oe,{options:st,values:R,onChange:be,disabled:!ze,placeholder:ze?st.length?`选择知识库文档…`:`暂无知识库文档`:`知识库管理未启用`}),ze?null:(0,Z.jsx)(`p`,{className:`mt-1 text-[11px] text-stone-400`,children:`请先在「我的插件」中启用「知识库管理」后再引用。`})]})]}),(0,Z.jsxs)(`section`,{className:`rounded-xl border border-stone-200 p-3`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,Z.jsx)(`div`,{className:`text-xs font-medium text-stone-500`,children:`需求来源`}),(0,Z.jsxs)(`div`,{className:`inline-flex rounded-lg border border-stone-200 bg-stone-50 p-0.5`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:()=>g(`doc`),className:`h-7 rounded-md px-2.5 text-xs transition-colors ${p===`doc`?`bg-white text-stone-900 shadow-sm`:`text-stone-500 hover:text-stone-700`}`,children:`需求文档`}),(0,Z.jsx)(`button`,{type:`button`,disabled:!y,onClick:()=>{y&&g(`stories`)},className:`h-7 rounded-md px-2.5 text-xs transition-colors disabled:opacity-40 ${p===`stories`?`bg-white text-stone-900 shadow-sm`:`text-stone-500 hover:text-stone-700`}`,children:`用户故事`})]}),(0,Z.jsx)(`p`,{className:`text-[11px] text-stone-400`,children:p===`stories`?`来自「需求分析」拆好的故事:按 US 编号逐条覆盖,改动后重新生成即可`:`来自「需求文档库」的原始文档`})]}),(0,Z.jsx)(`div`,{className:`mt-2`,children:p===`stories`?(0,Z.jsx)(se,{options:_.map(e=>({value:e.id,label:`${e.title}(${e.stories.length} 个故事)`})),value:x,onChange:e=>{S(e);let t=_.find(t=>t.id===e);w(t?.stories.map(e=>e.id)??[]),Te([])},allowEmpty:!1,disabled:!y,placeholder:z?y?_.length?`搜索并选择需求分析记录…`:`暂无需求分析记录,请先在「需求分析」拆解`:`需求分析服务未就绪`:`需求分析插件未启用`}):(0,Z.jsx)(se,{options:it,value:d,onChange:f,allowEmpty:!1,disabled:!Ve,placeholder:Ve?it.length?`搜索并选择需求文档…`:`请先在需求文档库中上传`:`需求文档库未启用`})}),p===`stories`?(0,Z.jsxs)(`div`,{className:`mt-2 rounded-lg bg-stone-50/80 p-2.5`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsxs)(`div`,{className:`flex-1 text-[11px] text-stone-500`,children:[`选择故事`,(0,Z.jsxs)(`span`,{className:`ml-1 text-stone-400`,children:[ut,`/`,lt.length]})]}),(0,Z.jsx)(`button`,{type:`button`,className:`text-[11px] text-[#4176e6] hover:underline`,onClick:()=>w(lt.map(e=>e.id)),children:`全选`}),(0,Z.jsx)(`button`,{type:`button`,className:`text-[11px] text-stone-500 hover:underline`,onClick:()=>w([]),children:`全不选`})]}),lt.length?(0,Z.jsx)(`div`,{className:`mt-1.5 grid max-h-56 grid-cols-1 gap-x-4 overflow-y-auto sm:grid-cols-2`,children:lt.map(e=>(0,Z.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-1.5 py-1 text-xs`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,className:`mt-0.5`,checked:C.includes(e.id),onChange:t=>w(n=>t.target.checked?[...n,e.id]:n.filter(t=>t!==e.id))}),(0,Z.jsx)(`span`,{className:`shrink-0 font-mono text-[11px] text-stone-400`,children:e.id}),(0,Z.jsx)(`span`,{className:`min-w-0 flex-1`,children:(0,Z.jsx)(te,{text:e.title,className:`block truncate text-stone-800`})}),(0,Z.jsx)(`span`,{className:`shrink-0 text-[11px] text-stone-400`,children:e.priority})]},e.id))}):(0,Z.jsx)(`p`,{className:`mt-1.5 text-[11px] text-stone-400`,children:x?`这份分析还没有拆出用户故事`:`先选择一份需求分析记录`}),z?null:(0,Z.jsx)(`p`,{className:`mt-1.5 text-[11px] text-stone-400`,children:`需求分析插件已关闭;用户故事来源暂不可用,可改用「需求文档」。`})]}):Ve?null:(0,Z.jsx)(`p`,{className:`mt-1 text-[11px] text-stone-400`,children:`请先在「我的插件」中启用「需求文档库」后再选择。`})]}),(0,Z.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 lg:grid-cols-2`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`mb-1 flex items-center justify-between gap-2`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0 text-xs font-medium text-stone-500`,children:[`测试点(可多选)`,dt.length?(0,Z.jsxs)(`span`,{className:`ml-1 font-normal text-stone-400`,children:[ft.length,`/`,dt.length]}):null]}),dt.length?(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 text-[11px]`,children:[(0,Z.jsx)(`button`,{type:`button`,className:`text-[#4176e6] transition-colors hover:text-[#3565c7]`,onClick:()=>Te(dt.map(e=>e.id)),children:`全选`}),(0,Z.jsx)(`button`,{type:`button`,className:`text-stone-500 transition-colors hover:text-stone-700`,onClick:()=>Te([]),children:`清空`})]}):null]}),(0,Z.jsx)(oe,{options:pt,values:ft,onChange:Te,disabled:!pt.length,placeholder:mt}),(0,Z.jsx)(`p`,{className:`mt-1 text-[11px] text-stone-400`,children:yt})]}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`mb-1 text-xs font-medium text-stone-500`,children:[`提示词`,(0,Z.jsxs)(`span`,{className:`ml-1 font-normal text-stone-400`,children:[`(`,Je,` 挂载)`]})]}),(0,Z.jsx)(`button`,{type:`button`,disabled:!Le,onClick:()=>me(!0),className:`flex h-9 w-full min-w-0 items-center gap-2 rounded-lg border px-2.5 text-left text-sm transition-colors disabled:cursor-not-allowed disabled:opacity-50 ${Ze?`border-amber-300 bg-amber-50/50 text-amber-700 hover:border-amber-400`:`border-stone-200 bg-white text-stone-800 hover:border-stone-300`}`,children:(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:Le?Xe?Xe.replace(/\.md$/i,``):de?`未挂载提示词 · 点击挂载`:`读取提示词…`:`提示词管理未启用`})}),(0,Z.jsx)(`p`,{className:`mt-1 text-[11px] text-stone-400`,children:Le?Ze?de?`当前类型还没有挂载提示词,未挂载时无法确认。`:`正在读取提示词列表…`:`每个用例类型只挂一份提示词:换类型会切到该类型挂载的那份。`:`请先在「我的插件」中启用「提示词管理」后再挂载。`})]})]}),(0,Z.jsxs)(`section`,{className:`rounded-xl border border-stone-200 bg-stone-50/60 px-4 py-3`,children:[(0,Z.jsx)(`div`,{className:`text-xs font-semibold text-stone-600`,children:`本次配置`}),(0,Z.jsxs)(`dl`,{className:`mt-2 grid grid-cols-2 gap-x-4 gap-y-2 sm:grid-cols-3`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`dt`,{className:`text-[10px] text-stone-400`,children:`用例类型`}),(0,Z.jsx)(`dd`,{className:`truncate text-xs text-stone-700`,children:Je})]}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`dt`,{className:`text-[10px] text-stone-400`,children:`用例模板`}),(0,Z.jsx)(`dd`,{className:`truncate text-xs text-stone-700`,children:Ke?.title||`—`})]}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`dt`,{className:`text-[10px] text-stone-400`,children:`输出格式`}),(0,Z.jsx)(`dd`,{className:`truncate text-xs text-stone-700`,children:Bc.find(e=>e.value===Ee)?.label??Ee})]}),(0,Z.jsxs)(`div`,{className:`col-span-2 min-w-0`,children:[(0,Z.jsx)(`dt`,{className:`text-[10px] text-stone-400`,children:`需求来源`}),(0,Z.jsx)(`dd`,{className:`truncate text-xs text-stone-700`,children:p===`stories`?ct?`用户故事 · ${ct.title}(${ut}/${lt.length} 条)`:`用户故事 · 未选择`:d?`需求文档 · ${d}`:`需求文档 · 未选择`})]}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`dt`,{className:`text-[10px] text-stone-400`,children:`引用知识库`}),(0,Z.jsx)(`dd`,{className:`truncate text-xs text-stone-700`,children:R.length?`${R.length} 个文档`:`未引用`})]}),(0,Z.jsxs)(`div`,{className:`col-span-2 grid min-w-0 grid-cols-2 gap-x-4 sm:col-span-3`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`dt`,{className:`text-[10px] text-stone-400`,children:`测试点`}),(0,Z.jsx)(`dd`,{className:`truncate text-xs text-stone-700`,children:ft.length?`${ft.length} 条`:`未选择`})]}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`dt`,{className:`text-[10px] text-stone-400`,children:`提示词`}),(0,Z.jsx)(`dd`,{className:`truncate text-xs text-stone-700`,children:Xe?`${Xe.replace(/\.md$/i,``)}(${Je})`:`未挂载`})]})]})]}),(0,Z.jsx)(`p`,{className:`mt-2.5 text-[10px] leading-4 text-stone-400`,children:`确认后在主输入框描述本次生成范围并发送;结果写入用例管理,后续修改仍走该工作台会话。`})]})]}),(0,Z.jsx)(zc,{mode:Ne,currentLabel:qe.label,templateFolder:qe.templateFolder,error:Fe??``,onClose:()=>{Pe(null),Ie(null)},onSubmit:nt,onDelete:rt}),(0,Z.jsx)(Ot,{open:pe,prompts:ot,value:Xe,force:!Xe,onClose:()=>me(!1),onMount:Qe,onCreate:et,target:`用例类型`,createHint:`会按用例生成的模板生成一份(逐条覆盖、边界 / 异常 / 优先级),之后可在「提示词管理」里改。`})]})}function Wc({open:e,onClose:t,initial:n,onConfirm:r}){let[i,a]=(0,K.useState)(!1),[o,s]=(0,K.useState)(``),[c,l]=(0,K.useState)(()=>Si()),[u,d]=(0,K.useState)(Si()[0]?.id??`case`),[f,p]=(0,K.useState)(null),[m,h]=(0,K.useState)(null),[g,_]=(0,K.useState)(null),v=c.find(e=>e.id===u)??c[0]??Ci(u);function y(e){let t=Si();l(t),d(n=>{let r=e??n;return t.some(e=>e.id===r)?r:t[0]?.id??n})}function b(e){let t=m===`add`;try{if(t){let t=Ti(e);y(t.id),M(`已新增提示词类型「${t.label}」`,`success`)}else Ei(u,e),y(u),M(`已重命名为「${e.trim()}」`,`success`);h(null),_(null)}catch(e){let n=e instanceof Error?e.message:String(e);_(n),M(`${t?`新增`:`保存`}提示词类型失败:${n}`,`error`)}}function x(){try{let e=v.label,t=Di(u);l(t),d(t[0]?.id??``),h(null),_(null),p(null),M(`已删除提示词类型「${e}」`,`success`)}catch(e){let t=e instanceof Error?e.message:String(e);_(t),M(`删除提示词类型失败:${t}`,`error`)}}(0,K.useEffect)(()=>{e&&(y(n?.kind),s(n?.titleHint??``),d(n?.kind??Si()[0]?.id??`case`),h(null),_(null),p(null),we(`prompts`).then(a))},[e,n]);function S(){p(null),i?(r({active:!0,titleHint:o.trim(),kind:u,confirmedAt:Date.now(),linkedPromptPath:n?.linkedPromptPath}),t()):p(`本地文档服务未就绪,无法写入提示词库`)}return(0,Z.jsxs)(ht,{open:e,onClose:t,title:`生成提示词 · 配置`,closeAriaLabel:`关闭生成提示词面板`,escDisabled:m!==null,footer:(0,Z.jsxs)(`footer`,{className:`shrink-0 p-4 border-t border-stone-100 flex items-center gap-2`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:t,className:`h-9 px-3 text-sm text-stone-600 rounded-lg hover:bg-stone-100`,children:`取消`}),(0,Z.jsx)(`button`,{type:`button`,disabled:!i,onClick:S,className:`flex-1 h-9 text-sm font-medium text-white bg-[#4176e6] rounded-lg hover:bg-[#3565c7] disabled:opacity-40`,children:`确认`})]}),children:[i?null:(0,Z.jsx)(`div`,{className:`rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-sm text-amber-900`,children:`本地文档服务未就绪,无法读写提示词库。`}),(0,Z.jsx)(`p`,{className:`text-xs text-stone-500 leading-5`,children:`按所选类型生成可复用提示词:确认后在主输入框描述编写要求并发送,质检通过后写入提示词库,可在「提示词管理」中查看与引用。`}),f?(0,Z.jsx)(`div`,{className:`text-sm text-red-700 bg-red-50 border border-red-200 rounded-lg px-3 py-2`,children:f}):null,(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`mb-1 flex items-center gap-2`,children:[(0,Z.jsx)(`div`,{className:`flex-1 text-xs font-medium text-stone-500`,children:`提示词类型`}),(0,Z.jsx)(`button`,{type:`button`,className:`inline-flex h-[23px] items-center rounded border border-stone-200 px-1.5 text-[11px] leading-none text-[#4176e6] transition-colors hover:border-[#4176e6]/40 hover:bg-[#edf3fe]`,onClick:()=>{h(`add`),_(null)},children:`新增`}),(0,Z.jsx)(`button`,{type:`button`,className:`inline-flex h-[23px] items-center rounded border border-stone-200 px-1.5 text-[11px] leading-none text-stone-600 transition-colors hover:border-stone-300 hover:bg-stone-50`,onClick:()=>{h(`edit`),_(null)},children:`编辑`}),(0,Z.jsx)(`button`,{type:`button`,className:`inline-flex h-[23px] items-center rounded border border-stone-200 px-1.5 text-[11px] leading-none text-red-600 transition-colors hover:border-red-300 hover:bg-red-50 disabled:opacity-40 disabled:hover:border-stone-200 disabled:hover:bg-transparent`,disabled:c.length<=1,onClick:()=>{h(`delete`),_(null)},children:`删除`})]}),(0,Z.jsx)(j,{options:c.map(e=>({value:e.id,label:e.label})),value:u,onChange:d,dimWhenOpen:!0}),(0,Z.jsx)(`p`,{className:`mt-1 text-[11px] text-stone-400 leading-4`,children:v.hint}),(0,Z.jsx)(`p`,{className:`mt-1 text-[11px] text-stone-400 leading-4`,children:`类型决定生成时给模型的写作侧重(例如用例提示词要求约束 JSON 与模板字段), 同时出现在这份提示词的配置标签里;不影响你在主输入框补充的具体要求。`})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`text-xs font-medium text-stone-500`,htmlFor:`pg-title`,children:`期望名称`}),(0,Z.jsx)(`input`,{id:`pg-title`,value:o,onChange:e=>s(e.target.value),placeholder:`如:接口测试用例提示词.md`,className:`mt-1 w-full h-9 px-3 text-sm rounded-lg border border-stone-200 focus:outline-none focus:ring-2 focus:ring-[#4176e6]/40`}),(0,Z.jsx)(`p`,{className:`mt-1.5 text-[11px] text-stone-400 leading-4`,children:`可填期望文件名;留空则由模型自拟。具体编写要求在主输入框描述。`})]}),(0,Z.jsx)(Rc,{mode:m,entityLabel:`提示词类型`,currentLabel:v.label,placeholder:`如:缺陷分析提示词`,error:g??``,onClose:()=>{h(null),_(null)},onSubmit:b,onDelete:x,hint:e=>(0,Z.jsxs)(Z.Fragment,{children:[`类型名称会写入这份提示词的配置标签:`,e||`名称`]}),deleteMessage:e=>(0,Z.jsxs)(Z.Fragment,{children:[`确定删除「`,e,`」?已生成的提示词与文档不会被删除,只是不能再选这个类型。`]})})]})}function Gc({open:e,onClose:t,initial:n,onConfirm:r}){let[i,a]=(0,K.useState)(!1),[o,s]=(0,K.useState)(``),[c,l]=(0,K.useState)(()=>Li()),[u,d]=(0,K.useState)(Li()[0]??`测试规范`),[f,p]=(0,K.useState)(null),[m,h]=(0,K.useState)(null),[g,_]=(0,K.useState)(null);function v(e){let t=Li();l(t),d(n=>{let r=e??n;return t.includes(r)?r:t[0]??n})}function y(e){let t=m===`add`;try{if(t){let t=zi(e);v(t),M(`已新增分类「${t}」`,`success`)}else{let t=Bi(u,e);v(t),M(`已重命名为「${t}」`,`success`)}h(null),_(null)}catch(e){let n=e instanceof Error?e.message:String(e);_(n),M(`${t?`新增`:`保存`}分类失败:${n}`,`error`)}}function b(){try{let e=u,t=Vi(u);l(t),d(t[0]??``),h(null),_(null),p(null),M(`已删除分类「${e}」`,`success`)}catch(e){let t=e instanceof Error?e.message:String(e);_(t),M(`删除分类失败:${t}`,`error`)}}(0,K.useEffect)(()=>{e&&(v(n?.category),s(n?.titleHint??``),d(n?.category??Li()[0]??`测试规范`),h(null),_(null),p(null),we(`knowledge`).then(a))},[e,n]);function x(){p(null),i?(r({active:!0,titleHint:o.trim(),category:u,confirmedAt:Date.now(),linkedKnowledgePath:n?.linkedKnowledgePath}),t()):p(`本地文档服务未就绪,无法写入知识库`)}return(0,Z.jsxs)(ht,{open:e,onClose:t,title:`生成知识库 · 配置`,closeAriaLabel:`关闭生成知识库面板`,escDisabled:m!==null,footer:(0,Z.jsxs)(`footer`,{className:`shrink-0 p-4 border-t border-stone-100 flex items-center gap-2`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:t,className:`h-9 px-3 text-sm text-stone-600 rounded-lg hover:bg-stone-100`,children:`取消`}),(0,Z.jsx)(`button`,{type:`button`,disabled:!i,onClick:x,className:`flex-1 h-9 text-sm font-medium text-white bg-[#4176e6] rounded-lg hover:bg-[#3565c7] disabled:opacity-40`,children:`确认`})]}),children:[i?null:(0,Z.jsx)(`div`,{className:`rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-sm text-amber-900`,children:`本地文档服务未就绪,无法读写知识库。`}),(0,Z.jsx)(`p`,{className:`text-xs text-stone-500 leading-5`,children:`按所选分类沉淀测试规范、方法论或环境约定:确认后在主输入框粘贴/描述素材并发送,质检通过后写入知识库,可在「知识库管理」中查看与 @ 引用。`}),f?(0,Z.jsx)(`div`,{className:`text-sm text-red-700 bg-red-50 border border-red-200 rounded-lg px-3 py-2`,children:f}):null,(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`mb-1 flex items-center gap-2`,children:[(0,Z.jsx)(`div`,{className:`flex-1 text-xs font-medium text-stone-500`,children:`分类`}),(0,Z.jsx)(`button`,{type:`button`,className:`inline-flex h-[23px] items-center rounded border border-stone-200 px-1.5 text-[11px] leading-none text-[#4176e6] transition-colors hover:border-[#4176e6]/40 hover:bg-[#edf3fe]`,onClick:()=>{h(`add`),_(null)},children:`新增`}),(0,Z.jsx)(`button`,{type:`button`,className:`inline-flex h-[23px] items-center rounded border border-stone-200 px-1.5 text-[11px] leading-none text-stone-600 transition-colors hover:border-stone-300 hover:bg-stone-50`,onClick:()=>{h(`edit`),_(null)},children:`编辑`}),(0,Z.jsx)(`button`,{type:`button`,className:`inline-flex h-[23px] items-center rounded border border-stone-200 px-1.5 text-[11px] leading-none text-red-600 transition-colors hover:border-red-300 hover:bg-red-50 disabled:opacity-40 disabled:hover:border-stone-200 disabled:hover:bg-transparent`,disabled:c.length<=1,onClick:()=>{h(`delete`),_(null)},children:`删除`})]}),(0,Z.jsx)(j,{options:c.map(e=>({value:e,label:e})),value:u,onChange:d,dimWhenOpen:!0}),(0,Z.jsx)(`p`,{className:`mt-1 text-[11px] text-stone-400 leading-4`,children:`分类决定两件事:生成时告诉模型按哪类知识写(规范 / 方法论 / 环境约定侧重不同), 入库时写进文档 frontmatter 的 category,知识库管理里就按它归类展示。`})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`text-xs font-medium text-stone-500`,htmlFor:`kg-title`,children:`期望名称`}),(0,Z.jsx)(`input`,{id:`kg-title`,value:o,onChange:e=>s(e.target.value),placeholder:`如:接口自动化环境约定.md`,className:`mt-1 w-full h-9 px-3 text-sm rounded-lg border border-stone-200 focus:outline-none focus:ring-2 focus:ring-[#4176e6]/40`}),(0,Z.jsx)(`p`,{className:`mt-1.5 text-[11px] text-stone-400 leading-4`,children:`可填期望文件名;留空则由模型自拟。素材与编写要求在主输入框描述。`})]}),(0,Z.jsx)(Rc,{mode:m,entityLabel:`知识库分类`,currentLabel:u,placeholder:`如:安全基线`,error:g??``,onClose:()=>{h(null),_(null)},onSubmit:y,onDelete:b,hint:()=>(0,Z.jsx)(Z.Fragment,{children:`分类写入文档 frontmatter,文件平铺存放于 知识库管理/;改名不会自动迁移已有文件。`}),deleteMessage:e=>(0,Z.jsxs)(Z.Fragment,{children:[`确定删除「`,e,`」?已入库的知识文档不会被删除,但该分类将不能再用于生成。`]})})]})}function Kc({task:e,onClose:t,onSave:n,onRemove:r}){let[i,a]=(0,K.useState)(``),o=!!e;(0,K.useEffect)(()=>{a(e?.body??``)},[e]);let s=!!e&&i.trim()!==e?.body.trim();return(0,Z.jsxs)(C,{open:o,onClose:t,transition:!0,className:`relative z-110`,children:[(0,Z.jsx)(w,{transition:!0,className:`tw-dialog-backdrop-anim fixed inset-0 bg-black/30`,"aria-hidden":`true`}),(0,Z.jsx)(`div`,{className:`fixed inset-0 flex items-center justify-center p-4`,children:(0,Z.jsxs)(x,{transition:!0,className:`tw-dialog-panel-anim relative flex max-h-[85vh] w-full max-w-2xl flex-col rounded-xl border border-stone-200 bg-white p-5 shadow-xl`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:t,className:`absolute top-3.5 right-3.5 flex h-7 w-7 items-center justify-center rounded-md text-stone-400 transition-colors hover:bg-stone-100 hover:text-stone-700`,"aria-label":`关闭`,children:`✕`}),(0,Z.jsx)(S,{className:`pr-8 text-base font-semibold text-stone-900`,children:e?.label||`任务要求`}),(0,Z.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-2 gap-y-0.5 text-[11px] text-stone-400`,children:[(0,Z.jsx)(`span`,{children:`发送时这段要求会随消息一起带给模型`}),e?.detail?(0,Z.jsxs)(`span`,{className:`truncate`,children:[`· `,e.detail]}):null]}),(0,Z.jsx)(`textarea`,{value:i,onChange:e=>a(e.target.value),spellCheck:!1,className:`mt-3 min-h-[240px] flex-1 resize-none overflow-y-auto rounded-lg border border-stone-200 bg-stone-50/60 px-3 py-2.5 font-mono text-[12.5px] leading-relaxed text-stone-700 outline-none focus:border-[#4176e6]/40 focus:bg-white`}),(0,Z.jsxs)(`div`,{className:`mt-4 flex items-center justify-between gap-2`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:r,className:`h-8 rounded-lg border border-stone-200 px-3 text-sm text-stone-500 transition-colors hover:border-red-300 hover:bg-red-50 hover:text-red-600`,children:`移除`}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:t,className:`h-8 rounded-lg border border-stone-200 px-3 text-sm text-stone-600 transition-colors hover:bg-stone-100`,children:`取消`}),(0,Z.jsx)(`button`,{type:`button`,disabled:!i.trim(),onClick:()=>n(i.trim()),className:`h-8 rounded-lg bg-[#4176e6] px-3.5 text-sm text-white transition-colors hover:bg-[#3566d0] disabled:cursor-not-allowed disabled:bg-stone-300`,children:s?`保存修改`:`完成`})]})]})]})})]})}var qc={user:`用户档案`,memory:`长期记忆`,key:`项目关键记忆`,project:`项目日志`};function Jc(e){return e?e.replace(/\\/g,`/`).replace(/^\/Users\/[^/]+/,`~`):``}var Yc={project:{title:`项目日志`,fileHint:`MEMORY.md`,desc:`项目进展流水账,按需查阅,默认不注入上下文。`,curated:!1},key:{title:`项目关键记忆`,fileHint:`KEY.md`,desc:`项目关键约定与事实;写入需经待确认记忆建议采纳后注入。`,curated:!0},memory:{title:`长期记忆`,fileHint:`MEMORY.md`,desc:`全局环境与跨项目事实,注入所有会话;写入需审查建议并经确认。`,curated:!0}},Xc=[{id:`guide`,label:`指南`},{id:`suggestions`,label:`待确认记忆建议`},{id:`project`,label:`项目日志`},{id:`key`,label:`项目关键记忆 KEY.md`},{id:`memory`,label:`长期记忆 MEMORY.md`},{id:`agents`,label:`全局规则 AGENTS.md`},{id:`archive`,label:`归档`},{id:`settings`,label:`设置`}];function Zc({live:e,pluginOn:t,workspacePath:n=``}){let[r,i]=(0,K.useState)(`suggestions`),[a,o]=(0,K.useState)(null),[s,c]=(0,K.useState)({}),[l,u]=(0,K.useState)(``),[d,f]=(0,K.useState)([]),[p,m]=(0,K.useState)([]),[h,g]=(0,K.useState)(`memory`),[_,v]=(0,K.useState)(null),[y,b]=(0,K.useState)([]),[x,S]=(0,K.useState)(null),[C,w]=(0,K.useState)(``),[T,E]=(0,K.useState)(!1),[D,O]=(0,K.useState)(null),[k,ee]=(0,K.useState)(null),[te,j]=(0,K.useState)(null),M=n.trim(),ne=(0,K.useCallback)(async()=>{if(!e)o(null),c({}),f([]),b([]);else{S(null);try{let[e,t,n,i,a]=await Promise.all([nr(),rr(M,`all`),dr(),hr(),Vt().catch(()=>null)]);o(e),c(t.tracks),u(t.projectId||``),f(n),v(i),b(a?.files?.length?a.files:a?.text?[{path:`AGENTS.md`,name:`AGENTS.md`}]:[]),r===`archive`&&m(await sr(h,M))}catch(e){S(e instanceof Error?e.message:String(e))}}},[e,M,r,h]);if((0,K.useEffect)(()=>{ne()},[ne]),!t)return(0,Z.jsxs)(`div`,{className:`h-full flex flex-col items-center justify-center text-center px-6`,children:[(0,Z.jsx)(`p`,{className:`text-sm text-stone-600`,children:`会话记忆未启用`}),(0,Z.jsx)(`p`,{className:`mt-1 text-xs text-stone-400`,children:`在「我的插件」中打开「会话记忆」后,可在此管理记忆轨与待确认记忆建议`})]});if(!e)return(0,Z.jsxs)(`div`,{className:`h-full flex flex-col items-center justify-center text-center px-6`,children:[(0,Z.jsx)(`p`,{className:`text-sm text-stone-600`,children:`会话记忆中间件未就绪`}),(0,Z.jsx)(`p`,{className:`mt-1 text-xs text-stone-400`,children:`本地记忆服务未就绪`})]});let re=r===`memory`||r===`key`,ie=r===`memory`||r===`key`||r===`project`,ae=ie?s[r]?.entries??[]:[],N=ie?s[r]?.path:null,P=a?.path||`.lantern/local/memories`;async function oe(e){E(!0);try{await or(e),await ne()}catch(e){S(e instanceof Error?e.message:String(e))}finally{E(!1)}}async function se(e){E(!0);try{await gr(e),await ne()}catch(e){S(e instanceof Error?e.message:String(e))}finally{E(!1)}}function ce(e){re&&ee(e)}async function le(){if(k==null||!re)return;let e=k;ee(null),E(!0);try{await G(r,e,M),await ne()}catch(e){S(e instanceof Error?e.message:String(e))}finally{E(!1)}}async function ue(){if(te==null)return;let e=te;j(null),E(!0);try{await ur(h,e,M),await ne()}catch(e){S(e instanceof Error?e.message:String(e))}finally{E(!1)}}function F(e){O(e)}async function de(){if(D==null)return;let e=D;O(null),E(!0);try{await pr(r,e,M),await ne()}catch(e){S(e instanceof Error?e.message:String(e))}finally{E(!1)}}async function fe(){if(re&&C.trim()){E(!0);try{await cr(r,C.trim(),M),w(``),await ne()}catch(e){S(e instanceof Error?e.message:String(e))}finally{E(!1)}}}async function I(e){E(!0);try{let t=await tr(e);v(t)}catch(e){S(e instanceof Error?e.message:String(e))}finally{E(!1)}}function L(e){let t=Yc[e],n=e===`key`?`KEY.md`:t.fileHint,r=e===`key`?`项目关键记忆 ${n}`:e===`memory`?`长期记忆 ${n}`:t.title,i=Jc(N)||`${Jc(P)}/…/${n}`;return(0,Z.jsxs)(`div`,{className:`mb-3 space-y-1.5`,children:[(0,Z.jsxs)(`div`,{className:`flex items-start gap-2 flex-wrap min-w-0`,children:[(0,Z.jsx)(`h3`,{className:`text-sm font-semibold text-stone-800`,children:r}),t.curated?null:(0,Z.jsx)(`span`,{className:`px-1.5 py-0.5 text-[10px] rounded bg-stone-100 text-stone-500 border border-stone-200`,children:`只读追加`}),(0,Z.jsxs)(`span`,{className:`text-[11px] text-stone-400 tabular-nums`,children:[ae.length,` 条`]}),(0,Z.jsx)(`span`,{className:`max-w-full break-all whitespace-normal text-[11px] text-[#4176e6] bg-[#edf3fe] border border-[#4176e6]/20 rounded-lg px-2 py-0.5 font-mono leading-4`,"data-hint":N||i,children:i})]}),(0,Z.jsx)(`p`,{className:`text-xs text-stone-500 leading-5 break-words`,children:t.desc}),M?(0,Z.jsxs)(`p`,{className:`text-[11px] text-stone-400 break-all`,children:[`当前会话工作目录:`,(0,Z.jsx)(`span`,{className:`font-mono`,children:M}),l?(0,Z.jsxs)(Z.Fragment,{children:[` · `,`项目 id `,(0,Z.jsx)(`span`,{className:`font-mono`,children:l.slice(0,12)})]}):null]}):null]})}return(0,Z.jsxs)(`div`,{className:`h-full flex flex-col min-h-0`,children:[(0,Z.jsxs)(`div`,{className:`shrink-0 flex flex-wrap items-center gap-2 px-4 py-2 border-b border-stone-200/80`,children:[Xc.map(e=>(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>i(e.id),className:`h-7 px-2.5 text-xs rounded-md whitespace-normal text-left leading-tight ${r===e.id?`bg-stone-900 text-white`:`text-stone-600 hover:bg-stone-100`}`,children:[e.label,e.id===`suggestions`&&d.length>0?(0,Z.jsxs)(`span`,{className:`ml-1 tabular-nums`,children:[`(`,d.length,`)`]}):null]},e.id)),(0,Z.jsxs)(`span`,{className:`text-[11px] text-stone-400 tabular-nums`,children:[a?.entryCount??0,` 条 · 待确认 `,a?.suggestionCount??d.length]})]}),x?(0,Z.jsx)(`div`,{className:`mx-4 mt-3 px-3 py-2 text-sm text-red-700 bg-red-50 border border-red-200 rounded-lg`,children:x}):null,(0,Z.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4`,children:[r===`guide`?(0,Z.jsxs)(`div`,{className:`space-y-3 max-w-2xl`,children:[(0,Z.jsxs)(`section`,{className:`rounded-xl border border-stone-200 bg-white p-4`,children:[(0,Z.jsx)(`h3`,{className:`text-sm font-semibold text-stone-800`,children:`确认制:为什么必须你点头`}),(0,Z.jsx)(`p`,{className:`mt-1.5 text-xs text-stone-500 leading-5`,children:`记忆会改变后续对话行为。长期记忆 / 项目关键记忆经「待确认记忆建议」采纳后才写入并注入;项目日志可直写但不注入。`})]}),(0,Z.jsxs)(`section`,{className:`rounded-xl border border-stone-200 bg-white p-4`,children:[(0,Z.jsx)(`h3`,{className:`text-sm font-semibold text-stone-800`,children:`待确认记忆建议:AI 只提议,你拍板`}),(0,Z.jsx)(`p`,{className:`mt-1.5 text-xs text-stone-500 leading-5`,children:`后台或对话中产出的记忆建议进入独立队列。采纳可写入对应轨;拒绝则丢弃。`}),(0,Z.jsxs)(`ul`,{className:`mt-2 space-y-1.5 text-xs text-stone-600`,children:[(0,Z.jsx)(`li`,{className:`rounded-lg bg-stone-50 border border-stone-100 px-2.5 py-2 break-words`,children:`采纳 → 长期记忆 MEMORY.md / 项目关键记忆 KEY.md`}),(0,Z.jsx)(`li`,{className:`rounded-lg bg-stone-50 border border-stone-100 px-2.5 py-2`,children:`拒绝 → 丢弃,不落盘`})]})]}),(0,Z.jsxs)(`section`,{className:`rounded-xl border border-stone-200 bg-white p-4`,children:[(0,Z.jsx)(`h3`,{className:`text-sm font-semibold text-stone-800`,children:`各轨文件(对齐 dsh)`}),(0,Z.jsxs)(`ul`,{className:`mt-2 space-y-1.5 text-xs text-stone-600`,children:[(0,Z.jsx)(`li`,{className:`rounded-lg bg-stone-50 border border-stone-100 px-2.5 py-2`,children:`项目日志 · 项目目录 MEMORY.md(不注入)`}),(0,Z.jsx)(`li`,{className:`rounded-lg bg-stone-50 border border-stone-100 px-2.5 py-2`,children:`项目关键记忆 KEY.md(注入,需确认)`}),(0,Z.jsx)(`li`,{className:`rounded-lg bg-stone-50 border border-stone-100 px-2.5 py-2`,children:`长期记忆 MEMORY.md(注入,需确认)`}),(0,Z.jsx)(`li`,{className:`rounded-lg bg-stone-50 border border-stone-100 px-2.5 py-2`,children:`全局规则:展示工作区 AGENTS.md 等规则文件`})]})]}),(0,Z.jsxs)(`section`,{className:`rounded-xl border border-stone-200 bg-white p-4`,children:[(0,Z.jsx)(`h3`,{className:`text-sm font-semibold text-stone-800`,children:`编辑与维护`}),(0,Z.jsx)(`p`,{className:`mt-1.5 text-xs text-stone-500 leading-5`,children:`可在本 Tab 浏览条目、手动添加(注入轨)、归档或删除。文件为 § 分隔结构化记忆,用外部编辑器打开时请谨慎修改。`}),(0,Z.jsxs)(`p`,{className:`mt-2 text-[11px] text-amber-700/90`,children:[`存储目录:`,(0,Z.jsx)(`code`,{className:`font-mono`,children:P})]})]})]}):null,r===`suggestions`?(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h3`,{className:`text-sm font-semibold text-stone-800`,children:`待确认记忆建议`}),(0,Z.jsx)(`p`,{className:`mt-1 text-xs text-stone-500 leading-5`,children:`后台审查或对话沉淀产出的记忆建议:采纳后写入记忆文件并注入;拒绝则丢弃。`})]}),d.length===0?(0,Z.jsx)(`div`,{className:`rounded-xl border border-dashed border-stone-200 bg-stone-50/50 px-4 py-16 text-center text-sm text-stone-400`,children:`没有待确认的建议。`}):(0,Z.jsx)(`ul`,{className:`space-y-3`,children:d.map(e=>(0,Z.jsxs)(`li`,{className:`rounded-lg border border-amber-200/80 bg-amber-50/30 p-3`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] text-stone-400 mb-1 flex-wrap`,children:[(0,Z.jsx)(`span`,{className:`px-1.5 py-0.5 rounded bg-amber-100 text-amber-900 border border-amber-200 font-medium`,children:`待确认记忆建议`}),(0,Z.jsx)(`span`,{className:`px-1.5 py-0.5 rounded bg-white text-stone-600 border border-stone-200`,children:qc[e.target]??e.target}),(0,Z.jsx)(`span`,{children:e.time}),e.hits&&e.hits>1?(0,Z.jsxs)(`span`,{children:[`×`,e.hits]}):null]}),(0,Z.jsx)(`p`,{className:`text-sm text-stone-800 whitespace-pre-wrap`,children:e.content}),e.reason?(0,Z.jsxs)(`p`,{className:`mt-1 text-xs text-stone-500`,children:[`原因:`,e.reason]}):null,(0,Z.jsxs)(`div`,{className:`mt-2 flex gap-2`,children:[(0,Z.jsx)(`button`,{type:`button`,disabled:T,onClick:()=>void oe(e.id),className:`h-7 px-2.5 text-xs text-white bg-emerald-600 rounded-md hover:bg-emerald-700 disabled:opacity-40`,children:`采纳`}),(0,Z.jsx)(`button`,{type:`button`,disabled:T,onClick:()=>void se(e.id),className:`h-7 px-2.5 text-xs text-stone-600 border border-stone-200 rounded-md hover:bg-stone-50 disabled:opacity-40`,children:`拒绝`})]})]},e.id))})]}):null,ie?(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[L(r),re?(0,Z.jsxs)(`div`,{className:`rounded-xl border border-stone-200 bg-white p-3 space-y-2`,children:[(0,Z.jsx)(`textarea`,{value:C,onChange:e=>w(e.target.value),placeholder:r===`key`?`输入一条项目关键约定,例如:本仓库包管理器用 pnpm…`:`输入一条想长期记住的全局事实/惯例/环境…`,rows:3,className:`w-full text-sm rounded-lg border border-stone-200 px-3 py-2 focus:outline-none focus:border-[#4176e6] resize-y`}),(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Z.jsx)(`p`,{className:`text-[11px] text-stone-400`,children:`手动写入会直接落盘;重要偏好更推荐走「待确认记忆建议」。`}),(0,Z.jsx)(`button`,{type:`button`,disabled:T||!C.trim(),onClick:()=>void fe(),className:`shrink-0 h-8 px-3 text-xs text-white bg-[#4176e6] rounded-lg disabled:opacity-40`,children:`保存`})]})]}):(0,Z.jsx)(`p`,{className:`text-xs text-stone-400`,children:`本轨由对话中 memory_append 自动追加,一般不注入上下文。`}),ae.length===0?(0,Z.jsx)(`div`,{className:`rounded-xl border border-dashed border-stone-200 bg-stone-50/50 px-4 py-12 text-center text-sm text-stone-400`,children:`(文件不存在或为空)`}):(0,Z.jsx)(`ul`,{className:`space-y-2`,children:ae.map(e=>(0,Z.jsxs)(`li`,{className:`rounded-lg border border-stone-200 bg-white px-3 py-2.5 flex gap-2`,children:[(0,Z.jsx)(`p`,{className:`flex-1 text-sm text-stone-800 whitespace-pre-wrap`,children:e.text}),(0,Z.jsxs)(`div`,{className:`shrink-0 self-start flex flex-col gap-0.5`,children:[re?(0,Z.jsx)(`button`,{type:`button`,disabled:T,onClick:()=>void ce(e.index),className:`h-7 px-2 text-[11px] text-stone-500 hover:bg-stone-50 rounded-md`,children:`归档`}):null,(0,Z.jsx)(`button`,{type:`button`,disabled:T,onClick:()=>void F(e.index),className:`h-7 px-2 text-[11px] text-red-600 hover:bg-red-50 rounded-md`,children:`删除`})]})]},`${r}-${e.index}`))})]}):null,r===`agents`?(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[(0,Z.jsx)(`h3`,{className:`text-sm font-semibold text-stone-800`,children:`全局规则`}),(0,Z.jsx)(`p`,{className:`text-xs text-stone-500 leading-5`,children:`工作区规则文件(AGENTS.md 等),随系统提示注入。`}),y.length===0?(0,Z.jsx)(`div`,{className:`rounded-xl border border-dashed border-stone-200 bg-stone-50/50 px-4 py-12 text-center text-sm text-stone-400`,children:`(未找到规则文件)`}):(0,Z.jsx)(`ul`,{className:`space-y-2 w-full`,children:y.map(e=>{let t=Jc(e.abs)||Jc(e.path)||e.label||e.path||e.name;return(0,Z.jsx)(`li`,{className:`w-full`,children:(0,Z.jsxs)(`div`,{className:`w-full flex items-center gap-4 rounded-xl border border-stone-200 bg-white px-4 py-3.5`,children:[(0,Z.jsx)(`span`,{className:`w-12 h-12 rounded-xl bg-[#edf3fe] text-[#4176e6] flex items-center justify-center text-[11px] font-semibold shrink-0`,children:(e.name.split(`.`).pop()||`MD`).toUpperCase()}),(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`span`,{className:`block text-[15px] font-medium text-stone-800 break-all`,children:e.name||`AGENTS.md`}),(0,Z.jsx)(`span`,{className:`block text-xs text-stone-400 break-all font-mono mt-1`,children:t})]}),(0,Z.jsx)(`button`,{type:`button`,disabled:T,onClick:()=>{S(null),E(!0),Nt(e.path||e.name||`AGENTS.md`,Re(),{abs:e.abs}).catch(e=>S(e instanceof Error?e.message:String(e))).finally(()=>E(!1))},className:`shrink-0 h-9 px-4 text-xs text-[#4176e6] border border-[#4176e6]/30 rounded-lg hover:bg-[#f5f8ff] disabled:opacity-40`,children:`打开文件`})]})},e.abs||e.path)})})]}):null,r===`archive`?(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[(0,Z.jsx)(`div`,{className:`flex gap-2`,children:[`user`,`memory`,`key`].map(e=>(0,Z.jsx)(`button`,{type:`button`,onClick:()=>{g(e)},className:`h-7 px-2.5 text-xs rounded-md ${h===e?`bg-stone-800 text-white`:`border border-stone-200`}`,children:qc[e]??e},e))}),p.length===0?(0,Z.jsx)(`p`,{className:`text-sm text-stone-400 text-center py-10`,children:`暂无归档`}):(0,Z.jsx)(`ul`,{className:`space-y-2`,children:p.map(e=>(0,Z.jsxs)(`li`,{className:`rounded-lg border border-stone-200 bg-white px-3 py-2.5 flex gap-2`,children:[(0,Z.jsx)(`p`,{className:`flex-1 text-sm text-stone-800 whitespace-pre-wrap`,children:e.text}),(0,Z.jsxs)(`div`,{className:`shrink-0 self-start flex flex-col gap-0.5`,children:[(0,Z.jsx)(`button`,{type:`button`,disabled:T,onClick:()=>void(async()=>{E(!0);try{await ir(h,e.index,M),await ne()}catch(e){S(e instanceof Error?e.message:String(e))}finally{E(!1)}})(),className:`h-7 px-2 text-[11px] text-emerald-700 hover:bg-emerald-50 rounded-md`,children:`转正`}),(0,Z.jsx)(`button`,{type:`button`,disabled:T,onClick:()=>j(e.index),className:`h-7 px-2 text-[11px] text-red-600 hover:bg-red-50 rounded-md`,children:`删除`})]})]},`a-${e.index}`))})]}):null,r===`settings`&&_?(0,Z.jsxs)(`div`,{className:`space-y-4 max-w-md`,children:[(0,Z.jsxs)(`label`,{className:`flex items-center justify-between gap-3 text-sm text-stone-700`,children:[(0,Z.jsx)(`span`,{children:`每回合注入 USER / MEMORY / KEY`}),(0,Z.jsx)(`input`,{type:`checkbox`,checked:_.injectMemory,onChange:e=>void I({injectMemory:e.target.checked})})]}),(0,Z.jsxs)(`label`,{className:`flex items-center justify-between gap-3 text-sm text-stone-700`,children:[(0,Z.jsx)(`span`,{children:`收尾提示写 project`}),(0,Z.jsx)(`input`,{type:`checkbox`,checked:_.perTurnProjectWrites,onChange:e=>void I({perTurnProjectWrites:e.target.checked})})]}),(0,Z.jsxs)(`label`,{className:`flex items-center justify-between gap-3 text-sm text-stone-700`,children:[(0,Z.jsx)(`span`,{children:`重要事实用 suggest(KEY)`}),(0,Z.jsx)(`input`,{type:`checkbox`,checked:_.perTurnKeyWrites,onChange:e=>void I({perTurnKeyWrites:e.target.checked})})]}),(0,Z.jsxs)(`p`,{className:`text-xs text-stone-400 leading-5 break-all`,children:[`存储目录:`,(0,Z.jsx)(`code`,{className:`font-mono`,children:a?.path??`.lantern/local/memories`}),`。memory/key 经待确认记忆建议后注入;project 不注入。`]})]}):null]}),(0,Z.jsx)(A,{open:D!=null,title:`删除记忆`,message:`永久删除该条目?此操作不可恢复。`,confirmLabel:`删除`,cancelLabel:`取消`,danger:!0,onClose:()=>O(null),onConfirm:()=>void de()}),(0,Z.jsx)(A,{open:k!=null,title:`归档记忆`,message:`归档该条目?归档后不再注入上下文。`,confirmLabel:`归档`,cancelLabel:`取消`,onClose:()=>ee(null),onConfirm:()=>void le()}),(0,Z.jsx)(A,{open:te!=null,title:`删除归档`,message:`永久删除该归档?此操作不可恢复。`,confirmLabel:`删除`,cancelLabel:`取消`,danger:!0,onClose:()=>j(null),onConfirm:()=>void ue()})]})}var Qc=`/`,$c=[{id:`all`,label:`全部待办`},{id:`open`,label:`未完成`},{id:`done`,label:`已完成`}],el={urgent_important:`bg-red-500`,important:`bg-amber-500`,urgent:`bg-orange-500`,normal:`bg-stone-300`},tl={urgent_important:`text-red-600`,important:`text-amber-600`,urgent:`text-orange-600`,normal:`text-stone-500`};function nl(){let e=new Date;return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`}function rl(e){let t=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e);return t?`${t[1]}/${t[2]}/${t[3]}`:``}function Q(e,t){let n=rl(e.dueDate),r=e.status===`done`||e.status===`cancelled`,i=gn(e,t),a=``,o=`text-stone-500`;return r?a=Sn[e.status]:i===null?(a=`未设置截止`,o=`text-stone-400`):i<0?(a=`逾期 ${Math.abs(i)} 天`,o=`text-red-600`):i===0?(a=`今天截止`,o=`text-[#4176e6]`):a=`剩余 ${i} 天`,{due:n,remain:a,tone:r?`text-stone-400`:o}}function il(e){return[...e].filter(e=>e.status===`done`||e.status===`cancelled`).sort((e,t)=>e.updatedAt<t.updatedAt?1:-1).slice(0,30)}function al(e,t,n){if(t===`done`)return[{key:`done`,label:`已完成 / 已取消`,items:il(e)}];let r=e.filter(e=>{let t=mn(e,n);return t!==`done`&&t!==`cancelled`}),i=[],a=[],o=[],s=[];for(let e of r){let t=gn(e,n);t===null?s.push(e):t<0?i.push(e):t===0?a.push(e):o.push(e)}let c=[{key:`overdue`,label:`已逾期`,items:i,tone:`text-red-600`},{key:`today`,label:`今天截止`,items:a,tone:`text-[#4176e6]`},{key:`later`,label:`接下来`,items:o},{key:`undated`,label:`没有截止日期`,items:s}];return t===`all`&&c.push({key:`done`,label:`已完成 / 已取消`,items:il(e)}),c.filter(e=>e.items.length>0)}function ol(e){let[t,n]=(0,K.useState)(null),[r,i]=(0,K.useState)(null),[a,o]=(0,K.useState)(`all`),[s,c]=(0,K.useState)({}),l=(0,K.useCallback)(async()=>{try{let e=await hn();n(e),i(null)}catch(e){i(e instanceof Error?e.message:String(e))}},[]);(0,K.useEffect)(()=>{l();let e=window.setInterval(()=>void l(),15e3);return()=>window.clearInterval(e)},[l]);let u=nl(),d=(0,K.useMemo)(()=>t?al(t,a,u):[],[t,a,u]),f=(0,K.useMemo)(()=>{let e=t??[],n=0,r=0,i=0;for(let t of e){let e=mn(t,u);if(e===`done`||e===`cancelled`)continue;i+=1;let a=gn(t,u);a!==null&&a<0?n+=1:a===0&&(r+=1)}return{overdue:n,dueToday:r,open:i}},[t,u]);async function p(e){if(s[e.id])return;let t=e.status===`done`?`pending`:`done`;c(t=>({...t,[e.id]:!0})),n(n=>n&&n.map(n=>n.id===e.id?{...n,status:t}:n));try{await vn(e.id,{status:t}),i(null)}catch(t){n(t=>t&&t.map(t=>t.id===e.id?{...t,status:e.status}:t)),i(t instanceof Error?t.message:String(t))}finally{c(t=>{let n={...t};return delete n[e.id],n})}}return e.live===!1?(0,Z.jsxs)(`div`,{className:`h-full flex flex-col items-center justify-center text-center px-6`,children:[(0,Z.jsx)(`p`,{className:`text-sm text-stone-600`,children:`待办事项需要本地服务`}),(0,Z.jsx)(`p`,{className:`mt-1 text-xs text-stone-400`,children:`当前未就绪(仅 npm run dev / 本地一体服务可用)`})]}):(0,Z.jsxs)(`div`,{className:`h-full flex flex-col min-h-0`,children:[(0,Z.jsxs)(`div`,{className:`shrink-0 flex flex-wrap items-center gap-2 px-4 py-2 border-b border-stone-200/80`,children:[$c.map(e=>(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>o(e.id),"aria-pressed":a===e.id,className:`h-7 px-2.5 text-xs rounded-md ${a===e.id?`bg-stone-900 text-white`:`text-stone-600 hover:bg-stone-100`}`,children:[e.label,e.id===`all`&&f.dueToday+f.overdue>0?(0,Z.jsx)(`span`,{className:`ml-1 tabular-nums`,children:f.dueToday+f.overdue}):null]},e.id)),(0,Z.jsxs)(`span`,{className:`ml-auto text-[11px] text-stone-400 tabular-nums`,children:[`未完成 `,f.open,f.overdue?` · 逾期 ${f.overdue}`:``]}),(0,Z.jsx)(`a`,{href:`${Qc}todos/`,className:`text-[11px] text-[#4176e6] hover:underline shrink-0`,children:`打开待办页 →`})]}),r?(0,Z.jsx)(`div`,{className:`mx-4 mt-3 px-3 py-2 text-sm text-red-700 bg-red-50 border border-red-200 rounded-lg`,children:r}):null,(0,Z.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-4 py-3`,children:t===null?(0,Z.jsx)(`div`,{className:`h-full flex items-center justify-center`,children:(0,Z.jsx)(`span`,{className:`tw-lib-spin`,"aria-hidden":`true`})}):d.length===0?(0,Z.jsxs)(`div`,{className:`h-full flex flex-col items-center justify-center text-center px-6`,children:[(0,Z.jsx)(`p`,{className:`text-sm text-stone-500`,children:a===`all`?`当前空间还没有待办`:a===`done`?`还没有已完成的待办`:`当前没有未完成的待办`}),(0,Z.jsx)(`a`,{href:`${Qc}todos/`,className:`mt-2 text-xs text-[#4176e6] hover:underline`,children:`去待办页新增 →`})]}):(0,Z.jsx)(`div`,{className:`space-y-4 max-w-3xl`,children:d.map(e=>(0,Z.jsxs)(`section`,{children:[(0,Z.jsxs)(`h3`,{className:`mb-1.5 flex items-center gap-1.5 px-1 text-[11px] font-medium ${e.tone??`text-stone-500`}`,children:[e.label,(0,Z.jsx)(`span`,{className:`text-stone-400 tabular-nums`,children:e.items.length})]}),(0,Z.jsx)(`ul`,{className:`list-none m-0 p-0 space-y-1`,children:e.items.map(e=>{let t=e.status===`done`||e.status===`cancelled`,n=Q(e,u);return(0,Z.jsxs)(`li`,{className:`group flex items-start gap-2 rounded-lg border border-stone-200 bg-white px-2.5 py-2 hover:border-stone-300`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:()=>void p(e),"aria-label":t?`恢复 ${e.title}`:`完成 ${e.title}`,"aria-pressed":t,className:`mt-0.5 grid h-4 w-4 shrink-0 place-items-center rounded-full border transition-colors ${t?`border-[#4176e6] bg-[#4176e6] text-white`:`border-stone-300 text-transparent hover:border-[#4176e6]`}`,children:(0,Z.jsx)(`svg`,{viewBox:`0 0 20 20`,width:`10`,height:`10`,fill:`none`,stroke:`currentColor`,strokeWidth:`3`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:(0,Z.jsx)(`path`,{d:`m4 10 4 4 8-9`})})}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[13px] leading-5 ${t?`text-stone-400 line-through`:`text-stone-800`}`,children:e.title}),t?(0,Z.jsx)(`span`,{className:`shrink-0 text-[11px] text-stone-400`,children:Sn[e.status]}):e.priority?(0,Z.jsxs)(`span`,{className:`flex shrink-0 items-center gap-1 text-[11px] ${tl[e.priority]??`text-stone-400`}`,children:[(0,Z.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full ${el[e.priority]??`bg-stone-300`}`}),Mn[e.priority]]}):null]}),(0,Z.jsxs)(`div`,{className:`mt-0.5 flex min-w-0 flex-wrap items-center gap-x-1.5 gap-y-0.5 text-[11px] leading-4`,children:[(0,Z.jsx)(`span`,{className:`shrink-0 text-stone-400 tabular-nums`,children:n.due?`截止 ${n.due}`:`无截止日期`}),(0,Z.jsx)(`span`,{className:`shrink-0 text-stone-300`,children:`·`}),(0,Z.jsx)(`span`,{className:`shrink-0 tabular-nums ${n.tone}`,children:n.remain}),e.linkedTask?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`span`,{className:`shrink-0 text-stone-300`,children:`·`}),(0,Z.jsxs)(`span`,{className:`min-w-0 truncate ${t?`text-stone-400`:`text-stone-500`}`,children:[`任务 `,e.linkedTask]})]}):null]})]})]},e.id)})})]},e.key))})})]})}var sl=`__routine__`;function cl(e){return{title:``,status:e===`todo`?`pending`:`pool`,priority:``,taskId:``,linkedTask:``,startDate:pn(),dueDate:pn(),note:``}}function ll(e,t){let n=Array.isArray(t)?t:[],r=[];for(let t of n){if(!t||typeof t!=`object`)continue;let n=t,i=typeof n.title==`string`?n.title.trim():``;if(!i)continue;let a=e===`todo`?Pn:jn,o=e===`todo`?H:U,s=cl(e);r.push({...s,title:i,status:typeof n.status==`string`&&a.includes(n.status)?n.status:e===`todo`?`pending`:`pool`,priority:typeof n.priority==`string`&&o.includes(n.priority)?n.priority:``,taskId:typeof n.taskId==`string`?n.taskId.trim():``,linkedTask:typeof n.linkedTask==`string`?n.linkedTask.trim():``,startDate:typeof n.startDate==`string`?n.startDate.trim().slice(0,10):s.startDate,dueDate:typeof n.dueDate==`string`?n.dueDate.trim().slice(0,10):s.dueDate,note:typeof n.note==`string`?n.note.trim():``})}return r}function ul(e,t){return t.map(t=>{let n={title:t.title.trim(),status:t.status,priority:t.priority,startDate:t.startDate,dueDate:t.dueDate,note:t.note};return e===`todo`&&(n.taskId=t.taskId,n.linkedTask=t.linkedTask),n})}var dl=`text-[11px] font-medium text-stone-500`,fl=`h-9 w-full rounded-lg border border-stone-200 px-2.5 text-[13px] text-stone-800 outline-none focus:border-[#4176e6]`;function pl(e){let t=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e);return t?`${t[1]}/${t[2]}/${t[3]}`:``}function ml(e){return(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-center justify-between gap-2`,children:[(0,Z.jsx)(`span`,{className:`shrink-0 text-[11px] text-stone-400`,children:e.label}),(0,Z.jsx)(`span`,{className:`min-w-0 truncate text-[12px] text-stone-700`,children:e.children})]})}function hl(e){return(0,Z.jsxs)(`div`,{className:`grid grid-cols-[48px_minmax(0,1fr)] items-center gap-x-2`,children:[(0,Z.jsx)(`span`,{className:`text-[11px] text-stone-400`,children:e.label}),(0,Z.jsx)(`span`,{className:`min-w-0 truncate text-[12px] text-stone-700`,children:e.children})]})}function gl(e){let{startDate:t,dueDate:n}=e,r=n||t,i=`h-7 rounded-md px-1.5 text-[12px] text-stone-700 tabular-nums transition-colors hover:bg-stone-100`;return(0,Z.jsxs)(`div`,{className:`grid grid-cols-[48px_minmax(0,1fr)] items-center gap-x-2`,children:[(0,Z.jsx)(`span`,{className:`text-[11px] text-stone-400`,children:`日期`}),(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-center gap-0.5`,children:[(0,Z.jsx)(`span`,{className:`min-w-0 flex-1`,children:(0,Z.jsx)(ee,{value:t,ariaLabel:`开始日期`,placeholder:`开始日期`,clearable:!1,className:i,onChange:t=>{t&&e.onChange({startDate:t,dueDate:t>r?t:r})}})}),(0,Z.jsx)(`span`,{className:`shrink-0 px-0.5 text-[11px] text-stone-300`,"aria-hidden":!0,children:`~`}),(0,Z.jsx)(`span`,{className:`min-w-0 flex-1`,children:(0,Z.jsx)(ee,{value:n,ariaLabel:`截止日期`,placeholder:`截止日期`,clearable:!1,className:i,onChange:n=>{n&&e.onChange({startDate:n<t?n:t,dueDate:n})}})})]})]})}function _l(e){let[t,n]=(0,K.useState)(()=>e.items),[r,i]=(0,K.useState)(0),[a,o]=(0,K.useState)([]);(0,K.useEffect)(()=>{n(e.items),i(0)},[e.items]);let s=e.kind===`todo`,c=!!e.quick&&s,l=s&&e.tasksOn!==!1,u=s&&!c&&l,d=s?`待办`:`任务`,f=s?`待办事项`:`任务管理`;(0,K.useEffect)(()=>{if(!l)return;let e=!0;return W().then(t=>{e&&o(t)}).catch(()=>{}),()=>{e=!1}},[l]);let p=s?Pn:jn,m=s?H:U,h=(0,K.useMemo)(()=>p.map(e=>({value:e,label:s?Sn[e]:En[e]})),[s,p]),g=(0,K.useMemo)(()=>[{value:``,label:`未设置`},...m.map(e=>({value:e,label:s?Mn[e]:kn[e]}))],[s,m]),_=(0,K.useMemo)(()=>[{value:``,label:`不关联`},...a.filter(e=>e.status!==`closed`&&e.status!==`cancelled`).map(e=>({value:e.id,label:e.title}))],[a]),v=(0,K.useMemo)(()=>!!Ha(a),[a]),y=(0,K.useMemo)(()=>{let e=new Set(t.map(e=>e.taskId).filter(Boolean));return[{value:``,label:`不关联`},...v?[]:[{value:sl,label:`${Ba}(确认后自动创建)`}],...a.filter(t=>e.has(t.id)||t.status!==`closed`&&t.status!==`cancelled`).map(e=>({value:e.id,label:e.title}))]},[t,a,v]);function b(e){return e.taskId&&a.some(t=>t.id===e.taskId)?e.taskId:!v&&e.linkedTask.trim()===`日常待办`?sl:``}function x(e,t){if(t===sl){S(e,{taskId:``,linkedTask:Ba});return}let n=a.find(e=>e.id===t);S(e,{taskId:n?.id??``,linkedTask:n?.title??``,...n?{priority:n.priority}:{}})}function S(e,t){n(n=>n.map((n,r)=>r===e?{...n,...t}:n))}function C(e,n){let r=t[e],i=a.find(e=>e.id===n);i?S(e,{taskId:i.id,linkedTask:i.title,startDate:i.startDate||r?.startDate||``,dueDate:i.dueDate||r?.dueDate||``,priority:r?.priority||i.priority||``}):S(e,{taskId:``,linkedTask:``})}function w(e){n(t=>t.filter((t,n)=>n!==e))}let T=t.length>0&&t.every(e=>!!e.title.trim()),E=u&&r>=1,D=c&&t.some(e=>!e.taskId.trim()&&e.linkedTask.trim()===`日常待办`)&&!v,O=E?`所属任务的日期与紧急程度已带到第一页,可回去再调`:c?D?e.quickNote??`确认后会自动创建任务「日常待办」并关联`:`状态 / 所属任务 / 日期已填好(日期可点开改),确认后写入「待办事项」`:`确认后才会写入「${f}」`;return(0,Z.jsxs)(`div`,{className:[`tw-create-card tw-create-card-anim mb-2 flex max-h-[min(62vh,560px)] flex-col overflow-hidden rounded-2xl border border-stone-200 bg-white shadow-[0_6px_24px_rgba(15,23,42,0.08)]`,e.closing?`is-closing`:``].filter(Boolean).join(` `),children:[(0,Z.jsxs)(`div`,{className:`shrink-0 px-5 pt-4`,children:[(0,Z.jsxs)(`div`,{className:`mb-1 flex items-center gap-2 text-[11px] leading-4 text-stone-400`,children:[(0,Z.jsxs)(`span`,{children:[`新增 `,t.length,` 条`,d]}),u?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`span`,{className:`text-stone-300`,children:`·`}),(0,Z.jsxs)(`span`,{className:`tabular-nums`,children:[`第 `,r+1,` / 2 步`]})]}):null]}),(0,Z.jsx)(`h3`,{className:`text-[15px] leading-5.5 font-medium text-stone-900`,children:E?`关联任务`:r===0?`确认内容后再添加到${f}`:f})]}),(0,Z.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto overscroll-contain px-5 py-3`,children:(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[t.map((e,n)=>{let r=a.find(t=>t.id===e.taskId);return(0,Z.jsx)(`div`,{className:`rounded-xl border border-stone-200 bg-stone-50/40 p-3`,children:c?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Z.jsx)(`input`,{value:e.title,onChange:e=>S(n,{title:e.target.value}),placeholder:`待办名称`,className:`${fl} bg-white`,autoFocus:n===0}),t.length>1?(0,Z.jsx)(`button`,{type:`button`,onClick:()=>w(n),"aria-label":`移除这一条`,className:`h-9 shrink-0 rounded-lg px-2 text-[12px] text-stone-400 hover:bg-white hover:text-red-600`,children:`移除`}):null]}),(0,Z.jsxs)(`div`,{className:`mt-2 space-y-1.5 rounded-lg border border-stone-200 bg-white px-2.5 py-2`,children:[(0,Z.jsx)(hl,{label:`状态`,children:Sn[e.status]??`进行中`}),l?(0,Z.jsxs)(`div`,{className:`grid grid-cols-[48px_minmax(0,1fr)] items-center gap-x-2`,children:[(0,Z.jsx)(`span`,{className:`text-[11px] text-stone-400`,children:`所属任务`}),a.length||!v?(0,Z.jsx)(j,{flat:!0,ariaLabel:`所属任务`,menuMatchTrigger:!1,menuMinWidth:200,options:y,value:b(e),onChange:e=>x(n,e),className:`min-w-0`,triggerClassName:`h-7 gap-1 rounded-md border-0 bg-transparent pl-0 pr-0.5 text-[12px] hover:bg-stone-50`}):(0,Z.jsx)(`span`,{className:`min-w-0 truncate text-[12px] text-stone-700`,children:e.linkedTask||`未关联`})]}):null,(0,Z.jsx)(gl,{startDate:e.startDate,dueDate:e.dueDate,onChange:e=>S(n,e)})]})]}):E?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,Z.jsx)(`span`,{className:dl,children:`所属任务`}),a.length?(0,Z.jsx)(j,{flat:!0,ariaLabel:`所属任务`,options:_,value:e.taskId,onChange:e=>C(n,e),className:`w-full`}):(0,Z.jsx)(`span`,{className:`flex h-9 items-center rounded-lg border border-stone-200 bg-white px-2 text-[13px] text-stone-400`,children:`任务管理里还没有任务,可稍后到任务管理关联`})]}),r?(0,Z.jsxs)(`div`,{className:`mt-2 space-y-1.5 rounded-lg border border-stone-200 bg-white px-2.5 py-2`,children:[(0,Z.jsx)(ml,{label:`任务名称`,children:r.title}),(0,Z.jsx)(ml,{label:`状态`,children:En[r.status]??r.status}),(0,Z.jsx)(ml,{label:`紧急程度`,children:r.priority?kn[r.priority]:`未设置`}),(0,Z.jsx)(ml,{label:`开始日期`,children:pl(r.startDate)||`未设置`}),(0,Z.jsx)(ml,{label:`结束日期`,children:pl(r.dueDate)||`未设置`})]}):(0,Z.jsx)(`p`,{className:`mt-2 text-[11px] leading-4 text-stone-400`,children:`选中任务后,它的开始 / 结束日期与紧急程度会自动带到第一页。`})]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Z.jsx)(`input`,{value:e.title,onChange:e=>S(n,{title:e.target.value}),placeholder:s?`待办名称`:`任务名称`,className:`${fl} bg-white`,autoFocus:n===0}),t.length>1?(0,Z.jsx)(`button`,{type:`button`,onClick:()=>w(n),"aria-label":`移除这一条`,className:`h-9 shrink-0 rounded-lg px-2 text-[12px] text-stone-400 hover:bg-white hover:text-red-600`,children:`移除`}):null]}),(0,Z.jsxs)(`div`,{className:`mt-2 grid grid-cols-2 gap-2`,children:[(0,Z.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,Z.jsx)(`span`,{className:dl,children:`状态`}),(0,Z.jsx)(j,{flat:!0,ariaLabel:s?`待办状态`:`任务状态`,options:h,value:e.status,onChange:e=>S(n,{status:e}),className:`w-full`})]}),(0,Z.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,Z.jsx)(`span`,{className:dl,children:`紧急程度`}),(0,Z.jsx)(j,{flat:!0,ariaLabel:`紧急程度`,options:g,value:e.priority,onChange:e=>S(n,{priority:e}),className:`w-full`})]}),(0,Z.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,Z.jsx)(`span`,{className:dl,children:`开始日期`}),(0,Z.jsx)(ee,{value:e.startDate,onChange:e=>S(n,{startDate:e}),placeholder:`选择日期`,className:`h-9 rounded-lg border border-stone-200 bg-white px-2 text-[13px] tabular-nums`})]}),(0,Z.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,Z.jsx)(`span`,{className:dl,children:`截止日期`}),(0,Z.jsx)(ee,{value:e.dueDate,onChange:e=>S(n,{dueDate:e}),placeholder:`选择日期`,className:`h-9 rounded-lg border border-stone-200 bg-white px-2 text-[13px] tabular-nums`})]})]}),(0,Z.jsxs)(`label`,{className:`mt-2 flex flex-col gap-1`,children:[(0,Z.jsx)(`span`,{className:dl,children:`备注`}),(0,Z.jsx)(`input`,{value:e.note,onChange:e=>S(n,{note:e.target.value}),placeholder:`备注(可选)`,className:`${fl} bg-white`})]})]})},n)}),t.length?null:(0,Z.jsx)(`p`,{className:`py-4 text-center text-[12px] text-stone-400`,children:`内容已清空,点「取消」放弃这次新增。`})]})}),(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between gap-3 border-t border-stone-100 px-5 py-3`,children:[(0,Z.jsx)(`span`,{className:`min-w-0 truncate text-[11px] text-stone-400`,children:O}),(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:E?()=>i(0):e.onCancel,className:`h-8 rounded-lg px-3 text-[12px] text-stone-600 outline-none hover:bg-stone-100`,children:E?`上一步`:`取消`}),(0,Z.jsx)(`button`,{type:`button`,disabled:!E&&!T,onClick:()=>{u&&r===0?i(1):e.onConfirm(t)},className:`h-8 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:u&&r===0?`下一步`:e.manual?`提交`:`确认新增`})]})]})]})}function vl(e,t,n){let r=e;if(n.knowledge&&(r=`${r}\n\n${cc}`),n.fs&&(r=`${r}\n\n${Bt}\n\n${ia}\n\n${io}\n\n${ai}\n\n${ti}`),n.bash&&(r=`${r}\n\n${Gn}`),n.pwsh&&(r=`${r}\n\n${Kn}`),n.web&&(r=`${r}\n\n${Vn}`),n.memory&&(r=`${r}\n\n${lr}`),n.interact&&(r=`${r}\n\n${go}`),n.todos&&(r=`${r}\n\n${ja}`),n.tasks&&(r=`${r}\n\n${Ka}`),n.projects&&(r=`${r}\n\n${ca}`),n.iterations&&(r=`${r}\n\n${la}`),n.pmRequirements&&(r=`${r}\n\n${ua}`),n.bugs&&(r=`${r}\n\n${da}`),n.planPhase===`planning`&&(r=`${r}\n\n${wo}`),n.planPhase===`approved`&&(r=`${r}\n\n${To}`),n.goalEnabled){r=`${r}\n\n${Ro}`;let e=Ho(n.goal);e&&(r=`${r}\n\n【当前会话目标】${e}`)}n.scheduleEnabled&&(r=`${r}\n\n${as}`),n.subagentEnabled&&(r=`${r}\n\n${ws}`),n.workflowEnabled&&(r=`${r}\n\n${Qs}`);let i=n.memory?t.slice(-10):t;return[{role:`system`,content:r},...i]}function yl(e){if(!/(?:^|[\s\n])\/$/.test(e))return null;let t=e.lastIndexOf(`/`);return t<0?null:{from:t}}function bl(e){let t=/(?:^|[\s\n])@([^\s@]*)$/.exec(e);if(!t)return null;let n=e.lastIndexOf(`@`);return n<0?null:{from:n,query:t[1]??``}}function xl(e){let t=/\s*(?:[((](?:recommended|推荐)[))])\s*$/i;return t.test(e)?{label:e.replace(t,``),recommended:!0}:{label:e,recommended:!1}}var Sl=je,Cl=5,wl=[`image/png`,`image/jpeg`,`image/jpg`,`image/webp`,`image/gif`],Tl=[`dialog`,`thread`,`todos`,`memory`],El=`chat.tab`;function Dl(e){let t=[];if(e.content&&t.push(e.content),e.refs?.length){let n=e.refs.filter(e=>e.collection!==`workspace`),r=e.refs.filter(e=>e.collection===`workspace`);if(n.length){let e=n.filter(e=>e.collection===`knowledge`||e.collection===`templates`),r=n.filter(e=>e.collection===`prompts`||e.collection===`cases`);if(e.length){let n=e.map(e=>`- ${e.path} 《${e.title}》(${e.category} · ${oc(e.format)})`);t.push(`引用项目文档(请使用 kb_read 读取):\n${n.join(`
218
218
  `)}`)}if(r.length){let e=r.map(e=>`- ${e.collection}/${e.path} 《${e.title}》(${e.category})`);t.push(`引用管理文档(路径已给出,正文可能已在上文):\n${e.join(`
219
219
  `)}`)}}if(r.length){let e=r.map(e=>`- ${e.path} 《${e.title}》(${e.format===`dir`?`文件夹`:`文件`})`);t.push(`引用工作区路径(请使用 fs_list / fs_read):\n${e.join(`
220
220
  `)}`)}}return e.attachments?.length&&t.push(e.attachments.map(e=>`附件《${e.name}》:\n\`\`\`\`\n${e.content}\n\`\`\`\``).join(`
@@ -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),[Ce,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 Te(`prompts`)){M(`提示词管理服务未就绪,系统提示词暂时用内置兜底。`,`error`);return}let e=(await Se(`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&&Ce&&(fi.current.add(Ce),X(et(Y.current,Ce,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:()=>{we(`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:()=>{we(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:!!Ce,title:`重命名会话`,label:`会话名称`,placeholder:`请输入会话名称`,initialValue:Ce?a?.sessions.find(e=>e.id===Ce)?.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];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};