@shawnstack/quickforge 1.7.7 → 1.7.9
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/bin/quickforge.mjs +10 -1
- package/dist/assets/AgentProfilesPage-BSM5w3bn.js +1 -0
- package/dist/assets/ChatPanelHost-cd80S4EX.js +48 -0
- package/dist/assets/CloudAccountSettingsPage-BJMrfgy9.js +1 -0
- package/dist/assets/{PluginsPage-CPE5tbbf.js → PluginsPage-mJkTmVVV.js} +1 -1
- package/dist/assets/ScheduledTasksPage-DJj_NLm9.js +2 -0
- package/dist/assets/{SettingsWorkspacePage-BE2T4d3P.js → SettingsWorkspacePage-7lQ0Wl63.js} +389 -389
- package/dist/assets/ShareLinksSettingsPage-DjFq_Lnb.js +1 -0
- package/dist/assets/SharedConversationPage-BbuNpcpP.js +1 -0
- package/dist/assets/TerminalDock-CczcCJJE.js +2 -0
- package/dist/assets/WorkspaceInspector-0i6x-diB.js +36 -0
- package/dist/assets/{icons-2D18YbSI.js → icons-DM_qJ7VJ.js} +1 -1
- package/dist/assets/{index-BiCTgUlY.css → index-D-J_8Smf.css} +1 -1
- package/dist/assets/index-DFASc15l.js +66 -0
- package/dist/assets/local-tools-Dn1Y9aPe.js +270 -0
- package/dist/assets/{model-display-label-C6-0eDxF.js → logger-8REuLPGK.js} +1 -1
- package/dist/assets/{mcp-servers-dialog-GY7sdfIr.js → mcp-servers-dialog-BG4b67ea.js} +2 -2
- package/dist/assets/{model-reference-o41fJ6jQ.js → model-display-label-CURwH0xM.js} +1 -1
- package/dist/assets/{monaco-DvXErxp2.js → monaco-bDr860xx.js} +1 -1
- package/dist/assets/{react-vendor-3UaA-C9W.js → react-vendor-BpWW_Nvp.js} +1 -1
- package/dist/assets/{skills-dialog-C1fJ1Jl7.js → skills-dialog-DIzZvQqW.js} +3 -3
- package/dist/index.html +8 -8
- package/package.json +1 -1
- package/server/acp/server.mjs +17 -1
- package/server/agent-manager.mjs +251 -31
- package/server/ai-http-logger.mjs +162 -19
- package/server/ai-provider-options.mjs +4 -1
- package/server/auto-archive.mjs +42 -29
- package/server/cloud/auto-approval.mjs +155 -0
- package/server/cloud/client.mjs +5 -0
- package/server/cloud/qf-agent-process.mjs +163 -3
- package/server/cloud/service-config.mjs +1 -1
- package/server/index.mjs +69 -13
- package/server/lan-access-backup.mjs +256 -0
- package/server/lan-access-cutover.mjs +306 -0
- package/server/lan-access-json-file.mjs +75 -0
- package/server/lan-access-service.mjs +155 -0
- package/server/lan-access-store.mjs +110 -9
- package/server/maintenance/downgrade-lan-access-v1.mjs +101 -0
- package/server/maintenance/downgrade-session-state-v1.mjs +130 -0
- package/server/maintenance/downgrade-share-v1.mjs +101 -0
- package/server/maintenance/export-lan-access-v1.mjs +80 -0
- package/server/maintenance/export-scheduled-runs-v1.mjs +45 -0
- package/server/maintenance/export-session-state-v1.mjs +67 -0
- package/server/maintenance/export-share-v1.mjs +77 -0
- package/server/public-api.mjs +21 -2
- package/server/routes/agent.mjs +37 -4
- package/server/routes/backup.mjs +221 -39
- package/server/routes/cloud.mjs +28 -1
- package/server/routes/scheduled-tasks.mjs +347 -134
- package/server/routes/shares.mjs +4 -2
- package/server/routes/storage.mjs +138 -8
- package/server/routes/workspace.mjs +265 -4
- package/server/scheduled-runs-backup.mjs +235 -0
- package/server/scheduled-runs-cutover.mjs +497 -0
- package/server/scheduled-task-runs-service.mjs +279 -0
- package/server/session-index-service.mjs +495 -0
- package/server/session-state-backup.mjs +277 -0
- package/server/session-state-cutover.mjs +370 -0
- package/server/session-state-service.mjs +709 -0
- package/server/share-backup.mjs +255 -0
- package/server/share-cutover.mjs +296 -0
- package/server/share-json-file.mjs +60 -0
- package/server/share-service.mjs +163 -0
- package/server/share-store.mjs +196 -19
- package/server/skills.mjs +0 -1
- package/server/sqlite/database.mjs +233 -0
- package/server/sqlite/lan-access-repository.mjs +652 -0
- package/server/sqlite/migrations.mjs +577 -0
- package/server/sqlite/scheduled-task-runs-repository.mjs +464 -0
- package/server/sqlite/session-index-repository.mjs +297 -0
- package/server/sqlite/session-state-repository.mjs +786 -0
- package/server/sqlite/share-repository.mjs +854 -0
- package/server/storage.mjs +317 -1
- package/dist/assets/AgentProfilesPage-BfA_sQ3A.js +0 -1
- package/dist/assets/ChatPanelHost-Dul1ahKj.js +0 -307
- package/dist/assets/CloudAccountSettingsPage-qZh0lTUN.js +0 -1
- package/dist/assets/ScheduledTasksPage-PTxL_PPg.js +0 -2
- package/dist/assets/ShareLinksSettingsPage-Bl8fP62X.js +0 -1
- package/dist/assets/SharedConversationPage-BK9XJnEe.js +0 -1
- package/dist/assets/TerminalDock-CL7HU9DI.js +0 -2
- package/dist/assets/WorkspaceInspector-MNBLIKMn.js +0 -36
- package/dist/assets/index-BTPzyq7d.js +0 -65
- package/dist/assets/mermaid-renderer-jEbqFaTe.js +0 -2
- /package/dist/assets/{plugin-api-Uu2xAB4d.js → plugin-api-BrdQeM4B.js} +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{C as t,G as n,K as r,S as i,X as ee,_ as te,_t as ne,a as re,b as ie,c as ae,p as oe,pt as se,qt as a,xt as ce,yt as le}from"./icons-2D18YbSI.js";import{n as o}from"./react-vendor-3UaA-C9W.js";import{$ as ue,B as de,G as fe,H as s,J as pe,K as me,Q as he,Tt as c,U as ge,V as _e,W as ve,X as ye,Y as be,Z as xe,_n as Se,et as Ce,hn as we,mn as l,nt as u,q as Te,tt as Ee,vn as d,yn as f}from"./index-BTPzyq7d.js";var p=e(a(),1);function m(e,t=`cloudRequestFailed`){return e instanceof s?e.code===`cloud_session_active`?f(`cloudSessionActiveGuidance`):e.code===`cloud_disabled`?f(`cloudDisabledError`):e.code===`cloud_local_only`?f(`cloudLocalOnlyError`):e.code===`cloud_configuration_error`||e.code===`cloud_not_configured`?f(`cloudConfigurationError`):e.code===`cloud_session_service_mismatch`?f(`cloudSessionServiceMismatch`):[`expired_token`,`device_code_expired`,`expired`].includes(e.code)?f(`cloudDeviceFlowExpiredError`):[`access_denied`,`authorization_declined`,`denied`].includes(e.code)?f(`cloudDeviceFlowDeniedError`):[`refresh_token_reused`,`installation_revoked`,`invalid_refresh_token`,`cloud_not_connected`].includes(e.code)?f(`cloudSessionExpired`):Se()===`en`&&e.message.trim()?e.message:e.status>0?f(`cloudRequestFailedWithStatus`,{status:e.status}):f(t):f(t)}var De={usage:void 0,installations:[],models:[],errors:{},loading:!1};function Oe(e,t){return t.type===`replace`?t.state:{...De,loading:t.type===`begin`}}async function ke(e,t){let[n,r,i]=await Promise.allSettled([e.usage(),e.installations(),e.models()]);return{usage:n.status===`fulfilled`?n.value:void 0,installations:r.status===`fulfilled`?r.value:[],models:i.status===`fulfilled`?i.value:[],errors:{...n.status===`rejected`?{usage:t(`usage`,n.reason)}:{},...r.status===`rejected`?{installations:t(`installations`,r.reason)}:{},...i.status===`rejected`?{models:t(`models`,i.reason)}:{}},loading:!1}}function Ae({loading:e,loadError:t,status:n,details:r}){if(e&&!n)return`loading`;if(t)return`load-error`;if(!n?.configured)return`unconfigured`;if(n.sessionServiceMismatch)return`session-mismatch`;if(n.pendingDeviceFlow)return n.hasSession?`connected`:`no-session`;if(!n.hasSession)return`no-session`;let i=Object.values(r.errors);return n.cloudAvailable===!1||i.length===3&&i.every(e=>e?.unavailable)?`cloud-unavailable`:i.length>0?`partial-details`:`connected`}function je(e){let t=e?.configured===!0,n=t&&e.hasSession===!0,r=n&&e.sessionServiceMismatch!==!0;return{showDeviceFlow:t&&!!e.pendingDeviceFlow,showDisconnectedActions:t&&!e.pendingDeviceFlow&&!n,showDetails:r}}function Me(e){return e===`starting`||e===`authorizing`}function Ne(e,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 h=o();function g(e){if(!e)return f(`cloudNotAvailable`);let t=new Date(e);return Number.isNaN(t.getTime())?f(`cloudNotAvailable`):t.toLocaleString(d())}function _(e){let t=e.id||e.installationId;return typeof t==`string`?t:``}function v(e){let t=e.name||e.installationName;return typeof t==`string`&&t?t:f(`cloudUnnamedDevice`)}function Fe(e){return typeof e==`number`&&Number.isFinite(e)?e.toLocaleString(d()):f(`cloudNotAvailable`)}function Ie(e){return f(e===`saved`?`cloudConfigSourceSaved`:e===`env`?`cloudConfigSourceEnv`:`cloudConfigSourceDefault`)}function y(e){let t=String(e||``).toLowerCase();return t===`localhost`||t.endsWith(`.localhost`)||t.startsWith(`127.`)?!0:t===`::1`}function b(e){let t=e.trim();if(!t)return``;let n;try{n=new URL(t)}catch{return f(`cloudUrlInvalid`)}return n.protocol!==`https:`&&n.protocol!==`http:`?f(`cloudUrlInvalidProtocol`):y(n.hostname)&&n.port===`8081`?f(`cloudUrlAdminPort`):``}function x(e){if(!e||typeof e!=`object`)return f(`cloudConnectionUnknown`);let t=e;return t.ok===!0||t.status===`ok`||t.ready===!0?f(`cloudConnectionOk`):f(`cloudConnectionError`)}function S(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=x(t);return(0,h.jsxs)(`span`,{className:we(`quickforge-settings-badge`,n===f(`cloudConnectionUnknown`)?`quickforge-settings-badge-muted`:S(t)?`quickforge-settings-badge-success`:`quickforge-settings-badge-danger`),children:[e,`: `,n]})}function Re(e){let t=e.quickforgeCapabilities;return[t?.tools?f(`cloudCapabilityTools`):void 0,t?.vision?f(`cloudCapabilityVision`):void 0,t?.reasoning?f(`cloudCapabilityReasoning`):void 0].filter(Boolean).join(` · `)||f(`cloudCapabilityText`)}function ze(e){return f(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=m(t);return{message:r===f(`cloudRequestFailed`)?f(n):r,unavailable:!(`code`in Object(t))||[`cloud_request_failed`,`cloud_unavailable`].includes(String(t?.code||``))}}function C({error:e,onRetry:n,disabled:r}){return(0,h.jsxs)(`div`,{className:`p-4 text-sm`,children:[(0,h.jsx)(`div`,{className:`quickforge-settings-error`,children:e.message}),(0,h.jsxs)(l,{type:`button`,variant:`outline`,size:`sm`,className:`mt-3`,onClick:n,disabled:r,children:[(0,h.jsx)(t,{className:`mr-2 size-4`}),f(`retry`)]})]})}function w(){let[e,a]=(0,p.useState)(),[o,s]=(0,p.useState)(``),[Se,d]=(0,p.useState)(!1),[y,x]=(0,p.useState)(),[S,w]=(0,p.useState)(),[T,Ve]=(0,p.useState)(),[E,D]=(0,p.useReducer)(Oe,De),[O,He]=(0,p.useState)(!0),[k,A]=(0,p.useState)(``),[Ue,j]=(0,p.useState)(``),[M,N]=(0,p.useState)(``),[We,P]=(0,p.useState)(``),[Ge,Ke]=(0,p.useState)(0),F=(0,p.useRef)(0),I=(0,p.useRef)(0),L=S?.pendingDeviceFlow,R=L?Math.max(0,Math.ceil((L.expiresAt-Ge)/1e3)):0,z=(0,p.useCallback)(()=>D({type:`clear`}),[]),B=(0,p.useCallback)(async()=>{let e=++I.current;try{let t=await Te();e===I.current&&Ve(t)}catch{}},[]),V=(0,p.useCallback)(async(e=!0,t=!1,n=!0)=>{let r=++F.current;e&&He(!0),N(``),D({type:`begin`}),n&&B();try{let[e,n]=await Promise.all([ve(),pe()]);if(r!==F.current)return;if(a(e),t||s(e.cloudUrl),w(n),!e.enabled||!n.configured||!n.hasSession||n.sessionServiceMismatch){z();return}let i=await ke({usage:be,installations:fe,models:me},Be);if(r!==F.current)return;D({type:`replace`,state:i})}catch(e){if(r!==F.current)return;a(void 0),w(void 0),z(),N(m(e,`cloudLoadFailed`))}finally{r===F.current&&He(!1)}},[z,B]);(0,p.useEffect)(()=>{let e=window.setTimeout(()=>{V()},0);return()=>{window.clearTimeout(e),F.current+=1,I.current+=1}},[V]),(0,p.useEffect)(()=>{if(!e?.enabled||!Me(T?.status))return;let t=window.setInterval(()=>{B()},1750);return()=>window.clearInterval(t)},[e?.enabled,B,T?.status]),(0,p.useEffect)(()=>{let e=()=>{document.visibilityState===`visible`&&B()};return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[B]),(0,p.useEffect)(()=>{if(!e?.enabled||!S?.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,S?.pendingDeviceFlow]),(0,p.useEffect)(()=>{let t=S?.pendingDeviceFlow;if(!e?.enabled||!t||R>0)return;let n=window.setTimeout(()=>{V(!1)},0);return()=>window.clearTimeout(n)},[e?.enabled,R,V,S?.pendingDeviceFlow]),(0,p.useEffect)(()=>{let t=S?.pendingDeviceFlow;if(!e?.enabled||!t||k===`device-start`||k===`device-cancel`)return;let n=Math.max(1,Number(t.interval)||5)*1e3,r=window.setTimeout(async()=>{try{let e=await xe();w(e),e.deviceFlowResult===`success`?(window.dispatchEvent(new Event(_e)),N(``),j(f(`cloudDeviceFlowSucceeded`)),await Promise.all([V(!1,!1,!1),B()])):e.deviceFlowResult===`denied`?N(f(`cloudDeviceFlowDenied`)):e.deviceFlowResult===`expired`?N(f(`cloudDeviceFlowExpired`)):e.deviceFlowResult===`network`&&N(f(`cloudDeviceFlowNetwork`))}catch(e){N(m(e))}},n);return()=>window.clearTimeout(r)},[k,e?.enabled,V,B,S?.pendingDeviceFlow]);let H=()=>window.dispatchEvent(new Event(_e)),qe=async()=>{if(!k){if(b(o)){d(!0);return}A(`test`),j(``),N(``),x(void 0);try{let e=await Ee(o);s(e.cloudUrl),x(e),j(f(`cloudConnectionTestSucceeded`))}catch(e){N(m(e,`cloudConnectionFailed`))}finally{A(``)}}},Je=async()=>{if(!k){if(b(o)){d(!0);return}A(`save`),j(``),N(``);try{let e=await u({cloudUrl:o});a(e),s(e.cloudUrl),x(void 0),P(``),H(),j(f(`cloudConnectionSaved`)),await V(!1)}catch(e){N(m(e))}finally{A(``)}}},Ye=async t=>{if(!(k||!e||e.enabled===t)){A(`cloud-toggle`),j(``),N(``),P(``);try{let e=await u({enabled:t});a(e),s(e.cloudUrl),x(void 0),e.enabled||z(),H(),j(f(e.enabled?`cloudServiceEnabledSaved`:`cloudServiceDisabledSaved`)),await V(!1)}catch(e){N(m(e))}finally{A(``)}}},Xe=async()=>{let t=o.trim()||e?.cloudUrl||``;if(b(t)){d(!0);return}if(!(!await c({title:f(`cloudForceSwitchTitle`),description:f(`cloudForceSwitchDescription`),confirmLabel:f(`cloudForceSwitchConfirm`),cancelLabel:f(`cancel`),variant:`destructive`})||k||!t)){A(`force-switch`),j(``),N(``),P(``);try{let e=await Pe(t,{reset:he,save:e=>u({cloudUrl:e}),onIdentityReset:()=>{F.current+=1,w(e=>e&&{...e,mode:`local`,hasSession:!1,sessionServiceMismatch:!1}),z(),H()}});if(e.status===`url-save-failed`){let t=m(e.error);P(f(`cloudIdentityRebuiltUrlSaveFailed`)),await V(!1,!0),N(t);return}a(e.config),s(e.config.cloudUrl),x(void 0),H(),j(f(`cloudForceSwitchSucceeded`)),await V(!1)}catch(e){N(m(e))}finally{A(``)}}},Ze=async()=>{if(!k){A(`device-start`),j(``),N(``),P(``);try{w(await Ce()),H()}catch(e){N(m(e))}finally{A(``)}}},Qe=async()=>{if(!k){A(`device-cancel`),j(``),N(``);try{w(await ge()),j(f(`cloudDeviceFlowCancelled`))}catch(e){N(m(e))}finally{A(``)}}},$e=async()=>{let e=S?.pendingDeviceFlow?.userCode;if(e)try{await navigator.clipboard.writeText(e),j(f(`cloudDeviceCodeCopied`))}catch{N(f(`copyFailed`))}},et=async()=>{if(!(!await c({title:f(`cloudLogoutTitle`),description:f(`cloudLogoutDescription`),confirmLabel:f(`cloudLogout`),cancelLabel:f(`cancel`),variant:`destructive`})||k)){A(`logout`),j(``),N(``),P(``);try{await ye(),F.current+=1,z(),w(e=>e&&{...e,mode:`local`,hasSession:!1,sessionServiceMismatch:!1}),H(),j(f(`cloudLoggedOut`)),await V(!1)}catch(e){N(m(e))}finally{A(``)}}},tt=async e=>{let t=_(e);if(!(!t||t===S?.installationId||k)&&await c({description:f(`cloudRevokeDeviceConfirm`,{name:v(e)}),confirmLabel:f(`cloudRevokeDevice`),cancelLabel:f(`cancel`),variant:`destructive`})){A(t),j(``),N(``);try{await ue(t),D({type:`replace`,state:{...E,installations:E.installations.filter(e=>_(e)!==t)}}),j(f(`cloudDeviceRevoked`))}catch(e){N(m(e))}finally{A(``)}}},U=e?.enabled===!0,nt=!!(S?.configured&&S.hasSession),W=S?.sessionServiceMismatch===!0,G=nt&&!W,K=!!(e?.cloudUrl&&o.trim()&&e.cloudUrl!==o.trim()),q=b(o),J=!!(q&&Se),rt=Ae({loading:O,loadError:M,status:S,details:E}),Y=je(S),X=rt===`cloud-unavailable`,it=W?f(`cloudSessionMismatchLabel`):S?.mode===`account`?f(`cloudFormalAccount`):f(`cloudNotConnected`),at=ze(T?.status),ot=T?.status===`running`?`quickforge-settings-badge-success`:T?.status===`authorizing`||T?.status===`starting`?`quickforge-settings-badge-info`:T?.status===`error`||T?.status===`conflict`?`quickforge-settings-badge-warning`:`quickforge-settings-badge-muted`,st=U?S?.configured?f(W?`cloudSessionServiceMismatch`:G?X?`cloudUnavailableDescription`:`cloudConnectedDescription`:`cloudLocalOnlyDescription`):f(`cloudNotConfiguredDescription`):f(`cloudServiceDisabledDescription`),Z=()=>{V()},Q=O||E.loading,$=new Map;for(let e of E.installations){let t=v(e);$.set(t,($.get(t)??0)+1)}let ct=[...$.entries()].filter(([,e])=>e>1),lt=ct.reduce((e,[,t])=>e+t,0);return(0,h.jsxs)(`div`,{className:`quickforge-settings-stack`,children:[(0,h.jsxs)(`div`,{className:`quickforge-settings-heading`,children:[(0,h.jsx)(`div`,{children:(0,h.jsxs)(`h2`,{className:`quickforge-settings-title`,children:[(0,h.jsx)(ce,{className:`size-5`}),f(`cloudAccount`)]})}),(0,h.jsxs)(l,{variant:`outline`,size:`sm`,onClick:()=>void V(),disabled:O||!!k,className:`quickforge-settings-heading-action`,children:[(0,h.jsx)(t,{className:`mr-2 size-4 ${O?`animate-spin`:``}`}),f(`refresh`)]})]}),Ue?(0,h.jsx)(`div`,{className:`quickforge-settings-message`,children:Ue}):null,We?(0,h.jsx)(`div`,{className:`quickforge-settings-warning`,children:We}):null,M?(0,h.jsx)(`div`,{className:`quickforge-settings-error`,children:M}):null,(0,h.jsxs)(`div`,{className:`quickforge-settings-section`,children:[(0,h.jsxs)(`div`,{className:`quickforge-settings-list-header`,children:[(0,h.jsxs)(`div`,{className:`quickforge-settings-row-title`,children:[(0,h.jsx)(te,{className:`size-4`}),f(`cloudServiceConnection`)]}),(0,h.jsx)(`span`,{className:`quickforge-settings-badge quickforge-settings-badge-info shrink-0`,children:`QuickForge Cloud`})]}),(0,h.jsxs)(`div`,{className:`quickforge-settings-row`,children:[(0,h.jsxs)(`div`,{className:`quickforge-settings-row-main`,children:[(0,h.jsx)(`div`,{className:`quickforge-settings-row-title`,children:f(`cloudServiceEnabled`)}),(0,h.jsx)(`div`,{className:`quickforge-settings-row-description`,children:f(`cloudServiceEnabledDescription`)})]}),(0,h.jsx)(`div`,{className:`quickforge-settings-row-control`,children:(0,h.jsxs)(`label`,{className:`quickforge-settings-switch`,"aria-label":f(`cloudServiceEnabled`),children:[(0,h.jsx)(`input`,{type:`checkbox`,checked:U,disabled:!e||!!k,onChange:e=>{Ye(e.target.checked)}}),(0,h.jsx)(`span`,{"aria-hidden":`true`})]})})]}),(0,h.jsxs)(`div`,{className:`quickforge-settings-row items-start`,children:[(0,h.jsx)(`div`,{className:`quickforge-settings-row-main`,children:(0,h.jsx)(`label`,{className:`quickforge-settings-row-title h-9 whitespace-nowrap`,htmlFor:`quickforge-cloud-url`,children:f(`cloudUrl`)})}),(0,h.jsxs)(`div`,{className:`quickforge-settings-row-control w-full max-w-xl flex-col items-stretch gap-2`,children:[(0,h.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,h.jsx)(de,{id:`quickforge-cloud-url`,value:o,onChange:e=>s(e.target.value),onKeyDown:e=>{e.key===`Enter`&&o.trim()&&K&&!k&&(e.preventDefault(),Je())},placeholder:f(`cloudUrlPlaceholder`),inputMode:`url`,autoCapitalize:`none`,autoCorrect:`off`,spellCheck:!1,onBlur:()=>d(!0),"aria-invalid":J,className:we(`min-w-0 flex-1`,J?`border-destructive`:void 0),disabled:!!k}),(0,h.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[(0,h.jsxs)(l,{variant:`outline`,size:`sm`,onClick:()=>void qe(),disabled:!o.trim()||!!q||!!k,children:[k===`test`?(0,h.jsx)(t,{className:`mr-2 size-4 animate-spin`}):(0,h.jsx)(ae,{className:`mr-2 size-4`}),f(`cloudTestConnection`)]}),(0,h.jsxs)(l,{size:`sm`,onClick:()=>void Je(),disabled:!o.trim()||!K||!!q||!!k,children:[k===`save`?(0,h.jsx)(t,{className:`mr-2 size-4 animate-spin`}):(0,h.jsx)(ie,{className:`mr-2 size-4`}),f(`saveChanges`)]})]})]}),J?(0,h.jsx)(`div`,{className:`text-xs text-destructive`,children:q}):null,(0,h.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[f(`cloudConfigSource`),`: `,Ie(e?.source)]}),Ne(S,K)&&!q?(0,h.jsx)(`div`,{className:`quickforge-settings-cloud-force-switch flex justify-end`,children:(0,h.jsxs)(l,{variant:`destructive`,size:`sm`,onClick:()=>void Xe(),disabled:!!k,title:f(`cloudForceSwitchDescription`),children:[(0,h.jsx)(i,{className:`mr-2 size-4`}),f(`cloudForceSwitch`)]})}):null]})]}),e?.configurationError?(0,h.jsx)(`div`,{className:`quickforge-settings-error m-3`,children:f(`cloudConfigurationError`)}):null,y?(0,h.jsxs)(`div`,{className:`quickforge-settings-row`,children:[(0,h.jsxs)(`div`,{className:`quickforge-settings-row-main`,children:[(0,h.jsx)(`div`,{className:`quickforge-settings-row-title`,children:f(`cloudConnectionTestResult`)}),(0,h.jsx)(`div`,{className:`quickforge-settings-row-description break-all`,children:y.cloudUrl})]}),(0,h.jsxs)(`div`,{className:`quickforge-settings-row-control flex-wrap justify-end gap-1.5`,children:[Le(f(`cloudHealth`),y.health),Le(f(`cloudReady`),y.ready)]})]}):null]}),U?(0,h.jsxs)(`div`,{className:`quickforge-settings-section`,children:[(0,h.jsxs)(`div`,{className:`quickforge-settings-row`,children:[(0,h.jsxs)(`div`,{className:`quickforge-settings-row-main`,children:[(0,h.jsxs)(`div`,{className:`quickforge-settings-row-title`,children:[(0,h.jsx)(ee,{className:`size-4`}),f(`cloudRemoteAccess`)]}),(0,h.jsx)(`div`,{className:`quickforge-settings-row-description`,children:f(`cloudRemoteAccessDescription`)})]}),(0,h.jsx)(`div`,{className:`quickforge-settings-row-control`,children:(0,h.jsx)(`span`,{className:`quickforge-settings-badge ${ot}`,children:at})})]}),T?.serverUrl?(0,h.jsxs)(`div`,{className:`quickforge-settings-row`,children:[(0,h.jsx)(`div`,{className:`quickforge-settings-row-main`,children:(0,h.jsx)(`div`,{className:`quickforge-settings-row-title`,children:f(`cloudRemoteServerUrl`)})}),(0,h.jsx)(`div`,{className:`quickforge-settings-row-control break-all text-sm text-muted-foreground`,children:T.serverUrl})]}):null,T?.pid?(0,h.jsxs)(`div`,{className:`quickforge-settings-row`,children:[(0,h.jsx)(`div`,{className:`quickforge-settings-row-main`,children:(0,h.jsx)(`div`,{className:`quickforge-settings-row-title`,children:f(`cloudRemotePid`)})}),(0,h.jsx)(`div`,{className:`quickforge-settings-row-control text-sm font-medium`,children:T.pid})]}):null,T?.status===`authorizing`&&T.verificationUriComplete?(0,h.jsxs)(`div`,{className:`quickforge-settings-row`,children:[(0,h.jsx)(`div`,{className:`quickforge-settings-row-main`,children:(0,h.jsx)(`div`,{className:`quickforge-settings-row-title`,children:f(`cloudRemoteAuthorization`)})}),(0,h.jsx)(`div`,{className:`quickforge-settings-row-control`,children:(0,h.jsxs)(`a`,{className:`inline-flex items-center gap-1 text-sm text-primary hover:underline`,href:T.verificationUriComplete,target:`_blank`,rel:`noreferrer`,children:[f(`cloudRemoteOpenAuthorization`),(0,h.jsx)(se,{className:`size-3.5`})]})})]}):null,T?.error?(0,h.jsx)(`div`,{className:`quickforge-settings-warning quickforge-settings-warning-attached`,children:T.error}):null]}):null,(0,h.jsxs)(`div`,{className:`quickforge-settings-section`,children:[(0,h.jsxs)(`div`,{className:`quickforge-settings-row`,children:[(0,h.jsxs)(`div`,{className:`quickforge-settings-row-main`,children:[(0,h.jsxs)(`div`,{className:`quickforge-settings-row-title`,children:[(0,h.jsx)(oe,{className:`size-4`}),f(`cloudIdentityStatus`)]}),(0,h.jsx)(`div`,{className:`quickforge-settings-row-description`,children:st})]}),(0,h.jsx)(`div`,{className:`quickforge-settings-row-control`,children:(0,h.jsx)(`span`,{className:`quickforge-settings-badge ${G&&!X?`quickforge-settings-badge-success`:W||X?`quickforge-settings-badge-warning`:`quickforge-settings-badge-muted`}`,children:it})})]}),X?(0,h.jsx)(`div`,{className:`quickforge-settings-warning quickforge-settings-warning-attached`,children:f(`cloudUnavailableDescription`)}):null,W?(0,h.jsx)(`div`,{className:`quickforge-settings-warning quickforge-settings-warning-attached`,children:f(`cloudSessionServiceMismatch`)}):null,G?(0,h.jsxs)(h.Fragment,{children:[S?.mode===`account`?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`div`,{className:`quickforge-settings-row`,children:[(0,h.jsx)(`div`,{className:`quickforge-settings-row-main`,children:(0,h.jsx)(`div`,{className:`quickforge-settings-row-title`,children:f(`cloudAccountEmail`)})}),(0,h.jsx)(`div`,{className:`quickforge-settings-row-control text-sm font-medium`,children:S.account?.email||f(`cloudNotAvailable`)})]}),(0,h.jsxs)(`div`,{className:`quickforge-settings-row`,children:[(0,h.jsx)(`div`,{className:`quickforge-settings-row-main`,children:(0,h.jsx)(`div`,{className:`quickforge-settings-row-title`,children:f(`cloudAccountPlan`)})}),(0,h.jsx)(`div`,{className:`quickforge-settings-row-control text-sm font-medium`,children:S.account?.plan||f(`cloudNotAvailable`)})]})]}):null,U?E.errors.usage?(0,h.jsx)(C,{error:E.errors.usage,onRetry:Z,disabled:Q||!!k}):(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`div`,{className:`quickforge-settings-row`,children:[(0,h.jsx)(`div`,{className:`quickforge-settings-row-main`,children:(0,h.jsx)(`div`,{className:`quickforge-settings-row-title`,children:f(`cloudRemainingQuota`)})}),(0,h.jsx)(`div`,{className:`quickforge-settings-row-control text-sm font-medium`,children:Fe(E.usage?.remaining)})]}),(0,h.jsxs)(`div`,{className:`quickforge-settings-row`,children:[(0,h.jsx)(`div`,{className:`quickforge-settings-row-main`,children:(0,h.jsx)(`div`,{className:`quickforge-settings-row-title`,children:f(`cloudQuotaExpiresAt`)})}),(0,h.jsx)(`div`,{className:`quickforge-settings-row-control text-sm text-muted-foreground`,children:g(E.usage?.resetsAt||E.usage?.expiresAt)})]})]}):null,(0,h.jsxs)(`div`,{className:`quickforge-settings-row`,children:[(0,h.jsxs)(`div`,{className:`quickforge-settings-row-main`,children:[(0,h.jsx)(`div`,{className:`quickforge-settings-row-title`,children:f(`cloudLogout`)}),(0,h.jsx)(`div`,{className:`quickforge-settings-row-description`,children:f(`cloudLogoutRowDescription`)})]}),(0,h.jsx)(`div`,{className:`quickforge-settings-row-control`,children:(0,h.jsxs)(l,{variant:`destructive`,className:`quickforge-settings-cloud-logout`,onClick:()=>void et(),disabled:!!k,children:[(0,h.jsx)(n,{className:`mr-2 size-4`}),f(`cloudLogout`)]})})]})]}):null]}),!U||!S?.configured?null:Y.showDeviceFlow&&L?(0,h.jsxs)(`div`,{className:`quickforge-settings-section`,children:[(0,h.jsxs)(`div`,{className:`quickforge-settings-list-header`,children:[(0,h.jsxs)(`div`,{className:`quickforge-settings-row-main`,children:[(0,h.jsxs)(`div`,{className:`quickforge-settings-row-title`,children:[(0,h.jsx)(re,{className:`size-4`}),f(`cloudDeviceFlowTitle`)]}),(0,h.jsx)(`div`,{className:`quickforge-settings-row-description`,children:f(`cloudDeviceFlowDescription`)})]}),(0,h.jsx)(`span`,{className:`quickforge-settings-badge quickforge-settings-badge-info`,children:f(`cloudDeviceFlowCountdown`,{seconds:R})})]}),(0,h.jsxs)(`div`,{className:`quickforge-settings-row items-start`,children:[(0,h.jsxs)(`div`,{className:`quickforge-settings-row-main`,children:[(0,h.jsx)(`div`,{className:`quickforge-settings-row-description`,children:f(`cloudDeviceCode`)}),(0,h.jsx)(`div`,{className:`mt-1 font-mono text-2xl font-semibold tracking-[0.18em] text-foreground`,children:L.userCode})]}),(0,h.jsxs)(`div`,{className:`quickforge-settings-row-control flex-wrap gap-2`,children:[(0,h.jsxs)(l,{variant:`outline`,size:`sm`,onClick:()=>void $e(),children:[(0,h.jsx)(le,{className:`mr-2 size-4`}),f(`copy`)]}),(0,h.jsxs)(l,{size:`sm`,onClick:()=>window.open(L.verificationUriComplete||L.verificationUri,`_blank`,`noopener,noreferrer`),children:[(0,h.jsx)(se,{className:`mr-2 size-4`}),f(`cloudOpenVerificationPage`)]}),(0,h.jsx)(l,{variant:`outline`,size:`sm`,onClick:()=>void Qe(),disabled:!!k,children:f(`cancel`)})]})]}),S.deviceFlowResult===`slow_down`?(0,h.jsx)(`div`,{className:`quickforge-settings-warning quickforge-settings-warning-attached`,children:f(`cloudDeviceFlowSlowDown`)}):null]}):Y.showDisconnectedActions?(0,h.jsx)(`div`,{className:`quickforge-settings-section`,children:(0,h.jsxs)(`div`,{className:`quickforge-settings-row`,children:[(0,h.jsxs)(`div`,{className:`quickforge-settings-row-main`,children:[(0,h.jsxs)(`div`,{className:`quickforge-settings-row-title`,children:[(0,h.jsx)(re,{className:`size-4`}),f(`cloudLoginOrRegister`)]}),(0,h.jsx)(`div`,{className:`quickforge-settings-row-description`,children:f(`cloudLoginOrRegisterDescription`)})]}),(0,h.jsx)(`div`,{className:`quickforge-settings-row-control`,children:(0,h.jsxs)(l,{onClick:()=>void Ze(),disabled:O||!!k,children:[(0,h.jsx)(r,{className:`mr-2 size-4`}),f(`cloudLoginOrRegister`)]})})]})}):Y.showDetails?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`div`,{className:`quickforge-settings-section`,children:[(0,h.jsx)(`div`,{className:`quickforge-settings-list-header`,children:(0,h.jsxs)(`div`,{className:`quickforge-settings-row-title`,children:[(0,h.jsx)(ne,{className:`size-4`}),f(`cloudModels`)]})}),E.errors.models?(0,h.jsx)(C,{error:E.errors.models,onRetry:Z,disabled:Q||!!k}):E.models.length===0?(0,h.jsx)(`div`,{className:`p-6 text-center text-sm text-muted-foreground`,children:f(Q?`loading`:`cloudNoModels`)}):E.models.map(e=>(0,h.jsx)(`div`,{className:`quickforge-settings-list-item`,children:(0,h.jsxs)(`div`,{className:`quickforge-settings-list-item-main`,children:[(0,h.jsx)(`div`,{className:`text-sm font-medium`,children:e.name||e.id}),(0,h.jsxs)(`div`,{className:`quickforge-settings-row-description`,children:[e.id,` · `,Re(e)]})]})},`${e.provider}:${e.id}`))]}),(0,h.jsxs)(`div`,{className:`quickforge-settings-section`,children:[(0,h.jsx)(`div`,{className:`quickforge-settings-list-header`,children:(0,h.jsxs)(`div`,{className:`quickforge-settings-row-title`,children:[(0,h.jsx)(ee,{className:`size-4`}),f(`cloudDevices`)]})}),lt>1?(0,h.jsx)(`div`,{className:`quickforge-settings-warning quickforge-settings-warning-attached`,children:f(`cloudDuplicateDevicesHint`,{count:lt,name:ct[0][0]})}):null,E.errors.installations?(0,h.jsx)(C,{error:E.errors.installations,onRetry:Z,disabled:Q||!!k}):E.installations.length===0?(0,h.jsx)(`div`,{className:`p-6 text-center text-sm text-muted-foreground`,children:f(Q?`loading`:`cloudNoDevices`)}):E.installations.map(e=>{let t=_(e),n=e.current===!0||t===S?.installationId;return(0,h.jsxs)(`div`,{className:`quickforge-settings-list-item`,children:[(0,h.jsxs)(`div`,{className:`quickforge-settings-list-item-main`,children:[(0,h.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,h.jsx)(`div`,{className:`truncate text-sm font-medium`,children:v(e)}),n?(0,h.jsx)(`span`,{className:`quickforge-settings-badge quickforge-settings-badge-info`,children:f(`cloudCurrentDevice`)}):null]}),(0,h.jsx)(`div`,{className:`quickforge-settings-row-description`,children:[e.platform,e.createdAt?`${f(`cloudRegisteredAt`)} ${g(e.createdAt)}`:void 0,e.lastSeenAt?`${f(`cloudLastSeenAt`)} ${g(e.lastSeenAt)}`:void 0,t?`#${t.slice(0,8)}`:void 0].filter(Boolean).join(` · `)||f(`cloudNotAvailable`)})]}),(0,h.jsx)(`div`,{className:`quickforge-settings-list-item-actions`,children:(0,h.jsx)(l,{variant:`outline`,size:`sm`,onClick:()=>void tt(e),disabled:n||!!k,children:f(`cloudRevokeDevice`)})})]},t||v(e))})]})]}):null]})}export{w as CloudAccountSettingsPage};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{A as t,Dt as n,Lt as r,Rt as i,Tt as a,Wt as o,at as ee,d as te,ft as ne,mt as re,qt as s,s as ie,t as ae,y as oe}from"./icons-2D18YbSI.js";import{n as c}from"./react-vendor-3UaA-C9W.js";import{t as se}from"./model-display-label-C6-0eDxF.js";import{n as ce,r as le,t as ue}from"./model-reference-o41fJ6jQ.js";import{$t as de,Qt as l,Tt as fe,fn as pe,hn as u,ln as d,mn as f,nn as me,tn as he,yn as p}from"./index-BTPzyq7d.js";import{i as m,n as h,t as ge}from"./model-identity-CgA6_Pbm.js";var g=e(s(),1),_=c(),_e=[{value:`off`,label:()=>p(`thinkingOff`)},{value:`low`,label:()=>p(`thinkingLow`)},{value:`medium`,label:()=>p(`thinkingMedium`)},{value:`high`,label:()=>p(`thinkingHigh`)},{value:`xhigh`,label:()=>p(`thinkingXHigh`)}];function ve(e,t){return m(e,t)}function v(e){return String(e).padStart(2,`0`)}function y(e){if(!e)return`-`;let t=new Date(e);return Number.isNaN(t.getTime())?`-`:`${t.getFullYear()}-${v(t.getMonth()+1)}-${v(t.getDate())} ${v(t.getHours())}:${v(t.getMinutes())}`}function ye(e,t=20){let n=String(e||``).trim();return n.length>t?`${n.slice(0,t)}...`:n}function be(){return{scheduleText:``,title:``,instruction:``,cronExpression:``,scheduleRule:``,nextRunAt:``,enabled:!0,agentId:``,executionMode:`serial`}}function b(){return{taskId:``,status:``,trigger:``,keyword:``,startedFrom:``,startedTo:``,page:1,pageSize:10}}function xe(e){return{scheduleText:[e.scheduleRule,e.instruction].filter(Boolean).join(`
|
|
2
|
-
`),title:e.title,instruction:e.instruction,cronExpression:e.cronExpression??``,scheduleRule:e.scheduleRule,nextRunAt:e.nextRunAt,enabled:e.status!==`paused`,agentId:e.agentId??``,executionMode:e.executionMode??`serial`}}function Se(e,t){return{...t,title:e.title,instruction:e.instruction,cronExpression:e.cronExpression??``,scheduleRule:e.scheduleRule,nextRunAt:e.nextRunAt,enabled:t.enabled}}function Ce(e){return{title:e.title.trim(),instruction:e.instruction.trim(),scheduleType:`cron`,scheduleRule:e.scheduleRule.trim()||e.cronExpression.trim(),cronExpression:e.cronExpression.trim(),nextRunAt:e.nextRunAt,enabled:e.enabled,agentId:e.agentId||null,executionMode:e.executionMode}}function x(e){return!!(e.currentRunId||e.currentRunIds?.length)}function we(e){return(e.executionMode??`serial`)===`parallel`||!x(e)}function Te(e){return p(e===`parallel`?`taskExecutionModeParallel`:`taskExecutionModeSerial`)}function Ee(e){return!!(e.title.trim()&&e.instruction.trim()&&e.cronExpression.trim())}function De(e){return p(e===`enabled`?`taskEnabled`:e===`running`?`taskRunning`:e===`paused`?`taskPaused`:e===`completed`?`taskFinished`:e===`success`?`executionSuccess`:`taskFailed`)}function Oe(e){return e===`enabled`||e===`success`?`bg-emerald-500/10 text-emerald-700`:e===`running`?`bg-blue-500/10 text-blue-700`:e===`paused`?`bg-amber-500/10 text-amber-700`:`bg-muted text-muted-foreground`}async function S(e,t){let n=await fetch(e,{...t,headers:{"content-type":`application/json`,...t?.headers}}),r=await n.json().catch(()=>null);if(!n.ok)throw Error(r?.error||`请求失败`);return r}function C({onOpenSession:e}){let[s,c]=(0,g.useState)([]),[m,v]=(0,g.useState)(`tasks`),[C,w]=(0,g.useState)(()=>be()),[T,ke]=(0,g.useState)(null),[E,D]=(0,g.useState)(null),[O,k]=(0,g.useState)(null),[A,j]=(0,g.useState)(!1),[M,N]=(0,g.useState)(null),[Ae,P]=(0,g.useState)(``),[F,I]=(0,g.useState)(!1),[L,R]=(0,g.useState)(``),[z,je]=(0,g.useState)([]),[B,V]=(0,g.useState)(),[Me,H]=(0,g.useState)(`off`),[Ne,Pe]=(0,g.useState)([]),[Fe,Ie]=(0,g.useState)(``),[U,W]=(0,g.useState)(()=>b()),[G,K]=(0,g.useState)(()=>b()),[q,Le]=(0,g.useState)({runs:[],total:0,page:1,pageSize:10}),[Re,ze]=(0,g.useState)(!1),[Be,Ve]=(0,g.useState)(null),[He,Ue]=(0,g.useState)([]),We=Ne[0]?.id??``;(0,g.useEffect)(()=>{if(!O)return;let e=()=>k(null);return window.addEventListener(`click`,e),window.addEventListener(`blur`,e),()=>{window.removeEventListener(`click`,e),window.removeEventListener(`blur`,e)}},[O]);async function Ge(){c((await S(`/api/scheduled-tasks`)).tasks)}async function J(e=G){ze(!0),R(``);try{let t=new URLSearchParams;t.set(`page`,String(e.page)),t.set(`pageSize`,String(e.pageSize)),e.taskId&&t.set(`taskId`,e.taskId),e.status&&t.set(`status`,e.status),e.trigger&&t.set(`trigger`,e.trigger),e.keyword.trim()&&t.set(`keyword`,e.keyword.trim()),e.startedFrom&&t.set(`startedFrom`,e.startedFrom),e.startedTo&&t.set(`startedTo`,e.startedTo),Le(await S(`/api/scheduled-tasks/runs?${t.toString()}`))}catch(e){R(e instanceof Error?e.message:p(`requestFailed`))}finally{ze(!1)}}(0,g.useEffect)(()=>{let e=!1;async function t(){try{let t=await S(`/api/project`);if(e)return;Pe(t.projects??[])}catch{}}return t(),()=>{e=!0}},[]),(0,g.useEffect)(()=>{let e=!1;async function t(){try{let t=await he(),[n,r]=await Promise.all([de(t),ue().catch(()=>[])]),i=r.length?r:n,a=i.filter(d),o=await me(t),ee=(o.model&&d(o.model)?a.find(e=>ve(e,o.model))||(le(o.model)?a.find(e=>e.quickforgeCatalogId===o.model.quickforgeCatalogId):void 0):void 0)??a[0];if(e)return;je(i),V(ee),H(o.thinkingLevel??l(ee))}catch(t){e||R(t instanceof Error?t.message:p(`requestFailed`))}}return t(),()=>{e=!0}},[]),(0,g.useEffect)(()=>{let e=!1,t=async()=>{try{let t=await S(`/api/scheduled-tasks`);e||c(t.tasks)}catch(t){e||R(t instanceof Error?t.message:p(`requestFailed`))}};t();let n=window.setInterval(t,10*1e3);return()=>{e=!0,window.clearInterval(n)}},[]),(0,g.useEffect)(()=>{let e=!1;async function t(){try{let t=await S(`/api/agent-profiles`);if(e)return;Ue(t.agents)}catch(t){e||R(t instanceof Error?t.message:p(`requestFailed`))}}return t(),()=>{e=!0}},[]);let Ke=(0,g.useMemo)(()=>s.find(e=>e.id===T),[T,s]),qe=(0,g.useMemo)(()=>z.filter(d),[z]),Je=(0,g.useMemo)(()=>ge(qe,B),[qe,B]),Y=(0,g.useMemo)(()=>s.find(e=>e.id===E)??null,[E,s]),Ye=(0,g.useMemo)(()=>s.filter(e=>e.status===`enabled`).length,[s]),Xe=Math.max(1,Math.ceil(q.total/q.pageSize));function Ze(e){return e?He.find(t=>t.id===e||t.name===e)?.label??e:p(`defaultAgent`)}function X(e,t){w(n=>({...n,[e]:t}))}function Z(e,t){W(n=>({...n,[e]:t}))}function Qe(){let e=z.find(d);ke(null),Ie(We),V(e),H(l(e)),w(be()),N(null),P(``),R(``)}function $e(){Qe(),j(!0)}function Q(){F||(j(!1),Qe())}function et(){let e={...U,page:1};W(e),K(e),J(e)}function tt(){let e=b();W(e),K(e),J(e)}function nt(e){let t=Math.min(Math.max(1,e),Xe),n={...G,page:t};W(n),K(n),J(n)}function rt(e){let t={...G,page:1,pageSize:e};W(t),K(t),J(t)}async function it(){let e=C.scheduleText.trim();if(e){I(!0),R(``);try{let t=await S(`/api/scheduled-tasks/parse`,{method:`POST`,body:JSON.stringify({instruction:e,modelRef:B?ce(B):void 0,model:B,thinkingLevel:Me})});if(t.needMoreInfo||!t.task){P(t.question||`请补充任务信息。`),N(null);return}let n=t.task;P(``),N(n),w(e=>Se(n,e))}catch(e){R(e instanceof Error?e.message:p(`requestFailed`))}finally{I(!1)}}}async function at(){if(Ee(C)){I(!0),R(``);try{let e=Ne.find(e=>e.id===Fe),t={task:Ce(C),modelRef:B?ce(B):void 0,model:B,thinkingLevel:Me,projectId:e?.id,projectName:e?.name};T?await S(`/api/scheduled-tasks/${encodeURIComponent(T)}`,{method:`PUT`,body:JSON.stringify(t)}):await S(`/api/scheduled-tasks`,{method:`POST`,body:JSON.stringify(t)}),Q(),await Ge(),m===`history`&&await J(G)}catch(e){R(e instanceof Error?e.message:p(`requestFailed`))}finally{I(!1)}}}function ot(e){k(null),ke(e.id),w(xe(e)),N(null),P(``),R(``),Ie(e.projectId??``),e.model&&V(e.model),e.thinkingLevel&&H(e.thinkingLevel),j(!0)}async function $(e,t){if(R(``),k(null),!(t===`delete`&&!await fe({description:p(`confirmDeleteTask`),confirmLabel:p(`confirmDelete`),cancelLabel:p(`cancel`),variant:`destructive`})))try{t===`delete`?(await S(`/api/scheduled-tasks/${encodeURIComponent(e)}`,{method:`DELETE`}),T===e&&Q(),E===e&&D(null)):await S(`/api/scheduled-tasks/${encodeURIComponent(e)}/${t}`,{method:`POST`}),await Ge(),m===`history`&&await J(G)}catch(e){R(e instanceof Error?e.message:p(`requestFailed`))}}function st(t){return(0,_.jsxs)(`div`,{className:`mt-2 space-y-2 text-xs text-muted-foreground`,children:[t.sessionId?(0,_.jsx)(f,{variant:`outline`,size:`sm`,onClick:()=>e?.(t.sessionId),children:p(`viewConversation`)}):null,(0,_.jsxs)(`div`,{children:[p(`executionAgent`),t.agentLabel||Ze(t.agentId)]}),t.warning?(0,_.jsx)(`div`,{className:`text-amber-600`,children:t.warning}):null,t.inputContent?(0,_.jsxs)(`div`,{children:[(0,_.jsx)(`div`,{className:`font-medium text-foreground`,children:p(`runInputContent`)}),(0,_.jsx)(`pre`,{className:`mt-1 max-h-32 overflow-auto whitespace-pre-wrap`,children:t.inputContent})]}):null,t.aiResult||t.result?(0,_.jsxs)(`div`,{children:[(0,_.jsx)(`div`,{className:`font-medium text-foreground`,children:p(`runAiResult`)}),(0,_.jsx)(`pre`,{className:`mt-1 max-h-48 overflow-auto whitespace-pre-wrap`,children:t.aiResult||t.result})]}):null,t.errorMessage?(0,_.jsx)(`div`,{className:`text-destructive`,children:t.errorMessage}):null,t.durationMs?(0,_.jsxs)(`div`,{children:[p(`runDuration`),t.durationMs,`ms`]}):null]})}return(0,_.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden bg-background`,children:[(0,_.jsxs)(`div`,{className:`border-b border-border px-6 py-5`,children:[(0,_.jsx)(`div`,{className:`flex flex-wrap items-center justify-end gap-3`,children:A||Y?(0,_.jsxs)(f,{variant:`outline`,onClick:()=>{A?Q():D(null)},children:[(0,_.jsx)(o,{className:`mr-1 size-4`}),p(`back`)]}):(0,_.jsx)(f,{onClick:$e,children:p(`createTask`)})}),!A&&!Y?(0,_.jsxs)(`div`,{className:`mt-4 flex flex-wrap gap-2`,children:[(0,_.jsxs)(`button`,{type:`button`,className:u(`rounded-full px-4 py-2 text-sm font-medium transition-colors`,m===`tasks`?`bg-primary text-primary-foreground`:`bg-muted text-muted-foreground hover:text-foreground`),onClick:()=>v(`tasks`),children:[p(`taskListTab`),` `,(0,_.jsx)(`span`,{className:`opacity-80`,children:s.length})]}),(0,_.jsx)(`button`,{type:`button`,className:u(`rounded-full px-4 py-2 text-sm font-medium transition-colors`,m===`history`?`bg-primary text-primary-foreground`:`bg-muted text-muted-foreground hover:text-foreground`),onClick:()=>{v(`history`),J(G)},children:p(`executionHistoryTab`)})]}):null]}),(0,_.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-6`,children:(0,_.jsx)(`div`,{className:`mx-auto max-w-5xl space-y-5`,children:A?(0,_.jsxs)(_.Fragment,{children:[(0,_.jsxs)(`div`,{className:`rounded-xl border border-border bg-card p-5 space-y-4`,children:[(0,_.jsxs)(`h2`,{className:`inline-flex items-center gap-1.5 text-base font-semibold text-foreground`,children:[p(Ke?`editTask`:`createTask`),(0,_.jsx)(pe,{label:p(`quickAiParseTask`)})]}),(0,_.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[p(`taskScheduleDescriptionLabel`),(0,_.jsx)(`textarea`,{className:`mt-1 min-h-24 w-full resize-y rounded-xl border border-input bg-background px-3 py-2 text-sm outline-none transition-colors placeholder:text-muted-foreground/65 focus:border-ring`,value:C.scheduleText,onChange:e=>X(`scheduleText`,e.target.value),placeholder:p(`taskScheduleDescriptionPlaceholder`)})]}),(0,_.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,_.jsxs)(f,{onClick:it,disabled:F||!B||!C.scheduleText.trim(),children:[(0,_.jsx)(te,{className:`mr-1 size-3.5`}),p(`aiParseTask`)]}),Ae?(0,_.jsx)(`span`,{className:`text-sm text-amber-600`,children:Ae}):null]}),(0,_.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,_.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[p(`taskTitleLabel`),(0,_.jsx)(`input`,{className:`mt-1 h-10 w-full rounded-md border border-input bg-background px-3 text-sm outline-none focus:border-ring`,value:C.title,onChange:e=>X(`title`,e.target.value),placeholder:p(`taskTitlePlaceholder`)})]}),(0,_.jsxs)(`div`,{className:`block text-sm font-medium text-foreground`,children:[p(`executionRule`),(0,_.jsx)(`div`,{className:`mt-1 flex h-10 items-center rounded-md border border-input bg-muted/20 px-3 text-sm text-muted-foreground`,children:C.scheduleRule||`-`})]}),(0,_.jsxs)(`div`,{className:`block text-sm font-medium text-foreground`,children:[`cron`,(0,_.jsx)(`div`,{className:`mt-1 flex h-10 items-center rounded-md border border-input bg-muted/20 px-3 font-mono text-sm text-muted-foreground`,children:C.cronExpression||`-`})]}),(0,_.jsxs)(`div`,{className:`block text-sm font-medium text-foreground`,children:[p(`nextExecutionTime`),(0,_.jsx)(`div`,{className:`mt-1 flex h-10 items-center rounded-md border border-input bg-muted/20 px-3 text-sm text-muted-foreground`,children:y(C.nextRunAt)})]}),(0,_.jsxs)(`label`,{className:`block text-sm font-medium text-foreground sm:col-span-2`,children:[(0,_.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[p(`taskExecutionMode`),(0,_.jsx)(pe,{label:p(`taskExecutionModeHelp`)})]}),(0,_.jsxs)(`select`,{className:`mt-1 h-10 w-full rounded-md border border-input bg-background px-3 text-sm text-foreground outline-none focus:border-ring`,value:C.executionMode,onChange:e=>X(`executionMode`,e.target.value),children:[(0,_.jsx)(`option`,{value:`serial`,children:p(`taskExecutionModeSerial`)}),(0,_.jsx)(`option`,{value:`parallel`,children:p(`taskExecutionModeParallel`)})]})]}),(0,_.jsxs)(`label`,{className:`block text-sm font-medium text-foreground sm:col-span-2`,children:[p(`promptContentLabel`),(0,_.jsx)(`textarea`,{className:`mt-1 min-h-28 w-full resize-y rounded-xl border border-input bg-background px-3 py-2 text-sm text-foreground outline-none transition-colors placeholder:text-muted-foreground/65 focus:border-ring`,value:C.instruction,onChange:e=>X(`instruction`,e.target.value),placeholder:p(`promptContentPlaceholder`)})]})]}),(0,_.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-foreground`,children:[(0,_.jsx)(`input`,{type:`checkbox`,checked:C.enabled,onChange:e=>X(`enabled`,e.target.checked)}),p(`taskEnabledSwitch`)]}),(0,_.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 rounded-xl border border-border bg-muted/20 px-2 py-2`,children:[(0,_.jsxs)(`span`,{className:`relative inline-flex items-center`,children:[(0,_.jsx)(te,{className:`pointer-events-none absolute left-2 size-3.5 text-muted-foreground/70`}),(0,_.jsxs)(`select`,{className:`h-8 max-w-[240px] rounded-md border border-transparent bg-transparent pl-7 pr-2 text-xs text-muted-foreground outline-none hover:bg-background focus:border-ring`,value:B?h(B):``,onChange:e=>{let t=Je.find(t=>h(t)===e.target.value);V(t),H(l(t))},title:p(`taskModel`),children:[Je.length===0?(0,_.jsx)(`option`,{value:``,children:p(`noModelAvailable`)}):null,Je.map(e=>(0,_.jsxs)(`option`,{value:h(e),children:[se(e),ve(e,B)?` ✓`:``]},h(e)))]})]}),(0,_.jsxs)(`span`,{className:`relative inline-flex items-center`,children:[(0,_.jsx)(r,{className:`pointer-events-none absolute left-2 size-3.5 text-muted-foreground/70`}),(0,_.jsx)(`select`,{className:`h-8 rounded-md border border-transparent bg-transparent pl-7 pr-2 text-xs text-muted-foreground outline-none hover:bg-background focus:border-ring`,value:Me,onChange:e=>H(e.target.value),title:p(`taskThinking`),children:_e.map(e=>(0,_.jsx)(`option`,{value:e.value,children:e.label()},e.value))})]}),(0,_.jsxs)(`span`,{className:`relative inline-flex items-center`,children:[(0,_.jsx)(ee,{className:`pointer-events-none absolute left-2 size-3.5 text-muted-foreground/70`}),(0,_.jsxs)(`select`,{className:`h-8 max-w-[220px] rounded-md border border-transparent bg-transparent pl-7 pr-2 text-xs text-muted-foreground outline-none hover:bg-background focus:border-ring`,value:Fe,onChange:e=>Ie(e.target.value),title:p(`taskProjectLabel`),children:[(0,_.jsx)(`option`,{value:``,children:p(`noProjectBound`)}),Ne.map(e=>(0,_.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,_.jsxs)(`span`,{className:`relative inline-flex items-center`,children:[(0,_.jsx)(i,{className:`pointer-events-none absolute left-2 size-3.5 text-muted-foreground/70`}),(0,_.jsxs)(`select`,{className:`h-8 max-w-[220px] rounded-md border border-transparent bg-transparent pl-7 pr-2 text-xs text-muted-foreground outline-none hover:bg-background focus:border-ring`,value:C.agentId,onChange:e=>X(`agentId`,e.target.value),title:p(`executionAgent`),children:[(0,_.jsx)(`option`,{value:``,children:p(`defaultAgent`)}),He.map(e=>(0,_.jsx)(`option`,{value:e.id,children:e.label},e.id))]})]})]}),M?(0,_.jsxs)(`div`,{className:`rounded-xl border border-border bg-muted/30 p-3 text-sm`,children:[(0,_.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 font-medium text-foreground`,children:[(0,_.jsx)(n,{className:`size-4 text-emerald-600`}),p(`aiParsed`)]}),(0,_.jsxs)(`div`,{className:`grid gap-2 text-muted-foreground sm:grid-cols-2`,children:[(0,_.jsxs)(`div`,{children:[p(`taskName`),(0,_.jsx)(`span`,{className:`text-foreground`,children:M.title})]}),(0,_.jsxs)(`div`,{children:[p(`executionRule`),(0,_.jsx)(`span`,{className:`text-foreground`,children:M.scheduleRule})]}),(0,_.jsxs)(`div`,{children:[`cron:`,(0,_.jsx)(`span`,{className:`font-mono text-foreground`,children:M.cronExpression??`-`})]}),(0,_.jsxs)(`div`,{children:[p(`nextExecutionTime`),(0,_.jsx)(`span`,{className:`text-foreground`,children:y(M.nextRunAt)})]}),(0,_.jsxs)(`div`,{className:`sm:col-span-2`,children:[p(`aiInstruction`),(0,_.jsx)(`span`,{className:`text-foreground`,children:M.instruction})]})]})]}):null,L?(0,_.jsx)(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive`,children:L}):null]}),(0,_.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,_.jsx)(f,{variant:`outline`,onClick:Q,disabled:F,children:p(`cancel`)}),(0,_.jsx)(f,{onClick:at,disabled:F||!B||!Ee(C),children:p(Ke?`saveTask`:`confirmCreate`)})]})]}):Y?(0,_.jsxs)(`div`,{className:`rounded-xl border border-border bg-card`,children:[(0,_.jsx)(`div`,{className:`flex flex-wrap items-start justify-between gap-3 border-b border-border px-5 py-4`,children:(0,_.jsxs)(`div`,{children:[(0,_.jsx)(`h2`,{className:`text-base font-semibold text-foreground`,children:Y.title}),(0,_.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:Y.scheduleRule})]})}),(0,_.jsx)(`div`,{className:`px-5 py-4`,children:(0,_.jsxs)(`div`,{className:`space-y-4 text-sm`,children:[(0,_.jsxs)(`div`,{children:[(0,_.jsx)(`div`,{className:`mb-1 font-medium text-foreground`,children:p(`taskContent`)}),(0,_.jsx)(`pre`,{className:`max-h-48 overflow-auto whitespace-pre-wrap rounded-xl border border-border bg-muted/20 p-3 text-muted-foreground`,children:Y.instruction})]}),(0,_.jsxs)(`div`,{className:`grid gap-3 text-muted-foreground sm:grid-cols-2`,children:[(0,_.jsxs)(`div`,{children:[p(`executionRule`),(0,_.jsx)(`span`,{className:`text-foreground`,children:Y.scheduleRule})]}),(0,_.jsxs)(`div`,{children:[p(`taskExecutionMode`),`:`,(0,_.jsx)(`span`,{className:`text-foreground`,children:Te(Y.executionMode)})]}),(0,_.jsxs)(`div`,{children:[`cron:`,(0,_.jsx)(`span`,{className:`font-mono text-foreground`,children:Y.cronExpression??`-`})]}),(0,_.jsxs)(`div`,{children:[p(`lastExecution`),(0,_.jsx)(`span`,{className:`text-foreground`,children:y(Y.lastRunAt)})]}),(0,_.jsxs)(`div`,{children:[p(`nextExecution`),(0,_.jsx)(`span`,{className:`text-foreground`,children:y(Y.nextRunAt)})]}),(0,_.jsxs)(`div`,{children:[p(`executionAgent`),(0,_.jsx)(`span`,{className:`text-foreground`,children:Ze(Y.agentId)})]}),Y.projectName?(0,_.jsxs)(`div`,{children:[p(`taskProject`),(0,_.jsx)(`span`,{className:`text-foreground`,children:Y.projectName})]}):null,Y.model?(0,_.jsxs)(`div`,{children:[p(`taskModel`),`:`,(0,_.jsx)(`span`,{className:`text-foreground`,children:se(Y.model)})]}):null,Y.thinkingLevel?(0,_.jsxs)(`div`,{children:[p(`taskThinkingLevel`),(0,_.jsx)(`span`,{className:`text-foreground`,children:_e.find(e=>e.value===Y.thinkingLevel)?.label()??Y.thinkingLevel})]}):null,(0,_.jsxs)(`div`,{children:[p(`createdAt`),`:`,(0,_.jsx)(`span`,{className:`text-foreground`,children:y(Y.createdAt)})]})]}),Y.runs?.length>0?(0,_.jsxs)(`div`,{children:[(0,_.jsx)(`div`,{className:`mb-2 font-medium text-foreground`,children:p(`recentExecutions`)}),(0,_.jsx)(`div`,{className:`space-y-2`,children:Y.runs.slice(0,5).map(e=>(0,_.jsxs)(`details`,{className:`rounded-lg border border-border bg-muted/20 p-2 text-xs text-muted-foreground`,children:[(0,_.jsxs)(`summary`,{className:`cursor-pointer text-foreground`,children:[y(e.startedAt),` · `,e.trigger===`manual`?p(`manualRun`):p(`autoRun`),` · `,De(e.status)]}),st(e)]},e.id))})]}):null]})}),(0,_.jsx)(`div`,{className:`border-t border-border px-5 py-4`,children:(0,_.jsxs)(`div`,{className:`flex flex-wrap justify-end gap-2`,children:[Y.lastSessionId?(0,_.jsx)(f,{variant:`outline`,onClick:()=>e?.(Y.lastSessionId),children:p(`viewConversation`)}):null,(0,_.jsxs)(f,{variant:`outline`,disabled:!we(Y),onClick:()=>void $(Y.id,`run`),children:[(0,_.jsx)(ae,{className:`mr-1 size-3.5`}),p(`executeNow`)]}),(0,_.jsxs)(f,{variant:`outline`,disabled:x(Y),onClick:()=>ot(Y),children:[(0,_.jsx)(t,{className:`mr-1 size-3.5`}),p(`editTask`)]}),(0,_.jsxs)(f,{variant:`destructive`,disabled:x(Y),onClick:()=>void $(Y.id,`delete`),children:[(0,_.jsx)(ie,{className:`mr-1 size-3.5`}),p(`deleteTask`)]})]})})]}):(0,_.jsxs)(_.Fragment,{children:[L?(0,_.jsx)(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive`,children:L}):null,m===`tasks`?(0,_.jsxs)(_.Fragment,{children:[(0,_.jsx)(`div`,{className:`rounded-xl border border-border bg-card p-4`,children:(0,_.jsx)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:(0,_.jsxs)(`div`,{children:[(0,_.jsx)(`h2`,{className:`text-base font-semibold text-foreground`,children:p(`taskList`)}),(0,_.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:p(`tasksCount`,{total:s.length,enabled:Ye})})]})})}),(0,_.jsx)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:s.length===0?(0,_.jsx)(`div`,{className:`rounded-lg px-3 py-3 text-center text-xs text-muted-foreground/55 md:col-span-2`,children:p(`noScheduledTasks`)}):s.map(e=>{let n=e.status===`enabled`,r=e.status===`completed`,o=x(e);return(0,_.jsxs)(`div`,{className:`relative cursor-pointer rounded-xl border border-border bg-card p-4 transition-colors hover:bg-muted/15`,onClick:()=>D(e.id),children:[(0,_.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,_.jsxs)(`div`,{className:`min-w-0`,children:[(0,_.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,_.jsx)(`h3`,{className:`truncate text-sm font-medium text-foreground/90`,children:e.title})}),(0,_.jsx)(`p`,{className:`mt-2 text-sm text-muted-foreground`,children:ye(e.instruction,20)})]}),(0,_.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,onClick:e=>e.stopPropagation(),children:[(0,_.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":n,disabled:r,className:u(`relative h-6 w-11 rounded-full transition-colors disabled:cursor-not-allowed disabled:opacity-60`,n?`bg-emerald-500`:`bg-muted-foreground/30`),onClick:()=>void $(e.id,e.status===`paused`?`resume`:`pause`),title:e.status===`paused`?p(`enable`):p(`pauseTask`),children:(0,_.jsx)(`span`,{className:u(`absolute left-0.5 top-0.5 size-5 rounded-full bg-white shadow transition-transform`,n?`translate-x-5`:`translate-x-0`)})}),(0,_.jsxs)(`div`,{className:`relative`,children:[(0,_.jsx)(f,{variant:`ghost`,size:`icon`,onClick:()=>k(O===e.id?null:e.id),title:p(`moreActions`),children:(0,_.jsx)(re,{className:`size-4`})}),O===e.id?(0,_.jsxs)(`div`,{className:`absolute right-0 z-20 mt-1 w-36 overflow-hidden rounded-xl border border-border bg-popover py-1 text-sm shadow-quickforge`,children:[(0,_.jsxs)(`button`,{className:`flex w-full items-center gap-2 px-3 py-2 text-left hover:bg-muted disabled:cursor-not-allowed disabled:opacity-50`,disabled:!we(e),onClick:()=>void $(e.id,`run`),children:[(0,_.jsx)(ae,{className:`size-3.5`}),p(`executeNow`)]}),(0,_.jsxs)(`button`,{className:`flex w-full items-center gap-2 px-3 py-2 text-left hover:bg-muted disabled:cursor-not-allowed disabled:opacity-50`,disabled:o,onClick:()=>ot(e),children:[(0,_.jsx)(t,{className:`size-3.5`}),p(`editTask`)]}),(0,_.jsxs)(`button`,{className:`flex w-full items-center gap-2 px-3 py-2 text-left hover:bg-muted`,onClick:()=>{k(null),D(e.id)},children:[(0,_.jsx)(ne,{className:`size-3.5`}),p(`viewDetails`)]}),(0,_.jsxs)(`button`,{className:`flex w-full items-center gap-2 px-3 py-2 text-left text-destructive hover:bg-muted disabled:cursor-not-allowed disabled:opacity-50`,disabled:o,onClick:()=>void $(e.id,`delete`),children:[(0,_.jsx)(ie,{className:`size-3.5`}),p(`deleteTask`)]})]}):null]})]})]}),(0,_.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-x-4 gap-y-1 text-xs text-muted-foreground`,children:[(0,_.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,_.jsx)(a,{className:`size-3`}),e.scheduleRule]}),(0,_.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,_.jsx)(i,{className:`size-3`}),Ze(e.agentId)]}),(0,_.jsxs)(`span`,{children:[p(`taskExecutionMode`),`:`,Te(e.executionMode)]}),e.projectName?(0,_.jsxs)(`span`,{children:[p(`taskProject`),e.projectName]}):null]}),(0,_.jsxs)(`div`,{className:`mt-4 grid gap-2 border-t border-border pt-3 text-xs text-muted-foreground sm:grid-cols-2`,children:[(0,_.jsxs)(`span`,{children:[p(`lastExecution`),y(e.lastRunAt)]}),(0,_.jsxs)(`span`,{children:[p(`nextExecution`),y(e.nextRunAt)]})]})]},e.id)})})]}):(0,_.jsxs)(`div`,{className:`space-y-4`,children:[(0,_.jsxs)(`div`,{className:`rounded-xl border border-border bg-card p-4`,children:[(0,_.jsxs)(`div`,{className:`mb-3 flex items-center gap-2 text-sm font-medium text-foreground`,children:[(0,_.jsx)(oe,{className:`size-4`}),p(`historyFilters`)]}),(0,_.jsxs)(`div`,{className:`grid gap-3 md:grid-cols-3`,children:[(0,_.jsxs)(`label`,{className:`block text-xs font-medium text-muted-foreground`,children:[p(`taskName`),(0,_.jsxs)(`select`,{className:`mt-1 h-9 w-full rounded-md border border-input bg-background px-2 text-sm text-foreground`,value:U.taskId,onChange:e=>Z(`taskId`,e.target.value),children:[(0,_.jsx)(`option`,{value:``,children:p(`allTasks`)}),s.map(e=>(0,_.jsx)(`option`,{value:e.id,children:e.title},e.id))]})]}),(0,_.jsxs)(`label`,{className:`block text-xs font-medium text-muted-foreground`,children:[p(`status`),(0,_.jsxs)(`select`,{className:`mt-1 h-9 w-full rounded-md border border-input bg-background px-2 text-sm text-foreground`,value:U.status,onChange:e=>Z(`status`,e.target.value),children:[(0,_.jsx)(`option`,{value:``,children:p(`allStatuses`)}),(0,_.jsx)(`option`,{value:`running`,children:p(`executionRunning`)}),(0,_.jsx)(`option`,{value:`success`,children:p(`executionSuccess`)}),(0,_.jsx)(`option`,{value:`failed`,children:p(`taskFailed`)})]})]}),(0,_.jsxs)(`label`,{className:`block text-xs font-medium text-muted-foreground`,children:[p(`triggerType`),(0,_.jsxs)(`select`,{className:`mt-1 h-9 w-full rounded-md border border-input bg-background px-2 text-sm text-foreground`,value:U.trigger,onChange:e=>Z(`trigger`,e.target.value),children:[(0,_.jsx)(`option`,{value:``,children:p(`allTriggers`)}),(0,_.jsx)(`option`,{value:`schedule`,children:p(`autoRun`)}),(0,_.jsx)(`option`,{value:`manual`,children:p(`manualRun`)})]})]}),(0,_.jsxs)(`label`,{className:`block text-xs font-medium text-muted-foreground`,children:[p(`startTime`),(0,_.jsx)(`input`,{type:`datetime-local`,className:`mt-1 h-9 w-full rounded-md border border-input bg-background px-2 text-sm text-foreground`,value:U.startedFrom,onChange:e=>Z(`startedFrom`,e.target.value)})]}),(0,_.jsxs)(`label`,{className:`block text-xs font-medium text-muted-foreground`,children:[p(`endTime`),(0,_.jsx)(`input`,{type:`datetime-local`,className:`mt-1 h-9 w-full rounded-md border border-input bg-background px-2 text-sm text-foreground`,value:U.startedTo,onChange:e=>Z(`startedTo`,e.target.value)})]}),(0,_.jsxs)(`label`,{className:`block text-xs font-medium text-muted-foreground`,children:[p(`keyword`),(0,_.jsx)(`input`,{className:`mt-1 h-9 w-full rounded-md border border-input bg-background px-2 text-sm text-foreground`,value:U.keyword,onChange:e=>Z(`keyword`,e.target.value),placeholder:p(`keywordPlaceholder`)})]})]}),(0,_.jsxs)(`div`,{className:`mt-3 flex justify-end gap-2`,children:[(0,_.jsx)(f,{variant:`outline`,onClick:tt,children:p(`reset`)}),(0,_.jsx)(f,{onClick:et,children:p(`query`)})]})]}),(0,_.jsxs)(`div`,{className:`overflow-x-auto rounded-xl border border-border bg-card`,children:[(0,_.jsxs)(`div`,{className:`grid min-w-[600px] grid-cols-[1.3fr_0.7fr_0.7fr_1fr_0.7fr] gap-3 border-b border-border px-4 py-3 text-xs font-medium text-muted-foreground`,children:[(0,_.jsx)(`span`,{children:p(`taskName`)}),(0,_.jsx)(`span`,{children:p(`status`)}),(0,_.jsx)(`span`,{children:p(`triggerType`)}),(0,_.jsx)(`span`,{children:p(`startTime`)}),(0,_.jsx)(`span`,{children:p(`runDuration`)})]}),Re?(0,_.jsx)(`div`,{className:`p-8 text-center text-sm text-muted-foreground`,children:p(`loading`)}):q.runs.length===0?(0,_.jsx)(`div`,{className:`p-8 text-center text-sm text-muted-foreground`,children:p(`noExecutionHistory`)}):q.runs.map(e=>(0,_.jsxs)(`div`,{className:`border-b border-border last:border-b-0`,children:[(0,_.jsxs)(`button`,{type:`button`,className:`grid w-full min-w-[600px] grid-cols-[1.3fr_0.7fr_0.7fr_1fr_0.7fr] gap-3 px-4 py-3 text-left text-sm hover:bg-muted/40`,onClick:()=>Ve(Be===e.id?null:e.id),children:[(0,_.jsx)(`span`,{className:`min-w-0 truncate text-foreground`,children:e.taskTitle}),(0,_.jsx)(`span`,{children:(0,_.jsx)(`span`,{className:u(`rounded-full px-2 py-0.5 text-xs`,Oe(e.status)),children:De(e.status)})}),(0,_.jsx)(`span`,{className:`text-muted-foreground`,children:e.trigger===`manual`?p(`manualRun`):p(`autoRun`)}),(0,_.jsx)(`span`,{className:`text-muted-foreground`,children:y(e.startedAt)}),(0,_.jsx)(`span`,{className:`text-muted-foreground`,children:e.durationMs?`${e.durationMs}ms`:`-`})]}),Be===e.id?(0,_.jsx)(`div`,{className:`border-t border-border bg-muted/20 px-4 py-3`,children:st(e)}):null]},`${e.taskId}:${e.id}`)),(0,_.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 px-4 py-3 text-sm text-muted-foreground`,children:[(0,_.jsx)(`span`,{children:p(`paginationSummary`,{page:q.page,pages:Xe,total:q.total})}),(0,_.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,_.jsx)(`select`,{className:`h-8 rounded-md border border-input bg-background px-2 text-sm`,value:q.pageSize,onChange:e=>rt(Number(e.target.value)),children:[10,20,50,100].map(e=>(0,_.jsx)(`option`,{value:e,children:p(`pageSize`,{size:e})},e))}),(0,_.jsx)(f,{variant:`outline`,size:`sm`,disabled:q.page<=1,onClick:()=>nt(q.page-1),children:p(`previousPage`)}),(0,_.jsx)(f,{variant:`outline`,size:`sm`,disabled:q.page>=Xe,onClick:()=>nt(q.page+1),children:p(`nextPage`)})]})]})]})]})]})})})]})}export{C as ScheduledTasksPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{A as t,C as n,T as r,Y as i,mt as a,pt as o,qt as s,s as c,y as l,yt as u}from"./icons-2D18YbSI.js";import{n as d}from"./react-vendor-3UaA-C9W.js";import{D as f,Dt as p,E as m,Tt as h,_ as g,b as _,g as v,mn as y,v as b,vn as x,w as S,x as C,y as w,yn as T}from"./index-BTPzyq7d.js";var E=e(s(),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(x())}function j(e){return T(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?g(t.hours):void 0}function P({share:e,onClose:t,onSaved:r}){let[i,a]=(0,E.useState)(e.permission),[o,s]=(0,E.useState)(``),[l,u]=(0,E.useState)(!1),[d,f]=(0,E.useState)(e.allowCloudUsage===!0),[p,h]=(0,E.useState)(`keep`),[g,v]=(0,E.useState)(!1),[b,x]=(0,E.useState)(``),S=i===`operate`,C=l?!1:!!(e.hasPassword||o.trim()),w=async()=>{if(S&&!C){x(T(`operateRequiresPassword`));return}v(!0),x(``);try{let n=l?``:o?o.trim():void 0,a=p===`keep`?void 0:N(p);r((await m(e.id,{permission:i,password:n,expiresAt:a,allowCloudUsage:i===`operate`&&d})).share),t()}catch(e){x(e instanceof Error?e.message:T(`requestFailed`)),v(!1)}};return(0,D.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/45 p-4`,onMouseDown:e=>{e.target===e.currentTarget&&t()},children:(0,D.jsxs)(`div`,{className:`flex max-h-[85vh] w-full max-w-md flex-col overflow-hidden rounded-2xl border border-border bg-background shadow-quickforge`,onMouseDown:e=>e.stopPropagation(),children:[(0,D.jsxs)(`div`,{className:`shrink-0 border-b border-border px-5 py-4`,children:[(0,D.jsx)(`h2`,{className:`text-base font-semibold`,children:T(`editShareTitle`)}),(0,D.jsx)(`p`,{className:`mt-1 truncate text-sm text-muted-foreground`,children:e.titleSnapshot||T(`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:T(`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 ${i===`read`?`border-primary bg-primary/10`:`border-border`}`,onClick:()=>a(`read`),children:[(0,D.jsx)(`div`,{className:`font-medium`,children:T(`sharePermissionRead`)}),(0,D.jsx)(`div`,{className:`mt-1 text-xs text-muted-foreground`,children:T(`sharePermissionReadHint`)})]}),(0,D.jsxs)(`button`,{type:`button`,className:`rounded-xl border p-3 text-left text-sm ${i===`operate`?`border-red-400 bg-red-50 text-red-950`:`border-border`}`,onClick:()=>a(`operate`),children:[(0,D.jsx)(`div`,{className:`font-medium text-red-700`,children:T(`sharePermissionOperate`)}),(0,D.jsx)(`div`,{className:`mt-1 text-xs text-red-700`,children:T(`sharePermissionOperateHint`)})]})]})]}),i===`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:T(`sharePasswordTitle`)}),(0,D.jsxs)(`div`,{className:`flex flex-col gap-3 sm:flex-row sm:items-center`,children:[(0,D.jsx)(`input`,{value:o,onChange:e=>s(e.target.value),disabled:l,className:`h-10 w-full min-w-0 rounded-md border border-input bg-background px-3 text-sm`,placeholder:e.hasPassword?T(`sharePasswordPlaceholderKeep`):T(`sharePasswordPlaceholderNone`),type:`text`,autoComplete:`new-password`}),(0,D.jsxs)(y,{variant:`outline`,className:`h-10 sm:shrink-0`,onClick:()=>{u(!1),s(_())},children:[(0,D.jsx)(n,{className:`mr-2 size-4`}),T(`generatePassword`)]})]}),l?(0,D.jsx)(`span`,{className:`block text-xs text-destructive`,children:T(`sharePasswordRemovalSelected`)}):(0,D.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:e.hasPassword?T(`sharePasswordEditHint`):T(`sharePasswordSetHint`)}),e.hasPassword&&!l?(0,D.jsxs)(y,{variant:`ghost`,size:`sm`,className:`h-8 text-destructive`,onClick:()=>{s(``),u(!0)},children:[(0,D.jsx)(c,{className:`mr-2 size-3.5`}),T(`removePassword`)]}):null]}),(0,D.jsxs)(`label`,{className:`block text-sm font-medium`,children:[T(`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:T(`keepCurrentExpiration`)}),(0,D.jsx)(`option`,{value:`1h`,children:T(`oneHour`)}),(0,D.jsx)(`option`,{value:`24h`,children:T(`twentyFourHours`)}),(0,D.jsx)(`option`,{value:`7d`,children:T(`sevenDays`)}),(0,D.jsx)(`option`,{value:`never`,children:T(`shareNeverExpires`)})]})]}),b?(0,D.jsx)(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive`,children:b}):null]}),(0,D.jsx)(`div`,{className:`shrink-0 border-t border-border px-5 py-4`,children:(0,D.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,D.jsx)(y,{variant:`outline`,onClick:t,disabled:g,children:T(`cancel`)}),(0,D.jsx)(y,{variant:i===`operate`?`destructive`:`default`,onClick:()=>void w(),disabled:g,children:T(`saveChanges`)})]})})]})})}function F({share:e,status:i,onClose:a,onAction:s}){let l=i===`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&&a()},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":T(`manageShare`),children:[(0,D.jsx)(`div`,{className:`truncate px-1 text-sm font-medium text-foreground`,children:e.titleSnapshot||T(`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)(y,{variant:`ghost`,className:`w-full justify-start`,onClick:()=>s(`copy`),children:[(0,D.jsx)(u,{className:`mr-2 size-4`}),T(`copyShareLink`)]}),(0,D.jsxs)(y,{variant:`ghost`,className:`w-full justify-start`,disabled:!l,onClick:()=>s(`open`),children:[(0,D.jsx)(o,{className:`mr-2 size-4`}),T(`openShareLink`)]}),i===`active`?(0,D.jsxs)(y,{variant:`ghost`,className:`w-full justify-start`,onClick:()=>s(`edit`),children:[(0,D.jsx)(t,{className:`mr-2 size-4`}),T(`editShare`)]}):null,i===`active`?(0,D.jsxs)(y,{variant:`ghost`,className:`w-full justify-start`,onClick:()=>s(`disable`),children:[(0,D.jsx)(r,{className:`mr-2 size-4`}),T(`disableShare`)]}):(0,D.jsxs)(y,{variant:`ghost`,className:`w-full justify-start`,onClick:()=>s(`restore`),children:[(0,D.jsx)(n,{className:`mr-2 size-4`}),T(`restoreShare`)]}),(0,D.jsxs)(y,{variant:`ghost`,className:`w-full justify-start hover:text-destructive`,onClick:()=>s(`delete`),children:[(0,D.jsx)(c,{className:`mr-2 size-4`}),T(`deleteShare`)]})]}),(0,D.jsx)(y,{variant:`outline`,className:`mt-3 w-full`,onClick:a,children:T(`cancel`)})]})})}function I(){let[e,s]=(0,E.useState)([]),[d,m]=(0,E.useState)(!0),[g,_]=(0,E.useState)(``),[x,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{s((await C()).shares)}catch(e){G(e instanceof Error?e.message:T(`shareLinksLoadFailed`))}finally{e&&m(!1)}};(0,E.useEffect)(()=>{let e=!1;return C().then(t=>{e||s(t.shares)}).catch(t=>{e||G(t instanceof Error?t.message:T(`shareLinksLoadFailed`))}).finally(()=>{e||m(!1)}),()=>{e=!0}},[]);let K=(0,E.useMemo)(()=>{let t=x.trim().toLowerCase();return t?e.filter(e=>`${e.titleSnapshot||``} ${e.id} ${e.projectId||``}`.toLowerCase().includes(t)):e},[x,e]),q=e=>{s(t=>t.map(t=>t.id===e.id?{...t,...e}:t))},J=async(e,t,n)=>{if(!g){_(e),U(``),G(``);try{q((await t()).share),U(n)}catch(e){G(e instanceof Error?e.message:T(`requestFailed`))}finally{_(``)}}},Y=async e=>{try{await p(k(e)),U(T(`shareLinkCopied`)),G(``)}catch{G(T(`copyFailed`))}},X=async e=>{await h({description:T(`disableShareConfirm`,{title:e.titleSnapshot||e.id}),confirmLabel:T(`disableShare`),cancelLabel:T(`cancel`),variant:`destructive`})&&await J(e.id,()=>w(e.id),T(`shareDisabled`))},Z=async e=>{let t=I[e.id]||`24h`;await J(e.id,()=>S(e.id,N(t)),T(`shareRestored`))},te=async e=>{let t=I[e.id]||`24h`;await J(e.id,()=>f(e.id,N(t)),T(`shareExpirationUpdated`))},Q=async e=>{if(!(!await h({description:T(`deleteShareConfirm`,{title:e.titleSnapshot||e.id}),confirmLabel:T(`confirmDelete`),cancelLabel:T(`cancel`),variant:`destructive`})||g)){_(e.id),U(``),G(``);try{await b(e.id),s(t=>t.filter(t=>t.id!==e.id)),U(T(`shareDeleted`))}catch(e){G(e instanceof Error?e.message:T(`requestFailed`))}finally{_(``)}}},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?v(R):null,$=B?v(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)(i,{className:`size-5`}),T(`shareLinks`)]}),(0,D.jsx)(`p`,{className:`quickforge-settings-row-description`,children:T(`shareLinksDescription`)})]}),(0,D.jsxs)(y,{variant:`outline`,size:`sm`,onClick:()=>void ee(),disabled:d||!!g,children:[(0,D.jsx)(n,{className:`mr-2 size-4 ${d?`animate-spin`:``}`}),T(`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)(l,{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:x,onChange:e=>O(e.target.value),className:`quickforge-settings-input`,placeholder:T(`searchShareLinks`),"aria-label":T(`searchShareLinks`)})]}),(0,D.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:T(`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:T(`loading`)}):K.length===0?(0,D.jsx)(`div`,{className:`p-8 text-center text-sm text-muted-foreground`,children:T(x?`noMatchingShareLinks`:`noShareLinks`)}):K.map(e=>{let i=v(e),s=g===e.id,l=i===`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||T(`untitledConversation`)}),(0,D.jsx)(`span`,{className:`quickforge-settings-badge ${M(i)}`,children:j(i)}),(0,D.jsx)(`span`,{className:`quickforge-settings-badge quickforge-settings-badge-info`,children:e.permission===`operate`?T(`sharePermissionOperate`):T(`sharePermissionRead`)}),e.hasPassword?(0,D.jsx)(`span`,{className:`quickforge-settings-badge quickforge-settings-badge-muted`,children:T(`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:[T(`shareCreatedAt`),`: `,A(e.createdAt)]}),(0,D.jsx)(`span`,{children:`·`}),(0,D.jsxs)(`span`,{children:[T(`shareExpiresAt`),`: `,e.expiresAt?A(e.expiresAt):T(`shareNeverExpires`)]}),(0,D.jsx)(`span`,{children:`·`}),(0,D.jsx)(`span`,{children:T(`shareAccessCount`,{count:e.accessCount||0})}),e.lastAccessedAt?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`span`,{children:`·`}),(0,D.jsxs)(`span`,{children:[T(`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:[i===`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":T(`shareUpdateExpiration`),disabled:s,children:[(0,D.jsx)(`option`,{value:`1h`,children:T(`oneHour`)}),(0,D.jsx)(`option`,{value:`24h`,children:T(`twentyFourHours`)}),(0,D.jsx)(`option`,{value:`7d`,children:T(`sevenDays`)}),(0,D.jsx)(`option`,{value:`never`,children:T(`shareNeverExpires`)})]}),(0,D.jsx)(y,{variant:`outline`,size:`sm`,onClick:()=>void te(e),disabled:s,children:T(`updateShareExpiration`)})]}):null,(0,D.jsx)(y,{variant:`ghost`,size:`icon`,onClick:()=>void Y(e),"aria-label":T(`copyShareLink`),title:T(`copyShareLink`),children:(0,D.jsx)(u,{className:`size-4`})}),(0,D.jsx)(y,{variant:`ghost`,size:`icon`,onClick:()=>window.open(k(e),`_blank`,`noopener,noreferrer`),disabled:!l,"aria-label":T(`openShareLink`),title:T(`openShareLink`),children:(0,D.jsx)(o,{className:`size-4`})}),i===`active`?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(y,{variant:`outline`,size:`sm`,onClick:()=>z(e),disabled:s,children:[(0,D.jsx)(t,{className:`mr-2 size-4`}),T(`editShare`)]}),(0,D.jsxs)(y,{variant:`outline`,size:`sm`,onClick:()=>void X(e),disabled:s,children:[(0,D.jsx)(r,{className:`mr-2 size-4`}),T(`disableShare`)]})]}):(0,D.jsxs)(y,{variant:`outline`,size:`sm`,onClick:()=>void Z(e),disabled:s,children:[(0,D.jsx)(n,{className:`mr-2 size-4`}),T(`restoreShare`)]}),(0,D.jsx)(y,{variant:`ghost`,size:`icon`,className:`hover:text-destructive`,onClick:()=>void Q(e),disabled:s,"aria-label":T(`deleteShare`),title:T(`deleteShare`),children:(0,D.jsx)(c,{className:`size-4`})})]}),(0,D.jsxs)(y,{variant:`outline`,size:`sm`,className:`md:hidden`,onClick:()=>V(e),disabled:s,children:[(0,D.jsx)(a,{className:`mr-2 size-4`}),T(`manageShare`)]})]})]},e.id)})]}),R&&re===`active`?(0,D.jsx)(P,{share:R,onClose:()=>z(null),onSaved:e=>{q(e),U(T(`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{o as t,qt as n,yt as r}from"./icons-2D18YbSI.js";import{n as i}from"./react-vendor-3UaA-C9W.js";import{S as a,b as o,d as s,f as c,p as l,u}from"./pi-web-ui-DV5jKjSg.js";import{U as d}from"./pi-ai-Cr2ee4a0.js";import{n as f}from"./model-display-label-C6-0eDxF.js";import{n as p}from"./model-reference-o41fJ6jQ.js";import{C as m,Dt as h,Mt as g,Nt as _,Ot as v,Qt as y,S as b,T as x,cn as S,dn as C,hn as w,it as T,jt as E,kt as D,mn as O,wt as k,yn as A}from"./index-BTPzyq7d.js";import{t as j}from"./model-identity-CgA6_Pbm.js";import{ChatPanelHost as M}from"./ChatPanelHost-Dul1ahKj.js";var N=e(n(),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`?A(`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=g(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=_(this.state.messages,E(t),!0),this.state.pendingToolCalls=new Set([...this.state.pendingToolCalls,t.toolCallId]));break}case`tool_execution_update`:{let t=e;this.state.messages=_(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=_(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??y(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[n,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,g]=(0,N.useState)(!1),[_,y]=(0,N.useState)(),C=(0,N.useRef)(!1),E=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(t=n.trim())=>{p(void 0),g(!0);try{let n=await x(e,t);c(n.permission),u(n.title||n.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{g(!1)}},[n,e]);(0,N.useEffect)(()=>{if(P||m||C.current)return;C.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(S((await G(e,a.state.model)).flatMap(e=>e.models??[])),a.state.model);if(!t.length)return;T(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=>{y(t=>t?.id===e?void 0:t)},[]),B=(0,N.useCallback)(async e=>{if(!a||a.permission!==`operate`)return;if(p(void 0),a.state.isStreaming){k(A(`generationStillRunning`));return}let t=D(a.state.messages,e),n=t>=0?a.state.messages[t]:void 0;if(!n){k(A(`noConversationTurnToRollback`));return}try{await a.rollback(e),y({id:Date.now(),sessionId:a.sessionId,text:v(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:w(`shrink-0 border-b px-4 py-3`,E?`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:w(`inline-flex items-center gap-1 rounded-full px-2 py-0.5 font-medium`,E?`bg-red-100 text-red-700`:`bg-muted text-muted-foreground`),children:[E?(0,U.jsx)(t,{className:`size-3.5`}):null,E?`高危可操作`:`只读分享`]}),(0,U.jsx)(`span`,{className:w(E?`text-red-800`:`text-muted-foreground`),children:E?`正在操作分享者的原始对话`:`只能查看,不能发送或修改`})]}),E?null:(0,U.jsx)(`div`,{className:`mt-1 text-xs leading-5 text-muted-foreground`,children:`界面与正常对话保持一致`})]}),(0,U.jsxs)(O,{variant:`ghost`,size:`sm`,className:w(`shrink-0`,E?`text-red-700 hover:bg-red-100 hover:text-red-800`:void 0),onClick:()=>void h(window.location.href),"aria-label":E?`复制高危分享链接`:`复制分享链接`,title:E?`复制高危分享链接`:`复制分享链接`,children:[(0,U.jsx)(r,{className:`size-4`}),(0,U.jsx)(`span`,{className:`hidden sm:inline`,children:E?`复制高危链接`:`复制链接`})]})]})}),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:A(`sharedRollbackConfirmTitle`),rollbackConfirmDescription:A(`sharedRollbackConfirm`),readOnly:!E,approvalReadOnly:!0,approvalReadOnlyMessage:A(`sharedApprovalReadOnly`),restoredDraft:_,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)(t,{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:n,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)(O,{className:`mt-5 w-full`,onClick:()=>void I(),disabled:m||!n.trim(),children:m?A(`loading`):`用密码打开分享对话`})]})})}export{J as SharedConversationPage};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{E as t,Nt as n,R as r,U as i,n as a,q as o,qt as s,u as c}from"./icons-2D18YbSI.js";import{n as l}from"./react-vendor-3UaA-C9W.js";import{_t as u,hn as d,lt as f,mn as p,mt as m,yn as h}from"./index-BTPzyq7d.js";import{n as g,t as _}from"./xterm-Bm_IbozX.js";var v=e(s(),1);async function y(e,t){let n=await fetch(e,{cache:`no-store`,...t}),r=await n.json().catch(()=>null);if(!n.ok)throw Error(r?.error||`Request failed: ${n.status}`);return r}function b(){return y(`/api/terminal/capabilities`,{cache:`default`})}function x(e){return y(`/api/terminal/sessions${e?`?projectId=${encodeURIComponent(e)}`:``}`)}function S(e){return y(`/api/terminal/sessions`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(e)})}function C(e){return y(`/api/terminal/sessions/${encodeURIComponent(e)}`,{method:`DELETE`})}function ee(e,t){return y(`/api/terminal/sessions/${encodeURIComponent(e)}/input`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({data:t})})}function w(){return``}function te(){let e=w();if(e){let t=new URL(e);return t.protocol=t.protocol===`https:`?`wss:`:`ws:`,t.toString().replace(/\/$/,``)}return`${location.protocol===`https:`?`wss:`:`ws:`}//${location.host}`}function T(){let[e,t]=(0,v.useState)(()=>f());return(0,v.useEffect)(()=>{if(typeof document>`u`)return;let e=document.documentElement,n=()=>t(f());n();let r=new MutationObserver(n);return r.observe(e,{attributes:!0,attributeFilter:[`class`]}),()=>r.disconnect()},[]),e}var E=1e4,D=[1e3,2e3,4e3],O=D.length;function k(e){return D[e]}function ne(e){return e.code===`SESSION_NOT_FOUND`||e.retryable===!1||e.message===`Terminal session not found`}var A=l(),j={light:{background:`#ffffff`,foreground:`#1f2937`,cursor:`#1f2937`,selectionBackground:`#dbeafe`},dark:{background:`#171717`,foreground:`#e5e7eb`,cursor:`#e5e7eb`,selectionBackground:`#3f3f46`}};function re({session:e,active:t,height:n,retryKey:r,onReady:i,onExited:a,onConnectionError:o,onConnectionState:s}){let c=j[T()],l=(0,v.useRef)(null),d=(0,v.useRef)(null),f=(0,v.useRef)(null),p=(0,v.useRef)(null),y=(0,v.useRef)(null),b=(0,v.useRef)(()=>{}),x=(0,v.useRef)(!1);return(0,v.useEffect)(()=>{let e=l.current;if(!e)return;let t=u(),n=new g({cursorBlink:!0,convertEol:!1,fontFamily:getComputedStyle(document.documentElement).getPropertyValue(`--font-mono`).trim()||`ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace`,fontSize:t.fontSize,lineHeight:t.lineHeight,scrollback:5e3}),r=new _;n.loadAddon(r),n.open(e),d.current=n,f.current=r;let i=()=>{if(e.isConnected)try{r.fit();let e=p.current;e?.readyState===WebSocket.OPEN&&e.send(JSON.stringify({type:`resize`,cols:n.cols,rows:n.rows}))}catch{}};b.current=i;let a=new ResizeObserver(()=>i());a.observe(e);let o=()=>{let e=u();n.options.fontSize=e.fontSize,n.options.lineHeight=e.lineHeight,window.setTimeout(i,0)};return window.addEventListener(m,o),window.setTimeout(i,50),()=>{window.removeEventListener(m,o),a.disconnect(),b.current=()=>{},n.dispose(),d.current=null,f.current=null}},[e.id]),(0,v.useEffect)(()=>{let e=d.current;e&&(e.options.theme=c)},[c]),(0,v.useEffect)(()=>{let t=!1,n=!1,r=!1,c=0,l,u=0,f=n=>{t||s(e.id,n)},m=()=>{if(t||n||r)return;let s=++u,g=!1,_=!1,v=new WebSocket(`${te()}/api/terminal/sessions/${encodeURIComponent(e.id)}/ws`);p.current=v,f(c===0?{status:`connecting`}:{status:`reconnecting`,reconnectAttempt:c});let S=window.setTimeout(()=>{if(!(t||n||r||_||s!==u)){C(h(`terminalConnectionTimedOut`));try{v.close()}catch{}}},E),C=i=>{if(t||n||r||g||s!==u)return;g=!0,window.clearTimeout(S),y.current?.dispose(),y.current=null;let a=k(c);if(c<O&&a!==void 0){c+=1,f({status:`reconnecting`,reconnectAttempt:c}),l=window.setTimeout(m,a);return}f({status:`disconnected`}),o(e.id,i)};v.addEventListener(`open`,()=>{if(t||n||g||s!==u){try{v.close()}catch{}return}y.current?.dispose(),y.current=d.current?.onData(e=>{v.readyState===WebSocket.OPEN&&v.send(JSON.stringify({type:`input`,data:e}))})??null,window.setTimeout(b.current,0)}),v.addEventListener(`message`,t=>{try{let s=JSON.parse(String(t.data));if(s.type===`ready`)_=!0,c=0,window.clearTimeout(S),o(e.id,void 0),f({status:`connected`}),x.current||(x.current=!0,d.current?.writeln(`\x1b[2mConnected to ${e.cwd}\x1b[0m`)),i(e.id);else if(s.type===`output`)d.current?.write(s.data);else if(s.type===`exit`)n=!0,window.clearTimeout(S),l!==void 0&&window.clearTimeout(l),d.current?.writeln(``),d.current?.writeln(`\x1b[33m[process exited with code ${s.exitCode??`unknown`}]\x1b[0m`),f({status:`exited`}),a(e.id);else if(s.type===`error`)if(ne(s)){r=!0,g=!0,window.clearTimeout(S),l!==void 0&&window.clearTimeout(l),y.current?.dispose(),y.current=null,f({status:`unavailable`}),o(e.id,h(`terminalSessionUnavailable`));try{v.close()}catch{}}else C(s.message||h(`terminalConnectionFailed`))}catch{}}),v.addEventListener(`error`,()=>{C(h(_?`terminalConnectionClosedUnexpectedly`:`terminalConnectionFailed`))}),v.addEventListener(`close`,()=>{window.clearTimeout(S),y.current?.dispose(),y.current=null,!(t||n||r||g||s!==u)&&C(h(_?`terminalConnectionClosedUnexpectedly`:`terminalConnectionFailed`))})};return o(e.id,void 0),m(),()=>{t=!0,u+=1,l!==void 0&&window.clearTimeout(l),y.current?.dispose(),y.current=null;let e=p.current;p.current=null;try{e?.close()}catch{}}},[o,s,a,i,r,e.cwd,e.id]),(0,v.useEffect)(()=>{t&&window.setTimeout(()=>{try{f.current?.fit(),d.current?.focus()}catch{}},0)},[t,n]),(0,A.jsx)(`div`,{className:t?`h-full min-h-0 w-full pl-2 md:pl-3`:`hidden`,"aria-hidden":!t,children:(0,A.jsx)(`div`,{ref:l,className:`h-full min-h-0 w-full`})})}var ie=180,ae=.7,oe=320;function M(e,t){let n=t?t.name:`Terminal`,r=new Set(e.map(e=>e.name));if(n!==`Terminal`&&!r.has(n))return n;let i=1;for(;r.has(`${n} ${i}`);)i+=1;return`${n} ${i}`}function N(e,t){let n=e?.terminalShellProfiles||[],r=t||e?.defaultTerminalShellProfileId||``;return n.find(e=>e.id===r)||n[0]}function se({project:e,onCollapse:s,pendingCommand:l,onPendingCommandHandled:u,variant:f=`dock`,singleSession:m=!1,panelInstanceId:g,panelSessionId:_,onPanelSessionReady:y}){let[w,te]=(0,v.useState)(null),[T,E]=(0,v.useState)([]),[D,O]=(0,v.useState)(),[k,ne]=(0,v.useState)(oe),[j,se]=(0,v.useState)(!0),[P,ce]=(0,v.useState)(!1),[le,F]=(0,v.useState)(),[ue,de]=(0,v.useState)({}),[I,fe]=(0,v.useState)({}),[pe,me]=(0,v.useState)({}),[L,R]=(0,v.useState)(!1),[z,he]=(0,v.useState)(!1),B=(0,v.useRef)(!1),V=(0,v.useRef)(!1),H=(0,v.useRef)(new Set),ge=(0,v.useRef)(l),U=(0,v.useRef)(new Set),_e=(0,v.useRef)(new Set),W=(0,v.useRef)(new Map),G=(0,v.useRef)(!0),ve=(0,v.useRef)(y),[ye,be]=(0,v.useState)(()=>new Set),xe=(0,v.useRef)(null),Se=(0,v.useRef)(null),K=e?.id,q=f===`panel`&&!!g,J=(0,v.useMemo)(()=>T.find(e=>e.id===D)??T[0],[D,T]);(0,v.useEffect)(()=>{ge.current=l},[l]),(0,v.useEffect)(()=>{ve.current=y},[y]),(0,v.useEffect)(()=>()=>{G.current=!1},[]);let Ce=(0,v.useCallback)(async()=>{let e=await x(K);return E(e.sessions),O(t=>t&&e.sessions.some(e=>e.id===t)?t:e.sessions[0]?.id),e.sessions},[K]),we=(0,v.useCallback)(async(e,t)=>{if(B.current)return;let n=N(w,t);B.current=!0,ce(!0),F(void 0);try{let t=await S({projectId:K,name:M(e,n),cols:120,rows:30,shellProfileId:n?.id,shellProfileName:n?.name});E(e=>[...e,t]),O(t.id),q&&ve.current?.(t.id)}catch(e){F(e instanceof Error?e.message:h(`terminalCreateFailed`))}finally{B.current=!1,ce(!1)}},[w,q,K]);(0,v.useEffect)(()=>{let e=!1;return(async()=>{se(!0),F(void 0);try{let[t,n]=await Promise.all([b(),x(K)]);if(e)return;if(te(t),t.enabled&&q&&_&&n.sessions.some(e=>e.id===_)){V.current=!0,E(n.sessions),O(_);return}if(t.enabled&&q&&!V.current){V.current=!0;let r=N(t);try{let t=await S({projectId:K,name:M(n.sessions,r),cols:120,rows:30,shellProfileId:r?.id,shellProfileName:r?.name});if(e){C(t.id).catch(()=>{});return}E([...n.sessions,t]),O(t.id),ve.current?.(t.id);return}catch(t){e||F(t instanceof Error?t.message:h(`terminalCreateFailed`))}}if(E(n.sessions),O(n.sessions[0]?.id),t.enabled&&n.sessions.length===0&&!ge.current){let n=N(t);S({projectId:K,name:M([],n),cols:120,rows:30,shellProfileId:n?.id,shellProfileName:n?.name}).then(t=>{if(e){C(t.id).catch(()=>{});return}E([t]),O(t.id)}).catch(t=>{e||F(t instanceof Error?t.message:h(`terminalCreateFailed`))})}}catch(t){e||F(t instanceof Error?t.message:h(`terminalUnavailable`))}finally{e||se(!1)}})(),()=>{e=!0}},[q,_,K]),(0,v.useEffect)(()=>{if(!L)return;let e=e=>{Se.current?.contains(e.target)||R(!1)},t=e=>{e.key===`Escape`&&R(!1)};return document.addEventListener(`pointerdown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`pointerdown`,e),document.removeEventListener(`keydown`,t)}},[L]),(0,v.useEffect)(()=>{if(!z)return;let e=e=>{e.key===`Escape`&&he(!1)};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[z]),(0,v.useEffect)(()=>{if(!l||H.current.has(l.id)||W.current.has(l.id)||U.current.has(l.id)||j||P||!w)return;if(!w.enabled){H.current.add(l.id),window.setTimeout(()=>{F(w.reason||h(`terminalUnavailable`)),u?.(l.id)},0);return}let e=J&&!J.exited?J:T.find(e=>!e.exited);if(e){W.current.set(l.id,e.id),window.setTimeout(()=>{G.current&&O(e.id)},0);return}U.current.add(l.id),window.setTimeout(()=>{G.current&&F(void 0)},0);let t=N(w);S({projectId:K,name:M(T,t),cols:120,rows:30,shellProfileId:t?.id,shellProfileName:t?.name}).then(e=>{if(!G.current){C(e.id).catch(()=>{});return}W.current.set(l.id,e.id),E(t=>t.some(t=>t.id===e.id)?t:[...t,e]),O(e.id)}).catch(e=>{G.current&&(F(e instanceof Error?e.message:h(`terminalCommandExecuteFailed`)),H.current.add(l.id),u?.(l.id))}).finally(()=>{U.current.delete(l.id)})},[J,w,P,j,u,l,K,T]),(0,v.useEffect)(()=>{if(!l||H.current.has(l.id)||_e.current.has(l.id))return;let e=W.current.get(l.id),t=e?T.find(t=>t.id===e):J&&!J.exited?J:T.find(e=>!e.exited);!t||t.exited||!ye.has(t.id)||(_e.current.add(l.id),window.setTimeout(()=>{G.current&&(O(t.id),F(void 0))},0),(async()=>{try{if(l.execute){let e=l.command.split(`
|
|
2
|
-
`),n=e.flatMap((t,n)=>n<e.length-1?[t,`\r`]:[t]);n.push(`\r`),await ee(t.id,n.join(``))}else await ee(t.id,l.command)}catch(e){G.current&&F(e instanceof Error?e.message:h(`terminalCommandExecuteFailed`))}finally{H.current.add(l.id),_e.current.delete(l.id),W.current.delete(l.id),G.current&&u?.(l.id)}})())},[J,u,l,ye,T]);let Y=async e=>{F(void 0),de(t=>{if(!t[e])return t;let n={...t};return delete n[e],n}),fe(t=>{if(!t[e])return t;let n={...t};return delete n[e],n}),me(t=>{if(t[e]===void 0)return t;let n={...t};return delete n[e],n});let t=T.filter(t=>t.id!==e);E(t),D===e&&O(t[0]?.id);try{await C(e)}catch(e){F(e instanceof Error?e.message:h(`terminalCloseFailed`)),Ce().catch(()=>{})}},Te=(0,v.useCallback)(e=>{E(t=>t.map(t=>t.id===e?{...t,exited:!0}:t)),be(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),n})},[]),Ee=(0,v.useCallback)(e=>{be(t=>{if(t.has(e))return t;let n=new Set(t);return n.add(e),n})},[]),De=(0,v.useCallback)((e,t)=>{de(n=>{if(!t){if(!n[e])return n;let t={...n};return delete t[e],t}return n[e]===t?n:{...n,[e]:t}})},[]),Oe=(0,v.useCallback)((e,t)=>{fe(n=>{let r=n[e];return r?.status===t.status&&r.reconnectAttempt===t.reconnectAttempt?n:{...n,[e]:t}})},[]),ke=(0,v.useCallback)(e=>{de(t=>{if(!t[e])return t;let n={...t};return delete n[e],n}),me(t=>({...t,[e]:(t[e]||0)+1}))},[]),Ae=async e=>{let t=T.filter(t=>t.id!==e);await Y(e),await we(t)},je=(e,t)=>e.exited||t===`exited`||t===`unavailable`?`bg-muted-foreground/40`:t===`connected`?`bg-emerald-500/80`:t===`connecting`||t===`reconnecting`?`bg-amber-500/80`:`bg-destructive/70`,Me=e=>{xe.current={startY:e.clientY,startHeight:k},e.currentTarget.setPointerCapture(e.pointerId)},Ne=e=>{let t=xe.current;if(!t)return;let n=Math.max(ie,Math.floor(window.innerHeight*ae));ne(Math.min(n,Math.max(ie,t.startHeight+t.startY-e.clientY)))},Pe=e=>{xe.current=null;try{e.currentTarget.releasePointerCapture(e.pointerId)}catch{}},X=w?.terminalShellProfiles||[],Fe=w?.defaultTerminalShellProfileId||``,Ie=X.find(e=>e.id===Fe)||X[0],Le=!!(w&&T.length>=w.maxSessions),Re=P||Le,ze=J?ue[J.id]:void 0,Z=J?I[J.id]:void 0,Be=Z?.status===`unavailable`,Ve=Z?.status===`connecting`?h(`terminalConnecting`):Z?.status===`reconnecting`?h(`terminalReconnecting`,{attempt:Z.reconnectAttempt||1,max:3}):void 0,He=q&&J?[J]:T,Q=le??ze,Ue=Q?void 0:Ve,We=!!(Q||Ue),$=f===`panel`,Ge=$&&m,Ke=$?void 0:z?We?`calc(100% - 4.25rem)`:`calc(100% - 2.25rem)`:We?k-72:k-45;return(0,A.jsxs)(`div`,{className:d($?`flex min-h-0 flex-1 flex-col bg-background`:`shrink-0 border-t border-border bg-background`,z&&`quickforge-terminal-fullscreen z-40 flex flex-col border-t-0`),style:z||$?void 0:{height:k},children:[!z&&!$?(0,A.jsx)(`div`,{className:`h-1 cursor-row-resize bg-transparent hover:bg-border`,onPointerDown:Me,onPointerMove:Ne,onPointerUp:Pe,onPointerCancel:Pe}):null,(0,A.jsxs)(`div`,{className:`flex h-9 items-center gap-1 border-b border-border px-2`,children:[(0,A.jsx)(c,{className:`size-4 shrink-0 text-muted-foreground/60`}),(0,A.jsx)(`div`,{className:`flex min-w-0 flex-1 items-center gap-1 overflow-x-auto`,children:He.map(e=>{let t=d(`flex max-w-44 shrink-0 items-center gap-1 rounded-md px-2 py-1 text-xs text-muted-foreground/72`,J?.id===e.id&&`bg-muted/28 text-foreground/90`);return Ge?(0,A.jsxs)(`div`,{className:t,title:`${e.name} — ${e.cwd}`,children:[(0,A.jsx)(`span`,{className:d(`size-1.5 rounded-full`,je(e,I[e.id]?.status))}),(0,A.jsx)(`span`,{className:`truncate`,children:e.name})]},e.id):(0,A.jsxs)(`button`,{type:`button`,className:d(t,`hover:bg-muted/20 hover:text-foreground/85`),onClick:()=>O(e.id),title:`${e.name} — ${e.cwd}`,children:[(0,A.jsx)(`span`,{className:d(`size-1.5 rounded-full`,je(e,I[e.id]?.status))}),(0,A.jsx)(`span`,{className:`truncate`,children:e.name}),(0,A.jsx)(`span`,{role:`button`,tabIndex:0,className:`ml-1 rounded-sm p-0.5 opacity-60 hover:bg-background hover:opacity-100`,onClick:t=>{t.stopPropagation(),Y(e.id)},onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),t.stopPropagation(),Y(e.id))},"aria-label":h(`terminalCloseSession`,{name:e.name}),children:(0,A.jsx)(a,{className:`size-3`})})]},e.id)})}),Ge?null:(0,A.jsxs)(`div`,{className:`relative shrink-0`,ref:Se,children:[(0,A.jsxs)(`div`,{className:`flex items-center overflow-hidden rounded-md border border-border bg-background`,children:[(0,A.jsx)(`button`,{type:`button`,className:`inline-flex h-7 w-7 items-center justify-center text-foreground/85 transition-colors hover:bg-muted/20 disabled:pointer-events-none disabled:opacity-50`,onClick:()=>void we(T),disabled:Re,title:Ie?h(`terminalNewWithProfile`,{name:Ie.name}):h(`terminalNew`),"aria-label":h(`terminalNew`),children:P?(0,A.jsx)(o,{className:`size-3.5 animate-spin`}):(0,A.jsx)(t,{className:`size-3.5`})}),X.length>0?(0,A.jsx)(`button`,{type:`button`,className:`inline-flex h-7 w-7 items-center justify-center border-l border-border text-muted-foreground/72 transition-colors hover:bg-muted/20 hover:text-foreground/85 disabled:pointer-events-none disabled:opacity-50`,onClick:()=>R(e=>!e),disabled:Re,title:h(`terminalSelectShell`),"aria-label":h(`terminalSelectShell`),"aria-expanded":L,children:(0,A.jsx)(n,{className:`size-3.5`})}):null]}),L?(0,A.jsxs)(`div`,{className:d(`absolute right-0 z-30 w-64 overflow-hidden rounded-lg border border-border bg-background p-1.5 shadow-[0_16px_38px_-22px_rgb(15_23_42_/_0.65)]`,$?`top-9`:`bottom-9`),children:[(0,A.jsx)(`div`,{className:`px-2 pb-1.5 pt-1 text-[11px] font-medium uppercase tracking-wide text-muted-foreground/60`,children:h(`terminalNewWith`)}),X.map(e=>(0,A.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-xs text-muted-foreground/80 hover:bg-muted/20 hover:text-foreground/90`,onClick:()=>{R(!1),we(T,e.id)},children:[(0,A.jsx)(`span`,{className:`inline-flex size-5 shrink-0 items-center justify-center rounded bg-muted/20 text-[10px] text-muted-foreground/70`,children:e.name.slice(0,1).toUpperCase()}),(0,A.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,A.jsx)(`span`,{className:`block truncate font-medium`,children:e.name}),(0,A.jsx)(`span`,{className:`block truncate font-mono text-[11px] text-muted-foreground/55`,children:e.command})]})]},e.id))]}):null]}),Ge?null:(0,A.jsx)(p,{variant:`ghost`,size:`icon`,className:`size-7`,onClick:()=>he(e=>!e),title:h(z?`terminalExitFullscreen`:`terminalFullscreen`),"aria-label":h(z?`terminalExitFullscreen`:`terminalFullscreen`),children:z?(0,A.jsx)(r,{className:`size-3.5`}):(0,A.jsx)(i,{className:`size-3.5`})}),(0,A.jsx)(p,{variant:`ghost`,size:`icon`,className:d(`size-7`,$&&`hidden`),onClick:s,title:h(`terminalCollapse`),"aria-label":h(`terminalCollapse`),children:(0,A.jsx)(n,{className:`size-3.5`})})]}),Q?(0,A.jsxs)(`div`,{className:`flex items-center justify-between gap-3 border-b border-border px-3 py-1.5 text-xs text-destructive`,children:[(0,A.jsx)(`span`,{children:Q}),Be&&J?(0,A.jsxs)(`span`,{className:`flex shrink-0 items-center gap-1`,children:[(0,A.jsx)(`button`,{type:`button`,className:`rounded px-1.5 py-0.5 font-medium text-foreground/80 hover:bg-muted/40`,onClick:()=>void Ae(J.id),disabled:P,children:h(`terminalStartNew`)}),(0,A.jsx)(`button`,{type:`button`,className:`rounded px-1.5 py-0.5 font-medium text-muted-foreground hover:bg-muted/40`,onClick:()=>void Y(J.id),children:h(`close`)})]}):ze&&J&&!J.exited?(0,A.jsx)(`button`,{type:`button`,className:`shrink-0 rounded px-1.5 py-0.5 font-medium text-destructive hover:bg-destructive/10`,onClick:()=>ke(J.id),children:h(`retry`)}):null]}):Ue?(0,A.jsx)(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-muted-foreground/70`,children:Ue}):null,(0,A.jsx)(`div`,{className:d(`min-h-0 bg-background`,$&&`flex-1`),style:Ke===void 0?void 0:{height:Ke},children:j?(0,A.jsxs)(`div`,{className:`flex h-full items-center justify-center gap-2 text-xs text-muted-foreground/60`,children:[(0,A.jsx)(o,{className:`size-4 animate-spin`}),` `,h(`terminalStarting`)]}):w&&!w.enabled?(0,A.jsx)(`div`,{className:`flex h-full items-center justify-center px-4 text-center text-xs text-muted-foreground/60`,children:w.reason||h(`terminalUnavailable`)}):T.length===0?(0,A.jsx)(`div`,{className:`flex h-full items-center justify-center text-xs text-muted-foreground/60`,children:h(`terminalNoSessions`)}):T.map(e=>(0,A.jsx)(re,{session:e,active:e.id===J?.id,height:z?window.innerHeight-36:$?0:k,retryKey:pe[e.id]||0,onReady:Ee,onExited:Te,onConnectionError:De,onConnectionState:Oe},e.id))})]})}export{se as TerminalDock,T as t};
|