module.exports=[23847,a=>{"use strict";var b=a.i(254157),c=a.i(839769),d=a.i(661694),e=a.i(995666),f=a.i(444881),g=a.i(986261),h=a.i(607699),i=a.i(224504),j=a.i(143);let k=(0,j.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 l=a.i(915346),m=a.i(577763),n=a.i(705587),o=a.i(18170),p=a.i(778737),q=a.i(550093),r=a.i(175035),s=a.i(347421),t=a.i(372712),u=a.i(82012),v=a.i(419573),w=a.i(303469);function x(a){return(0,w.useAppStore)(a=>a.agentProfiles.items).filter(b=>!b.capability_status||"ok"===b.capability_status||"probing"===b.capability_status||b.id===a)}var y=a.i(37546),z=a.i(592709),A=a.i(467313),B=a.i(863148),C=a.i(417132),D=a.i(75892),E=a.i(978361);function F({open:a,onOpenChange:c,title:d,content:e}){let{copied:f,copy:g}=(0,E.useCopyToClipboard)();return(0,b.jsx)(C.Dialog,{open:a,onOpenChange:c,children:(0,b.jsxs)(C.DialogContent,{className:"sm:max-w-2xl",children:[(0,b.jsx)(C.DialogHeader,{children:(0,b.jsx)(C.DialogTitle,{children:d})}),(0,b.jsx)(D.Textarea,{readOnly:!0,value:e,className:"font-mono text-xs max-h-96 overflow-y-auto"}),(0,b.jsxs)(C.DialogFooter,{children:[(0,b.jsx)(o.Button,{variant:"outline",onClick:()=>c(!1),className:"cursor-pointer",children:"Close"}),(0,b.jsxs)(o.Button,{onClick:()=>g(e),className:"cursor-pointer",children:[f?(0,b.jsx)(A.IconCheck,{className:"h-4 w-4 mr-2"}):(0,b.jsx)(B.IconCopy,{className:"h-4 w-4 mr-2"}),f?"Copied":"Copy"]})]})]})})}var G=a.i(681230),H=a.i(588068);let I=(0,j.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 J=a.i(354821),K=a.i(694340),L=a.i(54210),M=a.i(745250),N=a.i(482140),O=a.i(568001),P=a.i(341903),Q=a.i(515754),R=a.i(8272),S=a.i(740114);function T({text:a}){return(0,b.jsx)(M.TooltipProvider,{children:(0,b.jsxs)(M.Tooltip,{children:[(0,b.jsx)(M.TooltipTrigger,{asChild:!0,children:(0,b.jsx)(S.IconInfoCircle,{className:"h-3.5 w-3.5 text-muted-foreground/50 hover:text-muted-foreground cursor-help shrink-0"})}),(0,b.jsx)(M.TooltipContent,{className:"max-w-xs",children:a})]})})}let U=[{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"}],V=[{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 W(a,b){return a.events?.on_enter?.some(a=>a.type===b)??!1}function X({step:a,otherSteps:c,onUpdate:d,setOnTurnStartTransition:e,readOnly:f}){let g,h=(g=a.events?.on_turn_start?.find(a=>["move_to_next","move_to_previous","move_to_step"].includes(a.type)),g?.type??"none");return(0,b.jsxs)("div",{className:"space-y-2",children:[(0,b.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,b.jsx)(u.Label,{className:"text-xs font-medium",children:"On Turn Start"}),(0,b.jsx)(T,{text:"Runs when a user sends a message. Use for review cycles (e.g., move back to In Progress on feedback)."})]}),(0,b.jsxs)(v.Select,{value:h,onValueChange:a=>{f||e(a)},disabled:f,children:[(0,b.jsx)(v.SelectTrigger,{className:"w-full h-8",children:(0,b.jsx)(v.SelectValue,{placeholder:"Select action"})}),(0,b.jsxs)(v.SelectContent,{position:"popper",side:"bottom",align:"start",children:[(0,b.jsx)(v.SelectItem,{value:"none",children:"Do nothing"}),(0,b.jsx)(v.SelectItem,{value:"move_to_next",children:"Move to next step"}),(0,b.jsx)(v.SelectItem,{value:"move_to_previous",children:"Move to previous step"}),(0,b.jsx)(v.SelectItem,{value:"move_to_step",children:"Move to specific step"})]})]}),"move_to_step"===h&&(0,b.jsxs)(v.Select,{value:a.events?.on_turn_start?.find(a=>"move_to_step"===a.type)?.config?.step_id??"",onValueChange:b=>{if(f)return;let c=a.events??{},e=(c.on_turn_start??[]).map(a=>"move_to_step"===a.type?{...a,config:{step_id:b}}:a);d({events:{...c,on_turn_start:e}})},disabled:f,children:[(0,b.jsx)(v.SelectTrigger,{className:"w-full h-8",children:(0,b.jsx)(v.SelectValue,{placeholder:"Select step"})}),(0,b.jsx)(v.SelectContent,{position:"popper",side:"bottom",align:"start",children:c.map(a=>(0,b.jsx)(v.SelectItem,{value:a.id,children:(0,b.jsxs)("div",{className:"flex items-center gap-2",children:[(0,b.jsx)("div",{className:(0,N.cn)("w-2 h-2 rounded-full",a.color)}),a.name]})},a.id))})]})]})}function Y({step:a,otherSteps:c,onUpdate:d,setTransition:e,toggleDisablePlanMode:f,planModeEnabled:g,readOnly:h}){let i,j=(i=a.events?.on_turn_complete?.find(a=>["move_to_next","move_to_previous","move_to_step"].includes(a.type)),i?.type??"none");return(0,b.jsxs)("div",{className:"space-y-2",children:[(0,b.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,b.jsx)(u.Label,{className:"text-xs font-medium",children:"On Turn Complete"}),(0,b.jsx)(T,{text:"Runs after the agent finishes a turn. Use to auto-advance tasks through the pipeline."})]}),(0,b.jsxs)(v.Select,{value:j,onValueChange:a=>{h||e(a)},disabled:h,children:[(0,b.jsx)(v.SelectTrigger,{className:"w-full h-8",children:(0,b.jsx)(v.SelectValue,{placeholder:"Select action"})}),(0,b.jsxs)(v.SelectContent,{position:"popper",side:"bottom",align:"start",children:[(0,b.jsx)(v.SelectItem,{value:"none",children:"Do nothing (wait for user)"}),(0,b.jsx)(v.SelectItem,{value:"move_to_next",children:"Move to next step"}),(0,b.jsx)(v.SelectItem,{value:"move_to_previous",children:"Move to previous step"}),(0,b.jsx)(v.SelectItem,{value:"move_to_step",children:"Move to specific step"})]})]}),"move_to_step"===j&&(0,b.jsxs)(v.Select,{value:a.events?.on_turn_complete?.find(a=>"move_to_step"===a.type)?.config?.step_id??"",onValueChange:b=>{if(h)return;let c=a.events??{},e=(c.on_turn_complete??[]).map(a=>"move_to_step"===a.type?{...a,config:{step_id:b}}:a);d({events:{...c,on_turn_complete:e}})},disabled:h,children:[(0,b.jsx)(v.SelectTrigger,{className:"w-full h-8",children:(0,b.jsx)(v.SelectValue,{placeholder:"Select step"})}),(0,b.jsx)(v.SelectContent,{position:"popper",side:"bottom",align:"start",children:c.map(a=>(0,b.jsx)(v.SelectItem,{value:a.id,children:(0,b.jsxs)("div",{className:"flex items-center gap-2",children:[(0,b.jsx)("div",{className:(0,N.cn)("w-2 h-2 rounded-full",a.color)}),a.name]})},a.id))})]}),g&&(0,b.jsxs)("div",{className:"flex items-center gap-2 pt-1",children:[(0,b.jsx)(P.Checkbox,{id:`${a.id}-disable-plan`,checked:a.events?.on_turn_complete?.some(a=>"disable_plan_mode"===a.type)??!1,onCheckedChange:()=>{h||f()},disabled:h}),(0,b.jsx)(u.Label,{htmlFor:`${a.id}-disable-plan`,className:"text-sm",children:"Disable plan mode on complete"}),(0,b.jsx)(T,{text:"Turn off plan mode after the agent finishes this step."})]})]})}let Z=[{key:"task_prompt",description:"The original task description provided by the user",example:"Implement user authentication with OAuth2",executor_types:[]}];function $({step:a,onUpdate:c,readOnly:d}){let e=x(a.agent_profile_id);return(0,b.jsx)(M.TooltipProvider,{children:(0,b.jsxs)(M.Tooltip,{children:[(0,b.jsx)(M.TooltipTrigger,{asChild:!0,children:(0,b.jsx)("div",{className:"flex items-center",children:(0,b.jsxs)(v.Select,{value:a.agent_profile_id||"none",onValueChange:a=>{d||c({agent_profile_id:"none"===a?"":a})},disabled:d,children:[(0,b.jsxs)(v.SelectTrigger,{className:"w-[220px] h-8 cursor-pointer","data-testid":"step-agent-profile-select",children:[(0,b.jsx)(O.IconRobot,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),(0,b.jsx)(v.SelectValue,{placeholder:"No profile override"})]}),(0,b.jsxs)(v.SelectContent,{children:[(0,b.jsx)(v.SelectItem,{value:"none",className:"cursor-pointer",children:"No profile override"}),e.map(a=>(0,b.jsx)(v.SelectItem,{value:a.id,className:"cursor-pointer",children:a.label},a.id))]})]})})}),(0,b.jsx)(M.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 _({step:a,localName:c,onLocalNameChange:d,onUpdate:e,onRemove:f,readOnly:g,debouncedUpdateName:h}){return(0,b.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,b.jsxs)("div",{className:"flex items-center gap-3 flex-1 min-w-0",children:[(0,b.jsx)(t.Input,{id:`${a.id}-name`,value:c,onChange:a=>{g||(d(a.target.value),h(a.target.value))},placeholder:"Step name",disabled:g,className:"max-w-[240px] h-8"}),(0,b.jsxs)(v.Select,{value:a.color,onValueChange:a=>{g||e({color:a})},disabled:g,children:[(0,b.jsx)(v.SelectTrigger,{className:"w-[120px] h-8",children:(0,b.jsx)(v.SelectValue,{placeholder:"Color"})}),(0,b.jsx)(v.SelectContent,{position:"popper",side:"bottom",align:"start",children:U.map(a=>(0,b.jsx)(v.SelectItem,{value:a.value,children:(0,b.jsxs)("div",{className:"flex items-center gap-2",children:[(0,b.jsx)("div",{className:(0,N.cn)("w-3 h-3 rounded-full",a.value)}),a.label]})},a.value))})]}),(0,b.jsx)($,{step:a,onUpdate:e,readOnly:g})]}),(0,b.jsxs)(o.Button,{type:"button",variant:"ghost",size:"sm",onClick:f,disabled:g,className:"text-destructive hover:text-destructive h-8",children:[(0,b.jsx)(r.IconTrash,{className:"h-3.5 w-3.5 mr-1"}),"Delete"]})]})}function aa({step:a,onUpdate:c,readOnly:d}){return(0,b.jsxs)("div",{className:"flex items-center gap-2",children:[(0,b.jsx)(P.Checkbox,{id:`${a.id}-auto-archive`,checked:(a.auto_archive_after_hours??0)>0,onCheckedChange:a=>{d||c({auto_archive_after_hours:24*!!a})},disabled:d}),(0,b.jsx)(u.Label,{htmlFor:`${a.id}-auto-archive`,className:"text-sm",children:"Auto-archive"}),(0,b.jsx)(T,{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."}),(a.auto_archive_after_hours??0)>0&&(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)("span",{className:"text-sm text-muted-foreground",children:"after"}),(0,b.jsx)(t.Input,{id:`${a.id}-auto-archive-hours`,type:"number",min:1,className:"w-20 h-7 text-sm",value:a.auto_archive_after_hours??24,onChange:a=>{if(d)return;let b=parseInt(a.target.value,10);c({auto_archive_after_hours:isNaN(b)||b<1?1:b})},disabled:d}),(0,b.jsx)("span",{className:"text-sm text-muted-foreground",children:"hours"})]})]})}function ab({id:a,checked:c,onCheckedChange:d,disabled:e,label:f,helpText:g}){return(0,b.jsxs)("div",{className:"flex items-center gap-2",children:[(0,b.jsx)(P.Checkbox,{id:a,checked:c,onCheckedChange:a=>d(!0===a),disabled:e}),(0,b.jsx)(u.Label,{htmlFor:a,className:"text-sm",children:f}),(0,b.jsx)(T,{text:g})]})}function ac({step:a,onUpdate:c,toggleOnEnterAction:d,readOnly:e}){return(0,b.jsx)("div",{className:"space-y-3",children:(0,b.jsxs)("div",{className:"flex flex-wrap items-center gap-x-6 gap-y-2",children:[(0,b.jsx)(ab,{id:`${a.id}-start-step`,checked:!0===a.is_start_step,onCheckedChange:a=>!e&&c({is_start_step:a}),disabled:e,label:"Start step",helpText:"New tasks start in this step. Only one step per workflow can be the start step."}),(0,b.jsx)(ab,{id:`${a.id}-auto-start`,checked:W(a,"auto_start_agent"),onCheckedChange:()=>!e&&d("auto_start_agent"),disabled:e,label:"Auto-start agent",helpText:"Automatically start the agent when a task enters this step."}),(0,b.jsx)(ab,{id:`${a.id}-plan-mode`,checked:W(a,"enable_plan_mode"),onCheckedChange:()=>!e&&d("enable_plan_mode"),disabled:e,label:"Plan mode",helpText:"Agent proposes a plan instead of making changes directly."}),(0,b.jsx)(ab,{id:`${a.id}-reset-context`,checked:W(a,"reset_agent_context"),onCheckedChange:()=>!e&&d("reset_agent_context"),disabled:e||!!a.agent_profile_id,label:"Reset agent context",helpText:a.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,b.jsx)(ab,{id:`${a.id}-manual-move`,checked:!1!==a.allow_manual_move,onCheckedChange:a=>!e&&c({allow_manual_move:a}),disabled:e,label:"Allow manual move",helpText:"Allow dragging tasks into this step on the board."}),(0,b.jsx)(ab,{id:`${a.id}-command-panel`,checked:!1!==a.show_in_command_panel,onCheckedChange:a=>!e&&c({show_in_command_panel:a}),disabled:e,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,b.jsx)(aa,{step:a,onUpdate:c,readOnly:e})]})})}function ad({step:a,steps:c,onUpdate:d,setTransition:e,setOnTurnStartTransition:f,toggleDisablePlanMode:g,toggleOnExitAction:h,readOnly:i}){let j=c.filter(b=>b.id!==a.id),k=W(a,"enable_plan_mode");return(0,b.jsxs)("div",{className:"space-y-3",children:[(0,b.jsx)("div",{className:"flex items-center gap-1.5",children:(0,b.jsx)(u.Label,{className:"text-xs font-medium text-muted-foreground uppercase tracking-wider",children:"Transitions"})}),(0,b.jsxs)("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[(0,b.jsx)(X,{step:a,otherSteps:j,onUpdate:d,setOnTurnStartTransition:f,readOnly:i}),(0,b.jsx)(Y,{step:a,otherSteps:j,onUpdate:d,setTransition:e,toggleDisablePlanMode:g,planModeEnabled:k,readOnly:i})]}),k&&(0,b.jsxs)("div",{className:"space-y-2",children:[(0,b.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,b.jsx)(u.Label,{className:"text-xs font-medium",children:"On Exit"}),(0,b.jsx)(T,{text:"Runs when leaving this step (before entering the next step)."})]}),(0,b.jsxs)("div",{className:"flex items-center gap-2",children:[(0,b.jsx)(P.Checkbox,{id:`${a.id}-exit-disable-plan`,checked:a.events?.on_exit?.some(a=>"disable_plan_mode"===a.type)??!1,onCheckedChange:()=>{i||h("disable_plan_mode")},disabled:i}),(0,b.jsx)(u.Label,{htmlFor:`${a.id}-exit-disable-plan`,className:"text-sm",children:"Disable plan mode"}),(0,b.jsx)(T,{text:"Turn off plan mode when leaving this step."})]})]})]})}function ae({step:a,localPrompt:c,onLocalPromptChange:d,debouncedUpdatePrompt:e,readOnly:f}){return(0,b.jsxs)("div",{className:"space-y-2",children:[(0,b.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,b.jsx)(u.Label,{htmlFor:`${a.id}-prompt`,className:"text-xs font-medium text-muted-foreground uppercase tracking-wider",children:"Step Prompt"}),(0,b.jsx)(T,{text:"Custom instructions for the agent on this step. Use {{task_prompt}} to include the task description."})]}),!f&&(0,b.jsxs)("div",{className:"flex items-center gap-1.5 flex-wrap",children:[(0,b.jsx)("span",{className:"text-[11px] text-muted-foreground/60",children:"Templates:"}),V.map(a=>(0,b.jsx)("button",{type:"button",onClick:()=>{d(a.prompt),e(a.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:a.label},a.label))]}),(0,b.jsx)("div",{className:"rounded-md border overflow-hidden",children:(0,b.jsx)(R.ScriptEditor,{value:c,onChange:a=>{f||(d(a),e(a))},language:"markdown",height:(0,R.computeEditorHeight)(c),lineNumbers:"off",readOnly:f,placeholders:Z})}),(0,b.jsxs)("p",{className:"text-[11px] text-muted-foreground/60",children:["Type ","{{"," to see available placeholders. Use"," ",(0,b.jsx)("code",{className:"bg-muted px-1 py-0.5 rounded text-[10px]",children:"{{task_prompt}}"})," to include the original task description."]})]})}function af({step:a,steps:d,onUpdate:e,onRemove:f,readOnly:g=!1}){let[h,i]=(0,c.useState)(a.name),[j,k]=(0,c.useState)(a.prompt??""),l=(0,Q.useDebouncedCallback)(a=>{e({name:a})},500),m=(0,Q.useDebouncedCallback)(a=>{e({prompt:a})},500),n=function({step:a,onUpdate:b}){return{toggleOnEnterAction:c=>{let d=a.events??{},e=d.on_enter??[],f=e.some(a=>a.type===c)?e.filter(a=>a.type!==c):[...e,{type:c}];b({events:{...d,on_enter:f}})},setTransition:c=>{let d=a.events??{},e=(d.on_turn_complete??[]).filter(a=>!["move_to_next","move_to_previous","move_to_step"].includes(a.type));"none"!==c&&e.push({type:c}),b({events:{...d,on_turn_complete:e}})},setOnTurnStartTransition:c=>{let d=a.events??{},e=(d.on_turn_start??[]).filter(a=>!["move_to_next","move_to_previous","move_to_step"].includes(a.type));"none"!==c&&e.push({type:c}),b({events:{...d,on_turn_start:e}})},toggleDisablePlanMode:()=>{let c=a.events??{},d=c.on_turn_complete??[],e=d.some(a=>"disable_plan_mode"===a.type)?d.filter(a=>"disable_plan_mode"!==a.type):[...d,{type:"disable_plan_mode"}];b({events:{...c,on_turn_complete:e}})},toggleOnExitAction:c=>{let d=a.events??{},e=d.on_exit??[],f=e.some(a=>a.type===c)?e.filter(a=>a.type!==c):[...e,{type:c}];b({events:{...d,on_exit:f}})}}}({step:a,onUpdate:e});return(0,b.jsxs)("div",{className:"rounded-lg border bg-card animate-in fade-in-0 slide-in-from-top-2 duration-200",children:[(0,b.jsx)(_,{step:a,localName:h,onLocalNameChange:i,onUpdate:e,onRemove:f,readOnly:g,debouncedUpdateName:l}),(0,b.jsxs)("div",{className:"p-4 space-y-5",children:[(0,b.jsx)(ac,{step:a,onUpdate:e,toggleOnEnterAction:n.toggleOnEnterAction,readOnly:g}),(0,b.jsx)(ad,{step:a,steps:d,onUpdate:e,setTransition:n.setTransition,setOnTurnStartTransition:n.setOnTurnStartTransition,toggleDisablePlanMode:n.toggleDisablePlanMode,toggleOnExitAction:n.toggleOnExitAction,readOnly:g}),(0,b.jsx)(ae,{step:a,localPrompt:j,onLocalPromptChange:k,debouncedUpdatePrompt:m,readOnly:g})]})]},a.id)}function ag({step:a,isSelected:c,onSelect:d,onRemove:e,readOnly:f=!1}){let{attributes:h,listeners:i,setNodeRef:j,transform:k,transition:l,isDragging:o}=(0,m.useSortable)({id:a.id}),p={transform:n.CSS.Transform.toString(k),transition:l};return(0,b.jsxs)("div",{ref:j,style:p,className:(0,N.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",c?"border-primary bg-primary/5":"border-border bg-card hover:border-primary/50",o&&"opacity-50 z-50"),onClick:d,children:[a.is_start_step&&(0,b.jsx)(M.TooltipProvider,{children:(0,b.jsxs)(M.Tooltip,{children:[(0,b.jsx)(M.TooltipTrigger,{asChild:!0,children:(0,b.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,b.jsx)(I,{className:"h-3.5 w-3.5"})})}),(0,b.jsx)(M.TooltipContent,{children:"Start step"})]})}),(0,b.jsx)("button",{type:"button",className:(0,N.cn)("shrink-0 p-0.5 rounded text-muted-foreground/40 hover:text-muted-foreground",f?"cursor-default":"cursor-grab"),...f?{}:h,...f?{}:i,"aria-disabled":f,onClick:a=>a.stopPropagation(),children:(0,b.jsx)(g.IconGripVertical,{className:"h-3.5 w-3.5"})}),(0,b.jsxs)("div",{className:"flex flex-col gap-0.5 min-w-0 flex-1",children:[(0,b.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,b.jsx)("div",{className:(0,N.cn)("w-3 h-3 rounded-full shrink-0",a.color)}),(0,b.jsx)("span",{className:"text-sm font-medium truncate",children:a.name})]}),(0,b.jsx)(J.StepCapabilityIcons,{events:a.events,agentProfileId:a.agent_profile_id,fallback:(0,b.jsx)("span",{className:"text-xs text-muted-foreground/50",children:"manual"})})]}),!f&&(0,b.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:a=>{a.stopPropagation(),e()},children:(0,b.jsx)(r.IconTrash,{className:"h-3 w-3"})})]})}function ah({label:a}){return(0,b.jsxs)("div",{className:"flex flex-col items-center justify-center shrink-0 px-1",children:[(0,b.jsxs)("div",{className:"flex items-center gap-0.5 text-muted-foreground/60",children:[(0,b.jsx)("div",{className:"w-4 h-px bg-border"}),(0,b.jsx)(H.IconChevronRight,{className:"h-3 w-3"})]}),(0,b.jsx)("span",{className:"text-[10px] text-muted-foreground/50 leading-none mt-0.5",children:a})]})}function ai({steps:a,selectedStepId:c,onSelectStep:d,onRemoveStep:e,onAddStep:f,readOnly:g}){return(0,b.jsxs)("div",{className:"flex items-center gap-0 py-2 px-1",children:[a.map((f,h)=>{var i;let j,k;return(0,b.jsxs)("div",{className:"flex items-center",children:[h>0&&(0,b.jsx)(ah,{label:(i=a[h-1],j=i.events?.on_turn_complete?.find(a=>["move_to_next","move_to_previous","move_to_step"].includes(a.type)),"move_to_next"===(k=j?.type??"none")?"auto":"move_to_previous"===k?"back":"move_to_step"===k?"goto":"manual")}),(0,b.jsx)(ag,{step:f,isSelected:c===f.id,onSelect:()=>d(f.id),onRemove:()=>e(f.id),readOnly:g})]},f.id)}),a.length>0&&(0,b.jsx)("div",{className:"flex items-center",children:(0,b.jsx)("div",{className:"w-4 h-px bg-border shrink-0"})}),(0,b.jsx)("button",{type:"button",onClick:g?void 0:f,disabled:g,"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,b.jsx)(i.IconPlus,{className:"h-4 w-4"})})]})}function aj({stepName:a,open:c,onOpenChange:d,onConfirm:e}){return(0,b.jsx)(K.AlertDialog,{open:c,onOpenChange:d,children:(0,b.jsxs)(K.AlertDialogContent,{"data-testid":"step-delete-confirm-dialog",children:[(0,b.jsxs)(K.AlertDialogHeader,{children:[(0,b.jsxs)(K.AlertDialogTitle,{children:["Delete step “",a,"”?"]}),(0,b.jsx)(K.AlertDialogDescription,{children:"This will permanently remove the step from this workflow. This action cannot be undone."})]}),(0,b.jsxs)(K.AlertDialogFooter,{children:[(0,b.jsx)(K.AlertDialogCancel,{className:"cursor-pointer",children:"Cancel"}),(0,b.jsx)(K.AlertDialogAction,{variant:"destructive",onClick:e,className:"cursor-pointer",children:"Delete"})]})]})})}function ak({steps:a,onUpdateStep:d,onAddStep:e,onRemoveStep:f,onReorderSteps:g,readOnly:h=!1}){let[i,j]=(0,c.useState)(null),[k,n]=(0,c.useState)(a.length),[o,p]=(0,c.useState)(null);a.length!==k&&(a.length>k&&a.length>0&&j(a[a.length-1].id),n(a.length));let q=(0,c.useMemo)(()=>a.map(a=>a.id),[a]),r=(0,c.useSyncExternalStore)(()=>()=>{},()=>!0,()=>!1),s=(0,l.useSensors)((0,l.useSensor)(l.PointerSensor,{activationConstraint:{distance:8}})),t=a=>p(a),u=o?a.find(a=>a.id===o)?.name??"this step":"",v=a.find(a=>a.id===i),w=(0,b.jsx)(ai,{steps:a,selectedStepId:i,onSelectStep:a=>j(b=>b===a?null:a),onRemoveStep:t,onAddStep:e,readOnly:h});return(0,b.jsxs)("div",{className:"space-y-3",children:[(0,b.jsxs)(L.ScrollArea,{className:"w-full pb-1",children:[r?(0,b.jsx)(l.DndContext,{collisionDetection:l.closestCenter,onDragEnd:b=>{if(h)return;let{active:c,over:d}=b;if(!d||c.id===d.id)return;let e=a.findIndex(a=>a.id===c.id),f=a.findIndex(a=>a.id===d.id);-1!==e&&-1!==f&&g((0,m.arrayMove)(a,e,f).map((a,b)=>({...a,position:b})))},sensors:s,children:(0,b.jsx)(m.SortableContext,{items:q,strategy:m.horizontalListSortingStrategy,children:w})}):w,(0,b.jsx)(L.ScrollBar,{orientation:"horizontal",forceMount:!0,className:"mt-1"})]}),v&&(0,b.jsx)(af,{step:v,steps:a,onUpdate:a=>d(v.id,a),onRemove:()=>t(v.id),readOnly:h},v.id),(0,b.jsx)(aj,{stepName:u,open:!!o,onOpenChange:a=>{a||p(null)},onConfirm:()=>{o&&(f(o),i===o&&j(null),p(null))}})]})}var al=a.i(528198);let am=(0,al.createServerReference)("40cdced59dce6d54b27d53b1cde65e8847a1cd549f",al.callServer,void 0,al.findSourceMapURL,"listWorkflowStepsAction");function an({open:a,onOpenChange:c,workflowTaskCount:d,otherWorkflows:e,targetWorkflowId:f,setTargetWorkflowId:g,targetWorkflowSteps:h,targetStepId:i,setTargetStepId:j,migrateLoading:k,deleteLoading:l,onDelete:m,onMigrateAndDelete:n}){let p=null!==d&&d>0;return(0,b.jsx)(C.Dialog,{open:a,onOpenChange:c,children:(0,b.jsxs)(C.DialogContent,{children:[(0,b.jsxs)(C.DialogHeader,{children:[(0,b.jsx)(C.DialogTitle,{children:"Delete workflow"}),(0,b.jsx)(C.DialogDescription,{children:p?`This workflow has ${d} task${1===d?"":"s"}. Choose where to migrate them, or delete everything.`:"This will permanently delete the workflow and all its steps."})]}),p&&e.length>0&&(0,b.jsxs)("div",{className:"space-y-3 py-2",children:[(0,b.jsxs)("div",{className:"space-y-2",children:[(0,b.jsx)(u.Label,{children:"Target Workflow"}),(0,b.jsxs)(v.Select,{value:f,onValueChange:g,children:[(0,b.jsx)(v.SelectTrigger,{children:(0,b.jsx)(v.SelectValue,{placeholder:"Select workflow"})}),(0,b.jsx)(v.SelectContent,{children:e.map(a=>(0,b.jsx)(v.SelectItem,{value:a.id,children:a.name},a.id))})]})]}),h.length>0&&(0,b.jsxs)("div",{className:"space-y-2",children:[(0,b.jsx)(u.Label,{children:"Target Step"}),(0,b.jsxs)(v.Select,{value:i,onValueChange:j,children:[(0,b.jsx)(v.SelectTrigger,{children:(0,b.jsx)(v.SelectValue,{placeholder:"Select step"})}),(0,b.jsx)(v.SelectContent,{children:h.map(a=>(0,b.jsx)(v.SelectItem,{value:a.id,children:a.name},a.id))})]})]})]}),(0,b.jsxs)(C.DialogFooter,{children:[(0,b.jsx)(o.Button,{type:"button",variant:"outline",onClick:()=>c(!1),className:"cursor-pointer",children:"Cancel"}),p&&e.length>0&&(0,b.jsx)(o.Button,{type:"button",onClick:n,disabled:!f||!i||k||l,className:"cursor-pointer",children:k?"Migrating...":"Migrate & Delete"}),(0,b.jsx)(o.Button,{type:"button",variant:"destructive",onClick:m,disabled:l||k,className:"cursor-pointer",children:p?"Delete Everything":"Delete Workflow"})]})]})})}function ao({open:a,onOpenChange:c,stepTaskCount:d,stepsForMigration:e,targetStep:f,setTargetStep:g,loading:h,onMigrateAndDelete:i,onDeleteAndTasks:j}){return(0,b.jsx)(C.Dialog,{open:a,onOpenChange:c,children:(0,b.jsxs)(C.DialogContent,{children:[(0,b.jsxs)(C.DialogHeader,{children:[(0,b.jsx)(C.DialogTitle,{children:"Delete step"}),(0,b.jsxs)(C.DialogDescription,{children:["This step has ",d," task",1===d?"":"s",".",e.length>0?" Choose where to migrate them, or delete the step and its tasks.":" Deleting this step will affect these tasks."]})]}),e.length>0&&(0,b.jsxs)("div",{className:"space-y-2 py-2",children:[(0,b.jsx)(u.Label,{children:"Target Step"}),(0,b.jsxs)(v.Select,{value:f,onValueChange:g,children:[(0,b.jsx)(v.SelectTrigger,{children:(0,b.jsx)(v.SelectValue,{placeholder:"Select step"})}),(0,b.jsx)(v.SelectContent,{children:e.map(a=>(0,b.jsx)(v.SelectItem,{value:a.id,children:a.name},a.id))})]})]}),(0,b.jsxs)(C.DialogFooter,{children:[(0,b.jsx)(o.Button,{type:"button",variant:"outline",onClick:()=>c(!1),className:"cursor-pointer",children:"Cancel"}),e.length>0&&(0,b.jsx)(o.Button,{type:"button",onClick:i,disabled:!f||h,className:"cursor-pointer",children:h?"Migrating...":"Migrate & Delete Step"}),(0,b.jsx)(o.Button,{type:"button",variant:"destructive",onClick:j,disabled:h,className:"cursor-pointer",children:"Delete Step & Tasks"})]})]})})}let ap=(0,al.createServerReference)("40b493e595742822b6d45f695d3c4c31354225814d",al.callServer,void 0,al.findSourceMapURL,"createWorkflowAction"),aq=(0,al.createServerReference)("40fc234b633d0c7a653b1f154383a2a9a649678239",al.callServer,void 0,al.findSourceMapURL,"createWorkflowStepAction"),ar=(0,al.createServerReference)("60edc250632880e1356de14618fbd885c27ea41718",al.callServer,void 0,al.findSourceMapURL,"updateWorkflowStepAction"),as=(0,al.createServerReference)("4033716f665a95ffa297eb943a8f02ea39aaa65353",al.callServer,void 0,al.findSourceMapURL,"deleteWorkflowStepAction"),at=(0,al.createServerReference)("60731fc96abcba142faa9a4082dda73f4a6b5c5ddc",al.callServer,void 0,al.findSourceMapURL,"reorderWorkflowStepsAction"),au=(0,al.createServerReference)("404211cf99518033b533a714943292c03806bc468d",al.callServer,void 0,al.findSourceMapURL,"getStepTaskCount"),av=(0,al.createServerReference)("40abba378e0c5e3ff7869befd554de896895deca0a",al.callServer,void 0,al.findSourceMapURL,"getWorkflowTaskCount"),aw=(0,al.createServerReference)("400ea4b145cad06baad8902dea2d6acf16ae29b1ed",al.callServer,void 0,al.findSourceMapURL,"exportWorkflowAction"),ax=(0,al.createServerReference)("40a366629d08ab57f5c11f7365c2b94f036e9cb854",al.callServer,void 0,al.findSourceMapURL,"bulkMoveTasks"),ay="Request failed";async function az({stepId:a,workflowSteps:b,refreshWorkflowSteps:c,setStepToDelete:d,setStepTaskCount:e,setTargetStepForMigration:f,setStepDeleteOpen:g,toast:h}){try{let{task_count:h}=await au(a);if(0===h){await as(a),await c();return}d(a),e(h);let i=b.filter(b=>b.id!==a);f(i.length>0?i[0].id:""),g(!0)}catch(a){h({title:"Failed to check step tasks",description:a instanceof Error?a.message:ay,variant:"error"})}}let aA={name:"New Step",color:"bg-slate-500"};async function aB(a,b,c,d){try{await aq({workflow_id:a.id,...aA,position:b}),await c()}catch(a){d({title:"Failed to add workflow step",description:a instanceof Error?a.message:ay,variant:"error"})}}function aC(a,b){return{workflow_id:a,name:b.name,position:b.position,color:b.color,prompt:b.prompt,events:b.events,is_start_step:b.is_start_step,allow_manual_move:b.allow_manual_move}}async function aD(a,b,c){let{steps:d=[]}=await am(a);for(let a of d){let c=b.find(b=>b.position===a.position);if(!c)continue;let d=function(a,b){let c={};return a.name!==b.name&&(c.name=a.name),a.color!==b.color&&(c.color=a.color),a.prompt!==b.prompt&&(c.prompt=a.prompt),a.is_start_step!==b.is_start_step&&(c.is_start_step=a.is_start_step),a.allow_manual_move!==b.allow_manual_move&&(c.allow_manual_move=a.allow_manual_move),c}(c,a);Object.keys(d).length>0&&await ar(a.id,d)}for(let d of b)d.position>=c&&await aq(aC(a,d))}async function aE({workflowId:a,setExportYaml:b,setExportOpen:c,toast:d}){try{let d=await aw(a);b(d),c(!0)}catch(a){d({title:"Failed to export workflow",description:a instanceof Error?a.message:ay,variant:"error"})}}function aF({isNewWorkflow:a,workflowId:c,setExportYaml:d,setExportOpen:e,toast:g,onDeleteClick:h,deleteDisabled:i}){return(0,b.jsxs)("div",{className:"flex justify-end gap-2",children:[!a&&(0,b.jsxs)(o.Button,{type:"button",variant:"outline",onClick:()=>aE({workflowId:c,setExportYaml:d,setExportOpen:e,toast:g}),className:"cursor-pointer",children:[(0,b.jsx)(f.IconDownload,{className:"h-4 w-4 mr-2"}),"Export"]}),(0,b.jsxs)(o.Button,{type:"button",variant:"destructive",onClick:h,disabled:i,className:"cursor-pointer","data-testid":"delete-workflow-button",children:[(0,b.jsx)(r.IconTrash,{className:"h-4 w-4 mr-2"}),"Delete Workflow"]})]})}function aG({workflow:a,isWorkflowDirty:c,onUpdateWorkflow:d,activeSaveRequest:e,handleSaveWorkflow:f,workflowLoading:g,workflowSteps:h,stepActions:i}){let j=x(a.agent_profile_id);return(0,b.jsxs)(b.Fragment,{children:[(0,b.jsxs)("div",{className:"flex items-end gap-2",children:[(0,b.jsxs)("div",{className:"flex-1 space-y-1.5",children:[(0,b.jsxs)(u.Label,{className:"flex items-center gap-2",children:[(0,b.jsx)("span",{children:"Workflow Name"}),c&&(0,b.jsx)(G.UnsavedChangesBadge,{})]}),(0,b.jsx)(t.Input,{value:a.name,onChange:a=>d({name:a.target.value})})]}),(0,b.jsxs)("div",{className:"w-[240px] shrink-0 space-y-1.5",children:[(0,b.jsxs)(u.Label,{className:"flex items-center gap-1",children:[(0,b.jsx)("span",{children:"Agent Profile"}),(0,b.jsx)(T,{text:"Default agent profile for tasks in this workflow. When set, the agent selector is locked in the task creation dialog."})]}),(0,b.jsxs)(v.Select,{value:a.agent_profile_id||"none",onValueChange:a=>d({agent_profile_id:"none"===a?"":a}),children:[(0,b.jsx)(v.SelectTrigger,{className:"w-full cursor-pointer","data-testid":"workflow-agent-profile-select",children:(0,b.jsx)(v.SelectValue,{placeholder:"None (use task default)"})}),(0,b.jsxs)(v.SelectContent,{children:[(0,b.jsx)(v.SelectItem,{value:"none",className:"cursor-pointer",children:"None (use task default)"}),j.map(a=>(0,b.jsx)(v.SelectItem,{value:a.id,className:"cursor-pointer",children:a.label},a.id))]})]})]}),(0,b.jsx)(G.UnsavedSaveButton,{isDirty:c,isLoading:e.isLoading,status:e.status,onClick:f})]}),(0,b.jsxs)("div",{className:"space-y-2",children:[(0,b.jsx)(u.Label,{children:"Workflow Steps"}),g?(0,b.jsx)("div",{className:"text-sm text-muted-foreground",children:"Loading workflow steps..."}):(0,b.jsx)(ak,{steps:h,onUpdateStep:i.handleUpdateWorkflowStep,onAddStep:i.handleAddWorkflowStep,onRemoveStep:i.handleRemoveWorkflowStep,onReorderSteps:i.handleReorderWorkflowSteps})]})]})}function aH({wfDel:a,otherWorkflows:c,deleteWorkflowLoading:d,wfDeleteHandlers:e,exportOpen:f,setExportOpen:g,exportYaml:h,stepDel:i,stepsForStepMigration:j,stepDeleteHandlers:k}){return(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(an,{open:a.deleteOpen,onOpenChange:a.setDeleteOpen,workflowTaskCount:a.workflowTaskCount,otherWorkflows:c,targetWorkflowId:a.targetWorkflowId,setTargetWorkflowId:a.setTargetWorkflowId,targetWorkflowSteps:a.targetWorkflowSteps,targetStepId:a.targetStepId,setTargetStepId:a.setTargetStepId,migrateLoading:a.migrateLoading,deleteLoading:d,onDelete:e.handleDeleteWorkflow,onMigrateAndDelete:e.handleMigrateAndDeleteWorkflow}),(0,b.jsx)(F,{open:f,onOpenChange:g,title:"Export Workflow",content:h}),(0,b.jsx)(ao,{open:i.stepDeleteOpen,onOpenChange:i.setStepDeleteOpen,stepTaskCount:i.stepTaskCount,stepsForMigration:j,targetStep:i.targetStepForMigration,setTargetStep:i.setTargetStepForMigration,loading:i.stepMigrateLoading,onMigrateAndDelete:k.handleMigrateAndDeleteStep,onDeleteAndTasks:k.handleDeleteStepAndTasks})]})}function aI(a){let{workflow:d,isWorkflowDirty:e,otherWorkflows:f=[],onUpdateWorkflow:g}=a,h=function(a){let{workflow:b,initialWorkflowSteps:d,templateStepCount:e=0,otherWorkflows:f=[]}=a,{onDeleteWorkflow:g,onSaveWorkflow:h,onWorkflowCreated:i}=a,{toast:j}=(0,z.useToast)(),[k,l]=(0,c.useState)(!1),[m,n]=(0,c.useState)(""),o=function(){let[a,b]=(0,c.useState)(!1),[d,e]=(0,c.useState)(null),[f,g]=(0,c.useState)(!1),[h,i]=(0,c.useState)(""),[j,k]=(0,c.useState)([]),[l,m]=(0,c.useState)(""),[n,o]=(0,c.useState)(!1);return{deleteOpen:a,setDeleteOpen:b,workflowTaskCount:d,setWorkflowTaskCount:e,workflowDeleteLoading:f,setWorkflowDeleteLoading:g,targetWorkflowId:h,setTargetWorkflowId:i,targetWorkflowSteps:j,setTargetWorkflowSteps:k,targetStepId:l,setTargetStepId:m,migrateLoading:n,setMigrateLoading:o}}(),p=function(){let[a,b]=(0,c.useState)(!1),[d,e]=(0,c.useState)(null),[f,g]=(0,c.useState)(null),[h,i]=(0,c.useState)(""),[j,k]=(0,c.useState)(!1);return{stepDeleteOpen:a,setStepDeleteOpen:b,stepToDelete:d,setStepToDelete:e,stepTaskCount:f,setStepTaskCount:g,targetStepForMigration:h,setTargetStepForMigration:i,stepMigrateLoading:j,setStepMigrateLoading:k}}(),q=b.id.startsWith("temp-"),r=(0,y.useRequest)(g),{workflowSteps:s,setWorkflowSteps:t,workflowLoading:u,refreshWorkflowSteps:v}=function(a,b,d,e){let[f,g]=(0,c.useState)(b??[]),[h,i]=(0,c.useState)(!1);(0,c.useEffect)(()=>{if(d){g(b??[]),i(!1);return}let c=!1;return(async()=>{i(!0);try{let b=await am(a);c||g(b.steps??[])}catch{c||e({title:"Failed to load workflow steps",variant:"error"})}finally{c||i(!1)}})(),()=>{c=!0}},[a,b,d,e]);let j=async()=>{try{let b=await am(a);g(b.steps??[])}catch{}};return{workflowSteps:f,setWorkflowSteps:g,workflowLoading:h,refreshWorkflowSteps:j}}(b.id,d,q,j),w=function({workflow:a,isNewWorkflow:b,workflowSteps:c,setWorkflowSteps:d,refreshWorkflowSteps:e,setStepToDelete:f,setStepTaskCount:g,setTargetStepForMigration:h,setStepDeleteOpen:i,toast:j}){return{handleUpdateWorkflowStep:async(a,c)=>{if(b)return void d(b=>b.map(b=>b.id===a?{...b,...c}:b));try{await ar(a,c),await e()}catch(a){j({title:"Failed to update workflow step",description:a instanceof Error?a.message:ay,variant:"error"})}},handleAddWorkflowStep:async()=>{if(b)return void d(b=>[...b,{id:`temp-step-${(0,N.generateUUID)()}`,workflow_id:a.id,...aA,position:b.length,allow_manual_move:!0,created_at:"",updated_at:""}]);await aB(a,c.length,e,j)},handleRemoveWorkflowStep:async a=>{b?d(b=>b.filter(b=>b.id!==a).map((a,b)=>({...a,position:b}))):await az({stepId:a,workflowSteps:c,refreshWorkflowSteps:e,setStepToDelete:f,setStepTaskCount:g,setTargetStepForMigration:h,setStepDeleteOpen:i,toast:j})},handleReorderWorkflowSteps:async c=>{if(d(c),!b)try{await at(a.id,c.map(a=>a.id))}catch(a){j({title:"Failed to reorder workflow steps",description:a instanceof Error?a.message:ay,variant:"error"}),await e()}}}}({workflow:b,isNewWorkflow:q,workflowSteps:s,setWorkflowSteps:t,refreshWorkflowSteps:v,setStepToDelete:p.setStepToDelete,setStepTaskCount:p.setStepTaskCount,setTargetStepForMigration:p.setTargetStepForMigration,setStepDeleteOpen:p.setStepDeleteOpen,toast:j}),{activeSaveRequest:x,handleSaveWorkflow:A}=function({workflow:a,isNewWorkflow:b,workflowSteps:c,templateStepCount:d,onSaveWorkflow:e,onWorkflowCreated:f,toast:g}){let h=(0,y.useRequest)(e),i=(0,y.useRequest)(async()=>{let b=a.workflow_template_id,e=await ap({workspace_id:a.workspace_id,name:a.name.trim()||"New Workflow",workflow_template_id:b||void 0});if(b)await aD(e.id,c,d);else for(let a of c)await aq(aC(e.id,a));f?.(e)}),j=async()=>{try{b?await i.run():await h.run()}catch(a){g({title:"Failed to save workflow changes",description:a instanceof Error?a.message:ay,variant:"error"})}};return{activeSaveRequest:b?i:h,handleSaveWorkflow:j}}({workflow:b,isNewWorkflow:q,workflowSteps:s,templateStepCount:e,onSaveWorkflow:h,onWorkflowCreated:i,toast:j}),B=function({workflow:a,isNewWorkflow:b,otherWorkflows:d,wfDel:e,deleteWorkflowRun:f,toast:g}){return(0,c.useEffect)(()=>{if(!e.targetWorkflowId){e.setTargetWorkflowSteps([]),e.setTargetStepId("");return}let a=!1;return am(e.targetWorkflowId).then(b=>{if(!a){let a=b.steps??[];e.setTargetWorkflowSteps(a),e.setTargetStepId(a.length>0?a[0].id:"")}}).catch(()=>{a||e.setTargetWorkflowSteps([])}),()=>{a=!0}},[e.targetWorkflowId]),{handleDeleteWorkflowClick:async()=>{if(b){e.setWorkflowTaskCount(0),e.setDeleteOpen(!0);return}e.setWorkflowDeleteLoading(!0);try{let{task_count:b}=await av(a.id);e.setWorkflowTaskCount(b),b>0&&d.length>0&&e.setTargetWorkflowId(d[0].id),e.setDeleteOpen(!0)}catch(a){g({title:"Failed to check workflow tasks",description:a instanceof Error?a.message:ay,variant:"error"})}finally{e.setWorkflowDeleteLoading(!1)}},handleDeleteWorkflow:async()=>{try{await f(),e.setDeleteOpen(!1)}catch(a){g({title:"Failed to delete workflow",description:a instanceof Error?a.message:ay,variant:"error"})}},handleMigrateAndDeleteWorkflow:async()=>{if(e.targetWorkflowId&&e.targetStepId){e.setMigrateLoading(!0);try{await ax({source_workflow_id:a.id,target_workflow_id:e.targetWorkflowId,target_step_id:e.targetStepId}),await f(),e.setDeleteOpen(!1)}catch(a){g({title:"Failed to migrate tasks",description:a instanceof Error?a.message:ay,variant:"error"})}finally{e.setMigrateLoading(!1)}}}}}({workflow:b,isNewWorkflow:q,otherWorkflows:f,wfDel:o,deleteWorkflowRun:r.run,toast:j}),C=function({workflow:a,stepDel:b,refreshWorkflowSteps:c,toast:d}){return{handleMigrateAndDeleteStep:async()=>{if(b.stepToDelete&&b.targetStepForMigration){b.setStepMigrateLoading(!0);try{await ax({source_workflow_id:a.id,source_step_id:b.stepToDelete,target_workflow_id:a.id,target_step_id:b.targetStepForMigration}),await as(b.stepToDelete),await c(),b.setStepDeleteOpen(!1),b.setStepToDelete(null)}catch(a){d({title:"Failed to migrate tasks",description:a instanceof Error?a.message:ay,variant:"error"})}finally{b.setStepMigrateLoading(!1)}}},handleDeleteStepAndTasks:async()=>{if(b.stepToDelete){b.setStepMigrateLoading(!0);try{await as(b.stepToDelete),await c(),b.setStepDeleteOpen(!1),b.setStepToDelete(null)}catch(a){d({title:"Failed to delete step",description:a instanceof Error?a.message:ay,variant:"error"})}finally{b.setStepMigrateLoading(!1)}}}}}({workflow:b,stepDel:p,refreshWorkflowSteps:v,toast:j}),D=p.stepToDelete?s.filter(a=>a.id!==p.stepToDelete):[];return{toast:j,exportOpen:k,setExportOpen:l,exportYaml:m,setExportYaml:n,wfDel:o,stepDel:p,isNewWorkflow:q,deleteWorkflowRequest:r,workflowSteps:s,workflowLoading:u,stepActions:w,activeSaveRequest:x,handleSaveWorkflow:A,wfDeleteHandlers:B,stepDeleteHandlers:C,stepsForStepMigration:D}}(a);return(0,b.jsxs)(s.Card,{"data-testid":`workflow-card-${d.id}`,className:e?"ring-yellow-500/50":void 0,children:[(0,b.jsx)(s.CardContent,{className:"pt-6",children:(0,b.jsxs)("div",{className:"space-y-4",children:[(0,b.jsx)(aG,{workflow:d,isWorkflowDirty:e,onUpdateWorkflow:g,activeSaveRequest:h.activeSaveRequest,handleSaveWorkflow:h.handleSaveWorkflow,workflowLoading:h.workflowLoading,workflowSteps:h.workflowSteps,stepActions:h.stepActions}),(0,b.jsx)(aF,{isNewWorkflow:h.isNewWorkflow,workflowId:d.id,setExportYaml:h.setExportYaml,setExportOpen:h.setExportOpen,toast:h.toast,onDeleteClick:h.wfDeleteHandlers.handleDeleteWorkflowClick,deleteDisabled:h.deleteWorkflowRequest.isLoading||h.wfDel.workflowDeleteLoading})]})}),(0,b.jsx)(aH,{wfDel:h.wfDel,otherWorkflows:f,deleteWorkflowLoading:h.deleteWorkflowRequest.isLoading,wfDeleteHandlers:h.wfDeleteHandlers,exportOpen:h.exportOpen,setExportOpen:h.setExportOpen,exportYaml:h.exportYaml,stepDel:h.stepDel,stepsForStepMigration:h.stepsForStepMigration,stepDeleteHandlers:h.stepDeleteHandlers})]})}let aJ=(0,al.createServerReference)("40c93468e543b2caecba4d89ffe4f6fd8c0cc31817",al.callServer,void 0,al.findSourceMapURL,"deleteWorkflowAction"),aK=(0,al.createServerReference)("60b50104047620c3119d1ad108957522f12f5c7332",al.callServer,void 0,al.findSourceMapURL,"updateWorkflowAction"),aL=(0,al.createServerReference)("4078a1bca8c7f9c203ad72b7b2f4f4b6ba0a74ef5a",al.callServer,void 0,al.findSourceMapURL,"exportAllWorkflowsAction"),aM=(0,al.createServerReference)("603effa208271095a24f51f0a29195fb788956e3cf",al.callServer,void 0,al.findSourceMapURL,"importWorkflowsAction"),aN=(0,al.createServerReference)("60dc539f538e6cad5c0abc01185333ce648a9004c5",al.callServer,void 0,al.findSourceMapURL,"reorderWorkflowsAction");var aO=a.i(229614);function aP({open:a,onOpenChange:c,importYaml:d,onImportYamlChange:e,onFileUpload:f,fileInputRef:g,onImport:h,importLoading:i}){return(0,b.jsx)(C.Dialog,{open:a,onOpenChange:c,children:(0,b.jsxs)(C.DialogContent,{children:[(0,b.jsx)(C.DialogHeader,{children:(0,b.jsx)(C.DialogTitle,{children:"Import Workflows"})}),(0,b.jsxs)("div",{className:"space-y-4",children:[(0,b.jsxs)("div",{className:"space-y-2",children:[(0,b.jsx)(u.Label,{children:"Upload YAML file"}),(0,b.jsx)("input",{ref:g,type:"file",accept:".yml,.yaml",onChange:f,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,b.jsxs)("div",{className:"space-y-2",children:[(0,b.jsx)(u.Label,{children:"Or paste YAML"}),(0,b.jsx)(D.Textarea,{placeholder:"version: 1\ntype: kandev_workflow\nworkflows:\n  - name: My Workflow\n    steps: [...]",value:d,onChange:a=>e(a.target.value),className:"font-mono text-xs max-h-96 overflow-y-auto"})]})]}),(0,b.jsxs)(C.DialogFooter,{children:[(0,b.jsx)(o.Button,{variant:"outline",onClick:()=>c(!1),className:"cursor-pointer",children:"Cancel"}),(0,b.jsx)(o.Button,{onClick:h,disabled:!d.trim()||i,className:"cursor-pointer",children:i?"Importing...":"Import"})]})]})})}function aQ({template:a,isSelected:c}){return(0,b.jsxs)("label",{htmlFor:a.id,className:(0,N.cn)("flex items-start gap-3 p-3 rounded-lg border cursor-pointer transition-colors",c?"border-primary bg-primary/5":"border-border hover:border-primary/50"),children:[(0,b.jsx)(aO.RadioGroupItem,{value:a.id,id:a.id,className:"mt-0.5"}),(0,b.jsxs)("div",{className:"flex flex-col gap-1.5 min-w-0",children:[(0,b.jsx)("span",{className:"font-medium",children:a.name}),a.description&&(0,b.jsx)("span",{className:"text-sm text-muted-foreground",children:a.description}),a.default_steps&&a.default_steps.length>0&&(0,b.jsx)("div",{className:"flex items-center gap-1.5 flex-wrap mt-0.5",children:a.default_steps.map((a,c)=>(0,b.jsxs)("div",{className:"flex items-center gap-1",children:[c>0&&(0,b.jsx)("span",{className:"text-muted-foreground/40 text-xs",children:"→"}),(0,b.jsxs)("div",{className:"flex items-center gap-1 text-xs text-muted-foreground",children:[(0,b.jsx)("div",{className:(0,N.cn)("w-2 h-2 rounded-full",a.color??"bg-slate-500")}),a.name]})]},c))})]})]})}function aR({open:a,onOpenChange:c,workflowName:d,onWorkflowNameChange:e,selectedTemplateId:f,onSelectedTemplateChange:g,workflowTemplates:h,onCreate:i}){return(0,b.jsx)(C.Dialog,{open:a,onOpenChange:c,children:(0,b.jsxs)(C.DialogContent,{className:"sm:w-[900px] sm:max-w-none max-h-[90vh] flex flex-col","data-testid":"create-workflow-dialog",children:[(0,b.jsx)(C.DialogHeader,{children:(0,b.jsx)(C.DialogTitle,{children:"Add Workflow"})}),(0,b.jsxs)("div",{className:"space-y-6 overflow-y-auto",children:[(0,b.jsxs)("div",{className:"space-y-2",children:[(0,b.jsx)(u.Label,{htmlFor:"workflowName",children:"Name"}),(0,b.jsx)(t.Input,{id:"workflowName",placeholder:"My Project Workflow",value:d,onChange:a=>e(a.target.value),"data-testid":"workflow-name-input"})]}),h.length>0&&(0,b.jsxs)("div",{className:"space-y-2",children:[(0,b.jsx)(u.Label,{children:"Template"}),(0,b.jsx)(aO.RadioGroup,{value:f??"custom",onValueChange:a=>g("custom"===a?null:a),children:(0,b.jsxs)("div",{className:"grid gap-3",children:[h.map(a=>(0,b.jsx)(aQ,{template:a,isSelected:f===a.id},a.id)),(0,b.jsxs)("label",{htmlFor:"custom",className:(0,N.cn)("flex items-start gap-3 p-3 rounded-lg border cursor-pointer transition-colors",null===f?"border-primary bg-primary/5":"border-border hover:border-primary/50"),children:[(0,b.jsx)(aO.RadioGroupItem,{value:"custom",id:"custom",className:"mt-0.5"}),(0,b.jsxs)("div",{className:"flex flex-col gap-1.5",children:[(0,b.jsx)("span",{className:"font-medium",children:"Custom"}),(0,b.jsx)("span",{className:"text-sm text-muted-foreground",children:"Create your own agentic workflow from scratch."})]})]})]})})]})]}),(0,b.jsxs)(C.DialogFooter,{children:[(0,b.jsx)(o.Button,{variant:"outline",onClick:()=>c(!1),className:"cursor-pointer",children:"Cancel"}),(0,b.jsx)(o.Button,{onClick:i,className:"cursor-pointer","data-testid":"confirm-create-workflow",children:"Add Workflow"})]})]})})}var aS=a.i(81417);let aT=[{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 aU({onExport:a,onImport:c,onAdd:d}){return(0,b.jsxs)("div",{className:"flex gap-2",children:[(0,b.jsxs)(o.Button,{size:"sm",variant:"outline",onClick:a,className:"cursor-pointer",children:[(0,b.jsx)(f.IconDownload,{className:"h-4 w-4 mr-2"}),"Export All"]}),(0,b.jsxs)(o.Button,{size:"sm",variant:"outline",onClick:c,className:"cursor-pointer",children:[(0,b.jsx)(k,{className:"h-4 w-4 mr-2"}),"Import"]}),(0,b.jsxs)(o.Button,{size:"sm",onClick:d,className:"cursor-pointer","data-testid":"add-workflow-button",children:[(0,b.jsx)(i.IconPlus,{className:"h-4 w-4 mr-2"}),"Add Workflow"]})]})}function aV({workflow:a,children:c}){let{attributes:d,listeners:e,setNodeRef:f,transform:h,transition:i,isDragging:j}=(0,m.useSortable)({id:a.id}),k={transform:n.CSS.Transform.toString(h),transition:i,opacity:j?.5:1};return(0,b.jsxs)("div",{ref:f,style:k,className:"relative min-w-0",children:[(0,b.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-${a.id}`,...d,...e,children:(0,b.jsx)(g.IconGripVertical,{className:"h-5 w-5 text-muted-foreground"})}),c]})}function aW({workflowItems:a,workspaceId:c,templateStepsById:d,isWorkflowDirty:e,onUpdate:f,onDelete:g,onSave:h,onCreated:i,onReorder:j}){let k=(0,l.useSensors)((0,l.useSensor)(l.PointerSensor,{activationConstraint:{distance:8}}));return(0,b.jsx)(l.DndContext,{sensors:k,collisionDetection:l.closestCenter,onDragEnd:b=>{let{active:d,over:e}=b;if(!e||d.id===e.id)return;let f=a.findIndex(a=>a.id===d.id),g=a.findIndex(a=>a.id===e.id);if(-1===f||-1===g)return;let h=(0,m.arrayMove)(a,f,g);j(h);let i=h.filter(a=>!a.id.startsWith("temp-")).map(a=>a.id);i.length>0&&aN(c,i).catch(()=>{})},children:(0,b.jsx)(m.SortableContext,{items:a.map(a=>a.id),strategy:m.verticalListSortingStrategy,children:(0,b.jsx)("div",{className:"grid min-w-0 gap-3 pl-8",children:a.map(c=>{let j=c.id.startsWith("temp-"),k=j&&c.workflow_template_id?d.get(c.workflow_template_id)??[]:aT,l=j&&k.length?k.map((a,b)=>({id:`temp-step-${c.id}-${b}`,workflow_id:c.id,name:a.name,position:a.position??b,color:a.color??"bg-slate-500",prompt:a.prompt,events:a.events,is_start_step:a.is_start_step,show_in_command_panel:a.show_in_command_panel,allow_manual_move:!0,created_at:"",updated_at:""})):void 0;return(0,b.jsx)(aV,{workflow:c,children:(0,b.jsx)(aI,{workflow:c,isWorkflowDirty:e(c),initialWorkflowSteps:l,templateStepCount:j?k.length:0,otherWorkflows:a.filter(a=>a.id!==c.id&&!a.id.startsWith("temp-")),onUpdateWorkflow:a=>f(c.id,a),onDeleteWorkflow:async()=>{await g(c.id)},onSaveWorkflow:async()=>{await h(c.id)},onWorkflowCreated:a=>i(c.id,a)})},c.id)})})})})}function aX({page:a}){return(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(F,{open:a.isExportDialogOpen,onOpenChange:a.setIsExportDialogOpen,title:"Export Workflows",content:a.exportYaml}),(0,b.jsx)(aP,{open:a.isImportDialogOpen,onOpenChange:a.setIsImportDialogOpen,importYaml:a.importYaml,onImportYamlChange:a.setImportYaml,onFileUpload:a.handleFileUpload,fileInputRef:a.fileInputRef,onImport:a.handleImport,importLoading:a.importLoading}),(0,b.jsx)(aR,{open:a.isAddWorkflowDialogOpen,onOpenChange:a.setIsAddWorkflowDialogOpen,workflowName:a.newWorkflowName,onWorkflowNameChange:a.setNewWorkflowName,selectedTemplateId:a.selectedTemplateId,onSelectedTemplateChange:a.setSelectedTemplateId,workflowTemplates:a.workflowTemplates,onCreate:a.handleCreateWorkflow})]})}function aY({workspace:a,workflows:f,workflowTemplates:g}){let i=function(a,b,d){let f=(0,e.useRouter)(),{toast:g}=(0,z.useToast)(),{workflowItems:h,setWorkflowItems:i,setSavedWorkflowItems:j,isWorkflowDirty:k}=function(a,b){let d=(0,w.useAppStore)(a=>a.workflows.items),e=(0,c.useMemo)(()=>{let a=d.filter(a=>!a.hidden);return b?a.filter(a=>a.workspaceId===b):a},[d,b]),[f,g]=(0,c.useState)(a),[h,i]=(0,c.useState)(a),j=(0,c.useRef)(new Set(a.map(a=>a.id)));(0,c.useEffect)(()=>{let b=j.current,c=a.filter(a=>!b.has(a.id));if(0!==c.length){for(let a of c)b.add(a.id);g(a=>{let b=new Set(a.map(a=>a.id)),d=c.filter(a=>!b.has(a.id));return 0===d.length?a:[...a,...d]}),i(a=>{let b=new Set(a.map(a=>a.id)),d=c.filter(a=>!b.has(a.id));return 0===d.length?a:[...a,...d]})}},[a]);let k=(0,c.useRef)(new Set);(0,c.useEffect)(()=>{let a=new Set(e.map(a=>a.id)),b=new Set([...k.current].filter(b=>!a.has(b)));k.current=a;let c=a=>{let b=new Set(a.map(a=>a.id)),c=new Set(a.filter(a=>a.id.startsWith("temp-")).map(a=>a.workspace_id));return e.filter(a=>!b.has(a.id)&&!c.has(a.workspaceId)).map(a=>{var b;return{id:(b=a).id,workspace_id:b.workspaceId,name:b.name,description:b.description,created_at:"",updated_at:""}})};g(a=>{let d=c(a),f=a.filter(a=>!b.has(a.id)).map(a=>{if(a.id.startsWith("temp-"))return a;let b=e.find(b=>b.id===a.id);return b&&b.name!==a.name?{...a,name:b.name}:a});return 0===d.length&&f.length===a.length&&f.every((b,c)=>b===a[c])?a:[...d,...f]}),i(a=>{let d=c(a),e=a.filter(a=>!b.has(a.id));return 0===d.length&&e.length===a.length?a:[...d,...e]})},[e]);let l=(0,c.useMemo)(()=>new Map(h.map(a=>[a.id,a])),[h]);return{workflowItems:f,setWorkflowItems:g,savedWorkflowItems:h,setSavedWorkflowItems:i,isWorkflowDirty:a=>{let b=l.get(a.id);return!b||a.name!==b.name||a.description!==b.description||(a.agent_profile_id??"")!==(b.agent_profile_id??"")}}}(b,a?.id),{isExportDialogOpen:l,setIsExportDialogOpen:m,exportYaml:n,isImportDialogOpen:o,setIsImportDialogOpen:p,importYaml:q,setImportYaml:r,importLoading:s,fileInputRef:t,handleExportAll:u,handleFileUpload:v,handleImport:x}=function(a,b,d){let[e,f]=(0,c.useState)(!1),[g,h]=(0,c.useState)(""),[i,j]=(0,c.useState)(!1),[k,l]=(0,c.useState)(""),[m,n]=(0,c.useState)(!1),o=(0,c.useRef)(null),p=async()=>{if(a)try{let b=await aL(a.id);h(b),f(!0)}catch(a){d({title:"Failed to export workflows",description:a instanceof Error?a.message:"Request failed",variant:"error"})}},q=async()=>{if(a&&k.trim()){n(!0);try{let c=await aM(a.id,k.trim()),e=c.created??[],f=c.skipped??[],g=[];e.length>0&&g.push(`Created: ${e.join(", ")}`),f.length>0&&g.push(`Skipped (already exist): ${f.join(", ")}`),d({title:"Import complete",description:g.join(". ")}),j(!1),l(""),e.length>0&&b.refresh()}catch(a){d({title:"Failed to import workflows",description:a instanceof Error?a.message:"Invalid YAML",variant:"error"})}finally{n(!1)}}};return{isExportDialogOpen:e,setIsExportDialogOpen:f,exportYaml:g,isImportDialogOpen:i,setIsImportDialogOpen:j,importYaml:k,setImportYaml:l,importLoading:m,fileInputRef:o,handleExportAll:p,handleFileUpload:a=>{let b=a.target.files?.[0];if(!b)return;let c=new FileReader;c.onload=a=>{l(a.target?.result)},c.readAsText(b),a.target.value=""},handleImport:q}}(a,f,g),{isAddWorkflowDialogOpen:y,setIsAddWorkflowDialogOpen:A,newWorkflowName:B,setNewWorkflowName:C,selectedTemplateId:D,setSelectedTemplateId:E,handleOpenAddWorkflowDialog:F,handleCreateWorkflow:G,handleUpdateWorkflow:H,handleDeleteWorkflow:I,handleWorkflowCreated:J,handleSaveWorkflow:K}=function({workspace:a,workflowItems:b,workflowTemplates:d,setWorkflowItems:e,setSavedWorkflowItems:f}){let[g,h]=(0,c.useState)(!1),[i,j]=(0,c.useState)(""),[k,l]=(0,c.useState)(null);return{isAddWorkflowDialogOpen:g,setIsAddWorkflowDialogOpen:h,newWorkflowName:i,setNewWorkflowName:j,selectedTemplateId:k,setSelectedTemplateId:l,handleOpenAddWorkflowDialog:()=>{j(""),l(d.length>0?d[0].id:null),h(!0)},handleCreateWorkflow:()=>{if(!a)return;let b=k?d.find(a=>a.id===k)?.name??"New Workflow":"New Workflow",c={id:`temp-${(0,N.generateUUID)()}`,workspace_id:a.id,name:i.trim()||b,description:"",workflow_template_id:k,created_at:"",updated_at:""};e(a=>[c,...a]),h(!1)},handleUpdateWorkflow:(a,b)=>{e(c=>c.map(c=>c.id===a?{...c,...b}:c))},handleDeleteWorkflow:async a=>{a.startsWith("temp-")?e(b=>b.filter(b=>b.id!==a)):(await aJ(a),e(b=>b.filter(b=>b.id!==a)),f(b=>b.filter(b=>b.id!==a)))},handleWorkflowCreated:(a,b)=>{e(c=>c.map(c=>c.id===a?b:c)),f(a=>[{...b},...a])},handleSaveWorkflow:async a=>{let c=b.find(b=>b.id===a);if(!c)return;let d={};c.name.trim()&&(d.name=c.name.trim()),d.agent_profile_id=c.agent_profile_id??"",Object.keys(d).length&&await aK(a,d),e(b=>b.map(b=>b.id===a?{...b,...d}:b)),f(b=>b.some(b=>b.id===a)?b.map(b=>b.id===a?{...c,...d}:b):[...b,{...c,...d}])}}}({workspace:a,workflowItems:h,workflowTemplates:d,setWorkflowItems:i,setSavedWorkflowItems:j}),L=(0,c.useMemo)(()=>new Map(d.map(a=>[a.id,a.default_steps??[]])),[d]);return{router:f,workflowItems:h,isWorkflowDirty:k,isExportDialogOpen:l,setIsExportDialogOpen:m,exportYaml:n,isImportDialogOpen:o,setIsImportDialogOpen:p,importYaml:q,setImportYaml:r,importLoading:s,fileInputRef:t,handleExportAll:u,handleFileUpload:v,handleImport:x,isAddWorkflowDialogOpen:y,setIsAddWorkflowDialogOpen:A,newWorkflowName:B,setNewWorkflowName:C,selectedTemplateId:D,setSelectedTemplateId:E,handleOpenAddWorkflowDialog:F,handleCreateWorkflow:G,handleUpdateWorkflow:H,handleDeleteWorkflow:I,handleWorkflowCreated:J,handleSaveWorkflow:K,handleReorderWorkflows:a=>{i(a),j(b=>{let c=new Map(a.map((a,b)=>[a.id,b]));return[...b].sort((a,b)=>(c.get(a.id)??0)-(c.get(b.id)??0))})},workflowTemplates:d,templateStepsById:L}}(a,f,g);return a?(0,b.jsxs)("div",{className:"space-y-8",children:[(0,b.jsxs)("div",{className:"flex flex-wrap items-start justify-between gap-4",children:[(0,b.jsxs)("div",{children:[(0,b.jsx)("h2",{className:"text-2xl font-bold",children:a.name}),(0,b.jsx)("p",{className:"text-sm text-muted-foreground mt-1",children:"Manage workflows for this workspace."})]}),(0,b.jsx)(o.Button,{asChild:!0,variant:"outline",size:"sm",children:(0,b.jsx)(d.default,{href:`/settings/workspace/${a.id}`,children:"Workspace settings"})})]}),(0,b.jsx)(p.Separator,{}),(0,b.jsx)(q.SettingsSection,{icon:(0,b.jsx)(h.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,b.jsx)(aU,{onExport:i.handleExportAll,onImport:()=>i.setIsImportDialogOpen(!0),onAdd:i.handleOpenAddWorkflowDialog}),children:(0,b.jsx)(aW,{workflowItems:i.workflowItems,workspaceId:a.id,templateStepsById:i.templateStepsById,isWorkflowDirty:i.isWorkflowDirty,onUpdate:i.handleUpdateWorkflow,onDelete:i.handleDeleteWorkflow,onSave:i.handleSaveWorkflow,onCreated:i.handleWorkflowCreated,onReorder:i.handleReorderWorkflows})}),(0,b.jsx)(aX,{page:i})]}):(0,b.jsx)(aS.WorkspaceNotFoundCard,{onBack:()=>i.router.push("/settings/workspace")})}a.s(["WorkspaceWorkflowsClient",()=>aY],23847)}];

//# sourceMappingURL=web_app_settings_workspace_workspace-workflows-client_tsx_ed2b8ef5._.js.map