@shawnstack/quickforge 1.7.12 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/assets/AgentProfilesPage-lKGIE5Dj.js +1 -0
- package/dist/assets/ChatPanelHost-CWUYIkXG.js +11 -0
- package/dist/assets/CloudAccountSettingsPage-BhXH0ups.js +1 -0
- package/dist/assets/{PluginsPage-BIbIDfWY.js → PluginsPage-DHWF13mN.js} +1 -1
- package/dist/assets/{ScheduledTasksPage-BOqmBNCx.js → ScheduledTasksPage-DLAg-i8c.js} +2 -2
- package/dist/assets/{SettingsWorkspacePage-BCRtycRN.js → SettingsWorkspacePage-BhUzL5oi.js} +128 -128
- package/dist/assets/ShareLinksSettingsPage-DogGa3lH.js +1 -0
- package/dist/assets/SharedConversationPage-7QpeaG_P.js +1 -0
- package/dist/assets/{TerminalDock-Cqz_9mTC.js → TerminalDock-CWSKcuiU.js} +2 -2
- package/dist/assets/WorkspaceInspector-CEfyYqWy.js +36 -0
- package/dist/assets/{index-BWf6y3Kh.css → index-CX36XjVA.css} +1 -1
- package/dist/assets/index-CgVTwN15.js +66 -0
- package/dist/assets/local-tools-CJVNO1aW.js +388 -0
- package/dist/assets/{mcp-servers-dialog-7Xwu2RVW.js → mcp-servers-dialog-xf3UR49J.js} +2 -2
- package/dist/assets/{skills-dialog-C_JvWbAa.js → skills-dialog-Bbqtuy2h.js} +1 -1
- package/dist/index.html +4 -4
- package/dist/licenses/material-icon-theme.txt +8 -8
- package/package.json +1 -1
- package/server/agent-manager.mjs +175 -47
- package/server/context-references.mjs +139 -0
- package/server/custom-commands.mjs +43 -0
- package/server/index.mjs +1 -1
- package/server/project-config.mjs +17 -5
- package/server/routes/agent-profiles.mjs +16 -1
- package/server/routes/agent.mjs +1 -1
- package/server/routes/shared-conversation.mjs +13 -1
- package/server/routes/skills.mjs +22 -0
- package/server/routes/workspace.mjs +166 -2
- package/server/selected-capabilities.mjs +76 -0
- package/server/skills.mjs +1 -1
- package/server/system-prompt.mjs +1 -3
- package/server/tools/definitions.mjs +0 -10
- package/server/utils/workspace.mjs +13 -4
- package/skills/skill-creator/SKILL.md +485 -485
- package/skills/skill-creator/agents/analyzer.md +274 -274
- package/skills/skill-creator/agents/comparator.md +202 -202
- package/skills/skill-creator/agents/grader.md +223 -223
- package/skills/skill-creator/assets/eval_review.html +146 -146
- package/skills/skill-creator/eval-viewer/viewer.html +1325 -1325
- package/skills/skill-creator/references/schemas.md +430 -430
- package/dist/assets/AgentProfilesPage-CApCpsDd.js +0 -1
- package/dist/assets/ChatPanelHost-COTO7swS.js +0 -48
- package/dist/assets/CloudAccountSettingsPage-Be5r3dtv.js +0 -1
- package/dist/assets/ShareLinksSettingsPage-BrxQacJn.js +0 -1
- package/dist/assets/SharedConversationPage-DJa0M0El.js +0 -1
- package/dist/assets/WorkspaceInspector-C-GOK81D.js +0 -36
- package/dist/assets/index-D3GWkXJR.js +0 -66
- package/dist/assets/local-tools-DY0yEU3T.js +0 -350
|
@@ -1 +0,0 @@
|
|
|
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{An as re,Cn as d,Ln as f,Mn as p,Tt as ie,ct as ae,fn as oe,gn as se,hn as ce,pn as le}from"./index-D3GWkXJR.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:f(`requestFailed`))}}return t(),()=>{e=!0}},[]),(0,m.useEffect)(()=>{let e=!1;async function t(){try{let t=await ce(),[n,r]=await Promise.all([le(t),te().catch(()=>[])]),i=r.length?r:n;ye(i);let a=i.filter(d),o=await se(t),s=(o.model&&d(o.model)?a.find(e=>ue(e,o.model)):void 0)??a[0];if(e)return;ve(s),xe(o.thinkingLevel??oe(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(d),[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:f(`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(f(`aiFillAgentInputRequired`));return}if(!L){B(f(`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:f(`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:f(`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:f(`requestFailed`))}}async function Ne(e){if(!(e.builtin||e.readonly)&&await ie({description:f(`confirmDeleteAgent`),confirmLabel:f(`confirmDelete`),cancelLabel:f(`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:f(`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?f(`builtinAgentModelSettings`):f(G?`editAgent`:`createAgent`),(0,b.jsx)(re,{label:G?.builtin?f(`builtinAgentModelOnly`):G?.readonly?f(`readonlyAgentDescription`):f(`agentsDescription`)})]})}),(0,b.jsxs)(`section`,{className:`quickforge-settings-section`,"aria-label":f(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`}),f(`back`)]}),(0,b.jsxs)(`div`,{className:`quickforge-settings-row-main`,children:[(0,b.jsx)(`div`,{className:`quickforge-settings-row-title`,children:G?.builtin?f(`builtinAgentModelSettings`):f(G?`editAgent`:`createAgent`)}),G?.builtin?(0,b.jsx)(`div`,{className:`quickforge-settings-row-description`,children:f(`builtinAgentModelOnly`)}):G?.readonly?(0,b.jsx)(`div`,{className:`quickforge-settings-row-description`,children:f(`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`}),f(`aiFillAgent`),(0,b.jsx)(re,{label:f(`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:f(`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`}),f(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:[f(`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:[f(`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:f(`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:f(`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?f(`builtinAgent`):`-`})]}):null,(0,b.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[f(`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:[f(`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:[f(`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:f(`agentModelInherit`)}),(0,b.jsx)(`option`,{value:`fixed`,children:f(`agentModelFixed`)})]})]}),(0,b.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[f(`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:f(`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):f(`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:[f(`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:f(`agentThinkingInherit`)}),(0,b.jsx)(`option`,{value:`off`,children:f(`thinkingOff`)}),(0,b.jsx)(`option`,{value:`low`,children:f(`thinkingLow`)}),(0,b.jsx)(`option`,{value:`medium`,children:f(`thinkingMedium`)}),(0,b.jsx)(`option`,{value:`high`,children:f(`thinkingHigh`)}),(0,b.jsx)(`option`,{value:`xhigh`,children:f(`thinkingXHigh`)})]}),(0,b.jsx)(`span`,{className:`mt-1 block text-xs text-muted-foreground`,children:f(X?`agentThinkingUnsupported`:`agentThinkingDescription`)})]}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`div`,{className:`mb-2 text-sm font-medium text-foreground`,children:f(`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:f(`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:[f(`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:f(`maxRuntimeMinutesHelp`)})]}),(0,b.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[f(`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)}),f(`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:f(`cancel`)}),(0,b.jsx)(p,{onClick:je,disabled:j||F||J||!G?.builtin&&!_e(y)||y.modelMode===`fixed`&&!y.fixedModelValue,children:f(`save`)})]})]})]}):(0,b.jsxs)(`div`,{className:`quickforge-settings-stack`,children:[(0,b.jsxs)(`section`,{className:`quickforge-settings-section`,"aria-label":f(`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`}),f(`agentsTab`)]}),(0,b.jsx)(`div`,{className:`quickforge-settings-row-description`,children:f(`agentsDescription`)})]}),(0,b.jsx)(`button`,{className:`quickforge-settings-button quickforge-settings-button-primary`,type:`button`,onClick:ke,children:f(`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:f(`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?f(`disableAsSubagent`):f(`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:f(`moreActions`),"aria-label":f(`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":f(`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`}),f(`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`}),f(`delete`)]})]}),document.body):null]})}export{A as AgentProfilesPage};
|
|
@@ -1,48 +0,0 @@
|
|
|
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-BNuvqKDT.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,Ln 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-D3GWkXJR.js";import{_,a as v,b as y,d as b,f as ee,g as x,h as S,i as te,l as ne,m as re,n as ie,p as ae,r as oe,t as se,u as ce,v as le,y as ue}from"./local-tools-DY0yEU3T.js";import{t as C}from"./plugin-api-BrdQeM4B.js";var w=e(t(),1);function de({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()},ee=()=>{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},x=e=>{e.deltaY<0&&g()},S=e=>{e.target===e.currentTarget&&_()},te=e=>{(e.key===`ArrowUp`||e.key===`PageUp`||e.key===`Home`)&&g()},ne=e=>{o=e.touches[0]?.clientY},re=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`,ee,{passive:!0}),t.addEventListener(`wheel`,x,{passive:!0}),t.addEventListener(`pointerdown`,S,{passive:!0}),t.addEventListener(`keydown`,te),t.addEventListener(`touchstart`,ne,{passive:!0}),t.addEventListener(`touchmove`,re,{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`,ee),e?.removeEventListener(`wheel`,x),e?.removeEventListener(`pointerdown`,S),e?.removeEventListener(`keydown`,te),e?.removeEventListener(`touchstart`,ne),e?.removeEventListener(`touchmove`,re),l?.disconnect(),l=void 0,i!==void 0&&(window.cancelAnimationFrame(i),i=void 0)}}}function T(e){return e.role===`user`||e.role===`user-with-attachments`}function E(e){let t=[];for(let n=0;n<e.length;n++)T(e[n])&&t.push(n);return t}function fe(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 D(e,t){let n=0;for(let r of e)if(n+=fe(r.content,t-n),n>=t)return!0;return!1}function pe(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++)pe(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 me(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=E(e);let o=c.length;return l=Math.min(a,Math.max(1,o-1)),m=t&&o>1&&(o>n||e.length>r||D(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 he=!1,k=null;function ge(){return customElements.get(`message-list`)||null}function _e(e){if(k=e(),he)return;let t=()=>{let e=ge();if(!e)return!1;let t=Object.getOwnPropertyDescriptor(e,`messages`);if(!t||typeof t.set!=`function`)return!1;he=!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 ve(e){k===e&&(k=null)}function ye({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
|
-
<span class="quickforge-command-suggestion-name"></span>
|
|
3
|
-
<span class="quickforge-command-suggestion-description"></span>
|
|
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 be={plugin:`
|
|
5
|
-
<svg viewBox="0 0 20 20" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round">
|
|
6
|
-
<path d="M7.4 3.2h5.2a1.2 1.2 0 0 1 1.2 1.2v2.1h.9a2.1 2.1 0 1 1 0 4.2h-.9v2.1a1.2 1.2 0 0 1-1.2 1.2h-2.1v.7a2.1 2.1 0 1 1-4.2 0V14H4.4a1.2 1.2 0 0 1-1.2-1.2V9.9h.8a1.8 1.8 0 1 0 0-3.6h-.8V4.4a1.2 1.2 0 0 1 1.2-1.2h2.1v-.8a1.8 1.8 0 1 1 3.6 0v.8Z" />
|
|
7
|
-
</svg>`,document:`
|
|
8
|
-
<svg viewBox="0 0 20 20" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.65" stroke-linecap="round" stroke-linejoin="round">
|
|
9
|
-
<path d="M5.4 2.8h6.1L15.8 7v10.2H5.4z" />
|
|
10
|
-
<path d="M11.4 2.9V7h4.1" />
|
|
11
|
-
<path d="M7.6 10.2h5" />
|
|
12
|
-
<path d="M7.6 13h4.3" />
|
|
13
|
-
</svg>`,spreadsheet:`
|
|
14
|
-
<svg viewBox="0 0 20 20" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.65" stroke-linecap="round" stroke-linejoin="round">
|
|
15
|
-
<rect x="3.4" y="4" width="13.2" height="12.2" rx="1.5" />
|
|
16
|
-
<path d="M3.4 8h13.2" />
|
|
17
|
-
<path d="M7.8 4v12.2" />
|
|
18
|
-
<path d="M12.2 4v12.2" />
|
|
19
|
-
<path d="M3.4 12h13.2" />
|
|
20
|
-
</svg>`,presentation:`
|
|
21
|
-
<svg viewBox="0 0 20 20" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.65" stroke-linecap="round" stroke-linejoin="round">
|
|
22
|
-
<path d="M3 4.2h14" />
|
|
23
|
-
<rect x="4.2" y="4.2" width="11.6" height="8.4" rx="1.2" />
|
|
24
|
-
<path d="M10 12.6v3.2" />
|
|
25
|
-
<path d="m7.2 17 2.8-1.2 2.8 1.2" />
|
|
26
|
-
<path d="M7.1 9.5 9 7.7l1.5 1.3 2.4-2.5" />
|
|
27
|
-
</svg>`,skill:`
|
|
28
|
-
<svg viewBox="0 0 20 20" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round">
|
|
29
|
-
<path d="M4.2 3.2h4.4A2.4 2.4 0 0 1 11 5.6v11a2.4 2.4 0 0 0-2.4-2.4H4.2V3.2Z" />
|
|
30
|
-
<path d="M11 5.6a2.4 2.4 0 0 1 2.4-2.4h2.4v11.1h-2.4A2.4 2.4 0 0 0 11 16.7" />
|
|
31
|
-
</svg>`,tool:`
|
|
32
|
-
<svg viewBox="0 0 20 20" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
|
|
33
|
-
<path d="M12.8 3.5a4.2 4.2 0 0 0 4 5.5l-7.6 7.6a2.2 2.2 0 0 1-3.1-3.1l7.6-7.6a4.2 4.2 0 0 0-5.5-4" />
|
|
34
|
-
</svg>`,command:`
|
|
35
|
-
<svg viewBox="0 0 20 20" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
|
|
36
|
-
<path d="m5 6 4 4-4 4" />
|
|
37
|
-
<path d="M10.5 14h4.5" />
|
|
38
|
-
</svg>`};function A(e){return e.split(/[-_/\\]+/).filter(Boolean).map(e=>e&&`${e[0].toUpperCase()}${e.slice(1)}`).join(` `)}function xe(e){switch(e.name){case`documents`:return{label:l(`pluginDocumentsName`),description:l(`pluginDocumentsDescription`),mention:`Documents`,iconKind:`document`};case`spreadsheets`:return{label:l(`pluginSpreadsheetsName`),description:l(`pluginSpreadsheetsDescription`),mention:`Spreadsheets`,iconKind:`spreadsheet`};case`presentations`:return{label:l(`pluginPresentationsName`),description:l(`pluginPresentationsDescription`),mention:`Presentations`,iconKind:`presentation`};default:return null}}function Se(e){let t=xe(e);return t?t.label:(e.displayName||A(e.name.replace(/^openai-/,``))).replace(/^OpenAI\s+/i,``)}function j(e){let t=xe(e),n=t?.label??Se(e),r=t?.mention??n.replace(/\s+/g,``);return[{type:`plugin`,iconKind:t?.iconKind??`plugin`,pluginName:e.name,name:e.name,label:n,mention:r,insertText:r,description:t?.description??e.description}]}function M(e,t){let n=e.slice(0,t),r=/(^|\s)@([^\s@]*)$/.exec(n);if(!r)return null;let i=r[1]?.length??0;return{start:n.length-r[0].length+i,end:t,query:r[2]??``}}function Ce(e){let t=new Set,n=/(^|\s)@([\p{L}\p{N}_-]+)/gu,r;for(;r=n.exec(e);)t.add((r[2]||``).toLowerCase());return t}function we({panel:e,restoreDraftIntoComposer:t,onSelectionChange:n,enabled:r=!0}){let i=[],a=null,o=`idle`,s=!1,c=!1,u=new Map,d=()=>n?.([...u.values()]),f=()=>a||(o===`loaded`?Promise.resolve():(o=`loading`,a=C().then(e=>{i=(e.plugins??[]).filter(e=>e.enabled&&e.status===`loaded`)}).catch(()=>{i=[]}).finally(()=>{a=null,o=`loaded`}),a));r&&f();let p=()=>i.flatMap(j),m=()=>{let t=(e.querySelector(`.quickforge-capability-suggestions`)?.querySelector(`.quickforge-capability-suggestion-item`))?.dataset.quickforgeCapabilityKey;if(t)return p().find(e=>N(e)===t)},h=()=>{let t=e.querySelector(`.quickforge-capability-suggestions`);t?.__quickforgeDismissHandler&&(document.removeEventListener(`pointerdown`,t.__quickforgeDismissHandler,!0),t.__quickforgeDismissHandler=void 0),t?.remove()},g=(n,r)=>{let i=e.querySelector(`message-editor`),a=i?.querySelector(`textarea`),o=i?.value??a?.value??``,s=a?.selectionStart??o.length,c=r??M(o,s),l=`@${n.insertText}`,f=c?`${o.slice(0,c.start)}${l} ${o.slice(c.end)}`:`${o}${o.endsWith(` `)||o.length===0?``:` `}${l} `,p=c?c.start+l.length+1:f.length;u.set(N(n),n),d(),t({text:f,attachments:i?.attachments?[...i.attachments]:[]});let m=i?.querySelector(`textarea`);m?.focus(),m&&(m.selectionStart=p,m.selectionEnd=p),h()},_=e=>{let t=()=>{let t=p().find(t=>t.insertText===e);t&&g(t)};if(i.length>0){t();return}c||(c=!0,f().then(()=>{c=!1,t()}))},v=t=>{let n=e.querySelector(`message-editor`),r=n?.querySelector(`textarea`),c=t??n?.value??r?.value??``,u=M(c,r?.selectionStart??c.length),d=e.querySelector(`.quickforge-capability-suggestions`);if(!n||!r||!u){s&&(o=`idle`),s=!1,d?.remove();return}if(s=!0,i.length===0){let t=f();a!==null&&t.then(()=>{let t=e.querySelector(`message-editor`),n=t?.querySelector(`textarea`),r=t?.value??n?.value??``;M(r,n?.selectionStart??r.length)&&v(r)})}let m=u.query.toLowerCase(),_=p().filter(e=>[e.label,e.name,e.pluginName,e.description].filter(Boolean).join(` `).toLowerCase().includes(m)).slice(0,8);if(_.length===0){d?.remove();return}let y=d??document.createElement(`div`);y.className=`quickforge-capability-suggestions`,y.setAttribute(`role`,`listbox`),y.innerHTML=``;let b=document.createElement(`div`);b.className=`quickforge-capability-suggestions-header`,b.textContent=l(`pluginMentionHeader`),y.append(b);for(let e of _){let t=document.createElement(`button`);t.type=`button`,t.className=`quickforge-capability-suggestion-item`,t.dataset.quickforgeCapabilityKey=N(e),t.dataset.quickforgePluginName=e.pluginName,t.setAttribute(`role`,`option`),t.innerHTML=`
|
|
39
|
-
<span class="quickforge-capability-suggestion-icon quickforge-capability-suggestion-icon-${e.iconKind}">${be[e.iconKind]}</span>
|
|
40
|
-
<span class="quickforge-capability-suggestion-main">
|
|
41
|
-
<span class="quickforge-capability-suggestion-line">
|
|
42
|
-
<span class="quickforge-capability-suggestion-name"></span>
|
|
43
|
-
</span>
|
|
44
|
-
<span class="quickforge-capability-suggestion-description"></span>
|
|
45
|
-
</span>
|
|
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=M(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=Ce(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(N(e),e);return u=new Map,d(),[...i.values()].slice(0,4)},insertBuiltinPluginMention:_,availablePluginRows:p}}function N(e){return`${e.type}:${e.pluginName}:${e.name}`}function Te(e){return e>=5}function Ee(e){return e.role===`user`||e.role===`user-with-attachments`}function De(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
|
-
|
|
48
|
-
`).trim():``}function P(e){return Ee(e)?(typeof e.content==`string`?e.content:De(e.content)).trim():``}function Oe(e){return e.role===`assistant`?De(e.content):``}function ke(e,t){let n=[];for(let t=0;t<e.length;t++){let r=e[t];if(!Ee(r))continue;let i=``;for(let n=t+1;n<e.length;n++){let t=e[n];if(Ee(t))break;t.role===`assistant`&&(i=Oe(t))}n.push({messageIndex:t,userText:P(r),finalAnswerText:i,isGenerating:!1})}return t&&n.length>0&&(n[n.length-1].isGenerating=!0),n}var Ae=Ee;function F(e,t){return e.trim().replace(/\s+/g,` `)||t}function je({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,ee=()=>{h!==void 0&&(window.clearTimeout(h),h=void 0)},x=()=>{g!==void 0&&(window.clearTimeout(g),g=void 0)},S=()=>{ee(),x(),p?.remove(),p=null,m?.removeAttribute(`aria-describedby`),m=null},te=()=>{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`},ne=(e,t)=>{ee(),x(),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=F(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`,x),r.addEventListener(`pointerleave`,()=>{g=window.setTimeout(S,100)}),document.body.append(r),p=r,m=e,e.setAttribute(`aria-describedby`,i),te()},re=(e,t)=>{ee(),x(),h=window.setTimeout(()=>ne(e,t),150)},ie=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`)}))},ae=()=>{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=>Ae(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;ie(o[Math.min(l,o.length-1)])},oe=()=>{let e=t.querySelector(`agent-interface .overflow-y-auto`);e!==_&&(_?.removeEventListener(`scroll`,ae),_=e,_?.addEventListener(`scroll`,ae,{passive:!0}))},se=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(Ae).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`})),ie(e),o()})};(s.updateComplete??Promise.resolve()).then(m,m)},ce=()=>{if(c.replaceChildren(),!Te(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:F(e.userText,l(`turnNavigationAttachmentOnly`))})),n.addEventListener(`pointerenter`,()=>re(n,t)),n.addEventListener(`pointerleave`,()=>{ee(),g=window.setTimeout(S,100)}),n.addEventListener(`focus`,()=>re(n,t)),n.addEventListener(`blur`,()=>{g=window.setTimeout(S,100)}),n.addEventListener(`click`,()=>se(t)),c.append(n)}),f=-1},le=()=>{u=ke(n(),r());let e=u.map(e=>`${e.messageIndex}:${e.userText}`).join(`|`);e!==d&&(d=e,ce()),oe(),ae()},ue=e=>{e.key===`Escape`&&S()},C=()=>S();return document.addEventListener(`keydown`,ue),window.addEventListener(`resize`,C),{update:le,cleanup(){v+=1,b?.(),b=null,y?.(),y=null,S(),_?.removeEventListener(`scroll`,ae),document.removeEventListener(`keydown`,ue),window.removeEventListener(`resize`,C),s.remove()}}}function I(e){return!!(e&&typeof e==`object`&&!Array.isArray(e))}function L(e,t){let n=e[t];return typeof n==`string`&&n.trim()?n:void 0}function R(e,t){let n=e[t];return typeof n==`boolean`?n:void 0}function z(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:void 0}function Me(e){let t=e&&I(e.diff)?e.diff:void 0;return{addedLines:t?z(t,`addedLines`):void 0,removedLines:t?z(t,`removedLines`):void 0}}function B(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 Ne(e){return e===`html`||e===`image`||e===`markdown`||e===`code`}function Pe(e){return[e.source,e.path??``,e.command??``,e.outputFile??``,e.toolCallId??``,e.preview?`preview`:``].join(`\0`)}function V(e,t,n){let r=Pe(n);t.has(r)||(t.add(r),e.push({id:`${e.length}:${r}`,...n}))}function Fe(e){if(!(typeof e!=`string`||!e.trim()))try{return JSON.parse(e)}catch{return}}function Ie(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(!I(e)||e.type!==`text`)continue;let t=Fe(e.text);if(I(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(!I(e)||e.type!==`text`)continue;let t=Fe(e.text);if(I(t)&&(Array.isArray(t.files)||Array.isArray(t.previewed)))return t}return t}function H(e){if(typeof e==`string`&&e.trim())return{path:e};if(I(e)){let t=L(e,`path`);return t?{path:t,title:L(e,`title`),description:L(e,`description`),kind:L(e,`kind`),preview:R(e,`preview`)}:void 0}}function Le(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=I(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?L(i,`path`):void 0;if(r){let o=B(r),{addedLines:s,removedLines:c}=Me(i);V(n,t,{source:e,confidence:`high`,path:r,toolCallId:a,kind:o,preview:Ne(o),presentation:`inferred`,addedLines:s,removedLines:c})}}else if(e===`present_files`){let e=Ie(r,i),o=I(e)&&Array.isArray(e.files)?e.files:[],s=I(e)?L(e,`defaultPreview`):void 0,c=new Set(I(e)&&Array.isArray(e.previewed)?e.previewed.filter(e=>typeof e==`string`):[]);for(let e of o){let r=H(e);if(!r?.path)continue;let i=r.kind??B(r.path);V(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||Ne(i)),defaultPreview:s===r.path,presentation:`explicit`})}}else if(e===`run_command`&&i){let e=L(i,`command`),r=L(i,`outputFile`);(e||r)&&V(n,t,{source:`run_command`,confidence:`low`,command:e,outputFile:r,toolCallId:a})}}}return n}function Re(e){return e?.length?Le(e):[]}var U=`quickforge:composer-drafts:v1`,W=100,G={},K=!1;function q(e){return!!(e&&!e.startsWith(`pending-`))}function ze(e){return q(e.sessionId)?`session:${e.sessionId}`:e.scope===`project`&&e.projectId?`new:project:${e.projectId}`:`new:global`}function Be(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 Ve(){try{return globalThis.localStorage}catch{return}}function He(e,t=W){return Object.fromEntries(Object.entries(e).filter(([,e])=>e.text.length>0).sort(([,e],[,t])=>t.updatedAt.localeCompare(e.updatedAt)).slice(0,t))}function Ue(){let e=Ve();if(!e||K)return G;let t;try{t=e.getItem(U)}catch{return K=!0,G}try{return Be(t?JSON.parse(t):void 0)}catch{return G}}function We(e){let t=He(e);G=t;let n=Ve();if(!(!n||K))try{Object.keys(t).length===0?n.removeItem(U):n.setItem(U,JSON.stringify(t))}catch{let e=He(t,Math.ceil(W/2));G=e;try{Object.keys(e).length===0?n.removeItem(U):n.setItem(U,JSON.stringify(e))}catch{K=!0}}}async function Ge(e){let t=Ue()[e];if(!(!t||t.text.length===0))return{text:t.text,attachments:[]}}async function Ke(e,t,n){let r=t.text??``;if(r.length===0){await qe(e);return}let i=Ue();i[e]={text:r,updatedAt:new Date().toISOString(),scope:n.scope,projectId:n.scope===`project`?n.projectId:void 0,sessionId:q(n.sessionId)?n.sessionId:void 0},We(i)}async function qe(e){let t=Ue();Object.prototype.hasOwnProperty.call(t,e)&&(delete t[e],We(t))}function Je(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 Ye(){let e=0;return{version:()=>e,isCurrent:t=>t===e,invalidate:()=>(e+=1,e)}}var Xe=n();function Ze(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 Qe(e){let t=String(e.length);for(let n of e)n.role===`toolResult`&&(t+=`|${n.toolCallId??``}:${n.toolName??``}`);return t}function $e({agent:e,onModelSelect:t,revision:n,agentAccessMode:C,workspaceToolsEnabled:T,project:E,projectId:fe,chatScope:D=`global`,onAccessModeChange:pe,onRollbackFromMessage:O,onRetryFromMessage:he,onCopyAnswer:k,onForkFromMessage:ge,onApproveToolCall:be,onRejectToolCall:A,onAnswerAsk:xe,onApproveAutoCompact:Se,onRejectAutoCompact:j,onOpenWorkspaceGitChanges:M,onOpenLocalFilePath:Ce,onArtifactsChange:N,onContextUsageDisplayChange:Te,onInitialRenderReady:Ee,onInitialRenderError:De,restoredDraft:P,onRestoredDraftConsumed:Oe,disableFork:ke=!1,readOnly:Ae=!1,approvalReadOnly:F=!1,approvalReadOnlyMessage:I,bypassClientApiKeyCheck:L=!1,allowModelControls:R=!0,newChatEmptyState:z=!1,showTurnNavigation:Me=!0,rollbackConfirmTitle:B,rollbackConfirmDescription:Ne,capabilities:Pe=g}){let V=(0,w.useRef)(null),Fe=(0,w.useRef)(void 0),Ie=(0,w.useRef)(void 0),H=(0,w.useRef)(new Map),Le=(0,w.useRef)([]),U=(0,w.useRef)(void 0),W=(0,w.useRef)(new Set),G=(0,w.useRef)(void 0),K=(0,w.useRef)(null),q=(0,w.useRef)(!1),Be=(0,w.useRef)(new WeakSet),Ve=(0,w.useRef)(``),He=(0,w.useRef)(``),Ue=(0,w.useRef)(Ye()),[We,$e]=(0,w.useState)(),[et,tt]=(0,w.useState)(!1),J=(0,w.useMemo)(()=>m(Pe,{readOnly:Ae,disableFork:ke}),[Pe,Ae,ke]),nt=(0,w.useCallback)(()=>tt(e=>!e),[]),rt=(0,w.useCallback)(()=>tt(!1),[]);(0,w.useEffect)(()=>{let t=e,n=J.planMode&&et;t?.setPlanMode?.(n,n?rt:void 0),!J.planMode&&et&&queueMicrotask(rt)},[e,et,rt,J.planMode]);let it=(0,w.useCallback)(()=>{G.current&&=(window.clearTimeout(G.current),void 0)},[]),Y=(0,w.useCallback)(()=>{K.current?.cancel(),K.current=null,q.current=!1},[]),at=(0,w.useCallback)(e=>{Je(W.current,e),Oe?.(e)},[Oe]),ot=(0,w.useMemo)(()=>({sessionId:e?.sessionId,scope:D,projectId:fe}),[e?.sessionId,D,fe]),st=ze(ot),ct=(0,w.useRef)(ot),lt=(0,w.useRef)(st);(0,w.useEffect)(()=>{ct.current=ot,lt.current=st},[ot,st]),(0,w.useEffect)(()=>()=>{it(),Y()},[it,Y]);let ut=(0,w.useCallback)((e,t,n)=>{if(t.text.length===0){qe(e).catch(e=>a.error(`Failed to clear composer draft:`,e));return}Ke(e,t,n).catch(e=>a.error(`Failed to save composer draft:`,e))},[]),dt=(0,w.useCallback)((e,t,n)=>{G.current&&window.clearTimeout(G.current),G.current=window.setTimeout(()=>{G.current=void 0,ut(e,t,n)},400)},[ut]),ft=(0,w.useCallback)((e,t=lt.current,n=ct.current)=>{let r=le(e);c(r)?H.current.set(t,r):H.current.delete(t),ut(t,r,n)},[ut]),X=(0,w.useRef)({onCopyAnswer:k,onRollbackFromMessage:O,onRetryFromMessage:he,onForkFromMessage:ge,onAccessModeChange:pe,onTogglePlanMode:nt,onApproveToolCall:be,onRejectToolCall:A,onAnswerAsk:xe,onApproveAutoCompact:Se,onRejectAutoCompact:j,onOpenWorkspaceGitChanges:M,onOpenLocalFilePath:Ce,onArtifactsChange:N,onContextUsageDisplayChange:Te,onInitialRenderReady:Ee,onInitialRenderError:De,onModelSelect:t,agentAccessMode:C,planMode:et,workspaceToolsEnabled:T,disableFork:ke,readOnly:Ae,approvalReadOnly:F,approvalReadOnlyMessage:I,allowModelControls:R,newChatEmptyState:z,bypassClientApiKeyCheck:L,rollbackConfirmTitle:B,rollbackConfirmDescription:Ne,capabilities:J,gitBranch:We});(0,w.useEffect)(()=>{X.current={onCopyAnswer:k,onRollbackFromMessage:O,onRetryFromMessage:he,onForkFromMessage:ge,onAccessModeChange:pe,onTogglePlanMode:nt,onApproveToolCall:be,onRejectToolCall:A,onAnswerAsk:xe,onApproveAutoCompact:Se,onRejectAutoCompact:j,onOpenWorkspaceGitChanges:M,onOpenLocalFilePath:Ce,onArtifactsChange:N,onContextUsageDisplayChange:Te,onInitialRenderReady:Ee,onInitialRenderError:De,onModelSelect:t,agentAccessMode:C,planMode:et,workspaceToolsEnabled:T,disableFork:ke,readOnly:Ae,approvalReadOnly:F,approvalReadOnlyMessage:I,allowModelControls:R,newChatEmptyState:z,bypassClientApiKeyCheck:L,rollbackConfirmTitle:B,rollbackConfirmDescription:Ne,capabilities:J,gitBranch:We},Ie.current=P});let pt=E?.id??fe;(0,w.useEffect)(()=>{let e=!1;return queueMicrotask(()=>{if(!e){if(!pt){$e(void 0);return}p(pt).then(t=>{e||$e(t.isGitRepository?t.branch:void 0)}).catch(t=>{e||(a.warn(`Failed to load git branch:`,t),$e(void 0))})}}),()=>{e=!0}},[pt,n]);let mt=(0,w.useRef)(null),ht=(0,w.useRef)(null),Z=(0,w.useRef)(null),Q=(0,w.useRef)(null),$=(0,w.useRef)(null),gt=(0,w.useRef)(null);(0,w.useEffect)(()=>{let e=!1;return!J.commands||!E?.id?(Le.current=[],()=>{e=!0}):(fetch(`/api/project/commands?projectId=${encodeURIComponent(E.id)}`,{cache:`no-store`}).then(e=>e.ok?e.json():{commands:[]}).then(t=>{e||(Le.current=Array.isArray(t.commands)?t.commands:[],Z.current?.())}).catch(()=>{e||(Le.current=[],Z.current?.())}),()=>{e=!0})},[E?.id,n,J.commands]);let _t=(0,w.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]:[]}:H.current.get(r),o=U.current;if(!(o?.id!==t.id||!c(a??f())||a?.text===o.text))return;Ue.current.invalidate(),Y();let s=e.querySelector(`agent-interface`);K.current=y(e,t,H.current,r,{shouldApply:()=>!W.current.has(t.id)&&e.isConnected&&!!V.current?.contains(e),onApplyStart:()=>{q.current=!0},onApplyEnd:()=>{q.current=!1},onApplied:()=>{Be.current.add(e),Fe.current=t.id,U.current={id:t.id,text:t.text},at(t.id)},updateComplete:s?.updateComplete})},[Y,at]);return(0,w.useEffect)(()=>{if(!V.current||!e)return;let t=Ue.current,n=Be.current,p=new r;tt(!1);let m=e.sessionId,g=lt.current,le=ct.current,C=!1,w,T=!1,E=!1,fe=!1,D=e.state.isStreaming,pe=!1,O=0,he,k=me({enabled:!1});_e(()=>k);let ge=!1,be=()=>{if(C||ge||!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;ge=!0,e.messages=s;let c=()=>{window.requestAnimationFrame(()=>{if(ge=!1,!C){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=de({panel:p,onReachTop:()=>{be()},onAutoScrollEnabled:()=>{k.resetToTail()}});ht.current=A;let xe=oe({panel:p,onJumpSettled:()=>{let e=p.querySelector(`agent-interface .overflow-y-auto`);e&&e.scrollHeight-e.scrollTop-e.clientHeight<=120&&A.enable()}}),Se=null,j=ye({panel:p,getCustomCommands:()=>Le.current,getComposerDrafts:()=>H.current,sessionId:g,setComposerDrafts:e=>{H.current=e},restoreDraftIntoComposer:e=>{ue(p,e,H.current,g),dt(g,e,le)}}),M=we({panel:p,enabled:J.capabilitySuggestions,restoreDraftIntoComposer:e=>{ue(p,e,H.current,g),dt(g,e,le)}}),Ce=u({panel:p,getSystemPrompt:()=>e.state.systemPrompt,getMessages:()=>e.state.messages,getEffectiveMessages:()=>Ze(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)}),N=ce({panel:p,getAcpSession:()=>e.state.acpSession??null}),Te=()=>{if(q.current)return;fe=!0,t.invalidate(),Y();let e=Ie.current;e&&(!e.sessionId||e.sessionId===m)&&at(e.id)},Ee=e=>{Te(),T=!1;let t=p.querySelector(`message-editor`),n={text:e,attachments:t?.attachments?[...t.attachments]:[]};c(n)?(H.current.set(g,n),dt(g,n,le)):(H.current.delete(g),it(),qe(g).catch(e=>a.error(`Failed to clear composer draft:`,e)))},De=e=>{Te(),T=!1;let t=p.querySelector(`message-editor`),n=t?.querySelector(`textarea`),r={text:t?.value??n?.value??``,attachments:e?[...e]:[]};c(r)?(H.current.set(g,r),dt(g,r,le)):(H.current.delete(g),it(),qe(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?.())},P=()=>{e.state.isStreaming?p.dataset.quickforgeAgentStreaming=`true`:delete p.dataset.quickforgeAgentStreaming},Oe=!1,ke=()=>{if(C||Oe)return;Oe=!0;let t=()=>{if(Oe=!1,C)return;let t=Re(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!==Ve.current&&(Ve.current=n,X.current.onArtifactsChange?.(t))};typeof window.requestIdleCallback==`function`?window.requestIdleCallback(t,{timeout:500}):t()},Ae=()=>{if(C||!p.isConnected)return;P();let t=()=>k.isEnabled()?k.getWindowMessages():e.state.messages,n=k.isEnabled()?k.getWindowStart():0,r=X.current,i=Qe(e.state.messages);i!==He.current&&(He.current=i,ke());try{v({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}),ee({panel:p,getMessages:t,getContextCompaction:()=>r.capabilities.compaction?e.state.contextCompaction??null:null,messageIndexOffset:n}),b({panel:p,isDegraded:()=>e.state.persistDegraded===!0}),te({panel:p,getMessages:t,isStreaming:()=>e.state.isStreaming,isActive:D})}catch(e){a.warn(`Failed to decorate chat messages:`,e)}try{ie({panel:p,isStreaming:()=>e.state.isStreaming,isWaiting:()=>D,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:Ee,onFilesChange:De,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;S({panel:p,tone:`warning`,disabled:r.approvalReadOnly,disabledReason:r.approvalReadOnlyMessage,onApprove:async()=>{await X.current.onApproveToolCall(t),Q.current=null,e.state.pendingToolApproval=null,x(p)},onReject:async()=>{await X.current.onRejectToolCall(t),Q.current=null,e.state.pendingToolApproval=null,x(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;S({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,x(p)},onReject:async()=>{let t=X.current.onRejectAutoCompact;if(!t)throw Error(l(`autoCompactApprovalUnavailable`));await t(i),$.current=null,e.state.pendingAutoCompactApproval=null,x(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 x(p)}let s=gt.current??(()=>{let t=e.state.pendingAsk;return t?{...t,sessionId:e.sessionId}:null})();if(s&&s.sessionId===e.sessionId&&typeof s.askId==`string`&&Array.isArray(s.questions)&&s.questions.length>0){let e=s.askId;ae({panel:p,disabled:r.approvalReadOnly||!X.current.onAnswerAsk,disabledReason:r.approvalReadOnly?r.approvalReadOnlyMessage:void 0,onSubmit:async t=>{await X.current.onAnswerAsk?.(e,t,!1),gt.current=null,re(p)},onSkip:async()=>{await X.current.onAnswerAsk?.(e,[],!0),gt.current=null,re(p)}},s)}else re(p);r.capabilities.contextUsage?Ce.update():Ce.cleanup(),e.harness===`opencode`&&N.update(),Se?.update(),A.setup(),xe.setup(),A.isEnabled&&(k.resetToTail(),A.scheduleScrollToBottom())},F=!1,I,L=!1,R,z=()=>{R===void 0&&(R=window.requestAnimationFrame(()=>{R=void 0,L=!1}))},B=()=>{if(!C){L=!0;try{Ae()}finally{z()}}},Ne=()=>{F||(F=!0,I=window.requestAnimationFrame(()=>{I=void 0,F=!1,B()}))};mt.current=B;let Pe=()=>p.querySelector(`agent-interface`),U=()=>{pe||(pe=!0,window.requestAnimationFrame(()=>{if(pe=!1,C)return;P();let e=Pe();e?.requestUpdate?.(),(e?.updateComplete??Promise.resolve()).then(()=>{C||B()}),A.isEnabled&&A.scheduleScrollToBottom()}))};Z.current=Ne;let W=()=>{let e=++O;p.dataset.quickforgeProcessHandoff=String(e);let t=Pe();t?.requestUpdate?.(),Z.current?.(),window.requestAnimationFrame(()=>{!C&&O===e&&Z.current?.()});let n=()=>{C||O!==e||(delete p.dataset.quickforgeProcessHandoff,Z.current?.(),window.requestAnimationFrame(()=>{!C&&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=Ie.current;e&&(!e.sessionId||e.sessionId===m)&&at(e.id),it(),T=!0,j.remove(),H.current.delete(g),qe(g).catch(e=>a.error(`Failed to clear composer draft:`,e)),A.enable()},onModelSelect:X.current.onModelSelect,toolsFactory:()=>se(e.state.tools)}).then(()=>{if(C)return;let e=Ie.current,n=t.version(),r=r=>{if(!(C||!t.isCurrent(n)))if(e&&Fe.current!==e.id)_t(p,e,m,g);else{let e=r??H.current.get(g)??f();c(e)||(E=!0),Y();let i=p.querySelector(`agent-interface`);K.current=y(p,e,H.current,g,{shouldApply:()=>!C&&t.isCurrent(n)&&p.isConnected&&!!V.current?.contains(p),onApplyStart:()=>{q.current=!0},onApplyEnd:()=>{q.current=!1},onApplied:()=>{E=!0,Be.current.add(p)},updateComplete:i?.updateComplete})}};if(e&&Fe.current!==e.id)r();else{let e=H.current.get(g);e?r(e):Ge(g).then(e=>r(e)).catch(e=>a.error(`Failed to load composer draft:`,e))}w=new MutationObserver(()=>{L||Ne()}),w.observe(p,{childList:!0,subtree:!0}),window.requestAnimationFrame(()=>{C||B()});let i=Pe(),o=()=>{C||(he=d(()=>{C||X.current.onInitialRenderReady?.(m)}))};(i?.updateComplete??Promise.resolve()).then(o,o)},e=>{C||(a.error(`Failed to initialize chat panel:`,e),X.current.onInitialRenderError?.(m,e))}),V.current.replaceChildren(p),Me&&(Se=je({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,D=!0,P(),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`){P();let e=t.message;t.type===`message_start`&&e?.role===`assistant`&&(O+=1,delete p.dataset.quickforgeProcessHandoff,xe.notifyNewAssistantMessage()),(t.type===`message_update`||e?.role===`assistant`)&&(D=!1),Z.current?.(),t.type===`message_end`&&e?.role===`assistant`&&W(),A.isEnabled&&A.scheduleScrollToBottom()}if(t.type===`messages_replaced`){let e=Ie.current;e&&Fe.current===e.id&&_t(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`)&&U(),(n===`acp_session_update`||n===`acp_session_usage_update`)&&Z.current?.(),n===`persist_degraded`&&Z.current?.(),t.type===`agent_end`&&(D=!1,P(),W(),Q.current?.sessionId===e.sessionId&&(Q.current=null,Z.current?.()),gt.current?.sessionId===e.sessionId&&(gt.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`){ne(p);let e=Pe();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===`ask_user_required`){let n=t;typeof n.askId==`string`&&Array.isArray(n.questions)&&(gt.current={...n,sessionId:n.sessionId??e.sessionId},Z.current?.())}if(t.type===`ask_user_answered`){let e=t;(!e.askId||gt.current?.askId===e.askId)&&(gt.current=null,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()=>{C=!0,t.invalidate(),Y(),it(),he?.(),T?(H.current.delete(g),qe(g).catch(e=>a.error(`Failed to clear composer draft:`,e))):(E||fe||n.has(p))&&(_(p,H.current,g),ft(p,g,le)),j.remove(),j.cleanupTextareaHandler(),M.remove(),M.cleanupTextareaHandler(),Ce.cleanup(),N.cleanup(),Se?.cleanup(),A.cleanup(),ht.current=null,xe.cleanup(),ve(k),G(),w?.disconnect(),I!==void 0&&window.cancelAnimationFrame(I),R!==void 0&&window.cancelAnimationFrame(R),mt.current=null,p.remove()}},[e,Me,J.capabilitySuggestions,it,Y,at,ft,_t,dt]),(0,w.useEffect)(()=>{let e=V.current;e&&(e.classList.toggle(`quickforge-chat-panel-empty-host`,z),e.dataset.quickforgeEmptyChat=z?`true`:`false`)},[z]),(0,w.useEffect)(()=>{mt.current?.(),(V.current?.querySelector(`agent-interface`))?.requestUpdate?.()},[C,et,T,We,ke,Ae,F,I,R,Pe,n]),(0,w.useEffect)(()=>{let t=Ie.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&&_t(r,t,n,lt.current)},[P,e,_t]),(0,Xe.jsx)(`div`,{ref:V,className:`quickforge-chat-panel-host min-h-0 flex-1 overflow-hidden`})}export{$e as ChatPanelHost};
|
|
@@ -1 +0,0 @@
|
|
|
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,Fn as c,G as ue,H as de,In as l,J as fe,K as pe,Ln as u,Mn as d,Nn as me,Q as he,Tt as f,U as ge,W as p,X as _e,Y as ve,Z as ye,at as m,et as be,it as xe,nt as Se,q as Ce,rt as we,tt as Te}from"./index-D3GWkXJR.js";var h=e(n(),1);function g(e,t=`cloudRequestFailed`){return e instanceof p?e.code===`cloud_session_active`?u(`cloudSessionActiveGuidance`):e.code===`cloud_disabled`?u(`cloudDisabledError`):e.code===`cloud_local_only`?u(`cloudLocalOnlyError`):e.code===`cloud_configuration_error`||e.code===`cloud_not_configured`?u(`cloudConfigurationError`):e.code===`cloud_session_service_mismatch`?u(`cloudSessionServiceMismatch`):[`expired_token`,`device_code_expired`,`expired`].includes(e.code)?u(`cloudDeviceFlowExpiredError`):[`access_denied`,`authorization_declined`,`denied`].includes(e.code)?u(`cloudDeviceFlowDeniedError`):[`refresh_token_reused`,`installation_revoked`,`invalid_refresh_token`,`cloud_not_connected`].includes(e.code)?u(`cloudSessionExpired`):c()===`en`&&e.message.trim()?e.message:e.status>0?u(`cloudRequestFailedWithStatus`,{status:e.status}):u(t):u(t)}var Ee={usage:void 0,installations:[],models:[],errors:{},loading:!1};function De(e,t){return t.type===`replace`?t.state:{...Ee,loading:t.type===`begin`}}async function Oe(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 ke({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 Ae(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 je(e){return e===`starting`||e===`authorizing`}function Me(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 Ne(e,t){return!!(e?.hasSession&&(t||e.sessionServiceMismatch))}async function Pe(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 _=s();function v(e){if(!e)return u(`cloudNotAvailable`);let t=new Date(e);return Number.isNaN(t.getTime())?u(`cloudNotAvailable`):t.toLocaleString(l())}function y(e){let t=e.id||e.installationId;return typeof t==`string`?t:``}function b(e){let t=e.name||e.installationName;return typeof t==`string`&&t?t:u(`cloudUnnamedDevice`)}function Fe(e){return typeof e==`number`&&Number.isFinite(e)?e.toLocaleString(l()):u(`cloudNotAvailable`)}function Ie(e){return u(e===`saved`?`cloudConfigSourceSaved`:e===`env`?`cloudConfigSourceEnv`:`cloudConfigSourceDefault`)}function x(e){let t=String(e||``).toLowerCase();return t===`localhost`||t.endsWith(`.localhost`)||t.startsWith(`127.`)?!0:t===`::1`}function S(e){let t=e.trim();if(!t)return``;let n;try{n=new URL(t)}catch{return u(`cloudUrlInvalid`)}return n.protocol!==`https:`&&n.protocol!==`http:`?u(`cloudUrlInvalidProtocol`):x(n.hostname)&&n.port===`8081`?u(`cloudUrlAdminPort`):``}function C(e){if(!e||typeof e!=`object`)return u(`cloudConnectionUnknown`);let t=e;return t.ok===!0||t.status===`ok`||t.ready===!0?u(`cloudConnectionOk`):u(`cloudConnectionError`)}function w(e){if(!e||typeof e!=`object`)return!1;let t=e;return t.ok===!0||t.status===`ok`||t.ready===!0}function Le(e,t){let n=C(t);return(0,_.jsxs)(`span`,{className:me(`quickforge-settings-badge`,n===u(`cloudConnectionUnknown`)?`quickforge-settings-badge-muted`:w(t)?`quickforge-settings-badge-success`:`quickforge-settings-badge-danger`),children:[e,`: `,n]})}function Re(e){let t=e.quickforgeCapabilities;return[t?.tools?u(`cloudCapabilityTools`):void 0,t?.vision?u(`cloudCapabilityVision`):void 0,t?.reasoning?u(`cloudCapabilityReasoning`):void 0].filter(Boolean).join(` · `)||u(`cloudCapabilityText`)}function ze(e){return u(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 Be(e,t){let n=e===`usage`?`cloudUsageLoadFailed`:e===`installations`?`cloudDevicesLoadFailed`:`cloudModelsLoadFailed`,r=g(t);return{message:r===u(`cloudRequestFailed`)?u(n):r,unavailable:!(`code`in Object(t))||[`cloud_request_failed`,`cloud_unavailable`].includes(String(t?.code||``))}}function T({error:e,onRetry:t,disabled:n}){return(0,_.jsxs)(`div`,{className:`p-4 text-sm`,children:[(0,_.jsx)(`div`,{className:`quickforge-settings-error`,children:e.message}),(0,_.jsxs)(d,{type:`button`,variant:`outline`,size:`sm`,className:`mt-3`,onClick:t,disabled:n,children:[(0,_.jsx)(o,{className:`mr-2 size-4`}),u(`retry`)]})]})}function E(){let[e,n]=(0,h.useState)(),[s,c]=(0,h.useState)(``),[l,p]=(0,h.useState)(!1),[x,C]=(0,h.useState)(),[w,E]=(0,h.useState)(),[D,Ve]=(0,h.useState)(),[O,k]=(0,h.useReducer)(De,Ee),[A,He]=(0,h.useState)(!0),[j,M]=(0,h.useState)(``),[Ue,N]=(0,h.useState)(``),[P,F]=(0,h.useState)(``),[We,I]=(0,h.useState)(``),[Ge,Ke]=(0,h.useState)(0),L=(0,h.useRef)(0),R=(0,h.useRef)(0),z=w?.pendingDeviceFlow,B=z?Math.max(0,Math.ceil((z.expiresAt-Ge)/1e3)):0,V=(0,h.useCallback)(()=>k({type:`clear`}),[]),H=(0,h.useCallback)(async()=>{let e=++R.current;try{let t=await ve();e===R.current&&Ve(t)}catch{}},[]),U=(0,h.useCallback)(async(e=!0,t=!1,r=!0)=>{let i=++L.current;e&&He(!0),F(``),k({type:`begin`}),r&&H();try{let[e,r]=await Promise.all([pe(),_e()]);if(i!==L.current)return;if(n(e),t||c(e.cloudUrl),E(r),!e.enabled||!r.configured||!r.hasSession||r.sessionServiceMismatch){V();return}let a=await Oe({usage:ye,installations:Ce,models:fe},Be);if(i!==L.current)return;k({type:`replace`,state:a})}catch(e){if(i!==L.current)return;n(void 0),E(void 0),V(),F(g(e,`cloudLoadFailed`))}finally{i===L.current&&He(!1)}},[V,H]);(0,h.useEffect)(()=>{let e=window.setTimeout(()=>{U()},0);return()=>{window.clearTimeout(e),L.current+=1,R.current+=1}},[U]),(0,h.useEffect)(()=>{if(!e?.enabled||!je(D?.status))return;let t=window.setInterval(()=>{H()},1750);return()=>window.clearInterval(t)},[e?.enabled,H,D?.status]),(0,h.useEffect)(()=>{let e=()=>{document.visibilityState===`visible`&&H()};return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[H]),(0,h.useEffect)(()=>{if(!e?.enabled||!w?.pendingDeviceFlow)return;let t=()=>Ke(Date.now()),n=window.setTimeout(t,0),r=window.setInterval(t,1e3);return()=>{window.clearTimeout(n),window.clearInterval(r)}},[e?.enabled,w?.pendingDeviceFlow]),(0,h.useEffect)(()=>{let t=w?.pendingDeviceFlow;if(!e?.enabled||!t||B>0)return;let n=window.setTimeout(()=>{U(!1)},0);return()=>window.clearTimeout(n)},[e?.enabled,B,U,w?.pendingDeviceFlow]),(0,h.useEffect)(()=>{let t=w?.pendingDeviceFlow;if(!e?.enabled||!t||j===`device-start`||j===`device-cancel`)return;let n=Math.max(1,Number(t.interval)||5)*1e3,r=window.setTimeout(async()=>{try{let e=await le();E(e),e.deviceFlowResult===`success`?(window.dispatchEvent(new Event(ge)),F(``),N(u(`cloudDeviceFlowSucceeded`)),await Promise.all([U(!1,!1,!1),H()])):e.deviceFlowResult===`denied`?F(u(`cloudDeviceFlowDenied`)):e.deviceFlowResult===`expired`?F(u(`cloudDeviceFlowExpired`)):e.deviceFlowResult===`network`&&F(u(`cloudDeviceFlowNetwork`))}catch(e){F(g(e))}},n);return()=>window.clearTimeout(r)},[j,e?.enabled,U,H,w?.pendingDeviceFlow]);let W=()=>window.dispatchEvent(new Event(ge)),qe=async()=>{if(!j){if(S(s)){p(!0);return}M(`test`),N(``),F(``),C(void 0);try{let e=await xe(s);c(e.cloudUrl),C(e),N(u(`cloudConnectionTestSucceeded`))}catch(e){F(g(e,`cloudConnectionFailed`))}finally{M(``)}}},Je=async()=>{if(!j){if(S(s)){p(!0);return}M(`save`),N(``),F(``);try{let e=await m({cloudUrl:s});n(e),c(e.cloudUrl),C(void 0),I(``),W(),N(u(`cloudConnectionSaved`)),await U(!1)}catch(e){F(g(e))}finally{M(``)}}},Ye=async t=>{if(!(j||!e||e.enabled===t)){M(`cloud-toggle`),N(``),F(``),I(``);try{let e=await m({enabled:t});n(e),c(e.cloudUrl),C(void 0),e.enabled||V(),W(),N(u(e.enabled?`cloudServiceEnabledSaved`:`cloudServiceDisabledSaved`)),await U(!1)}catch(e){F(g(e))}finally{M(``)}}},Xe=async()=>{let t=s.trim()||e?.cloudUrl||``;if(S(t)){p(!0);return}if(!(!await f({title:u(`cloudForceSwitchTitle`),description:u(`cloudForceSwitchDescription`),confirmLabel:u(`cloudForceSwitchConfirm`),cancelLabel:u(`cancel`),variant:`destructive`})||j||!t)){M(`force-switch`),N(``),F(``),I(``);try{let e=await Pe(t,{reset:be,save:e=>m({cloudUrl:e}),onIdentityReset:()=>{L.current+=1,E(e=>e&&{...e,mode:`local`,hasSession:!1,sessionServiceMismatch:!1}),V(),W()}});if(e.status===`url-save-failed`){let t=g(e.error);I(u(`cloudIdentityRebuiltUrlSaveFailed`)),await U(!1,!0),F(t);return}n(e.config),c(e.config.cloudUrl),C(void 0),W(),N(u(`cloudForceSwitchSucceeded`)),await U(!1)}catch(e){F(g(e))}finally{M(``)}}},Ze=async()=>{if(!j){M(`device-start`),N(``),F(``),I(``);try{E(await we()),W()}catch(e){F(g(e))}finally{M(``)}}},Qe=async()=>{if(!j){M(`device-cancel`),N(``),F(``);try{E(await ue()),N(u(`cloudDeviceFlowCancelled`))}catch(e){F(g(e))}finally{M(``)}}},$e=async()=>{if(!j){M(`remote-authorize-retry`),N(``),F(``);try{let e=await Te();H(),e.status===`failed`?F(e.error||u(`cloudRemoteAutoApprovalFailed`)):N(u(`cloudRemoteAutoApprovalRetried`))}catch(e){F(g(e))}finally{M(``)}}},et=async()=>{let e=w?.pendingDeviceFlow?.userCode;if(e)try{await navigator.clipboard.writeText(e),N(u(`cloudDeviceCodeCopied`))}catch{F(u(`copyFailed`))}},tt=async()=>{if(!(!await f({title:u(`cloudLogoutTitle`),description:u(`cloudLogoutDescription`),confirmLabel:u(`cloudLogout`),cancelLabel:u(`cancel`),variant:`destructive`})||j)){M(`logout`),N(``),F(``),I(``);try{await he(),L.current+=1,V(),E(e=>e&&{...e,mode:`local`,hasSession:!1,sessionServiceMismatch:!1}),W(),N(u(`cloudLoggedOut`)),await U(!1)}catch(e){F(g(e))}finally{M(``)}}},nt=async e=>{let t=y(e);if(!(!t||t===w?.installationId||j)&&await f({description:u(`cloudRevokeDeviceConfirm`,{name:b(e)}),confirmLabel:u(`cloudRevokeDevice`),cancelLabel:u(`cancel`),variant:`destructive`})){M(t),N(``),F(``);try{await Se(t),k({type:`replace`,state:{...O,installations:O.installations.filter(e=>y(e)!==t)}}),N(u(`cloudDeviceRevoked`))}catch(e){F(g(e))}finally{M(``)}}},G=e?.enabled===!0,rt=!!(w?.configured&&w.hasSession),K=w?.sessionServiceMismatch===!0,q=rt&&!K,J=!!(e?.cloudUrl&&s.trim()&&e.cloudUrl!==s.trim()),Y=S(s),X=!!(Y&&l),it=ke({loading:A,loadError:P,status:w,details:O}),at=Ae(w),Z=it===`cloud-unavailable`,ot=K?u(`cloudSessionMismatchLabel`):w?.mode===`account`?u(`cloudFormalAccount`):u(`cloudNotConnected`),st=ze(D?.status),ct=D?.status===`running`?`quickforge-settings-badge-success`:D?.status===`authorizing`||D?.status===`starting`?`quickforge-settings-badge-info`:D?.status===`error`||D?.status===`conflict`?`quickforge-settings-badge-warning`:`quickforge-settings-badge-muted`,Q=Me(D),lt=G?w?.configured?u(K?`cloudSessionServiceMismatch`:q?Z?`cloudUnavailableDescription`:`cloudConnectedDescription`:`cloudLocalOnlyDescription`):u(`cloudNotConfiguredDescription`):u(`cloudServiceDisabledDescription`),ut=()=>{U()},$=A||O.loading,dt=new Map;for(let e of O.installations){let t=b(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,_.jsxs)(`div`,{className:`quickforge-settings-stack`,children:[(0,_.jsxs)(`div`,{className:`quickforge-settings-heading`,children:[(0,_.jsx)(`div`,{children:(0,_.jsxs)(`h2`,{className:`quickforge-settings-title`,children:[(0,_.jsx)(i,{className:`size-5`}),u(`cloudAccount`)]})}),(0,_.jsxs)(d,{variant:`outline`,size:`sm`,onClick:()=>void U(),disabled:A||!!j,className:`quickforge-settings-heading-action`,children:[(0,_.jsx)(o,{className:`mr-2 size-4 ${A?`animate-spin`:``}`}),u(`refresh`)]})]}),Ue?(0,_.jsx)(`div`,{className:`quickforge-settings-message`,children:Ue}):null,We?(0,_.jsx)(`div`,{className:`quickforge-settings-warning`,children:We}):null,P?(0,_.jsx)(`div`,{className:`quickforge-settings-error`,children:P}):null,(0,_.jsxs)(`div`,{className:`quickforge-settings-section`,children:[(0,_.jsxs)(`div`,{className:`quickforge-settings-list-header`,children:[(0,_.jsxs)(`div`,{className:`quickforge-settings-row-title`,children:[(0,_.jsx)(oe,{className:`size-4`}),u(`cloudServiceConnection`)]}),(0,_.jsx)(`span`,{className:`quickforge-settings-badge quickforge-settings-badge-info shrink-0`,children:`QuickForge Cloud`})]}),(0,_.jsxs)(`div`,{className:`quickforge-settings-row`,children:[(0,_.jsxs)(`div`,{className:`quickforge-settings-row-main`,children:[(0,_.jsx)(`div`,{className:`quickforge-settings-row-title`,children:u(`cloudServiceEnabled`)}),(0,_.jsx)(`div`,{className:`quickforge-settings-row-description`,children:u(`cloudServiceEnabledDescription`)})]}),(0,_.jsx)(`div`,{className:`quickforge-settings-row-control`,children:(0,_.jsxs)(`label`,{className:`quickforge-settings-switch`,"aria-label":u(`cloudServiceEnabled`),children:[(0,_.jsx)(`input`,{type:`checkbox`,checked:G,disabled:!e||!!j,onChange:e=>{Ye(e.target.checked)}}),(0,_.jsx)(`span`,{"aria-hidden":`true`})]})})]}),(0,_.jsxs)(`div`,{className:`quickforge-settings-row items-start`,children:[(0,_.jsx)(`div`,{className:`quickforge-settings-row-main`,children:(0,_.jsx)(`label`,{className:`quickforge-settings-row-title h-9 whitespace-nowrap`,htmlFor:`quickforge-cloud-url`,children:u(`cloudUrl`)})}),(0,_.jsxs)(`div`,{className:`quickforge-settings-row-control w-full max-w-xl flex-col items-stretch gap-2`,children:[(0,_.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,_.jsx)(de,{id:`quickforge-cloud-url`,value:s,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Enter`&&s.trim()&&J&&!j&&(e.preventDefault(),Je())},placeholder:u(`cloudUrlPlaceholder`),inputMode:`url`,autoCapitalize:`none`,autoCorrect:`off`,spellCheck:!1,onBlur:()=>p(!0),"aria-invalid":X,className:me(`min-w-0 flex-1`,X?`border-destructive`:void 0),disabled:!!j}),(0,_.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[(0,_.jsxs)(d,{variant:`outline`,size:`sm`,onClick:()=>void qe(),disabled:!s.trim()||!!Y||!!j,children:[j===`test`?(0,_.jsx)(o,{className:`mr-2 size-4 animate-spin`}):(0,_.jsx)(ne,{className:`mr-2 size-4`}),u(`cloudTestConnection`)]}),(0,_.jsxs)(d,{size:`sm`,onClick:()=>void Je(),disabled:!s.trim()||!J||!!Y||!!j,children:[j===`save`?(0,_.jsx)(o,{className:`mr-2 size-4 animate-spin`}):(0,_.jsx)(ce,{className:`mr-2 size-4`}),u(`saveChanges`)]})]})]}),X?(0,_.jsx)(`div`,{className:`text-xs text-destructive`,children:Y}):null,(0,_.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[u(`cloudConfigSource`),`: `,Ie(e?.source)]}),Ne(w,J)&&!Y?(0,_.jsx)(`div`,{className:`quickforge-settings-cloud-force-switch flex justify-end`,children:(0,_.jsxs)(d,{variant:`destructive`,size:`sm`,onClick:()=>void Xe(),disabled:!!j,title:u(`cloudForceSwitchDescription`),children:[(0,_.jsx)(t,{className:`mr-2 size-4`}),u(`cloudForceSwitch`)]})}):null]})]}),e?.configurationError?(0,_.jsx)(`div`,{className:`quickforge-settings-error m-3`,children:u(`cloudConfigurationError`)}):null,x?(0,_.jsxs)(`div`,{className:`quickforge-settings-row`,children:[(0,_.jsxs)(`div`,{className:`quickforge-settings-row-main`,children:[(0,_.jsx)(`div`,{className:`quickforge-settings-row-title`,children:u(`cloudConnectionTestResult`)}),(0,_.jsx)(`div`,{className:`quickforge-settings-row-description break-all`,children:x.cloudUrl})]}),(0,_.jsxs)(`div`,{className:`quickforge-settings-row-control flex-wrap justify-end gap-1.5`,children:[Le(u(`cloudHealth`),x.health),Le(u(`cloudReady`),x.ready)]})]}):null]}),G?(0,_.jsxs)(`div`,{className:`quickforge-settings-section`,children:[(0,_.jsxs)(`div`,{className:`quickforge-settings-row`,children:[(0,_.jsxs)(`div`,{className:`quickforge-settings-row-main`,children:[(0,_.jsxs)(`div`,{className:`quickforge-settings-row-title`,children:[(0,_.jsx)(a,{className:`size-4`}),u(`cloudRemoteAccess`)]}),(0,_.jsx)(`div`,{className:`quickforge-settings-row-description`,children:u(`cloudRemoteAccessDescription`)})]}),(0,_.jsx)(`div`,{className:`quickforge-settings-row-control`,children:(0,_.jsx)(`span`,{className:`quickforge-settings-badge ${ct}`,children:st})})]}),D?.serverUrl?(0,_.jsxs)(`div`,{className:`quickforge-settings-row`,children:[(0,_.jsx)(`div`,{className:`quickforge-settings-row-main`,children:(0,_.jsx)(`div`,{className:`quickforge-settings-row-title`,children:u(`cloudRemoteServerUrl`)})}),(0,_.jsx)(`div`,{className:`quickforge-settings-row-control break-all text-sm text-muted-foreground`,children:D.serverUrl})]}):null,D?.pid?(0,_.jsxs)(`div`,{className:`quickforge-settings-row`,children:[(0,_.jsx)(`div`,{className:`quickforge-settings-row-main`,children:(0,_.jsx)(`div`,{className:`quickforge-settings-row-title`,children:u(`cloudRemotePid`)})}),(0,_.jsx)(`div`,{className:`quickforge-settings-row-control text-sm font-medium`,children:D.pid})]}):null,D?.status===`authorizing`?(0,_.jsxs)(`div`,{className:`quickforge-settings-row items-start`,children:[(0,_.jsxs)(`div`,{className:`quickforge-settings-row-main`,children:[(0,_.jsx)(`div`,{className:`quickforge-settings-row-title`,children:u(`cloudRemoteAuthorization`)}),(0,_.jsx)(`div`,{className:`quickforge-settings-row-description`,children:Q.pending?u(`cloudRemoteAutoApprovalPending`):Q.failed?u(`cloudRemoteAutoApprovalFailed`):u(`cloudRemoteAutoApprovalNeedsLocalEnable`)}),Q.failed&&Q.failedError?(0,_.jsx)(`div`,{className:`quickforge-settings-warning quickforge-settings-warning-attached mt-1`,children:Q.failedError}):null]}),(0,_.jsx)(`div`,{className:`quickforge-settings-row-control flex-wrap gap-1.5`,children:Q.pending?(0,_.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:u(`cloudRemoteAutoApprovalWaiting`)}):Q.failed?(0,_.jsxs)(d,{variant:`outline`,size:`sm`,onClick:()=>void $e(),disabled:!!j,children:[(0,_.jsx)(o,{className:`mr-2 size-3.5`}),u(`cloudRemoteAutoApprovalRetry`)]}):null})]}):null,D?.error?(0,_.jsx)(`div`,{className:`quickforge-settings-warning quickforge-settings-warning-attached`,children:D.error}):null]}):null,(0,_.jsxs)(`div`,{className:`quickforge-settings-section`,children:[(0,_.jsxs)(`div`,{className:`quickforge-settings-row`,children:[(0,_.jsxs)(`div`,{className:`quickforge-settings-row-main`,children:[(0,_.jsxs)(`div`,{className:`quickforge-settings-row-title`,children:[(0,_.jsx)(re,{className:`size-4`}),u(`cloudIdentityStatus`)]}),(0,_.jsx)(`div`,{className:`quickforge-settings-row-description`,children:lt})]}),(0,_.jsx)(`div`,{className:`quickforge-settings-row-control`,children:(0,_.jsx)(`span`,{className:`quickforge-settings-badge ${q&&!Z?`quickforge-settings-badge-success`:K||Z?`quickforge-settings-badge-warning`:`quickforge-settings-badge-muted`}`,children:ot})})]}),Z?(0,_.jsx)(`div`,{className:`quickforge-settings-warning quickforge-settings-warning-attached`,children:u(`cloudUnavailableDescription`)}):null,K?(0,_.jsx)(`div`,{className:`quickforge-settings-warning quickforge-settings-warning-attached`,children:u(`cloudSessionServiceMismatch`)}):null,q?(0,_.jsxs)(_.Fragment,{children:[w?.mode===`account`?(0,_.jsxs)(_.Fragment,{children:[(0,_.jsxs)(`div`,{className:`quickforge-settings-row`,children:[(0,_.jsx)(`div`,{className:`quickforge-settings-row-main`,children:(0,_.jsx)(`div`,{className:`quickforge-settings-row-title`,children:u(`cloudAccountEmail`)})}),(0,_.jsx)(`div`,{className:`quickforge-settings-row-control text-sm font-medium`,children:w.account?.email||u(`cloudNotAvailable`)})]}),(0,_.jsxs)(`div`,{className:`quickforge-settings-row`,children:[(0,_.jsx)(`div`,{className:`quickforge-settings-row-main`,children:(0,_.jsx)(`div`,{className:`quickforge-settings-row-title`,children:u(`cloudAccountPlan`)})}),(0,_.jsx)(`div`,{className:`quickforge-settings-row-control text-sm font-medium`,children:w.account?.plan||u(`cloudNotAvailable`)})]})]}):null,G?O.errors.usage?(0,_.jsx)(T,{error:O.errors.usage,onRetry:ut,disabled:$||!!j}):(0,_.jsxs)(_.Fragment,{children:[(0,_.jsxs)(`div`,{className:`quickforge-settings-row`,children:[(0,_.jsx)(`div`,{className:`quickforge-settings-row-main`,children:(0,_.jsx)(`div`,{className:`quickforge-settings-row-title`,children:u(`cloudRemainingQuota`)})}),(0,_.jsx)(`div`,{className:`quickforge-settings-row-control text-sm font-medium`,children:Fe(O.usage?.remaining)})]}),(0,_.jsxs)(`div`,{className:`quickforge-settings-row`,children:[(0,_.jsx)(`div`,{className:`quickforge-settings-row-main`,children:(0,_.jsx)(`div`,{className:`quickforge-settings-row-title`,children:u(`cloudQuotaExpiresAt`)})}),(0,_.jsx)(`div`,{className:`quickforge-settings-row-control text-sm text-muted-foreground`,children:v(O.usage?.resetsAt||O.usage?.expiresAt)})]})]}):null,(0,_.jsxs)(`div`,{className:`quickforge-settings-row`,children:[(0,_.jsxs)(`div`,{className:`quickforge-settings-row-main`,children:[(0,_.jsx)(`div`,{className:`quickforge-settings-row-title`,children:u(`cloudLogout`)}),(0,_.jsx)(`div`,{className:`quickforge-settings-row-description`,children:u(`cloudLogoutRowDescription`)})]}),(0,_.jsx)(`div`,{className:`quickforge-settings-row-control`,children:(0,_.jsxs)(d,{variant:`destructive`,className:`quickforge-settings-cloud-logout`,onClick:()=>void tt(),disabled:!!j,children:[(0,_.jsx)(r,{className:`mr-2 size-4`}),u(`cloudLogout`)]})})]})]}):null]}),!G||!w?.configured?null:at.showDeviceFlow&&z?(0,_.jsxs)(`div`,{className:`quickforge-settings-section`,children:[(0,_.jsxs)(`div`,{className:`quickforge-settings-list-header`,children:[(0,_.jsxs)(`div`,{className:`quickforge-settings-row-main`,children:[(0,_.jsxs)(`div`,{className:`quickforge-settings-row-title`,children:[(0,_.jsx)(ee,{className:`size-4`}),u(`cloudDeviceFlowTitle`)]}),(0,_.jsx)(`div`,{className:`quickforge-settings-row-description`,children:u(`cloudDeviceFlowDescription`)})]}),(0,_.jsx)(`span`,{className:`quickforge-settings-badge quickforge-settings-badge-info`,children:u(`cloudDeviceFlowCountdown`,{seconds:B})})]}),(0,_.jsxs)(`div`,{className:`quickforge-settings-row items-start`,children:[(0,_.jsxs)(`div`,{className:`quickforge-settings-row-main`,children:[(0,_.jsx)(`div`,{className:`quickforge-settings-row-description`,children:u(`cloudDeviceCode`)}),(0,_.jsx)(`div`,{className:`mt-1 font-mono text-2xl font-semibold tracking-[0.18em] text-foreground`,children:z.userCode})]}),(0,_.jsxs)(`div`,{className:`quickforge-settings-row-control flex-wrap gap-2`,children:[(0,_.jsxs)(d,{variant:`outline`,size:`sm`,onClick:()=>void et(),children:[(0,_.jsx)(te,{className:`mr-2 size-4`}),u(`copy`)]}),(0,_.jsxs)(d,{size:`sm`,onClick:()=>window.open(z.verificationUriComplete||z.verificationUri,`_blank`,`noopener,noreferrer`),children:[(0,_.jsx)(ie,{className:`mr-2 size-4`}),u(`cloudOpenVerificationPage`)]}),(0,_.jsx)(d,{variant:`outline`,size:`sm`,onClick:()=>void Qe(),disabled:!!j,children:u(`cancel`)})]})]}),w.deviceFlowResult===`slow_down`?(0,_.jsx)(`div`,{className:`quickforge-settings-warning quickforge-settings-warning-attached`,children:u(`cloudDeviceFlowSlowDown`)}):null]}):at.showDisconnectedActions?(0,_.jsx)(`div`,{className:`quickforge-settings-section`,children:(0,_.jsxs)(`div`,{className:`quickforge-settings-row`,children:[(0,_.jsxs)(`div`,{className:`quickforge-settings-row-main`,children:[(0,_.jsxs)(`div`,{className:`quickforge-settings-row-title`,children:[(0,_.jsx)(ee,{className:`size-4`}),u(`cloudLoginOrRegister`)]}),(0,_.jsx)(`div`,{className:`quickforge-settings-row-description`,children:u(`cloudLoginOrRegisterDescription`)})]}),(0,_.jsx)(`div`,{className:`quickforge-settings-row-control`,children:(0,_.jsxs)(d,{onClick:()=>void Ze(),disabled:A||!!j,children:[(0,_.jsx)(ae,{className:`mr-2 size-4`}),u(`cloudLoginOrRegister`)]})})]})}):at.showDetails?(0,_.jsxs)(_.Fragment,{children:[(0,_.jsxs)(`div`,{className:`quickforge-settings-section`,children:[(0,_.jsx)(`div`,{className:`quickforge-settings-list-header`,children:(0,_.jsxs)(`div`,{className:`quickforge-settings-row-title`,children:[(0,_.jsx)(se,{className:`size-4`}),u(`cloudModels`)]})}),O.errors.models?(0,_.jsx)(T,{error:O.errors.models,onRetry:ut,disabled:$||!!j}):O.models.length===0?(0,_.jsx)(`div`,{className:`p-6 text-center text-sm text-muted-foreground`,children:u($?`loading`:`cloudNoModels`)}):O.models.map(e=>(0,_.jsx)(`div`,{className:`quickforge-settings-list-item`,children:(0,_.jsxs)(`div`,{className:`quickforge-settings-list-item-main`,children:[(0,_.jsx)(`div`,{className:`text-sm font-medium`,children:e.name||e.id}),(0,_.jsxs)(`div`,{className:`quickforge-settings-row-description`,children:[e.id,` · `,Re(e)]})]})},`${e.provider}:${e.id}`))]}),(0,_.jsxs)(`div`,{className:`quickforge-settings-section`,children:[(0,_.jsx)(`div`,{className:`quickforge-settings-list-header`,children:(0,_.jsxs)(`div`,{className:`quickforge-settings-row-title`,children:[(0,_.jsx)(a,{className:`size-4`}),u(`cloudDevices`)]})}),pt>1?(0,_.jsx)(`div`,{className:`quickforge-settings-warning quickforge-settings-warning-attached`,children:u(`cloudDuplicateDevicesHint`,{count:pt,name:ft[0][0]})}):null,O.errors.installations?(0,_.jsx)(T,{error:O.errors.installations,onRetry:ut,disabled:$||!!j}):O.installations.length===0?(0,_.jsx)(`div`,{className:`p-6 text-center text-sm text-muted-foreground`,children:u($?`loading`:`cloudNoDevices`)}):O.installations.map(e=>{let t=y(e),n=e.current===!0||t===w?.installationId;return(0,_.jsxs)(`div`,{className:`quickforge-settings-list-item`,children:[(0,_.jsxs)(`div`,{className:`quickforge-settings-list-item-main`,children:[(0,_.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,_.jsx)(`div`,{className:`truncate text-sm font-medium`,children:b(e)}),n?(0,_.jsx)(`span`,{className:`quickforge-settings-badge quickforge-settings-badge-info`,children:u(`cloudCurrentDevice`)}):null]}),(0,_.jsx)(`div`,{className:`quickforge-settings-row-description`,children:[e.platform,e.createdAt?`${u(`cloudRegisteredAt`)} ${v(e.createdAt)}`:void 0,e.lastSeenAt?`${u(`cloudLastSeenAt`)} ${v(e.lastSeenAt)}`:void 0,t?`#${t.slice(0,8)}`:void 0].filter(Boolean).join(` · `)||u(`cloudNotAvailable`)})]}),(0,_.jsx)(`div`,{className:`quickforge-settings-list-item-actions`,children:(0,_.jsx)(d,{variant:`outline`,size:`sm`,onClick:()=>void nt(e),disabled:n||!!j,children:u(`cloudRevokeDevice`)})})]},t||b(e))})]})]}):null]})}export{E as CloudAccountSettingsPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{E as t,Jt as n,X as r,b as i,bt as a,ht as o,j as s,mt as c,s as l,w as u}from"./icons-DM_qJ7VJ.js";import{n as d}from"./react-vendor-BpWW_Nvp.js";import{D as f,Dt as p,E as m,In as h,Ln as g,Mn as _,Tt as v,_ as y,b,g as x,v as S,w as C,x as w,y as T}from"./index-D3GWkXJR.js";var E=e(n(),1),D=d(),O=[{value:`1h`,hours:1},{value:`24h`,hours:24},{value:`7d`,hours:168},{value:`never`}];function k(e){return e.url||`${window.location.origin}/share/${encodeURIComponent(e.id)}`}function A(e){if(!e)return`-`;let t=new Date(e);return Number.isNaN(t.getTime())?`-`:t.toLocaleString(h())}function j(e){return g(e===`disabled`?`shareStatusDisabled`:e===`expired`?`shareStatusExpired`:`shareStatusActive`)}function M(e){return e===`disabled`?`quickforge-settings-badge-muted`:e===`expired`?`quickforge-settings-badge-warning`:`quickforge-settings-badge-success`}function N(e){let t=O.find(t=>t.value===e);return t&&`hours`in t?y(t.hours):void 0}function P({share:e,onClose:t,onSaved:n}){let[r,i]=(0,E.useState)(e.permission),[a,o]=(0,E.useState)(``),[s,c]=(0,E.useState)(!1),[d,f]=(0,E.useState)(e.allowCloudUsage===!0),[p,h]=(0,E.useState)(`keep`),[v,y]=(0,E.useState)(!1),[x,S]=(0,E.useState)(``),C=r===`operate`,w=s?!1:!!(e.hasPassword||a.trim()),T=async()=>{if(C&&!w){S(g(`operateRequiresPassword`));return}y(!0),S(``);try{let i=s?``:a?a.trim():void 0,o=p===`keep`?void 0:N(p);n((await m(e.id,{permission:r,password:i,expiresAt:o,allowCloudUsage:r===`operate`&&d})).share),t()}catch(e){S(e instanceof Error?e.message:g(`requestFailed`)),y(!1)}};return(0,D.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/45 p-4`,onMouseDown:e=>{e.target===e.currentTarget&&t()},children:(0,D.jsxs)(`div`,{className:`flex max-h-[85vh] w-full max-w-md flex-col overflow-hidden rounded-2xl border border-border bg-background shadow-quickforge`,onMouseDown:e=>e.stopPropagation(),children:[(0,D.jsxs)(`div`,{className:`shrink-0 border-b border-border px-5 py-4`,children:[(0,D.jsx)(`h2`,{className:`text-base font-semibold`,children:g(`editShareTitle`)}),(0,D.jsx)(`p`,{className:`mt-1 truncate text-sm text-muted-foreground`,children:e.titleSnapshot||g(`untitledConversation`)})]}),(0,D.jsxs)(`div`,{className:`min-h-0 flex-1 space-y-4 overflow-y-auto px-5 py-4`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`div`,{className:`mb-2 text-sm font-medium`,children:g(`sharePermissionTitle`)}),(0,D.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:[(0,D.jsxs)(`button`,{type:`button`,className:`rounded-xl border p-3 text-left text-sm ${r===`read`?`border-primary bg-primary/10`:`border-border`}`,onClick:()=>i(`read`),children:[(0,D.jsx)(`div`,{className:`font-medium`,children:g(`sharePermissionRead`)}),(0,D.jsx)(`div`,{className:`mt-1 text-xs text-muted-foreground`,children:g(`sharePermissionReadHint`)})]}),(0,D.jsxs)(`button`,{type:`button`,className:`rounded-xl border p-3 text-left text-sm ${r===`operate`?`border-red-400 bg-red-50 text-red-950`:`border-border`}`,onClick:()=>i(`operate`),children:[(0,D.jsx)(`div`,{className:`font-medium text-red-700`,children:g(`sharePermissionOperate`)}),(0,D.jsx)(`div`,{className:`mt-1 text-xs text-red-700`,children:g(`sharePermissionOperateHint`)})]})]})]}),r===`operate`?(0,D.jsxs)(`label`,{className:`flex items-start gap-2 rounded-xl border border-border bg-muted/20 p-3 text-xs font-medium`,children:[(0,D.jsx)(`input`,{type:`checkbox`,checked:d,onChange:e=>f(e.target.checked)}),(0,D.jsx)(`span`,{children:`允许该分享使用宿主机的 QuickForge Cloud 模型和额度。默认关闭。`})]}):null,(0,D.jsxs)(`div`,{className:`space-y-2`,children:[(0,D.jsx)(`label`,{className:`block text-sm font-medium`,children:g(`sharePasswordTitle`)}),(0,D.jsxs)(`div`,{className:`flex flex-col gap-3 sm:flex-row sm:items-center`,children:[(0,D.jsx)(`input`,{value:a,onChange:e=>o(e.target.value),disabled:s,className:`h-10 w-full min-w-0 rounded-md border border-input bg-background px-3 text-sm`,placeholder:e.hasPassword?g(`sharePasswordPlaceholderKeep`):g(`sharePasswordPlaceholderNone`),type:`text`,autoComplete:`new-password`}),(0,D.jsxs)(_,{variant:`outline`,className:`h-10 sm:shrink-0`,onClick:()=>{c(!1),o(b())},children:[(0,D.jsx)(u,{className:`mr-2 size-4`}),g(`generatePassword`)]})]}),s?(0,D.jsx)(`span`,{className:`block text-xs text-destructive`,children:g(`sharePasswordRemovalSelected`)}):(0,D.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:e.hasPassword?g(`sharePasswordEditHint`):g(`sharePasswordSetHint`)}),e.hasPassword&&!s?(0,D.jsxs)(_,{variant:`ghost`,size:`sm`,className:`h-8 text-destructive`,onClick:()=>{o(``),c(!0)},children:[(0,D.jsx)(l,{className:`mr-2 size-3.5`}),g(`removePassword`)]}):null]}),(0,D.jsxs)(`label`,{className:`block text-sm font-medium`,children:[g(`shareExpiresAt`),(0,D.jsxs)(`select`,{value:p,onChange:e=>h(e.target.value),className:`mt-2 h-10 w-full rounded-md border border-input bg-background px-3 text-sm`,children:[(0,D.jsx)(`option`,{value:`keep`,children:g(`keepCurrentExpiration`)}),(0,D.jsx)(`option`,{value:`1h`,children:g(`oneHour`)}),(0,D.jsx)(`option`,{value:`24h`,children:g(`twentyFourHours`)}),(0,D.jsx)(`option`,{value:`7d`,children:g(`sevenDays`)}),(0,D.jsx)(`option`,{value:`never`,children:g(`shareNeverExpires`)})]})]}),x?(0,D.jsx)(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive`,children:x}):null]}),(0,D.jsx)(`div`,{className:`shrink-0 border-t border-border px-5 py-4`,children:(0,D.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,D.jsx)(_,{variant:`outline`,onClick:t,disabled:v,children:g(`cancel`)}),(0,D.jsx)(_,{variant:r===`operate`?`destructive`:`default`,onClick:()=>void T(),disabled:v,children:g(`saveChanges`)})]})})]})})}function F({share:e,status:n,onClose:r,onAction:i}){let o=n===`active`;return(0,D.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-end justify-center bg-black/45 sm:items-center`,onMouseDown:e=>{e.target===e.currentTarget&&r()},children:(0,D.jsxs)(`div`,{className:`w-full max-w-md rounded-t-2xl border border-border bg-background p-4 pb-[max(1rem,env(safe-area-inset-bottom))] shadow-quickforge sm:rounded-2xl sm:pb-4`,role:`dialog`,"aria-modal":`true`,"aria-label":g(`manageShare`),children:[(0,D.jsx)(`div`,{className:`truncate px-1 text-sm font-medium text-foreground`,children:e.titleSnapshot||g(`untitledConversation`)}),(0,D.jsx)(`div`,{className:`mt-1 truncate px-1 font-mono text-xs text-muted-foreground`,title:k(e),children:k(e)}),(0,D.jsxs)(`div`,{className:`mt-3 space-y-1`,children:[(0,D.jsxs)(_,{variant:`ghost`,className:`w-full justify-start`,onClick:()=>i(`copy`),children:[(0,D.jsx)(a,{className:`mr-2 size-4`}),g(`copyShareLink`)]}),(0,D.jsxs)(_,{variant:`ghost`,className:`w-full justify-start`,disabled:!o,onClick:()=>i(`open`),children:[(0,D.jsx)(c,{className:`mr-2 size-4`}),g(`openShareLink`)]}),n===`active`?(0,D.jsxs)(_,{variant:`ghost`,className:`w-full justify-start`,onClick:()=>i(`edit`),children:[(0,D.jsx)(s,{className:`mr-2 size-4`}),g(`editShare`)]}):null,n===`active`?(0,D.jsxs)(_,{variant:`ghost`,className:`w-full justify-start`,onClick:()=>i(`disable`),children:[(0,D.jsx)(t,{className:`mr-2 size-4`}),g(`disableShare`)]}):(0,D.jsxs)(_,{variant:`ghost`,className:`w-full justify-start`,onClick:()=>i(`restore`),children:[(0,D.jsx)(u,{className:`mr-2 size-4`}),g(`restoreShare`)]}),(0,D.jsxs)(_,{variant:`ghost`,className:`w-full justify-start hover:text-destructive`,onClick:()=>i(`delete`),children:[(0,D.jsx)(l,{className:`mr-2 size-4`}),g(`deleteShare`)]})]}),(0,D.jsx)(_,{variant:`outline`,className:`mt-3 w-full`,onClick:r,children:g(`cancel`)})]})})}function I(){let[e,n]=(0,E.useState)([]),[d,m]=(0,E.useState)(!0),[h,y]=(0,E.useState)(``),[b,O]=(0,E.useState)(``),[I,L]=(0,E.useState)({}),[R,z]=(0,E.useState)(null),[B,V]=(0,E.useState)(null),[H,U]=(0,E.useState)(``),[W,G]=(0,E.useState)(``),ee=async(e=!0)=>{e&&m(!0),G(``);try{n((await w()).shares)}catch(e){G(e instanceof Error?e.message:g(`shareLinksLoadFailed`))}finally{e&&m(!1)}};(0,E.useEffect)(()=>{let e=!1;return w().then(t=>{e||n(t.shares)}).catch(t=>{e||G(t instanceof Error?t.message:g(`shareLinksLoadFailed`))}).finally(()=>{e||m(!1)}),()=>{e=!0}},[]);let K=(0,E.useMemo)(()=>{let t=b.trim().toLowerCase();return t?e.filter(e=>`${e.titleSnapshot||``} ${e.id} ${e.projectId||``}`.toLowerCase().includes(t)):e},[b,e]),q=e=>{n(t=>t.map(t=>t.id===e.id?{...t,...e}:t))},J=async(e,t,n)=>{if(!h){y(e),U(``),G(``);try{q((await t()).share),U(n)}catch(e){G(e instanceof Error?e.message:g(`requestFailed`))}finally{y(``)}}},Y=async e=>{try{await p(k(e)),U(g(`shareLinkCopied`)),G(``)}catch{G(g(`copyFailed`))}},X=async e=>{await v({description:g(`disableShareConfirm`,{title:e.titleSnapshot||e.id}),confirmLabel:g(`disableShare`),cancelLabel:g(`cancel`),variant:`destructive`})&&await J(e.id,()=>T(e.id),g(`shareDisabled`))},Z=async e=>{let t=I[e.id]||`24h`;await J(e.id,()=>C(e.id,N(t)),g(`shareRestored`))},te=async e=>{let t=I[e.id]||`24h`;await J(e.id,()=>f(e.id,N(t)),g(`shareExpirationUpdated`))},Q=async e=>{if(!(!await v({description:g(`deleteShareConfirm`,{title:e.titleSnapshot||e.id}),confirmLabel:g(`confirmDelete`),cancelLabel:g(`cancel`),variant:`destructive`})||h)){y(e.id),U(``),G(``);try{await S(e.id),n(t=>t.filter(t=>t.id!==e.id)),U(g(`shareDeleted`))}catch(e){G(e instanceof Error?e.message:g(`requestFailed`))}finally{y(``)}}},ne=(e,t)=>{V(null),t===`copy`&&Y(e),t===`open`&&window.open(k(e),`_blank`,`noopener,noreferrer`),t===`edit`&&z(e),t===`disable`&&X(e),t===`restore`&&Z(e),t===`delete`&&Q(e)},re=R?x(R):null,$=B?x(B):null;return(0,D.jsxs)(`div`,{className:`quickforge-settings-stack`,children:[(0,D.jsxs)(`div`,{className:`quickforge-settings-heading`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsxs)(`h2`,{className:`quickforge-settings-title`,children:[(0,D.jsx)(r,{className:`size-5`}),g(`shareLinks`)]}),(0,D.jsx)(`p`,{className:`quickforge-settings-row-description`,children:g(`shareLinksDescription`)})]}),(0,D.jsxs)(_,{variant:`outline`,size:`sm`,onClick:()=>void ee(),disabled:d||!!h,children:[(0,D.jsx)(u,{className:`mr-2 size-4 ${d?`animate-spin`:``}`}),g(`refresh`)]})]}),(0,D.jsxs)(`div`,{className:`quickforge-settings-section`,children:[(0,D.jsxs)(`div`,{className:`quickforge-settings-toolbar`,children:[(0,D.jsxs)(`div`,{className:`quickforge-settings-inline-field max-w-md`,children:[(0,D.jsx)(i,{className:`pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground/60`,"aria-hidden":`true`}),(0,D.jsx)(`input`,{value:b,onChange:e=>O(e.target.value),className:`quickforge-settings-input`,placeholder:g(`searchShareLinks`),"aria-label":g(`searchShareLinks`)})]}),(0,D.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:g(`shareLinksCount`,{count:K.length})})]}),H?(0,D.jsx)(`div`,{className:`quickforge-settings-note quickforge-share-links-message`,children:H}):null,W?(0,D.jsx)(`div`,{className:`quickforge-settings-error quickforge-share-links-message`,children:W}):null,d?(0,D.jsx)(`div`,{className:`p-6 text-center text-sm text-muted-foreground`,children:g(`loading`)}):K.length===0?(0,D.jsx)(`div`,{className:`p-8 text-center text-sm text-muted-foreground`,children:g(b?`noMatchingShareLinks`:`noShareLinks`)}):K.map(e=>{let n=x(e),r=h===e.id,i=n===`active`;return(0,D.jsxs)(`div`,{className:`quickforge-settings-list-item quickforge-share-link-item`,children:[(0,D.jsxs)(`div`,{className:`quickforge-settings-list-item-main`,children:[(0,D.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,D.jsx)(`div`,{className:`truncate text-sm font-medium text-foreground`,children:e.titleSnapshot||g(`untitledConversation`)}),(0,D.jsx)(`span`,{className:`quickforge-settings-badge ${M(n)}`,children:j(n)}),(0,D.jsx)(`span`,{className:`quickforge-settings-badge quickforge-settings-badge-info`,children:e.permission===`operate`?g(`sharePermissionOperate`):g(`sharePermissionRead`)}),e.hasPassword?(0,D.jsx)(`span`,{className:`quickforge-settings-badge quickforge-settings-badge-muted`,children:g(`sharePasswordProtected`)}):null]}),(0,D.jsx)(`div`,{className:`quickforge-share-link-url`,title:k(e),children:k(e)}),(0,D.jsxs)(`div`,{className:`quickforge-settings-meta text-xs text-muted-foreground`,children:[(0,D.jsxs)(`span`,{children:[g(`shareCreatedAt`),`: `,A(e.createdAt)]}),(0,D.jsx)(`span`,{children:`·`}),(0,D.jsxs)(`span`,{children:[g(`shareExpiresAt`),`: `,e.expiresAt?A(e.expiresAt):g(`shareNeverExpires`)]}),(0,D.jsx)(`span`,{children:`·`}),(0,D.jsx)(`span`,{children:g(`shareAccessCount`,{count:e.accessCount||0})}),e.lastAccessedAt?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`span`,{children:`·`}),(0,D.jsxs)(`span`,{children:[g(`shareLastAccessedAt`),`: `,A(e.lastAccessedAt)]})]}):null]})]}),(0,D.jsxs)(`div`,{className:`quickforge-settings-list-item-actions quickforge-share-link-actions`,children:[(0,D.jsxs)(`div`,{className:`hidden flex-wrap items-center justify-end gap-2 md:flex`,children:[n===`active`?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(`select`,{className:`quickforge-settings-select quickforge-share-expiration-select`,value:I[e.id]||`24h`,onChange:t=>L(n=>({...n,[e.id]:t.target.value})),"aria-label":g(`shareUpdateExpiration`),disabled:r,children:[(0,D.jsx)(`option`,{value:`1h`,children:g(`oneHour`)}),(0,D.jsx)(`option`,{value:`24h`,children:g(`twentyFourHours`)}),(0,D.jsx)(`option`,{value:`7d`,children:g(`sevenDays`)}),(0,D.jsx)(`option`,{value:`never`,children:g(`shareNeverExpires`)})]}),(0,D.jsx)(_,{variant:`outline`,size:`sm`,onClick:()=>void te(e),disabled:r,children:g(`updateShareExpiration`)})]}):null,(0,D.jsx)(_,{variant:`ghost`,size:`icon`,onClick:()=>void Y(e),"aria-label":g(`copyShareLink`),title:g(`copyShareLink`),children:(0,D.jsx)(a,{className:`size-4`})}),(0,D.jsx)(_,{variant:`ghost`,size:`icon`,onClick:()=>window.open(k(e),`_blank`,`noopener,noreferrer`),disabled:!i,"aria-label":g(`openShareLink`),title:g(`openShareLink`),children:(0,D.jsx)(c,{className:`size-4`})}),n===`active`?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(_,{variant:`outline`,size:`sm`,onClick:()=>z(e),disabled:r,children:[(0,D.jsx)(s,{className:`mr-2 size-4`}),g(`editShare`)]}),(0,D.jsxs)(_,{variant:`outline`,size:`sm`,onClick:()=>void X(e),disabled:r,children:[(0,D.jsx)(t,{className:`mr-2 size-4`}),g(`disableShare`)]})]}):(0,D.jsxs)(_,{variant:`outline`,size:`sm`,onClick:()=>void Z(e),disabled:r,children:[(0,D.jsx)(u,{className:`mr-2 size-4`}),g(`restoreShare`)]}),(0,D.jsx)(_,{variant:`ghost`,size:`icon`,className:`hover:text-destructive`,onClick:()=>void Q(e),disabled:r,"aria-label":g(`deleteShare`),title:g(`deleteShare`),children:(0,D.jsx)(l,{className:`size-4`})})]}),(0,D.jsxs)(_,{variant:`outline`,size:`sm`,className:`md:hidden`,onClick:()=>V(e),disabled:r,children:[(0,D.jsx)(o,{className:`mr-2 size-4`}),g(`manageShare`)]})]})]},e.id)})]}),R&&re===`active`?(0,D.jsx)(P,{share:R,onClose:()=>z(null),onSaved:e=>{q(e),U(g(`shareUpdated`)),G(``)}},R.id):null,B&&$?(0,D.jsx)(F,{share:B,status:$,onClose:()=>V(null),onAction:e=>ne(B,e)}):null]})}export{I as ShareLinksSettingsPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{Jt as t,bt as n,o as r}from"./icons-DM_qJ7VJ.js";import{n as i}from"./react-vendor-BpWW_Nvp.js";import{S as a,b as o,d as s,f as c,p as l,u}from"./pi-web-ui-BNuvqKDT.js";import{U as d}from"./pi-ai-Cr2ee4a0.js";import{t as f}from"./logger-8REuLPGK.js";import{r as p}from"./model-display-label-CURwH0xM.js";import{C as m,Dt as h,Ln as g,Mn as _,Nn as v,Ot as y,S as b,Sn as x,T as S,Tn as C,cn as w,fn as T,kt as E,ln as D,st as O,un as k,wt as A}from"./index-D3GWkXJR.js";import{t as j}from"./model-identity-CgA6_Pbm.js";import{ChatPanelHost as M}from"./ChatPanelHost-COTO7swS.js";var N=e(t(),1),P=`quickforgeClientMessageId`;function F(e){let t=e?.metadata;return t&&typeof t==`object`&&!Array.isArray(t)?t:void 0}function I(e){let t=F(e)?.[P];return typeof t==`string`&&t?t:void 0}function L(){return`qfcm_${typeof crypto<`u`&&typeof crypto.randomUUID==`function`?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`}`}function R(e){let t=I(e);if(t)return{message:e,clientMessageId:t};let n=L();return{message:{...e,metadata:{...F(e),[P]:n}},clientMessageId:n}}function z(e){return typeof e==`string`?e:Array.isArray(e)?e.filter(e=>e&&typeof e==`object`&&e.type===`text`).map(e=>e.text).filter(e=>typeof e==`string`).join(``):``}function B(e,t){if(!e||!t||e.role!==t.role)return!1;let n=I(e),r=I(t);return n&&r?n===r:z(e.content)===z(t.content)}async function V(e,t){let n=await fetch(e,{...t,cache:`no-store`,headers:{...t?.body?{"content-type":`application/json`}:void 0,...t?.headers}}),r=await n.json().catch(()=>null);if(!n.ok){let e=r?.code===`GENERATION_ALREADY_RUNNING`?g(`generationAlreadyRunning`):r?.error||`Request failed: ${n.status}`;throw Error(e)}return r}var H=class e{state;streamFn=d;getApiKey;sessionId;shareId;permission;harness=`quickforge`;listeners=new Set;eventSource=null;disposed=!1;reconnectTimer=null;reconnectDelay=1e3;baseUrl=``;syncingThinkingLevel=!1;planMode=!1;onPlanModeConsumed;constructor(e,t){this.shareId=e,this.sessionId=t.sessionId||t.id||e,this.permission=t.permission??`read`;let n={systemPrompt:t.systemPrompt??``,model:t.model??{provider:`shared`,id:`shared`},thinkingLevel:t.thinkingLevel??`off`,messages:t.messages?.slice()??[],tools:t.tools??[],isStreaming:!!t.isStreaming,streamingMessage:void 0,pendingToolCalls:new Set,errorMessage:t.errorMessage,contextCompaction:t.contextCompaction??null,contextUsage:t.contextUsage??null};this.state=new Proxy(n,{set:(e,t,n)=>{let r=e[t];return e[t]=n,t===`thinkingLevel`&&!this.syncingThinkingLevel&&n!==r&&this.updateThinkingLevel(n).catch(e=>{f.error(`Failed to update shared thinking level:`,e)}),!0}}),this.connectEvents()}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}setNextPromptCapabilities(){}setPlanMode(e,t){this.planMode=e,this.onPlanModeConsumed=e?t:void 0}async prompt(e){if(this.disposed||this.permission!==`operate`)return;let{message:t,clientMessageId:n}=R(this.normalizeInput(e)),r=this.planMode?{type:`plan`}:void 0;if(this.planMode){this.planMode=!1;let e=this.onPlanModeConsumed;this.onPlanModeConsumed=void 0,e?.()}this.state.messages=[...this.state.messages,t],this.emit({type:`message_start`,message:t}),this.state.isStreaming||(this.state.isStreaming=!0,this.state.errorMessage=void 0,this.emit({type:`agent_start`}));try{await V(`/api/shared/${encodeURIComponent(this.shareId)}/message`,{method:`POST`,body:JSON.stringify({message:t,clientMessageId:n,command:r})})}catch(e){let t=e instanceof Error?e.message:String(e);throw this.state.errorMessage=t,this.state.isStreaming=!1,this.emit({type:`error`,error:t}),this.emit({type:`agent_end`,messages:this.state.messages}),e}}async updateModel(e){if(this.disposed||this.permission!==`operate`)return;let t=this.state.model;this.state.model=e;try{let t=await V(`/api/shared/${encodeURIComponent(this.shareId)}/model`,{method:`POST`,body:JSON.stringify({modelRef:p(e),model:e})});t.model&&(this.state.model=t.model)}catch(e){this.state.model=t;let n=e instanceof Error?e.message:String(e);throw this.state.errorMessage=n,this.emit({type:`error`,error:n}),e}}async updateThinkingLevel(e){if(!(this.disposed||this.permission!==`operate`)){!this.syncingThinkingLevel&&this.state.thinkingLevel!==e&&(this.state.thinkingLevel=e);try{let t=await V(`/api/shared/${encodeURIComponent(this.shareId)}/thinking-level`,{method:`POST`,body:JSON.stringify({thinkingLevel:e})});t.thinkingLevel&&(this.state.thinkingLevel=t.thinkingLevel)}catch(e){let t=e instanceof Error?e.message:String(e);throw this.state.errorMessage=t,this.emit({type:`error`,error:t}),e}}}abort(){this.permission===`operate`&&fetch(`/api/shared/${encodeURIComponent(this.shareId)}/abort`,{method:`POST`}).catch(e=>{f.error(`Failed to abort shared conversation:`,e)})}steer(){}followUp(){}reset(){this.state.messages=[],this.state.errorMessage=void 0,this.state.isStreaming=!1,this.state.streamingMessage=void 0,this.state.pendingToolCalls=new Set}async rollback(e){if(this.permission!==`operate`)return;let t=await V(`/api/shared/${encodeURIComponent(this.shareId)}/rollback`,{method:`POST`,body:JSON.stringify({messageIndex:e})});return this.applyState(t.session),this.emit({type:`messages_replaced`,messages:this.state.messages}),t}dispose(){this.disposed=!0,this.reconnectTimer&&clearTimeout(this.reconnectTimer),this.reconnectTimer=null,this.eventSource?.close(),this.eventSource=null,this.listeners.clear()}static async loadState(e){return V(`/api/shared/${encodeURIComponent(e)}/session`)}static async create(t){return new e(t,await e.loadState(t))}normalizeInput(e){return typeof e==`string`?{role:`user`,content:e,timestamp:Date.now()}:Array.isArray(e)?[...e].reverse().find(e=>e.role===`user`||e.role===`user-with-attachments`)??e[e.length-1]:e}connectEvents(){this.disposed||(this.eventSource?.close(),this.baseUrl=``,this.openEventSource())}openEventSource(){if(this.disposed)return;let e=`${this.baseUrl}/api/shared/${encodeURIComponent(this.shareId)}/events`;this.eventSource=new EventSource(e,{withCredentials:!0}),this.eventSource.onopen=()=>{this.reconnectDelay=1e3};let t=[`state`,`agent_start`,`agent_end`,`message_start`,`message_end`,`turn_start`,`turn_end`,`message_update`,`tool_execution_start`,`tool_execution_update`,`tool_execution_end`,`tool_approval_required`,`auto_compact_approval_required`,`auto_compact_failed`,`error`,`title_updated`,`messages_replaced`,`auto_compact_completed`],n=e=>t=>{try{let n=JSON.parse(t.data);this.handleEvent(e?{type:e,...n}:n)}catch{}};this.eventSource.onmessage=n();for(let e of t)this.eventSource.addEventListener(e,n(e));this.eventSource.onerror=()=>{this.eventSource?.close(),this.eventSource=null,this.scheduleReconnect()}}scheduleReconnect(){this.disposed||this.reconnectTimer||(this.reconnectTimer=setTimeout(()=>{this.reconnectTimer=null,this.reconnectDelay=Math.min(this.reconnectDelay*2,3e4),this.openEventSource()},this.reconnectDelay))}handleEvent(e){if(e.type){switch(e.type){case`state`:this.applyState(e);break;case`agent_start`:this.state.isStreaming=!0,this.state.errorMessage=void 0;break;case`agent_end`:this.state.isStreaming=!1,this.state.streamingMessage=void 0;break;case`message_start`:if(e.message){let t=this.state.messages.findIndex(t=>B(t,e.message));if(t>=0){let n=this.state.messages.slice();n[t]=e.message,this.state.messages=n}else this.state.messages=[...this.state.messages,e.message];this.state.contextUsage=null}break;case`message_update`:e.message&&(this.state.streamingMessage=e.message);break;case`message_end`:e.message&&(this.state.messages=D(this.state.messages,e.message)),this.state.contextUsage=`contextUsage`in e?e.contextUsage:null,this.state.streamingMessage=void 0;break;case`messages_replaced`:e.messages&&(this.state.messages=e.messages,this.state.streamingMessage=void 0),`contextCompaction`in e&&(this.state.contextCompaction=e.contextCompaction),`contextUsage`in e&&(this.state.contextUsage=e.contextUsage);break;case`auto_compact_completed`:`contextCompaction`in e&&(this.state.contextCompaction=e.contextCompaction),`contextUsage`in e&&(this.state.contextUsage=e.contextUsage);break;case`tool_execution_start`:{let t=e;t.toolCallId&&(this.state.messages=k(this.state.messages,w(t),!0),this.state.pendingToolCalls=new Set([...this.state.pendingToolCalls,t.toolCallId]));break}case`tool_execution_update`:{let t=e;this.state.messages=k(this.state.messages,t,!0),t.toolCallId&&(this.state.pendingToolCalls=new Set([...this.state.pendingToolCalls,t.toolCallId]));break}case`tool_execution_end`:{let t=e;if(this.state.messages=k(this.state.messages,t,!1),t.toolCallId){let e=new Set(this.state.pendingToolCalls);e.delete(t.toolCallId),this.state.pendingToolCalls=e}break}case`error`:this.state.errorMessage=typeof e.error==`string`?e.error:`Unknown error`,this.state.isStreaming=!1;break}this.emit(e)}}applyState(e){this.sessionId=e.sessionId||e.id||this.sessionId,e.messages&&(this.state.messages=e.messages,this.state.contextUsage=e.contextUsage===void 0?null:e.contextUsage),e.systemPrompt!==void 0&&(this.state.systemPrompt=e.systemPrompt),e.model&&(this.state.model=e.model),e.thinkingLevel&&(this.syncingThinkingLevel=!0,this.state.thinkingLevel=e.thinkingLevel,this.syncingThinkingLevel=!1),e.tools&&(this.state.tools=e.tools),e.isStreaming!==void 0&&(this.state.isStreaming=!!e.isStreaming),e.errorMessage!==void 0&&(this.state.errorMessage=e.errorMessage),e.contextCompaction!==void 0&&(this.state.contextCompaction=e.contextCompaction),e.contextUsage!==void 0&&(this.state.contextUsage=e.contextUsage)}emit(e){for(let t of this.listeners)try{t(e)}catch{}}},U=i();function W(e){return{id:`shared-${e.provider}`,name:e.provider,type:e.api,baseUrl:e.baseUrl??``,models:[e]}}async function G(e,t){try{let t=await m(e);if(t.providers?.length)return t.providers}catch{}return t?[W(t)]:[]}function K(e,t){let n=t.model??{provider:`shared`,id:`shared`};return new H(e,{...t,model:n,thinkingLevel:t.thinkingLevel??T(n)})}function q(e,t){let n={settings:new u,providerKeys:new c,sessions:new s,customProviders:new l},r=new C(``,{blockedStores:[`sessions`,`provider-keys`],fakeProviderKeys:t?[t.provider]:void 0,storeOverrides:t?{"custom-providers":{keys:async()=>(await G(e,t)).map(e=>e.name),get:async n=>(await G(e,t)).find(e=>e.name===n)??null,has:async n=>(await G(e,t)).some(e=>e.name===n)}}:void 0});n.settings.setBackend(r),n.providerKeys.setBackend(r),n.sessions.setBackend(r),n.customProviders.setBackend(r),a(new o(n.settings,n.providerKeys,n.sessions,n.customProviders,r))}function J({shareId:e}){let[t,i]=(0,N.useState)(``),[a,o]=(0,N.useState)(null),[s,c]=(0,N.useState)(`read`),[l,u]=(0,N.useState)(`QuickForge 分享对话`),[d,p]=(0,N.useState)(),[m,C]=(0,N.useState)(!1),[w,T]=(0,N.useState)(),D=(0,N.useRef)(!1),k=s===`operate`,P=!!a,F=!!a?.state.tools?.length;(0,N.useEffect)(()=>{q(e,a?.state.model)},[a?.state.model,e]),(0,N.useEffect)(()=>()=>a?.dispose(),[a]);let I=(0,N.useCallback)(async(n=t.trim())=>{p(void 0),C(!0);try{let t=await S(e,n);c(t.permission),u(t.title||t.share.titleSnapshot||`QuickForge 分享对话`);let r=await H.loadState(e);q(e,r.model),o(K(e,r))}catch(e){p(e instanceof Error?e.message:`Failed to unlock shared conversation`)}finally{C(!1)}},[t,e]);(0,N.useEffect)(()=>{if(P||m||D.current)return;D.current=!0;let t=window.setTimeout(()=>{(async()=>{try{(await b(e)).share.hasPassword||await I(``)}catch(e){p(e instanceof Error?e.message:`Failed to load shared conversation`)}})()},0);return()=>window.clearTimeout(t)},[m,e,I,P]);let L=(0,N.useCallback)(async e=>{await h(e)},[]),R=(0,N.useCallback)(async()=>{if(!(!a||a.permission!==`operate`))try{let t=j(x((await G(e,a.state.model)).flatMap(e=>e.models??[])),a.state.model);if(!t.length)return;O(a.state.model,t,t=>{!t.reasoning&&a.state.thinkingLevel!==`off`&&a.updateThinkingLevel(`off`).catch(e=>{f.error(`Failed to update shared thinking level:`,e)}),q(e,t),a.updateModel(t).catch(e=>{p(e instanceof Error?e.message:`Failed to update model`)})},void 0,{thinkingLevel:a.state.thinkingLevel,onThinkingLevelSelect:e=>{a.updateThinkingLevel(e).catch(e=>{f.error(`Failed to update shared thinking level:`,e),p(e instanceof Error?e.message:`Failed to update thinking level`)})}})}catch(e){p(e instanceof Error?e.message:`Failed to load models`)}},[a,e]),z=(0,N.useCallback)(e=>{T(t=>t?.id===e?void 0:t)},[]),B=(0,N.useCallback)(async e=>{if(!a||a.permission!==`operate`)return;if(p(void 0),a.state.isStreaming){A(g(`generationStillRunning`));return}let t=E(a.state.messages,e),n=t>=0?a.state.messages[t]:void 0;if(!n){A(g(`noConversationTurnToRollback`));return}try{await a.rollback(e),T({id:Date.now(),sessionId:a.sessionId,text:y(n),attachments:n.role===`user-with-attachments`?n.attachments:void 0})}catch(e){p(e instanceof Error?e.message:`Failed to roll back`)}},[a]);return P?(0,U.jsxs)(`div`,{className:`flex h-screen min-h-0 flex-col bg-background text-foreground`,children:[(0,U.jsx)(`header`,{className:v(`shrink-0 border-b px-4 py-3`,k?`border-red-300 bg-red-50 text-red-950`:`border-border bg-background`),children:(0,U.jsxs)(`div`,{className:`mx-auto flex max-w-4xl items-start gap-3`,children:[(0,U.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,U.jsx)(`div`,{className:`truncate text-sm font-semibold`,children:l}),(0,U.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-2 gap-y-1 text-xs`,children:[(0,U.jsxs)(`span`,{className:v(`inline-flex items-center gap-1 rounded-full px-2 py-0.5 font-medium`,k?`bg-red-100 text-red-700`:`bg-muted text-muted-foreground`),children:[k?(0,U.jsx)(r,{className:`size-3.5`}):null,k?`高危可操作`:`只读分享`]}),(0,U.jsx)(`span`,{className:v(k?`text-red-800`:`text-muted-foreground`),children:k?`正在操作分享者的原始对话`:`只能查看,不能发送或修改`})]}),k?null:(0,U.jsx)(`div`,{className:`mt-1 text-xs leading-5 text-muted-foreground`,children:`界面与正常对话保持一致`})]}),(0,U.jsxs)(_,{variant:`ghost`,size:`sm`,className:v(`shrink-0`,k?`text-red-700 hover:bg-red-100 hover:text-red-800`:void 0),onClick:()=>void h(window.location.href),"aria-label":k?`复制高危分享链接`:`复制分享链接`,title:k?`复制高危分享链接`:`复制分享链接`,children:[(0,U.jsx)(n,{className:`size-4`}),(0,U.jsx)(`span`,{className:`hidden sm:inline`,children:k?`复制高危链接`:`复制链接`})]})]})}),d?(0,U.jsx)(`div`,{className:`mx-auto w-full max-w-4xl px-4 py-2 text-sm text-destructive`,children:d}):null,(0,U.jsx)(M,{agent:a,revision:0,agentAccessMode:F?`full-access`:`default`,workspaceToolsEnabled:F,onModelSelect:R,onAccessModeChange:()=>void 0,onRollbackFromMessage:B,onRetryFromMessage:()=>void 0,onCopyAnswer:L,onForkFromMessage:()=>void 0,onApproveToolCall:()=>void 0,onRejectToolCall:()=>void 0,disableFork:!0,rollbackConfirmTitle:g(`sharedRollbackConfirmTitle`),rollbackConfirmDescription:g(`sharedRollbackConfirm`),readOnly:!k,approvalReadOnly:!0,approvalReadOnlyMessage:g(`sharedApprovalReadOnly`),restoredDraft:w,onRestoredDraftConsumed:z,bypassClientApiKeyCheck:!0,showTurnNavigation:!1})]}):(0,U.jsx)(`div`,{className:`flex min-h-screen items-center justify-center bg-background p-6 text-foreground`,children:(0,U.jsxs)(`div`,{className:`w-full max-w-md rounded-2xl border border-border bg-background p-6 shadow-quickforge`,children:[(0,U.jsxs)(`div`,{className:`flex items-center gap-2 text-base font-semibold`,children:[(0,U.jsx)(r,{className:`size-5 text-amber-500`}),`QuickForge 局域网对话分享`]}),(0,U.jsx)(`p`,{className:`mt-2 text-sm text-muted-foreground`,children:`如果分享者设置了密码,请输入密码。未设置密码的链接会自动打开。`}),(0,U.jsx)(`input`,{type:`password`,value:t,onChange:e=>i(e.target.value),onKeyDown:e=>{e.key===`Enter`&&I()},className:`mt-5 h-10 w-full rounded-md border border-input bg-background px-3 text-sm outline-none focus:border-primary`,placeholder:`密码`,autoFocus:!0}),d?(0,U.jsx)(`div`,{className:`mt-3 rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive`,children:d}):null,(0,U.jsx)(_,{className:`mt-5 w-full`,onClick:()=>void I(),disabled:m||!t.trim(),children:m?g(`loading`):`用密码打开分享对话`})]})})}export{J as SharedConversationPage};
|