lantern-harness 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +106 -0
- package/README.md +9 -9
- package/builtin/session/lh-nav-groups.mjs +106 -9
- package/builtin/session/lh-spaces.mjs +102 -0
- package/cli/data-root.mjs +110 -3
- package/cli/lantern.mjs +36 -7
- package/cli/server.mjs +8 -0
- package/cli/spaces.mjs +91 -5
- package/config/app.defaults.json +7 -2
- package/dist/500.html +19 -5
- package/dist/_astro/Base.C_AmDbI9.css +1 -0
- package/dist/_astro/{Base.astro_astro_type_script_index_0_lang.lxEwQ1R4.js → Base.astro_astro_type_script_index_0_lang.-g0SuFCa.js} +1 -1
- package/dist/_astro/CaseExecBoard.CNZh0sre.js +1 -0
- package/dist/_astro/CaseGenerateApp.BQalnGiC.js +9 -0
- package/dist/_astro/CasesLibrary.u7ek8rOp.js +1 -0
- package/dist/_astro/ChatApp.Dk5uOXr0.js +273 -0
- package/dist/_astro/ColumnResize.Bs6GL3DJ.js +1 -0
- package/dist/_astro/ConfirmDialog.Dbyjb4-6.js +1 -0
- package/dist/_astro/DatePicker.CMfX7F6z.js +1 -0
- package/dist/_astro/DocsFileBrowser.CHVgH1vj.js +1 -0
- package/dist/_astro/DocsPager.DaiWchhj.js +1 -0
- package/dist/_astro/DrawerField.KANqQwFl.js +1 -0
- package/dist/_astro/KnowledgeLibrary.DSxgeW4L.js +1 -0
- package/dist/_astro/NamePromptDialog.DZSZ5Y16.js +1 -0
- package/dist/_astro/NavLibraries.BN5smOBt.js +1 -0
- package/dist/_astro/PluginsPage.BB18crT3.js +1 -0
- package/dist/_astro/PluginsPage.Oh8hWup8.js +39 -0
- package/dist/_astro/PromptsLibrary.DWgox1du.js +1 -0
- package/dist/_astro/ReportsPage.BlHA_AtE.js +1 -0
- package/dist/_astro/RequirementsLibrary.2o-KMk7K.js +1 -0
- package/dist/_astro/SearchableSelect.BMl1Bp59.js +1 -0
- package/dist/_astro/SelectDropdown.flhHcwyd.js +1 -0
- package/dist/_astro/SettingsDialog.Cs8z0Hhb.js +1 -0
- package/dist/_astro/SpaceSwitcher.DicPqrSH.js +7 -0
- package/dist/_astro/TagSelect.u8DTop7v.js +1 -0
- package/dist/_astro/TasksBoard.dgJxOpVG.js +1 -0
- package/dist/_astro/TemplatesLibrary.BfC9HIuu.js +1 -0
- package/dist/_astro/TestStatsBoard.Dg23e0O_.js +1 -0
- package/dist/_astro/TodosBoard.CyvTZybr.js +1 -0
- package/dist/_astro/active-element-history.CeefGkFQ.js +1 -0
- package/dist/_astro/app-config.Crg0VdkS.js +1 -0
- package/dist/_astro/case-exec.HjGrOY_O.js +1 -0
- package/dist/_astro/doc-roots.DAJP9Svr.js +1 -0
- package/dist/_astro/i18n.C8FKLrB5.js +7 -0
- package/dist/_astro/listbox.Di-t5U37.js +1 -0
- package/dist/_astro/menu.Bkluqxic.js +1 -0
- package/dist/_astro/{open-docs-in-session.D3JCwMWB.js → open-docs-in-session.BC5D-BoF.js} +1 -1
- package/dist/_astro/plugins.CNOYmeAe.js +1 -0
- package/dist/_astro/portal.Cm9XlIPf.js +5 -0
- package/dist/_astro/project-docs.Cd2gKPKh.js +1 -0
- package/dist/_astro/report-prompt.Cmw4XzfY.js +1 -0
- package/dist/_astro/{settings.BoQ0e0m1.js → settings.DBIYsQY-.js} +2 -2
- package/dist/_astro/tasks.WhfT-DnC.js +1 -0
- package/dist/_astro/test-stats.BIHEJz5c.js +1 -0
- package/dist/_astro/use-text-value.BuY0Cm1z.js +1 -0
- package/dist/_astro/use-tree-walker.CfTHFX43.js +1 -0
- package/dist/_astro/useListAnim.CpGB1cft.js +1 -0
- package/dist/_astro/view-prefs.C9Mtta1E.js +1 -0
- package/dist/case-exec/index.html +263 -0
- package/dist/cases/generate/index.html +20 -6
- package/dist/cases/library/index.html +20 -6
- package/dist/docs/changelog/index.html +121 -6
- package/dist/docs/install/index.html +35 -11
- package/dist/docs/manual/index.html +149 -14
- package/dist/index.html +20 -6
- package/dist/knowledge/index.html +20 -6
- 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 +19 -5
- package/dist/plugins/index.html +20 -6
- package/dist/prompts/index.html +20 -6
- package/dist/reports/index.html +263 -0
- package/dist/requirements/index.html +20 -6
- package/dist/tasks/index.html +263 -0
- package/dist/templates/index.html +20 -6
- 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 +19 -5
- 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 +19 -5
- 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 +19 -5
- 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 +19 -5
- 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 +19 -5
- package/dist/test-stats/index.html +263 -0
- package/dist/todos/index.html +263 -0
- package/docs//345/205/250/345/261/200/346/217/222/344/273/266.md +2 -2
- package/docs//345/256/211/350/243/205/346/211/213/345/206/214.md +13 -11
- package/docs//346/223/215/344/275/234/346/211/213/345/206/214.md +125 -26
- package/lh-plugins/lh-project-docs.mjs +3 -1
- package/lh-plugins/lh-reports.mjs +413 -0
- package/lh-plugins/lh-stats.mjs +409 -0
- package/lh-plugins/lh-tasks.mjs +224 -0
- package/lh-plugins/lh-todos.mjs +295 -0
- package/lh-plugins/lh-work-store.mjs +81 -0
- package/lh-plugins/storage-domain.mjs +54 -3
- package/package.json +2 -1
- package/config/seeds//346/217/220/347/244/272/350/257/215/347/256/241/347/220/206//345/212/237/350/203/275/346/265/213/350/257/225/347/224/250/344/276/213/346/217/220/347/244/272/350/257/215v1.0.md +0 -155
- package/dist/_astro/Base.B9f_iFAZ.css +0 -1
- package/dist/_astro/CaseGenerateApp.Br4uKjun.js +0 -9
- package/dist/_astro/CasesLibrary.CpPoVQ4P.js +0 -1
- package/dist/_astro/ChatApp.CYSPlSNP.js +0 -258
- package/dist/_astro/ConfirmDialog.BYz4HREM.js +0 -1
- package/dist/_astro/DocsFileBrowser.DkE26UTR.js +0 -1
- package/dist/_astro/KnowledgeLibrary.DZinlAWn.js +0 -1
- package/dist/_astro/NamePromptDialog.DGBlDH_k.js +0 -1
- package/dist/_astro/NavLibraries.EayBsg5g.js +0 -1
- package/dist/_astro/PluginsPage.BNzpPg2H.js +0 -39
- package/dist/_astro/PluginsPage.CY61glLU.js +0 -1
- package/dist/_astro/PromptsLibrary.DfrrCjs7.js +0 -1
- package/dist/_astro/RequirementsLibrary.Dt0Gj6Nr.js +0 -1
- package/dist/_astro/SearchableSelect.DMS2XmXc.js +0 -1
- package/dist/_astro/SelectDropdown.Dc7QaPbH.js +0 -1
- package/dist/_astro/SettingsDialog.DC0e7580.js +0 -1
- package/dist/_astro/SpaceSwitcher.Yy2w8MDF.js +0 -7
- package/dist/_astro/TemplatesLibrary.uK-SjK1z.js +0 -1
- package/dist/_astro/app-config.CpjKWnzM.js +0 -1
- package/dist/_astro/i18n.BVvhz-vw.js +0 -7
- package/dist/_astro/listbox.DdDDDJ5Z.js +0 -1
- package/dist/_astro/menu.CqkL87bV.js +0 -1
- package/dist/_astro/plugins.CrpY8UI9.js +0 -1
- package/dist/_astro/portal.C3KrUREL.js +0 -5
- package/dist/_astro/use-text-value.C0IDspmh.js +0 -1
- package/dist/_astro/use-tree-walker.oRTnhHS-.js +0 -1
- package/dist/_astro/useListAnim.CnbC_9MC.js +0 -1
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["_astro/lib.DJNDi_Ht.js","_astro/react-dom.CqAxpHMt.js","_astro/ExcelFieldTags.B_XMwNNx.js","_astro/jsx-runtime.BUXbF_vF.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{c as e,n as t,t as n}from"./react-dom.CqAxpHMt.js";import{B as r,F as i,I as a,L as o,R as s,i as c,p as l,r as u,t as d,u as f,z as p}from"./app-config.Crg0VdkS.js";import{a as m,i as h,o as g,r as _,t as v}from"./plugins.CNOYmeAe.js";import{r as y,t as b}from"./view-prefs.C9Mtta1E.js";import{t as x}from"./ConfirmDialog.Dbyjb4-6.js";import{c as S,d as C,f as w,l as ee,n as T,t as E,u as D}from"./SearchableSelect.BMl1Bp59.js";import{i as te,n as ne,r as O,t as re}from"./menu.Bkluqxic.js";import{t as k}from"./jsx-runtime.BUXbF_vF.js";import{t as A}from"./DatePicker.CMfX7F6z.js";import{t as j}from"./SelectDropdown.flhHcwyd.js";import{a as M,c as ie,d as N,f as ae,i as oe,n as se,o as P,r as ce,s as le,t as ue,u as de}from"./ExcelFieldTags.B_XMwNNx.js";import{a as fe,i as F,r as pe,s as me,t as he}from"./llm.BZEzE0x2.js";import{_ as I,d as ge,f as L,g as _e,l as ve,r as ye,s as be}from"./project-docs.Cd2gKPKh.js";import{n as xe,t as Se}from"./doc-roots.DAJP9Svr.js";import{i as Ce,n as we,r as Te,t as Ee}from"./prompts-meta.F4wwkjUA.js";import{d as De,f as Oe,l as ke,m as Ae,o as je,p as Me,r as Ne,s as Pe,y as Fe}from"./settings.DBIYsQY-.js";import{C as Ie,D as Le,E as Re,O as ze,S as Be,T as Ve,_ as He,a as Ue,b as We,c as Ge,d as Ke,f as qe,g as Je,h as Ye,i as Xe,l as Ze,m as Qe,n as $e,o as et,p as tt,r as nt,s as rt,u as it,v as at,w as ot,x as st,y as ct}from"./open-docs-in-session.BC5D-BoF.js";import{n as R}from"./i18n.C8FKLrB5.js";import{$ as lt,A as ut,B as dt,C as ft,D as pt,E as mt,F as ht,G as gt,H as _t,I as vt,J as yt,K as bt,L as xt,M as St,N as Ct,O as wt,P as Tt,Q as Et,R as Dt,T as Ot,U as kt,V as At,W as jt,X as Mt,Y as Nt,Z as Pt,_ as Ft,a as It,at as Lt,b as Rt,c as zt,d as Bt,et as Vt,f as Ht,g as Ut,h as Wt,i as Gt,it as Kt,j as qt,k as Jt,l as Yt,m as Xt,n as Zt,nt as Qt,o as $t,p as en,q as tn,r as nn,rt as rn,s as an,t as on,tt as sn,u as cn,v as z,w as ln,x as un,y as dn,z as fn}from"./PluginsPage.Oh8hWup8.js";import{A as pn,C as mn,D as hn,N as gn,O as B,P as _n,S as vn,T as yn,_ as bn,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 Mn,u as V,v as Nn,x as Pn,y as Fn}from"./tasks.WhfT-DnC.js";import{n as In,s as Ln,t as Rn}from"./report-prompt.Cmw4XzfY.js";import{t as zn}from"./NamePromptDialog.DZSZ5Y16.js";var H=e(t(),1),Bn=e(n(),1),Vn=`/__tb_sessions/runs`;async function Hn(e){try{return(await fetch(Vn,{signal:e??AbortSignal.timeout(1500)})).ok}catch{return!1}}async function Un(e){let t=await fetch(Vn,{signal:e??AbortSignal.timeout(3e3)});if(!t.ok)return[];let n=await t.json();return Array.isArray(n.runs)?n.runs:[]}async function Wn(e){let t=await fetch(Vn,{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 Gn(e){await fetch(`${Vn}/${encodeURIComponent(e)}/stop`,{method:`POST`}).catch(()=>{})}async function Kn(e){try{let t=await fetch(`${Vn}/${encodeURIComponent(e)}`,{signal:AbortSignal.timeout(3e3)});return t.status===404?{ok:!1}:t.ok?await t.json():null}catch{return null}}function qn(e){return e===`completed`||e===`stopped`||e===`error`}function Jn(e,t,n,r){let i=new AbortController,a=`${Vn}/${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
|
+
`);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 Yn(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=Jn(e,i,e=>{typeof e.seq==`number`&&Number.isFinite(e.seq)&&(i=Math.max(i,e.seq)),n.onEvent(e),e.type===`status`&&qn(e.status)&&(n.onTerminal?.(e),l())},t=>{r||n.signal?.aborted||(async()=>{a+=1;try{let r=await Kn(e);if(r?.ok&&typeof r.seq==`number`&&(i=Math.max(i,r.seq)),r?.ok&&qn(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 Xn(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 Zn(e,t){let n=(e||``).trim()||`新对话`;return n===`新对话`||n===Ie(t)}function Qn(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 $n(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 Qn(await pe(e,i,n))||null}catch{return null}}function er(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 tr(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
|
+
`)}var nr=new Map,rr=new Map,ir=40;function ar(e,t,n=``){return`${e}:${t}:${n}`}function or(e){for(;e.size>ir;){let t=e.keys().next().value;if(t===void 0)break;e.delete(t)}}function sr(e,t,n,r,i=``){let a=e===`outline`?nr:rr,o=ar(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}),or(a),c}var cr=`/__tb_sessions/log`;function lr(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 ur(e){try{let t=await fetch(cr,{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 dr(e){return String(e??``).trim()}function fr(e,t=80){let n=dr(e).replace(/\s+/g,` `);return n?n.length>t?`${n.slice(0,t)}…`:n:``}function pr(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=dr(a.content),t=fr(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=dr(a.content),t=dr(a.reasoning)||void 0;n.push({index:n.length+1,userPreview:r.preview,assistantPreview:fr(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 mr(e,t){let n=String(t??``).trim();return!n||n===`inherit`||n===e.model?e:{...e,model:n}}var hr=`/__tb_fs`,gr=`你可以使用 office_to_pdf:优先用本机 LibreOffice 转为 PDF;若未安装,则对 docx/xlsx/pptx 降级抽取正文为同目录 .extracted.md(需写权限)。`,_r={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 vr(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(`${hr}/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 U=`/__tb_fs`,yr=`你可以使用 load_workspace_dependencies:查询本机 node / npm / pnpm / python 等可执行文件绝对路径(需本地 fs 服务)。`,br={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 xr(e){if(e!==`load_workspace_dependencies`)return JSON.stringify({error:`unknown tool: ${e}`});try{let e=await fetch(`${U}/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 Sr(e){return Array.isArray(e)}function Cr(e){return Sr(e)?e.some(e=>e.type===`image_url`):!1}function wr(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
|
+
`)||r||`(图片已卸载)`}]}function Tr(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`&&Cr(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`||!Cr(e.content)||i.has(t)||!Sr(e.content)?e:(a=!0,{...e,content:wr(e.content)}));return a?o:e}function Er(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var Dr=Er();function Or(e){Dr=e}var kr={exec:()=>null};function W(e,t=``){let n=typeof e==`string`?e:e.source,r={replace:(e,t)=>{let i=typeof t==`string`?t:t.source;return i=i.replace(Ar.caret,`$1`),n=n.replace(e,i),r},getRegex:()=>new RegExp(n,t)};return r}var Ar={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceTabs:/^\t+/,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] /,listReplaceTask:/^\[[ xX]\] +/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,unescapeTest:/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/gi,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:e=>RegExp(`^( {0,3}${e})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),hrRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}#`),htmlBeginRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}<(?:[a-z].*>|!--)`,`i`)},jr=/^(?:[ \t]*(?:\n|$))+/,Mr=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,Nr=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,Pr=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,Fr=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,Ir=/(?:[*+-]|\d{1,9}[.)])/,Lr=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,G=W(Lr).replace(/bull/g,Ir).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,``).getRegex(),Rr=W(Lr).replace(/bull/g,Ir).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),zr=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,Br=/^[^\n]+/,Vr=/(?!\s*\])(?:\\.|[^\[\]\\])+/,Hr=W(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace(`label`,Vr).replace(`title`,/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),Ur=W(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,Ir).getRegex(),Wr=`address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul`,Gr=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,Kr=W(`^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))`,`i`).replace(`comment`,Gr).replace(`tag`,Wr).replace(`attribute`,/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),qr=W(zr).replace(`hr`,Pr).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`|lheading`,``).replace(`|table`,``).replace(`blockquote`,` {0,3}>`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace(`list`,` {0,3}(?:[*+-]|1[.)]) `).replace(`html`,`</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,Wr).getRegex(),Jr={blockquote:W(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace(`paragraph`,qr).getRegex(),code:Mr,def:Hr,fences:Nr,heading:Fr,hr:Pr,html:Kr,lheading:G,list:Ur,newline:jr,paragraph:qr,table:kr,text:Br},Yr=W(`^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)`).replace(`hr`,Pr).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`blockquote`,` {0,3}>`).replace(`code`,`(?: {4}| {0,3} )[^\\n]`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace(`list`,` {0,3}(?:[*+-]|1[.)]) `).replace(`html`,`</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,Wr).getRegex(),Xr={...Jr,lheading:Rr,table:Yr,paragraph:W(zr).replace(`hr`,Pr).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`|lheading`,``).replace(`table`,Yr).replace(`blockquote`,` {0,3}>`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace(`list`,` {0,3}(?:[*+-]|1[.)]) `).replace(`html`,`</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,Wr).getRegex()},Zr={...Jr,html:W(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace(`comment`,Gr).replace(/tag/g,`(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b`).getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:kr,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:W(zr).replace(`hr`,Pr).replace(`heading`,` *#{1,6} *[^
|
|
6
|
+
]`).replace(`lheading`,G).replace(`|table`,``).replace(`blockquote`,` {0,3}>`).replace(`|fences`,``).replace(`|list`,``).replace(`|html`,``).replace(`|tag`,``).getRegex()},Qr=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,$r=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,ei=/^( {2,}|\\)\n(?!\s*$)/,ti=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,ni=/[\p{P}\p{S}]/u,ri=/[\s\p{P}\p{S}]/u,ii=/[^\s\p{P}\p{S}]/u,ai=W(/^((?![*_])punctSpace)/,`u`).replace(/punctSpace/g,ri).getRegex(),oi=/(?!~)[\p{P}\p{S}]/u,si=/(?!~)[\s\p{P}\p{S}]/u,ci=/(?:[^\s\p{P}\p{S}]|~)/u,li=/\[[^[\]]*?\]\((?:\\.|[^\\\(\)]|\((?:\\.|[^\\\(\)])*\))*\)|`[^`]*?`|<[^<>]*?>/g,ui=/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/,di=W(ui,`u`).replace(/punct/g,ni).getRegex(),fi=W(ui,`u`).replace(/punct/g,oi).getRegex(),pi=`^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)`,mi=W(pi,`gu`).replace(/notPunctSpace/g,ii).replace(/punctSpace/g,ri).replace(/punct/g,ni).getRegex(),hi=W(pi,`gu`).replace(/notPunctSpace/g,ci).replace(/punctSpace/g,si).replace(/punct/g,oi).getRegex(),gi=W(`^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)`,`gu`).replace(/notPunctSpace/g,ii).replace(/punctSpace/g,ri).replace(/punct/g,ni).getRegex(),_i=W(/\\(punct)/,`gu`).replace(/punct/g,ni).getRegex(),vi=W(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace(`scheme`,/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace(`email`,/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),yi=W(Gr).replace(`(?:-->|$)`,`-->`).getRegex(),bi=W(`^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>`).replace(`comment`,yi).replace(`attribute`,/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),xi=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,Si=W(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]*(?:\n[ \t]*)?)(title))?\s*\)/).replace(`label`,xi).replace(`href`,/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace(`title`,/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),Ci=W(/^!?\[(label)\]\[(ref)\]/).replace(`label`,xi).replace(`ref`,Vr).getRegex(),wi=W(/^!?\[(ref)\](?:\[\])?/).replace(`ref`,Vr).getRegex(),Ti={_backpedal:kr,anyPunctuation:_i,autolink:vi,blockSkip:li,br:ei,code:$r,del:kr,emStrongLDelim:di,emStrongRDelimAst:mi,emStrongRDelimUnd:gi,escape:Qr,link:Si,nolink:wi,punctuation:ai,reflink:Ci,reflinkSearch:W(`reflink|nolink(?!\\()`,`g`).replace(`reflink`,Ci).replace(`nolink`,wi).getRegex(),tag:bi,text:ti,url:kr},Ei={...Ti,link:W(/^!?\[(label)\]\((.*?)\)/).replace(`label`,xi).getRegex(),reflink:W(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace(`label`,xi).getRegex()},Di={...Ti,emStrongRDelimAst:hi,emStrongLDelim:fi,url:W(/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,`i`).replace(`email`,/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])((?:\\.|[^\\])*?(?:\\.|[^\s~\\]))\1(?=[^~]|$)/,text:/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/},Oi={...Di,br:W(ei).replace(`{2,}`,`*`).getRegex(),text:W(Di.text).replace(`\\b_`,`\\b_| {2,}\\n`).replace(/\{2,\}/g,`*`).getRegex()},ki={normal:Jr,gfm:Xr,pedantic:Zr},Ai={normal:Ti,gfm:Di,breaks:Oi,pedantic:Ei},ji={"&":`&`,"<":`<`,">":`>`,'"':`"`,"'":`'`},Mi=e=>ji[e];function Ni(e,t){if(t){if(Ar.escapeTest.test(e))return e.replace(Ar.escapeReplace,Mi)}else if(Ar.escapeTestNoEncode.test(e))return e.replace(Ar.escapeReplaceNoEncode,Mi);return e}function Pi(e){try{e=encodeURI(e).replace(Ar.percentDecode,`%`)}catch{return null}return e}function Fi(e,t){let n=e.replace(Ar.findPipe,(e,t,n)=>{let r=!1,i=t;for(;--i>=0&&n[i]===`\\`;)r=!r;return r?`|`:` |`}).split(Ar.splitPipe),r=0;if(n[0].trim()||n.shift(),n.length>0&&!n.at(-1)?.trim()&&n.pop(),t){if(n.length>t)n.splice(t);else for(;n.length<t;)n.push(``)}for(;r<n.length;r++)n[r]=n[r].trim().replace(Ar.slashPipe,`|`);return n}function Ii(e,t,n){let r=e.length;if(r===0)return``;let i=0;for(;i<r;){let a=e.charAt(r-i-1);if(a===t&&!n)i++;else if(a!==t&&n)i++;else break}return e.slice(0,r-i)}function Li(e,t){if(e.indexOf(t[1])===-1)return-1;let n=0;for(let r=0;r<e.length;r++)if(e[r]===`\\`)r++;else if(e[r]===t[0])n++;else if(e[r]===t[1]&&(n--,n<0))return r;return n>0?-2:-1}function Ri(e,t,n,r,i){let a=t.href,o=t.title||null,s=e[1].replace(i.other.outputLinkReplace,`$1`);r.state.inLink=!0;let c={type:e[0].charAt(0)===`!`?`image`:`link`,raw:n,href:a,title:o,text:s,tokens:r.inlineTokens(s)};return r.state.inLink=!1,c}function zi(e,t,n){let r=e.match(n.other.indentCodeCompensation);if(r===null)return t;let i=r[1];return t.split(`
|
|
7
|
+
`).map(e=>{let t=e.match(n.other.beginningSpace);if(t===null)return e;let[r]=t;return r.length>=i.length?e.slice(i.length):e}).join(`
|
|
8
|
+
`)}var Bi=class{options;rules;lexer;constructor(e){this.options=e||Dr}space(e){let t=this.rules.block.newline.exec(e);if(t&&t[0].length>0)return{type:`space`,raw:t[0]}}code(e){let t=this.rules.block.code.exec(e);if(t){let e=t[0].replace(this.rules.other.codeRemoveIndent,``);return{type:`code`,raw:t[0],codeBlockStyle:`indented`,text:this.options.pedantic?e:Ii(e,`
|
|
9
|
+
`)}}}fences(e){let t=this.rules.block.fences.exec(e);if(t){let e=t[0],n=zi(e,t[3]||``,this.rules);return{type:`code`,raw:e,lang:t[2]?t[2].trim().replace(this.rules.inline.anyPunctuation,`$1`):t[2],text:n}}}heading(e){let t=this.rules.block.heading.exec(e);if(t){let e=t[2].trim();if(this.rules.other.endingHash.test(e)){let t=Ii(e,`#`);(this.options.pedantic||!t||this.rules.other.endingSpaceChar.test(t))&&(e=t.trim())}return{type:`heading`,raw:t[0],depth:t[1].length,text:e,tokens:this.lexer.inline(e)}}}hr(e){let t=this.rules.block.hr.exec(e);if(t)return{type:`hr`,raw:Ii(t[0],`
|
|
10
|
+
`)}}blockquote(e){let t=this.rules.block.blockquote.exec(e);if(t){let e=Ii(t[0],`
|
|
11
|
+
`).split(`
|
|
12
|
+
`),n=``,r=``,i=[];for(;e.length>0;){let t=!1,a=[],o=0;for(;o<e.length;o++)if(this.rules.other.blockquoteStart.test(e[o]))a.push(e[o]),t=!0;else if(!t)a.push(e[o]);else break;e=e.slice(o);let s=a.join(`
|
|
13
|
+
`),c=s.replace(this.rules.other.blockquoteSetextReplace,`
|
|
14
|
+
$1`).replace(this.rules.other.blockquoteSetextReplace2,``);n=n?`${n}
|
|
15
|
+
${s}`:s,r=r?`${r}
|
|
16
|
+
${c}`:c;let l=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(c,i,!0),this.lexer.state.top=l,e.length===0)break;let u=i.at(-1);if(u?.type===`code`)break;if(u?.type===`blockquote`){let t=u,a=t.raw+`
|
|
17
|
+
`+e.join(`
|
|
18
|
+
`),o=this.blockquote(a);i[i.length-1]=o,n=n.substring(0,n.length-t.raw.length)+o.raw,r=r.substring(0,r.length-t.text.length)+o.text;break}if(u?.type===`list`){let t=u,a=t.raw+`
|
|
19
|
+
`+e.join(`
|
|
20
|
+
`),o=this.list(a);i[i.length-1]=o,n=n.substring(0,n.length-u.raw.length)+o.raw,r=r.substring(0,r.length-t.raw.length)+o.raw,e=a.substring(i.at(-1).raw.length).split(`
|
|
21
|
+
`)}}return{type:`blockquote`,raw:n,tokens:i,text:r}}}list(e){let t=this.rules.block.list.exec(e);if(t){let n=t[1].trim(),r=n.length>1,i={type:`list`,raw:``,ordered:r,start:r?+n.slice(0,-1):``,loose:!1,items:[]};n=r?`\\d{1,9}\\${n.slice(-1)}`:`\\${n}`,this.options.pedantic&&(n=r?n:`[*+-]`);let a=this.rules.other.listItemRegex(n),o=!1;for(;e;){let n=!1,r=``,s=``;if(!(t=a.exec(e))||this.rules.block.hr.test(e))break;r=t[0],e=e.substring(r.length);let c=t[2].split(`
|
|
22
|
+
`,1)[0].replace(this.rules.other.listReplaceTabs,e=>` `.repeat(3*e.length)),l=e.split(`
|
|
23
|
+
`,1)[0],u=!c.trim(),d=0;if(this.options.pedantic?(d=2,s=c.trimStart()):u?d=t[1].length+1:(d=t[2].search(this.rules.other.nonSpaceChar),d=d>4?1:d,s=c.slice(d),d+=t[1].length),u&&this.rules.other.blankLine.test(l)&&(r+=l+`
|
|
24
|
+
`,e=e.substring(l.length+1),n=!0),!n){let t=this.rules.other.nextBulletRegex(d),n=this.rules.other.hrRegex(d),i=this.rules.other.fencesBeginRegex(d),a=this.rules.other.headingBeginRegex(d),o=this.rules.other.htmlBeginRegex(d);for(;e;){let f=e.split(`
|
|
25
|
+
`,1)[0],p;if(l=f,this.options.pedantic?(l=l.replace(this.rules.other.listReplaceNesting,` `),p=l):p=l.replace(this.rules.other.tabCharGlobal,` `),i.test(l)||a.test(l)||o.test(l)||t.test(l)||n.test(l))break;if(p.search(this.rules.other.nonSpaceChar)>=d||!l.trim())s+=`
|
|
26
|
+
`+p.slice(d);else{if(u||c.replace(this.rules.other.tabCharGlobal,` `).search(this.rules.other.nonSpaceChar)>=4||i.test(c)||a.test(c)||n.test(c))break;s+=`
|
|
27
|
+
`+l}!u&&!l.trim()&&(u=!0),r+=f+`
|
|
28
|
+
`,e=e.substring(f.length+1),c=p.slice(d)}}i.loose||(o?i.loose=!0:this.rules.other.doubleBlankLine.test(r)&&(o=!0));let f=null,p;this.options.gfm&&(f=this.rules.other.listIsTask.exec(s),f&&(p=f[0]!==`[ ] `,s=s.replace(this.rules.other.listReplaceTask,``))),i.items.push({type:`list_item`,raw:r,task:!!f,checked:p,loose:!1,text:s,tokens:[]}),i.raw+=r}let s=i.items.at(-1);if(s)s.raw=s.raw.trimEnd(),s.text=s.text.trimEnd();else return;i.raw=i.raw.trimEnd();for(let e=0;e<i.items.length;e++)if(this.lexer.state.top=!1,i.items[e].tokens=this.lexer.blockTokens(i.items[e].text,[]),!i.loose){let t=i.items[e].tokens.filter(e=>e.type===`space`);i.loose=t.length>0&&t.some(e=>this.rules.other.anyLine.test(e.raw))}if(i.loose)for(let e=0;e<i.items.length;e++)i.items[e].loose=!0;return i}}html(e){let t=this.rules.block.html.exec(e);if(t)return{type:`html`,block:!0,raw:t[0],pre:t[1]===`pre`||t[1]===`script`||t[1]===`style`,text:t[0]}}def(e){let t=this.rules.block.def.exec(e);if(t){let e=t[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal,` `),n=t[2]?t[2].replace(this.rules.other.hrefBrackets,`$1`).replace(this.rules.inline.anyPunctuation,`$1`):``,r=t[3]?t[3].substring(1,t[3].length-1).replace(this.rules.inline.anyPunctuation,`$1`):t[3];return{type:`def`,tag:e,raw:t[0],href:n,title:r}}}table(e){let t=this.rules.block.table.exec(e);if(!t||!this.rules.other.tableDelimiter.test(t[2]))return;let n=Fi(t[1]),r=t[2].replace(this.rules.other.tableAlignChars,``).split(`|`),i=t[3]?.trim()?t[3].replace(this.rules.other.tableRowBlankLine,``).split(`
|
|
29
|
+
`):[],a={type:`table`,raw:t[0],header:[],align:[],rows:[]};if(n.length===r.length){for(let e of r)this.rules.other.tableAlignRight.test(e)?a.align.push(`right`):this.rules.other.tableAlignCenter.test(e)?a.align.push(`center`):this.rules.other.tableAlignLeft.test(e)?a.align.push(`left`):a.align.push(null);for(let e=0;e<n.length;e++)a.header.push({text:n[e],tokens:this.lexer.inline(n[e]),header:!0,align:a.align[e]});for(let e of i)a.rows.push(Fi(e,a.header.length).map((e,t)=>({text:e,tokens:this.lexer.inline(e),header:!1,align:a.align[t]})));return a}}lheading(e){let t=this.rules.block.lheading.exec(e);if(t)return{type:`heading`,raw:t[0],depth:t[2].charAt(0)===`=`?1:2,text:t[1],tokens:this.lexer.inline(t[1])}}paragraph(e){let t=this.rules.block.paragraph.exec(e);if(t){let e=t[1].charAt(t[1].length-1)===`
|
|
30
|
+
`?t[1].slice(0,-1):t[1];return{type:`paragraph`,raw:t[0],text:e,tokens:this.lexer.inline(e)}}}text(e){let t=this.rules.block.text.exec(e);if(t)return{type:`text`,raw:t[0],text:t[0],tokens:this.lexer.inline(t[0])}}escape(e){let t=this.rules.inline.escape.exec(e);if(t)return{type:`escape`,raw:t[0],text:t[1]}}tag(e){let t=this.rules.inline.tag.exec(e);if(t)return!this.lexer.state.inLink&&this.rules.other.startATag.test(t[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test(t[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test(t[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.test(t[0])&&(this.lexer.state.inRawBlock=!1),{type:`html`,raw:t[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:t[0]}}link(e){let t=this.rules.inline.link.exec(e);if(t){let e=t[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(e)){if(!this.rules.other.endAngleBracket.test(e))return;let t=Ii(e.slice(0,-1),`\\`);if((e.length-t.length)%2==0)return}else{let e=Li(t[2],`()`);if(e===-2)return;if(e>-1){let n=(t[0].indexOf(`!`)===0?5:4)+t[1].length+e;t[2]=t[2].substring(0,e),t[0]=t[0].substring(0,n).trim(),t[3]=``}}let n=t[2],r=``;if(this.options.pedantic){let e=this.rules.other.pedanticHrefTitle.exec(n);e&&(n=e[1],r=e[3])}else r=t[3]?t[3].slice(1,-1):``;return n=n.trim(),this.rules.other.startAngleBracket.test(n)&&(n=this.options.pedantic&&!this.rules.other.endAngleBracket.test(e)?n.slice(1):n.slice(1,-1)),Ri(t,{href:n&&n.replace(this.rules.inline.anyPunctuation,`$1`),title:r&&r.replace(this.rules.inline.anyPunctuation,`$1`)},t[0],this.lexer,this.rules)}}reflink(e,t){let n;if((n=this.rules.inline.reflink.exec(e))||(n=this.rules.inline.nolink.exec(e))){let e=t[(n[2]||n[1]).replace(this.rules.other.multipleSpaceGlobal,` `).toLowerCase()];if(!e){let e=n[0].charAt(0);return{type:`text`,raw:e,text:e}}return Ri(n,e,n[0],this.lexer,this.rules)}}emStrong(e,t,n=``){let r=this.rules.inline.emStrongLDelim.exec(e);if(r&&!(r[3]&&n.match(this.rules.other.unicodeAlphaNumeric))&&(!(r[1]||r[2])||!n||this.rules.inline.punctuation.exec(n))){let n=[...r[0]].length-1,i,a,o=n,s=0,c=r[0][0]===`*`?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(c.lastIndex=0,t=t.slice(-1*e.length+n);(r=c.exec(t))!=null;){if(i=r[1]||r[2]||r[3]||r[4]||r[5]||r[6],!i)continue;if(a=[...i].length,r[3]||r[4]){o+=a;continue}if((r[5]||r[6])&&n%3&&!((n+a)%3)){s+=a;continue}if(o-=a,o>0)continue;a=Math.min(a,a+o+s);let t=[...r[0]][0].length,c=e.slice(0,n+r.index+t+a);if(Math.min(n,a)%2){let e=c.slice(1,-1);return{type:`em`,raw:c,text:e,tokens:this.lexer.inlineTokens(e)}}let l=c.slice(2,-2);return{type:`strong`,raw:c,text:l,tokens:this.lexer.inlineTokens(l)}}}}codespan(e){let t=this.rules.inline.code.exec(e);if(t){let e=t[2].replace(this.rules.other.newLineCharGlobal,` `),n=this.rules.other.nonSpaceChar.test(e),r=this.rules.other.startingSpaceChar.test(e)&&this.rules.other.endingSpaceChar.test(e);return n&&r&&(e=e.substring(1,e.length-1)),{type:`codespan`,raw:t[0],text:e}}}br(e){let t=this.rules.inline.br.exec(e);if(t)return{type:`br`,raw:t[0]}}del(e){let t=this.rules.inline.del.exec(e);if(t)return{type:`del`,raw:t[0],text:t[2],tokens:this.lexer.inlineTokens(t[2])}}autolink(e){let t=this.rules.inline.autolink.exec(e);if(t){let e,n;return t[2]===`@`?(e=t[1],n=`mailto:`+e):(e=t[1],n=e),{type:`link`,raw:t[0],text:e,href:n,tokens:[{type:`text`,raw:e,text:e}]}}}url(e){let t;if(t=this.rules.inline.url.exec(e)){let e,n;if(t[2]===`@`)e=t[0],n=`mailto:`+e;else{let r;do r=t[0],t[0]=this.rules.inline._backpedal.exec(t[0])?.[0]??``;while(r!==t[0]);e=t[0],n=t[1]===`www.`?`http://`+t[0]:t[0]}return{type:`link`,raw:t[0],text:e,href:n,tokens:[{type:`text`,raw:e,text:e}]}}}inlineText(e){let t=this.rules.inline.text.exec(e);if(t){let e=this.lexer.state.inRawBlock;return{type:`text`,raw:t[0],text:t[0],escaped:e}}}},Vi=class e{tokens;options;state;tokenizer;inlineQueue;constructor(e){this.tokens=[],this.tokens.links=Object.create(null),this.options=e||Dr,this.options.tokenizer=this.options.tokenizer||new Bi,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};let t={other:Ar,block:ki.normal,inline:Ai.normal};this.options.pedantic?(t.block=ki.pedantic,t.inline=Ai.pedantic):this.options.gfm&&(t.block=ki.gfm,t.inline=this.options.breaks?Ai.breaks:Ai.gfm),this.tokenizer.rules=t}static get rules(){return{block:ki,inline:Ai}}static lex(t,n){return new e(n).lex(t)}static lexInline(t,n){return new e(n).inlineTokens(t)}lex(e){e=e.replace(Ar.carriageReturn,`
|
|
31
|
+
`),this.blockTokens(e,this.tokens);for(let e=0;e<this.inlineQueue.length;e++){let t=this.inlineQueue[e];this.inlineTokens(t.src,t.tokens)}return this.inlineQueue=[],this.tokens}blockTokens(e,t=[],n=!1){for(this.options.pedantic&&(e=e.replace(Ar.tabCharGlobal,` `).replace(Ar.spaceLine,``));e;){let r;if(this.options.extensions?.block?.some(n=>(r=n.call({lexer:this},e,t))?(e=e.substring(r.raw.length),t.push(r),!0):!1))continue;if(r=this.tokenizer.space(e)){e=e.substring(r.raw.length);let n=t.at(-1);r.raw.length===1&&n!==void 0?n.raw+=`
|
|
32
|
+
`:t.push(r);continue}if(r=this.tokenizer.code(e)){e=e.substring(r.raw.length);let n=t.at(-1);n?.type===`paragraph`||n?.type===`text`?(n.raw+=`
|
|
33
|
+
`+r.raw,n.text+=`
|
|
34
|
+
`+r.text,this.inlineQueue.at(-1).src=n.text):t.push(r);continue}if((r=this.tokenizer.fences(e))||(r=this.tokenizer.heading(e))||(r=this.tokenizer.hr(e))||(r=this.tokenizer.blockquote(e))||(r=this.tokenizer.list(e))||(r=this.tokenizer.html(e))){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.def(e)){e=e.substring(r.raw.length);let n=t.at(-1);n?.type===`paragraph`||n?.type===`text`?(n.raw+=`
|
|
35
|
+
`+r.raw,n.text+=`
|
|
36
|
+
`+r.raw,this.inlineQueue.at(-1).src=n.text):this.tokens.links[r.tag]||(this.tokens.links[r.tag]={href:r.href,title:r.title});continue}if((r=this.tokenizer.table(e))||(r=this.tokenizer.lheading(e))){e=e.substring(r.raw.length),t.push(r);continue}let i=e;if(this.options.extensions?.startBlock){let t=1/0,n=e.slice(1),r;this.options.extensions.startBlock.forEach(e=>{r=e.call({lexer:this},n),typeof r==`number`&&r>=0&&(t=Math.min(t,r))}),t<1/0&&t>=0&&(i=e.substring(0,t+1))}if(this.state.top&&(r=this.tokenizer.paragraph(i))){let a=t.at(-1);n&&a?.type===`paragraph`?(a.raw+=`
|
|
37
|
+
`+r.raw,a.text+=`
|
|
38
|
+
`+r.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=a.text):t.push(r),n=i.length!==e.length,e=e.substring(r.raw.length)}else if(r=this.tokenizer.text(e)){e=e.substring(r.raw.length);let n=t.at(-1);n?.type===`text`?(n.raw+=`
|
|
39
|
+
`+r.raw,n.text+=`
|
|
40
|
+
`+r.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=n.text):t.push(r)}else if(e){let t=`Infinite loop on byte: `+e.charCodeAt(0);if(this.options.silent){console.error(t);break}throw Error(t)}}return this.state.top=!0,t}inline(e,t=[]){return this.inlineQueue.push({src:e,tokens:t}),t}inlineTokens(e,t=[]){let n=e,r=null;if(this.tokens.links){let e=Object.keys(this.tokens.links);if(e.length>0)for(;(r=this.tokenizer.rules.inline.reflinkSearch.exec(n))!=null;)e.includes(r[0].slice(r[0].lastIndexOf(`[`)+1,-1))&&(n=n.slice(0,r.index)+`[`+`a`.repeat(r[0].length-2)+`]`+n.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(r=this.tokenizer.rules.inline.anyPunctuation.exec(n))!=null;)n=n.slice(0,r.index)+`++`+n.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);for(;(r=this.tokenizer.rules.inline.blockSkip.exec(n))!=null;)n=n.slice(0,r.index)+`[`+`a`.repeat(r[0].length-2)+`]`+n.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);let i=!1,a=``;for(;e;){i||(a=``),i=!1;let r;if(this.options.extensions?.inline?.some(n=>(r=n.call({lexer:this},e,t))?(e=e.substring(r.raw.length),t.push(r),!0):!1))continue;if((r=this.tokenizer.escape(e))||(r=this.tokenizer.tag(e))||(r=this.tokenizer.link(e))){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.reflink(e,this.tokens.links)){e=e.substring(r.raw.length);let n=t.at(-1);r.type===`text`&&n?.type===`text`?(n.raw+=r.raw,n.text+=r.text):t.push(r);continue}if((r=this.tokenizer.emStrong(e,n,a))||(r=this.tokenizer.codespan(e))||(r=this.tokenizer.br(e))||(r=this.tokenizer.del(e))||(r=this.tokenizer.autolink(e))||!this.state.inLink&&(r=this.tokenizer.url(e))){e=e.substring(r.raw.length),t.push(r);continue}let o=e;if(this.options.extensions?.startInline){let t=1/0,n=e.slice(1),r;this.options.extensions.startInline.forEach(e=>{r=e.call({lexer:this},n),typeof r==`number`&&r>=0&&(t=Math.min(t,r))}),t<1/0&&t>=0&&(o=e.substring(0,t+1))}if(r=this.tokenizer.inlineText(o)){e=e.substring(r.raw.length),r.raw.slice(-1)!==`_`&&(a=r.raw.slice(-1)),i=!0;let n=t.at(-1);n?.type===`text`?(n.raw+=r.raw,n.text+=r.text):t.push(r)}else if(e){let t=`Infinite loop on byte: `+e.charCodeAt(0);if(this.options.silent){console.error(t);break}throw Error(t)}}return t}},Hi=class{options;parser;constructor(e){this.options=e||Dr}space(e){return``}code({text:e,lang:t,escaped:n}){let r=(t||``).match(Ar.notSpaceStart)?.[0],i=e.replace(Ar.endingNewline,``)+`
|
|
41
|
+
`;return r?`<pre><code class="language-`+Ni(r)+`">`+(n?i:Ni(i,!0))+`</code></pre>
|
|
42
|
+
`:`<pre><code>`+(n?i:Ni(i,!0))+`</code></pre>
|
|
43
|
+
`}blockquote({tokens:e}){return`<blockquote>
|
|
44
|
+
${this.parser.parse(e)}</blockquote>
|
|
45
|
+
`}html({text:e}){return e}heading({tokens:e,depth:t}){return`<h${t}>${this.parser.parseInline(e)}</h${t}>
|
|
46
|
+
`}hr(e){return`<hr>
|
|
47
|
+
`}list(e){let t=e.ordered,n=e.start,r=``;for(let t=0;t<e.items.length;t++){let n=e.items[t];r+=this.listitem(n)}let i=t?`ol`:`ul`,a=t&&n!==1?` start="`+n+`"`:``;return`<`+i+a+`>
|
|
48
|
+
`+r+`</`+i+`>
|
|
49
|
+
`}listitem(e){let t=``;if(e.task){let n=this.checkbox({checked:!!e.checked});e.loose?e.tokens[0]?.type===`paragraph`?(e.tokens[0].text=n+` `+e.tokens[0].text,e.tokens[0].tokens&&e.tokens[0].tokens.length>0&&e.tokens[0].tokens[0].type===`text`&&(e.tokens[0].tokens[0].text=n+` `+Ni(e.tokens[0].tokens[0].text),e.tokens[0].tokens[0].escaped=!0)):e.tokens.unshift({type:`text`,raw:n+` `,text:n+` `,escaped:!0}):t+=n+` `}return t+=this.parser.parse(e.tokens,!!e.loose),`<li>${t}</li>
|
|
50
|
+
`}checkbox({checked:e}){return`<input `+(e?`checked="" `:``)+`disabled="" type="checkbox">`}paragraph({tokens:e}){return`<p>${this.parser.parseInline(e)}</p>
|
|
51
|
+
`}table(e){let t=``,n=``;for(let t=0;t<e.header.length;t++)n+=this.tablecell(e.header[t]);t+=this.tablerow({text:n});let r=``;for(let t=0;t<e.rows.length;t++){let i=e.rows[t];n=``;for(let e=0;e<i.length;e++)n+=this.tablecell(i[e]);r+=this.tablerow({text:n})}return r&&=`<tbody>${r}</tbody>`,`<table>
|
|
52
|
+
<thead>
|
|
53
|
+
`+t+`</thead>
|
|
54
|
+
`+r+`</table>
|
|
55
|
+
`}tablerow({text:e}){return`<tr>
|
|
56
|
+
${e}</tr>
|
|
57
|
+
`}tablecell(e){let t=this.parser.parseInline(e.tokens),n=e.header?`th`:`td`;return(e.align?`<${n} align="${e.align}">`:`<${n}>`)+t+`</${n}>
|
|
58
|
+
`}strong({tokens:e}){return`<strong>${this.parser.parseInline(e)}</strong>`}em({tokens:e}){return`<em>${this.parser.parseInline(e)}</em>`}codespan({text:e}){return`<code>${Ni(e,!0)}</code>`}br(e){return`<br>`}del({tokens:e}){return`<del>${this.parser.parseInline(e)}</del>`}link({href:e,title:t,tokens:n}){let r=this.parser.parseInline(n),i=Pi(e);if(i===null)return r;e=i;let a=`<a href="`+e+`"`;return t&&(a+=` title="`+Ni(t)+`"`),a+=`>`+r+`</a>`,a}image({href:e,title:t,text:n,tokens:r}){r&&(n=this.parser.parseInline(r,this.parser.textRenderer));let i=Pi(e);if(i===null)return Ni(n);e=i;let a=`<img src="${e}" alt="${n}"`;return t&&(a+=` title="${Ni(t)}"`),a+=`>`,a}text(e){return`tokens`in e&&e.tokens?this.parser.parseInline(e.tokens):`escaped`in e&&e.escaped?e.text:Ni(e.text)}},Ui=class{strong({text:e}){return e}em({text:e}){return e}codespan({text:e}){return e}del({text:e}){return e}html({text:e}){return e}text({text:e}){return e}link({text:e}){return``+e}image({text:e}){return``+e}br(){return``}},Wi=class e{options;renderer;textRenderer;constructor(e){this.options=e||Dr,this.options.renderer=this.options.renderer||new Hi,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new Ui}static parse(t,n){return new e(n).parse(t)}static parseInline(t,n){return new e(n).parseInline(t)}parse(e,t=!0){let n=``;for(let r=0;r<e.length;r++){let i=e[r];if(this.options.extensions?.renderers?.[i.type]){let e=i,t=this.options.extensions.renderers[e.type].call({parser:this},e);if(t!==!1||![`space`,`hr`,`heading`,`code`,`table`,`blockquote`,`list`,`html`,`paragraph`,`text`].includes(e.type)){n+=t||``;continue}}let a=i;switch(a.type){case`space`:n+=this.renderer.space(a);continue;case`hr`:n+=this.renderer.hr(a);continue;case`heading`:n+=this.renderer.heading(a);continue;case`code`:n+=this.renderer.code(a);continue;case`table`:n+=this.renderer.table(a);continue;case`blockquote`:n+=this.renderer.blockquote(a);continue;case`list`:n+=this.renderer.list(a);continue;case`html`:n+=this.renderer.html(a);continue;case`paragraph`:n+=this.renderer.paragraph(a);continue;case`text`:{let i=a,o=this.renderer.text(i);for(;r+1<e.length&&e[r+1].type===`text`;)i=e[++r],o+=`
|
|
59
|
+
`+this.renderer.text(i);n+=t?this.renderer.paragraph({type:`paragraph`,raw:o,text:o,tokens:[{type:`text`,raw:o,text:o,escaped:!0}]}):o;continue}default:{let e=`Token with "`+a.type+`" type was not found.`;if(this.options.silent)return console.error(e),``;throw Error(e)}}}return n}parseInline(e,t=this.renderer){let n=``;for(let r=0;r<e.length;r++){let i=e[r];if(this.options.extensions?.renderers?.[i.type]){let e=this.options.extensions.renderers[i.type].call({parser:this},i);if(e!==!1||![`escape`,`html`,`link`,`image`,`strong`,`em`,`codespan`,`br`,`del`,`text`].includes(i.type)){n+=e||``;continue}}let a=i;switch(a.type){case`escape`:n+=t.text(a);break;case`html`:n+=t.html(a);break;case`link`:n+=t.link(a);break;case`image`:n+=t.image(a);break;case`strong`:n+=t.strong(a);break;case`em`:n+=t.em(a);break;case`codespan`:n+=t.codespan(a);break;case`br`:n+=t.br(a);break;case`del`:n+=t.del(a);break;case`text`:n+=t.text(a);break;default:{let e=`Token with "`+a.type+`" type was not found.`;if(this.options.silent)return console.error(e),``;throw Error(e)}}}return n}},Gi=class{options;block;constructor(e){this.options=e||Dr}static passThroughHooks=new Set([`preprocess`,`postprocess`,`processAllTokens`]);preprocess(e){return e}postprocess(e){return e}processAllTokens(e){return e}provideLexer(){return this.block?Vi.lex:Vi.lexInline}provideParser(){return this.block?Wi.parse:Wi.parseInline}},Ki=class{defaults=Er();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=Wi;Renderer=Hi;TextRenderer=Ui;Lexer=Vi;Tokenizer=Bi;Hooks=Gi;constructor(...e){this.use(...e)}walkTokens(e,t){let n=[];for(let r of e)switch(n=n.concat(t.call(this,r)),r.type){case`table`:{let e=r;for(let r of e.header)n=n.concat(this.walkTokens(r.tokens,t));for(let r of e.rows)for(let e of r)n=n.concat(this.walkTokens(e.tokens,t));break}case`list`:{let e=r;n=n.concat(this.walkTokens(e.items,t));break}default:{let e=r;this.defaults.extensions?.childTokens?.[e.type]?this.defaults.extensions.childTokens[e.type].forEach(r=>{let i=e[r].flat(1/0);n=n.concat(this.walkTokens(i,t))}):e.tokens&&(n=n.concat(this.walkTokens(e.tokens,t)))}}return n}use(...e){let t=this.defaults.extensions||{renderers:{},childTokens:{}};return e.forEach(e=>{let n={...e};if(n.async=this.defaults.async||n.async||!1,e.extensions&&(e.extensions.forEach(e=>{if(!e.name)throw Error(`extension name required`);if(`renderer`in e){let n=t.renderers[e.name];n?t.renderers[e.name]=function(...t){let r=e.renderer.apply(this,t);return r===!1&&(r=n.apply(this,t)),r}:t.renderers[e.name]=e.renderer}if(`tokenizer`in e){if(!e.level||e.level!==`block`&&e.level!==`inline`)throw Error(`extension level must be 'block' or 'inline'`);let n=t[e.level];n?n.unshift(e.tokenizer):t[e.level]=[e.tokenizer],e.start&&(e.level===`block`?t.startBlock?t.startBlock.push(e.start):t.startBlock=[e.start]:e.level===`inline`&&(t.startInline?t.startInline.push(e.start):t.startInline=[e.start]))}`childTokens`in e&&e.childTokens&&(t.childTokens[e.name]=e.childTokens)}),n.extensions=t),e.renderer){let t=this.defaults.renderer||new Hi(this.defaults);for(let n in e.renderer){if(!(n in t))throw Error(`renderer '${n}' does not exist`);if([`options`,`parser`].includes(n))continue;let r=n,i=e.renderer[r],a=t[r];t[r]=(...e)=>{let n=i.apply(t,e);return n===!1&&(n=a.apply(t,e)),n||``}}n.renderer=t}if(e.tokenizer){let t=this.defaults.tokenizer||new Bi(this.defaults);for(let n in e.tokenizer){if(!(n in t))throw Error(`tokenizer '${n}' does not exist`);if([`options`,`rules`,`lexer`].includes(n))continue;let r=n,i=e.tokenizer[r],a=t[r];t[r]=(...e)=>{let n=i.apply(t,e);return n===!1&&(n=a.apply(t,e)),n}}n.tokenizer=t}if(e.hooks){let t=this.defaults.hooks||new Gi;for(let n in e.hooks){if(!(n in t))throw Error(`hook '${n}' does not exist`);if([`options`,`block`].includes(n))continue;let r=n,i=e.hooks[r],a=t[r];t[r]=Gi.passThroughHooks.has(n)?e=>{if(this.defaults.async)return Promise.resolve(i.call(t,e)).then(e=>a.call(t,e));let n=i.call(t,e);return a.call(t,n)}:(...e)=>{let n=i.apply(t,e);return n===!1&&(n=a.apply(t,e)),n}}n.hooks=t}if(e.walkTokens){let t=this.defaults.walkTokens,r=e.walkTokens;n.walkTokens=function(e){let n=[];return n.push(r.call(this,e)),t&&(n=n.concat(t.call(this,e))),n}}this.defaults={...this.defaults,...n}}),this}setOptions(e){return this.defaults={...this.defaults,...e},this}lexer(e,t){return Vi.lex(e,t??this.defaults)}parser(e,t){return Wi.parse(e,t??this.defaults)}parseMarkdown(e){return(t,n)=>{let r={...n},i={...this.defaults,...r},a=this.onError(!!i.silent,!!i.async);if(this.defaults.async===!0&&r.async===!1)return a(Error(`marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise.`));if(t==null)return a(Error(`marked(): input parameter is undefined or null`));if(typeof t!=`string`)return a(Error(`marked(): input parameter is of type `+Object.prototype.toString.call(t)+`, string expected`));i.hooks&&(i.hooks.options=i,i.hooks.block=e);let o=i.hooks?i.hooks.provideLexer():e?Vi.lex:Vi.lexInline,s=i.hooks?i.hooks.provideParser():e?Wi.parse:Wi.parseInline;if(i.async)return Promise.resolve(i.hooks?i.hooks.preprocess(t):t).then(e=>o(e,i)).then(e=>i.hooks?i.hooks.processAllTokens(e):e).then(e=>i.walkTokens?Promise.all(this.walkTokens(e,i.walkTokens)).then(()=>e):e).then(e=>s(e,i)).then(e=>i.hooks?i.hooks.postprocess(e):e).catch(a);try{i.hooks&&(t=i.hooks.preprocess(t));let e=o(t,i);i.hooks&&(e=i.hooks.processAllTokens(e)),i.walkTokens&&this.walkTokens(e,i.walkTokens);let n=s(e,i);return i.hooks&&(n=i.hooks.postprocess(n)),n}catch(e){return a(e)}}}onError(e,t){return n=>{if(n.message+=`
|
|
60
|
+
Please report this to https://github.com/markedjs/marked.`,e){let e=`<p>An error occurred:</p><pre>`+Ni(n.message+``,!0)+`</pre>`;return t?Promise.resolve(e):e}if(t)return Promise.reject(n);throw n}}},qi=new Ki;function K(e,t){return qi.parse(e,t)}K.options=K.setOptions=function(e){return qi.setOptions(e),K.defaults=qi.defaults,Or(K.defaults),K},K.getDefaults=Er,K.defaults=Dr,K.use=function(...e){return qi.use(...e),K.defaults=qi.defaults,Or(K.defaults),K},K.walkTokens=function(e,t){return qi.walkTokens(e,t)},K.parseInline=qi.parseInline,K.Parser=Wi,K.parser=Wi.parse,K.Renderer=Hi,K.TextRenderer=Ui,K.Lexer=Vi,K.lexer=Vi.lex,K.Tokenizer=Bi,K.Hooks=Gi,K.parse=K,K.options,K.setOptions,K.use,K.walkTokens,K.parseInline,Wi.parse,Vi.lex;function Ji(e,t){this.v=e,this.k=t}function Yi(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function Xi(e){if(Array.isArray(e))return e}function Zi(e,t){var n=e==null?null:typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`];if(n!=null){var r,i,a,o,s=[],c=!0,l=!1;try{if(a=(n=n.call(e)).next,t===0){if(Object(n)!==n)return;c=!1}else for(;!(c=(r=a.call(n)).done)&&(s.push(r.value),s.length!==t);c=!0);}catch(e){l=!0,i=e}finally{try{if(!c&&n.return!=null&&(o=n.return(),Object(o)!==o))return}finally{if(l)throw i}}return s}}function Qi(){throw TypeError(`Invalid attempt to destructure non-iterable instance.
|
|
61
|
+
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function $i(e,t){return Xi(e)||Zi(e,t)||ea(e,t)||Qi()}function ea(e,t){if(e){if(typeof e==`string`)return Yi(e,t);var n={}.toString.call(e).slice(8,-1);return n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`?Array.from(e):n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?Yi(e,t):void 0}}function ta(e){var t,n;function r(t,n){try{var a=e[t](n),o=a.value,s=o instanceof Ji;Promise.resolve(s?o.v:o).then(function(n){if(s){var c=t===`return`&&o.k?t:`next`;if(!o.k||n.done)return r(c,n);n=e[c](n).value}i(!!a.done,n)},function(e){r(`throw`,e)})}catch(e){i(2,e)}}function i(e,i){e===2?t.reject(i):t.resolve({value:i,done:e}),(t=t.next)?r(t.key,t.arg):n=null}this._invoke=function(e,i){return new Promise(function(a,o){var s={key:e,arg:i,resolve:a,reject:o,next:null};n?n=n.next=s:(t=n=s,r(e,i))})},typeof e.return!=`function`&&(this.return=void 0)}ta.prototype[typeof Symbol==`function`&&Symbol.asyncIterator||`@@asyncIterator`]=function(){return this},ta.prototype.next=function(e){return this._invoke(`next`,e)},ta.prototype.throw=function(e){return this._invoke(`throw`,e)},ta.prototype.return=function(e){return this._invoke(`return`,e)};var na=Object.entries,ra=Object.setPrototypeOf,ia=Object.isFrozen,aa=Object.getPrototypeOf,oa=Object.getOwnPropertyDescriptor,sa=Object.freeze,q=Object.seal,ca=Object.create,la=typeof Reflect<`u`&&Reflect,J=la.apply,ua=la.construct;sa||=function(e){return e},q||=function(e){return e},J||=function(e,t){var n=[...arguments].slice(2);return e.apply(t,n)},ua||=function(e){return new e(...[...arguments].slice(1))};var da=Y(Array.prototype.forEach);Array.prototype.indexOf;var fa=Y(Array.prototype.lastIndexOf),pa=Y(Array.prototype.pop),ma=Y(Array.prototype.push),ha=Y(Array.prototype.slice),ga=Y(Array.prototype.splice),_a=Array.isArray,va=Fa(Set),ya=Y(Set.prototype.add),ba=Y(Set.prototype.has),xa=Y(String.prototype.toLowerCase),Sa=Y(String.prototype.toString),Ca=Y(String.prototype.match),wa=Y(String.prototype.replace),Ta=Y(String.prototype.indexOf),Ea=Y(String.prototype.trim),Da=Y(Number.prototype.toString),Oa=Y(Boolean.prototype.toString),ka=typeof BigInt>`u`?null:Y(BigInt.prototype.toString),Aa=typeof Symbol>`u`?null:Y(Symbol.prototype.toString),ja=Y(Object.prototype.hasOwnProperty),Ma=Y(Object.prototype.toString),Na=Y(RegExp.prototype.test),Pa=Fa(TypeError);function Y(e){return function(t){t instanceof RegExp&&(t.lastIndex=0);var n=[...arguments].slice(1);return J(e,t,n)}}function Fa(e){return function(){return ua(e,[...arguments])}}function X(e,t){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:xa;if(ra&&ra(e,null),!_a(t))return e;let r=t.length;for(;r--;){let i=t[r];if(typeof i==`string`){let e=n(i);e!==i&&(ia(t)||(t[r]=e),i=e)}e[i]=!0}return e}function Ia(e){for(let t=0;t<e.length;t++)ja(e,t)||(e[t]=null);return e}function La(e){let t=ca(null);for(let r of na(e)){var n=$i(r,2);let i=n[0],a=n[1];ja(e,i)&&(t[i]=_a(a)?Ia(a):a&&typeof a==`object`&&a.constructor===Object?La(a):a)}return t}function Ra(e){switch(typeof e){case`string`:return e;case`number`:return Da(e);case`boolean`:return Oa(e);case`bigint`:return ka?ka(e):`0`;case`symbol`:return Aa?Aa(e):`Symbol()`;case`undefined`:return Ma(e);case`function`:case`object`:{if(e===null)return Ma(e);let t=e,n=za(t,`toString`);if(typeof n==`function`){let e=n(t);return typeof e==`string`?e:Ma(e)}return Ma(e)}default:return Ma(e)}}function za(e,t){for(;e!==null;){let n=oa(e,t);if(n){if(n.get)return Y(n.get);if(typeof n.value==`function`)return Y(n.value)}e=aa(e)}function n(){return null}return n}function Ba(e,t){for(;e!==null;){let n=oa(e,t);if(n)return n.get?Y(n.get):null;e=aa(e)}return null}function Va(e){try{return Na(e,``),!0}catch{return!1}}var Ha=sa(`a.abbr.acronym.address.area.article.aside.audio.b.bdi.bdo.big.blink.blockquote.body.br.button.canvas.caption.center.cite.code.col.colgroup.content.data.datalist.dd.decorator.del.details.dfn.dialog.dir.div.dl.dt.element.em.fieldset.figcaption.figure.font.footer.form.h1.h2.h3.h4.h5.h6.head.header.hgroup.hr.html.i.img.input.ins.kbd.label.legend.li.main.map.mark.marquee.menu.menuitem.meter.nav.nobr.ol.optgroup.option.output.p.picture.pre.progress.q.rp.rt.ruby.s.samp.search.section.select.shadow.slot.small.source.spacer.span.strike.strong.style.sub.summary.sup.table.tbody.td.template.textarea.tfoot.th.thead.time.tr.track.tt.u.ul.var.video.wbr`.split(`.`)),Ua=sa(`svg.a.altglyph.altglyphdef.altglyphitem.animatecolor.animatemotion.animatetransform.circle.clippath.defs.desc.ellipse.enterkeyhint.exportparts.filter.font.g.glyph.glyphref.hkern.image.inputmode.line.lineargradient.marker.mask.metadata.mpath.part.path.pattern.polygon.polyline.radialgradient.rect.stop.style.switch.symbol.text.textpath.title.tref.tspan.view.vkern`.split(`.`)),Wa=sa([`feBlend`,`feColorMatrix`,`feComponentTransfer`,`feComposite`,`feConvolveMatrix`,`feDiffuseLighting`,`feDisplacementMap`,`feDistantLight`,`feDropShadow`,`feFlood`,`feFuncA`,`feFuncB`,`feFuncG`,`feFuncR`,`feGaussianBlur`,`feImage`,`feMerge`,`feMergeNode`,`feMorphology`,`feOffset`,`fePointLight`,`feSpecularLighting`,`feSpotLight`,`feTile`,`feTurbulence`]),Ga=sa([`animate`,`color-profile`,`cursor`,`discard`,`font-face`,`font-face-format`,`font-face-name`,`font-face-src`,`font-face-uri`,`foreignobject`,`hatch`,`hatchpath`,`mesh`,`meshgradient`,`meshpatch`,`meshrow`,`missing-glyph`,`script`,`set`,`solidcolor`,`unknown`,`use`]),Ka=sa(`math.menclose.merror.mfenced.mfrac.mglyph.mi.mlabeledtr.mmultiscripts.mn.mo.mover.mpadded.mphantom.mroot.mrow.ms.mspace.msqrt.mstyle.msub.msup.msubsup.mtable.mtd.mtext.mtr.munder.munderover.mprescripts`.split(`.`)),qa=sa([`maction`,`maligngroup`,`malignmark`,`mlongdiv`,`mscarries`,`mscarry`,`msgroup`,`mstack`,`msline`,`msrow`,`semantics`,`annotation`,`annotation-xml`,`mprescripts`,`none`]),Ja=sa([`#text`]),Ya=sa(`accept.action.align.alt.autocapitalize.autocomplete.autopictureinpicture.autoplay.background.bgcolor.border.capture.cellpadding.cellspacing.checked.cite.class.clear.color.cols.colspan.command.commandfor.controls.controlslist.coords.crossorigin.datetime.decoding.default.dir.disabled.disablepictureinpicture.disableremoteplayback.download.draggable.enctype.enterkeyhint.exportparts.face.for.headers.height.hidden.high.href.hreflang.id.inert.inputmode.integrity.ismap.kind.label.lang.list.loading.loop.low.max.maxlength.media.method.min.minlength.multiple.muted.name.nonce.noshade.novalidate.nowrap.open.optimum.part.pattern.placeholder.playsinline.popover.popovertarget.popovertargetaction.poster.preload.pubdate.radiogroup.readonly.rel.required.rev.reversed.role.rows.rowspan.spellcheck.scope.selected.shape.size.sizes.slot.span.srclang.start.src.srcset.step.style.summary.tabindex.title.translate.type.usemap.valign.value.width.wrap.xmlns`.split(`.`)),Xa=sa(`accent-height.accumulate.additive.alignment-baseline.amplitude.ascent.attributename.attributetype.azimuth.basefrequency.baseline-shift.begin.bias.by.class.clip.clippathunits.clip-path.clip-rule.color.color-interpolation.color-interpolation-filters.color-profile.color-rendering.cx.cy.d.dx.dy.diffuseconstant.direction.display.divisor.dominant-baseline.dur.edgemode.elevation.end.exponent.fill.fill-opacity.fill-rule.filter.filterunits.flood-color.flood-opacity.font-family.font-size.font-size-adjust.font-stretch.font-style.font-variant.font-weight.fx.fy.g1.g2.glyph-name.glyphref.gradientunits.gradienttransform.height.href.id.image-rendering.in.in2.intercept.k.k1.k2.k3.k4.kerning.keypoints.keysplines.keytimes.lang.lengthadjust.letter-spacing.kernelmatrix.kernelunitlength.lighting-color.local.marker-end.marker-mid.marker-start.markerheight.markerunits.markerwidth.maskcontentunits.maskunits.max.mask.mask-type.media.method.mode.min.name.numoctaves.offset.operator.opacity.order.orient.orientation.origin.overflow.paint-order.path.pathlength.patterncontentunits.patterntransform.patternunits.pointer-events.points.preservealpha.preserveaspectratio.primitiveunits.r.rx.ry.radius.refx.refy.repeatcount.repeatdur.restart.result.rotate.scale.seed.shape-rendering.slope.specularconstant.specularexponent.spreadmethod.startoffset.stddeviation.stitchtiles.stop-color.stop-opacity.stroke-dasharray.stroke-dashoffset.stroke-linecap.stroke-linejoin.stroke-miterlimit.stroke-opacity.stroke.stroke-width.style.surfacescale.systemlanguage.tabindex.tablevalues.targetx.targety.transform.transform-origin.text-anchor.text-decoration.text-orientation.text-rendering.textlength.type.u1.u2.unicode.values.vector-effect.viewbox.visibility.version.vert-adv-y.vert-origin-x.vert-origin-y.width.word-spacing.wrap.writing-mode.xchannelselector.ychannelselector.x.x1.x2.xmlns.y.y1.y2.z.zoomandpan`.split(`.`)),Za=sa(`accent.accentunder.align.bevelled.close.columnalign.columnlines.columnspacing.columnspan.denomalign.depth.dir.display.displaystyle.encoding.fence.frame.height.href.id.largeop.length.linethickness.lquote.lspace.mathbackground.mathcolor.mathsize.mathvariant.maxsize.minsize.movablelimits.notation.numalign.open.rowalign.rowlines.rowspacing.rowspan.rspace.rquote.scriptlevel.scriptminsize.scriptsizemultiplier.selection.separator.separators.stretchy.subscriptshift.supscriptshift.symmetric.voffset.width.xmlns`.split(`.`)),Qa=sa([`xlink:href`,`xml:id`,`xlink:title`,`xml:space`,`xmlns:xlink`]),$a=q(/{{[\w\W]*|^[\w\W]*}}/g),eo=q(/<%[\w\W]*|^[\w\W]*%>/g),to=q(/\${[\w\W]*/g),no=q(/^data-[\-\w.\u00B7-\uFFFF]+$/),ro=q(/^aria-[\-\w]+$/),io=q(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),ao=q(/^(?:\w+script|data):/i),oo=q(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),so=q(/^html$/i),co=q(/^[a-z][.\w]*(-[.\w]+)+$/i),lo=q(/<[/\w!]/g),uo=q(/<[/\w]/g),fo=q(/<\/no(script|embed|frames)/i),po=q(/\/>/i),mo={element:1,attribute:2,text:3,cdataSection:4,entityReference:5,entityNode:6,processingInstruction:7,comment:8,document:9,documentType:10,documentFragment:11,notation:12},ho=sa(X({},[`style`,`script`,`xmp`,`iframe`,`noembed`,`noframes`,`plaintext`,`noscript`])),go=function(){return typeof window>`u`?null:window},_o=function(e,t){if(typeof e!=`object`||typeof e.createPolicy!=`function`)return null;let n=null,r=`data-tt-policy-suffix`;t&&t.hasAttribute(r)&&(n=t.getAttribute(r));let i=`dompurify`+(n?`#`+n:``);try{return e.createPolicy(i,{createHTML(e){return e},createScriptURL(e){return e}})}catch{return console.warn(`TrustedTypes policy `+i+` could not be created.`),null}},vo=function(){return{afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}},yo=function(e,t,n,r){return ja(e,t)&&_a(e[t])?X(r.base?La(r.base):{},e[t],r.transform):n},bo=function(e,t,n){let r=ja(e,t)?e[t]:void 0;return r&&typeof r==`object`?La(r):n()};function xo(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:go(),t=e=>xo(e);if(t.version=`3.4.17`,t.removed=[],!e||!e.document||e.document.nodeType!==mo.document||!e.Element)return t.isSupported=!1,t;let n=e.document,r=n,i=r.currentScript;e.DocumentFragment;let a=e.HTMLTemplateElement,o=e.Node,s=e.Element,c=e.NodeFilter;e.NamedNodeMap===void 0&&(e.NamedNodeMap||e.MozNamedAttrMap),e.HTMLFormElement;let l=e.DOMParser,u=e.trustedTypes,d=s.prototype,f=za(d,`cloneNode`),p=za(d,`remove`),m=za(d,`removeAttributeNode`),h=za(d,`nextSibling`),g=za(d,`childNodes`),_=za(d,`parentNode`),v=za(d,`shadowRoot`),y=za(d,`attributes`),b=o&&o.prototype?za(o.prototype,`nodeType`):null,x=o&&o.prototype?za(o.prototype,`nodeName`):null,S=o&&o.prototype?za(o.prototype,`ownerDocument`):null,C=function(e){return b?b(e):e.nodeType},w=function(e){return x?x(e):e.nodeName},ee=Ba(d,`namespaceURI`),T=function(e){return ee?ee(e):e.namespaceURI};if(typeof a==`function`){let e=n.createElement(`template`);e.content&&e.content.ownerDocument&&(n=e.content.ownerDocument)}let E,D=``,te,ne=!1,O=0,re=function(){if(O>0)throw Pa(`A configured TRUSTED_TYPES_POLICY callback (createHTML or createScriptURL) must not call DOMPurify.sanitize, as that causes infinite recursion. Do not pass a policy whose callbacks wrap DOMPurify as TRUSTED_TYPES_POLICY; see the "DOMPurify and Trusted Types" section of the README.`)},k=function(e){re(),O++;try{return E.createHTML(e)}finally{O--}},A=function(e){re(),O++;try{return E.createScriptURL(e)}finally{O--}},j=function(){return ne||=(te=_o(u,i),!0),te},M=n,ie=M.implementation,N=M.createNodeIterator,ae=M.createDocumentFragment,oe=M.getElementsByTagName,se=r.importNode,P=vo();t.isSupported=typeof na==`function`&&typeof _==`function`&&ie&&ie.createHTMLDocument!==void 0;let ce=$a,le=eo,ue=to,de=no,fe=ro,F=ao,pe=oo,me=co,he=io,I=null,ge=X({},[...Ha,...Ua,...Wa,...Ka,...Ja]),L=null,_e=X({},[...Ya,...Xa,...Za,...Qa]),ve=Object.seal(ca(null,{tagNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},allowCustomizedBuiltInElements:{writable:!0,configurable:!1,enumerable:!0,value:!1}})),ye=null,be=null,xe=Object.seal(ca(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}})),Se=!0,Ce=!0,we=!1,Te=!0,Ee=!1,De=!0,Oe=!1,ke=!1,Ae=null,je=null,Me=!1,Ne=!1,Pe=!1,Fe=!1,Ie=!0,Le=!1,Re=`user-content-`,ze=!0,Be=!1,Ve=null,He={},Ue=null,We=X({},`annotation-xml.audio.colgroup.desc.foreignobject.head.iframe.math.mi.mn.mo.ms.mtext.noembed.noframes.noscript.plaintext.script.selectedcontent.style.svg.template.thead.title.video.xmp`.split(`.`)),Ge=null,Ke=X({},[`audio`,`video`,`img`,`source`,`image`,`track`]),qe=null,Je=X({},[`alt`,`class`,`for`,`id`,`label`,`name`,`pattern`,`placeholder`,`role`,`summary`,`title`,`value`,`style`,`xmlns`]),Ye=`http://www.w3.org/1998/Math/MathML`,Xe=`http://www.w3.org/2000/svg`,Ze=`http://www.w3.org/1999/xhtml`,Qe=Ze,$e=!1,et=null,tt=X({},[Ye,Xe,Ze],Sa),nt=sa([`mi`,`mo`,`mn`,`ms`,`mtext`]),rt=X({},nt),it=sa([`annotation-xml`]),at=X({},it),ot=X({},[`title`,`style`,`font`,`a`,`script`]),st=null,ct=[`application/xhtml+xml`,`text/html`],R=null,lt=null,ut=n.createElement(`form`),dt=function(e){return e instanceof RegExp||e instanceof Function},ft=function(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(lt&<===e)return;(!e||typeof e!=`object`)&&(e={}),e=La(e),st=ct.indexOf(e.PARSER_MEDIA_TYPE)===-1?`text/html`:e.PARSER_MEDIA_TYPE,R=st===`application/xhtml+xml`?Sa:xa,I=yo(e,`ALLOWED_TAGS`,ge,{transform:R}),L=yo(e,`ALLOWED_ATTR`,_e,{transform:R}),et=yo(e,`ALLOWED_NAMESPACES`,tt,{transform:Sa}),qe=yo(e,`ADD_URI_SAFE_ATTR`,Je,{transform:R,base:Je}),Ge=yo(e,`ADD_DATA_URI_TAGS`,Ke,{transform:R,base:Ke}),Ue=yo(e,`FORBID_CONTENTS`,We,{transform:R}),ye=yo(e,`FORBID_TAGS`,La({}),{transform:R}),be=yo(e,`FORBID_ATTR`,La({}),{transform:R}),He=ja(e,`USE_PROFILES`)?e.USE_PROFILES&&typeof e.USE_PROFILES==`object`?La(e.USE_PROFILES):e.USE_PROFILES:!1,Se=e.ALLOW_ARIA_ATTR!==!1,Ce=e.ALLOW_DATA_ATTR!==!1,we=e.ALLOW_UNKNOWN_PROTOCOLS||!1,Te=e.ALLOW_SELF_CLOSE_IN_ATTR!==!1,Ee=e.SAFE_FOR_TEMPLATES||!1,De=e.SAFE_FOR_XML!==!1,Oe=e.WHOLE_DOCUMENT||!1,Ne=e.RETURN_DOM||!1,Pe=e.RETURN_DOM_FRAGMENT||!1,Fe=e.RETURN_TRUSTED_TYPE||!1,Me=e.FORCE_BODY||!1,Ie=e.SANITIZE_DOM!==!1,Le=e.SANITIZE_NAMED_PROPS||!1,ze=e.KEEP_CONTENT!==!1,Be=e.IN_PLACE||!1,he=Va(e.ALLOWED_URI_REGEXP)?e.ALLOWED_URI_REGEXP:io,Qe=typeof e.NAMESPACE==`string`?e.NAMESPACE:Ze,rt=bo(e,`MATHML_TEXT_INTEGRATION_POINTS`,()=>X({},nt)),at=bo(e,`HTML_INTEGRATION_POINTS`,()=>X({},it));let t=bo(e,`CUSTOM_ELEMENT_HANDLING`,()=>ca(null));if(ve=ca(null),ja(t,`tagNameCheck`)&&dt(t.tagNameCheck)&&(ve.tagNameCheck=t.tagNameCheck),ja(t,`attributeNameCheck`)&&dt(t.attributeNameCheck)&&(ve.attributeNameCheck=t.attributeNameCheck),ja(t,`allowCustomizedBuiltInElements`)&&typeof t.allowCustomizedBuiltInElements==`boolean`&&(ve.allowCustomizedBuiltInElements=t.allowCustomizedBuiltInElements),q(ve),Ee&&(Ce=!1),Pe&&(Ne=!0),He&&(I=X({},Ja),L=ca(null),He.html===!0&&(X(I,Ha),X(L,Ya)),He.svg===!0&&(X(I,Ua),X(L,Xa),X(L,Qa)),He.svgFilters===!0&&(X(I,Wa),X(L,Xa),X(L,Qa)),He.mathMl===!0&&(X(I,Ka),X(L,Za),X(L,Qa))),xe.tagCheck=null,xe.attributeCheck=null,ja(e,`ADD_TAGS`)&&(typeof e.ADD_TAGS==`function`?xe.tagCheck=e.ADD_TAGS:_a(e.ADD_TAGS)&&(I===ge&&(I=La(I)),X(I,e.ADD_TAGS,R))),ja(e,`ADD_ATTR`)&&(typeof e.ADD_ATTR==`function`?xe.attributeCheck=e.ADD_ATTR:_a(e.ADD_ATTR)&&(L===_e&&(L=La(L)),X(L,e.ADD_ATTR,R))),ja(e,`ADD_FORBID_CONTENTS`)&&_a(e.ADD_FORBID_CONTENTS)&&(Ue===We&&(Ue=La(Ue)),X(Ue,e.ADD_FORBID_CONTENTS,R)),ze&&(I[`#text`]=!0),Oe&&X(I,[`html`,`head`,`body`]),I.table&&(X(I,[`tbody`]),delete ye.tbody),e.TRUSTED_TYPES_POLICY){if(typeof e.TRUSTED_TYPES_POLICY.createHTML!=`function`)throw Pa(`TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.`);if(typeof e.TRUSTED_TYPES_POLICY.createScriptURL!=`function`)throw Pa(`TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.`);let t=E;E=e.TRUSTED_TYPES_POLICY;try{D=k(``)}catch(e){throw E=t,e}}else e.TRUSTED_TYPES_POLICY===null?(E=void 0,D=``):(E===void 0&&(E=j()),E&&typeof D==`string`&&(D=k(``)));sa&&sa(e),lt=e},pt=X({},[...Ua,...Wa,...Ga]),mt=X({},[...Ka,...qa]),ht=function(e,t,n){return t.namespaceURI===Ze?e===`svg`:t.namespaceURI===Ye?e===`svg`&&(n===`annotation-xml`||rt[n]):!!pt[e]},gt=function(e,t,n){return t.namespaceURI===Ze?e===`math`:t.namespaceURI===Xe?e===`math`&&at[n]:!!mt[e]},_t=function(e,t,n){return t.namespaceURI===Xe&&!at[n]||t.namespaceURI===Ye&&!rt[n]?!1:!mt[e]&&(ot[e]||!pt[e])},vt=function(e){let t=T(e),n=xa(w(e)),r=_(e),i,a;return r&&C(r)===mo.element?(i={namespaceURI:T(r)},a=xa(w(r))):(i={namespaceURI:Qe},a=`template`),et[t]?t===Xe?ht(n,i,a):t===Ye?gt(n,i,a):t===Ze?_t(n,i,a):!!(st===`application/xhtml+xml`&&et[t]):!1},yt=function(e){ma(t.removed,{element:e});try{_(e).removeChild(e)}catch{if(p(e),!_(e))throw Pa(`a node selected for removal could not be detached from its tree and cannot be safely returned; refusing to sanitize in place`)}},bt=function(e,t,n){try{m(e,t)}catch{try{e.removeAttribute(n)}catch{}}},xt=function(e){Tt(e);let t=g(e);t&&da(ha(t),e=>{try{p(e)}catch{}});let n=C(e)===mo.element?y(e):null;if(n)for(let t=n.length-1;t>=0;--t){let r=n[t],i=r&&r.name;typeof i==`string`&&bt(e,r,i)}},St=function(e,n,r){if(!r)try{r=n.getAttributeNode(e)}catch{r=null}ma(t.removed,{attribute:r||null,from:n});try{r?m(n,r):n.removeAttribute(e)}catch{try{n.removeAttribute(e)}catch{}}if(e===`is`){if(Ne||Pe)try{yt(n)}catch{}else try{n.setAttribute(e,``)}catch{}}},Ct=function(e){let t=y(e);if(t)for(let n=t.length-1;n>=0;--n){let r=t[n],i=r&&r.name;typeof i!=`string`||L[R(i)]||bt(e,r,i)}},wt=function(e,t){let n=arguments.length>2&&arguments[2]!==void 0&&arguments[2],r=[e];for(;r.length>0;){let e=r.pop();if(t(e)===!1)continue;if(n&&C(e)===mo.element){let t=v(e);Bt(t)&&r.push(t)}let i=g(e);if(i)for(let e=i.length-1;e>=0;--e)r.push(i[e])}},Tt=function(e){wt(e,e=>{C(e)===mo.element&&Ct(e)})},Et=function(e){let t=[];return wt(e,e=>{t.push(e)},!0),t},Dt=function(e,t){let n=va();da(Et(e),e=>{C(e)===mo.element&&ya(n,e)}),da(t,e=>{C(e)===mo.element&&!ba(n,e)&&Ct(e)})},Ot=function(e,n){let r=!1;return da(t.removed,t=>{t.element&&(r||=t.element===e,Tt(t.element))}),Dt(e,n),r},kt=function(e,t){let n=Ve,r=null,i=()=>(r||(r=va(),da(t,e=>{ya(r,e)})),r);for(let t=0;;t++){let r=Et(e),a=[e],o=!1;if(da(r,e=>{C(e)===mo.documentFragment?ma(a,e):!o&&!ba(n,e)&&(o=ba(i(),e))}),!o)return;if(t>=8)throw Pa(`the tree kept changing during in-place sanitization; refusing to return it`);da(a,(t,n)=>{At(t,n>0,e,i())})}},At=function(e,t,n,r){let i=Ft(e),a;for(;a=i.nextNode();)ba(r,a)&&!ba(Ve,a)&&(t&&Ht(P.uponSanitizeShadowNode,a,null),Jt(a,n),tn(a,n),Bt(a.content)&&nn(a.content))},jt=function(e){Ve&&ya(Ve,e)},Mt=function(e,t){return De?e===`patchsrc`||e===`for`&&t!==`label`&&t!==`output`:!1},Nt=function(e){De&&wt(e,e=>{let t=C(e);if(t===mo.processingInstruction||t===mo.comment&&Na(uo,e.data)){try{p(e)}catch{}return!1}if(t===mo.element){let t=e,n=R(w(e));try{t.hasAttribute&&t.hasAttribute(`patchsrc`)&&t.removeAttribute(`patchsrc`),t.hasAttribute&&t.hasAttribute(`for`)&&Mt(`for`,n)&&t.removeAttribute(`for`)}catch{}}return!0})},Pt=function(e){let t=null,r=null;if(Me)e=`<remove></remove>`+e;else{let t=Ca(e,/^[\r\n\t ]+/);r=t&&t[0]}st===`application/xhtml+xml`&&Qe===Ze&&(e=`<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>`+e+`</body></html>`);let i=E?k(e):e;if(Qe===Ze)try{t=new l().parseFromString(i,st)}catch{}if(!t||!t.documentElement){t=ie.createDocument(Qe,`template`,null);try{t.documentElement.innerHTML=$e?D:i}catch{}}let a=t.body||t.documentElement;return e&&r&&a.insertBefore(n.createTextNode(r),a.childNodes[0]||null),Qe===Ze?oe.call(t,Oe?`html`:`body`)[0]:Oe?t.documentElement:a},Ft=function(e){let t=S?S(e):e.ownerDocument;return N.call(t||e,e,c.SHOW_ELEMENT|c.SHOW_COMMENT|c.SHOW_TEXT|c.SHOW_PROCESSING_INSTRUCTION|c.SHOW_CDATA_SECTION,null)},It=function(e){return e=wa(e,ce,` `),e=wa(e,le,` `),e=wa(e,ue,` `),e},Lt=function(e){Rt(e);let t=e.querySelectorAll?.call(e,`template`);t&&da(t,e=>{Bt(e.content)&&Lt(e.content)})},Rt=function(e){e.normalize();let t=S?S(e):e.ownerDocument,n=N.call(t||e,e,c.SHOW_TEXT|c.SHOW_COMMENT|c.SHOW_CDATA_SECTION|c.SHOW_PROCESSING_INSTRUCTION,null),r=n.nextNode();for(;r;)r.data=It(r.data),r=n.nextNode()},zt=function(e){let t=x?x(e):null;return typeof t!=`string`||R(t)!==`form`?!1:typeof e.nodeName!=`string`||typeof e.textContent!=`string`||typeof e.removeChild!=`function`||e.attributes!==y(e)||typeof e.removeAttribute!=`function`||typeof e.removeAttributeNode!=`function`||typeof e.getAttributeNode!=`function`||typeof e.setAttribute!=`function`||typeof e.namespaceURI!=`string`||typeof e.insertBefore!=`function`||typeof e.hasChildNodes!=`function`||e.nodeType!==b(e)||e.childNodes!==g(e)},Bt=function(e){if(!b||typeof e!=`object`||!e)return!1;try{return b(e)===mo.documentFragment}catch{return!1}},Vt=function(e){if(!b||typeof e!=`object`||!e)return!1;try{return typeof b(e)==`number`}catch{return!1}};function Ht(e,n,r){e.length!==0&&da(e,e=>{e.call(t,n,r,lt)})}let Ut=function(e,t){return!!(De&&e.hasChildNodes()&&!Vt(e.firstElementChild)&&Na(lo,e.textContent)&&Na(lo,e.innerHTML)||De&&ho[t]&&C(e)===mo.element&&T(e)===Ze&&(Vt(e.firstElementChild)||typeof e.textContent==`string`&&Na(lo,e.textContent))||e.nodeType===mo.processingInstruction||De&&e.nodeType===mo.comment&&Na(uo,e.data))},Wt=function(e,t){return e instanceof RegExp?Na(e,t):e instanceof Function&&!!e(t,...[...arguments].slice(2))},Gt=function(e,t,n){if(!ye[t]&&Zt(t)&&Wt(ve.tagNameCheck,t))return!1;if(ze&&!Ue[t]&&!Ue[xa(t)]){let t=_(e),r=g(e);if(r&&t){let i=r.length;for(let a=i-1;a>=0;--a){let i=e===n?f(r[a],!0):r[a];t.insertBefore(i,h(e))}}}return yt(e),!0},Kt=function(e,t,n,r){return e.length===0?t:t===n||t===r?La(t):t},qt=function(e,t){return e===t||_(e)!==null?!1:(Be&&Tt(e),!0)},Jt=function(e,n){if(jt(e),Ht(P.beforeSanitizeElements,e,null),qt(e,n))return!0;if(zt(e))return yt(e),!0;let r=R(w(e));if(I=Kt(P.uponSanitizeElement,I,ge,Ae),Ht(P.uponSanitizeElement,e,{tagName:r,allowedTags:I}),qt(e,n))return!0;if(Ut(e,r))return yt(e),!0;if(ye[r]||!(xe.tagCheck instanceof Function&&xe.tagCheck(r))&&!I[r]){let t=Gt(e,r,n);return t===!1&&(Ht(P.afterSanitizeElements,e,null),qt(e,n))?!0:t}if(C(e)===mo.element&&!vt(e)||(r===`noscript`||r===`noembed`||r===`noframes`)&&Na(fo,e.innerHTML))return yt(e),!0;if(Ee&&e.nodeType===mo.text){let n=It(e.textContent);e.textContent!==n&&(ma(t.removed,{element:e.cloneNode()}),e.textContent=n)}return Ht(P.afterSanitizeElements,e,null),qt(e,n)},Yt=function(e,t,r){if(be[t]||Mt(t,e)||Ie&&(t===`id`||t===`name`)&&(r in n||r in ut))return!1;let i=L[t]||xe.attributeCheck instanceof Function&&xe.attributeCheck(t,e);return Ce&&Na(de,t)||Se&&Na(fe,t)?!0:i?qe[t]||Na(he,wa(r,pe,``))||(t===`src`||t===`xlink:href`||t===`href`)&&e!==`script`&&Ta(r,`data:`)===0&&Ge[e]||we&&!Na(F,wa(r,pe,``))?!0:!r:Zt(e)&&Wt(ve.tagNameCheck,e)&&Wt(ve.attributeNameCheck,t,e)||t===`is`&&ve.allowCustomizedBuiltInElements&&Wt(ve.tagNameCheck,r)},Xt=X({},[`annotation-xml`,`color-profile`,`font-face`,`font-face-format`,`font-face-name`,`font-face-src`,`font-face-uri`,`missing-glyph`]),Zt=function(e){return!Xt[xa(e)]&&Na(me,e)},Qt=function(e,t,n,r){if(E&&typeof u==`object`&&typeof u.getAttributeType==`function`&&!n)switch(u.getAttributeType(e,t)){case`TrustedHTML`:return k(r);case`TrustedScriptURL`:return A(r)}return r},$t=function(e,t,n,r){try{return n?e.setAttributeNS(n,t,r):e.setAttribute(t,r),!zt(e)||(yt(e),!1)}catch{return St(t,e),!1}},en=function(e,t){return De&&Na(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i,t)?!0:xa(e)===`attributename`&&Ca(t,`href`)!==null},tn=function(e,n){if(Ht(P.beforeSanitizeAttributes,e,null),qt(e,n))return;let r=e.attributes;if(!r||zt(e))return;L=Kt(P.uponSanitizeAttribute,L,_e,je);let i={attrName:``,attrValue:``,keepAttr:!0,allowedAttributes:L,forceKeepAttr:void 0},a=r.length,o=R(e.nodeName);for(;a--;){let n=r[a],s=n.name,c=n.namespaceURI,l=n.value,u=R(s),d=l,f=s===`value`?d:Ea(d),p=!1;i.attrName=u,i.attrValue=f,i.keepAttr=!0,i.forceKeepAttr=void 0,Ht(P.uponSanitizeAttribute,e,i),f=i.attrValue,Le&&(u===`id`||u===`name`)&&Ta(f,Re)!==0&&(St(s,e,n),f=Re+f,p=!0),en(s,f)?St(s,e,n):i.forceKeepAttr||(i.keepAttr?!Te&&Na(po,f)?St(s,e,n):(Ee&&(f=It(f)),Yt(o,u,f)?(f=Qt(o,u,c,f),f!==d&&$t(e,s,c,f)&&p&&pa(t.removed)):St(s,e,n)):St(s,e,n))}Ht(P.afterSanitizeAttributes,e,null),qt(e,n)},nn=function(e){let t=null,n=Ft(e);for(Ht(P.beforeSanitizeShadowDOM,e,null);t=n.nextNode();)if(Ht(P.uponSanitizeShadowNode,t,null),Jt(t,e),tn(t,e),Bt(t.content)&&nn(t.content),C(t)===mo.element){let e=v(t);Bt(e)&&(rn(e),nn(e))}Ee&&Rt(e),Ht(P.afterSanitizeShadowDOM,e,null)},rn=function(e){let t=[{node:e,shadow:null}];for(;t.length>0;){let e=t.pop();if(e.shadow){nn(e.shadow);continue}let n=e.node,r=C(n)===mo.element,i=g(n);if(i)for(let e=i.length-1;e>=0;--e)t.push({node:i[e],shadow:null});if(r){let e=x?x(n):null;if(typeof e==`string`&&R(e)===`template`){let e=n.content;Bt(e)&&t.push({node:e,shadow:null})}}if(r){let e=v(n);Bt(e)&&t.push({node:null,shadow:e},{node:e,shadow:null})}}};return t.sanitize=function(e){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},i=null,a=null,o=null,s=null;if($e=!e,$e&&(e=`<!-->`),typeof e!=`string`&&!Vt(e)&&(e=Ra(e),typeof e!=`string`))throw Pa(`dirty is not a string, aborting`);if(!t.isSupported)return e;ke?(I=Ae,L=je):ft(n),(P.uponSanitizeElement.length>0||P.uponSanitizeAttribute.length>0)&&(I=La(I)),P.uponSanitizeAttribute.length>0&&(L=La(L)),t.removed=[];let c=Be&&typeof e!=`string`&&Vt(e),l=[],u=Ve;if(c){Nt(e);let t=w(e);if(typeof t==`string`){let n=R(t);if(!I[n]||ye[n])throw xt(e),Pa(`root node is forbidden and cannot be sanitized in-place`)}if(zt(e))throw xt(e),Pa(`root node is clobbered and cannot be sanitized in-place`);l=Et(e),Ve=va()}else if(Vt(e))i=Pt(`<!---->`),a=i.ownerDocument.importNode(e,!0),a.nodeType===mo.element&&a.nodeName===`BODY`||a.nodeName===`HTML`?i=a:i.appendChild(a),rn(i);else{if(!Ne&&!Ee&&!Oe&&e.indexOf(`<`)===-1)return E&&Fe?k(e):e;if(i=Pt(e),!i)return Ne?null:Fe?D:``}i&&Me&&yt(i.firstChild);let d=c?e:i;try{c&&rn(e);let t=Ft(d);for(;o=t.nextNode();)Jt(o,d),tn(o,d),Bt(o.content)&&nn(o.content);c&&kt(e,l)}catch(t){throw c&&(xt(e),Ot(e,l)),t}finally{Ve=u}if(c){if(Ot(e,l))throw Pa(`a node selected for removal could not be safely returned; refusing to sanitize in place`);return Ee&&Lt(e),e}if(Ne){if(Ee&&Lt(i),Pe)for(s=ae.call(i.ownerDocument);i.firstChild;)s.appendChild(i.firstChild);else s=i;return(L.shadowroot||L.shadowrootmode)&&(s=se.call(r,s,!0)),s}let f=Oe?i.outerHTML:i.innerHTML;return Oe&&I[`!doctype`]&&i.ownerDocument&&i.ownerDocument.doctype&&i.ownerDocument.doctype.name&&Na(so,i.ownerDocument.doctype.name)&&(f=`<!DOCTYPE `+i.ownerDocument.doctype.name+`>
|
|
62
|
+
`+f),Ee&&(f=It(f)),E&&Fe?k(f):f},t.setConfig=function(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};ft(e),ke=!0,Ae=I,je=L},t.clearConfig=function(){lt=null,ke=!1,Ae=null,je=null,E=te,D=``},t.isValidAttribute=function(e,t,n){lt||ft({});let r=R(e),i=R(t);return typeof n==`string`&&(en(t,n)||!Te&&Na(po,n))?!1:Yt(r,i,n)},t.addHook=function(e,t){typeof t==`function`&&ja(P,e)&&ma(P[e],t)},t.removeHook=function(e,t){if(ja(P,e)){if(t!==void 0){let n=fa(P[e],t);return n===-1?void 0:ga(P[e],n,1)[0]}return pa(P[e])}},t.removeHooks=function(e){ja(P,e)&&(P[e]=[])},t.removeAllHooks=function(){P=vo()},t}var So=xo();function Co(e){return e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`).replace(/'/g,`'`)}var wo=new Ki({renderer:{code({text:e,lang:t,escaped:n}){return`<div class="code-block"><div class="code-block-head"><span>${Co((t??``).trim().split(/\s+/)[0]||`代码块`)}</span><button type="button" data-copy-code>复制</button></div><pre><code>${n?e:Co(e)}</code></pre></div>`},link(e){return`<a href="${Co(e.href||``)}"${e.title?` title="${Co(e.title)}"`:``} target="_blank" rel="noopener noreferrer">${this.parser.parseInline(e.tokens??[])}</a>`}}});function To(e){let t=wo.parse(e,{async:!1});return So.sanitize(t,{ADD_ATTR:[`target`]})}function Eo(e){let t=[e.templateTitle||e.templateId?.split(`/`).pop()||`默认模板`,e.outputFormat.toUpperCase()];return e.reqPath&&t.push(e.reqPath.split(`/`).pop()||e.reqPath),t.join(` · `)}function Do(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 Oo(e){return e.replace(/[\\/:*?"<>|]/g,`_`).replace(/\s+/g,`-`).slice(0,48)||`cases`}function ko(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 Ao(e,t=``){let n=ee(e.caseType).label,r=e.templateHeaders.length>0?e.templateHeaders:[...de],i=e.outputFormat===`md`?`最终结果将保存为 Markdown 表格文件`:e.outputFormat===`csv`?`最终结果将保存为 CSV 文件`:`最终结果将保存为 Excel 文件`,a=e.promptBody.trim();if(!a)throw Error(`请先在生成测试用例插件中选择提示词`);return`${a}
|
|
63
|
+
${e.templateBody?`\n\n### 用例模板:${e.templateTitle||e.templateId||``}\n${e.templateBody.slice(0,8e3)}`:`\n\n### 模板字段:${r.join(`、`)}`}
|
|
64
|
+
|
|
65
|
+
【运行时约束 · 生成测试用例插件已启用】
|
|
66
|
+
- 本轮以「生成测试用例」插件所选提示词为准,不要再遵循工作台闲聊/系统提示词风格
|
|
67
|
+
- 用例类型:${n}
|
|
68
|
+
- ${i}
|
|
69
|
+
- 需求名称默认可用「${t||`未命名需求`}」
|
|
70
|
+
- 「用例」对象键必须与模板字段完全一致:${r.join(`、`)}
|
|
71
|
+
- 仅输出一个 JSON 对象(可无代码围栏),结构为:
|
|
72
|
+
{"需求名称":"...","覆盖需求率":0-100,"未覆盖说明":["..."],"编写说明":"...","用例":[...]}
|
|
73
|
+
- 不要输出 JSON 以外的解释性正文;界面只会展示执行摘要,用例由系统静默入库`}function jo(e=0){return`正在编写用例…\n\n已用 ${Math.max(0,Math.floor(e))}s · 通常约 30–120 秒\n完成后将给出覆盖率与入库结果。`}function Mo(e){if(!e.ok)return[`**执行失败**`,``,e.error||`未知错误`,``,`可调整插件中的需求 / 模板 / 提示词后重试。`].join(`
|
|
74
|
+
`);let t=[`**执行成功**`,``,`- 需求名称:${e.title||`—`}`,`- 共编写:${e.count??0} 条用例`,`- 覆盖需求率:${e.coverageRate==null?`未给出(已按用例入库)`:`${e.coverageRate}%`}`];e.path&&t.push(`- 入库文件:用例管理/${e.path}`),e.writeNote&&t.push(``,`**编写说明**`,e.writeNote);let n=e.uncovered??[];if(t.push(``,`**未覆盖 / 未编写原因**`),n.length)for(let e of n)t.push(`- ${e}`);else t.push(`- 无(模型未声明未覆盖项)`);let r=e.fieldGaps??[];if(r.length){t.push(``,`**字段完整性检测**`);for(let e of r)t.push(`- ${e}`)}return t.join(`
|
|
75
|
+
`)}async function No(e){if(!_(`cases`))throw Error(g(`cases`));let t=ee(e.caseType),n=Oo(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:[...de];return e.outputFormat===`md`?await I(`cases`,i,le(e.cases,e.title,a)):e.outputFormat===`csv`?await I(`cases`,i,P(e.cases,a)):await _e(`cases`,i,await ie(e.cases,a,t.label)),i}async function Po(e,t,n){let r=Do(e);if(!r){let e=`未能解析出用例结果,未写入文件`;return{ok:!1,error:e,summary:Mo({ok:!1,error:e})}}let i=t.templateHeaders.length>0?t.templateHeaders:[...de],a=se(r.cases,i),o=r.docTitle||n||ee(t.caseType).label,s=ko(a,i);try{let e=await No({cases:a,headers:i,caseType:t.caseType,outputFormat:t.outputFormat,title:o}),n=Mo({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:Mo({ok:!1,error:t})}}}function Fo(){let e=u().promptKinds;return s(e?.length?e:i)}function Io(e){let t=Fo();return t.find(t=>t.id===e)??t[0]??i[0]}function Lo(e){let t=s(e);return f({promptKinds:t}),d(),t}function Ro(e){let t=e.trim();if(!t)throw Error(`类型名称不能为空`);if(t.length>40)throw Error(`类型名称过长(最多 40 字)`);let n=Fo();if(n.some(e=>e.label===t))throw Error(`已存在「${t}」`);let r={id:o(),label:t,hint:a(t)};return Lo([...n,r]),r}function zo(e,t){let n=t.trim();if(!n)throw Error(`类型名称不能为空`);if(n.length>40)throw Error(`类型名称过长(最多 40 字)`);let r=Fo(),i=r.findIndex(t=>t.id===e);if(i<0)throw Error(`类型不存在`);if(r.some(t=>t.id!==e&&t.label===n))throw Error(`已存在「${n}」`);let o=r[i],s={...o,label:n,hint:o.id===`case`||o.id===`general`?o.hint:a(n)},c=[...r];return c[i]=s,Lo(c),s}function Bo(e){let t=Fo();if(t.length<=1)throw Error(`至少保留一个提示词类型`);if(!t.some(t=>t.id===e))throw Error(`类型不存在`);return Lo(t.filter(t=>t.id!==e))}function Vo(e){return`${Io(e.kind).label} · ${e.titleHint.trim()||`未命名`}`}function Ho(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 Uo(e){return e.replace(/[\\/:*?"<>|]/g,`_`).replace(/\s+/g,``).replace(/\.md$/i,``).slice(0,64)||`未命名提示词`}function Wo(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=Uo(r),a=`${i}.md`;Ce(a)&&n.push(`不可覆盖受保护提示词「${a}」`),e.body.trim()?e.body.trim().length<80&&n.push(`正文过短(建议不少于 80 字)`):n.push(`正文为空`),!/^#\s+/m.test(e.body)&&!e.body.includes(`
|
|
76
|
+
`)&&n.push(`正文建议使用 Markdown 标题与分段结构`);let o=[...new Set(n.filter(Boolean))];return{ok:o.length===0,issues:o,title:r,fileBase:i}}function Go(e){return`你是资深提示词工程师,擅长为测试与研发场景编写可落地的中文提示词。
|
|
77
|
+
|
|
78
|
+
【任务】
|
|
79
|
+
根据用户在对话中的需求,编写一份完整的 Markdown 提示词正文,供后续入库到提示词库。
|
|
80
|
+
具体要求以用户本轮及近期对话输入为准。
|
|
81
|
+
|
|
82
|
+
【类型】
|
|
83
|
+
${Io(e.kind).hint}
|
|
84
|
+
|
|
85
|
+
【用户期望名称】
|
|
86
|
+
${e.titleHint.trim()||`(可在结果中自拟简洁中文名)`}
|
|
87
|
+
|
|
88
|
+
【输出前自检(必须)】
|
|
89
|
+
1. 角色与目标是否清晰?
|
|
90
|
+
2. 约束是否可执行、无互相矛盾?
|
|
91
|
+
3. 是否避免空话与不可判定要求?
|
|
92
|
+
4. 用例类提示词:是否要求按模板字段输出、步骤换行、按需求覆盖(不设固定条数)?
|
|
93
|
+
5. 若未通过,将「质检通过」设为 false,并在「质检问题」列出具体项。
|
|
94
|
+
|
|
95
|
+
【输出格式(强制)】
|
|
96
|
+
仅输出一个 JSON 对象(可无代码围栏),不要其它解释:
|
|
97
|
+
{
|
|
98
|
+
"提示词名称": "简短中文名(不含 .md)",
|
|
99
|
+
"质检通过": true,
|
|
100
|
+
"质检问题": [],
|
|
101
|
+
"质检说明": "一句话说明质检结论",
|
|
102
|
+
"正文": "# 标题\\n\\n完整 Markdown 正文……"
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
约束:
|
|
106
|
+
- 「正文」为完整 Markdown 字符串,可含换行;不要把正文拆到 JSON 外。
|
|
107
|
+
- 「质检通过」为 false 时系统不会入库。
|
|
108
|
+
- 不要输出 JSON 以外的闲聊;界面只展示执行摘要。`}function Ko(e=0){return`正在编写提示词…\n\n已用 ${Math.max(0,Math.floor(e))}s · 通常约 30–90 秒\n完成后将质检并自动入库到提示词管理。`}function qo(e){if(!e.ok){let t=[`**执行失败 / 未入库**`,``,e.error||`质检未通过或解析失败`],n=e.issues??[];if(n.length){t.push(``,`**质检问题**`);for(let e of n)t.push(`- ${e}`)}return t.push(``,`可在对话中补充要求后重新发送,或在插件中修改名称/类型。`),t.join(`
|
|
109
|
+
`)}let t=[`**执行成功**`,``,`- 提示词名称:${e.title||`—`}`];return e.path&&t.push(`- 入库文件:提示词管理/${e.path}`),e.qcNote&&t.push(``,`**质检说明**`,e.qcNote),t.push(``,`下方卡片可点击打开文件。`),t.join(`
|
|
110
|
+
`)}async function Jo(e){let t=`${e}.md`;try{let{entries:n}=await be(`prompts`,`.`),r=new Set(n.filter(e=>e.type===`file`).map(e=>e.name));if(!r.has(t))return t;for(let t=2;t<100;t++){let n=`${e}-${t}.md`;if(!r.has(n))return n}}catch{}return`${e}-${Date.now().toString(36)}.md`}async function Yo(e,t){let n=Ho(e);if(!n){let e=`未能解析出提示词结果,未写入文件`;return{ok:!1,error:e,issues:[],summary:qo({ok:!1,error:e})}}let r=Wo(n,t.titleHint);if(!r.ok){let e=`入库前质检未通过`;return{ok:!1,error:e,issues:r.issues,summary:qo({ok:!1,error:e,issues:r.issues,qcNote:n.qcNote})}}if(!_(`prompts`)){let e=g(`prompts`);return{ok:!1,error:e,issues:[],summary:qo({ok:!1,error:e})}}try{let e=await Jo(r.fileBase);await I(`prompts`,e,n.body.endsWith(`
|
|
111
|
+
`)?n.body:`${n.body}\n`);let t=qo({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:qo({ok:!1,error:t})}}}function Xo(){let e=u().knowledgeCategories;return e?.length?[...e]:[...p]}function Zo(e){let t=r(e);return f({knowledgeCategories:t}),d(),t}function Qo(e){let t=e.trim();if(!t)throw Error(`分类名称不能为空`);if(t.length>40)throw Error(`分类名称过长(最多 40 字)`);if(/[\\/]/.test(t))throw Error(`分类名称不可包含路径分隔符`);let n=Xo();if(n.includes(t))throw Error(`已存在「${t}」`);return Zo([...n,t]),t}function $o(e,t){let n=t.trim();if(!n)throw Error(`分类名称不能为空`);if(n.length>40)throw Error(`分类名称过长(最多 40 字)`);if(/[\\/]/.test(n))throw Error(`分类名称不可包含路径分隔符`);let r=Xo(),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,Zo(a),n}function es(e){let t=Xo();if(t.length<=1)throw Error(`至少保留一个分类`);if(!t.includes(e))throw Error(`分类不存在`);return Zo(t.filter(t=>t!==e))}function ts(e){let t=e.titleHint.trim()||`未命名`;return`${e.category} · ${t}`}function ns(e){return Xo().includes(e)}function rs(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 is(e){return e.replace(/[\\/:*?"<>|]/g,`_`).replace(/\s+/g,``).replace(/\.md$/i,``).slice(0,64)||`未命名知识`}function as(e){let t=e.trim();return!t||/[:#{}[\],&*?|>!<>=%@`"'\\\n]/.test(t)||/^\s|\s$/.test(e)?JSON.stringify(t):t}function os(e){return(e.match(/^---\r?\n[\s\S]*?\r?\n---\r?\n?([\s\S]*)$/)?.[1]??e).trim()}function ss(e){let t=e.description.trim(),n=os(e.body),r=n.startsWith(`#`)?n:`# ${e.title}\n\n${n}`,i=[`---`,`title: ${as(e.title)}`,`category: ${as(e.category)}`];return t&&i.push(`description: ${as(t)}`),i.push(`---`,``,r,``),i.join(`
|
|
112
|
+
`)}function cs(e,t){let n=[...e.qcIssues],r=(e.title||t.titleHint||`未命名知识`).trim(),i=(e.category||t.category||``).trim();ns(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(`标题不可包含路径分隔符`),ns(i)||n.push(`分类必须是:${Xo().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:is(r),description:(e.description||``).trim().slice(0,120)}}function ls(e){let t=e.titleHint.trim()||`(可在结果中自拟简洁中文名)`;return`你是资深测试知识库编辑,擅长把规范、方法论、环境约定写成可复用的 Markdown 文档。
|
|
113
|
+
|
|
114
|
+
【任务】
|
|
115
|
+
根据用户在对话中提供的素材/需求,编写一份完整的知识库 Markdown 正文,入库到知识库对应分类目录。
|
|
116
|
+
具体要求以用户本轮及近期对话输入为准。
|
|
117
|
+
|
|
118
|
+
【目标分类】
|
|
119
|
+
${e.category}
|
|
120
|
+
(分类仅限:${Xo().join(` / `)};不要写成需求文档或测试用例)
|
|
121
|
+
|
|
122
|
+
【用户期望标题】
|
|
123
|
+
${t}
|
|
124
|
+
|
|
125
|
+
【内容要求】
|
|
126
|
+
1. 结构清晰:标题、条目/表格/步骤可执行;避免空话。
|
|
127
|
+
2. 可复用:适合后续对话用「@」引用。
|
|
128
|
+
3. 不要输出用例表格字段集;不要写成需求 PRD。
|
|
129
|
+
|
|
130
|
+
【输出前自检(必须)】
|
|
131
|
+
1. 分类是否正确?
|
|
132
|
+
2. 标题是否简洁可作文件名?
|
|
133
|
+
3. 正文是否可落地、无互相矛盾?
|
|
134
|
+
4. 若未通过,将「质检通过」设为 false,并在「质检问题」列出具体项。
|
|
135
|
+
|
|
136
|
+
【输出格式(强制)】
|
|
137
|
+
仅输出一个 JSON 对象(可无代码围栏),不要其它解释:
|
|
138
|
+
{
|
|
139
|
+
"标题": "简短中文名(不含 .md)",
|
|
140
|
+
"分类": "${e.category}",
|
|
141
|
+
"描述": "一句话摘要",
|
|
142
|
+
"质检通过": true,
|
|
143
|
+
"质检问题": [],
|
|
144
|
+
"质检说明": "一句话说明质检结论",
|
|
145
|
+
"正文": "# 标题\\n\\n完整 Markdown 正文……"
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
约束:
|
|
149
|
+
- 「正文」为完整 Markdown 字符串(可含换行);frontmatter 由系统自动拼接,正文不要再写 --- frontmatter。
|
|
150
|
+
- 「质检通过」为 false 时系统不会入库。
|
|
151
|
+
- 不要输出 JSON 以外的闲聊;界面只展示执行摘要。`}function us(e=0){return`正在编写知识库文档…\n\n已用 ${Math.max(0,Math.floor(e))}s · 通常约 30–90 秒\n完成后将质检并自动入库到知识库管理。`}function ds(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(`
|
|
152
|
+
`)}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(`
|
|
153
|
+
`)}async function fs(e){let t=`${e}.md`;try{let{entries:n}=await be(`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 ps(e,t){let n=rs(e);if(!n){let e=`未能解析出知识库结果,未写入文件`;return{ok:!1,error:e,issues:[],summary:ds({ok:!1,error:e})}}let r=cs(n,t);if(!r.ok){let e=`入库前质检未通过`;return{ok:!1,error:e,issues:r.issues,summary:ds({ok:!1,error:e,issues:r.issues,qcNote:n.qcNote})}}if(!_(`knowledgeLib`)){let e=g(`knowledgeLib`);return{ok:!1,error:e,issues:[],summary:ds({ok:!1,error:e})}}try{let e=await fs(r.fileBase),t=ss({title:r.title,category:r.category,description:r.description,body:n.body});await I(`knowledge`,e,t.endsWith(`
|
|
154
|
+
`)?t:`${t}\n`);let i=ds({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:ds({ok:!1,error:t})}}}var ms=`你是 Lantern Harness(仓库 lantern-harness)的「插件开发」助手,只负责在本项目里开发「扩展插件」。
|
|
155
|
+
|
|
156
|
+
# 铁律:先评估、再确认、后开发
|
|
157
|
+
1. 收到需求后,先只读调研相关代码(fs_read / fs_glob / fs_grep,必要时用只读命令),弄清现有插件约定。
|
|
158
|
+
调研纪律:先用 fs_grep 定位符号 / 字符串,再只读命中片段;不要为了「看清楚」把整个目录、整份大文件逐个读一遍;
|
|
159
|
+
与本次插件无关的模块不必打开;发出确认选项前,读取次数控制在必要范围(一般 8 次以内,确有必要再增加)。
|
|
160
|
+
2. 在改任何文件之前,必须调用 ask_user_question 提出 2~4 个选择题(每题 2~4 个选项),覆盖:
|
|
161
|
+
- 插件形态:纯提示词型 / 带配置面板 / 侧栏库 / 需要本地服务能力
|
|
162
|
+
- 范围与边界:做什么、不做什么
|
|
163
|
+
- 命名与入口:插件 id / 中文名 / 从「+」「/」还是侧栏进入
|
|
164
|
+
- 默认开关:新插件在新建空间里默认开还是关(推荐默认关)
|
|
165
|
+
每题给出推荐项,便于用户直接确认。
|
|
166
|
+
3. 用户回答之前,禁止 fs_write / fs_mkdir / 改配置 / 写文档;这一轮只允许只读调研。
|
|
167
|
+
4. 用户确认后才开始实现;用户改选或补充要求时,按新答案调整后再动手。
|
|
168
|
+
5. 「确认」只认用户明确表达(如「开始实施」「按这个方案做」「确认」)。用户跳过(skipped)、关闭提问卡片、没作答、沉默,都不算确认,也绝不等于批准实施:
|
|
169
|
+
- 这类情况先停手,用几行说明你将采用的默认假设(哪几项按推荐)、插件形态与准备改动的文件范围;
|
|
170
|
+
- 然后等用户明确回复「开始实施」再写文件;跳过当轮只能写代码计划,禁止 fs_write / fs_mkdir / 改配置。
|
|
171
|
+
6. 只改与本次插件相关的文件:不重构无关代码、不改主题样式、不动其它插件行为、不执行 git commit / git push。
|
|
172
|
+
7. 完成后用简短条目汇报:插件 id / 中文名 / 入口位置 / 默认开关 / 改动文件 / 用户如何验证。
|
|
173
|
+
|
|
174
|
+
# 项目插件实现位置(先读再改)
|
|
175
|
+
- 注册表:src/lib/plugins.ts → PluginId 联合类型 + PLUGIN_CATALOG(字段:id/name/description/version/requiresDev/defaultEnabled/hasPanel/requires)
|
|
176
|
+
- 新建空间默认开关:config/app.defaults.json 的 plugins;同时补 src/lib/app-config.ts 的 emptyAppConfig().plugins
|
|
177
|
+
- 我的插件页:src/components/islands/PluginsPage.tsx(按注册表自动渲染;Tab「扩展插件」即扩展插件列表,卡片按 PLUGIN_CATALOG 的 category 分组)
|
|
178
|
+
- 工作台入口:hasPanel=true 的插件会自动出现在「+」弹窗与「/」菜单;入口文案与面板打开逻辑在 src/components/islands/ChatApp.tsx(pluginMenuItems / openPluginPanel / pickPluginMenu / 菜单 tip)
|
|
179
|
+
- 胶囊型入口(与「计划」「插件开发」一致):在 ChatApp 的 composerChip 增加一个取值,+ 菜单里点击后只激活胶囊,用户在主输入框描述要求后发送
|
|
180
|
+
- 带配置面板的插件:新建 src/components/islands/XxxPanel.tsx(复用 SlideOverDrawer);配置类型放 src/lib/xxx.ts;若配置需要跟会话保存,加到 src/lib/sessions.ts 的 ChatSession 与 SessionMetaPatch,并在 ChatApp 的会话切换 / 新建流程里同步
|
|
181
|
+
- 纯提示词型插件:在 src/lib/xxx.ts 导出固定系统提示词与 buildXxxSystemPrompt(),在 ChatApp 的 executeSend 里按会话配置替换 baseSystem
|
|
182
|
+
- 侧栏库:src/lib/nav-menu.ts(NavEntryId / NavEntryDef / i18n 键)、src/lib/plugin-nav.ts、src/components/islands/NavLibraries.tsx、src/lib/i18n.ts,以及 lh-plugins/lh-project-docs.mjs 的 DOC_ROOT_DIRS
|
|
183
|
+
- 本地 API:新建 lh-plugins/lh-xxx.mjs(导出 lhXxxPlugin,提供 configureServer 中间件),并在 astro.config.mjs 与 cli/server.mjs 的插件列表里注册;数据根用 builtin/session/space-context.mjs 的 getDataRoot() / getBaseRoot();PLUGIN_CATALOG 里补 category(内容库 / 生成能力 / 记忆与检索 / 待办与效率 / 开发工具),没有合适的分类时先问用户
|
|
184
|
+
- 文档:更新 docs/操作手册.md 的插件表与对应章节;在 CHANGELOG.md 顶部(当前版本或 Unreleased)增加条目
|
|
185
|
+
|
|
186
|
+
# 默认值约定
|
|
187
|
+
- 新建空间的插件开关默认关闭:config/app.defaults.json 与 src/lib/app-config.ts 的 emptyAppConfig().plugins 都写 false,不要为新插件破例。
|
|
188
|
+
- 唯一例外是「提示词管理」:它是内置常开项(每个空间都需要默认提示词),在 PLUGIN_CATALOG 里 defaultEnabled / alwaysOn 都为 true,新插件不要照抄。
|
|
189
|
+
- PLUGIN_CATALOG 里的 defaultEnabled 也写 false:新增插件默认关闭,由用户在「我的插件」里手动开启。
|
|
190
|
+
- 依赖其它插件时用 requires 声明(如生成器依赖对应管理插件)。
|
|
191
|
+
|
|
192
|
+
# 验证
|
|
193
|
+
- 可用时至少运行 pnpm typecheck;涉及服务端或纯函数时补充/运行相关 node:test。
|
|
194
|
+
- 不执行 git commit / git push,不擅自格式化无关文件。
|
|
195
|
+
- 改完说明哪些点没有实际运行验证,不要声称已跑通。
|
|
196
|
+
|
|
197
|
+
# 回答风格
|
|
198
|
+
- 中文、直接、少客套;评估阶段先说结论(做成哪种插件、为什么),再给确认选项。
|
|
199
|
+
- 不要空泛地描述「可以开发」,要给具体方案与取舍。
|
|
200
|
+
- 需要用户批准开工时,用一句明确的话收尾,例如「确认无误请回复:开始实施」。`;function hs(e,t){let n=String(t??``).trim(),r=[ms];return n&&r.push(`# 本次运行环境\n项目根(可直接用 fs_* 工具读写):${n}`),r.push(`# 本次需求\n${e.requirement.trim()||`(未填写,按用户后续消息执行)`}`),r.join(`
|
|
201
|
+
|
|
202
|
+
`)}var gs=`/__tb_fs`,_s=`你可以使用 Skill 工具(本地 fs 可用时):
|
|
203
|
+
- skill_list:列出工作区 / 项目根下约定目录中的 SKILL.md
|
|
204
|
+
- skill_load:按 id(目录名)或 path 加载技能正文到本轮上下文
|
|
205
|
+
- 需要遵循某技能流程时先 skill_list 再 skill_load,勿臆造技能内容`,vs=[{type:`function`,function:{name:`skill_list`,description:`List available skills (SKILL.md) under the workspace / project (.cursor/skills, .agents/skills, skills/, or */SKILL.md).`,parameters:{type:`object`,properties:{}}}},{type:`function`,function:{name:`skill_load`,description:`Load a skill by id (directory name) or path to SKILL.md. Returns the skill markdown body (may be truncated).`,parameters:{type:`object`,properties:{name:{type:`string`,description:`Skill id / directory name from skill_list, or relative/absolute path to SKILL.md`},path:{type:`string`,description:`Optional path to SKILL.md (alias of name)`}}}}}];async function ys(e,t){if(e===`skill_list`)try{let e=await fetch(`${gs}/skills`,{signal:AbortSignal.timeout(5e3)}),t=await e.json().catch(()=>({}));return e.ok?JSON.stringify({ok:!0,count:t.count??t.skills?.length??0,skills:t.skills??[]},null,2):JSON.stringify({ok:!1,error:t.error||`HTTP ${e.status}`})}catch(e){return JSON.stringify({ok:!1,error:e instanceof Error?e.message:String(e)})}if(e===`skill_load`){let e={};try{e=JSON.parse(t||`{}`)}catch{return JSON.stringify({ok:!1,error:`invalid JSON arguments`})}let n=String(e.name??e.path??e.id??``).trim();if(!n)return JSON.stringify({ok:!1,error:`name or path is required`});try{let e=await fetch(`${gs}/skill-load`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:n}),signal:AbortSignal.timeout(8e3)}),t=await e.json().catch(()=>({}));if(!e.ok){let n=typeof t==`object`&&t&&`error`in t?String(t.error):`HTTP ${e.status}`;return JSON.stringify({ok:!1,error:n})}return JSON.stringify(t,null,2)}catch(e){return JSON.stringify({ok:!1,error:e instanceof Error?e.message:String(e)})}}return JSON.stringify({error:`unknown tool: ${e}`})}var bs=`待办事项工具(空间级,跨会话保留,页面在 /todos/):
|
|
206
|
+
- 用户让你「记一下 / 加个待办 / 跟进 / 周五前完成」时,调用 todo_add 记录;一次可传多条。
|
|
207
|
+
- 不要先用 ask_user_question 逐项追问待办字段。直接调用 todo_add,把已知字段填好;系统会弹出与「+ → 待办」完全相同的确认卡片,用户在卡片里补充或修改,点「确认新增」才落库。
|
|
208
|
+
- 用户没说待办内容时也直接调用 todo_add(items 传空数组或 [{ "title": "" }]),系统会打开空白确认卡片让用户自己填。
|
|
209
|
+
- 用户问「还有哪些待办 / 进度」时用 todo_list;完成后用 todo_update 把 status 改为 done;删掉用 todo_delete。
|
|
210
|
+
- 日期一律 YYYY-MM-DD;不确定截止日期就先不填,不要凭空猜测。
|
|
211
|
+
- 只记录用户明确要求或明确同意的事项,不要把闲聊、假设写成待办。`,xs=[...Fn,`overdue`,`all`],Ss=[{type:`function`,function:{name:`todo_add`,description:`Create one or more long-lived todos in the current space (visible on the /todos/ page). Use when the user asks to note, follow up, or track something. This opens the same editable confirm card as the manual + menu, so do not ask the user for the fields first.`,parameters:{type:`object`,properties:{items:{type:`array`,description:`Todos to create. Pass an empty array to open a blank confirm card for the user to fill in.`,items:{type:`object`,properties:{title:{type:`string`,description:`Short imperative title.`},status:{type:`string`,enum:Fn,description:`pending | in_progress | done | cancelled. Default pending.`},priority:{type:`string`,enum:bn,description:`urgent_important | important | urgent | normal. Omit when unclear.`},linkedTask:{type:`string`,description:`Related task name / project name.`},taskId:{type:`string`,description:`Task id from the 任务管理 plugin (task_add / task_list). Prefer over linkedTask.`},startDate:{type:`string`,description:`YYYY-MM-DD.`},dueDate:{type:`string`,description:`YYYY-MM-DD.`},note:{type:`string`,description:`Extra detail, dependencies, links.`}},required:[`title`]}}},required:[`items`]}}},{type:`function`,function:{name:`todo_list`,description:`List long-lived todos of the current space, optionally filtered by status, priority or keyword.`,parameters:{type:`object`,properties:{status:{type:`string`,enum:xs,description:`Default all.`},priority:{type:`string`,enum:[...bn,`all`],description:`Default all.`},keyword:{type:`string`,description:`Match title / linked task / note.`},limit:{type:`number`,description:`Max rows, default 50.`}}}}},{type:`function`,function:{name:`todo_update`,description:`Update one todo by id. Only pass fields that change; use status "done" when the user finishes it.`,parameters:{type:`object`,properties:{id:{type:`string`,description:`Todo id from todo_list / todo_add.`},title:{type:`string`},status:{type:`string`,enum:Fn},priority:{type:`string`,enum:bn},linkedTask:{type:`string`},taskId:{type:`string`,description:`Task id; empty string unlinks.`},startDate:{type:`string`,description:`YYYY-MM-DD.`},dueDate:{type:`string`,description:`YYYY-MM-DD.`},note:{type:`string`}},required:[`id`]}}},{type:`function`,function:{name:`todo_delete`,description:`Delete one or more todos by id.`,parameters:{type:`object`,properties:{ids:{type:`array`,description:`Todo ids to delete.`,items:{type:`string`}}},required:[`ids`]}}}];function Cs(e){let t=mn(e),n=gn(e);return[`[${e.id}] ${e.title}`,`状态=${Sn[t]}`,e.priority?`紧急程度=${Nn[e.priority]}`:``,e.dueDate?`截止=${e.dueDate}`:``,n!==null&&t!==`done`&&t!==`cancelled`?n<0?`逾期${Math.abs(n)}天`:`剩余${n}天`:``,e.linkedTask?`关联=${e.linkedTask}`:``,e.note?`备注=${e.note}`:``].filter(Boolean).join(` | `)}function ws(e){return e.length?e.map((e,t)=>`${t+1}. ${Cs(e)}`).join(`
|
|
212
|
+
`):`当前没有匹配的待办。`}function Ts(e){return typeof e==`string`&&Fn.includes(e)}function Es(e){return typeof e==`string`&&bn.includes(e)}function Ds(e){let t={};return typeof e.title==`string`&&(t.title=e.title.trim()),Ts(e.status)&&(t.status=e.status),Es(e.priority)&&(t.priority=e.priority),typeof e.linkedTask==`string`&&(t.linkedTask=e.linkedTask.trim()),typeof e.taskId==`string`&&(t.taskId=e.taskId.trim()),typeof e.startDate==`string`&&(t.startDate=e.startDate.trim()),typeof e.dueDate==`string`&&(t.dueDate=e.dueDate.trim()),typeof e.note==`string`&&(t.note=e.note.trim()),t}async function Os(e,t,n={}){let r={};try{r=JSON.parse(t||`{}`)}catch{return JSON.stringify({error:`invalid JSON arguments`})}try{if(e===`todo_add`){let e=(Array.isArray(r.items)?r.items:[r]).map(B).filter(e=>!!e);if(!e.length)return JSON.stringify({error:`待办名称不能为空`});let t=await Pn(e,{mode:`ai`,sessionId:n.sessionId});return JSON.stringify({ok:!0,count:t.length,items:t,summary:`已记录 ${t.length} 条待办:\n${ws(t)}`})}if(e===`todo_list`){let e=await hn(),t=r.status,n=Ts(t)?t:t===`overdue`?`overdue`:`all`,i=Es(r.priority)?r.priority:`all`,a=typeof r.keyword==`string`?r.keyword:``,o=Math.max(1,Math.min(200,Number(r.limit)||50)),s=yn(e,{status:n,priority:i,keyword:a}).slice(0,o);return JSON.stringify({ok:!0,total:e.length,count:s.length,items:s,summary:ws(s)})}if(e===`todo_update`){let e=typeof r.id==`string`?r.id.trim():``;if(!e)return JSON.stringify({error:`缺少待办 id`});let t=Ds(r);if(!Object.keys(t).length)return JSON.stringify({error:`没有可更新的字段`});let n=await _n(e,t);return JSON.stringify({ok:!0,item:n,summary:`已更新待办:${Cs(n)}`})}if(e===`todo_delete`){let e=(Array.isArray(r.ids)?r.ids:[r.id]).filter(e=>typeof e==`string`&&!!e.trim()).map(e=>e.trim());if(!e.length)return JSON.stringify({error:`缺少待办 id`});let t=await vn(e);return JSON.stringify({ok:!0,removed:t,summary:`已删除 ${t} 条待办。`})}return JSON.stringify({error:`unknown todo tool: ${e}`})}catch(e){return JSON.stringify({error:e instanceof Error?e.message:String(e)})}}var ks=`任务管理工具(空间级,跨会话保留,页面在 /tasks/):
|
|
213
|
+
- 用户说「建个任务 / 开个项目任务 / 把这件事拆成任务」时调用 task_add;一次可传多条。
|
|
214
|
+
- 不要先用 ask_user_question 逐项追问任务字段。直接调用 task_add,把已知字段填好;系统会弹出与「+ → 任务」完全相同的确认卡片,用户在卡片里补充或修改,点「确认新增」才落库。
|
|
215
|
+
- 用户没说任务内容时也直接调用 task_add(items 传空数组或 [{ "title": "" }]),系统会打开空白确认卡片让用户自己填。
|
|
216
|
+
- 只查询用 task_list;改状态 / 日期用 task_update;删任务用 task_delete。
|
|
217
|
+
- 任务下的待办用 todo_add 的 taskId 关联,任务本身不重复记录待办内容。
|
|
218
|
+
- 日期一律 YYYY-MM-DD;不确定就先不填,不要凭空猜测。`,As=[...jn,`urgent`,`all`];function js(e){return typeof e==`string`&&jn.includes(e)}function Z(e){let t=On(e);return[`[${e.id}] ${e.title}`,`状态=${En[e.status]}`,e.priority?`紧急程度=${kn[e.priority]}`:``,e.startDate?`开始=${e.startDate}`:``,e.dueDate?`截止=${e.dueDate}`:``,t===null?``:`周期=${t}天`,e.note?`备注=${e.note}`:``].filter(Boolean).join(` | `)}function Ms(e){return e.length?e.map((e,t)=>`${t+1}. ${Z(e)}`).join(`
|
|
219
|
+
`):`当前没有匹配的任务。`}var Ns=[{type:`function`,function:{name:`task_add`,description:`Create one or more long-lived tasks in the current space (visible on the /tasks/ page). Use when the user asks to create a task / project item. This opens the same editable confirm card as the manual + menu, so do not ask the user for the fields first.`,parameters:{type:`object`,properties:{items:{type:`array`,description:`Tasks to create. Pass an empty array to open a blank confirm card for the user to fill in.`,items:{type:`object`,properties:{title:{type:`string`,description:`Short task title.`},status:{type:`string`,enum:jn,description:`pool | in_progress | done | closed. Default pool.`},priority:{type:`string`,enum:Mn,description:`urgent_important | important | urgent | normal. Omit when unclear.`},startDate:{type:`string`,description:`YYYY-MM-DD.`},dueDate:{type:`string`,description:`YYYY-MM-DD.`},note:{type:`string`,description:`Extra detail, scope, links.`}},required:[`title`]}}},required:[`items`]}}},{type:`function`,function:{name:`task_list`,description:`List tasks of the current space, optionally filtered by status, priority or keyword.`,parameters:{type:`object`,properties:{status:{type:`string`,enum:As,description:`Default all.`},priority:{type:`string`,enum:[...Mn,`all`],description:`Default all.`},keyword:{type:`string`,description:`Match title / note.`},limit:{type:`number`,description:`Max rows, default 50.`}}}}},{type:`function`,function:{name:`task_update`,description:`Update one task by id. Only pass fields that change.`,parameters:{type:`object`,properties:{id:{type:`string`,description:`Task id from task_list / task_add.`},title:{type:`string`},status:{type:`string`,enum:jn},priority:{type:`string`,enum:[...Mn,``]},startDate:{type:`string`,description:`YYYY-MM-DD; empty string clears.`},dueDate:{type:`string`,description:`YYYY-MM-DD; empty string clears.`},note:{type:`string`}},required:[`id`]}}},{type:`function`,function:{name:`task_delete`,description:`Delete one or more tasks by id. Linked todos are kept (only unlinked).`,parameters:{type:`object`,properties:{ids:{type:`array`,description:`Task ids to delete.`,items:{type:`string`}}},required:[`ids`]}}}];function Ps(e){try{let t=JSON.parse(e||`{}`);return(Array.isArray(t.items)?t.items:[t]).filter(e=>!!e&&typeof e==`object`&&typeof e.title==`string`)}catch{return[]}}async function Fs(e,t,n={}){let r={};try{r=JSON.parse(t||`{}`)}catch{return JSON.stringify({error:`invalid JSON arguments`})}try{if(e===`task_add`){let e=(Array.isArray(r.items)?r.items:[r]).map(wn).filter(e=>!!e);if(!e.length)return JSON.stringify({error:`任务名称不能为空`});let t=await xn(e,{mode:`ai`,sessionId:n.sessionId});return JSON.stringify({ok:!0,count:t.length,items:t,summary:`已创建 ${t.length} 个任务:\n${Ms(t)}`})}if(e===`task_list`){let e=await V(),t=r.status,n=js(t)?t:t===`urgent`?`urgent`:`all`,i=typeof r.priority==`string`&&Mn.includes(r.priority)?r.priority:`all`,a=typeof r.keyword==`string`?r.keyword:``,o=Math.max(1,Math.min(200,Number(r.limit)||50)),s=Cn(e,{status:n,priority:i,keyword:a}).slice(0,o);return JSON.stringify({ok:!0,total:e.length,count:s.length,items:s,summary:Ms(s)})}if(e===`task_update`){let e=typeof r.id==`string`?r.id.trim():``;if(!e)return JSON.stringify({error:`缺少任务 id`});let t={};if(typeof r.title==`string`&&(t.title=r.title.trim()),js(r.status)&&(t.status=r.status),r.priority===``?t.priority=``:Dn(r.priority)&&(t.priority=r.priority),typeof r.startDate==`string`&&(t.startDate=r.startDate.trim()),typeof r.dueDate==`string`&&(t.dueDate=r.dueDate.trim()),typeof r.note==`string`&&(t.note=r.note.trim()),!Object.keys(t).length)return JSON.stringify({error:`没有可更新的字段`});let n=await Tn(e,t);return JSON.stringify({ok:!0,item:n,summary:`已更新任务:${Z(n)}`})}if(e===`task_delete`){let e=(Array.isArray(r.ids)?r.ids:[r.id]).filter(e=>typeof e==`string`&&!!e.trim()).map(e=>e.trim());if(!e.length)return JSON.stringify({error:`缺少任务 id`});let t=await An(e);return JSON.stringify({ok:!0,removed:t,summary:`已删除 ${t} 个任务。`})}return JSON.stringify({error:`unknown task tool: ${e}`})}catch(e){return JSON.stringify({error:e instanceof Error?e.message:String(e)})}}var Is=`/__tb_sessions/query`;function Ls(e){if(!e||typeof e!=`object`)return``;let t=e;return typeof t.content==`string`?t.content:Array.isArray(t.content)?t.content.map(e=>typeof e==`string`?e:e&&typeof e==`object`&&`text`in e?String(e.text??``):``).join(`
|
|
220
|
+
`):``}function Rs(e,t){let n=t.trim().toLowerCase();if(!n)return null;let r=(e.title||``).trim(),i=0,a=``;r.toLowerCase().includes(n)&&(i+=10,a=r);let o=Array.isArray(e.messages)?e.messages:[];for(let e=o.length-1;e>=0;e--){let t=Ls(o[e]),r=t.toLowerCase().indexOf(n);if(!(r<0)){if(i+=1,!a){let e=Math.max(0,r-24),i=Math.min(t.length,r+n.length+48);a=`${e>0?`…`:``}${t.slice(e,i).replace(/\s+/g,` `)}${i<t.length?`…`:``}`}if(o.length-e>40)break}}return i<=0?null:{score:i,snippet:a||r||e.id}}function zs(e,t,n){let r=String(t??``).trim();if(!r||!e?.sessions?.length)return[];let i=Math.min(Math.max(n?.limit??20,1),50),a=n?.includeArchived===!0,o=[];for(let t of e.sessions){if(t.deleted||t.archived&&!a)continue;let e=Rs(t,r);e&&o.push({sessionId:t.id,title:t.title||`新对话`,archived:!!t.archived,score:e.score,snippet:e.snippet,updatedAt:t.updatedAt})}return o.sort((e,t)=>t.score-e.score||t.updatedAt-e.updatedAt),o.slice(0,i)}async function Bs(e,t){let n=String(e??``).trim();if(!n)return{backend:`sqlite`,hits:[]};try{let e=new URLSearchParams({q:n,limit:String(t?.limit??20)});t?.includeArchived&&e.set(`archived`,`1`);let r=await fetch(`${Is}?${e}`,{signal:AbortSignal.timeout(4e3)}),i=await r.json().catch(()=>null);return!r.ok||!i||!Array.isArray(i.hits)?null:{backend:i.backend||`sqlite`,hits:i.hits}}catch{return null}}var Vs=`你可以使用工作区变更工具:
|
|
221
|
+
- workspace_changes_list:查看本会话内已记录的写文件/建目录
|
|
222
|
+
- workspace_changes_clear:清空本会话变更记录(不回滚磁盘文件)`,Hs=[{type:`function`,function:{name:`workspace_changes_list`,description:`List workspace file mutations recorded in this chat session (fs_write / fs_mkdir).`,parameters:{type:`object`,properties:{}}}},{type:`function`,function:{name:`workspace_changes_clear`,description:`Clear the in-session workspace change log (does not delete files on disk).`,parameters:{type:`object`,properties:{}}}}];function Us(e){return String(e??``).trim().replace(/\\/g,`/`).replace(/^\.\//,``)}function Ws(e,t){let n=Us(t.path);if(!n)return Array.isArray(e)?[...e]:[];let r={path:n,op:t.op,at:t.at??Date.now()};return[...Array.isArray(e)?e.filter(e=>Us(e.path)!==n):[],r].slice(-100)}function Gs(e,t){if(e!==`fs_write`&&e!==`fs_mkdir`)return null;try{let n=JSON.parse(t||`{}`);if(n.error||n.ok===!1)return null;let r=Us(String(n.path??``));return r?{path:r,op:e===`fs_mkdir`?`mkdir`:`write`}:null}catch{return null}}function Ks(e,t){if(e===`workspace_changes_list`){let e=Array.isArray(t)?t:[];return{text:JSON.stringify({ok:!0,count:e.length,changes:e.map(e=>({path:e.path,op:e.op,at:new Date(e.at).toISOString()}))},null,2)}}return e===`workspace_changes_clear`?{text:JSON.stringify({ok:!0,cleared:!0,count:0}),next:[]}:{text:JSON.stringify({error:`unknown tool: ${e}`})}}var qs=6e5;function Js(e){if(e==null||!Number.isFinite(e)||e<0)return`unavailable`;let t=Math.floor(e/1e3);if(t<60)return`${t}s`;let n=Math.floor(t/60),r=t%60;if(n<60)return r?`${n}m${r}s`:`${n}m`;let i=Math.floor(n/60),a=n%60;return a?`${i}h${a}m`:`${i}h`}function Ys(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone||`unavailable`}catch{return`unavailable`}}function Xs(e,t){try{return`${new Intl.DateTimeFormat(`en-CA`,{timeZone:t,year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`,hour12:!1,timeZoneName:`shortOffset`}).format(e).replace(`,`,``)} (${t})`}catch{return e.toISOString()}}function Zs(e={}){let t=e.now??Date.now(),n=Ys(),r=e.lastInjectAt??null;if(!(r==null||!Number.isFinite(r)||t-r>=6e5)&&r!=null)return{text:`【时间上下文 time-context】沿用上次采样(节流 ${qs/6e4} 分钟)。浏览器时区:${n}。解释未标注时区的日期时间时请使用该时区;若不确定请向用户确认。`,injected:!1,at:r};let i=e.lastUserMessageAt!=null&&Number.isFinite(e.lastUserMessageAt)?t-e.lastUserMessageAt:null;return{text:[`【时间上下文 time-context】`,`当前时间:${Xs(new Date(t),n)}`,`浏览器时区:${n}`,`距上一轮用户消息:${Js(i)}`,`解释未标注时区的日期时间时请使用上述时区;若时区信息混杂或缺失,请向用户确认。`].join(`
|
|
223
|
+
`),injected:!0,at:t}}var Qs=`会话交互工具(默认可用):
|
|
224
|
+
- todo_write:维护本会话完整待办列表(替换式写入);多步任务用它展示进度;允许多个 in_progress
|
|
225
|
+
- ask_user_question:向用户提出结构化问题并等待回答;缺信息或需确认时使用,勿空猜`,$s={type:`function`,function:{name:`todo_write`,description:`Record and update a task list for multi-step work. Replace the complete list each call. Keep active work in_progress (several allowed in parallel). Mark completed as soon as done. Skip for trivial single-step tasks.`,parameters:{type:`object`,properties:{todos:{type:`array`,description:`The COMPLETE task list, replacing any previous list.`,items:{type:`object`,properties:{content:{type:`string`,description:`What the task is — a short imperative line.`},status:{type:`string`,enum:[`pending`,`in_progress`,`completed`],description:`pending | in_progress | completed`}},required:[`content`,`status`]}}},required:[`todos`]}}},ec={type:`function`,function:{name:`ask_user_question`,description:`Ask the user a concise structured question when you need confirmation, a choice, or missing information before proceeding. Pauses until the user answers.`,parameters:{type:`object`,properties:{questions:{type:`array`,description:`Questions to ask the user before continuing.`,items:{type:`object`,properties:{id:{type:`string`,description:`Stable id; echoed in the answer.`},question:{type:`string`,description:`The specific question.`},header:{type:`string`,description:`Optional short heading.`},options:{type:`array`,items:{type:`object`,properties:{label:{type:`string`},description:{type:`string`}},required:[`label`]}},multi_select:{type:`boolean`,description:`Allow selecting more than one option. Default false.`}},required:[`id`,`question`]}}},required:[`questions`]}}};function tc(e){if(!Array.isArray(e))return[];let t=[];for(let n of e){if(!n||typeof n!=`object`)continue;let e=String(n.content??``).trim(),r=String(n.status??``);e&&(r===`pending`||r===`in_progress`||r===`completed`)&&t.push({content:e,status:r})}return t}function nc(e){let t={};try{t=JSON.parse(e||`{}`)}catch{return[]}if(!Array.isArray(t.questions))return[];let n=[];for(let e of t.questions){if(!e||typeof e!=`object`)continue;let t=String(e.id??``).trim(),r=String(e.question??``).trim();if(!t||!r)continue;let i=e.options,a=Array.isArray(i)?i.map(e=>({label:String(e?.label??``).trim(),description:e?.description?String(e.description):void 0})).filter(e=>e.label):void 0;n.push({id:t,question:r,header:e.header?String(e.header):void 0,options:a?.length?a:void 0,multi_select:!!e.multi_select})}return n}function rc(e,t){let n=e.options??[];if(!n.length)return null;let r=t.trim().split(/[,,、;;\s]+/).filter(Boolean);if(!r.length)return null;let i=[];for(let e of r){let t=Number(e.replace(/^第/,``).replace(/[.。)]$/,``));if(!Number.isInteger(t)||t<1||t>n.length)return null;let r=n[t-1]?.label;r&&!i.includes(r)&&i.push(r)}return!e.multi_select&&i.length>1?null:i.length?i:null}function ic(e,t){let n=t??{selected:[],text:``};if(n.skipped)return{id:e.id,selected:[],skipped:!0};let r=n.text.trim();if(r){let t=e.options?.length?rc(e,r):null;return t?{id:e.id,selected:t}:{id:e.id,text:r}}return{id:e.id,selected:[...n.selected]}}function ac(e,t){return e.map((e,n)=>{let r=t[n],i=r?.skipped?`(跳过,未作答)`:r?.text?.trim()?r.text.trim():(r?.selected??[]).join(`、`)||`(跳过,未作答)`,a=e.header?`${e.header} / ${e.question}`:e.question;return`${n+1}. ${a}\n → ${i}`}).join(`
|
|
226
|
+
`)}var oc=`【计划模式 · 探查中】当前禁止写操作(不可 fs_write / bash / pwsh 等)。
|
|
227
|
+
- 先用只读工具(fs_list / fs_read / fs_glob / fs_grep / web_* / kb_*)探查
|
|
228
|
+
- 形成方案后调用 submit_plan,等待用户批准;未批准前不要声称已修改文件
|
|
229
|
+
- 可用 ask_user_question / todo_write 澄清与拆解`,sc=`【计划模式 · 已批准】用户已批准方案,可以按批准内容实施(写文件 / 执行命令)。
|
|
230
|
+
- 实施中若需大幅变更方案,再次 submit_plan 征求批准
|
|
231
|
+
- 仍优先小步、可回滚的改动`,cc={type:`function`,function:{name:`submit_plan`,description:`Submit an implementation plan for user approval (plan mode). Blocks until the user approves or rejects.`,parameters:{type:`object`,properties:{title:{type:`string`,description:`Short plan title`},summary:{type:`string`,description:`What will change and why`},steps:{type:`array`,items:{type:`string`},description:`Ordered implementation steps`}},required:[`title`,`steps`]}}};function lc(e){try{let t=JSON.parse(e||`{}`),n=String(t.title??``).trim(),r=String(t.summary??``).trim(),i=Array.isArray(t.steps)?t.steps.map(e=>String(e??``).trim()).filter(Boolean):[];return!n||!i.length?null:{title:n,summary:r,steps:i.slice(0,24)}}catch{return null}}var uc=8e4,dc=.28;function fc(e){return(e.content?.length??0)+(e.reasoning?.length??0)}function pc(e){return e.reduce((e,t)=>e+fc(t),0)}function mc(e){let t=e?he[e]:void 0;return t&&t>0?Math.max(24e3,Math.floor(t*4*dc)):uc}function hc(e,t){return pc(e)>=mc(t)}function gc(e){return e.map(e=>{let t=e.role===`user`?`User`:`Assistant`,n=(e.content||``).trim(),r=e.reasoning?.trim()?`\n[thinking]\n${e.reasoning.trim().slice(0,1200)}`:``;return`${t}:\n${n.slice(0,6e3)}${r}`}).join(`
|
|
232
|
+
|
|
233
|
+
---
|
|
234
|
+
|
|
235
|
+
`).slice(0,6e4)}async function _c(e,t,n){let r=gc(t);if(!r.trim())return``;let i=[{role:`system`,content:`你是会话压缩助手。将对话历史压缩为简洁中文摘要,保留:目标、关键决策、文件路径、未完成事项、约束。不要编造;不要输出寒暄;用条目或短段落,控制在 800 字以内。`},{role:`user`,content:`请压缩下列对话历史:\n\n${r}`}];return(await pe(e,i,n)).trim()||`(摘要为空)`}async function vc(e,t,n){let r=Math.max(2,n?.keepRecent??8);if(t.length<=r+1||!n?.force&&!hc(t,e.model))return{messages:t,summary:``,compacted:!1};let i=t.slice(0,-r),a=t.slice(-r),o=await _c(e,i,n?.signal);return{messages:[{role:`user`,content:`【会话摘要 · 较早消息已压缩】\n${o}`},{role:`assistant`,content:`已记录摘要。后续回复将基于摘要与最近对话继续。`},...a],summary:o,compacted:!0}}function yc(e){return/^\/compact(?:\s|$)/i.test(e.trim())}var bc=`你可以使用会话目标工具:
|
|
236
|
+
- goal_get:读取本会话当前目标
|
|
237
|
+
- goal_set:设定或更新目标(status=active)
|
|
238
|
+
- goal_done:将目标标为已完成
|
|
239
|
+
- goal_clear:清除目标
|
|
240
|
+
有活跃目标时应围绕其推进;重大偏离前用 ask_user_question 或更新目标。
|
|
241
|
+
系统可能在目标未完成时自动续轮(goal-round-driver);完成后务必 goal_done,避免空转。`,xc=[{type:`function`,function:{name:`goal_get`,description:`Get the current session goal (text + status).`,parameters:{type:`object`,properties:{}}}},{type:`function`,function:{name:`goal_set`,description:`Set or replace the session goal. Marks it active.`,parameters:{type:`object`,properties:{text:{type:`string`,description:`Goal statement for this session`}},required:[`text`]}}},{type:`function`,function:{name:`goal_done`,description:`Mark the current session goal as done.`,parameters:{type:`object`,properties:{}}}},{type:`function`,function:{name:`goal_clear`,description:`Clear the session goal.`,parameters:{type:`object`,properties:{}}}}];function Sc(e){if(!e||typeof e!=`object`)return null;let t=e,n=String(t.text??``).trim();if(!n)return null;let r=t.status===`done`||t.status===`cleared`||t.status===`active`?t.status:`active`;return{text:n.slice(0,500),status:r,updatedAt:typeof t.updatedAt==`number`?t.updatedAt:Date.now()}}function Cc(e){return!e||e.status===`cleared`||!e.text?JSON.stringify({ok:!0,goal:null}):JSON.stringify({ok:!0,goal:{text:e.text,status:e.status}})}function wc(e){return!e||e.status!==`active`?null:e.text.trim()||null}function Tc(e){let t=e.trim();if(!/^\/goal(?:\s|$)/i.test(t))return null;let n=t.replace(/^\/goal\s*/i,``).trim();if(!n)return{kind:`show`};if(/^clear\b/i.test(n))return{kind:`clear`};if(/^done\b/i.test(n))return{kind:`done`};if(/^set\s+/i.test(n)){let e=n.replace(/^set\s+/i,``).trim();return e?{kind:`set`,text:e}:{kind:`show`}}return{kind:`set`,text:n}}function Ec(e){return Tc(e)!=null}var Dc=`[goal-round-driver]`;function Oc(e,t,n){return`${Dc} 续轮 ${t}/${n}:请继续推进目标「${e.trim().slice(0,200)}」。若已完成请调用 goal_done;若阻塞请说明原因或 ask_user_question,勿空转重复相同工具。`}function kc(e){return e.trimStart().startsWith(Dc)}function Ac(e){let t=Math.max(1,Math.floor(e.maxRounds??3));return!(!e.goalActive||!e.turnOk||e.aborted||e.hasFollowUp||e.askUserPending||e.roundsUsed>=t)}function jc(e){return e.trim().replace(/[\\/:*?"<>|]+/g,`_`).replace(/\s+/g,` `).slice(0,48)||`session`}function Mc(e){if(!e||typeof e!=`object`)return{raw:e};let t=e,n={role:t.role,content:(t.content,t.content)};return typeof t.reasoning==`string`&&t.reasoning&&(n.reasoning=t.reasoning),typeof t.time==`number`&&(n.time=t.time),typeof t.model==`string`&&(n.model=t.model),t.usage&&typeof t.usage==`object`&&(n.usage=t.usage),typeof t.scheduleId==`string`&&(n.scheduleId=t.scheduleId),Array.isArray(t.attachments)&&(n.attachments=t.attachments.map(e=>{if(!e||typeof e!=`object`)return e;let t=e;return{name:t.name,size:t.size,type:t.type}})),Array.isArray(t.images)&&(n.images=t.images.map(e=>{if(!e||typeof e!=`object`)return e;let t=e;return{id:t.id,name:t.name,omittedDataUrl:!0}})),Array.isArray(t.refs)&&(n.refs=t.refs),n}var Nc=`lantern-harness-session-v1`;function Pc(e){return{exportedAt:new Date().toISOString(),format:Nc,session:{id:e.id,title:e.title,createdAt:e.createdAt,updatedAt:e.updatedAt,archived:e.archived,pinned:e.pinned,workspacePath:e.workspacePath,goal:e.goal,todos:e.todos,messages:(e.messages??[]).map(Mc)}}}function Fc(e){return`${JSON.stringify(Pc(e),null,2)}\n`}function Ic(e){let t=[];t.push(JSON.stringify({type:`session`,exportedAt:new Date().toISOString(),id:e.id,title:e.title,createdAt:e.createdAt,updatedAt:e.updatedAt,workspacePath:e.workspacePath,goal:e.goal}));for(let n of e.messages??[])t.push(JSON.stringify({type:`message`,sessionId:e.id,...Mc(n)}));return`${t.join(`
|
|
242
|
+
`)}\n`}function Lc(e,t,n){let r=new Blob([t],{type:n}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=e,a.rel=`noopener`,document.body.appendChild(a),a.click(),a.remove(),URL.revokeObjectURL(i)}function Rc(e,t=`json`){if(typeof document>`u`)return{ok:!1,error:`download requires browser`};let n=new Date().toISOString().replace(/[:.]/g,`-`).slice(0,19),r=`session-${jc(e.title)}-${n}`;if(t===`jsonl`){let t=`${r}.jsonl`;return Lc(t,Ic(e),`application/x-ndjson;charset=utf-8`),{ok:!0,filename:t}}let i=`${r}.json`;return Lc(i,Fc(e),`application/json;charset=utf-8`),{ok:!0,filename:i}}var zc=`tw-session-schedules`,Bc=`/__tb_schedule`,Vc=`你可以使用定时提醒工具:
|
|
243
|
+
- schedule_create:创建提醒(text + dueAt ISO 或 delayMinutes)
|
|
244
|
+
- schedule_list:列出本会话未取消的提醒
|
|
245
|
+
- schedule_update:修改 text / dueAt
|
|
246
|
+
- schedule_cancel:取消提醒
|
|
247
|
+
本地服务在线时提醒落盘并由主机到点写入原会话;否则仅页面打开时投递。`,Hc=[{type:`function`,function:{name:`schedule_create`,description:`Create a session reminder. Provide dueAt (ISO datetime) or delayMinutes from now.`,parameters:{type:`object`,properties:{text:{type:`string`,description:`Reminder content`},dueAt:{type:`string`,description:`ISO 8601 datetime`},delayMinutes:{type:`number`,description:`Minutes from now (alternative to dueAt)`}},required:[`text`]}}},{type:`function`,function:{name:`schedule_list`,description:`List scheduled reminders for the current session.`,parameters:{type:`object`,properties:{includeDelivered:{type:`boolean`}}}}},{type:`function`,function:{name:`schedule_update`,description:`Update a scheduled reminder text and/or dueAt.`,parameters:{type:`object`,properties:{id:{type:`string`},text:{type:`string`},dueAt:{type:`string`},delayMinutes:{type:`number`}},required:[`id`]}}},{type:`function`,function:{name:`schedule_cancel`,description:`Cancel a scheduled reminder.`,parameters:{type:`object`,properties:{id:{type:`string`}},required:[`id`]}}}];function Uc(){return`sch_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,7)}`}var Wc=null;async function Gc(){try{let e=await fetch(`${Bc}/health`,{signal:AbortSignal.timeout(1500)});return e.ok?(Wc=!!(await e.json()).ok,Wc):(Wc=!1,!1)}catch{return Wc=!1,!1}}function Kc(){try{let e=localStorage.getItem(l(zc));if(!e)return[];let t=JSON.parse(e);return Array.isArray(t)?t.map(e=>Jc(e)).filter(e=>!!e):[]}catch{return[]}}function qc(e){localStorage.setItem(l(zc),JSON.stringify(e.slice(-200)))}function Jc(e){if(!e||typeof e!=`object`)return null;let t=e,n=String(t.id??``).trim(),r=String(t.sessionId??``).trim(),i=String(t.text??``).trim(),a=Number(t.dueAt);if(!n||!r||!i||!Number.isFinite(a))return null;let o=t.status===`delivered`||t.status===`cancelled`||t.status===`scheduled`?t.status:`scheduled`;return{id:n,sessionId:r,text:i.slice(0,500),dueAt:a,status:o,createdAt:Number(t.createdAt)||Date.now(),updatedAt:Number(t.updatedAt)||Date.now()}}function Yc(e){if(typeof e.delayMinutes==`number`&&Number.isFinite(e.delayMinutes)){let t=Math.max(.1,e.delayMinutes);return Date.now()+Math.round(t*6e4)}let t=String(e.dueAt??``).trim();if(!t)return null;let n=Date.parse(t);return Number.isFinite(n)?n:null}function Xc(e,t=!1){return Kc().filter(t=>t.sessionId===e).filter(e=>t||e.status===`scheduled`).sort((e,t)=>e.dueAt-t.dueAt)}function Zc(e,t){let n=String(t.text??``).trim();if(!n)return{ok:!1,error:`text is required`};if(!e)return{ok:!1,error:`no active session`};let r=Yc(t);if(r==null)return{ok:!1,error:`dueAt or delayMinutes is required`};if(r<Date.now()-5e3)return{ok:!1,error:`dueAt is in the past`};let i=Date.now(),a={id:Uc(),sessionId:e,text:n.slice(0,500),dueAt:r,status:`scheduled`,createdAt:i,updatedAt:i},o=Kc();return o.push(a),qc(o),{ok:!0,reminder:a}}function Qc(e,t){let n=String(t.id??``).trim();if(!n)return{ok:!1,error:`id is required`};let r=Kc(),i=r.findIndex(t=>t.id===n&&t.sessionId===e);if(i<0)return{ok:!1,error:`reminder not found`};let a=r[i];if(a.status!==`scheduled`)return{ok:!1,error:`cannot update status=${a.status}`};let o=a.dueAt;if(t.dueAt!=null||t.delayMinutes!=null){let e=Yc(t);if(e==null)return{ok:!1,error:`invalid dueAt / delayMinutes`};o=e}let s=t.text==null?a.text:String(t.text).trim();if(!s)return{ok:!1,error:`text cannot be empty`};let c={...a,text:s.slice(0,500),dueAt:o,updatedAt:Date.now()};return r[i]=c,qc(r),{ok:!0,reminder:c}}function $c(e,t){let n=String(t??``).trim();if(!n)return{ok:!1,error:`id is required`};let r=Kc(),i=r.findIndex(t=>t.id===n&&t.sessionId===e);if(i<0)return{ok:!1,error:`reminder not found`};let a={...r[i],status:`cancelled`,updatedAt:Date.now()};return r[i]=a,qc(r),{ok:!0,reminder:a}}function el(e=Date.now()){let t=Kc(),n=[],r=!1;for(let i=0;i<t.length;i++){let a=t[i];if(a.status===`scheduled`&&a.dueAt<=e){let o={...a,status:`delivered`,updatedAt:e};t[i]=o,n.push(o),r=!0}}return r&&qc(t),n}function tl(e,t){return`⏰ 定时提醒:${e}\n<!--tb-schedule:${t}-->`}async function nl(e,t){try{let n=await fetch(`${Bc}${e}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t),signal:AbortSignal.timeout(8e3)});return n.ok?await n.json():null}catch{return null}}async function rl(){if(Wc!==!1){let e=await nl(`/claim`,{});if(e&&e.ok)return Wc=!0,Array.isArray(e.reminders)?e.reminders.map(Jc).filter(e=>!!e):[];if(Wc===!0)return el();if(await Gc(),Wc){let e=await nl(`/claim`,{});if(e&&e.ok&&Array.isArray(e.reminders))return e.reminders.map(Jc).filter(e=>!!e)}}return el()}async function il(e,t,n){let r={};try{r=JSON.parse(t||`{}`)}catch{return JSON.stringify({error:`invalid JSON arguments`})}if(Wc??await Gc()){if(e===`schedule_create`){let e=await nl(`/create`,{...r,sessionId:n});if(e)return JSON.stringify(e,null,2)}else if(e===`schedule_list`)try{let e=new URLSearchParams({sessionId:n,includeDelivered:r.includeDelivered?`1`:`0`}),t=await fetch(`${Bc}/list?${e}`,{signal:AbortSignal.timeout(5e3)});if(t.ok)return JSON.stringify(await t.json(),null,2)}catch{}else if(e===`schedule_update`){let e=await nl(`/update`,{...r,sessionId:n});if(e)return JSON.stringify(e,null,2)}else if(e===`schedule_cancel`){let e=await nl(`/cancel`,{id:r.id,sessionId:n});if(e)return JSON.stringify(e,null,2)}else return JSON.stringify({error:`unknown tool: ${e}`});Wc=!1}if(e===`schedule_create`)return JSON.stringify(Zc(n,r),null,2);if(e===`schedule_list`){let e=Xc(n,!!r.includeDelivered);return JSON.stringify({ok:!0,count:e.length,reminders:e},null,2)}return e===`schedule_update`?JSON.stringify(Qc(n,r),null,2):e===`schedule_cancel`?JSON.stringify($c(n,r.id),null,2):JSON.stringify({error:`unknown tool: ${e}`})}var al=[{id:`explore`,label:`探索`,description:`只读查文件 / 搜网页,汇总结论(不可写盘、无 bash)`,mode:`explore`},{id:`general`,label:`通用`,description:`可读写工作区文件 + 网页(无 bash、不可再派生子代理)`,mode:`general`}],ol=`你可以使用子代理工具(进程内;默认与主会话同模型,可在设置里改子代理模型):
|
|
248
|
+
- list_agents:列出可用预设与正在运行/最近完成的子代理
|
|
249
|
+
- spawn_subagent:派生子代理执行独立任务(默认等待完成;background=true 则后台跑)
|
|
250
|
+
- fork_subagent:带着当前对话上下文 fork 子代理并行干活
|
|
251
|
+
- subagent_list / subagent_await / subagent_abort:查看、等待、中断
|
|
252
|
+
适合可隔离的探索/子任务;主会话勿把全部工作塞给子代理。`,sl=[{type:`function`,function:{name:`list_agents`,description:`List available subagent presets and recent/running subagents.`,parameters:{type:`object`,properties:{includeRecent:{type:`boolean`,description:`Include recent finished agents (default true)`}}}}},{type:`function`,function:{name:`spawn_subagent`,description:`Spawn a subagent to run a focused task. Default waits until done and returns the result.`,parameters:{type:`object`,properties:{agent:{type:`string`,description:`Preset id: explore | general (default explore)`},prompt:{type:`string`,description:`Task for the subagent`},background:{type:`boolean`,description:`If true, return id immediately; use subagent_await later`}},required:[`prompt`]}}},{type:`function`,function:{name:`fork_subagent`,description:`Fork a subagent with a slice of the current conversation context, then run a task.`,parameters:{type:`object`,properties:{agent:{type:`string`,description:`Preset id: explore | general`},prompt:{type:`string`,description:`Task for the forked subagent`},background:{type:`boolean`}},required:[`prompt`]}}},{type:`function`,function:{name:`subagent_list`,description:`List running and recent subagents for this page session.`,parameters:{type:`object`,properties:{includeDone:{type:`boolean`}}}}},{type:`function`,function:{name:`subagent_await`,description:`Wait for a background subagent to finish and return its result.`,parameters:{type:`object`,properties:{id:{type:`string`},timeoutMs:{type:`number`,description:`Default 120000`}},required:[`id`]}}},{type:`function`,function:{name:`subagent_abort`,description:`Abort a running subagent.`,parameters:{type:`object`,properties:{id:{type:`string`}},required:[`id`]}}}],cl=2,ll=6,ul=24,dl=12e3,fl=new Map,pl=new Map,ml=new Map;function hl(){return`sa_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,7)}`}function gl(e){let t=String(e??`explore`).trim()||`explore`;return al.find(e=>e.id===t)??al[0]}function _l(){let e=0;for(let t of fl.values())t.status===`running`&&e++;return e}function vl(){if(fl.size<=ul)return;let e=[...fl.values()].sort((e,t)=>e.updatedAt-t.updatedAt);for(let t of e){if(fl.size<=ul)break;t.status!==`running`&&(fl.delete(t.id),pl.delete(t.id),ml.delete(t.id))}}function yl(e){return{id:e.id,agent:e.agent,prompt:e.prompt.slice(0,200),forked:e.forked,status:e.status,createdAt:e.createdAt,updatedAt:e.updatedAt,result:e.result,error:e.error,toolCalls:e.toolCalls}}function bl(e,t){return e.mode===`explore`?`readonly`:t===`full`?`readwrite`:t}async function xl(e,t,n,r){let i=new AbortController;pl.set(e.id,i);let a=()=>i.abort();n.parentSignal?.addEventListener(`abort`,a);let o=0;try{if(i.signal.aborted||n.parentSignal?.aborted)throw new DOMException(`Aborted`,`AbortError`);let a=bl(t,n.access),s=[],c=`你是 Lantern Harness 子代理「${t.id}」(${t.label})。\n任务:独立完成用户交给你的子任务,给出简洁可核对的结论。\n- 不要声称自己是主会话;不要尝试再派生子代理或执行 shell\n- 工具轮次有限,优先检索再结论`;n.fsEnabled&&(s.push(...yt(a)),c+=`\n\n${At}`),n.webEnabled&&(s.push(...vt),c+=`\n\n${ht}`),s.length||(c+=`
|
|
253
|
+
(当前无 fs/web 工具,仅凭已有上下文回答。)`);let l=[{role:`system`,content:c}];if(r&&n.parentMessages?.length){let e=n.parentMessages.filter(e=>e.role===`user`||e.role===`assistant`).slice(-12).map(e=>({role:e.role,content:typeof e.content==`string`?e.content.slice(0,4e3):JSON.stringify(e.content).slice(0,4e3)}));l.push(...e)}l.push({role:`user`,content:`【子代理任务】\n${e.prompt}`}),n.onHint?.(`子代理 ${e.id}(${t.id})运行中…`);let u=``;for await(let t of me(n.settings,l,i.signal,{tools:s.length?s:void 0,maxToolRounds:4,thinking:!1,runTool:s.length?async(t,r)=>(o++,n.onHint?.(`子代理 ${e.id}: ${t}`),t.startsWith(`fs_`)?n.runFs(t,r,a):t.startsWith(`web_`)?n.runWeb(t,r):JSON.stringify({error:`subagent cannot use tool: ${t}`})):void 0}))t.type===`content`&&(u+=t.delta);let d=u.trim().slice(0,dl);e.status=`done`,e.result=d||`(子代理无文本输出)`,e.toolCalls=o,e.updatedAt=Date.now()}catch(t){let r=t instanceof DOMException&&t.name===`AbortError`||i.signal.aborted||!!n.parentSignal?.aborted;e.status=r?`aborted`:`error`,e.error=r?`aborted`:t instanceof Error?t.message:String(t),e.toolCalls=o,e.updatedAt=Date.now()}finally{n.parentSignal?.removeEventListener(`abort`,a),pl.delete(e.id),vl()}}function Sl(e,t,n,r,i){if(!e)return{ok:!1,error:`prompt is required`};if(_l()>=i)return{ok:!1,error:`too many running subagents (max ${i})`};let a=gl(t),o=Date.now(),s={id:hl(),agent:a.id,prompt:e.slice(0,4e3),forked:r,status:`running`,createdAt:o,updatedAt:o};fl.set(s.id,s);let c=xl(s,a,n,r).then(()=>s);return ml.set(s.id,c),{ok:!0,rec:s,job:c}}function Cl(e,t,n){let r=Sl(String(e.prompt??``).trim(),e.agent,t,n,cl);return r.ok?e.background===!0?(r.job.finally(()=>{}),JSON.stringify({ok:!0,id:r.rec.id,agent:r.rec.agent,status:`running`,forked:n,hint:`Use subagent_await to get the result`})):r.job.then(e=>JSON.stringify({ok:e.status===`done`,id:e.id,agent:e.agent,status:e.status,forked:e.forked,toolCalls:e.toolCalls??0,result:e.result,error:e.error},null,2)):JSON.stringify({ok:!1,error:r.error})}async function wl(e,t,n){let r=Sl(e.trim(),n?.agent??`explore`,t,!!n?.forked,ll);if(!r.ok)return{ok:!1,id:``,text:null,error:r.error};let i=await r.job;return i.status===`done`?{ok:!0,id:i.id,text:i.result??null}:{ok:!1,id:i.id,text:null,error:i.error??i.status}}function Tl(e=!0){return[...fl.values()].filter(t=>e||t.status===`running`).sort((e,t)=>t.updatedAt-e.updatedAt).map(yl)}function El(e){let t=String(e??``).trim();if(!t)return{ok:!1,error:`id is required`};let n=fl.get(t);return n?n.status===`running`?(pl.get(t)?.abort(),{ok:!0,record:{...yl(n),status:`aborted`}}):{ok:!0,record:yl(n)}:{ok:!1,error:`subagent not found`}}async function Dl(e,t){let n=String(e??``).trim();if(!n)return JSON.stringify({ok:!1,error:`id is required`});let r=typeof t==`number`&&Number.isFinite(t)?Math.min(Math.max(1e3,t),3e5):12e4,i=fl.get(n);if(!i)return JSON.stringify({ok:!1,error:`subagent not found`});if(i.status!==`running`)return JSON.stringify({ok:i.status===`done`,...yl(i)},null,2);let a=ml.get(n);if(!a)return JSON.stringify({ok:!1,error:`subagent waiter missing`});let o=await Promise.race([a,new Promise(e=>{setTimeout(()=>e(null),r)})]);return o?JSON.stringify({ok:o.status===`done`,...yl(o)},null,2):JSON.stringify({ok:!1,id:n,status:`running`,error:`timeout after ${r}ms`})}async function Ol(e,t,n){let r={};try{r=JSON.parse(t||`{}`)}catch{return JSON.stringify({error:`invalid JSON arguments`})}if(e===`list_agents`){let e=r.includeRecent!==!1;return JSON.stringify({ok:!0,presets:al,agents:Tl(e),running:_l(),maxConcurrent:cl},null,2)}return e===`subagent_list`?JSON.stringify({ok:!0,agents:Tl(r.includeDone!==!1),running:_l()},null,2):e===`subagent_abort`?JSON.stringify(El(r.id),null,2):e===`subagent_await`?await Dl(r.id,r.timeoutMs):e===`spawn_subagent`?await Promise.resolve(Cl(r,n,!1)):e===`fork_subagent`?await Promise.resolve(Cl(r,n,!0)):JSON.stringify({error:`unknown tool: ${e}`})}var kl=4e4,Al=5e4,jl=12,Ml=4,Nl=80,Pl=`你可以使用 workflow 工具(仅当用户明确要求工作流 / 大规模多代理编排时):
|
|
254
|
+
- 参数:meta{name,description,phases?}、script(纯 JS 函数体,可用 top-level await)、args?
|
|
255
|
+
- 脚本内钩子:agent(prompt, opts?)、parallel(fns)、pipeline(fns)、phase(name)、log(...)
|
|
256
|
+
- agent() 返回子代理结论文本,失败返回 null
|
|
257
|
+
- 一两个子任务请用 spawn_subagent / fork_subagent,勿滥用 workflow`,Fl=[{type:`function`,function:{name:`workflow`,description:`Run a JavaScript orchestration script that fans out subagents and returns a JSON value. Use ONLY when the user explicitly asks for a workflow or large multi-agent orchestration. Script body may use top-level await and helpers: agent, parallel, pipeline, phase, log. Example body: const xs = await parallel([() => agent("task A"), () => agent("task B")]); return xs.filter(Boolean);`,parameters:{type:`object`,properties:{meta:{type:`object`,description:`Workflow identity`,properties:{name:{type:`string`},description:{type:`string`},phases:{type:`array`,items:{type:`string`}}},required:[`name`,`description`]},script:{type:`string`,description:`Plain JavaScript body (no export). Globals: args, agent, parallel, pipeline, phase, log.`},args:{type:`object`,description:`JSON object exposed to the script as args (wrap arrays in a field)`}},required:[`meta`,`script`]}}}];function Il(){return`wf_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,7)}`}function Ll(e){if(!e||typeof e!=`object`)return{error:`meta is required`};let t=e,n=String(t.name??``).trim(),r=String(t.description??``).trim();if(!n)return{error:`meta.name is required`};if(!r)return{error:`meta.description is required`};let i=Array.isArray(t.phases)?t.phases.map(e=>String(e).trim()).filter(Boolean).slice(0,20):void 0;return{name:n.slice(0,80),description:r.slice(0,400),phases:i}}function Rl(e){return/\brequire\b|\bprocess\.|\bchild_process\b|\bfs\.|\bglobalThis\b|\bFunction\s*\(|\beval\s*\(|\bimport\s*\(|\bXMLHttpRequest\b|\blocalStorage\b|\bindexedDB\b|\bdocument\.|\bwindow\./.test(e)?`script uses disallowed APIs (browser/Node escape)`:null}async function zl(e,t,n,r){let i=Array(e.length),a=0;async function o(){for(;a<e.length;){if(r?.aborted)throw new DOMException(`Aborted`,`AbortError`);let t=a++;i[t]=await n(e[t],t)}}let s=Math.min(Math.max(1,t),e.length||1);return await Promise.all(Array.from({length:s},()=>o())),i}async function Bl(e,t,n,r){let i=Il(),a=[],o=[],s=0,c=jl,l=(...t)=>{let n=t.map(e=>{if(typeof e==`string`)return e;try{return JSON.stringify(e)}catch{return String(e)}}).join(` `);a.push(n.slice(0,500)),a.length>Nl&&a.splice(0,a.length-Nl),r.onHint?.(`workflow ${e.name}: ${n.slice(0,80)}`)},u=async(e,t)=>{if(r.parentSignal?.aborted)throw new DOMException(`Aborted`,`AbortError`);let n=String(e??``).trim();if(!n)return null;if(c<=0)return l(`agent budget exhausted`),null;c--,s++;let i=t?.label?` [${t.label}]`:``;l(`agent${i}: ${n.slice(0,120)}`);let a=await wl(n,r,{agent:t?.agent??`explore`,forked:!1});return a.ok?a.text:(l(`agent failed${i}: ${a.error??`error`}`),null)},d=async(e,t=Ml)=>{if(!Array.isArray(e))throw Error(`parallel() expects an array of functions`);return zl(e.slice(0,jl),Math.min(Ml,t||Ml),async e=>{if(typeof e!=`function`)return null;try{return await e()}catch(e){return l(`parallel task error`,e instanceof Error?e.message:String(e)),null}},r.parentSignal)},f=async e=>{if(!Array.isArray(e))throw Error(`pipeline() expects an array of functions`);let t=[];for(let n of e.slice(0,jl)){if(r.parentSignal?.aborted)throw new DOMException(`Aborted`,`AbortError`);if(typeof n!=`function`)t.push(null);else try{t.push(await n())}catch(e){l(`pipeline task error`,e instanceof Error?e.message:String(e)),t.push(null)}}return t},p=t=>{let n=String(t??``).trim()||`phase`;o.push(n.slice(0,80)),l(`phase: ${n}`),r.onHint?.(`workflow ${e.name} · ${n}`)},m=(...e)=>l(...e),h=Rl(t);if(h)return{ok:!1,kind:`foreground`,runId:i,name:e.name,agentsStarted:0,stopReason:`error`,error:h};if(t.length>kl)return{ok:!1,kind:`foreground`,runId:i,name:e.name,agentsStarted:0,stopReason:`error`,error:`script too long (max ${kl})`};try{let c=Object.getPrototypeOf(async function(){}).constructor,l=await new c(`args`,`agent`,`parallel`,`pipeline`,`phase`,`log`,`"use strict";\n${t}`)(n,u,d,f,p,m);if(r.parentSignal?.aborted)return{ok:!1,kind:`foreground`,runId:i,name:e.name,agentsStarted:s,stopReason:`cancelled`,error:`workflow run was cancelled`,logs:a,phases:o};let h=l===void 0?null:l;try{let e=JSON.stringify(h);h=e&&e.length>Al?{truncated:!0,preview:e.slice(0,Al)}:e===void 0?null:JSON.parse(e)}catch{h=String(h).slice(0,Al)}return{ok:!0,kind:`foreground`,runId:i,name:e.name,agentsStarted:s,result:h,stopReason:`completed`,logs:a,phases:o}}catch(t){let n=t instanceof DOMException&&t.name===`AbortError`||!!r.parentSignal?.aborted;return{ok:!1,kind:`foreground`,runId:i,name:e.name,agentsStarted:s,stopReason:n?`cancelled`:`error`,error:n?`workflow run was cancelled`:t instanceof Error?t.message:String(t),logs:a,phases:o}}}async function Vl(e,t,n){if(e!==`workflow`)return JSON.stringify({error:`unknown tool: ${e}`});let r={};try{r=JSON.parse(t||`{}`)}catch{return JSON.stringify({error:`invalid JSON arguments`})}let i=Ll(r.meta);if(`error`in i)return JSON.stringify({ok:!1,error:i.error});let a=String(r.script??``);if(!a.trim())return JSON.stringify({ok:!1,error:`script is required`});let o=r.args&&typeof r.args==`object`&&!Array.isArray(r.args)?r.args:{};n.onHint?.(`workflow "${i.name}" 启动…`);let s=await Bl(i,a,o,n);return s.ok?[`workflow "${s.name}" completed (${s.agentsStarted} agent${s.agentsStarted===1?``:`s`}).`,`Return value:`,JSON.stringify(s.result,null,2)].join(`
|
|
258
|
+
`):s.stopReason===`cancelled`?`Error: workflow run was cancelled${s.error&&s.error!==`workflow run was cancelled`?` (${s.error})`:``}`:`Error: workflow run failed: ${s.error??`unknown`}`}function Hl(e){return e===`md`?`Markdown`:e===`xlsx`||e===`xls`?`Excel`:e===`docx`||e===`doc`?`Word`:e===`dir`?`文件夹`:e===`file`?`文件`:e.toUpperCase()}function Ul(e,t){return!(t&&![e.title,e.category,e.id,e.description,e.path,e.format,Hl(e.format)].join(`
|
|
259
|
+
`).toLowerCase().includes(t)&&(t!==`excel`&&t!==`表格`&&t!==`xls`||e.format!==`xlsx`&&e.format!==`xls`)&&(t!==`word`&&t!==`文档`&&t!==`doc`||e.format!==`docx`&&e.format!==`doc`)&&(t!==`md`&&t!==`markdown`&&t!==`标记`||e.format!==`md`))}var Wl=`用户可能通过「@」引用了知识库与模板下的 Markdown / Excel / Word 等文档(消息中会列出路径)。仅当用户引用了文档,或问题明显依赖知识库/模板时,再调用 kb_read / kb_search;一般闲聊或无关问题不要为了凑答去检索。读取时:Markdown 为全文,Excel/Word 为字段或元数据摘要;不要臆造未读到的正文。`,Gl=[{type:`function`,function:{name:`kb_search`,description:`在知识库与模板(含 Markdown、Excel、Word)中按关键词搜索,返回 path、标题、格式与摘要。`,parameters:{type:`object`,properties:{query:{type:`string`,description:`搜索关键词,如 接口、excel、用例`},scope:{type:`string`,enum:[`all`,`knowledge`,`templates`],description:`限定范围,默认 all`}},required:[`query`]}}},{type:`function`,function:{name:`kb_read`,description:`按 path 读取文档。Markdown 返回全文;Excel/Word 返回构建期摘要。path 如 测试模板库/接口测试用例/接口测试用例模版.xlsx 或 知识库管理/xxx.md`,parameters:{type:`object`,properties:{path:{type:`string`,description:`相对路径(与引用列表中的 path 一致)`}},required:[`path`]}}}];function Kl(e){return e.trim().replace(/^\/+/,``).replace(/\\/g,`/`)}function ql(e,t){let n=Kl(t),r=n.replace(/\.md$/i,``);return e.find(e=>{let t=Kl(e.path);return t===n||t===`${r}.md`||`${e.collection}/${e.id}`===n||`${e.collection}/${e.id}.md`===n||e.id===n||e.id===r})}async function Jl(e,t,n){let r={};try{r=JSON.parse(t||`{}`)}catch{return JSON.stringify({error:`invalid JSON arguments`})}let i=typeof n.base==`string`&&n.base?n.base:`/`,a=i.endsWith(`/`)?i:`${i}/`;try{switch(e){case`kb_search`:{let e=String(r.query??``).trim().toLowerCase(),t=String(r.scope??`all`);if(!e)return JSON.stringify({error:`query required`,results:[]});let i=n.docs.filter(e=>t===`all`||e.collection===t).filter(t=>Ul(t,e)).slice(0,12).map(e=>({path:e.path,title:e.title,category:e.category,collection:e.collection,format:e.format,snippet:e.description||e.category}));return JSON.stringify({results:i,count:i.length})}case`kb_read`:{let e=ql(n.docs,String(r.path??``));if(!e)return JSON.stringify({error:`未找到文档;请使用 kb_search 返回的 path`,path:String(r.path??``)});if(e.attachText)return JSON.stringify({path:e.path,title:e.title,category:e.category,format:e.format,content:e.attachText,note:`Office 模板返回构建期摘要,非完整二进制内容`});let t=`${a}raw/${e.collection}/${e.id}.md`,i=await fetch(t);if(!i.ok)return JSON.stringify({error:`读取失败 HTTP ${i.status}`,path:e.path});let o=await i.text();return JSON.stringify({path:e.path,title:e.title,category:e.category,format:e.format,content:o})}default:return JSON.stringify({error:`unknown tool: ${e}`})}}catch(e){return JSON.stringify({error:e instanceof Error?e.message:String(e)})}}var Yl=10485760,Xl=new Set([`png`,`jpg`,`jpeg`,`webp`,`gif`]),Zl=new Set([`xlsx`,`xls`,`xlsm`,`xlsb`,`ods`]),Ql=new Set([`docx`]),$l=new Set(`md.markdown.txt.text.json.csv.tsv.yaml.yml.xml.html.htm.log.sql.feature.toml.ini.conf.properties.rst.css.js.ts.tsx.jsx.py.java.go.rs.sh.bash.zsh.env.gitignore.dockerfile.makefile.svg`.split(`.`)),eu=[...$l,...Xl,...Zl,...Ql,`doc`,`pdf`];function tu(e){let t=e.lastIndexOf(`.`);return t>=0?e.slice(t+1).toLowerCase():``}async function nu(e){let t=await e.arrayBuffer(),n=N(t,{type:`array`}),r=[`# ${e.name}`,`工作表数:${n.SheetNames.length}`,``];for(let e of n.SheetNames){let t=n.Sheets[e];if(!t)continue;let i=ae.sheet_to_csv(t);r.push(`## ${e}`,i.trim()||`(空表)`,``)}return r.join(`
|
|
260
|
+
`).trim()}async function ru(t){let n=await Fe(()=>import(`./lib.DJNDi_Ht.js`).then(t=>e(t.default,1)),__vite__mapDeps([0,1,2,3])),r=await t.arrayBuffer(),i=await n.extractRawText({arrayBuffer:r}),a=(i.value??``).trim(),o=[`# ${t.name}`,``];return i.messages?.length&&o.push(`(解析备注:${i.messages.slice(0,3).map(e=>e.message).join(`;`)})`,``),o.push(a||`(未提取到正文)`),o.join(`
|
|
261
|
+
`)}async function iu(e){let t=tu(e.name);if(!t)throw Error(`${e.name}:无法识别扩展名`);if(e.size>10485760)throw Error(`${e.name}:超过 ${Math.round(Yl/1024/1024)} MB`);if(Xl.has(t)||e.type.startsWith(`image/`))return{kind:`image`,file:e};if(Zl.has(t))return{kind:`text`,name:e.name,size:e.size,content:await nu(e)};if(Ql.has(t))return{kind:`text`,name:e.name,size:e.size,content:await ru(e)};if(t===`doc`)throw Error(`${e.name}:旧版 .doc 请另存为 .docx 后再添加`);if(t===`pdf`)throw Error(`${e.name}:PDF 暂不解析正文,请转 Markdown/图片后添加`);if($l.has(t)||e.type.startsWith(`text/`)||e.type===`application/json`)return{kind:`text`,name:e.name,size:e.size,content:await e.text()};throw Error(`${e.name}:暂不支持的类型 .${t}`)}var au=[{prefix:`知识库管理`,aliases:[`knowledge`],collection:`knowledge`,category:`知识库`},{prefix:`用例管理`,aliases:[`cases`],collection:`cases`,category:`用例`},{prefix:`提示词管理`,aliases:[`prompts`],collection:`prompts`,category:`提示词`},{prefix:`测试模板库`,aliases:[`templates`],collection:`templates`,category:`模板`}];function ou(e){return e.replace(/\\/g,`/`).replace(/\/+/g,`/`)}function su(e){let t=ou(e),n=t.lastIndexOf(`/`);return n>=0?t.slice(n+1):t}function cu(e){let t=e.lastIndexOf(`.`);return t>=0?e.slice(t+1).toLowerCase():`file`}function lu(e){let t=e.trim();if(!/^file:/i.test(t))return null;try{let e=new URL(t),n=decodeURIComponent(e.pathname||``);return/^\/[A-Za-z]:\//.test(n)&&(n=n.slice(1)),ou(n)}catch{return null}}function uu(e){let t=ou(e);return t.startsWith(`/`)||/^[A-Za-z]:\//.test(t)}function du(e){let t=e.trim();return!t||t.includes(`
|
|
262
|
+
`)||/\s/.test(t)||t.includes(`://`)||t.includes(`/`)||t.includes(`\\`)?!1:/\.[A-Za-z0-9]{1,16}$/.test(t)}function fu(e){let t=e.trim();return!t||t.includes(`
|
|
263
|
+
`)?!1:!!(/^file:/i.test(t)||uu(t)||(t.includes(`/`)||t.includes(`\\`))&&!/\s/.test(t)&&t.length<512)}function pu(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=lu(n);r?t.push(r):uu(n)&&t.push(ou(n))}let r=(e.getData(`text/plain`)||``).trim();if(r&&!r.includes(`
|
|
264
|
+
`)){let e=lu(r);e?t.push(e):fu(r)&&!du(r)&&t.push(ou(r))}return[...new Set(t)]}function mu(e){return{collection:e.collection,id:`${e.collection}:${e.path}`,title:e.title||su(e.path),category:e.category,path:e.path,format:e.format||cu(e.path)}}function hu(e,t){let n=ou(e),r=ou(t).replace(/\/$/,``);return n===r?``:n.startsWith(`${r}/`)?n.slice(r.length+1):null}function gu(e,t){let n=ou(e.trim()),r=lu(n);r&&(n=r);let i=t.projectRoot?ou(t.projectRoot):``,a=t.workspace?ou(t.workspace):``,o=n;if(i){let e=hu(n,i);e!=null&&(o=e)}for(let{prefix:e,aliases:t,collection:n,category:r}of au)for(let i of[e,...t??[]])if(o!==i&&o.startsWith(`${i}/`)){let e=o.slice(i.length+1);if(!e)continue;return mu({collection:n,path:e,title:su(e),category:r,format:cu(e)})}if(a){let e=hu(n,a);if(e!=null&&e!==``)return mu({collection:`workspace`,path:e,title:su(e),category:t.workspaceLabel||`工作区`,format:cu(e)})}if(!uu(o)&&o.includes(`/`)){let e=o.split(`/`)[0]||``,n=au.find(t=>t.prefix===e||t.aliases?.includes(e));if(n){let t=o.slice(e.length+1);if(t)return mu({collection:n.collection,path:t,title:su(t),category:n.category,format:cu(t)})}return mu({collection:`workspace`,path:o,title:su(o),category:t.workspaceLabel||`工作区`,format:cu(o)})}return null}function _u(e,t){let n=e.trim();if(!n)return null;let r=n.toLowerCase(),i=t.filter(e=>{let t=su(e.path).toLowerCase(),n=(e.title||``).toLowerCase();return t===r||n===r||e.path.toLowerCase()===r});return i.length===1?mu(i[0]):null}var Q=k(),vu=220;function yu({open:e,onClose:t,title:n,closeAriaLabel:r=`关闭面板`,children:i,footer:a}){let[o,s]=(0,H.useState)(e),[c,l]=(0,H.useState)(!1);return(0,H.useEffect)(()=>{if(e){s(!0);let e=window.requestAnimationFrame(()=>{window.requestAnimationFrame(()=>l(!0))});return()=>window.cancelAnimationFrame(e)}l(!1);let t=window.setTimeout(()=>s(!1),vu);return()=>window.clearTimeout(t)},[e]),(0,H.useEffect)(()=>{if(!e)return;function n(e){e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),t())}return window.addEventListener(`keydown`,n,!0),()=>window.removeEventListener(`keydown`,n,!0)},[e,t]),o?(0,Q.jsxs)(`div`,{className:`fixed inset-0 z-60 flex justify-end`,role:`dialog`,"aria-modal":`true`,children:[(0,Q.jsx)(`button`,{type:`button`,className:`absolute inset-0 bg-stone-900/30 transition-opacity duration-200 ease-out ${c?`opacity-100`:`opacity-0`}`,"aria-label":r,onClick:t}),(0,Q.jsxs)(`aside`,{className:`tw-slide-over relative w-full max-w-md h-full shadow-2xl border-l border-stone-200 flex flex-col transition-transform duration-200 ease-out will-change-transform ${c?`translate-x-0`:`translate-x-full`}`,children:[(0,Q.jsxs)(`header`,{className:`shrink-0 h-12 px-4 border-b border-stone-100 flex items-center gap-2`,children:[(0,Q.jsx)(`h2`,{className:`tw-slide-over-title text-sm font-semibold text-stone-800 flex-1`,children:n}),(0,Q.jsx)(`button`,{type:`button`,onClick:t,className:`tw-icon-btn w-8 h-8 rounded-lg`,"data-hint":`关闭(Esc)`,children:`✕`})]}),(0,Q.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4 space-y-4`,children:i}),a]})]}):null}var bu=[{value:`md`,label:`Markdown 表格`},{value:`xlsx`,label:`Excel`},{value:`csv`,label:`CSV`}];async function xu(e,t){let n=t.find(t=>t.id===e)?.templateFolder??ee(e).templateFolder;try{let{entries:e}=await be(`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=[...de],i=``;try{if(t.endsWith(`.xlsx`)||t.endsWith(`.xls`)){let t=await ge(`templates`,e.path);if(t.encoding===`base64`&&t.contentBase64){let e=M(t.contentBase64);n=e.headers,i=e.body}}else if(t.endsWith(`.csv`)){let t=await L(`templates`,e.path),r=ce(t.content);n=r.headers,i=r.body}else if(t.endsWith(`.md`)||t.endsWith(`.txt`)){let t=await L(`templates`,e.path),r=oe(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 Su(t){let n=t.toLowerCase();if(n.endsWith(`.md`)||n.endsWith(`.txt`)||n.endsWith(`.csv`))return(await L(`requirements`,t)).content;if(n.endsWith(`.docx`)){let n=await ge(`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 Fe(()=>import(`./lib.DJNDi_Ht.js`).then(t=>e(t.default,1)),__vite__mapDeps([0,1,2,3]))).extractRawText({arrayBuffer:i.buffer})).value??``).trim()}return``}function Cu({open:e,onClose:t,initial:n,onConfirm:r}){let[i,a]=(0,H.useState)(!1),[o,s]=(0,H.useState)([]),[l,u]=(0,H.useState)(n?.reqPath??``),[d,f]=(0,H.useState)(()=>D()),[p,h]=(0,H.useState)(n?.caseType??D()[0]?.id??`functional`),[g,v]=(0,H.useState)([]),[y,b]=(0,H.useState)(n?.templateId??``),[x,te]=(0,H.useState)([]),[ne,O]=(0,H.useState)(n?.promptPath??``),[re,k]=(0,H.useState)(n?.promptBody??``),[A,M]=(0,H.useState)([]),[ie,N]=(0,H.useState)(n?.knowledgePaths??[]),[ae,oe]=(0,H.useState)(n?.outputFormat??`xlsx`),[se,P]=(0,H.useState)(null),[ce,le]=(0,H.useState)(!1),[fe,F]=(0,H.useState)(null),[pe,me]=(0,H.useState)(``),[he,I]=(0,H.useState)(!1),[ge,_e]=(0,H.useState)(()=>_(`prompts`)),[ve,xe]=(0,H.useState)(()=>_(`knowledgeLib`)),[Se,Ce]=(0,H.useState)(()=>_(`requirements`)),[we,Ee]=(0,H.useState)(()=>_(`templates`)),De=(0,H.useMemo)(()=>g.find(e=>e.id===y)??g[0],[g,y]),Oe=d.find(e=>e.id===p)??d[0]??ee(p),ke=Oe.label;function Ae(e){let t=D();f(t),h(n=>{let r=e??n;return t.some(e=>e.id===r)?r:t[0]?.id??n})}function je(){try{fe===`add`?Ae(S(pe).id):fe===`edit`&&(w(p,pe),Ae(p)),F(null),me(``),P(null)}catch(e){P(e instanceof Error?e.message:String(e))}}(0,H.useEffect)(()=>{let e=()=>{_e(_(`prompts`)),xe(_(`knowledgeLib`)),Ce(_(`requirements`)),Ee(_(`templates`))},t=m(()=>e());return c().then(e),t},[]),(0,H.useEffect)(()=>{e&&(Ae(n?.caseType),u(n?.reqPath??``),h(n?.caseType??D()[0]?.id??`functional`),b(n?.templateId??``),O(n?.promptPath??``),k(n?.promptBody??``),N(n?.knowledgePaths??[]),oe(n?.outputFormat??`xlsx`),F(null),me(``),I(!1),P(null),(async()=>{let e=await ye(`templates`)&&await ye(`prompts`)&&await ye(`requirements`)&&await ye(`knowledge`);if(a(e),!e)return;async function t(e,n,r){let{entries:i}=await be(e,n);for(let n of i)n.type===`file`?r.push(n):await t(e,n.path,r)}if(!Se)s([]),u(``);else try{let e=[];await t(`requirements`,`.`,e),s(e),u(t=>t&&e.some(e=>e.path===t)?t:``)}catch{}if(!ve)M([]),N([]);else try{let e=[];await t(`knowledge`,`.`,e),e.sort((e,t)=>(t.mtime??0)-(e.mtime??0)),M(e),N(t=>t.filter(t=>e.some(e=>e.path===t)))}catch{}if(!ge)te([]),O(``),k(``);else try{let e=[];await t(`prompts`,`.`,e);let r=e.filter(e=>!Te(e.path));r.sort((e,t)=>(t.mtime??0)-(e.mtime??0)),te(r),O(e=>e&&r.some(t=>t.path===e)?e:n?.promptPath&&r.some(e=>e.path===n.promptPath)?n.promptPath:r.find(e=>e.path.includes(`功能测试用例提示词`))?.path??r[0]?.path??``)}catch{}})())},[e,n,ge,ve,Se]),(0,H.useEffect)(()=>{if(!e||!i)return;if(!we){v([]),b(``);return}let t=!1;return xu(p,d).then(e=>{t||(v(e),b(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,i,we,p,d,n?.templateId]),(0,H.useEffect)(()=>{ne?L(`prompts`,ne).then(e=>k(e.content)).catch(()=>k(``)):k(``)},[ne]);let Me=o.map(e=>({value:e.path,label:e.path})),Ne=g.map(e=>({value:e.id,label:e.title})),Pe=x.map(e=>({value:e.path,label:e.path.replace(/\.[^.]+$/,``)})),Fe=A.map(e=>({value:e.path,label:e.path.replace(/\.[^.]+$/,``)}));async function Ie(){le(!0),P(null);try{if(!ge){P(`请先在「我的插件」中启用「提示词管理」`);return}if(!ne||!re.trim()){P(`请先选择用例生成提示词(不再使用「默认提示词」或工作台系统提示词)`);return}let e=g.find(e=>e.id===y)??g[0],i=``;if(l)try{i=(await Su(l)).slice(0,12e3)}catch(e){P(e instanceof Error?e.message:String(e));return}let a=[];for(let e of ie)try{let t=await L(`knowledge`,e);a.push(`\n### 知识库:${e}\n${t.content.slice(0,6e3)}`)}catch{a.push(`\n### 知识库:${e}\n(无法读取)`)}r({active:!0,caseType:p,outputFormat:ae,reqPath:l||void 0,templateId:e?.id,templateTitle:e?.title,promptPath:ne,knowledgePaths:ie.length?[...ie]:void 0,templateHeaders:e?.headers?.length?e.headers:[...de],templateBody:[e?.body||``,i?`\n### 需求文档:${l}\n${i}`:``,...a].join(``).trim(),promptBody:re.trim(),confirmedAt:Date.now(),linkedCasePath:n?.linkedCasePath}),t()}finally{le(!1)}}return(0,Q.jsxs)(yu,{open:e,onClose:t,title:`生成测试用例 · 配置`,closeAriaLabel:`关闭生成测试用例面板`,footer:(0,Q.jsxs)(`footer`,{className:`shrink-0 p-4 border-t border-stone-100 flex items-center gap-2`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:t,className:`h-9 px-3 text-sm text-stone-600 rounded-lg hover:bg-stone-100`,children:`取消`}),(0,Q.jsx)(`button`,{type:`button`,disabled:ce||!i||!ge||!ne,onClick:()=>void Ie(),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,Q.jsx)(`div`,{className:`rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-sm text-amber-900`,children:`本地文档服务未就绪,无法读写文档库。`}),(0,Q.jsx)(`p`,{className:`text-xs text-stone-500 leading-5`,children:`按所选用例类型、模板与提示词生成可入库用例:确认后在主输入框描述需求并发送,输出结构化用例并写入用例库,可在「用例管理」中查看。`}),se?(0,Q.jsx)(`div`,{className:`text-sm text-red-700 bg-red-50 border border-red-200 rounded-lg px-3 py-2`,children:se}):null,(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,Q.jsx)(`div`,{className:`text-xs font-medium text-stone-500 flex-1`,children:`用例类型`}),(0,Q.jsx)(`button`,{type:`button`,className:`text-[11px] text-[#4176e6] hover:underline`,onClick:()=>{F(`add`),me(``),P(null),I(!1)},children:`新增`}),(0,Q.jsx)(`button`,{type:`button`,className:`text-[11px] text-stone-600 hover:underline`,onClick:()=>{F(`edit`),me(Oe.label),P(null),I(!1)},children:`编辑`}),he?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{className:`text-[11px] text-stone-500 shrink-0`,children:`确认删除?`}),(0,Q.jsx)(`button`,{type:`button`,className:`text-[11px] text-red-600 hover:underline shrink-0`,onClick:()=>{I(!1);try{let e=C(p);f(e),h(e[0]?.id??``),F(null),P(null)}catch(e){P(e instanceof Error?e.message:String(e))}},children:`确认`}),(0,Q.jsx)(`button`,{type:`button`,className:`text-[11px] text-stone-500 hover:underline shrink-0`,onClick:()=>I(!1),children:`取消`})]}):(0,Q.jsx)(`button`,{type:`button`,className:`text-[11px] text-red-600 hover:underline disabled:opacity-40`,disabled:d.length<=1,onClick:()=>{F(null),I(!0),P(null)},children:`删除`})]}),(0,Q.jsx)(j,{options:d.map(e=>({value:e.id,label:e.label})),value:p,onChange:e=>{h(e),I(!1)}}),fe?(0,Q.jsxs)(`div`,{className:`mt-2 rounded-lg border border-stone-200 bg-stone-50 p-2 space-y-2`,children:[(0,Q.jsx)(`label`,{className:`text-[11px] text-stone-500`,htmlFor:`cg-type-draft`,children:fe===`add`?`新类型名称`:`修改名称`}),(0,Q.jsx)(`input`,{id:`cg-type-draft`,value:pe,onChange:e=>me(e.target.value),placeholder:`如:安全测试`,className:`w-full h-8 px-2 text-sm rounded-md border border-stone-200 bg-white focus:outline-none focus:ring-2 focus:ring-[#4176e6]/40`,onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),je())}}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`button`,{type:`button`,className:`h-7 px-2.5 text-xs font-medium text-white bg-[#4176e6] rounded-md hover:bg-[#3565c7]`,onClick:je,children:`保存`}),(0,Q.jsx)(`button`,{type:`button`,className:`h-7 px-2.5 text-xs text-stone-600 rounded-md hover:bg-stone-200/80`,onClick:()=>{F(null),me(``)},children:`取消`})]}),(0,Q.jsx)(`p`,{className:`text-[10px] text-stone-400 leading-4`,children:`模板目录约定为「名称 + 用例」,如「安全测试」→ 测试模板库/安全测试用例/`})]}):null]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`div`,{className:`text-xs font-medium text-stone-500`,children:`输出格式`}),(0,Q.jsx)(j,{options:bu,value:ae,onChange:oe})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`div`,{className:`text-xs font-medium text-stone-500 mb-0.5`,children:`需求文档`}),(0,Q.jsx)(E,{options:Me,value:l,onChange:u,allowEmpty:!1,disabled:!Se,placeholder:Se?Me.length?`搜索并选择需求文档…`:`请先在需求文档库中上传`:`需求文档库未启用`}),Se?null:(0,Q.jsx)(`p`,{className:`mt-1 text-[11px] text-stone-400`,children:`请先在「我的插件」中启用「需求文档库」后再选择。`})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`div`,{className:`text-xs font-medium text-stone-500 mb-0.5`,children:[`用例模板`,(0,Q.jsxs)(`span`,{className:`ml-1 font-normal text-stone-400`,children:[`(`,ke,` · `,Oe.templateFolder,`)`]})]}),(0,Q.jsx)(E,{options:Ne,value:De?.id??``,onChange:b,allowEmpty:!1,disabled:!we,placeholder:we?Ne.length?`搜索并选择模板…`:`暂无「${Oe.templateFolder}」模板`:`测试模板库未启用`}),we?null:(0,Q.jsx)(`p`,{className:`mt-1 text-[11px] text-stone-400`,children:`请先在「我的插件」中启用「测试模板库」后再选择;未启用时按默认字段生成。`}),De?.headers?.length?(0,Q.jsx)(ue,{fields:De.headers}):null]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`div`,{className:`text-xs font-medium text-stone-500 mb-0.5`,children:`提示词`}),(0,Q.jsx)(E,{options:Pe,value:ne,onChange:O,allowEmpty:!1,disabled:!ge,placeholder:ge?Pe.length?`搜索并选择提示词…`:`请先在提示词管理中上传`:`提示词管理未启用`}),(0,Q.jsx)(`p`,{className:`mt-1 text-[11px] text-stone-400`,children:ge?`启用后主会话将只使用该提示词,不再叠加「系统提示词」。`:`请先在「我的插件」中启用「提示词管理」后再选择。`})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`div`,{className:`text-xs font-medium text-stone-500 mb-0.5`,children:`引用知识库(可多选)`}),(0,Q.jsx)(T,{options:Fe,values:ie,onChange:N,disabled:!ve,placeholder:ve?Fe.length?`选择知识库文档…`:`暂无知识库文档`:`知识库管理未启用`}),ve?null:(0,Q.jsx)(`p`,{className:`mt-1 text-[11px] text-stone-400`,children:`请先在「我的插件」中启用「知识库管理」后再引用。`})]})]})}function wu({open:e,onClose:t,initial:n,onConfirm:r}){let[i,a]=(0,H.useState)(!1),[o,s]=(0,H.useState)(``),[c,l]=(0,H.useState)(()=>Fo()),[u,d]=(0,H.useState)(Fo()[0]?.id??`case`),[f,p]=(0,H.useState)(null),[m,h]=(0,H.useState)(null),[g,_]=(0,H.useState)(``),[v,y]=(0,H.useState)(!1),b=c.find(e=>e.id===u)??c[0]??Io(u);function x(e){let t=Fo();l(t),d(n=>{let r=e??n;return t.some(e=>e.id===r)?r:t[0]?.id??n})}function S(){try{m===`add`?x(Ro(g).id):m===`edit`&&(zo(u,g),x(u)),h(null),_(``),p(null)}catch(e){p(e instanceof Error?e.message:String(e))}}(0,H.useEffect)(()=>{e&&(x(n?.kind),s(n?.titleHint??``),d(n?.kind??Fo()[0]?.id??`case`),h(null),_(``),y(!1),p(null),ye(`prompts`).then(a))},[e,n]);function C(){p(null),i?(r({active:!0,titleHint:o.trim(),kind:u,confirmedAt:Date.now(),linkedPromptPath:n?.linkedPromptPath}),t()):p(`本地文档服务未就绪,无法写入提示词库`)}return(0,Q.jsxs)(yu,{open:e,onClose:t,title:`生成提示词 · 配置`,closeAriaLabel:`关闭生成提示词面板`,footer:(0,Q.jsxs)(`footer`,{className:`shrink-0 p-4 border-t border-stone-100 flex items-center gap-2`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:t,className:`h-9 px-3 text-sm text-stone-600 rounded-lg hover:bg-stone-100`,children:`取消`}),(0,Q.jsx)(`button`,{type:`button`,disabled:!i,onClick:C,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,Q.jsx)(`div`,{className:`rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-sm text-amber-900`,children:`本地文档服务未就绪,无法读写提示词库。`}),(0,Q.jsx)(`p`,{className:`text-xs text-stone-500 leading-5`,children:`按所选类型生成可复用提示词:确认后在主输入框描述编写要求并发送,质检通过后写入提示词库,可在「提示词管理」中查看与引用。`}),f?(0,Q.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,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,Q.jsx)(`div`,{className:`text-xs font-medium text-stone-500 flex-1`,children:`提示词类型`}),(0,Q.jsx)(`button`,{type:`button`,className:`text-[11px] text-[#4176e6] hover:underline`,onClick:()=>{h(`add`),_(``),p(null),y(!1)},children:`新增`}),(0,Q.jsx)(`button`,{type:`button`,className:`text-[11px] text-stone-600 hover:underline`,onClick:()=>{h(`edit`),_(b.label),p(null),y(!1)},children:`编辑`}),v?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{className:`text-[11px] text-stone-500 shrink-0`,children:`确认删除?`}),(0,Q.jsx)(`button`,{type:`button`,className:`text-[11px] text-red-600 hover:underline shrink-0`,onClick:()=>{y(!1);try{let e=Bo(u);l(e),d(e[0]?.id??``),h(null),p(null)}catch(e){p(e instanceof Error?e.message:String(e))}},children:`确认`}),(0,Q.jsx)(`button`,{type:`button`,className:`text-[11px] text-stone-500 hover:underline shrink-0`,onClick:()=>y(!1),children:`取消`})]}):(0,Q.jsx)(`button`,{type:`button`,className:`text-[11px] text-red-600 hover:underline disabled:opacity-40`,disabled:c.length<=1,onClick:()=>{h(null),y(!0),p(null)},children:`删除`})]}),(0,Q.jsx)(j,{options:c.map(e=>({value:e.id,label:e.label})),value:u,onChange:e=>{d(e),y(!1)}}),(0,Q.jsx)(`p`,{className:`mt-1 text-[11px] text-stone-400 leading-4 break-words`,children:b.hint}),m?(0,Q.jsxs)(`div`,{className:`mt-2 rounded-lg border border-stone-200 bg-stone-50 p-2 space-y-2`,children:[(0,Q.jsx)(`label`,{className:`text-[11px] text-stone-500`,htmlFor:`pg-kind-draft`,children:m===`add`?`新类型名称`:`修改名称`}),(0,Q.jsx)(`input`,{id:`pg-kind-draft`,value:g,onChange:e=>_(e.target.value),placeholder:`如:缺陷分析提示词`,className:`w-full h-8 px-2 text-sm rounded-md border border-stone-200 bg-white focus:outline-none focus:ring-2 focus:ring-[#4176e6]/40`,onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),S())}}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`button`,{type:`button`,className:`h-7 px-2.5 text-xs font-medium text-white bg-[#4176e6] rounded-md hover:bg-[#3565c7]`,onClick:S,children:`保存`}),(0,Q.jsx)(`button`,{type:`button`,className:`h-7 px-2.5 text-xs text-stone-600 rounded-md hover:bg-stone-200/80`,onClick:()=>{h(null),_(``)},children:`取消`})]})]}):null]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`label`,{className:`text-xs font-medium text-stone-500`,htmlFor:`pg-title`,children:`期望名称`}),(0,Q.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,Q.jsx)(`p`,{className:`mt-1.5 text-[11px] text-stone-400 leading-4`,children:`可填期望文件名;留空则由模型自拟。具体编写要求在主输入框描述。`})]})]})}function Tu({open:e,onClose:t,initial:n,onConfirm:r}){let[i,a]=(0,H.useState)(!1),[o,s]=(0,H.useState)(``),[c,l]=(0,H.useState)(()=>Xo()),[u,d]=(0,H.useState)(Xo()[0]??`测试规范`),[f,p]=(0,H.useState)(null),[m,h]=(0,H.useState)(null),[g,_]=(0,H.useState)(``),[v,y]=(0,H.useState)(!1);function b(e){let t=Xo();l(t),d(n=>{let r=e??n;return t.includes(r)?r:t[0]??n})}function x(){try{m===`add`?b(Qo(g)):m===`edit`&&b($o(u,g)),h(null),_(``),p(null)}catch(e){p(e instanceof Error?e.message:String(e))}}(0,H.useEffect)(()=>{e&&(b(n?.category),s(n?.titleHint??``),d(n?.category??Xo()[0]??`测试规范`),h(null),_(``),y(!1),p(null),ye(`knowledge`).then(a))},[e,n]);function S(){p(null),i?(r({active:!0,titleHint:o.trim(),category:u,confirmedAt:Date.now(),linkedKnowledgePath:n?.linkedKnowledgePath}),t()):p(`本地文档服务未就绪,无法写入知识库`)}return(0,Q.jsxs)(yu,{open:e,onClose:t,title:`生成知识库 · 配置`,closeAriaLabel:`关闭生成知识库面板`,footer:(0,Q.jsxs)(`footer`,{className:`shrink-0 p-4 border-t border-stone-100 flex items-center gap-2`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:t,className:`h-9 px-3 text-sm text-stone-600 rounded-lg hover:bg-stone-100`,children:`取消`}),(0,Q.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,Q.jsx)(`div`,{className:`rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-sm text-amber-900`,children:`本地文档服务未就绪,无法读写知识库。`}),(0,Q.jsx)(`p`,{className:`text-xs text-stone-500 leading-5`,children:`按所选分类沉淀测试规范、方法论或环境约定:确认后在主输入框粘贴/描述素材并发送,质检通过后写入知识库,可在「知识库管理」中查看与 @ 引用。`}),f?(0,Q.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,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,Q.jsx)(`div`,{className:`text-xs font-medium text-stone-500 flex-1`,children:`分类`}),(0,Q.jsx)(`button`,{type:`button`,className:`text-[11px] text-[#4176e6] hover:underline`,onClick:()=>{h(`add`),_(``),p(null),y(!1)},children:`新增`}),(0,Q.jsx)(`button`,{type:`button`,className:`text-[11px] text-stone-600 hover:underline`,onClick:()=>{h(`edit`),_(u),p(null),y(!1)},children:`编辑`}),v?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{className:`text-[11px] text-stone-500 shrink-0`,children:`确认删除?`}),(0,Q.jsx)(`button`,{type:`button`,className:`text-[11px] text-red-600 hover:underline shrink-0`,onClick:()=>{y(!1);try{let e=es(u);l(e),d(e[0]??``),h(null),p(null)}catch(e){p(e instanceof Error?e.message:String(e))}},children:`确认`}),(0,Q.jsx)(`button`,{type:`button`,className:`text-[11px] text-stone-500 hover:underline shrink-0`,onClick:()=>y(!1),children:`取消`})]}):(0,Q.jsx)(`button`,{type:`button`,className:`text-[11px] text-red-600 hover:underline disabled:opacity-40`,disabled:c.length<=1,onClick:()=>{h(null),y(!0),p(null)},children:`删除`})]}),(0,Q.jsx)(j,{options:c.map(e=>({value:e,label:e})),value:u,onChange:e=>{d(e),y(!1)}}),m?(0,Q.jsxs)(`div`,{className:`mt-2 rounded-lg border border-stone-200 bg-stone-50 p-2 space-y-2`,children:[(0,Q.jsx)(`label`,{className:`text-[11px] text-stone-500`,htmlFor:`kg-cat-draft`,children:m===`add`?`新分类名称`:`修改名称`}),(0,Q.jsx)(`input`,{id:`kg-cat-draft`,value:g,onChange:e=>_(e.target.value),placeholder:`如:安全基线`,className:`w-full h-8 px-2 text-sm rounded-md border border-stone-200 bg-white focus:outline-none focus:ring-2 focus:ring-[#4176e6]/40`,onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),x())}}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`button`,{type:`button`,className:`h-7 px-2.5 text-xs font-medium text-white bg-[#4176e6] rounded-md hover:bg-[#3565c7]`,onClick:x,children:`保存`}),(0,Q.jsx)(`button`,{type:`button`,className:`h-7 px-2.5 text-xs text-stone-600 rounded-md hover:bg-stone-200/80`,onClick:()=>{h(null),_(``)},children:`取消`})]}),(0,Q.jsx)(`p`,{className:`text-[10px] text-stone-400 leading-4`,children:`分类写入文档 frontmatter,文件平铺存放于 知识库管理/;改名不会自动迁移已有文件。`})]}):null]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`label`,{className:`text-xs font-medium text-stone-500`,htmlFor:`kg-title`,children:`期望名称`}),(0,Q.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,Q.jsx)(`p`,{className:`mt-1.5 text-[11px] text-stone-400 leading-4`,children:`可填期望文件名;留空则由模型自拟。素材与编写要求在主输入框描述。`})]})]})}var Eu={user:`用户档案`,memory:`长期记忆`,key:`项目关键记忆`,project:`项目日志`};function Du(e){return e?e.replace(/\\/g,`/`).replace(/^\/Users\/[^/]+/,`~`):``}var Ou={project:{title:`项目日志`,fileHint:`MEMORY.md`,desc:`项目进展流水账,按需查阅,默认不注入上下文。`,curated:!1},key:{title:`项目关键记忆`,fileHint:`KEY.md`,desc:`项目关键约定与事实;写入需经待确认记忆建议采纳后注入。`,curated:!0},memory:{title:`长期记忆`,fileHint:`MEMORY.md`,desc:`全局环境与跨项目事实,注入所有会话;写入需审查建议并经确认。`,curated:!0}},ku=[{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 Au({live:e,pluginOn:t,workspacePath:n=``}){let[r,i]=(0,H.useState)(`suggestions`),[a,o]=(0,H.useState)(null),[s,c]=(0,H.useState)({}),[l,u]=(0,H.useState)(``),[d,f]=(0,H.useState)([]),[p,m]=(0,H.useState)([]),[h,g]=(0,H.useState)(`memory`),[_,v]=(0,H.useState)(null),[y,b]=(0,H.useState)([]),[S,C]=(0,H.useState)(null),[w,ee]=(0,H.useState)(``),[T,E]=(0,H.useState)(!1),[D,te]=(0,H.useState)(null),[ne,O]=(0,H.useState)(null),[re,k]=(0,H.useState)(null),A=n.trim(),j=(0,H.useCallback)(async()=>{if(!e)o(null),c({}),f([]),b([]);else{C(null);try{let[e,t,n,i,a]=await Promise.all([Ot(),mt(A,`all`),pt(),ln(),gt().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 ft(h,A))}catch(e){C(e instanceof Error?e.message:String(e))}}},[e,A,r,h]);if((0,H.useEffect)(()=>{j()},[j]),!t)return(0,Q.jsxs)(`div`,{className:`h-full flex flex-col items-center justify-center text-center px-6`,children:[(0,Q.jsx)(`p`,{className:`text-sm text-stone-600`,children:`会话记忆未启用`}),(0,Q.jsx)(`p`,{className:`mt-1 text-xs text-stone-400`,children:`在「我的插件」中打开「会话记忆」后,可在此管理记忆轨与待确认记忆建议`})]});if(!e)return(0,Q.jsxs)(`div`,{className:`h-full flex flex-col items-center justify-center text-center px-6`,children:[(0,Q.jsx)(`p`,{className:`text-sm text-stone-600`,children:`会话记忆中间件未就绪`}),(0,Q.jsx)(`p`,{className:`mt-1 text-xs text-stone-400`,children:`本地记忆服务未就绪`})]});let M=r===`memory`||r===`key`,ie=r===`memory`||r===`key`||r===`project`,N=ie?s[r]?.entries??[]:[],ae=ie?s[r]?.path:null,oe=a?.path||`.lantern/local/memories`;async function se(e){E(!0);try{await z(e),await j()}catch(e){C(e instanceof Error?e.message:String(e))}finally{E(!1)}}async function P(e){E(!0);try{await St(e),await j()}catch(e){C(e instanceof Error?e.message:String(e))}finally{E(!1)}}function ce(e){M&&O(e)}async function le(){if(ne==null||!M)return;let e=ne;O(null),E(!0);try{await dn(r,e,A),await j()}catch(e){C(e instanceof Error?e.message:String(e))}finally{E(!1)}}async function ue(){if(re==null)return;let e=re;k(null),E(!0);try{await Rt(h,e,A),await j()}catch(e){C(e instanceof Error?e.message:String(e))}finally{E(!1)}}function de(e){te(e)}async function fe(){if(D==null)return;let e=D;te(null),E(!0);try{await un(r,e,A),await j()}catch(e){C(e instanceof Error?e.message:String(e))}finally{E(!1)}}async function F(){if(M&&w.trim()){E(!0);try{await wt(r,w.trim(),A),ee(``),await j()}catch(e){C(e instanceof Error?e.message:String(e))}finally{E(!1)}}}async function pe(e){E(!0);try{let t=await Tt(e);v(t)}catch(e){C(e instanceof Error?e.message:String(e))}finally{E(!1)}}function me(e){let t=Ou[e],n=e===`key`?`KEY.md`:t.fileHint,r=e===`key`?`项目关键记忆 ${n}`:e===`memory`?`长期记忆 ${n}`:t.title,i=Du(ae)||`${Du(oe)}/…/${n}`;return(0,Q.jsxs)(`div`,{className:`mb-3 space-y-1.5`,children:[(0,Q.jsxs)(`div`,{className:`flex items-start gap-2 flex-wrap min-w-0`,children:[(0,Q.jsx)(`h3`,{className:`text-sm font-semibold text-stone-800`,children:r}),t.curated?null:(0,Q.jsx)(`span`,{className:`px-1.5 py-0.5 text-[10px] rounded bg-stone-100 text-stone-500 border border-stone-200`,children:`只读追加`}),(0,Q.jsxs)(`span`,{className:`text-[11px] text-stone-400 tabular-nums`,children:[N.length,` 条`]}),(0,Q.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":ae||i,children:i})]}),(0,Q.jsx)(`p`,{className:`text-xs text-stone-500 leading-5 break-words`,children:t.desc}),A?(0,Q.jsxs)(`p`,{className:`text-[11px] text-stone-400 break-all`,children:[`当前会话工作目录:`,(0,Q.jsx)(`span`,{className:`font-mono`,children:A}),l?(0,Q.jsxs)(Q.Fragment,{children:[` · `,`项目 id `,(0,Q.jsx)(`span`,{className:`font-mono`,children:l.slice(0,12)})]}):null]}):null]})}return(0,Q.jsxs)(`div`,{className:`h-full flex flex-col min-h-0`,children:[(0,Q.jsxs)(`div`,{className:`shrink-0 flex flex-wrap items-center gap-2 px-4 py-2 border-b border-stone-200/80`,children:[ku.map(e=>(0,Q.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,Q.jsxs)(`span`,{className:`ml-1 tabular-nums`,children:[`(`,d.length,`)`]}):null]},e.id)),(0,Q.jsxs)(`span`,{className:`text-[11px] text-stone-400 tabular-nums`,children:[a?.entryCount??0,` 条 · 待确认 `,a?.suggestionCount??d.length]})]}),S?(0,Q.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:S}):null,(0,Q.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4`,children:[r===`guide`?(0,Q.jsxs)(`div`,{className:`space-y-3 max-w-2xl`,children:[(0,Q.jsxs)(`section`,{className:`rounded-xl border border-stone-200 bg-white p-4`,children:[(0,Q.jsx)(`h3`,{className:`text-sm font-semibold text-stone-800`,children:`确认制:为什么必须你点头`}),(0,Q.jsx)(`p`,{className:`mt-1.5 text-xs text-stone-500 leading-5`,children:`记忆会改变后续对话行为。长期记忆 / 项目关键记忆经「待确认记忆建议」采纳后才写入并注入;项目日志可直写但不注入。`})]}),(0,Q.jsxs)(`section`,{className:`rounded-xl border border-stone-200 bg-white p-4`,children:[(0,Q.jsx)(`h3`,{className:`text-sm font-semibold text-stone-800`,children:`待确认记忆建议:AI 只提议,你拍板`}),(0,Q.jsx)(`p`,{className:`mt-1.5 text-xs text-stone-500 leading-5`,children:`后台或对话中产出的记忆建议进入独立队列。采纳可写入对应轨;拒绝则丢弃。`}),(0,Q.jsxs)(`ul`,{className:`mt-2 space-y-1.5 text-xs text-stone-600`,children:[(0,Q.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,Q.jsx)(`li`,{className:`rounded-lg bg-stone-50 border border-stone-100 px-2.5 py-2`,children:`拒绝 → 丢弃,不落盘`})]})]}),(0,Q.jsxs)(`section`,{className:`rounded-xl border border-stone-200 bg-white p-4`,children:[(0,Q.jsx)(`h3`,{className:`text-sm font-semibold text-stone-800`,children:`各轨文件(对齐 dsh)`}),(0,Q.jsxs)(`ul`,{className:`mt-2 space-y-1.5 text-xs text-stone-600`,children:[(0,Q.jsx)(`li`,{className:`rounded-lg bg-stone-50 border border-stone-100 px-2.5 py-2`,children:`项目日志 · 项目目录 MEMORY.md(不注入)`}),(0,Q.jsx)(`li`,{className:`rounded-lg bg-stone-50 border border-stone-100 px-2.5 py-2`,children:`项目关键记忆 KEY.md(注入,需确认)`}),(0,Q.jsx)(`li`,{className:`rounded-lg bg-stone-50 border border-stone-100 px-2.5 py-2`,children:`长期记忆 MEMORY.md(注入,需确认)`}),(0,Q.jsx)(`li`,{className:`rounded-lg bg-stone-50 border border-stone-100 px-2.5 py-2`,children:`全局规则:展示工作区 AGENTS.md 等规则文件`})]})]}),(0,Q.jsxs)(`section`,{className:`rounded-xl border border-stone-200 bg-white p-4`,children:[(0,Q.jsx)(`h3`,{className:`text-sm font-semibold text-stone-800`,children:`编辑与维护`}),(0,Q.jsx)(`p`,{className:`mt-1.5 text-xs text-stone-500 leading-5`,children:`可在本 Tab 浏览条目、手动添加(注入轨)、归档或删除。文件为 § 分隔结构化记忆,用外部编辑器打开时请谨慎修改。`}),(0,Q.jsxs)(`p`,{className:`mt-2 text-[11px] text-amber-700/90`,children:[`存储目录:`,(0,Q.jsx)(`code`,{className:`font-mono`,children:oe})]})]})]}):null,r===`suggestions`?(0,Q.jsxs)(`div`,{className:`space-y-3`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h3`,{className:`text-sm font-semibold text-stone-800`,children:`待确认记忆建议`}),(0,Q.jsx)(`p`,{className:`mt-1 text-xs text-stone-500 leading-5`,children:`后台审查或对话沉淀产出的记忆建议:采纳后写入记忆文件并注入;拒绝则丢弃。`})]}),d.length===0?(0,Q.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,Q.jsx)(`ul`,{className:`space-y-3`,children:d.map(e=>(0,Q.jsxs)(`li`,{className:`rounded-lg border border-amber-200/80 bg-amber-50/30 p-3`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] text-stone-400 mb-1 flex-wrap`,children:[(0,Q.jsx)(`span`,{className:`px-1.5 py-0.5 rounded bg-amber-100 text-amber-900 border border-amber-200 font-medium`,children:`待确认记忆建议`}),(0,Q.jsx)(`span`,{className:`px-1.5 py-0.5 rounded bg-white text-stone-600 border border-stone-200`,children:Eu[e.target]??e.target}),(0,Q.jsx)(`span`,{children:e.time}),e.hits&&e.hits>1?(0,Q.jsxs)(`span`,{children:[`×`,e.hits]}):null]}),(0,Q.jsx)(`p`,{className:`text-sm text-stone-800 whitespace-pre-wrap`,children:e.content}),e.reason?(0,Q.jsxs)(`p`,{className:`mt-1 text-xs text-stone-500`,children:[`原因:`,e.reason]}):null,(0,Q.jsxs)(`div`,{className:`mt-2 flex gap-2`,children:[(0,Q.jsx)(`button`,{type:`button`,disabled:T,onClick:()=>void se(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,Q.jsx)(`button`,{type:`button`,disabled:T,onClick:()=>void P(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,Q.jsxs)(`div`,{className:`space-y-3`,children:[me(r),M?(0,Q.jsxs)(`div`,{className:`rounded-xl border border-stone-200 bg-white p-3 space-y-2`,children:[(0,Q.jsx)(`textarea`,{value:w,onChange:e=>ee(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,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Q.jsx)(`p`,{className:`text-[11px] text-stone-400`,children:`手动写入会直接落盘;重要偏好更推荐走「待确认记忆建议」。`}),(0,Q.jsx)(`button`,{type:`button`,disabled:T||!w.trim(),onClick:()=>void F(),className:`shrink-0 h-8 px-3 text-xs text-white bg-[#4176e6] rounded-lg disabled:opacity-40`,children:`保存`})]})]}):(0,Q.jsx)(`p`,{className:`text-xs text-stone-400`,children:`本轨由对话中 memory_append 自动追加,一般不注入上下文。`}),N.length===0?(0,Q.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,Q.jsx)(`ul`,{className:`space-y-2`,children:N.map(e=>(0,Q.jsxs)(`li`,{className:`rounded-lg border border-stone-200 bg-white px-3 py-2.5 flex gap-2`,children:[(0,Q.jsx)(`p`,{className:`flex-1 text-sm text-stone-800 whitespace-pre-wrap`,children:e.text}),(0,Q.jsxs)(`div`,{className:`shrink-0 self-start flex flex-col gap-0.5`,children:[M?(0,Q.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,Q.jsx)(`button`,{type:`button`,disabled:T,onClick:()=>void de(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,Q.jsxs)(`div`,{className:`space-y-3`,children:[(0,Q.jsx)(`h3`,{className:`text-sm font-semibold text-stone-800`,children:`全局规则`}),(0,Q.jsx)(`p`,{className:`text-xs text-stone-500 leading-5`,children:`工作区规则文件(AGENTS.md 等),随系统提示注入。`}),y.length===0?(0,Q.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,Q.jsx)(`ul`,{className:`space-y-2 w-full`,children:y.map(e=>{let t=Du(e.abs)||Du(e.path)||e.label||e.path||e.name;return(0,Q.jsx)(`li`,{className:`w-full`,children:(0,Q.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,Q.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,Q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`span`,{className:`block text-[15px] font-medium text-stone-800 break-all`,children:e.name||`AGENTS.md`}),(0,Q.jsx)(`span`,{className:`block text-xs text-stone-400 break-all font-mono mt-1`,children:t})]}),(0,Q.jsx)(`button`,{type:`button`,disabled:T,onClick:()=>{C(null),E(!0),Mt(e.path||e.name||`AGENTS.md`,je(),{abs:e.abs}).catch(e=>C(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,Q.jsxs)(`div`,{className:`space-y-3`,children:[(0,Q.jsx)(`div`,{className:`flex gap-2`,children:[`user`,`memory`,`key`].map(e=>(0,Q.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:Eu[e]??e},e))}),p.length===0?(0,Q.jsx)(`p`,{className:`text-sm text-stone-400 text-center py-10`,children:`暂无归档`}):(0,Q.jsx)(`ul`,{className:`space-y-2`,children:p.map(e=>(0,Q.jsxs)(`li`,{className:`rounded-lg border border-stone-200 bg-white px-3 py-2.5 flex gap-2`,children:[(0,Q.jsx)(`p`,{className:`flex-1 text-sm text-stone-800 whitespace-pre-wrap`,children:e.text}),(0,Q.jsxs)(`div`,{className:`shrink-0 self-start flex flex-col gap-0.5`,children:[(0,Q.jsx)(`button`,{type:`button`,disabled:T,onClick:()=>void(async()=>{E(!0);try{await ut(h,e.index,A),await j()}catch(e){C(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,Q.jsx)(`button`,{type:`button`,disabled:T,onClick:()=>k(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,Q.jsxs)(`div`,{className:`space-y-4 max-w-md`,children:[(0,Q.jsxs)(`label`,{className:`flex items-center justify-between gap-3 text-sm text-stone-700`,children:[(0,Q.jsx)(`span`,{children:`每回合注入 USER / MEMORY / KEY`}),(0,Q.jsx)(`input`,{type:`checkbox`,checked:_.injectMemory,onChange:e=>void pe({injectMemory:e.target.checked})})]}),(0,Q.jsxs)(`label`,{className:`flex items-center justify-between gap-3 text-sm text-stone-700`,children:[(0,Q.jsx)(`span`,{children:`收尾提示写 project`}),(0,Q.jsx)(`input`,{type:`checkbox`,checked:_.perTurnProjectWrites,onChange:e=>void pe({perTurnProjectWrites:e.target.checked})})]}),(0,Q.jsxs)(`label`,{className:`flex items-center justify-between gap-3 text-sm text-stone-700`,children:[(0,Q.jsx)(`span`,{children:`重要事实用 suggest(KEY)`}),(0,Q.jsx)(`input`,{type:`checkbox`,checked:_.perTurnKeyWrites,onChange:e=>void pe({perTurnKeyWrites:e.target.checked})})]}),(0,Q.jsxs)(`p`,{className:`text-xs text-stone-400 leading-5 break-all`,children:[`存储目录:`,(0,Q.jsx)(`code`,{className:`font-mono`,children:a?.path??`.lantern/local/memories`}),`。memory/key 经待确认记忆建议后注入;project 不注入。`]})]}):null]}),(0,Q.jsx)(x,{open:D!=null,title:`删除记忆`,message:`永久删除该条目?此操作不可恢复。`,confirmLabel:`删除`,cancelLabel:`取消`,danger:!0,onClose:()=>te(null),onConfirm:()=>void fe()}),(0,Q.jsx)(x,{open:ne!=null,title:`归档记忆`,message:`归档该条目?归档后不再注入上下文。`,confirmLabel:`归档`,cancelLabel:`取消`,onClose:()=>O(null),onConfirm:()=>void le()}),(0,Q.jsx)(x,{open:re!=null,title:`删除归档`,message:`永久删除该归档?此操作不可恢复。`,confirmLabel:`删除`,cancelLabel:`取消`,danger:!0,onClose:()=>k(null),onConfirm:()=>void ue()})]})}var ju=`/`,Mu=[{id:`all`,label:`全部待办`},{id:`open`,label:`未完成`},{id:`done`,label:`已完成`}],Nu={urgent_important:`bg-red-500`,important:`bg-amber-500`,urgent:`bg-orange-500`,normal:`bg-stone-300`},Pu={urgent_important:`text-red-600`,important:`text-amber-600`,urgent:`text-orange-600`,normal:`text-stone-500`};function Fu(){let e=new Date;return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`}function Iu(e){let t=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e);return t?`${t[1]}/${t[2]}/${t[3]}`:``}function Lu(e,t){let n=Iu(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 Ru(e){return[...e].filter(e=>e.status===`done`||e.status===`cancelled`).sort((e,t)=>e.updatedAt<t.updatedAt?1:-1).slice(0,30)}function zu(e,t,n){if(t===`done`)return[{key:`done`,label:`已完成 / 已取消`,items:Ru(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:Ru(e)}),c.filter(e=>e.items.length>0)}function Bu(e){let[t,n]=(0,H.useState)(null),[r,i]=(0,H.useState)(null),[a,o]=(0,H.useState)(`all`),[s,c]=(0,H.useState)({}),l=(0,H.useCallback)(async()=>{try{let e=await hn();n(e),i(null)}catch(e){i(e instanceof Error?e.message:String(e))}},[]);(0,H.useEffect)(()=>{l();let e=window.setInterval(()=>void l(),15e3);return()=>window.clearInterval(e)},[l]);let u=Fu(),d=(0,H.useMemo)(()=>t?zu(t,a,u):[],[t,a,u]),f=(0,H.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 _n(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,Q.jsxs)(`div`,{className:`h-full flex flex-col items-center justify-center text-center px-6`,children:[(0,Q.jsx)(`p`,{className:`text-sm text-stone-600`,children:`待办事项需要本地服务`}),(0,Q.jsx)(`p`,{className:`mt-1 text-xs text-stone-400`,children:`当前未就绪(仅 npm run dev / 本地一体服务可用)`})]}):(0,Q.jsxs)(`div`,{className:`h-full flex flex-col min-h-0`,children:[(0,Q.jsxs)(`div`,{className:`shrink-0 flex flex-wrap items-center gap-2 px-4 py-2 border-b border-stone-200/80`,children:[Mu.map(e=>(0,Q.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,Q.jsx)(`span`,{className:`ml-1 tabular-nums`,children:f.dueToday+f.overdue}):null]},e.id)),(0,Q.jsxs)(`span`,{className:`ml-auto text-[11px] text-stone-400 tabular-nums`,children:[`未完成 `,f.open,f.overdue?` · 逾期 ${f.overdue}`:``]}),(0,Q.jsx)(`a`,{href:`${ju}todos/`,className:`text-[11px] text-[#4176e6] hover:underline shrink-0`,children:`打开待办页 →`})]}),r?(0,Q.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,Q.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-4 py-3`,children:t===null?(0,Q.jsx)(`div`,{className:`h-full flex items-center justify-center`,children:(0,Q.jsx)(`span`,{className:`tw-lib-spin`,"aria-hidden":`true`})}):d.length===0?(0,Q.jsxs)(`div`,{className:`h-full flex flex-col items-center justify-center text-center px-6`,children:[(0,Q.jsx)(`p`,{className:`text-sm text-stone-500`,children:a===`all`?`当前空间还没有待办`:a===`done`?`还没有已完成的待办`:`当前没有未完成的待办`}),(0,Q.jsx)(`a`,{href:`${ju}todos/`,className:`mt-2 text-xs text-[#4176e6] hover:underline`,children:`去待办页新增 →`})]}):(0,Q.jsx)(`div`,{className:`space-y-4 max-w-3xl`,children:d.map(e=>(0,Q.jsxs)(`section`,{children:[(0,Q.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,Q.jsx)(`span`,{className:`text-stone-400 tabular-nums`,children:e.items.length})]}),(0,Q.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=Lu(e,u);return(0,Q.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,Q.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,Q.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,Q.jsx)(`path`,{d:`m4 10 4 4 8-9`})})}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.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,Q.jsx)(`span`,{className:`shrink-0 text-[11px] text-stone-400`,children:Sn[e.status]}):e.priority?(0,Q.jsxs)(`span`,{className:`flex shrink-0 items-center gap-1 text-[11px] ${Pu[e.priority]??`text-stone-400`}`,children:[(0,Q.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full ${Nu[e.priority]??`bg-stone-300`}`}),Nn[e.priority]]}):null]}),(0,Q.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,Q.jsx)(`span`,{className:`shrink-0 text-stone-400 tabular-nums`,children:n.due?`截止 ${n.due}`:`无截止日期`}),(0,Q.jsx)(`span`,{className:`shrink-0 text-stone-300`,children:`·`}),(0,Q.jsx)(`span`,{className:`shrink-0 tabular-nums ${n.tone}`,children:n.remain}),e.linkedTask?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{className:`shrink-0 text-stone-300`,children:`·`}),(0,Q.jsxs)(`span`,{className:`min-w-0 truncate ${t?`text-stone-400`:`text-stone-500`}`,children:[`任务 `,e.linkedTask]})]}):null]})]})]},e.id)})})]},e.key))})})]})}function Vu(e){return{title:``,status:e===`todo`?`pending`:`pool`,priority:``,taskId:``,linkedTask:``,startDate:pn(),dueDate:pn(),note:``}}function Hu(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`?Fn:jn,o=e===`todo`?bn:Mn,s=Vu(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 Uu(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 Wu=`text-[11px] font-medium text-stone-500`,Gu=`h-9 w-full rounded-lg border border-stone-200 px-2.5 text-[13px] text-stone-800 outline-none focus:border-[#4176e6]`;function Ku(e){let t=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e);return t?`${t[1]}/${t[2]}/${t[3]}`:``}function qu(e){return(0,Q.jsxs)(`div`,{className:`flex min-w-0 items-center justify-between gap-2`,children:[(0,Q.jsx)(`span`,{className:`shrink-0 text-[11px] text-stone-400`,children:e.label}),(0,Q.jsx)(`span`,{className:`min-w-0 truncate text-[12px] text-stone-700`,children:e.children})]})}function Ju(e){let[t,n]=(0,H.useState)(()=>e.items),[r,i]=(0,H.useState)(0),[a,o]=(0,H.useState)([]);(0,H.useEffect)(()=>{n(e.items),i(0)},[e.items]);let s=e.kind===`todo`,c=s,l=s?`待办`:`任务`,u=s?`待办事项`:`任务管理`,d=s&&e.tasksOn!==!1;(0,H.useEffect)(()=>{if(!d)return;let e=!0;return V().then(t=>{e&&o(t)}).catch(()=>{}),()=>{e=!1}},[d]);let f=s?Fn:jn,p=s?bn:Mn,m=(0,H.useMemo)(()=>f.map(e=>({value:e,label:s?Sn[e]:En[e]})),[s,f]),h=(0,H.useMemo)(()=>[{value:``,label:`未设置`},...p.map(e=>({value:e,label:s?Nn[e]:kn[e]}))],[s,p]),g=(0,H.useMemo)(()=>[{value:``,label:`不关联`},...a.filter(e=>e.status!==`closed`).map(e=>({value:e.id,label:e.title}))],[a]);function _(e,t){n(n=>n.map((n,r)=>r===e?{...n,...t}:n))}function v(e,n){let r=t[e],i=a.find(e=>e.id===n);i?_(e,{taskId:i.id,linkedTask:i.title,startDate:i.startDate||r?.startDate||``,dueDate:i.dueDate||r?.dueDate||``,priority:r?.priority||i.priority||``}):_(e,{taskId:``,linkedTask:``})}function y(e){n(t=>t.filter((t,n)=>n!==e))}let b=t.length>0&&t.every(e=>!!e.title.trim()),x=c&&r>=1,S=x?`所属任务的日期与紧急程度已带到第一页,可回去再调`:`确认后才会写入「${u}」`;return(0,Q.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,Q.jsxs)(`div`,{className:`shrink-0 px-5 pt-4`,children:[(0,Q.jsxs)(`div`,{className:`mb-1 flex items-center gap-2 text-[11px] leading-4 text-stone-400`,children:[(0,Q.jsxs)(`span`,{children:[`新增 `,t.length,` 条`,l]}),c?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{className:`text-stone-300`,children:`·`}),(0,Q.jsxs)(`span`,{className:`tabular-nums`,children:[`第 `,r+1,` / 2 步`]})]}):null]}),(0,Q.jsx)(`h3`,{className:`text-[15px] leading-5.5 font-medium text-stone-900`,children:x?`关联任务`:r===0?`确认内容后再添加到${u}`:u})]}),(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto overscroll-contain px-5 py-3`,children:(0,Q.jsxs)(`div`,{className:`space-y-3`,children:[t.map((e,n)=>{let r=a.find(t=>t.id===e.taskId);return(0,Q.jsx)(`div`,{className:`rounded-xl border border-stone-200 bg-stone-50/40 p-3`,children:x?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,Q.jsx)(`span`,{className:Wu,children:`所属任务`}),a.length?(0,Q.jsx)(j,{flat:!0,ariaLabel:`所属任务`,options:g,value:e.taskId,onChange:e=>v(n,e),className:`w-full`}):(0,Q.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,Q.jsxs)(`div`,{className:`mt-2 space-y-1.5 rounded-lg border border-stone-200 bg-white px-2.5 py-2`,children:[(0,Q.jsx)(qu,{label:`任务名称`,children:r.title}),(0,Q.jsx)(qu,{label:`状态`,children:En[r.status]??r.status}),(0,Q.jsx)(qu,{label:`紧急程度`,children:r.priority?kn[r.priority]:`未设置`}),(0,Q.jsx)(qu,{label:`开始日期`,children:Ku(r.startDate)||`未设置`}),(0,Q.jsx)(qu,{label:`结束日期`,children:Ku(r.dueDate)||`未设置`})]}):(0,Q.jsx)(`p`,{className:`mt-2 text-[11px] leading-4 text-stone-400`,children:`选中任务后,它的开始 / 结束日期与紧急程度会自动带到第一页。`})]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Q.jsx)(`input`,{value:e.title,onChange:e=>_(n,{title:e.target.value}),placeholder:s?`待办名称`:`任务名称`,className:`${Gu} bg-white`,autoFocus:n===0}),t.length>1?(0,Q.jsx)(`button`,{type:`button`,onClick:()=>y(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,Q.jsxs)(`div`,{className:`mt-2 grid grid-cols-2 gap-2`,children:[(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,Q.jsx)(`span`,{className:Wu,children:`状态`}),(0,Q.jsx)(j,{flat:!0,ariaLabel:s?`待办状态`:`任务状态`,options:m,value:e.status,onChange:e=>_(n,{status:e}),className:`w-full`})]}),(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,Q.jsx)(`span`,{className:Wu,children:`紧急程度`}),(0,Q.jsx)(j,{flat:!0,ariaLabel:`紧急程度`,options:h,value:e.priority,onChange:e=>_(n,{priority:e}),className:`w-full`})]}),(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,Q.jsx)(`span`,{className:Wu,children:`开始日期`}),(0,Q.jsx)(A,{value:e.startDate,onChange:e=>_(n,{startDate:e}),placeholder:`选择日期`,className:`h-9 rounded-lg border border-stone-200 bg-white px-2 text-[13px] tabular-nums`})]}),(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,Q.jsx)(`span`,{className:Wu,children:`截止日期`}),(0,Q.jsx)(A,{value:e.dueDate,onChange:e=>_(n,{dueDate:e}),placeholder:`选择日期`,className:`h-9 rounded-lg border border-stone-200 bg-white px-2 text-[13px] tabular-nums`})]})]}),(0,Q.jsxs)(`label`,{className:`mt-2 flex flex-col gap-1`,children:[(0,Q.jsx)(`span`,{className:Wu,children:`备注`}),(0,Q.jsx)(`input`,{value:e.note,onChange:e=>_(n,{note:e.target.value}),placeholder:`备注(可选)`,className:`${Gu} bg-white`})]})]})},n)}),t.length?null:(0,Q.jsx)(`p`,{className:`py-4 text-center text-[12px] text-stone-400`,children:`内容已清空,点「取消」放弃这次新增。`})]})}),(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between gap-3 border-t border-stone-100 px-5 py-3`,children:[(0,Q.jsx)(`span`,{className:`min-w-0 truncate text-[11px] text-stone-400`,children:S}),(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:x?()=>i(0):e.onCancel,className:`h-8 rounded-lg px-3 text-[12px] text-stone-600 outline-none hover:bg-stone-100`,children:x?`上一步`:`取消`}),(0,Q.jsx)(`button`,{type:`button`,disabled:!x&&!b,onClick:()=>{c&&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:c&&r===0?`下一步`:e.manual?`提交`:`确认新增`})]})]})]})}function Yu(e,t,n){let r=e;if(n.knowledge&&(r=`${r}\n\n${Wl}`),n.fs&&(r=`${r}\n\n${At}\n\n${_s}\n\n${Vs}\n\n${yr}\n\n${gr}`),n.bash&&(r=`${r}\n\n${nn}`),n.pwsh&&(r=`${r}\n\n${an}`),n.web&&(r=`${r}\n\n${ht}`),n.memory&&(r=`${r}\n\n${Ut}`),n.interact&&(r=`${r}\n\n${Qs}`),n.todos&&(r=`${r}\n\n${bs}`),n.tasks&&(r=`${r}\n\n${ks}`),n.planPhase===`planning`&&(r=`${r}\n\n${oc}`),n.planPhase===`approved`&&(r=`${r}\n\n${sc}`),n.goalEnabled){r=`${r}\n\n${bc}`;let e=wc(n.goal);e&&(r=`${r}\n\n【当前会话目标】${e}`)}n.scheduleEnabled&&(r=`${r}\n\n${Vc}`),n.subagentEnabled&&(r=`${r}\n\n${ol}`),n.workflowEnabled&&(r=`${r}\n\n${Pl}`);let i=n.memory?t.slice(-10):t;return[{role:`system`,content:r},...i]}function Xu(e){if(!/(?:^|[\s\n])\/$/.test(e))return null;let t=e.lastIndexOf(`/`);return t<0?null:{from:t}}function Zu(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 Qu(e){let t=/\s*(?:[((](?:recommended|推荐)[))])\s*$/i;return t.test(e)?{label:e.replace(t,``),recommended:!0}:{label:e,recommended:!1}}var $u=we,ed=5,td=[`image/png`,`image/jpeg`,`image/jpg`,`image/webp`,`image/gif`],nd=[`dialog`,`thread`,`todos`,`memory`],rd=`chat.tab`;function id(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} · ${Hl(e.format)})`);t.push(`引用项目文档(请使用 kb_read 读取):\n${n.join(`
|
|
265
|
+
`)}`)}if(r.length){let e=r.map(e=>`- ${e.collection}/${e.path} 《${e.title}》(${e.category})`);t.push(`引用管理文档(路径已给出,正文可能已在上文):\n${e.join(`
|
|
266
|
+
`)}`)}}if(r.length){let e=r.map(e=>`- ${e.path} 《${e.title}》(${e.format===`dir`?`文件夹`:`文件`})`);t.push(`引用工作区路径(请使用 fs_list / fs_read):\n${e.join(`
|
|
267
|
+
`)}`)}}return e.attachments?.length&&t.push(e.attachments.map(e=>`附件《${e.name}》:\n\`\`\`\`\n${e.content}\n\`\`\`\``).join(`
|
|
268
|
+
|
|
269
|
+
`)),t.join(`
|
|
270
|
+
|
|
271
|
+
`)}function ad(e){let t=id(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 od(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 sd(e){if(!td.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(Yl/1024/1024)} MB`);let t=await od(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 cd(e,t){return e.length+t.length}var ld=[{value:`low`,label:`Low`,desc:`响应更快,适合简单问答`},{value:`high`,label:`High`,desc:`质量与速度均衡(默认)`},{value:`max`,label:`Max`,desc:`最深推理,适合复杂分析`}],ud=[{value:`readonly`,label:`仅可查看`},{value:`readwrite`,label:`工作区内修改`},{value:`full`,label:`完全权限`}];function dd(e){return e===`present`?`交付文件`:e===`todo_write`?`待办`:e.startsWith(`todo_`)?`待办事项`:e===`ask_user_question`?`向用户提问`:e===`bash`?`Bash`:e===`pwsh`?`PowerShell`:e.startsWith(`bash_session_`)||e.startsWith(`pwsh_session_`)?`持久终端`:e.startsWith(`working_directory_`)?`工作目录`:e.startsWith(`skill_`)?`Skill`:e.startsWith(`workspace_changes_`)?`工作区变更`:e===`load_workspace_dependencies`?`工作区依赖`:e===`office_to_pdf`?`Office转PDF`:e===`submit_plan`?`提交计划`:e.startsWith(`goal_`)?`会话目标`:e.startsWith(`schedule_`)?`定时提醒`:e===`list_agents`||e===`spawn_subagent`||e===`fork_subagent`||e.startsWith(`subagent_`)?`子代理`:e===`workflow`?`工作流`:e===`job_list`?`任务列表`:e===`job_output`?`任务输出`:e===`job_kill`?`终止任务`:e===`web_search`?R(`tool.kind.webSearch`):e===`web_fetch`?R(`tool.kind.webFetch`):e.startsWith(`kb_`)?R(`tool.kind.kb`):e.startsWith(`fs_`)?R(`tool.kind.fs`):e.startsWith(`memory_`)?R(`tool.kind.memory`):e}function fd(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 pd(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 md({kind:e,status:t}){let n=t===`error`?`w-3.5 h-3.5 shrink-0 text-red-500`:t===`running`?`w-3.5 h-3.5 shrink-0 text-stone-500`:`w-3.5 h-3.5 shrink-0 text-stone-400`;return t===`running`&&e===`thinking`?(0,Q.jsx)(`span`,{className:`w-3.5 h-3.5 shrink-0 rounded-full border-2 border-purple-400 border-t-transparent animate-spin`}):e===`thinking`?(0,Q.jsxs)($,{className:n,children:[(0,Q.jsx)(`circle`,{cx:`12`,cy:`12`,r:`3`}),(0,Q.jsx)(`path`,{d:`M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4`})]}):e===`web_search`||e===`web_fetch`?(0,Q.jsxs)($,{className:n,children:[(0,Q.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`}),(0,Q.jsx)(`path`,{d:`M2 12h20`}),(0,Q.jsx)(`path`,{d:`M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z`})]}):e===`fs`||e===`kb`?(0,Q.jsxs)($,{className:n,children:[(0,Q.jsx)(`path`,{d:`M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z`}),(0,Q.jsx)(`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`})]}):e===`memory`?(0,Q.jsx)($,{className:n,children:(0,Q.jsx)(`path`,{d:`M12 2a4 4 0 0 1 4 4v2h2a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2h2V6a4 4 0 0 1 4-4Z`})}):(0,Q.jsx)($,{className:n,children:(0,Q.jsx)(`path`,{d:`m12 3 1.9 5.8H20l-4.9 3.6 1.9 5.8L12 14.6 7.1 18.2l1.9-5.8L4 8.8h6.1Z`})})}function hd(e,t){if(!t)return``;if(e.startsWith(`web_`))return fn(e,t);if(e===`present`)try{let e=(JSON.parse(t).files??[]).map(e=>e.path).filter(Boolean);return e.slice(0,3).join(`, `)+(e.length>3?`…`:``)}catch{return``}try{let n=JSON.parse(t);if(e===`submit_plan`){let e=typeof n.title==`string`?n.title.trim():``;return e.length>60?`${e.slice(0,60)}…`:e}if(e===`bash`||e===`pwsh`){let e=typeof n.command==`string`?n.command.trim():``,t=n.background===!0?` [bg]`:``;return`${e.length>80?`${e.slice(0,80)}…`:e}${t}`}if(e.startsWith(`bash_session_`)||e.startsWith(`pwsh_session_`)){let e=typeof n.sessionId==`string`?n.sessionId.trim():``,t=typeof n.command==`string`?n.command.trim():``;return[e,t.length>48?`${t.slice(0,48)}…`:t].filter(Boolean).join(` · `)}if(e.startsWith(`working_directory_`)){let e=typeof n.path==`string`?n.path.trim():``;return[typeof n.id==`string`?n.id.trim():``,e].filter(Boolean).join(` · `)}if(e.startsWith(`skill_`))return[typeof n.name==`string`?n.name.trim():``,typeof n.path==`string`?n.path.trim():``].filter(Boolean).join(` · `);if(e.startsWith(`workspace_changes_`))return``;if(e.startsWith(`job_`))return typeof n.jobId==`string`?n.jobId.trim():``;if(e.startsWith(`schedule_`)){let e=typeof n.text==`string`?n.text.trim():``,t=typeof n.id==`string`?n.id.trim():``,r=typeof n.dueAt==`string`?n.dueAt.trim():``,i=typeof n.delayMinutes==`number`&&Number.isFinite(n.delayMinutes)?`+${n.delayMinutes}m`:``;return[e,t,r||i].filter(Boolean).join(` · `)}if(e===`list_agents`||e===`spawn_subagent`||e===`fork_subagent`||e.startsWith(`subagent_`)){let t=typeof n.agent==`string`?n.agent.trim():``,r=typeof n.prompt==`string`?n.prompt.trim():``,i=typeof n.id==`string`?n.id.trim():``,a=r.length>48?`${r.slice(0,48)}…`:r;return[e===`fork_subagent`?`fork`:``,t,i,a].filter(Boolean).join(` · `)}if(e===`workflow`){let e=n.meta;return(typeof e?.name==`string`?e.name.trim():``)||`workflow`}if(e===`fs_glob`||e===`fs_grep`){let e=typeof n.pattern==`string`?n.pattern.trim():``;return[e,typeof n.path==`string`?n.path.trim():``].filter(Boolean).join(` @ `)||e}if(typeof n.path==`string`&&n.path.trim())return n.path.trim();if(typeof n.query==`string`&&n.query.trim())return n.query.trim()}catch{}return``}function gd(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(`
|
|
272
|
+
`),o=e.indexOf(`
|
|
273
|
+
`,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 _d(e,t,n,r){return e===`concise`?r===`running`?R(`tool.running`):null:e===`standard`?R(r===`running`?`tool.callingKind`:`tool.doneKind`,{kind:t}):R(e===`detailed`?r===`running`?`tool.callingNamed`:`tool.doneNamed`:r===`running`?`tool.callingFull`:`tool.doneFull`,{kind:t,name:n})}function $({className:e=``,children:t}){return(0,Q.jsx)(`svg`,{className:e,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:t})}var vd=({className:e=``})=>(0,Q.jsx)($,{className:e,children:(0,Q.jsx)(`path`,{d:`m6 9 6 6 6-6`})}),yd=({className:e=``})=>(0,Q.jsx)($,{className:e,children:(0,Q.jsx)(`path`,{d:`m9 18 6-6-6-6`})}),bd=({className:e=``})=>(0,Q.jsx)($,{className:e,children:(0,Q.jsx)(`path`,{d:`M20 6 9 17l-5-5`})}),xd=({className:e=``})=>(0,Q.jsxs)($,{className:e,children:[(0,Q.jsx)(`rect`,{width:`14`,height:`14`,x:`8`,y:`8`,rx:`2`,ry:`2`}),(0,Q.jsx)(`path`,{d:`M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2`})]}),Sd=({className:e=``})=>(0,Q.jsxs)($,{className:e,children:[(0,Q.jsx)(`ellipse`,{cx:`12`,cy:`5`,rx:`9`,ry:`3`}),(0,Q.jsx)(`path`,{d:`M3 5v14a9 3 0 0 0 18 0V5`}),(0,Q.jsx)(`path`,{d:`M3 12a9 3 0 0 0 18 0`})]}),Cd=({className:e=``})=>(0,Q.jsxs)($,{className:e,children:[(0,Q.jsx)(`path`,{d:`m12 14 4-4`}),(0,Q.jsx)(`path`,{d:`M3.34 19a10 10 0 1 1 17.32 0`})]}),wd=({className:e=``})=>(0,Q.jsxs)($,{className:e,children:[(0,Q.jsx)(`path`,{d:`M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z`}),(0,Q.jsx)(`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`})]}),Td=({className:e=``})=>(0,Q.jsx)($,{className:e,children:(0,Q.jsx)(`path`,{d:`m16.5 9.4-7.07 7.07a3 3 0 0 1-4.24-4.24l7.07-7.07a2 2 0 1 1 2.83 2.83L8.02 14.1a1 1 0 0 1-1.41-1.41l7.07-7.07`})}),Ed=({className:e=``})=>(0,Q.jsxs)($,{className:e,children:[(0,Q.jsx)(`path`,{d:`m5 12 7-7 7 7`}),(0,Q.jsx)(`path`,{d:`M12 19V5`})]}),Dd=({className:e=``,open:t=!1})=>(0,Q.jsx)($,{className:e,children:t?(0,Q.jsx)(Q.Fragment,{children:(0,Q.jsx)(`path`,{d:`m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.55 6A2 2 0 0 1 18.45 20H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.69.9H18a2 2 0 0 1 2 2v2`})}):(0,Q.jsx)(`path`,{d:`M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9l-.81-1.2A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z`})}),Od=({className:e=``,open:t=!1})=>(0,Q.jsx)(`svg`,{className:`${e} tw-arrow ${t?`is-open`:``}`,viewBox:`0 0 12 12`,fill:`currentColor`,"aria-hidden":!0,children:(0,Q.jsx)(`path`,{d:`M4.2 2.4a.75.75 0 0 1 1.2-.57l4.2 3.35a.75.75 0 0 1 0 1.14l-4.2 3.35A.75.75 0 0 1 4.2 9.1V2.9Z`})}),kd=({className:e=``})=>(0,Q.jsxs)($,{className:e,children:[(0,Q.jsx)(`circle`,{cx:`11`,cy:`11`,r:`8`}),(0,Q.jsx)(`path`,{d:`m21 21-4.3-4.3`})]}),Ad=({className:e=``})=>(0,Q.jsxs)($,{className:e,children:[(0,Q.jsx)(`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`}),(0,Q.jsx)(`path`,{d:`M12 8v8`}),(0,Q.jsx)(`path`,{d:`M8 12h8`})]}),jd=({className:e=``,filled:t=!1})=>(0,Q.jsx)($,{className:e,children:t?(0,Q.jsx)(`path`,{fill:`currentColor`,stroke:`none`,d:`M12 2a3 3 0 0 1 3 3v3.5l2.5 2.5V13h-3.5V20l-1.5 2-1.5-2v-7H7.5v-2L10 8.5V5a3 3 0 0 1 3-3Z`}):(0,Q.jsx)(`path`,{d:`M12 17v5M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16h14v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V6a2 2 0 0 0-2-2h-2a2 2 0 0 0-2 2z`})}),Md=({className:e=``})=>(0,Q.jsxs)($,{className:e,children:[(0,Q.jsx)(`circle`,{cx:`12`,cy:`12`,r:`1`,fill:`currentColor`,stroke:`none`}),(0,Q.jsx)(`circle`,{cx:`5`,cy:`12`,r:`1`,fill:`currentColor`,stroke:`none`}),(0,Q.jsx)(`circle`,{cx:`19`,cy:`12`,r:`1`,fill:`currentColor`,stroke:`none`})]}),Nd=({className:e=``})=>(0,Q.jsxs)($,{className:e,children:[(0,Q.jsx)(`path`,{d:`M4 8h16v11a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V8Z`}),(0,Q.jsx)(`path`,{d:`M8 8V5a1 1 0 0 1 1-1h6a1 1 0 0 1 1 1v3`}),(0,Q.jsx)(`path`,{d:`M10 12h4`})]}),Pd=({className:e=``})=>(0,Q.jsxs)($,{className:e,children:[(0,Q.jsx)(`path`,{d:`M12 22v-5`}),(0,Q.jsx)(`path`,{d:`M9 8V2`}),(0,Q.jsx)(`path`,{d:`M15 8V2`}),(0,Q.jsx)(`path`,{d:`M18 8v5a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V8Z`})]});function Fd(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 Id(e){let t=Fd(e);return t===`刚刚`?`刚刚`:t.endsWith(`前`)?t:`${t}前`}function Ld({open:e,onToggle:t,onRename:n,onDelete:r}){let i=(0,H.useRef)(null);return(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsx)(`button`,{ref:i,type:`button`,"aria-label":`更多`,onClick:e=>{e.stopPropagation(),t()},className:`w-6 h-6 flex items-center justify-center rounded text-(--tw-label-tertiary) hover:text-(--tw-label-primary) hover:bg-(--tw-session-hover-bg)`,children:(0,Q.jsx)(Md,{className:`w-3.5 h-3.5`})}),(0,Q.jsxs)(Rd,{open:e,anchorRef:i,dataAttr:`data-ws-menu`,children:[(0,Q.jsxs)(`button`,{type:`button`,className:`w-full flex items-center gap-2 px-3 py-1.5 text-left text-[13px] text-stone-700 hover:bg-stone-50`,onClick:e=>{e.stopPropagation(),n()},children:[(0,Q.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Q.jsx)(`path`,{d:`M12 20h9`}),(0,Q.jsx)(`path`,{d:`M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z`})]}),`重命名`]}),r?(0,Q.jsxs)(`button`,{type:`button`,className:`w-full flex items-center gap-2 px-3 py-1.5 text-left text-[13px] text-red-600 hover:bg-red-50`,onClick:e=>{e.stopPropagation(),r()},children:[(0,Q.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Q.jsx)(`path`,{d:`M3 6h18`}),(0,Q.jsx)(`path`,{d:`M8 6V4h8v2`}),(0,Q.jsx)(`path`,{d:`M19 6l-1 14H6L5 6`})]}),`删除工作区`]}):null]})]})}function Rd({open:e,anchorRef:t,dataAttr:n,children:r}){let[i,a]=(0,H.useState)(null);return(0,H.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,Bn.createPortal)((0,Q.jsx)(`div`,{[n]:``,className:`tw-popover tw-popover-anim z-80 w-40 rounded-xl border border-stone-200 py-1 shadow-lg`,style:{position:`fixed`,top:i.top,left:i.left,transform:i.openUp?`translateY(-100%)`:void 0},children:r}),document.body)}function zd({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,H.useRef)(null),m=(0,H.useRef)(null),h=(0,H.useRef)(null),g=(0,H.useRef)(null),_=(0,H.useRef)(null),v=(0,H.useRef)(null),[y,b]=(0,H.useState)(!1),[x,S]=(0,H.useState)(!1),[C,w]=(0,H.useState)(null);function ee(){_.current!=null&&(clearTimeout(_.current),_.current=null)}function T(){v.current!=null&&(clearTimeout(v.current),v.current=null)}function E(){T(),v.current=setTimeout(()=>{S(!1),ee()},180)}function D(){T(),ee(),_.current=setTimeout(()=>S(!0),1e3)}let te=Xn(Array.isArray(e.messages)?e.messages:[]).trim().replace(/\s+/g,` `)||e.title||`新对话`;(0,H.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,H.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,H.useEffect)(()=>{r&&(ee(),T(),S(!1))},[r]);let ne=i?`生成中`:`空闲`,O=!!(e.archived||e.deleted);return(0,Q.jsxs)(`div`,{ref:p,className:`tw-session-row relative ${t?`is-nested`:``} ${n?`is-selected`:``} ${r?`is-menu-open`:``} ${i?`is-busy`:``} ${O?`opacity-50`:``}`,onMouseLeave:()=>{ee(),E()},children:[i?(0,Q.jsx)(`span`,{className:`tw-session-busy-slot`,"data-hint":`生成中`,"aria-label":`生成中`,children:(0,Q.jsx)(`span`,{className:`tw-session-busy-dot`,"aria-hidden":!0})}):null,e.pinned&&!O?(0,Q.jsx)(`span`,{className:`tw-slot`,"aria-hidden":!0,children:(0,Q.jsx)(jd,{filled:!0,className:`tw-pin-indicator w-3 h-3`})}):null,(0,Q.jsx)(`button`,{ref:h,type:`button`,onClick:a,onDoubleClick:o,onMouseEnter:()=>D(),onMouseLeave:()=>{ee(),E()},className:`tw-session-title text-left outline-none focus:outline-none focus-visible:outline-none ${y?`is-overflow`:``}`,children:(0,Q.jsx)(`span`,{ref:g,className:`tw-session-title-inner`,children:e.title})}),(0,Q.jsx)(`span`,{className:`tw-session-time pr-1`,children:Fd(e.updatedAt)}),(0,Q.jsxs)(`div`,{"data-session-menu":``,className:`tw-row-actions items-center gap-0.5 shrink-0`,onClick:e=>e.stopPropagation(),children:[(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsx)(`button`,{ref:m,type:`button`,"aria-label":`更多`,onClick:s,className:`tw-session-action-btn w-6 h-6 flex items-center justify-center rounded`,children:(0,Q.jsx)(Md,{className:`w-3.5 h-3.5`})}),(0,Q.jsx)(Rd,{open:r,anchorRef:m,dataAttr:`data-session-menu`,children:e.deleted?(0,Q.jsxs)(Q.Fragment,{children:[f?(0,Q.jsx)(`button`,{type:`button`,className:`w-full flex items-center gap-2 px-3 py-1.5 text-left text-[13px] text-stone-700 hover:bg-stone-50`,onClick:f,children:`恢复会话`}):null,(0,Q.jsx)(`button`,{type:`button`,className:`w-full flex items-center gap-2 px-3 py-1.5 text-left text-[13px] text-red-600 hover:bg-red-50`,onClick:d,children:`永久删除`})]}):(0,Q.jsxs)(Q.Fragment,{children:[!e.archived&&(0,Q.jsxs)(`button`,{type:`button`,className:`w-full flex items-center gap-2 px-3 py-1.5 text-left text-[13px] text-stone-700 hover:bg-stone-50`,onClick:c,children:[(0,Q.jsx)(jd,{filled:!!e.pinned,className:`w-3.5 h-3.5`}),e.pinned?`取消置顶`:`置顶会话`]}),(0,Q.jsxs)(`button`,{type:`button`,className:`w-full flex items-center gap-2 px-3 py-1.5 text-left text-[13px] text-stone-700 hover:bg-stone-50`,onClick:o,children:[(0,Q.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Q.jsx)(`path`,{d:`M12 20h9`}),(0,Q.jsx)(`path`,{d:`M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z`})]}),`重命名`]}),(0,Q.jsxs)(`button`,{type:`button`,className:`w-full flex items-center gap-2 px-3 py-1.5 text-left text-[13px] text-stone-700 hover:bg-stone-50`,onClick:l,children:[(0,Q.jsx)(Nd,{className:`w-3.5 h-3.5`}),e.archived?`取消归档`:`归档会话`]}),(0,Q.jsxs)(`button`,{type:`button`,className:`w-full flex items-center gap-2 px-3 py-1.5 text-left text-[13px] text-stone-700 hover:bg-stone-50`,onClick:u,children:[(0,Q.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Q.jsx)(`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`}),(0,Q.jsx)(`polyline`,{points:`7 10 12 15 17 10`}),(0,Q.jsx)(`line`,{x1:`12`,x2:`12`,y1:`15`,y2:`3`})]}),`导出会话`]}),e.archived?(0,Q.jsxs)(`button`,{type:`button`,className:`w-full flex items-center gap-2 px-3 py-1.5 text-left text-[13px] text-red-600 hover:bg-red-50`,onClick:d,children:[(0,Q.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Q.jsx)(`path`,{d:`M3 6h18`}),(0,Q.jsx)(`path`,{d:`M8 6V4h8v2`}),(0,Q.jsx)(`path`,{d:`M19 6l-1 14H6L5 6`})]}),`永久删除`]}):null]})})]}),!e.deleted&&(0,Q.jsx)(`button`,{type:`button`,"aria-label":e.archived?`取消归档`:`归档会话`,"data-hint":e.archived?`取消归档`:`归档会话`,onClick:l,className:`tw-session-action-btn w-6 h-6 flex items-center justify-center rounded`,children:(0,Q.jsx)(Nd,{className:`w-3.5 h-3.5`})}),!e.archived&&!e.deleted&&(0,Q.jsx)(`button`,{type:`button`,"data-hint":e.pinned?`取消置顶`:`置顶`,onClick:c,className:`tw-session-action-btn w-6 h-6 flex items-center justify-center rounded`,children:(0,Q.jsx)(jd,{filled:!!e.pinned,className:`w-3.5 h-3.5`})})]}),x&&!r&&C&&typeof document<`u`?(0,Bn.createPortal)((0,Q.jsxs)(`div`,{className:`tw-session-preview`,role:`tooltip`,style:{position:`fixed`,top:C.top,left:C.left,transform:`translateY(-50%)`},onMouseEnter:()=>{ee(),T(),S(!0)},onMouseLeave:()=>E(),children:[(0,Q.jsx)(`div`,{className:`tw-session-preview-title`,children:te}),(0,Q.jsx)(`div`,{className:`tw-session-preview-meta`,children:Id(e.updatedAt)}),(0,Q.jsx)(`div`,{className:`tw-session-preview-status ${i?`is-busy`:``}`,children:ne})]}),document.body):null]})}var Bd=`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 Vd({level:e,className:t=``}){return(0,Q.jsxs)($,{className:t,children:[(0,Q.jsx)(`path`,{d:Bd}),e===`readonly`&&(0,Q.jsx)(`path`,{d:`m9 12 2 2 4-4`}),e===`readwrite`&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`path`,{d:`M9 10h6`}),(0,Q.jsx)(`path`,{d:`M9 14h3`})]}),e===`full`&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`path`,{d:`M12 8v4`}),(0,Q.jsx)(`path`,{d:`M12 16h.01`})]})]})}function Hd(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function Ud(e){return`${e.toLocaleString(`en-US`)} tok`}function Wd(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 Gd(e){return e>=99.95?`100`:e>=10?String(Math.round(e)):e.toFixed(1)}function Kd(e){let t=0;for(let n of e)t+=/[\u4e00-\u9fff]/.test(n)?1:.25;return Math.max(1,Math.round(t))}function qd(e){return e.uncachedTokens==null?e.cachedTokens==null?e.promptTokens:Math.max(0,e.promptTokens-e.cachedTokens):e.uncachedTokens}function Jd(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 Yd(e,t){return t<=0?null:e/t*100}function Xd(e){return e>=1024?`${(e/1024).toFixed(1)} KB`:`${e} B`}function Zd(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 Qd(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 $d({text:e}){let[t,n]=(0,H.useState)(!1),r=(0,H.useRef)(null);(0,H.useEffect)(()=>()=>{r.current!==null&&window.clearTimeout(r.current)},[]);async function i(){t||await Qd(e)&&(n(!0),r.current=window.setTimeout(()=>n(!1),1e3))}return(0,Q.jsx)(`button`,{type:`button`,onClick:i,"aria-label":t?`已复制`:`复制`,className:`tw-icon-btn tw-msg-action-btn inline-flex items-center justify-center rounded-md transition-colors`,children:t?(0,Q.jsx)(bd,{className:`w-3.5 h-3.5 text-emerald-600`}):(0,Q.jsx)(xd,{className:`w-3.5 h-3.5`})})}function ef({pct:e}){return(0,Q.jsxs)(`svg`,{className:`w-3.5 h-3.5 -rotate-90`,viewBox:`0 0 20 20`,"aria-hidden":`true`,children:[(0,Q.jsx)(`circle`,{cx:`10`,cy:`10`,r:`8`,fill:`none`,stroke:`var(--color-stone-200)`,strokeWidth:`3`}),(0,Q.jsx)(`circle`,{cx:`10`,cy:`10`,r:`8`,fill:`none`,stroke:`#4176e6`,strokeWidth:`3`,strokeLinecap:`round`,strokeDasharray:`${Math.max(e,1)/100*50.27} 50.27`})]})}function tf(){let[e,t]=(0,H.useState)(!1),n=(0,H.useRef)(null),r=(0,H.useRef)(null),[i,a]=(0,H.useState)(null);return(0,H.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,H.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 nf({title:e,titleValue:t,icon:n,children:r}){return(0,Q.jsxs)(`div`,{className:`tw-popover w-[min(320px,calc(100vw-24px))] rounded-2xl border border-stone-200 p-3.5 shadow-xl text-left`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-[13px]`,children:[n,(0,Q.jsx)(`span`,{className:`tw-popover-title font-medium text-stone-800`,children:e}),t!==void 0&&(0,Q.jsx)(`span`,{className:`tw-popover-muted ml-auto text-stone-500 tabular-nums`,children:t})]}),(0,Q.jsx)(`div`,{className:`mt-2.5 mb-2.5 border-t border-stone-100`}),r]})}function rf({rows:e}){return(0,Q.jsx)(`dl`,{className:`grid grid-cols-[1fr_auto] gap-x-6 gap-y-2 text-[13px]`,children:e.filter(e=>!e.hide).map(e=>(0,Q.jsxs)(`div`,{className:`contents`,children:[(0,Q.jsx)(`dt`,{className:`text-stone-500`,children:e.label}),(0,Q.jsx)(`dd`,{className:`text-stone-800 tabular-nums text-right`,children:e.value})]},e.label))})}function af({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}=tf();return(0,Q.jsxs)(`span`,{ref:l,className:`relative inline-flex items-center`,children:[(0,Q.jsxs)(`button`,{type:`button`,"aria-haspopup":`dialog`,"aria-expanded":s,"aria-label":n,onClick:()=>c(!s),className:o===`ghost`?`tw-msg-action-meta inline-flex items-center gap-1 tabular-nums transition-colors ${s?`text-stone-600`:`text-stone-400 hover:text-stone-600`}`:`inline-flex items-center gap-1.5 px-2 py-0.5 rounded-full transition-colors ${s?`bg-stone-200/70 text-stone-600`:`hover:bg-stone-200/60 hover:text-stone-600`}`,children:[t,(0,Q.jsx)(`span`,{className:`leading-none`,children:e})]}),s&&(0,Bn.createPortal)((0,Q.jsx)(`div`,{ref:u,role:`dialog`,"aria-label":r,style:d??{position:`fixed`,left:0,top:0,visibility:`hidden`},className:`z-80`,children:(0,Q.jsx)(nf,{title:r,titleValue:i,icon:t,children:a})}),document.body)]})}function of({messages:e,busy:t,onRestoreCheckpoint:n}){let[r,i]=(0,H.useState)(()=>new Set),a=(0,H.useMemo)(()=>pr(e.map(e=>({role:e.role,content:typeof e.content==`string`?e.content:id(e),time:e.time}))),[e]);function o(e){i(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}return a.length?(0,Q.jsx)(`ol`,{className:`list-none m-0 p-0 w-full max-w-[min(64rem,100%)] mx-auto space-y-2`,children:a.map(e=>{let i=r.has(e.index),a=!!e.assistantText;return(0,Q.jsxs)(`li`,{className:`rounded-xl border bg-white shadow-sm overflow-hidden ${i?`border-[#4176e6]/35`:`border-stone-200`}`,children:[(0,Q.jsxs)(`div`,{className:`flex items-start gap-1 px-3 py-2.5`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>o(e.index),"aria-expanded":i,className:`min-w-0 flex-1 text-left hover:bg-stone-50/80 rounded-lg -mx-1 px-1 py-0.5 transition-colors`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,Q.jsxs)(`span`,{className:`text-[11px] font-medium text-stone-400 tabular-nums`,children:[`第 `,e.index,` 轮`]}),(0,Q.jsx)(vd,{className:`w-3.5 h-3.5 text-stone-400 ml-auto shrink-0 transition-transform ${i?`rotate-180`:``}`})]}),i?null:(0,Q.jsxs)(`div`,{className:`space-y-1 text-[13px] leading-5`,children:[(0,Q.jsxs)(`p`,{className:`m-0 text-stone-800 truncate`,children:[(0,Q.jsx)(`span`,{className:`text-stone-400 mr-1.5`,children:`用户`}),e.userPreview]}),(0,Q.jsxs)(`p`,{className:`m-0 text-stone-600 truncate`,children:[(0,Q.jsx)(`span`,{className:`text-stone-400 mr-1.5`,children:`助手`}),e.assistantPreview||`(待回复)`]})]})]}),n?(0,Q.jsx)(`button`,{type:`button`,disabled:t||!a,"data-hint":a?`截断到本轮末,填入续写并发送`:`待本轮助手回复完成后可从此处继续`,className:`shrink-0 mt-0.5 text-[11px] text-[#4176e6] hover:underline disabled:opacity-40 disabled:no-underline px-1 whitespace-nowrap`,onClick:()=>n(e.endMessageIndex,e.index),children:`从此处继续`}):null]}),i?(0,Q.jsxs)(`div`,{className:`px-3 pb-3 space-y-2.5 text-[13px] leading-5 border-t border-stone-100 pt-2.5`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`div`,{className:`text-[11px] font-medium text-stone-400 mb-0.5`,children:`用户`}),(0,Q.jsx)(`div`,{className:`whitespace-pre-wrap break-words text-stone-800`,children:e.userText||`—`})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`div`,{className:`text-[11px] font-medium text-stone-400 mb-0.5`,children:`助手`}),e.assistantText?(0,Q.jsx)(`div`,{className:`chat-md prose prose-sm prose-stone max-w-none tw-chat-text`,dangerouslySetInnerHTML:{__html:To(e.assistantText)}}):(0,Q.jsx)(`div`,{className:`text-stone-400`,children:`(待回复)`})]})]}):null]},e.index)})}):(0,Q.jsx)(`div`,{className:`h-full flex items-center justify-center text-sm text-stone-400`,children:`暂无回合(还没有用户/助手对话)`})}function sf({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?qd(t.usage):0),0),d=r.reduce((e,t)=>e+(t.usage?.cacheWriteTokens??0),0),f=r.reduce((e,t)=>e+Jd(t.usage),0),p=r.some(e=>e.usage?.cachedTokens!=null),m=p?Yd(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?he[t]:void 0,w=i.usage?.promptTokens??0,ee=C?Math.min(100,w/C*100):void 0,T=Math.min(n,w),E=Math.max(0,w-T);return(0,Q.jsxs)(`div`,{className:`flex items-center justify-center gap-1 pt-2 text-xs text-stone-400 tabular-nums select-none`,children:[(0,Q.jsx)(af,{icon:(0,Q.jsx)(Cd,{className:`w-3.5 h-3.5`}),label:(0,Q.jsxs)(Q.Fragment,{children:[a,` 轮 `,o,` 步`,S?` · ${Math.round(S)} tok/s`:``]}),ariaLabel:`会话统计`,title:`会话统计`,children:(0,Q.jsx)(rf,{rows:[{label:`模型用时`,value:h>0?Wd(h):`—`},{label:`工具调用用时`,value:g>0?Wd(g):`—`},{label:`首 token 平均 (TTFT)`,value:_.length?Wd(v):`—`},{label:`输出速度 (TPS)`,value:S?`${Math.round(S)} tok/s`:`—`}]})}),(0,Q.jsx)(af,{icon:(0,Q.jsx)(Sd,{className:`w-3.5 h-3.5`}),label:(0,Q.jsxs)(Q.Fragment,{children:[Hd(s),` tok`,m==null?``:` · 缓存命中 ${Gd(m)}%`]}),ariaLabel:`Token 用量`,title:`Token 用量`,titleValue:Ud(s),children:(0,Q.jsx)(rf,{rows:[{label:`缓存命中`,value:m==null?`—`:`${Gd(m)}%`,hide:m==null},{label:`未缓存输入`,value:Ud(u)},{label:`缓存读取`,value:Ud(l),hide:!p},{label:`缓存写入`,value:Ud(d),hide:d<=0},{label:`输出`,value:Ud(f)}]})}),ee!==void 0&&C&&(0,Q.jsxs)(af,{icon:(0,Q.jsx)(ef,{pct:ee}),label:`${Gd(ee)}%`,ariaLabel:`上下文占用`,title:`上下文已用 ${Gd(ee)}%`,titleValue:`~${Hd(w)} / ${Hd(C)}`,children:[(0,Q.jsxs)(`div`,{className:`h-2 rounded-full bg-stone-100 overflow-hidden flex mb-3`,children:[(0,Q.jsx)(`span`,{className:`h-full bg-stone-400`,style:{width:`${T/C*100}%`},"data-hint":`系统提示词`}),(0,Q.jsx)(`span`,{className:`h-full bg-[#4176e6]`,style:{width:`${E/C*100}%`},"data-hint":`对话消息`})]}),(0,Q.jsx)(rf,{rows:[{label:`系统提示词`,value:`~${Hd(T)}`},{label:`对话消息`,value:`~${Hd(E)}`}]}),(0,Q.jsx)(`p`,{className:`mt-2.5 text-[11px] leading-4 text-stone-400`,children:`分段为示意估算(API 不返回上下文拆分);总量以最近一轮 prompt_tokens 为准。`})]})]})}function cf({usage:e,model:t}){let n=e.cachedTokens==null?null:Yd(e.cachedTokens,e.promptTokens);return(0,Q.jsx)(af,{variant:`ghost`,icon:(0,Q.jsx)(Sd,{className:`w-3.5 h-3.5 shrink-0`}),label:(0,Q.jsxs)(Q.Fragment,{children:[`用量 `,Hd(e.totalTokens),` tok`]}),ariaLabel:`本轮用量`,title:`本轮用量`,titleValue:Ud(e.totalTokens),children:(0,Q.jsx)(rf,{rows:[{label:`提供方 / 模型`,value:t??`—`,hide:!t},{label:`缓存命中`,value:n==null?`—`:`${Gd(n)}%`,hide:n==null},{label:`未缓存输入`,value:Ud(qd(e))},{label:`缓存读取`,value:Ud(e.cachedTokens??0),hide:e.cachedTokens==null},{label:`缓存写入`,value:Ud(e.cacheWriteTokens??0),hide:!(e.cacheWriteTokens&&e.cacheWriteTokens>0)},{label:`输出`,value:Ud(e.completionTokens)}]})})}function lf({settings:e}){let[t,n]=(0,H.useState)(!1),[r,i]=(0,H.useState)(null),[a,o]=(0,H.useState)([]),[s,c]=(0,H.useState)(`idle`),l=(0,H.useRef)(null),u=(0,H.useRef)(0);if((0,H.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,H.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;F(e.baseURL,e.apiKey).then(t=>{if(r!==u.current)return;let n=t.length?t:[e.model];o(n),c(`ok`),t.length&&Ae({availableModels:t})}).catch(()=>{r===u.current&&c(n.length>1?`ok`:`fail`)})},[t,e]),!e)return(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>Me(`model`),className:`flex items-center gap-1 h-7 shrink-0 pl-2 pr-1 text-[13px] leading-5 font-medium text-stone-500 rounded-md hover:bg-stone-100 transition-colors`,children:[(0,Q.jsx)(`span`,{className:`whitespace-nowrap`,children:`配置模型`}),(0,Q.jsx)(vd,{className:`w-3.5 h-3.5 shrink-0 text-stone-400`})]});let d=e.reasoningEffort??`high`,f=ld.find(e=>e.value===d)?.label??`High`;function p(e){Ae(e),n(!1),i(null)}let m=e=>`w-full flex items-center gap-3 px-3 py-2 rounded-lg text-left text-[13px] transition-colors ${e?`bg-stone-100`:`hover:bg-stone-100`}`;return(0,Q.jsxs)(`div`,{ref:l,className:`relative`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>{n(e=>!e),i(null)},className:`tw-composer-bar-model group flex items-center gap-1 h-7 shrink-0 pl-2 pr-1 text-[13px] leading-5 font-medium rounded-md outline-none focus:outline-none focus-visible:outline-none transition-colors ${t?`bg-stone-100`:`hover:bg-stone-100`}`,title:`${e.model} · ${f}`,"aria-label":`模型 ${e.model},推理 ${f}`,children:[(0,Q.jsx)(`span`,{className:`tw-composer-bar-model-name max-w-40 truncate text-stone-600`,children:e.model}),(0,Q.jsx)(`span`,{className:`tw-composer-bar-effort whitespace-nowrap text-stone-400`,children:f}),(0,Q.jsx)(vd,{className:`w-3.5 h-3.5 shrink-0 text-stone-400 transition-transform ${t?`rotate-180`:``}`})]}),t&&(0,Q.jsxs)(`div`,{className:`tw-popover tw-popover-anim absolute bottom-full right-0 mb-2 w-64 rounded-xl border border-stone-200 p-1 shadow-xl z-50`,children:[(0,Q.jsxs)(`button`,{type:`button`,onMouseEnter:()=>i(`model`),onClick:()=>i(`model`),className:m(r===`model`),children:[(0,Q.jsx)(`span`,{className:`text-stone-700`,children:`模型`}),(0,Q.jsx)(`span`,{className:`ml-auto max-w-32 truncate text-stone-400`,children:e.model}),(0,Q.jsx)(yd,{className:`w-3.5 h-3.5 text-stone-400`})]}),(0,Q.jsxs)(`button`,{type:`button`,onMouseEnter:()=>i(`effort`),onClick:()=>i(`effort`),className:m(r===`effort`),children:[(0,Q.jsx)(`span`,{className:`text-stone-700`,children:`推理等级`}),(0,Q.jsx)(`span`,{className:`ml-auto text-stone-400`,children:f}),(0,Q.jsx)(yd,{className:`w-3.5 h-3.5 text-stone-400`})]}),r===`model`&&(0,Q.jsxs)(`div`,{className:`tw-popover tw-popover-anim absolute right-full bottom-0 mr-1.5 w-64 max-h-72 overflow-y-auto rounded-xl border border-stone-200 p-1 shadow-xl`,children:[s===`loading`&&a.length<=1&&(0,Q.jsx)(`div`,{className:`px-3 py-2 text-xs text-stone-400`,children:`正在识别可用模型…`}),a.map(t=>(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>p({model:t}),className:m(!1),children:[(0,Q.jsx)(`span`,{className:`flex-1 truncate ${t===e.model?`text-stone-900 font-medium`:`text-stone-600`}`,children:t}),t===e.model&&(0,Q.jsx)(bd,{className:`w-3.5 h-3.5 text-[#4176e6]`})]},t)),(0,Q.jsx)(`div`,{className:`mt-1 border-t border-stone-100 pt-1`,children:(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{n(!1),i(null),Me(`model`)},className:`w-full px-3 py-1.5 rounded-lg text-left text-xs text-stone-400 hover:bg-stone-100`,children:s===`fail`?`识别失败,打开设置检查…`:a.length>1?`打开设置 · 模型…`:`打开设置识别可用模型…`})})]}),r===`effort`&&(0,Q.jsx)(`div`,{className:`tw-popover tw-popover-anim absolute right-full bottom-0 mr-1.5 w-60 rounded-xl border border-stone-200 p-1 shadow-xl`,children:ld.map(e=>(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>p({reasoningEffort:e.value}),className:`w-full px-3 py-2 rounded-lg text-left hover:bg-stone-100 transition-colors`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-[13px]`,children:[(0,Q.jsx)(`span`,{className:`flex-1 ${d===e.value?`text-stone-900 font-medium`:`text-stone-600`}`,children:e.label}),d===e.value&&(0,Q.jsx)(bd,{className:`w-3.5 h-3.5 text-[#4176e6]`})]}),(0,Q.jsx)(`div`,{className:`mt-0.5 text-xs text-stone-400`,children:e.desc})]},e.value))})]})]})}var uf=null;function df(){if(!uf){let e=tt();uf={store:e,messages:e.sessions.find(t=>t.id===e.activeId)?.messages??[]}}return uf}function ff({slashDocs:e=[]}){let[t,n]=(0,H.useState)(null),[r,i]=(0,H.useState)(!1),[a,o]=(0,H.useState)(()=>df().store),[s,l]=(0,H.useState)(()=>df().messages),[u,d]=(0,H.useState)(``),[f,p]=(0,H.useState)([]),[_,S]=(0,H.useState)([]),[C,w]=(0,H.useState)([]),[ee,T]=(0,H.useState)($u),[E,D]=(0,H.useState)(!1),[k,A]=(0,H.useState)(null),j=(0,H.useRef)(null);j.current=k;let[M,ie]=(0,H.useState)(!1),[N,ae]=(0,H.useState)(null),oe=(0,H.useRef)(null);oe.current=N;let[se,P]=(0,H.useState)(!1),[ce,le]=(0,H.useState)(null),ue=(0,H.useRef)(null);ue.current=ce;let[de,F]=(0,H.useState)(null),pe=(0,H.useRef)(null);pe.current=de;let he=(0,H.useRef)(null),[I,ge]=(0,H.useState)(null),[_e,be]=(0,H.useState)(0),[Ce,we]=(0,H.useState)(!1),[Te,Ae]=(0,H.useState)(null),[Fe,Ie]=(0,H.useState)(null),[tt,ut]=(0,H.useState)(null),[ft,pt]=(0,H.useState)(null),[mt,ht]=(0,H.useState)(null),[St,wt]=(0,H.useState)(!1),[Tt,At]=(0,H.useState)([]),[Rt,Ut]=(0,H.useState)(null),[nn,an]=(0,H.useState)(`error`);function z(e,t=`error`){an(t),Ut(e)}let[ln,un]=(0,H.useState)(`readonly`),[dn,fn]=(0,H.useState)(!1),[pn,mn]=(0,H.useState)(!0),[hn,gn]=(0,H.useState)(!1),[B,_n]=(0,H.useState)(()=>h()),[vn,yn]=(0,H.useState)(``),[bn,Sn]=(0,H.useState)(null),[Cn,wn]=(0,H.useState)(null),[Tn,En]=(0,H.useState)(!1),[Dn,On]=(0,H.useState)(null),[kn,An]=(0,H.useState)(null),[jn,Mn]=(0,H.useState)(null),[V,Nn]=(0,H.useState)(null),[Fn,Bn]=(0,H.useState)(!1),[Vn,qn]=(0,H.useState)({}),[Jn,Qn]=(0,H.useState)(``),[nr,rr]=(0,H.useState)(!1),[ir,ar]=(0,H.useState)(null),[or,cr]=(0,H.useState)(()=>b(rd,nd,`dialog`)),[dr,fr]=(0,H.useState)(()=>typeof window>`u`?{language:`zh-CN`,appearance:`system`,sessionFontSize:14,toolStepDetail:`standard`,busySendBehavior:`queue`,subagentModel:``}:Pe()),[pr,hr]=(0,H.useState)(!1),[gr,U]=(0,H.useState)(null),[yr,Sr]=(0,H.useState)(0),[Cr,wr]=(0,H.useState)(!1),[Er,Dr]=(0,H.useState)(!1),[Or,kr]=(0,H.useState)(!1),[W,Ar]=(0,H.useState)(!0),[jr,Mr]=(0,H.useState)([]),[Nr,Pr]=(0,H.useState)([]),Fr=!!(B.memory&&bn?.ok),Ir=!!B.knowledge,Lr=!!jn?.ok,G=!!Cn?.ok,Rr=Tn&&!G,zr=!!Dn?.ok,Br=!!(kn?.ok&&kn.available),Vr=(0,H.useRef)(null),Hr=(0,H.useRef)(new Map),Ur=(0,H.useRef)(null),Wr=(0,H.useRef)(new Map),Gr=(0,H.useRef)(new Map),Kr=(0,H.useRef)(new Map),qr=(0,H.useRef)(null),Jr=(0,H.useRef)(!1),Yr=(0,H.useRef)(null),Xr=(0,H.useRef)(null),[Zr,Qr]=(0,H.useState)([]),[$r,ei]=(0,H.useState)(null),ti=(0,H.useRef)(null),ni=(0,H.useRef)(0),ri=(0,H.useRef)(new Set),[ii,ai]=(0,H.useState)(`off`),[oi,si]=(0,H.useState)(null),[ci,li]=(0,H.useState)(`day`),[ui,di]=(0,H.useState)(null),[fi,pi]=(0,H.useState)(null),[mi,hi]=(0,H.useState)({}),[gi,_i]=(0,H.useState)(0),[vi,yi]=(0,H.useState)(!1),[bi,xi]=(0,H.useState)(null),[Si,Ci]=(0,H.useState)(!1),[wi,Ti]=(0,H.useState)(``),[Ei,Di]=(0,H.useState)(null),[Oi,ki]=(0,H.useState)(!1),Ai=(0,H.useRef)(null),ji=(0,H.useRef)(null);function Mi(){ji.current!==null&&(window.clearTimeout(ji.current),ji.current=null)}function Ni(){Mi(),ki(!1)}function Pi(e,t){return new Promise(n=>{Ai.current?.(null),Ai.current=n,Ni(),Di({kind:e,items:t})})}function Fi(e){let t=Ai.current;Ai.current=null,ki(!0),Mi(),ji.current=window.setTimeout(()=>{ji.current=null,Di(null),ki(!1)},160),t?.(e)}let Ii=(0,H.useRef)(()=>{});Ii.current=()=>Fi(null),(0,H.useEffect)(()=>{if(!Ei||Oi)return;let e=e=>{let t=e.target;t instanceof Element&&(t.closest(`.tw-create-card`)||t.closest(`[data-headlessui-portal]`)||t.closest(`.tw-select-menu`)||t.closest(`.tw-date-panel`)||Ii.current())};return document.addEventListener(`pointerdown`,e,!0),()=>document.removeEventListener(`pointerdown`,e,!0)},[Ei,Oi]);function Li(e){kr(!1),B[e===`todo`?`todos`:`tasks`]&&(Ni(),Di({kind:e,manual:!0,items:[Vu(e)]}))}async function Ri(e,t){let n=e===`todo`?`待办`:`任务`;try{e===`todo`?await Pn(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`}),an(`ok`),z(`已新增 ${t.length} 条${n},可在侧栏「${n===`待办`?`待办事项`:`任务管理`}」查看。`)}catch(e){an(`error`),z(e instanceof Error?e.message:String(e))}}(0,H.useEffect)(()=>()=>{Ai.current?.(null),Ai.current=null,ji.current!==null&&(window.clearTimeout(ji.current),ji.current=null)},[]);let zi=(0,H.useRef)([]),Bi=(0,H.useRef)(null);function Vi(e){zi.current=e,Mr(e)}function Hi(e){let t=e.content.trim().replace(/\s+/g,` `);if(t)return t.length>28?`${t.slice(0,28)}…`:t;let n=e.files.length+e.imgs.length+e.refs.length;return n>0?`附件 ${n} 项`:`(空消息)`}let Ui=(0,H.useRef)(null),Wi=(0,H.useRef)(null),Gi=(0,H.useRef)(null),Ki=(0,H.useRef)(null),qi=(0,H.useRef)(null),K=(0,H.useRef)(null),Ji=(0,H.useRef)(null),Yi=(0,H.useRef)(null),Xi=(0,H.useRef)({}),Zi=!!(G&&V?.workspace),Qi=Zu(u),$i=(()=>{if(!Qi||!Ir)return[];let t=Qi.query.toLowerCase();return(t?e.filter(e=>Ul(e,t)):e).slice(0,10)})(),ea=(()=>{if(!Qi||!Zi)return[];let e=Qi.query.toLowerCase(),t=Nr.map(e=>({collection:`workspace`,id:`ws:${e.path}`,title:e.name,category:Kt(V?.workspace,V?.projectRoot),description:e.path,format:e.type===`dir`?`dir`:`file`,path:e.path}));return(e?t.filter(t=>Ul(t,e)||t.path.toLowerCase().includes(e)||t.title.toLowerCase().includes(e)):t).slice(0,10)})(),ta=[...$i.map(e=>({section:`project`,doc:e})),...ea.map(e=>({section:`workspace`,doc:e}))],na=!(!Qi||Cr),ra=Xu(u),ia=v.filter(e=>e.hasPanel&&B[e.id]),aa=!!(ra&&!Er&&!na&&ia.length>0),oa=(0,H.useRef)(!0),sa=(0,H.useRef)(!1),q=(0,H.useRef)(null),ca=(0,H.useRef)(null),la=(0,H.useRef)([]);la.current=s,ca.current=V;function J(e){q.current=e,o(e),at(e)}let ua=a?.sessions.find(e=>e.id===a.activeId),da=ua?.id,fa=ua?.access;(0,H.useEffect)(()=>{da&&un(fa??je())},[da,fa]),(0,H.useEffect)(()=>{let e=!1,t=Oe(()=>n(ke())),r=m(e=>_n(e)),a=De(e=>{fr(e),Ne(e)});return(async()=>{if(await c(),e)return;let t=Pe();fr(t),Ne(t),n(ke()),un(je()),_n(h()),mn(qe());let r=new URLSearchParams(window.location.search),a=r.get(`session`),s=await it({preferSessionId:a});if(e)return;let u=s;if(a&&!u.sessions.some(e=>e.id===a))try{let e=sessionStorage.getItem($e(a));if(e){let t=JSON.parse(e)?.session;t&&t.id===a&&(u={...u,sessions:[t,...u.sessions.filter(e=>e.id!==a)],activeId:a},await Ze(u))}}catch{}if(a)try{sessionStorage.removeItem($e(a))}catch{}let d=r.get(`focusRoot`),f=r.get(`focusPath`),p=r.get(`attachRoot`),m=r.get(`attachPath`),_=r.get(`attachName`),v=null;if(d&&f)try{v=`${d}:${decodeURIComponent(f).replace(/\\/g,`/`).replace(/^\/+/,``)}`}catch{v=`${d}:${f}`}if(a&&u.sessions.some(e=>e.id===a)&&(u=Be(u,a),at(u)),v&&ge(v),p&&m){let e=p;if(e===`cases`||e===`prompts`||e===`knowledge`||e===`templates`){let t=m,n=_||``;try{t=decodeURIComponent(m).replace(/\\/g,`/`).replace(/^\/+/,``),_&&(n=decodeURIComponent(_))}catch{}n||=t.split(`/`).pop()||t;let r=(n.split(`.`).pop()||`md`).toLowerCase(),i=e===`cases`?`用例`:e===`prompts`?`提示词`:e===`knowledge`?`知识库`:`模板`;w([{collection:e,id:`${e}:${t}`,title:n,category:i,path:t,format:r}])}}let y=r.get(`report`);try{let e=new URL(window.location.href);e.searchParams.delete(`report`),e.searchParams.delete(`session`),e.searchParams.delete(`focusRoot`),e.searchParams.delete(`focusPath`),e.searchParams.delete(`attachRoot`),e.searchParams.delete(`attachPath`),e.searchParams.delete(`attachName`),window.history.replaceState({},``,e.pathname+e.search+e.hash)}catch{}let b=[];try{b=(await Un()).map(e=>e.sessionId)}catch{b=[]}let x=new Set(b);u=x.size?{...u,sessions:u.sessions.map(e=>{if(x.has(e.id))return e;let t=ct(e.messages);return t===e.messages?e:{...e,messages:t}})}:We(u);let S=je();u.sessions.some(e=>!e.access)&&(u={...u,sessions:u.sessions.map(e=>e.access?e:{...e,access:S})}),q.current=u,o(u),at(u);let C=u.sessions.find(e=>e.id===u.activeId);if(l(C?.messages??[]),A(C?.caseGen?.active?C.caseGen:null),ae(C?.promptGen?.active?C.promptGen:null),le(C?.knowledgeGen?.active?C.knowledgeGen:null),F(C?.pluginDev?.active?C.pluginDev:null),un(C?.access??S),C?.pluginDev?.active&&(si(`pluginDev`),C.access!==`readwrite`&&C.access!==`full`)){un(`readwrite`);let e={...u,sessions:u.sessions.map(e=>e.id===u.activeId?{...e,access:`readwrite`}:e)};q.current=e,o(e),at(e)}Qr(tc(C?.todos));{let e=Sc(C?.goal);ti.current=e,ei(e)}(y===`day`||y===`week`||y===`month`)&&h().reports&&Va(y),C?.workspacePath&&qn(e=>({...e,[C.workspacePath]:!0})),(C?.messages??[]).length||cr(`dialog`),At(b),i(!0),b.length&&queueMicrotask(()=>{for(let e of b)Aa(e,!0),e===q.current?.activeId&&(Jr.current=!0,wt(!0),Na(e,0))});try{let e=new URL(window.location.href),t=e.searchParams.get(`plugin`);if(t===`promptGen`||t===`knowledgeGen`||t===`caseGen`||t===`pluginDev`){let n=t;if(h()[n]){if(n===`pluginDev`)Ba();else{let e=q.current?.sessions.find(e=>e.id===q.current?.activeId);if((!e||e.archived||e.deleted||Array.isArray(e.messages)&&e.messages.length>0||e.caseGen?.active||e.promptGen?.active||e.knowledgeGen?.active)&&q.current){let e=q.current.activeId,t=Ca(e)??q.current,n=V?.workspace?.trim()||void 0,r=et(t,{workspacePath:n,access:je()});q.current=r,o(r),at(r),l([]),A(null),ae(null),le(null),Qr([]),ti.current=null,ei(null),ai(`off`)}n===`promptGen`?ie(!0):n===`knowledgeGen`?P(!0):D(!0)}}else z(g(n));e.searchParams.delete(`plugin`),window.history.replaceState({},``,e.pathname+e.search+e.hash)}}catch{}(async()=>{try{if(!await ye(`prompts`))return;let e=(await L(`prompts`,Ee)).content.trim();e&&T(e)}catch{}})(),Ot().then(e=>Sn(e)),bt().then(e=>{wn(e),En(!0)}),Yt().then(e=>On(e)),cn().then(e=>An(e)),xt().then(e=>Mn(e)),tn().then(e=>{Nn(e),e?.workspace&&qn(t=>({...t,[e.workspace]:!0}))})})(),()=>{e=!0,t(),r(),a()}},[]),(0,H.useEffect)(()=>{!B.memory&&or===`memory`&&cr(`dialog`)},[B.memory,or]),(0,H.useEffect)(()=>{!B.todos&&or===`todos`&&cr(`dialog`)},[B.todos,or]),(0,H.useEffect)(()=>{y(rd,or)},[or]),(0,H.useEffect)(()=>{if(!B.reports){yn(``);return}let e=!0;return(async()=>{try{await Ln(!0);let t=await In();e&&yn(t)}catch{}})(),()=>{e=!1}},[B.reports]),(0,H.useEffect)(()=>{if(!r)return;let e=!1,t=async()=>{if(!q.current)return;let t=await rl();if(e||!q.current)return;let n=q.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:tl(e.text,e.id),time:Date.now(),scheduleId:e.id};n=nt(n,e.sessionId,t),e.sessionId===n.activeId&&(r=!0)}try{typeof Notification<`u`&&Notification.permission===`granted`&&new Notification(`Lantern Harness 定时提醒`,{body:e.text})}catch{}}let i=await Ge();if(!e&&q.current){if(i){let e=Qe(n,i);e!==n&&(n=e,n.activeId&&(r=!0))}if((n!==q.current||t.length)&&J(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,H.useEffect)(()=>{if(!r||!G||!V)return;let e=a?.sessions.find(e=>e.id===a.activeId);_a(e)},[r,G,a?.activeId,V?.items]),(0,H.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,H.useEffect)(()=>{Sr(0),wr(!1)},[Qi?.query,Qi?.from]),(0,H.useEffect)(()=>{Dr(!1),be(0)},[ra?.from]),(0,H.useEffect)(()=>{be(e=>ia.length?Math.min(e,ia.length-1):0)},[ia.length]),(0,H.useEffect)(()=>{if(!na||!Zi){Zi||Pr([]);return}let e=!1;return Nt(ln,{maxDepth:3,maxEntries:80}).then(t=>{e||Pr(t)}),()=>{e=!0}},[na,Zi,ln,V?.workspace]),(0,H.useEffect)(()=>{if(!na)return;let e=Ki.current;e&&e.querySelector(`[data-mention-index="${yr}"]`)?.scrollIntoView({block:`nearest`})},[yr,na,ta.length]),(0,H.useEffect)(()=>{if(!aa)return;let e=qi.current;e&&e.querySelector(`[data-plugin-index="${_e}"]`)?.scrollIntoView({block:`nearest`})},[_e,aa,ia.length]),(0,H.useEffect)(()=>{if(!na&&!aa&&!Or)return;function e(e){let t=e.target;Ki.current?.contains(t)||qi.current?.contains(t)||K.current?.contains(t)||Wi.current?.contains(t)||e.target?.closest?.(`[data-add-menu-btn]`)||(wr(!0),Dr(!0),kr(!1))}return document.addEventListener(`pointerdown`,e,!0),()=>document.removeEventListener(`pointerdown`,e,!0)},[na,aa,Or]),(0,H.useEffect)(()=>{if(!Rt||nn!==`ok`)return;function e(e){let t=e.target;Ji.current?.contains(t)||z(null)}let t=window.setTimeout(()=>{document.addEventListener(`pointerdown`,e,!0)},0);return()=>{window.clearTimeout(t),document.removeEventListener(`pointerdown`,e,!0)}},[Rt,nn]),(0,H.useEffect)(()=>{if(!ir&&!tt)return;function e(e){let t=e.target;t?.closest?.(`[data-session-menu]`)||t?.closest?.(`[data-ws-menu]`)||(ar(null),ut(null))}return document.addEventListener(`pointerdown`,e,!0),()=>document.removeEventListener(`pointerdown`,e,!0)},[ir,tt]);function pa(){Ot().then(e=>Sn(e)),bt().then(e=>{wn(e),En(!0)}),Yt().then(e=>On(e)),cn().then(e=>An(e)),xt().then(e=>Mn(e)),tn().then(e=>Nn(e))}function ma(e){Nn(e),qn(t=>({...t,[e.workspace]:!0}))}async function ha(e,t=`select`){if(G&&!Fn){Bn(!0),z(null);try{ma(t===`add`?await jt(e):await rn(e))}catch(e){z(e instanceof Error?e.message:String(e))}finally{Bn(!1)}}}function ga(e){let t=ca.current;if(!t)return null;let n=e?.workspacePath?.trim();return n&&(n===t.harnessRoot||t.items.some(e=>e.path===n))?n:t.projectRoot?.trim()||null}async function _a(e){if(!G||Fn)return;let t=ga(e);if(!t)return;let n=ca.current;if(n&&t!==n.workspace){Bn(!0);try{ma(await rn(t))}catch{}finally{Bn(!1)}}}async function va(e){if(!G||Fn)return;await ha(e.path,`select`);let t=q.current;if(!t)return;let n=t.sessions.find(e=>e.id===t.activeId);n&&!n.workspacePath&&((n.messages??[]).length>0||(J(Ue(t,n.id,e.path)),qn(t=>({...t,[e.path]:!0}))))}async function ya(){if(G&&!Fn){Bn(!0),z(null);try{let e=await Pt();if(!e)return;ma(await jt(e))}catch(e){z(e instanceof Error?e.message:String(e))}finally{Bn(!1)}}}async function ba(){let e=ft;if(e&&G&&!Fn){if(e.id===`ws_project`)pt(null);else{pt(null),ut(null),Bn(!0),z(null);try{q.current&&J(ot(q.current,e.path));let t=await Et(e.id);ma(t),t.projectRoot&&qn(e=>({...e,[t.projectRoot]:!0}))}catch(e){z(e instanceof Error?e.message:String(e))}finally{Bn(!1)}}}}function xa(e){G&&!Fn&&e.id!==`ws_project`&&(ar(null),ut(null),pt(e))}async function Sa(e){let t=mt;if(ht(null),t&&G){Bn(!0),z(null);try{ma(await lt(t,e))}catch(e){z(e instanceof Error?e.message:String(e))}finally{Bn(!1)}}}function Ca(e){if(!e||!q.current)return q.current;let t=q.current.sessions.find(t=>t.id===e);if(!t||!Ke(t))return q.current;let n=Xi.current[e];return n&&(n.input?.trim()||(n.attachments?.length??0)>0||(n.images?.length??0)>0||(n.docRefs?.length??0)>0)?q.current:(delete Xi.current[e],rt(q.current,e))}function wa(e){Qi&&(e.collection!==`workspace`&&!Ir?z(g(`knowledge`)):C.length>=ed?z(`最多引用 ${ed} 篇文档`):(z(null),w(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,ed)),d(u.slice(0,Qi.from).replace(/\s+$/,``)),wr(!0),Wi.current?.focus()))}function Ta(){ra&&(d(u.slice(0,ra.from).replace(/\s+$/,``)),Dr(!0))}function Ea(e){if(!B[e])return z(g(e)),!1;if(z(null),e===`caseGen`)return D(!0),!0;if(e===`promptGen`)return ie(!0),!0;if(e===`knowledgeGen`)return P(!0),!0;if(e===`pluginDev`)return Ba(),!0;if(e===`memory`)return cr(`memory`),!0;if(e===`knowledge`){let e=u.replace(/\s+$/,``);return d(e?`${e} @`:`@`),wr(!1),requestAnimationFrame(()=>Wi.current?.focus()),!0}return!1}function Da(e){Ta(),Ea(e)}function Oa(){let e=Ui.current;if(!e)return;let t=e.scrollHeight-e.clientHeight-e.scrollTop<=48;if(sa.current){if(!t)return;sa.current=!1}oa.current=t,fn(!t)}function ka(){let e=Ui.current;e&&(oa.current=!0,sa.current=!0,fn(!1),e.scrollTo({top:e.scrollHeight,behavior:`smooth`}))}(0,H.useEffect)(()=>{if(!r||!q.current)return;let e=q.current.sessions.find(e=>e.id===q.current.activeId)?.messages??[],t=JSON.stringify(e)!==JSON.stringify(s),n=Ve(q.current,s,{touchUpdatedAt:t});q.current=n,o(n),at(n),oa.current&&!sa.current&&Ui.current?.scrollTo({top:Ui.current.scrollHeight})},[s,r]),(0,H.useEffect)(()=>{let e=()=>{q.current&&at(q.current)};return window.addEventListener(`pagehide`,e),()=>window.removeEventListener(`pagehide`,e)},[]),(0,H.useLayoutEffect)(()=>{let e=Wi.current;e&&(e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,280)}px`)},[u]),(0,H.useEffect)(()=>{if(!r||!I||!s.length)return;let e=I,t=window.setTimeout(()=>{let t=(Ui.current??document).querySelector(`[data-focus-doc="${CSS.escape(e)}"]`);t instanceof HTMLElement&&(t.scrollIntoView({behavior:`smooth`,block:`center`}),t.classList.add(`ring-2`,`ring-[#4176e6]`,`ring-offset-2`),window.setTimeout(()=>{t.classList.remove(`ring-2`,`ring-[#4176e6]`,`ring-offset-2`)},2400)),ge(null)},80);return()=>window.clearTimeout(t)},[r,I,s]);function Aa(e,t){At(n=>{let r=n.includes(e);return t&&!r?[...n,e]:!t&&r?n.filter(t=>t!==e):n}),q.current?.activeId===e&&(Jr.current=t,wt(t))}function ja(e){e&&(Hr.current.get(e)?.abort.abort(),Wr.current.get(e)?.(),Wr.current.delete(e),Gn(e))}function Ma(e,t){if(t.type===`reasoning`&&t.delta)Pa(e,n=>{let r=n[n.length-1];if(r?.role!==`assistant`)return n;let i=fe((r.reasoning??``)+t.delta),a=[...r.activitySteps??[]],o=a.findIndex(e=>e.kind===`thinking`),s={id:`thinking`,kind:`thinking`,title:`思考`,detail:gd(i).replaceAll(`**`,``).slice(0,80)||void 0,status:`running`};o>=0?a[o]={...a[o],...s}:a.unshift(s);let c=n.slice(),l=Kr.current.get(e),u=r.ttftMs;return l&&l.firstToken==null&&(l.firstToken=Date.now(),u=Math.max(0,l.firstToken-l.start)),c[c.length-1]={...r,reasoning:i,activitySteps:a,turnStatus:`running`,ttftMs:u},c});else if(t.type===`content`&&t.delta)Pa(e,n=>{let r=n[n.length-1];if(r?.role!==`assistant`)return n;let i=(r.activitySteps??[]).map(e=>e.kind===`thinking`&&e.status===`running`?{...e,status:`done`}:e),a=n.slice(),o=Kr.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:fe((r.content??``)+t.delta),activitySteps:i,turnStatus:`running`,ttftMs:s},a});else if(t.type===`tool`&&t.name){let n=dd(t.name),r=hd(t.name,t.args),i=`tool_${t.name}_${t.args?.slice(0,24)??``}`;Fa(e,i,t.status);let a=t.status===`done`&&typeof t.result==`string`&&/^\s*\{\s*"error"\s*:/.test(t.result);Pa(e,e=>{let o=e[e.length-1];if(o?.role!==`assistant`)return e;let s=[...o.activitySteps??[]],c=s.findIndex(e=>e.id===i||e.detail===r&&e.title===n&&e.status===`running`),l={id:i,kind:pd(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}),q.current?.activeId===e&&U(_d(Pe().toolStepDetail,n,t.name,t.status===`running`?`running`:`done`))}else if(t.type===`usage`&&t.usage)Pa(e,e=>{let n=e[e.length-1];if(n?.role!==`assistant`)return e;let r=e.slice();return r[r.length-1]={...n,usage:t.usage},r});else if(t.type===`status`){let n=t.status;(n===`completed`||n===`stopped`||n===`error`)&&(Pa(e,e=>{let r=e[e.length-1];if(r?.role!==`assistant`)return e;let i=t.assistant,a=e.slice(),o=typeof i?.toolMs==`number`?i.toolMs:void 0,s=typeof i?.llmMs==`number`?i.llmMs:void 0,c=typeof i?.ttftMs==`number`?i.ttftMs:void 0,l=typeof i?.tps==`number`?i.tps:void 0;return a[a.length-1]={...r,content:typeof i?.content==`string`?i.content:r.content,reasoning:typeof i?.reasoning==`string`?i.reasoning:r.reasoning,reasoningApi:typeof i?.reasoningApi==`string`?i.reasoningApi:r.reasoningApi,activitySteps:(i?.activitySteps??r.activitySteps??[]).map(e=>e.status===`running`?{...e,status:`done`}:e),turnStatus:n===`completed`?`completed`:`stopped`,time:Date.now(),usage:i?.usage??r.usage,model:typeof i?.model==`string`?i.model:r.model,toolMs:o==null?r.toolMs:Math.max(o,r.toolMs??0),llmMs:s??r.llmMs,ttftMs:c??r.ttftMs,tps:l??r.tps},a}),n===`error`&&t.error&&q.current?.activeId===e&&z(fd(t.error)),Hr.current.delete(e),Ur.current===e&&(Ur.current=null),Aa(e,!1),q.current?.activeId===e&&U(null))}}function Na(e,t=0){Wr.current.get(e)?.(),Aa(e,!0),(async()=>{let n=await Kn(e),r=t;if(n?.ok&&n.assistant&&(r=Math.max(r,n.seq??0),Pa(e,e=>{let t=e[e.length-1],r=t?.role===`assistant`?t:{role:`assistant`,content:``,turnStatus:`running`},i=n.assistant,a={...r,content:typeof i?.content==`string`?i.content:r.content,reasoning:typeof i?.reasoning==`string`?i.reasoning:r.reasoning,reasoningApi:typeof i?.reasoningApi==`string`?i.reasoningApi:r.reasoningApi,activitySteps:i?.activitySteps??r.activitySteps,turnStatus:n.status===`completed`?`completed`:n.status===`stopped`||n.status===`error`?`stopped`:`running`,usage:i?.usage??r.usage,model:typeof i?.model==`string`?i.model:r.model,llmMs:typeof i?.llmMs==`number`?i.llmMs:r.llmMs,ttftMs:typeof i?.ttftMs==`number`?i.ttftMs:r.ttftMs,toolMs:typeof i?.toolMs==`number`?Math.max(i.toolMs,r.toolMs??0):r.toolMs,tps:typeof i?.tps==`number`?i.tps:r.tps};if(t?.role===`assistant`){let t=e.slice();return t[t.length-1]=a,t}return[...e,a]}),n.status&&n.status!==`running`&&n.status!==`waiting_user`)){Aa(e,!1);return}let i=Yn(e,r,{onEvent:t=>Ma(e,t),onGaveUp:t=>{q.current?.activeId===e&&z(t.message||`与服务端回合断开`),Aa(e,!1)}});Wr.current.set(e,i)})()}function Pa(e,t,n){let r=Hr.current.get(e),i=q.current?.sessions.find(t=>t.id===e)?.messages??[],a=r?.messages??(q.current?.activeId===e?la.current:i),o=typeof t==`function`?t(a):t;r&&(r.messages=o),q.current?.activeId===e&&(la.current=o,l(o)),q.current&&J(Le(q.current,e,o,{touchUpdatedAt:n?.touchUpdatedAt!==!1}))}function Y(e){let t=Ur.current??q.current?.activeId;t&&Pa(t,t=>{let n=t[t.length-1];if(n?.role!==`assistant`)return t;let r=t.slice();return r[r.length-1]=e(n),r})}function Fa(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);Pa(e,e=>{let t=e[e.length-1];if(t?.role!==`assistant`)return e;let n=e.slice();return n[n.length-1]={...t,toolMs:(t.toolMs??0)+a},n})}async function X(e){if(!e.length)return;let t=[],n=[],r=cd(f,_);for(let i of e)if(r+t.length>=6)n.push(`${i.name||`图片`}(最多 6 个文件)`);else try{t.push(await sd(i))}catch(e){n.push(e instanceof Error?e.message:String(e))}t.length&&S(e=>[...e,...t].slice(0,6)),z(n.length?`以下图片未添加:${n.join(`、`)}`:null)}function Ia(){d(``),p([]),S([]),w([]),wr(!1),Dr(!1)}function La(){if(oi===`plan`&&(co(),ai(`off`)),oi===`pluginDev`){F(null),pe.current=null,q.current&&J(Re(q.current,{pluginDev:void 0}));let e=he.current;he.current=null,e===`readonly`&&(un(`readonly`),q.current&&J(Re(q.current,{access:`readonly`})))}si(null)}function Ra(){si(`goal`),requestAnimationFrame(()=>Wi.current?.focus())}function za(){ai(e=>e===`off`?`planning`:e),si(`plan`),requestAnimationFrame(()=>Wi.current?.focus())}function Ba(){G?(si(`pluginDev`),ln===`readonly`&&(he.current=`readonly`,un(`readwrite`),q.current&&J(Re(q.current,{access:`readwrite`}))),requestAnimationFrame(()=>Wi.current?.focus())):z(`本地文件服务未就绪:插件开发需要读写项目源码`)}function Va(e){li(e),si(`reports`),window.setTimeout(()=>Wi.current?.focus(),400)}function Ha(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 Ua(e){if(!t)return Me(`model`),!1;let n=Ha(la.current);if(n.length<4)return z(`对话轮次较少,无需压缩`),!1;U(`正在压缩上下文…`);try{let{messages:r,compacted:i}=await vc(t,n,{force:e.force,signal:e.signal});if(!i)return U(null),z(`当前上下文未超过阈值,未压缩`),!1;let a=Date.now(),o=r.map((e,t)=>({role:e.role,content:e.content,reasoning:e.reasoning,time:a+t}));return la.current=o,l(o),q.current&&J(Ve(q.current,o,{touchUpdatedAt:!0})),U(null),!0}catch(e){return U(null),e instanceof DOMException&&e.name===`AbortError`||z(e instanceof Error?e.message:String(e)),!1}}async function Wa(e,n){let r=e===void 0,i=r&&oi===`reports`?`生成${Rn[ci]}`:``,a=(e??u).trim()||i,o=r?f:[],s=r?C:[],c=r?_:[];if(!a&&!o.length&&!s.length&&!c.length)return;if(!t){Me(`model`);return}if(r&&oi===`reports`&&si(null),yc(a)&&!o.length&&!s.length&&!c.length){if(Jr.current){z(`请等待当前回复结束后再压缩`);return}r&&Ia(),await Ua({force:!0})&&z(null);return}if(oi===`goal`&&a&&!o.length&&!s.length&&!c.length&&!Ec(a)&&!yc(a)){r&&Ia();let e={text:a.slice(0,500),status:`active`,updatedAt:Date.now()};ti.current=e,ei(e),ni.current=0,q.current&&J(Re(q.current,{goal:e})),si(null),z(`已设定目标:${e.text}`);return}if(Ec(a)&&!o.length&&!s.length&&!c.length){let e=Tc(a);if(r&&Ia(),!e)return;if(e.kind===`show`){let e=$r;z(e&&e.status!==`cleared`?`当前目标(${e.status}):${e.text}`:`当前无会话目标。可用 /goal set <内容> 设定`);return}if(e.kind===`clear`){ti.current=null,ei(null),ni.current=0,q.current&&J(Re(q.current,{goal:void 0})),z(`已清除会话目标`);return}if(e.kind===`done`){if(!$r?.text){z(`当前无目标可标记完成`);return}let e={...$r,status:`done`,updatedAt:Date.now()};ti.current=e,ei(e),ni.current=0,q.current&&J(Re(q.current,{goal:e})),z(`已标记目标完成:${e.text}`);return}if(e.kind===`set`&&e.text){let t={text:e.text.slice(0,500),status:`active`,updatedAt:Date.now()};ti.current=t,ei(t),ni.current=0,q.current&&J(Re(q.current,{goal:t})),z(`已设定目标:${t.text}`);return}return}if(oi===`pluginDev`&&a&&!o.length&&!s.length&&!c.length){if(Jr.current){z(`请等待当前回复结束后再开始插件开发`);return}await no(a)}let l={id:`q_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,6)}`,content:a,files:[...o],refs:[...s],imgs:[...c]};if(Jr.current){let e=Pe().busySendBehavior??`queue`;if((n?.forceBusy??e)===`queue`){Vi([...zi.current,l]),r&&Ia();return}Bi.current=l,r&&Ia(),ja(q.current?.activeId)}else await Ga(l)}async function Ga(n){let r=q.current?.activeId;if(!t||!r||Hr.current.has(r))return;let{content:i,files:a,refs:o,imgs:s}=n;kc(i)||(ni.current=0),z(null);let c=Date.now(),u={role:`user`,content:i,time:c};a.length&&(u.attachments=a),o.length&&(u.refs=o),s.length&&(u.images=s);let d=la.current,f=d[d.length-1];f?.role===`assistant`&&!f.content&&!f.reasoning&&(d=d.slice(0,-1));let p=[...d,u];if(hc(Ha(p),t.model)){U(`上下文较长,正在压缩…`);try{let{messages:e,compacted:n}=await vc(t,Ha(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})),la.current=p,l(p),q.current&&J(Ve(q.current,p,{touchUpdatedAt:!0}))}}catch{}U(null)}let m=[...p,{role:`assistant`,content:``,time:c,turnStatus:`running`}];la.current=m,l(m),Ia();let h=new AbortController;Ur.current=r,Hr.current.set(r,{abort:h,messages:m}),Vr.current=h,Aa(r,!0),oa.current=!0,fn(!1);let g=Tr(p.map(e=>{let t={role:e.role,content:ad(e)},n=(e.reasoningApi??e.reasoning)?.trim();return e.role===`assistant`&&n&&(t.reasoning_content=n),t}),{keepRecentImageMessages:1}),_=Fr,v=Ir,y=G,b=Lr,x=!!B.todos,S=!!B.tasks,C=ii===`planning`,w=B.pluginDev&&pe.current?.active?pe.current:null,T=w?ln===`full`?`full`:`readwrite`:C?`readonly`:ln,E=zr&&T!==`readonly`,D=Br&&T!==`readonly`,te=ca.current?.workspace?.trim()||``,ne=te?`\n当前工作区:${te}`:``,O=B.promptGen&&oe.current?.active?oe.current:null,re=!O&&B.knowledgeGen&&ue.current?.active?ue.current:null,k=!O&&!re&&B.caseGen&&j.current?.active?j.current:null,M=!!(O||re||k),ie=te,N=ee;if(w)N=hs(w,ca.current?.harnessRoot||ca.current?.projectRoot||te);else if(O)N=Go(O);else if(re)N=ls(re);else if(k){if(!k.promptBody?.trim()){z(`生成测试用例已启用,但未选择提示词。请打开插件重新「确认」。`),Hr.current.delete(r),Ur.current=null,Vr.current=null,Aa(r,!1),l(e=>e[e.length-1]?.role===`assistant`&&!e[e.length-1]?.content?e.slice(0,-1):e);return}try{N=Ao(k,k.reqPath?.split(`/`).pop()?.replace(/\.[^.]+$/,``)||``)}catch(e){z(e instanceof Error?e.message:String(e)),Hr.current.delete(r),Ur.current=null,Vr.current=null,Aa(r,!1);return}}if(!M){let e=vn;if(!w&&!e.trim()&&B.reports)try{await Ln(!0),e=await In()}catch{}!w&&e.trim()&&(N=`${N}\n\n${e.trim()}`);let t=Zs({lastUserMessageAt:[...p].reverse().find(e=>e.role===`user`&&e!==p[p.length-1])?.time??[...p].reverse().find(e=>e.role===`user`)?.time??null,lastInjectAt:qr.current});if(t.injected&&(qr.current=t.at),N=`${N}\n\n${t.text}`,y)try{let e=await gt();e?.text&&(N=`${N}\n\n${dt}\n\n${e.text}`)}catch{}}let se=Yu(N,g,{memory:_&&!M,knowledge:v&&!M,fs:y&&!M,web:b&&!M,bash:E&&!M,pwsh:D&&!M,interact:!M,todos:x&&!M,tasks:S&&!M,planPhase:M||w?`off`:ii,goalEnabled:!M,goal:$r,scheduleEnabled:!M,subagentEnabled:!M,workflowEnabled:!M}).map((e,t)=>t===0&&e.role===`system`&&y&&ne&&!M?{...e,content:`${typeof e.content==`string`?e.content:``}${ne}`}:e);if(_&&!M&&!w){U(`记忆注入中…`);let{context:e}=await qt(i,{cwd:ie});if(e&&se[0]?.role===`system`){let t=typeof se[0].content==`string`?se[0].content:``;se=[{...se[0],content:`${t}\n\n${e}`},...se.slice(1)]}U(null)}let P=[];M||(v&&P.push(...Gl),y&&(P.push(...yt(T)),P.push(...kt),P.push(...vs),P.push(...Hs),P.push(br),C||(P.push(_r),P.push(_t))),E&&(P.push(Gt),P.push(...Zt)),D&&(P.push(zt),P.push(...$t)),(E||D)&&P.push(...It),b&&P.push(...vt),_&&P.push(...Ft),P.push($s),x&&P.push(...Ss),S&&P.push(...Ns),P.push(ec),P.push(...xc),P.push(...Hc),P.push(...sl),P.push(...Fl),(ii===`planning`||ii===`approved`)&&P.push(cc));let ce=Date.now(),de=0;Kr.current.set(r,{start:ce});let F=0,he=!1,I=``,ge=!1,L,_e=!!(O||re||k);function ve(e){return O?Ko(e):re?us(e):jo(e)}function ye(){return O?`正在编写提示词…`:re?`正在编写知识库…`:`正在编写用例…`}let be=!1;try{let n=``,a=``,o=``;if(_e){U(ye());let e=()=>{let e=Math.max(0,Math.floor((Date.now()-ce)/1e3));Y(t=>({...t,content:ve(e)}))};e(),L=window.setInterval(e,1e3)}if(!(x||S)&&!_e&&!w&&await Hn(h.signal)){let e=P.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 Wn({sessionId:r,messages:se,settings:{baseURL:t.baseURL,apiKey:t.apiKey,model:t.model,reasoningEffort:t.reasoningEffort},tools:e,thinking:!0,workspace:te||``,access:T})).ok&&(be=!0,await new Promise(e=>{let t=!1,n=()=>{t||(t=!0,e())},i=()=>{Gn(r)};h.signal.addEventListener(`abort`,i),Wr.current.get(r)?.();let a=Yn(r,0,{signal:h.signal,onEvent:e=>Ma(r,e),onTerminal:e=>{ge=e.status===`completed`,h.signal.removeEventListener(`abort`,i),Wr.current.delete(r),n()},onGaveUp:e=>{q.current?.activeId===r&&z(e.message||`与服务端回合断开`),Pa(r,e=>{let t=e[e.length-1];if(t?.role!==`assistant`)return e;let n=e.slice();return n[n.length-1]={...t,turnStatus:`stopped`,activitySteps:(t.activitySteps??[]).map(e=>e.status===`running`?{...e,status:`done`}:e)},n}),h.signal.removeEventListener(`abort`,i),Wr.current.delete(r),n()}});Wr.current.set(r,()=>{a(),n()})}))}if(!be){let s=me(t,se,h.signal,{tools:P.length?P:void 0,runTool:P.length?async(n,i)=>{hr(!0);let a=dd(n);U(_d(Pe().toolStepDetail,a,n,`running`));let o=Date.now();try{if(n.startsWith(`kb_`))return await Jl(n,i,{base:`/`,docs:e});if(n.startsWith(`fs_`)){let e=await Vt(n,i,T),t=Gs(n,e);if(t&&q.current){let e=Ws(q.current.sessions.find(e=>e.id===r)?.workspaceChanges,t);J(ze(q.current,r,{workspaceChanges:e}))}return e}if(n.startsWith(`skill_`))return await ys(n,i);if(n===`load_workspace_dependencies`)return await xr(n);if(n===`office_to_pdf`)return C?JSON.stringify({error:`计划模式探查中:请先 submit_plan 并等待批准`}):await vr(n,i,T);if(n.startsWith(`workspace_changes_`)){let e=q.current?.sessions.find(e=>e.id===r),{text:t,next:i}=Ks(n,e?.workspaceChanges);return i&&q.current&&J(ze(q.current,r,{workspaceChanges:i})),t}if(n.startsWith(`working_directory_`)){let{text:e,info:t}=await Qt(n,i);return t&&(ma(t),n===`working_directory_set`&&q.current&&J(ze(q.current,r,{workspacePath:t.workspace}))),e}if(n===`present`){if(C)return JSON.stringify({error:`计划模式探查中:请先 submit_plan 并等待批准`});let e=await sn(i,T);try{let t=JSON.parse(e);t.ok&&t.files?.length&&Y(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(C)return JSON.stringify({error:`计划模式探查中:请先 submit_plan 并等待批准`});let e;try{e=JSON.parse(i||`{}`).items}catch{e=void 0}let t=Hu(`todo`,e);t.length||t.push(Vu(`todo`));let n=await Pi(`todo`,t);if(!n)return JSON.stringify({ok:!1,cancelled:!0,message:`用户取消了新增待办,未写入任何数据。`});let r=(Array.isArray(e)?e:[]).filter(e=>!!e&&typeof e==`object`&&typeof e.title==`string`&&!!String(e.title).trim());i=JSON.stringify({items:Uu(`todo`,n).map((e,t)=>{let n=r[t]??{},i={...n,...e};return e.taskId||(n.taskId!==void 0&&(i.taskId=n.taskId),n.linkedTask!==void 0&&(i.linkedTask=n.linkedTask)),i})})}if(n===`task_add`){if(C)return JSON.stringify({error:`计划模式探查中:请先 submit_plan 并等待批准`});let e=Hu(`task`,Ps(i));e.length||e.push(Vu(`task`));let t=await Pi(`task`,e);if(!t)return JSON.stringify({ok:!1,cancelled:!0,message:`用户取消了新增任务,未写入任何数据。`});i=JSON.stringify({items:Uu(`task`,t)})}if(n.startsWith(`task_`)){let e=await Fs(n,i,{sessionId:r});if(n===`task_add`)try{let t=JSON.parse(e);t.ok&&t.count&&(an(`ok`),z(`已创建 ${t.count} 个任务,可在侧栏「任务管理」查看。`))}catch{}return e}if(n.startsWith(`todo_`)&&n!==`todo_write`){if(C&&n!==`todo_list`)return JSON.stringify({error:`计划模式探查中:请先 submit_plan 并等待批准`});let e=await Os(n,i,{sessionId:r});if(n===`todo_add`)try{let t=JSON.parse(e);t.ok&&t.count&&(an(`ok`),z(`已记录 ${t.count} 条待办,可在侧栏「待办事项」查看。`))}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=tc(e);return q.current?.activeId===r&&Qr(t),q.current&&J(ze(q.current,r,{todos:t})),JSON.stringify({ok:!0,count:t.length,todos:t})}if(n.startsWith(`goal_`)){if(n===`goal_get`)return Cc(q.current?.activeId===r?ti.current:Sc(q.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 q.current?.activeId===r&&(ti.current=t,ei(t),ni.current=0),q.current&&J(ze(q.current,r,{goal:t})),Cc(t)}if(n===`goal_done`){let e=q.current?.activeId===r?ti.current:Sc(q.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 q.current?.activeId===r&&(ti.current=t,ei(t),ni.current=0),q.current&&J(ze(q.current,r,{goal:t})),Cc(t)}return n===`goal_clear`?(q.current?.activeId===r&&(ti.current=null,ei(null),ni.current=0),q.current&&J(ze(q.current,r,{goal:void 0})),JSON.stringify({ok:!0,goal:null})):JSON.stringify({error:`unknown tool: ${n}`})}if(n.startsWith(`schedule_`))return await il(n,i,r);if(n===`list_agents`||n===`spawn_subagent`||n===`fork_subagent`||n.startsWith(`subagent_`))return await Ol(n,i,{settings:mr(t,Pe().subagentModel),parentSignal:h.signal,access:T,fsEnabled:y,webEnabled:b,parentMessages:g,onHint:e=>U(e),runFs:(e,t,n)=>Vt(e,t,n),runWeb:(e,t)=>Dt(e,t)});if(n===`workflow`)return await Vl(n,i,{settings:t,parentSignal:h.signal,access:T,fsEnabled:y,webEnabled:b,parentMessages:g,onHint:e=>U(e),runFs:(e,t,n)=>Vt(e,t,n),runWeb:(e,t)=>Dt(e,t)});if(n===`ask_user_question`){let e=nc(i);if(!e.length)return JSON.stringify({error:`questions is required`});let t={};for(let n of e)t[n.id]={selected:[],text:``};return hi(t),_i(0),yi(!1),xi(null),Ci(!1),Ti(``),pi(e),await new Promise((e,t)=>{Yr.current={resolve:e,reject:t};let n=Vr.current,r=()=>{n?.signal.removeEventListener(`abort`,r),so()};n?.signal.addEventListener(`abort`,r)})}if(n===`submit_plan`){let e=lc(i);return e?(di(e),await new Promise((e,t)=>{Xr.current={resolve:e,reject:t};let n=Vr.current,r=()=>{n?.signal.removeEventListener(`abort`,r),co()};n?.signal.addEventListener(`abort`,r)})):JSON.stringify({error:`title and steps are required`})}return n===`bash`?await Ht(i,T):n===`pwsh`?await Wt(i,T):n.startsWith(`bash_session_`)?await Bt(n,i,T):n.startsWith(`pwsh_session_`)?await Xt(n,i,T):n.startsWith(`job_`)?await en(n,i,T):n.startsWith(`web_`)?await Dt(n,i):n.startsWith(`memory_`)?await Ct(n,i,ie):JSON.stringify({error:`unknown tool: ${n}`})}finally{let e=Math.max(0,Date.now()-o);Y(t=>({...t,toolMs:(t.toolMs??0)+e})),hr(!1),pa()}}:void 0});for await(let e of s){if(e.type===`tool`){let t=dd(e.name);U(_d(Pe().toolStepDetail,t,e.name,e.status===`running`?`running`:`done`));let n=hd(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);Y(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:pd(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=de?(n-de)/1e3:0,i=Jd(e.usage),a=r>.2&&i>0?i/r:void 0;Y(r=>({...r,usage:e.usage,tps:a,model:t.model,ttftMs:de?de-ce:r.ttftMs,llmMs:n-ce}));continue}if(de===0&&(de=Date.now(),Y(e=>({...e,ttftMs:de-ce,model:t.model}))),e.type===`reasoning_api`){Y(t=>({...t,reasoningApi:e.content}));continue}e.type===`reasoning`&&F===0&&(F=Date.now());let r=e.type===`content`&&F>0&&!he;if(r&&(he=!0),_e){e.type===`content`&&(O?a+=e.delta:re?o+=e.delta:n+=e.delta);let t=ve(Math.max(0,Math.floor((Date.now()-ce)/1e3)));if(e.type===`reasoning`){I+=e.delta;let n=fe(I);Y(e=>{let i={...e,reasoning:n,content:t};return r&&(i.reasoningDuration=Math.max(1,Math.round((Date.now()-F)/1e3))),i})}else r&&Y(e=>({...e,content:t,reasoningDuration:Math.max(1,Math.round((Date.now()-F)/1e3))}))}else e.type===`reasoning`&&(I+=e.delta),Y(t=>{let n=e.type===`reasoning`?{...t,reasoning:fe(I)}:{...t,content:fe(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:gd(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()-F)/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(ge=!0,!_e){let e=[...q.current?.sessions.find(e=>e.id===r)?.messages??[]].reverse().find(e=>e.role===`assistant`);e&&typeof e.content==`string`&&!e.content.trim()&&z(`模型本轮没有返回正文(可能工具轮次用尽或输出被截断),请重试或回复「继续」`)}{let e=F>0&&!he?Math.max(1,Math.round((Date.now()-F)/1e3)):null;Y(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(L!=null&&(window.clearInterval(L),L=void 0),O){U(`正在质检并入库…`);let e=await Yo(a,O);if(Y(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&&q.current){let t={...O,linkedPromptPath:e.path};ae(t),oe.current=t,J(Re(q.current,{promptGen:t}))}}else if(re){U(`正在质检并入库…`);let e=await ps(o,re);if(Y(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&&q.current){let t={...re,linkedKnowledgePath:e.path};le(t),ue.current=t,J(Re(q.current,{knowledgeGen:t}))}}else if(k){U(`正在检测覆盖并入库…`);let e=k.reqPath?.split(`/`).pop()?.replace(/\.[^.]+$/,``)||i.slice(0,24),t=await Po(n,k,e);if(Y(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&&q.current){let e={...k,linkedCasePath:t.path};A(e),j.current=e,J(Re(q.current,{caseGen:e}))}}}be&&ge&&Y(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`||q.current?.activeId===r&&z(e instanceof Error?e.message:String(e)),Pa(r,e=>{let t=e[e.length-1];if(t?.role===`assistant`&&!t.content&&!t.reasoning&&!t.activitySteps?.length)return e.slice(0,-1);if(t?.role!==`assistant`)return e;let n=e.slice();return n[n.length-1]={...t,activitySteps:(t.activitySteps??[]).map(e=>e.status===`running`?{...e,status:`done`}:e)},n})}finally{L!=null&&(window.clearInterval(L),L=void 0);let e=Date.now(),n=Kr.current.get(r),a=de||n?.firstToken||0;Y(n=>{let r=n.llmMs??e-ce,i=n.ttftMs??(a?a-ce:void 0),o=i==null?0:Math.max(0,(r-i)/1e3),s=Jd(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:ge?`completed`:(h.signal.aborted||!be)&&n.turnStatus===`running`?`stopped`:n.turnStatus,activitySteps:(n.activitySteps??[]).map(e=>e.status===`running`?{...e,status:`done`}:e)}}),Kr.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),Aa(r,!1);{let e=Pe().toolStepDetail;e===`full`?window.setTimeout(()=>U(null),2800):e===`detailed`?window.setTimeout(()=>U(null),1200):U(null)}if(ge&&_&&Jt(i,ie).finally(()=>{pa()}),ge&&q.current){let e=[...q.current.sessions.find(e=>e.id===r)?.messages??[]].reverse().find(e=>e.role===`assistant`),n=lr({userContent:i,assistantContent:typeof e?.content==`string`?e.content:``,reasoning:e?.reasoning});n.length&&ur({sessionId:r,model:e?.model??t.model,messages:n})}if(ge&&t&&!h.signal.aborted&&q.current){let e=q.current.sessions.find(e=>e.id===r),n=e?.messages??[];if(e&&!ri.current.has(r)&&Zn(e.title,n)){let e=Xn(n);e&&(ri.current.add(r),$n(t,e).then(e=>{if(!e||!q.current)return;let t=q.current.sessions.find(e=>e.id===r);t&&Zn(t.title,t.messages)&&J(Je(q.current,r,e))}))}}let o=q.current?.activeId===r,s=null;if(o){s=Bi.current,Bi.current=null,!s&&zi.current.length&&(s=zi.current[0],Vi(zi.current.slice(1)));let e=wc(ti.current);if(!s&&!M&&Ac({goalActive:!!e,turnOk:ge,aborted:h.signal.aborted,hasFollowUp:!1,askUserPending:!!Yr.current,roundsUsed:ni.current,maxRounds:3})){let t=ni.current+1;ni.current=t,s={id:`goal_drv_${Date.now().toString(36)}`,content:Oc(e,t,3),files:[],refs:[],imgs:[]}}}s&&window.setTimeout(()=>{Ga(s)},0)}}function Ka(){Bi.current=null,Vi([]),ni.current=0;let e=q.current?.activeId;e&&Pa(e,e=>{let t=e[e.length-1];if(t?.role!==`assistant`)return e;let n=e.slice();return n[n.length-1]={...t,turnStatus:`stopped`,activitySteps:(t.activitySteps??[]).map(e=>e.status===`running`?{...e,status:`done`}:e)},n}),ja(e)}function qa(e){Vi(zi.current.filter(t=>t.id!==e))}function Ja(e){let t=zi.current.find(t=>t.id===e);t&&(qa(e),d(t.content),p(t.files),S(t.imgs),w(t.refs),requestAnimationFrame(()=>Wi.current?.focus()))}function Ya(e){let t=zi.current.find(t=>t.id===e);t&&(Vi(zi.current.filter(t=>t.id!==e)),Jr.current?(Bi.current=t,ja(q.current?.activeId)):Ga(t))}function Xa(e){let t=[...zi.current],n=e??t.shift()??null;n&&(Vi(t),Jr.current?(Bi.current=n,ja(q.current?.activeId)):Ga(n))}function Za(e,t){let n=!(s[e]?.reasoningOpen??!1);if(l(t=>t.map((t,n)=>n===e?{...t,reasoningOpen:!t.reasoningOpen}:t)),n){let e=t.currentTarget;requestAnimationFrame(()=>{(e.nextElementSibling??e).scrollIntoView({block:`nearest`,behavior:`smooth`})})}}function Qa(e){e&&(u.trim()||f.length>0||_.length>0||C.length>0?Xi.current[e]={input:u,attachments:f,images:_,docRefs:C}:delete Xi.current[e])}function $a(e){let t=e?Xi.current[e]:void 0;d(t?.input??``),p(t?.attachments??[]),S(t?.images??[]),w(t?.docRefs??[])}function eo(e){e?.abortRun!==!1&&ja(q.current?.activeId),Jr.current=!1,wt(!1),p([]),S([]),w([]),d(``),z(null),fn(!1),oa.current=!0,e?.clearDraft&&q.current?.activeId&&delete Xi.current[q.current.activeId]}function to(e,t){if(!q.current)return;cr(`dialog`);let n=q.current.activeId,r=q.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)eo({clearDraft:!0,abortRun:!1}),o={...q.current,activeId:n,sessions:q.current.sessions.map(e=>e.id===n?a(e):e)};else{Qa(n),eo({clearDraft:!0,abortRun:!1});let e=Ca(n)??q.current,t=V?.workspace?.trim()||void 0;o=et(e,{workspacePath:t,access:je()});let r=o.activeId;o={...o,sessions:o.sessions.map(e=>e.id===r?a(e):e)}}J(o),l([]),A(e===`caseGen`?t:null),j.current=e===`caseGen`?t:null,ae(e===`promptGen`?t:null),oe.current=e===`promptGen`?t:null,le(e===`knowledgeGen`?t:null),ue.current=e===`knowledgeGen`?t:null;let s=o.sessions.find(e=>e.id===o.activeId)?.workspacePath||V?.workspace?.trim()||V?.projectRoot;s&&qn(e=>({...e,[s]:!0})),_a(o.sessions.find(e=>e.id===o.activeId))}async function no(e){let t=q.current;if(!t)return;let n=t.sessions.find(e=>e.id===t.activeId),r=ca.current?.harnessRoot?.trim()||ca.current?.projectRoot?.trim()||ca.current?.workspace?.trim(),i=n?.pluginDev?.active?n.pluginDev:{active:!0,requirement:e.trim(),confirmedAt:Date.now()};if(J(Re(t,{pluginDev:i,access:ln===`full`?`full`:`readwrite`,...r?{workspacePath:r}:{}})),F(i),pe.current=i,he.current=null,co(),ai(`off`),r&&qn(e=>({...e,[r]:!0})),G&&r&&ca.current?.workspace!==r)try{ma(await rn(r))}catch{}}function ro(e){e?.active?to(`caseGen`,e):(A(null),j.current=null,q.current&&J(Re(q.current,{caseGen:void 0})))}function io(e){e?.active?to(`promptGen`,e):(ae(null),oe.current=null,q.current&&J(Re(q.current,{promptGen:void 0})))}function ao(e){e?.active?to(`knowledgeGen`,e):(le(null),ue.current=null,q.current&&J(Re(q.current,{knowledgeGen:void 0})))}function oo(e){if(we(!1),!q.current)return;cr(`dialog`);let t=q.current.activeId;Qa(t),eo({clearDraft:!0,abortRun:!1});let n=Ca(t)??q.current,r=e?.trim()||V?.workspace?.trim()||void 0,i=et(n,{workspacePath:r,access:je()});J(i),l([]),A(null),ae(null),le(null),F(null),pe.current=null,Qr([]),ti.current=null,ei(null),ni.current=0,ai(`off`),si(e=>e===`pluginDev`?null:e),so(),co();let a=r||V?.projectRoot;a&&qn(e=>({...e,[a]:!0})),_a(i.sessions.find(e=>e.id===i.activeId))}function so(){let e=Yr.current;e&&(Yr.current=null,pi(null),hi({}),_i(0),yi(!1),xi(null),Ci(!1),Ti(``),e.resolve(JSON.stringify({canceled:!0,error:`user aborted`})))}function co(){let e=Xr.current;e&&(Xr.current=null,di(null),e.resolve(JSON.stringify({approved:!1,canceled:!0})))}function lo(){let e=Xr.current;e&&(Xr.current=null,di(null),ai(`approved`),e.resolve(JSON.stringify({approved:!0,message:`用户已批准计划,可以开始实施`})))}function uo(){let e=Xr.current;e&&(Xr.current=null,di(null),ai(`planning`),e.resolve(JSON.stringify({approved:!1,message:`用户驳回了计划,请修订后再次 submit_plan`})))}function fo(){ai(e=>e===`off`?(si(`plan`),`planning`):(co(),si(e=>e===`plan`?null:e),`off`))}function po(e,t){return!e||!t?!1:t.skipped||t.text.trim()!==``?!0:e.options?.length?t.selected.length>0:!1}function mo(e,t,n){let r=Yr.current;if(!r)return;Yr.current=null,pi(null),hi({}),_i(0),yi(!1),xi(null),Ci(!1),Ti(``),z(null);let i=t.filter(e=>e.skipped).length,a=String(n?.skipReason??``).trim();r.resolve(JSON.stringify({answers:t,summary:ac(e,t),...i?{skipped:!0,approvalRequired:!0,...a?{skipReason:a}:{},note:`用户跳过了部分或全部问题:跳过的题不算确认,也未批准实施。`+(a?`用户给出的跳过原因:${a}。`:``)+`本轮只允许只读调研与文字方案,禁止 fs_write / fs_mkdir / 改配置;请先说明采用的默认假设(哪几项按推荐)与准备改动的范围`+(a?`,并针对上述原因给出调整`:``)+`,然后等用户明确回复「开始实施」再动手。`}:{note:`answers 为结构化答案;summary 是同一批答案的中文文本版本,可直接据此继续,无需再次提问。`},...n}))}function ho(e,t,n){hi(r=>{let i=r[e.id]??{selected:[],text:``},a=e.multi_select?n?i.selected.filter(e=>e!==t):[...i.selected,t]:[t];return{...r,[e.id]:{selected:a,text:``,skipped:!1}}}),xi(null),e.multi_select||_i(e=>Math.min(e+1,(fi?.length??1)-1))}function go(e){let t=fi?.length??0;t&&(_i(Math.max(0,Math.min(e,t-1))),xi(null))}function _o(e,t){e&&(hi(n=>{let r=n[e.id]??{selected:[],text:``};return{...n,[e.id]:{selected:e.multi_select?r.selected:[],text:t,skipped:!1}}}),xi(null))}function vo(e,t){let n=t.trim(),r=n&&e.options?.length?rc(e,n):null,i=r?{selected:r,text:``,skipped:!1}:{selected:e.multi_select?mi[e.id]?.selected??[]:[],text:n,skipped:!1},a={...mi,[e.id]:i};hi(a),xi(null),Is?bo(a):go(js+1)}function yo(e){return(fi??[]).map(t=>{let n=ic(t,e[t.id]??{selected:[],text:``});return n.skipped||n.text?.trim()||n.selected?.length?n:{id:t.id,selected:[],skipped:!0}})}function bo(e=mi,t=!1){let n=fi;if(!n?.length||!Yr.current)return!1;let r=yo(e),i=r.findIndex(e=>!e.skipped&&!e.text?.trim()&&!e.selected?.length);if(i>=0)return go(i),xi(n[i]?.options?.length?`请先选择选项再提交`:`请先填写回答再提交`),!1;if(!t&&r.some(e=>e.skipped))return Ci(!0),xi(null),!1;let a=wi.trim();return mo(n,r,a?{skipReason:a}:void 0),!0}function xo(){let e=fi,t=Z;if(!e?.length||!t)return;let n={...mi,[t.id]:{selected:[],text:``,skipped:!0}};hi(n),xi(null),Is?bo(n):go(js+1)}function So(){bo(mi,!0)}function Co(){Ci(!1);let e=yo(mi).findIndex(e=>e.skipped);go(e>=0?e:0)}function wo(e){if(we(!1),!q.current||(cr(`dialog`),ar(null),e===q.current.activeId))return;let t=q.current.activeId;Qa(t),so(),co(),ai(`off`),z(null),fn(!1),oa.current=!0;let n=Ca(t)??q.current;n.sessions.some(t=>t.id===e)||(n=q.current);let r=Be(n,e),i=r.sessions.find(t=>t.id===e),a=Hr.current.get(e)?.messages??i?.messages??[];la.current=a,l(a);let o=Hr.current.has(e)||Tt.includes(e);Jr.current=o,wt(o),Vr.current=Hr.current.get(e)?.abort??null,o&&!Wr.current.has(e)&&Na(e,0),A(i?.caseGen?.active?i.caseGen:null),ae(i?.promptGen?.active?i.promptGen:null),le(i?.knowledgeGen?.active?i.knowledgeGen:null),F(i?.pluginDev?.active?i.pluginDev:null),si(e=>i?.pluginDev?.active?`pluginDev`:e===`pluginDev`?null:e),Qr(tc(i?.todos));{let e=Sc(i?.goal);ti.current=e,ei(e),ni.current=0}$a(e),J(r),_a(i)}function Do(e){if(!q.current)return;ar(null),ut(null);let t=q.current.activeId===e;t&&eo({clearDraft:!0}),delete Xi.current[e];let n=rt(q.current,e);if(J(n),t){let e=n.sessions.find(e=>e.id===n.activeId);l(e?.messages??[]),A(e?.caseGen?.active?e.caseGen:null),ae(e?.promptGen?.active?e.promptGen:null),le(e?.knowledgeGen?.active?e.knowledgeGen:null),F(e?.pluginDev?.active?e.pluginDev:null),si(t=>e?.pluginDev?.active?`pluginDev`:t===`pluginDev`?null:t)}}function Oo(e,t){if(!q.current)return;ar(null);let n=q.current.activeId===e&&t;n&&eo();let r=Xe(q.current,e,t);if(J(r),n){let e=r.sessions.find(e=>e.id===r.activeId);l(e?.messages??[])}}function ko(e){if(!q.current)return;let t=q.current.sessions.find(t=>t.id===e);t&&(ar(null),J(Ye(q.current,e,!t.pinned)))}function Mo(e){q.current&&q.current.sessions.some(t=>t.id===e)&&(ar(null),ut(null),Ae(e))}function No(){let e=q.current?.activeId,t=q.current?.sessions.find(t=>t.id===e);t?z(sr(`stats`,t.id,t.updatedAt,()=>tr(er(t))),`ok`):z(`无活跃会话可统计`)}function Fo(e){q.current&&Te&&(ri.current.add(Te),J(Je(q.current,Te,e)),Ae(null))}function Io(){mn(e=>(He(!e),!e))}async function Lo(e){let t=Array.from(e.target.files??[]);e.target.value=``,await Bo(t)}function Ro(){let t=e.map(e=>({collection:e.collection,path:e.path,title:e.title,category:e.category,format:String(e.format)})),n=Nr.map(e=>({collection:`workspace`,path:e.path,title:e.name,category:Kt(V?.workspace,V?.projectRoot),format:e.type===`dir`?`dir`:`file`}));return[...t,...n]}function zo(e){e.length&&w(t=>{let n=[...t];for(let t of e){if(n.length>=ed)break;n.some(e=>e.collection===t.collection&&e.path===t.path)||n.push(t)}return n})}async function Bo(e,t){let n=[],r=[],i=[],a=cd(f,_);for(let o of e)if(a>=6)i.push(`${o.name}(最多 6 个文件)`);else try{let e=await iu(o);e.kind===`image`?r.push(await sd(e.file)):n.push({name:e.name,size:e.size,content:e.content,path:t?.get(o.name)||t?.get(e.name)}),a+=1}catch(e){i.push(e instanceof Error?e.message:String(e))}n.length&&p(e=>[...e,...n]),r.length&&S(e=>[...e,...r]),z(i.length?`以下文件未添加:${i.join(`、`)}`:null),Wi.current?.focus()}function Ho(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=pu(t),o=(t.getData(`text/plain`)||``).trim(),s=Ro(),c=Kt(V?.workspace,V?.projectRoot),l={projectRoot:V?.projectRoot,workspace:V?.workspace,workspaceLabel:c},u=[],d=new Map;for(let e of a){let t=gu(e,l);t?(u.push(t),d.set(su(e),t.path)):d.set(su(e),e)}let f=null;!r.length&&!i.length&&!a.length&&du(o)&&(f=_u(o,s));let p=[],m=[];for(let e of i){let t=d.get(e.name),n=(t?gu(t,l):null)||_u(e.name,s);n?p.push(n):m.push(e)}(u.length>0||p.length>0||f||r.length>0||m.length>0)&&(e.preventDefault(),z(null),zo([...u,...p,...f?[f]:[]]),r.length&&X(r),m.length&&Bo(m,d),Wi.current?.focus())}function Uo(e){let t=e.target.closest(`[data-copy-code]`);t&&Qd(t.closest(`.code-block`)?.querySelector(`pre`)?.textContent??``).then(e=>{e&&(t.textContent=`已复制`,window.setTimeout(()=>{t.textContent=`复制`},1e3))})}let Wo=s.length===0,qo=!!(u.trim()||f.length||C.length||_.length||oi===`reports`),Jo=-1,Xo=-1;s.forEach((e,t)=>{e.role===`user`?Jo=t:e.role===`assistant`&&(Xo=t)});let Zo=e=>e===Jo||e===Xo?``:`opacity-0 group-hover:opacity-100 group-focus-within:opacity-100 transition-opacity`,Qo=ud.find(e=>e.value===ln)??ud[0],$o=oi===`pluginDev`,es=(a?.sessions??[]).filter(e=>!e.archived&&!e.deleted),ns=(a?.sessions??[]).filter(e=>e.archived&&!e.deleted),rs=V?.items??[],is=new Set(rs.map(e=>e.path)),as=V?.workspace??``,os=V?.projectRoot??``,ss=a?.sessions.find(e=>e.id===a.activeId),cs=ss?.workspacePath,ds=!cs||!is.has(cs),fs=V?.workspace?.trim()||``,ms=rs.find(e=>e.path===fs),gs=ms?Lt(ms,os):fs?Kt(fs,os):`工作区`,_s=Jn.trim().toLowerCase(),bs=(0,H.useMemo)(()=>_s?new Set(zs(a,Jn,{limit:50,includeArchived:!0}).map(e=>e.sessionId)):null,[_s,a,Jn]),[xs,Cs]=(0,H.useState)(null);(0,H.useEffect)(()=>{if(!_s){Cs(null);return}let e=!1;return Cs(null),Bs(Jn,{limit:50,includeArchived:!0}).then(t=>{!e&&t?.hits&&Cs(new Set(t.hits.map(e=>e.sessionId)))}),()=>{e=!0}},[_s,Jn]);let ws=xs??bs,Ts=ws?ns.filter(e=>ws.has(e.id)):ns;function Es(e){let t=e.id===`ws_project`||e.path===os;return st(es.filter(n=>!(n.workspacePath!==e.path&&(!t||n.workspacePath&&is.has(n.workspacePath)))).filter(e=>!ws||ws.has(e.id)))}let Ds=rs.filter(e=>!_s||e.name.toLowerCase().includes(_s)||e.path.toLowerCase().includes(_s)?!0:Es(e).length>0);function ks({s:e,nested:t=!1}){let n=e.id===a?.activeId,r=ir===e.id,i=Tt.includes(e.id);return(0,Q.jsx)(zd,{s:e,nested:t,active:n,menuOpen:r,busy:i,onOpen:()=>wo(e.id),onRename:()=>Mo(e.id),onToggleMenu:()=>{ut(null),ar(r?null:e.id)},onTogglePin:()=>ko(e.id),onToggleArchive:()=>Oo(e.id,!e.archived),onExport:()=>{ar(null);let t=Rc(e,`json`);z(t.ok?`已导出 ${t.filename}`:t.error)},onRemove:()=>{ar(null),ut(null),Ie(e.id)}})}let As=fi?.length??0,js=Math.max(0,Math.min(gi,As-1)),Z=fi?.[js],Ms=Z&&mi[Z.id]||{selected:[],text:``},Is=js>=As-1,Ls=po(Z,Ms),Rs=(fi??[]).map((e,t)=>({q:e,index:t})).filter(({q:e})=>mi[e.id]?.skipped);return(0,Q.jsxs)(`div`,{className:`tw-app h-full min-h-0 flex overflow-hidden bg-(--tw-surface-page)`,children:[(0,Q.jsxs)(`aside`,{className:`tw-session-rail shrink-0 border-r border-(--tw-border) flex flex-col transition-[width] ${pn?`w-64`:`w-10`}`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1 ${pn?`px-2.5 pt-2.5`:`px-1 pt-2 justify-center`}`,children:[pn&&(0,Q.jsx)(`div`,{className:`flex-1 min-w-0 text-[13px] font-medium text-stone-700 truncate px-1`,children:R(`chat.workbench`,void 0,dr.language)}),(0,Q.jsx)(`button`,{type:`button`,"aria-label":pn?`收起侧栏`:`展开侧栏`,onClick:Io,className:`w-8 h-8 shrink-0 flex items-center justify-center rounded-lg text-stone-500 hover:bg-stone-200/70`,children:(0,Q.jsx)($,{className:`w-4 h-4`,children:pn?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`}),(0,Q.jsx)(`path`,{d:`M9 3v18`})]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`}),(0,Q.jsx)(`path`,{d:`M15 3v18`})]})})})]}),pn?(0,Q.jsxs)(`div`,{className:`px-2.5 pt-2 space-y-1.5`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>oo(),className:`w-full h-9 flex items-center justify-center gap-1.5 text-[13px] font-medium text-stone-700 bg-white rounded-full border border-stone-200/80 shadow-sm hover:bg-stone-50 transition-colors`,children:[(0,Q.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Q.jsx)(`path`,{d:`M5 12h14`}),(0,Q.jsx)(`path`,{d:`M12 5v14`})]}),R(`chat.newSession`,void 0,dr.language)]}),(0,Q.jsxs)(`button`,{type:`button`,"data-hint":`我的插件`,onClick:()=>we(e=>!e),className:`tw-rail-plugin-btn w-full h-9 flex items-center justify-center gap-1.5 text-[13px] font-medium rounded-full transition-colors ${Ce?`is-active`:``}`,children:[(0,Q.jsx)(Pd,{className:`w-3.5 h-3.5`}),`插件`]})]}):(0,Q.jsxs)(`div`,{className:`px-1 pt-1 flex flex-col gap-1`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>oo(),"data-hint":`新会话`,className:`w-8 h-8 flex items-center justify-center rounded-lg text-[#4176e6] hover:bg-white/80`,children:(0,Q.jsxs)($,{className:`w-4 h-4`,children:[(0,Q.jsx)(`path`,{d:`M5 12h14`}),(0,Q.jsx)(`path`,{d:`M12 5v14`})]})}),(0,Q.jsx)(`button`,{type:`button`,"data-hint":`我的插件`,onClick:()=>we(e=>!e),className:`tw-rail-plugin-btn tw-rail-plugin-btn--icon w-8 h-8 flex items-center justify-center rounded-lg ${Ce?`is-active`:``}`,children:(0,Q.jsx)(Pd,{className:`w-4 h-4`})})]}),pn&&(0,Q.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-2 py-3`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1 px-1.5 pb-2`,children:[(0,Q.jsx)(`div`,{className:`flex-1 text-[12px] font-semibold text-stone-500`,children:R(`chat.workspace`,void 0,dr.language)}),(0,Q.jsx)(`button`,{type:`button`,"aria-label":`搜索`,onClick:()=>{rr(e=>!e),nr&&Qn(``)},className:`w-6 h-6 flex items-center justify-center rounded text-stone-400 hover:text-stone-700 hover:bg-stone-200/70`,children:(0,Q.jsx)(kd,{className:`w-3.5 h-3.5`})}),(0,Q.jsx)(`button`,{type:`button`,"data-hint":G?`添加工作区(选择本地文件夹)`:`本地文件服务未就绪`,disabled:!G||Fn,onClick:()=>void ya(),className:`w-6 h-6 flex items-center justify-center rounded text-stone-400 hover:text-stone-700 hover:bg-stone-200/70 disabled:opacity-40`,children:(0,Q.jsx)(Ad,{className:`w-3.5 h-3.5`})})]}),nr&&(0,Q.jsx)(`input`,{value:Jn,onChange:e=>Qn(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`}),Rr&&(0,Q.jsx)(`div`,{className:`px-1.5 py-2 text-[11px] text-amber-700/80`,children:`本地文件服务未就绪,工作区暂不可用`}),(0,Q.jsxs)(`div`,{className:`space-y-0.5`,children:[Ds.map(e=>{let t=Es(e),n=!!(Vn[e.path]??t.length>0),r=e.id===`ws_project`||e.path===os,i=!!(ss&&(ds?r:cs===e.path)),a=tt===e.id;return(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`div`,{className:`tw-project-row group relative ${i?`is-active`:``} ${n?`is-expanded`:``} ${a?`is-menu-open`:``}`,children:[(0,Q.jsxs)(`button`,{type:`button`,"data-hint":e.path,onClick:t=>{t.stopPropagation(),ar(null),ut(null),qn(t=>({...t,[e.path]:!n})),G&&e.path!==as&&ha(e.path,`select`)},className:`flex-1 min-w-0 h-full flex items-center gap-1.5 text-left outline-none focus:outline-none`,children:[(0,Q.jsx)(`span`,{className:`tw-slot tw-folder`,children:(0,Q.jsx)(Dd,{open:n,className:`w-3.5 h-3.5`})}),(0,Q.jsx)(`span`,{className:`tw-slot tw-chevron`,children:(0,Q.jsx)(Od,{open:n,className:`w-3 h-3`})}),(0,Q.jsx)(`span`,{className:`tw-project-title`,children:Lt(e,os)})]}),(0,Q.jsxs)(`div`,{className:`tw-ws-actions relative shrink-0`,"data-ws-menu":``,children:[(0,Q.jsx)(Ld,{open:a,onToggle:()=>{ar(null),ut(a?null:e.id)},onRename:()=>{ar(null),ut(null),ht(e.id)},onDelete:e.id===`ws_project`?void 0:()=>xa(e)}),(0,Q.jsx)(`button`,{type:`button`,"data-hint":`在此工作区新建会话`,onClick:t=>{t.stopPropagation(),oo(e.path)},className:`w-6 h-6 flex items-center justify-center rounded text-(--tw-label-tertiary) hover:text-(--tw-label-primary) hover:bg-(--tw-session-hover-bg)`,children:(0,Q.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Q.jsx)(`path`,{d:`M5 12h14`}),(0,Q.jsx)(`path`,{d:`M12 5v14`})]})})]})]}),(0,Q.jsx)(`div`,{className:`tw-collapse ${n?`is-open`:``}`,children:(0,Q.jsx)(`div`,{className:`tw-collapse-inner`,children:t.map(e=>(0,Q.jsx)(ks,{s:e,nested:!0},e.id))})})]},e.id)}),!Ds.length&&G&&(0,Q.jsx)(`div`,{className:`px-2 py-3 text-xs text-stone-400`,children:`暂无工作区`})]}),Ts.length>0&&(0,Q.jsxs)(`div`,{className:`mt-3 pt-2 border-t border-stone-200/60`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>gn(e=>!e),className:`w-full flex items-center gap-1 px-1.5 pb-1 text-[11px] text-stone-400 hover:text-stone-600`,children:[(0,Q.jsx)(vd,{className:`w-3 h-3 transition-transform ${hn?`rotate-180`:``}`}),`已归档 (`,Ts.length,`)`]}),(0,Q.jsx)(`div`,{className:`tw-collapse ${hn?`is-open`:``}`,children:(0,Q.jsx)(`div`,{className:`tw-collapse-inner space-y-0.5`,children:Ts.map(e=>(0,Q.jsx)(ks,{s:e},e.id))})})]})]}),pn&&(as||pr||gr)&&(0,Q.jsxs)(`div`,{className:`shrink-0 border-t border-stone-200/60 px-3 py-2 space-y-1`,children:[as&&(0,Q.jsxs)(`div`,{className:`tw-rail-workspace-footer`,"data-hint":as,children:[(0,Q.jsx)(`span`,{className:`tw-rail-workspace-label`,"data-i18n":`chat.workspace`,children:`工作区`}),(0,Q.jsx)(`span`,{className:`tw-rail-workspace-name`,children:Kt(as,os)})]}),(pr||gr)&&(0,Q.jsx)(`div`,{className:`text-[11px] text-(--tw-accent)`,children:gr??R(`tool.running`,void 0,dr.language)})]})]}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex flex-col flex-1 ${Ce?`hidden`:``}`,children:[Wo?null:(0,Q.jsxs)(`div`,{className:`shrink-0 border-b border-(--tw-border) bg-(--tw-surface-page)`,children:[(0,Q.jsx)(`div`,{className:`flex items-center gap-3 px-6 pt-4 pb-2 min-w-0`,children:(0,Q.jsx)(`button`,{type:`button`,"data-hint":`点击重命名`,onClick:()=>{let e=a?.activeId;e&&Mo(e)},className:`min-w-0 flex-1 text-left text-[18px] leading-7 font-semibold text-(--tw-label-primary) truncate hover:text-[#4176e6] transition-colors`,children:a?.sessions.find(e=>e.id===a.activeId)?.title||`新对话`})}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-6 px-6`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>cr(`dialog`),className:`relative h-10 text-sm transition-colors ${or===`dialog`?`text-[#4176e6] font-medium`:`text-stone-500 hover:text-stone-700`}`,children:[`对话`,or===`dialog`&&(0,Q.jsx)(`span`,{className:`absolute left-0 right-0 -bottom-px h-0.5 bg-[#4176e6] rounded-full`})]}),(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>cr(`thread`),className:`relative h-10 text-sm transition-colors ${or===`thread`?`text-[#4176e6] font-medium`:`text-stone-500 hover:text-stone-700`}`,children:[`回合`,or===`thread`&&(0,Q.jsx)(`span`,{className:`absolute left-0 right-0 -bottom-px h-0.5 bg-[#4176e6] rounded-full`})]}),B.todos&&(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>cr(`todos`),className:`relative h-10 text-sm transition-colors ${or===`todos`?`text-[#4176e6] font-medium`:`text-stone-500 hover:text-stone-700`}`,children:[`待办`,or===`todos`&&(0,Q.jsx)(`span`,{className:`absolute left-0 right-0 -bottom-px h-0.5 bg-[#4176e6] rounded-full`})]}),B.memory&&(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>cr(`memory`),className:`relative h-10 text-sm transition-colors ${or===`memory`?`text-[#4176e6] font-medium`:`text-stone-500 hover:text-stone-700`}`,children:[(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[`记忆`,(bn?.suggestionCount??0)>0?(0,Q.jsx)(`span`,{className:`min-w-4.5 h-4.5 px-1 inline-flex items-center justify-center rounded-full bg-red-500 text-[10px] font-medium text-white tabular-nums leading-none`,"data-hint":`${bn?.suggestionCount} 条待确认`,children:bn.suggestionCount>99?`99+`:bn.suggestionCount}):null]}),or===`memory`&&(0,Q.jsx)(`span`,{className:`absolute left-0 right-0 -bottom-px h-0.5 bg-[#4176e6] rounded-full`})]})]}),$r&&$r.status!==`cleared`&&or===`dialog`?(0,Q.jsx)(`div`,{className:`px-6 pb-2`,children:(0,Q.jsxs)(`div`,{className:`rounded-xl border border-[#4176e6]/25 bg-[#f5f8ff] px-3 py-2 flex items-start gap-2`,children:[(0,Q.jsxs)(`span`,{className:`text-[11px] font-medium text-[#4176e6] shrink-0 pt-0.5`,children:[`目标`,$r.status===`done`?`·完成`:``]}),(0,Q.jsx)(`span`,{className:`flex-1 min-w-0 text-[12px] leading-5 ${$r.status===`done`?`text-stone-400 line-through`:`text-stone-800`}`,children:$r.text}),(0,Q.jsx)(`button`,{type:`button`,"data-hint":`清除目标`,className:`text-[11px] text-stone-400 hover:text-stone-600 shrink-0`,onClick:()=>{ti.current=null,ei(null),ni.current=0,q.current&&J(Re(q.current,{goal:void 0}))},children:`清除`})]})}):null,Zr.length>0&&or===`dialog`?(0,Q.jsx)(`div`,{className:`px-6 pb-3`,children:(0,Q.jsxs)(`div`,{className:`rounded-xl border border-stone-200 bg-white px-3 py-2.5`,children:[(0,Q.jsxs)(`div`,{className:`text-[11px] font-medium text-stone-500 mb-1.5`,children:[`待办 · `,Zr.filter(e=>e.status===`completed`).length,`/`,Zr.length]}),(0,Q.jsx)(`ul`,{className:`space-y-1 max-h-28 overflow-y-auto`,children:Zr.map((e,t)=>(0,Q.jsxs)(`li`,{className:`flex items-start gap-2 text-[12px] text-stone-700`,children:[(0,Q.jsx)(`span`,{className:`mt-0.5 w-3.5 h-3.5 rounded-sm border shrink-0 flex items-center justify-center text-[9px] ${e.status===`completed`?`bg-emerald-500 border-emerald-500 text-white`:e.status===`in_progress`?`border-[#4176e6] text-[#4176e6]`:`border-stone-300 text-transparent`}`,"aria-hidden":!0,children:e.status===`completed`?`✓`:e.status===`in_progress`?`…`:``}),(0,Q.jsx)(`span`,{className:e.status===`completed`?`line-through text-stone-400`:``,children:e.content})]},`${t}-${e.content}`))})]})}):null]}),or===`todos`&&B.todos?(0,Q.jsx)(`div`,{className:`flex-1 min-h-0 bg-(--tw-surface-page) tw-pane-enter`,children:(0,Q.jsx)(Bu,{})},`todos-${a?.activeId??``}`):or===`memory`&&B.memory?(0,Q.jsx)(`div`,{className:`flex-1 min-h-0 bg-(--tw-surface-page) tw-pane-enter`,children:(0,Q.jsx)(Au,{live:Fr,pluginOn:!!B.memory,workspacePath:a?.sessions.find(e=>e.id===a.activeId)?.workspacePath||V?.projectRoot||``})},`memory-${a?.activeId??``}`):or===`thread`?(0,Q.jsx)(`div`,{className:`flex-1 min-h-0 bg-(--tw-surface-page) tw-pane-enter overflow-y-auto px-12 sm:px-16 lg:px-20 py-6`,children:(0,Q.jsx)(of,{messages:s,busy:!!(a?.activeId&&Tt.includes(a.activeId)),onRestoreCheckpoint:(e,t)=>{let n=q.current?.activeId;if(!n)return;if(Tt.includes(n)||St){z(`请等待当前回复结束后再从此处继续`);return}let r=Math.max(0,Math.min(e,la.current.length-1)),i=la.current.slice(0,r+1);la.current=i,l(i),q.current&&J(Ve(q.current,i,{touchUpdatedAt:!0}));let a=`请从第 ${t} 轮继续`;cr(`dialog`),d(a),an(`ok`),z(`已回到第 ${t} 轮,正在继续…`),window.setTimeout(()=>{Wa(a)},0)}})},`thread-${a?.activeId??``}`):(0,Q.jsxs)(`div`,{className:`relative flex-1 min-h-0 flex flex-col${Wo?` justify-center`:``}`,children:[Wo?(0,Q.jsxs)(`div`,{className:`shrink-0 flex flex-col items-center text-center px-8 sm:px-10 lg:px-12 pb-8`,children:[(0,Q.jsx)(`img`,{src:`/brand-mark.png`,alt:``,width:64,height:64,className:`w-16 h-16 rounded-[14px] object-contain`}),(0,Q.jsx)(`h2`,{className:`mt-5 text-[22px] leading-8 font-semibold tracking-tight text-stone-800 text-balance`,children:R(`chat.emptyTitle`,void 0,dr.language)})]}):null,Wo?null:(0,Q.jsxs)(`div`,{className:`relative flex-1 min-h-0`,children:[(0,Q.jsx)(`div`,{ref:Ui,onScroll:Oa,className:`h-full overflow-y-auto px-8 sm:px-10 lg:px-12 py-6`,style:{fontSize:`var(--tw-session-font-size, ${dr.sessionFontSize}px)`},children:(0,Q.jsx)(`div`,{className:`w-full max-w-[min(64rem,100%)] mx-auto flex flex-col gap-4`,onClick:Uo,children:s.map((e,n)=>e.role===`user`?(0,Q.jsxs)(`div`,{className:`group flex flex-col items-end gap-1`,children:[e.refs?.length||e.attachments?.length||e.images?.length?(0,Q.jsxs)(`div`,{className:`flex flex-wrap justify-end gap-1.5 max-w-[82%]`,children:[e.refs?.map(e=>(0,Q.jsxs)(`span`,{className:`flex items-center gap-1.5 px-2.5 py-1.5 text-xs text-[#4176e6] bg-white border border-[#4176e6]/30 rounded-lg`,"data-hint":e.path,children:[(0,Q.jsx)(wd,{className:`w-3.5 h-3.5`}),(0,Q.jsx)(`span`,{className:`text-[10px] text-stone-400 shrink-0`,children:Hl(e.format)}),(0,Q.jsx)(`span`,{className:`max-w-40 truncate`,children:e.title})]},e.path)),e.attachments?.map(e=>(0,Q.jsxs)(`span`,{className:`flex items-center gap-1.5 px-2.5 py-1.5 text-xs text-stone-600 bg-white border border-stone-200 rounded-lg`,children:[(0,Q.jsx)(wd,{className:`w-3.5 h-3.5 text-[#4176e6]`}),(0,Q.jsx)(`span`,{className:`max-w-48 truncate`,children:e.name}),(0,Q.jsx)(`span`,{className:`text-stone-400`,children:Xd(e.size)})]},e.name)),e.images?.map(e=>(0,Q.jsx)(`a`,{href:e.dataUrl,target:`_blank`,rel:`noreferrer`,className:`block overflow-hidden rounded-lg border border-stone-200 bg-white`,"data-hint":e.name,children:(0,Q.jsx)(`img`,{src:e.dataUrl,alt:e.name,className:`max-h-40 max-w-48 object-contain`})},e.id))]}):null,e.content&&(0,Q.jsx)(`div`,{className:`tw-chat-text max-w-[82%] px-4 py-2.5 bg-[#edf3fe] rounded-2xl whitespace-pre-wrap break-words`,children:e.content}),(0,Q.jsxs)(`div`,{className:`tw-msg-actions ${Zo(n)}`,children:[e.time!=null&&(0,Q.jsx)(`span`,{className:`tw-msg-action-time pr-0.5`,children:Zd(e.time)}),(0,Q.jsx)($d,{text:e.content})]})]},n):(0,Q.jsxs)(`div`,{className:`group`,children:[e.turnStatus===`stopped`?(0,Q.jsxs)(`div`,{className:`mb-2`,children:[(0,Q.jsx)(`div`,{className:`text-[13px] text-stone-500 py-1`,children:`已停止`}),(0,Q.jsx)(`div`,{className:`border-t border-stone-200/80`})]}):null,(()=>{let t=e.activitySteps??[],r=t.some(e=>e.status===`running`),i=n===s.length-1&&e.turnStatus!==`stopped`&&(St||r),a=i&&!e.content,o=t.filter(e=>e.kind!==`thinking`);if(!(a||e.reasoning||o.length>0||t.length>0))return null;let c=e.reasoningOpen??!1,l=i||c||r,u=a&&!c&&!l&&e.reasoning?gd(e.reasoning).replaceAll(`**`,``):``;return(0,Q.jsxs)(`div`,{className:`mb-2`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:e=>Za(n,e),className:`flex w-full items-center gap-2 py-1 text-left select-none`,children:[a||i&&!e.content?(0,Q.jsx)(`span`,{className:`w-3.5 h-3.5 shrink-0 rounded-full border-2 border-purple-400 border-t-transparent animate-spin`}):(0,Q.jsxs)($,{className:`w-3.5 h-3.5 shrink-0 text-stone-400`,children:[(0,Q.jsx)(`path`,{d:`M15 14c.2-1 .7-1.7 1.5-2.5 1-.9 1.5-2.2 1.5-3.5A6 6 0 0 0 6 8c0 1 .2 2.2 1.5 3.5.7.7 1.3 1.5 1.5 2.5`}),(0,Q.jsx)(`path`,{d:`M9 18h6`}),(0,Q.jsx)(`path`,{d:`M10 22h4`})]}),(0,Q.jsx)(`span`,{className:`text-[13px] font-medium shrink-0 ${i&&!e.content?`text-shimmer`:`text-shimmer-static`}`,children:i&&!e.content?t.some(e=>e.kind!==`thinking`&&e.status===`running`)?`正在分析请求`:`思考中…`:i?`正在生成…`:e.turnStatus===`stopped`?`已完成分析`:`思考完成`}),!i&&e.reasoningDuration!=null&&(0,Q.jsxs)(`span`,{className:`text-xs text-stone-400 shrink-0`,children:[`用时 `,e.reasoningDuration,`s`]}),(0,Q.jsx)(vd,{className:`w-3.5 h-3.5 shrink-0 text-stone-400 transition-transform ${c?`rotate-180`:``}`}),u?(0,Q.jsx)(`span`,{className:`flex-1 min-w-0 truncate text-xs text-shimmer-muted think-mask`,children:u}):null]}),l&&t.length>0?(0,Q.jsx)(`ul`,{className:`mt-1.5 mb-1 pl-5.5 space-y-1.5`,children:t.map(e=>(0,Q.jsxs)(`li`,{className:`text-[12px] flex items-start gap-2 min-w-0 ${e.status===`error`?`text-red-600`:e.status===`running`?`text-stone-600`:`text-stone-500`}`,children:[(0,Q.jsx)(md,{kind:e.kind,status:e.status}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1 leading-5`,children:[(0,Q.jsx)(`span`,{className:`font-medium ${e.status===`running`?`text-shimmer`:``}`,children:e.title}),e.detail?(0,Q.jsxs)(`span`,{className:`text-stone-400`,children:[` · `,(0,Q.jsx)(`span`,{className:e.status===`error`?`text-red-600`:e.status===`running`?`text-shimmer-muted`:``,"data-hint":e.detail,children:e.detail.length>72?`${e.detail.slice(0,72)}…`:e.detail})]}):e.status===`running`?(0,Q.jsxs)(`span`,{className:`text-stone-400 text-shimmer-muted`,children:[` · `,`…`]}):null]})]},e.id))}):null,c&&e.reasoning?(0,Q.jsx)(`div`,{className:`mt-1.5 mb-2 pl-5.5 text-[13px] leading-5 text-stone-500 whitespace-pre-wrap max-h-80 overflow-y-auto`,children:e.reasoning}):null,e.turnStatus===`stopped`?(0,Q.jsx)(`div`,{className:`mt-1.5 pl-5.5`,children:(0,Q.jsx)(`span`,{className:`tw-turn-stopped-pill`,children:`已停止`})}):null]})})(),e.content?(0,Q.jsx)(`div`,{className:`chat-md prose prose-sm prose-stone max-w-none tw-chat-text`,dangerouslySetInnerHTML:{__html:To(e.content)}}):null,e.caseFile?(0,Q.jsxs)(`button`,{type:`button`,"data-focus-doc":`cases:${e.caseFile.path.replace(/\\/g,`/`)}`,"data-hint":`双击本地打开`,onDoubleClick:()=>{ve(`cases`,e.caseFile.path).catch(e=>z(e instanceof Error?e.message:String(e)))},className:`mt-3 w-full max-w-md flex items-center gap-3 rounded-xl border border-stone-200 bg-white px-3 py-2.5 text-left hover:border-[#4176e6] hover:bg-[#f5f8ff] transition-colors cursor-pointer`,children:[(0,Q.jsx)(`span`,{className:`w-10 h-10 rounded-lg bg-emerald-50 text-emerald-700 flex items-center justify-center text-[10px] font-semibold shrink-0`,children:e.caseFile.name.split(`.`).pop()?.toUpperCase()||`FILE`}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`span`,{className:`block text-sm text-stone-800 truncate`,children:e.caseFile.name}),(0,Q.jsxs)(`span`,{className:`block text-[11px] text-stone-400 truncate`,children:[xe(`cases`),e.caseFile.path,e.caseFile.count>0?` · ${e.caseFile.count} 条`:``,` · 双击本地打开`]})]})]}):null,e.docsFile?(0,Q.jsxs)(`button`,{type:`button`,"data-focus-doc":`${e.docsFile.root}:${e.docsFile.path.replace(/\\/g,`/`)}`,"data-hint":`点击本地打开`,onClick:()=>{ve(e.docsFile.root,e.docsFile.path).catch(e=>z(e instanceof Error?e.message:String(e)))},className:`mt-3 w-full max-w-md flex items-center gap-3 rounded-xl border border-stone-200 bg-white px-3 py-2.5 text-left hover:border-[#4176e6] hover:bg-[#f5f8ff] transition-colors cursor-pointer`,children:[(0,Q.jsx)(`span`,{className:`w-10 h-10 rounded-lg flex items-center justify-center text-[10px] font-semibold shrink-0 ${e.docsFile.root===`knowledge`?`bg-amber-50 text-amber-800`:`bg-sky-50 text-sky-700`}`,children:e.docsFile.name.split(`.`).pop()?.toUpperCase()||`MD`}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`span`,{className:`block text-sm text-stone-800 truncate`,children:e.docsFile.name}),(0,Q.jsxs)(`span`,{className:`block text-[11px] text-stone-400 truncate`,children:[xe(e.docsFile.root),e.docsFile.path,e.docsFile.note?` · ${e.docsFile.note}`:``,` · 点击打开`]})]})]}):null,e.presentFiles?.length?e.presentFiles.map(e=>(0,Q.jsxs)(`button`,{type:`button`,"data-hint":`点击本地打开`,onClick:()=>{Mt(e.path,ln).catch(e=>z(e instanceof Error?e.message:String(e)))},className:`mt-3 w-full max-w-md flex items-center gap-3 rounded-xl border border-stone-200 bg-white px-3 py-2.5 text-left hover:border-[#4176e6] hover:bg-[#f5f8ff] transition-colors cursor-pointer`,children:[(0,Q.jsx)(`span`,{className:`w-10 h-10 rounded-lg bg-violet-50 text-violet-700 flex items-center justify-center text-[10px] font-semibold shrink-0`,children:e.name.split(`.`).pop()?.toUpperCase()||`FILE`}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`span`,{className:`block text-sm text-stone-800 truncate`,children:e.name}),(0,Q.jsxs)(`span`,{className:`block text-[11px] text-stone-400 truncate`,children:[e.path,e.description?` · ${e.description}`:``,` · 点击打开`]})]})]},e.path)):null,e.content&&!(n===s.length-1&&St)?(0,Q.jsxs)(`div`,{className:`tw-msg-actions mt-1 ${Zo(n)}`,children:[(0,Q.jsx)($d,{text:e.content}),e.usage&&(0,Q.jsx)(cf,{usage:e.usage,model:e.model??t?.model}),e.time!=null&&(0,Q.jsx)(`span`,{className:`tw-msg-action-time`,children:Zd(e.time)})]}):null]},n))})}),dn&&(0,Q.jsx)(`button`,{type:`button`,onClick:ka,"data-hint":`回到底部`,className:`absolute bottom-3 right-8 sm:right-10 lg:right-12 w-8 h-8 rounded-full bg-white border border-stone-200 shadow-md flex items-center justify-center text-stone-500 hover:text-stone-800 transition-colors`,children:(0,Q.jsx)(vd,{className:`w-4 h-4`})})]},`dialog-${a?.activeId??``}`),Rt&&(0,Q.jsx)(`div`,{className:`shrink-0 px-8 sm:px-10 lg:px-12 pb-2`,children:(0,Q.jsxs)(`div`,{ref:Ji,className:`w-full max-w-[min(64rem,100%)] mx-auto flex items-start gap-3 px-4 py-3 rounded-xl text-sm border ${nn===`ok`?`tw-notice-anim`:``} ${nn===`ok`?`bg-emerald-50 border-emerald-200 text-emerald-900`:`bg-red-50 border-red-200 text-red-800`}`,children:[(0,Q.jsx)(`span`,{className:`mt-0.5 w-5 h-5 shrink-0 rounded-full flex items-center justify-center text-xs font-semibold ${nn===`ok`?`bg-emerald-100 text-emerald-700`:`bg-red-100 text-red-600`}`,children:nn===`ok`?`i`:`!`}),(0,Q.jsx)(`pre`,{className:`flex-1 min-w-0 m-0 font-sans text-[13px] leading-5 whitespace-pre-wrap break-words`,children:Rt.replace(/\*\*/g,``).replace(/\s*:\s*\*\*/g,`: `).trim()}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>z(null),className:`shrink-0 text-xs ${nn===`ok`?`text-emerald-500 hover:text-emerald-700`:`text-red-400 hover:text-red-600`}`,children:`关闭`})]})}),(0,Q.jsxs)(`div`,{className:`shrink-0 px-8 sm:px-10 lg:px-12 pb-3`,children:[(0,Q.jsxs)(`div`,{className:`w-full max-w-[min(64rem,100%)] mx-auto`,children:[N?.active&&B.promptGen?(0,Q.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 px-3 py-2 rounded-xl border border-[#4176e6]/30 bg-[#edf3fe] text-xs text-[#3565c7]`,children:[(0,Q.jsxs)(`span`,{className:`flex-1 min-w-0 truncate`,children:[`生成提示词已启用 · `,Vo(N)]}),(0,Q.jsx)(`button`,{type:`button`,className:`shrink-0 hover:underline`,onClick:()=>ie(!0),children:`改配置`}),(0,Q.jsx)(`button`,{type:`button`,className:`shrink-0 text-stone-500 hover:text-stone-800`,onClick:()=>io(null),children:`取消`})]}):null,ce?.active&&B.knowledgeGen?(0,Q.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 px-3 py-2 rounded-xl border border-amber-300/60 bg-amber-50 text-xs text-amber-900`,children:[(0,Q.jsxs)(`span`,{className:`flex-1 min-w-0 truncate`,children:[`生成知识库已启用 · `,ts(ce)]}),(0,Q.jsx)(`button`,{type:`button`,className:`shrink-0 hover:underline`,onClick:()=>P(!0),children:`改配置`}),(0,Q.jsx)(`button`,{type:`button`,className:`shrink-0 text-stone-500 hover:text-stone-800`,onClick:()=>ao(null),children:`取消`})]}):null,k?.active&&B.caseGen?(0,Q.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 px-3 py-2 rounded-xl border border-[#4176e6]/30 bg-[#edf3fe] text-xs text-[#3565c7]`,children:[(0,Q.jsxs)(`span`,{className:`flex-1 min-w-0 truncate`,children:[`生成测试用例已启用 · `,Eo(k)]}),(0,Q.jsx)(`button`,{type:`button`,className:`shrink-0 hover:underline`,onClick:()=>D(!0),children:`改配置`}),(0,Q.jsx)(`button`,{type:`button`,className:`shrink-0 text-stone-500 hover:text-stone-800`,onClick:()=>ro(null),children:`取消`})]}):null,jr.length>0?(0,Q.jsx)(`div`,{className:`mb-2 rounded-xl border border-stone-200/80 bg-stone-100/80 overflow-hidden`,children:jr.map(e=>(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 border-b border-stone-200/60 last:border-b-0`,children:[(0,Q.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-stone-400 shrink-0`,"aria-hidden":!0}),(0,Q.jsx)(`span`,{className:`flex-1 min-w-0 truncate text-[13px] text-stone-700`,children:Hi(e)}),(0,Q.jsx)(`button`,{type:`button`,"data-hint":`编辑回输入框`,onClick:()=>Ja(e.id),className:`tw-icon-btn w-7 h-7 rounded-md flex items-center justify-center outline-none`,children:(0,Q.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Q.jsx)(`path`,{d:`M12 20h9`}),(0,Q.jsx)(`path`,{d:`M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z`})]})}),(0,Q.jsx)(`button`,{type:`button`,"data-hint":`从队列移除`,onClick:()=>qa(e.id),className:`tw-icon-btn w-7 h-7 rounded-md flex items-center justify-center outline-none`,children:(0,Q.jsxs)($,{className:`w-3.5 h-3.5`,children:[(0,Q.jsx)(`path`,{d:`M3 6h18`}),(0,Q.jsx)(`path`,{d:`M8 6V4h8v2`}),(0,Q.jsx)(`path`,{d:`M19 6l-1 14H6L5 6`})]})}),(0,Q.jsx)(`button`,{type:`button`,"data-hint":`插话立即发送(其后队列仍会续发)`,onClick:()=>Ya(e.id),className:`tw-icon-btn w-7 h-7 rounded-md flex items-center justify-center outline-none text-[#4176e6]`,children:(0,Q.jsx)(Ed,{className:`w-3.5 h-3.5`})})]},e.id))}):null,ui?(0,Q.jsxs)(`div`,{className:`mb-2 rounded-xl border border-amber-300/60 bg-amber-50/90 px-4 py-3 shadow-sm`,children:[(0,Q.jsx)(`div`,{className:`text-[13px] font-medium text-stone-800 mb-1`,children:`待批准计划`}),(0,Q.jsx)(`div`,{className:`text-[14px] font-medium text-stone-900`,children:ui.title}),ui.summary?(0,Q.jsx)(`p`,{className:`mt-1 text-[13px] text-stone-600 leading-5`,children:ui.summary}):null,(0,Q.jsx)(`ol`,{className:`mt-2 list-decimal pl-5 space-y-1 text-[13px] text-stone-700`,children:ui.steps.map((e,t)=>(0,Q.jsx)(`li`,{children:e},`${t}-${e.slice(0,24)}`))}),(0,Q.jsxs)(`div`,{className:`mt-3 flex items-center justify-end gap-2`,children:[(0,Q.jsx)(`button`,{type:`button`,className:`h-8 px-3 rounded-lg border border-stone-200 bg-white text-[12px] text-stone-600 hover:bg-stone-50`,onClick:()=>uo(),children:`驳回`}),(0,Q.jsx)(`button`,{type:`button`,className:`h-8 px-3 rounded-lg bg-[#4176e6] text-[12px] text-white hover:bg-[#3467d4]`,onClick:()=>lo(),children:`批准实施`})]})]}):null,Ei?(0,Q.jsx)(Ju,{kind:Ei.kind,items:Ei.items,manual:Ei.manual,closing:Oi,onConfirm:e=>{Ei.manual?(Fi(null),Ri(Ei.kind,e)):Fi(e)},onCancel:()=>Fi(null)}):null,As>0&&Z?(0,Q.jsxs)(`div`,{className:`mb-2 flex max-h-[min(60vh,520px)] flex-col overflow-hidden rounded-2xl border border-stone-200 bg-white shadow-[0_6px_24px_rgba(15,23,42,0.08)]`,children:[(0,Q.jsxs)(`div`,{className:`flex shrink-0 justify-between gap-4 px-5 ${vi?`items-center py-3.5`:`items-start pt-4`}`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`div`,{className:`mb-1 text-[11px] leading-4 text-stone-400`,children:Si?`跳过确认`:Z.header||`模型需要你的确认`}),(0,Q.jsx)(`h3`,{className:`text-[15px] leading-5.5 font-medium text-stone-900`,children:Si?`确认 ${Rs.length} 道跳过的题怎么处理`:Z.question})]}),(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[vi?(0,Q.jsx)(`span`,{className:`text-[11px] leading-4 text-stone-400`,children:Si?`已跳过 ${Rs.length} 题`:`第 ${js+1} 步 / 共 ${As} 步`}):null,(0,Q.jsx)(`button`,{type:`button`,"aria-label":vi?`展开问题`:`收起问题`,onClick:()=>yi(e=>!e),className:`grid h-6 w-6 place-items-center rounded-full text-stone-400 outline-none hover:bg-stone-100 hover:text-stone-600`,children:(0,Q.jsx)(vd,{className:`h-4 w-4 transition-transform ${vi?`rotate-180`:``}`})})]})]}),vi?null:Si?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto overscroll-contain px-5 py-2`,children:[(0,Q.jsx)(`p`,{className:`text-[12px] leading-5 text-stone-500`,children:`跳过不算确认,本轮不会开始改代码。留下原因后我只出方案,等你回复「开始实施」。`}),(0,Q.jsx)(`ul`,{className:`mt-2 space-y-1 rounded-lg bg-stone-50 px-3 py-2`,children:Rs.map(({q:e,index:t})=>(0,Q.jsxs)(`li`,{className:`text-[12px] leading-5 text-stone-600`,children:[(0,Q.jsxs)(`span`,{className:`text-stone-400`,children:[t+1,`.`]}),` `,e.header?`${e.header} / `:``,e.question,(0,Q.jsx)(`span`,{className:`ml-1 text-stone-400`,children:`— 已跳过`})]},e.id))}),(0,Q.jsx)(`textarea`,{autoFocus:!0,value:wi,onChange:e=>Ti(e.target.value),onKeyDown:e=>{e.key!==`Enter`||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),So())},rows:3,className:`mt-2 w-full resize-none rounded-lg border border-stone-200 px-2.5 py-2 text-[13px] leading-5 outline-none focus:border-[#4176e6]`,placeholder:`为什么跳过这几题?例如:先只做评估,方案我稍后定 / 这几项按你推荐的来`})]}),(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between gap-3 px-5 pt-2 pb-3`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>Co(),className:`h-8 shrink-0 rounded-lg px-2 text-[12px] text-stone-500 outline-none hover:bg-stone-100 hover:text-stone-700`,children:`返回继续回答`}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>So(),className:`h-8 shrink-0 rounded-lg bg-[#4176e6] px-3.5 text-[12px] font-medium text-white hover:bg-[#3467d4]`,children:`提交并继续`})]})]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto overscroll-contain px-3 py-1`,children:[Z.options?.length?(0,Q.jsx)(`div`,{className:`mt-2 flex flex-col gap-0.5`,role:Z.multi_select?`group`:`radiogroup`,children:Z.options.map((e,t)=>{let n=Ms.selected.includes(e.label),r=Qu(e.label);return(0,Q.jsxs)(`button`,{type:`button`,role:Z.multi_select?`checkbox`:`radio`,"aria-checked":n,onClick:()=>ho(Z,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:[Z.multi_select?(0,Q.jsx)(`span`,{"aria-hidden":`true`,className:`mt-0.5 grid h-4 w-4 shrink-0 place-items-center rounded border ${n?`border-[#4176e6] bg-[#4176e6] text-white`:`border-stone-300 text-transparent`}`,children:(0,Q.jsx)(bd,{className:`h-3 w-3`})}):(0,Q.jsx)(`span`,{"aria-hidden":`true`,className:`mt-0.5 grid h-5 w-5 shrink-0 place-items-center rounded-md text-[11px] font-medium ${n?`bg-[#4176e6] text-white`:`bg-stone-100 text-stone-500`}`,children:t+1}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Q.jsxs)(`span`,{className:`flex flex-wrap items-center gap-x-2 gap-y-0.5`,children:[(0,Q.jsx)(`span`,{className:`text-[13px] leading-5 font-medium text-stone-800`,children:r.label}),r.recommended?(0,Q.jsx)(`span`,{className:`rounded bg-[#edf3fe] px-1 text-[10px] leading-4 font-semibold text-[#4176e6]`,children:`推荐`}):null]}),e.description?(0,Q.jsx)(`span`,{className:`mt-0.5 block text-[12px] leading-4.5 text-stone-400`,children:e.description}):null]})]},`${e.label}-${t}`)})}):(0,Q.jsx)(`div`,{className:`px-1.5 py-2`,children:(0,Q.jsx)(`textarea`,{autoFocus:!0,value:Ms.text,onChange:e=>_o(Z,e.target.value),onKeyDown:e=>{e.key!==`Enter`||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),vo(Z,Ms.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:`输入你的回答…`})}),Z.options?.length?(0,Q.jsx)(`div`,{className:`mt-1 px-1.5 pb-1`,children:(0,Q.jsxs)(`div`,{className:`flex items-start gap-2 rounded-lg border border-stone-200 px-2 py-1.5 focus-within:border-[#4176e6]`,children:[(0,Q.jsx)(`span`,{"aria-hidden":`true`,className:`mt-0.5 grid h-4 w-4 shrink-0 place-items-center rounded bg-stone-100 text-[10px] font-medium text-stone-500`,children:`#`}),(0,Q.jsx)(`textarea`,{value:Ms.text,onChange:e=>_o(Z,e.target.value),onKeyDown:e=>{e.key!==`Enter`||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),vo(Z,Ms.text))},rows:1,className:`min-h-5 w-full resize-none bg-transparent text-[13px] leading-5 outline-none`,placeholder:`输入序号选择(如 1${Z.multi_select?` 或 1,3`:``}),也可直接写你的回答`})]})}):null,(0,Q.jsx)(`div`,{className:`px-2 pb-2 pt-1 text-[11px] leading-4 text-stone-400`,children:Z.options?.length?`回车确认这一步;跳过的题会在提交前让你说明原因,不会直接开始实施`:`回车确认;跳过的题会在提交前让你说明原因,不会直接开始实施`})]}),(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between gap-3 px-5 pt-2 pb-3`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Q.jsx)(`button`,{type:`button`,"aria-label":`上一步`,disabled:js===0,onClick:()=>go(js-1),className:`grid h-6 w-6 place-items-center rounded-full text-stone-400 outline-none hover:bg-stone-100 hover:text-stone-600 disabled:cursor-default disabled:text-stone-200 disabled:hover:bg-transparent`,children:(0,Q.jsx)(yd,{className:`h-4 w-4 rotate-180`})}),(0,Q.jsxs)(`span`,{className:`px-1 text-[12px] font-medium text-stone-500`,children:[`第 `,js+1,` 步 / 共 `,As,` 步`]}),(0,Q.jsx)(`button`,{type:`button`,"aria-label":`下一步`,disabled:Is,onClick:()=>go(js+1),className:`grid h-6 w-6 place-items-center rounded-full text-stone-400 outline-none hover:bg-stone-100 hover:text-stone-600 disabled:cursor-default disabled:text-stone-200 disabled:hover:bg-transparent`,children:(0,Q.jsx)(yd,{className:`h-4 w-4`})})]}),(0,Q.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[bi?(0,Q.jsx)(`span`,{className:`truncate text-[11px] text-rose-500`,children:bi}):null,(0,Q.jsx)(`button`,{type:`button`,onClick:()=>xo(),className:`h-8 shrink-0 rounded-lg px-2 text-[12px] text-stone-500 outline-none hover:bg-stone-100 hover:text-stone-700`,children:`跳过`}),(0,Q.jsx)(`button`,{type:`button`,disabled:!Ls,onClick:()=>Is?bo():go(js+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:Is?`提交回答`:`下一步`})]})]})]})]}):null,(0,Q.jsxs)(`div`,{ref:Yi,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:[(C.length>0||f.length>0||_.length>0)&&(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-1.5 px-3 pt-0.5 pb-2`,children:[C.map(e=>(0,Q.jsxs)(`span`,{className:`flex items-center gap-1.5 pl-2.5 pr-1 py-1 text-xs text-[#4176e6] bg-[#edf3fe] border border-[#4176e6]/25 rounded-lg`,"data-hint":e.collection===`workspace`?e.path:`${e.collection}/${e.path}`,children:[(0,Q.jsx)(wd,{className:`w-3.5 h-3.5`}),(0,Q.jsx)(`span`,{className:`text-[10px] text-[#4176e6]/80 shrink-0`,children:e.collection===`workspace`?`工作区`:e.collection===`prompts`||e.collection===`cases`||e.collection===`knowledge`?e.category:Hl(e.format)}),(0,Q.jsx)(`span`,{className:`max-w-48 truncate`,children:e.title}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>w(t=>t.filter(t=>t.collection!==e.collection||t.path!==e.path)),className:`w-5 h-5 flex items-center justify-center rounded text-[#4176e6]/70 hover:text-[#4176e6] hover:bg-white/80`,children:(0,Q.jsxs)($,{className:`w-3 h-3`,children:[(0,Q.jsx)(`path`,{d:`M18 6 6 18`}),(0,Q.jsx)(`path`,{d:`m6 6 12 12`})]})})]},`${e.collection}:${e.path}`)),f.map((e,t)=>(0,Q.jsxs)(`span`,{className:`flex items-center gap-1.5 pl-2.5 pr-1 py-1 text-xs text-[#4176e6] bg-[#edf3fe] border border-[#4176e6]/25 rounded-lg`,"data-hint":e.path||e.name,children:[(0,Q.jsx)(wd,{className:`w-3.5 h-3.5`}),(0,Q.jsx)(`span`,{className:`text-[10px] text-[#4176e6]/80 shrink-0`,children:`文件`}),(0,Q.jsx)(`span`,{className:`max-w-48 truncate`,children:e.name}),(0,Q.jsx)(`button`,{type:`button`,"data-hint":`移除`,onClick:()=>p(e=>e.filter((e,n)=>n!==t)),className:`w-5 h-5 flex items-center justify-center rounded text-[#4176e6]/70 hover:text-[#4176e6] hover:bg-white/80`,children:(0,Q.jsxs)($,{className:`w-3 h-3`,children:[(0,Q.jsx)(`path`,{d:`M18 6 6 18`}),(0,Q.jsx)(`path`,{d:`m6 6 12 12`})]})})]},`${e.name}-${t}`)),_.map(e=>(0,Q.jsxs)(`span`,{className:`relative group inline-flex rounded-lg border border-stone-200 overflow-hidden bg-stone-50`,"data-hint":`${e.name} · ${Xd(e.size)}`,children:[(0,Q.jsx)(`img`,{src:e.dataUrl,alt:e.name,className:`h-14 w-14 object-cover`}),(0,Q.jsx)(`button`,{type:`button`,"data-hint":`移除图片`,onClick:()=>S(t=>t.filter(t=>t.id!==e.id)),className:`absolute top-0.5 right-0.5 w-5 h-5 flex items-center justify-center rounded bg-black/55 text-white hover:bg-black/75`,children:(0,Q.jsxs)($,{className:`w-3 h-3`,children:[(0,Q.jsx)(`path`,{d:`M18 6 6 18`}),(0,Q.jsx)(`path`,{d:`m6 6 12 12`})]})})]},e.id))]}),(0,Q.jsxs)(`div`,{className:`relative`,children:[Or&&!aa&&!na&&(0,Q.jsx)(`div`,{ref:K,className:`tw-composer-menu tw-popover-anim absolute bottom-full left-0 right-0 mb-3 z-40 h-[min(70vh,20rem)] overflow-hidden rounded-xl border border-stone-200 py-2.5 shadow-[0_4px_14px_-4px_rgba(15,23,42,0.08)]`,children:(0,Q.jsxs)(`div`,{className:`tw-dsh-scroll h-full overflow-y-auto overflow-x-hidden`,children:[(0,Q.jsx)(`div`,{className:`px-3 pt-0.5 pb-1.5 text-[11px] font-medium text-stone-400 tracking-wide`,children:`添加`}),(0,Q.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>{kr(!1),Gi.current?.click()},className:`tw-composer-menu-item w-full flex items-center gap-2.5 px-3 py-2 text-left rounded-lg hover:bg-stone-100`,children:[(0,Q.jsx)(Td,{className:`w-4 h-4 shrink-0 text-stone-500`}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1 text-[13px] text-stone-800`,children:[`文件`,(0,Q.jsx)(`span`,{className:`ml-1.5 text-stone-400 font-normal`,children:`file`})]}),(0,Q.jsx)(`span`,{className:`shrink-0 max-w-[45%] text-right text-[11px] text-stone-400 truncate`,children:`添加本地附件`})]}),(0,Q.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>{kr(!1),Ra()},className:`tw-composer-menu-item w-full flex items-center gap-2.5 px-3 py-2 text-left rounded-lg hover:bg-stone-100`,children:[(0,Q.jsxs)($,{className:`w-4 h-4 shrink-0 text-stone-500`,children:[(0,Q.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`}),(0,Q.jsx)(`circle`,{cx:`12`,cy:`12`,r:`6`}),(0,Q.jsx)(`circle`,{cx:`12`,cy:`12`,r:`2`})]}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1 text-[13px] text-stone-800`,children:[`目标`,(0,Q.jsx)(`span`,{className:`ml-1.5 text-stone-400 font-normal`,children:`goal`})]}),(0,Q.jsx)(`span`,{className:`shrink-0 max-w-[45%] text-right text-[11px] text-stone-400 truncate`,children:`设置或查看长期任务目标`})]}),(0,Q.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>{kr(!1),ii===`off`?za():fo()},className:`tw-composer-menu-item w-full flex items-center gap-2.5 px-3 py-2 text-left rounded-lg hover:bg-stone-100 ${ii===`planning`?`bg-amber-50`:ii===`approved`?`bg-emerald-50`:``}`,children:[(0,Q.jsxs)($,{className:`w-4 h-4 shrink-0 ${ii===`planning`?`text-amber-800`:ii===`approved`?`text-emerald-800`:`text-stone-500`}`,children:[(0,Q.jsx)(`path`,{d:`M8 6h13`}),(0,Q.jsx)(`path`,{d:`M8 12h13`}),(0,Q.jsx)(`path`,{d:`M8 18h13`}),(0,Q.jsx)(`path`,{d:`M3 6h.01`}),(0,Q.jsx)(`path`,{d:`M3 12h.01`}),(0,Q.jsx)(`path`,{d:`M3 18h.01`})]}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1 text-[13px] text-stone-800`,children:[`计划`,(0,Q.jsx)(`span`,{className:`ml-1.5 text-stone-400 font-normal`,children:`plan`})]}),(0,Q.jsx)(`span`,{className:`shrink-0 max-w-[45%] text-right text-[11px] text-stone-400 truncate`,children:`进入或退出计划模式`})]}),B.todos||B.tasks?(0,Q.jsxs)(Q.Fragment,{children:[B.todos?(0,Q.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>Li(`todo`),className:`tw-composer-menu-item w-full flex items-center gap-2.5 px-3 py-2 text-left rounded-lg hover:bg-stone-100`,children:[(0,Q.jsxs)($,{className:`w-4 h-4 shrink-0 text-stone-500`,children:[(0,Q.jsx)(`path`,{d:`M8 6h13`}),(0,Q.jsx)(`path`,{d:`M8 12h13`}),(0,Q.jsx)(`path`,{d:`M8 18h13`}),(0,Q.jsx)(`path`,{d:`M3 6h.01`}),(0,Q.jsx)(`path`,{d:`M3 12h.01`}),(0,Q.jsx)(`path`,{d:`M3 18h.01`})]}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1 text-[13px] text-stone-800`,children:[`待办`,(0,Q.jsx)(`span`,{className:`ml-1.5 text-stone-400 font-normal`,children:`todo`})]}),(0,Q.jsx)(`span`,{className:`shrink-0 max-w-[45%] text-right text-[11px] text-stone-400 truncate`,children:`手动添加一条待办`})]}):null,B.tasks?(0,Q.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>Li(`task`),className:`tw-composer-menu-item w-full flex items-center gap-2.5 px-3 py-2 text-left rounded-lg hover:bg-stone-100`,children:[(0,Q.jsxs)($,{className:`w-4 h-4 shrink-0 text-stone-500`,children:[(0,Q.jsx)(`path`,{d:`M9 5h10`}),(0,Q.jsx)(`path`,{d:`M9 12h10`}),(0,Q.jsx)(`path`,{d:`M9 19h10`}),(0,Q.jsx)(`path`,{d:`M4 5h.01`}),(0,Q.jsx)(`path`,{d:`M4 12h.01`}),(0,Q.jsx)(`path`,{d:`M4 19h.01`})]}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1 text-[13px] text-stone-800`,children:[`任务`,(0,Q.jsx)(`span`,{className:`ml-1.5 text-stone-400 font-normal`,children:`task`})]}),(0,Q.jsx)(`span`,{className:`shrink-0 max-w-[45%] text-right text-[11px] text-stone-400 truncate`,children:`手动添加一个任务`})]}):null]}):null,ia.length?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`my-1 border-t border-stone-100`}),(0,Q.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>Ar(e=>!e),className:`w-full flex items-center gap-2 px-3 py-1.5 text-left hover:bg-stone-50`,children:[(0,Q.jsx)(`span`,{className:`flex-1 text-[11px] font-medium text-stone-400 tracking-wide`,children:`扩展插件`}),(0,Q.jsx)(vd,{className:`w-3.5 h-3.5 text-stone-400 shrink-0 transition-transform ${W?`rotate-180`:``}`})]}),W?ia.map(e=>{let t=e.id===`caseGen`?`case`:e.id===`promptGen`?`prompt`:e.id===`knowledgeGen`?`knowledge`:e.id===`pluginDev`?`dev`:``,n=e.id===`caseGen`?`打开配置后生成用例并写入用例库`:e.id===`promptGen`?`对话生成提示词并写入提示词库`:e.id===`knowledgeGen`?`对话生成规范/方法论并写入知识库`:e.id===`pluginDev`?`输入需求后先评估确认,再开发扩展插件`:``;return(0,Q.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>{kr(!1),Da(e.id)},className:`tw-composer-menu-item w-full flex items-center gap-2.5 px-3 py-2 text-left rounded-lg hover:bg-stone-100`,children:[(0,Q.jsx)(Pd,{className:`w-4 h-4 shrink-0 text-stone-500`}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1 text-[13px] text-stone-800`,children:[e.name,t?(0,Q.jsx)(`span`,{className:`ml-1.5 text-stone-400 font-normal`,children:t}):null]}),n?(0,Q.jsx)(`span`,{className:`shrink-0 max-w-[45%] text-right text-[11px] text-stone-400 truncate`,children:n}):null]},e.id)}):null]}):null,(0,Q.jsx)(`div`,{className:`my-1 border-t border-stone-100`}),(0,Q.jsx)(`div`,{className:`px-3 pt-1 pb-1.5 text-[11px] font-medium text-stone-400 tracking-wide`,children:`指令`}),(0,Q.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>{kr(!1),Jr.current?z(`请等待当前回复结束后再压缩`):Ua({force:!0}).then(e=>{e&&z(`已压缩上下文`)})},className:`tw-composer-menu-item w-full flex items-center gap-2.5 px-3 py-2 text-left rounded-lg hover:bg-stone-100`,children:[(0,Q.jsx)($,{className:`w-4 h-4 shrink-0 text-stone-500`,children:(0,Q.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`})}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1 text-[13px] text-stone-800`,children:[`压缩`,(0,Q.jsx)(`span`,{className:`ml-1.5 text-stone-400 font-normal`,children:`compact`})]}),(0,Q.jsx)(`span`,{className:`shrink-0 max-w-[45%] text-right text-[11px] text-stone-400 truncate`,children:`压缩以上对话内容`})]}),(0,Q.jsxs)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>{kr(!1),No()},className:`tw-composer-menu-item w-full flex items-center gap-2.5 px-3 py-2 text-left rounded-lg hover:bg-stone-100`,children:[(0,Q.jsxs)($,{className:`w-4 h-4 shrink-0 text-stone-500`,children:[(0,Q.jsx)(`path`,{d:`M3 3v18h18`}),(0,Q.jsx)(`path`,{d:`M7 14v4`}),(0,Q.jsx)(`path`,{d:`M12 10v8`}),(0,Q.jsx)(`path`,{d:`M17 6v12`})]}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1 text-[13px] text-stone-800`,children:[`会话统计`,(0,Q.jsx)(`span`,{className:`ml-1.5 text-stone-400 font-normal`,children:`stats`})]}),(0,Q.jsx)(`span`,{className:`shrink-0 max-w-[45%] text-right text-[11px] text-stone-400 truncate`,children:`查看本会话用量摘要`})]})]})}),aa&&(0,Q.jsxs)(`div`,{ref:qi,className:`tw-composer-menu tw-popover-anim absolute bottom-full left-0 right-0 mb-2 mx-2 z-40 max-h-64 overflow-y-auto rounded-xl border border-stone-200 shadow-xl p-1`,children:[(0,Q.jsx)(`div`,{className:`px-3 py-1.5 text-[11px] text-stone-400`,children:`插件`}),ia.map((e,t)=>(0,Q.jsxs)(`button`,{type:`button`,"data-plugin-index":t,onMouseDown:e=>e.preventDefault(),onMouseEnter:()=>be(t),onClick:()=>Da(e.id),className:`tw-composer-menu-item w-full text-left px-3 py-2 rounded-lg transition-colors ${t===_e?`is-active`:``}`,children:[(0,Q.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,Q.jsx)(`div`,{className:`text-[13px] font-medium text-stone-800 flex-1`,children:e.name})}),(0,Q.jsx)(`div`,{className:`mt-0.5 text-xs text-stone-400 line-clamp-2`,children:e.description})]},e.id))]}),na&&(0,Q.jsx)(`div`,{ref:Ki,className:`tw-composer-menu tw-popover-anim absolute bottom-full left-0 right-0 mb-2 mx-2 z-40 max-h-64 overflow-y-auto rounded-xl border border-stone-200 shadow-xl p-1`,children:ta.length===0?(0,Q.jsxs)(`div`,{className:`px-3 py-2 text-xs text-stone-400 space-y-1`,children:[Ir?(0,Q.jsx)(`p`,{children:`项目文档:无匹配`}):null,Zi?(0,Q.jsx)(`p`,{children:`工作区:无匹配`}):(0,Q.jsx)(`p`,{children:`工作区:请先在侧栏添加并选择工作区`}),Ir?null:(0,Q.jsxs)(`p`,{children:[`「知识库检索」未启用:启用后才能用 @ 引用`,Se(`knowledge`),` / `,Se(`templates`),`文档`]})]}):(0,Q.jsxs)(Q.Fragment,{children:[$i.length>0?(0,Q.jsxs)(`div`,{className:`px-3 py-1.5 text-[11px] font-medium text-stone-400`,children:[`项目文档(`,Se(`knowledge`),` / `,Se(`templates`),`)`]}):null,ta.map((e,t)=>{let n=e.doc,r=ta[t-1],i=e.section===`workspace`&&r?.section!==`workspace`;return(0,Q.jsxs)(`div`,{children:[i?(0,Q.jsxs)(Q.Fragment,{children:[$i.length>0?(0,Q.jsx)(`div`,{className:`my-1 mx-2 border-t border-stone-200`,role:`separator`}):null,(0,Q.jsx)(`div`,{className:`px-3 py-1.5 text-[11px] font-medium text-stone-400`,children:`工作区`})]}):null,(0,Q.jsxs)(`button`,{type:`button`,"data-mention-index":t,onMouseDown:e=>e.preventDefault(),onClick:()=>wa(n),className:`tw-composer-menu-item w-full text-left px-3 py-2 rounded-lg transition-colors ${t===yr?`is-active`:``}`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-[13px] text-stone-800`,children:[(0,Q.jsx)(`span`,{className:`text-[11px] px-1.5 py-0.5 rounded bg-stone-100 text-stone-500 shrink-0`,children:n.collection===`knowledge`?Se(`knowledge`):n.collection===`templates`?Se(`templates`):n.format===`dir`?`文件夹`:`文件`}),n.collection===`workspace`?null:(0,Q.jsx)(`span`,{className:`text-[11px] px-1.5 py-0.5 rounded bg-stone-100 text-stone-500 shrink-0`,children:Hl(n.format)}),(0,Q.jsx)(`span`,{className:`truncate font-medium`,children:n.title})]}),(0,Q.jsx)(`div`,{className:`mt-0.5 pl-0 text-xs text-stone-400 truncate`,children:n.collection===`workspace`?n.path:`${n.category}${n.description?` · ${n.description}`:``}`})]})]},`${n.collection}/${n.id}`)}),Ir?null:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`my-1 mx-2 border-t border-stone-200`,role:`separator`}),(0,Q.jsx)(`p`,{className:`px-3 py-1.5 text-[11px] text-stone-400`,children:`「知识库检索」未启用:@ 仅引用工作区文件`})]})]})}),(0,Q.jsxs)(`div`,{className:`flex items-start gap-2 px-3`,children:[oi===`goal`?(0,Q.jsxs)(`span`,{className:`tw-composer-mode-chip is-goal`,"data-hint":`会话目标`,children:[(0,Q.jsxs)($,{className:`w-3.5 h-3.5 shrink-0`,children:[(0,Q.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`}),(0,Q.jsx)(`circle`,{cx:`12`,cy:`12`,r:`6`}),(0,Q.jsx)(`circle`,{cx:`12`,cy:`12`,r:`2`})]}),(0,Q.jsx)(`span`,{children:`目标`}),(0,Q.jsx)(`button`,{type:`button`,"aria-label":`取消目标输入`,onClick:()=>si(null),children:(0,Q.jsxs)($,{className:`w-3 h-3`,children:[(0,Q.jsx)(`path`,{d:`M18 6 6 18`}),(0,Q.jsx)(`path`,{d:`m6 6 12 12`})]})})]}):null,oi===`plan`?(0,Q.jsxs)(`span`,{className:`tw-composer-mode-chip is-plan${ii===`approved`?` is-approved`:``}`,"data-hint":ii===`approved`?`计划模式·已批准`:`计划模式·探查中`,children:[(0,Q.jsxs)($,{className:`w-3.5 h-3.5 shrink-0`,children:[(0,Q.jsx)(`path`,{d:`M8 6h13`}),(0,Q.jsx)(`path`,{d:`M8 12h13`}),(0,Q.jsx)(`path`,{d:`M8 18h13`}),(0,Q.jsx)(`path`,{d:`M3 6h.01`}),(0,Q.jsx)(`path`,{d:`M3 12h.01`}),(0,Q.jsx)(`path`,{d:`M3 18h.01`})]}),(0,Q.jsx)(`span`,{children:`计划`}),(0,Q.jsx)(`button`,{type:`button`,"aria-label":`退出计划模式`,onClick:()=>La(),children:(0,Q.jsxs)($,{className:`w-3 h-3`,children:[(0,Q.jsx)(`path`,{d:`M18 6 6 18`}),(0,Q.jsx)(`path`,{d:`m6 6 12 12`})]})})]}):null,oi===`pluginDev`?(0,Q.jsxs)(`span`,{className:`tw-composer-mode-chip is-plugin-dev`,children:[(0,Q.jsxs)($,{className:`w-3.5 h-3.5 shrink-0`,children:[(0,Q.jsx)(`path`,{d:`M9 7V3`}),(0,Q.jsx)(`path`,{d:`M15 7V3`}),(0,Q.jsx)(`path`,{d:`M6 7h12v4a6 6 0 0 1-12 0V7Z`}),(0,Q.jsx)(`path`,{d:`M12 17v4`})]}),(0,Q.jsx)(`span`,{children:`插件开发`}),(0,Q.jsx)(`button`,{type:`button`,"aria-label":`退出插件开发`,onClick:()=>La(),children:(0,Q.jsxs)($,{className:`w-3 h-3`,children:[(0,Q.jsx)(`path`,{d:`M18 6 6 18`}),(0,Q.jsx)(`path`,{d:`m6 6 12 12`})]})})]}):null,oi===`reports`?(0,Q.jsxs)(`span`,{className:`tw-composer-mode-chip is-report`,children:[(0,Q.jsxs)($,{className:`w-3.5 h-3.5 shrink-0`,children:[(0,Q.jsx)(`path`,{d:`M14 3v4a1 1 0 0 0 1 1h4`}),(0,Q.jsx)(`path`,{d:`M5 3h9l5 5v13H5z`}),(0,Q.jsx)(`path`,{d:`M8 13h8`}),(0,Q.jsx)(`path`,{d:`M8 17h5`})]}),(0,Q.jsxs)(`span`,{children:[`生成`,Rn[ci]]}),(0,Q.jsx)(`button`,{type:`button`,"aria-label":`取消汇报生成`,onClick:()=>La(),children:(0,Q.jsxs)($,{className:`w-3 h-3`,children:[(0,Q.jsx)(`path`,{d:`M18 6 6 18`}),(0,Q.jsx)(`path`,{d:`m6 6 12 12`})]})})]}):null,(0,Q.jsx)(`textarea`,{ref:Wi,value:u,onChange:e=>d(e.target.value),onPaste:Ho,onKeyDown:e=>{if(aa&&ia.length){if(e.key===`ArrowDown`){e.preventDefault(),be(e=>(e+1)%ia.length);return}if(e.key===`ArrowUp`){e.preventDefault(),be(e=>(e-1+ia.length)%ia.length);return}if(e.key===`Escape`){e.preventDefault(),Dr(!0),ra&&d(u.slice(0,ra.from));return}if(e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing){e.preventDefault();let t=ia[_e]??ia[0];t&&Da(t.id);return}}if(na&&ta.length){if(e.key===`ArrowDown`){e.preventDefault(),Sr(e=>(e+1)%ta.length);return}if(e.key===`ArrowUp`){e.preventDefault(),Sr(e=>(e-1+ta.length)%ta.length);return}if(e.key===`Escape`){e.preventDefault(),wr(!0),Qi&&d(u.slice(0,Qi.from));return}if(e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing){e.preventDefault();let t=ta[yr]?.doc;t&&wa(t);return}}if(e.key===`Escape`&&Or)e.preventDefault(),kr(!1);else if(e.key===`Escape`&&(Qi||ra)){e.preventDefault(),wr(!0),Dr(!0);let t=Qi?.from??ra?.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(Jr.current){if(t){let e=u.trim();if(e||f.length>0||_.length>0||C.length>0){let t={id:`q_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,6)}`,content:e,files:[...f],refs:[...C],imgs:[..._]};Ia(),Xa(t)}else zi.current.length&&Xa();return}Wa(void 0,{forceBusy:Pe().busySendBehavior??`queue`})}else Wa()}},rows:1,placeholder:t?jr.length>0&&St?`Cmd/Ctrl+Enter 插话发送全部排队消息`:Ir?`请输入内容,或用 @ 引用文档`:Zi?`请输入内容,或用 @ 引用工作区文件`:`请输入内容(@ 引用文档需先启用「知识库检索」)`:`请先配置模型(左下角「设置」→ 模型)`,className:`tw-chat-input block min-w-0 flex-1 min-h-13 pl-0 pr-2 pt-1.5 pb-0.5 bg-transparent resize-none focus:outline-none placeholder:text-(--tw-label-tertiary)`})]})]}),(0,Q.jsxs)(`div`,{className:`tw-composer-bar flex items-center gap-1.5 px-3 pb-3 pt-3`,children:[(0,Q.jsx)(`button`,{type:`button`,"data-add-menu-btn":!0,"aria-label":ii===`off`?`添加`:ii===`planning`?`添加(计划模式·探查中)`:`添加(计划模式·已批准)`,onClick:()=>{kr(e=>!e),wr(!0),Dr(!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 ${Or?`bg-(--tw-session-hover-bg)`:``}`,children:(0,Q.jsxs)($,{className:`w-4 h-4`,children:[(0,Q.jsx)(`path`,{d:`M5 12h14`}),(0,Q.jsx)(`path`,{d:`M12 5v14`})]})}),G&&(0,Q.jsxs)(O,{children:[(0,Q.jsxs)(re,{title:fs?`工作区:${fs}`:`选择工作区`,"aria-label":gs?`工作区:${gs}`:`选择工作区`,disabled:Fn,className:`tw-composer-bar-ws group flex items-center gap-1 h-7 shrink-0 max-w-[min(40vw,11rem)] pl-1.5 pr-1 text-[13px] leading-5 font-medium text-stone-600 rounded-md outline-none focus:outline-none focus-visible:outline-none hover:bg-stone-100 data-[open]:bg-stone-100 transition-colors disabled:opacity-50`,children:[(0,Q.jsx)(Dd,{className:`w-3.5 h-3.5 shrink-0 text-stone-500`}),(0,Q.jsx)(`span`,{className:`tw-composer-bar-label truncate`,children:gs}),(0,Q.jsx)(vd,{className:`tw-composer-bar-chevron w-3.5 h-3.5 shrink-0 text-stone-400 transition-transform group-data-[open]:rotate-180`})]}),(0,Q.jsxs)(te,{transition:!0,anchor:{to:`top start`,gap:8},className:`tw-select-menu tw-menu-anim z-50 w-[min(100vw-2rem,16rem)] rounded-xl border border-stone-200 py-1 shadow-xl focus:outline-none`,children:[(V?.items??[]).map(e=>{let t=e.path===fs;return(0,Q.jsx)(ne,{children:(0,Q.jsxs)(`button`,{type:`button`,disabled:Fn,onClick:()=>void va(e),className:`w-full flex items-center gap-2.5 px-3 py-2 text-left data-[focus]:bg-stone-100 disabled:opacity-50`,children:[(0,Q.jsx)(Dd,{className:`w-4 h-4 shrink-0 text-stone-500`}),(0,Q.jsx)(`span`,{className:`flex-1 min-w-0 truncate text-[13px] ${t?`text-stone-900 font-medium`:`text-stone-700`}`,"data-hint":e.path,children:Lt(e,os)}),t&&(0,Q.jsx)(bd,{className:`w-3.5 h-3.5 shrink-0 text-[#4176e6]`})]})},e.id)}),(V?.items?.length??0)>0&&(0,Q.jsx)(`div`,{className:`my-1 border-t border-stone-100`}),(0,Q.jsx)(ne,{children:(0,Q.jsxs)(`button`,{type:`button`,disabled:Fn,onClick:()=>void ya(),className:`w-full flex items-center gap-2.5 px-3 py-2 text-left text-[13px] text-stone-700 data-[focus]:bg-stone-100 disabled:opacity-50`,children:[(0,Q.jsx)(`span`,{className:`w-4 h-4 shrink-0 flex items-center justify-center text-stone-500 text-base leading-none`,children:`+`}),`添加工作区...`]})})]})]}),(0,Q.jsxs)(O,{children:[(0,Q.jsxs)(re,{title:`访问权限:${Qo.label}`,"aria-label":`访问权限:${Qo.label}`,className:`tw-composer-bar-access group flex items-center gap-1 h-7 shrink-0 max-w-55 pl-2 pr-1 text-[13px] leading-5 font-medium text-stone-600 rounded-md outline-none focus:outline-none focus-visible:outline-none hover:bg-stone-100 data-[open]:bg-stone-100 transition-colors`,children:[(0,Q.jsx)(Vd,{level:ln,className:`w-3.5 h-3.5 shrink-0 text-stone-500`}),(0,Q.jsx)(`span`,{className:`tw-composer-bar-label truncate`,children:Qo.label}),(0,Q.jsx)(`span`,{className:`ml-0.5 w-1.5 h-1.5 rounded-full shrink-0 ${G?`bg-emerald-500`:`bg-stone-300`}`,"data-hint":G?`Runner 在线`:`Runner 离线`}),(0,Q.jsx)(vd,{className:`tw-composer-bar-chevron w-3.5 h-3.5 shrink-0 text-stone-400 transition-transform group-data-[open]:rotate-180`})]}),(0,Q.jsxs)(te,{transition:!0,anchor:{to:`top start`,gap:8},className:`tw-select-menu tw-menu-anim z-50 w-56 rounded-xl border border-stone-200 p-1 shadow-xl focus:outline-none`,children:[(0,Q.jsx)(`div`,{className:`px-3 py-1.5 text-[11px] text-stone-400`,children:G?`本地文件服务已连接`:`本地文件服务未就绪`}),ud.map(e=>{let t=$o&&e.value===`readonly`;return(0,Q.jsx)(ne,{disabled:t,children:(0,Q.jsxs)(`button`,{type:`button`,disabled:t,onClick:()=>{un(e.value),q.current&&J(Re(q.current,{access:e.value}))},className:`w-full flex items-center gap-2 px-3 py-2 rounded-lg text-left text-[13px] data-[focus]:bg-stone-100 disabled:cursor-not-allowed`,children:[(0,Q.jsx)(Vd,{level:e.value,className:`w-4 h-4 shrink-0 ${t?`text-stone-300`:`text-stone-500`}`}),(0,Q.jsx)(`span`,{className:`flex-1 ${t?`text-stone-400`:ln===e.value?`text-stone-900 font-medium`:`text-stone-700`}`,children:e.label}),t?(0,Q.jsx)(`span`,{className:`text-[11px] text-stone-400`,children:`插件开发需要写入`}):ln===e.value?(0,Q.jsx)(bd,{className:`w-3.5 h-3.5 text-[#4176e6]`}):null]})},e.value)})]})]}),(0,Q.jsx)(`span`,{className:`flex-1`}),(0,Q.jsx)(lf,{settings:t}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{Jr.current?Ka():Wa()},disabled:!St&&!qo,"aria-label":St?`停止生成`:`发送`,className:`w-8 h-8 shrink-0 rounded-full flex items-center justify-center outline-none focus:outline-none focus-visible:outline-none transition-colors ${St?`bg-stone-200 text-stone-700 hover:bg-stone-300`:`bg-[#4176e6] text-white hover:bg-[#3565c7] disabled:bg-[#a9c3ef] disabled:cursor-not-allowed`}`,children:St?(0,Q.jsx)(`span`,{className:`w-2.5 h-2.5 bg-current rounded-xs`}):(0,Q.jsx)(Ed,{className:`w-4 h-4`})})]})]}),(0,Q.jsx)(sf,{messages:s,model:t?.model,systemPromptTokens:Kd(ee)})]}),(0,Q.jsx)(`input`,{ref:Gi,type:`file`,multiple:!0,hidden:!0,accept:[...eu.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 Lo(e)})]})]})]}),Ce?(0,Q.jsx)(`div`,{className:`tw-plugins-rail flex-1 min-w-0 min-h-0 self-stretch h-full overflow-hidden flex flex-col`,children:(0,Q.jsx)(on,{embedded:!0})}):null,(0,Q.jsx)(Cu,{open:E,initial:k,onClose:()=>D(!1),onConfirm:e=>ro(e)}),(0,Q.jsx)(wu,{open:M,initial:N,onClose:()=>ie(!1),onConfirm:e=>io(e)}),(0,Q.jsx)(Tu,{open:se,initial:ce,onClose:()=>P(!1),onConfirm:e=>ao(e)}),(0,Q.jsx)(zn,{open:!!Te,title:`重命名会话`,label:`会话名称`,placeholder:`请输入会话名称`,initialValue:Te?a?.sessions.find(e=>e.id===Te)?.title??``:``,confirmLabel:`保存`,cancelLabel:`取消`,onClose:()=>Ae(null),onConfirm:Fo}),(0,Q.jsx)(zn,{open:!!mt,title:`重命名工作区`,label:`显示名称`,placeholder:`请输入工作区名称`,initialValue:mt?V?.items.find(e=>e.id===mt)?.name??``:``,confirmLabel:`保存`,cancelLabel:`取消`,onClose:()=>ht(null),onConfirm:e=>void Sa(e)}),(0,Q.jsx)(x,{open:!!Fe,title:`删除会话`,message:Fe?`确定永久删除「${a?.sessions.find(e=>e.id===Fe)?.title??`该会话`}」?此操作不可恢复。`:``,confirmLabel:`删除`,cancelLabel:`取消`,danger:`outline`,onClose:()=>Ie(null),onConfirm:()=>{if(!Fe)return;let e=Fe;Ie(null),Do(e)}}),(0,Q.jsx)(x,{open:!!ft,title:`删除工作区`,message:ft?`将把「${ft.name}」从工作区列表中移除。文件夹与会话记录会保留,其会话将归入项目根工作区。`:``,confirmLabel:`删除工作区`,cancelLabel:`取消`,danger:`outline`,onClose:()=>pt(null),onConfirm:()=>void ba()})]})}export{ff as default};
|