@shawnstack/quickforge 1.7.0 → 1.7.1
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/dist/assets/AgentProfilesPage-__uY0AvK.js +1 -0
- package/dist/assets/{ChatPanelHost-vi1tDqlJ.js → ChatPanelHost-DIs_vWFX.js} +1 -1
- package/dist/assets/{PluginsPage-B8bHMwfv.js → PluginsPage-CKyWhlCo.js} +1 -1
- package/dist/assets/ScheduledTasksPage-KtJoeJYt.js +2 -0
- package/dist/assets/{SettingsWorkspacePage-BOP9CtoI.js → SettingsWorkspacePage-DwqEnUmX.js} +4 -4
- package/dist/assets/{SharedConversationPage-9A4L9UcQ.js → SharedConversationPage-yujCRsbe.js} +1 -1
- package/dist/assets/TerminalDock-B9xKnimU.js +2 -0
- package/dist/assets/WorkspaceInspector-CE6RD6Ys.js +13 -0
- package/dist/assets/icons-pPRMD2tE.js +1 -0
- package/dist/assets/index-BSXpUDCq.js +63 -0
- package/dist/assets/index-DpO7jEGP.css +3 -0
- package/dist/assets/{mcp-servers-dialog-XE4K8PCO.js → mcp-servers-dialog-CaQTvGiW.js} +2 -2
- package/dist/assets/{monaco-C13M09wD.js → monaco-CPwJMUsl.js} +1 -1
- package/dist/assets/{react-vendor-2RKYr-A4.js → react-vendor-CLbWF1Oy.js} +1 -1
- package/dist/assets/{skills-dialog-MpoxntiV.js → skills-dialog-D18mxNyW.js} +1 -1
- package/dist/index.html +6 -6
- package/package.json +1 -1
- package/server/routes/backup.mjs +79 -72
- package/server/routes/workspace.mjs +84 -32
- package/dist/assets/AgentProfilesPage-DQ8URegq.js +0 -1
- package/dist/assets/ScheduledTasksPage-AaUz5el2.js +0 -2
- package/dist/assets/TerminalDock-DQOXpaDe.js +0 -2
- package/dist/assets/WorkspaceInspector-DaM7TJHb.js +0 -13
- package/dist/assets/icons-ko_i0WpN.js +0 -1
- package/dist/assets/index-B2eauKpo.css +0 -3
- package/dist/assets/index-B8Awq5FV.js +0 -63
|
@@ -662,53 +662,105 @@ async function handleWorkspaceFile(req, res, url) {
|
|
|
662
662
|
})
|
|
663
663
|
}
|
|
664
664
|
|
|
665
|
-
|
|
666
|
-
const
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
665
|
+
function createWorkspacePreviewError(message, statusCode, previewCode) {
|
|
666
|
+
const error = new Error(message)
|
|
667
|
+
error.statusCode = statusCode
|
|
668
|
+
error.previewCode = previewCode
|
|
669
|
+
return error
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
export function workspacePreviewIssueFromError(error, requestedPath = '') {
|
|
673
|
+
let status = error?.statusCode || 500
|
|
674
|
+
let code = error?.previewCode || 'PREVIEW_SERVICE_FAILED'
|
|
675
|
+
|
|
676
|
+
if (error?.code === 'ENOENT' || error?.code === 'ENOTDIR') {
|
|
677
|
+
status = 404
|
|
678
|
+
code = 'PREVIEW_FILE_NOT_FOUND'
|
|
679
|
+
} else if (error?.name === 'URIError') {
|
|
680
|
+
status = 400
|
|
681
|
+
code = 'PREVIEW_INVALID_PATH'
|
|
682
|
+
} else if (error?.code === 'EACCES' || error?.code === 'EPERM') {
|
|
683
|
+
status = 403
|
|
684
|
+
code = 'PREVIEW_PERMISSION_DENIED'
|
|
685
|
+
} else if (status === 403 && !error?.previewCode) {
|
|
686
|
+
code = 'PREVIEW_PERMISSION_DENIED'
|
|
687
|
+
} else if (status === 400 && !error?.previewCode) {
|
|
688
|
+
code = 'PREVIEW_INVALID_PATH'
|
|
673
689
|
}
|
|
674
690
|
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
691
|
+
return {
|
|
692
|
+
status,
|
|
693
|
+
payload: {
|
|
694
|
+
error: error?.message || 'Internal server error',
|
|
695
|
+
code,
|
|
696
|
+
path: requestedPath,
|
|
697
|
+
},
|
|
681
698
|
}
|
|
699
|
+
}
|
|
682
700
|
|
|
683
|
-
|
|
701
|
+
export async function inspectWorkspacePreviewFile(context, relativePath) {
|
|
684
702
|
const file = resolveWorkspacePath(relativePath, context)
|
|
685
703
|
await assertSafeWorkspacePath(file, context)
|
|
686
704
|
const extension = path.extname(file).toLowerCase()
|
|
687
705
|
if (!PREVIEW_ALLOWED_EXTENSIONS.has(extension)) {
|
|
688
|
-
|
|
689
|
-
error.statusCode = 415
|
|
690
|
-
throw error
|
|
706
|
+
throw createWorkspacePreviewError('Unsupported preview file type', 415, 'PREVIEW_UNSUPPORTED_TYPE')
|
|
691
707
|
}
|
|
708
|
+
|
|
692
709
|
const stat = await fs.stat(file)
|
|
693
710
|
if (!stat.isFile()) {
|
|
694
|
-
|
|
695
|
-
error.statusCode = 400
|
|
696
|
-
throw error
|
|
711
|
+
throw createWorkspacePreviewError('Path is not a file', 400, 'PREVIEW_INVALID_PATH')
|
|
697
712
|
}
|
|
698
713
|
if (stat.size > MAX_STATIC_PREVIEW_BYTES) {
|
|
699
|
-
|
|
700
|
-
error.statusCode = 413
|
|
701
|
-
throw error
|
|
714
|
+
throw createWorkspacePreviewError('File is too large to preview', 413, 'PREVIEW_FILE_TOO_LARGE')
|
|
702
715
|
}
|
|
703
716
|
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
717
|
+
return {
|
|
718
|
+
file,
|
|
719
|
+
stat,
|
|
720
|
+
contentType: previewContentType(file),
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
async function handleWorkspacePreview(req, res, url) {
|
|
725
|
+
let relativePath = ''
|
|
726
|
+
try {
|
|
727
|
+
const prefix = '/api/workspace/preview/'
|
|
728
|
+
const tail = url.pathname.startsWith(prefix) ? url.pathname.slice(prefix.length) : ''
|
|
729
|
+
const slashIndex = tail.indexOf('/')
|
|
730
|
+
if (slashIndex <= 0) {
|
|
731
|
+
throw createWorkspacePreviewError('projectId and path are required', 400, 'PREVIEW_INVALID_PATH')
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
const projectId = decodeURIComponent(tail.slice(0, slashIndex))
|
|
735
|
+
relativePath = decodeURIComponent(tail.slice(slashIndex + 1))
|
|
736
|
+
if (!projectId || !relativePath) {
|
|
737
|
+
throw createWorkspacePreviewError('projectId and path are required', 400, 'PREVIEW_INVALID_PATH')
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
const context = await projectContextFromId(projectId)
|
|
741
|
+
const preview = await inspectWorkspacePreviewFile(context, relativePath)
|
|
742
|
+
if (url.searchParams.get('__quickforge_check') === '1') {
|
|
743
|
+
sendJson(res, 200, {
|
|
744
|
+
ok: true,
|
|
745
|
+
path: relativePath,
|
|
746
|
+
size: preview.stat.size,
|
|
747
|
+
contentType: preview.contentType,
|
|
748
|
+
})
|
|
749
|
+
return
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
res.writeHead(200, {
|
|
753
|
+
'content-type': preview.contentType,
|
|
754
|
+
'cache-control': 'no-store',
|
|
755
|
+
'x-content-type-options': 'nosniff',
|
|
756
|
+
})
|
|
757
|
+
const buffer = await fs.readFile(preview.file)
|
|
758
|
+
res.end(buffer)
|
|
759
|
+
} catch (error) {
|
|
760
|
+
const issue = workspacePreviewIssueFromError(error, relativePath)
|
|
761
|
+
if (issue.status >= 500) logger.error('Workspace preview failed', { error: issue.payload.error, path: relativePath })
|
|
762
|
+
sendJson(res, issue.status, issue.payload)
|
|
763
|
+
}
|
|
712
764
|
}
|
|
713
765
|
|
|
714
766
|
async function handleWorkspaceResolvePath(req, res) {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{Ot as t,Q as n,St as r,T as i,Tt as a,a as ee,c as o}from"./icons-ko_i0WpN.js";import{i as s,n as c}from"./react-vendor-2RKYr-A4.js";import{$ as te,Q as l,V as ne,Z as re,et as ie,lt as u,mt as d,st as f,tt as ae}from"./index-B8Awq5FV.js";var p=e(t(),1),oe=s(),m=c(),h=144,g=82,_=4,v=8;function y(e){return JSON.stringify({provider:e.provider,modelId:e.id,api:e.api,baseUrl:e.baseUrl})}function b(e){if(!e)return{mode:`inherit`};try{let t=JSON.parse(e);return{mode:`fixed`,provider:String(t.provider||``),modelId:String(t.modelId||``),api:t.api?String(t.api):void 0,baseUrl:t.baseUrl?String(t.baseUrl):void 0}}catch{return{mode:`inherit`}}}function x(e){return!e||e.mode!==`fixed`?``:JSON.stringify({provider:e.provider,modelId:e.modelId,api:e.api,baseUrl:e.baseUrl})}function se(e){return e.name||`${e.provider}/${e.id}`}function S(){return{name:``,label:``,description:``,systemPrompt:``,allowedTools:[`read_file`,`grep_files`],maxRuntimeMs:`1800000`,maxToolCalls:`300`,enabledAsSubagent:!0,modelMode:`inherit`,fixedModelValue:``,thinkingLevel:`inherit`}}function ce(e){return{name:e.name,label:e.label,description:e.description??``,systemPrompt:e.systemPrompt??``,allowedTools:e.allowedTools??[],maxRuntimeMs:String(e.maxRuntimeMs??18e5),maxToolCalls:String(e.maxToolCalls??300),enabledAsSubagent:e.enabledAsSubagent,modelMode:e.model?.mode===`fixed`?`fixed`:`inherit`,fixedModelValue:x(e.model),thinkingLevel:e.thinkingLevel??`inherit`}}function le(e){return{name:e.name.trim().toLowerCase(),label:e.label.trim(),description:e.description.trim(),systemPrompt:e.systemPrompt.trim(),allowedTools:e.allowedTools,maxRuntimeMs:Number(e.maxRuntimeMs||18e5),maxToolCalls:Number(e.maxToolCalls||300),enabledAsSubagent:e.enabledAsSubagent,model:e.modelMode===`fixed`?b(e.fixedModelValue):{mode:`inherit`},thinkingLevel:e.thinkingLevel}}function C(e){return!!(e.name.trim()&&e.label.trim()&&e.allowedTools.length>0)}async function w(e,t){let n=await fetch(e,{...t,headers:{"content-type":`application/json`,...t?.headers}}),r=await n.json().catch(()=>null);if(!n.ok)throw Error(r?.error||`请求失败`);return r}function T(){let[e,t]=(0,p.useState)([]),[s,c]=(0,p.useState)([]),[x,T]=(0,p.useState)(!1),[E,D]=(0,p.useState)(null),[O,k]=(0,p.useState)(()=>S()),[A,j]=(0,p.useState)(!1),[M,N]=(0,p.useState)(``),[P,F]=(0,p.useState)(!1),[I,ue]=(0,p.useState)(),[L,de]=(0,p.useState)([]),[fe,pe]=(0,p.useState)(`off`),[R,z]=(0,p.useState)(``),[B,V]=(0,p.useState)(null),[H,U]=(0,p.useState)(null);async function W(){let[e,n]=await Promise.all([w(`/api/agent-profiles`),w(`/api/agent-profiles/available-tools`)]);t(e.agents),c(n.tools)}(0,p.useEffect)(()=>{let e=!1;async function n(){try{let[n,r]=await Promise.all([w(`/api/agent-profiles`),w(`/api/agent-profiles/available-tools`)]);if(e)return;t(n.agents),c(r.tools)}catch(t){e||z(t instanceof Error?t.message:d(`requestFailed`))}}return n(),()=>{e=!0}},[]),(0,p.useEffect)(()=>{let e=!1;async function t(){try{let t=await te(),n=await l(t);de(n);let r=await ie(t),i=r.model??await ae(t)??n[0];if(e)return;ue(i),pe(r.thinkingLevel??re(i))}catch{}}return t(),()=>{e=!0}},[]),(0,p.useEffect)(()=>{if(!B)return;let e=()=>{V(null),U(null)},t=t=>{t.key===`Escape`&&e()};return window.addEventListener(`click`,e),window.addEventListener(`blur`,e),window.addEventListener(`resize`,e),window.addEventListener(`scroll`,e,!0),document.addEventListener(`keydown`,t),()=>{window.removeEventListener(`click`,e),window.removeEventListener(`blur`,e),window.removeEventListener(`resize`,e),window.removeEventListener(`scroll`,e,!0),document.removeEventListener(`keydown`,t)}},[B]);let G=(0,p.useMemo)(()=>e.find(e=>e.id===E)??null,[e,E]),K=(0,p.useMemo)(()=>e.find(e=>e.id===B)??null,[e,B]),q=!!G?.readonly,J=!!(G?.readonly&&!G?.builtin),Y=(0,p.useMemo)(()=>L.find(e=>y(e)===O.fixedModelValue),[O.fixedModelValue,L]),X=O.modelMode===`fixed`&&!!Y&&Y?.reasoning!==!0;function me(e,t){if(e.stopPropagation(),B===t){V(null),U(null);return}let n=e.currentTarget.getBoundingClientRect(),r=Math.max(v,Math.min(n.right-h,window.innerWidth-h-v)),i=n.bottom+_,a=n.top-_-g;U({left:r,top:i+g<=window.innerHeight-v?i:Math.max(v,a)}),V(t)}function Z(e,t){k(n=>({...n,[e]:t}))}function he(e){k(t=>({...t,allowedTools:t.allowedTools.includes(e)?t.allowedTools.filter(t=>t!==e):[...t.allowedTools,e]}))}function ge(){D(null),k(S()),N(``),z(``),T(!0)}function Q(e){D(e.id),k(ce(e)),N(``),z(``),T(!0)}function $(){A||P||(T(!1),D(null),k(S()),N(``))}async function _e(){let e=M.trim();if(!e){z(d(`aiFillAgentInputRequired`));return}if(!I){z(d(`aiFillAgentNoModel`));return}F(!0),z(``);try{let t=await w(`/api/agent-profiles/ai-fill`,{method:`POST`,body:JSON.stringify({instruction:e,model:I,thinkingLevel:fe})});k(e=>({...e,name:t.agent.name,label:t.agent.label,description:t.agent.description,systemPrompt:t.agent.systemPrompt}))}catch(e){z(e instanceof Error?e.message:d(`aiFillAgentFailed`))}finally{F(!1)}}async function ve(){if(C(O)){j(!0),z(``);try{let e=G?.builtin?{model:O.modelMode===`fixed`?b(O.fixedModelValue):{mode:`inherit`}}:le({...O,thinkingLevel:X?`off`:O.thinkingLevel});E?await w(`/api/agent-profiles/${encodeURIComponent(E)}`,{method:`PATCH`,body:JSON.stringify(e)}):await w(`/api/agent-profiles`,{method:`POST`,body:JSON.stringify(e)}),$(),await W()}catch(e){z(e instanceof Error?e.message:d(`requestFailed`))}finally{j(!1)}}}async function ye(e){if(e.builtin||e.readonly)return;let n=!e.enabledAsSubagent,r=e.enabledAsSubagent;t(t=>t.map(t=>t.id===e.id?{...t,enabledAsSubagent:n}:t)),V(null);try{await w(`/api/agent-profiles/${encodeURIComponent(e.id)}`,{method:`PATCH`,body:JSON.stringify({enabledAsSubagent:n})})}catch(n){t(t=>t.map(t=>t.id===e.id?{...t,enabledAsSubagent:r}:t)),z(n instanceof Error?n.message:d(`requestFailed`))}}async function be(e){if(!(e.builtin||e.readonly)&&await ne({description:d(`confirmDeleteAgent`),confirmLabel:d(`confirmDelete`),cancelLabel:d(`cancel`),variant:`destructive`})){z(``);try{await w(`/api/agent-profiles/${encodeURIComponent(e.id)}`,{method:`DELETE`}),await W()}catch(e){z(e instanceof Error?e.message:d(`requestFailed`))}}}return x?(0,m.jsxs)(`div`,{className:`quickforge-settings-stack`,children:[(0,m.jsx)(`div`,{className:`quickforge-settings-heading`,children:(0,m.jsxs)(`h3`,{className:`quickforge-settings-title`,children:[G?.builtin?d(`builtinAgentModelSettings`):d(G?`editAgent`:`createAgent`),(0,m.jsx)(f,{label:G?.builtin?d(`builtinAgentModelOnly`):G?.readonly?d(`readonlyAgentDescription`):d(`agentsDescription`)})]})}),(0,m.jsxs)(`section`,{className:`quickforge-settings-section`,"aria-label":d(G?`editAgent`:`createAgent`),children:[(0,m.jsxs)(`div`,{className:`quickforge-settings-toolbar`,children:[(0,m.jsxs)(`button`,{className:`quickforge-settings-button quickforge-settings-button-secondary`,type:`button`,onClick:$,disabled:A||P,children:[(0,m.jsx)(a,{className:`mr-2 size-4`}),d(`back`)]}),(0,m.jsxs)(`div`,{className:`quickforge-settings-row-main`,children:[(0,m.jsx)(`div`,{className:`quickforge-settings-row-title`,children:G?.builtin?d(`builtinAgentModelSettings`):d(G?`editAgent`:`createAgent`)}),G?.builtin?(0,m.jsx)(`div`,{className:`quickforge-settings-row-description`,children:d(`builtinAgentModelOnly`)}):G?.readonly?(0,m.jsx)(`div`,{className:`quickforge-settings-row-description`,children:d(`readonlyAgentDescription`)}):null]})]}),(0,m.jsx)(`div`,{className:`px-5 py-4`,children:(0,m.jsxs)(`div`,{className:`space-y-4`,children:[(0,m.jsxs)(`div`,{className:`rounded-2xl border border-border bg-muted/20 p-3`,children:[(0,m.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 text-sm font-medium text-foreground`,children:[(0,m.jsx)(o,{className:`size-4 text-primary`}),d(`aiFillAgent`),(0,m.jsx)(f,{label:d(`aiFillAgentDescription`)})]}),(0,m.jsx)(`textarea`,{className:`min-h-20 w-full resize-y rounded-xl border border-input bg-background px-3 py-2 text-sm outline-none transition-colors placeholder:text-muted-foreground/65 focus:border-ring disabled:opacity-60`,value:M,disabled:q||P,onChange:e=>N(e.target.value),placeholder:d(`aiFillAgentPlaceholder`)}),(0,m.jsx)(`div`,{className:`mt-2 flex justify-end`,children:(0,m.jsxs)(u,{variant:`outline`,size:`sm`,onClick:()=>void _e(),disabled:q||P||!M.trim(),children:[(0,m.jsx)(o,{className:`mr-1 size-3.5`}),d(P?`aiFillAgentLoading`:`aiFillAgent`)]})})]}),(0,m.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,m.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[d(`agentName`),(0,m.jsx)(`input`,{className:`mt-1 h-10 w-full rounded-md border border-input bg-background px-3 text-sm outline-none focus:border-ring disabled:opacity-60`,value:O.name,disabled:q,onChange:e=>Z(`name`,e.target.value),placeholder:`reviewer`})]}),(0,m.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[d(`agentLabel`),(0,m.jsx)(`input`,{className:`mt-1 h-10 w-full rounded-md border border-input bg-background px-3 text-sm outline-none focus:border-ring disabled:opacity-60`,value:O.label,disabled:q,onChange:e=>Z(`label`,e.target.value),placeholder:d(`agentLabelPlaceholder`)})]})]}),G?(0,m.jsxs)(`div`,{className:`rounded-xl border border-border bg-muted/20 px-3 py-2 text-sm`,children:[(0,m.jsx)(`div`,{className:`text-xs font-medium text-muted-foreground`,children:d(`agentSourcePath`)}),(0,m.jsx)(`div`,{className:`mt-1 truncate font-mono text-xs text-foreground`,title:G.source?`${G.source}${G.relativePath?` · ${G.relativePath}`:``}`:void 0,children:G.source?`${G.source}${G.relativePath?` · ${G.relativePath}`:``}`:G.builtin?d(`builtinAgent`):`-`})]}):null,(0,m.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[d(`agentDescription`),(0,m.jsx)(`input`,{className:`mt-1 h-10 w-full rounded-md border border-input bg-background px-3 text-sm outline-none focus:border-ring disabled:opacity-60`,value:O.description,disabled:q,onChange:e=>Z(`description`,e.target.value)})]}),(0,m.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[d(`agentSystemPrompt`),(0,m.jsx)(`textarea`,{className:`mt-1 min-h-36 w-full resize-y rounded-xl border border-input bg-background px-3 py-2 text-sm outline-none focus:border-ring disabled:opacity-60`,value:O.systemPrompt,disabled:q,onChange:e=>Z(`systemPrompt`,e.target.value)})]}),(0,m.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,m.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[d(`agentModelMode`),(0,m.jsxs)(`select`,{className:`mt-1 h-10 w-full rounded-md border border-input bg-background px-3 text-sm outline-none focus:border-ring disabled:opacity-60`,value:O.modelMode,disabled:J,onChange:e=>Z(`modelMode`,e.target.value),children:[(0,m.jsx)(`option`,{value:`inherit`,children:d(`agentModelInherit`)}),(0,m.jsx)(`option`,{value:`fixed`,children:d(`agentModelFixed`)})]})]}),(0,m.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[d(`agentFixedModel`),(0,m.jsxs)(`select`,{className:`mt-1 h-10 w-full rounded-md border border-input bg-background px-3 text-sm outline-none focus:border-ring disabled:opacity-60`,value:O.fixedModelValue,disabled:J||O.modelMode!==`fixed`,onChange:e=>Z(`fixedModelValue`,e.target.value),children:[(0,m.jsx)(`option`,{value:``,children:d(`agentModelInherit`)}),L.map(e=>(0,m.jsx)(`option`,{value:y(e),children:se(e)},y(e)))]})]})]}),(0,m.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[d(`agentThinkingLevel`),(0,m.jsxs)(`select`,{className:`mt-1 h-10 w-full rounded-md border border-input bg-background px-3 text-sm outline-none focus:border-ring disabled:opacity-60`,value:X&&O.thinkingLevel!==`inherit`?`off`:O.thinkingLevel,disabled:q||X,onChange:e=>Z(`thinkingLevel`,e.target.value),children:[(0,m.jsx)(`option`,{value:`inherit`,children:d(`agentThinkingInherit`)}),(0,m.jsx)(`option`,{value:`off`,children:d(`thinkingOff`)}),(0,m.jsx)(`option`,{value:`low`,children:d(`thinkingLow`)}),(0,m.jsx)(`option`,{value:`medium`,children:d(`thinkingMedium`)}),(0,m.jsx)(`option`,{value:`high`,children:d(`thinkingHigh`)}),(0,m.jsx)(`option`,{value:`xhigh`,children:d(`thinkingXHigh`)})]}),(0,m.jsx)(`span`,{className:`mt-1 block text-xs text-muted-foreground`,children:d(X?`agentThinkingUnsupported`:`agentThinkingDescription`)})]}),(0,m.jsxs)(`div`,{children:[(0,m.jsx)(`div`,{className:`mb-2 text-sm font-medium text-foreground`,children:d(`allowedTools`)}),(0,m.jsx)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:s.map(e=>(0,m.jsxs)(`label`,{className:`flex items-start gap-2 rounded-xl border border-border bg-muted/20 p-3 text-sm disabled:opacity-60`,children:[(0,m.jsx)(`input`,{type:`checkbox`,className:`mt-1`,disabled:q,checked:O.allowedTools.includes(e.name),onChange:()=>he(e.name)}),(0,m.jsxs)(`span`,{children:[(0,m.jsx)(`span`,{className:`font-medium text-foreground`,children:e.label}),(0,m.jsx)(`span`,{className:`ml-2 font-mono text-xs text-muted-foreground`,children:e.name}),e.riskLevel===`dangerous`?(0,m.jsx)(`span`,{className:`ml-2 rounded-full bg-amber-500/10 px-2 py-0.5 text-xs text-amber-700`,children:d(`highRiskTool`)}):null,(0,m.jsx)(`span`,{className:`mt-1 block text-xs text-muted-foreground`,children:e.description})]})]},e.name))})]}),(0,m.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,m.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[d(`maxRuntimeMs`),(0,m.jsx)(`input`,{type:`number`,className:`mt-1 h-10 w-full rounded-md border border-input bg-background px-3 text-sm outline-none focus:border-ring disabled:opacity-60`,value:O.maxRuntimeMs,disabled:q,onChange:e=>Z(`maxRuntimeMs`,e.target.value)})]}),(0,m.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[d(`maxToolCalls`),(0,m.jsx)(`input`,{type:`number`,className:`mt-1 h-10 w-full rounded-md border border-input bg-background px-3 text-sm outline-none focus:border-ring disabled:opacity-60`,value:O.maxToolCalls,disabled:q,onChange:e=>Z(`maxToolCalls`,e.target.value)})]})]}),(0,m.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-foreground`,children:[(0,m.jsx)(`input`,{type:`checkbox`,checked:O.enabledAsSubagent,disabled:q,onChange:e=>Z(`enabledAsSubagent`,e.target.checked)}),d(`enabledAsSubagent`)]}),R?(0,m.jsx)(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive`,children:R}):null]})}),(0,m.jsxs)(`div`,{className:`quickforge-settings-divider flex justify-end gap-2 px-5 py-4`,children:[(0,m.jsx)(u,{variant:`outline`,onClick:$,disabled:A||P,children:d(`cancel`)}),(0,m.jsx)(u,{onClick:ve,disabled:A||P||J||!G?.builtin&&!C(O)||O.modelMode===`fixed`&&!O.fixedModelValue,children:d(`save`)})]})]})]}):(0,m.jsxs)(`div`,{className:`quickforge-settings-stack`,children:[(0,m.jsxs)(`section`,{className:`quickforge-settings-section`,"aria-label":d(`agentsTab`),children:[(0,m.jsxs)(`div`,{className:`quickforge-settings-toolbar`,children:[(0,m.jsxs)(`div`,{className:`quickforge-settings-row-main`,children:[(0,m.jsxs)(`div`,{className:`quickforge-settings-row-title`,children:[(0,m.jsx)(r,{className:`size-4 text-primary`}),d(`agentsTab`)]}),(0,m.jsx)(`div`,{className:`quickforge-settings-row-description`,children:d(`agentsDescription`)})]}),(0,m.jsx)(`button`,{className:`quickforge-settings-button quickforge-settings-button-primary`,type:`button`,onClick:ge,children:d(`createAgent`)})]}),R?(0,m.jsx)(`div`,{className:`quickforge-settings-alert quickforge-settings-warning-attached`,children:R}):null,e.length===0?(0,m.jsx)(`div`,{className:`quickforge-settings-empty-row`,children:d(`loading`)}):e.map(e=>(0,m.jsxs)(`div`,{className:`quickforge-settings-list-item quickforge-agent-profile-row`,role:`button`,tabIndex:0,onClick:()=>Q(e),onKeyDown:t=>{t.target===t.currentTarget&&(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),Q(e))},children:[(0,m.jsx)(`div`,{className:`quickforge-settings-list-item-main quickforge-agent-profile-row-main`,children:(0,m.jsxs)(`div`,{className:`quickforge-agent-profile-summary`,children:[(0,m.jsx)(`span`,{className:`quickforge-agent-profile-label`,title:e.label,children:e.label}),e.description?(0,m.jsx)(`span`,{className:`quickforge-agent-profile-description`,title:e.description,children:e.description}):null]})}),(0,m.jsxs)(`div`,{className:`quickforge-settings-list-item-actions`,onClick:e=>e.stopPropagation(),children:[(0,m.jsxs)(`label`,{className:`quickforge-settings-switch`,"aria-disabled":e.builtin||e.readonly?`true`:`false`,title:e.enabledAsSubagent?d(`disableAsSubagent`):d(`enableAsSubagent`),children:[(0,m.jsx)(`input`,{type:`checkbox`,checked:e.enabledAsSubagent,disabled:e.builtin||e.readonly,onChange:()=>void ye(e)}),(0,m.jsx)(`span`,{"aria-hidden":`true`})]}),(0,m.jsx)(`button`,{className:`quickforge-settings-icon-action`,type:`button`,onClick:t=>me(t,e.id),title:d(`moreActions`),"aria-label":d(`moreActions`),"aria-haspopup":`menu`,"aria-expanded":B===e.id,children:(0,m.jsx)(n,{className:`size-4`})})]})]},e.id))]}),K&&H?(0,oe.createPortal)((0,m.jsxs)(`div`,{className:`fixed z-50 w-36 overflow-hidden rounded-xl border border-border bg-popover py-1 text-sm shadow-quickforge`,style:{left:H.left,top:H.top},role:`menu`,"aria-label":d(`moreActions`),onClick:e=>e.stopPropagation(),children:[(0,m.jsxs)(`button`,{className:`flex w-full items-center gap-2 px-3 py-2 text-left hover:bg-muted disabled:cursor-not-allowed disabled:opacity-50`,type:`button`,role:`menuitem`,disabled:K.readonly&&!K.builtin,onClick:()=>{V(null),U(null),Q(K)},children:[(0,m.jsx)(i,{className:`size-3.5`}),K.builtin?d(`builtinAgentModelSettings`):d(`editTask`)]}),(0,m.jsxs)(`button`,{className:`flex w-full items-center gap-2 px-3 py-2 text-left text-destructive hover:bg-muted disabled:cursor-not-allowed disabled:opacity-50`,type:`button`,role:`menuitem`,disabled:K.builtin||K.readonly,onClick:()=>{V(null),U(null),be(K)},children:[(0,m.jsx)(ee,{className:`size-3.5`}),d(`delete`)]})]}),document.body):null]})}export{T as AgentProfilesPage};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{G as t,Ot as n,Q as r,St as i,T as ee,Tt as a,X as te,a as ne,c as re,ct as ie,g as ae,t as oe,ut as se,xt as ce}from"./icons-ko_i0WpN.js";import{n as o}from"./react-vendor-2RKYr-A4.js";import{$ as le,Q as ue,V as de,Z as fe,et as pe,lt as s,mt as c,st as me,tt as he,ut as l}from"./index-B8Awq5FV.js";var u=e(n(),1),d=o(),ge=[{value:`off`,label:()=>c(`thinkingOff`)},{value:`low`,label:()=>c(`thinkingLow`)},{value:`medium`,label:()=>c(`thinkingMedium`)},{value:`high`,label:()=>c(`thinkingHigh`)},{value:`xhigh`,label:()=>c(`thinkingXHigh`)}];function _e(e){return`${e.provider} / ${e.id}`}function ve(e,t){return!!(e&&t&&e.api===t.api&&e.provider===t.provider&&e.id===t.id)}function f(e){return String(e).padStart(2,`0`)}function p(e){if(!e)return`-`;let t=new Date(e);return Number.isNaN(t.getTime())?`-`:`${t.getFullYear()}-${f(t.getMonth()+1)}-${f(t.getDate())} ${f(t.getHours())}:${f(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 m(){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 h(e){return!!(e.currentRunId||e.currentRunIds?.length)}function we(e){return(e.executionMode??`serial`)===`parallel`||!h(e)}function Te(e){return c(e===`parallel`?`taskExecutionModeParallel`:`taskExecutionModeSerial`)}function Ee(e){return!!(e.title.trim()&&e.instruction.trim()&&e.cronExpression.trim())}function De(e){return c(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 g(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 _({onOpenSession:e}){let[n,o]=(0,u.useState)([]),[f,_]=(0,u.useState)(`tasks`),[v,y]=(0,u.useState)(()=>be()),[b,ke]=(0,u.useState)(null),[x,S]=(0,u.useState)(null),[C,w]=(0,u.useState)(null),[T,E]=(0,u.useState)(!1),[D,O]=(0,u.useState)(null),[Ae,k]=(0,u.useState)(``),[A,j]=(0,u.useState)(!1),[M,N]=(0,u.useState)(``),[P,je]=(0,u.useState)([]),[F,I]=(0,u.useState)(),[L,R]=(0,u.useState)(`off`),[z,Me]=(0,u.useState)([]),[Ne,B]=(0,u.useState)(``),[V,H]=(0,u.useState)(()=>m()),[U,W]=(0,u.useState)(()=>m()),[G,Pe]=(0,u.useState)({runs:[],total:0,page:1,pageSize:10}),[Fe,Ie]=(0,u.useState)(!1),[Le,Re]=(0,u.useState)(null),[ze,Be]=(0,u.useState)([]),Ve=z[0]?.id??``;(0,u.useEffect)(()=>{if(!C)return;let e=()=>w(null);return window.addEventListener(`click`,e),window.addEventListener(`blur`,e),()=>{window.removeEventListener(`click`,e),window.removeEventListener(`blur`,e)}},[C]);async function He(){o((await g(`/api/scheduled-tasks`)).tasks)}async function K(e=U){Ie(!0),N(``);try{let t=new URLSearchParams;t.set(`page`,String(e.page)),t.set(`pageSize`,String(e.pageSize)),e.taskId&&t.set(`taskId`,e.taskId),e.status&&t.set(`status`,e.status),e.trigger&&t.set(`trigger`,e.trigger),e.keyword.trim()&&t.set(`keyword`,e.keyword.trim()),e.startedFrom&&t.set(`startedFrom`,e.startedFrom),e.startedTo&&t.set(`startedTo`,e.startedTo),Pe(await g(`/api/scheduled-tasks/runs?${t.toString()}`))}catch(e){N(e instanceof Error?e.message:c(`requestFailed`))}finally{Ie(!1)}}(0,u.useEffect)(()=>{let e=!1;async function t(){try{let t=await g(`/api/project`);if(e)return;Me(t.projects??[])}catch{}}return t(),()=>{e=!0}},[]),(0,u.useEffect)(()=>{let e=!1;async function t(){try{let t=await le(),n=await ue(t),r=await pe(t),i=r.model??await he(t)??n[0];if(e)return;je(n),I(i),R(r.thinkingLevel??fe(i))}catch(t){e||N(t instanceof Error?t.message:c(`requestFailed`))}}return t(),()=>{e=!0}},[]),(0,u.useEffect)(()=>{let e=!1,t=async()=>{try{let t=await g(`/api/scheduled-tasks`);e||o(t.tasks)}catch(t){e||N(t instanceof Error?t.message:c(`requestFailed`))}};t();let n=window.setInterval(t,10*1e3);return()=>{e=!0,window.clearInterval(n)}},[]),(0,u.useEffect)(()=>{let e=!1;async function t(){try{let t=await g(`/api/agent-profiles`);if(e)return;Be(t.agents)}catch(t){e||N(t instanceof Error?t.message:c(`requestFailed`))}}return t(),()=>{e=!0}},[]);let Ue=(0,u.useMemo)(()=>n.find(e=>e.id===b),[b,n]),q=(0,u.useMemo)(()=>n.find(e=>e.id===x)??null,[x,n]),We=(0,u.useMemo)(()=>n.filter(e=>e.status===`enabled`).length,[n]),J=Math.max(1,Math.ceil(G.total/G.pageSize));function Y(e){return e?ze.find(t=>t.id===e||t.name===e)?.label??e:c(`defaultAgent`)}function X(e,t){y(n=>({...n,[e]:t}))}function Z(e,t){H(n=>({...n,[e]:t}))}function Ge(){ke(null),B(Ve),y(be()),O(null),k(``),N(``)}function Ke(){Ge(),E(!0)}function Q(){A||(E(!1),Ge())}function qe(){let e={...V,page:1};H(e),W(e),K(e)}function Je(){let e=m();H(e),W(e),K(e)}function Ye(e){let t=Math.min(Math.max(1,e),J),n={...U,page:t};H(n),W(n),K(n)}function Xe(e){let t={...U,page:1,pageSize:e};H(t),W(t),K(t)}async function Ze(){let e=v.scheduleText.trim();if(e){j(!0),N(``);try{let t=await g(`/api/scheduled-tasks/parse`,{method:`POST`,body:JSON.stringify({instruction:e,model:F,thinkingLevel:L})});if(t.needMoreInfo||!t.task){k(t.question||`请补充任务信息。`),O(null);return}let n=t.task;k(``),O(n),y(e=>Se(n,e))}catch(e){N(e instanceof Error?e.message:c(`requestFailed`))}finally{j(!1)}}}async function Qe(){if(Ee(v)){j(!0),N(``);try{let e=z.find(e=>e.id===Ne),t={task:Ce(v),model:F,thinkingLevel:L,projectId:e?.id,projectName:e?.name};b?await g(`/api/scheduled-tasks/${encodeURIComponent(b)}`,{method:`PUT`,body:JSON.stringify(t)}):await g(`/api/scheduled-tasks`,{method:`POST`,body:JSON.stringify(t)}),Q(),await He(),f===`history`&&await K(U)}catch(e){N(e instanceof Error?e.message:c(`requestFailed`))}finally{j(!1)}}}function $e(e){w(null),ke(e.id),y(xe(e)),O(null),k(``),N(``),B(e.projectId??``),e.model&&I(e.model),e.thinkingLevel&&R(e.thinkingLevel),E(!0)}async function $(e,t){if(N(``),w(null),!(t===`delete`&&!await de({description:c(`confirmDeleteTask`),confirmLabel:c(`confirmDelete`),cancelLabel:c(`cancel`),variant:`destructive`})))try{t===`delete`?(await g(`/api/scheduled-tasks/${encodeURIComponent(e)}`,{method:`DELETE`}),b===e&&Q(),x===e&&S(null)):await g(`/api/scheduled-tasks/${encodeURIComponent(e)}/${t}`,{method:`POST`}),await He(),f===`history`&&await K(U)}catch(e){N(e instanceof Error?e.message:c(`requestFailed`))}}function et(t){return(0,d.jsxs)(`div`,{className:`mt-2 space-y-2 text-xs text-muted-foreground`,children:[t.sessionId?(0,d.jsx)(s,{variant:`outline`,size:`sm`,onClick:()=>e?.(t.sessionId),children:c(`viewConversation`)}):null,(0,d.jsxs)(`div`,{children:[c(`executionAgent`),t.agentLabel||Y(t.agentId)]}),t.warning?(0,d.jsx)(`div`,{className:`text-amber-600`,children:t.warning}):null,t.inputContent?(0,d.jsxs)(`div`,{children:[(0,d.jsx)(`div`,{className:`font-medium text-foreground`,children:c(`runInputContent`)}),(0,d.jsx)(`pre`,{className:`mt-1 max-h-32 overflow-auto whitespace-pre-wrap`,children:t.inputContent})]}):null,t.aiResult||t.result?(0,d.jsxs)(`div`,{children:[(0,d.jsx)(`div`,{className:`font-medium text-foreground`,children:c(`runAiResult`)}),(0,d.jsx)(`pre`,{className:`mt-1 max-h-48 overflow-auto whitespace-pre-wrap`,children:t.aiResult||t.result})]}):null,t.errorMessage?(0,d.jsx)(`div`,{className:`text-destructive`,children:t.errorMessage}):null,t.durationMs?(0,d.jsxs)(`div`,{children:[c(`runDuration`),t.durationMs,`ms`]}):null]})}return(0,d.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden bg-background`,children:[(0,d.jsxs)(`div`,{className:`border-b border-border px-6 py-5`,children:[(0,d.jsx)(`div`,{className:`flex flex-wrap items-center justify-end gap-3`,children:T||q?(0,d.jsxs)(s,{variant:`outline`,onClick:()=>{T?Q():S(null)},children:[(0,d.jsx)(a,{className:`mr-1 size-4`}),c(`back`)]}):(0,d.jsx)(s,{onClick:Ke,children:c(`createTask`)})}),!T&&!q?(0,d.jsxs)(`div`,{className:`mt-4 flex flex-wrap gap-2`,children:[(0,d.jsxs)(`button`,{type:`button`,className:l(`rounded-full px-4 py-2 text-sm font-medium transition-colors`,f===`tasks`?`bg-primary text-primary-foreground`:`bg-muted text-muted-foreground hover:text-foreground`),onClick:()=>_(`tasks`),children:[c(`taskListTab`),` `,(0,d.jsx)(`span`,{className:`opacity-80`,children:n.length})]}),(0,d.jsx)(`button`,{type:`button`,className:l(`rounded-full px-4 py-2 text-sm font-medium transition-colors`,f===`history`?`bg-primary text-primary-foreground`:`bg-muted text-muted-foreground hover:text-foreground`),onClick:()=>{_(`history`),K(U)},children:c(`executionHistoryTab`)})]}):null]}),(0,d.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-6`,children:(0,d.jsx)(`div`,{className:`mx-auto max-w-5xl space-y-5`,children:T?(0,d.jsxs)(d.Fragment,{children:[(0,d.jsxs)(`div`,{className:`rounded-xl border border-border bg-card p-5 space-y-4`,children:[(0,d.jsxs)(`h2`,{className:`inline-flex items-center gap-1.5 text-base font-semibold text-foreground`,children:[c(Ue?`editTask`:`createTask`),(0,d.jsx)(me,{label:c(`quickAiParseTask`)})]}),(0,d.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[c(`taskScheduleDescriptionLabel`),(0,d.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:v.scheduleText,onChange:e=>X(`scheduleText`,e.target.value),placeholder:c(`taskScheduleDescriptionPlaceholder`)})]}),(0,d.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,d.jsxs)(s,{onClick:Ze,disabled:A||!F||!v.scheduleText.trim(),children:[(0,d.jsx)(re,{className:`mr-1 size-3.5`}),c(`aiParseTask`)]}),Ae?(0,d.jsx)(`span`,{className:`text-sm text-amber-600`,children:Ae}):null]}),(0,d.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,d.jsxs)(`label`,{className:`block text-sm font-medium text-foreground`,children:[c(`taskTitleLabel`),(0,d.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:v.title,onChange:e=>X(`title`,e.target.value),placeholder:c(`taskTitlePlaceholder`)})]}),(0,d.jsxs)(`div`,{className:`block text-sm font-medium text-foreground`,children:[c(`executionRule`),(0,d.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:v.scheduleRule||`-`})]}),(0,d.jsxs)(`div`,{className:`block text-sm font-medium text-foreground`,children:[`cron`,(0,d.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:v.cronExpression||`-`})]}),(0,d.jsxs)(`div`,{className:`block text-sm font-medium text-foreground`,children:[c(`nextExecutionTime`),(0,d.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:p(v.nextRunAt)})]}),(0,d.jsxs)(`label`,{className:`block text-sm font-medium text-foreground sm:col-span-2`,children:[(0,d.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[c(`taskExecutionMode`),(0,d.jsx)(me,{label:c(`taskExecutionModeHelp`)})]}),(0,d.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:v.executionMode,onChange:e=>X(`executionMode`,e.target.value),children:[(0,d.jsx)(`option`,{value:`serial`,children:c(`taskExecutionModeSerial`)}),(0,d.jsx)(`option`,{value:`parallel`,children:c(`taskExecutionModeParallel`)})]})]}),(0,d.jsxs)(`label`,{className:`block text-sm font-medium text-foreground sm:col-span-2`,children:[c(`promptContentLabel`),(0,d.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:v.instruction,onChange:e=>X(`instruction`,e.target.value),placeholder:c(`promptContentPlaceholder`)})]})]}),(0,d.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-foreground`,children:[(0,d.jsx)(`input`,{type:`checkbox`,checked:v.enabled,onChange:e=>X(`enabled`,e.target.checked)}),c(`taskEnabledSwitch`)]}),(0,d.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 rounded-xl border border-border bg-muted/20 px-2 py-2`,children:[(0,d.jsxs)(`span`,{className:`relative inline-flex items-center`,children:[(0,d.jsx)(re,{className:`pointer-events-none absolute left-2 size-3.5 text-muted-foreground/70`}),(0,d.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:F?`${F.provider}\u0000${F.id}`:``,onChange:e=>{let t=P.find(t=>`${t.provider}\u0000${t.id}`===e.target.value);I(t),R(fe(t))},title:c(`taskModel`),children:[P.length===0?(0,d.jsx)(`option`,{value:``,children:c(`noModelAvailable`)}):null,P.map(e=>(0,d.jsxs)(`option`,{value:`${e.provider}\u0000${e.id}`,children:[_e(e),ve(e,F)?` ✓`:``]},`${e.provider}:${e.id}`))]})]}),(0,d.jsxs)(`span`,{className:`relative inline-flex items-center`,children:[(0,d.jsx)(ce,{className:`pointer-events-none absolute left-2 size-3.5 text-muted-foreground/70`}),(0,d.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:L,onChange:e=>R(e.target.value),title:c(`taskThinking`),children:ge.map(e=>(0,d.jsx)(`option`,{value:e.value,children:e.label()},e.value))})]}),(0,d.jsxs)(`span`,{className:`relative inline-flex items-center`,children:[(0,d.jsx)(t,{className:`pointer-events-none absolute left-2 size-3.5 text-muted-foreground/70`}),(0,d.jsxs)(`select`,{className:`h-8 max-w-[220px] rounded-md border border-transparent bg-transparent pl-7 pr-2 text-xs text-muted-foreground outline-none hover:bg-background focus:border-ring`,value:Ne,onChange:e=>B(e.target.value),title:c(`taskProjectLabel`),children:[(0,d.jsx)(`option`,{value:``,children:c(`noProjectBound`)}),z.map(e=>(0,d.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,d.jsxs)(`span`,{className:`relative inline-flex items-center`,children:[(0,d.jsx)(i,{className:`pointer-events-none absolute left-2 size-3.5 text-muted-foreground/70`}),(0,d.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:v.agentId,onChange:e=>X(`agentId`,e.target.value),title:c(`executionAgent`),children:[(0,d.jsx)(`option`,{value:``,children:c(`defaultAgent`)}),ze.map(e=>(0,d.jsx)(`option`,{value:e.id,children:e.label},e.id))]})]})]}),D?(0,d.jsxs)(`div`,{className:`rounded-xl border border-border bg-muted/30 p-3 text-sm`,children:[(0,d.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 font-medium text-foreground`,children:[(0,d.jsx)(se,{className:`size-4 text-emerald-600`}),c(`aiParsed`)]}),(0,d.jsxs)(`div`,{className:`grid gap-2 text-muted-foreground sm:grid-cols-2`,children:[(0,d.jsxs)(`div`,{children:[c(`taskName`),(0,d.jsx)(`span`,{className:`text-foreground`,children:D.title})]}),(0,d.jsxs)(`div`,{children:[c(`executionRule`),(0,d.jsx)(`span`,{className:`text-foreground`,children:D.scheduleRule})]}),(0,d.jsxs)(`div`,{children:[`cron:`,(0,d.jsx)(`span`,{className:`font-mono text-foreground`,children:D.cronExpression??`-`})]}),(0,d.jsxs)(`div`,{children:[c(`nextExecutionTime`),(0,d.jsx)(`span`,{className:`text-foreground`,children:p(D.nextRunAt)})]}),(0,d.jsxs)(`div`,{className:`sm:col-span-2`,children:[c(`aiInstruction`),(0,d.jsx)(`span`,{className:`text-foreground`,children:D.instruction})]})]})]}):null,M?(0,d.jsx)(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive`,children:M}):null]}),(0,d.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,d.jsx)(s,{variant:`outline`,onClick:Q,disabled:A,children:c(`cancel`)}),(0,d.jsx)(s,{onClick:Qe,disabled:A||!F||!Ee(v),children:c(Ue?`saveTask`:`confirmCreate`)})]})]}):q?(0,d.jsxs)(`div`,{className:`rounded-xl border border-border bg-card`,children:[(0,d.jsx)(`div`,{className:`flex flex-wrap items-start justify-between gap-3 border-b border-border px-5 py-4`,children:(0,d.jsxs)(`div`,{children:[(0,d.jsx)(`h2`,{className:`text-base font-semibold text-foreground`,children:q.title}),(0,d.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:q.scheduleRule})]})}),(0,d.jsx)(`div`,{className:`px-5 py-4`,children:(0,d.jsxs)(`div`,{className:`space-y-4 text-sm`,children:[(0,d.jsxs)(`div`,{children:[(0,d.jsx)(`div`,{className:`mb-1 font-medium text-foreground`,children:c(`taskContent`)}),(0,d.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:q.instruction})]}),(0,d.jsxs)(`div`,{className:`grid gap-3 text-muted-foreground sm:grid-cols-2`,children:[(0,d.jsxs)(`div`,{children:[c(`executionRule`),(0,d.jsx)(`span`,{className:`text-foreground`,children:q.scheduleRule})]}),(0,d.jsxs)(`div`,{children:[c(`taskExecutionMode`),`:`,(0,d.jsx)(`span`,{className:`text-foreground`,children:Te(q.executionMode)})]}),(0,d.jsxs)(`div`,{children:[`cron:`,(0,d.jsx)(`span`,{className:`font-mono text-foreground`,children:q.cronExpression??`-`})]}),(0,d.jsxs)(`div`,{children:[c(`lastExecution`),(0,d.jsx)(`span`,{className:`text-foreground`,children:p(q.lastRunAt)})]}),(0,d.jsxs)(`div`,{children:[c(`nextExecution`),(0,d.jsx)(`span`,{className:`text-foreground`,children:p(q.nextRunAt)})]}),(0,d.jsxs)(`div`,{children:[c(`executionAgent`),(0,d.jsx)(`span`,{className:`text-foreground`,children:Y(q.agentId)})]}),q.projectName?(0,d.jsxs)(`div`,{children:[c(`taskProject`),(0,d.jsx)(`span`,{className:`text-foreground`,children:q.projectName})]}):null,q.model?(0,d.jsxs)(`div`,{children:[c(`taskModel`),`:`,(0,d.jsx)(`span`,{className:`text-foreground`,children:_e(q.model)})]}):null,q.thinkingLevel?(0,d.jsxs)(`div`,{children:[c(`taskThinkingLevel`),(0,d.jsx)(`span`,{className:`text-foreground`,children:ge.find(e=>e.value===q.thinkingLevel)?.label()??q.thinkingLevel})]}):null,(0,d.jsxs)(`div`,{children:[c(`createdAt`),`:`,(0,d.jsx)(`span`,{className:`text-foreground`,children:p(q.createdAt)})]})]}),q.runs?.length>0?(0,d.jsxs)(`div`,{children:[(0,d.jsx)(`div`,{className:`mb-2 font-medium text-foreground`,children:c(`recentExecutions`)}),(0,d.jsx)(`div`,{className:`space-y-2`,children:q.runs.slice(0,5).map(e=>(0,d.jsxs)(`details`,{className:`rounded-lg border border-border bg-muted/20 p-2 text-xs text-muted-foreground`,children:[(0,d.jsxs)(`summary`,{className:`cursor-pointer text-foreground`,children:[p(e.startedAt),` · `,e.trigger===`manual`?c(`manualRun`):c(`autoRun`),` · `,De(e.status)]}),et(e)]},e.id))})]}):null]})}),(0,d.jsx)(`div`,{className:`border-t border-border px-5 py-4`,children:(0,d.jsxs)(`div`,{className:`flex flex-wrap justify-end gap-2`,children:[q.lastSessionId?(0,d.jsx)(s,{variant:`outline`,onClick:()=>e?.(q.lastSessionId),children:c(`viewConversation`)}):null,(0,d.jsxs)(s,{variant:`outline`,disabled:!we(q),onClick:()=>void $(q.id,`run`),children:[(0,d.jsx)(oe,{className:`mr-1 size-3.5`}),c(`executeNow`)]}),(0,d.jsxs)(s,{variant:`outline`,disabled:h(q),onClick:()=>$e(q),children:[(0,d.jsx)(ee,{className:`mr-1 size-3.5`}),c(`editTask`)]}),(0,d.jsxs)(s,{variant:`destructive`,disabled:h(q),onClick:()=>void $(q.id,`delete`),children:[(0,d.jsx)(ne,{className:`mr-1 size-3.5`}),c(`deleteTask`)]})]})})]}):(0,d.jsxs)(d.Fragment,{children:[M?(0,d.jsx)(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive`,children:M}):null,f===`tasks`?(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(`div`,{className:`rounded-xl border border-border bg-card p-4`,children:(0,d.jsx)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:(0,d.jsxs)(`div`,{children:[(0,d.jsx)(`h2`,{className:`text-base font-semibold text-foreground`,children:c(`taskList`)}),(0,d.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:c(`tasksCount`,{total:n.length,enabled:We})})]})})}),(0,d.jsx)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:n.length===0?(0,d.jsx)(`div`,{className:`rounded-lg px-3 py-3 text-center text-xs text-muted-foreground/55 md:col-span-2`,children:c(`noScheduledTasks`)}):n.map(e=>{let t=e.status===`enabled`,n=e.status===`completed`,a=h(e);return(0,d.jsxs)(`div`,{className:`relative cursor-pointer rounded-xl border border-border bg-card p-4 transition-colors hover:bg-muted/15`,onClick:()=>S(e.id),children:[(0,d.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,d.jsxs)(`div`,{className:`min-w-0`,children:[(0,d.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,d.jsx)(`h3`,{className:`truncate text-sm font-medium text-foreground/90`,children:e.title})}),(0,d.jsx)(`p`,{className:`mt-2 text-sm text-muted-foreground`,children:ye(e.instruction,20)})]}),(0,d.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,onClick:e=>e.stopPropagation(),children:[(0,d.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":t,disabled:n,className:l(`relative h-6 w-11 rounded-full transition-colors disabled:cursor-not-allowed disabled:opacity-60`,t?`bg-emerald-500`:`bg-muted-foreground/30`),onClick:()=>void $(e.id,e.status===`paused`?`resume`:`pause`),title:e.status===`paused`?c(`enable`):c(`pauseTask`),children:(0,d.jsx)(`span`,{className:l(`absolute left-0.5 top-0.5 size-5 rounded-full bg-white shadow transition-transform`,t?`translate-x-5`:`translate-x-0`)})}),(0,d.jsxs)(`div`,{className:`relative`,children:[(0,d.jsx)(s,{variant:`ghost`,size:`icon`,onClick:()=>w(C===e.id?null:e.id),title:c(`moreActions`),children:(0,d.jsx)(r,{className:`size-4`})}),C===e.id?(0,d.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,d.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,d.jsx)(oe,{className:`size-3.5`}),c(`executeNow`)]}),(0,d.jsxs)(`button`,{className:`flex w-full items-center gap-2 px-3 py-2 text-left hover:bg-muted disabled:cursor-not-allowed disabled:opacity-50`,disabled:a,onClick:()=>$e(e),children:[(0,d.jsx)(ee,{className:`size-3.5`}),c(`editTask`)]}),(0,d.jsxs)(`button`,{className:`flex w-full items-center gap-2 px-3 py-2 text-left hover:bg-muted`,onClick:()=>{w(null),S(e.id)},children:[(0,d.jsx)(te,{className:`size-3.5`}),c(`viewDetails`)]}),(0,d.jsxs)(`button`,{className:`flex w-full items-center gap-2 px-3 py-2 text-left text-destructive hover:bg-muted disabled:cursor-not-allowed disabled:opacity-50`,disabled:a,onClick:()=>void $(e.id,`delete`),children:[(0,d.jsx)(ne,{className:`size-3.5`}),c(`deleteTask`)]})]}):null]})]})]}),(0,d.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-x-4 gap-y-1 text-xs text-muted-foreground`,children:[(0,d.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,d.jsx)(ie,{className:`size-3`}),e.scheduleRule]}),(0,d.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,d.jsx)(i,{className:`size-3`}),Y(e.agentId)]}),(0,d.jsxs)(`span`,{children:[c(`taskExecutionMode`),`:`,Te(e.executionMode)]}),e.projectName?(0,d.jsxs)(`span`,{children:[c(`taskProject`),e.projectName]}):null]}),(0,d.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,d.jsxs)(`span`,{children:[c(`lastExecution`),p(e.lastRunAt)]}),(0,d.jsxs)(`span`,{children:[c(`nextExecution`),p(e.nextRunAt)]})]})]},e.id)})})]}):(0,d.jsxs)(`div`,{className:`space-y-4`,children:[(0,d.jsxs)(`div`,{className:`rounded-xl border border-border bg-card p-4`,children:[(0,d.jsxs)(`div`,{className:`mb-3 flex items-center gap-2 text-sm font-medium text-foreground`,children:[(0,d.jsx)(ae,{className:`size-4`}),c(`historyFilters`)]}),(0,d.jsxs)(`div`,{className:`grid gap-3 md:grid-cols-3`,children:[(0,d.jsxs)(`label`,{className:`block text-xs font-medium text-muted-foreground`,children:[c(`taskName`),(0,d.jsxs)(`select`,{className:`mt-1 h-9 w-full rounded-md border border-input bg-background px-2 text-sm text-foreground`,value:V.taskId,onChange:e=>Z(`taskId`,e.target.value),children:[(0,d.jsx)(`option`,{value:``,children:c(`allTasks`)}),n.map(e=>(0,d.jsx)(`option`,{value:e.id,children:e.title},e.id))]})]}),(0,d.jsxs)(`label`,{className:`block text-xs font-medium text-muted-foreground`,children:[c(`status`),(0,d.jsxs)(`select`,{className:`mt-1 h-9 w-full rounded-md border border-input bg-background px-2 text-sm text-foreground`,value:V.status,onChange:e=>Z(`status`,e.target.value),children:[(0,d.jsx)(`option`,{value:``,children:c(`allStatuses`)}),(0,d.jsx)(`option`,{value:`running`,children:c(`executionRunning`)}),(0,d.jsx)(`option`,{value:`success`,children:c(`executionSuccess`)}),(0,d.jsx)(`option`,{value:`failed`,children:c(`taskFailed`)})]})]}),(0,d.jsxs)(`label`,{className:`block text-xs font-medium text-muted-foreground`,children:[c(`triggerType`),(0,d.jsxs)(`select`,{className:`mt-1 h-9 w-full rounded-md border border-input bg-background px-2 text-sm text-foreground`,value:V.trigger,onChange:e=>Z(`trigger`,e.target.value),children:[(0,d.jsx)(`option`,{value:``,children:c(`allTriggers`)}),(0,d.jsx)(`option`,{value:`schedule`,children:c(`autoRun`)}),(0,d.jsx)(`option`,{value:`manual`,children:c(`manualRun`)})]})]}),(0,d.jsxs)(`label`,{className:`block text-xs font-medium text-muted-foreground`,children:[c(`startTime`),(0,d.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:V.startedFrom,onChange:e=>Z(`startedFrom`,e.target.value)})]}),(0,d.jsxs)(`label`,{className:`block text-xs font-medium text-muted-foreground`,children:[c(`endTime`),(0,d.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:V.startedTo,onChange:e=>Z(`startedTo`,e.target.value)})]}),(0,d.jsxs)(`label`,{className:`block text-xs font-medium text-muted-foreground`,children:[c(`keyword`),(0,d.jsx)(`input`,{className:`mt-1 h-9 w-full rounded-md border border-input bg-background px-2 text-sm text-foreground`,value:V.keyword,onChange:e=>Z(`keyword`,e.target.value),placeholder:c(`keywordPlaceholder`)})]})]}),(0,d.jsxs)(`div`,{className:`mt-3 flex justify-end gap-2`,children:[(0,d.jsx)(s,{variant:`outline`,onClick:Je,children:c(`reset`)}),(0,d.jsx)(s,{onClick:qe,children:c(`query`)})]})]}),(0,d.jsxs)(`div`,{className:`overflow-hidden rounded-xl border border-border bg-card`,children:[(0,d.jsxs)(`div`,{className:`grid grid-cols-[1.3fr_0.7fr_0.7fr_1fr_0.7fr] gap-3 border-b border-border px-4 py-3 text-xs font-medium text-muted-foreground`,children:[(0,d.jsx)(`span`,{children:c(`taskName`)}),(0,d.jsx)(`span`,{children:c(`status`)}),(0,d.jsx)(`span`,{children:c(`triggerType`)}),(0,d.jsx)(`span`,{children:c(`startTime`)}),(0,d.jsx)(`span`,{children:c(`runDuration`)})]}),Fe?(0,d.jsx)(`div`,{className:`p-8 text-center text-sm text-muted-foreground`,children:c(`loading`)}):G.runs.length===0?(0,d.jsx)(`div`,{className:`p-8 text-center text-sm text-muted-foreground`,children:c(`noExecutionHistory`)}):G.runs.map(e=>(0,d.jsxs)(`div`,{className:`border-b border-border last:border-b-0`,children:[(0,d.jsxs)(`button`,{type:`button`,className:`grid w-full grid-cols-[1.3fr_0.7fr_0.7fr_1fr_0.7fr] gap-3 px-4 py-3 text-left text-sm hover:bg-muted/40`,onClick:()=>Re(Le===e.id?null:e.id),children:[(0,d.jsx)(`span`,{className:`min-w-0 truncate text-foreground`,children:e.taskTitle}),(0,d.jsx)(`span`,{children:(0,d.jsx)(`span`,{className:l(`rounded-full px-2 py-0.5 text-xs`,Oe(e.status)),children:De(e.status)})}),(0,d.jsx)(`span`,{className:`text-muted-foreground`,children:e.trigger===`manual`?c(`manualRun`):c(`autoRun`)}),(0,d.jsx)(`span`,{className:`text-muted-foreground`,children:p(e.startedAt)}),(0,d.jsx)(`span`,{className:`text-muted-foreground`,children:e.durationMs?`${e.durationMs}ms`:`-`})]}),Le===e.id?(0,d.jsx)(`div`,{className:`border-t border-border bg-muted/20 px-4 py-3`,children:et(e)}):null]},`${e.taskId}:${e.id}`)),(0,d.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 px-4 py-3 text-sm text-muted-foreground`,children:[(0,d.jsx)(`span`,{children:c(`paginationSummary`,{page:G.page,pages:J,total:G.total})}),(0,d.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,d.jsx)(`select`,{className:`h-8 rounded-md border border-input bg-background px-2 text-sm`,value:G.pageSize,onChange:e=>Xe(Number(e.target.value)),children:[10,20,50,100].map(e=>(0,d.jsx)(`option`,{value:e,children:c(`pageSize`,{size:e})},e))}),(0,d.jsx)(s,{variant:`outline`,size:`sm`,disabled:G.page<=1,onClick:()=>Ye(G.page-1),children:c(`previousPage`)}),(0,d.jsx)(s,{variant:`outline`,size:`sm`,disabled:G.page>=J,onClick:()=>Ye(G.page+1),children:c(`nextPage`)})]})]})]})]})]})})})]})}export{_ as ScheduledTasksPage};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{F as t,L as n,Ot as r,_t as i,j as a,n as o,s,x as c}from"./icons-ko_i0WpN.js";import{n as l}from"./react-vendor-2RKYr-A4.js";import{A as u,N as d,T as f,lt as p,mt as m,ut as h}from"./index-B8Awq5FV.js";import{n as ee,t as g}from"./xterm-CGiQzDiR.js";var _=e(r(),1);async function v(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 y(){return v(`/api/terminal/capabilities`)}function b(e){return v(`/api/terminal/sessions${e?`?projectId=${encodeURIComponent(e)}`:``}`)}function x(e){return v(`/api/terminal/sessions`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(e)})}function S(e){return v(`/api/terminal/sessions/${encodeURIComponent(e)}`,{method:`DELETE`})}function C(e,t){return v(`/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,_.useState)(()=>f());return(0,_.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=l(),D={light:{background:`#ffffff`,foreground:`#1f2937`,cursor:`#1f2937`,selectionBackground:`#dbeafe`},dark:{background:`#171717`,foreground:`#e5e7eb`,cursor:`#e5e7eb`,selectionBackground:`#3f3f46`}};function ne({session:e,active:t,height:n,onReady:r,onExited:i,onConnectionError:a}){let o=T(),s=D[o],c=(0,_.useRef)(null),l=(0,_.useRef)(null),f=(0,_.useRef)(null),p=(0,_.useRef)(null),h=(0,_.useRef)(null),v=(0,_.useRef)(null);return(0,_.useEffect)(()=>{let t=c.current;if(!t)return;let n=!1,o=!1,_=!1,y=!1,b=t=>{n||_||y||(y=!0,a(e.id,t))},x=d(),S=new ee({cursorBlink:!0,convertEol:!1,fontFamily:getComputedStyle(document.documentElement).getPropertyValue(`--font-mono`).trim()||`ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace`,fontSize:x.fontSize,lineHeight:x.lineHeight,scrollback:5e3,theme:s}),C=new g;S.loadAddon(C),S.open(t),S.writeln(`\x1b[2mConnected to ${e.cwd}\x1b[0m`),l.current=S,f.current=C;let w=()=>{if(t.isConnected)try{C.fit();let{cols:e,rows:t}=S,n=p.current;n?.readyState===WebSocket.OPEN&&n.send(JSON.stringify({type:`resize`,cols:e,rows:t}))}catch{}},T=new WebSocket(`${te()}/api/terminal/sessions/${encodeURIComponent(e.id)}/ws`);p.current=T,T.addEventListener(`open`,()=>{o=!0,y=!1,a(e.id,void 0),h.current=S.onData(e=>{T.readyState===WebSocket.OPEN&&T.send(JSON.stringify({type:`input`,data:e}))}),window.setTimeout(w,0)}),T.addEventListener(`message`,t=>{try{let n=JSON.parse(String(t.data));n.type===`ready`?r(e.id):n.type===`output`?S.write(n.data):n.type===`exit`?(_=!0,S.writeln(``),S.writeln(`\x1b[33m[process exited with code ${n.exitCode??`unknown`}]\x1b[0m`),i(e.id)):n.type===`error`&&S.writeln(`\x1b[31m${n.message}\x1b[0m`)}catch{}}),T.addEventListener(`error`,()=>{b(m(o?`terminalConnectionClosedUnexpectedly`:`terminalConnectionFailed`))}),T.addEventListener(`close`,e=>{h.current?.dispose(),h.current=null,!(n||_)&&(!e.wasClean||e.code!==1e3)&&b(m(o?`terminalConnectionClosedUnexpectedly`:`terminalConnectionFailed`))});let E=new ResizeObserver(()=>w());E.observe(t),v.current=E;let D=()=>{let e=d();S.options.fontSize=e.fontSize,S.options.lineHeight=e.lineHeight,window.setTimeout(w,0)};return window.addEventListener(u,D),window.setTimeout(w,50),()=>{n=!0,window.removeEventListener(u,D),E.disconnect(),v.current=null,h.current?.dispose(),h.current=null,T.close(),p.current=null,S.dispose(),l.current=null,f.current=null}},[o,a,i,r,e.cwd,e.id,s]),(0,_.useEffect)(()=>{if(!t)return;let e=f.current,n=l.current;window.setTimeout(()=>{try{e?.fit(),n?.focus()}catch{}},0)},[t,n]),(0,E.jsx)(`div`,{className:t?`h-full min-h-0 w-full pl-2 md:pl-3`:`hidden`,"aria-hidden":!t,children:(0,E.jsx)(`div`,{ref:c,className:`h-full min-h-0 w-full`})})}var re=180,ie=.7,ae=320;function O(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 k(e,t){let n=e?.terminalShellProfiles||[],r=t||e?.defaultTerminalShellProfileId||``;return n.find(e=>e.id===r)||n[0]}function A({project:e,onCollapse:r,pendingCommand:l,onPendingCommandHandled:u,variant:d=`dock`,singleSession:f=!1,panelInstanceId:ee,panelSessionId:g,onPanelSessionReady:v}){let[w,te]=(0,_.useState)(null),[T,D]=(0,_.useState)([]),[A,j]=(0,_.useState)(),[M,oe]=(0,_.useState)(ae),[N,se]=(0,_.useState)(!0),[P,ce]=(0,_.useState)(!1),[le,F]=(0,_.useState)(),[ue,I]=(0,_.useState)({}),[L,R]=(0,_.useState)(!1),[z,de]=(0,_.useState)(!1),B=(0,_.useRef)(!1),V=(0,_.useRef)(!1),H=(0,_.useRef)(new Set),fe=(0,_.useRef)(l),U=(0,_.useRef)(new Set),W=(0,_.useRef)(new Set),G=(0,_.useRef)(new Map),K=(0,_.useRef)(!0),pe=(0,_.useRef)(v),[me,he]=(0,_.useState)(()=>new Set),q=(0,_.useRef)(null),ge=(0,_.useRef)(null),J=e?.id,Y=d===`panel`&&!!ee,X=(0,_.useMemo)(()=>T.find(e=>e.id===A)??T[0],[A,T]);(0,_.useEffect)(()=>{fe.current=l},[l]),(0,_.useEffect)(()=>{pe.current=v},[v]),(0,_.useEffect)(()=>()=>{K.current=!1},[]);let _e=(0,_.useCallback)(async()=>{let e=await b(J);return D(e.sessions),j(t=>t&&e.sessions.some(e=>e.id===t)?t:e.sessions[0]?.id),e.sessions},[J]),ve=(0,_.useCallback)(async(e,t)=>{if(B.current)return;let n=k(w,t);B.current=!0,ce(!0),F(void 0),I({});try{let t=await x({projectId:J,name:O(e,n),cols:120,rows:30,shellProfileId:n?.id,shellProfileName:n?.name});D(e=>[...e,t]),j(t.id)}catch(e){F(e instanceof Error?e.message:m(`terminalCreateFailed`))}finally{B.current=!1,ce(!1)}},[w,J]);(0,_.useEffect)(()=>{let e=!1;return(async()=>{se(!0),F(void 0);try{let[t,n]=await Promise.all([y(),b(J)]);if(e)return;if(te(t),t.enabled&&Y&&g&&n.sessions.some(e=>e.id===g)){V.current=!0,D(n.sessions),j(g);return}if(t.enabled&&Y&&!V.current){V.current=!0;let r=k(t);try{let t=await x({projectId:J,name:O(n.sessions,r),cols:120,rows:30,shellProfileId:r?.id,shellProfileName:r?.name});if(e){S(t.id).catch(()=>{});return}D([...n.sessions,t]),j(t.id),pe.current?.(t.id);return}catch(t){e||F(t instanceof Error?t.message:m(`terminalCreateFailed`))}}if(D(n.sessions),j(n.sessions[0]?.id),t.enabled&&n.sessions.length===0&&!fe.current){let n=k(t);x({projectId:J,name:O([],n),cols:120,rows:30,shellProfileId:n?.id,shellProfileName:n?.name}).then(t=>{if(e){S(t.id).catch(()=>{});return}D([t]),j(t.id)}).catch(t=>{e||F(t instanceof Error?t.message:m(`terminalCreateFailed`))})}}catch(t){e||F(t instanceof Error?t.message:m(`terminalUnavailable`))}finally{e||se(!1)}})(),()=>{e=!0}},[Y,g,J]),(0,_.useEffect)(()=>{if(!L)return;let e=e=>{ge.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,_.useEffect)(()=>{if(!z)return;let e=e=>{e.key===`Escape`&&de(!1)};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[z]),(0,_.useEffect)(()=>{if(!l||H.current.has(l.id)||G.current.has(l.id)||U.current.has(l.id)||N||P||!w)return;if(!w.enabled){H.current.add(l.id),window.setTimeout(()=>{F(w.reason||m(`terminalUnavailable`)),u?.(l.id)},0);return}let e=X&&!X.exited?X:T.find(e=>!e.exited);if(e){G.current.set(l.id,e.id),window.setTimeout(()=>{K.current&&j(e.id)},0);return}U.current.add(l.id),window.setTimeout(()=>{K.current&&F(void 0)},0);let t=k(w);x({projectId:J,name:O(T,t),cols:120,rows:30,shellProfileId:t?.id,shellProfileName:t?.name}).then(e=>{if(!K.current){S(e.id).catch(()=>{});return}G.current.set(l.id,e.id),D(t=>t.some(t=>t.id===e.id)?t:[...t,e]),j(e.id)}).catch(e=>{K.current&&(F(e instanceof Error?e.message:m(`terminalCommandExecuteFailed`)),H.current.add(l.id),u?.(l.id))}).finally(()=>{U.current.delete(l.id)})},[X,w,P,N,u,l,J,T]),(0,_.useEffect)(()=>{if(!l||H.current.has(l.id)||W.current.has(l.id))return;let e=G.current.get(l.id),t=e?T.find(t=>t.id===e):X&&!X.exited?X:T.find(e=>!e.exited);!t||t.exited||!me.has(t.id)||(W.current.add(l.id),window.setTimeout(()=>{K.current&&(j(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 C(t.id,n.join(``))}else await C(t.id,l.command)}catch(e){K.current&&F(e instanceof Error?e.message:m(`terminalCommandExecuteFailed`))}finally{H.current.add(l.id),W.current.delete(l.id),G.current.delete(l.id),K.current&&u?.(l.id)}})())},[X,u,l,me,T]);let ye=async e=>{F(void 0),I(t=>{if(!t[e])return t;let n={...t};return delete n[e],n});let t=T.filter(t=>t.id!==e);D(t),A===e&&j(t[0]?.id);try{await S(e)}catch(e){F(e instanceof Error?e.message:m(`terminalCloseFailed`)),_e().catch(()=>{})}},be=(0,_.useCallback)(e=>{D(t=>t.map(t=>t.id===e?{...t,exited:!0}:t)),he(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),n})},[]),xe=(0,_.useCallback)(e=>{he(t=>{if(t.has(e))return t;let n=new Set(t);return n.add(e),n})},[]),Se=(0,_.useCallback)((e,t)=>{I(n=>{if(!t){if(!n[e])return n;let t={...n};return delete t[e],t}return n[e]===t?n:{...n,[e]:t}})},[]),Ce=e=>{q.current={startY:e.clientY,startHeight:M},e.currentTarget.setPointerCapture(e.pointerId)},we=e=>{let t=q.current;if(!t)return;let n=Math.max(re,Math.floor(window.innerHeight*ie));oe(Math.min(n,Math.max(re,t.startHeight+t.startY-e.clientY)))},Te=e=>{q.current=null;try{e.currentTarget.releasePointerCapture(e.pointerId)}catch{}},Z=w?.terminalShellProfiles||[],Ee=w?.defaultTerminalShellProfileId||``,De=Z.find(e=>e.id===Ee)||Z[0],Oe=!!(w&&T.length>=w.maxSessions),ke=P||Oe,Ae=X?ue[X.id]:void 0,je=Y&&X?[X]:T,Q=le??Ae,$=d===`panel`,Me=$&&f,Ne=$?void 0:z?Q?`calc(100% - 4.25rem)`:`calc(100% - 2.25rem)`:Q?M-72:M-45;return(0,E.jsxs)(`div`,{className:h($?`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:M},children:[!z&&!$?(0,E.jsx)(`div`,{className:`h-1 cursor-row-resize bg-transparent hover:bg-border`,onPointerDown:Ce,onPointerMove:we,onPointerUp:Te,onPointerCancel:Te}):null,(0,E.jsxs)(`div`,{className:`flex h-9 items-center gap-1 border-b border-border px-2`,children:[(0,E.jsx)(s,{className:`size-4 shrink-0 text-muted-foreground/60`}),(0,E.jsx)(`div`,{className:`flex min-w-0 flex-1 items-center gap-1 overflow-x-auto`,children:je.map(e=>{let t=h(`flex max-w-44 shrink-0 items-center gap-1 rounded-md px-2 py-1 text-xs text-muted-foreground/72`,X?.id===e.id&&`bg-muted/28 text-foreground/90`);return Me?(0,E.jsxs)(`div`,{className:t,title:`${e.name} — ${e.cwd}`,children:[(0,E.jsx)(`span`,{className:h(`size-1.5 rounded-full`,e.exited?`bg-muted-foreground/40`:`bg-emerald-500/80`)}),(0,E.jsx)(`span`,{className:`truncate`,children:e.name})]},e.id):(0,E.jsxs)(`button`,{type:`button`,className:h(t,`hover:bg-muted/20 hover:text-foreground/85`),onClick:()=>j(e.id),title:`${e.name} — ${e.cwd}`,children:[(0,E.jsx)(`span`,{className:h(`size-1.5 rounded-full`,e.exited?`bg-muted-foreground/40`:`bg-emerald-500/80`)}),(0,E.jsx)(`span`,{className:`truncate`,children:e.name}),(0,E.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(),ye(e.id)},onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),t.stopPropagation(),ye(e.id))},"aria-label":m(`terminalCloseSession`,{name:e.name}),children:(0,E.jsx)(o,{className:`size-3`})})]},e.id)})}),Me?null:(0,E.jsxs)(`div`,{className:`relative shrink-0`,ref:ge,children:[(0,E.jsxs)(`div`,{className:`flex items-center overflow-hidden rounded-md border border-border bg-background`,children:[(0,E.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 ve(T),disabled:ke,title:De?m(`terminalNewWithProfile`,{name:De.name}):m(`terminalNew`),"aria-label":m(`terminalNew`),children:P?(0,E.jsx)(n,{className:`size-3.5 animate-spin`}):(0,E.jsx)(c,{className:`size-3.5`})}),Z.length>0?(0,E.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:ke,title:m(`terminalSelectShell`),"aria-label":m(`terminalSelectShell`),"aria-expanded":L,children:(0,E.jsx)(i,{className:`size-3.5`})}):null]}),L?(0,E.jsxs)(`div`,{className:h(`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,E.jsx)(`div`,{className:`px-2 pb-1.5 pt-1 text-[11px] font-medium uppercase tracking-wide text-muted-foreground/60`,children:m(`terminalNewWith`)}),Z.map(e=>(0,E.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),ve(T,e.id)},children:[(0,E.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,E.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,E.jsx)(`span`,{className:`block truncate font-medium`,children:e.name}),(0,E.jsx)(`span`,{className:`block truncate font-mono text-[11px] text-muted-foreground/55`,children:e.command})]})]},e.id))]}):null]}),Me?null:(0,E.jsx)(p,{variant:`ghost`,size:`icon`,className:`size-7`,onClick:()=>de(e=>!e),title:m(z?`terminalExitFullscreen`:`terminalFullscreen`),"aria-label":m(z?`terminalExitFullscreen`:`terminalFullscreen`),children:z?(0,E.jsx)(a,{className:`size-3.5`}):(0,E.jsx)(t,{className:`size-3.5`})}),(0,E.jsx)(p,{variant:`ghost`,size:`icon`,className:h(`size-7`,$&&`hidden`),onClick:r,title:m(`terminalCollapse`),"aria-label":m(`terminalCollapse`),children:(0,E.jsx)(i,{className:`size-3.5`})})]}),Q?(0,E.jsx)(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-destructive`,children:Q}):null,(0,E.jsx)(`div`,{className:h(`min-h-0 bg-background`,$&&`flex-1`),style:Ne===void 0?void 0:{height:Ne},children:N?(0,E.jsxs)(`div`,{className:`flex h-full items-center justify-center gap-2 text-xs text-muted-foreground/60`,children:[(0,E.jsx)(n,{className:`size-4 animate-spin`}),` `,m(`terminalStarting`)]}):w&&!w.enabled?(0,E.jsx)(`div`,{className:`flex h-full items-center justify-center px-4 text-center text-xs text-muted-foreground/60`,children:w.reason||m(`terminalUnavailable`)}):T.length===0?(0,E.jsx)(`div`,{className:`flex h-full items-center justify-center text-xs text-muted-foreground/60`,children:m(`terminalNoSessions`)}):T.map(e=>(0,E.jsx)(ne,{session:e,active:e.id===X?.id,height:z?window.innerHeight-36:$?0:M,onReady:xe,onExited:be,onConnectionError:Se},e.id))})]})}export{A as TerminalDock,T as t};
|