@shawnstack/quickforge 1.7.8 → 1.7.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/bin/quickforge.mjs +10 -1
  2. package/dist/assets/{AgentProfilesPage-BSM5w3bn.js → AgentProfilesPage-Dw9orPNt.js} +1 -1
  3. package/dist/assets/{ChatPanelHost-cd80S4EX.js → ChatPanelHost-CW3-MQyL.js} +2 -2
  4. package/dist/assets/{CloudAccountSettingsPage-BJMrfgy9.js → CloudAccountSettingsPage-CDkKN1Sz.js} +1 -1
  5. package/dist/assets/{PluginsPage-mJkTmVVV.js → PluginsPage-Dj1bmsEf.js} +1 -1
  6. package/dist/assets/{ScheduledTasksPage-DJj_NLm9.js → ScheduledTasksPage-C9lOTi75.js} +1 -1
  7. package/dist/assets/{SettingsWorkspacePage-7lQ0Wl63.js → SettingsWorkspacePage-CFuvSATi.js} +3 -3
  8. package/dist/assets/{ShareLinksSettingsPage-DjFq_Lnb.js → ShareLinksSettingsPage-CH_t33A3.js} +1 -1
  9. package/dist/assets/{SharedConversationPage-BbuNpcpP.js → SharedConversationPage-DLo05j7c.js} +1 -1
  10. package/dist/assets/{TerminalDock-CczcCJJE.js → TerminalDock-CSOVub-m.js} +1 -1
  11. package/dist/assets/{WorkspaceInspector-0i6x-diB.js → WorkspaceInspector-DPXgLIum.js} +1 -1
  12. package/dist/assets/index-DQBOm9gt.js +66 -0
  13. package/dist/assets/index-ps85guTs.css +3 -0
  14. package/dist/assets/{local-tools-Dn1Y9aPe.js → local-tools-BxfQeIUQ.js} +1 -1
  15. package/dist/assets/{mcp-servers-dialog-BG4b67ea.js → mcp-servers-dialog-CwHp0K4q.js} +1 -1
  16. package/dist/assets/{skills-dialog-DIzZvQqW.js → skills-dialog-k9ycekIU.js} +1 -1
  17. package/dist/index.html +4 -4
  18. package/package.json +1 -1
  19. package/server/agent-manager.mjs +68 -2
  20. package/server/auto-compaction.mjs +0 -2
  21. package/server/context-usage.mjs +9 -7
  22. package/server/maintenance/downgrade-session-state-v1.mjs +4 -2
  23. package/server/maintenance/export-session-state-v1.mjs +4 -2
  24. package/server/public-api.mjs +21 -2
  25. package/server/routes/backup.mjs +7 -0
  26. package/server/routes/storage.mjs +23 -0
  27. package/server/session-persistence-lock.mjs +17 -6
  28. package/server/session-state-backup.mjs +4 -2
  29. package/server/session-state-cutover.mjs +284 -91
  30. package/server/session-state-service.mjs +38 -17
  31. package/server/sqlite/session-state-repository.mjs +145 -25
  32. package/server/storage.mjs +28 -0
  33. package/server/utils/process-tree.mjs +14 -2
  34. package/dist/assets/index-D-J_8Smf.css +0 -3
  35. package/dist/assets/index-DFASc15l.js +0 -66
@@ -1,5 +1,5 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/AgentProfilesPage-BSM5w3bn.js","assets/rolldown-runtime-DWdDZTNf.js","assets/index-DFASc15l.js","assets/pi-ai-Cr2ee4a0.js","assets/dist-yDHbi5ux.js","assets/pi-web-ui-DV5jKjSg.js","assets/lit-vendor-DvaQX_UQ.js","assets/css-utils-31qzCXsk.js","assets/icons-DM_qJ7VJ.js","assets/react-vendor-BpWW_Nvp.js","assets/skills-dialog-DIzZvQqW.js","assets/logger-8REuLPGK.js","assets/model-display-label-CURwH0xM.js","assets/index-D-J_8Smf.css","assets/model-identity-CgA6_Pbm.js","assets/mcp-servers-dialog-BG4b67ea.js","assets/PluginsPage-mJkTmVVV.js","assets/plugin-api-BrdQeM4B.js","assets/ScheduledTasksPage-DJj_NLm9.js","assets/ShareLinksSettingsPage-DjFq_Lnb.js","assets/CloudAccountSettingsPage-BJMrfgy9.js"])))=>i.map(i=>d[i]);
2
- import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{$ as t,Bt as n,F as r,Gt as i,Ht as a,Jt as o,Kt as s,Lt as c,Mt as ee,Rt as l,St as u,T as d,X as f,_t as p,b as te,h as m,p as ne,u as h,v as g,vt as _,wt as v,zt as y}from"./icons-DM_qJ7VJ.js";import{n as b,r as re}from"./react-vendor-BpWW_Nvp.js";import{c as ie,d as ae,f as oe,l as se,p as x,u as ce}from"./lit-vendor-DvaQX_UQ.js";import{m as S,x as C}from"./pi-web-ui-DV5jKjSg.js";import{J as w}from"./pi-ai-Cr2ee4a0.js";import{t as T}from"./logger-8REuLPGK.js";import{n as le,t as ue}from"./model-display-label-CURwH0xM.js";import{An as E,Ct as de,Dn as fe,J as pe,Mn as me,Mt as he,Nn as D,Nt as ge,Pn as O,St as _e,Tt as k,U as ve,X as ye,_n as be,a as xe,c as Se,cn as A,dn as Ce,dt as we,ft as Te,gn as Ee,gt as j,hn as De,ht as M,i as Oe,jn as ke,jt as Ae,kn as je,l as Me,ln as Ne,lt as Pe,mn as Fe,mt as Ie,pn as Le,pt as Re,s as ze,ut as Be,vn as Ve,vt as He,wt as N,xn as Ue,xt as We}from"./index-DFASc15l.js";var P=e(o(),1),Ge={openai:{name:`OpenAI`,baseUrl:`https://api.openai.com/v1`,protocol:`openai-completions`,modelId:`gpt-4o`,supportsImages:!0},deepseek:{name:`DeepSeek`,baseUrl:`https://api.deepseek.com/v1`,protocol:`openai-completions`,modelId:`deepseek-chat`},glm:{name:`Zhipu GLM`,baseUrl:`https://open.bigmodel.cn/api/paas/v4`,protocol:`openai-completions`,modelId:`glm-4-plus`},ollama:{name:`Ollama`,baseUrl:`http://localhost:11434/v1`,protocol:`openai-completions`,modelId:`llama3.1`},litellm:{name:A.name,baseUrl:A.baseUrl,protocol:`openai-completions`,modelId:A.modelId,supportsImages:A.supportsImages}},Ke=[{key:`openai`,label:O(`presetOpenai`)},{key:`deepseek`,label:O(`presetDeepseek`)},{key:`glm`,label:O(`presetGlm`)},{key:`ollama`,label:O(`presetOllama`)},{key:`litellm`,label:O(`presetLitellm`)},{key:`custom`,label:O(`presetCustom`)}],F=()=>({modelId:``,contextWindow:A.contextWindow,maxTokens:A.maxTokens,reasoning:!0,supportsImages:!1,visibleInSelectors:!0,open:!1}),I=()=>({name:A.name,baseUrl:A.baseUrl,apiKey:``,headerRows:[],protocol:`openai-completions`,models:[F()]}),qe=class extends S{providers=[];form=I();editingProviderId;formOpen=!1;loading=!0;apiKeyVisible=!1;advancedOpen=!1;activePreset=``;testing=!1;testResult=`idle`;testError=``;autoEditProviderName=null;async connectedCallback(){if(super.connectedCallback(),await this.loadProviders(),this.autoEditProviderName){let e=this.providers.find(e=>e.name===this.autoEditProviderName);e&&await this.openEditForm(e),this.autoEditProviderName=null}}getTabName(){return O(`customModels`)}async loadProviders(){this.loading=!0,this.requestUpdate();try{this.providers=await C().customProviders.getAll()}catch(e){T.error(`Failed to load custom providers:`,e),this.providers=[]}finally{this.loading=!1,this.requestUpdate()}}resetTestState(){this.testing=!1,this.testResult=`idle`,this.testError=``}openAddForm(){this.editingProviderId=void 0,this.form=I(),this.apiKeyVisible=!1,this.advancedOpen=!1,this.activePreset=``,this.resetTestState(),this.formOpen=!0,this.requestUpdate()}async openEditForm(e){let t=await C().providerKeys.get(e.name)??e.apiKey??``,n=e.models??[],r=n.length>0?n.map(e=>({modelId:e.id,contextWindow:e.contextWindow??A.contextWindow,maxTokens:e.maxTokens??A.maxTokens,reasoning:e.reasoning===!0,supportsImages:e.input?.includes(`image`)===!0,visibleInSelectors:e.quickforgeHidden!==!0,open:!1})):[F()],i=n[0]?.headers??{},a=Object.entries(i).map(([e,t])=>({key:e,value:String(t)}));this.editingProviderId=e.id,this.form={providerId:e.id,id:e.id,name:e.name,baseUrl:e.baseUrl,apiKey:t,headerRows:a,protocol:e.type===`anthropic-messages`?`anthropic-messages`:`openai-completions`,models:r},this.apiKeyVisible=!1,this.advancedOpen=a.length>0||e.type===`anthropic-messages`,this.activePreset=``,this.resetTestState(),this.formOpen=!0,this.requestUpdate()}closeForm(){this.formOpen=!1,this.editingProviderId=void 0,this.form=I(),this.apiKeyVisible=!1,this.advancedOpen=!1,this.activePreset=``,this.resetTestState(),this.requestUpdate()}toggleApiKeyVisibility(){this.apiKeyVisible=!this.apiKeyVisible,this.requestUpdate()}updateForm(e,t){this.form={...this.form,[e]:t},(e===`name`||e===`baseUrl`)&&(this.activePreset=``),this.resetTestState(),this.requestUpdate()}updateModelField(e,t,n){let r=this.form.models.map((r,i)=>i===e?{...r,[t]:n}:r);this.form={...this.form,models:r},t===`modelId`&&(this.activePreset=``,this.resetTestState()),this.requestUpdate()}addModelRow(){this.form={...this.form,models:[...this.form.models,F()]},this.requestUpdate()}removeModelRow(e){let t=this.form.models.filter((t,n)=>n!==e);this.form={...this.form,models:t},this.requestUpdate()}toggleModelExpanded(e){let t=this.form.models.map((t,n)=>n===e?{...t,open:!t.open}:t);this.form={...this.form,models:t},this.requestUpdate()}addHeaderRow(){this.form={...this.form,headerRows:[...this.form.headerRows,{key:``,value:``}]},this.requestUpdate()}updateHeaderRow(e,t,n){let r=this.form.headerRows.map((r,i)=>i===e?{...r,[t]:n}:r);this.form={...this.form,headerRows:r},this.requestUpdate()}removeHeaderRow(e){let t=this.form.headerRows.filter((t,n)=>n!==e);this.form={...this.form,headerRows:t},this.requestUpdate()}applyPreset(e){if(this.activePreset=e,e===`custom`)this.form={...this.form,name:``,baseUrl:``,protocol:`openai-completions`,models:[F()]};else{let t=Ge[e];this.form={...this.form,name:t.name,baseUrl:t.baseUrl,protocol:t.protocol,models:[{...F(),modelId:t.modelId,supportsImages:t.supportsImages===!0,open:!1}]}}this.resetTestState(),this.requestUpdate()}buildHeadersFromRows(){let e={};for(let t of this.form.headerRows){let n=t.key.trim(),r=t.value.trim();n&&r&&(e[n]=r)}return e}buildModel(e,t){let n=this.form.name.trim(),r=this.form.baseUrl.trim(),i=e.reasoning===!0,a=e.supportsImages===!0?[`text`,`image`]:[`text`],o=r.includes(`api.deepseek.com`);return De({id:e.modelId,name:`${e.modelId} (${n})`,api:this.form.protocol,provider:n,baseUrl:r.replace(/\/$/,``),reasoning:i,input:a,quickforgeHidden:e.visibleInSelectors?void 0:!0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0},contextWindow:Number(e.contextWindow)||A.contextWindow,maxTokens:Number(e.maxTokens)||A.maxTokens,headers:Object.keys(t).length>0?t:void 0,thinkingLevelMap:o&&i?{low:`high`,medium:`high`,high:`high`,xhigh:`max`}:void 0,compat:this.form.protocol===`openai-completions`?{supportsStore:!1,supportsDeveloperRole:!1,supportsReasoningEffort:i,supportsUsageInStreaming:!1,supportsStrictMode:!1,maxTokensField:`max_tokens`,...o&&i?{requiresReasoningContentOnAssistantMessages:!0,thinkingFormat:`deepseek`}:{}}:void 0})}async testConnection(){let e=this.form.baseUrl.trim(),t=this.form.models.find(e=>e.modelId.trim());if(!e||!t){this.testing=!1,this.testResult=`fail`,this.testError=O(`testRequiresFields`),this.requestUpdate();return}let n=this.buildHeadersFromRows(),r=this.buildModel(t,n);this.testing=!0,this.testResult=`idle`,this.testError=``,this.requestUpdate();try{let e=await(await fetch(`/api/models/test-connection`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({model:r,apiKey:this.form.apiKey.trim()})})).json().catch(()=>({}));e?.ok?(this.testResult=`ok`,this.testError=``):(this.testResult=`fail`,this.testError=e?.error||O(`connectionFailed`))}catch(e){this.testResult=`fail`,this.testError=e?.message||O(`connectionFailed`)}finally{this.testing=!1,this.requestUpdate()}}async saveModel(){let e=this.form.name.trim(),t=this.form.baseUrl.trim();if(!e||!t){N(O(`fillProviderBaseUrlModel`));return}let n=this.form.models.filter(e=>e.modelId.trim());if(n.length===0){N(O(`atLeastOneModel`));return}let r=n.map(e=>e.modelId.trim());if(new Set(r).size!==r.length){N(O(`duplicateModelId`));return}let i=this.buildHeadersFromRows(),a=n.map(e=>this.buildModel(e,i)),o=this.form.apiKey.trim(),s=this.editingProviderId?this.providers.find(e=>e.id===this.editingProviderId):void 0,c={id:this.editingProviderId??Ve(),name:e,type:this.form.protocol,baseUrl:a[0].baseUrl,apiKey:o||void 0,models:a};try{let e=C();await e.customProviders.set(c),s&&s.name!==c.name&&await e.providerKeys.delete(s.name),o?await e.providerKeys.set(c.name,o):await e.providerKeys.delete(c.name),Ue(),this.closeForm(),await this.loadProviders()}catch(e){T.error(`Failed to save custom model:`,e),N(O(`saveCustomModelFailed`))}}async deleteProvider(e){if(await k({description:O(`confirmDeleteProvider`,{name:e.name}),confirmLabel:O(`confirmDelete`),cancelLabel:O(`cancel`),variant:`destructive`}))try{let t=C();await t.customProviders.delete(e.id),await t.providerKeys.delete(e.name),Ue(),await this.loadProviders()}catch(e){T.error(`Failed to delete custom provider:`,e),N(O(`deleteFailed`))}}renderProvider(e){let t=e.models??[],n=t.length,r=e.type===`anthropic-messages`?`Anthropic Messages`:`OpenAI Compatible`;return x`
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/AgentProfilesPage-Dw9orPNt.js","assets/rolldown-runtime-DWdDZTNf.js","assets/index-DQBOm9gt.js","assets/pi-ai-Cr2ee4a0.js","assets/dist-yDHbi5ux.js","assets/pi-web-ui-DV5jKjSg.js","assets/lit-vendor-DvaQX_UQ.js","assets/css-utils-31qzCXsk.js","assets/icons-DM_qJ7VJ.js","assets/react-vendor-BpWW_Nvp.js","assets/skills-dialog-k9ycekIU.js","assets/logger-8REuLPGK.js","assets/model-display-label-CURwH0xM.js","assets/index-ps85guTs.css","assets/model-identity-CgA6_Pbm.js","assets/mcp-servers-dialog-CwHp0K4q.js","assets/PluginsPage-Dj1bmsEf.js","assets/plugin-api-BrdQeM4B.js","assets/ScheduledTasksPage-C9lOTi75.js","assets/ShareLinksSettingsPage-CH_t33A3.js","assets/CloudAccountSettingsPage-CDkKN1Sz.js"])))=>i.map(i=>d[i]);
2
+ import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{$ as t,Bt as n,F as r,Gt as i,Ht as a,Jt as o,Kt as s,Lt as c,Mt as ee,Rt as l,St as u,T as d,X as f,_t as p,b as te,h as m,p as ne,u as h,v as g,vt as _,wt as v,zt as y}from"./icons-DM_qJ7VJ.js";import{n as b,r as re}from"./react-vendor-BpWW_Nvp.js";import{c as ie,d as ae,f as oe,l as se,p as x,u as ce}from"./lit-vendor-DvaQX_UQ.js";import{m as S,x as C}from"./pi-web-ui-DV5jKjSg.js";import{J as w}from"./pi-ai-Cr2ee4a0.js";import{t as T}from"./logger-8REuLPGK.js";import{n as le,t as ue}from"./model-display-label-CURwH0xM.js";import{An as E,Ct as de,Dn as fe,J as pe,Mn as me,Mt as he,Nn as D,Nt as ge,Pn as O,St as _e,Tt as k,U as ve,X as ye,_n as be,a as xe,c as Se,cn as A,dn as Ce,dt as we,ft as Te,gn as Ee,gt as j,hn as De,ht as M,i as Oe,jn as ke,jt as Ae,kn as je,l as Me,ln as Ne,lt as Pe,mn as Fe,mt as Ie,pn as Le,pt as Re,s as ze,ut as Be,vn as Ve,vt as He,wt as N,xn as Ue,xt as We}from"./index-DQBOm9gt.js";var P=e(o(),1),Ge={openai:{name:`OpenAI`,baseUrl:`https://api.openai.com/v1`,protocol:`openai-completions`,modelId:`gpt-4o`,supportsImages:!0},deepseek:{name:`DeepSeek`,baseUrl:`https://api.deepseek.com/v1`,protocol:`openai-completions`,modelId:`deepseek-chat`},glm:{name:`Zhipu GLM`,baseUrl:`https://open.bigmodel.cn/api/paas/v4`,protocol:`openai-completions`,modelId:`glm-4-plus`},ollama:{name:`Ollama`,baseUrl:`http://localhost:11434/v1`,protocol:`openai-completions`,modelId:`llama3.1`},litellm:{name:A.name,baseUrl:A.baseUrl,protocol:`openai-completions`,modelId:A.modelId,supportsImages:A.supportsImages}},Ke=[{key:`openai`,label:O(`presetOpenai`)},{key:`deepseek`,label:O(`presetDeepseek`)},{key:`glm`,label:O(`presetGlm`)},{key:`ollama`,label:O(`presetOllama`)},{key:`litellm`,label:O(`presetLitellm`)},{key:`custom`,label:O(`presetCustom`)}],F=()=>({modelId:``,contextWindow:A.contextWindow,maxTokens:A.maxTokens,reasoning:!0,supportsImages:!1,visibleInSelectors:!0,open:!1}),I=()=>({name:A.name,baseUrl:A.baseUrl,apiKey:``,headerRows:[],protocol:`openai-completions`,models:[F()]}),qe=class extends S{providers=[];form=I();editingProviderId;formOpen=!1;loading=!0;apiKeyVisible=!1;advancedOpen=!1;activePreset=``;testing=!1;testResult=`idle`;testError=``;autoEditProviderName=null;async connectedCallback(){if(super.connectedCallback(),await this.loadProviders(),this.autoEditProviderName){let e=this.providers.find(e=>e.name===this.autoEditProviderName);e&&await this.openEditForm(e),this.autoEditProviderName=null}}getTabName(){return O(`customModels`)}async loadProviders(){this.loading=!0,this.requestUpdate();try{this.providers=await C().customProviders.getAll()}catch(e){T.error(`Failed to load custom providers:`,e),this.providers=[]}finally{this.loading=!1,this.requestUpdate()}}resetTestState(){this.testing=!1,this.testResult=`idle`,this.testError=``}openAddForm(){this.editingProviderId=void 0,this.form=I(),this.apiKeyVisible=!1,this.advancedOpen=!1,this.activePreset=``,this.resetTestState(),this.formOpen=!0,this.requestUpdate()}async openEditForm(e){let t=await C().providerKeys.get(e.name)??e.apiKey??``,n=e.models??[],r=n.length>0?n.map(e=>({modelId:e.id,contextWindow:e.contextWindow??A.contextWindow,maxTokens:e.maxTokens??A.maxTokens,reasoning:e.reasoning===!0,supportsImages:e.input?.includes(`image`)===!0,visibleInSelectors:e.quickforgeHidden!==!0,open:!1})):[F()],i=n[0]?.headers??{},a=Object.entries(i).map(([e,t])=>({key:e,value:String(t)}));this.editingProviderId=e.id,this.form={providerId:e.id,id:e.id,name:e.name,baseUrl:e.baseUrl,apiKey:t,headerRows:a,protocol:e.type===`anthropic-messages`?`anthropic-messages`:`openai-completions`,models:r},this.apiKeyVisible=!1,this.advancedOpen=a.length>0||e.type===`anthropic-messages`,this.activePreset=``,this.resetTestState(),this.formOpen=!0,this.requestUpdate()}closeForm(){this.formOpen=!1,this.editingProviderId=void 0,this.form=I(),this.apiKeyVisible=!1,this.advancedOpen=!1,this.activePreset=``,this.resetTestState(),this.requestUpdate()}toggleApiKeyVisibility(){this.apiKeyVisible=!this.apiKeyVisible,this.requestUpdate()}updateForm(e,t){this.form={...this.form,[e]:t},(e===`name`||e===`baseUrl`)&&(this.activePreset=``),this.resetTestState(),this.requestUpdate()}updateModelField(e,t,n){let r=this.form.models.map((r,i)=>i===e?{...r,[t]:n}:r);this.form={...this.form,models:r},t===`modelId`&&(this.activePreset=``,this.resetTestState()),this.requestUpdate()}addModelRow(){this.form={...this.form,models:[...this.form.models,F()]},this.requestUpdate()}removeModelRow(e){let t=this.form.models.filter((t,n)=>n!==e);this.form={...this.form,models:t},this.requestUpdate()}toggleModelExpanded(e){let t=this.form.models.map((t,n)=>n===e?{...t,open:!t.open}:t);this.form={...this.form,models:t},this.requestUpdate()}addHeaderRow(){this.form={...this.form,headerRows:[...this.form.headerRows,{key:``,value:``}]},this.requestUpdate()}updateHeaderRow(e,t,n){let r=this.form.headerRows.map((r,i)=>i===e?{...r,[t]:n}:r);this.form={...this.form,headerRows:r},this.requestUpdate()}removeHeaderRow(e){let t=this.form.headerRows.filter((t,n)=>n!==e);this.form={...this.form,headerRows:t},this.requestUpdate()}applyPreset(e){if(this.activePreset=e,e===`custom`)this.form={...this.form,name:``,baseUrl:``,protocol:`openai-completions`,models:[F()]};else{let t=Ge[e];this.form={...this.form,name:t.name,baseUrl:t.baseUrl,protocol:t.protocol,models:[{...F(),modelId:t.modelId,supportsImages:t.supportsImages===!0,open:!1}]}}this.resetTestState(),this.requestUpdate()}buildHeadersFromRows(){let e={};for(let t of this.form.headerRows){let n=t.key.trim(),r=t.value.trim();n&&r&&(e[n]=r)}return e}buildModel(e,t){let n=this.form.name.trim(),r=this.form.baseUrl.trim(),i=e.reasoning===!0,a=e.supportsImages===!0?[`text`,`image`]:[`text`],o=r.includes(`api.deepseek.com`);return De({id:e.modelId,name:`${e.modelId} (${n})`,api:this.form.protocol,provider:n,baseUrl:r.replace(/\/$/,``),reasoning:i,input:a,quickforgeHidden:e.visibleInSelectors?void 0:!0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0},contextWindow:Number(e.contextWindow)||A.contextWindow,maxTokens:Number(e.maxTokens)||A.maxTokens,headers:Object.keys(t).length>0?t:void 0,thinkingLevelMap:o&&i?{low:`high`,medium:`high`,high:`high`,xhigh:`max`}:void 0,compat:this.form.protocol===`openai-completions`?{supportsStore:!1,supportsDeveloperRole:!1,supportsReasoningEffort:i,supportsUsageInStreaming:!1,supportsStrictMode:!1,maxTokensField:`max_tokens`,...o&&i?{requiresReasoningContentOnAssistantMessages:!0,thinkingFormat:`deepseek`}:{}}:void 0})}async testConnection(){let e=this.form.baseUrl.trim(),t=this.form.models.find(e=>e.modelId.trim());if(!e||!t){this.testing=!1,this.testResult=`fail`,this.testError=O(`testRequiresFields`),this.requestUpdate();return}let n=this.buildHeadersFromRows(),r=this.buildModel(t,n);this.testing=!0,this.testResult=`idle`,this.testError=``,this.requestUpdate();try{let e=await(await fetch(`/api/models/test-connection`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({model:r,apiKey:this.form.apiKey.trim()})})).json().catch(()=>({}));e?.ok?(this.testResult=`ok`,this.testError=``):(this.testResult=`fail`,this.testError=e?.error||O(`connectionFailed`))}catch(e){this.testResult=`fail`,this.testError=e?.message||O(`connectionFailed`)}finally{this.testing=!1,this.requestUpdate()}}async saveModel(){let e=this.form.name.trim(),t=this.form.baseUrl.trim();if(!e||!t){N(O(`fillProviderBaseUrlModel`));return}let n=this.form.models.filter(e=>e.modelId.trim());if(n.length===0){N(O(`atLeastOneModel`));return}let r=n.map(e=>e.modelId.trim());if(new Set(r).size!==r.length){N(O(`duplicateModelId`));return}let i=this.buildHeadersFromRows(),a=n.map(e=>this.buildModel(e,i)),o=this.form.apiKey.trim(),s=this.editingProviderId?this.providers.find(e=>e.id===this.editingProviderId):void 0,c={id:this.editingProviderId??Ve(),name:e,type:this.form.protocol,baseUrl:a[0].baseUrl,apiKey:o||void 0,models:a};try{let e=C();await e.customProviders.set(c),s&&s.name!==c.name&&await e.providerKeys.delete(s.name),o?await e.providerKeys.set(c.name,o):await e.providerKeys.delete(c.name),Ue(),this.closeForm(),await this.loadProviders()}catch(e){T.error(`Failed to save custom model:`,e),N(O(`saveCustomModelFailed`))}}async deleteProvider(e){if(await k({description:O(`confirmDeleteProvider`,{name:e.name}),confirmLabel:O(`confirmDelete`),cancelLabel:O(`cancel`),variant:`destructive`}))try{let t=C();await t.customProviders.delete(e.id),await t.providerKeys.delete(e.name),Ue(),await this.loadProviders()}catch(e){T.error(`Failed to delete custom provider:`,e),N(O(`deleteFailed`))}}renderProvider(e){let t=e.models??[],n=t.length,r=e.type===`anthropic-messages`?`Anthropic Messages`:`OpenAI Compatible`;return x`
3
3
  <div class="quickforge-settings-list-item">
4
4
  <div class="quickforge-settings-list-item-main">
5
5
  <div class="flex min-w-0 items-start gap-3">
@@ -1693,4 +1693,4 @@ import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{$ as t,Bt as n,F as r,
1693
1693
  ${this.message?x`<div class="quickforge-settings-message">${this.message}</div>`:null}
1694
1694
  ${this.error?x`<div class="quickforge-settings-alert">${this.error}</div>`:null}
1695
1695
  </div>
1696
- `}},un=`quickforge-channels-settings-tab`;customElements.get(un)||customElements.define(un,ln);function dn(){return document.createElement(un)}var fn=re(),X=b(),pn=(0,P.lazy)(()=>w(()=>import(`./AgentProfilesPage-BSM5w3bn.js`).then(e=>({default:e.AgentProfilesPage})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14]))),mn=(0,P.lazy)(()=>w(()=>import(`./mcp-servers-dialog-BG4b67ea.js`).then(e=>({default:e.McpServersPanel})),__vite__mapDeps([15,1,2,3,4,5,6,7,8,9,10,11,12,13]))),hn=(0,P.lazy)(()=>w(()=>import(`./skills-dialog-DIzZvQqW.js`).then(e=>e.n).then(e=>({default:e.SkillsManagerPanel})),__vite__mapDeps([10,1,2,3,4,5,6,7,8,9,11,12,13]))),gn=(0,P.lazy)(()=>w(()=>import(`./PluginsPage-mJkTmVVV.js`).then(e=>({default:e.PluginsPage})),__vite__mapDeps([16,1,2,3,4,5,6,7,8,9,10,11,12,13,17]))),_n=(0,P.lazy)(()=>w(()=>import(`./ScheduledTasksPage-DJj_NLm9.js`).then(e=>({default:e.ScheduledTasksPage})),__vite__mapDeps([18,1,2,3,4,5,6,7,8,9,10,11,12,13,14]))),vn=(0,P.lazy)(()=>w(()=>import(`./ShareLinksSettingsPage-DjFq_Lnb.js`).then(e=>({default:e.ShareLinksSettingsPage})),__vite__mapDeps([19,1,2,3,4,5,6,7,8,9,10,11,12,13]))),yn=(0,P.lazy)(()=>w(()=>import(`./CloudAccountSettingsPage-BJMrfgy9.js`).then(e=>({default:e.CloudAccountSettingsPage})),__vite__mapDeps([20,1,2,3,4,5,6,7,8,9,10,11,12,13]))),bn=class extends S{tabName=``;renderReact;root;getTabName(){return this.tabName}connectedCallback(){super.connectedCallback(),this.updateComplete.then(()=>this.mountReact())}disconnectedCallback(){this.root?.unmount(),this.root=void 0,super.disconnectedCallback()}render(){return x`<div class="quickforge-react-settings-tab h-full min-h-0"></div>`}mountReact(){let e=this.querySelector(`.quickforge-react-settings-tab`);!e||!this.renderReact||(this.root??=(0,fn.createRoot)(e),this.root.render(this.renderReact()))}},xn=`quickforge-react-settings-tab`;customElements.get(xn)||customElements.define(xn,bn);function Z(e,t){let n=document.createElement(xn);return n.tabName=e,n.renderReact=t,n}function Q({children:e}){return(0,X.jsx)(`div`,{className:`quickforge-settings-stack h-full min-h-[30rem]`,children:(0,X.jsx)(P.Suspense,{fallback:(0,X.jsx)(`div`,{className:`quickforge-settings-note`,children:O(`loading`)}),children:e})})}function Sn(e){window.dispatchEvent(new CustomEvent(`quickforge:open-session-from-settings`,{detail:{sessionId:e}}))}function Cn(){return Z(O(`agentsTab`),()=>(0,X.jsx)(Q,{children:(0,X.jsx)(pn,{})}))}function wn(){return Z(O(`skills`),()=>(0,X.jsx)(Q,{children:(0,X.jsx)(hn,{active:!0,scope:`global`,embedded:!0,onSaved:()=>void 0})}))}function Tn(){return Z(O(`mcpServers`),()=>(0,X.jsx)(Q,{children:(0,X.jsx)(mn,{active:!0})}))}function En(){return Z(O(`plugins`),()=>(0,X.jsx)(Q,{children:(0,X.jsx)(gn,{})}))}function Dn(){return Z(O(`scheduledTasks`),()=>(0,X.jsx)(Q,{children:(0,X.jsx)(_n,{onOpenSession:Sn})}))}function On(){return Z(O(`cloudAccount`),()=>(0,X.jsx)(Q,{children:(0,X.jsx)(yn,{})}))}function kn(){return Z(O(`shareLinks`),()=>(0,X.jsx)(Q,{children:(0,X.jsx)(vn,{})}))}function An(e){let t=[{key:`appearance`,tab:Ze(),getDescription:()=>O(`appearanceDescription`)},{key:`cloudAccount`,tab:On(),getDescription:()=>O(`cloudAccountDescription`)},{key:`defaults`,tab:_t(),getDescription:()=>O(`defaultOptionsDescription`)},{key:`memory`,tab:wt(),getDescription:()=>O(`memoryDescription`)},{key:`customModels`,tab:Je(e),getDescription:()=>O(`customModelsDescription`)},{key:`agents`,tab:Cn(),getDescription:()=>O(`agentsDescription`)},{key:`skills`,tab:wn(),getDescription:()=>O(`globalSkillsDescription`)},{key:`mcp`,tab:Tn(),getDescription:void 0},{key:`plugins`,tab:En(),getDescription:()=>O(`pluginsDescription`)},{key:`scheduledTasks`,tab:Dn(),getDescription:()=>O(`scheduledTasksDescription`)},{key:`projectCommands`,tab:on(),getDescription:()=>O(`projectCommandsDescription`)},{key:`backup`,tab:Pt(),getDescription:()=>O(`backupRestoreDescription`)},{key:`archivedConversations`,tab:zt(),getDescription:()=>O(`archivedConversationsDescription`)},{key:`shareLinks`,tab:kn(),getDescription:()=>O(`shareLinksDescription`)},{key:`channels`,tab:dn(),getDescription:()=>O(`channelsDescription`)},{key:`lanAccess`,tab:Gt(),getDescription:()=>O(`lanAccessDescription`)},{key:`about`,tab:nn(),getDescription:()=>O(`aboutQuickForgeDescription`)}];return{items:[...t],tabs:t.map(e=>e.tab),indexOf:e=>t.findIndex(t=>t.key===e)}}var $={appearance:r,cloudAccount:u,defaults:ne,memory:l,customModels:_,agents:y,skills:n,mcp:g,plugins:d,scheduledTasks:c,projectCommands:h,backup:v,archivedConversations:s,shareLinks:f,channels:m,lanAccess:p,about:t};function jn({tab:e}){let t=(0,P.useRef)(null);return(0,P.useEffect)(()=>{let n=t.current;if(n)return n.replaceChildren(e),()=>{e.parentNode===n&&n.removeChild(e)}},[e]),(0,X.jsx)(`div`,{ref:t,className:`quickforge-settings-tab-host min-h-0 flex-1`})}function Mn({initialTab:e,customProvider:t,onBack:n}){let r=(0,P.useMemo)(()=>An(t),[t]),o=Math.max(0,r.indexOf(e)),[s,c]=(0,P.useState)(),[l,u]=(0,P.useState)(null),d=s??o,[f,p]=(0,P.useState)(``),m=f.trim().toLowerCase(),h=(0,P.useMemo)(()=>r.items.map((e,t)=>({item:e,index:t})).filter(({item:e})=>m?[e.key,e.tab.getTabName(),e.getDescription?.()??``].join(` `).toLowerCase().includes(m):!0),[r.items,m]),g=(0,P.useMemo)(()=>{if(!m)return d;let e=h[0];return e?h.some(({index:e})=>e===d)?d:e.index:d},[d,h,m]),_=r.items[g]??r.items[0],v=_?.getDescription?.(),y=_?$[_.key]:void 0,b=(0,P.useRef)(null),[re,ie]=(0,P.useState)(!1);return(0,P.useEffect)(()=>{b.current?.scrollTo({top:0})},[g,l]),(0,X.jsxs)(`div`,{className:`flex h-screen min-h-0 supports-[height:100dvh]:h-dvh bg-[var(--quickforge-sidebar-bg)] text-foreground`,children:[(0,X.jsxs)(`aside`,{className:`relative z-10 hidden w-80 shrink-0 overflow-hidden bg-[var(--quickforge-sidebar-bg)] md:flex md:min-h-0 md:flex-col`,children:[(0,X.jsxs)(`div`,{className:`shrink-0 px-3 pb-2 pt-3`,children:[(0,X.jsxs)(`button`,{type:`button`,className:`group relative flex w-full items-center gap-2 overflow-hidden rounded-lg px-2 py-1.5 text-left text-muted-foreground/72 transition-[background-color,color,box-shadow] duration-160 ease-out hover:bg-[var(--quickforge-sidebar-hover-bg)] hover:text-foreground/86 hover:shadow-[0_8px_20px_-18px_rgb(15_23_42_/_0.35)]`,onClick:n,"aria-label":`返回工作区`,children:[(0,X.jsx)(`span`,{className:`inline-flex size-6 shrink-0 items-center justify-center rounded-full text-muted-foreground/55 transition-colors group-hover:text-foreground/70`,children:(0,X.jsx)(i,{className:`size-4`})}),(0,X.jsx)(`span`,{className:`truncate text-sm leading-5`,children:`返回工作区`})]}),(0,X.jsxs)(`div`,{className:`quickforge-settings-inline-field mt-3`,children:[(0,X.jsx)(te,{className:`pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground/60`,"aria-hidden":`true`}),(0,X.jsx)(`input`,{value:f,onChange:e=>p(e.target.value),placeholder:O(`searchSettings`),"aria-label":O(`searchSettings`),className:`quickforge-settings-input`})]})]}),(0,X.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-3 pb-4 pt-4`,children:(0,X.jsxs)(`nav`,{className:`space-y-1`,"aria-label":O(`settings`),children:[h.map(({item:e,index:t})=>{let n=t===g,r=$[e.key];return(0,X.jsxs)(`button`,{type:`button`,className:E(`group relative flex w-full items-center gap-2.5 overflow-hidden rounded-lg px-2 py-1.5 text-left text-sm leading-5 transition-[background-color,color,box-shadow] duration-160 ease-out`,n?`bg-[var(--quickforge-sidebar-active-bg)] font-medium text-foreground/92 shadow-[0_8px_22px_-20px_rgb(15_23_42_/_0.32)]`:`text-muted-foreground/76 hover:bg-[var(--quickforge-sidebar-hover-bg)] hover:text-foreground/90 hover:shadow-[0_8px_20px_-18px_rgb(15_23_42_/_0.35)]`),onClick:()=>c(t),"aria-current":n?`page`:void 0,children:[(0,X.jsx)(`span`,{className:E(`inline-flex size-5 shrink-0 items-center justify-center transition-colors`,n?`text-foreground/72`:`text-muted-foreground/52 group-hover:text-foreground/68`),children:(0,X.jsx)(r,{className:`size-4`,"aria-hidden":`true`})}),(0,X.jsx)(`span`,{className:`truncate`,children:e.tab.getTabName()})]},e.key)}),h.length===0?(0,X.jsx)(`div`,{className:`px-2 py-3 text-sm text-muted-foreground/70`,children:O(`noSettingsResults`)}):null]})})]}),(0,X.jsxs)(`main`,{className:`relative flex min-w-0 flex-1 flex-col bg-[var(--quickforge-main-bg)] md:overflow-hidden md:rounded-tl-2xl`,children:[(0,X.jsxs)(`header`,{className:`flex h-14 shrink-0 items-center gap-2 border-b-[0.5px] border-[color-mix(in_oklab,var(--border)_34%,transparent)] px-3 pr-4 md:px-5`,children:[(0,X.jsx)(je,{variant:`ghost`,size:`icon`,className:`md:hidden`,onClick:l===null?n:()=>u(null),"aria-label":l===null?`返回工作区`:`返回设置`,children:(0,X.jsx)(i,{className:`size-4`})}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:E(`flex min-w-0 items-center gap-2`,l===null?`md:hidden`:`hidden`),children:[(0,X.jsx)(ne,{className:`size-4 shrink-0 text-muted-foreground/65`,"aria-hidden":`true`}),(0,X.jsx)(`div`,{className:`min-w-0 truncate text-sm font-medium text-foreground/90`,children:O(`settings`)})]}),(0,X.jsxs)(`div`,{className:E(`flex min-w-0 items-center gap-2`,l===null&&`hidden md:flex`),children:[y?(0,X.jsx)(y,{className:`size-4 shrink-0 text-muted-foreground/65`,"aria-hidden":`true`}):null,(0,X.jsx)(`div`,{className:`min-w-0 truncate text-sm font-medium text-foreground/90`,children:_?.tab.getTabName()}),v?(0,X.jsx)(fe,{label:v}):null]})]})]}),(0,X.jsxs)(`div`,{className:E(`flex min-h-0 flex-1 flex-col md:hidden`,l!==null&&`hidden`),children:[(0,X.jsx)(`div`,{className:`shrink-0 border-b-[0.5px] border-[color-mix(in_oklab,var(--border)_30%,transparent)] px-3 py-2`,children:(0,X.jsxs)(`div`,{className:`quickforge-settings-inline-field`,children:[(0,X.jsx)(te,{className:`pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground/60`,"aria-hidden":`true`}),(0,X.jsx)(`input`,{value:f,onChange:e=>p(e.target.value),placeholder:O(`searchSettings`),"aria-label":O(`searchSettings`),className:`quickforge-settings-input`})]})}),(0,X.jsx)(`nav`,{className:`quickforge-settings-mobile-list`,"aria-label":O(`settings`),children:(0,X.jsxs)(`div`,{className:`quickforge-settings-mobile-list-card`,children:[h.map(({item:e,index:t})=>{let n=$[e.key];return(0,X.jsxs)(`button`,{type:`button`,className:`quickforge-settings-mobile-list-item`,onClick:()=>{c(t),u(t)},children:[(0,X.jsx)(`span`,{className:`quickforge-settings-mobile-list-icon`,children:(0,X.jsx)(n,{className:`size-4 shrink-0`,"aria-hidden":`true`})}),(0,X.jsx)(`span`,{className:`quickforge-settings-mobile-list-label`,children:e.tab.getTabName()}),(0,X.jsx)(ee,{className:`quickforge-settings-mobile-list-chevron size-4 shrink-0`,"aria-hidden":`true`})]},e.key)}),h.length===0?(0,X.jsx)(`div`,{className:`px-2 py-8 text-center text-sm text-muted-foreground/70`,children:O(`noSettingsResults`)}):null]})})]}),(0,X.jsx)(`section`,{ref:b,onScroll:()=>ie((b.current?.scrollTop??0)>160),className:E(`min-h-0 flex-1 overflow-y-auto px-4 py-5 md:px-8 md:py-7`,l===null&&`hidden md:block`),children:(0,X.jsx)(`div`,{className:`mx-auto flex min-h-full w-full max-w-5xl flex-col`,children:h.length===0?(0,X.jsx)(`div`,{className:`rounded-xl border border-dashed border-[color-mix(in_oklab,var(--border)_70%,transparent)] p-8 text-center text-sm text-muted-foreground/70`,children:O(`noSettingsResults`)}):_?(0,X.jsx)(jn,{tab:_.tab}):null})}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>b.current?.scrollTo({top:0,behavior:`smooth`}),"aria-label":`返回顶部`,className:E(`absolute bottom-5 right-4 z-20 flex size-9 items-center justify-center rounded-[10px] border-[0.5px] border-[color-mix(in_oklab,var(--border)_65%,transparent)] bg-[var(--background)] text-muted-foreground/85 shadow-[0_10px_24px_-16px_rgb(15_23_42_/_0.55)] transition-opacity duration-160 md:hidden`,re?`opacity-100`:`pointer-events-none opacity-0`,l===null&&`hidden`),children:(0,X.jsx)(a,{className:`size-4`})})]})]})}export{Mn as SettingsWorkspacePage};
1696
+ `}},un=`quickforge-channels-settings-tab`;customElements.get(un)||customElements.define(un,ln);function dn(){return document.createElement(un)}var fn=re(),X=b(),pn=(0,P.lazy)(()=>w(()=>import(`./AgentProfilesPage-Dw9orPNt.js`).then(e=>({default:e.AgentProfilesPage})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14]))),mn=(0,P.lazy)(()=>w(()=>import(`./mcp-servers-dialog-CwHp0K4q.js`).then(e=>({default:e.McpServersPanel})),__vite__mapDeps([15,1,2,3,4,5,6,7,8,9,10,11,12,13]))),hn=(0,P.lazy)(()=>w(()=>import(`./skills-dialog-k9ycekIU.js`).then(e=>e.n).then(e=>({default:e.SkillsManagerPanel})),__vite__mapDeps([10,1,2,3,4,5,6,7,8,9,11,12,13]))),gn=(0,P.lazy)(()=>w(()=>import(`./PluginsPage-Dj1bmsEf.js`).then(e=>({default:e.PluginsPage})),__vite__mapDeps([16,1,2,3,4,5,6,7,8,9,10,11,12,13,17]))),_n=(0,P.lazy)(()=>w(()=>import(`./ScheduledTasksPage-C9lOTi75.js`).then(e=>({default:e.ScheduledTasksPage})),__vite__mapDeps([18,1,2,3,4,5,6,7,8,9,10,11,12,13,14]))),vn=(0,P.lazy)(()=>w(()=>import(`./ShareLinksSettingsPage-CH_t33A3.js`).then(e=>({default:e.ShareLinksSettingsPage})),__vite__mapDeps([19,1,2,3,4,5,6,7,8,9,10,11,12,13]))),yn=(0,P.lazy)(()=>w(()=>import(`./CloudAccountSettingsPage-CDkKN1Sz.js`).then(e=>({default:e.CloudAccountSettingsPage})),__vite__mapDeps([20,1,2,3,4,5,6,7,8,9,10,11,12,13]))),bn=class extends S{tabName=``;renderReact;root;getTabName(){return this.tabName}connectedCallback(){super.connectedCallback(),this.updateComplete.then(()=>this.mountReact())}disconnectedCallback(){this.root?.unmount(),this.root=void 0,super.disconnectedCallback()}render(){return x`<div class="quickforge-react-settings-tab h-full min-h-0"></div>`}mountReact(){let e=this.querySelector(`.quickforge-react-settings-tab`);!e||!this.renderReact||(this.root??=(0,fn.createRoot)(e),this.root.render(this.renderReact()))}},xn=`quickforge-react-settings-tab`;customElements.get(xn)||customElements.define(xn,bn);function Z(e,t){let n=document.createElement(xn);return n.tabName=e,n.renderReact=t,n}function Q({children:e}){return(0,X.jsx)(`div`,{className:`quickforge-settings-stack h-full min-h-[30rem]`,children:(0,X.jsx)(P.Suspense,{fallback:(0,X.jsx)(`div`,{className:`quickforge-settings-note`,children:O(`loading`)}),children:e})})}function Sn(e){window.dispatchEvent(new CustomEvent(`quickforge:open-session-from-settings`,{detail:{sessionId:e}}))}function Cn(){return Z(O(`agentsTab`),()=>(0,X.jsx)(Q,{children:(0,X.jsx)(pn,{})}))}function wn(){return Z(O(`skills`),()=>(0,X.jsx)(Q,{children:(0,X.jsx)(hn,{active:!0,scope:`global`,embedded:!0,onSaved:()=>void 0})}))}function Tn(){return Z(O(`mcpServers`),()=>(0,X.jsx)(Q,{children:(0,X.jsx)(mn,{active:!0})}))}function En(){return Z(O(`plugins`),()=>(0,X.jsx)(Q,{children:(0,X.jsx)(gn,{})}))}function Dn(){return Z(O(`scheduledTasks`),()=>(0,X.jsx)(Q,{children:(0,X.jsx)(_n,{onOpenSession:Sn})}))}function On(){return Z(O(`cloudAccount`),()=>(0,X.jsx)(Q,{children:(0,X.jsx)(yn,{})}))}function kn(){return Z(O(`shareLinks`),()=>(0,X.jsx)(Q,{children:(0,X.jsx)(vn,{})}))}function An(e){let t=[{key:`appearance`,tab:Ze(),getDescription:()=>O(`appearanceDescription`)},{key:`cloudAccount`,tab:On(),getDescription:()=>O(`cloudAccountDescription`)},{key:`defaults`,tab:_t(),getDescription:()=>O(`defaultOptionsDescription`)},{key:`memory`,tab:wt(),getDescription:()=>O(`memoryDescription`)},{key:`customModels`,tab:Je(e),getDescription:()=>O(`customModelsDescription`)},{key:`agents`,tab:Cn(),getDescription:()=>O(`agentsDescription`)},{key:`skills`,tab:wn(),getDescription:()=>O(`globalSkillsDescription`)},{key:`mcp`,tab:Tn(),getDescription:void 0},{key:`plugins`,tab:En(),getDescription:()=>O(`pluginsDescription`)},{key:`scheduledTasks`,tab:Dn(),getDescription:()=>O(`scheduledTasksDescription`)},{key:`projectCommands`,tab:on(),getDescription:()=>O(`projectCommandsDescription`)},{key:`backup`,tab:Pt(),getDescription:()=>O(`backupRestoreDescription`)},{key:`archivedConversations`,tab:zt(),getDescription:()=>O(`archivedConversationsDescription`)},{key:`shareLinks`,tab:kn(),getDescription:()=>O(`shareLinksDescription`)},{key:`channels`,tab:dn(),getDescription:()=>O(`channelsDescription`)},{key:`lanAccess`,tab:Gt(),getDescription:()=>O(`lanAccessDescription`)},{key:`about`,tab:nn(),getDescription:()=>O(`aboutQuickForgeDescription`)}];return{items:[...t],tabs:t.map(e=>e.tab),indexOf:e=>t.findIndex(t=>t.key===e)}}var $={appearance:r,cloudAccount:u,defaults:ne,memory:l,customModels:_,agents:y,skills:n,mcp:g,plugins:d,scheduledTasks:c,projectCommands:h,backup:v,archivedConversations:s,shareLinks:f,channels:m,lanAccess:p,about:t};function jn({tab:e}){let t=(0,P.useRef)(null);return(0,P.useEffect)(()=>{let n=t.current;if(n)return n.replaceChildren(e),()=>{e.parentNode===n&&n.removeChild(e)}},[e]),(0,X.jsx)(`div`,{ref:t,className:`quickforge-settings-tab-host min-h-0 flex-1`})}function Mn({initialTab:e,customProvider:t,onBack:n}){let r=(0,P.useMemo)(()=>An(t),[t]),o=Math.max(0,r.indexOf(e)),[s,c]=(0,P.useState)(),[l,u]=(0,P.useState)(null),d=s??o,[f,p]=(0,P.useState)(``),m=f.trim().toLowerCase(),h=(0,P.useMemo)(()=>r.items.map((e,t)=>({item:e,index:t})).filter(({item:e})=>m?[e.key,e.tab.getTabName(),e.getDescription?.()??``].join(` `).toLowerCase().includes(m):!0),[r.items,m]),g=(0,P.useMemo)(()=>{if(!m)return d;let e=h[0];return e?h.some(({index:e})=>e===d)?d:e.index:d},[d,h,m]),_=r.items[g]??r.items[0],v=_?.getDescription?.(),y=_?$[_.key]:void 0,b=(0,P.useRef)(null),[re,ie]=(0,P.useState)(!1);return(0,P.useEffect)(()=>{b.current?.scrollTo({top:0})},[g,l]),(0,X.jsxs)(`div`,{className:`flex h-screen min-h-0 supports-[height:100dvh]:h-dvh bg-[var(--quickforge-sidebar-bg)] text-foreground`,children:[(0,X.jsxs)(`aside`,{className:`relative z-10 hidden w-80 shrink-0 overflow-hidden bg-[var(--quickforge-sidebar-bg)] md:flex md:min-h-0 md:flex-col`,children:[(0,X.jsxs)(`div`,{className:`shrink-0 px-3 pb-2 pt-3`,children:[(0,X.jsxs)(`button`,{type:`button`,className:`group relative flex w-full items-center gap-2 overflow-hidden rounded-lg px-2 py-1.5 text-left text-muted-foreground/72 transition-[background-color,color,box-shadow] duration-160 ease-out hover:bg-[var(--quickforge-sidebar-hover-bg)] hover:text-foreground/86 hover:shadow-[0_8px_20px_-18px_rgb(15_23_42_/_0.35)]`,onClick:n,"aria-label":`返回工作区`,children:[(0,X.jsx)(`span`,{className:`inline-flex size-6 shrink-0 items-center justify-center rounded-full text-muted-foreground/55 transition-colors group-hover:text-foreground/70`,children:(0,X.jsx)(i,{className:`size-4`})}),(0,X.jsx)(`span`,{className:`truncate text-sm leading-5`,children:`返回工作区`})]}),(0,X.jsxs)(`div`,{className:`quickforge-settings-inline-field mt-3`,children:[(0,X.jsx)(te,{className:`pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground/60`,"aria-hidden":`true`}),(0,X.jsx)(`input`,{value:f,onChange:e=>p(e.target.value),placeholder:O(`searchSettings`),"aria-label":O(`searchSettings`),className:`quickforge-settings-input`})]})]}),(0,X.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-3 pb-4 pt-4`,children:(0,X.jsxs)(`nav`,{className:`space-y-1`,"aria-label":O(`settings`),children:[h.map(({item:e,index:t})=>{let n=t===g,r=$[e.key];return(0,X.jsxs)(`button`,{type:`button`,className:E(`group relative flex w-full items-center gap-2.5 overflow-hidden rounded-lg px-2 py-1.5 text-left text-sm leading-5 transition-[background-color,color,box-shadow] duration-160 ease-out`,n?`bg-[var(--quickforge-sidebar-active-bg)] font-medium text-foreground/92 shadow-[0_8px_22px_-20px_rgb(15_23_42_/_0.32)]`:`text-muted-foreground/76 hover:bg-[var(--quickforge-sidebar-hover-bg)] hover:text-foreground/90 hover:shadow-[0_8px_20px_-18px_rgb(15_23_42_/_0.35)]`),onClick:()=>c(t),"aria-current":n?`page`:void 0,children:[(0,X.jsx)(`span`,{className:E(`inline-flex size-5 shrink-0 items-center justify-center transition-colors`,n?`text-foreground/72`:`text-muted-foreground/52 group-hover:text-foreground/68`),children:(0,X.jsx)(r,{className:`size-4`,"aria-hidden":`true`})}),(0,X.jsx)(`span`,{className:`truncate`,children:e.tab.getTabName()})]},e.key)}),h.length===0?(0,X.jsx)(`div`,{className:`px-2 py-3 text-sm text-muted-foreground/70`,children:O(`noSettingsResults`)}):null]})})]}),(0,X.jsxs)(`main`,{className:`relative flex min-w-0 flex-1 flex-col bg-[var(--quickforge-main-bg)] md:overflow-hidden md:rounded-tl-2xl`,children:[(0,X.jsxs)(`header`,{className:`flex h-14 shrink-0 items-center gap-2 border-b-[0.5px] border-[color-mix(in_oklab,var(--border)_34%,transparent)] px-3 pr-4 md:px-5`,children:[(0,X.jsx)(je,{variant:`ghost`,size:`icon`,className:`md:hidden`,onClick:l===null?n:()=>u(null),"aria-label":l===null?`返回工作区`:`返回设置`,children:(0,X.jsx)(i,{className:`size-4`})}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:E(`flex min-w-0 items-center gap-2`,l===null?`md:hidden`:`hidden`),children:[(0,X.jsx)(ne,{className:`size-4 shrink-0 text-muted-foreground/65`,"aria-hidden":`true`}),(0,X.jsx)(`div`,{className:`min-w-0 truncate text-sm font-medium text-foreground/90`,children:O(`settings`)})]}),(0,X.jsxs)(`div`,{className:E(`flex min-w-0 items-center gap-2`,l===null&&`hidden md:flex`),children:[y?(0,X.jsx)(y,{className:`size-4 shrink-0 text-muted-foreground/65`,"aria-hidden":`true`}):null,(0,X.jsx)(`div`,{className:`min-w-0 truncate text-sm font-medium text-foreground/90`,children:_?.tab.getTabName()}),v?(0,X.jsx)(fe,{label:v}):null]})]})]}),(0,X.jsxs)(`div`,{className:E(`flex min-h-0 flex-1 flex-col md:hidden`,l!==null&&`hidden`),children:[(0,X.jsx)(`div`,{className:`shrink-0 border-b-[0.5px] border-[color-mix(in_oklab,var(--border)_30%,transparent)] px-3 py-2`,children:(0,X.jsxs)(`div`,{className:`quickforge-settings-inline-field`,children:[(0,X.jsx)(te,{className:`pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground/60`,"aria-hidden":`true`}),(0,X.jsx)(`input`,{value:f,onChange:e=>p(e.target.value),placeholder:O(`searchSettings`),"aria-label":O(`searchSettings`),className:`quickforge-settings-input`})]})}),(0,X.jsx)(`nav`,{className:`quickforge-settings-mobile-list`,"aria-label":O(`settings`),children:(0,X.jsxs)(`div`,{className:`quickforge-settings-mobile-list-card`,children:[h.map(({item:e,index:t})=>{let n=$[e.key];return(0,X.jsxs)(`button`,{type:`button`,className:`quickforge-settings-mobile-list-item`,onClick:()=>{c(t),u(t)},children:[(0,X.jsx)(`span`,{className:`quickforge-settings-mobile-list-icon`,children:(0,X.jsx)(n,{className:`size-4 shrink-0`,"aria-hidden":`true`})}),(0,X.jsx)(`span`,{className:`quickforge-settings-mobile-list-label`,children:e.tab.getTabName()}),(0,X.jsx)(ee,{className:`quickforge-settings-mobile-list-chevron size-4 shrink-0`,"aria-hidden":`true`})]},e.key)}),h.length===0?(0,X.jsx)(`div`,{className:`px-2 py-8 text-center text-sm text-muted-foreground/70`,children:O(`noSettingsResults`)}):null]})})]}),(0,X.jsx)(`section`,{ref:b,onScroll:()=>ie((b.current?.scrollTop??0)>160),className:E(`min-h-0 flex-1 overflow-y-auto px-4 py-5 md:px-8 md:py-7`,l===null&&`hidden md:block`),children:(0,X.jsx)(`div`,{className:`mx-auto flex min-h-full w-full max-w-5xl flex-col`,children:h.length===0?(0,X.jsx)(`div`,{className:`rounded-xl border border-dashed border-[color-mix(in_oklab,var(--border)_70%,transparent)] p-8 text-center text-sm text-muted-foreground/70`,children:O(`noSettingsResults`)}):_?(0,X.jsx)(jn,{tab:_.tab}):null})}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>b.current?.scrollTo({top:0,behavior:`smooth`}),"aria-label":`返回顶部`,className:E(`absolute bottom-5 right-4 z-20 flex size-9 items-center justify-center rounded-[10px] border-[0.5px] border-[color-mix(in_oklab,var(--border)_65%,transparent)] bg-[var(--background)] text-muted-foreground/85 shadow-[0_10px_24px_-16px_rgb(15_23_42_/_0.55)] transition-opacity duration-160 md:hidden`,re?`opacity-100`:`pointer-events-none opacity-0`,l===null&&`hidden`),children:(0,X.jsx)(a,{className:`size-4`})})]})]})}export{Mn as SettingsWorkspacePage};
@@ -1 +1 @@
1
- import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{E as t,Jt as n,X as r,b as i,bt as a,ht as o,j as s,mt as c,s as l,w as u}from"./icons-DM_qJ7VJ.js";import{n as d}from"./react-vendor-BpWW_Nvp.js";import{D as f,Dt as p,E as m,Nn as h,Pn as g,Tt as _,_ as v,b as y,g as b,kn as x,v as S,w as C,x as w,y as T}from"./index-DFASc15l.js";var E=e(n(),1),D=d(),O=[{value:`1h`,hours:1},{value:`24h`,hours:24},{value:`7d`,hours:168},{value:`never`}];function k(e){return e.url||`${window.location.origin}/share/${encodeURIComponent(e.id)}`}function A(e){if(!e)return`-`;let t=new Date(e);return Number.isNaN(t.getTime())?`-`:t.toLocaleString(h())}function j(e){return g(e===`disabled`?`shareStatusDisabled`:e===`expired`?`shareStatusExpired`:`shareStatusActive`)}function M(e){return e===`disabled`?`quickforge-settings-badge-muted`:e===`expired`?`quickforge-settings-badge-warning`:`quickforge-settings-badge-success`}function N(e){let t=O.find(t=>t.value===e);return t&&`hours`in t?v(t.hours):void 0}function P({share:e,onClose:t,onSaved:n}){let[r,i]=(0,E.useState)(e.permission),[a,o]=(0,E.useState)(``),[s,c]=(0,E.useState)(!1),[d,f]=(0,E.useState)(e.allowCloudUsage===!0),[p,h]=(0,E.useState)(`keep`),[_,v]=(0,E.useState)(!1),[b,S]=(0,E.useState)(``),C=r===`operate`,w=s?!1:!!(e.hasPassword||a.trim()),T=async()=>{if(C&&!w){S(g(`operateRequiresPassword`));return}v(!0),S(``);try{let i=s?``:a?a.trim():void 0,o=p===`keep`?void 0:N(p);n((await m(e.id,{permission:r,password:i,expiresAt:o,allowCloudUsage:r===`operate`&&d})).share),t()}catch(e){S(e instanceof Error?e.message:g(`requestFailed`)),v(!1)}};return(0,D.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/45 p-4`,onMouseDown:e=>{e.target===e.currentTarget&&t()},children:(0,D.jsxs)(`div`,{className:`flex max-h-[85vh] w-full max-w-md flex-col overflow-hidden rounded-2xl border border-border bg-background shadow-quickforge`,onMouseDown:e=>e.stopPropagation(),children:[(0,D.jsxs)(`div`,{className:`shrink-0 border-b border-border px-5 py-4`,children:[(0,D.jsx)(`h2`,{className:`text-base font-semibold`,children:g(`editShareTitle`)}),(0,D.jsx)(`p`,{className:`mt-1 truncate text-sm text-muted-foreground`,children:e.titleSnapshot||g(`untitledConversation`)})]}),(0,D.jsxs)(`div`,{className:`min-h-0 flex-1 space-y-4 overflow-y-auto px-5 py-4`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`div`,{className:`mb-2 text-sm font-medium`,children:g(`sharePermissionTitle`)}),(0,D.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:[(0,D.jsxs)(`button`,{type:`button`,className:`rounded-xl border p-3 text-left text-sm ${r===`read`?`border-primary bg-primary/10`:`border-border`}`,onClick:()=>i(`read`),children:[(0,D.jsx)(`div`,{className:`font-medium`,children:g(`sharePermissionRead`)}),(0,D.jsx)(`div`,{className:`mt-1 text-xs text-muted-foreground`,children:g(`sharePermissionReadHint`)})]}),(0,D.jsxs)(`button`,{type:`button`,className:`rounded-xl border p-3 text-left text-sm ${r===`operate`?`border-red-400 bg-red-50 text-red-950`:`border-border`}`,onClick:()=>i(`operate`),children:[(0,D.jsx)(`div`,{className:`font-medium text-red-700`,children:g(`sharePermissionOperate`)}),(0,D.jsx)(`div`,{className:`mt-1 text-xs text-red-700`,children:g(`sharePermissionOperateHint`)})]})]})]}),r===`operate`?(0,D.jsxs)(`label`,{className:`flex items-start gap-2 rounded-xl border border-border bg-muted/20 p-3 text-xs font-medium`,children:[(0,D.jsx)(`input`,{type:`checkbox`,checked:d,onChange:e=>f(e.target.checked)}),(0,D.jsx)(`span`,{children:`允许该分享使用宿主机的 QuickForge Cloud 模型和额度。默认关闭。`})]}):null,(0,D.jsxs)(`div`,{className:`space-y-2`,children:[(0,D.jsx)(`label`,{className:`block text-sm font-medium`,children:g(`sharePasswordTitle`)}),(0,D.jsxs)(`div`,{className:`flex flex-col gap-3 sm:flex-row sm:items-center`,children:[(0,D.jsx)(`input`,{value:a,onChange:e=>o(e.target.value),disabled:s,className:`h-10 w-full min-w-0 rounded-md border border-input bg-background px-3 text-sm`,placeholder:e.hasPassword?g(`sharePasswordPlaceholderKeep`):g(`sharePasswordPlaceholderNone`),type:`text`,autoComplete:`new-password`}),(0,D.jsxs)(x,{variant:`outline`,className:`h-10 sm:shrink-0`,onClick:()=>{c(!1),o(y())},children:[(0,D.jsx)(u,{className:`mr-2 size-4`}),g(`generatePassword`)]})]}),s?(0,D.jsx)(`span`,{className:`block text-xs text-destructive`,children:g(`sharePasswordRemovalSelected`)}):(0,D.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:e.hasPassword?g(`sharePasswordEditHint`):g(`sharePasswordSetHint`)}),e.hasPassword&&!s?(0,D.jsxs)(x,{variant:`ghost`,size:`sm`,className:`h-8 text-destructive`,onClick:()=>{o(``),c(!0)},children:[(0,D.jsx)(l,{className:`mr-2 size-3.5`}),g(`removePassword`)]}):null]}),(0,D.jsxs)(`label`,{className:`block text-sm font-medium`,children:[g(`shareExpiresAt`),(0,D.jsxs)(`select`,{value:p,onChange:e=>h(e.target.value),className:`mt-2 h-10 w-full rounded-md border border-input bg-background px-3 text-sm`,children:[(0,D.jsx)(`option`,{value:`keep`,children:g(`keepCurrentExpiration`)}),(0,D.jsx)(`option`,{value:`1h`,children:g(`oneHour`)}),(0,D.jsx)(`option`,{value:`24h`,children:g(`twentyFourHours`)}),(0,D.jsx)(`option`,{value:`7d`,children:g(`sevenDays`)}),(0,D.jsx)(`option`,{value:`never`,children:g(`shareNeverExpires`)})]})]}),b?(0,D.jsx)(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive`,children:b}):null]}),(0,D.jsx)(`div`,{className:`shrink-0 border-t border-border px-5 py-4`,children:(0,D.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,D.jsx)(x,{variant:`outline`,onClick:t,disabled:_,children:g(`cancel`)}),(0,D.jsx)(x,{variant:r===`operate`?`destructive`:`default`,onClick:()=>void T(),disabled:_,children:g(`saveChanges`)})]})})]})})}function F({share:e,status:n,onClose:r,onAction:i}){let o=n===`active`;return(0,D.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-end justify-center bg-black/45 sm:items-center`,onMouseDown:e=>{e.target===e.currentTarget&&r()},children:(0,D.jsxs)(`div`,{className:`w-full max-w-md rounded-t-2xl border border-border bg-background p-4 pb-[max(1rem,env(safe-area-inset-bottom))] shadow-quickforge sm:rounded-2xl sm:pb-4`,role:`dialog`,"aria-modal":`true`,"aria-label":g(`manageShare`),children:[(0,D.jsx)(`div`,{className:`truncate px-1 text-sm font-medium text-foreground`,children:e.titleSnapshot||g(`untitledConversation`)}),(0,D.jsx)(`div`,{className:`mt-1 truncate px-1 font-mono text-xs text-muted-foreground`,title:k(e),children:k(e)}),(0,D.jsxs)(`div`,{className:`mt-3 space-y-1`,children:[(0,D.jsxs)(x,{variant:`ghost`,className:`w-full justify-start`,onClick:()=>i(`copy`),children:[(0,D.jsx)(a,{className:`mr-2 size-4`}),g(`copyShareLink`)]}),(0,D.jsxs)(x,{variant:`ghost`,className:`w-full justify-start`,disabled:!o,onClick:()=>i(`open`),children:[(0,D.jsx)(c,{className:`mr-2 size-4`}),g(`openShareLink`)]}),n===`active`?(0,D.jsxs)(x,{variant:`ghost`,className:`w-full justify-start`,onClick:()=>i(`edit`),children:[(0,D.jsx)(s,{className:`mr-2 size-4`}),g(`editShare`)]}):null,n===`active`?(0,D.jsxs)(x,{variant:`ghost`,className:`w-full justify-start`,onClick:()=>i(`disable`),children:[(0,D.jsx)(t,{className:`mr-2 size-4`}),g(`disableShare`)]}):(0,D.jsxs)(x,{variant:`ghost`,className:`w-full justify-start`,onClick:()=>i(`restore`),children:[(0,D.jsx)(u,{className:`mr-2 size-4`}),g(`restoreShare`)]}),(0,D.jsxs)(x,{variant:`ghost`,className:`w-full justify-start hover:text-destructive`,onClick:()=>i(`delete`),children:[(0,D.jsx)(l,{className:`mr-2 size-4`}),g(`deleteShare`)]})]}),(0,D.jsx)(x,{variant:`outline`,className:`mt-3 w-full`,onClick:r,children:g(`cancel`)})]})})}function I(){let[e,n]=(0,E.useState)([]),[d,m]=(0,E.useState)(!0),[h,v]=(0,E.useState)(``),[y,O]=(0,E.useState)(``),[I,L]=(0,E.useState)({}),[R,z]=(0,E.useState)(null),[B,V]=(0,E.useState)(null),[H,U]=(0,E.useState)(``),[W,G]=(0,E.useState)(``),ee=async(e=!0)=>{e&&m(!0),G(``);try{n((await w()).shares)}catch(e){G(e instanceof Error?e.message:g(`shareLinksLoadFailed`))}finally{e&&m(!1)}};(0,E.useEffect)(()=>{let e=!1;return w().then(t=>{e||n(t.shares)}).catch(t=>{e||G(t instanceof Error?t.message:g(`shareLinksLoadFailed`))}).finally(()=>{e||m(!1)}),()=>{e=!0}},[]);let K=(0,E.useMemo)(()=>{let t=y.trim().toLowerCase();return t?e.filter(e=>`${e.titleSnapshot||``} ${e.id} ${e.projectId||``}`.toLowerCase().includes(t)):e},[y,e]),q=e=>{n(t=>t.map(t=>t.id===e.id?{...t,...e}:t))},J=async(e,t,n)=>{if(!h){v(e),U(``),G(``);try{q((await t()).share),U(n)}catch(e){G(e instanceof Error?e.message:g(`requestFailed`))}finally{v(``)}}},Y=async e=>{try{await p(k(e)),U(g(`shareLinkCopied`)),G(``)}catch{G(g(`copyFailed`))}},X=async e=>{await _({description:g(`disableShareConfirm`,{title:e.titleSnapshot||e.id}),confirmLabel:g(`disableShare`),cancelLabel:g(`cancel`),variant:`destructive`})&&await J(e.id,()=>T(e.id),g(`shareDisabled`))},Z=async e=>{let t=I[e.id]||`24h`;await J(e.id,()=>C(e.id,N(t)),g(`shareRestored`))},te=async e=>{let t=I[e.id]||`24h`;await J(e.id,()=>f(e.id,N(t)),g(`shareExpirationUpdated`))},Q=async e=>{if(!(!await _({description:g(`deleteShareConfirm`,{title:e.titleSnapshot||e.id}),confirmLabel:g(`confirmDelete`),cancelLabel:g(`cancel`),variant:`destructive`})||h)){v(e.id),U(``),G(``);try{await S(e.id),n(t=>t.filter(t=>t.id!==e.id)),U(g(`shareDeleted`))}catch(e){G(e instanceof Error?e.message:g(`requestFailed`))}finally{v(``)}}},ne=(e,t)=>{V(null),t===`copy`&&Y(e),t===`open`&&window.open(k(e),`_blank`,`noopener,noreferrer`),t===`edit`&&z(e),t===`disable`&&X(e),t===`restore`&&Z(e),t===`delete`&&Q(e)},re=R?b(R):null,$=B?b(B):null;return(0,D.jsxs)(`div`,{className:`quickforge-settings-stack`,children:[(0,D.jsxs)(`div`,{className:`quickforge-settings-heading`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsxs)(`h2`,{className:`quickforge-settings-title`,children:[(0,D.jsx)(r,{className:`size-5`}),g(`shareLinks`)]}),(0,D.jsx)(`p`,{className:`quickforge-settings-row-description`,children:g(`shareLinksDescription`)})]}),(0,D.jsxs)(x,{variant:`outline`,size:`sm`,onClick:()=>void ee(),disabled:d||!!h,children:[(0,D.jsx)(u,{className:`mr-2 size-4 ${d?`animate-spin`:``}`}),g(`refresh`)]})]}),(0,D.jsxs)(`div`,{className:`quickforge-settings-section`,children:[(0,D.jsxs)(`div`,{className:`quickforge-settings-toolbar`,children:[(0,D.jsxs)(`div`,{className:`quickforge-settings-inline-field max-w-md`,children:[(0,D.jsx)(i,{className:`pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground/60`,"aria-hidden":`true`}),(0,D.jsx)(`input`,{value:y,onChange:e=>O(e.target.value),className:`quickforge-settings-input`,placeholder:g(`searchShareLinks`),"aria-label":g(`searchShareLinks`)})]}),(0,D.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:g(`shareLinksCount`,{count:K.length})})]}),H?(0,D.jsx)(`div`,{className:`quickforge-settings-note quickforge-share-links-message`,children:H}):null,W?(0,D.jsx)(`div`,{className:`quickforge-settings-error quickforge-share-links-message`,children:W}):null,d?(0,D.jsx)(`div`,{className:`p-6 text-center text-sm text-muted-foreground`,children:g(`loading`)}):K.length===0?(0,D.jsx)(`div`,{className:`p-8 text-center text-sm text-muted-foreground`,children:g(y?`noMatchingShareLinks`:`noShareLinks`)}):K.map(e=>{let n=b(e),r=h===e.id,i=n===`active`;return(0,D.jsxs)(`div`,{className:`quickforge-settings-list-item quickforge-share-link-item`,children:[(0,D.jsxs)(`div`,{className:`quickforge-settings-list-item-main`,children:[(0,D.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,D.jsx)(`div`,{className:`truncate text-sm font-medium text-foreground`,children:e.titleSnapshot||g(`untitledConversation`)}),(0,D.jsx)(`span`,{className:`quickforge-settings-badge ${M(n)}`,children:j(n)}),(0,D.jsx)(`span`,{className:`quickforge-settings-badge quickforge-settings-badge-info`,children:e.permission===`operate`?g(`sharePermissionOperate`):g(`sharePermissionRead`)}),e.hasPassword?(0,D.jsx)(`span`,{className:`quickforge-settings-badge quickforge-settings-badge-muted`,children:g(`sharePasswordProtected`)}):null]}),(0,D.jsx)(`div`,{className:`quickforge-share-link-url`,title:k(e),children:k(e)}),(0,D.jsxs)(`div`,{className:`quickforge-settings-meta text-xs text-muted-foreground`,children:[(0,D.jsxs)(`span`,{children:[g(`shareCreatedAt`),`: `,A(e.createdAt)]}),(0,D.jsx)(`span`,{children:`·`}),(0,D.jsxs)(`span`,{children:[g(`shareExpiresAt`),`: `,e.expiresAt?A(e.expiresAt):g(`shareNeverExpires`)]}),(0,D.jsx)(`span`,{children:`·`}),(0,D.jsx)(`span`,{children:g(`shareAccessCount`,{count:e.accessCount||0})}),e.lastAccessedAt?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`span`,{children:`·`}),(0,D.jsxs)(`span`,{children:[g(`shareLastAccessedAt`),`: `,A(e.lastAccessedAt)]})]}):null]})]}),(0,D.jsxs)(`div`,{className:`quickforge-settings-list-item-actions quickforge-share-link-actions`,children:[(0,D.jsxs)(`div`,{className:`hidden flex-wrap items-center justify-end gap-2 md:flex`,children:[n===`active`?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(`select`,{className:`quickforge-settings-select quickforge-share-expiration-select`,value:I[e.id]||`24h`,onChange:t=>L(n=>({...n,[e.id]:t.target.value})),"aria-label":g(`shareUpdateExpiration`),disabled:r,children:[(0,D.jsx)(`option`,{value:`1h`,children:g(`oneHour`)}),(0,D.jsx)(`option`,{value:`24h`,children:g(`twentyFourHours`)}),(0,D.jsx)(`option`,{value:`7d`,children:g(`sevenDays`)}),(0,D.jsx)(`option`,{value:`never`,children:g(`shareNeverExpires`)})]}),(0,D.jsx)(x,{variant:`outline`,size:`sm`,onClick:()=>void te(e),disabled:r,children:g(`updateShareExpiration`)})]}):null,(0,D.jsx)(x,{variant:`ghost`,size:`icon`,onClick:()=>void Y(e),"aria-label":g(`copyShareLink`),title:g(`copyShareLink`),children:(0,D.jsx)(a,{className:`size-4`})}),(0,D.jsx)(x,{variant:`ghost`,size:`icon`,onClick:()=>window.open(k(e),`_blank`,`noopener,noreferrer`),disabled:!i,"aria-label":g(`openShareLink`),title:g(`openShareLink`),children:(0,D.jsx)(c,{className:`size-4`})}),n===`active`?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(x,{variant:`outline`,size:`sm`,onClick:()=>z(e),disabled:r,children:[(0,D.jsx)(s,{className:`mr-2 size-4`}),g(`editShare`)]}),(0,D.jsxs)(x,{variant:`outline`,size:`sm`,onClick:()=>void X(e),disabled:r,children:[(0,D.jsx)(t,{className:`mr-2 size-4`}),g(`disableShare`)]})]}):(0,D.jsxs)(x,{variant:`outline`,size:`sm`,onClick:()=>void Z(e),disabled:r,children:[(0,D.jsx)(u,{className:`mr-2 size-4`}),g(`restoreShare`)]}),(0,D.jsx)(x,{variant:`ghost`,size:`icon`,className:`hover:text-destructive`,onClick:()=>void Q(e),disabled:r,"aria-label":g(`deleteShare`),title:g(`deleteShare`),children:(0,D.jsx)(l,{className:`size-4`})})]}),(0,D.jsxs)(x,{variant:`outline`,size:`sm`,className:`md:hidden`,onClick:()=>V(e),disabled:r,children:[(0,D.jsx)(o,{className:`mr-2 size-4`}),g(`manageShare`)]})]})]},e.id)})]}),R&&re===`active`?(0,D.jsx)(P,{share:R,onClose:()=>z(null),onSaved:e=>{q(e),U(g(`shareUpdated`)),G(``)}},R.id):null,B&&$?(0,D.jsx)(F,{share:B,status:$,onClose:()=>V(null),onAction:e=>ne(B,e)}):null]})}export{I as ShareLinksSettingsPage};
1
+ import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{E as t,Jt as n,X as r,b as i,bt as a,ht as o,j as s,mt as c,s as l,w as u}from"./icons-DM_qJ7VJ.js";import{n as d}from"./react-vendor-BpWW_Nvp.js";import{D as f,Dt as p,E as m,Nn as h,Pn as g,Tt as _,_ as v,b as y,g as b,kn as x,v as S,w as C,x as w,y as T}from"./index-DQBOm9gt.js";var E=e(n(),1),D=d(),O=[{value:`1h`,hours:1},{value:`24h`,hours:24},{value:`7d`,hours:168},{value:`never`}];function k(e){return e.url||`${window.location.origin}/share/${encodeURIComponent(e.id)}`}function A(e){if(!e)return`-`;let t=new Date(e);return Number.isNaN(t.getTime())?`-`:t.toLocaleString(h())}function j(e){return g(e===`disabled`?`shareStatusDisabled`:e===`expired`?`shareStatusExpired`:`shareStatusActive`)}function M(e){return e===`disabled`?`quickforge-settings-badge-muted`:e===`expired`?`quickforge-settings-badge-warning`:`quickforge-settings-badge-success`}function N(e){let t=O.find(t=>t.value===e);return t&&`hours`in t?v(t.hours):void 0}function P({share:e,onClose:t,onSaved:n}){let[r,i]=(0,E.useState)(e.permission),[a,o]=(0,E.useState)(``),[s,c]=(0,E.useState)(!1),[d,f]=(0,E.useState)(e.allowCloudUsage===!0),[p,h]=(0,E.useState)(`keep`),[_,v]=(0,E.useState)(!1),[b,S]=(0,E.useState)(``),C=r===`operate`,w=s?!1:!!(e.hasPassword||a.trim()),T=async()=>{if(C&&!w){S(g(`operateRequiresPassword`));return}v(!0),S(``);try{let i=s?``:a?a.trim():void 0,o=p===`keep`?void 0:N(p);n((await m(e.id,{permission:r,password:i,expiresAt:o,allowCloudUsage:r===`operate`&&d})).share),t()}catch(e){S(e instanceof Error?e.message:g(`requestFailed`)),v(!1)}};return(0,D.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/45 p-4`,onMouseDown:e=>{e.target===e.currentTarget&&t()},children:(0,D.jsxs)(`div`,{className:`flex max-h-[85vh] w-full max-w-md flex-col overflow-hidden rounded-2xl border border-border bg-background shadow-quickforge`,onMouseDown:e=>e.stopPropagation(),children:[(0,D.jsxs)(`div`,{className:`shrink-0 border-b border-border px-5 py-4`,children:[(0,D.jsx)(`h2`,{className:`text-base font-semibold`,children:g(`editShareTitle`)}),(0,D.jsx)(`p`,{className:`mt-1 truncate text-sm text-muted-foreground`,children:e.titleSnapshot||g(`untitledConversation`)})]}),(0,D.jsxs)(`div`,{className:`min-h-0 flex-1 space-y-4 overflow-y-auto px-5 py-4`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`div`,{className:`mb-2 text-sm font-medium`,children:g(`sharePermissionTitle`)}),(0,D.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:[(0,D.jsxs)(`button`,{type:`button`,className:`rounded-xl border p-3 text-left text-sm ${r===`read`?`border-primary bg-primary/10`:`border-border`}`,onClick:()=>i(`read`),children:[(0,D.jsx)(`div`,{className:`font-medium`,children:g(`sharePermissionRead`)}),(0,D.jsx)(`div`,{className:`mt-1 text-xs text-muted-foreground`,children:g(`sharePermissionReadHint`)})]}),(0,D.jsxs)(`button`,{type:`button`,className:`rounded-xl border p-3 text-left text-sm ${r===`operate`?`border-red-400 bg-red-50 text-red-950`:`border-border`}`,onClick:()=>i(`operate`),children:[(0,D.jsx)(`div`,{className:`font-medium text-red-700`,children:g(`sharePermissionOperate`)}),(0,D.jsx)(`div`,{className:`mt-1 text-xs text-red-700`,children:g(`sharePermissionOperateHint`)})]})]})]}),r===`operate`?(0,D.jsxs)(`label`,{className:`flex items-start gap-2 rounded-xl border border-border bg-muted/20 p-3 text-xs font-medium`,children:[(0,D.jsx)(`input`,{type:`checkbox`,checked:d,onChange:e=>f(e.target.checked)}),(0,D.jsx)(`span`,{children:`允许该分享使用宿主机的 QuickForge Cloud 模型和额度。默认关闭。`})]}):null,(0,D.jsxs)(`div`,{className:`space-y-2`,children:[(0,D.jsx)(`label`,{className:`block text-sm font-medium`,children:g(`sharePasswordTitle`)}),(0,D.jsxs)(`div`,{className:`flex flex-col gap-3 sm:flex-row sm:items-center`,children:[(0,D.jsx)(`input`,{value:a,onChange:e=>o(e.target.value),disabled:s,className:`h-10 w-full min-w-0 rounded-md border border-input bg-background px-3 text-sm`,placeholder:e.hasPassword?g(`sharePasswordPlaceholderKeep`):g(`sharePasswordPlaceholderNone`),type:`text`,autoComplete:`new-password`}),(0,D.jsxs)(x,{variant:`outline`,className:`h-10 sm:shrink-0`,onClick:()=>{c(!1),o(y())},children:[(0,D.jsx)(u,{className:`mr-2 size-4`}),g(`generatePassword`)]})]}),s?(0,D.jsx)(`span`,{className:`block text-xs text-destructive`,children:g(`sharePasswordRemovalSelected`)}):(0,D.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:e.hasPassword?g(`sharePasswordEditHint`):g(`sharePasswordSetHint`)}),e.hasPassword&&!s?(0,D.jsxs)(x,{variant:`ghost`,size:`sm`,className:`h-8 text-destructive`,onClick:()=>{o(``),c(!0)},children:[(0,D.jsx)(l,{className:`mr-2 size-3.5`}),g(`removePassword`)]}):null]}),(0,D.jsxs)(`label`,{className:`block text-sm font-medium`,children:[g(`shareExpiresAt`),(0,D.jsxs)(`select`,{value:p,onChange:e=>h(e.target.value),className:`mt-2 h-10 w-full rounded-md border border-input bg-background px-3 text-sm`,children:[(0,D.jsx)(`option`,{value:`keep`,children:g(`keepCurrentExpiration`)}),(0,D.jsx)(`option`,{value:`1h`,children:g(`oneHour`)}),(0,D.jsx)(`option`,{value:`24h`,children:g(`twentyFourHours`)}),(0,D.jsx)(`option`,{value:`7d`,children:g(`sevenDays`)}),(0,D.jsx)(`option`,{value:`never`,children:g(`shareNeverExpires`)})]})]}),b?(0,D.jsx)(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive`,children:b}):null]}),(0,D.jsx)(`div`,{className:`shrink-0 border-t border-border px-5 py-4`,children:(0,D.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,D.jsx)(x,{variant:`outline`,onClick:t,disabled:_,children:g(`cancel`)}),(0,D.jsx)(x,{variant:r===`operate`?`destructive`:`default`,onClick:()=>void T(),disabled:_,children:g(`saveChanges`)})]})})]})})}function F({share:e,status:n,onClose:r,onAction:i}){let o=n===`active`;return(0,D.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-end justify-center bg-black/45 sm:items-center`,onMouseDown:e=>{e.target===e.currentTarget&&r()},children:(0,D.jsxs)(`div`,{className:`w-full max-w-md rounded-t-2xl border border-border bg-background p-4 pb-[max(1rem,env(safe-area-inset-bottom))] shadow-quickforge sm:rounded-2xl sm:pb-4`,role:`dialog`,"aria-modal":`true`,"aria-label":g(`manageShare`),children:[(0,D.jsx)(`div`,{className:`truncate px-1 text-sm font-medium text-foreground`,children:e.titleSnapshot||g(`untitledConversation`)}),(0,D.jsx)(`div`,{className:`mt-1 truncate px-1 font-mono text-xs text-muted-foreground`,title:k(e),children:k(e)}),(0,D.jsxs)(`div`,{className:`mt-3 space-y-1`,children:[(0,D.jsxs)(x,{variant:`ghost`,className:`w-full justify-start`,onClick:()=>i(`copy`),children:[(0,D.jsx)(a,{className:`mr-2 size-4`}),g(`copyShareLink`)]}),(0,D.jsxs)(x,{variant:`ghost`,className:`w-full justify-start`,disabled:!o,onClick:()=>i(`open`),children:[(0,D.jsx)(c,{className:`mr-2 size-4`}),g(`openShareLink`)]}),n===`active`?(0,D.jsxs)(x,{variant:`ghost`,className:`w-full justify-start`,onClick:()=>i(`edit`),children:[(0,D.jsx)(s,{className:`mr-2 size-4`}),g(`editShare`)]}):null,n===`active`?(0,D.jsxs)(x,{variant:`ghost`,className:`w-full justify-start`,onClick:()=>i(`disable`),children:[(0,D.jsx)(t,{className:`mr-2 size-4`}),g(`disableShare`)]}):(0,D.jsxs)(x,{variant:`ghost`,className:`w-full justify-start`,onClick:()=>i(`restore`),children:[(0,D.jsx)(u,{className:`mr-2 size-4`}),g(`restoreShare`)]}),(0,D.jsxs)(x,{variant:`ghost`,className:`w-full justify-start hover:text-destructive`,onClick:()=>i(`delete`),children:[(0,D.jsx)(l,{className:`mr-2 size-4`}),g(`deleteShare`)]})]}),(0,D.jsx)(x,{variant:`outline`,className:`mt-3 w-full`,onClick:r,children:g(`cancel`)})]})})}function I(){let[e,n]=(0,E.useState)([]),[d,m]=(0,E.useState)(!0),[h,v]=(0,E.useState)(``),[y,O]=(0,E.useState)(``),[I,L]=(0,E.useState)({}),[R,z]=(0,E.useState)(null),[B,V]=(0,E.useState)(null),[H,U]=(0,E.useState)(``),[W,G]=(0,E.useState)(``),ee=async(e=!0)=>{e&&m(!0),G(``);try{n((await w()).shares)}catch(e){G(e instanceof Error?e.message:g(`shareLinksLoadFailed`))}finally{e&&m(!1)}};(0,E.useEffect)(()=>{let e=!1;return w().then(t=>{e||n(t.shares)}).catch(t=>{e||G(t instanceof Error?t.message:g(`shareLinksLoadFailed`))}).finally(()=>{e||m(!1)}),()=>{e=!0}},[]);let K=(0,E.useMemo)(()=>{let t=y.trim().toLowerCase();return t?e.filter(e=>`${e.titleSnapshot||``} ${e.id} ${e.projectId||``}`.toLowerCase().includes(t)):e},[y,e]),q=e=>{n(t=>t.map(t=>t.id===e.id?{...t,...e}:t))},J=async(e,t,n)=>{if(!h){v(e),U(``),G(``);try{q((await t()).share),U(n)}catch(e){G(e instanceof Error?e.message:g(`requestFailed`))}finally{v(``)}}},Y=async e=>{try{await p(k(e)),U(g(`shareLinkCopied`)),G(``)}catch{G(g(`copyFailed`))}},X=async e=>{await _({description:g(`disableShareConfirm`,{title:e.titleSnapshot||e.id}),confirmLabel:g(`disableShare`),cancelLabel:g(`cancel`),variant:`destructive`})&&await J(e.id,()=>T(e.id),g(`shareDisabled`))},Z=async e=>{let t=I[e.id]||`24h`;await J(e.id,()=>C(e.id,N(t)),g(`shareRestored`))},te=async e=>{let t=I[e.id]||`24h`;await J(e.id,()=>f(e.id,N(t)),g(`shareExpirationUpdated`))},Q=async e=>{if(!(!await _({description:g(`deleteShareConfirm`,{title:e.titleSnapshot||e.id}),confirmLabel:g(`confirmDelete`),cancelLabel:g(`cancel`),variant:`destructive`})||h)){v(e.id),U(``),G(``);try{await S(e.id),n(t=>t.filter(t=>t.id!==e.id)),U(g(`shareDeleted`))}catch(e){G(e instanceof Error?e.message:g(`requestFailed`))}finally{v(``)}}},ne=(e,t)=>{V(null),t===`copy`&&Y(e),t===`open`&&window.open(k(e),`_blank`,`noopener,noreferrer`),t===`edit`&&z(e),t===`disable`&&X(e),t===`restore`&&Z(e),t===`delete`&&Q(e)},re=R?b(R):null,$=B?b(B):null;return(0,D.jsxs)(`div`,{className:`quickforge-settings-stack`,children:[(0,D.jsxs)(`div`,{className:`quickforge-settings-heading`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsxs)(`h2`,{className:`quickforge-settings-title`,children:[(0,D.jsx)(r,{className:`size-5`}),g(`shareLinks`)]}),(0,D.jsx)(`p`,{className:`quickforge-settings-row-description`,children:g(`shareLinksDescription`)})]}),(0,D.jsxs)(x,{variant:`outline`,size:`sm`,onClick:()=>void ee(),disabled:d||!!h,children:[(0,D.jsx)(u,{className:`mr-2 size-4 ${d?`animate-spin`:``}`}),g(`refresh`)]})]}),(0,D.jsxs)(`div`,{className:`quickforge-settings-section`,children:[(0,D.jsxs)(`div`,{className:`quickforge-settings-toolbar`,children:[(0,D.jsxs)(`div`,{className:`quickforge-settings-inline-field max-w-md`,children:[(0,D.jsx)(i,{className:`pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground/60`,"aria-hidden":`true`}),(0,D.jsx)(`input`,{value:y,onChange:e=>O(e.target.value),className:`quickforge-settings-input`,placeholder:g(`searchShareLinks`),"aria-label":g(`searchShareLinks`)})]}),(0,D.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:g(`shareLinksCount`,{count:K.length})})]}),H?(0,D.jsx)(`div`,{className:`quickforge-settings-note quickforge-share-links-message`,children:H}):null,W?(0,D.jsx)(`div`,{className:`quickforge-settings-error quickforge-share-links-message`,children:W}):null,d?(0,D.jsx)(`div`,{className:`p-6 text-center text-sm text-muted-foreground`,children:g(`loading`)}):K.length===0?(0,D.jsx)(`div`,{className:`p-8 text-center text-sm text-muted-foreground`,children:g(y?`noMatchingShareLinks`:`noShareLinks`)}):K.map(e=>{let n=b(e),r=h===e.id,i=n===`active`;return(0,D.jsxs)(`div`,{className:`quickforge-settings-list-item quickforge-share-link-item`,children:[(0,D.jsxs)(`div`,{className:`quickforge-settings-list-item-main`,children:[(0,D.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,D.jsx)(`div`,{className:`truncate text-sm font-medium text-foreground`,children:e.titleSnapshot||g(`untitledConversation`)}),(0,D.jsx)(`span`,{className:`quickforge-settings-badge ${M(n)}`,children:j(n)}),(0,D.jsx)(`span`,{className:`quickforge-settings-badge quickforge-settings-badge-info`,children:e.permission===`operate`?g(`sharePermissionOperate`):g(`sharePermissionRead`)}),e.hasPassword?(0,D.jsx)(`span`,{className:`quickforge-settings-badge quickforge-settings-badge-muted`,children:g(`sharePasswordProtected`)}):null]}),(0,D.jsx)(`div`,{className:`quickforge-share-link-url`,title:k(e),children:k(e)}),(0,D.jsxs)(`div`,{className:`quickforge-settings-meta text-xs text-muted-foreground`,children:[(0,D.jsxs)(`span`,{children:[g(`shareCreatedAt`),`: `,A(e.createdAt)]}),(0,D.jsx)(`span`,{children:`·`}),(0,D.jsxs)(`span`,{children:[g(`shareExpiresAt`),`: `,e.expiresAt?A(e.expiresAt):g(`shareNeverExpires`)]}),(0,D.jsx)(`span`,{children:`·`}),(0,D.jsx)(`span`,{children:g(`shareAccessCount`,{count:e.accessCount||0})}),e.lastAccessedAt?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`span`,{children:`·`}),(0,D.jsxs)(`span`,{children:[g(`shareLastAccessedAt`),`: `,A(e.lastAccessedAt)]})]}):null]})]}),(0,D.jsxs)(`div`,{className:`quickforge-settings-list-item-actions quickforge-share-link-actions`,children:[(0,D.jsxs)(`div`,{className:`hidden flex-wrap items-center justify-end gap-2 md:flex`,children:[n===`active`?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(`select`,{className:`quickforge-settings-select quickforge-share-expiration-select`,value:I[e.id]||`24h`,onChange:t=>L(n=>({...n,[e.id]:t.target.value})),"aria-label":g(`shareUpdateExpiration`),disabled:r,children:[(0,D.jsx)(`option`,{value:`1h`,children:g(`oneHour`)}),(0,D.jsx)(`option`,{value:`24h`,children:g(`twentyFourHours`)}),(0,D.jsx)(`option`,{value:`7d`,children:g(`sevenDays`)}),(0,D.jsx)(`option`,{value:`never`,children:g(`shareNeverExpires`)})]}),(0,D.jsx)(x,{variant:`outline`,size:`sm`,onClick:()=>void te(e),disabled:r,children:g(`updateShareExpiration`)})]}):null,(0,D.jsx)(x,{variant:`ghost`,size:`icon`,onClick:()=>void Y(e),"aria-label":g(`copyShareLink`),title:g(`copyShareLink`),children:(0,D.jsx)(a,{className:`size-4`})}),(0,D.jsx)(x,{variant:`ghost`,size:`icon`,onClick:()=>window.open(k(e),`_blank`,`noopener,noreferrer`),disabled:!i,"aria-label":g(`openShareLink`),title:g(`openShareLink`),children:(0,D.jsx)(c,{className:`size-4`})}),n===`active`?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(x,{variant:`outline`,size:`sm`,onClick:()=>z(e),disabled:r,children:[(0,D.jsx)(s,{className:`mr-2 size-4`}),g(`editShare`)]}),(0,D.jsxs)(x,{variant:`outline`,size:`sm`,onClick:()=>void X(e),disabled:r,children:[(0,D.jsx)(t,{className:`mr-2 size-4`}),g(`disableShare`)]})]}):(0,D.jsxs)(x,{variant:`outline`,size:`sm`,onClick:()=>void Z(e),disabled:r,children:[(0,D.jsx)(u,{className:`mr-2 size-4`}),g(`restoreShare`)]}),(0,D.jsx)(x,{variant:`ghost`,size:`icon`,className:`hover:text-destructive`,onClick:()=>void Q(e),disabled:r,"aria-label":g(`deleteShare`),title:g(`deleteShare`),children:(0,D.jsx)(l,{className:`size-4`})})]}),(0,D.jsxs)(x,{variant:`outline`,size:`sm`,className:`md:hidden`,onClick:()=>V(e),disabled:r,children:[(0,D.jsx)(o,{className:`mr-2 size-4`}),g(`manageShare`)]})]})]},e.id)})]}),R&&re===`active`?(0,D.jsx)(P,{share:R,onClose:()=>z(null),onSaved:e=>{q(e),U(g(`shareUpdated`)),G(``)}},R.id):null,B&&$?(0,D.jsx)(F,{share:B,status:$,onClose:()=>V(null),onAction:e=>ne(B,e)}):null]})}export{I as ShareLinksSettingsPage};
@@ -1 +1 @@
1
- import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{Jt as t,bt as n,o as r}from"./icons-DM_qJ7VJ.js";import{n as i}from"./react-vendor-BpWW_Nvp.js";import{S as a,b as o,d as s,f as c,p as l,u}from"./pi-web-ui-DV5jKjSg.js";import{U as d}from"./pi-ai-Cr2ee4a0.js";import{t as f}from"./logger-8REuLPGK.js";import{r as p}from"./model-display-label-CURwH0xM.js";import{An as m,C as h,Dt as g,Ot as _,Pn as v,S as y,Sn as b,T as x,an as S,kn as C,kt as w,ln as T,on as E,sn as D,st as O,wt as k,yn as A}from"./index-DFASc15l.js";import{t as j}from"./model-identity-CgA6_Pbm.js";import{ChatPanelHost as M}from"./ChatPanelHost-cd80S4EX.js";var N=e(t(),1),P=`quickforgeClientMessageId`;function F(e){let t=e?.metadata;return t&&typeof t==`object`&&!Array.isArray(t)?t:void 0}function I(e){let t=F(e)?.[P];return typeof t==`string`&&t?t:void 0}function L(){return`qfcm_${typeof crypto<`u`&&typeof crypto.randomUUID==`function`?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`}`}function R(e){let t=I(e);if(t)return{message:e,clientMessageId:t};let n=L();return{message:{...e,metadata:{...F(e),[P]:n}},clientMessageId:n}}function z(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 B(e,t){if(!e||!t||e.role!==t.role)return!1;let n=I(e),r=I(t);return n&&r?n===r:z(e.content)===z(t.content)}async function V(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){let e=r?.code===`GENERATION_ALREADY_RUNNING`?v(`generationAlreadyRunning`):r?.error||`Request failed: ${n.status}`;throw Error(e)}return r}var H=class e{state;streamFn=d;getApiKey;sessionId;shareId;permission;harness=`quickforge`;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}=R(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 V(`/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`)return;let t=this.state.model;this.state.model=e;try{let t=await V(`/api/shared/${encodeURIComponent(this.shareId)}/model`,{method:`POST`,body:JSON.stringify({modelRef:p(e),model:e})});t.model&&(this.state.model=t.model)}catch(e){this.state.model=t;let n=e instanceof Error?e.message:String(e);throw this.state.errorMessage=n,this.emit({type:`error`,error:n}),e}}async updateThinkingLevel(e){if(!(this.disposed||this.permission!==`operate`)){!this.syncingThinkingLevel&&this.state.thinkingLevel!==e&&(this.state.thinkingLevel=e);try{let t=await V(`/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 V(`/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 V(`/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`,`tool_approval_required`,`auto_compact_approval_required`,`auto_compact_failed`,`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=>B(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=E(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,S(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{}}},U=i();function W(e){return{id:`shared-${e.provider}`,name:e.provider,type:e.api,baseUrl:e.baseUrl??``,models:[e]}}async function G(e,t){try{let t=await h(e);if(t.providers?.length)return t.providers}catch{}return t?[W(t)]:[]}function K(e,t){let n=t.model??{provider:`shared`,id:`shared`};return new H(e,{...t,model:n,thinkingLevel:t.thinkingLevel??T(n)})}function q(e,t){let n={settings:new u,providerKeys:new c,sessions:new s,customProviders:new l},r=new b(``,{blockedStores:[`sessions`,`provider-keys`],fakeProviderKeys:t?[t.provider]:void 0,storeOverrides:t?{"custom-providers":{keys:async()=>(await G(e,t)).map(e=>e.name),get:async n=>(await G(e,t)).find(e=>e.name===n)??null,has:async n=>(await G(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 o(n.settings,n.providerKeys,n.sessions,n.customProviders,r))}function J({shareId:e}){let[t,i]=(0,N.useState)(``),[a,o]=(0,N.useState)(null),[s,c]=(0,N.useState)(`read`),[l,u]=(0,N.useState)(`QuickForge 分享对话`),[d,p]=(0,N.useState)(),[h,b]=(0,N.useState)(!1),[S,T]=(0,N.useState)(),E=(0,N.useRef)(!1),D=s===`operate`,P=!!a,F=!!a?.state.tools?.length;(0,N.useEffect)(()=>{q(e,a?.state.model)},[a?.state.model,e]),(0,N.useEffect)(()=>()=>a?.dispose(),[a]);let I=(0,N.useCallback)(async(n=t.trim())=>{p(void 0),b(!0);try{let t=await x(e,n);c(t.permission),u(t.title||t.share.titleSnapshot||`QuickForge 分享对话`);let r=await H.loadState(e);q(e,r.model),o(K(e,r))}catch(e){p(e instanceof Error?e.message:`Failed to unlock shared conversation`)}finally{b(!1)}},[t,e]);(0,N.useEffect)(()=>{if(P||h||E.current)return;E.current=!0;let t=window.setTimeout(()=>{(async()=>{try{(await y(e)).share.hasPassword||await I(``)}catch(e){p(e instanceof Error?e.message:`Failed to load shared conversation`)}})()},0);return()=>window.clearTimeout(t)},[h,e,I,P]);let L=(0,N.useCallback)(async e=>{await g(e)},[]),R=(0,N.useCallback)(async()=>{if(!(!a||a.permission!==`operate`))try{let t=j(A((await G(e,a.state.model)).flatMap(e=>e.models??[])),a.state.model);if(!t.length)return;O(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)}),q(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]),z=(0,N.useCallback)(e=>{T(t=>t?.id===e?void 0:t)},[]),B=(0,N.useCallback)(async e=>{if(!a||a.permission!==`operate`)return;if(p(void 0),a.state.isStreaming){k(v(`generationStillRunning`));return}let t=w(a.state.messages,e),n=t>=0?a.state.messages[t]:void 0;if(!n){k(v(`noConversationTurnToRollback`));return}try{await a.rollback(e),T({id:Date.now(),sessionId:a.sessionId,text:_(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 P?(0,U.jsxs)(`div`,{className:`flex h-screen min-h-0 flex-col bg-background text-foreground`,children:[(0,U.jsx)(`header`,{className:m(`shrink-0 border-b px-4 py-3`,D?`border-red-300 bg-red-50 text-red-950`:`border-border bg-background`),children:(0,U.jsxs)(`div`,{className:`mx-auto flex max-w-4xl items-start gap-3`,children:[(0,U.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,U.jsx)(`div`,{className:`truncate text-sm font-semibold`,children:l}),(0,U.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-2 gap-y-1 text-xs`,children:[(0,U.jsxs)(`span`,{className:m(`inline-flex items-center gap-1 rounded-full px-2 py-0.5 font-medium`,D?`bg-red-100 text-red-700`:`bg-muted text-muted-foreground`),children:[D?(0,U.jsx)(r,{className:`size-3.5`}):null,D?`高危可操作`:`只读分享`]}),(0,U.jsx)(`span`,{className:m(D?`text-red-800`:`text-muted-foreground`),children:D?`正在操作分享者的原始对话`:`只能查看,不能发送或修改`})]}),D?null:(0,U.jsx)(`div`,{className:`mt-1 text-xs leading-5 text-muted-foreground`,children:`界面与正常对话保持一致`})]}),(0,U.jsxs)(C,{variant:`ghost`,size:`sm`,className:m(`shrink-0`,D?`text-red-700 hover:bg-red-100 hover:text-red-800`:void 0),onClick:()=>void g(window.location.href),"aria-label":D?`复制高危分享链接`:`复制分享链接`,title:D?`复制高危分享链接`:`复制分享链接`,children:[(0,U.jsx)(n,{className:`size-4`}),(0,U.jsx)(`span`,{className:`hidden sm:inline`,children:D?`复制高危链接`:`复制链接`})]})]})}),d?(0,U.jsx)(`div`,{className:`mx-auto w-full max-w-4xl px-4 py-2 text-sm text-destructive`,children:d}):null,(0,U.jsx)(M,{agent:a,revision:0,agentAccessMode:F?`full-access`:`default`,workspaceToolsEnabled:F,onModelSelect:R,onAccessModeChange:()=>void 0,onRollbackFromMessage:B,onRetryFromMessage:()=>void 0,onCopyAnswer:L,onForkFromMessage:()=>void 0,onApproveToolCall:()=>void 0,onRejectToolCall:()=>void 0,disableFork:!0,rollbackConfirmTitle:v(`sharedRollbackConfirmTitle`),rollbackConfirmDescription:v(`sharedRollbackConfirm`),readOnly:!D,approvalReadOnly:!0,approvalReadOnlyMessage:v(`sharedApprovalReadOnly`),restoredDraft:S,onRestoredDraftConsumed:z,bypassClientApiKeyCheck:!0,showTurnNavigation:!1})]}):(0,U.jsx)(`div`,{className:`flex min-h-screen items-center justify-center bg-background p-6 text-foreground`,children:(0,U.jsxs)(`div`,{className:`w-full max-w-md rounded-2xl border border-border bg-background p-6 shadow-quickforge`,children:[(0,U.jsxs)(`div`,{className:`flex items-center gap-2 text-base font-semibold`,children:[(0,U.jsx)(r,{className:`size-5 text-amber-500`}),`QuickForge 局域网对话分享`]}),(0,U.jsx)(`p`,{className:`mt-2 text-sm text-muted-foreground`,children:`如果分享者设置了密码,请输入密码。未设置密码的链接会自动打开。`}),(0,U.jsx)(`input`,{type:`password`,value:t,onChange:e=>i(e.target.value),onKeyDown:e=>{e.key===`Enter`&&I()},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,U.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,U.jsx)(C,{className:`mt-5 w-full`,onClick:()=>void I(),disabled:h||!t.trim(),children:h?v(`loading`):`用密码打开分享对话`})]})})}export{J as SharedConversationPage};
1
+ import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{Jt as t,bt as n,o as r}from"./icons-DM_qJ7VJ.js";import{n as i}from"./react-vendor-BpWW_Nvp.js";import{S as a,b as o,d as s,f as c,p as l,u}from"./pi-web-ui-DV5jKjSg.js";import{U as d}from"./pi-ai-Cr2ee4a0.js";import{t as f}from"./logger-8REuLPGK.js";import{r as p}from"./model-display-label-CURwH0xM.js";import{An as m,C as h,Dt as g,Ot as _,Pn as v,S as y,Sn as b,T as x,an as S,kn as C,kt as w,ln as T,on as E,sn as D,st as O,wt as k,yn as A}from"./index-DQBOm9gt.js";import{t as j}from"./model-identity-CgA6_Pbm.js";import{ChatPanelHost as M}from"./ChatPanelHost-CW3-MQyL.js";var N=e(t(),1),P=`quickforgeClientMessageId`;function F(e){let t=e?.metadata;return t&&typeof t==`object`&&!Array.isArray(t)?t:void 0}function I(e){let t=F(e)?.[P];return typeof t==`string`&&t?t:void 0}function L(){return`qfcm_${typeof crypto<`u`&&typeof crypto.randomUUID==`function`?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`}`}function R(e){let t=I(e);if(t)return{message:e,clientMessageId:t};let n=L();return{message:{...e,metadata:{...F(e),[P]:n}},clientMessageId:n}}function z(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 B(e,t){if(!e||!t||e.role!==t.role)return!1;let n=I(e),r=I(t);return n&&r?n===r:z(e.content)===z(t.content)}async function V(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){let e=r?.code===`GENERATION_ALREADY_RUNNING`?v(`generationAlreadyRunning`):r?.error||`Request failed: ${n.status}`;throw Error(e)}return r}var H=class e{state;streamFn=d;getApiKey;sessionId;shareId;permission;harness=`quickforge`;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}=R(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 V(`/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`)return;let t=this.state.model;this.state.model=e;try{let t=await V(`/api/shared/${encodeURIComponent(this.shareId)}/model`,{method:`POST`,body:JSON.stringify({modelRef:p(e),model:e})});t.model&&(this.state.model=t.model)}catch(e){this.state.model=t;let n=e instanceof Error?e.message:String(e);throw this.state.errorMessage=n,this.emit({type:`error`,error:n}),e}}async updateThinkingLevel(e){if(!(this.disposed||this.permission!==`operate`)){!this.syncingThinkingLevel&&this.state.thinkingLevel!==e&&(this.state.thinkingLevel=e);try{let t=await V(`/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 V(`/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 V(`/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`,`tool_approval_required`,`auto_compact_approval_required`,`auto_compact_failed`,`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=>B(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=E(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,S(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{}}},U=i();function W(e){return{id:`shared-${e.provider}`,name:e.provider,type:e.api,baseUrl:e.baseUrl??``,models:[e]}}async function G(e,t){try{let t=await h(e);if(t.providers?.length)return t.providers}catch{}return t?[W(t)]:[]}function K(e,t){let n=t.model??{provider:`shared`,id:`shared`};return new H(e,{...t,model:n,thinkingLevel:t.thinkingLevel??T(n)})}function q(e,t){let n={settings:new u,providerKeys:new c,sessions:new s,customProviders:new l},r=new b(``,{blockedStores:[`sessions`,`provider-keys`],fakeProviderKeys:t?[t.provider]:void 0,storeOverrides:t?{"custom-providers":{keys:async()=>(await G(e,t)).map(e=>e.name),get:async n=>(await G(e,t)).find(e=>e.name===n)??null,has:async n=>(await G(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 o(n.settings,n.providerKeys,n.sessions,n.customProviders,r))}function J({shareId:e}){let[t,i]=(0,N.useState)(``),[a,o]=(0,N.useState)(null),[s,c]=(0,N.useState)(`read`),[l,u]=(0,N.useState)(`QuickForge 分享对话`),[d,p]=(0,N.useState)(),[h,b]=(0,N.useState)(!1),[S,T]=(0,N.useState)(),E=(0,N.useRef)(!1),D=s===`operate`,P=!!a,F=!!a?.state.tools?.length;(0,N.useEffect)(()=>{q(e,a?.state.model)},[a?.state.model,e]),(0,N.useEffect)(()=>()=>a?.dispose(),[a]);let I=(0,N.useCallback)(async(n=t.trim())=>{p(void 0),b(!0);try{let t=await x(e,n);c(t.permission),u(t.title||t.share.titleSnapshot||`QuickForge 分享对话`);let r=await H.loadState(e);q(e,r.model),o(K(e,r))}catch(e){p(e instanceof Error?e.message:`Failed to unlock shared conversation`)}finally{b(!1)}},[t,e]);(0,N.useEffect)(()=>{if(P||h||E.current)return;E.current=!0;let t=window.setTimeout(()=>{(async()=>{try{(await y(e)).share.hasPassword||await I(``)}catch(e){p(e instanceof Error?e.message:`Failed to load shared conversation`)}})()},0);return()=>window.clearTimeout(t)},[h,e,I,P]);let L=(0,N.useCallback)(async e=>{await g(e)},[]),R=(0,N.useCallback)(async()=>{if(!(!a||a.permission!==`operate`))try{let t=j(A((await G(e,a.state.model)).flatMap(e=>e.models??[])),a.state.model);if(!t.length)return;O(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)}),q(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]),z=(0,N.useCallback)(e=>{T(t=>t?.id===e?void 0:t)},[]),B=(0,N.useCallback)(async e=>{if(!a||a.permission!==`operate`)return;if(p(void 0),a.state.isStreaming){k(v(`generationStillRunning`));return}let t=w(a.state.messages,e),n=t>=0?a.state.messages[t]:void 0;if(!n){k(v(`noConversationTurnToRollback`));return}try{await a.rollback(e),T({id:Date.now(),sessionId:a.sessionId,text:_(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 P?(0,U.jsxs)(`div`,{className:`flex h-screen min-h-0 flex-col bg-background text-foreground`,children:[(0,U.jsx)(`header`,{className:m(`shrink-0 border-b px-4 py-3`,D?`border-red-300 bg-red-50 text-red-950`:`border-border bg-background`),children:(0,U.jsxs)(`div`,{className:`mx-auto flex max-w-4xl items-start gap-3`,children:[(0,U.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,U.jsx)(`div`,{className:`truncate text-sm font-semibold`,children:l}),(0,U.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-2 gap-y-1 text-xs`,children:[(0,U.jsxs)(`span`,{className:m(`inline-flex items-center gap-1 rounded-full px-2 py-0.5 font-medium`,D?`bg-red-100 text-red-700`:`bg-muted text-muted-foreground`),children:[D?(0,U.jsx)(r,{className:`size-3.5`}):null,D?`高危可操作`:`只读分享`]}),(0,U.jsx)(`span`,{className:m(D?`text-red-800`:`text-muted-foreground`),children:D?`正在操作分享者的原始对话`:`只能查看,不能发送或修改`})]}),D?null:(0,U.jsx)(`div`,{className:`mt-1 text-xs leading-5 text-muted-foreground`,children:`界面与正常对话保持一致`})]}),(0,U.jsxs)(C,{variant:`ghost`,size:`sm`,className:m(`shrink-0`,D?`text-red-700 hover:bg-red-100 hover:text-red-800`:void 0),onClick:()=>void g(window.location.href),"aria-label":D?`复制高危分享链接`:`复制分享链接`,title:D?`复制高危分享链接`:`复制分享链接`,children:[(0,U.jsx)(n,{className:`size-4`}),(0,U.jsx)(`span`,{className:`hidden sm:inline`,children:D?`复制高危链接`:`复制链接`})]})]})}),d?(0,U.jsx)(`div`,{className:`mx-auto w-full max-w-4xl px-4 py-2 text-sm text-destructive`,children:d}):null,(0,U.jsx)(M,{agent:a,revision:0,agentAccessMode:F?`full-access`:`default`,workspaceToolsEnabled:F,onModelSelect:R,onAccessModeChange:()=>void 0,onRollbackFromMessage:B,onRetryFromMessage:()=>void 0,onCopyAnswer:L,onForkFromMessage:()=>void 0,onApproveToolCall:()=>void 0,onRejectToolCall:()=>void 0,disableFork:!0,rollbackConfirmTitle:v(`sharedRollbackConfirmTitle`),rollbackConfirmDescription:v(`sharedRollbackConfirm`),readOnly:!D,approvalReadOnly:!0,approvalReadOnlyMessage:v(`sharedApprovalReadOnly`),restoredDraft:S,onRestoredDraftConsumed:z,bypassClientApiKeyCheck:!0,showTurnNavigation:!1})]}):(0,U.jsx)(`div`,{className:`flex min-h-screen items-center justify-center bg-background p-6 text-foreground`,children:(0,U.jsxs)(`div`,{className:`w-full max-w-md rounded-2xl border border-border bg-background p-6 shadow-quickforge`,children:[(0,U.jsxs)(`div`,{className:`flex items-center gap-2 text-base font-semibold`,children:[(0,U.jsx)(r,{className:`size-5 text-amber-500`}),`QuickForge 局域网对话分享`]}),(0,U.jsx)(`p`,{className:`mt-2 text-sm text-muted-foreground`,children:`如果分享者设置了密码,请输入密码。未设置密码的链接会自动打开。`}),(0,U.jsx)(`input`,{type:`password`,value:t,onChange:e=>i(e.target.value),onKeyDown:e=>{e.key===`Enter`&&I()},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,U.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,U.jsx)(C,{className:`mt-5 w-full`,onClick:()=>void I(),disabled:h||!t.trim(),children:h?v(`loading`):`用密码打开分享对话`})]})})}export{J as SharedConversationPage};
@@ -1,2 +1,2 @@
1
- import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{D as t,J as n,Jt as r,Pt as i,W as a,n as o,u as s,z as c}from"./icons-DM_qJ7VJ.js";import{n as l}from"./react-vendor-BpWW_Nvp.js";import{An as u,Pn as d,_t as f,bt as p,ft as m,kn as h,wn as ee}from"./index-DFASc15l.js";import{n as g,t as _}from"./xterm-Bm_IbozX.js";var v=e(r(),1);async function y(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 b(){return y(`/api/terminal/capabilities`,{cache:`default`})}function x(e){return y(`/api/terminal/sessions${e?`?projectId=${encodeURIComponent(e)}`:``}`)}function S(e){return y(`/api/terminal/sessions`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(e)})}function C(e){return y(`/api/terminal/sessions/${encodeURIComponent(e)}`,{method:`DELETE`})}function te(e,t){return y(`/api/terminal/sessions/${encodeURIComponent(e)}/input`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({data:t})})}function ne(){let[e,t]=(0,v.useState)(()=>m());return(0,v.useEffect)(()=>{if(typeof document>`u`)return;let e=document.documentElement,n=()=>t(m());n();let r=new MutationObserver(n);return r.observe(e,{attributes:!0,attributeFilter:[`class`]}),()=>r.disconnect()},[]),e}var w=1e4,T=[1e3,2e3,4e3],E=T.length;function D(e){return T[e]}function O(e){return e.code===`SESSION_NOT_FOUND`||e.retryable===!1||e.message===`Terminal session not found`}var k=l(),re={light:{background:`#ffffff`,foreground:`#1f2937`,cursor:`#1f2937`,selectionBackground:`#dbeafe`},dark:{background:`#171717`,foreground:`#e5e7eb`,cursor:`#e5e7eb`,selectionBackground:`#3f3f46`}};function ie({session:e,active:t,height:n,retryKey:r,onReady:i,onExited:a,onConnectionError:o,onConnectionState:s}){let c=re[ne()],l=(0,v.useRef)(null),u=(0,v.useRef)(null),m=(0,v.useRef)(null),h=(0,v.useRef)(null),y=(0,v.useRef)(null),b=(0,v.useRef)(()=>{}),x=(0,v.useRef)(!1);return(0,v.useEffect)(()=>{let e=l.current;if(!e)return;let t=p(),n=new g({cursorBlink:!0,convertEol:!1,fontFamily:getComputedStyle(document.documentElement).getPropertyValue(`--font-mono`).trim()||`ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace`,fontSize:t.fontSize,lineHeight:t.lineHeight,scrollback:5e3}),r=new _;n.loadAddon(r),n.open(e),u.current=n,m.current=r;let i=()=>{if(e.isConnected)try{r.fit();let e=h.current;e?.readyState===WebSocket.OPEN&&e.send(JSON.stringify({type:`resize`,cols:n.cols,rows:n.rows}))}catch{}};b.current=i;let a=new ResizeObserver(()=>i());a.observe(e);let o=()=>{let e=p();n.options.fontSize=e.fontSize,n.options.lineHeight=e.lineHeight,window.setTimeout(i,0)};return window.addEventListener(f,o),window.setTimeout(i,50),()=>{window.removeEventListener(f,o),a.disconnect(),b.current=()=>{},n.dispose(),u.current=null,m.current=null}},[e.id]),(0,v.useEffect)(()=>{let e=u.current;e&&(e.options.theme=c)},[c]),(0,v.useEffect)(()=>{let t=!1,n=!1,r=!1,c=0,l,f=0,p=n=>{t||s(e.id,n)},m=()=>{if(t||n||r)return;let s=++f,g=!1,_=!1,v=new WebSocket(`${ee()}/api/terminal/sessions/${encodeURIComponent(e.id)}/ws`);h.current=v,p(c===0?{status:`connecting`}:{status:`reconnecting`,reconnectAttempt:c});let S=window.setTimeout(()=>{if(!(t||n||r||_||s!==f)){C(d(`terminalConnectionTimedOut`));try{v.close()}catch{}}},w),C=i=>{if(t||n||r||g||s!==f)return;g=!0,window.clearTimeout(S),y.current?.dispose(),y.current=null;let a=D(c);if(c<E&&a!==void 0){c+=1,p({status:`reconnecting`,reconnectAttempt:c}),l=window.setTimeout(m,a);return}p({status:`disconnected`}),o(e.id,i)};v.addEventListener(`open`,()=>{if(t||n||g||s!==f){try{v.close()}catch{}return}y.current?.dispose(),y.current=u.current?.onData(e=>{v.readyState===WebSocket.OPEN&&v.send(JSON.stringify({type:`input`,data:e}))})??null,window.setTimeout(b.current,0)}),v.addEventListener(`message`,t=>{try{let s=JSON.parse(String(t.data));if(s.type===`ready`)_=!0,c=0,window.clearTimeout(S),o(e.id,void 0),p({status:`connected`}),x.current||(x.current=!0,u.current?.writeln(`\x1b[2mConnected to ${e.cwd}\x1b[0m`)),i(e.id);else if(s.type===`output`)u.current?.write(s.data);else if(s.type===`exit`)n=!0,window.clearTimeout(S),l!==void 0&&window.clearTimeout(l),u.current?.writeln(``),u.current?.writeln(`\x1b[33m[process exited with code ${s.exitCode??`unknown`}]\x1b[0m`),p({status:`exited`}),a(e.id);else if(s.type===`error`)if(O(s)){r=!0,g=!0,window.clearTimeout(S),l!==void 0&&window.clearTimeout(l),y.current?.dispose(),y.current=null,p({status:`unavailable`}),o(e.id,d(`terminalSessionUnavailable`));try{v.close()}catch{}}else C(s.message||d(`terminalConnectionFailed`))}catch{}}),v.addEventListener(`error`,()=>{C(d(_?`terminalConnectionClosedUnexpectedly`:`terminalConnectionFailed`))}),v.addEventListener(`close`,()=>{window.clearTimeout(S),y.current?.dispose(),y.current=null,!(t||n||r||g||s!==f)&&C(d(_?`terminalConnectionClosedUnexpectedly`:`terminalConnectionFailed`))})};return o(e.id,void 0),m(),()=>{t=!0,f+=1,l!==void 0&&window.clearTimeout(l),y.current?.dispose(),y.current=null;let e=h.current;h.current=null;try{e?.close()}catch{}}},[o,s,a,i,r,e.cwd,e.id]),(0,v.useEffect)(()=>{t&&window.setTimeout(()=>{try{m.current?.fit(),u.current?.focus()}catch{}},0)},[t,n]),(0,k.jsx)(`div`,{className:t?`h-full min-h-0 w-full pl-2 md:pl-3`:`hidden`,"aria-hidden":!t,children:(0,k.jsx)(`div`,{ref:l,className:`h-full min-h-0 w-full`})})}var ae=180,oe=.7,se=320;function A(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 j(e,t){let n=e?.terminalShellProfiles||[],r=t||e?.defaultTerminalShellProfileId||``;return n.find(e=>e.id===r)||n[0]}function M({project:e,onCollapse:r,pendingCommand:l,onPendingCommandHandled:f,variant:p=`dock`,singleSession:m=!1,panelInstanceId:ee,panelSessionId:g,onPanelSessionReady:_}){let[y,ne]=(0,v.useState)(null),[w,T]=(0,v.useState)([]),[E,D]=(0,v.useState)(),[O,re]=(0,v.useState)(se),[M,ce]=(0,v.useState)(!0),[N,le]=(0,v.useState)(!1),[ue,P]=(0,v.useState)(),[de,fe]=(0,v.useState)({}),[F,pe]=(0,v.useState)({}),[me,he]=(0,v.useState)({}),[I,L]=(0,v.useState)(!1),[R,ge]=(0,v.useState)(!1),z=(0,v.useRef)(!1),B=(0,v.useRef)(!1),V=(0,v.useRef)(new Set),_e=(0,v.useRef)(l),H=(0,v.useRef)(new Set),U=(0,v.useRef)(new Set),W=(0,v.useRef)(new Map),G=(0,v.useRef)(!0),ve=(0,v.useRef)(_),[ye,be]=(0,v.useState)(()=>new Set),xe=(0,v.useRef)(null),Se=(0,v.useRef)(null),K=e?.id,q=p===`panel`&&!!ee,J=(0,v.useMemo)(()=>w.find(e=>e.id===E)??w[0],[E,w]);(0,v.useEffect)(()=>{_e.current=l},[l]),(0,v.useEffect)(()=>{ve.current=_},[_]),(0,v.useEffect)(()=>()=>{G.current=!1},[]);let Ce=(0,v.useCallback)(async()=>{let e=await x(K);return T(e.sessions),D(t=>t&&e.sessions.some(e=>e.id===t)?t:e.sessions[0]?.id),e.sessions},[K]),we=(0,v.useCallback)(async(e,t)=>{if(z.current)return;let n=j(y,t);z.current=!0,le(!0),P(void 0);try{let t=await S({projectId:K,name:A(e,n),cols:120,rows:30,shellProfileId:n?.id,shellProfileName:n?.name});T(e=>[...e,t]),D(t.id),q&&ve.current?.(t.id)}catch(e){P(e instanceof Error?e.message:d(`terminalCreateFailed`))}finally{z.current=!1,le(!1)}},[y,q,K]);(0,v.useEffect)(()=>{let e=!1;return(async()=>{ce(!0),P(void 0);try{let[t,n]=await Promise.all([b(),x(K)]);if(e)return;if(ne(t),t.enabled&&q&&g&&n.sessions.some(e=>e.id===g)){B.current=!0,T(n.sessions),D(g);return}if(t.enabled&&q&&!B.current){B.current=!0;let r=j(t);try{let t=await S({projectId:K,name:A(n.sessions,r),cols:120,rows:30,shellProfileId:r?.id,shellProfileName:r?.name});if(e){C(t.id).catch(()=>{});return}T([...n.sessions,t]),D(t.id),ve.current?.(t.id);return}catch(t){e||P(t instanceof Error?t.message:d(`terminalCreateFailed`))}}if(T(n.sessions),D(n.sessions[0]?.id),t.enabled&&n.sessions.length===0&&!_e.current){let n=j(t);S({projectId:K,name:A([],n),cols:120,rows:30,shellProfileId:n?.id,shellProfileName:n?.name}).then(t=>{if(e){C(t.id).catch(()=>{});return}T([t]),D(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||ce(!1)}})(),()=>{e=!0}},[q,g,K]),(0,v.useEffect)(()=>{if(!I)return;let e=e=>{Se.current?.contains(e.target)||L(!1)},t=e=>{e.key===`Escape`&&L(!1)};return document.addEventListener(`pointerdown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`pointerdown`,e),document.removeEventListener(`keydown`,t)}},[I]),(0,v.useEffect)(()=>{if(!R)return;let e=e=>{e.key===`Escape`&&ge(!1)};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[R]),(0,v.useEffect)(()=>{if(!l||V.current.has(l.id)||W.current.has(l.id)||H.current.has(l.id)||M||N||!y)return;if(!y.enabled){V.current.add(l.id),window.setTimeout(()=>{P(y.reason||d(`terminalUnavailable`)),f?.(l.id)},0);return}let e=J&&!J.exited?J:w.find(e=>!e.exited);if(e){W.current.set(l.id,e.id),window.setTimeout(()=>{G.current&&D(e.id)},0);return}H.current.add(l.id),window.setTimeout(()=>{G.current&&P(void 0)},0);let t=j(y);S({projectId:K,name:A(w,t),cols:120,rows:30,shellProfileId:t?.id,shellProfileName:t?.name}).then(e=>{if(!G.current){C(e.id).catch(()=>{});return}W.current.set(l.id,e.id),T(t=>t.some(t=>t.id===e.id)?t:[...t,e]),D(e.id)}).catch(e=>{G.current&&(P(e instanceof Error?e.message:d(`terminalCommandExecuteFailed`)),V.current.add(l.id),f?.(l.id))}).finally(()=>{H.current.delete(l.id)})},[J,y,N,M,f,l,K,w]),(0,v.useEffect)(()=>{if(!l||V.current.has(l.id)||U.current.has(l.id))return;let e=W.current.get(l.id),t=e?w.find(t=>t.id===e):J&&!J.exited?J:w.find(e=>!e.exited);!t||t.exited||!ye.has(t.id)||(U.current.add(l.id),window.setTimeout(()=>{G.current&&(D(t.id),P(void 0))},0),(async()=>{try{if(l.execute){let e=l.command.split(`
1
+ import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{D as t,J as n,Jt as r,Pt as i,W as a,n as o,u as s,z as c}from"./icons-DM_qJ7VJ.js";import{n as l}from"./react-vendor-BpWW_Nvp.js";import{An as u,Pn as d,_t as f,bt as p,ft as m,kn as h,wn as ee}from"./index-DQBOm9gt.js";import{n as g,t as _}from"./xterm-Bm_IbozX.js";var v=e(r(),1);async function y(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 b(){return y(`/api/terminal/capabilities`,{cache:`default`})}function x(e){return y(`/api/terminal/sessions${e?`?projectId=${encodeURIComponent(e)}`:``}`)}function S(e){return y(`/api/terminal/sessions`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(e)})}function C(e){return y(`/api/terminal/sessions/${encodeURIComponent(e)}`,{method:`DELETE`})}function te(e,t){return y(`/api/terminal/sessions/${encodeURIComponent(e)}/input`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({data:t})})}function ne(){let[e,t]=(0,v.useState)(()=>m());return(0,v.useEffect)(()=>{if(typeof document>`u`)return;let e=document.documentElement,n=()=>t(m());n();let r=new MutationObserver(n);return r.observe(e,{attributes:!0,attributeFilter:[`class`]}),()=>r.disconnect()},[]),e}var w=1e4,T=[1e3,2e3,4e3],E=T.length;function D(e){return T[e]}function O(e){return e.code===`SESSION_NOT_FOUND`||e.retryable===!1||e.message===`Terminal session not found`}var k=l(),re={light:{background:`#ffffff`,foreground:`#1f2937`,cursor:`#1f2937`,selectionBackground:`#dbeafe`},dark:{background:`#171717`,foreground:`#e5e7eb`,cursor:`#e5e7eb`,selectionBackground:`#3f3f46`}};function ie({session:e,active:t,height:n,retryKey:r,onReady:i,onExited:a,onConnectionError:o,onConnectionState:s}){let c=re[ne()],l=(0,v.useRef)(null),u=(0,v.useRef)(null),m=(0,v.useRef)(null),h=(0,v.useRef)(null),y=(0,v.useRef)(null),b=(0,v.useRef)(()=>{}),x=(0,v.useRef)(!1);return(0,v.useEffect)(()=>{let e=l.current;if(!e)return;let t=p(),n=new g({cursorBlink:!0,convertEol:!1,fontFamily:getComputedStyle(document.documentElement).getPropertyValue(`--font-mono`).trim()||`ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace`,fontSize:t.fontSize,lineHeight:t.lineHeight,scrollback:5e3}),r=new _;n.loadAddon(r),n.open(e),u.current=n,m.current=r;let i=()=>{if(e.isConnected)try{r.fit();let e=h.current;e?.readyState===WebSocket.OPEN&&e.send(JSON.stringify({type:`resize`,cols:n.cols,rows:n.rows}))}catch{}};b.current=i;let a=new ResizeObserver(()=>i());a.observe(e);let o=()=>{let e=p();n.options.fontSize=e.fontSize,n.options.lineHeight=e.lineHeight,window.setTimeout(i,0)};return window.addEventListener(f,o),window.setTimeout(i,50),()=>{window.removeEventListener(f,o),a.disconnect(),b.current=()=>{},n.dispose(),u.current=null,m.current=null}},[e.id]),(0,v.useEffect)(()=>{let e=u.current;e&&(e.options.theme=c)},[c]),(0,v.useEffect)(()=>{let t=!1,n=!1,r=!1,c=0,l,f=0,p=n=>{t||s(e.id,n)},m=()=>{if(t||n||r)return;let s=++f,g=!1,_=!1,v=new WebSocket(`${ee()}/api/terminal/sessions/${encodeURIComponent(e.id)}/ws`);h.current=v,p(c===0?{status:`connecting`}:{status:`reconnecting`,reconnectAttempt:c});let S=window.setTimeout(()=>{if(!(t||n||r||_||s!==f)){C(d(`terminalConnectionTimedOut`));try{v.close()}catch{}}},w),C=i=>{if(t||n||r||g||s!==f)return;g=!0,window.clearTimeout(S),y.current?.dispose(),y.current=null;let a=D(c);if(c<E&&a!==void 0){c+=1,p({status:`reconnecting`,reconnectAttempt:c}),l=window.setTimeout(m,a);return}p({status:`disconnected`}),o(e.id,i)};v.addEventListener(`open`,()=>{if(t||n||g||s!==f){try{v.close()}catch{}return}y.current?.dispose(),y.current=u.current?.onData(e=>{v.readyState===WebSocket.OPEN&&v.send(JSON.stringify({type:`input`,data:e}))})??null,window.setTimeout(b.current,0)}),v.addEventListener(`message`,t=>{try{let s=JSON.parse(String(t.data));if(s.type===`ready`)_=!0,c=0,window.clearTimeout(S),o(e.id,void 0),p({status:`connected`}),x.current||(x.current=!0,u.current?.writeln(`\x1b[2mConnected to ${e.cwd}\x1b[0m`)),i(e.id);else if(s.type===`output`)u.current?.write(s.data);else if(s.type===`exit`)n=!0,window.clearTimeout(S),l!==void 0&&window.clearTimeout(l),u.current?.writeln(``),u.current?.writeln(`\x1b[33m[process exited with code ${s.exitCode??`unknown`}]\x1b[0m`),p({status:`exited`}),a(e.id);else if(s.type===`error`)if(O(s)){r=!0,g=!0,window.clearTimeout(S),l!==void 0&&window.clearTimeout(l),y.current?.dispose(),y.current=null,p({status:`unavailable`}),o(e.id,d(`terminalSessionUnavailable`));try{v.close()}catch{}}else C(s.message||d(`terminalConnectionFailed`))}catch{}}),v.addEventListener(`error`,()=>{C(d(_?`terminalConnectionClosedUnexpectedly`:`terminalConnectionFailed`))}),v.addEventListener(`close`,()=>{window.clearTimeout(S),y.current?.dispose(),y.current=null,!(t||n||r||g||s!==f)&&C(d(_?`terminalConnectionClosedUnexpectedly`:`terminalConnectionFailed`))})};return o(e.id,void 0),m(),()=>{t=!0,f+=1,l!==void 0&&window.clearTimeout(l),y.current?.dispose(),y.current=null;let e=h.current;h.current=null;try{e?.close()}catch{}}},[o,s,a,i,r,e.cwd,e.id]),(0,v.useEffect)(()=>{t&&window.setTimeout(()=>{try{m.current?.fit(),u.current?.focus()}catch{}},0)},[t,n]),(0,k.jsx)(`div`,{className:t?`h-full min-h-0 w-full pl-2 md:pl-3`:`hidden`,"aria-hidden":!t,children:(0,k.jsx)(`div`,{ref:l,className:`h-full min-h-0 w-full`})})}var ae=180,oe=.7,se=320;function A(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 j(e,t){let n=e?.terminalShellProfiles||[],r=t||e?.defaultTerminalShellProfileId||``;return n.find(e=>e.id===r)||n[0]}function M({project:e,onCollapse:r,pendingCommand:l,onPendingCommandHandled:f,variant:p=`dock`,singleSession:m=!1,panelInstanceId:ee,panelSessionId:g,onPanelSessionReady:_}){let[y,ne]=(0,v.useState)(null),[w,T]=(0,v.useState)([]),[E,D]=(0,v.useState)(),[O,re]=(0,v.useState)(se),[M,ce]=(0,v.useState)(!0),[N,le]=(0,v.useState)(!1),[ue,P]=(0,v.useState)(),[de,fe]=(0,v.useState)({}),[F,pe]=(0,v.useState)({}),[me,he]=(0,v.useState)({}),[I,L]=(0,v.useState)(!1),[R,ge]=(0,v.useState)(!1),z=(0,v.useRef)(!1),B=(0,v.useRef)(!1),V=(0,v.useRef)(new Set),_e=(0,v.useRef)(l),H=(0,v.useRef)(new Set),U=(0,v.useRef)(new Set),W=(0,v.useRef)(new Map),G=(0,v.useRef)(!0),ve=(0,v.useRef)(_),[ye,be]=(0,v.useState)(()=>new Set),xe=(0,v.useRef)(null),Se=(0,v.useRef)(null),K=e?.id,q=p===`panel`&&!!ee,J=(0,v.useMemo)(()=>w.find(e=>e.id===E)??w[0],[E,w]);(0,v.useEffect)(()=>{_e.current=l},[l]),(0,v.useEffect)(()=>{ve.current=_},[_]),(0,v.useEffect)(()=>()=>{G.current=!1},[]);let Ce=(0,v.useCallback)(async()=>{let e=await x(K);return T(e.sessions),D(t=>t&&e.sessions.some(e=>e.id===t)?t:e.sessions[0]?.id),e.sessions},[K]),we=(0,v.useCallback)(async(e,t)=>{if(z.current)return;let n=j(y,t);z.current=!0,le(!0),P(void 0);try{let t=await S({projectId:K,name:A(e,n),cols:120,rows:30,shellProfileId:n?.id,shellProfileName:n?.name});T(e=>[...e,t]),D(t.id),q&&ve.current?.(t.id)}catch(e){P(e instanceof Error?e.message:d(`terminalCreateFailed`))}finally{z.current=!1,le(!1)}},[y,q,K]);(0,v.useEffect)(()=>{let e=!1;return(async()=>{ce(!0),P(void 0);try{let[t,n]=await Promise.all([b(),x(K)]);if(e)return;if(ne(t),t.enabled&&q&&g&&n.sessions.some(e=>e.id===g)){B.current=!0,T(n.sessions),D(g);return}if(t.enabled&&q&&!B.current){B.current=!0;let r=j(t);try{let t=await S({projectId:K,name:A(n.sessions,r),cols:120,rows:30,shellProfileId:r?.id,shellProfileName:r?.name});if(e){C(t.id).catch(()=>{});return}T([...n.sessions,t]),D(t.id),ve.current?.(t.id);return}catch(t){e||P(t instanceof Error?t.message:d(`terminalCreateFailed`))}}if(T(n.sessions),D(n.sessions[0]?.id),t.enabled&&n.sessions.length===0&&!_e.current){let n=j(t);S({projectId:K,name:A([],n),cols:120,rows:30,shellProfileId:n?.id,shellProfileName:n?.name}).then(t=>{if(e){C(t.id).catch(()=>{});return}T([t]),D(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||ce(!1)}})(),()=>{e=!0}},[q,g,K]),(0,v.useEffect)(()=>{if(!I)return;let e=e=>{Se.current?.contains(e.target)||L(!1)},t=e=>{e.key===`Escape`&&L(!1)};return document.addEventListener(`pointerdown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`pointerdown`,e),document.removeEventListener(`keydown`,t)}},[I]),(0,v.useEffect)(()=>{if(!R)return;let e=e=>{e.key===`Escape`&&ge(!1)};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[R]),(0,v.useEffect)(()=>{if(!l||V.current.has(l.id)||W.current.has(l.id)||H.current.has(l.id)||M||N||!y)return;if(!y.enabled){V.current.add(l.id),window.setTimeout(()=>{P(y.reason||d(`terminalUnavailable`)),f?.(l.id)},0);return}let e=J&&!J.exited?J:w.find(e=>!e.exited);if(e){W.current.set(l.id,e.id),window.setTimeout(()=>{G.current&&D(e.id)},0);return}H.current.add(l.id),window.setTimeout(()=>{G.current&&P(void 0)},0);let t=j(y);S({projectId:K,name:A(w,t),cols:120,rows:30,shellProfileId:t?.id,shellProfileName:t?.name}).then(e=>{if(!G.current){C(e.id).catch(()=>{});return}W.current.set(l.id,e.id),T(t=>t.some(t=>t.id===e.id)?t:[...t,e]),D(e.id)}).catch(e=>{G.current&&(P(e instanceof Error?e.message:d(`terminalCommandExecuteFailed`)),V.current.add(l.id),f?.(l.id))}).finally(()=>{H.current.delete(l.id)})},[J,y,N,M,f,l,K,w]),(0,v.useEffect)(()=>{if(!l||V.current.has(l.id)||U.current.has(l.id))return;let e=W.current.get(l.id),t=e?w.find(t=>t.id===e):J&&!J.exited?J:w.find(e=>!e.exited);!t||t.exited||!ye.has(t.id)||(U.current.add(l.id),window.setTimeout(()=>{G.current&&(D(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 te(t.id,n.join(``))}else await te(t.id,l.command)}catch(e){G.current&&P(e instanceof Error?e.message:d(`terminalCommandExecuteFailed`))}finally{V.current.add(l.id),U.current.delete(l.id),W.current.delete(l.id),G.current&&f?.(l.id)}})())},[J,f,l,ye,w]);let Y=async e=>{P(void 0),fe(t=>{if(!t[e])return t;let n={...t};return delete n[e],n}),pe(t=>{if(!t[e])return t;let n={...t};return delete n[e],n}),he(t=>{if(t[e]===void 0)return t;let n={...t};return delete n[e],n});let t=w.filter(t=>t.id!==e);T(t),E===e&&D(t[0]?.id);try{await C(e)}catch(e){P(e instanceof Error?e.message:d(`terminalCloseFailed`)),Ce().catch(()=>{})}},Te=(0,v.useCallback)(e=>{T(t=>t.map(t=>t.id===e?{...t,exited:!0}:t)),be(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),n})},[]),Ee=(0,v.useCallback)(e=>{be(t=>{if(t.has(e))return t;let n=new Set(t);return n.add(e),n})},[]),De=(0,v.useCallback)((e,t)=>{fe(n=>{if(!t){if(!n[e])return n;let t={...n};return delete t[e],t}return n[e]===t?n:{...n,[e]:t}})},[]),Oe=(0,v.useCallback)((e,t)=>{pe(n=>{let r=n[e];return r?.status===t.status&&r.reconnectAttempt===t.reconnectAttempt?n:{...n,[e]:t}})},[]),ke=(0,v.useCallback)(e=>{fe(t=>{if(!t[e])return t;let n={...t};return delete n[e],n}),he(t=>({...t,[e]:(t[e]||0)+1}))},[]),Ae=async e=>{let t=w.filter(t=>t.id!==e);await Y(e),await we(t)},je=(e,t)=>e.exited||t===`exited`||t===`unavailable`?`bg-muted-foreground/40`:t===`connected`?`bg-emerald-500/80`:t===`connecting`||t===`reconnecting`?`bg-amber-500/80`:`bg-destructive/70`,Me=e=>{xe.current={startY:e.clientY,startHeight:O},e.currentTarget.setPointerCapture(e.pointerId)},Ne=e=>{let t=xe.current;if(!t)return;let n=Math.max(ae,Math.floor(window.innerHeight*oe));re(Math.min(n,Math.max(ae,t.startHeight+t.startY-e.clientY)))},Pe=e=>{xe.current=null;try{e.currentTarget.releasePointerCapture(e.pointerId)}catch{}},X=y?.terminalShellProfiles||[],Fe=y?.defaultTerminalShellProfileId||``,Ie=X.find(e=>e.id===Fe)||X[0],Le=!!(y&&w.length>=y.maxSessions),Re=N||Le,ze=J?de[J.id]:void 0,Z=J?F[J.id]:void 0,Be=Z?.status===`unavailable`,Ve=Z?.status===`connecting`?d(`terminalConnecting`):Z?.status===`reconnecting`?d(`terminalReconnecting`,{attempt:Z.reconnectAttempt||1,max:3}):void 0,He=q&&J?[J]:w,Q=ue??ze,Ue=Q?void 0:Ve,We=!!(Q||Ue),$=p===`panel`,Ge=$&&m,Ke=$?void 0:R?We?`calc(100% - 4.25rem)`:`calc(100% - 2.25rem)`:We?O-72:O-45;return(0,k.jsxs)(`div`,{className:u($?`flex min-h-0 flex-1 flex-col bg-background`:`shrink-0 border-t border-border bg-background`,R&&`quickforge-terminal-fullscreen z-40 flex flex-col border-t-0`),style:R||$?void 0:{height:O},children:[!R&&!$?(0,k.jsx)(`div`,{className:`h-1 cursor-row-resize bg-transparent hover:bg-border`,onPointerDown:Me,onPointerMove:Ne,onPointerUp:Pe,onPointerCancel:Pe}):null,(0,k.jsxs)(`div`,{className:`flex h-9 items-center gap-1 border-b border-border px-2`,children:[(0,k.jsx)(s,{className:`size-4 shrink-0 text-muted-foreground/60`}),(0,k.jsx)(`div`,{className:`flex min-w-0 flex-1 items-center gap-1 overflow-x-auto`,children:He.map(e=>{let t=u(`flex max-w-44 shrink-0 items-center gap-1 rounded-md px-2 py-1 text-xs text-muted-foreground/72`,J?.id===e.id&&`bg-muted/28 text-foreground/90`);return Ge?(0,k.jsxs)(`div`,{className:t,title:`${e.name} — ${e.cwd}`,children:[(0,k.jsx)(`span`,{className:u(`size-1.5 rounded-full`,je(e,F[e.id]?.status))}),(0,k.jsx)(`span`,{className:`truncate`,children:e.name})]},e.id):(0,k.jsxs)(`button`,{type:`button`,className:u(t,`hover:bg-muted/20 hover:text-foreground/85`),onClick:()=>D(e.id),title:`${e.name} — ${e.cwd}`,children:[(0,k.jsx)(`span`,{className:u(`size-1.5 rounded-full`,je(e,F[e.id]?.status))}),(0,k.jsx)(`span`,{className:`truncate`,children:e.name}),(0,k.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(),Y(e.id)},onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),t.stopPropagation(),Y(e.id))},"aria-label":d(`terminalCloseSession`,{name:e.name}),children:(0,k.jsx)(o,{className:`size-3`})})]},e.id)})}),Ge?null:(0,k.jsxs)(`div`,{className:`relative shrink-0`,ref:Se,children:[(0,k.jsxs)(`div`,{className:`flex items-center overflow-hidden rounded-md border border-border bg-background`,children:[(0,k.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 we(w),disabled:Re,title:Ie?d(`terminalNewWithProfile`,{name:Ie.name}):d(`terminalNew`),"aria-label":d(`terminalNew`),children:N?(0,k.jsx)(n,{className:`size-3.5 animate-spin`}):(0,k.jsx)(t,{className:`size-3.5`})}),X.length>0?(0,k.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:Re,title:d(`terminalSelectShell`),"aria-label":d(`terminalSelectShell`),"aria-expanded":I,children:(0,k.jsx)(i,{className:`size-3.5`})}):null]}),I?(0,k.jsxs)(`div`,{className:u(`absolute 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)]`,$?`top-9`:`bottom-9`),children:[(0,k.jsx)(`div`,{className:`px-2 pb-1.5 pt-1 text-[11px] font-medium uppercase tracking-wide text-muted-foreground/60`,children:d(`terminalNewWith`)}),X.map(e=>(0,k.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),we(w,e.id)},children:[(0,k.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,k.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,k.jsx)(`span`,{className:`block truncate font-medium`,children:e.name}),(0,k.jsx)(`span`,{className:`block truncate font-mono text-[11px] text-muted-foreground/55`,children:e.command})]})]},e.id))]}):null]}),Ge?null:(0,k.jsx)(h,{variant:`ghost`,size:`icon`,className:`size-7`,onClick:()=>ge(e=>!e),title:d(R?`terminalExitFullscreen`:`terminalFullscreen`),"aria-label":d(R?`terminalExitFullscreen`:`terminalFullscreen`),children:R?(0,k.jsx)(c,{className:`size-3.5`}):(0,k.jsx)(a,{className:`size-3.5`})}),(0,k.jsx)(h,{variant:`ghost`,size:`icon`,className:u(`size-7`,$&&`hidden`),onClick:r,title:d(`terminalCollapse`),"aria-label":d(`terminalCollapse`),children:(0,k.jsx)(i,{className:`size-3.5`})})]}),Q?(0,k.jsxs)(`div`,{className:`flex items-center justify-between gap-3 border-b border-border px-3 py-1.5 text-xs text-destructive`,children:[(0,k.jsx)(`span`,{children:Q}),Be&&J?(0,k.jsxs)(`span`,{className:`flex shrink-0 items-center gap-1`,children:[(0,k.jsx)(`button`,{type:`button`,className:`rounded px-1.5 py-0.5 font-medium text-foreground/80 hover:bg-muted/40`,onClick:()=>void Ae(J.id),disabled:N,children:d(`terminalStartNew`)}),(0,k.jsx)(`button`,{type:`button`,className:`rounded px-1.5 py-0.5 font-medium text-muted-foreground hover:bg-muted/40`,onClick:()=>void Y(J.id),children:d(`close`)})]}):ze&&J&&!J.exited?(0,k.jsx)(`button`,{type:`button`,className:`shrink-0 rounded px-1.5 py-0.5 font-medium text-destructive hover:bg-destructive/10`,onClick:()=>ke(J.id),children:d(`retry`)}):null]}):Ue?(0,k.jsx)(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-muted-foreground/70`,children:Ue}):null,(0,k.jsx)(`div`,{className:u(`min-h-0 bg-background`,$&&`flex-1`),style:Ke===void 0?void 0:{height:Ke},children:M?(0,k.jsxs)(`div`,{className:`flex h-full items-center justify-center gap-2 text-xs text-muted-foreground/60`,children:[(0,k.jsx)(n,{className:`size-4 animate-spin`}),` `,d(`terminalStarting`)]}):y&&!y.enabled?(0,k.jsx)(`div`,{className:`flex h-full items-center justify-center px-4 text-center text-xs text-muted-foreground/60`,children:y.reason||d(`terminalUnavailable`)}):w.length===0?(0,k.jsx)(`div`,{className:`flex h-full items-center justify-center text-xs text-muted-foreground/60`,children:d(`terminalNoSessions`)}):w.map(e=>(0,k.jsx)(ie,{session:e,active:e.id===J?.id,height:R?window.innerHeight-36:$?0:O,retryKey:me[e.id]||0,onReady:Ee,onExited:Te,onConnectionError:De,onConnectionState:Oe},e.id))})]})}export{M as TerminalDock,ne as t};