@shawnstack/quickforge 1.5.0 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/README.md +10 -10
  2. package/dist/assets/{AgentProfilesPage-DUmXUxjA.js → AgentProfilesPage-BIwd5Nzg.js} +1 -1
  3. package/dist/assets/{ChatPanelHost-Syx0SSLe.js → ChatPanelHost-De-DMjx5.js} +16 -16
  4. package/dist/assets/{PluginsPage-kiBq0gOT.js → PluginsPage-kRzB5k8J.js} +1 -1
  5. package/dist/assets/{ScheduledTasksPage-Dw4-tgp9.js → ScheduledTasksPage-ZnjohaPS.js} +2 -2
  6. package/dist/assets/SharedConversationPage-EQdZgWCM.js +1 -0
  7. package/dist/assets/TerminalDock-P2pJH_tx.js +2 -0
  8. package/dist/assets/WorkspaceInspector-CkLAqYQ6.js +3 -0
  9. package/dist/assets/{WorkspaceReaderDialog-BJo_KEWi.js → WorkspaceReaderDialog-BwzZ8Tgv.js} +1 -1
  10. package/dist/assets/diff-line-counts-CeZC7b0z.js +10 -0
  11. package/dist/assets/icons-DJqt-rnw.js +1 -0
  12. package/dist/assets/index-CcGy4TXo.js +1354 -0
  13. package/dist/assets/index-DuTUuAMk.css +3 -0
  14. package/dist/assets/{monaco-CGq6uVF1.js → monaco-CNEfYIy1.js} +1 -1
  15. package/dist/assets/{react-vendor-DunfCFfp.js → react-vendor-CZCcjpSR.js} +1 -1
  16. package/dist/index.html +4 -4
  17. package/package.json +1 -1
  18. package/server/agent-manager.mjs +2 -2
  19. package/server/routes/workspace.mjs +8 -24
  20. package/server/tools/index.mjs +5 -2
  21. package/server/utils/workspace.mjs +1 -1
  22. package/dist/assets/SharedConversationPage-CaE9bNb9.js +0 -1
  23. package/dist/assets/TerminalDock-BYJcp8Ts.js +0 -2
  24. package/dist/assets/WorkspaceInspector-Bzmv8Cvi.js +0 -3
  25. package/dist/assets/diff-line-counts-BZoYp5ai.js +0 -10
  26. package/dist/assets/icons-47L5YLKz.js +0 -1
  27. package/dist/assets/index-CqfScETb.js +0 -1200
  28. package/dist/assets/index-DzkBgHZf.css +0 -3
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # 速构 QuickForge
2
2
 
3
3
  <p align="center">
4
- <img alt="Version" src="https://img.shields.io/badge/version-1.5.0-blue" />
4
+ <img alt="Version" src="https://img.shields.io/badge/version-1.5.1-blue" />
5
5
  <img alt="License" src="https://img.shields.io/badge/license-MIT-green" />
6
6
  <img alt="Node" src="https://img.shields.io/badge/node-%3E%3D20-brightgreen" />
7
7
  <img alt="React" src="https://img.shields.io/badge/react-19-61DAFB?logo=react" />
@@ -70,7 +70,7 @@ QuickForge 的工具能力很直接,因此也需要谨慎使用:
70
70
  #### 从 npm 安装
71
71
 
72
72
  ```bash
73
- npm install -g @shawnstack/quickforge@1.5.0
73
+ npm install -g @shawnstack/quickforge@1.5.1
74
74
  qf
75
75
 
76
76
  # CLI 工具
@@ -84,17 +84,17 @@ qf update
84
84
  当前版本的离线包:
85
85
 
86
86
  ```text
87
- package-offline/shawnstack-quickforge-1.5.0.tgz
87
+ package-offline/shawnstack-quickforge-1.5.1.tgz
88
88
  ```
89
89
 
90
90
  在安装了 Node.js 20+ 和 npm 的机器上执行:
91
91
 
92
92
  ```bash
93
- npm install -g ./package-offline/shawnstack-quickforge-1.5.0.tgz
93
+ npm install -g ./package-offline/shawnstack-quickforge-1.5.1.tgz
94
94
  qf
95
95
  ```
96
96
 
97
- 该包由 `v1.5.0` 标签生成,包含 QuickForge 运行时资源,依赖由 npm 安装。
97
+ 该包由 `v1.5.1` 标签生成,包含 QuickForge 运行时资源,依赖由 npm 安装。
98
98
 
99
99
  ### 本地开发
100
100
 
@@ -234,7 +234,7 @@ QuickForge intentionally exposes powerful local capabilities, so the boundaries
234
234
  #### npm
235
235
 
236
236
  ```bash
237
- npm install -g @shawnstack/quickforge@1.5.0
237
+ npm install -g @shawnstack/quickforge@1.5.1
238
238
  qf
239
239
 
240
240
  # CLI utilities
@@ -245,20 +245,20 @@ qf update
245
245
 
246
246
  #### Offline tarball
247
247
 
248
- The offline release package for `v1.5.0` is:
248
+ The offline release package for `v1.5.1` is:
249
249
 
250
250
  ```text
251
- package-offline/shawnstack-quickforge-1.5.0.tgz
251
+ package-offline/shawnstack-quickforge-1.5.1.tgz
252
252
  ```
253
253
 
254
254
  Install it on a machine with Node.js 20+ and npm:
255
255
 
256
256
  ```bash
257
- npm install -g ./package-offline/shawnstack-quickforge-1.5.0.tgz
257
+ npm install -g ./package-offline/shawnstack-quickforge-1.5.1.tgz
258
258
  qf
259
259
  ```
260
260
 
261
- The package was generated from tag `v1.5.0` and includes QuickForge runtime assets and installs dependencies with npm.
261
+ The package was generated from tag `v1.5.1` and includes QuickForge runtime assets and installs dependencies with npm.
262
262
 
263
263
  ### Local development
264
264
 
@@ -1 +1 @@
1
- import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{St as t,bt as n,c as r}from"./icons-47L5YLKz.js";import{n as i}from"./react-vendor-DunfCFfp.js";import{A as a,C as o,E as s,N as c,S as l,T as u,j as d,k as f,w as p}from"./index-CqfScETb.js";var m=e(t(),1),h=i();function g(){return{name:``,label:``,description:``,systemPrompt:``,allowedTools:[`read_file`,`grep_files`],maxRuntimeMs:`1800000`,maxToolCalls:`300`,enabledAsSubagent:!0}}function _(e){return{name:e.name,label:e.label,description:e.description??``,systemPrompt:e.systemPrompt??``,allowedTools:e.allowedTools??[],maxRuntimeMs:String(e.maxRuntimeMs??18e5),maxToolCalls:String(e.maxToolCalls??300),enabledAsSubagent:e.enabledAsSubagent}}function v(e){return{name:e.name.trim().toLowerCase(),label:e.label.trim(),description:e.description.trim(),systemPrompt:e.systemPrompt.trim(),allowedTools:e.allowedTools,maxRuntimeMs:Number(e.maxRuntimeMs||18e5),maxToolCalls:Number(e.maxToolCalls||300),enabledAsSubagent:e.enabledAsSubagent}}function y(e){return!!(e.name.trim()&&e.label.trim()&&e.allowedTools.length>0)}async function b(e,t){let n=await fetch(e,{...t,headers:{"content-type":`application/json`,...t?.headers}}),r=await n.json().catch(()=>null);if(!n.ok)throw Error(r?.error||`请求失败`);return r}function x(){let[e,t]=(0,m.useState)([]),[i,x]=(0,m.useState)([]),[S,C]=(0,m.useState)(!1),[w,T]=(0,m.useState)(null),[E,D]=(0,m.useState)(()=>g()),[O,k]=(0,m.useState)(!1),[A,j]=(0,m.useState)(``),[M,N]=(0,m.useState)(!1),[P,F]=(0,m.useState)(),[I,L]=(0,m.useState)(`off`),[R,z]=(0,m.useState)(``);async function B(){let[e,n]=await Promise.all([b(`/api/agent-profiles`),b(`/api/agent-profiles/available-tools`)]);t(e.agents),x(n.tools)}(0,m.useEffect)(()=>{let e=!1;async function n(){try{let[n,r]=await Promise.all([b(`/api/agent-profiles`),b(`/api/agent-profiles/available-tools`)]);if(e)return;t(n.agents),x(r.tools)}catch(t){e||z(t instanceof Error?t.message:c(`requestFailed`))}}return n(),()=>{e=!0}},[]),(0,m.useEffect)(()=>{let e=!1;async function t(){try{let t=await p(),n=await o(t),r=await u(t),i=r.model??await s(t)??n[0];if(e)return;F(i),L(r.thinkingLevel??l(i))}catch{}}return t(),()=>{e=!0}},[]);let V=(0,m.useMemo)(()=>e.find(e=>e.id===w)??null,[e,w]);function H(e,t){D(n=>({...n,[e]:t}))}function U(e){D(t=>({...t,allowedTools:t.allowedTools.includes(e)?t.allowedTools.filter(t=>t!==e):[...t.allowedTools,e]}))}function W(){T(null),D(g()),j(``),z(``),C(!0)}function G(e){T(e.id),D(_(e)),j(``),z(``),C(!0)}function K(){O||M||(C(!1),T(null),D(g()),j(``))}async function q(){let e=A.trim();if(!e){z(c(`aiFillAgentInputRequired`));return}if(!P){z(c(`aiFillAgentNoModel`));return}N(!0),z(``);try{let t=await b(`/api/agent-profiles/ai-fill`,{method:`POST`,body:JSON.stringify({instruction:e,model:P,thinkingLevel:I})});D(e=>({...e,name:t.agent.name,label:t.agent.label,description:t.agent.description,systemPrompt:t.agent.systemPrompt}))}catch(e){z(e instanceof Error?e.message:c(`aiFillAgentFailed`))}finally{N(!1)}}async function J(){if(y(E)){k(!0),z(``);try{let e=v(E);w?await b(`/api/agent-profiles/${encodeURIComponent(w)}`,{method:`PATCH`,body:JSON.stringify(e)}):await b(`/api/agent-profiles`,{method:`POST`,body:JSON.stringify(e)}),K(),await B()}catch(e){z(e instanceof Error?e.message:c(`requestFailed`))}finally{k(!1)}}}async function Y(e){if(!(e.builtin||e.readonly)&&await f({description:c(`confirmDeleteAgent`),confirmLabel:c(`confirmDelete`),cancelLabel:c(`cancel`),variant:`destructive`})){z(``);try{await b(`/api/agent-profiles/${encodeURIComponent(e.id)}`,{method:`DELETE`}),await B()}catch(e){z(e instanceof Error?e.message:c(`requestFailed`))}}}return(0,h.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden bg-background`,children:[(0,h.jsx)(`div`,{className:`border-b border-border px-6 py-5`,children:(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,h.jsx)(`div`,{className:`flex size-10 items-center justify-center rounded-2xl bg-primary/10 text-primary`,children:(0,h.jsx)(n,{className:`size-5`})}),(0,h.jsx)(`div`,{children:(0,h.jsxs)(`h1`,{className:`inline-flex items-center gap-1.5 text-lg font-semibold text-foreground`,children:[c(`agentsTab`),(0,h.jsx)(a,{label:c(`agentsDescription`)})]})})]}),(0,h.jsx)(d,{onClick:W,children:c(`createAgent`)})]})}),(0,h.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-6`,children:(0,h.jsxs)(`div`,{className:`mx-auto max-w-5xl space-y-5`,children:[R&&!S?(0,h.jsx)(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive`,children:R}):null,(0,h.jsx)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:e.map(e=>(0,h.jsxs)(`div`,{className:`rounded-xl border border-border bg-card p-4`,children:[(0,h.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,h.jsxs)(`div`,{className:`min-w-0`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(`h3`,{className:`truncate text-sm font-medium text-foreground/90`,children:e.label}),e.builtin?(0,h.jsx)(`span`,{className:`rounded-full bg-primary/10 px-2 py-0.5 text-xs text-primary`,children:c(`builtinAgent`)}):null,e.enabledAsSubagent?(0,h.jsx)(`span`,{className:`rounded-full bg-emerald-500/10 px-2 py-0.5 text-xs text-emerald-700`,children:c(`enabledAsSubagent`)}):null]}),(0,h.jsx)(`p`,{className:`mt-1 font-mono text-xs text-muted-foreground`,children:e.name}),e.source&&!e.builtin?(0,h.jsxs)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:[e.source,e.relativePath?` · ${e.relativePath}`:``]}):null,(0,h.jsx)(`p`,{className:`mt-2 text-sm text-muted-foreground`,children:e.description||c(`noDescription`)})]}),(0,h.jsxs)(`div`,{className:`flex shrink-0 gap-1`,children:[(0,h.jsx)(d,{variant:`outline`,size:`sm`,disabled:e.builtin||e.readonly,onClick:()=>G(e),children:c(`editTask`)}),(0,h.jsx)(d,{variant:`destructive`,size:`sm`,disabled:e.builtin||e.readonly,onClick:()=>void Y(e),children:c(`delete`)})]})]}),(0,h.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-1`,children:e.allowedTools.map(e=>(0,h.jsx)(`span`,{className:`rounded-full bg-muted px-2 py-0.5 font-mono text-xs text-muted-foreground`,children:e},e))}),(0,h.jsxs)(`div`,{className:`mt-3 grid gap-2 border-t border-border pt-3 text-xs text-muted-foreground sm:grid-cols-2`,children:[(0,h.jsxs)(`span`,{children:[c(`maxRuntimeMs`),e.maxRuntimeMs??`-`]}),(0,h.jsxs)(`span`,{children:[c(`maxToolCalls`),e.maxToolCalls??`-`]})]})]},e.id))})]})}),S?(0,h.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4`,onMouseDown:e=>{e.target===e.currentTarget&&K()},children:(0,h.jsxs)(`div`,{className:`flex max-h-[90vh] w-full max-w-3xl flex-col overflow-hidden rounded-2xl border border-border bg-background shadow-quickforge`,onMouseDown:e=>e.stopPropagation(),children:[(0,h.jsxs)(`div`,{className:`shrink-0 border-b border-border px-5 py-4`,children:[(0,h.jsx)(`h2`,{className:`text-base font-medium text-foreground`,children:c(V?`editAgent`:`createAgent`)}),V?.readonly?(0,h.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:c(`builtinAgentReadonly`)}):null]}),(0,h.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-5 py-4`,children:(0,h.jsxs)(`div`,{className:`space-y-4`,children:[(0,h.jsxs)(`div`,{className:`rounded-2xl border border-border bg-muted/20 p-3`,children:[(0,h.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 text-sm font-medium text-foreground`,children:[(0,h.jsx)(r,{className:`size-4 text-primary`}),c(`aiFillAgent`),(0,h.jsx)(a,{label:c(`aiFillAgentDescription`)})]}),(0,h.jsx)(`textarea`,{className:`min-h-20 w-full resize-y rounded-xl border border-input bg-background px-3 py-2 text-sm outline-none transition-colors placeholder:text-muted-foreground/65 focus:border-ring disabled:opacity-60`,value:A,disabled:!!V?.readonly||M,onChange:e=>j(e.target.value),placeholder:c(`aiFillAgentPlaceholder`)}),(0,h.jsx)(`div`,{className:`mt-2 flex justify-end`,children:(0,h.jsxs)(d,{variant:`outline`,size:`sm`,onClick:()=>void q(),disabled:!!V?.readonly||M||!A.trim(),children:[(0,h.jsx)(r,{className:`mr-1 size-3.5`}),c(M?`aiFillAgentLoading`:`aiFillAgent`)]})})]}),(0,h.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,h.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[c(`agentName`),(0,h.jsx)(`input`,{className:`mt-1 h-10 w-full rounded-md border border-input bg-background px-3 text-sm outline-none focus:border-ring disabled:opacity-60`,value:E.name,disabled:!!V?.readonly,onChange:e=>H(`name`,e.target.value),placeholder:`reviewer`})]}),(0,h.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[c(`agentLabel`),(0,h.jsx)(`input`,{className:`mt-1 h-10 w-full rounded-md border border-input bg-background px-3 text-sm outline-none focus:border-ring disabled:opacity-60`,value:E.label,disabled:!!V?.readonly,onChange:e=>H(`label`,e.target.value),placeholder:c(`agentLabelPlaceholder`)})]})]}),(0,h.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[c(`agentDescription`),(0,h.jsx)(`input`,{className:`mt-1 h-10 w-full rounded-md border border-input bg-background px-3 text-sm outline-none focus:border-ring disabled:opacity-60`,value:E.description,disabled:!!V?.readonly,onChange:e=>H(`description`,e.target.value)})]}),(0,h.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[c(`agentSystemPrompt`),(0,h.jsx)(`textarea`,{className:`mt-1 min-h-36 w-full resize-y rounded-xl border border-input bg-background px-3 py-2 text-sm outline-none focus:border-ring disabled:opacity-60`,value:E.systemPrompt,disabled:!!V?.readonly,onChange:e=>H(`systemPrompt`,e.target.value)})]}),(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`div`,{className:`mb-2 text-sm font-medium text-foreground`,children:c(`allowedTools`)}),(0,h.jsx)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:i.map(e=>(0,h.jsxs)(`label`,{className:`flex items-start gap-2 rounded-xl border border-border bg-muted/20 p-3 text-sm disabled:opacity-60`,children:[(0,h.jsx)(`input`,{type:`checkbox`,className:`mt-1`,disabled:!!V?.readonly,checked:E.allowedTools.includes(e.name),onChange:()=>U(e.name)}),(0,h.jsxs)(`span`,{children:[(0,h.jsx)(`span`,{className:`font-medium text-foreground`,children:e.label}),(0,h.jsx)(`span`,{className:`ml-2 font-mono text-xs text-muted-foreground`,children:e.name}),e.riskLevel===`dangerous`?(0,h.jsx)(`span`,{className:`ml-2 rounded-full bg-amber-500/10 px-2 py-0.5 text-xs text-amber-700`,children:c(`highRiskTool`)}):null,(0,h.jsx)(`span`,{className:`mt-1 block text-xs text-muted-foreground`,children:e.description})]})]},e.name))})]}),(0,h.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,h.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[c(`maxRuntimeMs`),(0,h.jsx)(`input`,{type:`number`,className:`mt-1 h-10 w-full rounded-md border border-input bg-background px-3 text-sm outline-none focus:border-ring disabled:opacity-60`,value:E.maxRuntimeMs,disabled:!!V?.readonly,onChange:e=>H(`maxRuntimeMs`,e.target.value)})]}),(0,h.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[c(`maxToolCalls`),(0,h.jsx)(`input`,{type:`number`,className:`mt-1 h-10 w-full rounded-md border border-input bg-background px-3 text-sm outline-none focus:border-ring disabled:opacity-60`,value:E.maxToolCalls,disabled:!!V?.readonly,onChange:e=>H(`maxToolCalls`,e.target.value)})]})]}),(0,h.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-foreground`,children:[(0,h.jsx)(`input`,{type:`checkbox`,checked:E.enabledAsSubagent,disabled:!!V?.readonly,onChange:e=>H(`enabledAsSubagent`,e.target.checked)}),c(`enabledAsSubagent`)]}),R?(0,h.jsx)(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive`,children:R}):null]})}),(0,h.jsx)(`div`,{className:`shrink-0 border-t border-border px-5 py-4`,children:(0,h.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,h.jsx)(d,{variant:`outline`,onClick:K,disabled:O||M,children:c(`cancel`)}),(0,h.jsx)(d,{onClick:J,disabled:O||M||!!V?.readonly||!y(E),children:c(`save`)})]})})]})}):null]})}export{x as AgentProfilesPage};
1
+ import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{Ct as t,c as n,xt as r}from"./icons-DJqt-rnw.js";import{n as i}from"./react-vendor-CZCcjpSR.js";import{D as a,E as o,I as s,M as c,N as l,O as u,P as d,T as f,k as p}from"./index-CcGy4TXo.js";var m=e(t(),1),h=i();function g(){return{name:``,label:``,description:``,systemPrompt:``,allowedTools:[`read_file`,`grep_files`],maxRuntimeMs:`1800000`,maxToolCalls:`300`,enabledAsSubagent:!0}}function _(e){return{name:e.name,label:e.label,description:e.description??``,systemPrompt:e.systemPrompt??``,allowedTools:e.allowedTools??[],maxRuntimeMs:String(e.maxRuntimeMs??18e5),maxToolCalls:String(e.maxToolCalls??300),enabledAsSubagent:e.enabledAsSubagent}}function v(e){return{name:e.name.trim().toLowerCase(),label:e.label.trim(),description:e.description.trim(),systemPrompt:e.systemPrompt.trim(),allowedTools:e.allowedTools,maxRuntimeMs:Number(e.maxRuntimeMs||18e5),maxToolCalls:Number(e.maxToolCalls||300),enabledAsSubagent:e.enabledAsSubagent}}function y(e){return!!(e.name.trim()&&e.label.trim()&&e.allowedTools.length>0)}async function b(e,t){let n=await fetch(e,{...t,headers:{"content-type":`application/json`,...t?.headers}}),r=await n.json().catch(()=>null);if(!n.ok)throw Error(r?.error||`请求失败`);return r}function x(){let[e,t]=(0,m.useState)([]),[i,x]=(0,m.useState)([]),[S,C]=(0,m.useState)(!1),[w,T]=(0,m.useState)(null),[E,D]=(0,m.useState)(()=>g()),[O,k]=(0,m.useState)(!1),[A,j]=(0,m.useState)(``),[M,N]=(0,m.useState)(!1),[P,F]=(0,m.useState)(),[I,L]=(0,m.useState)(`off`),[R,z]=(0,m.useState)(``);async function B(){let[e,n]=await Promise.all([b(`/api/agent-profiles`),b(`/api/agent-profiles/available-tools`)]);t(e.agents),x(n.tools)}(0,m.useEffect)(()=>{let e=!1;async function n(){try{let[n,r]=await Promise.all([b(`/api/agent-profiles`),b(`/api/agent-profiles/available-tools`)]);if(e)return;t(n.agents),x(r.tools)}catch(t){e||z(t instanceof Error?t.message:s(`requestFailed`))}}return n(),()=>{e=!0}},[]),(0,m.useEffect)(()=>{let e=!1;async function t(){try{let t=await a(),n=await o(t),r=await u(t),i=r.model??await p(t)??n[0];if(e)return;F(i),L(r.thinkingLevel??f(i))}catch{}}return t(),()=>{e=!0}},[]);let V=(0,m.useMemo)(()=>e.find(e=>e.id===w)??null,[e,w]);function H(e,t){D(n=>({...n,[e]:t}))}function U(e){D(t=>({...t,allowedTools:t.allowedTools.includes(e)?t.allowedTools.filter(t=>t!==e):[...t.allowedTools,e]}))}function W(){T(null),D(g()),j(``),z(``),C(!0)}function G(e){T(e.id),D(_(e)),j(``),z(``),C(!0)}function K(){O||M||(C(!1),T(null),D(g()),j(``))}async function q(){let e=A.trim();if(!e){z(s(`aiFillAgentInputRequired`));return}if(!P){z(s(`aiFillAgentNoModel`));return}N(!0),z(``);try{let t=await b(`/api/agent-profiles/ai-fill`,{method:`POST`,body:JSON.stringify({instruction:e,model:P,thinkingLevel:I})});D(e=>({...e,name:t.agent.name,label:t.agent.label,description:t.agent.description,systemPrompt:t.agent.systemPrompt}))}catch(e){z(e instanceof Error?e.message:s(`aiFillAgentFailed`))}finally{N(!1)}}async function J(){if(y(E)){k(!0),z(``);try{let e=v(E);w?await b(`/api/agent-profiles/${encodeURIComponent(w)}`,{method:`PATCH`,body:JSON.stringify(e)}):await b(`/api/agent-profiles`,{method:`POST`,body:JSON.stringify(e)}),K(),await B()}catch(e){z(e instanceof Error?e.message:s(`requestFailed`))}finally{k(!1)}}}async function Y(e){if(!(e.builtin||e.readonly)&&await c({description:s(`confirmDeleteAgent`),confirmLabel:s(`confirmDelete`),cancelLabel:s(`cancel`),variant:`destructive`})){z(``);try{await b(`/api/agent-profiles/${encodeURIComponent(e.id)}`,{method:`DELETE`}),await B()}catch(e){z(e instanceof Error?e.message:s(`requestFailed`))}}}return(0,h.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden bg-background`,children:[(0,h.jsx)(`div`,{className:`border-b border-border px-6 py-5`,children:(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,h.jsx)(`div`,{className:`flex size-10 items-center justify-center rounded-2xl bg-primary/10 text-primary`,children:(0,h.jsx)(r,{className:`size-5`})}),(0,h.jsx)(`div`,{children:(0,h.jsxs)(`h1`,{className:`inline-flex items-center gap-1.5 text-lg font-semibold text-foreground`,children:[s(`agentsTab`),(0,h.jsx)(l,{label:s(`agentsDescription`)})]})})]}),(0,h.jsx)(d,{onClick:W,children:s(`createAgent`)})]})}),(0,h.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-6`,children:(0,h.jsxs)(`div`,{className:`mx-auto max-w-5xl space-y-5`,children:[R&&!S?(0,h.jsx)(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive`,children:R}):null,(0,h.jsx)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:e.map(e=>(0,h.jsxs)(`div`,{className:`rounded-xl border border-border bg-card p-4`,children:[(0,h.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,h.jsxs)(`div`,{className:`min-w-0`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(`h3`,{className:`truncate text-sm font-medium text-foreground/90`,children:e.label}),e.builtin?(0,h.jsx)(`span`,{className:`rounded-full bg-primary/10 px-2 py-0.5 text-xs text-primary`,children:s(`builtinAgent`)}):null,e.enabledAsSubagent?(0,h.jsx)(`span`,{className:`rounded-full bg-emerald-500/10 px-2 py-0.5 text-xs text-emerald-700`,children:s(`enabledAsSubagent`)}):null]}),(0,h.jsx)(`p`,{className:`mt-1 font-mono text-xs text-muted-foreground`,children:e.name}),e.source&&!e.builtin?(0,h.jsxs)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:[e.source,e.relativePath?` · ${e.relativePath}`:``]}):null,(0,h.jsx)(`p`,{className:`mt-2 text-sm text-muted-foreground`,children:e.description||s(`noDescription`)})]}),(0,h.jsxs)(`div`,{className:`flex shrink-0 gap-1`,children:[(0,h.jsx)(d,{variant:`outline`,size:`sm`,disabled:e.builtin||e.readonly,onClick:()=>G(e),children:s(`editTask`)}),(0,h.jsx)(d,{variant:`destructive`,size:`sm`,disabled:e.builtin||e.readonly,onClick:()=>void Y(e),children:s(`delete`)})]})]}),(0,h.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-1`,children:e.allowedTools.map(e=>(0,h.jsx)(`span`,{className:`rounded-full bg-muted px-2 py-0.5 font-mono text-xs text-muted-foreground`,children:e},e))}),(0,h.jsxs)(`div`,{className:`mt-3 grid gap-2 border-t border-border pt-3 text-xs text-muted-foreground sm:grid-cols-2`,children:[(0,h.jsxs)(`span`,{children:[s(`maxRuntimeMs`),e.maxRuntimeMs??`-`]}),(0,h.jsxs)(`span`,{children:[s(`maxToolCalls`),e.maxToolCalls??`-`]})]})]},e.id))})]})}),S?(0,h.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4`,onMouseDown:e=>{e.target===e.currentTarget&&K()},children:(0,h.jsxs)(`div`,{className:`flex max-h-[90vh] w-full max-w-3xl flex-col overflow-hidden rounded-2xl border border-border bg-background shadow-quickforge`,onMouseDown:e=>e.stopPropagation(),children:[(0,h.jsxs)(`div`,{className:`shrink-0 border-b border-border px-5 py-4`,children:[(0,h.jsx)(`h2`,{className:`text-base font-medium text-foreground`,children:s(V?`editAgent`:`createAgent`)}),V?.readonly?(0,h.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:s(`builtinAgentReadonly`)}):null]}),(0,h.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-5 py-4`,children:(0,h.jsxs)(`div`,{className:`space-y-4`,children:[(0,h.jsxs)(`div`,{className:`rounded-2xl border border-border bg-muted/20 p-3`,children:[(0,h.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 text-sm font-medium text-foreground`,children:[(0,h.jsx)(n,{className:`size-4 text-primary`}),s(`aiFillAgent`),(0,h.jsx)(l,{label:s(`aiFillAgentDescription`)})]}),(0,h.jsx)(`textarea`,{className:`min-h-20 w-full resize-y rounded-xl border border-input bg-background px-3 py-2 text-sm outline-none transition-colors placeholder:text-muted-foreground/65 focus:border-ring disabled:opacity-60`,value:A,disabled:!!V?.readonly||M,onChange:e=>j(e.target.value),placeholder:s(`aiFillAgentPlaceholder`)}),(0,h.jsx)(`div`,{className:`mt-2 flex justify-end`,children:(0,h.jsxs)(d,{variant:`outline`,size:`sm`,onClick:()=>void q(),disabled:!!V?.readonly||M||!A.trim(),children:[(0,h.jsx)(n,{className:`mr-1 size-3.5`}),s(M?`aiFillAgentLoading`:`aiFillAgent`)]})})]}),(0,h.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,h.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[s(`agentName`),(0,h.jsx)(`input`,{className:`mt-1 h-10 w-full rounded-md border border-input bg-background px-3 text-sm outline-none focus:border-ring disabled:opacity-60`,value:E.name,disabled:!!V?.readonly,onChange:e=>H(`name`,e.target.value),placeholder:`reviewer`})]}),(0,h.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[s(`agentLabel`),(0,h.jsx)(`input`,{className:`mt-1 h-10 w-full rounded-md border border-input bg-background px-3 text-sm outline-none focus:border-ring disabled:opacity-60`,value:E.label,disabled:!!V?.readonly,onChange:e=>H(`label`,e.target.value),placeholder:s(`agentLabelPlaceholder`)})]})]}),(0,h.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[s(`agentDescription`),(0,h.jsx)(`input`,{className:`mt-1 h-10 w-full rounded-md border border-input bg-background px-3 text-sm outline-none focus:border-ring disabled:opacity-60`,value:E.description,disabled:!!V?.readonly,onChange:e=>H(`description`,e.target.value)})]}),(0,h.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[s(`agentSystemPrompt`),(0,h.jsx)(`textarea`,{className:`mt-1 min-h-36 w-full resize-y rounded-xl border border-input bg-background px-3 py-2 text-sm outline-none focus:border-ring disabled:opacity-60`,value:E.systemPrompt,disabled:!!V?.readonly,onChange:e=>H(`systemPrompt`,e.target.value)})]}),(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`div`,{className:`mb-2 text-sm font-medium text-foreground`,children:s(`allowedTools`)}),(0,h.jsx)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:i.map(e=>(0,h.jsxs)(`label`,{className:`flex items-start gap-2 rounded-xl border border-border bg-muted/20 p-3 text-sm disabled:opacity-60`,children:[(0,h.jsx)(`input`,{type:`checkbox`,className:`mt-1`,disabled:!!V?.readonly,checked:E.allowedTools.includes(e.name),onChange:()=>U(e.name)}),(0,h.jsxs)(`span`,{children:[(0,h.jsx)(`span`,{className:`font-medium text-foreground`,children:e.label}),(0,h.jsx)(`span`,{className:`ml-2 font-mono text-xs text-muted-foreground`,children:e.name}),e.riskLevel===`dangerous`?(0,h.jsx)(`span`,{className:`ml-2 rounded-full bg-amber-500/10 px-2 py-0.5 text-xs text-amber-700`,children:s(`highRiskTool`)}):null,(0,h.jsx)(`span`,{className:`mt-1 block text-xs text-muted-foreground`,children:e.description})]})]},e.name))})]}),(0,h.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,h.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[s(`maxRuntimeMs`),(0,h.jsx)(`input`,{type:`number`,className:`mt-1 h-10 w-full rounded-md border border-input bg-background px-3 text-sm outline-none focus:border-ring disabled:opacity-60`,value:E.maxRuntimeMs,disabled:!!V?.readonly,onChange:e=>H(`maxRuntimeMs`,e.target.value)})]}),(0,h.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[s(`maxToolCalls`),(0,h.jsx)(`input`,{type:`number`,className:`mt-1 h-10 w-full rounded-md border border-input bg-background px-3 text-sm outline-none focus:border-ring disabled:opacity-60`,value:E.maxToolCalls,disabled:!!V?.readonly,onChange:e=>H(`maxToolCalls`,e.target.value)})]})]}),(0,h.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-foreground`,children:[(0,h.jsx)(`input`,{type:`checkbox`,checked:E.enabledAsSubagent,disabled:!!V?.readonly,onChange:e=>H(`enabledAsSubagent`,e.target.checked)}),s(`enabledAsSubagent`)]}),R?(0,h.jsx)(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive`,children:R}):null]})}),(0,h.jsx)(`div`,{className:`shrink-0 border-t border-border px-5 py-4`,children:(0,h.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,h.jsx)(d,{variant:`outline`,onClick:K,disabled:O||M,children:s(`cancel`)}),(0,h.jsx)(d,{onClick:J,disabled:O||M||!!V?.readonly||!y(E),children:s(`save`)})]})})]})}):null]})}export{x as AgentProfilesPage};
@@ -1,4 +1,4 @@
1
- import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{R as t,St as n}from"./icons-47L5YLKz.js";import{n as r,t as i}from"./react-vendor-DunfCFfp.js";import{d as a,p as o,t as s}from"./lit-vendor-Dr3cpBGF.js";import{c,l,s as u}from"./pi-web-ui-CBet4bMl.js";import{t as d}from"./logger-B65Akg8A.js";import{N as f,g as p,h as m,m as h,n as g,o as _,p as v,v as y}from"./index-CqfScETb.js";import{t as b}from"./plugin-api-YfYj_Bd7.js";var x=e(n(),1),S={maxHeight:`28rem`,overflow:`auto`,border:`1px solid color-mix(in oklab, var(--border) 75%, transparent)`,borderRadius:`0.75rem`,background:`color-mix(in oklab, var(--muted) 28%, transparent)`,fontFamily:`ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace`,fontSize:`0.78rem`,lineHeight:`1.45`},C={minHeight:`1.35em`,padding:`0 0.75rem`,whiteSpace:`pre`},w={display:`inline-flex`,alignItems:`center`,borderRadius:`999px`,padding:`0.05rem 0.45rem`,fontFamily:`ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace`,fontSize:`0.72rem`,fontWeight:`650`};function T(e){if(e==null)return``;if(typeof e==`string`)try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}try{return JSON.stringify(e,null,2)}catch{return String(e)}}function E(e){return e?.content?.filter(e=>e.type===`text`).map(e=>e.text??``).join(`
1
+ import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{Ct as t,R as n}from"./icons-DJqt-rnw.js";import{n as r,t as i}from"./react-vendor-CZCcjpSR.js";import{d as a,p as o,t as s}from"./lit-vendor-Dr3cpBGF.js";import{c,l,s as u}from"./pi-web-ui-CBet4bMl.js";import{t as d}from"./logger-B65Akg8A.js";import{I as f,_ as p,c as m,g as h,r as g,v as _,x as v,y}from"./index-CcGy4TXo.js";import{t as b}from"./plugin-api-YfYj_Bd7.js";var x=e(t(),1),S={maxHeight:`28rem`,overflow:`auto`,border:`1px solid color-mix(in oklab, var(--border) 75%, transparent)`,borderRadius:`0.75rem`,background:`color-mix(in oklab, var(--muted) 28%, transparent)`,fontFamily:`ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace`,fontSize:`0.78rem`,lineHeight:`1.45`},C={minHeight:`1.35em`,padding:`0 0.75rem`,whiteSpace:`pre`},w={display:`inline-flex`,alignItems:`center`,borderRadius:`999px`,padding:`0.05rem 0.45rem`,fontFamily:`ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace`,fontSize:`0.72rem`,fontWeight:`650`};function T(e){if(e==null)return``;if(typeof e==`string`)try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}try{return JSON.stringify(e,null,2)}catch{return String(e)}}function E(e){return e?.content?.filter(e=>e.type===`text`).map(e=>e.text??``).join(`
2
2
  `)??``}function D(e){return!!(e&&typeof e==`object`&&!Array.isArray(e))}function O(e,t){if(e.running===!0||t)return`Status: running`;let n=[e.timedOut?`timed out`:null,e.aborted?`aborted`:null].filter(Boolean),r=n.length?` (${n.join(`, `)})`:``;return`Exit code: ${e.code??`unknown`}${typeof e.signal==`string`&&e.signal?`, signal: ${e.signal}`:``}${r}`}function k(e,t,n){let r=D(t)?t:void 0,i=typeof r?.command==`string`?r.command:typeof e?.command==`string`?e.command:``;if(!i||!r)return``;let a=typeof r?.stdout_preview==`string`?r.stdout_preview:typeof r?.stdout==`string`?r.stdout:``,o=typeof r?.stderr_preview==`string`?r.stderr_preview:typeof r?.stderr==`string`?r.stderr:``,s=!!(a||o),c=r.running===!0||r.code!==void 0||r.signal!==void 0||r.timedOut===!0||r.aborted===!0;return!s&&!c&&!n?``:[`Command: ${i}`,O(r,n),``,`STDOUT:`,a||`(empty)`,``,`STDERR:`,o||`(empty)`].join(`
3
3
  `)}function A(e,t,n,r){return E(n)||(e===`run_command`?k(t,n?.details,r):``)}function j(e,t){return D(e)&&typeof e[t]==`string`?e[t]:``}function M(e,t,n){if(!t&&!n?.details)return``;if(e===`run_command`&&typeof t?.command==`string`)return t.command;if(e===`present_files`){let e=(Array.isArray(t?.files)?t.files:Array.isArray(n?.details&&n.details.files)?(n?.details).files:[]).map(e=>typeof e==`string`?e:D(e)&&typeof e.path==`string`?e.path:``).filter(Boolean);return e.length?e.slice(0,3).join(`, `)+(e.length>3?` +${e.length-3}`:``):``}if(e===`grep_files`){let e=typeof t?.query==`string`&&t.query?t.query:j(n?.details,`query`),r=typeof t?.path==`string`&&t.path?t.path:j(n?.details,`path`)||`.`,i=t?.regex||D(n?.details)&&D(n.details.searchOptions)&&n.details.searchOptions.regex?`regex`:`text`,a=r&&r!==`.`?` in ${r}`:` in current workspace`;return e?`${i}: ${e}${a}`:`searching${a}`}return e===`activate_skill`&&typeof t?.name==`string`?t.name:e===`read_skill_resource`&&typeof t?.path==`string`||t&&`path`in t&&typeof t.path==`string`?t.path:t&&`query`in t&&typeof t.query==`string`?t.query:t&&`search_query`in t&&typeof t.search_query==`string`?t.search_query:``}function N(e){if(!e||typeof e!=`object`)return;let t=e.diff;if(!t||typeof t!=`object`)return;let n=t;return typeof n.text==`string`?n:void 0}function ee(e){if(!e||typeof e!=`object`)return e;let t=e,n=t.diff;if(!n||typeof n!=`object`)return e;let{text:r,...i}=n;return{...t,diff:i}}function P(e){if(!e||typeof e!=`object`)return{};let t=e;return{sessionId:typeof t.sessionId==`string`?t.sessionId:void 0,toolCallId:typeof t.toolCallId==`string`?t.toolCallId:void 0}}async function te(e,t,n){let r=n.getAttribute(`aria-label`)||f(`terminateCommand`);n.disabled=!0,n.setAttribute(`aria-label`,f(`commandTerminateRequested`)),n.setAttribute(`title`,f(`commandTerminateRequested`));try{let n=await fetch(`/api/agents/${encodeURIComponent(e)}/abort-tool`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({toolCallId:t})});if(!n.ok)throw Error(`HTTP ${n.status}`)}catch{n.disabled=!1,n.setAttribute(`aria-label`,r),n.setAttribute(`title`,f(`terminateCommandTitle`))}}function ne(e){return e.startsWith(`+++`)||e.startsWith(`---`)?`quickforge-diff-file`:e.startsWith(`@@`)?`quickforge-diff-hunk`:e.startsWith(`+`)?`quickforge-diff-add`:e.startsWith(`-`)?`quickforge-diff-del`:`quickforge-diff-context`}function F(e){return e.startsWith(`+++`)||e.startsWith(`---`)?{...C,background:`color-mix(in oklab, var(--muted) 48%, transparent)`,color:`color-mix(in oklab, var(--muted-foreground) 88%, transparent)`}:e.startsWith(`@@`)?{...C,background:`color-mix(in oklab, rgb(37 99 235) 10%, transparent)`,color:`rgb(37 99 235)`}:e.startsWith(`+`)?{...C,background:`color-mix(in oklab, rgb(34 197 94) 16%, transparent)`,color:`rgb(22 101 52)`}:e.startsWith(`-`)?{...C,background:`color-mix(in oklab, rgb(239 68 68) 14%, transparent)`,color:`rgb(153 27 27)`}:{...C,color:`var(--foreground)`}}function I(e,t){if(e!==`write_file`&&e!==`edit_file`||!t)return a;let n=Number(t.addedLines??0),r=Number(t.removedLines??0);return o`
4
4
  <span class="shrink-0 inline-flex items-center gap-1" title="+${n} -${r}">
@@ -57,7 +57,7 @@ import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{R as t,St as n}from"./
57
57
  aria-label=${f(`previewArtifact`)}
58
58
  @click=${e=>{e.preventDefault(),e.stopPropagation(),window.dispatchEvent(new CustomEvent(fe,{detail:{path:n}}))}}
59
59
  ><svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M2 12s3-7 10-7 10 7 10 7-3 7-10 7-10-7-10-7Z"/><circle cx="12" cy="12" r="3"/></svg></button>
60
- `:a}function he(e,t){return D(t)&&typeof t.label==`string`&&t.label?t.label:e===`general`?f(`subagentGeneral`):e===`explore`?f(`subagentExplore`):e||f(`runSubagent`)}function z(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function B(e){return Array.isArray(e)?e:[]}function V(e){let t=new Set,n=[];for(let r of e){if(!D(r)||r.role!==`assistant`||!Array.isArray(r.content))continue;let e=r.content.filter(e=>D(e)&&e.type===`toolCall`);if(e.length!==0){for(let n of e)D(n)&&typeof n.id==`string`&&t.add(n.id);n.push({...r,content:e,usage:void 0})}}let r=e.filter(e=>D(e)&&e.role===`toolResult`&&typeof e.toolCallId==`string`&&t.has(e.toolCallId));return[...n,...r]}var H=new Map,U=100;function ge(e,t){if(e){if(!H.has(e)&&H.size>=U){let e=H.keys().next().value;e&&H.delete(e)}H.set(e,t)}}var _e=class{render(e,t,n){let r=t?.isError?`error`:n?`running`:t?`done`:`called`,i=y(t?.details),s=D(t?.details)?t.details:void 0,c=typeof e?.subagent==`string`?e.subagent:typeof s?.subagent==`string`?s.subagent:``,l=he(c,s),u=typeof e?.task==`string`?e.task:``,d=typeof e?.context==`string`?e.context:``,p=typeof e?.expectedOutput==`string`?e.expectedOutput:``,m=typeof s?.toolCalls==`number`?s.toolCalls:void 0,h=z(s?.allowedTools),g=B(s?.messages),_=B(s?.tools),b=new Set(z(s?.pendingToolCalls)),x=v(),S=x.showToolDetails?g:V(g),C=x.showToolDetails?T(e):``,w=x.showToolDetails?T(t?.details):``,O=E(t),k=typeof s?.sessionId==`string`?s.sessionId:`${c}:${u}`,A=H.get(k)??x.expandToolsByDefault,j=r===`running`?f(`subagentRunning`,{name:l}):r===`done`?f(`subagentCompleted`,{name:l}):r===`error`?f(`subagentFailed`,{name:l}):f(`runSubagent`);return{isCustom:!1,content:o`
60
+ `:a}function he(e,t){return D(t)&&typeof t.label==`string`&&t.label?t.label:e===`general`?f(`subagentGeneral`):e===`explore`?f(`subagentExplore`):e||f(`runSubagent`)}function z(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function B(e){return Array.isArray(e)?e:[]}function V(e){let t=new Set,n=[];for(let r of e){if(!D(r)||r.role!==`assistant`||!Array.isArray(r.content))continue;let e=r.content.filter(e=>D(e)&&e.type===`toolCall`);if(e.length!==0){for(let n of e)D(n)&&typeof n.id==`string`&&t.add(n.id);n.push({...r,content:e,usage:void 0})}}let r=e.filter(e=>D(e)&&e.role===`toolResult`&&typeof e.toolCallId==`string`&&t.has(e.toolCallId));return[...n,...r]}var H=new Map,U=100;function ge(e,t){if(e){if(!H.has(e)&&H.size>=U){let e=H.keys().next().value;e&&H.delete(e)}H.set(e,t)}}var _e=class{render(e,t,n){let r=t?.isError?`error`:n?`running`:t?`done`:`called`,i=v(t?.details),s=D(t?.details)?t.details:void 0,c=typeof e?.subagent==`string`?e.subagent:typeof s?.subagent==`string`?s.subagent:``,l=he(c,s),u=typeof e?.task==`string`?e.task:``,d=typeof e?.context==`string`?e.context:``,p=typeof e?.expectedOutput==`string`?e.expectedOutput:``,m=typeof s?.toolCalls==`number`?s.toolCalls:void 0,g=z(s?.allowedTools),_=B(s?.messages),y=B(s?.tools),b=new Set(z(s?.pendingToolCalls)),x=h(),S=x.showToolDetails?_:V(_),C=x.showToolDetails?T(e):``,w=x.showToolDetails?T(t?.details):``,O=E(t),k=typeof s?.sessionId==`string`?s.sessionId:`${c}:${u}`,A=H.get(k)??x.expandToolsByDefault,j=r===`running`?f(`subagentRunning`,{name:l}):r===`done`?f(`subagentCompleted`,{name:l}):r===`error`?f(`subagentFailed`,{name:l}):f(`runSubagent`);return{isCustom:!1,content:o`
61
61
  <details class="group/tool quickforge-subagent-tool" ?open=${A} @toggle=${e=>ge(k,e.currentTarget.open)}>
62
62
  <summary class="flex cursor-pointer list-none items-center gap-2 text-sm text-muted-foreground select-none">
63
63
  <svg class="shrink-0 transition-transform group-open/tool:rotate-90" xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m9 18 6-6-6-6"/></svg>
@@ -75,15 +75,15 @@ import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{R as t,St as n}from"./
75
75
  ${u?o`<div class="mt-2 text-muted-foreground/85"><span class="font-medium text-foreground/75">${f(`subagentTask`)}:</span> ${u}</div>`:a}
76
76
  ${d?o`<div class="mt-1 text-xs text-muted-foreground/70"><span class="font-medium">${f(`subagentContext`)}:</span> ${d}</div>`:a}
77
77
  ${p?o`<div class="mt-1 text-xs text-muted-foreground/70"><span class="font-medium">${f(`subagentExpectedOutput`)}:</span> ${p}</div>`:a}
78
- ${h.length>0?o`<div class="mt-2 flex flex-wrap gap-1.5">${h.map(e=>o`<span class="rounded-full bg-background/80 px-2 py-0.5 text-[11px] text-muted-foreground/80">${e}</span>`)}</div>`:a}
78
+ ${g.length>0?o`<div class="mt-2 flex flex-wrap gap-1.5">${g.map(e=>o`<span class="rounded-full bg-background/80 px-2 py-0.5 text-[11px] text-muted-foreground/80">${e}</span>`)}</div>`:a}
79
79
  </div>`:a}
80
- ${S.length>0?o`<div class="quickforge-subagent-trace rounded-lg border border-border/70 bg-background/60 p-2.5"><message-list .messages=${S} .tools=${_} .pendingToolCalls=${b} .isStreaming=${r===`running`}></message-list></div>`:a}
80
+ ${S.length>0?o`<div class="quickforge-subagent-trace rounded-lg border border-border/70 bg-background/60 p-2.5"><message-list .messages=${S} .tools=${y} .pendingToolCalls=${b} .isStreaming=${r===`running`}></message-list></div>`:a}
81
81
  ${O?o`<div><div class="mb-1 text-xs font-medium text-muted-foreground">${f(`subagentResult`)}</div><code-block .code=${O} language="text"></code-block></div>`:a}
82
82
  ${C?o`<div><div class="mb-1 text-xs font-medium text-muted-foreground">${f(`input`)}</div><code-block .code=${C} language="json"></code-block></div>`:a}
83
83
  ${w?o`<div><div class="mb-1 text-xs font-medium text-muted-foreground">${f(`details`)}</div><code-block .code=${w} language="json"></code-block></div>`:a}
84
84
  </div>
85
85
  </details>
86
- `}}},ve=class{toolName;labelKey;constructor(e,t){this.toolName=e,this.labelKey=t}render(e,t,n){let r=t?.isError?`error`:n?`running`:t?`done`:`called`,i=y(t?.details),a=M(this.toolName,e,t),s=v(),c=s.showToolDetails,l=s.expandToolsByDefault,u=c?T(e):``,d=A(this.toolName,e,t,n),p=N(t?.details),m=c?T(p?ee(t?.details):t?.details):``,h=t?.isError?`error`:`default`;return{isCustom:!1,content:o`
86
+ `}}},ve=class{toolName;labelKey;constructor(e,t){this.toolName=e,this.labelKey=t}render(e,t,n){let r=t?.isError?`error`:n?`running`:t?`done`:`called`,i=v(t?.details),a=M(this.toolName,e,t),s=h(),c=s.showToolDetails,l=s.expandToolsByDefault,u=c?T(e):``,d=A(this.toolName,e,t,n),p=N(t?.details),m=c?T(p?ee(t?.details):t?.details):``,g=t?.isError?`error`:`default`;return{isCustom:!1,content:o`
87
87
  <details class="group/tool" ?open=${l}>
88
88
  <summary class="flex cursor-pointer list-none items-center gap-2 text-sm text-muted-foreground select-none">
89
89
  <svg class="shrink-0 transition-transform group-open/tool:rotate-90" xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m9 18 6-6-6-6"/></svg>
@@ -96,23 +96,23 @@ import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{R as t,St as n}from"./
96
96
  </summary>
97
97
  <div class="mt-3 space-y-3">
98
98
  ${u?o`<div><div class="mb-1 text-xs font-medium text-muted-foreground">${f(`input`)}</div><code-block .code=${u} language="json"></code-block></div>`:``}
99
- ${d?o`<div><div class="mb-1 text-xs font-medium text-muted-foreground">${f(`output`)}</div>${this.toolName===`run_command`?o`<console-block .content=${d} .variant=${h}></console-block>`:o`<code-block .code=${d} language="text"></code-block>`}</div>`:``}
99
+ ${d?o`<div><div class="mb-1 text-xs font-medium text-muted-foreground">${f(`output`)}</div>${this.toolName===`run_command`?o`<console-block .content=${d} .variant=${g}></console-block>`:o`<code-block .code=${d} language="text"></code-block>`}</div>`:``}
100
100
  ${p?re(p):``}
101
101
  ${m?o`<div><div class="mb-1 text-xs font-medium text-muted-foreground">${f(`details`)}</div><code-block .code=${m} language="json"></code-block></div>`:``}
102
102
  </div>
103
103
  </details>
104
- `}}};function W(e){if(!e.startsWith(`mcp__`))return null;let t=e.slice(5),n=t.indexOf(`__`);return n<=0||n>=t.length-2?null:{serverName:t.slice(0,n),toolName:t.slice(n+2)}}function G(e,t){let n=W(e),r=D(t)?t:void 0,i=typeof r?.server==`string`&&r.server?r.server:n?.serverName??``,a=typeof r?.tool==`string`&&r.tool?r.tool:n?.toolName??e;return n||r?.mcp===!0?{serverName:i,toolName:a}:null}function K(e){if(!e)return`text`;try{return JSON.parse(e),`json`}catch{return`text`}}var ye=class{toolName;label;constructor(e,t){this.toolName=e,this.label=t}render(e,t,n){let r=t?.isError?`error`:n?`running`:t?`done`:`called`,i=y(t?.details),s=G(this.toolName,t?.details)??W(this.toolName),c=s?.serverName??``,l=s?.toolName??this.toolName,u=M(this.toolName,e,t),d=v(),p=T(e),m=A(this.toolName,e,t,n),h=d.showToolDetails?T(t?.details):``,g=this.label&&this.label!==l?`${this.label} (${l})`:l;return{isCustom:!1,content:o`
104
+ `}}};function W(e){if(!e.startsWith(`mcp__`))return null;let t=e.slice(5),n=t.indexOf(`__`);return n<=0||n>=t.length-2?null:{serverName:t.slice(0,n),toolName:t.slice(n+2)}}function G(e,t){let n=W(e),r=D(t)?t:void 0,i=typeof r?.server==`string`&&r.server?r.server:n?.serverName??``,a=typeof r?.tool==`string`&&r.tool?r.tool:n?.toolName??e;return n||r?.mcp===!0?{serverName:i,toolName:a}:null}function K(e){if(!e)return`text`;try{return JSON.parse(e),`json`}catch{return`text`}}var ye=class{toolName;label;constructor(e,t){this.toolName=e,this.label=t}render(e,t,n){let r=t?.isError?`error`:n?`running`:t?`done`:`called`,i=v(t?.details),s=G(this.toolName,t?.details)??W(this.toolName),c=s?.serverName??``,l=s?.toolName??this.toolName,u=M(this.toolName,e,t),d=h(),p=T(e),m=A(this.toolName,e,t,n),g=d.showToolDetails?T(t?.details):``,_=this.label&&this.label!==l?`${this.label} (${l})`:l;return{isCustom:!1,content:o`
105
105
  <details class="group/tool quickforge-mcp-tool" ?open=${d.expandToolsByDefault}>
106
106
  <summary class="flex cursor-pointer list-none items-center gap-2 text-sm text-muted-foreground select-none">
107
107
  <svg class="shrink-0 transition-transform group-open/tool:rotate-90" xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m9 18 6-6-6-6"/></svg>
108
108
  ${ce(this.toolName)}
109
- <span class="min-w-0 flex-1 truncate">MCP${c?o`<span class="text-muted-foreground/70"> · ${c}</span>`:a}<span class="text-muted-foreground/70"> · ${g}</span>${u?o`<span class="text-muted-foreground/70"> · ${u}</span>`:a}</span>
109
+ <span class="min-w-0 flex-1 truncate">MCP${c?o`<span class="text-muted-foreground/70"> · ${c}</span>`:a}<span class="text-muted-foreground/70"> · ${_}</span>${u?o`<span class="text-muted-foreground/70"> · ${u}</span>`:a}</span>
110
110
  ${ue(r,i)}
111
111
  </summary>
112
112
  <div class="mt-3 space-y-3">
113
113
  ${p?o`<div><div class="mb-1 text-xs font-medium text-muted-foreground">${f(`input`)}</div><code-block .code=${p} language="json"></code-block></div>`:a}
114
114
  ${m?o`<div><div class="mb-1 text-xs font-medium text-muted-foreground">${f(`output`)}</div><code-block .code=${m} language=${K(m)}></code-block></div>`:a}
115
- ${h?o`<div><div class="mb-1 text-xs font-medium text-muted-foreground">${f(`details`)}</div><code-block .code=${h} language="json"></code-block></div>`:a}
115
+ ${g?o`<div><div class="mb-1 text-xs font-medium text-muted-foreground">${f(`details`)}</div><code-block .code=${g} language="json"></code-block></div>`:a}
116
116
  </div>
117
117
  </details>
118
118
  `}}},be=new Set;function xe(e){for(let t of e){if(!D(t)||typeof t.name!=`string`||!W(t.name)||be.has(t.name))continue;let e=typeof t.label==`string`?t.label:typeof t.description==`string`?t.description.replace(/^\[MCP:[^\]]+\]\s*/,``):void 0;l(t.name,new ye(t.name,e)),be.add(t.name)}}for(let[e,t]of[[`read_file`,`readFile`],[`grep_files`,`searchFiles`],[`write_file`,`writeFile`],[`edit_file`,`editFile`],[`run_command`,`runCommand`],[`present_files`,`presentFiles`],[`activate_skill`,`activateSkill`],[`read_skill_resource`,`readSkillResource`]])l(e,new ve(e,t));l(`run_subagent`,new _e);function Se(e=[]){return xe(e),e}function Ce(e,t){let n=document.createElement(`template`);n.innerHTML=t;let r=n.content.firstElementChild;if(!r)return;let i=e.querySelector(`svg`);i?i.replaceWith(r):e.appendChild(r)}function we(e,t){let n=document.createElement(`template`);n.innerHTML=t;let r=Array.from(n.content.children);for(let t of Array.from(e.children))t.remove();for(let t of r)e.appendChild(t)}var Te=()=>({text:``,attachments:[]}),q=e=>e.text.length>0||(e.attachments?.length??0)>0;function Ee(e){try{return JSON.stringify(e)}catch{return``}}function De(e){let t=String(e||``);if(!t)return 0;let n=t.match(/[\u3400-\u9fff\uf900-\ufaff]/g)?.length??0,r=Math.max(0,t.length-n);return Math.ceil(n+r/3.5)}function Oe(e){return e?typeof e==`string`?e:Array.isArray(e)?e.map(e=>{if(!e||typeof e!=`object`)return Oe(e);let t=e;return t.type===`text`?typeof t.text==`string`?t.text:``:t.type===`thinking`?typeof t.thinking==`string`?t.thinking:``:t.type===`image`?`[image:${typeof t.mimeType==`string`?t.mimeType:`unknown`}]`:t.type===`toolCall`?`[toolCall:${typeof t.name==`string`?t.name:`unknown`}] ${Ee(t.arguments)}`:Ee(t)}).filter(Boolean).join(`
@@ -163,11 +163,11 @@ import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{R as t,St as n}from"./
163
163
  <span class="quickforge-capability-suggestion-description"></span>
164
164
  </span>
165
165
  `,t.querySelector(`.quickforge-capability-suggestion-name`).textContent=e.label,t.querySelector(`.quickforge-capability-suggestion-description`).textContent=e.description??e.pluginName,t.onpointerdown=t=>{t.preventDefault(),t.stopPropagation(),d(e,o)},g.append(t)}l||n.parentElement?.insertBefore(g,n),g.__quickforgeDismissHandler||(g.__quickforgeDismissHandler=e=>{g.contains(e.target)||n.contains(e.target)||u()},document.addEventListener(`pointerdown`,g.__quickforgeDismissHandler,!0))};return{update:m,remove:u,setupTextareaHandler:e=>{let t=e?.querySelector(`textarea`);if(!t)return;let n=t;n.__quickforgeCapabilityCompleteHandler&&n.removeEventListener(`keydown`,n.__quickforgeCapabilityCompleteHandler,!0),n.__quickforgeCapabilityCompleteHandler=t=>{if(t.isComposing||t.key===`Process`)return;if(t.key===`Escape`){u();return}if(t.key!==`Tab`&&t.key!==`Enter`)return;let r=e?.value??n.value??``,i=He(r,n.selectionStart??r.length);if(!i||t.shiftKey)return;let a=l();a&&(t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation(),d(a,i))},n.addEventListener(`keydown`,n.__quickforgeCapabilityCompleteHandler,!0)},cleanupTextareaHandler:()=>{let t=e.querySelector(`message-editor textarea`);t?.__quickforgeCapabilityCompleteHandler&&t.removeEventListener(`keydown`,t.__quickforgeCapabilityCompleteHandler,!0)},consumeSelectedCapabilities:e=>{let t=Ue(e),n=[...a.values()].filter(e=>t.has(e.mention.toLowerCase())),r=c().filter(e=>t.has(e.insertText.toLowerCase())||t.has(e.label.replace(/\s+/g,``).toLowerCase())),i=new Map;for(let e of[...n,...r])i.set(Ge(e),e);return a=new Map,o(),[...i.values()].slice(0,4)},insertBuiltinPluginMention:p}}function Ge(e){return`${e.type}:${e.pluginName}:${e.name}`}var Ke=i();function qe(e){return`hsl(${Math.round(142-142*Math.min(100,Math.max(0,e))/100)} 72% 45%)`}function Je(e,t){let n=Number(e.inputTokens)||0,r=Math.max(0,Number(e.knownInputTokens??e.providerContextTokens)||0),i=Math.max(0,Number(e.estimatedInputTokens)||0),a=Math.max(0,Number(e.reservedOutputTokens)||0),o=Math.max(0,Number(e.totalTokens)||n+a),s=Number.isFinite(Number(e.percent))?Number(e.percent):0,c=e.inputTokenSource??(r>0?`provider`:`estimated`);return{contextWindow:Math.max(0,Number(e.contextWindow)||t),usedTokens:Math.max(0,Number(e.usedTokens)||n),totalTokens:o,inputTokens:n,estimatedInputTokens:i,knownInputTokens:r,inputTokenSource:c,reservedOutputTokens:a,percent:s,color:e.color||qe(s),isCompacted:e.isCompacted,compactedUpToIndex:e.compactedUpToIndex,originalMessageCount:e.originalMessageCount,effectiveMessageCount:e.effectiveMessageCount,breakdown:e.breakdown}}function Ye(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`).replace(/'/g,`&#39;`)}function Xe(e){let t=Math.max(0,Number(e)||0);return t>0?J(t):null}function Ze({usage:e,contextWindow:t,serverCalculated:n,compacted:r}){let i=e.inputTokenSource===`provider`?`provider context`:e.inputTokenSource===`mixed`?`provider/local mixed context`:`estimated context`,a=[`Context used: ${e.percent}% (${J(e.totalTokens)} / ${J(t)} tokens)`,`Input/context: ${J(e.inputTokens)} (${i})`,`Local estimate: ${J(e.estimatedInputTokens)}`],o=e.breakdown;return o&&(a.push(` System prompt: ${Xe(o.systemPromptTokens)??`0`}`,` Tools schema: ${Xe(o.toolsTokens)??`0`}`,` Messages: ${Xe(o.messagesTokens)??`0`}`),(o.providerUsageTokens||o.trailingTokens)&&a.push(` Provider usage baseline: ${Xe(o.providerUsageTokens)??`0`}`,` Trailing messages after usage: ${Xe(o.trailingTokens)??`0`}`)),a.push(`Reserved output: ${J(e.reservedOutputTokens)}`),n&&a.push(`Source: server calculated via pi-agent-core/pi-ai`),a.push(r?`Scope: compacted model context, not full visible chat history`:`Scope: full model context`),r&&e.originalMessageCount!==void 0&&e.effectiveMessageCount!==void 0&&a.push(`Messages: ${e.effectiveMessageCount} effective / ${e.originalMessageCount} visible`),e.knownInputTokens&&e.knownInputTokens>0&&a.push(`Provider context tokens: ${J(e.knownInputTokens)}`),a.join(`
166
- `)}function Qe(e,t){if(!t){e.removeAttribute(`role`),e.removeAttribute(`tabindex`),e.style.cursor=``;return}e.setAttribute(`role`,`button`),e.tabIndex=0,e.style.cursor=`pointer`,!e.dataset.quickforgeGitBranchBound&&(e.dataset.quickforgeGitBranchBound=`true`,e.addEventListener(`click`,e=>{e.preventDefault(),e.stopPropagation(),t()}),e.addEventListener(`keydown`,e=>{e.key!==`Enter`&&e.key!==` `||(e.preventDefault(),e.stopPropagation(),t())}))}var $e=(0,Ke.renderToStaticMarkup)((0,x.createElement)(t,{size:13,strokeWidth:2,"aria-hidden":!0,style:{flex:`0 0 auto`}}));function et({panel:e,getSystemPrompt:t,getMessages:n,getContextWindow:r,getTools:i,getMaxTokens:a,getEffectiveMessages:o,getServerContextUsage:s,getGitBranch:c,onGitBranchClick:l,renderInline:u=!0,onDisplayChange:d}){return{update:()=>{let f=r(),p=n(),m=o?.()??p,h=e.querySelector(`.quickforge-context-usage`),g=e.querySelector(`.quickforge-context-usage-label`),_=e.querySelector(`.quickforge-git-branch-inline`),v=u?e.querySelector(`message-editor`)?.parentElement?.querySelector(`.ml-auto.items-center`):null,y=c?.()?.trim()||void 0,b={gitBranch:y};if(!u)_?.remove(),h?.remove(),g?.remove();else if(y&&v){let e=`${$e}<span style="max-width: 8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">${Ye(y)}</span>`,t=`Git branch: ${y}`;if(_)_.dataset.quickforgeGitBranch!==y&&(_.innerHTML=e,_.dataset.quickforgeGitBranch=y),_.title=t,_.setAttribute(`aria-label`,t),Qe(_,l);else{let n=document.createElement(`span`);n.className=`quickforge-git-branch-inline`,n.dataset.quickforgeGitBranch=y,n.title=t,n.setAttribute(`aria-label`,t),n.innerHTML=e,n.style.cssText=[`display: inline-flex`,`align-items: center`,`gap: 0.25rem`,`max-width: 10rem`,`color: hsl(var(--muted-foreground))`,`font-size: 12px`,`line-height: 1`,`font-weight: 500`].join(`;`),Qe(n,l),v.prepend(n)}}else _?.remove();if(!f)return u&&(h?.remove(),g?.remove()),d?.(b),b;let x=s?.(),S=m.length>0,C=x?Je(x,f):S?Pe(t(),m,f,i?.()??[],a?.()):{contextWindow:f,usedTokens:0,totalTokens:0,inputTokens:0,estimatedInputTokens:0,inputTokenSource:`estimated`,reservedOutputTokens:0,percent:0,color:`hsl(142 72% 45%)`},w=C.contextWindow||f,T=!!C.isCompacted||m!==p,E=Ze({usage:C,contextWindow:w,serverCalculated:!!x,compacted:T});if(b.context={percent:C.percent,color:C.color,label:`${C.percent}% · ${J(C.totalTokens)} / ${J(w)} tokens`,title:E},d?.(b),!u||!v)return h?.remove(),g?.remove(),b;let D=Math.min(100,Math.max(0,C.percent)),O=`conic-gradient(${C.color} ${D*3.6}deg, rgb(229 231 235) 0deg)`,k=h??document.createElement(`span`);k.className=`quickforge-context-usage`,k.title=E,k.setAttribute(`aria-label`,E),k.style.cssText=[`position: relative`,`display: inline-flex`,`width: 14px`,`height: 14px`,`flex: 0 0 auto`,`border-radius: 9999px`,`background: ${O}`,`vertical-align: middle`,`box-shadow: 0 0 0 1px rgb(0 0 0 / 0.06)`].join(`;`);let A=k.firstElementChild;A||(A=document.createElement(`span`),k.append(A)),A.style.cssText=[`position: absolute`,`inset: 3px`,`border-radius: 9999px`,`background: hsl(var(--background))`].join(`;`);let j=k.nextElementSibling;return j?.classList.contains(`quickforge-context-usage-label`)||(j=document.createElement(`span`),j.className=`quickforge-context-usage-label`,j.style.cssText=`color: hsl(var(--muted-foreground)); font-size: 12px; line-height: 1;`),j.textContent=`${C.percent}%`,j.title=E,j.setAttribute(`aria-label`,E),h?k.nextElementSibling!==j&&k.after(j):(v.prepend(j),v.prepend(k)),b}}}var tt=`<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect width="14" height="14" x="8" y="8" rx="2" ry="2"/><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"/></svg>`,nt=`<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M20 6 9 17l-5-5"/></svg>`,rt=`<svg xmlns="http://www.w3.org/2000/svg" width="17" height="17" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M9 14 4 9l5-5"/><path d="M4 9h10.5a5.5 5.5 0 0 1 0 11H11"/></svg>`,it=`<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="18" r="3"/><circle cx="6" cy="6" r="3"/><circle cx="18" cy="6" r="3"/><path d="M18 9v1a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2V9"/><path d="M12 12v3"/></svg>`,at=`<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><polygon points="6 3 20 12 6 21 6 3"/></svg>`,ot=`<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M21 2v6h-6"/><path d="M3 12a9 9 0 0 1 15.36-5.64L21 9"/><path d="M3 22v-6h6"/><path d="M21 12a9 9 0 0 1-15.36 5.64L3 15"/></svg>`,st=`<svg class="quickforge-plan-mode-icon" xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4 6h1"/><path d="M4 12h1"/><path d="M4 18h1"/><path d="M9 6h11"/><path d="M9 12h11"/><path d="M9 18h11"/></svg>`,ct=`<svg class="quickforge-plan-remove-icon" xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>`,lt=`<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 5v14"/><path d="M5 12h14"/></svg>`,ut=`<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m21.44 11.05-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48"/></svg>`,dt=`<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M7.5 4.5h5a1.5 1.5 0 0 1 1.5 1.5v2h1a2.5 2.5 0 0 1 0 5h-1v2a1.5 1.5 0 0 1-1.5 1.5h-2v1a2.5 2.5 0 0 1-5 0v-1h-2A1.5 1.5 0 0 1 2 15.5v-3h1a2 2 0 1 0 0-4H2v-2A1.5 1.5 0 0 1 3.5 5h2v-1a2.5 2.5 0 0 1 5 0v.5Z"/></svg>`,ft=`<svg viewBox="0 0 20 20" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.65" stroke-linecap="round" stroke-linejoin="round"><path d="M5.4 2.8h6.1L15.8 7v10.2H5.4z"/><path d="M11.4 2.9V7h4.1"/><path d="M7.6 10.2h5"/><path d="M7.6 13h4.3"/></svg>`,pt=`<svg viewBox="0 0 20 20" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.65" stroke-linecap="round" stroke-linejoin="round"><rect x="3.4" y="4" width="13.2" height="12.2" rx="1.5"/><path d="M3.4 8h13.2"/><path d="M7.8 4v12.2"/><path d="M12.2 4v12.2"/><path d="M3.4 12h13.2"/></svg>`,mt=`<svg viewBox="0 0 20 20" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.65" stroke-linecap="round" stroke-linejoin="round"><path d="M3 4.2h14"/><rect x="4.2" y="4.2" width="11.6" height="8.4" rx="1.2"/><path d="M10 12.6v3.2"/><path d="m7.2 17 2.8-1.2 2.8 1.2"/><path d="M7.1 9.5 9 7.7l1.5 1.3 2.4-2.5"/></svg>`;function ht(e,t,n){let r=f(`copied`),i=Number(e.dataset.quickforgeCopyFeedbackTimer);i&&window.clearTimeout(i),Ce(e,nt),e.title=r,e.setAttribute(`aria-label`,r),e.style.color=`rgb(5 150 105)`;let a=window.setTimeout(()=>{Ce(e,n),e.title=t,e.setAttribute(`aria-label`,t),e.style.color=``,delete e.dataset.quickforgeCopyFeedbackTimer},1200);e.dataset.quickforgeCopyFeedbackTimer=String(a)}function gt(e,t,n,r){let i=document.createElement(`button`);return i.type=`button`,i.dataset.quickforgeAction=e,i.title=t,i.setAttribute(`aria-label`,t),Ce(i,n),i.className=`pointer-events-auto inline-flex size-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-transparent hover:text-foreground disabled:cursor-not-allowed disabled:opacity-40`,i.onclick=e=>{e.stopPropagation(),r(i)},i}function _t(e){e.querySelectorAll(`.quickforge-rollback-popover`).forEach(e=>{e.quickforgeCleanup?.(),(e.closest(`.quickforge-rollback-action`)?.querySelector(`button[data-quickforge-action="rollback"]`))?.setAttribute(`aria-expanded`,`false`),e.remove()})}function vt(e){let{panel:t,button:n,messageIndex:r,title:i,description:a,onConfirm:o}=e,s=n.closest(`.quickforge-rollback-action`);if(!s||n.disabled)return;if(s.querySelector(`.quickforge-rollback-popover`)){_t(t);return}_t(t);let c=document.createElement(`div`);c.className=`quickforge-rollback-popover`,c.setAttribute(`role`,`dialog`),c.setAttribute(`aria-label`,i),c.tabIndex=-1;let l=document.createElement(`div`);l.className=`quickforge-rollback-popover-arrow`;let u=document.createElement(`div`);u.className=`quickforge-rollback-popover-title`,u.textContent=i;let d=document.createElement(`div`);d.className=`quickforge-rollback-popover-description`,d.textContent=a;let p=document.createElement(`div`);p.className=`quickforge-rollback-popover-footer`;let m=document.createElement(`button`);m.type=`button`,m.className=`quickforge-rollback-popover-cancel`,m.textContent=f(`cancel`);let h=document.createElement(`button`);h.type=`button`,h.className=`quickforge-rollback-popover-confirm`,h.textContent=f(`confirmRollback`),p.append(m,h),c.append(l,u,d,p);let g=()=>_t(t),_=e=>{let t=e.target;!t||c.contains(t)||n.contains(t)||g()},v=e=>{e.key===`Escape`&&(e.preventDefault(),g())};c.quickforgeCleanup=()=>{document.removeEventListener(`pointerdown`,_,!0),document.removeEventListener(`keydown`,v)},c.addEventListener(`pointerdown`,e=>e.stopPropagation()),c.addEventListener(`click`,e=>e.stopPropagation()),m.addEventListener(`click`,g),h.addEventListener(`click`,async()=>{h.disabled=!0,m.disabled=!0,h.textContent=f(`rollingBack`);try{await o(r)}finally{g()}}),s.append(c),n.setAttribute(`aria-expanded`,`true`),document.addEventListener(`pointerdown`,_,!0),document.addEventListener(`keydown`,v),window.requestAnimationFrame(()=>h.focus())}function yt(e){let t=document.createElement(`span`);t.className=`quickforge-rollback-action`;let n=gt(`rollback`,f(`rollback`),rt,t=>{vt({panel:e.panel,button:t,messageIndex:e.messageIndex,title:e.title,description:e.description,onConfirm:e.onConfirm})});return n.disabled=e.isDisabled,n.setAttribute(`aria-haspopup`,`dialog`),n.setAttribute(`aria-expanded`,`false`),t.append(n),t}var bt=new Set([`bash`,`sh`,`shell`,`zsh`,`fish`,`cmd`,`bat`,`batch`,`powershell`,`ps1`,`terminal`,`console`]),xt=/\b(rm\s+-rf|sudo|chmod\b|chown\b|npm\s+publish|pnpm\s+publish|yarn\s+publish|git\s+push|curl\b[^\n|;]*\|\s*(sh|bash)|wget\b[^\n|;]*\|\s*(sh|bash))\b/i,St=/<\s*(script|foreignObject)\b|\son[a-z]+\s*=|javascript\s*:/i;function Ct(e){return e.role===`user`||e.role===`user-with-attachments`||e.role===`assistant`}function wt(e){return e.role===`user`||e.role===`user-with-attachments`}function Tt(e){return e.role===`assistant`?h(e).trim().length>0:!1}function Et(e){return e.querySelector(`message-list`)}function Dt(e){let t=Et(e);return t?Array.from(t.querySelectorAll(`user-message, assistant-message`)).filter(e=>e.closest(`message-list`)===t):[]}function Ot(e){if(typeof e.getDecodedCode==`function`)try{return e.getDecodedCode()}catch{}let t=typeof e.code==`string`?e.code:e.getAttribute(`code`)??``;if(!t)return``;try{return decodeURIComponent(escape(window.atob(t)))}catch{return t}}function kt(e){return e.replace(/\r\n/g,`
166
+ `)}function Qe(e,t){if(!t){e.removeAttribute(`role`),e.removeAttribute(`tabindex`),e.style.cursor=``;return}e.setAttribute(`role`,`button`),e.tabIndex=0,e.style.cursor=`pointer`,!e.dataset.quickforgeGitBranchBound&&(e.dataset.quickforgeGitBranchBound=`true`,e.addEventListener(`click`,e=>{e.preventDefault(),e.stopPropagation(),t()}),e.addEventListener(`keydown`,e=>{e.key!==`Enter`&&e.key!==` `||(e.preventDefault(),e.stopPropagation(),t())}))}var $e=(0,Ke.renderToStaticMarkup)((0,x.createElement)(n,{size:13,strokeWidth:2,"aria-hidden":!0,style:{flex:`0 0 auto`}}));function et({panel:e,getSystemPrompt:t,getMessages:n,getContextWindow:r,getTools:i,getMaxTokens:a,getEffectiveMessages:o,getServerContextUsage:s,getGitBranch:c,onGitBranchClick:l,renderInline:u=!0,onDisplayChange:d}){return{update:()=>{let f=r(),p=n(),m=o?.()??p,h=e.querySelector(`.quickforge-context-usage`),g=e.querySelector(`.quickforge-context-usage-label`),_=e.querySelector(`.quickforge-git-branch-inline`),v=u?e.querySelector(`message-editor`)?.parentElement?.querySelector(`.ml-auto.items-center`):null,y=c?.()?.trim()||void 0,b={gitBranch:y};if(!u)_?.remove(),h?.remove(),g?.remove();else if(y&&v){let e=`${$e}<span style="max-width: 8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">${Ye(y)}</span>`,t=`Git branch: ${y}`;if(_)_.dataset.quickforgeGitBranch!==y&&(_.innerHTML=e,_.dataset.quickforgeGitBranch=y),_.title=t,_.setAttribute(`aria-label`,t),Qe(_,l);else{let n=document.createElement(`span`);n.className=`quickforge-git-branch-inline`,n.dataset.quickforgeGitBranch=y,n.title=t,n.setAttribute(`aria-label`,t),n.innerHTML=e,n.style.cssText=[`display: inline-flex`,`align-items: center`,`gap: 0.25rem`,`max-width: 10rem`,`color: hsl(var(--muted-foreground))`,`font-size: 12px`,`line-height: 1`,`font-weight: 500`].join(`;`),Qe(n,l),v.prepend(n)}}else _?.remove();if(!f)return u&&(h?.remove(),g?.remove()),d?.(b),b;let x=s?.(),S=m.length>0,C=x?Je(x,f):S?Pe(t(),m,f,i?.()??[],a?.()):{contextWindow:f,usedTokens:0,totalTokens:0,inputTokens:0,estimatedInputTokens:0,inputTokenSource:`estimated`,reservedOutputTokens:0,percent:0,color:`hsl(142 72% 45%)`},w=C.contextWindow||f,T=!!C.isCompacted||m!==p,E=Ze({usage:C,contextWindow:w,serverCalculated:!!x,compacted:T});if(b.context={percent:C.percent,color:C.color,label:`${C.percent}% · ${J(C.totalTokens)} / ${J(w)} tokens`,title:E},d?.(b),!u||!v)return h?.remove(),g?.remove(),b;let D=Math.min(100,Math.max(0,C.percent)),O=`conic-gradient(${C.color} ${D*3.6}deg, rgb(229 231 235) 0deg)`,k=h??document.createElement(`span`);k.className=`quickforge-context-usage`,k.title=E,k.setAttribute(`aria-label`,E),k.style.cssText=[`position: relative`,`display: inline-flex`,`width: 14px`,`height: 14px`,`flex: 0 0 auto`,`border-radius: 9999px`,`background: ${O}`,`vertical-align: middle`,`box-shadow: 0 0 0 1px rgb(0 0 0 / 0.06)`].join(`;`);let A=k.firstElementChild;A||(A=document.createElement(`span`),k.append(A)),A.style.cssText=[`position: absolute`,`inset: 3px`,`border-radius: 9999px`,`background: hsl(var(--background))`].join(`;`);let j=k.nextElementSibling;return j?.classList.contains(`quickforge-context-usage-label`)||(j=document.createElement(`span`),j.className=`quickforge-context-usage-label`,j.style.cssText=`color: hsl(var(--muted-foreground)); font-size: 12px; line-height: 1;`),j.textContent=`${C.percent}%`,j.title=E,j.setAttribute(`aria-label`,E),h?k.nextElementSibling!==j&&k.after(j):(v.prepend(j),v.prepend(k)),b}}}var tt=`<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect width="14" height="14" x="8" y="8" rx="2" ry="2"/><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"/></svg>`,nt=`<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M20 6 9 17l-5-5"/></svg>`,rt=`<svg xmlns="http://www.w3.org/2000/svg" width="17" height="17" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M9 14 4 9l5-5"/><path d="M4 9h10.5a5.5 5.5 0 0 1 0 11H11"/></svg>`,it=`<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="18" r="3"/><circle cx="6" cy="6" r="3"/><circle cx="18" cy="6" r="3"/><path d="M18 9v1a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2V9"/><path d="M12 12v3"/></svg>`,at=`<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><polygon points="6 3 20 12 6 21 6 3"/></svg>`,ot=`<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M21 2v6h-6"/><path d="M3 12a9 9 0 0 1 15.36-5.64L21 9"/><path d="M3 22v-6h6"/><path d="M21 12a9 9 0 0 1-15.36 5.64L3 15"/></svg>`,st=`<svg class="quickforge-plan-mode-icon" xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4 6h1"/><path d="M4 12h1"/><path d="M4 18h1"/><path d="M9 6h11"/><path d="M9 12h11"/><path d="M9 18h11"/></svg>`,ct=`<svg class="quickforge-plan-remove-icon" xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>`,lt=`<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 5v14"/><path d="M5 12h14"/></svg>`,ut=`<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m21.44 11.05-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48"/></svg>`,dt=`<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M7.5 4.5h5a1.5 1.5 0 0 1 1.5 1.5v2h1a2.5 2.5 0 0 1 0 5h-1v2a1.5 1.5 0 0 1-1.5 1.5h-2v1a2.5 2.5 0 0 1-5 0v-1h-2A1.5 1.5 0 0 1 2 15.5v-3h1a2 2 0 1 0 0-4H2v-2A1.5 1.5 0 0 1 3.5 5h2v-1a2.5 2.5 0 0 1 5 0v.5Z"/></svg>`,ft=`<svg viewBox="0 0 20 20" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.65" stroke-linecap="round" stroke-linejoin="round"><path d="M5.4 2.8h6.1L15.8 7v10.2H5.4z"/><path d="M11.4 2.9V7h4.1"/><path d="M7.6 10.2h5"/><path d="M7.6 13h4.3"/></svg>`,pt=`<svg viewBox="0 0 20 20" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.65" stroke-linecap="round" stroke-linejoin="round"><rect x="3.4" y="4" width="13.2" height="12.2" rx="1.5"/><path d="M3.4 8h13.2"/><path d="M7.8 4v12.2"/><path d="M12.2 4v12.2"/><path d="M3.4 12h13.2"/></svg>`,mt=`<svg viewBox="0 0 20 20" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.65" stroke-linecap="round" stroke-linejoin="round"><path d="M3 4.2h14"/><rect x="4.2" y="4.2" width="11.6" height="8.4" rx="1.2"/><path d="M10 12.6v3.2"/><path d="m7.2 17 2.8-1.2 2.8 1.2"/><path d="M7.1 9.5 9 7.7l1.5 1.3 2.4-2.5"/></svg>`;function ht(e,t,n){let r=f(`copied`),i=Number(e.dataset.quickforgeCopyFeedbackTimer);i&&window.clearTimeout(i),Ce(e,nt),e.title=r,e.setAttribute(`aria-label`,r),e.style.color=`rgb(5 150 105)`;let a=window.setTimeout(()=>{Ce(e,n),e.title=t,e.setAttribute(`aria-label`,t),e.style.color=``,delete e.dataset.quickforgeCopyFeedbackTimer},1200);e.dataset.quickforgeCopyFeedbackTimer=String(a)}function gt(e,t,n,r){let i=document.createElement(`button`);return i.type=`button`,i.dataset.quickforgeAction=e,i.title=t,i.setAttribute(`aria-label`,t),Ce(i,n),i.className=`pointer-events-auto inline-flex size-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-transparent hover:text-foreground disabled:cursor-not-allowed disabled:opacity-40`,i.onclick=e=>{e.stopPropagation(),r(i)},i}function _t(e){e.querySelectorAll(`.quickforge-rollback-popover`).forEach(e=>{e.quickforgeCleanup?.(),(e.closest(`.quickforge-rollback-action`)?.querySelector(`button[data-quickforge-action="rollback"]`))?.setAttribute(`aria-expanded`,`false`),e.remove()})}function vt(e){let{panel:t,button:n,messageIndex:r,title:i,description:a,onConfirm:o}=e,s=n.closest(`.quickforge-rollback-action`);if(!s||n.disabled)return;if(s.querySelector(`.quickforge-rollback-popover`)){_t(t);return}_t(t);let c=document.createElement(`div`);c.className=`quickforge-rollback-popover`,c.setAttribute(`role`,`dialog`),c.setAttribute(`aria-label`,i),c.tabIndex=-1;let l=document.createElement(`div`);l.className=`quickforge-rollback-popover-arrow`;let u=document.createElement(`div`);u.className=`quickforge-rollback-popover-title`,u.textContent=i;let d=document.createElement(`div`);d.className=`quickforge-rollback-popover-description`,d.textContent=a;let p=document.createElement(`div`);p.className=`quickforge-rollback-popover-footer`;let m=document.createElement(`button`);m.type=`button`,m.className=`quickforge-rollback-popover-cancel`,m.textContent=f(`cancel`);let h=document.createElement(`button`);h.type=`button`,h.className=`quickforge-rollback-popover-confirm`,h.textContent=f(`confirmRollback`),p.append(m,h),c.append(l,u,d,p);let g=()=>_t(t),_=e=>{let t=e.target;!t||c.contains(t)||n.contains(t)||g()},v=e=>{e.key===`Escape`&&(e.preventDefault(),g())};c.quickforgeCleanup=()=>{document.removeEventListener(`pointerdown`,_,!0),document.removeEventListener(`keydown`,v)},c.addEventListener(`pointerdown`,e=>e.stopPropagation()),c.addEventListener(`click`,e=>e.stopPropagation()),m.addEventListener(`click`,g),h.addEventListener(`click`,async()=>{h.disabled=!0,m.disabled=!0,h.textContent=f(`rollingBack`);try{await o(r)}finally{g()}}),s.append(c),n.setAttribute(`aria-expanded`,`true`),document.addEventListener(`pointerdown`,_,!0),document.addEventListener(`keydown`,v),window.requestAnimationFrame(()=>h.focus())}function yt(e){let t=document.createElement(`span`);t.className=`quickforge-rollback-action`;let n=gt(`rollback`,f(`rollback`),rt,t=>{vt({panel:e.panel,button:t,messageIndex:e.messageIndex,title:e.title,description:e.description,onConfirm:e.onConfirm})});return n.disabled=e.isDisabled,n.setAttribute(`aria-haspopup`,`dialog`),n.setAttribute(`aria-expanded`,`false`),t.append(n),t}var bt=new Set([`bash`,`sh`,`shell`,`zsh`,`fish`,`cmd`,`bat`,`batch`,`powershell`,`ps1`,`terminal`,`console`]),xt=/\b(rm\s+-rf|sudo|chmod\b|chown\b|npm\s+publish|pnpm\s+publish|yarn\s+publish|git\s+push|curl\b[^\n|;]*\|\s*(sh|bash)|wget\b[^\n|;]*\|\s*(sh|bash))\b/i,St=/<\s*(script|foreignObject)\b|\son[a-z]+\s*=|javascript\s*:/i;function Ct(e){return e.role===`user`||e.role===`user-with-attachments`||e.role===`assistant`}function wt(e){return e.role===`user`||e.role===`user-with-attachments`}function Tt(e){return e.role===`assistant`?p(e).trim().length>0:!1}function Et(e){return e.querySelector(`message-list`)}function Dt(e){let t=Et(e);return t?Array.from(t.querySelectorAll(`user-message, assistant-message`)).filter(e=>e.closest(`message-list`)===t):[]}function Ot(e){if(typeof e.getDecodedCode==`function`)try{return e.getDecodedCode()}catch{}let t=typeof e.code==`string`?e.code:e.getAttribute(`code`)??``;if(!t)return``;try{return decodeURIComponent(escape(window.atob(t)))}catch{return t}}function kt(e){return e.replace(/\r\n/g,`
167
167
  `).split(`
168
168
  `).map(e=>e.replace(/^\s*\$\s+/,``).replace(/^\s*>\s+/,``).replace(/^\s*PS\s+[^>\n]+>\s+/i,``)).join(`
169
169
  `).trim()}function At(e){return e.split(`
170
- `).map(e=>e.trim()).filter(Boolean).length}function jt(e){let t=String(e.language??e.getAttribute(`language`)??``).trim().toLowerCase();return bt.has(t)}function Mt(e){return String(e.language??e.getAttribute(`language`)??``).trim().toLowerCase()===`svg`}function Nt(e){let t=e.trim();return/^<svg[\s>]/i.test(t)&&/<\/svg>\s*$/i.test(t)&&!St.test(t)}function Pt(e){return`data:image/svg+xml;charset=utf-8,${encodeURIComponent(e)}`}function Ft(){let e=document.querySelector(`.quickforge-svg-code-lightbox`);e?.quickforgeCleanup?.(),e?.remove()}function It(e){Ft();let t=document.createElement(`div`);t.className=`quickforge-svg-code-lightbox`,t.setAttribute(`role`,`dialog`),t.setAttribute(`aria-modal`,`true`),t.setAttribute(`aria-label`,`SVG preview`);let n=document.createElement(`img`);n.alt=`SVG preview`,n.src=e,n.addEventListener(`click`,e=>e.stopPropagation()),t.append(n);let r=()=>Ft(),i=e=>{e.key===`Escape`&&r()};t.quickforgeCleanup=()=>document.removeEventListener(`keydown`,i),t.addEventListener(`click`,r),document.addEventListener(`keydown`,i),document.body.append(t)}function Lt(e,t,n){let r=new Blob([t],{type:n}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=e,document.body.appendChild(a),a.click(),a.remove(),URL.revokeObjectURL(i)}function Rt(e){let t=0;for(let n=0;n<e.length;n++)t=Math.imul(31,t)+e.charCodeAt(n)|0;return`${e.length}:${t}`}function zt(e){e.nextElementSibling instanceof HTMLElement&&e.nextElementSibling.dataset.quickforgeSvgPreview===`true`&&e.nextElementSibling.remove(),e.querySelector(`[data-quickforge-svg-preview="true"]`)?.remove(),e.classList.remove(`quickforge-svg-code-block`),e.querySelector(`copy-button[data-quickforge-svg-original-copy="true"]`)?.removeAttribute(`hidden`),e.querySelector(`copy-button[data-quickforge-svg-original-copy="true"]`)?.removeAttribute(`data-quickforge-svg-original-copy`),e.querySelector(`[data-quickforge-svg-toolbar="true"]`)?.remove();let t=e.querySelector(`pre`)?.parentElement;t instanceof HTMLElement&&(t.hidden=!1),delete e.dataset.quickforgeSvgPreviewSource,delete e.dataset.quickforgeSvgMode}function Bt(e,t){let n=e.querySelector(`[data-quickforge-svg-preview="true"]`),r=e.querySelector(`:scope > div > div:first-child`),i=e.querySelector(`pre`)?.parentElement;e.dataset.quickforgeSvgMode=t,n&&(n.hidden=t!==`preview`),r&&r.classList.toggle(`quickforge-svg-code-toolbar-floating`,t===`preview`),i instanceof HTMLElement&&(i.hidden=t===`preview`)}function Vt(e,t,n){let r=document.createElement(`button`);return r.type=`button`,r.dataset.quickforgeAction=e,r.className=`quickforge-svg-code-menu-item`,r.title=t,r.setAttribute(`aria-label`,t),r.setAttribute(`role`,`menuitem`),Ce(r,n),r}function Ht(e=document,t){e.querySelectorAll(`.quickforge-svg-code-menu[open]`).forEach(e=>{e!==t&&(e.open=!1)})}var Ut=!1;function Wt(){Ut||(Ut=!0,document.addEventListener(`pointerdown`,e=>{e.target?.closest(`.quickforge-svg-code-menu`)||Ht(document)},!0),document.addEventListener(`keydown`,e=>{e.key===`Escape`&&Ht(document)}))}function Gt(e,t){Wt();let n=e.querySelector(`:scope > div > div:first-child`),r=n?.querySelector(`copy-button`);if(!n||!r)return;let i=n.querySelector(`[data-quickforge-svg-toolbar="true"]`);if(!i){i=document.createElement(`div`),i.dataset.quickforgeSvgToolbar=`true`,i.className=`quickforge-svg-code-toolbar`;let e=document.createElement(`details`);e.className=`quickforge-svg-code-menu`;let t=document.createElement(`summary`);t.className=`quickforge-svg-code-menu-trigger`,t.title=f(`moreActions`),t.setAttribute(`aria-label`,f(`moreActions`)),t.textContent=`⋯`;let n=document.createElement(`div`);n.className=`quickforge-svg-code-menu-content`,n.setAttribute(`role`,`menu`);let a=Vt(`svg-preview-mode`,f(`svgPreviewMode`),`<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M2 12s3-7 10-7 10 7 10 7-3 7-10 7-10-7-10-7Z"/><circle cx="12" cy="12" r="3"/></svg>`),o=Vt(`svg-source-mode`,f(`svgSourceMode`),`<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m16 18 6-6-6-6"/><path d="m8 6-6 6 6 6"/></svg>`),s=Vt(`copy-svg-code`,f(`copySvgSource`),tt),c=Vt(`download-svg-code`,f(`downloadSvg`),`<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><path d="M7 10l5 5 5-5"/><path d="M12 15V3"/></svg>`);n.append(a,o,s,c),r.before(i),r.dataset.quickforgeSvgOriginalCopy=`true`,r.setAttribute(`hidden`,``),e.append(t,n),i.append(e)}let a=i.querySelector(`.quickforge-svg-code-menu`),o=i.querySelector(`[data-quickforge-action="svg-preview-mode"]`),s=i.querySelector(`[data-quickforge-action="svg-source-mode"]`),c=i.querySelector(`[data-quickforge-action="copy-svg-code"]`),l=i.querySelector(`[data-quickforge-action="download-svg-code"]`),u=()=>{a&&(a.open=!1)};a&&!a.dataset.quickforgeSvgMenuBound&&(a.dataset.quickforgeSvgMenuBound=`true`,a.addEventListener(`toggle`,()=>{a.open&&Ht(e.closest(`markdown-block`)??document,a)})),o&&(o.onclick=()=>{Bt(e,`preview`),u()}),s&&(s.onclick=()=>{Bt(e,`source`),u()}),c&&(c.onclick=async()=>{await m(t),ht(c,f(`copySvgSource`),tt)}),l&&(l.onclick=()=>{Lt(`quickforge-svg-${Date.now()}.svg`,t,`image/svg+xml;charset=utf-8`),u()})}function Kt(e,t){e.querySelectorAll(`assistant-message markdown-block code-block`).forEach(e=>{if(!Mt(e)){zt(e);return}if(t)return;let n=Ot(e).trim();if(!n||!Nt(n)){zt(e);return}let r=Rt(n);if(e.querySelector(`[data-quickforge-svg-preview="true"]`)&&e.dataset.quickforgeSvgPreviewSource===r){Gt(e,n),Bt(e,e.dataset.quickforgeSvgMode===`source`?`source`:`preview`);return}let i=e.querySelector(`:scope > div > div:first-child`);if(!i)return;zt(e);let a=document.createElement(`div`);e.classList.add(`quickforge-svg-code-block`),a.dataset.quickforgeSvgPreview=`true`,a.className=`quickforge-svg-code-preview`,a.setAttribute(`aria-label`,`SVG preview`);let o=document.createElement(`img`);o.alt=`SVG preview`,o.src=Pt(n),o.title=f(`svgEnlargePreview`),o.addEventListener(`click`,()=>It(o.src)),a.replaceChildren(o),i.after(a),Gt(e,n),e.dataset.quickforgeSvgPreviewSource=r,Bt(e,e.dataset.quickforgeSvgMode===`source`?`source`:`preview`)})}function qt(e,t){e.querySelectorAll(`assistant-message markdown-block code-block`).forEach(e=>{let n=e.querySelector(`[data-quickforge-action="execute-markdown-command"]`);if(!jt(e)){n?.remove(),delete e.dataset.quickforgeCommand;return}let r;if(n&&e.dataset.quickforgeCommand!==void 0){if(n.disabled===t)return;r=e.dataset.quickforgeCommand}else r=kt(Ot(e));if(!r){n?.remove(),delete e.dataset.quickforgeCommand;return}e.dataset.quickforgeCommand=r;let i=f(`executeInTerminal`),a=n??gt(`execute-markdown-command`,i,at,()=>{let t=kt(Ot(e));t&&window.dispatchEvent(new CustomEvent(`quickforge:execute-markdown-command`,{detail:{command:t,confirm:At(t)>1,dangerous:xt.test(t)}}))});if(a.title=i,a.setAttribute(`aria-label`,i),a.disabled=t,a.className=`pointer-events-auto inline-flex size-8 items-center justify-center rounded-md text-emerald-600 transition-colors hover:bg-emerald-500/10 hover:text-emerald-700 disabled:cursor-not-allowed disabled:opacity-40 dark:text-emerald-400 dark:hover:text-emerald-300`,!n){let t=e.querySelector(`:scope > div > div:first-child`),n=t?.querySelector(`copy-button`);if(t&&n){let e=document.createElement(`div`);e.className=`flex items-center gap-1`,n.before(e),e.appendChild(n),e.appendChild(a)}}})}function Jt(e,t,n,r){let i=Dt(e),a=0;for(let e=0;e<t.length;e++)if(Ct(t[e])){if(e===n){let e=i[a];if(e){r.nextElementSibling!==e&&e.before(r);return}break}a+=1}let o=e.querySelector(`message-list`);o&&o.firstElementChild!==r&&o.prepend(r)}function Yt(e){let t=e,n=t?.role===`assistant`?h(t):p(t);return(n.match(/<compact_summary>\s*([\s\S]*?)\s*<\/compact_summary>/i)?.[1]??n).trim()}function Xt(e,t,n=!1){let r=e.querySelector(`.quickforge-context-compaction-details`),i=e.querySelector(`.quickforge-context-compaction-summary`),a=e.querySelector(`.quickforge-context-compaction-toggle-label`),o=e.querySelector(`[data-quickforge-action="copy-compact-summary"]`);r&&(r.open=n);let s=()=>{a&&r&&(a.textContent=r.open?f(`contextCompactedHideSummary`):f(`contextCompactedViewSummary`))};i&&!i.dataset.quickforgeCompactionBound&&(i.dataset.quickforgeCompactionBound=`true`,i.addEventListener(`click`,e=>{e.preventDefault(),e.stopPropagation(),r&&(r.open=!r.open,s())})),r&&!r.dataset.quickforgeCompactionBound&&(r.dataset.quickforgeCompactionBound=`true`,r.addEventListener(`toggle`,s)),s(),o&&(o.onclick=async e=>{e.preventDefault(),e.stopPropagation(),await m(t),ht(o,f(`contextCompactedCopySummary`),tt)})}function Zt(e){let{panel:t,getMessages:n,getContextCompaction:r}=e,i=r(),a=n(),o=t.querySelector(`.quickforge-context-compaction-notice`);if(!i||a.length===0){o?.remove();return}let s=Math.min(a.length,Math.max(0,Number(i.compactedUpToIndex)||0));if(s<=0){o?.remove();return}let c=i.summaryMessage?Yt(i.summaryMessage):``,l=o?.querySelector(`.quickforge-context-compaction-details`)?.open??!1,u=o??document.createElement(`div`),d=u.dataset.summaryText??``,p=u.dataset.hasSummary===`true`,m=!o||d!==c||p!==!!c;u.className=`quickforge-context-compaction-notice`,u.dataset.tailStart=String(s),u.dataset.summaryText=c,u.dataset.hasSummary=String(!!c),u.title=f(`contextCompactedTooltip`),u.setAttribute(`aria-label`,f(`contextCompactedTooltip`)),m&&(u.innerHTML=c?`
170
+ `).map(e=>e.trim()).filter(Boolean).length}function jt(e){let t=String(e.language??e.getAttribute(`language`)??``).trim().toLowerCase();return bt.has(t)}function Mt(e){return String(e.language??e.getAttribute(`language`)??``).trim().toLowerCase()===`svg`}function Nt(e){let t=e.trim();return/^<svg[\s>]/i.test(t)&&/<\/svg>\s*$/i.test(t)&&!St.test(t)}function Pt(e){return`data:image/svg+xml;charset=utf-8,${encodeURIComponent(e)}`}function Ft(){let e=document.querySelector(`.quickforge-svg-code-lightbox`);e?.quickforgeCleanup?.(),e?.remove()}function It(e){Ft();let t=document.createElement(`div`);t.className=`quickforge-svg-code-lightbox`,t.setAttribute(`role`,`dialog`),t.setAttribute(`aria-modal`,`true`),t.setAttribute(`aria-label`,`SVG preview`);let n=document.createElement(`img`);n.alt=`SVG preview`,n.src=e,n.addEventListener(`click`,e=>e.stopPropagation()),t.append(n);let r=()=>Ft(),i=e=>{e.key===`Escape`&&r()};t.quickforgeCleanup=()=>document.removeEventListener(`keydown`,i),t.addEventListener(`click`,r),document.addEventListener(`keydown`,i),document.body.append(t)}function Lt(e,t,n){let r=new Blob([t],{type:n}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=e,document.body.appendChild(a),a.click(),a.remove(),URL.revokeObjectURL(i)}function Rt(e){let t=0;for(let n=0;n<e.length;n++)t=Math.imul(31,t)+e.charCodeAt(n)|0;return`${e.length}:${t}`}function zt(e){e.nextElementSibling instanceof HTMLElement&&e.nextElementSibling.dataset.quickforgeSvgPreview===`true`&&e.nextElementSibling.remove(),e.querySelector(`[data-quickforge-svg-preview="true"]`)?.remove(),e.classList.remove(`quickforge-svg-code-block`),e.querySelector(`copy-button[data-quickforge-svg-original-copy="true"]`)?.removeAttribute(`hidden`),e.querySelector(`copy-button[data-quickforge-svg-original-copy="true"]`)?.removeAttribute(`data-quickforge-svg-original-copy`),e.querySelector(`[data-quickforge-svg-toolbar="true"]`)?.remove();let t=e.querySelector(`pre`)?.parentElement;t instanceof HTMLElement&&(t.hidden=!1),delete e.dataset.quickforgeSvgPreviewSource,delete e.dataset.quickforgeSvgMode}function Bt(e,t){let n=e.querySelector(`[data-quickforge-svg-preview="true"]`),r=e.querySelector(`:scope > div > div:first-child`),i=e.querySelector(`pre`)?.parentElement;e.dataset.quickforgeSvgMode=t,n&&(n.hidden=t!==`preview`),r&&r.classList.toggle(`quickforge-svg-code-toolbar-floating`,t===`preview`),i instanceof HTMLElement&&(i.hidden=t===`preview`)}function Vt(e,t,n){let r=document.createElement(`button`);return r.type=`button`,r.dataset.quickforgeAction=e,r.className=`quickforge-svg-code-menu-item`,r.title=t,r.setAttribute(`aria-label`,t),r.setAttribute(`role`,`menuitem`),Ce(r,n),r}function Ht(e=document,t){e.querySelectorAll(`.quickforge-svg-code-menu[open]`).forEach(e=>{e!==t&&(e.open=!1)})}var Ut=!1;function Wt(){Ut||(Ut=!0,document.addEventListener(`pointerdown`,e=>{e.target?.closest(`.quickforge-svg-code-menu`)||Ht(document)},!0),document.addEventListener(`keydown`,e=>{e.key===`Escape`&&Ht(document)}))}function Gt(e,t){Wt();let n=e.querySelector(`:scope > div > div:first-child`),r=n?.querySelector(`copy-button`);if(!n||!r)return;let i=n.querySelector(`[data-quickforge-svg-toolbar="true"]`);if(!i){i=document.createElement(`div`),i.dataset.quickforgeSvgToolbar=`true`,i.className=`quickforge-svg-code-toolbar`;let e=document.createElement(`details`);e.className=`quickforge-svg-code-menu`;let t=document.createElement(`summary`);t.className=`quickforge-svg-code-menu-trigger`,t.title=f(`moreActions`),t.setAttribute(`aria-label`,f(`moreActions`)),t.textContent=`⋯`;let n=document.createElement(`div`);n.className=`quickforge-svg-code-menu-content`,n.setAttribute(`role`,`menu`);let a=Vt(`svg-preview-mode`,f(`svgPreviewMode`),`<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M2 12s3-7 10-7 10 7 10 7-3 7-10 7-10-7-10-7Z"/><circle cx="12" cy="12" r="3"/></svg>`),o=Vt(`svg-source-mode`,f(`svgSourceMode`),`<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m16 18 6-6-6-6"/><path d="m8 6-6 6 6 6"/></svg>`),s=Vt(`copy-svg-code`,f(`copySvgSource`),tt),c=Vt(`download-svg-code`,f(`downloadSvg`),`<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><path d="M7 10l5 5 5-5"/><path d="M12 15V3"/></svg>`);n.append(a,o,s,c),r.before(i),r.dataset.quickforgeSvgOriginalCopy=`true`,r.setAttribute(`hidden`,``),e.append(t,n),i.append(e)}let a=i.querySelector(`.quickforge-svg-code-menu`),o=i.querySelector(`[data-quickforge-action="svg-preview-mode"]`),s=i.querySelector(`[data-quickforge-action="svg-source-mode"]`),c=i.querySelector(`[data-quickforge-action="copy-svg-code"]`),l=i.querySelector(`[data-quickforge-action="download-svg-code"]`),u=()=>{a&&(a.open=!1)};a&&!a.dataset.quickforgeSvgMenuBound&&(a.dataset.quickforgeSvgMenuBound=`true`,a.addEventListener(`toggle`,()=>{a.open&&Ht(e.closest(`markdown-block`)??document,a)})),o&&(o.onclick=()=>{Bt(e,`preview`),u()}),s&&(s.onclick=()=>{Bt(e,`source`),u()}),c&&(c.onclick=async()=>{await _(t),ht(c,f(`copySvgSource`),tt)}),l&&(l.onclick=()=>{Lt(`quickforge-svg-${Date.now()}.svg`,t,`image/svg+xml;charset=utf-8`),u()})}function Kt(e,t){e.querySelectorAll(`assistant-message markdown-block code-block`).forEach(e=>{if(!Mt(e)){zt(e);return}if(t)return;let n=Ot(e).trim();if(!n||!Nt(n)){zt(e);return}let r=Rt(n);if(e.querySelector(`[data-quickforge-svg-preview="true"]`)&&e.dataset.quickforgeSvgPreviewSource===r){Gt(e,n),Bt(e,e.dataset.quickforgeSvgMode===`source`?`source`:`preview`);return}let i=e.querySelector(`:scope > div > div:first-child`);if(!i)return;zt(e);let a=document.createElement(`div`);e.classList.add(`quickforge-svg-code-block`),a.dataset.quickforgeSvgPreview=`true`,a.className=`quickforge-svg-code-preview`,a.setAttribute(`aria-label`,`SVG preview`);let o=document.createElement(`img`);o.alt=`SVG preview`,o.src=Pt(n),o.title=f(`svgEnlargePreview`),o.addEventListener(`click`,()=>It(o.src)),a.replaceChildren(o),i.after(a),Gt(e,n),e.dataset.quickforgeSvgPreviewSource=r,Bt(e,e.dataset.quickforgeSvgMode===`source`?`source`:`preview`)})}function qt(e,t){e.querySelectorAll(`assistant-message markdown-block code-block`).forEach(e=>{let n=e.querySelector(`[data-quickforge-action="execute-markdown-command"]`);if(!jt(e)){n?.remove(),delete e.dataset.quickforgeCommand;return}let r;if(n&&e.dataset.quickforgeCommand!==void 0){if(n.disabled===t)return;r=e.dataset.quickforgeCommand}else r=kt(Ot(e));if(!r){n?.remove(),delete e.dataset.quickforgeCommand;return}e.dataset.quickforgeCommand=r;let i=f(`executeInTerminal`),a=n??gt(`execute-markdown-command`,i,at,()=>{let t=kt(Ot(e));t&&window.dispatchEvent(new CustomEvent(`quickforge:execute-markdown-command`,{detail:{command:t,confirm:At(t)>1,dangerous:xt.test(t)}}))});if(a.title=i,a.setAttribute(`aria-label`,i),a.disabled=t,a.className=`pointer-events-auto inline-flex size-8 items-center justify-center rounded-md text-emerald-600 transition-colors hover:bg-emerald-500/10 hover:text-emerald-700 disabled:cursor-not-allowed disabled:opacity-40 dark:text-emerald-400 dark:hover:text-emerald-300`,!n){let t=e.querySelector(`:scope > div > div:first-child`),n=t?.querySelector(`copy-button`);if(t&&n){let e=document.createElement(`div`);e.className=`flex items-center gap-1`,n.before(e),e.appendChild(n),e.appendChild(a)}}})}function Jt(e,t,n,r){let i=Dt(e),a=0;for(let e=0;e<t.length;e++)if(Ct(t[e])){if(e===n){let e=i[a];if(e){r.nextElementSibling!==e&&e.before(r);return}break}a+=1}let o=e.querySelector(`message-list`);o&&o.firstElementChild!==r&&o.prepend(r)}function Yt(e){let t=e,n=t?.role===`assistant`?p(t):y(t);return(n.match(/<compact_summary>\s*([\s\S]*?)\s*<\/compact_summary>/i)?.[1]??n).trim()}function Xt(e,t,n=!1){let r=e.querySelector(`.quickforge-context-compaction-details`),i=e.querySelector(`.quickforge-context-compaction-summary`),a=e.querySelector(`.quickforge-context-compaction-toggle-label`),o=e.querySelector(`[data-quickforge-action="copy-compact-summary"]`);r&&(r.open=n);let s=()=>{a&&r&&(a.textContent=r.open?f(`contextCompactedHideSummary`):f(`contextCompactedViewSummary`))};i&&!i.dataset.quickforgeCompactionBound&&(i.dataset.quickforgeCompactionBound=`true`,i.addEventListener(`click`,e=>{e.preventDefault(),e.stopPropagation(),r&&(r.open=!r.open,s())})),r&&!r.dataset.quickforgeCompactionBound&&(r.dataset.quickforgeCompactionBound=`true`,r.addEventListener(`toggle`,s)),s(),o&&(o.onclick=async e=>{e.preventDefault(),e.stopPropagation(),await _(t),ht(o,f(`contextCompactedCopySummary`),tt)})}function Zt(e){let{panel:t,getMessages:n,getContextCompaction:r}=e,i=r(),a=n(),o=t.querySelector(`.quickforge-context-compaction-notice`);if(!i||a.length===0){o?.remove();return}let s=Math.min(a.length,Math.max(0,Number(i.compactedUpToIndex)||0));if(s<=0){o?.remove();return}let c=i.summaryMessage?Yt(i.summaryMessage):``,l=o?.querySelector(`.quickforge-context-compaction-details`)?.open??!1,u=o??document.createElement(`div`),d=u.dataset.summaryText??``,p=u.dataset.hasSummary===`true`,m=!o||d!==c||p!==!!c;u.className=`quickforge-context-compaction-notice`,u.dataset.tailStart=String(s),u.dataset.summaryText=c,u.dataset.hasSummary=String(!!c),u.title=f(`contextCompactedTooltip`),u.setAttribute(`aria-label`,f(`contextCompactedTooltip`)),m&&(u.innerHTML=c?`
171
171
  <details class="quickforge-context-compaction-details">
172
172
  <summary class="quickforge-context-compaction-summary">
173
173
  <div class="quickforge-context-compaction-line"></div>
@@ -200,7 +200,7 @@ import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{R as t,St as n}from"./
200
200
  <span></span>
201
201
  <span></span>
202
202
  </div>
203
- `),g.previousElementSibling!==m&&m.after(g),!0}function nn(e){let{panel:t,getMessages:n,isStreaming:r,onCopyAnswer:i,onRollbackFromMessage:a,onRetryFromMessage:o,onForkFromMessage:s,onOpenLocalFilePath:c,disableFork:l,readOnly:u=!1,enableTerminalCommandActions:d=!0,rollbackConfirmTitle:m=f(`rollbackConfirmTitle`),rollbackConfirmDescription:g=f(`rollbackConfirm`)}=e,_=n().map((e,t)=>({message:e,index:t})).filter(({message:e})=>e.role===`user`||e.role===`user-with-attachments`||e.role===`assistant`),v=(()=>{for(let e=_.length-1;e>=0;e--)if(_[e].message.role!==`assistant`)return _[e]})(),y=Dt(t),b=e=>{let t=f(`copy`);return gt(`copy`,t,tt,async n=>{let r=e();if(r)try{await i(r),ht(n,t,tt)}catch{}})};y.forEach((e,i)=>{let d=_[i];if(!d)return;e.classList.add(`group`,`relative`),e.classList.toggle(`quickforge-assistant-message`,d.message.role===`assistant`),e.classList.toggle(`quickforge-user-message`,d.message.role!==`assistant`),d.message.role===`assistant`&&c&&dn(e,d.message,c);let y=`quickforge-message-actions pointer-events-none mt-1 flex gap-1 opacity-0 transition-opacity group-hover:opacity-100 group-focus-within:opacity-100 ${d.message.role===`assistant`?`px-4 justify-start`:`mx-4 justify-end`}`,x=e.querySelector(`.quickforge-message-actions`);if(x?.dataset.quickforgeLayout===`message-bottom`){x.className=y,x.parentElement===e&&x!==e.lastElementChild&&e.append(x),u&&_t(t),x.querySelectorAll(`button[data-quickforge-action="rollback"], button[data-quickforge-action="retry"], button[data-quickforge-action="fork"]`).forEach(e=>{if(u){e.closest(`.quickforge-rollback-action`)?.remove(),e.remove();return}e.disabled=r()}),r()&&_t(t);let n=x.querySelector(`button[data-quickforge-action="retry"]`),i=!u&&v&&d.index===v.index&&d.message.role!==`assistant`;if(n&&!i)n.remove();else if(!n&&i){let e=gt(`retry`,f(`retry`),ot,()=>{o(d.index)});e.disabled=r(),x.append(e)}return}x?.remove();let S=document.createElement(`div`);if(S.dataset.quickforgeLayout=`message-bottom`,S.className=y,d.message.role===`assistant`){let e=h(d.message);if(!e)return;let t=b(()=>{let t=n()[d.index];return t?h(t):e});if(S.append(t),!u&&!l){let e=gt(`fork`,f(`forkConversation`),it,()=>{s(d.index)});e.disabled=r(),S.append(e)}}else{let e=p(d.message);if(e){let t=b(()=>{let t=n()[d.index];return t?p(t):e});S.append(t)}if(!u){let e=yt({panel:t,messageIndex:d.index,isDisabled:r(),title:m,description:g,onConfirm:a});S.append(e)}if(!u&&v&&d.index===v.index){let e=gt(`retry`,f(`retry`),ot,()=>{o(d.index)});e.disabled=r(),S.append(e)}}e.append(S)}),Ht(t),Jn(t,r()),Kt(t,r()),d?qt(t,r()):t.querySelectorAll(`[data-quickforge-action="execute-markdown-command"]`).forEach(e=>e.remove())}var rn=/[A-Za-z]:[\\/][^\s"'<>`]+|(?:\/Users|\/home|\/workspace|\/mnt|\/Volumes)\/[^\s"'<>`]+/g,an=new Set([`.`,`,`,`;`,`:`,`!`,`?`,`)`,`]`,`}`,`>`,`。`,`,`,`;`,`:`,`!`,`?`,`)`,`】`,`》`]),on=[`pre`,`code`,`a`,`button`,`textarea`,`input`,`select`,`thinking-block`,`tool-message`,`.quickforge-file-path-link`,`.quickforge-message-actions`,`.quickforge-process-group`,`.quickforge-approval-card`].join(`,`);function sn(e){let t=e.length;for(;t>0&&an.has(e[t-1]);)--t;return{path:e.slice(0,t),suffix:e.slice(t)}}function cn(e,t){let n=document.createElement(`button`);return n.type=`button`,n.className=`quickforge-file-path-link`,n.dataset.quickforgeFilePath=e,n.textContent=e,n.title=`Open file`,n.setAttribute(`aria-label`,`Open file ${e}`),n.onclick=n=>{n.preventDefault(),n.stopPropagation(),t(e)},n}function ln(e){let t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_TEXT,{acceptNode(e){let t=e.textContent??``;if(!rn.test(t))return NodeFilter.FILTER_REJECT;rn.lastIndex=0;let n=e.parentElement;return!n||n.closest(on)?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}}),r=n.nextNode();for(;r;)t.push(r),r=n.nextNode();return t}function un(e,t){let n=e.textContent??``;rn.lastIndex=0;let r,i=0,a=document.createDocumentFragment(),o=!1;for(;r=rn.exec(n);){let e=r[0],{path:s,suffix:c}=sn(e);if(!s)continue;let l=r.index,u=l+e.length;l>i&&a.append(document.createTextNode(n.slice(i,l))),a.append(cn(s,t)),c&&a.append(document.createTextNode(c)),i=u,o=!0}o&&(i<n.length&&a.append(document.createTextNode(n.slice(i))),e.replaceWith(a))}function dn(e,t,n){let r=Array.from(e.querySelectorAll(`markdown-block`)),i=r.reduce((e,t)=>e+(t.textContent?.length??0),0),a=h(t).length,o=`${String(t.timestamp??``)}:${a}:${r.length}:${i}`;e.dataset.quickforgeLocalPathSignature!==o&&(r.forEach(e=>{ln(e).forEach(e=>un(e,n))}),e.dataset.quickforgeLocalPathSignature=o)}var fn=`.quickforge-process-group`,Y=`.quickforge-process-body`,pn=`thinking-block, tool-message, streaming-message-container`,mn=`thinking-block, tool-message, markdown-block, streaming-message-container`,hn=`data-quickforge-process-final-summary`,gn=`data-quickforge-process-folded`,_n=500,vn=new WeakMap;function yn(e){let t=vn.get(e);return t||(t=new Map,vn.set(e,t)),t}function bn(e,t,n){let r=yn(e);if(r.set(t,n),r.size<=_n)return;let i=r.keys().next().value;i&&r.delete(i)}function xn(e,t){return`turn:${t}:started:${Tn(e[0]?.message?.timestamp)??`unknown`}`}function Sn(e,t,n){let r=t.dataset.quickforgeProcessKey;t.dataset.quickforgeProcessKey=n;let i=yn(e).get(n);if(i!==void 0){t.dataset.expanded=String(i);return}t.dataset.expanded=r===n&&t.dataset.expanded===`true`?`true`:`false`}function Cn(e){return!!(e&&typeof e==`object`&&!Array.isArray(e))}function wn(e){return typeof e==`number`&&Number.isFinite(e)?e:void 0}function Tn(e){if(typeof e==`number`&&Number.isFinite(e))return e;if(typeof e==`string`){let t=e.trim();if(!t)return;let n=Number(t);if(Number.isFinite(n))return n;let r=Date.parse(t);return Number.isNaN(r)?void 0:r}}function En(e){if(!Cn(e))return;let t=e.details;if(!Cn(t))return;let n=t.quickforgeTiming;if(Cn(n))return{startedAt:wn(n.startedAt),finishedAt:wn(n.finishedAt),durationMs:wn(n.durationMs)}}function Dn(e){let t=En(e.result);if(t?.finishedAt!==void 0)return t.finishedAt;if(t?.startedAt!==void 0&&t.durationMs!==void 0)return t.startedAt+t.durationMs}function On(e){return En(e.result)?.startedAt}function kn(e){if(e===void 0||e<1e3)return``;let t=Math.max(1,Math.round(e/1e3)),n=Math.floor(t/60),r=t%60;return n>0?`${n}m ${r}s`:`${r}s`}function An(e,t,n,r){let i=r,a=[...e].reverse().find(e=>e.message?.stopReason)?.message?.stopReason,o=Array.from(t.querySelectorAll(`tool-message`)),s=[...e.map(e=>Tn(e.message?.timestamp)),...o.map(On)].filter(e=>e!==void 0),c=o.map(Dn).filter(e=>e!==void 0),l=s.length>0?Math.min(...s):void 0,u=c.length>0?Math.max(...c):void 0;if(i)u=Date.now();else{let e=Tn(n.dataset.quickforgeFinishedAt);e!==void 0&&e>0?u=e:(u??=Date.now(),n.dataset.quickforgeFinishedAt=String(u))}let d=l!==void 0&&u!==void 0?kn(Math.max(0,u-l)):``,p=f(a===`error`?`processFailed`:a===`aborted`?`processAborted`:i?`processing`:`processed`);return d?`${p} ${d}`:p}function jn(e){let t=e.querySelector(`${mn}, ${fn}`);return t?.closest(`.px-4.flex.flex-col`)??t?.parentElement??null}function Mn(){let e=document.createElement(`div`);e.className=`quickforge-process-group`,e.dataset.expanded=`false`;let t=document.createElement(`button`);t.type=`button`,t.className=`quickforge-process-summary`,t.innerHTML=`
203
+ `),g.previousElementSibling!==m&&m.after(g),!0}function nn(e){let{panel:t,getMessages:n,isStreaming:r,onCopyAnswer:i,onRollbackFromMessage:a,onRetryFromMessage:o,onForkFromMessage:s,onOpenLocalFilePath:c,disableFork:l,readOnly:u=!1,enableTerminalCommandActions:d=!0,rollbackConfirmTitle:m=f(`rollbackConfirmTitle`),rollbackConfirmDescription:h=f(`rollbackConfirm`)}=e,g=n().map((e,t)=>({message:e,index:t})).filter(({message:e})=>e.role===`user`||e.role===`user-with-attachments`||e.role===`assistant`),_=(()=>{for(let e=g.length-1;e>=0;e--)if(g[e].message.role!==`assistant`)return g[e]})(),v=Dt(t),b=e=>{let t=f(`copy`);return gt(`copy`,t,tt,async n=>{let r=e();if(r)try{await i(r),ht(n,t,tt)}catch{}})};v.forEach((e,i)=>{let d=g[i];if(!d)return;e.classList.add(`group`,`relative`),e.classList.toggle(`quickforge-assistant-message`,d.message.role===`assistant`),e.classList.toggle(`quickforge-user-message`,d.message.role!==`assistant`),d.message.role===`assistant`&&c&&dn(e,d.message,c);let v=`quickforge-message-actions pointer-events-none mt-1 flex gap-1 opacity-0 transition-opacity group-hover:opacity-100 group-focus-within:opacity-100 ${d.message.role===`assistant`?`px-4 justify-start`:`mx-4 justify-end`}`,x=e.querySelector(`.quickforge-message-actions`);if(x?.dataset.quickforgeLayout===`message-bottom`){x.className=v,x.parentElement===e&&x!==e.lastElementChild&&e.append(x),u&&_t(t),x.querySelectorAll(`button[data-quickforge-action="rollback"], button[data-quickforge-action="retry"], button[data-quickforge-action="fork"]`).forEach(e=>{if(u){e.closest(`.quickforge-rollback-action`)?.remove(),e.remove();return}e.disabled=r()}),r()&&_t(t);let n=x.querySelector(`button[data-quickforge-action="retry"]`),i=!u&&_&&d.index===_.index&&d.message.role!==`assistant`;if(n&&!i)n.remove();else if(!n&&i){let e=gt(`retry`,f(`retry`),ot,()=>{o(d.index)});e.disabled=r(),x.append(e)}return}x?.remove();let S=document.createElement(`div`);if(S.dataset.quickforgeLayout=`message-bottom`,S.className=v,d.message.role===`assistant`){let e=p(d.message);if(!e)return;let t=b(()=>{let t=n()[d.index];return t?p(t):e});if(S.append(t),!u&&!l){let e=gt(`fork`,f(`forkConversation`),it,()=>{s(d.index)});e.disabled=r(),S.append(e)}}else{let e=y(d.message);if(e){let t=b(()=>{let t=n()[d.index];return t?y(t):e});S.append(t)}if(!u){let e=yt({panel:t,messageIndex:d.index,isDisabled:r(),title:m,description:h,onConfirm:a});S.append(e)}if(!u&&_&&d.index===_.index){let e=gt(`retry`,f(`retry`),ot,()=>{o(d.index)});e.disabled=r(),S.append(e)}}e.append(S)}),Ht(t),Jn(t,r()),Kt(t,r()),d?qt(t,r()):t.querySelectorAll(`[data-quickforge-action="execute-markdown-command"]`).forEach(e=>e.remove())}var rn=/[A-Za-z]:[\\/][^\s"'<>`]+|(?:\/Users|\/home|\/workspace|\/mnt|\/Volumes)\/[^\s"'<>`]+/g,an=new Set([`.`,`,`,`;`,`:`,`!`,`?`,`)`,`]`,`}`,`>`,`。`,`,`,`;`,`:`,`!`,`?`,`)`,`】`,`》`]),on=[`pre`,`code`,`a`,`button`,`textarea`,`input`,`select`,`thinking-block`,`tool-message`,`.quickforge-file-path-link`,`.quickforge-message-actions`,`.quickforge-process-group`,`.quickforge-approval-card`].join(`,`);function sn(e){let t=e.length;for(;t>0&&an.has(e[t-1]);)--t;return{path:e.slice(0,t),suffix:e.slice(t)}}function cn(e,t){let n=document.createElement(`button`);return n.type=`button`,n.className=`quickforge-file-path-link`,n.dataset.quickforgeFilePath=e,n.textContent=e,n.title=`Open file`,n.setAttribute(`aria-label`,`Open file ${e}`),n.onclick=n=>{n.preventDefault(),n.stopPropagation(),t(e)},n}function ln(e){let t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_TEXT,{acceptNode(e){let t=e.textContent??``;if(!rn.test(t))return NodeFilter.FILTER_REJECT;rn.lastIndex=0;let n=e.parentElement;return!n||n.closest(on)?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}}),r=n.nextNode();for(;r;)t.push(r),r=n.nextNode();return t}function un(e,t){let n=e.textContent??``;rn.lastIndex=0;let r,i=0,a=document.createDocumentFragment(),o=!1;for(;r=rn.exec(n);){let e=r[0],{path:s,suffix:c}=sn(e);if(!s)continue;let l=r.index,u=l+e.length;l>i&&a.append(document.createTextNode(n.slice(i,l))),a.append(cn(s,t)),c&&a.append(document.createTextNode(c)),i=u,o=!0}o&&(i<n.length&&a.append(document.createTextNode(n.slice(i))),e.replaceWith(a))}function dn(e,t,n){let r=Array.from(e.querySelectorAll(`markdown-block`)),i=r.reduce((e,t)=>e+(t.textContent?.length??0),0),a=p(t).length,o=`${String(t.timestamp??``)}:${a}:${r.length}:${i}`;e.dataset.quickforgeLocalPathSignature!==o&&(r.forEach(e=>{ln(e).forEach(e=>un(e,n))}),e.dataset.quickforgeLocalPathSignature=o)}var fn=`.quickforge-process-group`,Y=`.quickforge-process-body`,pn=`thinking-block, tool-message, streaming-message-container`,mn=`thinking-block, tool-message, markdown-block, streaming-message-container`,hn=`data-quickforge-process-final-summary`,gn=`data-quickforge-process-folded`,_n=500,vn=new WeakMap;function yn(e){let t=vn.get(e);return t||(t=new Map,vn.set(e,t)),t}function bn(e,t,n){let r=yn(e);if(r.set(t,n),r.size<=_n)return;let i=r.keys().next().value;i&&r.delete(i)}function xn(e,t){return`turn:${t}:started:${Tn(e[0]?.message?.timestamp)??`unknown`}`}function Sn(e,t,n){let r=t.dataset.quickforgeProcessKey;t.dataset.quickforgeProcessKey=n;let i=yn(e).get(n);if(i!==void 0){t.dataset.expanded=String(i);return}t.dataset.expanded=r===n&&t.dataset.expanded===`true`?`true`:`false`}function Cn(e){return!!(e&&typeof e==`object`&&!Array.isArray(e))}function wn(e){return typeof e==`number`&&Number.isFinite(e)?e:void 0}function Tn(e){if(typeof e==`number`&&Number.isFinite(e))return e;if(typeof e==`string`){let t=e.trim();if(!t)return;let n=Number(t);if(Number.isFinite(n))return n;let r=Date.parse(t);return Number.isNaN(r)?void 0:r}}function En(e){if(!Cn(e))return;let t=e.details;if(!Cn(t))return;let n=t.quickforgeTiming;if(Cn(n))return{startedAt:wn(n.startedAt),finishedAt:wn(n.finishedAt),durationMs:wn(n.durationMs)}}function Dn(e){let t=En(e.result);if(t?.finishedAt!==void 0)return t.finishedAt;if(t?.startedAt!==void 0&&t.durationMs!==void 0)return t.startedAt+t.durationMs}function On(e){return En(e.result)?.startedAt}function kn(e){if(e===void 0||e<1e3)return``;let t=Math.max(1,Math.round(e/1e3)),n=Math.floor(t/60),r=t%60;return n>0?`${n}m ${r}s`:`${r}s`}function An(e,t,n,r){let i=r,a=[...e].reverse().find(e=>e.message?.stopReason)?.message?.stopReason,o=Array.from(t.querySelectorAll(`tool-message`)),s=[...e.map(e=>Tn(e.message?.timestamp)),...o.map(On)].filter(e=>e!==void 0),c=o.map(Dn).filter(e=>e!==void 0),l=s.length>0?Math.min(...s):void 0,u=c.length>0?Math.max(...c):void 0;if(i)u=Date.now();else{let e=Tn(n.dataset.quickforgeFinishedAt);e!==void 0&&e>0?u=e:(u??=Date.now(),n.dataset.quickforgeFinishedAt=String(u))}let d=l!==void 0&&u!==void 0?kn(Math.max(0,u-l)):``,p=f(a===`error`?`processFailed`:a===`aborted`?`processAborted`:i?`processing`:`processed`);return d?`${p} ${d}`:p}function jn(e){let t=e.querySelector(`${mn}, ${fn}`);return t?.closest(`.px-4.flex.flex-col`)??t?.parentElement??null}function Mn(){let e=document.createElement(`div`);e.className=`quickforge-process-group`,e.dataset.expanded=`false`;let t=document.createElement(`button`);t.type=`button`,t.className=`quickforge-process-summary`,t.innerHTML=`
204
204
  <span class="quickforge-process-label"></span>
205
205
  <span class="quickforge-process-chevron" aria-hidden="true">
206
206
  <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m9 18 6-6-6-6"/></svg>
@@ -218,13 +218,13 @@ import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{R as t,St as n}from"./
218
218
  `,i.querySelector(`.quickforge-agent-access-item-label`).textContent=ur(e),i.onpointerdown=t=>{t.preventDefault(),t.stopPropagation(),n(e)},i}function pr(e){let{panel:t,trigger:n,agentAccessMode:r,onAccessModeChange:i}=e;if(document.querySelector(`.quickforge-agent-access-menu`)){dr(t);return}$n(t),dr(t);let a=document.createElement(`div`);a.className=`quickforge-agent-access-menu`,a.setAttribute(`role`,`menu`),a.setAttribute(`aria-label`,f(`agentAccessMenuLabel`));let o=e=>{dr(t),e!==r&&i(e)};a.append(fr(`default`,r,o),fr(`full-access`,r,o));let s=()=>{let e=n.getBoundingClientRect(),t=Math.min(196,window.innerWidth-24);a.style.width=`${t}px`;let r=a.offsetHeight||96,i=Math.max(12,Math.min(e.left,window.innerWidth-t-12)),o=Math.max(12,e.top-r-8);a.style.left=`${i}px`,a.style.top=`${o}px`},c=e=>{if(e.type===`resize`||e.type===`scroll`){s();return}if(e instanceof KeyboardEvent){if(e.key!==`Escape`)return;e.preventDefault()}else{let t=e.target;if(a.contains(t)||n.contains(t))return}dr(t)};a.__quickforgeDismissHandler=c,a.addEventListener(`pointerdown`,e=>e.stopPropagation()),document.addEventListener(`pointerdown`,c,!0),document.addEventListener(`keydown`,c,!0),window.addEventListener(`resize`,c,!0),window.addEventListener(`scroll`,c,!0),document.body.append(a),s(),n.setAttribute(`aria-expanded`,`true`)}function mr(e){let{panel:t,leftControls:n,agentAccessMode:r,onAccessModeChange:i}=e;n.classList.add(`quickforge-composer-left-controls`),t.querySelector(`.quickforge-yolo-inline`)?.remove();let a=ur(r),o=f(r===`full-access`?`agentAccessFullTitle`:`agentAccessDefaultTitle`),s=`${r===`full-access`?sr:or}<span class="quickforge-agent-access-label"></span>${lr}`,c=`quickforge-agent-access-inline inline-flex h-8 items-center justify-center gap-1.5 rounded-md border border-transparent px-2 text-xs font-medium text-muted-foreground${r===`full-access`?` quickforge-agent-access-inline-full`:``}`,l=n.querySelector(`.quickforge-agent-access-inline`),u=e=>{we(e,s),e.querySelector(`.quickforge-agent-access-label`).textContent=a,e.title=o,e.setAttribute(`aria-label`,o),e.setAttribute(`aria-haspopup`,`menu`),e.setAttribute(`aria-expanded`,document.querySelector(`.quickforge-agent-access-menu`)?`true`:`false`),e.dataset.quickforgeAgentAccessMode=r,e.className=c,e.onpointerdown=n=>{n.preventDefault(),n.stopPropagation(),pr({panel:t,trigger:e,agentAccessMode:r,onAccessModeChange:i})},e.onclick=e=>{e.preventDefault(),e.stopPropagation()},e.onkeydown=n=>{n.key!==`Enter`&&n.key!==` `&&n.key!==`ArrowDown`||(n.preventDefault(),pr({panel:t,trigger:e,agentAccessMode:r,onAccessModeChange:i}))}};if(l)u(l);else{let e=document.createElement(`button`);e.type=`button`,u(e),n.append(e)}let d=n.querySelector(`.quickforge-agent-access-inline`),p=n.querySelector(`.quickforge-plan-inline`);d&&p&&d.nextSibling!==p&&n.insertBefore(p,d.nextSibling)}function hr(e){let{panel:t,isStreaming:n,abort:r,agentAccessMode:i,planMode:a,workspaceToolsEnabled:o,readOnly:s,allowModelControls:c,onAccessModeChange:l,onTogglePlanMode:u,onInput:d,onFilesChange:p,removeCommandSuggestions:m,updateCommandSuggestions:h,setupCommandTextareaHandler:g,removeCapabilitySuggestions:_,updateCapabilitySuggestions:v,setupCapabilityTextareaHandler:y,insertBuiltinPluginMention:b,onBeforeSend:x}=e,S=t.querySelector(`message-editor`);S?.classList.add(`quickforge-composer`),S?.parentElement?.classList.add(`quickforge-composer-shell`),S?.parentElement?.parentElement?.classList.add(`quickforge-composer-dock`);let C=S?.querySelector(`textarea`);if(C&&(C.placeholder=f(`composerPlaceholder`)),s){t.querySelector(`.quickforge-composer-dock`)?.remove();return}if(S){S.onInput=e=>{d(e),h(e),v(e)},S.onFilesChange=e=>{p(e?[...e]:[])};let e=S.onSend;e&&e!==S.__quickforgePlanWrappedOnSend&&(S.__quickforgePlanBaseOnSend=e);let t=S.__quickforgePlanBaseOnSend;if(t){let e=(e,n)=>{let r=String(e??``);r.trim().length>0&&x?.(r),m(),_(),t(r,n)};S.__quickforgePlanWrappedOnSend=e,S.onSend=e}h(),v()}g(S),y(S),Zn(S,a,u);let w=t.querySelector(`agent-interface`);if(w){let e=w.enableModelSelector!==c;w.enableModelSelector=c,w.enableThinkingSelector=!1,e&&w.requestUpdate?.()}let T=S?.querySelectorAll(`.flex.gap-2.items-center`),E=T?.[0],D=T?.[T.length-1];if(!D)return;Xn(S,D);let O=D.querySelector(`button:last-child`);if(O){let e=()=>{O.__quickforgeStopHandler&&=(O.removeEventListener(`pointerdown`,O.__quickforgeStopHandler,!0),O.removeEventListener(`click`,O.__quickforgeStopHandler,!0),void 0)};if(n())O.disabled=!1,O.classList.remove(`quickforge-send-button`),O.classList.add(`quickforge-stop-button`),O.title=`Stop`,O.setAttribute(`aria-label`,`Stop`),delete O.dataset.quickforgeSendIcon,Ce(O,`<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><rect x="6" y="6" width="12" height="12" rx="2"/></svg>`),O.__quickforgeStopHandler||(O.__quickforgeStopHandler=e=>{e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation(),m(),r()},O.addEventListener(`pointerdown`,O.__quickforgeStopHandler,!0),O.addEventListener(`click`,O.__quickforgeStopHandler,!0));else if(e(),O.classList.remove(`quickforge-stop-button`),O.classList.add(`quickforge-send-button`),O.dataset.quickforgeSendIcon!==`arrow-up`){O.dataset.quickforgeSendIcon=`arrow-up`,Ce(O,`<svg xmlns="http://www.w3.org/2000/svg" width="17" height="17" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 19V5"/><path d="m5 12 7-7 7 7"/></svg>`);let e=O.querySelector(`svg`)?.parentElement;e&&e!==O&&e.style.transform&&(e.style.transform=``)}}if(!E){t.querySelector(`.quickforge-plus-inline`)?.remove(),$n(t),t.querySelector(`.quickforge-agent-access-inline`)?.remove(),dr(t),t.querySelector(`.quickforge-yolo-inline`)?.remove(),t.querySelector(`.quickforge-plan-inline`)?.remove();return}S&&ar({panel:t,editor:S,leftControls:E,insertBuiltinPluginMention:b,removeCommandSuggestions:m,removeCapabilitySuggestions:_});let k=f(`planModeEnabledTitle`),A=`${st}${ct}<span>${f(`planModeLabel`)}</span>`,j=e=>{e.preventDefault(),e.stopPropagation(),u()},M=e=>{e.key!==`Enter`&&e.key!==` `||j(e)},N=t.querySelector(`.quickforge-plan-inline`),ee=e=>{we(e,A),e.title=k,e.setAttribute(`aria-label`,k),e.setAttribute(`aria-pressed`,String(a)),e.className=`quickforge-plan-inline inline-flex h-8 items-center justify-center gap-1.5 rounded-md border border-transparent px-2 text-xs font-medium text-muted-foreground`,e.onpointerdown=j,e.onclick=e=>{e.preventDefault(),e.stopPropagation()},e.onkeydown=M};if(!a)N?.remove();else if(N)ee(N);else{let e=document.createElement(`button`);e.type=`button`,ee(e);let t=E.querySelector(`.quickforge-agent-access-inline`);t?E.insertBefore(e,t.nextSibling):E.append(e)}if(!o){t.querySelector(`.quickforge-agent-access-inline`)?.remove(),dr(t),t.querySelector(`.quickforge-yolo-inline`)?.remove();return}mr({panel:t,leftControls:E,agentAccessMode:i,onAccessModeChange:l})}function gr(e){let t=e.querySelector(`message-editor`),n=t?.querySelector(`textarea`);return{text:t?.value??n?.value??``,attachments:t?.attachments?[...t.attachments]:[]}}function _r(e,t,n){let r=gr(e);q(r)?t.set(n,r):t.delete(n)}function vr(e,t,n,r){if(!q(t))return;let i={text:t.text,attachments:t.attachments?[...t.attachments]:[]},a=()=>{let t=e.querySelector(`message-editor`),n=t?.querySelector(`textarea`);t&&(t.value=i.text,t.attachments=i.attachments,t.requestUpdate?.(),t.onInput?.(i.text),t.onFilesChange?.(i.attachments)),n&&(n.value=i.text,n.dispatchEvent(new Event(`input`,{bubbles:!0})),n.focus())};e.querySelector(`agent-interface`)?.setInput?.(i.text,i.attachments),a(),requestAnimationFrame(a),window.setTimeout(a,0),n.set(r,i)}var yr=`.quickforge-approval-card`;function br(e){if(!e.startsWith(`mcp__`))return null;let t=e.slice(5),n=t.indexOf(`__`);return n<=0||n>=t.length-2?null:{serverName:t.slice(0,n),toolName:t.slice(n+2)}}function xr(e,t){return typeof t.summary==`string`?t.summary:e===`run_command`&&typeof t.command==`string`?t.command:e===`activate_skill`&&typeof t.name==`string`?t.name:e===`read_skill_resource`&&typeof t.path==`string`||typeof t.path==`string`?t.path:typeof t.query==`string`?t.query:typeof t.name==`string`?t.name:``}function Sr(e,t){let n=xr(e,t);return`
219
219
  ${n?`<div class="text-xs text-muted-foreground mb-1">${Z(f(`toolArgsSummary`))}: ${Z(n)}</div>`:``}
220
220
  <div class="text-xs bg-background border rounded p-2 text-muted-foreground">${Z(f(`toolDetailsHidden`))}</div>
221
- `}function Cr(e,t,n,r,i){let{panel:a,onApprove:o,onReject:s}=e;if(a.querySelector(`.quickforge-approval-card[data-tool-call-id="${CSS.escape(n)}"]`))return;wr(a);let c=document.createElement(`div`);c.className=`quickforge-approval-card pointer-events-auto mb-4 mx-4 rounded-lg border border-amber-300 dark:border-amber-700 bg-amber-50 dark:bg-amber-950/30 p-4`,c.dataset.toolCallId=n;let l=br(t),u=l?`MCP · ${l.serverName} · ${l.toolName}`:t,d=i?.type===`subagent`?i.label||i.subagent||`Subagent`:``,p=document.createElement(`div`);if(p.className=`flex items-center gap-2 mb-3 text-sm font-medium text-amber-800 dark:text-amber-300`,p.innerHTML=`<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"/><line x1="12" y1="9" x2="12" y2="13"/><line x1="12" y1="17" x2="12.01" y2="17"/></svg>`,p.append(` ${d?f(`subagentToolApprovalWaiting`,{source:d,toolName:u}):f(`toolApprovalWaiting`,{toolName:u})}`),c.append(p),d){let e=document.createElement(`div`);e.className=`mb-3 rounded-md border border-amber-200/80 bg-background/65 px-2.5 py-1.5 text-xs text-amber-800/85 dark:border-amber-800/70 dark:text-amber-200/85`,e.textContent=f(`toolApprovalSourceSubagent`,{source:d}),c.append(e)}let m=document.createElement(`div`);m.className=`quickforge-approval-preview mb-3`;let h=v().showToolDetails;if(l)m.innerHTML=`
221
+ `}function Cr(e,t,n,r,i){let{panel:a,onApprove:o,onReject:s}=e;if(a.querySelector(`.quickforge-approval-card[data-tool-call-id="${CSS.escape(n)}"]`))return;wr(a);let c=document.createElement(`div`);c.className=`quickforge-approval-card pointer-events-auto mb-4 mx-4 rounded-lg border border-amber-300 dark:border-amber-700 bg-amber-50 dark:bg-amber-950/30 p-4`,c.dataset.toolCallId=n;let l=br(t),u=l?`MCP · ${l.serverName} · ${l.toolName}`:t,d=i?.type===`subagent`?i.label||i.subagent||`Subagent`:``,p=document.createElement(`div`);if(p.className=`flex items-center gap-2 mb-3 text-sm font-medium text-amber-800 dark:text-amber-300`,p.innerHTML=`<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"/><line x1="12" y1="9" x2="12" y2="13"/><line x1="12" y1="17" x2="12.01" y2="17"/></svg>`,p.append(` ${d?f(`subagentToolApprovalWaiting`,{source:d,toolName:u}):f(`toolApprovalWaiting`,{toolName:u})}`),c.append(p),d){let e=document.createElement(`div`);e.className=`mb-3 rounded-md border border-amber-200/80 bg-background/65 px-2.5 py-1.5 text-xs text-amber-800/85 dark:border-amber-800/70 dark:text-amber-200/85`,e.textContent=f(`toolApprovalSourceSubagent`,{source:d}),c.append(e)}let m=document.createElement(`div`);m.className=`quickforge-approval-preview mb-3`;let g=h().showToolDetails;if(l)m.innerHTML=`
222
222
  <div class="rounded-md border bg-background/70 p-2 text-xs text-muted-foreground">
223
223
  <div><span class="font-medium text-foreground">Source:</span> MCP</div>
224
224
  <div><span class="font-medium text-foreground">Server:</span> ${Z(l.serverName)}</div>
225
225
  <div><span class="font-medium text-foreground">Tool:</span> ${Z(l.toolName)}</div>
226
226
  </div>
227
- ${h?`<pre class="mt-2 text-xs bg-background border rounded p-2 max-h-40 overflow-auto font-mono whitespace-pre-wrap">${Z(JSON.stringify(r,null,2))}</pre>`:Sr(t,r)}
227
+ ${g?`<pre class="mt-2 text-xs bg-background border rounded p-2 max-h-40 overflow-auto font-mono whitespace-pre-wrap">${Z(JSON.stringify(r,null,2))}</pre>`:Sr(t,r)}
228
228
  `;else if(t===`write_file`){let e=String(r.path??``),t=String(r.content??``),n=t.length>800;m.innerHTML=`
229
229
  <div class="text-xs text-muted-foreground mb-1">📁 ${Z(e)}</div>
230
230
  <pre class="text-xs bg-background border rounded p-2 max-h-40 overflow-auto font-mono whitespace-pre-wrap">${Tr(t.slice(0,800))}${n?`\n${Z(f(`toolApprovalTruncated`))}`:``}</pre>
@@ -234,9 +234,9 @@ import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{R as t,St as n}from"./
234
234
  `}else if(t===`run_command`){let e=String(r.command??``);m.innerHTML=`
235
235
  <div class="text-xs text-muted-foreground mb-1">⏱️ ${f(`toolApprovalTimeout`)}: ${Z(`30m`)}</div>
236
236
  <pre class="text-xs bg-background border rounded p-2 max-h-40 overflow-auto font-mono whitespace-pre-wrap">$ ${Z(e)}</pre>
237
- `}else typeof r.description==`string`?m.innerHTML=`<div class="text-xs bg-background border rounded p-2 text-muted-foreground">${Z(r.description)}</div>`:m.innerHTML=h?`<pre class="text-xs bg-background border rounded p-2 max-h-40 overflow-auto font-mono whitespace-pre-wrap">${Z(JSON.stringify(r,null,2))}</pre>`:Sr(t,r);c.append(m);let g=document.createElement(`div`);g.className=`mb-2 hidden text-xs text-red-700 dark:text-red-400`,c.append(g);let _=document.createElement(`div`);_.className=`flex items-center gap-2`;let y=e=>{x.disabled=e,S.disabled=e,x.classList.toggle(`opacity-60`,e),S.classList.toggle(`opacity-60`,e),x.textContent=f(e?`toolApprovalSubmitting`:`toolApprovalAccept`)},b=async e=>{g.classList.add(`hidden`),g.textContent=``,y(!0);try{await e()}catch(e){g.textContent=e instanceof Error?e.message:f(`toolApprovalFailed`),g.classList.remove(`hidden`),y(!1)}},x=document.createElement(`button`);x.type=`button`,x.className=`inline-flex items-center gap-1.5 rounded-md bg-emerald-600 px-3 py-1.5 text-xs font-medium text-white hover:bg-emerald-700 transition-colors cursor-pointer disabled:cursor-not-allowed`,x.textContent=f(`toolApprovalAccept`),x.addEventListener(`click`,e=>{e.stopPropagation(),e.preventDefault(),b(o)});let S=document.createElement(`button`);S.type=`button`,S.className=`inline-flex items-center gap-1.5 rounded-md border border-red-300 dark:border-red-700 px-3 py-1.5 text-xs font-medium text-red-700 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-950/30 transition-colors cursor-pointer disabled:cursor-not-allowed`,S.textContent=f(`toolApprovalReject`),S.addEventListener(`click`,e=>{e.stopPropagation(),e.preventDefault(),b(s)}),_.append(x,S),c.append(_);let C=a.querySelector(`message-list`);C?C.append(c):a.querySelector(`agent-interface`)?.append(c),c.scrollIntoView({behavior:`smooth`,block:`end`})}function wr(e){e.querySelectorAll(yr).forEach(e=>e.remove())}function Z(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`)}function Tr(e){return e.split(`
237
+ `}else typeof r.description==`string`?m.innerHTML=`<div class="text-xs bg-background border rounded p-2 text-muted-foreground">${Z(r.description)}</div>`:m.innerHTML=g?`<pre class="text-xs bg-background border rounded p-2 max-h-40 overflow-auto font-mono whitespace-pre-wrap">${Z(JSON.stringify(r,null,2))}</pre>`:Sr(t,r);c.append(m);let _=document.createElement(`div`);_.className=`mb-2 hidden text-xs text-red-700 dark:text-red-400`,c.append(_);let v=document.createElement(`div`);v.className=`flex items-center gap-2`;let y=e=>{x.disabled=e,S.disabled=e,x.classList.toggle(`opacity-60`,e),S.classList.toggle(`opacity-60`,e),x.textContent=f(e?`toolApprovalSubmitting`:`toolApprovalAccept`)},b=async e=>{_.classList.add(`hidden`),_.textContent=``,y(!0);try{await e()}catch(e){_.textContent=e instanceof Error?e.message:f(`toolApprovalFailed`),_.classList.remove(`hidden`),y(!1)}},x=document.createElement(`button`);x.type=`button`,x.className=`inline-flex items-center gap-1.5 rounded-md bg-emerald-600 px-3 py-1.5 text-xs font-medium text-white hover:bg-emerald-700 transition-colors cursor-pointer disabled:cursor-not-allowed`,x.textContent=f(`toolApprovalAccept`),x.addEventListener(`click`,e=>{e.stopPropagation(),e.preventDefault(),b(o)});let S=document.createElement(`button`);S.type=`button`,S.className=`inline-flex items-center gap-1.5 rounded-md border border-red-300 dark:border-red-700 px-3 py-1.5 text-xs font-medium text-red-700 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-950/30 transition-colors cursor-pointer disabled:cursor-not-allowed`,S.textContent=f(`toolApprovalReject`),S.addEventListener(`click`,e=>{e.stopPropagation(),e.preventDefault(),b(s)}),v.append(x,S),c.append(v);let C=a.querySelector(`message-list`);C?C.append(c):a.querySelector(`agent-interface`)?.append(c),c.scrollIntoView({behavior:`smooth`,block:`end`})}function wr(e){e.querySelectorAll(yr).forEach(e=>e.remove())}function Z(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`)}function Tr(e){return e.split(`
238
238
  `).map(e=>{let t=Z(e);return e.startsWith(`+`)?`<span style="color:rgb(22 101 52);background:rgba(34,197,94,.14);display:block;">${t}</span>`:e.startsWith(`-`)?`<span style="color:rgb(153 27 27);background:rgba(239,68,68,.12);display:block;">${t}</span>`:e.startsWith(`@@`)?`<span style="color:rgb(37 99 235);background:rgba(37,99,235,.10);display:block;">${t}</span>`:`<span style="display:block;">${t||` `}</span>`}).join(`
239
239
  `)}function Er(e,t){let n=e.split(`
240
240
  `),r=t.split(`
241
241
  `),i=[];for(let e of n)i.push(`<span style="color:rgb(153 27 27);background:rgba(239,68,68,.12);display:block;">- ${Z(e)}</span>`);for(let e of r)i.push(`<span style="color:rgb(22 101 52);background:rgba(34,197,94,.14);display:block;">+ ${Z(e)}</span>`);return i.join(`
242
- `)}function Q(e){return!!(e&&typeof e==`object`&&!Array.isArray(e))}function $(e,t){let n=e[t];return typeof n==`string`&&n.trim()?n:void 0}function Dr(e,t){let n=e[t];return typeof n==`boolean`?n:void 0}function Or(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:void 0}function kr(e){let t=e&&Q(e.diff)?e.diff:void 0;return{addedLines:t?Or(t,`addedLines`):void 0,removedLines:t?Or(t,`removedLines`):void 0}}function Ar(e=``){let t=e.toLowerCase();return t.endsWith(`.html`)||t.endsWith(`.htm`)?`html`:/\.(svg|png|jpe?g|webp|gif|bmp|ico)$/i.test(t)?`image`:t.endsWith(`.md`)||t.endsWith(`.mdx`)?`markdown`:/\.(ts|tsx|js|jsx|mjs|cjs|css|scss|less|json|jsonc|txt|xml|yml|yaml|toml|ini|py|rb|go|rs|java|c|h|cpp|hpp|cs|php|sh|bash|zsh|ps1)$/i.test(t)?`code`:`unknown`}function jr(e){return e===`html`||e===`image`||e===`markdown`||e===`code`}function Mr(e){return[e.source,e.path??``,e.command??``,e.outputFile??``,e.toolCallId??``,e.preview?`preview`:``].join(`\0`)}function Nr(e,t,n){let r=Mr(n);t.has(r)||(t.add(r),e.push({id:`${e.length}:${r}`,...n}))}function Pr(e){if(!(typeof e!=`string`||!e.trim()))try{return JSON.parse(e)}catch{return}}function Fr(e,t){if(t&&(Array.isArray(t.files)||Array.isArray(t.previewed)))return t;let n=e.data;if(Array.isArray(n))for(let e of n){if(!Q(e)||e.type!==`text`)continue;let t=Pr(e.text);if(Q(t)&&(Array.isArray(t.files)||Array.isArray(t.previewed)))return t}let r=e.content;if(Array.isArray(r))for(let e of r){if(!Q(e)||e.type!==`text`)continue;let t=Pr(e.text);if(Q(t)&&(Array.isArray(t.files)||Array.isArray(t.previewed)))return t}return t}function Ir(e){if(typeof e==`string`&&e.trim())return{path:e};if(Q(e)){let t=$(e,`path`);return t?{path:t,title:$(e,`title`),description:$(e,`description`),kind:$(e,`kind`),preview:Dr(e,`preview`)}:void 0}}function Lr(e){let t=new Set,n=[];for(let r of e){if(r.role!==`toolResult`)continue;let e=typeof r.toolName==`string`?r.toolName:``,i=Q(r.details)?r.details:void 0,a=typeof r.toolCallId==`string`?r.toolCallId:void 0;if(!(!i&&e!==`present_files`)){if(e===`write_file`||e===`edit_file`){let r=i?$(i,`path`):void 0;if(r){let o=Ar(r),{addedLines:s,removedLines:c}=kr(i);Nr(n,t,{source:e,confidence:`high`,path:r,toolCallId:a,kind:o,preview:jr(o),presentation:`inferred`,addedLines:s,removedLines:c})}}else if(e===`present_files`){let e=Fr(r,i),o=Q(e)&&Array.isArray(e.files)?e.files:[],s=Q(e)?$(e,`defaultPreview`):void 0,c=new Set(Q(e)&&Array.isArray(e.previewed)?e.previewed.filter(e=>typeof e==`string`):[]);for(let e of o){let r=Ir(e);if(!r?.path)continue;let i=r.kind??Ar(r.path);Nr(n,t,{source:`present_files`,confidence:`high`,path:r.path,title:r.title,description:r.description,toolCallId:a,kind:i,preview:r.preview??(c.has(r.path)||s===r.path||jr(i)),defaultPreview:s===r.path,presentation:`explicit`})}}else if(e===`run_command`&&i){let e=$(i,`command`),r=$(i,`outputFile`);(e||r)&&Nr(n,t,{source:`run_command`,confidence:`low`,command:e,outputFile:r,toolCallId:a})}}}return n}function Rr(e){return e?.length?Lr(e):[]}var zr=`composer-drafts:v1`;function Br(e){return!!(e&&!e.startsWith(`pending-`))}function Vr(e){return Br(e.sessionId)?`session:${e.sessionId}`:e.scope===`project`&&e.projectId?`new:project:${e.projectId}`:`new:global`}function Hr(e){if(!e||typeof e!=`object`||Array.isArray(e))return{};let t={};for(let[n,r]of Object.entries(e)){if(!r||typeof r!=`object`||Array.isArray(r))continue;let e=r;typeof e.text==`string`&&(t[n]={text:e.text,updatedAt:typeof e.updatedAt==`string`?e.updatedAt:new Date().toISOString(),scope:e.scope===`project`?`project`:e.scope===`global`?`global`:void 0,projectId:typeof e.projectId==`string`?e.projectId:void 0,sessionId:typeof e.sessionId==`string`?e.sessionId:void 0})}return t}async function Ur(e){return Hr(await e.settings.get(zr))}async function Wr(e,t){let n=(await Ur(e))[t];if(!(!n||n.text.length===0))return{text:n.text,attachments:[]}}async function Gr(e,t,n,r){let i=n.text??``;if(i.length===0){await Kr(e,t);return}let a=await Ur(e);a[t]={text:i,updatedAt:new Date().toISOString(),scope:r.scope,projectId:r.scope===`project`?r.projectId:void 0,sessionId:Br(r.sessionId)?r.sessionId:void 0},await e.settings.set(zr,a)}async function Kr(e,t){let n=await Ur(e);Object.prototype.hasOwnProperty.call(n,t)&&(delete n[t],await e.settings.set(zr,n))}var qr=r();function Jr(e){let t=e.state.contextCompaction;if(!t?.summaryMessage)return e.state.messages;let n=e.state.messages,r=Math.min(n.length,Math.max(0,Number(t.compactedUpToIndex)||0));return[t.summaryMessage,...n.slice(r)]}function Yr({agent:e,onModelSelect:t,revision:n,agentAccessMode:r,workspaceToolsEnabled:i,project:a,projectId:o,chatScope:s=`global`,storage:l=null,onAccessModeChange:p,onRollbackFromMessage:m,onRetryFromMessage:h,onCopyAnswer:g,onForkFromMessage:v,onApproveToolCall:y,onRejectToolCall:b,onApproveAutoCompact:S,onRejectAutoCompact:C,onOpenWorkspaceGitChanges:w,onOpenLocalFilePath:T,onArtifactsChange:E,onContextUsageDisplayChange:D,restoredDraft:O,disableFork:k=!1,readOnly:A=!1,bypassClientApiKeyCheck:j=!1,allowModelControls:M=!0,rollbackConfirmTitle:N,rollbackConfirmDescription:ee}){let P=(0,x.useRef)(null),te=(0,x.useRef)(void 0),ne=(0,x.useRef)(void 0),F=(0,x.useRef)(new Map),I=(0,x.useRef)(l),re=(0,x.useRef)([]),ie=(0,x.useRef)(void 0),ae=(0,x.useRef)(new Set),L=(0,x.useRef)(void 0),oe=(0,x.useRef)(``),[se,ce]=(0,x.useState)(),[R,le]=(0,x.useState)(!1),ue=(0,x.useCallback)(()=>le(e=>!e),[]),de=(0,x.useCallback)(()=>le(!1),[]);(0,x.useEffect)(()=>{e?.setPlanMode?.(R,R?de:void 0)},[e,R,de]);let fe=(0,x.useCallback)(()=>{L.current&&=(window.clearTimeout(L.current),void 0)},[]);(0,x.useEffect)(()=>{I.current=l},[l]);let pe=(0,x.useMemo)(()=>({sessionId:e?.sessionId,scope:s,projectId:o}),[e?.sessionId,s,o]),me=Vr(pe),he=(0,x.useRef)(pe),z=(0,x.useRef)(me);(0,x.useEffect)(()=>{he.current=pe,z.current=me},[pe,me]),(0,x.useEffect)(()=>()=>{fe()},[fe]);let B=(0,x.useCallback)((e,t,n)=>{let r=I.current;if(r){if(t.text.length===0){Kr(r,e).catch(e=>d.error(`Failed to clear composer draft:`,e));return}Gr(r,e,t,n).catch(e=>d.error(`Failed to save composer draft:`,e))}},[]),V=(0,x.useCallback)((e,t,n)=>{L.current&&window.clearTimeout(L.current),L.current=window.setTimeout(()=>{L.current=void 0,B(e,t,n)},400)},[B]),H=(0,x.useCallback)((e,t=z.current,n=he.current)=>{let r=gr(e);q(r)?F.current.set(t,r):F.current.delete(t),B(t,r,n)},[B]),U=(0,x.useRef)({onCopyAnswer:g,onRollbackFromMessage:m,onRetryFromMessage:h,onForkFromMessage:v,onAccessModeChange:p,onTogglePlanMode:ue,onApproveToolCall:y,onRejectToolCall:b,onApproveAutoCompact:S,onRejectAutoCompact:C,onOpenWorkspaceGitChanges:w,onOpenLocalFilePath:T,onArtifactsChange:E,onContextUsageDisplayChange:D,onModelSelect:t,agentAccessMode:r,planMode:R,workspaceToolsEnabled:i,disableFork:k,readOnly:A,allowModelControls:M,bypassClientApiKeyCheck:j,rollbackConfirmTitle:N,rollbackConfirmDescription:ee,gitBranch:se});(0,x.useEffect)(()=>{U.current={onCopyAnswer:g,onRollbackFromMessage:m,onRetryFromMessage:h,onForkFromMessage:v,onAccessModeChange:p,onTogglePlanMode:ue,onApproveToolCall:y,onRejectToolCall:b,onApproveAutoCompact:S,onRejectAutoCompact:C,onOpenWorkspaceGitChanges:w,onOpenLocalFilePath:T,onArtifactsChange:E,onContextUsageDisplayChange:D,onModelSelect:t,agentAccessMode:r,planMode:R,workspaceToolsEnabled:i,disableFork:k,readOnly:A,allowModelControls:M,bypassClientApiKeyCheck:j,rollbackConfirmTitle:N,rollbackConfirmDescription:ee,gitBranch:se},ne.current=O});let ge=a?.id??o;(0,x.useEffect)(()=>{let e=!1;return queueMicrotask(()=>{if(!e){if(!ge){ce(void 0);return}_(ge).then(t=>{e||ce(t.isGitRepository?t.branch:void 0)}).catch(t=>{e||(d.warn(`Failed to load git branch:`,t),ce(void 0))})}}),()=>{e=!0}},[ge,n]);let _e=(0,x.useRef)(null),ve=(0,x.useRef)(null),W=(0,x.useRef)(null),G=(0,x.useRef)(null),K=(0,x.useRef)(null);(0,x.useEffect)(()=>{let e=!1;return a?.id?(fetch(`/api/project/commands?projectId=${encodeURIComponent(a.id)}`,{cache:`no-store`}).then(e=>e.ok?e.json():{commands:[]}).then(t=>{e||(re.current=Array.isArray(t.commands)?t.commands:[],W.current?.())}).catch(()=>{e||(re.current=[],W.current?.())}),()=>{e=!0}):(re.current=[],()=>{e=!0})},[a?.id,n]);let ye=(e,t,n,r,i=!1)=>{if(t.sessionId&&t.sessionId!==n||!q(t)||!i&&ae.current.has(t.id))return;let a=()=>{if(!i&&ae.current.has(t.id))return;let n=e.querySelector(`message-editor`),a=n?{text:n.value??n.querySelector(`textarea`)?.value??``,attachments:n.attachments?[...n.attachments]:[]}:F.current.get(r),o=ie.current;(o?.id!==t.id||!q(a??Te())||a?.text===o.text)&&(vr(e,t,F.current,r),ie.current={id:t.id,text:t.text})};a(),window.requestAnimationFrame(a);for(let e of[0,50,150,300,600])window.setTimeout(a,e);e.querySelector(`agent-interface`)?.updateComplete?.then(a)};return(0,x.useEffect)(()=>{if(!P.current||!e)return;let t=new c;le(!1);let n=e.sessionId,r=z.current,i=he.current,a=!1,o,s=!1,l=e.state.isStreaming,p=!1,m=Fe({panel:t});ve.current=m;let h=Ie({panel:t,getCustomCommands:()=>re.current,getComposerDrafts:()=>F.current,sessionId:r,setComposerDrafts:e=>{F.current=e},restoreDraftIntoComposer:e=>{vr(t,e,F.current,r),V(r,e,i)}}),g=We({panel:t,restoreDraftIntoComposer:e=>{vr(t,e,F.current,r),V(r,e,i)}}),_=et({panel:t,getSystemPrompt:()=>e.state.systemPrompt,getMessages:()=>e.state.messages,getEffectiveMessages:()=>Jr(e),getContextWindow:()=>e.state.model?.contextWindow??0,getTools:()=>e.state.tools,getMaxTokens:()=>e.state.model?.maxTokens,getServerContextUsage:()=>e.state.contextUsage??null,getGitBranch:()=>U.current.gitBranch,onGitBranchClick:()=>U.current.onOpenWorkspaceGitChanges?.(),renderInline:!1,onDisplayChange:t=>U.current.onContextUsageDisplayChange?.(e.sessionId,t)}),v=e=>{s=!1;let n=t.querySelector(`message-editor`),a={text:e,attachments:n?.attachments?[...n.attachments]:[]};q(a)?F.current.set(r,a):F.current.delete(r),V(r,a,i)},y=e=>{s=!1;let n=t.querySelector(`message-editor`),a=n?.querySelector(`textarea`),o={text:n?.value??a?.value??``,attachments:e?[...e]:[]};q(o)?F.current.set(r,o):F.current.delete(r),V(r,o,i);let c=t.querySelector(`agent-interface`);c?.requestUpdate?.(),window.requestAnimationFrame(()=>W.current?.()),c?.updateComplete?.then(()=>W.current?.())},b=()=>{e.state.isStreaming?t.dataset.quickforgeAgentStreaming=`true`:delete t.dataset.quickforgeAgentStreaming},x=()=>{if(a||!t.isConnected)return;b();let n=U.current,r=Rr(e.state.messages),i=JSON.stringify(r.map(e=>[e.source,e.path,e.command,e.outputFile,e.confidence,e.preview,e.defaultPreview,e.addedLines,e.removedLines]));i!==oe.current&&(oe.current=i,n.onArtifactsChange?.(r));try{nn({panel:t,getMessages:()=>e.state.messages,isStreaming:()=>e.state.isStreaming,onCopyAnswer:n.onCopyAnswer,onRollbackFromMessage:n.onRollbackFromMessage,onRetryFromMessage:n.onRetryFromMessage,onForkFromMessage:n.onForkFromMessage,onOpenLocalFilePath:n.onOpenLocalFilePath,disableFork:n.disableFork,readOnly:n.readOnly,enableTerminalCommandActions:!n.readOnly,rollbackConfirmTitle:n.rollbackConfirmTitle,rollbackConfirmDescription:n.rollbackConfirmDescription}),Zt({panel:t,getMessages:()=>e.state.messages,getContextCompaction:()=>e.state.contextCompaction??null}),tn({panel:t,getMessages:()=>e.state.messages,isStreaming:()=>e.state.isStreaming,isActive:l})}catch{}try{hr({panel:t,isStreaming:()=>e.state.isStreaming,abort:()=>e.abort(),agentAccessMode:n.agentAccessMode,planMode:n.planMode,workspaceToolsEnabled:n.workspaceToolsEnabled,readOnly:n.readOnly,allowModelControls:n.allowModelControls,onAccessModeChange:n.onAccessModeChange,onTogglePlanMode:n.onTogglePlanMode,onInput:v,onFilesChange:y,removeCommandSuggestions:h.remove,updateCommandSuggestions:h.update,setupCommandTextareaHandler:h.setupTextareaHandler,removeCapabilitySuggestions:g.remove,updateCapabilitySuggestions:g.update,setupCapabilityTextareaHandler:g.setupTextareaHandler,insertBuiltinPluginMention:g.insertBuiltinPluginMention,onBeforeSend:t=>{let n=g.consumeSelectedCapabilities(t);e.setNextPromptCapabilities?.(n)}})}catch{}let o=G.current;if(o&&o.sessionId===e.sessionId){let e=o.toolCallId;Cr({panel:t,onApprove:async()=>{await U.current.onApproveToolCall(e),G.current=null,wr(t)},onReject:async()=>{await U.current.onRejectToolCall(e),G.current=null,wr(t)}},o.toolName,e,o.args,o.source)}else{let n=K.current;if(n&&n.sessionId===e.sessionId){let e=n.approvalId;Cr({panel:t,onApprove:async()=>{await U.current.onApproveAutoCompact?.(e),K.current=null,wr(t)},onReject:async()=>{await U.current.onRejectAutoCompact?.(e),K.current=null,wr(t)}},f(`contextManagement`),e,{percent:n.usage?.percent??0,threshold:n.thresholdPercent??0,keepRecentTurns:n.keepRecentTurns??2,summary:f(`autoCompactApprovalWaiting`,{percent:n.usage?.percent??0,threshold:n.thresholdPercent??0}),description:f(`autoCompactApprovalPreview`,{keepRecentTurns:n.keepRecentTurns??2})})}else wr(t)}_.update(),m.setup(),m.isEnabled&&m.scheduleScrollToBottom()},S=!1,C,w=!1,T,E=()=>{T===void 0&&(T=window.requestAnimationFrame(()=>{T=void 0,w=!1}))},D=()=>{if(!a){w=!0;try{x()}finally{E()}}},O=()=>{S||(S=!0,C=window.requestAnimationFrame(()=>{C=void 0,S=!1,D()}))};_e.current=D;let k=()=>{p||(p=!0,window.requestAnimationFrame(()=>{if(p=!1,a)return;b();let e=t.querySelector(`agent-interface`);e?.requestUpdate?.(),W.current?.(),e?.updateComplete?.then(()=>W.current?.()),m.isEnabled&&m.scheduleScrollToBottom()}))};W.current=O,t.setAgent(e,{onApiKeyRequired:U.current.bypassClientApiKeyCheck?async()=>!0:e=>u.prompt(e),onBeforeSend:()=>{let e=ne.current;e&&ae.current.add(e.id),fe(),s=!0,h.remove(),F.current.delete(r);let t=I.current;t&&Kr(t,r).catch(e=>d.error(`Failed to clear composer draft:`,e)),m.enable()},onModelSelect:U.current.onModelSelect,toolsFactory:()=>Se(e.state.tools)}).then(()=>{if(a)return;let e=ne.current,i=i=>{a||(e&&te.current!==e.id?(te.current=e.id,ye(t,e,n,r)):vr(t,i??F.current.get(r)??Te(),F.current,r))};if(e&&te.current!==e.id)i();else{let e=F.current.get(r);e?i(e):I.current?Wr(I.current,r).then(e=>i(e)).catch(e=>d.error(`Failed to load composer draft:`,e)):i()}o=new MutationObserver(()=>{w||O()}),o.observe(t,{childList:!0,subtree:!0}),window.requestAnimationFrame(()=>{a||D()})}),P.current.replaceChildren(t);let A=e.subscribe(i=>{if(i.type===`agent_start`&&(l=!0,b(),W.current?.(),m.enable(),G.current?.sessionId===e.sessionId&&(G.current=null),K.current?.sessionId===e.sessionId&&(K.current=null)),i.type===`message_start`||i.type===`message_update`||i.type===`message_end`||i.type===`turn_end`||i.type===`agent_end`){b();let e=i.message;(i.type===`message_update`||e?.role===`assistant`)&&(l=!1),W.current?.(),m.isEnabled&&m.scheduleScrollToBottom()}if(i.type===`messages_replaced`){let e=ne.current;e&&te.current===e.id&&ye(t,e,n,r)}let a=i.type;if(a===`tool_execution_start`||a===`tool_execution_end`){b();let e=t.querySelector(`agent-interface`);e?.requestUpdate?.(),W.current?.(),window.requestAnimationFrame(()=>W.current?.()),e?.updateComplete?.then(()=>W.current?.()),m.isEnabled&&m.scheduleScrollToBottom()}if(a===`tool_execution_update`&&k(),i.type===`agent_end`&&(l=!1,b(),W.current?.(),G.current?.sessionId===e.sessionId&&(G.current=null,W.current?.()),K.current?.sessionId===e.sessionId&&(K.current=null,W.current?.())),a===`auto_compact_completed`||a===`messages_replaced`){let e=t.querySelector(`agent-interface`);e?.requestUpdate?.(),W.current?.(),window.requestAnimationFrame(()=>W.current?.()),e?.updateComplete?.then(()=>W.current?.())}if(a===`auto_compact_failed`&&d.warn(f(`autoCompactFailed`)),i.type===`tool_approval_required`){let e=i;G.current={toolCallId:e.toolCallId,toolName:e.toolName,args:e.args,sessionId:e.sessionId,source:e.source},W.current?.()}if(i.type===`auto_compact_approval_required`){let e=i;K.current={approvalId:e.approvalId,usage:e.usage,thresholdPercent:e.thresholdPercent,keepRecentTurns:e.keepRecentTurns,sessionId:e.sessionId},W.current?.()}});return()=>{if(s){fe(),F.current.delete(r);let e=I.current;e&&Kr(e,r).catch(e=>d.error(`Failed to clear composer draft:`,e))}else _r(t,F.current,r),H(t,r,i);h.remove(),h.cleanupTextareaHandler(),g.remove(),g.cleanupTextareaHandler(),a=!0,m.cleanup(),ve.current=null,A(),o?.disconnect(),C!==void 0&&window.cancelAnimationFrame(C),T!==void 0&&window.cancelAnimationFrame(T),_e.current=null,t.remove()}},[e,fe,H,V]),(0,x.useEffect)(()=>{_e.current?.(),(P.current?.querySelector(`agent-interface`))?.requestUpdate?.()},[r,R,i,se,k,A,M,n]),(0,x.useEffect)(()=>{let t=ne.current;if(!t||!P.current)return;let n=e?.sessionId??``;if(t.sessionId&&t.sessionId!==n)return;let r=P.current.querySelector(`pi-chat-panel`);r&&(te.current=t.id,ye(r,t,n,z.current,!0))},[O,e]),(0,qr.jsx)(`div`,{ref:P,className:`min-h-0 flex-1 overflow-hidden`})}export{Yr as ChatPanelHost};
242
+ `)}function Q(e){return!!(e&&typeof e==`object`&&!Array.isArray(e))}function $(e,t){let n=e[t];return typeof n==`string`&&n.trim()?n:void 0}function Dr(e,t){let n=e[t];return typeof n==`boolean`?n:void 0}function Or(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:void 0}function kr(e){let t=e&&Q(e.diff)?e.diff:void 0;return{addedLines:t?Or(t,`addedLines`):void 0,removedLines:t?Or(t,`removedLines`):void 0}}function Ar(e=``){let t=e.toLowerCase();return t.endsWith(`.html`)||t.endsWith(`.htm`)?`html`:/\.(svg|png|jpe?g|webp|gif|bmp|ico)$/i.test(t)?`image`:t.endsWith(`.md`)||t.endsWith(`.mdx`)?`markdown`:/\.(ts|tsx|js|jsx|mjs|cjs|css|scss|less|json|jsonc|txt|xml|yml|yaml|toml|ini|py|rb|go|rs|java|c|h|cpp|hpp|cs|php|sh|bash|zsh|ps1)$/i.test(t)?`code`:`unknown`}function jr(e){return e===`html`||e===`image`||e===`markdown`||e===`code`}function Mr(e){return[e.source,e.path??``,e.command??``,e.outputFile??``,e.toolCallId??``,e.preview?`preview`:``].join(`\0`)}function Nr(e,t,n){let r=Mr(n);t.has(r)||(t.add(r),e.push({id:`${e.length}:${r}`,...n}))}function Pr(e){if(!(typeof e!=`string`||!e.trim()))try{return JSON.parse(e)}catch{return}}function Fr(e,t){if(t&&(Array.isArray(t.files)||Array.isArray(t.previewed)))return t;let n=e.data;if(Array.isArray(n))for(let e of n){if(!Q(e)||e.type!==`text`)continue;let t=Pr(e.text);if(Q(t)&&(Array.isArray(t.files)||Array.isArray(t.previewed)))return t}let r=e.content;if(Array.isArray(r))for(let e of r){if(!Q(e)||e.type!==`text`)continue;let t=Pr(e.text);if(Q(t)&&(Array.isArray(t.files)||Array.isArray(t.previewed)))return t}return t}function Ir(e){if(typeof e==`string`&&e.trim())return{path:e};if(Q(e)){let t=$(e,`path`);return t?{path:t,title:$(e,`title`),description:$(e,`description`),kind:$(e,`kind`),preview:Dr(e,`preview`)}:void 0}}function Lr(e){let t=new Set,n=[];for(let r of e){if(r.role!==`toolResult`)continue;let e=typeof r.toolName==`string`?r.toolName:``,i=Q(r.details)?r.details:void 0,a=typeof r.toolCallId==`string`?r.toolCallId:void 0;if(!(!i&&e!==`present_files`)){if(e===`write_file`||e===`edit_file`){let r=i?$(i,`path`):void 0;if(r){let o=Ar(r),{addedLines:s,removedLines:c}=kr(i);Nr(n,t,{source:e,confidence:`high`,path:r,toolCallId:a,kind:o,preview:jr(o),presentation:`inferred`,addedLines:s,removedLines:c})}}else if(e===`present_files`){let e=Fr(r,i),o=Q(e)&&Array.isArray(e.files)?e.files:[],s=Q(e)?$(e,`defaultPreview`):void 0,c=new Set(Q(e)&&Array.isArray(e.previewed)?e.previewed.filter(e=>typeof e==`string`):[]);for(let e of o){let r=Ir(e);if(!r?.path)continue;let i=r.kind??Ar(r.path);Nr(n,t,{source:`present_files`,confidence:`high`,path:r.path,title:r.title,description:r.description,toolCallId:a,kind:i,preview:r.preview??(c.has(r.path)||s===r.path||jr(i)),defaultPreview:s===r.path,presentation:`explicit`})}}else if(e===`run_command`&&i){let e=$(i,`command`),r=$(i,`outputFile`);(e||r)&&Nr(n,t,{source:`run_command`,confidence:`low`,command:e,outputFile:r,toolCallId:a})}}}return n}function Rr(e){return e?.length?Lr(e):[]}var zr=`composer-drafts:v1`;function Br(e){return!!(e&&!e.startsWith(`pending-`))}function Vr(e){return Br(e.sessionId)?`session:${e.sessionId}`:e.scope===`project`&&e.projectId?`new:project:${e.projectId}`:`new:global`}function Hr(e){if(!e||typeof e!=`object`||Array.isArray(e))return{};let t={};for(let[n,r]of Object.entries(e)){if(!r||typeof r!=`object`||Array.isArray(r))continue;let e=r;typeof e.text==`string`&&(t[n]={text:e.text,updatedAt:typeof e.updatedAt==`string`?e.updatedAt:new Date().toISOString(),scope:e.scope===`project`?`project`:e.scope===`global`?`global`:void 0,projectId:typeof e.projectId==`string`?e.projectId:void 0,sessionId:typeof e.sessionId==`string`?e.sessionId:void 0})}return t}async function Ur(e){return Hr(await e.settings.get(zr))}async function Wr(e,t){let n=(await Ur(e))[t];if(!(!n||n.text.length===0))return{text:n.text,attachments:[]}}async function Gr(e,t,n,r){let i=n.text??``;if(i.length===0){await Kr(e,t);return}let a=await Ur(e);a[t]={text:i,updatedAt:new Date().toISOString(),scope:r.scope,projectId:r.scope===`project`?r.projectId:void 0,sessionId:Br(r.sessionId)?r.sessionId:void 0},await e.settings.set(zr,a)}async function Kr(e,t){let n=await Ur(e);Object.prototype.hasOwnProperty.call(n,t)&&(delete n[t],await e.settings.set(zr,n))}var qr=r();function Jr(e){let t=e.state.contextCompaction;if(!t?.summaryMessage)return e.state.messages;let n=e.state.messages,r=Math.min(n.length,Math.max(0,Number(t.compactedUpToIndex)||0));return[t.summaryMessage,...n.slice(r)]}function Yr({agent:e,onModelSelect:t,revision:n,agentAccessMode:r,workspaceToolsEnabled:i,project:a,projectId:o,chatScope:s=`global`,storage:l=null,onAccessModeChange:p,onRollbackFromMessage:h,onRetryFromMessage:g,onCopyAnswer:_,onForkFromMessage:v,onApproveToolCall:y,onRejectToolCall:b,onApproveAutoCompact:S,onRejectAutoCompact:C,onOpenWorkspaceGitChanges:w,onOpenLocalFilePath:T,onArtifactsChange:E,onContextUsageDisplayChange:D,restoredDraft:O,disableFork:k=!1,readOnly:A=!1,bypassClientApiKeyCheck:j=!1,allowModelControls:M=!0,rollbackConfirmTitle:N,rollbackConfirmDescription:ee}){let P=(0,x.useRef)(null),te=(0,x.useRef)(void 0),ne=(0,x.useRef)(void 0),F=(0,x.useRef)(new Map),I=(0,x.useRef)(l),re=(0,x.useRef)([]),ie=(0,x.useRef)(void 0),ae=(0,x.useRef)(new Set),L=(0,x.useRef)(void 0),oe=(0,x.useRef)(``),[se,ce]=(0,x.useState)(),[R,le]=(0,x.useState)(!1),ue=(0,x.useCallback)(()=>le(e=>!e),[]),de=(0,x.useCallback)(()=>le(!1),[]);(0,x.useEffect)(()=>{e?.setPlanMode?.(R,R?de:void 0)},[e,R,de]);let fe=(0,x.useCallback)(()=>{L.current&&=(window.clearTimeout(L.current),void 0)},[]);(0,x.useEffect)(()=>{I.current=l},[l]);let pe=(0,x.useMemo)(()=>({sessionId:e?.sessionId,scope:s,projectId:o}),[e?.sessionId,s,o]),me=Vr(pe),he=(0,x.useRef)(pe),z=(0,x.useRef)(me);(0,x.useEffect)(()=>{he.current=pe,z.current=me},[pe,me]),(0,x.useEffect)(()=>()=>{fe()},[fe]);let B=(0,x.useCallback)((e,t,n)=>{let r=I.current;if(r){if(t.text.length===0){Kr(r,e).catch(e=>d.error(`Failed to clear composer draft:`,e));return}Gr(r,e,t,n).catch(e=>d.error(`Failed to save composer draft:`,e))}},[]),V=(0,x.useCallback)((e,t,n)=>{L.current&&window.clearTimeout(L.current),L.current=window.setTimeout(()=>{L.current=void 0,B(e,t,n)},400)},[B]),H=(0,x.useCallback)((e,t=z.current,n=he.current)=>{let r=gr(e);q(r)?F.current.set(t,r):F.current.delete(t),B(t,r,n)},[B]),U=(0,x.useRef)({onCopyAnswer:_,onRollbackFromMessage:h,onRetryFromMessage:g,onForkFromMessage:v,onAccessModeChange:p,onTogglePlanMode:ue,onApproveToolCall:y,onRejectToolCall:b,onApproveAutoCompact:S,onRejectAutoCompact:C,onOpenWorkspaceGitChanges:w,onOpenLocalFilePath:T,onArtifactsChange:E,onContextUsageDisplayChange:D,onModelSelect:t,agentAccessMode:r,planMode:R,workspaceToolsEnabled:i,disableFork:k,readOnly:A,allowModelControls:M,bypassClientApiKeyCheck:j,rollbackConfirmTitle:N,rollbackConfirmDescription:ee,gitBranch:se});(0,x.useEffect)(()=>{U.current={onCopyAnswer:_,onRollbackFromMessage:h,onRetryFromMessage:g,onForkFromMessage:v,onAccessModeChange:p,onTogglePlanMode:ue,onApproveToolCall:y,onRejectToolCall:b,onApproveAutoCompact:S,onRejectAutoCompact:C,onOpenWorkspaceGitChanges:w,onOpenLocalFilePath:T,onArtifactsChange:E,onContextUsageDisplayChange:D,onModelSelect:t,agentAccessMode:r,planMode:R,workspaceToolsEnabled:i,disableFork:k,readOnly:A,allowModelControls:M,bypassClientApiKeyCheck:j,rollbackConfirmTitle:N,rollbackConfirmDescription:ee,gitBranch:se},ne.current=O});let ge=a?.id??o;(0,x.useEffect)(()=>{let e=!1;return queueMicrotask(()=>{if(!e){if(!ge){ce(void 0);return}m(ge).then(t=>{e||ce(t.isGitRepository?t.branch:void 0)}).catch(t=>{e||(d.warn(`Failed to load git branch:`,t),ce(void 0))})}}),()=>{e=!0}},[ge,n]);let _e=(0,x.useRef)(null),ve=(0,x.useRef)(null),W=(0,x.useRef)(null),G=(0,x.useRef)(null),K=(0,x.useRef)(null);(0,x.useEffect)(()=>{let e=!1;return a?.id?(fetch(`/api/project/commands?projectId=${encodeURIComponent(a.id)}`,{cache:`no-store`}).then(e=>e.ok?e.json():{commands:[]}).then(t=>{e||(re.current=Array.isArray(t.commands)?t.commands:[],W.current?.())}).catch(()=>{e||(re.current=[],W.current?.())}),()=>{e=!0}):(re.current=[],()=>{e=!0})},[a?.id,n]);let ye=(e,t,n,r,i=!1)=>{if(t.sessionId&&t.sessionId!==n||!q(t)||!i&&ae.current.has(t.id))return;let a=()=>{if(!i&&ae.current.has(t.id))return;let n=e.querySelector(`message-editor`),a=n?{text:n.value??n.querySelector(`textarea`)?.value??``,attachments:n.attachments?[...n.attachments]:[]}:F.current.get(r),o=ie.current;(o?.id!==t.id||!q(a??Te())||a?.text===o.text)&&(vr(e,t,F.current,r),ie.current={id:t.id,text:t.text})};a(),window.requestAnimationFrame(a);for(let e of[0,50,150,300,600])window.setTimeout(a,e);e.querySelector(`agent-interface`)?.updateComplete?.then(a)};return(0,x.useEffect)(()=>{if(!P.current||!e)return;let t=new c;le(!1);let n=e.sessionId,r=z.current,i=he.current,a=!1,o,s=!1,l=e.state.isStreaming,p=!1,m=Fe({panel:t});ve.current=m;let h=Ie({panel:t,getCustomCommands:()=>re.current,getComposerDrafts:()=>F.current,sessionId:r,setComposerDrafts:e=>{F.current=e},restoreDraftIntoComposer:e=>{vr(t,e,F.current,r),V(r,e,i)}}),g=We({panel:t,restoreDraftIntoComposer:e=>{vr(t,e,F.current,r),V(r,e,i)}}),_=et({panel:t,getSystemPrompt:()=>e.state.systemPrompt,getMessages:()=>e.state.messages,getEffectiveMessages:()=>Jr(e),getContextWindow:()=>e.state.model?.contextWindow??0,getTools:()=>e.state.tools,getMaxTokens:()=>e.state.model?.maxTokens,getServerContextUsage:()=>e.state.contextUsage??null,getGitBranch:()=>U.current.gitBranch,onGitBranchClick:()=>U.current.onOpenWorkspaceGitChanges?.(),renderInline:!1,onDisplayChange:t=>U.current.onContextUsageDisplayChange?.(e.sessionId,t)}),v=e=>{s=!1;let n=t.querySelector(`message-editor`),a={text:e,attachments:n?.attachments?[...n.attachments]:[]};q(a)?F.current.set(r,a):F.current.delete(r),V(r,a,i)},y=e=>{s=!1;let n=t.querySelector(`message-editor`),a=n?.querySelector(`textarea`),o={text:n?.value??a?.value??``,attachments:e?[...e]:[]};q(o)?F.current.set(r,o):F.current.delete(r),V(r,o,i);let c=t.querySelector(`agent-interface`);c?.requestUpdate?.(),window.requestAnimationFrame(()=>W.current?.()),c?.updateComplete?.then(()=>W.current?.())},b=()=>{e.state.isStreaming?t.dataset.quickforgeAgentStreaming=`true`:delete t.dataset.quickforgeAgentStreaming},x=()=>{if(a||!t.isConnected)return;b();let n=U.current,r=Rr(e.state.messages),i=JSON.stringify(r.map(e=>[e.source,e.path,e.command,e.outputFile,e.confidence,e.preview,e.defaultPreview,e.addedLines,e.removedLines]));i!==oe.current&&(oe.current=i,n.onArtifactsChange?.(r));try{nn({panel:t,getMessages:()=>e.state.messages,isStreaming:()=>e.state.isStreaming,onCopyAnswer:n.onCopyAnswer,onRollbackFromMessage:n.onRollbackFromMessage,onRetryFromMessage:n.onRetryFromMessage,onForkFromMessage:n.onForkFromMessage,onOpenLocalFilePath:n.onOpenLocalFilePath,disableFork:n.disableFork,readOnly:n.readOnly,enableTerminalCommandActions:!n.readOnly,rollbackConfirmTitle:n.rollbackConfirmTitle,rollbackConfirmDescription:n.rollbackConfirmDescription}),Zt({panel:t,getMessages:()=>e.state.messages,getContextCompaction:()=>e.state.contextCompaction??null}),tn({panel:t,getMessages:()=>e.state.messages,isStreaming:()=>e.state.isStreaming,isActive:l})}catch{}try{hr({panel:t,isStreaming:()=>e.state.isStreaming,abort:()=>e.abort(),agentAccessMode:n.agentAccessMode,planMode:n.planMode,workspaceToolsEnabled:n.workspaceToolsEnabled,readOnly:n.readOnly,allowModelControls:n.allowModelControls,onAccessModeChange:n.onAccessModeChange,onTogglePlanMode:n.onTogglePlanMode,onInput:v,onFilesChange:y,removeCommandSuggestions:h.remove,updateCommandSuggestions:h.update,setupCommandTextareaHandler:h.setupTextareaHandler,removeCapabilitySuggestions:g.remove,updateCapabilitySuggestions:g.update,setupCapabilityTextareaHandler:g.setupTextareaHandler,insertBuiltinPluginMention:g.insertBuiltinPluginMention,onBeforeSend:t=>{let n=g.consumeSelectedCapabilities(t);e.setNextPromptCapabilities?.(n)}})}catch{}let o=G.current;if(o&&o.sessionId===e.sessionId){let e=o.toolCallId;Cr({panel:t,onApprove:async()=>{await U.current.onApproveToolCall(e),G.current=null,wr(t)},onReject:async()=>{await U.current.onRejectToolCall(e),G.current=null,wr(t)}},o.toolName,e,o.args,o.source)}else{let n=K.current;if(n&&n.sessionId===e.sessionId){let e=n.approvalId;Cr({panel:t,onApprove:async()=>{await U.current.onApproveAutoCompact?.(e),K.current=null,wr(t)},onReject:async()=>{await U.current.onRejectAutoCompact?.(e),K.current=null,wr(t)}},f(`contextManagement`),e,{percent:n.usage?.percent??0,threshold:n.thresholdPercent??0,keepRecentTurns:n.keepRecentTurns??2,summary:f(`autoCompactApprovalWaiting`,{percent:n.usage?.percent??0,threshold:n.thresholdPercent??0}),description:f(`autoCompactApprovalPreview`,{keepRecentTurns:n.keepRecentTurns??2})})}else wr(t)}_.update(),m.setup(),m.isEnabled&&m.scheduleScrollToBottom()},S=!1,C,w=!1,T,E=()=>{T===void 0&&(T=window.requestAnimationFrame(()=>{T=void 0,w=!1}))},D=()=>{if(!a){w=!0;try{x()}finally{E()}}},O=()=>{S||(S=!0,C=window.requestAnimationFrame(()=>{C=void 0,S=!1,D()}))};_e.current=D;let k=()=>{p||(p=!0,window.requestAnimationFrame(()=>{if(p=!1,a)return;b();let e=t.querySelector(`agent-interface`);e?.requestUpdate?.(),W.current?.(),e?.updateComplete?.then(()=>W.current?.()),m.isEnabled&&m.scheduleScrollToBottom()}))};W.current=O,t.setAgent(e,{onApiKeyRequired:U.current.bypassClientApiKeyCheck?async()=>!0:e=>u.prompt(e),onBeforeSend:()=>{let e=ne.current;e&&ae.current.add(e.id),fe(),s=!0,h.remove(),F.current.delete(r);let t=I.current;t&&Kr(t,r).catch(e=>d.error(`Failed to clear composer draft:`,e)),m.enable()},onModelSelect:U.current.onModelSelect,toolsFactory:()=>Se(e.state.tools)}).then(()=>{if(a)return;let e=ne.current,i=i=>{a||(e&&te.current!==e.id?(te.current=e.id,ye(t,e,n,r)):vr(t,i??F.current.get(r)??Te(),F.current,r))};if(e&&te.current!==e.id)i();else{let e=F.current.get(r);e?i(e):I.current?Wr(I.current,r).then(e=>i(e)).catch(e=>d.error(`Failed to load composer draft:`,e)):i()}o=new MutationObserver(()=>{w||O()}),o.observe(t,{childList:!0,subtree:!0}),window.requestAnimationFrame(()=>{a||D()})}),P.current.replaceChildren(t);let A=e.subscribe(i=>{if(i.type===`agent_start`&&(l=!0,b(),W.current?.(),m.enable(),G.current?.sessionId===e.sessionId&&(G.current=null),K.current?.sessionId===e.sessionId&&(K.current=null)),i.type===`message_start`||i.type===`message_update`||i.type===`message_end`||i.type===`turn_end`||i.type===`agent_end`){b();let e=i.message;(i.type===`message_update`||e?.role===`assistant`)&&(l=!1),W.current?.(),m.isEnabled&&m.scheduleScrollToBottom()}if(i.type===`messages_replaced`){let e=ne.current;e&&te.current===e.id&&ye(t,e,n,r)}let a=i.type;if(a===`tool_execution_start`||a===`tool_execution_end`){b();let e=t.querySelector(`agent-interface`);e?.requestUpdate?.(),W.current?.(),window.requestAnimationFrame(()=>W.current?.()),e?.updateComplete?.then(()=>W.current?.()),m.isEnabled&&m.scheduleScrollToBottom()}if(a===`tool_execution_update`&&k(),i.type===`agent_end`&&(l=!1,b(),W.current?.(),G.current?.sessionId===e.sessionId&&(G.current=null,W.current?.()),K.current?.sessionId===e.sessionId&&(K.current=null,W.current?.())),a===`auto_compact_completed`||a===`messages_replaced`){let e=t.querySelector(`agent-interface`);e?.requestUpdate?.(),W.current?.(),window.requestAnimationFrame(()=>W.current?.()),e?.updateComplete?.then(()=>W.current?.())}if(a===`auto_compact_failed`&&d.warn(f(`autoCompactFailed`)),i.type===`tool_approval_required`){let e=i;G.current={toolCallId:e.toolCallId,toolName:e.toolName,args:e.args,sessionId:e.sessionId,source:e.source},W.current?.()}if(i.type===`auto_compact_approval_required`){let e=i;K.current={approvalId:e.approvalId,usage:e.usage,thresholdPercent:e.thresholdPercent,keepRecentTurns:e.keepRecentTurns,sessionId:e.sessionId},W.current?.()}});return()=>{if(s){fe(),F.current.delete(r);let e=I.current;e&&Kr(e,r).catch(e=>d.error(`Failed to clear composer draft:`,e))}else _r(t,F.current,r),H(t,r,i);h.remove(),h.cleanupTextareaHandler(),g.remove(),g.cleanupTextareaHandler(),a=!0,m.cleanup(),ve.current=null,A(),o?.disconnect(),C!==void 0&&window.cancelAnimationFrame(C),T!==void 0&&window.cancelAnimationFrame(T),_e.current=null,t.remove()}},[e,fe,H,V]),(0,x.useEffect)(()=>{_e.current?.(),(P.current?.querySelector(`agent-interface`))?.requestUpdate?.()},[r,R,i,se,k,A,M,n]),(0,x.useEffect)(()=>{let t=ne.current;if(!t||!P.current)return;let n=e?.sessionId??``;if(t.sessionId&&t.sessionId!==n)return;let r=P.current.querySelector(`pi-chat-panel`);r&&(te.current=t.id,ye(r,t,n,z.current,!0))},[O,e]),(0,qr.jsx)(`div`,{ref:P,className:`min-h-0 flex-1 overflow-hidden`})}export{Yr as ChatPanelHost};