pisper 0.6.22 → 0.6.23

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.
Files changed (108) hide show
  1. package/package.json +5 -5
  2. package/web/.vite/manifest.json +550 -550
  3. package/web/assets/{AppDialog-BluIYP8v.js → AppDialog-_fH6eQpb.js} +1 -1
  4. package/web/assets/{AppOverlays-vn_Ter3M.js → AppOverlays-BMST1vfu.js} +1 -1
  5. package/web/assets/{AssetsPage-CLlSYXp8.js → AssetsPage-CDJmOEP7.js} +1 -1
  6. package/web/assets/{BoardPage-nSsZudtr.js → BoardPage-CJT8VYBj.js} +3 -3
  7. package/web/assets/{ChannelsPage-DqnfAoWC.js → ChannelsPage-l3o-utCr.js} +1 -1
  8. package/web/assets/{ChatAppearancePage-2itvW4ex.js → ChatAppearancePage-CdJHIq2M.js} +1 -1
  9. package/web/assets/{ChatHistoryPage-OPTj6spQ.js → ChatHistoryPage-7EAqApuM.js} +1 -1
  10. package/web/assets/{ChatPage-C_3_rpJn.js → ChatPage-DPnOu_7p.js} +3 -3
  11. package/web/assets/{ConfigPage-DnPb_QrV.js → ConfigPage-Qd6FIlD6.js} +2 -2
  12. package/web/assets/{DesktopWindowControls-DQf3N-Pq.js → DesktopWindowControls-X6khTXXD.js} +1 -1
  13. package/web/assets/{FeaturePage-B8dFhtLs.js → FeaturePage-CgoODqI_.js} +1 -1
  14. package/web/assets/{FileAttachmentPreview-CeQTyfpt.js → FileAttachmentPreview-WMfxb0MX.js} +1 -1
  15. package/web/assets/{FloatingWidgets-CWpMJq1K.js → FloatingWidgets-CtU5t-r2.js} +1 -1
  16. package/web/assets/{FocusRuntimeControls-J_hbXz7v.js → FocusRuntimeControls-DSAsb9Mz.js} +1 -1
  17. package/web/assets/{GitDiffViewer-DZm3DoP7.js → GitDiffViewer-AcMle1-H.js} +1 -1
  18. package/web/assets/{ManageProjectsDialog-VaG1Uu6p.js → ManageProjectsDialog-jq84FKmf.js} +1 -1
  19. package/web/assets/{MarkdownMessage-Dbypp4RC.js → MarkdownMessage-BDrWMmiv.js} +1 -1
  20. package/web/assets/{McpPage-D8NZyKoO.js → McpPage-Dyz-7b-d.js} +1 -1
  21. package/web/assets/{MemoryPage-DZsAXror.js → MemoryPage-CG-PNmFi.js} +1 -1
  22. package/web/assets/{MobileNavigation-DHWkx5h0.js → MobileNavigation-oAbj8oEW.js} +1 -1
  23. package/web/assets/{MorePage-PK0vEEda.js → MorePage-7NckHj2X.js} +1 -1
  24. package/web/assets/{NewFolderDialog-DjC2xSrj.js → NewFolderDialog-CSwYKD8L.js} +1 -1
  25. package/web/assets/{PageHeader-CcgJJB4K.js → PageHeader-BWTQQV6l.js} +1 -1
  26. package/web/assets/{PhoneDrawer-DMIlKCRW.js → PhoneDrawer-CRjYXK4U.js} +1 -1
  27. package/web/assets/{PhoneMenuButton-dzvj0NS0.js → PhoneMenuButton-YyU4CxN-.js} +1 -1
  28. package/web/assets/{PhoneTopBar-UqSQG8KO.js → PhoneTopBar-fFBj5SYy.js} +1 -1
  29. package/web/assets/{PluginsPage-D_7E0Mcm.js → PluginsPage-TtUACDkO.js} +1 -1
  30. package/web/assets/{SafeModePrompt-CYubRBr0.js → SafeModePrompt-BdJZpk9Z.js} +1 -1
  31. package/web/assets/{SchedulesPage-BsX821QZ.js → SchedulesPage-CEont77M.js} +1 -1
  32. package/web/assets/{SessionBrowserPane-ZvjA5vop.js → SessionBrowserPane-C41VsVCn.js} +2 -2
  33. package/web/assets/{SessionContextPanel-39eXpERL.js → SessionContextPanel-UpOQ6Tf5.js} +2 -2
  34. package/web/assets/{SessionHome-Cm131bvz.js → SessionHome-ByCLax94.js} +1 -1
  35. package/web/assets/{SessionInspector-DiSWVd6R.js → SessionInspector-BQ-ZzmN8.js} +1 -1
  36. package/web/assets/{SessionShell-DiWPHdio.js → SessionShell-DzcjZ9sC.js} +1 -1
  37. package/web/assets/{SettingsSidebar-Br83KuNT.js → SettingsSidebar-BnzGBl2P.js} +1 -1
  38. package/web/assets/{ShortcutHelpDialog-rmlTJwrg.js → ShortcutHelpDialog-6xpCSBSl.js} +1 -1
  39. package/web/assets/{ShortcutKeys-CE7wsdx4.js → ShortcutKeys-wE65pcQn.js} +1 -1
  40. package/web/assets/{SidebarUpdateStatus-BSxoGQFm.js → SidebarUpdateStatus-1ObaQPYU.js} +1 -1
  41. package/web/assets/{SkillsPage-zrZCbP5L.js → SkillsPage-DCqMIsRZ.js} +1 -1
  42. package/web/assets/{TaskProcessesPane-B9a-bK8Q.js → TaskProcessesPane-B4o1GC7K.js} +1 -1
  43. package/web/assets/{TaskTerminalView-Dnl9t0Yq.js → TaskTerminalView-DxVr8Wtj.js} +1 -1
  44. package/web/assets/{TerminalPanel-EbsJNe9L.js → TerminalPanel-lHTUD4Da.js} +1 -1
  45. package/web/assets/{WebDesktopPet-CqR3puOx.js → WebDesktopPet-KS-ffs_Y.js} +1 -1
  46. package/web/assets/{WorkflowsPage-ChXjB-wW.js → WorkflowsPage-BiWUVESO.js} +1 -1
  47. package/web/assets/{WorkspacePicker-CojYPYIa.js → WorkspacePicker-BdQxcQ7F.js} +1 -1
  48. package/web/assets/{api-3pnTJcsp.js → api-CWaE7hay.js} +1 -1
  49. package/web/assets/{app-update-C6PjqV-N.js → app-update-BhZYouFz.js} +1 -1
  50. package/web/assets/{approval-confirm-Ng3lhZR9.js → approval-confirm-hgX2Qj5h.js} +1 -1
  51. package/web/assets/{board-projects-Cn83x27D.js → board-projects-Br5xIhXi.js} +1 -1
  52. package/web/assets/{bots-store-B0uE78FQ.js → bots-store-BxXimpjG.js} +1 -1
  53. package/web/assets/{chat-api-DE-00AQt.js → chat-api-DIe7JvSq.js} +1 -1
  54. package/web/assets/{client-store-B0G8KCEA.js → client-store-BVvrKxe7.js} +1 -1
  55. package/web/assets/{config-search-Cnob89Wh.js → config-search-BS9VXlM0.js} +1 -1
  56. package/web/assets/{dialog-sq6TFrs2.js → dialog-VGmRGR6P.js} +1 -1
  57. package/web/assets/{events-BYm_7rfH.js → events-CAk4qwf5.js} +1 -1
  58. package/web/assets/{folder-paths-BeZN9wq7.js → folder-paths-9JtGeIlu.js} +1 -1
  59. package/web/assets/{hosts-BWu_xvML.js → hosts-Cc6SO6LM.js} +1 -1
  60. package/web/assets/i18n-BkTAd6ln.js +1 -0
  61. package/web/assets/{index-DT21IKeB.js → index-BEFqinGB.js} +2 -2
  62. package/web/assets/{mount-app-YAzhl88_.js → mount-app-Z24rEaKY.js} +3 -3
  63. package/web/assets/{permission-rules-api-DdYftUQE.js → permission-rules-api-C_to5cI_.js} +1 -1
  64. package/web/assets/{pick-system-directory-LOpQirAM.js → pick-system-directory-BEo0M2BR.js} +1 -1
  65. package/web/assets/{placements-BzbpQDQ7.js → placements-41bRhaLX.js} +2 -2
  66. package/web/assets/{popover-CEwCyvso.js → popover-CyHncZuo.js} +1 -1
  67. package/web/assets/{public-CgfPT7gK.js → public-BLPYRVOl.js} +2 -2
  68. package/web/assets/{public-CoivUKr6.js → public-BxfK5CJX.js} +1 -1
  69. package/web/assets/{public-Ck1i4t8o.js → public-Dxz02eyM.js} +1 -1
  70. package/web/assets/{public-components-CQf0np0Z.js → public-components--elKl8rY.js} +1 -1
  71. package/web/assets/public-diff-DuYNyToX.js +1 -0
  72. package/web/assets/public-events-CVwkgTyV.js +1 -0
  73. package/web/assets/{public-flags-DZvYvsWH.js → public-flags-bV1lnTa9.js} +1 -1
  74. package/web/assets/{public-session-Bx2TqcKh.js → public-session-71n0uBba.js} +1 -1
  75. package/web/assets/{public-sidebar-3z7xPwe3.js → public-sidebar-COsk0-e3.js} +1 -1
  76. package/web/assets/{runtime-capabilities-store-CDhzPVU-.js → runtime-capabilities-store-DIlItxug.js} +1 -1
  77. package/web/assets/{safe-mode-instance-D_H4Z8Xv.js → safe-mode-instance-B4YViTAj.js} +1 -1
  78. package/web/assets/safe-mode-sentinel-BOIlJBCx.js +1 -0
  79. package/web/assets/{session-change-summary-api-CxOV5OrA.js → session-change-summary-api-Dvl_So5i.js} +1 -1
  80. package/web/assets/{session-home-chPk0XEV.js → session-home-CpduZY-Y.js} +1 -1
  81. package/web/assets/{session-organization-api-A3EudhgK.js → session-organization-api-C3f-pQuJ.js} +1 -1
  82. package/web/assets/{session-scope-CF4OLtKw.js → session-scope-9NO78BDR.js} +1 -1
  83. package/web/assets/{session-tree-actions-DNefaiZO.js → session-tree-actions-Ch4rkxjV.js} +1 -1
  84. package/web/assets/{session-tree-summary-DPqtCWEP.js → session-tree-summary-DXft8Rmr.js} +1 -1
  85. package/web/assets/{shortcuts-zcQP1D4E.js → shortcuts-BtoPU0le.js} +1 -1
  86. package/web/assets/{side-chat-context-BpjCorLu.js → side-chat-context-D7xA1822.js} +4 -4
  87. package/web/assets/{sidebar-Bb6NlEeR.js → sidebar-CG-HyJsS.js} +1 -1
  88. package/web/assets/{sidebar-store-CQWNlMxT.js → sidebar-store-C9Pot2yY.js} +1 -1
  89. package/web/assets/{speech-session-2WJk-z3P.js → speech-session-TxJG88R-.js} +1 -1
  90. package/web/assets/{startup-queries-C9AHlyOp.js → startup-queries-VYxaEx9w.js} +1 -1
  91. package/web/assets/{use-i18n-BPJI6-Ue.js → use-i18n-D2lZDIiK.js} +1 -1
  92. package/web/assets/{use-open-bot-5wf_No4c.js → use-open-bot-CFe4Kt8r.js} +1 -1
  93. package/web/assets/{use-studio-actions-C5heO0nL.js → use-studio-actions-CfZNLW6c.js} +1 -1
  94. package/web/assets/{useCatalogProjects-BWKT2GrE.js → useCatalogProjects-CGj_Phaf.js} +1 -1
  95. package/web/assets/{useNewProjectPicker-BCkEpwht.js → useNewProjectPicker-pn-RD8BP.js} +2 -2
  96. package/web/assets/{useNow-e0HHzVad.js → useNow-CtiiZXYi.js} +1 -1
  97. package/web/assets/{usePhoneShell-C90daPSI.js → usePhoneShell-CnoUyYeJ.js} +1 -1
  98. package/web/assets/{useSessionListQuery-Ezaq4rI5.js → useSessionListQuery-BeFsCihm.js} +1 -1
  99. package/web/assets/{useSessionRowActions-BIJ-eKcN.js → useSessionRowActions-Cv7ZLvGZ.js} +1 -1
  100. package/web/assets/{useSidebarModel-DDqX8onb.js → useSidebarModel-BFDzcvAc.js} +1 -1
  101. package/web/assets/{web-preview-C5NXKRu-.js → web-preview-BvYYjssc.js} +1 -1
  102. package/web/assets/{web-preview-events-CIJw4Wx-.js → web-preview-events-DREck2MQ.js} +1 -1
  103. package/web/assets/{workspace-order-store-0jm2oVHS.js → workspace-order-store-BDSlzOUk.js} +1 -1
  104. package/web/index.html +1 -1
  105. package/web/assets/i18n-Cewq43aI.js +0 -1
  106. package/web/assets/public-diff-wY-tpFFs.js +0 -1
  107. package/web/assets/public-events-B-fuAF9_.js +0 -1
  108. package/web/assets/safe-mode-sentinel-BG7I9wh1.js +0 -1
@@ -1 +1 @@
1
- import{a as e}from"./rolldown-runtime-B0Z9INg1.js";import{f as t,m as n,u as r}from"./vendor-router-CSN_DGvx.js";import{i,r as a}from"./vendor-react-DwNgTV1j.js";import{p as o,r as s}from"./routes-DIeaqWVc.js";import{d as c}from"./i18n-Cewq43aI.js";import{t as l}from"./use-i18n-BPJI6-Ue.js";import{r as u,t as d}from"./useQuery-DdcpUQhO.js";import{a as f,i as p,l as m,t as h,u as g}from"./api-3pnTJcsp.js";import{t as _}from"./usePhoneShell-C90daPSI.js";import{t as v}from"./createLucideIcon-Cd-3GVxJ.js";import{t as y}from"./arrow-down-CDGua-ue.js";import{t as b}from"./arrow-up-DST6-qVQ.js";import{t as x}from"./bell-BjONAtgH.js";import{t as S}from"./bot-B3TaBp_T.js";import{t as C}from"./braces-DQcXLGFF.js";import{t as w}from"./check-2vYc6QaP.js";import{t as T}from"./chevron-down-CxtxIjiP.js";import{t as E}from"./chevron-left-BAtyp3_6.js";import{t as ee}from"./chevron-right-C3t2Rckj.js";import{t as D}from"./circle-check-iEdCm3Pw.js";import{n as O,t as k}from"./image-plus-D7bzZog0.js";import{t as A}from"./code-xml-BrUXrBax.js";import{t as j}from"./copy-DHmIFc52.js";import{t as M}from"./download-BCfIiuaL.js";import{t as N}from"./ellipsis-CfGKfbq6.js";import{t as P}from"./file-code-corner-BnE1ljT0.js";import{t as F}from"./file-Bllajneu.js";import{t as te}from"./git-branch-N7LGjtzt.js";import{t as ne}from"./grip-vertical-B__LYT0s.js";import{t as I}from"./image-BY_c3FYU.js";import{t as re}from"./loader-circle-BOwQzHB-.js";import{n as ie,t as ae}from"./send-QxBfLFo-.js";import{n as oe,r as se,t as ce}from"./zap-DZHw5afO.js";import{t as le}from"./panel-right-BSUtqUd8.js";import{t as ue}from"./paperclip-BCXrwYpb.js";import{t as de}from"./pencil-U08v_vV9.js";import{t as fe}from"./play-DNDjDNGn.js";import{t as pe}from"./plus-fQbSqB1n.js";import{t as me}from"./refresh-cw-TbWxTY4K.js";import{t as L}from"./rocket-BgLSjoHY.js";import{t as he}from"./save-CHBB52P8.js";import{t as ge}from"./search-D0mqDaf_.js";import{t as _e}from"./server-BgNvmqwJ.js";import{t as ve}from"./settings-2-CXJjXJS9.js";import{t as ye}from"./square-bHHVTT3G.js";import{t as be}from"./trash-2-CNrPOoPR.js";import{t as xe}from"./triangle-alert-CE1q54ci.js";import{t as Se}from"./workflow-Bg94dy8I.js";import{t as Ce}from"./x-07u4-129.js";import{t as we}from"./more-pages-D_PnxLN0.js";import{c as Te,i as Ee,p as De,r as Oe,t as ke}from"./dropdown-menu-Ds0gD8S8.js";import{t as R}from"./label-CVWjEcfV.js";import{i as Ae,n as je,t as Me}from"./popover-CEwCyvso.js";import{t as Ne}from"./progress-5odAz3B9.js";import{t as Pe}from"./slider-DTmAZl-R.js";import{t as z}from"./switch-D_G8wFhs.js";import{i as Fe,r as Ie,t as Le}from"./tabs-DsgBuvJv.js";import{t as B}from"./utils-C8uzG5AZ.js";import{n as Re,t as V}from"./button-CCcCN8tE.js";import{s as ze}from"./shortcuts-zcQP1D4E.js";import{a as Be,n as Ve,o as He,r as Ue,t as We}from"./sheet-BTaIEX4w.js";import{a as Ge}from"./format-DMJQzoZ7.js";import{t as Ke}from"./StatusGlyph-1KgitlUg.js";import{a as qe,i as Je,l as Ye,o as Xe,s as Ze,t as Qe,u as $e}from"./dialog-sq6TFrs2.js";import{t as H}from"./input-CPw-zkYh.js";import{t as et}from"./textarea-DmATpOqT.js";import{n as tt,t as nt}from"./PageState-Cz6vFMXv.js";import{n as rt,t as it}from"./alert-firawb0H.js";import{a as at,i as ot,n as st,o as ct,r as lt,s as ut}from"./FeaturePage-B8dFhtLs.js";import{n as U}from"./field-DoLEb0np.js";import{t as W}from"./AppSelect-BD6RAaJ5.js";import{n as dt,r as ft,t as pt}from"./collapsible-Dcoy-qnz.js";import{n as mt,r as ht,t as gt}from"./browser-notifications-DBS0oXqN.js";import{t as _t}from"./PageFrame-DNwGZ-Dz.js";import{a as vt,c as yt,d as bt,f as xt,i as St,l as Ct,n as wt,o as Tt,r as Et,s as Dt,t as Ot,u as kt}from"./vendor-xyflow-hxQFvEHK.js";import{n as At}from"./navigation-DkcKi1_5.js";var jt=v(`clock-3`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 6v6h4`,key:`135r8i`}]]),Mt=v(`file-up`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M12 12v6`,key:`3ahymv`}],[`path`,{d:`m15 15-3-3-3 3`,key:`15xj92`}]]),Nt=v(`pause`,[[`rect`,{x:`14`,y:`3`,width:`5`,height:`18`,rx:`1`,key:`kaeet6`}],[`rect`,{x:`5`,y:`3`,width:`5`,height:`18`,rx:`1`,key:`1wsw3u`}]]),G=e(i(),1),Pt=new Set([`__proto__`,`constructor`,`prototype`]),Ft=/^[A-Za-z_][A-Za-z0-9_]{0,79}$/,K=class extends Error{constructor(e,t=``,n=``){super(e===`workflow_template_unknown`?`工作流模板引用了未知或不可用的变量。`:`工作流输入无效,请检查字段名称、类型和必填值。`),this.code=e,this.inputName=t,this.label=n,this.statusCode=400}};function It(e){if(!e||typeof e!=`object`||Array.isArray(e))throw new K(`workflow_input_type`);return e}function Lt(e){let t=It(e);if(Object.keys(t).some(e=>![`id`,`name`,`mimeType`,`size`].includes(e))||typeof t.id!=`string`||!/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,79}$/.test(t.id)||typeof t.name!=`string`||!t.name.trim()||t.name.length>160||/[\\/]/.test(t.name)||typeof t.mimeType!=`string`||![`image/png`,`image/jpeg`,`image/webp`,`video/mp4`,`video/webm`].includes(t.mimeType)||typeof t.size!=`number`||!Number.isSafeInteger(t.size)||t.size<=0||t.size>(t.mimeType.startsWith(`image/`)?8:64)*1024*1024)throw new K(`workflow_input_type`);return{id:t.id,name:t.name,mimeType:t.mimeType,size:t.size}}function Rt(e,t,n){let r=t==null||typeof t==`string`&&!t.trim();if(n&&r)throw new K(`workflow_input_required`,e.name,e.label);if(r)return e.type===`boolean`?!1:e.type===`image`||e.type===`video`?null:``;if(typeof t==`string`&&t.length>16e3)throw new K(`workflow_input_too_long`,e.name,e.label);if(e.type===`number`){if(typeof t!=`number`&&typeof t!=`string`||typeof t==`string`&&!/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i.test(t.trim())||!Number.isFinite(Number(t)))throw new K(`workflow_input_type`,e.name,e.label);return Number(t)}if(e.type===`boolean`){if(t!==!0&&t!==!1&&t!==`true`&&t!==`false`)throw new K(`workflow_input_type`,e.name,e.label);return t===!0||t===`true`}if(e.type===`image`||e.type===`video`){let n=Lt(t);if(!n.mimeType.startsWith(`${e.type}/`))throw new K(`workflow_input_type`,e.name,e.label);return n}if(typeof t!=`string`)throw new K(`workflow_input_type`,e.name,e.label);return t}function zt(e){if(e===void 0)return[];if(!Array.isArray(e)||e.length>30)throw new K(`workflow_input_invalid_definition`);let t=new Set,n=new Set;return e.map((e,r)=>{let i=It(e),a=i.name;if(typeof a!=`string`||!Ft.test(a)||Pt.has(a))throw new K(`workflow_input_unsafe_name`);let o=i.id===void 0?`input-${r+1}`:i.id,s=i.label===void 0?a:i.label;if(typeof o!=`string`||!o||o.length>80||typeof s!=`string`||!s.trim()||s.length>120||i.description!==void 0&&(typeof i.description!=`string`||i.description.length>300)||i.required!==void 0&&typeof i.required!=`boolean`)throw new K(`workflow_input_invalid_definition`,a);if(t.has(a)||n.has(o))throw new K(`workflow_input_duplicate_name`,a,s);t.add(a),n.add(o);let c=i.type===void 0?`string`:i.type;if(c!==`string`&&c!==`text`&&c!==`number`&&c!==`boolean`&&c!==`image`&&c!==`video`)throw new K(`workflow_input_invalid_definition`,a,s);let l={id:o,name:a,label:s.trim(),type:c,required:i.required===!0,defaultValue:``,description:typeof i.description==`string`?i.description:``};return l.defaultValue=i.defaultValue==null||i.defaultValue===``?c===`image`||c===`video`?null:``:Rt(l,i.defaultValue,!1),l})}function Bt(e,t={}){let n=zt(e),r=It(t),i=n.length?n:[{id:`task`,name:`task`,label:`Task`,type:`text`,required:!1,defaultValue:``,description:``}],a=new Set(i.map(e=>e.name));for(let e of Object.keys(r))if(!a.has(e)||Pt.has(e))throw new K(`workflow_input_unknown`,e);let o={};for(let e of i){if(!n.length&&!Object.hasOwn(r,e.name))continue;let t=Object.hasOwn(r,e.name)?r[e.name]:e.defaultValue;o[e.name]=Rt(e,t,e.required)}return o}var Vt=Object.freeze([`S`,`SW`,`W`,`NW`,`N`,`NE`,`E`,`SE`]);function q(e){return Object.assign(Error(e),{code:e,statusCode:400})}function J(e){if(!e||typeof e!=`object`||Array.isArray(e))throw q(`workflow_image_invalid`);return e}function Y(e,t,n,r){if(e===void 0)return t;if(typeof e!=`number`||!Number.isFinite(e)||e<n||e>r)throw q(`workflow_image_invalid`);return e}function Ht(e,t,n){if(e===void 0)return t;if(typeof e!=`string`||e.length>n)throw q(`workflow_image_invalid`);return e.trim()}function Ut(e={}){let t=J(e),n=t.colors??[],r=t.directions??[`S`],i=t.frameOrder??[],a=t.transforms??[],o=J(t.region??{});if(!Array.isArray(n)||n.length>8||n.some(e=>typeof e!=`string`||!/^#[0-9a-f]{6}$/i.test(e))||!Array.isArray(r)||r.length<1||r.length>8||r.some(e=>!Vt.some(t=>t===e))||new Set(r).size!==r.length||!Array.isArray(i)||i.length>512||i.some(e=>!Number.isSafeInteger(e)||e<0||e>=512)||new Set(i).size!==i.length||!Array.isArray(a)||a.length>512)throw q(`workflow_image_invalid`);let s=t.method??`color`,c=t.align??`bottom-center`;if(s!==`color`&&s!==`model`||c!==`center`&&c!==`bottom-center`&&c!==`none`)throw q(`workflow_image_invalid`);let l=Ht(t.inputName,`reference`,80);if(!/^[a-zA-Z][a-zA-Z0-9_]{0,79}$/.test(l)||[`constructor`,`prototype`,`__proto__`].includes(l))throw q(`workflow_image_invalid`);let u={inputName:l,method:s,colors:n.map(e=>String(e)),tolerance:Y(t.tolerance,24,0,255),softness:Y(t.softness,8,0,64),edgeConnected:t.edgeConnected!==!1,region:{x:Y(o.x,25,0,99),y:Y(o.y,25,0,99),width:Y(o.width,20,1,100),height:Y(o.height,10,1,100)},action:Ht(t.action,`idle`,160),frameCount:Math.round(Y(t.frameCount,4,1,16)),directions:[...r],columns:Math.round(Y(t.columns,4,1,16)),rows:Math.round(Y(t.rows,1,1,16)),durationMs:Math.round(Y(t.durationMs,125,16,1e4)),trim:t.trim!==!1,align:c,padding:Math.round(Y(t.padding,4,0,64)),maxFrameSize:Math.round(Y(t.maxFrameSize,256,16,1024)),frameOrder:i.map(e=>Number(e)),transforms:a.map(e=>{let t=J(e);return{index:Math.round(Y(t.index,0,0,511)),x:Y(t.x,0,-4096,4096),y:Y(t.y,0,-4096,4096),rotation:Y(t.rotation,0,-360,360),scale:Y(t.scale,1,.05,8),opacity:Y(t.opacity,1,0,1),durationMs:Math.round(Y(t.durationMs,125,16,1e4)),enabled:t.enabled!==!1}}),filename:Ht(t.filename,`animation`,100)};if(new Set(u.transforms.map(e=>e.index)).size!==u.transforms.length)throw q(`workflow_image_invalid`);return u}function Wt(e){let t=J(e);if(t.type!==`workflow-images`||t.version!==1||!Array.isArray(t.frames)||t.frames.length>512)throw q(`workflow_image_invalid`);let n={type:`workflow-images`,version:1,frames:t.frames.map(e=>{let t=J(e),n=Lt(t.media);if(!n.mimeType.startsWith(`image/`))throw q(`workflow_image_invalid`);return{media:n,width:Y(t.width,1,1,4096),height:Y(t.height,1,1,4096),durationMs:Y(t.durationMs,125,16,1e4),action:Ht(t.action,``,160),direction:Ht(t.direction,``,16),columns:Y(t.columns,1,1,16),rows:Y(t.rows,1,1,16),frameCount:Y(t.frameCount,1,1,256)}})};if(t.atlas!==void 0){let e=J(t.atlas);if(!Array.isArray(e.frames)||e.frames.length>512)throw q(`workflow_image_invalid`);n.atlas={media:Lt(e.media),width:Y(e.width,1,1,4096),height:Y(e.height,1,1,4096),frames:e.frames.map(e=>{let t=J(e);return{x:Y(t.x,0,0,4096),y:Y(t.y,0,0,4096),width:Y(t.width,1,1,4096),height:Y(t.height,1,1,4096),durationMs:Y(t.durationMs,125,16,1e4),action:Ht(t.action,``,160),direction:Ht(t.direction,``,16)}})}}return n}var Gt=Object.freeze([`media-input`,`media-background`,`media-inpaint`,`media-generate`,`media-frames`,`media-transform`,`media-preview`,`media-export`]);function Kt(e){return typeof e==`string`&&Gt.some(t=>t===e)}var X=a(),qt=({className:e,...t})=>(0,X.jsx)(Et,{className:B(`gap-px overflow-hidden rounded-md border bg-card p-1 shadow-none!`,`[&>button]:rounded-md [&>button]:border-none! [&>button]:bg-transparent! [&>button]:hover:bg-secondary!`,e),...t}),Jt=[`trigger`,`prompt`,`skill`,`file`,`mcp`,`notification`,`condition`,`parallel`,`approval`,...Gt];function Yt(e){return new Map(e.map((e,t)=>[e.id,t]))}function Xt(e=[],t){return e.slice(1).map((n,r)=>{let i=e[r];return{id:t?.(r,i.id,n.id)||`edge-${r}-${i.id}-${n.id}`,source:i.id,sourcePort:`output`,target:n.id,targetPort:`input`}})}function Zt(e=[],t=[]){let n=e.filter(e=>e.enabled!==!1),r=new Set(n.map(e=>e.id)),i=t.filter(e=>r.has(e.source)&&r.has(e.target)),a=new Map(n.map(e=>[e.id,[]])),o=new Map(n.map(e=>[e.id,[]])),s=new Map(n.map(e=>[e.id,0])),c=Yt(n);for(let e of i)a.get(e.target)?.push(e),o.get(e.source)?.push(e),s.set(e.target,(s.get(e.target)||0)+1);let l=n.filter(e=>s.get(e.id)===0),u=[];for(;l.length;){l.sort((e,t)=>c.get(e.id)-c.get(t.id));let e=l.shift();u.push(e);for(let t of o.get(e.id)||[]){let e=(s.get(t.target)||0)-1;s.set(t.target,e),e===0&&l.push(n.find(e=>e.id===t.target))}}let d=n.filter(e=>(a.get(e.id)||[]).length===0),f=d.find(e=>e.kind===`trigger`)||d[0];return{nodes:n,edges:i,incoming:a,outgoing:o,order:u,roots:d,unconnected:n.filter(e=>e.id!==f?.id&&(a.get(e.id)||[]).length===0),invalidTriggerTargets:n.filter(e=>e.kind===`trigger`&&(a.get(e.id)||[]).length>0),hasCycle:u.length!==n.length}}function Qt(e,t,n,r,i=`output`){return Zt(e,[...t,{id:`__candidate__`,source:n,sourcePort:i,target:r,targetPort:`input`}]).hasCycle}var $t={trigger:`触发器`,prompt:`任务`,skill:`Skill`,file:`文件`,mcp:`MCP`,notification:`通知`,condition:`判断`,parallel:`并行`,approval:`审批`,"media-input":`图片输入`,"media-inpaint":`区域修补`,"media-background":`去背景`,"media-generate":`动作生成`,"media-frames":`拆分帧`,"media-transform":`帧处理`,"media-preview":`动画预览`,"media-export":`图集输出`},en=[{kind:`trigger`,label:`手动触发`,Icon:ce},{kind:`prompt`,label:`运行 Prompt`,Icon:S},{kind:`skill`,label:`调用 Skill`,Icon:C},{kind:`file`,label:`读写文件`,Icon:P},{kind:`mcp`,label:`调用 MCP`,Icon:_e},{kind:`condition`,label:`条件分支`,Icon:te},{kind:`parallel`,label:`并行汇合`,Icon:se},{kind:`approval`,label:`人工审批`,Icon:D},{kind:`notification`,label:`发送通知`,Icon:x},{kind:`media-inpaint`,label:`区域修补`,Icon:I},{kind:`media-input`,label:`图片输入`,Icon:I},{kind:`media-background`,label:`去背景`,Icon:I},{kind:`media-generate`,label:`动作生成`,Icon:I},{kind:`media-frames`,label:`拆分帧`,Icon:I},{kind:`media-transform`,label:`帧处理`,Icon:I},{kind:`media-preview`,label:`动画预览`,Icon:I},{kind:`media-export`,label:`图集输出`,Icon:I}];function tn(e,t){return t(e===`media-inpaint`?`workflows:imageNodes.inpaint`:e===`media-input`?`workflows:imageNodes.input`:e===`media-background`?`workflows:imageNodes.background`:e===`media-generate`?`workflows:imageNodes.generate`:e===`media-frames`?`workflows:imageNodes.frames`:e===`media-transform`?`workflows:imageNodes.transform`:e===`media-preview`?`workflows:imageNodes.preview`:e===`media-export`?`workflows:imageNodes.export`:e===`trigger`?`workflows:workflowsPage.triggerNode`:e===`skill`?`workflows:workflowsPage.skillNode`:e===`file`?`workflows:workflowsPage.fileNode`:e===`mcp`?`workflows:workflowsPage.mcpNode`:e===`notification`?`workflows:workflowsPage.notificationNode`:e===`condition`?`workflows:workflowsPage.conditionNode`:e===`parallel`?`workflows:workflowsPage.parallelNode`:e===`approval`?`workflows:workflowsPage.approvalNode`:`workflows:workflowsPage.task`)}function nn(e,t){return Kt(e)?tn(e,t):t(e===`trigger`?`workflows:workflowsPage.manualTrigger`:e===`skill`?`workflows:workflowsPage.callSkill`:e===`file`?`workflows:workflowsPage.readWriteFiles`:e===`mcp`?`workflows:workflowsPage.callMcp`:e===`condition`?`workflows:workflowsPage.conditionBranch`:e===`parallel`?`workflows:workflowsPage.parallelJoin`:e===`approval`?`workflows:workflowsPage.humanApproval`:e===`notification`?`workflows:workflowsPage.sendNotification`:`workflows:workflowsPage.runPrompt`)}function rn(e,t){return t(e===`sprite`?`workflows:imageNodes.templateName`:e===`pr-fix`?`workflows:workflowsPage.prFix`:e===`research`?`workflows:workflowsPage.research`:e===`report`?`workflows:workflowsPage.dailyWeeklyReport`:e===`asset`?`workflows:workflowsPage.assetGeneration`:e===`release`?`workflows:workflowsPage.releasePreparation`:`workflows:workflowsPage.codeReview`)}function an(e,t){return t(e===`sprite`?`workflows:imageNodes.templateDescription`:e===`pr-fix`?`workflows:workflowsPage.prFixDescription`:e===`research`?`workflows:workflowsPage.researchDescription`:e===`report`?`workflows:workflowsPage.reportDescription`:e===`asset`?`workflows:workflowsPage.assetDescription`:e===`release`?`workflows:workflowsPage.releaseDescription`:`workflows:workflowsPage.codeReviewDescription`)}function Z(e,t,n,r,i,a,o={}){return{id:e,kind:t,label:n,prompt:r,x:i,y:a,model:null,executionMode:`full-access`,retries:0,timeoutMinutes:20,failurePolicy:`stop`,enabled:!0,outputFormat:`text`,skillName:``,requestedToolNames:[],condition:{source:`previous`,operator:`exists`,value:``},approval:{message:``,timeoutMinutes:60},notification:{title:``,content:``},notificationTargets:[],...Kt(t)?{image:Ut()}:{},...o}}function on(e){return Xt(e,()=>crypto.randomUUID())}function sn(e){return[{id:`input-task`,name:`task`,label:e?e(`workflows:inputs.task`):`本次任务`,description:e?e(`workflows:inputs.taskHint`):`描述这次运行需要完成的目标。`,type:`text`,required:!0,defaultValue:``},{id:`input-materials`,name:`materials`,label:e?e(`workflows:inputs.materials`):`参考材料`,description:e?e(`workflows:inputs.materialsHint`):`填写文件路径、链接、代码片段或需要处理的内容。`,type:`text`,required:!1,defaultValue:``},{id:`input-constraints`,name:`constraints`,label:e?e(`workflows:inputs.constraints`):`约束与输出要求`,description:e?e(`workflows:inputs.constraintsHint`):`说明范围、格式、禁止操作及验收条件。`,type:`text`,required:!1,defaultValue:``}]}function cn(e){return`${e}\n\n本次任务:{{inputs.task}}\n参考材料:{{inputs.materials}}\n约束与输出要求:{{inputs.constraints}}\n以本次运行输入限定任务范围,节点只规定处理方法;不要把节点示例或工作流名称当作本次任务。`}var ln=[{id:`code-review`,name:`代码审查`,description:`读取 diff → 运行测试 → 生成 review`,Icon:A,nodes:[Z(`review-trigger`,`trigger`,`手动触发`,``,65,45),Z(`review-diff`,`file`,`读取 diff`,`读取当前工作区的 git diff,识别改动范围与高风险文件。`,235,45),Z(`review-test`,`prompt`,`运行检查`,`运行适合当前项目的测试与 lint,记录失败原因。`,405,45),Z(`review-report`,`prompt`,`生成 review`,`结合 diff 和验证结果,输出按严重度排序的代码审查结论。`,235,180),Z(`review-notify`,`notification`,`发送结果`,``,405,180)]},{id:`pr-fix`,name:`PR 修复`,description:`定位失败 → 修改代码 → 回归测试`,Icon:te,nodes:[Z(`fix-trigger`,`trigger`,`手动触发`,``,65,45),Z(`fix-find`,`prompt`,`定位失败`,`检查项目状态与失败信息,定位最可能的根因。`,235,45),Z(`fix-code`,`prompt`,`修改代码`,`修复已定位的问题,保留用户已有改动,不执行破坏性命令。`,405,45),Z(`fix-test`,`prompt`,`回归测试`,`运行针对性测试和构建,确认修复没有引入回归。`,235,180),Z(`fix-notify`,`notification`,`通知结果`,``,405,180)]},{id:`research`,name:`资料调研`,description:`搜索资料 → 提取引用 → 点亮星忆`,Icon:ge,nodes:[Z(`research-trigger`,`trigger`,`手动输入`,``,65,45),Z(`research-search`,`prompt`,`搜索资料`,`围绕工作流描述中的主题检索项目内资料与可用信息源。`,235,45),Z(`research-summary`,`prompt`,`整理引用`,`整理关键结论、证据、限制和下一步建议。`,405,45),Z(`research-memory`,`prompt`,`保存星忆`,`把适合长期保留的结论写入 Agent 记忆。`,320,180)]},{id:`report`,name:`日报周报`,description:`汇总会话 → 生成摘要 → 渠道通知`,Icon:F,nodes:[Z(`report-trigger`,`trigger`,`手动触发`,``,65,45),Z(`report-collect`,`prompt`,`汇总进展`,`汇总当前项目近期完成事项、风险与待办。`,235,45),Z(`report-write`,`prompt`,`生成报告`,`将汇总内容整理为清晰的日报或周报。`,405,45),Z(`report-notify`,`notification`,`渠道通知`,``,320,180)]},{id:`asset`,name:`资产生成`,description:`生成图片 → 存入资产库 → 通知验收`,Icon:I,nodes:[Z(`asset-trigger`,`trigger`,`手动输入`,``,65,45),Z(`asset-generate`,`prompt`,`生成视觉资产`,`根据工作流描述生成需要的视觉资产,并保存生成文件。`,235,45),Z(`asset-check`,`prompt`,`检查产物`,`检查生成资产是否完整、可访问并符合需求。`,405,45),Z(`asset-notify`,`notification`,`通知验收`,``,320,180)]},{id:`release`,name:`发布准备`,description:`版本检查 → changelog → 创建发布单`,Icon:L,nodes:[Z(`release-trigger`,`trigger`,`手动触发`,``,65,45),Z(`release-check`,`prompt`,`版本检查`,`检查工作区、测试、构建和版本信息是否满足发布要求。`,235,45),Z(`release-log`,`prompt`,`生成 changelog`,`根据近期提交和改动生成 changelog 与发布说明。`,405,45),Z(`release-report`,`prompt`,`发布清单`,`生成最终发布检查清单并标记阻塞项。`,320,180)]}].map(e=>({...e,inputs:sn(),nodes:e.nodes.map(e=>[`prompt`,`file`,`skill`,`mcp`].includes(e.kind)?{...e,prompt:cn(e.prompt)}:e)}));function un(){let e=[Z(`sprite-trigger`,`trigger`,`手动触发`,``,0,180),Z(`sprite-source`,`media-input`,`参考图片`,``,180,180)],t=[{id:`sprite-input`,source:`sprite-trigger`,target:`sprite-source`,sourcePort:`output`,targetPort:`input`}];return[{id:`idle`,label:`待机呼吸`,prompt:`Subtle breathing idle cycle. Preserve the reference style; the feet stay planted.`},{id:`walk`,label:`走路`,prompt:`Walking cycle: alternating foot contact, passing pose and opposite contact. Keep the character in place.`},{id:`run`,label:`跑步`,prompt:`Running cycle: contact, compression, passing and flight. Preserve proportions and keep the character in place.`},{id:`attack`,label:`攻击`,prompt:`Attack sequence: anticipation, wind-up, strike and recovery. Use only the equipment visible in the reference.`}].forEach((n,r)=>{let i=r*140,a=[Z(`${n.id}-generate`,`media-generate`,n.label,`${n.prompt}\n{{inputs.task}}`,380,i,{image:Ut({action:n.id,frameCount:4,directions:[...Vt]})}),Z(`${n.id}-background`,`media-background`,`色键去背景`,``,560,i),Z(`${n.id}-frames`,`media-frames`,`拆分连续帧`,``,740,i),Z(`${n.id}-align`,`media-transform`,`裁边与脚底对齐`,``,920,i)];e.push(...a);let o=[`sprite-source`,...a.map(e=>e.id),`sprite-preview`];for(let e=1;e<o.length;e++)t.push({id:`${n.id}-edge-${e}`,source:o[e-1],target:o[e],sourcePort:`output`,targetPort:`input`})}),e.push(Z(`sprite-preview`,`media-preview`,`动画预览`,``,1100,180),Z(`sprite-export`,`media-export`,`输出精灵图集`,``,1280,180)),t.push({id:`sprite-output`,source:`sprite-preview`,target:`sprite-export`,sourcePort:`output`,targetPort:`input`}),{id:`sprite`,name:`游戏精灵图生成`,description:`参考图 → 分方向动作 → 去背景 → 拆帧对齐 → 动画预览 → 图集`,Icon:I,nodes:e,edges:t,inputs:[{id:`sprite-reference`,name:`reference`,type:`image`,required:!0,label:`角色参考图`,description:`上传图片并保留原图风格。`,defaultValue:null},{id:`sprite-task`,name:`task`,type:`text`,required:!1,label:`角色与动作要求`,description:`本次运行的角色特征、动作及其他要求。`,defaultValue:``}]}}var dn=un(),fn=[...ln,dn];function pn(e){return fn.find(t=>t.id===e)}function mn(e){return e.nodes.reduce((e,t)=>e+(t.enabled&&t.kind===`media-generate`?Ut(t.image).directions.length:0),0)}function hn(e=``,t){let n=[Z(crypto.randomUUID(),`trigger`,`手动触发`,``,65,45),Z(crypto.randomUUID(),`prompt`,`运行 Prompt`,cn(`按本次输入完成任务,结合材料执行所需步骤,验证产物并报告结果。`),235,45)];return{id:``,name:`未命名工作流`,description:``,status:`draft`,revision:1,cwd:e,model:null,inputs:sn(t),tags:[],visibility:`private`,notifications:[],nodes:n,edges:on(n)}}function gn(e,t){if(e.kind===`media-generate`){if(e.image?.action===`idle`)return t(`workflows:imageNodes.idle`);if(e.image?.action===`walk`)return t(`workflows:imageNodes.walk`);if(e.image?.action===`run`)return t(`workflows:imageNodes.run`);if(e.image?.action===`attack`)return t(`workflows:imageNodes.attack`)}return nn(e.kind,t)}function _n(e,t=``,n){let r=e.nodes.map(t=>({...structuredClone(t),...e.id===`sprite`&&n?{label:gn(t,n)}:{},id:crypto.randomUUID()})),i=fn.includes(e)?sn(n):[],a=new Map(e.nodes.map((e,t)=>[e.id,r[t].id]));return{...hn(t,n),name:n&&fn.includes(e)?rn(e.id,n):e.name,description:n&&fn.includes(e)?an(e.id,n):e.description,inputs:e.inputs.map(t=>{let r=i.find(e=>e.name===t.name);return{...structuredClone(t),...r?{label:r.label,description:r.description}:{},...e.id===`sprite`&&t.name===`reference`&&n?{label:n(`workflows:imageNodes.reference`),description:n(`workflows:imageNodes.referenceHint`)}:{},id:crypto.randomUUID()}}),nodes:r,edges:e.edges?e.edges.map(e=>({...e,id:crypto.randomUUID(),source:a.get(e.source)??``,target:a.get(e.target)??``})):on(r)}}var vn=new Map(en.map(({kind:e,Icon:t})=>[e,t])),yn=`flow-port size-2.5! rounded-full! border-[1.5px]! border-control! bg-panel! cursor-crosshair after:absolute after:-inset-2 hover:border-focus!`;function bn({status:e}){return e===`running`?(0,X.jsx)(Re,{className:`ml-auto size-3.5`}):e===`completed`?(0,X.jsx)(w,{className:`ml-auto size-3.5 text-success`,strokeWidth:2.25}):e===`failed`?(0,X.jsx)(Ce,{className:`ml-auto size-3.5 text-danger`,strokeWidth:2.25}):e===`waiting_approval`?(0,X.jsx)(jt,{className:`ml-auto size-3.5 text-warning-strong`}):null}function xn({data:e,selected:t}){let n=vn.get(e.kind);return(0,X.jsxs)(`div`,{className:B(`flow-node relative flex w-36 min-h-14 cursor-grab flex-col justify-center gap-0.5 rounded-md border border-stroke bg-panel px-3 py-2 text-left transition-[border-color,box-shadow] duration-(--d-fast) ease-precise [:focus-visible>&]:outline-2 [:focus-visible>&]:outline-offset-2 [:focus-visible>&]:outline-focus`,`type-${e.kind}`,t&&`active border-stroke-strong bg-key shadow-key`,e.status===`running`&&`border-star-border`),children:[t&&(0,X.jsx)(`i`,{"aria-hidden":`true`,className:`absolute inset-y-2 -left-px w-[3px] rounded-r-[3px] bg-star`}),e.kind!==`trigger`&&(0,X.jsx)(St,{id:`input`,className:`${yn} input`,type:`target`,position:xt.Left,title:e.inputLabel,"aria-label":e.inputLabel}),e.kind===`condition`?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(St,{id:`true`,className:`${yn} output condition-true`,type:`source`,position:xt.Right,title:`true`,"aria-label":`true`}),(0,X.jsx)(St,{id:`false`,className:`${yn} output condition-false`,type:`source`,position:xt.Bottom,title:`false`,"aria-label":`false`})]}):(0,X.jsx)(St,{id:`output`,className:`${yn} output`,type:`source`,position:xt.Right,title:e.outputLabel,"aria-label":e.outputLabel}),(0,X.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1.5 text-xs text-content-muted`,children:[n&&(0,X.jsx)(n,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),(0,X.jsx)(`span`,{className:`truncate`,children:e.typeLabel}),(0,X.jsx)(bn,{status:e.status})]}),(0,X.jsx)(`strong`,{className:`truncate text-sm font-medium text-content`,title:e.label,children:e.label})]})}var Sn={workflow:xn};function Cn(e){return typeof e==`string`&&Jt.includes(e)}function wn(e){return e.data.status===`running`?`var(--star)`:`var(--stroke-strong)`}function Tn({nodes:e,edges:t,selectedNodeId:n,selectedEdgeId:r,nodeStatus:i,hint:a,inputLabel:o,outputLabel:s,nodeTypeLabel:c,onAddNode:l,onConnect:u,onMoveNode:d,onSelectNode:f,onSelectEdge:p,onClearSelection:m,onDeleteNodes:h,onDeleteEdges:g}){let{screenToFlowPosition:_}=Ct(),v=(0,G.useMemo)(()=>e.map(e=>({id:e.id,type:`workflow`,position:{x:e.x,y:e.y},selected:e.id===n,data:{kind:e.kind,label:e.label,typeLabel:c(e.kind),inputLabel:o,outputLabel:s,status:i?.get(e.id)}})),[o,i,c,e,s,n]),y=(0,G.useRef)(new Set),b=(0,G.useRef)(new Map),x=(0,G.useRef)(null),[S,C,w]=yt(v);(0,G.useEffect)(()=>{C(e=>{let t=new Map(e.map(e=>[e.id,e])),n=e.length!==v.length,r=v.map(e=>{let r=t.get(e.id);if(!r)return n=!0,e;let i=y.current.has(e.id)?r.position:e.position,a=r.data.kind===e.data.kind&&r.data.label===e.data.label&&r.data.typeLabel===e.data.typeLabel&&r.data.inputLabel===e.data.inputLabel&&r.data.outputLabel===e.data.outputLabel&&r.data.status===e.data.status;return i.x===r.position.x&&i.y===r.position.y&&r.selected===e.selected&&a?r:(n=!0,{...r,position:i,selected:e.selected,data:e.data})});return n?r:e})},[v,C]);let T=(0,G.useCallback)(()=>{x.current=null,b.current.forEach((e,t)=>d(t,e)),b.current.clear()},[d]),E=(0,G.useCallback)((e,t)=>{b.current.set(e,t),x.current??=requestAnimationFrame(T)},[T]);(0,G.useEffect)(()=>()=>{x.current!==null&&cancelAnimationFrame(x.current)},[]);let ee=(0,G.useMemo)(()=>t.map(e=>({id:e.id,source:e.source,sourceHandle:e.sourcePort,target:e.target,targetHandle:e.targetPort,selected:e.id===r,markerEnd:{type:bt.ArrowClosed,width:14,height:14,color:`var(--canvas-edge)`}})),[t,r]),D=(0,G.useCallback)(e=>{!e.source||!e.target||u(e.source,e.target,e.sourceHandle||`output`)},[u]),O=(0,G.useCallback)(e=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`},[]),k=(0,G.useCallback)(e=>{e.preventDefault();let t={};try{t=JSON.parse(e.dataTransfer.getData(`text/plain`)||`{}`)}catch{return}if(!Cn(t.kind))return;let n=_({x:e.clientX,y:e.clientY});l(t.kind,typeof t.label==`string`?t.label:c(t.kind),n)},[c,l,_]);return(0,X.jsxs)(`div`,{className:`workflow-react-flow absolute inset-0`,children:[(0,X.jsxs)(Dt,{nodes:S,edges:ee,nodeTypes:Sn,onNodesChange:w,connectionMode:kt.Strict,deleteKeyCode:[`Backspace`,`Delete`],fitView:!0,fitViewOptions:{padding:.18,minZoom:.6,maxZoom:1,nodes:S.length>8?S.slice(0,3).map(({id:e})=>({id:e})):void 0},minZoom:.15,maxZoom:1.8,snapToGrid:!0,snapGrid:[20,20],panOnDrag:!0,zoomOnDoubleClick:!1,onConnect:D,onNodeClick:(e,t)=>f(t.id),onEdgeClick:(e,t)=>p(t.id),onPaneClick:m,onNodeDragStart:(e,t)=>y.current.add(t.id),onNodeDrag:(e,t)=>E(t.id,t.position),onNodeDragStop:(e,t)=>{y.current.delete(t.id),b.current.delete(t.id),d(t.id,t.position)},onNodesDelete:e=>h(e.map(e=>e.id)),onEdgesDelete:e=>g(e.map(e=>e.id)),onDragOver:O,onDrop:k,children:[(0,X.jsx)(Ot,{variant:wt.Dots,gap:20,size:1,color:`var(--canvas-grid)`}),(0,X.jsx)(vt,{className:`workflow-react-flow-minimap m-3! h-24! w-36! overflow-hidden rounded-md border border-stroke [&_svg]:h-full [&_svg]:w-full @max-[640px]/workflow:hidden`,nodeColor:wn,nodeBorderRadius:4,pannable:!0,zoomable:!0}),(0,X.jsx)(qt,{position:`top-left`,showInteractive:!1,className:`border-stroke bg-panel p-0.5 [&>button]:size-7! [&>button]:rounded-sm! [&>button]:hover:bg-surface-hover! max-[650px]:[&>button]:size-11! pointer-coarse:[&>button]:size-11!`})]}),(0,X.jsx)(`div`,{className:`pointer-events-none absolute bottom-3 left-3 z-[5] hidden max-w-[calc(100%-180px)] text-xs text-content-muted @min-[640px]/workflow:block`,children:a})]})}function En(e){return(0,X.jsx)(Tt,{children:(0,X.jsx)(Tn,{...e})})}function Dn({nodeCount:e,t,onAddNode:n}){let[r,i]=(0,G.useState)(!1),[a,o]=(0,G.useState)(``),s=[{label:t(`workflows:editor.flowNodes`),match:e=>[`trigger`,`condition`,`parallel`,`approval`].includes(e)},{label:t(`workflows:editor.agentNodes`),match:e=>[`prompt`,`skill`,`file`,`mcp`,`notification`].includes(e)},{label:t(`workflows:editor.imageNodes`),match:Kt}],c=en.filter(({kind:e})=>nn(e,t).toLocaleLowerCase().includes(a.trim().toLocaleLowerCase()));return(0,X.jsxs)(Me,{open:r,onOpenChange:i,children:[(0,X.jsx)(Ae,{asChild:!0,children:(0,X.jsxs)(V,{variant:`outline`,size:`sm`,title:t(`workflows:editor.addNode`),children:[(0,X.jsx)(pe,{}),(0,X.jsx)(`span`,{className:`max-[650px]:sr-only @max-[760px]/workflow-header:sr-only`,children:t(`workflows:editor.addNode`)})]})}),(0,X.jsxs)(je,{align:`end`,className:`w-72 max-w-[calc(100vw-2rem)] p-1.5`,"aria-label":t(`workflows:workflowsPage.nodeLibrary`),children:[(0,X.jsxs)(`div`,{className:`relative`,children:[(0,X.jsx)(ge,{className:`pointer-events-none absolute top-2.5 left-2.5 size-4 text-content-muted`}),(0,X.jsx)(H,{value:a,onChange:e=>o(e.target.value),className:`pl-8`,placeholder:t(`workflows:editor.searchNodes`),"aria-label":t(`workflows:editor.searchNodes`)})]}),(0,X.jsxs)(`div`,{className:`node-library max-h-[min(420px,60vh)] overflow-y-auto overscroll-contain supports-[height:100dvh]:max-h-[min(420px,60dvh)]`,children:[s.map(r=>{let a=c.filter(({kind:e})=>r.match(e));return a.length===0?null:(0,X.jsxs)(`section`,{className:`py-1`,children:[(0,X.jsx)(`h3`,{className:`px-2 py-1.5 text-xs font-medium text-content-muted`,children:r.label}),a.map(({kind:r,Icon:a})=>(0,X.jsxs)(`button`,{type:`button`,draggable:!0,className:`flex min-h-[30px] w-full cursor-grab items-center gap-2 rounded-sm px-2 text-left text-sm text-content transition-colors duration-(--d-fast) hover:bg-surface-hover focus-visible:-outline-offset-2 max-[650px]:min-h-11 pointer-coarse:min-h-11`,onClick:()=>{n(r,nn(r,t),{x:160+e%4*180,y:100+Math.floor(e/4)*100}),i(!1)},onDragStart:e=>e.dataTransfer.setData(`text/plain`,JSON.stringify({kind:r,label:nn(r,t)})),onDragEnd:()=>i(!1),children:[(0,X.jsx)(a,{className:`size-4 shrink-0 text-content-muted`}),(0,X.jsx)(`span`,{className:`flex-1`,children:nn(r,t)}),(0,X.jsx)(ne,{className:`size-3.5 text-content-faint`,"aria-hidden":`true`})]},r))]},r.label)}),c.length===0&&(0,X.jsx)(`p`,{className:`p-3 text-xs text-content-muted`,children:t(`workflows:editor.noMatchingNodes`)})]})]})]})}function On({draft:e,selectedNodeId:t,selectedEdgeId:n,nodeStatus:r,t:i,onAddNode:a,onConnect:o,onMoveNode:s,onSelectNode:c,onSelectEdge:l,onClearSelection:u,onDeleteNodes:d,onDeleteEdges:f}){return(0,X.jsx)(`section`,{className:`builder-canvas relative h-full min-h-0 min-w-0 overflow-hidden bg-panel`,"aria-label":i(`workflows:editor.canvas`),children:(0,X.jsx)(En,{nodes:e.nodes,edges:e.edges,selectedNodeId:t,selectedEdgeId:n,nodeStatus:r,hint:i(`workflows:workflowsPage.dragFromANodeOutputToTheTargetInputToConnectThem`),inputLabel:i(`workflows:workflowsPage.inputPort`),outputLabel:i(`workflows:workflowsPage.outputPort`),nodeTypeLabel:e=>tn(e,i),onAddNode:a,onConnect:o,onMoveNode:s,onSelectNode:c,onSelectEdge:l,onClearSelection:u,onDeleteNodes:d,onDeleteEdges:f})})}function kn(e){if(e.size>134217728)throw new g(`Workflow package exceeds 128 MiB`,{kind:`protocol`,data:{code:`workflow_bundle_too_large`}})}function An(e){return e instanceof g&&e.data?.code===`workflow_bundle_too_large`}function jn(e,t){return p(`/api/workflows/${encodeURIComponent(e)}/bundle`,{signal:t,timeout:12e4})}async function Mn(e,t){return kn(e),f(`/api/workflows/import-bundle`,{method:`POST`,data:e,signal:t,timeout:12e4,parse:e=>{if(!e||typeof e!=`object`||!(`workflow`in e))throw m();let t=e.workflow;if(!t||typeof t!=`object`||!(`id`in t)||typeof t.id!=`string`)throw m()}})}var Nn={workflows:[],runs:[],limits:{maxConcurrent:4,running:0},notificationTargets:{browser:{enabled:!1},feishu:{enabled:!1},weixin:{enabled:!1},qq:{enabled:!1},telegram:{enabled:!1}},models:[],skills:[],cwd:``};function Q(e){let t=e instanceof g?e.data?.code:typeof e==`string`?e:e&&typeof e==`object`&&`code`in e?e.code:``;return t===`workflow_image_source_stale`?c(`workflows:imageNodes.sourceStale`):t===`workflow_image_source_required`?c(`workflows:imageNodes.sourceRequired`):t===`workflow_image_engine_missing`?c(`workflows:imageNodes.engineMissing`):t===`workflow_image_generation_failed`?c(`workflows:imageNodes.generationFailed`):t===`workflow_image_too_large`?c(`workflows:imageNodes.tooLarge`):t===`workflow_image_timeout`?c(`workflows:imageNodes.timeout`):typeof t==`string`&&t.startsWith(`workflow_image_`)?c(`workflows:imageNodes.invalidOutput`):e instanceof Error?e.message:String(e)}function Pn({notify:e,requestConfirm:t,query:n}){let{t:r}=l(),[i,a]=(0,G.useState)(Nn),[o,s]=(0,G.useState)(`all`),[c,u]=(0,G.useState)(!0),[d,f]=(0,G.useState)(!1),[p,m]=(0,G.useState)(``),[g,_]=(0,G.useState)(``),v=(0,G.useRef)(null);(0,G.useEffect)(()=>()=>v.current?.abort(),[]);let y=(0,G.useCallback)(async()=>{try{a(await h(`/api/workflows`)),f(!0),_(``)}catch(e){_(Q(e))}finally{u(!1)}},[]);(0,G.useEffect)(()=>{y()},[y]),(0,G.useEffect)(()=>{let e=window.setInterval(()=>{y()},i.limits.running?1500:8e3);return()=>window.clearInterval(e)},[i.limits.running,y]);let b=(0,G.useCallback)(e=>i.runs.filter(t=>t.workflowId===e).sort((e,t)=>Date.parse(t.startedAt)-Date.parse(e.startedAt))[0],[i.runs]),x=(0,G.useMemo)(()=>i.workflows.filter(e=>{let t=b(e.id);return`${e.name} ${e.description}`.toLowerCase().includes(n.toLowerCase())?o===`running`?t?.status===`running`:o===`failed`?t?.status===`failed`:o===`draft`?e.status===`draft`:o!==`presets`:!1}),[i.workflows,o,b,n]),S=(0,G.useCallback)(async(t,n={})=>{m(t.id),_(``);try{return await h(`/api/workflows/${encodeURIComponent(t.id)}/run`,{method:`POST`,body:JSON.stringify({inputs:n})}),await y(),e(r(`workflows:workflowsPage.workflowStarted`)),!0}catch(t){let n=Q(t);return _(n),e(n,`error`),!1}finally{m(``)}},[y,e,r]),C=(0,G.useCallback)(async t=>{m(t.id),_(``);try{await h(`/api/workflow-runs/${encodeURIComponent(t.id)}/stop`,{method:`POST`,body:`{}`}),await y(),e(r(`workflows:workflowsPage.stoppingWorkflow`),`info`)}catch(t){let n=Q(t);_(n),e(n,`error`)}finally{m(``)}},[y,e,r]),w=(0,G.useCallback)(async t=>{m(t.id);try{await h(`/api/workflow-runs/${encodeURIComponent(t.id)}/retry`,{method:`POST`,body:`{}`}),await y(),e(r(`workflows:workflowsPage.workflowStarted`))}catch(t){let n=Q(t);_(n),e(n,`error`)}finally{m(``)}},[y,e,r]),T=(0,G.useCallback)(async(t,n,r)=>{m(n);try{await h(`/api/workflow-runs/${encodeURIComponent(t.id)}/approvals/${encodeURIComponent(n)}`,{method:`POST`,body:JSON.stringify({approved:r})}),await y()}catch(t){let n=Q(t);_(n),e(n,`error`)}finally{m(``)}},[y,e]),E=(0,G.useCallback)(async t=>{m(t.id);try{await h(`/api/workflows/${encodeURIComponent(t.id)}/duplicate`,{method:`POST`,body:`{}`}),await y(),e(r(`workflows:workflowsPage.workflowDuplicated`))}catch(t){let n=Q(t);_(n),e(n,`error`)}finally{m(``)}},[y,e,r]),ee=(0,G.useCallback)(async t=>{if(v.current)return;let n=new AbortController;v.current=n,m(t.id);try{let e=await jn(t.id,n.signal);if(n.signal.aborted)return;let r=URL.createObjectURL(e),i=document.createElement(`a`);i.href=r,i.download=`${t.name.replace(/[\\/:*?"<>|]/g,`-`)}.pisper-workflow.zip`,i.click(),window.setTimeout(()=>URL.revokeObjectURL(r),1e3)}catch{n.signal.aborted||e(r(`workflows:workflowsPage.packageFailed`),`error`)}finally{v.current=null,n.signal.aborted||m(``)}},[e,r]),D=(0,G.useCallback)(async t=>{if(v.current)return;let n=new AbortController;v.current=n,m(`import`);try{if(await Mn(t,n.signal),n.signal.aborted||(await y(),n.signal.aborted))return;e(r(`workflows:workflowsPage.workflowImported`))}catch(t){if(n.signal.aborted)return;let i=An(t)?r(`workflows:workflowsPage.packageTooLarge`):r(`workflows:workflowsPage.packageFailed`);_(i),e(i,`error`)}finally{v.current=null,n.signal.aborted||m(``)}},[y,e,r]),O=(0,G.useCallback)(async n=>{if(await t?.({title:r(`workflows:workflowsPage.deleteWorkflow`),message:r(`workflows:workflowsPage.deleteWorkflowNameAndItsRunHistory`,{name:n.name}),confirmLabel:r(`workflows:workflowsPage.delete`),tone:`danger`})){m(n.id);try{await h(`/api/workflows/${encodeURIComponent(n.id)}`,{method:`DELETE`}),await y(),e(r(`workflows:workflowsPage.workflowDeleted`))}catch(t){let n=Q(t);_(n),e(n,`error`)}finally{m(``)}}},[y,e,t,r]);return{data:i,filter:o,setFilter:s,loading:c,loaded:d,reload:(0,G.useCallback)(async()=>{u(!0),await y()},[y]),busyId:p,error:g,visibleWorkflows:x,latestRun:b,runWorkflow:S,stopRun:C,retryRun:w,resolveApproval:T,duplicateWorkflow:E,exportWorkflow:ee,importWorkflow:D,removeWorkflow:O}}function Fn(e){return e===`running`?`run`:e===`waiting_approval`?`attention`:e===`completed`?`done`:e===`failed`||e===`interrupted`?`failed`:e===`cancelled`?`stopped`:null}function In({status:e,className:t}){let n=Fn(e);return(0,X.jsx)(`span`,{"aria-hidden":`true`,className:B(`grid size-[18px] flex-none place-items-center rounded-xs`,!n&&`bg-surface-muted`,t),children:n&&(0,X.jsx)(Ke,{status:n,className:`size-3.5`})})}function Ln(e){return e===`running`?`bg-st-run`:e===`waiting_approval`?`bg-st-attn-fill`:e===`completed`?`bg-content-muted`:e===`failed`||e===`interrupted`?`bg-content-secondary`:`bg-stroke-strong`}function Rn({nodes:e,className:t}){return e.length?(0,X.jsx)(`span`,{"aria-hidden":`true`,className:B(`flex h-1 min-w-0 gap-0.5`,t),children:e.map(e=>(0,X.jsx)(`i`,{className:`h-full w-[18px] min-w-0.5 shrink rounded-full ${Ln(e.status)}`},e.id))}):null}function zn({status:e,label:t}){let n=Fn(e);return(0,X.jsxs)(`span`,{"data-run-status":e,className:B(`inline-flex min-w-0 items-center gap-1 whitespace-nowrap`,e===`waiting_approval`?`font-medium text-st-attn`:`text-content-secondary`),children:[n&&(0,X.jsx)(Ke,{status:n,className:`size-3.5`}),(0,X.jsx)(`span`,{className:`min-w-0 truncate`,children:t})]})}function Bn(e){let t=Math.max(0,Math.round((Number(e)||0)/1e3));return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`}function Vn(e,t){return t(e===`running`?`workflows:workflowsPage.running`:e===`waiting_approval`?`workflows:workflowsPage.waitingApproval`:e===`completed`?`workflows:workflowsPage.completed`:e===`failed`?`workflows:workflowsPage.failed`:e===`cancelled`?`workflows:workflowsPage.stopped`:e===`interrupted`?`workflows:workflowsPage.interrupted`:`workflows:workflowsPage.draft`)}var Hn=[`running`,`waiting_approval`];function Un({value:e,onChange:t,t:n}){let r=`min-w-14 flex-none px-3 max-[650px]:flex-1`;return(0,X.jsx)(Le,{value:e,onValueChange:e=>t(e),className:`max-[650px]:w-full`,children:(0,X.jsxs)(Ie,{className:`max-w-full justify-start overflow-x-auto overflow-y-hidden [scrollbar-width:none] max-[650px]:min-h-11 max-[650px]:w-full pointer-coarse:min-h-11 [&::-webkit-scrollbar]:hidden`,children:[(0,X.jsx)(Fe,{className:r,value:`workflows`,children:n(`workflows:workflowsPage.workflows`)}),(0,X.jsx)(Fe,{className:r,value:`runs`,children:n(`workflows:workflowsPage.runHistory`)}),(0,X.jsx)(Fe,{className:r,value:`templates`,children:n(`workflows:workflowsPage.templates`)})]})})}function Wn({workflows:e,runs:t,busyId:n,query:r,language:i,t:a,onRun:o,onEdit:s,onDuplicate:c,onExport:l,onDelete:u}){let d=e=>t.filter(t=>t.workflowId===e).sort((e,t)=>Date.parse(t.startedAt)-Date.parse(e.startedAt))[0],f=e.filter(e=>e.status===`published`).length;return(0,X.jsx)(ct,{title:a(`workflows:workflowsPage.workflows`),count:e.length,meta:e.length?a(`workflows:workflowsPage.publishedCount`,{count:f}):void 0,children:e.length?(0,X.jsx)(st,{children:e.map(e=>{let t=d(e.id),r=Hn.includes(t?.status||``),f=r||n===e.id;return(0,X.jsx)(ot,{"data-workflow-id":e.id,icon:(0,X.jsx)(Se,{}),name:e.name,nameMeta:`v${e.revision}`,description:e.description||(0,X.jsx)(`span`,{className:`font-mono`,children:e.cwd}),meta:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{children:e.status===`published`?a(`workflows:workflowsPage.published`):a(`workflows:workflowsPage.draft`)}),(0,X.jsx)(`span`,{"aria-hidden":`true`,children:`·`}),(0,X.jsx)(`span`,{className:`truncate`,children:e.visibility===`shared`?a(`workflows:workflowsPage.shared`):a(`workflows:workflowsPage.private`)})]}),status:t?(0,X.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[(0,X.jsx)(zn,{status:t.status,label:Vn(t.status,a)}),(0,X.jsx)(`span`,{className:`whitespace-nowrap`,children:Ge(t.startedAt,i)})]}):a(`workflows:workflowsPage.neverRun`),onOpen:()=>s(e.id),openLabel:`${a(`workflows:workflowsPage.edit`)}: ${e.name}`,actions:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(V,{size:`icon-sm`,variant:`outline`,disabled:f,title:a(`workflows:workflowsPage.run`),"aria-label":`${a(`workflows:workflowsPage.run`)}: ${e.name}`,className:`max-[650px]:size-11 pointer-coarse:size-11`,onClick:()=>o(e),children:n===e.id?(0,X.jsx)(me,{className:`animate-spin`}):(0,X.jsx)(fe,{})}),(0,X.jsxs)(ke,{children:[(0,X.jsx)(De,{asChild:!0,children:(0,X.jsx)(V,{size:`icon-sm`,variant:`ghost`,className:`text-content-muted max-[650px]:size-11 pointer-coarse:size-11`,"aria-label":a(`workflows:workflowsPage.moreActionsFor`,{name:e.name}),children:(0,X.jsx)(N,{})})}),(0,X.jsxs)(Oe,{align:`end`,className:`min-w-44`,children:[(0,X.jsxs)(Ee,{className:`pointer-coarse:min-h-11 max-[650px]:min-h-11`,onSelect:()=>c(e),children:[(0,X.jsx)(j,{}),a(`workflows:workflowsPage.duplicateWorkflow`)]}),(0,X.jsxs)(Ee,{className:`pointer-coarse:min-h-11 max-[650px]:min-h-11`,onSelect:()=>l(e),children:[(0,X.jsx)(M,{}),a(`workflows:workflowsPage.export`)]}),(0,X.jsx)(Te,{}),(0,X.jsxs)(Ee,{className:`pointer-coarse:min-h-11 max-[650px]:min-h-11`,variant:`destructive`,disabled:r,onSelect:()=>u(e),children:[(0,X.jsx)(be,{}),a(`workflows:workflowsPage.delete`)]})]})]})]})},e.id)})}):(0,X.jsx)(nt,{title:a(r?`workflows:workflowsPage.noMatchingWorkflows`:`workflows:workflowsPage.noWorkflowsYet`),description:r?void 0:a(`workflows:workflowsPage.emptyHint`)})})}function Gn({runs:e,busyId:t,language:n,t:r,onStop:i,onRetry:a,onApproval:o}){let s=[...e].sort((e,t)=>Date.parse(t.startedAt)-Date.parse(e.startedAt)),[c,l]=(0,G.useState)(s[0]?.id||``),u=s.filter(e=>e.status===`waiting_approval`).length;return(0,X.jsx)(ct,{title:r(`workflows:workflowsPage.runHistory`),count:s.length,meta:u?(0,X.jsx)(`span`,{className:`font-medium text-st-attn`,children:r(`workflows:workflowsPage.waitingApprovalCount`,{count:u})}):void 0,children:s.length?(0,X.jsx)(st,{children:s.map(e=>{let s=c===e.id,u=Math.round((Number(e.completedNodes)||0)/Math.max(1,Number(e.totalNodes)||1)*100),d=e.workflowName||e.workflowId;return(0,X.jsx)(ot,{"data-workflow-run":e.id,icon:(0,X.jsx)(In,{status:e.status,className:`bg-transparent`}),name:d,nameMeta:`v${e.workflowRevision||1}`,description:(0,X.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[(0,X.jsx)(zn,{status:e.status,label:Vn(e.status,r)}),(0,X.jsx)(`span`,{className:`truncate tabular-nums`,children:Ge(e.startedAt,n)})]}),status:(0,X.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[(0,X.jsx)(`span`,{className:`flex w-24 min-w-0 items-center max-[650px]:hidden`,children:e.nodes?.length?(0,X.jsx)(Rn,{nodes:e.nodes,className:`flex-1`}):(0,X.jsx)(Ne,{value:e.status===`completed`?100:u,className:`h-1 flex-1`})}),(0,X.jsxs)(`span`,{className:`font-mono`,children:[Number(e.completedNodes)||0,`/`,Number(e.totalNodes)||0]}),(0,X.jsx)(`span`,{className:`font-mono`,children:Bn(e.durationMs)})]}),expanded:s,onExpandedChange:t=>l(t?e.id:``),toggleLabel:r(`workflows:workflowsPage.toggleRunDetails`,{name:d}),detail:(0,X.jsxs)(`div`,{className:`workflow-run-detail flex flex-col gap-2.5`,children:[(e.summary||e.error)&&(0,X.jsxs)(`p`,{className:`workflow-run-result flex items-start gap-1.5 text-xs leading-relaxed whitespace-pre-wrap text-content-secondary`,children:[e.error&&(0,X.jsx)(Ke,{status:`failed`,className:`mt-px size-3.5 text-content`}),e.error?Q(e.error):e.summary]}),!!e.nodes?.length&&(0,X.jsx)(`ul`,{className:`divide-y divide-stroke-soft overflow-hidden rounded-[var(--r-md)] border border-stroke`,children:(e.nodes||[]).map(n=>(0,X.jsxs)(`li`,{className:`workflow-run-node grid min-h-[34px] grid-cols-[18px_minmax(0,1fr)_auto] items-center gap-2.5 px-3 py-1.5 max-[650px]:min-h-11 max-[650px]:grid-cols-[18px_minmax(0,1fr)] ${n.status}`,children:[(0,X.jsx)(In,{status:n.status}),(0,X.jsxs)(`span`,{className:`flex min-w-0 flex-col gap-0.5`,children:[(0,X.jsxs)(`span`,{className:`flex min-w-0 items-baseline gap-2`,children:[(0,X.jsx)(`strong`,{className:`truncate text-sm font-medium text-content`,children:n.label}),(0,X.jsx)(`small`,{className:`shrink-0 text-xs text-content-muted tabular-nums`,children:r(`workflows:workflowsPage.countAttempts`,{count:n.attempts||0})})]}),(n.error||n.summary)&&(0,X.jsx)(`p`,{className:`text-xs leading-relaxed whitespace-pre-wrap text-content-muted`,children:n.error?Q(n.error):n.summary})]}),n.status===`waiting_approval`?(0,X.jsxs)(`div`,{className:`workflow-approval-actions flex gap-1.5 max-[650px]:col-span-2 max-[650px]:justify-end`,children:[(0,X.jsxs)(V,{size:`xs`,variant:`outline`,className:`max-[650px]:h-11`,disabled:t===n.id,onClick:()=>o(e,n.id,!1),children:[(0,X.jsx)(O,{"data-icon":`inline-start`}),r(`workflows:workflowsPage.reject`)]}),(0,X.jsxs)(V,{size:`xs`,className:`max-[650px]:h-11`,disabled:t===n.id,onClick:()=>o(e,n.id,!0),children:[(0,X.jsx)(w,{"data-icon":`inline-start`}),r(`workflows:workflowsPage.approve`)]})]}):(0,X.jsx)(`span`,{className:`font-mono text-xs text-content-muted tabular-nums max-[650px]:hidden`,children:n.status===`running`?`…`:Bn(n.durationMs)})]},n.id))}),(0,X.jsx)(`div`,{className:`workflow-run-detail-actions flex gap-1.5 empty:hidden max-[650px]:[&>button]:h-11`,children:Hn.includes(e.status)?(0,X.jsxs)(V,{size:`sm`,variant:`outline`,onClick:()=>i(e),children:[(0,X.jsx)(ye,{"data-icon":`inline-start`}),r(`workflows:workflowsPage.stop`)]}):[`failed`,`cancelled`,`interrupted`].includes(e.status)?(0,X.jsxs)(V,{size:`sm`,variant:`outline`,onClick:()=>a(e),children:[(0,X.jsx)(me,{"data-icon":`inline-start`}),r(`workflows:workflowsPage.retryRun`)]}):null})]})},e.id)})}):(0,X.jsx)(nt,{title:r(`workflows:workflowsPage.noRunHistory`)})})}function Kn({query:e,t,onOpenTemplate:n}){let r=e.trim().toLocaleLowerCase(),i=ln.filter(e=>`${rn(e.id,t)} ${an(e.id,t)}`.toLocaleLowerCase().includes(r));return(0,X.jsx)(ct,{title:t(`workflows:workflowsPage.templates`),count:i.length,description:t(`workflows:workflowsPage.templatesHint`),children:i.length?(0,X.jsx)(st,{className:`workflow-template-gallery`,children:i.map(e=>{let r=e.Icon,i=rn(e.id,t);return(0,X.jsx)(ot,{"data-workflow-template":e.id,icon:(0,X.jsx)(r,{}),name:i,description:an(e.id,t),onOpen:()=>n(e.id),openLabel:t(`workflows:workflowsPage.useTemplate`,{name:i})},e.id)})}):(0,X.jsx)(nt,{title:t(`workflows:workflowsPage.noMatchingTemplates`)})})}function qn({data:e,t}){let n=e.runs.filter(e=>e.status===`failed`).length,r=e.runs.filter(e=>e.status===`waiting_approval`).length,i=e.runs.filter(e=>e.status===`completed`),a=i.length?i.reduce((e,t)=>e+(t.durationMs||0),0)/i.length:0,o=`inline-flex items-baseline gap-1.5 whitespace-nowrap`,s=`text-sm font-medium text-content tabular-nums`;return(0,X.jsxs)(`div`,{className:`workflow-operations-strip flex min-w-0 flex-wrap items-center gap-x-5 gap-y-1 text-xs text-content-muted max-[650px]:w-full max-[650px]:justify-between max-[650px]:gap-x-3`,children:[(0,X.jsxs)(`span`,{className:o,children:[e.limits.running>0&&(0,X.jsx)(Ke,{status:`run`,className:`size-3 self-center text-st-run`}),(0,X.jsx)(`strong`,{className:s,children:e.limits.running}),t(`workflows:workflowsPage.running`)]}),(0,X.jsxs)(`span`,{className:B(o,r>0&&`text-st-attn`),children:[(0,X.jsx)(`strong`,{className:B(s,r>0&&`text-st-attn`),children:r}),t(`workflows:workflowsPage.waitingApproval`)]}),(0,X.jsxs)(`span`,{className:o,children:[(0,X.jsx)(`strong`,{className:s,children:n}),t(`workflows:workflowsPage.failed`)]}),(0,X.jsxs)(`span`,{className:o,children:[(0,X.jsx)(`strong`,{className:B(s,`font-mono`),children:Bn(a)}),t(`workflows:workflowsPage.averageDuration`)]})]})}function Jn({value:e=``,onValueChange:t,files:n=[],onFilesSelected:r,onRemoveFile:i,accept:a=`media`,allowFiles:o=!0,allowText:s=!0,multiple:c=!1,disabled:l=!1,label:u,placeholder:d,attachmentLabel:f,removeLabel:p,children:m,className:h,maxLength:g}){let _=(0,G.useId)(),v=(0,G.useRef)(null),y=a===`image`?`image/png,image/jpeg,image/webp`:a===`video`?`video/mp4,video/webm`:`image/png,image/jpeg,image/webp,video/mp4,video/webm`;return(0,X.jsxs)(`div`,{className:B(`flex min-w-0 flex-col gap-2`,h),children:[(0,X.jsx)(R,{htmlFor:s?`${_}-text`:`${_}-picker`,children:u}),(0,X.jsxs)(`div`,{className:`min-w-0 rounded-md border border-control bg-panel transition-colors duration-[var(--d-fast)] focus-within:border-focus focus-within:ring-3 focus-within:ring-focus-ring`,onDragOver:e=>{o&&e.preventDefault()},onDrop:e=>{o&&(e.preventDefault(),!l&&e.dataTransfer.files.length&&r?.(Array.from(e.dataTransfer.files)))},children:[s&&(0,X.jsx)(et,{id:`${_}-text`,value:e,onChange:e=>t?.(e.target.value),placeholder:d,disabled:l,maxLength:g,className:`min-h-28 resize-y border-0 bg-transparent shadow-none focus-visible:ring-0`}),n.length>0&&(0,X.jsx)(`ul`,{className:B(`grid min-w-0 gap-2 p-3`,n.length>1&&`sm:grid-cols-2`),children:n.map(e=>(0,X.jsxs)(`li`,{className:`relative min-w-0 rounded-md border border-stroke bg-surface-subtle p-2`,children:[e.url&&e.mimeType.startsWith(`image/`)?(0,X.jsx)(`img`,{src:e.url,alt:e.name,className:`h-32 w-full rounded object-contain`}):e.url&&e.mimeType.startsWith(`video/`)?(0,X.jsx)(`video`,{src:e.url,controls:!0,preload:`metadata`,className:`h-32 w-full rounded object-contain`,"aria-label":e.name}):(0,X.jsx)(`div`,{className:`flex h-12 items-center justify-center text-muted-foreground`,children:e.mimeType.startsWith(`video/`)?(0,X.jsx)(oe,{}):(0,X.jsx)(k,{})}),(0,X.jsx)(`p`,{className:`mt-2 truncate pr-8 text-xs`,title:e.name,children:e.name}),i&&(0,X.jsx)(V,{type:`button`,variant:`ghost`,size:`icon-sm`,disabled:l,className:`absolute right-1 bottom-1`,"aria-label":`${p} ${e.name}`,onClick:()=>i(e.id),children:(0,X.jsx)(Ce,{className:`size-3.5`})})]},e.id))}),o&&(0,X.jsxs)(`div`,{className:`p-2`,children:[(0,X.jsx)(`input`,{id:`${_}-picker`,ref:v,className:`sr-only`,type:`file`,accept:y,multiple:c,disabled:l,"aria-label":f,onChange:e=>{let t=Array.from(e.currentTarget.files??[]);e.currentTarget.value=``,t.length&&r?.(t)}}),(0,X.jsxs)(V,{type:`button`,variant:`ghost`,size:`sm`,disabled:l,onClick:()=>v.current?.click(),children:[(0,X.jsx)(ue,{className:`size-4`}),f]})]})]}),m]})}function Yn(e){if(!e||typeof e!=`object`||!(`models`in e)||!Array.isArray(e.models))throw m();return e.models.map(e=>{if(!e||typeof e!=`object`||!(`id`in e)||typeof e.id!=`string`||!(`name`in e)||typeof e.name!=`string`||!(`providerId`in e)||typeof e.providerId!=`string`||!(`providerName`in e)||typeof e.providerName!=`string`||!e.id.startsWith(`${e.providerId}/`))throw m();return{id:e.id,name:e.name,providerId:e.providerId,providerName:e.providerName}})}function Xn(e){if(!e||typeof e!=`object`||!(`started`in e)||e.started!==!0||!(`run`in e)||!e.run||typeof e.run!=`object`||!(`id`in e.run)||typeof e.run.id!=`string`||!(`workflowId`in e.run)||typeof e.run.workflowId!=`string`)throw m();return{started:!0,run:{id:e.run.id,workflowId:e.run.workflowId}}}var Zn={runNode:(e,t,n,r)=>f(`/api/workflows/${encodeURIComponent(e)}/nodes/${encodeURIComponent(t)}/run`,{method:`POST`,data:{sourceRunId:n},signal:r,parse:Xn}),models:e=>f(`/api/workflow-image-models`,{signal:e,parse:Yn})};Object.freeze([{id:`background`,name:`U²-Net small + ONNX Runtime Web`,version:`ort-1.20.1_u2netp-v0.0.0`,licenses:[{name:`ONNX Runtime — MIT`,url:`https://github.com/microsoft/onnxruntime/blob/v1.20.1/LICENSE`},{name:`U²-Net — Apache-2.0`,url:`https://github.com/xuebinqin/U-2-Net/blob/ac7e1c817ecab7c7dff5ce6b1abba61cd213ff29/LICENSE`}],files:[{name:`ort.wasm.min.js`,url:`https://cdn.jsdelivr.net/npm/onnxruntime-web@1.20.1/dist/ort.wasm.min.js`,bytes:49026,sha256:`e66568724f8848e57cc2a56e4bea3a5b86ce3ff81b2da11eac8ed7ab02b27bd4`,mimeType:`text/javascript`},{name:`ort-wasm-simd-threaded.mjs`,url:`https://cdn.jsdelivr.net/npm/onnxruntime-web@1.20.1/dist/ort-wasm-simd-threaded.mjs`,bytes:24618,sha256:`745eb7c0ce6f18a6aa521971b2877babc7ffb27eecb58ab3bc6e5ef4692672e8`,mimeType:`text/javascript`},{name:`ort-wasm-simd-threaded.wasm`,url:`https://cdn.jsdelivr.net/npm/onnxruntime-web@1.20.1/dist/ort-wasm-simd-threaded.wasm`,bytes:11246032,sha256:`207d02be4591c156b0a98f024f3d58005b5b04c92274d759fb390338c63559ea`,mimeType:`application/wasm`},{name:`u2netp.onnx`,url:`https://gh-proxy.com/https://github.com/danielgatis/rembg/releases/download/v0.0.0/u2netp.onnx`,fallbackUrls:[`https://ghfast.top/https://github.com/danielgatis/rembg/releases/download/v0.0.0/u2netp.onnx`],bytes:4574861,sha256:`309c8469258dda742793dce0ebea8e6dd393174f89934733ecc8b14c76f4ddd8`,mimeType:`application/octet-stream`},{name:`LICENSE-ORT.txt`,url:`https://cdn.jsdelivr.net/gh/microsoft/onnxruntime@v1.20.1/LICENSE`,bytes:1073,sha256:`2f07c72751aed99790b8a4869cf2311df85a860b22ded05fa22803587a48922c`,mimeType:`text/plain; charset=utf-8`},{name:`LICENSE-U2NET.txt`,url:`https://cdn.jsdelivr.net/gh/xuebinqin/U-2-Net@ac7e1c817ecab7c7dff5ce6b1abba61cd213ff29/LICENSE`,bytes:11357,sha256:`c71d239df91726fc519c6eb72d318ec65820627232b2f796219e87dcf35d0ab4`,mimeType:`text/plain; charset=utf-8`}]},{id:`inpaint`,name:`OpenCV.js inpainting`,version:`5.0.0-release.1`,licenses:[{name:`OpenCV — Apache-2.0`,url:`https://github.com/opencv/opencv/blob/5.0.0/LICENSE`},{name:`TechStark OpenCV.js — Apache-2.0`,url:`https://github.com/TechStark/opencv-js/blob/v5.0.0-release.1/LICENSE`}],files:[{name:`opencv.js`,url:`https://cdn.jsdelivr.net/npm/@techstark/opencv-js@5.0.0-release.1/dist/opencv.js`,bytes:13298869,sha256:`b873c8211421da7b9bf41ae157a923f05a46a0b8d3e5904c44c6f3ad6d39a1bd`,mimeType:`text/javascript`},{name:`LICENSE-OpenCV.txt`,url:`https://cdn.jsdelivr.net/gh/opencv/opencv@5.0.0/LICENSE`,bytes:11358,sha256:`cfc7749b96f63bd31c3c42b5c471bf756814053e847c10f3eb003417bc523d30`,mimeType:`text/plain; charset=utf-8`},{name:`LICENSE-OpenCV-JS.txt`,url:`https://cdn.jsdelivr.net/gh/TechStark/opencv-js@v5.0.0-release.1/LICENSE`,bytes:11357,sha256:`c71d239df91726fc519c6eb72d318ec65820627232b2f796219e87dcf35d0ab4`,mimeType:`text/plain; charset=utf-8`}]}]);function Qn(e){let t=()=>Error(`Invalid sprite engine catalog`);if(!e||typeof e!=`object`||!(`engines`in e)||!Array.isArray(e.engines)||e.engines.length>2)throw t();let n=e.engines.map(e=>{if(!e||typeof e!=`object`)throw t();let n=e.id,r=e.status;if(n!==`background`&&n!==`inpaint`||![`missing`,`downloading`,`ready`,`failed`].includes(r))throw t();for(let n of[`name`,`version`,`error`])if(typeof e[n]!=`string`||e[n].length>500)throw t();if(e.file!==void 0&&(typeof e.file!=`string`||!/^[a-zA-Z0-9._-]{0,160}$/.test(e.file)))throw t();for(let n of[`bytes`,`received`,`total`])if(!Number.isSafeInteger(e[n])||e[n]<0)throw t();if(e.received>e.total)throw t();return{id:n,name:e.name,version:e.version,bytes:e.bytes,status:r,received:e.received,total:e.total,error:e.error,file:e.file??``}});if(new Set(n.map(e=>e.id)).size!==n.length)throw t();return{engines:n}}var $n=[`workflows`,`sprite-engines`];function er(e){try{return Qn(e)}catch{throw m()}}var tr={catalog:e=>f(`/api/sprite-engines`,{signal:e,parse:er}),download:(e,t)=>f(`/api/sprite-engines/${e}/download`,{method:`POST`,data:{},signal:t,parse:er}),cancel:(e,t)=>f(`/api/sprite-engines/${e}/cancel`,{method:`POST`,data:{},signal:t,parse:er}),remove:(e,t)=>f(`/api/sprite-engines/${e}`,{method:`DELETE`,signal:t,parse:er})};function $({label:e,value:t,min:n,max:r,step:i=1,onChange:a}){return(0,X.jsxs)(U,{variant:`control`,children:[e,(0,X.jsx)(H,{type:`number`,value:t,min:n,max:r,step:i,onChange:e=>{if(!e.target.value)return;let t=e.target.valueAsNumber;Number.isFinite(t)&&a(Math.max(n,Math.min(r,t)))}})]})}function nr({t:e,id:t=`background`}){let n=u(),[r,i]=(0,G.useState)(!1),[a,o]=(0,G.useState)(!1),s=(0,G.useRef)(null);(0,G.useEffect)(()=>()=>s.current?.abort(),[]);let c=d({queryKey:$n,queryFn:({signal:e})=>tr.catalog(e),refetchInterval:e=>e.state.data?.engines.some(e=>e.status===`downloading`)?1e3:!1}),l=c.data?.engines.find(e=>e.id===t),f=async()=>{if(s.current)return;let e=new AbortController;s.current=e,o(!0),i(!1);try{n.setQueryData($n,await tr.download(t,e.signal))}catch{e.signal.aborted||i(!0)}finally{e.signal.aborted||o(!1),s.current===e&&(s.current=null)}};return(0,X.jsxs)(`div`,{className:`space-y-2 rounded-md border p-3 text-xs`,children:[(0,X.jsx)(`p`,{children:e(`workflows:imageNodes.modelHint`)}),(0,X.jsx)(`p`,{children:l?.status===`ready`?e(`workflows:imageNodes.engineReady`):l?.status===`downloading`?e(`workflows:imageNodes.engineDownloading`,{percent:Math.round(l.total?100*l.received/l.total:0)}):e(`workflows:imageNodes.engineMissing`)}),(r||c.isError||l?.status===`failed`)&&(0,X.jsx)(`p`,{role:`alert`,children:e(`workflows:imageNodes.engineFailed`)}),l?.status!==`ready`&&(0,X.jsxs)(V,{size:`sm`,variant:`outline`,disabled:a||l?.status===`downloading`,onClick:()=>void f(),children:[a||l?.status===`downloading`?(0,X.jsx)(re,{className:`animate-spin`}):(0,X.jsx)(M,{}),e(`workflows:imageNodes.download`)]})]})}function rr({node:e,inputs:t,t:n,onChange:r}){let i=Ut(e.image),a=e=>r({image:{...i,...e}}),o=d({queryKey:[`workflows`,`image-models`],queryFn:({signal:e})=>Zn.models(e),enabled:e.kind===`media-generate`}),[s,c]=(0,G.useState)(0);(0,G.useEffect)(()=>c(0),[e.id]);let l=i.transforms.find(e=>e.index===s)??{index:s,x:0,y:0,rotation:0,scale:1,opacity:1,durationMs:i.durationMs,enabled:!0},u=e=>a({transforms:[...i.transforms.filter(e=>e.index!==s),{...l,...e}]}),f=i.frameOrder,p=(e,t)=>{let n=[...f],r=e+t;r<0||r>=n.length||([n[e],n[r]]=[n[r],n[e]],a({frameOrder:n}))};return(0,X.jsxs)(`div`,{className:`my-3 space-y-3 border-y py-3`,children:[e.kind===`media-input`&&(0,X.jsxs)(U,{variant:`control`,children:[n(`workflows:imageNodes.inputField`),(0,X.jsxs)(W,{value:i.inputName,onChange:e=>a({inputName:e.target.value}),children:[!t.some(e=>e.type===`image`&&e.name===i.inputName)&&(0,X.jsx)(`option`,{value:i.inputName,children:n(`workflows:imageNodes.chooseInput`)}),t.filter(e=>e.type===`image`).map(e=>(0,X.jsx)(`option`,{value:e.name,children:e.label},e.id))]}),(0,X.jsx)(`small`,{children:n(`workflows:imageNodes.inputHint`)})]}),e.kind===`media-generate`&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(U,{variant:`control`,children:[n(`workflows:imageNodes.imageModel`),(0,X.jsxs)(W,{value:e.model?`${e.model.provider}/${e.model.model}`:``,onChange:e=>{let t=o.data?.find(t=>t.id===e.target.value);r({model:t?{provider:t.providerId,model:t.id.slice(t.providerId.length+1)}:null})},children:[(0,X.jsx)(`option`,{value:``,children:n(`workflows:imageNodes.defaultImageModel`)}),o.data?.map(e=>(0,X.jsxs)(`option`,{value:e.id,children:[e.providerName,` / `,e.name]},e.id))]}),o.isError&&(0,X.jsx)(`small`,{role:`alert`,children:n(`workflows:imageNodes.modelsFailed`)})]}),(0,X.jsxs)(U,{variant:`control`,children:[n(`workflows:imageNodes.action`),(0,X.jsx)(H,{value:i.action,maxLength:160,onChange:e=>a({action:e.target.value})})]}),(0,X.jsx)(Jn,{label:n(`workflows:imageNodes.prompt`),value:e.prompt,onValueChange:e=>r({prompt:e}),allowFiles:!1,maxLength:16e3,attachmentLabel:n(`workflows:inputs.chooseImage`),removeLabel:n(`workflows:inputs.removeMedia`)}),(0,X.jsx)($,{label:n(`workflows:imageNodes.frameCount`),value:i.frameCount,min:1,max:16,onChange:e=>a({frameCount:e})}),(0,X.jsxs)(`fieldset`,{className:`space-y-2`,children:[(0,X.jsx)(`legend`,{className:`text-sm`,children:n(`workflows:imageNodes.directions`)}),(0,X.jsx)(`div`,{className:`grid grid-cols-4 gap-1`,children:Vt.map(e=>(0,X.jsx)(V,{size:`sm`,variant:i.directions.includes(e)?`secondary`:`outline`,"aria-pressed":i.directions.includes(e),disabled:i.directions.length===1&&i.directions[0]===e,onClick:()=>a({directions:i.directions.includes(e)?i.directions.filter(t=>t!==e):Vt.filter(t=>i.directions.includes(t)||t===e)}),children:e},e))})]}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(`workflows:imageNodes.generateHint`,{count:i.directions.length})})]}),e.kind===`media-background`&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(U,{variant:`control`,children:[n(`workflows:imageNodes.method`),(0,X.jsxs)(W,{value:i.method,onChange:e=>a({method:e.target.value===`model`?`model`:`color`}),children:[(0,X.jsx)(`option`,{value:`color`,children:n(`workflows:imageNodes.colorKey`)}),(0,X.jsx)(`option`,{value:`model`,children:n(`workflows:imageNodes.localModel`)})]})]}),i.method===`model`?(0,X.jsx)(nr,{t:n}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(`p`,{className:`text-sm`,children:n(`workflows:imageNodes.colors`)}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(`workflows:imageNodes.colorsHint`)}),(0,X.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:i.colors.map((e,t)=>(0,X.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,X.jsx)(`input`,{className:`h-8 w-10 cursor-pointer rounded border`,type:`color`,value:e,"aria-label":n(`workflows:imageNodes.colorAt`,{index:t+1}),onChange:e=>a({colors:i.colors.map((n,r)=>r===t?e.target.value:n)})}),(0,X.jsx)(V,{size:`icon-xs`,variant:`ghost`,"aria-label":n(`workflows:imageNodes.removeColor`),onClick:()=>a({colors:i.colors.filter((e,n)=>n!==t)}),children:(0,X.jsx)(be,{})})]},t))}),(0,X.jsxs)(V,{size:`sm`,variant:`outline`,disabled:i.colors.length>=8,onClick:()=>a({colors:[...i.colors,`#00ff00`]}),children:[(0,X.jsx)(pe,{}),n(`workflows:imageNodes.addColor`)]})]}),(0,X.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,X.jsx)($,{label:n(`workflows:imageNodes.tolerance`),value:i.tolerance,min:0,max:255,onChange:e=>a({tolerance:e})}),(0,X.jsx)($,{label:n(`workflows:imageNodes.softness`),value:i.softness,min:0,max:64,onChange:e=>a({softness:e})})]}),(0,X.jsxs)(`label`,{className:`flex items-center justify-between gap-3 text-sm`,children:[n(`workflows:imageNodes.edgeConnected`),(0,X.jsx)(z,{checked:i.edgeConnected,onCheckedChange:e=>a({edgeConnected:e})})]})]})]}),e.kind===`media-inpaint`&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(`workflows:imageNodes.regionHint`)}),(0,X.jsx)(nr,{t:n,id:`inpaint`}),(0,X.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,X.jsx)($,{label:n(`workflows:imageNodes.regionX`),value:i.region.x,min:0,max:99,onChange:e=>a({region:{...i.region,x:e}})}),(0,X.jsx)($,{label:n(`workflows:imageNodes.regionY`),value:i.region.y,min:0,max:99,onChange:e=>a({region:{...i.region,y:e}})}),(0,X.jsx)($,{label:n(`workflows:imageNodes.regionWidth`),value:i.region.width,min:1,max:100,onChange:e=>a({region:{...i.region,width:e}})}),(0,X.jsx)($,{label:n(`workflows:imageNodes.regionHeight`),value:i.region.height,min:1,max:100,onChange:e=>a({region:{...i.region,height:e}})})]})]}),e.kind===`media-frames`&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(`workflows:imageNodes.gridHint`)}),(0,X.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,X.jsx)($,{label:n(`workflows:imageNodes.columns`),value:i.columns,min:1,max:16,onChange:e=>a({columns:e})}),(0,X.jsx)($,{label:n(`workflows:imageNodes.rows`),value:i.rows,min:1,max:16,onChange:e=>a({rows:e})})]}),(0,X.jsx)($,{label:n(`workflows:imageNodes.duration`),value:i.durationMs,min:16,max:1e4,onChange:e=>a({durationMs:e})})]}),e.kind===`media-transform`&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`label`,{className:`flex items-center justify-between gap-3 text-sm`,children:[n(`workflows:imageNodes.trim`),(0,X.jsx)(z,{checked:i.trim,onCheckedChange:e=>a({trim:e})})]}),(0,X.jsxs)(U,{variant:`control`,children:[n(`workflows:imageNodes.align`),(0,X.jsxs)(W,{value:i.align,onChange:e=>a({align:e.target.value===`center`?`center`:e.target.value===`none`?`none`:`bottom-center`}),children:[(0,X.jsx)(`option`,{value:`bottom-center`,children:n(`workflows:imageNodes.bottomCenter`)}),(0,X.jsx)(`option`,{value:`center`,children:n(`workflows:imageNodes.center`)}),(0,X.jsx)(`option`,{value:`none`,children:n(`workflows:imageNodes.noAlign`)})]})]}),(0,X.jsx)($,{label:n(`workflows:imageNodes.maxFrameSize`),value:i.maxFrameSize,min:16,max:1024,onChange:e=>a({maxFrameSize:Math.round(e)})}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(`workflows:imageNodes.maxFrameSizeHint`,{size:i.maxFrameSize})}),(0,X.jsx)($,{label:n(`workflows:imageNodes.padding`),value:i.padding,min:0,max:64,onChange:e=>a({padding:e})}),(0,X.jsxs)(`details`,{className:`rounded-md border p-3`,children:[(0,X.jsx)(`summary`,{className:`cursor-pointer text-sm`,children:n(`workflows:imageNodes.frameEdits`)}),(0,X.jsxs)(`div`,{className:`mt-3 space-y-3`,children:[(0,X.jsx)($,{label:n(`workflows:imageNodes.frameNumber`),value:s+1,min:1,max:512,onChange:e=>c(Math.round(e)-1)}),(0,X.jsxs)(`label`,{className:`flex justify-between text-sm`,children:[n(`workflows:imageNodes.frameEnabled`),(0,X.jsx)(z,{checked:l.enabled,onCheckedChange:e=>u({enabled:e})})]}),(0,X.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,X.jsx)($,{label:`X`,value:l.x,min:-4096,max:4096,onChange:e=>u({x:e})}),(0,X.jsx)($,{label:`Y`,value:l.y,min:-4096,max:4096,onChange:e=>u({y:e})}),(0,X.jsx)($,{label:n(`workflows:imageNodes.rotation`),value:l.rotation,min:-360,max:360,onChange:e=>u({rotation:e})}),(0,X.jsx)($,{label:n(`workflows:imageNodes.scale`),value:l.scale,min:.05,max:8,step:.05,onChange:e=>u({scale:e})}),(0,X.jsx)($,{label:n(`workflows:imageNodes.opacity`),value:l.opacity,min:0,max:1,step:.05,onChange:e=>u({opacity:e})}),(0,X.jsx)($,{label:n(`workflows:imageNodes.duration`),value:l.durationMs,min:16,max:1e4,onChange:e=>u({durationMs:e})})]}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(`workflows:imageNodes.orderHint`)}),(0,X.jsx)(V,{size:`sm`,variant:`outline`,disabled:f.includes(s),onClick:()=>a({frameOrder:[...f,s]}),children:n(`workflows:imageNodes.addToOrder`)}),f.map((e,t)=>(0,X.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,X.jsx)(`span`,{className:`mr-auto text-xs`,children:n(`workflows:imageNodes.frameAt`,{index:e+1})}),(0,X.jsx)(V,{size:`icon-xs`,variant:`ghost`,"aria-label":n(`workflows:imageNodes.earlier`),disabled:t===0,onClick:()=>p(t,-1),children:(0,X.jsx)(b,{})}),(0,X.jsx)(V,{size:`icon-xs`,variant:`ghost`,"aria-label":n(`workflows:imageNodes.later`),disabled:t===f.length-1,onClick:()=>p(t,1),children:(0,X.jsx)(y,{})}),(0,X.jsx)(V,{size:`icon-xs`,variant:`ghost`,"aria-label":n(`workflows:imageNodes.resetOrder`),onClick:()=>a({frameOrder:f.filter(t=>t!==e)}),children:(0,X.jsx)(be,{})})]},e))]})]})]}),e.kind===`media-preview`&&(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(`workflows:imageNodes.previewHint`)}),e.kind===`media-export`&&(0,X.jsxs)(U,{variant:`control`,children:[n(`workflows:imageNodes.filename`),(0,X.jsx)(H,{value:i.filename,maxLength:100,onChange:e=>a({filename:e.target.value})}),(0,X.jsx)(`small`,{children:n(`workflows:imageNodes.exportHint`)})]})]})}var ir={upload:(e,t)=>f(`/api/workflow-media?name=${encodeURIComponent(e.name)}`,{method:`POST`,data:e,headers:{"Content-Type":e.type},signal:t,timeout:12e4,parse:e=>{try{return Lt(e)}catch{throw m()}}}),preview:(e,t)=>p(`/api/workflow-media/${encodeURIComponent(e)}/content`,{signal:t})};function ar(e){try{return Wt(e)}catch{return null}}function or(e){let[t,n]=(0,G.useState)({id:``,image:null,error:!1}),r=e?.media.id;return(0,G.useEffect)(()=>{if(n({id:r??``,image:null,error:!1}),!r)return;let e=new AbortController,t=``,i=null;return ir.preview(r,e.signal).then(a=>{if(e.signal.aborted)return;t=URL.createObjectURL(a),i=new Image;let o=i;i.onload=()=>{e.signal.aborted||n({id:r,image:o,error:!1})},i.onerror=()=>{e.signal.aborted||n({id:r,image:null,error:!0})},i.src=t}).catch(()=>{e.signal.aborted||n({id:r,image:null,error:!0})}),()=>{e.abort(),i&&(i.onload=null,i.onerror=null,i.src=``),t&&URL.revokeObjectURL(t)}},[r]),t.id===r?t:{id:r??``,image:null,error:!1}}function sr(e,t){return t(e===`workflow_image_source_stale`?`workflows:imageNodes.sourceStale`:e===`workflow_image_source_required`?`workflows:imageNodes.sourceRequired`:e===`workflow_image_engine_missing`?`workflows:imageNodes.engineMissing`:e===`workflow_image_decode_failed`?`workflows:imageNodes.decodeFailed`:e===`workflow_image_generation_failed`?`workflows:imageNodes.generationFailed`:e===`workflow_image_too_large`?`workflows:imageNodes.tooLarge`:e===`workflow_image_cancelled`?`workflows:imageNodes.cancelled`:e===`workflow_image_timeout`?`workflows:imageNodes.timeout`:`workflows:imageNodes.invalidOutput`)}function cr({value:e,previousValue:t,error:n,t:r}){let i=(0,G.useMemo)(()=>ar(e),[e]),a=(0,G.useMemo)(()=>ar(t),[t]),[o,s]=(0,G.useState)(``),[c,l]=(0,G.useState)(``),[u,d]=(0,G.useState)(0),[f,p]=(0,G.useState)(!1),[m,h]=(0,G.useState)(!1),[g,_]=(0,G.useState)(!1),[v,y]=(0,G.useState)(!1),[b,x]=(0,G.useState)(!1),S=(0,G.useRef)(null),C=(0,G.useRef)(null),w=[...new Set(i?.frames.map(e=>e.action).filter(Boolean)??[])],T=[...new Set(i?.frames.map(e=>e.direction).filter(Boolean)??[])],D=w.includes(o)?o:w[0]??``,O=T.includes(c)?c:T[0]??``,k=(0,G.useMemo)(()=>i?.frames.filter(e=>(!D||e.action===D)&&(!O||e.direction===O))??[],[i,D,O]),A=Math.min(u,Math.max(0,k.length-1)),j=a?.frames.filter(e=>e.action===k[A]?.action&&e.direction===k[A]?.direction),N=j?.[A]??j?.[0]??a?.frames[0],P=or(g?N:k[A]),F=or(m&&!g?k[(A+k.length-1)%k.length]:void 0),te=or(m&&!g?k[(A+1)%k.length]:void 0);(0,G.useEffect)(()=>{d(0),p(!1),_(!1)},[D,O,e]),(0,G.useEffect)(()=>()=>S.current?.abort(),[]),(0,G.useEffect)(()=>{if(!f||k.length<2)return;let e=window.setTimeout(()=>{document.hidden||d((A+1)%k.length)},k[A]?.durationMs??125),t=()=>{document.hidden&&p(!1)};return document.addEventListener(`visibilitychange`,t),()=>{window.clearTimeout(e),document.removeEventListener(`visibilitychange`,t)}},[f,k,A]),(0,G.useEffect)(()=>{let e=C.current?.getContext(`2d`);if(!e)return;e.clearRect(0,0,512,384);let t=[F.image,P.image,te.image].filter(e=>!!e),n=Math.min(1,512/Math.max(1,...t.map(e=>e.naturalWidth)),384/Math.max(1,...t.map(e=>e.naturalHeight)))*.9,r=(t,r)=>{if(!t)return;e.save(),e.imageSmoothingEnabled=!1,e.globalAlpha=r;let i=t.naturalWidth*n,a=t.naturalHeight*n;e.drawImage(t,(512-i)/2,384*.95-a,i,a),e.restore()};r(F.image,.2),r(te.image,.15),r(P.image,1)},[P.image,F.image,te.image]);let ne=async e=>{if(!i||S.current)return;let t=new AbortController;S.current=t,x(!0),y(!1);let n=``;try{let r=e===`atlas`?i.atlas?.media:k[A]?.media,a=e===`json`?new Blob([JSON.stringify(i.atlas??i,null,2)],{type:`application/json`}):r?await ir.preview(r.id,t.signal):null;if(!a||t.signal.aborted)return;n=URL.createObjectURL(a);let o=document.createElement(`a`);o.href=n,o.download=e===`json`?`animation.frames.json`:(r?.name??`animation.png`).replace(/[\\/:*?"<>|\p{Cc}]/gu,`_`),o.click()}catch{t.signal.aborted||y(!0)}finally{n&&URL.revokeObjectURL(n),t.signal.aborted||x(!1),S.current===t&&(S.current=null)}};return!i&&!n?(0,X.jsx)(`p`,{className:`my-3 text-xs text-muted-foreground`,children:r(`workflows:imageNodes.noResult`)}):(0,X.jsxs)(`section`,{className:`my-3 space-y-3 rounded-md border p-3`,"aria-label":r(`workflows:imageNodes.result`),children:[(0,X.jsx)(`h3`,{className:`text-sm font-medium`,children:r(`workflows:imageNodes.result`)}),n&&(0,X.jsx)(`p`,{role:`alert`,className:`text-xs text-muted-foreground`,children:sr(n,r)}),k.length>0&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[w.length>0&&(0,X.jsx)(W,{"aria-label":r(`workflows:imageNodes.action`),value:D,onChange:e=>s(e.target.value),children:w.map(e=>(0,X.jsx)(`option`,{value:e,children:e},e))}),T.length>0&&(0,X.jsx)(W,{"aria-label":r(`workflows:imageNodes.directions`),value:O,onChange:e=>l(e.target.value),children:T.map(e=>(0,X.jsx)(`option`,{value:e,children:e},e))})]}),(0,X.jsxs)(`div`,{className:`relative overflow-hidden rounded-md border bg-[repeating-conic-gradient(var(--surface-active)_0%_25%,var(--surface-muted)_0%_50%)] bg-size-[16px_16px]`,children:[(0,X.jsx)(`canvas`,{width:512,height:384,ref:C,className:`w-full`,role:`img`,"aria-label":r(`workflows:imageNodes.frameAt`,{index:A+1})}),!P.image&&!P.error&&(0,X.jsx)(re,{className:`absolute top-1/2 left-1/2 size-5 animate-spin`})]}),P.error&&(0,X.jsx)(`p`,{role:`alert`,className:`text-xs`,children:r(`workflows:inputs.previewFailed`)}),(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center justify-center gap-1`,children:[(0,X.jsx)(V,{size:`icon-sm`,variant:`outline`,"aria-label":r(`workflows:imageNodes.previousFrame`),disabled:k.length<2,onClick:()=>{p(!1),d((A+k.length-1)%k.length)},children:(0,X.jsx)(E,{})}),(0,X.jsx)(V,{size:`icon-sm`,variant:`outline`,"aria-label":r(f?`workflows:imageNodes.pause`:`workflows:imageNodes.play`),disabled:k.length<2,onClick:()=>p(!f),children:f?(0,X.jsx)(Nt,{}):(0,X.jsx)(fe,{})}),(0,X.jsx)(V,{size:`icon-sm`,variant:`outline`,"aria-label":r(`workflows:imageNodes.nextFrame`),disabled:k.length<2,onClick:()=>{p(!1),d((A+1)%k.length)},children:(0,X.jsx)(ee,{})}),(0,X.jsxs)(`span`,{className:`px-1 text-xs tabular-nums`,children:[A+1,` / `,k.length]})]}),(0,X.jsx)(Pe,{className:`h-7 w-full`,min:0,max:Math.max(0,k.length-1),step:1,value:[A],"aria-label":r(`workflows:imageNodes.frameNumber`),valueText:`${A+1} / ${k.length}`,onValueChange:([e])=>{p(!1),d(e)}}),(0,X.jsxs)(`label`,{className:`flex items-center justify-between text-xs`,children:[r(`workflows:imageNodes.onionSkin`),(0,X.jsx)(z,{checked:m,onCheckedChange:h})]}),N&&(0,X.jsxs)(`label`,{className:`flex items-center justify-between text-xs`,children:[r(`workflows:imageNodes.showInput`),(0,X.jsx)(z,{checked:g,onCheckedChange:_})]}),(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,X.jsxs)(V,{size:`sm`,variant:`outline`,disabled:b,onClick:()=>void ne(`frame`),children:[(0,X.jsx)(M,{}),r(`workflows:imageNodes.saveFrame`)]}),i?.atlas&&(0,X.jsxs)(V,{size:`sm`,variant:`outline`,disabled:b,onClick:()=>void ne(`atlas`),children:[(0,X.jsx)(M,{}),`PNG`]}),(0,X.jsxs)(V,{size:`sm`,variant:`outline`,disabled:b,onClick:()=>void ne(`json`),children:[(0,X.jsx)(M,{}),`JSON`]})]})]}),v&&(0,X.jsx)(`p`,{role:`alert`,className:`text-xs`,children:r(`workflows:imageNodes.downloadFailed`)})]})}function lr(e){return e?e.status===`completed`?100:Math.round((Number(e.completedNodes)||0)/Math.max(1,Number(e.totalNodes)||1)*100):0}function ur(e){let t=Math.max(0,Math.round((Number(e)||0)/1e3));return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`}function dr({run:e,t}){let n=e.status===`waiting_approval`,r=lr(e);return(0,X.jsxs)(`div`,{role:`status`,className:B(`relative flex min-h-9 shrink-0 items-center gap-2 overflow-hidden border-b border-stroke-soft px-3 text-sm max-[650px]:min-h-11`,n?`bg-warning-soft`:`bg-star-soft`),children:[n?(0,X.jsx)(jt,{className:`size-4 shrink-0 text-warning-strong`,"aria-hidden":`true`}):(0,X.jsx)(Re,{}),(0,X.jsx)(`strong`,{className:B(`shrink-0 font-medium`,n?`text-warning-strong`:`text-accent-fg`),children:t(n?`workflows:workflowsPage.waitingApproval`:`workflows:workflowsPage.workflowRunning`)}),(0,X.jsx)(`span`,{className:`min-w-0 truncate text-content-secondary tabular-nums`,children:t(`workflows:workflowsPage.runningNodeCompletedTotalCompleted`,{node:e.currentNodeLabel||t(`workflows:workflowsPage.preparing`),completed:e.completedNodes,total:e.totalNodes})}),(0,X.jsx)(`span`,{className:`ml-auto shrink-0 font-mono text-xs text-content-muted tabular-nums`,children:ur(e.durationMs)}),(0,X.jsx)(`i`,{"aria-hidden":`true`,className:`absolute inset-x-0 bottom-0 h-0.5 origin-left bg-star transition-transform duration-(--d-base) ease-precise`,style:{transform:`scaleX(${r/100})`}})]})}function fr({run:e,language:t,t:n}){return e?(0,X.jsxs)(`div`,{className:`activity-row flex min-w-0 items-start gap-2.5 text-sm ${e.status}`,children:[(0,X.jsx)(In,{status:e.status,className:`mt-px`}),(0,X.jsxs)(`span`,{className:`flex min-w-0 flex-col gap-0.5`,children:[(0,X.jsx)(`strong`,{className:B(`font-medium break-words`,e.status===`failed`?`text-danger`:`text-content`),children:e.status===`completed`?e.summary||n(`workflows:workflowsPage.workflowCompleted`):e.status===`waiting_approval`?n(`workflows:workflowsPage.waitingApproval`):e.status===`running`?e.currentNodeLabel||n(`workflows:workflowsPage.running`):e.error?Q(e.error):n(`workflows:workflowsPage.workflowFailed`)}),(0,X.jsxs)(`small`,{className:`text-xs text-content-muted tabular-nums`,children:[Ge(e.startedAt,t),` · `,ur(e.durationMs)]})]})]}):(0,X.jsx)(`p`,{className:`text-xs text-content-muted`,children:n(`workflows:workflowsPage.noRunHistory`)})}function pr({input:e,value:t,onChange:n,label:r,disabled:i=!1,onBusyChange:a}){let{t:o}=l(),[s,c]=(0,G.useState)({id:``,url:``}),[u,d]=(0,G.useState)(!1),[f,p]=(0,G.useState)(``),m=(0,G.useRef)(null),h=(0,G.useRef)(!0),g=(0,G.useRef)(a);g.current=a;let _=(0,G.useRef)({onChange:n,id:e.id,type:e.type});_.current={onChange:n,id:e.id,type:e.type};let v=e.type,y=(()=>{try{return Lt(t)}catch{return null}})(),b=y?.id;(0,G.useEffect)(()=>(h.current=!0,d(!1),p(``),()=>{h.current=!1,m.current?.abort(),m.current=null,g.current?.(e.id,!1)}),[e.id,v]),(0,G.useEffect)(()=>{if(c({id:``,url:``}),!b)return;let e=new AbortController,t=``;return ir.preview(b,e.signal).then(n=>{e.signal.aborted||(t=URL.createObjectURL(n),c({id:b,url:t}))}).catch(()=>{e.signal.aborted||p(o(`workflows:inputs.previewFailed`))}),()=>{e.abort(),t&&URL.revokeObjectURL(t)}},[b,o]);let x=async(t,n)=>{if(!t.length||i||m.current||n!==`image`&&n!==`video`)return;if(t.length!==1){p(o(`workflows:inputs.oneFile`));return}let r=t[0];if(!(n===`image`?[`image/png`,`image/jpeg`,`image/webp`]:[`video/mp4`,`video/webm`]).includes(r.type)){p(o(`workflows:inputs.mediaType`));return}if(r.size>(n===`image`?8:64)*1024*1024){p(o(n===`image`?`workflows:inputs.imageLimit`:`workflows:inputs.videoLimit`));return}let a=new AbortController;m.current=a,d(!0),g.current?.(e.id,!0),p(``);try{let t=await ir.upload(r,a.signal);h.current&&!a.signal.aborted&&m.current===a&&_.current.id===e.id&&_.current.type===n&&_.current.onChange(t)}catch{h.current&&!a.signal.aborted&&p(o(`workflows:inputs.uploadFailed`))}finally{m.current===a&&(m.current=null,h.current&&(d(!1),g.current?.(e.id,!1)))}};return(0,X.jsxs)(Jn,{label:r,value:typeof t==`string`?t:``,onValueChange:n,files:y?[{...y,url:s.id===y.id?s.url:void 0}]:[],onFilesSelected:e=>void x(e,v),onRemoveFile:()=>n(``),accept:v===`image`?`image`:`video`,allowFiles:v===`image`||v===`video`,allowText:v!==`image`&&v!==`video`,disabled:i||u,maxLength:16e3,attachmentLabel:o(v===`image`?`workflows:inputs.chooseImage`:`workflows:inputs.chooseVideo`),removeLabel:o(`workflows:inputs.removeMedia`),children:[u&&(0,X.jsxs)(`p`,{role:`status`,className:`flex items-center gap-1 text-xs text-muted-foreground`,children:[(0,X.jsx)(re,{className:`size-3 animate-spin`}),o(`workflows:inputs.uploading`)]}),f&&(0,X.jsx)(`p`,{role:`alert`,className:`text-xs text-destructive`,children:f})]})}function mr(e){return e===`number`||e===`boolean`||e===`text`||e===`image`||e===`video`?e:`string`}function hr(e){if(e.type===`image`||e.type===`video`)try{return Lt(e.defaultValue)}catch{return null}return e.type===`boolean`?e.defaultValue===!0||e.defaultValue===`true`:typeof e.defaultValue==`number`||typeof e.defaultValue==`string`?e.defaultValue:``}function gr(e,t){if(!(e instanceof K))return t(`workflows:inputs.invalidDefinition`);let n=e.label||e.inputName;return e.code===`workflow_input_unsafe_name`?t(`workflows:inputs.invalidName`):e.code===`workflow_input_duplicate_name`?t(`workflows:inputs.duplicateName`,{name:n}):e.code===`workflow_input_required`?t(`workflows:inputs.requiredValue`,{name:n}):e.code===`workflow_input_type`?t(`workflows:inputs.invalidValue`,{name:n}):e.code===`workflow_input_too_long`?t(`workflows:inputs.valueTooLong`,{name:n}):e.code===`workflow_input_unknown`?t(`workflows:inputs.unknownInput`,{name:n}):t(`workflows:inputs.invalidDefinition`)}function _r(e,t){try{return zt(e),``}catch(e){return gr(e,t)}}function vr(e,t,n){try{return Bt(e,t),``}catch(e){return gr(e,n)}}function yr(e,t){return Bt(e,t)}function br(e,t){return e.type===`text`?t(`workflows:inputs.longText`):e.type===`number`?t(`workflows:inputs.number`):e.type===`boolean`?t(`workflows:inputs.boolean`):e.type===`image`?t(`workflows:inputs.image`):e.type===`video`?t(`workflows:inputs.video`):t(`workflows:inputs.shortText`)}function xr({inputs:e,onChange:t,t:n,onUploadBusy:r}){let i=(0,G.useId)(),[a,o]=(0,G.useState)(null),s=_r(e,n),c=(n,r)=>t(e.map(e=>e.id===n?{...e,...r}:e));return(0,X.jsxs)(`section`,{className:`mt-4 min-w-0 space-y-3`,"aria-labelledby":`${i}-title`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,X.jsx)(`h3`,{id:`${i}-title`,className:`text-sm font-medium`,children:n(`workflows:workflowsPage.inputParameters`)}),(0,X.jsxs)(V,{variant:`ghost`,size:`sm`,disabled:e.length>=30,onClick:()=>{let r=e.length+1;for(;e.some(e=>e.name===`input_${r}`);)r+=1;let i=crypto.randomUUID();t([...e,{id:i,name:`input_${r}`,label:n(`workflows:workflowsPage.newInput`),type:`string`,required:!1,defaultValue:``,description:``}]),o(i)},children:[(0,X.jsx)(pe,{}),n(`workflows:workflowsPage.addInput`)]})]}),(0,X.jsx)(`p`,{className:`text-xs leading-relaxed text-muted-foreground`,children:n(`workflows:inputs.definitionHint`)}),s&&(0,X.jsx)(`p`,{role:`alert`,className:`text-xs text-destructive`,children:s}),e.length===0&&(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(`workflows:inputs.emptyDefinition`)}),e.map(s=>(0,X.jsxs)(pt,{className:`min-w-0 rounded-md border`,open:a===s.id,onOpenChange:e=>o(e?s.id:null),children:[(0,X.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2 p-3`,children:[(0,X.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-1`,children:[(0,X.jsx)(`p`,{className:`truncate text-sm font-medium`,children:s.label||s.name}),(0,X.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[br(s,n),` ·`,` `,s.required?n(`workflows:workflowsPage.required`):n(`workflows:inputs.optional`)]})]}),(0,X.jsx)(ft,{asChild:!0,children:(0,X.jsxs)(V,{variant:`ghost`,size:`sm`,"aria-label":n(`workflows:inputs.editNamedInput`,{name:s.label||s.name}),children:[(0,X.jsx)(de,{}),n(`workflows:inputs.editInput`)]})})]}),(0,X.jsxs)(dt,{className:`space-y-3 border-t p-3`,children:[(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(R,{htmlFor:`${i}-${s.id}-label`,className:`text-xs`,children:n(`workflows:inputs.label`)}),(0,X.jsx)(H,{id:`${i}-${s.id}-label`,value:s.label,maxLength:120,onChange:e=>c(s.id,{label:e.target.value})})]}),(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(R,{id:`${i}-${s.id}-type`,className:`text-xs`,children:n(`workflows:workflowsPage.parameterType`)}),(0,X.jsxs)(W,{"aria-labelledby":`${i}-${s.id}-type`,value:s.type,onChange:e=>{let t=mr(e.target.value);c(s.id,{type:t,defaultValue:t!==`boolean`&&``})},children:[(0,X.jsx)(`option`,{value:`string`,children:n(`workflows:inputs.shortText`)}),(0,X.jsx)(`option`,{value:`text`,children:n(`workflows:inputs.longText`)}),(0,X.jsx)(`option`,{value:`number`,children:n(`workflows:inputs.number`)}),(0,X.jsx)(`option`,{value:`boolean`,children:n(`workflows:inputs.boolean`)}),(0,X.jsx)(`option`,{value:`image`,children:n(`workflows:inputs.image`)}),(0,X.jsx)(`option`,{value:`video`,children:n(`workflows:inputs.video`)})]})]}),(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(R,{htmlFor:`${i}-${s.id}-description`,className:`text-xs`,children:n(`workflows:inputs.description`)}),(0,X.jsx)(et,{id:`${i}-${s.id}-description`,value:s.description,maxLength:300,rows:2,className:`min-h-14`,onChange:e=>c(s.id,{description:e.target.value})})]}),(0,X.jsxs)(`details`,{className:`group rounded-md border p-2`,children:[(0,X.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center justify-between gap-2 text-xs font-medium [&::-webkit-details-marker]:hidden`,children:[n(`workflows:inputs.advancedSettings`),(0,X.jsx)(T,{className:`size-3.5 transition-transform group-open:rotate-180`})]}),(0,X.jsxs)(`div`,{className:`space-y-3 pt-3`,children:[(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(R,{htmlFor:`${i}-${s.id}-name`,className:`text-xs`,children:n(`workflows:workflowsPage.parameterName`)}),(0,X.jsx)(H,{id:`${i}-${s.id}-name`,value:s.name,maxLength:80,onChange:e=>c(s.id,{name:e.target.value})}),(0,X.jsx)(`code`,{className:`block break-all text-xs text-muted-foreground`,children:`{{inputs.`+s.name+`}}`})]}),(0,X.jsxs)(`div`,{className:`space-y-1`,children:[s.type!==`text`&&s.type!==`image`&&s.type!==`video`&&(0,X.jsx)(R,{htmlFor:`${i}-${s.id}-default`,className:`text-xs`,children:n(`workflows:inputs.defaultValue`)}),s.type===`boolean`?(0,X.jsx)(z,{id:`${i}-${s.id}-default`,checked:hr(s)===!0,onCheckedChange:e=>c(s.id,{defaultValue:e})}):s.type===`text`||s.type===`image`||s.type===`video`?(0,X.jsx)(pr,{input:s,value:s.defaultValue,label:n(`workflows:inputs.defaultValue`),onBusyChange:r,onChange:e=>c(s.id,{defaultValue:e})}):(0,X.jsx)(H,{id:`${i}-${s.id}-default`,type:s.type===`number`?`number`:`text`,value:String(hr(s)),onChange:e=>c(s.id,{defaultValue:e.target.value})})]}),(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,X.jsx)(R,{htmlFor:`${i}-${s.id}-required`,className:`text-xs`,children:n(`workflows:workflowsPage.required`)}),(0,X.jsx)(z,{id:`${i}-${s.id}-required`,checked:s.required,onCheckedChange:e=>c(s.id,{required:e})})]})]})]}),(0,X.jsxs)(V,{variant:`ghost`,size:`sm`,"aria-label":n(`workflows:inputs.deleteInput`,{name:s.label}),onClick:()=>{t(e.filter(e=>e.id!==s.id)),o(null)},children:[(0,X.jsx)(be,{}),n(`workflows:inputs.removeInput`)]})]})]},s.id))]})}var Sr={browser:{Icon:x},feishu:{Icon:S},weixin:{Icon:ie},qq:{Icon:ie},telegram:{Icon:ae}},Cr=[`workspace-write`,`full-access`],wr=`workflow-notification-alert mt-2.5 mb-1.5 border-(--warning-border) bg-warning-soft text-content-secondary *:[svg]:text-warning-strong [&_[data-slot=alert-description]]:flex [&_[data-slot=alert-description]]:flex-wrap [&_[data-slot=alert-description]]:items-center [&_[data-slot=alert-description]]:gap-1 [&_[data-slot=alert-description]]:text-xs`,Tr=`rounded-md bg-surface-subtle p-3 text-xs leading-relaxed text-content-muted`;function Er(e,t){return t(e===`workspace-write`?`workflows:workflowsPage.workspaceWrite`:`workflows:workflowsPage.fullAccess`)}function Dr(e,t){return t(e===`workspace-write`?`workflows:workflowsPage.workspaceWriteHelp`:`workflows:workflowsPage.fullAccessHelp`)}function Or(e,t){return t(e===`feishu`?`workflows:workflowsPage.feishu`:e===`weixin`?`workflows:workflowsPage.weChat`:e===`qq`?`workflows:workflowsPage.qq`:e===`telegram`?`workflows:workflowsPage.telegram`:`workflows:workflowsPage.browserNotification`)}function kr({draft:e,catalog:t,t:n,onUpdateDraft:r,onInputUploadBusy:i}){return(0,X.jsxs)(`div`,{className:`min-w-0 space-y-4`,children:[(0,X.jsxs)(U,{variant:`control`,children:[n(`workflows:workflowsPage.name`),(0,X.jsx)(H,{value:e.name,onChange:e=>r({name:e.target.value})})]}),(0,X.jsxs)(U,{variant:`control`,children:[n(`workflows:workflowsPage.description`),(0,X.jsx)(et,{value:e.description,onChange:e=>r({description:e.target.value})})]}),(0,X.jsxs)(U,{variant:`control`,children:[n(`workflows:workflowsPage.workingDirectory`),(0,X.jsx)(H,{value:e.cwd,onChange:e=>r({cwd:e.target.value})})]}),(0,X.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-3`,children:[(0,X.jsxs)(U,{variant:`control`,children:[n(`workflows:workflowsPage.visibility`),(0,X.jsxs)(W,{value:e.visibility,onChange:e=>r({visibility:e.target.value===`shared`?`shared`:`private`}),children:[(0,X.jsx)(`option`,{value:`private`,children:n(`workflows:workflowsPage.private`)}),(0,X.jsx)(`option`,{value:`shared`,children:n(`workflows:workflowsPage.shared`)})]})]}),(0,X.jsxs)(U,{variant:`control`,children:[n(`workflows:workflowsPage.tags`),(0,X.jsx)(H,{value:e.tags.join(`, `),onChange:e=>r({tags:e.target.value.split(`,`).map(e=>e.trim()).filter(Boolean)})})]}),(0,X.jsxs)(U,{variant:`control`,children:[n(`workflows:workflowsPage.revision`),(0,X.jsx)(H,{value:`v${e.revision}`,disabled:!0})]})]}),(0,X.jsxs)(U,{variant:`control`,children:[n(`workflows:workflowsPage.defaultModel`),(0,X.jsxs)(W,{value:e.model?`${e.model.provider}/${e.model.model}`:``,onChange:e=>{let n=t.models.find(t=>`${t.provider}/${t.model}`===e.target.value);r({model:n?{provider:n.provider,model:n.model}:null})},children:[(0,X.jsx)(`option`,{value:``,children:n(`workflows:workflowsPage.useSystemDefault`)}),t.models.map(e=>(0,X.jsx)(`option`,{value:`${e.provider}/${e.model}`,children:e.label},`${e.provider}/${e.model}`))]})]}),(0,X.jsx)(xr,{inputs:e.inputs,t:n,onUploadBusy:i,onChange:e=>r({inputs:e})})]})}function Ar({node:e,catalog:t,t:n,systemNotificationPermission:r,onUpdateNode:i,onToggleNotification:a,onOpenChannels:o,onOpenSystemNotificationSettings:s}){let c=[`feishu`,`weixin`,`qq`,`telegram`].some(e=>t.notificationTargets[e]?.enabled),l=r==="default"||r===`granted`;return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(U,{variant:`control`,children:[n(`workflows:workflowsPage.notificationTitle`),(0,X.jsx)(H,{value:e.notification.title,onChange:t=>i({notification:{...e.notification,title:t.target.value}}),placeholder:`{{workflow.name}}`})]}),(0,X.jsxs)(U,{variant:`control`,children:[n(`workflows:workflowsPage.notificationContent`),(0,X.jsx)(et,{value:e.notification.content,onChange:t=>i({notification:{...e.notification,content:t.target.value}}),placeholder:`{{inputs.name}} · {{previous.summary}}`})]}),(0,X.jsx)(`strong`,{className:`mt-3 block text-xs font-medium text-content-secondary`,children:n(`workflows:workflowsPage.notificationChannels`)}),!c&&(0,X.jsxs)(it,{className:wr,children:[(0,X.jsx)(xe,{}),(0,X.jsxs)(rt,{children:[n(`workflows:workflowsPage.noExternalNotificationChannelsEnabled`),(0,X.jsx)(V,{type:`button`,variant:`link`,size:`sm`,onClick:o,children:n(`workflows:workflowsPage.openChannelSettings`)})]})]}),(r===`denied`||r===`unsupported`)&&(0,X.jsxs)(it,{className:wr,children:[(0,X.jsx)(xe,{}),(0,X.jsxs)(rt,{children:[n(r===`unsupported`?`workflows:workflowsPage.systemNotificationsUnsupported`:`workflows:workflowsPage.systemNotificationPermissionRequired`),(0,X.jsx)(V,{type:`button`,variant:`link`,size:`sm`,onClick:s,children:n(`workflows:workflowsPage.openSystemNotificationSettings`)})]})]}),Object.entries(Sr).map(([i,o])=>{let s=o.Icon,c=i===`browser`?l:!!t.notificationTargets[i]?.enabled;return(0,X.jsxs)(`div`,{className:`toggle-line flex min-h-[34px] items-center justify-between gap-3 border-t border-stroke-soft text-sm max-[650px]:min-h-11 [&>span]:flex [&>span]:items-center [&>span]:gap-2 [&>span]:text-content-secondary`,children:[(0,X.jsxs)(`span`,{children:[(0,X.jsx)(s,{size:15}),Or(i,n)]}),(0,X.jsx)(z,{checked:c&&(i!==`browser`||r===`granted`&&t.notificationTargets.browser.enabled)&&e.notificationTargets.includes(i),disabled:!c,"aria-label":Or(i,n),title:i===`browser`?c?t.notificationTargets.browser.enabled?n(`workflows:workflowsPage.systemNotificationsEnabled`):n(`workflows:workflowsPage.systemNotificationReady`):n(`workflows:workflowsPage.systemNotificationPermissionRequired`):n(c?`workflows:workflowsPage.notificationChannelEnabled`:`workflows:workflowsPage.notificationChannelNotEnabled`),onCheckedChange:()=>void a(i)})]},i)})]})}function jr({edge:e,nodes:t,t:n,onDelete:r}){let i=new Map(t.map(e=>[e.id,e]));return(0,X.jsxs)(`section`,{className:`min-w-0 space-y-3`,children:[(0,X.jsxs)(`div`,{className:`workflow-edge-summary my-2.5 grid grid-cols-[minmax(0,1fr)_auto_minmax(0,1fr)] items-center gap-2 text-sm [&_strong]:truncate [&_strong]:font-medium [&>span]:text-content-faint`,children:[(0,X.jsx)(`strong`,{children:i.get(e.source)?.label||n(`workflows:workflowsPage.unknownNode`)}),(0,X.jsx)(`span`,{children:`→`}),(0,X.jsx)(`strong`,{children:i.get(e.target)?.label||n(`workflows:workflowsPage.unknownNode`)})]}),(0,X.jsx)(`p`,{className:`muted-copy text-xs leading-relaxed text-content-muted`,children:n(`workflows:workflowsPage.pressDeleteOrBackspaceToRemoveThisConnection`)}),(0,X.jsxs)(V,{size:`sm`,variant:`destructive`,onClick:r,children:[(0,X.jsx)(be,{"data-icon":`inline-start`}),n(`workflows:workflowsPage.deleteConnection`)]})]})}function Mr({node:e,inputs:t,selectedEdge:n,catalog:r,t:i,onUpdateNode:a,systemNotificationPermission:o,onToggleNotification:s,onCopy:c,onDelete:l,onOpenChannels:u,onOpenSystemNotificationSettings:d}){let f=(0,G.useRef)(null);return(0,X.jsx)(`section`,{className:`min-w-0 space-y-3`,children:e?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(U,{variant:`control`,children:[i(`workflows:workflowsPage.nodeName`),(0,X.jsx)(H,{value:e.label,onChange:e=>a({label:e.target.value})})]}),[`prompt`,`skill`,`file`,`mcp`].includes(e.kind)&&(0,X.jsxs)(U,{variant:`control`,children:[i(`workflows:workflowsPage.nodeModel`),(0,X.jsxs)(W,{value:e.model?`${e.model.provider}/${e.model.model}`:``,onChange:e=>{let t=r.models.find(t=>`${t.provider}/${t.model}`===e.target.value);a({model:t?{provider:t.provider,model:t.model}:null})},children:[(0,X.jsx)(`option`,{value:``,children:i(`workflows:workflowsPage.inheritWorkflowDefaultModel`)}),r.models.map(e=>(0,X.jsx)(`option`,{value:`${e.provider}/${e.model}`,children:e.label},`${e.provider}/${e.model}`))]})]}),e.kind===`trigger`&&(0,X.jsx)(`p`,{className:Tr,children:i(`workflows:editor.manualTriggerHint`)}),e.kind===`parallel`&&(0,X.jsx)(`p`,{className:Tr,children:i(`workflows:editor.parallelHint`)}),![`trigger`,`parallel`,`condition`,`approval`].includes(e.kind)&&(0,X.jsxs)(`details`,{className:`rounded-md border border-stroke p-3`,children:[(0,X.jsx)(`summary`,{className:`cursor-pointer text-xs font-medium text-content-secondary`,children:i(`workflows:editor.executionSettings`)}),(0,X.jsxs)(`div`,{className:`grid gap-3 pt-3`,children:[(0,X.jsxs)(U,{variant:`control`,children:[i(`workflows:workflowsPage.retryCount`),(0,X.jsx)(H,{type:`number`,min:`0`,max:`3`,value:e.retries,onChange:e=>a({retries:Number(e.target.value)})})]}),(0,X.jsxs)(U,{variant:`control`,children:[i(`workflows:workflowsPage.timeoutMinutes`),(0,X.jsx)(H,{type:`number`,min:`1`,max:`240`,value:e.timeoutMinutes,onChange:e=>a({timeoutMinutes:Number(e.target.value)})})]}),(0,X.jsxs)(U,{variant:`control`,children:[i(`workflows:workflowsPage.failureHandling`),(0,X.jsxs)(W,{value:e.failurePolicy,onChange:e=>a({failurePolicy:e.target.value===`skip`?`skip`:`stop`}),children:[(0,X.jsx)(`option`,{value:`stop`,children:i(`workflows:workflowsPage.stopImmediately`)}),(0,X.jsx)(`option`,{value:`skip`,children:i(`workflows:workflowsPage.skipThisNode`)})]})]})]})]}),Kt(e.kind)&&(0,X.jsx)(rr,{node:e,inputs:t,t:i,onChange:a}),[`prompt`,`skill`,`file`,`mcp`].includes(e.kind)&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(U,{variant:`control`,children:[i(`workflows:workflowsPage.executionMode`),(0,X.jsx)(W,{value:e.executionMode,onChange:e=>a({executionMode:e.target.value}),children:Cr.map(e=>(0,X.jsx)(`option`,{value:e,children:Er(e,i)},e))}),(0,X.jsx)(`small`,{children:Dr(e.executionMode,i)})]}),e.kind===`skill`&&(0,X.jsxs)(U,{variant:`control`,children:[`Skill`,(0,X.jsxs)(W,{value:e.skillName,onChange:e=>a({skillName:e.target.value}),children:[(0,X.jsx)(`option`,{value:``,children:i(`workflows:workflowsPage.chooseSkill`)}),r.skills.map(e=>(0,X.jsx)(`option`,{value:e.name,children:e.name},e.id))]})]}),e.kind===`mcp`&&(0,X.jsxs)(U,{variant:`control`,children:[i(`workflows:workflowsPage.mcpToolNames`),(0,X.jsx)(H,{value:e.requestedToolNames.join(`, `),onChange:e=>a({requestedToolNames:e.target.value.split(`,`).map(e=>e.trim()).filter(Boolean)}),placeholder:`server.tool_name`})]}),(0,X.jsxs)(U,{variant:`control`,children:[i(`workflows:inputs.nodeRules`),(0,X.jsx)(et,{ref:f,value:e.prompt,onChange:e=>a({prompt:e.target.value}),placeholder:i(`workflows:workflowsPage.describeTheWorkTheAgentShouldCompleteInThisNode`)})]}),(0,X.jsxs)(`div`,{className:`space-y-2 py-2`,children:[(0,X.jsx)(`p`,{className:`text-xs leading-relaxed text-content-muted`,children:i(`workflows:inputs.nodeRulesHint`)}),(0,X.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:t.map(t=>(0,X.jsx)(V,{type:`button`,variant:`outline`,size:`xs`,title:i(`workflows:inputs.insertVariable`,{name:t.label}),onClick:()=>{let n=f.current,r=n?.selectionStart??e.prompt.length,i=n?.selectionEnd??r,o=`{{inputs.`+t.name+`}}`;a({prompt:e.prompt.slice(0,r)+o+e.prompt.slice(i)}),requestAnimationFrame(()=>{n?.focus(),n?.setSelectionRange(r+o.length,r+o.length)})},children:(0,X.jsx)(`code`,{children:`{{inputs.`+t.name+`}}`})},t.id))})]}),(0,X.jsxs)(U,{variant:`control`,children:[i(`workflows:workflowsPage.outputFormat`),(0,X.jsxs)(W,{value:e.outputFormat,onChange:e=>a({outputFormat:e.target.value===`json`?`json`:`text`}),children:[(0,X.jsx)(`option`,{value:`text`,children:`Text`}),(0,X.jsx)(`option`,{value:`json`,children:`JSON`})]})]})]}),e.kind===`condition`&&(0,X.jsxs)(`div`,{className:`grid gap-3`,children:[(0,X.jsxs)(U,{variant:`control`,children:[i(`workflows:workflowsPage.dataPath`),(0,X.jsx)(H,{value:e.condition.source,onChange:t=>a({condition:{...e.condition,source:t.target.value}}),placeholder:`inputs.approved`})]}),(0,X.jsxs)(U,{variant:`control`,children:[i(`workflows:workflowsPage.operator`),(0,X.jsx)(W,{value:e.condition.operator,onChange:t=>a({condition:{...e.condition,operator:t.target.value}}),children:[`exists`,`not_exists`,`equals`,`not_equals`,`contains`,`greater_than`,`less_than`].map(e=>(0,X.jsx)(`option`,{value:e,children:e},e))})]}),(0,X.jsxs)(U,{variant:`control`,children:[i(`workflows:workflowsPage.comparisonValue`),(0,X.jsx)(H,{value:String(e.condition.value??``),onChange:t=>a({condition:{...e.condition,value:t.target.value}})})]})]}),e.kind===`notification`&&(0,X.jsx)(Ar,{node:e,catalog:r,t:i,systemNotificationPermission:o,onUpdateNode:a,onToggleNotification:s,onOpenChannels:u,onOpenSystemNotificationSettings:d}),e.kind===`approval`&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(U,{variant:`control`,children:[i(`workflows:workflowsPage.approvalMessage`),(0,X.jsx)(et,{value:e.approval.message,onChange:t=>a({approval:{...e.approval,message:t.target.value}})})]}),(0,X.jsxs)(U,{variant:`control`,children:[i(`workflows:workflowsPage.approvalTimeout`),(0,X.jsx)(H,{type:`number`,min:`1`,max:`10080`,value:e.approval.timeoutMinutes,onChange:t=>a({approval:{...e.approval,timeoutMinutes:Number(t.target.value)}})})]})]}),(0,X.jsxs)(`div`,{className:`mt-4 flex gap-2 max-[650px]:flex-wrap`,children:[(0,X.jsxs)(V,{size:`sm`,variant:`secondary`,onClick:c,children:[(0,X.jsx)(j,{"data-icon":`inline-start`}),i(`workflows:workflowsPage.duplicateNode`)]}),(0,X.jsxs)(V,{size:`sm`,variant:`destructive`,onClick:l,children:[(0,X.jsx)(be,{"data-icon":`inline-start`}),i(`workflows:workflowsPage.deleteNode`)]})]})]}):(0,X.jsx)(`p`,{className:`muted-copy text-xs leading-relaxed text-content-muted`,children:i(n?`workflows:workflowsPage.aConnectionIsCurrentlySelected`:`workflows:workflowsPage.dragNodesFromTheLeftToStartBuildingTheWorkflow`)})})}function Nr({draft:e,catalog:t,selectedNode:n,selectedEdge:r,currentRun:i,language:a,t:o,onUpdateNode:s,systemNotificationPermission:c,onToggleNotification:l,onDeleteEdge:u,onCopyNode:d,onDeleteNode:f,onOpenChannels:p,onOpenSystemNotificationSettings:m,onRunImageNode:h,imageRunBusy:g=!1}){let _=e.edges.filter(e=>e.target===n?.id).map(e=>e.source),v=(i?[i]:[]).find(t=>t.workflowId===e.id&&(n?.kind===`media-input`?!!t.inputs:_.length>0&&_.every(e=>t.nodes?.some(t=>t.id===e&&t.status===`completed`&&t.output)))),y=i;return(0,X.jsxs)(`div`,{className:`detail-stack min-w-0 space-y-5`,children:[r&&(0,X.jsx)(jr,{edge:r,nodes:e.nodes,t:o,onDelete:u}),!r&&(0,X.jsx)(Mr,{node:n,inputs:e.inputs,selectedEdge:r,catalog:t,t:o,onUpdateNode:s,systemNotificationPermission:c,onToggleNotification:l,onCopy:d,onDelete:f,onOpenChannels:p,onOpenSystemNotificationSettings:m}),n&&Kt(n.kind)&&h&&(0,X.jsxs)(`div`,{className:`space-y-2 rounded-md border border-stroke p-3`,children:[(0,X.jsxs)(V,{className:`w-full`,variant:`outline`,disabled:!e.id||!v||g,onClick:()=>{v&&h(n.id,v.id)},children:[(0,X.jsx)(fe,{}),o(`workflows:imageNodes.runNode`)]}),(0,X.jsx)(`p`,{className:`text-xs text-content-muted`,children:o(`workflows:imageNodes.runNodeHint`)})]}),n&&Kt(n.kind)&&(0,X.jsx)(cr,{value:y?.nodes?.find(e=>e.id===n.id)?.output,previousValue:v?.nodes?.find(t=>t.id===e.edges.find(e=>e.target===n.id)?.source)?.output,error:y?.nodes?.find(e=>e.id===n.id)?.error,t:o},n.id),e.id&&i&&(0,X.jsxs)(`details`,{className:`overflow-hidden rounded-md border border-stroke`,children:[(0,X.jsx)(`summary`,{className:`cursor-pointer px-3 py-2 text-sm font-medium hover:bg-surface-subtle focus-visible:-outline-offset-2 max-[650px]:py-3`,children:o(`workflows:workflowsPage.latestRun`)}),(0,X.jsx)(`div`,{className:`border-t border-stroke-soft px-3 py-2.5`,children:(0,X.jsx)(fr,{run:i,language:a,t:o})})]})]})}function Pr({workflowId:e,templateId:t,notify:n,onCreated:r}){let{t:i}=l(),[a,o]=(0,G.useState)(Nn),[s,c]=(0,G.useState)(null),[u,d]=(0,G.useState)(``),[f,p]=(0,G.useState)(``),[m,g]=(0,G.useState)(!0),[_,v]=(0,G.useState)(!1),[y,b]=(0,G.useState)(``),x=(0,G.useRef)(null),S=(0,G.useRef)(new Set),[C,w]=(0,G.useState)(!1),T=(0,G.useRef)(null),E=(0,G.useRef)(!0);(0,G.useEffect)(()=>{let e=S.current;return E.current=!0,v(!1),w(!1),()=>{E.current=!1,T.current?.abort(),T.current=null,e.clear()}},[e,t]);let ee=(0,G.useCallback)((e,t)=>{t?S.current.add(e):S.current.delete(e),E.current&&w(S.current.size>0)},[]),D=!!window.pisperDesktop?.showNotification,[O,k]=(0,G.useState)(()=>D?`checking`:gt()),A=(0,G.useCallback)(async()=>{if(!D){k(gt());return}let e=window.pisperDesktop?.getNotificationStatus;if(!e){k(`granted`);return}try{let t=await e(),n=t?.permission;k(n==="default"||n===`denied`||n===`granted`||n===`checking`||n===`unsupported`?n:t?.supported===!1?`unsupported`:`granted`)}catch{k(`unsupported`)}},[D]),j=(0,G.useCallback)(async n=>{try{let r=await h(`/api/workflows`,{signal:n});if(n.aborted)return;o(r);let a=e===`new`?null:r.workflows.find(t=>t.id===e),s=pn(t),l=a?structuredClone(a):s?_n(s,r.cwd,i):hn(r.cwd,i);c(l),d(e=>l.nodes.some(t=>t.id===e)?e:l.nodes[0]?.id||``),p(``),b(a||e===`new`?``:i(`workflows:workflowsPage.workflowNotFoundABlankEditorWasOpened`))}catch(e){n.aborted||b(Q(e))}finally{n.aborted||g(!1)}},[i,t,e]),M=(0,G.useCallback)(()=>{x.current?.abort();let e=new AbortController;x.current=e,g(!0),b(``),j(e.signal)},[j]);(0,G.useEffect)(()=>(M(),()=>x.current?.abort()),[M]),(0,G.useEffect)(()=>{A();let e=()=>void A();return window.addEventListener(`focus`,e),()=>window.removeEventListener(`focus`,e)},[A]);let N=(0,G.useMemo)(()=>a.runs.filter(e=>e.workflowId===s?.id).sort((e,t)=>Date.parse(t.startedAt)-Date.parse(e.startedAt))[0],[a.runs,s?.id]),P=N?.status===`running`||N?.status===`waiting_approval`;(0,G.useEffect)(()=>{if(!P)return;let e=new AbortController,t=!1,n=window.setInterval(async()=>{if(!t){t=!0;try{let t=await h(`/api/workflows`,{signal:e.signal});e.signal.aborted||o(t)}catch{}finally{t=!1}}},1500);return()=>{e.abort(),window.clearInterval(n)}},[P,e]);let F=(0,G.useMemo)(()=>s?.nodes.find(e=>e.id===u)||null,[s?.nodes,u]),te=(0,G.useMemo)(()=>s?.edges.find(e=>e.id===f)||null,[s?.edges,f]),ne=(0,G.useCallback)(e=>{c(t=>t&&{...t,...e})},[]),I=(0,G.useCallback)(e=>{c(t=>t&&{...t,nodes:t.nodes.map(t=>t.id===u?{...t,...e}:t)})},[u]),re=(0,G.useCallback)(e=>{d(e),p(``)},[]),ie=(0,G.useCallback)(e=>{p(e),d(``)},[]),ae=(0,G.useCallback)(()=>{d(``),p(``)},[]),oe=(0,G.useCallback)((e,t,r=`output`)=>{if(!s||e===t)return;let a=s.nodes.find(e=>e.id===t);if(!a||a.kind===`trigger`){n(i(`workflows:workflowsPage.aTriggerCannotHaveAnUpstreamConnection`),`error`);return}if(s.edges.some(n=>n.source===e&&n.target===t&&n.sourcePort===r)){n(i(`workflows:workflowsPage.thisConnectionAlreadyExists`),`info`);return}if(Qt(s.nodes,s.edges,e,t,r)){n(i(`workflows:workflowsPage.aWorkflowCannotContainCyclicConnections`),`error`);return}let o={id:crypto.randomUUID(),source:e,sourcePort:r,target:t,targetPort:`input`};c(e=>e&&{...e,edges:[...e.edges,o]}),p(o.id),d(``),n(i(`workflows:workflowsPage.connectionCreated`),`info`)},[s,n,i]),se=(0,G.useCallback)(e=>{if(!e.length)return;let t=new Set(e);c(e=>e&&{...e,edges:e.edges.filter(e=>!t.has(e.id))}),p(``),n(i(`workflows:workflowsPage.connectionDeleted`),`info`)},[n,i]),ce=(0,G.useCallback)(()=>{f&&se([f])},[se,f]),le=(0,G.useCallback)(e=>{if(!e.length)return;let t=new Set(e);c(e=>e&&{...e,nodes:e.nodes.filter(e=>!t.has(e.id)),edges:e.edges.filter(e=>!t.has(e.source)&&!t.has(e.target))}),ae(),n(i(`workflows:workflowsPage.nodeDeleted`),`info`)},[ae,n,i]),ue=(0,G.useCallback)((e,t,n)=>{let r=crypto.randomUUID();c(i=>i&&{...i,nodes:[...i.nodes,Z(r,e,t||$t[e],``,n.x,n.y)]}),d(r),p(``)},[]),de=(0,G.useCallback)((e,t)=>{c(n=>n&&{...n,nodes:n.nodes.map(n=>n.id===e&&(n.x!==t.x||n.y!==t.y)?{...n,x:t.x,y:t.y}:n)})},[]),fe=(0,G.useCallback)(()=>{if(!F)return;let e=crypto.randomUUID();c(t=>t&&{...t,nodes:[...t.nodes,{...F,id:e,label:`${F.label} 副本`,x:F.x+25,y:F.y+25}]}),d(e),p(``),n(i(`workflows:workflowsPage.nodeDuplicated`),`info`)},[n,F,i]),pe=(0,G.useCallback)(()=>{F&&le([F.id])},[le,F]),me=(0,G.useCallback)(async e=>{if(!F||F.kind!==`notification`)return;let t=F.notificationTargets;if(e!==`browser`){if(t.includes(e)){I({notificationTargets:t.filter(t=>t!==e)});return}if(!a.notificationTargets[e]?.enabled)return;I({notificationTargets:[...t,e]});return}if(t.includes(e)&&a.notificationTargets.browser.enabled&&O===`granted`){I({notificationTargets:t.filter(t=>t!==e)});return}let r=O;if(D){await A();let e=await window.pisperDesktop?.getNotificationStatus?.();r=e?.permission||(e?.supported===!1?`unsupported`:`granted`)}else if(r=await ht(),k(r),r===`granted`)try{await mt()}catch(e){n(Q(e),`error`);return}if(r!==`granted`){n(i(r===`unsupported`?`workflows:workflowsPage.systemNotificationsUnsupported`:`workflows:workflowsPage.systemNotificationPermissionRequired`),`error`);return}try{let r=await h(`/api/settings/notifications/browser`,{method:`PATCH`,body:JSON.stringify({enabled:!0})});o(e=>({...e,notificationTargets:{...e.notificationTargets,browser:{enabled:r.browser.enabled}}})),I({notificationTargets:t.includes(e)?t:[...t,e]}),n(i(`workflows:workflowsPage.systemNotificationsEnabled`))}catch(e){n(Q(e),`error`)}},[a.notificationTargets,D,n,A,F,O,i,I]),L=(0,G.useCallback)(async(t=`draft`,l=!1)=>{if(!s||!E.current||T.current)return null;if(S.current.size)return n(i(`workflows:inputs.uploading`),`info`),null;let u=_r(s.inputs,i);if(u)return b(u),n(u,`error`),null;v(!0),b(``);let d=new AbortController;T.current=d;try{let u=new Set(Object.entries(a.notificationTargets).filter(([e,t])=>t.enabled&&(e!==`browser`||O===`granted`||O===`checking`)).map(([e])=>e)),f={...s,status:t,notifications:s.notifications.filter(e=>u.has(e)),nodes:s.nodes.map(e=>({...e,notificationTargets:e.notificationTargets.filter(e=>u.has(e))}))},p=s.id?await h(`/api/workflows/${encodeURIComponent(s.id)}`,{method:`PATCH`,body:JSON.stringify(f),signal:d.signal}):await h(`/api/workflows`,{method:`POST`,body:JSON.stringify(f),signal:d.signal});return d.signal.throwIfAborted(),o(p.state),c(e=>e===s?structuredClone(p.workflow):e&&{...e,id:p.workflow.id,revision:p.workflow.revision}),e===`new`&&!l&&r(p.workflow.id,!1),l||n(i(t===`published`?`workflows:workflowsPage.workflowPublished`:`workflows:workflowsPage.workflowDraftSaved`)),p.workflow}catch(e){if(d.signal.aborted)return null;let t=Q(e);return b(t),n(t,`error`),null}finally{T.current===d&&(T.current=null,E.current&&v(!1))}},[a.notificationTargets,s,n,r,O,i,e]),he=(0,G.useCallback)(async(t,a)=>{let c=await L(s?.status||`draft`,!0);if(!c||!E.current)return!1;if(S.current.size)return n(i(`workflows:inputs.uploading`),`info`),!1;let l=new AbortController;T.current=l,v(!0);try{a?await Zn.runNode(c.id,a.nodeId,a.sourceRunId,l.signal):await h(`/api/workflows/${encodeURIComponent(c.id)}/run`,{method:`POST`,body:JSON.stringify({inputs:t}),signal:l.signal}),l.signal.throwIfAborted();let e=await h(`/api/workflows`,{signal:l.signal});return l.signal.throwIfAborted(),o(e),n(i(`workflows:workflowsPage.workflowStarted`)),!0}catch(e){if(l.signal.aborted)return!1;let t=Q(e);return b(t),n(t,`error`),!1}finally{T.current===l&&(T.current=null,E.current&&v(!1)),E.current&&!l.signal.aborted&&e===`new`&&r(c.id,!0)}},[s?.status,n,r,L,i,e]),ge=(0,G.useCallback)(e=>he(e),[he]),_e=(0,G.useCallback)((e,t)=>he(void 0,{nodeId:e,sourceRunId:t}),[he]),ve=(0,G.useCallback)(async()=>{if(!E.current||T.current||!N||![`running`,`waiting_approval`].includes(N.status))return;let e=new AbortController;T.current=e,v(!0);try{await h(`/api/workflow-runs/${encodeURIComponent(N.id)}/stop`,{method:`POST`,body:`{}`,signal:e.signal}),e.signal.throwIfAborted();let t=await h(`/api/workflows`,{signal:e.signal});e.signal.throwIfAborted(),o(t),n(i(`workflows:workflowsPage.stoppingWorkflow`),`info`)}catch(t){if(e.signal.aborted)return;let r=Q(t);b(r),n(r,`error`)}finally{T.current===e&&(T.current=null,E.current&&v(!1))}},[N,n,i]),ye=(0,G.useCallback)(()=>L(`published`),[L]);return{catalog:a,draft:s,selectedNode:F,selectedEdge:te,selectedNodeId:u,selectedEdgeId:f,currentRun:N,loading:m,retryLoad:M,busy:_||C,inputUploadsPending:C,onInputUploadBusy:ee,running:P,error:y,systemNotificationPermission:O,updateDraft:ne,updateNode:I,addEdge:oe,removeEdges:se,removeSelectedEdge:ce,removeNodes:le,addNode:ue,moveNode:de,copyNode:fe,deleteNode:pe,toggleNotification:me,selectNode:re,selectEdge:ie,clearSelection:ae,saveWorkflow:L,runWorkflow:ge,runImageNode:_e,stopWorkflow:ve,publishWorkflow:ye}}function Fr({workflow:e,onClose:t,onRun:n}){let{t:r}=l(),i=(0,G.useId)(),a={id:`task`,name:`task`,label:r(`workflows:inputs.task`),description:r(`workflows:inputs.contextHint`),type:`text`,required:!1,defaultValue:``},o=e.inputs.length?e.inputs:[a],[s,c]=(0,G.useState)(()=>Object.fromEntries(o.map(e=>[e.name,hr(e)]))),[u,d]=(0,G.useState)(!1),[f,p]=(0,G.useState)(``),[m,h]=(0,G.useState)([]),g=(0,G.useRef)(new Set),_=(0,G.useRef)(s);_.current=s;let v=(0,G.useRef)(!0);(0,G.useEffect)(()=>(v.current=!0,()=>{v.current=!1}),[]);let y=(e,t)=>{let n={..._.current,[e]:t};_.current=n,c(n)},b=(0,G.useCallback)((e,t)=>{t?g.current.add(e):g.current.delete(e),v.current&&h([...g.current])},[]),x=(0,G.useRef)(!1),S=async()=>{if(x.current||g.current.size)return;let e=_.current,i=vr(o,e,r);if(i){p(i);return}x.current=!0,d(!0),p(``);try{let i=await n(yr(o,e));if(!v.current)return;i?t():p(r(`workflows:inputs.startFailed`))}catch{v.current&&p(r(`workflows:inputs.startFailed`))}finally{x.current=!1,v.current&&d(!1)}};return(0,X.jsx)(Qe,{open:!0,onOpenChange:e=>{!e&&!x.current&&t()},children:(0,X.jsxs)(Je,{className:`max-h-[85vh] overflow-y-auto supports-[height:100dvh]:max-h-[85dvh] sm:max-w-xl`,showCloseButton:!u,children:[(0,X.jsxs)(Ze,{children:[(0,X.jsx)(Ye,{children:r(`workflows:inputs.runTitle`,{name:e.name})}),(0,X.jsx)(qe,{children:r(`workflows:inputs.runHint`)})]}),(0,X.jsxs)(`form`,{className:`space-y-4`,onSubmit:e=>{e.preventDefault(),S()},children:[mn(e)>0&&(0,X.jsx)(`p`,{className:`rounded-md bg-surface-subtle p-3 text-sm tabular-nums`,children:r(`workflows:imageNodes.requestEstimate`,{count:mn(e)})}),o.map(e=>(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[e.type!==`text`&&e.type!==`image`&&e.type!==`video`&&(0,X.jsxs)(R,{htmlFor:`${i}-${e.id}`,className:`flex items-center gap-1`,children:[e.label,e.required&&(0,X.jsx)(`span`,{className:`text-destructive`,"aria-hidden":`true`,children:`*`})]}),e.type===`boolean`?(0,X.jsx)(z,{id:`${i}-${e.id}`,checked:s[e.name]===!0,disabled:u,onCheckedChange:t=>y(e.name,t)}):e.type===`text`||e.type===`image`||e.type===`video`?(0,X.jsx)(pr,{input:e,value:s[e.name],disabled:u,label:`${e.label}${e.required?` *`:``}`,onBusyChange:b,onChange:t=>y(e.name,t)}):(0,X.jsx)(H,{id:`${i}-${e.id}`,type:e.type===`number`?`number`:`text`,step:e.type===`number`?`any`:void 0,value:String(s[e.name]??``),required:e.required,disabled:u,"aria-describedby":e.description?`${i}-${e.id}-description`:void 0,onChange:t=>y(e.name,t.target.value)}),e.description&&(0,X.jsx)(`p`,{id:`${i}-${e.id}-description`,className:`text-xs leading-relaxed text-muted-foreground`,children:e.description})]},e.id)),f&&(0,X.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:f}),(0,X.jsxs)(Xe,{children:[(0,X.jsx)(V,{type:`button`,variant:`outline`,disabled:u,onClick:()=>{x.current||t()},children:r(`workflows:sprite.cancel`)}),(0,X.jsxs)(V,{type:`submit`,disabled:u||m.length>0,children:[u?(0,X.jsx)(re,{className:`animate-spin`}):(0,X.jsx)(fe,{}),r(`workflows:workflowsPage.run`)]})]})]})]})})}function Ir({message:e}){return e?(0,X.jsxs)(it,{variant:`destructive`,children:[(0,X.jsx)(xe,{}),(0,X.jsx)(rt,{children:e})]}):null}var Lr=`max-[650px]:h-11 pointer-coarse:h-11`;function Rr({notify:e,requestConfirm:t,onBack:i}){let{t:a,language:s}=l(),c=r(),u=ze(`focusSearch`),[d,f]=n(),p=d.get(`view`),m=p===`runs`||p===`templates`?p:`workflows`,h=e=>f(t=>{let n=new URLSearchParams(t);return e===`workflows`?n.delete(`view`):n.set(`view`,e),n}),[g,_]=(0,G.useState)(``),v=Pn({notify:e,requestConfirm:t,query:g}),[y,b]=(0,G.useState)(null),x=(0,G.useRef)(null),S=g.trim().toLocaleLowerCase(),C=S?v.data.runs.filter(e=>`${e.workflowName||e.workflowId}`.toLocaleLowerCase().includes(S)):v.data.runs,w=a(`navigation:navigation.workflows`);return(0,X.jsxs)(lt,{title:w,description:a(`workflows:workflowsPage.lede`),back:i&&{label:a(`navigation:sidebar.features`),ariaLabel:a(`navigation:shell.backToFeaturesLabel`),onBack:i},toolbar:(0,X.jsx)(ut,{search:(0,X.jsx)(at,{id:we,value:g,onValueChange:_,placeholder:a(`navigation:pageHeader.searchPage`,{page:w}),shortcut:u,clearLabel:a(`navigation:more.clearSearch`)}),actions:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(V,{type:`button`,variant:`secondary`,className:`h-9`,onClick:()=>x.current?.click(),children:[(0,X.jsx)(Mt,{}),a(`workflows:workflowsPage.import`)]}),(0,X.jsx)(`input`,{ref:x,hidden:!0,type:`file`,accept:`application/zip,.zip`,onChange:e=>{let t=e.target.files?.[0];e.currentTarget.value=``,t&&v.importWorkflow(t)}}),(0,X.jsxs)(V,{type:`button`,className:`h-9`,onClick:()=>c(o(`new`)),children:[(0,X.jsx)(pe,{}),a(`workflows:workflowsPage.newWorkflow`)]})]}),filters:(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center justify-between gap-x-4 gap-y-2`,children:[(0,X.jsx)(Un,{value:m,t:a,onChange:h}),!v.loading&&(0,X.jsx)(qn,{data:v.data,t:a})]})}),children:[y&&(0,X.jsx)(Fr,{workflow:y,onClose:()=>b(null),onRun:e=>v.runWorkflow(y,e)}),v.loading?(0,X.jsx)(tt,{kind:`loading`,title:a(`workflows:workflowsPage.loadingWorkflows`)}):v.error&&!v.loaded?(0,X.jsx)(tt,{kind:`error`,title:a(`workflows:workflowsPage.loadFailed`),description:v.error,action:(0,X.jsxs)(V,{variant:`secondary`,className:`max-[650px]:h-11`,onClick:()=>void v.reload(),children:[(0,X.jsx)(me,{}),a(`workflows:workflowsPage.retryLoading`)]})}):(0,X.jsxs)(X.Fragment,{children:[v.error&&(0,X.jsx)(`div`,{className:`mt-4`,children:(0,X.jsx)(Ir,{message:v.error})}),m===`workflows`?(0,X.jsx)(Wn,{workflows:v.visibleWorkflows,runs:v.data.runs,busyId:v.busyId,query:g,language:s,t:a,onRun:b,onEdit:e=>c(o(e)),onDuplicate:e=>void v.duplicateWorkflow(e),onExport:e=>void v.exportWorkflow(e),onDelete:e=>void v.removeWorkflow(e)}):m===`runs`?(0,X.jsx)(Gn,{runs:C,busyId:v.busyId,language:s,t:a,onStop:e=>void v.stopRun(e),onRetry:e=>void v.retryRun(e),onApproval:(e,t,n)=>void v.resolveApproval(e,t,n)}):(0,X.jsx)(Kn,{query:g,t:a,onOpenTemplate:e=>c(`${o(`new`)}?template=${encodeURIComponent(e)}`)})]})]})}function zr({title:e,name:t,tools:n,commands:r,onBack:i,t:a}){let o=_();return(0,X.jsxs)(`header`,{"data-workflow-editor-header":!0,"data-focus-region":`header`,"data-window-drag-region":!0,className:`@container/workflow-header flex min-h-[52px] min-w-0 shrink-0 flex-wrap items-center gap-x-2 gap-y-1.5 border-b border-stroke-soft py-2 pr-3 pl-3 [[data-custom-titlebar]_&]:pr-[144px] max-[650px]:pb-2.5 max-[650px]:pt-0`,children:[(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-1 basis-56 items-center gap-1 max-[650px]:basis-0`,"data-window-drag-region":!0,children:[(0,X.jsx)(`nav`,{"aria-label":a(`workflows:workflowsPage.editorNavigation`),className:`flex-none`,children:(0,X.jsxs)(`button`,{type:`button`,"data-back-to-workflows":!0,"aria-label":a(`workflows:workflowsPage.backToWorkflows`),onClick:i,className:`inline-flex h-7 items-center gap-0.5 rounded-[var(--r-sm)] pr-1.5 pl-0.5 text-[13px] text-content-muted transition-colors duration-(--d-fast) hover:bg-surface-hover hover:text-content focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-focus max-[650px]:-ml-1.5 max-[650px]:h-11 max-[650px]:min-w-11 max-[650px]:pr-2 max-[650px]:text-sm max-[650px]:text-content-secondary pointer-coarse:h-11`,children:[(0,X.jsx)(E,{className:`size-4 max-[650px]:size-5`,"aria-hidden":`true`}),(0,X.jsx)(`span`,{children:a(`workflows:workflowsPage.workflows`)})]})}),(0,X.jsx)(`span`,{"aria-hidden":`true`,className:B(`text-content-faint`,o&&`hidden`),children:`/`}),(0,X.jsx)(`h1`,{className:B(`flex-none text-[13px] leading-5 font-medium text-content`,o&&`sr-only`),children:e}),t&&(0,X.jsx)(`p`,{"data-workflow-name":!0,className:`min-w-0 truncate pl-1 text-[13px] text-content-muted max-[650px]:text-sm max-[650px]:text-content`,title:t,children:t})]}),n&&(0,X.jsx)(`div`,{className:`flex flex-none items-center gap-1 max-[650px]:[&_button]:h-11 max-[650px]:[&_button]:min-w-11 max-[650px]:[&_button]:px-2.5 pointer-coarse:[&_button]:h-11`,children:n}),r&&(0,X.jsxs)(X.Fragment,{children:[n&&(0,X.jsx)(`span`,{"aria-hidden":`true`,className:`mx-0.5 h-4 w-px bg-stroke max-[650px]:hidden`}),(0,X.jsx)(`div`,{className:`flex flex-none items-center gap-1.5 max-[650px]:grid max-[650px]:w-full max-[650px]:grid-cols-3 max-[650px]:[&_button]:h-11 pointer-coarse:[&_button]:h-11`,children:r})]})]})}function Br({children:e}){return(0,X.jsx)(`span`,{className:`max-[650px]:sr-only @max-[760px]/workflow-header:sr-only`,children:e})}function Vr({notify:e,registerWorkflowActions:i}){let{t:a,language:c}=l(),u=r(),{workflowId:d=`new`}=t(),[f]=n(),p=(0,G.useCallback)(e=>{u(o(e),{replace:!0})},[u]),m=Pr({workflowId:d,templateId:f.get(`template`),notify:e,onCreated:p}),{busy:h,publishWorkflow:g,runWorkflow:_,running:v,saveWorkflow:y,stopWorkflow:b}=m,[x,S]=(0,G.useState)(!1),[C,w]=(0,G.useState)(!1),[T,E]=(0,G.useState)(null),ee=(0,G.useRef)(null);(0,G.useLayoutEffect)(()=>{let e=ee.current;if(!e)return;let t=()=>E(e.clientWidth>=1e3);t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[m.loading]);let D=(0,G.useCallback)(()=>{!h&&!v&&S(!0)},[h,v]),O=m.draft?!!m.draft.id:d!==`new`;(0,G.useEffect)(()=>i?.({editing:O}),[O,i]);let k=At(a,O)[0],A=()=>u(s.workflows),j=m.running?m.currentRun?.nodes:void 0,M=(0,G.useMemo)(()=>j?new Map(j.map(e=>[e.id,e.status])):void 0,[j]);if(m.loading||!m.draft)return(0,X.jsx)(_t,{variant:`workbench`,children:(0,X.jsxs)(`div`,{className:`workflow-editor-page flex h-full min-h-0 min-w-0 flex-col`,children:[(0,X.jsx)(zr,{title:k,onBack:A,t:a}),m.loading?(0,X.jsx)(tt,{kind:`loading`,title:a(`workflows:workflowsPage.loadingWorkflowEditor`)}):(0,X.jsx)(tt,{kind:`error`,title:a(`workflows:workflowsPage.workflowEditorLoadFailed`),description:m.error,action:(0,X.jsxs)(`div`,{className:`flex flex-wrap justify-center gap-2 max-[650px]:[&>button]:h-11`,children:[(0,X.jsxs)(V,{onClick:m.retryLoad,children:[(0,X.jsx)(me,{className:`size-4`}),a(`workflows:workflowsPage.retryLoading`)]}),(0,X.jsx)(V,{variant:`outline`,onClick:A,children:a(`workflows:workflowsPage.backToWorkflows`)})]})})]})});let N=m.draft,P=(0,X.jsx)(Nr,{draft:N,catalog:m.catalog,selectedNode:m.selectedNode,selectedEdge:m.selectedEdge,currentRun:m.currentRun,onRunImageNode:(e,t)=>{m.runImageNode(e,t)},imageRunBusy:m.busy||m.running,language:c,t:a,systemNotificationPermission:m.systemNotificationPermission,onUpdateNode:m.updateNode,onToggleNotification:m.toggleNotification,onDeleteEdge:m.removeSelectedEdge,onCopyNode:m.copyNode,onDeleteNode:m.deleteNode,onOpenChannels:()=>u(s.channels),onOpenSystemNotificationSettings:()=>{if(window.pisperDesktop?.openNotificationSettings){window.pisperDesktop.openNotificationSettings();return}u(`/config/notifications`)}}),F=m.selectedEdge?a(`workflows:workflowsPage.selectedConnection`):a(`workflows:editor.nodeProperties`);return(0,X.jsx)(_t,{variant:`workbench`,children:(0,X.jsxs)(`div`,{ref:ee,className:`workflow-editor-page @container/workflow flex h-full min-h-0 min-w-0 flex-col`,children:[x&&(0,X.jsx)(Fr,{workflow:N,onClose:()=>S(!1),onRun:_}),(0,X.jsx)(zr,{title:k,name:N.name,onBack:A,t:a,tools:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Dn,{nodeCount:N.nodes.length,t:a,onAddNode:m.addNode}),(0,X.jsxs)(Qe,{children:[(0,X.jsx)($e,{asChild:!0,children:(0,X.jsxs)(V,{variant:`ghost`,size:`sm`,className:Lr,title:a(`workflows:workflowsPage.workflowSettings`),children:[(0,X.jsx)(ve,{}),(0,X.jsx)(Br,{children:a(`workflows:workflowsPage.workflowSettings`)})]})}),(0,X.jsxs)(Je,{className:`sm:max-w-xl`,children:[(0,X.jsxs)(Ze,{children:[(0,X.jsx)(Ye,{children:a(`workflows:workflowsPage.workflowSettings`)}),(0,X.jsx)(qe,{children:a(`workflows:editor.settingsDescription`)})]}),(0,X.jsx)(kr,{draft:N,catalog:m.catalog,t:a,onUpdateDraft:m.updateDraft,onInputUploadBusy:m.onInputUploadBusy})]})]}),T===!1&&(0,X.jsxs)(V,{variant:`ghost`,size:`sm`,className:Lr,title:a(`workflows:editor.nodeProperties`),onClick:()=>w(!0),children:[(0,X.jsx)(le,{}),(0,X.jsx)(Br,{children:a(`workflows:editor.nodeProperties`)})]})]}),commands:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(V,{variant:`outline`,size:`sm`,disabled:h||v,onClick:()=>void y(`draft`),children:[(0,X.jsx)(he,{}),a(`workflows:editor.saveDraft`)]}),(0,X.jsxs)(V,{size:`sm`,disabled:h,onClick:()=>v?void b():D(),children:[v?(0,X.jsx)(ye,{}):(0,X.jsx)(fe,{}),a(v?`workflows:workflowsPage.stop`:`workflows:editor.testRun`)]}),(0,X.jsxs)(V,{variant:`outline`,size:`sm`,disabled:h,onClick:()=>void g(),children:[(0,X.jsx)(L,{}),a(`workflows:editor.publish`)]})]})}),m.error&&(0,X.jsx)(`div`,{className:`shrink-0 px-3 pt-3`,children:(0,X.jsx)(Ir,{message:m.error})}),m.running&&m.currentRun&&(0,X.jsx)(dr,{run:m.currentRun,t:a}),(0,X.jsxs)(`div`,{className:B(`builder-layout grid min-h-0 min-w-0 flex-1 overflow-hidden`,T?`grid-cols-[minmax(0,1fr)_320px]`:`grid-cols-1`),children:[T!==null&&(0,X.jsx)(On,{draft:N,selectedNodeId:m.selectedNodeId,selectedEdgeId:m.selectedEdgeId,nodeStatus:M,t:a,onAddNode:m.addNode,onConnect:m.addEdge,onMoveNode:m.moveNode,onSelectNode:e=>{m.selectNode(e),w(!0)},onSelectEdge:e=>{m.selectEdge(e),w(!0)},onClearSelection:m.clearSelection,onDeleteNodes:m.removeNodes,onDeleteEdges:m.removeEdges}),T&&(0,X.jsxs)(`aside`,{className:`flex min-h-0 min-w-0 flex-col border-l border-stroke-soft bg-panel`,"aria-label":F,children:[(0,X.jsx)(`header`,{className:`flex h-11 shrink-0 items-center border-b border-stroke-soft px-4`,children:(0,X.jsx)(`h2`,{className:`text-sm font-medium`,children:F})}),(0,X.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto overscroll-contain p-4`,children:P})]})]}),T===!1&&(0,X.jsx)(We,{open:C,onOpenChange:w,children:(0,X.jsxs)(Ve,{className:`gap-0 data-[side=right]:w-[min(400px,100vw)] data-[side=right]:sm:max-w-[400px]`,children:[(0,X.jsxs)(Be,{className:`border-b border-stroke-soft pr-12`,children:[(0,X.jsx)(He,{children:F}),(0,X.jsx)(Ue,{className:`sr-only`,children:a(`workflows:editor.inspectorDescription`)})]}),(0,X.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto overscroll-contain p-4`,children:P})]})})]})})}export{Vr as WorkflowBuilder,Rr as WorkflowsPage};
1
+ import{a as e}from"./rolldown-runtime-B0Z9INg1.js";import{f as t,m as n,u as r}from"./vendor-router-CSN_DGvx.js";import{i,r as a}from"./vendor-react-DwNgTV1j.js";import{p as o,r as s}from"./routes-DIeaqWVc.js";import{d as c}from"./i18n-BkTAd6ln.js";import{t as l}from"./use-i18n-D2lZDIiK.js";import{r as u,t as d}from"./useQuery-DdcpUQhO.js";import{a as f,i as p,l as m,t as h,u as g}from"./api-CWaE7hay.js";import{t as _}from"./usePhoneShell-CnoUyYeJ.js";import{t as v}from"./createLucideIcon-Cd-3GVxJ.js";import{t as y}from"./arrow-down-CDGua-ue.js";import{t as b}from"./arrow-up-DST6-qVQ.js";import{t as x}from"./bell-BjONAtgH.js";import{t as S}from"./bot-B3TaBp_T.js";import{t as C}from"./braces-DQcXLGFF.js";import{t as w}from"./check-2vYc6QaP.js";import{t as T}from"./chevron-down-CxtxIjiP.js";import{t as E}from"./chevron-left-BAtyp3_6.js";import{t as ee}from"./chevron-right-C3t2Rckj.js";import{t as D}from"./circle-check-iEdCm3Pw.js";import{n as O,t as k}from"./image-plus-D7bzZog0.js";import{t as A}from"./code-xml-BrUXrBax.js";import{t as j}from"./copy-DHmIFc52.js";import{t as M}from"./download-BCfIiuaL.js";import{t as N}from"./ellipsis-CfGKfbq6.js";import{t as P}from"./file-code-corner-BnE1ljT0.js";import{t as F}from"./file-Bllajneu.js";import{t as te}from"./git-branch-N7LGjtzt.js";import{t as ne}from"./grip-vertical-B__LYT0s.js";import{t as I}from"./image-BY_c3FYU.js";import{t as re}from"./loader-circle-BOwQzHB-.js";import{n as ie,t as ae}from"./send-QxBfLFo-.js";import{n as oe,r as se,t as ce}from"./zap-DZHw5afO.js";import{t as le}from"./panel-right-BSUtqUd8.js";import{t as ue}from"./paperclip-BCXrwYpb.js";import{t as de}from"./pencil-U08v_vV9.js";import{t as fe}from"./play-DNDjDNGn.js";import{t as pe}from"./plus-fQbSqB1n.js";import{t as me}from"./refresh-cw-TbWxTY4K.js";import{t as L}from"./rocket-BgLSjoHY.js";import{t as he}from"./save-CHBB52P8.js";import{t as ge}from"./search-D0mqDaf_.js";import{t as _e}from"./server-BgNvmqwJ.js";import{t as ve}from"./settings-2-CXJjXJS9.js";import{t as ye}from"./square-bHHVTT3G.js";import{t as be}from"./trash-2-CNrPOoPR.js";import{t as xe}from"./triangle-alert-CE1q54ci.js";import{t as Se}from"./workflow-Bg94dy8I.js";import{t as Ce}from"./x-07u4-129.js";import{t as we}from"./more-pages-D_PnxLN0.js";import{c as Te,i as Ee,p as De,r as Oe,t as ke}from"./dropdown-menu-Ds0gD8S8.js";import{t as R}from"./label-CVWjEcfV.js";import{i as Ae,n as je,t as Me}from"./popover-CyHncZuo.js";import{t as Ne}from"./progress-5odAz3B9.js";import{t as Pe}from"./slider-DTmAZl-R.js";import{t as z}from"./switch-D_G8wFhs.js";import{i as Fe,r as Ie,t as Le}from"./tabs-DsgBuvJv.js";import{t as B}from"./utils-C8uzG5AZ.js";import{n as Re,t as V}from"./button-CCcCN8tE.js";import{s as ze}from"./shortcuts-BtoPU0le.js";import{a as Be,n as Ve,o as He,r as Ue,t as We}from"./sheet-BTaIEX4w.js";import{a as Ge}from"./format-DMJQzoZ7.js";import{t as Ke}from"./StatusGlyph-1KgitlUg.js";import{a as qe,i as Je,l as Ye,o as Xe,s as Ze,t as Qe,u as $e}from"./dialog-VGmRGR6P.js";import{t as H}from"./input-CPw-zkYh.js";import{t as et}from"./textarea-DmATpOqT.js";import{n as tt,t as nt}from"./PageState-Cz6vFMXv.js";import{n as rt,t as it}from"./alert-firawb0H.js";import{a as at,i as ot,n as st,o as ct,r as lt,s as ut}from"./FeaturePage-CgoODqI_.js";import{n as U}from"./field-DoLEb0np.js";import{t as W}from"./AppSelect-BD6RAaJ5.js";import{n as dt,r as ft,t as pt}from"./collapsible-Dcoy-qnz.js";import{n as mt,r as ht,t as gt}from"./browser-notifications-DBS0oXqN.js";import{t as _t}from"./PageFrame-DNwGZ-Dz.js";import{a as vt,c as yt,d as bt,f as xt,i as St,l as Ct,n as wt,o as Tt,r as Et,s as Dt,t as Ot,u as kt}from"./vendor-xyflow-hxQFvEHK.js";import{n as At}from"./navigation-DkcKi1_5.js";var jt=v(`clock-3`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 6v6h4`,key:`135r8i`}]]),Mt=v(`file-up`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M12 12v6`,key:`3ahymv`}],[`path`,{d:`m15 15-3-3-3 3`,key:`15xj92`}]]),Nt=v(`pause`,[[`rect`,{x:`14`,y:`3`,width:`5`,height:`18`,rx:`1`,key:`kaeet6`}],[`rect`,{x:`5`,y:`3`,width:`5`,height:`18`,rx:`1`,key:`1wsw3u`}]]),G=e(i(),1),Pt=new Set([`__proto__`,`constructor`,`prototype`]),Ft=/^[A-Za-z_][A-Za-z0-9_]{0,79}$/,K=class extends Error{constructor(e,t=``,n=``){super(e===`workflow_template_unknown`?`工作流模板引用了未知或不可用的变量。`:`工作流输入无效,请检查字段名称、类型和必填值。`),this.code=e,this.inputName=t,this.label=n,this.statusCode=400}};function It(e){if(!e||typeof e!=`object`||Array.isArray(e))throw new K(`workflow_input_type`);return e}function Lt(e){let t=It(e);if(Object.keys(t).some(e=>![`id`,`name`,`mimeType`,`size`].includes(e))||typeof t.id!=`string`||!/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,79}$/.test(t.id)||typeof t.name!=`string`||!t.name.trim()||t.name.length>160||/[\\/]/.test(t.name)||typeof t.mimeType!=`string`||![`image/png`,`image/jpeg`,`image/webp`,`video/mp4`,`video/webm`].includes(t.mimeType)||typeof t.size!=`number`||!Number.isSafeInteger(t.size)||t.size<=0||t.size>(t.mimeType.startsWith(`image/`)?8:64)*1024*1024)throw new K(`workflow_input_type`);return{id:t.id,name:t.name,mimeType:t.mimeType,size:t.size}}function Rt(e,t,n){let r=t==null||typeof t==`string`&&!t.trim();if(n&&r)throw new K(`workflow_input_required`,e.name,e.label);if(r)return e.type===`boolean`?!1:e.type===`image`||e.type===`video`?null:``;if(typeof t==`string`&&t.length>16e3)throw new K(`workflow_input_too_long`,e.name,e.label);if(e.type===`number`){if(typeof t!=`number`&&typeof t!=`string`||typeof t==`string`&&!/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i.test(t.trim())||!Number.isFinite(Number(t)))throw new K(`workflow_input_type`,e.name,e.label);return Number(t)}if(e.type===`boolean`){if(t!==!0&&t!==!1&&t!==`true`&&t!==`false`)throw new K(`workflow_input_type`,e.name,e.label);return t===!0||t===`true`}if(e.type===`image`||e.type===`video`){let n=Lt(t);if(!n.mimeType.startsWith(`${e.type}/`))throw new K(`workflow_input_type`,e.name,e.label);return n}if(typeof t!=`string`)throw new K(`workflow_input_type`,e.name,e.label);return t}function zt(e){if(e===void 0)return[];if(!Array.isArray(e)||e.length>30)throw new K(`workflow_input_invalid_definition`);let t=new Set,n=new Set;return e.map((e,r)=>{let i=It(e),a=i.name;if(typeof a!=`string`||!Ft.test(a)||Pt.has(a))throw new K(`workflow_input_unsafe_name`);let o=i.id===void 0?`input-${r+1}`:i.id,s=i.label===void 0?a:i.label;if(typeof o!=`string`||!o||o.length>80||typeof s!=`string`||!s.trim()||s.length>120||i.description!==void 0&&(typeof i.description!=`string`||i.description.length>300)||i.required!==void 0&&typeof i.required!=`boolean`)throw new K(`workflow_input_invalid_definition`,a);if(t.has(a)||n.has(o))throw new K(`workflow_input_duplicate_name`,a,s);t.add(a),n.add(o);let c=i.type===void 0?`string`:i.type;if(c!==`string`&&c!==`text`&&c!==`number`&&c!==`boolean`&&c!==`image`&&c!==`video`)throw new K(`workflow_input_invalid_definition`,a,s);let l={id:o,name:a,label:s.trim(),type:c,required:i.required===!0,defaultValue:``,description:typeof i.description==`string`?i.description:``};return l.defaultValue=i.defaultValue==null||i.defaultValue===``?c===`image`||c===`video`?null:``:Rt(l,i.defaultValue,!1),l})}function Bt(e,t={}){let n=zt(e),r=It(t),i=n.length?n:[{id:`task`,name:`task`,label:`Task`,type:`text`,required:!1,defaultValue:``,description:``}],a=new Set(i.map(e=>e.name));for(let e of Object.keys(r))if(!a.has(e)||Pt.has(e))throw new K(`workflow_input_unknown`,e);let o={};for(let e of i){if(!n.length&&!Object.hasOwn(r,e.name))continue;let t=Object.hasOwn(r,e.name)?r[e.name]:e.defaultValue;o[e.name]=Rt(e,t,e.required)}return o}var Vt=Object.freeze([`S`,`SW`,`W`,`NW`,`N`,`NE`,`E`,`SE`]);function q(e){return Object.assign(Error(e),{code:e,statusCode:400})}function J(e){if(!e||typeof e!=`object`||Array.isArray(e))throw q(`workflow_image_invalid`);return e}function Y(e,t,n,r){if(e===void 0)return t;if(typeof e!=`number`||!Number.isFinite(e)||e<n||e>r)throw q(`workflow_image_invalid`);return e}function Ht(e,t,n){if(e===void 0)return t;if(typeof e!=`string`||e.length>n)throw q(`workflow_image_invalid`);return e.trim()}function Ut(e={}){let t=J(e),n=t.colors??[],r=t.directions??[`S`],i=t.frameOrder??[],a=t.transforms??[],o=J(t.region??{});if(!Array.isArray(n)||n.length>8||n.some(e=>typeof e!=`string`||!/^#[0-9a-f]{6}$/i.test(e))||!Array.isArray(r)||r.length<1||r.length>8||r.some(e=>!Vt.some(t=>t===e))||new Set(r).size!==r.length||!Array.isArray(i)||i.length>512||i.some(e=>!Number.isSafeInteger(e)||e<0||e>=512)||new Set(i).size!==i.length||!Array.isArray(a)||a.length>512)throw q(`workflow_image_invalid`);let s=t.method??`color`,c=t.align??`bottom-center`;if(s!==`color`&&s!==`model`||c!==`center`&&c!==`bottom-center`&&c!==`none`)throw q(`workflow_image_invalid`);let l=Ht(t.inputName,`reference`,80);if(!/^[a-zA-Z][a-zA-Z0-9_]{0,79}$/.test(l)||[`constructor`,`prototype`,`__proto__`].includes(l))throw q(`workflow_image_invalid`);let u={inputName:l,method:s,colors:n.map(e=>String(e)),tolerance:Y(t.tolerance,24,0,255),softness:Y(t.softness,8,0,64),edgeConnected:t.edgeConnected!==!1,region:{x:Y(o.x,25,0,99),y:Y(o.y,25,0,99),width:Y(o.width,20,1,100),height:Y(o.height,10,1,100)},action:Ht(t.action,`idle`,160),frameCount:Math.round(Y(t.frameCount,4,1,16)),directions:[...r],columns:Math.round(Y(t.columns,4,1,16)),rows:Math.round(Y(t.rows,1,1,16)),durationMs:Math.round(Y(t.durationMs,125,16,1e4)),trim:t.trim!==!1,align:c,padding:Math.round(Y(t.padding,4,0,64)),maxFrameSize:Math.round(Y(t.maxFrameSize,256,16,1024)),frameOrder:i.map(e=>Number(e)),transforms:a.map(e=>{let t=J(e);return{index:Math.round(Y(t.index,0,0,511)),x:Y(t.x,0,-4096,4096),y:Y(t.y,0,-4096,4096),rotation:Y(t.rotation,0,-360,360),scale:Y(t.scale,1,.05,8),opacity:Y(t.opacity,1,0,1),durationMs:Math.round(Y(t.durationMs,125,16,1e4)),enabled:t.enabled!==!1}}),filename:Ht(t.filename,`animation`,100)};if(new Set(u.transforms.map(e=>e.index)).size!==u.transforms.length)throw q(`workflow_image_invalid`);return u}function Wt(e){let t=J(e);if(t.type!==`workflow-images`||t.version!==1||!Array.isArray(t.frames)||t.frames.length>512)throw q(`workflow_image_invalid`);let n={type:`workflow-images`,version:1,frames:t.frames.map(e=>{let t=J(e),n=Lt(t.media);if(!n.mimeType.startsWith(`image/`))throw q(`workflow_image_invalid`);return{media:n,width:Y(t.width,1,1,4096),height:Y(t.height,1,1,4096),durationMs:Y(t.durationMs,125,16,1e4),action:Ht(t.action,``,160),direction:Ht(t.direction,``,16),columns:Y(t.columns,1,1,16),rows:Y(t.rows,1,1,16),frameCount:Y(t.frameCount,1,1,256)}})};if(t.atlas!==void 0){let e=J(t.atlas);if(!Array.isArray(e.frames)||e.frames.length>512)throw q(`workflow_image_invalid`);n.atlas={media:Lt(e.media),width:Y(e.width,1,1,4096),height:Y(e.height,1,1,4096),frames:e.frames.map(e=>{let t=J(e);return{x:Y(t.x,0,0,4096),y:Y(t.y,0,0,4096),width:Y(t.width,1,1,4096),height:Y(t.height,1,1,4096),durationMs:Y(t.durationMs,125,16,1e4),action:Ht(t.action,``,160),direction:Ht(t.direction,``,16)}})}}return n}var Gt=Object.freeze([`media-input`,`media-background`,`media-inpaint`,`media-generate`,`media-frames`,`media-transform`,`media-preview`,`media-export`]);function Kt(e){return typeof e==`string`&&Gt.some(t=>t===e)}var X=a(),qt=({className:e,...t})=>(0,X.jsx)(Et,{className:B(`gap-px overflow-hidden rounded-md border bg-card p-1 shadow-none!`,`[&>button]:rounded-md [&>button]:border-none! [&>button]:bg-transparent! [&>button]:hover:bg-secondary!`,e),...t}),Jt=[`trigger`,`prompt`,`skill`,`file`,`mcp`,`notification`,`condition`,`parallel`,`approval`,...Gt];function Yt(e){return new Map(e.map((e,t)=>[e.id,t]))}function Xt(e=[],t){return e.slice(1).map((n,r)=>{let i=e[r];return{id:t?.(r,i.id,n.id)||`edge-${r}-${i.id}-${n.id}`,source:i.id,sourcePort:`output`,target:n.id,targetPort:`input`}})}function Zt(e=[],t=[]){let n=e.filter(e=>e.enabled!==!1),r=new Set(n.map(e=>e.id)),i=t.filter(e=>r.has(e.source)&&r.has(e.target)),a=new Map(n.map(e=>[e.id,[]])),o=new Map(n.map(e=>[e.id,[]])),s=new Map(n.map(e=>[e.id,0])),c=Yt(n);for(let e of i)a.get(e.target)?.push(e),o.get(e.source)?.push(e),s.set(e.target,(s.get(e.target)||0)+1);let l=n.filter(e=>s.get(e.id)===0),u=[];for(;l.length;){l.sort((e,t)=>c.get(e.id)-c.get(t.id));let e=l.shift();u.push(e);for(let t of o.get(e.id)||[]){let e=(s.get(t.target)||0)-1;s.set(t.target,e),e===0&&l.push(n.find(e=>e.id===t.target))}}let d=n.filter(e=>(a.get(e.id)||[]).length===0),f=d.find(e=>e.kind===`trigger`)||d[0];return{nodes:n,edges:i,incoming:a,outgoing:o,order:u,roots:d,unconnected:n.filter(e=>e.id!==f?.id&&(a.get(e.id)||[]).length===0),invalidTriggerTargets:n.filter(e=>e.kind===`trigger`&&(a.get(e.id)||[]).length>0),hasCycle:u.length!==n.length}}function Qt(e,t,n,r,i=`output`){return Zt(e,[...t,{id:`__candidate__`,source:n,sourcePort:i,target:r,targetPort:`input`}]).hasCycle}var $t={trigger:`触发器`,prompt:`任务`,skill:`Skill`,file:`文件`,mcp:`MCP`,notification:`通知`,condition:`判断`,parallel:`并行`,approval:`审批`,"media-input":`图片输入`,"media-inpaint":`区域修补`,"media-background":`去背景`,"media-generate":`动作生成`,"media-frames":`拆分帧`,"media-transform":`帧处理`,"media-preview":`动画预览`,"media-export":`图集输出`},en=[{kind:`trigger`,label:`手动触发`,Icon:ce},{kind:`prompt`,label:`运行 Prompt`,Icon:S},{kind:`skill`,label:`调用 Skill`,Icon:C},{kind:`file`,label:`读写文件`,Icon:P},{kind:`mcp`,label:`调用 MCP`,Icon:_e},{kind:`condition`,label:`条件分支`,Icon:te},{kind:`parallel`,label:`并行汇合`,Icon:se},{kind:`approval`,label:`人工审批`,Icon:D},{kind:`notification`,label:`发送通知`,Icon:x},{kind:`media-inpaint`,label:`区域修补`,Icon:I},{kind:`media-input`,label:`图片输入`,Icon:I},{kind:`media-background`,label:`去背景`,Icon:I},{kind:`media-generate`,label:`动作生成`,Icon:I},{kind:`media-frames`,label:`拆分帧`,Icon:I},{kind:`media-transform`,label:`帧处理`,Icon:I},{kind:`media-preview`,label:`动画预览`,Icon:I},{kind:`media-export`,label:`图集输出`,Icon:I}];function tn(e,t){return t(e===`media-inpaint`?`workflows:imageNodes.inpaint`:e===`media-input`?`workflows:imageNodes.input`:e===`media-background`?`workflows:imageNodes.background`:e===`media-generate`?`workflows:imageNodes.generate`:e===`media-frames`?`workflows:imageNodes.frames`:e===`media-transform`?`workflows:imageNodes.transform`:e===`media-preview`?`workflows:imageNodes.preview`:e===`media-export`?`workflows:imageNodes.export`:e===`trigger`?`workflows:workflowsPage.triggerNode`:e===`skill`?`workflows:workflowsPage.skillNode`:e===`file`?`workflows:workflowsPage.fileNode`:e===`mcp`?`workflows:workflowsPage.mcpNode`:e===`notification`?`workflows:workflowsPage.notificationNode`:e===`condition`?`workflows:workflowsPage.conditionNode`:e===`parallel`?`workflows:workflowsPage.parallelNode`:e===`approval`?`workflows:workflowsPage.approvalNode`:`workflows:workflowsPage.task`)}function nn(e,t){return Kt(e)?tn(e,t):t(e===`trigger`?`workflows:workflowsPage.manualTrigger`:e===`skill`?`workflows:workflowsPage.callSkill`:e===`file`?`workflows:workflowsPage.readWriteFiles`:e===`mcp`?`workflows:workflowsPage.callMcp`:e===`condition`?`workflows:workflowsPage.conditionBranch`:e===`parallel`?`workflows:workflowsPage.parallelJoin`:e===`approval`?`workflows:workflowsPage.humanApproval`:e===`notification`?`workflows:workflowsPage.sendNotification`:`workflows:workflowsPage.runPrompt`)}function rn(e,t){return t(e===`sprite`?`workflows:imageNodes.templateName`:e===`pr-fix`?`workflows:workflowsPage.prFix`:e===`research`?`workflows:workflowsPage.research`:e===`report`?`workflows:workflowsPage.dailyWeeklyReport`:e===`asset`?`workflows:workflowsPage.assetGeneration`:e===`release`?`workflows:workflowsPage.releasePreparation`:`workflows:workflowsPage.codeReview`)}function an(e,t){return t(e===`sprite`?`workflows:imageNodes.templateDescription`:e===`pr-fix`?`workflows:workflowsPage.prFixDescription`:e===`research`?`workflows:workflowsPage.researchDescription`:e===`report`?`workflows:workflowsPage.reportDescription`:e===`asset`?`workflows:workflowsPage.assetDescription`:e===`release`?`workflows:workflowsPage.releaseDescription`:`workflows:workflowsPage.codeReviewDescription`)}function Z(e,t,n,r,i,a,o={}){return{id:e,kind:t,label:n,prompt:r,x:i,y:a,model:null,executionMode:`full-access`,retries:0,timeoutMinutes:20,failurePolicy:`stop`,enabled:!0,outputFormat:`text`,skillName:``,requestedToolNames:[],condition:{source:`previous`,operator:`exists`,value:``},approval:{message:``,timeoutMinutes:60},notification:{title:``,content:``},notificationTargets:[],...Kt(t)?{image:Ut()}:{},...o}}function on(e){return Xt(e,()=>crypto.randomUUID())}function sn(e){return[{id:`input-task`,name:`task`,label:e?e(`workflows:inputs.task`):`本次任务`,description:e?e(`workflows:inputs.taskHint`):`描述这次运行需要完成的目标。`,type:`text`,required:!0,defaultValue:``},{id:`input-materials`,name:`materials`,label:e?e(`workflows:inputs.materials`):`参考材料`,description:e?e(`workflows:inputs.materialsHint`):`填写文件路径、链接、代码片段或需要处理的内容。`,type:`text`,required:!1,defaultValue:``},{id:`input-constraints`,name:`constraints`,label:e?e(`workflows:inputs.constraints`):`约束与输出要求`,description:e?e(`workflows:inputs.constraintsHint`):`说明范围、格式、禁止操作及验收条件。`,type:`text`,required:!1,defaultValue:``}]}function cn(e){return`${e}\n\n本次任务:{{inputs.task}}\n参考材料:{{inputs.materials}}\n约束与输出要求:{{inputs.constraints}}\n以本次运行输入限定任务范围,节点只规定处理方法;不要把节点示例或工作流名称当作本次任务。`}var ln=[{id:`code-review`,name:`代码审查`,description:`读取 diff → 运行测试 → 生成 review`,Icon:A,nodes:[Z(`review-trigger`,`trigger`,`手动触发`,``,65,45),Z(`review-diff`,`file`,`读取 diff`,`读取当前工作区的 git diff,识别改动范围与高风险文件。`,235,45),Z(`review-test`,`prompt`,`运行检查`,`运行适合当前项目的测试与 lint,记录失败原因。`,405,45),Z(`review-report`,`prompt`,`生成 review`,`结合 diff 和验证结果,输出按严重度排序的代码审查结论。`,235,180),Z(`review-notify`,`notification`,`发送结果`,``,405,180)]},{id:`pr-fix`,name:`PR 修复`,description:`定位失败 → 修改代码 → 回归测试`,Icon:te,nodes:[Z(`fix-trigger`,`trigger`,`手动触发`,``,65,45),Z(`fix-find`,`prompt`,`定位失败`,`检查项目状态与失败信息,定位最可能的根因。`,235,45),Z(`fix-code`,`prompt`,`修改代码`,`修复已定位的问题,保留用户已有改动,不执行破坏性命令。`,405,45),Z(`fix-test`,`prompt`,`回归测试`,`运行针对性测试和构建,确认修复没有引入回归。`,235,180),Z(`fix-notify`,`notification`,`通知结果`,``,405,180)]},{id:`research`,name:`资料调研`,description:`搜索资料 → 提取引用 → 点亮星忆`,Icon:ge,nodes:[Z(`research-trigger`,`trigger`,`手动输入`,``,65,45),Z(`research-search`,`prompt`,`搜索资料`,`围绕工作流描述中的主题检索项目内资料与可用信息源。`,235,45),Z(`research-summary`,`prompt`,`整理引用`,`整理关键结论、证据、限制和下一步建议。`,405,45),Z(`research-memory`,`prompt`,`保存星忆`,`把适合长期保留的结论写入 Agent 记忆。`,320,180)]},{id:`report`,name:`日报周报`,description:`汇总会话 → 生成摘要 → 渠道通知`,Icon:F,nodes:[Z(`report-trigger`,`trigger`,`手动触发`,``,65,45),Z(`report-collect`,`prompt`,`汇总进展`,`汇总当前项目近期完成事项、风险与待办。`,235,45),Z(`report-write`,`prompt`,`生成报告`,`将汇总内容整理为清晰的日报或周报。`,405,45),Z(`report-notify`,`notification`,`渠道通知`,``,320,180)]},{id:`asset`,name:`资产生成`,description:`生成图片 → 存入资产库 → 通知验收`,Icon:I,nodes:[Z(`asset-trigger`,`trigger`,`手动输入`,``,65,45),Z(`asset-generate`,`prompt`,`生成视觉资产`,`根据工作流描述生成需要的视觉资产,并保存生成文件。`,235,45),Z(`asset-check`,`prompt`,`检查产物`,`检查生成资产是否完整、可访问并符合需求。`,405,45),Z(`asset-notify`,`notification`,`通知验收`,``,320,180)]},{id:`release`,name:`发布准备`,description:`版本检查 → changelog → 创建发布单`,Icon:L,nodes:[Z(`release-trigger`,`trigger`,`手动触发`,``,65,45),Z(`release-check`,`prompt`,`版本检查`,`检查工作区、测试、构建和版本信息是否满足发布要求。`,235,45),Z(`release-log`,`prompt`,`生成 changelog`,`根据近期提交和改动生成 changelog 与发布说明。`,405,45),Z(`release-report`,`prompt`,`发布清单`,`生成最终发布检查清单并标记阻塞项。`,320,180)]}].map(e=>({...e,inputs:sn(),nodes:e.nodes.map(e=>[`prompt`,`file`,`skill`,`mcp`].includes(e.kind)?{...e,prompt:cn(e.prompt)}:e)}));function un(){let e=[Z(`sprite-trigger`,`trigger`,`手动触发`,``,0,180),Z(`sprite-source`,`media-input`,`参考图片`,``,180,180)],t=[{id:`sprite-input`,source:`sprite-trigger`,target:`sprite-source`,sourcePort:`output`,targetPort:`input`}];return[{id:`idle`,label:`待机呼吸`,prompt:`Subtle breathing idle cycle. Preserve the reference style; the feet stay planted.`},{id:`walk`,label:`走路`,prompt:`Walking cycle: alternating foot contact, passing pose and opposite contact. Keep the character in place.`},{id:`run`,label:`跑步`,prompt:`Running cycle: contact, compression, passing and flight. Preserve proportions and keep the character in place.`},{id:`attack`,label:`攻击`,prompt:`Attack sequence: anticipation, wind-up, strike and recovery. Use only the equipment visible in the reference.`}].forEach((n,r)=>{let i=r*140,a=[Z(`${n.id}-generate`,`media-generate`,n.label,`${n.prompt}\n{{inputs.task}}`,380,i,{image:Ut({action:n.id,frameCount:4,directions:[...Vt]})}),Z(`${n.id}-background`,`media-background`,`色键去背景`,``,560,i),Z(`${n.id}-frames`,`media-frames`,`拆分连续帧`,``,740,i),Z(`${n.id}-align`,`media-transform`,`裁边与脚底对齐`,``,920,i)];e.push(...a);let o=[`sprite-source`,...a.map(e=>e.id),`sprite-preview`];for(let e=1;e<o.length;e++)t.push({id:`${n.id}-edge-${e}`,source:o[e-1],target:o[e],sourcePort:`output`,targetPort:`input`})}),e.push(Z(`sprite-preview`,`media-preview`,`动画预览`,``,1100,180),Z(`sprite-export`,`media-export`,`输出精灵图集`,``,1280,180)),t.push({id:`sprite-output`,source:`sprite-preview`,target:`sprite-export`,sourcePort:`output`,targetPort:`input`}),{id:`sprite`,name:`游戏精灵图生成`,description:`参考图 → 分方向动作 → 去背景 → 拆帧对齐 → 动画预览 → 图集`,Icon:I,nodes:e,edges:t,inputs:[{id:`sprite-reference`,name:`reference`,type:`image`,required:!0,label:`角色参考图`,description:`上传图片并保留原图风格。`,defaultValue:null},{id:`sprite-task`,name:`task`,type:`text`,required:!1,label:`角色与动作要求`,description:`本次运行的角色特征、动作及其他要求。`,defaultValue:``}]}}var dn=un(),fn=[...ln,dn];function pn(e){return fn.find(t=>t.id===e)}function mn(e){return e.nodes.reduce((e,t)=>e+(t.enabled&&t.kind===`media-generate`?Ut(t.image).directions.length:0),0)}function hn(e=``,t){let n=[Z(crypto.randomUUID(),`trigger`,`手动触发`,``,65,45),Z(crypto.randomUUID(),`prompt`,`运行 Prompt`,cn(`按本次输入完成任务,结合材料执行所需步骤,验证产物并报告结果。`),235,45)];return{id:``,name:`未命名工作流`,description:``,status:`draft`,revision:1,cwd:e,model:null,inputs:sn(t),tags:[],visibility:`private`,notifications:[],nodes:n,edges:on(n)}}function gn(e,t){if(e.kind===`media-generate`){if(e.image?.action===`idle`)return t(`workflows:imageNodes.idle`);if(e.image?.action===`walk`)return t(`workflows:imageNodes.walk`);if(e.image?.action===`run`)return t(`workflows:imageNodes.run`);if(e.image?.action===`attack`)return t(`workflows:imageNodes.attack`)}return nn(e.kind,t)}function _n(e,t=``,n){let r=e.nodes.map(t=>({...structuredClone(t),...e.id===`sprite`&&n?{label:gn(t,n)}:{},id:crypto.randomUUID()})),i=fn.includes(e)?sn(n):[],a=new Map(e.nodes.map((e,t)=>[e.id,r[t].id]));return{...hn(t,n),name:n&&fn.includes(e)?rn(e.id,n):e.name,description:n&&fn.includes(e)?an(e.id,n):e.description,inputs:e.inputs.map(t=>{let r=i.find(e=>e.name===t.name);return{...structuredClone(t),...r?{label:r.label,description:r.description}:{},...e.id===`sprite`&&t.name===`reference`&&n?{label:n(`workflows:imageNodes.reference`),description:n(`workflows:imageNodes.referenceHint`)}:{},id:crypto.randomUUID()}}),nodes:r,edges:e.edges?e.edges.map(e=>({...e,id:crypto.randomUUID(),source:a.get(e.source)??``,target:a.get(e.target)??``})):on(r)}}var vn=new Map(en.map(({kind:e,Icon:t})=>[e,t])),yn=`flow-port size-2.5! rounded-full! border-[1.5px]! border-control! bg-panel! cursor-crosshair after:absolute after:-inset-2 hover:border-focus!`;function bn({status:e}){return e===`running`?(0,X.jsx)(Re,{className:`ml-auto size-3.5`}):e===`completed`?(0,X.jsx)(w,{className:`ml-auto size-3.5 text-success`,strokeWidth:2.25}):e===`failed`?(0,X.jsx)(Ce,{className:`ml-auto size-3.5 text-danger`,strokeWidth:2.25}):e===`waiting_approval`?(0,X.jsx)(jt,{className:`ml-auto size-3.5 text-warning-strong`}):null}function xn({data:e,selected:t}){let n=vn.get(e.kind);return(0,X.jsxs)(`div`,{className:B(`flow-node relative flex w-36 min-h-14 cursor-grab flex-col justify-center gap-0.5 rounded-md border border-stroke bg-panel px-3 py-2 text-left transition-[border-color,box-shadow] duration-(--d-fast) ease-precise [:focus-visible>&]:outline-2 [:focus-visible>&]:outline-offset-2 [:focus-visible>&]:outline-focus`,`type-${e.kind}`,t&&`active border-stroke-strong bg-key shadow-key`,e.status===`running`&&`border-star-border`),children:[t&&(0,X.jsx)(`i`,{"aria-hidden":`true`,className:`absolute inset-y-2 -left-px w-[3px] rounded-r-[3px] bg-star`}),e.kind!==`trigger`&&(0,X.jsx)(St,{id:`input`,className:`${yn} input`,type:`target`,position:xt.Left,title:e.inputLabel,"aria-label":e.inputLabel}),e.kind===`condition`?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(St,{id:`true`,className:`${yn} output condition-true`,type:`source`,position:xt.Right,title:`true`,"aria-label":`true`}),(0,X.jsx)(St,{id:`false`,className:`${yn} output condition-false`,type:`source`,position:xt.Bottom,title:`false`,"aria-label":`false`})]}):(0,X.jsx)(St,{id:`output`,className:`${yn} output`,type:`source`,position:xt.Right,title:e.outputLabel,"aria-label":e.outputLabel}),(0,X.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1.5 text-xs text-content-muted`,children:[n&&(0,X.jsx)(n,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),(0,X.jsx)(`span`,{className:`truncate`,children:e.typeLabel}),(0,X.jsx)(bn,{status:e.status})]}),(0,X.jsx)(`strong`,{className:`truncate text-sm font-medium text-content`,title:e.label,children:e.label})]})}var Sn={workflow:xn};function Cn(e){return typeof e==`string`&&Jt.includes(e)}function wn(e){return e.data.status===`running`?`var(--star)`:`var(--stroke-strong)`}function Tn({nodes:e,edges:t,selectedNodeId:n,selectedEdgeId:r,nodeStatus:i,hint:a,inputLabel:o,outputLabel:s,nodeTypeLabel:c,onAddNode:l,onConnect:u,onMoveNode:d,onSelectNode:f,onSelectEdge:p,onClearSelection:m,onDeleteNodes:h,onDeleteEdges:g}){let{screenToFlowPosition:_}=Ct(),v=(0,G.useMemo)(()=>e.map(e=>({id:e.id,type:`workflow`,position:{x:e.x,y:e.y},selected:e.id===n,data:{kind:e.kind,label:e.label,typeLabel:c(e.kind),inputLabel:o,outputLabel:s,status:i?.get(e.id)}})),[o,i,c,e,s,n]),y=(0,G.useRef)(new Set),b=(0,G.useRef)(new Map),x=(0,G.useRef)(null),[S,C,w]=yt(v);(0,G.useEffect)(()=>{C(e=>{let t=new Map(e.map(e=>[e.id,e])),n=e.length!==v.length,r=v.map(e=>{let r=t.get(e.id);if(!r)return n=!0,e;let i=y.current.has(e.id)?r.position:e.position,a=r.data.kind===e.data.kind&&r.data.label===e.data.label&&r.data.typeLabel===e.data.typeLabel&&r.data.inputLabel===e.data.inputLabel&&r.data.outputLabel===e.data.outputLabel&&r.data.status===e.data.status;return i.x===r.position.x&&i.y===r.position.y&&r.selected===e.selected&&a?r:(n=!0,{...r,position:i,selected:e.selected,data:e.data})});return n?r:e})},[v,C]);let T=(0,G.useCallback)(()=>{x.current=null,b.current.forEach((e,t)=>d(t,e)),b.current.clear()},[d]),E=(0,G.useCallback)((e,t)=>{b.current.set(e,t),x.current??=requestAnimationFrame(T)},[T]);(0,G.useEffect)(()=>()=>{x.current!==null&&cancelAnimationFrame(x.current)},[]);let ee=(0,G.useMemo)(()=>t.map(e=>({id:e.id,source:e.source,sourceHandle:e.sourcePort,target:e.target,targetHandle:e.targetPort,selected:e.id===r,markerEnd:{type:bt.ArrowClosed,width:14,height:14,color:`var(--canvas-edge)`}})),[t,r]),D=(0,G.useCallback)(e=>{!e.source||!e.target||u(e.source,e.target,e.sourceHandle||`output`)},[u]),O=(0,G.useCallback)(e=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`},[]),k=(0,G.useCallback)(e=>{e.preventDefault();let t={};try{t=JSON.parse(e.dataTransfer.getData(`text/plain`)||`{}`)}catch{return}if(!Cn(t.kind))return;let n=_({x:e.clientX,y:e.clientY});l(t.kind,typeof t.label==`string`?t.label:c(t.kind),n)},[c,l,_]);return(0,X.jsxs)(`div`,{className:`workflow-react-flow absolute inset-0`,children:[(0,X.jsxs)(Dt,{nodes:S,edges:ee,nodeTypes:Sn,onNodesChange:w,connectionMode:kt.Strict,deleteKeyCode:[`Backspace`,`Delete`],fitView:!0,fitViewOptions:{padding:.18,minZoom:.6,maxZoom:1,nodes:S.length>8?S.slice(0,3).map(({id:e})=>({id:e})):void 0},minZoom:.15,maxZoom:1.8,snapToGrid:!0,snapGrid:[20,20],panOnDrag:!0,zoomOnDoubleClick:!1,onConnect:D,onNodeClick:(e,t)=>f(t.id),onEdgeClick:(e,t)=>p(t.id),onPaneClick:m,onNodeDragStart:(e,t)=>y.current.add(t.id),onNodeDrag:(e,t)=>E(t.id,t.position),onNodeDragStop:(e,t)=>{y.current.delete(t.id),b.current.delete(t.id),d(t.id,t.position)},onNodesDelete:e=>h(e.map(e=>e.id)),onEdgesDelete:e=>g(e.map(e=>e.id)),onDragOver:O,onDrop:k,children:[(0,X.jsx)(Ot,{variant:wt.Dots,gap:20,size:1,color:`var(--canvas-grid)`}),(0,X.jsx)(vt,{className:`workflow-react-flow-minimap m-3! h-24! w-36! overflow-hidden rounded-md border border-stroke [&_svg]:h-full [&_svg]:w-full @max-[640px]/workflow:hidden`,nodeColor:wn,nodeBorderRadius:4,pannable:!0,zoomable:!0}),(0,X.jsx)(qt,{position:`top-left`,showInteractive:!1,className:`border-stroke bg-panel p-0.5 [&>button]:size-7! [&>button]:rounded-sm! [&>button]:hover:bg-surface-hover! max-[650px]:[&>button]:size-11! pointer-coarse:[&>button]:size-11!`})]}),(0,X.jsx)(`div`,{className:`pointer-events-none absolute bottom-3 left-3 z-[5] hidden max-w-[calc(100%-180px)] text-xs text-content-muted @min-[640px]/workflow:block`,children:a})]})}function En(e){return(0,X.jsx)(Tt,{children:(0,X.jsx)(Tn,{...e})})}function Dn({nodeCount:e,t,onAddNode:n}){let[r,i]=(0,G.useState)(!1),[a,o]=(0,G.useState)(``),s=[{label:t(`workflows:editor.flowNodes`),match:e=>[`trigger`,`condition`,`parallel`,`approval`].includes(e)},{label:t(`workflows:editor.agentNodes`),match:e=>[`prompt`,`skill`,`file`,`mcp`,`notification`].includes(e)},{label:t(`workflows:editor.imageNodes`),match:Kt}],c=en.filter(({kind:e})=>nn(e,t).toLocaleLowerCase().includes(a.trim().toLocaleLowerCase()));return(0,X.jsxs)(Me,{open:r,onOpenChange:i,children:[(0,X.jsx)(Ae,{asChild:!0,children:(0,X.jsxs)(V,{variant:`outline`,size:`sm`,title:t(`workflows:editor.addNode`),children:[(0,X.jsx)(pe,{}),(0,X.jsx)(`span`,{className:`max-[650px]:sr-only @max-[760px]/workflow-header:sr-only`,children:t(`workflows:editor.addNode`)})]})}),(0,X.jsxs)(je,{align:`end`,className:`w-72 max-w-[calc(100vw-2rem)] p-1.5`,"aria-label":t(`workflows:workflowsPage.nodeLibrary`),children:[(0,X.jsxs)(`div`,{className:`relative`,children:[(0,X.jsx)(ge,{className:`pointer-events-none absolute top-2.5 left-2.5 size-4 text-content-muted`}),(0,X.jsx)(H,{value:a,onChange:e=>o(e.target.value),className:`pl-8`,placeholder:t(`workflows:editor.searchNodes`),"aria-label":t(`workflows:editor.searchNodes`)})]}),(0,X.jsxs)(`div`,{className:`node-library max-h-[min(420px,60vh)] overflow-y-auto overscroll-contain supports-[height:100dvh]:max-h-[min(420px,60dvh)]`,children:[s.map(r=>{let a=c.filter(({kind:e})=>r.match(e));return a.length===0?null:(0,X.jsxs)(`section`,{className:`py-1`,children:[(0,X.jsx)(`h3`,{className:`px-2 py-1.5 text-xs font-medium text-content-muted`,children:r.label}),a.map(({kind:r,Icon:a})=>(0,X.jsxs)(`button`,{type:`button`,draggable:!0,className:`flex min-h-[30px] w-full cursor-grab items-center gap-2 rounded-sm px-2 text-left text-sm text-content transition-colors duration-(--d-fast) hover:bg-surface-hover focus-visible:-outline-offset-2 max-[650px]:min-h-11 pointer-coarse:min-h-11`,onClick:()=>{n(r,nn(r,t),{x:160+e%4*180,y:100+Math.floor(e/4)*100}),i(!1)},onDragStart:e=>e.dataTransfer.setData(`text/plain`,JSON.stringify({kind:r,label:nn(r,t)})),onDragEnd:()=>i(!1),children:[(0,X.jsx)(a,{className:`size-4 shrink-0 text-content-muted`}),(0,X.jsx)(`span`,{className:`flex-1`,children:nn(r,t)}),(0,X.jsx)(ne,{className:`size-3.5 text-content-faint`,"aria-hidden":`true`})]},r))]},r.label)}),c.length===0&&(0,X.jsx)(`p`,{className:`p-3 text-xs text-content-muted`,children:t(`workflows:editor.noMatchingNodes`)})]})]})]})}function On({draft:e,selectedNodeId:t,selectedEdgeId:n,nodeStatus:r,t:i,onAddNode:a,onConnect:o,onMoveNode:s,onSelectNode:c,onSelectEdge:l,onClearSelection:u,onDeleteNodes:d,onDeleteEdges:f}){return(0,X.jsx)(`section`,{className:`builder-canvas relative h-full min-h-0 min-w-0 overflow-hidden bg-panel`,"aria-label":i(`workflows:editor.canvas`),children:(0,X.jsx)(En,{nodes:e.nodes,edges:e.edges,selectedNodeId:t,selectedEdgeId:n,nodeStatus:r,hint:i(`workflows:workflowsPage.dragFromANodeOutputToTheTargetInputToConnectThem`),inputLabel:i(`workflows:workflowsPage.inputPort`),outputLabel:i(`workflows:workflowsPage.outputPort`),nodeTypeLabel:e=>tn(e,i),onAddNode:a,onConnect:o,onMoveNode:s,onSelectNode:c,onSelectEdge:l,onClearSelection:u,onDeleteNodes:d,onDeleteEdges:f})})}function kn(e){if(e.size>134217728)throw new g(`Workflow package exceeds 128 MiB`,{kind:`protocol`,data:{code:`workflow_bundle_too_large`}})}function An(e){return e instanceof g&&e.data?.code===`workflow_bundle_too_large`}function jn(e,t){return p(`/api/workflows/${encodeURIComponent(e)}/bundle`,{signal:t,timeout:12e4})}async function Mn(e,t){return kn(e),f(`/api/workflows/import-bundle`,{method:`POST`,data:e,signal:t,timeout:12e4,parse:e=>{if(!e||typeof e!=`object`||!(`workflow`in e))throw m();let t=e.workflow;if(!t||typeof t!=`object`||!(`id`in t)||typeof t.id!=`string`)throw m()}})}var Nn={workflows:[],runs:[],limits:{maxConcurrent:4,running:0},notificationTargets:{browser:{enabled:!1},feishu:{enabled:!1},weixin:{enabled:!1},qq:{enabled:!1},telegram:{enabled:!1}},models:[],skills:[],cwd:``};function Q(e){let t=e instanceof g?e.data?.code:typeof e==`string`?e:e&&typeof e==`object`&&`code`in e?e.code:``;return t===`workflow_image_source_stale`?c(`workflows:imageNodes.sourceStale`):t===`workflow_image_source_required`?c(`workflows:imageNodes.sourceRequired`):t===`workflow_image_engine_missing`?c(`workflows:imageNodes.engineMissing`):t===`workflow_image_generation_failed`?c(`workflows:imageNodes.generationFailed`):t===`workflow_image_too_large`?c(`workflows:imageNodes.tooLarge`):t===`workflow_image_timeout`?c(`workflows:imageNodes.timeout`):typeof t==`string`&&t.startsWith(`workflow_image_`)?c(`workflows:imageNodes.invalidOutput`):e instanceof Error?e.message:String(e)}function Pn({notify:e,requestConfirm:t,query:n}){let{t:r}=l(),[i,a]=(0,G.useState)(Nn),[o,s]=(0,G.useState)(`all`),[c,u]=(0,G.useState)(!0),[d,f]=(0,G.useState)(!1),[p,m]=(0,G.useState)(``),[g,_]=(0,G.useState)(``),v=(0,G.useRef)(null);(0,G.useEffect)(()=>()=>v.current?.abort(),[]);let y=(0,G.useCallback)(async()=>{try{a(await h(`/api/workflows`)),f(!0),_(``)}catch(e){_(Q(e))}finally{u(!1)}},[]);(0,G.useEffect)(()=>{y()},[y]),(0,G.useEffect)(()=>{let e=window.setInterval(()=>{y()},i.limits.running?1500:8e3);return()=>window.clearInterval(e)},[i.limits.running,y]);let b=(0,G.useCallback)(e=>i.runs.filter(t=>t.workflowId===e).sort((e,t)=>Date.parse(t.startedAt)-Date.parse(e.startedAt))[0],[i.runs]),x=(0,G.useMemo)(()=>i.workflows.filter(e=>{let t=b(e.id);return`${e.name} ${e.description}`.toLowerCase().includes(n.toLowerCase())?o===`running`?t?.status===`running`:o===`failed`?t?.status===`failed`:o===`draft`?e.status===`draft`:o!==`presets`:!1}),[i.workflows,o,b,n]),S=(0,G.useCallback)(async(t,n={})=>{m(t.id),_(``);try{return await h(`/api/workflows/${encodeURIComponent(t.id)}/run`,{method:`POST`,body:JSON.stringify({inputs:n})}),await y(),e(r(`workflows:workflowsPage.workflowStarted`)),!0}catch(t){let n=Q(t);return _(n),e(n,`error`),!1}finally{m(``)}},[y,e,r]),C=(0,G.useCallback)(async t=>{m(t.id),_(``);try{await h(`/api/workflow-runs/${encodeURIComponent(t.id)}/stop`,{method:`POST`,body:`{}`}),await y(),e(r(`workflows:workflowsPage.stoppingWorkflow`),`info`)}catch(t){let n=Q(t);_(n),e(n,`error`)}finally{m(``)}},[y,e,r]),w=(0,G.useCallback)(async t=>{m(t.id);try{await h(`/api/workflow-runs/${encodeURIComponent(t.id)}/retry`,{method:`POST`,body:`{}`}),await y(),e(r(`workflows:workflowsPage.workflowStarted`))}catch(t){let n=Q(t);_(n),e(n,`error`)}finally{m(``)}},[y,e,r]),T=(0,G.useCallback)(async(t,n,r)=>{m(n);try{await h(`/api/workflow-runs/${encodeURIComponent(t.id)}/approvals/${encodeURIComponent(n)}`,{method:`POST`,body:JSON.stringify({approved:r})}),await y()}catch(t){let n=Q(t);_(n),e(n,`error`)}finally{m(``)}},[y,e]),E=(0,G.useCallback)(async t=>{m(t.id);try{await h(`/api/workflows/${encodeURIComponent(t.id)}/duplicate`,{method:`POST`,body:`{}`}),await y(),e(r(`workflows:workflowsPage.workflowDuplicated`))}catch(t){let n=Q(t);_(n),e(n,`error`)}finally{m(``)}},[y,e,r]),ee=(0,G.useCallback)(async t=>{if(v.current)return;let n=new AbortController;v.current=n,m(t.id);try{let e=await jn(t.id,n.signal);if(n.signal.aborted)return;let r=URL.createObjectURL(e),i=document.createElement(`a`);i.href=r,i.download=`${t.name.replace(/[\\/:*?"<>|]/g,`-`)}.pisper-workflow.zip`,i.click(),window.setTimeout(()=>URL.revokeObjectURL(r),1e3)}catch{n.signal.aborted||e(r(`workflows:workflowsPage.packageFailed`),`error`)}finally{v.current=null,n.signal.aborted||m(``)}},[e,r]),D=(0,G.useCallback)(async t=>{if(v.current)return;let n=new AbortController;v.current=n,m(`import`);try{if(await Mn(t,n.signal),n.signal.aborted||(await y(),n.signal.aborted))return;e(r(`workflows:workflowsPage.workflowImported`))}catch(t){if(n.signal.aborted)return;let i=An(t)?r(`workflows:workflowsPage.packageTooLarge`):r(`workflows:workflowsPage.packageFailed`);_(i),e(i,`error`)}finally{v.current=null,n.signal.aborted||m(``)}},[y,e,r]),O=(0,G.useCallback)(async n=>{if(await t?.({title:r(`workflows:workflowsPage.deleteWorkflow`),message:r(`workflows:workflowsPage.deleteWorkflowNameAndItsRunHistory`,{name:n.name}),confirmLabel:r(`workflows:workflowsPage.delete`),tone:`danger`})){m(n.id);try{await h(`/api/workflows/${encodeURIComponent(n.id)}`,{method:`DELETE`}),await y(),e(r(`workflows:workflowsPage.workflowDeleted`))}catch(t){let n=Q(t);_(n),e(n,`error`)}finally{m(``)}}},[y,e,t,r]);return{data:i,filter:o,setFilter:s,loading:c,loaded:d,reload:(0,G.useCallback)(async()=>{u(!0),await y()},[y]),busyId:p,error:g,visibleWorkflows:x,latestRun:b,runWorkflow:S,stopRun:C,retryRun:w,resolveApproval:T,duplicateWorkflow:E,exportWorkflow:ee,importWorkflow:D,removeWorkflow:O}}function Fn(e){return e===`running`?`run`:e===`waiting_approval`?`attention`:e===`completed`?`done`:e===`failed`||e===`interrupted`?`failed`:e===`cancelled`?`stopped`:null}function In({status:e,className:t}){let n=Fn(e);return(0,X.jsx)(`span`,{"aria-hidden":`true`,className:B(`grid size-[18px] flex-none place-items-center rounded-xs`,!n&&`bg-surface-muted`,t),children:n&&(0,X.jsx)(Ke,{status:n,className:`size-3.5`})})}function Ln(e){return e===`running`?`bg-st-run`:e===`waiting_approval`?`bg-st-attn-fill`:e===`completed`?`bg-content-muted`:e===`failed`||e===`interrupted`?`bg-content-secondary`:`bg-stroke-strong`}function Rn({nodes:e,className:t}){return e.length?(0,X.jsx)(`span`,{"aria-hidden":`true`,className:B(`flex h-1 min-w-0 gap-0.5`,t),children:e.map(e=>(0,X.jsx)(`i`,{className:`h-full w-[18px] min-w-0.5 shrink rounded-full ${Ln(e.status)}`},e.id))}):null}function zn({status:e,label:t}){let n=Fn(e);return(0,X.jsxs)(`span`,{"data-run-status":e,className:B(`inline-flex min-w-0 items-center gap-1 whitespace-nowrap`,e===`waiting_approval`?`font-medium text-st-attn`:`text-content-secondary`),children:[n&&(0,X.jsx)(Ke,{status:n,className:`size-3.5`}),(0,X.jsx)(`span`,{className:`min-w-0 truncate`,children:t})]})}function Bn(e){let t=Math.max(0,Math.round((Number(e)||0)/1e3));return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`}function Vn(e,t){return t(e===`running`?`workflows:workflowsPage.running`:e===`waiting_approval`?`workflows:workflowsPage.waitingApproval`:e===`completed`?`workflows:workflowsPage.completed`:e===`failed`?`workflows:workflowsPage.failed`:e===`cancelled`?`workflows:workflowsPage.stopped`:e===`interrupted`?`workflows:workflowsPage.interrupted`:`workflows:workflowsPage.draft`)}var Hn=[`running`,`waiting_approval`];function Un({value:e,onChange:t,t:n}){let r=`min-w-14 flex-none px-3 max-[650px]:flex-1`;return(0,X.jsx)(Le,{value:e,onValueChange:e=>t(e),className:`max-[650px]:w-full`,children:(0,X.jsxs)(Ie,{className:`max-w-full justify-start overflow-x-auto overflow-y-hidden [scrollbar-width:none] max-[650px]:min-h-11 max-[650px]:w-full pointer-coarse:min-h-11 [&::-webkit-scrollbar]:hidden`,children:[(0,X.jsx)(Fe,{className:r,value:`workflows`,children:n(`workflows:workflowsPage.workflows`)}),(0,X.jsx)(Fe,{className:r,value:`runs`,children:n(`workflows:workflowsPage.runHistory`)}),(0,X.jsx)(Fe,{className:r,value:`templates`,children:n(`workflows:workflowsPage.templates`)})]})})}function Wn({workflows:e,runs:t,busyId:n,query:r,language:i,t:a,onRun:o,onEdit:s,onDuplicate:c,onExport:l,onDelete:u}){let d=e=>t.filter(t=>t.workflowId===e).sort((e,t)=>Date.parse(t.startedAt)-Date.parse(e.startedAt))[0],f=e.filter(e=>e.status===`published`).length;return(0,X.jsx)(ct,{title:a(`workflows:workflowsPage.workflows`),count:e.length,meta:e.length?a(`workflows:workflowsPage.publishedCount`,{count:f}):void 0,children:e.length?(0,X.jsx)(st,{children:e.map(e=>{let t=d(e.id),r=Hn.includes(t?.status||``),f=r||n===e.id;return(0,X.jsx)(ot,{"data-workflow-id":e.id,icon:(0,X.jsx)(Se,{}),name:e.name,nameMeta:`v${e.revision}`,description:e.description||(0,X.jsx)(`span`,{className:`font-mono`,children:e.cwd}),meta:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{children:e.status===`published`?a(`workflows:workflowsPage.published`):a(`workflows:workflowsPage.draft`)}),(0,X.jsx)(`span`,{"aria-hidden":`true`,children:`·`}),(0,X.jsx)(`span`,{className:`truncate`,children:e.visibility===`shared`?a(`workflows:workflowsPage.shared`):a(`workflows:workflowsPage.private`)})]}),status:t?(0,X.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[(0,X.jsx)(zn,{status:t.status,label:Vn(t.status,a)}),(0,X.jsx)(`span`,{className:`whitespace-nowrap`,children:Ge(t.startedAt,i)})]}):a(`workflows:workflowsPage.neverRun`),onOpen:()=>s(e.id),openLabel:`${a(`workflows:workflowsPage.edit`)}: ${e.name}`,actions:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(V,{size:`icon-sm`,variant:`outline`,disabled:f,title:a(`workflows:workflowsPage.run`),"aria-label":`${a(`workflows:workflowsPage.run`)}: ${e.name}`,className:`max-[650px]:size-11 pointer-coarse:size-11`,onClick:()=>o(e),children:n===e.id?(0,X.jsx)(me,{className:`animate-spin`}):(0,X.jsx)(fe,{})}),(0,X.jsxs)(ke,{children:[(0,X.jsx)(De,{asChild:!0,children:(0,X.jsx)(V,{size:`icon-sm`,variant:`ghost`,className:`text-content-muted max-[650px]:size-11 pointer-coarse:size-11`,"aria-label":a(`workflows:workflowsPage.moreActionsFor`,{name:e.name}),children:(0,X.jsx)(N,{})})}),(0,X.jsxs)(Oe,{align:`end`,className:`min-w-44`,children:[(0,X.jsxs)(Ee,{className:`pointer-coarse:min-h-11 max-[650px]:min-h-11`,onSelect:()=>c(e),children:[(0,X.jsx)(j,{}),a(`workflows:workflowsPage.duplicateWorkflow`)]}),(0,X.jsxs)(Ee,{className:`pointer-coarse:min-h-11 max-[650px]:min-h-11`,onSelect:()=>l(e),children:[(0,X.jsx)(M,{}),a(`workflows:workflowsPage.export`)]}),(0,X.jsx)(Te,{}),(0,X.jsxs)(Ee,{className:`pointer-coarse:min-h-11 max-[650px]:min-h-11`,variant:`destructive`,disabled:r,onSelect:()=>u(e),children:[(0,X.jsx)(be,{}),a(`workflows:workflowsPage.delete`)]})]})]})]})},e.id)})}):(0,X.jsx)(nt,{title:a(r?`workflows:workflowsPage.noMatchingWorkflows`:`workflows:workflowsPage.noWorkflowsYet`),description:r?void 0:a(`workflows:workflowsPage.emptyHint`)})})}function Gn({runs:e,busyId:t,language:n,t:r,onStop:i,onRetry:a,onApproval:o}){let s=[...e].sort((e,t)=>Date.parse(t.startedAt)-Date.parse(e.startedAt)),[c,l]=(0,G.useState)(s[0]?.id||``),u=s.filter(e=>e.status===`waiting_approval`).length;return(0,X.jsx)(ct,{title:r(`workflows:workflowsPage.runHistory`),count:s.length,meta:u?(0,X.jsx)(`span`,{className:`font-medium text-st-attn`,children:r(`workflows:workflowsPage.waitingApprovalCount`,{count:u})}):void 0,children:s.length?(0,X.jsx)(st,{children:s.map(e=>{let s=c===e.id,u=Math.round((Number(e.completedNodes)||0)/Math.max(1,Number(e.totalNodes)||1)*100),d=e.workflowName||e.workflowId;return(0,X.jsx)(ot,{"data-workflow-run":e.id,icon:(0,X.jsx)(In,{status:e.status,className:`bg-transparent`}),name:d,nameMeta:`v${e.workflowRevision||1}`,description:(0,X.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[(0,X.jsx)(zn,{status:e.status,label:Vn(e.status,r)}),(0,X.jsx)(`span`,{className:`truncate tabular-nums`,children:Ge(e.startedAt,n)})]}),status:(0,X.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[(0,X.jsx)(`span`,{className:`flex w-24 min-w-0 items-center max-[650px]:hidden`,children:e.nodes?.length?(0,X.jsx)(Rn,{nodes:e.nodes,className:`flex-1`}):(0,X.jsx)(Ne,{value:e.status===`completed`?100:u,className:`h-1 flex-1`})}),(0,X.jsxs)(`span`,{className:`font-mono`,children:[Number(e.completedNodes)||0,`/`,Number(e.totalNodes)||0]}),(0,X.jsx)(`span`,{className:`font-mono`,children:Bn(e.durationMs)})]}),expanded:s,onExpandedChange:t=>l(t?e.id:``),toggleLabel:r(`workflows:workflowsPage.toggleRunDetails`,{name:d}),detail:(0,X.jsxs)(`div`,{className:`workflow-run-detail flex flex-col gap-2.5`,children:[(e.summary||e.error)&&(0,X.jsxs)(`p`,{className:`workflow-run-result flex items-start gap-1.5 text-xs leading-relaxed whitespace-pre-wrap text-content-secondary`,children:[e.error&&(0,X.jsx)(Ke,{status:`failed`,className:`mt-px size-3.5 text-content`}),e.error?Q(e.error):e.summary]}),!!e.nodes?.length&&(0,X.jsx)(`ul`,{className:`divide-y divide-stroke-soft overflow-hidden rounded-[var(--r-md)] border border-stroke`,children:(e.nodes||[]).map(n=>(0,X.jsxs)(`li`,{className:`workflow-run-node grid min-h-[34px] grid-cols-[18px_minmax(0,1fr)_auto] items-center gap-2.5 px-3 py-1.5 max-[650px]:min-h-11 max-[650px]:grid-cols-[18px_minmax(0,1fr)] ${n.status}`,children:[(0,X.jsx)(In,{status:n.status}),(0,X.jsxs)(`span`,{className:`flex min-w-0 flex-col gap-0.5`,children:[(0,X.jsxs)(`span`,{className:`flex min-w-0 items-baseline gap-2`,children:[(0,X.jsx)(`strong`,{className:`truncate text-sm font-medium text-content`,children:n.label}),(0,X.jsx)(`small`,{className:`shrink-0 text-xs text-content-muted tabular-nums`,children:r(`workflows:workflowsPage.countAttempts`,{count:n.attempts||0})})]}),(n.error||n.summary)&&(0,X.jsx)(`p`,{className:`text-xs leading-relaxed whitespace-pre-wrap text-content-muted`,children:n.error?Q(n.error):n.summary})]}),n.status===`waiting_approval`?(0,X.jsxs)(`div`,{className:`workflow-approval-actions flex gap-1.5 max-[650px]:col-span-2 max-[650px]:justify-end`,children:[(0,X.jsxs)(V,{size:`xs`,variant:`outline`,className:`max-[650px]:h-11`,disabled:t===n.id,onClick:()=>o(e,n.id,!1),children:[(0,X.jsx)(O,{"data-icon":`inline-start`}),r(`workflows:workflowsPage.reject`)]}),(0,X.jsxs)(V,{size:`xs`,className:`max-[650px]:h-11`,disabled:t===n.id,onClick:()=>o(e,n.id,!0),children:[(0,X.jsx)(w,{"data-icon":`inline-start`}),r(`workflows:workflowsPage.approve`)]})]}):(0,X.jsx)(`span`,{className:`font-mono text-xs text-content-muted tabular-nums max-[650px]:hidden`,children:n.status===`running`?`…`:Bn(n.durationMs)})]},n.id))}),(0,X.jsx)(`div`,{className:`workflow-run-detail-actions flex gap-1.5 empty:hidden max-[650px]:[&>button]:h-11`,children:Hn.includes(e.status)?(0,X.jsxs)(V,{size:`sm`,variant:`outline`,onClick:()=>i(e),children:[(0,X.jsx)(ye,{"data-icon":`inline-start`}),r(`workflows:workflowsPage.stop`)]}):[`failed`,`cancelled`,`interrupted`].includes(e.status)?(0,X.jsxs)(V,{size:`sm`,variant:`outline`,onClick:()=>a(e),children:[(0,X.jsx)(me,{"data-icon":`inline-start`}),r(`workflows:workflowsPage.retryRun`)]}):null})]})},e.id)})}):(0,X.jsx)(nt,{title:r(`workflows:workflowsPage.noRunHistory`)})})}function Kn({query:e,t,onOpenTemplate:n}){let r=e.trim().toLocaleLowerCase(),i=ln.filter(e=>`${rn(e.id,t)} ${an(e.id,t)}`.toLocaleLowerCase().includes(r));return(0,X.jsx)(ct,{title:t(`workflows:workflowsPage.templates`),count:i.length,description:t(`workflows:workflowsPage.templatesHint`),children:i.length?(0,X.jsx)(st,{className:`workflow-template-gallery`,children:i.map(e=>{let r=e.Icon,i=rn(e.id,t);return(0,X.jsx)(ot,{"data-workflow-template":e.id,icon:(0,X.jsx)(r,{}),name:i,description:an(e.id,t),onOpen:()=>n(e.id),openLabel:t(`workflows:workflowsPage.useTemplate`,{name:i})},e.id)})}):(0,X.jsx)(nt,{title:t(`workflows:workflowsPage.noMatchingTemplates`)})})}function qn({data:e,t}){let n=e.runs.filter(e=>e.status===`failed`).length,r=e.runs.filter(e=>e.status===`waiting_approval`).length,i=e.runs.filter(e=>e.status===`completed`),a=i.length?i.reduce((e,t)=>e+(t.durationMs||0),0)/i.length:0,o=`inline-flex items-baseline gap-1.5 whitespace-nowrap`,s=`text-sm font-medium text-content tabular-nums`;return(0,X.jsxs)(`div`,{className:`workflow-operations-strip flex min-w-0 flex-wrap items-center gap-x-5 gap-y-1 text-xs text-content-muted max-[650px]:w-full max-[650px]:justify-between max-[650px]:gap-x-3`,children:[(0,X.jsxs)(`span`,{className:o,children:[e.limits.running>0&&(0,X.jsx)(Ke,{status:`run`,className:`size-3 self-center text-st-run`}),(0,X.jsx)(`strong`,{className:s,children:e.limits.running}),t(`workflows:workflowsPage.running`)]}),(0,X.jsxs)(`span`,{className:B(o,r>0&&`text-st-attn`),children:[(0,X.jsx)(`strong`,{className:B(s,r>0&&`text-st-attn`),children:r}),t(`workflows:workflowsPage.waitingApproval`)]}),(0,X.jsxs)(`span`,{className:o,children:[(0,X.jsx)(`strong`,{className:s,children:n}),t(`workflows:workflowsPage.failed`)]}),(0,X.jsxs)(`span`,{className:o,children:[(0,X.jsx)(`strong`,{className:B(s,`font-mono`),children:Bn(a)}),t(`workflows:workflowsPage.averageDuration`)]})]})}function Jn({value:e=``,onValueChange:t,files:n=[],onFilesSelected:r,onRemoveFile:i,accept:a=`media`,allowFiles:o=!0,allowText:s=!0,multiple:c=!1,disabled:l=!1,label:u,placeholder:d,attachmentLabel:f,removeLabel:p,children:m,className:h,maxLength:g}){let _=(0,G.useId)(),v=(0,G.useRef)(null),y=a===`image`?`image/png,image/jpeg,image/webp`:a===`video`?`video/mp4,video/webm`:`image/png,image/jpeg,image/webp,video/mp4,video/webm`;return(0,X.jsxs)(`div`,{className:B(`flex min-w-0 flex-col gap-2`,h),children:[(0,X.jsx)(R,{htmlFor:s?`${_}-text`:`${_}-picker`,children:u}),(0,X.jsxs)(`div`,{className:`min-w-0 rounded-md border border-control bg-panel transition-colors duration-[var(--d-fast)] focus-within:border-focus focus-within:ring-3 focus-within:ring-focus-ring`,onDragOver:e=>{o&&e.preventDefault()},onDrop:e=>{o&&(e.preventDefault(),!l&&e.dataTransfer.files.length&&r?.(Array.from(e.dataTransfer.files)))},children:[s&&(0,X.jsx)(et,{id:`${_}-text`,value:e,onChange:e=>t?.(e.target.value),placeholder:d,disabled:l,maxLength:g,className:`min-h-28 resize-y border-0 bg-transparent shadow-none focus-visible:ring-0`}),n.length>0&&(0,X.jsx)(`ul`,{className:B(`grid min-w-0 gap-2 p-3`,n.length>1&&`sm:grid-cols-2`),children:n.map(e=>(0,X.jsxs)(`li`,{className:`relative min-w-0 rounded-md border border-stroke bg-surface-subtle p-2`,children:[e.url&&e.mimeType.startsWith(`image/`)?(0,X.jsx)(`img`,{src:e.url,alt:e.name,className:`h-32 w-full rounded object-contain`}):e.url&&e.mimeType.startsWith(`video/`)?(0,X.jsx)(`video`,{src:e.url,controls:!0,preload:`metadata`,className:`h-32 w-full rounded object-contain`,"aria-label":e.name}):(0,X.jsx)(`div`,{className:`flex h-12 items-center justify-center text-muted-foreground`,children:e.mimeType.startsWith(`video/`)?(0,X.jsx)(oe,{}):(0,X.jsx)(k,{})}),(0,X.jsx)(`p`,{className:`mt-2 truncate pr-8 text-xs`,title:e.name,children:e.name}),i&&(0,X.jsx)(V,{type:`button`,variant:`ghost`,size:`icon-sm`,disabled:l,className:`absolute right-1 bottom-1`,"aria-label":`${p} ${e.name}`,onClick:()=>i(e.id),children:(0,X.jsx)(Ce,{className:`size-3.5`})})]},e.id))}),o&&(0,X.jsxs)(`div`,{className:`p-2`,children:[(0,X.jsx)(`input`,{id:`${_}-picker`,ref:v,className:`sr-only`,type:`file`,accept:y,multiple:c,disabled:l,"aria-label":f,onChange:e=>{let t=Array.from(e.currentTarget.files??[]);e.currentTarget.value=``,t.length&&r?.(t)}}),(0,X.jsxs)(V,{type:`button`,variant:`ghost`,size:`sm`,disabled:l,onClick:()=>v.current?.click(),children:[(0,X.jsx)(ue,{className:`size-4`}),f]})]})]}),m]})}function Yn(e){if(!e||typeof e!=`object`||!(`models`in e)||!Array.isArray(e.models))throw m();return e.models.map(e=>{if(!e||typeof e!=`object`||!(`id`in e)||typeof e.id!=`string`||!(`name`in e)||typeof e.name!=`string`||!(`providerId`in e)||typeof e.providerId!=`string`||!(`providerName`in e)||typeof e.providerName!=`string`||!e.id.startsWith(`${e.providerId}/`))throw m();return{id:e.id,name:e.name,providerId:e.providerId,providerName:e.providerName}})}function Xn(e){if(!e||typeof e!=`object`||!(`started`in e)||e.started!==!0||!(`run`in e)||!e.run||typeof e.run!=`object`||!(`id`in e.run)||typeof e.run.id!=`string`||!(`workflowId`in e.run)||typeof e.run.workflowId!=`string`)throw m();return{started:!0,run:{id:e.run.id,workflowId:e.run.workflowId}}}var Zn={runNode:(e,t,n,r)=>f(`/api/workflows/${encodeURIComponent(e)}/nodes/${encodeURIComponent(t)}/run`,{method:`POST`,data:{sourceRunId:n},signal:r,parse:Xn}),models:e=>f(`/api/workflow-image-models`,{signal:e,parse:Yn})};Object.freeze([{id:`background`,name:`U²-Net small + ONNX Runtime Web`,version:`ort-1.20.1_u2netp-v0.0.0`,licenses:[{name:`ONNX Runtime — MIT`,url:`https://github.com/microsoft/onnxruntime/blob/v1.20.1/LICENSE`},{name:`U²-Net — Apache-2.0`,url:`https://github.com/xuebinqin/U-2-Net/blob/ac7e1c817ecab7c7dff5ce6b1abba61cd213ff29/LICENSE`}],files:[{name:`ort.wasm.min.js`,url:`https://cdn.jsdelivr.net/npm/onnxruntime-web@1.20.1/dist/ort.wasm.min.js`,bytes:49026,sha256:`e66568724f8848e57cc2a56e4bea3a5b86ce3ff81b2da11eac8ed7ab02b27bd4`,mimeType:`text/javascript`},{name:`ort-wasm-simd-threaded.mjs`,url:`https://cdn.jsdelivr.net/npm/onnxruntime-web@1.20.1/dist/ort-wasm-simd-threaded.mjs`,bytes:24618,sha256:`745eb7c0ce6f18a6aa521971b2877babc7ffb27eecb58ab3bc6e5ef4692672e8`,mimeType:`text/javascript`},{name:`ort-wasm-simd-threaded.wasm`,url:`https://cdn.jsdelivr.net/npm/onnxruntime-web@1.20.1/dist/ort-wasm-simd-threaded.wasm`,bytes:11246032,sha256:`207d02be4591c156b0a98f024f3d58005b5b04c92274d759fb390338c63559ea`,mimeType:`application/wasm`},{name:`u2netp.onnx`,url:`https://gh-proxy.com/https://github.com/danielgatis/rembg/releases/download/v0.0.0/u2netp.onnx`,fallbackUrls:[`https://ghfast.top/https://github.com/danielgatis/rembg/releases/download/v0.0.0/u2netp.onnx`],bytes:4574861,sha256:`309c8469258dda742793dce0ebea8e6dd393174f89934733ecc8b14c76f4ddd8`,mimeType:`application/octet-stream`},{name:`LICENSE-ORT.txt`,url:`https://cdn.jsdelivr.net/gh/microsoft/onnxruntime@v1.20.1/LICENSE`,bytes:1073,sha256:`2f07c72751aed99790b8a4869cf2311df85a860b22ded05fa22803587a48922c`,mimeType:`text/plain; charset=utf-8`},{name:`LICENSE-U2NET.txt`,url:`https://cdn.jsdelivr.net/gh/xuebinqin/U-2-Net@ac7e1c817ecab7c7dff5ce6b1abba61cd213ff29/LICENSE`,bytes:11357,sha256:`c71d239df91726fc519c6eb72d318ec65820627232b2f796219e87dcf35d0ab4`,mimeType:`text/plain; charset=utf-8`}]},{id:`inpaint`,name:`OpenCV.js inpainting`,version:`5.0.0-release.1`,licenses:[{name:`OpenCV — Apache-2.0`,url:`https://github.com/opencv/opencv/blob/5.0.0/LICENSE`},{name:`TechStark OpenCV.js — Apache-2.0`,url:`https://github.com/TechStark/opencv-js/blob/v5.0.0-release.1/LICENSE`}],files:[{name:`opencv.js`,url:`https://cdn.jsdelivr.net/npm/@techstark/opencv-js@5.0.0-release.1/dist/opencv.js`,bytes:13298869,sha256:`b873c8211421da7b9bf41ae157a923f05a46a0b8d3e5904c44c6f3ad6d39a1bd`,mimeType:`text/javascript`},{name:`LICENSE-OpenCV.txt`,url:`https://cdn.jsdelivr.net/gh/opencv/opencv@5.0.0/LICENSE`,bytes:11358,sha256:`cfc7749b96f63bd31c3c42b5c471bf756814053e847c10f3eb003417bc523d30`,mimeType:`text/plain; charset=utf-8`},{name:`LICENSE-OpenCV-JS.txt`,url:`https://cdn.jsdelivr.net/gh/TechStark/opencv-js@v5.0.0-release.1/LICENSE`,bytes:11357,sha256:`c71d239df91726fc519c6eb72d318ec65820627232b2f796219e87dcf35d0ab4`,mimeType:`text/plain; charset=utf-8`}]}]);function Qn(e){let t=()=>Error(`Invalid sprite engine catalog`);if(!e||typeof e!=`object`||!(`engines`in e)||!Array.isArray(e.engines)||e.engines.length>2)throw t();let n=e.engines.map(e=>{if(!e||typeof e!=`object`)throw t();let n=e.id,r=e.status;if(n!==`background`&&n!==`inpaint`||![`missing`,`downloading`,`ready`,`failed`].includes(r))throw t();for(let n of[`name`,`version`,`error`])if(typeof e[n]!=`string`||e[n].length>500)throw t();if(e.file!==void 0&&(typeof e.file!=`string`||!/^[a-zA-Z0-9._-]{0,160}$/.test(e.file)))throw t();for(let n of[`bytes`,`received`,`total`])if(!Number.isSafeInteger(e[n])||e[n]<0)throw t();if(e.received>e.total)throw t();return{id:n,name:e.name,version:e.version,bytes:e.bytes,status:r,received:e.received,total:e.total,error:e.error,file:e.file??``}});if(new Set(n.map(e=>e.id)).size!==n.length)throw t();return{engines:n}}var $n=[`workflows`,`sprite-engines`];function er(e){try{return Qn(e)}catch{throw m()}}var tr={catalog:e=>f(`/api/sprite-engines`,{signal:e,parse:er}),download:(e,t)=>f(`/api/sprite-engines/${e}/download`,{method:`POST`,data:{},signal:t,parse:er}),cancel:(e,t)=>f(`/api/sprite-engines/${e}/cancel`,{method:`POST`,data:{},signal:t,parse:er}),remove:(e,t)=>f(`/api/sprite-engines/${e}`,{method:`DELETE`,signal:t,parse:er})};function $({label:e,value:t,min:n,max:r,step:i=1,onChange:a}){return(0,X.jsxs)(U,{variant:`control`,children:[e,(0,X.jsx)(H,{type:`number`,value:t,min:n,max:r,step:i,onChange:e=>{if(!e.target.value)return;let t=e.target.valueAsNumber;Number.isFinite(t)&&a(Math.max(n,Math.min(r,t)))}})]})}function nr({t:e,id:t=`background`}){let n=u(),[r,i]=(0,G.useState)(!1),[a,o]=(0,G.useState)(!1),s=(0,G.useRef)(null);(0,G.useEffect)(()=>()=>s.current?.abort(),[]);let c=d({queryKey:$n,queryFn:({signal:e})=>tr.catalog(e),refetchInterval:e=>e.state.data?.engines.some(e=>e.status===`downloading`)?1e3:!1}),l=c.data?.engines.find(e=>e.id===t),f=async()=>{if(s.current)return;let e=new AbortController;s.current=e,o(!0),i(!1);try{n.setQueryData($n,await tr.download(t,e.signal))}catch{e.signal.aborted||i(!0)}finally{e.signal.aborted||o(!1),s.current===e&&(s.current=null)}};return(0,X.jsxs)(`div`,{className:`space-y-2 rounded-md border p-3 text-xs`,children:[(0,X.jsx)(`p`,{children:e(`workflows:imageNodes.modelHint`)}),(0,X.jsx)(`p`,{children:l?.status===`ready`?e(`workflows:imageNodes.engineReady`):l?.status===`downloading`?e(`workflows:imageNodes.engineDownloading`,{percent:Math.round(l.total?100*l.received/l.total:0)}):e(`workflows:imageNodes.engineMissing`)}),(r||c.isError||l?.status===`failed`)&&(0,X.jsx)(`p`,{role:`alert`,children:e(`workflows:imageNodes.engineFailed`)}),l?.status!==`ready`&&(0,X.jsxs)(V,{size:`sm`,variant:`outline`,disabled:a||l?.status===`downloading`,onClick:()=>void f(),children:[a||l?.status===`downloading`?(0,X.jsx)(re,{className:`animate-spin`}):(0,X.jsx)(M,{}),e(`workflows:imageNodes.download`)]})]})}function rr({node:e,inputs:t,t:n,onChange:r}){let i=Ut(e.image),a=e=>r({image:{...i,...e}}),o=d({queryKey:[`workflows`,`image-models`],queryFn:({signal:e})=>Zn.models(e),enabled:e.kind===`media-generate`}),[s,c]=(0,G.useState)(0);(0,G.useEffect)(()=>c(0),[e.id]);let l=i.transforms.find(e=>e.index===s)??{index:s,x:0,y:0,rotation:0,scale:1,opacity:1,durationMs:i.durationMs,enabled:!0},u=e=>a({transforms:[...i.transforms.filter(e=>e.index!==s),{...l,...e}]}),f=i.frameOrder,p=(e,t)=>{let n=[...f],r=e+t;r<0||r>=n.length||([n[e],n[r]]=[n[r],n[e]],a({frameOrder:n}))};return(0,X.jsxs)(`div`,{className:`my-3 space-y-3 border-y py-3`,children:[e.kind===`media-input`&&(0,X.jsxs)(U,{variant:`control`,children:[n(`workflows:imageNodes.inputField`),(0,X.jsxs)(W,{value:i.inputName,onChange:e=>a({inputName:e.target.value}),children:[!t.some(e=>e.type===`image`&&e.name===i.inputName)&&(0,X.jsx)(`option`,{value:i.inputName,children:n(`workflows:imageNodes.chooseInput`)}),t.filter(e=>e.type===`image`).map(e=>(0,X.jsx)(`option`,{value:e.name,children:e.label},e.id))]}),(0,X.jsx)(`small`,{children:n(`workflows:imageNodes.inputHint`)})]}),e.kind===`media-generate`&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(U,{variant:`control`,children:[n(`workflows:imageNodes.imageModel`),(0,X.jsxs)(W,{value:e.model?`${e.model.provider}/${e.model.model}`:``,onChange:e=>{let t=o.data?.find(t=>t.id===e.target.value);r({model:t?{provider:t.providerId,model:t.id.slice(t.providerId.length+1)}:null})},children:[(0,X.jsx)(`option`,{value:``,children:n(`workflows:imageNodes.defaultImageModel`)}),o.data?.map(e=>(0,X.jsxs)(`option`,{value:e.id,children:[e.providerName,` / `,e.name]},e.id))]}),o.isError&&(0,X.jsx)(`small`,{role:`alert`,children:n(`workflows:imageNodes.modelsFailed`)})]}),(0,X.jsxs)(U,{variant:`control`,children:[n(`workflows:imageNodes.action`),(0,X.jsx)(H,{value:i.action,maxLength:160,onChange:e=>a({action:e.target.value})})]}),(0,X.jsx)(Jn,{label:n(`workflows:imageNodes.prompt`),value:e.prompt,onValueChange:e=>r({prompt:e}),allowFiles:!1,maxLength:16e3,attachmentLabel:n(`workflows:inputs.chooseImage`),removeLabel:n(`workflows:inputs.removeMedia`)}),(0,X.jsx)($,{label:n(`workflows:imageNodes.frameCount`),value:i.frameCount,min:1,max:16,onChange:e=>a({frameCount:e})}),(0,X.jsxs)(`fieldset`,{className:`space-y-2`,children:[(0,X.jsx)(`legend`,{className:`text-sm`,children:n(`workflows:imageNodes.directions`)}),(0,X.jsx)(`div`,{className:`grid grid-cols-4 gap-1`,children:Vt.map(e=>(0,X.jsx)(V,{size:`sm`,variant:i.directions.includes(e)?`secondary`:`outline`,"aria-pressed":i.directions.includes(e),disabled:i.directions.length===1&&i.directions[0]===e,onClick:()=>a({directions:i.directions.includes(e)?i.directions.filter(t=>t!==e):Vt.filter(t=>i.directions.includes(t)||t===e)}),children:e},e))})]}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(`workflows:imageNodes.generateHint`,{count:i.directions.length})})]}),e.kind===`media-background`&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(U,{variant:`control`,children:[n(`workflows:imageNodes.method`),(0,X.jsxs)(W,{value:i.method,onChange:e=>a({method:e.target.value===`model`?`model`:`color`}),children:[(0,X.jsx)(`option`,{value:`color`,children:n(`workflows:imageNodes.colorKey`)}),(0,X.jsx)(`option`,{value:`model`,children:n(`workflows:imageNodes.localModel`)})]})]}),i.method===`model`?(0,X.jsx)(nr,{t:n}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(`p`,{className:`text-sm`,children:n(`workflows:imageNodes.colors`)}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(`workflows:imageNodes.colorsHint`)}),(0,X.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:i.colors.map((e,t)=>(0,X.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,X.jsx)(`input`,{className:`h-8 w-10 cursor-pointer rounded border`,type:`color`,value:e,"aria-label":n(`workflows:imageNodes.colorAt`,{index:t+1}),onChange:e=>a({colors:i.colors.map((n,r)=>r===t?e.target.value:n)})}),(0,X.jsx)(V,{size:`icon-xs`,variant:`ghost`,"aria-label":n(`workflows:imageNodes.removeColor`),onClick:()=>a({colors:i.colors.filter((e,n)=>n!==t)}),children:(0,X.jsx)(be,{})})]},t))}),(0,X.jsxs)(V,{size:`sm`,variant:`outline`,disabled:i.colors.length>=8,onClick:()=>a({colors:[...i.colors,`#00ff00`]}),children:[(0,X.jsx)(pe,{}),n(`workflows:imageNodes.addColor`)]})]}),(0,X.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,X.jsx)($,{label:n(`workflows:imageNodes.tolerance`),value:i.tolerance,min:0,max:255,onChange:e=>a({tolerance:e})}),(0,X.jsx)($,{label:n(`workflows:imageNodes.softness`),value:i.softness,min:0,max:64,onChange:e=>a({softness:e})})]}),(0,X.jsxs)(`label`,{className:`flex items-center justify-between gap-3 text-sm`,children:[n(`workflows:imageNodes.edgeConnected`),(0,X.jsx)(z,{checked:i.edgeConnected,onCheckedChange:e=>a({edgeConnected:e})})]})]})]}),e.kind===`media-inpaint`&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(`workflows:imageNodes.regionHint`)}),(0,X.jsx)(nr,{t:n,id:`inpaint`}),(0,X.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,X.jsx)($,{label:n(`workflows:imageNodes.regionX`),value:i.region.x,min:0,max:99,onChange:e=>a({region:{...i.region,x:e}})}),(0,X.jsx)($,{label:n(`workflows:imageNodes.regionY`),value:i.region.y,min:0,max:99,onChange:e=>a({region:{...i.region,y:e}})}),(0,X.jsx)($,{label:n(`workflows:imageNodes.regionWidth`),value:i.region.width,min:1,max:100,onChange:e=>a({region:{...i.region,width:e}})}),(0,X.jsx)($,{label:n(`workflows:imageNodes.regionHeight`),value:i.region.height,min:1,max:100,onChange:e=>a({region:{...i.region,height:e}})})]})]}),e.kind===`media-frames`&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(`workflows:imageNodes.gridHint`)}),(0,X.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,X.jsx)($,{label:n(`workflows:imageNodes.columns`),value:i.columns,min:1,max:16,onChange:e=>a({columns:e})}),(0,X.jsx)($,{label:n(`workflows:imageNodes.rows`),value:i.rows,min:1,max:16,onChange:e=>a({rows:e})})]}),(0,X.jsx)($,{label:n(`workflows:imageNodes.duration`),value:i.durationMs,min:16,max:1e4,onChange:e=>a({durationMs:e})})]}),e.kind===`media-transform`&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`label`,{className:`flex items-center justify-between gap-3 text-sm`,children:[n(`workflows:imageNodes.trim`),(0,X.jsx)(z,{checked:i.trim,onCheckedChange:e=>a({trim:e})})]}),(0,X.jsxs)(U,{variant:`control`,children:[n(`workflows:imageNodes.align`),(0,X.jsxs)(W,{value:i.align,onChange:e=>a({align:e.target.value===`center`?`center`:e.target.value===`none`?`none`:`bottom-center`}),children:[(0,X.jsx)(`option`,{value:`bottom-center`,children:n(`workflows:imageNodes.bottomCenter`)}),(0,X.jsx)(`option`,{value:`center`,children:n(`workflows:imageNodes.center`)}),(0,X.jsx)(`option`,{value:`none`,children:n(`workflows:imageNodes.noAlign`)})]})]}),(0,X.jsx)($,{label:n(`workflows:imageNodes.maxFrameSize`),value:i.maxFrameSize,min:16,max:1024,onChange:e=>a({maxFrameSize:Math.round(e)})}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(`workflows:imageNodes.maxFrameSizeHint`,{size:i.maxFrameSize})}),(0,X.jsx)($,{label:n(`workflows:imageNodes.padding`),value:i.padding,min:0,max:64,onChange:e=>a({padding:e})}),(0,X.jsxs)(`details`,{className:`rounded-md border p-3`,children:[(0,X.jsx)(`summary`,{className:`cursor-pointer text-sm`,children:n(`workflows:imageNodes.frameEdits`)}),(0,X.jsxs)(`div`,{className:`mt-3 space-y-3`,children:[(0,X.jsx)($,{label:n(`workflows:imageNodes.frameNumber`),value:s+1,min:1,max:512,onChange:e=>c(Math.round(e)-1)}),(0,X.jsxs)(`label`,{className:`flex justify-between text-sm`,children:[n(`workflows:imageNodes.frameEnabled`),(0,X.jsx)(z,{checked:l.enabled,onCheckedChange:e=>u({enabled:e})})]}),(0,X.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,X.jsx)($,{label:`X`,value:l.x,min:-4096,max:4096,onChange:e=>u({x:e})}),(0,X.jsx)($,{label:`Y`,value:l.y,min:-4096,max:4096,onChange:e=>u({y:e})}),(0,X.jsx)($,{label:n(`workflows:imageNodes.rotation`),value:l.rotation,min:-360,max:360,onChange:e=>u({rotation:e})}),(0,X.jsx)($,{label:n(`workflows:imageNodes.scale`),value:l.scale,min:.05,max:8,step:.05,onChange:e=>u({scale:e})}),(0,X.jsx)($,{label:n(`workflows:imageNodes.opacity`),value:l.opacity,min:0,max:1,step:.05,onChange:e=>u({opacity:e})}),(0,X.jsx)($,{label:n(`workflows:imageNodes.duration`),value:l.durationMs,min:16,max:1e4,onChange:e=>u({durationMs:e})})]}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(`workflows:imageNodes.orderHint`)}),(0,X.jsx)(V,{size:`sm`,variant:`outline`,disabled:f.includes(s),onClick:()=>a({frameOrder:[...f,s]}),children:n(`workflows:imageNodes.addToOrder`)}),f.map((e,t)=>(0,X.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,X.jsx)(`span`,{className:`mr-auto text-xs`,children:n(`workflows:imageNodes.frameAt`,{index:e+1})}),(0,X.jsx)(V,{size:`icon-xs`,variant:`ghost`,"aria-label":n(`workflows:imageNodes.earlier`),disabled:t===0,onClick:()=>p(t,-1),children:(0,X.jsx)(b,{})}),(0,X.jsx)(V,{size:`icon-xs`,variant:`ghost`,"aria-label":n(`workflows:imageNodes.later`),disabled:t===f.length-1,onClick:()=>p(t,1),children:(0,X.jsx)(y,{})}),(0,X.jsx)(V,{size:`icon-xs`,variant:`ghost`,"aria-label":n(`workflows:imageNodes.resetOrder`),onClick:()=>a({frameOrder:f.filter(t=>t!==e)}),children:(0,X.jsx)(be,{})})]},e))]})]})]}),e.kind===`media-preview`&&(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(`workflows:imageNodes.previewHint`)}),e.kind===`media-export`&&(0,X.jsxs)(U,{variant:`control`,children:[n(`workflows:imageNodes.filename`),(0,X.jsx)(H,{value:i.filename,maxLength:100,onChange:e=>a({filename:e.target.value})}),(0,X.jsx)(`small`,{children:n(`workflows:imageNodes.exportHint`)})]})]})}var ir={upload:(e,t)=>f(`/api/workflow-media?name=${encodeURIComponent(e.name)}`,{method:`POST`,data:e,headers:{"Content-Type":e.type},signal:t,timeout:12e4,parse:e=>{try{return Lt(e)}catch{throw m()}}}),preview:(e,t)=>p(`/api/workflow-media/${encodeURIComponent(e)}/content`,{signal:t})};function ar(e){try{return Wt(e)}catch{return null}}function or(e){let[t,n]=(0,G.useState)({id:``,image:null,error:!1}),r=e?.media.id;return(0,G.useEffect)(()=>{if(n({id:r??``,image:null,error:!1}),!r)return;let e=new AbortController,t=``,i=null;return ir.preview(r,e.signal).then(a=>{if(e.signal.aborted)return;t=URL.createObjectURL(a),i=new Image;let o=i;i.onload=()=>{e.signal.aborted||n({id:r,image:o,error:!1})},i.onerror=()=>{e.signal.aborted||n({id:r,image:null,error:!0})},i.src=t}).catch(()=>{e.signal.aborted||n({id:r,image:null,error:!0})}),()=>{e.abort(),i&&(i.onload=null,i.onerror=null,i.src=``),t&&URL.revokeObjectURL(t)}},[r]),t.id===r?t:{id:r??``,image:null,error:!1}}function sr(e,t){return t(e===`workflow_image_source_stale`?`workflows:imageNodes.sourceStale`:e===`workflow_image_source_required`?`workflows:imageNodes.sourceRequired`:e===`workflow_image_engine_missing`?`workflows:imageNodes.engineMissing`:e===`workflow_image_decode_failed`?`workflows:imageNodes.decodeFailed`:e===`workflow_image_generation_failed`?`workflows:imageNodes.generationFailed`:e===`workflow_image_too_large`?`workflows:imageNodes.tooLarge`:e===`workflow_image_cancelled`?`workflows:imageNodes.cancelled`:e===`workflow_image_timeout`?`workflows:imageNodes.timeout`:`workflows:imageNodes.invalidOutput`)}function cr({value:e,previousValue:t,error:n,t:r}){let i=(0,G.useMemo)(()=>ar(e),[e]),a=(0,G.useMemo)(()=>ar(t),[t]),[o,s]=(0,G.useState)(``),[c,l]=(0,G.useState)(``),[u,d]=(0,G.useState)(0),[f,p]=(0,G.useState)(!1),[m,h]=(0,G.useState)(!1),[g,_]=(0,G.useState)(!1),[v,y]=(0,G.useState)(!1),[b,x]=(0,G.useState)(!1),S=(0,G.useRef)(null),C=(0,G.useRef)(null),w=[...new Set(i?.frames.map(e=>e.action).filter(Boolean)??[])],T=[...new Set(i?.frames.map(e=>e.direction).filter(Boolean)??[])],D=w.includes(o)?o:w[0]??``,O=T.includes(c)?c:T[0]??``,k=(0,G.useMemo)(()=>i?.frames.filter(e=>(!D||e.action===D)&&(!O||e.direction===O))??[],[i,D,O]),A=Math.min(u,Math.max(0,k.length-1)),j=a?.frames.filter(e=>e.action===k[A]?.action&&e.direction===k[A]?.direction),N=j?.[A]??j?.[0]??a?.frames[0],P=or(g?N:k[A]),F=or(m&&!g?k[(A+k.length-1)%k.length]:void 0),te=or(m&&!g?k[(A+1)%k.length]:void 0);(0,G.useEffect)(()=>{d(0),p(!1),_(!1)},[D,O,e]),(0,G.useEffect)(()=>()=>S.current?.abort(),[]),(0,G.useEffect)(()=>{if(!f||k.length<2)return;let e=window.setTimeout(()=>{document.hidden||d((A+1)%k.length)},k[A]?.durationMs??125),t=()=>{document.hidden&&p(!1)};return document.addEventListener(`visibilitychange`,t),()=>{window.clearTimeout(e),document.removeEventListener(`visibilitychange`,t)}},[f,k,A]),(0,G.useEffect)(()=>{let e=C.current?.getContext(`2d`);if(!e)return;e.clearRect(0,0,512,384);let t=[F.image,P.image,te.image].filter(e=>!!e),n=Math.min(1,512/Math.max(1,...t.map(e=>e.naturalWidth)),384/Math.max(1,...t.map(e=>e.naturalHeight)))*.9,r=(t,r)=>{if(!t)return;e.save(),e.imageSmoothingEnabled=!1,e.globalAlpha=r;let i=t.naturalWidth*n,a=t.naturalHeight*n;e.drawImage(t,(512-i)/2,384*.95-a,i,a),e.restore()};r(F.image,.2),r(te.image,.15),r(P.image,1)},[P.image,F.image,te.image]);let ne=async e=>{if(!i||S.current)return;let t=new AbortController;S.current=t,x(!0),y(!1);let n=``;try{let r=e===`atlas`?i.atlas?.media:k[A]?.media,a=e===`json`?new Blob([JSON.stringify(i.atlas??i,null,2)],{type:`application/json`}):r?await ir.preview(r.id,t.signal):null;if(!a||t.signal.aborted)return;n=URL.createObjectURL(a);let o=document.createElement(`a`);o.href=n,o.download=e===`json`?`animation.frames.json`:(r?.name??`animation.png`).replace(/[\\/:*?"<>|\p{Cc}]/gu,`_`),o.click()}catch{t.signal.aborted||y(!0)}finally{n&&URL.revokeObjectURL(n),t.signal.aborted||x(!1),S.current===t&&(S.current=null)}};return!i&&!n?(0,X.jsx)(`p`,{className:`my-3 text-xs text-muted-foreground`,children:r(`workflows:imageNodes.noResult`)}):(0,X.jsxs)(`section`,{className:`my-3 space-y-3 rounded-md border p-3`,"aria-label":r(`workflows:imageNodes.result`),children:[(0,X.jsx)(`h3`,{className:`text-sm font-medium`,children:r(`workflows:imageNodes.result`)}),n&&(0,X.jsx)(`p`,{role:`alert`,className:`text-xs text-muted-foreground`,children:sr(n,r)}),k.length>0&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[w.length>0&&(0,X.jsx)(W,{"aria-label":r(`workflows:imageNodes.action`),value:D,onChange:e=>s(e.target.value),children:w.map(e=>(0,X.jsx)(`option`,{value:e,children:e},e))}),T.length>0&&(0,X.jsx)(W,{"aria-label":r(`workflows:imageNodes.directions`),value:O,onChange:e=>l(e.target.value),children:T.map(e=>(0,X.jsx)(`option`,{value:e,children:e},e))})]}),(0,X.jsxs)(`div`,{className:`relative overflow-hidden rounded-md border bg-[repeating-conic-gradient(var(--surface-active)_0%_25%,var(--surface-muted)_0%_50%)] bg-size-[16px_16px]`,children:[(0,X.jsx)(`canvas`,{width:512,height:384,ref:C,className:`w-full`,role:`img`,"aria-label":r(`workflows:imageNodes.frameAt`,{index:A+1})}),!P.image&&!P.error&&(0,X.jsx)(re,{className:`absolute top-1/2 left-1/2 size-5 animate-spin`})]}),P.error&&(0,X.jsx)(`p`,{role:`alert`,className:`text-xs`,children:r(`workflows:inputs.previewFailed`)}),(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center justify-center gap-1`,children:[(0,X.jsx)(V,{size:`icon-sm`,variant:`outline`,"aria-label":r(`workflows:imageNodes.previousFrame`),disabled:k.length<2,onClick:()=>{p(!1),d((A+k.length-1)%k.length)},children:(0,X.jsx)(E,{})}),(0,X.jsx)(V,{size:`icon-sm`,variant:`outline`,"aria-label":r(f?`workflows:imageNodes.pause`:`workflows:imageNodes.play`),disabled:k.length<2,onClick:()=>p(!f),children:f?(0,X.jsx)(Nt,{}):(0,X.jsx)(fe,{})}),(0,X.jsx)(V,{size:`icon-sm`,variant:`outline`,"aria-label":r(`workflows:imageNodes.nextFrame`),disabled:k.length<2,onClick:()=>{p(!1),d((A+1)%k.length)},children:(0,X.jsx)(ee,{})}),(0,X.jsxs)(`span`,{className:`px-1 text-xs tabular-nums`,children:[A+1,` / `,k.length]})]}),(0,X.jsx)(Pe,{className:`h-7 w-full`,min:0,max:Math.max(0,k.length-1),step:1,value:[A],"aria-label":r(`workflows:imageNodes.frameNumber`),valueText:`${A+1} / ${k.length}`,onValueChange:([e])=>{p(!1),d(e)}}),(0,X.jsxs)(`label`,{className:`flex items-center justify-between text-xs`,children:[r(`workflows:imageNodes.onionSkin`),(0,X.jsx)(z,{checked:m,onCheckedChange:h})]}),N&&(0,X.jsxs)(`label`,{className:`flex items-center justify-between text-xs`,children:[r(`workflows:imageNodes.showInput`),(0,X.jsx)(z,{checked:g,onCheckedChange:_})]}),(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,X.jsxs)(V,{size:`sm`,variant:`outline`,disabled:b,onClick:()=>void ne(`frame`),children:[(0,X.jsx)(M,{}),r(`workflows:imageNodes.saveFrame`)]}),i?.atlas&&(0,X.jsxs)(V,{size:`sm`,variant:`outline`,disabled:b,onClick:()=>void ne(`atlas`),children:[(0,X.jsx)(M,{}),`PNG`]}),(0,X.jsxs)(V,{size:`sm`,variant:`outline`,disabled:b,onClick:()=>void ne(`json`),children:[(0,X.jsx)(M,{}),`JSON`]})]})]}),v&&(0,X.jsx)(`p`,{role:`alert`,className:`text-xs`,children:r(`workflows:imageNodes.downloadFailed`)})]})}function lr(e){return e?e.status===`completed`?100:Math.round((Number(e.completedNodes)||0)/Math.max(1,Number(e.totalNodes)||1)*100):0}function ur(e){let t=Math.max(0,Math.round((Number(e)||0)/1e3));return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`}function dr({run:e,t}){let n=e.status===`waiting_approval`,r=lr(e);return(0,X.jsxs)(`div`,{role:`status`,className:B(`relative flex min-h-9 shrink-0 items-center gap-2 overflow-hidden border-b border-stroke-soft px-3 text-sm max-[650px]:min-h-11`,n?`bg-warning-soft`:`bg-star-soft`),children:[n?(0,X.jsx)(jt,{className:`size-4 shrink-0 text-warning-strong`,"aria-hidden":`true`}):(0,X.jsx)(Re,{}),(0,X.jsx)(`strong`,{className:B(`shrink-0 font-medium`,n?`text-warning-strong`:`text-accent-fg`),children:t(n?`workflows:workflowsPage.waitingApproval`:`workflows:workflowsPage.workflowRunning`)}),(0,X.jsx)(`span`,{className:`min-w-0 truncate text-content-secondary tabular-nums`,children:t(`workflows:workflowsPage.runningNodeCompletedTotalCompleted`,{node:e.currentNodeLabel||t(`workflows:workflowsPage.preparing`),completed:e.completedNodes,total:e.totalNodes})}),(0,X.jsx)(`span`,{className:`ml-auto shrink-0 font-mono text-xs text-content-muted tabular-nums`,children:ur(e.durationMs)}),(0,X.jsx)(`i`,{"aria-hidden":`true`,className:`absolute inset-x-0 bottom-0 h-0.5 origin-left bg-star transition-transform duration-(--d-base) ease-precise`,style:{transform:`scaleX(${r/100})`}})]})}function fr({run:e,language:t,t:n}){return e?(0,X.jsxs)(`div`,{className:`activity-row flex min-w-0 items-start gap-2.5 text-sm ${e.status}`,children:[(0,X.jsx)(In,{status:e.status,className:`mt-px`}),(0,X.jsxs)(`span`,{className:`flex min-w-0 flex-col gap-0.5`,children:[(0,X.jsx)(`strong`,{className:B(`font-medium break-words`,e.status===`failed`?`text-danger`:`text-content`),children:e.status===`completed`?e.summary||n(`workflows:workflowsPage.workflowCompleted`):e.status===`waiting_approval`?n(`workflows:workflowsPage.waitingApproval`):e.status===`running`?e.currentNodeLabel||n(`workflows:workflowsPage.running`):e.error?Q(e.error):n(`workflows:workflowsPage.workflowFailed`)}),(0,X.jsxs)(`small`,{className:`text-xs text-content-muted tabular-nums`,children:[Ge(e.startedAt,t),` · `,ur(e.durationMs)]})]})]}):(0,X.jsx)(`p`,{className:`text-xs text-content-muted`,children:n(`workflows:workflowsPage.noRunHistory`)})}function pr({input:e,value:t,onChange:n,label:r,disabled:i=!1,onBusyChange:a}){let{t:o}=l(),[s,c]=(0,G.useState)({id:``,url:``}),[u,d]=(0,G.useState)(!1),[f,p]=(0,G.useState)(``),m=(0,G.useRef)(null),h=(0,G.useRef)(!0),g=(0,G.useRef)(a);g.current=a;let _=(0,G.useRef)({onChange:n,id:e.id,type:e.type});_.current={onChange:n,id:e.id,type:e.type};let v=e.type,y=(()=>{try{return Lt(t)}catch{return null}})(),b=y?.id;(0,G.useEffect)(()=>(h.current=!0,d(!1),p(``),()=>{h.current=!1,m.current?.abort(),m.current=null,g.current?.(e.id,!1)}),[e.id,v]),(0,G.useEffect)(()=>{if(c({id:``,url:``}),!b)return;let e=new AbortController,t=``;return ir.preview(b,e.signal).then(n=>{e.signal.aborted||(t=URL.createObjectURL(n),c({id:b,url:t}))}).catch(()=>{e.signal.aborted||p(o(`workflows:inputs.previewFailed`))}),()=>{e.abort(),t&&URL.revokeObjectURL(t)}},[b,o]);let x=async(t,n)=>{if(!t.length||i||m.current||n!==`image`&&n!==`video`)return;if(t.length!==1){p(o(`workflows:inputs.oneFile`));return}let r=t[0];if(!(n===`image`?[`image/png`,`image/jpeg`,`image/webp`]:[`video/mp4`,`video/webm`]).includes(r.type)){p(o(`workflows:inputs.mediaType`));return}if(r.size>(n===`image`?8:64)*1024*1024){p(o(n===`image`?`workflows:inputs.imageLimit`:`workflows:inputs.videoLimit`));return}let a=new AbortController;m.current=a,d(!0),g.current?.(e.id,!0),p(``);try{let t=await ir.upload(r,a.signal);h.current&&!a.signal.aborted&&m.current===a&&_.current.id===e.id&&_.current.type===n&&_.current.onChange(t)}catch{h.current&&!a.signal.aborted&&p(o(`workflows:inputs.uploadFailed`))}finally{m.current===a&&(m.current=null,h.current&&(d(!1),g.current?.(e.id,!1)))}};return(0,X.jsxs)(Jn,{label:r,value:typeof t==`string`?t:``,onValueChange:n,files:y?[{...y,url:s.id===y.id?s.url:void 0}]:[],onFilesSelected:e=>void x(e,v),onRemoveFile:()=>n(``),accept:v===`image`?`image`:`video`,allowFiles:v===`image`||v===`video`,allowText:v!==`image`&&v!==`video`,disabled:i||u,maxLength:16e3,attachmentLabel:o(v===`image`?`workflows:inputs.chooseImage`:`workflows:inputs.chooseVideo`),removeLabel:o(`workflows:inputs.removeMedia`),children:[u&&(0,X.jsxs)(`p`,{role:`status`,className:`flex items-center gap-1 text-xs text-muted-foreground`,children:[(0,X.jsx)(re,{className:`size-3 animate-spin`}),o(`workflows:inputs.uploading`)]}),f&&(0,X.jsx)(`p`,{role:`alert`,className:`text-xs text-destructive`,children:f})]})}function mr(e){return e===`number`||e===`boolean`||e===`text`||e===`image`||e===`video`?e:`string`}function hr(e){if(e.type===`image`||e.type===`video`)try{return Lt(e.defaultValue)}catch{return null}return e.type===`boolean`?e.defaultValue===!0||e.defaultValue===`true`:typeof e.defaultValue==`number`||typeof e.defaultValue==`string`?e.defaultValue:``}function gr(e,t){if(!(e instanceof K))return t(`workflows:inputs.invalidDefinition`);let n=e.label||e.inputName;return e.code===`workflow_input_unsafe_name`?t(`workflows:inputs.invalidName`):e.code===`workflow_input_duplicate_name`?t(`workflows:inputs.duplicateName`,{name:n}):e.code===`workflow_input_required`?t(`workflows:inputs.requiredValue`,{name:n}):e.code===`workflow_input_type`?t(`workflows:inputs.invalidValue`,{name:n}):e.code===`workflow_input_too_long`?t(`workflows:inputs.valueTooLong`,{name:n}):e.code===`workflow_input_unknown`?t(`workflows:inputs.unknownInput`,{name:n}):t(`workflows:inputs.invalidDefinition`)}function _r(e,t){try{return zt(e),``}catch(e){return gr(e,t)}}function vr(e,t,n){try{return Bt(e,t),``}catch(e){return gr(e,n)}}function yr(e,t){return Bt(e,t)}function br(e,t){return e.type===`text`?t(`workflows:inputs.longText`):e.type===`number`?t(`workflows:inputs.number`):e.type===`boolean`?t(`workflows:inputs.boolean`):e.type===`image`?t(`workflows:inputs.image`):e.type===`video`?t(`workflows:inputs.video`):t(`workflows:inputs.shortText`)}function xr({inputs:e,onChange:t,t:n,onUploadBusy:r}){let i=(0,G.useId)(),[a,o]=(0,G.useState)(null),s=_r(e,n),c=(n,r)=>t(e.map(e=>e.id===n?{...e,...r}:e));return(0,X.jsxs)(`section`,{className:`mt-4 min-w-0 space-y-3`,"aria-labelledby":`${i}-title`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,X.jsx)(`h3`,{id:`${i}-title`,className:`text-sm font-medium`,children:n(`workflows:workflowsPage.inputParameters`)}),(0,X.jsxs)(V,{variant:`ghost`,size:`sm`,disabled:e.length>=30,onClick:()=>{let r=e.length+1;for(;e.some(e=>e.name===`input_${r}`);)r+=1;let i=crypto.randomUUID();t([...e,{id:i,name:`input_${r}`,label:n(`workflows:workflowsPage.newInput`),type:`string`,required:!1,defaultValue:``,description:``}]),o(i)},children:[(0,X.jsx)(pe,{}),n(`workflows:workflowsPage.addInput`)]})]}),(0,X.jsx)(`p`,{className:`text-xs leading-relaxed text-muted-foreground`,children:n(`workflows:inputs.definitionHint`)}),s&&(0,X.jsx)(`p`,{role:`alert`,className:`text-xs text-destructive`,children:s}),e.length===0&&(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(`workflows:inputs.emptyDefinition`)}),e.map(s=>(0,X.jsxs)(pt,{className:`min-w-0 rounded-md border`,open:a===s.id,onOpenChange:e=>o(e?s.id:null),children:[(0,X.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2 p-3`,children:[(0,X.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-1`,children:[(0,X.jsx)(`p`,{className:`truncate text-sm font-medium`,children:s.label||s.name}),(0,X.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[br(s,n),` ·`,` `,s.required?n(`workflows:workflowsPage.required`):n(`workflows:inputs.optional`)]})]}),(0,X.jsx)(ft,{asChild:!0,children:(0,X.jsxs)(V,{variant:`ghost`,size:`sm`,"aria-label":n(`workflows:inputs.editNamedInput`,{name:s.label||s.name}),children:[(0,X.jsx)(de,{}),n(`workflows:inputs.editInput`)]})})]}),(0,X.jsxs)(dt,{className:`space-y-3 border-t p-3`,children:[(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(R,{htmlFor:`${i}-${s.id}-label`,className:`text-xs`,children:n(`workflows:inputs.label`)}),(0,X.jsx)(H,{id:`${i}-${s.id}-label`,value:s.label,maxLength:120,onChange:e=>c(s.id,{label:e.target.value})})]}),(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(R,{id:`${i}-${s.id}-type`,className:`text-xs`,children:n(`workflows:workflowsPage.parameterType`)}),(0,X.jsxs)(W,{"aria-labelledby":`${i}-${s.id}-type`,value:s.type,onChange:e=>{let t=mr(e.target.value);c(s.id,{type:t,defaultValue:t!==`boolean`&&``})},children:[(0,X.jsx)(`option`,{value:`string`,children:n(`workflows:inputs.shortText`)}),(0,X.jsx)(`option`,{value:`text`,children:n(`workflows:inputs.longText`)}),(0,X.jsx)(`option`,{value:`number`,children:n(`workflows:inputs.number`)}),(0,X.jsx)(`option`,{value:`boolean`,children:n(`workflows:inputs.boolean`)}),(0,X.jsx)(`option`,{value:`image`,children:n(`workflows:inputs.image`)}),(0,X.jsx)(`option`,{value:`video`,children:n(`workflows:inputs.video`)})]})]}),(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(R,{htmlFor:`${i}-${s.id}-description`,className:`text-xs`,children:n(`workflows:inputs.description`)}),(0,X.jsx)(et,{id:`${i}-${s.id}-description`,value:s.description,maxLength:300,rows:2,className:`min-h-14`,onChange:e=>c(s.id,{description:e.target.value})})]}),(0,X.jsxs)(`details`,{className:`group rounded-md border p-2`,children:[(0,X.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center justify-between gap-2 text-xs font-medium [&::-webkit-details-marker]:hidden`,children:[n(`workflows:inputs.advancedSettings`),(0,X.jsx)(T,{className:`size-3.5 transition-transform group-open:rotate-180`})]}),(0,X.jsxs)(`div`,{className:`space-y-3 pt-3`,children:[(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(R,{htmlFor:`${i}-${s.id}-name`,className:`text-xs`,children:n(`workflows:workflowsPage.parameterName`)}),(0,X.jsx)(H,{id:`${i}-${s.id}-name`,value:s.name,maxLength:80,onChange:e=>c(s.id,{name:e.target.value})}),(0,X.jsx)(`code`,{className:`block break-all text-xs text-muted-foreground`,children:`{{inputs.`+s.name+`}}`})]}),(0,X.jsxs)(`div`,{className:`space-y-1`,children:[s.type!==`text`&&s.type!==`image`&&s.type!==`video`&&(0,X.jsx)(R,{htmlFor:`${i}-${s.id}-default`,className:`text-xs`,children:n(`workflows:inputs.defaultValue`)}),s.type===`boolean`?(0,X.jsx)(z,{id:`${i}-${s.id}-default`,checked:hr(s)===!0,onCheckedChange:e=>c(s.id,{defaultValue:e})}):s.type===`text`||s.type===`image`||s.type===`video`?(0,X.jsx)(pr,{input:s,value:s.defaultValue,label:n(`workflows:inputs.defaultValue`),onBusyChange:r,onChange:e=>c(s.id,{defaultValue:e})}):(0,X.jsx)(H,{id:`${i}-${s.id}-default`,type:s.type===`number`?`number`:`text`,value:String(hr(s)),onChange:e=>c(s.id,{defaultValue:e.target.value})})]}),(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,X.jsx)(R,{htmlFor:`${i}-${s.id}-required`,className:`text-xs`,children:n(`workflows:workflowsPage.required`)}),(0,X.jsx)(z,{id:`${i}-${s.id}-required`,checked:s.required,onCheckedChange:e=>c(s.id,{required:e})})]})]})]}),(0,X.jsxs)(V,{variant:`ghost`,size:`sm`,"aria-label":n(`workflows:inputs.deleteInput`,{name:s.label}),onClick:()=>{t(e.filter(e=>e.id!==s.id)),o(null)},children:[(0,X.jsx)(be,{}),n(`workflows:inputs.removeInput`)]})]})]},s.id))]})}var Sr={browser:{Icon:x},feishu:{Icon:S},weixin:{Icon:ie},qq:{Icon:ie},telegram:{Icon:ae}},Cr=[`workspace-write`,`full-access`],wr=`workflow-notification-alert mt-2.5 mb-1.5 border-(--warning-border) bg-warning-soft text-content-secondary *:[svg]:text-warning-strong [&_[data-slot=alert-description]]:flex [&_[data-slot=alert-description]]:flex-wrap [&_[data-slot=alert-description]]:items-center [&_[data-slot=alert-description]]:gap-1 [&_[data-slot=alert-description]]:text-xs`,Tr=`rounded-md bg-surface-subtle p-3 text-xs leading-relaxed text-content-muted`;function Er(e,t){return t(e===`workspace-write`?`workflows:workflowsPage.workspaceWrite`:`workflows:workflowsPage.fullAccess`)}function Dr(e,t){return t(e===`workspace-write`?`workflows:workflowsPage.workspaceWriteHelp`:`workflows:workflowsPage.fullAccessHelp`)}function Or(e,t){return t(e===`feishu`?`workflows:workflowsPage.feishu`:e===`weixin`?`workflows:workflowsPage.weChat`:e===`qq`?`workflows:workflowsPage.qq`:e===`telegram`?`workflows:workflowsPage.telegram`:`workflows:workflowsPage.browserNotification`)}function kr({draft:e,catalog:t,t:n,onUpdateDraft:r,onInputUploadBusy:i}){return(0,X.jsxs)(`div`,{className:`min-w-0 space-y-4`,children:[(0,X.jsxs)(U,{variant:`control`,children:[n(`workflows:workflowsPage.name`),(0,X.jsx)(H,{value:e.name,onChange:e=>r({name:e.target.value})})]}),(0,X.jsxs)(U,{variant:`control`,children:[n(`workflows:workflowsPage.description`),(0,X.jsx)(et,{value:e.description,onChange:e=>r({description:e.target.value})})]}),(0,X.jsxs)(U,{variant:`control`,children:[n(`workflows:workflowsPage.workingDirectory`),(0,X.jsx)(H,{value:e.cwd,onChange:e=>r({cwd:e.target.value})})]}),(0,X.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-3`,children:[(0,X.jsxs)(U,{variant:`control`,children:[n(`workflows:workflowsPage.visibility`),(0,X.jsxs)(W,{value:e.visibility,onChange:e=>r({visibility:e.target.value===`shared`?`shared`:`private`}),children:[(0,X.jsx)(`option`,{value:`private`,children:n(`workflows:workflowsPage.private`)}),(0,X.jsx)(`option`,{value:`shared`,children:n(`workflows:workflowsPage.shared`)})]})]}),(0,X.jsxs)(U,{variant:`control`,children:[n(`workflows:workflowsPage.tags`),(0,X.jsx)(H,{value:e.tags.join(`, `),onChange:e=>r({tags:e.target.value.split(`,`).map(e=>e.trim()).filter(Boolean)})})]}),(0,X.jsxs)(U,{variant:`control`,children:[n(`workflows:workflowsPage.revision`),(0,X.jsx)(H,{value:`v${e.revision}`,disabled:!0})]})]}),(0,X.jsxs)(U,{variant:`control`,children:[n(`workflows:workflowsPage.defaultModel`),(0,X.jsxs)(W,{value:e.model?`${e.model.provider}/${e.model.model}`:``,onChange:e=>{let n=t.models.find(t=>`${t.provider}/${t.model}`===e.target.value);r({model:n?{provider:n.provider,model:n.model}:null})},children:[(0,X.jsx)(`option`,{value:``,children:n(`workflows:workflowsPage.useSystemDefault`)}),t.models.map(e=>(0,X.jsx)(`option`,{value:`${e.provider}/${e.model}`,children:e.label},`${e.provider}/${e.model}`))]})]}),(0,X.jsx)(xr,{inputs:e.inputs,t:n,onUploadBusy:i,onChange:e=>r({inputs:e})})]})}function Ar({node:e,catalog:t,t:n,systemNotificationPermission:r,onUpdateNode:i,onToggleNotification:a,onOpenChannels:o,onOpenSystemNotificationSettings:s}){let c=[`feishu`,`weixin`,`qq`,`telegram`].some(e=>t.notificationTargets[e]?.enabled),l=r==="default"||r===`granted`;return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(U,{variant:`control`,children:[n(`workflows:workflowsPage.notificationTitle`),(0,X.jsx)(H,{value:e.notification.title,onChange:t=>i({notification:{...e.notification,title:t.target.value}}),placeholder:`{{workflow.name}}`})]}),(0,X.jsxs)(U,{variant:`control`,children:[n(`workflows:workflowsPage.notificationContent`),(0,X.jsx)(et,{value:e.notification.content,onChange:t=>i({notification:{...e.notification,content:t.target.value}}),placeholder:`{{inputs.name}} · {{previous.summary}}`})]}),(0,X.jsx)(`strong`,{className:`mt-3 block text-xs font-medium text-content-secondary`,children:n(`workflows:workflowsPage.notificationChannels`)}),!c&&(0,X.jsxs)(it,{className:wr,children:[(0,X.jsx)(xe,{}),(0,X.jsxs)(rt,{children:[n(`workflows:workflowsPage.noExternalNotificationChannelsEnabled`),(0,X.jsx)(V,{type:`button`,variant:`link`,size:`sm`,onClick:o,children:n(`workflows:workflowsPage.openChannelSettings`)})]})]}),(r===`denied`||r===`unsupported`)&&(0,X.jsxs)(it,{className:wr,children:[(0,X.jsx)(xe,{}),(0,X.jsxs)(rt,{children:[n(r===`unsupported`?`workflows:workflowsPage.systemNotificationsUnsupported`:`workflows:workflowsPage.systemNotificationPermissionRequired`),(0,X.jsx)(V,{type:`button`,variant:`link`,size:`sm`,onClick:s,children:n(`workflows:workflowsPage.openSystemNotificationSettings`)})]})]}),Object.entries(Sr).map(([i,o])=>{let s=o.Icon,c=i===`browser`?l:!!t.notificationTargets[i]?.enabled;return(0,X.jsxs)(`div`,{className:`toggle-line flex min-h-[34px] items-center justify-between gap-3 border-t border-stroke-soft text-sm max-[650px]:min-h-11 [&>span]:flex [&>span]:items-center [&>span]:gap-2 [&>span]:text-content-secondary`,children:[(0,X.jsxs)(`span`,{children:[(0,X.jsx)(s,{size:15}),Or(i,n)]}),(0,X.jsx)(z,{checked:c&&(i!==`browser`||r===`granted`&&t.notificationTargets.browser.enabled)&&e.notificationTargets.includes(i),disabled:!c,"aria-label":Or(i,n),title:i===`browser`?c?t.notificationTargets.browser.enabled?n(`workflows:workflowsPage.systemNotificationsEnabled`):n(`workflows:workflowsPage.systemNotificationReady`):n(`workflows:workflowsPage.systemNotificationPermissionRequired`):n(c?`workflows:workflowsPage.notificationChannelEnabled`:`workflows:workflowsPage.notificationChannelNotEnabled`),onCheckedChange:()=>void a(i)})]},i)})]})}function jr({edge:e,nodes:t,t:n,onDelete:r}){let i=new Map(t.map(e=>[e.id,e]));return(0,X.jsxs)(`section`,{className:`min-w-0 space-y-3`,children:[(0,X.jsxs)(`div`,{className:`workflow-edge-summary my-2.5 grid grid-cols-[minmax(0,1fr)_auto_minmax(0,1fr)] items-center gap-2 text-sm [&_strong]:truncate [&_strong]:font-medium [&>span]:text-content-faint`,children:[(0,X.jsx)(`strong`,{children:i.get(e.source)?.label||n(`workflows:workflowsPage.unknownNode`)}),(0,X.jsx)(`span`,{children:`→`}),(0,X.jsx)(`strong`,{children:i.get(e.target)?.label||n(`workflows:workflowsPage.unknownNode`)})]}),(0,X.jsx)(`p`,{className:`muted-copy text-xs leading-relaxed text-content-muted`,children:n(`workflows:workflowsPage.pressDeleteOrBackspaceToRemoveThisConnection`)}),(0,X.jsxs)(V,{size:`sm`,variant:`destructive`,onClick:r,children:[(0,X.jsx)(be,{"data-icon":`inline-start`}),n(`workflows:workflowsPage.deleteConnection`)]})]})}function Mr({node:e,inputs:t,selectedEdge:n,catalog:r,t:i,onUpdateNode:a,systemNotificationPermission:o,onToggleNotification:s,onCopy:c,onDelete:l,onOpenChannels:u,onOpenSystemNotificationSettings:d}){let f=(0,G.useRef)(null);return(0,X.jsx)(`section`,{className:`min-w-0 space-y-3`,children:e?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(U,{variant:`control`,children:[i(`workflows:workflowsPage.nodeName`),(0,X.jsx)(H,{value:e.label,onChange:e=>a({label:e.target.value})})]}),[`prompt`,`skill`,`file`,`mcp`].includes(e.kind)&&(0,X.jsxs)(U,{variant:`control`,children:[i(`workflows:workflowsPage.nodeModel`),(0,X.jsxs)(W,{value:e.model?`${e.model.provider}/${e.model.model}`:``,onChange:e=>{let t=r.models.find(t=>`${t.provider}/${t.model}`===e.target.value);a({model:t?{provider:t.provider,model:t.model}:null})},children:[(0,X.jsx)(`option`,{value:``,children:i(`workflows:workflowsPage.inheritWorkflowDefaultModel`)}),r.models.map(e=>(0,X.jsx)(`option`,{value:`${e.provider}/${e.model}`,children:e.label},`${e.provider}/${e.model}`))]})]}),e.kind===`trigger`&&(0,X.jsx)(`p`,{className:Tr,children:i(`workflows:editor.manualTriggerHint`)}),e.kind===`parallel`&&(0,X.jsx)(`p`,{className:Tr,children:i(`workflows:editor.parallelHint`)}),![`trigger`,`parallel`,`condition`,`approval`].includes(e.kind)&&(0,X.jsxs)(`details`,{className:`rounded-md border border-stroke p-3`,children:[(0,X.jsx)(`summary`,{className:`cursor-pointer text-xs font-medium text-content-secondary`,children:i(`workflows:editor.executionSettings`)}),(0,X.jsxs)(`div`,{className:`grid gap-3 pt-3`,children:[(0,X.jsxs)(U,{variant:`control`,children:[i(`workflows:workflowsPage.retryCount`),(0,X.jsx)(H,{type:`number`,min:`0`,max:`3`,value:e.retries,onChange:e=>a({retries:Number(e.target.value)})})]}),(0,X.jsxs)(U,{variant:`control`,children:[i(`workflows:workflowsPage.timeoutMinutes`),(0,X.jsx)(H,{type:`number`,min:`1`,max:`240`,value:e.timeoutMinutes,onChange:e=>a({timeoutMinutes:Number(e.target.value)})})]}),(0,X.jsxs)(U,{variant:`control`,children:[i(`workflows:workflowsPage.failureHandling`),(0,X.jsxs)(W,{value:e.failurePolicy,onChange:e=>a({failurePolicy:e.target.value===`skip`?`skip`:`stop`}),children:[(0,X.jsx)(`option`,{value:`stop`,children:i(`workflows:workflowsPage.stopImmediately`)}),(0,X.jsx)(`option`,{value:`skip`,children:i(`workflows:workflowsPage.skipThisNode`)})]})]})]})]}),Kt(e.kind)&&(0,X.jsx)(rr,{node:e,inputs:t,t:i,onChange:a}),[`prompt`,`skill`,`file`,`mcp`].includes(e.kind)&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(U,{variant:`control`,children:[i(`workflows:workflowsPage.executionMode`),(0,X.jsx)(W,{value:e.executionMode,onChange:e=>a({executionMode:e.target.value}),children:Cr.map(e=>(0,X.jsx)(`option`,{value:e,children:Er(e,i)},e))}),(0,X.jsx)(`small`,{children:Dr(e.executionMode,i)})]}),e.kind===`skill`&&(0,X.jsxs)(U,{variant:`control`,children:[`Skill`,(0,X.jsxs)(W,{value:e.skillName,onChange:e=>a({skillName:e.target.value}),children:[(0,X.jsx)(`option`,{value:``,children:i(`workflows:workflowsPage.chooseSkill`)}),r.skills.map(e=>(0,X.jsx)(`option`,{value:e.name,children:e.name},e.id))]})]}),e.kind===`mcp`&&(0,X.jsxs)(U,{variant:`control`,children:[i(`workflows:workflowsPage.mcpToolNames`),(0,X.jsx)(H,{value:e.requestedToolNames.join(`, `),onChange:e=>a({requestedToolNames:e.target.value.split(`,`).map(e=>e.trim()).filter(Boolean)}),placeholder:`server.tool_name`})]}),(0,X.jsxs)(U,{variant:`control`,children:[i(`workflows:inputs.nodeRules`),(0,X.jsx)(et,{ref:f,value:e.prompt,onChange:e=>a({prompt:e.target.value}),placeholder:i(`workflows:workflowsPage.describeTheWorkTheAgentShouldCompleteInThisNode`)})]}),(0,X.jsxs)(`div`,{className:`space-y-2 py-2`,children:[(0,X.jsx)(`p`,{className:`text-xs leading-relaxed text-content-muted`,children:i(`workflows:inputs.nodeRulesHint`)}),(0,X.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:t.map(t=>(0,X.jsx)(V,{type:`button`,variant:`outline`,size:`xs`,title:i(`workflows:inputs.insertVariable`,{name:t.label}),onClick:()=>{let n=f.current,r=n?.selectionStart??e.prompt.length,i=n?.selectionEnd??r,o=`{{inputs.`+t.name+`}}`;a({prompt:e.prompt.slice(0,r)+o+e.prompt.slice(i)}),requestAnimationFrame(()=>{n?.focus(),n?.setSelectionRange(r+o.length,r+o.length)})},children:(0,X.jsx)(`code`,{children:`{{inputs.`+t.name+`}}`})},t.id))})]}),(0,X.jsxs)(U,{variant:`control`,children:[i(`workflows:workflowsPage.outputFormat`),(0,X.jsxs)(W,{value:e.outputFormat,onChange:e=>a({outputFormat:e.target.value===`json`?`json`:`text`}),children:[(0,X.jsx)(`option`,{value:`text`,children:`Text`}),(0,X.jsx)(`option`,{value:`json`,children:`JSON`})]})]})]}),e.kind===`condition`&&(0,X.jsxs)(`div`,{className:`grid gap-3`,children:[(0,X.jsxs)(U,{variant:`control`,children:[i(`workflows:workflowsPage.dataPath`),(0,X.jsx)(H,{value:e.condition.source,onChange:t=>a({condition:{...e.condition,source:t.target.value}}),placeholder:`inputs.approved`})]}),(0,X.jsxs)(U,{variant:`control`,children:[i(`workflows:workflowsPage.operator`),(0,X.jsx)(W,{value:e.condition.operator,onChange:t=>a({condition:{...e.condition,operator:t.target.value}}),children:[`exists`,`not_exists`,`equals`,`not_equals`,`contains`,`greater_than`,`less_than`].map(e=>(0,X.jsx)(`option`,{value:e,children:e},e))})]}),(0,X.jsxs)(U,{variant:`control`,children:[i(`workflows:workflowsPage.comparisonValue`),(0,X.jsx)(H,{value:String(e.condition.value??``),onChange:t=>a({condition:{...e.condition,value:t.target.value}})})]})]}),e.kind===`notification`&&(0,X.jsx)(Ar,{node:e,catalog:r,t:i,systemNotificationPermission:o,onUpdateNode:a,onToggleNotification:s,onOpenChannels:u,onOpenSystemNotificationSettings:d}),e.kind===`approval`&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(U,{variant:`control`,children:[i(`workflows:workflowsPage.approvalMessage`),(0,X.jsx)(et,{value:e.approval.message,onChange:t=>a({approval:{...e.approval,message:t.target.value}})})]}),(0,X.jsxs)(U,{variant:`control`,children:[i(`workflows:workflowsPage.approvalTimeout`),(0,X.jsx)(H,{type:`number`,min:`1`,max:`10080`,value:e.approval.timeoutMinutes,onChange:t=>a({approval:{...e.approval,timeoutMinutes:Number(t.target.value)}})})]})]}),(0,X.jsxs)(`div`,{className:`mt-4 flex gap-2 max-[650px]:flex-wrap`,children:[(0,X.jsxs)(V,{size:`sm`,variant:`secondary`,onClick:c,children:[(0,X.jsx)(j,{"data-icon":`inline-start`}),i(`workflows:workflowsPage.duplicateNode`)]}),(0,X.jsxs)(V,{size:`sm`,variant:`destructive`,onClick:l,children:[(0,X.jsx)(be,{"data-icon":`inline-start`}),i(`workflows:workflowsPage.deleteNode`)]})]})]}):(0,X.jsx)(`p`,{className:`muted-copy text-xs leading-relaxed text-content-muted`,children:i(n?`workflows:workflowsPage.aConnectionIsCurrentlySelected`:`workflows:workflowsPage.dragNodesFromTheLeftToStartBuildingTheWorkflow`)})})}function Nr({draft:e,catalog:t,selectedNode:n,selectedEdge:r,currentRun:i,language:a,t:o,onUpdateNode:s,systemNotificationPermission:c,onToggleNotification:l,onDeleteEdge:u,onCopyNode:d,onDeleteNode:f,onOpenChannels:p,onOpenSystemNotificationSettings:m,onRunImageNode:h,imageRunBusy:g=!1}){let _=e.edges.filter(e=>e.target===n?.id).map(e=>e.source),v=(i?[i]:[]).find(t=>t.workflowId===e.id&&(n?.kind===`media-input`?!!t.inputs:_.length>0&&_.every(e=>t.nodes?.some(t=>t.id===e&&t.status===`completed`&&t.output)))),y=i;return(0,X.jsxs)(`div`,{className:`detail-stack min-w-0 space-y-5`,children:[r&&(0,X.jsx)(jr,{edge:r,nodes:e.nodes,t:o,onDelete:u}),!r&&(0,X.jsx)(Mr,{node:n,inputs:e.inputs,selectedEdge:r,catalog:t,t:o,onUpdateNode:s,systemNotificationPermission:c,onToggleNotification:l,onCopy:d,onDelete:f,onOpenChannels:p,onOpenSystemNotificationSettings:m}),n&&Kt(n.kind)&&h&&(0,X.jsxs)(`div`,{className:`space-y-2 rounded-md border border-stroke p-3`,children:[(0,X.jsxs)(V,{className:`w-full`,variant:`outline`,disabled:!e.id||!v||g,onClick:()=>{v&&h(n.id,v.id)},children:[(0,X.jsx)(fe,{}),o(`workflows:imageNodes.runNode`)]}),(0,X.jsx)(`p`,{className:`text-xs text-content-muted`,children:o(`workflows:imageNodes.runNodeHint`)})]}),n&&Kt(n.kind)&&(0,X.jsx)(cr,{value:y?.nodes?.find(e=>e.id===n.id)?.output,previousValue:v?.nodes?.find(t=>t.id===e.edges.find(e=>e.target===n.id)?.source)?.output,error:y?.nodes?.find(e=>e.id===n.id)?.error,t:o},n.id),e.id&&i&&(0,X.jsxs)(`details`,{className:`overflow-hidden rounded-md border border-stroke`,children:[(0,X.jsx)(`summary`,{className:`cursor-pointer px-3 py-2 text-sm font-medium hover:bg-surface-subtle focus-visible:-outline-offset-2 max-[650px]:py-3`,children:o(`workflows:workflowsPage.latestRun`)}),(0,X.jsx)(`div`,{className:`border-t border-stroke-soft px-3 py-2.5`,children:(0,X.jsx)(fr,{run:i,language:a,t:o})})]})]})}function Pr({workflowId:e,templateId:t,notify:n,onCreated:r}){let{t:i}=l(),[a,o]=(0,G.useState)(Nn),[s,c]=(0,G.useState)(null),[u,d]=(0,G.useState)(``),[f,p]=(0,G.useState)(``),[m,g]=(0,G.useState)(!0),[_,v]=(0,G.useState)(!1),[y,b]=(0,G.useState)(``),x=(0,G.useRef)(null),S=(0,G.useRef)(new Set),[C,w]=(0,G.useState)(!1),T=(0,G.useRef)(null),E=(0,G.useRef)(!0);(0,G.useEffect)(()=>{let e=S.current;return E.current=!0,v(!1),w(!1),()=>{E.current=!1,T.current?.abort(),T.current=null,e.clear()}},[e,t]);let ee=(0,G.useCallback)((e,t)=>{t?S.current.add(e):S.current.delete(e),E.current&&w(S.current.size>0)},[]),D=!!window.pisperDesktop?.showNotification,[O,k]=(0,G.useState)(()=>D?`checking`:gt()),A=(0,G.useCallback)(async()=>{if(!D){k(gt());return}let e=window.pisperDesktop?.getNotificationStatus;if(!e){k(`granted`);return}try{let t=await e(),n=t?.permission;k(n==="default"||n===`denied`||n===`granted`||n===`checking`||n===`unsupported`?n:t?.supported===!1?`unsupported`:`granted`)}catch{k(`unsupported`)}},[D]),j=(0,G.useCallback)(async n=>{try{let r=await h(`/api/workflows`,{signal:n});if(n.aborted)return;o(r);let a=e===`new`?null:r.workflows.find(t=>t.id===e),s=pn(t),l=a?structuredClone(a):s?_n(s,r.cwd,i):hn(r.cwd,i);c(l),d(e=>l.nodes.some(t=>t.id===e)?e:l.nodes[0]?.id||``),p(``),b(a||e===`new`?``:i(`workflows:workflowsPage.workflowNotFoundABlankEditorWasOpened`))}catch(e){n.aborted||b(Q(e))}finally{n.aborted||g(!1)}},[i,t,e]),M=(0,G.useCallback)(()=>{x.current?.abort();let e=new AbortController;x.current=e,g(!0),b(``),j(e.signal)},[j]);(0,G.useEffect)(()=>(M(),()=>x.current?.abort()),[M]),(0,G.useEffect)(()=>{A();let e=()=>void A();return window.addEventListener(`focus`,e),()=>window.removeEventListener(`focus`,e)},[A]);let N=(0,G.useMemo)(()=>a.runs.filter(e=>e.workflowId===s?.id).sort((e,t)=>Date.parse(t.startedAt)-Date.parse(e.startedAt))[0],[a.runs,s?.id]),P=N?.status===`running`||N?.status===`waiting_approval`;(0,G.useEffect)(()=>{if(!P)return;let e=new AbortController,t=!1,n=window.setInterval(async()=>{if(!t){t=!0;try{let t=await h(`/api/workflows`,{signal:e.signal});e.signal.aborted||o(t)}catch{}finally{t=!1}}},1500);return()=>{e.abort(),window.clearInterval(n)}},[P,e]);let F=(0,G.useMemo)(()=>s?.nodes.find(e=>e.id===u)||null,[s?.nodes,u]),te=(0,G.useMemo)(()=>s?.edges.find(e=>e.id===f)||null,[s?.edges,f]),ne=(0,G.useCallback)(e=>{c(t=>t&&{...t,...e})},[]),I=(0,G.useCallback)(e=>{c(t=>t&&{...t,nodes:t.nodes.map(t=>t.id===u?{...t,...e}:t)})},[u]),re=(0,G.useCallback)(e=>{d(e),p(``)},[]),ie=(0,G.useCallback)(e=>{p(e),d(``)},[]),ae=(0,G.useCallback)(()=>{d(``),p(``)},[]),oe=(0,G.useCallback)((e,t,r=`output`)=>{if(!s||e===t)return;let a=s.nodes.find(e=>e.id===t);if(!a||a.kind===`trigger`){n(i(`workflows:workflowsPage.aTriggerCannotHaveAnUpstreamConnection`),`error`);return}if(s.edges.some(n=>n.source===e&&n.target===t&&n.sourcePort===r)){n(i(`workflows:workflowsPage.thisConnectionAlreadyExists`),`info`);return}if(Qt(s.nodes,s.edges,e,t,r)){n(i(`workflows:workflowsPage.aWorkflowCannotContainCyclicConnections`),`error`);return}let o={id:crypto.randomUUID(),source:e,sourcePort:r,target:t,targetPort:`input`};c(e=>e&&{...e,edges:[...e.edges,o]}),p(o.id),d(``),n(i(`workflows:workflowsPage.connectionCreated`),`info`)},[s,n,i]),se=(0,G.useCallback)(e=>{if(!e.length)return;let t=new Set(e);c(e=>e&&{...e,edges:e.edges.filter(e=>!t.has(e.id))}),p(``),n(i(`workflows:workflowsPage.connectionDeleted`),`info`)},[n,i]),ce=(0,G.useCallback)(()=>{f&&se([f])},[se,f]),le=(0,G.useCallback)(e=>{if(!e.length)return;let t=new Set(e);c(e=>e&&{...e,nodes:e.nodes.filter(e=>!t.has(e.id)),edges:e.edges.filter(e=>!t.has(e.source)&&!t.has(e.target))}),ae(),n(i(`workflows:workflowsPage.nodeDeleted`),`info`)},[ae,n,i]),ue=(0,G.useCallback)((e,t,n)=>{let r=crypto.randomUUID();c(i=>i&&{...i,nodes:[...i.nodes,Z(r,e,t||$t[e],``,n.x,n.y)]}),d(r),p(``)},[]),de=(0,G.useCallback)((e,t)=>{c(n=>n&&{...n,nodes:n.nodes.map(n=>n.id===e&&(n.x!==t.x||n.y!==t.y)?{...n,x:t.x,y:t.y}:n)})},[]),fe=(0,G.useCallback)(()=>{if(!F)return;let e=crypto.randomUUID();c(t=>t&&{...t,nodes:[...t.nodes,{...F,id:e,label:`${F.label} 副本`,x:F.x+25,y:F.y+25}]}),d(e),p(``),n(i(`workflows:workflowsPage.nodeDuplicated`),`info`)},[n,F,i]),pe=(0,G.useCallback)(()=>{F&&le([F.id])},[le,F]),me=(0,G.useCallback)(async e=>{if(!F||F.kind!==`notification`)return;let t=F.notificationTargets;if(e!==`browser`){if(t.includes(e)){I({notificationTargets:t.filter(t=>t!==e)});return}if(!a.notificationTargets[e]?.enabled)return;I({notificationTargets:[...t,e]});return}if(t.includes(e)&&a.notificationTargets.browser.enabled&&O===`granted`){I({notificationTargets:t.filter(t=>t!==e)});return}let r=O;if(D){await A();let e=await window.pisperDesktop?.getNotificationStatus?.();r=e?.permission||(e?.supported===!1?`unsupported`:`granted`)}else if(r=await ht(),k(r),r===`granted`)try{await mt()}catch(e){n(Q(e),`error`);return}if(r!==`granted`){n(i(r===`unsupported`?`workflows:workflowsPage.systemNotificationsUnsupported`:`workflows:workflowsPage.systemNotificationPermissionRequired`),`error`);return}try{let r=await h(`/api/settings/notifications/browser`,{method:`PATCH`,body:JSON.stringify({enabled:!0})});o(e=>({...e,notificationTargets:{...e.notificationTargets,browser:{enabled:r.browser.enabled}}})),I({notificationTargets:t.includes(e)?t:[...t,e]}),n(i(`workflows:workflowsPage.systemNotificationsEnabled`))}catch(e){n(Q(e),`error`)}},[a.notificationTargets,D,n,A,F,O,i,I]),L=(0,G.useCallback)(async(t=`draft`,l=!1)=>{if(!s||!E.current||T.current)return null;if(S.current.size)return n(i(`workflows:inputs.uploading`),`info`),null;let u=_r(s.inputs,i);if(u)return b(u),n(u,`error`),null;v(!0),b(``);let d=new AbortController;T.current=d;try{let u=new Set(Object.entries(a.notificationTargets).filter(([e,t])=>t.enabled&&(e!==`browser`||O===`granted`||O===`checking`)).map(([e])=>e)),f={...s,status:t,notifications:s.notifications.filter(e=>u.has(e)),nodes:s.nodes.map(e=>({...e,notificationTargets:e.notificationTargets.filter(e=>u.has(e))}))},p=s.id?await h(`/api/workflows/${encodeURIComponent(s.id)}`,{method:`PATCH`,body:JSON.stringify(f),signal:d.signal}):await h(`/api/workflows`,{method:`POST`,body:JSON.stringify(f),signal:d.signal});return d.signal.throwIfAborted(),o(p.state),c(e=>e===s?structuredClone(p.workflow):e&&{...e,id:p.workflow.id,revision:p.workflow.revision}),e===`new`&&!l&&r(p.workflow.id,!1),l||n(i(t===`published`?`workflows:workflowsPage.workflowPublished`:`workflows:workflowsPage.workflowDraftSaved`)),p.workflow}catch(e){if(d.signal.aborted)return null;let t=Q(e);return b(t),n(t,`error`),null}finally{T.current===d&&(T.current=null,E.current&&v(!1))}},[a.notificationTargets,s,n,r,O,i,e]),he=(0,G.useCallback)(async(t,a)=>{let c=await L(s?.status||`draft`,!0);if(!c||!E.current)return!1;if(S.current.size)return n(i(`workflows:inputs.uploading`),`info`),!1;let l=new AbortController;T.current=l,v(!0);try{a?await Zn.runNode(c.id,a.nodeId,a.sourceRunId,l.signal):await h(`/api/workflows/${encodeURIComponent(c.id)}/run`,{method:`POST`,body:JSON.stringify({inputs:t}),signal:l.signal}),l.signal.throwIfAborted();let e=await h(`/api/workflows`,{signal:l.signal});return l.signal.throwIfAborted(),o(e),n(i(`workflows:workflowsPage.workflowStarted`)),!0}catch(e){if(l.signal.aborted)return!1;let t=Q(e);return b(t),n(t,`error`),!1}finally{T.current===l&&(T.current=null,E.current&&v(!1)),E.current&&!l.signal.aborted&&e===`new`&&r(c.id,!0)}},[s?.status,n,r,L,i,e]),ge=(0,G.useCallback)(e=>he(e),[he]),_e=(0,G.useCallback)((e,t)=>he(void 0,{nodeId:e,sourceRunId:t}),[he]),ve=(0,G.useCallback)(async()=>{if(!E.current||T.current||!N||![`running`,`waiting_approval`].includes(N.status))return;let e=new AbortController;T.current=e,v(!0);try{await h(`/api/workflow-runs/${encodeURIComponent(N.id)}/stop`,{method:`POST`,body:`{}`,signal:e.signal}),e.signal.throwIfAborted();let t=await h(`/api/workflows`,{signal:e.signal});e.signal.throwIfAborted(),o(t),n(i(`workflows:workflowsPage.stoppingWorkflow`),`info`)}catch(t){if(e.signal.aborted)return;let r=Q(t);b(r),n(r,`error`)}finally{T.current===e&&(T.current=null,E.current&&v(!1))}},[N,n,i]),ye=(0,G.useCallback)(()=>L(`published`),[L]);return{catalog:a,draft:s,selectedNode:F,selectedEdge:te,selectedNodeId:u,selectedEdgeId:f,currentRun:N,loading:m,retryLoad:M,busy:_||C,inputUploadsPending:C,onInputUploadBusy:ee,running:P,error:y,systemNotificationPermission:O,updateDraft:ne,updateNode:I,addEdge:oe,removeEdges:se,removeSelectedEdge:ce,removeNodes:le,addNode:ue,moveNode:de,copyNode:fe,deleteNode:pe,toggleNotification:me,selectNode:re,selectEdge:ie,clearSelection:ae,saveWorkflow:L,runWorkflow:ge,runImageNode:_e,stopWorkflow:ve,publishWorkflow:ye}}function Fr({workflow:e,onClose:t,onRun:n}){let{t:r}=l(),i=(0,G.useId)(),a={id:`task`,name:`task`,label:r(`workflows:inputs.task`),description:r(`workflows:inputs.contextHint`),type:`text`,required:!1,defaultValue:``},o=e.inputs.length?e.inputs:[a],[s,c]=(0,G.useState)(()=>Object.fromEntries(o.map(e=>[e.name,hr(e)]))),[u,d]=(0,G.useState)(!1),[f,p]=(0,G.useState)(``),[m,h]=(0,G.useState)([]),g=(0,G.useRef)(new Set),_=(0,G.useRef)(s);_.current=s;let v=(0,G.useRef)(!0);(0,G.useEffect)(()=>(v.current=!0,()=>{v.current=!1}),[]);let y=(e,t)=>{let n={..._.current,[e]:t};_.current=n,c(n)},b=(0,G.useCallback)((e,t)=>{t?g.current.add(e):g.current.delete(e),v.current&&h([...g.current])},[]),x=(0,G.useRef)(!1),S=async()=>{if(x.current||g.current.size)return;let e=_.current,i=vr(o,e,r);if(i){p(i);return}x.current=!0,d(!0),p(``);try{let i=await n(yr(o,e));if(!v.current)return;i?t():p(r(`workflows:inputs.startFailed`))}catch{v.current&&p(r(`workflows:inputs.startFailed`))}finally{x.current=!1,v.current&&d(!1)}};return(0,X.jsx)(Qe,{open:!0,onOpenChange:e=>{!e&&!x.current&&t()},children:(0,X.jsxs)(Je,{className:`max-h-[85vh] overflow-y-auto supports-[height:100dvh]:max-h-[85dvh] sm:max-w-xl`,showCloseButton:!u,children:[(0,X.jsxs)(Ze,{children:[(0,X.jsx)(Ye,{children:r(`workflows:inputs.runTitle`,{name:e.name})}),(0,X.jsx)(qe,{children:r(`workflows:inputs.runHint`)})]}),(0,X.jsxs)(`form`,{className:`space-y-4`,onSubmit:e=>{e.preventDefault(),S()},children:[mn(e)>0&&(0,X.jsx)(`p`,{className:`rounded-md bg-surface-subtle p-3 text-sm tabular-nums`,children:r(`workflows:imageNodes.requestEstimate`,{count:mn(e)})}),o.map(e=>(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[e.type!==`text`&&e.type!==`image`&&e.type!==`video`&&(0,X.jsxs)(R,{htmlFor:`${i}-${e.id}`,className:`flex items-center gap-1`,children:[e.label,e.required&&(0,X.jsx)(`span`,{className:`text-destructive`,"aria-hidden":`true`,children:`*`})]}),e.type===`boolean`?(0,X.jsx)(z,{id:`${i}-${e.id}`,checked:s[e.name]===!0,disabled:u,onCheckedChange:t=>y(e.name,t)}):e.type===`text`||e.type===`image`||e.type===`video`?(0,X.jsx)(pr,{input:e,value:s[e.name],disabled:u,label:`${e.label}${e.required?` *`:``}`,onBusyChange:b,onChange:t=>y(e.name,t)}):(0,X.jsx)(H,{id:`${i}-${e.id}`,type:e.type===`number`?`number`:`text`,step:e.type===`number`?`any`:void 0,value:String(s[e.name]??``),required:e.required,disabled:u,"aria-describedby":e.description?`${i}-${e.id}-description`:void 0,onChange:t=>y(e.name,t.target.value)}),e.description&&(0,X.jsx)(`p`,{id:`${i}-${e.id}-description`,className:`text-xs leading-relaxed text-muted-foreground`,children:e.description})]},e.id)),f&&(0,X.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:f}),(0,X.jsxs)(Xe,{children:[(0,X.jsx)(V,{type:`button`,variant:`outline`,disabled:u,onClick:()=>{x.current||t()},children:r(`workflows:sprite.cancel`)}),(0,X.jsxs)(V,{type:`submit`,disabled:u||m.length>0,children:[u?(0,X.jsx)(re,{className:`animate-spin`}):(0,X.jsx)(fe,{}),r(`workflows:workflowsPage.run`)]})]})]})]})})}function Ir({message:e}){return e?(0,X.jsxs)(it,{variant:`destructive`,children:[(0,X.jsx)(xe,{}),(0,X.jsx)(rt,{children:e})]}):null}var Lr=`max-[650px]:h-11 pointer-coarse:h-11`;function Rr({notify:e,requestConfirm:t,onBack:i}){let{t:a,language:s}=l(),c=r(),u=ze(`focusSearch`),[d,f]=n(),p=d.get(`view`),m=p===`runs`||p===`templates`?p:`workflows`,h=e=>f(t=>{let n=new URLSearchParams(t);return e===`workflows`?n.delete(`view`):n.set(`view`,e),n}),[g,_]=(0,G.useState)(``),v=Pn({notify:e,requestConfirm:t,query:g}),[y,b]=(0,G.useState)(null),x=(0,G.useRef)(null),S=g.trim().toLocaleLowerCase(),C=S?v.data.runs.filter(e=>`${e.workflowName||e.workflowId}`.toLocaleLowerCase().includes(S)):v.data.runs,w=a(`navigation:navigation.workflows`);return(0,X.jsxs)(lt,{title:w,description:a(`workflows:workflowsPage.lede`),back:i&&{label:a(`navigation:sidebar.features`),ariaLabel:a(`navigation:shell.backToFeaturesLabel`),onBack:i},toolbar:(0,X.jsx)(ut,{search:(0,X.jsx)(at,{id:we,value:g,onValueChange:_,placeholder:a(`navigation:pageHeader.searchPage`,{page:w}),shortcut:u,clearLabel:a(`navigation:more.clearSearch`)}),actions:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(V,{type:`button`,variant:`secondary`,className:`h-9`,onClick:()=>x.current?.click(),children:[(0,X.jsx)(Mt,{}),a(`workflows:workflowsPage.import`)]}),(0,X.jsx)(`input`,{ref:x,hidden:!0,type:`file`,accept:`application/zip,.zip`,onChange:e=>{let t=e.target.files?.[0];e.currentTarget.value=``,t&&v.importWorkflow(t)}}),(0,X.jsxs)(V,{type:`button`,className:`h-9`,onClick:()=>c(o(`new`)),children:[(0,X.jsx)(pe,{}),a(`workflows:workflowsPage.newWorkflow`)]})]}),filters:(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center justify-between gap-x-4 gap-y-2`,children:[(0,X.jsx)(Un,{value:m,t:a,onChange:h}),!v.loading&&(0,X.jsx)(qn,{data:v.data,t:a})]})}),children:[y&&(0,X.jsx)(Fr,{workflow:y,onClose:()=>b(null),onRun:e=>v.runWorkflow(y,e)}),v.loading?(0,X.jsx)(tt,{kind:`loading`,title:a(`workflows:workflowsPage.loadingWorkflows`)}):v.error&&!v.loaded?(0,X.jsx)(tt,{kind:`error`,title:a(`workflows:workflowsPage.loadFailed`),description:v.error,action:(0,X.jsxs)(V,{variant:`secondary`,className:`max-[650px]:h-11`,onClick:()=>void v.reload(),children:[(0,X.jsx)(me,{}),a(`workflows:workflowsPage.retryLoading`)]})}):(0,X.jsxs)(X.Fragment,{children:[v.error&&(0,X.jsx)(`div`,{className:`mt-4`,children:(0,X.jsx)(Ir,{message:v.error})}),m===`workflows`?(0,X.jsx)(Wn,{workflows:v.visibleWorkflows,runs:v.data.runs,busyId:v.busyId,query:g,language:s,t:a,onRun:b,onEdit:e=>c(o(e)),onDuplicate:e=>void v.duplicateWorkflow(e),onExport:e=>void v.exportWorkflow(e),onDelete:e=>void v.removeWorkflow(e)}):m===`runs`?(0,X.jsx)(Gn,{runs:C,busyId:v.busyId,language:s,t:a,onStop:e=>void v.stopRun(e),onRetry:e=>void v.retryRun(e),onApproval:(e,t,n)=>void v.resolveApproval(e,t,n)}):(0,X.jsx)(Kn,{query:g,t:a,onOpenTemplate:e=>c(`${o(`new`)}?template=${encodeURIComponent(e)}`)})]})]})}function zr({title:e,name:t,tools:n,commands:r,onBack:i,t:a}){let o=_();return(0,X.jsxs)(`header`,{"data-workflow-editor-header":!0,"data-focus-region":`header`,"data-window-drag-region":!0,className:`@container/workflow-header flex min-h-[52px] min-w-0 shrink-0 flex-wrap items-center gap-x-2 gap-y-1.5 border-b border-stroke-soft py-2 pr-3 pl-3 [[data-custom-titlebar]_&]:pr-[144px] max-[650px]:pb-2.5 max-[650px]:pt-0`,children:[(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-1 basis-56 items-center gap-1 max-[650px]:basis-0`,"data-window-drag-region":!0,children:[(0,X.jsx)(`nav`,{"aria-label":a(`workflows:workflowsPage.editorNavigation`),className:`flex-none`,children:(0,X.jsxs)(`button`,{type:`button`,"data-back-to-workflows":!0,"aria-label":a(`workflows:workflowsPage.backToWorkflows`),onClick:i,className:`inline-flex h-7 items-center gap-0.5 rounded-[var(--r-sm)] pr-1.5 pl-0.5 text-[13px] text-content-muted transition-colors duration-(--d-fast) hover:bg-surface-hover hover:text-content focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-focus max-[650px]:-ml-1.5 max-[650px]:h-11 max-[650px]:min-w-11 max-[650px]:pr-2 max-[650px]:text-sm max-[650px]:text-content-secondary pointer-coarse:h-11`,children:[(0,X.jsx)(E,{className:`size-4 max-[650px]:size-5`,"aria-hidden":`true`}),(0,X.jsx)(`span`,{children:a(`workflows:workflowsPage.workflows`)})]})}),(0,X.jsx)(`span`,{"aria-hidden":`true`,className:B(`text-content-faint`,o&&`hidden`),children:`/`}),(0,X.jsx)(`h1`,{className:B(`flex-none text-[13px] leading-5 font-medium text-content`,o&&`sr-only`),children:e}),t&&(0,X.jsx)(`p`,{"data-workflow-name":!0,className:`min-w-0 truncate pl-1 text-[13px] text-content-muted max-[650px]:text-sm max-[650px]:text-content`,title:t,children:t})]}),n&&(0,X.jsx)(`div`,{className:`flex flex-none items-center gap-1 max-[650px]:[&_button]:h-11 max-[650px]:[&_button]:min-w-11 max-[650px]:[&_button]:px-2.5 pointer-coarse:[&_button]:h-11`,children:n}),r&&(0,X.jsxs)(X.Fragment,{children:[n&&(0,X.jsx)(`span`,{"aria-hidden":`true`,className:`mx-0.5 h-4 w-px bg-stroke max-[650px]:hidden`}),(0,X.jsx)(`div`,{className:`flex flex-none items-center gap-1.5 max-[650px]:grid max-[650px]:w-full max-[650px]:grid-cols-3 max-[650px]:[&_button]:h-11 pointer-coarse:[&_button]:h-11`,children:r})]})]})}function Br({children:e}){return(0,X.jsx)(`span`,{className:`max-[650px]:sr-only @max-[760px]/workflow-header:sr-only`,children:e})}function Vr({notify:e,registerWorkflowActions:i}){let{t:a,language:c}=l(),u=r(),{workflowId:d=`new`}=t(),[f]=n(),p=(0,G.useCallback)(e=>{u(o(e),{replace:!0})},[u]),m=Pr({workflowId:d,templateId:f.get(`template`),notify:e,onCreated:p}),{busy:h,publishWorkflow:g,runWorkflow:_,running:v,saveWorkflow:y,stopWorkflow:b}=m,[x,S]=(0,G.useState)(!1),[C,w]=(0,G.useState)(!1),[T,E]=(0,G.useState)(null),ee=(0,G.useRef)(null);(0,G.useLayoutEffect)(()=>{let e=ee.current;if(!e)return;let t=()=>E(e.clientWidth>=1e3);t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[m.loading]);let D=(0,G.useCallback)(()=>{!h&&!v&&S(!0)},[h,v]),O=m.draft?!!m.draft.id:d!==`new`;(0,G.useEffect)(()=>i?.({editing:O}),[O,i]);let k=At(a,O)[0],A=()=>u(s.workflows),j=m.running?m.currentRun?.nodes:void 0,M=(0,G.useMemo)(()=>j?new Map(j.map(e=>[e.id,e.status])):void 0,[j]);if(m.loading||!m.draft)return(0,X.jsx)(_t,{variant:`workbench`,children:(0,X.jsxs)(`div`,{className:`workflow-editor-page flex h-full min-h-0 min-w-0 flex-col`,children:[(0,X.jsx)(zr,{title:k,onBack:A,t:a}),m.loading?(0,X.jsx)(tt,{kind:`loading`,title:a(`workflows:workflowsPage.loadingWorkflowEditor`)}):(0,X.jsx)(tt,{kind:`error`,title:a(`workflows:workflowsPage.workflowEditorLoadFailed`),description:m.error,action:(0,X.jsxs)(`div`,{className:`flex flex-wrap justify-center gap-2 max-[650px]:[&>button]:h-11`,children:[(0,X.jsxs)(V,{onClick:m.retryLoad,children:[(0,X.jsx)(me,{className:`size-4`}),a(`workflows:workflowsPage.retryLoading`)]}),(0,X.jsx)(V,{variant:`outline`,onClick:A,children:a(`workflows:workflowsPage.backToWorkflows`)})]})})]})});let N=m.draft,P=(0,X.jsx)(Nr,{draft:N,catalog:m.catalog,selectedNode:m.selectedNode,selectedEdge:m.selectedEdge,currentRun:m.currentRun,onRunImageNode:(e,t)=>{m.runImageNode(e,t)},imageRunBusy:m.busy||m.running,language:c,t:a,systemNotificationPermission:m.systemNotificationPermission,onUpdateNode:m.updateNode,onToggleNotification:m.toggleNotification,onDeleteEdge:m.removeSelectedEdge,onCopyNode:m.copyNode,onDeleteNode:m.deleteNode,onOpenChannels:()=>u(s.channels),onOpenSystemNotificationSettings:()=>{if(window.pisperDesktop?.openNotificationSettings){window.pisperDesktop.openNotificationSettings();return}u(`/config/notifications`)}}),F=m.selectedEdge?a(`workflows:workflowsPage.selectedConnection`):a(`workflows:editor.nodeProperties`);return(0,X.jsx)(_t,{variant:`workbench`,children:(0,X.jsxs)(`div`,{ref:ee,className:`workflow-editor-page @container/workflow flex h-full min-h-0 min-w-0 flex-col`,children:[x&&(0,X.jsx)(Fr,{workflow:N,onClose:()=>S(!1),onRun:_}),(0,X.jsx)(zr,{title:k,name:N.name,onBack:A,t:a,tools:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Dn,{nodeCount:N.nodes.length,t:a,onAddNode:m.addNode}),(0,X.jsxs)(Qe,{children:[(0,X.jsx)($e,{asChild:!0,children:(0,X.jsxs)(V,{variant:`ghost`,size:`sm`,className:Lr,title:a(`workflows:workflowsPage.workflowSettings`),children:[(0,X.jsx)(ve,{}),(0,X.jsx)(Br,{children:a(`workflows:workflowsPage.workflowSettings`)})]})}),(0,X.jsxs)(Je,{className:`sm:max-w-xl`,children:[(0,X.jsxs)(Ze,{children:[(0,X.jsx)(Ye,{children:a(`workflows:workflowsPage.workflowSettings`)}),(0,X.jsx)(qe,{children:a(`workflows:editor.settingsDescription`)})]}),(0,X.jsx)(kr,{draft:N,catalog:m.catalog,t:a,onUpdateDraft:m.updateDraft,onInputUploadBusy:m.onInputUploadBusy})]})]}),T===!1&&(0,X.jsxs)(V,{variant:`ghost`,size:`sm`,className:Lr,title:a(`workflows:editor.nodeProperties`),onClick:()=>w(!0),children:[(0,X.jsx)(le,{}),(0,X.jsx)(Br,{children:a(`workflows:editor.nodeProperties`)})]})]}),commands:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(V,{variant:`outline`,size:`sm`,disabled:h||v,onClick:()=>void y(`draft`),children:[(0,X.jsx)(he,{}),a(`workflows:editor.saveDraft`)]}),(0,X.jsxs)(V,{size:`sm`,disabled:h,onClick:()=>v?void b():D(),children:[v?(0,X.jsx)(ye,{}):(0,X.jsx)(fe,{}),a(v?`workflows:workflowsPage.stop`:`workflows:editor.testRun`)]}),(0,X.jsxs)(V,{variant:`outline`,size:`sm`,disabled:h,onClick:()=>void g(),children:[(0,X.jsx)(L,{}),a(`workflows:editor.publish`)]})]})}),m.error&&(0,X.jsx)(`div`,{className:`shrink-0 px-3 pt-3`,children:(0,X.jsx)(Ir,{message:m.error})}),m.running&&m.currentRun&&(0,X.jsx)(dr,{run:m.currentRun,t:a}),(0,X.jsxs)(`div`,{className:B(`builder-layout grid min-h-0 min-w-0 flex-1 overflow-hidden`,T?`grid-cols-[minmax(0,1fr)_320px]`:`grid-cols-1`),children:[T!==null&&(0,X.jsx)(On,{draft:N,selectedNodeId:m.selectedNodeId,selectedEdgeId:m.selectedEdgeId,nodeStatus:M,t:a,onAddNode:m.addNode,onConnect:m.addEdge,onMoveNode:m.moveNode,onSelectNode:e=>{m.selectNode(e),w(!0)},onSelectEdge:e=>{m.selectEdge(e),w(!0)},onClearSelection:m.clearSelection,onDeleteNodes:m.removeNodes,onDeleteEdges:m.removeEdges}),T&&(0,X.jsxs)(`aside`,{className:`flex min-h-0 min-w-0 flex-col border-l border-stroke-soft bg-panel`,"aria-label":F,children:[(0,X.jsx)(`header`,{className:`flex h-11 shrink-0 items-center border-b border-stroke-soft px-4`,children:(0,X.jsx)(`h2`,{className:`text-sm font-medium`,children:F})}),(0,X.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto overscroll-contain p-4`,children:P})]})]}),T===!1&&(0,X.jsx)(We,{open:C,onOpenChange:w,children:(0,X.jsxs)(Ve,{className:`gap-0 data-[side=right]:w-[min(400px,100vw)] data-[side=right]:sm:max-w-[400px]`,children:[(0,X.jsxs)(Be,{className:`border-b border-stroke-soft pr-12`,children:[(0,X.jsx)(He,{children:F}),(0,X.jsx)(Ue,{className:`sr-only`,children:a(`workflows:editor.inspectorDescription`)})]}),(0,X.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto overscroll-contain p-4`,children:P})]})})]})})}export{Vr as WorkflowBuilder,Rr as WorkflowsPage};