@fieldwangai/agentflow 0.1.60 → 0.1.61

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.
@@ -57,6 +57,7 @@ export function readPipelineListDescription(flowDir) {
57
57
  export function listFlowsJson(workspaceRoot, opts = {}) {
58
58
  const root = path.resolve(workspaceRoot);
59
59
  const out = [];
60
+ const includeWorkspaceFlows = opts.includeWorkspaceFlows === true || !opts.userId;
60
61
  const adminBuiltinConfig = readAdminBuiltinPipelineConfig();
61
62
  const hiddenBuiltins = new Set(adminBuiltinConfig.hiddenBuiltins);
62
63
  const fromBuiltin = collectPipelineNamesFromDir(PACKAGE_BUILTIN_PIPELINES_DIR);
@@ -93,39 +94,41 @@ export function listFlowsJson(workspaceRoot, opts = {}) {
93
94
  const description = readPipelineListDescription(dir);
94
95
  out.push({ id: name, path: dir, source: "user", archived: true, ...(description ? { description } : {}) });
95
96
  }
96
- const wsPrimary = path.join(root, PIPELINES_DIR);
97
- const fromWorkspace = collectPipelineNamesFromDir(wsPrimary);
98
- const workspaceIds = new Set(fromWorkspace);
99
- for (const name of fromWorkspace) {
100
- if (name === ARCHIVED_PIPELINES_DIR_NAME) continue;
101
- const dir = path.join(wsPrimary, name);
102
- const description = readPipelineListDescription(dir);
103
- out.push({ id: name, path: dir, source: "workspace", ...(description ? { description } : {}) });
104
- }
105
- const wsArchivedPrimary = path.join(wsPrimary, ARCHIVED_PIPELINES_DIR_NAME);
106
- const fromWsArchived = collectPipelineNamesFromDir(wsArchivedPrimary);
107
- const workspaceArchivedIds = new Set(fromWsArchived);
108
- for (const name of fromWsArchived) {
109
- const dir = path.join(wsArchivedPrimary, name);
110
- const description = readPipelineListDescription(dir);
111
- out.push({ id: name, path: dir, source: "workspace", archived: true, ...(description ? { description } : {}) });
112
- }
113
- const fromLegacyWs = collectPipelineNamesFromDir(path.join(root, LEGACY_PIPELINES_DIR));
114
- for (const name of fromLegacyWs) {
115
- if (name === ARCHIVED_PIPELINES_DIR_NAME) continue;
116
- if (workspaceIds.has(name)) continue;
117
- const legDir = path.join(root, LEGACY_PIPELINES_DIR, name);
118
- const description = readPipelineListDescription(legDir);
119
- out.push({ id: name, path: legDir, source: "workspace", ...(description ? { description } : {}) });
120
- }
121
- const legArchivedRoot = path.join(root, LEGACY_PIPELINES_DIR, ARCHIVED_PIPELINES_DIR_NAME);
122
- const fromLegArchived = collectPipelineNamesFromDir(legArchivedRoot);
123
- for (const name of fromLegArchived) {
124
- if (workspaceArchivedIds.has(name)) continue;
125
- const dir = path.join(legArchivedRoot, name);
126
- const description = readPipelineListDescription(dir);
127
- out.push({ id: name, path: dir, source: "workspace", archived: true, ...(description ? { description } : {}) });
128
- workspaceArchivedIds.add(name);
97
+ if (includeWorkspaceFlows) {
98
+ const wsPrimary = path.join(root, PIPELINES_DIR);
99
+ const fromWorkspace = collectPipelineNamesFromDir(wsPrimary);
100
+ const workspaceIds = new Set(fromWorkspace);
101
+ for (const name of fromWorkspace) {
102
+ if (name === ARCHIVED_PIPELINES_DIR_NAME) continue;
103
+ const dir = path.join(wsPrimary, name);
104
+ const description = readPipelineListDescription(dir);
105
+ out.push({ id: name, path: dir, source: "workspace", ...(description ? { description } : {}) });
106
+ }
107
+ const wsArchivedPrimary = path.join(wsPrimary, ARCHIVED_PIPELINES_DIR_NAME);
108
+ const fromWsArchived = collectPipelineNamesFromDir(wsArchivedPrimary);
109
+ const workspaceArchivedIds = new Set(fromWsArchived);
110
+ for (const name of fromWsArchived) {
111
+ const dir = path.join(wsArchivedPrimary, name);
112
+ const description = readPipelineListDescription(dir);
113
+ out.push({ id: name, path: dir, source: "workspace", archived: true, ...(description ? { description } : {}) });
114
+ }
115
+ const fromLegacyWs = collectPipelineNamesFromDir(path.join(root, LEGACY_PIPELINES_DIR));
116
+ for (const name of fromLegacyWs) {
117
+ if (name === ARCHIVED_PIPELINES_DIR_NAME) continue;
118
+ if (workspaceIds.has(name)) continue;
119
+ const legDir = path.join(root, LEGACY_PIPELINES_DIR, name);
120
+ const description = readPipelineListDescription(legDir);
121
+ out.push({ id: name, path: legDir, source: "workspace", ...(description ? { description } : {}) });
122
+ }
123
+ const legArchivedRoot = path.join(root, LEGACY_PIPELINES_DIR, ARCHIVED_PIPELINES_DIR_NAME);
124
+ const fromLegArchived = collectPipelineNamesFromDir(legArchivedRoot);
125
+ for (const name of fromLegArchived) {
126
+ if (workspaceArchivedIds.has(name)) continue;
127
+ const dir = path.join(legArchivedRoot, name);
128
+ const description = readPipelineListDescription(dir);
129
+ out.push({ id: name, path: dir, source: "workspace", archived: true, ...(description ? { description } : {}) });
130
+ workspaceArchivedIds.add(name);
131
+ }
129
132
  }
130
133
  const sourceRank = (s) => (s === "builtin" ? 0 : s === "admin" ? 1 : s === "user" ? 2 : 3);
131
134
  const archRank = (a) => (a.archived ? 1 : 0);
@@ -3589,7 +3589,10 @@ export function startUiServer({
3589
3589
  if (ts === "workspace" || ts === "user") {
3590
3590
  targetSpace = ts;
3591
3591
  }
3592
- const existing = listFlowsJson(root, userCtx);
3592
+ const existing = listFlowsJson(root, {
3593
+ ...userCtx,
3594
+ includeWorkspaceFlows: targetSpace === "workspace",
3595
+ });
3593
3596
  if (
3594
3597
  existing.some(
3595
3598
  (f) => f.id === flowId && (f.source ?? "user") === targetSpace && !f.archived,
@@ -3645,7 +3648,10 @@ export function startUiServer({
3645
3648
  }
3646
3649
  const flowId = idCheck.flowId;
3647
3650
  const targetSpace = parsed.targetSpace === "workspace" ? "workspace" : "user";
3648
- const existing = listFlowsJson(root, userCtx);
3651
+ const existing = listFlowsJson(root, {
3652
+ ...userCtx,
3653
+ includeWorkspaceFlows: targetSpace === "workspace",
3654
+ });
3649
3655
  if (
3650
3656
  existing.some(
3651
3657
  (f) => f.id === flowId && (f.source ?? "user") === targetSpace && !f.archived,
@@ -28,6 +28,8 @@ export function listAllRunDirs(workspaceRoot, opts = {}) {
28
28
  const root = path.resolve(workspaceRoot);
29
29
  const out = [];
30
30
  const seen = new Set();
31
+ const includeWorkspaceRuns = opts.includeWorkspaceRuns === true || !opts.userId;
32
+ const includeLegacyUserRuns = opts.includeLegacyUserRuns === true || !opts.userId;
31
33
  const add = (flowName, uuid, runDir, source) => {
32
34
  const key = `${flowName}\t${uuid}`;
33
35
  if (seen.has(key)) return;
@@ -64,7 +66,7 @@ export function listAllRunDirs(workspaceRoot, opts = {}) {
64
66
 
65
67
  // 新位置(优先)
66
68
  scanPipelinesDir(getUserPipelinesRoot(opts.userId), "user");
67
- scanPipelinesDir(path.join(root, PIPELINES_DIR), "workspace");
69
+ if (includeWorkspaceRuns) scanPipelinesDir(path.join(root, PIPELINES_DIR), "workspace");
68
70
 
69
71
  // 旧位置(兼容读)
70
72
  const scanLegacyRoot = (runBuildDir, source) => {
@@ -90,8 +92,8 @@ export function listAllRunDirs(workspaceRoot, opts = {}) {
90
92
  }
91
93
  }
92
94
  };
93
- scanLegacyRoot(getWorkspaceRunBuildRoot(root), "legacyWorkspaceRoot");
94
- scanLegacyRoot(getLegacyUserRunBuildRoot(), "legacyUserRoot");
95
+ if (includeWorkspaceRuns) scanLegacyRoot(getWorkspaceRunBuildRoot(root), "legacyWorkspaceRoot");
96
+ if (includeLegacyUserRuns) scanLegacyRoot(getLegacyUserRunBuildRoot(), "legacyUserRoot");
95
97
 
96
98
  return out;
97
99
  }
@@ -125,7 +125,7 @@ script: node -e "console.log('TODO: scripts/x.mjs')"
125
125
 
126
126
  `).trimEnd()}function _x(e){return String(e||"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function xK(e){const t=String(e||"");let n="",r=0;sg.lastIndex=0;let s;for(;s=sg.exec(t);)n+=_x(t.slice(r,s.index)),n+=`<span class="af-flow-node__image-token">${_x(s[0])}</span>`,r=s.index+s[0].length;return n+=_x(t.slice(r)),n||" "}function wK(e,t){const n=window.getComputedStyle(e),r=Number.parseFloat(n.lineHeight)||18,s=Number.parseFloat(n.paddingTop)||0,i=Number.parseFloat(n.paddingBottom)||0,a=Number.parseFloat(n.borderTopWidth)||0,l=Number.parseFloat(n.borderBottomWidth)||0,u=String(t||"").split(/\r\n|\r|\n/).length,d=Math.min(Math.max(u,2),8);return Math.ceil(d*r+s+i+a+l)}function AT({data:e,selected:t,id:n,deleteNode:r,onProvideExpand:s,onProvideValueChange:i,onNodeBodyChange:a,onNodeImagesChange:l,modelLists:u,onModelChange:d}){var hn,sr;const{t:f}=Pn(),c=(e==null?void 0:e.inputs)??[],p=(e==null?void 0:e.outputs)??[],m=((e==null?void 0:e.schemaType)??"agent").toLowerCase(),g=pK(e),b=hK(g),k=(e==null?void 0:e.isRunMode)??!1,y=!!(e!=null&&e.readOnly),v=(e==null?void 0:e.isExecuting)??!1,w=(e==null?void 0:e.isDim)??!1,j=(e==null?void 0:e.nodeStatus)??null,P=(e==null?void 0:e.nodeElapsed)??null,_=(e==null?void 0:e.definitionId)||"",L=_.startsWith("provide_"),B=_==="provide_bool",D=_==="provide_str",F=_==="provide_file",R=_==="agent_subAgent",M=R&&!k,W=B?mK(p[0]):!1,O=L?String(((hn=p[0])==null?void 0:hn.value)??((sr=p[0])==null?void 0:sr.default)??(e==null?void 0:e.body)??""):"",$=String((e==null?void 0:e.body)||""),I=(e==null?void 0:e.displayLabel)||(e==null?void 0:e.label)||f("flow:node.fallbackLabel"),z=!L&&!M&&(e!=null&&e.showBodyPreview)?String((e==null?void 0:e.body)||"").trim():"",C=Ps(e==null?void 0:e.images),T=h.useRef(!1),E=h.useRef(!1),G=h.useRef(null),Z=h.useRef(null),V=h.useRef(null),[se,de]=h.useState(O),[fe,pe]=h.useState($);h.useEffect(()=>{T.current||de(O)},[n,O]),h.useEffect(()=>{E.current||pe($)},[n,$]),h.useEffect(()=>{const xe=Z.current;if(!xe)return;const Me=wK(xe,fe);xe.style.minHeight=`${Me}px`,xe.style.height="",V.current&&(V.current.style.minHeight=`${Me}px`,V.current.style.height="")},[fe]),h.useEffect(()=>{const xe=G.current,Me=e==null?void 0:e.onNodeContentResize;if(!M||!xe||!Me||typeof ResizeObserver>"u")return;let Ze=0;const Dt=()=>{window.cancelAnimationFrame(Ze),Ze=window.requestAnimationFrame(()=>Me(n))},ie=new ResizeObserver(Dt);return ie.observe(xe),Dt(),()=>{window.cancelAnimationFrame(Ze),ie.disconnect()}},[e==null?void 0:e.onNodeContentResize,M,n]);const ae=Array.isArray(u==null?void 0:u.cursor)?u.cursor:[],be=Array.isArray(u==null?void 0:u.opencode)?u.opencode:[],_e=Array.isArray(u==null?void 0:u.claudeCode)?u.claudeCode:[],we=((e==null?void 0:e.model)??"").trim(),Oe=m==="agent"&&!_.startsWith("tool_nodejs"),Ie=new Set(ae.map(Yo)),et=new Set(be.map(Yo)),ft=new Set(_e.map(Yo)),Je=we?we.startsWith("cursor:")||we.startsWith("opencode:")||we.startsWith("claude-code:")?we:ft.has(we)?`claude-code:${we}`:et.has(we)?`opencode:${we}`:Ie.has(we)?`cursor:${we}`:we:"",bt=we&&!Je.startsWith("cursor:")&&!Je.startsWith("opencode:")&&!Je.startsWith("claude-code:")&&!Ie.has(we)&&!et.has(we)&&!ft.has(we),Ve=we.startsWith("cursor:")?we.slice(7):we.startsWith("opencode:")?we.slice(9):we.startsWith("claude-code:")?we.slice(12):we,jt=xe=>{if(y)return;const Me=xe.target.value;d&&d(n,Me)},An=xe=>{xe.stopPropagation(),!y&&r&&r(n)},pn=xe=>{xe.stopPropagation(),s&&s()},In=xe=>{xe.stopPropagation(),!y&&(i==null||i(n,xe.target.value==="true"?"true":"false"))},en=xe=>{if(xe.stopPropagation(),y)return;const Me=xe.target.value;de(Me),T.current||i==null||i(n,Me)},Wn=xe=>{xe.stopPropagation(),T.current=!0},Tn=xe=>{if(xe.stopPropagation(),y)return;T.current=!1;const Me=xe.currentTarget.value;de(Me),i==null||i(n,Me)},ce=()=>{y||i==null||i(n,se)},ve=xe=>{if(xe.stopPropagation(),y)return;const Me=window.prompt("文件路径",se);Me!=null&&(de(Me),i==null||i(n,Me))},ze=xe=>{if(pe(xe),a==null||a(n,xe),l){const Me=JU(C,xe);(Me.length!==C.length||Me.some((Ze,Dt)=>{var ie;return Ze.id!==((ie=C[Dt])==null?void 0:ie.id)}))&&l(n,Me)}},it=xe=>{if(xe.stopPropagation(),y)return;const Me=xe.target.value;E.current?pe(Me):ze(Me)},ot=xe=>{xe.stopPropagation(),!y&&(E.current=!0)},Tt=xe=>{if(xe.stopPropagation(),y)return;E.current=!1;const Me=xe.currentTarget.value;ze(Me)},tt=()=>{y||ze(fe)},an=async xe=>{if(y)return;const Me=await jT({files:xe,body:fe,images:C});Me&&(pe(Me.body),a==null||a(n,Me.body),l==null||l(n,Me.images))},Xt=(xe,Me)=>{if(xe.stopPropagation(),y)return;const Ze=C.filter(ie=>ie.id!==Me.id),Dt=yK(fe,Me.label);pe(Dt),a==null||a(n,Dt),l==null||l(n,Ze)},rr=xe=>{if(y)return;const Me=NT(xe);Me.length!==0&&(xe.preventDefault(),xe.stopPropagation(),an(Me).catch(()=>{}))},vn=xe=>{if(y)return;const Me=ig(xe);Me.length!==0&&(xe.preventDefault(),xe.stopPropagation(),an(Me).catch(()=>{}))},ln=()=>{const xe=Z.current,Me=V.current;!xe||!Me||(Me.scrollTop=xe.scrollTop,Me.scrollLeft=xe.scrollLeft)};return o.jsxs("div",{className:"af-flow-node"+(t?" af-flow-node--selected":"")+(v?" af-flow-node--executing":"")+(j==="success"?" af-flow-node--done":"")+(j==="failed"?" af-flow-node--failed":"")+(j==="running"&&!v?" af-flow-node--running-disk":"")+(w?" af-flow-node--dim":"")+(M?" af-flow-node--inline-body-editor":"")+" af-flow-node--"+m.replace(/[^a-z0-9_-]/g,""),"data-schema":m,children:[o.jsxs("div",{className:"af-flow-node__chrome",children:[o.jsx("span",{className:"af-flow-node__type",title:g,children:b}),!k&&Oe&&o.jsxs("div",{className:"af-flow-node__model-wrap nodrag",onPointerDown:Rr,onMouseDown:Rr,onClick:Rr,children:[o.jsxs("select",{className:"af-flow-node__model nodrag",value:Je,onChange:jt,onPointerDown:Rr,onMouseDown:Rr,onClick:Rr,"aria-label":f("flow:node.model"),title:Ve||f("flow:node.defaultModel"),disabled:y,children:[o.jsx("option",{value:"",children:f("flow:node.defaultModel")}),bt&&o.jsx("option",{value:we,children:we}),ae.length>0&&o.jsx("optgroup",{label:"Cursor",children:ae.map(xe=>o.jsx("option",{value:`cursor:${Yo(xe)}`,children:Yo(xe)},`c-${xe}`))}),be.length>0&&o.jsx("optgroup",{label:"OpenCode",children:be.map(xe=>o.jsx("option",{value:`opencode:${Yo(xe)}`,children:Yo(xe)},`o-${xe}`))}),_e.length>0&&o.jsx("optgroup",{label:"Claude Code",children:_e.map(xe=>o.jsx("option",{value:`claude-code:${Yo(xe)}`,children:Yo(xe)},`cc-${xe}`))})]}),o.jsx("span",{className:"af-flow-node__model-arrow material-symbols-outlined",children:"expand_more"})]}),v&&o.jsx("span",{className:"af-flow-node__status-badge af-flow-node__status-badge--executing",children:"EXECUTING"}),j==="running"&&!v&&o.jsx("span",{className:"af-flow-node__status-badge af-flow-node__status-badge--running-disk",title:f("flow:node.diskRunning"),children:"RUNNING"}),j==="success"&&o.jsx("span",{className:"af-flow-node__status-badge af-flow-node__status-badge--done",children:P!=null&&String(P).trim()!==""?P:"--"}),j==="failed"&&o.jsx("span",{className:"af-flow-node__status-badge af-flow-node__status-badge--failed",children:"FAILED"}),!k&&L&&!B&&!D&&!F&&o.jsx("button",{type:"button",className:"af-flow-node__expand",onClick:pn,"aria-label":f("flow:node.expandProvide"),title:f("flow:node.expandProvide"),children:o.jsx("span",{className:"material-symbols-outlined",children:"open_in_full"})}),!k&&o.jsx("button",{type:"button",className:"af-flow-node__delete",disabled:y,onClick:An,"aria-label":f("flow:node.deleteNode"),title:f("flow:node.deleteNode"),children:o.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),o.jsxs("div",{className:"af-flow-node__body",children:[o.jsx("div",{className:"af-flow-node__ports af-flow-node__ports--in",children:c.map((xe,Me)=>{if(xe.showOnNode===!1)return null;const Ze=f("flow:node.inputTooltip",{name:xe.name||`#${Me}`,type:xe.type})+(xe.default!=null&&xe.default!==""?f("flow:node.defaultSuffix",{value:xe.default}):""),Dt=xe.name||`#${Me+1}`;return o.jsxs("div",{className:"af-flow-node__port-row",title:Ze,children:[o.jsxs("span",{className:"af-flow-node__port-label af-flow-node__port-label--in",children:[Dt,xe.required?o.jsx("span",{className:"af-flow-node__port-required",children:"*"}):null]}),o.jsx(Ms,{type:"target",position:Xe.Left,id:`input-${Me}`,className:"af-flow-node__handle",style:{background:nr(xe.type)},title:Ze})]},`in-${Me}`)})}),o.jsxs("div",{className:"af-flow-node__title-wrap",children:[o.jsx("span",{className:"af-flow-node__title",children:I}),n?o.jsx("span",{className:"af-flow-node__subtitle",title:n,children:n}):null,B?o.jsxs("select",{className:"af-flow-node__bool-select nodrag"+(W?" af-flow-node__bool-select--true":""),value:W?"true":"false",onChange:In,onPointerDown:Rr,onMouseDown:Rr,onClick:Rr,"aria-label":"Boolean value",title:W?"true":"false",disabled:y,children:[o.jsx("option",{value:"false",children:"false"}),o.jsx("option",{value:"true",children:"true"})]}):D?o.jsx("textarea",{className:"af-flow-node__inline-text nodrag",value:se,onChange:en,onCompositionStart:Wn,onCompositionEnd:Tn,onBlur:ce,onPointerDown:Rr,onMouseDown:Rr,onClick:Rr,placeholder:"输入文本",rows:2,readOnly:y}):F?o.jsxs("div",{className:"af-flow-node__file-value nodrag",onPointerDown:Rr,onMouseDown:Rr,onClick:Rr,children:[o.jsx("input",{className:"af-flow-node__file-input nodrag",value:se,onChange:en,onCompositionStart:Wn,onCompositionEnd:Tn,onBlur:ce,placeholder:"选择或输入文件路径",title:se||"选择或输入文件路径",readOnly:y}),o.jsx("button",{type:"button",className:"af-flow-node__file-picker nodrag",disabled:y,onClick:ve,"aria-label":"选择文件",title:"选择文件",children:o.jsx("span",{className:"material-symbols-outlined",children:"folder_open"})})]}):R&&!k?o.jsxs("div",{ref:G,className:"af-flow-node__prompt-stack nodrag",children:[o.jsx("pre",{ref:V,className:"af-flow-node__prompt-backdrop","aria-hidden":"true",dangerouslySetInnerHTML:{__html:xK(fe)+`
127
127
  `}}),o.jsx("textarea",{ref:Z,className:"af-flow-node__prompt-editor nodrag",value:fe,onChange:it,onCompositionStart:ot,onCompositionEnd:Tt,onBlur:tt,onPaste:rr,onDrop:vn,onScroll:ln,onDragOver:xe=>{ig(xe).length>0&&xe.preventDefault()},placeholder:"输入 prompt",rows:2,readOnly:y})]}):null,R&&C.length>0?o.jsx("div",{className:"af-flow-node__image-chips",children:C.map((xe,Me)=>o.jsxs("span",{className:"af-flow-node__image-chip",title:xe.name,children:[o.jsx("img",{src:xe.dataUrl,alt:""}),o.jsxs("span",{children:["[",xe.label||`image ${Me+1}`,"]"]}),o.jsx("button",{type:"button",className:"af-flow-node__image-remove nodrag",disabled:y,onClick:Ze=>Xt(Ze,xe),onPointerDown:Rr,onMouseDown:Rr,"aria-label":`删除 ${xe.label||`image ${Me+1}`}`,title:"删除图片",children:o.jsx("span",{className:"material-symbols-outlined",children:"close"})})]},xe.id||Me))}):null,z?o.jsx("span",{className:"af-flow-node__prompt-preview",title:z,children:z}):null]}),o.jsx("div",{className:"af-flow-node__ports af-flow-node__ports--out",children:p.map((xe,Me)=>{if(xe.showOnNode===!1)return null;const Ze=f("flow:node.outputTooltip",{name:xe.name||`#${Me}`,type:xe.type})+(xe.default!=null&&xe.default!==""?f("flow:node.defaultSuffix",{value:xe.default}):""),Dt=xe.name||`#${Me+1}`;return o.jsxs("div",{className:"af-flow-node__port-row",title:Ze,children:[o.jsxs("span",{className:"af-flow-node__port-label af-flow-node__port-label--out",children:[Dt,xe.required?o.jsx("span",{className:"af-flow-node__port-required",children:"*"}):null]}),o.jsx(Ms,{type:"source",position:Xe.Right,id:`output-${Me}`,className:"af-flow-node__handle",style:{background:nr(xe.type)},title:Ze})]},`out-${Me}`)})})]})]})}const mp="flowNode";function IT(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 lg(e){return e.key==="?"||e.key==="/"&&e.shiftKey}function bK(){return typeof navigator>"u"?!1:/Mac|iPhone|iPod|iPad/i.test(navigator.platform||navigator.userAgent||"")}function TT({open:e,onClose:t,flowId:n,flowSource:r,onArchived:s}){const{t:i}=Pn(),a=h.useId(),l=h.useRef(null),[u,d]=h.useState(""),[f,c]=h.useState(!1),[p,m]=h.useState("");if(h.useEffect(()=>{if(!e)return;d(""),m(""),c(!1);const y=requestAnimationFrame(()=>{var v;return(v=l.current)==null?void 0:v.focus()});return()=>cancelAnimationFrame(y)},[e,n]),!e)return null;const g=u.trim(),b=g===n;async function k(y){if(y.preventDefault(),!(!b||f)){c(!0),m("");try{const v=await fetch("/api/flow/archive",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({flowId:n,flowSource:r,confirmFlowId:g})}),w=await v.json().catch(()=>({}));if(!v.ok){m(typeof w.error=="string"?w.error:i("project:archiveModal.archiveFailed"));return}s()}catch(v){m(String((v==null?void 0:v.message)||v))}finally{c(!1)}}}return o.jsx("div",{className:"af-shortcuts-overlay",role:"presentation",onMouseDown:y=>{y.target===y.currentTarget&&t()},children:o.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:[o.jsxs("div",{className:"af-shortcuts-panel__head",children:[o.jsx("h2",{id:a,className:"af-shortcuts-panel__title",children:i("project:archiveModal.title")}),o.jsx("button",{type:"button",className:"af-shortcuts-panel__close af-icon-btn",onClick:t,"aria-label":i("project:archiveModal.close"),children:o.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),o.jsxs("form",{className:"af-shortcuts-panel__body af-new-pipeline-form",onSubmit:k,children:[o.jsx("p",{className:"af-new-pipeline-lead",children:i("project:archiveModal.lead",{flowId:n})}),o.jsxs("label",{className:"af-new-pipeline-field",children:[o.jsx("span",{className:"af-pipeline-drawer-label",children:i("project:archiveModal.confirmLabel")}),o.jsx("input",{type:"text",className:"af-new-pipeline-input",value:u,onChange:y=>d(y.target.value),placeholder:n,autoComplete:"off",spellCheck:!1,"aria-invalid":g.length>0&&!b})]}),p?o.jsx("p",{className:"af-err af-new-pipeline-err",children:p}):null,o.jsxs("div",{className:"af-new-pipeline-actions",children:[o.jsx("button",{type:"button",className:"af-btn-secondary",onClick:t,disabled:f,children:i("project:archiveModal.cancel")}),o.jsx("button",{type:"submit",className:"af-btn-primary",disabled:!b||f,children:i(f?"project:archiveModal.archiving":"project:archiveModal.confirmArchive")})]})]})]})})}function Dj({open:e,title:t,message:n,confirmLabel:r,cancelLabel:s,destructive:i=!1,secondaryLabel:a,secondaryDestructive:l=!1,onSecondary:u,onConfirm:d,onCancel:f}){const{t:c}=Pn(),p=h.useId(),m=h.useRef(null);if(h.useEffect(()=>{if(!e)return;const y=requestAnimationFrame(()=>{var w;return(w=m.current)==null?void 0:w.focus()});function v(w){w.key==="Escape"&&f(),w.key==="Enter"&&d()}return window.addEventListener("keydown",v),()=>{cancelAnimationFrame(y),window.removeEventListener("keydown",v)}},[e,f,d]),!e)return null;const g=r??c("common:common.confirm","确定"),b=s??c("common:common.cancel","取消"),k=t??c("common:common.confirmTitle","请确认");return o.jsx("div",{className:"af-shortcuts-overlay",role:"presentation",onMouseDown:y=>{y.target===y.currentTarget&&f()},children:o.jsxs("div",{ref:m,className:"af-shortcuts-panel af-new-pipeline-panel",role:"dialog","aria-modal":"true","aria-labelledby":p,tabIndex:-1,onMouseDown:y=>y.stopPropagation(),children:[o.jsxs("div",{className:"af-shortcuts-panel__head",children:[o.jsx("h2",{id:p,className:"af-shortcuts-panel__title",children:k}),o.jsx("button",{type:"button",className:"af-shortcuts-panel__close af-icon-btn",onClick:f,"aria-label":b,children:o.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),o.jsxs("div",{className:"af-shortcuts-panel__body af-new-pipeline-form",children:[o.jsx("p",{className:"af-new-pipeline-lead",children:n}),o.jsxs("div",{className:"af-new-pipeline-actions",children:[o.jsx("button",{type:"button",className:"af-btn-secondary",onClick:f,children:b}),a&&u?o.jsx("button",{type:"button",className:l?"af-btn-secondary af-btn-destructive":"af-btn-secondary",onClick:u,children:a}):null,o.jsx("button",{type:"button",className:i?"af-btn-primary af-btn-destructive":"af-btn-primary",onClick:d,autoFocus:!0,children:g})]})]})]})})}function RT({open:e,onClose:t,flowId:n,flowSource:r,flowArchived:s=!1,onDeleted:i}){const{t:a}=Pn(),l=h.useId(),u=h.useRef(null),[d,f]=h.useState(""),[c,p]=h.useState(!1),[m,g]=h.useState("");if(h.useEffect(()=>{if(!e)return;f(""),g(""),p(!1);const v=requestAnimationFrame(()=>{var w;return(w=u.current)==null?void 0:w.focus()});return()=>cancelAnimationFrame(v)},[e,n]),!e)return null;const b=d.trim(),k=b===n;async function y(v){if(v.preventDefault(),!k||c)return;p(!0),g("");let w=null;try{const j=new AbortController;w=setTimeout(()=>j.abort(),15e3);const P=await fetch("/api/flow/delete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({flowId:n,flowSource:r,confirmFlowId:b,flowArchived:s}),signal:j.signal}),_=await P.json().catch(()=>({}));if(!P.ok){g(typeof _.error=="string"?_.error:a("project:deleteModal.deleteFailed"));return}try{for(let L=localStorage.length-1;L>=0;L--){const B=localStorage.key(L);B&&(B.startsWith(`af:composer-sessions:${n}:${r}`)||B.startsWith(`af:composer-active-session:${n}:${r}`)||B.startsWith(`af:workspace-composer:${n}:${r}`))&&localStorage.removeItem(B)}}catch{}await i()}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{w&&clearTimeout(w),p(!1)}}return o.jsx("div",{className:"af-shortcuts-overlay",role:"presentation",onMouseDown:v=>{v.target===v.currentTarget&&t()},children:o.jsxs("div",{ref:u,className:"af-shortcuts-panel af-new-pipeline-panel",role:"dialog","aria-modal":"true","aria-labelledby":l,tabIndex:-1,onMouseDown:v=>v.stopPropagation(),children:[o.jsxs("div",{className:"af-shortcuts-panel__head",children:[o.jsx("h2",{id:l,className:"af-shortcuts-panel__title",children:a("project:deleteModal.title")}),o.jsx("button",{type:"button",className:"af-shortcuts-panel__close af-icon-btn",onClick:t,"aria-label":a("project:deleteModal.close"),children:o.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),o.jsxs("form",{className:"af-shortcuts-panel__body af-new-pipeline-form",onSubmit:y,children:[o.jsx("p",{className:"af-new-pipeline-lead",children:a("project:deleteModal.lead",{flowId:n})}),o.jsxs("label",{className:"af-new-pipeline-field",children:[o.jsx("span",{className:"af-pipeline-drawer-label",children:a("project:deleteModal.confirmLabel")}),o.jsx("input",{type:"text",className:"af-new-pipeline-input",value:d,onChange:v=>f(v.target.value),placeholder:n,autoComplete:"off",spellCheck:!1,"aria-invalid":b.length>0&&!k})]}),m?o.jsx("p",{className:"af-err af-new-pipeline-err",children:m}):null,o.jsxs("div",{className:"af-new-pipeline-actions",children:[o.jsx("button",{type:"button",className:"af-btn-secondary",onClick:t,disabled:c,children:a("project:deleteModal.cancel")}),o.jsx("button",{type:"submit",className:"af-btn-primary af-btn-destructive",disabled:!k||c,children:a(c?"project:deleteModal.deleting":"project:deleteModal.confirmDelete")})]})]})]})})}function vK({children:e}){return o.jsx("kbd",{className:"af-kbd",children:e})}function zi({keys:e}){return o.jsx("span",{className:"af-shortcuts-keys",children:e.map((t,n)=>o.jsxs("span",{children:[n>0?o.jsx("span",{className:"af-shortcuts-keys__plus",children:"+"}):null,o.jsx(vK,{children:t})]},n))})}function LT({open:e,onClose:t}){const{t:n}=Pn(),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 i=bK()?"⌘":"Ctrl";return o.jsx("div",{className:"af-shortcuts-overlay",role:"presentation",onMouseDown:a=>{a.target===a.currentTarget&&t()},children:o.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:[o.jsxs("div",{className:"af-shortcuts-panel__head",children:[o.jsx("h2",{id:"af-shortcuts-title",className:"af-shortcuts-panel__title",children:n("flow:shortcuts.title")}),o.jsx("button",{type:"button",className:"af-shortcuts-panel__close af-icon-btn",onClick:t,"aria-label":n("common:common.close"),children:o.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),o.jsxs("div",{className:"af-shortcuts-panel__body",children:[o.jsxs("section",{className:"af-shortcuts-section",children:[o.jsx("h3",{className:"af-shortcuts-cat",children:n("flow:shortcuts.general")}),o.jsxs("ul",{className:"af-shortcuts-list",children:[o.jsxs("li",{className:"af-shortcuts-row",children:[o.jsx("span",{className:"af-shortcuts-row__label",children:n("flow:shortcuts.saveDesc")}),o.jsx(zi,{keys:[i,"S"]})]}),o.jsxs("li",{className:"af-shortcuts-row",children:[o.jsx("span",{className:"af-shortcuts-row__label",children:n("flow:shortcuts.shortcutsLabel")}),o.jsx(zi,{keys:["?"]})]}),o.jsxs("li",{className:"af-shortcuts-row",children:[o.jsx("span",{className:"af-shortcuts-row__label",children:n("flow:shortcuts.jumpToNode")}),o.jsx(zi,{keys:[i,"K"]})]}),o.jsxs("li",{className:"af-shortcuts-row",children:[o.jsx("span",{className:"af-shortcuts-row__label",children:n("flow:shortcuts.openNodePalette")}),o.jsx(zi,{keys:["A"]})]})]})]}),o.jsxs("section",{className:"af-shortcuts-section",children:[o.jsx("h3",{className:"af-shortcuts-cat",children:n("flow:shortcuts.canvas")}),o.jsxs("ul",{className:"af-shortcuts-list",children:[o.jsxs("li",{className:"af-shortcuts-row",children:[o.jsx("span",{className:"af-shortcuts-row__label",children:n("flow:shortcuts.selectTool")}),o.jsx(zi,{keys:["V"]})]}),o.jsxs("li",{className:"af-shortcuts-row",children:[o.jsx("span",{className:"af-shortcuts-row__label",children:n("flow:shortcuts.panTool")}),o.jsx(zi,{keys:["H"]})]}),o.jsxs("li",{className:"af-shortcuts-row",children:[o.jsx("span",{className:"af-shortcuts-row__label",children:n("flow:shortcuts.holdSpacePan")}),o.jsx(zi,{keys:["Space"]})]}),o.jsxs("li",{className:"af-shortcuts-row",children:[o.jsx("span",{className:"af-shortcuts-row__label",children:n("flow:shortcuts.saveViewport")}),o.jsx(zi,{keys:["F"]})]}),o.jsxs("li",{className:"af-shortcuts-row",children:[o.jsx("span",{className:"af-shortcuts-row__label",children:n("flow:shortcuts.selectAll")}),o.jsx(zi,{keys:[i,"A"]})]}),o.jsxs("li",{className:"af-shortcuts-row",children:[o.jsx("span",{className:"af-shortcuts-row__label",children:n("flow:shortcuts.undo")}),o.jsx(zi,{keys:[i,"Z"]})]}),o.jsxs("li",{className:"af-shortcuts-row",children:[o.jsx("span",{className:"af-shortcuts-row__label",children:n("flow:shortcuts.redo")}),o.jsx(zi,{keys:[i,"Shift","Z"]})]})]})]})]})]})})}function kK(e,t){if(!t)return 1;const n=t.toLowerCase(),r=(e.id||"").toLowerCase(),s=(e.label||"").toLowerCase(),i=(e.definitionId||"").toLowerCase();return r===n?100:r.startsWith(n)?80:r.includes(n)?60:s.startsWith(n)?40:s.includes(n)?30:i.includes(n)?15:0}function OT({open:e,onClose:t,onJump:n,nodes:r}){const{t:s}=Pn(),[i,a]=h.useState(""),[l,u]=h.useState(0),d=h.useRef(null),f=h.useRef(null);h.useEffect(()=>{if(!e)return;a(""),u(0);const g=requestAnimationFrame(()=>{var b;return(b=d.current)==null?void 0:b.focus()});return()=>cancelAnimationFrame(g)},[e]);const c=h.useMemo(()=>{const g=(r||[]).map(y=>{var v,w,j;return{id:y.id,label:((v=y.data)==null?void 0:v.label)||"",definitionId:((w=y.data)==null?void 0:w.definitionId)||"",schemaType:((j=y.data)==null?void 0:j.schemaType)||""}}),b=i.trim(),k=g.map(y=>({e:y,s:kK(y,b)})).filter(y=>y.s>0);return k.sort((y,v)=>v.s-y.s||y.e.id.localeCompare(v.e.id)),k.slice(0,50).map(y=>y.e)},[r,i]);if(h.useEffect(()=>{l>=c.length&&u(0)},[c.length,l]),h.useEffect(()=>{var b;const g=(b=f.current)==null?void 0:b.querySelector(`[data-idx="${l}"]`);g&&g.scrollIntoView({block:"nearest"})},[l]),!e)return null;const p=g=>{const b=c[g];b&&(n(b.id),t())},m=g=>{if(g.key==="Escape"){g.preventDefault(),t();return}if(g.key==="ArrowDown"){g.preventDefault(),u(b=>Math.min(c.length-1,b+1));return}if(g.key==="ArrowUp"){g.preventDefault(),u(b=>Math.max(0,b-1));return}g.key==="Enter"&&(g.preventDefault(),p(l))};return o.jsx("div",{className:"af-jump-overlay",role:"presentation",onMouseDown:g=>{g.target===g.currentTarget&&t()},children:o.jsxs("div",{className:"af-jump-panel",role:"dialog","aria-modal":"true","aria-label":s("flow:jumpPalette.title"),onMouseDown:g=>g.stopPropagation(),children:[o.jsxs("div",{className:"af-jump-panel__input-wrap",children:[o.jsx("span",{className:"af-jump-panel__icon material-symbols-outlined","aria-hidden":!0,children:"search"}),o.jsx("input",{ref:d,type:"text",className:"af-jump-panel__input",placeholder:s("flow:jumpPalette.placeholder"),value:i,onChange:g=>{a(g.target.value),u(0)},onKeyDown:m,spellCheck:!1,autoComplete:"off"}),o.jsx("span",{className:"af-jump-panel__count",children:c.length})]}),c.length===0?o.jsx("div",{className:"af-jump-panel__empty",children:s("flow:jumpPalette.empty")}):o.jsx("ul",{ref:f,className:"af-jump-panel__list",role:"listbox",children:c.map((g,b)=>o.jsxs("li",{"data-idx":b,role:"option","aria-selected":b===l,className:"af-jump-panel__item"+(b===l?" af-jump-panel__item--active":""),onMouseEnter:()=>u(b),onMouseDown:k=>{k.preventDefault(),p(b)},children:[o.jsx("span",{className:"af-jump-panel__id",children:g.id}),g.label&&g.label!==g.id&&o.jsx("span",{className:"af-jump-panel__label",children:g.label}),g.definitionId&&o.jsx("span",{className:"af-jump-panel__tag",children:g.definitionId})]},g.id))}),o.jsxs("div",{className:"af-jump-panel__hint",children:[o.jsxs("span",{children:[o.jsx("kbd",{className:"af-kbd",children:"↑"}),o.jsx("kbd",{className:"af-kbd",children:"↓"})," ",s("flow:jumpPalette.hintNavigate")]}),o.jsxs("span",{children:[o.jsx("kbd",{className:"af-kbd",children:"Enter"})," ",s("flow:jumpPalette.hintJump")]}),o.jsxs("span",{children:[o.jsx("kbd",{className:"af-kbd",children:"Esc"})," ",s("flow:jumpPalette.hintClose")]})]})]})})}function SK({open:e,onClose:t,flowId:n,flowSource:r,flowArchived:s=!1,filePath:i,fileName:a,onSaved:l,onAiEdit:u}){const{t:d}=Pn(),f=h.useId(),c=h.useRef(null),p=h.useRef(null),[m,g]=h.useState(""),[b,k]=h.useState(""),[y,v]=h.useState(!1),[w,j]=h.useState(!1),[P,_]=h.useState(!1),[L,B]=h.useState(""),[D,F]=h.useState("");if(h.useEffect(()=>{if(!e||!i)return;g(""),k(""),B(""),F(""),v(!0),j(!1),_(!1);const I=new URLSearchParams({flowId:n,flowSource:r,archived:s?"1":"0",path:i});(async()=>{try{const C=await fetch(`/api/pipeline-file-content?${I}`),T=await C.json();if(!C.ok)throw new Error(T.error||"HTTP "+C.status);g(T.content||""),k(T.content||"")}catch(C){B(C.message||String(C))}finally{v(!1)}})();const z=requestAnimationFrame(()=>{var C;return(C=c.current)==null?void 0:C.focus()});return()=>cancelAnimationFrame(z)},[e,i,n,r,s]),!e)return null;const R=m!==b;async function M(I){if(I.preventDefault(),!w){j(!0),B(""),F("");try{const z=new URLSearchParams({flowId:n,flowSource:r,archived:s?"1":"0",path:i}),C=await fetch(`/api/pipeline-file-save?${z}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:m})}),T=await C.json();if(!C.ok)throw new Error(T.error||"HTTP "+C.status);k(m),F(d("flow:fileEdit.saved")),l&&l()}catch(z){B(z.message||String(z))}finally{j(!1)}}}async function W(){if(!(!u||P||!m)){_(!0),B("");try{const I=await u(m);typeof I=="string"&&I&&g(I)}catch(I){B(I.message||String(I))}finally{_(!1)}}}function O(){g(b),B(""),F("")}const $=m.length>1e5;return o.jsx("div",{className:"af-shortcuts-overlay",role:"presentation",onMouseDown:I=>{I.target===I.currentTarget&&t()},children:o.jsxs("div",{ref:c,className:"af-shortcuts-panel af-file-edit-panel",role:"dialog","aria-modal":"true","aria-labelledby":f,tabIndex:-1,onMouseDown:I=>I.stopPropagation(),children:[o.jsxs("div",{className:"af-shortcuts-panel__head",children:[o.jsx("h2",{id:f,className:"af-shortcuts-panel__title",children:a||i}),o.jsx("button",{type:"button",className:"af-shortcuts-panel__close af-icon-btn",onClick:t,"aria-label":d("flow:fileEdit.close"),children:o.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),o.jsx("div",{className:"af-file-edit-body",children:y?o.jsx("div",{className:"af-file-edit-loading",children:d("flow:fileEdit.loading")}):L&&!m?o.jsx("div",{className:"af-file-edit-error",children:L}):o.jsxs(o.Fragment,{children:[$&&o.jsx("div",{className:"af-file-edit-warning",children:d("flow:fileEdit.largeFileWarning")}),o.jsx("textarea",{ref:p,className:"af-file-edit-textarea",value:m,onChange:I=>g(I.target.value),spellCheck:!1,placeholder:d("flow:fileEdit.placeholder")})]})}),(L||D)&&!y&&o.jsx("div",{className:`af-file-edit-status${D?" af-file-edit-status--success":""}`,children:D||L}),o.jsxs("div",{className:"af-file-edit-actions",children:[o.jsx("button",{type:"button",className:"af-btn-secondary",onClick:O,disabled:!R||w||P,children:d("flow:fileEdit.reset")}),u&&o.jsx("button",{type:"button",className:"af-btn-secondary af-btn-ai",onClick:W,disabled:P||w||!m,children:d(P?"flow:fileEdit.aiRunning":"flow:fileEdit.aiEdit")}),o.jsx("button",{type:"button",className:"af-btn-primary",onClick:M,disabled:!R||w||P,children:d(w?"flow:fileEdit.saving":"flow:fileEdit.save")})]})]})})}const MT=new Set(["workspaceRoot","pipelineWorkspace","cwd","flowName","runDir","flowDir"]),NK=["workspaceRoot","pipelineWorkspace","cwd","flowName","runDir","flowDir"];function jK(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 CK(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 Fj(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 $T(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(MT.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 DT(e){return{inputNames:Fj(e==null?void 0:e.inputs),outputNames:Fj(e==null?void 0:e.outputs)}}function EK(e,t,n){const r=DT(t),s=CK(e),i=[];for(const a of s)if(!$T(a.key,r)){const l=a.key.trim()===""?n("flow:placeholder.empty"):a.key.trim();i.push({start:a.start,end:a.end,message:n("flow:placeholder.invalidPlaceholder",{hint:l})})}return i}function _K(e,t){const n=DT(t),r=/\$\{([^}]*)\}/g,s=[];let i=0,a;for(;(a=r.exec(e))!==null;){a.index>i&&s.push({kind:"plain",text:e.slice(i,a.index)});const l=a[0],u=$T(a[1],n);s.push({kind:u?"ph-valid":"ph-invalid",text:l}),i=a.index+l.length}return i<e.length&&s.push({kind:"plain",text:e.slice(i)}),s}function PK(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function AK(e){return e.map(t=>{const n=PK(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 IK(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 i=(r==null?void 0:r.type)!=null?String(r.type):"";n.push({section:"input",insert:`input.${s}`,label:s,subtitle:i?t("flow:placeholder.inputSubtitle",{type:i}):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 i=(r==null?void 0:r.type)!=null?String(r.type):"";n.push({section:"output",insert:`output.${s}`,label:s,subtitle:i?t("flow:placeholder.outputSubtitle",{type:i}):t("flow:placeholder.outputSubtitleNoType")})}for(const r of NK)MT.has(r)&&n.push({section:"runtime",insert:r,label:r,subtitle:t("flow:placeholder.runtimeConst")});return n}function TK(e,t){const n=t.toLowerCase();return n?e.filter(r=>[r.insert,r.label,r.subtitle??""].map(i=>String(i).toLowerCase()).some(i=>i.includes(n))):e}function RK(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 i=e.clientWidth;if(i<=0)return null;s.style.width=`${i}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(),u=parseFloat(r.lineHeight),d=Number.isFinite(u)&&u>0?u:l.height||16;return document.body.removeChild(s),{top:l.top,left:l.left,bottom:l.bottom,height:d}}function Ah({value:e,onChange:t,disabled:n,placeholder:r,rows:s=8,textareaClassName:i,ioSlots:a,variant:l="drawer",images:u,onImagesChange:d}){const{t:f}=Pn(),c=h.useId(),p=h.useRef(null),m=h.useRef(null),[g,b]=h.useState(0),[k,y]=h.useState(0),[v,w]=h.useState(null),j=h.useMemo(()=>Ps(u),[u]),P=h.useMemo(()=>EK(e,a,f),[e,a,f]),_=P.length>0,L=h.useMemo(()=>_K(e,a),[e,a]),B=h.useMemo(()=>AK(L),[L]),D=h.useMemo(()=>n?null:jK(e,g),[e,g,n]),F=h.useMemo(()=>{if(!D)return[];const I=IK(a,f);return TK(I,D.query)},[D,a,f]);h.useEffect(()=>{y(I=>{const z=Math.max(0,F.length-1);return Math.min(Math.max(0,I),z)})},[F.length]);const R=h.useCallback(()=>{const I=p.current;if(!I||!D||F.length===0){w(null);return}const z=RK(I,g);if(!z){w(null);return}const C=4,T=44,E=13.5*16,G=Math.min(F.length*T+8,E);let Z=z.bottom+C;Z+G>window.innerHeight-8&&(Z=Math.max(8,z.top-G-C));const V=288;let se=z.left;se=Math.max(8,Math.min(se,window.innerWidth-V-8)),w({top:Z,left:se})},[D,F.length,g]);h.useLayoutEffect(()=>{if(!D||F.length===0){w(null);return}const I=requestAnimationFrame(()=>R());return()=>cancelAnimationFrame(I)},[D,F.length,g,e,R]),h.useEffect(()=>{if(!D||F.length===0)return;const I=()=>R();return window.addEventListener("scroll",I,!0),window.addEventListener("resize",I),()=>{window.removeEventListener("scroll",I,!0),window.removeEventListener("resize",I)}},[D,F.length,R]);const M=h.useCallback(I=>{if(!D)return;const{atIndex:z}=D,C=e.slice(0,z)+"${"+I+"}"+e.slice(g);t(C);const T=z+I.length+3;queueMicrotask(()=>{const E=p.current;E&&(E.focus(),E.setSelectionRange(T,T)),b(T)})},[D,e,g,t]),W=h.useCallback(()=>{const I=p.current,z=m.current;!I||!z||(z.scrollTop=I.scrollTop,z.scrollLeft=I.scrollLeft,D&&F.length>0&&queueMicrotask(()=>R()))},[D,F.length,R]),O=h.useCallback(I=>{if(!n&&D&&F.length>0&&(I.key==="ArrowDown"||I.key==="ArrowUp"||I.key==="Enter")){if(I.key==="ArrowDown")I.preventDefault(),y(z=>(z+1)%F.length);else if(I.key==="ArrowUp")I.preventDefault(),y(z=>(z-1+F.length)%F.length);else if(I.key==="Enter"&&!I.shiftKey){I.preventDefault();const z=F[k];z&&M(z.insert)}}},[n,D,F,k,M]),$=h.useCallback(async I=>{if(n||typeof d!="function")return!1;const z=await jT({files:I,body:e,images:j});return z?(t(z.body),d(z.images),queueMicrotask(()=>{const C=p.current;if(!C)return;C.focus();const T=z.body.length;C.setSelectionRange(T,T),b(T)}),!0):!1},[n,j,t,d,e]);return o.jsxs("div",{className:"af-body-prompt-editor"+(l==="expand"?" af-body-prompt-editor--expand":""),children:[j.length>0?o.jsx("div",{className:"af-body-image-list","aria-label":"image attachments",children:j.map((I,z)=>o.jsxs("span",{className:"af-body-image-chip",title:I.name,children:[o.jsx("img",{src:I.dataUrl,alt:""}),o.jsxs("span",{children:["[",I.label||`image ${z+1}`,"]"]})]},I.id||z))}):null,o.jsxs("div",{className:"af-body-prompt-stack",children:[o.jsx("pre",{ref:m,className:"af-body-prompt-backdrop "+i,"aria-hidden":"true",dangerouslySetInnerHTML:{__html:B+`
128
- `}}),o.jsx("textarea",{ref:p,className:"af-body-prompt-textarea "+i,rows:s,value:e,disabled:n,placeholder:r,spellCheck:!1,"aria-invalid":_,"aria-describedby":_?c:void 0,onChange:I=>{t(I.target.value),b(I.target.selectionStart??I.target.value.length)},onSelect:I=>{const z=I.target;z instanceof HTMLTextAreaElement&&b(z.selectionStart??0)},onClick:I=>{const z=I.target;z instanceof HTMLTextAreaElement&&b(z.selectionStart??0)},onKeyUp:I=>{const z=I.target;z instanceof HTMLTextAreaElement&&b(z.selectionStart??z.value.length)},onKeyDown:O,onPaste:I=>{const z=NT(I);z.length!==0&&(I.preventDefault(),$(z).catch(()=>{}))},onDragOver:I=>{ig(I).length>0&&I.preventDefault()},onDrop:I=>{const z=ig(I);z.length!==0&&(I.preventDefault(),$(z).catch(()=>{}))},onScroll:W})]}),D&&F.length>0&&v?Or.createPortal(o.jsx("ul",{className:"af-body-ph-menu af-body-ph-menu--pop af-composer-mention-menu",role:"listbox","aria-label":f("flow:nodeProps.placeholderSlots"),style:{position:"fixed",top:v.top,left:v.left,right:"auto",bottom:"auto",margin:0,zIndex:2e4},children:F.map((I,z)=>o.jsx("li",{role:"option","aria-selected":z===k,children:o.jsxs("button",{type:"button",className:"af-composer-mention-item"+(z===k?" af-composer-mention-item--active":""),onMouseDown:C=>C.preventDefault(),onMouseEnter:()=>y(z),onClick:()=>M(I.insert),children:[o.jsx("span",{className:"af-composer-mention-id",children:`\${${I.insert}}`}),I.subtitle?o.jsx("span",{className:"af-composer-mention-sub",children:I.subtitle}):null]})},`${I.section}-${I.insert}`))}),document.body):null,_?o.jsx("p",{id:c,className:"af-body-ph-issues",role:"status",children:P.map(I=>I.message).join(" · ")}):null]})}const FT=/^[a-zA-Z_][a-zA-Z0-9_-]*$/;function Ih(e){const t=e.indexOf(" - ");return t>=0?e.slice(0,t).trim():e.trim()}function zj({kind:e,label:t,slots:n,onSlotsChange:r,disabled:s,requiredReadonly:i=!0}){const{t:a}=Pn(),l=()=>r([...n,{type:"text",name:"",default:"",required:!1,showOnNode:!1}]),u=c=>r(n.filter((p,m)=>m!==c)),d=(c,p,m)=>{const g=n.map((b,k)=>{if(k!==c)return b;const y={...b,[p]:m};return p==="required"&&m===!0&&(y.showOnNode=!0),y});r(g)},f=e==="input"?"input":"output";return o.jsxs("div",{className:"af-node-props-field af-node-props-field--io",children:[o.jsxs("div",{className:"af-node-props-io-head",children:[o.jsx("span",{className:"af-node-props-label",children:t}),o.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")})]}),o.jsx("p",{className:"af-node-props-io-hint",children:a("flow:nodeProps.handleHint",{prefix:f})}),n.length===0?o.jsx("p",{className:"af-node-props-io-empty",children:a(e==="input"?"flow:nodeProps.noInputPins":"flow:nodeProps.noOutputPins")}):null,n.length>0?o.jsxs("div",{className:"af-node-props-io-table",role:"group","aria-label":t,children:[o.jsxs("div",{className:"af-node-props-io-table-head","aria-hidden":!0,children:[o.jsx("span",{children:a("flow:nodeProps.handle")}),o.jsx("span",{children:a("flow:nodeProps.type")}),o.jsx("span",{children:a("flow:nodeProps.name")}),o.jsx("span",{children:a("flow:nodeProps.defaultValue")}),o.jsx("span",{children:a("flow:nodeProps.required")}),o.jsx("span",{children:a("flow:nodeProps.showOnNode")}),o.jsx("span",{})]}),n.map((c,p)=>o.jsxs("div",{className:"af-node-props-io-row",children:[o.jsxs("span",{className:"af-node-props-io-handle",title:`${f}-${p}`,children:[f,"-",p]}),o.jsx("select",{className:"af-node-props-input af-node-props-io-cell",value:c.type,onChange:m=>d(p,"type",m.target.value),disabled:s,"aria-label":a("flow:nodeProps.pinTypeAriaLabel",{label:t,index:p}),children:["node","text","file","bool"].map(m=>o.jsx("option",{value:m,children:m},m))}),o.jsx("input",{type:"text",className:"af-node-props-input af-node-props-io-cell",value:c.name,onChange:m=>d(p,"name",m.target.value),disabled:s,spellCheck:!1,autoComplete:"off","aria-label":a("flow:nodeProps.pinNameAriaLabel",{label:t,index:p})}),o.jsx("input",{type:"text",className:"af-node-props-input af-node-props-io-cell",value:c.default,onChange:m=>d(p,"default",m.target.value),disabled:s,spellCheck:!1,autoComplete:"off","aria-label":a("flow:nodeProps.pinDefaultAriaLabel",{label:t,index:p})}),o.jsx("label",{className:"af-node-props-io-flag",title:a("flow:nodeProps.requiredHint"),children:o.jsx("input",{type:"checkbox",checked:!!c.required,onChange:m=>{i||d(p,"required",m.target.checked)},disabled:s||i,"aria-label":a("flow:nodeProps.pinRequiredAriaLabel",{label:t,index:p})})}),o.jsx("label",{className:"af-node-props-io-flag",title:a("flow:nodeProps.showOnNodeHint"),children:o.jsx("input",{type:"checkbox",checked:c.showOnNode!==!1,onChange:m=>d(p,"showOnNode",m.target.checked),disabled:s,"aria-label":a("flow:nodeProps.pinShowOnNodeAriaLabel",{label:t,index:p})})}),o.jsx("button",{type:"button",className:"af-icon-btn af-node-props-io-remove",onClick:()=>u(p),disabled:s,"aria-label":a("flow:nodeProps.deletePinAriaLabel",{label:t,index:p}),title:a("flow:nodeProps.deletePin"),children:o.jsx("span",{className:"material-symbols-outlined",children:"delete"})})]},`${f}-${p}`))]}):null]})}function zT({draft:e,setDraft:t,definitionId:n,systemPromptReadonly:r,modelLists:s,disabled:i,onIdBlur:a,onClose:l,onPublishToMarketplace:u,allowEditRequiredPins:d=!1,error:f,ioSlots:c}){const{t:p}=Pn(),[m,g]=h.useState(!1),[b,k]=h.useState(!1),[y,v]=h.useState({status:"idle",message:""}),w=h.useCallback(M=>{t(W=>W&&{...W,...M})},[t]),{cursorList:j,opencodeList:P,claudeCodeList:_,currentNotInLists:L}=h.useMemo(()=>{const M=Array.isArray(s==null?void 0:s.cursor)?s.cursor:[],W=Array.isArray(s==null?void 0:s.opencode)?s.opencode:[],O=Array.isArray(s==null?void 0:s.claudeCode)?s.claudeCode:[],$=new Set([...M,...W,...O].map(Ih)),I=((e==null?void 0:e.model)??"").trim(),z=I.startsWith("cursor:")?I.slice(7):I.startsWith("opencode:")?I.slice(9):I.startsWith("claude-code:")?I.slice(12):I,C=I&&!$.has(z)?I:"";return{cursorList:M,opencodeList:W,claudeCodeList:O,currentNotInLists:C}},[s,e==null?void 0:e.model]);if(!e)return null;const B=String(e.script??""),D=n==="tool_nodejs"||B.trim()!=="",F=typeof u=="function"&&!i&&(e==null?void 0:e.newId),R=async()=>{if(F){v({status:"running",message:p("flow:nodeProps.publishRunning")});try{const M=await u(e,n);v({status:"success",message:M!=null&&M.definitionId?p("flow:nodeProps.publishSuccessWithId",{id:M.definitionId}):p("flow:nodeProps.publishSuccess")})}catch(M){v({status:"error",message:String((M==null?void 0:M.message)||M)})}}};return o.jsxs(o.Fragment,{children:[o.jsxs("div",{className:"af-pipeline-drawer-head af-node-props-head",children:[o.jsx("h2",{className:"af-pipeline-drawer-title",children:p("flow:nodeProps.title")}),o.jsxs("div",{className:"af-node-props-head-actions",children:[o.jsxs("button",{type:"button",className:"af-btn-ghost af-node-props-market-btn",onClick:R,disabled:!F||y.status==="running",title:p("flow:nodeProps.publishToMarketplaceHint"),children:[o.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"inventory_2"}),y.status==="running"?p("flow:nodeProps.publishing"):p("flow:nodeProps.publishToMarketplace")]}),o.jsx("button",{type:"button",className:"af-btn-ghost af-node-props-close-secondary",onClick:l,children:p("common:common.close")})]})]}),o.jsxs("div",{className:"af-pipeline-drawer-body af-node-props-body",children:[f?o.jsx("p",{className:"af-err af-node-props-err",children:f}):null,y.message?o.jsx("p",{className:`af-node-props-market-status af-node-props-market-status--${y.status}`,children:y.message}):null,o.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[o.jsx("span",{className:"af-node-props-label",children:p("flow:node.nodeType")}),o.jsx("div",{className:"af-pipeline-drawer-readonly af-node-props-readonly-mono",children:n})]}),o.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[o.jsxs("span",{className:"af-node-props-label",children:[p("flow:nodeProps.instanceId"),o.jsx("span",{className:"af-node-props-hint",children:p("flow:node.displayNameHint")})]}),o.jsx("input",{type:"text",className:"af-node-props-input",value:e.newId,onChange:M=>w({newId:M.target.value}),onBlur:a,disabled:i,spellCheck:!1,autoComplete:"off","aria-label":p("flow:nodeProps.instanceId")})]}),o.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[o.jsxs("span",{className:"af-node-props-label",children:[p("flow:node.displayName"),"(LABEL)"]}),o.jsx("input",{type:"text",className:"af-node-props-input",value:e.label,onChange:M=>w({label:M.target.value}),disabled:i,spellCheck:!1})]}),o.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[o.jsxs("span",{className:"af-node-props-label",children:[p("flow:node.role"),"(ROLE)"]}),o.jsx("select",{className:"af-node-props-select",value:al.includes(e.role)?e.role:p("flow:roles.normal"),onChange:M=>w({role:M.target.value}),disabled:i,children:al.map(M=>o.jsx("option",{value:M,children:M},M))})]}),o.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[o.jsxs("span",{className:"af-node-props-label",children:[p("flow:node.model"),"(MODEL)"]}),o.jsx("span",{className:"af-node-props-sublabel",children:p("flow:node.modelHint")}),o.jsxs("select",{className:"af-node-props-select",value:(()=>{const M=(e.model||"").trim();return M?L||M:""})(),onChange:M=>w({model:M.target.value}),disabled:i,"aria-label":p("flow:nodeProps.modelAriaLabel"),children:[o.jsx("option",{value:"",children:p("flow:node.defaultModel")}),L?o.jsxs("option",{value:L,children:[L,p("flow:nodeProps.yamlValueNotInList")]}):null,j.length>0?o.jsx("optgroup",{label:"Cursor",children:j.map(M=>o.jsx("option",{value:Ih(M),children:M},`c-${M}`))}):null,P.length>0?o.jsx("optgroup",{label:"OpenCode",children:P.map(M=>o.jsx("option",{value:Ih(M),children:M},`o-${M}`))}):null,_.length>0?o.jsx("optgroup",{label:"Claude Code",children:_.map(M=>o.jsx("option",{value:`claude-code:${Ih(M)}`,children:M},`cc-${M}`))}):null]})]}),o.jsx(zj,{kind:"input",label:p("flow:nodeProps.inputPins"),slots:Array.isArray(e.inputs)?e.inputs:[],onSlotsChange:M=>w({inputs:M}),disabled:i,requiredReadonly:!d}),o.jsx(zj,{kind:"output",label:p("flow:nodeProps.outputPins"),slots:Array.isArray(e.outputs)?e.outputs:[],onSlotsChange:M=>w({outputs:M}),disabled:i,requiredReadonly:!d}),D?o.jsxs("div",{className:"af-pipeline-drawer-field af-node-props-field af-node-props-field--prompt",children:[o.jsxs("div",{className:"af-node-props-prompt-head",children:[o.jsxs("span",{className:"af-node-props-label",children:[p("flow:node.directCommand"),"(script)",o.jsx("span",{className:"af-node-props-hint",children:p("flow:node.scriptHint")})]}),o.jsx("button",{type:"button",className:"af-icon-btn af-node-props-expand",onClick:()=>k(!0),"aria-label":p("flow:nodeProps.expandEditScript"),title:p("flow:nodeProps.expand"),disabled:i,children:o.jsx("span",{className:"material-symbols-outlined",children:"open_in_full"})})]}),o.jsx(Ah,{value:B,onChange:M=>w({script:M}),disabled:i,placeholder:p("flow:nodeProps.scriptPlaceholder"),rows:6,textareaClassName:"af-pipeline-drawer-textarea af-node-props-body-textarea af-node-props-script-textarea",ioSlots:c,variant:"drawer"})]}):null,o.jsxs("div",{className:"af-pipeline-drawer-field af-node-props-field af-node-props-field--prompt",children:[o.jsxs("div",{className:"af-node-props-prompt-head",children:[o.jsx("span",{className:"af-node-props-label",children:p("flow:node.userPrompt")}),o.jsx("button",{type:"button",className:"af-icon-btn af-node-props-expand",onClick:()=>g(!0),"aria-label":p("flow:nodeProps.expandEdit"),title:p("flow:nodeProps.expand"),disabled:i,children:o.jsx("span",{className:"material-symbols-outlined",children:"open_in_full"})})]}),o.jsx(Ah,{value:e.body,onChange:M=>w({body:M}),images:e.images,onImagesChange:M=>w({images:M}),disabled:i,placeholder:p("flow:nodeProps.bodyPlaceholder"),rows:8,textareaClassName:"af-pipeline-drawer-textarea af-node-props-body-textarea",ioSlots:c,variant:"drawer"})]}),o.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[o.jsx("span",{className:"af-node-props-label",children:p("flow:node.systemDescription")}),o.jsx("textarea",{className:"af-pipeline-drawer-textarea af-node-props-system-readonly",rows:4,readOnly:!0,value:r||p("flow:nodeProps.noDescription"),spellCheck:!1})]})]}),b?o.jsx("div",{className:"af-node-props-expand-overlay",role:"dialog","aria-modal":"true","aria-label":p("flow:nodeProps.editScript"),onMouseDown:M=>{M.target===M.currentTarget&&k(!1)},children:o.jsxs("div",{className:"af-node-props-expand-panel",children:[o.jsxs("div",{className:"af-node-props-expand-head",children:[o.jsx("span",{className:"af-node-props-expand-title",children:p("flow:node.directCommand")}),o.jsx("button",{type:"button",className:"af-icon-btn",onClick:()=>k(!1),"aria-label":p("flow:nodeProps.collapse"),children:o.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),o.jsx(Ah,{value:B,onChange:M=>w({script:M}),disabled:i,placeholder:p("flow:nodeProps.scriptPlaceholderExpand"),rows:16,textareaClassName:"af-node-props-expand-textarea",ioSlots:c,variant:"expand"})]})}):null,m?o.jsx("div",{className:"af-node-props-expand-overlay",role:"dialog","aria-modal":"true","aria-label":p("flow:nodeProps.editUserPrompt"),onMouseDown:M=>{M.target===M.currentTarget&&g(!1)},children:o.jsxs("div",{className:"af-node-props-expand-panel",children:[o.jsxs("div",{className:"af-node-props-expand-head",children:[o.jsx("span",{className:"af-node-props-expand-title",children:p("flow:node.body")}),o.jsx("button",{type:"button",className:"af-icon-btn",onClick:()=>g(!1),"aria-label":p("flow:nodeProps.collapse"),children:o.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),o.jsx(Ah,{value:e.body,onChange:M=>w({body:M}),images:e.images,onImagesChange:M=>w({images:M}),disabled:i,placeholder:p("flow:nodeProps.bodyPlaceholderExpand"),rows:16,textareaClassName:"af-node-props-expand-textarea",ioSlots:c,variant:"expand"})]})}):null]})}function j0(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 LK(e){const t=j0(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 BT(e){try{return JSON.stringify(JSON.parse(e.trim()),null,2)}catch{return e}}function Bj({text:e}){const{t}=Pn(),n=e||"";return n.trim()?o.jsx("div",{className:"af-run-ctx-md",children:o.jsx(pp,{children:n})}):o.jsx("div",{className:"af-run-ctx-hint",children:t("flow:runContext.empty")})}function Hj({o:e}){var r;const{t}=Pn(),n=j0(e);if(n==="image"||e.encoding==="base64"&&((r=e.mimeType)!=null&&r.startsWith("image/"))){const i=`data:${e.mimeType||"image/png"};base64,${e.content||""}`;return o.jsxs("div",{className:"af-run-ctx-media",children:[o.jsx("img",{className:"af-run-ctx-img",src:i,alt:e.slot||"output",loading:"lazy"}),e.truncated?o.jsx("div",{className:"af-run-ctx-hint",children:t("flow:runContext.imageTruncated")}):null]})}if(n==="json")return o.jsx("pre",{className:"af-run-ctx-pre",children:BT(e.content||"")});if(n==="markdown"){const s=e.content||"";return s.trim()?o.jsx("div",{className:"af-run-ctx-md",children:o.jsx(pp,{children:s})}):o.jsx("div",{className:"af-run-ctx-hint",children:t("flow:runContext.empty")})}return o.jsx("pre",{className:"af-run-ctx-pre",children:e.content!=null&&e.content!==""?e.content:t("flow:runContext.empty")})}function Wj(e){return LK(e)}function Vj(e){var r;if(!e)return null;const t=j0(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"?BT(String(n)):String(n)}function Uj({text:e,title:t,copiedLabel:n}){const[r,s]=h.useState(!1);if(!e)return null;const i=async()=>{try{await navigator.clipboard.writeText(e),s(!0),window.setTimeout(()=>s(!1),1400)}catch{}};return o.jsx("button",{type:"button",className:"af-icon-btn af-run-ctx-copy-btn",onClick:i,title:r?n:t,"aria-label":r?n:t,children:o.jsx("span",{className:"material-symbols-outlined",children:r?"check":"content_copy"})})}const Kj=2e4,HT="af:run-node-ctx-width";function lm(){return typeof window>"u"?416:Math.min(26*16,window.innerWidth-32)}function Wa(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):Wa(lm())}function OK(){try{const e=localStorage.getItem(HT);if(e==null)return Wa(lm());const t=parseInt(e,10);return Number.isFinite(t)?Wa(t):Wa(lm())}catch{return Wa(lm())}}async function qj(e,t,n,r){const s=new URLSearchParams({flowId:e,instanceId:t});n&&String(n).trim()&&s.set("runId",String(n).trim());const i=await fetch(`/api/node-exec-context?${s.toString()}`,{signal:r}),a=await i.text();let l;try{l=JSON.parse(a)}catch{throw new Error(a.startsWith("<!")||a.startsWith("<html")?"apiConnectError":"invalidJson")}if(!i.ok)throw new Error(l.error||"HTTP "+i.status);return l}function MK(e,t){const n=`flow:runContext.${t}`,r=e(n);return r!==n?r:t}function $K({instanceId:e,flowId:t,runId:n,nodeStatus:r,onClose:s}){const{t:i}=Pn(),[a,l]=h.useState(()=>typeof window<"u"&&window.matchMedia("(max-width: 960px)").matches),[u,d]=h.useState(OK),f=h.useRef({active:!1,pointerId:-1,startX:0,startW:416}),[c,p]=h.useState(!0),[m,g]=h.useState(""),[b,k]=h.useState([]),[y,v]=h.useState(null),[w,j]=h.useState(null),P=h.useRef(null),_=h.useRef(null),L=h.useRef(0),B=h.useRef(0);h.useLayoutEffect(()=>{const C=window.matchMedia("(max-width: 960px)"),T=()=>l(C.matches);return C.addEventListener("change",T),()=>C.removeEventListener("change",T)},[]),h.useEffect(()=>{function C(){d(T=>Wa(T))}return window.addEventListener("resize",C),()=>window.removeEventListener("resize",C)},[]);const D=h.useCallback(()=>{d(C=>{const T=Wa(C);try{localStorage.setItem(HT,String(T))}catch{}return T})},[]),F=h.useCallback(C=>{if(a||C.button!==0)return;C.preventDefault();const T=C.currentTarget;f.current={active:!0,pointerId:C.pointerId,startX:C.clientX,startW:u},T.setPointerCapture(C.pointerId)},[a,u]),R=h.useCallback(C=>{const T=f.current;if(!T.active||C.pointerId!==T.pointerId)return;const E=T.startX-C.clientX;d(Wa(T.startW+E))},[]),M=h.useCallback(C=>{const T=f.current;if(!(!T.active||C.pointerId!==T.pointerId)){T.active=!1;try{C.currentTarget.releasePointerCapture(C.pointerId)}catch{}D()}},[D]),W=h.useCallback(()=>{const C=f.current;C.active&&(C.active=!1,D())},[D]),O=h.useCallback(C=>{const T=Array.isArray(C)?C:[];k(T),v(E=>E&&T.some(G=>G.execId===E)?E:T.length>0?T[T.length-1].execId:null)},[]),$=h.useCallback(()=>{if(!e||!t)return;const C=++L.current,T=new AbortController,E=window.setTimeout(()=>T.abort(),Kj);(async()=>{try{const G=await qj(t,e,n,T.signal);if(C!==L.current)return;O(Array.isArray(G.rounds)?G.rounds:[])}catch{}finally{window.clearTimeout(E)}})()},[e,t,n,O]);h.useEffect(()=>{if(!e||!t){p(!1),g(""),k([]);return}const C=++B.current;p(!0),g(""),k([]),v(null);const T=new AbortController,E=window.setTimeout(()=>T.abort(),Kj);return(async()=>{try{const G=await qj(t,e,n,T.signal);if(C!==B.current)return;O(Array.isArray(G.rounds)?G.rounds:[])}catch(G){if(C!==B.current)return;const Z=(G==null?void 0:G.name)==="AbortError"?"requestTimeout":G.message||String(G);g(Z)}finally{window.clearTimeout(E),C===B.current&&p(!1)}})(),()=>{T.abort(),B.current++,L.current++}},[e,t,n,O]),h.useEffect(()=>{r&&$()},[r,$]),h.useEffect(()=>{clearInterval(_.current);const C=b.length>0?b[b.length-1]:null;return(r==="running"&&b.length===0||!!(C&&C.status==="running"))&&e&&t&&(_.current=setInterval(()=>$(),2e3)),()=>clearInterval(_.current)},[b,e,t,n,r,$]),h.useEffect(()=>{P.current&&(P.current.scrollTop=0)},[y]);const I=b.find(C=>C.execId===y),z=a?void 0:{width:`${u}px`};return o.jsxs("aside",{className:"af-run-ctx-panel",style:z,"aria-label":i("flow:runContext.title"),children:[a?null:o.jsx("div",{className:"af-run-ctx-resize",role:"separator","aria-orientation":"vertical","aria-label":i("flow:runContext.resizeHandle"),onPointerDown:F,onPointerMove:R,onPointerUp:M,onPointerCancel:M,onLostPointerCapture:W}),o.jsxs("div",{className:"af-run-ctx-panel__main",children:[o.jsxs("div",{className:"af-run-ctx-head",children:[o.jsx("h2",{className:"af-run-ctx-title",title:e,children:e}),o.jsx("button",{type:"button",className:"af-icon-btn",onClick:s,"aria-label":i("common:common.close"),children:o.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),c&&o.jsx("div",{className:"af-run-ctx-placeholder",children:i("common:common.loading")}),m&&o.jsx("div",{className:"af-run-ctx-error",children:MK(i,m)}),!c&&!m&&b.length===0&&o.jsx("div",{className:"af-run-ctx-placeholder",children:i(r==="running"?"flow:runContext.executingNoArtifacts":"flow:runContext.noData")}),b.length>0&&o.jsxs(o.Fragment,{children:[o.jsxs("div",{className:"af-run-ctx-rounds af-run-ctx-rounds--select af-run-ctx-round--"+FK((I==null?void 0:I.status)||""),children:[o.jsx("span",{className:"af-run-ctx-round-dot","aria-hidden":!0}),o.jsx("select",{className:"af-run-ctx-round-select",value:String(y??""),onChange:C=>{const T=C.target.value;v(T==="latest"?"latest":Number(T))},children:[...b].reverse().map(C=>{const T=C.execId==="latest"?i("flow:runContext.latest"):`#${C.execId}`,E=zK(i,C.status),G=C.finishedAt?` · ${DK(C.finishedAt)}`:"";return o.jsx("option",{value:String(C.execId),children:`${T} · ${E}${G}`},C.execId)})})]}),I&&o.jsxs("div",{className:"af-run-ctx-body",ref:P,children:[I.inputs&&I.inputs.length>0&&o.jsxs("section",{className:"af-run-ctx-section",children:[o.jsxs("h3",{className:"af-run-ctx-section-title",children:[o.jsx("span",{className:"material-symbols-outlined af-run-ctx-section-icon","aria-hidden":!0,children:"input"}),"Inputs"]}),I.inputs.map((C,T)=>o.jsxs("div",{className:"af-run-ctx-output-slot",children:[o.jsx("div",{className:"af-run-ctx-slot-head",children:o.jsx("div",{className:"af-run-ctx-slot-name",children:C.slot})}),o.jsx("pre",{className:"af-run-ctx-slot-text",children:C.value})]},`${C.slot}-${T}`))]}),I.prompt!=null&&o.jsxs("section",{className:"af-run-ctx-section",children:[o.jsxs("h3",{className:"af-run-ctx-section-title",children:[o.jsx("span",{className:"material-symbols-outlined af-run-ctx-section-icon","aria-hidden":!0,children:"description"}),"Prompt",o.jsx("button",{type:"button",className:"af-icon-btn af-run-ctx-section-expand",onClick:()=>j("prompt"),title:i("flow:nodeProps.expand"),children:o.jsx("span",{className:"material-symbols-outlined",children:"open_in_full"})})]}),o.jsx(Bj,{text:I.prompt})]}),I.outputs&&I.outputs.length>0&&o.jsxs("section",{className:"af-run-ctx-section",children:[o.jsxs("h3",{className:"af-run-ctx-section-title",children:[o.jsx("span",{className:"material-symbols-outlined af-run-ctx-section-icon","aria-hidden":!0,children:"output"}),"Outputs",o.jsx("button",{type:"button",className:"af-icon-btn af-run-ctx-section-expand",onClick:()=>j("output"),title:i("flow:nodeProps.expand"),children:o.jsx("span",{className:"material-symbols-outlined",children:"open_in_full"})})]}),I.outputs.map((C,T)=>{const E=Wj(C),G=Vj(C);return o.jsxs("div",{className:"af-run-ctx-output-slot",children:[o.jsxs("div",{className:"af-run-ctx-slot-head",children:[o.jsx("div",{className:"af-run-ctx-slot-name",children:C.slot}),E?o.jsx("span",{className:"af-run-ctx-format-badge",title:i("flow:runContext.detectedContentType"),children:E}):null,o.jsx(Uj,{text:G,title:i("common:common.copy"),copiedLabel:i("common:common.copied")})]}),o.jsx(Hj,{o:C})]},`${C.slot}-${T}`)})]}),!I.prompt&&(!I.outputs||I.outputs.length===0)&&o.jsx("div",{className:"af-run-ctx-placeholder",children:i("flow:runContext.roundNoContent")})]})]})]}),w&&I&&o.jsx("div",{className:"af-node-props-expand-overlay",role:"dialog","aria-modal":"true",onClick:C=>{C.target===C.currentTarget&&j(null)},children:o.jsxs("div",{className:"af-node-props-expand-panel",children:[o.jsxs("div",{className:"af-node-props-expand-head",children:[o.jsx("span",{className:"af-node-props-expand-title",children:w==="prompt"?"Prompt":"Outputs"}),o.jsx("button",{type:"button",className:"af-icon-btn",onClick:()=>j(null),"aria-label":i("common:common.close"),children:o.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),o.jsxs("div",{className:"af-node-props-expand-body af-run-ctx-expand-body",children:[w==="prompt"&&I.prompt!=null&&o.jsx(Bj,{text:I.prompt}),w==="output"&&I.outputs&&I.outputs.map((C,T)=>{const E=Wj(C),G=Vj(C);return o.jsxs("div",{className:"af-run-ctx-output-slot",style:{marginBottom:"1rem"},children:[o.jsxs("div",{className:"af-run-ctx-slot-head",children:[o.jsx("div",{className:"af-run-ctx-slot-name",children:C.slot}),E?o.jsx("span",{className:"af-run-ctx-format-badge",children:E}):null,o.jsx(Uj,{text:G,title:i("common:common.copy"),copiedLabel:i("common:common.copied")})]}),o.jsx(Hj,{o:C})]},`${C.slot}-${T}`)})]})]})})]})}function DK(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 FK(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 zK(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 BK({flowId:e,flowSource:t,flowArchived:n,provideNodes:r,edges:s,nodes:i,onCliInputsChange:a,onBackToEdit:l}){const{t:u}=Pn(),[d,f]=h.useState({}),[c,p]=h.useState(null),[m,g]=h.useState({}),[b,k]=h.useState(!0),[y,v]=h.useState(!1),[w,j]=h.useState(""),[P,_]=h.useState(!1),[L,B]=h.useState(null),D=h.useRef(null),F=h.useRef(!0),R=h.useRef({});h.useMemo(()=>{var E,G,Z;const T={};for(const V of r){const se=(Z=(G=(E=V.data)==null?void 0:E.outputs)==null?void 0:G[0])==null?void 0:Z.default;se!=null&&se!==""&&(T[V.id]=String(se))}return R.current=T,T},[r]);const M=h.useMemo(()=>{var E;const T={};for(const G of i){if(!((E=G.data)!=null&&E.inputs))continue;const Z=G.data.inputs;for(let V=0;V<Z.length;V++){const se=Z[V];if(!(se!=null&&se.name))continue;const de=s.find(pe=>pe.target===G.id&&pe.targetHandle===`input-${V}`);if(!(de!=null&&de.source))continue;r.find(pe=>pe.id===de.source)&&(T[de.source]=se.name)}}return T},[i,s,r]);h.useEffect(()=>(F.current=!0,()=>{F.current=!1}),[]),h.useEffect(()=>{if(!e){k(!1);return}k(!0);const T=new URLSearchParams({flowId:e,flowSource:t||"user"});n&&T.set("archived","1"),fetch(`/api/flow/run-config?${T.toString()}`).then(E=>{if(!E.ok)throw new Error(`HTTP ${E.status}`);return E.json()}).then(E=>{var Z;if(!F.current)return;f(E.presets||{}),p(E.activePreset||null);const G=E.activePreset&&((Z=E.presets)!=null&&Z[E.activePreset])?E.presets[E.activePreset]:{};g({...R.current,...G}),k(!1)}).catch(()=>{F.current&&(g(R.current),k(!1))})},[e,t,n]),h.useEffect(()=>{var E;if(!a)return;const T={};for(const[G,Z]of Object.entries(m)){const V=M[G];if(!V)continue;const se=r.find(fe=>fe.id===G);if(!se)continue;(((E=se.data)==null?void 0:E.definitionId)||"").startsWith("provide_file")?T[V]={type:"file",path:Z}:T[V]={type:"str",value:Z}}a(T)},[m,M,r,a]);const W=h.useCallback((T,E)=>{g(G=>({...G,[T]:E}))},[]),O=h.useCallback(T=>{T!==c&&(p(T),T&&d[T]?g({...R.current,...d[T]}):g(R.current))},[c,d]),$=h.useCallback(async()=>{if(w.trim()){v(!0);try{const T={...d,[w.trim()]:m},E={flowId:e,flowSource:t,archived:n,presets:T,activePreset:w.trim()};(await fetch("/api/flow/run-config",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(E)})).ok&&(f(T),p(w.trim()),j(""),_(!1))}finally{v(!1)}}},[e,t,n,d,m,w]),I=h.useCallback(async()=>{if(c){v(!0);try{const T={...d};delete T[c];const E=Object.keys(T)[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:T,activePreset:E})})).ok&&(f(T),p(E),E&&T[E]?g({...R.current,...T[E]}):g(R.current))}finally{v(!1)}}},[e,t,n,d,c]),z=h.useCallback(async()=>{if(c){v(!0);try{const T={...d,[c]:m};(await fetch("/api/flow/run-config",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({flowId:e,flowSource:t,archived:n,presets:T,activePreset:c})})).ok&&f(T)}finally{v(!1)}}},[e,t,n,d,c,m]),C=Object.keys(d);return C.length>0,b?o.jsx("aside",{className:"af-run-config-panel",children:o.jsx("div",{className:"af-run-config-loading",children:u("common.loading")})}):o.jsxs("aside",{className:"af-run-config-panel",children:[o.jsxs("div",{className:"af-run-config-preset",children:[o.jsx("label",{className:"af-run-config-preset-label",children:u("flow:runConfig.preset")}),o.jsxs("div",{className:"af-run-config-preset-row",children:[o.jsxs("select",{className:"af-run-config-preset-select",value:c||"",onChange:T=>O(T.target.value||null),disabled:y,children:[o.jsx("option",{value:"",children:u("flow:runConfig.default")}),C.map(T=>o.jsx("option",{value:T,children:T},T))]}),o.jsx("button",{type:"button",className:"af-run-config-preset-btn af-run-config-preset-btn--new",onClick:()=>_(!0),disabled:y,title:u("flow:runConfig.newPreset"),children:o.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"add"})}),c&&o.jsx("button",{type:"button",className:"af-run-config-preset-btn af-run-config-preset-btn--save",onClick:z,disabled:y,title:u("flow:runConfig.savePreset"),children:o.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"save"})}),c&&o.jsx("button",{type:"button",className:"af-run-config-preset-btn af-run-config-preset-btn--delete",onClick:I,disabled:y,title:u("flow:runConfig.deletePreset"),children:o.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"delete"})})]})]}),P&&o.jsxs("div",{className:"af-run-config-save-dialog",children:[o.jsx("input",{type:"text",className:"af-run-config-save-input",placeholder:u("flow:runConfig.presetNamePlaceholder"),value:w,onChange:T=>j(T.target.value),disabled:y}),o.jsxs("div",{className:"af-run-config-save-actions",children:[o.jsx("button",{type:"button",className:"af-btn-primary",onClick:$,disabled:y||!w.trim(),children:u(y?"common.saving":"common.save")}),o.jsx("button",{type:"button",className:"af-btn-outline",onClick:()=>{_(!1),j("")},disabled:y,children:u("common.cancel")})]})]}),o.jsxs("div",{className:"af-run-config-inputs",children:[o.jsx("div",{className:"af-run-config-inputs-header",children:u("flow:runConfig.inputParams")}),r.length===0?o.jsx("div",{className:"af-run-config-empty",children:u("flow:runConfig.noProvideNodes")}):o.jsx("div",{className:"af-run-config-input-list",children:r.map(T=>{var pe,ae;const E=((pe=T.data)==null?void 0:pe.definitionId)||"",G=E.startsWith("provide_file"),Z=E==="provide_bool",V=((ae=T.data)==null?void 0:ae.label)||T.id,se=T.id,de=m[se]||"",fe=["true","1","yes","on"].includes(String(de).trim().toLowerCase());return o.jsxs("div",{className:"af-run-config-input-item",children:[o.jsxs("div",{className:"af-run-config-input-head",children:[o.jsx("span",{className:"af-run-config-input-icon material-symbols-outlined"+(G?" af-run-config-input-icon--file":""),"aria-hidden":!0,children:G?"description":Z?"toggle_on":"text_fields"}),o.jsx("span",{className:"af-run-config-input-label",children:V}),Z?null:o.jsx("button",{type:"button",className:"af-run-config-input-expand",onClick:()=>B({instanceId:se,label:V,content:de}),"aria-label":u("flow:runConfig.expandInput"),title:u("flow:runConfig.expandInput"),children:o.jsx("span",{className:"material-symbols-outlined",children:"open_in_full"})})]}),o.jsx("div",{className:"af-run-config-input-id",children:se}),Z?o.jsx("button",{type:"button",className:"af-run-config-bool-toggle"+(fe?" af-run-config-bool-toggle--true":""),onClick:()=>W(se,fe?"false":"true"),"aria-pressed":fe,children:fe?"true":"false"}):o.jsx("input",{type:"text",className:"af-run-config-input-field",value:de,onChange:be=>W(se,be.target.value),placeholder:u(G?"flow:runConfig.filePathPlaceholder":"flow:runConfig.stringValuePlaceholder")})]},se)})})]}),L&&Or.createPortal(o.jsx("div",{className:"af-provide-edit-overlay",children:o.jsxs("div",{className:"af-provide-edit-modal",role:"dialog","aria-modal":"true",children:[o.jsxs("div",{className:"af-provide-edit-modal__head",children:[o.jsx("span",{className:"material-symbols-outlined",children:"edit_document"}),o.jsx("span",{className:"af-provide-edit-modal__title",children:L.label}),o.jsx("button",{type:"button",className:"af-provide-edit-modal__close",onClick:()=>B(null),"aria-label":u("common:close"),children:o.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),o.jsx("div",{className:"af-provide-edit-modal__body",children:o.jsx("textarea",{ref:D,className:"af-provide-edit-modal__textarea",defaultValue:L.content,autoFocus:!0})}),o.jsxs("div",{className:"af-provide-edit-modal__foot",children:[o.jsxs("button",{type:"button",className:"af-provide-edit-modal__btn af-provide-edit-modal__btn--save",onClick:()=>{!L||!D.current||(W(L.instanceId,D.current.value),B(null))},children:[o.jsx("span",{className:"material-symbols-outlined",children:"save"}),u("flow:provideEdit.save")]}),o.jsxs("button",{type:"button",className:"af-provide-edit-modal__btn",onClick:()=>B(null),children:[o.jsx("span",{className:"material-symbols-outlined",children:"close"}),u("flow:provideEdit.cancel")]})]})]})}),document.body)]})}const WT={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"]},HK={"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 WK(e){return!e||e<1024?`${e||0} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/1024/1024).toFixed(2)} MB`}function VK(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 UK(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 Yj(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(WT))if(r.includes(e))return n;return"other"}function KK({event:e,defaultExpanded:t}){const[n,r]=h.useState(!!t),s=HK[e.tag]||"#a8a8a8",i=e.payload,a=i&&typeof i=="object",l=a?typeof i.text=="string"?i.text:"":String(i||""),u=a?i.meta:null,d=h.useMemo(()=>l?l.slice(0,140).replace(/\s+/g," "):a?Object.keys(i).filter(m=>m!=="text"&&m!=="meta").slice(0,3).map(m=>{const g=i[m];return g==null?`${m}:null`:typeof g=="object"?`${m}:{…}`:`${m}:${String(g).slice(0,30)}`}).join(" "):"",[i,l,a]),f=h.useCallback(c=>{c.stopPropagation();const p=a?JSON.stringify(i,null,2):String(i);try{navigator.clipboard.writeText(p)}catch{}},[i,a]);return o.jsxs("div",{style:{borderLeft:`3px solid ${s}`,background:n?"#1c1b1b":"#131313",marginBottom:4,borderRadius:4,cursor:"pointer",transition:"background 120ms"},onClick:()=>r(c=>!c),children:[o.jsxs("div",{style:{padding:"6px 10px",display:"flex",alignItems:"center",gap:10,fontSize:12},children:[o.jsx("span",{style:{color:"#9a9a9a",fontFamily:"monospace",flexShrink:0},children:VK(e.ts)}),o.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}),o.jsx("span",{style:{color:"#c5c2c1",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"monospace"},children:d}),n&&o.jsx("button",{type:"button",onClick:f,style:{background:"rgba(124,77,255,0.15)",color:"#e8deff",border:"none",borderRadius:3,padding:"2px 8px",fontSize:11,cursor:"pointer"},children:"Copy"})]}),n&&o.jsxs("div",{style:{padding:"0 10px 10px 10px",borderTop:"1px solid rgba(255,255,255,0.04)"},children:[u&&Object.keys(u).length>0&&o.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(u,null,2)}),l?o.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?o.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(i,null,2)}):null]})]})}function qK({open:e,onClose:t,flowId:n}){var B;const[r,s]=h.useState([]),[i,a]=h.useState(!1),[l,u]=h.useState(null),[d,f]=h.useState(null),[c,p]=h.useState(!1),[m,g]=h.useState(!0),[b,k]=h.useState({ai:!0,flow:!0,step:!0,output:!0,error:!0}),[y,v]=h.useState(""),w=h.useRef(null),j=h.useCallback(async()=>{a(!0);try{const D=m&&n?`?flowId=${encodeURIComponent(n)}`:"",R=await(await fetch(`/api/composer-logs${D}`)).json();s(Array.isArray(R.sessions)?R.sessions:[])}catch{s([])}finally{a(!1)}},[n,m]),P=h.useCallback(async D=>{if(!D){f(null);return}p(!0);try{const R=await(await fetch(`/api/composer-logs/${encodeURIComponent(D)}`)).json();f(R)}catch{f(null)}finally{p(!1)}},[]);h.useEffect(()=>{e&&j()},[e,j]),h.useEffect(()=>{if(!(!e||!l))return P(l),w.current=setInterval(()=>P(l),2e3),()=>{w.current&&clearInterval(w.current),w.current=null}},[e,l,P]);const _=h.useMemo(()=>{const D=(d==null?void 0:d.events)||[],F=y.trim().toLowerCase();return D.filter(R=>{const M=Yj(R.tag,R.payload);return!b[M]&&M!=="other"?!1:F?[R.tag,JSON.stringify(R.payload||"")].join(" ").toLowerCase().includes(F):!0})},[d,b,y]),L=h.useMemo(()=>{const D=(d==null?void 0:d.events)||[],F={};for(const R of D){const M=Yj(R.tag,R.payload);F[M]=(F[M]||0)+1}return F},[d]);return e?o.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:[o.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:[o.jsx("span",{style:{fontWeight:600,fontSize:14},children:"Composer Logs"}),o.jsx("span",{style:{fontSize:11,color:"#9a9a9a"},children:n?`flowId: ${n}`:"no flow selected"}),o.jsxs("label",{style:{fontSize:11,color:"#9a9a9a",display:"flex",alignItems:"center",gap:4,cursor:"pointer"},children:[o.jsx("input",{type:"checkbox",checked:m,onChange:D=>g(D.target.checked),disabled:!n}),"仅显示当前 flow"]}),o.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"}),o.jsx("span",{style:{flex:1}}),o.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"})]}),o.jsxs("div",{style:{flex:1,display:"flex",overflow:"hidden",minHeight:0},children:[o.jsxs("div",{style:{width:280,borderRight:"1px solid rgba(255,255,255,0.06)",overflowY:"auto",background:"#0e0e0e",flexShrink:0},children:[i&&o.jsx("div",{style:{padding:12,fontSize:12,color:"#9a9a9a"},children:"Loading…"}),!i&&r.length===0&&o.jsx("div",{style:{padding:12,fontSize:12,color:"#9a9a9a"},children:m&&n?"no sessions for this flow":"no sessions"}),r.map(D=>{const F=l===D.sessionId;return o.jsxs("div",{onClick:()=>u(D.sessionId),style:{padding:"10px 12px",borderBottom:"1px solid rgba(255,255,255,0.04)",cursor:"pointer",background:F?"rgba(124,77,255,0.18)":"transparent",borderLeft:F?"3px solid #7c4dff":"3px solid transparent"},children:[o.jsx("div",{style:{fontSize:12,fontWeight:600,color:"#e5e2e1"},children:UK(D.mtime)}),o.jsx("div",{style:{fontSize:11,color:"#9ecaff",marginTop:2,fontFamily:"monospace"},children:D.flowId||"(no flow)"}),D.promptPreview&&o.jsx("div",{style:{fontSize:11,color:"#9a9a9a",marginTop:4,overflow:"hidden",textOverflow:"ellipsis",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical"},children:D.promptPreview}),o.jsxs("div",{style:{fontSize:10,color:"#6a6a6a",marginTop:4},children:[WK(D.size)," · ",D.model||"default"]})]},D.sessionId)})]}),o.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",overflow:"hidden",minHeight:0},children:[o.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(WT).map(D=>o.jsxs("button",{type:"button",onClick:()=>k(F=>({...F,[D]:!F[D]})),style:{background:b[D]?"rgba(124,77,255,0.25)":"transparent",color:b[D]?"#e8deff":"#6a6a6a",border:`1px solid ${b[D]?"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:[D," ",L[D]!=null?`(${L[D]})`:""]},D)),o.jsx("input",{type:"text",placeholder:"search…",value:y,onChange:D=>v(D.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}})]}),o.jsxs("div",{style:{flex:1,overflowY:"auto",padding:12,minHeight:0},children:[!l&&o.jsx("div",{style:{color:"#9a9a9a",fontSize:12,padding:20,textAlign:"center"},children:"Select a session on the left to view events"}),c&&!d&&o.jsx("div",{style:{color:"#9a9a9a",fontSize:12,padding:20},children:"Loading…"}),d&&_.length===0&&o.jsxs("div",{style:{color:"#9a9a9a",fontSize:12,padding:20},children:["No events match current filter (",((B=d.events)==null?void 0:B.length)||0," total)"]}),_.map((D,F)=>o.jsx(KK,{event:D,defaultExpanded:D.tag==="error"},`${D.ts}_${F}`))]})]})]})]}):null}const YK="0.1.60";function Gj(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 Px(e,t){return t==="running"?Gj(e):e==null||!Number.isFinite(e)||e<=0?"--":Gj(e)}const VT=h.createContext({modelLists:{cursor:[],opencode:[]},onModelChange:()=>{}});function GK(e){var v,w,j,P,_,L,B,D,F,R,M;const{setNodes:t}=fc(),n=n0(),{modelLists:r,onModelChange:s}=h.useContext(VT),i=h.useRef(null),a=!!((v=e.data)!=null&&v.readOnly),l=(w=e.data)!=null&&w.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,u=((j=e.data)==null?void 0:j.definitionId)==="agent_subAgent"&&!((P=e.data)!=null&&P.isRunMode)&&!a,d=h.useCallback(W=>{const O=()=>n(W);window.requestAnimationFrame(O),window.setTimeout(O,80)},[n]),f=h.useCallback((W,O)=>{const $=r1(O);$&&(t(I=>I.map(z=>{var E,G,Z,V,se,de;if(z.id!==W)return z;const C=Number(((G=(E=z.data)==null?void 0:E.displaySize)==null?void 0:G.width)||z.width||((Z=z.measured)==null?void 0:Z.width)||0),T=Number(((se=(V=z.data)==null?void 0:V.displaySize)==null?void 0:se.height)||z.height||((de=z.measured)==null?void 0:de.height)||0);return Math.abs(C-$.width)<2&&Math.abs(T-$.height)<2?z:{...z,width:$.width,height:$.height,data:{...z.data,displaySize:$}}})),d(W))},[d,t]),c=h.useCallback(W=>{if(a)return;const O=i.current;if(!O)return;const $=O.getBoundingClientRect();f(W,{width:Math.max($.width,O.scrollWidth),height:Math.max($.height,O.scrollHeight)})},[f,a]),p=h.useCallback(W=>{var se,de,fe,pe,ae,be;if(!u)return;W.preventDefault(),W.stopPropagation();const O=i.current,$=O==null?void 0:O.getBoundingClientRect(),I=Number(((de=(se=e.data)==null?void 0:se.displaySize)==null?void 0:de.width)||e.width||((fe=e.measured)==null?void 0:fe.width)||($==null?void 0:$.width)||YT),z=Number(((ae=(pe=e.data)==null?void 0:pe.displaySize)==null?void 0:ae.height)||e.height||((be=e.measured)==null?void 0:be.height)||($==null?void 0:$.height)||Pb),C=W.clientX,T=W.clientY,E=e.id;let G=0;const Z=_e=>{const we=r1({width:I+_e.clientX-C,height:z+_e.clientY-T});we&&(window.cancelAnimationFrame(G),G=window.requestAnimationFrame(()=>f(E,we)))},V=()=>{window.cancelAnimationFrame(G),window.removeEventListener("pointermove",Z),window.removeEventListener("pointerup",V),window.removeEventListener("pointercancel",V),d(E)};window.addEventListener("pointermove",Z),window.addEventListener("pointerup",V,{once:!0}),window.addEventListener("pointercancel",V,{once:!0})},[f,(L=(_=e.data)==null?void 0:_.displaySize)==null?void 0:L.height,(D=(B=e.data)==null?void 0:B.displaySize)==null?void 0:D.width,e.height,e.id,(F=e.measured)==null?void 0:F.height,(R=e.measured)==null?void 0:R.width,e.width,d,u]),m=h.useCallback(W=>{t(O=>O.filter($=>$.id!==W))},[t]),g=h.useCallback(()=>{var I,z,C,T,E,G,Z,V;const W=((I=e.data)==null?void 0:I.definitionId)||"",O=((z=e.data)==null?void 0:z.label)||e.id,$=((E=(T=(C=e.data)==null?void 0:C.outputs)==null?void 0:T[0])==null?void 0:E.value)||((V=(Z=(G=e.data)==null?void 0:G.outputs)==null?void 0:Z[0])==null?void 0:V.default)||"";window.__provideEditContent={instanceId:e.id,label:O,definitionId:W,content:$},window.dispatchEvent(new CustomEvent("provide-expand"))},[e.id,e.data]),b=h.useCallback((W,O)=>{t($=>$.map(I=>{var C;if(I.id!==W)return I;const z=Array.isArray((C=I.data)==null?void 0:C.outputs)&&I.data.outputs.length?I.data.outputs.map((T,E)=>E===0?{...T,default:O,value:O}:T):[{type:"bool",name:"value",default:O,value:O}];return{...I,data:{...I.data,body:"",outputs:z}}}))},[t]),k=h.useCallback((W,O)=>{t($=>$.map(I=>I.id===W?{...I,data:{...I.data,body:O}}:I))},[t]),y=h.useCallback((W,O)=>{t($=>$.map(I=>I.id===W?{...I,data:{...I.data,images:Ps(O)}}:I))},[t]);return o.jsxs("div",{ref:i,className:"af-flow-node-shell"+(u?" af-flow-node-shell--resizable":""),style:l?{width:l.width,height:l.height}:void 0,children:[o.jsx(AT,{...e,data:{...e.data,onNodeContentResize:c},deleteNode:m,onProvideExpand:g,onProvideValueChange:b,onNodeBodyChange:k,onNodeImagesChange:y,modelLists:r,onModelChange:s}),u?o.jsx("span",{className:"af-flow-node-shell__resize-grip nodrag","aria-label":((M=e.data)==null?void 0:M.resizeLabel)||"Resize node",role:"separator",onPointerDown:p}):null]})}const XK={[mp]:GK},Wd=["CONTROL","TOOL","PROVIDE","AGENT"],JK=1200,Xj="af-flow-node--sync-flash",Jj="af-flow-edge--sync-flash";function Qj(e,t){const n=String(e||"").trim();return n?n.split(/\s+/).includes(t)?n:`${n} ${t}`:t}function Zj(e,t){const n=String(e||"").trim();return n?n.split(/\s+/).filter(r=>r&&r!==t).join(" "):""}function C0(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 QK(e){const t=C0(e);return t==="CONTROL"?"control":t==="PROVIDE"?"provide":t==="TOOL"?"tool":"agent"}function Th(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 UT(e){return String((e==null?void 0:e.label)||"").trim()||String((e==null?void 0:e.id)||"").trim()}function KT(e){return String((e==null?void 0:e.description)||(e==null?void 0:e.body)||"").replace(/\s+/g," ").trim()}function Ax(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 e1(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(),i=String((t==null?void 0:t.default)??(t==null?void 0:t.value)??"").trim();return[e,r,s?`type: ${s}`:"",i?`default: ${i}`:""].filter(Boolean).join(" · ")}function t1(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 ZK(e){return e==="CONTROL"?"account_tree":e==="TOOL"?"build":e==="PROVIDE"?"database":"smart_toy"}function e7(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 qT(e,t,n,r,s){const i=QK(e),a={id:t,type:mp,position:n,data:{label:e.label??e.id,definitionId:e.id,schemaType:i,inputs:Array.isArray(e.inputs)?e.inputs.map(l=>({...l})):[],outputs:Array.isArray(e.outputs)?e.outputs.map(l=>({...l})):[]}};return qf(a,r,s)}const YT=320,t7=220,n7=1600,Pb=104,r7=900;function n1(e,t,n){const r=Number(e);return!Number.isFinite(r)||r<=0?0:Math.min(n,Math.max(t,Math.round(r)))}function r1(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:n1(t,t7,n7)||YT,height:n1(n,Pb,r7)||Pb}}function s7(e){const t=(e==null?void 0:e.data)||{},n=r=>(Array.isArray(r)?r:[]).map((s,i)=>(s==null?void 0:s.showOnNode)===!1?"":[i,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 s1(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])),i=s.get(n),a=s.get(r),l=Ou(i,e.sourceHandle||"output-0","source"),u=Ou(a,e.targetHandle||"input-0","target");return!l||!u?!1:Lu(l,u)}function i7(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 i=t.find(l=>l.id===n),a=Ou(i,r,s);return a?{nodeId:n,handleId:r,handleType:s,slot:a,slotType:PT(a)}:null}function o7(e,t,n){var a;const r=qT(e,`__candidate_${e.id}`,{x:0,y:0},{},t),s=n.handleType==="source"?"inputs":"outputs",i=Array.isArray((a=r.data)==null?void 0:a[s])?r.data[s]:[];for(let l=0;l<i.length;l+=1){const u=i[l];if(n.handleType==="source"?Lu(n.slot,u):Lu(u,n.slot))return{slot:u,slotIndex:l,hydrated:r}}return null}function a7(e,t){return t?e.map((n,r)=>{const s=o7(n,e,t);if(!s)return null;const i=C0(n);return{def:n,order:r,category:i,categoryRank:Wd.indexOf(i),slot:s.slot,slotIndex:s.slotIndex,displayLabel:UT(s.hydrated.data||n),description:KT(n)}}).filter(Boolean).sort((n,r)=>{var a,l;const s=(a=n.slot)!=null&&a.required?0:1,i=(l=r.slot)!=null&&l.required?0:1;return s-i||n.slotIndex-r.slotIndex||n.categoryRank-r.categoryRank||n.order-r.order}):[]}const l7=/@([a-zA-Z_][a-zA-Z0-9_]*)/g;function c7(e){const t=new Set,n=[];let r;const s=new RegExp(l7.source,"g");for(;(r=s.exec(e))!==null;){const i=r[1];t.has(i)||(t.add(i),n.push(i))}return n}function i1(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 Qo(e){const t=String(e||"").indexOf(" - ");return t>=0?e.slice(0,t).trim():String(e||"").trim()}function Rh(e,t,n,r){const s=(e||"").trim();if(!s)return"";if(s.startsWith("opencode:")||s.startsWith("claude-code:"))return s;const i=Array.isArray(t)?t:[],a=Array.isArray(n)?n:[],l=Array.isArray(r)?r:[],u=i.map(Qo),d=a.map(Qo);return l.map(Qo).includes(s)&&!u.includes(s)&&!d.includes(s)?`claude-code:${s}`:d.includes(s)&&!u.includes(s)?`opencode:${s}`:s}function u7(e){if(e==null)return"";const t=String(e).trim();return t?t.length<=26?t:`${t.slice(0,12)}…${t.slice(-10)}`:""}function Ix(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 d7({steps:e}){const{t}=Pn();return!e||e.length===0?null:o.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,i=[`${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
+ `}}),o.jsx("textarea",{ref:p,className:"af-body-prompt-textarea "+i,rows:s,value:e,disabled:n,placeholder:r,spellCheck:!1,"aria-invalid":_,"aria-describedby":_?c:void 0,onChange:I=>{t(I.target.value),b(I.target.selectionStart??I.target.value.length)},onSelect:I=>{const z=I.target;z instanceof HTMLTextAreaElement&&b(z.selectionStart??0)},onClick:I=>{const z=I.target;z instanceof HTMLTextAreaElement&&b(z.selectionStart??0)},onKeyUp:I=>{const z=I.target;z instanceof HTMLTextAreaElement&&b(z.selectionStart??z.value.length)},onKeyDown:O,onPaste:I=>{const z=NT(I);z.length!==0&&(I.preventDefault(),$(z).catch(()=>{}))},onDragOver:I=>{ig(I).length>0&&I.preventDefault()},onDrop:I=>{const z=ig(I);z.length!==0&&(I.preventDefault(),$(z).catch(()=>{}))},onScroll:W})]}),D&&F.length>0&&v?Or.createPortal(o.jsx("ul",{className:"af-body-ph-menu af-body-ph-menu--pop af-composer-mention-menu",role:"listbox","aria-label":f("flow:nodeProps.placeholderSlots"),style:{position:"fixed",top:v.top,left:v.left,right:"auto",bottom:"auto",margin:0,zIndex:2e4},children:F.map((I,z)=>o.jsx("li",{role:"option","aria-selected":z===k,children:o.jsxs("button",{type:"button",className:"af-composer-mention-item"+(z===k?" af-composer-mention-item--active":""),onMouseDown:C=>C.preventDefault(),onMouseEnter:()=>y(z),onClick:()=>M(I.insert),children:[o.jsx("span",{className:"af-composer-mention-id",children:`\${${I.insert}}`}),I.subtitle?o.jsx("span",{className:"af-composer-mention-sub",children:I.subtitle}):null]})},`${I.section}-${I.insert}`))}),document.body):null,_?o.jsx("p",{id:c,className:"af-body-ph-issues",role:"status",children:P.map(I=>I.message).join(" · ")}):null]})}const FT=/^[a-zA-Z_][a-zA-Z0-9_-]*$/;function Ih(e){const t=e.indexOf(" - ");return t>=0?e.slice(0,t).trim():e.trim()}function zj({kind:e,label:t,slots:n,onSlotsChange:r,disabled:s,requiredReadonly:i=!0}){const{t:a}=Pn(),l=()=>r([...n,{type:"text",name:"",default:"",required:!1,showOnNode:!1}]),u=c=>r(n.filter((p,m)=>m!==c)),d=(c,p,m)=>{const g=n.map((b,k)=>{if(k!==c)return b;const y={...b,[p]:m};return p==="required"&&m===!0&&(y.showOnNode=!0),y});r(g)},f=e==="input"?"input":"output";return o.jsxs("div",{className:"af-node-props-field af-node-props-field--io",children:[o.jsxs("div",{className:"af-node-props-io-head",children:[o.jsx("span",{className:"af-node-props-label",children:t}),o.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")})]}),o.jsx("p",{className:"af-node-props-io-hint",children:a("flow:nodeProps.handleHint",{prefix:f})}),n.length===0?o.jsx("p",{className:"af-node-props-io-empty",children:a(e==="input"?"flow:nodeProps.noInputPins":"flow:nodeProps.noOutputPins")}):null,n.length>0?o.jsxs("div",{className:"af-node-props-io-table",role:"group","aria-label":t,children:[o.jsxs("div",{className:"af-node-props-io-table-head","aria-hidden":!0,children:[o.jsx("span",{children:a("flow:nodeProps.handle")}),o.jsx("span",{children:a("flow:nodeProps.type")}),o.jsx("span",{children:a("flow:nodeProps.name")}),o.jsx("span",{children:a("flow:nodeProps.defaultValue")}),o.jsx("span",{children:a("flow:nodeProps.required")}),o.jsx("span",{children:a("flow:nodeProps.showOnNode")}),o.jsx("span",{})]}),n.map((c,p)=>o.jsxs("div",{className:"af-node-props-io-row",children:[o.jsxs("span",{className:"af-node-props-io-handle",title:`${f}-${p}`,children:[f,"-",p]}),o.jsx("select",{className:"af-node-props-input af-node-props-io-cell",value:c.type,onChange:m=>d(p,"type",m.target.value),disabled:s,"aria-label":a("flow:nodeProps.pinTypeAriaLabel",{label:t,index:p}),children:["node","text","file","bool"].map(m=>o.jsx("option",{value:m,children:m},m))}),o.jsx("input",{type:"text",className:"af-node-props-input af-node-props-io-cell",value:c.name,onChange:m=>d(p,"name",m.target.value),disabled:s,spellCheck:!1,autoComplete:"off","aria-label":a("flow:nodeProps.pinNameAriaLabel",{label:t,index:p})}),o.jsx("input",{type:"text",className:"af-node-props-input af-node-props-io-cell",value:c.default,onChange:m=>d(p,"default",m.target.value),disabled:s,spellCheck:!1,autoComplete:"off","aria-label":a("flow:nodeProps.pinDefaultAriaLabel",{label:t,index:p})}),o.jsx("label",{className:"af-node-props-io-flag",title:a("flow:nodeProps.requiredHint"),children:o.jsx("input",{type:"checkbox",checked:!!c.required,onChange:m=>{i||d(p,"required",m.target.checked)},disabled:s||i,"aria-label":a("flow:nodeProps.pinRequiredAriaLabel",{label:t,index:p})})}),o.jsx("label",{className:"af-node-props-io-flag",title:a("flow:nodeProps.showOnNodeHint"),children:o.jsx("input",{type:"checkbox",checked:c.showOnNode!==!1,onChange:m=>d(p,"showOnNode",m.target.checked),disabled:s,"aria-label":a("flow:nodeProps.pinShowOnNodeAriaLabel",{label:t,index:p})})}),o.jsx("button",{type:"button",className:"af-icon-btn af-node-props-io-remove",onClick:()=>u(p),disabled:s,"aria-label":a("flow:nodeProps.deletePinAriaLabel",{label:t,index:p}),title:a("flow:nodeProps.deletePin"),children:o.jsx("span",{className:"material-symbols-outlined",children:"delete"})})]},`${f}-${p}`))]}):null]})}function zT({draft:e,setDraft:t,definitionId:n,systemPromptReadonly:r,modelLists:s,disabled:i,onIdBlur:a,onClose:l,onPublishToMarketplace:u,allowEditRequiredPins:d=!1,error:f,ioSlots:c}){const{t:p}=Pn(),[m,g]=h.useState(!1),[b,k]=h.useState(!1),[y,v]=h.useState({status:"idle",message:""}),w=h.useCallback(M=>{t(W=>W&&{...W,...M})},[t]),{cursorList:j,opencodeList:P,claudeCodeList:_,currentNotInLists:L}=h.useMemo(()=>{const M=Array.isArray(s==null?void 0:s.cursor)?s.cursor:[],W=Array.isArray(s==null?void 0:s.opencode)?s.opencode:[],O=Array.isArray(s==null?void 0:s.claudeCode)?s.claudeCode:[],$=new Set([...M,...W,...O].map(Ih)),I=((e==null?void 0:e.model)??"").trim(),z=I.startsWith("cursor:")?I.slice(7):I.startsWith("opencode:")?I.slice(9):I.startsWith("claude-code:")?I.slice(12):I,C=I&&!$.has(z)?I:"";return{cursorList:M,opencodeList:W,claudeCodeList:O,currentNotInLists:C}},[s,e==null?void 0:e.model]);if(!e)return null;const B=String(e.script??""),D=n==="tool_nodejs"||B.trim()!=="",F=typeof u=="function"&&!i&&(e==null?void 0:e.newId),R=async()=>{if(F){v({status:"running",message:p("flow:nodeProps.publishRunning")});try{const M=await u(e,n);v({status:"success",message:M!=null&&M.definitionId?p("flow:nodeProps.publishSuccessWithId",{id:M.definitionId}):p("flow:nodeProps.publishSuccess")})}catch(M){v({status:"error",message:String((M==null?void 0:M.message)||M)})}}};return o.jsxs(o.Fragment,{children:[o.jsxs("div",{className:"af-pipeline-drawer-head af-node-props-head",children:[o.jsx("h2",{className:"af-pipeline-drawer-title",children:p("flow:nodeProps.title")}),o.jsxs("div",{className:"af-node-props-head-actions",children:[o.jsxs("button",{type:"button",className:"af-btn-ghost af-node-props-market-btn",onClick:R,disabled:!F||y.status==="running",title:p("flow:nodeProps.publishToMarketplaceHint"),children:[o.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"inventory_2"}),y.status==="running"?p("flow:nodeProps.publishing"):p("flow:nodeProps.publishToMarketplace")]}),o.jsx("button",{type:"button",className:"af-btn-ghost af-node-props-close-secondary",onClick:l,children:p("common:common.close")})]})]}),o.jsxs("div",{className:"af-pipeline-drawer-body af-node-props-body",children:[f?o.jsx("p",{className:"af-err af-node-props-err",children:f}):null,y.message?o.jsx("p",{className:`af-node-props-market-status af-node-props-market-status--${y.status}`,children:y.message}):null,o.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[o.jsx("span",{className:"af-node-props-label",children:p("flow:node.nodeType")}),o.jsx("div",{className:"af-pipeline-drawer-readonly af-node-props-readonly-mono",children:n})]}),o.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[o.jsxs("span",{className:"af-node-props-label",children:[p("flow:nodeProps.instanceId"),o.jsx("span",{className:"af-node-props-hint",children:p("flow:node.displayNameHint")})]}),o.jsx("input",{type:"text",className:"af-node-props-input",value:e.newId,onChange:M=>w({newId:M.target.value}),onBlur:a,disabled:i,spellCheck:!1,autoComplete:"off","aria-label":p("flow:nodeProps.instanceId")})]}),o.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[o.jsxs("span",{className:"af-node-props-label",children:[p("flow:node.displayName"),"(LABEL)"]}),o.jsx("input",{type:"text",className:"af-node-props-input",value:e.label,onChange:M=>w({label:M.target.value}),disabled:i,spellCheck:!1})]}),o.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[o.jsxs("span",{className:"af-node-props-label",children:[p("flow:node.role"),"(ROLE)"]}),o.jsx("select",{className:"af-node-props-select",value:al.includes(e.role)?e.role:p("flow:roles.normal"),onChange:M=>w({role:M.target.value}),disabled:i,children:al.map(M=>o.jsx("option",{value:M,children:M},M))})]}),o.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[o.jsxs("span",{className:"af-node-props-label",children:[p("flow:node.model"),"(MODEL)"]}),o.jsx("span",{className:"af-node-props-sublabel",children:p("flow:node.modelHint")}),o.jsxs("select",{className:"af-node-props-select",value:(()=>{const M=(e.model||"").trim();return M?L||M:""})(),onChange:M=>w({model:M.target.value}),disabled:i,"aria-label":p("flow:nodeProps.modelAriaLabel"),children:[o.jsx("option",{value:"",children:p("flow:node.defaultModel")}),L?o.jsxs("option",{value:L,children:[L,p("flow:nodeProps.yamlValueNotInList")]}):null,j.length>0?o.jsx("optgroup",{label:"Cursor",children:j.map(M=>o.jsx("option",{value:Ih(M),children:M},`c-${M}`))}):null,P.length>0?o.jsx("optgroup",{label:"OpenCode",children:P.map(M=>o.jsx("option",{value:Ih(M),children:M},`o-${M}`))}):null,_.length>0?o.jsx("optgroup",{label:"Claude Code",children:_.map(M=>o.jsx("option",{value:`claude-code:${Ih(M)}`,children:M},`cc-${M}`))}):null]})]}),o.jsx(zj,{kind:"input",label:p("flow:nodeProps.inputPins"),slots:Array.isArray(e.inputs)?e.inputs:[],onSlotsChange:M=>w({inputs:M}),disabled:i,requiredReadonly:!d}),o.jsx(zj,{kind:"output",label:p("flow:nodeProps.outputPins"),slots:Array.isArray(e.outputs)?e.outputs:[],onSlotsChange:M=>w({outputs:M}),disabled:i,requiredReadonly:!d}),D?o.jsxs("div",{className:"af-pipeline-drawer-field af-node-props-field af-node-props-field--prompt",children:[o.jsxs("div",{className:"af-node-props-prompt-head",children:[o.jsxs("span",{className:"af-node-props-label",children:[p("flow:node.directCommand"),"(script)",o.jsx("span",{className:"af-node-props-hint",children:p("flow:node.scriptHint")})]}),o.jsx("button",{type:"button",className:"af-icon-btn af-node-props-expand",onClick:()=>k(!0),"aria-label":p("flow:nodeProps.expandEditScript"),title:p("flow:nodeProps.expand"),disabled:i,children:o.jsx("span",{className:"material-symbols-outlined",children:"open_in_full"})})]}),o.jsx(Ah,{value:B,onChange:M=>w({script:M}),disabled:i,placeholder:p("flow:nodeProps.scriptPlaceholder"),rows:6,textareaClassName:"af-pipeline-drawer-textarea af-node-props-body-textarea af-node-props-script-textarea",ioSlots:c,variant:"drawer"})]}):null,o.jsxs("div",{className:"af-pipeline-drawer-field af-node-props-field af-node-props-field--prompt",children:[o.jsxs("div",{className:"af-node-props-prompt-head",children:[o.jsx("span",{className:"af-node-props-label",children:p("flow:node.userPrompt")}),o.jsx("button",{type:"button",className:"af-icon-btn af-node-props-expand",onClick:()=>g(!0),"aria-label":p("flow:nodeProps.expandEdit"),title:p("flow:nodeProps.expand"),disabled:i,children:o.jsx("span",{className:"material-symbols-outlined",children:"open_in_full"})})]}),o.jsx(Ah,{value:e.body,onChange:M=>w({body:M}),images:e.images,onImagesChange:M=>w({images:M}),disabled:i,placeholder:p("flow:nodeProps.bodyPlaceholder"),rows:8,textareaClassName:"af-pipeline-drawer-textarea af-node-props-body-textarea",ioSlots:c,variant:"drawer"})]}),o.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[o.jsx("span",{className:"af-node-props-label",children:p("flow:node.systemDescription")}),o.jsx("textarea",{className:"af-pipeline-drawer-textarea af-node-props-system-readonly",rows:4,readOnly:!0,value:r||p("flow:nodeProps.noDescription"),spellCheck:!1})]})]}),b?o.jsx("div",{className:"af-node-props-expand-overlay",role:"dialog","aria-modal":"true","aria-label":p("flow:nodeProps.editScript"),onMouseDown:M=>{M.target===M.currentTarget&&k(!1)},children:o.jsxs("div",{className:"af-node-props-expand-panel",children:[o.jsxs("div",{className:"af-node-props-expand-head",children:[o.jsx("span",{className:"af-node-props-expand-title",children:p("flow:node.directCommand")}),o.jsx("button",{type:"button",className:"af-icon-btn",onClick:()=>k(!1),"aria-label":p("flow:nodeProps.collapse"),children:o.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),o.jsx(Ah,{value:B,onChange:M=>w({script:M}),disabled:i,placeholder:p("flow:nodeProps.scriptPlaceholderExpand"),rows:16,textareaClassName:"af-node-props-expand-textarea",ioSlots:c,variant:"expand"})]})}):null,m?o.jsx("div",{className:"af-node-props-expand-overlay",role:"dialog","aria-modal":"true","aria-label":p("flow:nodeProps.editUserPrompt"),onMouseDown:M=>{M.target===M.currentTarget&&g(!1)},children:o.jsxs("div",{className:"af-node-props-expand-panel",children:[o.jsxs("div",{className:"af-node-props-expand-head",children:[o.jsx("span",{className:"af-node-props-expand-title",children:p("flow:node.body")}),o.jsx("button",{type:"button",className:"af-icon-btn",onClick:()=>g(!1),"aria-label":p("flow:nodeProps.collapse"),children:o.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),o.jsx(Ah,{value:e.body,onChange:M=>w({body:M}),images:e.images,onImagesChange:M=>w({images:M}),disabled:i,placeholder:p("flow:nodeProps.bodyPlaceholderExpand"),rows:16,textareaClassName:"af-node-props-expand-textarea",ioSlots:c,variant:"expand"})]})}):null]})}function j0(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 LK(e){const t=j0(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 BT(e){try{return JSON.stringify(JSON.parse(e.trim()),null,2)}catch{return e}}function Bj({text:e}){const{t}=Pn(),n=e||"";return n.trim()?o.jsx("div",{className:"af-run-ctx-md",children:o.jsx(pp,{children:n})}):o.jsx("div",{className:"af-run-ctx-hint",children:t("flow:runContext.empty")})}function Hj({o:e}){var r;const{t}=Pn(),n=j0(e);if(n==="image"||e.encoding==="base64"&&((r=e.mimeType)!=null&&r.startsWith("image/"))){const i=`data:${e.mimeType||"image/png"};base64,${e.content||""}`;return o.jsxs("div",{className:"af-run-ctx-media",children:[o.jsx("img",{className:"af-run-ctx-img",src:i,alt:e.slot||"output",loading:"lazy"}),e.truncated?o.jsx("div",{className:"af-run-ctx-hint",children:t("flow:runContext.imageTruncated")}):null]})}if(n==="json")return o.jsx("pre",{className:"af-run-ctx-pre",children:BT(e.content||"")});if(n==="markdown"){const s=e.content||"";return s.trim()?o.jsx("div",{className:"af-run-ctx-md",children:o.jsx(pp,{children:s})}):o.jsx("div",{className:"af-run-ctx-hint",children:t("flow:runContext.empty")})}return o.jsx("pre",{className:"af-run-ctx-pre",children:e.content!=null&&e.content!==""?e.content:t("flow:runContext.empty")})}function Wj(e){return LK(e)}function Vj(e){var r;if(!e)return null;const t=j0(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"?BT(String(n)):String(n)}function Uj({text:e,title:t,copiedLabel:n}){const[r,s]=h.useState(!1);if(!e)return null;const i=async()=>{try{await navigator.clipboard.writeText(e),s(!0),window.setTimeout(()=>s(!1),1400)}catch{}};return o.jsx("button",{type:"button",className:"af-icon-btn af-run-ctx-copy-btn",onClick:i,title:r?n:t,"aria-label":r?n:t,children:o.jsx("span",{className:"material-symbols-outlined",children:r?"check":"content_copy"})})}const Kj=2e4,HT="af:run-node-ctx-width";function lm(){return typeof window>"u"?416:Math.min(26*16,window.innerWidth-32)}function Wa(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):Wa(lm())}function OK(){try{const e=localStorage.getItem(HT);if(e==null)return Wa(lm());const t=parseInt(e,10);return Number.isFinite(t)?Wa(t):Wa(lm())}catch{return Wa(lm())}}async function qj(e,t,n,r){const s=new URLSearchParams({flowId:e,instanceId:t});n&&String(n).trim()&&s.set("runId",String(n).trim());const i=await fetch(`/api/node-exec-context?${s.toString()}`,{signal:r}),a=await i.text();let l;try{l=JSON.parse(a)}catch{throw new Error(a.startsWith("<!")||a.startsWith("<html")?"apiConnectError":"invalidJson")}if(!i.ok)throw new Error(l.error||"HTTP "+i.status);return l}function MK(e,t){const n=`flow:runContext.${t}`,r=e(n);return r!==n?r:t}function $K({instanceId:e,flowId:t,runId:n,nodeStatus:r,onClose:s}){const{t:i}=Pn(),[a,l]=h.useState(()=>typeof window<"u"&&window.matchMedia("(max-width: 960px)").matches),[u,d]=h.useState(OK),f=h.useRef({active:!1,pointerId:-1,startX:0,startW:416}),[c,p]=h.useState(!0),[m,g]=h.useState(""),[b,k]=h.useState([]),[y,v]=h.useState(null),[w,j]=h.useState(null),P=h.useRef(null),_=h.useRef(null),L=h.useRef(0),B=h.useRef(0);h.useLayoutEffect(()=>{const C=window.matchMedia("(max-width: 960px)"),T=()=>l(C.matches);return C.addEventListener("change",T),()=>C.removeEventListener("change",T)},[]),h.useEffect(()=>{function C(){d(T=>Wa(T))}return window.addEventListener("resize",C),()=>window.removeEventListener("resize",C)},[]);const D=h.useCallback(()=>{d(C=>{const T=Wa(C);try{localStorage.setItem(HT,String(T))}catch{}return T})},[]),F=h.useCallback(C=>{if(a||C.button!==0)return;C.preventDefault();const T=C.currentTarget;f.current={active:!0,pointerId:C.pointerId,startX:C.clientX,startW:u},T.setPointerCapture(C.pointerId)},[a,u]),R=h.useCallback(C=>{const T=f.current;if(!T.active||C.pointerId!==T.pointerId)return;const E=T.startX-C.clientX;d(Wa(T.startW+E))},[]),M=h.useCallback(C=>{const T=f.current;if(!(!T.active||C.pointerId!==T.pointerId)){T.active=!1;try{C.currentTarget.releasePointerCapture(C.pointerId)}catch{}D()}},[D]),W=h.useCallback(()=>{const C=f.current;C.active&&(C.active=!1,D())},[D]),O=h.useCallback(C=>{const T=Array.isArray(C)?C:[];k(T),v(E=>E&&T.some(G=>G.execId===E)?E:T.length>0?T[T.length-1].execId:null)},[]),$=h.useCallback(()=>{if(!e||!t)return;const C=++L.current,T=new AbortController,E=window.setTimeout(()=>T.abort(),Kj);(async()=>{try{const G=await qj(t,e,n,T.signal);if(C!==L.current)return;O(Array.isArray(G.rounds)?G.rounds:[])}catch{}finally{window.clearTimeout(E)}})()},[e,t,n,O]);h.useEffect(()=>{if(!e||!t){p(!1),g(""),k([]);return}const C=++B.current;p(!0),g(""),k([]),v(null);const T=new AbortController,E=window.setTimeout(()=>T.abort(),Kj);return(async()=>{try{const G=await qj(t,e,n,T.signal);if(C!==B.current)return;O(Array.isArray(G.rounds)?G.rounds:[])}catch(G){if(C!==B.current)return;const Z=(G==null?void 0:G.name)==="AbortError"?"requestTimeout":G.message||String(G);g(Z)}finally{window.clearTimeout(E),C===B.current&&p(!1)}})(),()=>{T.abort(),B.current++,L.current++}},[e,t,n,O]),h.useEffect(()=>{r&&$()},[r,$]),h.useEffect(()=>{clearInterval(_.current);const C=b.length>0?b[b.length-1]:null;return(r==="running"&&b.length===0||!!(C&&C.status==="running"))&&e&&t&&(_.current=setInterval(()=>$(),2e3)),()=>clearInterval(_.current)},[b,e,t,n,r,$]),h.useEffect(()=>{P.current&&(P.current.scrollTop=0)},[y]);const I=b.find(C=>C.execId===y),z=a?void 0:{width:`${u}px`};return o.jsxs("aside",{className:"af-run-ctx-panel",style:z,"aria-label":i("flow:runContext.title"),children:[a?null:o.jsx("div",{className:"af-run-ctx-resize",role:"separator","aria-orientation":"vertical","aria-label":i("flow:runContext.resizeHandle"),onPointerDown:F,onPointerMove:R,onPointerUp:M,onPointerCancel:M,onLostPointerCapture:W}),o.jsxs("div",{className:"af-run-ctx-panel__main",children:[o.jsxs("div",{className:"af-run-ctx-head",children:[o.jsx("h2",{className:"af-run-ctx-title",title:e,children:e}),o.jsx("button",{type:"button",className:"af-icon-btn",onClick:s,"aria-label":i("common:common.close"),children:o.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),c&&o.jsx("div",{className:"af-run-ctx-placeholder",children:i("common:common.loading")}),m&&o.jsx("div",{className:"af-run-ctx-error",children:MK(i,m)}),!c&&!m&&b.length===0&&o.jsx("div",{className:"af-run-ctx-placeholder",children:i(r==="running"?"flow:runContext.executingNoArtifacts":"flow:runContext.noData")}),b.length>0&&o.jsxs(o.Fragment,{children:[o.jsxs("div",{className:"af-run-ctx-rounds af-run-ctx-rounds--select af-run-ctx-round--"+FK((I==null?void 0:I.status)||""),children:[o.jsx("span",{className:"af-run-ctx-round-dot","aria-hidden":!0}),o.jsx("select",{className:"af-run-ctx-round-select",value:String(y??""),onChange:C=>{const T=C.target.value;v(T==="latest"?"latest":Number(T))},children:[...b].reverse().map(C=>{const T=C.execId==="latest"?i("flow:runContext.latest"):`#${C.execId}`,E=zK(i,C.status),G=C.finishedAt?` · ${DK(C.finishedAt)}`:"";return o.jsx("option",{value:String(C.execId),children:`${T} · ${E}${G}`},C.execId)})})]}),I&&o.jsxs("div",{className:"af-run-ctx-body",ref:P,children:[I.inputs&&I.inputs.length>0&&o.jsxs("section",{className:"af-run-ctx-section",children:[o.jsxs("h3",{className:"af-run-ctx-section-title",children:[o.jsx("span",{className:"material-symbols-outlined af-run-ctx-section-icon","aria-hidden":!0,children:"input"}),"Inputs"]}),I.inputs.map((C,T)=>o.jsxs("div",{className:"af-run-ctx-output-slot",children:[o.jsx("div",{className:"af-run-ctx-slot-head",children:o.jsx("div",{className:"af-run-ctx-slot-name",children:C.slot})}),o.jsx("pre",{className:"af-run-ctx-slot-text",children:C.value})]},`${C.slot}-${T}`))]}),I.prompt!=null&&o.jsxs("section",{className:"af-run-ctx-section",children:[o.jsxs("h3",{className:"af-run-ctx-section-title",children:[o.jsx("span",{className:"material-symbols-outlined af-run-ctx-section-icon","aria-hidden":!0,children:"description"}),"Prompt",o.jsx("button",{type:"button",className:"af-icon-btn af-run-ctx-section-expand",onClick:()=>j("prompt"),title:i("flow:nodeProps.expand"),children:o.jsx("span",{className:"material-symbols-outlined",children:"open_in_full"})})]}),o.jsx(Bj,{text:I.prompt})]}),I.outputs&&I.outputs.length>0&&o.jsxs("section",{className:"af-run-ctx-section",children:[o.jsxs("h3",{className:"af-run-ctx-section-title",children:[o.jsx("span",{className:"material-symbols-outlined af-run-ctx-section-icon","aria-hidden":!0,children:"output"}),"Outputs",o.jsx("button",{type:"button",className:"af-icon-btn af-run-ctx-section-expand",onClick:()=>j("output"),title:i("flow:nodeProps.expand"),children:o.jsx("span",{className:"material-symbols-outlined",children:"open_in_full"})})]}),I.outputs.map((C,T)=>{const E=Wj(C),G=Vj(C);return o.jsxs("div",{className:"af-run-ctx-output-slot",children:[o.jsxs("div",{className:"af-run-ctx-slot-head",children:[o.jsx("div",{className:"af-run-ctx-slot-name",children:C.slot}),E?o.jsx("span",{className:"af-run-ctx-format-badge",title:i("flow:runContext.detectedContentType"),children:E}):null,o.jsx(Uj,{text:G,title:i("common:common.copy"),copiedLabel:i("common:common.copied")})]}),o.jsx(Hj,{o:C})]},`${C.slot}-${T}`)})]}),!I.prompt&&(!I.outputs||I.outputs.length===0)&&o.jsx("div",{className:"af-run-ctx-placeholder",children:i("flow:runContext.roundNoContent")})]})]})]}),w&&I&&o.jsx("div",{className:"af-node-props-expand-overlay",role:"dialog","aria-modal":"true",onClick:C=>{C.target===C.currentTarget&&j(null)},children:o.jsxs("div",{className:"af-node-props-expand-panel",children:[o.jsxs("div",{className:"af-node-props-expand-head",children:[o.jsx("span",{className:"af-node-props-expand-title",children:w==="prompt"?"Prompt":"Outputs"}),o.jsx("button",{type:"button",className:"af-icon-btn",onClick:()=>j(null),"aria-label":i("common:common.close"),children:o.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),o.jsxs("div",{className:"af-node-props-expand-body af-run-ctx-expand-body",children:[w==="prompt"&&I.prompt!=null&&o.jsx(Bj,{text:I.prompt}),w==="output"&&I.outputs&&I.outputs.map((C,T)=>{const E=Wj(C),G=Vj(C);return o.jsxs("div",{className:"af-run-ctx-output-slot",style:{marginBottom:"1rem"},children:[o.jsxs("div",{className:"af-run-ctx-slot-head",children:[o.jsx("div",{className:"af-run-ctx-slot-name",children:C.slot}),E?o.jsx("span",{className:"af-run-ctx-format-badge",children:E}):null,o.jsx(Uj,{text:G,title:i("common:common.copy"),copiedLabel:i("common:common.copied")})]}),o.jsx(Hj,{o:C})]},`${C.slot}-${T}`)})]})]})})]})}function DK(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 FK(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 zK(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 BK({flowId:e,flowSource:t,flowArchived:n,provideNodes:r,edges:s,nodes:i,onCliInputsChange:a,onBackToEdit:l}){const{t:u}=Pn(),[d,f]=h.useState({}),[c,p]=h.useState(null),[m,g]=h.useState({}),[b,k]=h.useState(!0),[y,v]=h.useState(!1),[w,j]=h.useState(""),[P,_]=h.useState(!1),[L,B]=h.useState(null),D=h.useRef(null),F=h.useRef(!0),R=h.useRef({});h.useMemo(()=>{var E,G,Z;const T={};for(const V of r){const se=(Z=(G=(E=V.data)==null?void 0:E.outputs)==null?void 0:G[0])==null?void 0:Z.default;se!=null&&se!==""&&(T[V.id]=String(se))}return R.current=T,T},[r]);const M=h.useMemo(()=>{var E;const T={};for(const G of i){if(!((E=G.data)!=null&&E.inputs))continue;const Z=G.data.inputs;for(let V=0;V<Z.length;V++){const se=Z[V];if(!(se!=null&&se.name))continue;const de=s.find(pe=>pe.target===G.id&&pe.targetHandle===`input-${V}`);if(!(de!=null&&de.source))continue;r.find(pe=>pe.id===de.source)&&(T[de.source]=se.name)}}return T},[i,s,r]);h.useEffect(()=>(F.current=!0,()=>{F.current=!1}),[]),h.useEffect(()=>{if(!e){k(!1);return}k(!0);const T=new URLSearchParams({flowId:e,flowSource:t||"user"});n&&T.set("archived","1"),fetch(`/api/flow/run-config?${T.toString()}`).then(E=>{if(!E.ok)throw new Error(`HTTP ${E.status}`);return E.json()}).then(E=>{var Z;if(!F.current)return;f(E.presets||{}),p(E.activePreset||null);const G=E.activePreset&&((Z=E.presets)!=null&&Z[E.activePreset])?E.presets[E.activePreset]:{};g({...R.current,...G}),k(!1)}).catch(()=>{F.current&&(g(R.current),k(!1))})},[e,t,n]),h.useEffect(()=>{var E;if(!a)return;const T={};for(const[G,Z]of Object.entries(m)){const V=M[G];if(!V)continue;const se=r.find(fe=>fe.id===G);if(!se)continue;(((E=se.data)==null?void 0:E.definitionId)||"").startsWith("provide_file")?T[V]={type:"file",path:Z}:T[V]={type:"str",value:Z}}a(T)},[m,M,r,a]);const W=h.useCallback((T,E)=>{g(G=>({...G,[T]:E}))},[]),O=h.useCallback(T=>{T!==c&&(p(T),T&&d[T]?g({...R.current,...d[T]}):g(R.current))},[c,d]),$=h.useCallback(async()=>{if(w.trim()){v(!0);try{const T={...d,[w.trim()]:m},E={flowId:e,flowSource:t,archived:n,presets:T,activePreset:w.trim()};(await fetch("/api/flow/run-config",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(E)})).ok&&(f(T),p(w.trim()),j(""),_(!1))}finally{v(!1)}}},[e,t,n,d,m,w]),I=h.useCallback(async()=>{if(c){v(!0);try{const T={...d};delete T[c];const E=Object.keys(T)[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:T,activePreset:E})})).ok&&(f(T),p(E),E&&T[E]?g({...R.current,...T[E]}):g(R.current))}finally{v(!1)}}},[e,t,n,d,c]),z=h.useCallback(async()=>{if(c){v(!0);try{const T={...d,[c]:m};(await fetch("/api/flow/run-config",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({flowId:e,flowSource:t,archived:n,presets:T,activePreset:c})})).ok&&f(T)}finally{v(!1)}}},[e,t,n,d,c,m]),C=Object.keys(d);return C.length>0,b?o.jsx("aside",{className:"af-run-config-panel",children:o.jsx("div",{className:"af-run-config-loading",children:u("common.loading")})}):o.jsxs("aside",{className:"af-run-config-panel",children:[o.jsxs("div",{className:"af-run-config-preset",children:[o.jsx("label",{className:"af-run-config-preset-label",children:u("flow:runConfig.preset")}),o.jsxs("div",{className:"af-run-config-preset-row",children:[o.jsxs("select",{className:"af-run-config-preset-select",value:c||"",onChange:T=>O(T.target.value||null),disabled:y,children:[o.jsx("option",{value:"",children:u("flow:runConfig.default")}),C.map(T=>o.jsx("option",{value:T,children:T},T))]}),o.jsx("button",{type:"button",className:"af-run-config-preset-btn af-run-config-preset-btn--new",onClick:()=>_(!0),disabled:y,title:u("flow:runConfig.newPreset"),children:o.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"add"})}),c&&o.jsx("button",{type:"button",className:"af-run-config-preset-btn af-run-config-preset-btn--save",onClick:z,disabled:y,title:u("flow:runConfig.savePreset"),children:o.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"save"})}),c&&o.jsx("button",{type:"button",className:"af-run-config-preset-btn af-run-config-preset-btn--delete",onClick:I,disabled:y,title:u("flow:runConfig.deletePreset"),children:o.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"delete"})})]})]}),P&&o.jsxs("div",{className:"af-run-config-save-dialog",children:[o.jsx("input",{type:"text",className:"af-run-config-save-input",placeholder:u("flow:runConfig.presetNamePlaceholder"),value:w,onChange:T=>j(T.target.value),disabled:y}),o.jsxs("div",{className:"af-run-config-save-actions",children:[o.jsx("button",{type:"button",className:"af-btn-primary",onClick:$,disabled:y||!w.trim(),children:u(y?"common.saving":"common.save")}),o.jsx("button",{type:"button",className:"af-btn-outline",onClick:()=>{_(!1),j("")},disabled:y,children:u("common.cancel")})]})]}),o.jsxs("div",{className:"af-run-config-inputs",children:[o.jsx("div",{className:"af-run-config-inputs-header",children:u("flow:runConfig.inputParams")}),r.length===0?o.jsx("div",{className:"af-run-config-empty",children:u("flow:runConfig.noProvideNodes")}):o.jsx("div",{className:"af-run-config-input-list",children:r.map(T=>{var pe,ae;const E=((pe=T.data)==null?void 0:pe.definitionId)||"",G=E.startsWith("provide_file"),Z=E==="provide_bool",V=((ae=T.data)==null?void 0:ae.label)||T.id,se=T.id,de=m[se]||"",fe=["true","1","yes","on"].includes(String(de).trim().toLowerCase());return o.jsxs("div",{className:"af-run-config-input-item",children:[o.jsxs("div",{className:"af-run-config-input-head",children:[o.jsx("span",{className:"af-run-config-input-icon material-symbols-outlined"+(G?" af-run-config-input-icon--file":""),"aria-hidden":!0,children:G?"description":Z?"toggle_on":"text_fields"}),o.jsx("span",{className:"af-run-config-input-label",children:V}),Z?null:o.jsx("button",{type:"button",className:"af-run-config-input-expand",onClick:()=>B({instanceId:se,label:V,content:de}),"aria-label":u("flow:runConfig.expandInput"),title:u("flow:runConfig.expandInput"),children:o.jsx("span",{className:"material-symbols-outlined",children:"open_in_full"})})]}),o.jsx("div",{className:"af-run-config-input-id",children:se}),Z?o.jsx("button",{type:"button",className:"af-run-config-bool-toggle"+(fe?" af-run-config-bool-toggle--true":""),onClick:()=>W(se,fe?"false":"true"),"aria-pressed":fe,children:fe?"true":"false"}):o.jsx("input",{type:"text",className:"af-run-config-input-field",value:de,onChange:be=>W(se,be.target.value),placeholder:u(G?"flow:runConfig.filePathPlaceholder":"flow:runConfig.stringValuePlaceholder")})]},se)})})]}),L&&Or.createPortal(o.jsx("div",{className:"af-provide-edit-overlay",children:o.jsxs("div",{className:"af-provide-edit-modal",role:"dialog","aria-modal":"true",children:[o.jsxs("div",{className:"af-provide-edit-modal__head",children:[o.jsx("span",{className:"material-symbols-outlined",children:"edit_document"}),o.jsx("span",{className:"af-provide-edit-modal__title",children:L.label}),o.jsx("button",{type:"button",className:"af-provide-edit-modal__close",onClick:()=>B(null),"aria-label":u("common:close"),children:o.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),o.jsx("div",{className:"af-provide-edit-modal__body",children:o.jsx("textarea",{ref:D,className:"af-provide-edit-modal__textarea",defaultValue:L.content,autoFocus:!0})}),o.jsxs("div",{className:"af-provide-edit-modal__foot",children:[o.jsxs("button",{type:"button",className:"af-provide-edit-modal__btn af-provide-edit-modal__btn--save",onClick:()=>{!L||!D.current||(W(L.instanceId,D.current.value),B(null))},children:[o.jsx("span",{className:"material-symbols-outlined",children:"save"}),u("flow:provideEdit.save")]}),o.jsxs("button",{type:"button",className:"af-provide-edit-modal__btn",onClick:()=>B(null),children:[o.jsx("span",{className:"material-symbols-outlined",children:"close"}),u("flow:provideEdit.cancel")]})]})]})}),document.body)]})}const WT={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"]},HK={"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 WK(e){return!e||e<1024?`${e||0} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/1024/1024).toFixed(2)} MB`}function VK(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 UK(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 Yj(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(WT))if(r.includes(e))return n;return"other"}function KK({event:e,defaultExpanded:t}){const[n,r]=h.useState(!!t),s=HK[e.tag]||"#a8a8a8",i=e.payload,a=i&&typeof i=="object",l=a?typeof i.text=="string"?i.text:"":String(i||""),u=a?i.meta:null,d=h.useMemo(()=>l?l.slice(0,140).replace(/\s+/g," "):a?Object.keys(i).filter(m=>m!=="text"&&m!=="meta").slice(0,3).map(m=>{const g=i[m];return g==null?`${m}:null`:typeof g=="object"?`${m}:{…}`:`${m}:${String(g).slice(0,30)}`}).join(" "):"",[i,l,a]),f=h.useCallback(c=>{c.stopPropagation();const p=a?JSON.stringify(i,null,2):String(i);try{navigator.clipboard.writeText(p)}catch{}},[i,a]);return o.jsxs("div",{style:{borderLeft:`3px solid ${s}`,background:n?"#1c1b1b":"#131313",marginBottom:4,borderRadius:4,cursor:"pointer",transition:"background 120ms"},onClick:()=>r(c=>!c),children:[o.jsxs("div",{style:{padding:"6px 10px",display:"flex",alignItems:"center",gap:10,fontSize:12},children:[o.jsx("span",{style:{color:"#9a9a9a",fontFamily:"monospace",flexShrink:0},children:VK(e.ts)}),o.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}),o.jsx("span",{style:{color:"#c5c2c1",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"monospace"},children:d}),n&&o.jsx("button",{type:"button",onClick:f,style:{background:"rgba(124,77,255,0.15)",color:"#e8deff",border:"none",borderRadius:3,padding:"2px 8px",fontSize:11,cursor:"pointer"},children:"Copy"})]}),n&&o.jsxs("div",{style:{padding:"0 10px 10px 10px",borderTop:"1px solid rgba(255,255,255,0.04)"},children:[u&&Object.keys(u).length>0&&o.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(u,null,2)}),l?o.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?o.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(i,null,2)}):null]})]})}function qK({open:e,onClose:t,flowId:n}){var B;const[r,s]=h.useState([]),[i,a]=h.useState(!1),[l,u]=h.useState(null),[d,f]=h.useState(null),[c,p]=h.useState(!1),[m,g]=h.useState(!0),[b,k]=h.useState({ai:!0,flow:!0,step:!0,output:!0,error:!0}),[y,v]=h.useState(""),w=h.useRef(null),j=h.useCallback(async()=>{a(!0);try{const D=m&&n?`?flowId=${encodeURIComponent(n)}`:"",R=await(await fetch(`/api/composer-logs${D}`)).json();s(Array.isArray(R.sessions)?R.sessions:[])}catch{s([])}finally{a(!1)}},[n,m]),P=h.useCallback(async D=>{if(!D){f(null);return}p(!0);try{const R=await(await fetch(`/api/composer-logs/${encodeURIComponent(D)}`)).json();f(R)}catch{f(null)}finally{p(!1)}},[]);h.useEffect(()=>{e&&j()},[e,j]),h.useEffect(()=>{if(!(!e||!l))return P(l),w.current=setInterval(()=>P(l),2e3),()=>{w.current&&clearInterval(w.current),w.current=null}},[e,l,P]);const _=h.useMemo(()=>{const D=(d==null?void 0:d.events)||[],F=y.trim().toLowerCase();return D.filter(R=>{const M=Yj(R.tag,R.payload);return!b[M]&&M!=="other"?!1:F?[R.tag,JSON.stringify(R.payload||"")].join(" ").toLowerCase().includes(F):!0})},[d,b,y]),L=h.useMemo(()=>{const D=(d==null?void 0:d.events)||[],F={};for(const R of D){const M=Yj(R.tag,R.payload);F[M]=(F[M]||0)+1}return F},[d]);return e?o.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:[o.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:[o.jsx("span",{style:{fontWeight:600,fontSize:14},children:"Composer Logs"}),o.jsx("span",{style:{fontSize:11,color:"#9a9a9a"},children:n?`flowId: ${n}`:"no flow selected"}),o.jsxs("label",{style:{fontSize:11,color:"#9a9a9a",display:"flex",alignItems:"center",gap:4,cursor:"pointer"},children:[o.jsx("input",{type:"checkbox",checked:m,onChange:D=>g(D.target.checked),disabled:!n}),"仅显示当前 flow"]}),o.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"}),o.jsx("span",{style:{flex:1}}),o.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"})]}),o.jsxs("div",{style:{flex:1,display:"flex",overflow:"hidden",minHeight:0},children:[o.jsxs("div",{style:{width:280,borderRight:"1px solid rgba(255,255,255,0.06)",overflowY:"auto",background:"#0e0e0e",flexShrink:0},children:[i&&o.jsx("div",{style:{padding:12,fontSize:12,color:"#9a9a9a"},children:"Loading…"}),!i&&r.length===0&&o.jsx("div",{style:{padding:12,fontSize:12,color:"#9a9a9a"},children:m&&n?"no sessions for this flow":"no sessions"}),r.map(D=>{const F=l===D.sessionId;return o.jsxs("div",{onClick:()=>u(D.sessionId),style:{padding:"10px 12px",borderBottom:"1px solid rgba(255,255,255,0.04)",cursor:"pointer",background:F?"rgba(124,77,255,0.18)":"transparent",borderLeft:F?"3px solid #7c4dff":"3px solid transparent"},children:[o.jsx("div",{style:{fontSize:12,fontWeight:600,color:"#e5e2e1"},children:UK(D.mtime)}),o.jsx("div",{style:{fontSize:11,color:"#9ecaff",marginTop:2,fontFamily:"monospace"},children:D.flowId||"(no flow)"}),D.promptPreview&&o.jsx("div",{style:{fontSize:11,color:"#9a9a9a",marginTop:4,overflow:"hidden",textOverflow:"ellipsis",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical"},children:D.promptPreview}),o.jsxs("div",{style:{fontSize:10,color:"#6a6a6a",marginTop:4},children:[WK(D.size)," · ",D.model||"default"]})]},D.sessionId)})]}),o.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",overflow:"hidden",minHeight:0},children:[o.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(WT).map(D=>o.jsxs("button",{type:"button",onClick:()=>k(F=>({...F,[D]:!F[D]})),style:{background:b[D]?"rgba(124,77,255,0.25)":"transparent",color:b[D]?"#e8deff":"#6a6a6a",border:`1px solid ${b[D]?"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:[D," ",L[D]!=null?`(${L[D]})`:""]},D)),o.jsx("input",{type:"text",placeholder:"search…",value:y,onChange:D=>v(D.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}})]}),o.jsxs("div",{style:{flex:1,overflowY:"auto",padding:12,minHeight:0},children:[!l&&o.jsx("div",{style:{color:"#9a9a9a",fontSize:12,padding:20,textAlign:"center"},children:"Select a session on the left to view events"}),c&&!d&&o.jsx("div",{style:{color:"#9a9a9a",fontSize:12,padding:20},children:"Loading…"}),d&&_.length===0&&o.jsxs("div",{style:{color:"#9a9a9a",fontSize:12,padding:20},children:["No events match current filter (",((B=d.events)==null?void 0:B.length)||0," total)"]}),_.map((D,F)=>o.jsx(KK,{event:D,defaultExpanded:D.tag==="error"},`${D.ts}_${F}`))]})]})]})]}):null}const YK="0.1.61";function Gj(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 Px(e,t){return t==="running"?Gj(e):e==null||!Number.isFinite(e)||e<=0?"--":Gj(e)}const VT=h.createContext({modelLists:{cursor:[],opencode:[]},onModelChange:()=>{}});function GK(e){var v,w,j,P,_,L,B,D,F,R,M;const{setNodes:t}=fc(),n=n0(),{modelLists:r,onModelChange:s}=h.useContext(VT),i=h.useRef(null),a=!!((v=e.data)!=null&&v.readOnly),l=(w=e.data)!=null&&w.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,u=((j=e.data)==null?void 0:j.definitionId)==="agent_subAgent"&&!((P=e.data)!=null&&P.isRunMode)&&!a,d=h.useCallback(W=>{const O=()=>n(W);window.requestAnimationFrame(O),window.setTimeout(O,80)},[n]),f=h.useCallback((W,O)=>{const $=r1(O);$&&(t(I=>I.map(z=>{var E,G,Z,V,se,de;if(z.id!==W)return z;const C=Number(((G=(E=z.data)==null?void 0:E.displaySize)==null?void 0:G.width)||z.width||((Z=z.measured)==null?void 0:Z.width)||0),T=Number(((se=(V=z.data)==null?void 0:V.displaySize)==null?void 0:se.height)||z.height||((de=z.measured)==null?void 0:de.height)||0);return Math.abs(C-$.width)<2&&Math.abs(T-$.height)<2?z:{...z,width:$.width,height:$.height,data:{...z.data,displaySize:$}}})),d(W))},[d,t]),c=h.useCallback(W=>{if(a)return;const O=i.current;if(!O)return;const $=O.getBoundingClientRect();f(W,{width:Math.max($.width,O.scrollWidth),height:Math.max($.height,O.scrollHeight)})},[f,a]),p=h.useCallback(W=>{var se,de,fe,pe,ae,be;if(!u)return;W.preventDefault(),W.stopPropagation();const O=i.current,$=O==null?void 0:O.getBoundingClientRect(),I=Number(((de=(se=e.data)==null?void 0:se.displaySize)==null?void 0:de.width)||e.width||((fe=e.measured)==null?void 0:fe.width)||($==null?void 0:$.width)||YT),z=Number(((ae=(pe=e.data)==null?void 0:pe.displaySize)==null?void 0:ae.height)||e.height||((be=e.measured)==null?void 0:be.height)||($==null?void 0:$.height)||Pb),C=W.clientX,T=W.clientY,E=e.id;let G=0;const Z=_e=>{const we=r1({width:I+_e.clientX-C,height:z+_e.clientY-T});we&&(window.cancelAnimationFrame(G),G=window.requestAnimationFrame(()=>f(E,we)))},V=()=>{window.cancelAnimationFrame(G),window.removeEventListener("pointermove",Z),window.removeEventListener("pointerup",V),window.removeEventListener("pointercancel",V),d(E)};window.addEventListener("pointermove",Z),window.addEventListener("pointerup",V,{once:!0}),window.addEventListener("pointercancel",V,{once:!0})},[f,(L=(_=e.data)==null?void 0:_.displaySize)==null?void 0:L.height,(D=(B=e.data)==null?void 0:B.displaySize)==null?void 0:D.width,e.height,e.id,(F=e.measured)==null?void 0:F.height,(R=e.measured)==null?void 0:R.width,e.width,d,u]),m=h.useCallback(W=>{t(O=>O.filter($=>$.id!==W))},[t]),g=h.useCallback(()=>{var I,z,C,T,E,G,Z,V;const W=((I=e.data)==null?void 0:I.definitionId)||"",O=((z=e.data)==null?void 0:z.label)||e.id,$=((E=(T=(C=e.data)==null?void 0:C.outputs)==null?void 0:T[0])==null?void 0:E.value)||((V=(Z=(G=e.data)==null?void 0:G.outputs)==null?void 0:Z[0])==null?void 0:V.default)||"";window.__provideEditContent={instanceId:e.id,label:O,definitionId:W,content:$},window.dispatchEvent(new CustomEvent("provide-expand"))},[e.id,e.data]),b=h.useCallback((W,O)=>{t($=>$.map(I=>{var C;if(I.id!==W)return I;const z=Array.isArray((C=I.data)==null?void 0:C.outputs)&&I.data.outputs.length?I.data.outputs.map((T,E)=>E===0?{...T,default:O,value:O}:T):[{type:"bool",name:"value",default:O,value:O}];return{...I,data:{...I.data,body:"",outputs:z}}}))},[t]),k=h.useCallback((W,O)=>{t($=>$.map(I=>I.id===W?{...I,data:{...I.data,body:O}}:I))},[t]),y=h.useCallback((W,O)=>{t($=>$.map(I=>I.id===W?{...I,data:{...I.data,images:Ps(O)}}:I))},[t]);return o.jsxs("div",{ref:i,className:"af-flow-node-shell"+(u?" af-flow-node-shell--resizable":""),style:l?{width:l.width,height:l.height}:void 0,children:[o.jsx(AT,{...e,data:{...e.data,onNodeContentResize:c},deleteNode:m,onProvideExpand:g,onProvideValueChange:b,onNodeBodyChange:k,onNodeImagesChange:y,modelLists:r,onModelChange:s}),u?o.jsx("span",{className:"af-flow-node-shell__resize-grip nodrag","aria-label":((M=e.data)==null?void 0:M.resizeLabel)||"Resize node",role:"separator",onPointerDown:p}):null]})}const XK={[mp]:GK},Wd=["CONTROL","TOOL","PROVIDE","AGENT"],JK=1200,Xj="af-flow-node--sync-flash",Jj="af-flow-edge--sync-flash";function Qj(e,t){const n=String(e||"").trim();return n?n.split(/\s+/).includes(t)?n:`${n} ${t}`:t}function Zj(e,t){const n=String(e||"").trim();return n?n.split(/\s+/).filter(r=>r&&r!==t).join(" "):""}function C0(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 QK(e){const t=C0(e);return t==="CONTROL"?"control":t==="PROVIDE"?"provide":t==="TOOL"?"tool":"agent"}function Th(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 UT(e){return String((e==null?void 0:e.label)||"").trim()||String((e==null?void 0:e.id)||"").trim()}function KT(e){return String((e==null?void 0:e.description)||(e==null?void 0:e.body)||"").replace(/\s+/g," ").trim()}function Ax(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 e1(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(),i=String((t==null?void 0:t.default)??(t==null?void 0:t.value)??"").trim();return[e,r,s?`type: ${s}`:"",i?`default: ${i}`:""].filter(Boolean).join(" · ")}function t1(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 ZK(e){return e==="CONTROL"?"account_tree":e==="TOOL"?"build":e==="PROVIDE"?"database":"smart_toy"}function e7(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 qT(e,t,n,r,s){const i=QK(e),a={id:t,type:mp,position:n,data:{label:e.label??e.id,definitionId:e.id,schemaType:i,inputs:Array.isArray(e.inputs)?e.inputs.map(l=>({...l})):[],outputs:Array.isArray(e.outputs)?e.outputs.map(l=>({...l})):[]}};return qf(a,r,s)}const YT=320,t7=220,n7=1600,Pb=104,r7=900;function n1(e,t,n){const r=Number(e);return!Number.isFinite(r)||r<=0?0:Math.min(n,Math.max(t,Math.round(r)))}function r1(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:n1(t,t7,n7)||YT,height:n1(n,Pb,r7)||Pb}}function s7(e){const t=(e==null?void 0:e.data)||{},n=r=>(Array.isArray(r)?r:[]).map((s,i)=>(s==null?void 0:s.showOnNode)===!1?"":[i,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 s1(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])),i=s.get(n),a=s.get(r),l=Ou(i,e.sourceHandle||"output-0","source"),u=Ou(a,e.targetHandle||"input-0","target");return!l||!u?!1:Lu(l,u)}function i7(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 i=t.find(l=>l.id===n),a=Ou(i,r,s);return a?{nodeId:n,handleId:r,handleType:s,slot:a,slotType:PT(a)}:null}function o7(e,t,n){var a;const r=qT(e,`__candidate_${e.id}`,{x:0,y:0},{},t),s=n.handleType==="source"?"inputs":"outputs",i=Array.isArray((a=r.data)==null?void 0:a[s])?r.data[s]:[];for(let l=0;l<i.length;l+=1){const u=i[l];if(n.handleType==="source"?Lu(n.slot,u):Lu(u,n.slot))return{slot:u,slotIndex:l,hydrated:r}}return null}function a7(e,t){return t?e.map((n,r)=>{const s=o7(n,e,t);if(!s)return null;const i=C0(n);return{def:n,order:r,category:i,categoryRank:Wd.indexOf(i),slot:s.slot,slotIndex:s.slotIndex,displayLabel:UT(s.hydrated.data||n),description:KT(n)}}).filter(Boolean).sort((n,r)=>{var a,l;const s=(a=n.slot)!=null&&a.required?0:1,i=(l=r.slot)!=null&&l.required?0:1;return s-i||n.slotIndex-r.slotIndex||n.categoryRank-r.categoryRank||n.order-r.order}):[]}const l7=/@([a-zA-Z_][a-zA-Z0-9_]*)/g;function c7(e){const t=new Set,n=[];let r;const s=new RegExp(l7.source,"g");for(;(r=s.exec(e))!==null;){const i=r[1];t.has(i)||(t.add(i),n.push(i))}return n}function i1(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 Qo(e){const t=String(e||"").indexOf(" - ");return t>=0?e.slice(0,t).trim():String(e||"").trim()}function Rh(e,t,n,r){const s=(e||"").trim();if(!s)return"";if(s.startsWith("opencode:")||s.startsWith("claude-code:"))return s;const i=Array.isArray(t)?t:[],a=Array.isArray(n)?n:[],l=Array.isArray(r)?r:[],u=i.map(Qo),d=a.map(Qo);return l.map(Qo).includes(s)&&!u.includes(s)&&!d.includes(s)?`claude-code:${s}`:d.includes(s)&&!u.includes(s)?`opencode:${s}`:s}function u7(e){if(e==null)return"";const t=String(e).trim();return t?t.length<=26?t:`${t.slice(0,12)}…${t.slice(-10)}`:""}function Ix(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 d7({steps:e}){const{t}=Pn();return!e||e.length===0?null:o.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,i=[`${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 o.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:i,children:[o.jsx("span",{className:"af-composer-step-chip-idx",children:n.index+1}),o.jsx("span",{className:"af-composer-step-chip-main",children:n.nodeRole||s?o.jsxs("span",{className:"af-composer-step-chip-meta",children:[n.nodeRole?o.jsx("span",{className:"af-composer-step-chip-role",children:n.nodeRole}):null,s?o.jsx("span",{className:"af-composer-step-chip-model",children:u7(s)}):null]}):null})]},n.index)})})}function f7(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 p7(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",i=t[t.length-1];i&&i.kind===s?i.text+=s==="error"||s==="result"?`
130
130
  ${n.text}`:n.text:t.push({kind:s,text:n.text})}return t}function h7(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 m7(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 o1({thread:e,liveSegments:t,running:n,className:r="",autoScroll:s=!0}){const{t:i}=Pn(),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 u=a.current;requestAnimationFrame(()=>{u.scrollTop=u.scrollHeight})},[e,t,s]),o.jsxs("div",{ref:a,className:l,children:[e.map((u,d)=>u.type==="user"?o.jsxs("section",{className:"af-composer-ai-block af-composer-ai-block--user-msg",children:[o.jsx("div",{className:"af-composer-ai-block-label",children:i("flow:composer.yourQuestion")}),o.jsx("div",{className:"af-composer-ai-block-body",children:u.text})]},`composer-u-${d}-${u.text.slice(0,48)}`):o.jsx("div",{className:"af-composer-thread-assistant",children:o.jsx(a1,{segments:u.segments,running:!1})},`composer-a-${d}`)),o.jsx("div",{className:"af-composer-thread-assistant",children:o.jsx(a1,{segments:t,running:n})})]})}function a1({segments:e,running:t=!1}){const{t:n}=Pn(),r=e.filter(c=>c.kind==="assistant").map(c=>c.text).join(""),s=e.filter(c=>c.kind==="result").map(c=>c.text).join(""),i=f7(r,s),a=e.filter(c=>c.kind==="error").map(c=>c.text).join(`
131
131
  `),l=e.filter(c=>c.kind!=="error"),u=i?l.filter(c=>c.kind!=="result"):l,d=p7(u),f=!!(d.length>0||a);return o.jsxs(o.Fragment,{children:[d.map((c,p)=>o.jsxs("section",{className:m7(c.kind),children:[o.jsx("div",{className:"af-composer-ai-block-label",children:h7(c.kind,n)}),o.jsx("div",{className:"af-composer-ai-block-body",children:c.text})]},`${c.kind}-${p}`)),t&&!f?o.jsxs("section",{className:"af-composer-ai-block af-composer-ai-block--reply af-composer-ai-block--pending",children:[o.jsx("div",{className:"af-composer-ai-block-label",children:n("flow:composer.reply")}),o.jsx("div",{className:"af-composer-ai-block-body",children:n("flow:composer.waiting")})]}):null,a?o.jsxs("section",{className:"af-composer-ai-block af-composer-ai-block--error",children:[o.jsx("div",{className:"af-composer-ai-block-label",children:n("flow:composer.error")}),o.jsx("div",{className:"af-composer-ai-block-body",children:a})]}):null]})}function g7({fitViewEpoch:e}){const{fitView:t}=fc(),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 y7({onReady:e}){const t=n0();return h.useEffect(()=>(e(t),()=>e(null)),[e,t]),null}function l1(e){const t=Number.isFinite(e)?e:1;return Math.min(Math.max(t,.75),1)}function c1(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 cm=1500,u1=500,x7=262144,w7=2e3;function Tx(e){return typeof e!="string"?"":e.length<=w7?e:`[log line truncated, ${e.length} chars]`}const b7=cm;function v7(e){const t=e.match(/^\[([^\]]+)\]\s+\[([^\]]+)\]\s+([\s\S]*)$/);if(!t)return null;const[,n,r,s]=t;if(r==="cli")try{const i=JSON.parse(s);return i&&i.event==="node-start"?{ts:n,type:"node-start",text:`节点 ${i.instanceId||""}${i.label?` · ${i.label}`:""} 开始`}:i&&i.event==="node-done"?{ts:n,type:"node-done",text:`节点 ${i.instanceId||""} 完成${i.elapsed?` (${i.elapsed})`:""}`}:i&&i.event==="node-failed"?{ts:n,type:"node-failed",text:`节点 ${i.instanceId||""} 失败${i.error?`: ${i.error}`:""}`}:i&&i.event==="apply-start"?{ts:n,type:"info",text:`[apply-start] uuid=${i.uuid||""}`}:{ts:n,type:"info",text:Tx(s)}}catch{return{ts:n,type:"info",text:Tx(s)}}return{ts:n,type:"log",text:Tx(`[${r}] ${s}`)}}function d1(e){if(!e)return[];const t=[],n=e.split(`
@@ -140,7 +140,7 @@ ${n.text}`:n.text:t.push({kind:s,text:n.text})}return t}function h7(e,t){return
140
140
  `);for(let l=0;l<a.length;l+=1){const u=a[l],d=a[l+1];if(i){u==='"'&&d==='"'?(s+='"',l+=1):u==='"'?i=!1:s+=u;continue}u==='"'?i=!0:u===t?(r.push(s.trim()),s=""):u===`
141
141
  `?(r.push(s.trim()),n.push(r),r=[],s=""):s+=u}return(s||r.length)&&(r.push(s.trim()),n.push(r)),n.filter(l=>l.some(u=>String(u||"").trim()))}function ho(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 q7(e){if(Array.isArray(e)){if(e.every(s=>s&&typeof s=="object"&&!Array.isArray(s))){const s=Array.from(new Set(e.flatMap(i=>Object.keys(i))));return{columns:s.map(i=>({key:i,label:i,align:"left"})),rows:e.map(i=>s.map(a=>ho(i[a])))}}if(e.every(Array.isArray)&&e.length>0){const s=e[0].map((i,a)=>ho(i)||`Column ${a+1}`);return{columns:s.map((i,a)=>({key:String(a),label:i,align:"left"})),rows:e.slice(1).map(i=>s.map((a,l)=>ho(i[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,i)=>s&&typeof s=="object"?{key:String(s.key||s.name||s.field||i),label:String(s.label||s.title||s.name||s.key||`Column ${i+1}`),align:["left","center","right"].includes(s.align)?s.align:"left"}:{key:String(i),label:ho(s)||`Column ${i+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,i)=>({key:String(i),label:ho(s)||`Column ${i+1}`,align:"left"})),{columns:r,rows:n.slice(1).map(s=>r.map((i,a)=>ho(s[a])))}):{columns:r,rows:n.map(s=>Array.isArray(s)?r.map((i,a)=>ho(s[a])):s&&typeof s=="object"?r.map(i=>ho(s[i.key])):r.map((i,a)=>a===0?ho(s):""))}}function Y7(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=q7(JSON.parse(r));if(l&&l.columns.length)return{...l,error:""}}catch{}const s=r.replace(/\r\n/g,`
142
142
  `).split(`
143
- `).filter(l=>l.trim());if(s.length>=2&&ra(s[0]).length>1&&XT(s[1])){const l=ra(s[0]),u=JT(s[1]);return{columns:l.map((d,f)=>({key:String(f),label:d,align:u[f]||"left"})),rows:s.slice(2).map(d=>ra(d)),error:""}}const i=r.includes(" ")?" ":",",a=K7(r,i);return a.length>0&&a[0].length>1?{columns:a[0].map((u,d)=>u||`Column ${d+1}`).map((u,d)=>({key:String(d),label:u,align:"left"})),rows:a.slice(1),error:""}:{columns:[],rows:[],error:"No table data detected"}}function _0({content:e}){const t=h.useMemo(()=>Y7(e),[e]);return t.error||t.columns.length===0?o.jsxs("div",{className:"af-work-display-table-empty",children:[o.jsx("strong",{children:"Table data error"}),o.jsx("span",{children:t.error||"No columns found"})]}):o.jsx("div",{className:"af-work-display-table-wrap af-work-display-table-wrap--standalone",children:o.jsxs("table",{className:"af-work-display-table",children:[o.jsx("thead",{children:o.jsx("tr",{children:t.columns.map((n,r)=>o.jsx("th",{style:{textAlign:n.align||"left"},children:n.label},`${n.key}-${r}`))})}),o.jsx("tbody",{children:t.rows.map((n,r)=>o.jsx("tr",{children:t.columns.map((s,i)=>o.jsx("td",{style:{textAlign:s.align||"left"},children:ho(n[i])},`${s.key}-${i}`))},r))})]})})}function P0({content:e}){const t=h.useRef(null),n=h.useMemo(()=>V7(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 i=!1,a=null,l=null,u=null;return s({loading:!0,error:""}),I7(()=>import("./index-DgQRkS4v.js"),[]).then(d=>{i||!t.current||(a=d.init(t.current,"dark",{renderer:"canvas"}),a.setOption(n.spec.option,!0),u=()=>a==null?void 0:a.resize(),typeof ResizeObserver<"u"&&(l=new ResizeObserver(u),l.observe(t.current)),window.addEventListener("resize",u),window.requestAnimationFrame(u),i||s({loading:!1,error:""}))}).catch(d=>{i||s({loading:!1,error:String((d==null?void 0:d.message)||d)})}),()=>{var d,f;i=!0,u&&window.removeEventListener("resize",u),(d=l==null?void 0:l.disconnect)==null||d.call(l),(f=a==null?void 0:a.dispose)==null||f.call(a)}},[n]),!n.ok||r.error?o.jsxs("div",{className:"af-work-display-chart-error",children:[o.jsx("strong",{children:"Chart configuration error"}),o.jsx("span",{children:r.error||n.error})]}):o.jsxs("div",{className:"af-work-display-chart",children:[o.jsx("div",{ref:t,className:"af-work-display-chart__canvas"}),r.loading?o.jsx("div",{className:"af-work-display-chart__loading",children:"Loading chart..."}):null]})}const G7="af:workspace-graph:v2",Fc=["DISPLAY","CONTROL","TOOL","PROVIDE","AGENT"],X7=new Set(["control_start","control_end","control_load_skills","control_load_mcp"]),J7={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:""}]},Q7={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}]},Z7={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}]},eq=new Set(["png","jpg","jpeg","gif","webp","svg"]),tq=320,ZT=180,eR=960,Ib=96,tR=900,Tb="display-ref:",nq="0.1.60";function rq(){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 Xo(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 cg(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 eq.has(n)}function ug(e,t){const n=String(e||"").trim();if(!n)return"";if(/^(?:https?:|data:|blob:|file:)/i.test(n)||n.startsWith("/"))return n;const r=Xo(t||{});return r.set("path",n),`/api/workspace/file/raw?${r.toString()}`}function sq(e,t){const n=String(e||"").trim();if(!n)return"";const r=Xo(t||{});return r.set("path",n),r.set("download","1"),`/api/workspace/file/raw?${r.toString()}`}function iq(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 oq(e){return!e||typeof e.closest!="function"?!1:!!e.closest("input, textarea, select, [contenteditable='true']")}function aq(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 lq(e){return!e||typeof e.closest!="function"?!1:!!e.closest(".af-flow-node__prompt-stack")&&!aq(e)}function cq(e){const t=String(e||"").trim();if(!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 i=r==="readToolCall"?"读取文件/上下文":r==="grepToolCall"?"搜索代码":r==="editToolCall"?"编辑文件":r;return s==="completed"?`完成:${i}`:`执行:${i}`}return/^\[stderr\]/.test(t)?t:""}function g1(e){if(String((e==null?void 0:e.type)||"")!=="raw"||String((e==null?void 0:e.eventType)||"")!=="thinking")return"";const t=String((e==null?void 0:e.text)||"").trim();if(!t)return"";try{const n=JSON.parse(t);if((n==null?void 0:n.type)!=="thinking")return"";const r=String((n==null?void 0:n.subtype)||"");return r&&r!=="delta"?"":String((n==null?void 0:n.text)||(n==null?void 0:n.delta)||(n==null?void 0:n.thinking)||"").trim()}catch{return""}}function nR(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 rR(e){const t=String((e==null?void 0:e.marketplaceDefinitionId)||(e==null?void 0:e.id)||"").trim();return t.startsWith("marketplace:")?t:""}function A0(e){if(!e)return"";const t=String(e.baseDefinitionId||"").trim();if(!t)return String(e.id||"").trim();const n=e.runtime&&typeof e.runtime=="object"?e.runtime:{};return!!(n.entry||n.command)&&t==="tool_nodejs"?String(e.id||"").trim():t}function Vd(e){const t=String(A0(e)||(e==null?void 0:e.id)||"");return t==="workspace_run"?"CONTROL":t.startsWith("display_")?"DISPLAY":/^control/i.test(t)?"CONTROL":/^tool/i.test(t)?"TOOL":/^provide/i.test(t)?"PROVIDE":"AGENT"}function y1(e){return e==="DISPLAY"?"preview":e==="CONTROL"?"account_tree":e==="TOOL"?"build":e==="PROVIDE"?"database":"smart_toy"}function dg(e){return String((e==null?void 0:e.displayName)||(e==null?void 0:e.label)||(e==null?void 0:e.id)||"Node")}function Ud(e){return dg(e)}function Rb(e){return String((e==null?void 0:e.description)||(e==null?void 0:e.body)||"").replace(/\s+/g," ").trim()}function Rx(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 x1(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(),i=String((t==null?void 0:t.default)??(t==null?void 0:t.value)??"").trim();return[e,r,s?`type: ${s}`:"",i?`default: ${i}`:""].filter(Boolean).join(" · ")}function w1(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 b1(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])),i=Ou(s.get(n),e.sourceHandle||"output-0","source"),a=Ou(s.get(r),e.targetHandle||"input-0","target");return!!(i&&a&&Lu(i,a))}function uq(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 i=t.find(l=>l.id===n),a=Ou(i,r,s);return a?{nodeId:n,handleId:r,handleType:s,slot:a,slotType:PT(a)}:null}function dq(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 i=0;i<s.length;i+=1){const a=s[i];if(!(t.handleType==="source"?Lu(t.slot,a):Lu(a,t.slot)))continue;const u=Vd(n);return{def:n,order:r,category:u,categoryRank:Fc.indexOf(u),slot:a,slotIndex:i,displayLabel:Ud(n),description:Rb(n)}}return null}).filter(Boolean).sort((n,r)=>{var a,l;const s=(a=n.slot)!=null&&a.required?0:1,i=(l=r.slot)!=null&&l.required?0:1;return s-i||n.slotIndex-r.slotIndex||n.categoryRank-r.categoryRank||n.order-r.order}):[]}function Kd(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 fq(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 i=`${n}_${s}`;if(!r.has(i))return i}return`${n}_${Date.now().toString(36)}`}function pq(e){return(e==null?void 0:e.default)!=null?String(e.default):(e==null?void 0:e.value)!=null?String(e.value):""}function Oh(e){return(Array.isArray(e)?e:[]).map(t=>({type:(t==null?void 0:t.type)||"node",name:(t==null?void 0:t.name)||"",default:pq(t),required:!!(t!=null&&t.required),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 sR(e){const t=(e==null?void 0:e.data)||{},n=r=>(Array.isArray(r)?r:[]).map((s,i)=>(s==null?void 0:s.showOnNode)===!1?"":[i,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 hq(e){var s,i;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[sR(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(((i=e==null?void 0:e.measured)==null?void 0:i.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)||"",(t==null?void 0:t.runningRunNodeId)||""].join("::")}function Lx(e,t){var c,p;const n=e!=null&&e.instances&&typeof e.instances=="object"?e.instances:{},r=oR(n),s=Array.isArray(e==null?void 0:e.edges)?e.edges:[],i=(c=e==null?void 0:e.ui)!=null&&c.nodePositions&&typeof e.ui.nodePositions=="object"?e.ui.nodePositions:{},a=(p=e==null?void 0:e.ui)!=null&&p.nodeSizes&&typeof e.ui.nodeSizes=="object"?e.ui.nodeSizes:{},l=new Set(Object.keys(r));for(const m of s)m!=null&&m.source&&l.add(String(m.source)),m!=null&&m.target&&l.add(String(m.target));const d=Array.from(l).map(m=>{const g=r[m]||{},b=g.definitionId||m,k=t.find(B=>B.id===b),y=A0(k)||b,v=t.find(B=>B.id===y)||k,w=g.marketplaceRef||rR(k),j=i[m]&&typeof i[m].x=="number"&&typeof i[m].y=="number"?i[m]:{x:320+l.size*20,y:180+l.size*12},P=!!Kn(y),_=a[m]&&typeof a[m].width=="number"&&typeof a[m].height=="number"?{width:a[m].width,height:a[m].height}:null,L=mu(_,{display:P});return{id:m,type:mp,position:j,...L?{width:L.width,height:L.height}:{},data:{label:g.label||dg(k)||dg(v)||m,definitionId:y,...w?{marketplaceRef:w}:{},...k!=null&&k.packageId?{marketplacePackageId:k.packageId}:{},...k!=null&&k.version?{marketplaceVersion:k.version}:{},schemaType:nR(y,v||k),role:g.role||"normal",model:g.model||void 0,body:g.body||"",script:g.script||"",...L?{nodeSize:L}:{},...P&&L?{displaySize:L}:{}}}}).map(m=>qf(m,r,t)),f=s.filter(m=>(m==null?void 0:m.source)&&(m==null?void 0:m.target)).map((m,g)=>({id:m.id||`we-${m.source}-${m.target}-${g}`,source:String(m.source),target:String(m.target),sourceHandle:m.sourceHandle??void 0,targetHandle:m.targetHandle??void 0,markerEnd:{type:Ls.ArrowClosed}}));return{nodes:d,edges:ET(f,d),instances:r}}function v1(e){return`${Tb}${e}`}function Ox(e){const t=String(e||"");return t.startsWith(Tb)?t.slice(Tb.length):t}function iR(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 Lb(e,t=[]){const n=new Map((Array.isArray(t)?t:[]).filter(c=>{var p;return Kn((p=c==null?void 0:c.data)==null?void 0:p.definitionId)}).map(c=>[c.id,c])),r=Array.isArray(e==null?void 0:e.nodeIds)?e.nodeIds:[],s=[],i=new Set;for(const c of r){const p=String(c||"").trim();!p||i.has(p)||!n.has(p)||(i.add(p),s.push(p))}const a={},l=e!=null&&e.nodePositions&&typeof e.nodePositions=="object"?e.nodePositions:{};s.forEach((c,p)=>{const m=l[c];a[c]=m&&typeof m.x=="number"&&typeof m.y=="number"?{x:m.x,y:m.y}:{x:180+p*36,y:120+p*28}});const u={},d=e!=null&&e.nodeSizes&&typeof e.nodeSizes=="object"?e.nodeSizes:{};s.forEach(c=>{const p=mu(d[c],{display:!0});p&&(u[c]=p)});const f=iR(e==null?void 0:e.viewport);return{nodeIds:s,nodePositions:a,nodeSizes:u,...f?{viewport:f}:{}}}function mq(e,t=[]){return Lb(e,t)}function gq(e){const t=Number.isFinite(e)?e:1;return Math.min(Math.max(t,.75),1)}async function yq(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 k1(e,t,n){const r=Number(e);return!Number.isFinite(r)||r<=0?0:Math.min(n,Math.max(t,Math.round(r)))}function mu(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:k1(n,ZT,eR)||tq,height:k1(r,Ib,tR)||Ib}}function zc(e){var s,i,a,l,u,d,f,c,p,m,g;const t=!!Kn((s=e==null?void 0:e.data)==null?void 0:s.definitionId),n=Number(((a=(i=e==null?void 0:e.data)==null?void 0:i.displaySize)==null?void 0:a.width)||((u=(l=e==null?void 0:e.data)==null?void 0:l.nodeSize)==null?void 0:u.width)||(e==null?void 0:e.width)||(t?(d=e==null?void 0:e.measured)==null?void 0:d.width:0)||0),r=Number(((c=(f=e==null?void 0:e.data)==null?void 0:f.displaySize)==null?void 0:c.height)||((m=(p=e==null?void 0:e.data)==null?void 0:p.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 mu({width:n,height:r},{display:t})}function Mh(e,t,n){var l,u;const r=oR(hp(e,n||{})),s=t.map(d=>({source:d.source,target:d.target,sourceHandle:d.sourceHandle??null,targetHandle:d.targetHandle??null})),i={},a={};for(const d of e){i[d.id]={x:((l=d.position)==null?void 0:l.x)||0,y:((u=d.position)==null?void 0:u.y)||0};const f=zc(d);f&&(a[d.id]=f)}return{version:1,instances:r,edges:s,ui:{nodePositions:i,nodeSizes:a}}}function oR(e){const t={};for(const[n,r]of Object.entries(e||{})){const s=String((r==null?void 0:r.definitionId)||n);if(!!Kn(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 Kn(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 Jl(e){const t=[...(e==null?void 0:e.inputs)||[],...(e==null?void 0:e.outputs)||[]],r=Kn(e==null?void 0:e.definitionId)==="image"?"src":"content",s=l=>String((l==null?void 0:l.value)??(l==null?void 0:l.default)??""),i=l=>s(l).trim(),a=t.find(l=>(l==null?void 0:l.name)===r&&i(l))||t.find(l=>(l==null?void 0:l.name)==="filePath"&&i(l))||t.find(l=>(l==null?void 0:l.type)==="text"&&i(l));return String((e==null?void 0:e.body)||(a?s(a):""))}function Wu(e){let t=String(e||"").trim();if(!t)return"";const n=t.match(/```(?:html|HTML)?\s*\n?([\s\S]*?)```/);if(n&&n[1])t=n[1].trim();else{const i=t.match(/```(?:html|HTML)?\s*\n?([\s\S]*)$/);i&&i[1]&&(t=i[1].trim())}t=t.replace(/^html\s*\n/i,"").replace(/```\s*$/g,"").trim();const s=[/<!doctype\b/i,/<html\b/i,/<head\b/i,/<body\b/i,/<style\b/i,/<script\b/i,/<main\b/i,/<section\b/i,/<article\b/i,/<div\b/i,/<svg\b/i,/<canvas\b/i].reduce((i,a)=>{const l=a.exec(t);return l?i<0?l.index:Math.min(i,l.index):i},-1);return s>0&&(t=t.slice(s).trim()),t}function aR(e){const t=Wu(e);if(!t.trim())return"";if(/<base\s+[^>]*target\s*=/i.test(t))return t;const n='<base target="_blank">';return/<head\b[^>]*>/i.test(t)?t.replace(/<head\b([^>]*)>/i,`<head$1>${n}`):/<html\b[^>]*>/i.test(t)?t.replace(/<html\b([^>]*)>/i,`<html$1><head>${n}</head>`):`<!doctype html><html><head>${n}</head><body>${t}</body></html>`}function xq(e,t){const n=String(e).trim().replace(/[\\/:*?"<>|]+/g,"-").replace(/\s+/g,"-").replace(/^-+|-+$/g,"")||"html-render",r=String(t).replace(/^\.+/,"")||"png";return`${n}.${r}`}function wq(e,t){const n=document.createElement("a");n.href=e,n.download=t,document.body.appendChild(n),n.click(),n.remove()}function S1(e,t){const n=URL.createObjectURL(e);try{wq(n,t)}finally{window.setTimeout(()=>URL.revokeObjectURL(n),1e3)}}function bq(e){const t=Wu(e),n=new DOMParser().parseFromString(t||"<body></body>","text/html"),r=new XMLSerializer,s=Array.from(n.querySelectorAll("style")).map(a=>r.serializeToString(a)).join(`
143
+ `).filter(l=>l.trim());if(s.length>=2&&ra(s[0]).length>1&&XT(s[1])){const l=ra(s[0]),u=JT(s[1]);return{columns:l.map((d,f)=>({key:String(f),label:d,align:u[f]||"left"})),rows:s.slice(2).map(d=>ra(d)),error:""}}const i=r.includes(" ")?" ":",",a=K7(r,i);return a.length>0&&a[0].length>1?{columns:a[0].map((u,d)=>u||`Column ${d+1}`).map((u,d)=>({key:String(d),label:u,align:"left"})),rows:a.slice(1),error:""}:{columns:[],rows:[],error:"No table data detected"}}function _0({content:e}){const t=h.useMemo(()=>Y7(e),[e]);return t.error||t.columns.length===0?o.jsxs("div",{className:"af-work-display-table-empty",children:[o.jsx("strong",{children:"Table data error"}),o.jsx("span",{children:t.error||"No columns found"})]}):o.jsx("div",{className:"af-work-display-table-wrap af-work-display-table-wrap--standalone",children:o.jsxs("table",{className:"af-work-display-table",children:[o.jsx("thead",{children:o.jsx("tr",{children:t.columns.map((n,r)=>o.jsx("th",{style:{textAlign:n.align||"left"},children:n.label},`${n.key}-${r}`))})}),o.jsx("tbody",{children:t.rows.map((n,r)=>o.jsx("tr",{children:t.columns.map((s,i)=>o.jsx("td",{style:{textAlign:s.align||"left"},children:ho(n[i])},`${s.key}-${i}`))},r))})]})})}function P0({content:e}){const t=h.useRef(null),n=h.useMemo(()=>V7(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 i=!1,a=null,l=null,u=null;return s({loading:!0,error:""}),I7(()=>import("./index-DgQRkS4v.js"),[]).then(d=>{i||!t.current||(a=d.init(t.current,"dark",{renderer:"canvas"}),a.setOption(n.spec.option,!0),u=()=>a==null?void 0:a.resize(),typeof ResizeObserver<"u"&&(l=new ResizeObserver(u),l.observe(t.current)),window.addEventListener("resize",u),window.requestAnimationFrame(u),i||s({loading:!1,error:""}))}).catch(d=>{i||s({loading:!1,error:String((d==null?void 0:d.message)||d)})}),()=>{var d,f;i=!0,u&&window.removeEventListener("resize",u),(d=l==null?void 0:l.disconnect)==null||d.call(l),(f=a==null?void 0:a.dispose)==null||f.call(a)}},[n]),!n.ok||r.error?o.jsxs("div",{className:"af-work-display-chart-error",children:[o.jsx("strong",{children:"Chart configuration error"}),o.jsx("span",{children:r.error||n.error})]}):o.jsxs("div",{className:"af-work-display-chart",children:[o.jsx("div",{ref:t,className:"af-work-display-chart__canvas"}),r.loading?o.jsx("div",{className:"af-work-display-chart__loading",children:"Loading chart..."}):null]})}const G7="af:workspace-graph:v2",Fc=["DISPLAY","CONTROL","TOOL","PROVIDE","AGENT"],X7=new Set(["control_start","control_end","control_load_skills","control_load_mcp"]),J7={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:""}]},Q7={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}]},Z7={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}]},eq=new Set(["png","jpg","jpeg","gif","webp","svg"]),tq=320,ZT=180,eR=960,Ib=96,tR=900,Tb="display-ref:",nq="0.1.61";function rq(){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 Xo(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 cg(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 eq.has(n)}function ug(e,t){const n=String(e||"").trim();if(!n)return"";if(/^(?:https?:|data:|blob:|file:)/i.test(n)||n.startsWith("/"))return n;const r=Xo(t||{});return r.set("path",n),`/api/workspace/file/raw?${r.toString()}`}function sq(e,t){const n=String(e||"").trim();if(!n)return"";const r=Xo(t||{});return r.set("path",n),r.set("download","1"),`/api/workspace/file/raw?${r.toString()}`}function iq(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 oq(e){return!e||typeof e.closest!="function"?!1:!!e.closest("input, textarea, select, [contenteditable='true']")}function aq(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 lq(e){return!e||typeof e.closest!="function"?!1:!!e.closest(".af-flow-node__prompt-stack")&&!aq(e)}function cq(e){const t=String(e||"").trim();if(!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 i=r==="readToolCall"?"读取文件/上下文":r==="grepToolCall"?"搜索代码":r==="editToolCall"?"编辑文件":r;return s==="completed"?`完成:${i}`:`执行:${i}`}return/^\[stderr\]/.test(t)?t:""}function g1(e){if(String((e==null?void 0:e.type)||"")!=="raw"||String((e==null?void 0:e.eventType)||"")!=="thinking")return"";const t=String((e==null?void 0:e.text)||"").trim();if(!t)return"";try{const n=JSON.parse(t);if((n==null?void 0:n.type)!=="thinking")return"";const r=String((n==null?void 0:n.subtype)||"");return r&&r!=="delta"?"":String((n==null?void 0:n.text)||(n==null?void 0:n.delta)||(n==null?void 0:n.thinking)||"").trim()}catch{return""}}function nR(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 rR(e){const t=String((e==null?void 0:e.marketplaceDefinitionId)||(e==null?void 0:e.id)||"").trim();return t.startsWith("marketplace:")?t:""}function A0(e){if(!e)return"";const t=String(e.baseDefinitionId||"").trim();if(!t)return String(e.id||"").trim();const n=e.runtime&&typeof e.runtime=="object"?e.runtime:{};return!!(n.entry||n.command)&&t==="tool_nodejs"?String(e.id||"").trim():t}function Vd(e){const t=String(A0(e)||(e==null?void 0:e.id)||"");return t==="workspace_run"?"CONTROL":t.startsWith("display_")?"DISPLAY":/^control/i.test(t)?"CONTROL":/^tool/i.test(t)?"TOOL":/^provide/i.test(t)?"PROVIDE":"AGENT"}function y1(e){return e==="DISPLAY"?"preview":e==="CONTROL"?"account_tree":e==="TOOL"?"build":e==="PROVIDE"?"database":"smart_toy"}function dg(e){return String((e==null?void 0:e.displayName)||(e==null?void 0:e.label)||(e==null?void 0:e.id)||"Node")}function Ud(e){return dg(e)}function Rb(e){return String((e==null?void 0:e.description)||(e==null?void 0:e.body)||"").replace(/\s+/g," ").trim()}function Rx(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 x1(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(),i=String((t==null?void 0:t.default)??(t==null?void 0:t.value)??"").trim();return[e,r,s?`type: ${s}`:"",i?`default: ${i}`:""].filter(Boolean).join(" · ")}function w1(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 b1(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])),i=Ou(s.get(n),e.sourceHandle||"output-0","source"),a=Ou(s.get(r),e.targetHandle||"input-0","target");return!!(i&&a&&Lu(i,a))}function uq(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 i=t.find(l=>l.id===n),a=Ou(i,r,s);return a?{nodeId:n,handleId:r,handleType:s,slot:a,slotType:PT(a)}:null}function dq(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 i=0;i<s.length;i+=1){const a=s[i];if(!(t.handleType==="source"?Lu(t.slot,a):Lu(a,t.slot)))continue;const u=Vd(n);return{def:n,order:r,category:u,categoryRank:Fc.indexOf(u),slot:a,slotIndex:i,displayLabel:Ud(n),description:Rb(n)}}return null}).filter(Boolean).sort((n,r)=>{var a,l;const s=(a=n.slot)!=null&&a.required?0:1,i=(l=r.slot)!=null&&l.required?0:1;return s-i||n.slotIndex-r.slotIndex||n.categoryRank-r.categoryRank||n.order-r.order}):[]}function Kd(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 fq(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 i=`${n}_${s}`;if(!r.has(i))return i}return`${n}_${Date.now().toString(36)}`}function pq(e){return(e==null?void 0:e.default)!=null?String(e.default):(e==null?void 0:e.value)!=null?String(e.value):""}function Oh(e){return(Array.isArray(e)?e:[]).map(t=>({type:(t==null?void 0:t.type)||"node",name:(t==null?void 0:t.name)||"",default:pq(t),required:!!(t!=null&&t.required),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 sR(e){const t=(e==null?void 0:e.data)||{},n=r=>(Array.isArray(r)?r:[]).map((s,i)=>(s==null?void 0:s.showOnNode)===!1?"":[i,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 hq(e){var s,i;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[sR(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(((i=e==null?void 0:e.measured)==null?void 0:i.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)||"",(t==null?void 0:t.runningRunNodeId)||""].join("::")}function Lx(e,t){var c,p;const n=e!=null&&e.instances&&typeof e.instances=="object"?e.instances:{},r=oR(n),s=Array.isArray(e==null?void 0:e.edges)?e.edges:[],i=(c=e==null?void 0:e.ui)!=null&&c.nodePositions&&typeof e.ui.nodePositions=="object"?e.ui.nodePositions:{},a=(p=e==null?void 0:e.ui)!=null&&p.nodeSizes&&typeof e.ui.nodeSizes=="object"?e.ui.nodeSizes:{},l=new Set(Object.keys(r));for(const m of s)m!=null&&m.source&&l.add(String(m.source)),m!=null&&m.target&&l.add(String(m.target));const d=Array.from(l).map(m=>{const g=r[m]||{},b=g.definitionId||m,k=t.find(B=>B.id===b),y=A0(k)||b,v=t.find(B=>B.id===y)||k,w=g.marketplaceRef||rR(k),j=i[m]&&typeof i[m].x=="number"&&typeof i[m].y=="number"?i[m]:{x:320+l.size*20,y:180+l.size*12},P=!!Kn(y),_=a[m]&&typeof a[m].width=="number"&&typeof a[m].height=="number"?{width:a[m].width,height:a[m].height}:null,L=mu(_,{display:P});return{id:m,type:mp,position:j,...L?{width:L.width,height:L.height}:{},data:{label:g.label||dg(k)||dg(v)||m,definitionId:y,...w?{marketplaceRef:w}:{},...k!=null&&k.packageId?{marketplacePackageId:k.packageId}:{},...k!=null&&k.version?{marketplaceVersion:k.version}:{},schemaType:nR(y,v||k),role:g.role||"normal",model:g.model||void 0,body:g.body||"",script:g.script||"",...L?{nodeSize:L}:{},...P&&L?{displaySize:L}:{}}}}).map(m=>qf(m,r,t)),f=s.filter(m=>(m==null?void 0:m.source)&&(m==null?void 0:m.target)).map((m,g)=>({id:m.id||`we-${m.source}-${m.target}-${g}`,source:String(m.source),target:String(m.target),sourceHandle:m.sourceHandle??void 0,targetHandle:m.targetHandle??void 0,markerEnd:{type:Ls.ArrowClosed}}));return{nodes:d,edges:ET(f,d),instances:r}}function v1(e){return`${Tb}${e}`}function Ox(e){const t=String(e||"");return t.startsWith(Tb)?t.slice(Tb.length):t}function iR(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 Lb(e,t=[]){const n=new Map((Array.isArray(t)?t:[]).filter(c=>{var p;return Kn((p=c==null?void 0:c.data)==null?void 0:p.definitionId)}).map(c=>[c.id,c])),r=Array.isArray(e==null?void 0:e.nodeIds)?e.nodeIds:[],s=[],i=new Set;for(const c of r){const p=String(c||"").trim();!p||i.has(p)||!n.has(p)||(i.add(p),s.push(p))}const a={},l=e!=null&&e.nodePositions&&typeof e.nodePositions=="object"?e.nodePositions:{};s.forEach((c,p)=>{const m=l[c];a[c]=m&&typeof m.x=="number"&&typeof m.y=="number"?{x:m.x,y:m.y}:{x:180+p*36,y:120+p*28}});const u={},d=e!=null&&e.nodeSizes&&typeof e.nodeSizes=="object"?e.nodeSizes:{};s.forEach(c=>{const p=mu(d[c],{display:!0});p&&(u[c]=p)});const f=iR(e==null?void 0:e.viewport);return{nodeIds:s,nodePositions:a,nodeSizes:u,...f?{viewport:f}:{}}}function mq(e,t=[]){return Lb(e,t)}function gq(e){const t=Number.isFinite(e)?e:1;return Math.min(Math.max(t,.75),1)}async function yq(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 k1(e,t,n){const r=Number(e);return!Number.isFinite(r)||r<=0?0:Math.min(n,Math.max(t,Math.round(r)))}function mu(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:k1(n,ZT,eR)||tq,height:k1(r,Ib,tR)||Ib}}function zc(e){var s,i,a,l,u,d,f,c,p,m,g;const t=!!Kn((s=e==null?void 0:e.data)==null?void 0:s.definitionId),n=Number(((a=(i=e==null?void 0:e.data)==null?void 0:i.displaySize)==null?void 0:a.width)||((u=(l=e==null?void 0:e.data)==null?void 0:l.nodeSize)==null?void 0:u.width)||(e==null?void 0:e.width)||(t?(d=e==null?void 0:e.measured)==null?void 0:d.width:0)||0),r=Number(((c=(f=e==null?void 0:e.data)==null?void 0:f.displaySize)==null?void 0:c.height)||((m=(p=e==null?void 0:e.data)==null?void 0:p.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 mu({width:n,height:r},{display:t})}function Mh(e,t,n){var l,u;const r=oR(hp(e,n||{})),s=t.map(d=>({source:d.source,target:d.target,sourceHandle:d.sourceHandle??null,targetHandle:d.targetHandle??null})),i={},a={};for(const d of e){i[d.id]={x:((l=d.position)==null?void 0:l.x)||0,y:((u=d.position)==null?void 0:u.y)||0};const f=zc(d);f&&(a[d.id]=f)}return{version:1,instances:r,edges:s,ui:{nodePositions:i,nodeSizes:a}}}function oR(e){const t={};for(const[n,r]of Object.entries(e||{})){const s=String((r==null?void 0:r.definitionId)||n);if(!!Kn(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 Kn(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 Jl(e){const t=[...(e==null?void 0:e.inputs)||[],...(e==null?void 0:e.outputs)||[]],r=Kn(e==null?void 0:e.definitionId)==="image"?"src":"content",s=l=>String((l==null?void 0:l.value)??(l==null?void 0:l.default)??""),i=l=>s(l).trim(),a=t.find(l=>(l==null?void 0:l.name)===r&&i(l))||t.find(l=>(l==null?void 0:l.name)==="filePath"&&i(l))||t.find(l=>(l==null?void 0:l.type)==="text"&&i(l));return String((e==null?void 0:e.body)||(a?s(a):""))}function Wu(e){let t=String(e||"").trim();if(!t)return"";const n=t.match(/```(?:html|HTML)?\s*\n?([\s\S]*?)```/);if(n&&n[1])t=n[1].trim();else{const i=t.match(/```(?:html|HTML)?\s*\n?([\s\S]*)$/);i&&i[1]&&(t=i[1].trim())}t=t.replace(/^html\s*\n/i,"").replace(/```\s*$/g,"").trim();const s=[/<!doctype\b/i,/<html\b/i,/<head\b/i,/<body\b/i,/<style\b/i,/<script\b/i,/<main\b/i,/<section\b/i,/<article\b/i,/<div\b/i,/<svg\b/i,/<canvas\b/i].reduce((i,a)=>{const l=a.exec(t);return l?i<0?l.index:Math.min(i,l.index):i},-1);return s>0&&(t=t.slice(s).trim()),t}function aR(e){const t=Wu(e);if(!t.trim())return"";if(/<base\s+[^>]*target\s*=/i.test(t))return t;const n='<base target="_blank">';return/<head\b[^>]*>/i.test(t)?t.replace(/<head\b([^>]*)>/i,`<head$1>${n}`):/<html\b[^>]*>/i.test(t)?t.replace(/<html\b([^>]*)>/i,`<html$1><head>${n}</head>`):`<!doctype html><html><head>${n}</head><body>${t}</body></html>`}function xq(e,t){const n=String(e).trim().replace(/[\\/:*?"<>|]+/g,"-").replace(/\s+/g,"-").replace(/^-+|-+$/g,"")||"html-render",r=String(t).replace(/^\.+/,"")||"png";return`${n}.${r}`}function wq(e,t){const n=document.createElement("a");n.href=e,n.download=t,document.body.appendChild(n),n.click(),n.remove()}function S1(e,t){const n=URL.createObjectURL(e);try{wq(n,t)}finally{window.setTimeout(()=>URL.revokeObjectURL(n),1e3)}}function bq(e){const t=Wu(e),n=new DOMParser().parseFromString(t||"<body></body>","text/html"),r=new XMLSerializer,s=Array.from(n.querySelectorAll("style")).map(a=>r.serializeToString(a)).join(`
144
144
  `),i=n.body?Array.from(n.body.childNodes).map(a=>r.serializeToString(a)).join(""):t;return`
145
145
  <style>
146
146
  * { box-sizing: border-box; }
@@ -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-mvyspN0Q.js"></script>
18
+ <script type="module" crossorigin src="/assets/index-DdSsdIza.js"></script>
19
19
  <link rel="stylesheet" crossorigin href="/assets/index-Db5Z0V8r.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.60",
3
+ "version": "0.1.61",
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",