@shawnstack/quickforge 1.7.9 → 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 (33) hide show
  1. package/dist/assets/{AgentProfilesPage-BSM5w3bn.js → AgentProfilesPage-Dw9orPNt.js} +1 -1
  2. package/dist/assets/{ChatPanelHost-cd80S4EX.js → ChatPanelHost-CW3-MQyL.js} +2 -2
  3. package/dist/assets/{CloudAccountSettingsPage-BJMrfgy9.js → CloudAccountSettingsPage-CDkKN1Sz.js} +1 -1
  4. package/dist/assets/{PluginsPage-mJkTmVVV.js → PluginsPage-Dj1bmsEf.js} +1 -1
  5. package/dist/assets/{ScheduledTasksPage-DJj_NLm9.js → ScheduledTasksPage-C9lOTi75.js} +1 -1
  6. package/dist/assets/{SettingsWorkspacePage-7lQ0Wl63.js → SettingsWorkspacePage-CFuvSATi.js} +3 -3
  7. package/dist/assets/{ShareLinksSettingsPage-DjFq_Lnb.js → ShareLinksSettingsPage-CH_t33A3.js} +1 -1
  8. package/dist/assets/{SharedConversationPage-BbuNpcpP.js → SharedConversationPage-DLo05j7c.js} +1 -1
  9. package/dist/assets/{TerminalDock-CczcCJJE.js → TerminalDock-CSOVub-m.js} +1 -1
  10. package/dist/assets/{WorkspaceInspector-0i6x-diB.js → WorkspaceInspector-DPXgLIum.js} +1 -1
  11. package/dist/assets/index-DQBOm9gt.js +66 -0
  12. package/dist/assets/index-ps85guTs.css +3 -0
  13. package/dist/assets/{local-tools-Dn1Y9aPe.js → local-tools-BxfQeIUQ.js} +1 -1
  14. package/dist/assets/{mcp-servers-dialog-BG4b67ea.js → mcp-servers-dialog-CwHp0K4q.js} +1 -1
  15. package/dist/assets/{skills-dialog-DIzZvQqW.js → skills-dialog-k9ycekIU.js} +1 -1
  16. package/dist/index.html +4 -4
  17. package/package.json +1 -1
  18. package/server/agent-manager.mjs +68 -2
  19. package/server/auto-compaction.mjs +0 -2
  20. package/server/context-usage.mjs +9 -7
  21. package/server/maintenance/downgrade-session-state-v1.mjs +4 -2
  22. package/server/maintenance/export-session-state-v1.mjs +4 -2
  23. package/server/routes/backup.mjs +7 -0
  24. package/server/routes/storage.mjs +23 -0
  25. package/server/session-persistence-lock.mjs +17 -6
  26. package/server/session-state-backup.mjs +4 -2
  27. package/server/session-state-cutover.mjs +284 -91
  28. package/server/session-state-service.mjs +38 -17
  29. package/server/sqlite/session-state-repository.mjs +145 -25
  30. package/server/storage.mjs +28 -0
  31. package/server/utils/process-tree.mjs +14 -2
  32. package/dist/assets/index-D-J_8Smf.css +0 -3
  33. package/dist/assets/index-DFASc15l.js +0 -66
@@ -1 +1 @@
1
- import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{Gt as t,Jt as n,Pt as r,f as i,ht as a,j as o,s,zt as ee}from"./icons-DM_qJ7VJ.js";import{i as c,n as l}from"./react-vendor-BpWW_Nvp.js";import{n as te,r as u,t as ne}from"./model-display-label-CURwH0xM.js";import{Dn as re,Pn as d,Tt as ie,bn as f,ct as ae,fn as oe,kn as p,ln as se,pn as ce,un as le}from"./index-DFASc15l.js";import{i as ue,r as de,t as fe}from"./model-identity-CgA6_Pbm.js";var m=e(n(),1),pe=c(),me=1e3/6e4,h=6e4,g=1e3;function _(e){let t=Number.isFinite(e)&&Number(e)>0?Math.max(Math.round(Number(e)),g):60*h;return Number((t/h).toFixed(6)).toString()}function v(e){return Math.max(Math.round(Number(e)*h),g)}function y(e){let t=Number(e);return Number.isFinite(t)&&t>=.016666666666666666&&t<=60}var b=l(),x=144,S=82,C=4,w=8;function T(e){return JSON.stringify(u(e))}function E(e){if(!e)return{mode:`inherit`};try{return{mode:`fixed`,...JSON.parse(e)}}catch{return{mode:`inherit`}}}function D(e){return!e||e.mode!==`fixed`?``:e.source===`cloud`?JSON.stringify({version:1,source:`cloud`,catalogId:e.catalogId}):e.source===`custom`?JSON.stringify({version:1,source:`custom`,providerId:e.providerId,modelId:e.modelId}):JSON.stringify({version:1,source:`legacy-custom`,provider:e.provider,modelId:e.modelId,...e.api?{api:e.api}:{},...e.baseUrl?{baseUrl:e.baseUrl}:{}})}function O(){return{name:``,label:``,description:``,systemPrompt:``,allowedTools:[`read_file`,`grep_files`],maxRuntimeMinutes:`60`,maxToolCalls:`300`,enabledAsSubagent:!0,modelMode:`inherit`,fixedModelValue:``,thinkingLevel:`inherit`}}function he(e){return{name:e.name,label:e.label,description:e.description??``,systemPrompt:e.systemPrompt??``,allowedTools:e.allowedTools??[],maxRuntimeMinutes:_(e.maxRuntimeMs),maxToolCalls:String(e.maxToolCalls??300),enabledAsSubagent:e.enabledAsSubagent,modelMode:e.model?.mode===`fixed`?`fixed`:`inherit`,fixedModelValue:D(e.model),thinkingLevel:e.thinkingLevel??`inherit`}}function ge(e){return{name:e.name.trim().toLowerCase(),label:e.label.trim(),description:e.description.trim(),systemPrompt:e.systemPrompt.trim(),allowedTools:e.allowedTools,maxRuntimeMs:v(e.maxRuntimeMinutes),maxToolCalls:Number(e.maxToolCalls||300),enabledAsSubagent:e.enabledAsSubagent,model:e.modelMode===`fixed`?E(e.fixedModelValue):{mode:`inherit`},thinkingLevel:e.thinkingLevel}}function _e(e){return!!(e.name.trim()&&e.label.trim()&&e.allowedTools.length>0&&y(e.maxRuntimeMinutes))}async function k(e,t){let n=await fetch(e,{...t,headers:{"content-type":`application/json`,...t?.headers}}),r=await n.json().catch(()=>null);if(!n.ok)throw Error(r?.error||`请求失败`);return r}function A(){let[e,n]=(0,m.useState)([]),[c,l]=(0,m.useState)([]),[h,g]=(0,m.useState)(!1),[_,v]=(0,m.useState)(null),[y,A]=(0,m.useState)(()=>O()),[j,M]=(0,m.useState)(!1),[N,P]=(0,m.useState)(``),[F,I]=(0,m.useState)(!1),[L,ve]=(0,m.useState)(),[R,ye]=(0,m.useState)([]),[be,xe]=(0,m.useState)(`off`),[z,B]=(0,m.useState)(``),[V,H]=(0,m.useState)(null),[U,W]=(0,m.useState)(null);async function Se(){let[e,t]=await Promise.all([k(`/api/agent-profiles`),k(`/api/agent-profiles/available-tools`)]);n(e.agents),l(t.tools)}(0,m.useEffect)(()=>{let e=!1;async function t(){try{let[t,r]=await Promise.all([k(`/api/agent-profiles`),k(`/api/agent-profiles/available-tools`)]);if(e)return;n(t.agents),l(r.tools)}catch(t){e||B(t instanceof Error?t.message:d(`requestFailed`))}}return t(),()=>{e=!0}},[]),(0,m.useEffect)(()=>{let e=!1;async function t(){try{let t=await oe(),[n,r]=await Promise.all([le(t),te().catch(()=>[])]),i=r.length?r:n;ye(i);let a=i.filter(f),o=await ce(t),s=(o.model&&f(o.model)?a.find(e=>ue(e,o.model)):void 0)??a[0];if(e)return;ve(s),xe(o.thinkingLevel??se(s))}catch{}}return t(),()=>{e=!0}},[]),(0,m.useEffect)(()=>{if(!V)return;let e=()=>{H(null),W(null)},t=t=>{t.key===`Escape`&&e()};return window.addEventListener(`click`,e),window.addEventListener(`blur`,e),window.addEventListener(`resize`,e),window.addEventListener(`scroll`,e,!0),document.addEventListener(`keydown`,t),()=>{window.removeEventListener(`click`,e),window.removeEventListener(`blur`,e),window.removeEventListener(`resize`,e),window.removeEventListener(`scroll`,e,!0),document.removeEventListener(`keydown`,t)}},[V]);let G=(0,m.useMemo)(()=>e.find(e=>e.id===_)??null,[e,_]),K=(0,m.useMemo)(()=>e.find(e=>e.id===V)??null,[e,V]),q=!!G?.readonly,J=!!(G?.readonly&&!G?.builtin),Y=(0,m.useMemo)(()=>{let e=E(y.fixedModelValue);if(e.mode!==`fixed`)return;let t=D(e);return R.find(e=>T(e)===t)??(`provider`in e?R.find(t=>de(t,e)):void 0)},[y.fixedModelValue,R]),Ce=(0,m.useMemo)(()=>R.filter(f),[R]),we=(0,m.useMemo)(()=>fe(Ce,Y),[Ce,Y]),Te=Y?T(Y):y.fixedModelValue,X=y.modelMode===`fixed`&&!!Y&&Y?.reasoning!==!0;function Ee(e,t){if(e.stopPropagation(),V===t){H(null),W(null);return}let n=e.currentTarget.getBoundingClientRect(),r=Math.max(w,Math.min(n.right-x,window.innerWidth-x-w)),i=n.bottom+C,a=n.top-C-S;W({left:r,top:i+S<=window.innerHeight-w?i:Math.max(w,a)}),H(t)}function Z(e,t){A(n=>({...n,[e]:t}))}function De(e){ae(Y??null,we,e=>Z(`fixedModelValue`,e?T(e):``),{anchor:e.currentTarget,noneLabel:d(`agentModelInherit`)})}function Oe(e){A(t=>({...t,allowedTools:t.allowedTools.includes(e)?t.allowedTools.filter(t=>t!==e):[...t.allowedTools,e]}))}function ke(){v(null),A(O()),P(``),B(``),g(!0)}function Q(e){v(e.id),A(he(e)),P(``),B(``),g(!0)}function $(){j||F||(g(!1),v(null),A(O()),P(``))}async function Ae(){let e=N.trim();if(!e){B(d(`aiFillAgentInputRequired`));return}if(!L){B(d(`aiFillAgentNoModel`));return}I(!0),B(``);try{let t=await k(`/api/agent-profiles/ai-fill`,{method:`POST`,body:JSON.stringify({instruction:e,modelRef:u(L),model:L,thinkingLevel:be})});A(e=>({...e,name:t.agent.name,label:t.agent.label,description:t.agent.description,systemPrompt:t.agent.systemPrompt}))}catch(e){B(e instanceof Error?e.message:d(`aiFillAgentFailed`))}finally{I(!1)}}async function je(){if(!_e(y))return;M(!0),B(``);let e=X&&y.thinkingLevel!==`inherit`?`off`:y.thinkingLevel;try{let t=G?.builtin?{model:y.modelMode===`fixed`?E(y.fixedModelValue):{mode:`inherit`},thinkingLevel:e}:ge({...y,thinkingLevel:e});_?await k(`/api/agent-profiles/${encodeURIComponent(_)}`,{method:`PATCH`,body:JSON.stringify(t)}):await k(`/api/agent-profiles`,{method:`POST`,body:JSON.stringify(t)}),$(),await Se()}catch(e){B(e instanceof Error?e.message:d(`requestFailed`))}finally{M(!1)}}async function Me(e){if(e.builtin||e.readonly)return;let t=!e.enabledAsSubagent,r=e.enabledAsSubagent;n(n=>n.map(n=>n.id===e.id?{...n,enabledAsSubagent:t}:n)),H(null);try{await k(`/api/agent-profiles/${encodeURIComponent(e.id)}`,{method:`PATCH`,body:JSON.stringify({enabledAsSubagent:t})})}catch(t){n(t=>t.map(t=>t.id===e.id?{...t,enabledAsSubagent:r}:t)),B(t instanceof Error?t.message:d(`requestFailed`))}}async function Ne(e){if(!(e.builtin||e.readonly)&&await ie({description:d(`confirmDeleteAgent`),confirmLabel:d(`confirmDelete`),cancelLabel:d(`cancel`),variant:`destructive`})){B(``);try{await k(`/api/agent-profiles/${encodeURIComponent(e.id)}`,{method:`DELETE`}),await Se()}catch(e){B(e instanceof Error?e.message:d(`requestFailed`))}}}return h?(0,b.jsxs)(`div`,{className:`quickforge-settings-stack`,children:[(0,b.jsx)(`div`,{className:`quickforge-settings-heading`,children:(0,b.jsxs)(`h3`,{className:`quickforge-settings-title`,children:[G?.builtin?d(`builtinAgentModelSettings`):d(G?`editAgent`:`createAgent`),(0,b.jsx)(re,{label:G?.builtin?d(`builtinAgentModelOnly`):G?.readonly?d(`readonlyAgentDescription`):d(`agentsDescription`)})]})}),(0,b.jsxs)(`section`,{className:`quickforge-settings-section`,"aria-label":d(G?`editAgent`:`createAgent`),children:[(0,b.jsxs)(`div`,{className:`quickforge-settings-toolbar`,children:[(0,b.jsxs)(`button`,{className:`quickforge-settings-button quickforge-settings-button-secondary`,type:`button`,onClick:$,disabled:j||F,children:[(0,b.jsx)(t,{className:`mr-2 size-4`}),d(`back`)]}),(0,b.jsxs)(`div`,{className:`quickforge-settings-row-main`,children:[(0,b.jsx)(`div`,{className:`quickforge-settings-row-title`,children:G?.builtin?d(`builtinAgentModelSettings`):d(G?`editAgent`:`createAgent`)}),G?.builtin?(0,b.jsx)(`div`,{className:`quickforge-settings-row-description`,children:d(`builtinAgentModelOnly`)}):G?.readonly?(0,b.jsx)(`div`,{className:`quickforge-settings-row-description`,children:d(`readonlyAgentDescription`)}):null]})]}),(0,b.jsx)(`div`,{className:`px-5 py-4`,children:(0,b.jsxs)(`div`,{className:`space-y-4`,children:[(0,b.jsxs)(`div`,{className:`rounded-2xl border border-border bg-muted/20 p-3`,children:[(0,b.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 text-sm font-medium text-foreground`,children:[(0,b.jsx)(i,{className:`size-4 text-primary`}),d(`aiFillAgent`),(0,b.jsx)(re,{label:d(`aiFillAgentDescription`)})]}),(0,b.jsx)(`textarea`,{className:`min-h-20 w-full resize-y rounded-xl border border-input bg-background px-3 py-2 text-sm outline-none transition-colors placeholder:text-muted-foreground/65 focus:border-ring disabled:opacity-60`,value:N,disabled:q||F,onChange:e=>P(e.target.value),placeholder:d(`aiFillAgentPlaceholder`)}),(0,b.jsx)(`div`,{className:`mt-2 flex justify-end`,children:(0,b.jsxs)(p,{variant:`outline`,size:`sm`,onClick:()=>void Ae(),disabled:q||F||!N.trim(),children:[(0,b.jsx)(i,{className:`mr-1 size-3.5`}),d(F?`aiFillAgentLoading`:`aiFillAgent`)]})})]}),(0,b.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,b.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[d(`agentName`),(0,b.jsx)(`input`,{className:`mt-1 h-10 w-full rounded-md border border-input bg-background px-3 text-sm outline-none focus:border-ring disabled:opacity-60`,value:y.name,disabled:q,onChange:e=>Z(`name`,e.target.value),placeholder:`reviewer`})]}),(0,b.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[d(`agentLabel`),(0,b.jsx)(`input`,{className:`mt-1 h-10 w-full rounded-md border border-input bg-background px-3 text-sm outline-none focus:border-ring disabled:opacity-60`,value:y.label,disabled:q,onChange:e=>Z(`label`,e.target.value),placeholder:d(`agentLabelPlaceholder`)})]})]}),G?(0,b.jsxs)(`div`,{className:`rounded-xl border border-border bg-muted/20 px-3 py-2 text-sm`,children:[(0,b.jsx)(`div`,{className:`text-xs font-medium text-muted-foreground`,children:d(`agentSourcePath`)}),(0,b.jsx)(`div`,{className:`mt-1 truncate font-mono text-xs text-foreground`,title:G.source?`${G.source}${G.relativePath?` · ${G.relativePath}`:``}`:void 0,children:G.source?`${G.source}${G.relativePath?` · ${G.relativePath}`:``}`:G.builtin?d(`builtinAgent`):`-`})]}):null,(0,b.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[d(`agentDescription`),(0,b.jsx)(`input`,{className:`mt-1 h-10 w-full rounded-md border border-input bg-background px-3 text-sm outline-none focus:border-ring disabled:opacity-60`,value:y.description,disabled:q,onChange:e=>Z(`description`,e.target.value)})]}),(0,b.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[d(`agentSystemPrompt`),(0,b.jsx)(`textarea`,{className:`mt-1 min-h-36 w-full resize-y rounded-xl border border-input bg-background px-3 py-2 text-sm outline-none focus:border-ring disabled:opacity-60`,value:y.systemPrompt,disabled:q,onChange:e=>Z(`systemPrompt`,e.target.value)})]}),(0,b.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,b.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[d(`agentModelMode`),(0,b.jsxs)(`select`,{className:`mt-1 h-10 w-full rounded-md border border-input bg-background px-3 text-sm outline-none focus:border-ring disabled:opacity-60`,value:y.modelMode,disabled:J,onChange:e=>Z(`modelMode`,e.target.value),children:[(0,b.jsx)(`option`,{value:`inherit`,children:d(`agentModelInherit`)}),(0,b.jsx)(`option`,{value:`fixed`,children:d(`agentModelFixed`)})]})]}),(0,b.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[d(`agentFixedModel`),(0,b.jsxs)(`select`,{className:`quickforge-model-select-desktop mt-1 h-10 w-full rounded-md border border-input bg-background px-3 text-sm outline-none focus:border-ring disabled:opacity-60`,value:Te,disabled:J||y.modelMode!==`fixed`,onChange:e=>Z(`fixedModelValue`,e.target.value),children:[(0,b.jsx)(`option`,{value:``,children:d(`agentModelInherit`)}),we.map(e=>(0,b.jsx)(`option`,{value:T(e),children:ne(e)},T(e)))]}),(0,b.jsxs)(`button`,{type:`button`,className:`quickforge-model-select-mobile mt-1 flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 text-sm text-left outline-none focus:border-ring disabled:opacity-60`,disabled:J||y.modelMode!==`fixed`,onClick:De,children:[(0,b.jsx)(`span`,{className:`truncate`,children:Y?ne(Y):d(`agentModelInherit`)}),(0,b.jsx)(r,{className:`ml-2 size-4 shrink-0 text-muted-foreground`})]})]})]}),(0,b.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[d(`agentThinkingLevel`),(0,b.jsxs)(`select`,{className:`mt-1 h-10 w-full rounded-md border border-input bg-background px-3 text-sm outline-none focus:border-ring disabled:opacity-60`,value:X&&y.thinkingLevel!==`inherit`?`off`:y.thinkingLevel,disabled:J||X,onChange:e=>Z(`thinkingLevel`,e.target.value),children:[(0,b.jsx)(`option`,{value:`inherit`,children:d(`agentThinkingInherit`)}),(0,b.jsx)(`option`,{value:`off`,children:d(`thinkingOff`)}),(0,b.jsx)(`option`,{value:`low`,children:d(`thinkingLow`)}),(0,b.jsx)(`option`,{value:`medium`,children:d(`thinkingMedium`)}),(0,b.jsx)(`option`,{value:`high`,children:d(`thinkingHigh`)}),(0,b.jsx)(`option`,{value:`xhigh`,children:d(`thinkingXHigh`)})]}),(0,b.jsx)(`span`,{className:`mt-1 block text-xs text-muted-foreground`,children:d(X?`agentThinkingUnsupported`:`agentThinkingDescription`)})]}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`div`,{className:`mb-2 text-sm font-medium text-foreground`,children:d(`allowedTools`)}),(0,b.jsx)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:c.map(e=>(0,b.jsxs)(`label`,{className:`flex items-start gap-2 rounded-xl border border-border bg-muted/20 p-3 text-sm disabled:opacity-60`,children:[(0,b.jsx)(`input`,{type:`checkbox`,className:`mt-1`,disabled:q,checked:y.allowedTools.includes(e.name),onChange:()=>Oe(e.name)}),(0,b.jsxs)(`span`,{children:[(0,b.jsx)(`span`,{className:`font-medium text-foreground`,children:e.label}),(0,b.jsx)(`span`,{className:`ml-2 font-mono text-xs text-muted-foreground`,children:e.name}),e.riskLevel===`dangerous`?(0,b.jsx)(`span`,{className:`ml-2 rounded-full bg-amber-500/10 px-2 py-0.5 text-xs text-amber-700`,children:d(`highRiskTool`)}):null,(0,b.jsx)(`span`,{className:`mt-1 block text-xs text-muted-foreground`,children:e.description})]})]},e.name))})]}),(0,b.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,b.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[d(`maxRuntimeMinutes`),(0,b.jsx)(`input`,{type:`number`,min:me,max:60,step:`any`,className:`mt-1 h-10 w-full rounded-md border border-input bg-background px-3 text-sm outline-none focus:border-ring disabled:opacity-60`,value:y.maxRuntimeMinutes,disabled:q,onChange:e=>Z(`maxRuntimeMinutes`,e.target.value)}),(0,b.jsx)(`span`,{className:`mt-1 block text-xs text-muted-foreground`,children:d(`maxRuntimeMinutesHelp`)})]}),(0,b.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[d(`maxToolCalls`),(0,b.jsx)(`input`,{type:`number`,className:`mt-1 h-10 w-full rounded-md border border-input bg-background px-3 text-sm outline-none focus:border-ring disabled:opacity-60`,value:y.maxToolCalls,disabled:q,onChange:e=>Z(`maxToolCalls`,e.target.value)})]})]}),(0,b.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-foreground`,children:[(0,b.jsx)(`input`,{type:`checkbox`,checked:y.enabledAsSubagent,disabled:q,onChange:e=>Z(`enabledAsSubagent`,e.target.checked)}),d(`enabledAsSubagent`)]}),z?(0,b.jsx)(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive`,children:z}):null]})}),(0,b.jsxs)(`div`,{className:`quickforge-settings-divider flex justify-end gap-2 px-5 py-4`,children:[(0,b.jsx)(p,{variant:`outline`,onClick:$,disabled:j||F,children:d(`cancel`)}),(0,b.jsx)(p,{onClick:je,disabled:j||F||J||!G?.builtin&&!_e(y)||y.modelMode===`fixed`&&!y.fixedModelValue,children:d(`save`)})]})]})]}):(0,b.jsxs)(`div`,{className:`quickforge-settings-stack`,children:[(0,b.jsxs)(`section`,{className:`quickforge-settings-section`,"aria-label":d(`agentsTab`),children:[(0,b.jsxs)(`div`,{className:`quickforge-settings-toolbar`,children:[(0,b.jsxs)(`div`,{className:`quickforge-settings-row-main`,children:[(0,b.jsxs)(`div`,{className:`quickforge-settings-row-title`,children:[(0,b.jsx)(ee,{className:`size-4 text-primary`}),d(`agentsTab`)]}),(0,b.jsx)(`div`,{className:`quickforge-settings-row-description`,children:d(`agentsDescription`)})]}),(0,b.jsx)(`button`,{className:`quickforge-settings-button quickforge-settings-button-primary`,type:`button`,onClick:ke,children:d(`createAgent`)})]}),z?(0,b.jsx)(`div`,{className:`quickforge-settings-alert quickforge-settings-warning-attached`,children:z}):null,e.length===0?(0,b.jsx)(`div`,{className:`quickforge-settings-empty-row`,children:d(`loading`)}):e.map(e=>(0,b.jsxs)(`div`,{className:`quickforge-settings-list-item quickforge-agent-profile-row`,role:`button`,tabIndex:0,onClick:()=>Q(e),onKeyDown:t=>{t.target===t.currentTarget&&(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),Q(e))},children:[(0,b.jsx)(`div`,{className:`quickforge-settings-list-item-main quickforge-agent-profile-row-main`,children:(0,b.jsxs)(`div`,{className:`quickforge-agent-profile-summary`,children:[(0,b.jsx)(`span`,{className:`quickforge-agent-profile-label`,title:e.label,children:e.label}),e.description?(0,b.jsx)(`span`,{className:`quickforge-agent-profile-description`,title:e.description,children:e.description}):null]})}),(0,b.jsxs)(`div`,{className:`quickforge-settings-list-item-actions`,onClick:e=>e.stopPropagation(),children:[(0,b.jsxs)(`label`,{className:`quickforge-settings-switch`,"aria-disabled":e.builtin||e.readonly?`true`:`false`,title:e.enabledAsSubagent?d(`disableAsSubagent`):d(`enableAsSubagent`),children:[(0,b.jsx)(`input`,{type:`checkbox`,checked:e.enabledAsSubagent,disabled:e.builtin||e.readonly,onChange:()=>void Me(e)}),(0,b.jsx)(`span`,{"aria-hidden":`true`})]}),(0,b.jsx)(`button`,{className:`quickforge-settings-icon-action`,type:`button`,onClick:t=>Ee(t,e.id),title:d(`moreActions`),"aria-label":d(`moreActions`),"aria-haspopup":`menu`,"aria-expanded":V===e.id,children:(0,b.jsx)(a,{className:`size-4`})})]})]},e.id))]}),K&&U?(0,pe.createPortal)((0,b.jsxs)(`div`,{className:`fixed z-50 w-36 overflow-hidden rounded-xl border border-border bg-popover py-1 text-sm shadow-quickforge`,style:{left:U.left,top:U.top},role:`menu`,"aria-label":d(`moreActions`),onClick:e=>e.stopPropagation(),children:[(0,b.jsxs)(`button`,{className:`flex w-full items-center gap-2 px-3 py-2 text-left hover:bg-muted disabled:cursor-not-allowed disabled:opacity-50`,type:`button`,role:`menuitem`,disabled:K.readonly&&!K.builtin,onClick:()=>{H(null),W(null),Q(K)},children:[(0,b.jsx)(o,{className:`size-3.5`}),d(`editTask`)]}),(0,b.jsxs)(`button`,{className:`flex w-full items-center gap-2 px-3 py-2 text-left text-destructive hover:bg-muted disabled:cursor-not-allowed disabled:opacity-50`,type:`button`,role:`menuitem`,disabled:K.builtin||K.readonly,onClick:()=>{H(null),W(null),Ne(K)},children:[(0,b.jsx)(s,{className:`size-3.5`}),d(`delete`)]})]}),document.body):null]})}export{A as AgentProfilesPage};
1
+ import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{Gt as t,Jt as n,Pt as r,f as i,ht as a,j as o,s,zt as ee}from"./icons-DM_qJ7VJ.js";import{i as c,n as l}from"./react-vendor-BpWW_Nvp.js";import{n as te,r as u,t as ne}from"./model-display-label-CURwH0xM.js";import{Dn as re,Pn as d,Tt as ie,bn as f,ct as ae,fn as oe,kn as p,ln as se,pn as ce,un as le}from"./index-DQBOm9gt.js";import{i as ue,r as de,t as fe}from"./model-identity-CgA6_Pbm.js";var m=e(n(),1),pe=c(),me=1e3/6e4,h=6e4,g=1e3;function _(e){let t=Number.isFinite(e)&&Number(e)>0?Math.max(Math.round(Number(e)),g):60*h;return Number((t/h).toFixed(6)).toString()}function v(e){return Math.max(Math.round(Number(e)*h),g)}function y(e){let t=Number(e);return Number.isFinite(t)&&t>=.016666666666666666&&t<=60}var b=l(),x=144,S=82,C=4,w=8;function T(e){return JSON.stringify(u(e))}function E(e){if(!e)return{mode:`inherit`};try{return{mode:`fixed`,...JSON.parse(e)}}catch{return{mode:`inherit`}}}function D(e){return!e||e.mode!==`fixed`?``:e.source===`cloud`?JSON.stringify({version:1,source:`cloud`,catalogId:e.catalogId}):e.source===`custom`?JSON.stringify({version:1,source:`custom`,providerId:e.providerId,modelId:e.modelId}):JSON.stringify({version:1,source:`legacy-custom`,provider:e.provider,modelId:e.modelId,...e.api?{api:e.api}:{},...e.baseUrl?{baseUrl:e.baseUrl}:{}})}function O(){return{name:``,label:``,description:``,systemPrompt:``,allowedTools:[`read_file`,`grep_files`],maxRuntimeMinutes:`60`,maxToolCalls:`300`,enabledAsSubagent:!0,modelMode:`inherit`,fixedModelValue:``,thinkingLevel:`inherit`}}function he(e){return{name:e.name,label:e.label,description:e.description??``,systemPrompt:e.systemPrompt??``,allowedTools:e.allowedTools??[],maxRuntimeMinutes:_(e.maxRuntimeMs),maxToolCalls:String(e.maxToolCalls??300),enabledAsSubagent:e.enabledAsSubagent,modelMode:e.model?.mode===`fixed`?`fixed`:`inherit`,fixedModelValue:D(e.model),thinkingLevel:e.thinkingLevel??`inherit`}}function ge(e){return{name:e.name.trim().toLowerCase(),label:e.label.trim(),description:e.description.trim(),systemPrompt:e.systemPrompt.trim(),allowedTools:e.allowedTools,maxRuntimeMs:v(e.maxRuntimeMinutes),maxToolCalls:Number(e.maxToolCalls||300),enabledAsSubagent:e.enabledAsSubagent,model:e.modelMode===`fixed`?E(e.fixedModelValue):{mode:`inherit`},thinkingLevel:e.thinkingLevel}}function _e(e){return!!(e.name.trim()&&e.label.trim()&&e.allowedTools.length>0&&y(e.maxRuntimeMinutes))}async function k(e,t){let n=await fetch(e,{...t,headers:{"content-type":`application/json`,...t?.headers}}),r=await n.json().catch(()=>null);if(!n.ok)throw Error(r?.error||`请求失败`);return r}function A(){let[e,n]=(0,m.useState)([]),[c,l]=(0,m.useState)([]),[h,g]=(0,m.useState)(!1),[_,v]=(0,m.useState)(null),[y,A]=(0,m.useState)(()=>O()),[j,M]=(0,m.useState)(!1),[N,P]=(0,m.useState)(``),[F,I]=(0,m.useState)(!1),[L,ve]=(0,m.useState)(),[R,ye]=(0,m.useState)([]),[be,xe]=(0,m.useState)(`off`),[z,B]=(0,m.useState)(``),[V,H]=(0,m.useState)(null),[U,W]=(0,m.useState)(null);async function Se(){let[e,t]=await Promise.all([k(`/api/agent-profiles`),k(`/api/agent-profiles/available-tools`)]);n(e.agents),l(t.tools)}(0,m.useEffect)(()=>{let e=!1;async function t(){try{let[t,r]=await Promise.all([k(`/api/agent-profiles`),k(`/api/agent-profiles/available-tools`)]);if(e)return;n(t.agents),l(r.tools)}catch(t){e||B(t instanceof Error?t.message:d(`requestFailed`))}}return t(),()=>{e=!0}},[]),(0,m.useEffect)(()=>{let e=!1;async function t(){try{let t=await oe(),[n,r]=await Promise.all([le(t),te().catch(()=>[])]),i=r.length?r:n;ye(i);let a=i.filter(f),o=await ce(t),s=(o.model&&f(o.model)?a.find(e=>ue(e,o.model)):void 0)??a[0];if(e)return;ve(s),xe(o.thinkingLevel??se(s))}catch{}}return t(),()=>{e=!0}},[]),(0,m.useEffect)(()=>{if(!V)return;let e=()=>{H(null),W(null)},t=t=>{t.key===`Escape`&&e()};return window.addEventListener(`click`,e),window.addEventListener(`blur`,e),window.addEventListener(`resize`,e),window.addEventListener(`scroll`,e,!0),document.addEventListener(`keydown`,t),()=>{window.removeEventListener(`click`,e),window.removeEventListener(`blur`,e),window.removeEventListener(`resize`,e),window.removeEventListener(`scroll`,e,!0),document.removeEventListener(`keydown`,t)}},[V]);let G=(0,m.useMemo)(()=>e.find(e=>e.id===_)??null,[e,_]),K=(0,m.useMemo)(()=>e.find(e=>e.id===V)??null,[e,V]),q=!!G?.readonly,J=!!(G?.readonly&&!G?.builtin),Y=(0,m.useMemo)(()=>{let e=E(y.fixedModelValue);if(e.mode!==`fixed`)return;let t=D(e);return R.find(e=>T(e)===t)??(`provider`in e?R.find(t=>de(t,e)):void 0)},[y.fixedModelValue,R]),Ce=(0,m.useMemo)(()=>R.filter(f),[R]),we=(0,m.useMemo)(()=>fe(Ce,Y),[Ce,Y]),Te=Y?T(Y):y.fixedModelValue,X=y.modelMode===`fixed`&&!!Y&&Y?.reasoning!==!0;function Ee(e,t){if(e.stopPropagation(),V===t){H(null),W(null);return}let n=e.currentTarget.getBoundingClientRect(),r=Math.max(w,Math.min(n.right-x,window.innerWidth-x-w)),i=n.bottom+C,a=n.top-C-S;W({left:r,top:i+S<=window.innerHeight-w?i:Math.max(w,a)}),H(t)}function Z(e,t){A(n=>({...n,[e]:t}))}function De(e){ae(Y??null,we,e=>Z(`fixedModelValue`,e?T(e):``),{anchor:e.currentTarget,noneLabel:d(`agentModelInherit`)})}function Oe(e){A(t=>({...t,allowedTools:t.allowedTools.includes(e)?t.allowedTools.filter(t=>t!==e):[...t.allowedTools,e]}))}function ke(){v(null),A(O()),P(``),B(``),g(!0)}function Q(e){v(e.id),A(he(e)),P(``),B(``),g(!0)}function $(){j||F||(g(!1),v(null),A(O()),P(``))}async function Ae(){let e=N.trim();if(!e){B(d(`aiFillAgentInputRequired`));return}if(!L){B(d(`aiFillAgentNoModel`));return}I(!0),B(``);try{let t=await k(`/api/agent-profiles/ai-fill`,{method:`POST`,body:JSON.stringify({instruction:e,modelRef:u(L),model:L,thinkingLevel:be})});A(e=>({...e,name:t.agent.name,label:t.agent.label,description:t.agent.description,systemPrompt:t.agent.systemPrompt}))}catch(e){B(e instanceof Error?e.message:d(`aiFillAgentFailed`))}finally{I(!1)}}async function je(){if(!_e(y))return;M(!0),B(``);let e=X&&y.thinkingLevel!==`inherit`?`off`:y.thinkingLevel;try{let t=G?.builtin?{model:y.modelMode===`fixed`?E(y.fixedModelValue):{mode:`inherit`},thinkingLevel:e}:ge({...y,thinkingLevel:e});_?await k(`/api/agent-profiles/${encodeURIComponent(_)}`,{method:`PATCH`,body:JSON.stringify(t)}):await k(`/api/agent-profiles`,{method:`POST`,body:JSON.stringify(t)}),$(),await Se()}catch(e){B(e instanceof Error?e.message:d(`requestFailed`))}finally{M(!1)}}async function Me(e){if(e.builtin||e.readonly)return;let t=!e.enabledAsSubagent,r=e.enabledAsSubagent;n(n=>n.map(n=>n.id===e.id?{...n,enabledAsSubagent:t}:n)),H(null);try{await k(`/api/agent-profiles/${encodeURIComponent(e.id)}`,{method:`PATCH`,body:JSON.stringify({enabledAsSubagent:t})})}catch(t){n(t=>t.map(t=>t.id===e.id?{...t,enabledAsSubagent:r}:t)),B(t instanceof Error?t.message:d(`requestFailed`))}}async function Ne(e){if(!(e.builtin||e.readonly)&&await ie({description:d(`confirmDeleteAgent`),confirmLabel:d(`confirmDelete`),cancelLabel:d(`cancel`),variant:`destructive`})){B(``);try{await k(`/api/agent-profiles/${encodeURIComponent(e.id)}`,{method:`DELETE`}),await Se()}catch(e){B(e instanceof Error?e.message:d(`requestFailed`))}}}return h?(0,b.jsxs)(`div`,{className:`quickforge-settings-stack`,children:[(0,b.jsx)(`div`,{className:`quickforge-settings-heading`,children:(0,b.jsxs)(`h3`,{className:`quickforge-settings-title`,children:[G?.builtin?d(`builtinAgentModelSettings`):d(G?`editAgent`:`createAgent`),(0,b.jsx)(re,{label:G?.builtin?d(`builtinAgentModelOnly`):G?.readonly?d(`readonlyAgentDescription`):d(`agentsDescription`)})]})}),(0,b.jsxs)(`section`,{className:`quickforge-settings-section`,"aria-label":d(G?`editAgent`:`createAgent`),children:[(0,b.jsxs)(`div`,{className:`quickforge-settings-toolbar`,children:[(0,b.jsxs)(`button`,{className:`quickforge-settings-button quickforge-settings-button-secondary`,type:`button`,onClick:$,disabled:j||F,children:[(0,b.jsx)(t,{className:`mr-2 size-4`}),d(`back`)]}),(0,b.jsxs)(`div`,{className:`quickforge-settings-row-main`,children:[(0,b.jsx)(`div`,{className:`quickforge-settings-row-title`,children:G?.builtin?d(`builtinAgentModelSettings`):d(G?`editAgent`:`createAgent`)}),G?.builtin?(0,b.jsx)(`div`,{className:`quickforge-settings-row-description`,children:d(`builtinAgentModelOnly`)}):G?.readonly?(0,b.jsx)(`div`,{className:`quickforge-settings-row-description`,children:d(`readonlyAgentDescription`)}):null]})]}),(0,b.jsx)(`div`,{className:`px-5 py-4`,children:(0,b.jsxs)(`div`,{className:`space-y-4`,children:[(0,b.jsxs)(`div`,{className:`rounded-2xl border border-border bg-muted/20 p-3`,children:[(0,b.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 text-sm font-medium text-foreground`,children:[(0,b.jsx)(i,{className:`size-4 text-primary`}),d(`aiFillAgent`),(0,b.jsx)(re,{label:d(`aiFillAgentDescription`)})]}),(0,b.jsx)(`textarea`,{className:`min-h-20 w-full resize-y rounded-xl border border-input bg-background px-3 py-2 text-sm outline-none transition-colors placeholder:text-muted-foreground/65 focus:border-ring disabled:opacity-60`,value:N,disabled:q||F,onChange:e=>P(e.target.value),placeholder:d(`aiFillAgentPlaceholder`)}),(0,b.jsx)(`div`,{className:`mt-2 flex justify-end`,children:(0,b.jsxs)(p,{variant:`outline`,size:`sm`,onClick:()=>void Ae(),disabled:q||F||!N.trim(),children:[(0,b.jsx)(i,{className:`mr-1 size-3.5`}),d(F?`aiFillAgentLoading`:`aiFillAgent`)]})})]}),(0,b.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,b.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[d(`agentName`),(0,b.jsx)(`input`,{className:`mt-1 h-10 w-full rounded-md border border-input bg-background px-3 text-sm outline-none focus:border-ring disabled:opacity-60`,value:y.name,disabled:q,onChange:e=>Z(`name`,e.target.value),placeholder:`reviewer`})]}),(0,b.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[d(`agentLabel`),(0,b.jsx)(`input`,{className:`mt-1 h-10 w-full rounded-md border border-input bg-background px-3 text-sm outline-none focus:border-ring disabled:opacity-60`,value:y.label,disabled:q,onChange:e=>Z(`label`,e.target.value),placeholder:d(`agentLabelPlaceholder`)})]})]}),G?(0,b.jsxs)(`div`,{className:`rounded-xl border border-border bg-muted/20 px-3 py-2 text-sm`,children:[(0,b.jsx)(`div`,{className:`text-xs font-medium text-muted-foreground`,children:d(`agentSourcePath`)}),(0,b.jsx)(`div`,{className:`mt-1 truncate font-mono text-xs text-foreground`,title:G.source?`${G.source}${G.relativePath?` · ${G.relativePath}`:``}`:void 0,children:G.source?`${G.source}${G.relativePath?` · ${G.relativePath}`:``}`:G.builtin?d(`builtinAgent`):`-`})]}):null,(0,b.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[d(`agentDescription`),(0,b.jsx)(`input`,{className:`mt-1 h-10 w-full rounded-md border border-input bg-background px-3 text-sm outline-none focus:border-ring disabled:opacity-60`,value:y.description,disabled:q,onChange:e=>Z(`description`,e.target.value)})]}),(0,b.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[d(`agentSystemPrompt`),(0,b.jsx)(`textarea`,{className:`mt-1 min-h-36 w-full resize-y rounded-xl border border-input bg-background px-3 py-2 text-sm outline-none focus:border-ring disabled:opacity-60`,value:y.systemPrompt,disabled:q,onChange:e=>Z(`systemPrompt`,e.target.value)})]}),(0,b.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,b.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[d(`agentModelMode`),(0,b.jsxs)(`select`,{className:`mt-1 h-10 w-full rounded-md border border-input bg-background px-3 text-sm outline-none focus:border-ring disabled:opacity-60`,value:y.modelMode,disabled:J,onChange:e=>Z(`modelMode`,e.target.value),children:[(0,b.jsx)(`option`,{value:`inherit`,children:d(`agentModelInherit`)}),(0,b.jsx)(`option`,{value:`fixed`,children:d(`agentModelFixed`)})]})]}),(0,b.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[d(`agentFixedModel`),(0,b.jsxs)(`select`,{className:`quickforge-model-select-desktop mt-1 h-10 w-full rounded-md border border-input bg-background px-3 text-sm outline-none focus:border-ring disabled:opacity-60`,value:Te,disabled:J||y.modelMode!==`fixed`,onChange:e=>Z(`fixedModelValue`,e.target.value),children:[(0,b.jsx)(`option`,{value:``,children:d(`agentModelInherit`)}),we.map(e=>(0,b.jsx)(`option`,{value:T(e),children:ne(e)},T(e)))]}),(0,b.jsxs)(`button`,{type:`button`,className:`quickforge-model-select-mobile mt-1 flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 text-sm text-left outline-none focus:border-ring disabled:opacity-60`,disabled:J||y.modelMode!==`fixed`,onClick:De,children:[(0,b.jsx)(`span`,{className:`truncate`,children:Y?ne(Y):d(`agentModelInherit`)}),(0,b.jsx)(r,{className:`ml-2 size-4 shrink-0 text-muted-foreground`})]})]})]}),(0,b.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[d(`agentThinkingLevel`),(0,b.jsxs)(`select`,{className:`mt-1 h-10 w-full rounded-md border border-input bg-background px-3 text-sm outline-none focus:border-ring disabled:opacity-60`,value:X&&y.thinkingLevel!==`inherit`?`off`:y.thinkingLevel,disabled:J||X,onChange:e=>Z(`thinkingLevel`,e.target.value),children:[(0,b.jsx)(`option`,{value:`inherit`,children:d(`agentThinkingInherit`)}),(0,b.jsx)(`option`,{value:`off`,children:d(`thinkingOff`)}),(0,b.jsx)(`option`,{value:`low`,children:d(`thinkingLow`)}),(0,b.jsx)(`option`,{value:`medium`,children:d(`thinkingMedium`)}),(0,b.jsx)(`option`,{value:`high`,children:d(`thinkingHigh`)}),(0,b.jsx)(`option`,{value:`xhigh`,children:d(`thinkingXHigh`)})]}),(0,b.jsx)(`span`,{className:`mt-1 block text-xs text-muted-foreground`,children:d(X?`agentThinkingUnsupported`:`agentThinkingDescription`)})]}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`div`,{className:`mb-2 text-sm font-medium text-foreground`,children:d(`allowedTools`)}),(0,b.jsx)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:c.map(e=>(0,b.jsxs)(`label`,{className:`flex items-start gap-2 rounded-xl border border-border bg-muted/20 p-3 text-sm disabled:opacity-60`,children:[(0,b.jsx)(`input`,{type:`checkbox`,className:`mt-1`,disabled:q,checked:y.allowedTools.includes(e.name),onChange:()=>Oe(e.name)}),(0,b.jsxs)(`span`,{children:[(0,b.jsx)(`span`,{className:`font-medium text-foreground`,children:e.label}),(0,b.jsx)(`span`,{className:`ml-2 font-mono text-xs text-muted-foreground`,children:e.name}),e.riskLevel===`dangerous`?(0,b.jsx)(`span`,{className:`ml-2 rounded-full bg-amber-500/10 px-2 py-0.5 text-xs text-amber-700`,children:d(`highRiskTool`)}):null,(0,b.jsx)(`span`,{className:`mt-1 block text-xs text-muted-foreground`,children:e.description})]})]},e.name))})]}),(0,b.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,b.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[d(`maxRuntimeMinutes`),(0,b.jsx)(`input`,{type:`number`,min:me,max:60,step:`any`,className:`mt-1 h-10 w-full rounded-md border border-input bg-background px-3 text-sm outline-none focus:border-ring disabled:opacity-60`,value:y.maxRuntimeMinutes,disabled:q,onChange:e=>Z(`maxRuntimeMinutes`,e.target.value)}),(0,b.jsx)(`span`,{className:`mt-1 block text-xs text-muted-foreground`,children:d(`maxRuntimeMinutesHelp`)})]}),(0,b.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[d(`maxToolCalls`),(0,b.jsx)(`input`,{type:`number`,className:`mt-1 h-10 w-full rounded-md border border-input bg-background px-3 text-sm outline-none focus:border-ring disabled:opacity-60`,value:y.maxToolCalls,disabled:q,onChange:e=>Z(`maxToolCalls`,e.target.value)})]})]}),(0,b.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-foreground`,children:[(0,b.jsx)(`input`,{type:`checkbox`,checked:y.enabledAsSubagent,disabled:q,onChange:e=>Z(`enabledAsSubagent`,e.target.checked)}),d(`enabledAsSubagent`)]}),z?(0,b.jsx)(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive`,children:z}):null]})}),(0,b.jsxs)(`div`,{className:`quickforge-settings-divider flex justify-end gap-2 px-5 py-4`,children:[(0,b.jsx)(p,{variant:`outline`,onClick:$,disabled:j||F,children:d(`cancel`)}),(0,b.jsx)(p,{onClick:je,disabled:j||F||J||!G?.builtin&&!_e(y)||y.modelMode===`fixed`&&!y.fixedModelValue,children:d(`save`)})]})]})]}):(0,b.jsxs)(`div`,{className:`quickforge-settings-stack`,children:[(0,b.jsxs)(`section`,{className:`quickforge-settings-section`,"aria-label":d(`agentsTab`),children:[(0,b.jsxs)(`div`,{className:`quickforge-settings-toolbar`,children:[(0,b.jsxs)(`div`,{className:`quickforge-settings-row-main`,children:[(0,b.jsxs)(`div`,{className:`quickforge-settings-row-title`,children:[(0,b.jsx)(ee,{className:`size-4 text-primary`}),d(`agentsTab`)]}),(0,b.jsx)(`div`,{className:`quickforge-settings-row-description`,children:d(`agentsDescription`)})]}),(0,b.jsx)(`button`,{className:`quickforge-settings-button quickforge-settings-button-primary`,type:`button`,onClick:ke,children:d(`createAgent`)})]}),z?(0,b.jsx)(`div`,{className:`quickforge-settings-alert quickforge-settings-warning-attached`,children:z}):null,e.length===0?(0,b.jsx)(`div`,{className:`quickforge-settings-empty-row`,children:d(`loading`)}):e.map(e=>(0,b.jsxs)(`div`,{className:`quickforge-settings-list-item quickforge-agent-profile-row`,role:`button`,tabIndex:0,onClick:()=>Q(e),onKeyDown:t=>{t.target===t.currentTarget&&(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),Q(e))},children:[(0,b.jsx)(`div`,{className:`quickforge-settings-list-item-main quickforge-agent-profile-row-main`,children:(0,b.jsxs)(`div`,{className:`quickforge-agent-profile-summary`,children:[(0,b.jsx)(`span`,{className:`quickforge-agent-profile-label`,title:e.label,children:e.label}),e.description?(0,b.jsx)(`span`,{className:`quickforge-agent-profile-description`,title:e.description,children:e.description}):null]})}),(0,b.jsxs)(`div`,{className:`quickforge-settings-list-item-actions`,onClick:e=>e.stopPropagation(),children:[(0,b.jsxs)(`label`,{className:`quickforge-settings-switch`,"aria-disabled":e.builtin||e.readonly?`true`:`false`,title:e.enabledAsSubagent?d(`disableAsSubagent`):d(`enableAsSubagent`),children:[(0,b.jsx)(`input`,{type:`checkbox`,checked:e.enabledAsSubagent,disabled:e.builtin||e.readonly,onChange:()=>void Me(e)}),(0,b.jsx)(`span`,{"aria-hidden":`true`})]}),(0,b.jsx)(`button`,{className:`quickforge-settings-icon-action`,type:`button`,onClick:t=>Ee(t,e.id),title:d(`moreActions`),"aria-label":d(`moreActions`),"aria-haspopup":`menu`,"aria-expanded":V===e.id,children:(0,b.jsx)(a,{className:`size-4`})})]})]},e.id))]}),K&&U?(0,pe.createPortal)((0,b.jsxs)(`div`,{className:`fixed z-50 w-36 overflow-hidden rounded-xl border border-border bg-popover py-1 text-sm shadow-quickforge`,style:{left:U.left,top:U.top},role:`menu`,"aria-label":d(`moreActions`),onClick:e=>e.stopPropagation(),children:[(0,b.jsxs)(`button`,{className:`flex w-full items-center gap-2 px-3 py-2 text-left hover:bg-muted disabled:cursor-not-allowed disabled:opacity-50`,type:`button`,role:`menuitem`,disabled:K.readonly&&!K.builtin,onClick:()=>{H(null),W(null),Q(K)},children:[(0,b.jsx)(o,{className:`size-3.5`}),d(`editTask`)]}),(0,b.jsxs)(`button`,{className:`flex w-full items-center gap-2 px-3 py-2 text-left text-destructive hover:bg-muted disabled:cursor-not-allowed disabled:opacity-50`,type:`button`,role:`menuitem`,disabled:K.builtin||K.readonly,onClick:()=>{H(null),W(null),Ne(K)},children:[(0,b.jsx)(s,{className:`size-3.5`}),d(`delete`)]})]}),document.body):null]})}export{A as AgentProfilesPage};
@@ -1,4 +1,4 @@
1
- import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{Jt as t}from"./icons-DM_qJ7VJ.js";import{n}from"./react-vendor-BpWW_Nvp.js";import{g as r,h as i}from"./pi-web-ui-DV5jKjSg.js";import{t as a}from"./logger-8REuLPGK.js";import{i as o}from"./model-display-label-CURwH0xM.js";import{At as s,Kt as c,Pn as l,Ut as u,V as d,Wt as f,k as p,n as m,o as h,t as g}from"./index-DFASc15l.js";import{c as _,d as v,f as y,g as b,h as x,i as ee,l as S,m as C,n as te,p as ne,r as re,t as ie,u as ae}from"./local-tools-Dn1Y9aPe.js";import{t as w}from"./plugin-api-BrdQeM4B.js";var T=e(t(),1);function oe({panel:e,onReachTop:t,onAutoScrollEnabled:n}){let r=!0,i,a=0,o,s=-1/0,c=-1/0,l,u=0,d=()=>e.querySelector(`agent-interface .overflow-y-auto`),f=e=>e.scrollHeight-e.scrollTop-e.clientHeight<=80,p=t=>{e.querySelector(`agent-interface`)?.setAutoScroll?.(t)},m=()=>{let e=Math.max(s,c);return window.performance.now()-e<=500},h=()=>{i!==void 0&&(window.cancelAnimationFrame(i),i=void 0),r=!1,p(!1)},g=()=>{s=window.performance.now(),h()},_=()=>{c=window.performance.now()},v=()=>{let e=d();if(!e||!r)return;let t=e.scrollHeight-e.clientHeight;if(Math.abs(e.scrollTop-t)<=1){a=e.scrollTop;return}e.scrollTop=e.scrollHeight,a=e.scrollTop},y=()=>{i===void 0&&(i=window.requestAnimationFrame(()=>{i=void 0,v(),window.requestAnimationFrame(v)}))},b=()=>{r=!0,p(!0),n?.(),y()},x=()=>{let e=d();if(!e)return;let n=e.scrollTop,i=n<a-1;if(u>0){a=n;return}n<=0&&a>0&&t?.();let o=i&&m();if(i&&r&&!o&&!f(e)){a=n,y();return}o?h():f(e)&&(r=!0,p(!0)),a=n},ee=e=>{e.deltaY<0&&g()},S=e=>{e.target===e.currentTarget&&_()},C=e=>{(e.key===`ArrowUp`||e.key===`PageUp`||e.key===`Home`)&&g()},te=e=>{o=e.touches[0]?.clientY},ne=e=>{let t=e.touches[0]?.clientY;t===void 0||o===void 0||(t>o+1&&g(),o=t)};return{get isEnabled(){return r},beginProgrammaticScroll:()=>(u+=1,h(),()=>{u=Math.max(0,u-1);let e=d();e&&(a=e.scrollTop)}),enable:b,disable:h,scheduleScrollToBottom:y,setup:()=>{let t=d();if(!t||l)return;a=t.scrollTop,t.addEventListener(`scroll`,x,{passive:!0}),t.addEventListener(`wheel`,ee,{passive:!0}),t.addEventListener(`pointerdown`,S,{passive:!0}),t.addEventListener(`keydown`,C),t.addEventListener(`touchstart`,te,{passive:!0}),t.addEventListener(`touchmove`,ne,{passive:!0}),l=new ResizeObserver(()=>{r&&y()}),l.observe(t);let n=t.querySelector(`.max-w-3xl`);n&&l.observe(n);let i=e.querySelector(`.quickforge-composer-dock`);i&&l.observe(i),b()},cleanup:()=>{let e=d();e?.removeEventListener(`scroll`,x),e?.removeEventListener(`wheel`,ee),e?.removeEventListener(`pointerdown`,S),e?.removeEventListener(`keydown`,C),e?.removeEventListener(`touchstart`,te),e?.removeEventListener(`touchmove`,ne),l?.disconnect(),l=void 0,i!==void 0&&(window.cancelAnimationFrame(i),i=void 0)}}}function E(e){return e.role===`user`||e.role===`user-with-attachments`}function D(e){let t=[];for(let n=0;n<e.length;n++)E(e[n])&&t.push(n);return t}function se(e,t){if(typeof e==`string`)return Math.min(e.length,t);if(!Array.isArray(e))return 0;let n=0;for(let r of e){if(n>=t)break;if(typeof r==`string`){n+=Math.min(r.length,t-n);continue}if(!r||typeof r!=`object`)continue;let e=r;for(let r of[`text`,`content`,`arguments`]){let i=e[r];if(typeof i==`string`&&(n+=Math.min(i.length,t-n),n>=t))break}}return n}function ce(e,t){let n=0;for(let r of e)if(n+=se(r.content,t-n),n>=t)return!0;return!1}function le(e,t){if(e.role!==`assistant`)return;let n=Array.isArray(e.content)?e.content:[];for(let e of n){if(!e||typeof e!=`object`)continue;let n=e;n.type!==`toolCall`||!n.id||t.add(n.id)}}function O(e,t,n){let r=e.slice(t,n),i=new Set;for(let r=t;r<n;r++)le(e[r],i);if(i.size===0)return r;let a=[];for(let r=0;r<e.length;r++){if(r>=t&&r<n)continue;let o=e[r];o.role===`toolResult`&&typeof o.toolCallId==`string`&&i.has(o.toolCallId)&&a.push(o)}return a.length>0?[...r,...a]:r}function ue(e={}){let t=e.enabled??!0,n=e.enableTurns??6,r=e.enableMessages??48,i=e.enableContentChars??8e4,a=e.windowTurns??3,o=e.pageTurns??3,s=[],c=[],l=a,u=0,d=0,f=[],p=!1,m=!1,h=e=>Math.max(0,e-l),g=()=>{let e=u===0?0:c[u],t=Math.min(c.length,u+l),n=t<c.length?c[t]:s.length;d=e,f=O(s,e,n)};return{setFullMessages(e){s=e,c=D(e);let o=c.length;return l=Math.min(a,Math.max(1,o-1)),m=t&&o>1&&(o>n||e.length>r||ce(e,i)),m?(u=p?Math.max(0,Math.min(u,h(o))):h(o),g(),f):(u=0,d=0,f=e,p=!1,e)},getWindowStart(){return d},getWindowMessages(){return f},isEnabled(){return m},hasMore(){return m&&u>0},loadMore(){return!m||u<=0?null:(p=!0,u=Math.max(0,u-o),g(),f)},showMessageIndex(e){if(!m||c.length===0)return null;let t=Math.max(0,Math.min(e,s.length-1)),n=0;for(let e=0;e<c.length&&!(c[e]>t);e++)n=e;let r=Math.min(c.length,u+l);return n>=u&&n<r?f:(p=!0,u=Math.min(n,h(c.length)),g(),f)},resetToTail(){p=!1},isAssignedWindow(e){return e===f}}}var de=!1,k=null;function fe(){return customElements.get(`message-list`)||null}function pe(e){if(k=e(),de)return;let t=()=>{let e=fe();if(!e)return!1;let t=Object.getOwnPropertyDescriptor(e,`messages`);if(!t||typeof t.set!=`function`)return!1;de=!0;let n=t.set;return Object.defineProperty(e,`messages`,{...t,set(e){let t=k,r=this.hasAttribute(`data-quickforge-subagent-process`);if(t&&!r){if(t.isAssignedWindow(e)){n.call(this,e);return}n.call(this,t.setFullMessages(e));return}n.call(this,e)}}),!0};t()||customElements.whenDefined(`message-list`).then(()=>{t()})}function me(e){k===e&&(k=null)}function he({panel:e,getCustomCommands:t,restoreDraftIntoComposer:n}){let r=e=>`/${e.name}${e.argumentHint?` ${e.argumentHint}`:``}`,i=()=>[{name:`init`,description:l(`initCommandDescription`),argumentHint:``},{name:`plan`,description:l(`planCommandDescription`),argumentHint:`[task]`},{name:`review`,description:l(`reviewCommandDescription`),argumentHint:`[scope]`},{name:`summary`,description:l(`summaryCommandDescription`),argumentHint:``},{name:`compact`,description:l(`compactCommandDescription`),argumentHint:``},{name:`clear`,description:l(`clearCommandDescription`),argumentHint:``},{name:`help`,description:l(`helpCommandDescription`),argumentHint:``}],a=()=>{let n=(e.querySelector(`.quickforge-command-suggestions`)?.querySelector(`.quickforge-command-suggestion-item`))?.dataset.quickforgeCommandName;if(n)return[...i(),...t()].find(e=>e.name===n)},o=()=>{let t=e.querySelector(`.quickforge-command-suggestions`);t?.__quickforgeDismissHandler&&(document.removeEventListener(`pointerdown`,t.__quickforgeDismissHandler,!0),t.__quickforgeDismissHandler=void 0),t?.remove()},s=t=>{let r=e.querySelector(`message-editor`),i=`/${t.name}${t.argumentHint?` `:``}`;n({text:i,attachments:[]});let a=r?.querySelector(`textarea`);a?.focus(),a&&(a.selectionStart=i.length,a.selectionEnd=i.length),o()};return{update:n=>{let a=e.querySelector(`message-editor`),c=n??a?.value??a?.querySelector(`textarea`)?.value??``,u=a?.querySelector(`textarea`),d=e.querySelector(`.quickforge-command-suggestions`);if(!a||!u||!c.startsWith(`/`)){d?.remove();return}let f=c.slice(1).trim().toLowerCase(),p=t(),m=[...i(),...p].filter(e=>e.name.includes(f)||e.description?.toLowerCase().includes(f));if(m.length===0){d?.remove();return}let h=d??document.createElement(`div`);h.className=`quickforge-command-suggestions`,h.setAttribute(`role`,`listbox`),h.innerHTML=``;let g=document.createElement(`div`);g.className=`quickforge-command-suggestions-header`,g.textContent=l(p.length?`customCommandsHint`:`customCommandsEmptyHint`),h.append(g);for(let e of m){let t=document.createElement(`button`);t.type=`button`,t.className=`quickforge-command-suggestion-item`,t.dataset.quickforgeCommandName=e.name,t.setAttribute(`role`,`option`),t.innerHTML=`
1
+ import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{Jt as t}from"./icons-DM_qJ7VJ.js";import{n}from"./react-vendor-BpWW_Nvp.js";import{g as r,h as i}from"./pi-web-ui-DV5jKjSg.js";import{t as a}from"./logger-8REuLPGK.js";import{i as o}from"./model-display-label-CURwH0xM.js";import{At as s,Kt as c,Pn as l,Ut as u,V as d,Wt as f,k as p,n as m,o as h,t as g}from"./index-DQBOm9gt.js";import{c as _,d as v,f as y,g as b,h as x,i as ee,l as S,m as C,n as te,p as ne,r as re,t as ie,u as ae}from"./local-tools-BxfQeIUQ.js";import{t as w}from"./plugin-api-BrdQeM4B.js";var T=e(t(),1);function oe({panel:e,onReachTop:t,onAutoScrollEnabled:n}){let r=!0,i,a=0,o,s=-1/0,c=-1/0,l,u=0,d=()=>e.querySelector(`agent-interface .overflow-y-auto`),f=e=>e.scrollHeight-e.scrollTop-e.clientHeight<=80,p=t=>{e.querySelector(`agent-interface`)?.setAutoScroll?.(t)},m=()=>{let e=Math.max(s,c);return window.performance.now()-e<=500},h=()=>{i!==void 0&&(window.cancelAnimationFrame(i),i=void 0),r=!1,p(!1)},g=()=>{s=window.performance.now(),h()},_=()=>{c=window.performance.now()},v=()=>{let e=d();if(!e||!r)return;let t=e.scrollHeight-e.clientHeight;if(Math.abs(e.scrollTop-t)<=1){a=e.scrollTop;return}e.scrollTop=e.scrollHeight,a=e.scrollTop},y=()=>{i===void 0&&(i=window.requestAnimationFrame(()=>{i=void 0,v(),window.requestAnimationFrame(v)}))},b=()=>{r=!0,p(!0),n?.(),y()},x=()=>{let e=d();if(!e)return;let n=e.scrollTop,i=n<a-1;if(u>0){a=n;return}n<=0&&a>0&&t?.();let o=i&&m();if(i&&r&&!o&&!f(e)){a=n,y();return}o?h():f(e)&&(r=!0,p(!0)),a=n},ee=e=>{e.deltaY<0&&g()},S=e=>{e.target===e.currentTarget&&_()},C=e=>{(e.key===`ArrowUp`||e.key===`PageUp`||e.key===`Home`)&&g()},te=e=>{o=e.touches[0]?.clientY},ne=e=>{let t=e.touches[0]?.clientY;t===void 0||o===void 0||(t>o+1&&g(),o=t)};return{get isEnabled(){return r},beginProgrammaticScroll:()=>(u+=1,h(),()=>{u=Math.max(0,u-1);let e=d();e&&(a=e.scrollTop)}),enable:b,disable:h,scheduleScrollToBottom:y,setup:()=>{let t=d();if(!t||l)return;a=t.scrollTop,t.addEventListener(`scroll`,x,{passive:!0}),t.addEventListener(`wheel`,ee,{passive:!0}),t.addEventListener(`pointerdown`,S,{passive:!0}),t.addEventListener(`keydown`,C),t.addEventListener(`touchstart`,te,{passive:!0}),t.addEventListener(`touchmove`,ne,{passive:!0}),l=new ResizeObserver(()=>{r&&y()}),l.observe(t);let n=t.querySelector(`.max-w-3xl`);n&&l.observe(n);let i=e.querySelector(`.quickforge-composer-dock`);i&&l.observe(i),b()},cleanup:()=>{let e=d();e?.removeEventListener(`scroll`,x),e?.removeEventListener(`wheel`,ee),e?.removeEventListener(`pointerdown`,S),e?.removeEventListener(`keydown`,C),e?.removeEventListener(`touchstart`,te),e?.removeEventListener(`touchmove`,ne),l?.disconnect(),l=void 0,i!==void 0&&(window.cancelAnimationFrame(i),i=void 0)}}}function E(e){return e.role===`user`||e.role===`user-with-attachments`}function D(e){let t=[];for(let n=0;n<e.length;n++)E(e[n])&&t.push(n);return t}function se(e,t){if(typeof e==`string`)return Math.min(e.length,t);if(!Array.isArray(e))return 0;let n=0;for(let r of e){if(n>=t)break;if(typeof r==`string`){n+=Math.min(r.length,t-n);continue}if(!r||typeof r!=`object`)continue;let e=r;for(let r of[`text`,`content`,`arguments`]){let i=e[r];if(typeof i==`string`&&(n+=Math.min(i.length,t-n),n>=t))break}}return n}function ce(e,t){let n=0;for(let r of e)if(n+=se(r.content,t-n),n>=t)return!0;return!1}function le(e,t){if(e.role!==`assistant`)return;let n=Array.isArray(e.content)?e.content:[];for(let e of n){if(!e||typeof e!=`object`)continue;let n=e;n.type!==`toolCall`||!n.id||t.add(n.id)}}function O(e,t,n){let r=e.slice(t,n),i=new Set;for(let r=t;r<n;r++)le(e[r],i);if(i.size===0)return r;let a=[];for(let r=0;r<e.length;r++){if(r>=t&&r<n)continue;let o=e[r];o.role===`toolResult`&&typeof o.toolCallId==`string`&&i.has(o.toolCallId)&&a.push(o)}return a.length>0?[...r,...a]:r}function ue(e={}){let t=e.enabled??!0,n=e.enableTurns??6,r=e.enableMessages??48,i=e.enableContentChars??8e4,a=e.windowTurns??3,o=e.pageTurns??3,s=[],c=[],l=a,u=0,d=0,f=[],p=!1,m=!1,h=e=>Math.max(0,e-l),g=()=>{let e=u===0?0:c[u],t=Math.min(c.length,u+l),n=t<c.length?c[t]:s.length;d=e,f=O(s,e,n)};return{setFullMessages(e){s=e,c=D(e);let o=c.length;return l=Math.min(a,Math.max(1,o-1)),m=t&&o>1&&(o>n||e.length>r||ce(e,i)),m?(u=p?Math.max(0,Math.min(u,h(o))):h(o),g(),f):(u=0,d=0,f=e,p=!1,e)},getWindowStart(){return d},getWindowMessages(){return f},isEnabled(){return m},hasMore(){return m&&u>0},loadMore(){return!m||u<=0?null:(p=!0,u=Math.max(0,u-o),g(),f)},showMessageIndex(e){if(!m||c.length===0)return null;let t=Math.max(0,Math.min(e,s.length-1)),n=0;for(let e=0;e<c.length&&!(c[e]>t);e++)n=e;let r=Math.min(c.length,u+l);return n>=u&&n<r?f:(p=!0,u=Math.min(n,h(c.length)),g(),f)},resetToTail(){p=!1},isAssignedWindow(e){return e===f}}}var de=!1,k=null;function fe(){return customElements.get(`message-list`)||null}function pe(e){if(k=e(),de)return;let t=()=>{let e=fe();if(!e)return!1;let t=Object.getOwnPropertyDescriptor(e,`messages`);if(!t||typeof t.set!=`function`)return!1;de=!0;let n=t.set;return Object.defineProperty(e,`messages`,{...t,set(e){let t=k,r=this.hasAttribute(`data-quickforge-subagent-process`);if(t&&!r){if(t.isAssignedWindow(e)){n.call(this,e);return}n.call(this,t.setFullMessages(e));return}n.call(this,e)}}),!0};t()||customElements.whenDefined(`message-list`).then(()=>{t()})}function me(e){k===e&&(k=null)}function he({panel:e,getCustomCommands:t,restoreDraftIntoComposer:n}){let r=e=>`/${e.name}${e.argumentHint?` ${e.argumentHint}`:``}`,i=()=>[{name:`init`,description:l(`initCommandDescription`),argumentHint:``},{name:`plan`,description:l(`planCommandDescription`),argumentHint:`[task]`},{name:`review`,description:l(`reviewCommandDescription`),argumentHint:`[scope]`},{name:`summary`,description:l(`summaryCommandDescription`),argumentHint:``},{name:`compact`,description:l(`compactCommandDescription`),argumentHint:``},{name:`clear`,description:l(`clearCommandDescription`),argumentHint:``},{name:`help`,description:l(`helpCommandDescription`),argumentHint:``}],a=()=>{let n=(e.querySelector(`.quickforge-command-suggestions`)?.querySelector(`.quickforge-command-suggestion-item`))?.dataset.quickforgeCommandName;if(n)return[...i(),...t()].find(e=>e.name===n)},o=()=>{let t=e.querySelector(`.quickforge-command-suggestions`);t?.__quickforgeDismissHandler&&(document.removeEventListener(`pointerdown`,t.__quickforgeDismissHandler,!0),t.__quickforgeDismissHandler=void 0),t?.remove()},s=t=>{let r=e.querySelector(`message-editor`),i=`/${t.name}${t.argumentHint?` `:``}`;n({text:i,attachments:[]});let a=r?.querySelector(`textarea`);a?.focus(),a&&(a.selectionStart=i.length,a.selectionEnd=i.length),o()};return{update:n=>{let a=e.querySelector(`message-editor`),c=n??a?.value??a?.querySelector(`textarea`)?.value??``,u=a?.querySelector(`textarea`),d=e.querySelector(`.quickforge-command-suggestions`);if(!a||!u||!c.startsWith(`/`)){d?.remove();return}let f=c.slice(1).trim().toLowerCase(),p=t(),m=[...i(),...p].filter(e=>e.name.includes(f)||e.description?.toLowerCase().includes(f));if(m.length===0){d?.remove();return}let h=d??document.createElement(`div`);h.className=`quickforge-command-suggestions`,h.setAttribute(`role`,`listbox`),h.innerHTML=``;let g=document.createElement(`div`);g.className=`quickforge-command-suggestions-header`,g.textContent=l(p.length?`customCommandsHint`:`customCommandsEmptyHint`),h.append(g);for(let e of m){let t=document.createElement(`button`);t.type=`button`,t.className=`quickforge-command-suggestion-item`,t.dataset.quickforgeCommandName=e.name,t.setAttribute(`role`,`option`),t.innerHTML=`
2
2
  <span class="quickforge-command-suggestion-name"></span>
3
3
  <span class="quickforge-command-suggestion-description"></span>
4
4
  `,t.querySelector(`.quickforge-command-suggestion-name`).textContent=r(e),t.querySelector(`.quickforge-command-suggestion-description`).textContent=e.description??``,t.onpointerdown=t=>{t.preventDefault(),t.stopPropagation(),s(e)},h.append(t)}d||a.parentElement?.insertBefore(h,a),h.__quickforgeDismissHandler||(h.__quickforgeDismissHandler=e=>{h.contains(e.target)||a.contains(e.target)||o()},document.addEventListener(`pointerdown`,h.__quickforgeDismissHandler,!0))},remove:o,setupTextareaHandler:e=>{let t=e?.querySelector(`textarea`);if(!t)return;let n=t;n.__quickforgeCommandCompleteHandler&&n.removeEventListener(`keydown`,n.__quickforgeCommandCompleteHandler,!0),n.__quickforgeCommandCompleteHandler=t=>{if(t.isComposing||t.key===`Process`)return;if(t.key===`Enter`&&t.shiftKey){t.stopImmediatePropagation();return}if(t.key!==`Tab`||!(e?.value??n.value??``).startsWith(`/`)||t.shiftKey)return;let r=a();r&&(t.preventDefault(),t.stopPropagation(),s(r))},n.addEventListener(`keydown`,n.__quickforgeCommandCompleteHandler,!0)},cleanupTextareaHandler:()=>{let t=e.querySelector(`message-editor textarea`);t?.__quickforgeCommandCompleteHandler&&t.removeEventListener(`keydown`,t.__quickforgeCommandCompleteHandler,!0)}}}var ge={plugin:`
@@ -45,4 +45,4 @@ import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{Jt as t}from"./icons-D
45
45
  </span>
46
46
  `,t.querySelector(`.quickforge-capability-suggestion-name`).textContent=e.label,t.querySelector(`.quickforge-capability-suggestion-description`).textContent=e.description??e.pluginName,t.onpointerdown=t=>{t.preventDefault(),t.stopPropagation(),g(e,u)},y.append(t)}d||n.parentElement?.insertBefore(y,n),y.__quickforgeDismissHandler||(y.__quickforgeDismissHandler=e=>{y.contains(e.target)||n.contains(e.target)||h()},document.addEventListener(`pointerdown`,y.__quickforgeDismissHandler,!0))};return{update:v,remove:h,setupTextareaHandler:e=>{let t=e?.querySelector(`textarea`);if(!t)return;let n=t;n.__quickforgeCapabilityCompleteHandler&&n.removeEventListener(`keydown`,n.__quickforgeCapabilityCompleteHandler,!0),n.__quickforgeCapabilityCompleteHandler=t=>{if(t.isComposing||t.key===`Process`)return;if(t.key===`Escape`){h();return}if(t.key!==`Tab`&&t.key!==`Enter`)return;let r=e?.value??n.value??``,i=N(r,n.selectionStart??r.length);if(!i||t.shiftKey)return;let a=m();a&&(t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation(),g(a,i))},n.addEventListener(`keydown`,n.__quickforgeCapabilityCompleteHandler,!0)},cleanupTextareaHandler:()=>{let t=e.querySelector(`message-editor textarea`);t?.__quickforgeCapabilityCompleteHandler&&t.removeEventListener(`keydown`,t.__quickforgeCapabilityCompleteHandler,!0)},consumeSelectedCapabilities:e=>{let t=ve(e),n=[...u.values()].filter(e=>t.has(e.mention.toLowerCase())),r=p().filter(e=>t.has(e.insertText.toLowerCase())||t.has(e.label.replace(/\s+/g,``).toLowerCase())),i=new Map;for(let e of[...n,...r])i.set(P(e),e);return u=new Map,d(),[...i.values()].slice(0,4)},insertBuiltinPluginMention:_,availablePluginRows:p}}function P(e){return`${e.type}:${e.pluginName}:${e.name}`}function be(e){return e>=5}function xe(e){return e.role===`user`||e.role===`user-with-attachments`}function F(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&`type`in e&&e.type===`text`&&`text`in e&&typeof e.text==`string`).map(e=>e.text).join(`
47
47
 
48
- `).trim():``}function Se(e){return xe(e)?(typeof e.content==`string`?e.content:F(e.content)).trim():``}function Ce(e){return e.role===`assistant`?F(e.content):``}function we(e,t){let n=[];for(let t=0;t<e.length;t++){let r=e[t];if(!xe(r))continue;let i=``;for(let n=t+1;n<e.length;n++){let t=e[n];if(xe(t))break;t.role===`assistant`&&(i=Ce(t))}n.push({messageIndex:t,userText:Se(r),finalAnswerText:i,isGenerating:!1})}return t&&n.length>0&&(n[n.length-1].isGenerating=!0),n}var I=xe;function L(e,t){return e.trim().replace(/\s+/g,` `)||t}function Te({host:e,panel:t,getMessages:n,isStreaming:r,windowLayer:i,beginProgrammaticScroll:a,onWindowChanged:o}){let s=document.createElement(`nav`);s.className=`quickforge-turn-navigation`,s.setAttribute(`aria-label`,l(`turnNavigationLabel`)),s.hidden=!0;let c=document.createElement(`div`);c.className=`quickforge-turn-navigation-track`,s.append(c),e.append(s);let u=[],d=``,f=-1,p=null,m=null,h,g,_=null,v=0,y=null,b=null,x=()=>{h!==void 0&&(window.clearTimeout(h),h=void 0)},ee=()=>{g!==void 0&&(window.clearTimeout(g),g=void 0)},S=()=>{x(),ee(),p?.remove(),p=null,m?.removeAttribute(`aria-describedby`),m=null},C=()=>{if(!p||!m)return;let e=m.getBoundingClientRect(),t=p.getBoundingClientRect(),n=e.right+10;n+t.width>window.innerWidth-12&&(n=e.left-t.width-10);let r=Math.min(Math.max(12,e.top+e.height/2-t.height/2),Math.max(12,window.innerHeight-t.height-12));p.style.left=`${Math.max(12,n)}px`,p.style.top=`${r}px`},te=(e,t)=>{x(),ee(),S();let n=u[t];if(!n)return;let r=document.createElement(`div`),i=`quickforge-turn-navigation-tooltip-${t}`;r.id=i,r.className=`quickforge-turn-navigation-tooltip`,r.setAttribute(`role`,`tooltip`);let a=document.createElement(`div`);a.className=`quickforge-turn-navigation-tooltip-text quickforge-turn-navigation-tooltip-user`,a.textContent=L(n.userText,l(`turnNavigationAttachmentOnly`)),r.append(a);let o=n.isGenerating?l(`turnNavigationGenerating`):n.finalAnswerText.trim();if(o){let e=document.createElement(`div`);e.className=`quickforge-turn-navigation-tooltip-text quickforge-turn-navigation-tooltip-answer`,e.textContent=o,r.append(e)}r.addEventListener(`pointerenter`,ee),r.addEventListener(`pointerleave`,()=>{g=window.setTimeout(S,100)}),document.body.append(r),p=r,m=e,e.setAttribute(`aria-describedby`,i),C()},ne=(e,t)=>{x(),ee(),h=window.setTimeout(()=>te(e,t),150)},re=e=>{e!==f&&(f=e,c.querySelectorAll(`.quickforge-turn-navigation-node`).forEach((t,n)=>{let r=n===e,i=Math.abs(n-e);t.classList.toggle(`is-active`,r),t.classList.toggle(`is-nearby`,i===1),t.classList.toggle(`is-nearby-secondary`,i===2),r?t.setAttribute(`aria-current`,`true`):t.removeAttribute(`aria-current`)}))},ie=()=>{let e=_,r=t.querySelector(`message-list`);if(!e||!r||u.length===0)return;let a=n(),o=(i.isEnabled()?i.getWindowMessages():a).map(e=>I(e)?a.indexOf(e):-1).filter(e=>e>=0).map(e=>u.findIndex(t=>t.messageIndex===e)).filter(e=>e>=0),s=Array.from(r.querySelectorAll(`user-message`)).filter(e=>e.closest(`message-list`)===r);if(s.length===0||o.length===0)return;let c=e.getBoundingClientRect().top+Math.min(120,e.clientHeight*.2),l=0;for(let e=0;e<s.length&&s[e].getBoundingClientRect().top<=c;e++)l=e;re(o[Math.min(l,o.length-1)])},ae=()=>{let e=t.querySelector(`agent-interface .overflow-y-auto`);e!==_&&(_?.removeEventListener(`scroll`,ie),_=e,_?.addEventListener(`scroll`,ie,{passive:!0}))},w=e=>{let r=u[e],s=t.querySelector(`message-list`),c=t.querySelector(`agent-interface .overflow-y-auto`);if(!r||!s||!c)return;S();let l=++v;b?.(),b=null,y?.(),y=a();let d=()=>{if(l!==v)return;b?.(),b=null;let e=y;y=null,window.requestAnimationFrame(()=>e?.())},f=()=>{let e=!1,t=()=>{e||(e=!0,c.removeEventListener(`scrollend`,t),window.clearTimeout(n),d())};c.addEventListener(`scrollend`,t,{once:!0});let n=window.setTimeout(t,900);b=()=>{e=!0,c.removeEventListener(`scrollend`,t),window.clearTimeout(n)}},p=i.showMessageIndex(r.messageIndex);p&&s.messages!==p&&(s.messages=p);let m=()=>{window.requestAnimationFrame(()=>{if(l!==v)return;let t=n(),a=i.isEnabled()?i.getWindowMessages():t,u=a.findIndex(e=>e===t[r.messageIndex]);if(u<0){d();return}let p=a.slice(0,u+1).filter(I).length-1,m=Array.from(s.querySelectorAll(`user-message`)).filter(e=>e.closest(`message-list`)===s)[p];if(!m){d();return}let h=c.scrollTop+m.getBoundingClientRect().top-c.getBoundingClientRect().top-24,g=Math.max(0,h);Math.abs(c.scrollTop-g)<=1?(c.scrollTop=g,d()):(f(),c.scrollTo({top:g,behavior:`smooth`})),re(e),o()})};(s.updateComplete??Promise.resolve()).then(m,m)},T=()=>{if(c.replaceChildren(),!be(u.length)){s.hidden=!0;return}s.hidden=!1,u.forEach((e,t)=>{let n=document.createElement(`button`);n.type=`button`,n.className=`quickforge-turn-navigation-node`,n.setAttribute(`aria-label`,l(`turnNavigationJumpLabel`,{index:t+1,preview:L(e.userText,l(`turnNavigationAttachmentOnly`))})),n.addEventListener(`pointerenter`,()=>ne(n,t)),n.addEventListener(`pointerleave`,()=>{x(),g=window.setTimeout(S,100)}),n.addEventListener(`focus`,()=>ne(n,t)),n.addEventListener(`blur`,()=>{g=window.setTimeout(S,100)}),n.addEventListener(`click`,()=>w(t)),c.append(n)}),f=-1},oe=()=>{u=we(n(),r());let e=u.map(e=>`${e.messageIndex}:${e.userText}`).join(`|`);e!==d&&(d=e,T()),ae(),ie()},E=e=>{e.key===`Escape`&&S()},D=()=>S();return document.addEventListener(`keydown`,E),window.addEventListener(`resize`,D),{update:oe,cleanup(){v+=1,b?.(),b=null,y?.(),y=null,S(),_?.removeEventListener(`scroll`,ie),document.removeEventListener(`keydown`,E),window.removeEventListener(`resize`,D),s.remove()}}}function R(e){return!!(e&&typeof e==`object`&&!Array.isArray(e))}function z(e,t){let n=e[t];return typeof n==`string`&&n.trim()?n:void 0}function Ee(e,t){let n=e[t];return typeof n==`boolean`?n:void 0}function De(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:void 0}function Oe(e){let t=e&&R(e.diff)?e.diff:void 0;return{addedLines:t?De(t,`addedLines`):void 0,removedLines:t?De(t,`removedLines`):void 0}}function ke(e=``){let t=e.toLowerCase(),n=t.replace(/\\/g,`/`).split(`/`).pop()||t;return t.endsWith(`.html`)||t.endsWith(`.htm`)?`html`:/\.(svg|png|jpe?g|webp|gif|ico)$/i.test(t)?`image`:/\.(md|mdx|markdown)$/i.test(t)?`markdown`:n===`dockerfile`||n.endsWith(`.dockerfile`)||n===`makefile`||/\.(ts|tsx|js|jsx|mjs|cjs|css|scss|less|json|jsonc|txt|csv|tsv|log|sql|xml|yml|yaml|toml|ini|py|rb|go|rs|java|swift|kt|kts|c|h|cpp|hpp|cs|php|sh|bash|zsh|ps1)$/i.test(t)?`code`:`unknown`}function B(e){return e===`html`||e===`image`||e===`markdown`||e===`code`}function V(e){return[e.source,e.path??``,e.command??``,e.outputFile??``,e.toolCallId??``,e.preview?`preview`:``].join(`\0`)}function Ae(e,t,n){let r=V(n);t.has(r)||(t.add(r),e.push({id:`${e.length}:${r}`,...n}))}function H(e){if(!(typeof e!=`string`||!e.trim()))try{return JSON.parse(e)}catch{return}}function U(e,t){if(t&&(Array.isArray(t.files)||Array.isArray(t.previewed)))return t;let n=e.data;if(Array.isArray(n))for(let e of n){if(!R(e)||e.type!==`text`)continue;let t=H(e.text);if(R(t)&&(Array.isArray(t.files)||Array.isArray(t.previewed)))return t}let r=e.content;if(Array.isArray(r))for(let e of r){if(!R(e)||e.type!==`text`)continue;let t=H(e.text);if(R(t)&&(Array.isArray(t.files)||Array.isArray(t.previewed)))return t}return t}function je(e){if(typeof e==`string`&&e.trim())return{path:e};if(R(e)){let t=z(e,`path`);return t?{path:t,title:z(e,`title`),description:z(e,`description`),kind:z(e,`kind`),preview:Ee(e,`preview`)}:void 0}}function Me(e){let t=new Set,n=[];for(let r of e){if(r.role!==`toolResult`)continue;let e=typeof r.toolName==`string`?r.toolName:``,i=R(r.details)?r.details:void 0,a=typeof r.toolCallId==`string`?r.toolCallId:void 0;if(!(!i&&e!==`present_files`)){if(e===`write_file`||e===`edit_file`){let r=i?z(i,`path`):void 0;if(r){let o=ke(r),{addedLines:s,removedLines:c}=Oe(i);Ae(n,t,{source:e,confidence:`high`,path:r,toolCallId:a,kind:o,preview:B(o),presentation:`inferred`,addedLines:s,removedLines:c})}}else if(e===`present_files`){let e=U(r,i),o=R(e)&&Array.isArray(e.files)?e.files:[],s=R(e)?z(e,`defaultPreview`):void 0,c=new Set(R(e)&&Array.isArray(e.previewed)?e.previewed.filter(e=>typeof e==`string`):[]);for(let e of o){let r=je(e);if(!r?.path)continue;let i=r.kind??ke(r.path);Ae(n,t,{source:`present_files`,confidence:`high`,path:r.path,title:r.title,description:r.description,toolCallId:a,kind:i,preview:r.preview??(c.has(r.path)||s===r.path||B(i)),defaultPreview:s===r.path,presentation:`explicit`})}}else if(e===`run_command`&&i){let e=z(i,`command`),r=z(i,`outputFile`);(e||r)&&Ae(n,t,{source:`run_command`,confidence:`low`,command:e,outputFile:r,toolCallId:a})}}}return n}function Ne(e){return e?.length?Me(e):[]}var W=`quickforge:composer-drafts:v1`,G=100,K={},q=!1;function Pe(e){return!!(e&&!e.startsWith(`pending-`))}function Fe(e){return Pe(e.sessionId)?`session:${e.sessionId}`:e.scope===`project`&&e.projectId?`new:project:${e.projectId}`:`new:global`}function Ie(e){if(!e||typeof e!=`object`||Array.isArray(e))return{};let t={};for(let[n,r]of Object.entries(e)){if(!r||typeof r!=`object`||Array.isArray(r))continue;let e=r;typeof e.text==`string`&&(t[n]={text:e.text,updatedAt:typeof e.updatedAt==`string`?e.updatedAt:new Date().toISOString(),scope:e.scope===`project`?`project`:e.scope===`global`?`global`:void 0,projectId:typeof e.projectId==`string`?e.projectId:void 0,sessionId:typeof e.sessionId==`string`?e.sessionId:void 0})}return t}function Le(){try{return globalThis.localStorage}catch{return}}function Re(e,t=G){return Object.fromEntries(Object.entries(e).filter(([,e])=>e.text.length>0).sort(([,e],[,t])=>t.updatedAt.localeCompare(e.updatedAt)).slice(0,t))}function ze(){let e=Le();if(!e||q)return K;let t;try{t=e.getItem(W)}catch{return q=!0,K}try{return Ie(t?JSON.parse(t):void 0)}catch{return K}}function Be(e){let t=Re(e);K=t;let n=Le();if(!(!n||q))try{Object.keys(t).length===0?n.removeItem(W):n.setItem(W,JSON.stringify(t))}catch{let e=Re(t,Math.ceil(G/2));K=e;try{Object.keys(e).length===0?n.removeItem(W):n.setItem(W,JSON.stringify(e))}catch{q=!0}}}async function Ve(e){let t=ze()[e];if(!(!t||t.text.length===0))return{text:t.text,attachments:[]}}async function He(e,t,n){let r=t.text??``;if(r.length===0){await Ue(e);return}let i=ze();i[e]={text:r,updatedAt:new Date().toISOString(),scope:n.scope,projectId:n.scope===`project`?n.projectId:void 0,sessionId:Pe(n.sessionId)?n.sessionId:void 0},Be(i)}async function Ue(e){let t=ze();Object.prototype.hasOwnProperty.call(t,e)&&(delete t[e],Be(t))}function We(e,t,n=200){for(e.delete(t),e.add(t);e.size>n;){let t=e.values().next().value;if(t===void 0)break;e.delete(t)}}function Ge(){let e=0;return{version:()=>e,isCurrent:t=>t===e,invalidate:()=>(e+=1,e)}}var Ke=n();function qe(e){let t=e.state.contextCompaction;if(!t?.summaryMessage)return e.state.messages;let n=e.state.messages,r=Math.min(n.length,Math.max(0,Number(t.compactedUpToIndex)||0));return[t.summaryMessage,...n.slice(r)]}function Je(e){let t=String(e.length);for(let n of e)n.role===`toolResult`&&(t+=`|${n.toolCallId??``}:${n.toolName??``}`);return t}function Ye({agent:e,onModelSelect:t,revision:n,agentAccessMode:w,workspaceToolsEnabled:E,project:D,projectId:se,chatScope:ce=`global`,onAccessModeChange:le,onRollbackFromMessage:O,onRetryFromMessage:de,onCopyAnswer:k,onForkFromMessage:fe,onApproveToolCall:ge,onRejectToolCall:A,onApproveAutoCompact:_e,onRejectAutoCompact:j,onOpenWorkspaceGitChanges:M,onOpenLocalFilePath:N,onArtifactsChange:ve,onContextUsageDisplayChange:P,onInitialRenderReady:be,onInitialRenderError:xe,restoredDraft:F,onRestoredDraftConsumed:Se,disableFork:Ce=!1,readOnly:we=!1,approvalReadOnly:I=!1,approvalReadOnlyMessage:L,bypassClientApiKeyCheck:R=!1,allowModelControls:z=!0,newChatEmptyState:Ee=!1,showTurnNavigation:De=!0,rollbackConfirmTitle:Oe,rollbackConfirmDescription:ke,capabilities:B=g}){let V=(0,T.useRef)(null),Ae=(0,T.useRef)(void 0),H=(0,T.useRef)(void 0),U=(0,T.useRef)(new Map),je=(0,T.useRef)([]),Me=(0,T.useRef)(void 0),W=(0,T.useRef)(new Set),G=(0,T.useRef)(void 0),K=(0,T.useRef)(null),q=(0,T.useRef)(!1),Pe=(0,T.useRef)(new WeakSet),Ie=(0,T.useRef)(``),Le=(0,T.useRef)(``),Re=(0,T.useRef)(Ge()),[ze,Be]=(0,T.useState)(),[Ye,Xe]=(0,T.useState)(!1),J=(0,T.useMemo)(()=>m(B,{readOnly:we,disableFork:Ce}),[B,we,Ce]),Ze=(0,T.useCallback)(()=>Xe(e=>!e),[]),Qe=(0,T.useCallback)(()=>Xe(!1),[]);(0,T.useEffect)(()=>{let t=e,n=J.planMode&&Ye;t?.setPlanMode?.(n,n?Qe:void 0),!J.planMode&&Ye&&queueMicrotask(Qe)},[e,Ye,Qe,J.planMode]);let $e=(0,T.useCallback)(()=>{G.current&&=(window.clearTimeout(G.current),void 0)},[]),Y=(0,T.useCallback)(()=>{K.current?.cancel(),K.current=null,q.current=!1},[]),et=(0,T.useCallback)(e=>{We(W.current,e),Se?.(e)},[Se]),tt=(0,T.useMemo)(()=>({sessionId:e?.sessionId,scope:ce,projectId:se}),[e?.sessionId,ce,se]),nt=Fe(tt),rt=(0,T.useRef)(tt),it=(0,T.useRef)(nt);(0,T.useEffect)(()=>{rt.current=tt,it.current=nt},[tt,nt]),(0,T.useEffect)(()=>()=>{$e(),Y()},[$e,Y]);let at=(0,T.useCallback)((e,t,n)=>{if(t.text.length===0){Ue(e).catch(e=>a.error(`Failed to clear composer draft:`,e));return}He(e,t,n).catch(e=>a.error(`Failed to save composer draft:`,e))},[]),ot=(0,T.useCallback)((e,t,n)=>{G.current&&window.clearTimeout(G.current),G.current=window.setTimeout(()=>{G.current=void 0,at(e,t,n)},400)},[at]),st=(0,T.useCallback)((e,t=it.current,n=rt.current)=>{let r=C(e);c(r)?U.current.set(t,r):U.current.delete(t),at(t,r,n)},[at]),X=(0,T.useRef)({onCopyAnswer:k,onRollbackFromMessage:O,onRetryFromMessage:de,onForkFromMessage:fe,onAccessModeChange:le,onTogglePlanMode:Ze,onApproveToolCall:ge,onRejectToolCall:A,onApproveAutoCompact:_e,onRejectAutoCompact:j,onOpenWorkspaceGitChanges:M,onOpenLocalFilePath:N,onArtifactsChange:ve,onContextUsageDisplayChange:P,onInitialRenderReady:be,onInitialRenderError:xe,onModelSelect:t,agentAccessMode:w,planMode:Ye,workspaceToolsEnabled:E,disableFork:Ce,readOnly:we,approvalReadOnly:I,approvalReadOnlyMessage:L,allowModelControls:z,newChatEmptyState:Ee,bypassClientApiKeyCheck:R,rollbackConfirmTitle:Oe,rollbackConfirmDescription:ke,capabilities:J,gitBranch:ze});(0,T.useEffect)(()=>{X.current={onCopyAnswer:k,onRollbackFromMessage:O,onRetryFromMessage:de,onForkFromMessage:fe,onAccessModeChange:le,onTogglePlanMode:Ze,onApproveToolCall:ge,onRejectToolCall:A,onApproveAutoCompact:_e,onRejectAutoCompact:j,onOpenWorkspaceGitChanges:M,onOpenLocalFilePath:N,onArtifactsChange:ve,onContextUsageDisplayChange:P,onInitialRenderReady:be,onInitialRenderError:xe,onModelSelect:t,agentAccessMode:w,planMode:Ye,workspaceToolsEnabled:E,disableFork:Ce,readOnly:we,approvalReadOnly:I,approvalReadOnlyMessage:L,allowModelControls:z,newChatEmptyState:Ee,bypassClientApiKeyCheck:R,rollbackConfirmTitle:Oe,rollbackConfirmDescription:ke,capabilities:J,gitBranch:ze},H.current=F});let ct=D?.id??se;(0,T.useEffect)(()=>{let e=!1;return queueMicrotask(()=>{if(!e){if(!ct){Be(void 0);return}p(ct).then(t=>{e||Be(t.isGitRepository?t.branch:void 0)}).catch(t=>{e||(a.warn(`Failed to load git branch:`,t),Be(void 0))})}}),()=>{e=!0}},[ct,n]);let lt=(0,T.useRef)(null),ut=(0,T.useRef)(null),Z=(0,T.useRef)(null),Q=(0,T.useRef)(null),$=(0,T.useRef)(null);(0,T.useEffect)(()=>{let e=!1;return!J.commands||!D?.id?(je.current=[],()=>{e=!0}):(fetch(`/api/project/commands?projectId=${encodeURIComponent(D.id)}`,{cache:`no-store`}).then(e=>e.ok?e.json():{commands:[]}).then(t=>{e||(je.current=Array.isArray(t.commands)?t.commands:[],Z.current?.())}).catch(()=>{e||(je.current=[],Z.current?.())}),()=>{e=!0})},[D?.id,n,J.commands]);let dt=(0,T.useCallback)((e,t,n,r)=>{if(t.sessionId&&t.sessionId!==n||!c(t)||W.current.has(t.id))return;let i=e.querySelector(`message-editor`),a=i?{text:i.value??i.querySelector(`textarea`)?.value??``,attachments:i.attachments?[...i.attachments]:[]}:U.current.get(r),o=Me.current;if(!(o?.id!==t.id||!c(a??f())||a?.text===o.text))return;Re.current.invalidate(),Y();let s=e.querySelector(`agent-interface`);K.current=b(e,t,U.current,r,{shouldApply:()=>!W.current.has(t.id)&&e.isConnected&&!!V.current?.contains(e),onApplyStart:()=>{q.current=!0},onApplyEnd:()=>{q.current=!1},onApplied:()=>{Pe.current.add(e),Ae.current=t.id,Me.current={id:t.id,text:t.text},et(t.id)},updateComplete:s?.updateComplete})},[Y,et]);return(0,T.useEffect)(()=>{if(!V.current||!e)return;let t=Re.current,n=Pe.current,p=new r;Xe(!1);let m=e.sessionId,g=it.current,C=rt.current,w=!1,T,E=!1,D=!1,se=!1,ce=e.state.isStreaming,le=!1,O=0,de,k=ue({enabled:!1});pe(()=>k);let fe=!1,ge=()=>{if(w||fe||!k.hasMore())return;let e=p.querySelector(`message-list`),t=p.querySelector(`agent-interface .overflow-y-auto`);if(!e||!t)return;let n=Array.from(e.querySelectorAll(`user-message, assistant-message`)).filter(t=>t.closest(`message-list`)===e),r=t.getBoundingClientRect().top,i=-1,a=0;for(let e=0;e<n.length;e++){let t=n[e].getBoundingClientRect();if(t.bottom>r){i=e,a=t.top;break}}let o=t.scrollTop,s=k.loadMore();if(!s)return;fe=!0,e.messages=s;let c=()=>{window.requestAnimationFrame(()=>{if(fe=!1,!w){if(i>=0){let n=Array.from(e.querySelectorAll(`user-message, assistant-message`))[i];n&&(t.scrollTop=o+(n.getBoundingClientRect().top-a))}Z.current?.()}})};(e.updateComplete??Promise.resolve()).then(c,c)},A=oe({panel:p,onReachTop:()=>{ge()},onAutoScrollEnabled:()=>{k.resetToTail()}});ut.current=A;let _e=null,j=he({panel:p,getCustomCommands:()=>je.current,getComposerDrafts:()=>U.current,sessionId:g,setComposerDrafts:e=>{U.current=e},restoreDraftIntoComposer:e=>{x(p,e,U.current,g),ot(g,e,C)}}),M=ye({panel:p,enabled:J.capabilitySuggestions,restoreDraftIntoComposer:e=>{x(p,e,U.current,g),ot(g,e,C)}}),N=u({panel:p,getSystemPrompt:()=>e.state.systemPrompt,getMessages:()=>e.state.messages,getEffectiveMessages:()=>qe(e),getContextWindow:()=>e.state.model?.contextWindow??0,getTools:()=>e.state.tools,getMaxTokens:()=>e.state.model?.maxTokens,getServerContextUsage:()=>e.state.contextUsage??null,getIsCompacted:()=>!!e.state.contextCompaction?.summaryMessage,getGitBranch:()=>X.current.gitBranch,onGitBranchClick:()=>X.current.onOpenWorkspaceGitChanges?.(),renderInline:!1,renderModelRing:s().showContextUsage,onDisplayChange:t=>X.current.onContextUsageDisplayChange?.(e.sessionId,t)}),ve=S({panel:p,getAcpSession:()=>e.state.acpSession??null}),P=()=>{if(q.current)return;se=!0,t.invalidate(),Y();let e=H.current;e&&(!e.sessionId||e.sessionId===m)&&et(e.id)},be=e=>{P(),E=!1;let t=p.querySelector(`message-editor`),n={text:e,attachments:t?.attachments?[...t.attachments]:[]};c(n)?(U.current.set(g,n),ot(g,n,C)):(U.current.delete(g),$e(),Ue(g).catch(e=>a.error(`Failed to clear composer draft:`,e)))},xe=e=>{P(),E=!1;let t=p.querySelector(`message-editor`),n=t?.querySelector(`textarea`),r={text:t?.value??n?.value??``,attachments:e?[...e]:[]};c(r)?(U.current.set(g,r),ot(g,r,C)):(U.current.delete(g),$e(),Ue(g).catch(e=>a.error(`Failed to clear composer draft:`,e)));let i=p.querySelector(`agent-interface`);i?.requestUpdate?.(),window.requestAnimationFrame(()=>Z.current?.()),i?.updateComplete?.then(()=>Z.current?.())},F=()=>{e.state.isStreaming?p.dataset.quickforgeAgentStreaming=`true`:delete p.dataset.quickforgeAgentStreaming},Se=!1,Ce=()=>{if(w||Se)return;Se=!0;let t=()=>{if(Se=!1,w)return;let t=Ne(e.state.messages),n=JSON.stringify(t.map(e=>[e.source,e.path,e.command,e.outputFile,e.confidence,e.preview,e.defaultPreview,e.addedLines,e.removedLines]));n!==Ie.current&&(Ie.current=n,X.current.onArtifactsChange?.(t))};typeof window.requestIdleCallback==`function`?window.requestIdleCallback(t,{timeout:500}):t()},we=()=>{if(w||!p.isConnected)return;F();let t=()=>k.isEnabled()?k.getWindowMessages():e.state.messages,n=k.isEnabled()?k.getWindowStart():0,r=X.current,i=Je(e.state.messages);i!==Le.current&&(Le.current=i,Ce());try{ee({panel:p,getMessages:t,messageIndexOffset:n,isStreaming:()=>e.state.isStreaming,onCopyAnswer:r.onCopyAnswer,onRollbackFromMessage:r.onRollbackFromMessage,onRetryFromMessage:r.onRetryFromMessage,onForkFromMessage:r.onForkFromMessage,onOpenLocalFilePath:r.onOpenLocalFilePath,disableFork:!r.capabilities.forkFromMessage,allowRollback:r.capabilities.rollback,allowRetry:r.capabilities.retry,readOnly:r.readOnly,enableTerminalCommandActions:!r.readOnly,rollbackConfirmTitle:r.rollbackConfirmTitle,rollbackConfirmDescription:r.rollbackConfirmDescription}),ae({panel:p,getMessages:t,getContextCompaction:()=>r.capabilities.compaction?e.state.contextCompaction??null:null,messageIndexOffset:n}),re({panel:p,getMessages:t,isStreaming:()=>e.state.isStreaming,isActive:ce})}catch(e){a.warn(`Failed to decorate chat messages:`,e)}try{te({panel:p,isStreaming:()=>e.state.isStreaming,abort:()=>e.abort(),agentAccessMode:r.agentAccessMode,harness:e.harness,getAcpSession:()=>e.state.acpSession??null,onOpenCodeConfigOptionChange:(t,n)=>{e.setConfigOption(t,n).catch(e=>{a.error(`Failed to update OpenCode config option:`,e)})},onOpenCodeModeChange:t=>{e.setMode(t).catch(e=>{a.error(`Failed to update OpenCode mode:`,e)})},planMode:r.planMode,workspaceToolsEnabled:r.workspaceToolsEnabled,readOnly:r.readOnly,allowModelControls:r.allowModelControls&&r.capabilities.modelSelection,planModeEnabled:r.capabilities.planMode,accessModeEnabled:r.capabilities.accessMode,commandSuggestionsEnabled:r.capabilities.commands,capabilitySuggestionsEnabled:r.capabilities.capabilitySuggestions,attachmentsEnabled:r.capabilities.attachments,onAccessModeChange:r.onAccessModeChange,onTogglePlanMode:r.onTogglePlanMode,onInput:be,onFilesChange:xe,removeCommandSuggestions:j.remove,updateCommandSuggestions:j.update,setupCommandTextareaHandler:j.setupTextareaHandler,removeCapabilitySuggestions:M.remove,updateCapabilitySuggestions:M.update,setupCapabilityTextareaHandler:M.setupTextareaHandler,insertBuiltinPluginMention:M.insertBuiltinPluginMention,availablePluginRows:M.availablePluginRows,onBeforeSend:t=>{h();let n=r.capabilities.capabilitySuggestions?M.consumeSelectedCapabilities(t):[];e.setNextPromptCapabilities?.(n)}})}catch{}let o=Q.current??(()=>{let t=e.state.pendingToolApproval;return t?{...t,sessionId:e.sessionId}:null})();if(o&&o.sessionId===e.sessionId&&typeof o.toolCallId==`string`&&typeof o.toolName==`string`){let t=o.toolCallId;v({panel:p,tone:`warning`,disabled:r.approvalReadOnly,disabledReason:r.approvalReadOnlyMessage,onApprove:async()=>{await X.current.onApproveToolCall(t),Q.current=null,e.state.pendingToolApproval=null,y(p)},onReject:async()=>{await X.current.onRejectToolCall(t),Q.current=null,e.state.pendingToolApproval=null,y(p)}},o.toolName,t,o.args,o.source)}else{let n=$.current??(()=>{let t=e.state.pendingAutoCompactApproval;return t?{...t,sessionId:e.sessionId}:null})();if(n&&n.sessionId===e.sessionId){let i=n.approvalId,a=!r.onApproveAutoCompact||!r.onRejectAutoCompact,o=r.approvalReadOnly||a,s=r.approvalReadOnly?r.approvalReadOnlyMessage:a?l(`autoCompactApprovalUnavailable`):void 0;v({panel:p,tone:`info`,copy:{status:l(`autoCompactApprovalStatus`),title:l(`autoCompactApprovalTitle`),risk:l(`autoCompactApprovalRisk`,{keepRecentTurns:n.keepRecentTurns??3}),approve:l(`autoCompactApprovalAccept`),reject:l(`autoCompactApprovalReject`)},disabled:o,disabledReason:s,getMessages:t,keepRecentTurns:n.keepRecentTurns??3,onApprove:async()=>{let t=X.current.onApproveAutoCompact;if(!t)throw Error(l(`autoCompactApprovalUnavailable`));await t(i),$.current=null,e.state.pendingAutoCompactApproval=null,y(p)},onReject:async()=>{let t=X.current.onRejectAutoCompact;if(!t)throw Error(l(`autoCompactApprovalUnavailable`));await t(i),$.current=null,e.state.pendingAutoCompactApproval=null,y(p)}},l(`contextManagement`),i,{percent:n.usage?.percent??0,threshold:n.thresholdPercent??0,keepRecentTurns:n.keepRecentTurns??3,summary:l(`autoCompactApprovalWaiting`,{percent:n.usage?.percent??0,threshold:n.thresholdPercent??0}),description:l(`autoCompactApprovalPreview`,{keepRecentTurns:n.keepRecentTurns??3})})}else y(p)}r.capabilities.contextUsage?N.update():N.cleanup(),e.harness===`opencode`&&ve.update(),_e?.update(),A.setup(),A.isEnabled&&(k.resetToTail(),A.scheduleScrollToBottom())},I=!1,L,R=!1,z,Ee=()=>{z===void 0&&(z=window.requestAnimationFrame(()=>{z=void 0,R=!1}))},Oe=()=>{if(!w){R=!0;try{we()}finally{Ee()}}},ke=()=>{I||(I=!0,L=window.requestAnimationFrame(()=>{L=void 0,I=!1,Oe()}))};lt.current=Oe;let B=()=>p.querySelector(`agent-interface`),Me=()=>{le||(le=!0,window.requestAnimationFrame(()=>{if(le=!1,w)return;F();let e=B();e?.requestUpdate?.(),(e?.updateComplete??Promise.resolve()).then(()=>{w||Oe()}),A.isEnabled&&A.scheduleScrollToBottom()}))};Z.current=ke;let W=()=>{let e=++O;p.dataset.quickforgeProcessHandoff=String(e);let t=B();t?.requestUpdate?.(),Z.current?.(),window.requestAnimationFrame(()=>{!w&&O===e&&Z.current?.()});let n=()=>{w||O!==e||(delete p.dataset.quickforgeProcessHandoff,Z.current?.(),window.requestAnimationFrame(()=>{!w&&O===e&&Z.current?.()}))};(t?.updateComplete??Promise.resolve()).then(n,n)};p.setAgent(e,{onApiKeyRequired:!X.current.capabilities.clientApiKeyCheck||X.current.bypassClientApiKeyCheck?async()=>!0:t=>o(e.state.model)?Promise.resolve(!0):i.prompt(t),onBeforeSend:()=>{t.invalidate(),Y();let e=H.current;e&&(!e.sessionId||e.sessionId===m)&&et(e.id),$e(),E=!0,j.remove(),U.current.delete(g),Ue(g).catch(e=>a.error(`Failed to clear composer draft:`,e)),A.enable()},onModelSelect:X.current.onModelSelect,toolsFactory:()=>ie(e.state.tools)}).then(()=>{if(w)return;let e=H.current,n=t.version(),r=r=>{if(!(w||!t.isCurrent(n)))if(e&&Ae.current!==e.id)dt(p,e,m,g);else{let e=r??U.current.get(g)??f();c(e)||(D=!0),Y();let i=p.querySelector(`agent-interface`);K.current=b(p,e,U.current,g,{shouldApply:()=>!w&&t.isCurrent(n)&&p.isConnected&&!!V.current?.contains(p),onApplyStart:()=>{q.current=!0},onApplyEnd:()=>{q.current=!1},onApplied:()=>{D=!0,Pe.current.add(p)},updateComplete:i?.updateComplete})}};if(e&&Ae.current!==e.id)r();else{let e=U.current.get(g);e?r(e):Ve(g).then(e=>r(e)).catch(e=>a.error(`Failed to load composer draft:`,e))}T=new MutationObserver(()=>{R||ke()}),T.observe(p,{childList:!0,subtree:!0}),window.requestAnimationFrame(()=>{w||Oe()});let i=B(),o=()=>{w||(de=d(()=>{w||X.current.onInitialRenderReady?.(m)}))};(i?.updateComplete??Promise.resolve()).then(o,o)},e=>{w||(a.error(`Failed to initialize chat panel:`,e),X.current.onInitialRenderError?.(m,e))}),V.current.replaceChildren(p),De&&(_e=Te({host:V.current,panel:p,getMessages:()=>e.state.messages,isStreaming:()=>e.state.isStreaming,windowLayer:k,beginProgrammaticScroll:A.beginProgrammaticScroll,onWindowChanged:()=>Z.current?.()}));let G=e.subscribe(t=>{if(t.type===`agent_start`&&(O+=1,delete p.dataset.quickforgeProcessHandoff,ce=!0,F(),Z.current?.(),A.enable(),Q.current?.sessionId===e.sessionId&&(Q.current=null),$.current?.sessionId===e.sessionId&&($.current=null)),t.type===`message_start`||t.type===`message_update`||t.type===`message_end`||t.type===`turn_end`||t.type===`agent_end`){F();let e=t.message;t.type===`message_start`&&e?.role===`assistant`&&(O+=1,delete p.dataset.quickforgeProcessHandoff),(t.type===`message_update`||e?.role===`assistant`)&&(ce=!1),Z.current?.(),t.type===`message_end`&&e?.role===`assistant`&&W(),A.isEnabled&&A.scheduleScrollToBottom()}if(t.type===`messages_replaced`){let e=H.current;e&&Ae.current===e.id&&dt(p,e,m,g)}let n=t.type;if(n===`tool_execution_start`){let n=t,r=Q.current,i=n.sessionId??e.sessionId;r&&r.sessionId===e.sessionId&&i===e.sessionId&&n.toolCallId===r.toolCallId&&(Q.current=null,e.state.pendingToolApproval?.toolCallId===n.toolCallId&&(e.state.pendingToolApproval=null),Z.current?.())}if((n===`tool_execution_start`||n===`tool_execution_update`||n===`tool_execution_end`)&&Me(),(n===`acp_session_update`||n===`acp_session_usage_update`)&&Z.current?.(),t.type===`agent_end`&&(ce=!1,F(),W(),Q.current?.sessionId===e.sessionId&&(Q.current=null,Z.current?.()),$.current?.sessionId===e.sessionId&&($.current=null,Z.current?.())),(n===`auto_compact_completed`||n===`auto_compact_failed`)&&($.current?.sessionId===e.sessionId&&($.current=null),e.state.pendingAutoCompactApproval=null,Z.current?.()),n===`auto_compact_completed`||n===`messages_replaced`){_(p);let e=B();e?.requestUpdate?.(),Z.current?.(),window.requestAnimationFrame(()=>Z.current?.()),e?.updateComplete?.then(()=>Z.current?.())}if(n===`auto_compact_failed`&&a.warn(l(`autoCompactFailed`)),t.type===`tool_approval_required`){let e=t;Q.current={toolCallId:e.toolCallId,toolName:e.toolName,args:e.args,sessionId:e.sessionId,source:e.source},Z.current?.()}if(t.type===`auto_compact_approval_required`){let e=t;$.current={approvalId:e.approvalId,usage:e.usage,thresholdPercent:e.thresholdPercent,keepRecentTurns:e.keepRecentTurns,sessionId:e.sessionId},Z.current?.()}});return()=>{w=!0,t.invalidate(),Y(),$e(),de?.(),E?(U.current.delete(g),Ue(g).catch(e=>a.error(`Failed to clear composer draft:`,e))):(D||se||n.has(p))&&(ne(p,U.current,g),st(p,g,C)),j.remove(),j.cleanupTextareaHandler(),M.remove(),M.cleanupTextareaHandler(),N.cleanup(),ve.cleanup(),_e?.cleanup(),A.cleanup(),ut.current=null,me(k),G(),T?.disconnect(),L!==void 0&&window.cancelAnimationFrame(L),z!==void 0&&window.cancelAnimationFrame(z),lt.current=null,p.remove()}},[e,De,J.capabilitySuggestions,$e,Y,et,st,dt,ot]),(0,T.useEffect)(()=>{let e=V.current;e&&(e.classList.toggle(`quickforge-chat-panel-empty-host`,Ee),e.dataset.quickforgeEmptyChat=Ee?`true`:`false`)},[Ee]),(0,T.useEffect)(()=>{lt.current?.(),(V.current?.querySelector(`agent-interface`))?.requestUpdate?.()},[w,Ye,E,ze,Ce,we,I,L,z,B,n]),(0,T.useEffect)(()=>{let t=H.current;if(!t||!V.current)return;let n=e?.sessionId??``;if(t.sessionId&&t.sessionId!==n||W.current.has(t.id))return;let r=V.current.querySelector(`pi-chat-panel`);r&&dt(r,t,n,it.current)},[F,e,dt]),(0,Ke.jsx)(`div`,{ref:V,className:`quickforge-chat-panel-host min-h-0 flex-1 overflow-hidden`})}export{Ye as ChatPanelHost};
48
+ `).trim():``}function Se(e){return xe(e)?(typeof e.content==`string`?e.content:F(e.content)).trim():``}function Ce(e){return e.role===`assistant`?F(e.content):``}function we(e,t){let n=[];for(let t=0;t<e.length;t++){let r=e[t];if(!xe(r))continue;let i=``;for(let n=t+1;n<e.length;n++){let t=e[n];if(xe(t))break;t.role===`assistant`&&(i=Ce(t))}n.push({messageIndex:t,userText:Se(r),finalAnswerText:i,isGenerating:!1})}return t&&n.length>0&&(n[n.length-1].isGenerating=!0),n}var I=xe;function L(e,t){return e.trim().replace(/\s+/g,` `)||t}function Te({host:e,panel:t,getMessages:n,isStreaming:r,windowLayer:i,beginProgrammaticScroll:a,onWindowChanged:o}){let s=document.createElement(`nav`);s.className=`quickforge-turn-navigation`,s.setAttribute(`aria-label`,l(`turnNavigationLabel`)),s.hidden=!0;let c=document.createElement(`div`);c.className=`quickforge-turn-navigation-track`,s.append(c),e.append(s);let u=[],d=``,f=-1,p=null,m=null,h,g,_=null,v=0,y=null,b=null,x=()=>{h!==void 0&&(window.clearTimeout(h),h=void 0)},ee=()=>{g!==void 0&&(window.clearTimeout(g),g=void 0)},S=()=>{x(),ee(),p?.remove(),p=null,m?.removeAttribute(`aria-describedby`),m=null},C=()=>{if(!p||!m)return;let e=m.getBoundingClientRect(),t=p.getBoundingClientRect(),n=e.right+10;n+t.width>window.innerWidth-12&&(n=e.left-t.width-10);let r=Math.min(Math.max(12,e.top+e.height/2-t.height/2),Math.max(12,window.innerHeight-t.height-12));p.style.left=`${Math.max(12,n)}px`,p.style.top=`${r}px`},te=(e,t)=>{x(),ee(),S();let n=u[t];if(!n)return;let r=document.createElement(`div`),i=`quickforge-turn-navigation-tooltip-${t}`;r.id=i,r.className=`quickforge-turn-navigation-tooltip`,r.setAttribute(`role`,`tooltip`);let a=document.createElement(`div`);a.className=`quickforge-turn-navigation-tooltip-text quickforge-turn-navigation-tooltip-user`,a.textContent=L(n.userText,l(`turnNavigationAttachmentOnly`)),r.append(a);let o=n.isGenerating?l(`turnNavigationGenerating`):n.finalAnswerText.trim();if(o){let e=document.createElement(`div`);e.className=`quickforge-turn-navigation-tooltip-text quickforge-turn-navigation-tooltip-answer`,e.textContent=o,r.append(e)}r.addEventListener(`pointerenter`,ee),r.addEventListener(`pointerleave`,()=>{g=window.setTimeout(S,100)}),document.body.append(r),p=r,m=e,e.setAttribute(`aria-describedby`,i),C()},ne=(e,t)=>{x(),ee(),h=window.setTimeout(()=>te(e,t),150)},re=e=>{e!==f&&(f=e,c.querySelectorAll(`.quickforge-turn-navigation-node`).forEach((t,n)=>{let r=n===e,i=Math.abs(n-e);t.classList.toggle(`is-active`,r),t.classList.toggle(`is-nearby`,i===1),t.classList.toggle(`is-nearby-secondary`,i===2),r?t.setAttribute(`aria-current`,`true`):t.removeAttribute(`aria-current`)}))},ie=()=>{let e=_,r=t.querySelector(`message-list`);if(!e||!r||u.length===0)return;let a=n(),o=(i.isEnabled()?i.getWindowMessages():a).map(e=>I(e)?a.indexOf(e):-1).filter(e=>e>=0).map(e=>u.findIndex(t=>t.messageIndex===e)).filter(e=>e>=0),s=Array.from(r.querySelectorAll(`user-message`)).filter(e=>e.closest(`message-list`)===r);if(s.length===0||o.length===0)return;let c=e.getBoundingClientRect().top+Math.min(120,e.clientHeight*.2),l=0;for(let e=0;e<s.length&&s[e].getBoundingClientRect().top<=c;e++)l=e;re(o[Math.min(l,o.length-1)])},ae=()=>{let e=t.querySelector(`agent-interface .overflow-y-auto`);e!==_&&(_?.removeEventListener(`scroll`,ie),_=e,_?.addEventListener(`scroll`,ie,{passive:!0}))},w=e=>{let r=u[e],s=t.querySelector(`message-list`),c=t.querySelector(`agent-interface .overflow-y-auto`);if(!r||!s||!c)return;S();let l=++v;b?.(),b=null,y?.(),y=a();let d=()=>{if(l!==v)return;b?.(),b=null;let e=y;y=null,window.requestAnimationFrame(()=>e?.())},f=()=>{let e=!1,t=()=>{e||(e=!0,c.removeEventListener(`scrollend`,t),window.clearTimeout(n),d())};c.addEventListener(`scrollend`,t,{once:!0});let n=window.setTimeout(t,900);b=()=>{e=!0,c.removeEventListener(`scrollend`,t),window.clearTimeout(n)}},p=i.showMessageIndex(r.messageIndex);p&&s.messages!==p&&(s.messages=p);let m=()=>{window.requestAnimationFrame(()=>{if(l!==v)return;let t=n(),a=i.isEnabled()?i.getWindowMessages():t,u=a.findIndex(e=>e===t[r.messageIndex]);if(u<0){d();return}let p=a.slice(0,u+1).filter(I).length-1,m=Array.from(s.querySelectorAll(`user-message`)).filter(e=>e.closest(`message-list`)===s)[p];if(!m){d();return}let h=c.scrollTop+m.getBoundingClientRect().top-c.getBoundingClientRect().top-24,g=Math.max(0,h);Math.abs(c.scrollTop-g)<=1?(c.scrollTop=g,d()):(f(),c.scrollTo({top:g,behavior:`smooth`})),re(e),o()})};(s.updateComplete??Promise.resolve()).then(m,m)},T=()=>{if(c.replaceChildren(),!be(u.length)){s.hidden=!0;return}s.hidden=!1,u.forEach((e,t)=>{let n=document.createElement(`button`);n.type=`button`,n.className=`quickforge-turn-navigation-node`,n.setAttribute(`aria-label`,l(`turnNavigationJumpLabel`,{index:t+1,preview:L(e.userText,l(`turnNavigationAttachmentOnly`))})),n.addEventListener(`pointerenter`,()=>ne(n,t)),n.addEventListener(`pointerleave`,()=>{x(),g=window.setTimeout(S,100)}),n.addEventListener(`focus`,()=>ne(n,t)),n.addEventListener(`blur`,()=>{g=window.setTimeout(S,100)}),n.addEventListener(`click`,()=>w(t)),c.append(n)}),f=-1},oe=()=>{u=we(n(),r());let e=u.map(e=>`${e.messageIndex}:${e.userText}`).join(`|`);e!==d&&(d=e,T()),ae(),ie()},E=e=>{e.key===`Escape`&&S()},D=()=>S();return document.addEventListener(`keydown`,E),window.addEventListener(`resize`,D),{update:oe,cleanup(){v+=1,b?.(),b=null,y?.(),y=null,S(),_?.removeEventListener(`scroll`,ie),document.removeEventListener(`keydown`,E),window.removeEventListener(`resize`,D),s.remove()}}}function R(e){return!!(e&&typeof e==`object`&&!Array.isArray(e))}function z(e,t){let n=e[t];return typeof n==`string`&&n.trim()?n:void 0}function Ee(e,t){let n=e[t];return typeof n==`boolean`?n:void 0}function De(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:void 0}function Oe(e){let t=e&&R(e.diff)?e.diff:void 0;return{addedLines:t?De(t,`addedLines`):void 0,removedLines:t?De(t,`removedLines`):void 0}}function ke(e=``){let t=e.toLowerCase(),n=t.replace(/\\/g,`/`).split(`/`).pop()||t;return t.endsWith(`.html`)||t.endsWith(`.htm`)?`html`:/\.(svg|png|jpe?g|webp|gif|ico)$/i.test(t)?`image`:/\.(md|mdx|markdown)$/i.test(t)?`markdown`:n===`dockerfile`||n.endsWith(`.dockerfile`)||n===`makefile`||/\.(ts|tsx|js|jsx|mjs|cjs|css|scss|less|json|jsonc|txt|csv|tsv|log|sql|xml|yml|yaml|toml|ini|py|rb|go|rs|java|swift|kt|kts|c|h|cpp|hpp|cs|php|sh|bash|zsh|ps1)$/i.test(t)?`code`:`unknown`}function B(e){return e===`html`||e===`image`||e===`markdown`||e===`code`}function V(e){return[e.source,e.path??``,e.command??``,e.outputFile??``,e.toolCallId??``,e.preview?`preview`:``].join(`\0`)}function Ae(e,t,n){let r=V(n);t.has(r)||(t.add(r),e.push({id:`${e.length}:${r}`,...n}))}function H(e){if(!(typeof e!=`string`||!e.trim()))try{return JSON.parse(e)}catch{return}}function U(e,t){if(t&&(Array.isArray(t.files)||Array.isArray(t.previewed)))return t;let n=e.data;if(Array.isArray(n))for(let e of n){if(!R(e)||e.type!==`text`)continue;let t=H(e.text);if(R(t)&&(Array.isArray(t.files)||Array.isArray(t.previewed)))return t}let r=e.content;if(Array.isArray(r))for(let e of r){if(!R(e)||e.type!==`text`)continue;let t=H(e.text);if(R(t)&&(Array.isArray(t.files)||Array.isArray(t.previewed)))return t}return t}function je(e){if(typeof e==`string`&&e.trim())return{path:e};if(R(e)){let t=z(e,`path`);return t?{path:t,title:z(e,`title`),description:z(e,`description`),kind:z(e,`kind`),preview:Ee(e,`preview`)}:void 0}}function Me(e){let t=new Set,n=[];for(let r of e){if(r.role!==`toolResult`)continue;let e=typeof r.toolName==`string`?r.toolName:``,i=R(r.details)?r.details:void 0,a=typeof r.toolCallId==`string`?r.toolCallId:void 0;if(!(!i&&e!==`present_files`)){if(e===`write_file`||e===`edit_file`){let r=i?z(i,`path`):void 0;if(r){let o=ke(r),{addedLines:s,removedLines:c}=Oe(i);Ae(n,t,{source:e,confidence:`high`,path:r,toolCallId:a,kind:o,preview:B(o),presentation:`inferred`,addedLines:s,removedLines:c})}}else if(e===`present_files`){let e=U(r,i),o=R(e)&&Array.isArray(e.files)?e.files:[],s=R(e)?z(e,`defaultPreview`):void 0,c=new Set(R(e)&&Array.isArray(e.previewed)?e.previewed.filter(e=>typeof e==`string`):[]);for(let e of o){let r=je(e);if(!r?.path)continue;let i=r.kind??ke(r.path);Ae(n,t,{source:`present_files`,confidence:`high`,path:r.path,title:r.title,description:r.description,toolCallId:a,kind:i,preview:r.preview??(c.has(r.path)||s===r.path||B(i)),defaultPreview:s===r.path,presentation:`explicit`})}}else if(e===`run_command`&&i){let e=z(i,`command`),r=z(i,`outputFile`);(e||r)&&Ae(n,t,{source:`run_command`,confidence:`low`,command:e,outputFile:r,toolCallId:a})}}}return n}function Ne(e){return e?.length?Me(e):[]}var W=`quickforge:composer-drafts:v1`,G=100,K={},q=!1;function Pe(e){return!!(e&&!e.startsWith(`pending-`))}function Fe(e){return Pe(e.sessionId)?`session:${e.sessionId}`:e.scope===`project`&&e.projectId?`new:project:${e.projectId}`:`new:global`}function Ie(e){if(!e||typeof e!=`object`||Array.isArray(e))return{};let t={};for(let[n,r]of Object.entries(e)){if(!r||typeof r!=`object`||Array.isArray(r))continue;let e=r;typeof e.text==`string`&&(t[n]={text:e.text,updatedAt:typeof e.updatedAt==`string`?e.updatedAt:new Date().toISOString(),scope:e.scope===`project`?`project`:e.scope===`global`?`global`:void 0,projectId:typeof e.projectId==`string`?e.projectId:void 0,sessionId:typeof e.sessionId==`string`?e.sessionId:void 0})}return t}function Le(){try{return globalThis.localStorage}catch{return}}function Re(e,t=G){return Object.fromEntries(Object.entries(e).filter(([,e])=>e.text.length>0).sort(([,e],[,t])=>t.updatedAt.localeCompare(e.updatedAt)).slice(0,t))}function ze(){let e=Le();if(!e||q)return K;let t;try{t=e.getItem(W)}catch{return q=!0,K}try{return Ie(t?JSON.parse(t):void 0)}catch{return K}}function Be(e){let t=Re(e);K=t;let n=Le();if(!(!n||q))try{Object.keys(t).length===0?n.removeItem(W):n.setItem(W,JSON.stringify(t))}catch{let e=Re(t,Math.ceil(G/2));K=e;try{Object.keys(e).length===0?n.removeItem(W):n.setItem(W,JSON.stringify(e))}catch{q=!0}}}async function Ve(e){let t=ze()[e];if(!(!t||t.text.length===0))return{text:t.text,attachments:[]}}async function He(e,t,n){let r=t.text??``;if(r.length===0){await Ue(e);return}let i=ze();i[e]={text:r,updatedAt:new Date().toISOString(),scope:n.scope,projectId:n.scope===`project`?n.projectId:void 0,sessionId:Pe(n.sessionId)?n.sessionId:void 0},Be(i)}async function Ue(e){let t=ze();Object.prototype.hasOwnProperty.call(t,e)&&(delete t[e],Be(t))}function We(e,t,n=200){for(e.delete(t),e.add(t);e.size>n;){let t=e.values().next().value;if(t===void 0)break;e.delete(t)}}function Ge(){let e=0;return{version:()=>e,isCurrent:t=>t===e,invalidate:()=>(e+=1,e)}}var Ke=n();function qe(e){let t=e.state.contextCompaction;if(!t?.summaryMessage)return e.state.messages;let n=e.state.messages,r=Math.min(n.length,Math.max(0,Number(t.compactedUpToIndex)||0));return[t.summaryMessage,...n.slice(r)]}function Je(e){let t=String(e.length);for(let n of e)n.role===`toolResult`&&(t+=`|${n.toolCallId??``}:${n.toolName??``}`);return t}function Ye({agent:e,onModelSelect:t,revision:n,agentAccessMode:w,workspaceToolsEnabled:E,project:D,projectId:se,chatScope:ce=`global`,onAccessModeChange:le,onRollbackFromMessage:O,onRetryFromMessage:de,onCopyAnswer:k,onForkFromMessage:fe,onApproveToolCall:ge,onRejectToolCall:A,onApproveAutoCompact:_e,onRejectAutoCompact:j,onOpenWorkspaceGitChanges:M,onOpenLocalFilePath:N,onArtifactsChange:ve,onContextUsageDisplayChange:P,onInitialRenderReady:be,onInitialRenderError:xe,restoredDraft:F,onRestoredDraftConsumed:Se,disableFork:Ce=!1,readOnly:we=!1,approvalReadOnly:I=!1,approvalReadOnlyMessage:L,bypassClientApiKeyCheck:R=!1,allowModelControls:z=!0,newChatEmptyState:Ee=!1,showTurnNavigation:De=!0,rollbackConfirmTitle:Oe,rollbackConfirmDescription:ke,capabilities:B=g}){let V=(0,T.useRef)(null),Ae=(0,T.useRef)(void 0),H=(0,T.useRef)(void 0),U=(0,T.useRef)(new Map),je=(0,T.useRef)([]),Me=(0,T.useRef)(void 0),W=(0,T.useRef)(new Set),G=(0,T.useRef)(void 0),K=(0,T.useRef)(null),q=(0,T.useRef)(!1),Pe=(0,T.useRef)(new WeakSet),Ie=(0,T.useRef)(``),Le=(0,T.useRef)(``),Re=(0,T.useRef)(Ge()),[ze,Be]=(0,T.useState)(),[Ye,Xe]=(0,T.useState)(!1),J=(0,T.useMemo)(()=>m(B,{readOnly:we,disableFork:Ce}),[B,we,Ce]),Ze=(0,T.useCallback)(()=>Xe(e=>!e),[]),Qe=(0,T.useCallback)(()=>Xe(!1),[]);(0,T.useEffect)(()=>{let t=e,n=J.planMode&&Ye;t?.setPlanMode?.(n,n?Qe:void 0),!J.planMode&&Ye&&queueMicrotask(Qe)},[e,Ye,Qe,J.planMode]);let $e=(0,T.useCallback)(()=>{G.current&&=(window.clearTimeout(G.current),void 0)},[]),Y=(0,T.useCallback)(()=>{K.current?.cancel(),K.current=null,q.current=!1},[]),et=(0,T.useCallback)(e=>{We(W.current,e),Se?.(e)},[Se]),tt=(0,T.useMemo)(()=>({sessionId:e?.sessionId,scope:ce,projectId:se}),[e?.sessionId,ce,se]),nt=Fe(tt),rt=(0,T.useRef)(tt),it=(0,T.useRef)(nt);(0,T.useEffect)(()=>{rt.current=tt,it.current=nt},[tt,nt]),(0,T.useEffect)(()=>()=>{$e(),Y()},[$e,Y]);let at=(0,T.useCallback)((e,t,n)=>{if(t.text.length===0){Ue(e).catch(e=>a.error(`Failed to clear composer draft:`,e));return}He(e,t,n).catch(e=>a.error(`Failed to save composer draft:`,e))},[]),ot=(0,T.useCallback)((e,t,n)=>{G.current&&window.clearTimeout(G.current),G.current=window.setTimeout(()=>{G.current=void 0,at(e,t,n)},400)},[at]),st=(0,T.useCallback)((e,t=it.current,n=rt.current)=>{let r=C(e);c(r)?U.current.set(t,r):U.current.delete(t),at(t,r,n)},[at]),X=(0,T.useRef)({onCopyAnswer:k,onRollbackFromMessage:O,onRetryFromMessage:de,onForkFromMessage:fe,onAccessModeChange:le,onTogglePlanMode:Ze,onApproveToolCall:ge,onRejectToolCall:A,onApproveAutoCompact:_e,onRejectAutoCompact:j,onOpenWorkspaceGitChanges:M,onOpenLocalFilePath:N,onArtifactsChange:ve,onContextUsageDisplayChange:P,onInitialRenderReady:be,onInitialRenderError:xe,onModelSelect:t,agentAccessMode:w,planMode:Ye,workspaceToolsEnabled:E,disableFork:Ce,readOnly:we,approvalReadOnly:I,approvalReadOnlyMessage:L,allowModelControls:z,newChatEmptyState:Ee,bypassClientApiKeyCheck:R,rollbackConfirmTitle:Oe,rollbackConfirmDescription:ke,capabilities:J,gitBranch:ze});(0,T.useEffect)(()=>{X.current={onCopyAnswer:k,onRollbackFromMessage:O,onRetryFromMessage:de,onForkFromMessage:fe,onAccessModeChange:le,onTogglePlanMode:Ze,onApproveToolCall:ge,onRejectToolCall:A,onApproveAutoCompact:_e,onRejectAutoCompact:j,onOpenWorkspaceGitChanges:M,onOpenLocalFilePath:N,onArtifactsChange:ve,onContextUsageDisplayChange:P,onInitialRenderReady:be,onInitialRenderError:xe,onModelSelect:t,agentAccessMode:w,planMode:Ye,workspaceToolsEnabled:E,disableFork:Ce,readOnly:we,approvalReadOnly:I,approvalReadOnlyMessage:L,allowModelControls:z,newChatEmptyState:Ee,bypassClientApiKeyCheck:R,rollbackConfirmTitle:Oe,rollbackConfirmDescription:ke,capabilities:J,gitBranch:ze},H.current=F});let ct=D?.id??se;(0,T.useEffect)(()=>{let e=!1;return queueMicrotask(()=>{if(!e){if(!ct){Be(void 0);return}p(ct).then(t=>{e||Be(t.isGitRepository?t.branch:void 0)}).catch(t=>{e||(a.warn(`Failed to load git branch:`,t),Be(void 0))})}}),()=>{e=!0}},[ct,n]);let lt=(0,T.useRef)(null),ut=(0,T.useRef)(null),Z=(0,T.useRef)(null),Q=(0,T.useRef)(null),$=(0,T.useRef)(null);(0,T.useEffect)(()=>{let e=!1;return!J.commands||!D?.id?(je.current=[],()=>{e=!0}):(fetch(`/api/project/commands?projectId=${encodeURIComponent(D.id)}`,{cache:`no-store`}).then(e=>e.ok?e.json():{commands:[]}).then(t=>{e||(je.current=Array.isArray(t.commands)?t.commands:[],Z.current?.())}).catch(()=>{e||(je.current=[],Z.current?.())}),()=>{e=!0})},[D?.id,n,J.commands]);let dt=(0,T.useCallback)((e,t,n,r)=>{if(t.sessionId&&t.sessionId!==n||!c(t)||W.current.has(t.id))return;let i=e.querySelector(`message-editor`),a=i?{text:i.value??i.querySelector(`textarea`)?.value??``,attachments:i.attachments?[...i.attachments]:[]}:U.current.get(r),o=Me.current;if(!(o?.id!==t.id||!c(a??f())||a?.text===o.text))return;Re.current.invalidate(),Y();let s=e.querySelector(`agent-interface`);K.current=b(e,t,U.current,r,{shouldApply:()=>!W.current.has(t.id)&&e.isConnected&&!!V.current?.contains(e),onApplyStart:()=>{q.current=!0},onApplyEnd:()=>{q.current=!1},onApplied:()=>{Pe.current.add(e),Ae.current=t.id,Me.current={id:t.id,text:t.text},et(t.id)},updateComplete:s?.updateComplete})},[Y,et]);return(0,T.useEffect)(()=>{if(!V.current||!e)return;let t=Re.current,n=Pe.current,p=new r;Xe(!1);let m=e.sessionId,g=it.current,C=rt.current,w=!1,T,E=!1,D=!1,se=!1,ce=e.state.isStreaming,le=!1,O=0,de,k=ue({enabled:!1});pe(()=>k);let fe=!1,ge=()=>{if(w||fe||!k.hasMore())return;let e=p.querySelector(`message-list`),t=p.querySelector(`agent-interface .overflow-y-auto`);if(!e||!t)return;let n=Array.from(e.querySelectorAll(`user-message, assistant-message`)).filter(t=>t.closest(`message-list`)===e),r=t.getBoundingClientRect().top,i=-1,a=0;for(let e=0;e<n.length;e++){let t=n[e].getBoundingClientRect();if(t.bottom>r){i=e,a=t.top;break}}let o=t.scrollTop,s=k.loadMore();if(!s)return;fe=!0,e.messages=s;let c=()=>{window.requestAnimationFrame(()=>{if(fe=!1,!w){if(i>=0){let n=Array.from(e.querySelectorAll(`user-message, assistant-message`))[i];n&&(t.scrollTop=o+(n.getBoundingClientRect().top-a))}Z.current?.()}})};(e.updateComplete??Promise.resolve()).then(c,c)},A=oe({panel:p,onReachTop:()=>{ge()},onAutoScrollEnabled:()=>{k.resetToTail()}});ut.current=A;let _e=null,j=he({panel:p,getCustomCommands:()=>je.current,getComposerDrafts:()=>U.current,sessionId:g,setComposerDrafts:e=>{U.current=e},restoreDraftIntoComposer:e=>{x(p,e,U.current,g),ot(g,e,C)}}),M=ye({panel:p,enabled:J.capabilitySuggestions,restoreDraftIntoComposer:e=>{x(p,e,U.current,g),ot(g,e,C)}}),N=u({panel:p,getSystemPrompt:()=>e.state.systemPrompt,getMessages:()=>e.state.messages,getEffectiveMessages:()=>qe(e),getContextWindow:()=>e.state.model?.contextWindow??0,getTools:()=>e.state.tools,getServerContextUsage:()=>e.state.contextUsage??null,getIsCompacted:()=>!!e.state.contextCompaction?.summaryMessage,getGitBranch:()=>X.current.gitBranch,onGitBranchClick:()=>X.current.onOpenWorkspaceGitChanges?.(),renderInline:!1,renderModelRing:s().showContextUsage,onDisplayChange:t=>X.current.onContextUsageDisplayChange?.(e.sessionId,t)}),ve=S({panel:p,getAcpSession:()=>e.state.acpSession??null}),P=()=>{if(q.current)return;se=!0,t.invalidate(),Y();let e=H.current;e&&(!e.sessionId||e.sessionId===m)&&et(e.id)},be=e=>{P(),E=!1;let t=p.querySelector(`message-editor`),n={text:e,attachments:t?.attachments?[...t.attachments]:[]};c(n)?(U.current.set(g,n),ot(g,n,C)):(U.current.delete(g),$e(),Ue(g).catch(e=>a.error(`Failed to clear composer draft:`,e)))},xe=e=>{P(),E=!1;let t=p.querySelector(`message-editor`),n=t?.querySelector(`textarea`),r={text:t?.value??n?.value??``,attachments:e?[...e]:[]};c(r)?(U.current.set(g,r),ot(g,r,C)):(U.current.delete(g),$e(),Ue(g).catch(e=>a.error(`Failed to clear composer draft:`,e)));let i=p.querySelector(`agent-interface`);i?.requestUpdate?.(),window.requestAnimationFrame(()=>Z.current?.()),i?.updateComplete?.then(()=>Z.current?.())},F=()=>{e.state.isStreaming?p.dataset.quickforgeAgentStreaming=`true`:delete p.dataset.quickforgeAgentStreaming},Se=!1,Ce=()=>{if(w||Se)return;Se=!0;let t=()=>{if(Se=!1,w)return;let t=Ne(e.state.messages),n=JSON.stringify(t.map(e=>[e.source,e.path,e.command,e.outputFile,e.confidence,e.preview,e.defaultPreview,e.addedLines,e.removedLines]));n!==Ie.current&&(Ie.current=n,X.current.onArtifactsChange?.(t))};typeof window.requestIdleCallback==`function`?window.requestIdleCallback(t,{timeout:500}):t()},we=()=>{if(w||!p.isConnected)return;F();let t=()=>k.isEnabled()?k.getWindowMessages():e.state.messages,n=k.isEnabled()?k.getWindowStart():0,r=X.current,i=Je(e.state.messages);i!==Le.current&&(Le.current=i,Ce());try{ee({panel:p,getMessages:t,messageIndexOffset:n,isStreaming:()=>e.state.isStreaming,onCopyAnswer:r.onCopyAnswer,onRollbackFromMessage:r.onRollbackFromMessage,onRetryFromMessage:r.onRetryFromMessage,onForkFromMessage:r.onForkFromMessage,onOpenLocalFilePath:r.onOpenLocalFilePath,disableFork:!r.capabilities.forkFromMessage,allowRollback:r.capabilities.rollback,allowRetry:r.capabilities.retry,readOnly:r.readOnly,enableTerminalCommandActions:!r.readOnly,rollbackConfirmTitle:r.rollbackConfirmTitle,rollbackConfirmDescription:r.rollbackConfirmDescription}),ae({panel:p,getMessages:t,getContextCompaction:()=>r.capabilities.compaction?e.state.contextCompaction??null:null,messageIndexOffset:n}),re({panel:p,getMessages:t,isStreaming:()=>e.state.isStreaming,isActive:ce})}catch(e){a.warn(`Failed to decorate chat messages:`,e)}try{te({panel:p,isStreaming:()=>e.state.isStreaming,abort:()=>e.abort(),agentAccessMode:r.agentAccessMode,harness:e.harness,getAcpSession:()=>e.state.acpSession??null,onOpenCodeConfigOptionChange:(t,n)=>{e.setConfigOption(t,n).catch(e=>{a.error(`Failed to update OpenCode config option:`,e)})},onOpenCodeModeChange:t=>{e.setMode(t).catch(e=>{a.error(`Failed to update OpenCode mode:`,e)})},planMode:r.planMode,workspaceToolsEnabled:r.workspaceToolsEnabled,readOnly:r.readOnly,allowModelControls:r.allowModelControls&&r.capabilities.modelSelection,planModeEnabled:r.capabilities.planMode,accessModeEnabled:r.capabilities.accessMode,commandSuggestionsEnabled:r.capabilities.commands,capabilitySuggestionsEnabled:r.capabilities.capabilitySuggestions,attachmentsEnabled:r.capabilities.attachments,onAccessModeChange:r.onAccessModeChange,onTogglePlanMode:r.onTogglePlanMode,onInput:be,onFilesChange:xe,removeCommandSuggestions:j.remove,updateCommandSuggestions:j.update,setupCommandTextareaHandler:j.setupTextareaHandler,removeCapabilitySuggestions:M.remove,updateCapabilitySuggestions:M.update,setupCapabilityTextareaHandler:M.setupTextareaHandler,insertBuiltinPluginMention:M.insertBuiltinPluginMention,availablePluginRows:M.availablePluginRows,onBeforeSend:t=>{h();let n=r.capabilities.capabilitySuggestions?M.consumeSelectedCapabilities(t):[];e.setNextPromptCapabilities?.(n)}})}catch{}let o=Q.current??(()=>{let t=e.state.pendingToolApproval;return t?{...t,sessionId:e.sessionId}:null})();if(o&&o.sessionId===e.sessionId&&typeof o.toolCallId==`string`&&typeof o.toolName==`string`){let t=o.toolCallId;v({panel:p,tone:`warning`,disabled:r.approvalReadOnly,disabledReason:r.approvalReadOnlyMessage,onApprove:async()=>{await X.current.onApproveToolCall(t),Q.current=null,e.state.pendingToolApproval=null,y(p)},onReject:async()=>{await X.current.onRejectToolCall(t),Q.current=null,e.state.pendingToolApproval=null,y(p)}},o.toolName,t,o.args,o.source)}else{let n=$.current??(()=>{let t=e.state.pendingAutoCompactApproval;return t?{...t,sessionId:e.sessionId}:null})();if(n&&n.sessionId===e.sessionId){let i=n.approvalId,a=!r.onApproveAutoCompact||!r.onRejectAutoCompact,o=r.approvalReadOnly||a,s=r.approvalReadOnly?r.approvalReadOnlyMessage:a?l(`autoCompactApprovalUnavailable`):void 0;v({panel:p,tone:`info`,copy:{status:l(`autoCompactApprovalStatus`),title:l(`autoCompactApprovalTitle`),risk:l(`autoCompactApprovalRisk`,{keepRecentTurns:n.keepRecentTurns??3}),approve:l(`autoCompactApprovalAccept`),reject:l(`autoCompactApprovalReject`)},disabled:o,disabledReason:s,getMessages:t,keepRecentTurns:n.keepRecentTurns??3,onApprove:async()=>{let t=X.current.onApproveAutoCompact;if(!t)throw Error(l(`autoCompactApprovalUnavailable`));await t(i),$.current=null,e.state.pendingAutoCompactApproval=null,y(p)},onReject:async()=>{let t=X.current.onRejectAutoCompact;if(!t)throw Error(l(`autoCompactApprovalUnavailable`));await t(i),$.current=null,e.state.pendingAutoCompactApproval=null,y(p)}},l(`contextManagement`),i,{percent:n.usage?.percent??0,threshold:n.thresholdPercent??0,keepRecentTurns:n.keepRecentTurns??3,summary:l(`autoCompactApprovalWaiting`,{percent:n.usage?.percent??0,threshold:n.thresholdPercent??0}),description:l(`autoCompactApprovalPreview`,{keepRecentTurns:n.keepRecentTurns??3})})}else y(p)}r.capabilities.contextUsage?N.update():N.cleanup(),e.harness===`opencode`&&ve.update(),_e?.update(),A.setup(),A.isEnabled&&(k.resetToTail(),A.scheduleScrollToBottom())},I=!1,L,R=!1,z,Ee=()=>{z===void 0&&(z=window.requestAnimationFrame(()=>{z=void 0,R=!1}))},Oe=()=>{if(!w){R=!0;try{we()}finally{Ee()}}},ke=()=>{I||(I=!0,L=window.requestAnimationFrame(()=>{L=void 0,I=!1,Oe()}))};lt.current=Oe;let B=()=>p.querySelector(`agent-interface`),Me=()=>{le||(le=!0,window.requestAnimationFrame(()=>{if(le=!1,w)return;F();let e=B();e?.requestUpdate?.(),(e?.updateComplete??Promise.resolve()).then(()=>{w||Oe()}),A.isEnabled&&A.scheduleScrollToBottom()}))};Z.current=ke;let W=()=>{let e=++O;p.dataset.quickforgeProcessHandoff=String(e);let t=B();t?.requestUpdate?.(),Z.current?.(),window.requestAnimationFrame(()=>{!w&&O===e&&Z.current?.()});let n=()=>{w||O!==e||(delete p.dataset.quickforgeProcessHandoff,Z.current?.(),window.requestAnimationFrame(()=>{!w&&O===e&&Z.current?.()}))};(t?.updateComplete??Promise.resolve()).then(n,n)};p.setAgent(e,{onApiKeyRequired:!X.current.capabilities.clientApiKeyCheck||X.current.bypassClientApiKeyCheck?async()=>!0:t=>o(e.state.model)?Promise.resolve(!0):i.prompt(t),onBeforeSend:()=>{t.invalidate(),Y();let e=H.current;e&&(!e.sessionId||e.sessionId===m)&&et(e.id),$e(),E=!0,j.remove(),U.current.delete(g),Ue(g).catch(e=>a.error(`Failed to clear composer draft:`,e)),A.enable()},onModelSelect:X.current.onModelSelect,toolsFactory:()=>ie(e.state.tools)}).then(()=>{if(w)return;let e=H.current,n=t.version(),r=r=>{if(!(w||!t.isCurrent(n)))if(e&&Ae.current!==e.id)dt(p,e,m,g);else{let e=r??U.current.get(g)??f();c(e)||(D=!0),Y();let i=p.querySelector(`agent-interface`);K.current=b(p,e,U.current,g,{shouldApply:()=>!w&&t.isCurrent(n)&&p.isConnected&&!!V.current?.contains(p),onApplyStart:()=>{q.current=!0},onApplyEnd:()=>{q.current=!1},onApplied:()=>{D=!0,Pe.current.add(p)},updateComplete:i?.updateComplete})}};if(e&&Ae.current!==e.id)r();else{let e=U.current.get(g);e?r(e):Ve(g).then(e=>r(e)).catch(e=>a.error(`Failed to load composer draft:`,e))}T=new MutationObserver(()=>{R||ke()}),T.observe(p,{childList:!0,subtree:!0}),window.requestAnimationFrame(()=>{w||Oe()});let i=B(),o=()=>{w||(de=d(()=>{w||X.current.onInitialRenderReady?.(m)}))};(i?.updateComplete??Promise.resolve()).then(o,o)},e=>{w||(a.error(`Failed to initialize chat panel:`,e),X.current.onInitialRenderError?.(m,e))}),V.current.replaceChildren(p),De&&(_e=Te({host:V.current,panel:p,getMessages:()=>e.state.messages,isStreaming:()=>e.state.isStreaming,windowLayer:k,beginProgrammaticScroll:A.beginProgrammaticScroll,onWindowChanged:()=>Z.current?.()}));let G=e.subscribe(t=>{if(t.type===`agent_start`&&(O+=1,delete p.dataset.quickforgeProcessHandoff,ce=!0,F(),Z.current?.(),A.enable(),Q.current?.sessionId===e.sessionId&&(Q.current=null),$.current?.sessionId===e.sessionId&&($.current=null)),t.type===`message_start`||t.type===`message_update`||t.type===`message_end`||t.type===`turn_end`||t.type===`agent_end`){F();let e=t.message;t.type===`message_start`&&e?.role===`assistant`&&(O+=1,delete p.dataset.quickforgeProcessHandoff),(t.type===`message_update`||e?.role===`assistant`)&&(ce=!1),Z.current?.(),t.type===`message_end`&&e?.role===`assistant`&&W(),A.isEnabled&&A.scheduleScrollToBottom()}if(t.type===`messages_replaced`){let e=H.current;e&&Ae.current===e.id&&dt(p,e,m,g)}let n=t.type;if(n===`tool_execution_start`){let n=t,r=Q.current,i=n.sessionId??e.sessionId;r&&r.sessionId===e.sessionId&&i===e.sessionId&&n.toolCallId===r.toolCallId&&(Q.current=null,e.state.pendingToolApproval?.toolCallId===n.toolCallId&&(e.state.pendingToolApproval=null),Z.current?.())}if((n===`tool_execution_start`||n===`tool_execution_update`||n===`tool_execution_end`)&&Me(),(n===`acp_session_update`||n===`acp_session_usage_update`)&&Z.current?.(),t.type===`agent_end`&&(ce=!1,F(),W(),Q.current?.sessionId===e.sessionId&&(Q.current=null,Z.current?.()),$.current?.sessionId===e.sessionId&&($.current=null,Z.current?.())),(n===`auto_compact_completed`||n===`auto_compact_failed`)&&($.current?.sessionId===e.sessionId&&($.current=null),e.state.pendingAutoCompactApproval=null,Z.current?.()),n===`auto_compact_completed`||n===`messages_replaced`){_(p);let e=B();e?.requestUpdate?.(),Z.current?.(),window.requestAnimationFrame(()=>Z.current?.()),e?.updateComplete?.then(()=>Z.current?.())}if(n===`auto_compact_failed`&&a.warn(l(`autoCompactFailed`)),t.type===`tool_approval_required`){let e=t;Q.current={toolCallId:e.toolCallId,toolName:e.toolName,args:e.args,sessionId:e.sessionId,source:e.source},Z.current?.()}if(t.type===`auto_compact_approval_required`){let e=t;$.current={approvalId:e.approvalId,usage:e.usage,thresholdPercent:e.thresholdPercent,keepRecentTurns:e.keepRecentTurns,sessionId:e.sessionId},Z.current?.()}});return()=>{w=!0,t.invalidate(),Y(),$e(),de?.(),E?(U.current.delete(g),Ue(g).catch(e=>a.error(`Failed to clear composer draft:`,e))):(D||se||n.has(p))&&(ne(p,U.current,g),st(p,g,C)),j.remove(),j.cleanupTextareaHandler(),M.remove(),M.cleanupTextareaHandler(),N.cleanup(),ve.cleanup(),_e?.cleanup(),A.cleanup(),ut.current=null,me(k),G(),T?.disconnect(),L!==void 0&&window.cancelAnimationFrame(L),z!==void 0&&window.cancelAnimationFrame(z),lt.current=null,p.remove()}},[e,De,J.capabilitySuggestions,$e,Y,et,st,dt,ot]),(0,T.useEffect)(()=>{let e=V.current;e&&(e.classList.toggle(`quickforge-chat-panel-empty-host`,Ee),e.dataset.quickforgeEmptyChat=Ee?`true`:`false`)},[Ee]),(0,T.useEffect)(()=>{lt.current?.(),(V.current?.querySelector(`agent-interface`))?.requestUpdate?.()},[w,Ye,E,ze,Ce,we,I,L,z,B,n]),(0,T.useEffect)(()=>{let t=H.current;if(!t||!V.current)return;let n=e?.sessionId??``;if(t.sessionId&&t.sessionId!==n||W.current.has(t.id))return;let r=V.current.querySelector(`pi-chat-panel`);r&&dt(r,t,n,it.current)},[F,e,dt]),(0,Ke.jsx)(`div`,{ref:V,className:`quickforge-chat-panel-host min-h-0 flex-1 overflow-hidden`})}export{Ye as ChatPanelHost};
@@ -1 +1 @@
1
- import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{C as t,Jt as n,K as r,St as i,Z as a,a as ee,bt as te,c as ne,m as re,mt as ie,q as ae,v as oe,vt as se,w as o,x as ce}from"./icons-DM_qJ7VJ.js";import{n as s}from"./react-vendor-BpWW_Nvp.js";import{$ as le,An as ue,G as de,H as fe,J as pe,K as me,Mn as c,Nn as he,Pn as l,Q as ge,Tt as u,U as _e,W as d,X as ve,Y as ye,Z as be,at as f,et as xe,it as Se,kn as p,nt as Ce,q as we,rt as Te,tt as Ee}from"./index-DFASc15l.js";var m=e(n(),1);function h(e,t=`cloudRequestFailed`){return e instanceof d?e.code===`cloud_session_active`?l(`cloudSessionActiveGuidance`):e.code===`cloud_disabled`?l(`cloudDisabledError`):e.code===`cloud_local_only`?l(`cloudLocalOnlyError`):e.code===`cloud_configuration_error`||e.code===`cloud_not_configured`?l(`cloudConfigurationError`):e.code===`cloud_session_service_mismatch`?l(`cloudSessionServiceMismatch`):[`expired_token`,`device_code_expired`,`expired`].includes(e.code)?l(`cloudDeviceFlowExpiredError`):[`access_denied`,`authorization_declined`,`denied`].includes(e.code)?l(`cloudDeviceFlowDeniedError`):[`refresh_token_reused`,`installation_revoked`,`invalid_refresh_token`,`cloud_not_connected`].includes(e.code)?l(`cloudSessionExpired`):c()===`en`&&e.message.trim()?e.message:e.status>0?l(`cloudRequestFailedWithStatus`,{status:e.status}):l(t):l(t)}var De={usage:void 0,installations:[],models:[],errors:{},loading:!1};function Oe(e,t){return t.type===`replace`?t.state:{...De,loading:t.type===`begin`}}async function ke(e,t){let[n,r,i]=await Promise.allSettled([e.usage(),e.installations(),e.models()]);return{usage:n.status===`fulfilled`?n.value:void 0,installations:r.status===`fulfilled`?r.value:[],models:i.status===`fulfilled`?i.value:[],errors:{...n.status===`rejected`?{usage:t(`usage`,n.reason)}:{},...r.status===`rejected`?{installations:t(`installations`,r.reason)}:{},...i.status===`rejected`?{models:t(`models`,i.reason)}:{}},loading:!1}}function Ae({loading:e,loadError:t,status:n,details:r}){if(e&&!n)return`loading`;if(t)return`load-error`;if(!n?.configured)return`unconfigured`;if(n.sessionServiceMismatch)return`session-mismatch`;if(n.pendingDeviceFlow)return n.hasSession?`connected`:`no-session`;if(!n.hasSession)return`no-session`;let i=Object.values(r.errors);return n.cloudAvailable===!1||i.length===3&&i.every(e=>e?.unavailable)?`cloud-unavailable`:i.length>0?`partial-details`:`connected`}function je(e){let t=e?.configured===!0,n=t&&e.hasSession===!0,r=n&&e.sessionServiceMismatch!==!0;return{showDeviceFlow:t&&!!e.pendingDeviceFlow,showDisconnectedActions:t&&!e.pendingDeviceFlow&&!n,showDetails:r}}function Me(e){return e===`starting`||e===`authorizing`}function Ne(e){if(e?.status!==`authorizing`)return{pending:!1,failed:!1,needsLocalEnable:!1};let t=e.autoApproval;return t?.status===`armed`||t?.status===`pending`||t?.status===`consumed`?{pending:!0,failed:!1,needsLocalEnable:!1}:t?.status===`failed`?{pending:!1,failed:!0,failedError:t.error||void 0,needsLocalEnable:!1}:{pending:!1,failed:!1,needsLocalEnable:!0}}function Pe(e,t){return!!(e?.hasSession&&(t||e.sessionServiceMismatch))}async function Fe(e,t){await t.reset(),t.onIdentityReset?.();try{return{status:`success`,config:await t.save(e)}}catch(e){return{status:`url-save-failed`,error:e}}}var g=s();function _(e){if(!e)return l(`cloudNotAvailable`);let t=new Date(e);return Number.isNaN(t.getTime())?l(`cloudNotAvailable`):t.toLocaleString(he())}function v(e){let t=e.id||e.installationId;return typeof t==`string`?t:``}function y(e){let t=e.name||e.installationName;return typeof t==`string`&&t?t:l(`cloudUnnamedDevice`)}function Ie(e){return typeof e==`number`&&Number.isFinite(e)?e.toLocaleString(he()):l(`cloudNotAvailable`)}function Le(e){return l(e===`saved`?`cloudConfigSourceSaved`:e===`env`?`cloudConfigSourceEnv`:`cloudConfigSourceDefault`)}function b(e){let t=String(e||``).toLowerCase();return t===`localhost`||t.endsWith(`.localhost`)||t.startsWith(`127.`)?!0:t===`::1`}function x(e){let t=e.trim();if(!t)return``;let n;try{n=new URL(t)}catch{return l(`cloudUrlInvalid`)}return n.protocol!==`https:`&&n.protocol!==`http:`?l(`cloudUrlInvalidProtocol`):b(n.hostname)&&n.port===`8081`?l(`cloudUrlAdminPort`):``}function S(e){if(!e||typeof e!=`object`)return l(`cloudConnectionUnknown`);let t=e;return t.ok===!0||t.status===`ok`||t.ready===!0?l(`cloudConnectionOk`):l(`cloudConnectionError`)}function C(e){if(!e||typeof e!=`object`)return!1;let t=e;return t.ok===!0||t.status===`ok`||t.ready===!0}function Re(e,t){let n=S(t);return(0,g.jsxs)(`span`,{className:ue(`quickforge-settings-badge`,n===l(`cloudConnectionUnknown`)?`quickforge-settings-badge-muted`:C(t)?`quickforge-settings-badge-success`:`quickforge-settings-badge-danger`),children:[e,`: `,n]})}function ze(e){let t=e.quickforgeCapabilities;return[t?.tools?l(`cloudCapabilityTools`):void 0,t?.vision?l(`cloudCapabilityVision`):void 0,t?.reasoning?l(`cloudCapabilityReasoning`):void 0].filter(Boolean).join(` · `)||l(`cloudCapabilityText`)}function Be(e){return l(e?e===`disabled`?`cloudRemoteStatusDisabled`:e===`unavailable`?`cloudRemoteStatusUnavailable`:e===`stopped`?`cloudRemoteStatusStopped`:e===`starting`?`cloudRemoteStatusStarting`:e===`authorizing`?`cloudRemoteStatusAuthorizing`:e===`running`?`cloudRemoteStatusRunning`:e===`conflict`?`cloudRemoteStatusConflict`:`cloudRemoteStatusError`:`cloudRemoteStatusLoading`)}function Ve(e,t){let n=e===`usage`?`cloudUsageLoadFailed`:e===`installations`?`cloudDevicesLoadFailed`:`cloudModelsLoadFailed`,r=h(t);return{message:r===l(`cloudRequestFailed`)?l(n):r,unavailable:!(`code`in Object(t))||[`cloud_request_failed`,`cloud_unavailable`].includes(String(t?.code||``))}}function w({error:e,onRetry:t,disabled:n}){return(0,g.jsxs)(`div`,{className:`p-4 text-sm`,children:[(0,g.jsx)(`div`,{className:`quickforge-settings-error`,children:e.message}),(0,g.jsxs)(p,{type:`button`,variant:`outline`,size:`sm`,className:`mt-3`,onClick:t,disabled:n,children:[(0,g.jsx)(o,{className:`mr-2 size-4`}),l(`retry`)]})]})}function T(){let[e,n]=(0,m.useState)(),[s,c]=(0,m.useState)(``),[he,d]=(0,m.useState)(!1),[b,S]=(0,m.useState)(),[C,T]=(0,m.useState)(),[E,He]=(0,m.useState)(),[D,O]=(0,m.useReducer)(Oe,De),[k,Ue]=(0,m.useState)(!0),[A,j]=(0,m.useState)(``),[We,M]=(0,m.useState)(``),[N,P]=(0,m.useState)(``),[Ge,F]=(0,m.useState)(``),[Ke,qe]=(0,m.useState)(0),I=(0,m.useRef)(0),L=(0,m.useRef)(0),R=C?.pendingDeviceFlow,z=R?Math.max(0,Math.ceil((R.expiresAt-Ke)/1e3)):0,B=(0,m.useCallback)(()=>O({type:`clear`}),[]),V=(0,m.useCallback)(async()=>{let e=++L.current;try{let t=await ye();e===L.current&&He(t)}catch{}},[]),H=(0,m.useCallback)(async(e=!0,t=!1,r=!0)=>{let i=++I.current;e&&Ue(!0),P(``),O({type:`begin`}),r&&V();try{let[e,r]=await Promise.all([me(),ve()]);if(i!==I.current)return;if(n(e),t||c(e.cloudUrl),T(r),!e.enabled||!r.configured||!r.hasSession||r.sessionServiceMismatch){B();return}let a=await ke({usage:be,installations:we,models:pe},Ve);if(i!==I.current)return;O({type:`replace`,state:a})}catch(e){if(i!==I.current)return;n(void 0),T(void 0),B(),P(h(e,`cloudLoadFailed`))}finally{i===I.current&&Ue(!1)}},[B,V]);(0,m.useEffect)(()=>{let e=window.setTimeout(()=>{H()},0);return()=>{window.clearTimeout(e),I.current+=1,L.current+=1}},[H]),(0,m.useEffect)(()=>{if(!e?.enabled||!Me(E?.status))return;let t=window.setInterval(()=>{V()},1750);return()=>window.clearInterval(t)},[e?.enabled,V,E?.status]),(0,m.useEffect)(()=>{let e=()=>{document.visibilityState===`visible`&&V()};return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[V]),(0,m.useEffect)(()=>{if(!e?.enabled||!C?.pendingDeviceFlow)return;let t=()=>qe(Date.now()),n=window.setTimeout(t,0),r=window.setInterval(t,1e3);return()=>{window.clearTimeout(n),window.clearInterval(r)}},[e?.enabled,C?.pendingDeviceFlow]),(0,m.useEffect)(()=>{let t=C?.pendingDeviceFlow;if(!e?.enabled||!t||z>0)return;let n=window.setTimeout(()=>{H(!1)},0);return()=>window.clearTimeout(n)},[e?.enabled,z,H,C?.pendingDeviceFlow]),(0,m.useEffect)(()=>{let t=C?.pendingDeviceFlow;if(!e?.enabled||!t||A===`device-start`||A===`device-cancel`)return;let n=Math.max(1,Number(t.interval)||5)*1e3,r=window.setTimeout(async()=>{try{let e=await le();T(e),e.deviceFlowResult===`success`?(window.dispatchEvent(new Event(_e)),P(``),M(l(`cloudDeviceFlowSucceeded`)),await Promise.all([H(!1,!1,!1),V()])):e.deviceFlowResult===`denied`?P(l(`cloudDeviceFlowDenied`)):e.deviceFlowResult===`expired`?P(l(`cloudDeviceFlowExpired`)):e.deviceFlowResult===`network`&&P(l(`cloudDeviceFlowNetwork`))}catch(e){P(h(e))}},n);return()=>window.clearTimeout(r)},[A,e?.enabled,H,V,C?.pendingDeviceFlow]);let U=()=>window.dispatchEvent(new Event(_e)),Je=async()=>{if(!A){if(x(s)){d(!0);return}j(`test`),M(``),P(``),S(void 0);try{let e=await Se(s);c(e.cloudUrl),S(e),M(l(`cloudConnectionTestSucceeded`))}catch(e){P(h(e,`cloudConnectionFailed`))}finally{j(``)}}},Ye=async()=>{if(!A){if(x(s)){d(!0);return}j(`save`),M(``),P(``);try{let e=await f({cloudUrl:s});n(e),c(e.cloudUrl),S(void 0),F(``),U(),M(l(`cloudConnectionSaved`)),await H(!1)}catch(e){P(h(e))}finally{j(``)}}},Xe=async t=>{if(!(A||!e||e.enabled===t)){j(`cloud-toggle`),M(``),P(``),F(``);try{let e=await f({enabled:t});n(e),c(e.cloudUrl),S(void 0),e.enabled||B(),U(),M(l(e.enabled?`cloudServiceEnabledSaved`:`cloudServiceDisabledSaved`)),await H(!1)}catch(e){P(h(e))}finally{j(``)}}},Ze=async()=>{let t=s.trim()||e?.cloudUrl||``;if(x(t)){d(!0);return}if(!(!await u({title:l(`cloudForceSwitchTitle`),description:l(`cloudForceSwitchDescription`),confirmLabel:l(`cloudForceSwitchConfirm`),cancelLabel:l(`cancel`),variant:`destructive`})||A||!t)){j(`force-switch`),M(``),P(``),F(``);try{let e=await Fe(t,{reset:xe,save:e=>f({cloudUrl:e}),onIdentityReset:()=>{I.current+=1,T(e=>e&&{...e,mode:`local`,hasSession:!1,sessionServiceMismatch:!1}),B(),U()}});if(e.status===`url-save-failed`){let t=h(e.error);F(l(`cloudIdentityRebuiltUrlSaveFailed`)),await H(!1,!0),P(t);return}n(e.config),c(e.config.cloudUrl),S(void 0),U(),M(l(`cloudForceSwitchSucceeded`)),await H(!1)}catch(e){P(h(e))}finally{j(``)}}},Qe=async()=>{if(!A){j(`device-start`),M(``),P(``),F(``);try{T(await Te()),U()}catch(e){P(h(e))}finally{j(``)}}},$e=async()=>{if(!A){j(`device-cancel`),M(``),P(``);try{T(await de()),M(l(`cloudDeviceFlowCancelled`))}catch(e){P(h(e))}finally{j(``)}}},et=async()=>{if(!A){j(`remote-authorize-retry`),M(``),P(``);try{let e=await Ee();V(),e.status===`failed`?P(e.error||l(`cloudRemoteAutoApprovalFailed`)):M(l(`cloudRemoteAutoApprovalRetried`))}catch(e){P(h(e))}finally{j(``)}}},tt=async()=>{let e=C?.pendingDeviceFlow?.userCode;if(e)try{await navigator.clipboard.writeText(e),M(l(`cloudDeviceCodeCopied`))}catch{P(l(`copyFailed`))}},nt=async()=>{if(!(!await u({title:l(`cloudLogoutTitle`),description:l(`cloudLogoutDescription`),confirmLabel:l(`cloudLogout`),cancelLabel:l(`cancel`),variant:`destructive`})||A)){j(`logout`),M(``),P(``),F(``);try{await ge(),I.current+=1,B(),T(e=>e&&{...e,mode:`local`,hasSession:!1,sessionServiceMismatch:!1}),U(),M(l(`cloudLoggedOut`)),await H(!1)}catch(e){P(h(e))}finally{j(``)}}},rt=async e=>{let t=v(e);if(!(!t||t===C?.installationId||A)&&await u({description:l(`cloudRevokeDeviceConfirm`,{name:y(e)}),confirmLabel:l(`cloudRevokeDevice`),cancelLabel:l(`cancel`),variant:`destructive`})){j(t),M(``),P(``);try{await Ce(t),O({type:`replace`,state:{...D,installations:D.installations.filter(e=>v(e)!==t)}}),M(l(`cloudDeviceRevoked`))}catch(e){P(h(e))}finally{j(``)}}},W=e?.enabled===!0,it=!!(C?.configured&&C.hasSession),G=C?.sessionServiceMismatch===!0,K=it&&!G,q=!!(e?.cloudUrl&&s.trim()&&e.cloudUrl!==s.trim()),J=x(s),Y=!!(J&&he),at=Ae({loading:k,loadError:N,status:C,details:D}),X=je(C),Z=at===`cloud-unavailable`,ot=G?l(`cloudSessionMismatchLabel`):C?.mode===`account`?l(`cloudFormalAccount`):l(`cloudNotConnected`),st=Be(E?.status),ct=E?.status===`running`?`quickforge-settings-badge-success`:E?.status===`authorizing`||E?.status===`starting`?`quickforge-settings-badge-info`:E?.status===`error`||E?.status===`conflict`?`quickforge-settings-badge-warning`:`quickforge-settings-badge-muted`,Q=Ne(E),lt=W?C?.configured?l(G?`cloudSessionServiceMismatch`:K?Z?`cloudUnavailableDescription`:`cloudConnectedDescription`:`cloudLocalOnlyDescription`):l(`cloudNotConfiguredDescription`):l(`cloudServiceDisabledDescription`),ut=()=>{H()},$=k||D.loading,dt=new Map;for(let e of D.installations){let t=y(e);dt.set(t,(dt.get(t)??0)+1)}let ft=[...dt.entries()].filter(([,e])=>e>1),pt=ft.reduce((e,[,t])=>e+t,0);return(0,g.jsxs)(`div`,{className:`quickforge-settings-stack`,children:[(0,g.jsxs)(`div`,{className:`quickforge-settings-heading`,children:[(0,g.jsx)(`div`,{children:(0,g.jsxs)(`h2`,{className:`quickforge-settings-title`,children:[(0,g.jsx)(i,{className:`size-5`}),l(`cloudAccount`)]})}),(0,g.jsxs)(p,{variant:`outline`,size:`sm`,onClick:()=>void H(),disabled:k||!!A,className:`quickforge-settings-heading-action`,children:[(0,g.jsx)(o,{className:`mr-2 size-4 ${k?`animate-spin`:``}`}),l(`refresh`)]})]}),We?(0,g.jsx)(`div`,{className:`quickforge-settings-message`,children:We}):null,Ge?(0,g.jsx)(`div`,{className:`quickforge-settings-warning`,children:Ge}):null,N?(0,g.jsx)(`div`,{className:`quickforge-settings-error`,children:N}):null,(0,g.jsxs)(`div`,{className:`quickforge-settings-section`,children:[(0,g.jsxs)(`div`,{className:`quickforge-settings-list-header`,children:[(0,g.jsxs)(`div`,{className:`quickforge-settings-row-title`,children:[(0,g.jsx)(oe,{className:`size-4`}),l(`cloudServiceConnection`)]}),(0,g.jsx)(`span`,{className:`quickforge-settings-badge quickforge-settings-badge-info shrink-0`,children:`QuickForge Cloud`})]}),(0,g.jsxs)(`div`,{className:`quickforge-settings-row`,children:[(0,g.jsxs)(`div`,{className:`quickforge-settings-row-main`,children:[(0,g.jsx)(`div`,{className:`quickforge-settings-row-title`,children:l(`cloudServiceEnabled`)}),(0,g.jsx)(`div`,{className:`quickforge-settings-row-description`,children:l(`cloudServiceEnabledDescription`)})]}),(0,g.jsx)(`div`,{className:`quickforge-settings-row-control`,children:(0,g.jsxs)(`label`,{className:`quickforge-settings-switch`,"aria-label":l(`cloudServiceEnabled`),children:[(0,g.jsx)(`input`,{type:`checkbox`,checked:W,disabled:!e||!!A,onChange:e=>{Xe(e.target.checked)}}),(0,g.jsx)(`span`,{"aria-hidden":`true`})]})})]}),(0,g.jsxs)(`div`,{className:`quickforge-settings-row items-start`,children:[(0,g.jsx)(`div`,{className:`quickforge-settings-row-main`,children:(0,g.jsx)(`label`,{className:`quickforge-settings-row-title h-9 whitespace-nowrap`,htmlFor:`quickforge-cloud-url`,children:l(`cloudUrl`)})}),(0,g.jsxs)(`div`,{className:`quickforge-settings-row-control w-full max-w-xl flex-col items-stretch gap-2`,children:[(0,g.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,g.jsx)(fe,{id:`quickforge-cloud-url`,value:s,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Enter`&&s.trim()&&q&&!A&&(e.preventDefault(),Ye())},placeholder:l(`cloudUrlPlaceholder`),inputMode:`url`,autoCapitalize:`none`,autoCorrect:`off`,spellCheck:!1,onBlur:()=>d(!0),"aria-invalid":Y,className:ue(`min-w-0 flex-1`,Y?`border-destructive`:void 0),disabled:!!A}),(0,g.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[(0,g.jsxs)(p,{variant:`outline`,size:`sm`,onClick:()=>void Je(),disabled:!s.trim()||!!J||!!A,children:[A===`test`?(0,g.jsx)(o,{className:`mr-2 size-4 animate-spin`}):(0,g.jsx)(ne,{className:`mr-2 size-4`}),l(`cloudTestConnection`)]}),(0,g.jsxs)(p,{size:`sm`,onClick:()=>void Ye(),disabled:!s.trim()||!q||!!J||!!A,children:[A===`save`?(0,g.jsx)(o,{className:`mr-2 size-4 animate-spin`}):(0,g.jsx)(ce,{className:`mr-2 size-4`}),l(`saveChanges`)]})]})]}),Y?(0,g.jsx)(`div`,{className:`text-xs text-destructive`,children:J}):null,(0,g.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[l(`cloudConfigSource`),`: `,Le(e?.source)]}),Pe(C,q)&&!J?(0,g.jsx)(`div`,{className:`quickforge-settings-cloud-force-switch flex justify-end`,children:(0,g.jsxs)(p,{variant:`destructive`,size:`sm`,onClick:()=>void Ze(),disabled:!!A,title:l(`cloudForceSwitchDescription`),children:[(0,g.jsx)(t,{className:`mr-2 size-4`}),l(`cloudForceSwitch`)]})}):null]})]}),e?.configurationError?(0,g.jsx)(`div`,{className:`quickforge-settings-error m-3`,children:l(`cloudConfigurationError`)}):null,b?(0,g.jsxs)(`div`,{className:`quickforge-settings-row`,children:[(0,g.jsxs)(`div`,{className:`quickforge-settings-row-main`,children:[(0,g.jsx)(`div`,{className:`quickforge-settings-row-title`,children:l(`cloudConnectionTestResult`)}),(0,g.jsx)(`div`,{className:`quickforge-settings-row-description break-all`,children:b.cloudUrl})]}),(0,g.jsxs)(`div`,{className:`quickforge-settings-row-control flex-wrap justify-end gap-1.5`,children:[Re(l(`cloudHealth`),b.health),Re(l(`cloudReady`),b.ready)]})]}):null]}),W?(0,g.jsxs)(`div`,{className:`quickforge-settings-section`,children:[(0,g.jsxs)(`div`,{className:`quickforge-settings-row`,children:[(0,g.jsxs)(`div`,{className:`quickforge-settings-row-main`,children:[(0,g.jsxs)(`div`,{className:`quickforge-settings-row-title`,children:[(0,g.jsx)(a,{className:`size-4`}),l(`cloudRemoteAccess`)]}),(0,g.jsx)(`div`,{className:`quickforge-settings-row-description`,children:l(`cloudRemoteAccessDescription`)})]}),(0,g.jsx)(`div`,{className:`quickforge-settings-row-control`,children:(0,g.jsx)(`span`,{className:`quickforge-settings-badge ${ct}`,children:st})})]}),E?.serverUrl?(0,g.jsxs)(`div`,{className:`quickforge-settings-row`,children:[(0,g.jsx)(`div`,{className:`quickforge-settings-row-main`,children:(0,g.jsx)(`div`,{className:`quickforge-settings-row-title`,children:l(`cloudRemoteServerUrl`)})}),(0,g.jsx)(`div`,{className:`quickforge-settings-row-control break-all text-sm text-muted-foreground`,children:E.serverUrl})]}):null,E?.pid?(0,g.jsxs)(`div`,{className:`quickforge-settings-row`,children:[(0,g.jsx)(`div`,{className:`quickforge-settings-row-main`,children:(0,g.jsx)(`div`,{className:`quickforge-settings-row-title`,children:l(`cloudRemotePid`)})}),(0,g.jsx)(`div`,{className:`quickforge-settings-row-control text-sm font-medium`,children:E.pid})]}):null,E?.status===`authorizing`?(0,g.jsxs)(`div`,{className:`quickforge-settings-row items-start`,children:[(0,g.jsxs)(`div`,{className:`quickforge-settings-row-main`,children:[(0,g.jsx)(`div`,{className:`quickforge-settings-row-title`,children:l(`cloudRemoteAuthorization`)}),(0,g.jsx)(`div`,{className:`quickforge-settings-row-description`,children:Q.pending?l(`cloudRemoteAutoApprovalPending`):Q.failed?l(`cloudRemoteAutoApprovalFailed`):l(`cloudRemoteAutoApprovalNeedsLocalEnable`)}),Q.failed&&Q.failedError?(0,g.jsx)(`div`,{className:`quickforge-settings-warning quickforge-settings-warning-attached mt-1`,children:Q.failedError}):null]}),(0,g.jsx)(`div`,{className:`quickforge-settings-row-control flex-wrap gap-1.5`,children:Q.pending?(0,g.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:l(`cloudRemoteAutoApprovalWaiting`)}):Q.failed?(0,g.jsxs)(p,{variant:`outline`,size:`sm`,onClick:()=>void et(),disabled:!!A,children:[(0,g.jsx)(o,{className:`mr-2 size-3.5`}),l(`cloudRemoteAutoApprovalRetry`)]}):null})]}):null,E?.error?(0,g.jsx)(`div`,{className:`quickforge-settings-warning quickforge-settings-warning-attached`,children:E.error}):null]}):null,(0,g.jsxs)(`div`,{className:`quickforge-settings-section`,children:[(0,g.jsxs)(`div`,{className:`quickforge-settings-row`,children:[(0,g.jsxs)(`div`,{className:`quickforge-settings-row-main`,children:[(0,g.jsxs)(`div`,{className:`quickforge-settings-row-title`,children:[(0,g.jsx)(re,{className:`size-4`}),l(`cloudIdentityStatus`)]}),(0,g.jsx)(`div`,{className:`quickforge-settings-row-description`,children:lt})]}),(0,g.jsx)(`div`,{className:`quickforge-settings-row-control`,children:(0,g.jsx)(`span`,{className:`quickforge-settings-badge ${K&&!Z?`quickforge-settings-badge-success`:G||Z?`quickforge-settings-badge-warning`:`quickforge-settings-badge-muted`}`,children:ot})})]}),Z?(0,g.jsx)(`div`,{className:`quickforge-settings-warning quickforge-settings-warning-attached`,children:l(`cloudUnavailableDescription`)}):null,G?(0,g.jsx)(`div`,{className:`quickforge-settings-warning quickforge-settings-warning-attached`,children:l(`cloudSessionServiceMismatch`)}):null,K?(0,g.jsxs)(g.Fragment,{children:[C?.mode===`account`?(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)(`div`,{className:`quickforge-settings-row`,children:[(0,g.jsx)(`div`,{className:`quickforge-settings-row-main`,children:(0,g.jsx)(`div`,{className:`quickforge-settings-row-title`,children:l(`cloudAccountEmail`)})}),(0,g.jsx)(`div`,{className:`quickforge-settings-row-control text-sm font-medium`,children:C.account?.email||l(`cloudNotAvailable`)})]}),(0,g.jsxs)(`div`,{className:`quickforge-settings-row`,children:[(0,g.jsx)(`div`,{className:`quickforge-settings-row-main`,children:(0,g.jsx)(`div`,{className:`quickforge-settings-row-title`,children:l(`cloudAccountPlan`)})}),(0,g.jsx)(`div`,{className:`quickforge-settings-row-control text-sm font-medium`,children:C.account?.plan||l(`cloudNotAvailable`)})]})]}):null,W?D.errors.usage?(0,g.jsx)(w,{error:D.errors.usage,onRetry:ut,disabled:$||!!A}):(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)(`div`,{className:`quickforge-settings-row`,children:[(0,g.jsx)(`div`,{className:`quickforge-settings-row-main`,children:(0,g.jsx)(`div`,{className:`quickforge-settings-row-title`,children:l(`cloudRemainingQuota`)})}),(0,g.jsx)(`div`,{className:`quickforge-settings-row-control text-sm font-medium`,children:Ie(D.usage?.remaining)})]}),(0,g.jsxs)(`div`,{className:`quickforge-settings-row`,children:[(0,g.jsx)(`div`,{className:`quickforge-settings-row-main`,children:(0,g.jsx)(`div`,{className:`quickforge-settings-row-title`,children:l(`cloudQuotaExpiresAt`)})}),(0,g.jsx)(`div`,{className:`quickforge-settings-row-control text-sm text-muted-foreground`,children:_(D.usage?.resetsAt||D.usage?.expiresAt)})]})]}):null,(0,g.jsxs)(`div`,{className:`quickforge-settings-row`,children:[(0,g.jsxs)(`div`,{className:`quickforge-settings-row-main`,children:[(0,g.jsx)(`div`,{className:`quickforge-settings-row-title`,children:l(`cloudLogout`)}),(0,g.jsx)(`div`,{className:`quickforge-settings-row-description`,children:l(`cloudLogoutRowDescription`)})]}),(0,g.jsx)(`div`,{className:`quickforge-settings-row-control`,children:(0,g.jsxs)(p,{variant:`destructive`,className:`quickforge-settings-cloud-logout`,onClick:()=>void nt(),disabled:!!A,children:[(0,g.jsx)(r,{className:`mr-2 size-4`}),l(`cloudLogout`)]})})]})]}):null]}),!W||!C?.configured?null:X.showDeviceFlow&&R?(0,g.jsxs)(`div`,{className:`quickforge-settings-section`,children:[(0,g.jsxs)(`div`,{className:`quickforge-settings-list-header`,children:[(0,g.jsxs)(`div`,{className:`quickforge-settings-row-main`,children:[(0,g.jsxs)(`div`,{className:`quickforge-settings-row-title`,children:[(0,g.jsx)(ee,{className:`size-4`}),l(`cloudDeviceFlowTitle`)]}),(0,g.jsx)(`div`,{className:`quickforge-settings-row-description`,children:l(`cloudDeviceFlowDescription`)})]}),(0,g.jsx)(`span`,{className:`quickforge-settings-badge quickforge-settings-badge-info`,children:l(`cloudDeviceFlowCountdown`,{seconds:z})})]}),(0,g.jsxs)(`div`,{className:`quickforge-settings-row items-start`,children:[(0,g.jsxs)(`div`,{className:`quickforge-settings-row-main`,children:[(0,g.jsx)(`div`,{className:`quickforge-settings-row-description`,children:l(`cloudDeviceCode`)}),(0,g.jsx)(`div`,{className:`mt-1 font-mono text-2xl font-semibold tracking-[0.18em] text-foreground`,children:R.userCode})]}),(0,g.jsxs)(`div`,{className:`quickforge-settings-row-control flex-wrap gap-2`,children:[(0,g.jsxs)(p,{variant:`outline`,size:`sm`,onClick:()=>void tt(),children:[(0,g.jsx)(te,{className:`mr-2 size-4`}),l(`copy`)]}),(0,g.jsxs)(p,{size:`sm`,onClick:()=>window.open(R.verificationUriComplete||R.verificationUri,`_blank`,`noopener,noreferrer`),children:[(0,g.jsx)(ie,{className:`mr-2 size-4`}),l(`cloudOpenVerificationPage`)]}),(0,g.jsx)(p,{variant:`outline`,size:`sm`,onClick:()=>void $e(),disabled:!!A,children:l(`cancel`)})]})]}),C.deviceFlowResult===`slow_down`?(0,g.jsx)(`div`,{className:`quickforge-settings-warning quickforge-settings-warning-attached`,children:l(`cloudDeviceFlowSlowDown`)}):null]}):X.showDisconnectedActions?(0,g.jsx)(`div`,{className:`quickforge-settings-section`,children:(0,g.jsxs)(`div`,{className:`quickforge-settings-row`,children:[(0,g.jsxs)(`div`,{className:`quickforge-settings-row-main`,children:[(0,g.jsxs)(`div`,{className:`quickforge-settings-row-title`,children:[(0,g.jsx)(ee,{className:`size-4`}),l(`cloudLoginOrRegister`)]}),(0,g.jsx)(`div`,{className:`quickforge-settings-row-description`,children:l(`cloudLoginOrRegisterDescription`)})]}),(0,g.jsx)(`div`,{className:`quickforge-settings-row-control`,children:(0,g.jsxs)(p,{onClick:()=>void Qe(),disabled:k||!!A,children:[(0,g.jsx)(ae,{className:`mr-2 size-4`}),l(`cloudLoginOrRegister`)]})})]})}):X.showDetails?(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)(`div`,{className:`quickforge-settings-section`,children:[(0,g.jsx)(`div`,{className:`quickforge-settings-list-header`,children:(0,g.jsxs)(`div`,{className:`quickforge-settings-row-title`,children:[(0,g.jsx)(se,{className:`size-4`}),l(`cloudModels`)]})}),D.errors.models?(0,g.jsx)(w,{error:D.errors.models,onRetry:ut,disabled:$||!!A}):D.models.length===0?(0,g.jsx)(`div`,{className:`p-6 text-center text-sm text-muted-foreground`,children:l($?`loading`:`cloudNoModels`)}):D.models.map(e=>(0,g.jsx)(`div`,{className:`quickforge-settings-list-item`,children:(0,g.jsxs)(`div`,{className:`quickforge-settings-list-item-main`,children:[(0,g.jsx)(`div`,{className:`text-sm font-medium`,children:e.name||e.id}),(0,g.jsxs)(`div`,{className:`quickforge-settings-row-description`,children:[e.id,` · `,ze(e)]})]})},`${e.provider}:${e.id}`))]}),(0,g.jsxs)(`div`,{className:`quickforge-settings-section`,children:[(0,g.jsx)(`div`,{className:`quickforge-settings-list-header`,children:(0,g.jsxs)(`div`,{className:`quickforge-settings-row-title`,children:[(0,g.jsx)(a,{className:`size-4`}),l(`cloudDevices`)]})}),pt>1?(0,g.jsx)(`div`,{className:`quickforge-settings-warning quickforge-settings-warning-attached`,children:l(`cloudDuplicateDevicesHint`,{count:pt,name:ft[0][0]})}):null,D.errors.installations?(0,g.jsx)(w,{error:D.errors.installations,onRetry:ut,disabled:$||!!A}):D.installations.length===0?(0,g.jsx)(`div`,{className:`p-6 text-center text-sm text-muted-foreground`,children:l($?`loading`:`cloudNoDevices`)}):D.installations.map(e=>{let t=v(e),n=e.current===!0||t===C?.installationId;return(0,g.jsxs)(`div`,{className:`quickforge-settings-list-item`,children:[(0,g.jsxs)(`div`,{className:`quickforge-settings-list-item-main`,children:[(0,g.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,g.jsx)(`div`,{className:`truncate text-sm font-medium`,children:y(e)}),n?(0,g.jsx)(`span`,{className:`quickforge-settings-badge quickforge-settings-badge-info`,children:l(`cloudCurrentDevice`)}):null]}),(0,g.jsx)(`div`,{className:`quickforge-settings-row-description`,children:[e.platform,e.createdAt?`${l(`cloudRegisteredAt`)} ${_(e.createdAt)}`:void 0,e.lastSeenAt?`${l(`cloudLastSeenAt`)} ${_(e.lastSeenAt)}`:void 0,t?`#${t.slice(0,8)}`:void 0].filter(Boolean).join(` · `)||l(`cloudNotAvailable`)})]}),(0,g.jsx)(`div`,{className:`quickforge-settings-list-item-actions`,children:(0,g.jsx)(p,{variant:`outline`,size:`sm`,onClick:()=>void rt(e),disabled:n||!!A,children:l(`cloudRevokeDevice`)})})]},t||y(e))})]})]}):null]})}export{T as CloudAccountSettingsPage};
1
+ import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{C as t,Jt as n,K as r,St as i,Z as a,a as ee,bt as te,c as ne,m as re,mt as ie,q as ae,v as oe,vt as se,w as o,x as ce}from"./icons-DM_qJ7VJ.js";import{n as s}from"./react-vendor-BpWW_Nvp.js";import{$ as le,An as ue,G as de,H as fe,J as pe,K as me,Mn as c,Nn as he,Pn as l,Q as ge,Tt as u,U as _e,W as d,X as ve,Y as ye,Z as be,at as f,et as xe,it as Se,kn as p,nt as Ce,q as we,rt as Te,tt as Ee}from"./index-DQBOm9gt.js";var m=e(n(),1);function h(e,t=`cloudRequestFailed`){return e instanceof d?e.code===`cloud_session_active`?l(`cloudSessionActiveGuidance`):e.code===`cloud_disabled`?l(`cloudDisabledError`):e.code===`cloud_local_only`?l(`cloudLocalOnlyError`):e.code===`cloud_configuration_error`||e.code===`cloud_not_configured`?l(`cloudConfigurationError`):e.code===`cloud_session_service_mismatch`?l(`cloudSessionServiceMismatch`):[`expired_token`,`device_code_expired`,`expired`].includes(e.code)?l(`cloudDeviceFlowExpiredError`):[`access_denied`,`authorization_declined`,`denied`].includes(e.code)?l(`cloudDeviceFlowDeniedError`):[`refresh_token_reused`,`installation_revoked`,`invalid_refresh_token`,`cloud_not_connected`].includes(e.code)?l(`cloudSessionExpired`):c()===`en`&&e.message.trim()?e.message:e.status>0?l(`cloudRequestFailedWithStatus`,{status:e.status}):l(t):l(t)}var De={usage:void 0,installations:[],models:[],errors:{},loading:!1};function Oe(e,t){return t.type===`replace`?t.state:{...De,loading:t.type===`begin`}}async function ke(e,t){let[n,r,i]=await Promise.allSettled([e.usage(),e.installations(),e.models()]);return{usage:n.status===`fulfilled`?n.value:void 0,installations:r.status===`fulfilled`?r.value:[],models:i.status===`fulfilled`?i.value:[],errors:{...n.status===`rejected`?{usage:t(`usage`,n.reason)}:{},...r.status===`rejected`?{installations:t(`installations`,r.reason)}:{},...i.status===`rejected`?{models:t(`models`,i.reason)}:{}},loading:!1}}function Ae({loading:e,loadError:t,status:n,details:r}){if(e&&!n)return`loading`;if(t)return`load-error`;if(!n?.configured)return`unconfigured`;if(n.sessionServiceMismatch)return`session-mismatch`;if(n.pendingDeviceFlow)return n.hasSession?`connected`:`no-session`;if(!n.hasSession)return`no-session`;let i=Object.values(r.errors);return n.cloudAvailable===!1||i.length===3&&i.every(e=>e?.unavailable)?`cloud-unavailable`:i.length>0?`partial-details`:`connected`}function je(e){let t=e?.configured===!0,n=t&&e.hasSession===!0,r=n&&e.sessionServiceMismatch!==!0;return{showDeviceFlow:t&&!!e.pendingDeviceFlow,showDisconnectedActions:t&&!e.pendingDeviceFlow&&!n,showDetails:r}}function Me(e){return e===`starting`||e===`authorizing`}function Ne(e){if(e?.status!==`authorizing`)return{pending:!1,failed:!1,needsLocalEnable:!1};let t=e.autoApproval;return t?.status===`armed`||t?.status===`pending`||t?.status===`consumed`?{pending:!0,failed:!1,needsLocalEnable:!1}:t?.status===`failed`?{pending:!1,failed:!0,failedError:t.error||void 0,needsLocalEnable:!1}:{pending:!1,failed:!1,needsLocalEnable:!0}}function Pe(e,t){return!!(e?.hasSession&&(t||e.sessionServiceMismatch))}async function Fe(e,t){await t.reset(),t.onIdentityReset?.();try{return{status:`success`,config:await t.save(e)}}catch(e){return{status:`url-save-failed`,error:e}}}var g=s();function _(e){if(!e)return l(`cloudNotAvailable`);let t=new Date(e);return Number.isNaN(t.getTime())?l(`cloudNotAvailable`):t.toLocaleString(he())}function v(e){let t=e.id||e.installationId;return typeof t==`string`?t:``}function y(e){let t=e.name||e.installationName;return typeof t==`string`&&t?t:l(`cloudUnnamedDevice`)}function Ie(e){return typeof e==`number`&&Number.isFinite(e)?e.toLocaleString(he()):l(`cloudNotAvailable`)}function Le(e){return l(e===`saved`?`cloudConfigSourceSaved`:e===`env`?`cloudConfigSourceEnv`:`cloudConfigSourceDefault`)}function b(e){let t=String(e||``).toLowerCase();return t===`localhost`||t.endsWith(`.localhost`)||t.startsWith(`127.`)?!0:t===`::1`}function x(e){let t=e.trim();if(!t)return``;let n;try{n=new URL(t)}catch{return l(`cloudUrlInvalid`)}return n.protocol!==`https:`&&n.protocol!==`http:`?l(`cloudUrlInvalidProtocol`):b(n.hostname)&&n.port===`8081`?l(`cloudUrlAdminPort`):``}function S(e){if(!e||typeof e!=`object`)return l(`cloudConnectionUnknown`);let t=e;return t.ok===!0||t.status===`ok`||t.ready===!0?l(`cloudConnectionOk`):l(`cloudConnectionError`)}function C(e){if(!e||typeof e!=`object`)return!1;let t=e;return t.ok===!0||t.status===`ok`||t.ready===!0}function Re(e,t){let n=S(t);return(0,g.jsxs)(`span`,{className:ue(`quickforge-settings-badge`,n===l(`cloudConnectionUnknown`)?`quickforge-settings-badge-muted`:C(t)?`quickforge-settings-badge-success`:`quickforge-settings-badge-danger`),children:[e,`: `,n]})}function ze(e){let t=e.quickforgeCapabilities;return[t?.tools?l(`cloudCapabilityTools`):void 0,t?.vision?l(`cloudCapabilityVision`):void 0,t?.reasoning?l(`cloudCapabilityReasoning`):void 0].filter(Boolean).join(` · `)||l(`cloudCapabilityText`)}function Be(e){return l(e?e===`disabled`?`cloudRemoteStatusDisabled`:e===`unavailable`?`cloudRemoteStatusUnavailable`:e===`stopped`?`cloudRemoteStatusStopped`:e===`starting`?`cloudRemoteStatusStarting`:e===`authorizing`?`cloudRemoteStatusAuthorizing`:e===`running`?`cloudRemoteStatusRunning`:e===`conflict`?`cloudRemoteStatusConflict`:`cloudRemoteStatusError`:`cloudRemoteStatusLoading`)}function Ve(e,t){let n=e===`usage`?`cloudUsageLoadFailed`:e===`installations`?`cloudDevicesLoadFailed`:`cloudModelsLoadFailed`,r=h(t);return{message:r===l(`cloudRequestFailed`)?l(n):r,unavailable:!(`code`in Object(t))||[`cloud_request_failed`,`cloud_unavailable`].includes(String(t?.code||``))}}function w({error:e,onRetry:t,disabled:n}){return(0,g.jsxs)(`div`,{className:`p-4 text-sm`,children:[(0,g.jsx)(`div`,{className:`quickforge-settings-error`,children:e.message}),(0,g.jsxs)(p,{type:`button`,variant:`outline`,size:`sm`,className:`mt-3`,onClick:t,disabled:n,children:[(0,g.jsx)(o,{className:`mr-2 size-4`}),l(`retry`)]})]})}function T(){let[e,n]=(0,m.useState)(),[s,c]=(0,m.useState)(``),[he,d]=(0,m.useState)(!1),[b,S]=(0,m.useState)(),[C,T]=(0,m.useState)(),[E,He]=(0,m.useState)(),[D,O]=(0,m.useReducer)(Oe,De),[k,Ue]=(0,m.useState)(!0),[A,j]=(0,m.useState)(``),[We,M]=(0,m.useState)(``),[N,P]=(0,m.useState)(``),[Ge,F]=(0,m.useState)(``),[Ke,qe]=(0,m.useState)(0),I=(0,m.useRef)(0),L=(0,m.useRef)(0),R=C?.pendingDeviceFlow,z=R?Math.max(0,Math.ceil((R.expiresAt-Ke)/1e3)):0,B=(0,m.useCallback)(()=>O({type:`clear`}),[]),V=(0,m.useCallback)(async()=>{let e=++L.current;try{let t=await ye();e===L.current&&He(t)}catch{}},[]),H=(0,m.useCallback)(async(e=!0,t=!1,r=!0)=>{let i=++I.current;e&&Ue(!0),P(``),O({type:`begin`}),r&&V();try{let[e,r]=await Promise.all([me(),ve()]);if(i!==I.current)return;if(n(e),t||c(e.cloudUrl),T(r),!e.enabled||!r.configured||!r.hasSession||r.sessionServiceMismatch){B();return}let a=await ke({usage:be,installations:we,models:pe},Ve);if(i!==I.current)return;O({type:`replace`,state:a})}catch(e){if(i!==I.current)return;n(void 0),T(void 0),B(),P(h(e,`cloudLoadFailed`))}finally{i===I.current&&Ue(!1)}},[B,V]);(0,m.useEffect)(()=>{let e=window.setTimeout(()=>{H()},0);return()=>{window.clearTimeout(e),I.current+=1,L.current+=1}},[H]),(0,m.useEffect)(()=>{if(!e?.enabled||!Me(E?.status))return;let t=window.setInterval(()=>{V()},1750);return()=>window.clearInterval(t)},[e?.enabled,V,E?.status]),(0,m.useEffect)(()=>{let e=()=>{document.visibilityState===`visible`&&V()};return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[V]),(0,m.useEffect)(()=>{if(!e?.enabled||!C?.pendingDeviceFlow)return;let t=()=>qe(Date.now()),n=window.setTimeout(t,0),r=window.setInterval(t,1e3);return()=>{window.clearTimeout(n),window.clearInterval(r)}},[e?.enabled,C?.pendingDeviceFlow]),(0,m.useEffect)(()=>{let t=C?.pendingDeviceFlow;if(!e?.enabled||!t||z>0)return;let n=window.setTimeout(()=>{H(!1)},0);return()=>window.clearTimeout(n)},[e?.enabled,z,H,C?.pendingDeviceFlow]),(0,m.useEffect)(()=>{let t=C?.pendingDeviceFlow;if(!e?.enabled||!t||A===`device-start`||A===`device-cancel`)return;let n=Math.max(1,Number(t.interval)||5)*1e3,r=window.setTimeout(async()=>{try{let e=await le();T(e),e.deviceFlowResult===`success`?(window.dispatchEvent(new Event(_e)),P(``),M(l(`cloudDeviceFlowSucceeded`)),await Promise.all([H(!1,!1,!1),V()])):e.deviceFlowResult===`denied`?P(l(`cloudDeviceFlowDenied`)):e.deviceFlowResult===`expired`?P(l(`cloudDeviceFlowExpired`)):e.deviceFlowResult===`network`&&P(l(`cloudDeviceFlowNetwork`))}catch(e){P(h(e))}},n);return()=>window.clearTimeout(r)},[A,e?.enabled,H,V,C?.pendingDeviceFlow]);let U=()=>window.dispatchEvent(new Event(_e)),Je=async()=>{if(!A){if(x(s)){d(!0);return}j(`test`),M(``),P(``),S(void 0);try{let e=await Se(s);c(e.cloudUrl),S(e),M(l(`cloudConnectionTestSucceeded`))}catch(e){P(h(e,`cloudConnectionFailed`))}finally{j(``)}}},Ye=async()=>{if(!A){if(x(s)){d(!0);return}j(`save`),M(``),P(``);try{let e=await f({cloudUrl:s});n(e),c(e.cloudUrl),S(void 0),F(``),U(),M(l(`cloudConnectionSaved`)),await H(!1)}catch(e){P(h(e))}finally{j(``)}}},Xe=async t=>{if(!(A||!e||e.enabled===t)){j(`cloud-toggle`),M(``),P(``),F(``);try{let e=await f({enabled:t});n(e),c(e.cloudUrl),S(void 0),e.enabled||B(),U(),M(l(e.enabled?`cloudServiceEnabledSaved`:`cloudServiceDisabledSaved`)),await H(!1)}catch(e){P(h(e))}finally{j(``)}}},Ze=async()=>{let t=s.trim()||e?.cloudUrl||``;if(x(t)){d(!0);return}if(!(!await u({title:l(`cloudForceSwitchTitle`),description:l(`cloudForceSwitchDescription`),confirmLabel:l(`cloudForceSwitchConfirm`),cancelLabel:l(`cancel`),variant:`destructive`})||A||!t)){j(`force-switch`),M(``),P(``),F(``);try{let e=await Fe(t,{reset:xe,save:e=>f({cloudUrl:e}),onIdentityReset:()=>{I.current+=1,T(e=>e&&{...e,mode:`local`,hasSession:!1,sessionServiceMismatch:!1}),B(),U()}});if(e.status===`url-save-failed`){let t=h(e.error);F(l(`cloudIdentityRebuiltUrlSaveFailed`)),await H(!1,!0),P(t);return}n(e.config),c(e.config.cloudUrl),S(void 0),U(),M(l(`cloudForceSwitchSucceeded`)),await H(!1)}catch(e){P(h(e))}finally{j(``)}}},Qe=async()=>{if(!A){j(`device-start`),M(``),P(``),F(``);try{T(await Te()),U()}catch(e){P(h(e))}finally{j(``)}}},$e=async()=>{if(!A){j(`device-cancel`),M(``),P(``);try{T(await de()),M(l(`cloudDeviceFlowCancelled`))}catch(e){P(h(e))}finally{j(``)}}},et=async()=>{if(!A){j(`remote-authorize-retry`),M(``),P(``);try{let e=await Ee();V(),e.status===`failed`?P(e.error||l(`cloudRemoteAutoApprovalFailed`)):M(l(`cloudRemoteAutoApprovalRetried`))}catch(e){P(h(e))}finally{j(``)}}},tt=async()=>{let e=C?.pendingDeviceFlow?.userCode;if(e)try{await navigator.clipboard.writeText(e),M(l(`cloudDeviceCodeCopied`))}catch{P(l(`copyFailed`))}},nt=async()=>{if(!(!await u({title:l(`cloudLogoutTitle`),description:l(`cloudLogoutDescription`),confirmLabel:l(`cloudLogout`),cancelLabel:l(`cancel`),variant:`destructive`})||A)){j(`logout`),M(``),P(``),F(``);try{await ge(),I.current+=1,B(),T(e=>e&&{...e,mode:`local`,hasSession:!1,sessionServiceMismatch:!1}),U(),M(l(`cloudLoggedOut`)),await H(!1)}catch(e){P(h(e))}finally{j(``)}}},rt=async e=>{let t=v(e);if(!(!t||t===C?.installationId||A)&&await u({description:l(`cloudRevokeDeviceConfirm`,{name:y(e)}),confirmLabel:l(`cloudRevokeDevice`),cancelLabel:l(`cancel`),variant:`destructive`})){j(t),M(``),P(``);try{await Ce(t),O({type:`replace`,state:{...D,installations:D.installations.filter(e=>v(e)!==t)}}),M(l(`cloudDeviceRevoked`))}catch(e){P(h(e))}finally{j(``)}}},W=e?.enabled===!0,it=!!(C?.configured&&C.hasSession),G=C?.sessionServiceMismatch===!0,K=it&&!G,q=!!(e?.cloudUrl&&s.trim()&&e.cloudUrl!==s.trim()),J=x(s),Y=!!(J&&he),at=Ae({loading:k,loadError:N,status:C,details:D}),X=je(C),Z=at===`cloud-unavailable`,ot=G?l(`cloudSessionMismatchLabel`):C?.mode===`account`?l(`cloudFormalAccount`):l(`cloudNotConnected`),st=Be(E?.status),ct=E?.status===`running`?`quickforge-settings-badge-success`:E?.status===`authorizing`||E?.status===`starting`?`quickforge-settings-badge-info`:E?.status===`error`||E?.status===`conflict`?`quickforge-settings-badge-warning`:`quickforge-settings-badge-muted`,Q=Ne(E),lt=W?C?.configured?l(G?`cloudSessionServiceMismatch`:K?Z?`cloudUnavailableDescription`:`cloudConnectedDescription`:`cloudLocalOnlyDescription`):l(`cloudNotConfiguredDescription`):l(`cloudServiceDisabledDescription`),ut=()=>{H()},$=k||D.loading,dt=new Map;for(let e of D.installations){let t=y(e);dt.set(t,(dt.get(t)??0)+1)}let ft=[...dt.entries()].filter(([,e])=>e>1),pt=ft.reduce((e,[,t])=>e+t,0);return(0,g.jsxs)(`div`,{className:`quickforge-settings-stack`,children:[(0,g.jsxs)(`div`,{className:`quickforge-settings-heading`,children:[(0,g.jsx)(`div`,{children:(0,g.jsxs)(`h2`,{className:`quickforge-settings-title`,children:[(0,g.jsx)(i,{className:`size-5`}),l(`cloudAccount`)]})}),(0,g.jsxs)(p,{variant:`outline`,size:`sm`,onClick:()=>void H(),disabled:k||!!A,className:`quickforge-settings-heading-action`,children:[(0,g.jsx)(o,{className:`mr-2 size-4 ${k?`animate-spin`:``}`}),l(`refresh`)]})]}),We?(0,g.jsx)(`div`,{className:`quickforge-settings-message`,children:We}):null,Ge?(0,g.jsx)(`div`,{className:`quickforge-settings-warning`,children:Ge}):null,N?(0,g.jsx)(`div`,{className:`quickforge-settings-error`,children:N}):null,(0,g.jsxs)(`div`,{className:`quickforge-settings-section`,children:[(0,g.jsxs)(`div`,{className:`quickforge-settings-list-header`,children:[(0,g.jsxs)(`div`,{className:`quickforge-settings-row-title`,children:[(0,g.jsx)(oe,{className:`size-4`}),l(`cloudServiceConnection`)]}),(0,g.jsx)(`span`,{className:`quickforge-settings-badge quickforge-settings-badge-info shrink-0`,children:`QuickForge Cloud`})]}),(0,g.jsxs)(`div`,{className:`quickforge-settings-row`,children:[(0,g.jsxs)(`div`,{className:`quickforge-settings-row-main`,children:[(0,g.jsx)(`div`,{className:`quickforge-settings-row-title`,children:l(`cloudServiceEnabled`)}),(0,g.jsx)(`div`,{className:`quickforge-settings-row-description`,children:l(`cloudServiceEnabledDescription`)})]}),(0,g.jsx)(`div`,{className:`quickforge-settings-row-control`,children:(0,g.jsxs)(`label`,{className:`quickforge-settings-switch`,"aria-label":l(`cloudServiceEnabled`),children:[(0,g.jsx)(`input`,{type:`checkbox`,checked:W,disabled:!e||!!A,onChange:e=>{Xe(e.target.checked)}}),(0,g.jsx)(`span`,{"aria-hidden":`true`})]})})]}),(0,g.jsxs)(`div`,{className:`quickforge-settings-row items-start`,children:[(0,g.jsx)(`div`,{className:`quickforge-settings-row-main`,children:(0,g.jsx)(`label`,{className:`quickforge-settings-row-title h-9 whitespace-nowrap`,htmlFor:`quickforge-cloud-url`,children:l(`cloudUrl`)})}),(0,g.jsxs)(`div`,{className:`quickforge-settings-row-control w-full max-w-xl flex-col items-stretch gap-2`,children:[(0,g.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,g.jsx)(fe,{id:`quickforge-cloud-url`,value:s,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Enter`&&s.trim()&&q&&!A&&(e.preventDefault(),Ye())},placeholder:l(`cloudUrlPlaceholder`),inputMode:`url`,autoCapitalize:`none`,autoCorrect:`off`,spellCheck:!1,onBlur:()=>d(!0),"aria-invalid":Y,className:ue(`min-w-0 flex-1`,Y?`border-destructive`:void 0),disabled:!!A}),(0,g.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[(0,g.jsxs)(p,{variant:`outline`,size:`sm`,onClick:()=>void Je(),disabled:!s.trim()||!!J||!!A,children:[A===`test`?(0,g.jsx)(o,{className:`mr-2 size-4 animate-spin`}):(0,g.jsx)(ne,{className:`mr-2 size-4`}),l(`cloudTestConnection`)]}),(0,g.jsxs)(p,{size:`sm`,onClick:()=>void Ye(),disabled:!s.trim()||!q||!!J||!!A,children:[A===`save`?(0,g.jsx)(o,{className:`mr-2 size-4 animate-spin`}):(0,g.jsx)(ce,{className:`mr-2 size-4`}),l(`saveChanges`)]})]})]}),Y?(0,g.jsx)(`div`,{className:`text-xs text-destructive`,children:J}):null,(0,g.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[l(`cloudConfigSource`),`: `,Le(e?.source)]}),Pe(C,q)&&!J?(0,g.jsx)(`div`,{className:`quickforge-settings-cloud-force-switch flex justify-end`,children:(0,g.jsxs)(p,{variant:`destructive`,size:`sm`,onClick:()=>void Ze(),disabled:!!A,title:l(`cloudForceSwitchDescription`),children:[(0,g.jsx)(t,{className:`mr-2 size-4`}),l(`cloudForceSwitch`)]})}):null]})]}),e?.configurationError?(0,g.jsx)(`div`,{className:`quickforge-settings-error m-3`,children:l(`cloudConfigurationError`)}):null,b?(0,g.jsxs)(`div`,{className:`quickforge-settings-row`,children:[(0,g.jsxs)(`div`,{className:`quickforge-settings-row-main`,children:[(0,g.jsx)(`div`,{className:`quickforge-settings-row-title`,children:l(`cloudConnectionTestResult`)}),(0,g.jsx)(`div`,{className:`quickforge-settings-row-description break-all`,children:b.cloudUrl})]}),(0,g.jsxs)(`div`,{className:`quickforge-settings-row-control flex-wrap justify-end gap-1.5`,children:[Re(l(`cloudHealth`),b.health),Re(l(`cloudReady`),b.ready)]})]}):null]}),W?(0,g.jsxs)(`div`,{className:`quickforge-settings-section`,children:[(0,g.jsxs)(`div`,{className:`quickforge-settings-row`,children:[(0,g.jsxs)(`div`,{className:`quickforge-settings-row-main`,children:[(0,g.jsxs)(`div`,{className:`quickforge-settings-row-title`,children:[(0,g.jsx)(a,{className:`size-4`}),l(`cloudRemoteAccess`)]}),(0,g.jsx)(`div`,{className:`quickforge-settings-row-description`,children:l(`cloudRemoteAccessDescription`)})]}),(0,g.jsx)(`div`,{className:`quickforge-settings-row-control`,children:(0,g.jsx)(`span`,{className:`quickforge-settings-badge ${ct}`,children:st})})]}),E?.serverUrl?(0,g.jsxs)(`div`,{className:`quickforge-settings-row`,children:[(0,g.jsx)(`div`,{className:`quickforge-settings-row-main`,children:(0,g.jsx)(`div`,{className:`quickforge-settings-row-title`,children:l(`cloudRemoteServerUrl`)})}),(0,g.jsx)(`div`,{className:`quickforge-settings-row-control break-all text-sm text-muted-foreground`,children:E.serverUrl})]}):null,E?.pid?(0,g.jsxs)(`div`,{className:`quickforge-settings-row`,children:[(0,g.jsx)(`div`,{className:`quickforge-settings-row-main`,children:(0,g.jsx)(`div`,{className:`quickforge-settings-row-title`,children:l(`cloudRemotePid`)})}),(0,g.jsx)(`div`,{className:`quickforge-settings-row-control text-sm font-medium`,children:E.pid})]}):null,E?.status===`authorizing`?(0,g.jsxs)(`div`,{className:`quickforge-settings-row items-start`,children:[(0,g.jsxs)(`div`,{className:`quickforge-settings-row-main`,children:[(0,g.jsx)(`div`,{className:`quickforge-settings-row-title`,children:l(`cloudRemoteAuthorization`)}),(0,g.jsx)(`div`,{className:`quickforge-settings-row-description`,children:Q.pending?l(`cloudRemoteAutoApprovalPending`):Q.failed?l(`cloudRemoteAutoApprovalFailed`):l(`cloudRemoteAutoApprovalNeedsLocalEnable`)}),Q.failed&&Q.failedError?(0,g.jsx)(`div`,{className:`quickforge-settings-warning quickforge-settings-warning-attached mt-1`,children:Q.failedError}):null]}),(0,g.jsx)(`div`,{className:`quickforge-settings-row-control flex-wrap gap-1.5`,children:Q.pending?(0,g.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:l(`cloudRemoteAutoApprovalWaiting`)}):Q.failed?(0,g.jsxs)(p,{variant:`outline`,size:`sm`,onClick:()=>void et(),disabled:!!A,children:[(0,g.jsx)(o,{className:`mr-2 size-3.5`}),l(`cloudRemoteAutoApprovalRetry`)]}):null})]}):null,E?.error?(0,g.jsx)(`div`,{className:`quickforge-settings-warning quickforge-settings-warning-attached`,children:E.error}):null]}):null,(0,g.jsxs)(`div`,{className:`quickforge-settings-section`,children:[(0,g.jsxs)(`div`,{className:`quickforge-settings-row`,children:[(0,g.jsxs)(`div`,{className:`quickforge-settings-row-main`,children:[(0,g.jsxs)(`div`,{className:`quickforge-settings-row-title`,children:[(0,g.jsx)(re,{className:`size-4`}),l(`cloudIdentityStatus`)]}),(0,g.jsx)(`div`,{className:`quickforge-settings-row-description`,children:lt})]}),(0,g.jsx)(`div`,{className:`quickforge-settings-row-control`,children:(0,g.jsx)(`span`,{className:`quickforge-settings-badge ${K&&!Z?`quickforge-settings-badge-success`:G||Z?`quickforge-settings-badge-warning`:`quickforge-settings-badge-muted`}`,children:ot})})]}),Z?(0,g.jsx)(`div`,{className:`quickforge-settings-warning quickforge-settings-warning-attached`,children:l(`cloudUnavailableDescription`)}):null,G?(0,g.jsx)(`div`,{className:`quickforge-settings-warning quickforge-settings-warning-attached`,children:l(`cloudSessionServiceMismatch`)}):null,K?(0,g.jsxs)(g.Fragment,{children:[C?.mode===`account`?(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)(`div`,{className:`quickforge-settings-row`,children:[(0,g.jsx)(`div`,{className:`quickforge-settings-row-main`,children:(0,g.jsx)(`div`,{className:`quickforge-settings-row-title`,children:l(`cloudAccountEmail`)})}),(0,g.jsx)(`div`,{className:`quickforge-settings-row-control text-sm font-medium`,children:C.account?.email||l(`cloudNotAvailable`)})]}),(0,g.jsxs)(`div`,{className:`quickforge-settings-row`,children:[(0,g.jsx)(`div`,{className:`quickforge-settings-row-main`,children:(0,g.jsx)(`div`,{className:`quickforge-settings-row-title`,children:l(`cloudAccountPlan`)})}),(0,g.jsx)(`div`,{className:`quickforge-settings-row-control text-sm font-medium`,children:C.account?.plan||l(`cloudNotAvailable`)})]})]}):null,W?D.errors.usage?(0,g.jsx)(w,{error:D.errors.usage,onRetry:ut,disabled:$||!!A}):(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)(`div`,{className:`quickforge-settings-row`,children:[(0,g.jsx)(`div`,{className:`quickforge-settings-row-main`,children:(0,g.jsx)(`div`,{className:`quickforge-settings-row-title`,children:l(`cloudRemainingQuota`)})}),(0,g.jsx)(`div`,{className:`quickforge-settings-row-control text-sm font-medium`,children:Ie(D.usage?.remaining)})]}),(0,g.jsxs)(`div`,{className:`quickforge-settings-row`,children:[(0,g.jsx)(`div`,{className:`quickforge-settings-row-main`,children:(0,g.jsx)(`div`,{className:`quickforge-settings-row-title`,children:l(`cloudQuotaExpiresAt`)})}),(0,g.jsx)(`div`,{className:`quickforge-settings-row-control text-sm text-muted-foreground`,children:_(D.usage?.resetsAt||D.usage?.expiresAt)})]})]}):null,(0,g.jsxs)(`div`,{className:`quickforge-settings-row`,children:[(0,g.jsxs)(`div`,{className:`quickforge-settings-row-main`,children:[(0,g.jsx)(`div`,{className:`quickforge-settings-row-title`,children:l(`cloudLogout`)}),(0,g.jsx)(`div`,{className:`quickforge-settings-row-description`,children:l(`cloudLogoutRowDescription`)})]}),(0,g.jsx)(`div`,{className:`quickforge-settings-row-control`,children:(0,g.jsxs)(p,{variant:`destructive`,className:`quickforge-settings-cloud-logout`,onClick:()=>void nt(),disabled:!!A,children:[(0,g.jsx)(r,{className:`mr-2 size-4`}),l(`cloudLogout`)]})})]})]}):null]}),!W||!C?.configured?null:X.showDeviceFlow&&R?(0,g.jsxs)(`div`,{className:`quickforge-settings-section`,children:[(0,g.jsxs)(`div`,{className:`quickforge-settings-list-header`,children:[(0,g.jsxs)(`div`,{className:`quickforge-settings-row-main`,children:[(0,g.jsxs)(`div`,{className:`quickforge-settings-row-title`,children:[(0,g.jsx)(ee,{className:`size-4`}),l(`cloudDeviceFlowTitle`)]}),(0,g.jsx)(`div`,{className:`quickforge-settings-row-description`,children:l(`cloudDeviceFlowDescription`)})]}),(0,g.jsx)(`span`,{className:`quickforge-settings-badge quickforge-settings-badge-info`,children:l(`cloudDeviceFlowCountdown`,{seconds:z})})]}),(0,g.jsxs)(`div`,{className:`quickforge-settings-row items-start`,children:[(0,g.jsxs)(`div`,{className:`quickforge-settings-row-main`,children:[(0,g.jsx)(`div`,{className:`quickforge-settings-row-description`,children:l(`cloudDeviceCode`)}),(0,g.jsx)(`div`,{className:`mt-1 font-mono text-2xl font-semibold tracking-[0.18em] text-foreground`,children:R.userCode})]}),(0,g.jsxs)(`div`,{className:`quickforge-settings-row-control flex-wrap gap-2`,children:[(0,g.jsxs)(p,{variant:`outline`,size:`sm`,onClick:()=>void tt(),children:[(0,g.jsx)(te,{className:`mr-2 size-4`}),l(`copy`)]}),(0,g.jsxs)(p,{size:`sm`,onClick:()=>window.open(R.verificationUriComplete||R.verificationUri,`_blank`,`noopener,noreferrer`),children:[(0,g.jsx)(ie,{className:`mr-2 size-4`}),l(`cloudOpenVerificationPage`)]}),(0,g.jsx)(p,{variant:`outline`,size:`sm`,onClick:()=>void $e(),disabled:!!A,children:l(`cancel`)})]})]}),C.deviceFlowResult===`slow_down`?(0,g.jsx)(`div`,{className:`quickforge-settings-warning quickforge-settings-warning-attached`,children:l(`cloudDeviceFlowSlowDown`)}):null]}):X.showDisconnectedActions?(0,g.jsx)(`div`,{className:`quickforge-settings-section`,children:(0,g.jsxs)(`div`,{className:`quickforge-settings-row`,children:[(0,g.jsxs)(`div`,{className:`quickforge-settings-row-main`,children:[(0,g.jsxs)(`div`,{className:`quickforge-settings-row-title`,children:[(0,g.jsx)(ee,{className:`size-4`}),l(`cloudLoginOrRegister`)]}),(0,g.jsx)(`div`,{className:`quickforge-settings-row-description`,children:l(`cloudLoginOrRegisterDescription`)})]}),(0,g.jsx)(`div`,{className:`quickforge-settings-row-control`,children:(0,g.jsxs)(p,{onClick:()=>void Qe(),disabled:k||!!A,children:[(0,g.jsx)(ae,{className:`mr-2 size-4`}),l(`cloudLoginOrRegister`)]})})]})}):X.showDetails?(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)(`div`,{className:`quickforge-settings-section`,children:[(0,g.jsx)(`div`,{className:`quickforge-settings-list-header`,children:(0,g.jsxs)(`div`,{className:`quickforge-settings-row-title`,children:[(0,g.jsx)(se,{className:`size-4`}),l(`cloudModels`)]})}),D.errors.models?(0,g.jsx)(w,{error:D.errors.models,onRetry:ut,disabled:$||!!A}):D.models.length===0?(0,g.jsx)(`div`,{className:`p-6 text-center text-sm text-muted-foreground`,children:l($?`loading`:`cloudNoModels`)}):D.models.map(e=>(0,g.jsx)(`div`,{className:`quickforge-settings-list-item`,children:(0,g.jsxs)(`div`,{className:`quickforge-settings-list-item-main`,children:[(0,g.jsx)(`div`,{className:`text-sm font-medium`,children:e.name||e.id}),(0,g.jsxs)(`div`,{className:`quickforge-settings-row-description`,children:[e.id,` · `,ze(e)]})]})},`${e.provider}:${e.id}`))]}),(0,g.jsxs)(`div`,{className:`quickforge-settings-section`,children:[(0,g.jsx)(`div`,{className:`quickforge-settings-list-header`,children:(0,g.jsxs)(`div`,{className:`quickforge-settings-row-title`,children:[(0,g.jsx)(a,{className:`size-4`}),l(`cloudDevices`)]})}),pt>1?(0,g.jsx)(`div`,{className:`quickforge-settings-warning quickforge-settings-warning-attached`,children:l(`cloudDuplicateDevicesHint`,{count:pt,name:ft[0][0]})}):null,D.errors.installations?(0,g.jsx)(w,{error:D.errors.installations,onRetry:ut,disabled:$||!!A}):D.installations.length===0?(0,g.jsx)(`div`,{className:`p-6 text-center text-sm text-muted-foreground`,children:l($?`loading`:`cloudNoDevices`)}):D.installations.map(e=>{let t=v(e),n=e.current===!0||t===C?.installationId;return(0,g.jsxs)(`div`,{className:`quickforge-settings-list-item`,children:[(0,g.jsxs)(`div`,{className:`quickforge-settings-list-item-main`,children:[(0,g.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,g.jsx)(`div`,{className:`truncate text-sm font-medium`,children:y(e)}),n?(0,g.jsx)(`span`,{className:`quickforge-settings-badge quickforge-settings-badge-info`,children:l(`cloudCurrentDevice`)}):null]}),(0,g.jsx)(`div`,{className:`quickforge-settings-row-description`,children:[e.platform,e.createdAt?`${l(`cloudRegisteredAt`)} ${_(e.createdAt)}`:void 0,e.lastSeenAt?`${l(`cloudLastSeenAt`)} ${_(e.lastSeenAt)}`:void 0,t?`#${t.slice(0,8)}`:void 0].filter(Boolean).join(` · `)||l(`cloudNotAvailable`)})]}),(0,g.jsx)(`div`,{className:`quickforge-settings-list-item-actions`,children:(0,g.jsx)(p,{variant:`outline`,size:`sm`,onClick:()=>void rt(e),disabled:n||!!A,children:l(`cloudRevokeDevice`)})})]},t||y(e))})]})]}):null]})}export{T as CloudAccountSettingsPage};
@@ -1 +1 @@
1
- import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{J as t,Jt as n,T as r,o as i,w as a}from"./icons-DM_qJ7VJ.js";import{n as o}from"./react-vendor-BpWW_Nvp.js";import{Pn as s}from"./index-DFASc15l.js";import{n as c,r as l,t as u}from"./plugin-api-BrdQeM4B.js";var d=e(n(),1),f=o();function p(e){switch(e){case`documents`:return{label:s(`pluginDocumentsName`),description:s(`pluginDocumentsDescription`)};case`spreadsheets`:return{label:s(`pluginSpreadsheetsName`),description:s(`pluginSpreadsheetsDescription`)};case`presentations`:return{label:s(`pluginPresentationsName`),description:s(`pluginPresentationsDescription`)};default:return null}}function m(e){return p(e.name)?.label||(e.displayName||e.name).replace(/^OpenAI\s+/i,``)}function h(e){return p(e.name)?.description||e.description||s(`noDescription`)}function g({onChanged:e}){let[n,o]=(0,d.useState)(null),[p,g]=(0,d.useState)(!0),[_,v]=(0,d.useState)(null),[y,b]=(0,d.useState)(null),x=(0,d.useCallback)(async(t=`load`)=>{b(null),g(!0);try{o(t===`reload`?await c():await u()),t===`reload`&&e?.()}catch(e){b(e instanceof Error?e.message:s(`pluginsLoadFailed`))}finally{g(!1)}},[e]);(0,d.useEffect)(()=>{let e=!1;return u().then(t=>{e||o(t)}).catch(t=>{e||b(t instanceof Error?t.message:s(`pluginsLoadFailed`))}).finally(()=>{e||g(!1)}),()=>{e=!0}},[]);let S=(0,d.useMemo)(()=>{let e=n?.plugins||[];return{total:e.length,enabled:e.filter(e=>e.enabled).length}},[n]),C=(0,d.useMemo)(()=>n?.plugins||[],[n]),w=async(t,n)=>{v(t),b(null);try{o(await l(t,n)),e?.()}catch(e){b(e instanceof Error?e.message:s(`pluginsSaveFailed`))}finally{v(null)}};return(0,f.jsx)(`div`,{className:`quickforge-settings-stack`,children:(0,f.jsxs)(`section`,{className:`quickforge-settings-section`,"aria-label":s(`plugins`),children:[(0,f.jsxs)(`div`,{className:`quickforge-settings-toolbar`,children:[(0,f.jsxs)(`div`,{className:`quickforge-settings-row-main`,children:[(0,f.jsxs)(`div`,{className:`quickforge-settings-row-title`,children:[(0,f.jsx)(r,{className:`size-4 text-primary`}),s(`plugins`)]}),(0,f.jsx)(`div`,{className:`quickforge-settings-row-description`,children:s(`pluginsDescription`)}),(0,f.jsx)(`div`,{className:`quickforge-settings-meta`,children:(0,f.jsx)(`span`,{className:`quickforge-settings-badge quickforge-settings-badge-muted`,children:s(`pluginsCount`,S)})})]}),(0,f.jsxs)(`button`,{className:`quickforge-settings-button quickforge-settings-button-secondary`,type:`button`,onClick:()=>void x(`reload`),disabled:p,children:[p?(0,f.jsx)(t,{className:`mr-2 size-4 animate-spin`}):(0,f.jsx)(a,{className:`mr-2 size-4`}),s(`pluginsReload`)]})]}),y?(0,f.jsx)(`div`,{className:`quickforge-settings-alert quickforge-settings-warning-attached`,children:y}):null,n?.errors?.length?(0,f.jsxs)(`div`,{className:`quickforge-settings-warning quickforge-settings-warning-attached`,children:[(0,f.jsxs)(`div`,{className:`mb-2 inline-flex items-center gap-2 font-medium`,children:[(0,f.jsx)(i,{className:`size-4`}),s(`pluginDiscoveryErrors`)]}),n.errors.map((e,t)=>(0,f.jsxs)(`div`,{className:`break-all text-sm`,children:[(0,f.jsx)(`code`,{className:`quickforge-settings-command-name`,children:e.dir}),`: `,e.error]},`${e.dir}-${t}`))]}):null,p&&!n?(0,f.jsxs)(`div`,{className:`quickforge-settings-empty-row inline-flex items-center gap-2`,children:[(0,f.jsx)(t,{className:`size-4 animate-spin`}),s(`loadingPlugins`)]}):null,!p&&n&&n.plugins.length===0?(0,f.jsxs)(`div`,{className:`quickforge-settings-empty-row`,children:[(0,f.jsx)(`div`,{className:`quickforge-settings-row-title`,children:s(`noPlugins`)}),(0,f.jsx)(`div`,{className:`quickforge-settings-row-description`,children:s(`noPluginsDescription`)}),(0,f.jsx)(`div`,{className:`quickforge-settings-meta`,children:(n.searchPaths||[]).map(e=>(0,f.jsx)(`code`,{className:`quickforge-settings-command-name`,children:e},e))})]}):null,C.map(e=>(0,f.jsx)(`article`,{className:`quickforge-settings-list-item quickforge-settings-list-item--column`,children:(0,f.jsxs)(`div`,{className:`quickforge-settings-list-item-header`,children:[(0,f.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,f.jsx)(`span`,{className:`quickforge-settings-row-title`,children:m(e)}),(0,f.jsx)(`span`,{className:`quickforge-settings-row-description`,children:h(e)}),e.error?(0,f.jsx)(`span`,{className:`quickforge-settings-alert mt-3 block`,children:e.error}):null]}),(0,f.jsx)(`div`,{className:`quickforge-settings-list-item-actions`,children:(0,f.jsxs)(`label`,{className:`quickforge-settings-switch`,"aria-disabled":_===e.name?`true`:`false`,children:[(0,f.jsx)(`input`,{type:`checkbox`,checked:e.enabled,disabled:_===e.name,onChange:t=>void w(e.name,t.target.checked)}),(0,f.jsx)(`span`,{"aria-hidden":`true`})]})})]})},e.name))]})})}export{g as PluginsPage};
1
+ import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{J as t,Jt as n,T as r,o as i,w as a}from"./icons-DM_qJ7VJ.js";import{n as o}from"./react-vendor-BpWW_Nvp.js";import{Pn as s}from"./index-DQBOm9gt.js";import{n as c,r as l,t as u}from"./plugin-api-BrdQeM4B.js";var d=e(n(),1),f=o();function p(e){switch(e){case`documents`:return{label:s(`pluginDocumentsName`),description:s(`pluginDocumentsDescription`)};case`spreadsheets`:return{label:s(`pluginSpreadsheetsName`),description:s(`pluginSpreadsheetsDescription`)};case`presentations`:return{label:s(`pluginPresentationsName`),description:s(`pluginPresentationsDescription`)};default:return null}}function m(e){return p(e.name)?.label||(e.displayName||e.name).replace(/^OpenAI\s+/i,``)}function h(e){return p(e.name)?.description||e.description||s(`noDescription`)}function g({onChanged:e}){let[n,o]=(0,d.useState)(null),[p,g]=(0,d.useState)(!0),[_,v]=(0,d.useState)(null),[y,b]=(0,d.useState)(null),x=(0,d.useCallback)(async(t=`load`)=>{b(null),g(!0);try{o(t===`reload`?await c():await u()),t===`reload`&&e?.()}catch(e){b(e instanceof Error?e.message:s(`pluginsLoadFailed`))}finally{g(!1)}},[e]);(0,d.useEffect)(()=>{let e=!1;return u().then(t=>{e||o(t)}).catch(t=>{e||b(t instanceof Error?t.message:s(`pluginsLoadFailed`))}).finally(()=>{e||g(!1)}),()=>{e=!0}},[]);let S=(0,d.useMemo)(()=>{let e=n?.plugins||[];return{total:e.length,enabled:e.filter(e=>e.enabled).length}},[n]),C=(0,d.useMemo)(()=>n?.plugins||[],[n]),w=async(t,n)=>{v(t),b(null);try{o(await l(t,n)),e?.()}catch(e){b(e instanceof Error?e.message:s(`pluginsSaveFailed`))}finally{v(null)}};return(0,f.jsx)(`div`,{className:`quickforge-settings-stack`,children:(0,f.jsxs)(`section`,{className:`quickforge-settings-section`,"aria-label":s(`plugins`),children:[(0,f.jsxs)(`div`,{className:`quickforge-settings-toolbar`,children:[(0,f.jsxs)(`div`,{className:`quickforge-settings-row-main`,children:[(0,f.jsxs)(`div`,{className:`quickforge-settings-row-title`,children:[(0,f.jsx)(r,{className:`size-4 text-primary`}),s(`plugins`)]}),(0,f.jsx)(`div`,{className:`quickforge-settings-row-description`,children:s(`pluginsDescription`)}),(0,f.jsx)(`div`,{className:`quickforge-settings-meta`,children:(0,f.jsx)(`span`,{className:`quickforge-settings-badge quickforge-settings-badge-muted`,children:s(`pluginsCount`,S)})})]}),(0,f.jsxs)(`button`,{className:`quickforge-settings-button quickforge-settings-button-secondary`,type:`button`,onClick:()=>void x(`reload`),disabled:p,children:[p?(0,f.jsx)(t,{className:`mr-2 size-4 animate-spin`}):(0,f.jsx)(a,{className:`mr-2 size-4`}),s(`pluginsReload`)]})]}),y?(0,f.jsx)(`div`,{className:`quickforge-settings-alert quickforge-settings-warning-attached`,children:y}):null,n?.errors?.length?(0,f.jsxs)(`div`,{className:`quickforge-settings-warning quickforge-settings-warning-attached`,children:[(0,f.jsxs)(`div`,{className:`mb-2 inline-flex items-center gap-2 font-medium`,children:[(0,f.jsx)(i,{className:`size-4`}),s(`pluginDiscoveryErrors`)]}),n.errors.map((e,t)=>(0,f.jsxs)(`div`,{className:`break-all text-sm`,children:[(0,f.jsx)(`code`,{className:`quickforge-settings-command-name`,children:e.dir}),`: `,e.error]},`${e.dir}-${t}`))]}):null,p&&!n?(0,f.jsxs)(`div`,{className:`quickforge-settings-empty-row inline-flex items-center gap-2`,children:[(0,f.jsx)(t,{className:`size-4 animate-spin`}),s(`loadingPlugins`)]}):null,!p&&n&&n.plugins.length===0?(0,f.jsxs)(`div`,{className:`quickforge-settings-empty-row`,children:[(0,f.jsx)(`div`,{className:`quickforge-settings-row-title`,children:s(`noPlugins`)}),(0,f.jsx)(`div`,{className:`quickforge-settings-row-description`,children:s(`noPluginsDescription`)}),(0,f.jsx)(`div`,{className:`quickforge-settings-meta`,children:(n.searchPaths||[]).map(e=>(0,f.jsx)(`code`,{className:`quickforge-settings-command-name`,children:e},e))})]}):null,C.map(e=>(0,f.jsx)(`article`,{className:`quickforge-settings-list-item quickforge-settings-list-item--column`,children:(0,f.jsxs)(`div`,{className:`quickforge-settings-list-item-header`,children:[(0,f.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,f.jsx)(`span`,{className:`quickforge-settings-row-title`,children:m(e)}),(0,f.jsx)(`span`,{className:`quickforge-settings-row-description`,children:h(e)}),e.error?(0,f.jsx)(`span`,{className:`quickforge-settings-alert mt-3 block`,children:e.error}):null]}),(0,f.jsx)(`div`,{className:`quickforge-settings-list-item-actions`,children:(0,f.jsxs)(`label`,{className:`quickforge-settings-switch`,"aria-disabled":_===e.name?`true`:`false`,children:[(0,f.jsx)(`input`,{type:`checkbox`,checked:e.enabled,disabled:_===e.name,onChange:t=>void w(e.name,t.target.checked)}),(0,f.jsx)(`span`,{"aria-hidden":`true`})]})})]})},e.name))]})})}export{g as PluginsPage};
@@ -1,2 +1,2 @@
1
- import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{Et as t,Gt as n,Jt as r,Ot as i,Rt as a,b as o,f as s,ht as ee,j as te,ot as ne,pt as re,s as ie,t as ae,zt as oe}from"./icons-DM_qJ7VJ.js";import{n as c}from"./react-vendor-BpWW_Nvp.js";import{i as se,n as ce,r as le,t as ue}from"./model-display-label-CURwH0xM.js";import{An as l,Dn as de,Pn as u,Tt as fe,bn as d,fn as pe,kn as f,ln as p,pn as me,un as he}from"./index-DFASc15l.js";import{i as m,n as h,t as ge}from"./model-identity-CgA6_Pbm.js";var g=e(r(),1),_=c(),_e=[{value:`off`,label:()=>u(`thinkingOff`)},{value:`low`,label:()=>u(`thinkingLow`)},{value:`medium`,label:()=>u(`thinkingMedium`)},{value:`high`,label:()=>u(`thinkingHigh`)},{value:`xhigh`,label:()=>u(`thinkingXHigh`)}];function ve(e,t){return m(e,t)}function v(e){return String(e).padStart(2,`0`)}function y(e){if(!e)return`-`;let t=new Date(e);return Number.isNaN(t.getTime())?`-`:`${t.getFullYear()}-${v(t.getMonth()+1)}-${v(t.getDate())} ${v(t.getHours())}:${v(t.getMinutes())}`}function ye(e,t=20){let n=String(e||``).trim();return n.length>t?`${n.slice(0,t)}...`:n}function be(){return{scheduleText:``,title:``,instruction:``,cronExpression:``,scheduleRule:``,nextRunAt:``,enabled:!0,agentId:``,executionMode:`serial`}}function b(){return{taskId:``,status:``,trigger:``,keyword:``,startedFrom:``,startedTo:``,page:1,pageSize:10}}function xe(e){return{scheduleText:[e.scheduleRule,e.instruction].filter(Boolean).join(`
1
+ import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{Et as t,Gt as n,Jt as r,Ot as i,Rt as a,b as o,f as s,ht as ee,j as te,ot as ne,pt as re,s as ie,t as ae,zt as oe}from"./icons-DM_qJ7VJ.js";import{n as c}from"./react-vendor-BpWW_Nvp.js";import{i as se,n as ce,r as le,t as ue}from"./model-display-label-CURwH0xM.js";import{An as l,Dn as de,Pn as u,Tt as fe,bn as d,fn as pe,kn as f,ln as p,pn as me,un as he}from"./index-DQBOm9gt.js";import{i as m,n as h,t as ge}from"./model-identity-CgA6_Pbm.js";var g=e(r(),1),_=c(),_e=[{value:`off`,label:()=>u(`thinkingOff`)},{value:`low`,label:()=>u(`thinkingLow`)},{value:`medium`,label:()=>u(`thinkingMedium`)},{value:`high`,label:()=>u(`thinkingHigh`)},{value:`xhigh`,label:()=>u(`thinkingXHigh`)}];function ve(e,t){return m(e,t)}function v(e){return String(e).padStart(2,`0`)}function y(e){if(!e)return`-`;let t=new Date(e);return Number.isNaN(t.getTime())?`-`:`${t.getFullYear()}-${v(t.getMonth()+1)}-${v(t.getDate())} ${v(t.getHours())}:${v(t.getMinutes())}`}function ye(e,t=20){let n=String(e||``).trim();return n.length>t?`${n.slice(0,t)}...`:n}function be(){return{scheduleText:``,title:``,instruction:``,cronExpression:``,scheduleRule:``,nextRunAt:``,enabled:!0,agentId:``,executionMode:`serial`}}function b(){return{taskId:``,status:``,trigger:``,keyword:``,startedFrom:``,startedTo:``,page:1,pageSize:10}}function xe(e){return{scheduleText:[e.scheduleRule,e.instruction].filter(Boolean).join(`
2
2
  `),title:e.title,instruction:e.instruction,cronExpression:e.cronExpression??``,scheduleRule:e.scheduleRule,nextRunAt:e.nextRunAt,enabled:e.status!==`paused`,agentId:e.agentId??``,executionMode:e.executionMode??`serial`}}function Se(e,t){return{...t,title:e.title,instruction:e.instruction,cronExpression:e.cronExpression??``,scheduleRule:e.scheduleRule,nextRunAt:e.nextRunAt,enabled:t.enabled}}function Ce(e){return{title:e.title.trim(),instruction:e.instruction.trim(),scheduleType:`cron`,scheduleRule:e.scheduleRule.trim()||e.cronExpression.trim(),cronExpression:e.cronExpression.trim(),nextRunAt:e.nextRunAt,enabled:e.enabled,agentId:e.agentId||null,executionMode:e.executionMode}}function x(e){return!!(e.currentRunId||e.currentRunIds?.length)}function we(e){return(e.executionMode??`serial`)===`parallel`||!x(e)}function Te(e){return u(e===`parallel`?`taskExecutionModeParallel`:`taskExecutionModeSerial`)}function Ee(e){return!!(e.title.trim()&&e.instruction.trim()&&e.cronExpression.trim())}function De(e){return u(e===`enabled`?`taskEnabled`:e===`running`?`taskRunning`:e===`paused`?`taskPaused`:e===`completed`?`taskFinished`:e===`success`?`executionSuccess`:`taskFailed`)}function Oe(e){return e===`enabled`||e===`success`?`bg-emerald-500/10 text-emerald-700`:e===`running`?`bg-blue-500/10 text-blue-700`:e===`paused`?`bg-amber-500/10 text-amber-700`:`bg-muted text-muted-foreground`}async function S(e,t){let n=await fetch(e,{...t,headers:{"content-type":`application/json`,...t?.headers}}),r=await n.json().catch(()=>null);if(!n.ok)throw Error(r?.error||`请求失败`);return r}function C({onOpenSession:e}){let[r,c]=(0,g.useState)([]),[m,v]=(0,g.useState)(`tasks`),[C,w]=(0,g.useState)(()=>be()),[T,ke]=(0,g.useState)(null),[Ae,E]=(0,g.useState)(null),[D,O]=(0,g.useState)(null),[k,A]=(0,g.useState)(!1),[j,M]=(0,g.useState)(null),[je,N]=(0,g.useState)(``),[P,F]=(0,g.useState)(!1),[I,L]=(0,g.useState)(``),[R,Me]=(0,g.useState)([]),[z,B]=(0,g.useState)(),[V,H]=(0,g.useState)(`off`),[Ne,Pe]=(0,g.useState)([]),[Fe,Ie]=(0,g.useState)(``),[U,W]=(0,g.useState)(()=>b()),[G,K]=(0,g.useState)(()=>b()),[q,Le]=(0,g.useState)({runs:[],total:0,page:1,pageSize:10}),[Re,ze]=(0,g.useState)(!1),[Be,Ve]=(0,g.useState)(null),[He,Ue]=(0,g.useState)([]),We=Ne[0]?.id??``;(0,g.useEffect)(()=>{if(!D)return;let e=()=>O(null);return window.addEventListener(`click`,e),window.addEventListener(`blur`,e),()=>{window.removeEventListener(`click`,e),window.removeEventListener(`blur`,e)}},[D]);async function Ge(){c((await S(`/api/scheduled-tasks`)).tasks)}async function J(e=G){ze(!0),L(``);try{let t=new URLSearchParams;t.set(`page`,String(e.page)),t.set(`pageSize`,String(e.pageSize)),e.taskId&&t.set(`taskId`,e.taskId),e.status&&t.set(`status`,e.status),e.trigger&&t.set(`trigger`,e.trigger),e.keyword.trim()&&t.set(`keyword`,e.keyword.trim()),e.startedFrom&&t.set(`startedFrom`,e.startedFrom),e.startedTo&&t.set(`startedTo`,e.startedTo),Le(await S(`/api/scheduled-tasks/runs?${t.toString()}`))}catch(e){L(e instanceof Error?e.message:u(`requestFailed`))}finally{ze(!1)}}(0,g.useEffect)(()=>{let e=!1;async function t(){try{let t=await S(`/api/project`);if(e)return;Pe(t.projects??[])}catch{}}return t(),()=>{e=!0}},[]),(0,g.useEffect)(()=>{let e=!1;async function t(){try{let t=await pe(),[n,r]=await Promise.all([he(t),ce().catch(()=>[])]),i=r.length?r:n,a=i.filter(d),o=await me(t),s=(o.model&&d(o.model)?a.find(e=>ve(e,o.model))||(se(o.model)?a.find(e=>e.quickforgeCatalogId===o.model.quickforgeCatalogId):void 0):void 0)??a[0];if(e)return;Me(i),B(s),H(o.thinkingLevel??p(s))}catch(t){e||L(t instanceof Error?t.message:u(`requestFailed`))}}return t(),()=>{e=!0}},[]),(0,g.useEffect)(()=>{let e=!1,t=async()=>{try{let t=await S(`/api/scheduled-tasks`);e||c(t.tasks)}catch(t){e||L(t instanceof Error?t.message:u(`requestFailed`))}};t();let n=window.setInterval(t,10*1e3);return()=>{e=!0,window.clearInterval(n)}},[]),(0,g.useEffect)(()=>{let e=!1;async function t(){try{let t=await S(`/api/agent-profiles`);if(e)return;Ue(t.agents)}catch(t){e||L(t instanceof Error?t.message:u(`requestFailed`))}}return t(),()=>{e=!0}},[]);let Ke=(0,g.useMemo)(()=>r.find(e=>e.id===T),[T,r]),qe=(0,g.useMemo)(()=>R.filter(d),[R]),Je=(0,g.useMemo)(()=>ge(qe,z),[qe,z]),Y=(0,g.useMemo)(()=>r.find(e=>e.id===Ae)??null,[Ae,r]),Ye=(0,g.useMemo)(()=>r.filter(e=>e.status===`enabled`).length,[r]),Xe=Math.max(1,Math.ceil(q.total/q.pageSize));function Ze(e){return e?He.find(t=>t.id===e||t.name===e)?.label??e:u(`defaultAgent`)}function X(e,t){w(n=>({...n,[e]:t}))}function Z(e,t){W(n=>({...n,[e]:t}))}function Qe(){let e=R.find(d);ke(null),Ie(We),B(e),H(p(e)),w(be()),M(null),N(``),L(``)}function $e(){Qe(),A(!0)}function Q(){P||(A(!1),Qe())}function et(){let e={...U,page:1};W(e),K(e),J(e)}function tt(){let e=b();W(e),K(e),J(e)}function nt(e){let t=Math.min(Math.max(1,e),Xe),n={...G,page:t};W(n),K(n),J(n)}function rt(e){let t={...G,page:1,pageSize:e};W(t),K(t),J(t)}async function it(){let e=C.scheduleText.trim();if(e){F(!0),L(``);try{let t=await S(`/api/scheduled-tasks/parse`,{method:`POST`,body:JSON.stringify({instruction:e,modelRef:z?le(z):void 0,model:z,thinkingLevel:V})});if(t.needMoreInfo||!t.task){N(t.question||`请补充任务信息。`),M(null);return}let n=t.task;N(``),M(n),w(e=>Se(n,e))}catch(e){L(e instanceof Error?e.message:u(`requestFailed`))}finally{F(!1)}}}async function at(){if(Ee(C)){F(!0),L(``);try{let e=Ne.find(e=>e.id===Fe),t={task:Ce(C),modelRef:z?le(z):void 0,model:z,thinkingLevel:V,projectId:e?.id,projectName:e?.name};T?await S(`/api/scheduled-tasks/${encodeURIComponent(T)}`,{method:`PUT`,body:JSON.stringify(t)}):await S(`/api/scheduled-tasks`,{method:`POST`,body:JSON.stringify(t)}),Q(),await Ge(),m===`history`&&await J(G)}catch(e){L(e instanceof Error?e.message:u(`requestFailed`))}finally{F(!1)}}}function ot(e){O(null),ke(e.id),w(xe(e)),M(null),N(``),L(``),Ie(e.projectId??``),e.model&&B(e.model),e.thinkingLevel&&H(e.thinkingLevel),A(!0)}async function $(e,t){if(L(``),O(null),!(t===`delete`&&!await fe({description:u(`confirmDeleteTask`),confirmLabel:u(`confirmDelete`),cancelLabel:u(`cancel`),variant:`destructive`})))try{t===`delete`?(await S(`/api/scheduled-tasks/${encodeURIComponent(e)}`,{method:`DELETE`}),T===e&&Q(),Ae===e&&E(null)):await S(`/api/scheduled-tasks/${encodeURIComponent(e)}/${t}`,{method:`POST`}),await Ge(),m===`history`&&await J(G)}catch(e){L(e instanceof Error?e.message:u(`requestFailed`))}}function st(t){return(0,_.jsxs)(`div`,{className:`mt-2 space-y-2 text-xs text-muted-foreground`,children:[t.sessionId?(0,_.jsx)(f,{variant:`outline`,size:`sm`,onClick:()=>e?.(t.sessionId),children:u(`viewConversation`)}):null,(0,_.jsxs)(`div`,{children:[u(`executionAgent`),t.agentLabel||Ze(t.agentId)]}),t.warning?(0,_.jsx)(`div`,{className:`text-amber-600`,children:t.warning}):null,t.inputContent?(0,_.jsxs)(`div`,{children:[(0,_.jsx)(`div`,{className:`font-medium text-foreground`,children:u(`runInputContent`)}),(0,_.jsx)(`pre`,{className:`mt-1 max-h-32 overflow-auto whitespace-pre-wrap`,children:t.inputContent})]}):null,t.aiResult||t.result?(0,_.jsxs)(`div`,{children:[(0,_.jsx)(`div`,{className:`font-medium text-foreground`,children:u(`runAiResult`)}),(0,_.jsx)(`pre`,{className:`mt-1 max-h-48 overflow-auto whitespace-pre-wrap`,children:t.aiResult||t.result})]}):null,t.errorMessage?(0,_.jsx)(`div`,{className:`text-destructive`,children:t.errorMessage}):null,t.durationMs?(0,_.jsxs)(`div`,{children:[u(`runDuration`),t.durationMs,`ms`]}):null]})}return(0,_.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden bg-background`,children:[(0,_.jsxs)(`div`,{className:`border-b border-border px-6 py-5`,children:[(0,_.jsx)(`div`,{className:`flex flex-wrap items-center justify-end gap-3`,children:k||Y?(0,_.jsxs)(f,{variant:`outline`,onClick:()=>{k?Q():E(null)},children:[(0,_.jsx)(n,{className:`mr-1 size-4`}),u(`back`)]}):(0,_.jsx)(f,{onClick:$e,children:u(`createTask`)})}),!k&&!Y?(0,_.jsxs)(`div`,{className:`mt-4 flex flex-wrap gap-2`,children:[(0,_.jsxs)(`button`,{type:`button`,className:l(`rounded-full px-4 py-2 text-sm font-medium transition-colors`,m===`tasks`?`bg-primary text-primary-foreground`:`bg-muted text-muted-foreground hover:text-foreground`),onClick:()=>v(`tasks`),children:[u(`taskListTab`),` `,(0,_.jsx)(`span`,{className:`opacity-80`,children:r.length})]}),(0,_.jsx)(`button`,{type:`button`,className:l(`rounded-full px-4 py-2 text-sm font-medium transition-colors`,m===`history`?`bg-primary text-primary-foreground`:`bg-muted text-muted-foreground hover:text-foreground`),onClick:()=>{v(`history`),J(G)},children:u(`executionHistoryTab`)})]}):null]}),(0,_.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-6`,children:(0,_.jsx)(`div`,{className:`mx-auto max-w-5xl space-y-5`,children:k?(0,_.jsxs)(_.Fragment,{children:[(0,_.jsxs)(`div`,{className:`rounded-xl border border-border bg-card p-5 space-y-4`,children:[(0,_.jsxs)(`h2`,{className:`inline-flex items-center gap-1.5 text-base font-semibold text-foreground`,children:[u(Ke?`editTask`:`createTask`),(0,_.jsx)(de,{label:u(`quickAiParseTask`)})]}),(0,_.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[u(`taskScheduleDescriptionLabel`),(0,_.jsx)(`textarea`,{className:`mt-1 min-h-24 w-full resize-y rounded-xl border border-input bg-background px-3 py-2 text-sm outline-none transition-colors placeholder:text-muted-foreground/65 focus:border-ring`,value:C.scheduleText,onChange:e=>X(`scheduleText`,e.target.value),placeholder:u(`taskScheduleDescriptionPlaceholder`)})]}),(0,_.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,_.jsxs)(f,{onClick:it,disabled:P||!z||!C.scheduleText.trim(),children:[(0,_.jsx)(s,{className:`mr-1 size-3.5`}),u(`aiParseTask`)]}),je?(0,_.jsx)(`span`,{className:`text-sm text-amber-600`,children:je}):null]}),(0,_.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,_.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[u(`taskTitleLabel`),(0,_.jsx)(`input`,{className:`mt-1 h-10 w-full rounded-md border border-input bg-background px-3 text-sm outline-none focus:border-ring`,value:C.title,onChange:e=>X(`title`,e.target.value),placeholder:u(`taskTitlePlaceholder`)})]}),(0,_.jsxs)(`div`,{className:`block text-sm font-medium text-foreground`,children:[u(`executionRule`),(0,_.jsx)(`div`,{className:`mt-1 flex h-10 items-center rounded-md border border-input bg-muted/20 px-3 text-sm text-muted-foreground`,children:C.scheduleRule||`-`})]}),(0,_.jsxs)(`div`,{className:`block text-sm font-medium text-foreground`,children:[`cron`,(0,_.jsx)(`div`,{className:`mt-1 flex h-10 items-center rounded-md border border-input bg-muted/20 px-3 font-mono text-sm text-muted-foreground`,children:C.cronExpression||`-`})]}),(0,_.jsxs)(`div`,{className:`block text-sm font-medium text-foreground`,children:[u(`nextExecutionTime`),(0,_.jsx)(`div`,{className:`mt-1 flex h-10 items-center rounded-md border border-input bg-muted/20 px-3 text-sm text-muted-foreground`,children:y(C.nextRunAt)})]}),(0,_.jsxs)(`label`,{className:`block text-sm font-medium text-foreground sm:col-span-2`,children:[(0,_.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[u(`taskExecutionMode`),(0,_.jsx)(de,{label:u(`taskExecutionModeHelp`)})]}),(0,_.jsxs)(`select`,{className:`mt-1 h-10 w-full rounded-md border border-input bg-background px-3 text-sm text-foreground outline-none focus:border-ring`,value:C.executionMode,onChange:e=>X(`executionMode`,e.target.value),children:[(0,_.jsx)(`option`,{value:`serial`,children:u(`taskExecutionModeSerial`)}),(0,_.jsx)(`option`,{value:`parallel`,children:u(`taskExecutionModeParallel`)})]})]}),(0,_.jsxs)(`label`,{className:`block text-sm font-medium text-foreground sm:col-span-2`,children:[u(`promptContentLabel`),(0,_.jsx)(`textarea`,{className:`mt-1 min-h-28 w-full resize-y rounded-xl border border-input bg-background px-3 py-2 text-sm text-foreground outline-none transition-colors placeholder:text-muted-foreground/65 focus:border-ring`,value:C.instruction,onChange:e=>X(`instruction`,e.target.value),placeholder:u(`promptContentPlaceholder`)})]})]}),(0,_.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-foreground`,children:[(0,_.jsx)(`input`,{type:`checkbox`,checked:C.enabled,onChange:e=>X(`enabled`,e.target.checked)}),u(`taskEnabledSwitch`)]}),(0,_.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 rounded-xl border border-border bg-muted/20 px-2 py-2`,children:[(0,_.jsxs)(`span`,{className:`relative inline-flex items-center`,children:[(0,_.jsx)(s,{className:`pointer-events-none absolute left-2 size-3.5 text-muted-foreground/70`}),(0,_.jsxs)(`select`,{className:`h-8 max-w-[240px] rounded-md border border-transparent bg-transparent pl-7 pr-2 text-xs text-muted-foreground outline-none hover:bg-background focus:border-ring`,value:z?h(z):``,onChange:e=>{let t=Je.find(t=>h(t)===e.target.value);B(t),H(p(t))},title:u(`taskModel`),children:[Je.length===0?(0,_.jsx)(`option`,{value:``,children:u(`noModelAvailable`)}):null,Je.map(e=>(0,_.jsxs)(`option`,{value:h(e),children:[ue(e),ve(e,z)?` ✓`:``]},h(e)))]})]}),(0,_.jsxs)(`span`,{className:`relative inline-flex items-center`,children:[(0,_.jsx)(a,{className:`pointer-events-none absolute left-2 size-3.5 text-muted-foreground/70`}),(0,_.jsx)(`select`,{className:`h-8 rounded-md border border-transparent bg-transparent pl-7 pr-2 text-xs text-muted-foreground outline-none hover:bg-background focus:border-ring`,value:V,onChange:e=>H(e.target.value),title:u(`taskThinking`),children:_e.map(e=>(0,_.jsx)(`option`,{value:e.value,children:e.label()},e.value))})]}),(0,_.jsxs)(`span`,{className:`relative inline-flex items-center`,children:[(0,_.jsx)(ne,{className:`pointer-events-none absolute left-2 size-3.5 text-muted-foreground/70`}),(0,_.jsxs)(`select`,{className:`h-8 max-w-[220px] rounded-md border border-transparent bg-transparent pl-7 pr-2 text-xs text-muted-foreground outline-none hover:bg-background focus:border-ring`,value:Fe,onChange:e=>Ie(e.target.value),title:u(`taskProjectLabel`),children:[(0,_.jsx)(`option`,{value:``,children:u(`noProjectBound`)}),Ne.map(e=>(0,_.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,_.jsxs)(`span`,{className:`relative inline-flex items-center`,children:[(0,_.jsx)(oe,{className:`pointer-events-none absolute left-2 size-3.5 text-muted-foreground/70`}),(0,_.jsxs)(`select`,{className:`h-8 max-w-[220px] rounded-md border border-transparent bg-transparent pl-7 pr-2 text-xs text-muted-foreground outline-none hover:bg-background focus:border-ring`,value:C.agentId,onChange:e=>X(`agentId`,e.target.value),title:u(`executionAgent`),children:[(0,_.jsx)(`option`,{value:``,children:u(`defaultAgent`)}),He.map(e=>(0,_.jsx)(`option`,{value:e.id,children:e.label},e.id))]})]})]}),j?(0,_.jsxs)(`div`,{className:`rounded-xl border border-border bg-muted/30 p-3 text-sm`,children:[(0,_.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 font-medium text-foreground`,children:[(0,_.jsx)(i,{className:`size-4 text-emerald-600`}),u(`aiParsed`)]}),(0,_.jsxs)(`div`,{className:`grid gap-2 text-muted-foreground sm:grid-cols-2`,children:[(0,_.jsxs)(`div`,{children:[u(`taskName`),(0,_.jsx)(`span`,{className:`text-foreground`,children:j.title})]}),(0,_.jsxs)(`div`,{children:[u(`executionRule`),(0,_.jsx)(`span`,{className:`text-foreground`,children:j.scheduleRule})]}),(0,_.jsxs)(`div`,{children:[`cron:`,(0,_.jsx)(`span`,{className:`font-mono text-foreground`,children:j.cronExpression??`-`})]}),(0,_.jsxs)(`div`,{children:[u(`nextExecutionTime`),(0,_.jsx)(`span`,{className:`text-foreground`,children:y(j.nextRunAt)})]}),(0,_.jsxs)(`div`,{className:`sm:col-span-2`,children:[u(`aiInstruction`),(0,_.jsx)(`span`,{className:`text-foreground`,children:j.instruction})]})]})]}):null,I?(0,_.jsx)(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive`,children:I}):null]}),(0,_.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,_.jsx)(f,{variant:`outline`,onClick:Q,disabled:P,children:u(`cancel`)}),(0,_.jsx)(f,{onClick:at,disabled:P||!z||!Ee(C),children:u(Ke?`saveTask`:`confirmCreate`)})]})]}):Y?(0,_.jsxs)(`div`,{className:`rounded-xl border border-border bg-card`,children:[(0,_.jsx)(`div`,{className:`flex flex-wrap items-start justify-between gap-3 border-b border-border px-5 py-4`,children:(0,_.jsxs)(`div`,{children:[(0,_.jsx)(`h2`,{className:`text-base font-semibold text-foreground`,children:Y.title}),(0,_.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:Y.scheduleRule})]})}),(0,_.jsx)(`div`,{className:`px-5 py-4`,children:(0,_.jsxs)(`div`,{className:`space-y-4 text-sm`,children:[(0,_.jsxs)(`div`,{children:[(0,_.jsx)(`div`,{className:`mb-1 font-medium text-foreground`,children:u(`taskContent`)}),(0,_.jsx)(`pre`,{className:`max-h-48 overflow-auto whitespace-pre-wrap rounded-xl border border-border bg-muted/20 p-3 text-muted-foreground`,children:Y.instruction})]}),(0,_.jsxs)(`div`,{className:`grid gap-3 text-muted-foreground sm:grid-cols-2`,children:[(0,_.jsxs)(`div`,{children:[u(`executionRule`),(0,_.jsx)(`span`,{className:`text-foreground`,children:Y.scheduleRule})]}),(0,_.jsxs)(`div`,{children:[u(`taskExecutionMode`),`:`,(0,_.jsx)(`span`,{className:`text-foreground`,children:Te(Y.executionMode)})]}),(0,_.jsxs)(`div`,{children:[`cron:`,(0,_.jsx)(`span`,{className:`font-mono text-foreground`,children:Y.cronExpression??`-`})]}),(0,_.jsxs)(`div`,{children:[u(`lastExecution`),(0,_.jsx)(`span`,{className:`text-foreground`,children:y(Y.lastRunAt)})]}),(0,_.jsxs)(`div`,{children:[u(`nextExecution`),(0,_.jsx)(`span`,{className:`text-foreground`,children:y(Y.nextRunAt)})]}),(0,_.jsxs)(`div`,{children:[u(`executionAgent`),(0,_.jsx)(`span`,{className:`text-foreground`,children:Ze(Y.agentId)})]}),Y.projectName?(0,_.jsxs)(`div`,{children:[u(`taskProject`),(0,_.jsx)(`span`,{className:`text-foreground`,children:Y.projectName})]}):null,Y.model?(0,_.jsxs)(`div`,{children:[u(`taskModel`),`:`,(0,_.jsx)(`span`,{className:`text-foreground`,children:ue(Y.model)})]}):null,Y.thinkingLevel?(0,_.jsxs)(`div`,{children:[u(`taskThinkingLevel`),(0,_.jsx)(`span`,{className:`text-foreground`,children:_e.find(e=>e.value===Y.thinkingLevel)?.label()??Y.thinkingLevel})]}):null,(0,_.jsxs)(`div`,{children:[u(`createdAt`),`:`,(0,_.jsx)(`span`,{className:`text-foreground`,children:y(Y.createdAt)})]})]}),Y.runs?.length>0?(0,_.jsxs)(`div`,{children:[(0,_.jsx)(`div`,{className:`mb-2 font-medium text-foreground`,children:u(`recentExecutions`)}),(0,_.jsx)(`div`,{className:`space-y-2`,children:Y.runs.slice(0,5).map(e=>(0,_.jsxs)(`details`,{className:`rounded-lg border border-border bg-muted/20 p-2 text-xs text-muted-foreground`,children:[(0,_.jsxs)(`summary`,{className:`cursor-pointer text-foreground`,children:[y(e.startedAt),` · `,e.trigger===`manual`?u(`manualRun`):u(`autoRun`),` · `,De(e.status)]}),st(e)]},`${Y.id}:${e.id}`))})]}):null]})}),(0,_.jsx)(`div`,{className:`border-t border-border px-5 py-4`,children:(0,_.jsxs)(`div`,{className:`flex flex-wrap justify-end gap-2`,children:[Y.lastSessionId?(0,_.jsx)(f,{variant:`outline`,onClick:()=>e?.(Y.lastSessionId),children:u(`viewConversation`)}):null,(0,_.jsxs)(f,{variant:`outline`,disabled:!we(Y),onClick:()=>void $(Y.id,`run`),children:[(0,_.jsx)(ae,{className:`mr-1 size-3.5`}),u(`executeNow`)]}),(0,_.jsxs)(f,{variant:`outline`,disabled:x(Y),onClick:()=>ot(Y),children:[(0,_.jsx)(te,{className:`mr-1 size-3.5`}),u(`editTask`)]}),(0,_.jsxs)(f,{variant:`destructive`,disabled:x(Y),onClick:()=>void $(Y.id,`delete`),children:[(0,_.jsx)(ie,{className:`mr-1 size-3.5`}),u(`deleteTask`)]})]})})]}):(0,_.jsxs)(_.Fragment,{children:[I?(0,_.jsx)(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive`,children:I}):null,m===`tasks`?(0,_.jsxs)(_.Fragment,{children:[(0,_.jsx)(`div`,{className:`rounded-xl border border-border bg-card p-4`,children:(0,_.jsx)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:(0,_.jsxs)(`div`,{children:[(0,_.jsx)(`h2`,{className:`text-base font-semibold text-foreground`,children:u(`taskList`)}),(0,_.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:u(`tasksCount`,{total:r.length,enabled:Ye})})]})})}),(0,_.jsx)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:r.length===0?(0,_.jsx)(`div`,{className:`rounded-lg px-3 py-3 text-center text-xs text-muted-foreground/55 md:col-span-2`,children:u(`noScheduledTasks`)}):r.map(e=>{let n=e.status===`enabled`,r=e.status===`completed`,i=x(e);return(0,_.jsxs)(`div`,{className:`relative cursor-pointer rounded-xl border border-border bg-card p-4 transition-colors hover:bg-muted/15`,onClick:()=>E(e.id),children:[(0,_.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,_.jsxs)(`div`,{className:`min-w-0`,children:[(0,_.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,_.jsx)(`h3`,{className:`truncate text-sm font-medium text-foreground/90`,children:e.title})}),(0,_.jsx)(`p`,{className:`mt-2 text-sm text-muted-foreground`,children:ye(e.instruction,20)})]}),(0,_.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,onClick:e=>e.stopPropagation(),children:[(0,_.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":n,disabled:r,className:l(`relative h-6 w-11 rounded-full transition-colors disabled:cursor-not-allowed disabled:opacity-60`,n?`bg-emerald-500`:`bg-muted-foreground/30`),onClick:()=>void $(e.id,e.status===`paused`?`resume`:`pause`),title:e.status===`paused`?u(`enable`):u(`pauseTask`),children:(0,_.jsx)(`span`,{className:l(`absolute left-0.5 top-0.5 size-5 rounded-full bg-white shadow transition-transform`,n?`translate-x-5`:`translate-x-0`)})}),(0,_.jsxs)(`div`,{className:`relative`,children:[(0,_.jsx)(f,{variant:`ghost`,size:`icon`,onClick:()=>O(D===e.id?null:e.id),title:u(`moreActions`),children:(0,_.jsx)(ee,{className:`size-4`})}),D===e.id?(0,_.jsxs)(`div`,{className:`absolute right-0 z-20 mt-1 w-36 overflow-hidden rounded-xl border border-border bg-popover py-1 text-sm shadow-quickforge`,children:[(0,_.jsxs)(`button`,{className:`flex w-full items-center gap-2 px-3 py-2 text-left hover:bg-muted disabled:cursor-not-allowed disabled:opacity-50`,disabled:!we(e),onClick:()=>void $(e.id,`run`),children:[(0,_.jsx)(ae,{className:`size-3.5`}),u(`executeNow`)]}),(0,_.jsxs)(`button`,{className:`flex w-full items-center gap-2 px-3 py-2 text-left hover:bg-muted disabled:cursor-not-allowed disabled:opacity-50`,disabled:i,onClick:()=>ot(e),children:[(0,_.jsx)(te,{className:`size-3.5`}),u(`editTask`)]}),(0,_.jsxs)(`button`,{className:`flex w-full items-center gap-2 px-3 py-2 text-left hover:bg-muted`,onClick:()=>{O(null),E(e.id)},children:[(0,_.jsx)(re,{className:`size-3.5`}),u(`viewDetails`)]}),(0,_.jsxs)(`button`,{className:`flex w-full items-center gap-2 px-3 py-2 text-left text-destructive hover:bg-muted disabled:cursor-not-allowed disabled:opacity-50`,disabled:i,onClick:()=>void $(e.id,`delete`),children:[(0,_.jsx)(ie,{className:`size-3.5`}),u(`deleteTask`)]})]}):null]})]})]}),(0,_.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-x-4 gap-y-1 text-xs text-muted-foreground`,children:[(0,_.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,_.jsx)(t,{className:`size-3`}),e.scheduleRule]}),(0,_.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,_.jsx)(oe,{className:`size-3`}),Ze(e.agentId)]}),(0,_.jsxs)(`span`,{children:[u(`taskExecutionMode`),`:`,Te(e.executionMode)]}),e.projectName?(0,_.jsxs)(`span`,{children:[u(`taskProject`),e.projectName]}):null]}),(0,_.jsxs)(`div`,{className:`mt-4 grid gap-2 border-t border-border pt-3 text-xs text-muted-foreground sm:grid-cols-2`,children:[(0,_.jsxs)(`span`,{children:[u(`lastExecution`),y(e.lastRunAt)]}),(0,_.jsxs)(`span`,{children:[u(`nextExecution`),y(e.nextRunAt)]})]})]},e.id)})})]}):(0,_.jsxs)(`div`,{className:`space-y-4`,children:[(0,_.jsxs)(`div`,{className:`rounded-xl border border-border bg-card p-4`,children:[(0,_.jsxs)(`div`,{className:`mb-3 flex items-center gap-2 text-sm font-medium text-foreground`,children:[(0,_.jsx)(o,{className:`size-4`}),u(`historyFilters`)]}),(0,_.jsxs)(`div`,{className:`grid gap-3 md:grid-cols-3`,children:[(0,_.jsxs)(`label`,{className:`block text-xs font-medium text-muted-foreground`,children:[u(`taskName`),(0,_.jsxs)(`select`,{className:`mt-1 h-9 w-full rounded-md border border-input bg-background px-2 text-sm text-foreground`,value:U.taskId,onChange:e=>Z(`taskId`,e.target.value),children:[(0,_.jsx)(`option`,{value:``,children:u(`allTasks`)}),r.map(e=>(0,_.jsx)(`option`,{value:e.id,children:e.title},e.id))]})]}),(0,_.jsxs)(`label`,{className:`block text-xs font-medium text-muted-foreground`,children:[u(`status`),(0,_.jsxs)(`select`,{className:`mt-1 h-9 w-full rounded-md border border-input bg-background px-2 text-sm text-foreground`,value:U.status,onChange:e=>Z(`status`,e.target.value),children:[(0,_.jsx)(`option`,{value:``,children:u(`allStatuses`)}),(0,_.jsx)(`option`,{value:`running`,children:u(`executionRunning`)}),(0,_.jsx)(`option`,{value:`success`,children:u(`executionSuccess`)}),(0,_.jsx)(`option`,{value:`failed`,children:u(`taskFailed`)})]})]}),(0,_.jsxs)(`label`,{className:`block text-xs font-medium text-muted-foreground`,children:[u(`triggerType`),(0,_.jsxs)(`select`,{className:`mt-1 h-9 w-full rounded-md border border-input bg-background px-2 text-sm text-foreground`,value:U.trigger,onChange:e=>Z(`trigger`,e.target.value),children:[(0,_.jsx)(`option`,{value:``,children:u(`allTriggers`)}),(0,_.jsx)(`option`,{value:`schedule`,children:u(`autoRun`)}),(0,_.jsx)(`option`,{value:`manual`,children:u(`manualRun`)})]})]}),(0,_.jsxs)(`label`,{className:`block text-xs font-medium text-muted-foreground`,children:[u(`startTime`),(0,_.jsx)(`input`,{type:`datetime-local`,className:`mt-1 h-9 w-full rounded-md border border-input bg-background px-2 text-sm text-foreground`,value:U.startedFrom,onChange:e=>Z(`startedFrom`,e.target.value)})]}),(0,_.jsxs)(`label`,{className:`block text-xs font-medium text-muted-foreground`,children:[u(`endTime`),(0,_.jsx)(`input`,{type:`datetime-local`,className:`mt-1 h-9 w-full rounded-md border border-input bg-background px-2 text-sm text-foreground`,value:U.startedTo,onChange:e=>Z(`startedTo`,e.target.value)})]}),(0,_.jsxs)(`label`,{className:`block text-xs font-medium text-muted-foreground`,children:[u(`keyword`),(0,_.jsx)(`input`,{className:`mt-1 h-9 w-full rounded-md border border-input bg-background px-2 text-sm text-foreground`,value:U.keyword,onChange:e=>Z(`keyword`,e.target.value),placeholder:u(`keywordPlaceholder`)})]})]}),(0,_.jsxs)(`div`,{className:`mt-3 flex justify-end gap-2`,children:[(0,_.jsx)(f,{variant:`outline`,onClick:tt,children:u(`reset`)}),(0,_.jsx)(f,{onClick:et,children:u(`query`)})]})]}),(0,_.jsxs)(`div`,{className:`overflow-x-auto rounded-xl border border-border bg-card`,children:[(0,_.jsxs)(`div`,{className:`grid min-w-[600px] grid-cols-[1.3fr_0.7fr_0.7fr_1fr_0.7fr] gap-3 border-b border-border px-4 py-3 text-xs font-medium text-muted-foreground`,children:[(0,_.jsx)(`span`,{children:u(`taskName`)}),(0,_.jsx)(`span`,{children:u(`status`)}),(0,_.jsx)(`span`,{children:u(`triggerType`)}),(0,_.jsx)(`span`,{children:u(`startTime`)}),(0,_.jsx)(`span`,{children:u(`runDuration`)})]}),Re?(0,_.jsx)(`div`,{className:`p-8 text-center text-sm text-muted-foreground`,children:u(`loading`)}):q.runs.length===0?(0,_.jsx)(`div`,{className:`p-8 text-center text-sm text-muted-foreground`,children:u(`noExecutionHistory`)}):q.runs.map(e=>(0,_.jsxs)(`div`,{className:`border-b border-border last:border-b-0`,children:[(0,_.jsxs)(`button`,{type:`button`,className:`grid w-full min-w-[600px] grid-cols-[1.3fr_0.7fr_0.7fr_1fr_0.7fr] gap-3 px-4 py-3 text-left text-sm hover:bg-muted/40`,onClick:()=>{let t=`${e.taskId}:${e.id}`;Ve(Be===t?null:t)},children:[(0,_.jsx)(`span`,{className:`min-w-0 truncate text-foreground`,children:e.taskTitle}),(0,_.jsx)(`span`,{children:(0,_.jsx)(`span`,{className:l(`rounded-full px-2 py-0.5 text-xs`,Oe(e.status)),children:De(e.status)})}),(0,_.jsx)(`span`,{className:`text-muted-foreground`,children:e.trigger===`manual`?u(`manualRun`):u(`autoRun`)}),(0,_.jsx)(`span`,{className:`text-muted-foreground`,children:y(e.startedAt)}),(0,_.jsx)(`span`,{className:`text-muted-foreground`,children:e.durationMs?`${e.durationMs}ms`:`-`})]}),Be===`${e.taskId}:${e.id}`?(0,_.jsx)(`div`,{className:`border-t border-border bg-muted/20 px-4 py-3`,children:st(e)}):null]},`${e.taskId}:${e.id}`)),(0,_.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 px-4 py-3 text-sm text-muted-foreground`,children:[(0,_.jsx)(`span`,{children:u(`paginationSummary`,{page:q.page,pages:Xe,total:q.total})}),(0,_.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,_.jsx)(`select`,{className:`h-8 rounded-md border border-input bg-background px-2 text-sm`,value:q.pageSize,onChange:e=>rt(Number(e.target.value)),children:[10,20,50,100].map(e=>(0,_.jsx)(`option`,{value:e,children:u(`pageSize`,{size:e})},e))}),(0,_.jsx)(f,{variant:`outline`,size:`sm`,disabled:q.page<=1,onClick:()=>nt(q.page-1),children:u(`previousPage`)}),(0,_.jsx)(f,{variant:`outline`,size:`sm`,disabled:q.page>=Xe,onClick:()=>nt(q.page+1),children:u(`nextPage`)})]})]})]})]})]})})})]})}export{C as ScheduledTasksPage};