@fieldwangai/agentflow 0.1.83 → 0.1.84

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.
@@ -4329,8 +4329,11 @@ function workspaceDefaultWorktreePath(runTmpRoot, nodeId, repoPath, branch = "")
4329
4329
  );
4330
4330
  }
4331
4331
 
4332
- function workspaceShouldAutoCleanupWorktree(result) {
4333
- return Boolean(result?.worktreePath) && result.created === true;
4332
+ function workspaceShouldAutoCleanupWorktree(result, scopedRoot = "") {
4333
+ const worktreePath = String(result?.worktreePath || "").trim();
4334
+ if (!worktreePath) return false;
4335
+ if (result.created === true) return true;
4336
+ return scopedRoot ? workspacePathInside(scopedRoot, worktreePath) : false;
4334
4337
  }
4335
4338
 
4336
4339
  function workspaceTrackAutoCleanupWorktree(list, item) {
@@ -5010,7 +5013,7 @@ async function runWorkspaceGraph(root, scopedRoot, payload, userCtx = {}, opts =
5010
5013
  const pruneMissingRaw = workspaceSlotValue(workspaceSlotByName(instance, "pruneMissing")).trim().toLowerCase();
5011
5014
  const pruneMissing = pruneMissingRaw !== "false";
5012
5015
  const result = loadGitWorktree({ repoPath, branch, worktreePath, pipelineWorkspace: scopedRoot, force, pruneMissing });
5013
- if (workspaceShouldAutoCleanupWorktree(result)) {
5016
+ if (workspaceShouldAutoCleanupWorktree(result, scopedRoot)) {
5014
5017
  workspaceTrackAutoCleanupWorktree(autoCleanupWorktrees, {
5015
5018
  nodeId,
5016
5019
  repoPath: result.repoRoot,
@@ -8,7 +8,8 @@ description: |
8
8
  - `branch` is optional. When empty, AgentFlow creates a detached worktree at the current HEAD.
9
9
  - `worktreePath` is optional. When empty, AgentFlow creates a temporary worktree under the current run temp directory.
10
10
  - A worktree created by this node during the current Workspace run is removed when the run finishes or is stopped, even when `worktreePath` is explicitly set.
11
- - Existing registered worktrees that were present before the run are reused and not removed automatically.
11
+ - Existing registered worktrees under the current flow workspace are also removed after the run, covering leftovers from previous interrupted runs.
12
+ - Existing registered worktrees outside the current flow workspace are reused and not removed automatically unless this run created them.
12
13
  - Existing worktree paths are reused only when they are registered by `git worktree list` for the given repo.
13
14
  - `pruneMissing` defaults to true. When Git has a registered worktree whose directory is missing, AgentFlow runs `git worktree prune` before adding it again.
14
15
  - `force` defaults to false. When true, AgentFlow passes `--force` to `git worktree add`.
@@ -125,7 +125,7 @@ script: node -e "console.log('TODO: scripts/x.mjs')"
125
125
 
126
126
  `).trimEnd()}function yw(e){return String(e||"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function pU(e){const t=String(e||"");let n="",r=0;Ug.lastIndex=0;let s;for(;s=Ug.exec(t);)n+=yw(t.slice(r,s.index)),n+=`<span class="af-flow-node__image-token">${yw(s[0])}</span>`,r=s.index+s[0].length;return n+=yw(t.slice(r)),n||" "}function hU(e,t){const n=window.getComputedStyle(e),r=Number.parseFloat(n.lineHeight)||18,s=Number.parseFloat(n.paddingTop)||0,o=Number.parseFloat(n.paddingBottom)||0,a=Number.parseFloat(n.borderTopWidth)||0,l=Number.parseFloat(n.borderBottomWidth)||0,c=String(t||"").split(/\r\n|\r|\n/).length,d=Math.min(Math.max(c,2),8);return Math.ceil(d*r+s+o+a+l)}function ER({data:e,selected:t,id:n,deleteNode:r,onProvideExpand:s,onProvideValueChange:o,onNodeBodyChange:a,onNodeImagesChange:l,modelLists:c,onModelChange:d}){var ce,he;const{t:p}=zn(),u=(e==null?void 0:e.inputs)??[],f=(e==null?void 0:e.outputs)??[],m=((e==null?void 0:e.schemaType)??"agent").toLowerCase(),g=cU(e),w=(e==null?void 0:e.isRunMode)??!1,k=!!(e!=null&&e.readOnly),y=(e==null?void 0:e.isExecuting)??!1,b=(e==null?void 0:e.isDim)??!1,x=(e==null?void 0:e.nodeStatus)??null,j=(e==null?void 0:e.nodeElapsed)??null,E=(e==null?void 0:e.definitionId)||"",N=E.startsWith("provide_"),T=E==="provide_bool",$=E==="provide_str",z=E==="provide_file",K=E==="provide_password",B=E==="agent_subAgent",L=E==="control_agent_toBool",D=(B||L)&&!w,R=T?uU(f[0]):!1,M=N?String(((ce=f[0])==null?void 0:ce.value)??((he=f[0])==null?void 0:he.default)??(e==null?void 0:e.body)??""):"",I=String((e==null?void 0:e.body)||""),F=(e==null?void 0:e.displayLabel)||(e==null?void 0:e.label)||p("flow:node.fallbackLabel"),P=!N&&!D&&(e!=null&&e.showBodyPreview)?String((e==null?void 0:e.body)||"").trim():"",O=Vs(e==null?void 0:e.images),_=T||$||z||K||D||!!P,Z=h.useRef(!1),ee=h.useRef(!1),V=h.useRef(null),ae=h.useRef(null),fe=h.useRef(null),xe=h.useRef(null),Se=h.useRef(null),[ue,Ee]=h.useState(M),[le,me]=h.useState(!1),[we,je]=h.useState(I),[Ye,tt]=h.useState(!1),[ze,dt]=h.useState({visible:!1,top:0,height:100}),[Ft,Ue]=h.useState(!1),pt=h.useCallback(()=>{const Q=ae.current;if(!Q)return;const ge=Math.max(1,Q.scrollHeight),qe=Math.max(1,Q.clientHeight),Me=ge>qe+1,zt=Me?Math.max(12,qe/ge*100):100,Rn=Math.max(0,100-zt),Hn=Me?Math.min(Rn,Q.scrollTop/Math.max(1,ge-qe)*Rn):0;dt({visible:Me,top:Hn,height:zt})},[]);h.useEffect(()=>{Z.current||Ee(M)},[n,M]),h.useEffect(()=>{ee.current||je(I)},[n,I]),h.useEffect(()=>{const Q=ae.current;if(!Q)return;if(D){Q.style.minHeight="",Q.style.height="",fe.current&&(fe.current.style.minHeight="",fe.current.style.height="");return}const ge=hU(Q,we);Q.style.minHeight=`${ge}px`,Q.style.height="",fe.current&&(fe.current.style.minHeight=`${ge}px`,fe.current.style.height="")},[we,D]),h.useEffect(()=>{if(!D)return;const Q=window.requestAnimationFrame(pt),ge=ae.current;if(!ge||typeof ResizeObserver>"u")return()=>window.cancelAnimationFrame(Q);const qe=new ResizeObserver(pt);return qe.observe(ge),()=>{window.cancelAnimationFrame(Q),qe.disconnect()}},[we,D,pt]),h.useEffect(()=>{const Q=V.current,ge=e==null?void 0:e.onNodeContentResize;if(!D||!Q||!ge||typeof ResizeObserver>"u")return;let qe=0;const Me=()=>{window.cancelAnimationFrame(qe),qe=window.requestAnimationFrame(()=>ge(n))},zt=new ResizeObserver(Me);return zt.observe(Q),Me(),()=>{window.cancelAnimationFrame(qe),zt.disconnect()}},[e==null?void 0:e.onNodeContentResize,D,n]),h.useEffect(()=>{if(!Ft)return;const Q=window.setTimeout(()=>{const ge=Se.current;if(!ge)return;ge.focus();const qe=ge.value.length;ge.setSelectionRange(qe,qe)},0);return()=>window.clearTimeout(Q)},[Ft]);const _n=Array.isArray(c==null?void 0:c.cursor)?c.cursor:[],We=Array.isArray(c==null?void 0:c.opencode)?c.opencode:[],sn=Array.isArray(c==null?void 0:c.claudeCode)?c.claudeCode:[],xt=((e==null?void 0:e.model)??"").trim(),kn=m==="agent"&&!E.startsWith("tool_nodejs"),pe=new Set(_n.map(pa)),_e=new Set(We.map(pa)),Ve=new Set(sn.map(pa)),rt=xt?xt.startsWith("cursor:")||xt.startsWith("opencode:")||xt.startsWith("claude-code:")?xt:Ve.has(xt)?`claude-code:${xt}`:_e.has(xt)?`opencode:${xt}`:pe.has(xt)?`cursor:${xt}`:xt:"",it=xt&&!rt.startsWith("cursor:")&&!rt.startsWith("opencode:")&&!rt.startsWith("claude-code:")&&!pe.has(xt)&&!_e.has(xt)&&!Ve.has(xt),Mt=xt.startsWith("cursor:")?xt.slice(7):xt.startsWith("opencode:")?xt.slice(9):xt.startsWith("claude-code:")?xt.slice(12):xt,wt=Q=>{if(k)return;const ge=Q.target.value;d&&d(n,ge)},gn=Q=>{Q.stopPropagation(),!k&&r&&r(n)},cn=Q=>{Q.stopPropagation(),s&&s()},Jn=Q=>{Q.stopPropagation(),!k&&(o==null||o(n,Q.target.value==="true"?"true":"false"))},on=Q=>{if(Q.stopPropagation(),k)return;const ge=Q.target.value;Ee(ge),Z.current||o==null||o(n,ge)},An=Q=>{Q.stopPropagation(),Z.current=!0},Pn=Q=>{if(Q.stopPropagation(),k)return;Z.current=!1;const ge=Q.currentTarget.value;Ee(ge),o==null||o(n,ge)},mr=()=>{k||o==null||o(n,ue)},Cr=Q=>{if(Q.stopPropagation(),k)return;if(typeof(e==null?void 0:e.onOpenProvideFilePicker)=="function"){e.onOpenProvideFilePicker(n,ue);return}const ge=window.prompt("文件路径",ue);ge!=null&&(Ee(ge),o==null||o(n,ge))},gr=Q=>{Q.stopPropagation(),me(ge=>!ge)},Wt=Q=>{if(je(Q),a==null||a(n,Q),l){const ge=V7(O,Q);(ge.length!==O.length||ge.some((qe,Me)=>{var zt;return qe.id!==((zt=O[Me])==null?void 0:zt.id)}))&&l(n,ge)}},Vt=Q=>{if(Q.stopPropagation(),k)return;const ge=Q.target.value;ee.current?je(ge):Wt(ge)},ir=Q=>{Q.stopPropagation(),!k&&(ee.current=!0,tt(!0))},Er=Q=>{if(Q.stopPropagation(),k)return;ee.current=!1,tt(!1);const ge=Q.currentTarget.value;Wt(ge)},dr=()=>{k||(ee.current=!1,tt(!1),Wt(we))},yr=Q=>{Q.stopPropagation(),Q.preventDefault(),!k&&Ue(!0)},_r=()=>{Ue(!1),dr()},Lr=Q=>{Q.stopPropagation(),Q.key==="Escape"&&(Q.preventDefault(),_r())},or=h.useCallback(Q=>{const ge=ae.current;if(!ge)return;const qe=Math.max(0,ge.scrollHeight-ge.clientHeight);ge.scrollTop=Math.min(1,Math.max(0,Q))*qe,pt()},[pt]),xr=h.useCallback((Q,ge=0)=>{const qe=xe.current;if(!qe)return 0;const Me=qe.getBoundingClientRect(),zt=ze.height/100*Me.height,Rn=Math.max(1,Me.height-zt);return(Q-Me.top-ge)/Rn},[ze.height]),Or=h.useCallback(Q=>{var lt,pn;if(!ze.visible)return;Q.preventDefault(),Q.stopPropagation();const ge=xe.current;if(!ge)return;const qe=ge.getBoundingClientRect(),Me=ze.top/100*qe.height,zt=ze.height/100*qe.height,Hn=Q.clientY>=qe.top+Me&&Q.clientY<=qe.top+Me+zt?Q.clientY-qe.top-Me:zt/2;or(xr(Q.clientY,Hn));const wr=Q.pointerId;(pn=(lt=Q.currentTarget).setPointerCapture)==null||pn.call(lt,wr);const Ae=Zt=>{Zt.preventDefault(),or(xr(Zt.clientY,Hn))},Br=()=>{window.removeEventListener("pointermove",Ae),window.removeEventListener("pointerup",Br),window.removeEventListener("pointercancel",Br)};window.addEventListener("pointermove",Ae),window.addEventListener("pointerup",Br),window.addEventListener("pointercancel",Br)},[xr,ze.height,ze.top,ze.visible,or]),ws=async Q=>{if(k)return;const ge=await vR({files:Q,body:we,images:O});ge&&(je(ge.body),a==null||a(n,ge.body),l==null||l(n,ge.images))},ar=(Q,ge)=>{if(Q.stopPropagation(),k)return;const qe=O.filter(zt=>zt.id!==ge.id),Me=fU(we,ge.label);je(Me),a==null||a(n,Me),l==null||l(n,qe)},Ar=Q=>{if(k)return;const ge=bR(Q);ge.length!==0&&(Q.preventDefault(),Q.stopPropagation(),ws(ge).catch(()=>{}))},In=Q=>{if(k)return;const ge=np(Q);ge.length!==0&&(Q.preventDefault(),Q.stopPropagation(),ws(ge).catch(()=>{}))},Tn=()=>{const Q=ae.current,ge=fe.current;!Q||!ge||(ge.scrollTop=Q.scrollTop,ge.scrollLeft=Q.scrollLeft)};return i.jsxs("div",{className:"af-flow-node"+(t?" af-flow-node--selected":"")+(y?" af-flow-node--executing":"")+(x==="success"?" af-flow-node--done":"")+(x==="failed"?" af-flow-node--failed":"")+(x==="running"&&!y?" af-flow-node--running-disk":"")+(b?" af-flow-node--dim":"")+(D?" af-flow-node--inline-body-editor":"")+($?" af-flow-node--provide-text":"")+(K?" af-flow-node--provide-password":"")+" af-flow-node--"+m.replace(/[^a-z0-9_-]/g,""),"data-schema":m,children:[i.jsxs("div",{className:"af-flow-node__chrome",children:[i.jsx("span",{className:"af-flow-node__title af-flow-node__title--chrome",title:`${F}${n?` (${n})`:""}${g?` · ${g}`:""}`,children:F}),!w&&kn&&i.jsxs("div",{className:"af-flow-node__model-wrap nodrag",onPointerDown:mn,onMouseDown:mn,onClick:mn,children:[i.jsxs("select",{className:"af-flow-node__model nodrag",value:rt,onChange:wt,onPointerDown:mn,onMouseDown:mn,onClick:mn,"aria-label":p("flow:node.model"),title:Mt||p("flow:node.defaultModel"),disabled:k,children:[i.jsx("option",{value:"",children:p("flow:node.defaultModel")}),it&&i.jsx("option",{value:xt,children:xt}),_n.length>0&&i.jsx("optgroup",{label:"Cursor",children:_n.map(Q=>i.jsx("option",{value:`cursor:${pa(Q)}`,children:pa(Q)},`c-${Q}`))}),We.length>0&&i.jsx("optgroup",{label:"OpenCode",children:We.map(Q=>i.jsx("option",{value:`opencode:${pa(Q)}`,children:pa(Q)},`o-${Q}`))}),sn.length>0&&i.jsx("optgroup",{label:"Claude Code",children:sn.map(Q=>i.jsx("option",{value:`claude-code:${pa(Q)}`,children:pa(Q)},`cc-${Q}`))})]}),i.jsx("span",{className:"af-flow-node__model-arrow material-symbols-outlined",children:"expand_more"})]}),y&&i.jsx("span",{className:"af-flow-node__status-badge af-flow-node__status-badge--executing",children:"EXECUTING"}),x==="running"&&!y&&i.jsx("span",{className:"af-flow-node__status-badge af-flow-node__status-badge--running-disk",title:p("flow:node.diskRunning"),children:"RUNNING"}),x==="success"&&i.jsx("span",{className:"af-flow-node__status-badge af-flow-node__status-badge--done",children:j!=null&&String(j).trim()!==""?j:"--"}),x==="failed"&&i.jsx("span",{className:"af-flow-node__status-badge af-flow-node__status-badge--failed",children:"FAILED"}),!w&&N&&!T&&!$&&!z&&!K&&i.jsx("button",{type:"button",className:"af-flow-node__expand",onClick:cn,"aria-label":p("flow:node.expandProvide"),title:p("flow:node.expandProvide"),children:i.jsx("span",{className:"material-symbols-outlined",children:"open_in_full"})}),!w&&i.jsx("button",{type:"button",className:"af-flow-node__delete",disabled:k,onClick:gn,"aria-label":p("flow:node.deleteNode"),title:p("flow:node.deleteNode"),children:i.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),i.jsxs("div",{className:"af-flow-node__body",children:[i.jsx("div",{className:"af-flow-node__ports af-flow-node__ports--in",children:u.map((Q,ge)=>{if(Q.showOnNode===!1)return null;const qe=p("flow:node.inputTooltip",{name:Q.name||`#${ge}`,type:Q.type})+(Q.default!=null&&Q.default!==""?p("flow:node.defaultSuffix",{value:Q.default}):""),Me=Q.name||`#${ge+1}`;return i.jsxs("div",{className:"af-flow-node__port-row",title:qe,children:[i.jsxs("span",{className:"af-flow-node__port-label af-flow-node__port-label--in",children:[Me,Q.required?i.jsx("span",{className:"af-flow-node__port-required",children:"*"}):null]}),i.jsx(gs,{type:"target",position:Qe.Left,id:`input-${ge}`,className:"af-flow-node__handle",style:{background:qn(Q.type)},title:qe})]},`in-${ge}`)})}),i.jsxs("div",{className:"af-flow-node__title-wrap",children:[T?i.jsxs("select",{className:"af-flow-node__bool-select nodrag"+(R?" af-flow-node__bool-select--true":""),value:R?"true":"false",onChange:Jn,onPointerDown:mn,onMouseDown:mn,onClick:mn,"aria-label":"Boolean value",title:R?"true":"false",disabled:k,children:[i.jsx("option",{value:"false",children:"false"}),i.jsx("option",{value:"true",children:"true"})]}):$?i.jsx("textarea",{className:"af-flow-node__inline-text nodrag",value:ue,onChange:on,onCompositionStart:An,onCompositionEnd:Pn,onBlur:mr,onPointerDown:mn,onMouseDown:mn,onClick:mn,placeholder:"输入文本",rows:2,readOnly:k}):z?i.jsxs("div",{className:"af-flow-node__file-value nodrag",onPointerDown:mn,onMouseDown:mn,onClick:mn,children:[i.jsx("input",{className:"af-flow-node__file-input nodrag",value:ue,onChange:on,onCompositionStart:An,onCompositionEnd:Pn,onBlur:mr,placeholder:"选择或输入文件路径",title:ue||"选择或输入文件路径",readOnly:k}),i.jsx("button",{type:"button",className:"af-flow-node__file-picker nodrag",disabled:k,onClick:Cr,"aria-label":"选择文件",title:"选择文件",children:i.jsx("span",{className:"material-symbols-outlined",children:"folder_open"})})]}):K?i.jsxs("div",{className:"af-flow-node__password-value nodrag",onPointerDown:mn,onMouseDown:mn,onClick:mn,children:[i.jsx("input",{className:"af-flow-node__password-input nodrag",type:le?"text":"password",value:ue,onChange:on,onCompositionStart:An,onCompositionEnd:Pn,onBlur:mr,placeholder:"输入密码或密钥",title:le?ue:"密码已隐藏",autoComplete:"off",readOnly:k}),i.jsx("button",{type:"button",className:"af-flow-node__password-toggle nodrag",disabled:k,onClick:gr,"aria-label":le?"隐藏密码":"预览密码",title:le?"隐藏密码":"预览密码",children:i.jsx("span",{className:"material-symbols-outlined",children:le?"visibility_off":"visibility"})})]}):D?i.jsxs("div",{ref:V,className:"af-flow-node__prompt-stack nodrag"+(Ye?" af-flow-node__prompt-stack--composing":""),children:[i.jsx("pre",{ref:fe,className:"af-flow-node__prompt-backdrop","aria-hidden":"true",dangerouslySetInnerHTML:{__html:pU(we)+`
127
127
  `}}),i.jsx("textarea",{ref:ae,className:"af-flow-node__prompt-editor nodrag",value:we,onChange:Vt,onCompositionStart:ir,onCompositionEnd:Er,onBlur:dr,onPaste:Ar,onDrop:In,onScroll:Q=>{Tn(),pt()},onPointerDown:mn,onMouseDown:mn,onClick:mn,onKeyDown:mn,onDragOver:Q=>{np(Q).length>0&&Q.preventDefault()},placeholder:L?"输入判断条件 / prompt":"输入 prompt",rows:2,readOnly:k}),!k&&i.jsx("button",{type:"button",className:"af-flow-node__prompt-expand nodrag",onPointerDown:mn,onMouseDown:mn,onClick:yr,"aria-label":"放大编辑",title:"放大编辑",children:i.jsx("span",{className:"material-symbols-outlined",children:"open_in_full"})}),i.jsx("div",{ref:xe,className:"af-flow-node__prompt-scrollbar"+(ze.visible?" af-flow-node__prompt-scrollbar--visible":""),onPointerDown:Or,"aria-hidden":"true",children:i.jsx("span",{style:{height:`${ze.height}%`,top:`${ze.top}%`}})})]}):null,D&&O.length>0?i.jsx("div",{className:"af-flow-node__image-chips",children:O.map((Q,ge)=>i.jsxs("span",{className:"af-flow-node__image-chip",title:Q.name,children:[i.jsx("img",{src:Q.dataUrl,alt:""}),i.jsxs("span",{children:["[",Q.label||`image ${ge+1}`,"]"]}),i.jsx("button",{type:"button",className:"af-flow-node__image-remove nodrag",disabled:k,onClick:qe=>ar(qe,Q),onPointerDown:mn,onMouseDown:mn,"aria-label":`删除 ${Q.label||`image ${ge+1}`}`,title:"删除图片",children:i.jsx("span",{className:"material-symbols-outlined",children:"close"})})]},Q.id||ge))}):null,P?i.jsx("span",{className:"af-flow-node__prompt-preview",title:P,children:P}):null,_?null:i.jsx("span",{className:"af-flow-node__body-title",title:F,children:F})]}),i.jsx("div",{className:"af-flow-node__ports af-flow-node__ports--out",children:f.map((Q,ge)=>{if(Q.showOnNode===!1)return null;const qe=p("flow:node.outputTooltip",{name:Q.name||`#${ge}`,type:Q.type})+(Q.default!=null&&Q.default!==""?p("flow:node.defaultSuffix",{value:Q.default}):""),Me=Q.name||`#${ge+1}`;return i.jsxs("div",{className:"af-flow-node__port-row",title:qe,children:[i.jsxs("span",{className:"af-flow-node__port-label af-flow-node__port-label--out",children:[Me,Q.required?i.jsx("span",{className:"af-flow-node__port-required",children:"*"}):null]}),i.jsx(gs,{type:"source",position:Qe.Right,id:`output-${ge}`,className:"af-flow-node__handle",style:{background:qn(Q.type)},title:qe})]},`out-${ge}`)})})]}),Ft?Ir.createPortal(i.jsx("div",{className:"af-flow-node-full-editor nodrag",onPointerDown:mn,onMouseDown:mn,onClick:mn,onWheel:mn,children:i.jsxs("div",{className:"af-flow-node-full-editor__panel",children:[i.jsxs("div",{className:"af-flow-node-full-editor__header",children:[i.jsxs("div",{children:[i.jsx("div",{className:"af-flow-node-full-editor__title",children:F}),i.jsx("div",{className:"af-flow-node-full-editor__hint",children:"编辑 prompt,Esc 关闭"})]}),i.jsx("button",{type:"button",className:"af-flow-node-full-editor__close",onClick:_r,"aria-label":"关闭",title:"关闭",children:i.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),i.jsx("textarea",{ref:Se,className:"af-flow-node-full-editor__textarea",value:we,onChange:Vt,onCompositionStart:ir,onCompositionEnd:Er,onPaste:Ar,onDrop:In,onKeyDown:Lr,onDragOver:Q=>{np(Q).length>0&&Q.preventDefault()},placeholder:L?"输入判断条件 / prompt":"输入 prompt",readOnly:k})]})}),document.body):null]})}const $c="flowNode";function _R(e){if(!e||!(e instanceof Element))return!1;if(e.closest('[contenteditable="true"]'))return!0;const t=e.tagName;return!!(t==="INPUT"||t==="TEXTAREA"||t==="SELECT"||e.isContentEditable)}function Yg(e){return e.key==="?"||e.key==="/"&&e.shiftKey}function mU(){return typeof navigator>"u"?!1:/Mac|iPhone|iPod|iPad/i.test(navigator.platform||navigator.userAgent||"")}function AR({open:e,onClose:t,flowId:n,flowSource:r,onArchived:s}){const{t:o}=zn(),a=h.useId(),l=h.useRef(null),[c,d]=h.useState(""),[p,u]=h.useState(!1),[f,m]=h.useState("");if(h.useEffect(()=>{if(!e)return;d(""),m(""),u(!1);const y=requestAnimationFrame(()=>{var b;return(b=l.current)==null?void 0:b.focus()});return()=>cancelAnimationFrame(y)},[e,n]),!e)return null;const g=c.trim(),w=g===n;async function k(y){if(y.preventDefault(),!(!w||p)){u(!0),m("");try{const b=await fetch("/api/flow/archive",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({flowId:n,flowSource:r,confirmFlowId:g})}),x=await b.json().catch(()=>({}));if(!b.ok){m(typeof x.error=="string"?x.error:o("project:archiveModal.archiveFailed"));return}s()}catch(b){m(String((b==null?void 0:b.message)||b))}finally{u(!1)}}}return i.jsx("div",{className:"af-shortcuts-overlay",role:"presentation",onMouseDown:y=>{y.target===y.currentTarget&&t()},children:i.jsxs("div",{ref:l,className:"af-shortcuts-panel af-new-pipeline-panel",role:"dialog","aria-modal":"true","aria-labelledby":a,tabIndex:-1,onMouseDown:y=>y.stopPropagation(),children:[i.jsxs("div",{className:"af-shortcuts-panel__head",children:[i.jsx("h2",{id:a,className:"af-shortcuts-panel__title",children:o("project:archiveModal.title")}),i.jsx("button",{type:"button",className:"af-shortcuts-panel__close af-icon-btn",onClick:t,"aria-label":o("project:archiveModal.close"),children:i.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),i.jsxs("form",{className:"af-shortcuts-panel__body af-new-pipeline-form",onSubmit:k,children:[i.jsx("p",{className:"af-new-pipeline-lead",children:o("project:archiveModal.lead",{flowId:n})}),i.jsxs("label",{className:"af-new-pipeline-field",children:[i.jsx("span",{className:"af-pipeline-drawer-label",children:o("project:archiveModal.confirmLabel")}),i.jsx("input",{type:"text",className:"af-new-pipeline-input",value:c,onChange:y=>d(y.target.value),placeholder:n,autoComplete:"off",spellCheck:!1,"aria-invalid":g.length>0&&!w})]}),f?i.jsx("p",{className:"af-err af-new-pipeline-err",children:f}):null,i.jsxs("div",{className:"af-new-pipeline-actions",children:[i.jsx("button",{type:"button",className:"af-btn-secondary",onClick:t,disabled:p,children:o("project:archiveModal.cancel")}),i.jsx("button",{type:"submit",className:"af-btn-primary",disabled:!w||p,children:o(p?"project:archiveModal.archiving":"project:archiveModal.confirmArchive")})]})]})]})})}function P1({open:e,title:t,message:n,confirmLabel:r,cancelLabel:s,destructive:o=!1,secondaryLabel:a,secondaryDestructive:l=!1,onSecondary:c,onConfirm:d,onCancel:p}){const{t:u}=zn(),f=h.useId(),m=h.useRef(null);if(h.useEffect(()=>{if(!e)return;const y=requestAnimationFrame(()=>{var x;return(x=m.current)==null?void 0:x.focus()});function b(x){x.key==="Escape"&&p(),x.key==="Enter"&&d()}return window.addEventListener("keydown",b),()=>{cancelAnimationFrame(y),window.removeEventListener("keydown",b)}},[e,p,d]),!e)return null;const g=r??u("common:common.confirm","确定"),w=s??u("common:common.cancel","取消"),k=t??u("common:common.confirmTitle","请确认");return i.jsx("div",{className:"af-shortcuts-overlay",role:"presentation",onMouseDown:y=>{y.target===y.currentTarget&&p()},children:i.jsxs("div",{ref:m,className:"af-shortcuts-panel af-new-pipeline-panel",role:"dialog","aria-modal":"true","aria-labelledby":f,tabIndex:-1,onMouseDown:y=>y.stopPropagation(),children:[i.jsxs("div",{className:"af-shortcuts-panel__head",children:[i.jsx("h2",{id:f,className:"af-shortcuts-panel__title",children:k}),i.jsx("button",{type:"button",className:"af-shortcuts-panel__close af-icon-btn",onClick:p,"aria-label":w,children:i.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),i.jsxs("div",{className:"af-shortcuts-panel__body af-new-pipeline-form",children:[i.jsx("p",{className:"af-new-pipeline-lead",children:n}),i.jsxs("div",{className:"af-new-pipeline-actions",children:[i.jsx("button",{type:"button",className:"af-btn-secondary",onClick:p,children:w}),a&&c?i.jsx("button",{type:"button",className:l?"af-btn-secondary af-btn-destructive":"af-btn-secondary",onClick:c,children:a}):null,i.jsx("button",{type:"button",className:o?"af-btn-primary af-btn-destructive":"af-btn-primary",onClick:d,autoFocus:!0,children:g})]})]})]})})}function PR({open:e,onClose:t,flowId:n,flowSource:r,flowArchived:s=!1,onDeleted:o}){const{t:a}=zn(),l=h.useId(),c=h.useRef(null),[d,p]=h.useState(""),[u,f]=h.useState(!1),[m,g]=h.useState("");if(h.useEffect(()=>{if(!e)return;p(""),g(""),f(!1);const b=requestAnimationFrame(()=>{var x;return(x=c.current)==null?void 0:x.focus()});return()=>cancelAnimationFrame(b)},[e,n]),!e)return null;const w=d.trim(),k=w===n;async function y(b){if(b.preventDefault(),!k||u)return;f(!0),g("");let x=null;try{const j=new AbortController;x=setTimeout(()=>j.abort(),15e3);const E=await fetch("/api/flow/delete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({flowId:n,flowSource:r,confirmFlowId:w,flowArchived:s}),signal:j.signal}),N=await E.json().catch(()=>({}));if(!E.ok){g(typeof N.error=="string"?N.error:a("project:deleteModal.deleteFailed"));return}try{for(let T=localStorage.length-1;T>=0;T--){const $=localStorage.key(T);$&&($.startsWith(`af:composer-sessions:${n}:${r}`)||$.startsWith(`af:composer-active-session:${n}:${r}`)||$.startsWith(`af:workspace-composer:${n}:${r}`))&&localStorage.removeItem($)}}catch{}await o()}catch(j){if((j==null?void 0:j.name)==="AbortError"){g(a("project:deleteModal.deleteTimeout"));return}g(String((j==null?void 0:j.message)||j))}finally{x&&clearTimeout(x),f(!1)}}return i.jsx("div",{className:"af-shortcuts-overlay",role:"presentation",onMouseDown:b=>{b.target===b.currentTarget&&t()},children:i.jsxs("div",{ref:c,className:"af-shortcuts-panel af-new-pipeline-panel",role:"dialog","aria-modal":"true","aria-labelledby":l,tabIndex:-1,onMouseDown:b=>b.stopPropagation(),children:[i.jsxs("div",{className:"af-shortcuts-panel__head",children:[i.jsx("h2",{id:l,className:"af-shortcuts-panel__title",children:a("project:deleteModal.title")}),i.jsx("button",{type:"button",className:"af-shortcuts-panel__close af-icon-btn",onClick:t,"aria-label":a("project:deleteModal.close"),children:i.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),i.jsxs("form",{className:"af-shortcuts-panel__body af-new-pipeline-form",onSubmit:y,children:[i.jsx("p",{className:"af-new-pipeline-lead",children:a("project:deleteModal.lead",{flowId:n})}),i.jsxs("label",{className:"af-new-pipeline-field",children:[i.jsx("span",{className:"af-pipeline-drawer-label",children:a("project:deleteModal.confirmLabel")}),i.jsx("input",{type:"text",className:"af-new-pipeline-input",value:d,onChange:b=>p(b.target.value),placeholder:n,autoComplete:"off",spellCheck:!1,"aria-invalid":w.length>0&&!k})]}),m?i.jsx("p",{className:"af-err af-new-pipeline-err",children:m}):null,i.jsxs("div",{className:"af-new-pipeline-actions",children:[i.jsx("button",{type:"button",className:"af-btn-secondary",onClick:t,disabled:u,children:a("project:deleteModal.cancel")}),i.jsx("button",{type:"submit",className:"af-btn-primary af-btn-destructive",disabled:!k||u,children:a(u?"project:deleteModal.deleting":"project:deleteModal.confirmDelete")})]})]})]})})}function gU({children:e}){return i.jsx("kbd",{className:"af-kbd",children:e})}function Ui({keys:e}){return i.jsx("span",{className:"af-shortcuts-keys",children:e.map((t,n)=>i.jsxs("span",{children:[n>0?i.jsx("span",{className:"af-shortcuts-keys__plus",children:"+"}):null,i.jsx(gU,{children:t})]},n))})}function IR({open:e,onClose:t}){const{t:n}=zn(),r=h.useRef(null);if(h.useEffect(()=>{if(!e)return;const a=requestAnimationFrame(()=>{var l;return(l=r.current)==null?void 0:l.focus()});return()=>cancelAnimationFrame(a)},[e]),!e)return null;const o=mU()?"⌘":"Ctrl";return i.jsx("div",{className:"af-shortcuts-overlay",role:"presentation",onMouseDown:a=>{a.target===a.currentTarget&&t()},children:i.jsxs("div",{ref:r,className:"af-shortcuts-panel",role:"dialog","aria-modal":"true","aria-labelledby":"af-shortcuts-title",tabIndex:-1,onMouseDown:a=>a.stopPropagation(),children:[i.jsxs("div",{className:"af-shortcuts-panel__head",children:[i.jsx("h2",{id:"af-shortcuts-title",className:"af-shortcuts-panel__title",children:n("flow:shortcuts.title")}),i.jsx("button",{type:"button",className:"af-shortcuts-panel__close af-icon-btn",onClick:t,"aria-label":n("common:common.close"),children:i.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),i.jsxs("div",{className:"af-shortcuts-panel__body",children:[i.jsxs("section",{className:"af-shortcuts-section",children:[i.jsx("h3",{className:"af-shortcuts-cat",children:n("flow:shortcuts.general")}),i.jsxs("ul",{className:"af-shortcuts-list",children:[i.jsxs("li",{className:"af-shortcuts-row",children:[i.jsx("span",{className:"af-shortcuts-row__label",children:n("flow:shortcuts.saveDesc")}),i.jsx(Ui,{keys:[o,"S"]})]}),i.jsxs("li",{className:"af-shortcuts-row",children:[i.jsx("span",{className:"af-shortcuts-row__label",children:n("flow:shortcuts.shortcutsLabel")}),i.jsx(Ui,{keys:["?"]})]}),i.jsxs("li",{className:"af-shortcuts-row",children:[i.jsx("span",{className:"af-shortcuts-row__label",children:n("flow:shortcuts.jumpToNode")}),i.jsx(Ui,{keys:[o,"K"]})]}),i.jsxs("li",{className:"af-shortcuts-row",children:[i.jsx("span",{className:"af-shortcuts-row__label",children:n("flow:shortcuts.openNodePalette")}),i.jsx(Ui,{keys:["A"]})]})]})]}),i.jsxs("section",{className:"af-shortcuts-section",children:[i.jsx("h3",{className:"af-shortcuts-cat",children:n("flow:shortcuts.canvas")}),i.jsxs("ul",{className:"af-shortcuts-list",children:[i.jsxs("li",{className:"af-shortcuts-row",children:[i.jsx("span",{className:"af-shortcuts-row__label",children:n("flow:shortcuts.selectTool")}),i.jsx(Ui,{keys:["V"]})]}),i.jsxs("li",{className:"af-shortcuts-row",children:[i.jsx("span",{className:"af-shortcuts-row__label",children:n("flow:shortcuts.panTool")}),i.jsx(Ui,{keys:["H"]})]}),i.jsxs("li",{className:"af-shortcuts-row",children:[i.jsx("span",{className:"af-shortcuts-row__label",children:n("flow:shortcuts.holdSpacePan")}),i.jsx(Ui,{keys:["Space"]})]}),i.jsxs("li",{className:"af-shortcuts-row",children:[i.jsx("span",{className:"af-shortcuts-row__label",children:n("flow:shortcuts.saveViewport")}),i.jsx(Ui,{keys:["F"]})]}),i.jsxs("li",{className:"af-shortcuts-row",children:[i.jsx("span",{className:"af-shortcuts-row__label",children:n("flow:shortcuts.selectAll")}),i.jsx(Ui,{keys:[o,"A"]})]}),i.jsxs("li",{className:"af-shortcuts-row",children:[i.jsx("span",{className:"af-shortcuts-row__label",children:n("flow:shortcuts.undo")}),i.jsx(Ui,{keys:[o,"Z"]})]}),i.jsxs("li",{className:"af-shortcuts-row",children:[i.jsx("span",{className:"af-shortcuts-row__label",children:n("flow:shortcuts.redo")}),i.jsx(Ui,{keys:[o,"Shift","Z"]})]})]})]})]})]})})}function yU(e,t){if(!t)return 1;const n=t.toLowerCase(),r=(e.id||"").toLowerCase(),s=(e.label||"").toLowerCase(),o=(e.definitionId||"").toLowerCase();return r===n?100:r.startsWith(n)?80:r.includes(n)?60:s.startsWith(n)?40:s.includes(n)?30:o.includes(n)?15:0}function TR({open:e,onClose:t,onJump:n,nodes:r}){const{t:s}=zn(),[o,a]=h.useState(""),[l,c]=h.useState(0),d=h.useRef(null),p=h.useRef(null);h.useEffect(()=>{if(!e)return;a(""),c(0);const g=requestAnimationFrame(()=>{var w;return(w=d.current)==null?void 0:w.focus()});return()=>cancelAnimationFrame(g)},[e]);const u=h.useMemo(()=>{const g=(r||[]).map(y=>{var b,x,j;return{id:y.id,label:((b=y.data)==null?void 0:b.label)||"",definitionId:((x=y.data)==null?void 0:x.definitionId)||"",schemaType:((j=y.data)==null?void 0:j.schemaType)||""}}),w=o.trim(),k=g.map(y=>({e:y,s:yU(y,w)})).filter(y=>y.s>0);return k.sort((y,b)=>b.s-y.s||y.e.id.localeCompare(b.e.id)),k.slice(0,50).map(y=>y.e)},[r,o]);if(h.useEffect(()=>{l>=u.length&&c(0)},[u.length,l]),h.useEffect(()=>{var w;const g=(w=p.current)==null?void 0:w.querySelector(`[data-idx="${l}"]`);g&&g.scrollIntoView({block:"nearest"})},[l]),!e)return null;const f=g=>{const w=u[g];w&&(n(w.id),t())},m=g=>{if(g.key==="Escape"){g.preventDefault(),t();return}if(g.key==="ArrowDown"){g.preventDefault(),c(w=>Math.min(u.length-1,w+1));return}if(g.key==="ArrowUp"){g.preventDefault(),c(w=>Math.max(0,w-1));return}g.key==="Enter"&&(g.preventDefault(),f(l))};return i.jsx("div",{className:"af-jump-overlay",role:"presentation",onMouseDown:g=>{g.target===g.currentTarget&&t()},children:i.jsxs("div",{className:"af-jump-panel",role:"dialog","aria-modal":"true","aria-label":s("flow:jumpPalette.title"),onMouseDown:g=>g.stopPropagation(),children:[i.jsxs("div",{className:"af-jump-panel__input-wrap",children:[i.jsx("span",{className:"af-jump-panel__icon material-symbols-outlined","aria-hidden":!0,children:"search"}),i.jsx("input",{ref:d,type:"text",className:"af-jump-panel__input",placeholder:s("flow:jumpPalette.placeholder"),value:o,onChange:g=>{a(g.target.value),c(0)},onKeyDown:m,spellCheck:!1,autoComplete:"off"}),i.jsx("span",{className:"af-jump-panel__count",children:u.length})]}),u.length===0?i.jsx("div",{className:"af-jump-panel__empty",children:s("flow:jumpPalette.empty")}):i.jsx("ul",{ref:p,className:"af-jump-panel__list",role:"listbox",children:u.map((g,w)=>i.jsxs("li",{"data-idx":w,role:"option","aria-selected":w===l,className:"af-jump-panel__item"+(w===l?" af-jump-panel__item--active":""),onMouseEnter:()=>c(w),onMouseDown:k=>{k.preventDefault(),f(w)},children:[i.jsx("span",{className:"af-jump-panel__id",children:g.id}),g.label&&g.label!==g.id&&i.jsx("span",{className:"af-jump-panel__label",children:g.label}),g.definitionId&&i.jsx("span",{className:"af-jump-panel__tag",children:g.definitionId})]},g.id))}),i.jsxs("div",{className:"af-jump-panel__hint",children:[i.jsxs("span",{children:[i.jsx("kbd",{className:"af-kbd",children:"↑"}),i.jsx("kbd",{className:"af-kbd",children:"↓"})," ",s("flow:jumpPalette.hintNavigate")]}),i.jsxs("span",{children:[i.jsx("kbd",{className:"af-kbd",children:"Enter"})," ",s("flow:jumpPalette.hintJump")]}),i.jsxs("span",{children:[i.jsx("kbd",{className:"af-kbd",children:"Esc"})," ",s("flow:jumpPalette.hintClose")]})]})]})})}function xU({open:e,onClose:t,flowId:n,flowSource:r,flowArchived:s=!1,filePath:o,fileName:a,onSaved:l,onAiEdit:c}){const{t:d}=zn(),p=h.useId(),u=h.useRef(null),f=h.useRef(null),[m,g]=h.useState(""),[w,k]=h.useState(""),[y,b]=h.useState(!1),[x,j]=h.useState(!1),[E,N]=h.useState(!1),[T,$]=h.useState(""),[z,K]=h.useState("");if(h.useEffect(()=>{if(!e||!o)return;g(""),k(""),$(""),K(""),b(!0),j(!1),N(!1);const I=new URLSearchParams({flowId:n,flowSource:r,archived:s?"1":"0",path:o});(async()=>{try{const P=await fetch(`/api/pipeline-file-content?${I}`),O=await P.json();if(!P.ok)throw new Error(O.error||"HTTP "+P.status);g(O.content||""),k(O.content||"")}catch(P){$(P.message||String(P))}finally{b(!1)}})();const F=requestAnimationFrame(()=>{var P;return(P=u.current)==null?void 0:P.focus()});return()=>cancelAnimationFrame(F)},[e,o,n,r,s]),!e)return null;const B=m!==w;async function L(I){if(I.preventDefault(),!x){j(!0),$(""),K("");try{const F=new URLSearchParams({flowId:n,flowSource:r,archived:s?"1":"0",path:o}),P=await fetch(`/api/pipeline-file-save?${F}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:m})}),O=await P.json();if(!P.ok)throw new Error(O.error||"HTTP "+P.status);k(m),K(d("flow:fileEdit.saved")),l&&l()}catch(F){$(F.message||String(F))}finally{j(!1)}}}async function D(){if(!(!c||E||!m)){N(!0),$("");try{const I=await c(m);typeof I=="string"&&I&&g(I)}catch(I){$(I.message||String(I))}finally{N(!1)}}}function R(){g(w),$(""),K("")}const M=m.length>1e5;return i.jsx("div",{className:"af-shortcuts-overlay",role:"presentation",onMouseDown:I=>{I.target===I.currentTarget&&t()},children:i.jsxs("div",{ref:u,className:"af-shortcuts-panel af-file-edit-panel",role:"dialog","aria-modal":"true","aria-labelledby":p,tabIndex:-1,onMouseDown:I=>I.stopPropagation(),children:[i.jsxs("div",{className:"af-shortcuts-panel__head",children:[i.jsx("h2",{id:p,className:"af-shortcuts-panel__title",children:a||o}),i.jsx("button",{type:"button",className:"af-shortcuts-panel__close af-icon-btn",onClick:t,"aria-label":d("flow:fileEdit.close"),children:i.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),i.jsx("div",{className:"af-file-edit-body",children:y?i.jsx("div",{className:"af-file-edit-loading",children:d("flow:fileEdit.loading")}):T&&!m?i.jsx("div",{className:"af-file-edit-error",children:T}):i.jsxs(i.Fragment,{children:[M&&i.jsx("div",{className:"af-file-edit-warning",children:d("flow:fileEdit.largeFileWarning")}),i.jsx("textarea",{ref:f,className:"af-file-edit-textarea",value:m,onChange:I=>g(I.target.value),spellCheck:!1,placeholder:d("flow:fileEdit.placeholder")})]})}),(T||z)&&!y&&i.jsx("div",{className:`af-file-edit-status${z?" af-file-edit-status--success":""}`,children:z||T}),i.jsxs("div",{className:"af-file-edit-actions",children:[i.jsx("button",{type:"button",className:"af-btn-secondary",onClick:R,disabled:!B||x||E,children:d("flow:fileEdit.reset")}),c&&i.jsx("button",{type:"button",className:"af-btn-secondary af-btn-ai",onClick:D,disabled:E||x||!m,children:d(E?"flow:fileEdit.aiRunning":"flow:fileEdit.aiEdit")}),i.jsx("button",{type:"button",className:"af-btn-primary",onClick:L,disabled:!B||x||E,children:d(x?"flow:fileEdit.saving":"flow:fileEdit.save")})]})]})})}const RR=new Set(["workspaceRoot","pipelineWorkspace","cwd","flowName","runDir","flowDir"]),wU=["workspaceRoot","pipelineWorkspace","cwd","flowName","runDir","flowDir"];function bU(e,t){const n=e.slice(0,t),r=n.lastIndexOf("${");if(r<0)return null;const s=n.slice(r+2);return s.includes("}")?null:{atIndex:r,query:s}}function vU(e){const t=/\$\{([^}]*)\}/g,n=[];let r;for(;(r=t.exec(e))!==null;)n.push({start:r.index,end:r.index+r[0].length,key:r[1]});return n}function I1(e){const t=new Set;if(!Array.isArray(e))return t;for(const n of e){const r=(n==null?void 0:n.name)!=null?String(n.name).trim():"";r&&t.add(r)}return t}function MR(e,{inputNames:t,outputNames:n}){const r=e.trim();if(!r)return!1;if(r.startsWith("input.")){const s=r.slice(6).trim();return s!==""&&t.has(s)}if(r.startsWith("output.")){const s=r.slice(7).trim();return s!==""&&n.has(s)}if(RR.has(r)||t.has(r)||n.has(r))return!0;if(!r.includes(".")){const s=`${r}.md`;if(t.has(s)||n.has(s))return!0}return!1}function LR(e){return{inputNames:I1(e==null?void 0:e.inputs),outputNames:I1(e==null?void 0:e.outputs)}}function kU(e,t,n){const r=LR(t),s=vU(e),o=[];for(const a of s)if(!MR(a.key,r)){const l=a.key.trim()===""?n("flow:placeholder.empty"):a.key.trim();o.push({start:a.start,end:a.end,message:n("flow:placeholder.invalidPlaceholder",{hint:l})})}return o}function SU(e,t){const n=LR(t),r=/\$\{([^}]*)\}/g,s=[];let o=0,a;for(;(a=r.exec(e))!==null;){a.index>o&&s.push({kind:"plain",text:e.slice(o,a.index)});const l=a[0],c=MR(a[1],n);s.push({kind:c?"ph-valid":"ph-invalid",text:l}),o=a.index+l.length}return o<e.length&&s.push({kind:"plain",text:e.slice(o)}),s}function NU(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function jU(e){return e.map(t=>{const n=NU(t.text);return t.kind==="ph-invalid"?`<span class="af-body-ph-invalid">${n}</span>`:t.kind==="ph-valid"?`<span class="af-body-ph-valid">${n}</span>`:n}).join("")}function CU(e,t){const n=[];for(const r of(e==null?void 0:e.inputs)??[]){const s=(r==null?void 0:r.name)!=null?String(r.name).trim():"";if(!s)continue;const o=(r==null?void 0:r.type)!=null?String(r.type):"";n.push({section:"input",insert:`input.${s}`,label:s,subtitle:o?t("flow:placeholder.inputSubtitle",{type:o}):t("flow:placeholder.inputSubtitleNoType")})}for(const r of(e==null?void 0:e.outputs)??[]){const s=(r==null?void 0:r.name)!=null?String(r.name).trim():"";if(!s)continue;const o=(r==null?void 0:r.type)!=null?String(r.type):"";n.push({section:"output",insert:`output.${s}`,label:s,subtitle:o?t("flow:placeholder.outputSubtitle",{type:o}):t("flow:placeholder.outputSubtitleNoType")})}for(const r of wU)RR.has(r)&&n.push({section:"runtime",insert:r,label:r,subtitle:t("flow:placeholder.runtimeConst")});return n}function EU(e,t){const n=t.toLowerCase();return n?e.filter(r=>[r.insert,r.label,r.subtitle??""].map(o=>String(o).toLowerCase()).some(o=>o.includes(n))):e}function _U(e,t){if(!e||t<0)return null;const n=Math.min(t,e.value.length),r=getComputedStyle(e),s=document.createElement("div");s.setAttribute("aria-hidden","true"),s.style.visibility="hidden",s.style.position="fixed",s.style.top="0",s.style.left="-99999px",s.style.whiteSpace="pre-wrap",s.style.wordWrap="break-word",s.style.overflow="hidden";const o=e.clientWidth;if(o<=0)return null;s.style.width=`${o}px`,s.style.font=r.font,s.style.lineHeight=r.lineHeight,s.style.padding=r.padding,s.style.border=r.border,s.style.boxSizing=r.boxSizing,s.style.letterSpacing=r.letterSpacing,s.style.textIndent=r.textIndent,s.style.tabSize=r.tabSize||"8",s.textContent=e.value.slice(0,n);const a=document.createElement("span");a.textContent="​",s.appendChild(a),document.body.appendChild(s);const l=a.getBoundingClientRect(),c=parseFloat(r.lineHeight),d=Number.isFinite(c)&&c>0?c:l.height||16;return document.body.removeChild(s),{top:l.top,left:l.left,bottom:l.bottom,height:d}}function mm({value:e,onChange:t,disabled:n,placeholder:r,rows:s=8,textareaClassName:o,ioSlots:a,variant:l="drawer",images:c,onImagesChange:d}){const{t:p}=zn(),u=h.useId(),f=h.useRef(null),m=h.useRef(null),[g,w]=h.useState(0),[k,y]=h.useState(0),[b,x]=h.useState(null),j=h.useMemo(()=>Vs(c),[c]),E=h.useMemo(()=>kU(e,a,p),[e,a,p]),N=E.length>0,T=h.useMemo(()=>SU(e,a),[e,a]),$=h.useMemo(()=>jU(T),[T]),z=h.useMemo(()=>n?null:bU(e,g),[e,g,n]),K=h.useMemo(()=>{if(!z)return[];const I=CU(a,p);return EU(I,z.query)},[z,a,p]);h.useEffect(()=>{y(I=>{const F=Math.max(0,K.length-1);return Math.min(Math.max(0,I),F)})},[K.length]);const B=h.useCallback(()=>{const I=f.current;if(!I||!z||K.length===0){x(null);return}const F=_U(I,g);if(!F){x(null);return}const P=4,O=44,_=13.5*16,Z=Math.min(K.length*O+8,_);let ee=F.bottom+P;ee+Z>window.innerHeight-8&&(ee=Math.max(8,F.top-Z-P));const V=288;let ae=F.left;ae=Math.max(8,Math.min(ae,window.innerWidth-V-8)),x({top:ee,left:ae})},[z,K.length,g]);h.useLayoutEffect(()=>{if(!z||K.length===0){x(null);return}const I=requestAnimationFrame(()=>B());return()=>cancelAnimationFrame(I)},[z,K.length,g,e,B]),h.useEffect(()=>{if(!z||K.length===0)return;const I=()=>B();return window.addEventListener("scroll",I,!0),window.addEventListener("resize",I),()=>{window.removeEventListener("scroll",I,!0),window.removeEventListener("resize",I)}},[z,K.length,B]);const L=h.useCallback(I=>{if(!z)return;const{atIndex:F}=z,P=e.slice(0,F)+"${"+I+"}"+e.slice(g);t(P);const O=F+I.length+3;queueMicrotask(()=>{const _=f.current;_&&(_.focus(),_.setSelectionRange(O,O)),w(O)})},[z,e,g,t]),D=h.useCallback(()=>{const I=f.current,F=m.current;!I||!F||(F.scrollTop=I.scrollTop,F.scrollLeft=I.scrollLeft,z&&K.length>0&&queueMicrotask(()=>B()))},[z,K.length,B]),R=h.useCallback(I=>{if(!n&&z&&K.length>0&&(I.key==="ArrowDown"||I.key==="ArrowUp"||I.key==="Enter")){if(I.key==="ArrowDown")I.preventDefault(),y(F=>(F+1)%K.length);else if(I.key==="ArrowUp")I.preventDefault(),y(F=>(F-1+K.length)%K.length);else if(I.key==="Enter"&&!I.shiftKey){I.preventDefault();const F=K[k];F&&L(F.insert)}}},[n,z,K,k,L]),M=h.useCallback(async I=>{if(n||typeof d!="function")return!1;const F=await vR({files:I,body:e,images:j});return F?(t(F.body),d(F.images),queueMicrotask(()=>{const P=f.current;if(!P)return;P.focus();const O=F.body.length;P.setSelectionRange(O,O),w(O)}),!0):!1},[n,j,t,d,e]);return i.jsxs("div",{className:"af-body-prompt-editor"+(l==="expand"?" af-body-prompt-editor--expand":""),children:[j.length>0?i.jsx("div",{className:"af-body-image-list","aria-label":"image attachments",children:j.map((I,F)=>i.jsxs("span",{className:"af-body-image-chip",title:I.name,children:[i.jsx("img",{src:I.dataUrl,alt:""}),i.jsxs("span",{children:["[",I.label||`image ${F+1}`,"]"]})]},I.id||F))}):null,i.jsxs("div",{className:"af-body-prompt-stack",children:[i.jsx("pre",{ref:m,className:"af-body-prompt-backdrop "+o,"aria-hidden":"true",dangerouslySetInnerHTML:{__html:$+`
128
- `}}),i.jsx("textarea",{ref:f,className:"af-body-prompt-textarea "+o,rows:s,value:e,disabled:n,placeholder:r,spellCheck:!1,"aria-invalid":N,"aria-describedby":N?u:void 0,onChange:I=>{t(I.target.value),w(I.target.selectionStart??I.target.value.length)},onSelect:I=>{const F=I.target;F instanceof HTMLTextAreaElement&&w(F.selectionStart??0)},onClick:I=>{const F=I.target;F instanceof HTMLTextAreaElement&&w(F.selectionStart??0)},onKeyUp:I=>{const F=I.target;F instanceof HTMLTextAreaElement&&w(F.selectionStart??F.value.length)},onKeyDown:R,onPaste:I=>{const F=bR(I);F.length!==0&&(I.preventDefault(),M(F).catch(()=>{}))},onDragOver:I=>{np(I).length>0&&I.preventDefault()},onDrop:I=>{const F=np(I);F.length!==0&&(I.preventDefault(),M(F).catch(()=>{}))},onScroll:D})]}),z&&K.length>0&&b?Ir.createPortal(i.jsx("ul",{className:"af-body-ph-menu af-body-ph-menu--pop af-composer-mention-menu",role:"listbox","aria-label":p("flow:nodeProps.placeholderSlots"),style:{position:"fixed",top:b.top,left:b.left,right:"auto",bottom:"auto",margin:0,zIndex:2e4},children:K.map((I,F)=>i.jsx("li",{role:"option","aria-selected":F===k,children:i.jsxs("button",{type:"button",className:"af-composer-mention-item"+(F===k?" af-composer-mention-item--active":""),onMouseDown:P=>P.preventDefault(),onMouseEnter:()=>y(F),onClick:()=>L(I.insert),children:[i.jsx("span",{className:"af-composer-mention-id",children:`\${${I.insert}}`}),I.subtitle?i.jsx("span",{className:"af-composer-mention-sub",children:I.subtitle}):null]})},`${I.section}-${I.insert}`))}),document.body):null,N?i.jsx("p",{id:u,className:"af-body-ph-issues",role:"status",children:E.map(I=>I.message).join(" · ")}):null]})}const OR=/^[a-zA-Z_][a-zA-Z0-9_-]*$/;function gm(e){const t=e.indexOf(" - ");return t>=0?e.slice(0,t).trim():e.trim()}function T1({kind:e,label:t,slots:n,onSlotsChange:r,disabled:s,requiredReadonly:o=!0}){const{t:a}=zn(),l=()=>r([...n,{type:"text",name:"",default:"",required:!1,showOnNode:!1}]),c=u=>r(n.filter((f,m)=>m!==u)),d=(u,f,m)=>{const g=n.map((w,k)=>{if(k!==u)return w;const y={...w,[f]:m};return f==="required"&&m===!0&&(y.showOnNode=!0),y});r(g)},p=e==="input"?"input":"output";return i.jsxs("div",{className:"af-node-props-field af-node-props-field--io",children:[i.jsxs("div",{className:"af-node-props-io-head",children:[i.jsx("span",{className:"af-node-props-label",children:t}),i.jsx("button",{type:"button",className:"af-btn-ghost af-node-props-io-add",onClick:l,disabled:s,"aria-label":a("flow:nodeProps.addPinAriaLabel",{label:t}),children:a("flow:nodeProps.addPin")})]}),i.jsx("p",{className:"af-node-props-io-hint",children:a("flow:nodeProps.handleHint",{prefix:p})}),n.length===0?i.jsx("p",{className:"af-node-props-io-empty",children:a(e==="input"?"flow:nodeProps.noInputPins":"flow:nodeProps.noOutputPins")}):null,n.length>0?i.jsxs("div",{className:"af-node-props-io-table",role:"group","aria-label":t,children:[i.jsxs("div",{className:"af-node-props-io-table-head","aria-hidden":!0,children:[i.jsx("span",{children:a("flow:nodeProps.handle")}),i.jsx("span",{children:a("flow:nodeProps.type")}),i.jsx("span",{children:a("flow:nodeProps.name")}),i.jsx("span",{children:a("flow:nodeProps.defaultValue")}),i.jsx("span",{children:a("flow:nodeProps.description")}),i.jsx("span",{children:a("flow:nodeProps.required")}),i.jsx("span",{children:a("flow:nodeProps.showOnNode")}),i.jsx("span",{})]}),n.map((u,f)=>i.jsxs("div",{className:"af-node-props-io-row",children:[i.jsxs("span",{className:"af-node-props-io-handle",title:`${p}-${f}`,children:[p,"-",f]}),i.jsx("select",{className:"af-node-props-input af-node-props-io-cell",value:u.type,onChange:m=>d(f,"type",m.target.value),disabled:s,"aria-label":a("flow:nodeProps.pinTypeAriaLabel",{label:t,index:f}),children:["node","text","file","bool"].map(m=>i.jsx("option",{value:m,children:m},m))}),i.jsx("input",{type:"text",className:"af-node-props-input af-node-props-io-cell",value:u.name,onChange:m=>d(f,"name",m.target.value),disabled:s,spellCheck:!1,autoComplete:"off","aria-label":a("flow:nodeProps.pinNameAriaLabel",{label:t,index:f})}),i.jsx("input",{type:"text",className:"af-node-props-input af-node-props-io-cell",value:u.default,onChange:m=>d(f,"default",m.target.value),disabled:s,spellCheck:!1,autoComplete:"off","aria-label":a("flow:nodeProps.pinDefaultAriaLabel",{label:t,index:f})}),i.jsx("input",{type:"text",className:"af-node-props-input af-node-props-io-cell",value:u.description||"",onChange:m=>d(f,"description",m.target.value),disabled:s,spellCheck:!1,autoComplete:"off","aria-label":a("flow:nodeProps.pinDescriptionAriaLabel",{label:t,index:f})}),i.jsx("label",{className:"af-node-props-io-flag",title:a("flow:nodeProps.requiredHint"),children:i.jsx("input",{type:"checkbox",checked:!!u.required,onChange:m=>{o||d(f,"required",m.target.checked)},disabled:s||o,"aria-label":a("flow:nodeProps.pinRequiredAriaLabel",{label:t,index:f})})}),i.jsx("label",{className:"af-node-props-io-flag",title:a("flow:nodeProps.showOnNodeHint"),children:i.jsx("input",{type:"checkbox",checked:u.showOnNode!==!1,onChange:m=>d(f,"showOnNode",m.target.checked),disabled:s,"aria-label":a("flow:nodeProps.pinShowOnNodeAriaLabel",{label:t,index:f})})}),i.jsx("button",{type:"button",className:"af-icon-btn af-node-props-io-remove",onClick:()=>c(f),disabled:s,"aria-label":a("flow:nodeProps.deletePinAriaLabel",{label:t,index:f}),title:a("flow:nodeProps.deletePin"),children:i.jsx("span",{className:"material-symbols-outlined",children:"delete"})})]},`${p}-${f}`))]}):null]})}function $R({draft:e,setDraft:t,definitionId:n,systemPromptReadonly:r,modelLists:s,disabled:o,onIdBlur:a,onClose:l,onPublishToMarketplace:c,allowEditRequiredPins:d=!1,error:p,ioSlots:u}){const{t:f}=zn(),[m,g]=h.useState(!1),[w,k]=h.useState(!1),[y,b]=h.useState({status:"idle",message:""}),x=h.useCallback(L=>{t(D=>D&&{...D,...L})},[t]),{cursorList:j,opencodeList:E,claudeCodeList:N,currentNotInLists:T}=h.useMemo(()=>{const L=Array.isArray(s==null?void 0:s.cursor)?s.cursor:[],D=Array.isArray(s==null?void 0:s.opencode)?s.opencode:[],R=Array.isArray(s==null?void 0:s.claudeCode)?s.claudeCode:[],M=new Set([...L,...D,...R].map(gm)),I=((e==null?void 0:e.model)??"").trim(),F=I.startsWith("cursor:")?I.slice(7):I.startsWith("opencode:")?I.slice(9):I.startsWith("claude-code:")?I.slice(12):I,P=I&&!M.has(F)?I:"";return{cursorList:L,opencodeList:D,claudeCodeList:R,currentNotInLists:P}},[s,e==null?void 0:e.model]);if(!e)return null;const $=String(e.script??""),z=n==="tool_nodejs"||$.trim()!=="",K=typeof c=="function"&&!o&&(e==null?void 0:e.newId),B=async()=>{if(K){b({status:"running",message:f("flow:nodeProps.publishRunning")});try{const L=await c(e,n);b({status:"success",message:L!=null&&L.definitionId?f("flow:nodeProps.publishSuccessWithId",{id:L.definitionId}):f("flow:nodeProps.publishSuccess")})}catch(L){b({status:"error",message:String((L==null?void 0:L.message)||L)})}}};return i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"af-pipeline-drawer-head af-node-props-head",children:[i.jsx("h2",{className:"af-pipeline-drawer-title",children:f("flow:nodeProps.title")}),i.jsxs("div",{className:"af-node-props-head-actions",children:[i.jsxs("button",{type:"button",className:"af-btn-ghost af-node-props-market-btn",onClick:B,disabled:!K||y.status==="running",title:f("flow:nodeProps.publishToMarketplaceHint"),children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"inventory_2"}),y.status==="running"?f("flow:nodeProps.publishing"):f("flow:nodeProps.publishToMarketplace")]}),i.jsx("button",{type:"button",className:"af-btn-ghost af-node-props-close-secondary",onClick:l,children:f("common:common.close")})]})]}),i.jsxs("div",{className:"af-pipeline-drawer-body af-node-props-body",children:[p?i.jsx("p",{className:"af-err af-node-props-err",children:p}):null,y.message?i.jsx("p",{className:`af-node-props-market-status af-node-props-market-status--${y.status}`,children:y.message}):null,i.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[i.jsx("span",{className:"af-node-props-label",children:f("flow:node.nodeType")}),i.jsx("div",{className:"af-pipeline-drawer-readonly af-node-props-readonly-mono",children:n})]}),i.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[i.jsxs("span",{className:"af-node-props-label",children:[f("flow:nodeProps.instanceId"),i.jsx("span",{className:"af-node-props-hint",children:f("flow:node.displayNameHint")})]}),i.jsx("input",{type:"text",className:"af-node-props-input",value:e.newId,onChange:L=>x({newId:L.target.value}),onBlur:a,disabled:o,spellCheck:!1,autoComplete:"off","aria-label":f("flow:nodeProps.instanceId")})]}),i.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[i.jsxs("span",{className:"af-node-props-label",children:[f("flow:node.displayName"),"(LABEL)"]}),i.jsx("input",{type:"text",className:"af-node-props-input",value:e.label,onChange:L=>x({label:L.target.value}),disabled:o,spellCheck:!1})]}),i.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[i.jsxs("span",{className:"af-node-props-label",children:[f("flow:node.role"),"(ROLE)"]}),i.jsx("select",{className:"af-node-props-select",value:Rl.includes(e.role)?e.role:f("flow:roles.normal"),onChange:L=>x({role:L.target.value}),disabled:o,children:Rl.map(L=>i.jsx("option",{value:L,children:L},L))})]}),i.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[i.jsxs("span",{className:"af-node-props-label",children:[f("flow:node.model"),"(MODEL)"]}),i.jsx("span",{className:"af-node-props-sublabel",children:f("flow:node.modelHint")}),i.jsxs("select",{className:"af-node-props-select",value:(()=>{const L=(e.model||"").trim();return L?T||L:""})(),onChange:L=>x({model:L.target.value}),disabled:o,"aria-label":f("flow:nodeProps.modelAriaLabel"),children:[i.jsx("option",{value:"",children:f("flow:node.defaultModel")}),T?i.jsxs("option",{value:T,children:[T,f("flow:nodeProps.yamlValueNotInList")]}):null,j.length>0?i.jsx("optgroup",{label:"Cursor",children:j.map(L=>i.jsx("option",{value:gm(L),children:L},`c-${L}`))}):null,E.length>0?i.jsx("optgroup",{label:"OpenCode",children:E.map(L=>i.jsx("option",{value:gm(L),children:L},`o-${L}`))}):null,N.length>0?i.jsx("optgroup",{label:"Claude Code",children:N.map(L=>i.jsx("option",{value:`claude-code:${gm(L)}`,children:L},`cc-${L}`))}):null]})]}),i.jsx(T1,{kind:"input",label:f("flow:nodeProps.inputPins"),slots:Array.isArray(e.inputs)?e.inputs:[],onSlotsChange:L=>x({inputs:L}),disabled:o,requiredReadonly:!d}),i.jsx(T1,{kind:"output",label:f("flow:nodeProps.outputPins"),slots:Array.isArray(e.outputs)?e.outputs:[],onSlotsChange:L=>x({outputs:L}),disabled:o,requiredReadonly:!d}),z?i.jsxs("div",{className:"af-pipeline-drawer-field af-node-props-field af-node-props-field--prompt",children:[i.jsxs("div",{className:"af-node-props-prompt-head",children:[i.jsxs("span",{className:"af-node-props-label",children:[f("flow:node.directCommand"),"(script)",i.jsx("span",{className:"af-node-props-hint",children:f("flow:node.scriptHint")})]}),i.jsx("button",{type:"button",className:"af-icon-btn af-node-props-expand",onClick:()=>k(!0),"aria-label":f("flow:nodeProps.expandEditScript"),title:f("flow:nodeProps.expand"),disabled:o,children:i.jsx("span",{className:"material-symbols-outlined",children:"open_in_full"})})]}),i.jsx(mm,{value:$,onChange:L=>x({script:L}),disabled:o,placeholder:f("flow:nodeProps.scriptPlaceholder"),rows:6,textareaClassName:"af-pipeline-drawer-textarea af-node-props-body-textarea af-node-props-script-textarea",ioSlots:u,variant:"drawer"})]}):null,i.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[i.jsx("span",{className:"af-node-props-label",children:"Script file(scriptRef)"}),i.jsxs("span",{className:"af-node-props-sublabel",children:["Relative path under this flow, for example nodes/",e.id,"/script.mjs"]}),i.jsx("input",{type:"text",className:"af-node-props-input",value:e.scriptRef||"",onChange:L=>x({scriptRef:L.target.value}),disabled:o,spellCheck:!1,autoComplete:"off"})]}),i.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[i.jsx("span",{className:"af-node-props-label",children:"Implementation file(implementationRef)"}),i.jsxs("span",{className:"af-node-props-sublabel",children:["Relative path under this flow, for example nodes/",e.id,"/implementation.md"]}),i.jsx("input",{type:"text",className:"af-node-props-input",value:e.implementationRef||"",onChange:L=>x({implementationRef:L.target.value}),disabled:o,spellCheck:!1,autoComplete:"off"})]}),i.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[i.jsx("span",{className:"af-node-props-label",children:"Implementation mode"}),i.jsxs("select",{className:"af-node-props-select",value:e.implementationMode||"",onChange:L=>x({implementationMode:L.target.value}),disabled:o,children:[i.jsx("option",{value:"",children:"auto"}),i.jsx("option",{value:"script",children:"script"}),i.jsx("option",{value:"steps",children:"steps"}),i.jsx("option",{value:"hybrid",children:"hybrid"})]})]}),i.jsxs("div",{className:"af-pipeline-drawer-field af-node-props-field af-node-props-field--prompt",children:[i.jsxs("div",{className:"af-node-props-prompt-head",children:[i.jsx("span",{className:"af-node-props-label",children:f("flow:node.userPrompt")}),i.jsx("button",{type:"button",className:"af-icon-btn af-node-props-expand",onClick:()=>g(!0),"aria-label":f("flow:nodeProps.expandEdit"),title:f("flow:nodeProps.expand"),disabled:o,children:i.jsx("span",{className:"material-symbols-outlined",children:"open_in_full"})})]}),i.jsx(mm,{value:e.body,onChange:L=>x({body:L}),images:e.images,onImagesChange:L=>x({images:L}),disabled:o,placeholder:f("flow:nodeProps.bodyPlaceholder"),rows:8,textareaClassName:"af-pipeline-drawer-textarea af-node-props-body-textarea",ioSlots:u,variant:"drawer"})]}),i.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[i.jsx("span",{className:"af-node-props-label",children:f("flow:node.systemDescription")}),i.jsx("textarea",{className:"af-pipeline-drawer-textarea af-node-props-system-readonly",rows:4,readOnly:!0,value:r||f("flow:nodeProps.noDescription"),spellCheck:!1})]})]}),w?i.jsx("div",{className:"af-node-props-expand-overlay",role:"dialog","aria-modal":"true","aria-label":f("flow:nodeProps.editScript"),onMouseDown:L=>{L.target===L.currentTarget&&k(!1)},children:i.jsxs("div",{className:"af-node-props-expand-panel",children:[i.jsxs("div",{className:"af-node-props-expand-head",children:[i.jsx("span",{className:"af-node-props-expand-title",children:f("flow:node.directCommand")}),i.jsx("button",{type:"button",className:"af-icon-btn",onClick:()=>k(!1),"aria-label":f("flow:nodeProps.collapse"),children:i.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),i.jsx(mm,{value:$,onChange:L=>x({script:L}),disabled:o,placeholder:f("flow:nodeProps.scriptPlaceholderExpand"),rows:16,textareaClassName:"af-node-props-expand-textarea",ioSlots:u,variant:"expand"})]})}):null,m?i.jsx("div",{className:"af-node-props-expand-overlay",role:"dialog","aria-modal":"true","aria-label":f("flow:nodeProps.editUserPrompt"),onMouseDown:L=>{L.target===L.currentTarget&&g(!1)},children:i.jsxs("div",{className:"af-node-props-expand-panel",children:[i.jsxs("div",{className:"af-node-props-expand-head",children:[i.jsx("span",{className:"af-node-props-expand-title",children:f("flow:node.body")}),i.jsx("button",{type:"button",className:"af-icon-btn",onClick:()=>g(!1),"aria-label":f("flow:nodeProps.collapse"),children:i.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),i.jsx(mm,{value:e.body,onChange:L=>x({body:L}),images:e.images,onImagesChange:L=>x({images:L}),disabled:o,placeholder:f("flow:nodeProps.bodyPlaceholderExpand"),rows:16,textareaClassName:"af-node-props-expand-textarea",ioSlots:u,variant:"expand"})]})}):null]})}function vk(e){var n;if(e.displayKind==="image"||e.encoding==="base64"&&((n=e.mimeType)!=null&&n.startsWith("image/")))return"image";if(e.displayKind==="json"||e.mimeType==="application/json")return"json";if(e.displayKind==="markdown"||e.mimeType==="text/markdown")return"markdown";if(e.displayKind==="text")return"text";const t=(e.content||"").trim();if(t&&(t.startsWith("{")||t.startsWith("[")))try{return JSON.parse(t),"json"}catch{}return"text"}function AU(e){const t=vk(e);if(t==="image"){const n=(e.mimeType||"image/png").split("/")[1];return n?n.toUpperCase():"IMAGE"}return t==="json"?"JSON":t==="markdown"?"MD":null}function DR(e){try{return JSON.stringify(JSON.parse(e.trim()),null,2)}catch{return e}}function R1({text:e}){const{t}=zn(),n=e||"";return n.trim()?i.jsx("div",{className:"af-run-ctx-md",children:i.jsx(ah,{children:n})}):i.jsx("div",{className:"af-run-ctx-hint",children:t("flow:runContext.empty")})}function M1({o:e}){var r;const{t}=zn(),n=vk(e);if(n==="image"||e.encoding==="base64"&&((r=e.mimeType)!=null&&r.startsWith("image/"))){const o=`data:${e.mimeType||"image/png"};base64,${e.content||""}`;return i.jsxs("div",{className:"af-run-ctx-media",children:[i.jsx("img",{className:"af-run-ctx-img",src:o,alt:e.slot||"output",loading:"lazy"}),e.truncated?i.jsx("div",{className:"af-run-ctx-hint",children:t("flow:runContext.imageTruncated")}):null]})}if(n==="json")return i.jsx("pre",{className:"af-run-ctx-pre",children:DR(e.content||"")});if(n==="markdown"){const s=e.content||"";return s.trim()?i.jsx("div",{className:"af-run-ctx-md",children:i.jsx(ah,{children:s})}):i.jsx("div",{className:"af-run-ctx-hint",children:t("flow:runContext.empty")})}return i.jsx("pre",{className:"af-run-ctx-pre",children:e.content!=null&&e.content!==""?e.content:t("flow:runContext.empty")})}function L1(e){return AU(e)}function O1(e){var r;if(!e)return null;const t=vk(e);if(t==="image"||e.encoding==="base64"&&((r=e.mimeType)!=null&&r.startsWith("image/")))return null;const n=e.content;return n==null||n===""?null:t==="json"?DR(String(n)):String(n)}function $1({text:e,title:t,copiedLabel:n}){const[r,s]=h.useState(!1);if(!e)return null;const o=async()=>{try{await navigator.clipboard.writeText(e),s(!0),window.setTimeout(()=>s(!1),1400)}catch{}};return i.jsx("button",{type:"button",className:"af-icon-btn af-run-ctx-copy-btn",onClick:o,title:r?n:t,"aria-label":r?n:t,children:i.jsx("span",{className:"material-symbols-outlined",children:r?"check":"content_copy"})})}const D1=2e4,FR="af:run-node-ctx-width";function Jm(){return typeof window>"u"?416:Math.min(26*16,window.innerWidth-32)}function hl(e){const n=Math.max(280,Math.min(Math.floor(window.innerWidth*.92),1200));return Number.isFinite(e)?Math.min(Math.max(Math.round(e),200),n):hl(Jm())}function PU(){try{const e=localStorage.getItem(FR);if(e==null)return hl(Jm());const t=parseInt(e,10);return Number.isFinite(t)?hl(t):hl(Jm())}catch{return hl(Jm())}}async function F1(e,t,n,r){const s=new URLSearchParams({flowId:e,instanceId:t});n&&String(n).trim()&&s.set("runId",String(n).trim());const o=await fetch(`/api/node-exec-context?${s.toString()}`,{signal:r}),a=await o.text();let l;try{l=JSON.parse(a)}catch{throw new Error(a.startsWith("<!")||a.startsWith("<html")?"apiConnectError":"invalidJson")}if(!o.ok)throw new Error(l.error||"HTTP "+o.status);return l}function IU(e,t){const n=`flow:runContext.${t}`,r=e(n);return r!==n?r:t}function TU({instanceId:e,flowId:t,runId:n,nodeStatus:r,onClose:s}){const{t:o}=zn(),[a,l]=h.useState(()=>typeof window<"u"&&window.matchMedia("(max-width: 960px)").matches),[c,d]=h.useState(PU),p=h.useRef({active:!1,pointerId:-1,startX:0,startW:416}),[u,f]=h.useState(!0),[m,g]=h.useState(""),[w,k]=h.useState([]),[y,b]=h.useState(null),[x,j]=h.useState(null),E=h.useRef(null),N=h.useRef(null),T=h.useRef(0),$=h.useRef(0);h.useLayoutEffect(()=>{const P=window.matchMedia("(max-width: 960px)"),O=()=>l(P.matches);return P.addEventListener("change",O),()=>P.removeEventListener("change",O)},[]),h.useEffect(()=>{function P(){d(O=>hl(O))}return window.addEventListener("resize",P),()=>window.removeEventListener("resize",P)},[]);const z=h.useCallback(()=>{d(P=>{const O=hl(P);try{localStorage.setItem(FR,String(O))}catch{}return O})},[]),K=h.useCallback(P=>{if(a||P.button!==0)return;P.preventDefault();const O=P.currentTarget;p.current={active:!0,pointerId:P.pointerId,startX:P.clientX,startW:c},O.setPointerCapture(P.pointerId)},[a,c]),B=h.useCallback(P=>{const O=p.current;if(!O.active||P.pointerId!==O.pointerId)return;const _=O.startX-P.clientX;d(hl(O.startW+_))},[]),L=h.useCallback(P=>{const O=p.current;if(!(!O.active||P.pointerId!==O.pointerId)){O.active=!1;try{P.currentTarget.releasePointerCapture(P.pointerId)}catch{}z()}},[z]),D=h.useCallback(()=>{const P=p.current;P.active&&(P.active=!1,z())},[z]),R=h.useCallback(P=>{const O=Array.isArray(P)?P:[];k(O),b(_=>_&&O.some(Z=>Z.execId===_)?_:O.length>0?O[O.length-1].execId:null)},[]),M=h.useCallback(()=>{if(!e||!t)return;const P=++T.current,O=new AbortController,_=window.setTimeout(()=>O.abort(),D1);(async()=>{try{const Z=await F1(t,e,n,O.signal);if(P!==T.current)return;R(Array.isArray(Z.rounds)?Z.rounds:[])}catch{}finally{window.clearTimeout(_)}})()},[e,t,n,R]);h.useEffect(()=>{if(!e||!t){f(!1),g(""),k([]);return}const P=++$.current;f(!0),g(""),k([]),b(null);const O=new AbortController,_=window.setTimeout(()=>O.abort(),D1);return(async()=>{try{const Z=await F1(t,e,n,O.signal);if(P!==$.current)return;R(Array.isArray(Z.rounds)?Z.rounds:[])}catch(Z){if(P!==$.current)return;const ee=(Z==null?void 0:Z.name)==="AbortError"?"requestTimeout":Z.message||String(Z);g(ee)}finally{window.clearTimeout(_),P===$.current&&f(!1)}})(),()=>{O.abort(),$.current++,T.current++}},[e,t,n,R]),h.useEffect(()=>{r&&M()},[r,M]),h.useEffect(()=>{clearInterval(N.current);const P=w.length>0?w[w.length-1]:null;return(r==="running"&&w.length===0||!!(P&&P.status==="running"))&&e&&t&&(N.current=setInterval(()=>M(),2e3)),()=>clearInterval(N.current)},[w,e,t,n,r,M]),h.useEffect(()=>{E.current&&(E.current.scrollTop=0)},[y]);const I=w.find(P=>P.execId===y),F=a?void 0:{width:`${c}px`};return i.jsxs("aside",{className:"af-run-ctx-panel",style:F,"aria-label":o("flow:runContext.title"),children:[a?null:i.jsx("div",{className:"af-run-ctx-resize",role:"separator","aria-orientation":"vertical","aria-label":o("flow:runContext.resizeHandle"),onPointerDown:K,onPointerMove:B,onPointerUp:L,onPointerCancel:L,onLostPointerCapture:D}),i.jsxs("div",{className:"af-run-ctx-panel__main",children:[i.jsxs("div",{className:"af-run-ctx-head",children:[i.jsx("h2",{className:"af-run-ctx-title",title:e,children:e}),i.jsx("button",{type:"button",className:"af-icon-btn",onClick:s,"aria-label":o("common:common.close"),children:i.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),u&&i.jsx("div",{className:"af-run-ctx-placeholder",children:o("common:common.loading")}),m&&i.jsx("div",{className:"af-run-ctx-error",children:IU(o,m)}),!u&&!m&&w.length===0&&i.jsx("div",{className:"af-run-ctx-placeholder",children:o(r==="running"?"flow:runContext.executingNoArtifacts":"flow:runContext.noData")}),w.length>0&&i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"af-run-ctx-rounds af-run-ctx-rounds--select af-run-ctx-round--"+MU((I==null?void 0:I.status)||""),children:[i.jsx("span",{className:"af-run-ctx-round-dot","aria-hidden":!0}),i.jsx("select",{className:"af-run-ctx-round-select",value:String(y??""),onChange:P=>{const O=P.target.value;b(O==="latest"?"latest":Number(O))},children:[...w].reverse().map(P=>{const O=P.execId==="latest"?o("flow:runContext.latest"):`#${P.execId}`,_=LU(o,P.status),Z=P.finishedAt?` · ${RU(P.finishedAt)}`:"";return i.jsx("option",{value:String(P.execId),children:`${O} · ${_}${Z}`},P.execId)})})]}),I&&i.jsxs("div",{className:"af-run-ctx-body",ref:E,children:[I.inputs&&I.inputs.length>0&&i.jsxs("section",{className:"af-run-ctx-section",children:[i.jsxs("h3",{className:"af-run-ctx-section-title",children:[i.jsx("span",{className:"material-symbols-outlined af-run-ctx-section-icon","aria-hidden":!0,children:"input"}),"Inputs"]}),I.inputs.map((P,O)=>i.jsxs("div",{className:"af-run-ctx-output-slot",children:[i.jsx("div",{className:"af-run-ctx-slot-head",children:i.jsx("div",{className:"af-run-ctx-slot-name",children:P.slot})}),i.jsx("pre",{className:"af-run-ctx-slot-text",children:P.value})]},`${P.slot}-${O}`))]}),I.prompt!=null&&i.jsxs("section",{className:"af-run-ctx-section",children:[i.jsxs("h3",{className:"af-run-ctx-section-title",children:[i.jsx("span",{className:"material-symbols-outlined af-run-ctx-section-icon","aria-hidden":!0,children:"description"}),"Prompt",i.jsx("button",{type:"button",className:"af-icon-btn af-run-ctx-section-expand",onClick:()=>j("prompt"),title:o("flow:nodeProps.expand"),children:i.jsx("span",{className:"material-symbols-outlined",children:"open_in_full"})})]}),i.jsx(R1,{text:I.prompt})]}),I.outputs&&I.outputs.length>0&&i.jsxs("section",{className:"af-run-ctx-section",children:[i.jsxs("h3",{className:"af-run-ctx-section-title",children:[i.jsx("span",{className:"material-symbols-outlined af-run-ctx-section-icon","aria-hidden":!0,children:"output"}),"Outputs",i.jsx("button",{type:"button",className:"af-icon-btn af-run-ctx-section-expand",onClick:()=>j("output"),title:o("flow:nodeProps.expand"),children:i.jsx("span",{className:"material-symbols-outlined",children:"open_in_full"})})]}),I.outputs.map((P,O)=>{const _=L1(P),Z=O1(P);return i.jsxs("div",{className:"af-run-ctx-output-slot",children:[i.jsxs("div",{className:"af-run-ctx-slot-head",children:[i.jsx("div",{className:"af-run-ctx-slot-name",children:P.slot}),_?i.jsx("span",{className:"af-run-ctx-format-badge",title:o("flow:runContext.detectedContentType"),children:_}):null,i.jsx($1,{text:Z,title:o("common:common.copy"),copiedLabel:o("common:common.copied")})]}),i.jsx(M1,{o:P})]},`${P.slot}-${O}`)})]}),!I.prompt&&(!I.outputs||I.outputs.length===0)&&i.jsx("div",{className:"af-run-ctx-placeholder",children:o("flow:runContext.roundNoContent")})]})]})]}),x&&I&&i.jsx("div",{className:"af-node-props-expand-overlay",role:"dialog","aria-modal":"true",onClick:P=>{P.target===P.currentTarget&&j(null)},children:i.jsxs("div",{className:"af-node-props-expand-panel",children:[i.jsxs("div",{className:"af-node-props-expand-head",children:[i.jsx("span",{className:"af-node-props-expand-title",children:x==="prompt"?"Prompt":"Outputs"}),i.jsx("button",{type:"button",className:"af-icon-btn",onClick:()=>j(null),"aria-label":o("common:common.close"),children:i.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),i.jsxs("div",{className:"af-node-props-expand-body af-run-ctx-expand-body",children:[x==="prompt"&&I.prompt!=null&&i.jsx(R1,{text:I.prompt}),x==="output"&&I.outputs&&I.outputs.map((P,O)=>{const _=L1(P),Z=O1(P);return i.jsxs("div",{className:"af-run-ctx-output-slot",style:{marginBottom:"1rem"},children:[i.jsxs("div",{className:"af-run-ctx-slot-head",children:[i.jsx("div",{className:"af-run-ctx-slot-name",children:P.slot}),_?i.jsx("span",{className:"af-run-ctx-format-badge",children:_}):null,i.jsx($1,{text:Z,title:o("common:common.copy"),copiedLabel:o("common:common.copied")})]}),i.jsx(M1,{o:P})]},`${P.slot}-${O}`)})]})]})})]})}function RU(e){try{const t=new Date(e);if(isNaN(t.getTime()))return e;const n=r=>String(r).padStart(2,"0");return`${n(t.getMonth()+1)}-${n(t.getDate())} ${n(t.getHours())}:${n(t.getMinutes())}`}catch{return e}}function MU(e){const t=String(e||"").toLowerCase();return t==="success"||t==="completed"||t==="done"?"success":t==="failed"||t==="error"?"failed":t==="running"||t==="executing"?"running":t==="cache_not_met"?"cache":t?"unknown":"pending"}function LU(e,t){const n=String(t||"").toLowerCase();return n?n==="success"||n==="completed"||n==="done"?e("flow:runContext.statusSuccess",{defaultValue:"成功"}):n==="failed"||n==="error"?e("flow:runContext.statusFailed",{defaultValue:"失败"}):n==="running"||n==="executing"?e("flow:runContext.statusRunning",{defaultValue:"运行中"}):n==="cache_not_met"?e("flow:runContext.statusCacheMiss",{defaultValue:"缓存失效"}):t:e("flow:runContext.statusPending",{defaultValue:"等待"})}function OU({flowId:e,flowSource:t,flowArchived:n,provideNodes:r,edges:s,nodes:o,onCliInputsChange:a,onBackToEdit:l}){const{t:c}=zn(),[d,p]=h.useState({}),[u,f]=h.useState(null),[m,g]=h.useState({}),[w,k]=h.useState(!0),[y,b]=h.useState(!1),[x,j]=h.useState(""),[E,N]=h.useState(!1),[T,$]=h.useState(null),z=h.useRef(null),K=h.useRef(!0),B=h.useRef({});h.useMemo(()=>{var _,Z,ee;const O={};for(const V of r){const ae=(ee=(Z=(_=V.data)==null?void 0:_.outputs)==null?void 0:Z[0])==null?void 0:ee.default;ae!=null&&ae!==""&&(O[V.id]=String(ae))}return B.current=O,O},[r]);const L=h.useMemo(()=>{var _;const O={};for(const Z of o){if(!((_=Z.data)!=null&&_.inputs))continue;const ee=Z.data.inputs;for(let V=0;V<ee.length;V++){const ae=ee[V];if(!(ae!=null&&ae.name))continue;const fe=s.find(Se=>Se.target===Z.id&&Se.targetHandle===`input-${V}`);if(!(fe!=null&&fe.source))continue;r.find(Se=>Se.id===fe.source)&&(O[fe.source]=ae.name)}}return O},[o,s,r]);h.useEffect(()=>(K.current=!0,()=>{K.current=!1}),[]),h.useEffect(()=>{if(!e){k(!1);return}k(!0);const O=new URLSearchParams({flowId:e,flowSource:t||"user"});n&&O.set("archived","1"),fetch(`/api/flow/run-config?${O.toString()}`).then(_=>{if(!_.ok)throw new Error(`HTTP ${_.status}`);return _.json()}).then(_=>{var ee;if(!K.current)return;p(_.presets||{}),f(_.activePreset||null);const Z=_.activePreset&&((ee=_.presets)!=null&&ee[_.activePreset])?_.presets[_.activePreset]:{};g({...B.current,...Z}),k(!1)}).catch(()=>{K.current&&(g(B.current),k(!1))})},[e,t,n]),h.useEffect(()=>{var _;if(!a)return;const O={};for(const[Z,ee]of Object.entries(m)){const V=L[Z];if(!V)continue;const ae=r.find(xe=>xe.id===Z);if(!ae)continue;(((_=ae.data)==null?void 0:_.definitionId)||"").startsWith("provide_file")?O[V]={type:"file",path:ee}:O[V]={type:"str",value:ee}}a(O)},[m,L,r,a]);const D=h.useCallback((O,_)=>{g(Z=>({...Z,[O]:_}))},[]),R=h.useCallback(O=>{O!==u&&(f(O),O&&d[O]?g({...B.current,...d[O]}):g(B.current))},[u,d]),M=h.useCallback(async()=>{if(x.trim()){b(!0);try{const O={...d,[x.trim()]:m},_={flowId:e,flowSource:t,archived:n,presets:O,activePreset:x.trim()};(await fetch("/api/flow/run-config",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(_)})).ok&&(p(O),f(x.trim()),j(""),N(!1))}finally{b(!1)}}},[e,t,n,d,m,x]),I=h.useCallback(async()=>{if(u){b(!0);try{const O={...d};delete O[u];const _=Object.keys(O)[0]||null;(await fetch("/api/flow/run-config",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({flowId:e,flowSource:t,archived:n,presets:O,activePreset:_})})).ok&&(p(O),f(_),_&&O[_]?g({...B.current,...O[_]}):g(B.current))}finally{b(!1)}}},[e,t,n,d,u]),F=h.useCallback(async()=>{if(u){b(!0);try{const O={...d,[u]:m};(await fetch("/api/flow/run-config",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({flowId:e,flowSource:t,archived:n,presets:O,activePreset:u})})).ok&&p(O)}finally{b(!1)}}},[e,t,n,d,u,m]),P=Object.keys(d);return P.length>0,w?i.jsx("aside",{className:"af-run-config-panel",children:i.jsx("div",{className:"af-run-config-loading",children:c("common.loading")})}):i.jsxs("aside",{className:"af-run-config-panel",children:[i.jsxs("div",{className:"af-run-config-preset",children:[i.jsx("label",{className:"af-run-config-preset-label",children:c("flow:runConfig.preset")}),i.jsxs("div",{className:"af-run-config-preset-row",children:[i.jsxs("select",{className:"af-run-config-preset-select",value:u||"",onChange:O=>R(O.target.value||null),disabled:y,children:[i.jsx("option",{value:"",children:c("flow:runConfig.default")}),P.map(O=>i.jsx("option",{value:O,children:O},O))]}),i.jsx("button",{type:"button",className:"af-run-config-preset-btn af-run-config-preset-btn--new",onClick:()=>N(!0),disabled:y,title:c("flow:runConfig.newPreset"),children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"add"})}),u&&i.jsx("button",{type:"button",className:"af-run-config-preset-btn af-run-config-preset-btn--save",onClick:F,disabled:y,title:c("flow:runConfig.savePreset"),children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"save"})}),u&&i.jsx("button",{type:"button",className:"af-run-config-preset-btn af-run-config-preset-btn--delete",onClick:I,disabled:y,title:c("flow:runConfig.deletePreset"),children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"delete"})})]})]}),E&&i.jsxs("div",{className:"af-run-config-save-dialog",children:[i.jsx("input",{type:"text",className:"af-run-config-save-input",placeholder:c("flow:runConfig.presetNamePlaceholder"),value:x,onChange:O=>j(O.target.value),disabled:y}),i.jsxs("div",{className:"af-run-config-save-actions",children:[i.jsx("button",{type:"button",className:"af-btn-primary",onClick:M,disabled:y||!x.trim(),children:c(y?"common.saving":"common.save")}),i.jsx("button",{type:"button",className:"af-btn-outline",onClick:()=>{N(!1),j("")},disabled:y,children:c("common.cancel")})]})]}),i.jsxs("div",{className:"af-run-config-inputs",children:[i.jsx("div",{className:"af-run-config-inputs-header",children:c("flow:runConfig.inputParams")}),r.length===0?i.jsx("div",{className:"af-run-config-empty",children:c("flow:runConfig.noProvideNodes")}):i.jsx("div",{className:"af-run-config-input-list",children:r.map(O=>{var Se,ue;const _=((Se=O.data)==null?void 0:Se.definitionId)||"",Z=_.startsWith("provide_file"),ee=_==="provide_bool",V=((ue=O.data)==null?void 0:ue.label)||O.id,ae=O.id,fe=m[ae]||"",xe=["true","1","yes","on"].includes(String(fe).trim().toLowerCase());return i.jsxs("div",{className:"af-run-config-input-item",children:[i.jsxs("div",{className:"af-run-config-input-head",children:[i.jsx("span",{className:"af-run-config-input-icon material-symbols-outlined"+(Z?" af-run-config-input-icon--file":""),"aria-hidden":!0,children:Z?"description":ee?"toggle_on":"text_fields"}),i.jsx("span",{className:"af-run-config-input-label",children:V}),ee?null:i.jsx("button",{type:"button",className:"af-run-config-input-expand",onClick:()=>$({instanceId:ae,label:V,content:fe}),"aria-label":c("flow:runConfig.expandInput"),title:c("flow:runConfig.expandInput"),children:i.jsx("span",{className:"material-symbols-outlined",children:"open_in_full"})})]}),i.jsx("div",{className:"af-run-config-input-id",children:ae}),ee?i.jsx("button",{type:"button",className:"af-run-config-bool-toggle"+(xe?" af-run-config-bool-toggle--true":""),onClick:()=>D(ae,xe?"false":"true"),"aria-pressed":xe,children:xe?"true":"false"}):i.jsx("input",{type:"text",className:"af-run-config-input-field",value:fe,onChange:Ee=>D(ae,Ee.target.value),placeholder:c(Z?"flow:runConfig.filePathPlaceholder":"flow:runConfig.stringValuePlaceholder")})]},ae)})})]}),T&&Ir.createPortal(i.jsx("div",{className:"af-provide-edit-overlay",children:i.jsxs("div",{className:"af-provide-edit-modal",role:"dialog","aria-modal":"true",children:[i.jsxs("div",{className:"af-provide-edit-modal__head",children:[i.jsx("span",{className:"material-symbols-outlined",children:"edit_document"}),i.jsx("span",{className:"af-provide-edit-modal__title",children:T.label}),i.jsx("button",{type:"button",className:"af-provide-edit-modal__close",onClick:()=>$(null),"aria-label":c("common:close"),children:i.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),i.jsx("div",{className:"af-provide-edit-modal__body",children:i.jsx("textarea",{ref:z,className:"af-provide-edit-modal__textarea",defaultValue:T.content,autoFocus:!0})}),i.jsxs("div",{className:"af-provide-edit-modal__foot",children:[i.jsxs("button",{type:"button",className:"af-provide-edit-modal__btn af-provide-edit-modal__btn--save",onClick:()=>{!T||!z.current||(D(T.instanceId,z.current.value),$(null))},children:[i.jsx("span",{className:"material-symbols-outlined",children:"save"}),c("flow:provideEdit.save")]}),i.jsxs("button",{type:"button",className:"af-provide-edit-modal__btn",onClick:()=>$(null),children:[i.jsx("span",{className:"material-symbols-outlined",children:"close"}),c("flow:provideEdit.cancel")]})]})]})}),document.body)]})}const zR={ai:["planner-system","planner-user","planner-response","agent-step-prompt","repair-prompt","ai-thinking","ai-assistant","ai-result","ai-tool"],flow:["composer-start","classify","plan","phase-plan","phase-complete","phase-auto-continue","composer-done"],step:["step-start","step-progress","step-done","validation"],output:["natural","status"],error:["error"]},$U={"planner-system":"#9ecaff","planner-user":"#9ecaff","planner-response":"#7c4dff","agent-step-prompt":"#7c4dff","repair-prompt":"#ff6b6b","ai-thinking":"#a8b9d4","ai-assistant":"#e8deff","ai-result":"#00e475","ai-tool":"#9ecaff","composer-start":"#00e475","composer-done":"#00e475","step-start":"#e8deff","step-done":"#e8deff","step-progress":"#e8deff",natural:"#a8a8a8",status:"#a8a8a8",error:"#ff6b6b","phase-plan":"#00e475","phase-complete":"#00e475"};function DU(e){return!e||e<1024?`${e||0} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/1024/1024).toFixed(2)} MB`}function FU(e){if(!e)return"";const t=new Date(e);return isNaN(t.getTime())?e:`${t.getHours().toString().padStart(2,"0")}:${t.getMinutes().toString().padStart(2,"0")}:${t.getSeconds().toString().padStart(2,"0")}.${t.getMilliseconds().toString().padStart(3,"0")}`}function zU(e){if(!e)return"";const t=new Date(e);return isNaN(t.getTime())?e:`${t.getMonth()+1}/${t.getDate()} ${t.getHours().toString().padStart(2,"0")}:${t.getMinutes().toString().padStart(2,"0")}`}function z1(e,t){if(e==="natural"&&t&&typeof t=="object"){const n=t.kind;if(n==="thinking"||n==="assistant"||n==="result"||n==="tool")return"ai";if(n==="error")return"error"}for(const[n,r]of Object.entries(zR))if(r.includes(e))return n;return"other"}function HU({event:e,defaultExpanded:t}){const[n,r]=h.useState(!!t),s=$U[e.tag]||"#a8a8a8",o=e.payload,a=o&&typeof o=="object",l=a?typeof o.text=="string"?o.text:"":String(o||""),c=a?o.meta:null,d=h.useMemo(()=>l?l.slice(0,140).replace(/\s+/g," "):a?Object.keys(o).filter(m=>m!=="text"&&m!=="meta").slice(0,3).map(m=>{const g=o[m];return g==null?`${m}:null`:typeof g=="object"?`${m}:{…}`:`${m}:${String(g).slice(0,30)}`}).join(" "):"",[o,l,a]),p=h.useCallback(u=>{u.stopPropagation();const f=a?JSON.stringify(o,null,2):String(o);try{navigator.clipboard.writeText(f)}catch{}},[o,a]);return i.jsxs("div",{style:{borderLeft:`3px solid ${s}`,background:n?"#1c1b1b":"#131313",marginBottom:4,borderRadius:4,cursor:"pointer",transition:"background 120ms"},onClick:()=>r(u=>!u),children:[i.jsxs("div",{style:{padding:"6px 10px",display:"flex",alignItems:"center",gap:10,fontSize:12},children:[i.jsx("span",{style:{color:"#9a9a9a",fontFamily:"monospace",flexShrink:0},children:FU(e.ts)}),i.jsx("span",{style:{color:s,fontWeight:600,fontFamily:"monospace",flexShrink:0,padding:"1px 6px",background:"rgba(255,255,255,0.04)",borderRadius:3},children:e.tag}),i.jsx("span",{style:{color:"#c5c2c1",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"monospace"},children:d}),n&&i.jsx("button",{type:"button",onClick:p,style:{background:"rgba(124,77,255,0.15)",color:"#e8deff",border:"none",borderRadius:3,padding:"2px 8px",fontSize:11,cursor:"pointer"},children:"Copy"})]}),n&&i.jsxs("div",{style:{padding:"0 10px 10px 10px",borderTop:"1px solid rgba(255,255,255,0.04)"},children:[c&&Object.keys(c).length>0&&i.jsx("div",{style:{marginTop:8,padding:8,background:"#0e0e0e",borderRadius:4,fontSize:11,fontFamily:"monospace",color:"#9ecaff",whiteSpace:"pre-wrap",wordBreak:"break-all"},children:JSON.stringify(c,null,2)}),l?i.jsx("pre",{style:{marginTop:8,padding:10,background:"#0e0e0e",borderRadius:4,fontSize:12,color:"#e5e2e1",whiteSpace:"pre-wrap",wordBreak:"break-word",maxHeight:600,overflowY:"auto",margin:"8px 0 0 0",fontFamily:"ui-monospace, SF Mono, Menlo, monospace"},children:l}):a?i.jsx("pre",{style:{marginTop:8,padding:10,background:"#0e0e0e",borderRadius:4,fontSize:12,color:"#e5e2e1",whiteSpace:"pre-wrap",wordBreak:"break-all",maxHeight:400,overflowY:"auto",margin:"8px 0 0 0",fontFamily:"ui-monospace, SF Mono, Menlo, monospace"},children:JSON.stringify(o,null,2)}):null]})]})}function BU({open:e,onClose:t,flowId:n}){var $;const[r,s]=h.useState([]),[o,a]=h.useState(!1),[l,c]=h.useState(null),[d,p]=h.useState(null),[u,f]=h.useState(!1),[m,g]=h.useState(!0),[w,k]=h.useState({ai:!0,flow:!0,step:!0,output:!0,error:!0}),[y,b]=h.useState(""),x=h.useRef(null),j=h.useCallback(async()=>{a(!0);try{const z=m&&n?`?flowId=${encodeURIComponent(n)}`:"",B=await(await fetch(`/api/composer-logs${z}`)).json();s(Array.isArray(B.sessions)?B.sessions:[])}catch{s([])}finally{a(!1)}},[n,m]),E=h.useCallback(async z=>{if(!z){p(null);return}f(!0);try{const B=await(await fetch(`/api/composer-logs/${encodeURIComponent(z)}`)).json();p(B)}catch{p(null)}finally{f(!1)}},[]);h.useEffect(()=>{e&&j()},[e,j]),h.useEffect(()=>{if(!(!e||!l))return E(l),x.current=setInterval(()=>E(l),2e3),()=>{x.current&&clearInterval(x.current),x.current=null}},[e,l,E]);const N=h.useMemo(()=>{const z=(d==null?void 0:d.events)||[],K=y.trim().toLowerCase();return z.filter(B=>{const L=z1(B.tag,B.payload);return!w[L]&&L!=="other"?!1:K?[B.tag,JSON.stringify(B.payload||"")].join(" ").toLowerCase().includes(K):!0})},[d,w,y]),T=h.useMemo(()=>{const z=(d==null?void 0:d.events)||[],K={};for(const B of z){const L=z1(B.tag,B.payload);K[L]=(K[L]||0)+1}return K},[d]);return e?i.jsxs("div",{style:{position:"fixed",top:0,right:0,bottom:0,width:"min(1100px, 80vw)",background:"#131313",borderLeft:"1px solid rgba(255,255,255,0.08)",display:"flex",flexDirection:"column",zIndex:9999,boxShadow:"-8px 0 32px rgba(0,0,0,0.5)",color:"#e5e2e1",fontFamily:"Inter, system-ui, sans-serif"},children:[i.jsxs("div",{style:{padding:"12px 16px",borderBottom:"1px solid rgba(255,255,255,0.06)",display:"flex",alignItems:"center",gap:12,flexShrink:0,background:"#1c1b1b"},children:[i.jsx("span",{style:{fontWeight:600,fontSize:14},children:"Composer Logs"}),i.jsx("span",{style:{fontSize:11,color:"#9a9a9a"},children:n?`flowId: ${n}`:"no flow selected"}),i.jsxs("label",{style:{fontSize:11,color:"#9a9a9a",display:"flex",alignItems:"center",gap:4,cursor:"pointer"},children:[i.jsx("input",{type:"checkbox",checked:m,onChange:z=>g(z.target.checked),disabled:!n}),"仅显示当前 flow"]}),i.jsx("button",{type:"button",onClick:j,style:{background:"rgba(124,77,255,0.15)",color:"#e8deff",border:"none",borderRadius:4,padding:"4px 10px",fontSize:12,cursor:"pointer"},children:"Refresh"}),i.jsx("span",{style:{flex:1}}),i.jsx("button",{type:"button",onClick:t,style:{background:"transparent",color:"#e5e2e1",border:"1px solid rgba(255,255,255,0.12)",borderRadius:4,padding:"4px 12px",fontSize:12,cursor:"pointer"},children:"Close"})]}),i.jsxs("div",{style:{flex:1,display:"flex",overflow:"hidden",minHeight:0},children:[i.jsxs("div",{style:{width:280,borderRight:"1px solid rgba(255,255,255,0.06)",overflowY:"auto",background:"#0e0e0e",flexShrink:0},children:[o&&i.jsx("div",{style:{padding:12,fontSize:12,color:"#9a9a9a"},children:"Loading…"}),!o&&r.length===0&&i.jsx("div",{style:{padding:12,fontSize:12,color:"#9a9a9a"},children:m&&n?"no sessions for this flow":"no sessions"}),r.map(z=>{const K=l===z.sessionId;return i.jsxs("div",{onClick:()=>c(z.sessionId),style:{padding:"10px 12px",borderBottom:"1px solid rgba(255,255,255,0.04)",cursor:"pointer",background:K?"rgba(124,77,255,0.18)":"transparent",borderLeft:K?"3px solid #7c4dff":"3px solid transparent"},children:[i.jsx("div",{style:{fontSize:12,fontWeight:600,color:"#e5e2e1"},children:zU(z.mtime)}),i.jsx("div",{style:{fontSize:11,color:"#9ecaff",marginTop:2,fontFamily:"monospace"},children:z.flowId||"(no flow)"}),z.promptPreview&&i.jsx("div",{style:{fontSize:11,color:"#9a9a9a",marginTop:4,overflow:"hidden",textOverflow:"ellipsis",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical"},children:z.promptPreview}),i.jsxs("div",{style:{fontSize:10,color:"#6a6a6a",marginTop:4},children:[DU(z.size)," · ",z.model||"default"]})]},z.sessionId)})]}),i.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",overflow:"hidden",minHeight:0},children:[i.jsxs("div",{style:{padding:"10px 16px",borderBottom:"1px solid rgba(255,255,255,0.06)",display:"flex",alignItems:"center",gap:8,flexWrap:"wrap",flexShrink:0,background:"#1c1b1b"},children:[Object.keys(zR).map(z=>i.jsxs("button",{type:"button",onClick:()=>k(K=>({...K,[z]:!K[z]})),style:{background:w[z]?"rgba(124,77,255,0.25)":"transparent",color:w[z]?"#e8deff":"#6a6a6a",border:`1px solid ${w[z]?"rgba(124,77,255,0.4)":"rgba(255,255,255,0.08)"}`,borderRadius:999,padding:"3px 12px",fontSize:11,cursor:"pointer",fontFamily:"monospace",textTransform:"uppercase"},children:[z," ",T[z]!=null?`(${T[z]})`:""]},z)),i.jsx("input",{type:"text",placeholder:"search…",value:y,onChange:z=>b(z.target.value),style:{marginLeft:8,flex:1,minWidth:120,background:"#0e0e0e",border:"1px solid rgba(255,255,255,0.08)",borderRadius:4,color:"#e5e2e1",padding:"4px 8px",fontSize:12}})]}),i.jsxs("div",{style:{flex:1,overflowY:"auto",padding:12,minHeight:0},children:[!l&&i.jsx("div",{style:{color:"#9a9a9a",fontSize:12,padding:20,textAlign:"center"},children:"Select a session on the left to view events"}),u&&!d&&i.jsx("div",{style:{color:"#9a9a9a",fontSize:12,padding:20},children:"Loading…"}),d&&N.length===0&&i.jsxs("div",{style:{color:"#9a9a9a",fontSize:12,padding:20},children:["No events match current filter (",(($=d.events)==null?void 0:$.length)||0," total)"]}),N.map((z,K)=>i.jsx(HU,{event:z,defaultExpanded:z.tag==="error"},`${z.ts}_${K}`))]})]})]})]}):null}const WU="0.1.83";function H1(e){const t=Math.max(0,Number(e)||0),n=Math.floor(t/36e5),r=Math.floor(t%36e5/6e4),s=Math.floor(t%6e4/1e3);return`${String(n).padStart(2,"0")}:${String(r).padStart(2,"0")}:${String(s).padStart(2,"0")}`}function xw(e,t){return t==="running"?H1(e):e==null||!Number.isFinite(e)||e<=0?"--":H1(e)}const HR=h.createContext({modelLists:{cursor:[],opencode:[]},onModelChange:()=>{}});function VU(e){var b,x,j,E,N,T,$,z,K,B,L;const{setNodes:t}=Hl(),n=J0(),{modelLists:r,onModelChange:s}=h.useContext(HR),o=h.useRef(null),a=!!((b=e.data)!=null&&b.readOnly),l=(x=e.data)!=null&&x.displaySize&&Number(e.data.displaySize.width)>0&&Number(e.data.displaySize.height)>0?{width:Number(e.data.displaySize.width),height:Number(e.data.displaySize.height)}:null,c=((j=e.data)==null?void 0:j.definitionId)==="agent_subAgent"&&!((E=e.data)!=null&&E.isRunMode)&&!a,d=h.useCallback(D=>{const R=()=>n(D);window.requestAnimationFrame(R),window.setTimeout(R,80)},[n]),p=h.useCallback((D,R)=>{const M=G1(R);M&&(t(I=>I.map(F=>{var _,Z,ee,V,ae,fe;if(F.id!==D)return F;const P=Number(((Z=(_=F.data)==null?void 0:_.displaySize)==null?void 0:Z.width)||F.width||((ee=F.measured)==null?void 0:ee.width)||0),O=Number(((ae=(V=F.data)==null?void 0:V.displaySize)==null?void 0:ae.height)||F.height||((fe=F.measured)==null?void 0:fe.height)||0);return Math.abs(P-M.width)<2&&Math.abs(O-M.height)<2?F:{...F,width:M.width,height:M.height,data:{...F.data,displaySize:M}}})),d(D))},[d,t]),u=h.useCallback(D=>{if(a)return;const R=o.current;if(!R)return;const M=R.getBoundingClientRect();p(D,{width:Math.max(M.width,R.scrollWidth),height:Math.max(M.height,R.scrollHeight)})},[p,a]),f=h.useCallback(D=>{var ae,fe,xe,Se,ue,Ee;if(!c)return;D.preventDefault(),D.stopPropagation();const R=o.current,M=R==null?void 0:R.getBoundingClientRect(),I=Number(((fe=(ae=e.data)==null?void 0:ae.displaySize)==null?void 0:fe.width)||e.width||((xe=e.measured)==null?void 0:xe.width)||(M==null?void 0:M.width)||KR),F=Number(((ue=(Se=e.data)==null?void 0:Se.displaySize)==null?void 0:ue.height)||e.height||((Ee=e.measured)==null?void 0:Ee.height)||(M==null?void 0:M.height)||vv),P=D.clientX,O=D.clientY,_=e.id;let Z=0;const ee=le=>{const me=G1({width:I+le.clientX-P,height:F+le.clientY-O});me&&(window.cancelAnimationFrame(Z),Z=window.requestAnimationFrame(()=>p(_,me)))},V=()=>{window.cancelAnimationFrame(Z),window.removeEventListener("pointermove",ee),window.removeEventListener("pointerup",V),window.removeEventListener("pointercancel",V),d(_)};window.addEventListener("pointermove",ee),window.addEventListener("pointerup",V,{once:!0}),window.addEventListener("pointercancel",V,{once:!0})},[p,(T=(N=e.data)==null?void 0:N.displaySize)==null?void 0:T.height,(z=($=e.data)==null?void 0:$.displaySize)==null?void 0:z.width,e.height,e.id,(K=e.measured)==null?void 0:K.height,(B=e.measured)==null?void 0:B.width,e.width,d,c]),m=h.useCallback(D=>{t(R=>R.filter(M=>M.id!==D))},[t]),g=h.useCallback(()=>{var I,F,P,O,_,Z,ee,V;const D=((I=e.data)==null?void 0:I.definitionId)||"",R=((F=e.data)==null?void 0:F.label)||e.id,M=((_=(O=(P=e.data)==null?void 0:P.outputs)==null?void 0:O[0])==null?void 0:_.value)||((V=(ee=(Z=e.data)==null?void 0:Z.outputs)==null?void 0:ee[0])==null?void 0:V.default)||"";window.__provideEditContent={instanceId:e.id,label:R,definitionId:D,content:M},window.dispatchEvent(new CustomEvent("provide-expand"))},[e.id,e.data]),w=h.useCallback((D,R)=>{t(M=>M.map(I=>{var P;if(I.id!==D)return I;const F=Array.isArray((P=I.data)==null?void 0:P.outputs)&&I.data.outputs.length?I.data.outputs.map((O,_)=>_===0?{...O,default:R,value:R}:O):[{type:"bool",name:"value",default:R,value:R}];return{...I,data:{...I.data,body:"",outputs:F}}}))},[t]),k=h.useCallback((D,R)=>{t(M=>M.map(I=>I.id===D?{...I,data:{...I.data,body:R}}:I))},[t]),y=h.useCallback((D,R)=>{t(M=>M.map(I=>I.id===D?{...I,data:{...I.data,images:Vs(R)}}:I))},[t]);return i.jsxs("div",{ref:o,className:"af-flow-node-shell"+(c?" af-flow-node-shell--resizable":""),style:l?{width:l.width,height:l.height}:void 0,children:[i.jsx(ER,{...e,data:{...e.data,onNodeContentResize:u},deleteNode:m,onProvideExpand:g,onProvideValueChange:w,onNodeBodyChange:k,onNodeImagesChange:y,modelLists:r,onModelChange:s}),c?i.jsx("span",{className:"af-flow-node-shell__resize-grip nodrag","aria-label":((L=e.data)==null?void 0:L.resizeLabel)||"Resize node",role:"separator",onPointerDown:f}):null]})}const KU={[$c]:VU},Lf=["CONTROL","TOOL","PROVIDE","AGENT"],UU=1200,B1="af-flow-node--sync-flash",W1="af-flow-edge--sync-flash";function V1(e,t){const n=String(e||"").trim();return n?n.split(/\s+/).includes(t)?n:`${n} ${t}`:t}function K1(e,t){const n=String(e||"").trim();return n?n.split(/\s+/).filter(r=>r&&r!==t).join(" "):""}function kk(e){const t=((e==null?void 0:e.id)??"").trim();return/^control/i.test(t)?"CONTROL":/^tool/i.test(t)?"TOOL":/^provide/i.test(t)?"PROVIDE":"AGENT"}function qU(e){const t=kk(e);return t==="CONTROL"?"control":t==="PROVIDE"?"provide":t==="TOOL"?"tool":"agent"}function ym(e){return(Array.isArray(e)?e:[]).map(n=>{const r=String((n==null?void 0:n.name)||(n==null?void 0:n.id)||"").trim(),s=String((n==null?void 0:n.type)||"").trim();return!r&&!s?"":s?`${r||"-"}: ${s}`:r}).filter(Boolean)}function BR(e){return String((e==null?void 0:e.label)||"").trim()||String((e==null?void 0:e.id)||"").trim()}function WR(e){return String((e==null?void 0:e.description)||(e==null?void 0:e.body)||"").replace(/\s+/g," ").trim()}function ww(e,t){const n=String((e==null?void 0:e.name)||(e==null?void 0:e.id)||"").trim(),r=String((e==null?void 0:e.type)||"").trim();return n||r||`#${t+1}`}function U1(e,t,n){const r=String((t==null?void 0:t.name)||(t==null?void 0:t.id)||`#${n+1}`).trim(),s=String((t==null?void 0:t.type)||"").trim(),o=String((t==null?void 0:t.default)??(t==null?void 0:t.value)??"").trim();return[e,r,s?`type: ${s}`:"",o?`default: ${o}`:""].filter(Boolean).join(" · ")}function q1(e,t){const n=Array.isArray(e)?e:[],r=n.slice(0,4),s=Math.max(0,n.length-r.length);return{list:n,shown:r,hidden:s,kind:t}}function YU(e){return e==="CONTROL"?"account_tree":e==="TOOL"?"build":e==="PROVIDE"?"database":"smart_toy"}function GU(e,t){return t?[e==null?void 0:e.id,e==null?void 0:e.label,e==null?void 0:e.description].filter(Boolean).some(r=>String(r).toLowerCase().includes(t)):!0}function VR(e,t,n,r,s){const o=qU(e),a={id:t,type:$c,position:n,data:{label:e.label??e.id,definitionId:e.id,schemaType:o,inputs:Array.isArray(e.inputs)?e.inputs.map(l=>({...l})):[],outputs:Array.isArray(e.outputs)?e.outputs.map(l=>({...l})):[]}};return zp(a,r,s)}const KR=320,XU=220,JU=1600,vv=104,QU=900;function Y1(e,t,n){const r=Number(e);return!Number.isFinite(r)||r<=0?0:Math.min(n,Math.max(t,Math.round(r)))}function G1(e){if(!e||typeof e!="object")return null;const t=Number(e.width),n=Number(e.height);return!Number.isFinite(t)||!Number.isFinite(n)||t<=0||n<=0?null:{width:Y1(t,XU,JU)||KR,height:Y1(n,vv,QU)||vv}}function ZU(e){const t=(e==null?void 0:e.data)||{},n=r=>(Array.isArray(r)?r:[]).map((s,o)=>(s==null?void 0:s.showOnNode)===!1?"":[o,String((s==null?void 0:s.type)||""),String((s==null?void 0:s.name)||""),s!=null&&s.required?"1":"0"].join(":")).filter(Boolean).join("|");return`${n(t.inputs)}=>${n(t.outputs)}`}function X1(e,t){const n=String((e==null?void 0:e.source)||""),r=String((e==null?void 0:e.target)||"");if(!n||!r)return!1;const s=new Map(t.map(d=>[d.id,d])),o=s.get(n),a=s.get(r),l=jd(o,e.sourceHandle||"output-0","source"),c=jd(a,e.targetHandle||"input-0","target");return!l||!c?!1:Ml(l,c)}function eq(e,t){const n=String((e==null?void 0:e.nodeId)||""),r=String((e==null?void 0:e.handleId)||""),s=(e==null?void 0:e.handleType)==="target"?"target":(e==null?void 0:e.handleType)==="source"?"source":"";if(!n||!r||!s)return null;const o=t.find(l=>l.id===n),a=jd(o,r,s);return a?{nodeId:n,handleId:r,handleType:s,slot:a,slotType:CR(a)}:null}function tq(e,t,n){var a;const r=VR(e,`__candidate_${e.id}`,{x:0,y:0},{},t),s=n.handleType==="source"?"inputs":"outputs",o=Array.isArray((a=r.data)==null?void 0:a[s])?r.data[s]:[];for(let l=0;l<o.length;l+=1){const c=o[l];if(n.handleType==="source"?Ml(n.slot,c):Ml(c,n.slot))return{slot:c,slotIndex:l,hydrated:r}}return null}function nq(e,t){return t?e.map((n,r)=>{const s=tq(n,e,t);if(!s)return null;const o=kk(n);return{def:n,order:r,category:o,categoryRank:Lf.indexOf(o),slot:s.slot,slotIndex:s.slotIndex,displayLabel:BR(s.hydrated.data||n),description:WR(n)}}).filter(Boolean).sort((n,r)=>{var a,l;const s=(a=n.slot)!=null&&a.required?0:1,o=(l=r.slot)!=null&&l.required?0:1;return s-o||n.slotIndex-r.slotIndex||n.categoryRank-r.categoryRank||n.order-r.order}):[]}const rq=/@([a-zA-Z_][a-zA-Z0-9_]*)/g;function sq(e){const t=new Set,n=[];let r;const s=new RegExp(rq.source,"g");for(;(r=s.exec(e))!==null;){const o=r[1];t.has(o)||(t.add(o),n.push(o))}return n}function J1(e,t){const n=e.slice(0,t),r=n.lastIndexOf("@");if(r<0)return null;const s=n.slice(r+1);return/[\s\n]/.test(s)?null:{atIndex:r,query:s}}function ga(e){const t=String(e||"").indexOf(" - ");return t>=0?e.slice(0,t).trim():String(e||"").trim()}function xm(e,t,n,r){const s=(e||"").trim();if(!s)return"";if(s.startsWith("opencode:")||s.startsWith("claude-code:"))return s;const o=Array.isArray(t)?t:[],a=Array.isArray(n)?n:[],l=Array.isArray(r)?r:[],c=o.map(ga),d=a.map(ga);return l.map(ga).includes(s)&&!c.includes(s)&&!d.includes(s)?`claude-code:${s}`:d.includes(s)&&!c.includes(s)?`opencode:${s}`:s}function iq(e){if(e==null)return"";const t=String(e).trim();return t?t.length<=26?t:`${t.slice(0,12)}…${t.slice(-10)}`:""}function bw(e){if(!Array.isArray(e)||e.length===0)return 0;let t=0;for(const n of e){const r=/^(?:对话|Conversation|Chat)\s*(\d+)\s*$/.exec(String((n==null?void 0:n.label)??"").trim());r&&(t=Math.max(t,parseInt(r[1],10)))}return t}function oq({steps:e}){const{t}=zn();return!e||e.length===0?null:i.jsx("div",{className:"af-composer-steps-track",role:"list","aria-label":t("flow:composer.stepsAriaLabel"),children:e.map(n=>{const r=String(n.description||n.type||"").trim(),s=n.model||n.executorModel,o=[`${n.index+1}. ${r||"—"}`,n.nodeRole?t("flow:composer.stepRoleLabel",{role:n.nodeRole}):"",n.instanceId?t("flow:composer.stepInstanceLabel",{instanceId:n.instanceId}):"",s?`${t("flow:palette.model")}:${s}`:""].filter(Boolean).join(`
128
+ `}}),i.jsx("textarea",{ref:f,className:"af-body-prompt-textarea "+o,rows:s,value:e,disabled:n,placeholder:r,spellCheck:!1,"aria-invalid":N,"aria-describedby":N?u:void 0,onChange:I=>{t(I.target.value),w(I.target.selectionStart??I.target.value.length)},onSelect:I=>{const F=I.target;F instanceof HTMLTextAreaElement&&w(F.selectionStart??0)},onClick:I=>{const F=I.target;F instanceof HTMLTextAreaElement&&w(F.selectionStart??0)},onKeyUp:I=>{const F=I.target;F instanceof HTMLTextAreaElement&&w(F.selectionStart??F.value.length)},onKeyDown:R,onPaste:I=>{const F=bR(I);F.length!==0&&(I.preventDefault(),M(F).catch(()=>{}))},onDragOver:I=>{np(I).length>0&&I.preventDefault()},onDrop:I=>{const F=np(I);F.length!==0&&(I.preventDefault(),M(F).catch(()=>{}))},onScroll:D})]}),z&&K.length>0&&b?Ir.createPortal(i.jsx("ul",{className:"af-body-ph-menu af-body-ph-menu--pop af-composer-mention-menu",role:"listbox","aria-label":p("flow:nodeProps.placeholderSlots"),style:{position:"fixed",top:b.top,left:b.left,right:"auto",bottom:"auto",margin:0,zIndex:2e4},children:K.map((I,F)=>i.jsx("li",{role:"option","aria-selected":F===k,children:i.jsxs("button",{type:"button",className:"af-composer-mention-item"+(F===k?" af-composer-mention-item--active":""),onMouseDown:P=>P.preventDefault(),onMouseEnter:()=>y(F),onClick:()=>L(I.insert),children:[i.jsx("span",{className:"af-composer-mention-id",children:`\${${I.insert}}`}),I.subtitle?i.jsx("span",{className:"af-composer-mention-sub",children:I.subtitle}):null]})},`${I.section}-${I.insert}`))}),document.body):null,N?i.jsx("p",{id:u,className:"af-body-ph-issues",role:"status",children:E.map(I=>I.message).join(" · ")}):null]})}const OR=/^[a-zA-Z_][a-zA-Z0-9_-]*$/;function gm(e){const t=e.indexOf(" - ");return t>=0?e.slice(0,t).trim():e.trim()}function T1({kind:e,label:t,slots:n,onSlotsChange:r,disabled:s,requiredReadonly:o=!0}){const{t:a}=zn(),l=()=>r([...n,{type:"text",name:"",default:"",required:!1,showOnNode:!1}]),c=u=>r(n.filter((f,m)=>m!==u)),d=(u,f,m)=>{const g=n.map((w,k)=>{if(k!==u)return w;const y={...w,[f]:m};return f==="required"&&m===!0&&(y.showOnNode=!0),y});r(g)},p=e==="input"?"input":"output";return i.jsxs("div",{className:"af-node-props-field af-node-props-field--io",children:[i.jsxs("div",{className:"af-node-props-io-head",children:[i.jsx("span",{className:"af-node-props-label",children:t}),i.jsx("button",{type:"button",className:"af-btn-ghost af-node-props-io-add",onClick:l,disabled:s,"aria-label":a("flow:nodeProps.addPinAriaLabel",{label:t}),children:a("flow:nodeProps.addPin")})]}),i.jsx("p",{className:"af-node-props-io-hint",children:a("flow:nodeProps.handleHint",{prefix:p})}),n.length===0?i.jsx("p",{className:"af-node-props-io-empty",children:a(e==="input"?"flow:nodeProps.noInputPins":"flow:nodeProps.noOutputPins")}):null,n.length>0?i.jsxs("div",{className:"af-node-props-io-table",role:"group","aria-label":t,children:[i.jsxs("div",{className:"af-node-props-io-table-head","aria-hidden":!0,children:[i.jsx("span",{children:a("flow:nodeProps.handle")}),i.jsx("span",{children:a("flow:nodeProps.type")}),i.jsx("span",{children:a("flow:nodeProps.name")}),i.jsx("span",{children:a("flow:nodeProps.defaultValue")}),i.jsx("span",{children:a("flow:nodeProps.description")}),i.jsx("span",{children:a("flow:nodeProps.required")}),i.jsx("span",{children:a("flow:nodeProps.showOnNode")}),i.jsx("span",{})]}),n.map((u,f)=>i.jsxs("div",{className:"af-node-props-io-row",children:[i.jsxs("span",{className:"af-node-props-io-handle",title:`${p}-${f}`,children:[p,"-",f]}),i.jsx("select",{className:"af-node-props-input af-node-props-io-cell",value:u.type,onChange:m=>d(f,"type",m.target.value),disabled:s,"aria-label":a("flow:nodeProps.pinTypeAriaLabel",{label:t,index:f}),children:["node","text","file","bool"].map(m=>i.jsx("option",{value:m,children:m},m))}),i.jsx("input",{type:"text",className:"af-node-props-input af-node-props-io-cell",value:u.name,onChange:m=>d(f,"name",m.target.value),disabled:s,spellCheck:!1,autoComplete:"off","aria-label":a("flow:nodeProps.pinNameAriaLabel",{label:t,index:f})}),i.jsx("input",{type:"text",className:"af-node-props-input af-node-props-io-cell",value:u.default,onChange:m=>d(f,"default",m.target.value),disabled:s,spellCheck:!1,autoComplete:"off","aria-label":a("flow:nodeProps.pinDefaultAriaLabel",{label:t,index:f})}),i.jsx("input",{type:"text",className:"af-node-props-input af-node-props-io-cell",value:u.description||"",onChange:m=>d(f,"description",m.target.value),disabled:s,spellCheck:!1,autoComplete:"off","aria-label":a("flow:nodeProps.pinDescriptionAriaLabel",{label:t,index:f})}),i.jsx("label",{className:"af-node-props-io-flag",title:a("flow:nodeProps.requiredHint"),children:i.jsx("input",{type:"checkbox",checked:!!u.required,onChange:m=>{o||d(f,"required",m.target.checked)},disabled:s||o,"aria-label":a("flow:nodeProps.pinRequiredAriaLabel",{label:t,index:f})})}),i.jsx("label",{className:"af-node-props-io-flag",title:a("flow:nodeProps.showOnNodeHint"),children:i.jsx("input",{type:"checkbox",checked:u.showOnNode!==!1,onChange:m=>d(f,"showOnNode",m.target.checked),disabled:s,"aria-label":a("flow:nodeProps.pinShowOnNodeAriaLabel",{label:t,index:f})})}),i.jsx("button",{type:"button",className:"af-icon-btn af-node-props-io-remove",onClick:()=>c(f),disabled:s,"aria-label":a("flow:nodeProps.deletePinAriaLabel",{label:t,index:f}),title:a("flow:nodeProps.deletePin"),children:i.jsx("span",{className:"material-symbols-outlined",children:"delete"})})]},`${p}-${f}`))]}):null]})}function $R({draft:e,setDraft:t,definitionId:n,systemPromptReadonly:r,modelLists:s,disabled:o,onIdBlur:a,onClose:l,onPublishToMarketplace:c,allowEditRequiredPins:d=!1,error:p,ioSlots:u}){const{t:f}=zn(),[m,g]=h.useState(!1),[w,k]=h.useState(!1),[y,b]=h.useState({status:"idle",message:""}),x=h.useCallback(L=>{t(D=>D&&{...D,...L})},[t]),{cursorList:j,opencodeList:E,claudeCodeList:N,currentNotInLists:T}=h.useMemo(()=>{const L=Array.isArray(s==null?void 0:s.cursor)?s.cursor:[],D=Array.isArray(s==null?void 0:s.opencode)?s.opencode:[],R=Array.isArray(s==null?void 0:s.claudeCode)?s.claudeCode:[],M=new Set([...L,...D,...R].map(gm)),I=((e==null?void 0:e.model)??"").trim(),F=I.startsWith("cursor:")?I.slice(7):I.startsWith("opencode:")?I.slice(9):I.startsWith("claude-code:")?I.slice(12):I,P=I&&!M.has(F)?I:"";return{cursorList:L,opencodeList:D,claudeCodeList:R,currentNotInLists:P}},[s,e==null?void 0:e.model]);if(!e)return null;const $=String(e.script??""),z=n==="tool_nodejs"||$.trim()!=="",K=typeof c=="function"&&!o&&(e==null?void 0:e.newId),B=async()=>{if(K){b({status:"running",message:f("flow:nodeProps.publishRunning")});try{const L=await c(e,n);b({status:"success",message:L!=null&&L.definitionId?f("flow:nodeProps.publishSuccessWithId",{id:L.definitionId}):f("flow:nodeProps.publishSuccess")})}catch(L){b({status:"error",message:String((L==null?void 0:L.message)||L)})}}};return i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"af-pipeline-drawer-head af-node-props-head",children:[i.jsx("h2",{className:"af-pipeline-drawer-title",children:f("flow:nodeProps.title")}),i.jsxs("div",{className:"af-node-props-head-actions",children:[i.jsxs("button",{type:"button",className:"af-btn-ghost af-node-props-market-btn",onClick:B,disabled:!K||y.status==="running",title:f("flow:nodeProps.publishToMarketplaceHint"),children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"inventory_2"}),y.status==="running"?f("flow:nodeProps.publishing"):f("flow:nodeProps.publishToMarketplace")]}),i.jsx("button",{type:"button",className:"af-btn-ghost af-node-props-close-secondary",onClick:l,children:f("common:common.close")})]})]}),i.jsxs("div",{className:"af-pipeline-drawer-body af-node-props-body",children:[p?i.jsx("p",{className:"af-err af-node-props-err",children:p}):null,y.message?i.jsx("p",{className:`af-node-props-market-status af-node-props-market-status--${y.status}`,children:y.message}):null,i.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[i.jsx("span",{className:"af-node-props-label",children:f("flow:node.nodeType")}),i.jsx("div",{className:"af-pipeline-drawer-readonly af-node-props-readonly-mono",children:n})]}),i.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[i.jsxs("span",{className:"af-node-props-label",children:[f("flow:nodeProps.instanceId"),i.jsx("span",{className:"af-node-props-hint",children:f("flow:node.displayNameHint")})]}),i.jsx("input",{type:"text",className:"af-node-props-input",value:e.newId,onChange:L=>x({newId:L.target.value}),onBlur:a,disabled:o,spellCheck:!1,autoComplete:"off","aria-label":f("flow:nodeProps.instanceId")})]}),i.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[i.jsxs("span",{className:"af-node-props-label",children:[f("flow:node.displayName"),"(LABEL)"]}),i.jsx("input",{type:"text",className:"af-node-props-input",value:e.label,onChange:L=>x({label:L.target.value}),disabled:o,spellCheck:!1})]}),i.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[i.jsxs("span",{className:"af-node-props-label",children:[f("flow:node.role"),"(ROLE)"]}),i.jsx("select",{className:"af-node-props-select",value:Rl.includes(e.role)?e.role:f("flow:roles.normal"),onChange:L=>x({role:L.target.value}),disabled:o,children:Rl.map(L=>i.jsx("option",{value:L,children:L},L))})]}),i.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[i.jsxs("span",{className:"af-node-props-label",children:[f("flow:node.model"),"(MODEL)"]}),i.jsx("span",{className:"af-node-props-sublabel",children:f("flow:node.modelHint")}),i.jsxs("select",{className:"af-node-props-select",value:(()=>{const L=(e.model||"").trim();return L?T||L:""})(),onChange:L=>x({model:L.target.value}),disabled:o,"aria-label":f("flow:nodeProps.modelAriaLabel"),children:[i.jsx("option",{value:"",children:f("flow:node.defaultModel")}),T?i.jsxs("option",{value:T,children:[T,f("flow:nodeProps.yamlValueNotInList")]}):null,j.length>0?i.jsx("optgroup",{label:"Cursor",children:j.map(L=>i.jsx("option",{value:gm(L),children:L},`c-${L}`))}):null,E.length>0?i.jsx("optgroup",{label:"OpenCode",children:E.map(L=>i.jsx("option",{value:gm(L),children:L},`o-${L}`))}):null,N.length>0?i.jsx("optgroup",{label:"Claude Code",children:N.map(L=>i.jsx("option",{value:`claude-code:${gm(L)}`,children:L},`cc-${L}`))}):null]})]}),i.jsx(T1,{kind:"input",label:f("flow:nodeProps.inputPins"),slots:Array.isArray(e.inputs)?e.inputs:[],onSlotsChange:L=>x({inputs:L}),disabled:o,requiredReadonly:!d}),i.jsx(T1,{kind:"output",label:f("flow:nodeProps.outputPins"),slots:Array.isArray(e.outputs)?e.outputs:[],onSlotsChange:L=>x({outputs:L}),disabled:o,requiredReadonly:!d}),z?i.jsxs("div",{className:"af-pipeline-drawer-field af-node-props-field af-node-props-field--prompt",children:[i.jsxs("div",{className:"af-node-props-prompt-head",children:[i.jsxs("span",{className:"af-node-props-label",children:[f("flow:node.directCommand"),"(script)",i.jsx("span",{className:"af-node-props-hint",children:f("flow:node.scriptHint")})]}),i.jsx("button",{type:"button",className:"af-icon-btn af-node-props-expand",onClick:()=>k(!0),"aria-label":f("flow:nodeProps.expandEditScript"),title:f("flow:nodeProps.expand"),disabled:o,children:i.jsx("span",{className:"material-symbols-outlined",children:"open_in_full"})})]}),i.jsx(mm,{value:$,onChange:L=>x({script:L}),disabled:o,placeholder:f("flow:nodeProps.scriptPlaceholder"),rows:6,textareaClassName:"af-pipeline-drawer-textarea af-node-props-body-textarea af-node-props-script-textarea",ioSlots:u,variant:"drawer"})]}):null,i.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[i.jsx("span",{className:"af-node-props-label",children:"Script file(scriptRef)"}),i.jsxs("span",{className:"af-node-props-sublabel",children:["Relative path under this flow, for example nodes/",e.id,"/script.mjs"]}),i.jsx("input",{type:"text",className:"af-node-props-input",value:e.scriptRef||"",onChange:L=>x({scriptRef:L.target.value}),disabled:o,spellCheck:!1,autoComplete:"off"})]}),i.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[i.jsx("span",{className:"af-node-props-label",children:"Implementation file(implementationRef)"}),i.jsxs("span",{className:"af-node-props-sublabel",children:["Relative path under this flow, for example nodes/",e.id,"/implementation.md"]}),i.jsx("input",{type:"text",className:"af-node-props-input",value:e.implementationRef||"",onChange:L=>x({implementationRef:L.target.value}),disabled:o,spellCheck:!1,autoComplete:"off"})]}),i.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[i.jsx("span",{className:"af-node-props-label",children:"Implementation mode"}),i.jsxs("select",{className:"af-node-props-select",value:e.implementationMode||"",onChange:L=>x({implementationMode:L.target.value}),disabled:o,children:[i.jsx("option",{value:"",children:"auto"}),i.jsx("option",{value:"script",children:"script"}),i.jsx("option",{value:"steps",children:"steps"}),i.jsx("option",{value:"hybrid",children:"hybrid"})]})]}),i.jsxs("div",{className:"af-pipeline-drawer-field af-node-props-field af-node-props-field--prompt",children:[i.jsxs("div",{className:"af-node-props-prompt-head",children:[i.jsx("span",{className:"af-node-props-label",children:f("flow:node.userPrompt")}),i.jsx("button",{type:"button",className:"af-icon-btn af-node-props-expand",onClick:()=>g(!0),"aria-label":f("flow:nodeProps.expandEdit"),title:f("flow:nodeProps.expand"),disabled:o,children:i.jsx("span",{className:"material-symbols-outlined",children:"open_in_full"})})]}),i.jsx(mm,{value:e.body,onChange:L=>x({body:L}),images:e.images,onImagesChange:L=>x({images:L}),disabled:o,placeholder:f("flow:nodeProps.bodyPlaceholder"),rows:8,textareaClassName:"af-pipeline-drawer-textarea af-node-props-body-textarea",ioSlots:u,variant:"drawer"})]}),i.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[i.jsx("span",{className:"af-node-props-label",children:f("flow:node.systemDescription")}),i.jsx("textarea",{className:"af-pipeline-drawer-textarea af-node-props-system-readonly",rows:4,readOnly:!0,value:r||f("flow:nodeProps.noDescription"),spellCheck:!1})]})]}),w?i.jsx("div",{className:"af-node-props-expand-overlay",role:"dialog","aria-modal":"true","aria-label":f("flow:nodeProps.editScript"),onMouseDown:L=>{L.target===L.currentTarget&&k(!1)},children:i.jsxs("div",{className:"af-node-props-expand-panel",children:[i.jsxs("div",{className:"af-node-props-expand-head",children:[i.jsx("span",{className:"af-node-props-expand-title",children:f("flow:node.directCommand")}),i.jsx("button",{type:"button",className:"af-icon-btn",onClick:()=>k(!1),"aria-label":f("flow:nodeProps.collapse"),children:i.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),i.jsx(mm,{value:$,onChange:L=>x({script:L}),disabled:o,placeholder:f("flow:nodeProps.scriptPlaceholderExpand"),rows:16,textareaClassName:"af-node-props-expand-textarea",ioSlots:u,variant:"expand"})]})}):null,m?i.jsx("div",{className:"af-node-props-expand-overlay",role:"dialog","aria-modal":"true","aria-label":f("flow:nodeProps.editUserPrompt"),onMouseDown:L=>{L.target===L.currentTarget&&g(!1)},children:i.jsxs("div",{className:"af-node-props-expand-panel",children:[i.jsxs("div",{className:"af-node-props-expand-head",children:[i.jsx("span",{className:"af-node-props-expand-title",children:f("flow:node.body")}),i.jsx("button",{type:"button",className:"af-icon-btn",onClick:()=>g(!1),"aria-label":f("flow:nodeProps.collapse"),children:i.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),i.jsx(mm,{value:e.body,onChange:L=>x({body:L}),images:e.images,onImagesChange:L=>x({images:L}),disabled:o,placeholder:f("flow:nodeProps.bodyPlaceholderExpand"),rows:16,textareaClassName:"af-node-props-expand-textarea",ioSlots:u,variant:"expand"})]})}):null]})}function vk(e){var n;if(e.displayKind==="image"||e.encoding==="base64"&&((n=e.mimeType)!=null&&n.startsWith("image/")))return"image";if(e.displayKind==="json"||e.mimeType==="application/json")return"json";if(e.displayKind==="markdown"||e.mimeType==="text/markdown")return"markdown";if(e.displayKind==="text")return"text";const t=(e.content||"").trim();if(t&&(t.startsWith("{")||t.startsWith("[")))try{return JSON.parse(t),"json"}catch{}return"text"}function AU(e){const t=vk(e);if(t==="image"){const n=(e.mimeType||"image/png").split("/")[1];return n?n.toUpperCase():"IMAGE"}return t==="json"?"JSON":t==="markdown"?"MD":null}function DR(e){try{return JSON.stringify(JSON.parse(e.trim()),null,2)}catch{return e}}function R1({text:e}){const{t}=zn(),n=e||"";return n.trim()?i.jsx("div",{className:"af-run-ctx-md",children:i.jsx(ah,{children:n})}):i.jsx("div",{className:"af-run-ctx-hint",children:t("flow:runContext.empty")})}function M1({o:e}){var r;const{t}=zn(),n=vk(e);if(n==="image"||e.encoding==="base64"&&((r=e.mimeType)!=null&&r.startsWith("image/"))){const o=`data:${e.mimeType||"image/png"};base64,${e.content||""}`;return i.jsxs("div",{className:"af-run-ctx-media",children:[i.jsx("img",{className:"af-run-ctx-img",src:o,alt:e.slot||"output",loading:"lazy"}),e.truncated?i.jsx("div",{className:"af-run-ctx-hint",children:t("flow:runContext.imageTruncated")}):null]})}if(n==="json")return i.jsx("pre",{className:"af-run-ctx-pre",children:DR(e.content||"")});if(n==="markdown"){const s=e.content||"";return s.trim()?i.jsx("div",{className:"af-run-ctx-md",children:i.jsx(ah,{children:s})}):i.jsx("div",{className:"af-run-ctx-hint",children:t("flow:runContext.empty")})}return i.jsx("pre",{className:"af-run-ctx-pre",children:e.content!=null&&e.content!==""?e.content:t("flow:runContext.empty")})}function L1(e){return AU(e)}function O1(e){var r;if(!e)return null;const t=vk(e);if(t==="image"||e.encoding==="base64"&&((r=e.mimeType)!=null&&r.startsWith("image/")))return null;const n=e.content;return n==null||n===""?null:t==="json"?DR(String(n)):String(n)}function $1({text:e,title:t,copiedLabel:n}){const[r,s]=h.useState(!1);if(!e)return null;const o=async()=>{try{await navigator.clipboard.writeText(e),s(!0),window.setTimeout(()=>s(!1),1400)}catch{}};return i.jsx("button",{type:"button",className:"af-icon-btn af-run-ctx-copy-btn",onClick:o,title:r?n:t,"aria-label":r?n:t,children:i.jsx("span",{className:"material-symbols-outlined",children:r?"check":"content_copy"})})}const D1=2e4,FR="af:run-node-ctx-width";function Jm(){return typeof window>"u"?416:Math.min(26*16,window.innerWidth-32)}function hl(e){const n=Math.max(280,Math.min(Math.floor(window.innerWidth*.92),1200));return Number.isFinite(e)?Math.min(Math.max(Math.round(e),200),n):hl(Jm())}function PU(){try{const e=localStorage.getItem(FR);if(e==null)return hl(Jm());const t=parseInt(e,10);return Number.isFinite(t)?hl(t):hl(Jm())}catch{return hl(Jm())}}async function F1(e,t,n,r){const s=new URLSearchParams({flowId:e,instanceId:t});n&&String(n).trim()&&s.set("runId",String(n).trim());const o=await fetch(`/api/node-exec-context?${s.toString()}`,{signal:r}),a=await o.text();let l;try{l=JSON.parse(a)}catch{throw new Error(a.startsWith("<!")||a.startsWith("<html")?"apiConnectError":"invalidJson")}if(!o.ok)throw new Error(l.error||"HTTP "+o.status);return l}function IU(e,t){const n=`flow:runContext.${t}`,r=e(n);return r!==n?r:t}function TU({instanceId:e,flowId:t,runId:n,nodeStatus:r,onClose:s}){const{t:o}=zn(),[a,l]=h.useState(()=>typeof window<"u"&&window.matchMedia("(max-width: 960px)").matches),[c,d]=h.useState(PU),p=h.useRef({active:!1,pointerId:-1,startX:0,startW:416}),[u,f]=h.useState(!0),[m,g]=h.useState(""),[w,k]=h.useState([]),[y,b]=h.useState(null),[x,j]=h.useState(null),E=h.useRef(null),N=h.useRef(null),T=h.useRef(0),$=h.useRef(0);h.useLayoutEffect(()=>{const P=window.matchMedia("(max-width: 960px)"),O=()=>l(P.matches);return P.addEventListener("change",O),()=>P.removeEventListener("change",O)},[]),h.useEffect(()=>{function P(){d(O=>hl(O))}return window.addEventListener("resize",P),()=>window.removeEventListener("resize",P)},[]);const z=h.useCallback(()=>{d(P=>{const O=hl(P);try{localStorage.setItem(FR,String(O))}catch{}return O})},[]),K=h.useCallback(P=>{if(a||P.button!==0)return;P.preventDefault();const O=P.currentTarget;p.current={active:!0,pointerId:P.pointerId,startX:P.clientX,startW:c},O.setPointerCapture(P.pointerId)},[a,c]),B=h.useCallback(P=>{const O=p.current;if(!O.active||P.pointerId!==O.pointerId)return;const _=O.startX-P.clientX;d(hl(O.startW+_))},[]),L=h.useCallback(P=>{const O=p.current;if(!(!O.active||P.pointerId!==O.pointerId)){O.active=!1;try{P.currentTarget.releasePointerCapture(P.pointerId)}catch{}z()}},[z]),D=h.useCallback(()=>{const P=p.current;P.active&&(P.active=!1,z())},[z]),R=h.useCallback(P=>{const O=Array.isArray(P)?P:[];k(O),b(_=>_&&O.some(Z=>Z.execId===_)?_:O.length>0?O[O.length-1].execId:null)},[]),M=h.useCallback(()=>{if(!e||!t)return;const P=++T.current,O=new AbortController,_=window.setTimeout(()=>O.abort(),D1);(async()=>{try{const Z=await F1(t,e,n,O.signal);if(P!==T.current)return;R(Array.isArray(Z.rounds)?Z.rounds:[])}catch{}finally{window.clearTimeout(_)}})()},[e,t,n,R]);h.useEffect(()=>{if(!e||!t){f(!1),g(""),k([]);return}const P=++$.current;f(!0),g(""),k([]),b(null);const O=new AbortController,_=window.setTimeout(()=>O.abort(),D1);return(async()=>{try{const Z=await F1(t,e,n,O.signal);if(P!==$.current)return;R(Array.isArray(Z.rounds)?Z.rounds:[])}catch(Z){if(P!==$.current)return;const ee=(Z==null?void 0:Z.name)==="AbortError"?"requestTimeout":Z.message||String(Z);g(ee)}finally{window.clearTimeout(_),P===$.current&&f(!1)}})(),()=>{O.abort(),$.current++,T.current++}},[e,t,n,R]),h.useEffect(()=>{r&&M()},[r,M]),h.useEffect(()=>{clearInterval(N.current);const P=w.length>0?w[w.length-1]:null;return(r==="running"&&w.length===0||!!(P&&P.status==="running"))&&e&&t&&(N.current=setInterval(()=>M(),2e3)),()=>clearInterval(N.current)},[w,e,t,n,r,M]),h.useEffect(()=>{E.current&&(E.current.scrollTop=0)},[y]);const I=w.find(P=>P.execId===y),F=a?void 0:{width:`${c}px`};return i.jsxs("aside",{className:"af-run-ctx-panel",style:F,"aria-label":o("flow:runContext.title"),children:[a?null:i.jsx("div",{className:"af-run-ctx-resize",role:"separator","aria-orientation":"vertical","aria-label":o("flow:runContext.resizeHandle"),onPointerDown:K,onPointerMove:B,onPointerUp:L,onPointerCancel:L,onLostPointerCapture:D}),i.jsxs("div",{className:"af-run-ctx-panel__main",children:[i.jsxs("div",{className:"af-run-ctx-head",children:[i.jsx("h2",{className:"af-run-ctx-title",title:e,children:e}),i.jsx("button",{type:"button",className:"af-icon-btn",onClick:s,"aria-label":o("common:common.close"),children:i.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),u&&i.jsx("div",{className:"af-run-ctx-placeholder",children:o("common:common.loading")}),m&&i.jsx("div",{className:"af-run-ctx-error",children:IU(o,m)}),!u&&!m&&w.length===0&&i.jsx("div",{className:"af-run-ctx-placeholder",children:o(r==="running"?"flow:runContext.executingNoArtifacts":"flow:runContext.noData")}),w.length>0&&i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"af-run-ctx-rounds af-run-ctx-rounds--select af-run-ctx-round--"+MU((I==null?void 0:I.status)||""),children:[i.jsx("span",{className:"af-run-ctx-round-dot","aria-hidden":!0}),i.jsx("select",{className:"af-run-ctx-round-select",value:String(y??""),onChange:P=>{const O=P.target.value;b(O==="latest"?"latest":Number(O))},children:[...w].reverse().map(P=>{const O=P.execId==="latest"?o("flow:runContext.latest"):`#${P.execId}`,_=LU(o,P.status),Z=P.finishedAt?` · ${RU(P.finishedAt)}`:"";return i.jsx("option",{value:String(P.execId),children:`${O} · ${_}${Z}`},P.execId)})})]}),I&&i.jsxs("div",{className:"af-run-ctx-body",ref:E,children:[I.inputs&&I.inputs.length>0&&i.jsxs("section",{className:"af-run-ctx-section",children:[i.jsxs("h3",{className:"af-run-ctx-section-title",children:[i.jsx("span",{className:"material-symbols-outlined af-run-ctx-section-icon","aria-hidden":!0,children:"input"}),"Inputs"]}),I.inputs.map((P,O)=>i.jsxs("div",{className:"af-run-ctx-output-slot",children:[i.jsx("div",{className:"af-run-ctx-slot-head",children:i.jsx("div",{className:"af-run-ctx-slot-name",children:P.slot})}),i.jsx("pre",{className:"af-run-ctx-slot-text",children:P.value})]},`${P.slot}-${O}`))]}),I.prompt!=null&&i.jsxs("section",{className:"af-run-ctx-section",children:[i.jsxs("h3",{className:"af-run-ctx-section-title",children:[i.jsx("span",{className:"material-symbols-outlined af-run-ctx-section-icon","aria-hidden":!0,children:"description"}),"Prompt",i.jsx("button",{type:"button",className:"af-icon-btn af-run-ctx-section-expand",onClick:()=>j("prompt"),title:o("flow:nodeProps.expand"),children:i.jsx("span",{className:"material-symbols-outlined",children:"open_in_full"})})]}),i.jsx(R1,{text:I.prompt})]}),I.outputs&&I.outputs.length>0&&i.jsxs("section",{className:"af-run-ctx-section",children:[i.jsxs("h3",{className:"af-run-ctx-section-title",children:[i.jsx("span",{className:"material-symbols-outlined af-run-ctx-section-icon","aria-hidden":!0,children:"output"}),"Outputs",i.jsx("button",{type:"button",className:"af-icon-btn af-run-ctx-section-expand",onClick:()=>j("output"),title:o("flow:nodeProps.expand"),children:i.jsx("span",{className:"material-symbols-outlined",children:"open_in_full"})})]}),I.outputs.map((P,O)=>{const _=L1(P),Z=O1(P);return i.jsxs("div",{className:"af-run-ctx-output-slot",children:[i.jsxs("div",{className:"af-run-ctx-slot-head",children:[i.jsx("div",{className:"af-run-ctx-slot-name",children:P.slot}),_?i.jsx("span",{className:"af-run-ctx-format-badge",title:o("flow:runContext.detectedContentType"),children:_}):null,i.jsx($1,{text:Z,title:o("common:common.copy"),copiedLabel:o("common:common.copied")})]}),i.jsx(M1,{o:P})]},`${P.slot}-${O}`)})]}),!I.prompt&&(!I.outputs||I.outputs.length===0)&&i.jsx("div",{className:"af-run-ctx-placeholder",children:o("flow:runContext.roundNoContent")})]})]})]}),x&&I&&i.jsx("div",{className:"af-node-props-expand-overlay",role:"dialog","aria-modal":"true",onClick:P=>{P.target===P.currentTarget&&j(null)},children:i.jsxs("div",{className:"af-node-props-expand-panel",children:[i.jsxs("div",{className:"af-node-props-expand-head",children:[i.jsx("span",{className:"af-node-props-expand-title",children:x==="prompt"?"Prompt":"Outputs"}),i.jsx("button",{type:"button",className:"af-icon-btn",onClick:()=>j(null),"aria-label":o("common:common.close"),children:i.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),i.jsxs("div",{className:"af-node-props-expand-body af-run-ctx-expand-body",children:[x==="prompt"&&I.prompt!=null&&i.jsx(R1,{text:I.prompt}),x==="output"&&I.outputs&&I.outputs.map((P,O)=>{const _=L1(P),Z=O1(P);return i.jsxs("div",{className:"af-run-ctx-output-slot",style:{marginBottom:"1rem"},children:[i.jsxs("div",{className:"af-run-ctx-slot-head",children:[i.jsx("div",{className:"af-run-ctx-slot-name",children:P.slot}),_?i.jsx("span",{className:"af-run-ctx-format-badge",children:_}):null,i.jsx($1,{text:Z,title:o("common:common.copy"),copiedLabel:o("common:common.copied")})]}),i.jsx(M1,{o:P})]},`${P.slot}-${O}`)})]})]})})]})}function RU(e){try{const t=new Date(e);if(isNaN(t.getTime()))return e;const n=r=>String(r).padStart(2,"0");return`${n(t.getMonth()+1)}-${n(t.getDate())} ${n(t.getHours())}:${n(t.getMinutes())}`}catch{return e}}function MU(e){const t=String(e||"").toLowerCase();return t==="success"||t==="completed"||t==="done"?"success":t==="failed"||t==="error"?"failed":t==="running"||t==="executing"?"running":t==="cache_not_met"?"cache":t?"unknown":"pending"}function LU(e,t){const n=String(t||"").toLowerCase();return n?n==="success"||n==="completed"||n==="done"?e("flow:runContext.statusSuccess",{defaultValue:"成功"}):n==="failed"||n==="error"?e("flow:runContext.statusFailed",{defaultValue:"失败"}):n==="running"||n==="executing"?e("flow:runContext.statusRunning",{defaultValue:"运行中"}):n==="cache_not_met"?e("flow:runContext.statusCacheMiss",{defaultValue:"缓存失效"}):t:e("flow:runContext.statusPending",{defaultValue:"等待"})}function OU({flowId:e,flowSource:t,flowArchived:n,provideNodes:r,edges:s,nodes:o,onCliInputsChange:a,onBackToEdit:l}){const{t:c}=zn(),[d,p]=h.useState({}),[u,f]=h.useState(null),[m,g]=h.useState({}),[w,k]=h.useState(!0),[y,b]=h.useState(!1),[x,j]=h.useState(""),[E,N]=h.useState(!1),[T,$]=h.useState(null),z=h.useRef(null),K=h.useRef(!0),B=h.useRef({});h.useMemo(()=>{var _,Z,ee;const O={};for(const V of r){const ae=(ee=(Z=(_=V.data)==null?void 0:_.outputs)==null?void 0:Z[0])==null?void 0:ee.default;ae!=null&&ae!==""&&(O[V.id]=String(ae))}return B.current=O,O},[r]);const L=h.useMemo(()=>{var _;const O={};for(const Z of o){if(!((_=Z.data)!=null&&_.inputs))continue;const ee=Z.data.inputs;for(let V=0;V<ee.length;V++){const ae=ee[V];if(!(ae!=null&&ae.name))continue;const fe=s.find(Se=>Se.target===Z.id&&Se.targetHandle===`input-${V}`);if(!(fe!=null&&fe.source))continue;r.find(Se=>Se.id===fe.source)&&(O[fe.source]=ae.name)}}return O},[o,s,r]);h.useEffect(()=>(K.current=!0,()=>{K.current=!1}),[]),h.useEffect(()=>{if(!e){k(!1);return}k(!0);const O=new URLSearchParams({flowId:e,flowSource:t||"user"});n&&O.set("archived","1"),fetch(`/api/flow/run-config?${O.toString()}`).then(_=>{if(!_.ok)throw new Error(`HTTP ${_.status}`);return _.json()}).then(_=>{var ee;if(!K.current)return;p(_.presets||{}),f(_.activePreset||null);const Z=_.activePreset&&((ee=_.presets)!=null&&ee[_.activePreset])?_.presets[_.activePreset]:{};g({...B.current,...Z}),k(!1)}).catch(()=>{K.current&&(g(B.current),k(!1))})},[e,t,n]),h.useEffect(()=>{var _;if(!a)return;const O={};for(const[Z,ee]of Object.entries(m)){const V=L[Z];if(!V)continue;const ae=r.find(xe=>xe.id===Z);if(!ae)continue;(((_=ae.data)==null?void 0:_.definitionId)||"").startsWith("provide_file")?O[V]={type:"file",path:ee}:O[V]={type:"str",value:ee}}a(O)},[m,L,r,a]);const D=h.useCallback((O,_)=>{g(Z=>({...Z,[O]:_}))},[]),R=h.useCallback(O=>{O!==u&&(f(O),O&&d[O]?g({...B.current,...d[O]}):g(B.current))},[u,d]),M=h.useCallback(async()=>{if(x.trim()){b(!0);try{const O={...d,[x.trim()]:m},_={flowId:e,flowSource:t,archived:n,presets:O,activePreset:x.trim()};(await fetch("/api/flow/run-config",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(_)})).ok&&(p(O),f(x.trim()),j(""),N(!1))}finally{b(!1)}}},[e,t,n,d,m,x]),I=h.useCallback(async()=>{if(u){b(!0);try{const O={...d};delete O[u];const _=Object.keys(O)[0]||null;(await fetch("/api/flow/run-config",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({flowId:e,flowSource:t,archived:n,presets:O,activePreset:_})})).ok&&(p(O),f(_),_&&O[_]?g({...B.current,...O[_]}):g(B.current))}finally{b(!1)}}},[e,t,n,d,u]),F=h.useCallback(async()=>{if(u){b(!0);try{const O={...d,[u]:m};(await fetch("/api/flow/run-config",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({flowId:e,flowSource:t,archived:n,presets:O,activePreset:u})})).ok&&p(O)}finally{b(!1)}}},[e,t,n,d,u,m]),P=Object.keys(d);return P.length>0,w?i.jsx("aside",{className:"af-run-config-panel",children:i.jsx("div",{className:"af-run-config-loading",children:c("common.loading")})}):i.jsxs("aside",{className:"af-run-config-panel",children:[i.jsxs("div",{className:"af-run-config-preset",children:[i.jsx("label",{className:"af-run-config-preset-label",children:c("flow:runConfig.preset")}),i.jsxs("div",{className:"af-run-config-preset-row",children:[i.jsxs("select",{className:"af-run-config-preset-select",value:u||"",onChange:O=>R(O.target.value||null),disabled:y,children:[i.jsx("option",{value:"",children:c("flow:runConfig.default")}),P.map(O=>i.jsx("option",{value:O,children:O},O))]}),i.jsx("button",{type:"button",className:"af-run-config-preset-btn af-run-config-preset-btn--new",onClick:()=>N(!0),disabled:y,title:c("flow:runConfig.newPreset"),children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"add"})}),u&&i.jsx("button",{type:"button",className:"af-run-config-preset-btn af-run-config-preset-btn--save",onClick:F,disabled:y,title:c("flow:runConfig.savePreset"),children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"save"})}),u&&i.jsx("button",{type:"button",className:"af-run-config-preset-btn af-run-config-preset-btn--delete",onClick:I,disabled:y,title:c("flow:runConfig.deletePreset"),children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"delete"})})]})]}),E&&i.jsxs("div",{className:"af-run-config-save-dialog",children:[i.jsx("input",{type:"text",className:"af-run-config-save-input",placeholder:c("flow:runConfig.presetNamePlaceholder"),value:x,onChange:O=>j(O.target.value),disabled:y}),i.jsxs("div",{className:"af-run-config-save-actions",children:[i.jsx("button",{type:"button",className:"af-btn-primary",onClick:M,disabled:y||!x.trim(),children:c(y?"common.saving":"common.save")}),i.jsx("button",{type:"button",className:"af-btn-outline",onClick:()=>{N(!1),j("")},disabled:y,children:c("common.cancel")})]})]}),i.jsxs("div",{className:"af-run-config-inputs",children:[i.jsx("div",{className:"af-run-config-inputs-header",children:c("flow:runConfig.inputParams")}),r.length===0?i.jsx("div",{className:"af-run-config-empty",children:c("flow:runConfig.noProvideNodes")}):i.jsx("div",{className:"af-run-config-input-list",children:r.map(O=>{var Se,ue;const _=((Se=O.data)==null?void 0:Se.definitionId)||"",Z=_.startsWith("provide_file"),ee=_==="provide_bool",V=((ue=O.data)==null?void 0:ue.label)||O.id,ae=O.id,fe=m[ae]||"",xe=["true","1","yes","on"].includes(String(fe).trim().toLowerCase());return i.jsxs("div",{className:"af-run-config-input-item",children:[i.jsxs("div",{className:"af-run-config-input-head",children:[i.jsx("span",{className:"af-run-config-input-icon material-symbols-outlined"+(Z?" af-run-config-input-icon--file":""),"aria-hidden":!0,children:Z?"description":ee?"toggle_on":"text_fields"}),i.jsx("span",{className:"af-run-config-input-label",children:V}),ee?null:i.jsx("button",{type:"button",className:"af-run-config-input-expand",onClick:()=>$({instanceId:ae,label:V,content:fe}),"aria-label":c("flow:runConfig.expandInput"),title:c("flow:runConfig.expandInput"),children:i.jsx("span",{className:"material-symbols-outlined",children:"open_in_full"})})]}),i.jsx("div",{className:"af-run-config-input-id",children:ae}),ee?i.jsx("button",{type:"button",className:"af-run-config-bool-toggle"+(xe?" af-run-config-bool-toggle--true":""),onClick:()=>D(ae,xe?"false":"true"),"aria-pressed":xe,children:xe?"true":"false"}):i.jsx("input",{type:"text",className:"af-run-config-input-field",value:fe,onChange:Ee=>D(ae,Ee.target.value),placeholder:c(Z?"flow:runConfig.filePathPlaceholder":"flow:runConfig.stringValuePlaceholder")})]},ae)})})]}),T&&Ir.createPortal(i.jsx("div",{className:"af-provide-edit-overlay",children:i.jsxs("div",{className:"af-provide-edit-modal",role:"dialog","aria-modal":"true",children:[i.jsxs("div",{className:"af-provide-edit-modal__head",children:[i.jsx("span",{className:"material-symbols-outlined",children:"edit_document"}),i.jsx("span",{className:"af-provide-edit-modal__title",children:T.label}),i.jsx("button",{type:"button",className:"af-provide-edit-modal__close",onClick:()=>$(null),"aria-label":c("common:close"),children:i.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),i.jsx("div",{className:"af-provide-edit-modal__body",children:i.jsx("textarea",{ref:z,className:"af-provide-edit-modal__textarea",defaultValue:T.content,autoFocus:!0})}),i.jsxs("div",{className:"af-provide-edit-modal__foot",children:[i.jsxs("button",{type:"button",className:"af-provide-edit-modal__btn af-provide-edit-modal__btn--save",onClick:()=>{!T||!z.current||(D(T.instanceId,z.current.value),$(null))},children:[i.jsx("span",{className:"material-symbols-outlined",children:"save"}),c("flow:provideEdit.save")]}),i.jsxs("button",{type:"button",className:"af-provide-edit-modal__btn",onClick:()=>$(null),children:[i.jsx("span",{className:"material-symbols-outlined",children:"close"}),c("flow:provideEdit.cancel")]})]})]})}),document.body)]})}const zR={ai:["planner-system","planner-user","planner-response","agent-step-prompt","repair-prompt","ai-thinking","ai-assistant","ai-result","ai-tool"],flow:["composer-start","classify","plan","phase-plan","phase-complete","phase-auto-continue","composer-done"],step:["step-start","step-progress","step-done","validation"],output:["natural","status"],error:["error"]},$U={"planner-system":"#9ecaff","planner-user":"#9ecaff","planner-response":"#7c4dff","agent-step-prompt":"#7c4dff","repair-prompt":"#ff6b6b","ai-thinking":"#a8b9d4","ai-assistant":"#e8deff","ai-result":"#00e475","ai-tool":"#9ecaff","composer-start":"#00e475","composer-done":"#00e475","step-start":"#e8deff","step-done":"#e8deff","step-progress":"#e8deff",natural:"#a8a8a8",status:"#a8a8a8",error:"#ff6b6b","phase-plan":"#00e475","phase-complete":"#00e475"};function DU(e){return!e||e<1024?`${e||0} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/1024/1024).toFixed(2)} MB`}function FU(e){if(!e)return"";const t=new Date(e);return isNaN(t.getTime())?e:`${t.getHours().toString().padStart(2,"0")}:${t.getMinutes().toString().padStart(2,"0")}:${t.getSeconds().toString().padStart(2,"0")}.${t.getMilliseconds().toString().padStart(3,"0")}`}function zU(e){if(!e)return"";const t=new Date(e);return isNaN(t.getTime())?e:`${t.getMonth()+1}/${t.getDate()} ${t.getHours().toString().padStart(2,"0")}:${t.getMinutes().toString().padStart(2,"0")}`}function z1(e,t){if(e==="natural"&&t&&typeof t=="object"){const n=t.kind;if(n==="thinking"||n==="assistant"||n==="result"||n==="tool")return"ai";if(n==="error")return"error"}for(const[n,r]of Object.entries(zR))if(r.includes(e))return n;return"other"}function HU({event:e,defaultExpanded:t}){const[n,r]=h.useState(!!t),s=$U[e.tag]||"#a8a8a8",o=e.payload,a=o&&typeof o=="object",l=a?typeof o.text=="string"?o.text:"":String(o||""),c=a?o.meta:null,d=h.useMemo(()=>l?l.slice(0,140).replace(/\s+/g," "):a?Object.keys(o).filter(m=>m!=="text"&&m!=="meta").slice(0,3).map(m=>{const g=o[m];return g==null?`${m}:null`:typeof g=="object"?`${m}:{…}`:`${m}:${String(g).slice(0,30)}`}).join(" "):"",[o,l,a]),p=h.useCallback(u=>{u.stopPropagation();const f=a?JSON.stringify(o,null,2):String(o);try{navigator.clipboard.writeText(f)}catch{}},[o,a]);return i.jsxs("div",{style:{borderLeft:`3px solid ${s}`,background:n?"#1c1b1b":"#131313",marginBottom:4,borderRadius:4,cursor:"pointer",transition:"background 120ms"},onClick:()=>r(u=>!u),children:[i.jsxs("div",{style:{padding:"6px 10px",display:"flex",alignItems:"center",gap:10,fontSize:12},children:[i.jsx("span",{style:{color:"#9a9a9a",fontFamily:"monospace",flexShrink:0},children:FU(e.ts)}),i.jsx("span",{style:{color:s,fontWeight:600,fontFamily:"monospace",flexShrink:0,padding:"1px 6px",background:"rgba(255,255,255,0.04)",borderRadius:3},children:e.tag}),i.jsx("span",{style:{color:"#c5c2c1",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"monospace"},children:d}),n&&i.jsx("button",{type:"button",onClick:p,style:{background:"rgba(124,77,255,0.15)",color:"#e8deff",border:"none",borderRadius:3,padding:"2px 8px",fontSize:11,cursor:"pointer"},children:"Copy"})]}),n&&i.jsxs("div",{style:{padding:"0 10px 10px 10px",borderTop:"1px solid rgba(255,255,255,0.04)"},children:[c&&Object.keys(c).length>0&&i.jsx("div",{style:{marginTop:8,padding:8,background:"#0e0e0e",borderRadius:4,fontSize:11,fontFamily:"monospace",color:"#9ecaff",whiteSpace:"pre-wrap",wordBreak:"break-all"},children:JSON.stringify(c,null,2)}),l?i.jsx("pre",{style:{marginTop:8,padding:10,background:"#0e0e0e",borderRadius:4,fontSize:12,color:"#e5e2e1",whiteSpace:"pre-wrap",wordBreak:"break-word",maxHeight:600,overflowY:"auto",margin:"8px 0 0 0",fontFamily:"ui-monospace, SF Mono, Menlo, monospace"},children:l}):a?i.jsx("pre",{style:{marginTop:8,padding:10,background:"#0e0e0e",borderRadius:4,fontSize:12,color:"#e5e2e1",whiteSpace:"pre-wrap",wordBreak:"break-all",maxHeight:400,overflowY:"auto",margin:"8px 0 0 0",fontFamily:"ui-monospace, SF Mono, Menlo, monospace"},children:JSON.stringify(o,null,2)}):null]})]})}function BU({open:e,onClose:t,flowId:n}){var $;const[r,s]=h.useState([]),[o,a]=h.useState(!1),[l,c]=h.useState(null),[d,p]=h.useState(null),[u,f]=h.useState(!1),[m,g]=h.useState(!0),[w,k]=h.useState({ai:!0,flow:!0,step:!0,output:!0,error:!0}),[y,b]=h.useState(""),x=h.useRef(null),j=h.useCallback(async()=>{a(!0);try{const z=m&&n?`?flowId=${encodeURIComponent(n)}`:"",B=await(await fetch(`/api/composer-logs${z}`)).json();s(Array.isArray(B.sessions)?B.sessions:[])}catch{s([])}finally{a(!1)}},[n,m]),E=h.useCallback(async z=>{if(!z){p(null);return}f(!0);try{const B=await(await fetch(`/api/composer-logs/${encodeURIComponent(z)}`)).json();p(B)}catch{p(null)}finally{f(!1)}},[]);h.useEffect(()=>{e&&j()},[e,j]),h.useEffect(()=>{if(!(!e||!l))return E(l),x.current=setInterval(()=>E(l),2e3),()=>{x.current&&clearInterval(x.current),x.current=null}},[e,l,E]);const N=h.useMemo(()=>{const z=(d==null?void 0:d.events)||[],K=y.trim().toLowerCase();return z.filter(B=>{const L=z1(B.tag,B.payload);return!w[L]&&L!=="other"?!1:K?[B.tag,JSON.stringify(B.payload||"")].join(" ").toLowerCase().includes(K):!0})},[d,w,y]),T=h.useMemo(()=>{const z=(d==null?void 0:d.events)||[],K={};for(const B of z){const L=z1(B.tag,B.payload);K[L]=(K[L]||0)+1}return K},[d]);return e?i.jsxs("div",{style:{position:"fixed",top:0,right:0,bottom:0,width:"min(1100px, 80vw)",background:"#131313",borderLeft:"1px solid rgba(255,255,255,0.08)",display:"flex",flexDirection:"column",zIndex:9999,boxShadow:"-8px 0 32px rgba(0,0,0,0.5)",color:"#e5e2e1",fontFamily:"Inter, system-ui, sans-serif"},children:[i.jsxs("div",{style:{padding:"12px 16px",borderBottom:"1px solid rgba(255,255,255,0.06)",display:"flex",alignItems:"center",gap:12,flexShrink:0,background:"#1c1b1b"},children:[i.jsx("span",{style:{fontWeight:600,fontSize:14},children:"Composer Logs"}),i.jsx("span",{style:{fontSize:11,color:"#9a9a9a"},children:n?`flowId: ${n}`:"no flow selected"}),i.jsxs("label",{style:{fontSize:11,color:"#9a9a9a",display:"flex",alignItems:"center",gap:4,cursor:"pointer"},children:[i.jsx("input",{type:"checkbox",checked:m,onChange:z=>g(z.target.checked),disabled:!n}),"仅显示当前 flow"]}),i.jsx("button",{type:"button",onClick:j,style:{background:"rgba(124,77,255,0.15)",color:"#e8deff",border:"none",borderRadius:4,padding:"4px 10px",fontSize:12,cursor:"pointer"},children:"Refresh"}),i.jsx("span",{style:{flex:1}}),i.jsx("button",{type:"button",onClick:t,style:{background:"transparent",color:"#e5e2e1",border:"1px solid rgba(255,255,255,0.12)",borderRadius:4,padding:"4px 12px",fontSize:12,cursor:"pointer"},children:"Close"})]}),i.jsxs("div",{style:{flex:1,display:"flex",overflow:"hidden",minHeight:0},children:[i.jsxs("div",{style:{width:280,borderRight:"1px solid rgba(255,255,255,0.06)",overflowY:"auto",background:"#0e0e0e",flexShrink:0},children:[o&&i.jsx("div",{style:{padding:12,fontSize:12,color:"#9a9a9a"},children:"Loading…"}),!o&&r.length===0&&i.jsx("div",{style:{padding:12,fontSize:12,color:"#9a9a9a"},children:m&&n?"no sessions for this flow":"no sessions"}),r.map(z=>{const K=l===z.sessionId;return i.jsxs("div",{onClick:()=>c(z.sessionId),style:{padding:"10px 12px",borderBottom:"1px solid rgba(255,255,255,0.04)",cursor:"pointer",background:K?"rgba(124,77,255,0.18)":"transparent",borderLeft:K?"3px solid #7c4dff":"3px solid transparent"},children:[i.jsx("div",{style:{fontSize:12,fontWeight:600,color:"#e5e2e1"},children:zU(z.mtime)}),i.jsx("div",{style:{fontSize:11,color:"#9ecaff",marginTop:2,fontFamily:"monospace"},children:z.flowId||"(no flow)"}),z.promptPreview&&i.jsx("div",{style:{fontSize:11,color:"#9a9a9a",marginTop:4,overflow:"hidden",textOverflow:"ellipsis",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical"},children:z.promptPreview}),i.jsxs("div",{style:{fontSize:10,color:"#6a6a6a",marginTop:4},children:[DU(z.size)," · ",z.model||"default"]})]},z.sessionId)})]}),i.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",overflow:"hidden",minHeight:0},children:[i.jsxs("div",{style:{padding:"10px 16px",borderBottom:"1px solid rgba(255,255,255,0.06)",display:"flex",alignItems:"center",gap:8,flexWrap:"wrap",flexShrink:0,background:"#1c1b1b"},children:[Object.keys(zR).map(z=>i.jsxs("button",{type:"button",onClick:()=>k(K=>({...K,[z]:!K[z]})),style:{background:w[z]?"rgba(124,77,255,0.25)":"transparent",color:w[z]?"#e8deff":"#6a6a6a",border:`1px solid ${w[z]?"rgba(124,77,255,0.4)":"rgba(255,255,255,0.08)"}`,borderRadius:999,padding:"3px 12px",fontSize:11,cursor:"pointer",fontFamily:"monospace",textTransform:"uppercase"},children:[z," ",T[z]!=null?`(${T[z]})`:""]},z)),i.jsx("input",{type:"text",placeholder:"search…",value:y,onChange:z=>b(z.target.value),style:{marginLeft:8,flex:1,minWidth:120,background:"#0e0e0e",border:"1px solid rgba(255,255,255,0.08)",borderRadius:4,color:"#e5e2e1",padding:"4px 8px",fontSize:12}})]}),i.jsxs("div",{style:{flex:1,overflowY:"auto",padding:12,minHeight:0},children:[!l&&i.jsx("div",{style:{color:"#9a9a9a",fontSize:12,padding:20,textAlign:"center"},children:"Select a session on the left to view events"}),u&&!d&&i.jsx("div",{style:{color:"#9a9a9a",fontSize:12,padding:20},children:"Loading…"}),d&&N.length===0&&i.jsxs("div",{style:{color:"#9a9a9a",fontSize:12,padding:20},children:["No events match current filter (",(($=d.events)==null?void 0:$.length)||0," total)"]}),N.map((z,K)=>i.jsx(HU,{event:z,defaultExpanded:z.tag==="error"},`${z.ts}_${K}`))]})]})]})]}):null}const WU="0.1.84";function H1(e){const t=Math.max(0,Number(e)||0),n=Math.floor(t/36e5),r=Math.floor(t%36e5/6e4),s=Math.floor(t%6e4/1e3);return`${String(n).padStart(2,"0")}:${String(r).padStart(2,"0")}:${String(s).padStart(2,"0")}`}function xw(e,t){return t==="running"?H1(e):e==null||!Number.isFinite(e)||e<=0?"--":H1(e)}const HR=h.createContext({modelLists:{cursor:[],opencode:[]},onModelChange:()=>{}});function VU(e){var b,x,j,E,N,T,$,z,K,B,L;const{setNodes:t}=Hl(),n=J0(),{modelLists:r,onModelChange:s}=h.useContext(HR),o=h.useRef(null),a=!!((b=e.data)!=null&&b.readOnly),l=(x=e.data)!=null&&x.displaySize&&Number(e.data.displaySize.width)>0&&Number(e.data.displaySize.height)>0?{width:Number(e.data.displaySize.width),height:Number(e.data.displaySize.height)}:null,c=((j=e.data)==null?void 0:j.definitionId)==="agent_subAgent"&&!((E=e.data)!=null&&E.isRunMode)&&!a,d=h.useCallback(D=>{const R=()=>n(D);window.requestAnimationFrame(R),window.setTimeout(R,80)},[n]),p=h.useCallback((D,R)=>{const M=G1(R);M&&(t(I=>I.map(F=>{var _,Z,ee,V,ae,fe;if(F.id!==D)return F;const P=Number(((Z=(_=F.data)==null?void 0:_.displaySize)==null?void 0:Z.width)||F.width||((ee=F.measured)==null?void 0:ee.width)||0),O=Number(((ae=(V=F.data)==null?void 0:V.displaySize)==null?void 0:ae.height)||F.height||((fe=F.measured)==null?void 0:fe.height)||0);return Math.abs(P-M.width)<2&&Math.abs(O-M.height)<2?F:{...F,width:M.width,height:M.height,data:{...F.data,displaySize:M}}})),d(D))},[d,t]),u=h.useCallback(D=>{if(a)return;const R=o.current;if(!R)return;const M=R.getBoundingClientRect();p(D,{width:Math.max(M.width,R.scrollWidth),height:Math.max(M.height,R.scrollHeight)})},[p,a]),f=h.useCallback(D=>{var ae,fe,xe,Se,ue,Ee;if(!c)return;D.preventDefault(),D.stopPropagation();const R=o.current,M=R==null?void 0:R.getBoundingClientRect(),I=Number(((fe=(ae=e.data)==null?void 0:ae.displaySize)==null?void 0:fe.width)||e.width||((xe=e.measured)==null?void 0:xe.width)||(M==null?void 0:M.width)||KR),F=Number(((ue=(Se=e.data)==null?void 0:Se.displaySize)==null?void 0:ue.height)||e.height||((Ee=e.measured)==null?void 0:Ee.height)||(M==null?void 0:M.height)||vv),P=D.clientX,O=D.clientY,_=e.id;let Z=0;const ee=le=>{const me=G1({width:I+le.clientX-P,height:F+le.clientY-O});me&&(window.cancelAnimationFrame(Z),Z=window.requestAnimationFrame(()=>p(_,me)))},V=()=>{window.cancelAnimationFrame(Z),window.removeEventListener("pointermove",ee),window.removeEventListener("pointerup",V),window.removeEventListener("pointercancel",V),d(_)};window.addEventListener("pointermove",ee),window.addEventListener("pointerup",V,{once:!0}),window.addEventListener("pointercancel",V,{once:!0})},[p,(T=(N=e.data)==null?void 0:N.displaySize)==null?void 0:T.height,(z=($=e.data)==null?void 0:$.displaySize)==null?void 0:z.width,e.height,e.id,(K=e.measured)==null?void 0:K.height,(B=e.measured)==null?void 0:B.width,e.width,d,c]),m=h.useCallback(D=>{t(R=>R.filter(M=>M.id!==D))},[t]),g=h.useCallback(()=>{var I,F,P,O,_,Z,ee,V;const D=((I=e.data)==null?void 0:I.definitionId)||"",R=((F=e.data)==null?void 0:F.label)||e.id,M=((_=(O=(P=e.data)==null?void 0:P.outputs)==null?void 0:O[0])==null?void 0:_.value)||((V=(ee=(Z=e.data)==null?void 0:Z.outputs)==null?void 0:ee[0])==null?void 0:V.default)||"";window.__provideEditContent={instanceId:e.id,label:R,definitionId:D,content:M},window.dispatchEvent(new CustomEvent("provide-expand"))},[e.id,e.data]),w=h.useCallback((D,R)=>{t(M=>M.map(I=>{var P;if(I.id!==D)return I;const F=Array.isArray((P=I.data)==null?void 0:P.outputs)&&I.data.outputs.length?I.data.outputs.map((O,_)=>_===0?{...O,default:R,value:R}:O):[{type:"bool",name:"value",default:R,value:R}];return{...I,data:{...I.data,body:"",outputs:F}}}))},[t]),k=h.useCallback((D,R)=>{t(M=>M.map(I=>I.id===D?{...I,data:{...I.data,body:R}}:I))},[t]),y=h.useCallback((D,R)=>{t(M=>M.map(I=>I.id===D?{...I,data:{...I.data,images:Vs(R)}}:I))},[t]);return i.jsxs("div",{ref:o,className:"af-flow-node-shell"+(c?" af-flow-node-shell--resizable":""),style:l?{width:l.width,height:l.height}:void 0,children:[i.jsx(ER,{...e,data:{...e.data,onNodeContentResize:u},deleteNode:m,onProvideExpand:g,onProvideValueChange:w,onNodeBodyChange:k,onNodeImagesChange:y,modelLists:r,onModelChange:s}),c?i.jsx("span",{className:"af-flow-node-shell__resize-grip nodrag","aria-label":((L=e.data)==null?void 0:L.resizeLabel)||"Resize node",role:"separator",onPointerDown:f}):null]})}const KU={[$c]:VU},Lf=["CONTROL","TOOL","PROVIDE","AGENT"],UU=1200,B1="af-flow-node--sync-flash",W1="af-flow-edge--sync-flash";function V1(e,t){const n=String(e||"").trim();return n?n.split(/\s+/).includes(t)?n:`${n} ${t}`:t}function K1(e,t){const n=String(e||"").trim();return n?n.split(/\s+/).filter(r=>r&&r!==t).join(" "):""}function kk(e){const t=((e==null?void 0:e.id)??"").trim();return/^control/i.test(t)?"CONTROL":/^tool/i.test(t)?"TOOL":/^provide/i.test(t)?"PROVIDE":"AGENT"}function qU(e){const t=kk(e);return t==="CONTROL"?"control":t==="PROVIDE"?"provide":t==="TOOL"?"tool":"agent"}function ym(e){return(Array.isArray(e)?e:[]).map(n=>{const r=String((n==null?void 0:n.name)||(n==null?void 0:n.id)||"").trim(),s=String((n==null?void 0:n.type)||"").trim();return!r&&!s?"":s?`${r||"-"}: ${s}`:r}).filter(Boolean)}function BR(e){return String((e==null?void 0:e.label)||"").trim()||String((e==null?void 0:e.id)||"").trim()}function WR(e){return String((e==null?void 0:e.description)||(e==null?void 0:e.body)||"").replace(/\s+/g," ").trim()}function ww(e,t){const n=String((e==null?void 0:e.name)||(e==null?void 0:e.id)||"").trim(),r=String((e==null?void 0:e.type)||"").trim();return n||r||`#${t+1}`}function U1(e,t,n){const r=String((t==null?void 0:t.name)||(t==null?void 0:t.id)||`#${n+1}`).trim(),s=String((t==null?void 0:t.type)||"").trim(),o=String((t==null?void 0:t.default)??(t==null?void 0:t.value)??"").trim();return[e,r,s?`type: ${s}`:"",o?`default: ${o}`:""].filter(Boolean).join(" · ")}function q1(e,t){const n=Array.isArray(e)?e:[],r=n.slice(0,4),s=Math.max(0,n.length-r.length);return{list:n,shown:r,hidden:s,kind:t}}function YU(e){return e==="CONTROL"?"account_tree":e==="TOOL"?"build":e==="PROVIDE"?"database":"smart_toy"}function GU(e,t){return t?[e==null?void 0:e.id,e==null?void 0:e.label,e==null?void 0:e.description].filter(Boolean).some(r=>String(r).toLowerCase().includes(t)):!0}function VR(e,t,n,r,s){const o=qU(e),a={id:t,type:$c,position:n,data:{label:e.label??e.id,definitionId:e.id,schemaType:o,inputs:Array.isArray(e.inputs)?e.inputs.map(l=>({...l})):[],outputs:Array.isArray(e.outputs)?e.outputs.map(l=>({...l})):[]}};return zp(a,r,s)}const KR=320,XU=220,JU=1600,vv=104,QU=900;function Y1(e,t,n){const r=Number(e);return!Number.isFinite(r)||r<=0?0:Math.min(n,Math.max(t,Math.round(r)))}function G1(e){if(!e||typeof e!="object")return null;const t=Number(e.width),n=Number(e.height);return!Number.isFinite(t)||!Number.isFinite(n)||t<=0||n<=0?null:{width:Y1(t,XU,JU)||KR,height:Y1(n,vv,QU)||vv}}function ZU(e){const t=(e==null?void 0:e.data)||{},n=r=>(Array.isArray(r)?r:[]).map((s,o)=>(s==null?void 0:s.showOnNode)===!1?"":[o,String((s==null?void 0:s.type)||""),String((s==null?void 0:s.name)||""),s!=null&&s.required?"1":"0"].join(":")).filter(Boolean).join("|");return`${n(t.inputs)}=>${n(t.outputs)}`}function X1(e,t){const n=String((e==null?void 0:e.source)||""),r=String((e==null?void 0:e.target)||"");if(!n||!r)return!1;const s=new Map(t.map(d=>[d.id,d])),o=s.get(n),a=s.get(r),l=jd(o,e.sourceHandle||"output-0","source"),c=jd(a,e.targetHandle||"input-0","target");return!l||!c?!1:Ml(l,c)}function eq(e,t){const n=String((e==null?void 0:e.nodeId)||""),r=String((e==null?void 0:e.handleId)||""),s=(e==null?void 0:e.handleType)==="target"?"target":(e==null?void 0:e.handleType)==="source"?"source":"";if(!n||!r||!s)return null;const o=t.find(l=>l.id===n),a=jd(o,r,s);return a?{nodeId:n,handleId:r,handleType:s,slot:a,slotType:CR(a)}:null}function tq(e,t,n){var a;const r=VR(e,`__candidate_${e.id}`,{x:0,y:0},{},t),s=n.handleType==="source"?"inputs":"outputs",o=Array.isArray((a=r.data)==null?void 0:a[s])?r.data[s]:[];for(let l=0;l<o.length;l+=1){const c=o[l];if(n.handleType==="source"?Ml(n.slot,c):Ml(c,n.slot))return{slot:c,slotIndex:l,hydrated:r}}return null}function nq(e,t){return t?e.map((n,r)=>{const s=tq(n,e,t);if(!s)return null;const o=kk(n);return{def:n,order:r,category:o,categoryRank:Lf.indexOf(o),slot:s.slot,slotIndex:s.slotIndex,displayLabel:BR(s.hydrated.data||n),description:WR(n)}}).filter(Boolean).sort((n,r)=>{var a,l;const s=(a=n.slot)!=null&&a.required?0:1,o=(l=r.slot)!=null&&l.required?0:1;return s-o||n.slotIndex-r.slotIndex||n.categoryRank-r.categoryRank||n.order-r.order}):[]}const rq=/@([a-zA-Z_][a-zA-Z0-9_]*)/g;function sq(e){const t=new Set,n=[];let r;const s=new RegExp(rq.source,"g");for(;(r=s.exec(e))!==null;){const o=r[1];t.has(o)||(t.add(o),n.push(o))}return n}function J1(e,t){const n=e.slice(0,t),r=n.lastIndexOf("@");if(r<0)return null;const s=n.slice(r+1);return/[\s\n]/.test(s)?null:{atIndex:r,query:s}}function ga(e){const t=String(e||"").indexOf(" - ");return t>=0?e.slice(0,t).trim():String(e||"").trim()}function xm(e,t,n,r){const s=(e||"").trim();if(!s)return"";if(s.startsWith("opencode:")||s.startsWith("claude-code:"))return s;const o=Array.isArray(t)?t:[],a=Array.isArray(n)?n:[],l=Array.isArray(r)?r:[],c=o.map(ga),d=a.map(ga);return l.map(ga).includes(s)&&!c.includes(s)&&!d.includes(s)?`claude-code:${s}`:d.includes(s)&&!c.includes(s)?`opencode:${s}`:s}function iq(e){if(e==null)return"";const t=String(e).trim();return t?t.length<=26?t:`${t.slice(0,12)}…${t.slice(-10)}`:""}function bw(e){if(!Array.isArray(e)||e.length===0)return 0;let t=0;for(const n of e){const r=/^(?:对话|Conversation|Chat)\s*(\d+)\s*$/.exec(String((n==null?void 0:n.label)??"").trim());r&&(t=Math.max(t,parseInt(r[1],10)))}return t}function oq({steps:e}){const{t}=zn();return!e||e.length===0?null:i.jsx("div",{className:"af-composer-steps-track",role:"list","aria-label":t("flow:composer.stepsAriaLabel"),children:e.map(n=>{const r=String(n.description||n.type||"").trim(),s=n.model||n.executorModel,o=[`${n.index+1}. ${r||"—"}`,n.nodeRole?t("flow:composer.stepRoleLabel",{role:n.nodeRole}):"",n.instanceId?t("flow:composer.stepInstanceLabel",{instanceId:n.instanceId}):"",s?`${t("flow:palette.model")}:${s}`:""].filter(Boolean).join(`
129
129
  `),a=n.status||"pending";return i.jsxs("div",{className:"af-composer-step-chip"+(a==="done"?" af-composer-step-chip--done":"")+(a==="running"?" af-composer-step-chip--running":"")+(a==="error"?" af-composer-step-chip--error":"")+(a==="pending"?" af-composer-step-chip--pending":""),role:"listitem",title:o,children:[i.jsx("span",{className:"af-composer-step-chip-idx",children:n.index+1}),i.jsx("span",{className:"af-composer-step-chip-main",children:n.nodeRole||s?i.jsxs("span",{className:"af-composer-step-chip-meta",children:[n.nodeRole?i.jsx("span",{className:"af-composer-step-chip-role",children:n.nodeRole}):null,s?i.jsx("span",{className:"af-composer-step-chip-model",children:iq(s)}):null]}):null})]},n.index)})})}function aq(e,t){const n=e.trim(),r=t.trim();return r?n?!!(n===r||n.endsWith(r)||r.length>=8&&n.includes(r)):!1:!0}function lq(e){const t=[];for(const n of e){if(!n||typeof n.text!="string"||!n.text.trim())continue;const s=typeof n.kind=="string"&&n.kind?n.kind:"assistant",o=t[t.length-1];o&&o.kind===s?o.text+=s==="error"||s==="result"?`
130
130
  ${n.text}`:n.text:t.push({kind:s,text:n.text})}return t}function cq(e,t){return e==="thinking"?t("flow:composer.thinking"):e==="result"?t("flow:composer.result"):e==="assistant"?t("flow:composer.reply"):e==="error"?t("flow:composer.error"):String(e)}function uq(e){return e==="thinking"?"af-composer-ai-block af-composer-ai-block--thinking":e==="result"?"af-composer-ai-block af-composer-ai-block--result":e==="assistant"?"af-composer-ai-block af-composer-ai-block--reply":e==="error"?"af-composer-ai-block af-composer-ai-block--error":"af-composer-ai-block af-composer-ai-block--reply"}function Q1({thread:e,liveSegments:t,running:n,className:r="",autoScroll:s=!0}){const{t:o}=zn(),a=h.useRef(null),l=["af-composer-ai-stack","af-composer-ai-stack--in-panel","af-composer-thread-stack",r].filter(Boolean).join(" ");return h.useEffect(()=>{if(!s||!a.current)return;const c=a.current;requestAnimationFrame(()=>{c.scrollTop=c.scrollHeight})},[e,t,s]),i.jsxs("div",{ref:a,className:l,children:[e.map((c,d)=>c.type==="user"?i.jsxs("section",{className:"af-composer-ai-block af-composer-ai-block--user-msg",children:[i.jsx("div",{className:"af-composer-ai-block-label",children:o("flow:composer.yourQuestion")}),i.jsx("div",{className:"af-composer-ai-block-body",children:c.text})]},`composer-u-${d}-${c.text.slice(0,48)}`):i.jsx("div",{className:"af-composer-thread-assistant",children:i.jsx(Z1,{segments:c.segments,running:!1})},`composer-a-${d}`)),i.jsx("div",{className:"af-composer-thread-assistant",children:i.jsx(Z1,{segments:t,running:n})})]})}function Z1({segments:e,running:t=!1}){const{t:n}=zn(),r=e.filter(u=>u.kind==="assistant").map(u=>u.text).join(""),s=e.filter(u=>u.kind==="result").map(u=>u.text).join(""),o=aq(r,s),a=e.filter(u=>u.kind==="error").map(u=>u.text).join(`
131
131
  `),l=e.filter(u=>u.kind!=="error"),c=o?l.filter(u=>u.kind!=="result"):l,d=lq(c),p=!!(d.length>0||a);return i.jsxs(i.Fragment,{children:[d.map((u,f)=>i.jsxs("section",{className:uq(u.kind),children:[i.jsx("div",{className:"af-composer-ai-block-label",children:cq(u.kind,n)}),i.jsx("div",{className:"af-composer-ai-block-body",children:u.text})]},`${u.kind}-${f}`)),t&&!p?i.jsxs("section",{className:"af-composer-ai-block af-composer-ai-block--reply af-composer-ai-block--pending",children:[i.jsx("div",{className:"af-composer-ai-block-label",children:n("flow:composer.reply")}),i.jsx("div",{className:"af-composer-ai-block-body",children:n("flow:composer.waiting")})]}):null,a?i.jsxs("section",{className:"af-composer-ai-block af-composer-ai-block--error",children:[i.jsx("div",{className:"af-composer-ai-block-label",children:n("flow:composer.error")}),i.jsx("div",{className:"af-composer-ai-block-body",children:a})]}):null]})}function dq({fitViewEpoch:e}){const{fitView:t}=Hl(),n=h.useRef(t);return n.current=t,h.useEffect(()=>{if(e>0){const r=requestAnimationFrame(()=>n.current({padding:.2,duration:200,maxZoom:1}));return()=>cancelAnimationFrame(r)}},[e]),null}function fq({onReady:e}){const t=J0();return h.useEffect(()=>(e(t),()=>e(null)),[e,t]),null}function eC(e){const t=Number.isFinite(e)?e:1;return Math.min(Math.max(t,.75),1)}function tC(e){if(!e||typeof e!="object")return null;const t=Number(e.x),n=Number(e.y),r=Number(e.zoom);return!Number.isFinite(t)||!Number.isFinite(n)||!Number.isFinite(r)?null:{x:t,y:n,zoom:Math.min(Math.max(r,.1),4)}}const Qm=1500,nC=500,pq=262144,hq=2e3;function vw(e){return typeof e!="string"?"":e.length<=hq?e:`[log line truncated, ${e.length} chars]`}const mq=Qm;function gq(e){const t=e.match(/^\[([^\]]+)\]\s+\[([^\]]+)\]\s+([\s\S]*)$/);if(!t)return null;const[,n,r,s]=t;if(r==="cli")try{const o=JSON.parse(s);return o&&o.event==="node-start"?{ts:n,type:"node-start",text:`节点 ${o.instanceId||""}${o.label?` · ${o.label}`:""} 开始`}:o&&o.event==="node-done"?{ts:n,type:"node-done",text:`节点 ${o.instanceId||""} 完成${o.elapsed?` (${o.elapsed})`:""}`}:o&&o.event==="node-failed"?{ts:n,type:"node-failed",text:`节点 ${o.instanceId||""} 失败${o.error?`: ${o.error}`:""}`}:o&&o.event==="apply-start"?{ts:n,type:"info",text:`[apply-start] uuid=${o.uuid||""}`}:{ts:n,type:"info",text:vw(s)}}catch{return{ts:n,type:"info",text:vw(s)}}return{ts:n,type:"log",text:vw(`[${r}] ${s}`)}}function rC(e){if(!e)return[];const t=[],n=e.split(`
@@ -145,7 +145,7 @@ ${n.text}`:n.text:t.push({kind:s,text:n.text})}return t}function cq(e,t){return
145
145
  `);for(let l=0;l<a.length;l+=1){const c=a[l],d=a[l+1];if(o){c==='"'&&d==='"'?(s+='"',l+=1):c==='"'?o=!1:s+=c;continue}c==='"'?o=!0:c===t?(r.push(s.trim()),s=""):c===`
146
146
  `?(r.push(s.trim()),n.push(r),r=[],s=""):s+=c}return(s||r.length)&&(r.push(s.trim()),n.push(r)),n.filter(l=>l.some(c=>String(c||"").trim()))}function Po(e){if(e==null)return"";if(typeof e=="string"||typeof e=="number"||typeof e=="boolean")return String(e);try{return JSON.stringify(e)}catch{return String(e)}}function qq(e){if(Array.isArray(e)){if(e.every(s=>s&&typeof s=="object"&&!Array.isArray(s))){const s=Array.from(new Set(e.flatMap(o=>Object.keys(o))));return{columns:s.map(o=>({key:o,label:o,align:"left"})),rows:e.map(o=>s.map(a=>Po(o[a])))}}if(e.every(Array.isArray)&&e.length>0){const s=e[0].map((o,a)=>Po(o)||`Column ${a+1}`);return{columns:s.map((o,a)=>({key:String(a),label:o,align:"left"})),rows:e.slice(1).map(o=>s.map((a,l)=>Po(o[l])))}}}if(!e||typeof e!="object")return null;const t=Array.isArray(e.columns)?e.columns:Array.isArray(e.headers)?e.headers:[],n=Array.isArray(e.rows)?e.rows:Array.isArray(e.data)?e.data:[];let r=t.map((s,o)=>s&&typeof s=="object"?{key:String(s.key||s.name||s.field||o),label:String(s.label||s.title||s.name||s.key||`Column ${o+1}`),align:["left","center","right"].includes(s.align)?s.align:"left"}:{key:String(o),label:Po(s)||`Column ${o+1}`,align:"left"});return r.length===0&&n.every(s=>s&&typeof s=="object"&&!Array.isArray(s))&&(r=Array.from(new Set(n.flatMap(s=>Object.keys(s)))).map(s=>({key:s,label:s,align:"left"}))),r.length===0&&n.every(Array.isArray)&&n.length>0?(r=n[0].map((s,o)=>({key:String(o),label:Po(s)||`Column ${o+1}`,align:"left"})),{columns:r,rows:n.slice(1).map(s=>r.map((o,a)=>Po(s[a])))}):{columns:r,rows:n.map(s=>Array.isArray(s)?r.map((o,a)=>Po(s[a])):s&&typeof s=="object"?r.map(o=>Po(s[o.key])):r.map((o,a)=>a===0?Po(s):""))}}function Yq(e){const t=String(e||"").trim();if(!t)return{columns:[],rows:[],error:""};const n=t.match(/^```(?:json|table|csv|tsv|markdown|md)?\s*\n?([\s\S]*?)```\s*$/i),r=n?n[1].trim():t;try{const l=qq(JSON.parse(r));if(l&&l.columns.length)return{...l,error:""}}catch{}const s=r.replace(/\r\n/g,`
147
147
  `).split(`
148
- `).filter(l=>l.trim());if(s.length>=2&&va(s[0]).length>1&&qR(s[1])){const l=va(s[0]),c=YR(s[1]);return{columns:l.map((d,p)=>({key:String(p),label:d,align:c[p]||"left"})),rows:s.slice(2).map(d=>va(d)),error:""}}const o=r.includes(" ")?" ":",",a=Uq(r,o);return a.length>0&&a[0].length>1?{columns:a[0].map((c,d)=>c||`Column ${d+1}`).map((c,d)=>({key:String(d),label:c,align:"left"})),rows:a.slice(1),error:""}:{columns:[],rows:[],error:"No table data detected"}}function Nk({content:e}){const t=h.useMemo(()=>Yq(e),[e]);return t.error||t.columns.length===0?i.jsxs("div",{className:"af-work-display-table-empty",children:[i.jsx("strong",{children:"Table data error"}),i.jsx("span",{children:t.error||"No columns found"})]}):i.jsx("div",{className:"af-work-display-table-wrap af-work-display-table-wrap--standalone",children:i.jsxs("table",{className:"af-work-display-table",children:[i.jsx("thead",{children:i.jsx("tr",{children:t.columns.map((n,r)=>i.jsx("th",{style:{textAlign:n.align||"left"},children:n.label},`${n.key}-${r}`))})}),i.jsx("tbody",{children:t.rows.map((n,r)=>i.jsx("tr",{children:t.columns.map((s,o)=>i.jsx("td",{style:{textAlign:s.align||"left"},children:Po(n[o])},`${s.key}-${o}`))},r))})]})})}function jk({content:e}){const t=h.useRef(null),n=h.useMemo(()=>Fq(e),[e]),[r,s]=h.useState({loading:!1,error:""});return h.useEffect(()=>{if(!n.ok){s({loading:!1,error:n.error||"Invalid chart spec"});return}let o=!1,a=null,l=null,c=null;return s({loading:!0,error:""}),Cq(()=>import("./index-DgQRkS4v.js"),[]).then(d=>{o||!t.current||(a=d.init(t.current,"dark",{renderer:"canvas"}),a.setOption(n.spec.option,!0),c=()=>a==null?void 0:a.resize(),typeof ResizeObserver<"u"&&(l=new ResizeObserver(c),l.observe(t.current)),window.addEventListener("resize",c),window.requestAnimationFrame(c),o||s({loading:!1,error:""}))}).catch(d=>{o||s({loading:!1,error:String((d==null?void 0:d.message)||d)})}),()=>{var d,p;o=!0,c&&window.removeEventListener("resize",c),(d=l==null?void 0:l.disconnect)==null||d.call(l),(p=a==null?void 0:a.dispose)==null||p.call(a)}},[n]),!n.ok||r.error?i.jsxs("div",{className:"af-work-display-chart-error",children:[i.jsx("strong",{children:"Chart configuration error"}),i.jsx("span",{children:r.error||n.error})]}):i.jsxs("div",{className:"af-work-display-chart",children:[i.jsx("div",{ref:t,className:"af-work-display-chart__canvas"}),r.loading?i.jsx("div",{className:"af-work-display-chart__loading",children:"Loading chart..."}):null]})}const Gq="af:workspace-graph:v2",cC="agentflow.workspace.sidebarCollapsed",Eu=["DISPLAY","CONTROL","TOOL","PROVIDE","AGENT"],Xq=new Set(["control_start","control_end","control_load_skills","control_load_mcp"]),Jq={id:"workspace_run",displayName:"Run",label:"Run",description:"Run the downstream workspace subgraph connected from this node.",type:"control",inputs:[{type:"node",name:"prev",default:""}],outputs:[{type:"node",name:"next",default:""}]},Qq={id:"workspace_scheduled_run",displayName:"Scheduled Run",label:"Scheduled Run",description:"Run the downstream workspace subgraph on a schedule.",type:"control",inputs:[{type:"node",name:"prev",default:""}],outputs:[{type:"node",name:"next",default:""}]},Zq={id:"control_load_skills",displayName:"Load Skills",label:"Load Skills",description:"Load the currently selected Workspace skill collection for downstream agent nodes.",type:"control",inputs:[{type:"node",name:"prev",default:""},{type:"text",name:"skillKeys",default:"",showOnNode:!1}],outputs:[{type:"node",name:"next",default:""},{type:"text",name:"skillsContext",default:"",showOnNode:!0}]},eY={id:"control_load_mcp",displayName:"Load MCP",label:"Load MCP",description:"Load selected Cursor MCP server tool manifests for downstream agent nodes.",type:"control",inputs:[{type:"node",name:"prev",default:""},{type:"text",name:"serverNames",default:"",showOnNode:!1}],outputs:[{type:"node",name:"next",default:""},{type:"text",name:"mcpContext",default:"",showOnNode:!0}]},tY=new Set(["png","jpg","jpeg","gif","webp","svg"]),QR=320,ZR=180,e2=960,Gg=96,t2=900,bm=52,Fc=240,zc=160,Sv="display-ref:",Hp="0 9 * * *",nY="Asia/Shanghai",rY="0.1.83";function sY(){const e=new URLSearchParams(window.location.search);return{flowId:e.get("flowId")||"",flowSource:e.get("flowSource")||"user",archived:e.get("archived")==="1"||e.get("flowArchived")==="1"}}function Ro(e){const t=new URLSearchParams;return e.flowId&&t.set("flowId",e.flowId),e.flowSource&&t.set("flowSource",e.flowSource),e.archived&&t.set("archived","1"),t}function Xg(e){if(!e)return!1;const t=String(e.type||"");if(t&&/^image\//i.test(t))return!0;const n=String(e.name||"").toLowerCase().split(".").pop();return tY.has(n)}function Jg(e,t,n={}){const r=String(e||"").trim();if(!r)return"";if(/^(?:https?:|data:|blob:|file:)/i.test(r)||r.startsWith("/"))return r;const s=Ro(t||{});return s.set("path",r),n.download&&s.set("download","1"),`/api/workspace/file/raw?${s.toString()}`}function iY(e){const t=String((e==null?void 0:e.flowId)||"").trim();if(!t)return"";const n=String((e==null?void 0:e.flowSource)||"user").trim()||"user";return`af:composer-skills:workspace:${t}:${n}${e!=null&&e.archived?":archived":""}`}function oY(e){const t=String((e==null?void 0:e.username)||(e==null?void 0:e.userId)||"").trim();return t?`${cC}:${t}`:cC}function aY(e){try{const t=window.localStorage.getItem(e);if(t==="false")return!1;if(t==="true")return!0}catch{}return!0}function lY(e){return!e||typeof e.closest!="function"?!1:!!e.closest("input, textarea, select, [contenteditable='true']")}function cY(e){var t;if(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement)return Number(e.selectionStart??0)!==Number(e.selectionEnd??0);if(e instanceof Element&&e.closest('[contenteditable="true"]')){const n=(t=window.getSelection)==null?void 0:t.call(window);return!!(n&&!n.isCollapsed)}return!1}function uY(e){return!e||typeof e.closest!="function"?!1:!!e.closest(".af-flow-node__prompt-stack")&&!cY(e)}function dY(e){const t=String(e||"").trim();if(!t)return"";if(/^运行完成/.test(t))return"运行完成";if(/^运行暂停/.test(t))return"运行暂停";if(/^运行停止/.test(t))return"运行停止";if(/^思考中/.test(t))return"模型正在思考";if(/^生成回复中/.test(t))return"模型正在生成回复";if(/^Timing\s+(.+?):\s+(\d+)ms/i.test(t)){const n=t.match(/^Timing\s+(.+?):\s+(\d+)ms/i);return`耗时:${(n==null?void 0:n[1])||"step"} ${(n==null?void 0:n[2])||"0"}ms`}if(/^工具\s+(.+?)(?:\s+\((started|completed)\))?$/i.test(t)){const n=t.match(/^工具\s+(.+?)(?:\s+\((started|completed)\))?$/i),r=String((n==null?void 0:n[1])||"tool").trim(),s=String((n==null?void 0:n[2])||"").toLowerCase();if(r==="thinking")return"模型正在思考";const o=r==="readToolCall"?"读取文件/上下文":r==="grepToolCall"?"搜索代码":r==="editToolCall"?"编辑文件":r;return s==="completed"?`完成:${o}`:`执行:${o}`}return/^\[stderr\]/.test(t)?t:""}function fY(e){const t=String(e||"").trim();return t?/^模型/.test(t)?"model":/^(执行|完成|耗时):/.test(t)?"tool":/^运行/.test(t)?"run":/^\[stderr\]/.test(t)?"error":"other":"other"}function mc(e){const t=Math.max(0,Number(e)||0);if(t<1e3)return`${t}ms`;if(t<6e4)return`${(t/1e3).toFixed(t<1e4?1:0)}s`;const n=Math.floor(t/6e4),r=Math.round(t%6e4/1e3);return`${n}m${r?`${r}s`:""}`}function pY(e,t){const n=typeof e=="string"?e:String((e==null?void 0:e.text)||""),r=typeof e=="object"?Number(e==null?void 0:e.stepMs):NaN,s=typeof e=="object"?Number(e==null?void 0:e.totalMs):NaN,o=Number.isFinite(r)&&Number.isFinite(s)?`(+${mc(r)} / 总 ${mc(s)})`:"";return`${t+1}. ${n}${o}`}function n2(e){if(String((e==null?void 0:e.type)||"")!=="raw")return null;const t=String((e==null?void 0:e.text)||"").trim();if(!t)return null;try{return JSON.parse(t)}catch{return null}}function _u(...e){for(const t of e){const n=Number(t);if(Number.isFinite(n))return n}return NaN}function hY(e){const t=e!=null&&e.tool_call&&typeof e.tool_call=="object"?e.tool_call:{},n=Object.keys(t).find(r=>/ToolCall$/i.test(r))||"";return n||String((e==null?void 0:e.name)||(e==null?void 0:e.tool)||"tool_call")}function mY(e){const t=e!=null&&e.tool_call&&typeof e.tool_call=="object"?e.tool_call:{},n=Object.keys(t).find(r=>/ToolCall$/i.test(r))||"";return n&&t[n]&&typeof t[n]=="object"?t[n]:{}}function gY(e,t){var s;const n=String(((s=t==null?void 0:t.args)==null?void 0:s.command)||"");return/ck_fetch\.py/.test(n)?"CK 查询":/collect_important_mails\.py|list_mails_by_date\.py|read_mail_content\.py/.test(n)?"邮件脚本":/npm\s+run\s+build|build:web-ui/.test(n)?"前端构建":/python3/.test(n)?"Python 脚本":{shellToolCall:"Shell 命令",readToolCall:"读取文件/上下文",grepToolCall:"搜索代码",globToolCall:"查找文件",editToolCall:"编辑文件",writeToolCall:"写入文件"}[e]||e||"工具调用"}function yY(e){var o,a,l;const t=n2(e);if(!t||typeof t!="object")return null;const n=String(t.type||""),r=String(t.subtype||""),s=_u(t.timestamp_ms,t.completedAtMs,t.startedAtMs,e==null?void 0:e.ts,Date.now());if(n==="tool_call"&&r==="completed"){const c=mY(t),d=hY(t),p=_u(t.startedAtMs,c==null?void 0:c.startedAtMs),u=_u(t.completedAtMs,c==null?void 0:c.completedAtMs),f=((o=c==null?void 0:c.result)==null?void 0:o.success)||((a=c==null?void 0:c.result)==null?void 0:a.failure)||{},m=Number.isFinite(p)&&Number.isFinite(u)?Math.max(0,u-p):_u(f.executionTime,f.localExecutionTimeMs),g=String(((l=c==null?void 0:c.args)==null?void 0:l.command)||f.command||"").trim(),w=g?g.split(`
148
+ `).filter(l=>l.trim());if(s.length>=2&&va(s[0]).length>1&&qR(s[1])){const l=va(s[0]),c=YR(s[1]);return{columns:l.map((d,p)=>({key:String(p),label:d,align:c[p]||"left"})),rows:s.slice(2).map(d=>va(d)),error:""}}const o=r.includes(" ")?" ":",",a=Uq(r,o);return a.length>0&&a[0].length>1?{columns:a[0].map((c,d)=>c||`Column ${d+1}`).map((c,d)=>({key:String(d),label:c,align:"left"})),rows:a.slice(1),error:""}:{columns:[],rows:[],error:"No table data detected"}}function Nk({content:e}){const t=h.useMemo(()=>Yq(e),[e]);return t.error||t.columns.length===0?i.jsxs("div",{className:"af-work-display-table-empty",children:[i.jsx("strong",{children:"Table data error"}),i.jsx("span",{children:t.error||"No columns found"})]}):i.jsx("div",{className:"af-work-display-table-wrap af-work-display-table-wrap--standalone",children:i.jsxs("table",{className:"af-work-display-table",children:[i.jsx("thead",{children:i.jsx("tr",{children:t.columns.map((n,r)=>i.jsx("th",{style:{textAlign:n.align||"left"},children:n.label},`${n.key}-${r}`))})}),i.jsx("tbody",{children:t.rows.map((n,r)=>i.jsx("tr",{children:t.columns.map((s,o)=>i.jsx("td",{style:{textAlign:s.align||"left"},children:Po(n[o])},`${s.key}-${o}`))},r))})]})})}function jk({content:e}){const t=h.useRef(null),n=h.useMemo(()=>Fq(e),[e]),[r,s]=h.useState({loading:!1,error:""});return h.useEffect(()=>{if(!n.ok){s({loading:!1,error:n.error||"Invalid chart spec"});return}let o=!1,a=null,l=null,c=null;return s({loading:!0,error:""}),Cq(()=>import("./index-DgQRkS4v.js"),[]).then(d=>{o||!t.current||(a=d.init(t.current,"dark",{renderer:"canvas"}),a.setOption(n.spec.option,!0),c=()=>a==null?void 0:a.resize(),typeof ResizeObserver<"u"&&(l=new ResizeObserver(c),l.observe(t.current)),window.addEventListener("resize",c),window.requestAnimationFrame(c),o||s({loading:!1,error:""}))}).catch(d=>{o||s({loading:!1,error:String((d==null?void 0:d.message)||d)})}),()=>{var d,p;o=!0,c&&window.removeEventListener("resize",c),(d=l==null?void 0:l.disconnect)==null||d.call(l),(p=a==null?void 0:a.dispose)==null||p.call(a)}},[n]),!n.ok||r.error?i.jsxs("div",{className:"af-work-display-chart-error",children:[i.jsx("strong",{children:"Chart configuration error"}),i.jsx("span",{children:r.error||n.error})]}):i.jsxs("div",{className:"af-work-display-chart",children:[i.jsx("div",{ref:t,className:"af-work-display-chart__canvas"}),r.loading?i.jsx("div",{className:"af-work-display-chart__loading",children:"Loading chart..."}):null]})}const Gq="af:workspace-graph:v2",cC="agentflow.workspace.sidebarCollapsed",Eu=["DISPLAY","CONTROL","TOOL","PROVIDE","AGENT"],Xq=new Set(["control_start","control_end","control_load_skills","control_load_mcp"]),Jq={id:"workspace_run",displayName:"Run",label:"Run",description:"Run the downstream workspace subgraph connected from this node.",type:"control",inputs:[{type:"node",name:"prev",default:""}],outputs:[{type:"node",name:"next",default:""}]},Qq={id:"workspace_scheduled_run",displayName:"Scheduled Run",label:"Scheduled Run",description:"Run the downstream workspace subgraph on a schedule.",type:"control",inputs:[{type:"node",name:"prev",default:""}],outputs:[{type:"node",name:"next",default:""}]},Zq={id:"control_load_skills",displayName:"Load Skills",label:"Load Skills",description:"Load the currently selected Workspace skill collection for downstream agent nodes.",type:"control",inputs:[{type:"node",name:"prev",default:""},{type:"text",name:"skillKeys",default:"",showOnNode:!1}],outputs:[{type:"node",name:"next",default:""},{type:"text",name:"skillsContext",default:"",showOnNode:!0}]},eY={id:"control_load_mcp",displayName:"Load MCP",label:"Load MCP",description:"Load selected Cursor MCP server tool manifests for downstream agent nodes.",type:"control",inputs:[{type:"node",name:"prev",default:""},{type:"text",name:"serverNames",default:"",showOnNode:!1}],outputs:[{type:"node",name:"next",default:""},{type:"text",name:"mcpContext",default:"",showOnNode:!0}]},tY=new Set(["png","jpg","jpeg","gif","webp","svg"]),QR=320,ZR=180,e2=960,Gg=96,t2=900,bm=52,Fc=240,zc=160,Sv="display-ref:",Hp="0 9 * * *",nY="Asia/Shanghai",rY="0.1.84";function sY(){const e=new URLSearchParams(window.location.search);return{flowId:e.get("flowId")||"",flowSource:e.get("flowSource")||"user",archived:e.get("archived")==="1"||e.get("flowArchived")==="1"}}function Ro(e){const t=new URLSearchParams;return e.flowId&&t.set("flowId",e.flowId),e.flowSource&&t.set("flowSource",e.flowSource),e.archived&&t.set("archived","1"),t}function Xg(e){if(!e)return!1;const t=String(e.type||"");if(t&&/^image\//i.test(t))return!0;const n=String(e.name||"").toLowerCase().split(".").pop();return tY.has(n)}function Jg(e,t,n={}){const r=String(e||"").trim();if(!r)return"";if(/^(?:https?:|data:|blob:|file:)/i.test(r)||r.startsWith("/"))return r;const s=Ro(t||{});return s.set("path",r),n.download&&s.set("download","1"),`/api/workspace/file/raw?${s.toString()}`}function iY(e){const t=String((e==null?void 0:e.flowId)||"").trim();if(!t)return"";const n=String((e==null?void 0:e.flowSource)||"user").trim()||"user";return`af:composer-skills:workspace:${t}:${n}${e!=null&&e.archived?":archived":""}`}function oY(e){const t=String((e==null?void 0:e.username)||(e==null?void 0:e.userId)||"").trim();return t?`${cC}:${t}`:cC}function aY(e){try{const t=window.localStorage.getItem(e);if(t==="false")return!1;if(t==="true")return!0}catch{}return!0}function lY(e){return!e||typeof e.closest!="function"?!1:!!e.closest("input, textarea, select, [contenteditable='true']")}function cY(e){var t;if(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement)return Number(e.selectionStart??0)!==Number(e.selectionEnd??0);if(e instanceof Element&&e.closest('[contenteditable="true"]')){const n=(t=window.getSelection)==null?void 0:t.call(window);return!!(n&&!n.isCollapsed)}return!1}function uY(e){return!e||typeof e.closest!="function"?!1:!!e.closest(".af-flow-node__prompt-stack")&&!cY(e)}function dY(e){const t=String(e||"").trim();if(!t)return"";if(/^运行完成/.test(t))return"运行完成";if(/^运行暂停/.test(t))return"运行暂停";if(/^运行停止/.test(t))return"运行停止";if(/^思考中/.test(t))return"模型正在思考";if(/^生成回复中/.test(t))return"模型正在生成回复";if(/^Timing\s+(.+?):\s+(\d+)ms/i.test(t)){const n=t.match(/^Timing\s+(.+?):\s+(\d+)ms/i);return`耗时:${(n==null?void 0:n[1])||"step"} ${(n==null?void 0:n[2])||"0"}ms`}if(/^工具\s+(.+?)(?:\s+\((started|completed)\))?$/i.test(t)){const n=t.match(/^工具\s+(.+?)(?:\s+\((started|completed)\))?$/i),r=String((n==null?void 0:n[1])||"tool").trim(),s=String((n==null?void 0:n[2])||"").toLowerCase();if(r==="thinking")return"模型正在思考";const o=r==="readToolCall"?"读取文件/上下文":r==="grepToolCall"?"搜索代码":r==="editToolCall"?"编辑文件":r;return s==="completed"?`完成:${o}`:`执行:${o}`}return/^\[stderr\]/.test(t)?t:""}function fY(e){const t=String(e||"").trim();return t?/^模型/.test(t)?"model":/^(执行|完成|耗时):/.test(t)?"tool":/^运行/.test(t)?"run":/^\[stderr\]/.test(t)?"error":"other":"other"}function mc(e){const t=Math.max(0,Number(e)||0);if(t<1e3)return`${t}ms`;if(t<6e4)return`${(t/1e3).toFixed(t<1e4?1:0)}s`;const n=Math.floor(t/6e4),r=Math.round(t%6e4/1e3);return`${n}m${r?`${r}s`:""}`}function pY(e,t){const n=typeof e=="string"?e:String((e==null?void 0:e.text)||""),r=typeof e=="object"?Number(e==null?void 0:e.stepMs):NaN,s=typeof e=="object"?Number(e==null?void 0:e.totalMs):NaN,o=Number.isFinite(r)&&Number.isFinite(s)?`(+${mc(r)} / 总 ${mc(s)})`:"";return`${t+1}. ${n}${o}`}function n2(e){if(String((e==null?void 0:e.type)||"")!=="raw")return null;const t=String((e==null?void 0:e.text)||"").trim();if(!t)return null;try{return JSON.parse(t)}catch{return null}}function _u(...e){for(const t of e){const n=Number(t);if(Number.isFinite(n))return n}return NaN}function hY(e){const t=e!=null&&e.tool_call&&typeof e.tool_call=="object"?e.tool_call:{},n=Object.keys(t).find(r=>/ToolCall$/i.test(r))||"";return n||String((e==null?void 0:e.name)||(e==null?void 0:e.tool)||"tool_call")}function mY(e){const t=e!=null&&e.tool_call&&typeof e.tool_call=="object"?e.tool_call:{},n=Object.keys(t).find(r=>/ToolCall$/i.test(r))||"";return n&&t[n]&&typeof t[n]=="object"?t[n]:{}}function gY(e,t){var s;const n=String(((s=t==null?void 0:t.args)==null?void 0:s.command)||"");return/ck_fetch\.py/.test(n)?"CK 查询":/collect_important_mails\.py|list_mails_by_date\.py|read_mail_content\.py/.test(n)?"邮件脚本":/npm\s+run\s+build|build:web-ui/.test(n)?"前端构建":/python3/.test(n)?"Python 脚本":{shellToolCall:"Shell 命令",readToolCall:"读取文件/上下文",grepToolCall:"搜索代码",globToolCall:"查找文件",editToolCall:"编辑文件",writeToolCall:"写入文件"}[e]||e||"工具调用"}function yY(e){var o,a,l;const t=n2(e);if(!t||typeof t!="object")return null;const n=String(t.type||""),r=String(t.subtype||""),s=_u(t.timestamp_ms,t.completedAtMs,t.startedAtMs,e==null?void 0:e.ts,Date.now());if(n==="tool_call"&&r==="completed"){const c=mY(t),d=hY(t),p=_u(t.startedAtMs,c==null?void 0:c.startedAtMs),u=_u(t.completedAtMs,c==null?void 0:c.completedAtMs),f=((o=c==null?void 0:c.result)==null?void 0:o.success)||((a=c==null?void 0:c.result)==null?void 0:a.failure)||{},m=Number.isFinite(p)&&Number.isFinite(u)?Math.max(0,u-p):_u(f.executionTime,f.localExecutionTimeMs),g=String(((l=c==null?void 0:c.args)==null?void 0:l.command)||f.command||"").trim(),w=g?g.split(`
149
149
  `).find(Boolean)||g:"";return{kind:"tool",label:gY(d,c),durationMs:Number.isFinite(m)?m:null,at:s,detail:w?w.slice(0,90):""}}if(n==="result"){const c=_u(t.duration_ms,t.duration_api_ms);return{kind:"total",label:"运行总耗时",durationMs:Number.isFinite(c)?c:null,at:s,detail:t.is_error?"失败结束":"成功结束"}}return n==="connection"?{kind:"network",label:r==="reconnecting"?"连接重连":r==="reconnected"?"连接恢复":"连接事件",durationMs:null,at:s,detail:""}:n==="retry"?{kind:"network",label:r==="resuming"?"会话恢复":r==="starting"?"开始重试":"重试事件",durationMs:null,at:s,detail:""}:null}function uC(e,t,n,r){const s=(Array.isArray(e)?e:[]).map(k=>typeof k=="string"?{text:k}:k).filter(k=>k&&String(k.text||"").trim()),o=Array.isArray(t)?t:[],a=[...o].reverse().find(k=>(k==null?void 0:k.kind)==="total"&&Number.isFinite(Number(k.durationMs))),l=[...s].reverse().find(k=>Number.isFinite(Number(k.totalMs))),c=Number.isFinite(Number(r))&&Number.isFinite(Number(n))?Math.max(0,Number(r)-Number(n)):NaN,d=_u(a==null?void 0:a.durationMs,l==null?void 0:l.totalMs,c),p=s.filter(k=>k.kind==="model").reduce((k,y)=>k+(Number(y.stepMs)||0),0),u=o.filter(k=>(k==null?void 0:k.kind)==="tool"),f=u.reduce((k,y)=>k+(Number(y.durationMs)||0),0),m=o.filter(k=>(k==null?void 0:k.kind)==="network").length,g=[...s.filter(k=>Number(k.stepMs)>=1e3).map(k=>({label:k.text,durationMs:Number(k.stepMs),detail:"Activity 间隔"})),...u.filter(k=>Number(k.durationMs)>=1e3).map(k=>({label:k.label,durationMs:Number(k.durationMs),detail:k.detail||"工具实际执行"}))].sort((k,y)=>y.durationMs-k.durationMs).slice(0,6),w=["耗时概览"];return Number.isFinite(d)&&w.push(`- 当前总耗时:${mc(d)}`),p>0&&w.push(`- 模型相关间隔:约 ${mc(p)}(按 Activity 间隔估算)`),u.length>0&&w.push(`- 工具实际执行:${mc(f)}(${u.length} 次完成事件)`),m>0&&w.push(`- 网络/会话恢复事件:${m} 次`),g.length>0&&(w.push(""),w.push("慢步骤"),g.forEach((k,y)=>{const b=k.detail?` · ${k.detail}`:"";w.push(`${y+1}. ${k.label}:${mc(k.durationMs)}${b}`)})),s.length>0&&(w.push(""),w.push("最近 Activity"),s.slice(-10).forEach((k,y)=>{w.push(pY(k,y))})),u.length>0&&(w.push(""),w.push("最近工具完成"),u.slice(-8).forEach((k,y)=>{const b=Number.isFinite(Number(k.durationMs))?` ${mc(k.durationMs)}`:"",x=k.detail?` · ${k.detail}`:"";w.push(`${y+1}. ${k.label}${b}${x}`)})),w.join(`
150
150
  `)}function dC(e){if(String((e==null?void 0:e.type)||"")!=="raw"||String((e==null?void 0:e.eventType)||"")!=="thinking")return"";const t=n2(e);if((t==null?void 0:t.type)!=="thinking")return"";const n=String((t==null?void 0:t.subtype)||"");return n&&n!=="delta"?"":String((t==null?void 0:t.text)||(t==null?void 0:t.delta)||(t==null?void 0:t.thinking)||"").trim()}function r2(e,t){const n=String(e||(t==null?void 0:t.id)||"").toLowerCase();return n.startsWith("control_")?"control":n.startsWith("provide_")?"provide":n.startsWith("tool_")?"agent":(t==null?void 0:t.type)||"agent"}function s2(e){const t=String((e==null?void 0:e.marketplaceDefinitionId)||(e==null?void 0:e.id)||"").trim();return t.startsWith("marketplace:")?t:""}function Ck(e){if(!e)return"";const t=String(e.baseDefinitionId||"").trim();return t||String(e.id||"").trim()}function i2(e){const t=String(e??"");return/^[A-Za-z0-9_@%+=:,./-]+$/.test(t)?t:"'"+t.replace(/'/g,"'\\''")+"'"}function xY(e,t){const n=String((e==null?void 0:e.language)||"").trim().toLowerCase(),r=String(t||"").trim().toLowerCase();return n.includes("python")||r.endsWith(".py")?"python3":n.includes("shell")||n==="bash"||r.endsWith(".sh")||r.endsWith(".bash")?"bash":"node"}function wY(e){const t=String(e??"").trim();return t?t.includes("${")?t:i2(t):""}function o2(e){if(String((e==null?void 0:e.baseDefinitionId)||"").trim()!=="tool_nodejs")return"";const t=e!=null&&e.runtime&&typeof e.runtime=="object"?e.runtime:{},n=String(t.entry||"").trim().replace(/^\/+/,"");if(n){const s=String((e==null?void 0:e.packageDir)||"").trim().replace(/\/+$/,""),o=s?`${s}/${n}`:`\${flowDir}/${n}`,a=Array.isArray(t.args)?t.args.map(wY).filter(Boolean):[];return[xY(t,n),i2(o),...a].join(" ")}return String(t.command||"").trim()}function Of(e){const t=String(Ck(e)||(e==null?void 0:e.id)||"");return t==="workspace_run"||t==="workspace_scheduled_run"?"CONTROL":t.startsWith("display_")?"DISPLAY":/^control/i.test(t)?"CONTROL":/^tool/i.test(t)?"TOOL":/^provide/i.test(t)?"PROVIDE":"AGENT"}function fC(e){return e==="DISPLAY"?"preview":e==="CONTROL"?"account_tree":e==="TOOL"?"build":e==="PROVIDE"?"database":"smart_toy"}function Qg(e){return String((e==null?void 0:e.displayName)||(e==null?void 0:e.label)||(e==null?void 0:e.id)||"Node")}function $f(e){return Qg(e)}function Nv(e){return String((e==null?void 0:e.description)||(e==null?void 0:e.body)||"").replace(/\s+/g," ").trim()}function vm(e,t){const n=String((e==null?void 0:e.name)||(e==null?void 0:e.id)||"").trim(),r=String((e==null?void 0:e.type)||"").trim();return n||r||`#${t+1}`}function pC(e,t,n){const r=String((t==null?void 0:t.name)||(t==null?void 0:t.id)||`#${n+1}`).trim(),s=String((t==null?void 0:t.type)||"").trim(),o=String((t==null?void 0:t.default)??(t==null?void 0:t.value)??"").trim();return[e,r,s?`type: ${s}`:"",o?`default: ${o}`:""].filter(Boolean).join(" · ")}function hC(e,t){const n=Array.isArray(e)?e:[],r=n.slice(0,4),s=Math.max(0,n.length-r.length);return{list:n,shown:r,hidden:s,kind:t}}function kw(e,t){const n=String((e==null?void 0:e.source)||""),r=String((e==null?void 0:e.target)||"");if(!n||!r)return!1;const s=new Map(t.map(l=>[l.id,l])),o=jd(s.get(n),e.sourceHandle||"output-0","source"),a=jd(s.get(r),e.targetHandle||"input-0","target");return!!(o&&a&&Ml(o,a))}function bY(e,t){const n=String((e==null?void 0:e.nodeId)||""),r=String((e==null?void 0:e.handleId)||""),s=(e==null?void 0:e.handleType)==="target"?"target":(e==null?void 0:e.handleType)==="source"?"source":"";if(!n||!r||!s)return null;const o=t.find(l=>l.id===n),a=jd(o,r,s);return a?{nodeId:n,handleId:r,handleType:s,slot:a,slotType:CR(a)}:null}function vY(e,t){return t?e.map((n,r)=>{const s=Array.isArray(t.handleType==="source"?n.inputs:n.outputs)?t.handleType==="source"?n.inputs:n.outputs:[];for(let o=0;o<s.length;o+=1){const a=s[o];if(!(t.handleType==="source"?Ml(t.slot,a):Ml(a,t.slot)))continue;const c=Of(n);return{def:n,order:r,category:c,categoryRank:Eu.indexOf(c),slot:a,slotIndex:o,displayLabel:$f(n),description:Nv(n)}}return null}).filter(Boolean).sort((n,r)=>{var a,l;const s=(a=n.slot)!=null&&a.required?0:1,o=(l=r.slot)!=null&&l.required?0:1;return s-o||n.slotIndex-r.slotIndex||n.categoryRank-r.categoryRank||n.order-r.order}):[]}function kY(e,t,n){var o,a,l,c;if(!n)return[];const r=[],s=n.handleType==="source";for(const d of e||[]){if(!d||d.id===n.nodeId)continue;const p=Array.isArray(s?(o=d.data)==null?void 0:o.inputs:(a=d.data)==null?void 0:a.outputs)?s?d.data.inputs:d.data.outputs:[];for(let u=0;u<p.length;u+=1){const f=p[u];if((f==null?void 0:f.showOnNode)===!1||!(s?Ml(n.slot,f):Ml(f,n.slot)))continue;const g=s?{source:n.nodeId,sourceHandle:n.handleId,target:d.id,targetHandle:`input-${u}`}:{source:d.id,sourceHandle:`output-${u}`,target:n.nodeId,targetHandle:n.handleId},w=(t||[]).some(k=>k.target===g.target&&k.targetHandle===g.targetHandle);r.push({node:d,nodeId:d.id,nodeLabel:((l=d.data)==null?void 0:l.label)||d.id,definitionId:((c=d.data)==null?void 0:c.definitionId)||"",slot:f,slotIndex:u,handleId:s?g.targetHandle:g.sourceHandle,connection:g,occupied:w})}}return r.sort((d,p)=>{var w,k,y,b,x,j,E,N;const u=Number(((k=(w=d.node)==null?void 0:w.position)==null?void 0:k.y)||0),f=Number(((b=(y=p.node)==null?void 0:y.position)==null?void 0:b.y)||0),m=Number(((j=(x=d.node)==null?void 0:x.position)==null?void 0:j.x)||0),g=Number(((N=(E=p.node)==null?void 0:E.position)==null?void 0:N.x)||0);return u-f||m-g||d.slotIndex-p.slotIndex||String(d.nodeId).localeCompare(String(p.nodeId))})}function qu(e,t=!1){if(t)return"folder";const n=String(e||"").toLowerCase().split(".").pop();return n==="md"||n==="markdown"?"article":n==="html"?"web":["csv","tsv"].includes(n)?"table":["js","jsx","ts","tsx","mjs","cjs"].includes(n)?"code":["yaml","yml","json"].includes(n)?"data_object":"draft"}function SY(e,t){const n=String(e||"node").replace(/^(agent|control|provide|tool|display)_/i,"").replace(/[^a-zA-Z0-9_]+/g,"_").replace(/^_+|_+$/g,"")||"node",r=new Set(t.map(s=>s.id));for(let s=1;s<1e4;s++){const o=`${n}_${s}`;if(!r.has(o))return o}return`${n}_${Date.now().toString(36)}`}function NY(e){return(e==null?void 0:e.default)!=null?String(e.default):(e==null?void 0:e.value)!=null?String(e.value):""}function jY(e){const t=Number(e);if(!Number.isFinite(t)||t<=0)return Hp;const n=Math.max(1,Math.min(1440,Math.round(t)));return n<60?`*/${n} * * * *`:n===60?"0 * * * *":n<1440&&n%60===0?`0 */${n/60} * * *`:Hp}function ml(e,t=0,n=0,r=59){const s=Math.max(n,Math.min(r,Number.parseInt(String(e??t),10)||t));return String(s).padStart(2,"0")}function Ek(e){const t=String(e||"").trim().match(/^(\d{1,2}):(\d{1,2})$/);return t?`${ml(t[1],9,0,23)}:${ml(t[2],0,0,59)}`:"09:00"}function Df(e,t,n,r,s){const o=Ek(t),[a,l]=o.split(":").map(d=>Number.parseInt(d,10)),c=String(e||"daily");if(c==="weekly"){const d=Math.max(0,Math.min(6,Number.parseInt(String(n??1),10)||1));return`${l} ${a} * * ${d}`}if(c==="monthly"){const d=Math.max(1,Math.min(31,Number.parseInt(String(r??1),10)||1));return`${l} ${a} ${d} * *`}return c==="custom"?String(s||"").trim()||Hp:`${l} ${a} * * *`}function CY(e){const n=String(e||Hp).trim().split(/\s+/);if(n.length!==5)return{scheduleType:"custom",time:"09:00",weekday:1,monthDay:1};const[r,s,o,a,l]=n,c=Number.parseInt(r,10),d=Number.parseInt(s,10),p=Number.isFinite(c)&&Number.isFinite(d)&&r===String(c)&&s===String(d),u=p?`${ml(d,9,0,23)}:${ml(c,0,0,59)}`:"09:00";return p&&o==="*"&&a==="*"&&l==="*"?{scheduleType:"daily",time:u,weekday:1,monthDay:1}:p&&o==="*"&&a==="*"&&/^\d+$/.test(l)?{scheduleType:"weekly",time:u,weekday:Math.max(0,Math.min(6,Number.parseInt(l,10))),monthDay:1}:p&&/^\d+$/.test(o)&&a==="*"&&l==="*"?{scheduleType:"monthly",time:u,weekday:1,monthDay:Math.max(1,Math.min(31,Number.parseInt(o,10)))}:{scheduleType:"custom",time:u,weekday:1,monthDay:1}}function _k(e){let t={};const n=String(e||"").trim();if(n)try{t=JSON.parse(n)}catch{t={}}const r=Number(t.intervalMinutes),s=jY(r),o=typeof t.cron=="string"&&t.cron.trim()?t.cron.trim():s,a=CY(o),l=["daily","weekly","monthly","custom"].includes(t.scheduleType)?t.scheduleType:a.scheduleType,c=Ek(t.time||a.time||"09:00"),d=Math.max(0,Math.min(6,Number.parseInt(String(t.weekday??a.weekday??1),10)||1)),p=Math.max(1,Math.min(31,Number.parseInt(String(t.monthDay??a.monthDay??1),10)||1)),u=Df(l,c,d,p,o);return{enabled:t.enabled===!0,scheduleType:l,time:c,weekday:d,monthDay:p,cron:u,timezone:nY,targetRunNodeId:typeof t.targetRunNodeId=="string"?t.targetRunNodeId.trim():"",overlapPolicy:"skip"}}function EY(e){const t=_k(JSON.stringify(e||{}));return JSON.stringify(t)}function _Y(e){const t=Number(e||0);return!Number.isFinite(t)||t<=0?"-":new Date(t).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}function AY(e){return e==="weekly"?"每周":e==="monthly"?"每月":e==="custom"?"高级 Cron":"每天"}function mC(e){if(typeof e=="number"&&Number.isFinite(e))return e;if(typeof e=="string"&&e.trim()){const t=Date.parse(e);if(Number.isFinite(t))return t}return 0}function Sw(e){const t={};for(const n of Array.isArray(e)?e:[]){const r=String((n==null?void 0:n.scheduleNodeId)||(n==null?void 0:n.runNodeId)||"").trim();r&&(t[r]={nextAt:mC(n.nextRunAt),lastAt:mC(n.lastTriggeredAt),lastStatus:String(n.lastStatus||(n.enabled?"armed":"disabled")),lastError:String(n.lastError||""),lastRunId:String(n.lastRunId||""),targetRunNodeId:String(n.targetRunNodeId||n.runNodeId||""),cron:String(n.cron||""),timezone:String(n.timezone||"")})}return t}function ip(e){var t;return!!((t=e==null?void 0:e.data)!=null&&t.isWorkspaceGroup)}function Zg(e){return e>0?`Group ${e+1}`:"Group"}function PY(e){return(Array.isArray(e)?e:[]).map((n,r)=>{const s=String((n==null?void 0:n.id)||`group_${r+1}`).trim(),o=Number(n==null?void 0:n.x),a=Number(n==null?void 0:n.y),l=Number(n==null?void 0:n.width),c=Number(n==null?void 0:n.height);return!s||!Number.isFinite(o)||!Number.isFinite(a)||!Number.isFinite(l)||!Number.isFinite(c)?null:{id:s,title:String((n==null?void 0:n.title)||Zg(r)).trim()||Zg(r),color:String((n==null?void 0:n.color)||"purple").trim()||"purple",x:o,y:a,width:Math.max(Fc,Math.round(l)),height:Math.max(zc,Math.round(c))}}).filter(Boolean)}function IY(e){var n;return PY((n=e==null?void 0:e.ui)==null?void 0:n.groups).map(r=>({id:r.id,type:$c,position:{x:r.x,y:r.y},width:r.width,height:r.height,selected:!1,draggable:!0,selectable:!0,zIndex:0,data:{isWorkspaceGroup:!0,label:r.title,title:r.title,color:r.color,nodeSize:{width:r.width,height:r.height}}}))}function jv(e){const t=Number(e==null?void 0:e.width),n=Number(e==null?void 0:e.height);return!Number.isFinite(t)||!Number.isFinite(n)?null:{width:Math.max(Fc,Math.round(t)),height:Math.max(zc,Math.round(n))}}function km(e){return(Array.isArray(e)?e:[]).map(t=>({type:(t==null?void 0:t.type)||"node",name:(t==null?void 0:t.name)||"",default:NY(t),required:!!(t!=null&&t.required),description:String((t==null?void 0:t.description)||""),showOnNode:(t==null?void 0:t.showOnNode)!=null?t.showOnNode!==!1:!!(t!=null&&t.required)||String((t==null?void 0:t.type)||"node").trim().toLowerCase()==="node"}))}function a2(e){const t=(e==null?void 0:e.data)||{},n=r=>(Array.isArray(r)?r:[]).map((s,o)=>(s==null?void 0:s.showOnNode)===!1?"":[o,String((s==null?void 0:s.type)||""),String((s==null?void 0:s.name)||""),s!=null&&s.required?"1":"0"].join(":")).filter(Boolean).join("|");return`${n(t.inputs)}=>${n(t.outputs)}`}function TY(e){var s,o,a,l;const t=(e==null?void 0:e.data)||{},n=t!=null&&t.displaySize&&typeof t.displaySize=="object"?t.displaySize:{},r=t!=null&&t.nodeSize&&typeof t.nodeSize=="object"?t.nodeSize:{};return[a2(e),Number((e==null?void 0:e.width)||0)||"",Number((e==null?void 0:e.height)||0)||"",Number(((s=e==null?void 0:e.measured)==null?void 0:s.width)||0)||"",Number(((o=e==null?void 0:e.measured)==null?void 0:o.height)||0)||"",Number(r.width||0)||"",Number(r.height||0)||"",Number(n.width||0)||"",Number(n.height||0)||"",t!=null&&t.isExecuting?"executing":"",(t==null?void 0:t.nodeStatus)||"",(l=(a=t==null?void 0:t.runningRunNodeIds)==null?void 0:a.has)!=null&&l.call(a,e==null?void 0:e.id)?"running-run":""].join("::")}function Nw(e,t){var m,g;const n=e!=null&&e.instances&&typeof e.instances=="object"?e.instances:{},r=c2(n),s=Array.isArray(e==null?void 0:e.edges)?e.edges:[],o=(m=e==null?void 0:e.ui)!=null&&m.nodePositions&&typeof e.ui.nodePositions=="object"?e.ui.nodePositions:{},a=(g=e==null?void 0:e.ui)!=null&&g.nodeSizes&&typeof e.ui.nodeSizes=="object"?e.ui.nodeSizes:{},l=new Set(Object.keys(r));for(const w of s)w!=null&&w.source&&l.add(String(w.source)),w!=null&&w.target&&l.add(String(w.target));const d=Array.from(l).map(w=>{const k=r[w]||{},y=k.definitionId||w,b=t.find(B=>B.id===y),x=Ck(b)||y,j=t.find(B=>B.id===x)||b,E=k.marketplaceRef||s2(b),N=o2(b),T=o[w]&&typeof o[w].x=="number"&&typeof o[w].y=="number"?o[w]:{x:320+l.size*20,y:180+l.size*12},$=!!$n(x),z=a[w]&&typeof a[w].width=="number"&&typeof a[w].height=="number"?{width:a[w].width,height:a[w].height}:null,K=od(z,{display:$});return{id:w,type:$c,position:T,...K?{width:K.width,height:K.height}:{},data:{label:k.label||Qg(b)||Qg(j)||w,definitionId:x,...E?{marketplaceRef:E}:{},...b!=null&&b.packageId?{marketplacePackageId:b.packageId}:{},...b!=null&&b.version?{marketplaceVersion:b.version}:{},schemaType:r2(x,j||b),role:k.role||"normal",model:k.model||void 0,body:k.body||"",script:k.script||N||"",scriptRef:k.scriptRef||"",implementationRef:k.implementationRef||"",implementationMode:k.implementationMode||"",displayReloadKey:k.displayReloadKey||"",...K?{nodeSize:K}:{},...$&&K?{displaySize:K}:{}}}}).map(w=>zp(w,r,t)),p=IY(e),u=s.filter(w=>(w==null?void 0:w.source)&&(w==null?void 0:w.target)).filter(w=>!p.some(k=>k.id===String(w.source)||k.id===String(w.target))).map((w,k)=>({id:w.id||`we-${w.source}-${w.target}-${k}`,source:String(w.source),target:String(w.target),sourceHandle:w.sourceHandle??void 0,targetHandle:w.targetHandle??void 0,markerEnd:{type:js.ArrowClosed}})),f=[...p,...d];return{nodes:f,edges:NR(u,f),instances:r}}function gC(e){return`${Sv}${e}`}function jw(e){const t=String(e||"");return t.startsWith(Sv)?t.slice(Sv.length):t}function l2(e){if(!e||typeof e!="object")return null;const t=Number(e.x),n=Number(e.y),r=Number(e.zoom);return!Number.isFinite(t)||!Number.isFinite(n)||!Number.isFinite(r)?null:{x:t,y:n,zoom:Math.min(Math.max(r,.1),4)}}function Cv(e,t=[]){const n=new Map((Array.isArray(t)?t:[]).filter(u=>{var f;return $n((f=u==null?void 0:u.data)==null?void 0:f.definitionId)}).map(u=>[u.id,u])),r=Array.isArray(e==null?void 0:e.nodeIds)?e.nodeIds:[],s=[],o=new Set;for(const u of r){const f=String(u||"").trim();!f||o.has(f)||!n.has(f)||(o.add(f),s.push(f))}const a={},l=e!=null&&e.nodePositions&&typeof e.nodePositions=="object"?e.nodePositions:{};s.forEach((u,f)=>{const m=l[u];a[u]=m&&typeof m.x=="number"&&typeof m.y=="number"?{x:m.x,y:m.y}:{x:180+f*36,y:120+f*28}});const c={},d=e!=null&&e.nodeSizes&&typeof e.nodeSizes=="object"?e.nodeSizes:{};s.forEach(u=>{const f=od(d[u],{display:!0});f&&(c[u]=f)});const p=l2(e==null?void 0:e.viewport);return{nodeIds:s,nodePositions:a,nodeSizes:c,...p?{viewport:p}:{}}}function RY(e,t=[]){return Cv(e,t)}function MY(e){const t=Number.isFinite(e)?e:1;return Math.min(Math.max(t,.75),1)}async function LY(e){var n;const t=String(e||"");if(!t)return!1;try{if((n=navigator.clipboard)!=null&&n.writeText)return await navigator.clipboard.writeText(t),!0}catch{}try{const r=document.createElement("textarea");r.value=t,r.setAttribute("readonly",""),r.style.position="fixed",r.style.left="-9999px",r.style.top="0",document.body.appendChild(r),r.focus(),r.select();const s=document.execCommand("copy");return document.body.removeChild(r),s}catch{return!1}}function yC(e,t,n){const r=Number(e);return!Number.isFinite(r)||r<=0?0:Math.min(n,Math.max(t,Math.round(r)))}function od(e,{display:t=!1}={}){if(!e||typeof e!="object")return null;const n=Number(e.width),r=Number(e.height);return!Number.isFinite(n)||!Number.isFinite(r)||n<=0||r<=0?null:t?{width:Math.round(n),height:Math.round(r)}:{width:yC(n,ZR,e2)||QR,height:yC(r,Gg,t2)||Gg}}function Au(e){var s,o,a,l,c,d,p,u,f,m,g;const t=!!$n((s=e==null?void 0:e.data)==null?void 0:s.definitionId),n=Number(((a=(o=e==null?void 0:e.data)==null?void 0:o.displaySize)==null?void 0:a.width)||((c=(l=e==null?void 0:e.data)==null?void 0:l.nodeSize)==null?void 0:c.width)||(e==null?void 0:e.width)||(t?(d=e==null?void 0:e.measured)==null?void 0:d.width:0)||0),r=Number(((u=(p=e==null?void 0:e.data)==null?void 0:p.displaySize)==null?void 0:u.height)||((m=(f=e==null?void 0:e.data)==null?void 0:f.nodeSize)==null?void 0:m.height)||(e==null?void 0:e.height)||(t?(g=e==null?void 0:e.measured)==null?void 0:g.height:0)||0);return od({width:n,height:r},{display:t})}function Sm(e,t,n){var p,u,f,m,g,w,k,y,b,x,j,E,N;const r=(e||[]).filter(T=>!ip(T)),s=(e||[]).filter(ip),o=c2(lh(r,n||{})),a=t.map(T=>({source:T.source,target:T.target,sourceHandle:T.sourceHandle??null,targetHandle:T.targetHandle??null})).filter(T=>!s.some($=>$.id===T.source||$.id===T.target)),l={},c={},d=[];for(const T of r){l[T.id]={x:((p=T.position)==null?void 0:p.x)||0,y:((u=T.position)==null?void 0:u.y)||0};const $=Au(T);$&&(c[T.id]=$)}for(const T of s){const $=Number(((m=(f=T.data)==null?void 0:f.nodeSize)==null?void 0:m.width)||T.width||((g=T.measured)==null?void 0:g.width)||0),z=Number(((k=(w=T.data)==null?void 0:w.nodeSize)==null?void 0:k.height)||T.height||((y=T.measured)==null?void 0:y.height)||0);d.push({id:T.id,title:String(((b=T.data)==null?void 0:b.title)||((x=T.data)==null?void 0:x.label)||"Group"),color:String(((j=T.data)==null?void 0:j.color)||"purple"),x:Number(((E=T.position)==null?void 0:E.x)||0),y:Number(((N=T.position)==null?void 0:N.y)||0),width:Math.max(Fc,Math.round($||Fc)),height:Math.max(zc,Math.round(z||zc))})}return{version:1,instances:o,edges:a,ui:{nodePositions:l,nodeSizes:c,groups:d}}}function c2(e){const t={};for(const[n,r]of Object.entries(e||{})){const s=String((r==null?void 0:r.definitionId)||n);if(!!$n(s)||s.startsWith("provide_")||!Array.isArray(r==null?void 0:r.output)){t[n]=r;continue}t[n]={...r,output:r.output.map(a=>({...a,value:"",default:""}))}}return t}function $n(e){const t=String(e||"");return t==="display_markdown"?"markdown":t==="display_mermaid"?"mermaid":t==="display_ascii"?"ascii":t==="display_html"?"html":t==="display_image"?"image":t==="display_chart"?"chart":t==="display_table"?"table":""}function Cc(e){const t=[...(e==null?void 0:e.inputs)||[],...(e==null?void 0:e.outputs)||[]],r=$n(e==null?void 0:e.definitionId)==="image"?"src":"content",s=l=>String((l==null?void 0:l.value)??(l==null?void 0:l.default)??""),o=l=>s(l).trim(),a=t.find(l=>(l==null?void 0:l.name)===r&&o(l))||t.find(l=>(l==null?void 0:l.name)==="filePath"&&o(l))||t.find(l=>(l==null?void 0:l.type)==="text"&&o(l));return String((e==null?void 0:e.body)||(a?s(a):""))}function Cd(e,t=""){const n=String(e||"").trim();if(!n||n.length>260||/[\r\n<>]/.test(n)||/^(?:https?:|data:|blob:|file:|javascript:|mailto:|tel:)/i.test(n))return"";const r=n.replace(/^\/+/,"");if(r.includes("..")||r.startsWith("."))return"";const s=r.split("?")[0].split("#")[0].toLowerCase().split(".").pop()||"";return({html:new Set(["html","htm"]),markdown:new Set(["md","markdown","txt"]),mermaid:new Set(["mmd","mermaid","txt"]),ascii:new Set(["txt","log"]),chart:new Set(["json"]),table:new Set(["json","csv","tsv"])}[t]||new Set(["html","htm","md","markdown","txt","json","csv","tsv"])).has(s)?r:""}function OY(e){let t=String(e||"").replace(/\r\n/g,`
151
151
  `).trim();return t.includes(`
@@ -15,7 +15,7 @@
15
15
  href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@24,400,0,0"
16
16
  rel="stylesheet"
17
17
  />
18
- <script type="module" crossorigin src="/assets/index-DkW7IrCF.js"></script>
18
+ <script type="module" crossorigin src="/assets/index-w1bX4CFG.js"></script>
19
19
  <link rel="stylesheet" crossorigin href="/assets/index-CVdxKCZm.css">
20
20
  </head>
21
21
  <body>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fieldwangai/agentflow",
3
- "version": "0.1.83",
3
+ "version": "0.1.84",
4
4
  "description": "Orchestration system for long-running complex agent tasks using Cursor, OpenCode, or Claude Code as execution backends",
5
5
  "type": "module",
6
6
  "main": "bin/agentflow.mjs",