(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,21275,e=>{"use strict";var t=e.i(804690),a=e.i(753930),r=e.i(695186),s=e.i(427846),o=e.i(371449),n=e.i(524875),l=e.i(29501),i=e.i(524667),d=e.i(855387);let c=(0,d.default)("outline","upload","Upload",[["path",{d:"M4 17v2a2 2 0 0 0 2 2h12a2 2 0 0 0 2 -2v-2",key:"svg-0"}],["path",{d:"M7 9l5 -5l5 5",key:"svg-1"}],["path",{d:"M12 4l0 12",key:"svg-2"}]]);var p=e.i(879499),u=e.i(929776),m=e.i(189816),h=e.i(677607),f=e.i(120109),g=e.i(611978),x=e.i(670214),w=e.i(605278),v=e.i(635613),j=e.i(880177),k=e.i(798764),b=e.i(499023);function S(e){return(0,b.useAppStore)(e=>e.agentProfiles.items).filter(t=>!t.capability_status||"ok"===t.capability_status||"probing"===t.capability_status||t.id===e)}var _=e.i(550507),y=e.i(954337),N=e.i(844368),C=e.i(67470),D=e.i(618528),T=e.i(610120),I=e.i(569908);function W({open:e,onOpenChange:a,title:r,content:s}){let{copied:o,copy:n}=(0,I.useCopyToClipboard)();return(0,t.jsx)(D.Dialog,{open:e,onOpenChange:a,children:(0,t.jsxs)(D.DialogContent,{className:"sm:max-w-2xl",children:[(0,t.jsx)(D.DialogHeader,{children:(0,t.jsx)(D.DialogTitle,{children:r})}),(0,t.jsx)(T.Textarea,{readOnly:!0,value:s,className:"font-mono text-xs max-h-96 overflow-y-auto"}),(0,t.jsxs)(D.DialogFooter,{children:[(0,t.jsx)(h.Button,{variant:"outline",onClick:()=>a(!1),className:"cursor-pointer",children:"Close"}),(0,t.jsxs)(h.Button,{onClick:()=>n(s),className:"cursor-pointer",children:[o?(0,t.jsx)(N.IconCheck,{className:"h-4 w-4 mr-2"}):(0,t.jsx)(C.IconCopy,{className:"h-4 w-4 mr-2"}),o?"Copied":"Copy"]})]})]})})}var O=e.i(142891),R=e.i(29699);let M=(0,d.default)("outline","rosette-number-1","RosetteNumber1",[["path",{d:"M10 10l2 -2v8",key:"svg-0"}],["path",{d:"M5 7.2a2.2 2.2 0 0 1 2.2 -2.2h1a2.2 2.2 0 0 0 1.55 -.64l.7 -.7a2.2 2.2 0 0 1 3.12 0l.7 .7c.412 .41 .97 .64 1.55 .64h1a2.2 2.2 0 0 1 2.2 2.2v1c0 .58 .23 1.138 .64 1.55l.7 .7a2.2 2.2 0 0 1 0 3.12l-.7 .7a2.2 2.2 0 0 0 -.64 1.55v1a2.2 2.2 0 0 1 -2.2 2.2h-1a2.2 2.2 0 0 0 -1.55 .64l-.7 .7a2.2 2.2 0 0 1 -3.12 0l-.7 -.7a2.2 2.2 0 0 0 -1.55 -.64h-1a2.2 2.2 0 0 1 -2.2 -2.2v-1a2.2 2.2 0 0 0 -.64 -1.55l-.7 -.7a2.2 2.2 0 0 1 0 -3.12l.7 -.7a2.2 2.2 0 0 0 .64 -1.55v-1",key:"svg-1"}]]);var A=e.i(116763),L=e.i(360648),E=e.i(375308),U=e.i(513990),F=e.i(403055),P=e.i(385635),B=e.i(1414),V=e.i(625590),$=e.i(963458),H=e.i(284933);function Y({text:e}){return(0,t.jsx)(U.TooltipProvider,{children:(0,t.jsxs)(U.Tooltip,{children:[(0,t.jsx)(U.TooltipTrigger,{asChild:!0,children:(0,t.jsx)(H.IconInfoCircle,{className:"h-3.5 w-3.5 text-muted-foreground/50 hover:text-muted-foreground cursor-help shrink-0"})}),(0,t.jsx)(U.TooltipContent,{className:"max-w-xs",children:e})]})})}let q=[{value:"bg-slate-500",label:"Gray"},{value:"bg-red-500",label:"Red"},{value:"bg-orange-500",label:"Orange"},{value:"bg-yellow-500",label:"Yellow"},{value:"bg-green-500",label:"Green"},{value:"bg-cyan-500",label:"Cyan"},{value:"bg-blue-500",label:"Blue"},{value:"bg-indigo-500",label:"Indigo"},{value:"bg-purple-500",label:"Purple"}],z=[{label:"Plan",prompt:`Analyze the task and create a detailed implementation plan.

{{task_prompt}}

INSTRUCTIONS:
1. Break the task into clear, ordered steps
2. For each step, describe what needs to be done and which files are affected
3. Identify potential risks or blockers
4. Estimate relative complexity for each step (low/medium/high)

Output the plan as a numbered list. Be specific about file paths, function names, and the approach for each step. Do NOT implement anything yet — only plan.`},{label:"Code Review",prompt:`Please review the changed files in the current git worktree.

STEP 1: Determine what to review
- First, check if there are any uncommitted changes (dirty working directory)
- If there are uncommitted/staged changes: review those files
- If the working directory is clean: review the commits that have diverged from the master/main branch

STEP 2: Review the changes, then output your findings in EXACTLY 4 sections: BUG, IMPROVEMENT, NITPICK, PERFORMANCE.

Rules:
- Each section is OPTIONAL — only include it if you have findings for that category
- If a section has no findings, omit it entirely
- Format each finding as: filename:line_number - Description
- Be specific and reference exact line numbers
- Keep descriptions concise but actionable
- Sort findings by severity within each section
- Focus on logic and design issues, NOT formatting or style that automated tools handle

Section definitions:

BUG: Critical issues that will cause runtime errors, crashes, incorrect behavior, data corruption, or logic errors
- Examples: null/nil dereference, race conditions, incorrect algorithms, type mismatches, resource leaks, deadlocks

IMPROVEMENT: Code quality, architecture, security, or maintainability concerns
- Examples: missing error handling, incorrect access modifiers, SQL injection vulnerabilities, hardcoded credentials, tight coupling, missing validation

NITPICK: Significant readability or maintainability issues that impact code understanding
- Examples: misleading variable/function names, overly complex logic that should be refactored, missing critical comments for complex algorithms
- EXCLUDE: formatting, whitespace, import ordering, trivial naming preferences, style issues handled by linters/formatters

PERFORMANCE: Algorithmic or resource usage problems with measurable impact
- Examples: O(n\xb2) where O(n) or O(1) is possible, unnecessary allocations in loops, missing indexes for database queries, blocking I/O in hot paths
- Concurrency-specific: unprotected shared state, missing synchronization, goroutine leaks, missing context cancellation

Now review the changes.`},{label:"Security Audit",prompt:`Perform a security audit on the changed files in the current git worktree.

{{task_prompt}}

Review all changes and check for the following categories:

1. **Injection Vulnerabilities**: SQL injection, command injection, XSS, template injection, path traversal
2. **Authentication & Authorization**: Missing auth checks, broken access control, privilege escalation, insecure session handling
3. **Data Exposure**: Hardcoded secrets, credentials in logs, sensitive data in error messages, missing encryption
4. **Input Validation**: Missing or insufficient validation at system boundaries, unsafe deserialization, unrestricted file uploads
5. **Dependency Risks**: Known vulnerable dependencies, unsafe use of third-party libraries
6. **Concurrency Issues**: Race conditions on shared state, TOCTOU bugs, unsafe concurrent access to resources

For each finding, output:
- **Severity**: CRITICAL / HIGH / MEDIUM / LOW
- **Location**: filename:line_number
- **Issue**: What the vulnerability is
- **Impact**: What an attacker could do
- **Fix**: Specific remediation steps

Only report real, actionable findings. Do not flag theoretical issues without evidence in the code.`}];function G(e,t){return e.events?.on_enter?.some(e=>e.type===t)??!1}function K({step:e,otherSteps:a,onUpdate:r,setOnTurnStartTransition:s,readOnly:o}){let n,l=(n=e.events?.on_turn_start?.find(e=>["move_to_next","move_to_previous","move_to_step"].includes(e.type)),n?.type??"none");return(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,t.jsx)(j.Label,{className:"text-xs font-medium",children:"On Turn Start"}),(0,t.jsx)(Y,{text:"Runs when a user sends a message. Use for review cycles (e.g., move back to In Progress on feedback)."})]}),(0,t.jsxs)(k.Select,{value:l,onValueChange:e=>{o||s(e)},disabled:o,children:[(0,t.jsx)(k.SelectTrigger,{className:"w-full h-8",children:(0,t.jsx)(k.SelectValue,{placeholder:"Select action"})}),(0,t.jsxs)(k.SelectContent,{position:"popper",side:"bottom",align:"start",children:[(0,t.jsx)(k.SelectItem,{value:"none",children:"Do nothing"}),(0,t.jsx)(k.SelectItem,{value:"move_to_next",children:"Move to next step"}),(0,t.jsx)(k.SelectItem,{value:"move_to_previous",children:"Move to previous step"}),(0,t.jsx)(k.SelectItem,{value:"move_to_step",children:"Move to specific step"})]})]}),"move_to_step"===l&&(0,t.jsxs)(k.Select,{value:e.events?.on_turn_start?.find(e=>"move_to_step"===e.type)?.config?.step_id??"",onValueChange:t=>{if(o)return;let a=e.events??{},s=(a.on_turn_start??[]).map(e=>"move_to_step"===e.type?{...e,config:{step_id:t}}:e);r({events:{...a,on_turn_start:s}})},disabled:o,children:[(0,t.jsx)(k.SelectTrigger,{className:"w-full h-8",children:(0,t.jsx)(k.SelectValue,{placeholder:"Select step"})}),(0,t.jsx)(k.SelectContent,{position:"popper",side:"bottom",align:"start",children:a.map(e=>(0,t.jsx)(k.SelectItem,{value:e.id,children:(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("div",{className:(0,F.cn)("w-2 h-2 rounded-full",e.color)}),e.name]})},e.id))})]})]})}function X({step:e,otherSteps:a,onUpdate:r,setTransition:s,toggleDisablePlanMode:o,planModeEnabled:n,readOnly:l}){let i,d=(i=e.events?.on_turn_complete?.find(e=>["move_to_next","move_to_previous","move_to_step"].includes(e.type)),i?.type??"none");return(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,t.jsx)(j.Label,{className:"text-xs font-medium",children:"On Turn Complete"}),(0,t.jsx)(Y,{text:"Runs after the agent finishes a turn. Use to auto-advance tasks through the pipeline."})]}),(0,t.jsxs)(k.Select,{value:d,onValueChange:e=>{l||s(e)},disabled:l,children:[(0,t.jsx)(k.SelectTrigger,{className:"w-full h-8",children:(0,t.jsx)(k.SelectValue,{placeholder:"Select action"})}),(0,t.jsxs)(k.SelectContent,{position:"popper",side:"bottom",align:"start",children:[(0,t.jsx)(k.SelectItem,{value:"none",children:"Do nothing (wait for user)"}),(0,t.jsx)(k.SelectItem,{value:"move_to_next",children:"Move to next step"}),(0,t.jsx)(k.SelectItem,{value:"move_to_previous",children:"Move to previous step"}),(0,t.jsx)(k.SelectItem,{value:"move_to_step",children:"Move to specific step"})]})]}),"move_to_step"===d&&(0,t.jsxs)(k.Select,{value:e.events?.on_turn_complete?.find(e=>"move_to_step"===e.type)?.config?.step_id??"",onValueChange:t=>{if(l)return;let a=e.events??{},s=(a.on_turn_complete??[]).map(e=>"move_to_step"===e.type?{...e,config:{step_id:t}}:e);r({events:{...a,on_turn_complete:s}})},disabled:l,children:[(0,t.jsx)(k.SelectTrigger,{className:"w-full h-8",children:(0,t.jsx)(k.SelectValue,{placeholder:"Select step"})}),(0,t.jsx)(k.SelectContent,{position:"popper",side:"bottom",align:"start",children:a.map(e=>(0,t.jsx)(k.SelectItem,{value:e.id,children:(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("div",{className:(0,F.cn)("w-2 h-2 rounded-full",e.color)}),e.name]})},e.id))})]}),n&&(0,t.jsxs)("div",{className:"flex items-center gap-2 pt-1",children:[(0,t.jsx)(B.Checkbox,{id:`${e.id}-disable-plan`,checked:e.events?.on_turn_complete?.some(e=>"disable_plan_mode"===e.type)??!1,onCheckedChange:()=>{l||o()},disabled:l}),(0,t.jsx)(j.Label,{htmlFor:`${e.id}-disable-plan`,className:"text-sm",children:"Disable plan mode on complete"}),(0,t.jsx)(Y,{text:"Turn off plan mode after the agent finishes this step."})]})]})}let Q=[{key:"task_prompt",description:"The original task description provided by the user",example:"Implement user authentication with OAuth2",executor_types:[]}];function J({step:e,onUpdate:a,readOnly:r}){let s=S(e.agent_profile_id);return(0,t.jsx)(U.TooltipProvider,{children:(0,t.jsxs)(U.Tooltip,{children:[(0,t.jsx)(U.TooltipTrigger,{asChild:!0,children:(0,t.jsx)("div",{className:"flex items-center",children:(0,t.jsxs)(k.Select,{value:e.agent_profile_id||"none",onValueChange:e=>{r||a({agent_profile_id:"none"===e?"":e})},disabled:r,children:[(0,t.jsxs)(k.SelectTrigger,{className:"w-[220px] h-8 cursor-pointer","data-testid":"step-agent-profile-select",children:[(0,t.jsx)(P.IconRobot,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),(0,t.jsx)(k.SelectValue,{placeholder:"No profile override"})]}),(0,t.jsxs)(k.SelectContent,{children:[(0,t.jsx)(k.SelectItem,{value:"none",className:"cursor-pointer",children:"No profile override"}),s.map(e=>(0,t.jsx)(k.SelectItem,{value:e.id,className:"cursor-pointer",children:e.label},e.id))]})]})})}),(0,t.jsx)(U.TooltipContent,{className:"max-w-xs",children:"Override the agent profile for this step. A different profile creates a new session with fresh context when entering this step."})]})})}function Z({step:e,localName:a,onLocalNameChange:r,onUpdate:s,onRemove:o,readOnly:n,debouncedUpdateName:l}){return(0,t.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,t.jsxs)("div",{className:"flex items-center gap-3 flex-1 min-w-0",children:[(0,t.jsx)(v.Input,{id:`${e.id}-name`,value:a,onChange:e=>{n||(r(e.target.value),l(e.target.value))},placeholder:"Step name",disabled:n,className:"max-w-[240px] h-8"}),(0,t.jsxs)(k.Select,{value:e.color,onValueChange:e=>{n||s({color:e})},disabled:n,children:[(0,t.jsx)(k.SelectTrigger,{className:"w-[120px] h-8",children:(0,t.jsx)(k.SelectValue,{placeholder:"Color"})}),(0,t.jsx)(k.SelectContent,{position:"popper",side:"bottom",align:"start",children:q.map(e=>(0,t.jsx)(k.SelectItem,{value:e.value,children:(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("div",{className:(0,F.cn)("w-3 h-3 rounded-full",e.value)}),e.label]})},e.value))})]}),(0,t.jsx)(J,{step:e,onUpdate:s,readOnly:n})]}),(0,t.jsxs)(h.Button,{type:"button",variant:"ghost",size:"sm",onClick:o,disabled:n,className:"text-destructive hover:text-destructive h-8",children:[(0,t.jsx)(x.IconTrash,{className:"h-3.5 w-3.5 mr-1"}),"Delete"]})]})}function ee({step:e,onUpdate:a,readOnly:r}){return(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(B.Checkbox,{id:`${e.id}-auto-archive`,checked:(e.auto_archive_after_hours??0)>0,onCheckedChange:e=>{r||a({auto_archive_after_hours:24*!!e})},disabled:r}),(0,t.jsx)(j.Label,{htmlFor:`${e.id}-auto-archive`,className:"text-sm",children:"Auto-archive"}),(0,t.jsx)(Y,{text:"Automatically archive tasks after they have been in this step for a set number of hours. Useful for the last step of a workflow (e.g., Done) to keep the board clean."}),(e.auto_archive_after_hours??0)>0&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("span",{className:"text-sm text-muted-foreground",children:"after"}),(0,t.jsx)(v.Input,{id:`${e.id}-auto-archive-hours`,type:"number",min:1,className:"w-20 h-7 text-sm",value:e.auto_archive_after_hours??24,onChange:e=>{if(r)return;let t=parseInt(e.target.value,10);a({auto_archive_after_hours:isNaN(t)||t<1?1:t})},disabled:r}),(0,t.jsx)("span",{className:"text-sm text-muted-foreground",children:"hours"})]})]})}function et({id:e,checked:a,onCheckedChange:r,disabled:s,label:o,helpText:n}){return(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(B.Checkbox,{id:e,checked:a,onCheckedChange:e=>r(!0===e),disabled:s}),(0,t.jsx)(j.Label,{htmlFor:e,className:"text-sm",children:o}),(0,t.jsx)(Y,{text:n})]})}function ea({step:e,onUpdate:a,toggleOnEnterAction:r,readOnly:s}){return(0,t.jsx)("div",{className:"space-y-3",children:(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-x-6 gap-y-2",children:[(0,t.jsx)(et,{id:`${e.id}-start-step`,checked:!0===e.is_start_step,onCheckedChange:e=>!s&&a({is_start_step:e}),disabled:s,label:"Start step",helpText:"New tasks start in this step. Only one step per workflow can be the start step."}),(0,t.jsx)(et,{id:`${e.id}-auto-start`,checked:G(e,"auto_start_agent"),onCheckedChange:()=>!s&&r("auto_start_agent"),disabled:s,label:"Auto-start agent",helpText:"Automatically start the agent when a task enters this step."}),(0,t.jsx)(et,{id:`${e.id}-plan-mode`,checked:G(e,"enable_plan_mode"),onCheckedChange:()=>!s&&r("enable_plan_mode"),disabled:s,label:"Plan mode",helpText:"Agent proposes a plan instead of making changes directly."}),(0,t.jsx)(et,{id:`${e.id}-reset-context`,checked:G(e,"reset_agent_context"),onCheckedChange:()=>!s&&r("reset_agent_context"),disabled:s||!!e.agent_profile_id,label:"Reset agent context",helpText:e.agent_profile_id?"Not needed — switching agent profiles already creates a new session with fresh context.":"Restart the agent with a fresh conversation context when entering this step. Useful for review steps that need an unbiased perspective."}),(0,t.jsx)(et,{id:`${e.id}-manual-move`,checked:!1!==e.allow_manual_move,onCheckedChange:e=>!s&&a({allow_manual_move:e}),disabled:s,label:"Allow manual move",helpText:"Allow dragging tasks into this step on the board."}),(0,t.jsx)(et,{id:`${e.id}-command-panel`,checked:!1!==e.show_in_command_panel,onCheckedChange:e=>!s&&a({show_in_command_panel:e}),disabled:s,label:"Show in command panel",helpText:"Show tasks in this step when opening the command panel (Cmd+K). Useful for hiding backlog or done steps from quick access."}),(0,t.jsx)(ee,{step:e,onUpdate:a,readOnly:s})]})})}function er({step:e,steps:a,onUpdate:r,setTransition:s,setOnTurnStartTransition:o,toggleDisablePlanMode:n,toggleOnExitAction:l,readOnly:i}){let d=a.filter(t=>t.id!==e.id),c=G(e,"enable_plan_mode");return(0,t.jsxs)("div",{className:"space-y-3",children:[(0,t.jsx)("div",{className:"flex items-center gap-1.5",children:(0,t.jsx)(j.Label,{className:"text-xs font-medium text-muted-foreground uppercase tracking-wider",children:"Transitions"})}),(0,t.jsxs)("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[(0,t.jsx)(K,{step:e,otherSteps:d,onUpdate:r,setOnTurnStartTransition:o,readOnly:i}),(0,t.jsx)(X,{step:e,otherSteps:d,onUpdate:r,setTransition:s,toggleDisablePlanMode:n,planModeEnabled:c,readOnly:i})]}),c&&(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,t.jsx)(j.Label,{className:"text-xs font-medium",children:"On Exit"}),(0,t.jsx)(Y,{text:"Runs when leaving this step (before entering the next step)."})]}),(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(B.Checkbox,{id:`${e.id}-exit-disable-plan`,checked:e.events?.on_exit?.some(e=>"disable_plan_mode"===e.type)??!1,onCheckedChange:()=>{i||l("disable_plan_mode")},disabled:i}),(0,t.jsx)(j.Label,{htmlFor:`${e.id}-exit-disable-plan`,className:"text-sm",children:"Disable plan mode"}),(0,t.jsx)(Y,{text:"Turn off plan mode when leaving this step."})]})]})]})}function es({step:e,localPrompt:a,onLocalPromptChange:r,debouncedUpdatePrompt:s,readOnly:o}){return(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,t.jsx)(j.Label,{htmlFor:`${e.id}-prompt`,className:"text-xs font-medium text-muted-foreground uppercase tracking-wider",children:"Step Prompt"}),(0,t.jsx)(Y,{text:"Custom instructions for the agent on this step. Use {{task_prompt}} to include the task description."})]}),!o&&(0,t.jsxs)("div",{className:"flex items-center gap-1.5 flex-wrap",children:[(0,t.jsx)("span",{className:"text-[11px] text-muted-foreground/60",children:"Templates:"}),z.map(e=>(0,t.jsx)("button",{type:"button",onClick:()=>{r(e.prompt),s(e.prompt)},className:"text-[11px] px-2 py-0.5 rounded-md border border-border bg-muted/50 text-muted-foreground hover:bg-muted hover:text-foreground transition-colors cursor-pointer",children:e.label},e.label))]}),(0,t.jsx)("div",{className:"rounded-md border overflow-hidden",children:(0,t.jsx)($.ScriptEditor,{value:a,onChange:e=>{o||(r(e),s(e))},language:"markdown",height:(0,$.computeEditorHeight)(a),lineNumbers:"off",readOnly:o,placeholders:Q})}),(0,t.jsxs)("p",{className:"text-[11px] text-muted-foreground/60",children:["Type ","{{"," to see available placeholders. Use"," ",(0,t.jsx)("code",{className:"bg-muted px-1 py-0.5 rounded text-[10px]",children:"{{task_prompt}}"})," to include the original task description."]})]})}function eo({step:e,steps:r,onUpdate:s,onRemove:o,readOnly:n=!1}){let[l,i]=(0,a.useState)(e.name),[d,c]=(0,a.useState)(e.prompt??""),p=(0,V.useDebouncedCallback)(e=>{s({name:e})},500),u=(0,V.useDebouncedCallback)(e=>{s({prompt:e})},500),m=function({step:e,onUpdate:t}){return{toggleOnEnterAction:a=>{let r=e.events??{},s=r.on_enter??[],o=s.some(e=>e.type===a)?s.filter(e=>e.type!==a):[...s,{type:a}];t({events:{...r,on_enter:o}})},setTransition:a=>{let r=e.events??{},s=(r.on_turn_complete??[]).filter(e=>!["move_to_next","move_to_previous","move_to_step"].includes(e.type));"none"!==a&&s.push({type:a}),t({events:{...r,on_turn_complete:s}})},setOnTurnStartTransition:a=>{let r=e.events??{},s=(r.on_turn_start??[]).filter(e=>!["move_to_next","move_to_previous","move_to_step"].includes(e.type));"none"!==a&&s.push({type:a}),t({events:{...r,on_turn_start:s}})},toggleDisablePlanMode:()=>{let a=e.events??{},r=a.on_turn_complete??[],s=r.some(e=>"disable_plan_mode"===e.type)?r.filter(e=>"disable_plan_mode"!==e.type):[...r,{type:"disable_plan_mode"}];t({events:{...a,on_turn_complete:s}})},toggleOnExitAction:a=>{let r=e.events??{},s=r.on_exit??[],o=s.some(e=>e.type===a)?s.filter(e=>e.type!==a):[...s,{type:a}];t({events:{...r,on_exit:o}})}}}({step:e,onUpdate:s});return(0,t.jsxs)("div",{className:"rounded-lg border bg-card animate-in fade-in-0 slide-in-from-top-2 duration-200",children:[(0,t.jsx)(Z,{step:e,localName:l,onLocalNameChange:i,onUpdate:s,onRemove:o,readOnly:n,debouncedUpdateName:p}),(0,t.jsxs)("div",{className:"p-4 space-y-5",children:[(0,t.jsx)(ea,{step:e,onUpdate:s,toggleOnEnterAction:m.toggleOnEnterAction,readOnly:n}),(0,t.jsx)(er,{step:e,steps:r,onUpdate:s,setTransition:m.setTransition,setOnTurnStartTransition:m.setOnTurnStartTransition,toggleDisablePlanMode:m.toggleDisablePlanMode,toggleOnExitAction:m.toggleOnExitAction,readOnly:n}),(0,t.jsx)(es,{step:e,localPrompt:d,onLocalPromptChange:c,debouncedUpdatePrompt:u,readOnly:n})]})]},e.id)}function en({step:e,isSelected:a,onSelect:r,onRemove:s,readOnly:o=!1}){let{attributes:l,listeners:i,setNodeRef:d,transform:c,transition:p,isDragging:h}=(0,u.useSortable)({id:e.id}),f={transform:m.CSS.Transform.toString(c),transition:p};return(0,t.jsxs)("div",{ref:d,style:f,className:(0,F.cn)("group relative flex items-center gap-1.5 rounded-lg border-2 px-3 py-2 min-w-[120px] max-w-[160px] cursor-pointer transition-colors select-none",a?"border-primary bg-primary/5":"border-border bg-card hover:border-primary/50",h&&"opacity-50 z-50"),onClick:r,children:[e.is_start_step&&(0,t.jsx)(U.TooltipProvider,{children:(0,t.jsxs)(U.Tooltip,{children:[(0,t.jsx)(U.TooltipTrigger,{asChild:!0,children:(0,t.jsx)("div",{className:"absolute -top-2 -left-2 flex items-center justify-center w-5 h-5 rounded-full bg-amber-500 text-white",children:(0,t.jsx)(M,{className:"h-3.5 w-3.5"})})}),(0,t.jsx)(U.TooltipContent,{children:"Start step"})]})}),(0,t.jsx)("button",{type:"button",className:(0,F.cn)("shrink-0 p-0.5 rounded text-muted-foreground/40 hover:text-muted-foreground",o?"cursor-default":"cursor-grab"),...o?{}:l,...o?{}:i,"aria-disabled":o,onClick:e=>e.stopPropagation(),children:(0,t.jsx)(n.IconGripVertical,{className:"h-3.5 w-3.5"})}),(0,t.jsxs)("div",{className:"flex flex-col gap-0.5 min-w-0 flex-1",children:[(0,t.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,t.jsx)("div",{className:(0,F.cn)("w-3 h-3 rounded-full shrink-0",e.color)}),(0,t.jsx)("span",{className:"text-sm font-medium truncate",children:e.name})]}),(0,t.jsx)(A.StepCapabilityIcons,{events:e.events,agentProfileId:e.agent_profile_id,fallback:(0,t.jsx)("span",{className:"text-xs text-muted-foreground/50",children:"manual"})})]}),!o&&(0,t.jsx)("button",{type:"button",className:"absolute -top-2 -right-2 hidden group-hover:flex items-center justify-center w-5 h-5 rounded-full bg-destructive text-destructive-foreground hover:bg-destructive/90 cursor-pointer",onClick:e=>{e.stopPropagation(),s()},children:(0,t.jsx)(x.IconTrash,{className:"h-3 w-3"})})]})}function el({label:e}){return(0,t.jsxs)("div",{className:"flex flex-col items-center justify-center shrink-0 px-1",children:[(0,t.jsxs)("div",{className:"flex items-center gap-0.5 text-muted-foreground/60",children:[(0,t.jsx)("div",{className:"w-4 h-px bg-border"}),(0,t.jsx)(R.IconChevronRight,{className:"h-3 w-3"})]}),(0,t.jsx)("span",{className:"text-[10px] text-muted-foreground/50 leading-none mt-0.5",children:e})]})}function ei({steps:e,selectedStepId:a,onSelectStep:r,onRemoveStep:s,onAddStep:o,readOnly:n}){return(0,t.jsxs)("div",{className:"flex items-center gap-0 py-2 px-1",children:[e.map((o,l)=>{var i;let d,c;return(0,t.jsxs)("div",{className:"flex items-center",children:[l>0&&(0,t.jsx)(el,{label:(i=e[l-1],d=i.events?.on_turn_complete?.find(e=>["move_to_next","move_to_previous","move_to_step"].includes(e.type)),"move_to_next"===(c=d?.type??"none")?"auto":"move_to_previous"===c?"back":"move_to_step"===c?"goto":"manual")}),(0,t.jsx)(en,{step:o,isSelected:a===o.id,onSelect:()=>r(o.id),onRemove:()=>s(o.id),readOnly:n})]},o.id)}),e.length>0&&(0,t.jsx)("div",{className:"flex items-center",children:(0,t.jsx)("div",{className:"w-4 h-px bg-border shrink-0"})}),(0,t.jsx)("button",{type:"button",onClick:n?void 0:o,disabled:n,"data-testid":"add-step-button",className:"shrink-0 h-10 w-10 rounded-lg border border-dashed border-border text-muted-foreground hover:border-primary/50 hover:text-foreground flex items-center justify-center cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:(0,t.jsx)(i.IconPlus,{className:"h-4 w-4"})})]})}function ed({stepName:e,open:a,onOpenChange:r,onConfirm:s}){return(0,t.jsx)(L.AlertDialog,{open:a,onOpenChange:r,children:(0,t.jsxs)(L.AlertDialogContent,{"data-testid":"step-delete-confirm-dialog",children:[(0,t.jsxs)(L.AlertDialogHeader,{children:[(0,t.jsxs)(L.AlertDialogTitle,{children:["Delete step “",e,"”?"]}),(0,t.jsx)(L.AlertDialogDescription,{children:"This will permanently remove the step from this workflow. This action cannot be undone."})]}),(0,t.jsxs)(L.AlertDialogFooter,{children:[(0,t.jsx)(L.AlertDialogCancel,{className:"cursor-pointer",children:"Cancel"}),(0,t.jsx)(L.AlertDialogAction,{variant:"destructive",onClick:s,className:"cursor-pointer",children:"Delete"})]})]})})}function ec({steps:e,onUpdateStep:r,onAddStep:s,onRemoveStep:o,onReorderSteps:n,readOnly:l=!1}){let[i,d]=(0,a.useState)(null),[c,m]=(0,a.useState)(e.length),[h,f]=(0,a.useState)(null);e.length!==c&&(e.length>c&&e.length>0&&d(e[e.length-1].id),m(e.length));let g=(0,a.useMemo)(()=>e.map(e=>e.id),[e]),x=(0,a.useSyncExternalStore)(()=>()=>{},()=>!0,()=>!1),w=(0,p.useSensors)((0,p.useSensor)(p.PointerSensor,{activationConstraint:{distance:8}})),v=e=>f(e),j=h?e.find(e=>e.id===h)?.name??"this step":"",k=e.find(e=>e.id===i),b=(0,t.jsx)(ei,{steps:e,selectedStepId:i,onSelectStep:e=>d(t=>t===e?null:e),onRemoveStep:v,onAddStep:s,readOnly:l});return(0,t.jsxs)("div",{className:"space-y-3",children:[(0,t.jsxs)(E.ScrollArea,{className:"w-full pb-1",children:[x?(0,t.jsx)(p.DndContext,{collisionDetection:p.closestCenter,onDragEnd:t=>{if(l)return;let{active:a,over:r}=t;if(!r||a.id===r.id)return;let s=e.findIndex(e=>e.id===a.id),o=e.findIndex(e=>e.id===r.id);-1!==s&&-1!==o&&n((0,u.arrayMove)(e,s,o).map((e,t)=>({...e,position:t})))},sensors:w,children:(0,t.jsx)(u.SortableContext,{items:g,strategy:u.horizontalListSortingStrategy,children:b})}):b,(0,t.jsx)(E.ScrollBar,{orientation:"horizontal",forceMount:!0,className:"mt-1"})]}),k&&(0,t.jsx)(eo,{step:k,steps:e,onUpdate:e=>r(k.id,e),onRemove:()=>v(k.id),readOnly:l},k.id),(0,t.jsx)(ed,{stepName:j,open:!!h,onOpenChange:e=>{e||f(null)},onConfirm:()=>{h&&(o(h),i===h&&d(null),f(null))}})]})}var ep=e.i(854806);let eu=(0,ep.createServerReference)("40cdced59dce6d54b27d53b1cde65e8847a1cd549f",ep.callServer,void 0,ep.findSourceMapURL,"listWorkflowStepsAction");function em({open:e,onOpenChange:a,workflowTaskCount:r,otherWorkflows:s,targetWorkflowId:o,setTargetWorkflowId:n,targetWorkflowSteps:l,targetStepId:i,setTargetStepId:d,migrateLoading:c,deleteLoading:p,onDelete:u,onMigrateAndDelete:m}){let f=null!==r&&r>0;return(0,t.jsx)(D.Dialog,{open:e,onOpenChange:a,children:(0,t.jsxs)(D.DialogContent,{children:[(0,t.jsxs)(D.DialogHeader,{children:[(0,t.jsx)(D.DialogTitle,{children:"Delete workflow"}),(0,t.jsx)(D.DialogDescription,{children:f?`This workflow has ${r} task${1===r?"":"s"}. Choose where to migrate them, or delete everything.`:"This will permanently delete the workflow and all its steps."})]}),f&&s.length>0&&(0,t.jsxs)("div",{className:"space-y-3 py-2",children:[(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(j.Label,{children:"Target Workflow"}),(0,t.jsxs)(k.Select,{value:o,onValueChange:n,children:[(0,t.jsx)(k.SelectTrigger,{children:(0,t.jsx)(k.SelectValue,{placeholder:"Select workflow"})}),(0,t.jsx)(k.SelectContent,{children:s.map(e=>(0,t.jsx)(k.SelectItem,{value:e.id,children:e.name},e.id))})]})]}),l.length>0&&(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(j.Label,{children:"Target Step"}),(0,t.jsxs)(k.Select,{value:i,onValueChange:d,children:[(0,t.jsx)(k.SelectTrigger,{children:(0,t.jsx)(k.SelectValue,{placeholder:"Select step"})}),(0,t.jsx)(k.SelectContent,{children:l.map(e=>(0,t.jsx)(k.SelectItem,{value:e.id,children:e.name},e.id))})]})]})]}),(0,t.jsxs)(D.DialogFooter,{children:[(0,t.jsx)(h.Button,{type:"button",variant:"outline",onClick:()=>a(!1),className:"cursor-pointer",children:"Cancel"}),f&&s.length>0&&(0,t.jsx)(h.Button,{type:"button",onClick:m,disabled:!o||!i||c||p,className:"cursor-pointer",children:c?"Migrating...":"Migrate & Delete"}),(0,t.jsx)(h.Button,{type:"button",variant:"destructive",onClick:u,disabled:p||c,className:"cursor-pointer",children:f?"Delete Everything":"Delete Workflow"})]})]})})}function eh({open:e,onOpenChange:a,stepTaskCount:r,stepsForMigration:s,targetStep:o,setTargetStep:n,loading:l,onMigrateAndDelete:i,onDeleteAndTasks:d}){return(0,t.jsx)(D.Dialog,{open:e,onOpenChange:a,children:(0,t.jsxs)(D.DialogContent,{children:[(0,t.jsxs)(D.DialogHeader,{children:[(0,t.jsx)(D.DialogTitle,{children:"Delete step"}),(0,t.jsxs)(D.DialogDescription,{children:["This step has ",r," task",1===r?"":"s",".",s.length>0?" Choose where to migrate them, or delete the step and its tasks.":" Deleting this step will affect these tasks."]})]}),s.length>0&&(0,t.jsxs)("div",{className:"space-y-2 py-2",children:[(0,t.jsx)(j.Label,{children:"Target Step"}),(0,t.jsxs)(k.Select,{value:o,onValueChange:n,children:[(0,t.jsx)(k.SelectTrigger,{children:(0,t.jsx)(k.SelectValue,{placeholder:"Select step"})}),(0,t.jsx)(k.SelectContent,{children:s.map(e=>(0,t.jsx)(k.SelectItem,{value:e.id,children:e.name},e.id))})]})]}),(0,t.jsxs)(D.DialogFooter,{children:[(0,t.jsx)(h.Button,{type:"button",variant:"outline",onClick:()=>a(!1),className:"cursor-pointer",children:"Cancel"}),s.length>0&&(0,t.jsx)(h.Button,{type:"button",onClick:i,disabled:!o||l,className:"cursor-pointer",children:l?"Migrating...":"Migrate & Delete Step"}),(0,t.jsx)(h.Button,{type:"button",variant:"destructive",onClick:d,disabled:l,className:"cursor-pointer",children:"Delete Step & Tasks"})]})]})})}let ef=(0,ep.createServerReference)("40b493e595742822b6d45f695d3c4c31354225814d",ep.callServer,void 0,ep.findSourceMapURL,"createWorkflowAction"),eg=(0,ep.createServerReference)("40fc234b633d0c7a653b1f154383a2a9a649678239",ep.callServer,void 0,ep.findSourceMapURL,"createWorkflowStepAction"),ex=(0,ep.createServerReference)("60edc250632880e1356de14618fbd885c27ea41718",ep.callServer,void 0,ep.findSourceMapURL,"updateWorkflowStepAction"),ew=(0,ep.createServerReference)("4033716f665a95ffa297eb943a8f02ea39aaa65353",ep.callServer,void 0,ep.findSourceMapURL,"deleteWorkflowStepAction"),ev=(0,ep.createServerReference)("60731fc96abcba142faa9a4082dda73f4a6b5c5ddc",ep.callServer,void 0,ep.findSourceMapURL,"reorderWorkflowStepsAction"),ej=(0,ep.createServerReference)("404211cf99518033b533a714943292c03806bc468d",ep.callServer,void 0,ep.findSourceMapURL,"getStepTaskCount"),ek=(0,ep.createServerReference)("40abba378e0c5e3ff7869befd554de896895deca0a",ep.callServer,void 0,ep.findSourceMapURL,"getWorkflowTaskCount"),eb=(0,ep.createServerReference)("400ea4b145cad06baad8902dea2d6acf16ae29b1ed",ep.callServer,void 0,ep.findSourceMapURL,"exportWorkflowAction"),eS=(0,ep.createServerReference)("40a366629d08ab57f5c11f7365c2b94f036e9cb854",ep.callServer,void 0,ep.findSourceMapURL,"bulkMoveTasks"),e_="Request failed";async function ey({stepId:e,workflowSteps:t,refreshWorkflowSteps:a,setStepToDelete:r,setStepTaskCount:s,setTargetStepForMigration:o,setStepDeleteOpen:n,toast:l}){try{let{task_count:l}=await ej(e);if(0===l){await ew(e),await a();return}r(e),s(l);let i=t.filter(t=>t.id!==e);o(i.length>0?i[0].id:""),n(!0)}catch(e){l({title:"Failed to check step tasks",description:e instanceof Error?e.message:e_,variant:"error"})}}let eN={name:"New Step",color:"bg-slate-500"};async function eC(e,t,a,r){try{await eg({workflow_id:e.id,...eN,position:t}),await a()}catch(e){r({title:"Failed to add workflow step",description:e instanceof Error?e.message:e_,variant:"error"})}}function eD(e,t){return{workflow_id:e,name:t.name,position:t.position,color:t.color,prompt:t.prompt,events:t.events,is_start_step:t.is_start_step,allow_manual_move:t.allow_manual_move}}async function eT(e,t,a){let{steps:r=[]}=await eu(e);for(let e of r){let a=t.find(t=>t.position===e.position);if(!a)continue;let r=function(e,t){let a={};return e.name!==t.name&&(a.name=e.name),e.color!==t.color&&(a.color=e.color),e.prompt!==t.prompt&&(a.prompt=e.prompt),e.is_start_step!==t.is_start_step&&(a.is_start_step=e.is_start_step),e.allow_manual_move!==t.allow_manual_move&&(a.allow_manual_move=e.allow_manual_move),a}(a,e);Object.keys(r).length>0&&await ex(e.id,r)}for(let r of t)r.position>=a&&await eg(eD(e,r))}async function eI({workflowId:e,setExportYaml:t,setExportOpen:a,toast:r}){try{let r=await eb(e);t(r),a(!0)}catch(e){r({title:"Failed to export workflow",description:e instanceof Error?e.message:e_,variant:"error"})}}function eW({isNewWorkflow:e,workflowId:a,setExportYaml:r,setExportOpen:s,toast:n,onDeleteClick:l,deleteDisabled:i}){return(0,t.jsxs)("div",{className:"flex justify-end gap-2",children:[!e&&(0,t.jsxs)(h.Button,{type:"button",variant:"outline",onClick:()=>eI({workflowId:a,setExportYaml:r,setExportOpen:s,toast:n}),className:"cursor-pointer",children:[(0,t.jsx)(o.IconDownload,{className:"h-4 w-4 mr-2"}),"Export"]}),(0,t.jsxs)(h.Button,{type:"button",variant:"destructive",onClick:l,disabled:i,className:"cursor-pointer","data-testid":"delete-workflow-button",children:[(0,t.jsx)(x.IconTrash,{className:"h-4 w-4 mr-2"}),"Delete Workflow"]})]})}function eO({workflow:e,isWorkflowDirty:a,onUpdateWorkflow:r,activeSaveRequest:s,handleSaveWorkflow:o,workflowLoading:n,workflowSteps:l,stepActions:i}){let d=S(e.agent_profile_id);return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"flex items-end gap-2",children:[(0,t.jsxs)("div",{className:"flex-1 space-y-1.5",children:[(0,t.jsxs)(j.Label,{className:"flex items-center gap-2",children:[(0,t.jsx)("span",{children:"Workflow Name"}),a&&(0,t.jsx)(O.UnsavedChangesBadge,{})]}),(0,t.jsx)(v.Input,{value:e.name,onChange:e=>r({name:e.target.value})})]}),(0,t.jsxs)("div",{className:"w-[240px] shrink-0 space-y-1.5",children:[(0,t.jsxs)(j.Label,{className:"flex items-center gap-1",children:[(0,t.jsx)("span",{children:"Agent Profile"}),(0,t.jsx)(Y,{text:"Default agent profile for tasks in this workflow. When set, the agent selector is locked in the task creation dialog."})]}),(0,t.jsxs)(k.Select,{value:e.agent_profile_id||"none",onValueChange:e=>r({agent_profile_id:"none"===e?"":e}),children:[(0,t.jsx)(k.SelectTrigger,{className:"w-full cursor-pointer","data-testid":"workflow-agent-profile-select",children:(0,t.jsx)(k.SelectValue,{placeholder:"None (use task default)"})}),(0,t.jsxs)(k.SelectContent,{children:[(0,t.jsx)(k.SelectItem,{value:"none",className:"cursor-pointer",children:"None (use task default)"}),d.map(e=>(0,t.jsx)(k.SelectItem,{value:e.id,className:"cursor-pointer",children:e.label},e.id))]})]})]}),(0,t.jsx)(O.UnsavedSaveButton,{isDirty:a,isLoading:s.isLoading,status:s.status,onClick:o})]}),(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(j.Label,{children:"Workflow Steps"}),n?(0,t.jsx)("div",{className:"text-sm text-muted-foreground",children:"Loading workflow steps..."}):(0,t.jsx)(ec,{steps:l,onUpdateStep:i.handleUpdateWorkflowStep,onAddStep:i.handleAddWorkflowStep,onRemoveStep:i.handleRemoveWorkflowStep,onReorderSteps:i.handleReorderWorkflowSteps})]})]})}function eR({wfDel:e,otherWorkflows:a,deleteWorkflowLoading:r,wfDeleteHandlers:s,exportOpen:o,setExportOpen:n,exportYaml:l,stepDel:i,stepsForStepMigration:d,stepDeleteHandlers:c}){return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(em,{open:e.deleteOpen,onOpenChange:e.setDeleteOpen,workflowTaskCount:e.workflowTaskCount,otherWorkflows:a,targetWorkflowId:e.targetWorkflowId,setTargetWorkflowId:e.setTargetWorkflowId,targetWorkflowSteps:e.targetWorkflowSteps,targetStepId:e.targetStepId,setTargetStepId:e.setTargetStepId,migrateLoading:e.migrateLoading,deleteLoading:r,onDelete:s.handleDeleteWorkflow,onMigrateAndDelete:s.handleMigrateAndDeleteWorkflow}),(0,t.jsx)(W,{open:o,onOpenChange:n,title:"Export Workflow",content:l}),(0,t.jsx)(eh,{open:i.stepDeleteOpen,onOpenChange:i.setStepDeleteOpen,stepTaskCount:i.stepTaskCount,stepsForMigration:d,targetStep:i.targetStepForMigration,setTargetStep:i.setTargetStepForMigration,loading:i.stepMigrateLoading,onMigrateAndDelete:c.handleMigrateAndDeleteStep,onDeleteAndTasks:c.handleDeleteStepAndTasks})]})}function eM(e){let{workflow:r,isWorkflowDirty:s,otherWorkflows:o=[],onUpdateWorkflow:n}=e,l=function(e){let{workflow:t,initialWorkflowSteps:r,templateStepCount:s=0,otherWorkflows:o=[]}=e,{onDeleteWorkflow:n,onSaveWorkflow:l,onWorkflowCreated:i}=e,{toast:d}=(0,y.useToast)(),[c,p]=(0,a.useState)(!1),[u,m]=(0,a.useState)(""),h=function(){let[e,t]=(0,a.useState)(!1),[r,s]=(0,a.useState)(null),[o,n]=(0,a.useState)(!1),[l,i]=(0,a.useState)(""),[d,c]=(0,a.useState)([]),[p,u]=(0,a.useState)(""),[m,h]=(0,a.useState)(!1);return{deleteOpen:e,setDeleteOpen:t,workflowTaskCount:r,setWorkflowTaskCount:s,workflowDeleteLoading:o,setWorkflowDeleteLoading:n,targetWorkflowId:l,setTargetWorkflowId:i,targetWorkflowSteps:d,setTargetWorkflowSteps:c,targetStepId:p,setTargetStepId:u,migrateLoading:m,setMigrateLoading:h}}(),f=function(){let[e,t]=(0,a.useState)(!1),[r,s]=(0,a.useState)(null),[o,n]=(0,a.useState)(null),[l,i]=(0,a.useState)(""),[d,c]=(0,a.useState)(!1);return{stepDeleteOpen:e,setStepDeleteOpen:t,stepToDelete:r,setStepToDelete:s,stepTaskCount:o,setStepTaskCount:n,targetStepForMigration:l,setTargetStepForMigration:i,stepMigrateLoading:d,setStepMigrateLoading:c}}(),g=t.id.startsWith("temp-"),x=(0,_.useRequest)(n),{workflowSteps:w,setWorkflowSteps:v,workflowLoading:j,refreshWorkflowSteps:k}=function(e,t,r,s){let[o,n]=(0,a.useState)(t??[]),[l,i]=(0,a.useState)(!1);(0,a.useEffect)(()=>{if(r){n(t??[]),i(!1);return}let a=!1;return(async()=>{i(!0);try{let t=await eu(e);a||n(t.steps??[])}catch{a||s({title:"Failed to load workflow steps",variant:"error"})}finally{a||i(!1)}})(),()=>{a=!0}},[e,t,r,s]);let d=async()=>{try{let t=await eu(e);n(t.steps??[])}catch{}};return{workflowSteps:o,setWorkflowSteps:n,workflowLoading:l,refreshWorkflowSteps:d}}(t.id,r,g,d),b=function({workflow:e,isNewWorkflow:t,workflowSteps:a,setWorkflowSteps:r,refreshWorkflowSteps:s,setStepToDelete:o,setStepTaskCount:n,setTargetStepForMigration:l,setStepDeleteOpen:i,toast:d}){return{handleUpdateWorkflowStep:async(e,a)=>{if(t)return void r(t=>t.map(t=>t.id===e?{...t,...a}:t));try{await ex(e,a),await s()}catch(e){d({title:"Failed to update workflow step",description:e instanceof Error?e.message:e_,variant:"error"})}},handleAddWorkflowStep:async()=>{if(t)return void r(t=>[...t,{id:`temp-step-${(0,F.generateUUID)()}`,workflow_id:e.id,...eN,position:t.length,allow_manual_move:!0,created_at:"",updated_at:""}]);await eC(e,a.length,s,d)},handleRemoveWorkflowStep:async e=>{t?r(t=>t.filter(t=>t.id!==e).map((e,t)=>({...e,position:t}))):await ey({stepId:e,workflowSteps:a,refreshWorkflowSteps:s,setStepToDelete:o,setStepTaskCount:n,setTargetStepForMigration:l,setStepDeleteOpen:i,toast:d})},handleReorderWorkflowSteps:async a=>{if(r(a),!t)try{await ev(e.id,a.map(e=>e.id))}catch(e){d({title:"Failed to reorder workflow steps",description:e instanceof Error?e.message:e_,variant:"error"}),await s()}}}}({workflow:t,isNewWorkflow:g,workflowSteps:w,setWorkflowSteps:v,refreshWorkflowSteps:k,setStepToDelete:f.setStepToDelete,setStepTaskCount:f.setStepTaskCount,setTargetStepForMigration:f.setTargetStepForMigration,setStepDeleteOpen:f.setStepDeleteOpen,toast:d}),{activeSaveRequest:S,handleSaveWorkflow:N}=function({workflow:e,isNewWorkflow:t,workflowSteps:a,templateStepCount:r,onSaveWorkflow:s,onWorkflowCreated:o,toast:n}){let l=(0,_.useRequest)(s),i=(0,_.useRequest)(async()=>{let t=e.workflow_template_id,s=await ef({workspace_id:e.workspace_id,name:e.name.trim()||"New Workflow",workflow_template_id:t||void 0});if(t)await eT(s.id,a,r);else for(let e of a)await eg(eD(s.id,e));o?.(s)}),d=async()=>{try{t?await i.run():await l.run()}catch(e){n({title:"Failed to save workflow changes",description:e instanceof Error?e.message:e_,variant:"error"})}};return{activeSaveRequest:t?i:l,handleSaveWorkflow:d}}({workflow:t,isNewWorkflow:g,workflowSteps:w,templateStepCount:s,onSaveWorkflow:l,onWorkflowCreated:i,toast:d}),C=function({workflow:e,isNewWorkflow:t,otherWorkflows:r,wfDel:s,deleteWorkflowRun:o,toast:n}){return(0,a.useEffect)(()=>{if(!s.targetWorkflowId){s.setTargetWorkflowSteps([]),s.setTargetStepId("");return}let e=!1;return eu(s.targetWorkflowId).then(t=>{if(!e){let e=t.steps??[];s.setTargetWorkflowSteps(e),s.setTargetStepId(e.length>0?e[0].id:"")}}).catch(()=>{e||s.setTargetWorkflowSteps([])}),()=>{e=!0}},[s.targetWorkflowId]),{handleDeleteWorkflowClick:async()=>{if(t){s.setWorkflowTaskCount(0),s.setDeleteOpen(!0);return}s.setWorkflowDeleteLoading(!0);try{let{task_count:t}=await ek(e.id);s.setWorkflowTaskCount(t),t>0&&r.length>0&&s.setTargetWorkflowId(r[0].id),s.setDeleteOpen(!0)}catch(e){n({title:"Failed to check workflow tasks",description:e instanceof Error?e.message:e_,variant:"error"})}finally{s.setWorkflowDeleteLoading(!1)}},handleDeleteWorkflow:async()=>{try{await o(),s.setDeleteOpen(!1)}catch(e){n({title:"Failed to delete workflow",description:e instanceof Error?e.message:e_,variant:"error"})}},handleMigrateAndDeleteWorkflow:async()=>{if(s.targetWorkflowId&&s.targetStepId){s.setMigrateLoading(!0);try{await eS({source_workflow_id:e.id,target_workflow_id:s.targetWorkflowId,target_step_id:s.targetStepId}),await o(),s.setDeleteOpen(!1)}catch(e){n({title:"Failed to migrate tasks",description:e instanceof Error?e.message:e_,variant:"error"})}finally{s.setMigrateLoading(!1)}}}}}({workflow:t,isNewWorkflow:g,otherWorkflows:o,wfDel:h,deleteWorkflowRun:x.run,toast:d}),D=function({workflow:e,stepDel:t,refreshWorkflowSteps:a,toast:r}){return{handleMigrateAndDeleteStep:async()=>{if(t.stepToDelete&&t.targetStepForMigration){t.setStepMigrateLoading(!0);try{await eS({source_workflow_id:e.id,source_step_id:t.stepToDelete,target_workflow_id:e.id,target_step_id:t.targetStepForMigration}),await ew(t.stepToDelete),await a(),t.setStepDeleteOpen(!1),t.setStepToDelete(null)}catch(e){r({title:"Failed to migrate tasks",description:e instanceof Error?e.message:e_,variant:"error"})}finally{t.setStepMigrateLoading(!1)}}},handleDeleteStepAndTasks:async()=>{if(t.stepToDelete){t.setStepMigrateLoading(!0);try{await ew(t.stepToDelete),await a(),t.setStepDeleteOpen(!1),t.setStepToDelete(null)}catch(e){r({title:"Failed to delete step",description:e instanceof Error?e.message:e_,variant:"error"})}finally{t.setStepMigrateLoading(!1)}}}}}({workflow:t,stepDel:f,refreshWorkflowSteps:k,toast:d}),T=f.stepToDelete?w.filter(e=>e.id!==f.stepToDelete):[];return{toast:d,exportOpen:c,setExportOpen:p,exportYaml:u,setExportYaml:m,wfDel:h,stepDel:f,isNewWorkflow:g,deleteWorkflowRequest:x,workflowSteps:w,workflowLoading:j,stepActions:b,activeSaveRequest:S,handleSaveWorkflow:N,wfDeleteHandlers:C,stepDeleteHandlers:D,stepsForStepMigration:T}}(e);return(0,t.jsxs)(w.Card,{"data-testid":`workflow-card-${r.id}`,className:s?"ring-yellow-500/50":void 0,children:[(0,t.jsx)(w.CardContent,{className:"pt-6",children:(0,t.jsxs)("div",{className:"space-y-4",children:[(0,t.jsx)(eO,{workflow:r,isWorkflowDirty:s,onUpdateWorkflow:n,activeSaveRequest:l.activeSaveRequest,handleSaveWorkflow:l.handleSaveWorkflow,workflowLoading:l.workflowLoading,workflowSteps:l.workflowSteps,stepActions:l.stepActions}),(0,t.jsx)(eW,{isNewWorkflow:l.isNewWorkflow,workflowId:r.id,setExportYaml:l.setExportYaml,setExportOpen:l.setExportOpen,toast:l.toast,onDeleteClick:l.wfDeleteHandlers.handleDeleteWorkflowClick,deleteDisabled:l.deleteWorkflowRequest.isLoading||l.wfDel.workflowDeleteLoading})]})}),(0,t.jsx)(eR,{wfDel:l.wfDel,otherWorkflows:o,deleteWorkflowLoading:l.deleteWorkflowRequest.isLoading,wfDeleteHandlers:l.wfDeleteHandlers,exportOpen:l.exportOpen,setExportOpen:l.setExportOpen,exportYaml:l.exportYaml,stepDel:l.stepDel,stepsForStepMigration:l.stepsForStepMigration,stepDeleteHandlers:l.stepDeleteHandlers})]})}let eA=(0,ep.createServerReference)("40c93468e543b2caecba4d89ffe4f6fd8c0cc31817",ep.callServer,void 0,ep.findSourceMapURL,"deleteWorkflowAction"),eL=(0,ep.createServerReference)("60b50104047620c3119d1ad108957522f12f5c7332",ep.callServer,void 0,ep.findSourceMapURL,"updateWorkflowAction"),eE=(0,ep.createServerReference)("4078a1bca8c7f9c203ad72b7b2f4f4b6ba0a74ef5a",ep.callServer,void 0,ep.findSourceMapURL,"exportAllWorkflowsAction"),eU=(0,ep.createServerReference)("603effa208271095a24f51f0a29195fb788956e3cf",ep.callServer,void 0,ep.findSourceMapURL,"importWorkflowsAction"),eF=(0,ep.createServerReference)("60dc539f538e6cad5c0abc01185333ce648a9004c5",ep.callServer,void 0,ep.findSourceMapURL,"reorderWorkflowsAction");var eP=e.i(226571);function eB({open:e,onOpenChange:a,importYaml:r,onImportYamlChange:s,onFileUpload:o,fileInputRef:n,onImport:l,importLoading:i}){return(0,t.jsx)(D.Dialog,{open:e,onOpenChange:a,children:(0,t.jsxs)(D.DialogContent,{children:[(0,t.jsx)(D.DialogHeader,{children:(0,t.jsx)(D.DialogTitle,{children:"Import Workflows"})}),(0,t.jsxs)("div",{className:"space-y-4",children:[(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(j.Label,{children:"Upload YAML file"}),(0,t.jsx)("input",{ref:n,type:"file",accept:".yml,.yaml",onChange:o,className:"block w-full text-sm text-muted-foreground file:mr-4 file:py-2 file:px-4 file:rounded file:border-0 file:text-sm file:font-medium file:bg-primary file:text-primary-foreground file:cursor-pointer cursor-pointer"})]}),(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(j.Label,{children:"Or paste YAML"}),(0,t.jsx)(T.Textarea,{placeholder:"version: 1\ntype: kandev_workflow\nworkflows:\n  - name: My Workflow\n    steps: [...]",value:r,onChange:e=>s(e.target.value),className:"font-mono text-xs max-h-96 overflow-y-auto"})]})]}),(0,t.jsxs)(D.DialogFooter,{children:[(0,t.jsx)(h.Button,{variant:"outline",onClick:()=>a(!1),className:"cursor-pointer",children:"Cancel"}),(0,t.jsx)(h.Button,{onClick:l,disabled:!r.trim()||i,className:"cursor-pointer",children:i?"Importing...":"Import"})]})]})})}function eV({template:e,isSelected:a}){return(0,t.jsxs)("label",{htmlFor:e.id,className:(0,F.cn)("flex items-start gap-3 p-3 rounded-lg border cursor-pointer transition-colors",a?"border-primary bg-primary/5":"border-border hover:border-primary/50"),children:[(0,t.jsx)(eP.RadioGroupItem,{value:e.id,id:e.id,className:"mt-0.5"}),(0,t.jsxs)("div",{className:"flex flex-col gap-1.5 min-w-0",children:[(0,t.jsx)("span",{className:"font-medium",children:e.name}),e.description&&(0,t.jsx)("span",{className:"text-sm text-muted-foreground",children:e.description}),e.default_steps&&e.default_steps.length>0&&(0,t.jsx)("div",{className:"flex items-center gap-1.5 flex-wrap mt-0.5",children:e.default_steps.map((e,a)=>(0,t.jsxs)("div",{className:"flex items-center gap-1",children:[a>0&&(0,t.jsx)("span",{className:"text-muted-foreground/40 text-xs",children:"→"}),(0,t.jsxs)("div",{className:"flex items-center gap-1 text-xs text-muted-foreground",children:[(0,t.jsx)("div",{className:(0,F.cn)("w-2 h-2 rounded-full",e.color??"bg-slate-500")}),e.name]})]},a))})]})]})}function e$({open:e,onOpenChange:a,workflowName:r,onWorkflowNameChange:s,selectedTemplateId:o,onSelectedTemplateChange:n,workflowTemplates:l,onCreate:i}){return(0,t.jsx)(D.Dialog,{open:e,onOpenChange:a,children:(0,t.jsxs)(D.DialogContent,{className:"sm:w-[900px] sm:max-w-none max-h-[90vh] flex flex-col","data-testid":"create-workflow-dialog",children:[(0,t.jsx)(D.DialogHeader,{children:(0,t.jsx)(D.DialogTitle,{children:"Add Workflow"})}),(0,t.jsxs)("div",{className:"space-y-6 overflow-y-auto",children:[(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(j.Label,{htmlFor:"workflowName",children:"Name"}),(0,t.jsx)(v.Input,{id:"workflowName",placeholder:"My Project Workflow",value:r,onChange:e=>s(e.target.value),"data-testid":"workflow-name-input"})]}),l.length>0&&(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(j.Label,{children:"Template"}),(0,t.jsx)(eP.RadioGroup,{value:o??"custom",onValueChange:e=>n("custom"===e?null:e),children:(0,t.jsxs)("div",{className:"grid gap-3",children:[l.map(e=>(0,t.jsx)(eV,{template:e,isSelected:o===e.id},e.id)),(0,t.jsxs)("label",{htmlFor:"custom",className:(0,F.cn)("flex items-start gap-3 p-3 rounded-lg border cursor-pointer transition-colors",null===o?"border-primary bg-primary/5":"border-border hover:border-primary/50"),children:[(0,t.jsx)(eP.RadioGroupItem,{value:"custom",id:"custom",className:"mt-0.5"}),(0,t.jsxs)("div",{className:"flex flex-col gap-1.5",children:[(0,t.jsx)("span",{className:"font-medium",children:"Custom"}),(0,t.jsx)("span",{className:"text-sm text-muted-foreground",children:"Create your own agentic workflow from scratch."})]})]})]})})]})]}),(0,t.jsxs)(D.DialogFooter,{children:[(0,t.jsx)(h.Button,{variant:"outline",onClick:()=>a(!1),className:"cursor-pointer",children:"Cancel"}),(0,t.jsx)(h.Button,{onClick:i,className:"cursor-pointer","data-testid":"confirm-create-workflow",children:"Add Workflow"})]})]})})}var eH=e.i(199396);let eY=[{name:"Todo",position:0,color:"bg-slate-500"},{name:"In Progress",position:1,color:"bg-blue-500"},{name:"Review",position:2,color:"bg-purple-500"},{name:"Done",position:3,color:"bg-green-500"}];function eq({onExport:e,onImport:a,onAdd:r}){return(0,t.jsxs)("div",{className:"flex gap-2",children:[(0,t.jsxs)(h.Button,{size:"sm",variant:"outline",onClick:e,className:"cursor-pointer",children:[(0,t.jsx)(o.IconDownload,{className:"h-4 w-4 mr-2"}),"Export All"]}),(0,t.jsxs)(h.Button,{size:"sm",variant:"outline",onClick:a,className:"cursor-pointer",children:[(0,t.jsx)(c,{className:"h-4 w-4 mr-2"}),"Import"]}),(0,t.jsxs)(h.Button,{size:"sm",onClick:r,className:"cursor-pointer","data-testid":"add-workflow-button",children:[(0,t.jsx)(i.IconPlus,{className:"h-4 w-4 mr-2"}),"Add Workflow"]})]})}function ez({workflow:e,children:a}){let{attributes:r,listeners:s,setNodeRef:o,transform:l,transition:i,isDragging:d}=(0,u.useSortable)({id:e.id}),c={transform:m.CSS.Transform.toString(l),transition:i,opacity:d?.5:1};return(0,t.jsxs)("div",{ref:o,style:c,className:"relative min-w-0",children:[(0,t.jsx)("div",{className:"absolute left-0 top-6 -ml-8 flex items-center cursor-grab active:cursor-grabbing z-10","data-testid":`workflow-drag-handle-${e.id}`,...r,...s,children:(0,t.jsx)(n.IconGripVertical,{className:"h-5 w-5 text-muted-foreground"})}),a]})}function eG({workflowItems:e,workspaceId:a,templateStepsById:r,isWorkflowDirty:s,onUpdate:o,onDelete:n,onSave:l,onCreated:i,onReorder:d}){let c=(0,p.useSensors)((0,p.useSensor)(p.PointerSensor,{activationConstraint:{distance:8}}));return(0,t.jsx)(p.DndContext,{sensors:c,collisionDetection:p.closestCenter,onDragEnd:t=>{let{active:r,over:s}=t;if(!s||r.id===s.id)return;let o=e.findIndex(e=>e.id===r.id),n=e.findIndex(e=>e.id===s.id);if(-1===o||-1===n)return;let l=(0,u.arrayMove)(e,o,n);d(l);let i=l.filter(e=>!e.id.startsWith("temp-")).map(e=>e.id);i.length>0&&eF(a,i).catch(()=>{})},children:(0,t.jsx)(u.SortableContext,{items:e.map(e=>e.id),strategy:u.verticalListSortingStrategy,children:(0,t.jsx)("div",{className:"grid min-w-0 gap-3 pl-8",children:e.map(a=>{let d=a.id.startsWith("temp-"),c=d&&a.workflow_template_id?r.get(a.workflow_template_id)??[]:eY,p=d&&c.length?c.map((e,t)=>({id:`temp-step-${a.id}-${t}`,workflow_id:a.id,name:e.name,position:e.position??t,color:e.color??"bg-slate-500",prompt:e.prompt,events:e.events,is_start_step:e.is_start_step,show_in_command_panel:e.show_in_command_panel,allow_manual_move:!0,created_at:"",updated_at:""})):void 0;return(0,t.jsx)(ez,{workflow:a,children:(0,t.jsx)(eM,{workflow:a,isWorkflowDirty:s(a),initialWorkflowSteps:p,templateStepCount:d?c.length:0,otherWorkflows:e.filter(e=>e.id!==a.id&&!e.id.startsWith("temp-")),onUpdateWorkflow:e=>o(a.id,e),onDeleteWorkflow:async()=>{await n(a.id)},onSaveWorkflow:async()=>{await l(a.id)},onWorkflowCreated:e=>i(a.id,e)})},a.id)})})})})}function eK({page:e}){return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(W,{open:e.isExportDialogOpen,onOpenChange:e.setIsExportDialogOpen,title:"Export Workflows",content:e.exportYaml}),(0,t.jsx)(eB,{open:e.isImportDialogOpen,onOpenChange:e.setIsImportDialogOpen,importYaml:e.importYaml,onImportYamlChange:e.setImportYaml,onFileUpload:e.handleFileUpload,fileInputRef:e.fileInputRef,onImport:e.handleImport,importLoading:e.importLoading}),(0,t.jsx)(e$,{open:e.isAddWorkflowDialogOpen,onOpenChange:e.setIsAddWorkflowDialogOpen,workflowName:e.newWorkflowName,onWorkflowNameChange:e.setNewWorkflowName,selectedTemplateId:e.selectedTemplateId,onSelectedTemplateChange:e.setSelectedTemplateId,workflowTemplates:e.workflowTemplates,onCreate:e.handleCreateWorkflow})]})}function eX({workspace:e,workflows:o,workflowTemplates:n}){let i=function(e,t,r){let o=(0,s.useRouter)(),{toast:n}=(0,y.useToast)(),{workflowItems:l,setWorkflowItems:i,setSavedWorkflowItems:d,isWorkflowDirty:c}=function(e,t){let r=(0,b.useAppStore)(e=>e.workflows.items),s=(0,a.useMemo)(()=>{let e=r.filter(e=>!e.hidden);return t?e.filter(e=>e.workspaceId===t):e},[r,t]),[o,n]=(0,a.useState)(e),[l,i]=(0,a.useState)(e),d=(0,a.useRef)(new Set(e.map(e=>e.id)));(0,a.useEffect)(()=>{let t=d.current,a=e.filter(e=>!t.has(e.id));if(0!==a.length){for(let e of a)t.add(e.id);n(e=>{let t=new Set(e.map(e=>e.id)),r=a.filter(e=>!t.has(e.id));return 0===r.length?e:[...e,...r]}),i(e=>{let t=new Set(e.map(e=>e.id)),r=a.filter(e=>!t.has(e.id));return 0===r.length?e:[...e,...r]})}},[e]);let c=(0,a.useRef)(new Set);(0,a.useEffect)(()=>{let e=new Set(s.map(e=>e.id)),t=new Set([...c.current].filter(t=>!e.has(t)));c.current=e;let a=e=>{let t=new Set(e.map(e=>e.id)),a=new Set(e.filter(e=>e.id.startsWith("temp-")).map(e=>e.workspace_id));return s.filter(e=>!t.has(e.id)&&!a.has(e.workspaceId)).map(e=>{var t;return{id:(t=e).id,workspace_id:t.workspaceId,name:t.name,description:t.description,created_at:"",updated_at:""}})};n(e=>{let r=a(e),o=e.filter(e=>!t.has(e.id)).map(e=>{if(e.id.startsWith("temp-"))return e;let t=s.find(t=>t.id===e.id);return t&&t.name!==e.name?{...e,name:t.name}:e});return 0===r.length&&o.length===e.length&&o.every((t,a)=>t===e[a])?e:[...r,...o]}),i(e=>{let r=a(e),s=e.filter(e=>!t.has(e.id));return 0===r.length&&s.length===e.length?e:[...r,...s]})},[s]);let p=(0,a.useMemo)(()=>new Map(l.map(e=>[e.id,e])),[l]);return{workflowItems:o,setWorkflowItems:n,savedWorkflowItems:l,setSavedWorkflowItems:i,isWorkflowDirty:e=>{let t=p.get(e.id);return!t||e.name!==t.name||e.description!==t.description||(e.agent_profile_id??"")!==(t.agent_profile_id??"")}}}(t,e?.id),{isExportDialogOpen:p,setIsExportDialogOpen:u,exportYaml:m,isImportDialogOpen:h,setIsImportDialogOpen:f,importYaml:g,setImportYaml:x,importLoading:w,fileInputRef:v,handleExportAll:j,handleFileUpload:k,handleImport:S}=function(e,t,r){let[s,o]=(0,a.useState)(!1),[n,l]=(0,a.useState)(""),[i,d]=(0,a.useState)(!1),[c,p]=(0,a.useState)(""),[u,m]=(0,a.useState)(!1),h=(0,a.useRef)(null),f=async()=>{if(e)try{let t=await eE(e.id);l(t),o(!0)}catch(e){r({title:"Failed to export workflows",description:e instanceof Error?e.message:"Request failed",variant:"error"})}},g=async()=>{if(e&&c.trim()){m(!0);try{let a=await eU(e.id,c.trim()),s=a.created??[],o=a.skipped??[],n=[];s.length>0&&n.push(`Created: ${s.join(", ")}`),o.length>0&&n.push(`Skipped (already exist): ${o.join(", ")}`),r({title:"Import complete",description:n.join(". ")}),d(!1),p(""),s.length>0&&t.refresh()}catch(e){r({title:"Failed to import workflows",description:e instanceof Error?e.message:"Invalid YAML",variant:"error"})}finally{m(!1)}}};return{isExportDialogOpen:s,setIsExportDialogOpen:o,exportYaml:n,isImportDialogOpen:i,setIsImportDialogOpen:d,importYaml:c,setImportYaml:p,importLoading:u,fileInputRef:h,handleExportAll:f,handleFileUpload:e=>{let t=e.target.files?.[0];if(!t)return;let a=new FileReader;a.onload=e=>{p(e.target?.result)},a.readAsText(t),e.target.value=""},handleImport:g}}(e,o,n),{isAddWorkflowDialogOpen:_,setIsAddWorkflowDialogOpen:N,newWorkflowName:C,setNewWorkflowName:D,selectedTemplateId:T,setSelectedTemplateId:I,handleOpenAddWorkflowDialog:W,handleCreateWorkflow:O,handleUpdateWorkflow:R,handleDeleteWorkflow:M,handleWorkflowCreated:A,handleSaveWorkflow:L}=function({workspace:e,workflowItems:t,workflowTemplates:r,setWorkflowItems:s,setSavedWorkflowItems:o}){let[n,l]=(0,a.useState)(!1),[i,d]=(0,a.useState)(""),[c,p]=(0,a.useState)(null);return{isAddWorkflowDialogOpen:n,setIsAddWorkflowDialogOpen:l,newWorkflowName:i,setNewWorkflowName:d,selectedTemplateId:c,setSelectedTemplateId:p,handleOpenAddWorkflowDialog:()=>{d(""),p(r.length>0?r[0].id:null),l(!0)},handleCreateWorkflow:()=>{if(!e)return;let t=c?r.find(e=>e.id===c)?.name??"New Workflow":"New Workflow",a={id:`temp-${(0,F.generateUUID)()}`,workspace_id:e.id,name:i.trim()||t,description:"",workflow_template_id:c,created_at:"",updated_at:""};s(e=>[a,...e]),l(!1)},handleUpdateWorkflow:(e,t)=>{s(a=>a.map(a=>a.id===e?{...a,...t}:a))},handleDeleteWorkflow:async e=>{e.startsWith("temp-")?s(t=>t.filter(t=>t.id!==e)):(await eA(e),s(t=>t.filter(t=>t.id!==e)),o(t=>t.filter(t=>t.id!==e)))},handleWorkflowCreated:(e,t)=>{s(a=>a.map(a=>a.id===e?t:a)),o(e=>[{...t},...e])},handleSaveWorkflow:async e=>{let a=t.find(t=>t.id===e);if(!a)return;let r={};a.name.trim()&&(r.name=a.name.trim()),r.agent_profile_id=a.agent_profile_id??"",Object.keys(r).length&&await eL(e,r),s(t=>t.map(t=>t.id===e?{...t,...r}:t)),o(t=>t.some(t=>t.id===e)?t.map(t=>t.id===e?{...a,...r}:t):[...t,{...a,...r}])}}}({workspace:e,workflowItems:l,workflowTemplates:r,setWorkflowItems:i,setSavedWorkflowItems:d}),E=(0,a.useMemo)(()=>new Map(r.map(e=>[e.id,e.default_steps??[]])),[r]);return{router:o,workflowItems:l,isWorkflowDirty:c,isExportDialogOpen:p,setIsExportDialogOpen:u,exportYaml:m,isImportDialogOpen:h,setIsImportDialogOpen:f,importYaml:g,setImportYaml:x,importLoading:w,fileInputRef:v,handleExportAll:j,handleFileUpload:k,handleImport:S,isAddWorkflowDialogOpen:_,setIsAddWorkflowDialogOpen:N,newWorkflowName:C,setNewWorkflowName:D,selectedTemplateId:T,setSelectedTemplateId:I,handleOpenAddWorkflowDialog:W,handleCreateWorkflow:O,handleUpdateWorkflow:R,handleDeleteWorkflow:M,handleWorkflowCreated:A,handleSaveWorkflow:L,handleReorderWorkflows:e=>{i(e),d(t=>{let a=new Map(e.map((e,t)=>[e.id,t]));return[...t].sort((e,t)=>(a.get(e.id)??0)-(a.get(t.id)??0))})},workflowTemplates:r,templateStepsById:E}}(e,o,n);return e?(0,t.jsxs)("div",{className:"space-y-8",children:[(0,t.jsxs)("div",{className:"flex flex-wrap items-start justify-between gap-4",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("h2",{className:"text-2xl font-bold",children:e.name}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground mt-1",children:"Manage workflows for this workspace."})]}),(0,t.jsx)(h.Button,{asChild:!0,variant:"outline",size:"sm",children:(0,t.jsx)(r.default,{href:`/settings/workspace/${e.id}`,children:"Workspace settings"})})]}),(0,t.jsx)(f.Separator,{}),(0,t.jsx)(g.SettingsSection,{icon:(0,t.jsx)(l.IconArrowsShuffle,{className:"h-5 w-5"}),title:"Workflows",description:"Create autonomous pipelines with automated transitions or manual workflows where you move tasks yourself",action:(0,t.jsx)(eq,{onExport:i.handleExportAll,onImport:()=>i.setIsImportDialogOpen(!0),onAdd:i.handleOpenAddWorkflowDialog}),children:(0,t.jsx)(eG,{workflowItems:i.workflowItems,workspaceId:e.id,templateStepsById:i.templateStepsById,isWorkflowDirty:i.isWorkflowDirty,onUpdate:i.handleUpdateWorkflow,onDelete:i.handleDeleteWorkflow,onSave:i.handleSaveWorkflow,onCreated:i.handleWorkflowCreated,onReorder:i.handleReorderWorkflows})}),(0,t.jsx)(eK,{page:i})]}):(0,t.jsx)(eH.WorkspaceNotFoundCard,{onBack:()=>i.router.push("/settings/workspace")})}e.s(["WorkspaceWorkflowsClient",()=>eX],21275)}]);