@jiggai/kitchen 0.5.0 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.next/BUILD_ID +1 -1
- package/.next/build-manifest.json +2 -2
- package/.next/prerender-manifest.json +3 -3
- package/.next/server/app/_global-error.html +2 -2
- package/.next/server/app/_global-error.rsc +1 -1
- package/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/_not-found.html +1 -1
- package/.next/server/app/_not-found.rsc +2 -2
- package/.next/server/app/_not-found.segments/_full.segment.rsc +2 -2
- package/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/channels.html +2 -2
- package/.next/server/app/channels.rsc +2 -2
- package/.next/server/app/channels.segments/_full.segment.rsc +2 -2
- package/.next/server/app/channels.segments/_head.segment.rsc +1 -1
- package/.next/server/app/channels.segments/_index.segment.rsc +1 -1
- package/.next/server/app/channels.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/channels.segments/channels/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/channels.segments/channels.segment.rsc +1 -1
- package/.next/server/app/goals/new.html +2 -2
- package/.next/server/app/goals/new.rsc +2 -2
- package/.next/server/app/goals/new.segments/_full.segment.rsc +2 -2
- package/.next/server/app/goals/new.segments/_head.segment.rsc +1 -1
- package/.next/server/app/goals/new.segments/_index.segment.rsc +1 -1
- package/.next/server/app/goals/new.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/goals/new.segments/goals/new/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/goals/new.segments/goals/new.segment.rsc +1 -1
- package/.next/server/app/goals/new.segments/goals.segment.rsc +1 -1
- package/.next/server/app/goals.html +1 -1
- package/.next/server/app/goals.rsc +2 -2
- package/.next/server/app/goals.segments/_full.segment.rsc +2 -2
- package/.next/server/app/goals.segments/_head.segment.rsc +1 -1
- package/.next/server/app/goals.segments/_index.segment.rsc +1 -1
- package/.next/server/app/goals.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/goals.segments/goals/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/goals.segments/goals.segment.rsc +1 -1
- package/.next/server/app/settings.html +1 -1
- package/.next/server/app/settings.rsc +2 -2
- package/.next/server/app/settings.segments/_full.segment.rsc +2 -2
- package/.next/server/app/settings.segments/_head.segment.rsc +1 -1
- package/.next/server/app/settings.segments/_index.segment.rsc +1 -1
- package/.next/server/app/settings.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/settings.segments/settings/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/settings.segments/settings.segment.rsc +1 -1
- package/.next/server/app/teams/[teamId]/workflows/[workflowId]/page_client-reference-manifest.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__68b03663._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__68b03663._.js.map +1 -1
- package/.next/server/chunks/ssr/[root-of-the-server]__3b880807._.js +1 -1
- package/.next/server/chunks/ssr/[root-of-the-server]__3b880807._.js.map +1 -1
- package/.next/server/chunks/ssr/b1a17_app_teams_[teamId]_workflows_[workflowId]_workflows-editor-client_tsx_5e714aa2._.js +1 -1
- package/.next/server/chunks/ssr/b1a17_app_teams_[teamId]_workflows_[workflowId]_workflows-editor-client_tsx_5e714aa2._.js.map +1 -1
- package/.next/server/pages/404.html +1 -1
- package/.next/server/pages/500.html +2 -2
- package/.next/server/server-reference-manifest.js +1 -1
- package/.next/server/server-reference-manifest.json +1 -1
- package/.next/static/chunks/{f785b5eee9bc75de.js → 37d8bbefc2b9da30.js} +1 -1
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
- /package/.next/static/{joB2FecbcL7AranUOr_Dx → 1ChcprSdKen0WEtF_n03n}/_buildManifest.js +0 -0
- /package/.next/static/{joB2FecbcL7AranUOr_Dx → 1ChcprSdKen0WEtF_n03n}/_clientMiddlewareManifest.json +0 -0
- /package/.next/static/{joB2FecbcL7AranUOr_Dx → 1ChcprSdKen0WEtF_n03n}/_ssgManifest.js +0 -0
|
@@ -4,6 +4,6 @@ module.exports=[13833,a=>{"use strict";var b=a.i(87924),c=a.i(72131),d=a.i(38246
|
|
|
4
4
|
50% { transform: translateX(200%); }
|
|
5
5
|
100% { transform: translateX(-100%); }
|
|
6
6
|
}
|
|
7
|
-
`})]}),document.body):null}function n({targetTextareaRef:a,workflow:d,currentNodeId:e,onInsert:f}){let[g,h]=(0,c.useState)(!1),i=(0,c.useRef)(null),j=(0,c.useMemo)(()=>(function(a,b){let c=[],d=new Set,e=[b],f=new Set;for(;e.length>0;){let c=e.shift();if(!f.has(c))for(let g of(f.add(c),a.edges??[]))g.to!==c||d.has(g.from)||g.from===b||(d.add(g.from),e.push(g.from))}for(let b of d){let d=a.nodes.find(a=>a.id===b);if(!d)continue;let e=d.name||b,f=d.config&&"object"==typeof d.config&&!Array.isArray(d.config)?d.config:{};c.push({nodeId:b,nodeName:e,fieldName:"output",fieldType:"text"},{nodeId:b,nodeName:e,fieldName:"text",fieldType:"text"});let g=f.outputFields;if(Array.isArray(g))for(let a of g)a.name?.trim()&&c.push({nodeId:b,nodeName:e,fieldName:a.name.trim(),fieldType:a.type||"text"})}return c})(d,e),[d,e]),k=(0,c.useMemo)(()=>[{variable:"{{run.id}}",type:"text"},{variable:"{{workflow.name}}",type:"text"},{variable:"{{workflow.id}}",type:"text"},{variable:"{{node.id}}",type:"text"},{variable:"{{date}}",type:"text"}],[]);(0,c.useEffect)(()=>{function a(a){i.current&&!i.current.contains(a.target)&&h(!1)}if(g)return document.addEventListener("mousedown",a),()=>document.removeEventListener("mousedown",a)},[g]);let l=b=>{let c=a.current;if(c){let a=c.selectionStart,d=c.selectionEnd,e=c.value,g=e.substring(0,a)+b+e.substring(d);f&&(f(g),setTimeout(()=>{c.focus();let d=a+b.length;c.setSelectionRange(d,d)},0))}h(!1)},m=j.reduce((a,b)=>{let c=`${b.nodeId}|${b.nodeName}`;return a[c]||(a[c]={nodeId:b.nodeId,nodeName:b.nodeName,fields:[]}),a[c].fields.push({name:b.fieldName,type:b.fieldType}),a},{});return(0,b.jsxs)("div",{className:"absolute top-1 right-1",ref:i,children:[(0,b.jsx)("button",{type:"button",onClick:()=>h(!g),className:"rounded-lg border border-white/10 bg-black/30 px-2 py-1 text-[9px] text-[color:var(--ck-text-secondary)] hover:bg-white/10 hover:text-[color:var(--ck-text-primary)]",title:"Insert variable",children:"{{}}"}),g&&(0,b.jsx)("div",{className:"absolute right-0 top-8 z-50 w-72 max-h-80 overflow-auto rounded-lg border border-white/15 bg-black/80 backdrop-blur shadow-[var(--ck-shadow-1)]",children:(0,b.jsxs)("div",{className:"p-1",children:[(0,b.jsxs)("div",{children:[(0,b.jsx)("div",{className:"px-2 py-1 text-[10px] font-medium uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"Globals"}),k.map(({variable:a,type:c})=>(0,b.jsxs)("button",{type:"button",onClick:()=>l(a),className:"w-full flex items-center justify-between gap-2 rounded-lg px-2 py-1 text-left text-xs text-[color:var(--ck-text-primary)] hover:bg-white/10 cursor-pointer",children:[(0,b.jsx)("span",{className:"font-mono",children:a}),(0,b.jsx)("span",{className:"text-[9px] px-1 py-0.5 rounded-sm bg-black/30 text-blue-400",children:c})]},a))]}),Object.values(m).map(a=>(0,b.jsxs)("div",{children:[(0,b.jsx)("div",{className:"px-2 py-1 text-[10px] font-medium uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:a.nodeName}),a.fields.map(c=>{let d=`{{${a.nodeId}.${c.name}}}`,e="text"===c.type?"text-blue-400":"list"===c.type?"text-green-400":"json"===c.type?"text-amber-400":"text-gray-400";return(0,b.jsxs)("button",{type:"button",onClick:()=>l(d),className:"w-full flex items-center justify-between gap-2 rounded-lg px-2 py-1 text-left text-xs text-[color:var(--ck-text-primary)] hover:bg-white/10 cursor-pointer",children:[(0,b.jsx)("span",{className:"font-mono",children:d}),(0,b.jsx)("span",{className:`text-[9px] px-1 py-0.5 rounded-sm bg-black/30 ${e}`,children:c.type})]},`${a.nodeId}.${c.name}`)})]},a.nodeId)),0===j.length&&(0,b.jsx)("div",{className:"px-2 py-3 text-xs text-[color:var(--ck-text-secondary)]",children:"Tip: Add output fields to upstream nodes to see node-specific variables here."})]})})]})}function o({value:a,onChangeValue:d,workflow:e,currentNodeId:f,className:g,placeholder:h,spellCheck:i}){let j=(0,c.useRef)(null);return(0,b.jsxs)("div",{className:"relative",children:[(0,b.jsx)("textarea",{ref:j,value:a,onChange:a=>d(a.target.value),className:g,placeholder:h,spellCheck:i}),(0,b.jsx)(n,{targetTextareaRef:j,workflow:e,currentNodeId:f,onInsert:a=>d(a)})]})}function p({outputFields:a,onChange:c}){return(0,b.jsxs)("div",{children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"output fields (optional)"}),(0,b.jsx)("div",{className:"text-[9px] text-[color:var(--ck-text-secondary)] mb-2",children:"Define what this node produces for downstream nodes"}),(0,b.jsxs)("div",{className:"space-y-1",children:[a.map((d,e)=>(0,b.jsxs)("div",{className:"flex items-center gap-2",children:[(0,b.jsx)("input",{value:d.name,onChange:b=>{let f=[...a];f[e]={...d,name:b.target.value},c(f)},className:"flex-1 rounded-lg border border-white/10 bg-black/30 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",placeholder:"Field name"}),(0,b.jsxs)("select",{value:d.type,onChange:b=>{let f=b.target.value,g=[...a];g[e]={...d,type:f},c(g)},className:"rounded-lg border border-white/10 bg-black/30 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",children:[(0,b.jsx)("option",{value:"text",children:"text"}),(0,b.jsx)("option",{value:"list",children:"list"}),(0,b.jsx)("option",{value:"json",children:"json"})]}),(0,b.jsx)("button",{type:"button",onClick:()=>{c(a.filter((a,b)=>b!==e))},className:"text-xs text-[color:var(--ck-text-tertiary)] hover:text-[color:var(--ck-text-primary)]",children:"×"})]},e)),(0,b.jsx)("button",{type:"button",onClick:()=>{c([...a,{name:"",type:"text"}])},className:"text-xs text-[color:var(--ck-text-secondary)] hover:text-[color:var(--ck-text-primary)]",children:"+ Add field"})]})]})}function q(a,b){return`ck-wf-draft:${a}:${b}`}function r({teamId:a,workflowId:i,draft:j,llmTaskEnabled:l}){let n,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R=(0,e.useRouter)(),[S,T]=(0,c.useState)("canvas"),[U,V]=(0,c.useState)(!1),[W,X]=(0,c.useState)({kind:"loading"}),[Y,Z]=(0,c.useState)(""),[$,_]=(0,c.useState)("idle"),[aa,ab]=(0,c.useState)(""),ac=(0,c.useRef)(null),[ad,ae]=(0,c.useState)(!1),[af,ag]=(0,c.useState)(1),ah=(0,c.useRef)(null),[ai,aj]=(0,c.useState)(""),[ak,al]=(0,c.useState)(null),[am,an]=(0,c.useState)({kind:"select"}),[ao,ap]=(0,c.useState)(""),[aq,ar]=(0,c.useState)([]),[as,at]=(0,c.useState)(""),[au,av]=(0,c.useState)([]),[aw,ax]=(0,c.useState)(""),[ay,az]=(0,c.useState)([]),[aA,aB]=(0,c.useState)(""),[aC,aD]=(0,c.useState)([]),[aE,aF]=(0,c.useState)({}),[aG,aH]=(0,c.useState)(!1),[aI,aJ]=(0,c.useState)({}),[aK,aL]=(0,c.useState)({}),[aM,aN]=(0,c.useState)({}),aO=(0,c.useMemo)(()=>/Tool not available:\s*gateway/i.test(String(aw||"")),[aw]),[aP,aQ]=(0,c.useState)([]),[aR,aS]=(0,c.useState)(!1),[aT,aU]=(0,c.useState)(!1),[aV,aW]=(0,c.useState)(""),[aX,aY]=(0,c.useState)(""),[aZ,a$]=(0,c.useState)(!1),[a_,a0]=(0,c.useState)(""),[a1,a2]=(0,c.useState)({}),[a3,a4]=(0,c.useState)(!1),[a5,a6]=(0,c.useState)(!1),[a7,a8]=(0,c.useState)(""),[a9,ba]=(0,c.useState)(""),[bb,bc]=(0,c.useState)(""),[bd,be]=(0,c.useState)("llm"),[bf,bg]=(0,c.useState)(""),[bh,bi]=(0,c.useState)(""),[bj,bk]=(0,c.useState)("");function bl(a){return!!a&&"object"==typeof a&&!Array.isArray(a)}function bm(a){if(!bl(a))return null;let b=bl(a.match)?a.match:null;if(!b)return null;let c=String(b.channel??"").trim();if(!c)return null;let d=String(a.agentId??"").trim(),e=String(b.accountId??"").trim(),f=bl(b.peer)?b.peer:null,g=f?String(f.kind??"").trim():"",h=f?String(f.id??"").trim():"",i=h||e;if(!i)return null;let j=d||(e?`${c}:account:${e}`:`${c}:${g}:${h}`),k=[c];return d&&k.push(d),e&&k.push(`account:${e}`),g&&h&&k.push(`${g}:${h}`),{id:j,label:k.join(" · "),channel:c,target:i}}(0,c.useEffect)(()=>{(async()=>{try{if(j){let b=sessionStorage.getItem(q(a,i));if(b)return void X({kind:"ready",jsonText:b});let c=JSON.stringify({schema:"clawkitchen.workflow.v1",id:i,name:"New workflow",timezone:"UTC",nodes:[{id:"start",type:"start",name:"start",x:80,y:80,config:{}},{id:"end",type:"end",name:"end",x:520,y:80,config:{}}],edges:[{id:"e1",from:"start",to:"end"}]},null,2)+"\n";X({kind:"ready",jsonText:c});try{sessionStorage.setItem(q(a,i),c)}catch{}return}let b=await fetch(`/api/teams/workflows?teamId=${encodeURIComponent(a)}&id=${encodeURIComponent(i)}`,{cache:"no-store"}),c=await b.json();if(!b.ok||!c.ok)throw Error(c.error||"Failed to load workflow");X({kind:"ready",jsonText:JSON.stringify(c.workflow,null,2)+"\n"})}catch(a){X({kind:"error",error:a instanceof Error?a.message:String(a)})}})()},[a,i,j]),(0,c.useEffect)(()=>{(async()=>{at("");try{let b=await fetch("/api/agents",{cache:"no-store"}),c=await b.json();if(!b.ok)throw Error(c.error||c.message||"Failed to load agents");let d=(Array.isArray(c.agents)?c.agents:[]).map(a=>({id:String(a.id??"").trim(),identityName:"string"==typeof a.identityName?a.identityName:void 0})).filter(b=>b.id&&b.id.startsWith(`${a}-`));ar(d)}catch(a){at(a instanceof Error?a.message:String(a)),ar([])}})()},[a]),(0,c.useEffect)(()=>{(async()=>{ax("");try{let a=await fetch("/api/channels/bindings",{cache:"no-store"}),b=await a.json();if(!a.ok||!1===b.ok)throw Error(b.error||"Failed to load bindings");let c=(Array.isArray(b.bindings)?b.bindings:[]).map(bm).filter(Boolean);av(c)}catch(a){ax(a instanceof Error?a.message:String(a)),av([])}})()},[]),(0,c.useEffect)(()=>{(async()=>{aB("");try{let a=await fetch("/api/settings/model-options",{cache:"no-store"}),b=await a.json();if(!a.ok||!1===b.ok)throw Error(b.error||"Failed to load model options");let c=Array.isArray(b.models)?Array.from(new Set(b.models.map(a=>String(a??"").trim()).filter(Boolean))):[];az(c)}catch(a){aB(a instanceof Error?a.message:String(a)),az([])}})()},[]);let bn=(0,c.useCallback)(async()=>{a0(""),a$(!0);try{let a=await fetch("/api/cron/jobs",{cache:"no-store"}),b=await a.json();if(!a.ok||!1===b.ok)throw Error(b.error||"Failed to load cron jobs");let c=Array.isArray(b.jobs)?b.jobs:[],d={};for(let a of c){if(!a||!a.enabled)continue;let b=String(a.name??""),c=String(a.payload?.message??"");if(!(b.startsWith("workflow-worker:")||c.includes("worker-tick")))continue;let e=b.match(/^workflow-worker:[^:]+:(.+)$/);if(e?.[1]){d[e[1]]=!0;continue}let f=c.match(/--agent-id\s+(\S+)/);if(f?.[1]){d[f[1]]=!0;continue}let g=String(a.agentId??"").trim();g&&"main"!==g&&(d[g]=!0)}return a2(d),d}catch(a){return a0(a instanceof Error?a.message:String(a)),a2({}),{}}finally{a$(!1)}},[]);(0,c.useEffect)(()=>{bn()},[bn]);let bo=(0,c.useMemo)(()=>{if("ready"!==W.kind)return{wf:null,err:""};try{return{wf:JSON.parse(W.jsonText),err:""}}catch(a){return{wf:null,err:a instanceof Error?a.message:String(a)}}},[W]),bp=(0,c.useMemo)(()=>bo.wf?function(a){let b=[],c=[];"clawkitchen.workflow.v1"!==a.schema&&b.push(`schema must be clawkitchen.workflow.v1 (got ${String(a.schema)})`),String(a.id||"").trim()||b.push("id is required"),String(a.name||"").trim()||b.push("name is required");let d=Array.isArray(a.nodes)?a.nodes:[],e=Array.isArray(a.edges)?a.edges:[],f=Array.isArray(a.triggers)?a.triggers:[],h=d.map(a=>String(a?.id??"").trim()).filter(Boolean);h.length!==d.length&&b.push("all nodes must have a non-empty id"),g(h)!==h.length&&b.push("node ids must be unique");let i=e.map(a=>String(a?.id??"").trim()).filter(Boolean);i.length!==e.length&&b.push("all edges must have a non-empty id"),g(i)!==i.length&&b.push("edge ids must be unique");let j=new Set(h);for(let a of e){let c=String(a?.from??"").trim(),d=String(a?.to??"").trim();if(!c||!d){b.push(`edge ${String(a?.id??"(missing id)")} must have from/to`);continue}j.has(c)||b.push(`edge ${String(a.id)} references missing from node: ${c}`),j.has(d)||b.push(`edge ${String(a.id)} references missing to node: ${d}`)}let k=d.filter(a=>"start"===a.type),l=d.filter(a=>"end"===a.type);for(let a of(k.length||c.push("no start node found"),k.length>1&&c.push("multiple start nodes found (MVP supports this, but execution semantics may be ambiguous)"),l.length||c.push("no end node found"),f))if("cron"===a.kind){(String(a.id||"").trim()||b.push("cron trigger missing id"),String(a.expr||"").trim())?5!==String(a.expr||"").trim().split(/\s+/).filter(Boolean).length&&c.push(`cron trigger ${String(a.id)} expr is not 5-field: ${String(a.expr)}`):b.push(`cron trigger ${String(a.id||"(missing id)")} missing expr`);let d=a.tz?String(a.tz).trim():"";d&&"UTC"!==d&&!d.includes("/")&&c.push(`cron trigger ${String(a.id)} tz doesn't look like an IANA timezone: ${String(a.tz)}`)}let m=a.meta&&"object"==typeof a.meta&&!Array.isArray(a.meta)?a.meta:{},n=String(m.approvalTarget??"").trim();for(let a of d){if("human_approval"!==a.type)continue;let b=a.config&&"object"==typeof a.config&&!Array.isArray(a.config)?a.config:{},d=String(b.target??b.chatId??"").trim(),e=String(b.provider??b.channel??"").trim();d||n||c.push(`human_approval node ${String(a.id)} has no target (set node.config.target or workflow.meta.approvalTarget)`),!d||e||String(m.approvalProvider??"").trim()||c.push(`human_approval node ${String(a.id)} has a target but no provider (set node.config.provider or workflow.meta.approvalProvider)`)}return{errors:b,warnings:c}}(bo.wf):{errors:[],warnings:[]},[bo.wf]),bq=(0,c.useMemo)(()=>{let a=bo.wf;if(!a)return{missingAgentOnNodeIds:[],requiredAgentIds:[],agentIdsMissingCron:[],ok:!0};let b=(a.nodes??[]).filter(a=>"start"!==a.type&&"end"!==a.type&&"human_approval"!==a.type),c=b.filter(a=>!String((a.config&&"object"==typeof a.config&&!Array.isArray(a.config)?a.config:{}).agentId??"").trim()).map(a=>a.id),d=Array.from(new Set(b.map(a=>String((a.config&&"object"==typeof a.config&&!Array.isArray(a.config)?a.config:{}).agentId??"").trim()).filter(Boolean))),e=d.filter(a=>!a1[a]),f=0===c.length&&0===e.length;return{missingAgentOnNodeIds:c,requiredAgentIds:d,agentIdsMissingCron:e,ok:f}},[bo.wf,a1]);function br(b){let c=JSON.stringify(b,null,2)+"\n";if(X({kind:"ready",jsonText:c}),j)try{sessionStorage.setItem(q(a,i),c)}catch{}}async function bs(){if("ready"===W.kind&&bo.wf&&!bo.err&&!bp.errors.length){V(!0),Z(""),_("idle"),ab("");try{let b=await fetch("/api/teams/workflows",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({teamId:a,workflow:bo.wf})}),c=await b.json();if(!b.ok||!c.ok)throw Error(c.error||"Failed to save workflow");try{sessionStorage.removeItem(q(a,i))}catch{}if(bo.wf.triggers?.length)try{_("syncing");let b=await fetch("/api/teams/workflow-triggers",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({action:"sync",teamId:a,workflowId:bo.wf.id,triggers:bo.wf.triggers??[]})}),c=await b.json();b.ok&&c.ok?(_("success"),setTimeout(()=>_("idle"),3e3)):(_("error"),ab(c.error||"Failed to sync triggers"))}catch(a){_("error"),ab(a instanceof Error?a.message:"Failed to sync triggers")}}catch(a){Z(a instanceof Error?a.message:String(a))}finally{V(!1)}}}if("loading"===W.kind)return(0,b.jsx)("div",{className:"w-full",children:"Loading…"});if("error"===W.kind)return(0,b.jsx)("div",{className:"w-full",children:W.error});let bt=!1===l?(0,b.jsxs)("div",{className:"mx-3 mb-3 rounded-lg border border-amber-500/30 bg-amber-500/10 p-3 text-sm",children:[(0,b.jsx)("div",{className:"font-medium text-amber-200",children:"LLM support is not enabled"}),(0,b.jsxs)("div",{className:"mt-1 text-[color:var(--ck-text-secondary)]",children:["Workflow LLM nodes require the optional built-in ",(0,b.jsx)("code",{className:"px-1",children:"llm-task"})," plugin."]}),(0,b.jsxs)("div",{className:"mt-2 text-[color:var(--ck-text-secondary)]",children:["Enable it with: ",(0,b.jsx)("code",{className:"px-1",children:"openclaw plugins enable llm-task"})," then run"," ",(0,b.jsx)("code",{className:"px-1",children:"openclaw gateway restart"}),"."]})]}):null;return(0,b.jsxs)("div",{className:"flex h-full min-h-0 w-full flex-1 flex-col",children:[(0,b.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-3 px-3 py-3",children:[(0,b.jsxs)("div",{className:"flex min-w-0 items-center gap-2",children:[(0,b.jsx)("a",{href:`/teams/${encodeURIComponent(a)}?tab=workflows`,className:"rounded-lg border border-white/10 bg-white/5 px-3 py-2 text-sm font-medium text-[color:var(--ck-text-primary)] hover:bg-white/10",children:"Back"}),(0,b.jsxs)("div",{className:"min-w-0",children:[(0,b.jsxs)("div",{className:"truncate text-base font-medium text-[color:var(--ck-text-primary)]",children:[i,".workflow.json"]}),(0,b.jsxs)("div",{className:"mt-0.5 text-sm text-[color:var(--ck-text-tertiary)]",children:["Team: ",a]})]})]}),(0,b.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,b.jsxs)("div",{className:"flex overflow-hidden rounded-lg border border-white/10",children:[(0,b.jsx)("button",{type:"button",onClick:()=>T("canvas"),className:"canvas"===S?"bg-white/10 px-3 py-2 text-xs font-medium text-[color:var(--ck-text-primary)]":"bg-transparent px-3 py-2 text-xs font-medium text-[color:var(--ck-text-secondary)] hover:bg-white/5",children:"Canvas"}),(0,b.jsx)("button",{type:"button",onClick:()=>T("json"),className:"json"===S?"bg-white/10 px-3 py-2 text-xs font-medium text-[color:var(--ck-text-primary)]":"bg-transparent px-3 py-2 text-xs font-medium text-[color:var(--ck-text-secondary)] hover:bg-white/5",children:"JSON"})]}),(0,b.jsx)("input",{ref:ac,type:"file",accept:"application/json,.json",className:"hidden",onChange:async b=>{let c=b.target.files?.[0];if(b.target.value="",c){Z("");try{let b=await c.text(),d=JSON.parse(b);if(X({kind:"ready",jsonText:JSON.stringify(d,null,2)+"\n"}),j)try{sessionStorage.setItem(q(a,i),JSON.stringify(d,null,2)+"\n")}catch{}}catch(a){Z(a instanceof Error?a.message:String(a))}}}}),(0,b.jsx)("button",{type:"button",disabled:U,onClick:()=>ac.current?.click(),className:"rounded-lg border border-white/10 bg-white/5 px-3 py-2 text-sm font-medium text-[color:var(--ck-text-primary)] shadow-[var(--ck-shadow-1)] hover:bg-white/10 disabled:opacity-50",children:"Import"}),(0,b.jsx)("button",{type:"button",disabled:!bo.wf||!!bo.err||bp.errors.length>0,onClick:function(){if(!bo.wf||bo.err||bp.errors.length)return;let a=`${bo.wf.id||i}.workflow.json`,b=new Blob([JSON.stringify(bo.wf,null,2)+"\n"],{type:"application/json"}),c=URL.createObjectURL(b),d=document.createElement("a");d.href=c,d.download=a,document.body.appendChild(d),d.click(),d.remove(),URL.revokeObjectURL(c)},className:"rounded-lg border border-white/10 bg-white/5 px-3 py-2 text-sm font-medium text-[color:var(--ck-text-primary)] shadow-[var(--ck-shadow-1)] hover:bg-white/10 disabled:opacity-50",children:"Export"}),(0,b.jsx)("button",{type:"button",disabled:U||!bo.wf||!!bo.err||bp.errors.length>0,onClick:bs,className:"rounded-lg bg-[var(--ck-accent-red)] px-3 py-2 text-sm font-medium text-white shadow-[var(--ck-shadow-1)] disabled:opacity-50",children:U?"Saving…":"Save"})]})]}),bt,bo.err?(0,b.jsxs)("div",{className:"mt-3 rounded-lg border border-yellow-400/30 bg-yellow-500/10 p-3 text-sm text-yellow-100",children:["JSON parse error: ",bo.err]}):null,!bo.err&&bp.errors.length?(0,b.jsxs)("div",{className:"mt-3 rounded-lg border border-red-400/30 bg-red-500/10 p-3 text-sm text-red-100",children:[(0,b.jsx)("div",{className:"font-medium",children:"Workflow validation errors"}),(0,b.jsx)("ul",{className:"mt-2 list-disc space-y-1 pl-5",children:bp.errors.map(a=>(0,b.jsx)("li",{children:a},a))})]}):null,bo.err||bp.errors.length||!bp.warnings.length?null:(0,b.jsxs)("div",{className:"mt-3 rounded-lg border border-yellow-400/30 bg-yellow-500/10 p-3 text-sm text-yellow-100",children:[(0,b.jsx)("div",{className:"font-medium",children:"Workflow validation warnings"}),(0,b.jsx)("ul",{className:"mt-2 list-disc space-y-1 pl-5",children:bp.warnings.map(a=>(0,b.jsx)("li",{children:a},a))})]}),Y?(0,b.jsx)("div",{className:"mt-3 rounded-lg border border-red-400/30 bg-red-500/10 p-3 text-sm text-red-100",children:Y}):null,(0,b.jsxs)("div",{className:"flex min-h-0 flex-1 gap-0",children:["json"===S?(0,b.jsx)("textarea",{value:W.jsonText,onChange:b=>{let c=b.target.value;if(X({kind:"ready",jsonText:c}),j)try{sessionStorage.setItem(q(a,i),c)}catch{}},className:"h-full min-h-0 w-full flex-1 resize-none rounded-lg border border-white/10 bg-white/5 p-3 font-mono text-xs text-[color:var(--ck-text-primary)]"}):(0,b.jsx)("div",{ref:ah,className:"relative h-full min-h-0 w-full flex-1 overflow-auto bg-white/5",onWheel:a=>{if(!a.ctrlKey&&!a.metaKey)return;a.preventDefault();let b=a.deltaY>0?-1:1;ag(a=>Math.max(.5,Math.min(2.5,Math.round((a+.1*b)*10)/10)))},onClick:a=>{if("add-node"!==am.kind)return;let b=bo.wf;if(!b)return;let c=ah.current;if(!c)return;let d=a.target;if(d&&d.closest("[data-wf-node='1']"))return;let e=c.getBoundingClientRect(),f=(a.clientX-e.left+c.scrollLeft)/af,g=(a.clientY-e.top+c.scrollTop)/af,i=am.nodeType.replace(/[^a-z0-9_\-]/gi,"_"),j=new Set(b.nodes.map(a=>a.id)),k=1,l=`${i}_${k}`;for(;j.has(l);)k++,l=`${i}_${k}`;let m=Math.max(0,f-90),n=Math.max(0,g-24),o=am.nodeType in h?{...h[am.nodeType].defaultConfig}:{},p={id:l,type:am.nodeType,name:l,x:m,y:n,config:o};br({...b,nodes:[...b.nodes,p]}),aj(l),an({kind:"select"})},children:(0,b.jsxs)("div",{className:"relative",style:{width:2200*af,height:1200*af},children:[(0,b.jsxs)("div",{className:ad?"absolute left-3 top-3 z-20 w-[44px] overflow-hidden rounded-lg border border-white/10 bg-black/40 p-2 backdrop-blur":"absolute left-3 top-3 z-20 w-[260px] rounded-lg border border-white/10 bg-black/40 p-2 backdrop-blur",children:[(0,b.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,b.jsx)("div",{className:ad?"hidden":"text-[10px] font-medium uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"Tools"}),(0,b.jsxs)("div",{className:"flex items-center gap-2",children:[(0,b.jsxs)("div",{className:ad?"hidden":"flex items-center gap-1",children:[(0,b.jsx)("button",{type:"button",onClick:()=>ag(a=>Math.max(.5,Math.round((a-.1)*10)/10)),className:"rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-[10px] text-[color:var(--ck-text-secondary)] hover:bg-white/10",title:"Zoom out (Ctrl/Cmd+wheel)",children:"-"}),(0,b.jsxs)("div",{className:"min-w-[42px] text-center text-[10px] text-[color:var(--ck-text-tertiary)]",children:[Math.round(100*af),"%"]}),(0,b.jsx)("button",{type:"button",onClick:()=>ag(a=>Math.min(2.5,Math.round((a+.1)*10)/10)),className:"rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-[10px] text-[color:var(--ck-text-secondary)] hover:bg-white/10",title:"Zoom in (Ctrl/Cmd+wheel)",children:"+"})]}),(0,b.jsx)("button",{type:"button",onClick:()=>ae(a=>!a),className:"rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-[10px] text-[color:var(--ck-text-secondary)] hover:bg-white/10",title:ad?"Expand":"Collapse",children:ad?">":"<"})]})]}),ad?(0,b.jsx)("div",{className:"mt-2 flex flex-col items-center gap-2",children:[{key:"select",label:"Select",active:"select"===am.kind,onClick:()=>{an({kind:"select"}),ap("")},icon:(0,b.jsx)("svg",{viewBox:"0 0 24 24",className:"h-4 w-4",fill:"none","aria-hidden":"true",children:(0,b.jsx)("path",{d:"M5 4l7 16 2-7 7-2L5 4Z",stroke:"currentColor",strokeWidth:"1.6",strokeLinejoin:"round"})})},{key:"connect",label:"Connect",active:"connect"===am.kind,onClick:()=>{an(a=>"connect"===a.kind?{kind:"select"}:{kind:"connect"}),ap("")},icon:(0,b.jsxs)("svg",{viewBox:"0 0 24 24",className:"h-4 w-4",fill:"none","aria-hidden":"true",children:[(0,b.jsx)("path",{d:"M10 13a5 5 0 0 1 0-7l1.2-1.2a5 5 0 0 1 7 7L17 12",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round"}),(0,b.jsx)("path",{d:"M14 11a5 5 0 0 1 0 7L12.8 19.2a5 5 0 1 1-7-7L7 12",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round"})]})},{key:"llm",label:"LLM",active:"add-node"===am.kind&&"llm"===am.nodeType,onClick:()=>{an({kind:"add-node",nodeType:"llm"}),ap("")},icon:(0,b.jsx)("svg",{viewBox:"0 0 24 24",className:"h-4 w-4",fill:"none","aria-hidden":"true",children:(0,b.jsx)("path",{d:"M12 2l1.5 6.5L20 10l-6.5 1.5L12 18l-1.5-6.5L4 10l6.5-1.5L12 2Z",stroke:"currentColor",strokeWidth:"1.6",strokeLinejoin:"round"})})},{key:"tool",label:"Tool",active:"add-node"===am.kind&&"tool"===am.nodeType,onClick:()=>{an({kind:"add-node",nodeType:"tool"}),ap("")},icon:(0,b.jsxs)("svg",{viewBox:"0 0 24 24",className:"h-4 w-4",fill:"none","aria-hidden":"true",children:[(0,b.jsx)("path",{d:"M14.5 7.5l2 2-8.5 8.5H6v-2l8.5-8.5Z",stroke:"currentColor",strokeWidth:"1.6",strokeLinejoin:"round"}),(0,b.jsx)("path",{d:"M12 6a4 4 0 0 0-5 5l3-3 2 2 3-3A4 4 0 0 0 12 6Z",stroke:"currentColor",strokeWidth:"1.6",strokeLinejoin:"round"})]})},{key:"condition",label:"If",active:"add-node"===am.kind&&"condition"===am.nodeType,onClick:()=>{an({kind:"add-node",nodeType:"condition"}),ap("")},icon:(0,b.jsxs)("svg",{viewBox:"0 0 24 24",className:"h-4 w-4",fill:"none","aria-hidden":"true",children:[(0,b.jsx)("path",{d:"M7 4v7a3 3 0 0 0 3 3h7",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round"}),(0,b.jsx)("path",{d:"M17 10l3 3-3 3",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round"})]})},{key:"delay",label:"Delay",active:"add-node"===am.kind&&"delay"===am.nodeType,onClick:()=>{an({kind:"add-node",nodeType:"delay"}),ap("")},icon:(0,b.jsxs)("svg",{viewBox:"0 0 24 24",className:"h-4 w-4",fill:"none","aria-hidden":"true",children:[(0,b.jsx)("path",{d:"M12 7v5l3 2",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round"}),(0,b.jsx)("path",{d:"M21 12a9 9 0 1 1-9-9",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round"})]})},{key:"approval",label:"Approval",active:"add-node"===am.kind&&"human_approval"===am.nodeType,onClick:()=>{an({kind:"add-node",nodeType:"human_approval"}),ap("")},icon:(0,b.jsx)("svg",{viewBox:"0 0 24 24",className:"h-4 w-4",fill:"none","aria-hidden":"true",children:(0,b.jsx)("path",{d:"M20 6 9 17l-5-5",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round"})})},{key:"end",label:"End",active:"add-node"===am.kind&&"end"===am.nodeType,onClick:()=>{an({kind:"add-node",nodeType:"end"}),ap("")},icon:(0,b.jsx)("svg",{viewBox:"0 0 24 24",className:"h-4 w-4",fill:"none","aria-hidden":"true",children:(0,b.jsx)("path",{d:"M7 7h10v10H7V7Z",stroke:"currentColor",strokeWidth:"1.6",strokeLinejoin:"round"})})},{key:"media-image",label:"Image",active:"add-node"===am.kind&&"media-image"===am.nodeType,onClick:()=>{an({kind:"add-node",nodeType:"media-image"}),ap("")},icon:(0,b.jsxs)("svg",{viewBox:"0 0 24 24",className:"h-4 w-4",fill:"none","aria-hidden":"true",children:[(0,b.jsx)("path",{d:"M14.5 4h-5L7 6.5 4.5 9v6L7 17.5 9.5 20h5L17 17.5 19.5 15V9L17 6.5 14.5 4Z",stroke:"currentColor",strokeWidth:"1.6",strokeLinejoin:"round"}),(0,b.jsx)("path",{d:"M9 10a1 1 0 1 0 0-2 1 1 0 0 0 0 2Z",fill:"currentColor"}),(0,b.jsx)("path",{d:"m4.5 15 3.5-3.5L11 14l3.5-3.5 4 4",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round"})]})},{key:"media-video",label:"Video",active:"add-node"===am.kind&&"media-video"===am.nodeType,onClick:()=>{an({kind:"add-node",nodeType:"media-video"}),ap("")},icon:(0,b.jsxs)("svg",{viewBox:"0 0 24 24",className:"h-4 w-4",fill:"none","aria-hidden":"true",children:[(0,b.jsx)("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round"}),(0,b.jsx)("path",{d:"M14 2v6h6",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round"}),(0,b.jsx)("path",{d:"M10 12l4.5 2.5-4.5 2.5v-5z",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round"})]})},{key:"handoff",label:"Handoff",active:"add-node"===am.kind&&"handoff"===am.nodeType,onClick:()=>{an({kind:"add-node",nodeType:"handoff"}),ap("")},icon:(0,b.jsxs)("svg",{viewBox:"0 0 24 24",className:"h-4 w-4",fill:"none","aria-hidden":"true",children:[(0,b.jsx)("path",{d:"M5 12h14",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round"}),(0,b.jsx)("path",{d:"M13 6l6 6-6 6",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round"}),(0,b.jsx)("path",{d:"M3 6v12",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round"})]})}].map(a=>(0,b.jsx)("button",{type:"button",onClick:a.onClick,className:a.active?"flex h-8 w-8 items-center justify-center rounded-lg bg-white/10 text-[color:var(--ck-text-primary)]":"flex h-8 w-8 items-center justify-center rounded-lg border border-white/10 bg-white/5 text-[color:var(--ck-text-secondary)] hover:bg-white/10",title:a.label,"aria-label":a.label,children:a.icon},a.key))}):(0,b.jsxs)("div",{className:"mt-2 grid grid-cols-2 gap-2",children:[(0,b.jsx)("button",{type:"button",onClick:()=>{an({kind:"select"}),ap("")},className:"select"===am.kind?"rounded-lg bg-white/10 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]":"rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-secondary)] hover:bg-white/10",children:"Select"}),(0,b.jsx)("button",{type:"button",onClick:()=>{an({kind:"connect"}),ap("")},className:"connect"===am.kind?"rounded-lg bg-white/10 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]":"rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-secondary)] hover:bg-white/10",title:"Click a node, then click another node to create an edge",children:"Connect"}),[{t:"llm",label:"LLM"},{t:"tool",label:"Tool"},{t:"condition",label:"If"},{t:"delay",label:"Delay"},{t:"human_approval",label:"Approve"},{t:"media-image",label:"🎨 Image"},{t:"media-video",label:"🎬 Video"},{t:"handoff",label:"↗ Handoff"},{t:"end",label:"End"}].map(a=>(0,b.jsxs)("button",{type:"button",onClick:()=>{an({kind:"add-node",nodeType:a.t}),ap("")},className:"add-node"===am.kind&&am.nodeType===a.t?"rounded-lg bg-white/10 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]":"rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-secondary)] hover:bg-white/10",title:"Select tool, then click on the canvas to place",children:["+ ",a.label]},a.t))]}),!ad&&"connect"===am.kind&&ao?(0,b.jsxs)("div",{className:"mt-2 text-xs text-[color:var(--ck-text-secondary)]",children:["Connecting from: ",(0,b.jsx)("span",{className:"font-mono",children:ao})]}):null,ad||"add-node"!==am.kind?null:(0,b.jsxs)("div",{className:"mt-2 text-xs text-[color:var(--ck-text-secondary)]",children:["Click on the canvas to place a ",(0,b.jsx)("span",{className:"font-mono",children:am.nodeType})," node."]}),(0,b.jsxs)("div",{className:"mt-3 border-t border-white/10 pt-3",children:[(0,b.jsxs)("div",{className:ad?"hidden":"flex items-center justify-between gap-2",children:[(0,b.jsx)("div",{className:"text-[10px] font-medium uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"Agents"}),(0,b.jsx)("div",{className:"text-[10px] text-[color:var(--ck-text-tertiary)]",children:"drag → node"})]}),ad?(0,b.jsx)("button",{type:"button",onClick:()=>ae(!1),className:"mt-2 flex h-8 w-8 items-center justify-center rounded-lg border border-white/10 bg-white/5 text-[color:var(--ck-text-secondary)] hover:bg-white/10",title:"Expand to see agents","aria-label":"Expand to see agents",children:(0,b.jsxs)("svg",{viewBox:"0 0 24 24",className:"h-4 w-4",fill:"none","aria-hidden":"true",children:[(0,b.jsx)("path",{d:"M16 11a4 4 0 1 0-8 0",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round"}),(0,b.jsx)("path",{d:"M4 20a8 8 0 0 1 16 0",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round"})]})}):(0,b.jsxs)(b.Fragment,{children:[as?(0,b.jsx)("div",{className:"mt-1 text-[11px] text-red-200",children:as}):null,(0,b.jsx)("div",{className:"mt-2 max-h-[140px] space-y-1 overflow-auto",children:aq.length?aq.map(c=>(0,b.jsx)("div",{draggable:!0,onDragStart:a=>{a.dataTransfer.setData("text/plain",c.id),a.dataTransfer.effectAllowed="copy"},className:"cursor-grab rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-secondary)] hover:bg-white/10",title:c.id,children:c.identityName?c.identityName:c.id.replace(`${a}-`,"")},c.id)):(0,b.jsx)("div",{className:"text-xs text-[color:var(--ck-text-tertiary)]",children:"No team agents found."})})]})]})]}),(0,b.jsxs)("div",{className:"relative h-[1200px] w-[2200px]",style:{transform:`scale(${af})`,transformOrigin:"0 0"},children:[(0,b.jsx)("svg",{className:"pointer-events-none absolute inset-0 -z-10",width:2200,height:1200,style:{overflow:"visible"},children:(bo.wf?.edges??[]).map(a=>{let c=bo.wf;if(!c)return null;let d=c.nodes.find(b=>b.id===a.from),e=c.nodes.find(b=>b.id===a.to);if(!d||!e)return null;let f=("number"==typeof d.x?d.x:80)+90,g=("number"==typeof d.y?d.y:80)+24,h=("number"==typeof e.x?e.x:80)+90,i=("number"==typeof e.y?e.y:80)+24;return(0,b.jsx)("line",{x1:f,y1:g,x2:h,y2:i,stroke:"rgba(255,255,255,0.35)",strokeWidth:3},a.id)})}),(bo.wf?.nodes??[]).map((c,d)=>{let e="number"==typeof c.x?c.x:80+220*d,f="number"==typeof c.y?c.y:80,g=ai===c.id;return(0,b.jsxs)("div",{role:"button",tabIndex:0,"data-wf-node":"1",draggable:"select"===am.kind||"connect"===am.kind,onDragStart:a=>{"select"===am.kind&&a.dataTransfer.setData("text/plain","")},onDragOver:a=>{a.dataTransfer.types.includes("text/plain")&&a.preventDefault()},onDrop:a=>{let b=bo.wf;if(!b)return;a.preventDefault(),a.stopPropagation();let d=String(a.dataTransfer.getData("text/plain")||"").trim();if(!d)return;let e=b.nodes.map(a=>{if(a.id!==c.id)return a;let b=a.config&&"object"==typeof a.config&&!Array.isArray(a.config)?a.config:{};return{...a,config:{...b,agentId:d}}});br({...b,nodes:e}),aj(c.id)},onClick:a=>{a.stopPropagation();let b=bo.wf;if("connect"===am.kind){if(!b)return;if(!ao){ap(c.id),aj(c.id);return}let a=c.id;if(ap(""),!ao||!a||ao===a||(b.edges??[]).some(b=>b.from===ao&&b.to===a))return;let d=`e${Date.now()}`;br({...b,edges:[...b.edges??[],{id:d,from:ao,to:a}]}),an({kind:"select"});return}aj(c.id)},onPointerDown:a=>{if("add-node"===am.kind||0!==a.button)return;let b=ah.current;if(!b)return;let d=b.getBoundingClientRect();aj(c.id);try{a.currentTarget.setPointerCapture(a.pointerId)}catch{}a.preventDefault();let g=(a.clientX-d.left+b.scrollLeft)/af,h=(a.clientY-d.top+b.scrollTop)/af;al({nodeId:c.id,dx:g-e,dy:h-f})},onPointerUp:a=>{try{a.currentTarget.releasePointerCapture(a.pointerId)}catch{}al(null)},onPointerMove:a=>{if(!ak||ak.nodeId!==c.id)return;let b=bo.wf;if(!b)return;let d=ah.current;if(!d)return;let e=d.getBoundingClientRect(),f=(a.clientX-e.left+d.scrollLeft)/af,g=(a.clientY-e.top+d.scrollTop)/af,h=f-ak.dx,i=g-ak.dy,j=b.nodes.map(a=>a.id===c.id?{...a,x:h,y:i}:a);X({kind:"ready",jsonText:JSON.stringify({...b,nodes:j},null,2)+"\n"})},className:g?"absolute z-10 cursor-grab rounded-lg border border-white/25 bg-white/10 px-3 py-2 text-xs text-[color:var(--ck-text-primary)] shadow-[var(--ck-shadow-1)]":"absolute z-10 cursor-grab rounded-lg border border-white/10 bg-white/5 px-3 py-2 text-xs text-[color:var(--ck-text-secondary)] hover:bg-white/10",style:{left:e,top:f,width:180},children:[(0,b.jsxs)("div",{className:"flex items-center gap-2",children:[c.type in h&&(0,b.jsx)("span",{className:"text-lg",children:"media-image"===c.type?"🎨":"🎬"}),"handoff"===c.type&&(0,b.jsx)("span",{className:"text-lg",children:"↗"}),(0,b.jsx)("div",{className:"font-medium text-[color:var(--ck-text-primary)]",children:c.name||c.id})]}),(0,b.jsx)("div",{className:"mt-0.5 text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:c.type}),(()=>{let d=c.config&&"object"==typeof c.config&&!Array.isArray(c.config)?c.config:null;if(c.type in h&&d){let a=String(d.prompt??"").trim(),c=String(d.provider??"auto");return(0,b.jsxs)("div",{className:"mt-1 space-y-0.5",children:[a&&(0,b.jsxs)("div",{className:"text-[10px] text-[color:var(--ck-text-secondary)] truncate",title:a,children:['"',a.length>40?a.substring(0,40)+"...":a,'"']}),(0,b.jsxs)("div",{className:"text-[10px] text-[color:var(--ck-text-tertiary)]",children:["Provider: ",c]})]})}if("handoff"===c.type&&d){let a=String(d.targetTeamId??"").trim(),c=String(d.targetWorkflowId??"").trim(),e=String(d.mode??"fire-and-forget");return a?(0,b.jsxs)("div",{className:"mt-1 text-[10px] text-[color:var(--ck-text-secondary)]",children:["→ ",a,c?` / ${c}`:"","wait-for-completion"===e?(0,b.jsx)("span",{className:"ml-1 text-yellow-400",title:"Waits for target to complete",children:"⏳"}):null]}):null}let e=d?String(d.agentId??"").trim():"";if(!e)return null;let f=e.replace(`${a}-`,"");return(0,b.jsxs)("div",{className:"mt-1 text-[10px] text-[color:var(--ck-text-secondary)]",children:["Agent: ",f]})})()]},c.id)}),(()=>{let c,d,e,f,g,i,j,l,m,n,p,q,r=bo.wf;if(!r||!ai)return null;let s=r.nodes.find(a=>a.id===ai);if(!s)return null;let t="number"==typeof s.x?s.x:80,u="number"==typeof s.y?s.y:80,v=s.config&&"object"==typeof s.config&&!Array.isArray(s.config)?s.config:{},w=String(v.agentId??"").trim(),x=String(v.model??"").trim();return(0,b.jsxs)("div",{className:"absolute z-10 w-[320px] rounded-lg border border-white/15 bg-black/60 p-3 shadow-[var(--ck-shadow-1)] backdrop-blur",style:{left:t+200,top:u},children:[(0,b.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,b.jsx)("div",{className:"text-xs font-medium text-[color:var(--ck-text-primary)]",children:s.name||s.id}),(0,b.jsx)("button",{type:"button",onClick:()=>aj(""),className:"text-[10px] text-[color:var(--ck-text-tertiary)] hover:text-[color:var(--ck-text-primary)]",children:"Close"})]}),(0,b.jsxs)("div",{className:"mt-2 space-y-2",children:[(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"name"}),(0,b.jsx)("input",{value:String(s.name??""),onChange:a=>{let b=a.target.value;br({...r,nodes:r.nodes.map(a=>a.id===s.id?{...a,name:b}:a)})},className:"mt-1 w-full rounded-lg border border-white/10 bg-black/30 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",placeholder:"Optional"})]}),(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"type"}),(0,b.jsxs)("select",{value:s.type,onChange:a=>{let b=a.target.value;br({...r,nodes:r.nodes.map(a=>a.id===s.id?{...a,type:b}:a)})},className:"mt-1 w-full rounded-lg border border-white/10 bg-black/30 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",children:[(0,b.jsx)("option",{value:"start",children:"start"}),(0,b.jsx)("option",{value:"end",children:"end"}),(0,b.jsx)("option",{value:"llm",children:"llm"}),(0,b.jsx)("option",{value:"tool",children:"tool"}),(0,b.jsx)("option",{value:"condition",children:"condition"}),(0,b.jsx)("option",{value:"delay",children:"delay"}),(0,b.jsx)("option",{value:"human_approval",children:"human_approval"}),(0,b.jsx)("option",{value:"media-image",children:"media-image"}),(0,b.jsx)("option",{value:"media-video",children:"media-video"}),(0,b.jsx)("option",{value:"handoff",children:"handoff"})]})]}),(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"agentId"}),(0,b.jsx)("input",{value:w,onChange:a=>{let b=String(a.target.value||"").trim(),c={...v,...b?{agentId:b}:{}};b||delete c.agentId,br({...r,nodes:r.nodes.map(a=>a.id===s.id?{...a,config:c}:a)})},className:"mt-1 w-full rounded-lg border border-white/10 bg-black/30 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",placeholder:"(drag an agent onto the node or type)"})]}),"llm"===s.type?(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"model"}),(0,b.jsxs)("select",{value:x,onChange:a=>{let b=String(a.target.value||"").trim(),c={...v,...b?{model:b}:{}};b||delete c.model,br({...r,nodes:r.nodes.map(a=>a.id===s.id?{...a,config:c}:a)})},className:"mt-1 w-full rounded-lg border border-white/10 bg-black/30 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",children:[(0,b.jsx)("option",{value:"",children:"Default (inherit global)"}),ay.map(a=>(0,b.jsx)("option",{value:a,children:a},a))]}),aA?(0,b.jsxs)("div",{className:"mt-1 text-[10px] text-amber-300",children:["Could not load model list: ",aA]}):null]}):null,"human_approval"===s.type?(0,b.jsxs)("div",{className:"rounded-lg border border-white/10 bg-white/5 p-2",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"approval config"}),(0,b.jsxs)("div",{className:"mt-2 space-y-2",children:[(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"provider"}),(0,b.jsx)("input",{value:String(v.provider??""),onChange:a=>{let b=String(a.target.value||"").trim(),c={...v,...b?{provider:b}:{}};b||delete c.provider,br({...r,nodes:r.nodes.map(a=>a.id===s.id?{...a,config:c}:a)})},className:"mt-1 w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",placeholder:"telegram"})]}),(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"target"}),(0,b.jsx)("input",{value:String(v.target??""),onChange:a=>{let b=String(a.target.value||"").trim(),c={...v,...b?{target:b}:{}};b||delete c.target,br({...r,nodes:r.nodes.map(a=>a.id===s.id?{...a,config:c}:a)})},className:"mt-1 w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",placeholder:"(e.g. Telegram chat id)"}),(0,b.jsx)("div",{className:"mt-1 text-[10px] text-[color:var(--ck-text-tertiary)]",children:"Overrides workflow-level default when set."})]}),(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"messageTemplate (optional)"}),(0,b.jsx)(o,{value:String(v.messageTemplate??""),workflow:r,currentNodeId:s.id,onChangeValue:a=>{let b={...v,...a.trim()?{messageTemplate:a}:{}};a.trim()||delete b.messageTemplate,br({...r,nodes:r.nodes.map(a=>a.id===s.id?{...a,config:b}:a)})},className:"mt-1 h-[70px] w-full resize-none rounded-lg border border-white/10 bg-white/5 p-2 pr-12 font-mono text-[10px] text-[color:var(--ck-text-primary)]",placeholder:"Approval needed for {{workflowName}} (run {{runId}})",spellCheck:!1}),(0,b.jsxs)("div",{className:"mt-1 text-[10px] text-[color:var(--ck-text-tertiary)]",children:["Vars: ","{{workflowName}}",", ","{{workflowId}}",", ","{{runId}}",", ","{{nodeId}}"]})]})]})]}):null,s.type in h?(0,b.jsxs)("div",{className:"rounded-lg border border-white/10 bg-white/5 p-2",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"Media Generation"}),(0,b.jsx)("div",{className:"mt-2",children:(0,b.jsx)(k,{config:{mediaType:"image",provider:"auto",prompt:"",...s.config||{}},onChange:a=>{br({...r,nodes:r.nodes.map(b=>b.id===s.id?{...b,config:a}:b)})},teamId:a,workflow:r,workflowNodeIds:r.nodes.map(a=>a.id),workflowEdges:(r.edges??[]).map(a=>({from:a.from,to:a.to})),currentNodeId:s.id})})]}):null,"llm"===s.type?(0,b.jsxs)("div",{className:"space-y-2",children:[(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"prompt"}),(0,b.jsx)(o,{value:String(v.promptTemplate??""),workflow:r,currentNodeId:s.id,onChangeValue:a=>{let b={...v,promptTemplate:a};br({...r,nodes:r.nodes.map(a=>a.id===s.id?{...a,config:b}:a)})},className:"mt-1 min-h-[200px] w-full resize-y rounded-lg border border-white/10 bg-black/30 p-2 pr-12 font-mono text-xs text-[color:var(--ck-text-primary)]",placeholder:"What should this node do? Use {{nodeId.output}} to reference upstream node outputs.",spellCheck:!1})]}),(0,b.jsxs)("div",{children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"output fields (optional)"}),(0,b.jsx)("div",{className:"text-[9px] text-[color:var(--ck-text-secondary)] mb-2",children:"Define the structure of what this node should produce"}),(c=v.outputFields||[],(0,b.jsxs)("div",{className:"space-y-1",children:[c.map((a,d)=>(0,b.jsxs)("div",{className:"flex items-center gap-2",children:[(0,b.jsx)("input",{value:a.name,onChange:b=>{let e=[...c];e[d]={...a,name:b.target.value};let f={...v,outputFields:e};br({...r,nodes:r.nodes.map(a=>a.id===s.id?{...a,config:f}:a)})},className:"flex-1 rounded-lg border border-white/10 bg-black/30 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",placeholder:"Field name"}),(0,b.jsxs)("select",{value:a.type,onChange:b=>{let e=b.target.value,f=[...c];f[d]={...a,type:e};let g={...v,outputFields:f};br({...r,nodes:r.nodes.map(a=>a.id===s.id?{...a,config:g}:a)})},className:"rounded-lg border border-white/10 bg-black/30 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",children:[(0,b.jsx)("option",{value:"text",children:"text"}),(0,b.jsx)("option",{value:"list",children:"list"}),(0,b.jsx)("option",{value:"json",children:"json"})]}),(0,b.jsx)("button",{type:"button",onClick:()=>{let a=c.filter((a,b)=>b!==d),b={...v};a.length>0?b.outputFields=a:delete b.outputFields,br({...r,nodes:r.nodes.map(a=>a.id===s.id?{...a,config:b}:a)})},className:"text-xs text-[color:var(--ck-text-tertiary)] hover:text-[color:var(--ck-text-primary)]",children:"×"})]},d)),(0,b.jsx)("button",{type:"button",onClick:()=>{let a=[...c,{name:"",type:"text"}],b={...v,outputFields:a};br({...r,nodes:r.nodes.map(a=>a.id===s.id?{...a,config:b}:a)})},className:"text-xs text-[color:var(--ck-text-secondary)] hover:text-[color:var(--ck-text-primary)]",children:"+ Add field"})]}))]}),(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"timeout (seconds)"}),(0,b.jsx)("input",{type:"number",value:v.timeoutMs?String(Number(v.timeoutMs)/1e3):"",onChange:a=>{let b=a.target.value?Number(a.target.value):null,c={...v};b&&b>0?c.timeoutMs=1e3*b:delete c.timeoutMs,br({...r,nodes:r.nodes.map(a=>a.id===s.id?{...a,config:c}:a)})},className:"mt-1 w-24 rounded-lg border border-white/10 bg-black/30 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",placeholder:"120",min:"1"})]})]}):null,"handoff"===s.type?(d=String(v.targetTeamId??""),e=String(v.targetWorkflowId??""),f=v.variableMapping||{},g=String(v.mode??"fire-and-forget"),j=aI[i=String(f.kitchenTeamId??"").includes("{{")?a:String(f.kitchenTeamId??a)]||[],l=!!aK[i],m=String(f.integrationIds??f.integrationId??"").split(",").map(a=>a.trim()).filter(Boolean),n=aE[d]||[],p=e.toLowerCase().includes("instagram")||Object.prototype.hasOwnProperty.call(f,"integrationId")||Object.prototype.hasOwnProperty.call(f,"integrationIds"),q=a=>{let b={...v,...a};br({...r,nodes:r.nodes.map(a=>a.id===s.id?{...a,config:b}:a)})},0!==aC.length||aG||(async()=>{try{let a=await fetch("/api/teams/list"),b=await a.json();b.ok&&aD(b.teamIds)}catch{}})(),d&&!aE[d]&&(async()=>{try{let a=await fetch(`/api/teams/workflows?teamId=${encodeURIComponent(d)}`),b=await a.json();b.ok&&b.files&&aF(a=>({...a,[d]:b.files.map(a=>({id:a.replace(/\.workflow\.json$/,"")}))}))}catch{}})(),p&&i&&!aI[i]&&!aK[i]&&(async()=>{aL(a=>({...a,[i]:!0}));try{let a=(()=>{try{return JSON.parse(localStorage.getItem(`ck-postiz-${i}`)||"{}").apiKey||""}catch{return""}})(),b=await fetch(`/api/plugins/marketing/drivers?teamId=${encodeURIComponent(i)}`,{headers:a?{"x-postiz-api-key":a}:{}}),c=((await b.json()).drivers||[]).filter(a=>"instagram"===a.platform&&"postiz"===a.backend&&a.integrationId).map(a=>({integrationId:String(a.integrationId),displayName:String(a.displayName||"Instagram"),username:a.username?String(a.username):void 0}));aJ(a=>({...a,[i]:c}))}catch{}aL(a=>({...a,[i]:!1}))})(),(0,b.jsxs)("div",{className:"rounded-lg border border-white/10 bg-white/5 p-2 space-y-2",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"handoff config"}),(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"mode"}),(0,b.jsxs)("select",{value:g,onChange:a=>q({mode:"fire-and-forget"===a.target.value?void 0:a.target.value}),className:"mt-1 w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",children:[(0,b.jsx)("option",{value:"fire-and-forget",children:"Fire & Forget"}),(0,b.jsx)("option",{value:"wait-for-completion",children:"Wait for Completion"})]})]}),(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"target team"}),(0,b.jsxs)("select",{value:d,onChange:a=>{q({targetTeamId:a.target.value||void 0,targetWorkflowId:void 0})},className:"mt-1 w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",children:[(0,b.jsx)("option",{value:"",children:"— Select —"}),aC.map(c=>(0,b.jsxs)("option",{value:c,children:[c,c===a?" (current)":""]},c))]})]}),d?(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"target workflow"}),(0,b.jsxs)("select",{value:e,onChange:a=>q({targetWorkflowId:a.target.value||void 0}),className:"mt-1 w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",children:[(0,b.jsx)("option",{value:"",children:"— Select —"}),n.map(a=>(0,b.jsx)("option",{value:a.id,children:a.name||a.id},a.id))]})]}):null,p&&j.length>0?(0,b.jsxs)("div",{children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"instagram accounts"}),(0,b.jsx)("div",{className:"mt-1 space-y-1",children:j.map(a=>{let c=m.includes(a.integrationId);return(0,b.jsxs)("label",{className:"flex items-center gap-2 cursor-pointer rounded-lg border border-white/10 bg-white/5 px-2 py-1 hover:bg-white/10",children:[(0,b.jsx)("input",{type:"checkbox",checked:c,onChange:()=>{let b=c?m.filter(b=>b!==a.integrationId):[...m,a.integrationId],d={...f};delete d.integrationId,b.length>0?d.integrationIds=b.join(","):delete d.integrationIds,q({variableMapping:d})},className:"accent-[var(--ck-accent-red)]"}),(0,b.jsxs)("div",{children:[(0,b.jsx)("div",{className:"text-xs text-[color:var(--ck-text-primary)]",children:a.displayName}),a.username?(0,b.jsx)("div",{className:"text-[10px] text-[color:var(--ck-text-tertiary)]",children:a.username}):null]})]},a.integrationId)})})]}):null,p&&l?(0,b.jsx)("div",{className:"text-[10px] text-[color:var(--ck-text-tertiary)]",children:"Loading accounts…"}):null]})):null,(0,b.jsxs)("div",{children:[(0,b.jsxs)("button",{type:"button",onClick:()=>{let a=aM[s.id]??"llm"!==s.type;aN({...aM,[s.id]:!a})},className:"mb-2 text-[10px] text-[color:var(--ck-text-tertiary)] hover:text-[color:var(--ck-text-primary)]",children:[aM[s.id]??"llm"!==s.type?"Hide":"Show"," raw config"]}),aM[s.id]??"llm"!==s.type?(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"config (json)"}),(0,b.jsx)("textarea",{value:JSON.stringify(v,null,2),onChange:a=>{try{let b=JSON.parse(a.target.value);if(!b||"object"!=typeof b||Array.isArray(b))return;br({...r,nodes:r.nodes.map(a=>a.id===s.id?{...a,config:b}:a)})}catch{}},className:"mt-1 h-[140px] w-full resize-none rounded-lg border border-white/10 bg-black/30 p-2 font-mono text-[10px] text-[color:var(--ck-text-primary)]",spellCheck:!1}),(0,b.jsx)("div",{className:"mt-1 text-[10px] text-[color:var(--ck-text-tertiary)]",children:"(Edits apply when JSON is valid.)"})]}):null]})]})]})})()]})]})}),(0,b.jsx)("div",{className:"w-[380px] shrink-0 overflow-auto p-3 text-sm",children:(0,b.jsx)("div",{className:"space-y-3",children:bo.wf?(K=String((J=bo.wf).timezone??"").trim()||"UTC",L=J.triggers??[],N=String((M=J.meta&&"object"==typeof J.meta&&!Array.isArray(J.meta)?J.meta:{}).approvalBindingId??"").trim(),O=String(M.approvalProvider??"telegram").trim()||"telegram",P=String(M.approvalTarget??"").trim(),Q=[{label:"(no preset)",expr:""},{label:"Weekdays 09:00 local",expr:"0 9 * * 1-5"},{label:"Mon/Wed/Fri 09:00 local",expr:"0 9 * * 1,3,5"},{label:"Daily 08:00 local",expr:"0 8 * * *"},{label:"Daily 12:00 local",expr:"0 12 * * *"},{label:"Mon 09:30 local",expr:"30 9 * * 1"}],(0,b.jsxs)("div",{className:"space-y-3",children:[(0,b.jsxs)("details",{open:!0,className:"rounded-lg border border-white/10 bg-white/5",children:[(0,b.jsx)("summary",{className:"cursor-pointer list-none px-3 py-2 text-sm font-medium text-[color:var(--ck-text-primary)]",children:"Workflow"}),(0,b.jsx)("div",{className:"px-3 pb-3",children:(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[11px] font-medium text-[color:var(--ck-text-tertiary)]",children:"Timezone"}),(0,b.jsx)("input",{value:K,onChange:a=>{let b=String(a.target.value||"").trim()||"UTC";br({...J,timezone:b})},className:"mt-1 w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-sm text-[color:var(--ck-text-primary)]",placeholder:"America/New_York"})]})})]}),(0,b.jsxs)("details",{open:!0,className:"rounded-lg border border-white/10 bg-white/5",children:[(0,b.jsx)("summary",{className:"cursor-pointer list-none px-3 py-2 text-sm font-medium text-[color:var(--ck-text-primary)]",children:"Approval Channel"}),(0,b.jsxs)("div",{className:"px-3 pb-3 space-y-2",children:[(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"binding (recommended)"}),(0,b.jsxs)("select",{value:N,onChange:a=>{let b=String(a.target.value||"").trim(),c=au.find(a=>a.id===b);c?br({...J,meta:{...M,approvalBindingId:c.id,approvalProvider:c.channel,approvalTarget:c.target},nodes:J.nodes.map(a=>"human_approval"===a.type?{...a,config:{...a.config&&"object"==typeof a.config&&!Array.isArray(a.config)?a.config:{},approvalBindingId:c.id,provider:c.channel,target:c.target}}:a)}):br({...J,meta:{...M,approvalBindingId:""},nodes:J.nodes.map(a=>"human_approval"===a.type?{...a,config:{...a.config&&"object"==typeof a.config&&!Array.isArray(a.config)?a.config:{},approvalBindingId:""}}:a)})},className:"mt-1 w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",children:[(0,b.jsx)("option",{value:"",children:"(manual)"}),au.map(a=>(0,b.jsx)("option",{value:a.id,children:a.label},a.id))]}),aO?(0,b.jsxs)("div",{className:"mt-1 text-[10px] text-yellow-200",children:["Kitchen looks out of date. Run ",(0,b.jsx)("code",{className:"font-mono",children:"openclaw plugins update"})," then",(0,b.jsx)("code",{className:"ml-1 font-mono",children:"openclaw gateway restart"}),"."]}):null,aw?(0,b.jsxs)("div",{className:"mt-1 text-[10px] text-red-200",children:["Failed to load bindings: ",aw]}):null,(0,b.jsx)("div",{className:"mt-1 text-[10px] text-[color:var(--ck-text-tertiary)]",children:"Uses your existing OpenClaw bindings (recommended). Manual provider/target is an advanced override."})]}),(0,b.jsxs)("details",{className:"rounded-lg border border-white/10 bg-black/10",children:[(0,b.jsx)("summary",{className:"cursor-pointer list-none px-2 py-1 text-[11px] font-medium text-[color:var(--ck-text-secondary)]",children:"Advanced: manual override"}),(0,b.jsxs)("div",{className:"px-2 pb-2 pt-1 space-y-2",children:[(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"provider"}),(0,b.jsx)("input",{value:O,onChange:a=>{let b=String(a.target.value||"").trim()||"telegram";br({...J,meta:{...M,approvalBindingId:"",approvalProvider:b},nodes:J.nodes.map(a=>"human_approval"===a.type?{...a,config:{...a.config&&"object"==typeof a.config&&!Array.isArray(a.config)?a.config:{},approvalBindingId:"",provider:b}}:a)})},className:"mt-1 w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",placeholder:"telegram"})]}),(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"target"}),(0,b.jsx)("input",{value:P,onChange:a=>{let b=String(a.target.value||"").trim();br({...J,meta:{...M,approvalBindingId:"",approvalTarget:b},nodes:J.nodes.map(a=>"human_approval"===a.type?{...a,config:{...a.config&&"object"==typeof a.config&&!Array.isArray(a.config)?a.config:{},approvalBindingId:"",target:b}}:a)})},className:"mt-1 w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",placeholder:"(e.g. Telegram chat id)"})]})]})]})]})]}),(0,b.jsxs)("details",{open:!0,className:"rounded-lg border border-white/10 bg-white/5",children:[(0,b.jsx)("summary",{className:"cursor-pointer list-none px-3 py-2 text-sm font-medium text-[color:var(--ck-text-primary)]",children:"Node inspector"}),(0,b.jsxs)("div",{className:"px-3 pb-3",children:[(0,b.jsx)("div",{className:"flex items-center justify-between gap-2",children:ai?(0,b.jsx)("button",{type:"button",onClick:()=>{let a=J.nodes.filter(a=>a.id!==ai),b=(J.edges??[]).filter(a=>a.from!==ai&&a.to!==ai);br({...J,nodes:a,edges:b}),aj("")},className:"rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-[10px] font-medium text-red-100 hover:bg-white/10",children:"Delete node"}):null}),ai?(I=J.nodes.find(a=>a.id===ai))?(0,b.jsxs)("div",{className:"mt-3 space-y-3",children:[(0,b.jsxs)("div",{children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"id"}),(0,b.jsx)("div",{className:"mt-1 rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",children:I.id})]}),(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"name"}),(0,b.jsx)("input",{value:String(I.name??""),onChange:a=>{let b=a.target.value;br({...J,nodes:J.nodes.map(a=>a.id===I.id?{...a,name:b}:a)})},className:"mt-1 w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",placeholder:"Optional"})]}),(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"type"}),(0,b.jsxs)("select",{value:I.type,onChange:a=>{let b=a.target.value;br({...J,nodes:J.nodes.map(a=>a.id===I.id?{...a,type:b}:a)})},className:"mt-1 w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",children:[(0,b.jsx)("option",{value:"start",children:"start"}),(0,b.jsx)("option",{value:"end",children:"end"}),(0,b.jsx)("option",{value:"llm",children:"llm"}),(0,b.jsx)("option",{value:"tool",children:"tool"}),(0,b.jsx)("option",{value:"condition",children:"condition"}),(0,b.jsx)("option",{value:"delay",children:"delay"}),(0,b.jsx)("option",{value:"human_approval",children:"human_approval"}),(0,b.jsx)("option",{value:"media-image",children:"media-image"}),(0,b.jsx)("option",{value:"media-video",children:"media-video"}),(0,b.jsx)("option",{value:"handoff",children:"handoff"})]})]}),(0,b.jsxs)("div",{className:"grid grid-cols-2 gap-2",children:[(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"x"}),(0,b.jsx)("input",{type:"number",value:"number"==typeof I.x?I.x:0,onChange:a=>{let b=Number(a.target.value);br({...J,nodes:J.nodes.map(a=>a.id===I.id?{...a,x:b}:a)})},className:"mt-1 w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]"})]}),(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"y"}),(0,b.jsx)("input",{type:"number",value:"number"==typeof I.y?I.y:0,onChange:a=>{let b=Number(a.target.value);br({...J,nodes:J.nodes.map(a=>a.id===I.id?{...a,y:b}:a)})},className:"mt-1 w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]"})]})]}),"llm"===I.type?(0,b.jsxs)("div",{className:"space-y-3",children:[(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"prompt"}),(0,b.jsx)(o,{value:String((I.config||{}).promptTemplate??""),workflow:J,currentNodeId:I.id,onChangeValue:a=>{let b={...I.config,promptTemplate:a};br({...J,nodes:J.nodes.map(a=>a.id===I.id?{...a,config:b}:a)})},className:"mt-1 min-h-[150px] w-full resize-y rounded-lg border border-white/10 bg-white/5 p-2 pr-12 font-mono text-xs text-[color:var(--ck-text-primary)]",placeholder:"What should this node do? Use {{nodeId.output}} to reference upstream node outputs.",spellCheck:!1})]}),(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"model"}),(0,b.jsxs)("select",{value:String((I.config||{}).model??""),onChange:a=>{let b=String(a.target.value||"").trim(),c={...I.config,...b?{model:b}:{}};b||delete c.model,br({...J,nodes:J.nodes.map(a=>a.id===I.id?{...a,config:c}:a)})},className:"mt-1 w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",children:[(0,b.jsx)("option",{value:"",children:"Default (inherit global)"}),ay.map(a=>(0,b.jsx)("option",{value:a,children:a},a))]}),aA?(0,b.jsxs)("div",{className:"mt-1 text-[10px] text-amber-300",children:["Could not load model list: ",aA]}):null]}),(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"timeout (seconds)"}),(0,b.jsx)("input",{type:"number",value:(I.config||{}).timeoutMs?String(Number((I.config||{}).timeoutMs)/1e3):"",onChange:a=>{let b=a.target.value?Number(a.target.value):null,c={...I.config};b&&b>0?c.timeoutMs=1e3*b:delete c.timeoutMs,br({...J,nodes:J.nodes.map(a=>a.id===I.id?{...a,config:c}:a)})},className:"mt-1 w-24 rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",placeholder:"120",min:"1"})]})]}):null,I.type in h?(0,b.jsxs)("div",{children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"Media Generation"}),(0,b.jsx)("div",{className:"mt-1",children:(0,b.jsx)(k,{config:{mediaType:"image",provider:"auto",prompt:"",...I.config||{}},onChange:a=>{br({...J,nodes:J.nodes.map(b=>b.id===I.id?{...b,config:a}:b)})},teamId:a,workflow:J,workflowNodeIds:J.nodes.map(a=>a.id),workflowEdges:(J.edges??[]).map(a=>({from:a.from,to:a.to})),currentNodeId:I.id})})]}):null,"human_approval"===I.type?(0,b.jsxs)("div",{className:"space-y-2",children:[(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"provider"}),(0,b.jsx)("input",{value:String((I.config||{}).provider??""),onChange:a=>{let b=String(a.target.value||"").trim(),c={...I.config,...b?{provider:b}:{}};b||delete c.provider,br({...J,nodes:J.nodes.map(a=>a.id===I.id?{...a,config:c}:a)})},className:"mt-1 w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",placeholder:"telegram"})]}),(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"target"}),(0,b.jsx)("input",{value:String((I.config||{}).target??""),onChange:a=>{let b=String(a.target.value||"").trim(),c={...I.config,...b?{target:b}:{}};b||delete c.target,br({...J,nodes:J.nodes.map(a=>a.id===I.id?{...a,config:c}:a)})},className:"mt-1 w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",placeholder:"(e.g. Telegram chat id)"}),(0,b.jsx)("div",{className:"mt-1 text-[10px] text-[color:var(--ck-text-tertiary)]",children:"Overrides workflow-level default when set."})]}),(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"messageTemplate (optional)"}),(0,b.jsx)(o,{value:String((I.config||{}).messageTemplate??""),workflow:J,currentNodeId:I.id,onChangeValue:a=>{let b={...I.config,...a.trim()?{messageTemplate:a}:{}};a.trim()||delete b.messageTemplate,br({...J,nodes:J.nodes.map(a=>a.id===I.id?{...a,config:b}:a)})},className:"mt-1 h-[70px] w-full resize-none rounded-lg border border-white/10 bg-white/5 p-2 pr-12 font-mono text-[10px] text-[color:var(--ck-text-primary)]",placeholder:"Approval needed for {{workflowName}} (run {{runId}})",spellCheck:!1}),(0,b.jsxs)("div",{className:"mt-1 text-[10px] text-[color:var(--ck-text-tertiary)]",children:["Vars: ","{{workflowName}}",", ","{{workflowId}}",", ","{{runId}}",", ","{{nodeId}}"]})]})]}):null,"handoff"===I.type?(r=String((n=I.config||{}).targetTeamId??""),s=String(n.targetWorkflowId??""),t=n.variableMapping||{},u=async()=>{if(!(aC.length>0)&&!aG){aH(!0);try{let a=await fetch("/api/teams/list"),b=await a.json();b.ok&&Array.isArray(b.teamIds)&&aD(b.teamIds)}catch{}aH(!1)}},v=async a=>{if(a&&!aE[a])try{let b=await fetch(`/api/teams/workflows?teamId=${encodeURIComponent(a)}`),c=await b.json();if(c.ok&&Array.isArray(c.files)){let b=c.files.map(a=>({id:a.replace(/\.workflow\.json$/,"")}));aF(c=>({...c,[a]:b}))}}catch{}},w=async a=>{if(a&&!aI[a]&&!aK[a]){aL(b=>({...b,[a]:!0}));try{let b=(()=>{try{let b=localStorage.getItem(`ck-postiz-${a}`);return b&&JSON.parse(b).apiKey||""}catch{return""}})(),c=await fetch(`/api/plugins/marketing/drivers?teamId=${encodeURIComponent(a)}`,{headers:b?{"x-postiz-api-key":b}:{}}),d=await c.json(),e=(Array.isArray(d?.drivers)?d.drivers:[]).filter(a=>a?.platform==="instagram"&&a?.backend==="postiz"&&a?.integrationId).map(a=>({integrationId:String(a.integrationId),displayName:String(a.displayName||"Instagram"),username:a.username?String(a.username):void 0}));aJ(b=>({...b,[a]:e}))}catch{}aL(b=>({...b,[a]:!1}))}},y=(x=String(t.kitchenTeamId??""))&&!x.includes("{{")?x:a,0!==aC.length||aG||u(),r&&!aE[r]&&v(r),(z=s.toLowerCase().includes("instagram")||Object.prototype.hasOwnProperty.call(t,"integrationId")||Object.prototype.hasOwnProperty.call(t,"integrationIds"))&&y&&!aI[y]&&!aK[y]&&w(y),A=aE[r]||[],B=Object.entries(t),C=y&&aI[y]||[],D=!!y&&!!aK[y],E=String(t.integrationIds??t.integrationId??"").split(",").map(a=>a.trim()).filter(Boolean),F=a=>{let b={...n,...a};br({...J,nodes:J.nodes.map(a=>a.id===I.id?{...a,config:b}:a)})},G=String(n.mode??"fire-and-forget"),H="number"==typeof n.waitTimeoutMs?n.waitTimeoutMs:3e5,(0,b.jsxs)("div",{className:"space-y-2",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"Handoff Target"}),(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"mode"}),(0,b.jsxs)("select",{value:G,onChange:a=>{let b=a.target.value;F({mode:"fire-and-forget"===b?void 0:b})},className:"mt-1 w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",children:[(0,b.jsx)("option",{value:"fire-and-forget",children:"Fire & Forget"}),(0,b.jsx)("option",{value:"wait-for-completion",children:"Wait for Completion"})]})]}),"wait-for-completion"===G?(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"wait timeout (seconds)"}),(0,b.jsx)("input",{type:"number",min:30,value:Math.round(H/1e3),onChange:a=>{F({waitTimeoutMs:1e3*Math.max(30,parseInt(a.target.value,10)||300)})},className:"mt-1 w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]"}),(0,b.jsx)("div",{className:"mt-0.5 text-[9px] text-[color:var(--ck-text-tertiary)]",children:"Workflow will wait up to this long for the target to complete."})]}):null,(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"target team"}),(0,b.jsxs)("select",{value:r,onChange:a=>{let b=a.target.value;F({targetTeamId:b||void 0,targetWorkflowId:void 0}),b&&!aE[b]&&v(b)},className:"mt-1 w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",children:[(0,b.jsx)("option",{value:"",children:"— Select team —"}),aC.map(c=>(0,b.jsxs)("option",{value:c,children:[c,c===a?" (current)":""]},c))]})]}),r?(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"target workflow"}),(0,b.jsxs)("select",{value:s,onChange:a=>F({targetWorkflowId:a.target.value||void 0}),className:"mt-1 w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",children:[(0,b.jsx)("option",{value:"",children:"— Select workflow —"}),A.map(a=>(0,b.jsx)("option",{value:a.id,children:a.name||a.id},a.id))]}),r&&!aE[r]?(0,b.jsx)("div",{className:"mt-1 text-[10px] text-[color:var(--ck-text-tertiary)]",children:"Loading workflows…"}):null]}):null,z?(0,b.jsxs)("div",{children:[(0,b.jsxs)("div",{className:"flex items-center justify-between",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"instagram accounts"}),(0,b.jsx)("button",{type:"button",onClick:()=>{aJ(a=>{let b={...a};return delete b[y],b}),w(y)},className:"rounded-lg border border-white/10 bg-white/5 px-2 py-0.5 text-[10px] font-medium text-[color:var(--ck-text-primary)] hover:bg-white/10",children:"Refresh"})]}),D?(0,b.jsx)("div",{className:"mt-1 text-[10px] text-[color:var(--ck-text-tertiary)]",children:"Loading accounts…"}):0===C.length?(0,b.jsx)("div",{className:"mt-1 text-[10px] text-[color:var(--ck-text-tertiary)]",children:"No Instagram accounts found. Open Marketing → Accounts and connect IG in Postiz."}):(0,b.jsxs)("div",{className:"mt-1 space-y-1",children:[C.map(a=>{let c=E.includes(a.integrationId);return(0,b.jsxs)("label",{className:"flex items-center gap-2 cursor-pointer rounded-lg border border-white/10 bg-white/5 px-2 py-1 hover:bg-white/10",children:[(0,b.jsx)("input",{type:"checkbox",checked:c,onChange:()=>{let b=c?E.filter(b=>b!==a.integrationId):[...E,a.integrationId],d={...t};delete d.integrationId,b.length>0?d.integrationIds=b.join(","):delete d.integrationIds,F({variableMapping:d})},className:"accent-[var(--ck-accent-red)]"}),(0,b.jsxs)("div",{children:[(0,b.jsx)("div",{className:"text-xs text-[color:var(--ck-text-primary)]",children:a.displayName}),a.username?(0,b.jsx)("div",{className:"text-[10px] text-[color:var(--ck-text-tertiary)]",children:a.username}):null]})]},a.integrationId)}),(0,b.jsx)("div",{className:"text-[9px] text-[color:var(--ck-text-tertiary)]",children:0===E.length?"None selected — will use first connected account.":`${E.length} account${E.length>1?"s":""} selected.`})]})]}):null,(0,b.jsxs)("div",{children:[(0,b.jsxs)("div",{className:"flex items-center justify-between",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"variable mapping"}),(0,b.jsx)("button",{type:"button",onClick:()=>{let a=`var_${Date.now()}`;F({variableMapping:{...t,[a]:""}})},className:"rounded-lg border border-white/10 bg-white/5 px-2 py-0.5 text-[10px] font-medium text-[color:var(--ck-text-primary)] hover:bg-white/10",children:"+ Add"})]}),(0,b.jsxs)("div",{className:"mt-1 text-[10px] text-[color:var(--ck-text-tertiary)]",children:["Map target workflow trigger inputs to upstream node outputs. Key = target variable name, Value = ","{{nodeId.field}}"," template."]}),B.length>0?(0,b.jsx)("div",{className:"mt-2 space-y-1",children:B.map(([a,c],d)=>(0,b.jsxs)("div",{className:"flex items-center gap-1",children:[(0,b.jsx)("input",{value:a,onChange:b=>{let d=b.target.value,e={...t};delete e[a],e[d]=c,F({variableMapping:e})},className:"w-1/3 rounded-lg border border-white/10 bg-white/5 px-1.5 py-0.5 text-[10px] text-[color:var(--ck-text-primary)]",placeholder:"target_var"}),(0,b.jsx)("span",{className:"text-[10px] text-[color:var(--ck-text-tertiary)]",children:"→"}),(0,b.jsx)("input",{value:c,onChange:b=>{F({variableMapping:{...t,[a]:b.target.value}})},className:"flex-1 rounded-lg border border-white/10 bg-white/5 px-1.5 py-0.5 text-[10px] text-[color:var(--ck-text-primary)]",placeholder:"{{nodeId.output}}"}),(0,b.jsx)("button",{type:"button",onClick:()=>{let b={...t};delete b[a],F({variableMapping:Object.keys(b).length>0?b:void 0})},className:"text-[10px] text-red-400 hover:text-red-300",title:"Remove mapping",children:"✕"})]},d))}):(0,b.jsx)("div",{className:"mt-1 text-[10px] text-[color:var(--ck-text-tertiary)] italic",children:"No mappings — target workflow will receive empty trigger input."})]})]})):null,(0,b.jsx)("div",{children:(0,b.jsx)(p,{outputFields:(I.config||{}).outputFields||[],onChange:a=>{let b={...I.config};a.length>0?b.outputFields=a:delete b.outputFields,br({...J,nodes:J.nodes.map(a=>a.id===I.id?{...a,config:b}:a)})}})}),(0,b.jsxs)("details",{className:"rounded-lg border border-white/10 bg-black/10",children:[(0,b.jsx)("summary",{className:"cursor-pointer list-none px-2 py-1 text-[10px] font-medium text-[color:var(--ck-text-secondary)]",children:"Raw Config (debug)"}),(0,b.jsx)("div",{className:"p-2",children:(0,b.jsx)("pre",{className:"mt-1 max-h-[150px] overflow-auto rounded-lg border border-white/10 bg-white/5 p-2 text-[9px] text-[color:var(--ck-text-tertiary)]",children:JSON.stringify(I.config??{},null,2)})})]})]}):(0,b.jsx)("div",{className:"mt-2 text-sm text-[color:var(--ck-text-secondary)]",children:"No node selected."}):(0,b.jsx)("div",{className:"mt-2 text-sm text-[color:var(--ck-text-secondary)]",children:"Select a node."})]})]}),(0,b.jsxs)("details",{open:!0,className:"rounded-lg border border-white/10 bg-white/5",children:[(0,b.jsx)("summary",{className:"cursor-pointer list-none px-3 py-2 text-sm font-medium text-[color:var(--ck-text-primary)]",children:"Triggers"}),(0,b.jsxs)("div",{className:"px-3 pb-3",children:[(0,b.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"triggers"}),(0,b.jsx)("button",{type:"button",onClick:()=>{let a=`t${Date.now()}`;br({...J,triggers:[...L,{kind:"cron",id:a,name:"New trigger",enabled:!0,expr:"0 9 * * 1-5",tz:K}]})},className:"rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-[10px] font-medium text-[color:var(--ck-text-primary)] hover:bg-white/10",children:"+ Add"})]}),"idle"!==$&&(0,b.jsxs)("div",{className:"mt-2 flex items-center gap-2 rounded-lg border border-white/10 bg-white/5 px-2 py-1",children:["syncing"===$&&(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)("div",{className:"h-3 w-3 animate-spin rounded-full border border-blue-400 border-t-transparent"}),(0,b.jsx)("div",{className:"text-xs text-blue-400",children:"Syncing triggers..."})]}),"success"===$&&(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)("div",{className:"text-green-400",children:"✓"}),(0,b.jsx)("div",{className:"text-xs text-green-400",children:"Triggers synced"})]}),"error"===$&&(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)("div",{className:"text-red-400",children:"✗"}),(0,b.jsxs)("div",{className:"text-xs text-red-400",children:["Trigger sync failed: ",aa]})]})]}),(0,b.jsx)("div",{className:"mt-2 space-y-2",children:L.length?L.map((a,c)=>{let d=a.kind,e=String(a.id??""),f=String(a.name??""),g=!!a.enabled,h=String(a.expr??""),i=String(a.tz??K),j=h.trim().split(/\s+/).filter(Boolean),k=!h.trim()||5===j.length;return(0,b.jsxs)("div",{className:"rounded-lg border border-white/10 bg-white/5 p-2",children:[(0,b.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,b.jsx)("div",{className:"text-xs text-[color:var(--ck-text-primary)]",children:f||e||`trigger-${c+1}`}),(0,b.jsx)("button",{type:"button",onClick:()=>br({...J,triggers:L.filter((a,b)=>b!==c)}),className:"text-[10px] text-[color:var(--ck-text-tertiary)] hover:text-[color:var(--ck-text-primary)]",children:"Remove"})]}),"cron"===d?null:(0,b.jsxs)("div",{className:"mt-1 text-xs text-[color:var(--ck-text-secondary)]",children:["Unsupported trigger kind: ",String(d)]}),(0,b.jsxs)("div",{className:"mt-2 grid grid-cols-1 gap-2",children:[(0,b.jsxs)("label",{className:"flex items-center gap-2 text-xs text-[color:var(--ck-text-secondary)]",children:[(0,b.jsx)("input",{type:"checkbox",checked:g,onChange:a=>{let b=a.target.checked;br({...J,triggers:L.map((a,d)=>d===c&&"cron"===a.kind?{...a,enabled:b}:a)})}}),"Enabled"]}),(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"name"}),(0,b.jsx)("input",{value:f,onChange:a=>{let b=a.target.value;br({...J,triggers:L.map((a,d)=>d===c&&"cron"===a.kind?{...a,name:b}:a)})},className:"mt-1 w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",placeholder:"Content cadence"})]}),(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"schedule (cron)"}),(0,b.jsx)("input",{value:h,onChange:a=>{let b=a.target.value;br({...J,triggers:L.map((a,d)=>d===c&&"cron"===a.kind?{...a,expr:b}:a)})},className:k?"mt-1 w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 font-mono text-[11px] text-[color:var(--ck-text-primary)]":"mt-1 w-full rounded-lg border border-red-400/50 bg-white/5 px-2 py-1 font-mono text-[11px] text-[color:var(--ck-text-primary)]",placeholder:"0 9 * * 1,3,5"}),k?null:(0,b.jsxs)("div",{className:"mt-1 text-[10px] text-red-200",children:["Cron should be 5 fields (min hour dom month dow). You entered ",j.length,"."]}),(0,b.jsxs)("div",{className:"mt-1 grid grid-cols-1 gap-1",children:[(0,b.jsx)("select",{value:Q.some(a=>a.expr===h)?h:"",onChange:a=>{let b=a.target.value;br({...J,triggers:L.map((a,d)=>d===c&&"cron"===a.kind?{...a,expr:b}:a)})},className:"w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-[11px] text-[color:var(--ck-text-secondary)]",children:Q.map(a=>(0,b.jsx)("option",{value:a.expr,children:a.label},a.label))}),(0,b.jsx)("div",{className:"text-[10px] text-[color:var(--ck-text-tertiary)]",children:"Presets set the cron; edit freely for advanced schedules."})]})]}),(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"timezone override"}),(0,b.jsx)("input",{value:i,onChange:a=>{let b=String(a.target.value||"").trim()||K;br({...J,triggers:L.map((a,d)=>d===c&&"cron"===a.kind?{...a,tz:b}:a)})},className:"mt-1 w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",placeholder:K})]})]})]},`${e}-${c}`)}):(0,b.jsx)("div",{className:"text-xs text-[color:var(--ck-text-secondary)]",children:"No triggers yet."})})]})]}),(0,b.jsxs)("details",{open:!0,className:"rounded-lg border border-white/10 bg-white/5",children:[(0,b.jsx)("summary",{className:"cursor-pointer list-none px-3 py-2 text-sm font-medium text-[color:var(--ck-text-primary)]",children:"Runs"}),(0,b.jsxs)("div",{className:"px-3 pb-3",children:[(0,b.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,b.jsxs)("div",{className:"flex items-center gap-3",children:[(0,b.jsx)("div",{className:"text-xs font-medium text-[color:var(--ck-text-secondary)]",children:"Runs (history)"}),(0,b.jsx)(d.default,{href:`/teams/${encodeURIComponent(a)}/runs`,className:"text-[10px] font-medium text-[color:var(--ck-text-tertiary)] hover:text-[color:var(--ck-text-secondary)] hover:underline",children:"View all →"})]}),(0,b.jsxs)("div",{className:"flex items-center gap-2",children:[(0,b.jsx)("button",{type:"button",disabled:U,onClick:async()=>{let b=String(J.id??"").trim();if(b){aW(""),aS(!0);try{let c=await fetch("/api/teams/workflow-runs",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({teamId:a,workflowId:b,mode:"enqueue"})}),d=await c.json();if(!c.ok||!d.ok)throw Error(d.error||"Failed to enqueue run");let e=await fetch(`/api/teams/workflow-runs?teamId=${encodeURIComponent(a)}&workflowId=${encodeURIComponent(b)}`,{cache:"no-store"}),f=await e.json();if(!e.ok||!f.ok)throw Error(f.error||"Failed to refresh runs");let g=(Array.isArray(f.files)?f.files:[]).map(a=>String(a??"").trim()).filter(a=>!!a);aQ(g)}catch(a){aW(a instanceof Error?a.message:String(a))}finally{aS(!1)}}},className:"rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-[10px] font-medium text-[color:var(--ck-text-primary)] hover:bg-white/10 disabled:opacity-50",children:"+ Queue run"}),(0,b.jsx)("button",{type:"button",disabled:U||aZ||!bq.ok,onClick:async()=>{let b=String(J.id??"").trim();if(b){if(bq.missingAgentOnNodeIds.length)return void aW("All nodes must be assigned to an agent.");if(bq.agentIdsMissingCron.length){a6(!0),a8("");try{let b=await fetch("/api/cron/worker",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({action:"reconcile",teamId:a})}),c=await b.json();if(!b.ok||!1===c.ok)throw Error(c.error||"Failed to reconcile worker crons");let d=await bn(),e=bq.requiredAgentIds.filter(a=>!d[a]);if(e.length)return void aW(`Cron not set up for: ${e.join(", ")}`)}catch(a){aW(a instanceof Error?a.message:String(a));return}finally{a6(!1)}}aW(""),aS(!0),aU(!0);try{let c=await fetch("/api/teams/workflow-runs",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({teamId:a,workflowId:b,mode:"run_now"})}),d=await c.json();if(!c.ok||!d.ok)throw Error(d.error||"Failed to create run");let e=String(d.runId??"").trim();if(e)return void R.push(`/teams/${a}/runs/${i}/${e}`);aU(!1);let f=await fetch(`/api/teams/workflow-runs?teamId=${encodeURIComponent(a)}&workflowId=${encodeURIComponent(b)}`,{cache:"no-store"}),g=await f.json();if(!f.ok||!g.ok)throw Error(g.error||"Failed to refresh runs");let h=(Array.isArray(g.files)?g.files:[]).map(a=>String(a??"").trim()).filter(a=>!!a);aQ(h)}catch(a){aU(!1),aW(a instanceof Error?a.message:String(a))}finally{aS(!1)}}},className:"rounded-lg border border-emerald-400/30 bg-emerald-500/10 px-2 py-1 text-[10px] font-medium text-emerald-50 hover:bg-emerald-500/15 disabled:opacity-50",title:"Enqueue a run for the workflow runner (Kitchen does not execute nodes)",children:"+ Run now"}),a_?(0,b.jsx)("div",{className:"ml-2 text-[10px] text-amber-100/90",title:a_,children:"Cron check unavailable"}):null]})]}),bq.missingAgentOnNodeIds.length?(0,b.jsxs)("div",{className:"mt-2 rounded-lg border border-red-400/30 bg-red-500/10 p-2 text-xs text-red-100",children:["All nodes must be assigned to an agent. Missing agentId on: ",bq.missingAgentOnNodeIds.join(", ")]}):bq.agentIdsMissingCron.length?(0,b.jsxs)("div",{className:"mt-2 rounded-lg border border-amber-400/30 bg-amber-500/10 p-2 text-xs text-amber-50",children:[(0,b.jsxs)("div",{children:["Cron not set up for: ",bq.agentIdsMissingCron.join(", ")]}),(0,b.jsxs)("div",{className:"mt-2 flex items-center gap-2",children:[(0,b.jsx)("button",{type:"button",onClick:()=>{a8(""),a4(!0)},className:"rounded-lg border border-amber-300/30 bg-amber-500/10 px-2 py-1 text-[10px] font-medium text-amber-50 hover:bg-amber-500/15",children:"Install worker cron(s)"}),(0,b.jsx)("button",{type:"button",onClick:()=>void bn(),className:"rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-[10px] font-medium text-[color:var(--ck-text-primary)] hover:bg-white/10",children:"Re-check"})]})]}):null,(0,b.jsx)(f.ConfirmationModal,{open:a3,title:"Install worker cron jobs?",busy:a5,error:a7||void 0,confirmLabel:"Install",onClose:()=>{a5||a4(!1)},onConfirm:async()=>{a6(!0),a8("");try{let b=await fetch("/api/cron/worker",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({action:"reconcile",teamId:a})}),c=await b.json();if(!b.ok||!1===c.ok)throw Error(c.error||"Failed to install worker crons");await bn(),a4(!1)}catch(a){a8(a instanceof Error?a.message:String(a))}finally{a6(!1)}},children:(0,b.jsxs)("div",{className:"text-sm text-[color:var(--ck-text-secondary)]",children:["Kitchen will install (or enable) worker cron jobs for the following agents so this workflow can drain:",(0,b.jsx)("div",{className:"mt-2 rounded-lg border border-white/10 bg-white/5 p-2 font-mono text-[11px] text-[color:var(--ck-text-primary)]",children:bq.agentIdsMissingCron.join(", ")}),(0,b.jsxs)("div",{className:"mt-2 text-xs text-[color:var(--ck-text-tertiary)]",children:["Cron cadence: every 5 minutes. The worker runs: ",(0,b.jsx)("span",{className:"font-mono",children:"openclaw recipes workflows worker-tick"}),"."]})]})}),aV?(0,b.jsx)("div",{className:"mt-2 rounded-lg border border-red-400/30 bg-red-500/10 p-2 text-xs text-red-100",children:aV}):null,(0,b.jsx)("div",{className:"mt-2 space-y-1",children:aR?(0,b.jsx)("div",{className:"text-xs text-[color:var(--ck-text-secondary)]",children:"Serving up hot…"}):aP.length?aP.slice(0,8).map(c=>{let e=String(J.id??"").trim(),f=String(c).replace(/\.run\.json$/i,""),g=aX===f,h=e?`/teams/${encodeURIComponent(a)}/runs/${encodeURIComponent(e)}/${encodeURIComponent(f)}`:"#";return(0,b.jsx)(d.default,{href:h,onClick:()=>aY(f),className:g?"block w-full rounded-lg bg-white/10 px-2 py-1 text-left text-[11px] font-mono text-[color:var(--ck-text-primary)]":"block w-full rounded-lg px-2 py-1 text-left text-[11px] font-mono text-[color:var(--ck-text-secondary)] hover:bg-white/5",title:"Open run detail",children:f},c)}):(0,b.jsx)("div",{className:"text-xs text-[color:var(--ck-text-secondary)]",children:"No runs yet."})}),(0,b.jsxs)("details",{open:!0,className:"mt-3 rounded-lg border border-white/10 bg-black/10",children:[(0,b.jsx)("summary",{className:"cursor-pointer list-none px-3 py-2 text-sm font-medium text-[color:var(--ck-text-primary)]",children:"Nodes"}),(0,b.jsxs)("div",{className:"px-3 pb-3",children:[(0,b.jsx)("div",{className:"mt-2 rounded-lg border border-white/10 bg-white/5 p-2",children:(0,b.jsxs)("div",{className:"grid grid-cols-1 gap-2",children:[(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"id"}),(0,b.jsx)("input",{value:a9,onChange:a=>ba(a.target.value),className:"mt-1 w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",placeholder:"e.g. draft_assets"})]}),(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"name (optional)"}),(0,b.jsx)("input",{value:bb,onChange:a=>bc(a.target.value),className:"mt-1 w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",placeholder:"Human-friendly label"})]}),(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"type"}),(0,b.jsxs)("select",{value:bd,onChange:a=>be(a.target.value),className:"mt-1 w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",children:[(0,b.jsx)("option",{value:"start",children:"start"}),(0,b.jsx)("option",{value:"end",children:"end"}),(0,b.jsx)("option",{value:"llm",children:"llm"}),(0,b.jsx)("option",{value:"tool",children:"tool"}),(0,b.jsx)("option",{value:"condition",children:"condition"}),(0,b.jsx)("option",{value:"delay",children:"delay"}),(0,b.jsx)("option",{value:"human_approval",children:"human_approval"}),(0,b.jsx)("option",{value:"media-image",children:"media-image"}),(0,b.jsx)("option",{value:"media-video",children:"media-video"}),(0,b.jsx)("option",{value:"handoff",children:"handoff"})]})]}),(0,b.jsx)("button",{type:"button",onClick:()=>{let a=String(a9||"").trim().replace(/[^a-z0-9_\-]/gi,"_");if(!a||J.nodes.some(b=>b.id===a))return;let b=J.nodes.reduce((a,b)=>"number"==typeof b.x?Math.max(a,b.x):a,80),c={id:a,type:bd,name:String(bb||"").trim()||a,x:b+220,y:80};br({...J,nodes:[...J.nodes,c]}),aj(a),ba(""),bc("")},className:"rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-[11px] font-medium text-[color:var(--ck-text-primary)] hover:bg-white/10",children:"+ Add node"})]})}),(0,b.jsx)("div",{className:"mt-2 space-y-1",children:J.nodes.map(a=>{let c=ai===a.id;return(0,b.jsxs)("button",{type:"button",onClick:()=>aj(a.id),className:c?"w-full rounded-lg bg-white/10 px-2 py-1 text-left text-[11px] text-[color:var(--ck-text-primary)]":"w-full rounded-lg px-2 py-1 text-left text-[11px] text-[color:var(--ck-text-secondary)] hover:bg-white/5",children:[(0,b.jsx)("span",{className:"font-mono",children:a.id}),(0,b.jsx)("span",{className:"ml-2 text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:a.type})]},a.id)})})]})]}),(0,b.jsxs)("details",{open:!0,className:"mt-3 rounded-lg border border-white/10 bg-black/10",children:[(0,b.jsx)("summary",{className:"cursor-pointer list-none px-3 py-2 text-sm font-medium text-[color:var(--ck-text-primary)]",children:"Edges"}),(0,b.jsxs)("div",{className:"px-3 pb-3",children:[(0,b.jsx)("div",{className:"mt-2 rounded-lg border border-white/10 bg-white/5 p-2",children:(0,b.jsxs)("div",{className:"grid grid-cols-1 gap-2",children:[(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"from"}),(0,b.jsxs)("select",{value:bf,onChange:a=>bg(a.target.value),className:"mt-1 w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",children:[(0,b.jsx)("option",{value:"",children:"(select)"}),J.nodes.map(a=>(0,b.jsx)("option",{value:a.id,children:a.id},a.id))]})]}),(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"to"}),(0,b.jsxs)("select",{value:bh,onChange:a=>bi(a.target.value),className:"mt-1 w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",children:[(0,b.jsx)("option",{value:"",children:"(select)"}),J.nodes.map(a=>(0,b.jsx)("option",{value:a.id,children:a.id},a.id))]})]}),(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"label (optional)"}),(0,b.jsx)("input",{value:bj,onChange:a=>bk(a.target.value),className:"mt-1 w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",placeholder:"e.g. approve"})]}),(0,b.jsx)("button",{type:"button",onClick:()=>{let a=String(bf||"").trim(),b=String(bh||"").trim();if(!a||!b||a===b)return;let c={id:`e${Date.now()}`,from:a,to:b,...String(bj||"").trim()?{label:String(bj).trim()}:{}};br({...J,edges:[...J.edges??[],c]}),bk("")},className:"rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-[11px] font-medium text-[color:var(--ck-text-primary)] hover:bg-white/10",children:"+ Add edge"})]})}),(0,b.jsx)("div",{className:"mt-2 space-y-2",children:(J.edges??[]).length?(J.edges??[]).map(a=>(0,b.jsx)("div",{className:"rounded-lg border border-white/10 bg-white/5 p-2",children:(0,b.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,b.jsxs)("div",{className:"text-[11px] text-[color:var(--ck-text-secondary)]",children:[(0,b.jsx)("span",{className:"font-mono",children:a.from})," → ",(0,b.jsx)("span",{className:"font-mono",children:a.to}),a.label?(0,b.jsxs)("span",{className:"ml-2 text-[10px] text-[color:var(--ck-text-tertiary)]",children:["(",a.label,")"]}):null]}),(0,b.jsx)("button",{type:"button",onClick:()=>br({...J,edges:(J.edges??[]).filter(b=>b.id!==a.id)}),className:"text-[10px] text-[color:var(--ck-text-tertiary)] hover:text-[color:var(--ck-text-primary)]",children:"Remove"})]})},a.id)):(0,b.jsx)("div",{className:"text-xs text-[color:var(--ck-text-secondary)]",children:"No edges yet."})})]})]})]})]})]})):null})})]}),(0,b.jsx)(m,{open:aT})]})}a.s(["default",()=>r],13833)}];
|
|
7
|
+
`})]}),document.body):null}function n({targetTextareaRef:a,workflow:d,currentNodeId:e,onInsert:f}){let[g,h]=(0,c.useState)(!1),i=(0,c.useRef)(null),j=(0,c.useMemo)(()=>(function(a,b){let c=[],d=new Set,e=[b],f=new Set;for(;e.length>0;){let c=e.shift();if(!f.has(c))for(let g of(f.add(c),a.edges??[]))g.to!==c||d.has(g.from)||g.from===b||(d.add(g.from),e.push(g.from))}for(let b of d){let d=a.nodes.find(a=>a.id===b);if(!d)continue;let e=d.name||b,f=d.config&&"object"==typeof d.config&&!Array.isArray(d.config)?d.config:{};c.push({nodeId:b,nodeName:e,fieldName:"output",fieldType:"text"},{nodeId:b,nodeName:e,fieldName:"text",fieldType:"text"});let g=f.outputFields;if(Array.isArray(g))for(let a of g)a.name?.trim()&&c.push({nodeId:b,nodeName:e,fieldName:a.name.trim(),fieldType:a.type||"text"})}return c})(d,e),[d,e]),k=(0,c.useMemo)(()=>[{variable:"{{run.id}}",type:"text"},{variable:"{{workflow.name}}",type:"text"},{variable:"{{workflow.id}}",type:"text"},{variable:"{{node.id}}",type:"text"},{variable:"{{date}}",type:"text"}],[]);(0,c.useEffect)(()=>{function a(a){i.current&&!i.current.contains(a.target)&&h(!1)}if(g)return document.addEventListener("mousedown",a),()=>document.removeEventListener("mousedown",a)},[g]);let l=b=>{let c=a.current;if(c){let a=c.selectionStart,d=c.selectionEnd,e=c.value,g=e.substring(0,a)+b+e.substring(d);f&&(f(g),setTimeout(()=>{c.focus();let d=a+b.length;c.setSelectionRange(d,d)},0))}h(!1)},m=j.reduce((a,b)=>{let c=`${b.nodeId}|${b.nodeName}`;return a[c]||(a[c]={nodeId:b.nodeId,nodeName:b.nodeName,fields:[]}),a[c].fields.push({name:b.fieldName,type:b.fieldType}),a},{});return(0,b.jsxs)("div",{className:"absolute top-1 right-1",ref:i,children:[(0,b.jsx)("button",{type:"button",onClick:()=>h(!g),className:"rounded-lg border border-white/10 bg-black/30 px-2 py-1 text-[9px] text-[color:var(--ck-text-secondary)] hover:bg-white/10 hover:text-[color:var(--ck-text-primary)]",title:"Insert variable",children:"{{}}"}),g&&(0,b.jsx)("div",{className:"absolute right-0 top-8 z-50 w-72 max-h-80 overflow-auto rounded-lg border border-white/15 bg-black/80 backdrop-blur shadow-[var(--ck-shadow-1)]",children:(0,b.jsxs)("div",{className:"p-1",children:[(0,b.jsxs)("div",{children:[(0,b.jsx)("div",{className:"px-2 py-1 text-[10px] font-medium uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"Globals"}),k.map(({variable:a,type:c})=>(0,b.jsxs)("button",{type:"button",onClick:()=>l(a),className:"w-full flex items-center justify-between gap-2 rounded-lg px-2 py-1 text-left text-xs text-[color:var(--ck-text-primary)] hover:bg-white/10 cursor-pointer",children:[(0,b.jsx)("span",{className:"font-mono",children:a}),(0,b.jsx)("span",{className:"text-[9px] px-1 py-0.5 rounded-sm bg-black/30 text-blue-400",children:c})]},a))]}),Object.values(m).map(a=>(0,b.jsxs)("div",{children:[(0,b.jsx)("div",{className:"px-2 py-1 text-[10px] font-medium uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:a.nodeName}),a.fields.map(c=>{let d=`{{${a.nodeId}.${c.name}}}`,e="text"===c.type?"text-blue-400":"list"===c.type?"text-green-400":"json"===c.type?"text-amber-400":"text-gray-400";return(0,b.jsxs)("button",{type:"button",onClick:()=>l(d),className:"w-full flex items-center justify-between gap-2 rounded-lg px-2 py-1 text-left text-xs text-[color:var(--ck-text-primary)] hover:bg-white/10 cursor-pointer",children:[(0,b.jsx)("span",{className:"font-mono",children:d}),(0,b.jsx)("span",{className:`text-[9px] px-1 py-0.5 rounded-sm bg-black/30 ${e}`,children:c.type})]},`${a.nodeId}.${c.name}`)})]},a.nodeId)),0===j.length&&(0,b.jsx)("div",{className:"px-2 py-3 text-xs text-[color:var(--ck-text-secondary)]",children:"Tip: Add output fields to upstream nodes to see node-specific variables here."})]})})]})}function o({value:a,onChangeValue:d,workflow:e,currentNodeId:f,className:g,placeholder:h,spellCheck:i}){let j=(0,c.useRef)(null);return(0,b.jsxs)("div",{className:"relative",children:[(0,b.jsx)("textarea",{ref:j,value:a,onChange:a=>d(a.target.value),className:g,placeholder:h,spellCheck:i}),(0,b.jsx)(n,{targetTextareaRef:j,workflow:e,currentNodeId:f,onInsert:a=>d(a)})]})}function p({outputFields:a,onChange:c}){return(0,b.jsxs)("div",{children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"output fields (optional)"}),(0,b.jsx)("div",{className:"text-[9px] text-[color:var(--ck-text-secondary)] mb-2",children:"Define what this node produces for downstream nodes"}),(0,b.jsxs)("div",{className:"space-y-1",children:[a.map((d,e)=>(0,b.jsxs)("div",{className:"flex items-center gap-2",children:[(0,b.jsx)("input",{value:d.name,onChange:b=>{let f=[...a];f[e]={...d,name:b.target.value},c(f)},className:"flex-1 rounded-lg border border-white/10 bg-black/30 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",placeholder:"Field name"}),(0,b.jsxs)("select",{value:d.type,onChange:b=>{let f=b.target.value,g=[...a];g[e]={...d,type:f},c(g)},className:"rounded-lg border border-white/10 bg-black/30 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",children:[(0,b.jsx)("option",{value:"text",children:"text"}),(0,b.jsx)("option",{value:"list",children:"list"}),(0,b.jsx)("option",{value:"json",children:"json"})]}),(0,b.jsx)("button",{type:"button",onClick:()=>{c(a.filter((a,b)=>b!==e))},className:"text-xs text-[color:var(--ck-text-tertiary)] hover:text-[color:var(--ck-text-primary)]",children:"×"})]},e)),(0,b.jsx)("button",{type:"button",onClick:()=>{c([...a,{name:"",type:"text"}])},className:"text-xs text-[color:var(--ck-text-secondary)] hover:text-[color:var(--ck-text-primary)]",children:"+ Add field"})]})]})}function q(a,b){return`ck-wf-draft:${a}:${b}`}function r({teamId:a,workflowId:i,draft:j,llmTaskEnabled:l}){let n,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R=(0,e.useRouter)(),[S,T]=(0,c.useState)("canvas"),[U,V]=(0,c.useState)(!1),[W,X]=(0,c.useState)({kind:"loading"}),[Y,Z]=(0,c.useState)(""),[$,_]=(0,c.useState)("idle"),[aa,ab]=(0,c.useState)(""),ac=(0,c.useRef)(null),[ad,ae]=(0,c.useState)(!1),[af,ag]=(0,c.useState)(1),ah=(0,c.useRef)(null),[ai,aj]=(0,c.useState)(""),[ak,al]=(0,c.useState)(null),[am,an]=(0,c.useState)({kind:"select"}),[ao,ap]=(0,c.useState)(""),[aq,ar]=(0,c.useState)([]),[as,at]=(0,c.useState)(""),[au,av]=(0,c.useState)([]),[aw,ax]=(0,c.useState)(""),[ay,az]=(0,c.useState)([]),[aA,aB]=(0,c.useState)(""),[aC,aD]=(0,c.useState)([]),[aE,aF]=(0,c.useState)({}),[aG,aH]=(0,c.useState)(!1),[aI,aJ]=(0,c.useState)({}),[aK,aL]=(0,c.useState)({}),[aM,aN]=(0,c.useState)({}),aO=(0,c.useMemo)(()=>/Tool not available:\s*gateway/i.test(String(aw||"")),[aw]),[aP,aQ]=(0,c.useState)([]),[aR,aS]=(0,c.useState)(!1),[aT,aU]=(0,c.useState)(!1),[aV,aW]=(0,c.useState)(""),[aX,aY]=(0,c.useState)(""),[aZ,a$]=(0,c.useState)(!1),[a_,a0]=(0,c.useState)(""),[a1,a2]=(0,c.useState)({}),[a3,a4]=(0,c.useState)(!1),[a5,a6]=(0,c.useState)(!1),[a7,a8]=(0,c.useState)(""),[a9,ba]=(0,c.useState)(""),[bb,bc]=(0,c.useState)(""),[bd,be]=(0,c.useState)("llm"),[bf,bg]=(0,c.useState)(""),[bh,bi]=(0,c.useState)(""),[bj,bk]=(0,c.useState)("");function bl(a){return!!a&&"object"==typeof a&&!Array.isArray(a)}function bm(a){if(!bl(a))return null;let b=bl(a.match)?a.match:null;if(!b)return null;let c=String(b.channel??"").trim();if(!c)return null;let d=String(a.agentId??"").trim(),e=String(b.accountId??"").trim(),f=bl(b.peer)?b.peer:null,g=f?String(f.kind??"").trim():"",h=f?String(f.id??"").trim():"",i=h||e;if(!i)return null;let j=d||(e?`${c}:account:${e}`:`${c}:${g}:${h}`),k=[c];return d&&k.push(d),e&&k.push(`account:${e}`),g&&h&&k.push(`${g}:${h}`),{id:j,label:k.join(" · "),channel:c,target:i}}(0,c.useEffect)(()=>{(async()=>{try{if(j){let b=sessionStorage.getItem(q(a,i));if(b)return void X({kind:"ready",jsonText:b});let c=JSON.stringify({schema:"clawkitchen.workflow.v1",id:i,name:"New workflow",timezone:"UTC",nodes:[{id:"start",type:"start",name:"start",x:80,y:80,config:{}},{id:"end",type:"end",name:"end",x:520,y:80,config:{}}],edges:[{id:"e1",from:"start",to:"end"}]},null,2)+"\n";X({kind:"ready",jsonText:c});try{sessionStorage.setItem(q(a,i),c)}catch{}return}let b=await fetch(`/api/teams/workflows?teamId=${encodeURIComponent(a)}&id=${encodeURIComponent(i)}`,{cache:"no-store"}),c=await b.json();if(!b.ok||!c.ok)throw Error(c.error||"Failed to load workflow");X({kind:"ready",jsonText:JSON.stringify(c.workflow,null,2)+"\n"})}catch(a){X({kind:"error",error:a instanceof Error?a.message:String(a)})}})()},[a,i,j]),(0,c.useEffect)(()=>{(async()=>{at("");try{let b=await fetch("/api/agents",{cache:"no-store"}),c=await b.json();if(!b.ok)throw Error(c.error||c.message||"Failed to load agents");let d=(Array.isArray(c.agents)?c.agents:[]).map(a=>({id:String(a.id??"").trim(),identityName:"string"==typeof a.identityName?a.identityName:void 0})).filter(b=>b.id&&b.id.startsWith(`${a}-`));ar(d)}catch(a){at(a instanceof Error?a.message:String(a)),ar([])}})()},[a]),(0,c.useEffect)(()=>{(async()=>{ax("");try{let a=await fetch("/api/channels/bindings",{cache:"no-store"}),b=await a.json();if(!a.ok||!1===b.ok)throw Error(b.error||"Failed to load bindings");let c=(Array.isArray(b.bindings)?b.bindings:[]).map(bm).filter(Boolean);av(c)}catch(a){ax(a instanceof Error?a.message:String(a)),av([])}})()},[]),(0,c.useEffect)(()=>{(async()=>{aB("");try{let a=await fetch("/api/settings/model-options",{cache:"no-store"}),b=await a.json();if(!a.ok||!1===b.ok)throw Error(b.error||"Failed to load model options");let c=Array.isArray(b.models)?Array.from(new Set(b.models.map(a=>String(a??"").trim()).filter(Boolean))):[];az(c)}catch(a){aB(a instanceof Error?a.message:String(a)),az([])}})()},[]);let bn=(0,c.useCallback)(async()=>{a0(""),a$(!0);try{let a=await fetch("/api/cron/jobs",{cache:"no-store"}),b=await a.json();if(!a.ok||!1===b.ok)throw Error(b.error||"Failed to load cron jobs");let c=Array.isArray(b.jobs)?b.jobs:[],d={};for(let a of c){if(!a||!a.enabled)continue;let b=String(a.name??""),c=String(a.payload?.message??"");if(!(b.startsWith("workflow-worker:")||c.includes("worker-tick")))continue;let e=b.match(/^workflow-worker:[^:]+:(.+)$/);if(e?.[1]){d[e[1]]=!0;continue}let f=c.match(/--agent-id\s+(\S+)/);if(f?.[1]){d[f[1]]=!0;continue}let g=String(a.agentId??"").trim();g&&"main"!==g&&(d[g]=!0)}return a2(d),d}catch(a){return a0(a instanceof Error?a.message:String(a)),a2({}),{}}finally{a$(!1)}},[]);(0,c.useEffect)(()=>{bn()},[bn]);let bo=(0,c.useMemo)(()=>{if("ready"!==W.kind)return{wf:null,err:""};try{return{wf:JSON.parse(W.jsonText),err:""}}catch(a){return{wf:null,err:a instanceof Error?a.message:String(a)}}},[W]),bp=(0,c.useMemo)(()=>bo.wf?function(a){let b=[],c=[];"clawkitchen.workflow.v1"!==a.schema&&b.push(`schema must be clawkitchen.workflow.v1 (got ${String(a.schema)})`),String(a.id||"").trim()||b.push("id is required"),String(a.name||"").trim()||b.push("name is required");let d=Array.isArray(a.nodes)?a.nodes:[],e=Array.isArray(a.edges)?a.edges:[],f=Array.isArray(a.triggers)?a.triggers:[],h=d.map(a=>String(a?.id??"").trim()).filter(Boolean);h.length!==d.length&&b.push("all nodes must have a non-empty id"),g(h)!==h.length&&b.push("node ids must be unique");let i=e.map(a=>String(a?.id??"").trim()).filter(Boolean);i.length!==e.length&&b.push("all edges must have a non-empty id"),g(i)!==i.length&&b.push("edge ids must be unique");let j=new Set(h);for(let a of e){let c=String(a?.from??"").trim(),d=String(a?.to??"").trim();if(!c||!d){b.push(`edge ${String(a?.id??"(missing id)")} must have from/to`);continue}j.has(c)||b.push(`edge ${String(a.id)} references missing from node: ${c}`),j.has(d)||b.push(`edge ${String(a.id)} references missing to node: ${d}`)}let k=d.filter(a=>"start"===a.type),l=d.filter(a=>"end"===a.type);for(let a of(k.length||c.push("no start node found"),k.length>1&&c.push("multiple start nodes found (MVP supports this, but execution semantics may be ambiguous)"),l.length||c.push("no end node found"),f))if("cron"===a.kind){(String(a.id||"").trim()||b.push("cron trigger missing id"),String(a.expr||"").trim())?5!==String(a.expr||"").trim().split(/\s+/).filter(Boolean).length&&c.push(`cron trigger ${String(a.id)} expr is not 5-field: ${String(a.expr)}`):b.push(`cron trigger ${String(a.id||"(missing id)")} missing expr`);let d=a.tz?String(a.tz).trim():"";d&&"UTC"!==d&&!d.includes("/")&&c.push(`cron trigger ${String(a.id)} tz doesn't look like an IANA timezone: ${String(a.tz)}`)}let m=a.meta&&"object"==typeof a.meta&&!Array.isArray(a.meta)?a.meta:{},n=String(m.approvalTarget??"").trim();for(let a of d){if("human_approval"!==a.type)continue;let b=a.config&&"object"==typeof a.config&&!Array.isArray(a.config)?a.config:{},d=String(b.target??b.chatId??"").trim(),e=String(b.provider??b.channel??"").trim();d||n||c.push(`human_approval node ${String(a.id)} has no target (set node.config.target or workflow.meta.approvalTarget)`),!d||e||String(m.approvalProvider??"").trim()||c.push(`human_approval node ${String(a.id)} has a target but no provider (set node.config.provider or workflow.meta.approvalProvider)`)}return{errors:b,warnings:c}}(bo.wf):{errors:[],warnings:[]},[bo.wf]),bq=(0,c.useMemo)(()=>{let a=bo.wf;if(!a)return{missingAgentOnNodeIds:[],requiredAgentIds:[],agentIdsMissingCron:[],ok:!0};let b=(a.nodes??[]).filter(a=>"start"!==a.type&&"end"!==a.type&&"human_approval"!==a.type),c=b.filter(a=>!String((a.config&&"object"==typeof a.config&&!Array.isArray(a.config)?a.config:{}).agentId??"").trim()).map(a=>a.id),d=Array.from(new Set(b.map(a=>String((a.config&&"object"==typeof a.config&&!Array.isArray(a.config)?a.config:{}).agentId??"").trim()).filter(Boolean))),e=d.filter(a=>!a1[a]),f=0===c.length&&0===e.length;return{missingAgentOnNodeIds:c,requiredAgentIds:d,agentIdsMissingCron:e,ok:f}},[bo.wf,a1]);function br(b){let c=JSON.stringify(b,null,2)+"\n";if(X({kind:"ready",jsonText:c}),j)try{sessionStorage.setItem(q(a,i),c)}catch{}}async function bs(){if("ready"===W.kind&&bo.wf&&!bo.err&&!bp.errors.length){V(!0),Z(""),_("idle"),ab("");try{let b=await fetch("/api/teams/workflows",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({teamId:a,workflow:bo.wf})}),c=await b.json();if(!b.ok||!c.ok)throw Error(c.error||"Failed to save workflow");try{sessionStorage.removeItem(q(a,i))}catch{}if(bo.wf.triggers?.length)try{_("syncing");let b=await fetch("/api/teams/workflow-triggers",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({action:"sync",teamId:a,workflowId:bo.wf.id,triggers:bo.wf.triggers??[]})}),c=await b.json();b.ok&&c.ok?(_("success"),setTimeout(()=>_("idle"),3e3)):(_("error"),ab(c.error||"Failed to sync triggers"))}catch(a){_("error"),ab(a instanceof Error?a.message:"Failed to sync triggers")}}catch(a){Z(a instanceof Error?a.message:String(a))}finally{V(!1)}}}if("loading"===W.kind)return(0,b.jsx)("div",{className:"w-full",children:"Loading…"});if("error"===W.kind)return(0,b.jsx)("div",{className:"w-full",children:W.error});let bt=!1===l?(0,b.jsxs)("div",{className:"mx-3 mb-3 rounded-lg border border-amber-500/30 bg-amber-500/10 p-3 text-sm",children:[(0,b.jsx)("div",{className:"font-medium text-amber-200",children:"LLM support is not enabled"}),(0,b.jsxs)("div",{className:"mt-1 text-[color:var(--ck-text-secondary)]",children:["Workflow LLM nodes require the optional built-in ",(0,b.jsx)("code",{className:"px-1",children:"llm-task"})," plugin."]}),(0,b.jsxs)("div",{className:"mt-2 text-[color:var(--ck-text-secondary)]",children:["Enable it with: ",(0,b.jsx)("code",{className:"px-1",children:"openclaw plugins enable llm-task"})," then run"," ",(0,b.jsx)("code",{className:"px-1",children:"openclaw gateway restart"}),"."]})]}):null;return(0,b.jsxs)("div",{className:"flex h-full min-h-0 w-full flex-1 flex-col",children:[(0,b.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-3 px-3 py-3",children:[(0,b.jsxs)("div",{className:"flex min-w-0 items-center gap-2",children:[(0,b.jsx)("a",{href:`/teams/${encodeURIComponent(a)}?tab=workflows`,className:"rounded-lg border border-white/10 bg-white/5 px-3 py-2 text-sm font-medium text-[color:var(--ck-text-primary)] hover:bg-white/10",children:"Back"}),(0,b.jsxs)("div",{className:"min-w-0",children:[(0,b.jsxs)("div",{className:"truncate text-base font-medium text-[color:var(--ck-text-primary)]",children:[i,".workflow.json"]}),(0,b.jsxs)("div",{className:"mt-0.5 text-sm text-[color:var(--ck-text-tertiary)]",children:["Team: ",a]})]})]}),(0,b.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,b.jsxs)("div",{className:"flex overflow-hidden rounded-lg border border-white/10",children:[(0,b.jsx)("button",{type:"button",onClick:()=>T("canvas"),className:"canvas"===S?"bg-white/10 px-3 py-2 text-xs font-medium text-[color:var(--ck-text-primary)]":"bg-transparent px-3 py-2 text-xs font-medium text-[color:var(--ck-text-secondary)] hover:bg-white/5",children:"Canvas"}),(0,b.jsx)("button",{type:"button",onClick:()=>T("json"),className:"json"===S?"bg-white/10 px-3 py-2 text-xs font-medium text-[color:var(--ck-text-primary)]":"bg-transparent px-3 py-2 text-xs font-medium text-[color:var(--ck-text-secondary)] hover:bg-white/5",children:"JSON"})]}),(0,b.jsx)("input",{ref:ac,type:"file",accept:"application/json,.json",className:"hidden",onChange:async b=>{let c=b.target.files?.[0];if(b.target.value="",c){Z("");try{let b=await c.text(),d=JSON.parse(b);if(X({kind:"ready",jsonText:JSON.stringify(d,null,2)+"\n"}),j)try{sessionStorage.setItem(q(a,i),JSON.stringify(d,null,2)+"\n")}catch{}}catch(a){Z(a instanceof Error?a.message:String(a))}}}}),(0,b.jsx)("button",{type:"button",disabled:U,onClick:()=>ac.current?.click(),className:"rounded-lg border border-white/10 bg-white/5 px-3 py-2 text-sm font-medium text-[color:var(--ck-text-primary)] shadow-[var(--ck-shadow-1)] hover:bg-white/10 disabled:opacity-50",children:"Import"}),(0,b.jsx)("button",{type:"button",disabled:!bo.wf||!!bo.err||bp.errors.length>0,onClick:function(){if(!bo.wf||bo.err||bp.errors.length)return;let a=`${bo.wf.id||i}.workflow.json`,b=new Blob([JSON.stringify(bo.wf,null,2)+"\n"],{type:"application/json"}),c=URL.createObjectURL(b),d=document.createElement("a");d.href=c,d.download=a,document.body.appendChild(d),d.click(),d.remove(),URL.revokeObjectURL(c)},className:"rounded-lg border border-white/10 bg-white/5 px-3 py-2 text-sm font-medium text-[color:var(--ck-text-primary)] shadow-[var(--ck-shadow-1)] hover:bg-white/10 disabled:opacity-50",children:"Export"}),(0,b.jsx)("button",{type:"button",disabled:U||!bo.wf||!!bo.err||bp.errors.length>0,onClick:bs,className:"rounded-lg bg-[var(--ck-accent-red)] px-3 py-2 text-sm font-medium text-white shadow-[var(--ck-shadow-1)] disabled:opacity-50",children:U?"Saving…":"Save"})]})]}),bt,bo.err?(0,b.jsxs)("div",{className:"mt-3 rounded-lg border border-yellow-400/30 bg-yellow-500/10 p-3 text-sm text-yellow-100",children:["JSON parse error: ",bo.err]}):null,!bo.err&&bp.errors.length?(0,b.jsxs)("div",{className:"mt-3 rounded-lg border border-red-400/30 bg-red-500/10 p-3 text-sm text-red-100",children:[(0,b.jsx)("div",{className:"font-medium",children:"Workflow validation errors"}),(0,b.jsx)("ul",{className:"mt-2 list-disc space-y-1 pl-5",children:bp.errors.map(a=>(0,b.jsx)("li",{children:a},a))})]}):null,bo.err||bp.errors.length||!bp.warnings.length?null:(0,b.jsxs)("div",{className:"mt-3 rounded-lg border border-yellow-400/30 bg-yellow-500/10 p-3 text-sm text-yellow-100",children:[(0,b.jsx)("div",{className:"font-medium",children:"Workflow validation warnings"}),(0,b.jsx)("ul",{className:"mt-2 list-disc space-y-1 pl-5",children:bp.warnings.map(a=>(0,b.jsx)("li",{children:a},a))})]}),Y?(0,b.jsx)("div",{className:"mt-3 rounded-lg border border-red-400/30 bg-red-500/10 p-3 text-sm text-red-100",children:Y}):null,(0,b.jsxs)("div",{className:"flex min-h-0 flex-1 gap-0",children:["json"===S?(0,b.jsx)("textarea",{value:W.jsonText,onChange:b=>{let c=b.target.value;if(X({kind:"ready",jsonText:c}),j)try{sessionStorage.setItem(q(a,i),c)}catch{}},className:"h-full min-h-0 w-full flex-1 resize-none rounded-lg border border-white/10 bg-white/5 p-3 font-mono text-xs text-[color:var(--ck-text-primary)]"}):(0,b.jsx)("div",{ref:ah,className:"relative h-full min-h-0 w-full flex-1 overflow-auto bg-white/5",onWheel:a=>{if(!a.ctrlKey&&!a.metaKey)return;a.preventDefault();let b=a.deltaY>0?-1:1;ag(a=>Math.max(.5,Math.min(2.5,Math.round((a+.1*b)*10)/10)))},onClick:a=>{if("add-node"!==am.kind)return;let b=bo.wf;if(!b)return;let c=ah.current;if(!c)return;let d=a.target;if(d&&d.closest("[data-wf-node='1']"))return;let e=c.getBoundingClientRect(),f=(a.clientX-e.left+c.scrollLeft)/af,g=(a.clientY-e.top+c.scrollTop)/af,i=am.nodeType.replace(/[^a-z0-9_\-]/gi,"_"),j=new Set(b.nodes.map(a=>a.id)),k=1,l=`${i}_${k}`;for(;j.has(l);)k++,l=`${i}_${k}`;let m=Math.max(0,f-90),n=Math.max(0,g-24),o=am.nodeType in h?{...h[am.nodeType].defaultConfig}:{},p={id:l,type:am.nodeType,name:l,x:m,y:n,config:o};br({...b,nodes:[...b.nodes,p]}),aj(l),an({kind:"select"})},children:(0,b.jsxs)("div",{className:"relative",style:{width:2200*af,height:1200*af},children:[(0,b.jsxs)("div",{className:ad?"absolute left-3 top-3 z-20 w-[44px] overflow-hidden rounded-lg border border-white/10 bg-black/40 p-2 backdrop-blur":"absolute left-3 top-3 z-20 w-[260px] rounded-lg border border-white/10 bg-black/40 p-2 backdrop-blur",children:[(0,b.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,b.jsx)("div",{className:ad?"hidden":"text-[10px] font-medium uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"Tools"}),(0,b.jsxs)("div",{className:"flex items-center gap-2",children:[(0,b.jsxs)("div",{className:ad?"hidden":"flex items-center gap-1",children:[(0,b.jsx)("button",{type:"button",onClick:()=>ag(a=>Math.max(.5,Math.round((a-.1)*10)/10)),className:"rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-[10px] text-[color:var(--ck-text-secondary)] hover:bg-white/10",title:"Zoom out (Ctrl/Cmd+wheel)",children:"-"}),(0,b.jsxs)("div",{className:"min-w-[42px] text-center text-[10px] text-[color:var(--ck-text-tertiary)]",children:[Math.round(100*af),"%"]}),(0,b.jsx)("button",{type:"button",onClick:()=>ag(a=>Math.min(2.5,Math.round((a+.1)*10)/10)),className:"rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-[10px] text-[color:var(--ck-text-secondary)] hover:bg-white/10",title:"Zoom in (Ctrl/Cmd+wheel)",children:"+"})]}),(0,b.jsx)("button",{type:"button",onClick:()=>ae(a=>!a),className:"rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-[10px] text-[color:var(--ck-text-secondary)] hover:bg-white/10",title:ad?"Expand":"Collapse",children:ad?">":"<"})]})]}),ad?(0,b.jsx)("div",{className:"mt-2 flex flex-col items-center gap-2",children:[{key:"select",label:"Select",active:"select"===am.kind,onClick:()=>{an({kind:"select"}),ap("")},icon:(0,b.jsx)("svg",{viewBox:"0 0 24 24",className:"h-4 w-4",fill:"none","aria-hidden":"true",children:(0,b.jsx)("path",{d:"M5 4l7 16 2-7 7-2L5 4Z",stroke:"currentColor",strokeWidth:"1.6",strokeLinejoin:"round"})})},{key:"connect",label:"Connect",active:"connect"===am.kind,onClick:()=>{an(a=>"connect"===a.kind?{kind:"select"}:{kind:"connect"}),ap("")},icon:(0,b.jsxs)("svg",{viewBox:"0 0 24 24",className:"h-4 w-4",fill:"none","aria-hidden":"true",children:[(0,b.jsx)("path",{d:"M10 13a5 5 0 0 1 0-7l1.2-1.2a5 5 0 0 1 7 7L17 12",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round"}),(0,b.jsx)("path",{d:"M14 11a5 5 0 0 1 0 7L12.8 19.2a5 5 0 1 1-7-7L7 12",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round"})]})},{key:"llm",label:"LLM",active:"add-node"===am.kind&&"llm"===am.nodeType,onClick:()=>{an({kind:"add-node",nodeType:"llm"}),ap("")},icon:(0,b.jsx)("svg",{viewBox:"0 0 24 24",className:"h-4 w-4",fill:"none","aria-hidden":"true",children:(0,b.jsx)("path",{d:"M12 2l1.5 6.5L20 10l-6.5 1.5L12 18l-1.5-6.5L4 10l6.5-1.5L12 2Z",stroke:"currentColor",strokeWidth:"1.6",strokeLinejoin:"round"})})},{key:"tool",label:"Tool",active:"add-node"===am.kind&&"tool"===am.nodeType,onClick:()=>{an({kind:"add-node",nodeType:"tool"}),ap("")},icon:(0,b.jsxs)("svg",{viewBox:"0 0 24 24",className:"h-4 w-4",fill:"none","aria-hidden":"true",children:[(0,b.jsx)("path",{d:"M14.5 7.5l2 2-8.5 8.5H6v-2l8.5-8.5Z",stroke:"currentColor",strokeWidth:"1.6",strokeLinejoin:"round"}),(0,b.jsx)("path",{d:"M12 6a4 4 0 0 0-5 5l3-3 2 2 3-3A4 4 0 0 0 12 6Z",stroke:"currentColor",strokeWidth:"1.6",strokeLinejoin:"round"})]})},{key:"condition",label:"If",active:"add-node"===am.kind&&"condition"===am.nodeType,onClick:()=>{an({kind:"add-node",nodeType:"condition"}),ap("")},icon:(0,b.jsxs)("svg",{viewBox:"0 0 24 24",className:"h-4 w-4",fill:"none","aria-hidden":"true",children:[(0,b.jsx)("path",{d:"M7 4v7a3 3 0 0 0 3 3h7",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round"}),(0,b.jsx)("path",{d:"M17 10l3 3-3 3",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round"})]})},{key:"delay",label:"Delay",active:"add-node"===am.kind&&"delay"===am.nodeType,onClick:()=>{an({kind:"add-node",nodeType:"delay"}),ap("")},icon:(0,b.jsxs)("svg",{viewBox:"0 0 24 24",className:"h-4 w-4",fill:"none","aria-hidden":"true",children:[(0,b.jsx)("path",{d:"M12 7v5l3 2",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round"}),(0,b.jsx)("path",{d:"M21 12a9 9 0 1 1-9-9",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round"})]})},{key:"approval",label:"Approval",active:"add-node"===am.kind&&"human_approval"===am.nodeType,onClick:()=>{an({kind:"add-node",nodeType:"human_approval"}),ap("")},icon:(0,b.jsx)("svg",{viewBox:"0 0 24 24",className:"h-4 w-4",fill:"none","aria-hidden":"true",children:(0,b.jsx)("path",{d:"M20 6 9 17l-5-5",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round"})})},{key:"end",label:"End",active:"add-node"===am.kind&&"end"===am.nodeType,onClick:()=>{an({kind:"add-node",nodeType:"end"}),ap("")},icon:(0,b.jsx)("svg",{viewBox:"0 0 24 24",className:"h-4 w-4",fill:"none","aria-hidden":"true",children:(0,b.jsx)("path",{d:"M7 7h10v10H7V7Z",stroke:"currentColor",strokeWidth:"1.6",strokeLinejoin:"round"})})},{key:"media-image",label:"Image",active:"add-node"===am.kind&&"media-image"===am.nodeType,onClick:()=>{an({kind:"add-node",nodeType:"media-image"}),ap("")},icon:(0,b.jsxs)("svg",{viewBox:"0 0 24 24",className:"h-4 w-4",fill:"none","aria-hidden":"true",children:[(0,b.jsx)("path",{d:"M14.5 4h-5L7 6.5 4.5 9v6L7 17.5 9.5 20h5L17 17.5 19.5 15V9L17 6.5 14.5 4Z",stroke:"currentColor",strokeWidth:"1.6",strokeLinejoin:"round"}),(0,b.jsx)("path",{d:"M9 10a1 1 0 1 0 0-2 1 1 0 0 0 0 2Z",fill:"currentColor"}),(0,b.jsx)("path",{d:"m4.5 15 3.5-3.5L11 14l3.5-3.5 4 4",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round"})]})},{key:"media-video",label:"Video",active:"add-node"===am.kind&&"media-video"===am.nodeType,onClick:()=>{an({kind:"add-node",nodeType:"media-video"}),ap("")},icon:(0,b.jsxs)("svg",{viewBox:"0 0 24 24",className:"h-4 w-4",fill:"none","aria-hidden":"true",children:[(0,b.jsx)("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round"}),(0,b.jsx)("path",{d:"M14 2v6h6",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round"}),(0,b.jsx)("path",{d:"M10 12l4.5 2.5-4.5 2.5v-5z",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round"})]})},{key:"handoff",label:"Handoff",active:"add-node"===am.kind&&"handoff"===am.nodeType,onClick:()=>{an({kind:"add-node",nodeType:"handoff"}),ap("")},icon:(0,b.jsxs)("svg",{viewBox:"0 0 24 24",className:"h-4 w-4",fill:"none","aria-hidden":"true",children:[(0,b.jsx)("path",{d:"M5 12h14",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round"}),(0,b.jsx)("path",{d:"M13 6l6 6-6 6",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round"}),(0,b.jsx)("path",{d:"M3 6v12",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round"})]})}].map(a=>(0,b.jsx)("button",{type:"button",onClick:a.onClick,className:a.active?"flex h-8 w-8 items-center justify-center rounded-lg bg-white/10 text-[color:var(--ck-text-primary)]":"flex h-8 w-8 items-center justify-center rounded-lg border border-white/10 bg-white/5 text-[color:var(--ck-text-secondary)] hover:bg-white/10",title:a.label,"aria-label":a.label,children:a.icon},a.key))}):(0,b.jsxs)("div",{className:"mt-2 grid grid-cols-2 gap-2",children:[(0,b.jsx)("button",{type:"button",onClick:()=>{an({kind:"select"}),ap("")},className:"select"===am.kind?"rounded-lg bg-white/10 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]":"rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-secondary)] hover:bg-white/10",children:"Select"}),(0,b.jsx)("button",{type:"button",onClick:()=>{an({kind:"connect"}),ap("")},className:"connect"===am.kind?"rounded-lg bg-white/10 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]":"rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-secondary)] hover:bg-white/10",title:"Click a node, then click another node to create an edge",children:"Connect"}),[{t:"llm",label:"LLM"},{t:"tool",label:"Tool"},{t:"condition",label:"If"},{t:"delay",label:"Delay"},{t:"human_approval",label:"Approve"},{t:"media-image",label:"🎨 Image"},{t:"media-video",label:"🎬 Video"},{t:"handoff",label:"↗ Handoff"},{t:"end",label:"End"}].map(a=>(0,b.jsxs)("button",{type:"button",onClick:()=>{an({kind:"add-node",nodeType:a.t}),ap("")},className:"add-node"===am.kind&&am.nodeType===a.t?"rounded-lg bg-white/10 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]":"rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-secondary)] hover:bg-white/10",title:"Select tool, then click on the canvas to place",children:["+ ",a.label]},a.t))]}),!ad&&"connect"===am.kind&&ao?(0,b.jsxs)("div",{className:"mt-2 text-xs text-[color:var(--ck-text-secondary)]",children:["Connecting from: ",(0,b.jsx)("span",{className:"font-mono",children:ao})]}):null,ad||"add-node"!==am.kind?null:(0,b.jsxs)("div",{className:"mt-2 text-xs text-[color:var(--ck-text-secondary)]",children:["Click on the canvas to place a ",(0,b.jsx)("span",{className:"font-mono",children:am.nodeType})," node."]}),(0,b.jsxs)("div",{className:"mt-3 border-t border-white/10 pt-3",children:[(0,b.jsxs)("div",{className:ad?"hidden":"flex items-center justify-between gap-2",children:[(0,b.jsx)("div",{className:"text-[10px] font-medium uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"Agents"}),(0,b.jsx)("div",{className:"text-[10px] text-[color:var(--ck-text-tertiary)]",children:"drag → node"})]}),ad?(0,b.jsx)("button",{type:"button",onClick:()=>ae(!1),className:"mt-2 flex h-8 w-8 items-center justify-center rounded-lg border border-white/10 bg-white/5 text-[color:var(--ck-text-secondary)] hover:bg-white/10",title:"Expand to see agents","aria-label":"Expand to see agents",children:(0,b.jsxs)("svg",{viewBox:"0 0 24 24",className:"h-4 w-4",fill:"none","aria-hidden":"true",children:[(0,b.jsx)("path",{d:"M16 11a4 4 0 1 0-8 0",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round"}),(0,b.jsx)("path",{d:"M4 20a8 8 0 0 1 16 0",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round"})]})}):(0,b.jsxs)(b.Fragment,{children:[as?(0,b.jsx)("div",{className:"mt-1 text-[11px] text-red-200",children:as}):null,(0,b.jsx)("div",{className:"mt-2 max-h-[140px] space-y-1 overflow-auto",children:aq.length?aq.map(c=>(0,b.jsx)("div",{draggable:!0,onDragStart:a=>{a.dataTransfer.setData("text/plain",c.id),a.dataTransfer.effectAllowed="copy"},className:"cursor-grab rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-secondary)] hover:bg-white/10",title:c.id,children:c.identityName?c.identityName:c.id.replace(`${a}-`,"")},c.id)):(0,b.jsx)("div",{className:"text-xs text-[color:var(--ck-text-tertiary)]",children:"No team agents found."})})]})]})]}),(0,b.jsxs)("div",{className:"relative h-[1200px] w-[2200px]",style:{transform:`scale(${af})`,transformOrigin:"0 0"},children:[(0,b.jsx)("svg",{className:"pointer-events-none absolute inset-0 -z-10",width:2200,height:1200,style:{overflow:"visible"},children:(bo.wf?.edges??[]).map(a=>{let c=bo.wf;if(!c)return null;let d=c.nodes.find(b=>b.id===a.from),e=c.nodes.find(b=>b.id===a.to);if(!d||!e)return null;let f=("number"==typeof d.x?d.x:80)+90,g=("number"==typeof d.y?d.y:80)+24,h=("number"==typeof e.x?e.x:80)+90,i=("number"==typeof e.y?e.y:80)+24;return(0,b.jsx)("line",{x1:f,y1:g,x2:h,y2:i,stroke:"rgba(255,255,255,0.35)",strokeWidth:3},a.id)})}),(bo.wf?.nodes??[]).map((c,d)=>{let e="number"==typeof c.x?c.x:80+220*d,f="number"==typeof c.y?c.y:80,g=ai===c.id;return(0,b.jsxs)("div",{role:"button",tabIndex:0,"data-wf-node":"1",draggable:"select"===am.kind||"connect"===am.kind,onDragStart:a=>{"select"===am.kind&&a.dataTransfer.setData("text/plain","")},onDragOver:a=>{a.dataTransfer.types.includes("text/plain")&&a.preventDefault()},onDrop:a=>{let b=bo.wf;if(!b)return;a.preventDefault(),a.stopPropagation();let d=String(a.dataTransfer.getData("text/plain")||"").trim();if(!d)return;let e=b.nodes.map(a=>{if(a.id!==c.id)return a;let b=a.config&&"object"==typeof a.config&&!Array.isArray(a.config)?a.config:{};return{...a,config:{...b,agentId:d}}});br({...b,nodes:e}),aj(c.id)},onClick:a=>{a.stopPropagation();let b=bo.wf;if("connect"===am.kind){if(!b)return;if(!ao){ap(c.id),aj(c.id);return}let a=c.id;if(ap(""),!ao||!a||ao===a||(b.edges??[]).some(b=>b.from===ao&&b.to===a))return;let d=`e${Date.now()}`;br({...b,edges:[...b.edges??[],{id:d,from:ao,to:a}]}),an({kind:"select"});return}aj(c.id)},onPointerDown:a=>{if("add-node"===am.kind||0!==a.button)return;let b=ah.current;if(!b)return;let d=b.getBoundingClientRect();aj(c.id);try{a.currentTarget.setPointerCapture(a.pointerId)}catch{}a.preventDefault();let g=(a.clientX-d.left+b.scrollLeft)/af,h=(a.clientY-d.top+b.scrollTop)/af;al({nodeId:c.id,dx:g-e,dy:h-f})},onPointerUp:a=>{try{a.currentTarget.releasePointerCapture(a.pointerId)}catch{}al(null)},onPointerMove:a=>{if(!ak||ak.nodeId!==c.id)return;let b=bo.wf;if(!b)return;let d=ah.current;if(!d)return;let e=d.getBoundingClientRect(),f=(a.clientX-e.left+d.scrollLeft)/af,g=(a.clientY-e.top+d.scrollTop)/af,h=f-ak.dx,i=g-ak.dy,j=b.nodes.map(a=>a.id===c.id?{...a,x:h,y:i}:a);X({kind:"ready",jsonText:JSON.stringify({...b,nodes:j},null,2)+"\n"})},className:g?"absolute z-10 cursor-grab rounded-lg border border-white/25 bg-white/10 px-3 py-2 text-xs text-[color:var(--ck-text-primary)] shadow-[var(--ck-shadow-1)]":"absolute z-10 cursor-grab rounded-lg border border-white/10 bg-white/5 px-3 py-2 text-xs text-[color:var(--ck-text-secondary)] hover:bg-white/10",style:{left:e,top:f,width:180},children:[(0,b.jsxs)("div",{className:"flex items-center gap-2",children:[c.type in h&&(0,b.jsx)("span",{className:"text-lg",children:"media-image"===c.type?"🎨":"🎬"}),"handoff"===c.type&&(0,b.jsx)("span",{className:"text-lg",children:"↗"}),(0,b.jsx)("div",{className:"font-medium text-[color:var(--ck-text-primary)]",children:c.name||c.id})]}),(0,b.jsx)("div",{className:"mt-0.5 text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:c.type}),(()=>{let d=c.config&&"object"==typeof c.config&&!Array.isArray(c.config)?c.config:null;if(c.type in h&&d){let a=String(d.prompt??"").trim(),c=String(d.provider??"auto");return(0,b.jsxs)("div",{className:"mt-1 space-y-0.5",children:[a&&(0,b.jsxs)("div",{className:"text-[10px] text-[color:var(--ck-text-secondary)] truncate",title:a,children:['"',a.length>40?a.substring(0,40)+"...":a,'"']}),(0,b.jsxs)("div",{className:"text-[10px] text-[color:var(--ck-text-tertiary)]",children:["Provider: ",c]})]})}if("handoff"===c.type&&d){let a=String(d.targetTeamId??"").trim(),c=String(d.targetWorkflowId??"").trim(),e=String(d.mode??"fire-and-forget");return a?(0,b.jsxs)("div",{className:"mt-1 text-[10px] text-[color:var(--ck-text-secondary)]",children:["→ ",a,c?` / ${c}`:"","wait-for-completion"===e?(0,b.jsx)("span",{className:"ml-1 text-yellow-400",title:"Waits for target to complete",children:"⏳"}):null]}):null}let e=d?String(d.agentId??"").trim():"";if(!e)return null;let f=e.replace(`${a}-`,"");return(0,b.jsxs)("div",{className:"mt-1 text-[10px] text-[color:var(--ck-text-secondary)]",children:["Agent: ",f]})})()]},c.id)}),(()=>{let c,d,e,f,g,i,j,l,m,n,p,q,r=bo.wf;if(!r||!ai)return null;let s=r.nodes.find(a=>a.id===ai);if(!s)return null;let t="number"==typeof s.x?s.x:80,u="number"==typeof s.y?s.y:80,v=s.config&&"object"==typeof s.config&&!Array.isArray(s.config)?s.config:{},w=String(v.agentId??"").trim(),x=String(v.model??"").trim();return(0,b.jsxs)("div",{className:"absolute z-10 w-[320px] rounded-lg border border-white/15 bg-black/60 p-3 shadow-[var(--ck-shadow-1)] backdrop-blur",style:{left:t+200,top:u},children:[(0,b.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,b.jsx)("div",{className:"text-xs font-medium text-[color:var(--ck-text-primary)]",children:s.name||s.id}),(0,b.jsx)("button",{type:"button",onClick:()=>aj(""),className:"text-[10px] text-[color:var(--ck-text-tertiary)] hover:text-[color:var(--ck-text-primary)]",children:"Close"})]}),(0,b.jsxs)("div",{className:"mt-2 space-y-2",children:[(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"name"}),(0,b.jsx)("input",{value:String(s.name??""),onChange:a=>{let b=a.target.value;br({...r,nodes:r.nodes.map(a=>a.id===s.id?{...a,name:b}:a)})},className:"mt-1 w-full rounded-lg border border-white/10 bg-black/30 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",placeholder:"Optional"})]}),(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"type"}),(0,b.jsxs)("select",{value:s.type,onChange:a=>{let b=a.target.value;br({...r,nodes:r.nodes.map(a=>a.id===s.id?{...a,type:b}:a)})},className:"mt-1 w-full rounded-lg border border-white/10 bg-black/30 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",children:[(0,b.jsx)("option",{value:"start",children:"start"}),(0,b.jsx)("option",{value:"end",children:"end"}),(0,b.jsx)("option",{value:"llm",children:"llm"}),(0,b.jsx)("option",{value:"tool",children:"tool"}),(0,b.jsx)("option",{value:"condition",children:"condition"}),(0,b.jsx)("option",{value:"delay",children:"delay"}),(0,b.jsx)("option",{value:"human_approval",children:"human_approval"}),(0,b.jsx)("option",{value:"media-image",children:"media-image"}),(0,b.jsx)("option",{value:"media-video",children:"media-video"}),(0,b.jsx)("option",{value:"handoff",children:"handoff"})]})]}),(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"agentId"}),(0,b.jsx)("input",{value:w,onChange:a=>{let b=String(a.target.value||"").trim(),c={...v,...b?{agentId:b}:{}};b||delete c.agentId,br({...r,nodes:r.nodes.map(a=>a.id===s.id?{...a,config:c}:a)})},className:"mt-1 w-full rounded-lg border border-white/10 bg-black/30 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",placeholder:"(drag an agent onto the node or type)"})]}),"llm"===s.type?(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"model"}),(0,b.jsxs)("select",{value:x,onChange:a=>{let b=String(a.target.value||"").trim(),c={...v,...b?{model:b}:{}};b||delete c.model,br({...r,nodes:r.nodes.map(a=>a.id===s.id?{...a,config:c}:a)})},className:"mt-1 w-full rounded-lg border border-white/10 bg-black/30 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",children:[(0,b.jsx)("option",{value:"",children:"Default (inherit global)"}),ay.map(a=>(0,b.jsx)("option",{value:a,children:a},a))]}),aA?(0,b.jsxs)("div",{className:"mt-1 text-[10px] text-amber-300",children:["Could not load model list: ",aA]}):null]}):null,"human_approval"===s.type?(0,b.jsxs)("div",{className:"rounded-lg border border-white/10 bg-white/5 p-2",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"approval config"}),(0,b.jsxs)("div",{className:"mt-2 space-y-2",children:[(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"provider"}),(0,b.jsx)("input",{value:String(v.provider??""),onChange:a=>{let b=String(a.target.value||"").trim(),c={...v,...b?{provider:b}:{}};b||delete c.provider,br({...r,nodes:r.nodes.map(a=>a.id===s.id?{...a,config:c}:a)})},className:"mt-1 w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",placeholder:"telegram"})]}),(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"target"}),(0,b.jsx)("input",{value:String(v.target??""),onChange:a=>{let b=String(a.target.value||"").trim(),c={...v,...b?{target:b}:{}};b||delete c.target,br({...r,nodes:r.nodes.map(a=>a.id===s.id?{...a,config:c}:a)})},className:"mt-1 w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",placeholder:"(e.g. Telegram chat id)"}),(0,b.jsx)("div",{className:"mt-1 text-[10px] text-[color:var(--ck-text-tertiary)]",children:"Overrides workflow-level default when set."})]}),(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"messageTemplate (optional)"}),(0,b.jsx)(o,{value:String(v.messageTemplate??""),workflow:r,currentNodeId:s.id,onChangeValue:a=>{let b={...v,...a.trim()?{messageTemplate:a}:{}};a.trim()||delete b.messageTemplate,br({...r,nodes:r.nodes.map(a=>a.id===s.id?{...a,config:b}:a)})},className:"mt-1 h-[70px] w-full resize-none rounded-lg border border-white/10 bg-white/5 p-2 pr-12 font-mono text-[10px] text-[color:var(--ck-text-primary)]",placeholder:"Approval needed for {{workflowName}} (run {{runId}})",spellCheck:!1}),(0,b.jsxs)("div",{className:"mt-1 text-[10px] text-[color:var(--ck-text-tertiary)]",children:["Vars: ","{{workflowName}}",", ","{{workflowId}}",", ","{{runId}}",", ","{{nodeId}}"]})]})]})]}):null,s.type in h?(0,b.jsxs)("div",{className:"rounded-lg border border-white/10 bg-white/5 p-2",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"Media Generation"}),(0,b.jsx)("div",{className:"mt-2",children:(0,b.jsx)(k,{config:{mediaType:"image",provider:"auto",prompt:"",...s.config||{}},onChange:a=>{br({...r,nodes:r.nodes.map(b=>b.id===s.id?{...b,config:a}:b)})},teamId:a,workflow:r,workflowNodeIds:r.nodes.map(a=>a.id),workflowEdges:(r.edges??[]).map(a=>({from:a.from,to:a.to})),currentNodeId:s.id})})]}):null,"llm"===s.type?(0,b.jsxs)("div",{className:"space-y-2",children:[(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"prompt"}),(0,b.jsx)(o,{value:String(v.promptTemplate??""),workflow:r,currentNodeId:s.id,onChangeValue:a=>{let b={...v,promptTemplate:a};br({...r,nodes:r.nodes.map(a=>a.id===s.id?{...a,config:b}:a)})},className:"mt-1 min-h-[200px] w-full resize-y rounded-lg border border-white/10 bg-black/30 p-2 pr-12 font-mono text-xs text-[color:var(--ck-text-primary)]",placeholder:"What should this node do? Use {{nodeId.output}} to reference upstream node outputs.",spellCheck:!1})]}),(0,b.jsxs)("div",{children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"output fields (optional)"}),(0,b.jsx)("div",{className:"text-[9px] text-[color:var(--ck-text-secondary)] mb-2",children:"Define the structure of what this node should produce"}),(c=v.outputFields||[],(0,b.jsxs)("div",{className:"space-y-1",children:[c.map((a,d)=>(0,b.jsxs)("div",{className:"flex items-center gap-2",children:[(0,b.jsx)("input",{value:a.name,onChange:b=>{let e=[...c];e[d]={...a,name:b.target.value};let f={...v,outputFields:e};br({...r,nodes:r.nodes.map(a=>a.id===s.id?{...a,config:f}:a)})},className:"flex-1 rounded-lg border border-white/10 bg-black/30 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",placeholder:"Field name"}),(0,b.jsxs)("select",{value:a.type,onChange:b=>{let e=b.target.value,f=[...c];f[d]={...a,type:e};let g={...v,outputFields:f};br({...r,nodes:r.nodes.map(a=>a.id===s.id?{...a,config:g}:a)})},className:"rounded-lg border border-white/10 bg-black/30 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",children:[(0,b.jsx)("option",{value:"text",children:"text"}),(0,b.jsx)("option",{value:"list",children:"list"}),(0,b.jsx)("option",{value:"json",children:"json"})]}),(0,b.jsx)("button",{type:"button",onClick:()=>{let a=c.filter((a,b)=>b!==d),b={...v};a.length>0?b.outputFields=a:delete b.outputFields,br({...r,nodes:r.nodes.map(a=>a.id===s.id?{...a,config:b}:a)})},className:"text-xs text-[color:var(--ck-text-tertiary)] hover:text-[color:var(--ck-text-primary)]",children:"×"})]},d)),(0,b.jsx)("button",{type:"button",onClick:()=>{let a=[...c,{name:"",type:"text"}],b={...v,outputFields:a};br({...r,nodes:r.nodes.map(a=>a.id===s.id?{...a,config:b}:a)})},className:"text-xs text-[color:var(--ck-text-secondary)] hover:text-[color:var(--ck-text-primary)]",children:"+ Add field"})]}))]}),(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"timeout (seconds)"}),(0,b.jsx)("input",{type:"number",value:v.timeoutMs?String(Number(v.timeoutMs)/1e3):"",onChange:a=>{let b=a.target.value?Number(a.target.value):null,c={...v};b&&b>0?c.timeoutMs=1e3*b:delete c.timeoutMs,br({...r,nodes:r.nodes.map(a=>a.id===s.id?{...a,config:c}:a)})},className:"mt-1 w-24 rounded-lg border border-white/10 bg-black/30 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",placeholder:"120",min:"1"})]})]}):null,"handoff"===s.type?(d=String(v.targetTeamId??""),e=String(v.targetWorkflowId??""),f=v.variableMapping||{},g=String(v.mode??"fire-and-forget"),j=aI[i=String(f.kitchenTeamId??"").includes("{{")?a:String(f.kitchenTeamId??a)]||[],l=!!aK[i],m=String(f.integrationIds??f.integrationId??"").split(",").map(a=>a.trim()).filter(Boolean),n=aE[d]||[],p=e.toLowerCase().includes("instagram")||Object.prototype.hasOwnProperty.call(f,"integrationId")||Object.prototype.hasOwnProperty.call(f,"integrationIds"),q=a=>{let b={...v,...a};br({...r,nodes:r.nodes.map(a=>a.id===s.id?{...a,config:b}:a)})},0!==aC.length||aG||(async()=>{try{let a=await fetch("/api/teams/list"),b=await a.json();b.ok&&aD(b.teamIds)}catch{}})(),d&&!aE[d]&&(async()=>{try{let a=await fetch(`/api/teams/workflows?teamId=${encodeURIComponent(d)}`),b=await a.json();b.ok&&b.files&&aF(a=>({...a,[d]:b.files.map(a=>({id:a.replace(/\.workflow\.json$/,"")}))}))}catch{}})(),p&&i&&!aI[i]&&!aK[i]&&(async()=>{aL(a=>({...a,[i]:!0}));try{let a=(()=>{try{return JSON.parse(localStorage.getItem(`ck-postiz-${i}`)||"{}").apiKey||""}catch{return""}})(),b=await fetch(`/api/plugins/marketing/drivers?team=${encodeURIComponent(i)}&teamId=${encodeURIComponent(i)}`,{headers:a?{"x-postiz-api-key":a}:{}}),c=((await b.json()).drivers||[]).filter(a=>"instagram"===a.platform&&a.integrationId).map(a=>({integrationId:String(a.integrationId),displayName:String(a.displayName||a.username||"Instagram"),username:a.username?String(a.username):void 0}));aJ(a=>({...a,[i]:c}))}catch{}aL(a=>({...a,[i]:!1}))})(),(0,b.jsxs)("div",{className:"rounded-lg border border-white/10 bg-white/5 p-2 space-y-2",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"handoff config"}),(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"mode"}),(0,b.jsxs)("select",{value:g,onChange:a=>q({mode:"fire-and-forget"===a.target.value?void 0:a.target.value}),className:"mt-1 w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",children:[(0,b.jsx)("option",{value:"fire-and-forget",children:"Fire & Forget"}),(0,b.jsx)("option",{value:"wait-for-completion",children:"Wait for Completion"})]})]}),(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"target team"}),(0,b.jsxs)("select",{value:d,onChange:a=>{q({targetTeamId:a.target.value||void 0,targetWorkflowId:void 0})},className:"mt-1 w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",children:[(0,b.jsx)("option",{value:"",children:"— Select —"}),aC.map(c=>(0,b.jsxs)("option",{value:c,children:[c,c===a?" (current)":""]},c))]})]}),d?(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"target workflow"}),(0,b.jsxs)("select",{value:e,onChange:a=>q({targetWorkflowId:a.target.value||void 0}),className:"mt-1 w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",children:[(0,b.jsx)("option",{value:"",children:"— Select —"}),n.map(a=>(0,b.jsx)("option",{value:a.id,children:a.name||a.id},a.id))]})]}):null,p&&j.length>0?(0,b.jsxs)("div",{children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"instagram accounts"}),(0,b.jsx)("div",{className:"mt-1 space-y-1",children:j.map(a=>{let c=m.includes(a.integrationId);return(0,b.jsxs)("label",{className:"flex items-center gap-2 cursor-pointer rounded-lg border border-white/10 bg-white/5 px-2 py-1 hover:bg-white/10",children:[(0,b.jsx)("input",{type:"checkbox",checked:c,onChange:()=>{let b=c?m.filter(b=>b!==a.integrationId):[...m,a.integrationId],d={...f};delete d.integrationId,b.length>0?d.integrationIds=b.join(","):delete d.integrationIds,q({variableMapping:d})},className:"accent-[var(--ck-accent-red)]"}),(0,b.jsxs)("div",{children:[(0,b.jsx)("div",{className:"text-xs text-[color:var(--ck-text-primary)]",children:a.displayName}),a.username?(0,b.jsx)("div",{className:"text-[10px] text-[color:var(--ck-text-tertiary)]",children:a.username}):null]})]},a.integrationId)})})]}):null,p&&l?(0,b.jsx)("div",{className:"text-[10px] text-[color:var(--ck-text-tertiary)]",children:"Loading accounts…"}):null]})):null,(0,b.jsxs)("div",{children:[(0,b.jsxs)("button",{type:"button",onClick:()=>{let a=aM[s.id]??"llm"!==s.type;aN({...aM,[s.id]:!a})},className:"mb-2 text-[10px] text-[color:var(--ck-text-tertiary)] hover:text-[color:var(--ck-text-primary)]",children:[aM[s.id]??"llm"!==s.type?"Hide":"Show"," raw config"]}),aM[s.id]??"llm"!==s.type?(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"config (json)"}),(0,b.jsx)("textarea",{value:JSON.stringify(v,null,2),onChange:a=>{try{let b=JSON.parse(a.target.value);if(!b||"object"!=typeof b||Array.isArray(b))return;br({...r,nodes:r.nodes.map(a=>a.id===s.id?{...a,config:b}:a)})}catch{}},className:"mt-1 h-[140px] w-full resize-none rounded-lg border border-white/10 bg-black/30 p-2 font-mono text-[10px] text-[color:var(--ck-text-primary)]",spellCheck:!1}),(0,b.jsx)("div",{className:"mt-1 text-[10px] text-[color:var(--ck-text-tertiary)]",children:"(Edits apply when JSON is valid.)"})]}):null]})]})]})})()]})]})}),(0,b.jsx)("div",{className:"w-[380px] shrink-0 overflow-auto p-3 text-sm",children:(0,b.jsx)("div",{className:"space-y-3",children:bo.wf?(K=String((J=bo.wf).timezone??"").trim()||"UTC",L=J.triggers??[],N=String((M=J.meta&&"object"==typeof J.meta&&!Array.isArray(J.meta)?J.meta:{}).approvalBindingId??"").trim(),O=String(M.approvalProvider??"telegram").trim()||"telegram",P=String(M.approvalTarget??"").trim(),Q=[{label:"(no preset)",expr:""},{label:"Weekdays 09:00 local",expr:"0 9 * * 1-5"},{label:"Mon/Wed/Fri 09:00 local",expr:"0 9 * * 1,3,5"},{label:"Daily 08:00 local",expr:"0 8 * * *"},{label:"Daily 12:00 local",expr:"0 12 * * *"},{label:"Mon 09:30 local",expr:"30 9 * * 1"}],(0,b.jsxs)("div",{className:"space-y-3",children:[(0,b.jsxs)("details",{open:!0,className:"rounded-lg border border-white/10 bg-white/5",children:[(0,b.jsx)("summary",{className:"cursor-pointer list-none px-3 py-2 text-sm font-medium text-[color:var(--ck-text-primary)]",children:"Workflow"}),(0,b.jsx)("div",{className:"px-3 pb-3",children:(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[11px] font-medium text-[color:var(--ck-text-tertiary)]",children:"Timezone"}),(0,b.jsx)("input",{value:K,onChange:a=>{let b=String(a.target.value||"").trim()||"UTC";br({...J,timezone:b})},className:"mt-1 w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-sm text-[color:var(--ck-text-primary)]",placeholder:"America/New_York"})]})})]}),(0,b.jsxs)("details",{open:!0,className:"rounded-lg border border-white/10 bg-white/5",children:[(0,b.jsx)("summary",{className:"cursor-pointer list-none px-3 py-2 text-sm font-medium text-[color:var(--ck-text-primary)]",children:"Approval Channel"}),(0,b.jsxs)("div",{className:"px-3 pb-3 space-y-2",children:[(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"binding (recommended)"}),(0,b.jsxs)("select",{value:N,onChange:a=>{let b=String(a.target.value||"").trim(),c=au.find(a=>a.id===b);c?br({...J,meta:{...M,approvalBindingId:c.id,approvalProvider:c.channel,approvalTarget:c.target},nodes:J.nodes.map(a=>"human_approval"===a.type?{...a,config:{...a.config&&"object"==typeof a.config&&!Array.isArray(a.config)?a.config:{},approvalBindingId:c.id,provider:c.channel,target:c.target}}:a)}):br({...J,meta:{...M,approvalBindingId:""},nodes:J.nodes.map(a=>"human_approval"===a.type?{...a,config:{...a.config&&"object"==typeof a.config&&!Array.isArray(a.config)?a.config:{},approvalBindingId:""}}:a)})},className:"mt-1 w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",children:[(0,b.jsx)("option",{value:"",children:"(manual)"}),au.map(a=>(0,b.jsx)("option",{value:a.id,children:a.label},a.id))]}),aO?(0,b.jsxs)("div",{className:"mt-1 text-[10px] text-yellow-200",children:["Kitchen looks out of date. Run ",(0,b.jsx)("code",{className:"font-mono",children:"openclaw plugins update"})," then",(0,b.jsx)("code",{className:"ml-1 font-mono",children:"openclaw gateway restart"}),"."]}):null,aw?(0,b.jsxs)("div",{className:"mt-1 text-[10px] text-red-200",children:["Failed to load bindings: ",aw]}):null,(0,b.jsx)("div",{className:"mt-1 text-[10px] text-[color:var(--ck-text-tertiary)]",children:"Uses your existing OpenClaw bindings (recommended). Manual provider/target is an advanced override."})]}),(0,b.jsxs)("details",{className:"rounded-lg border border-white/10 bg-black/10",children:[(0,b.jsx)("summary",{className:"cursor-pointer list-none px-2 py-1 text-[11px] font-medium text-[color:var(--ck-text-secondary)]",children:"Advanced: manual override"}),(0,b.jsxs)("div",{className:"px-2 pb-2 pt-1 space-y-2",children:[(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"provider"}),(0,b.jsx)("input",{value:O,onChange:a=>{let b=String(a.target.value||"").trim()||"telegram";br({...J,meta:{...M,approvalBindingId:"",approvalProvider:b},nodes:J.nodes.map(a=>"human_approval"===a.type?{...a,config:{...a.config&&"object"==typeof a.config&&!Array.isArray(a.config)?a.config:{},approvalBindingId:"",provider:b}}:a)})},className:"mt-1 w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",placeholder:"telegram"})]}),(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"target"}),(0,b.jsx)("input",{value:P,onChange:a=>{let b=String(a.target.value||"").trim();br({...J,meta:{...M,approvalBindingId:"",approvalTarget:b},nodes:J.nodes.map(a=>"human_approval"===a.type?{...a,config:{...a.config&&"object"==typeof a.config&&!Array.isArray(a.config)?a.config:{},approvalBindingId:"",target:b}}:a)})},className:"mt-1 w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",placeholder:"(e.g. Telegram chat id)"})]})]})]})]})]}),(0,b.jsxs)("details",{open:!0,className:"rounded-lg border border-white/10 bg-white/5",children:[(0,b.jsx)("summary",{className:"cursor-pointer list-none px-3 py-2 text-sm font-medium text-[color:var(--ck-text-primary)]",children:"Node inspector"}),(0,b.jsxs)("div",{className:"px-3 pb-3",children:[(0,b.jsx)("div",{className:"flex items-center justify-between gap-2",children:ai?(0,b.jsx)("button",{type:"button",onClick:()=>{let a=J.nodes.filter(a=>a.id!==ai),b=(J.edges??[]).filter(a=>a.from!==ai&&a.to!==ai);br({...J,nodes:a,edges:b}),aj("")},className:"rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-[10px] font-medium text-red-100 hover:bg-white/10",children:"Delete node"}):null}),ai?(I=J.nodes.find(a=>a.id===ai))?(0,b.jsxs)("div",{className:"mt-3 space-y-3",children:[(0,b.jsxs)("div",{children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"id"}),(0,b.jsx)("div",{className:"mt-1 rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",children:I.id})]}),(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"name"}),(0,b.jsx)("input",{value:String(I.name??""),onChange:a=>{let b=a.target.value;br({...J,nodes:J.nodes.map(a=>a.id===I.id?{...a,name:b}:a)})},className:"mt-1 w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",placeholder:"Optional"})]}),(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"type"}),(0,b.jsxs)("select",{value:I.type,onChange:a=>{let b=a.target.value;br({...J,nodes:J.nodes.map(a=>a.id===I.id?{...a,type:b}:a)})},className:"mt-1 w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",children:[(0,b.jsx)("option",{value:"start",children:"start"}),(0,b.jsx)("option",{value:"end",children:"end"}),(0,b.jsx)("option",{value:"llm",children:"llm"}),(0,b.jsx)("option",{value:"tool",children:"tool"}),(0,b.jsx)("option",{value:"condition",children:"condition"}),(0,b.jsx)("option",{value:"delay",children:"delay"}),(0,b.jsx)("option",{value:"human_approval",children:"human_approval"}),(0,b.jsx)("option",{value:"media-image",children:"media-image"}),(0,b.jsx)("option",{value:"media-video",children:"media-video"}),(0,b.jsx)("option",{value:"handoff",children:"handoff"})]})]}),(0,b.jsxs)("div",{className:"grid grid-cols-2 gap-2",children:[(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"x"}),(0,b.jsx)("input",{type:"number",value:"number"==typeof I.x?I.x:0,onChange:a=>{let b=Number(a.target.value);br({...J,nodes:J.nodes.map(a=>a.id===I.id?{...a,x:b}:a)})},className:"mt-1 w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]"})]}),(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"y"}),(0,b.jsx)("input",{type:"number",value:"number"==typeof I.y?I.y:0,onChange:a=>{let b=Number(a.target.value);br({...J,nodes:J.nodes.map(a=>a.id===I.id?{...a,y:b}:a)})},className:"mt-1 w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]"})]})]}),"llm"===I.type?(0,b.jsxs)("div",{className:"space-y-3",children:[(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"prompt"}),(0,b.jsx)(o,{value:String((I.config||{}).promptTemplate??""),workflow:J,currentNodeId:I.id,onChangeValue:a=>{let b={...I.config,promptTemplate:a};br({...J,nodes:J.nodes.map(a=>a.id===I.id?{...a,config:b}:a)})},className:"mt-1 min-h-[150px] w-full resize-y rounded-lg border border-white/10 bg-white/5 p-2 pr-12 font-mono text-xs text-[color:var(--ck-text-primary)]",placeholder:"What should this node do? Use {{nodeId.output}} to reference upstream node outputs.",spellCheck:!1})]}),(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"model"}),(0,b.jsxs)("select",{value:String((I.config||{}).model??""),onChange:a=>{let b=String(a.target.value||"").trim(),c={...I.config,...b?{model:b}:{}};b||delete c.model,br({...J,nodes:J.nodes.map(a=>a.id===I.id?{...a,config:c}:a)})},className:"mt-1 w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",children:[(0,b.jsx)("option",{value:"",children:"Default (inherit global)"}),ay.map(a=>(0,b.jsx)("option",{value:a,children:a},a))]}),aA?(0,b.jsxs)("div",{className:"mt-1 text-[10px] text-amber-300",children:["Could not load model list: ",aA]}):null]}),(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"timeout (seconds)"}),(0,b.jsx)("input",{type:"number",value:(I.config||{}).timeoutMs?String(Number((I.config||{}).timeoutMs)/1e3):"",onChange:a=>{let b=a.target.value?Number(a.target.value):null,c={...I.config};b&&b>0?c.timeoutMs=1e3*b:delete c.timeoutMs,br({...J,nodes:J.nodes.map(a=>a.id===I.id?{...a,config:c}:a)})},className:"mt-1 w-24 rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",placeholder:"120",min:"1"})]})]}):null,I.type in h?(0,b.jsxs)("div",{children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"Media Generation"}),(0,b.jsx)("div",{className:"mt-1",children:(0,b.jsx)(k,{config:{mediaType:"image",provider:"auto",prompt:"",...I.config||{}},onChange:a=>{br({...J,nodes:J.nodes.map(b=>b.id===I.id?{...b,config:a}:b)})},teamId:a,workflow:J,workflowNodeIds:J.nodes.map(a=>a.id),workflowEdges:(J.edges??[]).map(a=>({from:a.from,to:a.to})),currentNodeId:I.id})})]}):null,"human_approval"===I.type?(0,b.jsxs)("div",{className:"space-y-2",children:[(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"provider"}),(0,b.jsx)("input",{value:String((I.config||{}).provider??""),onChange:a=>{let b=String(a.target.value||"").trim(),c={...I.config,...b?{provider:b}:{}};b||delete c.provider,br({...J,nodes:J.nodes.map(a=>a.id===I.id?{...a,config:c}:a)})},className:"mt-1 w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",placeholder:"telegram"})]}),(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"target"}),(0,b.jsx)("input",{value:String((I.config||{}).target??""),onChange:a=>{let b=String(a.target.value||"").trim(),c={...I.config,...b?{target:b}:{}};b||delete c.target,br({...J,nodes:J.nodes.map(a=>a.id===I.id?{...a,config:c}:a)})},className:"mt-1 w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",placeholder:"(e.g. Telegram chat id)"}),(0,b.jsx)("div",{className:"mt-1 text-[10px] text-[color:var(--ck-text-tertiary)]",children:"Overrides workflow-level default when set."})]}),(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"messageTemplate (optional)"}),(0,b.jsx)(o,{value:String((I.config||{}).messageTemplate??""),workflow:J,currentNodeId:I.id,onChangeValue:a=>{let b={...I.config,...a.trim()?{messageTemplate:a}:{}};a.trim()||delete b.messageTemplate,br({...J,nodes:J.nodes.map(a=>a.id===I.id?{...a,config:b}:a)})},className:"mt-1 h-[70px] w-full resize-none rounded-lg border border-white/10 bg-white/5 p-2 pr-12 font-mono text-[10px] text-[color:var(--ck-text-primary)]",placeholder:"Approval needed for {{workflowName}} (run {{runId}})",spellCheck:!1}),(0,b.jsxs)("div",{className:"mt-1 text-[10px] text-[color:var(--ck-text-tertiary)]",children:["Vars: ","{{workflowName}}",", ","{{workflowId}}",", ","{{runId}}",", ","{{nodeId}}"]})]})]}):null,"handoff"===I.type?(r=String((n=I.config||{}).targetTeamId??""),s=String(n.targetWorkflowId??""),t=n.variableMapping||{},u=async()=>{if(!(aC.length>0)&&!aG){aH(!0);try{let a=await fetch("/api/teams/list"),b=await a.json();b.ok&&Array.isArray(b.teamIds)&&aD(b.teamIds)}catch{}aH(!1)}},v=async a=>{if(a&&!aE[a])try{let b=await fetch(`/api/teams/workflows?teamId=${encodeURIComponent(a)}`),c=await b.json();if(c.ok&&Array.isArray(c.files)){let b=c.files.map(a=>({id:a.replace(/\.workflow\.json$/,"")}));aF(c=>({...c,[a]:b}))}}catch{}},w=async a=>{if(a&&!aI[a]&&!aK[a]){aL(b=>({...b,[a]:!0}));try{let b=(()=>{try{let b=localStorage.getItem(`ck-postiz-${a}`);return b&&JSON.parse(b).apiKey||""}catch{return""}})(),c=await fetch(`/api/plugins/marketing/drivers?team=${encodeURIComponent(a)}&teamId=${encodeURIComponent(a)}`,{headers:b?{"x-postiz-api-key":b}:{}}),d=await c.json(),e=(Array.isArray(d?.drivers)?d.drivers:[]).filter(a=>a?.platform==="instagram"&&a?.integrationId).map(a=>({integrationId:String(a.integrationId),displayName:String(a.displayName||a.username||"Instagram"),username:a.username?String(a.username):void 0}));aJ(b=>({...b,[a]:e}))}catch{}aL(b=>({...b,[a]:!1}))}},y=(x=String(t.kitchenTeamId??""))&&!x.includes("{{")?x:a,0!==aC.length||aG||u(),r&&!aE[r]&&v(r),(z=s.toLowerCase().includes("instagram")||Object.prototype.hasOwnProperty.call(t,"integrationId")||Object.prototype.hasOwnProperty.call(t,"integrationIds"))&&y&&!aI[y]&&!aK[y]&&w(y),A=aE[r]||[],B=Object.entries(t),C=y&&aI[y]||[],D=!!y&&!!aK[y],E=String(t.integrationIds??t.integrationId??"").split(",").map(a=>a.trim()).filter(Boolean),F=a=>{let b={...n,...a};br({...J,nodes:J.nodes.map(a=>a.id===I.id?{...a,config:b}:a)})},G=String(n.mode??"fire-and-forget"),H="number"==typeof n.waitTimeoutMs?n.waitTimeoutMs:3e5,(0,b.jsxs)("div",{className:"space-y-2",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"Handoff Target"}),(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"mode"}),(0,b.jsxs)("select",{value:G,onChange:a=>{let b=a.target.value;F({mode:"fire-and-forget"===b?void 0:b})},className:"mt-1 w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",children:[(0,b.jsx)("option",{value:"fire-and-forget",children:"Fire & Forget"}),(0,b.jsx)("option",{value:"wait-for-completion",children:"Wait for Completion"})]})]}),"wait-for-completion"===G?(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"wait timeout (seconds)"}),(0,b.jsx)("input",{type:"number",min:30,value:Math.round(H/1e3),onChange:a=>{F({waitTimeoutMs:1e3*Math.max(30,parseInt(a.target.value,10)||300)})},className:"mt-1 w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]"}),(0,b.jsx)("div",{className:"mt-0.5 text-[9px] text-[color:var(--ck-text-tertiary)]",children:"Workflow will wait up to this long for the target to complete."})]}):null,(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"target team"}),(0,b.jsxs)("select",{value:r,onChange:a=>{let b=a.target.value;F({targetTeamId:b||void 0,targetWorkflowId:void 0}),b&&!aE[b]&&v(b)},className:"mt-1 w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",children:[(0,b.jsx)("option",{value:"",children:"— Select team —"}),aC.map(c=>(0,b.jsxs)("option",{value:c,children:[c,c===a?" (current)":""]},c))]})]}),r?(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"target workflow"}),(0,b.jsxs)("select",{value:s,onChange:a=>F({targetWorkflowId:a.target.value||void 0}),className:"mt-1 w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",children:[(0,b.jsx)("option",{value:"",children:"— Select workflow —"}),A.map(a=>(0,b.jsx)("option",{value:a.id,children:a.name||a.id},a.id))]}),r&&!aE[r]?(0,b.jsx)("div",{className:"mt-1 text-[10px] text-[color:var(--ck-text-tertiary)]",children:"Loading workflows…"}):null]}):null,z?(0,b.jsxs)("div",{children:[(0,b.jsxs)("div",{className:"flex items-center justify-between",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"instagram accounts"}),(0,b.jsx)("button",{type:"button",onClick:()=>{aJ(a=>{let b={...a};return delete b[y],b}),w(y)},className:"rounded-lg border border-white/10 bg-white/5 px-2 py-0.5 text-[10px] font-medium text-[color:var(--ck-text-primary)] hover:bg-white/10",children:"Refresh"})]}),D?(0,b.jsx)("div",{className:"mt-1 text-[10px] text-[color:var(--ck-text-tertiary)]",children:"Loading accounts…"}):0===C.length?(0,b.jsx)("div",{className:"mt-1 text-[10px] text-[color:var(--ck-text-tertiary)]",children:"No Instagram accounts found. Open Marketing → Accounts and connect IG in Postiz."}):(0,b.jsxs)("div",{className:"mt-1 space-y-1",children:[C.map(a=>{let c=E.includes(a.integrationId);return(0,b.jsxs)("label",{className:"flex items-center gap-2 cursor-pointer rounded-lg border border-white/10 bg-white/5 px-2 py-1 hover:bg-white/10",children:[(0,b.jsx)("input",{type:"checkbox",checked:c,onChange:()=>{let b=c?E.filter(b=>b!==a.integrationId):[...E,a.integrationId],d={...t};delete d.integrationId,b.length>0?d.integrationIds=b.join(","):delete d.integrationIds,F({variableMapping:d})},className:"accent-[var(--ck-accent-red)]"}),(0,b.jsxs)("div",{children:[(0,b.jsx)("div",{className:"text-xs text-[color:var(--ck-text-primary)]",children:a.displayName}),a.username?(0,b.jsx)("div",{className:"text-[10px] text-[color:var(--ck-text-tertiary)]",children:a.username}):null]})]},a.integrationId)}),(0,b.jsx)("div",{className:"text-[9px] text-[color:var(--ck-text-tertiary)]",children:0===E.length?"None selected — will use first connected account.":`${E.length} account${E.length>1?"s":""} selected.`})]})]}):null,(0,b.jsxs)("div",{children:[(0,b.jsxs)("div",{className:"flex items-center justify-between",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"variable mapping"}),(0,b.jsx)("button",{type:"button",onClick:()=>{let a=`var_${Date.now()}`;F({variableMapping:{...t,[a]:""}})},className:"rounded-lg border border-white/10 bg-white/5 px-2 py-0.5 text-[10px] font-medium text-[color:var(--ck-text-primary)] hover:bg-white/10",children:"+ Add"})]}),(0,b.jsxs)("div",{className:"mt-1 text-[10px] text-[color:var(--ck-text-tertiary)]",children:["Map target workflow trigger inputs to upstream node outputs. Key = target variable name, Value = ","{{nodeId.field}}"," template."]}),B.length>0?(0,b.jsx)("div",{className:"mt-2 space-y-1",children:B.map(([a,c],d)=>(0,b.jsxs)("div",{className:"flex items-center gap-1",children:[(0,b.jsx)("input",{value:a,onChange:b=>{let d=b.target.value,e={...t};delete e[a],e[d]=c,F({variableMapping:e})},className:"w-1/3 rounded-lg border border-white/10 bg-white/5 px-1.5 py-0.5 text-[10px] text-[color:var(--ck-text-primary)]",placeholder:"target_var"}),(0,b.jsx)("span",{className:"text-[10px] text-[color:var(--ck-text-tertiary)]",children:"→"}),(0,b.jsx)("input",{value:c,onChange:b=>{F({variableMapping:{...t,[a]:b.target.value}})},className:"flex-1 rounded-lg border border-white/10 bg-white/5 px-1.5 py-0.5 text-[10px] text-[color:var(--ck-text-primary)]",placeholder:"{{nodeId.output}}"}),(0,b.jsx)("button",{type:"button",onClick:()=>{let b={...t};delete b[a],F({variableMapping:Object.keys(b).length>0?b:void 0})},className:"text-[10px] text-red-400 hover:text-red-300",title:"Remove mapping",children:"✕"})]},d))}):(0,b.jsx)("div",{className:"mt-1 text-[10px] text-[color:var(--ck-text-tertiary)] italic",children:"No mappings — target workflow will receive empty trigger input."})]})]})):null,(0,b.jsx)("div",{children:(0,b.jsx)(p,{outputFields:(I.config||{}).outputFields||[],onChange:a=>{let b={...I.config};a.length>0?b.outputFields=a:delete b.outputFields,br({...J,nodes:J.nodes.map(a=>a.id===I.id?{...a,config:b}:a)})}})}),(0,b.jsxs)("details",{className:"rounded-lg border border-white/10 bg-black/10",children:[(0,b.jsx)("summary",{className:"cursor-pointer list-none px-2 py-1 text-[10px] font-medium text-[color:var(--ck-text-secondary)]",children:"Raw Config (debug)"}),(0,b.jsx)("div",{className:"p-2",children:(0,b.jsx)("pre",{className:"mt-1 max-h-[150px] overflow-auto rounded-lg border border-white/10 bg-white/5 p-2 text-[9px] text-[color:var(--ck-text-tertiary)]",children:JSON.stringify(I.config??{},null,2)})})]})]}):(0,b.jsx)("div",{className:"mt-2 text-sm text-[color:var(--ck-text-secondary)]",children:"No node selected."}):(0,b.jsx)("div",{className:"mt-2 text-sm text-[color:var(--ck-text-secondary)]",children:"Select a node."})]})]}),(0,b.jsxs)("details",{open:!0,className:"rounded-lg border border-white/10 bg-white/5",children:[(0,b.jsx)("summary",{className:"cursor-pointer list-none px-3 py-2 text-sm font-medium text-[color:var(--ck-text-primary)]",children:"Triggers"}),(0,b.jsxs)("div",{className:"px-3 pb-3",children:[(0,b.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"triggers"}),(0,b.jsx)("button",{type:"button",onClick:()=>{let a=`t${Date.now()}`;br({...J,triggers:[...L,{kind:"cron",id:a,name:"New trigger",enabled:!0,expr:"0 9 * * 1-5",tz:K}]})},className:"rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-[10px] font-medium text-[color:var(--ck-text-primary)] hover:bg-white/10",children:"+ Add"})]}),"idle"!==$&&(0,b.jsxs)("div",{className:"mt-2 flex items-center gap-2 rounded-lg border border-white/10 bg-white/5 px-2 py-1",children:["syncing"===$&&(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)("div",{className:"h-3 w-3 animate-spin rounded-full border border-blue-400 border-t-transparent"}),(0,b.jsx)("div",{className:"text-xs text-blue-400",children:"Syncing triggers..."})]}),"success"===$&&(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)("div",{className:"text-green-400",children:"✓"}),(0,b.jsx)("div",{className:"text-xs text-green-400",children:"Triggers synced"})]}),"error"===$&&(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)("div",{className:"text-red-400",children:"✗"}),(0,b.jsxs)("div",{className:"text-xs text-red-400",children:["Trigger sync failed: ",aa]})]})]}),(0,b.jsx)("div",{className:"mt-2 space-y-2",children:L.length?L.map((a,c)=>{let d=a.kind,e=String(a.id??""),f=String(a.name??""),g=!!a.enabled,h=String(a.expr??""),i=String(a.tz??K),j=h.trim().split(/\s+/).filter(Boolean),k=!h.trim()||5===j.length;return(0,b.jsxs)("div",{className:"rounded-lg border border-white/10 bg-white/5 p-2",children:[(0,b.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,b.jsx)("div",{className:"text-xs text-[color:var(--ck-text-primary)]",children:f||e||`trigger-${c+1}`}),(0,b.jsx)("button",{type:"button",onClick:()=>br({...J,triggers:L.filter((a,b)=>b!==c)}),className:"text-[10px] text-[color:var(--ck-text-tertiary)] hover:text-[color:var(--ck-text-primary)]",children:"Remove"})]}),"cron"===d?null:(0,b.jsxs)("div",{className:"mt-1 text-xs text-[color:var(--ck-text-secondary)]",children:["Unsupported trigger kind: ",String(d)]}),(0,b.jsxs)("div",{className:"mt-2 grid grid-cols-1 gap-2",children:[(0,b.jsxs)("label",{className:"flex items-center gap-2 text-xs text-[color:var(--ck-text-secondary)]",children:[(0,b.jsx)("input",{type:"checkbox",checked:g,onChange:a=>{let b=a.target.checked;br({...J,triggers:L.map((a,d)=>d===c&&"cron"===a.kind?{...a,enabled:b}:a)})}}),"Enabled"]}),(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"name"}),(0,b.jsx)("input",{value:f,onChange:a=>{let b=a.target.value;br({...J,triggers:L.map((a,d)=>d===c&&"cron"===a.kind?{...a,name:b}:a)})},className:"mt-1 w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",placeholder:"Content cadence"})]}),(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"schedule (cron)"}),(0,b.jsx)("input",{value:h,onChange:a=>{let b=a.target.value;br({...J,triggers:L.map((a,d)=>d===c&&"cron"===a.kind?{...a,expr:b}:a)})},className:k?"mt-1 w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 font-mono text-[11px] text-[color:var(--ck-text-primary)]":"mt-1 w-full rounded-lg border border-red-400/50 bg-white/5 px-2 py-1 font-mono text-[11px] text-[color:var(--ck-text-primary)]",placeholder:"0 9 * * 1,3,5"}),k?null:(0,b.jsxs)("div",{className:"mt-1 text-[10px] text-red-200",children:["Cron should be 5 fields (min hour dom month dow). You entered ",j.length,"."]}),(0,b.jsxs)("div",{className:"mt-1 grid grid-cols-1 gap-1",children:[(0,b.jsx)("select",{value:Q.some(a=>a.expr===h)?h:"",onChange:a=>{let b=a.target.value;br({...J,triggers:L.map((a,d)=>d===c&&"cron"===a.kind?{...a,expr:b}:a)})},className:"w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-[11px] text-[color:var(--ck-text-secondary)]",children:Q.map(a=>(0,b.jsx)("option",{value:a.expr,children:a.label},a.label))}),(0,b.jsx)("div",{className:"text-[10px] text-[color:var(--ck-text-tertiary)]",children:"Presets set the cron; edit freely for advanced schedules."})]})]}),(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"timezone override"}),(0,b.jsx)("input",{value:i,onChange:a=>{let b=String(a.target.value||"").trim()||K;br({...J,triggers:L.map((a,d)=>d===c&&"cron"===a.kind?{...a,tz:b}:a)})},className:"mt-1 w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",placeholder:K})]})]})]},`${e}-${c}`)}):(0,b.jsx)("div",{className:"text-xs text-[color:var(--ck-text-secondary)]",children:"No triggers yet."})})]})]}),(0,b.jsxs)("details",{open:!0,className:"rounded-lg border border-white/10 bg-white/5",children:[(0,b.jsx)("summary",{className:"cursor-pointer list-none px-3 py-2 text-sm font-medium text-[color:var(--ck-text-primary)]",children:"Runs"}),(0,b.jsxs)("div",{className:"px-3 pb-3",children:[(0,b.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,b.jsxs)("div",{className:"flex items-center gap-3",children:[(0,b.jsx)("div",{className:"text-xs font-medium text-[color:var(--ck-text-secondary)]",children:"Runs (history)"}),(0,b.jsx)(d.default,{href:`/teams/${encodeURIComponent(a)}/runs`,className:"text-[10px] font-medium text-[color:var(--ck-text-tertiary)] hover:text-[color:var(--ck-text-secondary)] hover:underline",children:"View all →"})]}),(0,b.jsxs)("div",{className:"flex items-center gap-2",children:[(0,b.jsx)("button",{type:"button",disabled:U,onClick:async()=>{let b=String(J.id??"").trim();if(b){aW(""),aS(!0);try{let c=await fetch("/api/teams/workflow-runs",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({teamId:a,workflowId:b,mode:"enqueue"})}),d=await c.json();if(!c.ok||!d.ok)throw Error(d.error||"Failed to enqueue run");let e=await fetch(`/api/teams/workflow-runs?teamId=${encodeURIComponent(a)}&workflowId=${encodeURIComponent(b)}`,{cache:"no-store"}),f=await e.json();if(!e.ok||!f.ok)throw Error(f.error||"Failed to refresh runs");let g=(Array.isArray(f.files)?f.files:[]).map(a=>String(a??"").trim()).filter(a=>!!a);aQ(g)}catch(a){aW(a instanceof Error?a.message:String(a))}finally{aS(!1)}}},className:"rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-[10px] font-medium text-[color:var(--ck-text-primary)] hover:bg-white/10 disabled:opacity-50",children:"+ Queue run"}),(0,b.jsx)("button",{type:"button",disabled:U||aZ||!bq.ok,onClick:async()=>{let b=String(J.id??"").trim();if(b){if(bq.missingAgentOnNodeIds.length)return void aW("All nodes must be assigned to an agent.");if(bq.agentIdsMissingCron.length){a6(!0),a8("");try{let b=await fetch("/api/cron/worker",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({action:"reconcile",teamId:a})}),c=await b.json();if(!b.ok||!1===c.ok)throw Error(c.error||"Failed to reconcile worker crons");let d=await bn(),e=bq.requiredAgentIds.filter(a=>!d[a]);if(e.length)return void aW(`Cron not set up for: ${e.join(", ")}`)}catch(a){aW(a instanceof Error?a.message:String(a));return}finally{a6(!1)}}aW(""),aS(!0),aU(!0);try{let c=await fetch("/api/teams/workflow-runs",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({teamId:a,workflowId:b,mode:"run_now"})}),d=await c.json();if(!c.ok||!d.ok)throw Error(d.error||"Failed to create run");let e=String(d.runId??"").trim();if(e)return void R.push(`/teams/${a}/runs/${i}/${e}`);aU(!1);let f=await fetch(`/api/teams/workflow-runs?teamId=${encodeURIComponent(a)}&workflowId=${encodeURIComponent(b)}`,{cache:"no-store"}),g=await f.json();if(!f.ok||!g.ok)throw Error(g.error||"Failed to refresh runs");let h=(Array.isArray(g.files)?g.files:[]).map(a=>String(a??"").trim()).filter(a=>!!a);aQ(h)}catch(a){aU(!1),aW(a instanceof Error?a.message:String(a))}finally{aS(!1)}}},className:"rounded-lg border border-emerald-400/30 bg-emerald-500/10 px-2 py-1 text-[10px] font-medium text-emerald-50 hover:bg-emerald-500/15 disabled:opacity-50",title:"Enqueue a run for the workflow runner (Kitchen does not execute nodes)",children:"+ Run now"}),a_?(0,b.jsx)("div",{className:"ml-2 text-[10px] text-amber-100/90",title:a_,children:"Cron check unavailable"}):null]})]}),bq.missingAgentOnNodeIds.length?(0,b.jsxs)("div",{className:"mt-2 rounded-lg border border-red-400/30 bg-red-500/10 p-2 text-xs text-red-100",children:["All nodes must be assigned to an agent. Missing agentId on: ",bq.missingAgentOnNodeIds.join(", ")]}):bq.agentIdsMissingCron.length?(0,b.jsxs)("div",{className:"mt-2 rounded-lg border border-amber-400/30 bg-amber-500/10 p-2 text-xs text-amber-50",children:[(0,b.jsxs)("div",{children:["Cron not set up for: ",bq.agentIdsMissingCron.join(", ")]}),(0,b.jsxs)("div",{className:"mt-2 flex items-center gap-2",children:[(0,b.jsx)("button",{type:"button",onClick:()=>{a8(""),a4(!0)},className:"rounded-lg border border-amber-300/30 bg-amber-500/10 px-2 py-1 text-[10px] font-medium text-amber-50 hover:bg-amber-500/15",children:"Install worker cron(s)"}),(0,b.jsx)("button",{type:"button",onClick:()=>void bn(),className:"rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-[10px] font-medium text-[color:var(--ck-text-primary)] hover:bg-white/10",children:"Re-check"})]})]}):null,(0,b.jsx)(f.ConfirmationModal,{open:a3,title:"Install worker cron jobs?",busy:a5,error:a7||void 0,confirmLabel:"Install",onClose:()=>{a5||a4(!1)},onConfirm:async()=>{a6(!0),a8("");try{let b=await fetch("/api/cron/worker",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({action:"reconcile",teamId:a})}),c=await b.json();if(!b.ok||!1===c.ok)throw Error(c.error||"Failed to install worker crons");await bn(),a4(!1)}catch(a){a8(a instanceof Error?a.message:String(a))}finally{a6(!1)}},children:(0,b.jsxs)("div",{className:"text-sm text-[color:var(--ck-text-secondary)]",children:["Kitchen will install (or enable) worker cron jobs for the following agents so this workflow can drain:",(0,b.jsx)("div",{className:"mt-2 rounded-lg border border-white/10 bg-white/5 p-2 font-mono text-[11px] text-[color:var(--ck-text-primary)]",children:bq.agentIdsMissingCron.join(", ")}),(0,b.jsxs)("div",{className:"mt-2 text-xs text-[color:var(--ck-text-tertiary)]",children:["Cron cadence: every 5 minutes. The worker runs: ",(0,b.jsx)("span",{className:"font-mono",children:"openclaw recipes workflows worker-tick"}),"."]})]})}),aV?(0,b.jsx)("div",{className:"mt-2 rounded-lg border border-red-400/30 bg-red-500/10 p-2 text-xs text-red-100",children:aV}):null,(0,b.jsx)("div",{className:"mt-2 space-y-1",children:aR?(0,b.jsx)("div",{className:"text-xs text-[color:var(--ck-text-secondary)]",children:"Serving up hot…"}):aP.length?aP.slice(0,8).map(c=>{let e=String(J.id??"").trim(),f=String(c).replace(/\.run\.json$/i,""),g=aX===f,h=e?`/teams/${encodeURIComponent(a)}/runs/${encodeURIComponent(e)}/${encodeURIComponent(f)}`:"#";return(0,b.jsx)(d.default,{href:h,onClick:()=>aY(f),className:g?"block w-full rounded-lg bg-white/10 px-2 py-1 text-left text-[11px] font-mono text-[color:var(--ck-text-primary)]":"block w-full rounded-lg px-2 py-1 text-left text-[11px] font-mono text-[color:var(--ck-text-secondary)] hover:bg-white/5",title:"Open run detail",children:f},c)}):(0,b.jsx)("div",{className:"text-xs text-[color:var(--ck-text-secondary)]",children:"No runs yet."})}),(0,b.jsxs)("details",{open:!0,className:"mt-3 rounded-lg border border-white/10 bg-black/10",children:[(0,b.jsx)("summary",{className:"cursor-pointer list-none px-3 py-2 text-sm font-medium text-[color:var(--ck-text-primary)]",children:"Nodes"}),(0,b.jsxs)("div",{className:"px-3 pb-3",children:[(0,b.jsx)("div",{className:"mt-2 rounded-lg border border-white/10 bg-white/5 p-2",children:(0,b.jsxs)("div",{className:"grid grid-cols-1 gap-2",children:[(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"id"}),(0,b.jsx)("input",{value:a9,onChange:a=>ba(a.target.value),className:"mt-1 w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",placeholder:"e.g. draft_assets"})]}),(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"name (optional)"}),(0,b.jsx)("input",{value:bb,onChange:a=>bc(a.target.value),className:"mt-1 w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",placeholder:"Human-friendly label"})]}),(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"type"}),(0,b.jsxs)("select",{value:bd,onChange:a=>be(a.target.value),className:"mt-1 w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",children:[(0,b.jsx)("option",{value:"start",children:"start"}),(0,b.jsx)("option",{value:"end",children:"end"}),(0,b.jsx)("option",{value:"llm",children:"llm"}),(0,b.jsx)("option",{value:"tool",children:"tool"}),(0,b.jsx)("option",{value:"condition",children:"condition"}),(0,b.jsx)("option",{value:"delay",children:"delay"}),(0,b.jsx)("option",{value:"human_approval",children:"human_approval"}),(0,b.jsx)("option",{value:"media-image",children:"media-image"}),(0,b.jsx)("option",{value:"media-video",children:"media-video"}),(0,b.jsx)("option",{value:"handoff",children:"handoff"})]})]}),(0,b.jsx)("button",{type:"button",onClick:()=>{let a=String(a9||"").trim().replace(/[^a-z0-9_\-]/gi,"_");if(!a||J.nodes.some(b=>b.id===a))return;let b=J.nodes.reduce((a,b)=>"number"==typeof b.x?Math.max(a,b.x):a,80),c={id:a,type:bd,name:String(bb||"").trim()||a,x:b+220,y:80};br({...J,nodes:[...J.nodes,c]}),aj(a),ba(""),bc("")},className:"rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-[11px] font-medium text-[color:var(--ck-text-primary)] hover:bg-white/10",children:"+ Add node"})]})}),(0,b.jsx)("div",{className:"mt-2 space-y-1",children:J.nodes.map(a=>{let c=ai===a.id;return(0,b.jsxs)("button",{type:"button",onClick:()=>aj(a.id),className:c?"w-full rounded-lg bg-white/10 px-2 py-1 text-left text-[11px] text-[color:var(--ck-text-primary)]":"w-full rounded-lg px-2 py-1 text-left text-[11px] text-[color:var(--ck-text-secondary)] hover:bg-white/5",children:[(0,b.jsx)("span",{className:"font-mono",children:a.id}),(0,b.jsx)("span",{className:"ml-2 text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:a.type})]},a.id)})})]})]}),(0,b.jsxs)("details",{open:!0,className:"mt-3 rounded-lg border border-white/10 bg-black/10",children:[(0,b.jsx)("summary",{className:"cursor-pointer list-none px-3 py-2 text-sm font-medium text-[color:var(--ck-text-primary)]",children:"Edges"}),(0,b.jsxs)("div",{className:"px-3 pb-3",children:[(0,b.jsx)("div",{className:"mt-2 rounded-lg border border-white/10 bg-white/5 p-2",children:(0,b.jsxs)("div",{className:"grid grid-cols-1 gap-2",children:[(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"from"}),(0,b.jsxs)("select",{value:bf,onChange:a=>bg(a.target.value),className:"mt-1 w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",children:[(0,b.jsx)("option",{value:"",children:"(select)"}),J.nodes.map(a=>(0,b.jsx)("option",{value:a.id,children:a.id},a.id))]})]}),(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"to"}),(0,b.jsxs)("select",{value:bh,onChange:a=>bi(a.target.value),className:"mt-1 w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",children:[(0,b.jsx)("option",{value:"",children:"(select)"}),J.nodes.map(a=>(0,b.jsx)("option",{value:a.id,children:a.id},a.id))]})]}),(0,b.jsxs)("label",{className:"block",children:[(0,b.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[color:var(--ck-text-tertiary)]",children:"label (optional)"}),(0,b.jsx)("input",{value:bj,onChange:a=>bk(a.target.value),className:"mt-1 w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-xs text-[color:var(--ck-text-primary)]",placeholder:"e.g. approve"})]}),(0,b.jsx)("button",{type:"button",onClick:()=>{let a=String(bf||"").trim(),b=String(bh||"").trim();if(!a||!b||a===b)return;let c={id:`e${Date.now()}`,from:a,to:b,...String(bj||"").trim()?{label:String(bj).trim()}:{}};br({...J,edges:[...J.edges??[],c]}),bk("")},className:"rounded-lg border border-white/10 bg-white/5 px-2 py-1 text-[11px] font-medium text-[color:var(--ck-text-primary)] hover:bg-white/10",children:"+ Add edge"})]})}),(0,b.jsx)("div",{className:"mt-2 space-y-2",children:(J.edges??[]).length?(J.edges??[]).map(a=>(0,b.jsx)("div",{className:"rounded-lg border border-white/10 bg-white/5 p-2",children:(0,b.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,b.jsxs)("div",{className:"text-[11px] text-[color:var(--ck-text-secondary)]",children:[(0,b.jsx)("span",{className:"font-mono",children:a.from})," → ",(0,b.jsx)("span",{className:"font-mono",children:a.to}),a.label?(0,b.jsxs)("span",{className:"ml-2 text-[10px] text-[color:var(--ck-text-tertiary)]",children:["(",a.label,")"]}):null]}),(0,b.jsx)("button",{type:"button",onClick:()=>br({...J,edges:(J.edges??[]).filter(b=>b.id!==a.id)}),className:"text-[10px] text-[color:var(--ck-text-tertiary)] hover:text-[color:var(--ck-text-primary)]",children:"Remove"})]})},a.id)):(0,b.jsx)("div",{className:"text-xs text-[color:var(--ck-text-secondary)]",children:"No edges yet."})})]})]})]})]})]})):null})})]}),(0,b.jsx)(m,{open:aT})]})}a.s(["default",()=>r],13833)}];
|
|
8
8
|
|
|
9
9
|
//# sourceMappingURL=b1a17_app_teams_%5BteamId%5D_workflows_%5BworkflowId%5D_workflows-editor-client_tsx_5e714aa2._.js.map
|