@shawnstack/quickforge 1.5.2 → 1.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -10
- package/dist/assets/{AgentProfilesPage-DKyIh3dE.js → AgentProfilesPage-BToo_R3Y.js} +1 -1
- package/dist/assets/{ChatPanelHost-BUZ6scv9.js → ChatPanelHost-BTqhhkWK.js} +1 -1
- package/dist/assets/{PluginsPage-CN-SFQ_s.js → PluginsPage-DwzV2vQ4.js} +1 -1
- package/dist/assets/{ScheduledTasksPage-C0htXZk2.js → ScheduledTasksPage-Cbm6LVk3.js} +1 -1
- package/dist/assets/{SharedConversationPage-CxbAx1fN.js → SharedConversationPage-CHE9qABz.js} +1 -1
- package/dist/assets/{TerminalDock-_voUf7d-.js → TerminalDock-Loi8A4pJ.js} +1 -1
- package/dist/assets/{WorkspaceInspector-Ci4FuaZH.js → WorkspaceInspector-Nf5xELW7.js} +1 -1
- package/dist/assets/{WorkspaceReaderDialog-D75__GFg.js → WorkspaceReaderDialog-Bai7v3V0.js} +1 -1
- package/dist/assets/{diff-line-counts-DHyWKEXk.js → diff-line-counts-CCPYa_e0.js} +1 -1
- package/dist/assets/{index-BzOV50wA.js → index-Bt_dRvdG.js} +39 -5
- package/dist/assets/{index-BI7xZuj-.css → index-BzaZg9Br.css} +1 -1
- package/dist/index.html +2 -2
- package/package.json +1 -1
- package/server/mcp/config.mjs +20 -20
- package/server/routes/backup.mjs +84 -20
- package/server/storage.mjs +182 -48
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
|
+
<img alt="Version" src="https://img.shields.io/badge/version-1.5.3-blue" />
|
|
5
5
|
<img alt="License" src="https://img.shields.io/badge/license-MIT-green" />
|
|
6
6
|
<img alt="Node" src="https://img.shields.io/badge/node-%3E%3D20-brightgreen" />
|
|
7
7
|
<img alt="React" src="https://img.shields.io/badge/react-19-61DAFB?logo=react" />
|
|
@@ -70,7 +70,7 @@ QuickForge 的工具能力很直接,因此也需要谨慎使用:
|
|
|
70
70
|
#### 从 npm 安装
|
|
71
71
|
|
|
72
72
|
```bash
|
|
73
|
-
npm install -g @shawnstack/quickforge@1.5.
|
|
73
|
+
npm install -g @shawnstack/quickforge@1.5.3
|
|
74
74
|
qf
|
|
75
75
|
|
|
76
76
|
# CLI 工具
|
|
@@ -84,17 +84,17 @@ qf update
|
|
|
84
84
|
当前版本的离线包:
|
|
85
85
|
|
|
86
86
|
```text
|
|
87
|
-
package-offline/shawnstack-quickforge-1.5.
|
|
87
|
+
package-offline/shawnstack-quickforge-1.5.3.tgz
|
|
88
88
|
```
|
|
89
89
|
|
|
90
90
|
在安装了 Node.js 20+ 和 npm 的机器上执行:
|
|
91
91
|
|
|
92
92
|
```bash
|
|
93
|
-
npm install -g ./package-offline/shawnstack-quickforge-1.5.
|
|
93
|
+
npm install -g ./package-offline/shawnstack-quickforge-1.5.3.tgz
|
|
94
94
|
qf
|
|
95
95
|
```
|
|
96
96
|
|
|
97
|
-
该包由 `v1.5.
|
|
97
|
+
该包由 `v1.5.3` 标签生成,包含 QuickForge 运行时资源,依赖由 npm 安装。
|
|
98
98
|
|
|
99
99
|
### 本地开发
|
|
100
100
|
|
|
@@ -234,7 +234,7 @@ QuickForge intentionally exposes powerful local capabilities, so the boundaries
|
|
|
234
234
|
#### npm
|
|
235
235
|
|
|
236
236
|
```bash
|
|
237
|
-
npm install -g @shawnstack/quickforge@1.5.
|
|
237
|
+
npm install -g @shawnstack/quickforge@1.5.3
|
|
238
238
|
qf
|
|
239
239
|
|
|
240
240
|
# CLI utilities
|
|
@@ -245,20 +245,20 @@ qf update
|
|
|
245
245
|
|
|
246
246
|
#### Offline tarball
|
|
247
247
|
|
|
248
|
-
The offline release package for `v1.5.
|
|
248
|
+
The offline release package for `v1.5.3` is:
|
|
249
249
|
|
|
250
250
|
```text
|
|
251
|
-
package-offline/shawnstack-quickforge-1.5.
|
|
251
|
+
package-offline/shawnstack-quickforge-1.5.3.tgz
|
|
252
252
|
```
|
|
253
253
|
|
|
254
254
|
Install it on a machine with Node.js 20+ and npm:
|
|
255
255
|
|
|
256
256
|
```bash
|
|
257
|
-
npm install -g ./package-offline/shawnstack-quickforge-1.5.
|
|
257
|
+
npm install -g ./package-offline/shawnstack-quickforge-1.5.3.tgz
|
|
258
258
|
qf
|
|
259
259
|
```
|
|
260
260
|
|
|
261
|
-
The package was generated from tag `v1.5.
|
|
261
|
+
The package was generated from tag `v1.5.3` and includes QuickForge runtime assets and installs dependencies with npm.
|
|
262
262
|
|
|
263
263
|
### Local development
|
|
264
264
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{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-BzOV50wA.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{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-Bt_dRvdG.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,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-
|
|
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-Bt_dRvdG.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 ee(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 te(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 M(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 ne(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 re(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 N(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 ie(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 ae(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}">
|
|
@@ -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-
|
|
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-Bt_dRvdG.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,2 +1,2 @@
|
|
|
1
|
-
import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{$ as t,B as n,T as r,a as i,bt as ee,c as a,ct as te,h as ne,n as re,t as ie,tt as ae,ut as oe,wt as o,xt as se,yt as ce}from"./icons-DzxBk7tb.js";import{n as s}from"./react-vendor-DsAeMFcm.js";import{D as le,E as ue,F as c,I as l,M as de,N as u,O as fe,P as d,T as pe,k as me}from"./index-
|
|
1
|
+
import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{$ as t,B as n,T as r,a as i,bt as ee,c as a,ct as te,h as ne,n as re,t as ie,tt as ae,ut as oe,wt as o,xt as se,yt as ce}from"./icons-DzxBk7tb.js";import{n as s}from"./react-vendor-DsAeMFcm.js";import{D as le,E as ue,F as c,I as l,M as de,N as u,O as fe,P as d,T as pe,k as me}from"./index-Bt_dRvdG.js";var f=e(o(),1),p=s(),he=[{value:`off`,label:()=>l(`thinkingOff`)},{value:`low`,label:()=>l(`thinkingLow`)},{value:`medium`,label:()=>l(`thinkingMedium`)},{value:`high`,label:()=>l(`thinkingHigh`)},{value:`xhigh`,label:()=>l(`thinkingXHigh`)}];function ge(e){return`${e.provider} / ${e.id}`}function _e(e,t){return!!(e&&t&&e.api===t.api&&e.provider===t.provider&&e.id===t.id)}function m(e){return String(e).padStart(2,`0`)}function h(e){if(!e)return`-`;let t=new Date(e);return Number.isNaN(t.getTime())?`-`:`${t.getFullYear()}-${m(t.getMonth()+1)}-${m(t.getDate())} ${m(t.getHours())}:${m(t.getMinutes())}`}function ve(e,t=20){let n=String(e||``).trim();return n.length>t?`${n.slice(0,t)}...`:n}function ye(){return{scheduleText:``,title:``,instruction:``,cronExpression:``,scheduleRule:``,nextRunAt:``,enabled:!0,agentId:``,executionMode:`serial`}}function g(){return{taskId:``,status:``,trigger:``,keyword:``,startedFrom:``,startedTo:``,page:1,pageSize:10}}function be(e){return{scheduleText:[e.scheduleRule,e.instruction].filter(Boolean).join(`
|
|
2
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 xe(e,t){return{...t,title:e.title,instruction:e.instruction,cronExpression:e.cronExpression??``,scheduleRule:e.scheduleRule,nextRunAt:e.nextRunAt,enabled:t.enabled}}function Se(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 _(e){return!!(e.currentRunId||e.currentRunIds?.length)}function Ce(e){return(e.executionMode??`serial`)===`parallel`||!_(e)}function we(e){return l(e===`parallel`?`taskExecutionModeParallel`:`taskExecutionModeSerial`)}function Te(e){return!!(e.title.trim()&&e.instruction.trim()&&e.cronExpression.trim())}function Ee(e){return l(e===`enabled`?`taskEnabled`:e===`running`?`taskRunning`:e===`paused`?`taskPaused`:e===`completed`?`taskFinished`:e===`success`?`executionSuccess`:`taskFailed`)}function De(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 v(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 y({onOpenSession:e}){let[o,s]=(0,f.useState)([]),[m,y]=(0,f.useState)(`tasks`),[b,x]=(0,f.useState)(()=>ye()),[S,Oe]=(0,f.useState)(null),[C,w]=(0,f.useState)(null),[T,E]=(0,f.useState)(null),[ke,D]=(0,f.useState)(!1),[O,k]=(0,f.useState)(null),[Ae,A]=(0,f.useState)(``),[j,M]=(0,f.useState)(!1),[N,P]=(0,f.useState)(``),[F,je]=(0,f.useState)([]),[I,L]=(0,f.useState)(),[R,z]=(0,f.useState)(`off`),[B,Me]=(0,f.useState)([]),[Ne,V]=(0,f.useState)(``),[H,U]=(0,f.useState)(()=>g()),[W,G]=(0,f.useState)(()=>g()),[K,Pe]=(0,f.useState)({runs:[],total:0,page:1,pageSize:10}),[Fe,Ie]=(0,f.useState)(!1),[Le,Re]=(0,f.useState)(null),[ze,Be]=(0,f.useState)([]),Ve=B[0]?.id??``;(0,f.useEffect)(()=>{if(!T)return;let e=()=>E(null);return window.addEventListener(`click`,e),window.addEventListener(`blur`,e),()=>{window.removeEventListener(`click`,e),window.removeEventListener(`blur`,e)}},[T]);async function He(){s((await v(`/api/scheduled-tasks`)).tasks)}async function q(e=W){Ie(!0),P(``);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),Pe(await v(`/api/scheduled-tasks/runs?${t.toString()}`))}catch(e){P(e instanceof Error?e.message:l(`requestFailed`))}finally{Ie(!1)}}(0,f.useEffect)(()=>{let e=!1;async function t(){try{let t=await v(`/api/project`);if(e)return;Me(t.projects??[])}catch{}}return t(),()=>{e=!0}},[]),(0,f.useEffect)(()=>{let e=!1;async function t(){try{let t=await le(),n=await ue(t),r=await fe(t),i=r.model??await me(t)??n[0];if(e)return;je(n),L(i),z(r.thinkingLevel??pe(i))}catch(t){e||P(t instanceof Error?t.message:l(`requestFailed`))}}return t(),()=>{e=!0}},[]),(0,f.useEffect)(()=>{let e=!1,t=async()=>{try{let t=await v(`/api/scheduled-tasks`);e||s(t.tasks)}catch(t){e||P(t instanceof Error?t.message:l(`requestFailed`))}};t();let n=window.setInterval(t,10*1e3);return()=>{e=!0,window.clearInterval(n)}},[]),(0,f.useEffect)(()=>{let e=!1;async function t(){try{let t=await v(`/api/agent-profiles`);if(e)return;Be(t.agents)}catch(t){e||P(t instanceof Error?t.message:l(`requestFailed`))}}return t(),()=>{e=!0}},[]);let Ue=(0,f.useMemo)(()=>o.find(e=>e.id===S),[S,o]),J=(0,f.useMemo)(()=>o.find(e=>e.id===C)??null,[C,o]),We=(0,f.useMemo)(()=>o.filter(e=>e.status===`enabled`).length,[o]),Ge=Math.max(1,Math.ceil(K.total/K.pageSize));function Y(e){return e?ze.find(t=>t.id===e||t.name===e)?.label??e:l(`defaultAgent`)}function X(e,t){x(n=>({...n,[e]:t}))}function Z(e,t){U(n=>({...n,[e]:t}))}function Ke(){Oe(null),V(Ve),x(ye()),k(null),A(``),P(``)}function qe(){Ke(),D(!0)}function Q(){j||(D(!1),Ke())}function Je(){let e={...H,page:1};U(e),G(e),q(e)}function Ye(){let e=g();U(e),G(e),q(e)}function Xe(e){let t=Math.min(Math.max(1,e),Ge),n={...W,page:t};U(n),G(n),q(n)}function Ze(e){let t={...W,page:1,pageSize:e};U(t),G(t),q(t)}async function Qe(){let e=b.scheduleText.trim();if(e){M(!0),P(``);try{let t=await v(`/api/scheduled-tasks/parse`,{method:`POST`,body:JSON.stringify({instruction:e,model:I,thinkingLevel:R})});if(t.needMoreInfo||!t.task){A(t.question||`请补充任务信息。`),k(null);return}let n=t.task;A(``),k(n),x(e=>xe(n,e))}catch(e){P(e instanceof Error?e.message:l(`requestFailed`))}finally{M(!1)}}}async function $e(){if(Te(b)){M(!0),P(``);try{let e=B.find(e=>e.id===Ne),t={task:Se(b),model:I,thinkingLevel:R,projectId:e?.id,projectName:e?.name};S?await v(`/api/scheduled-tasks/${encodeURIComponent(S)}`,{method:`PUT`,body:JSON.stringify(t)}):await v(`/api/scheduled-tasks`,{method:`POST`,body:JSON.stringify(t)}),Q(),await He(),m===`history`&&await q(W)}catch(e){P(e instanceof Error?e.message:l(`requestFailed`))}finally{M(!1)}}}function et(e){E(null),Oe(e.id),x(be(e)),k(null),A(``),P(``),V(e.projectId??``),e.model&&L(e.model),e.thinkingLevel&&z(e.thinkingLevel),D(!0)}async function $(e,t){if(P(``),E(null),!(t===`delete`&&!await de({description:l(`confirmDeleteTask`),confirmLabel:l(`confirmDelete`),cancelLabel:l(`cancel`),variant:`destructive`})))try{t===`delete`?(await v(`/api/scheduled-tasks/${encodeURIComponent(e)}`,{method:`DELETE`}),S===e&&Q(),C===e&&w(null)):await v(`/api/scheduled-tasks/${encodeURIComponent(e)}/${t}`,{method:`POST`}),await He(),m===`history`&&await q(W)}catch(e){P(e instanceof Error?e.message:l(`requestFailed`))}}function tt(t){return(0,p.jsxs)(`div`,{className:`mt-2 space-y-2 text-xs text-muted-foreground`,children:[t.sessionId?(0,p.jsx)(d,{variant:`outline`,size:`sm`,onClick:()=>e?.(t.sessionId),children:l(`viewConversation`)}):null,(0,p.jsxs)(`div`,{children:[l(`executionAgent`),t.agentLabel||Y(t.agentId)]}),t.warning?(0,p.jsx)(`div`,{className:`text-amber-600`,children:t.warning}):null,t.inputContent?(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`div`,{className:`font-medium text-foreground`,children:l(`runInputContent`)}),(0,p.jsx)(`pre`,{className:`mt-1 max-h-32 overflow-auto whitespace-pre-wrap`,children:t.inputContent})]}):null,t.aiResult||t.result?(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`div`,{className:`font-medium text-foreground`,children:l(`runAiResult`)}),(0,p.jsx)(`pre`,{className:`mt-1 max-h-48 overflow-auto whitespace-pre-wrap`,children:t.aiResult||t.result})]}):null,t.errorMessage?(0,p.jsx)(`div`,{className:`text-destructive`,children:t.errorMessage}):null,t.durationMs?(0,p.jsxs)(`div`,{children:[l(`runDuration`),t.durationMs,`ms`]}):null]})}return(0,p.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden bg-background`,children:[(0,p.jsxs)(`div`,{className:`border-b border-border px-6 py-5`,children:[(0,p.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,p.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,p.jsx)(`div`,{className:`flex size-10 items-center justify-center rounded-2xl bg-primary/10 text-primary`,children:(0,p.jsx)(ce,{className:`size-5`})}),(0,p.jsx)(`div`,{children:(0,p.jsxs)(`h1`,{className:`inline-flex items-center gap-1.5 text-lg font-semibold text-foreground`,children:[l(`scheduledTasks`),(0,p.jsx)(u,{label:l(`scheduledTasksDescription`)})]})})]}),(0,p.jsx)(d,{onClick:qe,children:l(`createTask`)})]}),(0,p.jsxs)(`div`,{className:`mt-4 flex flex-wrap gap-2`,children:[(0,p.jsxs)(`button`,{type:`button`,className:c(`rounded-full px-4 py-2 text-sm font-medium transition-colors`,m===`tasks`?`bg-primary text-primary-foreground`:`bg-muted text-muted-foreground hover:text-foreground`),onClick:()=>y(`tasks`),children:[l(`taskListTab`),` `,(0,p.jsx)(`span`,{className:`opacity-80`,children:o.length})]}),(0,p.jsx)(`button`,{type:`button`,className:c(`rounded-full px-4 py-2 text-sm font-medium transition-colors`,m===`history`?`bg-primary text-primary-foreground`:`bg-muted text-muted-foreground hover:text-foreground`),onClick:()=>{y(`history`),q(W)},children:l(`executionHistoryTab`)})]})]}),(0,p.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-6`,children:(0,p.jsxs)(`div`,{className:`mx-auto max-w-5xl space-y-5`,children:[N&&!ke?(0,p.jsx)(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive`,children:N}):null,m===`tasks`?(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(`div`,{className:`rounded-xl border border-border bg-card p-4`,children:(0,p.jsx)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`h2`,{className:`text-base font-semibold text-foreground`,children:l(`taskList`)}),(0,p.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:l(`tasksCount`,{total:o.length,enabled:We})})]})})}),(0,p.jsx)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:o.length===0?(0,p.jsx)(`div`,{className:`rounded-lg px-3 py-3 text-center text-xs text-muted-foreground/55 md:col-span-2`,children:l(`noScheduledTasks`)}):o.map(e=>{let n=e.status===`enabled`,ee=e.status===`completed`,a=_(e);return(0,p.jsxs)(`div`,{className:`relative cursor-pointer rounded-xl border border-border bg-card p-4 transition-colors hover:bg-muted/15`,onClick:()=>w(e.id),children:[(0,p.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,p.jsxs)(`div`,{className:`min-w-0`,children:[(0,p.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,p.jsx)(`h3`,{className:`truncate text-sm font-medium text-foreground/90`,children:e.title})}),(0,p.jsx)(`p`,{className:`mt-2 text-sm text-muted-foreground`,children:ve(e.instruction,20)})]}),(0,p.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,onClick:e=>e.stopPropagation(),children:[(0,p.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":n,disabled:ee,className:c(`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`?l(`enable`):l(`pauseTask`),children:(0,p.jsx)(`span`,{className:c(`absolute left-0.5 top-0.5 size-5 rounded-full bg-white shadow transition-transform`,n?`translate-x-5`:`translate-x-0`)})}),(0,p.jsxs)(`div`,{className:`relative`,children:[(0,p.jsx)(d,{variant:`ghost`,size:`icon`,onClick:()=>E(T===e.id?null:e.id),title:l(`moreActions`),children:(0,p.jsx)(ae,{className:`size-4`})}),T===e.id?(0,p.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,p.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:!Ce(e),onClick:()=>void $(e.id,`run`),children:[(0,p.jsx)(ie,{className:`size-3.5`}),l(`executeNow`)]}),(0,p.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:a,onClick:()=>et(e),children:[(0,p.jsx)(r,{className:`size-3.5`}),l(`editTask`)]}),(0,p.jsxs)(`button`,{className:`flex w-full items-center gap-2 px-3 py-2 text-left hover:bg-muted`,onClick:()=>{E(null),w(e.id)},children:[(0,p.jsx)(t,{className:`size-3.5`}),l(`viewDetails`)]}),(0,p.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:a,onClick:()=>void $(e.id,`delete`),children:[(0,p.jsx)(i,{className:`size-3.5`}),l(`deleteTask`)]})]}):null]})]})]}),(0,p.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-x-4 gap-y-1 text-xs text-muted-foreground`,children:[(0,p.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,p.jsx)(te,{className:`size-3`}),e.scheduleRule]}),(0,p.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,p.jsx)(se,{className:`size-3`}),Y(e.agentId)]}),(0,p.jsxs)(`span`,{children:[l(`taskExecutionMode`),`:`,we(e.executionMode)]}),e.projectName?(0,p.jsxs)(`span`,{children:[l(`taskProject`),e.projectName]}):null]}),(0,p.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,p.jsxs)(`span`,{children:[l(`lastExecution`),h(e.lastRunAt)]}),(0,p.jsxs)(`span`,{children:[l(`nextExecution`),h(e.nextRunAt)]})]})]},e.id)})})]}):(0,p.jsxs)(`div`,{className:`space-y-4`,children:[(0,p.jsxs)(`div`,{className:`rounded-xl border border-border bg-card p-4`,children:[(0,p.jsxs)(`div`,{className:`mb-3 flex items-center gap-2 text-sm font-medium text-foreground`,children:[(0,p.jsx)(ne,{className:`size-4`}),l(`historyFilters`)]}),(0,p.jsxs)(`div`,{className:`grid gap-3 md:grid-cols-3`,children:[(0,p.jsxs)(`label`,{className:`block text-xs font-medium text-muted-foreground`,children:[l(`taskName`),(0,p.jsxs)(`select`,{className:`mt-1 h-9 w-full rounded-md border border-input bg-background px-2 text-sm text-foreground`,value:H.taskId,onChange:e=>Z(`taskId`,e.target.value),children:[(0,p.jsx)(`option`,{value:``,children:l(`allTasks`)}),o.map(e=>(0,p.jsx)(`option`,{value:e.id,children:e.title},e.id))]})]}),(0,p.jsxs)(`label`,{className:`block text-xs font-medium text-muted-foreground`,children:[l(`status`),(0,p.jsxs)(`select`,{className:`mt-1 h-9 w-full rounded-md border border-input bg-background px-2 text-sm text-foreground`,value:H.status,onChange:e=>Z(`status`,e.target.value),children:[(0,p.jsx)(`option`,{value:``,children:l(`allStatuses`)}),(0,p.jsx)(`option`,{value:`running`,children:l(`executionRunning`)}),(0,p.jsx)(`option`,{value:`success`,children:l(`executionSuccess`)}),(0,p.jsx)(`option`,{value:`failed`,children:l(`taskFailed`)})]})]}),(0,p.jsxs)(`label`,{className:`block text-xs font-medium text-muted-foreground`,children:[l(`triggerType`),(0,p.jsxs)(`select`,{className:`mt-1 h-9 w-full rounded-md border border-input bg-background px-2 text-sm text-foreground`,value:H.trigger,onChange:e=>Z(`trigger`,e.target.value),children:[(0,p.jsx)(`option`,{value:``,children:l(`allTriggers`)}),(0,p.jsx)(`option`,{value:`schedule`,children:l(`autoRun`)}),(0,p.jsx)(`option`,{value:`manual`,children:l(`manualRun`)})]})]}),(0,p.jsxs)(`label`,{className:`block text-xs font-medium text-muted-foreground`,children:[l(`startTime`),(0,p.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:H.startedFrom,onChange:e=>Z(`startedFrom`,e.target.value)})]}),(0,p.jsxs)(`label`,{className:`block text-xs font-medium text-muted-foreground`,children:[l(`endTime`),(0,p.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:H.startedTo,onChange:e=>Z(`startedTo`,e.target.value)})]}),(0,p.jsxs)(`label`,{className:`block text-xs font-medium text-muted-foreground`,children:[l(`keyword`),(0,p.jsx)(`input`,{className:`mt-1 h-9 w-full rounded-md border border-input bg-background px-2 text-sm text-foreground`,value:H.keyword,onChange:e=>Z(`keyword`,e.target.value),placeholder:l(`keywordPlaceholder`)})]})]}),(0,p.jsxs)(`div`,{className:`mt-3 flex justify-end gap-2`,children:[(0,p.jsx)(d,{variant:`outline`,onClick:Ye,children:l(`reset`)}),(0,p.jsx)(d,{onClick:Je,children:l(`query`)})]})]}),(0,p.jsxs)(`div`,{className:`overflow-hidden rounded-xl border border-border bg-card`,children:[(0,p.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,p.jsx)(`span`,{children:l(`taskName`)}),(0,p.jsx)(`span`,{children:l(`status`)}),(0,p.jsx)(`span`,{children:l(`triggerType`)}),(0,p.jsx)(`span`,{children:l(`startTime`)}),(0,p.jsx)(`span`,{children:l(`runDuration`)})]}),Fe?(0,p.jsx)(`div`,{className:`p-8 text-center text-sm text-muted-foreground`,children:l(`loading`)}):K.runs.length===0?(0,p.jsx)(`div`,{className:`p-8 text-center text-sm text-muted-foreground`,children:l(`noExecutionHistory`)}):K.runs.map(e=>(0,p.jsxs)(`div`,{className:`border-b border-border last:border-b-0`,children:[(0,p.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:()=>Re(Le===e.id?null:e.id),children:[(0,p.jsx)(`span`,{className:`min-w-0 truncate text-foreground`,children:e.taskTitle}),(0,p.jsx)(`span`,{children:(0,p.jsx)(`span`,{className:c(`rounded-full px-2 py-0.5 text-xs`,De(e.status)),children:Ee(e.status)})}),(0,p.jsx)(`span`,{className:`text-muted-foreground`,children:e.trigger===`manual`?l(`manualRun`):l(`autoRun`)}),(0,p.jsx)(`span`,{className:`text-muted-foreground`,children:h(e.startedAt)}),(0,p.jsx)(`span`,{className:`text-muted-foreground`,children:e.durationMs?`${e.durationMs}ms`:`-`})]}),Le===e.id?(0,p.jsx)(`div`,{className:`border-t border-border bg-muted/20 px-4 py-3`,children:tt(e)}):null]},`${e.taskId}:${e.id}`)),(0,p.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 px-4 py-3 text-sm text-muted-foreground`,children:[(0,p.jsx)(`span`,{children:l(`paginationSummary`,{page:K.page,pages:Ge,total:K.total})}),(0,p.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,p.jsx)(`select`,{className:`h-8 rounded-md border border-input bg-background px-2 text-sm`,value:K.pageSize,onChange:e=>Ze(Number(e.target.value)),children:[10,20,50,100].map(e=>(0,p.jsx)(`option`,{value:e,children:l(`pageSize`,{size:e})},e))}),(0,p.jsx)(d,{variant:`outline`,size:`sm`,disabled:K.page<=1,onClick:()=>Xe(K.page-1),children:l(`previousPage`)}),(0,p.jsx)(d,{variant:`outline`,size:`sm`,disabled:K.page>=Ge,onClick:()=>Xe(K.page+1),children:l(`nextPage`)})]})]})]})]})]})}),J?(0,p.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4`,onMouseDown:e=>{e.target===e.currentTarget&&w(null)},children:(0,p.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,p.jsxs)(`div`,{className:`flex shrink-0 items-start justify-between gap-3 border-b border-border px-5 py-4`,children:[(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`div`,{className:`flex flex-wrap items-center gap-2`,children:(0,p.jsx)(`h2`,{className:`text-base font-semibold text-foreground`,children:J.title})}),(0,p.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:J.scheduleRule})]}),(0,p.jsx)(d,{variant:`ghost`,size:`icon`,onClick:()=>w(null),children:(0,p.jsx)(re,{className:`size-4`})})]}),(0,p.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-5 py-4`,children:(0,p.jsxs)(`div`,{className:`space-y-4 text-sm`,children:[(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`div`,{className:`mb-1 font-medium text-foreground`,children:l(`taskContent`)}),(0,p.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:J.instruction})]}),(0,p.jsxs)(`div`,{className:`grid gap-3 text-muted-foreground sm:grid-cols-2`,children:[(0,p.jsxs)(`div`,{children:[l(`executionRule`),(0,p.jsx)(`span`,{className:`text-foreground`,children:J.scheduleRule})]}),(0,p.jsxs)(`div`,{children:[l(`taskExecutionMode`),`:`,(0,p.jsx)(`span`,{className:`text-foreground`,children:we(J.executionMode)})]}),(0,p.jsxs)(`div`,{children:[`cron:`,(0,p.jsx)(`span`,{className:`font-mono text-foreground`,children:J.cronExpression??`-`})]}),(0,p.jsxs)(`div`,{children:[l(`lastExecution`),(0,p.jsx)(`span`,{className:`text-foreground`,children:h(J.lastRunAt)})]}),(0,p.jsxs)(`div`,{children:[l(`nextExecution`),(0,p.jsx)(`span`,{className:`text-foreground`,children:h(J.nextRunAt)})]}),(0,p.jsxs)(`div`,{children:[l(`executionAgent`),(0,p.jsx)(`span`,{className:`text-foreground`,children:Y(J.agentId)})]}),J.projectName?(0,p.jsxs)(`div`,{children:[l(`taskProject`),(0,p.jsx)(`span`,{className:`text-foreground`,children:J.projectName})]}):null,J.model?(0,p.jsxs)(`div`,{children:[l(`taskModel`),`:`,(0,p.jsx)(`span`,{className:`text-foreground`,children:ge(J.model)})]}):null,J.thinkingLevel?(0,p.jsxs)(`div`,{children:[l(`taskThinkingLevel`),(0,p.jsx)(`span`,{className:`text-foreground`,children:he.find(e=>e.value===J.thinkingLevel)?.label()??J.thinkingLevel})]}):null,(0,p.jsxs)(`div`,{children:[l(`createdAt`),`:`,(0,p.jsx)(`span`,{className:`text-foreground`,children:h(J.createdAt)})]})]}),J.runs?.length>0?(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`div`,{className:`mb-2 font-medium text-foreground`,children:l(`recentExecutions`)}),(0,p.jsx)(`div`,{className:`space-y-2`,children:J.runs.slice(0,5).map(e=>(0,p.jsxs)(`details`,{className:`rounded-lg border border-border bg-muted/20 p-2 text-xs text-muted-foreground`,children:[(0,p.jsxs)(`summary`,{className:`cursor-pointer text-foreground`,children:[h(e.startedAt),` · `,e.trigger===`manual`?l(`manualRun`):l(`autoRun`),` · `,Ee(e.status)]}),tt(e)]},e.id))})]}):null]})}),(0,p.jsx)(`div`,{className:`shrink-0 border-t border-border px-5 py-4`,children:(0,p.jsxs)(`div`,{className:`flex flex-wrap justify-end gap-2`,children:[J.lastSessionId?(0,p.jsx)(d,{variant:`outline`,onClick:()=>e?.(J.lastSessionId),children:l(`viewConversation`)}):null,(0,p.jsxs)(d,{variant:`outline`,disabled:!Ce(J),onClick:()=>void $(J.id,`run`),children:[(0,p.jsx)(ie,{className:`mr-1 size-3.5`}),l(`executeNow`)]}),(0,p.jsxs)(d,{variant:`outline`,disabled:_(J),onClick:()=>et(J),children:[(0,p.jsx)(r,{className:`mr-1 size-3.5`}),l(`editTask`)]}),(0,p.jsxs)(d,{variant:`destructive`,disabled:_(J),onClick:()=>void $(J.id,`delete`),children:[(0,p.jsx)(i,{className:`mr-1 size-3.5`}),l(`deleteTask`)]})]})})]})}):null,ke?(0,p.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,p.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,p.jsx)(`div`,{className:`shrink-0 border-b border-border px-5 py-4`,children:(0,p.jsxs)(`h2`,{className:`inline-flex items-center gap-1.5 text-base font-semibold text-foreground`,children:[l(Ue?`editTask`:`createTask`),(0,p.jsx)(u,{label:l(`quickAiParseTask`)})]})}),(0,p.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-5 py-4`,children:(0,p.jsxs)(`div`,{className:`space-y-4`,children:[(0,p.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[l(`taskScheduleDescriptionLabel`),(0,p.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:b.scheduleText,onChange:e=>X(`scheduleText`,e.target.value),placeholder:l(`taskScheduleDescriptionPlaceholder`)})]}),(0,p.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,p.jsxs)(d,{onClick:Qe,disabled:j||!I||!b.scheduleText.trim(),children:[(0,p.jsx)(a,{className:`mr-1 size-3.5`}),l(`aiParseTask`)]}),Ae?(0,p.jsx)(`span`,{className:`text-sm text-amber-600`,children:Ae}):null]}),(0,p.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,p.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[l(`taskTitleLabel`),(0,p.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:b.title,onChange:e=>X(`title`,e.target.value),placeholder:l(`taskTitlePlaceholder`)})]}),(0,p.jsxs)(`div`,{className:`block text-sm font-medium text-foreground`,children:[l(`executionRule`),(0,p.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:b.scheduleRule||`-`})]}),(0,p.jsxs)(`div`,{className:`block text-sm font-medium text-foreground`,children:[`cron`,(0,p.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:b.cronExpression||`-`})]}),(0,p.jsxs)(`div`,{className:`block text-sm font-medium text-foreground`,children:[l(`nextExecutionTime`),(0,p.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:h(b.nextRunAt)})]}),(0,p.jsxs)(`label`,{className:`block text-sm font-medium text-foreground sm:col-span-2`,children:[(0,p.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[l(`taskExecutionMode`),(0,p.jsx)(u,{label:l(`taskExecutionModeHelp`)})]}),(0,p.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:b.executionMode,onChange:e=>X(`executionMode`,e.target.value),children:[(0,p.jsx)(`option`,{value:`serial`,children:l(`taskExecutionModeSerial`)}),(0,p.jsx)(`option`,{value:`parallel`,children:l(`taskExecutionModeParallel`)})]})]}),(0,p.jsxs)(`label`,{className:`block text-sm font-medium text-foreground sm:col-span-2`,children:[l(`promptContentLabel`),(0,p.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:b.instruction,onChange:e=>X(`instruction`,e.target.value),placeholder:l(`promptContentPlaceholder`)})]})]}),(0,p.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-foreground`,children:[(0,p.jsx)(`input`,{type:`checkbox`,checked:b.enabled,onChange:e=>X(`enabled`,e.target.checked)}),l(`taskEnabledSwitch`)]}),(0,p.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 rounded-xl border border-border bg-muted/20 px-2 py-2`,children:[(0,p.jsxs)(`span`,{className:`relative inline-flex items-center`,children:[(0,p.jsx)(a,{className:`pointer-events-none absolute left-2 size-3.5 text-muted-foreground/70`}),(0,p.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:I?`${I.provider}\u0000${I.id}`:``,onChange:e=>{let t=F.find(t=>`${t.provider}\u0000${t.id}`===e.target.value);L(t),z(pe(t))},title:l(`taskModel`),children:[F.length===0?(0,p.jsx)(`option`,{value:``,children:l(`noModelAvailable`)}):null,F.map(e=>(0,p.jsxs)(`option`,{value:`${e.provider}\u0000${e.id}`,children:[ge(e),_e(e,I)?` ✓`:``]},`${e.provider}:${e.id}`))]})]}),(0,p.jsxs)(`span`,{className:`relative inline-flex items-center`,children:[(0,p.jsx)(ee,{className:`pointer-events-none absolute left-2 size-3.5 text-muted-foreground/70`}),(0,p.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:R,onChange:e=>z(e.target.value),title:l(`taskThinking`),children:he.map(e=>(0,p.jsx)(`option`,{value:e.value,children:e.label()},e.value))})]}),(0,p.jsxs)(`span`,{className:`relative inline-flex items-center`,children:[(0,p.jsx)(n,{className:`pointer-events-none absolute left-2 size-3.5 text-muted-foreground/70`}),(0,p.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:Ne,onChange:e=>V(e.target.value),title:l(`taskProjectLabel`),children:[(0,p.jsx)(`option`,{value:``,children:l(`noProjectBound`)}),B.map(e=>(0,p.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,p.jsxs)(`span`,{className:`relative inline-flex items-center`,children:[(0,p.jsx)(se,{className:`pointer-events-none absolute left-2 size-3.5 text-muted-foreground/70`}),(0,p.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:b.agentId,onChange:e=>X(`agentId`,e.target.value),title:l(`executionAgent`),children:[(0,p.jsx)(`option`,{value:``,children:l(`defaultAgent`)}),ze.map(e=>(0,p.jsx)(`option`,{value:e.id,children:e.label},e.id))]})]})]}),O?(0,p.jsxs)(`div`,{className:`rounded-xl border border-border bg-muted/30 p-3 text-sm`,children:[(0,p.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 font-medium text-foreground`,children:[(0,p.jsx)(oe,{className:`size-4 text-emerald-600`}),l(`aiParsed`)]}),(0,p.jsxs)(`div`,{className:`grid gap-2 text-muted-foreground sm:grid-cols-2`,children:[(0,p.jsxs)(`div`,{children:[l(`taskName`),(0,p.jsx)(`span`,{className:`text-foreground`,children:O.title})]}),(0,p.jsxs)(`div`,{children:[l(`executionRule`),(0,p.jsx)(`span`,{className:`text-foreground`,children:O.scheduleRule})]}),(0,p.jsxs)(`div`,{children:[`cron:`,(0,p.jsx)(`span`,{className:`font-mono text-foreground`,children:O.cronExpression??`-`})]}),(0,p.jsxs)(`div`,{children:[l(`nextExecutionTime`),(0,p.jsx)(`span`,{className:`text-foreground`,children:h(O.nextRunAt)})]}),(0,p.jsxs)(`div`,{className:`sm:col-span-2`,children:[l(`aiInstruction`),(0,p.jsx)(`span`,{className:`text-foreground`,children:O.instruction})]})]})]}):null,N?(0,p.jsx)(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive`,children:N}):null]})}),(0,p.jsx)(`div`,{className:`shrink-0 border-t border-border px-5 py-4`,children:(0,p.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,p.jsx)(d,{variant:`outline`,onClick:Q,disabled:j,children:l(`cancel`)}),(0,p.jsx)(d,{onClick:$e,disabled:j||!I||!Te(b),children:l(Ue?`saveTask`:`confirmCreate`)})]})})]})}):null]})}export{y as ScheduledTasksPage};
|
package/dist/assets/{SharedConversationPage-CxbAx1fN.js → SharedConversationPage-CHE9qABz.js}
RENAMED
|
@@ -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-BzOV50wA.js";import{ChatPanelHost as k}from"./ChatPanelHost-BUZ6scv9.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{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-Bt_dRvdG.js";import{ChatPanelHost as k}from"./ChatPanelHost-BTqhhkWK.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,2 +1,2 @@
|
|
|
1
|
-
import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{F as t,P as n,_t as r,b as i,k as a,n as o,s,wt as c}from"./icons-DzxBk7tb.js";import{n as l}from"./react-vendor-DsAeMFcm.js";import{F as u,I as d,P as f}from"./index-
|
|
1
|
+
import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{F as t,P as n,_t as r,b as i,k as a,n as o,s,wt as c}from"./icons-DzxBk7tb.js";import{n as l}from"./react-vendor-DsAeMFcm.js";import{F as u,I as d,P as f}from"./index-Bt_dRvdG.js";import{n as p,t as m}from"./xterm-5XDrJ343.js";var h=e(c(),1);async function g(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 _(){return g(`/api/terminal/capabilities`)}function v(e){return g(`/api/terminal/sessions${e?`?projectId=${encodeURIComponent(e)}`:``}`)}function y(e){return g(`/api/terminal/sessions`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(e)})}function b(e){return g(`/api/terminal/sessions/${encodeURIComponent(e)}`,{method:`DELETE`})}function x(e,t){return g(`/api/terminal/sessions/${encodeURIComponent(e)}/input`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({data:t})})}function S(){return``}function C(){let e=S();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 w=l();function ee({session:e,active:t,height:n,onReady:r,onExited:i,onConnectionError:a}){let o=(0,h.useRef)(null),s=(0,h.useRef)(null),c=(0,h.useRef)(null),l=(0,h.useRef)(null),u=(0,h.useRef)(null),f=(0,h.useRef)(null);return(0,h.useEffect)(()=>{let t=o.current;if(!t)return;let n=!1,h=!1,g=!1,_=!1,v=t=>{n||g||_||(_=!0,a(e.id,t))},y=new p({cursorBlink:!0,convertEol:!1,fontFamily:`ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace`,fontSize:12,lineHeight:1.2,scrollback:5e3,theme:{background:`#ffffff`,foreground:`#1f2937`,cursor:`#1f2937`,selectionBackground:`#dbeafe`}}),b=new m;y.loadAddon(b),y.open(t),y.writeln(`\x1b[2mConnected to ${e.cwd}\x1b[0m`),s.current=y,c.current=b;let x=()=>{if(t.isConnected)try{b.fit();let{cols:e,rows:t}=y,n=l.current;n?.readyState===WebSocket.OPEN&&n.send(JSON.stringify({type:`resize`,cols:e,rows:t}))}catch{}},S=new WebSocket(`${C()}/api/terminal/sessions/${encodeURIComponent(e.id)}/ws`);l.current=S,S.addEventListener(`open`,()=>{h=!0,_=!1,a(e.id,void 0),u.current=y.onData(e=>{S.readyState===WebSocket.OPEN&&S.send(JSON.stringify({type:`input`,data:e}))}),window.setTimeout(x,0)}),S.addEventListener(`message`,t=>{try{let n=JSON.parse(String(t.data));n.type===`ready`?r(e.id):n.type===`output`?y.write(n.data):n.type===`exit`?(g=!0,y.writeln(``),y.writeln(`\x1b[33m[process exited with code ${n.exitCode??`unknown`}]\x1b[0m`),i(e.id)):n.type===`error`&&y.writeln(`\x1b[31m${n.message}\x1b[0m`)}catch{}}),S.addEventListener(`error`,()=>{v(d(h?`terminalConnectionClosedUnexpectedly`:`terminalConnectionFailed`))}),S.addEventListener(`close`,e=>{u.current?.dispose(),u.current=null,!(n||g)&&(!e.wasClean||e.code!==1e3)&&v(d(h?`terminalConnectionClosedUnexpectedly`:`terminalConnectionFailed`))});let w=new ResizeObserver(()=>x());return w.observe(t),f.current=w,window.setTimeout(x,50),()=>{n=!0,w.disconnect(),f.current=null,u.current?.dispose(),u.current=null,S.close(),l.current=null,y.dispose(),s.current=null,c.current=null}},[a,i,r,e.cwd,e.id]),(0,h.useEffect)(()=>{if(!t)return;let e=c.current,n=s.current;window.setTimeout(()=>{try{e?.fit(),n?.focus()}catch{}},0)},[t,n]),(0,w.jsx)(`div`,{ref:o,className:t?`h-full min-h-0 w-full`:`hidden`,"aria-hidden":!t})}var T=180,te=.7,ne=320;function E(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 D(e,t){let n=e?.terminalShellProfiles||[],r=t||e?.defaultTerminalShellProfileId||``;return n.find(e=>e.id===r)||n[0]}function O({project:e,onCollapse:c,pendingCommand:l,onPendingCommandHandled:p}){let[m,g]=(0,h.useState)(null),[S,C]=(0,h.useState)([]),[O,k]=(0,h.useState)(),[A,re]=(0,h.useState)(ne),[j,ie]=(0,h.useState)(!0),[M,N]=(0,h.useState)(!1),[ae,P]=(0,h.useState)(),[oe,F]=(0,h.useState)({}),[I,L]=(0,h.useState)(!1),[R,se]=(0,h.useState)(!1),z=(0,h.useRef)(!1),B=(0,h.useRef)(new Set),V=(0,h.useRef)(l),H=(0,h.useRef)(new Set),U=(0,h.useRef)(new Set),W=(0,h.useRef)(new Map),G=(0,h.useRef)(!0),[K,q]=(0,h.useState)(()=>new Set),J=(0,h.useRef)(null),ce=(0,h.useRef)(null),Y=e?.id,X=(0,h.useMemo)(()=>S.find(e=>e.id===O)??S[0],[O,S]);(0,h.useEffect)(()=>{V.current=l},[l]),(0,h.useEffect)(()=>()=>{G.current=!1},[]);let le=(0,h.useCallback)(async()=>{let e=await v(Y);return C(e.sessions),k(t=>t&&e.sessions.some(e=>e.id===t)?t:e.sessions[0]?.id),e.sessions},[Y]),ue=(0,h.useCallback)(async(e,t)=>{if(z.current)return;let n=D(m,t);z.current=!0,N(!0),P(void 0),F({});try{let t=await y({projectId:Y,name:E(e,n),cols:120,rows:30,shellProfileId:n?.id,shellProfileName:n?.name});C(e=>[...e,t]),k(t.id)}catch(e){P(e instanceof Error?e.message:d(`terminalCreateFailed`))}finally{z.current=!1,N(!1)}},[m,Y]);(0,h.useEffect)(()=>{let e=!1;return(async()=>{ie(!0),P(void 0);try{let[t,n]=await Promise.all([_(),v(Y)]);if(e)return;if(g(t),C(n.sessions),k(n.sessions[0]?.id),t.enabled&&n.sessions.length===0&&!V.current){let n=D(t);y({projectId:Y,name:E([],n),cols:120,rows:30,shellProfileId:n?.id,shellProfileName:n?.name}).then(t=>{if(e){b(t.id).catch(()=>{});return}C([t]),k(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||ie(!1)}})(),()=>{e=!0}},[Y]),(0,h.useEffect)(()=>{if(!I)return;let e=e=>{ce.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,h.useEffect)(()=>{if(!R)return;let e=e=>{e.key===`Escape`&&se(!1)};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[R]),(0,h.useEffect)(()=>{if(!l||B.current.has(l.id)||W.current.has(l.id)||H.current.has(l.id)||j||M||!m)return;if(!m.enabled){B.current.add(l.id),window.setTimeout(()=>{P(m.reason||d(`terminalUnavailable`)),p?.(l.id)},0);return}let e=X&&!X.exited?X:S.find(e=>!e.exited);if(e){W.current.set(l.id,e.id),window.setTimeout(()=>{G.current&&k(e.id)},0);return}H.current.add(l.id),window.setTimeout(()=>{G.current&&P(void 0)},0);let t=D(m);y({projectId:Y,name:E(S,t),cols:120,rows:30,shellProfileId:t?.id,shellProfileName:t?.name}).then(e=>{if(!G.current){b(e.id).catch(()=>{});return}W.current.set(l.id,e.id),C(t=>t.some(t=>t.id===e.id)?t:[...t,e]),k(e.id)}).catch(e=>{G.current&&(P(e instanceof Error?e.message:d(`terminalCommandExecuteFailed`)),B.current.add(l.id),p?.(l.id))}).finally(()=>{H.current.delete(l.id)})},[X,m,M,j,p,l,Y,S]),(0,h.useEffect)(()=>{if(!l||B.current.has(l.id)||U.current.has(l.id))return;let e=W.current.get(l.id),t=e?S.find(t=>t.id===e):X&&!X.exited?X:S.find(e=>!e.exited);!t||t.exited||!K.has(t.id)||(U.current.add(l.id),window.setTimeout(()=>{G.current&&(k(t.id),P(void 0))},0),(async()=>{try{if(l.execute){let e=l.command.split(`
|
|
2
2
|
`),n=e.flatMap((t,n)=>n<e.length-1?[t,`\r`]:[t]);n.push(`\r`),await x(t.id,n.join(``))}else await x(t.id,l.command)}catch(e){G.current&&P(e instanceof Error?e.message:d(`terminalCommandExecuteFailed`))}finally{B.current.add(l.id),U.current.delete(l.id),W.current.delete(l.id),G.current&&p?.(l.id)}})())},[X,p,l,K,S]);let de=async e=>{P(void 0),F(t=>{if(!t[e])return t;let n={...t};return delete n[e],n});let t=S.filter(t=>t.id!==e);C(t),O===e&&k(t[0]?.id);try{await b(e)}catch(e){P(e instanceof Error?e.message:d(`terminalCloseFailed`)),le().catch(()=>{})}},fe=(0,h.useCallback)(e=>{C(t=>t.map(t=>t.id===e?{...t,exited:!0}:t)),q(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),n})},[]),pe=(0,h.useCallback)(e=>{q(t=>{if(t.has(e))return t;let n=new Set(t);return n.add(e),n})},[]),me=(0,h.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}})},[]),he=e=>{J.current={startY:e.clientY,startHeight:A},e.currentTarget.setPointerCapture(e.pointerId)},ge=e=>{let t=J.current;if(!t)return;let n=Math.max(T,Math.floor(window.innerHeight*te));re(Math.min(n,Math.max(T,t.startHeight+t.startY-e.clientY)))},_e=e=>{J.current=null;try{e.currentTarget.releasePointerCapture(e.pointerId)}catch{}},Z=m?.terminalShellProfiles||[],ve=m?.defaultTerminalShellProfileId||``,Q=Z.find(e=>e.id===ve)||Z[0],ye=!!(m&&S.length>=m.maxSessions),be=M||ye,xe=X?oe[X.id]:void 0,$=ae??xe,Se=R?$?`calc(100% - 4.25rem)`:`calc(100% - 2.25rem)`:$?A-72:A-45;return(0,w.jsxs)(`div`,{className:u(`shrink-0 border-t border-border bg-background`,R&&`absolute inset-0 z-30 flex flex-col border-t-0`),style:R?void 0:{height:A},children:[R?null:(0,w.jsx)(`div`,{className:`h-1 cursor-row-resize bg-transparent hover:bg-border`,onPointerDown:he,onPointerMove:ge,onPointerUp:_e,onPointerCancel:_e}),(0,w.jsxs)(`div`,{className:`flex h-9 items-center gap-1 border-b border-border px-2`,children:[(0,w.jsx)(s,{className:`size-4 shrink-0 text-muted-foreground/60`}),(0,w.jsx)(`div`,{className:`flex min-w-0 flex-1 items-center gap-1 overflow-x-auto`,children:S.map(e=>(0,w.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`,X?.id===e.id&&`bg-muted/28 text-foreground/90`),onClick:()=>k(e.id),title:`${e.name} — ${e.cwd}`,children:[(0,w.jsx)(`span`,{className:u(`size-1.5 rounded-full`,e.exited?`bg-muted-foreground/40`:`bg-emerald-500/80`)}),(0,w.jsx)(`span`,{className:`truncate`,children:e.name}),(0,w.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(),de(e.id)},onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),t.stopPropagation(),de(e.id))},"aria-label":d(`terminalCloseSession`,{name:e.name}),children:(0,w.jsx)(o,{className:`size-3`})})]},e.id))}),(0,w.jsxs)(`div`,{className:`relative shrink-0`,ref:ce,children:[(0,w.jsxs)(`div`,{className:`flex items-center overflow-hidden rounded-md border border-border bg-background`,children:[(0,w.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 ue(S),disabled:be,title:Q?d(`terminalNewWithProfile`,{name:Q.name}):d(`terminalNew`),"aria-label":d(`terminalNew`),children:M?(0,w.jsx)(t,{className:`size-3.5 animate-spin`}):(0,w.jsx)(i,{className:`size-3.5`})}),Z.length>0?(0,w.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,w.jsx)(r,{className:`size-3.5`})}):null]}),I?(0,w.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,w.jsx)(`div`,{className:`px-2 pb-1.5 pt-1 text-[11px] font-medium uppercase tracking-wide text-muted-foreground/60`,children:d(`terminalNewWith`)}),Z.map(e=>(0,w.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),ue(S,e.id)},children:[(0,w.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,w.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,w.jsx)(`span`,{className:`block truncate font-medium`,children:e.name}),(0,w.jsx)(`span`,{className:`block truncate font-mono text-[11px] text-muted-foreground/55`,children:e.command})]})]},e.id))]}):null]}),(0,w.jsx)(f,{variant:`ghost`,size:`icon`,className:`size-7`,onClick:()=>se(e=>!e),title:d(R?`terminalExitFullscreen`:`terminalFullscreen`),"aria-label":d(R?`terminalExitFullscreen`:`terminalFullscreen`),children:R?(0,w.jsx)(a,{className:`size-3.5`}):(0,w.jsx)(n,{className:`size-3.5`})}),(0,w.jsx)(f,{variant:`ghost`,size:`icon`,className:`size-7`,onClick:c,title:d(`terminalCollapse`),"aria-label":d(`terminalCollapse`),children:(0,w.jsx)(r,{className:`size-3.5`})})]}),$?(0,w.jsx)(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-destructive`,children:$}):null,(0,w.jsx)(`div`,{className:`min-h-0 bg-background`,style:{height:Se},children:j?(0,w.jsxs)(`div`,{className:`flex h-full items-center justify-center gap-2 text-xs text-muted-foreground/60`,children:[(0,w.jsx)(t,{className:`size-4 animate-spin`}),` `,d(`terminalStarting`)]}):m&&!m.enabled?(0,w.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`)}):S.length===0?(0,w.jsx)(`div`,{className:`flex h-full items-center justify-center text-xs text-muted-foreground/60`,children:d(`terminalNoSessions`)}):S.map(e=>(0,w.jsx)(ee,{session:e,active:e.id===X?.id,height:R?window.innerHeight-36:A,onReady:pe,onExited:fe,onConnectionError:me},e.id))})]})}export{O as TerminalDock};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{$ as t,A as n,B as r,G as i,H as a,I as o,J as s,K as c,L as l,P as u,Q as d,R as f,St as p,U as m,W as h,X as g,Y as _,Z as v,_t as ee,at as y,et as te,g as b,h as ne,ht as re,it as ie,k as ae,n as oe,nt as x,o as se,ot as S,pt as ce,q as C,rt as w,v as T,vt as E,wt as le}from"./icons-DzxBk7tb.js";import{n as D}from"./react-vendor-DsAeMFcm.js";import{F as O,I as k,P as A,a as ue,c as de,i as fe,l as pe,n as me,o as he,r as ge,s as _e,t as j,u as ve}from"./index-BzOV50wA.js";import{i as ye,n as M,r as be,t as xe}from"./diff-line-counts-DHyWKEXk.js";var N=e(le(),1),P=D();function F(e){let t=e.trim();if(!t.startsWith(`/api/workspace/preview/`))return!1;try{let e=new URL(t,window.location.origin);return e.origin===window.location.origin&&e.pathname.startsWith(`/api/workspace/preview/`)}catch{return!1}}function I(e){let t=e.trim().replace(/\\/g,`/`);return t.startsWith(`/`)||/^[a-zA-Z]:\//.test(t)}function L(e,t){let n=e.trim();if(!t||!F(n))return n;try{let e=new URL(n,window.location.origin),r=`/api/workspace/preview/${encodeURIComponent(t)}/`;return e.pathname.startsWith(r)?e.pathname.slice(r.length).split(`/`).map(e=>decodeURIComponent(e)).join(`/`):n}catch{return n}}function Se(e,t){let n=e.trim();if(!n)return{url:``,displayUrl:``,error:``};if(F(n)){let e=new URL(n,window.location.origin);return{url:`${e.pathname}${e.search}${e.hash}`,displayUrl:L(n,t),error:``}}if(t&&I(n))return{url:he(t,n),displayUrl:n,error:``};let r=/^https?:\/\//i.test(n)?n:`http://${n}`;try{let e=new URL(r);return e.protocol!==`http:`&&e.protocol!==`https:`?{url:``,displayUrl:n,error:k(`invalidPreviewUrl`)}:{url:e.toString(),displayUrl:e.toString(),error:``}}catch{return{url:``,displayUrl:n,error:k(`invalidPreviewUrl`)}}}function Ce({url:e,onUrlChange:t,projectId:n}){let r=(0,N.useMemo)(()=>Se(e,n),[n,e]),[i,a]=(0,N.useState)({sourceUrl:e,value:r.displayUrl}),[o,s]=(0,N.useState)(``),[c,l]=(0,N.useState)(0),u=r.url,d=u.startsWith(`/api/workspace/preview/`)?`allow-scripts allow-same-origin allow-forms`:`allow-scripts allow-same-origin allow-forms allow-popups allow-downloads allow-modals allow-pointer-lock`,f=i.sourceUrl===e?i.value:r.displayUrl;function p(e=f){let r=Se(e,n);if(r.error){s(r.error);return}s(``),a({sourceUrl:r.displayUrl,value:r.displayUrl}),t(r.displayUrl),r.url&&l(e=>e+1)}function m(){u&&l(e=>e+1)}function h(){u&&window.open(u,`_blank`,`noopener,noreferrer`)}return(0,P.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[(0,P.jsxs)(`div`,{className:`flex shrink-0 flex-col gap-2 border-b border-border p-3`,children:[(0,P.jsxs)(`form`,{className:`flex gap-2`,onSubmit:e=>{e.preventDefault(),p()},children:[(0,P.jsxs)(`label`,{className:`flex min-w-0 flex-1 items-center rounded-md border border-border bg-background px-2 py-1.5 text-xs text-muted-foreground/65 focus-within:text-foreground/85`,children:[(0,P.jsx)(`span`,{className:`sr-only`,children:k(`previewUrl`)}),(0,P.jsx)(`input`,{value:f,onChange:t=>{a({sourceUrl:e,value:t.target.value}),o&&s(``)},placeholder:k(`previewUrlPlaceholder`),className:`min-w-0 flex-1 bg-transparent text-xs text-foreground/85 outline-none placeholder:text-muted-foreground/50`})]}),(0,P.jsx)(A,{type:`submit`,variant:`outline`,size:`sm`,className:`h-8 shrink-0 px-3 text-xs`,children:k(`openPreview`)}),(0,P.jsx)(A,{variant:`ghost`,size:`icon`,onClick:m,disabled:!u,"aria-label":k(`refreshPreview`),title:k(`refreshPreview`),children:(0,P.jsx)(T,{className:`size-4`})}),(0,P.jsx)(A,{variant:`ghost`,size:`icon`,onClick:h,disabled:!u,"aria-label":k(`openInBrowser`),title:k(`openInBrowser`),children:(0,P.jsx)(te,{className:`size-4`})})]}),o?(0,P.jsx)(`div`,{className:`text-xs text-destructive`,children:o}):null]}),(0,P.jsx)(`div`,{className:`min-h-0 flex-1 bg-muted/10`,children:u?(0,P.jsx)(`iframe`,{title:k(`webPreview`),src:u,sandbox:d,className:`h-full w-full border-0 bg-background`},`${u}:${c}`):(0,P.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center px-8 text-center`,children:[(0,P.jsx)(`div`,{className:`rounded-full bg-muted/20 p-3 text-muted-foreground/70`,children:(0,P.jsx)(x,{className:`size-5`})}),(0,P.jsx)(`div`,{className:`mt-4 text-sm font-medium text-foreground/85`,children:k(`noPreviewUrlTitle`)}),(0,P.jsx)(`div`,{className:`mt-2 max-w-xs text-xs leading-5 text-muted-foreground/70`,children:k(`noPreviewUrlDescription`)})]})})]})}var R={ts:`typescript`,tsx:`typescript`,js:`javascript`,jsx:`javascript`,mjs:`javascript`,cjs:`javascript`,json:`json`,jsonc:`json`,css:`css`,scss:`scss`,less:`less`,html:`html`,htm:`html`,md:`markdown`,markdown:`markdown`,py:`python`,rb:`ruby`,go:`go`,rs:`rust`,java:`java`,c:`c`,h:`c`,cpp:`cpp`,cc:`cpp`,cxx:`cpp`,hpp:`cpp`,cs:`csharp`,php:`php`,swift:`swift`,kt:`kotlin`,kts:`kotlin`,sh:`shell`,bash:`shell`,zsh:`shell`,ps1:`powershell`,yml:`yaml`,yaml:`yaml`,xml:`xml`,sql:`sql`,dockerfile:`dockerfile`,toml:`toml`,ini:`ini`,env:`ini`};function z(e){let t=e.split(`/`).pop()?.toLowerCase()??``;return t===`dockerfile`||t.endsWith(`.dockerfile`)?`dockerfile`:R[t.includes(`.`)?t.split(`.`).pop()??``:t]??`plaintext`}function we(e){return e.slice(e.lastIndexOf(`/`)+1)}function B(e){let t=e.lastIndexOf(`.`);return t>0?e.slice(t+1):``}var V={typescript:{Icon:g,className:`text-sky-500 dark:text-sky-400`},javascript:{Icon:g,className:`text-amber-500 dark:text-amber-400`},python:{Icon:g,className:`text-blue-600 dark:text-blue-400`},go:{Icon:g,className:`text-cyan-600 dark:text-cyan-400`},rust:{Icon:g,className:`text-orange-600 dark:text-orange-400`},java:{Icon:g,className:`text-red-500 dark:text-red-400`},c:{Icon:g,className:`text-blue-500 dark:text-blue-400`},cpp:{Icon:g,className:`text-indigo-500 dark:text-indigo-400`},csharp:{Icon:g,className:`text-violet-500 dark:text-violet-400`},php:{Icon:g,className:`text-indigo-500 dark:text-indigo-400`},ruby:{Icon:g,className:`text-rose-500 dark:text-rose-400`},swift:{Icon:g,className:`text-orange-500 dark:text-orange-400`},kotlin:{Icon:g,className:`text-violet-500 dark:text-violet-400`},shell:{Icon:g,className:`text-green-600 dark:text-green-400`},powershell:{Icon:g,className:`text-blue-600 dark:text-blue-400`},json:{Icon:v,className:`text-amber-600 dark:text-amber-400`},css:{Icon:l,className:`text-sky-500 dark:text-sky-400`},scss:{Icon:l,className:`text-pink-500 dark:text-pink-400`},less:{Icon:l,className:`text-sky-500 dark:text-sky-400`},html:{Icon:x,className:`text-orange-500 dark:text-orange-400`},markdown:{Icon:i,className:`text-slate-500 dark:text-slate-400`},yaml:{Icon:_,className:`text-slate-500 dark:text-slate-400`},toml:{Icon:_,className:`text-slate-500 dark:text-slate-400`},ini:{Icon:_,className:`text-slate-500 dark:text-slate-400`},xml:{Icon:g,className:`text-slate-500 dark:text-slate-400`},sql:{Icon:w,className:`text-indigo-500 dark:text-indigo-400`},dockerfile:{Icon:y,className:`text-sky-600 dark:text-sky-400`},plaintext:{Icon:i,className:`text-slate-500 dark:text-slate-400`}},H=new Set([`png`,`jpg`,`jpeg`,`gif`,`svg`,`ico`,`webp`,`bmp`,`avif`]),U=new Set([`zip`,`tar`,`gz`,`tgz`,`rar`,`7z`,`bz2`,`xz`]),W=new Set([`csv`,`tsv`,`xls`,`xlsx`]);function G(e){if(e===`readme`||e.startsWith(`readme.`))return{Icon:p,className:`text-sky-500 dark:text-sky-400`};if(e===`license`||e.startsWith(`license.`)||e===`licence`||e.startsWith(`licence.`)||e===`copying`||e.startsWith(`copying.`))return{Icon:b,className:`text-slate-500 dark:text-slate-400`};if(e===`makefile`||e.startsWith(`makefile.`))return{Icon:se,className:`text-slate-500 dark:text-slate-400`};if(e.startsWith(`docker-compose`))return{Icon:y,className:`text-sky-600 dark:text-sky-400`};if(e===`.gitignore`||e===`.gitattributes`||e===`.gitmodules`)return{Icon:b,className:`text-orange-500 dark:text-orange-400`};if(e===`.env`||e.startsWith(`.env.`))return{Icon:_,className:`text-slate-500 dark:text-slate-400`};if(e.endsWith(`.lock`)||e.endsWith(`-lock.json`)||e.endsWith(`-lock.yaml`))return{Icon:C,className:`text-slate-500 dark:text-slate-400`}}function Te(e){let t=we(e).toLowerCase(),n=G(t);if(n)return n;let r=B(t);return H.has(r)?{Icon:s,className:`text-purple-500 dark:text-purple-400`}:U.has(r)?{Icon:d,className:`text-slate-500 dark:text-slate-400`}:W.has(r)?{Icon:c,className:`text-green-600 dark:text-green-400`}:V[z(e)]||{Icon:h,className:`text-slate-500 dark:text-slate-400`}}function Ee(e,t){let n=e.toLowerCase();return n===`.git`||n===`.svn`||n===`.hg`?{Icon:m,className:`text-orange-500 dark:text-orange-400`}:{Icon:t?a:r,className:`text-slate-500 dark:text-slate-400`}}function K({path:e,className:t=`size-3.5`}){let{Icon:n,className:r}=Te(e);return(0,P.jsx)(n,{className:`${r} ${t}`})}function q({name:e,open:t,className:n=`size-3.5`}){let{Icon:r,className:i}=Ee(e,t);return(0,P.jsx)(r,{className:`${i} ${n}`})}function De(e){return e===`added`?{label:`A`,text:k(`workspaceStatusAdded`),className:`text-emerald-600 dark:text-emerald-500`}:e===`deleted`?{label:`D`,text:k(`workspaceStatusDeleted`),className:`text-red-600 dark:text-red-500`}:e===`renamed`?{label:`R`,text:k(`workspaceStatusRenamed`),className:`text-blue-600 dark:text-blue-500`}:e===`untracked`?{label:`U`,text:k(`workspaceStatusUntracked`),className:`text-amber-600 dark:text-amber-500`}:e===`conflicted`?{label:`!`,text:k(`workspaceStatusConflict`),className:`text-red-600 dark:text-red-500`}:{label:`M`,text:k(`workspaceStatusModified`),className:`text-emerald-600 dark:text-emerald-500`}}function Oe({files:e,selectedPath:t,onSelectFile:n,emptyMessage:r=k(`workspaceNoWorkingTreeChanges`)}){return e.length===0?(0,P.jsx)(`div`,{className:`px-2 py-3 text-xs text-muted-foreground/70`,children:r}):(0,P.jsx)(`div`,{className:`space-y-0.5`,children:e.map(e=>{let r=De(e.status);return(0,P.jsxs)(`button`,{type:`button`,className:`flex h-7 w-full items-center gap-2 rounded-md px-2 text-left text-xs transition-colors ${t===e.path?`bg-muted/28 text-foreground/90`:`text-muted-foreground/72 hover:bg-muted/20 hover:text-foreground/85`}`,onClick:()=>n(e.path),title:e.oldPath?`${e.oldPath} → ${e.path}`:e.path,children:[(0,P.jsx)(`span`,{className:`w-4 shrink-0 font-mono text-[0.68rem] font-semibold ${r.className}`,children:r.label}),(0,P.jsx)(K,{path:e.path,className:`size-3.5 shrink-0`}),(0,P.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.path}),typeof e.additions==`number`&&typeof e.deletions==`number`?(0,P.jsxs)(`span`,{className:`shrink-0 font-mono text-[10px] font-medium`,children:[(0,P.jsxs)(`span`,{className:`text-emerald-600 dark:text-emerald-500`,children:[`+`,e.additions]}),(0,P.jsxs)(`span`,{className:`ml-1 text-red-600 dark:text-red-500`,children:[`-`,e.deletions]})]}):null,(0,P.jsx)(`span`,{className:`shrink-0 text-[0.68rem] text-muted-foreground/55`,children:r.text})]},`${e.status}:${e.oldPath??``}:${e.path}`)})})}function ke(e){return e?e.status===`added`?`A`:e.status===`deleted`?`D`:e.status===`renamed`?`R`:e.status===`untracked`?`U`:`M`:``}function Ae({projectId:e,path:t}){let[n,r]=(0,N.useState)(!1);return n?(0,P.jsx)(K,{path:t,className:`size-3.5 shrink-0`}):(0,P.jsx)(`img`,{src:he(e,t),alt:``,"aria-hidden":!0,loading:`lazy`,decoding:`async`,onError:()=>r(!0),className:`size-3.5 shrink-0 rounded-[3px] object-cover ring-1 ring-black/5 dark:ring-white/10`})}function je({node:e,depth:n,selectedPath:r,gitStatuses:i,onSelectFile:a,onPreviewFile:o,projectId:s}){let[c,l]=(0,N.useState)(n<1),u=e.type===`directory`,d=r===e.path,f=ke(i[e.path]),p=(u?void 0:me(e.path))===`image`,m=!!s&&p,h=!!o&&(p||fe(e.path));function g(){o?.(e.path)}return(0,P.jsxs)(`div`,{children:[(0,P.jsxs)(`button`,{type:`button`,className:`group flex h-7 w-full items-center gap-1.5 rounded-md px-2 text-left text-xs transition-colors ${d?`bg-muted/28 text-foreground/90`:`text-muted-foreground/72 hover:bg-muted/20 hover:text-foreground/85`}`,style:{paddingLeft:`${.5+n*.75}rem`},onClick:()=>{u?l(e=>!e):p&&o?g():a(e.path)},title:e.path,children:[u?(0,P.jsx)(re,{className:`size-3 shrink-0 transition-transform ${c?`rotate-90`:``}`}):(0,P.jsx)(`span`,{className:`w-3 shrink-0`}),u?(0,P.jsx)(q,{name:e.name,open:c,className:`size-3.5 shrink-0`}):m?(0,P.jsx)(Ae,{projectId:s,path:e.path}):(0,P.jsx)(K,{path:e.path,className:`size-3.5 shrink-0`}),(0,P.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.name}),f?(0,P.jsx)(`span`,{className:`shrink-0 font-mono text-[0.68rem] text-emerald-600 dark:text-emerald-500`,children:f}):null,h?(0,P.jsx)(`span`,{role:`button`,tabIndex:0,"aria-label":k(`openPreview`),title:k(`openPreview`),className:`-mr-1 shrink-0 rounded p-0.5 text-muted-foreground/60 opacity-0 transition-opacity hover:bg-muted/40 hover:text-foreground/85 focus-visible:opacity-100 focus-visible:text-foreground/85 focus-visible:outline-none group-hover:opacity-100`,onClick:e=>{e.stopPropagation(),g()},onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),e.stopPropagation(),g())},children:(0,P.jsx)(t,{className:`size-3.5`})}):null]}),u&&c?(0,P.jsx)(`div`,{children:(e.children??[]).map(e=>(0,P.jsx)(je,{node:e,depth:n+1,selectedPath:r,gitStatuses:i,onSelectFile:a,onPreviewFile:o,projectId:s},e.path))}):null]})}function Me({tree:e,selectedPath:t,gitStatuses:n={},onSelectFile:r,onPreviewFile:i,projectId:a}){return e.length===0?(0,P.jsx)(`div`,{className:`px-2 py-3 text-xs text-muted-foreground/70`,children:k(`workspaceNoFilesToDisplay`)}):(0,P.jsx)(`div`,{className:`space-y-0.5`,children:e.map(e=>(0,P.jsx)(je,{node:e,depth:0,selectedPath:t,gitStatuses:n,onSelectFile:r,onPreviewFile:i,projectId:a},e.path))})}function Ne(e,t){return e===`browser`?`browser`:`${e}:${t}`}var Pe=[{view:`overview`,label:k(`workspaceOverview`),icon:o},{view:`files`,label:k(`workspaceFiles`),icon:r},{view:`changes`,label:k(`workspaceChanges`),icon:f},{view:`browser`,label:k(`workspaceBrowser`),icon:x}],J=380,Y=480,X=800,Fe=`quickforge_workspaceInspectorWidth`,Ie=140,Le=200,Re=400;function ze(){if(typeof window>`u`)return Y;try{let e=window.localStorage.getItem(Fe);if(!e)return Y;let t=Number(e);return Number.isFinite(t)?Math.min(X,Math.max(J,t)):Y}catch{return Y}}function Be(e,t){let n=t.trim().toLowerCase();return n?e.flatMap(e=>{let t=e.children?Be(e.children,n):void 0;return!(e.name.toLowerCase().includes(n)||e.path.toLowerCase().includes(n))&&(!t||t.length===0)?[]:[{...e,...t?{children:t}:{}}]}):e}function Ve(e){return k(`workspaceReviewPrompt`,{list:e.map(e=>`- ${e.status}: ${e.oldPath?`${e.oldPath} -> `:``}${e.path}`).join(`
|
|
1
|
+
import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{$ as t,A as n,B as r,G as i,H as a,I as o,J as s,K as c,L as l,P as u,Q as d,R as f,St as p,U as m,W as h,X as g,Y as _,Z as v,_t as ee,at as y,et as te,g as b,h as ne,ht as re,it as ie,k as ae,n as oe,nt as x,o as se,ot as S,pt as ce,q as C,rt as w,v as T,vt as E,wt as le}from"./icons-DzxBk7tb.js";import{n as D}from"./react-vendor-DsAeMFcm.js";import{F as O,I as k,P as A,a as ue,c as de,i as fe,l as pe,n as me,o as he,r as ge,s as _e,t as j,u as ve}from"./index-Bt_dRvdG.js";import{i as ye,n as M,r as be,t as xe}from"./diff-line-counts-CCPYa_e0.js";var N=e(le(),1),P=D();function F(e){let t=e.trim();if(!t.startsWith(`/api/workspace/preview/`))return!1;try{let e=new URL(t,window.location.origin);return e.origin===window.location.origin&&e.pathname.startsWith(`/api/workspace/preview/`)}catch{return!1}}function I(e){let t=e.trim().replace(/\\/g,`/`);return t.startsWith(`/`)||/^[a-zA-Z]:\//.test(t)}function L(e,t){let n=e.trim();if(!t||!F(n))return n;try{let e=new URL(n,window.location.origin),r=`/api/workspace/preview/${encodeURIComponent(t)}/`;return e.pathname.startsWith(r)?e.pathname.slice(r.length).split(`/`).map(e=>decodeURIComponent(e)).join(`/`):n}catch{return n}}function Se(e,t){let n=e.trim();if(!n)return{url:``,displayUrl:``,error:``};if(F(n)){let e=new URL(n,window.location.origin);return{url:`${e.pathname}${e.search}${e.hash}`,displayUrl:L(n,t),error:``}}if(t&&I(n))return{url:he(t,n),displayUrl:n,error:``};let r=/^https?:\/\//i.test(n)?n:`http://${n}`;try{let e=new URL(r);return e.protocol!==`http:`&&e.protocol!==`https:`?{url:``,displayUrl:n,error:k(`invalidPreviewUrl`)}:{url:e.toString(),displayUrl:e.toString(),error:``}}catch{return{url:``,displayUrl:n,error:k(`invalidPreviewUrl`)}}}function Ce({url:e,onUrlChange:t,projectId:n}){let r=(0,N.useMemo)(()=>Se(e,n),[n,e]),[i,a]=(0,N.useState)({sourceUrl:e,value:r.displayUrl}),[o,s]=(0,N.useState)(``),[c,l]=(0,N.useState)(0),u=r.url,d=u.startsWith(`/api/workspace/preview/`)?`allow-scripts allow-same-origin allow-forms`:`allow-scripts allow-same-origin allow-forms allow-popups allow-downloads allow-modals allow-pointer-lock`,f=i.sourceUrl===e?i.value:r.displayUrl;function p(e=f){let r=Se(e,n);if(r.error){s(r.error);return}s(``),a({sourceUrl:r.displayUrl,value:r.displayUrl}),t(r.displayUrl),r.url&&l(e=>e+1)}function m(){u&&l(e=>e+1)}function h(){u&&window.open(u,`_blank`,`noopener,noreferrer`)}return(0,P.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[(0,P.jsxs)(`div`,{className:`flex shrink-0 flex-col gap-2 border-b border-border p-3`,children:[(0,P.jsxs)(`form`,{className:`flex gap-2`,onSubmit:e=>{e.preventDefault(),p()},children:[(0,P.jsxs)(`label`,{className:`flex min-w-0 flex-1 items-center rounded-md border border-border bg-background px-2 py-1.5 text-xs text-muted-foreground/65 focus-within:text-foreground/85`,children:[(0,P.jsx)(`span`,{className:`sr-only`,children:k(`previewUrl`)}),(0,P.jsx)(`input`,{value:f,onChange:t=>{a({sourceUrl:e,value:t.target.value}),o&&s(``)},placeholder:k(`previewUrlPlaceholder`),className:`min-w-0 flex-1 bg-transparent text-xs text-foreground/85 outline-none placeholder:text-muted-foreground/50`})]}),(0,P.jsx)(A,{type:`submit`,variant:`outline`,size:`sm`,className:`h-8 shrink-0 px-3 text-xs`,children:k(`openPreview`)}),(0,P.jsx)(A,{variant:`ghost`,size:`icon`,onClick:m,disabled:!u,"aria-label":k(`refreshPreview`),title:k(`refreshPreview`),children:(0,P.jsx)(T,{className:`size-4`})}),(0,P.jsx)(A,{variant:`ghost`,size:`icon`,onClick:h,disabled:!u,"aria-label":k(`openInBrowser`),title:k(`openInBrowser`),children:(0,P.jsx)(te,{className:`size-4`})})]}),o?(0,P.jsx)(`div`,{className:`text-xs text-destructive`,children:o}):null]}),(0,P.jsx)(`div`,{className:`min-h-0 flex-1 bg-muted/10`,children:u?(0,P.jsx)(`iframe`,{title:k(`webPreview`),src:u,sandbox:d,className:`h-full w-full border-0 bg-background`},`${u}:${c}`):(0,P.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center px-8 text-center`,children:[(0,P.jsx)(`div`,{className:`rounded-full bg-muted/20 p-3 text-muted-foreground/70`,children:(0,P.jsx)(x,{className:`size-5`})}),(0,P.jsx)(`div`,{className:`mt-4 text-sm font-medium text-foreground/85`,children:k(`noPreviewUrlTitle`)}),(0,P.jsx)(`div`,{className:`mt-2 max-w-xs text-xs leading-5 text-muted-foreground/70`,children:k(`noPreviewUrlDescription`)})]})})]})}var R={ts:`typescript`,tsx:`typescript`,js:`javascript`,jsx:`javascript`,mjs:`javascript`,cjs:`javascript`,json:`json`,jsonc:`json`,css:`css`,scss:`scss`,less:`less`,html:`html`,htm:`html`,md:`markdown`,markdown:`markdown`,py:`python`,rb:`ruby`,go:`go`,rs:`rust`,java:`java`,c:`c`,h:`c`,cpp:`cpp`,cc:`cpp`,cxx:`cpp`,hpp:`cpp`,cs:`csharp`,php:`php`,swift:`swift`,kt:`kotlin`,kts:`kotlin`,sh:`shell`,bash:`shell`,zsh:`shell`,ps1:`powershell`,yml:`yaml`,yaml:`yaml`,xml:`xml`,sql:`sql`,dockerfile:`dockerfile`,toml:`toml`,ini:`ini`,env:`ini`};function z(e){let t=e.split(`/`).pop()?.toLowerCase()??``;return t===`dockerfile`||t.endsWith(`.dockerfile`)?`dockerfile`:R[t.includes(`.`)?t.split(`.`).pop()??``:t]??`plaintext`}function we(e){return e.slice(e.lastIndexOf(`/`)+1)}function B(e){let t=e.lastIndexOf(`.`);return t>0?e.slice(t+1):``}var V={typescript:{Icon:g,className:`text-sky-500 dark:text-sky-400`},javascript:{Icon:g,className:`text-amber-500 dark:text-amber-400`},python:{Icon:g,className:`text-blue-600 dark:text-blue-400`},go:{Icon:g,className:`text-cyan-600 dark:text-cyan-400`},rust:{Icon:g,className:`text-orange-600 dark:text-orange-400`},java:{Icon:g,className:`text-red-500 dark:text-red-400`},c:{Icon:g,className:`text-blue-500 dark:text-blue-400`},cpp:{Icon:g,className:`text-indigo-500 dark:text-indigo-400`},csharp:{Icon:g,className:`text-violet-500 dark:text-violet-400`},php:{Icon:g,className:`text-indigo-500 dark:text-indigo-400`},ruby:{Icon:g,className:`text-rose-500 dark:text-rose-400`},swift:{Icon:g,className:`text-orange-500 dark:text-orange-400`},kotlin:{Icon:g,className:`text-violet-500 dark:text-violet-400`},shell:{Icon:g,className:`text-green-600 dark:text-green-400`},powershell:{Icon:g,className:`text-blue-600 dark:text-blue-400`},json:{Icon:v,className:`text-amber-600 dark:text-amber-400`},css:{Icon:l,className:`text-sky-500 dark:text-sky-400`},scss:{Icon:l,className:`text-pink-500 dark:text-pink-400`},less:{Icon:l,className:`text-sky-500 dark:text-sky-400`},html:{Icon:x,className:`text-orange-500 dark:text-orange-400`},markdown:{Icon:i,className:`text-slate-500 dark:text-slate-400`},yaml:{Icon:_,className:`text-slate-500 dark:text-slate-400`},toml:{Icon:_,className:`text-slate-500 dark:text-slate-400`},ini:{Icon:_,className:`text-slate-500 dark:text-slate-400`},xml:{Icon:g,className:`text-slate-500 dark:text-slate-400`},sql:{Icon:w,className:`text-indigo-500 dark:text-indigo-400`},dockerfile:{Icon:y,className:`text-sky-600 dark:text-sky-400`},plaintext:{Icon:i,className:`text-slate-500 dark:text-slate-400`}},H=new Set([`png`,`jpg`,`jpeg`,`gif`,`svg`,`ico`,`webp`,`bmp`,`avif`]),U=new Set([`zip`,`tar`,`gz`,`tgz`,`rar`,`7z`,`bz2`,`xz`]),W=new Set([`csv`,`tsv`,`xls`,`xlsx`]);function G(e){if(e===`readme`||e.startsWith(`readme.`))return{Icon:p,className:`text-sky-500 dark:text-sky-400`};if(e===`license`||e.startsWith(`license.`)||e===`licence`||e.startsWith(`licence.`)||e===`copying`||e.startsWith(`copying.`))return{Icon:b,className:`text-slate-500 dark:text-slate-400`};if(e===`makefile`||e.startsWith(`makefile.`))return{Icon:se,className:`text-slate-500 dark:text-slate-400`};if(e.startsWith(`docker-compose`))return{Icon:y,className:`text-sky-600 dark:text-sky-400`};if(e===`.gitignore`||e===`.gitattributes`||e===`.gitmodules`)return{Icon:b,className:`text-orange-500 dark:text-orange-400`};if(e===`.env`||e.startsWith(`.env.`))return{Icon:_,className:`text-slate-500 dark:text-slate-400`};if(e.endsWith(`.lock`)||e.endsWith(`-lock.json`)||e.endsWith(`-lock.yaml`))return{Icon:C,className:`text-slate-500 dark:text-slate-400`}}function Te(e){let t=we(e).toLowerCase(),n=G(t);if(n)return n;let r=B(t);return H.has(r)?{Icon:s,className:`text-purple-500 dark:text-purple-400`}:U.has(r)?{Icon:d,className:`text-slate-500 dark:text-slate-400`}:W.has(r)?{Icon:c,className:`text-green-600 dark:text-green-400`}:V[z(e)]||{Icon:h,className:`text-slate-500 dark:text-slate-400`}}function Ee(e,t){let n=e.toLowerCase();return n===`.git`||n===`.svn`||n===`.hg`?{Icon:m,className:`text-orange-500 dark:text-orange-400`}:{Icon:t?a:r,className:`text-slate-500 dark:text-slate-400`}}function K({path:e,className:t=`size-3.5`}){let{Icon:n,className:r}=Te(e);return(0,P.jsx)(n,{className:`${r} ${t}`})}function q({name:e,open:t,className:n=`size-3.5`}){let{Icon:r,className:i}=Ee(e,t);return(0,P.jsx)(r,{className:`${i} ${n}`})}function De(e){return e===`added`?{label:`A`,text:k(`workspaceStatusAdded`),className:`text-emerald-600 dark:text-emerald-500`}:e===`deleted`?{label:`D`,text:k(`workspaceStatusDeleted`),className:`text-red-600 dark:text-red-500`}:e===`renamed`?{label:`R`,text:k(`workspaceStatusRenamed`),className:`text-blue-600 dark:text-blue-500`}:e===`untracked`?{label:`U`,text:k(`workspaceStatusUntracked`),className:`text-amber-600 dark:text-amber-500`}:e===`conflicted`?{label:`!`,text:k(`workspaceStatusConflict`),className:`text-red-600 dark:text-red-500`}:{label:`M`,text:k(`workspaceStatusModified`),className:`text-emerald-600 dark:text-emerald-500`}}function Oe({files:e,selectedPath:t,onSelectFile:n,emptyMessage:r=k(`workspaceNoWorkingTreeChanges`)}){return e.length===0?(0,P.jsx)(`div`,{className:`px-2 py-3 text-xs text-muted-foreground/70`,children:r}):(0,P.jsx)(`div`,{className:`space-y-0.5`,children:e.map(e=>{let r=De(e.status);return(0,P.jsxs)(`button`,{type:`button`,className:`flex h-7 w-full items-center gap-2 rounded-md px-2 text-left text-xs transition-colors ${t===e.path?`bg-muted/28 text-foreground/90`:`text-muted-foreground/72 hover:bg-muted/20 hover:text-foreground/85`}`,onClick:()=>n(e.path),title:e.oldPath?`${e.oldPath} → ${e.path}`:e.path,children:[(0,P.jsx)(`span`,{className:`w-4 shrink-0 font-mono text-[0.68rem] font-semibold ${r.className}`,children:r.label}),(0,P.jsx)(K,{path:e.path,className:`size-3.5 shrink-0`}),(0,P.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.path}),typeof e.additions==`number`&&typeof e.deletions==`number`?(0,P.jsxs)(`span`,{className:`shrink-0 font-mono text-[10px] font-medium`,children:[(0,P.jsxs)(`span`,{className:`text-emerald-600 dark:text-emerald-500`,children:[`+`,e.additions]}),(0,P.jsxs)(`span`,{className:`ml-1 text-red-600 dark:text-red-500`,children:[`-`,e.deletions]})]}):null,(0,P.jsx)(`span`,{className:`shrink-0 text-[0.68rem] text-muted-foreground/55`,children:r.text})]},`${e.status}:${e.oldPath??``}:${e.path}`)})})}function ke(e){return e?e.status===`added`?`A`:e.status===`deleted`?`D`:e.status===`renamed`?`R`:e.status===`untracked`?`U`:`M`:``}function Ae({projectId:e,path:t}){let[n,r]=(0,N.useState)(!1);return n?(0,P.jsx)(K,{path:t,className:`size-3.5 shrink-0`}):(0,P.jsx)(`img`,{src:he(e,t),alt:``,"aria-hidden":!0,loading:`lazy`,decoding:`async`,onError:()=>r(!0),className:`size-3.5 shrink-0 rounded-[3px] object-cover ring-1 ring-black/5 dark:ring-white/10`})}function je({node:e,depth:n,selectedPath:r,gitStatuses:i,onSelectFile:a,onPreviewFile:o,projectId:s}){let[c,l]=(0,N.useState)(n<1),u=e.type===`directory`,d=r===e.path,f=ke(i[e.path]),p=(u?void 0:me(e.path))===`image`,m=!!s&&p,h=!!o&&(p||fe(e.path));function g(){o?.(e.path)}return(0,P.jsxs)(`div`,{children:[(0,P.jsxs)(`button`,{type:`button`,className:`group flex h-7 w-full items-center gap-1.5 rounded-md px-2 text-left text-xs transition-colors ${d?`bg-muted/28 text-foreground/90`:`text-muted-foreground/72 hover:bg-muted/20 hover:text-foreground/85`}`,style:{paddingLeft:`${.5+n*.75}rem`},onClick:()=>{u?l(e=>!e):p&&o?g():a(e.path)},title:e.path,children:[u?(0,P.jsx)(re,{className:`size-3 shrink-0 transition-transform ${c?`rotate-90`:``}`}):(0,P.jsx)(`span`,{className:`w-3 shrink-0`}),u?(0,P.jsx)(q,{name:e.name,open:c,className:`size-3.5 shrink-0`}):m?(0,P.jsx)(Ae,{projectId:s,path:e.path}):(0,P.jsx)(K,{path:e.path,className:`size-3.5 shrink-0`}),(0,P.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.name}),f?(0,P.jsx)(`span`,{className:`shrink-0 font-mono text-[0.68rem] text-emerald-600 dark:text-emerald-500`,children:f}):null,h?(0,P.jsx)(`span`,{role:`button`,tabIndex:0,"aria-label":k(`openPreview`),title:k(`openPreview`),className:`-mr-1 shrink-0 rounded p-0.5 text-muted-foreground/60 opacity-0 transition-opacity hover:bg-muted/40 hover:text-foreground/85 focus-visible:opacity-100 focus-visible:text-foreground/85 focus-visible:outline-none group-hover:opacity-100`,onClick:e=>{e.stopPropagation(),g()},onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),e.stopPropagation(),g())},children:(0,P.jsx)(t,{className:`size-3.5`})}):null]}),u&&c?(0,P.jsx)(`div`,{children:(e.children??[]).map(e=>(0,P.jsx)(je,{node:e,depth:n+1,selectedPath:r,gitStatuses:i,onSelectFile:a,onPreviewFile:o,projectId:s},e.path))}):null]})}function Me({tree:e,selectedPath:t,gitStatuses:n={},onSelectFile:r,onPreviewFile:i,projectId:a}){return e.length===0?(0,P.jsx)(`div`,{className:`px-2 py-3 text-xs text-muted-foreground/70`,children:k(`workspaceNoFilesToDisplay`)}):(0,P.jsx)(`div`,{className:`space-y-0.5`,children:e.map(e=>(0,P.jsx)(je,{node:e,depth:0,selectedPath:t,gitStatuses:n,onSelectFile:r,onPreviewFile:i,projectId:a},e.path))})}function Ne(e,t){return e===`browser`?`browser`:`${e}:${t}`}var Pe=[{view:`overview`,label:k(`workspaceOverview`),icon:o},{view:`files`,label:k(`workspaceFiles`),icon:r},{view:`changes`,label:k(`workspaceChanges`),icon:f},{view:`browser`,label:k(`workspaceBrowser`),icon:x}],J=380,Y=480,X=800,Fe=`quickforge_workspaceInspectorWidth`,Ie=140,Le=200,Re=400;function ze(){if(typeof window>`u`)return Y;try{let e=window.localStorage.getItem(Fe);if(!e)return Y;let t=Number(e);return Number.isFinite(t)?Math.min(X,Math.max(J,t)):Y}catch{return Y}}function Be(e,t){let n=t.trim().toLowerCase();return n?e.flatMap(e=>{let t=e.children?Be(e.children,n):void 0;return!(e.name.toLowerCase().includes(n)||e.path.toLowerCase().includes(n))&&(!t||t.length===0)?[]:[{...e,...t?{children:t}:{}}]}):e}function Ve(e){return k(`workspaceReviewPrompt`,{list:e.map(e=>`- ${e.status}: ${e.oldPath?`${e.oldPath} -> `:``}${e.path}`).join(`
|
|
2
2
|
`)})}function He(e){return k(`workspaceCommitMessagePrompt`,{list:e.map(e=>`- ${e.status}: ${e.oldPath?`${e.oldPath} -> `:``}${e.path}`).join(`
|
|
3
3
|
`)})}function Ue(e,t){let n=[`${k(`workspaceCurrentBranch`)}: ${e||k(`unknown`)}`];return t?.total&&n.push(`${t.total} ${k(`workspaceChangeCount`)}`),n.join(` · `)}function We({title:e,files:t,selectedPath:n,onSelectFile:r}){return t.length===0?null:(0,P.jsxs)(`div`,{className:`space-y-1`,children:[(0,P.jsxs)(`div`,{className:`px-2 text-[11px] font-medium uppercase tracking-wide text-muted-foreground/60`,children:[e,` `,t.length]}),(0,P.jsx)(Oe,{files:t,selectedPath:n,onSelectFile:r})]})}function Ge({view:e,changesCount:t,open:n,onOpenChange:r,onViewChange:i}){let a=Pe.find(t=>t.view===e)??Pe[0],o=a.icon;return(0,P.jsxs)(`div`,{className:`relative min-w-0`,children:[(0,P.jsxs)(`button`,{type:`button`,className:`flex max-w-full items-center gap-2 rounded-xl bg-muted/20 px-2.5 py-1.5 text-left text-sm font-semibold text-foreground/90 transition-colors hover:bg-muted/28`,onClick:()=>r(!n),"aria-haspopup":`menu`,"aria-expanded":n,children:[(0,P.jsx)(o,{className:`size-4 shrink-0 text-foreground/75`}),(0,P.jsx)(`span`,{className:`min-w-0 truncate`,children:a.label}),(0,P.jsx)(ee,{className:O(`size-4 shrink-0 text-muted-foreground/65 transition-transform`,n?`rotate-180`:``)})]}),n?(0,P.jsx)(`div`,{className:`absolute left-0 top-11 z-40 w-60 rounded-2xl border border-border bg-popover p-2 shadow-quickforge`,children:Pe.map(n=>{let a=n.icon,o=n.view===e;return(0,P.jsxs)(`button`,{type:`button`,className:O(`flex w-full items-center gap-3 rounded-xl px-3 py-2.5 text-left text-sm transition-colors`,o?`bg-muted/28 text-foreground/90`:`text-foreground/80 hover:bg-muted/20 hover:text-foreground/90`),onClick:()=>{i(n.view),r(!1)},children:[(0,P.jsx)(a,{className:`size-4 shrink-0`}),(0,P.jsxs)(`span`,{className:`min-w-0 flex-1 truncate`,children:[n.label,n.view===`changes`&&t?` ${t}`:``]}),o?(0,P.jsx)(E,{className:`size-4 shrink-0 text-emerald-600 dark:text-emerald-500`}):null]},n.view)})}):null]})}function Z(e){return e?e.language===`markdown`||/\.(md|markdown)$/i.test(e.path):!1}function Ke(e,t=!1){return k(t?`readerFileMarkdownPrompt`:`readerFilePrompt`,{path:e})}function qe(e){return k(`readerDiffPrompt`,{path:e})}function Q(e){return`Diff for ${e.oldPath?`${e.oldPath} -> ${e.path}`:e.path}\n\n--- OLD\n${e.oldContent}\n\n--- NEW\n${e.newContent}`}function Je({tabs:e,activeId:t,onSelect:n,onClose:r}){return(0,P.jsx)(`div`,{className:`flex h-full min-w-0 flex-1 items-center gap-0.5 overflow-x-auto px-1.5`,children:e.map(e=>{let i=e.id===t,a=e.mode===`browser`,s=a?k(`workspaceBrowser`):e.path.split(`/`).pop()||e.path,c=e.path.split(`.`).pop()||``;return(0,P.jsxs)(`button`,{type:`button`,className:O(`group flex max-w-44 shrink-0 items-center gap-1.5 rounded-md px-2 py-1 text-xs font-medium transition-colors`,i?`bg-background shadow-sm text-foreground`:`text-muted-foreground/70 hover:bg-muted/40 hover:text-foreground/85`),onClick:()=>n(e.id),title:e.path,children:[(0,P.jsx)(`span`,{className:O(`flex size-4 shrink-0 items-center justify-center rounded-sm`,i?`bg-primary/10 text-primary`:`bg-muted/30 text-muted-foreground/60`),children:e.loading?(0,P.jsx)(u,{className:`size-2.5 animate-spin`}):a?(0,P.jsx)(x,{className:`size-2.5`}):c===`md`||c===`markdown`?(0,P.jsx)(o,{className:`size-2.5`}):(0,P.jsx)(g,{className:`size-2.5`})}),(0,P.jsx)(`span`,{className:`min-w-0 truncate`,children:s}),(0,P.jsx)(`span`,{role:`button`,tabIndex:0,className:O(`ml-0.5 shrink-0 rounded-sm p-0.5 opacity-0 transition-opacity group-hover:opacity-100 hover:bg-destructive/15 hover:text-destructive`,i&&`opacity-100`),onClick:t=>{t.stopPropagation(),r(e.id)},onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),t.stopPropagation(),r(e.id))},"aria-label":k(`close`),children:(0,P.jsx)(oe,{className:`size-3`})})]},e.id)})})}function Ye({mode:e,file:t,diff:r,loading:i,error:a,onClose:o,onDraftRequest:s}){let[c,l]=(0,N.useState)(),[u,d]=(0,N.useState)(`preview`);async function f(e,t){t&&(await navigator.clipboard.writeText(t),l(e),window.setTimeout(()=>l(void 0),1200))}let p=e===`file`?t?.path:r?.path,m=e===`file`&&Z(t),h=e===`file`?t?.content:r?Q(r):void 0,g=e===`file`&&t?Ke(t.path,m):e===`diff`&&r?qe(r.path):void 0,_=(0,N.useMemo)(()=>e===`diff`&&r?xe(r.oldContent,r.newContent):void 0,[e,r]);return(0,P.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[(0,P.jsxs)(`div`,{className:`flex h-11 shrink-0 items-center gap-2 border-b border-border px-3`,children:[m?(0,P.jsx)(`div`,{className:`inline-flex rounded-full bg-muted/25 p-1 text-xs`,children:[`preview`,`source`].map(e=>(0,P.jsx)(`button`,{type:`button`,className:e===u?`rounded-full bg-background px-3 py-1 font-medium text-foreground/90 shadow-[0_8px_20px_-16px_rgb(15_23_42_/_0.42)]`:`rounded-full px-3 py-1 text-muted-foreground/70 hover:text-foreground/85`,onClick:()=>d(e),children:k(e===`preview`?`markdownPreview`:`markdownSource`)},e))}):null,_?(0,P.jsxs)(`span`,{className:`shrink-0 font-mono text-[11px] font-medium`,children:[(0,P.jsxs)(`span`,{className:`text-emerald-600 dark:text-emerald-400`,children:[`+`,_.added]}),(0,P.jsxs)(`span`,{className:`ml-1.5 text-red-600 dark:text-red-400`,children:[`-`,_.removed]})]}):null,(0,P.jsx)(`div`,{className:`flex-1`}),(0,P.jsx)(A,{variant:`ghost`,size:`icon`,className:`size-7`,onClick:()=>void f(`path`,p),disabled:!p,"aria-label":k(`copyPath`),title:k(`copyPath`),children:c===`path`?(0,P.jsx)(E,{className:`size-3.5`}):(0,P.jsx)(ie,{className:`size-3.5`})}),(0,P.jsx)(A,{variant:`ghost`,size:`icon`,className:`size-7`,onClick:()=>void f(`content`,h),disabled:!h,"aria-label":k(`copyContent`),title:k(e===`file`?`copyContent`:`copyDiffContent`),children:c===`content`?(0,P.jsx)(E,{className:`size-3.5`}):(0,P.jsx)(ie,{className:`size-3.5`})}),(0,P.jsx)(A,{variant:`ghost`,size:`icon`,className:`size-7`,onClick:()=>g&&s?.(g),disabled:!g||!s,"aria-label":k(`askAiAboutThis`),title:k(`askAiAboutThis`),children:(0,P.jsx)(n,{className:`size-3.5`})}),(0,P.jsx)(A,{variant:`ghost`,size:`icon`,className:`size-7`,onClick:o,"aria-label":k(`close`),title:k(`close`),children:(0,P.jsx)(oe,{className:`size-3.5`})})]}),(0,P.jsxs)(`div`,{className:`min-h-0 flex-1 bg-background`,children:[i?(0,P.jsx)(`div`,{className:`p-4 text-sm text-muted-foreground/70`,children:k(`openingReader`)}):null,!i&&a?(0,P.jsx)(`div`,{className:`p-4 text-sm text-destructive`,children:a}):null,!i&&!a&&e===`file`&&t?m?(0,P.jsx)(be,{path:t.path,content:t.content,language:t.language,mode:u},t.path):(0,P.jsx)(ye,{path:t.path,content:t.content,language:t.language}):null,!i&&!a&&e===`diff`&&r?(0,P.jsx)(M,{path:r.path,oldContent:r.oldContent,newContent:r.newContent,language:r.language,status:r.status}):null]})]})}function Xe({project:e,artifacts:n,changesCount:r,changedPaths:i,isGitRepository:a,gitBranch:o,onSelectFile:s,onSelectDiff:c,onPreviewFile:l}){let[u,d]=(0,N.useState)(!1),[f,p]=(0,N.useState)(()=>new Set),m=ue(n),h=n.filter(e=>e.command);function g(e){p(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}return(0,P.jsxs)(`div`,{className:`space-y-3 p-2`,children:[(0,P.jsxs)(`div`,{className:`rounded-lg border border-border bg-muted/10 px-3 py-3`,children:[(0,P.jsx)(`div`,{className:`text-xs font-medium text-foreground/85`,children:e?.name??k(`noProjectSelected`)}),(0,P.jsx)(`div`,{className:`mt-1 text-[11px] text-muted-foreground/65`,children:a?`${k(`workspaceCurrentBranch`)}: ${o||k(`unknown`)} · ${r} ${k(`workspaceChangeCount`)}`:k(`workspaceNotGitRepository`)})]}),(0,P.jsxs)(`div`,{className:`rounded-lg border border-border bg-background px-3 py-3`,children:[(0,P.jsxs)(`div`,{className:`flex items-center gap-2 text-xs font-semibold text-foreground/90`,children:[(0,P.jsx)(S,{className:`size-3.5 text-emerald-600 dark:text-emerald-500`}),k(`workspaceCurrentArtifacts`)]}),n.length===0?(0,P.jsx)(`div`,{className:`mt-2 text-xs leading-5 text-muted-foreground/70`,children:k(`workspaceNoArtifacts`)}):(0,P.jsxs)(`div`,{className:`mt-3 space-y-3`,children:[m.length?(0,P.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,P.jsxs)(`div`,{className:`text-[11px] font-medium uppercase tracking-wide text-muted-foreground/60`,children:[k(`workspaceFiles`),` `,m.length]}),m.slice(0,8).map(e=>{let n=e.path,r=ge(n),a=i.has(n),o=typeof e.addedLines==`number`||typeof e.removedLines==`number`;return(0,P.jsxs)(`div`,{className:`group flex min-w-0 items-center gap-2 rounded-md px-2 py-1.5 text-xs text-foreground/85 transition-colors hover:bg-muted/20`,children:[(0,P.jsx)(`button`,{type:`button`,className:`min-w-0 flex-1 truncate text-left font-medium`,onClick:()=>r?l(n):a?c(n):s(n),title:n,children:e.title||j(n)}),o?(0,P.jsxs)(`span`,{className:`shrink-0 font-mono text-[10px] font-medium`,children:[(0,P.jsxs)(`span`,{className:`text-emerald-600 dark:text-emerald-400`,children:[`+`,e.addedLines??0]}),(0,P.jsxs)(`span`,{className:`ml-1 text-red-600 dark:text-red-400`,children:[`-`,e.removedLines??0]})]}):null,(0,P.jsx)(`span`,{className:`shrink-0 rounded-full bg-muted/30 px-1.5 py-0.5 text-[10px] font-medium text-muted-foreground/70`,children:e.kind}),r?(0,P.jsx)(`button`,{type:`button`,className:`shrink-0 inline-flex size-5 items-center justify-center text-blue-600 opacity-0 transition-opacity hover:bg-blue-500/10 hover:text-blue-700 group-hover:opacity-100 dark:text-blue-400`,onClick:()=>l(n),"aria-label":k(`previewArtifact`),title:k(`previewArtifact`),children:(0,P.jsx)(t,{className:`size-3.5`})}):null,(0,P.jsx)(`button`,{type:`button`,className:`shrink-0 rounded-md px-1.5 py-0.5 text-[10px] font-medium text-muted-foreground/70 opacity-0 transition-opacity hover:bg-muted/25 group-hover:opacity-100`,onClick:()=>a?c(n):s(n),children:k(a?`workspaceViewDiff`:`artifactPreviewViewSource`)})]},e.id)}),m.length>8?(0,P.jsxs)(`div`,{className:`px-2 text-[11px] text-muted-foreground/60`,children:[`+`,m.length-8]}):null]}):null,h.length?(0,P.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,P.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-2 rounded-md px-1 py-1 text-left text-[11px] font-medium uppercase tracking-wide text-muted-foreground/60 transition-colors hover:bg-muted/15 hover:text-foreground/75`,onClick:()=>d(e=>!e),"aria-expanded":u,children:[(0,P.jsx)(ee,{className:O(`size-3.5 transition-transform`,u?``:`-rotate-90`)}),(0,P.jsxs)(`span`,{className:`min-w-0 flex-1 truncate`,children:[k(`workspaceCommands`),` `,h.length]})]}),u?(0,P.jsx)(`div`,{className:`space-y-1`,children:h.map((e,t)=>{let n=f.has(e.id);return(0,P.jsxs)(`div`,{className:`rounded-md bg-muted/15 text-[11px] text-muted-foreground/80`,children:[(0,P.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-2 px-2 py-1.5 text-left transition-colors hover:bg-muted/20`,onClick:()=>g(e.id),"aria-expanded":n,children:[(0,P.jsx)(ee,{className:O(`size-3 shrink-0 transition-transform`,n?``:`-rotate-90`)}),(0,P.jsxs)(`span`,{className:`shrink-0 font-medium text-muted-foreground/65`,children:[`#`,t+1]}),(0,P.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono`,children:e.command})]}),n?(0,P.jsxs)(`div`,{className:`space-y-1 px-2 pb-2 pt-1.5`,children:[(0,P.jsx)(`pre`,{className:`whitespace-pre-wrap break-words font-mono text-[11px] leading-5 text-foreground/80`,children:e.command}),e.outputFile?(0,P.jsxs)(`div`,{className:`text-[10px] text-muted-foreground/65`,children:[k(`workspaceCommandOutput`),`: `,(0,P.jsx)(`span`,{className:`font-mono`,children:e.outputFile})]}):null]}):null]},e.id)})}):null]}):null]})]})]})}function Ze({project:e,open:t,view:r,onViewChange:i,onPreviewArtifact:a,onDraftRequest:o,focusTarget:s,previewUrl:c,onPreviewUrlChange:l,artifacts:d=[]}){let[f,p]=(0,N.useState)([]),[m,h]=(0,N.useState)([]),[g,_]=(0,N.useState)(),[v,ee]=(0,N.useState)(),[y,te]=(0,N.useState)(!1),[b,re]=(0,N.useState)(!1),[ie,oe]=(0,N.useState)(),[x,se]=(0,N.useState)(``),[S,C]=(0,N.useState)([]),[w,T]=(0,N.useState)(),[E,le]=(0,N.useState)(!1),[D,ue]=(0,N.useState)(Le),[fe,me]=(0,N.useState)(!1),[he,ge]=(0,N.useState)(t),[j,ye]=(0,N.useState)(!1),[M,be]=(0,N.useState)(ze),[xe,F]=(0,N.useState)(!1),[I,L]=(0,N.useState)(!1),[Se,R]=(0,N.useState)(!1),z=(0,N.useRef)(null),we=(0,N.useRef)(null),B=(0,N.useRef)(null),V=(0,N.useRef)(null),H=(0,N.useRef)(null),U=(0,N.useRef)(null),W=(0,N.useRef)(null),G=(0,N.useRef)(null),Te=(0,N.useRef)(void 0),Ee=(0,N.useRef)(void 0),K=e?.id,q=(0,N.useMemo)(()=>S.find(e=>e.id===w),[w,S]),De=q?.mode===`browser`,Oe=!!(q&&q.mode!==`browser`),ke=r===`browser`?`files`:r,Ae=q?.id,je=(0,N.useMemo)(()=>{let e={};for(let t of m)e[t.path]=t;return e},[m]),Pe=(0,N.useMemo)(()=>{let e=new Set;for(let t of m)e.add(t.path),t.oldPath&&e.add(t.oldPath);return e},[m]),Y=(0,N.useMemo)(()=>Be(f,x),[x,f]),Z=(0,N.useMemo)(()=>({conflicts:m.filter(e=>e.conflict||e.status===`conflicted`),staged:m.filter(e=>!e.conflict&&e.status!==`untracked`&&e.staged),unstaged:m.filter(e=>!e.conflict&&e.status!==`untracked`&&e.unstaged),untracked:m.filter(e=>!e.conflict&&e.status===`untracked`)}),[m]);(0,N.useEffect)(()=>{if(t){let e=!1;return queueMicrotask(()=>{e||(ge(!0),window.requestAnimationFrame(()=>{e||ye(!0)}))}),()=>{e=!0}}let e=!1;queueMicrotask(()=>{e||ye(!1)});let n=window.setTimeout(()=>ge(!1),180);return()=>{e=!0,window.clearTimeout(n)}},[t]),(0,N.useEffect)(()=>{if(!E)return;let e=e=>{we.current?.contains(e.target)||le(!1)},t=e=>{e.key===`Escape`&&le(!1)};return document.addEventListener(`pointerdown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`pointerdown`,e),document.removeEventListener(`keydown`,t)}},[E]),(0,N.useEffect)(()=>{let e=!1;return!t||!s||queueMicrotask(()=>{e||(i(s.tab===`git`?`changes`:`files`),s.filePath&&Te.current?.(s.filePath))}),()=>{e=!0}},[s,i,t]),(0,N.useEffect)(()=>{if(!t)return;let e=S.find(e=>e.mode===`browser`);if(r===`browser`){if(!e){let e=Ne(`browser`,``);C(t=>t.some(t=>t.id===e)?t:[...t,{id:e,mode:`browser`,path:``,loading:!1}]),T(e);return}w!==e.id&&T(e.id)}else q?.mode===`browser`&&T(S.find(e=>e.mode!==`browser`)?.id)},[r,t,w,q,S]),(0,N.useEffect)(()=>{try{window.localStorage.setItem(Fe,String(M))}catch{}},[M]);let Ke=(0,N.useCallback)(()=>{be(e=>e<X?X:e)},[]);(0,N.useEffect)(()=>{!j||I||(r===`browser`||r!==`overview`&&Ae)&&Ke()},[Ae,r,j,I,Ke]),(0,N.useEffect)(()=>{let e=!1;if(!(!K||!t))return queueMicrotask(()=>{e||(re(!0),oe(void 0),Promise.all([ve(K),de(K)]).then(([t,n])=>{e||(p(t.tree),h(n.files),_(n.branch),ee(n.counts),te(n.isGitRepository))}).catch(t=>{e||oe(t instanceof Error?t.message:k(`workspaceLoadFailed`))}).finally(()=>{e||re(!1)}))}),()=>{e=!0}},[t,K]),(0,N.useEffect)(()=>{let e=Ee.current;Ee.current=K,!(e===void 0||e===K)&&(C([]),T(void 0))},[K]);function qe(e){if(a){a(e);return}Q(e)}async function Q(e){if(!K)return;i(`files`);let t=Ne(`file`,e);if(S.some(e=>e.id===t)){T(t);return}let n={id:t,mode:`file`,path:e,loading:!0};C(e=>[...e,n]),T(t);try{let n=await pe(K,e);C(e=>e.map(e=>e.id===t?{...e,file:n,loading:!1}:e))}catch(e){C(n=>n.map(n=>n.id===t?{...n,loading:!1,error:e instanceof Error?e.message:k(`workspaceOpenFileFailed`)}:n))}}Te.current=Q;function Ze(){let e=Ne(`browser`,``);if(S.some(t=>t.id===e)){T(e),i(`browser`);return}let t={id:e,mode:`browser`,path:``,loading:!1};C(e=>[...e,t]),T(e),i(`browser`)}async function Qe(e,t){if(!K)return;t&&i(`changes`);let n=Ne(`diff`,e);if(S.some(e=>e.id===n)){T(n);return}let r={id:n,mode:`diff`,path:e,loading:!0};C(e=>[...e,r]),T(n);try{let t=await _e(K,e);C(e=>e.map(e=>e.id===n?{...e,diff:t,loading:!1}:e))}catch(e){C(t=>t.map(t=>t.id===n?{...t,loading:!1,error:e instanceof Error?e.message:k(`workspaceOpenDiffFailed`)}:t))}}function $e(e){C(t=>{let n=t.findIndex(t=>t.id===e),r=t.filter(t=>t.id!==e);return w===e&&T((r[n]??r[n-1])?.id),r})}async function $(e){await Qe(e,!0)}async function et(e){await Qe(e,!1)}function tt(e){H.current={startX:e.clientX,startWidth:M,currentWidth:M},G.current={cursor:document.body.style.cursor,userSelect:document.body.style.userSelect},document.body.style.cursor=`col-resize`,document.body.style.userSelect=`none`,F(!0),e.preventDefault();try{e.currentTarget.setPointerCapture(e.pointerId)}catch{}}function nt(e){let t=H.current,n=z.current;!t||!n||(t.currentWidth=Math.min(X,Math.max(J,t.startWidth+t.startX-e.clientX)),U.current===null&&(U.current=window.requestAnimationFrame(()=>{U.current=null;let e=H.current;!e||!z.current||(z.current.style.width=`${e.currentWidth}px`)})))}function rt(e){let t=H.current?.currentWidth;H.current=null,U.current!==null&&(window.cancelAnimationFrame(U.current),U.current=null),typeof t==`number`&&(z.current&&(z.current.style.width=`${t}px`),be(t));let n=G.current;n&&(document.body.style.cursor=n.cursor,document.body.style.userSelect=n.userSelect,G.current=null),F(!1);try{e.currentTarget.releasePointerCapture(e.pointerId)}catch{}}function it(e){B.current={startX:e.clientX,startWidth:D,currentWidth:D},document.body.style.cursor=`col-resize`,document.body.style.userSelect=`none`,me(!0),e.preventDefault();try{e.currentTarget.setPointerCapture(e.pointerId)}catch{}}function at(e){let t=B.current;t&&(t.currentWidth=Math.min(Re,Math.max(Ie,t.startWidth+e.clientX-t.startX)),V.current===null&&(V.current=window.requestAnimationFrame(()=>{V.current=null;let e=B.current;e&&ue(e.currentWidth)})))}function ot(e){let t=B.current?.currentWidth;B.current=null,V.current!==null&&(window.cancelAnimationFrame(V.current),V.current=null),typeof t==`number`&&ue(t),document.body.style.cursor=``,document.body.style.userSelect=``,me(!1);try{e.currentTarget.releasePointerCapture(e.pointerId)}catch{}}let st=(0,N.useCallback)(()=>{let e=z.current;if(!e){L(e=>!e);return}W.current?.cancel();let t=e.getBoundingClientRect(),n=window.innerWidth,r=window.innerHeight,i=`cubic-bezier(0.22, 1, 0.36, 1)`;if(R(!0),!I){window.requestAnimationFrame(()=>{let e=z.current;if(!e)return;Object.assign(e.style,{position:`fixed`,left:`${t.left}px`,top:`${t.top}px`,right:`auto`,bottom:`auto`,width:`${t.width}px`,height:`${t.height}px`,minWidth:`0px`,maxWidth:`none`,zIndex:`40`});let a=e.animate([{left:`${t.left}px`,top:`${t.top}px`,width:`${t.width}px`,height:`${t.height}px`},{left:`0px`,top:`0px`,width:`${n}px`,height:`${r}px`}],{duration:240,easing:i,fill:`forwards`});W.current=a,a.onfinish=()=>{W.current=null,L(!0),window.requestAnimationFrame(()=>{a.cancel(),e.removeAttribute(`style`),window.requestAnimationFrame(()=>R(!1))})},a.oncancel=()=>{W.current=null,R(!1)}});return}window.requestAnimationFrame(()=>{let e=z.current;if(!e)return;Object.assign(e.style,{position:`fixed`,left:`0px`,top:`0px`,right:`auto`,bottom:`auto`,width:`${t.width}px`,height:`${t.height}px`,zIndex:`40`});let a=n-M,o=e.animate([{left:`0px`,top:`0px`,width:`${t.width}px`,height:`${t.height}px`},{left:`${a}px`,top:`0px`,width:`${M}px`,height:`${r}px`}],{duration:240,easing:i,fill:`forwards`});W.current=o,o.onfinish=()=>{W.current=null,L(!1),window.requestAnimationFrame(()=>{o.cancel(),e.style.position=``,e.style.left=``,e.style.top=``,e.style.right=``,e.style.bottom=``,e.style.height=``,e.style.zIndex=``,e.style.width=`${M}px`,e.style.minWidth=`${J}px`,e.style.maxWidth=`${X}px`,window.requestAnimationFrame(()=>R(!1))})},o.oncancel=()=>{W.current=null,R(!1)}})},[I,M]);return(0,N.useEffect)(()=>{if(!I)return;let e=e=>{e.key===`Escape`&&L(!1)};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[I]),(0,N.useEffect)(()=>()=>{U.current!==null&&window.cancelAnimationFrame(U.current),V.current!==null&&window.cancelAnimationFrame(V.current),W.current?.cancel(),z.current&&z.current.removeAttribute(`style`);let e=G.current;e&&(document.body.style.cursor=e.cursor,document.body.style.userSelect=e.userSelect)},[]),he?(0,P.jsx)(P.Fragment,{children:(0,P.jsxs)(`aside`,{ref:z,className:O(`relative hidden shrink-0 overflow-hidden flex-col border-l border-border bg-background transition-[width,min-width,max-width,opacity,transform] duration-200 ease-out will-change-[width,opacity,transform] lg:flex`,j?`translate-x-0 opacity-100`:`w-0 min-w-0 max-w-0 translate-x-4 opacity-0`,xe?`transition-none`:``,I?`fixed inset-0 z-40 border-l-0`:``),style:j?I?void 0:{width:M,minWidth:J,maxWidth:X}:void 0,children:[j&&!I?(0,P.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,"aria-valuemin":J,"aria-valuemax":X,"aria-valuenow":M,className:O(`group absolute inset-y-0 -left-2 z-20 flex w-4 cursor-col-resize items-center justify-center bg-transparent transition-colors hover:bg-border/40`,xe?`bg-border/45`:``),onPointerDown:tt,onPointerMove:nt,onPointerUp:rt,onPointerCancel:rt,children:(0,P.jsx)(`div`,{className:O(`flex h-10 w-3 items-center justify-center rounded-full border border-border bg-background text-muted-foreground/60 opacity-0 shadow-sm transition-opacity`,xe?`opacity-100`:`group-hover:opacity-100`),children:(0,P.jsx)(ce,{className:`size-3`})})}):null,(0,P.jsxs)(`div`,{className:O(`flex h-14 shrink-0 items-center gap-2 border-b border-border bg-muted/20 px-3 pr-20 transition-opacity duration-150`,Se?`opacity-0`:`opacity-100`),children:[(0,P.jsx)(`div`,{ref:we,className:`shrink-0`,children:(0,P.jsx)(Ge,{view:r,changesCount:m.length,open:E,onOpenChange:le,onViewChange:e=>{e===`browser`?Ze():i(e)}})}),(0,P.jsx)(`div`,{className:`h-5 w-px shrink-0 bg-border/60`}),(0,P.jsx)(Je,{tabs:S,activeId:w,onSelect:e=>{T(e),S.find(t=>t.id===e)?.mode===`browser`?r!==`browser`&&i(`browser`):r===`browser`&&i(`files`)},onClose:$e}),(0,P.jsx)(A,{variant:`ghost`,size:`icon`,className:`shrink-0`,onClick:st,"aria-label":k(I?`workspaceExitFullscreen`:`workspaceFullscreen`),title:k(I?`workspaceExitFullscreen`:`workspaceFullscreen`),children:I?(0,P.jsx)(ae,{className:`size-4`}):(0,P.jsx)(u,{className:`size-4`})})]}),(0,P.jsx)(`div`,{className:O(`flex min-h-0 flex-1 transition-opacity duration-150`,Se?`opacity-0`:`opacity-100`),children:e?.id?De?(0,P.jsx)(Ce,{url:c,onUrlChange:l,projectId:e.id}):(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(`div`,{className:O(`flex min-h-0 flex-col bg-muted/20`,Oe?`shrink-0 border-r border-border`:`flex-1`),style:Oe?{width:D,minWidth:Ie,maxWidth:Re}:void 0,children:ie?(0,P.jsx)(`div`,{className:`p-4 text-sm text-destructive`,children:ie}):(0,P.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-auto p-2`,children:[b?(0,P.jsx)(`div`,{className:`px-2 py-3 text-xs text-muted-foreground/70`,children:k(`workspaceLoading`)}):null,!b&&ke===`overview`?(0,P.jsx)(Xe,{project:e,artifacts:d,changesCount:m.length,changedPaths:Pe,isGitRepository:y,gitBranch:g,onSelectFile:Q,onSelectDiff:et,onPreviewFile:qe}):null,!b&&ke===`files`?(0,P.jsxs)(P.Fragment,{children:[(0,P.jsxs)(`label`,{className:`mb-2 flex items-center gap-2 rounded-md border border-border bg-background px-2 py-1.5 text-xs text-muted-foreground/65 focus-within:text-foreground/85`,children:[(0,P.jsx)(ne,{className:`size-3.5 shrink-0`}),(0,P.jsx)(`input`,{value:x,onChange:e=>se(e.target.value),placeholder:k(`workspaceFilterFiles`),className:`min-w-0 flex-1 bg-transparent text-xs text-foreground/85 outline-none placeholder:text-muted-foreground/50`})]}),(0,P.jsx)(Me,{tree:Y,selectedPath:void 0,gitStatuses:je,onSelectFile:Q,onPreviewFile:qe,projectId:K})]}):null,!b&&ke===`changes`?y?(0,P.jsxs)(`div`,{className:`space-y-3`,children:[(0,P.jsxs)(`div`,{className:`rounded-lg border border-border bg-muted/10 px-3 py-2`,children:[(0,P.jsx)(`div`,{className:`truncate text-xs font-medium text-foreground/85`,children:Ue(g,v)}),(0,P.jsxs)(`div`,{className:`mt-1 flex flex-wrap gap-x-3 gap-y-1 text-[11px] text-muted-foreground/60`,children:[(0,P.jsxs)(`span`,{children:[k(`workspaceStaged`),` `,v?.staged??0]}),(0,P.jsxs)(`span`,{children:[k(`workspaceChanges`),` `,v?.unstaged??0]}),(0,P.jsxs)(`span`,{children:[k(`workspaceUntracked`),` `,v?.untracked??0]}),v?.conflicts?(0,P.jsxs)(`span`,{className:`text-red-600 dark:text-red-500`,children:[k(`workspaceConflicts`),` `,v.conflicts]}):null]}),m.length>0&&o?(0,P.jsxs)(`div`,{className:`mt-2 flex gap-1.5`,children:[(0,P.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1 rounded-md px-1.5 py-1 text-[11px] font-medium text-muted-foreground/72 transition-colors hover:bg-muted/20 hover:text-foreground/85`,onClick:()=>o(Ve(m)),children:[(0,P.jsx)(n,{className:`size-3`}),k(`workspaceReview`)]}),(0,P.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1 rounded-md px-1.5 py-1 text-[11px] font-medium text-muted-foreground/72 transition-colors hover:bg-muted/20 hover:text-foreground/85`,onClick:()=>o(He(m)),children:[(0,P.jsx)(n,{className:`size-3`}),k(`workspaceCommitMessage`)]})]}):null]}),m.length===0?(0,P.jsx)(`div`,{className:`px-2 py-3 text-xs text-muted-foreground/70`,children:k(`workspaceNoWorkingTreeChanges`)}):(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(We,{title:k(`workspaceConflicts`),files:Z.conflicts,selectedPath:void 0,onSelectFile:$}),(0,P.jsx)(We,{title:k(`workspaceStagedChanges`),files:Z.staged,selectedPath:void 0,onSelectFile:$}),(0,P.jsx)(We,{title:k(`workspaceChanges`),files:Z.unstaged,selectedPath:void 0,onSelectFile:$}),(0,P.jsx)(We,{title:k(`workspaceUntracked`),files:Z.untracked,selectedPath:void 0,onSelectFile:$})]})]}):(0,P.jsx)(`div`,{className:`px-2 py-3 text-xs text-muted-foreground/70`,children:k(`workspaceNotGitRepository`)}):null]})}),Oe?(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,"aria-valuemin":Ie,"aria-valuemax":Re,"aria-valuenow":D,className:O(`group relative z-10 w-1.5 shrink-0 cursor-col-resize bg-transparent transition-colors`,fe?`bg-primary/30`:`hover:bg-border/60`),onPointerDown:it,onPointerMove:at,onPointerUp:ot,onPointerCancel:ot}),(0,P.jsx)(`div`,{className:`flex min-w-0 flex-1 flex-col bg-background`,children:q?(0,P.jsx)(Ye,{mode:q.mode,file:q.file,diff:q.diff,loading:q.loading,error:q.error,onClose:()=>$e(q.id),onDraftRequest:o}):null})]}):null]}):(0,P.jsx)(`div`,{className:`p-4 text-sm text-muted-foreground/70`,children:k(`workspaceSelectProject`)})})]})}):null}export{Ze as WorkspaceInspector};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{A as t,it as n,n as r,vt as i,wt as a}from"./icons-DzxBk7tb.js";import{i as o,n as s}from"./react-vendor-DsAeMFcm.js";import{I as c,P as l}from"./index-
|
|
1
|
+
import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{A as t,it as n,n as r,vt as i,wt as a}from"./icons-DzxBk7tb.js";import{i as o,n as s}from"./react-vendor-DsAeMFcm.js";import{I as c,P as l}from"./index-Bt_dRvdG.js";import{i as u,n as d,r as f,t as p}from"./diff-line-counts-CCPYa_e0.js";var m=e(a(),1),h=o(),g=s();function _(e){return Number.isFinite(e)?e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/1024/1024).toFixed(1)} MB`:``}function v(e){return e?e.status===`added`?c(`workspaceStatusAdded`):e.status===`deleted`?c(`workspaceStatusDeleted`):e.status===`renamed`?c(`workspaceStatusRenamed`):e.status===`untracked`?c(`workspaceStatusUntracked`):c(`workspaceStatusModified`):``}function y(e){return e?e.language===`markdown`||/\.(md|markdown)$/i.test(e.path):!1}function b(e,t=!1){return c(t?`readerFileMarkdownPrompt`:`readerFilePrompt`,{path:e})}function x(e){return c(`readerDiffPrompt`,{path:e})}function S(e){return`Diff for ${e.oldPath?`${e.oldPath} -> ${e.path}`:e.path}\n\n--- OLD\n${e.oldContent}\n\n--- NEW\n${e.newContent}`}function C({open:e,mode:a,file:o,diff:s,loading:C,error:w,onOpenChange:T,onDraftRequest:E}){let[D,O]=(0,m.useState)(),[k,A]=(0,m.useState)(`preview`);async function j(e,t){t&&(await navigator.clipboard.writeText(t),O(e),window.setTimeout(()=>O(void 0),1200))}(0,m.useEffect)(()=>{if(!e)return;let t=e=>{e.key===`Escape`&&T(!1)};return document.addEventListener(`keydown`,t),()=>document.removeEventListener(`keydown`,t)},[T,e]);let M=(0,m.useMemo)(()=>a===`diff`&&s?p(s.oldContent,s.newContent):void 0,[a,s]);if(!e)return null;let N=a===`file`?o?.path:s?.path,P=a===`file`&&y(o),F=a===`file`?o?.content:s?S(s):void 0,I=a===`file`&&o?b(o.path,P):a===`diff`&&s?x(s.path):void 0,L=a===`file`&&o?`${o.language} · ${_(o.size)}`:a===`diff`&&s?`${v(s)} · ${s.language}`:``;return(0,h.createPortal)((0,g.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/65 px-4 py-6 backdrop-blur-sm`,role:`dialog`,"aria-modal":`true`,children:[(0,g.jsx)(`button`,{type:`button`,className:`absolute inset-0 cursor-default`,"aria-label":c(`close`),onClick:()=>T(!1)}),(0,g.jsxs)(`div`,{className:`relative flex h-[min(88vh,900px)] w-[min(92vw,1280px)] min-w-0 flex-col overflow-hidden rounded-2xl border border-border bg-background shadow-quickforge`,children:[(0,g.jsxs)(`header`,{className:`flex h-14 shrink-0 items-center gap-3 border-b border-border px-4`,children:[(0,g.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,g.jsx)(`div`,{className:`truncate text-sm font-semibold text-foreground/90`,children:N??(a===`file`?`Code reader`:`Diff reader`)}),L?(0,g.jsx)(`div`,{className:`truncate text-xs text-muted-foreground/65`,children:L}):null]}),P?(0,g.jsx)(`div`,{className:`inline-flex shrink-0 rounded-full bg-muted/25 p-1 text-xs`,children:[`preview`,`source`].map(e=>(0,g.jsx)(`button`,{type:`button`,className:e===k?`rounded-full bg-background px-3 py-1 font-medium text-foreground/90 shadow-[0_8px_20px_-16px_rgb(15_23_42_/_0.42)]`:`rounded-full px-3 py-1 text-muted-foreground/70 hover:text-foreground/85`,onClick:()=>A(e),children:c(e===`preview`?`markdownPreview`:`markdownSource`)},e))}):null,M?(0,g.jsxs)(`span`,{className:`shrink-0 font-mono text-xs font-medium`,children:[(0,g.jsxs)(`span`,{className:`text-emerald-600 dark:text-emerald-400`,children:[`+`,M.added]}),(0,g.jsxs)(`span`,{className:`ml-1.5 text-red-600 dark:text-red-400`,children:[`-`,M.removed]})]}):null,(0,g.jsx)(l,{variant:`ghost`,size:`icon`,onClick:()=>void j(`path`,N),disabled:!N,"aria-label":c(`copyPath`),title:c(`copyPath`),children:D===`path`?(0,g.jsx)(i,{className:`size-4`}):(0,g.jsx)(n,{className:`size-4`})}),(0,g.jsx)(l,{variant:`ghost`,size:`icon`,onClick:()=>void j(`content`,F),disabled:!F,"aria-label":c(`copyContent`),title:c(a===`file`?`copyContent`:`copyDiffContent`),children:D===`content`?(0,g.jsx)(i,{className:`size-4`}):(0,g.jsx)(n,{className:`size-4`})}),(0,g.jsx)(l,{variant:`ghost`,size:`icon`,onClick:()=>I&&E?.(I),disabled:!I||!E,"aria-label":c(`askAiAboutThis`),title:c(`askAiAboutThis`),children:(0,g.jsx)(t,{className:`size-4`})}),(0,g.jsx)(l,{variant:`ghost`,size:`icon`,onClick:()=>T(!1),"aria-label":c(`close`),title:c(`close`),children:(0,g.jsx)(r,{className:`size-4`})})]}),(0,g.jsxs)(`div`,{className:`min-h-0 flex-1 bg-background`,children:[C?(0,g.jsx)(`div`,{className:`p-4 text-sm text-muted-foreground/70`,children:c(`openingReader`)}):null,!C&&w?(0,g.jsx)(`div`,{className:`p-4 text-sm text-destructive`,children:w}):null,!C&&!w&&a===`file`&&o?P?(0,g.jsx)(f,{path:o.path,content:o.content,language:o.language,mode:k},o.path):(0,g.jsx)(u,{path:o.path,content:o.content,language:o.language}):null,!C&&!w&&a===`diff`&&s?(0,g.jsx)(d,{path:s.path,oldContent:s.oldContent,newContent:s.newContent,language:s.language,status:s.status}):null]})]})]}),document.body)}export{C as WorkspaceReaderDialog};
|