@shawnstack/quickforge 1.5.4 → 1.5.5

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 (26) hide show
  1. package/README.md +10 -10
  2. package/dist/assets/{AgentProfilesPage-CGm7ZzRM.js → AgentProfilesPage-nVhgwanY.js} +1 -1
  3. package/dist/assets/{ChatPanelHost-nzOC6Tbg.js → ChatPanelHost-u0K5IWMF.js} +2 -2
  4. package/dist/assets/{PluginsPage-K3o4AB2E.js → PluginsPage-BVRTC0rz.js} +1 -1
  5. package/dist/assets/ScheduledTasksPage-D37TE2cM.js +2 -0
  6. package/dist/assets/{SharedConversationPage-BwmUajLr.js → SharedConversationPage-D5hnzsZC.js} +1 -1
  7. package/dist/assets/TerminalDock-NvH9esAS.js +2 -0
  8. package/dist/assets/WorkspaceInspector-DbnO1fei.js +3 -0
  9. package/dist/assets/{WorkspaceReaderDialog-D9Qy6LUm.js → WorkspaceReaderDialog-BcxIbNBq.js} +1 -1
  10. package/dist/assets/diff-line-counts-N83e7__F.js +10 -0
  11. package/dist/assets/{icons-DzxBk7tb.js → icons-Uo4Gd-eK.js} +1 -1
  12. package/dist/assets/index-DiaCCmXE.js +1482 -0
  13. package/dist/assets/index-KdiXReMI.css +3 -0
  14. package/dist/assets/{monaco-dMY7_GLO.js → monaco-DtXl4zfe.js} +1 -1
  15. package/dist/assets/{react-vendor-DsAeMFcm.js → react-vendor-BjDQPVuK.js} +1 -1
  16. package/dist/assets/useAppTheme-Bm6HIzLF.js +1 -0
  17. package/dist/index.html +4 -4
  18. package/dist/sw.js +1 -1
  19. package/package.json +1 -1
  20. package/server/agent-manager.mjs +8 -1
  21. package/dist/assets/ScheduledTasksPage-BVjejep8.js +0 -2
  22. package/dist/assets/TerminalDock-D-GWlS7P.js +0 -2
  23. package/dist/assets/WorkspaceInspector-CEU6nnM-.js +0 -3
  24. package/dist/assets/diff-line-counts-DCot_pZu.js +0 -10
  25. package/dist/assets/index-CkQWeO9c.css +0 -3
  26. package/dist/assets/index-DTiIspXQ.js +0 -1482
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.4-blue" />
4
+ <img alt="Version" src="https://img.shields.io/badge/version-1.5.5-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" />
@@ -73,7 +73,7 @@ QuickForge 的工具能力很直接,因此也需要谨慎使用:
73
73
  #### 从 npm 安装
74
74
 
75
75
  ```bash
76
- npm install -g @shawnstack/quickforge@1.5.4
76
+ npm install -g @shawnstack/quickforge@1.5.5
77
77
  qf
78
78
 
79
79
  # CLI 工具
@@ -104,17 +104,17 @@ console.log(app.url)
104
104
  当前版本的离线包:
105
105
 
106
106
  ```text
107
- package-offline/shawnstack-quickforge-1.5.4.tgz
107
+ package-offline/shawnstack-quickforge-1.5.5.tgz
108
108
  ```
109
109
 
110
110
  在安装了 Node.js 20+ 和 npm 的机器上执行:
111
111
 
112
112
  ```bash
113
- npm install -g ./package-offline/shawnstack-quickforge-1.5.4.tgz
113
+ npm install -g ./package-offline/shawnstack-quickforge-1.5.5.tgz
114
114
  qf
115
115
  ```
116
116
 
117
- 该包由 `v1.5.4` 标签生成,包含 QuickForge 运行时资源,依赖由 npm 安装。
117
+ 该包由 `v1.5.5` 标签生成,包含 QuickForge 运行时资源,依赖由 npm 安装。
118
118
 
119
119
  ### 本地开发
120
120
 
@@ -285,7 +285,7 @@ QuickForge intentionally exposes powerful local capabilities, so the boundaries
285
285
  #### npm
286
286
 
287
287
  ```bash
288
- npm install -g @shawnstack/quickforge@1.5.4
288
+ npm install -g @shawnstack/quickforge@1.5.5
289
289
  qf
290
290
 
291
291
  # CLI utilities
@@ -313,20 +313,20 @@ This entry is exposed through the `main` field in `package.json` and does not ch
313
313
 
314
314
  #### Offline tarball
315
315
 
316
- The offline release package for `v1.5.4` is:
316
+ The offline release package for `v1.5.5` is:
317
317
 
318
318
  ```text
319
- package-offline/shawnstack-quickforge-1.5.4.tgz
319
+ package-offline/shawnstack-quickforge-1.5.5.tgz
320
320
  ```
321
321
 
322
322
  Install it on a machine with Node.js 20+ and npm:
323
323
 
324
324
  ```bash
325
- npm install -g ./package-offline/shawnstack-quickforge-1.5.4.tgz
325
+ npm install -g ./package-offline/shawnstack-quickforge-1.5.5.tgz
326
326
  qf
327
327
  ```
328
328
 
329
- The package was generated from tag `v1.5.4` and includes QuickForge runtime assets and installs dependencies with npm.
329
+ The package was generated from tag `v1.5.5` and includes QuickForge runtime assets and installs dependencies with npm.
330
330
 
331
331
  ### Local development
332
332
 
@@ -1 +1 @@
1
- import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{T as t,a as n,c as r,tt as i,wt as a,xt as o}from"./icons-DzxBk7tb.js";import{n as s}from"./react-vendor-DsAeMFcm.js";import{D as c,E as l,F as u,I as d,M as f,N as p,O as m,P as h,T as g,k as _}from"./index-DTiIspXQ.js";var v=e(a(),1),y=s();function b(){return{name:``,label:``,description:``,systemPrompt:``,allowedTools:[`read_file`,`grep_files`],maxRuntimeMs:`1800000`,maxToolCalls:`300`,enabledAsSubagent:!0}}function x(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 S(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 C(e){return!!(e.name.trim()&&e.label.trim()&&e.allowedTools.length>0)}async function w(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 T(){let[e,a]=(0,v.useState)([]),[s,T]=(0,v.useState)([]),[E,D]=(0,v.useState)(!1),[O,k]=(0,v.useState)(null),[A,j]=(0,v.useState)(()=>b()),[M,N]=(0,v.useState)(!1),[P,F]=(0,v.useState)(``),[I,L]=(0,v.useState)(!1),[R,z]=(0,v.useState)(),[B,V]=(0,v.useState)(`off`),[H,U]=(0,v.useState)(``),[W,G]=(0,v.useState)(null);async function K(){let[e,t]=await Promise.all([w(`/api/agent-profiles`),w(`/api/agent-profiles/available-tools`)]);a(e.agents),T(t.tools)}(0,v.useEffect)(()=>{let e=!1;async function t(){try{let[t,n]=await Promise.all([w(`/api/agent-profiles`),w(`/api/agent-profiles/available-tools`)]);if(e)return;a(t.agents),T(n.tools)}catch(t){e||U(t instanceof Error?t.message:d(`requestFailed`))}}return t(),()=>{e=!0}},[]),(0,v.useEffect)(()=>{let e=!1;async function t(){try{let t=await c(),n=await l(t),r=await m(t),i=r.model??await _(t)??n[0];if(e)return;z(i),V(r.thinkingLevel??g(i))}catch{}}return t(),()=>{e=!0}},[]),(0,v.useEffect)(()=>{if(!W)return;let e=()=>G(null);return window.addEventListener(`click`,e),window.addEventListener(`blur`,e),()=>{window.removeEventListener(`click`,e),window.removeEventListener(`blur`,e)}},[W]);let q=(0,v.useMemo)(()=>e.find(e=>e.id===O)??null,[e,O]);function J(e,t){j(n=>({...n,[e]:t}))}function Y(e){j(t=>({...t,allowedTools:t.allowedTools.includes(e)?t.allowedTools.filter(t=>t!==e):[...t.allowedTools,e]}))}function X(){k(null),j(b()),F(``),U(``),D(!0)}function Z(e){k(e.id),j(x(e)),F(``),U(``),D(!0)}function Q(){M||I||(D(!1),k(null),j(b()),F(``))}async function $(){let e=P.trim();if(!e){U(d(`aiFillAgentInputRequired`));return}if(!R){U(d(`aiFillAgentNoModel`));return}L(!0),U(``);try{let t=await w(`/api/agent-profiles/ai-fill`,{method:`POST`,body:JSON.stringify({instruction:e,model:R,thinkingLevel:B})});j(e=>({...e,name:t.agent.name,label:t.agent.label,description:t.agent.description,systemPrompt:t.agent.systemPrompt}))}catch(e){U(e instanceof Error?e.message:d(`aiFillAgentFailed`))}finally{L(!1)}}async function ee(){if(C(A)){N(!0),U(``);try{let e=S(A);O?await w(`/api/agent-profiles/${encodeURIComponent(O)}`,{method:`PATCH`,body:JSON.stringify(e)}):await w(`/api/agent-profiles`,{method:`POST`,body:JSON.stringify(e)}),Q(),await K()}catch(e){U(e instanceof Error?e.message:d(`requestFailed`))}finally{N(!1)}}}async function te(e){if(e.builtin||e.readonly)return;let t=!e.enabledAsSubagent,n=e.enabledAsSubagent;a(n=>n.map(n=>n.id===e.id?{...n,enabledAsSubagent:t}:n)),G(null);try{await w(`/api/agent-profiles/${encodeURIComponent(e.id)}`,{method:`PATCH`,body:JSON.stringify({enabledAsSubagent:t})})}catch(t){a(t=>t.map(t=>t.id===e.id?{...t,enabledAsSubagent:n}:t)),U(t instanceof Error?t.message:d(`requestFailed`))}}async function ne(e){if(!(e.builtin||e.readonly)&&await f({description:d(`confirmDeleteAgent`),confirmLabel:d(`confirmDelete`),cancelLabel:d(`cancel`),variant:`destructive`})){U(``);try{await w(`/api/agent-profiles/${encodeURIComponent(e.id)}`,{method:`DELETE`}),await K()}catch(e){U(e instanceof Error?e.message:d(`requestFailed`))}}}return(0,y.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden bg-background`,children:[(0,y.jsx)(`div`,{className:`border-b border-border px-6 py-5`,children:(0,y.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,y.jsx)(`div`,{className:`flex size-10 items-center justify-center rounded-2xl bg-primary/10 text-primary`,children:(0,y.jsx)(o,{className:`size-5`})}),(0,y.jsx)(`div`,{children:(0,y.jsxs)(`h1`,{className:`inline-flex items-center gap-1.5 text-lg font-semibold text-foreground`,children:[d(`agentsTab`),(0,y.jsx)(p,{label:d(`agentsDescription`)})]})})]}),(0,y.jsx)(h,{onClick:X,children:d(`createAgent`)})]})}),(0,y.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-6`,children:(0,y.jsxs)(`div`,{className:`mx-auto max-w-5xl space-y-5`,children:[H&&!E?(0,y.jsx)(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive`,children:H}):null,(0,y.jsx)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:e.map(e=>(0,y.jsxs)(`div`,{className:`rounded-xl border border-border bg-card p-4`,children:[(0,y.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,y.jsxs)(`div`,{className:`min-w-0`,children:[(0,y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,y.jsx)(`h3`,{className:u(`truncate text-sm font-medium`,e.enabledAsSubagent?`text-foreground/90`:`text-muted-foreground`),children:e.label}),e.builtin?(0,y.jsx)(`span`,{className:`rounded-full bg-primary/10 px-2 py-0.5 text-xs text-primary`,children:d(`builtinAgent`)}):null]}),(0,y.jsx)(`p`,{className:`mt-1 font-mono text-xs text-muted-foreground`,children:e.name}),e.source&&!e.builtin?(0,y.jsxs)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:[e.source,e.relativePath?` · ${e.relativePath}`:``]}):null,(0,y.jsx)(`p`,{className:`mt-2 text-sm text-muted-foreground`,children:e.description||d(`noDescription`)})]}),(0,y.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,onClick:e=>e.stopPropagation(),children:[(0,y.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":e.enabledAsSubagent,disabled:e.builtin||e.readonly,className:u(`relative h-6 w-11 rounded-full transition-colors disabled:cursor-not-allowed disabled:opacity-60`,e.enabledAsSubagent?`bg-emerald-500`:`bg-muted-foreground/30`),onClick:()=>void te(e),title:e.enabledAsSubagent?d(`disableAsSubagent`):d(`enableAsSubagent`),children:(0,y.jsx)(`span`,{className:u(`absolute left-0.5 top-0.5 size-5 rounded-full bg-white shadow transition-transform`,e.enabledAsSubagent?`translate-x-5`:`translate-x-0`)})}),(0,y.jsxs)(`div`,{className:`relative`,children:[(0,y.jsx)(h,{variant:`ghost`,size:`icon`,onClick:()=>G(W===e.id?null:e.id),title:d(`moreActions`),children:(0,y.jsx)(i,{className:`size-4`})}),W===e.id?(0,y.jsxs)(`div`,{className:`absolute right-0 z-20 mt-1 w-36 overflow-hidden rounded-xl border border-border bg-popover py-1 text-sm shadow-quickforge`,children:[(0,y.jsxs)(`button`,{className:`flex w-full items-center gap-2 px-3 py-2 text-left hover:bg-muted disabled:cursor-not-allowed disabled:opacity-50`,disabled:e.builtin||e.readonly,onClick:()=>{G(null),Z(e)},children:[(0,y.jsx)(t,{className:`size-3.5`}),d(`editTask`)]}),(0,y.jsxs)(`button`,{className:`flex w-full items-center gap-2 px-3 py-2 text-left text-destructive hover:bg-muted disabled:cursor-not-allowed disabled:opacity-50`,disabled:e.builtin||e.readonly,onClick:()=>{G(null),ne(e)},children:[(0,y.jsx)(n,{className:`size-3.5`}),d(`delete`)]})]}):null]})]})]}),(0,y.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-1`,children:e.allowedTools.map(e=>(0,y.jsx)(`span`,{className:`rounded-full bg-muted px-2 py-0.5 font-mono text-xs text-muted-foreground`,children:e},e))}),(0,y.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,y.jsxs)(`span`,{children:[d(`maxRuntimeMs`),e.maxRuntimeMs??`-`]}),(0,y.jsxs)(`span`,{children:[d(`maxToolCalls`),e.maxToolCalls??`-`]})]})]},e.id))})]})}),E?(0,y.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4`,onMouseDown:e=>{e.target===e.currentTarget&&Q()},children:(0,y.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,y.jsxs)(`div`,{className:`shrink-0 border-b border-border px-5 py-4`,children:[(0,y.jsx)(`h2`,{className:`text-base font-medium text-foreground`,children:d(q?`editAgent`:`createAgent`)}),q?.readonly?(0,y.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:d(`builtinAgentReadonly`)}):null]}),(0,y.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-5 py-4`,children:(0,y.jsxs)(`div`,{className:`space-y-4`,children:[(0,y.jsxs)(`div`,{className:`rounded-2xl border border-border bg-muted/20 p-3`,children:[(0,y.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 text-sm font-medium text-foreground`,children:[(0,y.jsx)(r,{className:`size-4 text-primary`}),d(`aiFillAgent`),(0,y.jsx)(p,{label:d(`aiFillAgentDescription`)})]}),(0,y.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:P,disabled:!!q?.readonly||I,onChange:e=>F(e.target.value),placeholder:d(`aiFillAgentPlaceholder`)}),(0,y.jsx)(`div`,{className:`mt-2 flex justify-end`,children:(0,y.jsxs)(h,{variant:`outline`,size:`sm`,onClick:()=>void $(),disabled:!!q?.readonly||I||!P.trim(),children:[(0,y.jsx)(r,{className:`mr-1 size-3.5`}),d(I?`aiFillAgentLoading`:`aiFillAgent`)]})})]}),(0,y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,y.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[d(`agentName`),(0,y.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:A.name,disabled:!!q?.readonly,onChange:e=>J(`name`,e.target.value),placeholder:`reviewer`})]}),(0,y.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[d(`agentLabel`),(0,y.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:A.label,disabled:!!q?.readonly,onChange:e=>J(`label`,e.target.value),placeholder:d(`agentLabelPlaceholder`)})]})]}),(0,y.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[d(`agentDescription`),(0,y.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:A.description,disabled:!!q?.readonly,onChange:e=>J(`description`,e.target.value)})]}),(0,y.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[d(`agentSystemPrompt`),(0,y.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:A.systemPrompt,disabled:!!q?.readonly,onChange:e=>J(`systemPrompt`,e.target.value)})]}),(0,y.jsxs)(`div`,{children:[(0,y.jsx)(`div`,{className:`mb-2 text-sm font-medium text-foreground`,children:d(`allowedTools`)}),(0,y.jsx)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:s.map(e=>(0,y.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,y.jsx)(`input`,{type:`checkbox`,className:`mt-1`,disabled:!!q?.readonly,checked:A.allowedTools.includes(e.name),onChange:()=>Y(e.name)}),(0,y.jsxs)(`span`,{children:[(0,y.jsx)(`span`,{className:`font-medium text-foreground`,children:e.label}),(0,y.jsx)(`span`,{className:`ml-2 font-mono text-xs text-muted-foreground`,children:e.name}),e.riskLevel===`dangerous`?(0,y.jsx)(`span`,{className:`ml-2 rounded-full bg-amber-500/10 px-2 py-0.5 text-xs text-amber-700`,children:d(`highRiskTool`)}):null,(0,y.jsx)(`span`,{className:`mt-1 block text-xs text-muted-foreground`,children:e.description})]})]},e.name))})]}),(0,y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,y.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[d(`maxRuntimeMs`),(0,y.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:A.maxRuntimeMs,disabled:!!q?.readonly,onChange:e=>J(`maxRuntimeMs`,e.target.value)})]}),(0,y.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[d(`maxToolCalls`),(0,y.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:A.maxToolCalls,disabled:!!q?.readonly,onChange:e=>J(`maxToolCalls`,e.target.value)})]})]}),(0,y.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-foreground`,children:[(0,y.jsx)(`input`,{type:`checkbox`,checked:A.enabledAsSubagent,disabled:!!q?.readonly,onChange:e=>J(`enabledAsSubagent`,e.target.checked)}),d(`enabledAsSubagent`)]}),H?(0,y.jsx)(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive`,children:H}):null]})}),(0,y.jsx)(`div`,{className:`shrink-0 border-t border-border px-5 py-4`,children:(0,y.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,y.jsx)(h,{variant:`outline`,onClick:Q,disabled:M||I,children:d(`cancel`)}),(0,y.jsx)(h,{onClick:ee,disabled:M||I||!!q?.readonly||!C(A),children:d(`save`)})]})})]})}):null]})}export{T as AgentProfilesPage};
1
+ import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{Ct as t,Et as n,T as r,a as i,c as a,rt as o}from"./icons-Uo4Gd-eK.js";import{n as s}from"./react-vendor-BjDQPVuK.js";import{D as c,E as l,F as u,I as d,M as f,N as p,O as m,P as h,T as g,k as _}from"./index-DiaCCmXE.js";var v=e(n(),1),y=s();function b(){return{name:``,label:``,description:``,systemPrompt:``,allowedTools:[`read_file`,`grep_files`],maxRuntimeMs:`1800000`,maxToolCalls:`300`,enabledAsSubagent:!0}}function x(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 S(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 C(e){return!!(e.name.trim()&&e.label.trim()&&e.allowedTools.length>0)}async function w(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 T(){let[e,n]=(0,v.useState)([]),[s,T]=(0,v.useState)([]),[E,D]=(0,v.useState)(!1),[O,k]=(0,v.useState)(null),[A,j]=(0,v.useState)(()=>b()),[M,N]=(0,v.useState)(!1),[P,F]=(0,v.useState)(``),[I,L]=(0,v.useState)(!1),[R,z]=(0,v.useState)(),[B,V]=(0,v.useState)(`off`),[H,U]=(0,v.useState)(``),[W,G]=(0,v.useState)(null);async function K(){let[e,t]=await Promise.all([w(`/api/agent-profiles`),w(`/api/agent-profiles/available-tools`)]);n(e.agents),T(t.tools)}(0,v.useEffect)(()=>{let e=!1;async function t(){try{let[t,r]=await Promise.all([w(`/api/agent-profiles`),w(`/api/agent-profiles/available-tools`)]);if(e)return;n(t.agents),T(r.tools)}catch(t){e||U(t instanceof Error?t.message:d(`requestFailed`))}}return t(),()=>{e=!0}},[]),(0,v.useEffect)(()=>{let e=!1;async function t(){try{let t=await c(),n=await l(t),r=await m(t),i=r.model??await _(t)??n[0];if(e)return;z(i),V(r.thinkingLevel??g(i))}catch{}}return t(),()=>{e=!0}},[]),(0,v.useEffect)(()=>{if(!W)return;let e=()=>G(null);return window.addEventListener(`click`,e),window.addEventListener(`blur`,e),()=>{window.removeEventListener(`click`,e),window.removeEventListener(`blur`,e)}},[W]);let q=(0,v.useMemo)(()=>e.find(e=>e.id===O)??null,[e,O]);function J(e,t){j(n=>({...n,[e]:t}))}function Y(e){j(t=>({...t,allowedTools:t.allowedTools.includes(e)?t.allowedTools.filter(t=>t!==e):[...t.allowedTools,e]}))}function X(){k(null),j(b()),F(``),U(``),D(!0)}function Z(e){k(e.id),j(x(e)),F(``),U(``),D(!0)}function Q(){M||I||(D(!1),k(null),j(b()),F(``))}async function $(){let e=P.trim();if(!e){U(d(`aiFillAgentInputRequired`));return}if(!R){U(d(`aiFillAgentNoModel`));return}L(!0),U(``);try{let t=await w(`/api/agent-profiles/ai-fill`,{method:`POST`,body:JSON.stringify({instruction:e,model:R,thinkingLevel:B})});j(e=>({...e,name:t.agent.name,label:t.agent.label,description:t.agent.description,systemPrompt:t.agent.systemPrompt}))}catch(e){U(e instanceof Error?e.message:d(`aiFillAgentFailed`))}finally{L(!1)}}async function ee(){if(C(A)){N(!0),U(``);try{let e=S(A);O?await w(`/api/agent-profiles/${encodeURIComponent(O)}`,{method:`PATCH`,body:JSON.stringify(e)}):await w(`/api/agent-profiles`,{method:`POST`,body:JSON.stringify(e)}),Q(),await K()}catch(e){U(e instanceof Error?e.message:d(`requestFailed`))}finally{N(!1)}}}async function te(e){if(e.builtin||e.readonly)return;let t=!e.enabledAsSubagent,r=e.enabledAsSubagent;n(n=>n.map(n=>n.id===e.id?{...n,enabledAsSubagent:t}:n)),G(null);try{await w(`/api/agent-profiles/${encodeURIComponent(e.id)}`,{method:`PATCH`,body:JSON.stringify({enabledAsSubagent:t})})}catch(t){n(t=>t.map(t=>t.id===e.id?{...t,enabledAsSubagent:r}:t)),U(t instanceof Error?t.message:d(`requestFailed`))}}async function ne(e){if(!(e.builtin||e.readonly)&&await f({description:d(`confirmDeleteAgent`),confirmLabel:d(`confirmDelete`),cancelLabel:d(`cancel`),variant:`destructive`})){U(``);try{await w(`/api/agent-profiles/${encodeURIComponent(e.id)}`,{method:`DELETE`}),await K()}catch(e){U(e instanceof Error?e.message:d(`requestFailed`))}}}return(0,y.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden bg-background`,children:[(0,y.jsx)(`div`,{className:`border-b border-border px-6 py-5`,children:(0,y.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,y.jsx)(`div`,{className:`flex size-10 items-center justify-center rounded-2xl bg-primary/10 text-primary`,children:(0,y.jsx)(t,{className:`size-5`})}),(0,y.jsx)(`div`,{children:(0,y.jsxs)(`h1`,{className:`inline-flex items-center gap-1.5 text-lg font-semibold text-foreground`,children:[d(`agentsTab`),(0,y.jsx)(p,{label:d(`agentsDescription`)})]})})]}),(0,y.jsx)(h,{onClick:X,children:d(`createAgent`)})]})}),(0,y.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-6`,children:(0,y.jsxs)(`div`,{className:`mx-auto max-w-5xl space-y-5`,children:[H&&!E?(0,y.jsx)(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive`,children:H}):null,(0,y.jsx)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:e.map(e=>(0,y.jsxs)(`div`,{className:`rounded-xl border border-border bg-card p-4`,children:[(0,y.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,y.jsxs)(`div`,{className:`min-w-0`,children:[(0,y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,y.jsx)(`h3`,{className:u(`truncate text-sm font-medium`,e.enabledAsSubagent?`text-foreground/90`:`text-muted-foreground`),children:e.label}),e.builtin?(0,y.jsx)(`span`,{className:`rounded-full bg-primary/10 px-2 py-0.5 text-xs text-primary`,children:d(`builtinAgent`)}):null]}),(0,y.jsx)(`p`,{className:`mt-1 font-mono text-xs text-muted-foreground`,children:e.name}),e.source&&!e.builtin?(0,y.jsxs)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:[e.source,e.relativePath?` · ${e.relativePath}`:``]}):null,(0,y.jsx)(`p`,{className:`mt-2 text-sm text-muted-foreground`,children:e.description||d(`noDescription`)})]}),(0,y.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,onClick:e=>e.stopPropagation(),children:[(0,y.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":e.enabledAsSubagent,disabled:e.builtin||e.readonly,className:u(`relative h-6 w-11 rounded-full transition-colors disabled:cursor-not-allowed disabled:opacity-60`,e.enabledAsSubagent?`bg-emerald-500`:`bg-muted-foreground/30`),onClick:()=>void te(e),title:e.enabledAsSubagent?d(`disableAsSubagent`):d(`enableAsSubagent`),children:(0,y.jsx)(`span`,{className:u(`absolute left-0.5 top-0.5 size-5 rounded-full bg-white shadow transition-transform`,e.enabledAsSubagent?`translate-x-5`:`translate-x-0`)})}),(0,y.jsxs)(`div`,{className:`relative`,children:[(0,y.jsx)(h,{variant:`ghost`,size:`icon`,onClick:()=>G(W===e.id?null:e.id),title:d(`moreActions`),children:(0,y.jsx)(o,{className:`size-4`})}),W===e.id?(0,y.jsxs)(`div`,{className:`absolute right-0 z-20 mt-1 w-36 overflow-hidden rounded-xl border border-border bg-popover py-1 text-sm shadow-quickforge`,children:[(0,y.jsxs)(`button`,{className:`flex w-full items-center gap-2 px-3 py-2 text-left hover:bg-muted disabled:cursor-not-allowed disabled:opacity-50`,disabled:e.builtin||e.readonly,onClick:()=>{G(null),Z(e)},children:[(0,y.jsx)(r,{className:`size-3.5`}),d(`editTask`)]}),(0,y.jsxs)(`button`,{className:`flex w-full items-center gap-2 px-3 py-2 text-left text-destructive hover:bg-muted disabled:cursor-not-allowed disabled:opacity-50`,disabled:e.builtin||e.readonly,onClick:()=>{G(null),ne(e)},children:[(0,y.jsx)(i,{className:`size-3.5`}),d(`delete`)]})]}):null]})]})]}),(0,y.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-1`,children:e.allowedTools.map(e=>(0,y.jsx)(`span`,{className:`rounded-full bg-muted px-2 py-0.5 font-mono text-xs text-muted-foreground`,children:e},e))}),(0,y.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,y.jsxs)(`span`,{children:[d(`maxRuntimeMs`),e.maxRuntimeMs??`-`]}),(0,y.jsxs)(`span`,{children:[d(`maxToolCalls`),e.maxToolCalls??`-`]})]})]},e.id))})]})}),E?(0,y.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4`,onMouseDown:e=>{e.target===e.currentTarget&&Q()},children:(0,y.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,y.jsxs)(`div`,{className:`shrink-0 border-b border-border px-5 py-4`,children:[(0,y.jsx)(`h2`,{className:`text-base font-medium text-foreground`,children:d(q?`editAgent`:`createAgent`)}),q?.readonly?(0,y.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:d(`builtinAgentReadonly`)}):null]}),(0,y.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-5 py-4`,children:(0,y.jsxs)(`div`,{className:`space-y-4`,children:[(0,y.jsxs)(`div`,{className:`rounded-2xl border border-border bg-muted/20 p-3`,children:[(0,y.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 text-sm font-medium text-foreground`,children:[(0,y.jsx)(a,{className:`size-4 text-primary`}),d(`aiFillAgent`),(0,y.jsx)(p,{label:d(`aiFillAgentDescription`)})]}),(0,y.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:P,disabled:!!q?.readonly||I,onChange:e=>F(e.target.value),placeholder:d(`aiFillAgentPlaceholder`)}),(0,y.jsx)(`div`,{className:`mt-2 flex justify-end`,children:(0,y.jsxs)(h,{variant:`outline`,size:`sm`,onClick:()=>void $(),disabled:!!q?.readonly||I||!P.trim(),children:[(0,y.jsx)(a,{className:`mr-1 size-3.5`}),d(I?`aiFillAgentLoading`:`aiFillAgent`)]})})]}),(0,y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,y.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[d(`agentName`),(0,y.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:A.name,disabled:!!q?.readonly,onChange:e=>J(`name`,e.target.value),placeholder:`reviewer`})]}),(0,y.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[d(`agentLabel`),(0,y.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:A.label,disabled:!!q?.readonly,onChange:e=>J(`label`,e.target.value),placeholder:d(`agentLabelPlaceholder`)})]})]}),(0,y.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[d(`agentDescription`),(0,y.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:A.description,disabled:!!q?.readonly,onChange:e=>J(`description`,e.target.value)})]}),(0,y.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[d(`agentSystemPrompt`),(0,y.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:A.systemPrompt,disabled:!!q?.readonly,onChange:e=>J(`systemPrompt`,e.target.value)})]}),(0,y.jsxs)(`div`,{children:[(0,y.jsx)(`div`,{className:`mb-2 text-sm font-medium text-foreground`,children:d(`allowedTools`)}),(0,y.jsx)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:s.map(e=>(0,y.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,y.jsx)(`input`,{type:`checkbox`,className:`mt-1`,disabled:!!q?.readonly,checked:A.allowedTools.includes(e.name),onChange:()=>Y(e.name)}),(0,y.jsxs)(`span`,{children:[(0,y.jsx)(`span`,{className:`font-medium text-foreground`,children:e.label}),(0,y.jsx)(`span`,{className:`ml-2 font-mono text-xs text-muted-foreground`,children:e.name}),e.riskLevel===`dangerous`?(0,y.jsx)(`span`,{className:`ml-2 rounded-full bg-amber-500/10 px-2 py-0.5 text-xs text-amber-700`,children:d(`highRiskTool`)}):null,(0,y.jsx)(`span`,{className:`mt-1 block text-xs text-muted-foreground`,children:e.description})]})]},e.name))})]}),(0,y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,y.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[d(`maxRuntimeMs`),(0,y.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:A.maxRuntimeMs,disabled:!!q?.readonly,onChange:e=>J(`maxRuntimeMs`,e.target.value)})]}),(0,y.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[d(`maxToolCalls`),(0,y.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:A.maxToolCalls,disabled:!!q?.readonly,onChange:e=>J(`maxToolCalls`,e.target.value)})]})]}),(0,y.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-foreground`,children:[(0,y.jsx)(`input`,{type:`checkbox`,checked:A.enabledAsSubagent,disabled:!!q?.readonly,onChange:e=>J(`enabledAsSubagent`,e.target.checked)}),d(`enabledAsSubagent`)]}),H?(0,y.jsx)(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive`,children:H}):null]})}),(0,y.jsx)(`div`,{className:`shrink-0 border-t border-border px-5 py-4`,children:(0,y.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,y.jsx)(h,{variant:`outline`,onClick:Q,disabled:M||I,children:d(`cancel`)}),(0,y.jsx)(h,{onClick:ee,disabled:M||I||!!q?.readonly||!C(A),children:d(`save`)})]})})]})}):null]})}export{T as AgentProfilesPage};
@@ -1,4 +1,4 @@
1
- import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{R as t,wt as n}from"./icons-DzxBk7tb.js";import{n as r,t as i}from"./react-vendor-DsAeMFcm.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-DTiIspXQ.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{B as t,Et as n}from"./icons-Uo4Gd-eK.js";import{n as r,t as i}from"./react-vendor-BjDQPVuK.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-DiaCCmXE.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(`
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 ee(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 te(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 N(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 ne(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 re(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 P(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 ie(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}">
@@ -239,4 +239,4 @@ import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{R as t,wt as n}from"./
239
239
  <span></span>
240
240
  <span></span>
241
241
  </div>
242
- `),g.previousElementSibling!==m&&m.after(g),!0}function Ir(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}It({editor:S,onInput:d,onFilesChange:p,removeCommandSuggestions:m,updateCommandSuggestions:h,removeCapabilitySuggestions:_,updateCapabilitySuggestions:v,onBeforeSend:x}),g(S),y(S),Nt(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){if(Mt(S,D),Ft({rightControls:D,isStreaming:n,abort:r,removeCommandSuggestions:m}),!E){t.querySelector(`.quickforge-plus-inline`)?.remove(),wt(t),t.querySelector(`.quickforge-agent-access-inline`)?.remove(),yt(t),t.querySelector(`.quickforge-yolo-inline`)?.remove(),t.querySelector(`.quickforge-plan-inline`)?.remove();return}if(S&&At({panel:t,editor:S,leftControls:E,insertBuiltinPluginMention:b,removeCommandSuggestions:m,removeCapabilitySuggestions:_}),Pt({panel:t,leftControls:E,planMode:a,onTogglePlanMode:u}),!o){t.querySelector(`.quickforge-agent-access-inline`)?.remove(),yt(t),t.querySelector(`.quickforge-yolo-inline`)?.remove();return}St({panel:t,leftControls:E,agentAccessMode:i,onAccessModeChange:l,dismissComposerMenus:()=>wt(t)})}}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 Lr(e,t){let n=e[t];return typeof n==`boolean`?n:void 0}function Rr(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:void 0}function zr(e){let t=e&&Q(e.diff)?e.diff:void 0;return{addedLines:t?Rr(t,`addedLines`):void 0,removedLines:t?Rr(t,`removedLines`):void 0}}function Br(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 Vr(e){return e===`html`||e===`image`||e===`markdown`||e===`code`}function Hr(e){return[e.source,e.path??``,e.command??``,e.outputFile??``,e.toolCallId??``,e.preview?`preview`:``].join(`\0`)}function Ur(e,t,n){let r=Hr(n);t.has(r)||(t.add(r),e.push({id:`${e.length}:${r}`,...n}))}function Wr(e){if(!(typeof e!=`string`||!e.trim()))try{return JSON.parse(e)}catch{return}}function Gr(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=Wr(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=Wr(e.text);if(Q(t)&&(Array.isArray(t.files)||Array.isArray(t.previewed)))return t}return t}function Kr(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:Lr(e,`preview`)}:void 0}}function qr(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=Br(r),{addedLines:s,removedLines:c}=zr(i);Ur(n,t,{source:e,confidence:`high`,path:r,toolCallId:a,kind:o,preview:Vr(o),presentation:`inferred`,addedLines:s,removedLines:c})}}else if(e===`present_files`){let e=Gr(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=Kr(e);if(!r?.path)continue;let i=r.kind??Br(r.path);Ur(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||Vr(i)),defaultPreview:s===r.path,presentation:`explicit`})}}else if(e===`run_command`&&i){let e=$(i,`command`),r=$(i,`outputFile`);(e||r)&&Ur(n,t,{source:`run_command`,confidence:`low`,command:e,outputFile:r,toolCallId:a})}}}return n}function Jr(e){return e?.length?qr(e):[]}var Yr=`quickforge:composer-drafts:v1`,Xr=100,Zr={},Qr=!1;function $r(e){return!!(e&&!e.startsWith(`pending-`))}function ei(e){return $r(e.sessionId)?`session:${e.sessionId}`:e.scope===`project`&&e.projectId?`new:project:${e.projectId}`:`new:global`}function ti(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}function ni(){try{return globalThis.localStorage}catch{return}}function ri(e,t=Xr){return Object.fromEntries(Object.entries(e).filter(([,e])=>e.text.length>0).sort(([,e],[,t])=>t.updatedAt.localeCompare(e.updatedAt)).slice(0,t))}function ii(){let e=ni();if(!e||Qr)return Zr;let t;try{t=e.getItem(Yr)}catch{return Qr=!0,Zr}try{return ti(t?JSON.parse(t):void 0)}catch{return Zr}}function ai(e){let t=ri(e);Zr=t;let n=ni();if(!(!n||Qr))try{Object.keys(t).length===0?n.removeItem(Yr):n.setItem(Yr,JSON.stringify(t))}catch{let e=ri(t,Math.ceil(Xr/2));Zr=e;try{Object.keys(e).length===0?n.removeItem(Yr):n.setItem(Yr,JSON.stringify(e))}catch{Qr=!0}}}async function oi(e){let t=ii()[e];if(!(!t||t.text.length===0))return{text:t.text,attachments:[]}}async function si(e,t,n){let r=t.text??``;if(r.length===0){await ci(e);return}let i=ii();i[e]={text:r,updatedAt:new Date().toISOString(),scope:n.scope,projectId:n.scope===`project`?n.projectId:void 0,sessionId:$r(n.sessionId)?n.sessionId:void 0},ai(i)}async function ci(e){let t=ii();Object.prototype.hasOwnProperty.call(t,e)&&(delete t[e],ai(t))}var li=r();function ui(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 di(e){let t=String(e.length);for(let n of e)n.role===`toolResult`&&(t+=`|${n.toolCallId??``}:${n.toolName??``}`);return t}function fi({agent:e,onModelSelect:t,revision:n,agentAccessMode:r,workspaceToolsEnabled:i,project:a,projectId:o,chatScope:s=`global`,onAccessModeChange:l,onRollbackFromMessage:p,onRetryFromMessage:h,onCopyAnswer:g,onForkFromMessage:_,onApproveToolCall:v,onRejectToolCall:y,onApproveAutoCompact:b,onRejectAutoCompact:S,onOpenWorkspaceGitChanges:C,onOpenLocalFilePath:w,onArtifactsChange:T,onContextUsageDisplayChange:E,restoredDraft:D,disableFork:O=!1,readOnly:k=!1,bypassClientApiKeyCheck:A=!1,allowModelControls:j=!0,newChatEmptyState:M=!1,rollbackConfirmTitle:ee,rollbackConfirmDescription:te}){let N=(0,x.useRef)(null),ne=(0,x.useRef)(void 0),re=(0,x.useRef)(void 0),P=(0,x.useRef)(new Map),ie=(0,x.useRef)([]),ae=(0,x.useRef)(void 0),oe=(0,x.useRef)(new Set),F=(0,x.useRef)(void 0),se=(0,x.useRef)(``),ce=(0,x.useRef)(``),[le,ue]=(0,x.useState)(),[I,de]=(0,x.useState)(!1),fe=(0,x.useCallback)(()=>de(e=>!e),[]),pe=(0,x.useCallback)(()=>de(!1),[]);(0,x.useEffect)(()=>{e?.setPlanMode?.(I,I?pe:void 0)},[e,I,pe]);let L=(0,x.useCallback)(()=>{F.current&&=(window.clearTimeout(F.current),void 0)},[]),me=(0,x.useMemo)(()=>({sessionId:e?.sessionId,scope:s,projectId:o}),[e?.sessionId,s,o]),he=ei(me),ge=(0,x.useRef)(me),R=(0,x.useRef)(he);(0,x.useEffect)(()=>{ge.current=me,R.current=he},[me,he]),(0,x.useEffect)(()=>()=>{L()},[L]);let z=(0,x.useCallback)((e,t,n)=>{if(t.text.length===0){ci(e).catch(e=>d.error(`Failed to clear composer draft:`,e));return}si(e,t,n).catch(e=>d.error(`Failed to save composer draft:`,e))},[]),B=(0,x.useCallback)((e,t,n)=>{F.current&&window.clearTimeout(F.current),F.current=window.setTimeout(()=>{F.current=void 0,z(e,t,n)},400)},[z]),V=(0,x.useCallback)((e,t=R.current,n=ge.current)=>{let r=Lt(e);q(r)?P.current.set(t,r):P.current.delete(t),z(t,r,n)},[z]),H=(0,x.useRef)({onCopyAnswer:g,onRollbackFromMessage:p,onRetryFromMessage:h,onForkFromMessage:_,onAccessModeChange:l,onTogglePlanMode:fe,onApproveToolCall:v,onRejectToolCall:y,onApproveAutoCompact:b,onRejectAutoCompact:S,onOpenWorkspaceGitChanges:C,onOpenLocalFilePath:w,onArtifactsChange:T,onContextUsageDisplayChange:E,onModelSelect:t,agentAccessMode:r,planMode:I,workspaceToolsEnabled:i,disableFork:O,readOnly:k,allowModelControls:j,newChatEmptyState:M,bypassClientApiKeyCheck:A,rollbackConfirmTitle:ee,rollbackConfirmDescription:te,gitBranch:le});(0,x.useEffect)(()=>{H.current={onCopyAnswer:g,onRollbackFromMessage:p,onRetryFromMessage:h,onForkFromMessage:_,onAccessModeChange:l,onTogglePlanMode:fe,onApproveToolCall:v,onRejectToolCall:y,onApproveAutoCompact:b,onRejectAutoCompact:S,onOpenWorkspaceGitChanges:C,onOpenLocalFilePath:w,onArtifactsChange:T,onContextUsageDisplayChange:E,onModelSelect:t,agentAccessMode:r,planMode:I,workspaceToolsEnabled:i,disableFork:O,readOnly:k,allowModelControls:j,newChatEmptyState:M,bypassClientApiKeyCheck:A,rollbackConfirmTitle:ee,rollbackConfirmDescription:te,gitBranch:le},re.current=D});let _e=a?.id??o;(0,x.useEffect)(()=>{let e=!1;return queueMicrotask(()=>{if(!e){if(!_e){ue(void 0);return}m(_e).then(t=>{e||ue(t.isGitRepository?t.branch:void 0)}).catch(t=>{e||(d.warn(`Failed to load git branch:`,t),ue(void 0))})}}),()=>{e=!0}},[_e,n]);let ve=(0,x.useRef)(null),ye=(0,x.useRef)(null),U=(0,x.useRef)(null),W=(0,x.useRef)(null),G=(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||(ie.current=Array.isArray(t.commands)?t.commands:[],U.current?.())}).catch(()=>{e||(ie.current=[],U.current?.())}),()=>{e=!0}):(ie.current=[],()=>{e=!0})},[a?.id,n]);let be=(e,t,n,r,i=!1)=>{if(t.sessionId&&t.sessionId!==n||!q(t)||!i&&oe.current.has(t.id))return;let a=()=>{if(!i&&oe.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]:[]}:P.current.get(r),o=ae.current;(o?.id!==t.id||!q(a??Te())||a?.text===o.text)&&(zt(e,t,P.current,r),ae.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(!N.current||!e)return;let t=new c;de(!1);let n=e.sessionId,r=R.current,i=ge.current,a=!1,o,s=!1,l=e.state.isStreaming,p=!1,m=Fe({panel:t});ye.current=m;let h=Ie({panel:t,getCustomCommands:()=>ie.current,getComposerDrafts:()=>P.current,sessionId:r,setComposerDrafts:e=>{P.current=e},restoreDraftIntoComposer:e=>{zt(t,e,P.current,r),B(r,e,i)}}),g=We({panel:t,restoreDraftIntoComposer:e=>{zt(t,e,P.current,r),B(r,e,i)}}),_=et({panel:t,getSystemPrompt:()=>e.state.systemPrompt,getMessages:()=>e.state.messages,getEffectiveMessages:()=>ui(e),getContextWindow:()=>e.state.model?.contextWindow??0,getTools:()=>e.state.tools,getMaxTokens:()=>e.state.model?.maxTokens,getServerContextUsage:()=>e.state.contextUsage??null,getGitBranch:()=>H.current.gitBranch,onGitBranchClick:()=>H.current.onOpenWorkspaceGitChanges?.(),renderInline:!1,onDisplayChange:t=>H.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)?P.current.set(r,a):P.current.delete(r),B(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)?P.current.set(r,o):P.current.delete(r),B(r,o,i);let c=t.querySelector(`agent-interface`);c?.requestUpdate?.(),window.requestAnimationFrame(()=>U.current?.()),c?.updateComplete?.then(()=>U.current?.())},b=()=>{e.state.isStreaming?t.dataset.quickforgeAgentStreaming=`true`:delete t.dataset.quickforgeAgentStreaming},x=()=>{if(a||!t.isConnected)return;b();let n=H.current,r=di(e.state.messages);if(r!==ce.current){ce.current=r;let t=Jr(e.state.messages),i=JSON.stringify(t.map(e=>[e.source,e.path,e.command,e.outputFile,e.confidence,e.preview,e.defaultPreview,e.addedLines,e.removedLines]));i!==se.current&&(se.current=i,n.onArtifactsChange?.(t))}try{Er({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}),en({panel:t,getMessages:()=>e.state.messages,getContextCompaction:()=>e.state.contextCompaction??null}),Fr({panel:t,getMessages:()=>e.state.messages,isStreaming:()=>e.state.isStreaming,isActive:l})}catch{}try{Ir({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 i=W.current;if(i&&i.sessionId===e.sessionId){let e=i.toolCallId;Kt({panel:t,onApprove:async()=>{await H.current.onApproveToolCall(e),W.current=null,qt(t)},onReject:async()=>{await H.current.onRejectToolCall(e),W.current=null,qt(t)}},i.toolName,e,i.args,i.source)}else{let n=G.current;if(n&&n.sessionId===e.sessionId){let e=n.approvalId;Kt({panel:t,onApprove:async()=>{await H.current.onApproveAutoCompact?.(e),G.current=null,qt(t)},onReject:async()=>{await H.current.onRejectAutoCompact?.(e),G.current=null,qt(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 qt(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()}))};ve.current=D;let k=()=>{p||(p=!0,window.requestAnimationFrame(()=>{if(p=!1,a)return;b();let e=t.querySelector(`agent-interface`);e?.requestUpdate?.(),U.current?.(),e?.updateComplete?.then(()=>U.current?.()),m.isEnabled&&m.scheduleScrollToBottom()}))};U.current=O,t.setAgent(e,{onApiKeyRequired:H.current.bypassClientApiKeyCheck?async()=>!0:e=>u.prompt(e),onBeforeSend:()=>{let e=re.current;e&&oe.current.add(e.id),L(),s=!0,h.remove(),P.current.delete(r),ci(r).catch(e=>d.error(`Failed to clear composer draft:`,e)),m.enable()},onModelSelect:H.current.onModelSelect,toolsFactory:()=>Ce(e.state.tools)}).then(()=>{if(a)return;let e=re.current,i=i=>{a||(e&&ne.current!==e.id?(ne.current=e.id,be(t,e,n,r)):zt(t,i??P.current.get(r)??Te(),P.current,r))};if(e&&ne.current!==e.id)i();else{let e=P.current.get(r);e?i(e):oi(r).then(e=>i(e)).catch(e=>d.error(`Failed to load composer draft:`,e))}o=new MutationObserver(()=>{w||O()}),o.observe(t,{childList:!0,subtree:!0}),window.requestAnimationFrame(()=>{a||D()})}),N.current.replaceChildren(t);let A=e.subscribe(i=>{if(i.type===`agent_start`&&(l=!0,b(),U.current?.(),m.enable(),W.current?.sessionId===e.sessionId&&(W.current=null),G.current?.sessionId===e.sessionId&&(G.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),U.current?.(),m.isEnabled&&m.scheduleScrollToBottom()}if(i.type===`messages_replaced`){let e=re.current;e&&ne.current===e.id&&be(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?.(),U.current?.(),window.requestAnimationFrame(()=>U.current?.()),e?.updateComplete?.then(()=>U.current?.()),m.isEnabled&&m.scheduleScrollToBottom()}if(a===`tool_execution_update`&&k(),i.type===`agent_end`&&(l=!1,b(),U.current?.(),W.current?.sessionId===e.sessionId&&(W.current=null,U.current?.()),G.current?.sessionId===e.sessionId&&(G.current=null,U.current?.())),a===`auto_compact_completed`||a===`messages_replaced`){let e=t.querySelector(`agent-interface`);e?.requestUpdate?.(),U.current?.(),window.requestAnimationFrame(()=>U.current?.()),e?.updateComplete?.then(()=>U.current?.())}if(a===`auto_compact_failed`&&d.warn(f(`autoCompactFailed`)),i.type===`tool_approval_required`){let e=i;W.current={toolCallId:e.toolCallId,toolName:e.toolName,args:e.args,sessionId:e.sessionId,source:e.source},U.current?.()}if(i.type===`auto_compact_approval_required`){let e=i;G.current={approvalId:e.approvalId,usage:e.usage,thresholdPercent:e.thresholdPercent,keepRecentTurns:e.keepRecentTurns,sessionId:e.sessionId},U.current?.()}});return()=>{s?(L(),P.current.delete(r),ci(r).catch(e=>d.error(`Failed to clear composer draft:`,e))):(Rt(t,P.current,r),V(t,r,i)),h.remove(),h.cleanupTextareaHandler(),g.remove(),g.cleanupTextareaHandler(),a=!0,m.cleanup(),ye.current=null,A(),o?.disconnect(),C!==void 0&&window.cancelAnimationFrame(C),T!==void 0&&window.cancelAnimationFrame(T),ve.current=null,t.remove()}},[e,L,V,B]),(0,x.useEffect)(()=>{let e=N.current;e&&(e.classList.toggle(`quickforge-chat-panel-empty-host`,M),e.dataset.quickforgeEmptyChat=M?`true`:`false`)},[M]),(0,x.useEffect)(()=>{ve.current?.(),(N.current?.querySelector(`agent-interface`))?.requestUpdate?.()},[r,I,i,le,O,k,j,n]),(0,x.useEffect)(()=>{let t=re.current;if(!t||!N.current)return;let n=e?.sessionId??``;if(t.sessionId&&t.sessionId!==n)return;let r=N.current.querySelector(`pi-chat-panel`);r&&(ne.current=t.id,be(r,t,n,R.current,!0))},[D,e]),(0,li.jsx)(`div`,{ref:N,className:`min-h-0 flex-1 overflow-hidden`})}export{fi as ChatPanelHost};
242
+ `),g.previousElementSibling!==m&&m.after(g),!0}function Ir(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}It({editor:S,onInput:d,onFilesChange:p,removeCommandSuggestions:m,updateCommandSuggestions:h,removeCapabilitySuggestions:_,updateCapabilitySuggestions:v,onBeforeSend:x}),g(S),y(S),Nt(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){if(Mt(S,D),Ft({rightControls:D,isStreaming:n,abort:r,removeCommandSuggestions:m}),!E){t.querySelector(`.quickforge-plus-inline`)?.remove(),wt(t),t.querySelector(`.quickforge-agent-access-inline`)?.remove(),yt(t),t.querySelector(`.quickforge-yolo-inline`)?.remove(),t.querySelector(`.quickforge-plan-inline`)?.remove();return}if(S&&At({panel:t,editor:S,leftControls:E,insertBuiltinPluginMention:b,removeCommandSuggestions:m,removeCapabilitySuggestions:_}),Pt({panel:t,leftControls:E,planMode:a,onTogglePlanMode:u}),!o){t.querySelector(`.quickforge-agent-access-inline`)?.remove(),yt(t),t.querySelector(`.quickforge-yolo-inline`)?.remove();return}St({panel:t,leftControls:E,agentAccessMode:i,onAccessModeChange:l,dismissComposerMenus:()=>wt(t)})}}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 Lr(e,t){let n=e[t];return typeof n==`boolean`?n:void 0}function Rr(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:void 0}function zr(e){let t=e&&Q(e.diff)?e.diff:void 0;return{addedLines:t?Rr(t,`addedLines`):void 0,removedLines:t?Rr(t,`removedLines`):void 0}}function Br(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 Vr(e){return e===`html`||e===`image`||e===`markdown`||e===`code`}function Hr(e){return[e.source,e.path??``,e.command??``,e.outputFile??``,e.toolCallId??``,e.preview?`preview`:``].join(`\0`)}function Ur(e,t,n){let r=Hr(n);t.has(r)||(t.add(r),e.push({id:`${e.length}:${r}`,...n}))}function Wr(e){if(!(typeof e!=`string`||!e.trim()))try{return JSON.parse(e)}catch{return}}function Gr(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=Wr(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=Wr(e.text);if(Q(t)&&(Array.isArray(t.files)||Array.isArray(t.previewed)))return t}return t}function Kr(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:Lr(e,`preview`)}:void 0}}function qr(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=Br(r),{addedLines:s,removedLines:c}=zr(i);Ur(n,t,{source:e,confidence:`high`,path:r,toolCallId:a,kind:o,preview:Vr(o),presentation:`inferred`,addedLines:s,removedLines:c})}}else if(e===`present_files`){let e=Gr(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=Kr(e);if(!r?.path)continue;let i=r.kind??Br(r.path);Ur(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||Vr(i)),defaultPreview:s===r.path,presentation:`explicit`})}}else if(e===`run_command`&&i){let e=$(i,`command`),r=$(i,`outputFile`);(e||r)&&Ur(n,t,{source:`run_command`,confidence:`low`,command:e,outputFile:r,toolCallId:a})}}}return n}function Jr(e){return e?.length?qr(e):[]}var Yr=`quickforge:composer-drafts:v1`,Xr=100,Zr={},Qr=!1;function $r(e){return!!(e&&!e.startsWith(`pending-`))}function ei(e){return $r(e.sessionId)?`session:${e.sessionId}`:e.scope===`project`&&e.projectId?`new:project:${e.projectId}`:`new:global`}function ti(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}function ni(){try{return globalThis.localStorage}catch{return}}function ri(e,t=Xr){return Object.fromEntries(Object.entries(e).filter(([,e])=>e.text.length>0).sort(([,e],[,t])=>t.updatedAt.localeCompare(e.updatedAt)).slice(0,t))}function ii(){let e=ni();if(!e||Qr)return Zr;let t;try{t=e.getItem(Yr)}catch{return Qr=!0,Zr}try{return ti(t?JSON.parse(t):void 0)}catch{return Zr}}function ai(e){let t=ri(e);Zr=t;let n=ni();if(!(!n||Qr))try{Object.keys(t).length===0?n.removeItem(Yr):n.setItem(Yr,JSON.stringify(t))}catch{let e=ri(t,Math.ceil(Xr/2));Zr=e;try{Object.keys(e).length===0?n.removeItem(Yr):n.setItem(Yr,JSON.stringify(e))}catch{Qr=!0}}}async function oi(e){let t=ii()[e];if(!(!t||t.text.length===0))return{text:t.text,attachments:[]}}async function si(e,t,n){let r=t.text??``;if(r.length===0){await ci(e);return}let i=ii();i[e]={text:r,updatedAt:new Date().toISOString(),scope:n.scope,projectId:n.scope===`project`?n.projectId:void 0,sessionId:$r(n.sessionId)?n.sessionId:void 0},ai(i)}async function ci(e){let t=ii();Object.prototype.hasOwnProperty.call(t,e)&&(delete t[e],ai(t))}var li=r();function ui(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 di(e){let t=String(e.length);for(let n of e)n.role===`toolResult`&&(t+=`|${n.toolCallId??``}:${n.toolName??``}`);return t}function fi({agent:e,onModelSelect:t,revision:n,agentAccessMode:r,workspaceToolsEnabled:i,project:a,projectId:o,chatScope:s=`global`,onAccessModeChange:l,onRollbackFromMessage:p,onRetryFromMessage:h,onCopyAnswer:g,onForkFromMessage:_,onApproveToolCall:v,onRejectToolCall:y,onApproveAutoCompact:b,onRejectAutoCompact:S,onOpenWorkspaceGitChanges:C,onOpenLocalFilePath:w,onArtifactsChange:T,onContextUsageDisplayChange:E,restoredDraft:D,disableFork:O=!1,readOnly:k=!1,bypassClientApiKeyCheck:A=!1,allowModelControls:j=!0,newChatEmptyState:M=!1,rollbackConfirmTitle:ee,rollbackConfirmDescription:te}){let N=(0,x.useRef)(null),ne=(0,x.useRef)(void 0),re=(0,x.useRef)(void 0),P=(0,x.useRef)(new Map),ie=(0,x.useRef)([]),ae=(0,x.useRef)(void 0),oe=(0,x.useRef)(new Set),F=(0,x.useRef)(void 0),se=(0,x.useRef)(``),ce=(0,x.useRef)(``),[le,ue]=(0,x.useState)(),[I,de]=(0,x.useState)(!1),fe=(0,x.useCallback)(()=>de(e=>!e),[]),pe=(0,x.useCallback)(()=>de(!1),[]);(0,x.useEffect)(()=>{e?.setPlanMode?.(I,I?pe:void 0)},[e,I,pe]);let L=(0,x.useCallback)(()=>{F.current&&=(window.clearTimeout(F.current),void 0)},[]),me=(0,x.useMemo)(()=>({sessionId:e?.sessionId,scope:s,projectId:o}),[e?.sessionId,s,o]),he=ei(me),ge=(0,x.useRef)(me),R=(0,x.useRef)(he);(0,x.useEffect)(()=>{ge.current=me,R.current=he},[me,he]),(0,x.useEffect)(()=>()=>{L()},[L]);let z=(0,x.useCallback)((e,t,n)=>{if(t.text.length===0){ci(e).catch(e=>d.error(`Failed to clear composer draft:`,e));return}si(e,t,n).catch(e=>d.error(`Failed to save composer draft:`,e))},[]),B=(0,x.useCallback)((e,t,n)=>{F.current&&window.clearTimeout(F.current),F.current=window.setTimeout(()=>{F.current=void 0,z(e,t,n)},400)},[z]),V=(0,x.useCallback)((e,t=R.current,n=ge.current)=>{let r=Lt(e);q(r)?P.current.set(t,r):P.current.delete(t),z(t,r,n)},[z]),H=(0,x.useRef)({onCopyAnswer:g,onRollbackFromMessage:p,onRetryFromMessage:h,onForkFromMessage:_,onAccessModeChange:l,onTogglePlanMode:fe,onApproveToolCall:v,onRejectToolCall:y,onApproveAutoCompact:b,onRejectAutoCompact:S,onOpenWorkspaceGitChanges:C,onOpenLocalFilePath:w,onArtifactsChange:T,onContextUsageDisplayChange:E,onModelSelect:t,agentAccessMode:r,planMode:I,workspaceToolsEnabled:i,disableFork:O,readOnly:k,allowModelControls:j,newChatEmptyState:M,bypassClientApiKeyCheck:A,rollbackConfirmTitle:ee,rollbackConfirmDescription:te,gitBranch:le});(0,x.useEffect)(()=>{H.current={onCopyAnswer:g,onRollbackFromMessage:p,onRetryFromMessage:h,onForkFromMessage:_,onAccessModeChange:l,onTogglePlanMode:fe,onApproveToolCall:v,onRejectToolCall:y,onApproveAutoCompact:b,onRejectAutoCompact:S,onOpenWorkspaceGitChanges:C,onOpenLocalFilePath:w,onArtifactsChange:T,onContextUsageDisplayChange:E,onModelSelect:t,agentAccessMode:r,planMode:I,workspaceToolsEnabled:i,disableFork:O,readOnly:k,allowModelControls:j,newChatEmptyState:M,bypassClientApiKeyCheck:A,rollbackConfirmTitle:ee,rollbackConfirmDescription:te,gitBranch:le},re.current=D});let _e=a?.id??o;(0,x.useEffect)(()=>{let e=!1;return queueMicrotask(()=>{if(!e){if(!_e){ue(void 0);return}m(_e).then(t=>{e||ue(t.isGitRepository?t.branch:void 0)}).catch(t=>{e||(d.warn(`Failed to load git branch:`,t),ue(void 0))})}}),()=>{e=!0}},[_e,n]);let ve=(0,x.useRef)(null),ye=(0,x.useRef)(null),U=(0,x.useRef)(null),W=(0,x.useRef)(null),G=(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||(ie.current=Array.isArray(t.commands)?t.commands:[],U.current?.())}).catch(()=>{e||(ie.current=[],U.current?.())}),()=>{e=!0}):(ie.current=[],()=>{e=!0})},[a?.id,n]);let be=(e,t,n,r,i=!1)=>{if(t.sessionId&&t.sessionId!==n||!q(t)||!i&&oe.current.has(t.id))return;let a=()=>{if(!i&&oe.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]:[]}:P.current.get(r),o=ae.current;(o?.id!==t.id||!q(a??Te())||a?.text===o.text)&&(zt(e,t,P.current,r),ae.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(!N.current||!e)return;let t=new c;de(!1);let n=e.sessionId,r=R.current,i=ge.current,a=!1,o,s=!1,l=e.state.isStreaming,p=!1,m=Fe({panel:t});ye.current=m;let h=Ie({panel:t,getCustomCommands:()=>ie.current,getComposerDrafts:()=>P.current,sessionId:r,setComposerDrafts:e=>{P.current=e},restoreDraftIntoComposer:e=>{zt(t,e,P.current,r),B(r,e,i)}}),g=We({panel:t,restoreDraftIntoComposer:e=>{zt(t,e,P.current,r),B(r,e,i)}}),_=et({panel:t,getSystemPrompt:()=>e.state.systemPrompt,getMessages:()=>e.state.messages,getEffectiveMessages:()=>ui(e),getContextWindow:()=>e.state.model?.contextWindow??0,getTools:()=>e.state.tools,getMaxTokens:()=>e.state.model?.maxTokens,getServerContextUsage:()=>e.state.contextUsage??null,getGitBranch:()=>H.current.gitBranch,onGitBranchClick:()=>H.current.onOpenWorkspaceGitChanges?.(),renderInline:!1,onDisplayChange:t=>H.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)?P.current.set(r,a):P.current.delete(r),B(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)?P.current.set(r,o):P.current.delete(r),B(r,o,i);let c=t.querySelector(`agent-interface`);c?.requestUpdate?.(),window.requestAnimationFrame(()=>U.current?.()),c?.updateComplete?.then(()=>U.current?.())},b=()=>{e.state.isStreaming?t.dataset.quickforgeAgentStreaming=`true`:delete t.dataset.quickforgeAgentStreaming},x=()=>{if(a||!t.isConnected)return;b();let n=H.current,r=di(e.state.messages);if(r!==ce.current){ce.current=r;let t=Jr(e.state.messages),i=JSON.stringify(t.map(e=>[e.source,e.path,e.command,e.outputFile,e.confidence,e.preview,e.defaultPreview,e.addedLines,e.removedLines]));i!==se.current&&(se.current=i,n.onArtifactsChange?.(t))}try{Er({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}),en({panel:t,getMessages:()=>e.state.messages,getContextCompaction:()=>e.state.contextCompaction??null}),Fr({panel:t,getMessages:()=>e.state.messages,isStreaming:()=>e.state.isStreaming,isActive:l})}catch{}try{Ir({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 i=W.current;if(i&&i.sessionId===e.sessionId){let e=i.toolCallId;Kt({panel:t,onApprove:async()=>{await H.current.onApproveToolCall(e),W.current=null,qt(t)},onReject:async()=>{await H.current.onRejectToolCall(e),W.current=null,qt(t)}},i.toolName,e,i.args,i.source)}else{let n=G.current;if(n&&n.sessionId===e.sessionId){let e=n.approvalId;Kt({panel:t,onApprove:async()=>{await H.current.onApproveAutoCompact?.(e),G.current=null,qt(t)},onReject:async()=>{await H.current.onRejectAutoCompact?.(e),G.current=null,qt(t)}},f(`contextManagement`),e,{percent:n.usage?.percent??0,threshold:n.thresholdPercent??0,keepRecentTurns:n.keepRecentTurns??3,summary:f(`autoCompactApprovalWaiting`,{percent:n.usage?.percent??0,threshold:n.thresholdPercent??0}),description:f(`autoCompactApprovalPreview`,{keepRecentTurns:n.keepRecentTurns??3})})}else qt(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()}))};ve.current=D;let k=()=>{p||(p=!0,window.requestAnimationFrame(()=>{if(p=!1,a)return;b();let e=t.querySelector(`agent-interface`);e?.requestUpdate?.(),U.current?.(),e?.updateComplete?.then(()=>U.current?.()),m.isEnabled&&m.scheduleScrollToBottom()}))};U.current=O,t.setAgent(e,{onApiKeyRequired:H.current.bypassClientApiKeyCheck?async()=>!0:e=>u.prompt(e),onBeforeSend:()=>{let e=re.current;e&&oe.current.add(e.id),L(),s=!0,h.remove(),P.current.delete(r),ci(r).catch(e=>d.error(`Failed to clear composer draft:`,e)),m.enable()},onModelSelect:H.current.onModelSelect,toolsFactory:()=>Ce(e.state.tools)}).then(()=>{if(a)return;let e=re.current,i=i=>{a||(e&&ne.current!==e.id?(ne.current=e.id,be(t,e,n,r)):zt(t,i??P.current.get(r)??Te(),P.current,r))};if(e&&ne.current!==e.id)i();else{let e=P.current.get(r);e?i(e):oi(r).then(e=>i(e)).catch(e=>d.error(`Failed to load composer draft:`,e))}o=new MutationObserver(()=>{w||O()}),o.observe(t,{childList:!0,subtree:!0}),window.requestAnimationFrame(()=>{a||D()})}),N.current.replaceChildren(t);let A=e.subscribe(i=>{if(i.type===`agent_start`&&(l=!0,b(),U.current?.(),m.enable(),W.current?.sessionId===e.sessionId&&(W.current=null),G.current?.sessionId===e.sessionId&&(G.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),U.current?.(),m.isEnabled&&m.scheduleScrollToBottom()}if(i.type===`messages_replaced`){let e=re.current;e&&ne.current===e.id&&be(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?.(),U.current?.(),window.requestAnimationFrame(()=>U.current?.()),e?.updateComplete?.then(()=>U.current?.()),m.isEnabled&&m.scheduleScrollToBottom()}if(a===`tool_execution_update`&&k(),i.type===`agent_end`&&(l=!1,b(),U.current?.(),W.current?.sessionId===e.sessionId&&(W.current=null,U.current?.()),G.current?.sessionId===e.sessionId&&(G.current=null,U.current?.())),a===`auto_compact_completed`||a===`messages_replaced`){let e=t.querySelector(`agent-interface`);e?.requestUpdate?.(),U.current?.(),window.requestAnimationFrame(()=>U.current?.()),e?.updateComplete?.then(()=>U.current?.())}if(a===`auto_compact_failed`&&d.warn(f(`autoCompactFailed`)),i.type===`tool_approval_required`){let e=i;W.current={toolCallId:e.toolCallId,toolName:e.toolName,args:e.args,sessionId:e.sessionId,source:e.source},U.current?.()}if(i.type===`auto_compact_approval_required`){let e=i;G.current={approvalId:e.approvalId,usage:e.usage,thresholdPercent:e.thresholdPercent,keepRecentTurns:e.keepRecentTurns,sessionId:e.sessionId},U.current?.()}});return()=>{s?(L(),P.current.delete(r),ci(r).catch(e=>d.error(`Failed to clear composer draft:`,e))):(Rt(t,P.current,r),V(t,r,i)),h.remove(),h.cleanupTextareaHandler(),g.remove(),g.cleanupTextareaHandler(),a=!0,m.cleanup(),ye.current=null,A(),o?.disconnect(),C!==void 0&&window.cancelAnimationFrame(C),T!==void 0&&window.cancelAnimationFrame(T),ve.current=null,t.remove()}},[e,L,V,B]),(0,x.useEffect)(()=>{let e=N.current;e&&(e.classList.toggle(`quickforge-chat-panel-empty-host`,M),e.dataset.quickforgeEmptyChat=M?`true`:`false`)},[M]),(0,x.useEffect)(()=>{ve.current?.(),(N.current?.querySelector(`agent-interface`))?.requestUpdate?.()},[r,I,i,le,O,k,j,n]),(0,x.useEffect)(()=>{let t=re.current;if(!t||!N.current)return;let n=e?.sessionId??``;if(t.sessionId&&t.sessionId!==n)return;let r=N.current.querySelector(`pi-chat-panel`);r&&(ne.current=t.id,be(r,t,n,R.current,!0))},[D,e]),(0,li.jsx)(`div`,{ref:N,className:`min-h-0 flex-1 overflow-hidden`})}export{fi as ChatPanelHost};
@@ -1 +1 @@
1
- import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{F as t,i as n,l as r,r as i,v as a,wt as o,y as s}from"./icons-DzxBk7tb.js";import{n as c}from"./react-vendor-DsAeMFcm.js";import{F as l,I as u,N as d,P as f}from"./index-DTiIspXQ.js";import{n as p,r as m,t as h}from"./plugin-api-YfYj_Bd7.js";var g=e(o(),1),_=c();function v(e){return e===`loaded`?`bg-emerald-500/10 text-emerald-700 dark:text-emerald-300`:e===`error`?`bg-destructive/10 text-destructive`:`bg-muted text-muted-foreground`}function y(e){return e===`loaded`?u(`pluginStatusLoaded`):e===`disabled`?u(`pluginStatusDisabled`):e===`error`?u(`pluginStatusError`):e}function b(e){switch(e){case`openai-documents`:return{label:u(`pluginOpenaiDocumentsName`),description:u(`pluginOpenaiDocumentsDescription`)};case`openai-spreadsheets`:return{label:u(`pluginOpenaiSpreadsheetsName`),description:u(`pluginOpenaiSpreadsheetsDescription`)};case`openai-presentations`:return{label:u(`pluginOpenaiPresentationsName`),description:u(`pluginOpenaiPresentationsDescription`)};default:return null}}function x(e){return b(e.name)?.label||(e.displayName||e.name).replace(/^OpenAI\s+/i,``)}function S(e){return b(e.name)?.description||e.description||u(`noDescription`)}function C(e){return(e.label||e.name||e.quickForgeName).replace(/^OpenAI\s+/i,``)}function w({onChanged:e}){let[o,c]=(0,g.useState)(null),[b,w]=(0,g.useState)(!0),[T,E]=(0,g.useState)(null),[D,O]=(0,g.useState)(null),[k,A]=(0,g.useState)(null),j=(0,g.useCallback)(async(t=`load`)=>{A(null),w(!0);try{c(t===`reload`?await p():await h()),t===`reload`&&e?.()}catch(e){A(e instanceof Error?e.message:u(`pluginsLoadFailed`))}finally{w(!1)}},[e]);(0,g.useEffect)(()=>{let e=!1;return h().then(t=>{e||c(t)}).catch(t=>{e||A(t instanceof Error?t.message:u(`pluginsLoadFailed`))}).finally(()=>{e||w(!1)}),()=>{e=!0}},[]);let M=(0,g.useMemo)(()=>{let e=o?.plugins||[];return{total:e.length,enabled:e.filter(e=>e.enabled).length,tools:e.reduce((e,t)=>e+t.tools.length,0)}},[o]),N=(0,g.useMemo)(()=>D&&(o?.plugins||[]).find(e=>e.name===D)||null,[o,D]),P=async(t,n)=>{E(t),A(null);try{c(await m(t,n)),e?.()}catch(e){A(e instanceof Error?e.message:u(`pluginsSaveFailed`))}finally{E(null)}};return(0,_.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden bg-background`,children:[(0,_.jsxs)(`div`,{className:`border-b border-border px-6 py-5`,children:[(0,_.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,_.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,_.jsx)(`div`,{className:`flex size-10 items-center justify-center rounded-2xl bg-primary/10 text-primary`,children:(0,_.jsx)(s,{className:`size-5`})}),(0,_.jsx)(`div`,{children:(0,_.jsxs)(`h1`,{className:`inline-flex items-center gap-1.5 text-lg font-semibold text-foreground`,children:[u(`plugins`),(0,_.jsx)(d,{label:u(`pluginsDescription`)})]})})]}),(0,_.jsxs)(f,{variant:`outline`,size:`sm`,onClick:()=>void j(`reload`),disabled:b,children:[b?(0,_.jsx)(t,{className:`mr-2 size-4 animate-spin`}):(0,_.jsx)(a,{className:`mr-2 size-4`}),u(`pluginsReload`)]})]}),(0,_.jsxs)(`div`,{className:`mt-4 flex flex-wrap gap-2 text-xs text-muted-foreground`,children:[(0,_.jsx)(`span`,{className:`rounded-full bg-muted px-2 py-0.5`,children:u(`pluginsCount`,M)}),(0,_.jsx)(`span`,{className:`rounded-full bg-muted px-2 py-0.5`,children:u(`pluginToolsCount`,{count:M.tools})})]})]}),(0,_.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-6`,children:(0,_.jsxs)(`div`,{className:`mx-auto max-w-5xl space-y-5`,children:[k?(0,_.jsx)(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive`,children:k}):null,o?.errors?.length?(0,_.jsxs)(`div`,{className:`space-y-2 rounded-lg border border-amber-500/30 bg-amber-500/8 p-3 text-sm`,children:[(0,_.jsxs)(`div`,{className:`flex items-center gap-2 font-medium text-amber-700 dark:text-amber-300`,children:[(0,_.jsx)(n,{className:`size-4`}),u(`pluginDiscoveryErrors`)]}),o.errors.map((e,t)=>(0,_.jsxs)(`div`,{className:`text-muted-foreground`,children:[(0,_.jsx)(`span`,{className:`font-mono text-xs`,children:e.dir}),`: `,e.error]},`${e.dir}-${t}`))]}):null,b&&!o?(0,_.jsxs)(`div`,{className:`flex h-40 items-center justify-center text-sm text-muted-foreground`,children:[(0,_.jsx)(t,{className:`mr-2 size-4 animate-spin`}),u(`loadingPlugins`)]}):null,!b&&o&&o.plugins.length===0?(0,_.jsxs)(`div`,{className:`rounded-lg border border-border bg-muted/15 p-4 text-xs text-muted-foreground/55`,children:[(0,_.jsx)(`div`,{className:`text-base font-medium text-foreground`,children:u(`noPlugins`)}),(0,_.jsx)(`p`,{className:`mt-2`,children:u(`noPluginsDescription`)}),(0,_.jsx)(`div`,{className:`mt-4 space-y-1`,children:(o.searchPaths||[]).map(e=>(0,_.jsx)(`div`,{className:`font-mono text-xs`,children:e},e))})]}):null,(0,_.jsx)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:(o?.plugins||[]).map(e=>(0,_.jsxs)(`article`,{className:`rounded-xl border border-border bg-card p-4`,children:[(0,_.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,_.jsxs)(`div`,{className:`min-w-0`,children:[(0,_.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,_.jsx)(`h2`,{className:`truncate text-sm font-medium text-foreground/90`,children:x(e)}),(0,_.jsxs)(`span`,{className:`rounded-full bg-muted px-2 py-0.5 text-xs text-muted-foreground`,children:[`v`,e.version]}),(0,_.jsx)(`span`,{className:l(`rounded-full px-2 py-0.5 text-xs`,v(e.status)),children:y(e.status)})]}),(0,_.jsx)(`p`,{className:`mt-2 line-clamp-2 text-sm text-muted-foreground`,children:S(e)})]}),(0,_.jsxs)(`div`,{className:`flex shrink-0 flex-col gap-1.5`,children:[(0,_.jsxs)(f,{variant:e.enabled?`outline`:`default`,size:`sm`,disabled:T===e.name,onClick:()=>void P(e.name,!e.enabled),children:[T===e.name?(0,_.jsx)(t,{className:`mr-2 size-4 animate-spin`}):null,e.enabled?u(`disablePlugin`):u(`enablePlugin`)]}),(0,_.jsx)(f,{variant:`ghost`,size:`sm`,onClick:()=>O(e.name),children:u(`viewDetails`)})]})]}),e.error?(0,_.jsx)(`div`,{className:`mt-3 rounded-lg border border-destructive/30 bg-destructive/8 px-3 py-2 text-sm text-destructive`,children:e.error}):null,(0,_.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-x-4 gap-y-1 border-t border-border pt-3 text-xs text-muted-foreground`,children:[(0,_.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,_.jsx)(i,{className:`size-3`}),u(`pluginToolsCount`,{count:e.tools.length})]}),(0,_.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,_.jsx)(r,{className:`size-3`}),u(`pluginPermissionsCount`,{count:e.permissions.length})]}),(0,_.jsx)(`span`,{children:e.enabled?u(`enabled`):u(`disabled`)})]})]},e.name))})]})}),N?(0,_.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4`,onMouseDown:e=>{e.target===e.currentTarget&&O(null)},children:(0,_.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,_.jsxs)(`div`,{className:`flex shrink-0 items-start justify-between gap-3 border-b border-border px-5 py-4`,children:[(0,_.jsxs)(`div`,{className:`min-w-0`,children:[(0,_.jsx)(`h2`,{className:`text-base font-medium text-foreground`,children:u(`pluginDetails`)}),(0,_.jsx)(`p`,{className:`mt-1 truncate text-sm text-muted-foreground`,children:x(N)})]}),(0,_.jsx)(f,{variant:`ghost`,size:`sm`,onClick:()=>O(null),children:u(`close`)})]}),(0,_.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-5 py-4`,children:(0,_.jsxs)(`div`,{className:`space-y-4`,children:[N.error?(0,_.jsx)(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/8 px-3 py-2 text-sm text-destructive`,children:N.error}):null,(0,_.jsxs)(`div`,{className:`rounded-xl border border-border bg-card p-4`,children:[(0,_.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:S(N)}),(0,_.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,_.jsxs)(`span`,{children:[u(`pluginVersion`),`:`,N.version]}),(0,_.jsxs)(`span`,{children:[u(`status`),`:`,y(N.status)]}),(0,_.jsx)(`span`,{children:u(`pluginToolsCount`,{count:N.tools.length})}),(0,_.jsx)(`span`,{children:N.enabled?u(`enabled`):u(`disabled`)})]})]}),(0,_.jsxs)(`div`,{className:`rounded-xl border border-border bg-card p-4`,children:[(0,_.jsxs)(`div`,{className:`mb-3 flex items-center gap-2 text-sm font-medium text-foreground`,children:[(0,_.jsx)(i,{className:`size-4 text-muted-foreground`}),u(`pluginTools`)]}),N.tools.length?(0,_.jsx)(`div`,{className:`space-y-2`,children:N.tools.map(e=>(0,_.jsxs)(`div`,{className:`rounded-xl bg-muted/30 px-3 py-2`,children:[(0,_.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:C(e)}),e.description?(0,_.jsx)(`div`,{className:`mt-1 text-xs text-muted-foreground`,children:e.description}):null]},e.quickForgeName))}):(0,_.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:u(`pluginNoTools`)})]}),(0,_.jsxs)(`div`,{className:`rounded-xl border border-border bg-card p-4`,children:[(0,_.jsxs)(`div`,{className:`mb-3 flex items-center gap-2 text-sm font-medium text-foreground`,children:[(0,_.jsx)(r,{className:`size-4 text-muted-foreground`}),u(`pluginPermissions`)]}),N.permissions.length?(0,_.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:N.permissions.map(e=>(0,_.jsx)(`span`,{className:`rounded-full bg-muted px-2 py-0.5 font-mono text-xs text-muted-foreground`,children:e},e))}):(0,_.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:u(`pluginNoPermissions`)}),(0,_.jsx)(`p`,{className:`mt-3 text-xs text-muted-foreground/80`,children:u(`pluginTrustedNotice`)})]})]})})]})}):null]})}export{w as PluginsPage};
1
+ import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{Et as t,I as n,i as r,l as i,r as a,v as o,y as s}from"./icons-Uo4Gd-eK.js";import{n as c}from"./react-vendor-BjDQPVuK.js";import{F as l,I as u,N as d,P as f}from"./index-DiaCCmXE.js";import{n as p,r as m,t as h}from"./plugin-api-YfYj_Bd7.js";var g=e(t(),1),_=c();function v(e){return e===`loaded`?`bg-emerald-500/10 text-emerald-700 dark:text-emerald-300`:e===`error`?`bg-destructive/10 text-destructive`:`bg-muted text-muted-foreground`}function y(e){return e===`loaded`?u(`pluginStatusLoaded`):e===`disabled`?u(`pluginStatusDisabled`):e===`error`?u(`pluginStatusError`):e}function b(e){switch(e){case`openai-documents`:return{label:u(`pluginOpenaiDocumentsName`),description:u(`pluginOpenaiDocumentsDescription`)};case`openai-spreadsheets`:return{label:u(`pluginOpenaiSpreadsheetsName`),description:u(`pluginOpenaiSpreadsheetsDescription`)};case`openai-presentations`:return{label:u(`pluginOpenaiPresentationsName`),description:u(`pluginOpenaiPresentationsDescription`)};default:return null}}function x(e){return b(e.name)?.label||(e.displayName||e.name).replace(/^OpenAI\s+/i,``)}function S(e){return b(e.name)?.description||e.description||u(`noDescription`)}function C(e){return(e.label||e.name||e.quickForgeName).replace(/^OpenAI\s+/i,``)}function w({onChanged:e}){let[t,c]=(0,g.useState)(null),[b,w]=(0,g.useState)(!0),[T,E]=(0,g.useState)(null),[D,O]=(0,g.useState)(null),[k,A]=(0,g.useState)(null),j=(0,g.useCallback)(async(t=`load`)=>{A(null),w(!0);try{c(t===`reload`?await p():await h()),t===`reload`&&e?.()}catch(e){A(e instanceof Error?e.message:u(`pluginsLoadFailed`))}finally{w(!1)}},[e]);(0,g.useEffect)(()=>{let e=!1;return h().then(t=>{e||c(t)}).catch(t=>{e||A(t instanceof Error?t.message:u(`pluginsLoadFailed`))}).finally(()=>{e||w(!1)}),()=>{e=!0}},[]);let M=(0,g.useMemo)(()=>{let e=t?.plugins||[];return{total:e.length,enabled:e.filter(e=>e.enabled).length,tools:e.reduce((e,t)=>e+t.tools.length,0)}},[t]),N=(0,g.useMemo)(()=>D&&(t?.plugins||[]).find(e=>e.name===D)||null,[t,D]),P=async(t,n)=>{E(t),A(null);try{c(await m(t,n)),e?.()}catch(e){A(e instanceof Error?e.message:u(`pluginsSaveFailed`))}finally{E(null)}};return(0,_.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden bg-background`,children:[(0,_.jsxs)(`div`,{className:`border-b border-border px-6 py-5`,children:[(0,_.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,_.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,_.jsx)(`div`,{className:`flex size-10 items-center justify-center rounded-2xl bg-primary/10 text-primary`,children:(0,_.jsx)(s,{className:`size-5`})}),(0,_.jsx)(`div`,{children:(0,_.jsxs)(`h1`,{className:`inline-flex items-center gap-1.5 text-lg font-semibold text-foreground`,children:[u(`plugins`),(0,_.jsx)(d,{label:u(`pluginsDescription`)})]})})]}),(0,_.jsxs)(f,{variant:`outline`,size:`sm`,onClick:()=>void j(`reload`),disabled:b,children:[b?(0,_.jsx)(n,{className:`mr-2 size-4 animate-spin`}):(0,_.jsx)(o,{className:`mr-2 size-4`}),u(`pluginsReload`)]})]}),(0,_.jsxs)(`div`,{className:`mt-4 flex flex-wrap gap-2 text-xs text-muted-foreground`,children:[(0,_.jsx)(`span`,{className:`rounded-full bg-muted px-2 py-0.5`,children:u(`pluginsCount`,M)}),(0,_.jsx)(`span`,{className:`rounded-full bg-muted px-2 py-0.5`,children:u(`pluginToolsCount`,{count:M.tools})})]})]}),(0,_.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-6`,children:(0,_.jsxs)(`div`,{className:`mx-auto max-w-5xl space-y-5`,children:[k?(0,_.jsx)(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive`,children:k}):null,t?.errors?.length?(0,_.jsxs)(`div`,{className:`space-y-2 rounded-lg border border-amber-500/30 bg-amber-500/8 p-3 text-sm`,children:[(0,_.jsxs)(`div`,{className:`flex items-center gap-2 font-medium text-amber-700 dark:text-amber-300`,children:[(0,_.jsx)(r,{className:`size-4`}),u(`pluginDiscoveryErrors`)]}),t.errors.map((e,t)=>(0,_.jsxs)(`div`,{className:`text-muted-foreground`,children:[(0,_.jsx)(`span`,{className:`font-mono text-xs`,children:e.dir}),`: `,e.error]},`${e.dir}-${t}`))]}):null,b&&!t?(0,_.jsxs)(`div`,{className:`flex h-40 items-center justify-center text-sm text-muted-foreground`,children:[(0,_.jsx)(n,{className:`mr-2 size-4 animate-spin`}),u(`loadingPlugins`)]}):null,!b&&t&&t.plugins.length===0?(0,_.jsxs)(`div`,{className:`rounded-lg border border-border bg-muted/15 p-4 text-xs text-muted-foreground/55`,children:[(0,_.jsx)(`div`,{className:`text-base font-medium text-foreground`,children:u(`noPlugins`)}),(0,_.jsx)(`p`,{className:`mt-2`,children:u(`noPluginsDescription`)}),(0,_.jsx)(`div`,{className:`mt-4 space-y-1`,children:(t.searchPaths||[]).map(e=>(0,_.jsx)(`div`,{className:`font-mono text-xs`,children:e},e))})]}):null,(0,_.jsx)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:(t?.plugins||[]).map(e=>(0,_.jsxs)(`article`,{className:`rounded-xl border border-border bg-card p-4`,children:[(0,_.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,_.jsxs)(`div`,{className:`min-w-0`,children:[(0,_.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,_.jsx)(`h2`,{className:`truncate text-sm font-medium text-foreground/90`,children:x(e)}),(0,_.jsxs)(`span`,{className:`rounded-full bg-muted px-2 py-0.5 text-xs text-muted-foreground`,children:[`v`,e.version]}),(0,_.jsx)(`span`,{className:l(`rounded-full px-2 py-0.5 text-xs`,v(e.status)),children:y(e.status)})]}),(0,_.jsx)(`p`,{className:`mt-2 line-clamp-2 text-sm text-muted-foreground`,children:S(e)})]}),(0,_.jsxs)(`div`,{className:`flex shrink-0 flex-col gap-1.5`,children:[(0,_.jsxs)(f,{variant:e.enabled?`outline`:`default`,size:`sm`,disabled:T===e.name,onClick:()=>void P(e.name,!e.enabled),children:[T===e.name?(0,_.jsx)(n,{className:`mr-2 size-4 animate-spin`}):null,e.enabled?u(`disablePlugin`):u(`enablePlugin`)]}),(0,_.jsx)(f,{variant:`ghost`,size:`sm`,onClick:()=>O(e.name),children:u(`viewDetails`)})]})]}),e.error?(0,_.jsx)(`div`,{className:`mt-3 rounded-lg border border-destructive/30 bg-destructive/8 px-3 py-2 text-sm text-destructive`,children:e.error}):null,(0,_.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-x-4 gap-y-1 border-t border-border pt-3 text-xs text-muted-foreground`,children:[(0,_.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,_.jsx)(a,{className:`size-3`}),u(`pluginToolsCount`,{count:e.tools.length})]}),(0,_.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,_.jsx)(i,{className:`size-3`}),u(`pluginPermissionsCount`,{count:e.permissions.length})]}),(0,_.jsx)(`span`,{children:e.enabled?u(`enabled`):u(`disabled`)})]})]},e.name))})]})}),N?(0,_.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4`,onMouseDown:e=>{e.target===e.currentTarget&&O(null)},children:(0,_.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,_.jsxs)(`div`,{className:`flex shrink-0 items-start justify-between gap-3 border-b border-border px-5 py-4`,children:[(0,_.jsxs)(`div`,{className:`min-w-0`,children:[(0,_.jsx)(`h2`,{className:`text-base font-medium text-foreground`,children:u(`pluginDetails`)}),(0,_.jsx)(`p`,{className:`mt-1 truncate text-sm text-muted-foreground`,children:x(N)})]}),(0,_.jsx)(f,{variant:`ghost`,size:`sm`,onClick:()=>O(null),children:u(`close`)})]}),(0,_.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-5 py-4`,children:(0,_.jsxs)(`div`,{className:`space-y-4`,children:[N.error?(0,_.jsx)(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/8 px-3 py-2 text-sm text-destructive`,children:N.error}):null,(0,_.jsxs)(`div`,{className:`rounded-xl border border-border bg-card p-4`,children:[(0,_.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:S(N)}),(0,_.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,_.jsxs)(`span`,{children:[u(`pluginVersion`),`:`,N.version]}),(0,_.jsxs)(`span`,{children:[u(`status`),`:`,y(N.status)]}),(0,_.jsx)(`span`,{children:u(`pluginToolsCount`,{count:N.tools.length})}),(0,_.jsx)(`span`,{children:N.enabled?u(`enabled`):u(`disabled`)})]})]}),(0,_.jsxs)(`div`,{className:`rounded-xl border border-border bg-card p-4`,children:[(0,_.jsxs)(`div`,{className:`mb-3 flex items-center gap-2 text-sm font-medium text-foreground`,children:[(0,_.jsx)(a,{className:`size-4 text-muted-foreground`}),u(`pluginTools`)]}),N.tools.length?(0,_.jsx)(`div`,{className:`space-y-2`,children:N.tools.map(e=>(0,_.jsxs)(`div`,{className:`rounded-xl bg-muted/30 px-3 py-2`,children:[(0,_.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:C(e)}),e.description?(0,_.jsx)(`div`,{className:`mt-1 text-xs text-muted-foreground`,children:e.description}):null]},e.quickForgeName))}):(0,_.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:u(`pluginNoTools`)})]}),(0,_.jsxs)(`div`,{className:`rounded-xl border border-border bg-card p-4`,children:[(0,_.jsxs)(`div`,{className:`mb-3 flex items-center gap-2 text-sm font-medium text-foreground`,children:[(0,_.jsx)(i,{className:`size-4 text-muted-foreground`}),u(`pluginPermissions`)]}),N.permissions.length?(0,_.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:N.permissions.map(e=>(0,_.jsx)(`span`,{className:`rounded-full bg-muted px-2 py-0.5 font-mono text-xs text-muted-foreground`,children:e},e))}):(0,_.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:u(`pluginNoPermissions`)}),(0,_.jsx)(`p`,{className:`mt-3 text-xs text-muted-foreground/80`,children:u(`pluginTrustedNotice`)})]})]})})]})}):null]})}export{w as PluginsPage};
@@ -0,0 +1,2 @@
1
+ import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{Ct as t,Et as n,H as r,St as i,T as ee,a as te,c as ne,ft as re,h as ie,n as ae,rt as oe,t as se,tt as ce,ut as le,xt as ue}from"./icons-Uo4Gd-eK.js";import{n as a}from"./react-vendor-BjDQPVuK.js";import{D as de,E as fe,F as o,I as s,M as pe,N as c,O as me,P as l,T as he,k as ge}from"./index-DiaCCmXE.js";var u=e(n(),1),d=a(),_e=[{value:`off`,label:()=>s(`thinkingOff`)},{value:`low`,label:()=>s(`thinkingLow`)},{value:`medium`,label:()=>s(`thinkingMedium`)},{value:`high`,label:()=>s(`thinkingHigh`)},{value:`xhigh`,label:()=>s(`thinkingXHigh`)}];function ve(e){return`${e.provider} / ${e.id}`}function ye(e,t){return!!(e&&t&&e.api===t.api&&e.provider===t.provider&&e.id===t.id)}function f(e){return String(e).padStart(2,`0`)}function p(e){if(!e)return`-`;let t=new Date(e);return Number.isNaN(t.getTime())?`-`:`${t.getFullYear()}-${f(t.getMonth()+1)}-${f(t.getDate())} ${f(t.getHours())}:${f(t.getMinutes())}`}function be(e,t=20){let n=String(e||``).trim();return n.length>t?`${n.slice(0,t)}...`:n}function xe(){return{scheduleText:``,title:``,instruction:``,cronExpression:``,scheduleRule:``,nextRunAt:``,enabled:!0,agentId:``,executionMode:`serial`}}function m(){return{taskId:``,status:``,trigger:``,keyword:``,startedFrom:``,startedTo:``,page:1,pageSize:10}}function Se(e){return{scheduleText:[e.scheduleRule,e.instruction].filter(Boolean).join(`
2
+ `),title:e.title,instruction:e.instruction,cronExpression:e.cronExpression??``,scheduleRule:e.scheduleRule,nextRunAt:e.nextRunAt,enabled:e.status!==`paused`,agentId:e.agentId??``,executionMode:e.executionMode??`serial`}}function Ce(e,t){return{...t,title:e.title,instruction:e.instruction,cronExpression:e.cronExpression??``,scheduleRule:e.scheduleRule,nextRunAt:e.nextRunAt,enabled:t.enabled}}function we(e){return{title:e.title.trim(),instruction:e.instruction.trim(),scheduleType:`cron`,scheduleRule:e.scheduleRule.trim()||e.cronExpression.trim(),cronExpression:e.cronExpression.trim(),nextRunAt:e.nextRunAt,enabled:e.enabled,agentId:e.agentId||null,executionMode:e.executionMode}}function h(e){return!!(e.currentRunId||e.currentRunIds?.length)}function Te(e){return(e.executionMode??`serial`)===`parallel`||!h(e)}function Ee(e){return s(e===`parallel`?`taskExecutionModeParallel`:`taskExecutionModeSerial`)}function De(e){return!!(e.title.trim()&&e.instruction.trim()&&e.cronExpression.trim())}function Oe(e){return s(e===`enabled`?`taskEnabled`:e===`running`?`taskRunning`:e===`paused`?`taskPaused`:e===`completed`?`taskFinished`:e===`success`?`executionSuccess`:`taskFailed`)}function ke(e){return e===`enabled`||e===`success`?`bg-emerald-500/10 text-emerald-700`:e===`running`?`bg-blue-500/10 text-blue-700`:e===`paused`?`bg-amber-500/10 text-amber-700`:`bg-muted text-muted-foreground`}async function g(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 _({onOpenSession:e}){let[n,a]=(0,u.useState)([]),[f,_]=(0,u.useState)(`tasks`),[v,y]=(0,u.useState)(()=>xe()),[b,Ae]=(0,u.useState)(null),[x,S]=(0,u.useState)(null),[C,w]=(0,u.useState)(null),[je,T]=(0,u.useState)(!1),[E,D]=(0,u.useState)(null),[Me,O]=(0,u.useState)(``),[k,A]=(0,u.useState)(!1),[j,M]=(0,u.useState)(``),[N,Ne]=(0,u.useState)([]),[P,F]=(0,u.useState)(),[I,L]=(0,u.useState)(`off`),[R,Pe]=(0,u.useState)([]),[Fe,z]=(0,u.useState)(``),[B,V]=(0,u.useState)(()=>m()),[H,U]=(0,u.useState)(()=>m()),[W,Ie]=(0,u.useState)({runs:[],total:0,page:1,pageSize:10}),[Le,Re]=(0,u.useState)(!1),[ze,Be]=(0,u.useState)(null),[Ve,He]=(0,u.useState)([]),Ue=R[0]?.id??``;(0,u.useEffect)(()=>{if(!C)return;let e=()=>w(null);return window.addEventListener(`click`,e),window.addEventListener(`blur`,e),()=>{window.removeEventListener(`click`,e),window.removeEventListener(`blur`,e)}},[C]);async function We(){a((await g(`/api/scheduled-tasks`)).tasks)}async function G(e=H){Re(!0),M(``);try{let t=new URLSearchParams;t.set(`page`,String(e.page)),t.set(`pageSize`,String(e.pageSize)),e.taskId&&t.set(`taskId`,e.taskId),e.status&&t.set(`status`,e.status),e.trigger&&t.set(`trigger`,e.trigger),e.keyword.trim()&&t.set(`keyword`,e.keyword.trim()),e.startedFrom&&t.set(`startedFrom`,e.startedFrom),e.startedTo&&t.set(`startedTo`,e.startedTo),Ie(await g(`/api/scheduled-tasks/runs?${t.toString()}`))}catch(e){M(e instanceof Error?e.message:s(`requestFailed`))}finally{Re(!1)}}(0,u.useEffect)(()=>{let e=!1;async function t(){try{let t=await g(`/api/project`);if(e)return;Pe(t.projects??[])}catch{}}return t(),()=>{e=!0}},[]),(0,u.useEffect)(()=>{let e=!1;async function t(){try{let t=await de(),n=await fe(t),r=await me(t),i=r.model??await ge(t)??n[0];if(e)return;Ne(n),F(i),L(r.thinkingLevel??he(i))}catch(t){e||M(t instanceof Error?t.message:s(`requestFailed`))}}return t(),()=>{e=!0}},[]),(0,u.useEffect)(()=>{let e=!1,t=async()=>{try{let t=await g(`/api/scheduled-tasks`);e||a(t.tasks)}catch(t){e||M(t instanceof Error?t.message:s(`requestFailed`))}};t();let n=window.setInterval(t,10*1e3);return()=>{e=!0,window.clearInterval(n)}},[]),(0,u.useEffect)(()=>{let e=!1;async function t(){try{let t=await g(`/api/agent-profiles`);if(e)return;He(t.agents)}catch(t){e||M(t instanceof Error?t.message:s(`requestFailed`))}}return t(),()=>{e=!0}},[]);let K=(0,u.useMemo)(()=>n.find(e=>e.id===b),[b,n]),q=(0,u.useMemo)(()=>n.find(e=>e.id===x)??null,[x,n]),Ge=(0,u.useMemo)(()=>n.filter(e=>e.status===`enabled`).length,[n]),J=Math.max(1,Math.ceil(W.total/W.pageSize));function Y(e){return e?Ve.find(t=>t.id===e||t.name===e)?.label??e:s(`defaultAgent`)}function X(e,t){y(n=>({...n,[e]:t}))}function Z(e,t){V(n=>({...n,[e]:t}))}function Ke(){Ae(null),z(Ue),y(xe()),D(null),O(``),M(``)}function qe(){Ke(),T(!0)}function Q(){k||(T(!1),Ke())}function Je(){let e={...B,page:1};V(e),U(e),G(e)}function Ye(){let e=m();V(e),U(e),G(e)}function Xe(e){let t=Math.min(Math.max(1,e),J),n={...H,page:t};V(n),U(n),G(n)}function Ze(e){let t={...H,page:1,pageSize:e};V(t),U(t),G(t)}async function Qe(){let e=v.scheduleText.trim();if(e){A(!0),M(``);try{let t=await g(`/api/scheduled-tasks/parse`,{method:`POST`,body:JSON.stringify({instruction:e,model:P,thinkingLevel:I})});if(t.needMoreInfo||!t.task){O(t.question||`请补充任务信息。`),D(null);return}let n=t.task;O(``),D(n),y(e=>Ce(n,e))}catch(e){M(e instanceof Error?e.message:s(`requestFailed`))}finally{A(!1)}}}async function $e(){if(De(v)){A(!0),M(``);try{let e=R.find(e=>e.id===Fe),t={task:we(v),model:P,thinkingLevel:I,projectId:e?.id,projectName:e?.name};b?await g(`/api/scheduled-tasks/${encodeURIComponent(b)}`,{method:`PUT`,body:JSON.stringify(t)}):await g(`/api/scheduled-tasks`,{method:`POST`,body:JSON.stringify(t)}),Q(),await We(),f===`history`&&await G(H)}catch(e){M(e instanceof Error?e.message:s(`requestFailed`))}finally{A(!1)}}}function et(e){w(null),Ae(e.id),y(Se(e)),D(null),O(``),M(``),z(e.projectId??``),e.model&&F(e.model),e.thinkingLevel&&L(e.thinkingLevel),T(!0)}async function $(e,t){if(M(``),w(null),!(t===`delete`&&!await pe({description:s(`confirmDeleteTask`),confirmLabel:s(`confirmDelete`),cancelLabel:s(`cancel`),variant:`destructive`})))try{t===`delete`?(await g(`/api/scheduled-tasks/${encodeURIComponent(e)}`,{method:`DELETE`}),b===e&&Q(),x===e&&S(null)):await g(`/api/scheduled-tasks/${encodeURIComponent(e)}/${t}`,{method:`POST`}),await We(),f===`history`&&await G(H)}catch(e){M(e instanceof Error?e.message:s(`requestFailed`))}}function tt(t){return(0,d.jsxs)(`div`,{className:`mt-2 space-y-2 text-xs text-muted-foreground`,children:[t.sessionId?(0,d.jsx)(l,{variant:`outline`,size:`sm`,onClick:()=>e?.(t.sessionId),children:s(`viewConversation`)}):null,(0,d.jsxs)(`div`,{children:[s(`executionAgent`),t.agentLabel||Y(t.agentId)]}),t.warning?(0,d.jsx)(`div`,{className:`text-amber-600`,children:t.warning}):null,t.inputContent?(0,d.jsxs)(`div`,{children:[(0,d.jsx)(`div`,{className:`font-medium text-foreground`,children:s(`runInputContent`)}),(0,d.jsx)(`pre`,{className:`mt-1 max-h-32 overflow-auto whitespace-pre-wrap`,children:t.inputContent})]}):null,t.aiResult||t.result?(0,d.jsxs)(`div`,{children:[(0,d.jsx)(`div`,{className:`font-medium text-foreground`,children:s(`runAiResult`)}),(0,d.jsx)(`pre`,{className:`mt-1 max-h-48 overflow-auto whitespace-pre-wrap`,children:t.aiResult||t.result})]}):null,t.errorMessage?(0,d.jsx)(`div`,{className:`text-destructive`,children:t.errorMessage}):null,t.durationMs?(0,d.jsxs)(`div`,{children:[s(`runDuration`),t.durationMs,`ms`]}):null]})}return(0,d.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden bg-background`,children:[(0,d.jsxs)(`div`,{className:`border-b border-border px-6 py-5`,children:[(0,d.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,d.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,d.jsx)(`div`,{className:`flex size-10 items-center justify-center rounded-2xl bg-primary/10 text-primary`,children:(0,d.jsx)(ue,{className:`size-5`})}),(0,d.jsx)(`div`,{children:(0,d.jsxs)(`h1`,{className:`inline-flex items-center gap-1.5 text-lg font-semibold text-foreground`,children:[s(`scheduledTasks`),(0,d.jsx)(c,{label:s(`scheduledTasksDescription`)})]})})]}),(0,d.jsx)(l,{onClick:qe,children:s(`createTask`)})]}),(0,d.jsxs)(`div`,{className:`mt-4 flex flex-wrap gap-2`,children:[(0,d.jsxs)(`button`,{type:`button`,className:o(`rounded-full px-4 py-2 text-sm font-medium transition-colors`,f===`tasks`?`bg-primary text-primary-foreground`:`bg-muted text-muted-foreground hover:text-foreground`),onClick:()=>_(`tasks`),children:[s(`taskListTab`),` `,(0,d.jsx)(`span`,{className:`opacity-80`,children:n.length})]}),(0,d.jsx)(`button`,{type:`button`,className:o(`rounded-full px-4 py-2 text-sm font-medium transition-colors`,f===`history`?`bg-primary text-primary-foreground`:`bg-muted text-muted-foreground hover:text-foreground`),onClick:()=>{_(`history`),G(H)},children:s(`executionHistoryTab`)})]})]}),(0,d.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-6`,children:(0,d.jsxs)(`div`,{className:`mx-auto max-w-5xl space-y-5`,children:[j&&!je?(0,d.jsx)(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive`,children:j}):null,f===`tasks`?(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(`div`,{className:`rounded-xl border border-border bg-card p-4`,children:(0,d.jsx)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:(0,d.jsxs)(`div`,{children:[(0,d.jsx)(`h2`,{className:`text-base font-semibold text-foreground`,children:s(`taskList`)}),(0,d.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:s(`tasksCount`,{total:n.length,enabled:Ge})})]})})}),(0,d.jsx)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:n.length===0?(0,d.jsx)(`div`,{className:`rounded-lg px-3 py-3 text-center text-xs text-muted-foreground/55 md:col-span-2`,children:s(`noScheduledTasks`)}):n.map(e=>{let n=e.status===`enabled`,r=e.status===`completed`,i=h(e);return(0,d.jsxs)(`div`,{className:`relative cursor-pointer rounded-xl border border-border bg-card p-4 transition-colors hover:bg-muted/15`,onClick:()=>S(e.id),children:[(0,d.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,d.jsxs)(`div`,{className:`min-w-0`,children:[(0,d.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,d.jsx)(`h3`,{className:`truncate text-sm font-medium text-foreground/90`,children:e.title})}),(0,d.jsx)(`p`,{className:`mt-2 text-sm text-muted-foreground`,children:be(e.instruction,20)})]}),(0,d.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,onClick:e=>e.stopPropagation(),children:[(0,d.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":n,disabled:r,className:o(`relative h-6 w-11 rounded-full transition-colors disabled:cursor-not-allowed disabled:opacity-60`,n?`bg-emerald-500`:`bg-muted-foreground/30`),onClick:()=>void $(e.id,e.status===`paused`?`resume`:`pause`),title:e.status===`paused`?s(`enable`):s(`pauseTask`),children:(0,d.jsx)(`span`,{className:o(`absolute left-0.5 top-0.5 size-5 rounded-full bg-white shadow transition-transform`,n?`translate-x-5`:`translate-x-0`)})}),(0,d.jsxs)(`div`,{className:`relative`,children:[(0,d.jsx)(l,{variant:`ghost`,size:`icon`,onClick:()=>w(C===e.id?null:e.id),title:s(`moreActions`),children:(0,d.jsx)(oe,{className:`size-4`})}),C===e.id?(0,d.jsxs)(`div`,{className:`absolute right-0 z-20 mt-1 w-36 overflow-hidden rounded-xl border border-border bg-popover py-1 text-sm shadow-quickforge`,children:[(0,d.jsxs)(`button`,{className:`flex w-full items-center gap-2 px-3 py-2 text-left hover:bg-muted disabled:cursor-not-allowed disabled:opacity-50`,disabled:!Te(e),onClick:()=>void $(e.id,`run`),children:[(0,d.jsx)(se,{className:`size-3.5`}),s(`executeNow`)]}),(0,d.jsxs)(`button`,{className:`flex w-full items-center gap-2 px-3 py-2 text-left hover:bg-muted disabled:cursor-not-allowed disabled:opacity-50`,disabled:i,onClick:()=>et(e),children:[(0,d.jsx)(ee,{className:`size-3.5`}),s(`editTask`)]}),(0,d.jsxs)(`button`,{className:`flex w-full items-center gap-2 px-3 py-2 text-left hover:bg-muted`,onClick:()=>{w(null),S(e.id)},children:[(0,d.jsx)(ce,{className:`size-3.5`}),s(`viewDetails`)]}),(0,d.jsxs)(`button`,{className:`flex w-full items-center gap-2 px-3 py-2 text-left text-destructive hover:bg-muted disabled:cursor-not-allowed disabled:opacity-50`,disabled:i,onClick:()=>void $(e.id,`delete`),children:[(0,d.jsx)(te,{className:`size-3.5`}),s(`deleteTask`)]})]}):null]})]})]}),(0,d.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-x-4 gap-y-1 text-xs text-muted-foreground`,children:[(0,d.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,d.jsx)(le,{className:`size-3`}),e.scheduleRule]}),(0,d.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,d.jsx)(t,{className:`size-3`}),Y(e.agentId)]}),(0,d.jsxs)(`span`,{children:[s(`taskExecutionMode`),`:`,Ee(e.executionMode)]}),e.projectName?(0,d.jsxs)(`span`,{children:[s(`taskProject`),e.projectName]}):null]}),(0,d.jsxs)(`div`,{className:`mt-4 grid gap-2 border-t border-border pt-3 text-xs text-muted-foreground sm:grid-cols-2`,children:[(0,d.jsxs)(`span`,{children:[s(`lastExecution`),p(e.lastRunAt)]}),(0,d.jsxs)(`span`,{children:[s(`nextExecution`),p(e.nextRunAt)]})]})]},e.id)})})]}):(0,d.jsxs)(`div`,{className:`space-y-4`,children:[(0,d.jsxs)(`div`,{className:`rounded-xl border border-border bg-card p-4`,children:[(0,d.jsxs)(`div`,{className:`mb-3 flex items-center gap-2 text-sm font-medium text-foreground`,children:[(0,d.jsx)(ie,{className:`size-4`}),s(`historyFilters`)]}),(0,d.jsxs)(`div`,{className:`grid gap-3 md:grid-cols-3`,children:[(0,d.jsxs)(`label`,{className:`block text-xs font-medium text-muted-foreground`,children:[s(`taskName`),(0,d.jsxs)(`select`,{className:`mt-1 h-9 w-full rounded-md border border-input bg-background px-2 text-sm text-foreground`,value:B.taskId,onChange:e=>Z(`taskId`,e.target.value),children:[(0,d.jsx)(`option`,{value:``,children:s(`allTasks`)}),n.map(e=>(0,d.jsx)(`option`,{value:e.id,children:e.title},e.id))]})]}),(0,d.jsxs)(`label`,{className:`block text-xs font-medium text-muted-foreground`,children:[s(`status`),(0,d.jsxs)(`select`,{className:`mt-1 h-9 w-full rounded-md border border-input bg-background px-2 text-sm text-foreground`,value:B.status,onChange:e=>Z(`status`,e.target.value),children:[(0,d.jsx)(`option`,{value:``,children:s(`allStatuses`)}),(0,d.jsx)(`option`,{value:`running`,children:s(`executionRunning`)}),(0,d.jsx)(`option`,{value:`success`,children:s(`executionSuccess`)}),(0,d.jsx)(`option`,{value:`failed`,children:s(`taskFailed`)})]})]}),(0,d.jsxs)(`label`,{className:`block text-xs font-medium text-muted-foreground`,children:[s(`triggerType`),(0,d.jsxs)(`select`,{className:`mt-1 h-9 w-full rounded-md border border-input bg-background px-2 text-sm text-foreground`,value:B.trigger,onChange:e=>Z(`trigger`,e.target.value),children:[(0,d.jsx)(`option`,{value:``,children:s(`allTriggers`)}),(0,d.jsx)(`option`,{value:`schedule`,children:s(`autoRun`)}),(0,d.jsx)(`option`,{value:`manual`,children:s(`manualRun`)})]})]}),(0,d.jsxs)(`label`,{className:`block text-xs font-medium text-muted-foreground`,children:[s(`startTime`),(0,d.jsx)(`input`,{type:`datetime-local`,className:`mt-1 h-9 w-full rounded-md border border-input bg-background px-2 text-sm text-foreground`,value:B.startedFrom,onChange:e=>Z(`startedFrom`,e.target.value)})]}),(0,d.jsxs)(`label`,{className:`block text-xs font-medium text-muted-foreground`,children:[s(`endTime`),(0,d.jsx)(`input`,{type:`datetime-local`,className:`mt-1 h-9 w-full rounded-md border border-input bg-background px-2 text-sm text-foreground`,value:B.startedTo,onChange:e=>Z(`startedTo`,e.target.value)})]}),(0,d.jsxs)(`label`,{className:`block text-xs font-medium text-muted-foreground`,children:[s(`keyword`),(0,d.jsx)(`input`,{className:`mt-1 h-9 w-full rounded-md border border-input bg-background px-2 text-sm text-foreground`,value:B.keyword,onChange:e=>Z(`keyword`,e.target.value),placeholder:s(`keywordPlaceholder`)})]})]}),(0,d.jsxs)(`div`,{className:`mt-3 flex justify-end gap-2`,children:[(0,d.jsx)(l,{variant:`outline`,onClick:Ye,children:s(`reset`)}),(0,d.jsx)(l,{onClick:Je,children:s(`query`)})]})]}),(0,d.jsxs)(`div`,{className:`overflow-hidden rounded-xl border border-border bg-card`,children:[(0,d.jsxs)(`div`,{className:`grid grid-cols-[1.3fr_0.7fr_0.7fr_1fr_0.7fr] gap-3 border-b border-border px-4 py-3 text-xs font-medium text-muted-foreground`,children:[(0,d.jsx)(`span`,{children:s(`taskName`)}),(0,d.jsx)(`span`,{children:s(`status`)}),(0,d.jsx)(`span`,{children:s(`triggerType`)}),(0,d.jsx)(`span`,{children:s(`startTime`)}),(0,d.jsx)(`span`,{children:s(`runDuration`)})]}),Le?(0,d.jsx)(`div`,{className:`p-8 text-center text-sm text-muted-foreground`,children:s(`loading`)}):W.runs.length===0?(0,d.jsx)(`div`,{className:`p-8 text-center text-sm text-muted-foreground`,children:s(`noExecutionHistory`)}):W.runs.map(e=>(0,d.jsxs)(`div`,{className:`border-b border-border last:border-b-0`,children:[(0,d.jsxs)(`button`,{type:`button`,className:`grid w-full grid-cols-[1.3fr_0.7fr_0.7fr_1fr_0.7fr] gap-3 px-4 py-3 text-left text-sm hover:bg-muted/40`,onClick:()=>Be(ze===e.id?null:e.id),children:[(0,d.jsx)(`span`,{className:`min-w-0 truncate text-foreground`,children:e.taskTitle}),(0,d.jsx)(`span`,{children:(0,d.jsx)(`span`,{className:o(`rounded-full px-2 py-0.5 text-xs`,ke(e.status)),children:Oe(e.status)})}),(0,d.jsx)(`span`,{className:`text-muted-foreground`,children:e.trigger===`manual`?s(`manualRun`):s(`autoRun`)}),(0,d.jsx)(`span`,{className:`text-muted-foreground`,children:p(e.startedAt)}),(0,d.jsx)(`span`,{className:`text-muted-foreground`,children:e.durationMs?`${e.durationMs}ms`:`-`})]}),ze===e.id?(0,d.jsx)(`div`,{className:`border-t border-border bg-muted/20 px-4 py-3`,children:tt(e)}):null]},`${e.taskId}:${e.id}`)),(0,d.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 px-4 py-3 text-sm text-muted-foreground`,children:[(0,d.jsx)(`span`,{children:s(`paginationSummary`,{page:W.page,pages:J,total:W.total})}),(0,d.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,d.jsx)(`select`,{className:`h-8 rounded-md border border-input bg-background px-2 text-sm`,value:W.pageSize,onChange:e=>Ze(Number(e.target.value)),children:[10,20,50,100].map(e=>(0,d.jsx)(`option`,{value:e,children:s(`pageSize`,{size:e})},e))}),(0,d.jsx)(l,{variant:`outline`,size:`sm`,disabled:W.page<=1,onClick:()=>Xe(W.page-1),children:s(`previousPage`)}),(0,d.jsx)(l,{variant:`outline`,size:`sm`,disabled:W.page>=J,onClick:()=>Xe(W.page+1),children:s(`nextPage`)})]})]})]})]})]})}),q?(0,d.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4`,onMouseDown:e=>{e.target===e.currentTarget&&S(null)},children:(0,d.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,d.jsxs)(`div`,{className:`flex shrink-0 items-start justify-between gap-3 border-b border-border px-5 py-4`,children:[(0,d.jsxs)(`div`,{children:[(0,d.jsx)(`div`,{className:`flex flex-wrap items-center gap-2`,children:(0,d.jsx)(`h2`,{className:`text-base font-semibold text-foreground`,children:q.title})}),(0,d.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:q.scheduleRule})]}),(0,d.jsx)(l,{variant:`ghost`,size:`icon`,onClick:()=>S(null),children:(0,d.jsx)(ae,{className:`size-4`})})]}),(0,d.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-5 py-4`,children:(0,d.jsxs)(`div`,{className:`space-y-4 text-sm`,children:[(0,d.jsxs)(`div`,{children:[(0,d.jsx)(`div`,{className:`mb-1 font-medium text-foreground`,children:s(`taskContent`)}),(0,d.jsx)(`pre`,{className:`max-h-48 overflow-auto whitespace-pre-wrap rounded-xl border border-border bg-muted/20 p-3 text-muted-foreground`,children:q.instruction})]}),(0,d.jsxs)(`div`,{className:`grid gap-3 text-muted-foreground sm:grid-cols-2`,children:[(0,d.jsxs)(`div`,{children:[s(`executionRule`),(0,d.jsx)(`span`,{className:`text-foreground`,children:q.scheduleRule})]}),(0,d.jsxs)(`div`,{children:[s(`taskExecutionMode`),`:`,(0,d.jsx)(`span`,{className:`text-foreground`,children:Ee(q.executionMode)})]}),(0,d.jsxs)(`div`,{children:[`cron:`,(0,d.jsx)(`span`,{className:`font-mono text-foreground`,children:q.cronExpression??`-`})]}),(0,d.jsxs)(`div`,{children:[s(`lastExecution`),(0,d.jsx)(`span`,{className:`text-foreground`,children:p(q.lastRunAt)})]}),(0,d.jsxs)(`div`,{children:[s(`nextExecution`),(0,d.jsx)(`span`,{className:`text-foreground`,children:p(q.nextRunAt)})]}),(0,d.jsxs)(`div`,{children:[s(`executionAgent`),(0,d.jsx)(`span`,{className:`text-foreground`,children:Y(q.agentId)})]}),q.projectName?(0,d.jsxs)(`div`,{children:[s(`taskProject`),(0,d.jsx)(`span`,{className:`text-foreground`,children:q.projectName})]}):null,q.model?(0,d.jsxs)(`div`,{children:[s(`taskModel`),`:`,(0,d.jsx)(`span`,{className:`text-foreground`,children:ve(q.model)})]}):null,q.thinkingLevel?(0,d.jsxs)(`div`,{children:[s(`taskThinkingLevel`),(0,d.jsx)(`span`,{className:`text-foreground`,children:_e.find(e=>e.value===q.thinkingLevel)?.label()??q.thinkingLevel})]}):null,(0,d.jsxs)(`div`,{children:[s(`createdAt`),`:`,(0,d.jsx)(`span`,{className:`text-foreground`,children:p(q.createdAt)})]})]}),q.runs?.length>0?(0,d.jsxs)(`div`,{children:[(0,d.jsx)(`div`,{className:`mb-2 font-medium text-foreground`,children:s(`recentExecutions`)}),(0,d.jsx)(`div`,{className:`space-y-2`,children:q.runs.slice(0,5).map(e=>(0,d.jsxs)(`details`,{className:`rounded-lg border border-border bg-muted/20 p-2 text-xs text-muted-foreground`,children:[(0,d.jsxs)(`summary`,{className:`cursor-pointer text-foreground`,children:[p(e.startedAt),` · `,e.trigger===`manual`?s(`manualRun`):s(`autoRun`),` · `,Oe(e.status)]}),tt(e)]},e.id))})]}):null]})}),(0,d.jsx)(`div`,{className:`shrink-0 border-t border-border px-5 py-4`,children:(0,d.jsxs)(`div`,{className:`flex flex-wrap justify-end gap-2`,children:[q.lastSessionId?(0,d.jsx)(l,{variant:`outline`,onClick:()=>e?.(q.lastSessionId),children:s(`viewConversation`)}):null,(0,d.jsxs)(l,{variant:`outline`,disabled:!Te(q),onClick:()=>void $(q.id,`run`),children:[(0,d.jsx)(se,{className:`mr-1 size-3.5`}),s(`executeNow`)]}),(0,d.jsxs)(l,{variant:`outline`,disabled:h(q),onClick:()=>et(q),children:[(0,d.jsx)(ee,{className:`mr-1 size-3.5`}),s(`editTask`)]}),(0,d.jsxs)(l,{variant:`destructive`,disabled:h(q),onClick:()=>void $(q.id,`delete`),children:[(0,d.jsx)(te,{className:`mr-1 size-3.5`}),s(`deleteTask`)]})]})})]})}):null,je?(0,d.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4`,onMouseDown:e=>{e.target===e.currentTarget&&Q()},children:(0,d.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,d.jsx)(`div`,{className:`shrink-0 border-b border-border px-5 py-4`,children:(0,d.jsxs)(`h2`,{className:`inline-flex items-center gap-1.5 text-base font-semibold text-foreground`,children:[s(K?`editTask`:`createTask`),(0,d.jsx)(c,{label:s(`quickAiParseTask`)})]})}),(0,d.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-5 py-4`,children:(0,d.jsxs)(`div`,{className:`space-y-4`,children:[(0,d.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[s(`taskScheduleDescriptionLabel`),(0,d.jsx)(`textarea`,{className:`mt-1 min-h-24 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`,value:v.scheduleText,onChange:e=>X(`scheduleText`,e.target.value),placeholder:s(`taskScheduleDescriptionPlaceholder`)})]}),(0,d.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,d.jsxs)(l,{onClick:Qe,disabled:k||!P||!v.scheduleText.trim(),children:[(0,d.jsx)(ne,{className:`mr-1 size-3.5`}),s(`aiParseTask`)]}),Me?(0,d.jsx)(`span`,{className:`text-sm text-amber-600`,children:Me}):null]}),(0,d.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,d.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[s(`taskTitleLabel`),(0,d.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`,value:v.title,onChange:e=>X(`title`,e.target.value),placeholder:s(`taskTitlePlaceholder`)})]}),(0,d.jsxs)(`div`,{className:`block text-sm font-medium text-foreground`,children:[s(`executionRule`),(0,d.jsx)(`div`,{className:`mt-1 flex h-10 items-center rounded-md border border-input bg-muted/20 px-3 text-sm text-muted-foreground`,children:v.scheduleRule||`-`})]}),(0,d.jsxs)(`div`,{className:`block text-sm font-medium text-foreground`,children:[`cron`,(0,d.jsx)(`div`,{className:`mt-1 flex h-10 items-center rounded-md border border-input bg-muted/20 px-3 font-mono text-sm text-muted-foreground`,children:v.cronExpression||`-`})]}),(0,d.jsxs)(`div`,{className:`block text-sm font-medium text-foreground`,children:[s(`nextExecutionTime`),(0,d.jsx)(`div`,{className:`mt-1 flex h-10 items-center rounded-md border border-input bg-muted/20 px-3 text-sm text-muted-foreground`,children:p(v.nextRunAt)})]}),(0,d.jsxs)(`label`,{className:`block text-sm font-medium text-foreground sm:col-span-2`,children:[(0,d.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[s(`taskExecutionMode`),(0,d.jsx)(c,{label:s(`taskExecutionModeHelp`)})]}),(0,d.jsxs)(`select`,{className:`mt-1 h-10 w-full rounded-md border border-input bg-background px-3 text-sm text-foreground outline-none focus:border-ring`,value:v.executionMode,onChange:e=>X(`executionMode`,e.target.value),children:[(0,d.jsx)(`option`,{value:`serial`,children:s(`taskExecutionModeSerial`)}),(0,d.jsx)(`option`,{value:`parallel`,children:s(`taskExecutionModeParallel`)})]})]}),(0,d.jsxs)(`label`,{className:`block text-sm font-medium text-foreground sm:col-span-2`,children:[s(`promptContentLabel`),(0,d.jsx)(`textarea`,{className:`mt-1 min-h-28 w-full resize-y rounded-xl border border-input bg-background px-3 py-2 text-sm text-foreground outline-none transition-colors placeholder:text-muted-foreground/65 focus:border-ring`,value:v.instruction,onChange:e=>X(`instruction`,e.target.value),placeholder:s(`promptContentPlaceholder`)})]})]}),(0,d.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-foreground`,children:[(0,d.jsx)(`input`,{type:`checkbox`,checked:v.enabled,onChange:e=>X(`enabled`,e.target.checked)}),s(`taskEnabledSwitch`)]}),(0,d.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 rounded-xl border border-border bg-muted/20 px-2 py-2`,children:[(0,d.jsxs)(`span`,{className:`relative inline-flex items-center`,children:[(0,d.jsx)(ne,{className:`pointer-events-none absolute left-2 size-3.5 text-muted-foreground/70`}),(0,d.jsxs)(`select`,{className:`h-8 max-w-[240px] rounded-md border border-transparent bg-transparent pl-7 pr-2 text-xs text-muted-foreground outline-none hover:bg-background focus:border-ring`,value:P?`${P.provider}\u0000${P.id}`:``,onChange:e=>{let t=N.find(t=>`${t.provider}\u0000${t.id}`===e.target.value);F(t),L(he(t))},title:s(`taskModel`),children:[N.length===0?(0,d.jsx)(`option`,{value:``,children:s(`noModelAvailable`)}):null,N.map(e=>(0,d.jsxs)(`option`,{value:`${e.provider}\u0000${e.id}`,children:[ve(e),ye(e,P)?` ✓`:``]},`${e.provider}:${e.id}`))]})]}),(0,d.jsxs)(`span`,{className:`relative inline-flex items-center`,children:[(0,d.jsx)(i,{className:`pointer-events-none absolute left-2 size-3.5 text-muted-foreground/70`}),(0,d.jsx)(`select`,{className:`h-8 rounded-md border border-transparent bg-transparent pl-7 pr-2 text-xs text-muted-foreground outline-none hover:bg-background focus:border-ring`,value:I,onChange:e=>L(e.target.value),title:s(`taskThinking`),children:_e.map(e=>(0,d.jsx)(`option`,{value:e.value,children:e.label()},e.value))})]}),(0,d.jsxs)(`span`,{className:`relative inline-flex items-center`,children:[(0,d.jsx)(r,{className:`pointer-events-none absolute left-2 size-3.5 text-muted-foreground/70`}),(0,d.jsxs)(`select`,{className:`h-8 max-w-[220px] rounded-md border border-transparent bg-transparent pl-7 pr-2 text-xs text-muted-foreground outline-none hover:bg-background focus:border-ring`,value:Fe,onChange:e=>z(e.target.value),title:s(`taskProjectLabel`),children:[(0,d.jsx)(`option`,{value:``,children:s(`noProjectBound`)}),R.map(e=>(0,d.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,d.jsxs)(`span`,{className:`relative inline-flex items-center`,children:[(0,d.jsx)(t,{className:`pointer-events-none absolute left-2 size-3.5 text-muted-foreground/70`}),(0,d.jsxs)(`select`,{className:`h-8 max-w-[220px] rounded-md border border-transparent bg-transparent pl-7 pr-2 text-xs text-muted-foreground outline-none hover:bg-background focus:border-ring`,value:v.agentId,onChange:e=>X(`agentId`,e.target.value),title:s(`executionAgent`),children:[(0,d.jsx)(`option`,{value:``,children:s(`defaultAgent`)}),Ve.map(e=>(0,d.jsx)(`option`,{value:e.id,children:e.label},e.id))]})]})]}),E?(0,d.jsxs)(`div`,{className:`rounded-xl border border-border bg-muted/30 p-3 text-sm`,children:[(0,d.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 font-medium text-foreground`,children:[(0,d.jsx)(re,{className:`size-4 text-emerald-600`}),s(`aiParsed`)]}),(0,d.jsxs)(`div`,{className:`grid gap-2 text-muted-foreground sm:grid-cols-2`,children:[(0,d.jsxs)(`div`,{children:[s(`taskName`),(0,d.jsx)(`span`,{className:`text-foreground`,children:E.title})]}),(0,d.jsxs)(`div`,{children:[s(`executionRule`),(0,d.jsx)(`span`,{className:`text-foreground`,children:E.scheduleRule})]}),(0,d.jsxs)(`div`,{children:[`cron:`,(0,d.jsx)(`span`,{className:`font-mono text-foreground`,children:E.cronExpression??`-`})]}),(0,d.jsxs)(`div`,{children:[s(`nextExecutionTime`),(0,d.jsx)(`span`,{className:`text-foreground`,children:p(E.nextRunAt)})]}),(0,d.jsxs)(`div`,{className:`sm:col-span-2`,children:[s(`aiInstruction`),(0,d.jsx)(`span`,{className:`text-foreground`,children:E.instruction})]})]})]}):null,j?(0,d.jsx)(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive`,children:j}):null]})}),(0,d.jsx)(`div`,{className:`shrink-0 border-t border-border px-5 py-4`,children:(0,d.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,d.jsx)(l,{variant:`outline`,onClick:Q,disabled:k,children:s(`cancel`)}),(0,d.jsx)(l,{onClick:$e,disabled:k||!P||!De(v),children:s(K?`saveTask`:`confirmCreate`)})]})})]})}):null]})}export{_ as ScheduledTasksPage};
@@ -1 +1 @@
1
- import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{i as t,it as n,wt as r}from"./icons-DzxBk7tb.js";import{n as i}from"./react-vendor-DsAeMFcm.js";import{f as a,i as o,n as s,r as c,t as l,u}from"./pi-web-ui-CBet4bMl.js";import{p as d}from"./pi-ai-Cx633yhb.js";import{t as f}from"./logger-B65Akg8A.js";import{A as p,C as m,F as h,I as g,P as _,S as v,T as y,b,d as x,f as S,j as C,m as w,p as T,v as E,w as D,y as O}from"./index-DTiIspXQ.js";import{ChatPanelHost as k}from"./ChatPanelHost-nzOC6Tbg.js";var A=e(r(),1),j=`quickforgeClientMessageId`;function M(e){let t=e?.metadata;return t&&typeof t==`object`&&!Array.isArray(t)?t:void 0}function N(e){let t=M(e)?.[j];return typeof t==`string`&&t?t:void 0}function P(){return`qfcm_${typeof crypto<`u`&&typeof crypto.randomUUID==`function`?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`}`}function F(e){let t=N(e);if(t)return{message:e,clientMessageId:t};let n=P();return{message:{...e,metadata:{...M(e),[j]:n}},clientMessageId:n}}function I(e){return typeof e==`string`?e:Array.isArray(e)?e.filter(e=>e&&typeof e==`object`&&e.type===`text`).map(e=>e.text).filter(e=>typeof e==`string`).join(``):``}function L(e,t){if(!e||!t||e.role!==t.role)return!1;let n=N(e),r=N(t);return n&&r?n===r:I(e.content)===I(t.content)}async function R(e,t){let n=await fetch(e,{...t,cache:`no-store`,headers:{...t?.body?{"content-type":`application/json`}:void 0,...t?.headers}}),r=await n.json().catch(()=>null);if(!n.ok)throw Error(r?.error||`Request failed: ${n.status}`);return r}var z=class e{state;streamFn=d;getApiKey;sessionId;shareId;permission;listeners=new Set;eventSource=null;disposed=!1;reconnectTimer=null;reconnectDelay=1e3;baseUrl=``;syncingThinkingLevel=!1;planMode=!1;onPlanModeConsumed;constructor(e,t){this.shareId=e,this.sessionId=t.sessionId||t.id||e,this.permission=t.permission??`read`;let n={systemPrompt:t.systemPrompt??``,model:t.model??{provider:`shared`,id:`shared`},thinkingLevel:t.thinkingLevel??`off`,messages:t.messages?.slice()??[],tools:t.tools??[],isStreaming:!!t.isStreaming,streamingMessage:void 0,pendingToolCalls:new Set,errorMessage:t.errorMessage,contextCompaction:t.contextCompaction??null,contextUsage:t.contextUsage??null};this.state=new Proxy(n,{set:(e,t,n)=>{let r=e[t];return e[t]=n,t===`thinkingLevel`&&!this.syncingThinkingLevel&&n!==r&&this.updateThinkingLevel(n).catch(e=>{f.error(`Failed to update shared thinking level:`,e)}),!0}}),this.connectEvents()}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}setNextPromptCapabilities(){}setPlanMode(e,t){this.planMode=e,this.onPlanModeConsumed=e?t:void 0}async prompt(e){if(this.disposed||this.permission!==`operate`)return;let{message:t,clientMessageId:n}=F(this.normalizeInput(e)),r=this.planMode?{type:`plan`}:void 0;if(this.planMode){this.planMode=!1;let e=this.onPlanModeConsumed;this.onPlanModeConsumed=void 0,e?.()}this.state.messages=[...this.state.messages,t],this.emit({type:`message_start`,message:t}),this.state.isStreaming||(this.state.isStreaming=!0,this.state.errorMessage=void 0,this.emit({type:`agent_start`}));try{await R(`/api/shared/${encodeURIComponent(this.shareId)}/message`,{method:`POST`,body:JSON.stringify({message:t,clientMessageId:n,command:r})})}catch(e){let t=e instanceof Error?e.message:String(e);throw this.state.errorMessage=t,this.state.isStreaming=!1,this.emit({type:`error`,error:t}),this.emit({type:`agent_end`,messages:this.state.messages}),e}}async updateModel(e){if(!(this.disposed||this.permission!==`operate`)){this.state.model=e;try{let t=await R(`/api/shared/${encodeURIComponent(this.shareId)}/model`,{method:`POST`,body:JSON.stringify({model:e})});t.model&&(this.state.model=t.model)}catch(e){let t=e instanceof Error?e.message:String(e);throw this.state.errorMessage=t,this.emit({type:`error`,error:t}),e}}}async updateThinkingLevel(e){if(!(this.disposed||this.permission!==`operate`)){!this.syncingThinkingLevel&&this.state.thinkingLevel!==e&&(this.state.thinkingLevel=e);try{let t=await R(`/api/shared/${encodeURIComponent(this.shareId)}/thinking-level`,{method:`POST`,body:JSON.stringify({thinkingLevel:e})});t.thinkingLevel&&(this.state.thinkingLevel=t.thinkingLevel)}catch(e){let t=e instanceof Error?e.message:String(e);throw this.state.errorMessage=t,this.emit({type:`error`,error:t}),e}}}abort(){this.permission===`operate`&&fetch(`/api/shared/${encodeURIComponent(this.shareId)}/abort`,{method:`POST`}).catch(e=>{f.error(`Failed to abort shared conversation:`,e)})}steer(){}followUp(){}reset(){this.state.messages=[],this.state.errorMessage=void 0,this.state.isStreaming=!1,this.state.streamingMessage=void 0,this.state.pendingToolCalls=new Set}async rollback(e){if(this.permission!==`operate`)return;let t=await R(`/api/shared/${encodeURIComponent(this.shareId)}/rollback`,{method:`POST`,body:JSON.stringify({messageIndex:e})});return this.applyState(t.session),this.emit({type:`messages_replaced`,messages:this.state.messages}),t}dispose(){this.disposed=!0,this.reconnectTimer&&clearTimeout(this.reconnectTimer),this.reconnectTimer=null,this.eventSource?.close(),this.eventSource=null,this.listeners.clear()}static async loadState(e){return R(`/api/shared/${encodeURIComponent(e)}/session`)}static async create(t){return new e(t,await e.loadState(t))}normalizeInput(e){return typeof e==`string`?{role:`user`,content:e,timestamp:Date.now()}:Array.isArray(e)?[...e].reverse().find(e=>e.role===`user`||e.role===`user-with-attachments`)??e[e.length-1]:e}connectEvents(){this.disposed||(this.eventSource?.close(),this.baseUrl=``,this.openEventSource())}openEventSource(){if(this.disposed)return;let e=`${this.baseUrl}/api/shared/${encodeURIComponent(this.shareId)}/events`;this.eventSource=new EventSource(e,{withCredentials:!0}),this.eventSource.onopen=()=>{this.reconnectDelay=1e3};let t=[`state`,`agent_start`,`agent_end`,`message_start`,`message_end`,`turn_start`,`turn_end`,`message_update`,`tool_execution_start`,`tool_execution_update`,`tool_execution_end`,`error`,`title_updated`,`messages_replaced`,`auto_compact_completed`],n=e=>t=>{try{let n=JSON.parse(t.data);this.handleEvent(e?{type:e,...n}:n)}catch{}};this.eventSource.onmessage=n();for(let e of t)this.eventSource.addEventListener(e,n(e));this.eventSource.onerror=()=>{this.eventSource?.close(),this.eventSource=null,this.scheduleReconnect()}}scheduleReconnect(){this.disposed||this.reconnectTimer||(this.reconnectTimer=setTimeout(()=>{this.reconnectTimer=null,this.reconnectDelay=Math.min(this.reconnectDelay*2,3e4),this.openEventSource()},this.reconnectDelay))}handleEvent(e){if(e.type){switch(e.type){case`state`:this.applyState(e);break;case`agent_start`:this.state.isStreaming=!0,this.state.errorMessage=void 0;break;case`agent_end`:this.state.isStreaming=!1,this.state.streamingMessage=void 0;break;case`message_start`:if(e.message){let t=this.state.messages.findIndex(t=>L(t,e.message));if(t>=0){let n=this.state.messages.slice();n[t]=e.message,this.state.messages=n}else this.state.messages=[...this.state.messages,e.message];this.state.contextUsage=null}break;case`message_update`:e.message&&(this.state.streamingMessage=e.message);break;case`message_end`:e.message&&(this.state.messages=m(this.state.messages,e.message)),this.state.contextUsage=`contextUsage`in e?e.contextUsage:null,this.state.streamingMessage=void 0;break;case`messages_replaced`:e.messages&&(this.state.messages=e.messages,this.state.streamingMessage=void 0),`contextCompaction`in e&&(this.state.contextCompaction=e.contextCompaction),`contextUsage`in e&&(this.state.contextUsage=e.contextUsage);break;case`auto_compact_completed`:`contextCompaction`in e&&(this.state.contextCompaction=e.contextCompaction),`contextUsage`in e&&(this.state.contextUsage=e.contextUsage);break;case`tool_execution_start`:{let t=e;t.toolCallId&&(this.state.messages=D(this.state.messages,v(t),!0),this.state.pendingToolCalls=new Set([...this.state.pendingToolCalls,t.toolCallId]));break}case`tool_execution_update`:{let t=e;this.state.messages=D(this.state.messages,t,!0),t.toolCallId&&(this.state.pendingToolCalls=new Set([...this.state.pendingToolCalls,t.toolCallId]));break}case`tool_execution_end`:{let t=e;if(this.state.messages=D(this.state.messages,t,!1),t.toolCallId){let e=new Set(this.state.pendingToolCalls);e.delete(t.toolCallId),this.state.pendingToolCalls=e}break}case`error`:this.state.errorMessage=typeof e.error==`string`?e.error:`Unknown error`,this.state.isStreaming=!1;break}this.emit(e)}}applyState(e){this.sessionId=e.sessionId||e.id||this.sessionId,e.messages&&(this.state.messages=e.messages,this.state.contextUsage=e.contextUsage===void 0?null:e.contextUsage),e.systemPrompt!==void 0&&(this.state.systemPrompt=e.systemPrompt),e.model&&(this.state.model=e.model),e.thinkingLevel&&(this.syncingThinkingLevel=!0,this.state.thinkingLevel=e.thinkingLevel,this.syncingThinkingLevel=!1),e.tools&&(this.state.tools=e.tools),e.isStreaming!==void 0&&(this.state.isStreaming=!!e.isStreaming),e.errorMessage!==void 0&&(this.state.errorMessage=e.errorMessage),e.contextCompaction!==void 0&&(this.state.contextCompaction=e.contextCompaction),e.contextUsage!==void 0&&(this.state.contextUsage=e.contextUsage)}emit(e){for(let t of this.listeners)try{t(e)}catch{}}},B=i();function V(e){return{id:`shared-${e.provider}`,name:e.provider,type:e.api,baseUrl:e.baseUrl??``,models:[e]}}async function H(e,t){try{let t=await S(e);if(t.providers?.length)return t.providers}catch{}return t?[V(t)]:[]}function U(e,t){let n=t.model??{provider:`shared`,id:`shared`};return new z(e,{...t,model:n,thinkingLevel:t.thinkingLevel??y(n)})}function W(e,t){let n={settings:new l,providerKeys:new c,sessions:new s,customProviders:new o},r=new p(``,{blockedStores:[`sessions`,`provider-keys`],fakeProviderKeys:t?[t.provider]:void 0,storeOverrides:t?{"custom-providers":{keys:async()=>(await H(e,t)).map(e=>e.name),get:async n=>(await H(e,t)).find(e=>e.name===n)??null,has:async n=>(await H(e,t)).some(e=>e.name===n)}}:void 0});n.settings.setBackend(r),n.providerKeys.setBackend(r),n.sessions.setBackend(r),n.customProviders.setBackend(r),a(new u(n.settings,n.providerKeys,n.sessions,n.customProviders,r))}function G({shareId:e}){let[r,i]=(0,A.useState)(``),[a,o]=(0,A.useState)(null),[s,c]=(0,A.useState)(`read`),[l,u]=(0,A.useState)(`QuickForge 分享对话`),[d,p]=(0,A.useState)(),[m,v]=(0,A.useState)(!1),[y,S]=(0,A.useState)(),D=(0,A.useRef)(!1),j=s===`operate`,M=!!a,N=!!a?.state.tools?.length;(0,A.useEffect)(()=>{W(e,a?.state.model)},[a?.state.model,e]),(0,A.useEffect)(()=>()=>a?.dispose(),[a]);let P=(0,A.useCallback)(async(t=r.trim())=>{p(void 0),v(!0);try{let n=await T(e,t);c(n.permission),u(n.title||n.share.titleSnapshot||`QuickForge 分享对话`);let r=await z.loadState(e);W(e,r.model),o(U(e,r))}catch(e){p(e instanceof Error?e.message:`Failed to unlock shared conversation`)}finally{v(!1)}},[r,e]);(0,A.useEffect)(()=>{if(M||m||D.current)return;D.current=!0;let t=window.setTimeout(()=>{(async()=>{try{(await x(e)).share.hasPassword||await P(``)}catch(e){p(e instanceof Error?e.message:`Failed to load shared conversation`)}})()},0);return()=>window.clearTimeout(t)},[m,e,P,M]);let F=(0,A.useCallback)(async e=>{await E(e)},[]),I=(0,A.useCallback)(async()=>{if(!(!a||a.permission!==`operate`))try{let t=(await H(e,a.state.model)).flatMap(e=>e.models??[]);if(!t.length)return;w(a.state.model,t,t=>{!t.reasoning&&a.state.thinkingLevel!==`off`&&a.updateThinkingLevel(`off`).catch(e=>{f.error(`Failed to update shared thinking level:`,e)}),W(e,t),a.updateModel(t).catch(e=>{p(e instanceof Error?e.message:`Failed to update model`)})},void 0,{thinkingLevel:a.state.thinkingLevel,onThinkingLevelSelect:e=>{a.updateThinkingLevel(e).catch(e=>{f.error(`Failed to update shared thinking level:`,e),p(e instanceof Error?e.message:`Failed to update thinking level`)})}})}catch(e){p(e instanceof Error?e.message:`Failed to load models`)}},[a,e]),L=(0,A.useCallback)(async e=>{if(!a||a.permission!==`operate`)return;if(p(void 0),a.state.isStreaming){C(g(`generationStillRunning`));return}let t=b(a.state.messages,e),n=t>=0?a.state.messages[t]:void 0;if(!n){C(g(`noConversationTurnToRollback`));return}try{await a.rollback(e),S({id:Date.now(),sessionId:a.sessionId,text:O(n),attachments:n.role===`user-with-attachments`?n.attachments:void 0})}catch(e){p(e instanceof Error?e.message:`Failed to roll back`)}},[a]);return M?(0,B.jsxs)(`div`,{className:`flex h-screen min-h-0 flex-col bg-background text-foreground`,children:[(0,B.jsx)(`header`,{className:h(`shrink-0 border-b px-4 py-3`,j?`border-red-300 bg-red-50 text-red-950`:`border-border bg-background`),children:(0,B.jsxs)(`div`,{className:`mx-auto flex max-w-4xl items-start gap-3`,children:[(0,B.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,B.jsx)(`div`,{className:`truncate text-sm font-semibold`,children:l}),(0,B.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-2 gap-y-1 text-xs`,children:[(0,B.jsxs)(`span`,{className:h(`inline-flex items-center gap-1 rounded-full px-2 py-0.5 font-medium`,j?`bg-red-100 text-red-700`:`bg-muted text-muted-foreground`),children:[j?(0,B.jsx)(t,{className:`size-3.5`}):null,j?`高危可操作`:`只读分享`]}),(0,B.jsx)(`span`,{className:h(j?`text-red-800`:`text-muted-foreground`),children:j?`正在操作分享者的原始对话`:`只能查看,不能发送或修改`})]}),j?null:(0,B.jsx)(`div`,{className:`mt-1 text-xs leading-5 text-muted-foreground`,children:`界面与正常对话保持一致`})]}),(0,B.jsxs)(_,{variant:`ghost`,size:`sm`,className:h(`shrink-0`,j?`text-red-700 hover:bg-red-100 hover:text-red-800`:void 0),onClick:()=>void E(window.location.href),"aria-label":j?`复制高危分享链接`:`复制分享链接`,title:j?`复制高危分享链接`:`复制分享链接`,children:[(0,B.jsx)(n,{className:`size-4`}),(0,B.jsx)(`span`,{className:`hidden sm:inline`,children:j?`复制高危链接`:`复制链接`})]})]})}),d?(0,B.jsx)(`div`,{className:`mx-auto w-full max-w-4xl px-4 py-2 text-sm text-destructive`,children:d}):null,(0,B.jsx)(k,{agent:a,revision:0,agentAccessMode:N?`full-access`:`default`,workspaceToolsEnabled:N,onModelSelect:I,onAccessModeChange:()=>void 0,onRollbackFromMessage:L,onRetryFromMessage:()=>void 0,onCopyAnswer:F,onForkFromMessage:()=>void 0,onApproveToolCall:()=>void 0,onRejectToolCall:()=>void 0,disableFork:!0,rollbackConfirmTitle:g(`sharedRollbackConfirmTitle`),rollbackConfirmDescription:g(`sharedRollbackConfirm`),readOnly:!j,restoredDraft:y,bypassClientApiKeyCheck:!0})]}):(0,B.jsx)(`div`,{className:`flex min-h-screen items-center justify-center bg-background p-6 text-foreground`,children:(0,B.jsxs)(`div`,{className:`w-full max-w-md rounded-2xl border border-border bg-background p-6 shadow-quickforge`,children:[(0,B.jsxs)(`div`,{className:`flex items-center gap-2 text-base font-semibold`,children:[(0,B.jsx)(t,{className:`size-5 text-amber-500`}),`QuickForge 局域网对话分享`]}),(0,B.jsx)(`p`,{className:`mt-2 text-sm text-muted-foreground`,children:`如果分享者设置了密码,请输入密码。未设置密码的链接会自动打开。`}),(0,B.jsx)(`input`,{type:`password`,value:r,onChange:e=>i(e.target.value),onKeyDown:e=>{e.key===`Enter`&&P()},className:`mt-5 h-10 w-full rounded-md border border-input bg-background px-3 text-sm outline-none focus:border-primary`,placeholder:`密码`,autoFocus:!0}),d?(0,B.jsx)(`div`,{className:`mt-3 rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive`,children:d}):null,(0,B.jsx)(_,{className:`mt-5 w-full`,onClick:()=>void P(),disabled:m||!r.trim(),children:m?g(`loading`):`用密码打开分享对话`})]})})}export{G as SharedConversationPage};
1
+ import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{Et as t,i as n,ot as r}from"./icons-Uo4Gd-eK.js";import{n as i}from"./react-vendor-BjDQPVuK.js";import{f as a,i as o,n as s,r as c,t as l,u}from"./pi-web-ui-CBet4bMl.js";import{p as d}from"./pi-ai-Cx633yhb.js";import{t as f}from"./logger-B65Akg8A.js";import{A as p,C as m,F as h,I as g,P as _,S as v,T as y,b,d as x,f as S,j as C,m as w,p as T,v as E,w as D,y as O}from"./index-DiaCCmXE.js";import{ChatPanelHost as k}from"./ChatPanelHost-u0K5IWMF.js";var A=e(t(),1),j=`quickforgeClientMessageId`;function M(e){let t=e?.metadata;return t&&typeof t==`object`&&!Array.isArray(t)?t:void 0}function N(e){let t=M(e)?.[j];return typeof t==`string`&&t?t:void 0}function P(){return`qfcm_${typeof crypto<`u`&&typeof crypto.randomUUID==`function`?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`}`}function F(e){let t=N(e);if(t)return{message:e,clientMessageId:t};let n=P();return{message:{...e,metadata:{...M(e),[j]:n}},clientMessageId:n}}function I(e){return typeof e==`string`?e:Array.isArray(e)?e.filter(e=>e&&typeof e==`object`&&e.type===`text`).map(e=>e.text).filter(e=>typeof e==`string`).join(``):``}function L(e,t){if(!e||!t||e.role!==t.role)return!1;let n=N(e),r=N(t);return n&&r?n===r:I(e.content)===I(t.content)}async function R(e,t){let n=await fetch(e,{...t,cache:`no-store`,headers:{...t?.body?{"content-type":`application/json`}:void 0,...t?.headers}}),r=await n.json().catch(()=>null);if(!n.ok)throw Error(r?.error||`Request failed: ${n.status}`);return r}var z=class e{state;streamFn=d;getApiKey;sessionId;shareId;permission;listeners=new Set;eventSource=null;disposed=!1;reconnectTimer=null;reconnectDelay=1e3;baseUrl=``;syncingThinkingLevel=!1;planMode=!1;onPlanModeConsumed;constructor(e,t){this.shareId=e,this.sessionId=t.sessionId||t.id||e,this.permission=t.permission??`read`;let n={systemPrompt:t.systemPrompt??``,model:t.model??{provider:`shared`,id:`shared`},thinkingLevel:t.thinkingLevel??`off`,messages:t.messages?.slice()??[],tools:t.tools??[],isStreaming:!!t.isStreaming,streamingMessage:void 0,pendingToolCalls:new Set,errorMessage:t.errorMessage,contextCompaction:t.contextCompaction??null,contextUsage:t.contextUsage??null};this.state=new Proxy(n,{set:(e,t,n)=>{let r=e[t];return e[t]=n,t===`thinkingLevel`&&!this.syncingThinkingLevel&&n!==r&&this.updateThinkingLevel(n).catch(e=>{f.error(`Failed to update shared thinking level:`,e)}),!0}}),this.connectEvents()}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}setNextPromptCapabilities(){}setPlanMode(e,t){this.planMode=e,this.onPlanModeConsumed=e?t:void 0}async prompt(e){if(this.disposed||this.permission!==`operate`)return;let{message:t,clientMessageId:n}=F(this.normalizeInput(e)),r=this.planMode?{type:`plan`}:void 0;if(this.planMode){this.planMode=!1;let e=this.onPlanModeConsumed;this.onPlanModeConsumed=void 0,e?.()}this.state.messages=[...this.state.messages,t],this.emit({type:`message_start`,message:t}),this.state.isStreaming||(this.state.isStreaming=!0,this.state.errorMessage=void 0,this.emit({type:`agent_start`}));try{await R(`/api/shared/${encodeURIComponent(this.shareId)}/message`,{method:`POST`,body:JSON.stringify({message:t,clientMessageId:n,command:r})})}catch(e){let t=e instanceof Error?e.message:String(e);throw this.state.errorMessage=t,this.state.isStreaming=!1,this.emit({type:`error`,error:t}),this.emit({type:`agent_end`,messages:this.state.messages}),e}}async updateModel(e){if(!(this.disposed||this.permission!==`operate`)){this.state.model=e;try{let t=await R(`/api/shared/${encodeURIComponent(this.shareId)}/model`,{method:`POST`,body:JSON.stringify({model:e})});t.model&&(this.state.model=t.model)}catch(e){let t=e instanceof Error?e.message:String(e);throw this.state.errorMessage=t,this.emit({type:`error`,error:t}),e}}}async updateThinkingLevel(e){if(!(this.disposed||this.permission!==`operate`)){!this.syncingThinkingLevel&&this.state.thinkingLevel!==e&&(this.state.thinkingLevel=e);try{let t=await R(`/api/shared/${encodeURIComponent(this.shareId)}/thinking-level`,{method:`POST`,body:JSON.stringify({thinkingLevel:e})});t.thinkingLevel&&(this.state.thinkingLevel=t.thinkingLevel)}catch(e){let t=e instanceof Error?e.message:String(e);throw this.state.errorMessage=t,this.emit({type:`error`,error:t}),e}}}abort(){this.permission===`operate`&&fetch(`/api/shared/${encodeURIComponent(this.shareId)}/abort`,{method:`POST`}).catch(e=>{f.error(`Failed to abort shared conversation:`,e)})}steer(){}followUp(){}reset(){this.state.messages=[],this.state.errorMessage=void 0,this.state.isStreaming=!1,this.state.streamingMessage=void 0,this.state.pendingToolCalls=new Set}async rollback(e){if(this.permission!==`operate`)return;let t=await R(`/api/shared/${encodeURIComponent(this.shareId)}/rollback`,{method:`POST`,body:JSON.stringify({messageIndex:e})});return this.applyState(t.session),this.emit({type:`messages_replaced`,messages:this.state.messages}),t}dispose(){this.disposed=!0,this.reconnectTimer&&clearTimeout(this.reconnectTimer),this.reconnectTimer=null,this.eventSource?.close(),this.eventSource=null,this.listeners.clear()}static async loadState(e){return R(`/api/shared/${encodeURIComponent(e)}/session`)}static async create(t){return new e(t,await e.loadState(t))}normalizeInput(e){return typeof e==`string`?{role:`user`,content:e,timestamp:Date.now()}:Array.isArray(e)?[...e].reverse().find(e=>e.role===`user`||e.role===`user-with-attachments`)??e[e.length-1]:e}connectEvents(){this.disposed||(this.eventSource?.close(),this.baseUrl=``,this.openEventSource())}openEventSource(){if(this.disposed)return;let e=`${this.baseUrl}/api/shared/${encodeURIComponent(this.shareId)}/events`;this.eventSource=new EventSource(e,{withCredentials:!0}),this.eventSource.onopen=()=>{this.reconnectDelay=1e3};let t=[`state`,`agent_start`,`agent_end`,`message_start`,`message_end`,`turn_start`,`turn_end`,`message_update`,`tool_execution_start`,`tool_execution_update`,`tool_execution_end`,`error`,`title_updated`,`messages_replaced`,`auto_compact_completed`],n=e=>t=>{try{let n=JSON.parse(t.data);this.handleEvent(e?{type:e,...n}:n)}catch{}};this.eventSource.onmessage=n();for(let e of t)this.eventSource.addEventListener(e,n(e));this.eventSource.onerror=()=>{this.eventSource?.close(),this.eventSource=null,this.scheduleReconnect()}}scheduleReconnect(){this.disposed||this.reconnectTimer||(this.reconnectTimer=setTimeout(()=>{this.reconnectTimer=null,this.reconnectDelay=Math.min(this.reconnectDelay*2,3e4),this.openEventSource()},this.reconnectDelay))}handleEvent(e){if(e.type){switch(e.type){case`state`:this.applyState(e);break;case`agent_start`:this.state.isStreaming=!0,this.state.errorMessage=void 0;break;case`agent_end`:this.state.isStreaming=!1,this.state.streamingMessage=void 0;break;case`message_start`:if(e.message){let t=this.state.messages.findIndex(t=>L(t,e.message));if(t>=0){let n=this.state.messages.slice();n[t]=e.message,this.state.messages=n}else this.state.messages=[...this.state.messages,e.message];this.state.contextUsage=null}break;case`message_update`:e.message&&(this.state.streamingMessage=e.message);break;case`message_end`:e.message&&(this.state.messages=m(this.state.messages,e.message)),this.state.contextUsage=`contextUsage`in e?e.contextUsage:null,this.state.streamingMessage=void 0;break;case`messages_replaced`:e.messages&&(this.state.messages=e.messages,this.state.streamingMessage=void 0),`contextCompaction`in e&&(this.state.contextCompaction=e.contextCompaction),`contextUsage`in e&&(this.state.contextUsage=e.contextUsage);break;case`auto_compact_completed`:`contextCompaction`in e&&(this.state.contextCompaction=e.contextCompaction),`contextUsage`in e&&(this.state.contextUsage=e.contextUsage);break;case`tool_execution_start`:{let t=e;t.toolCallId&&(this.state.messages=D(this.state.messages,v(t),!0),this.state.pendingToolCalls=new Set([...this.state.pendingToolCalls,t.toolCallId]));break}case`tool_execution_update`:{let t=e;this.state.messages=D(this.state.messages,t,!0),t.toolCallId&&(this.state.pendingToolCalls=new Set([...this.state.pendingToolCalls,t.toolCallId]));break}case`tool_execution_end`:{let t=e;if(this.state.messages=D(this.state.messages,t,!1),t.toolCallId){let e=new Set(this.state.pendingToolCalls);e.delete(t.toolCallId),this.state.pendingToolCalls=e}break}case`error`:this.state.errorMessage=typeof e.error==`string`?e.error:`Unknown error`,this.state.isStreaming=!1;break}this.emit(e)}}applyState(e){this.sessionId=e.sessionId||e.id||this.sessionId,e.messages&&(this.state.messages=e.messages,this.state.contextUsage=e.contextUsage===void 0?null:e.contextUsage),e.systemPrompt!==void 0&&(this.state.systemPrompt=e.systemPrompt),e.model&&(this.state.model=e.model),e.thinkingLevel&&(this.syncingThinkingLevel=!0,this.state.thinkingLevel=e.thinkingLevel,this.syncingThinkingLevel=!1),e.tools&&(this.state.tools=e.tools),e.isStreaming!==void 0&&(this.state.isStreaming=!!e.isStreaming),e.errorMessage!==void 0&&(this.state.errorMessage=e.errorMessage),e.contextCompaction!==void 0&&(this.state.contextCompaction=e.contextCompaction),e.contextUsage!==void 0&&(this.state.contextUsage=e.contextUsage)}emit(e){for(let t of this.listeners)try{t(e)}catch{}}},B=i();function V(e){return{id:`shared-${e.provider}`,name:e.provider,type:e.api,baseUrl:e.baseUrl??``,models:[e]}}async function H(e,t){try{let t=await S(e);if(t.providers?.length)return t.providers}catch{}return t?[V(t)]:[]}function U(e,t){let n=t.model??{provider:`shared`,id:`shared`};return new z(e,{...t,model:n,thinkingLevel:t.thinkingLevel??y(n)})}function W(e,t){let n={settings:new l,providerKeys:new c,sessions:new s,customProviders:new o},r=new p(``,{blockedStores:[`sessions`,`provider-keys`],fakeProviderKeys:t?[t.provider]:void 0,storeOverrides:t?{"custom-providers":{keys:async()=>(await H(e,t)).map(e=>e.name),get:async n=>(await H(e,t)).find(e=>e.name===n)??null,has:async n=>(await H(e,t)).some(e=>e.name===n)}}:void 0});n.settings.setBackend(r),n.providerKeys.setBackend(r),n.sessions.setBackend(r),n.customProviders.setBackend(r),a(new u(n.settings,n.providerKeys,n.sessions,n.customProviders,r))}function G({shareId:e}){let[t,i]=(0,A.useState)(``),[a,o]=(0,A.useState)(null),[s,c]=(0,A.useState)(`read`),[l,u]=(0,A.useState)(`QuickForge 分享对话`),[d,p]=(0,A.useState)(),[m,v]=(0,A.useState)(!1),[y,S]=(0,A.useState)(),D=(0,A.useRef)(!1),j=s===`operate`,M=!!a,N=!!a?.state.tools?.length;(0,A.useEffect)(()=>{W(e,a?.state.model)},[a?.state.model,e]),(0,A.useEffect)(()=>()=>a?.dispose(),[a]);let P=(0,A.useCallback)(async(n=t.trim())=>{p(void 0),v(!0);try{let t=await T(e,n);c(t.permission),u(t.title||t.share.titleSnapshot||`QuickForge 分享对话`);let r=await z.loadState(e);W(e,r.model),o(U(e,r))}catch(e){p(e instanceof Error?e.message:`Failed to unlock shared conversation`)}finally{v(!1)}},[t,e]);(0,A.useEffect)(()=>{if(M||m||D.current)return;D.current=!0;let t=window.setTimeout(()=>{(async()=>{try{(await x(e)).share.hasPassword||await P(``)}catch(e){p(e instanceof Error?e.message:`Failed to load shared conversation`)}})()},0);return()=>window.clearTimeout(t)},[m,e,P,M]);let F=(0,A.useCallback)(async e=>{await E(e)},[]),I=(0,A.useCallback)(async()=>{if(!(!a||a.permission!==`operate`))try{let t=(await H(e,a.state.model)).flatMap(e=>e.models??[]);if(!t.length)return;w(a.state.model,t,t=>{!t.reasoning&&a.state.thinkingLevel!==`off`&&a.updateThinkingLevel(`off`).catch(e=>{f.error(`Failed to update shared thinking level:`,e)}),W(e,t),a.updateModel(t).catch(e=>{p(e instanceof Error?e.message:`Failed to update model`)})},void 0,{thinkingLevel:a.state.thinkingLevel,onThinkingLevelSelect:e=>{a.updateThinkingLevel(e).catch(e=>{f.error(`Failed to update shared thinking level:`,e),p(e instanceof Error?e.message:`Failed to update thinking level`)})}})}catch(e){p(e instanceof Error?e.message:`Failed to load models`)}},[a,e]),L=(0,A.useCallback)(async e=>{if(!a||a.permission!==`operate`)return;if(p(void 0),a.state.isStreaming){C(g(`generationStillRunning`));return}let t=b(a.state.messages,e),n=t>=0?a.state.messages[t]:void 0;if(!n){C(g(`noConversationTurnToRollback`));return}try{await a.rollback(e),S({id:Date.now(),sessionId:a.sessionId,text:O(n),attachments:n.role===`user-with-attachments`?n.attachments:void 0})}catch(e){p(e instanceof Error?e.message:`Failed to roll back`)}},[a]);return M?(0,B.jsxs)(`div`,{className:`flex h-screen min-h-0 flex-col bg-background text-foreground`,children:[(0,B.jsx)(`header`,{className:h(`shrink-0 border-b px-4 py-3`,j?`border-red-300 bg-red-50 text-red-950`:`border-border bg-background`),children:(0,B.jsxs)(`div`,{className:`mx-auto flex max-w-4xl items-start gap-3`,children:[(0,B.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,B.jsx)(`div`,{className:`truncate text-sm font-semibold`,children:l}),(0,B.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-2 gap-y-1 text-xs`,children:[(0,B.jsxs)(`span`,{className:h(`inline-flex items-center gap-1 rounded-full px-2 py-0.5 font-medium`,j?`bg-red-100 text-red-700`:`bg-muted text-muted-foreground`),children:[j?(0,B.jsx)(n,{className:`size-3.5`}):null,j?`高危可操作`:`只读分享`]}),(0,B.jsx)(`span`,{className:h(j?`text-red-800`:`text-muted-foreground`),children:j?`正在操作分享者的原始对话`:`只能查看,不能发送或修改`})]}),j?null:(0,B.jsx)(`div`,{className:`mt-1 text-xs leading-5 text-muted-foreground`,children:`界面与正常对话保持一致`})]}),(0,B.jsxs)(_,{variant:`ghost`,size:`sm`,className:h(`shrink-0`,j?`text-red-700 hover:bg-red-100 hover:text-red-800`:void 0),onClick:()=>void E(window.location.href),"aria-label":j?`复制高危分享链接`:`复制分享链接`,title:j?`复制高危分享链接`:`复制分享链接`,children:[(0,B.jsx)(r,{className:`size-4`}),(0,B.jsx)(`span`,{className:`hidden sm:inline`,children:j?`复制高危链接`:`复制链接`})]})]})}),d?(0,B.jsx)(`div`,{className:`mx-auto w-full max-w-4xl px-4 py-2 text-sm text-destructive`,children:d}):null,(0,B.jsx)(k,{agent:a,revision:0,agentAccessMode:N?`full-access`:`default`,workspaceToolsEnabled:N,onModelSelect:I,onAccessModeChange:()=>void 0,onRollbackFromMessage:L,onRetryFromMessage:()=>void 0,onCopyAnswer:F,onForkFromMessage:()=>void 0,onApproveToolCall:()=>void 0,onRejectToolCall:()=>void 0,disableFork:!0,rollbackConfirmTitle:g(`sharedRollbackConfirmTitle`),rollbackConfirmDescription:g(`sharedRollbackConfirm`),readOnly:!j,restoredDraft:y,bypassClientApiKeyCheck:!0})]}):(0,B.jsx)(`div`,{className:`flex min-h-screen items-center justify-center bg-background p-6 text-foreground`,children:(0,B.jsxs)(`div`,{className:`w-full max-w-md rounded-2xl border border-border bg-background p-6 shadow-quickforge`,children:[(0,B.jsxs)(`div`,{className:`flex items-center gap-2 text-base font-semibold`,children:[(0,B.jsx)(n,{className:`size-5 text-amber-500`}),`QuickForge 局域网对话分享`]}),(0,B.jsx)(`p`,{className:`mt-2 text-sm text-muted-foreground`,children:`如果分享者设置了密码,请输入密码。未设置密码的链接会自动打开。`}),(0,B.jsx)(`input`,{type:`password`,value:t,onChange:e=>i(e.target.value),onKeyDown:e=>{e.key===`Enter`&&P()},className:`mt-5 h-10 w-full rounded-md border border-input bg-background px-3 text-sm outline-none focus:border-primary`,placeholder:`密码`,autoFocus:!0}),d?(0,B.jsx)(`div`,{className:`mt-3 rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive`,children:d}):null,(0,B.jsx)(_,{className:`mt-5 w-full`,onClick:()=>void P(),disabled:m||!t.trim(),children:m?g(`loading`):`用密码打开分享对话`})]})})}export{G as SharedConversationPage};
@@ -0,0 +1,2 @@
1
+ import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{Et as t,I as n,P as r,b as i,k as a,n as o,s,yt as c}from"./icons-Uo4Gd-eK.js";import{n as l}from"./react-vendor-BjDQPVuK.js";import{F as u,I as d,P as f}from"./index-DiaCCmXE.js";import{n as p,t as m}from"./xterm-5XDrJ343.js";import{t as h}from"./useAppTheme-Bm6HIzLF.js";var g=e(t(),1);async function _(e,t){let n=await fetch(e,{cache:`no-store`,...t}),r=await n.json().catch(()=>null);if(!n.ok)throw Error(r?.error||`Request failed: ${n.status}`);return r}function v(){return _(`/api/terminal/capabilities`)}function y(e){return _(`/api/terminal/sessions${e?`?projectId=${encodeURIComponent(e)}`:``}`)}function b(e){return _(`/api/terminal/sessions`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(e)})}function x(e){return _(`/api/terminal/sessions/${encodeURIComponent(e)}`,{method:`DELETE`})}function S(e,t){return _(`/api/terminal/sessions/${encodeURIComponent(e)}/input`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({data:t})})}function C(){return``}function w(){let e=C();if(e){let t=new URL(e);return t.protocol=t.protocol===`https:`?`wss:`:`ws:`,t.toString().replace(/\/$/,``)}return`${location.protocol===`https:`?`wss:`:`ws:`}//${location.host}`}var T=l(),E={light:{background:`#ffffff`,foreground:`#1f2937`,cursor:`#1f2937`,selectionBackground:`#dbeafe`},dark:{background:`#171717`,foreground:`#e5e7eb`,cursor:`#e5e7eb`,selectionBackground:`#3f3f46`}};function ee({session:e,active:t,height:n,onReady:r,onExited:i,onConnectionError:a}){let o=h(),s=E[o],c=(0,g.useRef)(null),l=(0,g.useRef)(null),u=(0,g.useRef)(null),f=(0,g.useRef)(null),_=(0,g.useRef)(null),v=(0,g.useRef)(null);return(0,g.useEffect)(()=>{let t=c.current;if(!t)return;let n=!1,o=!1,h=!1,g=!1,y=t=>{n||h||g||(g=!0,a(e.id,t))},b=new p({cursorBlink:!0,convertEol:!1,fontFamily:`ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace`,fontSize:12,lineHeight:1.2,scrollback:5e3,theme:s}),x=new m;b.loadAddon(x),b.open(t),b.writeln(`\x1b[2mConnected to ${e.cwd}\x1b[0m`),l.current=b,u.current=x;let S=()=>{if(t.isConnected)try{x.fit();let{cols:e,rows:t}=b,n=f.current;n?.readyState===WebSocket.OPEN&&n.send(JSON.stringify({type:`resize`,cols:e,rows:t}))}catch{}},C=new WebSocket(`${w()}/api/terminal/sessions/${encodeURIComponent(e.id)}/ws`);f.current=C,C.addEventListener(`open`,()=>{o=!0,g=!1,a(e.id,void 0),_.current=b.onData(e=>{C.readyState===WebSocket.OPEN&&C.send(JSON.stringify({type:`input`,data:e}))}),window.setTimeout(S,0)}),C.addEventListener(`message`,t=>{try{let n=JSON.parse(String(t.data));n.type===`ready`?r(e.id):n.type===`output`?b.write(n.data):n.type===`exit`?(h=!0,b.writeln(``),b.writeln(`\x1b[33m[process exited with code ${n.exitCode??`unknown`}]\x1b[0m`),i(e.id)):n.type===`error`&&b.writeln(`\x1b[31m${n.message}\x1b[0m`)}catch{}}),C.addEventListener(`error`,()=>{y(d(o?`terminalConnectionClosedUnexpectedly`:`terminalConnectionFailed`))}),C.addEventListener(`close`,e=>{_.current?.dispose(),_.current=null,!(n||h)&&(!e.wasClean||e.code!==1e3)&&y(d(o?`terminalConnectionClosedUnexpectedly`:`terminalConnectionFailed`))});let T=new ResizeObserver(()=>S());return T.observe(t),v.current=T,window.setTimeout(S,50),()=>{n=!0,T.disconnect(),v.current=null,_.current?.dispose(),_.current=null,C.close(),f.current=null,b.dispose(),l.current=null,u.current=null}},[o,a,i,r,e.cwd,e.id,s]),(0,g.useEffect)(()=>{if(!t)return;let e=u.current,n=l.current;window.setTimeout(()=>{try{e?.fit(),n?.focus()}catch{}},0)},[t,n]),(0,T.jsx)(`div`,{ref:c,className:t?`h-full min-h-0 w-full`:`hidden`,"aria-hidden":!t})}var te=180,ne=.7,re=320;function D(e,t){let n=t?t.name:`Terminal`,r=new Set(e.map(e=>e.name));if(n!==`Terminal`&&!r.has(n))return n;let i=1;for(;r.has(`${n} ${i}`);)i+=1;return`${n} ${i}`}function O(e,t){let n=e?.terminalShellProfiles||[],r=t||e?.defaultTerminalShellProfileId||``;return n.find(e=>e.id===r)||n[0]}function k({project:e,onCollapse:t,pendingCommand:l,onPendingCommandHandled:p}){let[m,h]=(0,g.useState)(null),[_,C]=(0,g.useState)([]),[w,E]=(0,g.useState)(),[k,ie]=(0,g.useState)(re),[A,j]=(0,g.useState)(!0),[M,N]=(0,g.useState)(!1),[ae,P]=(0,g.useState)(),[oe,F]=(0,g.useState)({}),[I,L]=(0,g.useState)(!1),[R,z]=(0,g.useState)(!1),B=(0,g.useRef)(!1),V=(0,g.useRef)(new Set),H=(0,g.useRef)(l),U=(0,g.useRef)(new Set),W=(0,g.useRef)(new Set),G=(0,g.useRef)(new Map),K=(0,g.useRef)(!0),[q,J]=(0,g.useState)(()=>new Set),Y=(0,g.useRef)(null),se=(0,g.useRef)(null),X=e?.id,Z=(0,g.useMemo)(()=>_.find(e=>e.id===w)??_[0],[w,_]);(0,g.useEffect)(()=>{H.current=l},[l]),(0,g.useEffect)(()=>()=>{K.current=!1},[]);let ce=(0,g.useCallback)(async()=>{let e=await y(X);return C(e.sessions),E(t=>t&&e.sessions.some(e=>e.id===t)?t:e.sessions[0]?.id),e.sessions},[X]),le=(0,g.useCallback)(async(e,t)=>{if(B.current)return;let n=O(m,t);B.current=!0,N(!0),P(void 0),F({});try{let t=await b({projectId:X,name:D(e,n),cols:120,rows:30,shellProfileId:n?.id,shellProfileName:n?.name});C(e=>[...e,t]),E(t.id)}catch(e){P(e instanceof Error?e.message:d(`terminalCreateFailed`))}finally{B.current=!1,N(!1)}},[m,X]);(0,g.useEffect)(()=>{let e=!1;return(async()=>{j(!0),P(void 0);try{let[t,n]=await Promise.all([v(),y(X)]);if(e)return;if(h(t),C(n.sessions),E(n.sessions[0]?.id),t.enabled&&n.sessions.length===0&&!H.current){let n=O(t);b({projectId:X,name:D([],n),cols:120,rows:30,shellProfileId:n?.id,shellProfileName:n?.name}).then(t=>{if(e){x(t.id).catch(()=>{});return}C([t]),E(t.id)}).catch(t=>{e||P(t instanceof Error?t.message:d(`terminalCreateFailed`))})}}catch(t){e||P(t instanceof Error?t.message:d(`terminalUnavailable`))}finally{e||j(!1)}})(),()=>{e=!0}},[X]),(0,g.useEffect)(()=>{if(!I)return;let e=e=>{se.current?.contains(e.target)||L(!1)},t=e=>{e.key===`Escape`&&L(!1)};return document.addEventListener(`pointerdown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`pointerdown`,e),document.removeEventListener(`keydown`,t)}},[I]),(0,g.useEffect)(()=>{if(!R)return;let e=e=>{e.key===`Escape`&&z(!1)};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[R]),(0,g.useEffect)(()=>{if(!l||V.current.has(l.id)||G.current.has(l.id)||U.current.has(l.id)||A||M||!m)return;if(!m.enabled){V.current.add(l.id),window.setTimeout(()=>{P(m.reason||d(`terminalUnavailable`)),p?.(l.id)},0);return}let e=Z&&!Z.exited?Z:_.find(e=>!e.exited);if(e){G.current.set(l.id,e.id),window.setTimeout(()=>{K.current&&E(e.id)},0);return}U.current.add(l.id),window.setTimeout(()=>{K.current&&P(void 0)},0);let t=O(m);b({projectId:X,name:D(_,t),cols:120,rows:30,shellProfileId:t?.id,shellProfileName:t?.name}).then(e=>{if(!K.current){x(e.id).catch(()=>{});return}G.current.set(l.id,e.id),C(t=>t.some(t=>t.id===e.id)?t:[...t,e]),E(e.id)}).catch(e=>{K.current&&(P(e instanceof Error?e.message:d(`terminalCommandExecuteFailed`)),V.current.add(l.id),p?.(l.id))}).finally(()=>{U.current.delete(l.id)})},[Z,m,M,A,p,l,X,_]),(0,g.useEffect)(()=>{if(!l||V.current.has(l.id)||W.current.has(l.id))return;let e=G.current.get(l.id),t=e?_.find(t=>t.id===e):Z&&!Z.exited?Z:_.find(e=>!e.exited);!t||t.exited||!q.has(t.id)||(W.current.add(l.id),window.setTimeout(()=>{K.current&&(E(t.id),P(void 0))},0),(async()=>{try{if(l.execute){let e=l.command.split(`
2
+ `),n=e.flatMap((t,n)=>n<e.length-1?[t,`\r`]:[t]);n.push(`\r`),await S(t.id,n.join(``))}else await S(t.id,l.command)}catch(e){K.current&&P(e instanceof Error?e.message:d(`terminalCommandExecuteFailed`))}finally{V.current.add(l.id),W.current.delete(l.id),G.current.delete(l.id),K.current&&p?.(l.id)}})())},[Z,p,l,q,_]);let ue=async e=>{P(void 0),F(t=>{if(!t[e])return t;let n={...t};return delete n[e],n});let t=_.filter(t=>t.id!==e);C(t),w===e&&E(t[0]?.id);try{await x(e)}catch(e){P(e instanceof Error?e.message:d(`terminalCloseFailed`)),ce().catch(()=>{})}},de=(0,g.useCallback)(e=>{C(t=>t.map(t=>t.id===e?{...t,exited:!0}:t)),J(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),n})},[]),fe=(0,g.useCallback)(e=>{J(t=>{if(t.has(e))return t;let n=new Set(t);return n.add(e),n})},[]),pe=(0,g.useCallback)((e,t)=>{F(n=>{if(!t){if(!n[e])return n;let t={...n};return delete t[e],t}return n[e]===t?n:{...n,[e]:t}})},[]),me=e=>{Y.current={startY:e.clientY,startHeight:k},e.currentTarget.setPointerCapture(e.pointerId)},he=e=>{let t=Y.current;if(!t)return;let n=Math.max(te,Math.floor(window.innerHeight*ne));ie(Math.min(n,Math.max(te,t.startHeight+t.startY-e.clientY)))},ge=e=>{Y.current=null;try{e.currentTarget.releasePointerCapture(e.pointerId)}catch{}},Q=m?.terminalShellProfiles||[],_e=m?.defaultTerminalShellProfileId||``,ve=Q.find(e=>e.id===_e)||Q[0],ye=!!(m&&_.length>=m.maxSessions),be=M||ye,xe=Z?oe[Z.id]:void 0,$=ae??xe,Se=R?$?`calc(100% - 4.25rem)`:`calc(100% - 2.25rem)`:$?k-72:k-45;return(0,T.jsxs)(`div`,{className:u(`shrink-0 border-t border-border bg-background`,R&&`quickforge-terminal-fullscreen z-40 flex flex-col border-t-0`),style:R?void 0:{height:k},children:[R?null:(0,T.jsx)(`div`,{className:`h-1 cursor-row-resize bg-transparent hover:bg-border`,onPointerDown:me,onPointerMove:he,onPointerUp:ge,onPointerCancel:ge}),(0,T.jsxs)(`div`,{className:`flex h-9 items-center gap-1 border-b border-border px-2`,children:[(0,T.jsx)(s,{className:`size-4 shrink-0 text-muted-foreground/60`}),(0,T.jsx)(`div`,{className:`flex min-w-0 flex-1 items-center gap-1 overflow-x-auto`,children:_.map(e=>(0,T.jsxs)(`button`,{type:`button`,className:u(`group flex max-w-44 shrink-0 items-center gap-1 rounded-md px-2 py-1 text-xs text-muted-foreground/72 hover:bg-muted/20 hover:text-foreground/85`,Z?.id===e.id&&`bg-muted/28 text-foreground/90`),onClick:()=>E(e.id),title:`${e.name} — ${e.cwd}`,children:[(0,T.jsx)(`span`,{className:u(`size-1.5 rounded-full`,e.exited?`bg-muted-foreground/40`:`bg-emerald-500/80`)}),(0,T.jsx)(`span`,{className:`truncate`,children:e.name}),(0,T.jsx)(`span`,{role:`button`,tabIndex:0,className:`ml-1 rounded-sm p-0.5 opacity-60 hover:bg-background hover:opacity-100`,onClick:t=>{t.stopPropagation(),ue(e.id)},onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),t.stopPropagation(),ue(e.id))},"aria-label":d(`terminalCloseSession`,{name:e.name}),children:(0,T.jsx)(o,{className:`size-3`})})]},e.id))}),(0,T.jsxs)(`div`,{className:`relative shrink-0`,ref:se,children:[(0,T.jsxs)(`div`,{className:`flex items-center overflow-hidden rounded-md border border-border bg-background`,children:[(0,T.jsx)(`button`,{type:`button`,className:`inline-flex h-7 w-7 items-center justify-center text-foreground/85 transition-colors hover:bg-muted/20 disabled:pointer-events-none disabled:opacity-50`,onClick:()=>void le(_),disabled:be,title:ve?d(`terminalNewWithProfile`,{name:ve.name}):d(`terminalNew`),"aria-label":d(`terminalNew`),children:M?(0,T.jsx)(n,{className:`size-3.5 animate-spin`}):(0,T.jsx)(i,{className:`size-3.5`})}),Q.length>0?(0,T.jsx)(`button`,{type:`button`,className:`inline-flex h-7 w-7 items-center justify-center border-l border-border text-muted-foreground/72 transition-colors hover:bg-muted/20 hover:text-foreground/85 disabled:pointer-events-none disabled:opacity-50`,onClick:()=>L(e=>!e),disabled:be,title:d(`terminalSelectShell`),"aria-label":d(`terminalSelectShell`),"aria-expanded":I,children:(0,T.jsx)(c,{className:`size-3.5`})}):null]}),I?(0,T.jsxs)(`div`,{className:`absolute bottom-9 right-0 z-30 w-64 overflow-hidden rounded-lg border border-border bg-background p-1.5 shadow-[0_16px_38px_-22px_rgb(15_23_42_/_0.65)]`,children:[(0,T.jsx)(`div`,{className:`px-2 pb-1.5 pt-1 text-[11px] font-medium uppercase tracking-wide text-muted-foreground/60`,children:d(`terminalNewWith`)}),Q.map(e=>(0,T.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-xs text-muted-foreground/80 hover:bg-muted/20 hover:text-foreground/90`,onClick:()=>{L(!1),le(_,e.id)},children:[(0,T.jsx)(`span`,{className:`inline-flex size-5 shrink-0 items-center justify-center rounded bg-muted/20 text-[10px] text-muted-foreground/70`,children:e.name.slice(0,1).toUpperCase()}),(0,T.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,T.jsx)(`span`,{className:`block truncate font-medium`,children:e.name}),(0,T.jsx)(`span`,{className:`block truncate font-mono text-[11px] text-muted-foreground/55`,children:e.command})]})]},e.id))]}):null]}),(0,T.jsx)(f,{variant:`ghost`,size:`icon`,className:`size-7`,onClick:()=>z(e=>!e),title:d(R?`terminalExitFullscreen`:`terminalFullscreen`),"aria-label":d(R?`terminalExitFullscreen`:`terminalFullscreen`),children:R?(0,T.jsx)(a,{className:`size-3.5`}):(0,T.jsx)(r,{className:`size-3.5`})}),(0,T.jsx)(f,{variant:`ghost`,size:`icon`,className:`size-7`,onClick:t,title:d(`terminalCollapse`),"aria-label":d(`terminalCollapse`),children:(0,T.jsx)(c,{className:`size-3.5`})})]}),$?(0,T.jsx)(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-destructive`,children:$}):null,(0,T.jsx)(`div`,{className:`min-h-0 bg-background`,style:{height:Se},children:A?(0,T.jsxs)(`div`,{className:`flex h-full items-center justify-center gap-2 text-xs text-muted-foreground/60`,children:[(0,T.jsx)(n,{className:`size-4 animate-spin`}),` `,d(`terminalStarting`)]}):m&&!m.enabled?(0,T.jsx)(`div`,{className:`flex h-full items-center justify-center px-4 text-center text-xs text-muted-foreground/60`,children:m.reason||d(`terminalUnavailable`)}):_.length===0?(0,T.jsx)(`div`,{className:`flex h-full items-center justify-center text-xs text-muted-foreground/60`,children:d(`terminalNoSessions`)}):_.map(e=>(0,T.jsx)(ee,{session:e,active:e.id===Z?.id,height:R?window.innerHeight-36:k,onReady:fe,onExited:de,onConnectionError:pe},e.id))})]})}export{k as TerminalDock};